dsh-hive-runner 0.6.7 → 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:
@@ -43,6 +47,7 @@ Response:
43
47
  "waiting": null,
44
48
  "lastTickAt": "2026-12-04T00:00:00.000Z",
45
49
  "lastDiscoverError": null,
50
+ "pendingAnomalies": 0,
46
51
  "repos": [
47
52
  {
48
53
  "repo": "/abs/repo",
@@ -78,34 +83,40 @@ Response:
78
83
  "timeoutAt": "2026-12-04T00:15:03.000Z"
79
84
  }
80
85
  ],
81
- "limitsError": null
86
+ "limitsError": null,
87
+ "environmentError": null,
88
+ "mode": null,
89
+ "frozenSkipped": 0,
90
+ "lastSkipReason": null,
91
+ "gate": null
82
92
  }
83
93
  ]
84
94
  }
85
95
  ```
86
96
 
87
- - `roles[role].limit` — effective live-worker cap (persisted file > config >
97
+ - `roles[role].limit` — effective live-agent cap (persisted file > config >
88
98
  `defaultRoleConcurrency`).
89
- - `roles[role].live` — card workers running **now**; a completed worker frees
99
+ - `roles[role].live` — task agents running **now**; a completed agent frees
90
100
  its slot immediately.
91
- - `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
92
102
  against `live`).
93
103
  - `backlog` — aggregate `{ queued, inFlight, completed }` for the current or
94
104
  last drain.
95
- - `queenSessionId` — the queen conversation registered by the panel; every worker is
96
- parented to exactly this Session. `waiting` is `"no-queen-session"` until the
97
- registration arrives (startup-order hint, not an error); the supervisor never
98
- falls back to another Session. Workers/run records carry `parentSource: "queen"`.
99
- - `workers` — live workers in this repository: `cardId`, `role`, `agent`,
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`,
100
111
  `sessionId`, `agentName`, `startedAt`, `lastOutputAt`, `heartbeat`
101
112
  (`ok`/`warn`), `claimDeadline`, `timeoutAt`. The Session id is written into the
102
113
  `.hive/runs/<cardId>.json` record as soon as the activation is accepted.
103
114
  - `state` — `idle` | `running` | `backoff` | `paused`.
104
115
 
105
- Every card has a hard `cardTimeoutMs` deadline (default 15 min); when it expires
106
- the worker is aborted, the card is recorded failed and its announcements are released.
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.
107
118
  The claim TTL is observability only (`claimDeadline` in status) and never aborts a
108
- running card. While a worker runs, the repository HEAD is polled as the output signal;
119
+ running task. While an agent runs, the repository HEAD is polled as the output signal;
109
120
  no movement for `heartbeatWarnMs` marks `heartbeat: "warn"` in status/run record.
110
121
 
111
122
  ### `POST ?op=pause` / `POST ?op=resume`
@@ -133,13 +144,15 @@ Body:
133
144
 
134
145
  Body: `{ "sessionId": "<live queen Session id>" }`.
135
146
 
136
- - Registers the queen conversation that owns every worker. The panel calls this
147
+ - Registers the queen conversation that parents task agents. The panel calls this
137
148
  when its init/queen activation succeeds (or calls the `hiveSupervisor`
138
149
  service's `setQueenSession()` from the host side). Registration is in-memory;
139
150
  after a plugin restart the next panel access re-registers it.
140
151
  - Until registration the supervisor does not dispatch: `status` reports
141
152
  `waiting: "no-queen-session"` per repository and at the top level. This is a
142
- startup-order hint, not an error; the supervisor never picks another Session.
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.
143
156
  - Returns `{ ok: true, op: "queen", queenSessionId, waiting: null, repos: ... }`.
144
157
  - Missing `sessionId` -> `400` `hive/missing-session-id`; non-POST -> `405`.
145
158
  ## 3. Per-repository limits
@@ -164,29 +177,29 @@ reported in status). File shape:
164
177
 
165
178
  ## 4. Concurrency and capacity
166
179
 
167
- - Default behaviour: at most 5 **live** workers per role per repository.
168
- - Queued cards do not occupy a slot. A worker that finishes a card immediately
169
- 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.
170
183
  - `maxConcurrentRepos` (default 2) limits how many repositories may drain at the
171
184
  same time. A repository is always serial.
172
185
  - DSH's `subagent.maxActiveSubagents` is the hard ceiling below the plugin:
173
186
  `startActivation` can reject with `ACTIVATION_LIMIT_REACHED`. The queue
174
- treats that as a retry: the claimed card goes back to its role queue, the
175
- 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
176
189
  dropped.
177
- - 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.
178
191
 
179
192
  ## 5. Supervisor state machine
180
193
 
181
194
  ```text
182
- idle --tick, ready cards--> running --drain done--> idle (next tick in intervalMs)
183
- 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)
184
197
  running --drain exception--> backoff (intervalMs * 2^failures, capped idleBackoffMs)
185
198
  running --3 consecutive exceptions--> paused (auto; requires resume)
186
199
  paused --resume--> idle
187
200
  ```
188
201
 
189
- Card-level failures (no commit / acceptance failure / non-completed subagent)
202
+ Task-level failures (no commit / acceptance failure / non-completed subagent)
190
203
  are recorded in Hive as `fail` and do not count as round exceptions.
191
204
  Environmental errors (no live parent Agent, no subagent provider) are
192
205
  deferrable: they set `lastError` and back off for `idleBackoffMs` without
@@ -196,32 +209,65 @@ consuming the failure budget.
196
209
 
197
210
  | File | Responsibility |
198
211
  | --- | --- |
199
- | `index.js` | Cordis plugin entry: config, limits store, supervisor service/timer, Fetch route, tools |
200
- | `lib/supervisor.js` | Repository registry + state machine + per-repo queue/backlog/roles; exposes `setRoleLimits` |
201
- | `lib/queue.js` | Live-only per-role worker pools, immediate slot refill, capacity requeue, per-role state callback |
202
- | `lib/round.js` | One card end to end: claim → announcement/timeout guard (`hive guard` overlaps) + lesson read (`hive recall`) → subagent activation → commit/acceptance verify → done/fail + last-run record |
203
- | `lib/runs.js` | `<repo>/.hive/runs/<cardId>.json` last-run records: path validation, 200-line/32-KiB output truncation, optional worker `sessionId`/`agentName`, advisory `overlaps`, `lessons` read summary, 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 |
204
223
  | `lib/limits.js` | `<repo>/.hive/limits.json` read/write/hot-reload and precedence helpers |
205
- | `lib/config.js` | Config defaults/validation, role map parsing, effective-limit helpers |
206
- | `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 |
207
226
  | `lib/shell.js` | `ctx.shell.resolve/execute` adapter (sandbox policy per call) |
208
227
  | `lib/discover.js` | `refs/hive/v1` repository discovery |
209
- | `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) |
210
229
 
211
230
  ## 7. Security notes
212
231
 
213
- - 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
214
233
  shas are regex-validated, free text is POSIX-quoted before entering `bash -c`.
215
234
  - Agentless supervisor calls resolve the deployment sandbox policy and pin its
216
235
  workspace root to the target repository; tool-triggered calls use the calling
217
236
  session's policy.
218
- - Card `acceptance` is repository-controlled shell under the same policy: treat
237
+ - Task `acceptance` is repository-controlled shell under the same policy: treat
219
238
  the repository as trusted input.
220
239
 
221
240
  ## 8. Tests
222
241
 
223
- `node --test test/*.test.js`. Suites: supervisor state machine and limits
224
- persistence/hot reload, live-only role queue, single-card round paths (announcement
225
- overlaps, lesson reads, timeouts), config,
226
- HTTP protocol (including `op=limits` validation), discovery, command allowlist,
227
- 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.