cli: add code search via peregrine (ENT-993, ENT-994)#1615
Conversation
Add `entire search --code <query>` to search code content through peregrine via entire-api cells. Gated behind ENTIRE_CODE_SEARCH=1 env var so it stays dark until launch. - New `codesearch` package: client for peregrine's /search/api/search endpoint with request/response types matching the peregrine API - Auth via NewEntireAPICellClient (jurisdictional identity tokens), same pattern as `entire api --to cell` - Output modes: grep-style text (terminal) or JSON (--json / piped) - Flags: --code, --case-sensitive, --repo, --limit - Rejects incompatible flags (--page, --all-repos, --case-sensitive without --code) with clear error messages - Response overflow detection (8 MiB cap with explicit error) - Timeout scoped to the search call only (30s), not auth resolution Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds an env-gated (ENTIRE_CODE_SEARCH=1) code-content search mode to the existing entire search command, backed by a new codesearch client that calls peregrine via the authenticated entire-api cell.
Changes:
- Adds
entire search --code <query>with--case-sensitive,--repo, and--limit, plus validation to reject incompatible checkpoint-search flags. - Introduces
cmd/entire/cli/codesearchpackage to POST to/search/api/searchwith an 8 MiB response cap and typed request/response structs. - Adds unit tests covering the env gate, flag validation, output rendering, and
codesearch.Search()behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| cmd/entire/cli/search_cmd.go | Wires --code path into entire search, including env gate, flag validation, request mapping, and text/JSON rendering. |
| cmd/entire/cli/search_cmd_test.go | Adds tests for env gating, flag incompatibilities, and output helpers for the new code-search mode. |
| cmd/entire/cli/codesearch/codesearch.go | Implements peregrine code search client with response size limiting and error handling. |
| cmd/entire/cli/codesearch/codesearch_test.go | Adds unit tests for success/error/oversize response handling in the codesearch client. |
| if opts.repoFilter != "" { | ||
| if err := search.ValidateRepoFilters([]string{opts.repoFilter}); err != nil { | ||
| return fmt.Errorf("validating repo filter: %w", err) | ||
| } | ||
| } | ||
|
|
||
| req := codesearch.SearchRequest{ | ||
| Query: opts.query, | ||
| CaseSensitive: opts.caseSensitive, | ||
| } | ||
| if opts.limit > 0 { | ||
| req.MaxResults = opts.limit | ||
| } | ||
| if opts.repoFilter != "" { | ||
| req.Repos = []string{opts.repoFilter} | ||
| } |
| cmd.Flags().BoolVar(&jsonOutput, "json", false, "Output as JSON") | ||
| cmd.Flags().BoolVar(&codeFlag, "code", false, "Search code content via peregrine (requires ENTIRE_CODE_SEARCH=1)") | ||
| cmd.Flags().BoolVar(&caseSensitive, "case-sensitive", false, "Case-sensitive code search (only with --code)") | ||
| cmd.Flags().IntVar(&limitFlag, "limit", resultsPerPage, "Maximum number of results per page") |
| if resp.StatusCode != http.StatusOK { | ||
| var errResp struct { | ||
| Error string `json:"error"` | ||
| } | ||
| if json.Unmarshal(body, &errResp) == nil && errResp.Error != "" { | ||
| return nil, fmt.Errorf("code search error (%d): %s", resp.StatusCode, errResp.Error) | ||
| } | ||
| return nil, fmt.Errorf("code search returned %d: %s", resp.StatusCode, string(body)) |
- Parse inline repo: filters for --code path (was passing them as literal query text to peregrine) - Handle repo:* and --all-repos with --code as "no filter" instead of passing literal "*" to the API - Use api.ErrorResponse/HTTPError for error parsing instead of inline struct (supports both legacy and newer error envelopes) - Fix --limit help text to clarify behavior differs for --code - Drop --page/--all-repos rejection (silently ignored is less disruptive than breaking shared scripts) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
bugbot run |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 55ceb6e. Configure here.
| caseSensitive: caseSensitive, | ||
| jsonOutput: jsonOutput, | ||
| insecureHTTP: insecureHTTPAuth, | ||
| }) |
There was a problem hiding this comment.
Page flag ignored for code
Medium Severity
The --code branch returns before checkpoint search runs and never checks --page, so entire search --code --page 2 … still returns the first result set with no error. Code search has no pagination, so the flag should be rejected like --case-sensitive without --code.
Reviewed by Cursor Bugbot for commit 55ceb6e. Configure here.
| codeRepo := repoFlag | ||
| if codeRepo == "" && len(parsed.Repos) > 0 { | ||
| codeRepo = parsed.Repos[0] | ||
| } |
There was a problem hiding this comment.
Multiple repo filters silently ignored
Medium Severity
For --code, inline repo: filters are parsed into parsed.Repos, but only parsed.Repos[0] is used and search.ValidateRepoFilters is never run on the full list. Queries like repo:a/b repo:c/d term or repo:a/b,c/d term search one repo without the error checkpoint search returns for multiple repo filters.
Reviewed by Cursor Bugbot for commit 55ceb6e. Configure here.


https://entire.io/gh/entireio/cli/trails/739
Summary
entire search --code <query>to search code content through peregrine via entire-api cellscodesearchpackage with client for peregrine's/search/api/searchendpointENTIRE_CODE_SEARCH=1— returns a clear error otherwise, keeping it dark until launchNewEntireAPICellClient(jurisdictional identity tokens), same pattern asentire api --to cellDetails
repo:path:line: context(terminal) or structured JSON (--json/ piped)--code,--case-sensitive,--repo,--limit— incompatible flags (--page,--all-repos,--case-sensitivewithout--code) are rejected with clear errorsLinear tickets
Test plan
codesearch.Search()(success, API error, non-JSON error, response overflow)ENTIRE_CODE_SEARCHon/off/falsy values)--codewithout gate, without query,--case-sensitivewithout--code,--all-reposwith--code,--pagewith--code)mise run checkpasses (fmt + lint + all tests)🤖 Generated with Claude Code
Note
Medium Risk
Adds authenticated calls to a new cell API surface with jurisdictional routing; impact is limited by the
ENTIRE_CODE_SEARCH=1preview gate and bounded response handling.Overview
Adds preview code content search to the hidden
entire searchcommand via--code, calling peregrine through entire-api atPOST /search/api/search. A newcodesearchpackage defines request/response types andSearch(), including an 8 MiB response cap and structuredapi.HTTPErrorhandling on failures.The
--codepath is gated onENTIRE_CODE_SEARCH=1; otherwise users get a clear “not yet available” error. It authenticates withNewEntireAPICellClient, applies a 30s timeout only around the search POST, and supports--repo/ inlinerepo:(withrepo:*/--all-repostreated as no repo filter),--limit, and--case-sensitive(rejected unless--code). Results render as grep-stylerepo:path:line:on a TTY or JSON when--jsonor stdout is piped.Unit tests cover the client (success, API/non-JSON errors, oversized body), env gating, flag validation, and text/JSON output.
Reviewed by Cursor Bugbot for commit 55ceb6e. Configure here.