dsh-hive-runner 0.6.1 → 0.6.7

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/CHANGELOG.md CHANGED
@@ -7,6 +7,168 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
  Version 0.6.0 is the first public snapshot; 0.1.0-0.5.0 were local development
8
8
  iterations of the plugin before this repository was published.
9
9
 
10
+ ## [0.6.7] - 2026-12-04
11
+
12
+ ### Fixed
13
+
14
+ - Card workers are now parented to the **queen conversation** — the Session where the
15
+ panel was initialised and the queen took over. The panel registers that Session id
16
+ with the supervisor (`POST /api/hive-runner?op=queen { sessionId }`, or the
17
+ `hiveSupervisor.setQueenSession()` service), and every worker activation uses exactly
18
+ that parent, so the subagents appear in the user's own queen session instead of a
19
+ hidden session or an arbitrary live agent.
20
+ - Nothing is dispatched before that registration: the supervisor skips the round and
21
+ status reports `waiting: no-queen-session` per repository (and at the top level),
22
+ which is a startup-order hint, not an error. It never falls back to another Session.
23
+ - `status` exposes `queenSessionId` and the workers of each repository keep their
24
+ `sessionId`/`parentSource: "queen"`; last-run records carry `parentSource: "queen"`
25
+ as well.
26
+ - Requires `dsh-hive-panel` 0.2.3 or newer: its init/queen activation registers the
27
+ queen Session and every panel snapshot re-registers it after a plugin restart.
28
+
29
+
30
+ ## [0.6.6] - 2026-12-04
31
+
32
+ ### Changed
33
+
34
+ - Follows hive-consensus 1.5.0's announcement board: `hive claim` and `hive guard`
35
+ never block, so the runner no longer fails a card when another agent already
36
+ announced the same or a related path. `hive guard --json` overlaps are parsed,
37
+ logged (`card <id> in <repo> overlaps: ...`), kept on the last-run record and
38
+ treated as information: the worker keeps working and merge-on-commit three-way
39
+ merges the concurrent edits at commit time (unresolved conflicts stay as markers).
40
+ - Worker prompt rewritten for announcements: announce every scope entry (including
41
+ `resource:` keys) with `hive guard --task <card id>` before starting — the task id
42
+ ties the worker's own announcement to the card, so a retry or a re-announcement never
43
+ reports itself as an overlap — treat overlaps as information
44
+ only, and keep the release/lesson/commit/finish rules. The old "guard exits 2" stop
45
+ rule, the `HIVE_AGENT`-on-every-command rule and the "lease enforcement skipped"
46
+ warning are gone; the repository hook is owned by merge-on-commit and needs no
47
+ environment variable for a commit.
48
+ - Every per-card Hive command now runs with `HIVE_INSTANCE=<card id>` (claim, guard,
49
+ done, fail, release, renew), and the worker activation injects the same value, so
50
+ concurrent workers of one runner are distinct announcers and their overlaps surface
51
+ instead of being mistaken for the announcer itself.
52
+ - Lessons are now a pair: before dispatch `hive recall` runs for every scope path plus
53
+ the repository root and the deduplicated matches lead the worker prompt
54
+ (`## Recalled experience (hive recall)`); after the work, workers write genuinely new
55
+ knowledge with `hive lesson add`. A read error is logged and recorded on the run
56
+ record, never a card failure.
57
+ - Last-run records carry the optional `overlaps` array (`{ key, agent, task,
58
+ expiresAt }`, valid entries only, at most 100) on the opening `running` write and the
59
+ terminal write, and the `lessons` summary (`{ count, scopes, error? }`) the panel
60
+ reads to show how many lessons were read.
61
+
62
+ ### Fixed
63
+
64
+ - The last-run record's `output` is now the worker's **final result message** only:
65
+ the text blocks of the last assistant message. Reasoning/thinking blocks, tool calls
66
+ and the narration around them are stripped, and the provider diagnostic is no longer
67
+ appended (the card verdict already carries the failure reason). If a provider returns
68
+ no typed text block, the last non-empty text is used as a fallback; a run with no
69
+ text at all falls back to the card verdict. The 200-line/32-KiB cap is unchanged.
70
+
71
+ ### Removed
72
+
73
+ - The consensus claim-expiry abort: the `leaseCheckMs` config key and
74
+ `DEFAULT_LEASE_CHECK_MS` export, the claim-deadline interval and the lease-expiry
75
+ failure branch. The hard `cardTimeoutMs` remains; the claim deadline stays as status
76
+ observability only.
77
+ - The `hive/no-hive-agent-env` deferrable error and the hook-warning detection it fed
78
+ (hive-consensus 1.5.0 emits no such warnings).
79
+
80
+ ### Tests
81
+
82
+ - 124 `node:test` scenarios: announcement overlaps never block a card and are
83
+ logged/recorded, guard CLI problems only warn, per-card `HIVE_INSTANCE` injection,
84
+ lesson reads for every scope path and the repository root, run records with
85
+ `overlaps`/`lessons`, and the unchanged freeze-mode skip.
86
+
87
+ ## [0.6.5] - 2026-12-04
88
+
89
+ ### Fixed
90
+
91
+ - Every card now has a hard wall-clock timeout (`cardTimeoutMs`, default 15 min).
92
+ At the deadline the worker is aborted, the card is recorded failed, and its
93
+ leases are released, so a stuck worker can no longer stay "running" forever.
94
+ - While a card is in flight its claim lease is checked every `leaseCheckMs`
95
+ (default 1 s); an expired claim immediately aborts the worker, fails the card
96
+ and releases the leases.
97
+ - The running last-run record is refreshed as soon as the worker activation is
98
+ accepted: it carries `sessionId`/`agentName` while the card is still in progress,
99
+ not only after the terminal write. Panels can therefore open the worker chat for a
100
+ card that is currently running instead of waiting for done/failed.
101
+ - Status exposes the live `workers` of each repository with `cardId`, `sessionId`,
102
+ `agentName`, `startedAt`, `lastOutputAt`, `heartbeat`, `claimDeadline` and
103
+ `timeoutAt`, so the panel can jump to the worker session and show a stuck card.
104
+ - Heartbeat: while a worker runs, the repository HEAD is used as the observable
105
+ output signal. No movement for `heartbeatWarnMs` (default 5 min) marks the
106
+ worker `heartbeat: "warn"` in status and the last-run record and logs a warning.
107
+
108
+ ### Added
109
+
110
+ - Config keys `cardTimeoutMs`, `heartbeatWarnMs`, `heartbeatIntervalMs` and
111
+ `leaseCheckMs` (all defaulted; see `cordis.patch.yml`).
112
+
113
+ ### Changed
114
+
115
+ - Default claim TTL raised from `5m` to `20m` so the new 15-minute card timeout fits
116
+ inside a claim; set `ttl` ≥ `cardTimeoutMs` if you override either.
117
+
118
+ ## [0.6.4] - 2026-12-04
119
+
120
+ ### Added
121
+
122
+ - A card's last-run record now carries the worker activation's `sessionId` (the
123
+ child Session id) and `agentName` (its model-facing name), so Hive UIs can
124
+ open that worker's chat like one click in the header's subagent list.
125
+ - Both keys are omitted when the attempt never started a worker (a guard denial,
126
+ a missing merge-on-commit hook, or an activation that threw); success and
127
+ failure records keep them. Records without an activation stay byte-identical
128
+ to the previous shape.
129
+
130
+ ### Published
131
+
132
+ - npm: `dsh-hive-runner@0.6.4` on 2026-12-04.
133
+
134
+ ## [0.6.3] - 2026-12-04
135
+
136
+ ### Added
137
+
138
+ - Every card attempt now leaves a last-run record at
139
+ `<repo>/.hive/runs/<cardId>.json` (`cardId`, `agent`, `startedAt`,
140
+ `endedAt`, `status: running|done|failed`, optional `exitCode`/`commit`, and
141
+ the worker `output`). The record is written as `running` when the attempt
142
+ starts and overwritten with the terminal state for done, failed, guard-denied
143
+ and exceptional endings; only the most recent attempt is kept.
144
+ - `output` stores the smaller of the worker's last 200 lines and its last
145
+ 32 KiB of UTF-8, so a chatty worker cannot grow the file without bound.
146
+ - Run records are observability only: an unwritable repository never fails a
147
+ card (the write error is swallowed).
148
+
149
+ ### Fixed
150
+
151
+ - A failed verification with no worker text now keeps the verdict as the run
152
+ record's output instead of storing a blank line.
153
+
154
+ ## [0.6.2] - 2026-12-04
155
+
156
+ ### Fixed
157
+
158
+ - Every Hive/git command now runs with an explicit `HIVE_AGENT=<claim identity>`
159
+ environment entry (including git commit), so the merge-on-commit pre-commit
160
+ hook never skips lease enforcement with "HIVE_AGENT is not set".
161
+ - Worker subagent activations inject `HIVE_AGENT` into the in-process worker
162
+ environment for their lifetime (reference-counted and restored afterwards),
163
+ because DSH's model-facing bash tool only inherits ambient environment.
164
+ - The worker prompt now requires `HIVE_AGENT` on every command, especially
165
+ `git commit`, and tells the worker that a hook warning about the missing
166
+ variable is an environment error rather than success.
167
+ - The runner detects that hook warning in the worker output and raises the
168
+ deferrable `hive/no-hive-agent-env` environment error: the repository backs
169
+ off and reports `environmentError`; the card is not marked done/failed and no
170
+ auto-pause counts.
171
+
10
172
  ## [0.6.1] - 2026-12-04
11
173
 
12
174
  ### Fixed
package/README.md CHANGED
@@ -18,7 +18,7 @@ per-role worker limits you set in the Hive panel.
18
18
  ---
19
19
 
20
20
  [Hive](https://github.com/d86e/hive) coordinates a swarm of coding agents inside git: task
21
- cards with acceptance commands, expiring path leases, a presence board and a commit-time
21
+ cards 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
 
@@ -44,54 +44,83 @@ the plugin never spawns processes outside the harness.
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 protocol: the supervisor co-signs each card's scope
48
- with `hive guard` before a worker starts, injects recalled lessons into the prompt,
49
- and releases the scope leases afterwards. A scope held by another agent fails only that
50
- card, with the holder information.
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
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
51
+ three-way merges the concurrent edits at commit time (unresolved conflicts stay as
52
+ markers).
53
+ - Lessons are read before every card and written after it: the supervisor runs
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
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.
51
58
  - Commits are verified against merge-on-commit: the repository must have the
52
59
  merge-on-commit pre-commit hook (`hive init` installs it), and a card only counts as
53
60
  done when HEAD moved through that hook.
54
61
  - While the repository is in Hive freeze mode, non-fix cards stay on the board instead of
55
62
  failing.
56
63
 
64
+ ## Worker sessions
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.
71
+
72
+ - Nothing is dispatched before the queen Session is registered: status reports
73
+ `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.
76
+ - Once registered, dispatch works with zero other user sessions and keeps running when
77
+ the panel/UI is closed.
78
+
57
79
  ## Requirements
58
80
 
59
81
  - DSH 0.2.2-rc.5 with the `desktop` or `web` profile — the version the plugin is
60
82
  developed against. Node 22 or newer.
61
83
  - The [hive](https://github.com/d86e/hive) and
62
- [hive-tasks](https://github.com/d86e/hive-tasks) packages. `hive-tasks` must be
63
- reachable from the DSH host process, either on its PATH or via `tasksBin`.
84
+ [hive-tasks](https://github.com/d86e/hive-tasks) packages. `hive-tasks` and `hive`
85
+ 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.
64
87
  - Repositories already initialised with Hive (`hive init`), unless you enable discovery.
65
- - The [Hive panel](https://github.com/d86e/dsh-hive-panel) is not required, but it is the
66
- easiest way to change limits and pause/resume a repository.
88
+ - 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.
67
92
 
68
93
  ## Install
69
94
 
70
- Install into the profile that boots the DSH host where the supervisor should run. The
71
- **desktop** profile is managed by the DSH Desktop app, so
72
- `dsh plugin --profile desktop ...` refuses to edit it; edit it by hand:
73
-
74
- 1. In `~/.dsh/profiles/desktop/package.json`, add the dependency and the bundle:
75
-
76
- ```diff
77
- "dependencies": {
78
- + "dsh-hive-runner": "link:/path/to/dsh-hive-runner",
79
- },
80
- "dsh": {
81
- "profile": {
82
- "bundles": [
83
- + "dsh-hive-runner"
84
- ]
85
- }
86
- }
95
+ Install into the profile that boots the DSH host where the supervisor should run. Use the
96
+ `dsh` CLI of the same version as the DSH runtime (this plugin declares compatibility with
97
+ DSH 0.2.2-rc.5):
98
+
99
+ 1. **Quit DSH Desktop completely.** The `desktop` profile belongs to the Desktop app and
100
+ is locked while it runs. If the app has never been opened, start it once so it creates
101
+ `~/.dsh/profiles/desktop/package.json`, then quit.
102
+
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`:
105
+
106
+ ```bash
107
+ dsh plugin --profile desktop add dsh-hive-runner
87
108
  ```
88
109
 
89
- 2. Run `cd ~/.dsh/profiles/desktop && pnpm install`.
110
+ For a CLI profile such as `web`, use
111
+ `dsh plugin --profile web add dsh-hive-runner` and restart with `dsh web`.
112
+
90
113
  3. Add your repositories to the `hive-runner` entry in that profile's
91
114
  `cordis.patch.yml`, restart DSH, and open the Hive panel's **Runner** tab.
92
115
 
93
- For a CLI profile such as `web`, `dsh plugin --profile web add /path/to/dsh-hive-runner`
94
- also works; check that `dsh.profile.bundles` lists `dsh-hive-runner`.
116
+ <details>
117
+ <summary>Manual profile edit (same result, only needed when the CLI is unavailable)</summary>
118
+
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`.
122
+
123
+ </details>
95
124
 
96
125
  ## Five-minute quickstart
97
126
 
@@ -140,7 +169,10 @@ Runner tab. Pause stops new work from being scheduled; cards that are already ru
140
169
  finish, and resume makes the repository eligible again on the next tick.
141
170
 
142
171
  The panel also shows, per role, the configured limit, how many workers are live right now,
143
- and how many cards are waiting for a slot.
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).
144
176
 
145
177
  ## How many bees should I set?
146
178
 
@@ -170,13 +202,15 @@ accepted as plugin `config`. User-facing keys:
170
202
  | `discoverRoots` | `[]` | Roots to scan when auto-discovering; empty = parents of `repos` |
171
203
  | `intervalMs` / `idleBackoffMs` | `30000` / `120000` | How often to look for work / how long to wait when a repository is empty |
172
204
  | `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 |
173
207
  | `roleConcurrency` | `{ coder: 5, tester: 5 }` | Initial/fallback per-role worker limits |
174
208
  | `defaultRoleConcurrency` | `5` | Fallback for roles not listed in `roleConcurrency` |
175
209
  | `paused` | `[]` | Repositories paused at startup (absolute paths) |
176
- | `agent` / `ttl` | `dsh` / `5m` | Identity and lease TTL for claims |
210
+ | `agent` / `ttl` | `dsh` / `20m` | Identity and claim TTL for claims (raise `ttl` for very large waiting queues) |
177
211
  | `provider` | `spawn` | DSH subagent provider used for workers |
178
212
  | `parentSession` | `null` | Optional live session used as the parent for workers |
179
- | `tasksBin` / `hiveBin` | `null` | Explicit `hive-tasks` / `hive` executables (PATH name or absolute path) |
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 |
180
214
  | `gitBin` | `git` | Git executable |
181
215
  | `cliTimeoutMs` / `headTimeoutMs` / `acceptanceTimeoutMs` | `120000` / `30000` / `900000` | Command timeouts |
182
216
  | `debug` | `false` | Verbose supervisor logging |
@@ -186,9 +220,13 @@ values in `.hive/limits.json` take precedence for the roles they contain.
186
220
  Repository-specific defaults can also be written in the config with absolute-path keys,
187
221
  for example `{ "/abs/repo": { "coder": 3 } }`.
188
222
 
189
- `hive-tasks` must be resolvable from the DSH host's `PATH` (or configured as
190
- `tasksBin`). If DSH's shell service is unavailable the plugin fails loudly instead of
191
- bypassing the sandbox.
223
+ `hive-tasks` and `hive` are resolved from the DSH shell's `PATH` by default. When a
224
+ PATH lookup misses, the supervisor retries the same command once through `npx -y -p
225
+ <hive-tasks|hive-consensus>`; if that also fails, the error carries an install hint
226
+ (`npm i -g ...` plus the `tasksBin`/`hiveBin` key to set). First use needs network
227
+ access for npx to populate its cache; on an offline machine install the CLIs globally or
228
+ pin `tasksBin`/`hiveBin` to absolute paths. If DSH's shell service is unavailable the
229
+ plugin fails loudly instead of bypassing the sandbox.
192
230
 
193
231
  ## Architecture
194
232
 
@@ -219,7 +257,7 @@ applicable sandbox policy.
219
257
  | --- | --- | --- |
220
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 |
221
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 |
222
- | [hive-consensus](https://github.com/d86e/hive-consensus) | Path leases, presence board, freeze mode, shared lessons | Claims and presence keep concurrent agents from colliding |
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 |
223
261
  | [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 |
224
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 |
225
263
  | [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 |
@@ -242,7 +280,7 @@ do not fit wait and are retried, so very large limits do not increase real throu
242
280
  themselves, and token cost grows with concurrency.
243
281
 
244
282
  **A card is claimed but not started.** Cards waiting in a repository's queue hold their
245
- Hive claim; if the wait outlives the claim TTL (`ttl`, default 5m) the claim expires and
283
+ Hive claim; if the wait outlives the claim TTL (`ttl`, default 20m) the claim expires and
246
284
  the card can be reclaimed. Raise `ttl` for very large queues.
247
285
 
248
286
  **A repository says it is waiting.** Workers need a live DSH agent as their parent. When
@@ -266,7 +304,7 @@ pause/resume; the supervisor works from `cordis.patch.yml` alone.
266
304
  ## Development
267
305
 
268
306
  ```bash
269
- npm test # node --test test/*.test.js (89 tests)
307
+ npm test # node --test test/*.test.js (124 tests)
270
308
  npm run check # node --check on index.js and lib/
271
309
  npm pack --dry-run
272
310
  ```
package/README.zh-CN.md CHANGED
@@ -15,7 +15,7 @@
15
15
 
16
16
  ---
17
17
 
18
- [Hive](https://github.com/d86e/hive) 让一群 AI agent 在 git 里协调:带验收命令的任务卡、会过期的路径租约、在场看板、提交时合并,全部存在仓库自己的 refs 和文件里。[hive-runner](https://github.com/d86e/hive-runner) CLI 跑**一轮**就退出。
18
+ [Hive](https://github.com/d86e/hive) 让一群 AI agent 在 git 里协调:带验收命令的任务卡、路径公告、在场看板、提交时合并,全部存在仓库自己的 refs 和文件里。[hive-runner](https://github.com/d86e/hive-runner) CLI 跑**一轮**就退出。
19
19
 
20
20
  **dsh-hive-runner** 把这个循环常驻进 DSH:supervisor 活在 DSH 宿主进程里(不在浏览器 tab 里),关掉面板或窗口都照常工作,只要 DSH 还在运行。worker 是 DSH subagent,所有命令都走 DSH 自己的 shell 执行层,受部署 sandbox 约束——插件不会绕过 harness 直接 spawn 进程。
21
21
 
@@ -28,41 +28,56 @@
28
28
  - 单仓库一次只处理一轮;不同仓库可以并行(默认 2 个仓库)。
29
29
  - 卡片没产生 commit、验收命令失败或 worker 提前停止,会在 Hive 里记为失败,队列继续跑其余卡。
30
30
  - 仓库连续失败会退避,连续 3 次异常自动暂停;暂停的仓库不会自己恢复。
31
- - worker 遵循 Hive consensus 协议:supervisor 先用 `hive guard` 为卡片 scope 联签,再把 `hive recall` 到的经验注入 prompt,结束后释放 scope 租约。scope 被其他 agent 持有时只让这张卡失败,并记录持有者信息。
31
+ - worker 遵循 Hive consensus 公告协议:派发前 supervisor 用 `hive guard` 公告卡片的每个 scope 项(包括 `resource:` 键),结束后清除自己的公告。路径已被其他 agent 公告时只是提示:worker 照常干活,由 merge-on-commit 在提交时做三方合并(未解决的冲突会保留成标记)。
32
+ - 经验是「开工读取、收工写入」的一对:每张卡派发前 supervisor 对每个 scope 路径加仓库根各跑一次 `hive recall`,把去重后的命中结果注入 worker prompt 顶部;worker 发现真正的新知识用 `hive lesson add` 写回。写经验与读取经验缺一不可,只写不读不会积累。
32
33
  - 提交受 merge-on-commit 约束:仓库必须装好 merge-on-commit 的 pre-commit 钩子(`hive init` 会装),只有 HEAD 经过该钩子推进的卡才算 done。
33
34
  - 仓库处于 Hive freeze 模式时,非 fix 卡留在看板上,而不是记为失败。
34
35
 
36
+ ## Worker 会话归属
37
+
38
+ worker 跑在**女王会话**里:你打开 Hive 面板并完成 `hive init`(或女王接管)的那个会话。
39
+ 面板会把这个 Session 登记给 supervisor;之后每张卡的 worker 都以它为 parent——
40
+ 子智能体就出现在同一个会话里,你可以直接点开。
41
+
42
+ - 女王会话登记前不派发:status 显示 `waiting: no-queen-session`,这是启动顺序提示,不是错误。
43
+ - supervisor 始终使用登记的那个 Session,绝不会换成别的聊天窗口。
44
+ - 登记之后,即使没有别的用户会话、面板/界面关闭,也会继续派发和运行。
45
+
35
46
  ## 环境要求
36
47
 
37
- - DSH 0.2.2-rc.5,`desktop` 或 `web` profile——插件按这个版本开发;Node 22 或更新。
48
+ - DSH 0.2.2-rc.5,`desktop` 或 `web` profile——插件按这个版本开发;Node 22.19 或更新。
38
49
  - [hive](https://github.com/d86e/hive) 与 [hive-tasks](https://github.com/d86e/hive-tasks)。
39
- `hive-tasks` 必须能被 DSH 宿主进程找到:在 PATH 上,或配置 `tasksBin`。
50
+ `hive-tasks` 和 `hive` 默认按 PATH 名调用,shell 找不到时自动用 `npx` 重试;`tasksBin`/`hiveBin` 可以显式固定可执行文件。
40
51
  - 已经用 Hive 初始化过的仓库(`hive init`),除非开启自动发现。
41
- - [Hive 面板](https://github.com/d86e/dsh-hive-panel)不是必须的,但它是改上限、暂停/恢复仓库最方便的方式。
52
+ - [Hive 面板](https://github.com/d86e/dsh-hive-panel) **0.2.3 或更新**。在面板里初始化仓库时会登记女王会话(每次面板访问都会重新登记);没有这个登记 supervisor 会一直等待、不派发。
42
53
 
43
54
  ## 安装
44
55
 
45
- 装到启动目标 DSH 宿主所用的 profile 里。**desktop** profile 由 DSH Desktop 应用管理,`dsh plugin --profile desktop ...` 会拒绝修改,需要手动编辑:
46
-
47
- 1. 在 `~/.dsh/profiles/desktop/package.json` 里加依赖和 bundle:
48
-
49
- ```diff
50
- "dependencies": {
51
- + "dsh-hive-runner": "link:/path/to/dsh-hive-runner",
52
- },
53
- "dsh": {
54
- "profile": {
55
- "bundles": [
56
- + "dsh-hive-runner"
57
- ]
58
- }
59
- }
56
+ 装到启动目标 DSH 宿主所用的 profile 里。请使用与 DSH 运行时同版本的 `dsh` CLI(本插件声明兼容 DSH 0.2.2-rc.5):
57
+
58
+ 1. **完全退出 DSH Desktop。** `desktop` profile 归桌面应用管理,应用运行时是锁住的。
59
+ 如果桌面应用从没打开过,先启动一次让它生成 `~/.dsh/profiles/desktop/package.json`,再退出。
60
+
61
+ 2. **把插件装进 profile。** `dsh` 和 `pnpm` 需要在 PATH 上;命令会同时更新
62
+ `dependencies` 和 `dsh.profile.bundles`:
63
+
64
+ ```bash
65
+ dsh plugin --profile desktop add dsh-hive-runner
60
66
  ```
61
67
 
62
- 2. 执行 `cd ~/.dsh/profiles/desktop && pnpm install`。
68
+ CLI profile(例如 `web`)用 `dsh plugin --profile web add dsh-hive-runner`,
69
+ 重启方式换成 `dsh web`。
70
+
63
71
  3. 在该 profile 的 `cordis.patch.yml` 的 `hive-runner` 条目里配置仓库,重启 DSH,打开 Hive 面板的 **Runner** 标签页。
64
72
 
65
- CLI profile(例如 `web`)也可以用 `dsh plugin --profile web add /path/to/dsh-hive-runner`,确认 `dsh.profile.bundles` 里列出了 `dsh-hive-runner`。
73
+ <details>
74
+ <summary>手工改 profile(效果相同,仅在 CLI 不可用时使用)</summary>
75
+
76
+ 在 DSH Desktop 退出时,把 `"dsh-hive-runner": "^0.6.7"` 加进 profile 的
77
+ `dependencies`、把 `dsh-hive-runner` 加进 `dsh.profile.bundles`,然后
78
+ `cd ~/.dsh/profiles/desktop && pnpm install`。
79
+
80
+ </details>
66
81
 
67
82
  ## 五分钟上手
68
83
 
@@ -100,7 +115,9 @@ CLI profile(例如 `web`)也可以用 `dsh plugin --profile web add /path/to
100
115
 
101
116
  要暂停/恢复整个仓库,用同一个 Runner 标签页里的 **暂停 / 恢复** 按钮。暂停会阻止后续调度;已经在跑的卡会跑完,恢复后在下一个 tick 重新参与调度。
102
117
 
103
- 面板会按角色显示:当前上限、正在跑的 worker 数、等待名额的卡数。
118
+ 面板会按角色显示:当前上限、正在跑的 worker 数、等待名额的卡数。对正在跑的卡,
119
+ 面板会显示 worker Session(可直接打开该会话)、开始时间,以及长时间无输出时的
120
+ heartbeat 告警;卡住的任务会在 `cardTimeoutMs`(默认 15 分钟)到点时被 abort 并判失败。
104
121
 
105
122
  ## 设多少只蜂合适?
106
123
 
@@ -121,20 +138,22 @@ CLI profile(例如 `web`)也可以用 `dsh plugin --profile web add /path/to
121
138
  | `discoverRoots` | `[]` | 自动发现的扫描根目录;空 = 使用 `repos` 的父目录 |
122
139
  | `intervalMs` / `idleBackoffMs` | `30000` / `120000` | 多久找一次活 / 仓库没活时等多久 |
123
140
  | `maxConcurrentRepos` | `2` | 同时工作的仓库数 |
141
+ | `cardTimeoutMs` | `900000` | 每张卡的硬超时:到点 abort worker 并判失败 |
142
+ | `heartbeatWarnMs` / `heartbeatIntervalMs` | `300000` / `30000` | 运行中的 worker 多久无输出标记 heartbeat 告警 / 检查间隔 |
124
143
  | `roleConcurrency` | `{ coder: 5, tester: 5 }` | 每角色 worker 数的初始值/兜底值 |
125
144
  | `defaultRoleConcurrency` | `5` | 未在 `roleConcurrency` 中列出的角色的兜底值 |
126
145
  | `paused` | `[]` | 启动即暂停的仓库(绝对路径) |
127
- | `agent` / `ttl` | `dsh` / `5m` | claim 身份 / 租约 TTL |
146
+ | `agent` / `ttl` | `dsh` / `20m` | claim 身份 / claim TTL(队列很长时调大 `ttl`) |
128
147
  | `provider` | `spawn` | 卡片 worker 使用的 DSH subagent provider |
129
148
  | `parentSession` | `null` | 可选的、作为 worker parent 的 live session |
130
- | `tasksBin` / `hiveBin` | `null` | 显式指定 `hive-tasks` / `hive` 可执行文件(PATH 名或绝对路径) |
149
+ | `tasksBin` / `hiveBin` | `null` | 显式指定 `hive-tasks` / `hive` 可执行文件(PATH 名或绝对路径)。默认用 PATH 名,找不到时用 `npx -y -p hive-tasks` / `npx -y -p hive-consensus` 重试一次 |
131
150
  | `gitBin` | `git` | git 可执行文件 |
132
151
  | `cliTimeoutMs` / `headTimeoutMs` / `acceptanceTimeoutMs` | `120000` / `30000` / `900000` | 命令超时 |
133
152
  | `debug` | `false` | supervisor 详细日志 |
134
153
 
135
154
  `roleConcurrency` 只是初始值和兜底;面板写入 `.hive/limits.json` 的每仓库数值优先。也可以在这份配置里用绝对路径 key 写仓库级默认值,例如 `{ "/abs/repo": { "coder": 3 } }`。
136
155
 
137
- `hive-tasks` 必须在 DSH 宿主进程的 `PATH` 里(或配置 `tasksBin`)。DSH 的 shell 服务不可用时插件会直接报错,不会绕过 sandbox。
156
+ `hive-tasks` 和 `hive` 默认从 DSH shell 的 `PATH` 解析。PATH 找不到时,supervisor 会把同一条命令用 `npx -y -p <hive-tasks|hive-consensus>` 重试一次;仍然失败时错误里带安装提示(`npm i -g ...` 和该设置的 `tasksBin`/`hiveBin`)。首次使用需要联网让 npx 填充缓存;离线机器请全局安装或把 `tasksBin`/`hiveBin` 固定成绝对路径。DSH 的 shell 服务不可用时插件会直接报错,不会绕过 sandbox。
138
157
 
139
158
  ## 架构
140
159
 
@@ -163,7 +182,7 @@ DSH 宿主进程(应用开着就一直在)
163
182
  | --- | --- | --- |
164
183
  | [hive](https://github.com/d86e/hive) | 统一入口:init、roles、tasks、run、board、commit、doctor | supervisor 通过 Hive CLI 读状态和任务卡 |
165
184
  | [hive-tasks](https://github.com/d86e/hive-tasks) | 带依赖、优先级、验收命令的任务卡 | ready 卡的读取、认领、完成、失败都经它 |
166
- | [hive-consensus](https://github.com/d86e/hive-consensus) | 路径租约、在场看板、冻结模式、共享经验 | claim 和 presence 让并发 agent 不互相踩踏 |
185
+ | [hive-consensus](https://github.com/d86e/hive-consensus) | 路径公告、在场看板、冻结模式、共享经验 | `hive guard` 公告每个 worker 的路径;重叠只是提示,由 merge-on-commit 合并并发写入 |
167
186
  | [hive-runner](https://github.com/d86e/hive-runner) | 每次调用跑一轮(`hive-run --once`) | 本插件复用同样的轮次原语,但常驻在 DSH 里 |
168
187
  | [merge-on-commit](https://github.com/d86e/merge-on-commit) | 提交时三方合并 | worker 的提交和普通提交一样经过仓库钩子 |
169
188
  | [hive-panel](https://github.com/d86e/hive-panel) | DSH 之外的独立只读看板 | 不需要;DSH 原生看板是 [dsh-hive-panel](https://github.com/d86e/dsh-hive-panel) |
@@ -177,7 +196,7 @@ DSH 宿主进程(应用开着就一直在)
177
196
 
178
197
  **同时能跑多少只蜂?** 每仓库每角色的上限(默认 5)个在飞 worker。跨仓库最多 `maxConcurrentRepos` 个仓库同时处理;再往下的硬天花板是 DSH 的 `subagent.maxActiveSubagents`。放不下的卡只会等待重试,所以把上限调得很大并不会自动提高真实吞吐,token 成本随并发增长。
179
198
 
180
- **卡片被 claim 了却迟迟不跑。** 仓库队列里的卡会持有 Hive claim;等待时间超过 claim TTL(`ttl`,默认 5m)后 claim 过期、卡片可被重新认领。队列很长时请调大 `ttl`。
199
+ **卡片被 claim 了却迟迟不跑。** 仓库队列里的卡会持有 Hive claim;等待时间超过 claim TTL(`ttl`,默认 20m)后 claim 过期、卡片可被重新认领。队列很长时请调大 `ttl`。
181
200
 
182
201
  **仓库显示在等待。** worker 需要一个 live DSH agent 作为 parent。没有 live session 时仓库会等待(面板会说明原因),而不是直接失败。
183
202
 
@@ -192,7 +211,7 @@ DSH 宿主进程(应用开着就一直在)
192
211
  ## 开发
193
212
 
194
213
  ```bash
195
- npm test # node --test test/*.test.js(89 项)
214
+ npm test # node --test test/*.test.js(124 项)
196
215
  npm run check # node --check index.js 和 lib/
197
216
  npm pack --dry-run
198
217
  ```