dsh-hive-panel 0.1.8 → 0.2.3
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 +77 -1
- package/README.md +77 -42
- package/README.zh-CN.md +58 -37
- package/SPEC.md +42 -5
- package/cordis.patch.yml +6 -4
- package/docs/DESIGN.md +98 -13
- package/lib/client.js +1313 -353
- package/lib/index.js +328 -12
- package/package.json +1 -1
- package/scripts/build-client.mjs +3 -0
- package/scripts/verify-host-exec.mjs +11 -5
- package/scripts/verify.mjs +276 -5
- package/src/client.template.js +51 -0
- package/src/panel.css +434 -93
- package/src/panel.js +1258 -352
- package/src/theme.css +1 -18
package/lib/index.js
CHANGED
|
@@ -67,6 +67,61 @@ export const DEFAULT_BINS = Object.freeze({
|
|
|
67
67
|
moc: 'moc',
|
|
68
68
|
})
|
|
69
69
|
|
|
70
|
+
/**
|
|
71
|
+
* npm packages that publish the executable behind each default bin. When a
|
|
72
|
+
* default PATH name is not resolvable in the shell that runs the command, the
|
|
73
|
+
* host retries once through `npx -y -p <package> ... <bin>` before reporting an
|
|
74
|
+
* actionable error. `hive` is the umbrella router, so the whole toolchain is
|
|
75
|
+
* installed into the npx cache and the router can resolve its cores.
|
|
76
|
+
*/
|
|
77
|
+
export const BIN_PACKAGES = Object.freeze({
|
|
78
|
+
hive: Object.freeze(['@d86e/hive', 'hive-consensus', 'hive-tasks', 'hive-runner', 'merge-on-commit']),
|
|
79
|
+
tasks: Object.freeze(['hive-tasks']),
|
|
80
|
+
run: Object.freeze(['hive-runner']),
|
|
81
|
+
moc: Object.freeze(['merge-on-commit']),
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
/** The executable name inside each npx package set (the package's declared bin). */
|
|
85
|
+
const BIN_EXECUTABLES = Object.freeze({
|
|
86
|
+
hive: 'hive',
|
|
87
|
+
tasks: 'hive-tasks',
|
|
88
|
+
run: 'hive-run',
|
|
89
|
+
moc: 'moc',
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Build the `npx` argv that runs one bin from its published package(s).
|
|
94
|
+
* @param {string} key - one of the DEFAULT_BINS keys.
|
|
95
|
+
* @param {string[]} [argv] - arguments for the bin, always appended after its name.
|
|
96
|
+
* @returns {string[] | null}
|
|
97
|
+
*/
|
|
98
|
+
export function npxInvocation(key, argv = []) {
|
|
99
|
+
const packages = BIN_PACKAGES[key]
|
|
100
|
+
const executable = BIN_EXECUTABLES[key]
|
|
101
|
+
if (packages === undefined || executable === undefined) return null
|
|
102
|
+
const tokens = ['-y']
|
|
103
|
+
for (const name of packages) tokens.push('-p', name)
|
|
104
|
+
tokens.push(executable, ...argv.map(token => String(token)))
|
|
105
|
+
return tokens
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* The npx fallback command for one configured bin. A configured absolute (or
|
|
110
|
+
* relative) path is the operator's explicit choice and is never replaced; only
|
|
111
|
+
* the default PATH name gets the package fallback.
|
|
112
|
+
* @param {string} key - one of the DEFAULT_BINS keys.
|
|
113
|
+
* @param {string[]} [argv] - arguments for the executable.
|
|
114
|
+
* @param {object} [bins] - trusted executable overrides.
|
|
115
|
+
* @returns {string | null}
|
|
116
|
+
*/
|
|
117
|
+
export function fallbackCommandForBin(key, argv = [], bins = DEFAULT_BINS) {
|
|
118
|
+
const executable = bins[key]
|
|
119
|
+
if (typeof executable !== 'string' || executable === '') return null
|
|
120
|
+
if (executable.includes('/') || executable.includes('\\')) return null
|
|
121
|
+
const tokens = npxInvocation(key, argv)
|
|
122
|
+
return tokens === null ? null : buildCommand('npx', tokens)
|
|
123
|
+
}
|
|
124
|
+
|
|
70
125
|
/** Read-only commands emitted for one snapshot (all fixed; no browser input). */
|
|
71
126
|
export const SNAPSHOT_COMMANDS = Object.freeze({
|
|
72
127
|
board: ['board', '--json'],
|
|
@@ -102,6 +157,13 @@ export const ROLE_MODEL_RE = /^[A-Za-z0-9._:-]{1,64}$/
|
|
|
102
157
|
const ROLE_LIMITS_FILE = path.join('.hive', 'limits.json')
|
|
103
158
|
const ROLE_LIMIT_MAX = 999
|
|
104
159
|
|
|
160
|
+
/** Last-run records written by hive-runner: one file per card id. */
|
|
161
|
+
export const RUNS_DIR = path.join('.hive', 'runs')
|
|
162
|
+
/** Defensive read cap; hive-runner already truncates to this size. */
|
|
163
|
+
const MAX_RUN_OUTPUT_BYTES = 32 * 1024
|
|
164
|
+
/** Record statuses the panel understands. */
|
|
165
|
+
const RUN_STATUSES = Object.freeze(['done', 'failed', 'running'])
|
|
166
|
+
|
|
105
167
|
/** One typed failure with the HTTP status and JSON code returned to the browser. */
|
|
106
168
|
export class HiveRequestError extends Error {
|
|
107
169
|
/**
|
|
@@ -176,6 +238,57 @@ export function parseJson(text, fallback) {
|
|
|
176
238
|
}
|
|
177
239
|
}
|
|
178
240
|
|
|
241
|
+
/** Last `max` characters of CLI output collapsed onto one line. */
|
|
242
|
+
function tailText(text, max = 300) {
|
|
243
|
+
const normalized = String(text ?? '').replace(/\s+/g, ' ').trim()
|
|
244
|
+
return normalized.length <= max ? normalized : '…' + normalized.slice(-max)
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* A stable diagnostic for a failed snapshot CLI read, or null on success.
|
|
249
|
+
* The snapshot previously collapsed every failure into the empty fallback, which
|
|
250
|
+
* made "the CLI did not run" indistinguishable from "there is nothing to show".
|
|
251
|
+
* @param {object|undefined} result - ctx.shell execute result.
|
|
252
|
+
* @param {string} label - user-facing command name, for example `hive board`.
|
|
253
|
+
* @returns {string|null}
|
|
254
|
+
*/
|
|
255
|
+
export function snapshotReadError(result, label) {
|
|
256
|
+
if (result === undefined || result === null) return label + ' did not run'
|
|
257
|
+
if (result.timedOut === true) return label + ' timed out'
|
|
258
|
+
if (result.aborted === true) return label + ' was aborted'
|
|
259
|
+
if (result.exitCode !== 0) {
|
|
260
|
+
const stderr = String(result.stderr?.text ?? '')
|
|
261
|
+
const stdout = String(result.stdout?.text ?? '')
|
|
262
|
+
const detail = tailText(stderr !== '' ? stderr : stdout)
|
|
263
|
+
return label + ' exited ' + String(result.exitCode) + (detail === '' ? ' with no output' : ': ' + detail)
|
|
264
|
+
}
|
|
265
|
+
return null
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Parse `hive board --json` into `{ board, boardError }`. A failed, empty or
|
|
270
|
+
* malformed read keeps the array empty but reports why, so the panel can show a
|
|
271
|
+
* diagnostic instead of the misleading "no agents" empty state.
|
|
272
|
+
* @param {object|undefined} result - board CLI execute result.
|
|
273
|
+
* @returns {{ board: object[], boardError: string|null }}
|
|
274
|
+
*/
|
|
275
|
+
export function parseBoardSnapshot(result) {
|
|
276
|
+
const failure = snapshotReadError(result, 'hive board')
|
|
277
|
+
if (failure !== null) return { board: [], boardError: failure }
|
|
278
|
+
const parsed = parseJson(result.stdout?.text, undefined)
|
|
279
|
+
if (parsed === undefined) return { board: [], boardError: 'hive board returned no JSON' }
|
|
280
|
+
if (!Array.isArray(parsed)) return { board: [], boardError: 'hive board returned a non-array JSON value' }
|
|
281
|
+
return { board: parsed, boardError: null }
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/** The bin key behind each snapshot command. */
|
|
285
|
+
export const SNAPSHOT_BINS = Object.freeze({
|
|
286
|
+
board: 'hive',
|
|
287
|
+
tasks: 'tasks',
|
|
288
|
+
stats: 'tasks',
|
|
289
|
+
roles: 'hive',
|
|
290
|
+
})
|
|
291
|
+
|
|
179
292
|
/** The read-only commands one snapshot fans out to (fixed argv, validated bins). */
|
|
180
293
|
export function snapshotCliCommands(bins = DEFAULT_BINS) {
|
|
181
294
|
return {
|
|
@@ -186,6 +299,46 @@ export function snapshotCliCommands(bins = DEFAULT_BINS) {
|
|
|
186
299
|
}
|
|
187
300
|
}
|
|
188
301
|
|
|
302
|
+
/** npx fallback command per snapshot read; null for an explicit absolute bin. */
|
|
303
|
+
export function snapshotFallbackCommands(bins = DEFAULT_BINS) {
|
|
304
|
+
return {
|
|
305
|
+
board: fallbackCommandForBin('hive', SNAPSHOT_COMMANDS.board, bins),
|
|
306
|
+
tasks: fallbackCommandForBin('tasks', SNAPSHOT_COMMANDS.tasks, bins),
|
|
307
|
+
stats: fallbackCommandForBin('tasks', SNAPSHOT_COMMANDS.stats, bins),
|
|
308
|
+
roles: fallbackCommandForBin('hive', SNAPSHOT_COMMANDS.roles, bins),
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/** Bash exit status for "command not found". */
|
|
313
|
+
const COMMAND_NOT_FOUND = 127
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* True when a shell result means the executable itself was missing (not when a
|
|
317
|
+
* CLI ran and reported its own failure). bash/yash/zsh all use 127 for this, and
|
|
318
|
+
* some sandbox wrappers only leave the message.
|
|
319
|
+
* @param {object|undefined} result - ctx.shell execute result.
|
|
320
|
+
* @returns {boolean}
|
|
321
|
+
*/
|
|
322
|
+
export function missingBinary(result) {
|
|
323
|
+
if (result === undefined || result === null) return false
|
|
324
|
+
if (result.exitCode === COMMAND_NOT_FOUND) return true
|
|
325
|
+
const stderr = String(result.stderr?.text ?? '')
|
|
326
|
+
return /command not found|: not found|No such file or directory/i.test(stderr)
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Append an actionable line to a failed shell result, keeping the CLI output.
|
|
331
|
+
* @param {object} result - ctx.shell execute result.
|
|
332
|
+
* @param {string} line - diagnostic appended to stderr.
|
|
333
|
+
* @returns {object} a shallow copy with stderr.text extended.
|
|
334
|
+
*/
|
|
335
|
+
export function appendStderr(result, line) {
|
|
336
|
+
const stderr = result.stderr ?? {}
|
|
337
|
+
const text = String(stderr.text ?? '')
|
|
338
|
+
const joined = text === '' ? line : text.replace(/\s+$/, '') + '\n' + line
|
|
339
|
+
return { ...result, stderr: { ...stderr, text: joined } }
|
|
340
|
+
}
|
|
341
|
+
|
|
189
342
|
/**
|
|
190
343
|
* Normalize `hive roles list --json` rows into the snapshot contract.
|
|
191
344
|
* Unknown/malformed rows are dropped; adapter/model/prompt are nullable.
|
|
@@ -249,6 +402,92 @@ export function readRoleLimits(cwd) {
|
|
|
249
402
|
return { limits, error: null }
|
|
250
403
|
}
|
|
251
404
|
|
|
405
|
+
/**
|
|
406
|
+
* Resolve one last-run record path, validating the id and containment.
|
|
407
|
+
* The card id is never trusted: anything that is not a single safe token
|
|
408
|
+
* (separators, dots-only ids) resolves to null before touching the filesystem.
|
|
409
|
+
* @param {string} cwd - repository root.
|
|
410
|
+
* @param {unknown} cardId - card id from the task list.
|
|
411
|
+
* @returns {string|null}
|
|
412
|
+
*/
|
|
413
|
+
export function lastRunPath(cwd, cardId) {
|
|
414
|
+
if (typeof cwd !== 'string' || cwd === '') return null
|
|
415
|
+
if (typeof cardId !== 'string' || !ID_RE.test(cardId)) return null
|
|
416
|
+
const dir = path.resolve(cwd, RUNS_DIR)
|
|
417
|
+
const file = path.resolve(dir, cardId + '.json')
|
|
418
|
+
if (!file.startsWith(dir + path.sep)) return null
|
|
419
|
+
return file
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Read one card's last-run record. Missing, unreadable, invalid or
|
|
424
|
+
* out-of-contract files all degrade to null: a broken record never breaks the
|
|
425
|
+
* snapshot. A record written by a worker activation also carries that worker's
|
|
426
|
+
* `sessionId` (and its `agentName`); both are forwarded only when present so a
|
|
427
|
+
* legacy record keeps its exact previous shape. hive-consensus `overlaps` and
|
|
428
|
+
* the memory-recall `lessons` summary are forwarded verbatim for the shared
|
|
429
|
+
* renderer to normalize, and are omitted from legacy records the same way.
|
|
430
|
+
* @param {string} cwd - repository root.
|
|
431
|
+
* @param {unknown} cardId - card id from the task list.
|
|
432
|
+
* @returns {null|{ cardId: string, agent: string, startedAt: string|null, endedAt: string|null, status: 'done'|'failed'|'running', exitCode?: number, commit?: string, sessionId?: string, agentName?: string, overlaps?: Array<object>, lessons?: object, output: string }}
|
|
433
|
+
*/
|
|
434
|
+
export function readLastRun(cwd, cardId) {
|
|
435
|
+
const file = lastRunPath(cwd, cardId)
|
|
436
|
+
if (file === null) return null
|
|
437
|
+
let text
|
|
438
|
+
try {
|
|
439
|
+
text = fs.readFileSync(file, 'utf8')
|
|
440
|
+
} catch {
|
|
441
|
+
return null
|
|
442
|
+
}
|
|
443
|
+
let parsed
|
|
444
|
+
try {
|
|
445
|
+
parsed = JSON.parse(text)
|
|
446
|
+
} catch {
|
|
447
|
+
return null
|
|
448
|
+
}
|
|
449
|
+
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) return null
|
|
450
|
+
if (!RUN_STATUSES.includes(parsed.status)) return null
|
|
451
|
+
const record = {
|
|
452
|
+
cardId: typeof parsed.cardId === 'string' && parsed.cardId !== '' ? parsed.cardId : cardId,
|
|
453
|
+
agent: typeof parsed.agent === 'string' ? parsed.agent : '',
|
|
454
|
+
startedAt: typeof parsed.startedAt === 'string' ? parsed.startedAt : null,
|
|
455
|
+
endedAt: typeof parsed.endedAt === 'string' ? parsed.endedAt : null,
|
|
456
|
+
status: parsed.status,
|
|
457
|
+
output: typeof parsed.output === 'string' ? parsed.output.slice(0, MAX_RUN_OUTPUT_BYTES) : '',
|
|
458
|
+
}
|
|
459
|
+
if (Number.isInteger(parsed.exitCode)) record.exitCode = parsed.exitCode
|
|
460
|
+
if (typeof parsed.commit === 'string' && parsed.commit !== '') record.commit = parsed.commit
|
|
461
|
+
// Worker chat identity: forwarded verbatim, omitted on pre-0.6.4 records.
|
|
462
|
+
if (typeof parsed.sessionId === 'string' && parsed.sessionId !== '') record.sessionId = parsed.sessionId
|
|
463
|
+
if (typeof parsed.agentName === 'string' && parsed.agentName !== '') record.agentName = parsed.agentName
|
|
464
|
+
// hive-consensus announcements and the memory-recall summary: forwarded
|
|
465
|
+
// verbatim when present, normalized by the shared renderer. A malformed value
|
|
466
|
+
// is dropped here and an older record gains no extra key.
|
|
467
|
+
if (Array.isArray(parsed.overlaps)) record.overlaps = parsed.overlaps
|
|
468
|
+
if (parsed.lessons !== null && typeof parsed.lessons === 'object' && !Array.isArray(parsed.lessons)) {
|
|
469
|
+
record.lessons = parsed.lessons
|
|
470
|
+
}
|
|
471
|
+
return record
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Attach `lastRun` to every card of the current repository's task list.
|
|
476
|
+
* Non-array input is returned untouched so the snapshot contract cannot change
|
|
477
|
+
* shape because of a malformed CLI payload.
|
|
478
|
+
* @param {string} cwd - repository root.
|
|
479
|
+
* @param {unknown} tasks - parsed `hive-tasks list --json`.
|
|
480
|
+
* @returns {unknown}
|
|
481
|
+
*/
|
|
482
|
+
export function attachLastRuns(cwd, tasks) {
|
|
483
|
+
if (!Array.isArray(tasks)) return tasks
|
|
484
|
+
return tasks.map(task => (
|
|
485
|
+
task !== null && typeof task === 'object' && !Array.isArray(task)
|
|
486
|
+
? { ...task, lastRun: readLastRun(cwd, task.id) }
|
|
487
|
+
: task
|
|
488
|
+
))
|
|
489
|
+
}
|
|
490
|
+
|
|
252
491
|
// ── action argument validation ──────────────────────────────────────────────
|
|
253
492
|
|
|
254
493
|
function invalid(field, rule) {
|
|
@@ -404,10 +643,6 @@ const ACTION_BUILDERS = Object.freeze({
|
|
|
404
643
|
argv: ['fail', idArg(payload.id), '--reason', optionalString(payload.reason, 'reason', 2000) ?? 'failed from panel'],
|
|
405
644
|
}),
|
|
406
645
|
retry: payload => ({ bin: 'tasks', argv: ['retry', idArg(payload.id)] }),
|
|
407
|
-
block: payload => ({
|
|
408
|
-
bin: 'tasks',
|
|
409
|
-
argv: ['block', idArg(payload.id), '--reason', optionalString(payload.reason, 'reason', 2000) ?? 'blocked from panel'],
|
|
410
|
-
}),
|
|
411
646
|
renew: payload => {
|
|
412
647
|
const argv = ['renew', idArg(payload.id), '--ttl', ttlArg(payload.ttl)]
|
|
413
648
|
const agent = optionalString(payload.agent, 'agent', 64)
|
|
@@ -465,6 +700,15 @@ const ACTION_BUILDERS = Object.freeze({
|
|
|
465
700
|
if (description !== undefined) argv.push('--description', description)
|
|
466
701
|
return { bin: 'hive', argv }
|
|
467
702
|
},
|
|
703
|
+
// 'hive roles rm <name>': drops the role from .hive/roles.yaml. Neither
|
|
704
|
+
// --force nor --keep-file is ever sent, so the CLI itself decides every
|
|
705
|
+
// refusal (e.g. "role ... not found") and its stderr reaches the panel
|
|
706
|
+
// unchanged. The host does not inspect cards/limits: hive roles rm does not
|
|
707
|
+
// check in-flight work, and the contract file is kept by the CLI.
|
|
708
|
+
'roles-remove': payload => ({
|
|
709
|
+
bin: 'hive',
|
|
710
|
+
argv: ['roles', 'rm', roleNameArg(payload.name)],
|
|
711
|
+
}),
|
|
468
712
|
// 'hive tasks rm <id>' goes through the hive router to hive-tasks. No --force
|
|
469
713
|
// is ever sent: a claimed card is refused by the CLI, and that refusal (like
|
|
470
714
|
// a second delete's "not found") reaches the panel in stderr unchanged.
|
|
@@ -651,6 +895,43 @@ export function createBridge(ctx, config = {}) {
|
|
|
651
895
|
}
|
|
652
896
|
}
|
|
653
897
|
|
|
898
|
+
/** Actionable diagnostic for a bin whose PATH name and npx fallback both failed. */
|
|
899
|
+
function missingBinHint(key) {
|
|
900
|
+
const executable = typeof bins[key] === 'string' ? bins[key] : String(DEFAULT_BINS[key])
|
|
901
|
+
const packages = BIN_PACKAGES[key] ?? []
|
|
902
|
+
const install = packages.length === 0 ? 'npm i -g <package>' : 'npm i -g ' + packages.join(' ')
|
|
903
|
+
return '[hive-panel] ' + String(key) + ' CLI ' + JSON.stringify(executable)
|
|
904
|
+
+ ' was not found on the PATH of the DSH shell and the npx fallback did not run it; install it once with "'
|
|
905
|
+
+ install + '" or set config.bins.' + String(key) + ' to an absolute path.'
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
/**
|
|
909
|
+
* Execute one fixed command; when the bare PATH executable is missing, retry
|
|
910
|
+
* the same argv once through `npx -y -p <package> ... <bin>`. An explicit
|
|
911
|
+
* absolute bin (no npx fallback) fails with the same install hint.
|
|
912
|
+
*/
|
|
913
|
+
async function executeWithFallback(command, fallback, options, key) {
|
|
914
|
+
const first = await execute(command, options)
|
|
915
|
+
if (!missingBinary(first)) return first
|
|
916
|
+
if (typeof fallback === 'string') {
|
|
917
|
+
log('bin ' + String(key) + ' is not on the shell PATH; retrying through npx')
|
|
918
|
+
const retried = await execute(fallback, options)
|
|
919
|
+
if (!missingBinary(retried)) return retried
|
|
920
|
+
return appendStderr(retried, missingBinHint(key))
|
|
921
|
+
}
|
|
922
|
+
return appendStderr(first, missingBinHint(key))
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
/** tryExecute + npx fallback (snapshot fan-out and per-command probes). */
|
|
926
|
+
async function tryExecuteWithFallback(command, fallback, options, key) {
|
|
927
|
+
try {
|
|
928
|
+
return await executeWithFallback(command, fallback, options, key)
|
|
929
|
+
} catch (error) {
|
|
930
|
+
log('probe failed: ' + command, error)
|
|
931
|
+
return undefined
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
|
|
654
935
|
function readMode(result) {
|
|
655
936
|
const parsed = result === undefined ? null : parseJson(result.stdout?.text, null)
|
|
656
937
|
if (parsed !== null && typeof parsed === 'object' && !Array.isArray(parsed)) return parsed
|
|
@@ -674,6 +955,32 @@ export function createBridge(ctx, config = {}) {
|
|
|
674
955
|
}
|
|
675
956
|
}
|
|
676
957
|
|
|
958
|
+
/**
|
|
959
|
+
* Register the queen Session with the resident Hive runner (when mounted).
|
|
960
|
+
* The runner parents every card worker to exactly this Session; before this
|
|
961
|
+
* registration it waits instead of dispatching. Registration is in-memory and
|
|
962
|
+
* idempotent, so every panel snapshot re-registers after a restart.
|
|
963
|
+
* @param {string} sessionId live Session id of the queen conversation
|
|
964
|
+
*/
|
|
965
|
+
function registerQueenSession(sessionId) {
|
|
966
|
+
if (typeof sessionId !== 'string' || sessionId === '') return false
|
|
967
|
+
let runner
|
|
968
|
+
try {
|
|
969
|
+
runner = ctx.get('hiveSupervisor')
|
|
970
|
+
} catch (error) {
|
|
971
|
+
log('hive-runner queen registration lookup failed', error)
|
|
972
|
+
return false
|
|
973
|
+
}
|
|
974
|
+
if (runner === undefined || typeof runner.setQueenSession !== 'function') return false
|
|
975
|
+
try {
|
|
976
|
+
runner.setQueenSession(sessionId)
|
|
977
|
+
return true
|
|
978
|
+
} catch (error) {
|
|
979
|
+
log('hive-runner queen registration failed', error)
|
|
980
|
+
return false
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
|
|
677
984
|
/**
|
|
678
985
|
* Auto-activate queen mode for an initialised Session before a snapshot is
|
|
679
986
|
* returned. Idempotent: the controller does not rewrite an active session and
|
|
@@ -727,6 +1034,7 @@ export function createBridge(ctx, config = {}) {
|
|
|
727
1034
|
initialised: false,
|
|
728
1035
|
mode: { mode: 'free' },
|
|
729
1036
|
board: [],
|
|
1037
|
+
boardError: null,
|
|
730
1038
|
tasks: [],
|
|
731
1039
|
stats: null,
|
|
732
1040
|
events: [],
|
|
@@ -738,24 +1046,28 @@ export function createBridge(ctx, config = {}) {
|
|
|
738
1046
|
const initialised = refs !== undefined && refs.exitCode === 0 && String(refs.stdout?.text ?? '').trim() !== ''
|
|
739
1047
|
if (initialised) autoActivateQueen(sessionId, cwd)
|
|
740
1048
|
payload.queen = queenSnapshot(sessionId, cwd)
|
|
1049
|
+
if (payload.queen.active) registerQueenSession(sessionId)
|
|
741
1050
|
if (!initialised) {
|
|
742
1051
|
payload.events = readEvents(cwd)
|
|
743
1052
|
return payload
|
|
744
1053
|
}
|
|
745
1054
|
const commands = snapshotCliCommands(bins)
|
|
1055
|
+
const fallbacks = snapshotFallbackCommands(bins)
|
|
746
1056
|
const [board, tasks, stats, mode, roles] = await Promise.all([
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
1057
|
+
tryExecuteWithFallback(commands.board, fallbacks.board, { cwd, session, timeoutMs: snapshotTimeoutMs, signal }, 'hive'),
|
|
1058
|
+
tryExecuteWithFallback(commands.tasks, fallbacks.tasks, { cwd, session, timeoutMs: snapshotTimeoutMs, signal }, 'tasks'),
|
|
1059
|
+
tryExecuteWithFallback(commands.stats, fallbacks.stats, { cwd, session, timeoutMs: snapshotTimeoutMs, signal }, 'tasks'),
|
|
750
1060
|
tryExecute(SNAPSHOT_READS.mode, { cwd, session, timeoutMs: PROBE_TIMEOUT_MS, signal }),
|
|
751
|
-
|
|
1061
|
+
tryExecuteWithFallback(commands.roles, fallbacks.roles, { cwd, session, timeoutMs: snapshotTimeoutMs, signal }, 'hive'),
|
|
752
1062
|
])
|
|
1063
|
+
const boardRead = parseBoardSnapshot(board)
|
|
753
1064
|
return {
|
|
754
1065
|
...payload,
|
|
755
1066
|
initialised: true,
|
|
756
1067
|
mode: readMode(mode),
|
|
757
|
-
board:
|
|
758
|
-
|
|
1068
|
+
board: boardRead.board,
|
|
1069
|
+
boardError: boardRead.boardError,
|
|
1070
|
+
tasks: attachLastRuns(cwd, parseJson(tasks?.stdout?.text, [])),
|
|
759
1071
|
stats: parseJson(stats?.stdout?.text, null),
|
|
760
1072
|
events: readEvents(cwd),
|
|
761
1073
|
roles: rolesSnapshot(cwd, roles),
|
|
@@ -798,6 +1110,7 @@ export function createBridge(ctx, config = {}) {
|
|
|
798
1110
|
if (refs === undefined || refs.exitCode !== 0 || String(refs.stdout?.text ?? '').trim() === '') return false
|
|
799
1111
|
try {
|
|
800
1112
|
queen.mark({ sessionId, cwd })
|
|
1113
|
+
registerQueenSession(sessionId)
|
|
801
1114
|
return true
|
|
802
1115
|
} catch (error) {
|
|
803
1116
|
log('queen activation failed', error)
|
|
@@ -817,6 +1130,7 @@ export function createBridge(ctx, config = {}) {
|
|
|
817
1130
|
throw new HiveRequestError('hive/queen-unavailable', 'queen controller is unavailable', 500)
|
|
818
1131
|
}
|
|
819
1132
|
queen.mark({ sessionId, cwd, source: 'manual' })
|
|
1133
|
+
registerQueenSession(sessionId)
|
|
820
1134
|
return { status: 200, body: { ok: true, code: 0, stdout: '', stderr: '' } }
|
|
821
1135
|
}
|
|
822
1136
|
if (actionName === QUEEN_OFF_ACTION) {
|
|
@@ -834,8 +1148,10 @@ export function createBridge(ctx, config = {}) {
|
|
|
834
1148
|
body: { ok: false, code: 2, stdout: '', stderr: 'read-only: hive-panel writable=false' },
|
|
835
1149
|
}
|
|
836
1150
|
}
|
|
837
|
-
const
|
|
838
|
-
const
|
|
1151
|
+
const invocation = actionInvocation(actionName, payload)
|
|
1152
|
+
const command = buildCommand(bins[invocation.bin], invocation.argv)
|
|
1153
|
+
const fallback = fallbackCommandForBin(invocation.bin, invocation.argv, bins)
|
|
1154
|
+
const result = await executeWithFallback(command, fallback, { cwd, session, timeoutMs: actionTimeoutMs, signal }, invocation.bin)
|
|
839
1155
|
const body = actionBody(result)
|
|
840
1156
|
if (actionName === 'init' && body.ok) {
|
|
841
1157
|
await activateQueen(sessionId, cwd, session, signal)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-hive-panel",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Hive board and queen mode inside DSH Web: a conversation view scoped to the Session's repository, with allowlisted task-card actions over DSH's shell seam.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
package/scripts/build-client.mjs
CHANGED
|
@@ -53,6 +53,9 @@ const moduleCode = [
|
|
|
53
53
|
" onError: function (error) { console.warn('[hive-panel]', error) },",
|
|
54
54
|
" t: params.hiveTranslate,",
|
|
55
55
|
" subscribeLocale: params.hiveLocaleSubscribe,",
|
|
56
|
+
" // Optional: the client half only supplies this when the host",
|
|
57
|
+
" // exposes workspace navigation (ctx.uiWorkspace.openSession).",
|
|
58
|
+
" openSession: typeof params.hiveOpenSession === 'function' ? params.hiveOpenSession : undefined,",
|
|
56
59
|
" })",
|
|
57
60
|
" return function () { instance.destroy() }",
|
|
58
61
|
" }, [sessionId])",
|
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
import assert from 'node:assert/strict'
|
|
16
16
|
import { execFile } from 'node:child_process'
|
|
17
17
|
import { existsSync } from 'node:fs'
|
|
18
|
+
import os from 'node:os'
|
|
19
|
+
import path from 'node:path'
|
|
18
20
|
import { promisify } from 'node:util'
|
|
19
21
|
import { commandFor, inject, FETCH_PATH, RPC_CHANNEL, apply } from './hive-exec-demo.mjs'
|
|
20
22
|
|
|
@@ -23,11 +25,15 @@ let checks = 0
|
|
|
23
25
|
const ok = (message) => { checks += 1; console.log('ok ' + checks + ' - ' + message) }
|
|
24
26
|
const skip = (message) => { console.log('# skip - ' + message) }
|
|
25
27
|
|
|
26
|
-
//
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const
|
|
28
|
+
// Optional real-CLI evidence (check 10). Nothing here is required for the shim
|
|
29
|
+
// checks: point the env vars at your checkouts, or keep the sibling/PATH
|
|
30
|
+
// defaults. The demo repository must already contain Hive cards; without it the
|
|
31
|
+
// real-CLI check skips with a message instead of failing on an author path.
|
|
32
|
+
const SIBLINGS = path.resolve(import.meta.dirname, '..', '..')
|
|
33
|
+
const HIVE_BIN = process.env.HIVE_BIN || path.join(SIBLINGS, 'hive-consensus', 'bin', 'hive.js')
|
|
34
|
+
const HIVE_TASKS_BIN = process.env.HIVE_TASKS_BIN || path.join(SIBLINGS, 'hive-tasks', 'bin', 'hive-tasks.js')
|
|
35
|
+
const DEMO_REPO = process.env.HIVE_DEMO_REPO || path.join(os.tmpdir(), 'hive-demo')
|
|
36
|
+
const EMPTY_REPO = process.env.HIVE_EMPTY_REPO || process.cwd()
|
|
31
37
|
|
|
32
38
|
/**
|
|
33
39
|
* Build the shim Context. `real: true` actually spawns bash; otherwise the
|