dsh-hive-runner 1.0.13 → 1.0.15
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 +47 -0
- package/README.md +13 -11
- package/README.zh-CN.md +4 -3
- package/SPEC.md +21 -8
- package/cordis.patch.yml +5 -5
- package/docs/DESIGN.md +50 -12
- package/index.js +91 -18
- package/lib/checkpoint.js +92 -7
- package/lib/config.js +13 -7
- package/lib/round.js +8 -0
- package/lib/supervisor.js +55 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,49 @@ 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.15] - 2026-12-05
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- Queen tool visibility is now diagnosed and observable. On queen registration (and
|
|
15
|
+
retried by the patrol if the agent was not live yet) the plugin lists
|
|
16
|
+
`ctx.tools.schemas(queenAgent)` once, logs `queen visible tools (<n>): ...`, and
|
|
17
|
+
exposes `queenTools` / `queenToolsSessionId` / `queenToolsListedAt` /
|
|
18
|
+
`queenToolsError` in status. Investigation: under PTC the model request declares only
|
|
19
|
+
`run_code`; the plugin tools are registered globally and are bound inside `run_code`
|
|
20
|
+
(live session log shows successful `hive_arch_review` PTC dispatches). The earlier
|
|
21
|
+
"no tools" report came from the boundary guard blocking `run_code` before 1.0.12, not
|
|
22
|
+
from a per-agent registration failure.
|
|
23
|
+
- Added a tool-independent host fallback:
|
|
24
|
+
`hiveSupervisor.recordArchReview(repo, { card, verdict, findings, summary })` writes
|
|
25
|
+
the same durable `arch_review` event through the shared host writer, so a caller can
|
|
26
|
+
repair reviews when an agent tool is unavailable; `hive_events` verifies it.
|
|
27
|
+
|
|
28
|
+
## [1.0.14] - 2026-12-05
|
|
29
|
+
|
|
30
|
+
### Fixed
|
|
31
|
+
|
|
32
|
+
- Progress checkpoints are near-real-time again: the patrol default is now
|
|
33
|
+
`patrolIntervalMs: 5000` (the old `patrolMs` name is accepted as an alias), the first
|
|
34
|
+
drained checkpoint after a supervisor restart needs only 5 seconds of drained state,
|
|
35
|
+
and the first digest is labelled `supervisor 刚启动`. Later drain checkpoints keep the
|
|
36
|
+
10-minute `checkpointDrainMs` minimum.
|
|
37
|
+
- Card settle (`done`/`failed`) and gate-phase/releaseReady changes trigger an immediate
|
|
38
|
+
checkpoint request via new `onSettled`/`onGateChange` hooks instead of waiting for the
|
|
39
|
+
next patrol tick. Same-state dedup still applies.
|
|
40
|
+
- Board-read overhead is bounded: consecutive checkpoint ticks reuse the same repository
|
|
41
|
+
`hive-tasks list --json` result for 2 seconds (events invalidate it), and a failing
|
|
42
|
+
shell read backs off for 15 seconds.
|
|
43
|
+
|
|
44
|
+
### Compatibility
|
|
45
|
+
|
|
46
|
+
- `patrolMs` is still accepted as a legacy alias for `patrolIntervalMs`; both keys are
|
|
47
|
+
reported on the resolved config.
|
|
48
|
+
|
|
49
|
+
### Published
|
|
50
|
+
|
|
51
|
+
- npm: `dsh-hive-runner@1.0.14` on 2026-12-05.
|
|
52
|
+
|
|
10
53
|
## [1.0.13] - 2026-12-05
|
|
11
54
|
|
|
12
55
|
### Added
|
|
@@ -22,6 +65,10 @@ iterations of the plugin before this repository was published.
|
|
|
22
65
|
checkpoints pending (`status.pendingCheckpoints`) until the next patrol/registration.
|
|
23
66
|
- New config keys `checkpointDrainMs` / `checkpointIdleMs` (defaults 600000).
|
|
24
67
|
|
|
68
|
+
### Published
|
|
69
|
+
|
|
70
|
+
- npm: `dsh-hive-runner@1.0.13` on 2026-12-05.
|
|
71
|
+
|
|
25
72
|
## [1.0.12] - 2026-12-05
|
|
26
73
|
|
|
27
74
|
### Fixed
|
package/README.md
CHANGED
|
@@ -145,22 +145,24 @@ so a noisy minute becomes **one** message, not ten.
|
|
|
145
145
|
Two guarantees keep this quiet:
|
|
146
146
|
|
|
147
147
|
- **Only anomalies are delivered.** A healthy swarm produces no message at all; the
|
|
148
|
-
periodical **patrol** (`
|
|
148
|
+
periodical **patrol** (`patrolIntervalMs`, default 5 seconds) re-reads the supervisor status,
|
|
149
149
|
reports auto-paused repositories, environment errors, stalled heartbeats and agents
|
|
150
150
|
past their deadline, and delivers only when something is pending.
|
|
151
151
|
- **Nothing is lost when no queen is live.** If the panel is closed or the Session is
|
|
152
152
|
gone the digest stays in the pending list: `hive_anomalies` lists and acknowledges it,
|
|
153
153
|
`hive_supervisor_status` reports `pendingAnomalies`, and the next registered queen
|
|
154
154
|
Session flushes the queue. `notifyQueen: false` keeps the pending list only.
|
|
155
|
-
Progress is reported separately from anomalies: when the queue drains (
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
155
|
+
Progress is reported separately from anomalies: when the queue drains (the first
|
|
156
|
+
checkpoint after a restart needs only 5 seconds of drained state; later ones use
|
|
157
|
+
`checkpointDrainMs`, default 10 minutes), when every task is done, when a gate phase
|
|
158
|
+
advances (these fire immediately on the worker/gate event), or when no task is ready
|
|
159
|
+
for `checkpointIdleMs` (default 10 minutes) while work remains, the queen gets a
|
|
160
|
+
checkpoint digest with task counts, recently completed titles, gate state and the last
|
|
161
|
+
10 minutes of events. The first one is labelled `supervisor 刚启动`. It asks her to
|
|
162
|
+
evaluate the goal and either split the next batch or summarize and ask the human to
|
|
163
|
+
confirm release. The same state is sent once; a state change re-arms it. With no live
|
|
164
|
+
queen Session the checkpoint stays pending (`pendingCheckpoints` in status) and is
|
|
165
|
+
flushed on the next patrol/registration.
|
|
164
166
|
|
|
165
167
|
### The gates the queen orchestrates
|
|
166
168
|
|
|
@@ -294,7 +296,7 @@ written to `docs/CONVENTIONS.md` / `AGENTS.md` / an ADR, not just remembered in
|
|
|
294
296
|
|
|
295
297
|
| Key | Default | Meaning |
|
|
296
298
|
| --- | --- | --- |
|
|
297
|
-
| `
|
|
299
|
+
| `patrolIntervalMs` | `5000` (5 s) | queen/checkpoint patrol period; board reads are cached for 2 s |
|
|
298
300
|
| `notifyQueen` | `true` | inject the digest into the registered queen Session; `false` = pending list only |
|
|
299
301
|
| `anomalyDebounceMs` | `3000` | coalescing window before one digest is sent |
|
|
300
302
|
| `anomalyMax` | `50` | bound on the undelivered anomaly queue |
|
package/README.zh-CN.md
CHANGED
|
@@ -91,8 +91,9 @@ user 消息能通过 session 日志校验,不需要改 DSH。)同类事件
|
|
|
91
91
|
|
|
92
92
|
两条静默保证:
|
|
93
93
|
|
|
94
|
-
- **只有异常才投递。** 蜂群健康时一条消息都不发;周期性**巡检**(`
|
|
95
|
-
|
|
94
|
+
- **只有异常才投递。** 蜂群健康时一条消息都不发;周期性**巡检**(`patrolIntervalMs`,默认 5
|
|
95
|
+
秒)重读 supervisor 状态;同一仓库的 board 读取缓存 2 秒,发现自动暂停、环境错误、
|
|
96
|
+
心跳告警、任务超时或进度 checkpoint 时才投递。
|
|
96
97
|
- **没有女王时不丢。** 面板关掉或会话不在,摘要留在待处理列表:`hive_anomalies`
|
|
97
98
|
可列出/确认,`hive_supervisor_status` 报告 `pendingAnomalies`,下一个注册的女王会话
|
|
98
99
|
会把队列冲掉。`notifyQueen: false` 表示只保留待处理列表、不注入。
|
|
@@ -202,7 +203,7 @@ outstanding/failed 与 `releaseReady`、`reason`)。`releaseReady` 为 true
|
|
|
202
203
|
|
|
203
204
|
| 键 | 默认 | 含义 |
|
|
204
205
|
| --- | --- | --- |
|
|
205
|
-
| `
|
|
206
|
+
| `patrolIntervalMs` | `5000`(5 秒) | 女王/进度巡检周期;任务板读取缓存 2 秒 |
|
|
206
207
|
| `notifyQueen` | `true` | 把摘要注入已注册的女王会话;`false` 只留待处理列表 |
|
|
207
208
|
| `anomalyDebounceMs` | `3000` | 合并成一条摘要前的防抖时间 |
|
|
208
209
|
| `anomalyMax` | `50` | 待投递异常队列上限 |
|
package/SPEC.md
CHANGED
|
@@ -62,6 +62,10 @@ wrong method -> `405` (`hive/method-not-allowed`).
|
|
|
62
62
|
"lastDiscoverError": null,
|
|
63
63
|
"pendingAnomalies": 0,
|
|
64
64
|
"repoCount": 1,
|
|
65
|
+
"queenTools": ["hive_arch_review", "run_code"],
|
|
66
|
+
"queenToolsSessionId": "queen-session-id",
|
|
67
|
+
"queenToolsListedAt": "2026-12-05T09:00:00.000Z",
|
|
68
|
+
"queenToolsError": null,
|
|
65
69
|
"claimedButOrphaned": 0,
|
|
66
70
|
"workerSessionIds": ["worker-session-id"],
|
|
67
71
|
"repos": [
|
|
@@ -122,6 +126,8 @@ wrong method -> `405` (`hive/method-not-allowed`).
|
|
|
122
126
|
- `backlog` — aggregate `{ queued, inFlight, completed }` for the current or last drain.
|
|
123
127
|
- `pendingCheckpoints` — progress checkpoints queued while no live queen Session was
|
|
124
128
|
available; the next patrol/queen registration flushes them.
|
|
129
|
+
- `queenTools` — one-shot diagnostic list of tool schema names visible to the registered
|
|
130
|
+
queen Agent, with `queenToolsSessionId`, `queenToolsListedAt`, `queenToolsError`.
|
|
125
131
|
- `repos` / `repoCount` — the status-visible repository registry. `hiveSupervisor.addRepo(repo)`
|
|
126
132
|
adds one at runtime (absolute path, must be an initialized Hive repository; idempotent;
|
|
127
133
|
rejects a relative or uninitialized path).
|
|
@@ -350,8 +356,8 @@ Two sources feed one digest:
|
|
|
350
356
|
`auto-paused`, `environment-error`. The plugin pushes them into an in-memory
|
|
351
357
|
AnomalyFeed (`lib/anomalies.js`): entries coalesce per `(kind, repo, cardId)`
|
|
352
358
|
inside a ten-minute window and are bounded by `anomalyMax`.
|
|
353
|
-
- **Patrol** — `lib/patrol.js` re-reads `supervisor.status()` every `
|
|
354
|
-
(default 5
|
|
359
|
+
- **Patrol** — `lib/patrol.js` re-reads `supervisor.status()` every `patrolIntervalMs`
|
|
360
|
+
(default 5 seconds; same-repo board reads reuse a 2-second cache) and pushes `auto-paused`, `environment-error`, `heartbeat-warn`
|
|
355
361
|
(agent heartbeat `warn`) and `card-timeout` (agent past `timeoutAt`), so a missed
|
|
356
362
|
event is recovered even though only one digest is delivered.
|
|
357
363
|
|
|
@@ -376,12 +382,15 @@ delivers nothing.
|
|
|
376
382
|
|
|
377
383
|
### 8.6.1 Progress checkpoints
|
|
378
384
|
|
|
379
|
-
The patrol also sends a progress digest to the queen (not just anomalies):
|
|
380
|
-
queue is drained — no pending/claimed tasks, including failed ones — and
|
|
381
|
-
|
|
382
|
-
are done or the gate phase advanced
|
|
383
|
-
|
|
384
|
-
|
|
385
|
+
The 5-second patrol also sends a progress digest to the queen (not just anomalies):
|
|
386
|
+
(1) the queue is drained — no pending/claimed tasks, including failed ones — and the
|
|
387
|
+
first checkpoint after a restart needs only 5 seconds of drained state; later ones use
|
|
388
|
+
`checkpointDrainMs` (default 10 min); (2) all tasks are done or the gate phase advanced
|
|
389
|
+
/ `releaseReady` became true — delivered immediately via the settled/gate hooks, not on
|
|
390
|
+
the next tick; (3) no ready task exists while unfinished tasks remain, continuously for
|
|
391
|
+
`checkpointIdleMs` (default 10 min). The first checkpoint after startup is labelled
|
|
392
|
+
`supervisor 刚启动`. Board reads reuse a 2-second same-repo cache and back off 15 seconds
|
|
393
|
+
after a shell failure. The digest carries done/failed/pending/claimed/total counts, recent completed
|
|
385
394
|
task titles, gate phase/releaseReady, a bounded last-10-minute event summary, the
|
|
386
395
|
trigger, and the instruction: `评估目标是否达成:未达成请继续拆解下一批任务并说明依据;
|
|
387
396
|
达成请汇总结果并请人类确认发布。`. The same state is sent once (state signature =
|
|
@@ -389,6 +398,10 @@ counts + gate + recent completed ids); a change re-arms it. With no live queen
|
|
|
389
398
|
Session it stays pending (`status.pendingCheckpoints`) and is flushed by the next
|
|
390
399
|
patrol or queen registration.
|
|
391
400
|
|
|
401
|
+
A host-side fallback writes the same durable event without the agent tool:
|
|
402
|
+
`hiveSupervisor.recordArchReview(repo, { card, verdict, findings, summary })`; the
|
|
403
|
+
read-only `hive_events` tool verifies the appended event.
|
|
404
|
+
|
|
392
405
|
### 8.6.2 Queen tool boundary
|
|
393
406
|
|
|
394
407
|
DSH's `ctx.tools.guard` lets a plugin veto a tool call after pre-execute policy and
|
package/cordis.patch.yml
CHANGED
|
@@ -77,11 +77,11 @@
|
|
|
77
77
|
# poll cadence.
|
|
78
78
|
heartbeatWarnMs: 300000
|
|
79
79
|
heartbeatIntervalMs: 30000
|
|
80
|
-
# Queen coordination. The patrol checks the supervisor every
|
|
81
|
-
#
|
|
82
|
-
#
|
|
83
|
-
# notifyQueen=false
|
|
84
|
-
|
|
80
|
+
# Queen coordination. The patrol checks the supervisor every
|
|
81
|
+
# patrolIntervalMs (default 5s for near-real-time progress) and delivers
|
|
82
|
+
# ONE digest to the registered queen Session only when there is an
|
|
83
|
+
# anomaly or checkpoint. notifyQueen=false keeps the pending list only.
|
|
84
|
+
patrolIntervalMs: 5000
|
|
85
85
|
notifyQueen: true
|
|
86
86
|
# Card events coalesce for anomalyDebounceMs before one digest is sent;
|
|
87
87
|
# anomalyMax bounds the undelivered queue exposed by hive_anomalies.
|
package/docs/DESIGN.md
CHANGED
|
@@ -51,6 +51,10 @@ Response:
|
|
|
51
51
|
"lastDiscoverError": null,
|
|
52
52
|
"pendingAnomalies": 0,
|
|
53
53
|
"pendingCheckpoints": 0,
|
|
54
|
+
"queenTools": ["hive_arch_review", "run_code"],
|
|
55
|
+
"queenToolsSessionId": "queen-session-id",
|
|
56
|
+
"queenToolsListedAt": "2026-12-05T09:00:00.000Z",
|
|
57
|
+
"queenToolsError": null,
|
|
54
58
|
"repoCount": 1,
|
|
55
59
|
"claimedButOrphaned": 0,
|
|
56
60
|
"workerSessionIds": ["worker-session-id"],
|
|
@@ -113,6 +117,10 @@ Response:
|
|
|
113
117
|
last drain.
|
|
114
118
|
- `pendingCheckpoints` — progress checkpoints queued while no live queen Session was
|
|
115
119
|
available; the next patrol/queen registration flushes them.
|
|
120
|
+
- `queenTools` — one-shot diagnostic: the tool schema names visible to the registered
|
|
121
|
+
queen Agent (`ctx.tools.schemas(agent)`), plus `queenToolsSessionId`,
|
|
122
|
+
`queenToolsListedAt` and `queenToolsError`. Under the PTC preset the model-facing
|
|
123
|
+
request only exposes `run_code`; this list proves `hive_*` bindings exist inside it.
|
|
116
124
|
- `repos` / `repoCount` — the repositories the supervisor currently tracks; this is the
|
|
117
125
|
status-visible registry the panel renders. Runtime additions go through
|
|
118
126
|
`hiveSupervisor.addRepo(repo)` (absolute path, initialized Hive repository, idempotent).
|
|
@@ -271,7 +279,7 @@ auto-pause failure budget; status exposes `claimedButOrphaned`,
|
|
|
271
279
|
| `lib/events.js` | `.hive/events.jsonl` append/read plus the `arch_review`, `queen_intervention`, `queen_escalation` and `queen_boundary_violation` event contracts |
|
|
272
280
|
| `lib/queen-boundary.js` | `ctx.tools.guard` veto for queen → `subagent`/`subagent_fork`/`subagent_claude_code`; returns the correction and reports the attempt |
|
|
273
281
|
| `lib/limits.js` | `<repo>/.hive/limits.json` read/write/hot-reload and precedence helpers |
|
|
274
|
-
| `lib/config.js` | Config defaults/validation (`
|
|
282
|
+
| `lib/config.js` | Config defaults/validation (`patrolIntervalMs`, `notifyQueen`, `anomaly*`, `checkpoint*`, `rolesBin`), role map parsing, effective-limit helpers |
|
|
275
283
|
| `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 |
|
|
276
284
|
| `lib/shell.js` | `ctx.shell.resolve/execute` adapter (sandbox policy per call) |
|
|
277
285
|
| `lib/discover.js` | `refs/hive/v1` repository discovery |
|
|
@@ -320,23 +328,53 @@ lessons, and the supervisor feeds it anomalies. The design constraints:
|
|
|
320
328
|
|
|
321
329
|
### Progress checkpoints
|
|
322
330
|
|
|
323
|
-
A patrol also reports progress, not only problems. `lib/checkpoint.js` runs
|
|
324
|
-
patrol inspect hook for every registered repository and sends a checkpoint
|
|
331
|
+
A 5-second patrol also reports progress, not only problems. `lib/checkpoint.js` runs
|
|
332
|
+
from the patrol inspect hook for every registered repository and sends a checkpoint
|
|
333
|
+
when:
|
|
325
334
|
|
|
326
|
-
1. the queue is drained (no pending/claimed tasks, including failed ones)
|
|
327
|
-
|
|
328
|
-
|
|
335
|
+
1. the queue is drained (no pending/claimed tasks, including failed ones); the first
|
|
336
|
+
drained checkpoint after a supervisor restart needs only 5 seconds of drained state,
|
|
337
|
+
later ones use `checkpointDrainMs` (default 10 min);
|
|
338
|
+
2. all tasks are done, or the gate phase advanced / `releaseReady` flipped true — this
|
|
339
|
+
fires immediately via the `onSettled`/`onGateChange` hooks, without waiting for the
|
|
340
|
+
next patrol tick;
|
|
329
341
|
3. no ready task exists while unfinished tasks remain, continuously for
|
|
330
342
|
`checkpointIdleMs` (default 10 min).
|
|
331
343
|
|
|
332
|
-
The
|
|
333
|
-
|
|
334
|
-
|
|
344
|
+
The first checkpoint after startup carries `Context: supervisor 刚启动` so the queen
|
|
345
|
+
knows the digest is from a fresh process. The digest contains
|
|
346
|
+
`done/failed/pending/claimed/total`, the last completed task titles, gate
|
|
347
|
+
phase/releaseReady/reason, a bounded summary of events from the last 10 minutes, the
|
|
348
|
+
trigger, and the instruction `评估目标是否达成:未达成请继续拆解下一批任务并说明依据;达成请汇总结果并请人类确认发布。`.
|
|
335
349
|
It is delivered through the queen notifier. The state signature (counts + gate +
|
|
336
350
|
releaseReady + recent completed ids) deduplicates it: the same state is sent once and
|
|
337
|
-
only a state change re-arms it.
|
|
338
|
-
|
|
339
|
-
|
|
351
|
+
only a state change re-arms it. Board reads reuse a 2-second same-repo cache (events
|
|
352
|
+
invalidate it); a failing `hive-tasks list` backs off for 15 seconds. Without a live
|
|
353
|
+
queen Session the checkpoint is kept in the controller's pending list (status
|
|
354
|
+
`pendingCheckpoints`) and flushed by the next patrol or queen registration; it never
|
|
355
|
+
falls through to an anomaly digest.
|
|
356
|
+
|
|
357
|
+
### Tool visibility diagnostic and host fallback
|
|
358
|
+
|
|
359
|
+
Under the PTC preset the model-facing request declares only `run_code`; the plugin's
|
|
360
|
+
`hive_*` tools are still registered globally by `apply()` and are visible to the agent
|
|
361
|
+
as schemas inside `run_code` (`tool/ptc-dispatch-start` events for `hive_arch_review`
|
|
362
|
+
prove this on the live queen session). The 1.0.11 queen saw `run_code` denied by an
|
|
363
|
+
earlier version of the boundary guard and concluded that no tools existed; 1.0.12
|
|
364
|
+
allows `run_code`, and its nested `write`/`bash` calls remain vetoed. No per-agent
|
|
365
|
+
registration path change is needed for a correctly mounted plugin.
|
|
366
|
+
|
|
367
|
+
To make this observable, the plugin lists `ctx.tools.schemas(queenAgent)` once per
|
|
368
|
+
registered queen Session, logs the names, and exposes them as `queenTools` /
|
|
369
|
+
`queenToolsSessionId` / `queenToolsListedAt` / `queenToolsError` in status. If the
|
|
370
|
+
agent is not live yet, the patrol retries the listing; the log line is
|
|
371
|
+
`queen visible tools (<n>): ...`.
|
|
372
|
+
|
|
373
|
+
If a queen Session genuinely cannot reach the tool, the host has a tool-independent
|
|
374
|
+
fallback: `hiveSupervisor.recordArchReview(repo, { card, verdict, findings, summary })`
|
|
375
|
+
writes the same durable `arch_review` event through the shared host writer. The
|
|
376
|
+
`hive_events` tool remains read-only and can verify the event; a host/panel caller can
|
|
377
|
+
also invoke the service method directly.
|
|
340
378
|
|
|
341
379
|
### Tool boundary: hard veto through `ctx.tools.guard`
|
|
342
380
|
|
package/index.js
CHANGED
|
@@ -105,6 +105,9 @@ export function apply(ctx, config = {}) {
|
|
|
105
105
|
// POST ?op=queen). Every worker is parented to exactly that Session; before
|
|
106
106
|
// registration the supervisor does not dispatch at all.
|
|
107
107
|
const queenSession = { sessionId: null };
|
|
108
|
+
// One-shot diagnostic: schema names visible to the queen agent (under PTC the
|
|
109
|
+
// model sees only run_code, but tools.hive_* exist inside run_code).
|
|
110
|
+
const queenTools = { names: [], sessionId: null, listedAt: null, error: null };
|
|
108
111
|
/** Queen boundary violations observed by the tool guard (status observability). */
|
|
109
112
|
const queenBoundary = { count: 0, last: null };
|
|
110
113
|
let parentProviderImpl;
|
|
@@ -115,6 +118,13 @@ export function apply(ctx, config = {}) {
|
|
|
115
118
|
limitFor: (repo, role) => limits.limitFor(repo, role),
|
|
116
119
|
parentProvider: (explicit) => parentProviderImpl(explicit),
|
|
117
120
|
onAnomaly: (event) => recordAnomaly(event),
|
|
121
|
+
// A finished worker or a settled card asks for a near-real-time checkpoint
|
|
122
|
+
// check instead of waiting for the next patrol tick.
|
|
123
|
+
onSettled: (event) => {
|
|
124
|
+
if (checkpoint !== undefined) {
|
|
125
|
+
void checkpoint.requestTick({ repo: event.repo }).catch((error) => log('warn', 'checkpoint event tick failed', error));
|
|
126
|
+
}
|
|
127
|
+
},
|
|
118
128
|
log,
|
|
119
129
|
});
|
|
120
130
|
parentProviderImpl = async (explicit) => {
|
|
@@ -191,6 +201,40 @@ export function apply(ctx, config = {}) {
|
|
|
191
201
|
}
|
|
192
202
|
}
|
|
193
203
|
|
|
204
|
+
/**
|
|
205
|
+
* One-shot diagnostic: list the tool schemas the queen agent actually sees.
|
|
206
|
+
* Under the PTC preset the model-facing request only exposes run_code; this
|
|
207
|
+
* listing proves whether hive_* definitions are bound inside run_code.
|
|
208
|
+
* Logged once per registered queen Session and exposed in status.queenTools.
|
|
209
|
+
* @param {string} sessionId
|
|
210
|
+
*/
|
|
211
|
+
function inspectQueenTools(sessionId) {
|
|
212
|
+
if (typeof sessionId !== 'string' || sessionId === '') return;
|
|
213
|
+
if (queenTools.sessionId === sessionId && queenTools.listedAt !== null) return;
|
|
214
|
+
let agent;
|
|
215
|
+
try {
|
|
216
|
+
agent = ctx.get('agents')?.get?.(sessionId);
|
|
217
|
+
} catch (error) {
|
|
218
|
+
queenTools.error = 'queen-agent-lookup-failed';
|
|
219
|
+
log('warn', 'queen tool listing: agent lookup failed', error);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
if (agent === undefined) {
|
|
223
|
+
queenTools.error = 'queen-agent-not-live';
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
try {
|
|
227
|
+
const names = ctx.tools.schemas(agent).map((tool) => tool.name).sort();
|
|
228
|
+
queenTools.names = names;
|
|
229
|
+
queenTools.sessionId = sessionId;
|
|
230
|
+
queenTools.listedAt = new Date().toISOString();
|
|
231
|
+
queenTools.error = null;
|
|
232
|
+
log('info', 'queen visible tools (' + names.length + '): ' + names.join(', '));
|
|
233
|
+
} catch (error) {
|
|
234
|
+
queenTools.error = 'schema-listing-failed: ' + (error instanceof Error ? error.message : String(error));
|
|
235
|
+
log('warn', 'queen tool listing failed', error);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
194
238
|
// DSH tools.guard is evaluated after pre-execute policy/approval and before a
|
|
195
239
|
// tool body; returning a denial makes the call fail without executing it.
|
|
196
240
|
// Recognition is registration OR an ordinary initialized-repo Session; a
|
|
@@ -240,9 +284,17 @@ export function apply(ctx, config = {}) {
|
|
|
240
284
|
activeRuns: (repo) => runner.activeRuns(repo),
|
|
241
285
|
queenSession,
|
|
242
286
|
queenBoundary,
|
|
287
|
+
queenTools: () => queenTools,
|
|
288
|
+
archReview: (repo, review) => recordArchReviewHost(repo, review),
|
|
243
289
|
readMode: (repo) => commands.mode(repo),
|
|
244
290
|
onAnomaly: (event) => recordAnomaly(event),
|
|
245
|
-
|
|
291
|
+
onGateChange: (event) => {
|
|
292
|
+
if (checkpoint !== undefined) {
|
|
293
|
+
void checkpoint.requestTick({ repo: event.repo }).catch((error) => log('warn', 'checkpoint gate tick failed', error));
|
|
294
|
+
}
|
|
295
|
+
},
|
|
296
|
+
onQueenSession: (sessionId) => {
|
|
297
|
+
inspectQueenTools(sessionId);
|
|
246
298
|
if (patrol !== undefined) patrol.flushPending();
|
|
247
299
|
if (checkpoint !== undefined) checkpoint.flushPending();
|
|
248
300
|
},
|
|
@@ -256,7 +308,7 @@ export function apply(ctx, config = {}) {
|
|
|
256
308
|
supervisor,
|
|
257
309
|
feed: anomalies,
|
|
258
310
|
notifier: resolved.notifyQueen ? notifier : undefined,
|
|
259
|
-
intervalMs: resolved.
|
|
311
|
+
intervalMs: resolved.patrolIntervalMs,
|
|
260
312
|
debounceMs: resolved.anomalyDebounceMs,
|
|
261
313
|
// Every patrol also audits done cards for a missing architecture review.
|
|
262
314
|
inspect: async () => {
|
|
@@ -273,6 +325,9 @@ export function apply(ctx, config = {}) {
|
|
|
273
325
|
log('warn', 'arch review audit failed for ' + repo + ': ' + (error instanceof Error ? error.message : String(error)));
|
|
274
326
|
}
|
|
275
327
|
}
|
|
328
|
+
// Retry the one-shot tool listing if the panel registered before the agent
|
|
329
|
+
// was live (status/queenTools then contains an error until this succeeds).
|
|
330
|
+
if (supervisor.queenSession.sessionId !== null) inspectQueenTools(supervisor.queenSession.sessionId);
|
|
276
331
|
// Progress checkpoints: drained/all-done/gate-advance/idle goals. Delivery
|
|
277
332
|
// is direct; failures stay pending in the checkpoint controller.
|
|
278
333
|
try {
|
|
@@ -589,6 +644,39 @@ export function apply(ctx, config = {}) {
|
|
|
589
644
|
},
|
|
590
645
|
});
|
|
591
646
|
|
|
647
|
+
/**
|
|
648
|
+
* Shared arch-review writer used by the hive_arch_review tool and the
|
|
649
|
+
* host-side hiveSupervisor.recordArchReview() fallback. Appends the durable
|
|
650
|
+
* event; never edits the card.
|
|
651
|
+
* @param {string | undefined} repoArg
|
|
652
|
+
* @param {{ card?: string, verdict?: string, findings?: string[], summary?: string }} review
|
|
653
|
+
* @param {{ signal?: AbortSignal, agent?: object }} [exec]
|
|
654
|
+
* @returns {Promise<object>} the appended event
|
|
655
|
+
*/
|
|
656
|
+
async function recordArchReviewHost(repoArg, review = {}, exec = {}) {
|
|
657
|
+
const repo = repoArg === undefined || repoArg === null || repoArg === ''
|
|
658
|
+
? resolved.cwd
|
|
659
|
+
: normalizeRepoKey(String(repoArg));
|
|
660
|
+
if (repo !== resolved.cwd && !supervisor.hasRepo(repo)) {
|
|
661
|
+
throw new Error('repo ' + JSON.stringify(repo) + ' is not a configured Hive repository');
|
|
662
|
+
}
|
|
663
|
+
const cardId = typeof review.card === 'string' ? review.card.trim() : '';
|
|
664
|
+
if (cardId === '') throw new Error('hive_arch_review needs card');
|
|
665
|
+
const card = await commands.show(repo, cardId, {
|
|
666
|
+
signal: exec?.signal,
|
|
667
|
+
session: exec?.agent?.session,
|
|
668
|
+
});
|
|
669
|
+
if (card === null || card === undefined) throw new Error('no such card: ' + cardId);
|
|
670
|
+
if (card.state !== 'done') {
|
|
671
|
+
throw new Error('architecture review runs after acceptance: card ' + card.id + ' is ' + card.state + ', not done');
|
|
672
|
+
}
|
|
673
|
+
return appendArchReview(repo, {
|
|
674
|
+
card: card.id,
|
|
675
|
+
verdict: review.verdict,
|
|
676
|
+
findings: review.findings,
|
|
677
|
+
summary: review.summary,
|
|
678
|
+
});
|
|
679
|
+
}
|
|
592
680
|
registerTextTool({
|
|
593
681
|
name: 'hive_arch_review',
|
|
594
682
|
description:
|
|
@@ -608,22 +696,7 @@ export function apply(ctx, config = {}) {
|
|
|
608
696
|
summary: { type: 'string', description: 'One-line summary of the review.' },
|
|
609
697
|
},
|
|
610
698
|
execute: async (args = {}, exec) => {
|
|
611
|
-
const
|
|
612
|
-
if (typeof args.card !== 'string' || args.card.trim() === '') throw new Error('hive_arch_review needs card');
|
|
613
|
-
const card = await commands.show(repo, args.card.trim(), {
|
|
614
|
-
signal: exec?.signal,
|
|
615
|
-
session: exec?.agent?.session,
|
|
616
|
-
});
|
|
617
|
-
if (card === null || card === undefined) throw new Error('no such card: ' + args.card);
|
|
618
|
-
if (card.state !== 'done') {
|
|
619
|
-
throw new Error('architecture review runs after acceptance: card ' + card.id + ' is ' + card.state + ', not done');
|
|
620
|
-
}
|
|
621
|
-
const event = appendArchReview(repo, {
|
|
622
|
-
card: card.id,
|
|
623
|
-
verdict: args.verdict,
|
|
624
|
-
findings: args.findings,
|
|
625
|
-
summary: args.summary,
|
|
626
|
-
});
|
|
699
|
+
const event = await recordArchReviewHost(args.repo, args, exec);
|
|
627
700
|
return jsonText({ ok: true, event });
|
|
628
701
|
},
|
|
629
702
|
});
|
package/lib/checkpoint.js
CHANGED
|
@@ -17,6 +17,12 @@
|
|
|
17
17
|
|
|
18
18
|
/** Default minimum gap between queue-drained checkpoints. */
|
|
19
19
|
export const DEFAULT_CHECKPOINT_DRAIN_MS = 10 * 60_000;
|
|
20
|
+
/** First startup checkpoint after a drained queue needs only this long. */
|
|
21
|
+
export const DEFAULT_CHECKPOINT_FIRST_DRAIN_MS = 5_000;
|
|
22
|
+
/** A repeated checkpoint tick may reuse the board read for this long. */
|
|
23
|
+
export const DEFAULT_CHECKPOINT_CACHE_MS = 2_000;
|
|
24
|
+
/** After a shell failure, do not retry the board read for this long. */
|
|
25
|
+
export const DEFAULT_CHECKPOINT_ERROR_BACKOFF_MS = 15_000;
|
|
20
26
|
/** Default no-ready period before the idle checkpoint fires. */
|
|
21
27
|
export const DEFAULT_CHECKPOINT_IDLE_MS = 10 * 60_000;
|
|
22
28
|
/** Default event window shown in the digest. */
|
|
@@ -86,7 +92,7 @@ export function summarizeCheckpointEvents(events, { since = 0, maxKinds = 6 } =
|
|
|
86
92
|
}
|
|
87
93
|
|
|
88
94
|
/** Build the complete injected checkpoint body. */
|
|
89
|
-
export function renderCheckpoint({ repo, stats, gate, recentEvents, trigger, at }) {
|
|
95
|
+
export function renderCheckpoint({ repo, stats, gate, recentEvents, trigger, at, startup = false }) {
|
|
90
96
|
const gatePhase = typeof gate?.phase === 'string' ? gate.phase : 'unknown';
|
|
91
97
|
const releaseReady = gate?.releaseReady === true;
|
|
92
98
|
const titles = stats.recentCompleted.length > 0
|
|
@@ -94,6 +100,7 @@ export function renderCheckpoint({ repo, stats, gate, recentEvents, trigger, at
|
|
|
94
100
|
: '(none)';
|
|
95
101
|
return [
|
|
96
102
|
'[hive-runner] checkpoint — ' + String(repo),
|
|
103
|
+
...(startup ? ['Context: supervisor 刚启动(first checkpoint after restart)'] : []),
|
|
97
104
|
'Trigger: ' + String(trigger),
|
|
98
105
|
'Tasks: done=' + stats.done + ' failed=' + stats.failed + ' pending=' + stats.pending
|
|
99
106
|
+ ' claimed=' + stats.claimed + ' total=' + stats.total,
|
|
@@ -116,8 +123,12 @@ export function renderCheckpoint({ repo, stats, gate, recentEvents, trigger, at
|
|
|
116
123
|
* notifier?: { deliver: (body: string) => { delivered: boolean, via?: string, reason?: string } },
|
|
117
124
|
* now?: () => number,
|
|
118
125
|
* drainMs?: number,
|
|
126
|
+
* firstDrainMs?: number,
|
|
127
|
+
* startedAt?: number,
|
|
119
128
|
* idleMs?: number,
|
|
120
129
|
* eventWindowMs?: number,
|
|
130
|
+
* cacheMs?: number,
|
|
131
|
+
* errorBackoffMs?: number,
|
|
121
132
|
* log?: (level: string, ...args: unknown[]) => void,
|
|
122
133
|
* }} options
|
|
123
134
|
*/
|
|
@@ -128,13 +139,20 @@ export function createCheckpointController({
|
|
|
128
139
|
notifier,
|
|
129
140
|
now = () => Date.now(),
|
|
130
141
|
drainMs = DEFAULT_CHECKPOINT_DRAIN_MS,
|
|
142
|
+
firstDrainMs = DEFAULT_CHECKPOINT_FIRST_DRAIN_MS,
|
|
143
|
+
startedAt,
|
|
131
144
|
idleMs = DEFAULT_CHECKPOINT_IDLE_MS,
|
|
132
145
|
eventWindowMs = DEFAULT_CHECKPOINT_EVENT_WINDOW_MS,
|
|
146
|
+
cacheMs = DEFAULT_CHECKPOINT_CACHE_MS,
|
|
147
|
+
errorBackoffMs = DEFAULT_CHECKPOINT_ERROR_BACKOFF_MS,
|
|
133
148
|
log = () => {},
|
|
134
149
|
} = {}) {
|
|
135
150
|
if (typeof loadBoard !== 'function') throw new TypeError('createCheckpointController: loadBoard is required');
|
|
151
|
+
const controllerStartedAt = Number.isFinite(startedAt) ? startedAt : now();
|
|
136
152
|
const states = new Map();
|
|
137
153
|
const pending = [];
|
|
154
|
+
const boardCache = new Map();
|
|
155
|
+
let firstCheckpointCreated = false;
|
|
138
156
|
|
|
139
157
|
function stateFor(repo) {
|
|
140
158
|
let state = states.get(repo);
|
|
@@ -145,6 +163,8 @@ export function createCheckpointController({
|
|
|
145
163
|
lastGatePhase: undefined,
|
|
146
164
|
lastReleaseReady: undefined,
|
|
147
165
|
noReadySince: null,
|
|
166
|
+
drainedSince: null,
|
|
167
|
+
hasCheckpoint: false,
|
|
148
168
|
};
|
|
149
169
|
states.set(repo, state);
|
|
150
170
|
}
|
|
@@ -179,8 +199,9 @@ export function createCheckpointController({
|
|
|
179
199
|
});
|
|
180
200
|
}
|
|
181
201
|
|
|
182
|
-
async function
|
|
202
|
+
async function runTick(options = {}) {
|
|
183
203
|
const results = [];
|
|
204
|
+
const force = options.force === true;
|
|
184
205
|
if (supervisor === undefined || typeof supervisor.status !== 'function') return results;
|
|
185
206
|
let status;
|
|
186
207
|
try {
|
|
@@ -195,13 +216,29 @@ export function createCheckpointController({
|
|
|
195
216
|
if (repoStatus === null || typeof repoStatus !== 'object') continue;
|
|
196
217
|
const repo = typeof repoStatus.repo === 'string' ? repoStatus.repo : '';
|
|
197
218
|
if (repo === '') continue;
|
|
219
|
+
if (force) boardCache.delete(repo);
|
|
198
220
|
let board;
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
log('warn', 'checkpoint could not read board for ' + repo, error);
|
|
221
|
+
let cacheEntry = boardCache.get(repo);
|
|
222
|
+
if (cacheEntry !== undefined && Number.isFinite(cacheEntry.errorUntil) && cacheEntry.errorUntil > at) {
|
|
223
|
+
// Shell failure backoff: do not hammer a broken hive-tasks CLI.
|
|
203
224
|
continue;
|
|
204
225
|
}
|
|
226
|
+
const cacheFresh = cacheEntry !== undefined
|
|
227
|
+
&& cacheEntry.board !== undefined
|
|
228
|
+
&& cacheEntry.stale !== true
|
|
229
|
+
&& at - cacheEntry.at < cacheMs;
|
|
230
|
+
if (cacheFresh) {
|
|
231
|
+
board = cacheEntry.board;
|
|
232
|
+
} else {
|
|
233
|
+
try {
|
|
234
|
+
board = await loadBoard(repo);
|
|
235
|
+
boardCache.set(repo, { at, board, stale: false, errorUntil: 0 });
|
|
236
|
+
} catch (error) {
|
|
237
|
+
boardCache.set(repo, { at: 0, board: undefined, stale: true, errorUntil: at + errorBackoffMs });
|
|
238
|
+
log('warn', 'checkpoint could not read board for ' + repo, error);
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
205
242
|
if (board === null || typeof board !== 'object') continue;
|
|
206
243
|
const stats = taskCheckpointStats(board.tasks);
|
|
207
244
|
const gate = repoStatus.gate ?? null;
|
|
@@ -220,13 +257,28 @@ export function createCheckpointController({
|
|
|
220
257
|
}
|
|
221
258
|
|
|
222
259
|
const drained = stats.total > 0 && stats.pending === 0 && stats.claimed === 0;
|
|
260
|
+
// A restart must not wait the normal 10-minute drain interval: if the
|
|
261
|
+
// queue was already drained before this process started, the first
|
|
262
|
+
// checkpoint needs only firstDrainMs (60s). Later drain checkpoints use
|
|
263
|
+
// the normal drainMs gap.
|
|
264
|
+
if (drained) {
|
|
265
|
+
if (state.drainedSince === null) {
|
|
266
|
+
state.drainedSince = state.hasCheckpoint ? at : controllerStartedAt;
|
|
267
|
+
}
|
|
268
|
+
} else {
|
|
269
|
+
state.drainedSince = null;
|
|
270
|
+
}
|
|
271
|
+
const firstDrainReady = !state.hasCheckpoint
|
|
272
|
+
&& state.drainedSince !== null
|
|
273
|
+
&& at - state.drainedSince >= firstDrainMs;
|
|
274
|
+
const laterDrainReady = state.hasCheckpoint && at - state.lastCheckpointAt >= drainMs;
|
|
223
275
|
const allDone = stats.total > 0 && stats.done === stats.total;
|
|
224
276
|
const gateAdvanced = state.lastGatePhase !== undefined
|
|
225
277
|
&& (phaseRank(phase) > phaseRank(state.lastGatePhase)
|
|
226
278
|
|| (state.lastReleaseReady === false && releaseReady === true));
|
|
227
279
|
const reasons = [];
|
|
228
280
|
if (allDone) reasons.push('all-done');
|
|
229
|
-
else if (drained &&
|
|
281
|
+
else if (drained && (firstDrainReady || laterDrainReady)) reasons.push('queue-drained');
|
|
230
282
|
if (gateAdvanced) reasons.push('gate-advanced');
|
|
231
283
|
if (state.noReadySince !== null && at - state.noReadySince >= idleMs) reasons.push('no-ready');
|
|
232
284
|
|
|
@@ -245,11 +297,14 @@ export function createCheckpointController({
|
|
|
245
297
|
recentEvents: summarizeCheckpointEvents(events, { since: at - eventWindowMs }),
|
|
246
298
|
trigger: reasons.join('+'),
|
|
247
299
|
at,
|
|
300
|
+
startup: !firstCheckpointCreated,
|
|
248
301
|
});
|
|
249
302
|
const entry = { repo, body, signature, at, trigger: reasons.join('+') };
|
|
250
303
|
const delivery = deliver(entry);
|
|
251
304
|
state.lastSignature = signature;
|
|
252
305
|
state.lastCheckpointAt = at;
|
|
306
|
+
state.hasCheckpoint = true;
|
|
307
|
+
firstCheckpointCreated = true;
|
|
253
308
|
if (delivery.delivered) {
|
|
254
309
|
log('info', 'checkpoint delivered to queen', repo, reasons.join('+'));
|
|
255
310
|
results.push({ repo, trigger: entry.trigger, delivered: true, via: delivery.via ?? null });
|
|
@@ -278,8 +333,38 @@ export function createCheckpointController({
|
|
|
278
333
|
return { delivered, pending: pending.length };
|
|
279
334
|
}
|
|
280
335
|
|
|
336
|
+
let tickChain = Promise.resolve();
|
|
337
|
+
function enqueue(fn) {
|
|
338
|
+
const run = tickChain.then(fn, fn);
|
|
339
|
+
tickChain = run.then(() => undefined, () => undefined);
|
|
340
|
+
return run;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/** Serialize ticks; a board cache may serve repeated patrol ticks. */
|
|
344
|
+
function tick(options = {}) {
|
|
345
|
+
return enqueue(() => runTick(options));
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Immediate event-triggered check (card settled, gate advanced). Marks the
|
|
350
|
+
* affected board cache stale and runs without waiting for the next patrol.
|
|
351
|
+
* @param {{ repo?: string, force?: boolean }} [options]
|
|
352
|
+
* @returns {Promise<object[]>}
|
|
353
|
+
*/
|
|
354
|
+
function requestTick(options = {}) {
|
|
355
|
+
const repo = typeof options.repo === 'string' && options.repo !== '' ? options.repo : null;
|
|
356
|
+
if (repo === null) {
|
|
357
|
+
for (const entry of boardCache.values()) entry.stale = true;
|
|
358
|
+
} else {
|
|
359
|
+
const entry = boardCache.get(repo);
|
|
360
|
+
if (entry !== undefined) entry.stale = true;
|
|
361
|
+
}
|
|
362
|
+
return tick();
|
|
363
|
+
}
|
|
364
|
+
|
|
281
365
|
return {
|
|
282
366
|
tick,
|
|
367
|
+
requestTick,
|
|
283
368
|
flushPending,
|
|
284
369
|
pendingCount: () => pending.length,
|
|
285
370
|
pending: () => pending.map((entry) => ({ ...entry })),
|
package/lib/config.js
CHANGED
|
@@ -24,8 +24,10 @@ export const DEFAULT_CARD_TIMEOUT_MS = 15 * 60_000;
|
|
|
24
24
|
export const DEFAULT_HEARTBEAT_WARN_MS = 5 * 60_000;
|
|
25
25
|
/** How often heartbeat/liveness is checked while a worker runs. */
|
|
26
26
|
export const DEFAULT_HEARTBEAT_INTERVAL_MS = 30_000;
|
|
27
|
-
/** Queen patrol period:
|
|
28
|
-
export const
|
|
27
|
+
/** Queen patrol period: near-real-time supervision (5s) by default. */
|
|
28
|
+
export const DEFAULT_PATROL_INTERVAL_MS = 5_000;
|
|
29
|
+
/** Backward-compatible alias for the old patrol period constant. */
|
|
30
|
+
export const DEFAULT_PATROL_MS = DEFAULT_PATROL_INTERVAL_MS;
|
|
29
31
|
/** How long anomaly events coalesce before one digest is delivered to the queen. */
|
|
30
32
|
export const DEFAULT_ANOMALY_DEBOUNCE_MS = 3_000;
|
|
31
33
|
/** Maximum number of undelivered anomaly entries kept for the queen's pending list. */
|
|
@@ -70,10 +72,11 @@ const DEFAULTS = Object.freeze({
|
|
|
70
72
|
cardTimeoutMs: DEFAULT_CARD_TIMEOUT_MS,
|
|
71
73
|
heartbeatWarnMs: DEFAULT_HEARTBEAT_WARN_MS,
|
|
72
74
|
heartbeatIntervalMs: DEFAULT_HEARTBEAT_INTERVAL_MS,
|
|
73
|
-
// Queen coordination: the supervisor patrols every
|
|
74
|
-
// digest to the registered queen Session only when something
|
|
75
|
-
// Until a live queen Session exists the entries stay in the
|
|
76
|
-
patrolMs
|
|
75
|
+
// Queen coordination: the supervisor patrols every patrolIntervalMs and
|
|
76
|
+
// delivers ONE digest to the registered queen Session only when something
|
|
77
|
+
// needs attention. Until a live queen Session exists the entries stay in the
|
|
78
|
+
// pending list. `patrolMs` remains accepted as a legacy alias.
|
|
79
|
+
patrolIntervalMs: DEFAULT_PATROL_INTERVAL_MS,
|
|
77
80
|
notifyQueen: true,
|
|
78
81
|
anomalyDebounceMs: DEFAULT_ANOMALY_DEBOUNCE_MS,
|
|
79
82
|
anomalyMax: DEFAULT_ANOMALY_MAX,
|
|
@@ -307,7 +310,10 @@ export function resolveConfig(config = {}) {
|
|
|
307
310
|
if (cfg.parentSession !== null && cfg.parentSession !== undefined) cfg.parentSession = nonEmptyString(cfg.parentSession, 'parentSession');
|
|
308
311
|
else cfg.parentSession = null;
|
|
309
312
|
cfg.cwd = cfg.cwd === null || cfg.cwd === undefined ? process.cwd() : absolutePath(cfg.cwd, 'cwd');
|
|
310
|
-
|
|
313
|
+
// Accept the pre-1.0.14 `patrolMs` name as an alias for patrolIntervalMs.
|
|
314
|
+
if (config.patrolIntervalMs === undefined && config.patrolMs !== undefined) cfg.patrolIntervalMs = config.patrolMs;
|
|
315
|
+
cfg.patrolIntervalMs = positiveNumber(cfg.patrolIntervalMs, 'patrolIntervalMs');
|
|
316
|
+
cfg.patrolMs = cfg.patrolIntervalMs;
|
|
311
317
|
cfg.notifyQueen = boolean(cfg.notifyQueen, 'notifyQueen');
|
|
312
318
|
cfg.anomalyDebounceMs = positiveNumber(cfg.anomalyDebounceMs, 'anomalyDebounceMs');
|
|
313
319
|
cfg.anomalyMax = positiveInteger(cfg.anomalyMax, 'anomalyMax', 1000);
|
package/lib/round.js
CHANGED
|
@@ -178,6 +178,7 @@ export function createRoundRunner({
|
|
|
178
178
|
writeRun = writeRunRecord,
|
|
179
179
|
parentProvider,
|
|
180
180
|
onAnomaly,
|
|
181
|
+
onSettled,
|
|
181
182
|
now = () => Date.now(),
|
|
182
183
|
log = () => {},
|
|
183
184
|
}) {
|
|
@@ -494,6 +495,13 @@ export function createRoundRunner({
|
|
|
494
495
|
emitAnomaly({ kind: 'card-failed', repo, cardId: id, role: card.role, detail });
|
|
495
496
|
}
|
|
496
497
|
unregisterActive(repo, id);
|
|
498
|
+
try {
|
|
499
|
+
if (typeof onSettled === 'function') {
|
|
500
|
+
onSettled({ repo, cardId: id, role: card.role, status, sha: patch.commit ?? null, reason: patch.reason ?? null });
|
|
501
|
+
}
|
|
502
|
+
} catch (error) {
|
|
503
|
+
log('warn', 'onSettled hook failed', error);
|
|
504
|
+
}
|
|
497
505
|
};
|
|
498
506
|
let activation;
|
|
499
507
|
let releaseEnv = () => {};
|
package/lib/supervisor.js
CHANGED
|
@@ -138,7 +138,10 @@ export class HiveSupervisor {
|
|
|
138
138
|
* @param {(repo: string) => Promise<string|{mode: string}>} [options.readMode] Hive mode reader (free/freeze)
|
|
139
139
|
* @param {() => Promise<string[]>} [options.discover]
|
|
140
140
|
* @param {(event: object) => void} [options.onAnomaly] supervision event sink (queen digest)
|
|
141
|
+
* @param {(event: object) => void} [options.onGateChange] gate phase/release-readiness change sink
|
|
141
142
|
* @param {(sessionId: string) => void} [options.onQueenSession] called after a queen Session registers
|
|
143
|
+
* @param {() => { names?: string[], sessionId?: string | null, listedAt?: string | null, error?: string | null }} [options.queenTools] diagnostic: tools visible to the queen agent
|
|
144
|
+
* @param {(repo: string, review: object) => Promise<object>} [options.archReview] host-side arch_review fallback
|
|
142
145
|
* @param {() => number} [options.pendingAnomalies] undelivered queen anomalies reported in status
|
|
143
146
|
* @param {() => number} [options.pendingCheckpoints] undelivered progress checkpoints reported in status
|
|
144
147
|
* @param {Console} [options.logger]
|
|
@@ -177,7 +180,10 @@ export class HiveSupervisor {
|
|
|
177
180
|
this.queenBoundary = options.queenBoundary ?? { count: 0, last: null };
|
|
178
181
|
this.readMode = typeof options.readMode === 'function' ? options.readMode : undefined;
|
|
179
182
|
this.onAnomaly = typeof options.onAnomaly === 'function' ? options.onAnomaly : undefined;
|
|
183
|
+
this.onGateChange = typeof options.onGateChange === 'function' ? options.onGateChange : undefined;
|
|
180
184
|
this.onQueenSession = typeof options.onQueenSession === 'function' ? options.onQueenSession : undefined;
|
|
185
|
+
this.queenTools = typeof options.queenTools === 'function' ? options.queenTools : undefined;
|
|
186
|
+
this.archReview = typeof options.archReview === 'function' ? options.archReview : undefined;
|
|
181
187
|
this.pendingAnomalies = typeof options.pendingAnomalies === 'function' ? options.pendingAnomalies : undefined;
|
|
182
188
|
this.pendingCheckpoints = typeof options.pendingCheckpoints === 'function' ? options.pendingCheckpoints : undefined;
|
|
183
189
|
this.discover = options.discover;
|
|
@@ -391,6 +397,22 @@ export class HiveSupervisor {
|
|
|
391
397
|
return this.status();
|
|
392
398
|
}
|
|
393
399
|
|
|
400
|
+
/**
|
|
401
|
+
* Host-side fallback for the queen's arch-review tool. The normal path is the
|
|
402
|
+
* registered hive_arch_review tool (inside run_code under PTC); this method
|
|
403
|
+
* lets a host/panel/CLI caller record the same event when the agent tool is
|
|
404
|
+
* unavailable.
|
|
405
|
+
* @param {string} repo
|
|
406
|
+
* @param {{ card: string, verdict: string, findings?: string[], summary?: string }} review
|
|
407
|
+
* @returns {Promise<object>}
|
|
408
|
+
*/
|
|
409
|
+
async recordArchReview(repo, review) {
|
|
410
|
+
if (typeof this.archReview !== 'function') {
|
|
411
|
+
throw new Error('host arch-review fallback is not configured');
|
|
412
|
+
}
|
|
413
|
+
return this.archReview(repo, review);
|
|
414
|
+
}
|
|
415
|
+
|
|
394
416
|
/**
|
|
395
417
|
* Live worker Session ids across every registered repository. The panel uses
|
|
396
418
|
* this to exempt worker conversations from the queen role/prompt and guard.
|
|
@@ -433,6 +455,7 @@ export class HiveSupervisor {
|
|
|
433
455
|
*/
|
|
434
456
|
async #gateFor(repo, signal) {
|
|
435
457
|
const entry = this.#entry(repo);
|
|
458
|
+
const previous = entry.gate ?? null;
|
|
436
459
|
if (this.listAll === undefined) {
|
|
437
460
|
entry.gate = { phase: 'ungated', releaseReady: false, reason: 'gate ordering is not configured' };
|
|
438
461
|
return entry.gate;
|
|
@@ -441,6 +464,7 @@ export class HiveSupervisor {
|
|
|
441
464
|
const tasks = await this.listAll(repo, { signal });
|
|
442
465
|
const gate = gatePhase(tasks);
|
|
443
466
|
entry.gate = gate;
|
|
467
|
+
this.#emitGateChange(repo, previous, gate);
|
|
444
468
|
return gate;
|
|
445
469
|
} catch (error) {
|
|
446
470
|
entry.gate = {
|
|
@@ -453,6 +477,18 @@ export class HiveSupervisor {
|
|
|
453
477
|
}
|
|
454
478
|
}
|
|
455
479
|
|
|
480
|
+
/** Report a gate phase / release-readiness change for the immediate checkpoint path. */
|
|
481
|
+
#emitGateChange(repo, previous, gate) {
|
|
482
|
+
if (typeof this.onGateChange !== 'function' || previous === null) return;
|
|
483
|
+
const phaseChanged = previous.phase !== gate.phase;
|
|
484
|
+
const releaseChanged = previous.releaseReady !== gate.releaseReady;
|
|
485
|
+
if (!phaseChanged && !releaseChanged) return;
|
|
486
|
+
try {
|
|
487
|
+
this.onGateChange({ repo, previous, gate });
|
|
488
|
+
} catch (error) {
|
|
489
|
+
this.#log('warn', 'gate-change sink failed', messageOf(error));
|
|
490
|
+
}
|
|
491
|
+
}
|
|
456
492
|
/**
|
|
457
493
|
* Filter a ready list through the current gate phase. Manual rounds use this
|
|
458
494
|
* so the queen's on-demand run obeys the same gate order as the resident one.
|
|
@@ -553,6 +589,8 @@ export class HiveSupervisor {
|
|
|
553
589
|
// queen Session.
|
|
554
590
|
pendingAnomalies: this.#pendingAnomalyCount(),
|
|
555
591
|
pendingCheckpoints: this.#pendingCheckpointCount(),
|
|
592
|
+
// One-shot diagnostic: which tool names the registered queen agent can see.
|
|
593
|
+
...this.#queenToolsStatus(),
|
|
556
594
|
repoCount: this.repos.size,
|
|
557
595
|
// Worker Session ids across all repositories: the panel exempts them from
|
|
558
596
|
// queen-mode prompt injection and the guard exempts their tool calls.
|
|
@@ -836,6 +874,23 @@ export class HiveSupervisor {
|
|
|
836
874
|
};
|
|
837
875
|
}
|
|
838
876
|
|
|
877
|
+
/** Tool visibility diagnostic for status; observability never throws. */
|
|
878
|
+
#queenToolsStatus() {
|
|
879
|
+
try {
|
|
880
|
+
const info = typeof this.queenTools === 'function' ? this.queenTools() : null;
|
|
881
|
+
if (info === null || typeof info !== 'object') {
|
|
882
|
+
return { queenTools: [], queenToolsSessionId: null, queenToolsListedAt: null, queenToolsError: null };
|
|
883
|
+
}
|
|
884
|
+
return {
|
|
885
|
+
queenTools: Array.isArray(info.names) ? info.names : [],
|
|
886
|
+
queenToolsSessionId: typeof info.sessionId === 'string' ? info.sessionId : null,
|
|
887
|
+
queenToolsListedAt: typeof info.listedAt === 'string' ? info.listedAt : null,
|
|
888
|
+
queenToolsError: typeof info.error === 'string' ? info.error : null,
|
|
889
|
+
};
|
|
890
|
+
} catch {
|
|
891
|
+
return { queenTools: [], queenToolsSessionId: null, queenToolsListedAt: null, queenToolsError: 'status-read-failed' };
|
|
892
|
+
}
|
|
893
|
+
}
|
|
839
894
|
/** Emit one supervision event without letting the sink break scheduling. */
|
|
840
895
|
#anomaly(event) {
|
|
841
896
|
if (this.onAnomaly === undefined) return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-hive-runner",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.15",
|
|
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",
|