dsh-hive-panel 0.2.0 → 0.3.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/index.js CHANGED
@@ -238,6 +238,49 @@ export function parseJson(text, fallback) {
238
238
  }
239
239
  }
240
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
+
241
284
  /** The bin key behind each snapshot command. */
242
285
  export const SNAPSHOT_BINS = Object.freeze({
243
286
  board: 'hive',
@@ -381,10 +424,12 @@ export function lastRunPath(cwd, cardId) {
381
424
  * out-of-contract files all degrade to null: a broken record never breaks the
382
425
  * snapshot. A record written by a worker activation also carries that worker's
383
426
  * `sessionId` (and its `agentName`); both are forwarded only when present so a
384
- * legacy record keeps its exact previous shape.
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.
385
430
  * @param {string} cwd - repository root.
386
431
  * @param {unknown} cardId - card id from the task list.
387
- * @returns {null|{ cardId: string, agent: string, startedAt: string|null, endedAt: string|null, status: 'done'|'failed'|'running', exitCode?: number, commit?: string, sessionId?: string, agentName?: string, output: string }}
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 }}
388
433
  */
389
434
  export function readLastRun(cwd, cardId) {
390
435
  const file = lastRunPath(cwd, cardId)
@@ -416,6 +461,13 @@ export function readLastRun(cwd, cardId) {
416
461
  // Worker chat identity: forwarded verbatim, omitted on pre-0.6.4 records.
417
462
  if (typeof parsed.sessionId === 'string' && parsed.sessionId !== '') record.sessionId = parsed.sessionId
418
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
+ }
419
471
  return record
420
472
  }
421
473
 
@@ -465,6 +517,19 @@ function optionalNumber(value, field, min, max, fallback) {
465
517
  return number
466
518
  }
467
519
 
520
+ /**
521
+ * Plan size: a whole number of 0 or more; 0 means the planner has no card
522
+ * cap, so it must reach `--max-cards` unchanged. Empty/omitted = 50.
523
+ */
524
+ function planMaxCards(value) {
525
+ if (value === undefined || value === null || value === '') return 50
526
+ const number = typeof value === 'number' ? value : Number(value)
527
+ if (!Number.isSafeInteger(number) || number < 0) {
528
+ throw invalid('maxCards', 'must be an integer of 0 or more (0 = unlimited)')
529
+ }
530
+ return number
531
+ }
532
+
468
533
  function idArg(value, field = 'id') {
469
534
  const text = requiredString(value, field, 128)
470
535
  if (!ID_RE.test(text)) throw invalid(field, 'must match ' + String(ID_RE))
@@ -567,7 +632,7 @@ const ACTION_BUILDERS = Object.freeze({
567
632
  return { bin: 'tasks', argv }
568
633
  },
569
634
  plan: payload => {
570
- const argv = ['plan', '--goal', requiredString(payload.goal, 'goal', 4000), '--max-cards', String(optionalNumber(payload.maxCards, 'maxCards', 1, 64, 8))]
635
+ const argv = ['plan', '--goal', requiredString(payload.goal, 'goal', 4000), '--max-cards', String(planMaxCards(payload.maxCards))]
571
636
  if (payload.apply === true) argv.push('--apply')
572
637
  return { bin: 'run', argv }
573
638
  },
@@ -903,6 +968,32 @@ export function createBridge(ctx, config = {}) {
903
968
  }
904
969
  }
905
970
 
971
+ /**
972
+ * Register the queen Session with the resident Hive runner (when mounted).
973
+ * The runner parents every card worker to exactly this Session; before this
974
+ * registration it waits instead of dispatching. Registration is in-memory and
975
+ * idempotent, so every panel snapshot re-registers after a restart.
976
+ * @param {string} sessionId live Session id of the queen conversation
977
+ */
978
+ function registerQueenSession(sessionId) {
979
+ if (typeof sessionId !== 'string' || sessionId === '') return false
980
+ let runner
981
+ try {
982
+ runner = ctx.get('hiveSupervisor')
983
+ } catch (error) {
984
+ log('hive-runner queen registration lookup failed', error)
985
+ return false
986
+ }
987
+ if (runner === undefined || typeof runner.setQueenSession !== 'function') return false
988
+ try {
989
+ runner.setQueenSession(sessionId)
990
+ return true
991
+ } catch (error) {
992
+ log('hive-runner queen registration failed', error)
993
+ return false
994
+ }
995
+ }
996
+
906
997
  /**
907
998
  * Auto-activate queen mode for an initialised Session before a snapshot is
908
999
  * returned. Idempotent: the controller does not rewrite an active session and
@@ -956,6 +1047,7 @@ export function createBridge(ctx, config = {}) {
956
1047
  initialised: false,
957
1048
  mode: { mode: 'free' },
958
1049
  board: [],
1050
+ boardError: null,
959
1051
  tasks: [],
960
1052
  stats: null,
961
1053
  events: [],
@@ -967,6 +1059,7 @@ export function createBridge(ctx, config = {}) {
967
1059
  const initialised = refs !== undefined && refs.exitCode === 0 && String(refs.stdout?.text ?? '').trim() !== ''
968
1060
  if (initialised) autoActivateQueen(sessionId, cwd)
969
1061
  payload.queen = queenSnapshot(sessionId, cwd)
1062
+ if (payload.queen.active) registerQueenSession(sessionId)
970
1063
  if (!initialised) {
971
1064
  payload.events = readEvents(cwd)
972
1065
  return payload
@@ -980,11 +1073,13 @@ export function createBridge(ctx, config = {}) {
980
1073
  tryExecute(SNAPSHOT_READS.mode, { cwd, session, timeoutMs: PROBE_TIMEOUT_MS, signal }),
981
1074
  tryExecuteWithFallback(commands.roles, fallbacks.roles, { cwd, session, timeoutMs: snapshotTimeoutMs, signal }, 'hive'),
982
1075
  ])
1076
+ const boardRead = parseBoardSnapshot(board)
983
1077
  return {
984
1078
  ...payload,
985
1079
  initialised: true,
986
1080
  mode: readMode(mode),
987
- board: parseJson(board?.stdout?.text, []),
1081
+ board: boardRead.board,
1082
+ boardError: boardRead.boardError,
988
1083
  tasks: attachLastRuns(cwd, parseJson(tasks?.stdout?.text, [])),
989
1084
  stats: parseJson(stats?.stdout?.text, null),
990
1085
  events: readEvents(cwd),
@@ -1028,6 +1123,7 @@ export function createBridge(ctx, config = {}) {
1028
1123
  if (refs === undefined || refs.exitCode !== 0 || String(refs.stdout?.text ?? '').trim() === '') return false
1029
1124
  try {
1030
1125
  queen.mark({ sessionId, cwd })
1126
+ registerQueenSession(sessionId)
1031
1127
  return true
1032
1128
  } catch (error) {
1033
1129
  log('queen activation failed', error)
@@ -1047,6 +1143,7 @@ export function createBridge(ctx, config = {}) {
1047
1143
  throw new HiveRequestError('hive/queen-unavailable', 'queen controller is unavailable', 500)
1048
1144
  }
1049
1145
  queen.mark({ sessionId, cwd, source: 'manual' })
1146
+ registerQueenSession(sessionId)
1050
1147
  return { status: 200, body: { ok: true, code: 0, stdout: '', stderr: '' } }
1051
1148
  }
1052
1149
  if (actionName === QUEEN_OFF_ACTION) {
package/lib/queen.js CHANGED
@@ -22,7 +22,7 @@
22
22
  * history, so compaction cannot shadow it.
23
23
  *
24
24
  * The workspace role file is LOW-TRUST: the injected text names its absolute
25
- * source path, says it is untrusted, and is capped at 4096 characters
25
+ * source path, says it is untrusted, and is capped at 16384 characters
26
26
  * (annotation included).
27
27
  *
28
28
  * @module dsh-hive-panel/queen
@@ -37,7 +37,7 @@ export const QUEEN_SECTION = 'hive:queen'
37
37
  export const QUEEN_ORDER = 520
38
38
 
39
39
  /** Hard cap for the injected role text, annotation included. */
40
- export const QUEEN_MAX_CHARS = 4096
40
+ export const QUEEN_MAX_CHARS = 16384
41
41
 
42
42
  /** Workspace-relative role file written by `hive init`. */
43
43
  export const QUEEN_ROLE_PATH = path.join('.hive', 'roles', 'queen.md')
@@ -51,10 +51,10 @@ export const QUEEN_SOURCE_AUTO = 'auto'
51
51
  export const QUEEN_SOURCE_MANUAL = 'manual'
52
52
 
53
53
  /** Built-in role used when the workspace file is missing or unreadable. */
54
- export const QUEEN_FALLBACK_ROLE = '# Queen\n\nYou plan, you do not code. Split goals into cards; do not edit files or commit.\n'
54
+ export const QUEEN_FALLBACK_ROLE = '# Queen\n\nYou plan and coordinate; you never write code. Split work into fine-grained cards that each carry an acceptance command, then order, supervise, review and report. Load the hive-queen skill for the full responsibility matrix and commands. Do not edit code, do not commit, do not claim or finish cards.\n'
55
55
 
56
56
  /** Short exit hint appended to every rendered role. */
57
- export const QUEEN_EXIT_HINT = '\n\n[hive] Queen mode: plan and split cards only; do not edit code or commit. Exit with /queen off.'
57
+ export const QUEEN_EXIT_HINT = '\n\n[hive] Queen mode: plan, split, order, supervise, review, report; never edit code or commit. Fine-grained cards; every card needs an acceptance command. Load the hive-queen skill. Exit with /queen off.'
58
58
 
59
59
  /**
60
60
  * Build the injected prompt text for one Session.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-hive-panel",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
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",
@@ -46,7 +46,7 @@ function makeCtx({ agents, cwdOf, shell }) {
46
46
  }
47
47
 
48
48
  // ── the documented reference implementation (mirrors QUEEN-ACTIVATION §1) ─────
49
- const EXIT_HINT = '\n\n女王模式规则:只规划、拆卡;不改代码、不 commit。退出:/queen off。'
49
+ const EXIT_HINT = '\n\n[hive] Queen mode: plan, split, order, supervise, review, report; never edit code or commit. Fine-grained cards; every card needs an acceptance command. Load the hive-queen skill. Exit with /queen off.'
50
50
 
51
51
  function createQueen(ctx) {
52
52
  const queen = new Map()
@@ -85,7 +85,7 @@ function createQueen(ctx) {
85
85
 
86
86
  function readRole(cwd) {
87
87
  const file = path.join(cwd, '.hive/roles/queen.md')
88
- return fs.existsSync(file) ? fs.readFileSync(file, 'utf8') : '# Queen\n\nYou plan, you do not code.'
88
+ return fs.existsSync(file) ? fs.readFileSync(file, 'utf8') : '# Queen\n\nYou plan and coordinate; you never write code.'
89
89
  }
90
90
 
91
91
  async function ensureInitialised(ctx, agent) {
@@ -100,7 +100,7 @@ async function ensureInitialised(ctx, agent) {
100
100
  // ── fixture + checks ─────────────────────────────────────────────────────────
101
101
  const repo = fs.mkdtempSync(path.join(os.tmpdir(), 'queen-activation-'))
102
102
  fs.mkdirSync(path.join(repo, '.hive/roles'), { recursive: true })
103
- fs.writeFileSync(path.join(repo, '.hive/roles/queen.md'), '# Queen\n\nYou plan, you do not code.\n')
103
+ fs.writeFileSync(path.join(repo, '.hive/roles/queen.md'), '# Queen\n\nYou plan and coordinate; you never write code. Split work into fine-grained cards.\n')
104
104
  const shellState = { initialised: false, initExit: 0 }
105
105
  const agents = new Map([['s1', { id: 's1', session: { id: 's1' } }], ['s2', { id: 's2', session: { id: 's2' } }]])
106
106
  const ctx = makeCtx({ agents: { get: id => agents.get(id) }, cwdOf: () => repo, shell: makeShell(shellState) })
@@ -118,7 +118,8 @@ assert.equal(queen.queen.size, 0, 'failed verification must not activate')
118
118
  shellState.initialised = true
119
119
  await queen.enter(agents.get('s1'))
120
120
  const text = textFor('s1')
121
- assert.match(text, /You plan, you do not code/)
121
+ assert.match(text, /You plan and coordinate/)
122
+ assert.ok(text.includes('Fine-grained cards; every card needs an acceptance command.'))
122
123
  assert.ok(text.includes('/queen off'))
123
124
  assert.equal(textFor('s2'), '')
124
125
  console.log('ok 2 - enter() verifies refs/hive/v1 and renders .hive/roles/queen.md from the next assembly')
@@ -87,6 +87,7 @@ assert.ok(clientSource.includes('ctx.locale.bind('), 'the client half never bind
87
87
  assert.ok(clientSource.includes('uiWorkspace'), 'the client bundle never resolves workspace navigation')
88
88
  assert.ok(clientSource.includes('hiveOpenSession'), 'the client bundle never forwards an open-session callback')
89
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')
90
91
  assert.equal(clientSource.includes('/hive-panel/api'), false, 'the retired proxy prefix is still in the bundle')
91
92
  assert.equal(clientSource.includes('7717'), false, 'the retired 7717 upstream is still in the bundle')
92
93
  ok('client bundle uses /api/hive and forwards the Session id')
@@ -209,7 +210,7 @@ ok('host half has no proxy code; exports the native route + action allowlist')
209
210
  const fixture = mkdtempSync(join(os.tmpdir(), 'dsh-hive-panel-'))
210
211
  const repo = join(fixture, 'repo')
211
212
  mkdirSync(join(repo, '.hive', 'roles'), { recursive: true })
212
- writeFileSync(join(repo, '.hive', 'roles', 'queen.md'), '# Queen\n\nYou plan, you do not code.\n')
213
+ writeFileSync(join(repo, '.hive', 'roles', 'queen.md'), '# Queen\n\nYou plan and coordinate; you never write code. Split work into fine-grained cards.\n')
213
214
  writeFileSync(join(repo, '.hive', 'events.jsonl'), '{"ts":"2026-01-01T00:00:00.000Z","kind":"task_add","task":"c1","actor":"w1"}\n{"ts":"2026-01-02T00:00:00.000Z","kind":"task_done","task":"c1","actor":"w1"}\n')
214
215
  writeFileSync(join(repo, '.hive', 'limits.json'), JSON.stringify({ coder: 2, tester: 0 }))
215
216
  const other = join(fixture, 'other')
@@ -353,14 +354,15 @@ async function call(route, { method = 'GET', query = {}, body } = {}) {
353
354
  assert.equal(outcome.body.writable, false)
354
355
  assert.equal(outcome.body.mode.mode, 'free')
355
356
  assert.deepEqual(outcome.body.board, [{ agent: 'w1', state: 'claimed', task: 'c1' }])
357
+ assert.equal(outcome.body.boardError, null, 'a successful board read carries no error')
356
358
  assert.deepEqual(outcome.body.tasks, [{ id: 'c1', title: 'card one', state: 'pending', role: 'coder', lastRun: null }])
357
359
  assert.equal(outcome.body.stats.total, 1)
358
360
  assert.equal(outcome.body.events.length, 2)
359
361
  assert.equal(outcome.body.events[0].kind, 'task_done', 'events must be newest-first')
360
- 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']) {
361
363
  assert.ok(Object.prototype.hasOwnProperty.call(outcome.body, key), 'snapshot is missing ' + key)
362
364
  }
363
- 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'])
364
366
  assert.deepEqual(outcome.body.queen, { active: true, source: 'auto', repo }, 'an initialised repo must auto-enter queen mode from the snapshot')
365
367
  assert.deepEqual(outcome.body.roles, {
366
368
  list: [
@@ -384,7 +386,48 @@ async function call(route, { method = 'GET', query = {}, body } = {}) {
384
386
  assert.ok(execution.command.startsWith("'hive'") || execution.command.startsWith("'hive-tasks'") || execution.command.startsWith("'git'"))
385
387
  }
386
388
  ok('GET op=snapshot runs fixed Hive CLI commands in the Session cwd under its sandbox policy')
387
- 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/)
388
431
  }
389
432
 
390
433
  // ── 6b. uninitialised repo: no Hive CLI fan-out ─────────────────────────────
@@ -551,6 +594,32 @@ async function call(route, { method = 'GET', query = {}, body } = {}) {
551
594
  ok('actions validate every argument, quote argv tokens, and keep { ok, code, stdout, stderr }')
552
595
  }
553
596
 
597
+ // ── 9b. plan max-cards: 50 default, 0 = unlimited ───────────────────────────
598
+ {
599
+ assert.equal(
600
+ host.commandForAction('plan', { goal: 'ship it' }),
601
+ "'hive-run' 'plan' '--goal' 'ship it' '--max-cards' '50'",
602
+ 'plan must default to 50 cards',
603
+ )
604
+ assert.equal(
605
+ host.commandForAction('plan', { goal: 'ship it', maxCards: 0 }),
606
+ "'hive-run' 'plan' '--goal' 'ship it' '--max-cards' '0'",
607
+ 'maxCards=0 (unlimited) must reach argv unchanged',
608
+ )
609
+ assert.equal(
610
+ host.commandForAction('plan', { goal: 'ship it', maxCards: 8 }),
611
+ "'hive-run' 'plan' '--goal' 'ship it' '--max-cards' '8'",
612
+ )
613
+ for (const maxCards of [-1, 1.5, 'many']) {
614
+ assert.throws(
615
+ () => host.commandForAction('plan', { goal: 'ship it', maxCards }),
616
+ /0 or more/,
617
+ 'plan must reject maxCards ' + String(maxCards),
618
+ )
619
+ }
620
+ ok('plan defaults --max-cards to 50 and forwards 0 (unlimited) unchanged')
621
+ }
622
+
554
623
  // ── 10. action failure keeps the same envelope ──────────────────────────────
555
624
  {
556
625
  const shim = createCtx({
@@ -793,6 +862,11 @@ async function call(route, { method = 'GET', query = {}, body } = {}) {
793
862
  const queenSection = shim.sections.find(section => section.name === 'hive:queen')
794
863
  assert.ok(queenSection, 'the hive:queen system-prompt section is not registered')
795
864
  assert.equal(queenSection.order, 520)
865
+ const queenModule = await import(pathToFileURL(files.queen).href + '?verify=' + Date.now())
866
+ assert.equal(queenModule.QUEEN_MAX_CHARS, 16384, 'the injected role text cap must be 16384 characters')
867
+ assert.match(queenModule.QUEEN_FALLBACK_ROLE, /You plan and coordinate; you never write code/)
868
+ assert.match(queenModule.QUEEN_FALLBACK_ROLE, /Load the hive-queen skill/)
869
+ assert.ok(queenModule.QUEEN_EXIT_HINT.includes('Exit with /queen off.'))
796
870
  const agent = { session: { id: 's-live' } }
797
871
  const otherAgent = { session: { id: 's-other' } }
798
872
  assert.equal(queenSection.text({ agent }), '')
@@ -800,10 +874,12 @@ async function call(route, { method = 'GET', query = {}, body } = {}) {
800
874
  assert.equal(init.status, 200)
801
875
  assert.equal(init.body.ok, true)
802
876
  const text = queenSection.text({ agent })
803
- assert.match(text, /You plan, you do not code/)
877
+ assert.match(text, /You plan and coordinate/)
804
878
  assert.ok(text.includes(join(repo, '.hive', 'roles', 'queen.md')), 'the role text must name its source path')
805
879
  assert.ok(text.includes('untrusted'), 'the role text must be marked as low-trust workspace text')
806
- assert.ok(text.length <= 4096, 'the role text must be capped at 4096 characters')
880
+ assert.ok(text.length <= 16384, 'the role text must be capped at 16384 characters')
881
+ assert.ok(text.includes('Fine-grained cards; every card needs an acceptance command.'), 'the exit hint must carry the coordinator contract')
882
+ assert.ok(text.includes('Exit with /queen off.'), 'the exit hint must name /queen off')
807
883
  assert.equal(queenSection.text({ agent: otherAgent }), '', 'queen mode must not leak to another Session')
808
884
 
809
885
  const off = shim.commands.get('queen').handler({ agent, rawInput: ' off ', signal: {}, attachments: [], commandId: 'cmd-1' })
@@ -816,7 +892,17 @@ async function call(route, { method = 'GET', query = {}, body } = {}) {
816
892
  assert.equal(exited.status, 200)
817
893
  assert.deepEqual(exited.body, { ok: true, code: 0, stdout: '', stderr: '' })
818
894
  assert.equal(queenSection.text({ agent }), '')
819
- ok('init + refs/hive/v1 marks only that Session; /queen off and name=queen-off both clear it')
895
+
896
+ // A repository without .hive/roles/queen.md falls back to the coordinator contract.
897
+ const fallbackOn = await call(route, { method: 'POST', query: { op: 'action', name: 'queen-on', sessionId: 's-other' }, body: {} })
898
+ assert.equal(fallbackOn.status, 200)
899
+ const fallbackText = queenSection.text({ agent: otherAgent })
900
+ assert.ok(fallbackText.includes('missing; built-in fallback'), 'a missing role file must be labelled as the built-in fallback')
901
+ assert.match(fallbackText, /You plan and coordinate; you never write code/)
902
+ assert.match(fallbackText, /fine-grained cards that each carry an acceptance command/)
903
+ assert.match(fallbackText, /Load the hive-queen skill/)
904
+ assert.ok(fallbackText.length <= 16384)
905
+ ok('init + refs/hive/v1 marks only that Session; /queen off and name=queen-off both clear it; a missing role file uses the coordinator fallback')
820
906
  }
821
907
 
822
908
  // ── 12b. role truncation ────────────────────────────────────────────────────
@@ -833,9 +919,9 @@ async function call(route, { method = 'GET', query = {}, body } = {}) {
833
919
  await call(route, { method: 'POST', query: { op: 'action', name: 'init', sessionId: 's-long' }, body: {} })
834
920
  const section = shim.sections.find(entry => entry.name === 'hive:queen')
835
921
  const text = section.text({ agent: { session: { id: 's-long' } } })
836
- assert.ok(text.length <= 4096, 'a 20k role file must be truncated to 4096 characters')
922
+ assert.ok(text.length <= 16384, 'a 20k role file must be truncated to 16384 characters')
837
923
  assert.ok(text.includes('truncated'), 'truncation must be signalled in the prompt text')
838
- ok('a 20k role file is truncated to 4096 characters and marked truncated')
924
+ ok('a 20k role file is truncated to 16384 characters and marked truncated')
839
925
  }
840
926
 
841
927
  // ── 12c. snapshot auto-queen / explicit off / queen-on ─────────────────────
@@ -851,7 +937,7 @@ async function call(route, { method = 'GET', query = {}, body } = {}) {
851
937
  const first = await snapshot()
852
938
  assert.equal(first.status, 200)
853
939
  assert.deepEqual(first.body.queen, { active: true, source: 'auto', repo })
854
- assert.match(section.text({ agent }), /You plan, you do not code/)
940
+ assert.match(section.text({ agent }), /You plan and coordinate/)
855
941
 
856
942
  // Repeated polling is idempotent: the auto state stays, it never flips source.
857
943
  const second = await snapshot()
package/src/panel.css CHANGED
@@ -1086,3 +1086,48 @@ dialog.hive-dialog .hive-card-subline,
1086
1086
  dialog.hive-dialog .hive-settings-role-name { min-width: 0; overflow-wrap: anywhere; }
1087
1087
  dialog.hive-dialog .hive-dialog-foot { flex-wrap: wrap; }
1088
1088
 
1089
+ dialog.hive-dialog {
1090
+ display: flex;
1091
+ flex-direction: column;
1092
+ max-height: 80vh;
1093
+ }
1094
+ dialog.hive-dialog .hive-dialog-head,
1095
+ dialog.hive-dialog .hive-dialog-foot { flex: 0 0 auto; }
1096
+ dialog.hive-dialog .hive-dialog-body { flex: 1 1 auto; min-height: 0; overflow: auto; }
1097
+ .hive-card-run-output { max-height: 20lh; overflow: auto; }
1098
+ .hive-card-actions { flex-wrap: wrap; justify-content: flex-end; }
1099
+
1100
+ /* Virtual lanes: fixed 26px cards, 2px gaps, 28px stride. */
1101
+ .hive-lane-cards {
1102
+ display: block;
1103
+ flex: 1 1 auto;
1104
+ min-height: 0;
1105
+ padding: 7px;
1106
+ overflow-x: hidden;
1107
+ overflow-y: auto;
1108
+ }
1109
+ .hive-lane-virtual { position: relative; width: 100%; min-width: 0; }
1110
+ .hive-lane-virtual .hive-card {
1111
+ position: absolute;
1112
+ left: 0;
1113
+ right: 0;
1114
+ display: flex;
1115
+ align-items: center;
1116
+ height: 26px;
1117
+ min-height: 26px;
1118
+ padding: 2px 8px;
1119
+ overflow: hidden;
1120
+ border-radius: var(--hive-radius-sm);
1121
+ }
1122
+ .hive-lane-virtual .hive-card-title {
1123
+ width: 100%;
1124
+ overflow: hidden;
1125
+ font-size: 12px;
1126
+ line-height: 16px;
1127
+ text-overflow: ellipsis;
1128
+ white-space: nowrap;
1129
+ }
1130
+
1131
+ .hive-agent-count { font: inherit; cursor: pointer; }
1132
+ .hive-agent-count:disabled { cursor: default; }
1133
+