dsh-hive-runner 0.6.7 → 0.8.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/README.md CHANGED
@@ -4,9 +4,9 @@
4
4
 
5
5
  **English** · [简体中文](README.zh-CN.md)
6
6
 
7
- **A resident Hive supervisor inside DSH.** While DSH is open it keeps taking ready task
8
- cards for your repositories and runs one DSH subagent ("bee") per card, inside the
9
- per-role worker limits you set in the Hive panel.
7
+ **A resident Hive supervisor inside DSH.** While DSH is open it keeps taking ready tasks
8
+ for your repositories and runs one DSH subagent per task, inside the per-role
9
+ agent limits you set in the Hive panel.
10
10
 
11
11
  [![CI](https://img.shields.io/github/actions/workflow/status/d86e/dsh-hive-runner/ci.yml?style=for-the-badge&logo=github)](https://github.com/d86e/dsh-hive-runner/actions)
12
12
  [![npm](https://img.shields.io/npm/v/dsh-hive-runner?style=for-the-badge&logo=npm&color=cb3837)](https://www.npmjs.com/package/dsh-hive-runner)
@@ -17,78 +17,276 @@ per-role worker limits you set in the Hive panel.
17
17
 
18
18
  ---
19
19
 
20
- [Hive](https://github.com/d86e/hive) coordinates a swarm of coding agents inside git: task
21
- cards with acceptance commands, path announcements, a presence board and a commit-time
20
+ [Hive](https://github.com/d86e/hive) coordinates a swarm of coding agents inside git:
21
+ tasks with acceptance commands, path announcements, a presence board and a commit-time
22
22
  merge, all stored as refs and files in the repository itself. The
23
23
  [hive-runner](https://github.com/d86e/hive-runner) CLI runs **one** round and exits.
24
24
 
25
25
  **dsh-hive-runner** makes that loop resident inside DSH. It runs a supervisor in the DSH
26
26
  host process — not in the browser tab — so closing the panel or the window does not stop
27
- it; it keeps working as long as DSH is running. Workers are DSH subagents, and every shell
27
+ it; it keeps working as long as DSH is running. Agents are DSH subagents, and every shell
28
28
  call goes through DSH's own shell seam, so the work stays inside the deployment sandbox:
29
29
  the plugin never spawns processes outside the harness.
30
30
 
31
31
  ## What it does
32
32
 
33
- - For every configured repository it reads the ready task cards and dispatches one worker
34
- subagent per card.
35
- - **Only live workers occupy a slot.** A card waiting for a slot is not counted; when a
36
- worker finishes its card the slot is freed immediately and the next waiting card of the
37
- same role starts.
38
- - Each role has its own limit. The default is **5 live workers per role** for roles that
33
+ - For every configured repository it reads the ready tasks and dispatches one DSH
34
+ subagent per task.
35
+ - **Only running agents count against a slot.** A task waiting for a slot is not
36
+ counted; when an agent finishes its task the slot is freed immediately and the next
37
+ waiting task of the same role starts.
38
+ - Each role has its own limit. The default is **5 live agents per role** for roles that
39
39
  are not configured.
40
- - **0 pauses a role**: its ready cards stay on the Hive board and are not dispatched.
40
+ - **0 pauses a role**: its ready tasks stay on the Hive board and are not dispatched.
41
41
  - A repository is always processed one drain at a time; different repositories can run in
42
42
  parallel (2 by default).
43
- - A card that produces no commit, fails its acceptance command, or whose worker stops
43
+ - A task that produces no commit, fails its acceptance command, or whose agent stops
44
44
  early is recorded as failed in Hive; the rest of the queue continues.
45
45
  - If a repository keeps failing, it backs off and is auto-paused after three consecutive
46
46
  failures. Paused repositories never resume by themselves.
47
- - Workers follow the Hive consensus announcement protocol: before a worker starts, the
48
- supervisor announces the card's scope with `hive guard` (every scope entry, including
47
+ - Agents follow the Hive consensus announcement protocol: before an agent starts, the
48
+ supervisor announces the task's scope with `hive guard` (every scope entry, including
49
49
  `resource:` keys) and clears those announcements afterwards. An overlap with another
50
- agent's announcement is advisory only: the worker keeps working, and merge-on-commit
50
+ agent's announcement is advisory only: the agent keeps working, and merge-on-commit
51
51
  three-way merges the concurrent edits at commit time (unresolved conflicts stay as
52
52
  markers).
53
- - Lessons are read before every card and written after it: the supervisor runs
53
+ - Lessons are read before every task and written after it: the supervisor runs
54
54
  `hive recall` for every scope path plus the repository root and injects the
55
- deduplicated matches at the top of the worker prompt; workers record genuinely new
55
+ deduplicated matches at the top of the agent prompt; agents record genuinely new
56
56
  knowledge with `hive lesson add`. Writing a lesson and reading it at the start of the
57
- next card are a pair — one without the other does not compound.
57
+ next task are a pair — one without the other does not compound.
58
58
  - Commits are verified against merge-on-commit: the repository must have the
59
- merge-on-commit pre-commit hook (`hive init` installs it), and a card only counts as
59
+ merge-on-commit pre-commit hook (`hive init` installs it), and a task only counts as
60
60
  done when HEAD moved through that hook.
61
- - While the repository is in Hive freeze mode, non-fix cards stay on the board instead of
61
+ - While the repository is in Hive freeze mode, non-fix tasks stay on the board instead of
62
62
  failing.
63
63
 
64
- ## Worker sessions
64
+ ## Agent sessions
65
65
 
66
- Workers run in the **queen conversation**: the Session where you opened the Hive panel
67
- and finished `hive init` (or where the queen took over). The panel registers that
68
- Session with the supervisor, and from then on every card worker is parented to it — the
69
- workers show up as subagents in that same conversation, so you can open them from your
70
- own session.
66
+ Agents run in the **queen conversation**: the Session where you opened the Hive panel
67
+ and finished `hive init` (or where the queen took over — the panel's queen mode,
68
+ `autoQueen`, does this automatically for an initialised repository, and `/queen on` /
69
+ `/queen off` control it). The panel registers that Session with the supervisor, and from
70
+ then on each task's agent is parented to it — the agents show up as subagents in that
71
+ same conversation, so you can open them from your own session.
71
72
 
72
73
  - Nothing is dispatched before the queen Session is registered: status reports
73
74
  `waiting: no-queen-session`, a startup-order hint rather than an error.
74
- - The supervisor keeps using exactly that registered Session; it never switches to a
75
- different chat.
75
+ - The registration lives in plugin memory and is never replaced by another chat; after a
76
+ plugin restart the panel registers the same Session again on its next access.
76
77
  - Once registered, dispatch works with zero other user sessions and keeps running when
77
78
  the panel/UI is closed.
78
79
 
80
+ ## The queen as coordinator
81
+
82
+ Since 0.7 the registered queen Session is a **coordinator, supervisor and reviewer**, not
83
+ only a task splitter. The runner gives her the actions below and feeds her the anomalies
84
+ she must act on. The authoritative contract is `<repo>/.hive/roles/queen.md` (written by
85
+ `hive init`) plus the `hive-queen` skill; this section documents the host behaviour.
86
+
87
+ ### Her actions
88
+
89
+ | Tool | What the queen uses it for |
90
+ | --- | --- |
91
+ | `hive_board`, `hive_tasks_ready` | who is doing what, what is ready now |
92
+ | `hive_tasks` | `list`/`show` (task + last-run record: output tail, heartbeat, overlaps) and `add`/`edit`/`split`/`supersede`/`reopen`/`retry`/`rm` for goal evolution, ordering, splitting and remediation |
93
+ | `hive_arch_review` | record the architecture review of an accepted (done) task: appends a durable `arch_review` event `{ kind, task, verdict, findings }` to `.hive/events.jsonl` |
94
+ | `hive_events` | read the event tail (for example every `arch_review` still missing) |
95
+ | `hive_lesson_add`, `hive_recall` | knowledge management: read before planning, write after an episode |
96
+ | `hive_roles` | `list`/`add`/`rm` roles in `.hive/roles.yaml` |
97
+ | `hive_supervisor_status`, `hive_supervisor_control` | status; `pause`/`resume` a repository and `limits` (per-role agent caps) to throttle the swarm |
98
+ | `hive_anomalies` | `list`/`ack` the pending anomaly digest, `patrol` runs one audit tick now |
99
+ | `hive_intervene` | act on a stuck task (reopen/split/reassign/remove/rebuild/pause/fail/guide/escalate) and record it as an event |
100
+ | `hive_run_round` | run one round on demand (a registered queen Session is required) |
101
+
102
+ The tool surface keeps the boundary: none of the queen's tools claims or finishes a task
103
+ (`hive-tasks claim` / `done` belong to agents and the supervisor), and none edits or
104
+ commits code. The queen contract forbids code edits; task metadata
105
+ (add/reopen/retry/rm), roles and lessons are coordination state, not code.
106
+
107
+ ### When the queen hears from the supervisor
108
+
109
+ The runner turns supervision events — `card-failed`, `card-timeout`,
110
+ `heartbeat-warn`, `worker-aborted`, `round-failed`, `auto-paused`,
111
+ `environment-error` — into one compact digest and **injects it into the queen
112
+ conversation** through DSH's public Agent inbox:
113
+
114
+ ```text
115
+ agent.followup({ id, role: 'user', content: [{ type: 'text', text: digest }],
116
+ source: { kind: 'hive-runner' } })
117
+ ```
118
+
119
+ (`followup` queues an ordinary next turn and wakes the queen; `steer`/`inject` are
120
+ fallbacks. The user-role message with a plugin source kind passes the session-log
121
+ contract, so no DSH change is needed.) Duplicate events coalesce per
122
+ `(kind, repo, task)` (coalesced on the task id) in a ten-minute window and task events debounce for three seconds,
123
+ so a noisy minute becomes **one** message, not ten.
124
+
125
+ Two guarantees keep this quiet:
126
+
127
+ - **Only anomalies are delivered.** A healthy swarm produces no message at all; the
128
+ periodical **patrol** (`patrolMs`, default 5 minutes) re-reads the supervisor status,
129
+ reports auto-paused repositories, environment errors, stalled heartbeats and agents
130
+ past their deadline, and delivers only when something is pending.
131
+ - **Nothing is lost when no queen is live.** If the panel is closed or the Session is
132
+ gone the digest stays in the pending list: `hive_anomalies` lists and acknowledges it,
133
+ `hive_supervisor_status` reports `pendingAnomalies`, and the next registered queen
134
+ Session flushes the queue. `notifyQueen: false` keeps the pending list only.
135
+
136
+ ### The gates the queen orchestrates
137
+
138
+ 1. **Single task**: the agent commits and the task acceptance command must pass.
139
+ 2. **Architecture review**: the queen reviews every accepted task (batched at the next
140
+ patrol is fine) against directory/module boundaries, dependency direction, naming,
141
+ duplicated capabilities, error handling, docs/ADR updates, consistency with existing
142
+ patterns and test coverage; `pass` is recorded as an `arch_review` event,
143
+ `reject` reopens the task with a reason and spawns one or more fine-grained fix tasks.
144
+ 3. **Functional-group tests**: after a related set of tasks (one functional unit) lands,
145
+ she dispatches module-level integration test tasks.
146
+ 4. **Overall tests**: before release/delivery, separate tasks for smoke, end-to-end,
147
+ regression, performance, compatibility/cross-platform, security, and docs/examples
148
+ consistency — each with an executable acceptance command.
149
+ 5. **Release**: only after every gate is green; a failure at any gate becomes fix tasks
150
+ plus `after` links, never a silent retry.
151
+
152
+ ### Gate labels and release readiness
153
+
154
+ The gate order is mechanical, not just prose. Two labels turn the board into a
155
+ pipeline, and the supervisor refuses to dispatch a gate before the previous one is
156
+ all green:
157
+
158
+ | Tag | Tasks | Dispatches when |
159
+ | --- | --- | --- |
160
+ | (none) | ordinary work tasks | always |
161
+ | `gate:group` | module / functional-group integration tests | every base task is `done` |
162
+ | `gate:overall` | overall tests (smoke, e2e, regression, performance, compatibility, security, docs) | every `gate:group` task is `done` |
163
+
164
+ A phase is "all green" only when every task in it is `done`: a `failed` or `claimed`
165
+ task keeps the next gate closed, so the queen has to reopen/remove/fix it. This is a
166
+ tag plus ordinary dependencies — the four task states are unchanged. Status exposes the
167
+ computed `gate` per repository:
168
+
169
+ ```json
170
+ "gate": { "phase": "base|group|overall|released|no-overall|unknown",
171
+ "base": { "total": 3, "done": 1, "outstanding": 2, "failed": 0 },
172
+ "group": { ... }, "overall": { ... },
173
+ "releaseReady": false, "reason": "waiting for 2 base tasks to finish" }
174
+ ```
175
+
176
+ `releaseReady` is true only when an overall gate task exists and every gate is green —
177
+ the fact a release must be checked against. A repository with no `gate:overall` task
178
+ reports `phase: "no-overall"` and cannot be released.
179
+
180
+ ### Interventions on stuck tasks
181
+
182
+ The queen acts, not just reports. `hive_intervene` performs one action **and** records a
183
+ durable `queen_intervention` event `{ kind, task, action, reason, newCards?, removed? }`
184
+ in `.hive/events.jsonl`:
185
+
186
+ | Action | When | What happens |
187
+ | --- | --- | --- |
188
+ | `reopen` | the implementation path was wrong; the task itself is fine | reopens the task with the guidance in its `reason` — the next agent prompt opens with `## Queen guidance for this attempt`, so the diagnosis is the main guidance channel |
189
+ | `split` | the task is too coarse | creates fine-grained tasks (each needs `acceptance`), reopens the original with the new ids |
190
+ | `reassign` | the role/implementation route is wrong | creates tasks for another role, reopens the original |
191
+ | `remove` | the task content has no value or repeats are meaningless | deletes the task, but records its title/state/scope in the event first — nothing disappears silently |
192
+ | `rebuild` | title/scope/acceptance/dependencies were wrong | deletes and recreates it (new tasks reference the old id in `reason`/`after`); allowed at most twice per task |
193
+ | `pause` | the cause is environmental (missing external dependency) | pauses dispatch for the repository; status carries the reason |
194
+ | `fail` | no solution exists | only confirms a task an agent already failed (the queen never changes a task state) and records why |
195
+ | `guide` | an agent is live and a nudge helps | delivers the guidance message to that agent Session (optional path; the reopen reason remains the main channel) |
196
+ | `escalate` | a human must decide | records the escalation; after more than **3** interventions on one task the runner also writes a `queen_escalation` event and raises the error-severity `queen-escalation` anomaly (the red flag) |
197
+
198
+ Every action requires a reason with evidence. A reopen writes the guidance into the task's
199
+ reason, so the panel's task drawer shows it and the next agent prompt opens with it; the
200
+ events tail (`hive_events` / the panel's event list) shows every intervention and, for a
201
+ deletion, the removed task's summary.
202
+
203
+ ### Goal evolution and task lifecycle
204
+
205
+ The human's messages are the primary input. Every turn, classify the message before acting:
206
+ is this a goal change — **add / modify / delete / narrow / widen**? Say the interpretation out
207
+ loud ("this narrows the goal to X") and only then act. The queen does not change the goal
208
+ silently, and a change to the goal itself goes to the human — but inside the confirmed goal
209
+ frame she decides autonomously and reports afterwards.
210
+
211
+ **Autonomy.** The queen decides on her own: splitting, editing task details, splitting/removing
212
+ cards, ordering, pausing/resuming, retrying, arch-review reject, superseding. She reports
213
+ "what changed and why" after the fact instead of asking for permission in advance. Only four
214
+ things go to the human: (1) the goal itself changed, or is too ambiguous to judge the scope;
215
+ (2) two requirements conflict with no self-consistent trade-off; (3) an irreversible or
216
+ high-cost action (release, repo-level data deletion, external publication); (4) the same task
217
+ was handled three times without progress.
218
+
219
+ The task tree is a living structure, not a one-shot plan:
220
+
221
+ - **edit** — `hive_tasks action=edit` partially updates a pending/failed task: title,
222
+ role, priority, acceptance, scope (replace: the runner translates it to scope add/remove),
223
+ dependencies (replace), tags and the superseded flag. Goal and draft cannot be edited; the
224
+ CLI refuses claimed/done tasks (reopen first).
225
+ - **split** — `hive_tasks action=split` atomically replaces one task with **at least two**
226
+ fine-grained tasks (each with its own acceptance or the parent's) and marks the original
227
+ superseded in the same transaction (`replacedBy` = first child), without changing its
228
+ state. Each child may override role/scope/acceptance/after; priority and tags are inherited.
229
+ - **supersede** — `hive_tasks action=supersede` marks a task as superseded **without changing
230
+ its state** (a reason is required), so a claimed/running task can be marked and allowed to
231
+ finish; it is never dispatched again and never gates the pipeline.
232
+ - **rm** — `hive_tasks action=rm` deletes a card whose content has no value; the queen records
233
+ an intervention event with the card summary first, so the deletion is visible in the history.
234
+
235
+ Decomposition is continuous: plan only what can be determined now, and add/edit/split cards as
236
+ later messages and discoveries arrive. Every change also evaluates its impact:
237
+
238
+ | Situation | Queen action |
239
+ | --- | --- |
240
+ | an affected card is running | `hive_intervene action=pause` (stop new dispatch for the repo) or `action=abort` (stop that worker now; the card is recorded failed with the reason), or let it finish and `action=supersede` it |
241
+ | an affected card is claimed but waiting | `hive_tasks action=edit` (priority/after) or `supersede`, then reopen/rebuild as needed |
242
+ | a done card was overturned | reopen it (with guidance) or add a fine-grained correction card linked with `after` |
243
+ | a dependency disappeared | edit the dependents' `after` list, or split them again |
244
+
245
+ Events make the history auditable: hive-tasks writes `task_edit`, `task_split` and
246
+ `task_supersede` to `.hive/events.jsonl`; the runner writes `queen_intervention
247
+ { card, action, reason }` for the queen's decisions. Every report states **what changed, why,
248
+ and which cards were affected**.
249
+
250
+ ### Architecture review is audited
251
+
252
+ A `done` task must carry an `arch_review` event. Every patrol checks the board; a done
253
+ task with no review older than `archReviewGraceMs` (10 minutes) becomes an
254
+ `arch-review-missing` anomaly, is logged as a warning and appears in the queen's pending
255
+ digest. The queen reviews at the next patrol (batched) through
256
+ `hive_arch_review { card, verdict: pass|reject, findings[] }`, which appends an
257
+ `arch_review` event `{ kind, task, verdict, findings }`; a reject reopens the task and
258
+ spawns fine-grained fix tasks.
259
+
260
+ The queen contract's same-class rule: a third occurrence of one problem (three rejected
261
+ reviews of the same kind, three identical failures) is promoted to a convention —
262
+ written to `docs/CONVENTIONS.md` / `AGENTS.md` / an ADR, not just remembered in the chat.
263
+
264
+ ### New configuration
265
+
266
+ | Key | Default | Meaning |
267
+ | --- | --- | --- |
268
+ | `patrolMs` | `300000` (5 min) | queen patrol period; a tick delivers only when something is pending |
269
+ | `notifyQueen` | `true` | inject the digest into the registered queen Session; `false` = pending list only |
270
+ | `anomalyDebounceMs` | `3000` | coalescing window before one digest is sent |
271
+ | `anomalyMax` | `50` | bound on the undelivered anomaly queue |
272
+ | `archReviewGraceMs` | `600000` (10 min) | grace before a done task without an `arch_review` event is flagged |
273
+ | `rolesBin` | `null` | executable for `hive roles` (umbrella `@d86e/hive`); falls back to `hiveBin` |
274
+
79
275
  ## Requirements
80
276
 
81
277
  - DSH 0.2.2-rc.5 with the `desktop` or `web` profile — the version the plugin is
82
- developed against. Node 22 or newer.
278
+ developed against. Node 22.19 or newer.
83
279
  - The [hive](https://github.com/d86e/hive) and
84
280
  [hive-tasks](https://github.com/d86e/hive-tasks) packages. `hive-tasks` and `hive`
85
281
  are called by their PATH names by default and retried through `npx` when the shell
86
- cannot find them; `tasksBin`/`hiveBin` pin an explicit executable instead.
87
- - Repositories already initialised with Hive (`hive init`), unless you enable discovery.
282
+ cannot find them; `tasksBin`/`hiveBin`/`rolesBin` pin an explicit executable instead.
283
+ - Repositories already initialised with Hive (`hive init`); auto-discovery only finds
284
+ repositories that were initialised.
88
285
  - The [Hive panel](https://github.com/d86e/dsh-hive-panel) **0.2.3 or newer**. It
89
- registers the queen conversation when you initialise the repository there (and
90
- re-registers it on every panel access); without that registration the supervisor
91
- waits and dispatches nothing.
286
+ registers the queen conversation when a Session becomes the queen there (on `hive
287
+ init`, or when opening an already-initialised repository in queen mode) and
288
+ re-registers it on every panel access; without that registration the supervisor waits
289
+ and dispatches nothing.
92
290
 
93
291
  ## Install
94
292
 
@@ -100,31 +298,34 @@ DSH 0.2.2-rc.5):
100
298
  is locked while it runs. If the app has never been opened, start it once so it creates
101
299
  `~/.dsh/profiles/desktop/package.json`, then quit.
102
300
 
103
- 2. **Install the plugin into the profile.** `dsh` and `pnpm` must be on PATH; the
104
- command updates both `dependencies` and `dsh.profile.bundles`:
301
+ 2. **Install the panel and the plugin into the profile.** `dsh` and `pnpm` must be on
302
+ PATH; the command updates both `dependencies` and `dsh.profile.bundles`. The panel is
303
+ required: it registers the queen Session and exposes the supervisor controls.
105
304
 
106
305
  ```bash
107
- dsh plugin --profile desktop add dsh-hive-runner
306
+ dsh plugin --profile desktop add dsh-hive-panel dsh-hive-runner
108
307
  ```
109
308
 
110
309
  For a CLI profile such as `web`, use
111
- `dsh plugin --profile web add dsh-hive-runner` and restart with `dsh web`.
310
+ `dsh plugin --profile web add dsh-hive-panel dsh-hive-runner` and restart with
311
+ `dsh web`.
112
312
 
113
313
  3. Add your repositories to the `hive-runner` entry in that profile's
114
- `cordis.patch.yml`, restart DSH, and open the Hive panel's **Runner** tab.
314
+ `cordis.patch.yml`, restart DSH, and open an initialised repository in the Hive panel
315
+ so the Session becomes the queen.
115
316
 
116
317
  <details>
117
318
  <summary>Manual profile edit (same result, only needed when the CLI is unavailable)</summary>
118
319
 
119
- While DSH Desktop is not running, add `"dsh-hive-runner": "^0.6.7"` to the profile's
120
- `dependencies`, add `dsh-hive-runner` to `dsh.profile.bundles`, then
121
- `cd ~/.dsh/profiles/desktop && pnpm install`.
320
+ While DSH Desktop is not running, add `"dsh-hive-panel": ">=0.2.3"` and
321
+ `"dsh-hive-runner": "^0.8.0"` to the profile's `dependencies`, add both names to
322
+ `dsh.profile.bundles`, then `cd ~/.dsh/profiles/desktop && pnpm install`.
122
323
 
123
324
  </details>
124
325
 
125
326
  ## Five-minute quickstart
126
327
 
127
- 1. **Install** the plugin as above and restart DSH.
328
+ 1. **Install** the panel and the plugin as above and restart DSH.
128
329
  2. **Add one repository** to the `hive-runner` config entry:
129
330
 
130
331
  ```yaml
@@ -135,57 +336,62 @@ While DSH Desktop is not running, add `"dsh-hive-runner": "^0.6.7"` to the profi
135
336
  - /absolute/path/to/your/repo
136
337
  ```
137
338
 
138
- 3. **Create a ready card** in that repository (the Hive CLI, from the repository root):
339
+ 3. **Create a ready task** in that repository (the Hive CLI, from the repository root):
139
340
 
140
341
  ```bash
141
342
  hive tasks add --title "add token refresh" --role coder \
142
343
  --scope src/auth.ts --acceptance "npm test -- auth"
143
344
  ```
144
345
 
145
- 4. **Watch it run.** The supervisor ticks every 30 seconds, claims the card and starts a
146
- DSH subagent worker for it. The Hive panel's Runner tab shows the per-role limits, live
147
- workers and cards waiting for a slot; the card moves to done when the worker commits and
148
- the acceptance command passes.
149
- 5. **Adjust the swarm.** Set per-role worker counts in the panel (0 pauses a role), or
150
- pause the whole repository with the same tab. Changes take effect immediately.
346
+ 4. **Watch it run.** The supervisor ticks every 30 seconds, claims the task and starts a
347
+ DSH subagent for it. The Hive panel shows the supervisor state and running agent count,
348
+ and its agent-concurrency settings show the per-role limits with tasks waiting for a
349
+ slot; the task moves to done when the agent commits and the acceptance command passes.
350
+ 5. **Adjust the swarm.** Set the per-role agent limits in the panel's **Agent
351
+ concurrency** settings (0 pauses a role); changes take effect on the next dispatch.
352
+ To stop a repository, ask the queen to pause it (`hive_supervisor_control pause`) or
353
+ list it under `paused` in the config and restart.
151
354
 
152
355
  The supervisor keeps running with the panel closed. To stop all work, pause the
153
- repository or remove it from `repos`.
356
+ repository (queen or config) or remove it from `repos`.
154
357
 
155
- ## Changing the number of bees
358
+ ## Changing the number of agents
156
359
 
157
- Everything is controlled from the **Hive panel**:
360
+ The per-role limits are controlled from the **Hive panel**:
158
361
 
159
- 1. Open the Hive panel in DSH and select the **Runner** tab.
160
- 2. In **Per-role workers** (每角色蜂数量) set the number for each role: how many live
161
- workers of that role may run at the same time in that repository. Use 0 to pause a role.
162
- 3. Changes take effect immediately (no restart, no plugin reload).
362
+ 1. Open the Hive panel in DSH and open the repository's **Settings → Concurrency limit**
363
+ (设置 → 并发上限) dialog.
364
+ 2. Under **Agent concurrency** (智能体的并发上限) set the **Concurrency limit** (并发上限)
365
+ for each role: how many live agents of that role may run in that repository at the same
366
+ time. Use 0 to pause a role. The dialog also shows Running (运行) and Waiting (等待).
367
+ 3. Changes take effect on the next dispatch (no restart, no plugin reload).
163
368
  4. The value is saved to `<repo>/.hive/limits.json`, so it also survives DSH restarts.
164
369
  The file is plain JSON and **safe to commit** into the repository, which shares the same
165
370
  limits with every teammate and every machine.
166
371
 
167
- To pause or resume the whole repository, use the **Pause / Resume** button in the same
168
- Runner tab. Pause stops new work from being scheduled; cards that are already running
169
- finish, and resume makes the repository eligible again on the next tick.
372
+ The supervisor strip at the top of the Hive view shows the repository state (idle,
373
+ running, backoff, paused), the running agent count and a **resume** control. Pause stops
374
+ new work from being scheduled (tasks already running finish); resume makes the repository
375
+ eligible again on the next tick. Pausing is a queen decision (`hive_supervisor_control
376
+ pause` / `hive_intervene pause`) or a startup setting (`paused` in the config).
170
377
 
171
- The panel also shows, per role, the configured limit, how many workers are live right now,
172
- and how many cards are waiting for a slot. For a running card it exposes the worker
173
- Session (so you can open that conversation), the start time and a heartbeat warning when
174
- the worker has produced no commit/output for a while; stuck cards are aborted and failed
175
- at `cardTimeoutMs` (default 15 minutes).
378
+ The concurrency dialog shows, per role, the configured limit, how many agents are running
379
+ right now and how many tasks are waiting for a slot. For a running task the panel exposes
380
+ the agent Session (so you can open that conversation), the start time and a heartbeat
381
+ warning when the agent has produced no commit/output for a while; stuck tasks are aborted
382
+ and failed at `cardTimeoutMs` (default 15 minutes).
176
383
 
177
- ## How many bees should I set?
384
+ ## How many agents should I set?
178
385
 
179
386
  The limits are user settings, not a hardcoded number. Small values (the default 5 per
180
387
  role) keep token cost predictable. Only when you set the values very high does the
181
- supervisor approximate "as many bees as ready tasks", because the real ceiling is DSH's
388
+ supervisor approximate "as many agents as ready tasks", because the real ceiling is DSH's
182
389
  subagent capacity plus the model provider's rate limits:
183
390
 
184
- - DSH's profile setting `subagent.maxActiveSubagents` (desktop profile default 80 - check
185
- your profile) caps how many subagents can exist at once across the whole app. If more
186
- cards become ready than the capacity allows, they wait and are retried; no card is
187
- dropped.
188
- - Token consumption grows roughly linearly with the number of concurrent bees. Measure a
391
+ - DSH's profile setting `subagent.maxActiveSubagents` (check your profile) caps how many
392
+ subagents can exist at once across the whole app. If more tasks become ready than the
393
+ capacity allows, they wait and are retried; no task is dropped.
394
+ - Token consumption grows roughly linearly with the number of concurrent agents. Measure a
189
395
  small repository first, then raise the numbers.
190
396
  - If you want more parallelism than the default, raise both the panel limits and
191
397
  `subagent.maxActiveSubagents` (for example to 128), and confirm the provider rate limits.
@@ -202,15 +408,15 @@ accepted as plugin `config`. User-facing keys:
202
408
  | `discoverRoots` | `[]` | Roots to scan when auto-discovering; empty = parents of `repos` |
203
409
  | `intervalMs` / `idleBackoffMs` | `30000` / `120000` | How often to look for work / how long to wait when a repository is empty |
204
410
  | `maxConcurrentRepos` | `2` | How many repositories may work at the same time |
205
- | `cardTimeoutMs` | `900000` | Hard limit per card: abort the worker and fail the card at the deadline |
206
- | `heartbeatWarnMs` / `heartbeatIntervalMs` | `300000` / `30000` | Mark a running worker as heartbeat-warn after this long without output / how often to check |
207
- | `roleConcurrency` | `{ coder: 5, tester: 5 }` | Initial/fallback per-role worker limits |
411
+ | `cardTimeoutMs` | `900000` | Hard limit per task: abort the agent and fail the task at the deadline |
412
+ | `heartbeatWarnMs` / `heartbeatIntervalMs` | `300000` / `30000` | Mark a running agent as heartbeat-warn after this long without output / how often to check |
413
+ | `roleConcurrency` | `{ coder: 5, tester: 5 }` | Initial/fallback per-role agent limits |
208
414
  | `defaultRoleConcurrency` | `5` | Fallback for roles not listed in `roleConcurrency` |
209
415
  | `paused` | `[]` | Repositories paused at startup (absolute paths) |
210
- | `agent` / `ttl` | `dsh` / `20m` | Identity and claim TTL for claims (raise `ttl` for very large waiting queues) |
211
- | `provider` | `spawn` | DSH subagent provider used for workers |
212
- | `parentSession` | `null` | Optional live session used as the parent for workers |
213
- | `tasksBin` / `hiveBin` | `null` | Explicit `hive-tasks` / `hive` executables (PATH name or absolute path). Default: the PATH name, retried once through `npx -y -p hive-tasks` / `npx -y -p hive-consensus` when missing |
416
+ | `agent` / `ttl` | `dsh` / `20m` | Claim identity / claim TTL. Keep `ttl` at least `cardTimeoutMs` so a long run does not outlive its claim; the TTL never aborts a running agent |
417
+ | `provider` | `spawn` | DSH subagent provider used for agents |
418
+ | `parentSession` | `null` | Legacy fallback parent for agents, used only when the registered queen Session is not live |
419
+ | `tasksBin` / `hiveBin` / `rolesBin` | `null` | Explicit `hive-tasks` / `hive` / `hive roles` executables (PATH name or absolute path). Default: the PATH name, retried once through `npx -y -p hive-tasks` / `npx -y -p hive-consensus` / `npx -y -p @d86e/hive` when missing; `rolesBin` falls back to `hiveBin` |
214
420
  | `gitBin` | `git` | Git executable |
215
421
  | `cliTimeoutMs` / `headTimeoutMs` / `acceptanceTimeoutMs` | `120000` / `30000` / `900000` | Command timeouts |
216
422
  | `debug` | `false` | Verbose supervisor logging |
@@ -237,17 +443,18 @@ DSH host process (alive as long as the app runs)
237
443
  +-- HiveSupervisor: tick every 30 s, per-repository backoff, pause/resume
238
444
  | |
239
445
  | +-- repository registry: config.repos, discovery, <repo>/.hive/limits.json
240
- | +-- ready cards: hive-tasks through DSH's shell seam (sandbox applies)
446
+ | +-- ready tasks: hive-tasks through DSH's shell seam (sandbox applies)
241
447
  | +-- per-role queues: live-only slots, default 5, 0 pauses a role
242
448
  | |
243
- | +-- one card round
244
- | claim -> DSH subagent worker ("bee") -> commit + acceptance
449
+ | +-- one task round
450
+ | claim -> DSH subagent -> commit + acceptance
245
451
  | -> verify -> done | fail on the Hive board
246
452
  |
247
- +-- Hive panel Runner tab: per-role limits, live counts, pause/resume
453
+ +-- Hive panel: supervisor strip (state, running count, resume)
454
+ | and agent-concurrency settings (per-role limits)
248
455
  ```
249
456
 
250
- The supervisor owns the cadence (tick, backoff, persistence, pause state). A card worker
457
+ The supervisor owns the cadence (tick, backoff, persistence, pause state). A task's agent
251
458
  is a normal DSH subagent; its commands and shell run through the harness under the
252
459
  applicable sandbox policy.
253
460
 
@@ -255,70 +462,78 @@ applicable sandbox policy.
255
462
 
256
463
  | Project | What it does | How this plugin relates |
257
464
  | --- | --- | --- |
258
- | [hive](https://github.com/d86e/hive) | One CLI entry point: init, roles, tasks, run, board, commit, doctor | The supervisor reads state and cards through the Hive CLIs |
259
- | [hive-tasks](https://github.com/d86e/hive-tasks) | Task cards with dependencies, priority and acceptance | Ready cards are fetched, claimed, completed or failed through it |
260
- | [hive-consensus](https://github.com/d86e/hive-consensus) | Path announcements, presence board, freeze mode, shared lessons | `hive guard` publishes each worker's paths; overlaps are advisory and merge-on-commit resolves the concurrent writes |
465
+ | [hive](https://github.com/d86e/hive) | One CLI entry point: init, roles, tasks, plan, run, board, commit, stats, doctor | The supervisor reads state and tasks through the Hive CLIs |
466
+ | [hive-tasks](https://github.com/d86e/hive-tasks) | Tasks with dependencies, priority and acceptance | Ready tasks are fetched, claimed, completed or failed through it |
467
+ | [hive-consensus](https://github.com/d86e/hive-consensus) | Path announcements, presence board, freeze mode, shared lessons | `hive guard` publishes each agent's paths; overlaps are advisory and merge-on-commit resolves the concurrent writes |
261
468
  | [hive-runner](https://github.com/d86e/hive-runner) | One execution round per invocation (`hive-run --once`) | This plugin uses the same round primitives, resident and DSH-native |
262
- | [merge-on-commit](https://github.com/d86e/merge-on-commit) | Three-way merge at commit time | Workers' commits go through the repository hook like any other commit |
469
+ | [merge-on-commit](https://github.com/d86e/merge-on-commit) | Three-way merge at commit time | Agents' commits go through the repository hook like any other commit |
263
470
  | [hive-panel](https://github.com/d86e/hive-panel) | Standalone read-only board outside DSH | Not needed; [dsh-hive-panel](https://github.com/d86e/dsh-hive-panel) is the DSH-native board |
264
- | [dsh-hive-panel](https://github.com/d86e/dsh-hive-panel) | Hive view inside DSH Web | Optional UI: shows supervisor status and edits the per-role limits |
471
+ | [dsh-hive-panel](https://github.com/d86e/dsh-hive-panel) | Hive view inside DSH Web | Required for queen registration; shows the supervisor status, edits the per-role limits and resumes a paused repository |
265
472
 
266
473
  ## Relation to `hive-run --watch`
267
474
 
268
475
  `hive-run --watch` loops inside one CLI process over one repository. This plugin does
269
476
  **not** invoke `--watch` and does not modify the `hive-runner` CLI: the supervisor owns
270
- the cadence (tick every 30 s, back off when empty, persist per-role limits, pause/resume
271
- from the panel). `hive-run --once` still works manually; do not run it against a
477
+ the cadence (tick every 30 s, back off when empty, persist per-role limits, resume from
478
+ the panel). `hive-run --once` still works manually; do not run it against a
272
479
  repository while the supervisor is active on the same repository.
273
480
 
274
481
  ## FAQ and known limits
275
482
 
276
- **How many bees run at once?** Per role and per repository, the configured limit (default
277
- 5) of live workers. Across repositories, at most `maxConcurrentRepos` drains run at the
278
- same time; DSH's `subagent.maxActiveSubagents` is the hard ceiling below that. Cards that
483
+ **How many agents run at once?** Per role and per repository, the configured limit (default
484
+ 5) of live agents. Across repositories, at most `maxConcurrentRepos` drains run at the
485
+ same time; DSH's `subagent.maxActiveSubagents` is the hard ceiling below that. Tasks that
279
486
  do not fit wait and are retried, so very large limits do not increase real throughput by
280
487
  themselves, and token cost grows with concurrency.
281
488
 
282
- **A card is claimed but not started.** Cards waiting in a repository's queue hold their
283
- Hive claim; if the wait outlives the claim TTL (`ttl`, default 20m) the claim expires and
284
- the card can be reclaimed. Raise `ttl` for very large queues.
489
+ **A task stays claimed but never starts.** A claim is taken right before its agent
490
+ starts; an agent that ends without a verdict can leave one behind. It expires after the
491
+ claim TTL (`ttl`, default 20m) and the task becomes claimable again. Keep `ttl` at least
492
+ `cardTimeoutMs` so a long run does not outlive its claim.
285
493
 
286
- **A repository says it is waiting.** Workers need a live DSH agent as their parent. When
287
- no session is live the repository waits (and the panel says why) instead of failing.
494
+ **A repository says it is waiting.** Agents are parented to the registered queen
495
+ Session. Until the panel registers it (`waiting: no-queen-session`) nothing is
496
+ dispatched; the supervisor waits instead of failing. Re-open the repository in the Hive
497
+ panel after a restart to restore the registration.
288
498
 
289
499
  **A repository is paused and does not restart.** That is deliberate: auto-pause after
290
- three consecutive failures, and pause from the panel, both require an explicit resume.
500
+ three consecutive failures, and a queen/config pause, both require an explicit resume
501
+ (the panel's resume control, `hive_supervisor_control resume`, or removing the path
502
+ from `paused`).
291
503
 
292
- **Does it write without asking?** It claims cards and commits through the normal Hive and
293
- git flows of the repository. The acceptance command comes from the card, i.e. from the
504
+ **Does it write without asking?** It claims tasks and commits through the normal Hive and
505
+ git flows of the repository. The acceptance command comes from the task, i.e. from the
294
506
  repository; treat the repository as trusted input. A read-only deployment cannot claim or
295
- write cards.
507
+ write tasks.
296
508
 
297
509
  **What survives a DSH restart?** Per-role limits (in `.hive/limits.json`) and the Hive
298
- state (in git refs) survive. In-memory queues do not: claimed cards return to the board
299
- after their claim TTL.
510
+ state (in git refs) survive. In-memory queues and the queen registration do not: claimed
511
+ tasks return to the board after their claim TTL, and the panel re-registers the queen
512
+ Session on its next access.
300
513
 
301
- **Do I need the Hive panel?** No. The panel is the convenient front-end for limits and
302
- pause/resume; the supervisor works from `cordis.patch.yml` alone.
514
+ **Do I need the Hive panel?** Yes. The supervisor itself starts from `cordis.patch.yml`
515
+ alone, but nothing is dispatched until a live Session registers as the queen; the panel
516
+ is what registers it (on init/queen mode) and exposes the limits and resume controls.
303
517
 
304
518
  ## Development
305
519
 
306
520
  ```bash
307
- npm test # node --test test/*.test.js (124 tests)
521
+ npm test # node --test test/*.test.js (197 tests)
308
522
  npm run check # node --check on index.js and lib/
309
523
  npm pack --dry-run
310
524
  ```
311
525
 
312
526
  The test suite is a pure shim (no DSH process, no real timers, no real CLI) and covers the
313
- default five-per-role limits, live-only slot accounting with immediate refill, queued cards
314
- not occupying slots, 0 pausing a role, persisted limits taking effect immediately and
315
- surviving a restart, invalid limit updates being rejected, the state machine, card round
316
- paths, discovery, the command allowlist, and an architecture guard that the plugin never
317
- spawns child processes.
527
+ default five-per-role limits, live-only slot accounting with immediate refill, queued tasks
528
+ not counting against a slot, 0 pausing a role, persisted limits taking effect immediately
529
+ and surviving a restart, invalid limit updates being rejected, the state machine, task
530
+ round paths, discovery, the gate pipeline, queen-session dispatch and parenting, the
531
+ anomaly feed/patrol/notifier pipeline, arch-review and intervention events, the command
532
+ allowlist, and an architecture guard that the plugin never spawns child processes.
318
533
 
319
534
  The protocol is specified in [SPEC.md](SPEC.md); implementation notes are in
320
535
  [docs/DESIGN.md](docs/DESIGN.md).
321
536
 
322
537
  ## License
323
538
 
324
- MIT © Tommy. See [LICENSE](LICENSE).
539
+ MIT © Tommy. See [LICENSE](LICENSE).