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.
@@ -22,6 +22,9 @@
22
22
  * 11. An initialised repo auto-enters queen mode from op=snapshot (source
23
23
  * "auto"), explicit off suppresses re-activation, queen-off is idempotent,
24
24
  * and config autoQueen=false leaves activation to name=queen-on.
25
+ * 12. The default Hive bins stay PATH names; a missing one is retried once
26
+ * through npx with the declared package, an explicit absolute bin is never
27
+ * replaced, and a total miss carries an install hint.
25
28
  */
26
29
  import assert from 'node:assert/strict'
27
30
  import { spawnSync } from 'node:child_process'
@@ -81,6 +84,10 @@ assert.ok(clientSource.includes('hiveSessionId'), 'the tab body never receives t
81
84
  assert.ok(clientSource.includes('messages: messages'), 'the inlined renderer does not expose its dictionaries')
82
85
  assert.ok(clientSource.includes('ctx.locale.register('), 'the client half never registers locale dictionaries')
83
86
  assert.ok(clientSource.includes('ctx.locale.bind('), 'the client half never binds the locale namespace')
87
+ assert.ok(clientSource.includes('uiWorkspace'), 'the client bundle never resolves workspace navigation')
88
+ assert.ok(clientSource.includes('hiveOpenSession'), 'the client bundle never forwards an open-session callback')
89
+ assert.ok(clientSource.includes('drawer.openChat'), 'the inlined renderer lost the Open agent chat copy')
90
+ assert.ok(clientSource.includes('boardError'), 'the inlined renderer lost the board diagnostic rendering')
84
91
  assert.equal(clientSource.includes('/hive-panel/api'), false, 'the retired proxy prefix is still in the bundle')
85
92
  assert.equal(clientSource.includes('7717'), false, 'the retired 7717 upstream is still in the bundle')
86
93
  ok('client bundle uses /api/hive and forwards the Session id')
@@ -114,9 +121,23 @@ const locale = {
114
121
  bind(ns) { localeBound.push(ns); return key => ({ 'view.label': 'Hive' })[key] ?? key },
115
122
  subscribe() { return () => {} },
116
123
  }
124
+ const openedSessions = []
125
+ const clientServices = {
126
+ sessions: {
127
+ subagentAddress(sessionId) {
128
+ return sessionId === 'child-1'
129
+ ? { parentSessionId: 'parent-1', childSessionId: 'child-1', mode: 'one-shot' }
130
+ : undefined
131
+ },
132
+ },
133
+ uiWorkspace: {
134
+ openSession(target) { openedSessions.push(target) },
135
+ },
136
+ }
117
137
  const clientEffects = []
118
138
  client.apply({
119
139
  effect(run) { const dispose = run(); clientEffects.push(dispose); return dispose },
140
+ get(name) { return clientServices[name] },
120
141
  locale,
121
142
  slots: {
122
143
  inject(name, run) { assert.equal(name, 'conversation.view'); return run() },
@@ -134,14 +155,42 @@ const injected = slots[0].config.inject('session-42')
134
155
  assert.equal(injected.hiveSessionId, 'session-42', 'the slot inject(sessionId) must reach the tab body')
135
156
  assert.equal(typeof injected.hiveTranslate, 'function')
136
157
  assert.equal(typeof injected.hiveLocaleSubscribe, 'function')
158
+ assert.equal(typeof injected.hiveOpenSession, 'function', 'a host with workspace navigation must receive the open-session callback')
159
+ injected.hiveOpenSession('child-1')
160
+ assert.deepEqual(openedSessions[0], {
161
+ parentSessionId: 'parent-1',
162
+ childSessionId: 'child-1',
163
+ mode: 'one-shot',
164
+ }, 'the callback forwards the catalog address when the client knows the child')
165
+ injected.hiveOpenSession('child-unknown')
166
+ assert.equal(openedSessions[1], 'child-unknown', 'an unknown-to-the-catalog child is opened by its bare Session id')
137
167
  const bodySource = String(slots[0].component)
138
168
  assert.ok(bodySource.includes('HIVE_PANEL.mount('), 'the tab body does not mount the shared renderer')
139
169
  assert.ok(bodySource.includes('hiveSessionId'), 'the tab body does not read the injected Session id')
140
170
  assert.ok(bodySource.includes('op=snapshot'), 'the tab body does not point at the native snapshot URL')
141
171
  assert.ok(bodySource.includes('op=action&name={name}'), 'the tab body does not point at the native action URL')
172
+ assert.ok(bodySource.includes('hiveOpenSession'), 'the tab body does not read the injected open-session callback')
173
+ assert.ok(bodySource.includes('openSession:'), 'the tab body does not forward openSession to the renderer mount')
142
174
  assert.deepEqual(Object.keys(localeRegistrations.map(entry => entry.dictionaries)[0]).sort(), ['en', 'zh'])
143
175
  ok('apply() registers a conversation.view tab with Session-scoped inject()')
144
176
 
177
+ // A host without workspace navigation gets no callback, so the renderer never
178
+ // renders its chat button (no disabled placeholder).
179
+ const bareSlots = []
180
+ client.apply({
181
+ effect(run) { return run() },
182
+ get() { return undefined },
183
+ locale,
184
+ slots: {
185
+ inject(name, run) { assert.equal(name, 'conversation.view'); return run() },
186
+ register(config, component) { bareSlots.push({ config, component }); return () => {} },
187
+ },
188
+ })
189
+ const bareInjected = bareSlots[0].config.inject('session-42')
190
+ assert.equal(bareInjected.hiveSessionId, 'session-42')
191
+ assert.equal(Object.hasOwn(bareInjected, 'hiveOpenSession'), false, 'a host without uiWorkspace must not receive openSession')
192
+ ok('a host without ctx.uiWorkspace gets no openSession callback')
193
+
145
194
  // ── 5. host surface: no proxy, one Connection Fetch route ───────────────────
146
195
  const hostSource = await readFile(files.host, 'utf8')
147
196
  for (const banned of ['webServer', '7717', 'node:http', 'node:https', 'createProxyHandler', 'resolveUpstream', 'buildUpstreamPath']) {
@@ -152,7 +201,7 @@ assert.equal(host.name, 'hive-panel')
152
201
  assert.equal(host.FETCH_PATH, '/api/hive')
153
202
  assert.deepEqual(host.inject, ['connection', 'sessions', 'workingDirectory', 'shell', 'agents', 'systemPrompt', 'commands'])
154
203
  assert.equal(host.ACTION_NAMES.length, 18)
155
- for (const name of ['init', 'add', 'plan', 'claim', 'done', 'fail', 'retry', 'block', 'renew', 'mode', 'learn', 'recall', 'verdict', 'run', 'commit', 'doctor', 'roles-add', 'remove']) {
204
+ for (const name of ['init', 'add', 'plan', 'claim', 'done', 'fail', 'retry', 'renew', 'mode', 'learn', 'recall', 'verdict', 'run', 'commit', 'doctor', 'roles-add', 'roles-remove', 'remove']) {
156
205
  assert.ok(host.ACTION_NAMES.includes(name), 'the allowlist is missing ' + name)
157
206
  }
158
207
  ok('host half has no proxy code; exports the native route + action allowlist')
@@ -305,14 +354,15 @@ async function call(route, { method = 'GET', query = {}, body } = {}) {
305
354
  assert.equal(outcome.body.writable, false)
306
355
  assert.equal(outcome.body.mode.mode, 'free')
307
356
  assert.deepEqual(outcome.body.board, [{ agent: 'w1', state: 'claimed', task: 'c1' }])
308
- assert.deepEqual(outcome.body.tasks, [{ id: 'c1', title: 'card one', state: 'pending', role: 'coder' }])
357
+ assert.equal(outcome.body.boardError, null, 'a successful board read carries no error')
358
+ assert.deepEqual(outcome.body.tasks, [{ id: 'c1', title: 'card one', state: 'pending', role: 'coder', lastRun: null }])
309
359
  assert.equal(outcome.body.stats.total, 1)
310
360
  assert.equal(outcome.body.events.length, 2)
311
361
  assert.equal(outcome.body.events[0].kind, 'task_done', 'events must be newest-first')
312
- for (const key of ['at', 'repo', 'initialised', 'mode', 'board', 'tasks', 'stats', 'events', 'writable', 'queen', 'roles']) {
362
+ for (const key of ['at', 'repo', 'initialised', 'mode', 'board', 'boardError', 'tasks', 'stats', 'events', 'writable', 'queen', 'roles']) {
313
363
  assert.ok(Object.prototype.hasOwnProperty.call(outcome.body, key), 'snapshot is missing ' + key)
314
364
  }
315
- assert.deepEqual(Object.keys(outcome.body).sort(), ['at', 'board', 'events', 'initialised', 'mode', 'queen', 'repo', 'roles', 'stats', 'tasks', 'writable'])
365
+ assert.deepEqual(Object.keys(outcome.body).sort(), ['at', 'board', 'boardError', 'events', 'initialised', 'mode', 'queen', 'repo', 'roles', 'stats', 'tasks', 'writable'])
316
366
  assert.deepEqual(outcome.body.queen, { active: true, source: 'auto', repo }, 'an initialised repo must auto-enter queen mode from the snapshot')
317
367
  assert.deepEqual(outcome.body.roles, {
318
368
  list: [
@@ -336,7 +386,48 @@ async function call(route, { method = 'GET', query = {}, body } = {}) {
336
386
  assert.ok(execution.command.startsWith("'hive'") || execution.command.startsWith("'hive-tasks'") || execution.command.startsWith("'git'"))
337
387
  }
338
388
  ok('GET op=snapshot runs fixed Hive CLI commands in the Session cwd under its sandbox policy')
339
- ok('snapshot keeps the { at, repo, initialised, mode, board, tasks, stats, events, writable, queen, roles } contract')
389
+ ok('snapshot keeps the { at, repo, initialised, mode, board, boardError, tasks, stats, events, writable, queen, roles } contract')
390
+ }
391
+
392
+ // ── 6d. a failed board read is a diagnostic, never a silent empty board ────
393
+ {
394
+ const failingBoard = createCtx({
395
+ live,
396
+ cwdOf,
397
+ shell: spec => {
398
+ if (spec.command.includes("'for-each-ref'")) return { exitCode: 0, stdout: 'refs/hive/v1/mode\n' }
399
+ if (spec.command.includes("'board'")) return { exitCode: 1, stderr: 'fatal: refs/hive/v1/board is unreadable\n' }
400
+ return defaultShellResult(spec)
401
+ },
402
+ })
403
+ host.apply(failingBoard.ctx, {})
404
+ const failed = await call(failingBoard.routes.get('/api/hive'), { query: { op: 'snapshot', sessionId: 's-live' } })
405
+ assert.equal(failed.status, 200, 'a board failure must not fail the whole snapshot')
406
+ assert.deepEqual(failed.body.board, [], 'a failed board read keeps the empty array for the board field')
407
+ assert.match(failed.body.boardError, /hive board exited 1/, 'the snapshot must name the failed command')
408
+ assert.match(failed.body.boardError, /board is unreadable/, 'the snapshot must keep the CLI stderr')
409
+ ok('a failed hive board read puts a diagnostic in boardError instead of a silent empty board')
410
+
411
+ const malformedBoard = createCtx({
412
+ live,
413
+ cwdOf,
414
+ shell: spec => {
415
+ if (spec.command.includes("'for-each-ref'")) return { exitCode: 0, stdout: 'refs/hive/v1/mode\n' }
416
+ if (spec.command.includes("'board'")) return { exitCode: 0, stdout: '{ not a board array' }
417
+ return defaultShellResult(spec)
418
+ },
419
+ })
420
+ host.apply(malformedBoard.ctx, {})
421
+ const malformed = await call(malformedBoard.routes.get('/api/hive'), { query: { op: 'snapshot', sessionId: 's-live' } })
422
+ assert.equal(malformed.status, 200)
423
+ assert.deepEqual(malformed.body.board, [])
424
+ assert.match(malformed.body.boardError, /no JSON/, 'malformed board JSON is diagnosed, not swallowed')
425
+ ok('malformed hive board JSON is diagnosed in boardError')
426
+
427
+ assert.match(host.snapshotReadError(undefined, 'hive board'), /did not run/)
428
+ assert.equal(host.snapshotReadError({ exitCode: 0, stdout: { text: '[]' } }, 'hive board'), null)
429
+ assert.deepEqual(host.parseBoardSnapshot({ exitCode: 0, stdout: { text: '[]' } }), { board: [], boardError: null })
430
+ assert.match(host.parseBoardSnapshot(undefined).boardError, /did not run/)
340
431
  }
341
432
 
342
433
  // ── 6b. uninitialised repo: no Hive CLI fan-out ─────────────────────────────
@@ -359,6 +450,70 @@ async function call(route, { method = 'GET', query = {}, body } = {}) {
359
450
  ok('an uninitialised repo returns the empty contract after only the refs probe')
360
451
  }
361
452
 
453
+ // ── 6c. per-card lastRun from .hive/runs/<id>.json ─────────────────────────
454
+ {
455
+ const runsRepo = join(fixture, 'runs-repo')
456
+ mkdirSync(join(runsRepo, '.hive', 'runs'), { recursive: true })
457
+ const doneRecord = {
458
+ cardId: 'c1',
459
+ agent: 'dsh',
460
+ startedAt: '2026-12-04T00:00:00.000Z',
461
+ endedAt: '2026-12-04T00:05:00.000Z',
462
+ status: 'done',
463
+ exitCode: 0,
464
+ commit: 'abcdef1234567890',
465
+ sessionId: 'child-1',
466
+ agentName: 'lead/agent-1',
467
+ output: 'worker output\n',
468
+ }
469
+ // A pre-0.6.4 record has no worker identity; it must keep its exact shape.
470
+ const legacyRecord = {
471
+ cardId: 'c4',
472
+ agent: 'dsh',
473
+ startedAt: '2026-12-04T00:06:00.000Z',
474
+ endedAt: '2026-12-04T00:07:00.000Z',
475
+ status: 'failed',
476
+ exitCode: 1,
477
+ output: 'legacy output\n',
478
+ }
479
+ writeFileSync(join(runsRepo, '.hive', 'runs', 'c1.json'), JSON.stringify(doneRecord))
480
+ writeFileSync(join(runsRepo, '.hive', 'runs', 'c4.json'), JSON.stringify(legacyRecord))
481
+ writeFileSync(join(runsRepo, '.hive', 'runs', 'c2.json'), '{ not json')
482
+ const runShim = createCtx({
483
+ live: new Map([['s-runs', { id: 's-runs', header: { id: 's-runs', cwd: runsRepo } }]]),
484
+ shell: spec => {
485
+ const command = spec.command
486
+ if (command.includes("'list'") && !command.includes("'roles'")) {
487
+ return {
488
+ exitCode: 0,
489
+ stdout: JSON.stringify([
490
+ { id: 'c1', title: 'ran once', state: 'done', role: 'coder' },
491
+ { id: 'c2', title: 'corrupt record', state: 'failed', role: 'coder' },
492
+ { id: 'c3', title: 'never ran', state: 'pending', role: 'coder' },
493
+ { id: '../escape', title: 'traversal attempt', state: 'pending', role: 'coder' },
494
+ { id: 'c4', title: 'legacy record', state: 'failed', role: 'coder' },
495
+ ]),
496
+ }
497
+ }
498
+ return defaultShellResult(spec)
499
+ },
500
+ })
501
+ host.apply(runShim.ctx, {})
502
+ const outcome = await call(runShim.routes.get('/api/hive'), { query: { op: 'snapshot', sessionId: 's-runs' } })
503
+ assert.equal(outcome.status, 200)
504
+ const [ran, corrupt, never, unsafe, legacy] = outcome.body.tasks
505
+ assert.deepEqual(ran.lastRun, doneRecord, 'a valid record is attached verbatim under lastRun')
506
+ assert.equal(ran.lastRun.sessionId, 'child-1', 'the worker Session id must reach the panel snapshot')
507
+ assert.equal(ran.lastRun.agentName, 'lead/agent-1', 'the worker name must reach the panel snapshot')
508
+ assert.equal(corrupt.lastRun, null, 'a corrupt record degrades to null instead of failing the snapshot')
509
+ assert.equal(never.lastRun, null, 'a card without a record gets lastRun null')
510
+ assert.equal(unsafe.lastRun, null, 'a card id that is not a safe token never reads outside .hive/runs')
511
+ assert.deepEqual(legacy.lastRun, legacyRecord, 'a record without worker identity keeps its exact previous shape')
512
+ assert.equal(Object.hasOwn(legacy.lastRun, 'sessionId'), false, 'a legacy record must not gain a sessionId key')
513
+ assert.equal(host.RUNS_DIR, join('.hive', 'runs'))
514
+ ok('each snapshot card carries lastRun read from .hive/runs/<id>.json; worker sessionId/agentName pass through, corrupt/missing/unsafe ids degrade to null')
515
+ }
516
+
362
517
  // ── 7. cold session + unknown session ───────────────────────────────────────
363
518
  {
364
519
  const shim = createCtx({
@@ -390,6 +545,7 @@ async function call(route, { method = 'GET', query = {}, body } = {}) {
390
545
  assert.ok(catalog.body.actions.includes('queen-on'))
391
546
  assert.ok(catalog.body.actions.includes('queen-off'))
392
547
  assert.ok(catalog.body.actions.includes('roles-add'))
548
+ assert.ok(catalog.body.actions.includes('roles-remove'))
393
549
  assert.ok(catalog.body.actions.includes('remove'))
394
550
  assert.equal(catalog.body.actions.length, 20)
395
551
  const unknown = await call(route, { query: { op: 'nope', sessionId: 's-live' } })
@@ -602,6 +758,63 @@ async function call(route, { method = 'GET', query = {}, body } = {}) {
602
758
  ok('remove sends hive tasks rm through the router, validates the card id and passes stderr through')
603
759
  }
604
760
 
761
+ // ── 10e. roles-remove action ───────────────────────────────────────────────
762
+ {
763
+ const shim = createCtx({
764
+ live,
765
+ cwdOf,
766
+ shell: spec => {
767
+ if (spec.command.includes("'roles'") && spec.command.includes("'rm'")) {
768
+ if (spec.command.includes("'ghost'")) {
769
+ return { exitCode: 2, stderr: 'hive roles: role "ghost" not found in .hive/roles.yaml\n' }
770
+ }
771
+ return { exitCode: 0, stdout: 'removed role reviewer from .hive/roles.yaml\nkept .hive/roles/reviewer.md (pass --keep-file to silence)\n' }
772
+ }
773
+ return defaultShellResult(spec)
774
+ },
775
+ })
776
+ host.apply(shim.ctx, { writable: true })
777
+ const route = shim.routes.get('/api/hive')
778
+ const removed = await call(route, { method: 'POST', query: { op: 'action', name: 'roles-remove', sessionId: 's-live' }, body: { name: 'reviewer' } })
779
+ assert.equal(removed.status, 200)
780
+ assert.deepEqual(removed.body, {
781
+ ok: true,
782
+ code: 0,
783
+ stdout: 'removed role reviewer from .hive/roles.yaml\nkept .hive/roles/reviewer.md (pass --keep-file to silence)\n',
784
+ stderr: '',
785
+ })
786
+ const execution = shim.executions.at(-1)
787
+ assert.equal(execution.command, "'hive' 'roles' 'rm' 'reviewer'", 'roles-remove must call hive roles rm')
788
+ assert.equal(execution.command.includes('--force'), false, 'roles-remove must never send --force')
789
+ assert.equal(execution.command.includes('--keep-file'), false, 'roles-remove must never send --keep-file')
790
+ assert.equal(execution.workdir, repo, 'roles-remove must run in the Session repository')
791
+ assert.deepEqual(execution.sandboxPolicy, { mode: 'workspace-write', workspaceRoot: repo, sessionId: 's-live' })
792
+ assert.equal(host.commandForAction('roles-remove', { name: 'reviewer' }), "'hive' 'roles' 'rm' 'reviewer'")
793
+
794
+ const before = shim.executions.length
795
+ for (const body of [{}, { name: 'Reviewer' }, { name: 'a' }, { name: 'x; rm -rf /' }, { name: 'a'.repeat(33) }]) {
796
+ const rejected = await call(route, { method: 'POST', query: { op: 'action', name: 'roles-remove', sessionId: 's-live' }, body })
797
+ assert.equal(rejected.status, 400, 'roles-remove must reject ' + JSON.stringify(body))
798
+ assert.equal(rejected.body.ok, false)
799
+ assert.equal(rejected.body.code, 2)
800
+ assert.match(rejected.body.stderr, /^hive\/invalid-argument: /)
801
+ }
802
+ assert.equal(shim.executions.length, before, 'a rejected roles-remove must not spawn anything')
803
+
804
+ // A missing role is a normal CLI refusal: exit 2 + stderr pass through unchanged.
805
+ const missing = await call(route, { method: 'POST', query: { op: 'action', name: 'roles-remove', sessionId: 's-live' }, body: { name: 'ghost' } })
806
+ assert.equal(missing.status, 400)
807
+ assert.deepEqual(missing.body, { ok: false, code: 2, stdout: '', stderr: 'hive roles: role "ghost" not found in .hive/roles.yaml\n' })
808
+
809
+ const readonly = createCtx({ live, cwdOf })
810
+ host.apply(readonly.ctx, {})
811
+ const denied = await call(readonly.routes.get('/api/hive'), { method: 'POST', query: { op: 'action', name: 'roles-remove', sessionId: 's-live' }, body: { name: 'reviewer' } })
812
+ assert.equal(denied.status, 403)
813
+ assert.deepEqual(denied.body, { ok: false, code: 2, stdout: '', stderr: 'read-only: hive-panel writable=false' })
814
+ assert.equal(readonly.executions.length, 0)
815
+ ok('roles-remove sends hive roles rm, rejects bad names, requires writable and passes CLI stderr through')
816
+ }
817
+
605
818
  // ── 11. fail loud without ctx.shell ─────────────────────────────────────────
606
819
  {
607
820
  const shim = createCtx({ live, cwdOf, shell: null })
@@ -754,6 +967,64 @@ async function call(route, { method = 'GET', query = {}, body } = {}) {
754
967
  ok('queen state is in-memory only (no custom session event is appended)')
755
968
  }
756
969
 
970
+ // ── 14. PATH -> npx fallback for the default Hive binaries ─────────────────
971
+ {
972
+ assert.deepEqual(host.DEFAULT_BINS, { hive: 'hive', tasks: 'hive-tasks', run: 'hive-run', moc: 'moc' })
973
+ assert.deepEqual(
974
+ host.npxInvocation('tasks', ['list', '--json']),
975
+ ['-y', '-p', 'hive-tasks', 'hive-tasks', 'list', '--json'],
976
+ )
977
+ assert.match(host.npxInvocation('hive', ['board', '--json']).join(' '), /-p @d86e\/hive -p hive-consensus/)
978
+ assert.equal(host.fallbackCommandForBin('tasks', ['list'], { tasks: '/abs/hive-tasks.js' }), null, 'an explicit absolute bin must never be replaced')
979
+ assert.equal(
980
+ host.fallbackCommandForBin('tasks', ['list', '--json']),
981
+ "'npx' '-y' '-p' 'hive-tasks' 'hive-tasks' 'list' '--json'",
982
+ )
983
+ ok('DEFAULT_BINS stay PATH names; only a bare name gets the npx fallback')
984
+
985
+ // A shell without hive-tasks/hive on PATH: every first attempt exits 127 and
986
+ // the host retries the same argv once through npx.
987
+ const shim = createCtx({
988
+ live,
989
+ cwdOf,
990
+ shell: spec => {
991
+ if (spec.command.startsWith("'npx'")) return defaultShellResult(spec)
992
+ if (spec.command.includes("'for-each-ref'")) return { exitCode: 0, stdout: 'refs/hive/v1/mode\n' }
993
+ if (spec.command.includes("'cat-file'")) return { exitCode: 0, stdout: '{"v":1,"mode":"free"}' }
994
+ return { exitCode: 127, stderr: 'bash: line 1: hive: command not found' }
995
+ },
996
+ })
997
+ host.apply(shim.ctx, {})
998
+ const route = shim.routes.get('/api/hive')
999
+ const outcome = await call(route, { query: { op: 'snapshot', sessionId: 's-live' } })
1000
+ assert.equal(outcome.status, 200)
1001
+ assert.equal(outcome.body.initialised, true)
1002
+ const commands = shim.executions.map(entry => entry.command)
1003
+ assert.ok(commands.includes("'npx' '-y' '-p' 'hive-tasks' 'hive-tasks' 'list' '--json'"), 'snapshot must retry hive-tasks through npx')
1004
+ assert.ok(commands.includes("'hive' 'board' '--json'"), 'snapshot must try the PATH name first')
1005
+ assert.ok(commands.some(command => command.startsWith("'npx' '-y' '-p' '@d86e/hive'")), 'snapshot must retry hive through npx')
1006
+ ok('a missing PATH bin is retried once through npx -y -p <package>')
1007
+
1008
+ // An explicit absolute bin is the operator's choice: no npx substitution, and
1009
+ // the failure carries the install hint instead.
1010
+ const pinned = createCtx({
1011
+ live,
1012
+ cwdOf,
1013
+ shell: spec => {
1014
+ if (spec.command.includes("'for-each-ref'")) return { exitCode: 0, stdout: 'refs/hive/v1/mode\n' }
1015
+ if (spec.command.includes("'cat-file'")) return { exitCode: 0, stdout: '{"v":1,"mode":"free"}' }
1016
+ return { exitCode: 127, stderr: 'bash: /abs/hive: No such file or directory' }
1017
+ },
1018
+ })
1019
+ host.apply(pinned.ctx, { bins: { hive: '/abs/hive', tasks: '/abs/hive-tasks' } })
1020
+ const pinnedRoute = pinned.routes.get('/api/hive')
1021
+ const pinnedSnapshot = await call(pinnedRoute, { query: { op: 'snapshot', sessionId: 's-live' } })
1022
+ assert.equal(pinnedSnapshot.status, 200)
1023
+ assert.equal(pinned.executions.some(entry => entry.command.startsWith("'npx'")), false, 'an absolute bin must not be replaced by npx')
1024
+ assert.match(pinnedSnapshot.body.roles.error, /not found on the PATH of the DSH shell/)
1025
+ ok('an explicit absolute bin is never replaced; its failure carries the install hint')
1026
+ }
1027
+
757
1028
  rmSync(fixture, { recursive: true, force: true })
758
1029
 
759
1030
  console.log('\n' + String(results.length) + ' checks passed')
@@ -13,6 +13,12 @@
13
13
  * Transport: same-origin, cookie-authenticated Connection Fetch route
14
14
  * `/api/hive` (GET snapshot/actions, POST action). No separate service, no
15
15
  * proxy port, no client-side cwd.
16
+ *
17
+ * Opening a worker's chat is a client navigation, not an HTTP route: the mount
18
+ * option `openSession(sessionId)` is implemented below with the same
19
+ * `ctx.uiWorkspace.openSession()` call the header's subagent catalog makes. A
20
+ * host without that service receives no callback, so the renderer renders no
21
+ * "Open agent chat" button.
16
22
  */
17
23
  window.__ModuleLoader__.load({
18
24
  id: 'dsh-hive-panel',
@@ -23,6 +29,46 @@ window.__ModuleLoader__.load({
23
29
  const HIVE_API_PREFIX = '/api/hive'
24
30
  const HIVE_NS = 'hive-panel'
25
31
 
32
+ /**
33
+ * Resolve one optional client service without hard-depending on it, so the
34
+ * panel still loads in profiles that do not mount workspace navigation.
35
+ */
36
+ function clientService(ctx, name) {
37
+ return typeof ctx.get === 'function' ? ctx.get(name) : undefined;
38
+ }
39
+
40
+ /** Whether this host exposes the Workspace navigation API. */
41
+ function canOpenSession(ctx) {
42
+ const navigation = clientService(ctx, 'uiWorkspace');
43
+ return navigation !== undefined && typeof navigation.openSession === 'function';
44
+ }
45
+
46
+ /**
47
+ * Open the Session a Hive worker ran in. This mirrors one click on a row of
48
+ * the conversation header's subagent catalog: the client selection changes
49
+ * through ctx.uiWorkspace.openSession(target); there is no /session/<id>
50
+ * route to push. A SubagentAddress carries the breadcrumb facts when the
51
+ * catalog or Session list already knows the child; a bare id is enough
52
+ * otherwise because the client resolves it against the host Session list.
53
+ */
54
+ function openSession(ctx, sessionId) {
55
+ if (typeof sessionId !== 'string' || sessionId === '') return;
56
+ const navigation = clientService(ctx, 'uiWorkspace');
57
+ if (navigation === undefined || typeof navigation.openSession !== 'function') {
58
+ console.warn('[hive-panel] uiWorkspace.openSession is unavailable; cannot open the worker chat');
59
+ return;
60
+ }
61
+ const sessions = clientService(ctx, 'sessions');
62
+ const address = typeof sessions?.subagentAddress === 'function'
63
+ ? sessions.subagentAddress(sessionId)
64
+ : undefined;
65
+ try {
66
+ navigation.openSession(address === undefined ? sessionId : address);
67
+ } catch (error) {
68
+ console.warn('[hive-panel] opening the worker Session failed:', error);
69
+ }
70
+ }
71
+
26
72
  /* __HIVE_PANEL_MODULE__ */
27
73
 
28
74
  // The slot config declares the dictionary namespace and passes the bound
@@ -42,6 +88,11 @@ window.__ModuleLoader__.load({
42
88
  hiveSessionId: typeof sessionId === 'string' ? sessionId : '',
43
89
  hiveTranslate: t,
44
90
  hiveLocaleSubscribe: (listener) => ctx.locale.subscribe(listener),
91
+ // Only a host with client navigation receives the callback, so the
92
+ // renderer renders no chat button anywhere else (no disabled stub).
93
+ ...(canOpenSession(ctx)
94
+ ? { hiveOpenSession: (childSessionId) => { openSession(ctx, childSessionId) } }
95
+ : {}),
45
96
  }),
46
97
  }, HivePanelMount))
47
98
  }