dsh-hive-panel 1.0.4 → 1.0.5

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
@@ -4,6 +4,26 @@ All notable changes to this project are documented in this file. The format is
4
4
  based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and this project
5
5
  adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [1.0.5] - 2026-12-05
8
+
9
+ ### Fixed
10
+
11
+ - **The queen repository is registered with the supervisor from the first prompt
12
+ assembly.** When a Session's cwd is an initialised repository, the queen injection now
13
+ also calls `hiveSupervisor.addRepo(cwd)` with the full path, so a repository outside
14
+ the static `repos` config is supervised immediately instead of only after the panel is
15
+ opened. Registration is idempotent; relative or uninitialised paths are ignored.
16
+ - **The injected queen invariants now cover mutation tools and claim.** The
17
+ `QUEEN_INVARIANTS` block names the forbidden tools explicitly — `write`, `edit`,
18
+ `bash`, `cua` … — and states that `claim` is a worker action; read-only and
19
+ `hive_*` tools stay allowed. This sits above the untrusted workspace role file, so an
20
+ older `hive init` contract cannot widen the queen's tool surface.
21
+
22
+ ### Tests
23
+
24
+ - 41 checks cover the `addRepo` registration path, initialised-marker discovery, the
25
+ widened invariants copy and the unchanged suppression rules.
26
+
7
27
  ## [1.0.4] - 2026-12-05
8
28
 
9
29
  ### Fixed
@@ -25,6 +45,10 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
25
45
  registration, subagent exclusion, `/queen off` suppression and the unchanged
26
46
  invariants / role cap paths.
27
47
 
48
+ ### Published
49
+
50
+ - npm: `dsh-hive-panel@1.0.4` on 2026-12-05.
51
+
28
52
  ## [1.0.3] - 2026-12-05
29
53
 
30
54
  ### Fixed
package/README.md CHANGED
@@ -43,7 +43,7 @@ the Hive CLI writes them.
43
43
  | **Task actions** | Claim, complete, fail, retry and delete a task from its details; create tasks, ask the Queen for a task plan and pause or resume claiming from the toolbar |
44
44
  | **Task details** | ID, role, state and file scope, plus the last run: output, the **Also writing** overlap announcements and the lessons read. **Open agent chat** jumps to that worker's conversation when DSH can navigate to it |
45
45
  | **Settings** | The toolbar gear opens per-role concurrency limits (0–999, 0 pauses the role; needs `dsh-hive-runner`) and role management (add a role with adapter, model and responsibilities; delete a role) |
46
- | **Supervisor status** | When [dsh-hive-runner](https://github.com/d86e/dsh-hive-runner) is installed, the toolbar shows the current repository's supervisor state (idle, running, backoff, paused) with the running agent count, and **Resume** while paused |
46
+ | **Supervisor status** | When [dsh-hive-runner](https://github.com/d86e/dsh-hive-runner) is installed, the toolbar shows the current repository's supervisor state (idle, running, backoff, paused) with the running agent count, and **Resume** while paused. A repository that becomes the queen is added to the supervisor automatically, so it starts dispatching even when it is not listed in the runner's `repos` config |
47
47
  | **Read-only by default** | Watching the board is safe out of the box; mutations (including settings writes) are opt-in |
48
48
 
49
49
  ## Requirements
@@ -283,8 +283,12 @@ supervisor registration happens on the same first assembly.
283
283
  low-trust input: it is labelled as untrusted, has a built-in coordinator fallback and is
284
284
  capped at 24576 characters. A plugin-owned **trusted invariants** block is always injected
285
285
  above it (never call `subagent`/`subagent_fork`/`subagent_claude_code` or execution tools to
286
- implement; goals become Hive tasks; discussion creates tasks only when asked to execute), so
287
- a stale or custom workspace role file cannot remove the production boundary.
286
+ implement; never call `write`/`edit`/`apply_patch`/`bash`/`cua` or any file-mutating or
287
+ command-executing tool; tasks and state use only `hive_*` tools; `claim`/`done`/`fail` are
288
+ worker actions the queen must not call; implementation is delegated to the supervisor). The
289
+ tool-boundary sentence is injected in English and Chinese, so an older `hive init` role file
290
+ gets it without re-running init. Goals become Hive tasks; discussion creates tasks only when
291
+ asked to execute, so a stale or custom workspace role file cannot remove the boundary.
288
292
  - If you expose DSH Web beyond your machine, add authentication or a reverse proxy at the
289
293
  DSH layer first.
290
294
 
package/SPEC.md CHANGED
@@ -340,6 +340,17 @@ the registration on the first assembly, so the supervisor is ready even when no
340
340
  open; registration is in-memory, idempotent and repeated on each activation/snapshot, so a
341
341
  plugin restart restores it. The supervisor then parents task workers to that conversation.
342
342
 
343
+ Repository registration: the same registrar also adds the Session's cwd to the supervisor
344
+ (with `hiveSupervisor.addRepo(repo)`) so a repository that was never in
345
+ `config.repos` is still dispatched. It only runs when that cwd has
346
+ `.hive/roles/queen.md` (an initialised queen repository); `addRepo` is idempotent by
347
+ normalised path, so prompt assemblies, snapshots and init/queen-on may all repeat it
348
+ safely. The registration is deliberately **one-way**: `/queen off`, agent disposal,
349
+ plugin unload and process restart never remove it, and the supervisor's
350
+ `status().repos` list (what the panel's supervisor strip renders) shows the repository.
351
+ When the mounted supervisor predates `addRepo`, the repository step is skipped with a
352
+ log line and only the queen Session is registered.
353
+
343
354
  Injection: a system-prompt section `hive:queen` (order 520) evaluated on each prompt
344
355
  assembly with the Session's `agent`; it auto-activates from the agent's cwd on the first
345
356
  assembly (see Activation 1), renders role + invariants for the marked Session and an empty
@@ -350,8 +361,13 @@ naming the absolute source path, capped at 24576 characters and marked `[truncat
350
361
  when cut; a built-in fallback is labelled when the file is missing. Between the label and the
351
362
  workspace body the plugin always injects a **trusted invariants** block (`QUEEN_INVARIANTS`):
352
363
  never call `subagent`/`subagent_fork`/`subagent_claude_code` or execution tools to implement;
353
- goals become Hive tasks and the supervisor dispatches them; discussion creates tasks only when
354
- the human asks to execute. It is plugin-owned and cannot be overridden by the workspace file.
364
+ never call `write`/`edit`/`apply_patch`/`bash`/`cua` or any other file-mutating or
365
+ command-executing tool; tasks and state use only `hive_*` tools; `claim`/`done`/`fail` are
366
+ worker actions the queen must not call; implementation is delegated to the supervisor. The
367
+ tool-boundary sentence is injected in English and Chinese, so a repository initialised by an
368
+ older `hive init` (whose role file predates this contract) gets it without re-running init.
369
+ Goals become Hive tasks and the supervisor dispatches them; discussion creates tasks only when
370
+ the human asks to execute. The block is plugin-owned and cannot be overridden by the workspace file.
355
371
  The fallback and the exit hint both carry the coordinator contract (fine-grained tasks,
356
372
  acceptance commands, supervise/review/report, `hive-queen` skill) and never grant code-writing.
357
373
 
@@ -369,5 +385,8 @@ acceptance commands, supervise/review/report, `hive-queen` skill) and never gran
369
385
  Host APIs used: `connection.fetch.register`, `sessions`, `workingDirectory`, `shell`,
370
386
  `systemPrompt.section`, `commands.register` (and `agents` in the inject list), plus
371
387
  `ctx.effect` and `ctx.on('agent/disposed')`. `sandboxPolicy`, `sessionPersistence`
372
- and `hiveSupervisor` are optional and read through `ctx.get`. A DSH upgrade can change
373
- any of these: re-run `npm run check` against the installed DSH before releasing.
388
+ and `hiveSupervisor` are optional and read through `ctx.get`. The supervisor contract
389
+ used here is `setQueenSession(sessionId)` plus the optional `addRepo(repo)` /
390
+ `hasRepo(repo)` from dsh-hive-runner's `HiveSupervisor` (feature-detected; older
391
+ supervisors get no repository registration). A DSH upgrade can change any of these:
392
+ re-run `npm run check` against the installed DSH before releasing.
package/docs/DESIGN.md CHANGED
@@ -293,7 +293,14 @@ token(PATH 名或绝对路径)。
293
293
  就在**首次组装时**自动 mark(source auto)、注入角色文本 + `QUEEN_INVARIANTS`,并调用
294
294
  `registerQueenSession(sessionId)` 向 `ctx.get('hiveSupervisor')` 幂等登记。这条路径不需要
295
295
  打开面板,所以 DSH 重启后面板没开、或用户直接对 chat 说目标时,会话仍是女王而不是普通
296
- coding agent;只看**当前会话的 cwd**,不同仓库互不影响。subagent 会话
296
+ coding agent;只看**当前会话的 cwd**,不同仓库互不影响。同一钩子还会把该会话 cwd
297
+ 通过 `hiveSupervisor.addRepo(cwd)` 登记给 supervisor(仅当 cwd 有
298
+ `.hive/roles/queen.md`;`addRepo` 按规范化路径幂等去重),否则 supervisor 只对
299
+ `config.repos` 里的仓库派发、从面板 init/queen-on 打开的新仓库永远不会被跑。登记是
300
+ **单向**的:`/queen off`、agent dispose、插件卸载、进程重启都不会 `removeRepo`;
301
+ supervisor 的 `status().repos`(面板 supervisor 条的数据源)随即可见该仓库。
302
+ 旧版 supervisor 没有 `addRepo` 时跳过仓库登记并记一条日志,仍登记 queen Session。
303
+ subagent 会话
297
304
  (`session.header.origin === 'subagent'` 或 `delegationDepth > 0`)被排除:卡 worker 与父会话
298
305
  共享仓库 cwd,若自动注入会污染 worker 并把 supervisor 的 queen 登记顶掉。
299
306
  - **面板触发的自动标记**:`op=snapshot` 返回前已经跑过 `refs/hive/v1` 探针;若仓库已初始化、
@@ -318,7 +325,9 @@ token(PATH 名或绝对路径)。
318
325
  “`[hive:queen] role loaded from <绝对路径> … untrusted`” 开头,随后是无条件注入的
319
326
  **插件自有 trusted invariants**(禁止 subagent/直接执行实现;目标只转成 Hive 任务;讨论只在
320
327
  人类明确要执行时建任务)——旧版 `hive init` 写出的工作区角色文件无法覆盖它,因此生产红线不依赖
321
- 仓库是否重新 init。总长 **≤ 24576 字符**;超长截断并标注
328
+ 仓库是否重新 init。invariants 另含**工具边界**(中英各一句):禁止 `write`/`edit`/`apply_patch`/
329
+ `bash`/`cua` 等修改文件或执行命令的工具,任务与状态只用 `hive_*` 工具,`claim`/`done`/`fail` 是
330
+ worker 动作女王不得调用,实现交给 supervisor;这样老仓库不重跑 init 也能拿到该边界。总长 **≤ 24576 字符**;超长截断并标注
322
331
  `[truncated]`。文件缺失时用内置兜底角色,并标注 `missing; built-in fallback`;兜底与退出提示
323
332
  都写明协调者契约(细粒度卡、每卡必须有验收命令、排序/监督/审查/汇报,永不写码)。
324
333
  - **不污染会话日志**:不 append 自定义 session 事件(第三方未知事件会让 resume 拒绝解释日志),
@@ -433,7 +442,7 @@ npm run check
433
442
  # ok - node --check lib/queen.js
434
443
  # ok - node --check lib/client.js
435
444
  # ...
436
- # 39 checks passed
445
+ # 41 checks passed
437
446
  ```
438
447
 
439
448
  覆盖:语法、package/bundle 声明、无代理残留、client bundle 的 `/api/hive` URL 与 Session 注入、
@@ -447,7 +456,9 @@ Connection Fetch 路由注册、快照走 `ctx.shell` 且 cwd/policy 正确、
447
456
  另有 `initialised` 只靠 `.hive/roles.yaml`/`.hive/config.json` 即为 true、init 动作后立即 true、
448
457
  两者与 ref 都无才为 false,以及 client bundle 的 init 成功即时切面检查;prompt 首次组装自动注入
449
458
  (含 `QUEEN_INVARIANTS`、supervisor 幂等登记、跨仓库隔离)、`/queen off` 后不注入、
450
- `autoQueen=false` 不注入、未初始化仓库不注入。
459
+ `autoQueen=false` 不注入、未初始化仓库不注入;prompt/init/queen-on 路径对
460
+ `hiveSupervisor.addRepo` 的登记(幂等去重、只登记有 queen.md 的仓库、退出与卸载不删除);
461
+ invariants 的工具边界断言(write/edit/apply_patch/bash/cua/claim、hive_*、中英两句)。
451
462
 
452
463
  不启动、不重启任何 DSH 进程,也不写运行中的 `~/.dsh`。
453
464
 
package/lib/index.js CHANGED
@@ -30,7 +30,7 @@
30
30
  */
31
31
  import fs from 'node:fs'
32
32
  import path from 'node:path'
33
- import { createQueen, QUEEN_OFF_ACTION, QUEEN_ON_ACTION } from './queen.js'
33
+ import { createQueen, hasQueenRole, QUEEN_OFF_ACTION, QUEEN_ON_ACTION } from './queen.js'
34
34
 
35
35
  /** Cordis plugin name used in logs and fiber diagnostics. */
36
36
  export const name = 'hive-panel'
@@ -823,17 +823,23 @@ function createLog(ctx) {
823
823
 
824
824
  /**
825
825
  * Build the registrar that tells the resident Hive runner which Session is the
826
- * queen. The runner parents every card worker to exactly this Session; before
827
- * the registration it waits instead of dispatching. Registration is in-memory
828
- * and idempotent, so the prompt auto-injection and every panel snapshot may
829
- * re-register safely after a restart.
826
+ * queen and which repository it drives.
827
+ *
828
+ * The supervisor only dispatches repositories it tracks, so a Session that
829
+ * becomes queen by prompt auto-injection (or a panel init/queen-on) must also
830
+ * add its cwd. When the mounted supervisor exposes `addRepo(repo)` (the
831
+ * `hiveSupervisor` service in dsh-hive-runner does; it is idempotent by
832
+ * normalised path and its `status().repos` list then shows the repository) we
833
+ * register the cwd first; otherwise the repo step is skipped and only the
834
+ * queen Session is registered. Nothing is removed on unload/exit: the repo
835
+ * registration is deliberately one-way.
830
836
  *
831
837
  * @param {object} ctx - host Cordis context (may expose `hiveSupervisor`).
832
838
  * @param {(message: string, error?: unknown) => void} [log] - diagnostics sink.
833
- * @returns {(sessionId: string) => boolean} true when a runner accepted the id.
839
+ * @returns {(sessionId: string, cwd?: string) => boolean} true when a runner accepted the id.
834
840
  */
835
841
  export function createQueenSessionRegistrar(ctx, log = () => {}) {
836
- return function registerQueenSession(sessionId) {
842
+ return function registerQueenSession(sessionId, cwd) {
837
843
  if (typeof sessionId !== 'string' || sessionId === '') return false
838
844
  let runner
839
845
  try {
@@ -842,7 +848,23 @@ export function createQueenSessionRegistrar(ctx, log = () => {}) {
842
848
  log('hive-runner queen registration lookup failed', error)
843
849
  return false
844
850
  }
845
- if (runner === undefined || typeof runner.setQueenSession !== 'function') return false
851
+ if (runner === undefined) return false
852
+
853
+ // Repository step: only an initialised repository (queen role file present)
854
+ // is added; addRepo is idempotent, so repeated activations/snapshots are safe.
855
+ if (typeof cwd === 'string' && cwd !== '' && hasQueenRole(cwd)) {
856
+ if (typeof runner.addRepo === 'function') {
857
+ try {
858
+ runner.addRepo(cwd)
859
+ } catch (error) {
860
+ log('hive-runner repository registration failed: ' + cwd, error)
861
+ }
862
+ } else if (typeof runner.hasRepo === 'function' && runner.hasRepo(cwd) !== true) {
863
+ log('hive-runner supervisor does not expose addRepo(); repository not registered: ' + cwd)
864
+ }
865
+ }
866
+
867
+ if (typeof runner.setQueenSession !== 'function') return false
846
868
  try {
847
869
  runner.setQueenSession(sessionId)
848
870
  return true
@@ -1107,7 +1129,7 @@ export function createBridge(ctx, config = {}) {
1107
1129
  const initialised = isHiveInitialised(cwd, refsText)
1108
1130
  if (initialised) autoActivateQueen(sessionId, cwd)
1109
1131
  payload.queen = queenSnapshot(sessionId, cwd)
1110
- if (payload.queen.active) registerQueenSession(sessionId)
1132
+ if (payload.queen.active) registerQueenSession(sessionId, cwd)
1111
1133
  if (!initialised) {
1112
1134
  payload.events = readEvents(cwd)
1113
1135
  return payload
@@ -1172,7 +1194,7 @@ export function createBridge(ctx, config = {}) {
1172
1194
  if (!isHiveInitialised(cwd, refsText)) return false
1173
1195
  try {
1174
1196
  queen.mark({ sessionId, cwd })
1175
- registerQueenSession(sessionId)
1197
+ registerQueenSession(sessionId, cwd)
1176
1198
  return true
1177
1199
  } catch (error) {
1178
1200
  log('queen activation failed', error)
@@ -1192,7 +1214,7 @@ export function createBridge(ctx, config = {}) {
1192
1214
  throw new HiveRequestError('hive/queen-unavailable', 'queen controller is unavailable', 500)
1193
1215
  }
1194
1216
  queen.mark({ sessionId, cwd, source: 'manual' })
1195
- registerQueenSession(sessionId)
1217
+ registerQueenSession(sessionId, cwd)
1196
1218
  return { status: 200, body: { ok: true, code: 0, stdout: '', stderr: '' } }
1197
1219
  }
1198
1220
  if (actionName === QUEEN_OFF_ACTION) {
@@ -1337,7 +1359,7 @@ export function apply(ctx, config = {}) {
1337
1359
  const queen = createQueen(ctx, {
1338
1360
  log,
1339
1361
  autoQueen,
1340
- onAutoActivate: (sessionId) => { registerQueenSession(sessionId) },
1362
+ onAutoActivate: (sessionId, cwd) => { registerQueenSession(sessionId, cwd) },
1341
1363
  })
1342
1364
  ctx.effect(() => () => { queen.dispose() }, 'hive-panel: queen state')
1343
1365
  const bridge = createBridge(ctx, {
package/lib/queen.js CHANGED
@@ -66,10 +66,13 @@ export const QUEEN_FALLBACK_ROLE = '# Queen\n\nYou plan and coordinate; you neve
66
66
  *
67
67
  * They do not depend on the workspace role file, so a stale or custom
68
68
  * `.hive/roles/queen.md` (written by an older `hive init`) cannot remove the
69
- * production boundary that keeps the queen from implementing work herself. The
70
- * workspace text stays untrusted below this block.
69
+ * production boundary that keeps the queen from implementing work herself: no
70
+ * subagent tools, and (for repositories initialised by an older `hive init` whose
71
+ * role file predates this contract) no write/edit/apply_patch/bash/cua either.
72
+ * Tasks and state go through `hive_*` tools; claim/done/fail stay worker actions.
73
+ * The workspace text stays untrusted below this block.
71
74
  */
72
- export const QUEEN_INVARIANTS = '[hive:queen] trusted invariants (plugin-owned, cannot be overridden by the workspace): never call subagent/subagent_fork/subagent_claude_code or any execution tool to implement work; every goal becomes Hive tasks (hive_tasks add/plan) and the supervisor dispatches them. Classify each message (chat/progress/goal change/discussion/question/execute); discussion creates tasks only when the human asks to execute. Explain the classification only when it changes what the human expects.'
75
+ export const QUEEN_INVARIANTS = '[hive:queen] trusted invariants (plugin-owned, cannot be overridden by the workspace): never call subagent/subagent_fork/subagent_claude_code or any execution tool to implement work; every goal becomes Hive tasks (hive_tasks add/plan) and the supervisor dispatches them. Classify each message (chat/progress/goal change/discussion/question/execute); discussion creates tasks only when the human asks to execute. Explain the classification only when it changes what the human expects. Tool boundary: never call write, edit, apply_patch, bash, cua or any other file-mutating or command-executing tool; use only hive_* tools for tasks and state; claim/done/fail are worker actions and the queen must never call them; implementation is delegated to the supervisor. 工具边界:禁止调用 write、edit、apply_patch、bash、cua 等任何修改文件或执行命令的工具;任务与状态只能使用 hive_* 工具;claim/done/fail 属于 worker 动作,女王不得调用;具体实现交给 supervisor。'
73
76
 
74
77
  /** Short exit hint appended to every rendered role. */
75
78
  export const QUEEN_EXIT_HINT = '\n\n[hive] Queen mode: plan, split, order, supervise, review, report; never edit code or commit, never call subagent tools — create Hive tasks and let the supervisor dispatch. Fine-grained cards; every card needs an acceptance command. Load the hive-queen skill. Exit with /queen off.'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-hive-panel",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Hive board and queen mode inside DSH Web: a conversation view scoped to the Session's repository, with allowlisted task-card actions over DSH's shell seam.",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -917,7 +917,14 @@ async function call(route, { method = 'GET', query = {}, body } = {}) {
917
917
  // ── 11b. prompt auto-injection works without the panel ─────────────────────
918
918
  {
919
919
  const calls = []
920
- const supervisor = { setQueenSession(sessionId) { calls.push(sessionId) } }
920
+ const repos = []
921
+ const removals = []
922
+ const supervisor = {
923
+ setQueenSession(sessionId) { calls.push(sessionId) },
924
+ addRepo(repo) { if (!repos.includes(repo)) repos.push(repo); return { repo } },
925
+ hasRepo(repo) { return repos.includes(repo) },
926
+ removeRepo(repo) { removals.push(repo) },
927
+ }
921
928
  const shim = createCtx({
922
929
  live: new Map([
923
930
  ['s-auto', { id: 's-auto', header: { id: 's-auto', cwd: repo } }],
@@ -941,10 +948,13 @@ async function call(route, { method = 'GET', query = {}, body } = {}) {
941
948
  assert.ok(text.includes(join(repo, '.hive', 'roles', 'queen.md')), 'the auto-injected text must name its role file')
942
949
  assert.ok(text.includes('[hive:queen] trusted invariants'), 'prompt auto-injection must carry the trusted invariants')
943
950
  assert.deepEqual(calls, ['s-auto'], 'prompt auto-injection must register the queen Session with the supervisor')
951
+ assert.deepEqual(repos, [repo], 'prompt auto-injection must register the queen repository with the supervisor')
944
952
  assert.equal(section.text({ agent: autoAgent }), text, 'repeat assemblies reuse the same injection')
945
953
  assert.deepEqual(calls, ['s-auto'], 'the supervisor registration must be idempotent')
954
+ assert.deepEqual(repos, [repo], 'the supervisor repository registration must be deduplicated')
946
955
  assert.equal(section.text({ agent: plainAgent }), '', 'a Session whose cwd has no queen role file must not be injected')
947
956
  assert.deepEqual(calls, ['s-auto'], 'a Session in another repository is never registered')
957
+ assert.deepEqual(repos, [repo], 'an uninitialised repository is never registered as a supervisor repo')
948
958
  // Card workers / delegated children share the repo cwd but must never be queens.
949
959
  const workerAgent = { session: { id: 's-worker', header: { id: 's-worker', cwd: repo, origin: 'subagent', delegationDepth: 1 } } }
950
960
  assert.equal(section.text({ agent: workerAgent }), '', 'a subagent Session must never be auto-queened')
@@ -955,7 +965,9 @@ async function call(route, { method = 'GET', query = {}, body } = {}) {
955
965
  assert.deepEqual(snap.body.queen, { active: true, source: 'auto', repo })
956
966
  const plainSnap = await call(shim.routes.get('/api/hive'), { query: { op: 'snapshot', sessionId: 's-plain' } })
957
967
  assert.deepEqual(plainSnap.body.queen, { active: false, source: null, repo: other })
958
- ok('the first system-prompt assembly auto-injects the queen and registers the supervisor, without a panel request')
968
+ assert.deepEqual(repos, [repo], 'the snapshot path must not register an uninitialised repository either')
969
+ assert.deepEqual(removals, [], 'no path may remove a repository registration')
970
+ ok('the first system-prompt assembly auto-injects the queen and registers the repo + supervisor, without a panel request')
959
971
  }
960
972
 
961
973
  // ── 11c. prompt auto-injection respects /queen off, autoQueen and init state ──
@@ -991,6 +1003,53 @@ async function call(route, { method = 'GET', query = {}, body } = {}) {
991
1003
  ok('prompt auto-injection honours /queen off, autoQueen=false and uninitialised repositories')
992
1004
  }
993
1005
 
1006
+ // ── 11d. panel init/queen-on register the queen repo with the supervisor ───
1007
+ {
1008
+ const repos = []
1009
+ const removals = []
1010
+ const sessions = []
1011
+ const supervisor = {
1012
+ addRepo(repo) { if (!repos.includes(repo)) repos.push(repo); return { repo } },
1013
+ hasRepo(repo) { return repos.includes(repo) },
1014
+ removeRepo(repo) { removals.push(repo) },
1015
+ setQueenSession(sessionId) { sessions.push(sessionId) },
1016
+ }
1017
+ const shim = createCtx({
1018
+ live: new Map([
1019
+ ['s-live', { id: 's-live', header: { id: 's-live', cwd: repo } }],
1020
+ ['s-other', { id: 's-other', header: { id: 's-other', cwd: other } }],
1021
+ ]),
1022
+ cwdOf,
1023
+ supervisor,
1024
+ })
1025
+ host.apply(shim.ctx, { writable: true })
1026
+ const route = shim.routes.get('/api/hive')
1027
+
1028
+ const init = await call(route, { method: 'POST', query: { op: 'action', name: 'init', sessionId: 's-live' }, body: {} })
1029
+ assert.equal(init.status, 200)
1030
+ assert.equal(init.body.ok, true)
1031
+ assert.deepEqual(repos, [repo], 'the init action must register the queen cwd with the supervisor')
1032
+ assert.deepEqual(sessions, ['s-live'], 'the init action must also register the queen Session')
1033
+
1034
+ // Repeated activation (queen-on + snapshot) is deduplicated by the supervisor.
1035
+ await call(route, { method: 'POST', query: { op: 'action', name: 'queen-on', sessionId: 's-live' }, body: {} })
1036
+ await call(route, { query: { op: 'snapshot', sessionId: 's-live' } })
1037
+ assert.deepEqual(repos, [repo], 're-registering the same repo must stay a single entry')
1038
+
1039
+ // Only repositories with .hive/roles/queen.md are registered.
1040
+ const otherOn = await call(route, { method: 'POST', query: { op: 'action', name: 'queen-on', sessionId: 's-other' }, body: {} })
1041
+ assert.equal(otherOn.status, 200)
1042
+ assert.deepEqual(repos, [repo], 'an uninitialised repository must never be added to the supervisor')
1043
+ assert.deepEqual([...new Set(sessions)], ['s-live', 's-other'], 'the fallback queen Session still registers itself (idempotent at the supervisor)')
1044
+
1045
+ // Leaving queen mode never removes the repository registration (one-way).
1046
+ await call(route, { method: 'POST', query: { op: 'action', name: 'queen-off', sessionId: 's-live' }, body: {} })
1047
+ await call(route, { query: { op: 'snapshot', sessionId: 's-live' } })
1048
+ assert.deepEqual(repos, [repo], 'queen-off must not drop the repository registration')
1049
+ assert.deepEqual(removals, [], 'the panel must never call removeRepo on exit/unload')
1050
+ ok('panel init/queen-on register the queen cwd with the supervisor (idempotent, initialised repos only, one-way)')
1051
+ }
1052
+
994
1053
  // ── 12. queen activation / scope / exit ─────────────────────────────────────
995
1054
  {
996
1055
  const shim = createCtx({
@@ -1027,6 +1086,17 @@ async function call(route, { method = 'GET', query = {}, body } = {}) {
1027
1086
  assert.ok(text.length <= 24576, 'the role text must be capped at 24576 characters')
1028
1087
  assert.ok(text.includes('[hive:queen] trusted invariants'), 'the trusted invariants block must be injected')
1029
1088
  assert.match(text, /never call subagent/, 'the trusted invariants must forbid subagent implementation')
1089
+ // Tool boundary: an old repository whose role file predates this contract must
1090
+ // still be forbidden from mutating files or running commands.
1091
+ for (const keyword of ['write', 'edit', 'apply_patch', 'bash', 'cua']) {
1092
+ assert.ok(queenModule.QUEEN_INVARIANTS.includes(keyword), 'QUEEN_INVARIANTS must ban ' + keyword)
1093
+ assert.ok(text.includes(keyword), 'the injected queen text must ban ' + keyword)
1094
+ }
1095
+ assert.ok(queenModule.QUEEN_INVARIANTS.includes('claim'), 'QUEEN_INVARIANTS must reserve claim/done/fail for workers')
1096
+ assert.ok(text.includes('claim/done/fail are worker actions'), 'the injected text must say claim/done/fail are worker actions')
1097
+ assert.ok(text.includes('hive_*'), 'the injected text must route tasks and state through hive_* tools')
1098
+ assert.ok(text.includes('工具边界'), 'the injected invariants must carry the Chinese tool-boundary line')
1099
+ assert.ok(text.includes('never call write, edit, apply_patch, bash, cua'), 'the English tool-boundary sentence must be injected')
1030
1100
  assert.ok(text.indexOf('trusted invariants') < text.indexOf('Exit with /queen off.'), 'invariants come before the exit hint')
1031
1101
  assert.ok(text.includes('Fine-grained cards; every card needs an acceptance command.'), 'the exit hint must carry the coordinator contract')
1032
1102
  assert.ok(text.includes('Exit with /queen off.'), 'the exit hint must name /queen off')
@@ -1053,6 +1123,7 @@ async function call(route, { method = 'GET', query = {}, body } = {}) {
1053
1123
  assert.match(fallbackText, /Load the hive-queen skill/)
1054
1124
  assert.ok(fallbackText.length <= 24576)
1055
1125
  assert.ok(fallbackText.includes('[hive:queen] trusted invariants'), 'the fallback path must keep the trusted invariants')
1126
+ ok('the trusted invariants ban file/command tools (write/edit/apply_patch/bash/cua, claim) and route state through hive_* tools')
1056
1127
  ok('init + refs/hive/v1 marks only that Session; /queen off and name=queen-off both clear it; a missing role file uses the coordinator fallback')
1057
1128
  }
1058
1129