Repository navigation
feat(cli): orca search over the agent session index - #20514
Conversation
`orca search <query>` calls PR 5's `aiVault.searchSessions` over the CLI's existing runtime RPC, against the host `--environment` / `--pairing-code` selects and no other. `orca search --index-status` calls `aiVault.searchStatus`. It is the proof the contract works with no panel. Every flag maps onto a contract field and nothing else: `--scope`, `--fresh`, `--limit`, `--cursor`, repeatable `--agent` and `--path`, `--since`, `--sort`, `--debug`, `--json`. No fan-out, no merged output, no `--host`. One command rather than a `search status` subcommand: the query is a bare positional, so `orca search status` could not be told apart from searching for the word "status". `--status` is unavailable because `orchestration task-list --status <state>` already owns the name as a valued flag. No new runtime capability. PR 5 decided an explicit `method_not_found` refusal maps to `unavailable/no-service`, so reusing `createSessionSearchClient` gives an old host a plain "this host runs no session search service" answer at exit 0 instead of a raw JSON-RPC error. `CommandSpec.repeatableFlags` scopes repeatability per command, because `--agent` must repeat for search and stay single-valued for `worktree create`. `help.ts` sat exactly at max-lines, so `skills-command-flag-help.ts` becomes `command-scoped-flag-help.ts` carrying both tables at the same call-site size.
…w rejects Main gained a `consistent-type-assertions: never` scan in the changed-code gate after this branch was cut, and it reported twelve assertions in the new files. The four in the argument parser were avoidable. `readEnum` now keeps the value `find` returns, which already carries the narrow type, and the agent filter goes through an `isAiVaultAgent` predicate over a `Set<string>` instead of widening the agent tuple. The test now narrows the printed envelope by shape and re-reads the printed result through `AiVaultSearchResponseSchema`, so the JSON assertions are checked rather than claimed, and the flag table is typed so its callback needs no cast. One assertion is left, for the structural fake client, with the SAFETY rationale AGENTS.md requires.
276c181 to
1c9cc44
Compare
There was a problem hiding this comment.
Important
The text formatter sanitizes transcript text but not every host-supplied string it prints. updatedAt and executionHostId reach the terminal raw, which contradicts the security property the PR describes.
Reviewed changes
orca searchcommand — newsrc/cli/specs/search.ts,src/cli/search-command-arguments.ts,src/cli/handlers/search.ts, andsrc/cli/agent-session-search-format.ts. Flags map one-to-one onto PR5'saiVault.searchSessions/searchStatus; the handler reusescreateSessionSearchClient, so an old host'smethod_not_foundbecomesunavailable/no-serviceand the paired-caller exposure policy is applied.- Command-scoped repeatable flags —
CommandSpec.repeatableFlagsand a thirdspecsargument toparseArgs(specForPathPrefix+ a depth-memoisedrepeatableFlags), so--agent/--pathrepeat forsearchwhilelabel/skillkeep their global repeatability. - Global boolean flags —
debug,fresh,index-statusadded toCLI_BOOLEAN_FLAGS; no existing command used them. - Help/discovery plumbing —
skills-command-flag-help.tsbecomescommand-scoped-flag-help.ts, plus root help entries, handler-group registration,CLI_COMMAND_NAMES, and the contract doc bullet.
I traced two cross-cutting risks and both came back clean: orca search does not reach the SSH legacy formatRemoteCli (healthy hosts use the host-CLI passthrough; the legacy dispatcher rejects search outright rather than printing raw JSON), and the parser change does not alter any existing command's behavior (label/skill remain repeatable via the union, and no existing spec names the three new booleans).
Technical details
# Unsanitized host strings in the text output
## Affected sites
- `src/cli/agent-session-search-format.ts:36-41` — the hit header interpolates `hit.updatedAt` and `hit.executionHostId` directly; both are `z.string()` in `AiVaultSearchHitSchema` (`src/shared/ai-vault-search-contract.ts:34,44`) with no escape/control-byte constraint.
- `src/cli/agent-session-search-format.ts:71` — `debug.repairedTerms.join(' ')` is printed raw.
## Required outcome
Every host-supplied string that reaches stdout should pass through `terminalSafe` / `oneLine`, exactly as `title`, `evidence.snippet`, `resumeCommand`, and the status root/reason already do. An OSC 52 or cursor sequence in `updatedAt`/`executionHostId`/`repairedTerms` should not reach the reader's terminal.
## Suggested approach
Wrap `hit.updatedAt` and `hit.executionHostId` in `terminalSafe` (they are single-line fields), and run `repairedTerms` through `oneLine`.DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
ℹ️ Incremental review of the new commit — no new issues. The earlier terminal-sanitization finding is unchanged and still open.
Reviewed changes
refactor(cli): drop the search type assertions—src/cli/search-command-arguments.ts(readEnumkeeps the valuefindreturns, which already carriesTValue, and agent filtering goes through anisAiVaultAgentpredicate over aSet<string>) andsrc/cli/handlers/search.test.ts(typedflagCases, plusprintedEnvelope/printedResultshelpers that narrow the printed JSON by shape and re-read it throughAiVaultSearchResponseSchema). Behavior-preserving; the JSON assertions are stronger than the casts they replace, and the one remainingas nevercarries the requiredSAFETY:rationale.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (4)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughAdds the hidden Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to The hidden session-search CLI behavior has no established merge-blocking risk. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 5f9d7535-bc97-4a3e-a411-45b61d6f14e8
📒 Files selected for processing (21)
docs/reference/agent-session-search-contract.mdsrc/cli/agent-session-search-format.test.tssrc/cli/agent-session-search-format.tssrc/cli/args.tssrc/cli/command-scoped-flag-help.tssrc/cli/command-spec.tssrc/cli/handler-group-manifest.tssrc/cli/handlers/search.test.tssrc/cli/handlers/search.tssrc/cli/help.tssrc/cli/index.tssrc/cli/root-help-text-primary.tssrc/cli/root-help-text-secondary.tssrc/cli/search-command-arguments.test.tssrc/cli/search-command-arguments.tssrc/cli/skills-command-flag-help.tssrc/cli/specs/index.tssrc/cli/specs/search.test.tssrc/cli/specs/search.tssrc/main/startup/cli-command-names.tssrc/shared/cli-argument-boundary.ts
💤 Files with no reviewable changes (1)
- src/cli/skills-command-flag-help.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.
Route every host-supplied string the search formatter prints through the escape stripper, and resolve the repeatable-flag set from the command tokens ahead when a flag sits before the command.
|
the model provider had a temporary upstream failure. The provider refused or dropped the request mid-run — nothing in your repo or your credentials is at fault. Re-trigger Pullfrog; if it keeps happening, check the provider's status page.
|
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Sanitized the remaining host-supplied strings —
agent-session-search-format.tsnow routes the hitupdatedAtandexecutionHostId, the next-page cursor, eachrepairedTermsentry, and the degraded root/reason throughoneLine, closing the only outstanding finding. The new escape-sequence tests cover each field, and bothagent-session-search-format.test.tsandsearch-command-arguments.test.tspass locally (59 tests). - Scoped repeatable flags across the command boundary —
parseArgsnow derives the command scope from the tokens atfindCliCommandIndexwhen no command path has been read yet, so--agent/--pathplaced beforesearchstill repeat while a pre-command--agentstays single-valued forworktree create. Tests cover both directions.
Enum-constrained fields (agent, route, plannerScope, phase, evidence role) and fixed messages remain deliberately unsanitized; the earlier SSH/legacy-formatter and parser-regression traces still hold.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
|
the model provider had a temporary upstream failure. The provider refused or dropped the request mid-run — nothing in your repo or your credentials is at fault. Re-trigger Pullfrog; if it keeps happening, check the provider's status page.
|
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Simplified the
disabledanswer —formatUnavailablenow returns the single lineSession search is off on this host.The removed "Turn on Agent Session History in Orca settings to build the index" hint was premature: the contract still assigns consent/settings application and production-service registration to PR 3b (docs/reference/agent-session-search-contract.md:141-144), so there is no user action to name yet. The format and handler tests now assert the exact one-line output rather than a loose join. - Clarified SSH host scope — the contract doc and the command's
notesnow state that in an Orca SSH terminal the forwarded CLI defaults to the controlling Orca runtime's index, that--pathonly filters that index rather than selecting the SSH host, and that--environment/--pairing-codecan name a paired runtime.searchis absent fromshouldIgnoreRemoteSelection(src/cli/index.ts:29-43), so those routing flags are live for this command.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
`orca search` stays dispatchable but leaves every discovery surface: root help, group help, unknown-command suggestions, and `agent-context --json`. `buildAgentContext` did not filter hidden specs, so it also stops leaking the hidden `terminal stop`.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Withheld
orca searchfrom every discovery surface —SEARCH_COMMAND_SPECS[0]now setshidden: true, andbuildAgentContextfilters hidden specs, so a command that still dispatches no longer appears in root help,agent-context, group help, or typo suggestions. The earlier root-help additions for the command were reverted.specs/search.test.tsnow pins the whole hidden contract — absent fromROOT_HELP_TEXT_PRIMARY/SECONDARY, absent frombuildAgentContext, not offered bysuggestCommands, yet still resolved byfindCommandSpecfor dispatch and still printing its own help — andagent-context.test.tsadds a direct hidden-spec omission test. - No dispatch or parser regression —
findCommandSpecdoes not consulthidden,COMMAND_PATHSis built from unfiltered specs, andCLI_COMMAND_NAMESkeepssearchfor the launch redirect. The affected CLI suites (specs/search, agent-context, search-command-arguments, args-repeatable-flags, command-name parity, registry parity) pass locally: 74 tests.
The effect is intentional per the commit: the command is reachable only by a caller who already knows it until the settings toggle ships, so the agent-driving proof is no longer discoverable through agent-context. I noted this in the PR summary snapshot rather than as a finding.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
* feat(cli): orca search over the agent session index `orca search <query>` calls PR 5's `aiVault.searchSessions` over the CLI's existing runtime RPC, against the host `--environment` / `--pairing-code` selects and no other. `orca search --index-status` calls `aiVault.searchStatus`. It is the proof the contract works with no panel. Every flag maps onto a contract field and nothing else: `--scope`, `--fresh`, `--limit`, `--cursor`, repeatable `--agent` and `--path`, `--since`, `--sort`, `--debug`, `--json`. No fan-out, no merged output, no `--host`. One command rather than a `search status` subcommand: the query is a bare positional, so `orca search status` could not be told apart from searching for the word "status". `--status` is unavailable because `orchestration task-list --status <state>` already owns the name as a valued flag. No new runtime capability. PR 5 decided an explicit `method_not_found` refusal maps to `unavailable/no-service`, so reusing `createSessionSearchClient` gives an old host a plain "this host runs no session search service" answer at exit 0 instead of a raw JSON-RPC error. `CommandSpec.repeatableFlags` scopes repeatability per command, because `--agent` must repeat for search and stay single-valued for `worktree create`. `help.ts` sat exactly at max-lines, so `skills-command-flag-help.ts` becomes `command-scoped-flag-help.ts` carrying both tables at the same call-site size. * refactor(cli): drop the search type assertions main's casting gate now rejects Main gained a `consistent-type-assertions: never` scan in the changed-code gate after this branch was cut, and it reported twelve assertions in the new files. The four in the argument parser were avoidable. `readEnum` now keeps the value `find` returns, which already carries the narrow type, and the agent filter goes through an `isAiVaultAgent` predicate over a `Set<string>` instead of widening the agent tuple. The test now narrows the printed envelope by shape and re-reads the printed result through `AiVaultSearchResponseSchema`, so the JSON assertions are checked rather than claimed, and the flag table is typed so its callback needs no cast. One assertion is left, for the structural fake client, with the SAFETY rationale AGENTS.md requires. * fix(cli): sanitize host strings and scope pre-command repeatable flags Route every host-supplied string the search formatter prints through the escape stripper, and resolve the repeatable-flag set from the command tokens ahead when a flag sits before the command. * refactor(cli): resolve repeatable flag rules once per command * fix(cli): clarify session search availability and SSH scope * feat(cli): hide orca search until the settings toggle ships `orca search` stays dispatchable but leaves every discovery surface: root help, group help, unknown-command suggestions, and `agent-context --json`. `buildAgentContext` did not filter hidden specs, so it also stops leaking the hidden `terminal stop`.

ELI5
You can now find an old agent conversation from the terminal. Type
orca search "that resize bug"and Orca prints the sessions whose transcripts mention it, one line each, with the snippet that matched underneath.orca search --index-statustells you how much of the index has been built.What Changed
orca searchover PR 5's session-search contract. It callsaiVault.searchSessionsandaiVault.searchStatuson the CLI's existing runtime RPC client, against the host--environment/--pairing-codeselects and no other. One host per invocation, no fan-out. In an Orca SSH terminal, the forwarded CLI defaults to the controlling Orca runtime's index.--pathfilters results on the selected runtime; it does not select the SSH host.Flags map one-to-one onto the contract request and add nothing it does not have:
<query>, or--queryquery--scope conversation|allscope--freshfreshness: 'wait-until-current'--limit <n>limit--cursor <c>cursor--agent <id>(repeatable)filters.agents--path <p>(repeatable)filters.scopePaths--since <iso>filters.since--sort relevance|newestfilters.sort--debugdebug: true--index-statusaiVault.searchStatusExit codes:
unavailable(disabled, not-ready, no-service)stale-cursormalformed-cursor, transport failureSupporting changes:
CommandSpec.repeatableFlagsand a thirdspecsargument toparseArgs. Repeatability is per-command vocabulary:--agentmust repeat forsearchand stay single-valued forworktree create, which one global set cannot express. Every other command keeps last-wins, and there is a test for that.--fresh,--debugand--index-statusjoin the global boolean-flag set. None of the three collides with an existing flag.skills-command-flag-help.tsbecomescommand-scoped-flag-help.tsand carries both the skills and the search tables.help.tswas sitting exactly on itsmax-lineslimit, so this keeps the call site the same size instead of adding a disable.docs/reference/agent-session-search-contract.mdnaming the CLI boundary.Why
PR 5 shipped the contract with no consumer. The CLI is the cheapest proof that the API answers without a panel, which is the test question behind reviewer finding F3, and it is the form an agent can drive today.
Three shape decisions worth reviewing:
One command, not a
search statussubcommand. The query is a bare positional, soorca search statuscannot be told apart from searching for the word "status".--statusis also unavailable, becauseorchestration task-list --status <state>already owns that name as a valued flag and the boolean set is global.--index-statusis unambiguous and reads correctly next to the existingorca status. The query is also accepted as--query, which is howlinear searchandrepo search-refsalready spell it.No new runtime capability, and
RemoteRuntimeCompatGateis untouched. PR 5 decided that an explicit-32601/method_not_foundrefusal maps tounavailable/no-service. ReusingcreateSessionSearchClientgives that for free, so an old host gets a plain sentence rather than a raw JSON-RPC error. It also applies the same exposure policy the host applied: a paired runtime is a relay caller and gets no resume command or source path. Verified end to end below.--jsonkeeps the CLI envelope. The contract answer sits verbatim underresult.--jsonfailures already print{ ok: false, error }throughreportCliError, so a bare contract object on success would leave an agent with two different success signals.[[ ]]marks pass through unchanged. The CLI emits no ANSI anywhere in its output, so a highlight scheme invented here would be the only one in the surface. Transcript text is still stripped of escape and control bytes before printing, so an OSC 52 sequence in a tool log cannot reach the reader's terminal.Linked Issue
Part of the session-search stack, consuming the contract and transport from #20277. This PR targets
main.Fixes #
Visual Proof
A result page, from the handler test's fake response:
Truncation flags in words, and a hit with no text evidence:
An
unavailable / disabledanswer, which exits 0 because it is an answer:The built CLI against a live released Orca host that predates PR 5, which is the old-host path:
Bad input, from the same built binary:
Testing
Latest parser refactor validation on macOS: 1,309 CLI tests passed, including nested-command and alias regression coverage; CLI typecheck and changed-code quality checks passed. A temporary comparison against the previous parser passed across the command registry and flag placements. The final availability/help wording changes passed all 59 affected tests.
79 new tests across four files: spec and help registration (13), argument parsing including every flag, repeatables and bad values (29), text rendering for results, unavailable, stale-cursor, truncation, debug and status (18), and the handler against a fake
ctx.clientthat records method and params per flag combination (19).Gates, all exit 0 on macOS:
pnpm tc,pnpm run tc:clipnpm test src/cli src/main/startup src/shared: 9,608 passed, 124 skipped, 885 filespnpm run check:code-quality:changedandpnpm run check:react-doctor:changedagainst the PR base: 0 new findings across 19 filespnpm run audit:code-quality:type-awarepnpm build:cli, then the builtout/cli/index.jsrun against a live local Orca hostCross-platform: no shell assumptions in the output, paths printed exactly as the host sent them, times printed as ISO 8601. The
--pathfilter is a literal execution-host path and is never expanded or resolved against the current directory, so a Windows path survives a macOS caller.Not tested: Linux, Windows, and a live SSH or paired-server host. No index exists in production until PR 3b constructs the service, so every live run here took the
no-servicepath. The result-page rendering above is from test fixtures, not a real index.Known rough edge, not fixed: an unquoted multi-word query (
orca search strict mode violation) fails with a bare "Unknown command". Every other positional command behaves the same way. The command notes tell the reader to quote, and--queryis accepted; a variadic trailing positional would be a shared-parser change no other command has asked for.AI Disclosure
Review
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
Security: transcript text is stripped of ANSI escape and C0/C1 control bytes before printing, so a hostile tool log cannot drive the reader's terminal. The client re-applies
redactForTransport, so a paired runtime's hits carry source presence only, with nofilePath,codexHome, orresumeCommand.Backwards compatibility: no wire change. No new RPC method, no new stream opcode, no new capability. An old host's refusal becomes
unavailable/no-service, which is the behaviour PR 5's contract already specifies.Performance: one RPC per invocation. The parser collects flag entries in order, resolves the command-specific repeatability rules once, then combines the entries. No lookahead or mutable spec cache is needed.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)