dsh-hive-runner 0.6.4 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/docs/DESIGN.md CHANGED
@@ -9,12 +9,13 @@ not describe transport details.
9
9
  | Surface | Registration | Purpose |
10
10
  | --- | --- | --- |
11
11
  | `HiveSupervisor` | `ctx.provide('hiveSupervisor', supervisor)` | Resident scheduler service |
12
- | Timer | `ctx.effect(() => { supervisor.start(); return () => supervisor.stop(); })` | Ticks while DSH runs, independent of browser tabs |
12
+ | Timer | `ctx.effect(() => { supervisor.start(); patrol.start(); return () => { patrol.stop(); supervisor.stop(); }; })` | Ticks + queen patrol while DSH runs, independent of browser tabs |
13
13
  | Fetch route | `ctx.connection.fetch.register({ path: '/api/hive-runner', methods: ['GET','POST'], requestBody: 'buffered', fetch })` | Same-origin control/observability |
14
- | Tools | `ctx.tools.register(defineTool(...))` | `hive_run_round`, `hive_tasks_ready`, `hive_board`, `hive_supervisor_status` |
14
+ | Tools | `ctx.tools.register(defineTool(...))` | `hive_run_round`, `hive_tasks_ready`, `hive_board`, `hive_supervisor_status`, `hive_tasks`, `hive_arch_review`, `hive_events`, `hive_lesson_add`, `hive_recall`, `hive_roles`, `hive_supervisor_control`, `hive_anomalies`, `hive_intervene` |
15
+ | Queen notifier | `agent.followup(createUserMessage(...))` on the registered queen Session | One anomaly digest per flush; pending list when no live Session |
15
16
 
16
- All shell work goes through `ctx.shell.resolve` + `ctx.shell.execute`; card
17
- workers are DSH subagents via `ctx.subagents.startActivation`. No
17
+ All shell work goes through `ctx.shell.resolve` + `ctx.shell.execute`; task
18
+ agents are DSH subagents via `ctx.subagents.startActivation`. No
18
19
  `node:child_process` anywhere (architecture test enforces this).
19
20
 
20
21
  ## 2. HTTP protocol
@@ -22,6 +23,9 @@ workers are DSH subagents via `ctx.subagents.startActivation`. No
22
23
  Path: `/api/hive-runner`. JSON request/response. Unknown `op` → `400`;
23
24
  missing `repo` → `400`; unknown `repo` → `404`.
24
25
 
26
+ Ops: `GET status`, `GET pending[&all=1]`, `POST ack {ids}`, `POST pause`,
27
+ `POST resume`, `POST limits`, `POST queen`.
28
+
25
29
  ### `GET ?op=status`
26
30
 
27
31
  Response:
@@ -39,8 +43,11 @@ Response:
39
43
  "repoRoleConcurrency": {},
40
44
  "defaultRoleConcurrency": 5,
41
45
  "capacityRetryMs": 2000,
46
+ "queenSessionId": "queen-session-id",
47
+ "waiting": null,
42
48
  "lastTickAt": "2026-12-04T00:00:00.000Z",
43
49
  "lastDiscoverError": null,
50
+ "pendingAnomalies": 0,
44
51
  "repos": [
45
52
  {
46
53
  "repo": "/abs/repo",
@@ -56,27 +63,62 @@ Response:
56
63
  "consecutiveFailures": 0,
57
64
  "lastCards": 0,
58
65
  "lastResults": 0,
66
+ "waiting": null,
59
67
  "backlog": { "queued": 3, "inFlight": 5, "completed": 12 },
60
68
  "roles": {
61
69
  "coder": { "limit": 5, "live": 5, "queued": 3 },
62
70
  "tester": { "limit": 5, "live": 0, "queued": 0 }
63
71
  },
64
- "limitsError": null
72
+ "workers": [
73
+ {
74
+ "cardId": "readme-89ab",
75
+ "role": "coder",
76
+ "agent": "dsh",
77
+ "sessionId": "session-id",
78
+ "agentName": "agent-1",
79
+ "startedAt": "2026-12-04T00:00:03.000Z",
80
+ "lastOutputAt": "2026-12-04T00:02:00.000Z",
81
+ "heartbeat": "ok",
82
+ "claimDeadline": "2026-12-04T00:05:03.000Z",
83
+ "timeoutAt": "2026-12-04T00:15:03.000Z"
84
+ }
85
+ ],
86
+ "limitsError": null,
87
+ "environmentError": null,
88
+ "mode": null,
89
+ "frozenSkipped": 0,
90
+ "lastSkipReason": null,
91
+ "gate": null
65
92
  }
66
93
  ]
67
94
  }
68
95
  ```
69
96
 
70
- - `roles[role].limit` — effective live-worker cap (persisted file > config >
97
+ - `roles[role].limit` — effective live-agent cap (persisted file > config >
71
98
  `defaultRoleConcurrency`).
72
- - `roles[role].live` — card workers running **now**; a completed worker frees
99
+ - `roles[role].live` — task agents running **now**; a completed agent frees
73
100
  its slot immediately.
74
- - `roles[role].queued` — fetched cards waiting for a slot (they do not count
101
+ - `roles[role].queued` — fetched tasks waiting for a slot (they do not count
75
102
  against `live`).
76
103
  - `backlog` — aggregate `{ queued, inFlight, completed }` for the current or
77
104
  last drain.
105
+ - `queenSessionId` — the queen conversation registered by the panel; agents are
106
+ parented to that Session while its Agent is live. `waiting` is
107
+ `"no-queen-session"` until the registration arrives (startup-order hint, not an
108
+ error); the registration is only replaced by a new registration. Status workers and
109
+ run records carry `parentSource: "queen"` when the registered Session parented them.
110
+ - `workers` — live agents in this repository: `cardId`, `role`, `agent`,
111
+ `sessionId`, `agentName`, `startedAt`, `lastOutputAt`, `heartbeat`
112
+ (`ok`/`warn`), `claimDeadline`, `timeoutAt`. The Session id is written into the
113
+ `.hive/runs/<cardId>.json` record as soon as the activation is accepted.
78
114
  - `state` — `idle` | `running` | `backoff` | `paused`.
79
115
 
116
+ Every task has a hard `cardTimeoutMs` deadline (default 15 min); when it expires
117
+ the agent is aborted, the task is recorded failed and its announcements are released.
118
+ The claim TTL is observability only (`claimDeadline` in status) and never aborts a
119
+ running task. While an agent runs, the repository HEAD is polled as the output signal;
120
+ no movement for `heartbeatWarnMs` marks `heartbeat: "warn"` in status/run record.
121
+
80
122
  ### `POST ?op=pause` / `POST ?op=resume`
81
123
 
82
124
  Body or query: `{ "repo": "/abs/repo" }`. Returns
@@ -98,6 +140,21 @@ Body:
98
140
  - Malformed values → `400` `hive/invalid-role-limits`; non-POST → `405`
99
141
  `hive/method-not-allowed`; unknown repo → `404`.
100
142
 
143
+ ### `POST ?op=queen`
144
+
145
+ Body: `{ "sessionId": "<live queen Session id>" }`.
146
+
147
+ - Registers the queen conversation that parents task agents. The panel calls this
148
+ when its init/queen activation succeeds (or calls the `hiveSupervisor`
149
+ service's `setQueenSession()` from the host side). Registration is in-memory;
150
+ after a plugin restart the next panel access re-registers it.
151
+ - Until registration the supervisor does not dispatch: `status` reports
152
+ `waiting: "no-queen-session"` per repository and at the top level. This is a
153
+ startup-order hint, not an error. While registered, its live Agent is the parent;
154
+ if it cannot be resolved the round falls back to `parentSession` / the first live
155
+ Agent, and defers with `hive/no-parent-agent` when no Agent is live.
156
+ - Returns `{ ok: true, op: "queen", queenSessionId, waiting: null, repos: ... }`.
157
+ - Missing `sessionId` -> `400` `hive/missing-session-id`; non-POST -> `405`.
101
158
  ## 3. Per-repository limits
102
159
 
103
160
  Precedence for one role in one repository:
@@ -120,29 +177,29 @@ reported in status). File shape:
120
177
 
121
178
  ## 4. Concurrency and capacity
122
179
 
123
- - Default behaviour: at most 5 **live** workers per role per repository.
124
- - Queued cards do not occupy a slot. A worker that finishes a card immediately
125
- takes the next queued card of the same role.
180
+ - Default behaviour: at most 5 **live** agents per role per repository.
181
+ - Queued tasks do not use a slot. An agent that finishes a task immediately takes the
182
+ next queued task of the same role.
126
183
  - `maxConcurrentRepos` (default 2) limits how many repositories may drain at the
127
184
  same time. A repository is always serial.
128
185
  - DSH's `subagent.maxActiveSubagents` is the hard ceiling below the plugin:
129
186
  `startActivation` can reject with `ACTIVATION_LIMIT_REACHED`. The queue
130
- treats that as a retry: the claimed card goes back to its role queue, the
131
- worker waits `capacityRetryMs` (default 2000), and retries. Nothing is
187
+ treats that as a retry: the claimed task goes back to its role queue, the
188
+ agent waits `capacityRetryMs` (default 2000), and retries. Nothing is
132
189
  dropped.
133
- - A role limit of `0` leaves its ready cards untouched on the Hive board.
190
+ - A role limit of `0` leaves its ready tasks untouched on the Hive board.
134
191
 
135
192
  ## 5. Supervisor state machine
136
193
 
137
194
  ```text
138
- idle --tick, ready cards--> running --drain done--> idle (next tick in intervalMs)
139
- idle --tick, no cards--> backoff (idleBackoffMs 120s)
195
+ idle --tick, ready tasks--> running --drain done--> idle (next tick in intervalMs)
196
+ idle --tick, no tasks--> backoff (idleBackoffMs 120s)
140
197
  running --drain exception--> backoff (intervalMs * 2^failures, capped idleBackoffMs)
141
198
  running --3 consecutive exceptions--> paused (auto; requires resume)
142
199
  paused --resume--> idle
143
200
  ```
144
201
 
145
- Card-level failures (no commit / acceptance failure / non-completed subagent)
202
+ Task-level failures (no commit / acceptance failure / non-completed subagent)
146
203
  are recorded in Hive as `fail` and do not count as round exceptions.
147
204
  Environmental errors (no live parent Agent, no subagent provider) are
148
205
  deferrable: they set `lastError` and back off for `idleBackoffMs` without
@@ -152,31 +209,65 @@ consuming the failure budget.
152
209
 
153
210
  | File | Responsibility |
154
211
  | --- | --- |
155
- | `index.js` | Cordis plugin entry: config, limits store, supervisor service/timer, Fetch route, tools |
156
- | `lib/supervisor.js` | Repository registry + state machine + per-repo queue/backlog/roles; exposes `setRoleLimits` |
157
- | `lib/queue.js` | Live-only per-role worker pools, immediate slot refill, capacity requeue, per-role state callback |
158
- | `lib/round.js` | One card end to end: claim → subagent activation → commit/acceptance verify → done/fail + last-run record |
159
- | `lib/runs.js` | `<repo>/.hive/runs/<cardId>.json` last-run records: path validation, 200-line/32-KiB output truncation, optional worker `sessionId`/`agentName`, best-effort write |
212
+ | `index.js` | Cordis plugin entry: config, limits store, supervisor service/timers, Fetch route, queen tools, anomaly feed + notifier + patrol wiring |
213
+ | `lib/supervisor.js` | Repository registry + state machine + per-repo queue/backlog/roles; emits supervision anomalies; exposes pause/resume/setRoleLimits/status (with pendingAnomalies) |
214
+ | `lib/queue.js` | Live-only per-role agent pools, immediate slot refill, capacity requeue, per-role state callback |
215
+ | `lib/round.js` | One task end to end: claim → announcement/timeout guard (`hive guard` overlaps) + lesson read (`hive recall`) → subagent activation → commit/acceptance verify → done/fail + last-run record; emits task anomalies |
216
+ | `lib/runs.js` | `<repo>/.hive/runs/<cardId>.json` last-run records: path validation, 200-line/32-KiB output truncation, optional agent identity, advisory `overlaps`, `lessons` summary, best-effort write and `readRunRecord` for the queen |
217
+ | `lib/anomalies.js` | Supervision anomaly feed: coalescing per (kind, repo, task id), bounded queue, pending/delivered state, compact digest |
218
+ | `lib/notify.js` | Queen message injection: resolve the live Agent for the registered Session and deliver one identified user-role message (followup/steer/inject) |
219
+ | `lib/patrol.js` | 5-minute queen patrol: run the optional audit hook, scan supervisor status for auto-pause/environment/heartbeat/timeout anomalies, flush one digest, stay silent when healthy |
220
+ | `lib/gates.js` | Gate pipeline: tag classification (`gate:group`, `gate:overall`), phase computation (base -> group -> overall -> released/no-overall), release readiness and dispatch filtering |
221
+ | `lib/audit.js` | Patrol audit: done tasks without an `arch_review` event become `arch-review-missing` anomalies; more than three `queen_intervention` events on one stuck task write `queen_escalation` and raise the red-flag anomaly |
222
+ | `lib/events.js` | `.hive/events.jsonl` append/read plus the `arch_review`, `queen_intervention` and `queen_escalation` event contracts |
160
223
  | `lib/limits.js` | `<repo>/.hive/limits.json` read/write/hot-reload and precedence helpers |
161
- | `lib/config.js` | Config defaults/validation, role map parsing, effective-limit helpers |
162
- | `lib/commands.js` | Allowlisted `hive-tasks` / `git` / acceptance commands with shell quoting |
224
+ | `lib/config.js` | Config defaults/validation (`patrolMs`, `notifyQueen`, `anomaly*`, `rolesBin`), role map parsing, effective-limit helpers |
225
+ | `lib/commands.js` | Allowlisted `hive-tasks` / `hive` / `git` / acceptance commands with shell quoting; queen verbs list/add/reopen/retry/rm/lesson/roles |
163
226
  | `lib/shell.js` | `ctx.shell.resolve/execute` adapter (sandbox policy per call) |
164
227
  | `lib/discover.js` | `refs/hive/v1` repository discovery |
165
- | `lib/http.js` | `/api/hive-runner` Fetch route (status/pause/resume/limits) |
228
+ | `lib/http.js` | `/api/hive-runner` Fetch route (status/pending/ack/pause/resume/limits/queen) |
166
229
 
167
230
  ## 7. Security notes
168
231
 
169
- - Commands are built from fixed templates; card ids, roles, agents, TTLs and
232
+ - Commands are built from fixed templates; task ids, roles, agents, TTLs and
170
233
  shas are regex-validated, free text is POSIX-quoted before entering `bash -c`.
171
234
  - Agentless supervisor calls resolve the deployment sandbox policy and pin its
172
235
  workspace root to the target repository; tool-triggered calls use the calling
173
236
  session's policy.
174
- - Card `acceptance` is repository-controlled shell under the same policy: treat
237
+ - Task `acceptance` is repository-controlled shell under the same policy: treat
175
238
  the repository as trusted input.
176
239
 
177
240
  ## 8. Tests
178
241
 
179
- `node --test test/*.test.js`. Suites: supervisor state machine and limits
180
- persistence/hot reload, live-only role queue, single-card round paths, config,
181
- HTTP protocol (including `op=limits` validation), discovery, command allowlist,
182
- and an architecture guard (no child processes; README protocol hygiene).
242
+ `node --test test/*.test.js`. Suites: supervisor state machine, limits
243
+ persistence/hot reload, live-only role queue, single-task round paths (announcement
244
+ overlaps, lesson reads, timeouts, emitted anomalies), the anomaly feed/patrol/notifier
245
+ pipeline, arch-review event log, config, HTTP protocol (including `op=limits` and
246
+ `op=pending`/`op=ack` validation), discovery, the command allowlist (including the
247
+ queen's task/role/lesson verbs), and an architecture guard (no child processes; README
248
+ protocol hygiene).
249
+
250
+ ## 9. Queen coordination
251
+
252
+ The runner treats the registered queen Session as a coordinator: it gets tools to
253
+ order/split/triage tasks, throttle the swarm, record architecture reviews and read
254
+ lessons, and the supervisor feeds it anomalies. The design constraints:
255
+
256
+ - **No board mutation from the supervisor for task decisions**: the supervisor runs
257
+ tasks; the queen decides reopen/retry/add/rm/pause/limits. The two never claim the
258
+ same task.
259
+ - **One digest, only on anomalies**: events coalesce and debounce; a healthy swarm
260
+ sends nothing. The patrol exists to catch what the event path missed, not to poll
261
+ the model.
262
+ - **Delivery through the public Agent inbox** (DSH 0.2.2-rc.5): `followup` queues an
263
+ ordinary next turn and wakes the driver, `steer` targets the next step, `inject`
264
+ adds context without waking. The message is an identified user message with
265
+ `source.kind = "hive-runner"`; the session log validates any non-empty source kind,
266
+ so no new event type is introduced and replay stays safe.
267
+ - **Pending fallback**: every undelivered entry stays in memory and is exposed by
268
+ `hive_anomalies` / `GET ?op=pending`; the next queen registration or patrol flushes
269
+ it. This is the documented degradation path when no Session is live.
270
+
271
+ The queen must not edit code or commit: delivery is prompt-level coordination, and
272
+ the `hive_arch_review` tool only appends an event. Hard enforcement would be a DSH
273
+ `ctx.tools.restrict` decision outside this plugin.