Repository navigation
feat(search): show search results as a table of versions and platforms - #3041
Conversation
|
@mikeland73 Here is the improvement to the search output. |
Search against the v2 search API, asking for each result's newest releases and their systems, so `devbox search` lists versions alongside the platforms they are available on, grouping consecutive versions that share the same platforms. It requests 11 releases of the top 11 packages by default, and every release with --show-all. Search services that don't return releases fall back to one /v2/pkg call per displayed package. A package whose lookup fails is left out, and the search fails only when every lookup does. Search services set with DEVBOX_SEARCH_HOST now need to implement /v2/search, and /v2/pkg unless they return releases, instead of /v1/search.
b6482cb to
bff54d5
Compare
|
@claude ptal |
|
Claude finished @mikeland73's task in 31s —— View job Review of #3041I read the diff ( Looks good
Suggestions (non-blocking)
|
[Medium impact] The changes affect the CLI search workflow and search services configured by Devbox users. The PR appears safe to merge, with non-blocking improvements to trimming hints, response types, and the footer URL.
|
| if limit > 0 && len(hits) > limit { | ||
| hits = hits[:limit] |
There was a problem hiding this comment.
Hidden results lose their hint
Search cuts matches to 11 before dropping failed lookups. With 12 matches and one failed lookup among those 11, the CLI receives 10 packages. If their version lists are short, it omits the --show-all hint despite hiding more matches.
newPackage also loses this hint when empty versions consume the extra release slot. Keep truncation information when applying these limits instead of inferring it from the remaining items.
Prompt To Fix With AI
This is a comment left during a code review.
Path: internal/searcher/client.go
Line: 69-70
Comment:
**Hidden results lose their hint**
`Search` cuts matches to 11 before dropping failed lookups. With 12 matches and one failed lookup among those 11, the CLI receives 10 packages. If their version lists are short, it omits the `--show-all` hint despite hiding more matches.
`newPackage` also loses this hint when empty versions consume the extra release slot. Keep truncation information when applying these limits instead of inferring it from the remaining items.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| AttributePath string `json:"attribute_path"` | ||
| CommitHash string `json:"commit_hash"` | ||
| Date time.Time `json:"date"` | ||
| Outputs []Output `json:"outputs"` |
There was a problem hiding this comment.
Unused fields can break search
The new response types decode dates and nested outputs that search never uses. An empty timestamp or a changed output shape can reject the whole search response or drop a package, even when its name, versions, and platforms are usable.
Remove unused fields from these search-specific types, especially LastUpdated, Date, and Outputs, so unrelated metadata cannot prevent the table from being shown.
Prompt To Fix With AI
This is a comment left during a code review.
Path: internal/searcher/model.go
Line: 50-53
Comment:
**Unused fields can break search**
The new response types decode dates and nested outputs that search never uses. An empty timestamp or a changed output shape can reject the whole search response or drop a package, even when its name, versions, and platforms are usable.
Remove unused fields from these search-specific types, especially `LastUpdated`, `Date`, and `Outputs`, so unrelated metadata cannot prevent the table from being shown.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| trimmedVersionsLength, | ||
| ) | ||
| } | ||
| fmt.Fprintf(w, "For more information go to: %s/\n", strings.TrimSuffix(host, "/")) |
There was a problem hiding this comment.
Footer exposes URL credentials
If DEVBOX_SEARCH_HOST contains URL credentials, such as https://user:secret@example.com, this footer copies the password into stdout. Captured command output and CI logs will then contain it after a successful search. Remove the URL's user info before printing the link.
How this was verified: Client() reads the environment value unchanged, and Host() passes it directly to the footer's fmt.Fprintf call.
Prompt To Fix With AI
This is a comment left during a code review.
Path: internal/boxcli/search.go
Line: 156
Comment:
**Footer exposes URL credentials**
If `DEVBOX_SEARCH_HOST` contains URL credentials, such as `https://user:secret@example.com`, this footer copies the password into stdout. Captured command output and CI logs will then contain it after a successful search. Remove the URL's user info before printing the link.
**How this was verified:** `Client()` reads the environment value unchanged, and `Host()` passes it directly to the footer's `fmt.Fprintf` call.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Summary
devbox search <query>now prints a table of each package's versions and the platforms each version runs on. Consecutive versions available on the same platforms share a row:Before, the output was one line per package,
* ripgrep (15.2.0, 15.1.0, ... ...), with no way to tell which versions you can install on your machine.Why
/v2/searchinstead of/v1/search:/v1/searchreturns per-version platforms, but they don't match what Devbox can actually install. For example, it listsnodejs@24.0.0on all four systems, but/v1/resolveand/v2/resolveonly resolve it on Linux. The/v2data agrees with the resolve endpoints.One request per search. The client calls
/v2/search?q=<query>&releases=11. Each result then carries its newest releases and their systems, so the CLI can show 10 versions and know there are more.--show-allsendsreleases=all.By default the CLI still shows the top 10 packages and 10 versions of each, and prints the existing
--show-allhint when it trims.Fallback for other search services. A service that doesn't return
releasesstill works. The client calls/v2/pkgonce for each package it will display, at most 11 by default, several at a time. A package whose lookup fails is left out. The search fails only if every lookup fails with something other than a 404.Breaking change for
DEVBOX_SEARCH_HOST: a self-hosted search service now needs/v2/search, plus/v2/pkgif it doesn't returnreleases, instead of/v1/search.SEARCH_API.mddocuments both endpoints, the fields Devbox reads, and how/v2/pkgplatforms (arm64/macOS) map to Nix systems (aarch64-darwin).Open question: piped output. The table replaces the old
* name (versions)lines everywhere, including when stdout is a pipe, so scripts that parse the old format will break. If that matters, one option is to print the table only on a terminal and keep the old list when piped (go-isattyis already a dependency). I'm happy to add that, or another format you'd prefer.Other changes:
No results found for "<query>"and exits 0.Found <n>+ resultsstill uses the server'stotal_results.github.com/jedib0t/go-pretty/v6v6.8.3, andvendor-hashis updated.How was it tested?
golangci-lint run ./...reports 0 issues.go test ./internal/searcher/ ./internal/boxcli/passes. The tests cover:internal/searcher:/v2/pkgcalls;releases=allis sent when there's no limit;/v2/pkgfallback, with releases trimmed to the limit and duplicate systems collapsed;internal/boxcli:--show-all;https://www.nixsearch.com:devbox search ripgrep,devbox search ripgrep --show-all, and a query with no matches.Community Contribution License
All community contributions in this pull request are licensed to the project
maintainers under the terms of the
Apache 2 License.
By creating this pull request, I represent that I have the right to license the
contributions to the project maintainers under the Apache 2 License as stated in
the
Community Contribution License.