dsh-hive-runner 1.0.13 → 1.0.14
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 +25 -0
- package/README.md +13 -11
- package/README.zh-CN.md +4 -3
- package/SPEC.md +11 -8
- package/cordis.patch.yml +5 -5
- package/docs/DESIGN.md +20 -12
- package/index.js +13 -1
- package/lib/checkpoint.js +92 -7
- package/lib/config.js +13 -7
- package/lib/round.js +8 -0
- package/lib/supervisor.js +16 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,27 @@ 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.14] - 2026-12-05
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- Progress checkpoints are near-real-time again: the patrol default is now
|
|
15
|
+
`patrolIntervalMs: 5000` (the old `patrolMs` name is accepted as an alias), the first
|
|
16
|
+
drained checkpoint after a supervisor restart needs only 5 seconds of drained state,
|
|
17
|
+
and the first digest is labelled `supervisor 刚启动`. Later drain checkpoints keep the
|
|
18
|
+
10-minute `checkpointDrainMs` minimum.
|
|
19
|
+
- Card settle (`done`/`failed`) and gate-phase/releaseReady changes trigger an immediate
|
|
20
|
+
checkpoint request via new `onSettled`/`onGateChange` hooks instead of waiting for the
|
|
21
|
+
next patrol tick. Same-state dedup still applies.
|
|
22
|
+
- Board-read overhead is bounded: consecutive checkpoint ticks reuse the same repository
|
|
23
|
+
`hive-tasks list --json` result for 2 seconds (events invalidate it), and a failing
|
|
24
|
+
shell read backs off for 15 seconds.
|
|
25
|
+
|
|
26
|
+
### Compatibility
|
|
27
|
+
|
|
28
|
+
- `patrolMs` is still accepted as a legacy alias for `patrolIntervalMs`; both keys are
|
|
29
|
+
reported on the resolved config.
|
|
30
|
+
|
|
10
31
|
## [1.0.13] - 2026-12-05
|
|
11
32
|
|
|
12
33
|
### Added
|
|
@@ -22,6 +43,10 @@ iterations of the plugin before this repository was published.
|
|
|
22
43
|
checkpoints pending (`status.pendingCheckpoints`) until the next patrol/registration.
|
|
23
44
|
- New config keys `checkpointDrainMs` / `checkpointIdleMs` (defaults 600000).
|
|
24
45
|
|
|
46
|
+
### Published
|
|
47
|
+
|
|
48
|
+
- npm: `dsh-hive-runner@1.0.13` on 2026-12-05.
|
|
49
|
+
|
|
25
50
|
## [1.0.12] - 2026-12-05
|
|
26
51
|
|
|
27
52
|
### 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
|
@@ -350,8 +350,8 @@ Two sources feed one digest:
|
|
|
350
350
|
`auto-paused`, `environment-error`. The plugin pushes them into an in-memory
|
|
351
351
|
AnomalyFeed (`lib/anomalies.js`): entries coalesce per `(kind, repo, cardId)`
|
|
352
352
|
inside a ten-minute window and are bounded by `anomalyMax`.
|
|
353
|
-
- **Patrol** — `lib/patrol.js` re-reads `supervisor.status()` every `
|
|
354
|
-
(default 5
|
|
353
|
+
- **Patrol** — `lib/patrol.js` re-reads `supervisor.status()` every `patrolIntervalMs`
|
|
354
|
+
(default 5 seconds; same-repo board reads reuse a 2-second cache) and pushes `auto-paused`, `environment-error`, `heartbeat-warn`
|
|
355
355
|
(agent heartbeat `warn`) and `card-timeout` (agent past `timeoutAt`), so a missed
|
|
356
356
|
event is recovered even though only one digest is delivered.
|
|
357
357
|
|
|
@@ -376,12 +376,15 @@ delivers nothing.
|
|
|
376
376
|
|
|
377
377
|
### 8.6.1 Progress checkpoints
|
|
378
378
|
|
|
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
|
-
|
|
379
|
+
The 5-second patrol also sends a progress digest to the queen (not just anomalies):
|
|
380
|
+
(1) the queue is drained — no pending/claimed tasks, including failed ones — and the
|
|
381
|
+
first checkpoint after a restart needs only 5 seconds of drained state; later ones use
|
|
382
|
+
`checkpointDrainMs` (default 10 min); (2) all tasks are done or the gate phase advanced
|
|
383
|
+
/ `releaseReady` became true — delivered immediately via the settled/gate hooks, not on
|
|
384
|
+
the next tick; (3) no ready task exists while unfinished tasks remain, continuously for
|
|
385
|
+
`checkpointIdleMs` (default 10 min). The first checkpoint after startup is labelled
|
|
386
|
+
`supervisor 刚启动`. Board reads reuse a 2-second same-repo cache and back off 15 seconds
|
|
387
|
+
after a shell failure. The digest carries done/failed/pending/claimed/total counts, recent completed
|
|
385
388
|
task titles, gate phase/releaseReady, a bounded last-10-minute event summary, the
|
|
386
389
|
trigger, and the instruction: `评估目标是否达成:未达成请继续拆解下一批任务并说明依据;
|
|
387
390
|
达成请汇总结果并请人类确认发布。`. The same state is sent once (state signature =
|
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
|
@@ -271,7 +271,7 @@ auto-pause failure budget; status exposes `claimedButOrphaned`,
|
|
|
271
271
|
| `lib/events.js` | `.hive/events.jsonl` append/read plus the `arch_review`, `queen_intervention`, `queen_escalation` and `queen_boundary_violation` event contracts |
|
|
272
272
|
| `lib/queen-boundary.js` | `ctx.tools.guard` veto for queen → `subagent`/`subagent_fork`/`subagent_claude_code`; returns the correction and reports the attempt |
|
|
273
273
|
| `lib/limits.js` | `<repo>/.hive/limits.json` read/write/hot-reload and precedence helpers |
|
|
274
|
-
| `lib/config.js` | Config defaults/validation (`
|
|
274
|
+
| `lib/config.js` | Config defaults/validation (`patrolIntervalMs`, `notifyQueen`, `anomaly*`, `checkpoint*`, `rolesBin`), role map parsing, effective-limit helpers |
|
|
275
275
|
| `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
276
|
| `lib/shell.js` | `ctx.shell.resolve/execute` adapter (sandbox policy per call) |
|
|
277
277
|
| `lib/discover.js` | `refs/hive/v1` repository discovery |
|
|
@@ -320,23 +320,31 @@ lessons, and the supervisor feeds it anomalies. The design constraints:
|
|
|
320
320
|
|
|
321
321
|
### Progress checkpoints
|
|
322
322
|
|
|
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
|
|
323
|
+
A 5-second patrol also reports progress, not only problems. `lib/checkpoint.js` runs
|
|
324
|
+
from the patrol inspect hook for every registered repository and sends a checkpoint
|
|
325
|
+
when:
|
|
325
326
|
|
|
326
|
-
1. the queue is drained (no pending/claimed tasks, including failed ones)
|
|
327
|
-
|
|
328
|
-
|
|
327
|
+
1. the queue is drained (no pending/claimed tasks, including failed ones); the first
|
|
328
|
+
drained checkpoint after a supervisor restart needs only 5 seconds of drained state,
|
|
329
|
+
later ones use `checkpointDrainMs` (default 10 min);
|
|
330
|
+
2. all tasks are done, or the gate phase advanced / `releaseReady` flipped true — this
|
|
331
|
+
fires immediately via the `onSettled`/`onGateChange` hooks, without waiting for the
|
|
332
|
+
next patrol tick;
|
|
329
333
|
3. no ready task exists while unfinished tasks remain, continuously for
|
|
330
334
|
`checkpointIdleMs` (default 10 min).
|
|
331
335
|
|
|
332
|
-
The
|
|
333
|
-
|
|
334
|
-
|
|
336
|
+
The first checkpoint after startup carries `Context: supervisor 刚启动` so the queen
|
|
337
|
+
knows the digest is from a fresh process. The digest contains
|
|
338
|
+
`done/failed/pending/claimed/total`, the last completed task titles, gate
|
|
339
|
+
phase/releaseReady/reason, a bounded summary of events from the last 10 minutes, the
|
|
340
|
+
trigger, and the instruction `评估目标是否达成:未达成请继续拆解下一批任务并说明依据;达成请汇总结果并请人类确认发布。`.
|
|
335
341
|
It is delivered through the queen notifier. The state signature (counts + gate +
|
|
336
342
|
releaseReady + recent completed ids) deduplicates it: the same state is sent once and
|
|
337
|
-
only a state change re-arms it.
|
|
338
|
-
|
|
339
|
-
|
|
343
|
+
only a state change re-arms it. Board reads reuse a 2-second same-repo cache (events
|
|
344
|
+
invalidate it); a failing `hive-tasks list` backs off for 15 seconds. Without a live
|
|
345
|
+
queen Session the checkpoint is kept in the controller's pending list (status
|
|
346
|
+
`pendingCheckpoints`) and flushed by the next patrol or queen registration; it never
|
|
347
|
+
falls through to an anomaly digest.
|
|
340
348
|
|
|
341
349
|
### Tool boundary: hard veto through `ctx.tools.guard`
|
|
342
350
|
|
package/index.js
CHANGED
|
@@ -115,6 +115,13 @@ export function apply(ctx, config = {}) {
|
|
|
115
115
|
limitFor: (repo, role) => limits.limitFor(repo, role),
|
|
116
116
|
parentProvider: (explicit) => parentProviderImpl(explicit),
|
|
117
117
|
onAnomaly: (event) => recordAnomaly(event),
|
|
118
|
+
// A finished worker or a settled card asks for a near-real-time checkpoint
|
|
119
|
+
// check instead of waiting for the next patrol tick.
|
|
120
|
+
onSettled: (event) => {
|
|
121
|
+
if (checkpoint !== undefined) {
|
|
122
|
+
void checkpoint.requestTick({ repo: event.repo }).catch((error) => log('warn', 'checkpoint event tick failed', error));
|
|
123
|
+
}
|
|
124
|
+
},
|
|
118
125
|
log,
|
|
119
126
|
});
|
|
120
127
|
parentProviderImpl = async (explicit) => {
|
|
@@ -242,6 +249,11 @@ export function apply(ctx, config = {}) {
|
|
|
242
249
|
queenBoundary,
|
|
243
250
|
readMode: (repo) => commands.mode(repo),
|
|
244
251
|
onAnomaly: (event) => recordAnomaly(event),
|
|
252
|
+
onGateChange: (event) => {
|
|
253
|
+
if (checkpoint !== undefined) {
|
|
254
|
+
void checkpoint.requestTick({ repo: event.repo }).catch((error) => log('warn', 'checkpoint gate tick failed', error));
|
|
255
|
+
}
|
|
256
|
+
},
|
|
245
257
|
onQueenSession: () => {
|
|
246
258
|
if (patrol !== undefined) patrol.flushPending();
|
|
247
259
|
if (checkpoint !== undefined) checkpoint.flushPending();
|
|
@@ -256,7 +268,7 @@ export function apply(ctx, config = {}) {
|
|
|
256
268
|
supervisor,
|
|
257
269
|
feed: anomalies,
|
|
258
270
|
notifier: resolved.notifyQueen ? notifier : undefined,
|
|
259
|
-
intervalMs: resolved.
|
|
271
|
+
intervalMs: resolved.patrolIntervalMs,
|
|
260
272
|
debounceMs: resolved.anomalyDebounceMs,
|
|
261
273
|
// Every patrol also audits done cards for a missing architecture review.
|
|
262
274
|
inspect: async () => {
|
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,6 +138,7 @@ 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
|
|
142
143
|
* @param {() => number} [options.pendingAnomalies] undelivered queen anomalies reported in status
|
|
143
144
|
* @param {() => number} [options.pendingCheckpoints] undelivered progress checkpoints reported in status
|
|
@@ -177,6 +178,7 @@ export class HiveSupervisor {
|
|
|
177
178
|
this.queenBoundary = options.queenBoundary ?? { count: 0, last: null };
|
|
178
179
|
this.readMode = typeof options.readMode === 'function' ? options.readMode : undefined;
|
|
179
180
|
this.onAnomaly = typeof options.onAnomaly === 'function' ? options.onAnomaly : undefined;
|
|
181
|
+
this.onGateChange = typeof options.onGateChange === 'function' ? options.onGateChange : undefined;
|
|
180
182
|
this.onQueenSession = typeof options.onQueenSession === 'function' ? options.onQueenSession : undefined;
|
|
181
183
|
this.pendingAnomalies = typeof options.pendingAnomalies === 'function' ? options.pendingAnomalies : undefined;
|
|
182
184
|
this.pendingCheckpoints = typeof options.pendingCheckpoints === 'function' ? options.pendingCheckpoints : undefined;
|
|
@@ -433,6 +435,7 @@ export class HiveSupervisor {
|
|
|
433
435
|
*/
|
|
434
436
|
async #gateFor(repo, signal) {
|
|
435
437
|
const entry = this.#entry(repo);
|
|
438
|
+
const previous = entry.gate ?? null;
|
|
436
439
|
if (this.listAll === undefined) {
|
|
437
440
|
entry.gate = { phase: 'ungated', releaseReady: false, reason: 'gate ordering is not configured' };
|
|
438
441
|
return entry.gate;
|
|
@@ -441,6 +444,7 @@ export class HiveSupervisor {
|
|
|
441
444
|
const tasks = await this.listAll(repo, { signal });
|
|
442
445
|
const gate = gatePhase(tasks);
|
|
443
446
|
entry.gate = gate;
|
|
447
|
+
this.#emitGateChange(repo, previous, gate);
|
|
444
448
|
return gate;
|
|
445
449
|
} catch (error) {
|
|
446
450
|
entry.gate = {
|
|
@@ -453,6 +457,18 @@ export class HiveSupervisor {
|
|
|
453
457
|
}
|
|
454
458
|
}
|
|
455
459
|
|
|
460
|
+
/** Report a gate phase / release-readiness change for the immediate checkpoint path. */
|
|
461
|
+
#emitGateChange(repo, previous, gate) {
|
|
462
|
+
if (typeof this.onGateChange !== 'function' || previous === null) return;
|
|
463
|
+
const phaseChanged = previous.phase !== gate.phase;
|
|
464
|
+
const releaseChanged = previous.releaseReady !== gate.releaseReady;
|
|
465
|
+
if (!phaseChanged && !releaseChanged) return;
|
|
466
|
+
try {
|
|
467
|
+
this.onGateChange({ repo, previous, gate });
|
|
468
|
+
} catch (error) {
|
|
469
|
+
this.#log('warn', 'gate-change sink failed', messageOf(error));
|
|
470
|
+
}
|
|
471
|
+
}
|
|
456
472
|
/**
|
|
457
473
|
* Filter a ready list through the current gate phase. Manual rounds use this
|
|
458
474
|
* so the queen's on-demand run obeys the same gate order as the resident one.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-hive-runner",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.14",
|
|
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",
|