dsh-hive-runner 0.6.4 → 0.7.0

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/lib/commands.js CHANGED
@@ -32,10 +32,13 @@ export const SHA_RE = /^[0-9a-f]{7,64}$/;
32
32
  export const BIN_PACKAGES = Object.freeze({
33
33
  tasks: Object.freeze(['hive-tasks']),
34
34
  hive: Object.freeze(['hive-consensus']),
35
+ // `hive roles ...` belongs to the umbrella router (@d86e/hive); the
36
+ // consensus package only owns board/mode/lesson/recall.
37
+ roles: Object.freeze(['@d86e/hive']),
35
38
  });
36
39
 
37
40
  /** The executable name inside each published package. */
38
- const BIN_EXECUTABLES = Object.freeze({ tasks: 'hive-tasks', hive: 'hive' });
41
+ const BIN_EXECUTABLES = Object.freeze({ tasks: 'hive-tasks', hive: 'hive', roles: 'hive' });
39
42
 
40
43
  /** Which Hive bin a verb uses; null verbs (git, the card's own acceptance) cap no fallback. */
41
44
  const VERB_BINS = Object.freeze({
@@ -44,16 +47,42 @@ const VERB_BINS = Object.freeze({
44
47
  show: 'tasks',
45
48
  done: 'tasks',
46
49
  fail: 'tasks',
50
+ list: 'tasks',
51
+ add: 'tasks',
52
+ reopen: 'tasks',
53
+ retry: 'tasks',
54
+ remove: 'tasks',
47
55
  board: 'hive',
48
56
  guard: 'hive',
49
57
  release: 'hive',
50
58
  renew: 'hive',
51
59
  mode: 'hive',
52
60
  recall: 'hive',
61
+ lessonAdd: 'hive',
62
+ rolesList: 'roles',
63
+ rolesAdd: 'roles',
64
+ rolesRemove: 'roles',
53
65
  head: null,
54
66
  acceptance: null,
55
67
  });
56
68
 
69
+ /** Card states accepted by `hive-tasks list --state`. */
70
+ export const TASK_STATES = Object.freeze(['pending', 'claimed', 'done', 'failed']);
71
+ /** Role names accepted by `hive roles add` / `--role`. */
72
+ export const CARD_ROLE_RE = /^[a-z][a-z0-9-]{1,31}$/;
73
+ /** Adapters accepted by `hive roles add --adapter`. */
74
+ export const ROLE_ADAPTERS = Object.freeze(['dsh', 'claude', 'codex']);
75
+ /** Model ids accepted by `hive roles add --model`. */
76
+ export const MODEL_RE = /^[A-Za-z0-9._:-]{1,64}$/;
77
+ /** Lesson statuses accepted by `hive lesson add --status`. */
78
+ export const LESSON_STATUSES = Object.freeze(['hypothesis', 'confirmed', 'superseded']);
79
+ /** Maximum length of a free-text argument (title, goal, acceptance, lesson text). */
80
+ export const TEXT_MAX = 4000;
81
+ /** Maximum length of one scope / evidence token. */
82
+ export const TOKEN_MAX = 512;
83
+ /** Upper bound on repeated flags (scope/after/tag). */
84
+ const LIST_MAX = 64;
85
+
57
86
  /** POSIX single-quote one argv token. */
58
87
  export function quote(value) {
59
88
  return "'" + String(value).replaceAll("'", "'\\''") + "'";
@@ -72,6 +101,53 @@ function needMatch(re, value, name) {
72
101
  return value;
73
102
  }
74
103
 
104
+ /** One required free-text argument, trimmed and bounded; never empty, never NUL-containing. */
105
+ function textArg(value, name, max = TEXT_MAX) {
106
+ if (typeof value !== 'string') {
107
+ throw new HiveCommandError('hive/invalid-argument', name + ' must be a string');
108
+ }
109
+ if (value.includes('\u0000')) {
110
+ throw new HiveCommandError('hive/invalid-argument', name + ' must not contain NUL bytes');
111
+ }
112
+ const text = value.trim();
113
+ if (text === '') throw new HiveCommandError('hive/invalid-argument', name + ' must not be empty');
114
+ if (text.length > max) {
115
+ throw new HiveCommandError('hive/invalid-argument', name + ' must be at most ' + max + ' characters');
116
+ }
117
+ return text;
118
+ }
119
+
120
+ /** One optional free-text argument; undefined/null/empty -> null. */
121
+ function optionalText(value, name, max = TEXT_MAX) {
122
+ if (value === undefined || value === null || value === '') return null;
123
+ return textArg(value, name, max);
124
+ }
125
+
126
+ /** Repeated string flags (--scope/--after/--tag): trimmed, bounded, deduplicated. */
127
+ function listArg(value, name, { max = TOKEN_MAX, items = LIST_MAX } = {}) {
128
+ if (value === undefined || value === null) return [];
129
+ if (!Array.isArray(value)) {
130
+ throw new HiveCommandError('hive/invalid-argument', name + ' must be an array of strings');
131
+ }
132
+ if (value.length > items) {
133
+ throw new HiveCommandError('hive/invalid-argument', name + ' must have at most ' + items + ' entries');
134
+ }
135
+ const out = [];
136
+ for (const entry of value) {
137
+ const token = textArg(entry, name + ' entry', max);
138
+ if (!out.includes(token)) out.push(token);
139
+ }
140
+ return out;
141
+ }
142
+
143
+ /** One integer argument inside an inclusive range. */
144
+ function intArg(value, name, min, max) {
145
+ if (!Number.isInteger(value) || value < min || value > max) {
146
+ throw new HiveCommandError('hive/invalid-argument', name + ' must be an integer in ' + min + '..' + max);
147
+ }
148
+ return value;
149
+ }
150
+
75
151
  /** Non-empty, shell-quoted path / scope-key list for hive-consensus verbs. */
76
152
  function scopeArgs(paths, name) {
77
153
  if (!Array.isArray(paths) || paths.length === 0) {
@@ -94,6 +170,9 @@ function scopeArgs(paths, name) {
94
170
  export function buildCommand(verb, args = {}, bins = {}) {
95
171
  const tasks = bins.tasks ?? 'hive-tasks';
96
172
  const hive = bins.hive ?? 'hive';
173
+ // The umbrella router owns `hive roles`; fall back to the board bin so an
174
+ // operator who configured only one `hive` path still gets the right binary.
175
+ const roles = bins.roles ?? hive;
97
176
  const git = bins.git ?? 'git';
98
177
  switch (verb) {
99
178
  case 'ready': {
@@ -129,6 +208,60 @@ export function buildCommand(verb, args = {}, bins = {}) {
129
208
  const reason = args.reason === undefined || args.reason === null ? 'runner failure' : String(args.reason);
130
209
  return tasks + ' fail ' + quote(id) + ' --reason ' + quote(reason.slice(0, 1000));
131
210
  }
211
+ case 'list': {
212
+ const state = args.state === undefined || args.state === null
213
+ ? null
214
+ : needMatch(new RegExp('^(?:' + TASK_STATES.join('|') + ')$'), args.state, 'list.state');
215
+ const role = args.role === undefined || args.role === null ? null : needMatch(CARD_ROLE_RE, args.role, 'list.role');
216
+ return tasks + ' list --json'
217
+ + (state === null ? '' : ' --state ' + quote(state))
218
+ + (role === null ? '' : ' --role ' + quote(role));
219
+ }
220
+ case 'add': {
221
+ const title = textArg(args.title, 'add.title', 300);
222
+ const parts = [tasks, 'add', '--json', '--title', quote(title)];
223
+ const role = args.role === undefined || args.role === null || args.role === ''
224
+ ? null
225
+ : needMatch(CARD_ROLE_RE, args.role, 'add.role');
226
+ if (role !== null) parts.push('--role', quote(role));
227
+ for (const path of listArg(args.scope, 'add.scope')) parts.push('--scope', quote(path));
228
+ for (const dep of listArg(args.after, 'add.after', { max: 128 })) {
229
+ parts.push('--after', quote(needMatch(ID_RE, dep, 'add.after entry')));
230
+ }
231
+ if (args.priority !== undefined && args.priority !== null) {
232
+ parts.push('--priority', String(intArg(args.priority, 'add.priority', -1000, 1000)));
233
+ }
234
+ const goal = optionalText(args.goal, 'add.goal');
235
+ if (goal !== null) parts.push('--goal', quote(goal));
236
+ const acceptance = optionalText(args.acceptance, 'add.acceptance');
237
+ if (acceptance !== null) parts.push('--acceptance', quote(acceptance));
238
+ for (const tag of listArg(args.tags, 'add.tags', { max: 64 })) parts.push('--tag', quote(tag));
239
+ const reviewOf = args.reviewOf === undefined || args.reviewOf === null || args.reviewOf === ''
240
+ ? null
241
+ : needMatch(ID_RE, args.reviewOf, 'add.reviewOf');
242
+ if (reviewOf !== null) parts.push('--review-of', quote(reviewOf));
243
+ // A draft card is a note, not dispatchable work: hive-tasks excludes it
244
+ // from ready/next and it carries no acceptance requirement yet.
245
+ if (args.draft === true) parts.push('--draft');
246
+ return parts.join(' ');
247
+ }
248
+ case 'reopen': {
249
+ const id = needMatch(ID_RE, args.id, 'reopen.id');
250
+ const reason = args.reason === undefined || args.reason === null || args.reason === ''
251
+ ? null
252
+ : textArg(args.reason, 'reopen.reason', 1000);
253
+ return tasks + ' reopen ' + quote(id) + ' --json' + (reason === null ? '' : ' --reason ' + quote(reason));
254
+ }
255
+ case 'retry': {
256
+ const id = needMatch(ID_RE, args.id, 'retry.id');
257
+ return tasks + ' retry ' + quote(id) + ' --json';
258
+ }
259
+ case 'remove': {
260
+ const id = needMatch(ID_RE, args.id, 'remove.id');
261
+ // No --force: a claimed card must be released by its owner (or expire)
262
+ // before the queen may delete it; the CLI refuses instead of destroying work.
263
+ return tasks + ' rm ' + quote(id);
264
+ }
132
265
  case 'board':
133
266
  return hive + ' board --json';
134
267
  case 'guard': {
@@ -136,7 +269,7 @@ export function buildCommand(verb, args = {}, bins = {}) {
136
269
  const agent = ' --agent ' + quote(needMatch(AGENT_RE, args.agent, 'guard.agent'));
137
270
  const task = args.id === undefined || args.id === null ? '' : ' --task ' + quote(needMatch(ID_RE, args.id, 'guard.id'));
138
271
  const ttl = args.ttl === undefined || args.ttl === null ? '' : ' --ttl ' + quote(needMatch(TTL_RE, args.ttl, 'guard.ttl'));
139
- return hive + ' guard ' + keys + agent + task + ttl;
272
+ return hive + ' guard ' + keys + agent + task + ttl + ' --json';
140
273
  }
141
274
  case 'release':
142
275
  return hive + ' release ' + scopeArgs(args.paths, 'release.paths')
@@ -153,6 +286,50 @@ export function buildCommand(verb, args = {}, bins = {}) {
153
286
  }
154
287
  return hive + ' recall ' + quote(args.query.trim()) + ' --json';
155
288
  }
289
+ case 'lessonAdd': {
290
+ const text = textArg(args.text, 'lessonAdd.text');
291
+ const scope = args.scope === undefined || args.scope === null || args.scope === ''
292
+ ? null
293
+ : textArg(args.scope, 'lessonAdd.scope', TOKEN_MAX);
294
+ const evidence = args.evidence === undefined || args.evidence === null || args.evidence === ''
295
+ ? null
296
+ : textArg(args.evidence, 'lessonAdd.evidence', TOKEN_MAX);
297
+ const status = args.status === undefined || args.status === null || args.status === ''
298
+ ? null
299
+ : needMatch(new RegExp('^(?:' + LESSON_STATUSES.join('|') + ')$'), args.status, 'lessonAdd.status');
300
+ const parts = [hive, 'lesson', 'add'];
301
+ if (scope !== null) parts.push('--scope', quote(scope));
302
+ if (evidence !== null) parts.push('--evidence', quote(evidence));
303
+ if (status !== null) parts.push('--status', quote(status));
304
+ parts.push(quote(text));
305
+ return parts.join(' ');
306
+ }
307
+ case 'rolesList':
308
+ return roles + ' roles list --json';
309
+ case 'rolesAdd': {
310
+ const name = needMatch(CARD_ROLE_RE, args.name, 'rolesAdd.name');
311
+ const parts = [roles, 'roles', 'add', quote(name)];
312
+ const adapter = args.adapter === undefined || args.adapter === null || args.adapter === ''
313
+ ? null
314
+ : needMatch(new RegExp('^(?:' + ROLE_ADAPTERS.join('|') + ')$'), args.adapter, 'rolesAdd.adapter');
315
+ if (adapter !== null) parts.push('--adapter', quote(adapter));
316
+ const model = args.model === undefined || args.model === null || args.model === ''
317
+ ? null
318
+ : needMatch(MODEL_RE, args.model, 'rolesAdd.model');
319
+ if (model !== null) parts.push('--model', quote(model));
320
+ const prompt = args.prompt === undefined || args.prompt === null || args.prompt === ''
321
+ ? null
322
+ : textArg(args.prompt, 'rolesAdd.prompt', TOKEN_MAX);
323
+ if (prompt !== null) parts.push('--prompt', quote(prompt));
324
+ const description = optionalText(args.description, 'rolesAdd.description', 2000);
325
+ if (description !== null) parts.push('--description', quote(description));
326
+ if (args.force === true) parts.push('--force');
327
+ return parts.join(' ');
328
+ }
329
+ case 'rolesRemove': {
330
+ const name = needMatch(CARD_ROLE_RE, args.name, 'rolesRemove.name');
331
+ return roles + ' roles rm ' + quote(name);
332
+ }
156
333
  case 'head':
157
334
  return git + ' rev-parse HEAD';
158
335
  case 'acceptance': {
@@ -200,7 +377,7 @@ export function missingBinaryHint(verb, bins = {}) {
200
377
  if (key === undefined || key === null) return null;
201
378
  const configured = typeof bins[key] === 'string' && bins[key] !== '' ? bins[key] : BIN_EXECUTABLES[key];
202
379
  const packages = BIN_PACKAGES[key];
203
- const configKey = key === 'tasks' ? 'tasksBin' : 'hiveBin';
380
+ const configKey = key === 'tasks' ? 'tasksBin' : key === 'roles' ? 'rolesBin' : 'hiveBin';
204
381
  return '[hive-runner] ' + configured + ' was not found on the shell PATH and the npx fallback did not run it; '
205
382
  + 'install it with "npm i -g ' + packages.join(' ') + '" or set ' + configKey + '.';
206
383
  }
@@ -236,19 +413,29 @@ function failure(result, label) {
236
413
  */
237
414
  export function createCommands({ ctx, config }) {
238
415
  const run = createShellRunner({ ctx, config });
239
- const bins = { tasks: config.tasksBin, hive: config.hiveBin, git: config.gitBin };
416
+ const bins = {
417
+ tasks: config.tasksBin,
418
+ hive: config.hiveBin,
419
+ roles: config.rolesBin ?? config.hiveBin,
420
+ git: config.gitBin,
421
+ };
240
422
 
241
423
  /** Execute one allowlisted verb. @returns {Promise<object>} the raw shell result */
242
424
  async function execute(verb, args, options = {}) {
243
425
  const command = buildCommand(verb, args, bins);
426
+ // Every Hive/git command carries the claim identity explicitly. Per-card
427
+ // Hive calls also carry a per-card `HIVE_INSTANCE` (the card id), so
428
+ // concurrent workers of one runner are distinct announcers on the consensus
429
+ // board instead of looking like the same instance.
430
+ const env = { HIVE_AGENT: options.agent ?? config.agent };
431
+ const instance = typeof options.instance === 'string' ? options.instance.trim() : '';
432
+ if (instance !== '') env.HIVE_INSTANCE = instance;
244
433
  const shellOptions = {
245
434
  workdir: options.repo,
246
435
  signal: options.signal,
247
436
  session: options.session,
248
437
  timeoutMs: options.timeoutMs ?? config.cliTimeoutMs,
249
- // Every Hive/git command carries the claim identity explicitly; the
250
- // pre-commit hook must never fall back to "HIVE_AGENT is not set".
251
- env: { HIVE_AGENT: options.agent ?? config.agent, ...(options.env ?? {}) },
438
+ env: { ...env, ...(options.env ?? {}) },
252
439
  };
253
440
  let result = await run(command, shellOptions);
254
441
  if (!missingBinary(result)) return result;
@@ -319,9 +506,11 @@ export function createCommands({ ctx, config }) {
319
506
  return value ?? [];
320
507
  },
321
508
  /**
322
- * `hive guard <scope...> --task <id> --ttl <ttl>`: auto-sign the card's
323
- * leases and publish the board as working. Returns the raw result so the
324
- * caller can map exit 2 to a claim-conflict card failure.
509
+ * `hive guard <scope...> --task <id> --ttl <ttl> --json`: announce the
510
+ * card's scope and publish the board as working. hive-consensus 1.5.0 never
511
+ * blocks on an announcement, so the raw result is returned as-is; the
512
+ * `--json` document carries the advisory `overlaps` array the runner
513
+ * records, and a non-zero exit is only an unexpected CLI problem.
325
514
  */
326
515
  async guard(repo, paths, options = {}) {
327
516
  return execute('guard', {
@@ -331,11 +520,11 @@ export function createCommands({ ctx, config }) {
331
520
  ttl: options.ttl ?? config.ttl,
332
521
  }, { ...options, repo });
333
522
  },
334
- /** `hive release <scope...> --agent A`: drop our leases (best effort). */
523
+ /** `hive release <scope...> --agent A`: clear our announcements (best effort). */
335
524
  async release(repo, paths, options = {}) {
336
525
  return execute('release', { paths, agent: options.agent ?? config.agent }, { ...options, repo });
337
526
  },
338
- /** `hive renew <scope...> --agent A --ttl T`: extend leases we already hold. */
527
+ /** `hive renew <scope...> --agent A --ttl T`: refresh announcements we already published. */
339
528
  async renew(repo, paths, options = {}) {
340
529
  return execute('renew', {
341
530
  paths,
@@ -359,6 +548,87 @@ export function createCommands({ ctx, config }) {
359
548
  const value = parseJson(result.stdout, 'hive recall');
360
549
  return Array.isArray(value) ? value : [];
361
550
  },
551
+ /** `hive-tasks list --json [--state S] [--role R]` -> parsed card array. */
552
+ async list(repo, options = {}) {
553
+ const result = await execute('list', { state: options.state, role: options.role }, { ...options, repo });
554
+ if (result.exitCode !== 0) throw failure(result, 'hive-tasks list');
555
+ const value = parseJson(result.stdout, 'hive-tasks list');
556
+ return Array.isArray(value) ? value : [];
557
+ },
558
+ /** `hive-tasks add ...` -> the created card (parsed from --json output). */
559
+ async add(repo, card, options = {}) {
560
+ const args = {
561
+ title: card.title,
562
+ role: card.role,
563
+ scope: card.scope,
564
+ after: card.after,
565
+ priority: card.priority,
566
+ goal: card.goal,
567
+ acceptance: card.acceptance,
568
+ tags: card.tags,
569
+ reviewOf: card.reviewOf,
570
+ draft: card.draft,
571
+ };
572
+ const result = await execute('add', args, { ...options, repo });
573
+ if (result.exitCode !== 0) throw failure(result, 'hive-tasks add');
574
+ const value = parseJson(result.stdout, 'hive-tasks add');
575
+ return value !== null && typeof value === 'object' ? value : null;
576
+ },
577
+ /** `hive-tasks reopen <id> [--reason R]` -> the reopened card. */
578
+ async reopen(repo, id, options = {}) {
579
+ const result = await execute('reopen', { id, reason: options.reason }, { ...options, repo });
580
+ if (result.exitCode !== 0) throw failure(result, 'hive-tasks reopen ' + id);
581
+ return parseJson(result.stdout, 'hive-tasks reopen');
582
+ },
583
+ /** `hive-tasks retry <id>` -> the retried card. */
584
+ async retry(repo, id, options = {}) {
585
+ const result = await execute('retry', { id }, { ...options, repo });
586
+ if (result.exitCode !== 0) throw failure(result, 'hive-tasks retry ' + id);
587
+ return parseJson(result.stdout, 'hive-tasks retry');
588
+ },
589
+ /** `hive-tasks rm <id>`: delete a card; the CLI refuses a claimed card. */
590
+ async remove(repo, id, options = {}) {
591
+ const result = await execute('remove', { id }, { ...options, repo });
592
+ if (result.exitCode !== 0) throw failure(result, 'hive-tasks rm ' + id);
593
+ return result.stdout.trim();
594
+ },
595
+ /** `hive lesson add [--scope G] [--evidence E] [--status S] <text>`. */
596
+ async lessonAdd(repo, lesson, options = {}) {
597
+ const result = await execute('lessonAdd', {
598
+ text: lesson.text,
599
+ scope: lesson.scope,
600
+ evidence: lesson.evidence,
601
+ status: lesson.status,
602
+ }, { ...options, repo });
603
+ if (result.exitCode !== 0) throw failure(result, 'hive lesson add');
604
+ return result.stdout.trim();
605
+ },
606
+ /** `hive roles list --json` -> parsed role rows. */
607
+ async rolesList(repo, options = {}) {
608
+ const result = await execute('rolesList', {}, { ...options, repo });
609
+ if (result.exitCode !== 0) throw failure(result, 'hive roles list');
610
+ const value = parseJson(result.stdout, 'hive roles list');
611
+ return Array.isArray(value) ? value : [];
612
+ },
613
+ /** `hive roles add <name> [...]`; returns the CLI output. */
614
+ async rolesAdd(repo, role, options = {}) {
615
+ const result = await execute('rolesAdd', {
616
+ name: role.name,
617
+ adapter: role.adapter,
618
+ model: role.model,
619
+ prompt: role.prompt,
620
+ description: role.description,
621
+ force: role.force,
622
+ }, { ...options, repo });
623
+ if (result.exitCode !== 0) throw failure(result, 'hive roles add');
624
+ return result.stdout.trim();
625
+ },
626
+ /** `hive roles rm <name>`; returns the CLI output. */
627
+ async rolesRemove(repo, name, options = {}) {
628
+ const result = await execute('rolesRemove', { name }, { ...options, repo });
629
+ if (result.exitCode !== 0) throw failure(result, 'hive roles rm');
630
+ return result.stdout.trim();
631
+ },
362
632
  };
363
633
  }
364
634
 
package/lib/config.js CHANGED
@@ -18,6 +18,20 @@ export const DEFAULT_MAX_CONCURRENT_REPOS = 2;
18
18
  export const DEFAULT_MAX_CONSECUTIVE_FAILURES = 3;
19
19
  /** Default capacity retry delay when DSH's subagent capacity is exhausted. */
20
20
  export const DEFAULT_CAPACITY_RETRY_MS = 2_000;
21
+ /** Hard per-card wall-clock limit: abort the worker and fail the card at the deadline. */
22
+ export const DEFAULT_CARD_TIMEOUT_MS = 15 * 60_000;
23
+ /** Warn when a running worker produced no new commit/output for this long. */
24
+ export const DEFAULT_HEARTBEAT_WARN_MS = 5 * 60_000;
25
+ /** How often heartbeat/liveness is checked while a worker runs. */
26
+ export const DEFAULT_HEARTBEAT_INTERVAL_MS = 30_000;
27
+ /** Queen patrol period: the supervisor checks for anomalies and only then nudges the queen. */
28
+ export const DEFAULT_PATROL_MS = 5 * 60_000;
29
+ /** How long anomaly events coalesce before one digest is delivered to the queen. */
30
+ export const DEFAULT_ANOMALY_DEBOUNCE_MS = 3_000;
31
+ /** Maximum number of undelivered anomaly entries kept for the queen's pending list. */
32
+ export const DEFAULT_ANOMALY_MAX = 50;
33
+ /** Grace before a done card without an arch_review event is flagged. */
34
+ export const DEFAULT_ARCH_REVIEW_GRACE_MS = 10 * 60_000;
21
35
  /** Default role -> concurrent live-worker cap, per repository. */
22
36
  export const DEFAULT_ROLE_CONCURRENCY = Object.freeze({ coder: 5, tester: 5 });
23
37
  /** Fallback cap for roles not listed in `roleConcurrency` (also finite). */
@@ -37,7 +51,10 @@ const DEFAULTS = Object.freeze({
37
51
  maxConsecutiveFailures: DEFAULT_MAX_CONSECUTIVE_FAILURES,
38
52
  paused: [],
39
53
  agent: 'dsh',
40
- ttl: '5m',
54
+ // Claim TTL: bounds how long a claim survives while a card waits for a worker
55
+ // slot. It never aborts a running card (the hard cardTimeoutMs does that);
56
+ // raise it for very large queues.
57
+ ttl: '20m',
41
58
  // Finite, user-set default: five live workers per role per repository
42
59
  // (repo-level .hive/limits.json overrides this at runtime). Repository
43
60
  // overrides use absolute-path keys with a role-cap object, e.g.
@@ -46,6 +63,19 @@ const DEFAULTS = Object.freeze({
46
63
  // Fallback cap for roles not listed in roleConcurrency (also finite).
47
64
  defaultRoleConcurrency: DEFAULT_DEFAULT_ROLE_CONCURRENCY,
48
65
  capacityRetryMs: DEFAULT_CAPACITY_RETRY_MS,
66
+ cardTimeoutMs: DEFAULT_CARD_TIMEOUT_MS,
67
+ heartbeatWarnMs: DEFAULT_HEARTBEAT_WARN_MS,
68
+ heartbeatIntervalMs: DEFAULT_HEARTBEAT_INTERVAL_MS,
69
+ // Queen coordination: the supervisor patrols every patrolMs and delivers ONE
70
+ // digest to the registered queen Session only when something needs attention.
71
+ // Until a live queen Session exists the entries stay in the pending list.
72
+ patrolMs: DEFAULT_PATROL_MS,
73
+ notifyQueen: true,
74
+ anomalyDebounceMs: DEFAULT_ANOMALY_DEBOUNCE_MS,
75
+ anomalyMax: DEFAULT_ANOMALY_MAX,
76
+ // A done card must carry an arch_review event; flag it after this grace (the
77
+ // queen reviews finished cards at the next patrol).
78
+ archReviewGraceMs: DEFAULT_ARCH_REVIEW_GRACE_MS,
49
79
  provider: 'spawn',
50
80
  parentSession: null,
51
81
  cwd: null,
@@ -202,6 +232,17 @@ function bin(value, name, env, fallback) {
202
232
  return nonEmptyString(value, name);
203
233
  }
204
234
 
235
+ /**
236
+ * Parse a claim TTL string ("30s", "5m", "2h", "1d") to milliseconds.
237
+ * @param {string} ttl
238
+ * @returns {number}
239
+ */
240
+ export function parseTtlMs(ttl) {
241
+ const match = /^(\d{1,4})([smhd])$/.exec(String(ttl ?? ''));
242
+ if (match === null) return 5 * 60_000;
243
+ return Number(match[1]) * ({ s: 1_000, m: 60_000, h: 3_600_000, d: 86_400_000 }[match[2]] ?? 60_000);
244
+ }
245
+
205
246
  /**
206
247
  * Normalize one repository key. Configuration requires absolute paths; HTTP and
207
248
  * tool callers may send any string, resolved against the host working directory.
@@ -241,6 +282,9 @@ export function resolveConfig(config = {}) {
241
282
  fail('defaultRoleConcurrency must be an integer in 0..999 (0 pauses unlisted roles)');
242
283
  }
243
284
  cfg.capacityRetryMs = positiveNumber(cfg.capacityRetryMs, 'capacityRetryMs');
285
+ cfg.cardTimeoutMs = positiveNumber(cfg.cardTimeoutMs, 'cardTimeoutMs');
286
+ cfg.heartbeatWarnMs = positiveNumber(cfg.heartbeatWarnMs, 'heartbeatWarnMs');
287
+ cfg.heartbeatIntervalMs = positiveNumber(cfg.heartbeatIntervalMs, 'heartbeatIntervalMs');
244
288
  cfg.cliTimeoutMs = positiveNumber(cfg.cliTimeoutMs, 'cliTimeoutMs');
245
289
  cfg.headTimeoutMs = positiveNumber(cfg.headTimeoutMs, 'headTimeoutMs');
246
290
  cfg.acceptanceTimeoutMs = positiveNumber(cfg.acceptanceTimeoutMs, 'acceptanceTimeoutMs');
@@ -252,8 +296,14 @@ export function resolveConfig(config = {}) {
252
296
  if (cfg.parentSession !== null && cfg.parentSession !== undefined) cfg.parentSession = nonEmptyString(cfg.parentSession, 'parentSession');
253
297
  else cfg.parentSession = null;
254
298
  cfg.cwd = cfg.cwd === null || cfg.cwd === undefined ? process.cwd() : absolutePath(cfg.cwd, 'cwd');
299
+ cfg.patrolMs = positiveNumber(cfg.patrolMs, 'patrolMs');
300
+ cfg.notifyQueen = boolean(cfg.notifyQueen, 'notifyQueen');
301
+ cfg.anomalyDebounceMs = positiveNumber(cfg.anomalyDebounceMs, 'anomalyDebounceMs');
302
+ cfg.anomalyMax = positiveInteger(cfg.anomalyMax, 'anomalyMax', 1000);
303
+ cfg.archReviewGraceMs = positiveNumber(cfg.archReviewGraceMs, 'archReviewGraceMs');
255
304
  cfg.tasksBin = bin(cfg.tasksBin, 'tasksBin', 'HIVE_TASKS_BIN', 'hive-tasks');
256
305
  cfg.hiveBin = bin(cfg.hiveBin, 'hiveBin', 'HIVE_BIN', 'hive');
306
+ cfg.rolesBin = bin(cfg.rolesBin, 'rolesBin', 'HIVE_ROLES_BIN', cfg.hiveBin);
257
307
  cfg.gitBin = bin(cfg.gitBin, 'gitBin', 'HIVE_GIT_BIN', 'git');
258
308
 
259
309
  // Auto-discovery without explicit roots scans the parent of each configured