dsh-hive-runner 1.0.19 → 1.0.21
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 +48 -0
- package/SPEC.md +11 -1
- package/docs/DESIGN.md +5 -1
- package/index.js +46 -7
- package/lib/commands.js +1 -1
- package/lib/limits.js +17 -0
- package/lib/ops.js +6 -2
- package/lib/round.js +15 -6
- package/lib/services.js +12 -12
- package/lib/supervisor.js +72 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,50 @@ 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.21] - 2026-12-05
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- Concurrency limits are discoverable for roles that only appear on the board: each
|
|
15
|
+
repo status now exposes `taskRoles` and every `roles[role]` carries `source` =
|
|
16
|
+
`limits.json` | `config` | `default`. An undefined role such as `worker` can set its
|
|
17
|
+
cap in `.hive/limits.json` (e.g. `{"worker": 20}`) and the panel can see both the
|
|
18
|
+
effective limit and its source; without a file entry it falls back to
|
|
19
|
+
`defaultRoleConcurrency` with `source: "default"`.
|
|
20
|
+
- Creating a card (`hive_tasks add`, and intervention-created cards) calls
|
|
21
|
+
`hiveSupervisor.wake(repo)`, so an idle repository with 120 s backoff is re-checked
|
|
22
|
+
immediately instead of waiting for the next idle window; `wakeRequested` is honored
|
|
23
|
+
when a drain finishes.
|
|
24
|
+
|
|
25
|
+
### Tests
|
|
26
|
+
|
|
27
|
+
- limits file role source, board-only task role in status, `worker=20` live up to 20,
|
|
28
|
+
default fallback/source, and wake-on-new-card dispatch; 288 tests pass.
|
|
29
|
+
|
|
30
|
+
## [1.0.20] - 2026-12-05
|
|
31
|
+
|
|
32
|
+
### Fixed
|
|
33
|
+
|
|
34
|
+
- Event attribution follows the caller: `hive_tasks`/`hive_intervene`/
|
|
35
|
+
`hive_arch_review`/`hive_roles`/`hive_lesson_add` calls from a queen Session pass
|
|
36
|
+
`HIVE_AGENT=queen` to the CLI and write `actor: "queen"` instead of the generic
|
|
37
|
+
`dsh`; worker completion (`done`/`fail`) writes `worker:<role>`; host actions
|
|
38
|
+
(service card creation/audit, service events, host arch-review fallback) write
|
|
39
|
+
`actor: "supervisor"`. Claim identity stays the configured runner identity so
|
|
40
|
+
restart claim recovery and guard announcements remain consistent; the CLI
|
|
41
|
+
`HIVE_AGENT` is the same actor for each individual action.
|
|
42
|
+
- Worker completion events no longer inherit the generic configured agent name.
|
|
43
|
+
|
|
44
|
+
### Tests
|
|
45
|
+
|
|
46
|
+
- CLI `HIVE_AGENT` attribution for queen/worker/supervisor, round completion
|
|
47
|
+
attribution `worker:coder`, supervisor-created service card and service event
|
|
48
|
+
`actor: supervisor`; 281 tests pass.
|
|
49
|
+
|
|
50
|
+
### Published
|
|
51
|
+
|
|
52
|
+
- npm: `dsh-hive-runner@1.0.20` on 2026-12-05.
|
|
53
|
+
|
|
10
54
|
## [1.0.19] - 2026-12-05
|
|
11
55
|
|
|
12
56
|
### Fixed
|
|
@@ -24,6 +68,10 @@ iterations of the plugin before this repository was published.
|
|
|
24
68
|
- Prefix/id rejection, normal result-only titles, split child validation, and the tool
|
|
25
69
|
description rule; 277 tests pass.
|
|
26
70
|
|
|
71
|
+
### Published
|
|
72
|
+
|
|
73
|
+
- npm: `dsh-hive-runner@1.0.19` on 2026-12-05.
|
|
74
|
+
|
|
27
75
|
## [1.0.18] - 2026-12-05
|
|
28
76
|
|
|
29
77
|
### Fixed
|
package/SPEC.md
CHANGED
|
@@ -124,7 +124,10 @@ wrong method -> `405` (`hive/method-not-allowed`).
|
|
|
124
124
|
```
|
|
125
125
|
|
|
126
126
|
- `roles[role].limit` — effective live-agent cap (persisted file > repo config >
|
|
127
|
-
global role config > `defaultRoleConcurrency`).
|
|
127
|
+
global role config > `defaultRoleConcurrency`), with `roles[role].source` =
|
|
128
|
+
`limits.json` | `config` | `default`.
|
|
129
|
+
- `taskRoles` — roles actually present on the board, including roles absent from
|
|
130
|
+
`roles.yaml`/config; they appear in `roles` with their effective limit and source.
|
|
128
131
|
- `roles[role].live` — agents running right now; a finished agent frees its slot
|
|
129
132
|
immediately.
|
|
130
133
|
- `roles[role].queued` — fetched tasks waiting for a slot; they do not count as live.
|
|
@@ -268,6 +271,13 @@ health check; the card can be done while the service keeps running. The patrol r
|
|
|
268
271
|
records, probes the declared ports, and creates or reopens a service card when a service
|
|
269
272
|
is down, emitting `service_down`/`service_started` events. Commands or ports outside the
|
|
270
273
|
YAML are rejected. `hive_ops action=services` lists declared/running state.
|
|
274
|
+
Event/CLI attribution follows the caller: queen `hive_tasks`/`hive_intervene`/
|
|
275
|
+
`hive_arch_review` actions set `HIVE_AGENT=queen` and write `actor: "queen"`; worker
|
|
276
|
+
completion (`done`/`fail`) sets `HIVE_AGENT=worker:<role>` and writes that actor; host
|
|
277
|
+
actions (service card creation/audit, service events, host arch-review fallback) write
|
|
278
|
+
`actor: "supervisor"`. Claim identity stays the configured runner identity so restart
|
|
279
|
+
claim recovery remains consistent; the CLI `HIVE_AGENT` is the same actor for each
|
|
280
|
+
individual action.
|
|
271
281
|
The queen's tools never claim or finish a task: `hive-tasks claim`/`done` stay with the
|
|
272
282
|
supervisor. `hive tasks rm` is forwarded without `--force`, so a claimed task is refused
|
|
273
283
|
by the CLI instead of being deleted under a live agent. `hive_run_round` refuses to run
|
package/docs/DESIGN.md
CHANGED
|
@@ -113,7 +113,11 @@ Response:
|
|
|
113
113
|
```
|
|
114
114
|
|
|
115
115
|
- `roles[role].limit` — effective live-agent cap (persisted file > config >
|
|
116
|
-
`defaultRoleConcurrency`).
|
|
116
|
+
`defaultRoleConcurrency`), with `roles[role].source` = `limits.json` | `config` |
|
|
117
|
+
`default`.
|
|
118
|
+
- `taskRoles` — roles present on the board even when `roles.yaml`/config omit them;
|
|
119
|
+
they are merged into `roles` with their limit/source so the panel can discover and set
|
|
120
|
+
them.
|
|
117
121
|
- `roles[role].live` — task agents running **now**; a completed agent frees
|
|
118
122
|
its slot immediately.
|
|
119
123
|
- `roles[role].queued` — fetched tasks waiting for a slot (they do not count
|
package/index.js
CHANGED
|
@@ -204,6 +204,34 @@ export function apply(ctx, config = {}) {
|
|
|
204
204
|
return null;
|
|
205
205
|
}
|
|
206
206
|
|
|
207
|
+
/**
|
|
208
|
+
* Event/CLI actor for one tool call: queen actions are `queen`, worker
|
|
209
|
+
* completions `worker:<role>`, host-internal work `supervisor`.
|
|
210
|
+
* @param {object} [exec]
|
|
211
|
+
* @returns {string}
|
|
212
|
+
*/
|
|
213
|
+
function actorFor(exec) {
|
|
214
|
+
const session = exec?.agent?.session;
|
|
215
|
+
const sessionId = session?.id;
|
|
216
|
+
if (typeof sessionId === 'string' && sessionId !== '') {
|
|
217
|
+
try {
|
|
218
|
+
if (supervisor.isQueenSession(sessionId)) return 'queen';
|
|
219
|
+
} catch {
|
|
220
|
+
// Continue with cwd/worker detection.
|
|
221
|
+
}
|
|
222
|
+
const cwd = resolveQueenBoundaryCwd(exec?.agent, session);
|
|
223
|
+
if (typeof cwd === 'string' && cwd !== '' && hasQueenRole(cwd)) return 'queen';
|
|
224
|
+
try {
|
|
225
|
+
const worker = supervisor.workerForSession(sessionId);
|
|
226
|
+
if (worker !== null && typeof worker.role === 'string' && worker.role !== '') {
|
|
227
|
+
return 'worker:' + worker.role;
|
|
228
|
+
}
|
|
229
|
+
} catch {
|
|
230
|
+
// Fall through to the configured identity.
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return typeof resolved.agent === 'string' && resolved.agent !== '' ? resolved.agent : 'worker';
|
|
234
|
+
}
|
|
207
235
|
/** Idempotently register a cwd-recognized queen so the panel can show it. */
|
|
208
236
|
function registerDetectedQueen(sessionId, cwd) {
|
|
209
237
|
try {
|
|
@@ -602,7 +630,7 @@ export function apply(ctx, config = {}) {
|
|
|
602
630
|
},
|
|
603
631
|
execute: async (args = {}, exec) => {
|
|
604
632
|
const repo = repoOf(args);
|
|
605
|
-
const options = { signal: exec?.signal, session: exec?.agent?.session };
|
|
633
|
+
const options = { signal: exec?.signal, session: exec?.agent?.session, agent: actorFor(exec) };
|
|
606
634
|
const action = String(args.action ?? '');
|
|
607
635
|
if (action === 'list') {
|
|
608
636
|
const cards = await commands.list(repo, { state: args.state, role: args.role }, options);
|
|
@@ -627,6 +655,7 @@ export function apply(ctx, config = {}) {
|
|
|
627
655
|
reviewOf: args.reviewOf,
|
|
628
656
|
draft: args.draft,
|
|
629
657
|
}, options);
|
|
658
|
+
supervisor.wake(repo);
|
|
630
659
|
return jsonText({ ok: true, card });
|
|
631
660
|
}
|
|
632
661
|
if (action === 'edit') {
|
|
@@ -715,9 +744,13 @@ export function apply(ctx, config = {}) {
|
|
|
715
744
|
}
|
|
716
745
|
const cardId = typeof review.card === 'string' ? review.card.trim() : '';
|
|
717
746
|
if (cardId === '') throw new Error('hive_arch_review needs card');
|
|
747
|
+
const actor = typeof review.actor === 'string' && review.actor !== ''
|
|
748
|
+
? review.actor
|
|
749
|
+
: (exec?.agent === undefined ? 'supervisor' : actorFor(exec));
|
|
718
750
|
const card = await commands.show(repo, cardId, {
|
|
719
751
|
signal: exec?.signal,
|
|
720
752
|
session: exec?.agent?.session,
|
|
753
|
+
agent: actor,
|
|
721
754
|
});
|
|
722
755
|
if (card === null || card === undefined) throw new Error('no such card: ' + cardId);
|
|
723
756
|
if (card.state !== 'done') {
|
|
@@ -728,6 +761,7 @@ export function apply(ctx, config = {}) {
|
|
|
728
761
|
verdict: review.verdict,
|
|
729
762
|
findings: review.findings,
|
|
730
763
|
summary: review.summary,
|
|
764
|
+
actor,
|
|
731
765
|
});
|
|
732
766
|
}
|
|
733
767
|
registerTextTool({
|
|
@@ -779,20 +813,21 @@ export function apply(ctx, config = {}) {
|
|
|
779
813
|
queen = false;
|
|
780
814
|
}
|
|
781
815
|
if (!queen) throw new Error('hive_ops 仅女王可用');
|
|
816
|
+
const actor = actorFor(exec);
|
|
782
817
|
const repo = repoOf(args);
|
|
783
818
|
const policy = loadOpsPolicy(repo);
|
|
784
819
|
let plan;
|
|
785
820
|
try {
|
|
786
821
|
plan = planOpsAction(args.action, args.args, { repo, policy });
|
|
787
822
|
} catch (error) {
|
|
788
|
-
try { appendEvent(repo, opsDeniedEvent(repo, args.action, args.args, error, sessionId)); } catch { /* primary error wins */ }
|
|
823
|
+
try { appendEvent(repo, opsDeniedEvent(repo, args.action, args.args, error, sessionId, actor)); } catch { /* primary error wins */ }
|
|
789
824
|
throw error;
|
|
790
825
|
}
|
|
791
826
|
const appendHostEvent = (fields = {}) => {
|
|
792
827
|
try {
|
|
793
828
|
appendEvent(repo, {
|
|
794
829
|
ts: new Date().toISOString(),
|
|
795
|
-
actor
|
|
830
|
+
actor,
|
|
796
831
|
kind: 'hive_ops',
|
|
797
832
|
action: plan.action,
|
|
798
833
|
args: args.args ?? null,
|
|
@@ -809,6 +844,7 @@ export function apply(ctx, config = {}) {
|
|
|
809
844
|
repo,
|
|
810
845
|
argv: plan.argv,
|
|
811
846
|
action: plan.action,
|
|
847
|
+
actor,
|
|
812
848
|
validate: false,
|
|
813
849
|
run: opsRun,
|
|
814
850
|
session,
|
|
@@ -856,7 +892,7 @@ export function apply(ctx, config = {}) {
|
|
|
856
892
|
return jsonText({ ok: true, action: plan.action, repo, ...result });
|
|
857
893
|
} catch (error) {
|
|
858
894
|
if (error?.opsEventRecorded !== true) {
|
|
859
|
-
try { appendEvent(repo, opsDeniedEvent(repo, args.action, args.args, error, sessionId)); } catch { /* primary error wins */ }
|
|
895
|
+
try { appendEvent(repo, opsDeniedEvent(repo, args.action, args.args, error, sessionId, actor)); } catch { /* primary error wins */ }
|
|
860
896
|
}
|
|
861
897
|
throw error;
|
|
862
898
|
}
|
|
@@ -899,7 +935,7 @@ export function apply(ctx, config = {}) {
|
|
|
899
935
|
scope: args.scope,
|
|
900
936
|
evidence: args.evidence,
|
|
901
937
|
status: args.status,
|
|
902
|
-
}, { signal: exec?.signal, session: exec?.agent?.session });
|
|
938
|
+
}, { signal: exec?.signal, session: exec?.agent?.session, agent: actorFor(exec) });
|
|
903
939
|
return jsonText({ ok: true, output });
|
|
904
940
|
},
|
|
905
941
|
});
|
|
@@ -939,7 +975,7 @@ export function apply(ctx, config = {}) {
|
|
|
939
975
|
},
|
|
940
976
|
execute: async (args = {}, exec) => {
|
|
941
977
|
const repo = repoOf(args);
|
|
942
|
-
const options = { signal: exec?.signal, session: exec?.agent?.session };
|
|
978
|
+
const options = { signal: exec?.signal, session: exec?.agent?.session, agent: actorFor(exec) };
|
|
943
979
|
const action = String(args.action ?? '');
|
|
944
980
|
if (action === 'list') return jsonText(await commands.rolesList(repo, options));
|
|
945
981
|
if (action === 'add') {
|
|
@@ -1033,7 +1069,8 @@ export function apply(ctx, config = {}) {
|
|
|
1033
1069
|
},
|
|
1034
1070
|
execute: async (args = {}, exec) => {
|
|
1035
1071
|
const repo = repoOf(args);
|
|
1036
|
-
const
|
|
1072
|
+
const actor = actorFor(exec);
|
|
1073
|
+
const options = { signal: exec?.signal, session: exec?.agent?.session, agent: actor };
|
|
1037
1074
|
const action = String(args.action ?? '');
|
|
1038
1075
|
const cardId = typeof args.card === 'string' ? args.card.trim() : '';
|
|
1039
1076
|
if (cardId === '') throw new Error('hive_intervene needs card');
|
|
@@ -1133,7 +1170,9 @@ export function apply(ctx, config = {}) {
|
|
|
1133
1170
|
newCards,
|
|
1134
1171
|
removed,
|
|
1135
1172
|
sessionId: args.sessionId,
|
|
1173
|
+
actor,
|
|
1136
1174
|
});
|
|
1175
|
+
if (newCards.length > 0) supervisor.wake(repo);
|
|
1137
1176
|
const events = readEvents(repo, { limit: 500 });
|
|
1138
1177
|
const count = interventionCounts(events).get(cardId) ?? 1;
|
|
1139
1178
|
let escalated = false;
|
package/lib/commands.js
CHANGED
|
@@ -43,7 +43,7 @@ export function validateTaskTitle(title) {
|
|
|
43
43
|
return value;
|
|
44
44
|
}
|
|
45
45
|
export const ID_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
46
|
-
export const AGENT_RE = /^[A-Za-z0-9][A-Za-z0-9._
|
|
46
|
+
export const AGENT_RE = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$/;
|
|
47
47
|
export const TTL_RE = /^\d{1,4}[smhd]$/;
|
|
48
48
|
export const SHA_RE = /^[0-9a-f]{7,64}$/;
|
|
49
49
|
|
package/lib/limits.js
CHANGED
|
@@ -127,6 +127,23 @@ export class RepoLimits {
|
|
|
127
127
|
return this.refresh(repo).limits;
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
+
/**
|
|
131
|
+
* Where the effective limit came from: persisted limits.json, config, or default.
|
|
132
|
+
* @param {string} repo
|
|
133
|
+
* @param {string} role
|
|
134
|
+
* @returns {'limits.json' | 'config' | 'default'}
|
|
135
|
+
*/
|
|
136
|
+
sourceFor(repo, role) {
|
|
137
|
+
const entry = this.#entry(repo);
|
|
138
|
+
if (!entry.loaded) this.refresh(repo);
|
|
139
|
+
const current = this.#entry(repo);
|
|
140
|
+
if (Object.hasOwn(current.limits, role)) return 'limits.json';
|
|
141
|
+
const overrides = this.config.repoRoleConcurrency?.[repo];
|
|
142
|
+
if (overrides !== undefined && Object.hasOwn(overrides, role)) return 'config';
|
|
143
|
+
if (Object.hasOwn(this.config.roleConcurrency ?? {}, role)) return 'config';
|
|
144
|
+
return 'default';
|
|
145
|
+
}
|
|
146
|
+
|
|
130
147
|
/** Current reload error, if any. */
|
|
131
148
|
errorFor(repo) {
|
|
132
149
|
return this.#entry(repo).error;
|
package/lib/ops.js
CHANGED
|
@@ -286,6 +286,7 @@ export function truncateOpsOutput(text, maxBytes = OPS_MAX_OUTPUT_BYTES) {
|
|
|
286
286
|
* command?: string,
|
|
287
287
|
* argv?: string[],
|
|
288
288
|
* action?: string,
|
|
289
|
+
* actor?: string,
|
|
289
290
|
* validate?: boolean,
|
|
290
291
|
* run: Function,
|
|
291
292
|
* session?: object,
|
|
@@ -301,6 +302,7 @@ export async function runOpsCommand({
|
|
|
301
302
|
command,
|
|
302
303
|
argv: inputArgv,
|
|
303
304
|
action = 'diagnose',
|
|
305
|
+
actor = 'supervisor',
|
|
304
306
|
validate = true,
|
|
305
307
|
run,
|
|
306
308
|
session,
|
|
@@ -331,6 +333,7 @@ export async function runOpsCommand({
|
|
|
331
333
|
ts: new Date(startedAt).toISOString(),
|
|
332
334
|
actor: 'hive-runner',
|
|
333
335
|
kind: 'hive_ops',
|
|
336
|
+
actor,
|
|
334
337
|
action,
|
|
335
338
|
command: argv.join(' '),
|
|
336
339
|
exitCode: null,
|
|
@@ -351,6 +354,7 @@ export async function runOpsCommand({
|
|
|
351
354
|
ts: new Date(startedAt).toISOString(),
|
|
352
355
|
actor: 'hive-runner',
|
|
353
356
|
kind: 'hive_ops',
|
|
357
|
+
actor,
|
|
354
358
|
action,
|
|
355
359
|
command: argv.join(' '),
|
|
356
360
|
exitCode: result?.exitCode ?? null,
|
|
@@ -373,10 +377,10 @@ export async function runOpsCommand({
|
|
|
373
377
|
}
|
|
374
378
|
|
|
375
379
|
/** Short deny helper used by the tool layer to record denied attempts. */
|
|
376
|
-
export function opsDeniedEvent(repo, action, args, error, sessionId = null) {
|
|
380
|
+
export function opsDeniedEvent(repo, action, args, error, sessionId = null, actor = 'supervisor') {
|
|
377
381
|
return {
|
|
378
382
|
ts: new Date().toISOString(),
|
|
379
|
-
actor
|
|
383
|
+
actor,
|
|
380
384
|
kind: 'hive_ops',
|
|
381
385
|
action: typeof action === 'string' ? action : null,
|
|
382
386
|
args: args ?? null,
|
package/lib/round.js
CHANGED
|
@@ -28,6 +28,11 @@ import { writeRunRecord } from './runs.js';
|
|
|
28
28
|
/** Reopen reason used when the supervisor recovers a claim after a restart. */
|
|
29
29
|
export const ORPHAN_REOPEN_REASON = 'orphaned by supervisor restart';
|
|
30
30
|
|
|
31
|
+
/** Attribution identity for a card worker (also the CLI HIVE_AGENT actor). */
|
|
32
|
+
export function workerActor(role) {
|
|
33
|
+
return 'worker:' + (typeof role === 'string' && role.trim() !== '' ? role.trim() : 'worker');
|
|
34
|
+
}
|
|
35
|
+
|
|
31
36
|
/** A round-level failure. `hive/capacity` is retried from the queue. */
|
|
32
37
|
export class RoundError extends Error {
|
|
33
38
|
constructor(code, message, options = {}) {
|
|
@@ -448,6 +453,7 @@ export function createRoundRunner({
|
|
|
448
453
|
/** Best-effort release of a claim when the worker could not run at all. */
|
|
449
454
|
async function releaseClaim(repo, id, error, signal, session) {
|
|
450
455
|
await commands.fail(repo, id, {
|
|
456
|
+
agent: 'supervisor',
|
|
451
457
|
reason: 'runner error: ' + tail(messageOf(error)),
|
|
452
458
|
instance: id,
|
|
453
459
|
signal,
|
|
@@ -460,6 +466,9 @@ export function createRoundRunner({
|
|
|
460
466
|
const service = assertProvider(config.provider);
|
|
461
467
|
const scope = scopeOf(card);
|
|
462
468
|
const claimAgent = agent ?? config.agent;
|
|
469
|
+
// Completion events attribute the worker by role; the claim identity stays the
|
|
470
|
+
// runner identity so restart claim recovery and guards remain consistent.
|
|
471
|
+
const eventActor = workerActor(card.role);
|
|
463
472
|
// Per-card consensus instance: several cards of one runner share the same
|
|
464
473
|
// HIVE_AGENT, so the card id is what makes their announcements distinct and
|
|
465
474
|
// lets `hive guard --json` report overlaps instead of treating every
|
|
@@ -549,7 +558,7 @@ export function createRoundRunner({
|
|
|
549
558
|
};
|
|
550
559
|
const abortReason = () => 'card timeout after ' + cardTimeoutMs + 'ms';
|
|
551
560
|
const failCard = async (reason, output = reason) => {
|
|
552
|
-
await commands.fail(repo, id, { agent:
|
|
561
|
+
await commands.fail(repo, id, { agent: eventActor, instance, reason, signal, session }).catch(() => {});
|
|
553
562
|
finishRun('failed', { exitCode: 1, output });
|
|
554
563
|
await releaseScope(repo, scope, { signal, session, agent: claimAgent, instance });
|
|
555
564
|
return { id, state: 'failed', reason };
|
|
@@ -735,19 +744,19 @@ export function createRoundRunner({
|
|
|
735
744
|
if (outcome.stopReason !== 'completed') {
|
|
736
745
|
const detail = outcome.diagnostic ? ': ' + tail(outcome.diagnostic) : '';
|
|
737
746
|
const reason = 'subagent stopped: ' + outcome.stopReason + detail;
|
|
738
|
-
await commands.fail(repo, id, { agent:
|
|
747
|
+
await commands.fail(repo, id, { agent: eventActor, instance, reason, signal, session });
|
|
739
748
|
finishRun('failed', { exitCode: 1, output: workerOutput(outcome, reason), reason });
|
|
740
749
|
await releaseScope(repo, scope, { signal, session, agent: claimAgent, instance });
|
|
741
750
|
return { id, state: 'failed', reason };
|
|
742
751
|
}
|
|
743
752
|
const verdict = await verify({ repo, before, card, agent: claimAgent, signal, session });
|
|
744
753
|
if (verdict.ok) {
|
|
745
|
-
await commands.done(repo, id, { agent:
|
|
754
|
+
await commands.done(repo, id, { agent: eventActor, instance, sha: verdict.head, verdict: 'pass', signal, session });
|
|
746
755
|
finishRun('done', { exitCode: 0, commit: verdict.head, output: workerOutput(outcome) });
|
|
747
756
|
await releaseScope(repo, scope, { signal, session, agent: claimAgent, instance });
|
|
748
757
|
return { id, state: 'done', sha: verdict.head };
|
|
749
758
|
}
|
|
750
|
-
await commands.fail(repo, id, { agent:
|
|
759
|
+
await commands.fail(repo, id, { agent: eventActor, instance, reason: verdict.reason, signal, session });
|
|
751
760
|
finishRun('failed', { exitCode: 1, output: workerOutput(outcome, verdict.reason), reason: verdict.reason });
|
|
752
761
|
await releaseScope(repo, scope, { signal, session, agent: claimAgent, instance });
|
|
753
762
|
return { id, state: 'failed', reason: verdict.reason };
|
|
@@ -858,7 +867,7 @@ export function createRoundRunner({
|
|
|
858
867
|
try {
|
|
859
868
|
await commands.reopen(repo, card.id, {
|
|
860
869
|
reason: ORPHAN_REOPEN_REASON,
|
|
861
|
-
agent:
|
|
870
|
+
agent: 'supervisor',
|
|
862
871
|
signal,
|
|
863
872
|
session,
|
|
864
873
|
});
|
|
@@ -912,7 +921,7 @@ export function createRoundRunner({
|
|
|
912
921
|
const ttlMs = parseTtlMs(ttl ?? config.ttl);
|
|
913
922
|
if (!alreadyClaimed) {
|
|
914
923
|
const before = await commands.head(repo, { agent: agentId, signal, session });
|
|
915
|
-
const claim = await commands.claim(repo, id, { signal, session, agent, instance: id, ttl });
|
|
924
|
+
const claim = await commands.claim(repo, id, { signal, session, agent: agentId, instance: id, ttl });
|
|
916
925
|
if (claim.exitCode !== 0) {
|
|
917
926
|
return { id, state: 'skipped', reason: tail(claim.stderr || claim.stdout) || 'claim rejected' };
|
|
918
927
|
}
|
package/lib/services.js
CHANGED
|
@@ -167,7 +167,7 @@ export function probePort(port, options = {}) {
|
|
|
167
167
|
* Used by a service-role worker/test; the plugin never invents a command outside
|
|
168
168
|
* the declarations.
|
|
169
169
|
*/
|
|
170
|
-
export async function startService({ repo, name, run, now = () => Date.now(), append = appendEvent } = {}) {
|
|
170
|
+
export async function startService({ repo, name, run, actor = 'supervisor', now = () => Date.now(), append = appendEvent } = {}) {
|
|
171
171
|
if (typeof run !== 'function') throw new TypeError('startService: run is required');
|
|
172
172
|
const declaration = findService(repo, name);
|
|
173
173
|
const command = serviceStartCommand(declaration);
|
|
@@ -188,7 +188,7 @@ export async function startService({ repo, name, run, now = () => Date.now(), ap
|
|
|
188
188
|
startedAt: new Date(now()).toISOString(),
|
|
189
189
|
};
|
|
190
190
|
fs.writeFileSync(recordPath(repo, name), JSON.stringify(record) + '\n');
|
|
191
|
-
append(repo, { ts: record.startedAt, actor
|
|
191
|
+
append(repo, { ts: record.startedAt, actor, kind: 'service_started', service: name, port: declaration.port, pid: record.pid });
|
|
192
192
|
return record;
|
|
193
193
|
}
|
|
194
194
|
|
|
@@ -208,9 +208,9 @@ export async function serviceStatus(repo, { probe = probePort } = {}) {
|
|
|
208
208
|
function serviceTag(name) { return 'service:' + name; }
|
|
209
209
|
|
|
210
210
|
/** Find the latest service card for one declaration. */
|
|
211
|
-
async function serviceTask(commands, repo, name) {
|
|
211
|
+
async function serviceTask(commands, repo, name, options = {}) {
|
|
212
212
|
if (typeof commands?.list !== 'function') return null;
|
|
213
|
-
const tasks = await commands.list(repo, {});
|
|
213
|
+
const tasks = await commands.list(repo, {}, { agent: options.agent ?? 'supervisor' });
|
|
214
214
|
if (!Array.isArray(tasks)) return null;
|
|
215
215
|
const matches = tasks.filter((task) => Array.isArray(task?.tags) && task.tags.includes(serviceTag(name)));
|
|
216
216
|
return matches.length === 0 ? null : matches[matches.length - 1];
|
|
@@ -221,7 +221,7 @@ async function serviceTask(commands, repo, name) {
|
|
|
221
221
|
* and append service_down once per outage. Healthy services with a previous
|
|
222
222
|
* outage append service_started once.
|
|
223
223
|
*/
|
|
224
|
-
export async function auditServices({ repo, commands, probe = probePort, append = appendEvent, state = new Set(), now = () => Date.now(), log = () => {} } = {}) {
|
|
224
|
+
export async function auditServices({ repo, commands, probe = probePort, append = appendEvent, state = new Set(), agent = 'supervisor', actor = 'supervisor', now = () => Date.now(), log = () => {} } = {}) {
|
|
225
225
|
const declarations = loadServiceDeclarations(repo);
|
|
226
226
|
if (declarations.length === 0) return { checked: 0, down: [], started: [] };
|
|
227
227
|
const down = [];
|
|
@@ -233,7 +233,7 @@ export async function auditServices({ repo, commands, probe = probePort, append
|
|
|
233
233
|
if (state.has(key)) {
|
|
234
234
|
state.delete(key);
|
|
235
235
|
started.push(key);
|
|
236
|
-
append(repo, { ts: new Date(now()).toISOString(), actor
|
|
236
|
+
append(repo, { ts: new Date(now()).toISOString(), actor, kind: 'service_started', service: key, port: declaration.port });
|
|
237
237
|
}
|
|
238
238
|
continue;
|
|
239
239
|
}
|
|
@@ -242,9 +242,9 @@ export async function auditServices({ repo, commands, probe = probePort, append
|
|
|
242
242
|
// The outage was already reported; still reopen a failed service card so a
|
|
243
243
|
// later patrol retries the restart instead of staying silent forever.
|
|
244
244
|
try {
|
|
245
|
-
const existing = await serviceTask(commands, repo, key);
|
|
245
|
+
const existing = await serviceTask(commands, repo, key, { agent });
|
|
246
246
|
if (existing !== null && existing.state === 'failed') {
|
|
247
|
-
await commands.reopen(repo, existing.id, { reason: 'service still down: port ' + String(declaration.port) + ' did not answer' });
|
|
247
|
+
await commands.reopen(repo, existing.id, { agent, reason: 'service still down: port ' + String(declaration.port) + ' did not answer' });
|
|
248
248
|
}
|
|
249
249
|
} catch (error) {
|
|
250
250
|
log('warn', 'service retry failed for ' + key, error);
|
|
@@ -252,11 +252,11 @@ export async function auditServices({ repo, commands, probe = probePort, append
|
|
|
252
252
|
continue;
|
|
253
253
|
}
|
|
254
254
|
state.add(key);
|
|
255
|
-
append(repo, { ts: new Date(now()).toISOString(), actor
|
|
255
|
+
append(repo, { ts: new Date(now()).toISOString(), actor, kind: 'service_down', service: key, port: declaration.port });
|
|
256
256
|
try {
|
|
257
|
-
const existing = await serviceTask(commands, repo, key);
|
|
257
|
+
const existing = await serviceTask(commands, repo, key, { agent });
|
|
258
258
|
if (existing !== null && existing.state === 'failed') {
|
|
259
|
-
await commands.reopen(repo, existing.id, { reason: 'service down: port ' + String(declaration.port) + ' did not answer' });
|
|
259
|
+
await commands.reopen(repo, existing.id, { agent, reason: 'service down: port ' + String(declaration.port) + ' did not answer' });
|
|
260
260
|
} else if (existing === null || existing.state === 'done') {
|
|
261
261
|
await commands.add(repo, {
|
|
262
262
|
title: 'Restart service ' + key,
|
|
@@ -264,7 +264,7 @@ export async function auditServices({ repo, commands, probe = probePort, append
|
|
|
264
264
|
tags: ['service', serviceTag(key)],
|
|
265
265
|
acceptance: serviceAcceptance(declaration),
|
|
266
266
|
goal: 'Restart ' + key + ' from .hive/services.yaml; health check ' + declaration.health,
|
|
267
|
-
});
|
|
267
|
+
}, { agent });
|
|
268
268
|
}
|
|
269
269
|
} catch (error) {
|
|
270
270
|
log('warn', 'service redispatch failed for ' + key, error);
|
package/lib/supervisor.js
CHANGED
|
@@ -233,6 +233,15 @@ export class HiveSupervisor {
|
|
|
233
233
|
entry.backlog = emptyBacklog();
|
|
234
234
|
}
|
|
235
235
|
|
|
236
|
+
/** Remember roles present in board/ready snapshots for status discovery. */
|
|
237
|
+
#rememberTaskRoles(entry, tasks) {
|
|
238
|
+
if (!(entry.taskRoles instanceof Set)) entry.taskRoles = new Set();
|
|
239
|
+
for (const task of Array.isArray(tasks) ? tasks : []) {
|
|
240
|
+
const role = typeof task?.role === 'string' ? task.role.trim() : '';
|
|
241
|
+
if (role !== '') entry.taskRoles.add(role);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
236
245
|
/**
|
|
237
246
|
* Register a runtime repository (idempotent, absolute, initialized only).
|
|
238
247
|
* The panel queen activation calls this when a Session opens an initialized
|
|
@@ -284,6 +293,9 @@ export class HiveSupervisor {
|
|
|
284
293
|
queue: [],
|
|
285
294
|
backlog: emptyBacklog(),
|
|
286
295
|
roles: this.#seedRoles(key),
|
|
296
|
+
// Roles actually present on the board, even if roles.yaml/config omit them.
|
|
297
|
+
taskRoles: new Set(),
|
|
298
|
+
wakeRequested: false,
|
|
287
299
|
limitsError: this.limits.errorFor(key),
|
|
288
300
|
environmentError: null,
|
|
289
301
|
mode: null,
|
|
@@ -461,6 +473,20 @@ export class HiveSupervisor {
|
|
|
461
473
|
.sort((a, b) => a.repo.localeCompare(b.repo));
|
|
462
474
|
}
|
|
463
475
|
|
|
476
|
+
/**
|
|
477
|
+
* Worker descriptor for a Session id, across repositories (status/agent attribution).
|
|
478
|
+
* @param {string} sessionId
|
|
479
|
+
* @returns {{ repo: string, cardId?: string, role?: string, sessionId?: string } | null}
|
|
480
|
+
*/
|
|
481
|
+
workerForSession(sessionId) {
|
|
482
|
+
if (typeof sessionId !== 'string' || sessionId === '') return null;
|
|
483
|
+
for (const entry of this.repos.values()) {
|
|
484
|
+
const workers = this.#workers(entry.repo);
|
|
485
|
+
const found = workers.find((worker) => worker?.sessionId === sessionId);
|
|
486
|
+
if (found !== undefined) return { repo: entry.repo, ...found };
|
|
487
|
+
}
|
|
488
|
+
return null;
|
|
489
|
+
}
|
|
464
490
|
/** Whether this Session is registered for any repository. */
|
|
465
491
|
isQueenSession(sessionId) {
|
|
466
492
|
if (typeof sessionId !== 'string' || sessionId === '') return false;
|
|
@@ -543,6 +569,7 @@ export class HiveSupervisor {
|
|
|
543
569
|
}
|
|
544
570
|
try {
|
|
545
571
|
const tasks = await this.listAll(repo, { signal });
|
|
572
|
+
this.#rememberTaskRoles(entry, tasks);
|
|
546
573
|
const gate = gatePhase(tasks);
|
|
547
574
|
entry.gate = gate;
|
|
548
575
|
this.#emitGateChange(repo, previous, gate);
|
|
@@ -638,6 +665,26 @@ export class HiveSupervisor {
|
|
|
638
665
|
return outcomes;
|
|
639
666
|
}
|
|
640
667
|
|
|
668
|
+
/**
|
|
669
|
+
* A tool just changed the board: make this repository due immediately and
|
|
670
|
+
* start a tick when it is not already draining.
|
|
671
|
+
* @param {string} repo
|
|
672
|
+
* @returns {boolean} whether the repository is supervised
|
|
673
|
+
*/
|
|
674
|
+
wake(repo) {
|
|
675
|
+
let key;
|
|
676
|
+
try {
|
|
677
|
+
key = normalizeRepoKey(repo);
|
|
678
|
+
} catch {
|
|
679
|
+
return false;
|
|
680
|
+
}
|
|
681
|
+
const entry = this.repos.get(key);
|
|
682
|
+
if (entry === undefined) return false;
|
|
683
|
+
entry.nextAttemptAt = this.now();
|
|
684
|
+
entry.wakeRequested = true;
|
|
685
|
+
if (!entry.inFlight) void this.tick().catch((error) => this.#log('warn', 'tick after wake failed', messageOf(error)));
|
|
686
|
+
return true;
|
|
687
|
+
}
|
|
641
688
|
/** Serializable supervisor + per-repository status. */
|
|
642
689
|
status() {
|
|
643
690
|
const queens = this.queens();
|
|
@@ -794,6 +841,7 @@ export class HiveSupervisor {
|
|
|
794
841
|
}
|
|
795
842
|
|
|
796
843
|
const cards = await this.listReady(entry.repo, { signal });
|
|
844
|
+
this.#rememberTaskRoles(entry, cards);
|
|
797
845
|
entry.lastCheckAt = this.now();
|
|
798
846
|
if (entry.paused) return { repo: entry.repo, state: entry.state };
|
|
799
847
|
// Gate ordering: base work first, then gate:group, then gate:overall.
|
|
@@ -809,6 +857,7 @@ export class HiveSupervisor {
|
|
|
809
857
|
continue;
|
|
810
858
|
}
|
|
811
859
|
entry.queue.push({ role: card.role, card, claimed: false });
|
|
860
|
+
if (typeof card.role === 'string' && card.role !== '') entry.taskRoles.add(card.role);
|
|
812
861
|
queuedIds.add(card.id);
|
|
813
862
|
}
|
|
814
863
|
entry.frozenSkipped = frozenSkipped;
|
|
@@ -819,7 +868,8 @@ export class HiveSupervisor {
|
|
|
819
868
|
entry.state = STATES.BACKOFF;
|
|
820
869
|
entry.lastError = null;
|
|
821
870
|
this.#resetLiveCounts(entry);
|
|
822
|
-
entry.nextAttemptAt = this.now() + this.idleBackoffMs;
|
|
871
|
+
entry.nextAttemptAt = entry.wakeRequested ? this.now() : this.now() + this.idleBackoffMs;
|
|
872
|
+
entry.wakeRequested = false;
|
|
823
873
|
return { repo: entry.repo, state: entry.state, cards: 0 };
|
|
824
874
|
}
|
|
825
875
|
|
|
@@ -862,7 +912,8 @@ export class HiveSupervisor {
|
|
|
862
912
|
entry.environmentError = null;
|
|
863
913
|
if (!entry.paused) {
|
|
864
914
|
entry.state = STATES.IDLE;
|
|
865
|
-
entry.nextAttemptAt = this.now() + this.intervalMs;
|
|
915
|
+
entry.nextAttemptAt = entry.wakeRequested ? this.now() : this.now() + this.intervalMs;
|
|
916
|
+
entry.wakeRequested = false;
|
|
866
917
|
}
|
|
867
918
|
return { repo: entry.repo, state: entry.state, cards: outcome.results.length, results: outcome.results };
|
|
868
919
|
} catch (error) {
|
|
@@ -927,6 +978,21 @@ export class HiveSupervisor {
|
|
|
927
978
|
return entry;
|
|
928
979
|
}
|
|
929
980
|
|
|
981
|
+
/** Status roles including board-only roles and each effective limit's source. */
|
|
982
|
+
#roleSnapshot(entry) {
|
|
983
|
+
const roles = copyRoles(entry.roles);
|
|
984
|
+
for (const role of entry.taskRoles instanceof Set ? entry.taskRoles : []) {
|
|
985
|
+
if (roles[role] === undefined) {
|
|
986
|
+
roles[role] = { limit: this.limits.limitFor(entry.repo, role), live: 0, queued: 0 };
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
for (const role of Object.keys(roles)) {
|
|
990
|
+
roles[role].source = typeof this.limits?.sourceFor === 'function'
|
|
991
|
+
? this.limits.sourceFor(entry.repo, role)
|
|
992
|
+
: 'default';
|
|
993
|
+
}
|
|
994
|
+
return roles;
|
|
995
|
+
}
|
|
930
996
|
#snapshot(entry) {
|
|
931
997
|
const repoQueen = this.queenFor(entry.repo);
|
|
932
998
|
return {
|
|
@@ -950,7 +1016,10 @@ export class HiveSupervisor {
|
|
|
950
1016
|
orphanRecovered: Number.isInteger(entry.orphanRecovered) ? entry.orphanRecovered : 0,
|
|
951
1017
|
orphanRecoveryAt: iso(entry.orphanRecoveryAt),
|
|
952
1018
|
backlog: { ...entry.backlog },
|
|
953
|
-
roles:
|
|
1019
|
+
roles: this.#roleSnapshot(entry),
|
|
1020
|
+
// Roles actually present on the task board (also discoverable when config
|
|
1021
|
+
// and roles.yaml do not mention them).
|
|
1022
|
+
taskRoles: [...(entry.taskRoles instanceof Set ? entry.taskRoles : [])].sort(),
|
|
954
1023
|
// Live workers currently running in this repository: sessionId/start time
|
|
955
1024
|
// let the panel jump to the conversation or diagnose a stuck card.
|
|
956
1025
|
workers: this.#workers(entry.repo),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-hive-runner",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.21",
|
|
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",
|