Repository navigation
feat(agent-status): read OSC 7501 program status beside hooks - #30261
Conversation
ccad120 to
1ef6bde
Compare
Programs can tell Orca what they are doing through the Program Status Protocol (OSC 7501); Claude Code, Codex, Grok, pi and oh-my-pi already do. Orca answers the protocol's feature-detection probe (visible xterm and the hidden-pane emulator), parses reports from PTY output on the execution host (src/shared/program-status/), and keeps two lanes: - Lifecycle state keeps one owner per pane. Hooks win; OSC 7501 drives the row when hooks are off, missing, or silent on a state the program has left (server/program-status/hook-precedence). - The program's own report (progress, its one-line message, blocks such as sign-in) is a live-only `programStatus` facet kept per pane (server/program-status/facet-store), stitched onto rows at publish time and carried to the renderer store, mobile, paired clients and `worktree ps`. Facet-only changes patch just the facet. Title-driven readers (idle edges, delivery, tui-idle, exit inference) classify by the program's OSC 7501 activity while it reports one and fall back to title glyphs only for agents that report nothing explicit, so they keep working when Claude stops painting its title glyph after the probe.
1ef6bde to
e922020
Compare
📝 Walkthrough
Priority: ➖ Normal Merge Risk: 🟡 Moderate · up to
|
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:
ef7da9ab-c7a9-49b3-aa1d-898b1b46d20d
📒 Files selected for processing: 126
src/cli/workspace-format.tssrc/cli/worktree-ps-program-status.test.tssrc/cli/worktree-ps-program-status.tssrc/main/agent-hooks/README.mdsrc/main/agent-hooks/agent-hook-runtime-deps.tssrc/main/agent-hooks/server-program-status-hook-yield.test.tssrc/main/agent-hooks/server/program-status/facet-store.test.tssrc/main/agent-hooks/server/program-status/facet-store.tssrc/main/agent-hooks/server/program-status/hook-precedence.test.tssrc/main/agent-hooks/server/program-status/hook-precedence.tssrc/main/agent-hooks/server/program-status/pane-timers.test.tssrc/main/agent-hooks/server/program-status/pane-timers.tssrc/main/agent-hooks/server/server-authority-aliases.tssrc/main/agent-hooks/server/server-ingest-terminal.tssrc/main/agent-hooks/server/server-lifecycle.tssrc/main/agent-hooks/server/server-listeners.tssrc/main/agent-hooks/server/server-persistence.tssrc/main/agent-hooks/server/server-row-ownership.tssrc/main/agent-hooks/server/server-status-identity.tssrc/main/agent-hooks/server/server-tab-cleanup.tssrc/main/agent-hooks/server/server-types.tssrc/main/daemon/terminal-view-attribute-responder.test.tssrc/main/daemon/terminal-view-attribute-responder.tssrc/main/runtime/construction/runtime-construction-dependencies.tssrc/main/runtime/construction/runtime-construction.tssrc/main/runtime/construction/runtime-host-services.tssrc/main/runtime/orca-runtime-tests/program-status-osc.spec.tssrc/main/runtime/orca-runtime-tests/terminal-side-effect-facts-part-02.spec.tssrc/main/runtime/orca-runtime-tests/terminal-side-effect-facts-part-03.spec.tssrc/main/runtime/orca-runtime-tests/terminal-side-effect-facts.spec.tssrc/main/runtime/orca-runtime.test.tssrc/main/runtime/runtime-hook-agent-row-selection.tssrc/main/runtime/runtime-mobile-agent-status-builder.test.tssrc/main/runtime/runtime-mobile-agent-status-builder.tssrc/main/runtime/runtime-mobile-agent-status-projection.tssrc/main/runtime/runtime-terminal-contracts.tssrc/main/runtime/runtime-terminal-state-records.tssrc/main/runtime/runtime-worktree-agent-rows.tssrc/main/runtime/runtime-worktree-agent-source.tssrc/main/runtime/runtime-worktree-agent-sources.test.tssrc/main/runtime/runtime-worktree-pty-agent-sources.tssrc/main/runtime/terminal/lifecycle/floating-session-liveness.tssrc/main/runtime/terminal/lifecycle/pty-exit-lifecycle.tssrc/main/runtime/terminal/lifecycle/terminal-view-resources.tssrc/main/runtime/terminal/output/pty-output-ingestion.tssrc/main/runtime/terminal/output/terminal-derived-agent-facts.tssrc/main/runtime/terminal/output/terminal-output-generation.tssrc/main/runtime/terminal/output/terminal-title-observation.tssrc/main/runtime/terminal/output/terminal-title-tracker.tssrc/main/runtime/terminal/wait/terminal-wait-blocked-checks.tssrc/main/runtime/tui-idle-evidence.test.tssrc/main/runtime/tui-idle-evidence.tssrc/main/startup/main-window-agent-status.tssrc/renderer/src/components/terminal-pane/parked-terminal-byte-watcher.tssrc/renderer/src/components/terminal-pane/pty-connection/agent-task-complete-notify.tssrc/renderer/src/components/terminal-pane/pty-connection/pty-input-recovery.tssrc/renderer/src/components/terminal-pane/pty-output-effect-ordering.tssrc/renderer/src/components/terminal-pane/pty-output-processor-program-activity.test.tssrc/renderer/src/components/terminal-pane/pty-output-processor.tssrc/renderer/src/components/terminal-pane/pty-output-side-effect-queue.tssrc/renderer/src/components/terminal-pane/pty-output-title-observer.tssrc/renderer/src/components/terminal-pane/pty-transport-types.tssrc/renderer/src/components/terminal-pane/pty-transport.tssrc/renderer/src/components/terminal-pane/terminal-capability-replies.tssrc/renderer/src/components/terminal-pane/terminal-side-effect-facts-handler.test.tssrc/renderer/src/components/terminal-pane/terminal-side-effect-facts-handler.tssrc/renderer/src/hooks/ipc-events-agent-status-store-test-fixtures.tssrc/renderer/src/hooks/ipc-events/agent-status-event-applicator.tssrc/renderer/src/hooks/ipc-events/agent-status-listeners.tssrc/renderer/src/hooks/ipc-events/agent-status-partial-updates.tssrc/renderer/src/hooks/ipc-events/agent-status-program-status-only.test.tssrc/renderer/src/hooks/ipc-events/agent-status-unavailable.test.tssrc/renderer/src/hooks/useIpcEvents-agent-status-batch-projection.test.tssrc/renderer/src/lib/agent-idle-edge.test.tssrc/renderer/src/lib/agent-idle-edge.tssrc/renderer/src/runtime/remote-agent-row-program-status.test.tssrc/renderer/src/runtime/runtime-rpc-client.tssrc/renderer/src/runtime/sync-runtime-graph-agent-status-projection.test.tssrc/renderer/src/runtime/sync-runtime-graph-projection-hot-path.test.tssrc/renderer/src/runtime/sync-runtime-graph/agent-status-projection.tssrc/renderer/src/runtime/web-session-tabs-sync/agent-status-patch.tssrc/renderer/src/runtime/web-session-tabs-sync/state-equality-core.test.tssrc/renderer/src/runtime/web-session-tabs-sync/state-equality-core.tssrc/renderer/src/store/slices/agent-status-batch.test.tssrc/renderer/src/store/slices/agent-status-contract.tssrc/renderer/src/store/slices/agent-status-live-entry-builder.tssrc/renderer/src/store/slices/agent-status-program-status-actions.tssrc/renderer/src/store/slices/agent-status-program-status.test.tssrc/renderer/src/store/slices/agent-status-runtime.tssrc/renderer/src/store/slices/agent-status-slice-contract.tssrc/renderer/src/store/slices/agent-status.tssrc/shared/agent-detection.tssrc/shared/agent-status-ipc-payload.tssrc/shared/agent-status-observation.tssrc/shared/agent-status-osc-pending-retention.test.tssrc/shared/agent-status-osc-scan-budget.test.tssrc/shared/agent-status-osc.test.tssrc/shared/agent-status-osc.tssrc/shared/agent-status-subagent-snapshot.tssrc/shared/agent-status-tracker-program-activity.test.tssrc/shared/agent-status-types.tssrc/shared/agent-title-status.tssrc/shared/claude-terminal-interrupt.test.tssrc/shared/claude-terminal-interrupt.tssrc/shared/osc-title-extraction.tssrc/shared/program-status/activity.tssrc/shared/program-status/agent-status-projector.test.tssrc/shared/program-status/agent-status-projector.tssrc/shared/program-status/facet.tssrc/shared/program-status/osc-scanner.test.tssrc/shared/program-status/osc-scanner.tssrc/shared/program-status/presentation.test.tssrc/shared/program-status/presentation.tssrc/shared/program-status/protocol.test.tssrc/shared/program-status/protocol.tssrc/shared/program-status/query-responder.test.tssrc/shared/program-status/query-responder.tssrc/shared/program-status/records.test.tssrc/shared/program-status/records.tssrc/shared/program-status/title-activity-order.tssrc/shared/protocol-version.tssrc/shared/runtime-worktree-contracts.tssrc/shared/terminal-agent-status-processor.test.tssrc/shared/terminal-agent-status-processor.tssrc/shared/terminal-output-side-effects.tssrc/shared/terminal-side-effect-facts.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.
| if (event.removesProgramStatusRow === true) { | ||
| // Why: gone records end only the program's own row; they are no verdict on a hook agent. | ||
| this.hookSilenceRechecks.cancel(paneKey) | ||
| if (previous?.observation?.origin === 'osc') { | ||
| // Why a row drop, not pane teardown: the process lives on, and so do its alias and caches. | ||
| if (mutationBefore !== undefined) { | ||
| this.commitStatusRowMutation(mutationBefore, previous) | ||
| } | ||
| this.dropStatusEntry(paneKey) | ||
| this.emitPaneStatusCleared({ paneKey, programStatusRemoved: true }) | ||
| } | ||
| return | ||
| } |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
🔎 Supported by static analysis
🏁 Script executed:
sed -n '190,340p' src/main/agent-hooks/server/server-ingest-terminal.ts
rg -n "9999" src --glob '!*.test.ts' -l | head -40
rg -n "fromProgramStatus|programStatusOrigin|origin: 'osc'" src/main src/shared | head -60Repository: stablyai/orca
Length of output: 10923
🏁 Script executed:
set -o pipefail
printf '%s\n' '--- OSC 9999 references and emitters ---'
rg -n -F --glob '*.ts' --glob '*.tsx' --glob '*.md' -e '\x1b]9999;' -e '9999;' -e 'OSC 9999' -e 'osc9999' -e 'OSC9999' src docs .github 2>/dev/null || test "$?" -eq 1
printf '%s\n' '--- program-status flow and provenance fields ---'
rg -n -F --glob '*.ts' -e 'programStatusPayloads' -e 'fromProgramStatus' -e 'removesProgramStatusRow' -e 'origin:' -e 'ingestProgramStatusFacet' -e 'ingestTerminalStatus' src/main src/shared | head -240
printf '%s\n' '--- relevant declarations and parser/projector files ---'
sed -n '1,240p' src/shared/agent-status-osc.ts
sed -n '120,210p' src/main/runtime/terminal/output/terminal-derived-agent-facts.ts
sed -n '130,205p' src/main/runtime/runtime-terminal-contracts.ts
sed -n '1,180p' src/shared/agent-status-observation.ts
printf '%s\n' '--- runtime/configuration references for terminal agents and wrappers ---'
rg -n -i --glob '*.ts' --glob '*.tsx' --glob '*.md' -e 'agent integration' -e 'wrapper' -e 'pty' -e 'terminal.*agent' -e 'osc' src/main src/shared docs 2>/dev/null | head -240Repository: stablyai/orca
Length of output: 42297
🏁 Script executed:
set -o pipefail
printf '%s\n' '--- merged protocol processor ---'
nl -ba src/shared/terminal-agent-status-processor.ts | sed -n '1,180p'
printf '%s\n' '--- derived terminal facts and event dispatch ---'
nl -ba src/main/runtime/terminal/output/terminal-derived-agent-facts.ts | sed -n '1,240p'
printf '%s\n' '--- OSC 7501 projector ---'
nl -ba src/shared/program-status/agent-status-projector.ts | sed -n '1,240p'
printf '%s\n' '--- ingest event contract and mutation path ---'
nl -ba src/main/agent-hooks/server/server-ingest-terminal.ts | sed -n '70,340p'
printf '%s\n' '--- status application and origin handling ---'
nl -ba src/main/agent-hooks/server/server-status-application.ts | sed -n '230,330p'
printf '%s\n' '--- protocol tests showing interleaving and source path ---'
nl -ba src/shared/terminal-agent-status-processor.test.ts | sed -n '1,90p'
nl -ba src/main/runtime/orca-runtime-tests/terminal-output-and-worker-recovery.spec.ts | sed -n '130,205p'Repository: stablyai/orca
Length of output: 42405
[P1] Keep OSC 9999 and OSC 7501 row provenance separate.
The PTY processor accepts both protocols on the same PTY and preserves their byte order. It can therefore process an OSC 9999 payload followed by an OSC 7501 payload from the same stream.
emitTerminalAgentStatusEvents marks OSC 7501 events with fromProgramStatus, but the row stores only observation.origin: 'osc'. When an OSC 7501 report has removesProgramStatusRow, the removal branch checks only that shared origin. It can therefore drop an OSC 9999 row. An ordinary OSC 7501 update also reaches applyNormalizedStatus and can replace an OSC 9999 row because no stored provenance or agentType check gives the OSC 9999 row precedence.
Record OSC 7501 provenance on the stored row. Gate program-status removal and update precedence on that provenance instead of on the shared origin: 'osc' value.
| resetAgentStatusCarry: () => { | ||
| processAgentStatusChunk = createAgentStatusOscProcessor() | ||
| scanProgramStatus = createProgramStatusSideEffectScanner() | ||
| }, |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
#!/bin/bash
rg -nP -C4 '\bresetCrossChunkParserState\b'Repository: stablyai/orca
Length of output: 4892
Clear program activity when resetting parser state.
When resetCrossChunkParserState runs after dropped PTY bytes, resetAgentStatusCarry recreates scanProgramStatus but leaves titleObserver with its previous programActivity. The new scanner has no record of the prior activity, so it cannot emit the transition to null. Later title updates can remain classified as working, which prevents idle classification and related completion handling.
🐛 Suggested fix
--- "a/src/renderer/src/components/terminal-pane/pty-output-processor.ts"
+++ "b/src/renderer/src/components/terminal-pane/pty-output-processor.ts"
@@ -240,10 +240,12 @@
clearStaleTitleTimer: titleObserver.clearStaleTitleTimer,
flushPendingSideEffects: sideEffects.flush,
resetBellDetector: () => bellDetector.reset(),
resetAgentStatusCarry: () => {
processAgentStatusChunk = createAgentStatusOscProcessor()
scanProgramStatus = createProgramStatusSideEffectScanner()
+ // The fresh scanner no longer knows the program's records; titles classify again.
+ titleObserver.applyProgramActivity(null)
},
getPendingEscapeTailAnsi: () => partialEscapeTail,
disposePendingSideEffectGauge: sideEffects.disposeGauge
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| resetAgentStatusCarry: () => { | |
| processAgentStatusChunk = createAgentStatusOscProcessor() | |
| scanProgramStatus = createProgramStatusSideEffectScanner() | |
| }, | |
| resetAgentStatusCarry: () => { | |
| processAgentStatusChunk = createAgentStatusOscProcessor() | |
| scanProgramStatus = createProgramStatusSideEffectScanner() | |
| // The fresh scanner no longer knows the program's records; titles classify again. | |
| titleObserver.applyProgramActivity(null) | |
| }, |
ELI5
Terminal programs can tell the terminal what they're doing (working, waiting for you, done, failed, how far along) with a standard escape sequence called OSC 7501. Claude Code, Codex, Grok, pi and oh-my-pi already send it. With this PR Orca understands it, while still preferring its own hooks wherever they exist.
What Changed
Before: Orca learned an agent's status only from per-agent hooks, or by guessing from window titles. Programs without an Orca integration (brew, terraform, an agent run with hooks off) had no status.
After: any program that speaks OSC 7501 gets a status row: working, waiting (approval or question), blocked (e.g. sign-in), done or failed, carrying its own message and progress. For agents that have hooks, nothing visible changes: hooks still own state, prompt, tool, transcript and resume identity. How the extra data is displayed (progress ring, letter icons, previews) comes in the next PR.
Mechanism:
src/shared/program-status/holds the protocol grammar and limits, a split-safe scanner (it also watches OSC 133 A and RIS, which end a program's records), per-terminal records, and a projector. The projector emits one lifecycle payload plus one facet per change.OSC 7501 ; ?probe from the visible xterm (terminal-capability-replies) and from the hidden-pane emulator (terminal-view-attribute-responder). Claude and pi stay silent without that reply.server/program-status/hook-precedence.tsmakes OSC 7501 yield to a live hook row, unless hooks have been silent for 2 minutes on a state the program has since left.programStatus(state, kind, progress, message) is owned only by the OSC 7501 channel and lives inserver/program-status/facet-store.ts. It's attached to rows at publish time, never persisted, and never decides state. A facet-only change goes out asprogramStatusOnlyand patches just the facet in the renderer store: no notifications, state history or telemetry. It also reaches mobile, paired clients andworktree ps(42%/(Sign-in required)).tui-idlewaiters and exit inference. Claude stops painting its ⠂/✳ glyph once the probe is answered, which would have blinded them. Now, while a program reports OSC 7501, its activity is the status both the shared title tracker (createAgentStatusTracker) and main's records (classifyPtyTitleStatus) use. Titles only classify agents that report nothing explicit, so non-OSC 7501 agents are unchanged. A chunk's activity changes are applied before its titles, which then no longer move status.idle/permission), and the prompt-cache timer identifies Claude from the pane's status row, so nothing downstream re-reads the title to work out what happened.Why
OSC 7501 gives exact, ordered status for any program, at no per-event cost and with nothing to install. That makes it ideal over SSH and for tools Orca will never integrate. It can't replace hooks: it has no prompt, tool input, reply text or session id, and native chat and resume depend on those.
So I rejected both "switch agents to OSC 7501" and "ignore it where hooks exist" in favour of one owner for state (hooks first) plus an additive facet for what only the program knows. The facet lives in its own store, not inside the payload, so it can't race hook rows, isn't persisted, and stays wire-compatible: one optional field that older peers ignore.
Stack:
Linked Issue
N/A (maintainer change; no pre-existing issue)
Visual Proof
Little visual change here: program rows appear with today's styling, and the presentation lands in the next PR, which has the screenshots.
Real Claude Code 2.1.302 with hooks, sampled from the renderer store during a turn: hooks keep owning the row while the facet carries Claude's own phase line.
Testing
Live (macOS, background Orca dev build of the full stack):
agent-workingandagent-idle(status: idle) edges fire from its OSC 7501 reports. The row stays hook-owned with facet updates beside it, the prompt-cache timer starts, and the tab title resets when Claude exits.Automated:
src/{shared,main,renderer,cli}. The remaining failures also fail onmainor on this machine (real-shell suites, packaging,orcadpaths, structured-session adoption,badgeColor), or are timing flakes that pass when run on their own. The one failure,orca-runtime.test.ts(badgeColor on runtime cloneRepo), also fails onmain.AI Disclosure
Review
Agent skill upstream boundary
Notes
includeschecks per chunk on the fast path; facet ticks skip all state subscribers.src/main/agent-hooks/README.mdhas the OSC 7501 support matrix and the precedence rules.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)