shep

Agent activity (spec 149)

One answer to “is this feature working, blocked on me, or done, and why?”, for callers outside shep’s own UI: MCP clients, A2A orchestrators, scripts (shep feat status / shep feat wait) and terminal hosts such as Herdr.

The model

State Meaning From FeatureState
working An agent is executing running
blocked Someone must act: an approval gate, an agent question, a review action-required, or any working/waiting feature with an open agent question
waiting Not started: queued for a slot, deferred, or waiting on a parent queued, pending, blocked
done Finished, or archived done, archived, deleting
failed The run failed, was interrupted or cancelled, or its process died error

Every activity carries a reason (FeatureStateReason): the rule that decided it, such as approval-gate, agent-question, queued-for-capacity or process-died. The reason comes from explainFeatureState (domain/shared/feature-state.ts), which is the same derivation every surface uses (deriveFeatureState is its .state). So the activity can never disagree with the web canvas or shep tui. activityOf (domain/shared/agent-activity.ts) then folds the state into the five above. A gate keeps its own reason; an open agent question blocks a working or waiting feature with reason agent-question. A gate’s mirror question (spec 093) is not counted.

Each activity also has a version: the newest of the feature’s updatedAt, its run’s updatedAt and its open questions’ createdAt, in epoch ms. It survives restarts. Within one watch (MCP wait, A2A stream, shep feat wait) it strictly increases, because the watcher never emits a version at or below the last one it emitted. Between two separate reads it can drop once: answering an open question removes that question’s timestamp before anything else is written. A caller that polls should therefore compare the state as well as the version.

Enums live in tsp/common/enums/agent-activity.tsp: AgentActivityState, FeatureStateReason, ActivityWaitOutcome and FeatureReplyOutcome. All are derived and never stored, so there is no table and no migration.

Use cases (application/use-cases/agent-activity/)

Use case What it does
GetAgentActivityUseCase Activities projected from the console snapshot (one batched read, crashed runs reconciled), with counts and the overall state. Filter by feature id or prefix, or by repository. Done features are left out of a list unless includeSettled is set; a feature asked for by id is always returned
WatchAgentActivityUseCase Async generator: every activity first, then one change per feature whose state, reason, phase, run status or open question moved. Polls SQLite (1 s default) because feature workers are separate processes
WaitForAgentActivityUseCase Returns as soon as a feature reaches one of the given states (default blocked, done, failed), or timed-out / not-found / ambiguous / aborted
ReplyToFeatureUseCase Decides a gate (approve, or reject with feedback) through RunFeatureConsoleActionUseCase, answers the open question through AnswerAgentQuestionUseCase, or stops the run. Free text never decides a gate. Never throws
ReportHostActivityUseCase Tells the terminal host (IActivityHostReporter) the state, only when it changes; releases the pane on exit

Adapters

GetAgentActivity ── Watch ── WaitFor ── ReplyToFeature
      │                │         │            │
      ├── MCP tools (infrastructure/services/mcp/tools/agent-activity-tools.ts)
      ├── A2A JSON-RPC (infrastructure/services/a2a/, routes /api/a2a, /.well-known/agent-card.json)
      ├── CLI: shep feat status, shep feat wait
      ├── Web: GET /api/agent-activity, GET /api/agent-activity/wait
      └── shep tui ── ReportHostActivity ── IActivityHostReporter ── Herdr | no-op

Not covered