dsh-hive-runner 0.6.7 → 0.8.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/CHANGELOG.md +100 -0
- package/README.md +331 -116
- package/README.zh-CN.md +236 -72
- package/SPEC.md +197 -60
- package/cordis.patch.yml +24 -4
- package/docs/DESIGN.md +88 -42
- package/index.js +682 -38
- package/lib/anomalies.js +216 -0
- package/lib/audit.js +134 -0
- package/lib/commands.js +389 -4
- package/lib/config.js +24 -0
- package/lib/events.js +249 -0
- package/lib/gates.js +103 -0
- package/lib/http.js +42 -4
- package/lib/notify.js +145 -0
- package/lib/patrol.js +218 -0
- package/lib/round.js +103 -6
- package/lib/runs.js +19 -0
- package/lib/supervisor.js +96 -1
- package/package.json +1 -1
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,45 @@ const VERB_BINS = Object.freeze({
|
|
|
44
47
|
show: 'tasks',
|
|
45
48
|
done: 'tasks',
|
|
46
49
|
fail: 'tasks',
|
|
50
|
+
list: 'tasks',
|
|
51
|
+
add: 'tasks',
|
|
52
|
+
edit: 'tasks',
|
|
53
|
+
split: 'tasks',
|
|
54
|
+
supersede: 'tasks',
|
|
55
|
+
reopen: 'tasks',
|
|
56
|
+
retry: 'tasks',
|
|
57
|
+
remove: 'tasks',
|
|
47
58
|
board: 'hive',
|
|
48
59
|
guard: 'hive',
|
|
49
60
|
release: 'hive',
|
|
50
61
|
renew: 'hive',
|
|
51
62
|
mode: 'hive',
|
|
52
63
|
recall: 'hive',
|
|
64
|
+
lessonAdd: 'hive',
|
|
65
|
+
rolesList: 'roles',
|
|
66
|
+
rolesAdd: 'roles',
|
|
67
|
+
rolesRemove: 'roles',
|
|
53
68
|
head: null,
|
|
54
69
|
acceptance: null,
|
|
55
70
|
});
|
|
56
71
|
|
|
72
|
+
/** Card states accepted by `hive-tasks list --state`. */
|
|
73
|
+
export const TASK_STATES = Object.freeze(['pending', 'claimed', 'done', 'failed']);
|
|
74
|
+
/** Role names accepted by `hive roles add` / `--role`. */
|
|
75
|
+
export const CARD_ROLE_RE = /^[a-z][a-z0-9-]{1,31}$/;
|
|
76
|
+
/** Adapters accepted by `hive roles add --adapter`. */
|
|
77
|
+
export const ROLE_ADAPTERS = Object.freeze(['dsh', 'claude', 'codex']);
|
|
78
|
+
/** Model ids accepted by `hive roles add --model`. */
|
|
79
|
+
export const MODEL_RE = /^[A-Za-z0-9._:-]{1,64}$/;
|
|
80
|
+
/** Lesson statuses accepted by `hive lesson add --status`. */
|
|
81
|
+
export const LESSON_STATUSES = Object.freeze(['hypothesis', 'confirmed', 'superseded']);
|
|
82
|
+
/** Maximum length of a free-text argument (title, goal, acceptance, lesson text). */
|
|
83
|
+
export const TEXT_MAX = 4000;
|
|
84
|
+
/** Maximum length of one scope / evidence token. */
|
|
85
|
+
export const TOKEN_MAX = 512;
|
|
86
|
+
/** Upper bound on repeated flags (scope/after/tag). */
|
|
87
|
+
const LIST_MAX = 64;
|
|
88
|
+
|
|
57
89
|
/** POSIX single-quote one argv token. */
|
|
58
90
|
export function quote(value) {
|
|
59
91
|
return "'" + String(value).replaceAll("'", "'\\''") + "'";
|
|
@@ -72,6 +104,53 @@ function needMatch(re, value, name) {
|
|
|
72
104
|
return value;
|
|
73
105
|
}
|
|
74
106
|
|
|
107
|
+
/** One required free-text argument, trimmed and bounded; never empty, never NUL-containing. */
|
|
108
|
+
function textArg(value, name, max = TEXT_MAX) {
|
|
109
|
+
if (typeof value !== 'string') {
|
|
110
|
+
throw new HiveCommandError('hive/invalid-argument', name + ' must be a string');
|
|
111
|
+
}
|
|
112
|
+
if (value.includes('\u0000')) {
|
|
113
|
+
throw new HiveCommandError('hive/invalid-argument', name + ' must not contain NUL bytes');
|
|
114
|
+
}
|
|
115
|
+
const text = value.trim();
|
|
116
|
+
if (text === '') throw new HiveCommandError('hive/invalid-argument', name + ' must not be empty');
|
|
117
|
+
if (text.length > max) {
|
|
118
|
+
throw new HiveCommandError('hive/invalid-argument', name + ' must be at most ' + max + ' characters');
|
|
119
|
+
}
|
|
120
|
+
return text;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** One optional free-text argument; undefined/null/empty -> null. */
|
|
124
|
+
function optionalText(value, name, max = TEXT_MAX) {
|
|
125
|
+
if (value === undefined || value === null || value === '') return null;
|
|
126
|
+
return textArg(value, name, max);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Repeated string flags (--scope/--after/--tag): trimmed, bounded, deduplicated. */
|
|
130
|
+
function listArg(value, name, { max = TOKEN_MAX, items = LIST_MAX } = {}) {
|
|
131
|
+
if (value === undefined || value === null) return [];
|
|
132
|
+
if (!Array.isArray(value)) {
|
|
133
|
+
throw new HiveCommandError('hive/invalid-argument', name + ' must be an array of strings');
|
|
134
|
+
}
|
|
135
|
+
if (value.length > items) {
|
|
136
|
+
throw new HiveCommandError('hive/invalid-argument', name + ' must have at most ' + items + ' entries');
|
|
137
|
+
}
|
|
138
|
+
const out = [];
|
|
139
|
+
for (const entry of value) {
|
|
140
|
+
const token = textArg(entry, name + ' entry', max);
|
|
141
|
+
if (!out.includes(token)) out.push(token);
|
|
142
|
+
}
|
|
143
|
+
return out;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** One integer argument inside an inclusive range. */
|
|
147
|
+
function intArg(value, name, min, max) {
|
|
148
|
+
if (!Number.isInteger(value) || value < min || value > max) {
|
|
149
|
+
throw new HiveCommandError('hive/invalid-argument', name + ' must be an integer in ' + min + '..' + max);
|
|
150
|
+
}
|
|
151
|
+
return value;
|
|
152
|
+
}
|
|
153
|
+
|
|
75
154
|
/** Non-empty, shell-quoted path / scope-key list for hive-consensus verbs. */
|
|
76
155
|
function scopeArgs(paths, name) {
|
|
77
156
|
if (!Array.isArray(paths) || paths.length === 0) {
|
|
@@ -94,6 +173,9 @@ function scopeArgs(paths, name) {
|
|
|
94
173
|
export function buildCommand(verb, args = {}, bins = {}) {
|
|
95
174
|
const tasks = bins.tasks ?? 'hive-tasks';
|
|
96
175
|
const hive = bins.hive ?? 'hive';
|
|
176
|
+
// The umbrella router owns `hive roles`; fall back to the board bin so an
|
|
177
|
+
// operator who configured only one `hive` path still gets the right binary.
|
|
178
|
+
const roles = bins.roles ?? hive;
|
|
97
179
|
const git = bins.git ?? 'git';
|
|
98
180
|
switch (verb) {
|
|
99
181
|
case 'ready': {
|
|
@@ -129,6 +211,157 @@ export function buildCommand(verb, args = {}, bins = {}) {
|
|
|
129
211
|
const reason = args.reason === undefined || args.reason === null ? 'runner failure' : String(args.reason);
|
|
130
212
|
return tasks + ' fail ' + quote(id) + ' --reason ' + quote(reason.slice(0, 1000));
|
|
131
213
|
}
|
|
214
|
+
case 'list': {
|
|
215
|
+
const state = args.state === undefined || args.state === null
|
|
216
|
+
? null
|
|
217
|
+
: needMatch(new RegExp('^(?:' + TASK_STATES.join('|') + ')$'), args.state, 'list.state');
|
|
218
|
+
const role = args.role === undefined || args.role === null ? null : needMatch(CARD_ROLE_RE, args.role, 'list.role');
|
|
219
|
+
return tasks + ' list --json'
|
|
220
|
+
+ (state === null ? '' : ' --state ' + quote(state))
|
|
221
|
+
+ (role === null ? '' : ' --role ' + quote(role));
|
|
222
|
+
}
|
|
223
|
+
case 'add': {
|
|
224
|
+
const title = textArg(args.title, 'add.title', 300);
|
|
225
|
+
const parts = [tasks, 'add', '--json', '--title', quote(title)];
|
|
226
|
+
const role = args.role === undefined || args.role === null || args.role === ''
|
|
227
|
+
? null
|
|
228
|
+
: needMatch(CARD_ROLE_RE, args.role, 'add.role');
|
|
229
|
+
if (role !== null) parts.push('--role', quote(role));
|
|
230
|
+
for (const path of listArg(args.scope, 'add.scope')) parts.push('--scope', quote(path));
|
|
231
|
+
for (const dep of listArg(args.after, 'add.after', { max: 128 })) {
|
|
232
|
+
parts.push('--after', quote(needMatch(ID_RE, dep, 'add.after entry')));
|
|
233
|
+
}
|
|
234
|
+
if (args.priority !== undefined && args.priority !== null) {
|
|
235
|
+
parts.push('--priority', String(intArg(args.priority, 'add.priority', -1000, 1000)));
|
|
236
|
+
}
|
|
237
|
+
const goal = optionalText(args.goal, 'add.goal');
|
|
238
|
+
if (goal !== null) parts.push('--goal', quote(goal));
|
|
239
|
+
const acceptance = optionalText(args.acceptance, 'add.acceptance');
|
|
240
|
+
if (acceptance !== null) parts.push('--acceptance', quote(acceptance));
|
|
241
|
+
for (const tag of listArg(args.tags, 'add.tags', { max: 64 })) parts.push('--tag', quote(tag));
|
|
242
|
+
const reviewOf = args.reviewOf === undefined || args.reviewOf === null || args.reviewOf === ''
|
|
243
|
+
? null
|
|
244
|
+
: needMatch(ID_RE, args.reviewOf, 'add.reviewOf');
|
|
245
|
+
if (reviewOf !== null) parts.push('--review-of', quote(reviewOf));
|
|
246
|
+
// A draft card is a note, not dispatchable work: hive-tasks excludes it
|
|
247
|
+
// from ready/next and it carries no acceptance requirement yet.
|
|
248
|
+
if (args.draft === true) parts.push('--draft');
|
|
249
|
+
return parts.join(' ');
|
|
250
|
+
}
|
|
251
|
+
case 'edit': {
|
|
252
|
+
// hive-tasks 1.9 edit flags: --title/--role/--priority/--acceptance,
|
|
253
|
+
// incremental scope (--scope-add/--scope-remove), --after-set (comma list),
|
|
254
|
+
// --tag +name/-name, --superseded/--no-superseded, optional --reason.
|
|
255
|
+
const id = needMatch(ID_RE, args.id, 'edit.id');
|
|
256
|
+
const parts = [tasks, 'edit', quote(id), '--json'];
|
|
257
|
+
let changes = 0;
|
|
258
|
+
const title = optionalText(args.title, 'edit.title', 300);
|
|
259
|
+
if (title !== null) { parts.push('--title', quote(title)); changes += 1; }
|
|
260
|
+
if (args.role !== undefined && args.role !== null && args.role !== '') {
|
|
261
|
+
parts.push('--role', quote(needMatch(CARD_ROLE_RE, args.role, 'edit.role')));
|
|
262
|
+
changes += 1;
|
|
263
|
+
}
|
|
264
|
+
for (const path of listArg(args.scopeAdd, 'edit.scopeAdd')) { parts.push('--scope-add', quote(path)); changes += 1; }
|
|
265
|
+
for (const path of listArg(args.scopeRemove, 'edit.scopeRemove')) { parts.push('--scope-remove', quote(path)); changes += 1; }
|
|
266
|
+
if (args.afterSet !== undefined && args.afterSet !== null) {
|
|
267
|
+
const deps = Array.isArray(args.afterSet) ? args.afterSet : [];
|
|
268
|
+
const ids = deps.map((dep) => needMatch(ID_RE, dep, 'edit.afterSet entry'));
|
|
269
|
+
parts.push('--after-set', quote(ids.join(',')));
|
|
270
|
+
changes += 1;
|
|
271
|
+
}
|
|
272
|
+
if (args.priority !== undefined && args.priority !== null) {
|
|
273
|
+
parts.push('--priority', String(intArg(args.priority, 'edit.priority', -1000, 1000)));
|
|
274
|
+
changes += 1;
|
|
275
|
+
}
|
|
276
|
+
const acceptance = optionalText(args.acceptance, 'edit.acceptance');
|
|
277
|
+
if (acceptance !== null) { parts.push('--acceptance', quote(acceptance)); changes += 1; }
|
|
278
|
+
for (const mutation of listArg(args.tagMutations, 'edit.tagMutations', { max: 64 })) {
|
|
279
|
+
if (!/^[+-][A-Za-z0-9][A-Za-z0-9._-]{0,63}$/.test(mutation)) {
|
|
280
|
+
throw new HiveCommandError('hive/invalid-argument', 'edit.tagMutations entries must look like +tag or -tag');
|
|
281
|
+
}
|
|
282
|
+
parts.push('--tag', quote(mutation));
|
|
283
|
+
changes += 1;
|
|
284
|
+
}
|
|
285
|
+
if (args.superseded === true) { parts.push('--superseded'); changes += 1; }
|
|
286
|
+
else if (args.superseded === false) { parts.push('--no-superseded'); changes += 1; }
|
|
287
|
+
if (changes === 0) {
|
|
288
|
+
throw new HiveCommandError('hive/invalid-argument', 'edit needs at least one field to change');
|
|
289
|
+
}
|
|
290
|
+
if (args.superseded === true) {
|
|
291
|
+
const reason = optionalText(args.reason, 'edit.reason', 1000);
|
|
292
|
+
if (reason !== null) parts.push('--reason', quote(reason));
|
|
293
|
+
}
|
|
294
|
+
return parts.join(' ');
|
|
295
|
+
}
|
|
296
|
+
case 'split': {
|
|
297
|
+
// hive-tasks 1.9 split: --into '<json array>' (at least two entries),
|
|
298
|
+
// entries { title, role?, scope?, acceptance?, after? }; the parent is
|
|
299
|
+
// superseded with replacedBy = first child unless --keep is passed.
|
|
300
|
+
const id = needMatch(ID_RE, args.id, 'split.id');
|
|
301
|
+
const into = args.cards;
|
|
302
|
+
if (!Array.isArray(into) || into.length < 2) {
|
|
303
|
+
throw new HiveCommandError('hive/invalid-argument', 'split.cards must be an array of at least two fine-grained cards');
|
|
304
|
+
}
|
|
305
|
+
if (into.length > 32) {
|
|
306
|
+
throw new HiveCommandError('hive/invalid-argument', 'split.cards must have at most 32 entries; split in rounds');
|
|
307
|
+
}
|
|
308
|
+
const allowed = new Set(['title', 'role', 'scope', 'acceptance', 'after']);
|
|
309
|
+
const cards = into.map((entry, index) => {
|
|
310
|
+
if (entry === null || typeof entry !== 'object' || Array.isArray(entry)) {
|
|
311
|
+
throw new HiveCommandError('hive/invalid-argument', 'split.cards[' + index + '] must be an object');
|
|
312
|
+
}
|
|
313
|
+
for (const key of Object.keys(entry)) {
|
|
314
|
+
if (!allowed.has(key)) {
|
|
315
|
+
throw new HiveCommandError(
|
|
316
|
+
'hive/invalid-argument',
|
|
317
|
+
'split.cards[' + index + '].' + key + ' is not supported by hive-tasks 1.9 (title/role/scope/acceptance/after only)',
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
const card = { title: textArg(entry.title, 'split.cards[' + index + '].title', 300) };
|
|
322
|
+
if (entry.role !== undefined) card.role = needMatch(CARD_ROLE_RE, entry.role, 'split.cards[' + index + '].role');
|
|
323
|
+
if (entry.scope !== undefined) card.scope = listArg(entry.scope, 'split.cards[' + index + '].scope');
|
|
324
|
+
if (entry.acceptance !== undefined) card.acceptance = textArg(entry.acceptance, 'split.cards[' + index + '].acceptance');
|
|
325
|
+
if (entry.after !== undefined) {
|
|
326
|
+
card.after = listArg(entry.after, 'split.cards[' + index + '].after', { max: 128 })
|
|
327
|
+
.map((dep) => needMatch(ID_RE, dep, 'split.cards[' + index + '].after entry'));
|
|
328
|
+
}
|
|
329
|
+
return card;
|
|
330
|
+
});
|
|
331
|
+
const json = JSON.stringify(cards);
|
|
332
|
+
if (json.length > 24_000) {
|
|
333
|
+
throw new HiveCommandError('hive/invalid-argument', 'split.cards JSON is too large (limit 24000 characters)');
|
|
334
|
+
}
|
|
335
|
+
const reason = optionalText(args.reason, 'split.reason', 1000);
|
|
336
|
+
return tasks + ' split ' + quote(id) + ' --into ' + quote(json) + ' --json'
|
|
337
|
+
+ (reason === null ? '' : ' --reason ' + quote(reason));
|
|
338
|
+
}
|
|
339
|
+
case 'supersede': {
|
|
340
|
+
const id = needMatch(ID_RE, args.id, 'supersede.id');
|
|
341
|
+
const reason = textArg(args.reason, 'supersede.reason', 1000);
|
|
342
|
+
const parts = [tasks, 'supersede', quote(id), '--json', '--reason', quote(reason)];
|
|
343
|
+
if (args.replacedBy !== undefined && args.replacedBy !== null && args.replacedBy !== '') {
|
|
344
|
+
parts.push('--replaced-by', quote(needMatch(ID_RE, args.replacedBy, 'supersede.replacedBy')));
|
|
345
|
+
}
|
|
346
|
+
return parts.join(' ');
|
|
347
|
+
}
|
|
348
|
+
case 'reopen': {
|
|
349
|
+
const id = needMatch(ID_RE, args.id, 'reopen.id');
|
|
350
|
+
const reason = args.reason === undefined || args.reason === null || args.reason === ''
|
|
351
|
+
? null
|
|
352
|
+
: textArg(args.reason, 'reopen.reason', 1000);
|
|
353
|
+
return tasks + ' reopen ' + quote(id) + ' --json' + (reason === null ? '' : ' --reason ' + quote(reason));
|
|
354
|
+
}
|
|
355
|
+
case 'retry': {
|
|
356
|
+
const id = needMatch(ID_RE, args.id, 'retry.id');
|
|
357
|
+
return tasks + ' retry ' + quote(id) + ' --json';
|
|
358
|
+
}
|
|
359
|
+
case 'remove': {
|
|
360
|
+
const id = needMatch(ID_RE, args.id, 'remove.id');
|
|
361
|
+
// No --force: a claimed card must be released by its owner (or expire)
|
|
362
|
+
// before the queen may delete it; the CLI refuses instead of destroying work.
|
|
363
|
+
return tasks + ' rm ' + quote(id);
|
|
364
|
+
}
|
|
132
365
|
case 'board':
|
|
133
366
|
return hive + ' board --json';
|
|
134
367
|
case 'guard': {
|
|
@@ -153,6 +386,50 @@ export function buildCommand(verb, args = {}, bins = {}) {
|
|
|
153
386
|
}
|
|
154
387
|
return hive + ' recall ' + quote(args.query.trim()) + ' --json';
|
|
155
388
|
}
|
|
389
|
+
case 'lessonAdd': {
|
|
390
|
+
const text = textArg(args.text, 'lessonAdd.text');
|
|
391
|
+
const scope = args.scope === undefined || args.scope === null || args.scope === ''
|
|
392
|
+
? null
|
|
393
|
+
: textArg(args.scope, 'lessonAdd.scope', TOKEN_MAX);
|
|
394
|
+
const evidence = args.evidence === undefined || args.evidence === null || args.evidence === ''
|
|
395
|
+
? null
|
|
396
|
+
: textArg(args.evidence, 'lessonAdd.evidence', TOKEN_MAX);
|
|
397
|
+
const status = args.status === undefined || args.status === null || args.status === ''
|
|
398
|
+
? null
|
|
399
|
+
: needMatch(new RegExp('^(?:' + LESSON_STATUSES.join('|') + ')$'), args.status, 'lessonAdd.status');
|
|
400
|
+
const parts = [hive, 'lesson', 'add'];
|
|
401
|
+
if (scope !== null) parts.push('--scope', quote(scope));
|
|
402
|
+
if (evidence !== null) parts.push('--evidence', quote(evidence));
|
|
403
|
+
if (status !== null) parts.push('--status', quote(status));
|
|
404
|
+
parts.push(quote(text));
|
|
405
|
+
return parts.join(' ');
|
|
406
|
+
}
|
|
407
|
+
case 'rolesList':
|
|
408
|
+
return roles + ' roles list --json';
|
|
409
|
+
case 'rolesAdd': {
|
|
410
|
+
const name = needMatch(CARD_ROLE_RE, args.name, 'rolesAdd.name');
|
|
411
|
+
const parts = [roles, 'roles', 'add', quote(name)];
|
|
412
|
+
const adapter = args.adapter === undefined || args.adapter === null || args.adapter === ''
|
|
413
|
+
? null
|
|
414
|
+
: needMatch(new RegExp('^(?:' + ROLE_ADAPTERS.join('|') + ')$'), args.adapter, 'rolesAdd.adapter');
|
|
415
|
+
if (adapter !== null) parts.push('--adapter', quote(adapter));
|
|
416
|
+
const model = args.model === undefined || args.model === null || args.model === ''
|
|
417
|
+
? null
|
|
418
|
+
: needMatch(MODEL_RE, args.model, 'rolesAdd.model');
|
|
419
|
+
if (model !== null) parts.push('--model', quote(model));
|
|
420
|
+
const prompt = args.prompt === undefined || args.prompt === null || args.prompt === ''
|
|
421
|
+
? null
|
|
422
|
+
: textArg(args.prompt, 'rolesAdd.prompt', TOKEN_MAX);
|
|
423
|
+
if (prompt !== null) parts.push('--prompt', quote(prompt));
|
|
424
|
+
const description = optionalText(args.description, 'rolesAdd.description', 2000);
|
|
425
|
+
if (description !== null) parts.push('--description', quote(description));
|
|
426
|
+
if (args.force === true) parts.push('--force');
|
|
427
|
+
return parts.join(' ');
|
|
428
|
+
}
|
|
429
|
+
case 'rolesRemove': {
|
|
430
|
+
const name = needMatch(CARD_ROLE_RE, args.name, 'rolesRemove.name');
|
|
431
|
+
return roles + ' roles rm ' + quote(name);
|
|
432
|
+
}
|
|
156
433
|
case 'head':
|
|
157
434
|
return git + ' rev-parse HEAD';
|
|
158
435
|
case 'acceptance': {
|
|
@@ -200,7 +477,7 @@ export function missingBinaryHint(verb, bins = {}) {
|
|
|
200
477
|
if (key === undefined || key === null) return null;
|
|
201
478
|
const configured = typeof bins[key] === 'string' && bins[key] !== '' ? bins[key] : BIN_EXECUTABLES[key];
|
|
202
479
|
const packages = BIN_PACKAGES[key];
|
|
203
|
-
const configKey = key === 'tasks' ? 'tasksBin' : 'hiveBin';
|
|
480
|
+
const configKey = key === 'tasks' ? 'tasksBin' : key === 'roles' ? 'rolesBin' : 'hiveBin';
|
|
204
481
|
return '[hive-runner] ' + configured + ' was not found on the shell PATH and the npx fallback did not run it; '
|
|
205
482
|
+ 'install it with "npm i -g ' + packages.join(' ') + '" or set ' + configKey + '.';
|
|
206
483
|
}
|
|
@@ -236,7 +513,12 @@ function failure(result, label) {
|
|
|
236
513
|
*/
|
|
237
514
|
export function createCommands({ ctx, config }) {
|
|
238
515
|
const run = createShellRunner({ ctx, config });
|
|
239
|
-
const bins = {
|
|
516
|
+
const bins = {
|
|
517
|
+
tasks: config.tasksBin,
|
|
518
|
+
hive: config.hiveBin,
|
|
519
|
+
roles: config.rolesBin ?? config.hiveBin,
|
|
520
|
+
git: config.gitBin,
|
|
521
|
+
};
|
|
240
522
|
|
|
241
523
|
/** Execute one allowlisted verb. @returns {Promise<object>} the raw shell result */
|
|
242
524
|
async function execute(verb, args, options = {}) {
|
|
@@ -366,7 +648,110 @@ export function createCommands({ ctx, config }) {
|
|
|
366
648
|
const value = parseJson(result.stdout, 'hive recall');
|
|
367
649
|
return Array.isArray(value) ? value : [];
|
|
368
650
|
},
|
|
651
|
+
/** `hive-tasks list --json [--state S] [--role R]` -> parsed card array. */
|
|
652
|
+
async list(repo, options = {}) {
|
|
653
|
+
const result = await execute('list', { state: options.state, role: options.role }, { ...options, repo });
|
|
654
|
+
if (result.exitCode !== 0) throw failure(result, 'hive-tasks list');
|
|
655
|
+
const value = parseJson(result.stdout, 'hive-tasks list');
|
|
656
|
+
return Array.isArray(value) ? value : [];
|
|
657
|
+
},
|
|
658
|
+
/** `hive-tasks add ...` -> the created card (parsed from --json output). */
|
|
659
|
+
async add(repo, card, options = {}) {
|
|
660
|
+
const args = {
|
|
661
|
+
title: card.title,
|
|
662
|
+
role: card.role,
|
|
663
|
+
scope: card.scope,
|
|
664
|
+
after: card.after,
|
|
665
|
+
priority: card.priority,
|
|
666
|
+
goal: card.goal,
|
|
667
|
+
acceptance: card.acceptance,
|
|
668
|
+
tags: card.tags,
|
|
669
|
+
reviewOf: card.reviewOf,
|
|
670
|
+
draft: card.draft,
|
|
671
|
+
};
|
|
672
|
+
const result = await execute('add', args, { ...options, repo });
|
|
673
|
+
if (result.exitCode !== 0) throw failure(result, 'hive-tasks add');
|
|
674
|
+
const value = parseJson(result.stdout, 'hive-tasks add');
|
|
675
|
+
return value !== null && typeof value === 'object' ? value : null;
|
|
676
|
+
},
|
|
677
|
+
/** `hive-tasks edit <id> [flags]` -> the updated card (partial update). */
|
|
678
|
+
async edit(repo, id, patch, options = {}) {
|
|
679
|
+
const result = await execute('edit', { id, ...patch }, { ...options, repo });
|
|
680
|
+
if (result.exitCode !== 0) throw failure(result, 'hive-tasks edit ' + id);
|
|
681
|
+
return parseJson(result.stdout, 'hive-tasks edit');
|
|
682
|
+
},
|
|
683
|
+
/** `hive-tasks split <id> --into '<json>'` -> { task, cards }. */
|
|
684
|
+
async split(repo, id, cards, options = {}) {
|
|
685
|
+
const result = await execute('split', { id, cards, reason: options.reason }, { ...options, repo });
|
|
686
|
+
if (result.exitCode !== 0) throw failure(result, 'hive-tasks split ' + id);
|
|
687
|
+
return parseJson(result.stdout, 'hive-tasks split');
|
|
688
|
+
},
|
|
689
|
+
/** `hive-tasks supersede <id> --reason R [--replaced-by ID]` -> the marked card. */
|
|
690
|
+
async supersede(repo, id, options = {}) {
|
|
691
|
+
const result = await execute('supersede', {
|
|
692
|
+
id,
|
|
693
|
+
reason: options.reason,
|
|
694
|
+
replacedBy: options.replacedBy,
|
|
695
|
+
}, { ...options, repo });
|
|
696
|
+
if (result.exitCode !== 0) throw failure(result, 'hive-tasks supersede ' + id);
|
|
697
|
+
return parseJson(result.stdout, 'hive-tasks supersede');
|
|
698
|
+
},
|
|
699
|
+
/** `hive-tasks reopen <id> [--reason R]` -> the reopened card. */
|
|
700
|
+
async reopen(repo, id, options = {}) {
|
|
701
|
+
const result = await execute('reopen', { id, reason: options.reason }, { ...options, repo });
|
|
702
|
+
if (result.exitCode !== 0) throw failure(result, 'hive-tasks reopen ' + id);
|
|
703
|
+
return parseJson(result.stdout, 'hive-tasks reopen');
|
|
704
|
+
},
|
|
705
|
+
/** `hive-tasks retry <id>` -> the retried card. */
|
|
706
|
+
async retry(repo, id, options = {}) {
|
|
707
|
+
const result = await execute('retry', { id }, { ...options, repo });
|
|
708
|
+
if (result.exitCode !== 0) throw failure(result, 'hive-tasks retry ' + id);
|
|
709
|
+
return parseJson(result.stdout, 'hive-tasks retry');
|
|
710
|
+
},
|
|
711
|
+
/** `hive-tasks rm <id>`: delete a card; the CLI refuses a claimed card. */
|
|
712
|
+
async remove(repo, id, options = {}) {
|
|
713
|
+
const result = await execute('remove', { id }, { ...options, repo });
|
|
714
|
+
if (result.exitCode !== 0) throw failure(result, 'hive-tasks rm ' + id);
|
|
715
|
+
return result.stdout.trim();
|
|
716
|
+
},
|
|
717
|
+
/** `hive lesson add [--scope G] [--evidence E] [--status S] <text>`. */
|
|
718
|
+
async lessonAdd(repo, lesson, options = {}) {
|
|
719
|
+
const result = await execute('lessonAdd', {
|
|
720
|
+
text: lesson.text,
|
|
721
|
+
scope: lesson.scope,
|
|
722
|
+
evidence: lesson.evidence,
|
|
723
|
+
status: lesson.status,
|
|
724
|
+
}, { ...options, repo });
|
|
725
|
+
if (result.exitCode !== 0) throw failure(result, 'hive lesson add');
|
|
726
|
+
return result.stdout.trim();
|
|
727
|
+
},
|
|
728
|
+
/** `hive roles list --json` -> parsed role rows. */
|
|
729
|
+
async rolesList(repo, options = {}) {
|
|
730
|
+
const result = await execute('rolesList', {}, { ...options, repo });
|
|
731
|
+
if (result.exitCode !== 0) throw failure(result, 'hive roles list');
|
|
732
|
+
const value = parseJson(result.stdout, 'hive roles list');
|
|
733
|
+
return Array.isArray(value) ? value : [];
|
|
734
|
+
},
|
|
735
|
+
/** `hive roles add <name> [...]`; returns the CLI output. */
|
|
736
|
+
async rolesAdd(repo, role, options = {}) {
|
|
737
|
+
const result = await execute('rolesAdd', {
|
|
738
|
+
name: role.name,
|
|
739
|
+
adapter: role.adapter,
|
|
740
|
+
model: role.model,
|
|
741
|
+
prompt: role.prompt,
|
|
742
|
+
description: role.description,
|
|
743
|
+
force: role.force,
|
|
744
|
+
}, { ...options, repo });
|
|
745
|
+
if (result.exitCode !== 0) throw failure(result, 'hive roles add');
|
|
746
|
+
return result.stdout.trim();
|
|
747
|
+
},
|
|
748
|
+
/** `hive roles rm <name>`; returns the CLI output. */
|
|
749
|
+
async rolesRemove(repo, name, options = {}) {
|
|
750
|
+
const result = await execute('rolesRemove', { name }, { ...options, repo });
|
|
751
|
+
if (result.exitCode !== 0) throw failure(result, 'hive roles rm');
|
|
752
|
+
return result.stdout.trim();
|
|
753
|
+
},
|
|
369
754
|
};
|
|
370
755
|
}
|
|
371
756
|
|
|
372
|
-
export { createShellRunner };
|
|
757
|
+
export { createShellRunner };
|
package/lib/config.js
CHANGED
|
@@ -24,6 +24,14 @@ 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: 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;
|
|
27
35
|
/** Default role -> concurrent live-worker cap, per repository. */
|
|
28
36
|
export const DEFAULT_ROLE_CONCURRENCY = Object.freeze({ coder: 5, tester: 5 });
|
|
29
37
|
/** Fallback cap for roles not listed in `roleConcurrency` (also finite). */
|
|
@@ -58,6 +66,16 @@ const DEFAULTS = Object.freeze({
|
|
|
58
66
|
cardTimeoutMs: DEFAULT_CARD_TIMEOUT_MS,
|
|
59
67
|
heartbeatWarnMs: DEFAULT_HEARTBEAT_WARN_MS,
|
|
60
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,
|
|
61
79
|
provider: 'spawn',
|
|
62
80
|
parentSession: null,
|
|
63
81
|
cwd: null,
|
|
@@ -278,8 +296,14 @@ export function resolveConfig(config = {}) {
|
|
|
278
296
|
if (cfg.parentSession !== null && cfg.parentSession !== undefined) cfg.parentSession = nonEmptyString(cfg.parentSession, 'parentSession');
|
|
279
297
|
else cfg.parentSession = null;
|
|
280
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');
|
|
281
304
|
cfg.tasksBin = bin(cfg.tasksBin, 'tasksBin', 'HIVE_TASKS_BIN', 'hive-tasks');
|
|
282
305
|
cfg.hiveBin = bin(cfg.hiveBin, 'hiveBin', 'HIVE_BIN', 'hive');
|
|
306
|
+
cfg.rolesBin = bin(cfg.rolesBin, 'rolesBin', 'HIVE_ROLES_BIN', cfg.hiveBin);
|
|
283
307
|
cfg.gitBin = bin(cfg.gitBin, 'gitBin', 'HIVE_GIT_BIN', 'git');
|
|
284
308
|
|
|
285
309
|
// Auto-discovery without explicit roots scans the parent of each configured
|