dsh-hive-runner 1.0.10 → 1.0.11

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,19 @@ 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
+ ## [1.0.11] - 2026-12-05
11
+
12
+ ### Fixed
13
+
14
+ - Worker Sessions are no longer mistaken for the queen. The supervisor exposes
15
+ `isWorkerSession(sessionId)` / `workerSessionIds()` (backed by `activeRuns`, with
16
+ status top-level `workerSessionIds` for the panel); local providers reserve the
17
+ child Session id before activation and put it in `activeRuns`, closing the
18
+ just-activated window. The queen tool guard returns before any classification for
19
+ worker Sessions, with `origin: "subagent"`, positive `delegationDepth`, or
20
+ `parentSession === queenSessionId` as the restart/provider fallback, so a worker's
21
+ write/edit/bash and subagent tools keep working while the queen is still denied.
22
+
10
23
  ## [1.0.10] - 2026-12-05
11
24
 
12
25
  ### Fixed
@@ -25,6 +38,10 @@ iterations of the plugin before this repository was published.
25
38
  repository (plus an aggregate `claimedButOrphaned` at the top level), so a panel
26
39
  can distinguish recovered stale claims from real in-flight work.
27
40
 
41
+ ### Published
42
+
43
+ - npm: `dsh-hive-runner@1.0.10` on 2026-12-05.
44
+
28
45
  ## [1.0.9] - 2026-12-05
29
46
 
30
47
  ### Removed
package/README.md CHANGED
@@ -114,9 +114,13 @@ is a Hive-initialized repository (`.hive/roles/queen.md`), so it works without t
114
114
  panel; `/queen off` explicitly exempts that Session, and detection registers it
115
115
  idempotently so the panel can show it. Task
116
116
  metadata (add/reopen/retry/rm), roles and lessons are coordination state, not code.
117
- The veto covers only the queen's own tool calls: supervisor dispatch
118
- (`ctx.subagents.startActivation`) and a worker's own subagent calls are not tool
119
- calls and remain allowed.
117
+ Worker Sessions are exempt first: the guard asks the supervisor's
118
+ `isWorkerSession(sessionId)` registry (activeRuns, including a child id reserved
119
+ before activation) and falls back to `parentSession === queenSessionId` or
120
+ `origin: "subagent"`, so a card worker keeps write/edit/bash even when its cwd is
121
+ the initialized repository. The veto covers only the queen's own tool calls;
122
+ supervisor dispatch (`ctx.subagents.startActivation`) and a worker's own subagent
123
+ calls are not tool calls and remain allowed.
120
124
 
121
125
  ### When the queen hears from the supervisor
122
126
 
package/README.zh-CN.md CHANGED
@@ -69,6 +69,10 @@
69
69
  智能体和 supervisor),也没有改代码或 commit 的工具;女王契约同样禁止改代码。任务元数据
70
70
  (add/reopen/retry/rm)、角色和经验属于协调状态,不是代码。
71
71
 
72
+ worker 会话优先豁免:guard 先查 supervisor 的 `isWorkerSession(sessionId)`(activeRuns,含
73
+ activation 前预留的 child id),再用 `parentSession === queenSessionId` 或 `origin: "subagent"`
74
+ 兜底,因此 worker 的 write/edit/bash 不会被当成女王越界,即使它的 cwd 是已初始化的仓库。
75
+
72
76
  ### supervisor 什么时候找女王
73
77
 
74
78
  runner 把监督事件——`card-failed`、`card-timeout`、`heartbeat-warn`、
package/SPEC.md CHANGED
@@ -63,6 +63,7 @@ wrong method -> `405` (`hive/method-not-allowed`).
63
63
  "pendingAnomalies": 0,
64
64
  "repoCount": 1,
65
65
  "claimedButOrphaned": 0,
66
+ "workerSessionIds": ["worker-session-id"],
66
67
  "repos": [
67
68
  {
68
69
  "repo": "/abs/repo",
@@ -132,6 +133,9 @@ wrong method -> `405` (`hive/method-not-allowed`).
132
133
  identity (not by another agent) and not backed by a live worker, then reopens them
133
134
  with reason `orphaned by supervisor restart`; the values are the detected and
134
135
  reopened counts and the recovery time. The top-level status aggregates the counts.
136
+ - `workerSessionIds` — worker Session ids across repositories, also available via
137
+ `hiveSupervisor.isWorkerSession(sessionId)` / `workerSessionIds()`; the panel uses
138
+ this to keep worker conversations out of queen mode.
135
139
  - `workers` — the agents currently running in this repository, each with
136
140
  `cardId`, `role`, `agent`, `sessionId`, `agentName`, `parentSource` (`queen`),
137
141
  `startedAt`, `lastOutputAt`,
@@ -385,7 +389,12 @@ fails with `女王不改代码,请用 hive_tasks 建任务,执行交给 supe
385
389
  pushed as a `queen-boundary-violation` anomaly so the digest reaches the queen, and
386
390
  counted in status (`queenBoundaryViolations`, `lastQueenBoundaryViolation`). A cwd-
387
391
  recognized queen is also registered through `setQueenSession()` (idempotent) so the
388
- panel can display it. The guard sees model-requested tool executions only; supervisor dispatch through
392
+ panel can display it. Worker Sessions are exempt from the whole boundary: the guard
393
+ first asks `hiveSupervisor.isWorkerSession(sessionId)` (activeRuns, including the
394
+ reserved child id before activation) and falls back to header lineage
395
+ (`origin: "subagent"`, positive `delegationDepth`, or `parentSession === queenSessionId`),
396
+ returning before any queen classification so write/edit/bash work normally. The guard
397
+ sees model-requested tool executions only; supervisor dispatch through
389
398
  `ctx.subagents.startActivation` and a worker's own subagent calls do not pass through
390
399
  it, so the swarm and worker delegation keep working.
391
400
 
package/docs/DESIGN.md CHANGED
@@ -52,6 +52,7 @@ Response:
52
52
  "pendingAnomalies": 0,
53
53
  "repoCount": 1,
54
54
  "claimedButOrphaned": 0,
55
+ "workerSessionIds": ["worker-session-id"],
55
56
  "repos": [
56
57
  {
57
58
  "repo": "/abs/repo",
@@ -127,6 +128,12 @@ Response:
127
128
  `orphaned by supervisor restart`) before normal dispatch; `claimedButOrphaned`
128
129
  is the count found, `orphanRecovered` the count reopened. Claims owned by other
129
130
  agents are not touched. Top-level status aggregates the per-repo counts.
131
+ - `workerSessionIds` — all live worker Session ids across repositories. The panel
132
+ reads this (or calls the `hiveSupervisor.isWorkerSession(sessionId)` /
133
+ `workerSessionIds()` service methods) to exempt worker conversations from queen
134
+ prompt injection and the queen tool guard. A local provider's child id is reserved
135
+ and placed in `activeRuns` before activation, so the just-activated window is
136
+ covered too.
130
137
  - `workers` — live agents in this repository: `cardId`, `role`, `agent`,
131
138
  `sessionId`, `agentName`, `startedAt`, `lastOutputAt`, `heartbeat`
132
139
  (`ok`/`warn`), `claimDeadline`, `timeoutAt`. The Session id is written into the
@@ -348,11 +355,14 @@ needed and is not implemented.
348
355
  - it also becomes a `queen-boundary-violation` anomaly, so the coalesced anomaly digest
349
356
  tells the queen to self-correct; `status` exposes `queenBoundaryViolations` and
350
357
  `lastQueenBoundaryViolation`;
351
- - it only vetoes **model-requested tool calls from the queen Session**. The
352
- supervisor's swarm dispatch (`ctx.subagents.startActivation`) is a service call,
353
- not a tool execution, so it bypasses `tools.guard` and keeps working from the same
354
- queen Session; worker/child Sessions and their own subagent tools are unaffected
355
- (PTC nested tool calls share the same pipeline and are covered by the predicate).
358
+ - it only vetoes **model-requested tool calls from the queen Session**. Worker
359
+ Sessions are checked first and get **every tool back** (write/edit/bash/...) so a
360
+ card can actually run: the supervisor's `isWorkerSession(sessionId)` registry
361
+ (activeRuns, including a locally reserved child id before activation) is
362
+ authoritative; the Session header (`origin: "subagent"`, positive
363
+ `delegationDepth`, or `parentSession === queenSessionId`) is the restart/provider
364
+ fallback. The supervisor's swarm dispatch (`ctx.subagents.startActivation`) is a
365
+ service call, not a tool execution, so it bypasses `tools.guard` as well.
356
366
 
357
367
  Tests: `test/queen-boundary.test.js` covers all three delegation tools and the
358
368
  mutation tools (write/edit/bash/notebook/run_code denied; read/grep/web/hive allowed),
package/index.js CHANGED
@@ -197,6 +197,8 @@ export function apply(ctx, config = {}) {
197
197
  onViolation: recordQueenBoundaryViolation,
198
198
  onQueenDetected: registerDetectedQueen,
199
199
  resolveCwd: resolveQueenBoundaryCwd,
200
+ // Authoritative worker registry (activeRuns, incl. reserved child ids).
201
+ isWorkerSession: (sessionId) => supervisor.isWorkerSession(sessionId),
200
202
  log,
201
203
  })));
202
204
 
@@ -180,12 +180,23 @@ export function isQueenSuppressed(session) {
180
180
  return latestQueenCommand(session) === 'off';
181
181
  }
182
182
 
183
- /** Whether a Session is a card worker / delegation child, never the queen. */
184
- export function isWorkerSession(session) {
183
+ /**
184
+ * Session-header heuristic for a card worker / delegation child, never the
185
+ * queen. The authoritative check is the supervisor's activeRuns registry; this
186
+ * covers the window before a provider-reported child id reaches it and worker
187
+ * Sessions that survive a plugin restart.
188
+ * @param {object} session
189
+ * @param {string | null} [queenSessionId]
190
+ * @returns {boolean}
191
+ */
192
+ export function isWorkerSession(session, queenSessionId) {
185
193
  const header = session?.header;
186
194
  if (header === null || typeof header !== 'object') return false;
187
- return header.origin === 'subagent'
188
- || (Number.isInteger(header.delegationDepth) && header.delegationDepth > 0);
195
+ if (header.origin === 'subagent') return true;
196
+ if (Number.isInteger(header.delegationDepth) && header.delegationDepth > 0) return true;
197
+ return typeof queenSessionId === 'string'
198
+ && queenSessionId !== ''
199
+ && header.parentSession === queenSessionId;
189
200
  }
190
201
 
191
202
  /** Structured error identity recorded on the failed tool result. */
@@ -203,6 +214,7 @@ export const QUEEN_BOUNDARY_ERROR = Object.freeze({
203
214
  * resolveCwd?: (agent: object, session: object) => string | null,
204
215
  * hasRole?: (cwd: string) => boolean,
205
216
  * isSuppressed?: (session: object) => boolean,
217
+ * isWorkerSession?: (sessionId: string, session: object) => boolean,
206
218
  * log?: (level: string, ...args: unknown[]) => void,
207
219
  * }} options
208
220
  * @returns {(exec: { name: string, agent?: { session?: object } }) => object | undefined}
@@ -214,21 +226,34 @@ export function createQueenBoundaryGuard({
214
226
  resolveCwd,
215
227
  hasRole = hasQueenRole,
216
228
  isSuppressed = isQueenSuppressed,
229
+ isWorkerSession: isKnownWorkerSession,
217
230
  log = () => {},
218
231
  } = {}) {
219
232
  return function queenBoundaryGuard(exec) {
220
233
  if (exec === null || typeof exec !== 'object') return undefined;
221
- const toolClass = queenBoundaryToolClass(exec.name);
222
- if (toolClass === null) return undefined;
223
234
  const session = exec.agent?.session;
224
235
  const sessionId = session?.id;
225
236
  if (typeof sessionId !== 'string' || sessionId === '') return undefined;
226
237
 
227
238
  const queenSessionId = queenSession?.sessionId;
228
239
  const registered = typeof queenSessionId === 'string' && queenSessionId !== '' && sessionId === queenSessionId;
229
- // Worker/child Sessions never need the (possibly long) log scan and are
230
- // outside the queen boundary.
231
- if (!registered && isWorkerSession(session)) return undefined;
240
+ // Workers are never the queen: the supervisor's activeRuns registry is
241
+ // authoritative (including a child id reserved before activation), and
242
+ // the Session header covers the provider/restart window. A worker gets
243
+ // every tool back, before any queen recognition or log scan.
244
+ let worker = false;
245
+ try {
246
+ worker = typeof isKnownWorkerSession === 'function'
247
+ ? isKnownWorkerSession(sessionId, session) === true
248
+ : false;
249
+ } catch {
250
+ worker = false;
251
+ }
252
+ if (!worker) worker = isWorkerSession(session, queenSessionId);
253
+ if (worker) return undefined;
254
+
255
+ const toolClass = queenBoundaryToolClass(exec.name);
256
+ if (toolClass === null) return undefined;
232
257
 
233
258
  // `/queen off` wins over both recognition paths.
234
259
  let suppressed = false;
@@ -246,7 +271,7 @@ export function createQueenBoundaryGuard({
246
271
  } catch {
247
272
  cwd = null;
248
273
  }
249
- const initialised = !isWorkerSession(session) && hasRole(cwd);
274
+ const initialised = hasRole(cwd);
250
275
  if (!registered && !initialised) return undefined;
251
276
 
252
277
  if (!registered && initialised && typeof onQueenDetected === 'function') {
package/lib/round.js CHANGED
@@ -15,6 +15,8 @@
15
15
  * (missing hook = deferrable environment error, run `hive init`) and a card is
16
16
  * only recorded done when HEAD moved through that hook-equipped commit path.
17
17
  */
18
+ import { randomUUID } from 'node:crypto';
19
+
18
20
  import { parseTtlMs, roleLimitForRepo } from './config.js';
19
21
  import { HiveCommandError, tail } from './commands.js';
20
22
  import { assertMergeOnCommitHook } from './hooks.js';
@@ -546,6 +548,22 @@ export function createRoundRunner({
546
548
  // claim identity and this card's instance while the worker is alive, so
547
549
  // its own `hive guard` / `hive release` calls agree with the runner's.
548
550
  releaseEnv = acquireHiveAgentEnv(claimAgent, instance);
551
+ // Local providers can reserve the child Session id before activation.
552
+ // Recording it on the active run closes the window where a just-started
553
+ // worker calls a tool before the provider-reported id reaches activeRuns
554
+ // (the guard consults that registry to exempt worker Sessions).
555
+ let reservedChildId;
556
+ try {
557
+ const provider = typeof service.getProvider === 'function' ? service.getProvider(config.provider) : undefined;
558
+ if (provider !== undefined && typeof provider.prepareContinuable === 'function') reservedChildId = randomUUID();
559
+ } catch {
560
+ reservedChildId = undefined;
561
+ }
562
+ if (typeof reservedChildId === 'string') {
563
+ run.sessionId = reservedChildId;
564
+ recordRun(repo, run);
565
+ }
566
+
549
567
  // Hard per-card timeout: abort the worker at the deadline.
550
568
  timeoutTimer = setTimeout(() => {
551
569
  if (settled) return;
@@ -569,6 +587,7 @@ export function createRoundRunner({
569
587
  parent: owner,
570
588
  signal: workerSignal,
571
589
  delivery: 'caller',
590
+ ...(reservedChildId === undefined ? {} : { childId: reservedChildId }),
572
591
  }),
573
592
  abortWait.then(() => null),
574
593
  ]);
package/lib/supervisor.js CHANGED
@@ -389,6 +389,38 @@ export class HiveSupervisor {
389
389
  return this.status();
390
390
  }
391
391
 
392
+ /**
393
+ * Live worker Session ids across every registered repository. The panel uses
394
+ * this to exempt worker conversations from the queen role/prompt and guard.
395
+ * @returns {string[]}
396
+ */
397
+ workerSessionIds() {
398
+ const ids = new Set();
399
+ for (const entry of this.repos.values()) {
400
+ for (const worker of this.#workers(entry.repo)) {
401
+ if (typeof worker?.sessionId === 'string' && worker.sessionId !== '') ids.add(worker.sessionId);
402
+ }
403
+ }
404
+ return [...ids];
405
+ }
406
+
407
+ /**
408
+ * Whether a Session is one of the supervisor's card workers. This is the
409
+ * authoritative registry check used by the queen tool guard and the panel;
410
+ * guard fallbacks based on Session header lineage cover the short window
411
+ * before a provider-reported child id reaches activeRuns.
412
+ * @param {string} sessionId
413
+ * @returns {boolean}
414
+ */
415
+ isWorkerSession(sessionId) {
416
+ if (typeof sessionId !== 'string' || sessionId === '') return false;
417
+ for (const entry of this.repos.values()) {
418
+ for (const worker of this.#workers(entry.repo)) {
419
+ if (worker?.sessionId === sessionId) return true;
420
+ }
421
+ }
422
+ return false;
423
+ }
392
424
  /**
393
425
  * Read every card of one repository and compute the gate phase that governs
394
426
  * dispatch. Falls back to an explicit phase when the board read fails; a
@@ -518,6 +550,9 @@ export class HiveSupervisor {
518
550
  // Undelivered anomaly digests waiting for a live queen Session.
519
551
  pendingAnomalies: this.#pendingAnomalyCount(),
520
552
  repoCount: this.repos.size,
553
+ // Worker Session ids across all repositories: the panel exempts them from
554
+ // queen-mode prompt injection and the guard exempts their tool calls.
555
+ workerSessionIds: this.workerSessionIds(),
521
556
  // Aggregate of the per-repository orphan-claim counts.
522
557
  claimedButOrphaned: repoSnapshots.reduce((sum, repo) => sum + repo.claimedButOrphaned, 0),
523
558
  repos: repoSnapshots,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-hive-runner",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "description": "DSH host plugin for Hive: a resident supervisor that runs one DSH subagent per ready task card, with per-role worker limits, pause/resume and Hive tools.",
5
5
  "type": "module",
6
6
  "main": "./index.js",