dsh-hive-panel 0.2.3 → 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/CHANGELOG.md +46 -16
- package/README.md +72 -52
- package/README.zh-CN.md +45 -34
- package/SPEC.md +77 -40
- package/docs/DESIGN.md +4 -3
- package/docs/QUEEN-ACTIVATION.md +2 -2
- package/lib/client.js +243 -154
- package/lib/index.js +14 -1
- package/lib/queen.js +4 -4
- package/package.json +1 -1
- package/scripts/verify-queen-activation.mjs +5 -4
- package/scripts/verify.mjs +50 -7
- package/src/panel.css +34 -0
- package/src/panel.js +242 -153
package/SPEC.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# dsh-hive-panel — protocol specification
|
|
2
2
|
|
|
3
|
-
Status: 0.
|
|
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`
|
|
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,25 +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
|
|
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":
|
|
83
|
+
"mode": { "mode": "free", "reason": "", "since": null },
|
|
84
|
+
"board": [],
|
|
84
85
|
"boardError": null,
|
|
85
|
-
"tasks":
|
|
86
|
+
"tasks": [],
|
|
86
87
|
"stats": {},
|
|
87
88
|
"events": [],
|
|
88
89
|
"writable": false,
|
|
@@ -98,7 +99,19 @@ these top-level fields:
|
|
|
98
99
|
```
|
|
99
100
|
|
|
100
101
|
- `initialised` — `refs/hive/v1` exists in the repository (a refs probe), not a guess.
|
|
101
|
-
- `
|
|
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`.
|
|
102
115
|
- `boardError` — `null` when `hive board --json` ran and returned a JSON array;
|
|
103
116
|
otherwise a one-line diagnostic naming the failure ("did not run", timeout, exit
|
|
104
117
|
status with the CLI stderr, or malformed JSON). `board` stays `[]` in that case,
|
|
@@ -117,10 +130,10 @@ these top-level fields:
|
|
|
117
130
|
`limit` is `null` when the file has no entry — effective limits (config fallback,
|
|
118
131
|
runtime counts) are exposed by the hive-runner supervisor status endpoint instead.
|
|
119
132
|
A successful `roles-add` shows up here on the next poll.
|
|
120
|
-
- An uninitialised repository returns the same shape
|
|
121
|
-
|
|
122
|
-
`{ list: [], limits: {}, error: null }`;
|
|
123
|
-
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.
|
|
124
137
|
|
|
125
138
|
## 5. Action envelope
|
|
126
139
|
|
|
@@ -128,12 +141,14 @@ these top-level fields:
|
|
|
128
141
|
{ "ok": true, "code": 0, "stdout": "", "stderr": "" }
|
|
129
142
|
```
|
|
130
143
|
|
|
131
|
-
- A nonzero CLI exit maps to `ok:false` with the same envelope
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
`hive/unknown
|
|
136
|
-
|
|
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.
|
|
137
152
|
- In read-only mode a mutating action returns `403` with
|
|
138
153
|
`{ ok:false, code:2, stdout:'', stderr:'read-only: hive-panel writable=false' }` and
|
|
139
154
|
spawns nothing.
|
|
@@ -141,8 +156,12 @@ these top-level fields:
|
|
|
141
156
|
## 6. Action catalog
|
|
142
157
|
|
|
143
158
|
Actions: `init add plan claim done fail retry renew mode learn recall verdict run
|
|
144
|
-
commit doctor roles-add roles-remove remove`
|
|
145
|
-
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.
|
|
146
165
|
|
|
147
166
|
### 6.1 `roles-add`
|
|
148
167
|
|
|
@@ -186,13 +205,13 @@ Maps to `hive tasks rm <id>` in the Session cwd: the `hive` router forwards `tas
|
|
|
186
205
|
hive-tasks (`bin: 'hive'`, argv `['tasks', 'rm', <id>]`), through the same shell seam.
|
|
187
206
|
|
|
188
207
|
- `id` (required) — `^[a-z0-9][a-z0-9-]{1,63}$`. The rule is deliberately stricter than
|
|
189
|
-
the general
|
|
190
|
-
- `--force` is never sent. A claimed
|
|
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
|
|
191
210
|
`task … is claimed by …; release or reopen it first, or use --force`), and the CLI
|
|
192
211
|
stderr reaches the panel unchanged as `ok:false, code:2`. A second delete reports
|
|
193
212
|
`no such task` the same way: the action never silently succeeds twice.
|
|
194
213
|
- Success: `200 { ok:true, code:0, stdout:"<id> deleted [<state>] <title>\n", stderr:"" }`.
|
|
195
|
-
The
|
|
214
|
+
The task disappears from the next snapshot poll. Mutating action: requires
|
|
196
215
|
`writable: true`, otherwise `403` read-only.
|
|
197
216
|
|
|
198
217
|
### 6.3 `roles-remove`
|
|
@@ -214,7 +233,7 @@ file `.hive/roles/<name>.md` and says so on stdout.
|
|
|
214
233
|
`hive roles: role "<name>" not found in .hive/roles.yaml` on stderr, returned
|
|
215
234
|
unchanged as `{ ok:false, code:2, stdout:"", stderr:<that text> }`.
|
|
216
235
|
- The host does not pre-check in-flight work or limits: `hive roles rm` itself does not
|
|
217
|
-
inspect
|
|
236
|
+
inspect tasks, so deletion succeeds while tasks still name the role (they keep their
|
|
218
237
|
`role` field; the supervisor simply has no definition/limit entry for it). A stale
|
|
219
238
|
`<role>` key can remain in `.hive/limits.json`; this action does not edit that file.
|
|
220
239
|
- Success: `200 { ok:true, code:0, stdout:"removed role <name> from .hive/roles.yaml\n
|
|
@@ -223,20 +242,24 @@ file `.hive/roles/<name>.md` and says so on stdout.
|
|
|
223
242
|
requires `writable: true`, otherwise `403` read-only.
|
|
224
243
|
|
|
225
244
|
For every action the host builds one fixed command template. Each argument field is
|
|
226
|
-
validated (id, agent, ttl, sha,
|
|
227
|
-
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:
|
|
228
247
|
|
|
229
248
|
```js
|
|
230
249
|
quote(value) = "'" + String(value).replaceAll("'", "'\\''") + "'"
|
|
231
250
|
command = [bin, ...argv].map(quote).join(' ')
|
|
232
251
|
```
|
|
233
252
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
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.
|
|
240
263
|
|
|
241
264
|
## 7. Execution
|
|
242
265
|
|
|
@@ -246,7 +269,7 @@ Every command runs through DSH's shell seam:
|
|
|
246
269
|
const request = {
|
|
247
270
|
command,
|
|
248
271
|
workdir: cwd,
|
|
249
|
-
timeoutMs
|
|
272
|
+
timeoutMs, // 15 s git probe · 30 s snapshot read · 30 min action
|
|
250
273
|
stdoutMaxBytes: 4 * 1024 * 1024,
|
|
251
274
|
signal: request.signal,
|
|
252
275
|
}
|
|
@@ -255,6 +278,11 @@ const spec = ctx.shell.resolve(request)
|
|
|
255
278
|
const result = await (await ctx.shell.execute(spec)).result()
|
|
256
279
|
```
|
|
257
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
|
+
|
|
258
286
|
No `node:child_process` fallback exists: if `ctx.shell` is missing, `apply` throws
|
|
259
287
|
instead of bypassing the Session sandbox policy, credential scrubbing, timeout, output
|
|
260
288
|
cap and cancellation.
|
|
@@ -285,13 +313,21 @@ Deactivation:
|
|
|
285
313
|
Configuration: `autoQueen` on the plugin entry config, default `true`; when `false`
|
|
286
314
|
snapshots never auto-activate and only `init` / `queen-on` / `/queen on` activate.
|
|
287
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
|
+
|
|
288
322
|
Injection: a system-prompt section `hive:queen` (order 520) that renders text only for
|
|
289
323
|
the marked Session and an empty string for every other Session, evaluated on each prompt
|
|
290
324
|
assembly. It does not enter the conversation history.
|
|
291
325
|
|
|
292
326
|
Role text: `<cwd>/.hive/roles/queen.md`, prefixed with an "untrusted role file" label
|
|
293
|
-
naming the absolute source path, capped at
|
|
294
|
-
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.
|
|
295
331
|
|
|
296
332
|
## 9. Security invariants
|
|
297
333
|
|
|
@@ -304,7 +340,8 @@ when cut; a built-in fallback is labelled when the file is missing.
|
|
|
304
340
|
|
|
305
341
|
## 10. Compatibility
|
|
306
342
|
|
|
307
|
-
Host APIs used: `connection.fetch.register`, `sessions`, `workingDirectory`,
|
|
308
|
-
`
|
|
309
|
-
|
|
310
|
-
|
|
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
|
@@ -299,8 +299,9 @@ token(PATH 名或绝对路径)。
|
|
|
299
299
|
只有 `agent.session.id` 命中的 Session 返回文本;其他会话返回空串。下一个 model step 即生效,
|
|
300
300
|
不进会话历史、不会被 compaction 摘要。
|
|
301
301
|
- **角色文本**:读 `<cwd>/.hive/roles/queen.md`(低信任、工作区可控)。注入文本以
|
|
302
|
-
“`[hive:queen] role loaded from <绝对路径> … untrusted`” 开头,总长 **≤
|
|
303
|
-
`[truncated]`。文件缺失时用内置兜底角色,并标注 `missing; built-in fallback
|
|
302
|
+
“`[hive:queen] role loaded from <绝对路径> … untrusted`” 开头,总长 **≤ 16384 字符**;超长截断并标注
|
|
303
|
+
`[truncated]`。文件缺失时用内置兜底角色,并标注 `missing; built-in fallback`;兜底与退出提示
|
|
304
|
+
都写明协调者契约(细粒度卡、每卡必须有验收命令、排序/监督/审查/汇报,永不写码)。
|
|
304
305
|
- **不污染会话日志**:不 append 自定义 session 事件(第三方未知事件会让 resume 拒绝解释日志),
|
|
305
306
|
状态只存在 host 内存 `Map<SessionId, { text, source }>` + `Set<SessionId>`。
|
|
306
307
|
|
|
@@ -383,7 +384,7 @@ ctx.uiWorkspace.openSession(address /* SubagentAddress */)
|
|
|
383
384
|
| `ctx.systemPrompt.section` 行号 `:485-495` | 实际 `:485` 起;`assemble()` 在 `:621` | 一致 |
|
|
384
385
|
| `commands.register` 未给行号 | `dsh-commands/src/index.ts:285`,返回同步 disposer | 已在 queen 中显式 dispose |
|
|
385
386
|
| 女王端点样例是独立路由 `/api/hive-panel/queen` | 本实现折叠进单一路由 `/api/hive?op=action&name=init\|queen-on\|queen-off` | 少一条路由;语义不变 |
|
|
386
|
-
| 女王角色上限 16 KiB |
|
|
387
|
+
| 女王角色上限 16 KiB | 本实现与之一致:**16384 字符**(含来源标注/退出提示) | 与协调者任务契约一致 |
|
|
387
388
|
| “用 `resolveCore` 解析 hive 二进制” | host 侧无自动解析;本实现用受信配置 `bins` 或 PATH(`hive`/`hive-tasks`/`hive-run`/`moc`) | 找不到命令时返回干净的非 0 退出码与 stderr,不假装成功 |
|
|
388
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 |
|
|
389
390
|
|
package/docs/QUEEN-ACTIVATION.md
CHANGED
|
@@ -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
|
|
44
|
-
const DEFAULT_QUEEN = '# Queen\n\nYou plan
|
|
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) {
|