/* eslint-disable max-lines -- Why: root and generated command help text live together so CLI discovery stays greppable. */ import type { CommandSpec } from './args' import { findCommandSpec, isCommandGroup, supportsBrowserPageFlag } from './args' const ROOT_HELP_TEXT = `orca Usage: orca [options] Startup: open Launch Orca and wait for the runtime to be reachable serve Start a headless Orca runtime server status Show app/runtime/graph readiness Environments: environment add Save a remote Orca runtime from a pairing code environment list List saved remote Orca runtimes environment show Show one saved remote Orca runtime environment rm Remove a saved remote Orca runtime Automations: automations list List scheduled Orca automations automations show Show one Orca automation automations create Create a scheduled Orca automation automations edit Edit an Orca automation automations remove Remove an Orca automation and its run history automations run Run an Orca automation now automations runs List automation run history Repos: repo list List repos registered in Orca repo add Add a project to Orca by filesystem path repo show Show one registered repo repo set-base-ref Set the repo's default base ref for future worktrees repo search-refs Search branch/tag refs within a repo Worktrees: worktree list List Orca-managed worktrees worktree show Show one worktree worktree current Show the Orca-managed worktree for the current directory worktree create Create a new Orca-managed worktree worktree set Update Orca metadata for a worktree worktree rm Remove a worktree from Orca and git worktree ps Show a compact orchestration summary across worktrees Terminals: terminal list List live Orca-managed terminals terminal show Show terminal metadata and preview terminal read Read bounded terminal output terminal send Send input to a live terminal terminal wait Wait for a terminal condition (exit, tui-idle) terminal stop Stop terminals for a worktree terminal create Create a terminal session in a worktree terminal rename Set or clear the title of a terminal tab terminal split Split an existing terminal pane terminal switch Bring a terminal tab to the foreground terminal focus Alias for terminal switch terminal close Close a terminal pane (or tab if last pane) Orchestration: orchestration send Send an inter-agent message orchestration check Check messages for a terminal orchestration reply Reply to a message orchestration inbox Show all messages across recipients orchestration task-create Create an orchestration task orchestration task-list List orchestration tasks orchestration task-update Update a task status orchestration dispatch Dispatch a task to a terminal orchestration dispatch-show Show dispatch context for a task orchestration run Start the coordinator loop orchestration run-stop Stop the active coordinator run orchestration gate-create Create a decision gate blocking a task orchestration gate-resolve Resolve a pending decision gate orchestration gate-list List decision gates orchestration reset Reset orchestration state Computer Use: computer permissions Open the macOS permission setup for computer-use computer list-apps List running apps available to computer-use computer list-windows List visible windows for a target app computer get-app-state Capture a compact accessibility snapshot of an app computer click Click an app element or window coordinate computer perform-secondary-action Run an advertised accessibility action computer scroll Scroll an app element computer drag Drag between app elements or window coordinates computer type-text Type literal text at the current app focus computer press-key Press a key using xdotool-style syntax computer hotkey Press a shortcut combination such as CmdOrCtrl+A computer paste-text Paste text through the native clipboard path computer set-value Set the value of a settable app element Browser Automation: tab create Create a new browser tab (navigates to --url) tab list List open browser tabs tab show Show one browser tab by page id tab current Show the current browser tab tab profile list List browser session profiles tab profile create Create a browser session profile tab profile delete Delete a browser session profile tab profile set Switch a browser tab to a different profile tab profile show Show the profile bound to a browser tab tab profile use-default Switch a browser tab back to the default profile tab profile clone Clone a browser tab into another profile tab switch Switch the active browser tab by --index or --page tab close Close a browser tab by --index/--page or the current tab snapshot Accessibility snapshot with element refs (e.g. @e1, @e2) goto Navigate the active tab to --url click Click element by --element ref fill Clear and fill input by --element ref with --value type Type --input text at the current focus (no element needed) select Select dropdown option by --element ref and --value hover Hover element by --element ref keypress Press a key (e.g. --key Enter, --key Tab) scroll Scroll --direction (up/down) by --amount pixels back Navigate back in browser history reload Reload the active browser tab screenshot Capture viewport screenshot (--format png|jpeg) eval Evaluate --expression JavaScript in the page context wait Wait for page idle or --timeout ms check Check a checkbox by --element ref uncheck Uncheck a checkbox by --element ref focus Focus an element by --element ref clear Clear an input by --element ref drag Drag --from ref to --to ref upload Upload --files to a file input by --element ref dblclick Double-click element by --element ref forward Navigate forward in browser history scrollintoview Scroll --element into view get Get element property (--what: text, html, value, url, title) is Check element state (--what: visible, enabled, checked) inserttext Insert text without key events mouse move Move mouse to --x --y coordinates mouse down Press mouse button mouse up Release mouse button mouse wheel Scroll wheel --dy [--dx] find Find element by locator (--locator role|text|label --value ) set device Emulate device (--name "iPhone 12") set offline Toggle offline mode (--state on|off) set headers Set HTTP headers (--headers '{"key":"val"}') set credentials Set HTTP auth (--user --pass

) set media Set color scheme (--color-scheme dark|light) clipboard read Read clipboard contents clipboard write Write --text to clipboard dialog accept Accept browser dialog (--text for prompt response) dialog dismiss Dismiss browser dialog storage local get Get localStorage value by --key storage local set Set localStorage --key --value storage local clear Clear localStorage storage session get Get sessionStorage value by --key storage session set Set sessionStorage --key --value storage session clear Clear sessionStorage download Download file via --selector to --path highlight Highlight --selector on page exec Run any agent-browser command (--command "...") Common Commands: orca open [--json] orca serve [--port ] [--pairing-address ] [--mobile-pairing] [--no-pairing] [--json] orca status [--json] orca environment add --name --pairing-code [--json] orca environment list [--json] orca environment show --environment [--json] orca environment rm --environment [--json] orca worktree list [--repo ] [--limit ] [--json] orca worktree create --repo --name [--base-branch ] [--issue ] [--comment ] [--parent-worktree ] [--no-parent] [--run-hooks] [--activate] [--json] orca worktree show --worktree [--json] orca worktree current [--json] orca worktree set --worktree [--display-name ] [--issue ] [--comment ] [--parent-worktree |--no-parent] [--json] orca worktree rm --worktree [--force] [--run-hooks] [--json] orca worktree ps [--limit ] [--json] orca terminal list [--worktree ] [--limit ] [--json] orca terminal show [--terminal ] [--json] orca terminal read [--terminal ] [--json] orca terminal send [--terminal ] [--text ] [--enter] [--interrupt] [--json] orca terminal wait [--terminal ] --for exit|tui-idle [--timeout-ms ] [--json] orca terminal stop --worktree [--json] orca terminal create [--worktree ] [--title ] [--command ] [--focus] [--json] orca terminal split [--terminal ] [--direction horizontal|vertical] [--json] orca terminal switch [--terminal ] [--json] orca terminal close [--terminal ] [--json] orca repo list [--json] orca repo add --path [--json] orca repo show --repo [--json] orca repo set-base-ref --repo --ref [--json] orca repo search-refs --repo --query [--limit ] [--json] Selectors: --repo Registered repo selector such as id:, name:, or path: --worktree Worktree selector such as id:, branch:, issue:, path:, or active/current --terminal Runtime-issued terminal handle returned by \`orca terminal list --json\` --parent-worktree Parent worktree selector; create infers one from the Orca terminal or current directory by default --no-parent Force worktree creation/update to have no parent lineage Terminal Send Options: --text Text to send to the terminal --enter Append Enter after sending text --interrupt Send as an interrupt-style input when supported Wait Options: --for exit Wait until the target terminal exits --timeout-ms Maximum wait time before timing out Output Options: --json Emit machine-readable JSON instead of human text --pairing-code Connect to a remote Orca runtime using an orca://pair#... code --environment Connect using a saved environment id or name --help Show this help message Behavior: Most commands require a running Orca runtime. If Orca is not open yet, run \`orca open\` first. Remote runtime access can also be supplied with ORCA_PAIRING_CODE or ORCA_ENVIRONMENT. Use selectors for discovery and handles for repeated live terminal operations. Browser Workflow: 1. Create or navigate: orca tab create --url https://example.com orca goto --url https://example.com 2. Inspect the page: orca snapshot (Returns an accessibility tree with element refs like e1, e2, e3) For concurrent workflows, prefer: orca tab list --json then reuse tabs[].browserPageId with --page on later commands. 3. Interact: orca click --element e2 orca fill --element e5 --value "search query" orca keypress --key Enter 4. Re-inspect: orca snapshot (Element refs change after navigation — always re-snapshot before interacting) Browser Options: --element Element ref from snapshot (e.g. @e3) --url URL to navigate to --value Value to fill or select --input Text to type at current focus (no element needed) --expression JavaScript expression to evaluate --key Key to press (Enter, Tab, Escape, Control+a, etc.) --direction

Scroll direction: up or down --amount Scroll distance in pixels (default: viewport height) --index Tab index (from \`tab list\`) --page Stable browser page id (preferred for concurrent workflows) --profile Browser profile id --show-profile Include the tab's browser profile in text output --format Screenshot image format --from Drag source element ref --to Drag target element ref --files Comma-separated file paths for upload --timeout Wait timeout in milliseconds --worktree Scope commands to a specific worktree's browser tabs Examples: $ orca open $ orca status --json $ orca repo list $ orca worktree create --repo name:orca --name cli-test-1 --issue 273 $ orca worktree show --worktree branch:Jinwoo-H/cli $ orca worktree current $ orca worktree set --worktree active --comment "waiting on review" $ orca worktree ps --limit 10 $ orca terminal list --worktree path:/Users/me/orca/workspaces/orca/cli-test-1 --json $ orca terminal send --terminal term_123 --text "hi" --enter $ orca terminal wait --terminal term_123 --for exit --timeout-ms 60000 --json $ orca tab current --json $ orca tab show --page page_123 --json $ orca tab create --url https://example.com --profile work $ orca tab profile clone --page page_123 --profile work --json $ orca snapshot $ orca click --element e3 $ orca fill --element e5 --value "hello" $ orca goto --url https://example.com/login $ orca keypress --key Enter $ orca eval --expression "document.title" $ orca tab list --json` export function printHelp(specs: CommandSpec[], commandPath: string[] = []): void { const exactSpec = findCommandSpec(specs, commandPath) if (exactSpec) { console.log(formatCommandHelp(exactSpec)) return } if (isCommandGroup(commandPath)) { console.log(formatGroupHelp(specs, commandPath[0])) return } if (commandPath.length > 0) { console.log(`Unknown command: ${commandPath.join(' ')}\n`) } console.log(ROOT_HELP_TEXT) } export function formatCommandHelp(spec: CommandSpec): string { const lines = [`orca ${spec.path.join(' ')}`, '', `Usage: ${spec.usage}`, '', spec.summary] const displayedFlags = supportsBrowserPageFlag(spec.path) ? [...spec.allowedFlags, 'page'] : spec.allowedFlags if (displayedFlags.length > 0) { lines.push('', 'Options:') for (const flag of displayedFlags) { lines.push(` ${formatFlagHelp(flag)}`) } } if (spec.notes && spec.notes.length > 0) { lines.push('', 'Notes:') for (const note of spec.notes) { lines.push(` ${note}`) } } if (spec.examples && spec.examples.length > 0) { lines.push('', 'Examples:') for (const example of spec.examples) { lines.push(` $ ${example}`) } } return lines.join('\n') } export function formatGroupHelp(specs: CommandSpec[], group: string): string { const groupSpecs = specs.filter((spec) => spec.path[0] === group) const lines = [`orca ${group}`, '', `Usage: orca ${group} [options]`, '', 'Commands:'] for (const spec of groupSpecs) { lines.push(` ${spec.path.slice(1).join(' ').padEnd(18)} ${spec.summary}`) } lines.push('', `Run \`orca ${group} --help\` for command-specific usage.`) return lines.join('\n') } export function formatFlagHelp(flag: string): string { const helpByFlag: Record = { 'base-branch': '--base-branch Base branch/ref to create the worktree from', command: '--command Command to run in the terminal on startup', comment: '--comment Comment stored in Orca metadata', cursor: '--cursor Line cursor from a previous read (returns only new output)', action: '--action Secondary accessibility action name', activate: '--activate Reveal the new worktree in the Orca app', app: '--app App name, bundle ID, or pid:N', direction: '--direction Direction: up|down|left|right for scroll, horizontal|vertical for split', 'display-name': '--display-name Override the Orca display name', 'element-index': '--element-index Element index from get-app-state', title: '--title Custom title for the terminal tab (omit to reset)', enter: '--enter Append Enter after sending text', force: '--force Force worktree removal when supported', focus: '--focus Reveal the created terminal session in Orca', for: '--for exit|tui-idle Wait condition to satisfy', 'from-element-index': '--from-element-index Source element index from get-app-state', 'from-x': '--from-x Source window-local x coordinate', 'from-y': '--from-y Source window-local y coordinate', help: '--help Show this help message', interrupt: '--interrupt Send as an interrupt-style input when supported', issue: '--issue Linked GitHub issue number', json: '--json Emit machine-readable JSON', key: '--key Key or combo to press, e.g. Escape or CmdOrCtrl+L', limit: '--limit Maximum number of rows to return', 'mouse-button': '--mouse-button Mouse button: left, right, or middle', name: '--name Name for the new worktree or automation', 'no-parent': '--no-parent Force no parent lineage', 'no-screenshot': '--no-screenshot Skip screenshot capture after the operation', pages: '--pages Number of scroll pages', 'parent-worktree': '--parent-worktree Parent worktree selector; create infers one by default', path: '--path Filesystem path to the repo', query: '--query Search text for matching refs', ref: '--ref Base ref to persist for the repo', repo: '--repo Repo selector such as id:, name:, or path:', 'restore-window': '--restore-window Bring the target app/window forward before the operation', session: '--session Snapshot namespace for a related computer-use workflow', terminal: '--terminal Runtime-issued terminal handle', text: '--text Text payload to send or type', 'text-stdin': '--text-stdin Read text payload from stdin', 'timeout-ms': '--timeout-ms Maximum wait time before timing out', 'to-element-index': '--to-element-index Destination element index from get-app-state', 'to-x': '--to-x Destination window-local x coordinate', 'to-y': '--to-y Destination window-local y coordinate', worktree: '--worktree Worktree selector such as id:, branch:, issue:, path:, or active/current', workspace: '--workspace Existing worktree selector for automation runs', prompt: '--prompt Automation prompt to pass to the agent', provider: '--provider Agent id such as codex, claude, or gemini', trigger: '--trigger Automation schedule preset, cron, or RRULE', schedule: '--schedule Alias for --trigger', time: '--time Time used with daily/weekdays/weekly presets', day: '--day <0-6> Day used with weekly preset, Sunday=0', timezone: '--timezone IANA timezone for the automation', enabled: '--enabled Enable the automation', disabled: '--disabled Disable the automation', 'workspace-mode': '--workspace-mode existing or new-per-run', 'missed-run-grace-minutes': '--missed-run-grace-minutes Missed-run grace window', 'value-stdin': '--value-stdin Read set-value payload from stdin', 'window-id': '--window-id Target a window id from list-windows', 'window-index': '--window-index Target a window index from list-windows', // Browser automation flags element: '--element Element ref from snapshot (e.g. e3)', url: '--url URL to navigate to', value: '--value Value to fill or select', input: '--input Text to type at current focus', expression: '--expression JavaScript expression to evaluate', amount: '--amount Scroll distance in pixels', index: '--index Tab index to switch to', page: '--page Stable browser page id from `orca tab list --json`', profile: '--profile Browser profile id', 'show-profile': '--show-profile Include tab profile in text output', format: '--format Screenshot image format' } return helpByFlag[flag] ?? `--${flag}` }