Task 13: Drive agent indicators from Herdr
Summary
Replace local screen/OSC detection with server-provided agent state for Herdr-owned terminals, as required by parent plan #394. Map Herdr identity and lifecycle into the existing badges, waiting notifications, completion dots, and sidebar consumers. Stop invoking the local detector on Herdr terminals. Define unknown-state, viewed-completion, and reconnect behavior so duplicate notifications cannot fire. Do not switch the default runtime, delete the detector, or let Local detection and Herdr state both drive the same session.
Pin remains Herdr v0.9.0, JSON protocol 22, endpoint generation 1. Verified on empty shells: pane.agent_status is "unknown" and snapshot.agents is empty (docs/herdr-integration.md Later-task capabilities; herdr_contract.rs idle pane.get). Live working / blocked / done / idle transitions are unverified (#398). Map those documented strings from snapshot and events using fixtures; do not claim live CLI parity and do not close #398 unless a real agent CLI is exercised against this pin. Production must consume Herdr state, not write it: no pane.report_agent, pane.report_agent_session, agent.start, or agent.prompt. Namespace stays Task 4 2code. Session ownership stays per-id RuntimeRouter::backend_for, not RuntimeDiscovery.selected_backend.
Task 6 currently stores no agent fields on ProjectedPane, subscribes to pane.agent_detected but does not apply it, and excludes pane.agent_status_changed (subscribe_params_cover_lifecycle_not_output_waits). Task 11 still runs createAgentStatusDetector on Herdr frames. Task 12 reattaches the same 2code session id, so reconnect hydration must reuse that id and must not treat a still-blocked pane as a fresh waiting edge.
Dependencies: Parent plan #394. Prerequisites: #395 (Task 1, accepted on issue-395-herdr-integration-contract), #402 (Task 2, accepted on task-2-runtime-boundary), #404 (Task 3, accepted on task-3-herdr-sidecar), #406 (Task 4, accepted on task-4-server-discovery), #409 (Task 5, accepted on task-5-socket-client), #411 (Task 6, accepted on task-6-runtime-sync), #414 (Task 7, accepted on task-7-runtime-mapping), #417 (Task 8, accepted on task-8-profile-adoption), #419 (Task 9, accepted on task-9-terminal-lifecycle), #421 (Task 10, accepted on task-10-frame-bridge), #423 (Task 11, accepted on task-11-xterm-transport), #425 (Task 12, accepted on task-12-reattach-restore). Checkout base: #425 (task-12-reattach-restore). Open contract-gap issues #396–#401, docs gap #407, Task 6 event-apply gap #413, implemented Task 8/9 gaps #403/#416, and line-count trackers #400/#405/#408/#410/#412/#415/#418/#420/#422/#424/#426 do not block Linux Task 13. Live agent CLI parity remains #398 unless this task actually exercises a real agent against v0.9.0.
Work to complete
-
Project Herdr agent state onto mapped sessions
- Store
agent_status(raw Herdr string) and optional agent identity onProjectedPane. Seed both fromsession.snapshotpanes (andsnapshot.agentswhen it names the pane). Objects stay keyed bypane_id, never by display name. - Subscribe to
pane.agent_status_changedinSUBSCRIBE_TYPES. Apply it. Also apply already-subscribedpane.agent_detectedfor identity. Stale generations stayIgnoredStale. Unmapped panes (nofind_session_by_panerow in namespace2code) are ignored, not bound. - Keep
pane.output_matchedunsubscribed. Do not start applyingpane.exited/layout.updated/tab.moved(#413). - Drive this from the Herdr adapter that already has a JSON client. Do not call
ensure_herdr_listener/HerdrRuntimeSyncfrom Local default startup insrc-tauri/src/lib.rs.RuntimeRouter::newstays Local-default. - Bridge application DTOs to the GUI (thin
get_session_agent_statushydrate plus events or a Channel). Mappane_id→ 2code session id before emit. Do not put wire JSON (type, underscored event envelopes, Herdr agent records) in handler signatures ormodelIPC types. Runbun run typegen; do not editsrc/generated/by hand. - Ownership is
backend_for. A Local-owned id never receives Herdr agent updates. A Herdr-owned id with a missing/replaced pane fails closed (no badge, no Local detector fallback).
- Store
-
Map into existing badges and notifications
- Keep
AgentStatusasrunning|waiting, withidleclearing the record andcompletedremaining a viewed notification. Do not add Herdr strings to the store. - Mapping (verified
unknown; others documented by the pin/schema and #398, same vocabulary as localAgentSemanticState):unknown→ idle (no badge)working→runningblocked→waitingidle→ idledone→ idle; if the previous published status for that session wasrunning, set the existing completion notification- any other string → idle, no detector fallback, log once
- Reuse
setAgentStatus,shouldNotifyAgentWaiting/sendAgentWaitingNotification, waiting sound,AgentStatusDot, and sidebaruseProfileAgentStatus. Agent display name comes from Herdr identity when present; otherwise the existing generic title. - Unknown / reconnect: hydrate from the current projection on Herdr attach (Task 12 same session id). Seed the published previous status from the store so a still-
blockedpane does not re-notify or re-play the waiting sound. Snapshot replay after subscribe rebuild must not recreate a dismissed completion. - Viewed completions: keep dismiss-on-click.
done/idleafterrunningcreates completion once. Waiting → idle still does not create completion. - Duplicate notifications:
waitingonly on a true edge (previousStatus !== "waiting"), including GUI reconnect, stream reattach, and hidden-tab frame traffic. Tests must prove reconnect does not notify twice.
- Keep
-
Stop the local detector on Herdr terminals only
- In
Terminal.tsx, the Herdr transport path must not constructcreateAgentStatusDetector, schedule detection, or passscheduleAgentDetectionintoapplyHerdrFrameAction. Do not parse xterm screen, OSC title, or OSC progress for Herdr-owned ids. - Local-owned ids keep today’s detector, sound, and notification path unchanged.
- Running both detectors on one session is dual ownership of agent lifecycle — forbidden.
- Do not delete
src/features/terminal/detector/(Task 22). Do not call--takeover. Do not attach observe and control together.
- In
-
Prove with tests
- Projection: snapshot seeds
unknownas idle;working/blocked/done/idleevents update the mapped session; stale generation ignored; unmappedpane_idignored;pane.agent_status_changedis subscribed. - Frontend: Herdr-owned Terminal does not call the detector; Local-owned still publishes from title/screen fixtures (existing
Terminal.test.tsxwaiting-title case stays). - Notifications:
blocked→ waiting notifies once when unfocused; reconnect/hydrate of the same session id does not notify again;running→idle/donecreates completion once and does not recreate it after snapshot replay if dismissed. - Selector: Local-owned id never consumes Herdr agent IPC; Herdr-owned id never runs the detector and never falls back to Local PTY parsing.
RuntimeRouter::newstill selects Local. Existing Local PTY, Task 11 transport, and Task 12 reattach tests keep passing.- Optional live agent CLI probe: skip unless an explicit required flag and a real agent binary are present. Never target the user default Herdr session. Do not close #398 from fixtures or
pane.report_agentinjection alone. bun run lint:check,bun run typecheck,bun run test. If Rust changes:cargo test --workspacefromsrc-tauri(or--exclude codewhere GTK is unavailable). IPC changes usebun run typegen.
- Projection: snapshot seeds
Likely files and directories
- Update:
src-tauri/crates/service/src/runtime_sync.rs— pane agent fields, subscribepane.agent_status_changed, apply status/identity events - Update:
src-tauri/crates/service/src/runtime/herdr.rs,src-tauri/src/bridge.rs,src-tauri/src/handler/pty.rs— map pane → session, hydrate IPC, emit application DTOs; Local default startup unchanged - Update if needed:
src-tauri/crates/model/src/runtime.rs— application agent DTO only (no wire types);src-tauri/crates/repo/src/runtime_mapping.rsalready hasfind_session_by_pane - Update:
src/features/terminal/Terminal.tsx,src/features/terminal/Terminal.test.tsx,src/features/terminal/lib/agentNotification.ts/ tests,src/features/terminal/store.tsonly if reconnect/completion seeding needs a helper - Reuse, do not duplicate:
AgentStatusDot.tsx,TerminalTabs.tsx, sidebarProfileItem.tsx/ProjectMenuItem.tsx, Task 7 session↔pane mapping, Task 12 same-id reattach - Do not rewrite: Local PTY read loop, Task 10 CLI attach, Task 11 frame semantics,
detector/rules/(Task 22),docs/herdr-integration.md
Estimated changes: 200–400 lines total, additions plus deletions, including tests; excluding generated files and lockfile churn. Material scope growth should become a separate issue.
Acceptance criteria
- [ ] Herdr-owned sessions take agent badges, waiting notifications, waiting sound, and completion dots from projected Herdr
agent_status/ identity, keyed by persistedpane_id→ 2code session id.unknownis idle. - [ ] Documented
working/blocked/idle/donemap to existingrunning/waiting/ idle / completion behavior. Unrecognized statuses are idle with no detector fallback. - [ ] Herdr terminals do not run
createAgentStatusDetectoror parse xterm/OSC for lifecycle. Local-owned terminals still do. - [ ] Reattach and snapshot rebuild do not duplicate waiting notifications or recreate a dismissed completion for the same session id.
- [ ] Default runtime remains Local. Local PTY/agent path still works. No 2code session or worktree is owned by both backends. Agent updates are not started from Local default startup. Adapter choice uses per-session
backend_for. - [ ] Production UI does not call
pane.report_agent,pane.report_agent_session,agent.start,agent.prompt,pane.send_*,server.stop,--takeover, or a reimplementedherdr-client.sockprotocol. - [ ] Live CLI detection parity is not claimed (#398) unless a real agent was exercised against v0.9.0. Windows live attach is not claimed (#396). Detector deletion is not this task.
- [ ]
bun run lint:check,bun run typecheck, andbun run testpass. If Rust changes:cargo test --workspacefromsrc-tauri(or--exclude codewhere GTK is unavailable).bun run typegenfor IPC; do not editsrc/generated/by hand.
Out of scope
- Creating profiles through Herdr
worktree.create(Task 14) or routing worktree/project cleanup through Herdr (Task 15). - Git/editor path reconciliation (Task 16), startup-command mapping (Task 17 / #397), runtime health UI (Task 18), legacy-session migration (Task 19), or making Herdr the default (Task 21).
- Deleting
detector/(Task 22) or the local PTY runtime (Task 23). - Closing or implementing contract-gap issues #396–#401 except that this task may add fixture-only mapping for #398 without claiming live parity. Do not close #398 from fixtures or
pane.report_agentinjection. - Docs gap #407, Task 6 event-apply gap #413, implemented gaps #403/#416, or line-count trackers #400/#405/#408/#410/#412/#415/#418/#420/#422/#424/#426.
- Applying
pane.exited/layout.updated/tab.movedin the projection (#413). - Updating
docs/herdr-integration.md. - Changing Task 10 CLI attach, Task 11 frame/
full/seqsemantics, or Task 12 reattach/history policy. - Remote Herdr operation.
Standing constraints
- No default-runtime switch.
- Existing Local PTY/agent path stays working until the Herdr path passes acceptance.
- Never let both runtimes own the same terminal or worktree.