Files
orca/src/cli/worktree-ps-program-status.test.ts
T
Neil e3c9370da4 feat(agent-status): read OSC 7501 program status beside hooks (#30261)
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.
2026-10-18 22:12:37 -07:00

50 lines
1.7 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import type { RuntimeWorktreeAgentRow } from '../shared/runtime-types'
import { formatWorktreePsProgramStatus } from './worktree-ps-program-status'
function agent(over: Partial<RuntimeWorktreeAgentRow>): RuntimeWorktreeAgentRow {
return {
paneKey: 'tab:leaf',
parentPaneKey: null,
state: 'working',
agentType: 'codex',
prompt: 'ship it',
taskTitle: null,
displayName: null,
lastAssistantMessage: null,
toolName: null,
toolInput: null,
interrupted: false,
stateStartedAt: 1,
updatedAt: 1,
...over
}
}
describe('formatWorktreePsProgramStatus', () => {
it('is empty without agents or facets', () => {
expect(formatWorktreePsProgramStatus(undefined)).toBe('')
expect(formatWorktreePsProgramStatus([agent({})])).toBe('')
})
it('shows live progress', () => {
const programStatus = { state: 'working' as const, progress: 42, observedAt: 1 }
expect(formatWorktreePsProgramStatus([agent({ programStatus })])).toBe(' 42%')
})
it('prefers a reported block over another agent progress', () => {
const working = agent({ programStatus: { state: 'working', progress: 42, observedAt: 1 } })
const signIn = agent({
paneKey: 'tab:leaf-2',
state: 'done',
programStatus: { state: 'blocked', kind: 'auth', observedAt: 1 }
})
expect(formatWorktreePsProgramStatus([working, signIn])).toBe(' (Sign-in required)')
})
it('hides progress on a finished row', () => {
const programStatus = { state: 'working' as const, progress: 42, observedAt: 1 }
expect(formatWorktreePsProgramStatus([agent({ state: 'done', programStatus })])).toBe('')
})
})