dsh-hive-panel 0.2.0 → 0.3.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/SPEC.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # dsh-hive-panel — protocol specification
2
2
 
3
- Status: 0.1.0, verified against DSH 0.2.2-rc.5.
3
+ Status: 0.3.0, verified against DSH 0.2.2-rc.5.
4
4
 
5
5
  This document is normative for the browser/host contract of the plugin. It is written
6
6
  for maintainers: user documentation is [README.md](README.md) and
@@ -39,7 +39,8 @@ Every request carries a `sessionId`. The browser never sends a filesystem path.
39
39
 
40
40
  1. Live Session: `ctx.sessions.get(sessionId)` then
41
41
  `ctx.workingDirectory.get(session)` gives the effective cwd (including a `cd`).
42
- 2. Cold Session: `ctx.get('sessionPersistence').stat(sessionId).header.cwd` gives the
42
+ 2. Cold Session: `ctx.get('sessionPersistence').stat(sessionId).header.cwd` (falling
43
+ back to `ctx.workingDirectory.defaultDirectory` when the header has no cwd) gives the
43
44
  project recorded at creation; a later `cd` is not visible until the Session resumes.
44
45
  3. Neither: `400`, code `hive/session-unknown`.
45
46
 
@@ -64,24 +65,25 @@ Requests:
64
65
  | `POST ?op=action&name=<action>&sessionId=<id>` with a JSON body | `200` action envelope (§5) |
65
66
  | unknown `op` | `400 { ok:false, error:{ code:'hive/unknown-op', message } }` |
66
67
  | wrong method | `405` |
67
- | invalid JSON body | `400` |
68
+ | invalid JSON body (op=action) | `400 { ok:false, code:2, stdout:'', stderr:'hive/invalid-body: …' }` |
68
69
 
69
70
  `name=queen-on` and `name=queen-off` are accepted in read-only mode because they only
70
71
  touch host memory.
71
72
 
72
73
  ## 4. Snapshot
73
74
 
74
- The snapshot is assembled from fixed CLI reads in the Session cwd and always has exactly
75
- these top-level fields:
75
+ The snapshot is assembled from fixed CLI reads and file reads in the Session cwd and always
76
+ has exactly these top-level fields:
76
77
 
77
78
  ```json
78
79
  {
79
80
  "at": "2026-12-04T00:00:00.000Z",
80
81
  "repo": "/abs/repo",
81
82
  "initialised": true,
82
- "mode": "free",
83
- "board": {},
84
- "tasks": {},
83
+ "mode": { "mode": "free", "reason": "", "since": null },
84
+ "board": [],
85
+ "boardError": null,
86
+ "tasks": [],
85
87
  "stats": {},
86
88
  "events": [],
87
89
  "writable": false,
@@ -97,7 +99,23 @@ these top-level fields:
97
99
  ```
98
100
 
99
101
  - `initialised` — `refs/hive/v1` exists in the repository (a refs probe), not a guess.
100
- - `board`, `tasks`, `stats` — parsed JSON from the configured Hive binaries.
102
+ - `mode` — the parsed `refs/hive/v1/mode` document (`{ v, mode, reason, since }`), for
103
+ example `{ "mode": "free" }`; `{ "mode": "free" }` when the ref cannot be read or
104
+ parsed.
105
+ - `board`, `stats` — parsed JSON from the configured Hive binaries; `board` stays `[]`
106
+ when the read fails and `stats` is `null` when the read yields no JSON.
107
+ - `tasks` — the parsed `hive-tasks list --json` array. Every task object is passed through
108
+ with one added field, `lastRun`: `null`, or the record read from
109
+ `<cwd>/.hive/runs/<id>.json` shaped
110
+ `{ cardId, agent, startedAt, endedAt, status, output, exitCode?, commit?, sessionId?,
111
+ agentName?, overlaps?, lessons? }`. `status` is `done`, `failed` or `running`;
112
+ `overlaps` are hive-consensus announcements from other agents writing the same paths;
113
+ `lessons` is the worker's memory-recall summary. The optional fields are omitted on
114
+ legacy records, and a missing, malformed or unsafe record degrades to `null`.
115
+ - `boardError` — `null` when `hive board --json` ran and returned a JSON array;
116
+ otherwise a one-line diagnostic naming the failure ("did not run", timeout, exit
117
+ status with the CLI stderr, or malformed JSON). `board` stays `[]` in that case,
118
+ so consumers can distinguish "nobody is working" from "the board CLI did not run".
101
119
  - `events` — the newest 80 lines of `<cwd>/.hive/events.jsonl`, newest first.
102
120
  - `writable` — the plugin configuration (`false` by default).
103
121
  - `queen` — current host-memory queen mode for this Session: `active` is a boolean,
@@ -112,9 +130,10 @@ these top-level fields:
112
130
  `limit` is `null` when the file has no entry — effective limits (config fallback,
113
131
  runtime counts) are exposed by the hive-runner supervisor status endpoint instead.
114
132
  A successful `roles-add` shows up here on the next poll.
115
- - An uninitialised repository returns the same shape with empty reads after only the
116
- refs probe; `roles` is then `{ list: [], limits: {}, error: null }`; `queen` may
117
- still be active there after an explicit activation.
133
+ - An uninitialised repository returns the same shape after only the `refs/hive/v1`
134
+ probe and the events read: `board` is `[]`, `tasks` is `[]`, `stats` is `null`,
135
+ `boardError` is `null`, and `roles` is `{ list: [], limits: {}, error: null }`;
136
+ `queen` may still be active there after an explicit activation.
118
137
 
119
138
  ## 5. Action envelope
120
139
 
@@ -122,12 +141,14 @@ these top-level fields:
122
141
  { "ok": true, "code": 0, "stdout": "", "stderr": "" }
123
142
  ```
124
143
 
125
- - A nonzero CLI exit maps to `ok:false` with the same envelope and the CLI's exit code.
126
- - Host-side failures (unknown action, invalid argument, unknown Session, missing queen
127
- controller) use `code: 2` and start `stderr` with a stable `hive/<code>: ` prefix,
128
- e.g. `hive/session-unknown: no live or stored Session "…"`,
129
- `hive/unknown-action: …`, `hive/invalid-argument: …`. Queen actions therefore only
130
- fail with `400` when the Session cannot be resolved.
144
+ - A nonzero CLI exit maps to `ok:false` with the same envelope, the CLI's exit code and
145
+ HTTP `400`.
146
+ - Host-side failures (unknown action, invalid argument, unknown Session) use `code: 2`
147
+ and start `stderr` with a stable `hive/<code>: ` prefix, e.g.
148
+ `hive/session-unknown: no live or stored Session "…"`, `hive/unknown-action: …`,
149
+ `hive/invalid-argument: …`. The two host-memory queen actions never spawn a command:
150
+ they fail with `400` only when the Session cannot be resolved, and with
151
+ `500 hive/queen-unavailable` when the queen controller is missing.
131
152
  - In read-only mode a mutating action returns `403` with
132
153
  `{ ok:false, code:2, stdout:'', stderr:'read-only: hive-panel writable=false' }` and
133
154
  spawns nothing.
@@ -135,8 +156,12 @@ these top-level fields:
135
156
  ## 6. Action catalog
136
157
 
137
158
  Actions: `init add plan claim done fail retry renew mode learn recall verdict run
138
- commit doctor roles-add roles-remove remove` plus the host-memory actions `queen-on`
139
- and `queen-off`.
159
+ commit doctor roles-add roles-remove remove` (18 allowlisted actions) plus the
160
+ host-memory actions `queen-on` and `queen-off` (20 names in the `op=actions` catalog).
161
+ `plan` is the only action that sends `--max-cards`: the host builds
162
+ `hive-run plan --goal <goal> --max-cards <n>`, with `n` defaulting to 50; `0` means
163
+ no limit and is forwarded unchanged, and `apply: true` appends `--apply` for the
164
+ write pass.
140
165
 
141
166
  ### 6.1 `roles-add`
142
167
 
@@ -180,13 +205,13 @@ Maps to `hive tasks rm <id>` in the Session cwd: the `hive` router forwards `tas
180
205
  hive-tasks (`bin: 'hive'`, argv `['tasks', 'rm', <id>]`), through the same shell seam.
181
206
 
182
207
  - `id` (required) — `^[a-z0-9][a-z0-9-]{1,63}$`. The rule is deliberately stricter than
183
- the general card id space (`ID_RE`) because this action is destructive.
184
- - `--force` is never sent. A claimed card is refused by the CLI (exit `2`, stderr
208
+ the general task id space (`ID_RE`) because this action is destructive.
209
+ - `--force` is never sent. A claimed task is refused by the CLI (exit `2`, stderr
185
210
  `task … is claimed by …; release or reopen it first, or use --force`), and the CLI
186
211
  stderr reaches the panel unchanged as `ok:false, code:2`. A second delete reports
187
212
  `no such task` the same way: the action never silently succeeds twice.
188
213
  - Success: `200 { ok:true, code:0, stdout:"<id> deleted [<state>] <title>\n", stderr:"" }`.
189
- The card disappears from the next snapshot poll. Mutating action: requires
214
+ The task disappears from the next snapshot poll. Mutating action: requires
190
215
  `writable: true`, otherwise `403` read-only.
191
216
 
192
217
  ### 6.3 `roles-remove`
@@ -208,7 +233,7 @@ file `.hive/roles/<name>.md` and says so on stdout.
208
233
  `hive roles: role "<name>" not found in .hive/roles.yaml` on stderr, returned
209
234
  unchanged as `{ ok:false, code:2, stdout:"", stderr:<that text> }`.
210
235
  - The host does not pre-check in-flight work or limits: `hive roles rm` itself does not
211
- inspect cards, so deletion succeeds while cards still name the role (they keep their
236
+ inspect tasks, so deletion succeeds while tasks still name the role (they keep their
212
237
  `role` field; the supervisor simply has no definition/limit entry for it). A stale
213
238
  `<role>` key can remain in `.hive/limits.json`; this action does not edit that file.
214
239
  - Success: `200 { ok:true, code:0, stdout:"removed role <name> from .hive/roles.yaml\n
@@ -217,20 +242,24 @@ file `.hive/roles/<name>.md` and says so on stdout.
217
242
  requires `writable: true`, otherwise `403` read-only.
218
243
 
219
244
  For every action the host builds one fixed command template. Each argument field is
220
- validated (id, agent, ttl, sha, ref mode, integer ranges, string length, NUL) and every
221
- token is single-quoted before it enters the shell seam:
245
+ validated (id, agent, ttl, sha, verdict, mode, integer ranges, string length, NUL) and
246
+ every token is single-quoted before it enters the shell seam:
222
247
 
223
248
  ```js
224
249
  quote(value) = "'" + String(value).replaceAll("'", "'\\''") + "'"
225
250
  command = [bin, ...argv].map(quote).join(' ')
226
251
  ```
227
252
 
228
- Invalid input is rejected with `400` before execution. `bins` (hive, hive-tasks,
229
- hive-run, moc) come only from trusted host configuration and must each be a single
230
- executable token: a PATH name or an absolute path. The default for every key is its
231
- PATH name; a bare default that the shell cannot resolve is retried once as
232
- `npx -y -p <published package> ... <bin>`, and a configured absolute path is never
233
- replaced. When both attempts fail, the error carries an install hint.
253
+ In writable mode invalid input is rejected with `400` before execution; the read-only
254
+ `403` gate runs first. `bins` (`hive`, `tasks`,
255
+ `run`, `moc`; default executables `hive`, `hive-tasks`, `hive-run`, `moc`) come
256
+ only from trusted host configuration and must each be a single executable token: a PATH
257
+ name or an absolute path. The default for every key is its PATH name; a bare PATH name
258
+ that the shell cannot resolve is retried once as
259
+ `npx -y -p <published package> ... <bin>` (`hive` installs the whole toolchain so the
260
+ router can resolve its cores), and a configured absolute path is never replaced. When
261
+ both attempts fail, the error carries an install hint naming the package set and the
262
+ `bins.<key>` to set.
234
263
 
235
264
  ## 7. Execution
236
265
 
@@ -240,7 +269,7 @@ Every command runs through DSH's shell seam:
240
269
  const request = {
241
270
  command,
242
271
  workdir: cwd,
243
- timeoutMs: 30_000,
272
+ timeoutMs, // 15 s git probe · 30 s snapshot read · 30 min action
244
273
  stdoutMaxBytes: 4 * 1024 * 1024,
245
274
  signal: request.signal,
246
275
  }
@@ -249,6 +278,11 @@ const spec = ctx.shell.resolve(request)
249
278
  const result = await (await ctx.shell.execute(spec)).result()
250
279
  ```
251
280
 
281
+ Bounds: the `refs/hive/v1` and `mode` git probes use 15000 ms, snapshot CLI reads
282
+ 30000 ms and one action 30 minutes; `stdoutMaxBytes` is 4 MiB. `timeoutMs` overrides
283
+ the snapshot read bound and `actionTimeoutMs` the action bound; the probe bound is
284
+ fixed.
285
+
252
286
  No `node:child_process` fallback exists: if `ctx.shell` is missing, `apply` throws
253
287
  instead of bypassing the Session sandbox policy, credential scrubbing, timeout, output
254
288
  cap and cancellation.
@@ -279,13 +313,21 @@ Deactivation:
279
313
  Configuration: `autoQueen` on the plugin entry config, default `true`; when `false`
280
314
  snapshots never auto-activate and only `init` / `queen-on` / `/queen on` activate.
281
315
 
316
+ Runner registration: every successful activation (auto, `init`, `queen-on` /
317
+ `/queen on`) also registers the Session id with the resident supervisor when one is
318
+ mounted (`ctx.get('hiveSupervisor').setQueenSession(id)`). Registration is in-memory and
319
+ idempotent and is repeated on every snapshot, so a plugin restart restores it; the
320
+ supervisor then parents task workers to that conversation.
321
+
282
322
  Injection: a system-prompt section `hive:queen` (order 520) that renders text only for
283
323
  the marked Session and an empty string for every other Session, evaluated on each prompt
284
324
  assembly. It does not enter the conversation history.
285
325
 
286
326
  Role text: `<cwd>/.hive/roles/queen.md`, prefixed with an "untrusted role file" label
287
- naming the absolute source path, capped at 4096 characters and marked `[truncated]`
288
- when cut; a built-in fallback is labelled when the file is missing.
327
+ naming the absolute source path, capped at 16384 characters and marked `[truncated]`
328
+ when cut; a built-in fallback is labelled when the file is missing. The fallback and the
329
+ exit hint both carry the coordinator contract (fine-grained tasks, acceptance commands,
330
+ supervise/review/report, `hive-queen` skill) and never grant code-writing.
289
331
 
290
332
  ## 9. Security invariants
291
333
 
@@ -298,7 +340,8 @@ when cut; a built-in fallback is labelled when the file is missing.
298
340
 
299
341
  ## 10. Compatibility
300
342
 
301
- Host APIs used: `connection.fetch.register`, `sessions`, `workingDirectory`,
302
- `shell`, `systemPrompt.section`, `commands.register`, `agents`. `sandboxPolicy`
303
- and `sessionPersistence` are optional and read through `ctx.get`. A DSH upgrade can
304
- change any of these: re-run `npm run check` against the installed DSH before releasing.
343
+ Host APIs used: `connection.fetch.register`, `sessions`, `workingDirectory`, `shell`,
344
+ `systemPrompt.section`, `commands.register` (and `agents` in the inject list), plus
345
+ `ctx.effect` and `ctx.on('agent/disposed')`. `sandboxPolicy`, `sessionPersistence`
346
+ and `hiveSupervisor` are optional and read through `ctx.get`. A DSH upgrade can change
347
+ any of these: re-run `npm run check` against the installed DSH before releasing.
package/docs/DESIGN.md CHANGED
@@ -165,7 +165,7 @@ interface ConnectionFetchRoute {
165
165
 
166
166
  | 请求 | 响应 |
167
167
  | --- | --- |
168
- | `GET /api/hive?op=snapshot&sessionId=<id>` | 快照 JSON,字段固定 `{ at, repo, initialised, mode, board, tasks, stats, events, writable, queen, roles }` |
168
+ | `GET /api/hive?op=snapshot&sessionId=<id>` | 快照 JSON,字段固定 `{ at, repo, initialised, mode, board, boardError, tasks, stats, events, writable, queen, roles }` |
169
169
  | `GET /api/hive?op=actions&sessionId=<id>` | `{ writable, autoQueen, actions: string[], repo }` |
170
170
  | `POST /api/hive?op=action&name=<name>&sessionId=<id>`(JSON body) | 动作结果 `{ ok, code, stdout, stderr }` |
171
171
  | 未知 `op` | `400 { ok:false, error:{ code:'hive/unknown-op', message } }` |
@@ -231,6 +231,9 @@ child_process 会绕过 Session sandbox mode、凭证擦除、超时/输出上
231
231
  | 快照探针 | `git for-each-ref --format=%(refname) refs/hive/v1`、`git cat-file -p refs/hive/v1/mode` |
232
232
  | 动作 | `init add plan claim done fail retry renew mode learn recall verdict run commit doctor roles-add roles-remove remove` |
233
233
 
234
+ `hive board --json` 失败(未执行、超时、非零退出、非法 JSON)时 `board` 保持 `[]`,
235
+ `boardError` 携带退出状态和 stderr 等诊断;这样空看板与“读失败”不再混淆。
236
+
234
237
  动作表沿用 `hive-panel/src/actions.js` 的 argv 构造;每个字段先校验(id/agent/ttl/sha/mode/整数范围/
235
238
  字符串长度/NUL),再作为独立 argv token 用单引号严格转义:
236
239
 
@@ -296,8 +299,9 @@ token(PATH 名或绝对路径)。
296
299
  只有 `agent.session.id` 命中的 Session 返回文本;其他会话返回空串。下一个 model step 即生效,
297
300
  不进会话历史、不会被 compaction 摘要。
298
301
  - **角色文本**:读 `<cwd>/.hive/roles/queen.md`(低信任、工作区可控)。注入文本以
299
- “`[hive:queen] role loaded from <绝对路径> … untrusted`” 开头,总长 **≤ 4096 字符**;超长截断并标注
300
- `[truncated]`。文件缺失时用内置兜底角色,并标注 `missing; built-in fallback`。
302
+ “`[hive:queen] role loaded from <绝对路径> … untrusted`” 开头,总长 **≤ 16384 字符**;超长截断并标注
303
+ `[truncated]`。文件缺失时用内置兜底角色,并标注 `missing; built-in fallback`;兜底与退出提示
304
+ 都写明协调者契约(细粒度卡、每卡必须有验收命令、排序/监督/审查/汇报,永不写码)。
301
305
  - **不污染会话日志**:不 append 自定义 session 事件(第三方未知事件会让 resume 拒绝解释日志),
302
306
  状态只存在 host 内存 `Map<SessionId, { text, source }>` + `Set<SessionId>`。
303
307
 
@@ -380,7 +384,7 @@ ctx.uiWorkspace.openSession(address /* SubagentAddress */)
380
384
  | `ctx.systemPrompt.section` 行号 `:485-495` | 实际 `:485` 起;`assemble()` 在 `:621` | 一致 |
381
385
  | `commands.register` 未给行号 | `dsh-commands/src/index.ts:285`,返回同步 disposer | 已在 queen 中显式 dispose |
382
386
  | 女王端点样例是独立路由 `/api/hive-panel/queen` | 本实现折叠进单一路由 `/api/hive?op=action&name=init\|queen-on\|queen-off` | 少一条路由;语义不变 |
383
- | 女王角色上限 16 KiB | 本实现按任务要求收紧到 **4096 字符**(含来源标注/退出提示) | 低信任 prompt 更保守 |
387
+ | 女王角色上限 16 KiB | 本实现与之一致:**16384 字符**(含来源标注/退出提示) | 与协调者任务契约一致 |
384
388
  | “用 `resolveCore` 解析 hive 二进制” | host 侧无自动解析;本实现用受信配置 `bins` 或 PATH(`hive`/`hive-tasks`/`hive-run`/`moc`) | 找不到命令时返回干净的非 0 退出码与 stderr,不假装成功 |
385
389
  | 组合位置行号 | `dsh-base/cordis.patch.yml`:agent `:82`、commands `:321`、system-prompt `:528`、subprocess `:234`、sandbox `:240`、sandbox-policy `:243`、bash-sandbox `:249`、shell-env `:278`;`dsh-web-app/cordis.patch.yml`:connection `:238`、tool-bash disabled `:517` | 文档行号一致;`ctx.shell` 在 host 平面,第三方 bundle patch 可直接 inject |
386
390
 
@@ -40,8 +40,8 @@ import path from 'node:path'
40
40
  export const inject = ['agents', 'workingDirectory', 'shell', 'systemPrompt', 'commands', 'connection']
41
41
 
42
42
  const SECTION = 'hive:queen'
43
- const EXIT_HINT = '\n\n女王模式规则:只规划、拆卡;不改代码、不 commit。退出:/queen off。'
44
- const DEFAULT_QUEEN = '# Queen\n\nYou plan, you do not code.\n' // .hive/roles/queen.md 缺失时的兜底
43
+ const EXIT_HINT = '\n\n[hive] Queen mode: plan, split, order, supervise, review, report; never edit code or commit. Fine-grained cards; every card needs an acceptance command. Load the hive-queen skill. Exit with /queen off.'
44
+ const DEFAULT_QUEEN = '# Queen\n\nYou plan and coordinate; you never write code. Split work into fine-grained cards that each carry an acceptance command, then order, supervise, review and report. Load the hive-queen skill for the full responsibility matrix and commands. Do not edit code, do not commit, do not claim or finish cards.\n' // .hive/roles/queen.md 缺失时的兜底
45
45
  const queen = new Map() // SessionId -> roleText;唯一的模式状态
46
46
 
47
47
  export function apply(ctx) {