dsh-hive-runner 1.0.15 → 1.0.17

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,66 @@ 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.17] - 2026-12-05
11
+
12
+ ### Added
13
+
14
+ - Queen-only `hive_ops` with an explicit action enum (`status`, `pause`, `resume`,
15
+ `limits`, `run-round`, `health`, `services`, `diagnose`, `test`, `typecheck`, `build`)
16
+ instead of an open shell. `diagnose` accepts only `git status/log/diff/show`, `ls`,
17
+ `curl 127.0.0.1` and `lsof` (plus `.hive/ops.yaml` extensions); `test/typecheck/build`
18
+ run only the fixed pnpm script. Shell actions use the sandboxed shell seam with a
19
+ 120 s timeout and 64 KiB output cap; all actions/denials write a `hive_ops` event.
20
+ Repository isolation is enforced by the common hive_* wrapper and queen-only callers.
21
+ - Long-running services are agent work, not a human step: `.hive/services.yaml` declares
22
+ name/command/port/health; a service-role card starts the declared command detached
23
+ (`setsid nohup … >> .hive/services/<name>.log 2>&1 &`) and records PID/port in
24
+ `.hive/services/<name>.json`; acceptance is the local health check. The patrol probes
25
+ declared ports, emits `service_down`/`service_started`, and creates/reopens a service
26
+ card when a service is down. `hive_ops action=services` lists them; undeclared
27
+ commands/ports are rejected.
28
+
29
+ ### Tests
30
+
31
+ - Action enum mapping, diagnose allow/deny/extension, long-running rejection, 120 s
32
+ timeout/64 KiB truncation and `hive_ops` events; service declaration validation,
33
+ detached start/PID record, health acceptance, down/recovery redispatch and failed-card
34
+ reopen. 271 tests pass.
35
+
36
+ ## [1.0.16] - 2026-12-05
37
+
38
+ ### Fixed — hard repository isolation (release blocker)
39
+
40
+ - Queen registration is now a repo → latest-Session mapping (`setQueenSession`,
41
+ HTTP `op=queen` with `repo`; a single-repo deployment may omit it, a one-argument
42
+ panel call infers the repo from the live Session cwd). `status.queens` exposes the
43
+ mapping and each repo reports `queenSessionId`/`unmanaged`.
44
+ - Dispatch and parenting are per repo: only a repo with a registered queen dispatches;
45
+ unmanaged repos never dispatch. The round runner passes the repo to the parent
46
+ provider so workers use that repo's queen agent.
47
+ - Delivery is per repo: anomaly digests are grouped by repo and checkpoints are only
48
+ delivered to the matching queen; no match stays pending. No cross-repo fallback.
49
+ - Tool layer is mechanically enforced: every `hive_*` tool with a `repo` parameter
50
+ rejects a queen call whose repo differs from the Session cwd (omitted means cwd)
51
+ before the body runs, with `女王只能操作自己所在的仓库`, and increments status
52
+ `crossRepoBlocked` / `lastCrossRepoBlocked`.
53
+ - Event writers require an absolute repo and reject a `.hive` symlink that would
54
+ redirect the append outside the repository. Orphan recovery remains per repo and
55
+ per runner identity.
56
+ - `.hive` events/checkpoints and anomaly delivery no longer leak between repos;
57
+ concurrency (pause and role limits) stays isolated per repository.
58
+
59
+ ### Tests
60
+
61
+ - New per-layer isolation suite: dispatch/unmanaged, latest-queen-per-repo, pause and
62
+ role-limit isolation, notifier/anomaly/checkpoint delivery, tool-scope rejection for
63
+ `hive_tasks`/`hive_intervene`/`hive_arch_review`/`hive_board`/`hive_events`,
64
+ event-path symlink escape, recovery, and grouped status. 258 tests pass.
65
+
66
+ ### Published
67
+
68
+ - npm: `dsh-hive-runner@1.0.16` on 2026-12-05.
69
+
10
70
  ## [1.0.15] - 2026-12-05
11
71
 
12
72
  ### Fixed
@@ -25,6 +85,10 @@ iterations of the plugin before this repository was published.
25
85
  the same durable `arch_review` event through the shared host writer, so a caller can
26
86
  repair reviews when an agent tool is unavailable; `hive_events` verifies it.
27
87
 
88
+ ### Published
89
+
90
+ - npm: `dsh-hive-runner@1.0.15` on 2026-12-05.
91
+
28
92
  ## [1.0.14] - 2026-12-05
29
93
 
30
94
  ### Fixed
package/README.md CHANGED
@@ -98,6 +98,7 @@ she must act on. The authoritative contract is `<repo>/.hive/roles/queen.md` (wr
98
98
  | `hive_anomalies` | `list`/`ack` the pending anomaly digest, `patrol` runs one audit tick now |
99
99
  | `hive_intervene` | act on a stuck task (reopen/split/reassign/remove/rebuild/pause/fail/guide/escalate) and record it as an event |
100
100
  | `hive_run_round` | run one round on demand (a registered queen Session is required) |
101
+ | `hive_ops` | queen-only operational actions: `status`/`pause`/`resume`/`limits`/`run-round`/`health`/`services` plus the whitelisted `diagnose` and fixed `test`/`typecheck`/`build`; no shell escape, 120 s timeout, 64 KiB cap |
101
102
 
102
103
  The tool surface keeps the boundary: none of the queen's tools claims or finishes a task
103
104
  (`hive-tasks claim` / `done` belong to agents and the supervisor), and none edits or
@@ -164,6 +165,19 @@ confirm release. The same state is sent once; a state change re-arms it. With no
164
165
  queen Session the checkpoint stays pending (`pendingCheckpoints` in status) and is
165
166
  flushed on the next patrol/registration.
166
167
 
168
+ ### Long-running services
169
+
170
+ Long-running processes are agent work, not a human step. A repository can declare
171
+ its services in `.hive/services.yaml` (`name`, `command`, `port`, optional 127.0.0.1
172
+ `health`). A `service`-role card starts one with a detached
173
+ `setsid nohup <command> >> .hive/services/<name>.log 2>&1 &` and records
174
+ `.hive/services/<name>.json` (PID/port). The acceptance command is a local health
175
+ check, so the card can be done while the service keeps running. The patrol reads the
176
+ records, probes the declared ports, and creates/reopens a service card when a service
177
+ is down, recording `service_down` / `service_started` events. `hive_ops action=services`
178
+ shows declared/running state; commands and ports outside `.hive/services.yaml` are
179
+ rejected.
180
+
167
181
  ### The gates the queen orchestrates
168
182
 
169
183
  1. **Single task**: the agent commits and the task acceptance command must pass.
package/SPEC.md CHANGED
@@ -54,9 +54,12 @@ wrong method -> `405` (`hive/method-not-allowed`).
54
54
  "repoRoleConcurrency": {},
55
55
  "defaultRoleConcurrency": 5,
56
56
  "capacityRetryMs": 2000,
57
+ "queens": [{ "repo": "/abs/repo", "sessionId": "queen-session-id" }],
57
58
  "queenSessionId": "queen-session-id",
58
59
  "waiting": null,
59
60
  "queenBoundaryViolations": 0,
61
+ "crossRepoBlocked": 0,
62
+ "lastCrossRepoBlocked": null,
60
63
  "lastQueenBoundaryViolation": null,
61
64
  "lastTickAt": "2026-12-04T00:00:00.000Z",
62
65
  "lastDiscoverError": null,
@@ -83,6 +86,8 @@ wrong method -> `405` (`hive/method-not-allowed`).
83
86
  "consecutiveFailures": 0,
84
87
  "lastCards": 0,
85
88
  "lastResults": 0,
89
+ "queenSessionId": "queen-session-id",
90
+ "unmanaged": false,
86
91
  "waiting": null,
87
92
  "claimedButOrphaned": 0,
88
93
  "orphanRecovered": 0,
@@ -131,9 +136,13 @@ wrong method -> `405` (`hive/method-not-allowed`).
131
136
  - `repos` / `repoCount` — the status-visible repository registry. `hiveSupervisor.addRepo(repo)`
132
137
  adds one at runtime (absolute path, must be an initialized Hive repository; idempotent;
133
138
  rejects a relative or uninitialized path).
134
- - `queenSessionId` — the queen conversation registered by the panel; agents are
135
- parented to that Session while it is live (see §8). `waiting` is
136
- `"no-queen-session"` until that registration happens.
139
+ - `queens` — repo → queen Session mapping (`[{ repo, sessionId }]`, latest per repo).
140
+ Workers are parented only to the queen of their repo. `queenSessionId`/`waiting`
141
+ are a single-queen compatibility view (global id is `null` with several queens).
142
+ - `crossRepoBlocked` / `lastCrossRepoBlocked` — queen hive_* calls rejected because
143
+ `repo` did not resolve to the Session cwd (`女王只能操作自己所在的仓库`).
144
+ - Per-repo `queenSessionId`/`unmanaged` — a repo with no matching queen is unmanaged,
145
+ never dispatched to and never notified.
137
146
  - `waiting` — per repository (and top level) `"no-queen-session"` before the queen
138
147
  Session is registered; then `null`. It is a startup-order hint, never an error.
139
148
  - `claimedButOrphaned` / `orphanRecovered` / `orphanRecoveryAt` — after a supervisor
@@ -243,7 +252,18 @@ repository unless it is that default.
243
252
  | `hive_supervisor_control` | `action` = `status`/`pause`/`resume`/`limits`, `repo`, `reason`, `roleLimits` | Supervisor/repository snapshot |
244
253
  | `hive_anomalies` | `action` = `list`/`ack`/`patrol`, `ids`, `all`, `limit` | Pending digest queue or one patrol result |
245
254
  | `hive_intervene` | `repo`, `action: reopen|split|reassign|pause|abort|fail|guide|supersede|remove|rebuild|escalate`, `card`, `reason`, `cards[]`, `role`, `sessionId` | The intervention event, created tasks, intervention count and escalation flag |
246
-
255
+ | `hive_ops` | `repo`, `action: status|pause|resume|limits|run-round|health|diagnose|test|typecheck|build|services`, `args?` | Queen-only operational action result; `diagnose` is restricted to the read-only whitelist, shell actions have a 120 s timeout and 64 KiB cap, and every action/denial appends a `hive_ops` event |
256
+
257
+ ### 7.1 Long-running services
258
+
259
+ `.hive/services.yaml` is the only service allowlist: each entry declares `name`,
260
+ `command`, `port` and an optional 127.0.0.1 `health`. A `service`-role card starts the
261
+ declared command detached (`setsid nohup <command> >> .hive/services/<name>.log 2>&1 &`),
262
+ writes `.hive/services/<name>.json` with pointer/PID/port, and its acceptance is the local
263
+ health check; the card can be done while the service keeps running. The patrol reads the
264
+ records, probes the declared ports, and creates or reopens a service card when a service
265
+ is down, emitting `service_down`/`service_started` events. Commands or ports outside the
266
+ YAML are rejected. `hive_ops action=services` lists declared/running state.
247
267
  The queen's tools never claim or finish a task: `hive-tasks claim`/`done` stay with the
248
268
  supervisor. `hive tasks rm` is forwarded without `--force`, so a claimed task is refused
249
269
  by the CLI instead of being deleted under a live agent. `hive_run_round` refuses to run
@@ -402,6 +422,13 @@ A host-side fallback writes the same durable event without the agent tool:
402
422
  `hiveSupervisor.recordArchReview(repo, { card, verdict, findings, summary })`; the
403
423
  read-only `hive_events` tool verifies the appended event.
404
424
 
425
+ All queen actions are repository-scoped mechanically. Every `hive_*` tool with a
426
+ `repo` parameter is wrapped: for a registered queen the repo must resolve to the
427
+ Session cwd (omitted means cwd), otherwise the tool fails before its body with
428
+ `女王只能操作自己所在的仓库` and `crossRepoBlocked` increments. Anomaly/checkpoint
429
+ delivery is grouped per repo and only goes to that repo's queen; no match stays
430
+ pending. Repositories without a queen are unmanaged and never dispatch. Event writers
431
+ validate the absolute repo path and reject symlink escapes.
405
432
  ### 8.6.2 Queen tool boundary
406
433
 
407
434
  DSH's `ctx.tools.guard` lets a plugin veto a tool call after pre-execute policy and
package/docs/DESIGN.md CHANGED
@@ -43,10 +43,13 @@ Response:
43
43
  "repoRoleConcurrency": {},
44
44
  "defaultRoleConcurrency": 5,
45
45
  "capacityRetryMs": 2000,
46
+ "queens": [{ "repo": "/abs/repo", "sessionId": "queen-session-id" }],
46
47
  "queenSessionId": "queen-session-id",
47
48
  "waiting": null,
48
49
  "queenBoundaryViolations": 0,
49
50
  "lastQueenBoundaryViolation": null,
51
+ "crossRepoBlocked": 0,
52
+ "lastCrossRepoBlocked": null,
50
53
  "lastTickAt": "2026-12-04T00:00:00.000Z",
51
54
  "lastDiscoverError": null,
52
55
  "pendingAnomalies": 0,
@@ -73,6 +76,8 @@ Response:
73
76
  "consecutiveFailures": 0,
74
77
  "lastCards": 0,
75
78
  "lastResults": 0,
79
+ "queenSessionId": "queen-session-id",
80
+ "unmanaged": false,
76
81
  "waiting": null,
77
82
  "claimedButOrphaned": 0,
78
83
  "orphanRecovered": 0,
@@ -124,12 +129,14 @@ Response:
124
129
  - `repos` / `repoCount` — the repositories the supervisor currently tracks; this is the
125
130
  status-visible registry the panel renders. Runtime additions go through
126
131
  `hiveSupervisor.addRepo(repo)` (absolute path, initialized Hive repository, idempotent).
127
- - `queenSessionId` — the queen conversation registered by the panel **or detected by
128
- the queen tool guard** when an ordinary initialized-repo Session calls a subagent
129
- tool; agents are parented to that Session while its Agent is live. `waiting` is
130
- `"no-queen-session"` until the registration arrives (startup-order hint, not an
131
- error); the registration is only replaced by a new registration. Status workers and
132
- run records carry `parentSource: "queen"` when the registered Session parented them.
132
+ - `queens` — the repo → queen Session mapping (`[{ repo, sessionId }]`, latest
133
+ registration per repo). Workers are parented only to the queen of their own
134
+ repository; `queenSessionId`/`waiting` are a single-queen compatibility view and the
135
+ global id is `null` when several queens are registered.
136
+ - `crossRepoBlocked` / `lastCrossRepoBlocked` — mechanical rejections of a queen hive_*
137
+ call whose `repo` differed from her cwd (exact error: `女王只能操作自己所在的仓库`).
138
+ - Per-repository `queenSessionId` and `unmanaged` — a repo without a matching queen is
139
+ `unmanaged: true`; it is never dispatched to and receives no notification.
133
140
  - `queenBoundaryViolations` — how many direct `subagent`/`subagent_fork`/
134
141
  `subagent_claude_code` calls from the queen Session the tool guard has vetoed;
135
142
  `lastQueenBoundaryViolation` is `{ tool, sessionId, at, repo }` for the most recent.
@@ -194,7 +201,9 @@ required; an uninitialized path is rejected), so a repo outside `config.repos` a
194
201
  startup-order hint, not an error. While registered, its live Agent is the parent;
195
202
  if it cannot be resolved the round falls back to `parentSession` / the first live
196
203
  Agent, and defers with `hive/no-parent-agent` when no Agent is live.
197
- - Returns `{ ok: true, op: "queen", queenSessionId, waiting: null, repos: ... }`.
204
+ - Body `{ sessionId, repo }` (repo is required when several repositories are
205
+ configured; a single-repo deployment may omit it). Returns
206
+ `{ ok: true, op: "queen", queens, queenSessionId, waiting: null, repos: ... }`.
198
207
  - Missing `sessionId` -> `400` `hive/missing-session-id`; non-POST -> `405`.
199
208
  ## 3. Per-repository limits
200
209
 
@@ -282,6 +291,8 @@ auto-pause failure budget; status exposes `claimedButOrphaned`,
282
291
  | `lib/config.js` | Config defaults/validation (`patrolIntervalMs`, `notifyQueen`, `anomaly*`, `checkpoint*`, `rolesBin`), role map parsing, effective-limit helpers |
283
292
  | `lib/commands.js` | Allowlisted `hive-tasks` / `hive` / `git` / acceptance commands with shell quoting; queen verbs list/add/edit/split/supersede/reopen/retry/rm/lesson/roles |
284
293
  | `lib/shell.js` | `ctx.shell.resolve/execute` adapter (sandbox policy per call) |
294
+ | `lib/ops.js` | Queen-only `hive_ops` action enum and `diagnose` whitelist: action plan, read-only command validation, 64-KiB truncation, 120-s timeout, `hive_ops` events |
295
+ | `lib/services.js` | `.hive/services.yaml` allowlist + `.hive/services/<name>.json` records: detached start command/health acceptance, port probes, patrol `service_down`/`service_started` and service-card redispatch |
285
296
  | `lib/discover.js` | `refs/hive/v1` repository discovery |
286
297
  | `lib/http.js` | `/api/hive-runner` Fetch route (status/pending/ack/pause/resume/limits/queen) |
287
298
 
@@ -376,6 +387,51 @@ writes the same durable `arch_review` event through the shared host writer. The
376
387
  `hive_events` tool remains read-only and can verify the event; a host/panel caller can
377
388
  also invoke the service method directly.
378
389
 
390
+ ### Queen operations and services
391
+
392
+ `hive_ops` is an action enum, not a shell: `status`, `pause`, `resume`, `limits`,
393
+ `run-round`, `health`, `services`, `diagnose`, `test`, `typecheck`, `build`. Only
394
+ `diagnose` executes a command, restricted to `git status/log/diff/show`, `ls`,
395
+ `curl 127.0.0.1`, `lsof` plus `.hive/ops.yaml` extensions; `test`/`typecheck`/`build`
396
+ run only the fixed pnpm script. Shell actions use the DSH shell seam with a 120-second
397
+ timeout and 64-KiB output cap. `hive_ops` is queen-only and the common tool wrapper
398
+ enforces the repo=cwd rule before the body; every action/denial appends a `hive_ops`
399
+ event.
400
+
401
+ Long-running services are agent work: `.hive/services.yaml` declares name/command/port
402
+ and health. A service-role worker starts `setsid nohup <command> >>
403
+ .hive/services/<name>.log 2>&1 &`, writes `.hive/services/<name>.json` (PID/port), and
404
+ uses the local health URL as acceptance. The patrol probes declared ports, records
405
+ `service_down`/`service_started`, and creates or reopens a `service` card when a
406
+ service disappears; `hive_ops action=services` reports the declared/running state.
407
+ Commands or ports not in the YAML are rejected.
408
+
409
+ ### Repository isolation (hard, mechanical)
410
+
411
+ Every layer is scoped by repository; the model is never trusted for this:
412
+
413
+ 1. **Delivery**: anomalies are grouped per repo and each digest/checkpoint is delivered
414
+ only through that repo's queen (`repo → sessionId`); no matching queen queues the
415
+ entry as pending. A notifier can never fall back to another repo's Session.
416
+ 2. **Tools**: every `hive_*` tool with a `repo` parameter is wrapped; for a queen Session
417
+ the repo must resolve to the Session cwd (omitted means cwd), otherwise the call
418
+ fails before the body with `女王只能操作自己所在的仓库` and increments
419
+ `crossRepoBlocked`. This covers `hive_tasks`, `hive_intervene`,
420
+ `hive_arch_review`, `hive_board`, `hive_events`, `hive_run_round`, etc.
421
+ 3. **Dispatch**: `#runEntry` looks up `queenFor(repo)`; repositories without one are
422
+ `unmanaged` and never dispatch. The round runner passes the repo to the parent
423
+ provider, so a worker's parent is that repo's queen agent.
424
+ 4. **Concurrency**: pause and role limits are per repository; pausing repo A does not
425
+ stop repo B.
426
+ 5. **Status**: `queens` is the mapping, each repo carries `queenSessionId`/`unmanaged`
427
+ and its own `workers`; there is no global worker/queen aggregate that could be read
428
+ as cross-repo ownership.
429
+ 6. **Events**: writers append only under `<repo>/.hive/events.jsonl`; the repo must be an
430
+ absolute path, and the resolved log path is checked after symlink resolution so a
431
+ `.hive` symlink cannot redirect the append outside the repository.
432
+ 7. **Recovery**: orphan claims are recovered per repository, restricted to this
433
+ runner's identity and excluding live active cards.
434
+
379
435
  ### Tool boundary: hard veto through `ctx.tools.guard`
380
436
 
381
437
  DSH does expose a plugin-side tool veto. `ToolsService.guard(guard)` registers a