Files
orca/src/cli/command-scoped-flag-help.ts
T
Brennan Benson ffc2b3fba1 fix(orchestration): preserve task reset lineage per Run (#28823)
* fix(orchestration): preserve task reset lineage per Run

STA-10382

* fix(orchestration): record removed Tasks, Dispatches and workers per entity

Replace the per-Run capped JSON snapshot with one row per removed entity in
removed_orchestration_work, written by AFTER DELETE triggers on tasks,
dispatch_contexts, worker_dispatches, worker_terminal_resources,
remote_dispatch_attachments and federated_dispatches. The triggers are
rebuilt on every open after migrate and dropped at migrate start; a
recorded_since coverage marker moves forward whenever any trigger was
missing, so a Run created before recording reads partial, never
complete-and-empty.

reset --tasks keeps its delete list and order; its reply gains optional
removed counts computed after commit (a failed summary only drops the
field). run-show gains an optional constant-size removedWork summary and
--removed/--cursor paging. reset --all clears the record; deleting a Run
deletes its rows.

Removes the snapshot modules, the run_reset_lineage table, the in-transaction
receipt completion and alwaysRequestId from the first version of this PR.

* chore: drop accidental pnpm-lock.yaml churn

* refactor(orchestration): decode removed work entries through unknown before the checked cast

* fix(orchestration): count settled workers with open terminals and name affected Runs

- A worker may still be running when its state was possibly live or its
  Orca-owned terminal was never released; the reset reply, run-show line and
  listing share one derivation from the removed records.
- The reset reply names the affected Runs (optional runIds); the CLI prints
  the exact run-show command for one Run and the list for several.
- The watermark read is no longer swallowed inside the reset transaction.
- run-show's removed-work read is guarded; a failure omits the field.
- Coverage compares created_at strictly after recorded_since.
- --removed lists a federated worker once, shows a user-taken-over terminal
  as such, and says when a cursor is past the end.

* fix(orchestration): count removed workers by held process minus durable exit proof

- A removed worker may still be running when Orca held its process (live
  state, federated dispatch pending or dispatched, or an Orca-owned terminal)
  and no durable exit proof exists (stopped, released, released terminal, or
  a certified termination reason on its Dispatch).
- The exit proof is one DURABLE_EXIT_PROOF constant shared by the fleet
  liveness projection (no behavior change) and the removed-work reader.
- Dispatch records keep terminationReason.
- Coverage is complete when a Run was created at or after recorded_since; a
  moved marker is stamped one second past the newest existing non-legacy Run,
  and the capture installs after the stub home Run backfill.

* docs(orchestration): correct the terminationReason and coverage marker comments

* fix(orchestration): decode removed work entries through a checked schema

The stored record is parsed once with a discriminated zod schema per kind,
so the listed entry keeps its precise type without an assertion. The same
lineage field table drives the capture triggers' key set and integer casts.

* fix(orchestration): exhaustive removed-work listing switch; keep valid ids in id lists

List worker and remote worker entries with explicit cases so the switch is
exhaustive over the entry kinds. An id list drops non-string elements and
keeps the rest, as before the schema decoder.

* test(orchestration): build removed-work CLI fixtures without type assertions

Use a real RuntimeClient with a spied call and decode listing fixtures through
the entry schema, so the tests carry checked types instead of casts.

* fix(orchestration): name only the removed kinds in run-show and word the no-record message truthfully

The run-show line lists the kinds a Run actually lost, terminals included,
and the --removed message for a missing record no longer claims the host
keeps none, since a new host omits it when its read fails.

* fix(wsl-move): classify the removed-work tables with the other orchestration tables

removed_orchestration_work and its coverage marker live in the orchestration
database and go with its Runs, so the WSL mover rewrites them in place like
every other orchestration table.

* fix(orchestration): keep the removed-work hint when a reset removes only terminal records
2026-10-26 14:05:33 -07:00

87 lines
4.3 KiB
TypeScript

// File focus differs from terminal create's shared --focus help.
const FILE_OPEN_FOCUS_HELP =
"--focus Bring the user to the file (switches Orca's window to its worktree)"
const COMMAND_SCOPED_FLAG_HELP: Record<string, Record<string, string>> = {
'reference add': {
url: '--url <url-or-jira-key> Full review/issue URL or Jira key; use positionals or repeated --url',
'reference-site': '--reference-site <id> Jira site for bare keys; see orca jira connection'
},
'reference remove': {
url: '--url <url> Full review or issue URL; pass all URLs positionally or all as repeated --url',
key: '--key <key> Opaque key from reference list; repeat for several'
},
'reference find': {
query: '--query <url-or-key> Full URL or native issue key such as STA-1234',
repo: '--repo <selector> Filter by workspace repository membership',
'include-archived': '--include-archived Include archived workspaces',
limit: '--limit <n> Maximum matching workspaces (default 50)'
},
'worktree create': {
reference:
'--reference <url-or-jira-key> Attach an issue/review URL or Jira key; repeat for several',
'reference-site': '--reference-site <id> Jira site for bare keys; see orca jira connection',
pr: '--pr <number> Linked GitHub pull request number',
'gitlab-issue': '--gitlab-issue <number|url> Linked GitLab issue in the source project',
'gitlab-mr': '--gitlab-mr <number|url> Linked GitLab merge request in the source project'
},
'skills get': {
full: '--full Print the full guide with bundled references',
reference: '--reference <name> Print one bundled reference by name',
references: '--references List the bundled reference names for a topic'
},
'environment update': {
force: '--force Restart over running terminals instead of deferring the update'
},
'environment recover': {
'accept-changed-state':
'--accept-changed-state Restore the prelaunch snapshot over state a rejected build changed',
yes: '--yes Confirm discarding what the rejected build changed'
},
'environment stop': {
yes: '--yes Confirm stopping the server and unlinking it from this machine'
},
'file open': {
line: '--line <n> Cursor line (1-based)',
column: '--column <n> Cursor column (1-based; requires --line)',
focus: FILE_OPEN_FOCUS_HELP
},
'file diff': {
focus: FILE_OPEN_FOCUS_HELP
},
'file open-changed': {
focus: FILE_OPEN_FOCUS_HELP
},
'skills install': {
agent: '--agent <names> Comma-separated install targets; default is detected agents'
},
'orchestration run-show': {
removed: '--removed List the Tasks, Dispatches and workers removed from this Run',
cursor: '--cursor <cursor> Cursor printed by the previous page of removed work'
},
'worktree set': {
unread: '--unread Mark the workspace unread in the sidebar',
read: '--read Mark the workspace read, clearing the unread dot'
},
search: {
query: '--query <text> Search text; also accepted as the positional argument',
scope: '--scope <corpus> conversation (user and assistant turns) or all (default)',
fresh: '--fresh Wait up to 5s for the host to reconcile its index first',
limit: '--limit <n> Hits per page (default 20, maximum 100)',
cursor: '--cursor <cursor> Opaque cursor printed by the previous page of this search',
agent: '--agent <id> Restrict to one agent; repeat for several',
path: '--path <path> Restrict to an execution-host path; repeat for several',
since: '--since <iso> Only sessions updated at or after this ISO 8601 timestamp',
sort: '--sort <order> relevance (default) or newest',
debug: '--debug Include the planner route the host used',
'index-status': '--index-status Report the index instead of searching'
},
ports: {
all: '--all List every listener on the workspace host, not just this workspace'
}
}
export function formatCommandScopedFlagHelp(command: string, flag: string): string | undefined {
return COMMAND_SCOPED_FLAG_HELP[command]?.[flag]
}