Files
orca/src/shared/agent-terminal-status-equivalence.ts
Brennan BensonandNeil ec4687c434 feat(agents): distinguish Claude background monitoring (takes over #14205) (#16201)
* feat(agents): distinguish Claude background monitoring

Adds an optional `workingMode: 'monitoring'` discriminator for a Claude
session whose lead turn finished but which still has background shell tasks
or session crons registered. The wire state stays `working`, so older peers
that never read the field keep rendering Working.

(cherry picked from commit d5d54b4bdd)

Rebased onto current main (554 commits of drift) by Brennan Benson;
conflicts resolved by keeping both sides where main and this branch made
independent additions to the same construct.

* fix(sidebar): keep monitoring status visible

(cherry picked from commit fd6b38654d)

* test(agents): cover Claude monitoring drain

(cherry picked from commit ce4d61ebf8)

* test(mobile): avoid unresolved renderer test type

(cherry picked from commit bbcfa35ff9)

* feat(agents): render Claude monitoring as a static turquoise dot

Replaces the yellow Radio glyph from #14205 with a static dot in a new
--agent-monitoring token (#8abeb7), defined once for light and once for
dark like --workspace-status-done, so the status keeps its identity when
the theme flips. Deliberately a fixed UI value: it never reads terminal
theme state at runtime.

Adds the turn-boundary notification pins. The monitoring predicate and
the turnCompletedAt stamp are computed from the same "lead said done but
the pane resolves to working" expression, so a rename can silently drop
the stamp and kill a completion notification that works today with
nothing else going red.

* revert(agents): restore the yellow Radio glyph for monitoring

Brennan chose #14205's original treatment over the turquoise dot, so the visual
goes back to nwparker's: lucide Radio in text-yellow-500 across the sidebar,
dashboard dot, cmd-j palette and agent-map ring.

Reverts only the visual surface. The turn-boundary notification pins stay — the
monitoring predicate and the turnCompletedAt stamp share an expression, so a
rename can silently drop the stamp and kill a completion that works today with
nothing else going red. The --agent-monitoring token is removed with its last
consumer rather than left dead in main.css.

---------

Co-authored-by: Neil <4138956+nwparker@users.noreply.github.com>
2026-08-24 15:24:32 -07:00

33 lines
1.8 KiB
TypeScript

import type { ParsedAgentStatusPayload } from './agent-status-types'
/** Whether a terminal status is the same hook status with only hook-owned metadata omitted.
*
* `preserveActiveTurnStamp` marks the cached hook payload as the still-open turn the OSC ping
* belongs to: OSC carries neither the turn stamp nor the assistant tail, so their absence must
* read as "omitted", not "changed", or the ping overwrites a live turn's stamp. */
export function terminalStatusPayloadMatchesHook(
cachedHookPayload: ParsedAgentStatusPayload,
terminalPayload: ParsedAgentStatusPayload,
preserveActiveTurnStamp = false
): boolean {
// OSC never carries model/children; compare only fields its protocol owns.
return (
cachedHookPayload.state === terminalPayload.state &&
// OSC never carries workingMode either; only a stated mismatch breaks equivalence.
(terminalPayload.workingMode === undefined ||
cachedHookPayload.workingMode === terminalPayload.workingMode) &&
cachedHookPayload.prompt === terminalPayload.prompt &&
cachedHookPayload.agentType === terminalPayload.agentType &&
cachedHookPayload.toolName === terminalPayload.toolName &&
cachedHookPayload.toolInput === terminalPayload.toolInput &&
cachedHookPayload.interactivePrompt === terminalPayload.interactivePrompt &&
(cachedHookPayload.lastAssistantMessage === terminalPayload.lastAssistantMessage ||
(preserveActiveTurnStamp && terminalPayload.lastAssistantMessage === undefined)) &&
cachedHookPayload.interrupted === terminalPayload.interrupted &&
// A session-boundary done must never dedupe against a real done (STA-3386).
cachedHookPayload.sessionBoundary === terminalPayload.sessionBoundary &&
(cachedHookPayload.turnCompletedAt === terminalPayload.turnCompletedAt ||
(preserveActiveTurnStamp && terminalPayload.turnCompletedAt === undefined))
)
}