teamsmith 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.
Files changed (117) hide show
  1. package/README.md +4 -4
  2. package/package.json +1 -1
  3. package/skills/teamsmith/CHANGELOG.md +28 -0
  4. package/skills/teamsmith/SKILL.md +14 -7
  5. package/skills/teamsmith/extension/team-notify.ts +37 -6
  6. package/skills/teamsmith/extension/team.ts +438 -0
  7. package/skills/teamsmith/references/config.md +39 -6
  8. package/skills/teamsmith/references/migration.md +197 -47
  9. package/skills/teamsmith/references/protocol.md +176 -19
  10. package/skills/teamsmith/references/troubleshooting.md +124 -7
  11. package/skills/teamsmith/references/workflows.md +36 -2
  12. package/skills/teamsmith/scripts/lib/cmd-agents.sh +318 -23
  13. package/skills/teamsmith/scripts/lib/cmd-bootstrap.sh +2 -2
  14. package/skills/teamsmith/scripts/lib/cmd-config.sh +349 -67
  15. package/skills/teamsmith/scripts/lib/cmd-draft.sh +4 -4
  16. package/skills/teamsmith/scripts/lib/cmd-help.sh +677 -0
  17. package/skills/teamsmith/scripts/lib/cmd-init.sh +157 -5
  18. package/skills/teamsmith/scripts/lib/cmd-interrupt.sh +461 -0
  19. package/skills/teamsmith/scripts/lib/cmd-meeting.sh +2 -25
  20. package/skills/teamsmith/scripts/lib/cmd-project.sh +30 -103
  21. package/skills/teamsmith/scripts/lib/cmd-reap.sh +277 -0
  22. package/skills/teamsmith/scripts/lib/cmd-reply.sh +3 -3
  23. package/skills/teamsmith/scripts/lib/cmd-review.sh +175 -30
  24. package/skills/teamsmith/scripts/lib/cmd-status.sh +226 -17
  25. package/skills/teamsmith/scripts/lib/cmd-update.sh +36 -7
  26. package/skills/teamsmith/scripts/lib/cmd-watch.sh +564 -46
  27. package/skills/teamsmith/scripts/lib/common.sh +773 -48
  28. package/skills/teamsmith/scripts/lib/gate-lock.sh +544 -0
  29. package/skills/teamsmith/scripts/panel/draft-send.sh +11 -1
  30. package/skills/teamsmith/scripts/panel/panel.js +207 -207
  31. package/skills/teamsmith/scripts/panel/src/App.tsx +58 -21
  32. package/skills/teamsmith/scripts/panel/src/clipboard.ts +11 -5
  33. package/skills/teamsmith/scripts/panel/src/compose.ts +6 -3
  34. package/skills/teamsmith/scripts/panel/src/data.ts +11 -3
  35. package/skills/teamsmith/scripts/panel/src/layout.ts +209 -69
  36. package/skills/teamsmith/scripts/panel/src/main.tsx +33 -8
  37. package/skills/teamsmith/scripts/panel/src/strings/en.ts +39 -29
  38. package/skills/teamsmith/scripts/panel/src/strings/zh.ts +41 -31
  39. package/skills/teamsmith/scripts/panel/src/types.ts +28 -3
  40. package/skills/teamsmith/scripts/replies.mjs +4 -1
  41. package/skills/teamsmith/scripts/shim/tmux +18 -0
  42. package/skills/teamsmith/scripts/strings/commands.tsv +86 -0
  43. package/skills/teamsmith/scripts/strings/help.en.tsv +503 -0
  44. package/skills/teamsmith/scripts/strings/help.zh.tsv +489 -0
  45. package/skills/teamsmith/scripts/team +19 -6
  46. package/skills/teamsmith/templates/AGENTS.section.md.tmpl +8 -1
  47. package/skills/teamsmith/templates/config.sh.tmpl +20 -1
  48. package/skills/teamsmith/templates/pm-prompt.md.tmpl +21 -0
  49. package/skills/teamsmith/tests/bg-ledger-harness.mjs +464 -40
  50. package/skills/teamsmith/tests/bg-ledger.sh +168 -10
  51. package/skills/teamsmith/tests/checkout-shape-probe.sh +3 -1
  52. package/skills/teamsmith/tests/config-cli.sh +160 -14
  53. package/skills/teamsmith/tests/fixtures/delivery-truth-real/scenario.sh +7 -1
  54. package/skills/teamsmith/tests/fixtures/p287/lint-good.sh.in +3 -0
  55. package/skills/teamsmith/tests/fixtures/p287/lint-hardcoded.sh.in +3 -0
  56. package/skills/teamsmith/tests/fixtures/p287/lint-no-ns.sh.in +3 -0
  57. package/skills/teamsmith/tests/fixtures/p55/flip-p49.sh +18 -6
  58. package/skills/teamsmith/tests/flip-m33.sh +5 -3
  59. package/skills/teamsmith/tests/flip-m37.sh +4 -1
  60. package/skills/teamsmith/tests/flip-m4.3.sh +4 -1
  61. package/skills/teamsmith/tests/flip-m6.3.sh +4 -1
  62. package/skills/teamsmith/tests/flip-m6.5.sh +4 -1
  63. package/skills/teamsmith/tests/flip-m7.2.sh +4 -1
  64. package/skills/teamsmith/tests/flip-p158.sh +2 -1
  65. package/skills/teamsmith/tests/flip-p210.sh +4 -1
  66. package/skills/teamsmith/tests/flip-p217.sh +4 -1
  67. package/skills/teamsmith/tests/flip-p287-lock.sh +342 -0
  68. package/skills/teamsmith/tests/flip-p287-name.sh +279 -0
  69. package/skills/teamsmith/tests/flip-p304-read-side.sh +98 -0
  70. package/skills/teamsmith/tests/flip-p308-skip-not-pass.sh +151 -0
  71. package/skills/teamsmith/tests/flip-p309-p162-deep.sh +122 -0
  72. package/skills/teamsmith/tests/flip-p310-lock.sh +216 -0
  73. package/skills/teamsmith/tests/flip-p310-socket.sh +125 -0
  74. package/skills/teamsmith/tests/help-surface.sh +1664 -0
  75. package/skills/teamsmith/tests/install-shape.sh +279 -20
  76. package/skills/teamsmith/tests/key-replies-pty.sh +9 -10
  77. package/skills/teamsmith/tests/key-replies-ui.sh +0 -7
  78. package/skills/teamsmith/tests/key-replies.sh +240 -1
  79. package/skills/teamsmith/tests/ledger-ban.sh +5 -4
  80. package/skills/teamsmith/tests/ledger-claim.sh +2 -1
  81. package/skills/teamsmith/tests/lib/bounded-spin.sh +90 -0
  82. package/skills/teamsmith/tests/lib/model-policy.sh +4 -0
  83. package/skills/teamsmith/tests/lib/model-routing-flips.py +51 -0
  84. package/skills/teamsmith/tests/lib/reply-fixture.sh +4 -9
  85. package/skills/teamsmith/tests/lib/section-guard.sh +258 -13
  86. package/skills/teamsmith/tests/lib/tmp-root.sh +139 -27
  87. package/skills/teamsmith/tests/lib/tmux-cap.sh +10 -1
  88. package/skills/teamsmith/tests/lib/tmux-iso.sh +31 -13
  89. package/skills/teamsmith/tests/loop-inventory.tsv +59 -47
  90. package/skills/teamsmith/tests/panel-b2.sh +106 -3
  91. package/skills/teamsmith/tests/panel-b3-stub.sh +112 -4
  92. package/skills/teamsmith/tests/panel-b3.sh +175 -19
  93. package/skills/teamsmith/tests/panel-choices.sh +11 -6
  94. package/skills/teamsmith/tests/panel-cpu.sh +2 -1
  95. package/skills/teamsmith/tests/panel-knobs.sh +7 -1
  96. package/skills/teamsmith/tests/panel-p21.sh +156 -73
  97. package/skills/teamsmith/tests/panel-snapshots.sh +41 -225
  98. package/skills/teamsmith/tests/panel-strings.mjs +33 -18
  99. package/skills/teamsmith/tests/perf.sh +121 -30
  100. package/skills/teamsmith/tests/routes.sh +327 -93
  101. package/skills/teamsmith/tests/seat-interrupt.sh +1002 -0
  102. package/skills/teamsmith/tests/seat-visibility.sh +675 -0
  103. package/skills/teamsmith/tests/section-budgets.tsv +20 -10
  104. package/skills/teamsmith/tests/section-guard.sh +6 -1
  105. package/skills/teamsmith/tests/section-needs-audit.sh +24 -7
  106. package/skills/teamsmith/tests/section-paths.tsv +19 -13
  107. package/skills/teamsmith/tests/section-select.sh +8 -1
  108. package/skills/teamsmith/tests/slash-team-e2e.sh +323 -0
  109. package/skills/teamsmith/tests/slash-team.sh +617 -0
  110. package/skills/teamsmith/tests/smoke.sh +2972 -440
  111. package/skills/teamsmith/tests/task-model-routing.sh +507 -10
  112. package/skills/teamsmith/tests/tmp-hygiene.sh +782 -45
  113. package/skills/teamsmith/tests/tmux-identity-leak.sh +773 -0
  114. package/skills/teamsmith/tests/tmux-lint-legacy.txt +12 -18
  115. package/skills/teamsmith/tests/upgrade-recipe.sh +537 -0
  116. package/skills/teamsmith-init/SKILL.md +12 -12
  117. package/skills/teamsmith-init/references/bootstrap.md +3 -3
@@ -31,6 +31,7 @@ import type {
31
31
  ChangeRow,
32
32
  Density,
33
33
  DetailBlock,
34
+ DetailSource,
34
35
  DetailWindow,
35
36
  FocusRef,
36
37
  Frame,
@@ -742,8 +743,12 @@ function boardBlock(ctx: Ctx): Block | null {
742
743
  // M48: the focus names a **row**, not a bare id — two rows may share one id, and matching by id
743
744
  // highlights both at once and freezes the `↑`/`↓` walk on the first of them.
744
745
  const ordinals = dupOrdinals(rows)
745
- const named = focusRow(rows, ctx.view.focus)
746
- const focusedRow = named && rendered.includes(named) ? named : (rendered[0] ?? null)
746
+ const scoped = boardFocusRef(ctx.view.focus)
747
+ const named = scoped ? focusRow(rows, scoped) : null
748
+ // P249: a preview row's ref never lights a board row — the page's one cursor belongs to that
749
+ // block; the board only draws its default (first rendered row) when nothing is focused at all.
750
+ const focusedRow =
751
+ ctx.view.focus && !scoped ? null : named && rendered.includes(named) ? named : (rendered[0] ?? null)
747
752
  const order = rendered.map((r) => refFor(r, ordinals))
748
753
  for (const r of rendered) {
749
754
  const focused = r === focusedRow
@@ -958,6 +963,15 @@ function resolveFocusWith(
958
963
  return null
959
964
  }
960
965
 
966
+ /**
967
+ * The board-scoped part of a focus ref (P249): a preview row's ref (lane = a preview block's scope) never
968
+ * names a kanban card, so the board page neither draws a cursor for it nor opens anything from it. A
969
+ * missing ref keeps the board's own default (the first card of the first non-empty lane).
970
+ */
971
+ export function boardFocusRef(focus?: FocusRef | null): FocusRef | null {
972
+ return focus && LANES.includes(focus.lane) ? focus : null
973
+ }
974
+
961
975
  /**
962
976
  * One lane's visible window. `size` is the number of card rows the frame can spend, the offset is
963
977
  * clamped to the lane, and the focused card (when it lives in this lane) always stays inside — the
@@ -1178,7 +1192,10 @@ function kanbanBlock(ctx: Ctx): Block | null {
1178
1192
  const rows = board.rows ?? []
1179
1193
  if (!rows.length) return one([{ line: truncLine(ln(seg(` ${s.boardEmpty}`, 'dim')), ctx.width) }])
1180
1194
  const ordinals = dupOrdinals(rows)
1181
- const focus = resolveFocusWith(rows, ordinals, ctx.view.focus)
1195
+ // P249: only a ref that names one of the six lanes (or no ref at all, which keeps the board's own
1196
+ // default cursor) resolves here; a preview row's ref puts no cursor on the kanban.
1197
+ const focus =
1198
+ ctx.view.focus && !LANES.includes(ctx.view.focus.lane) ? null : resolveFocusWith(rows, ordinals, ctx.view.focus)
1182
1199
  // M48: one row object is the focus; every `card === target` below is O(1) and two rows sharing an
1183
1200
  // id never both light up. The duplicate ordinals are built once per frame and shared by the
1184
1201
  // focus/actions (no per-lane or per-card rescan of the board).
@@ -1278,11 +1295,19 @@ function detailBlock(ctx: Ctx): Block | null {
1278
1295
  return one([{ line: truncLine(ln(seg(` ${s.detailLoading}`, 'dim')), width) }], { index: 0, total: 0, visible: 0, offset: 0 })
1279
1296
  }
1280
1297
  const files = data.files ?? []
1281
- if (!files.length) return one([{ line: truncLine(ln(seg(` ${s.detailNoFiles}`, 'dim')), width) }])
1298
+ if (!files.length) {
1299
+ // A missing target is not an error: the reader's reason names it, so the view says the source is
1300
+ // unavailable instead of rendering an empty document as a successful read (P249).
1301
+ const line = data.reason ? fill(s.detailUnavailable, { reason: data.reason }) : s.detailNoFiles
1302
+ return one([{ line: truncLine(ln(seg(` ${line}`, 'dim')), width) }])
1303
+ }
1282
1304
  const detail = data as DetailBlock
1283
1305
  const index = Math.max(0, Math.min(files.length - 1, Math.floor(ctx.view.detailIndex ?? 0) || 0))
1284
1306
  const active = files[index]
1285
1307
  const rows: PlacedLine[] = [detailTabs(ctx, files, index, width)]
1308
+ // The reader refused a discovery (a symbolic link): the other files still open, and the reason
1309
+ // names what was refused (P249).
1310
+ if (data.reason) rows.push({ line: truncLine(ln(seg(` ${data.reason}`, 'warn')), width) })
1286
1311
  if (active.truncated) rows.push({ line: truncLine(ln(seg(` ${s.detailTruncated}`, 'warn')), width) })
1287
1312
  if (detail.file !== active.path) {
1288
1313
  // The tab was switched and its text has not arrived yet: the tabs stay live, the body says why.
@@ -1339,9 +1364,10 @@ function replyNavLine(ctx: Ctx, innerW: number): PlacedLine {
1339
1364
  }
1340
1365
 
1341
1366
  /**
1342
- * Page 5's list block. It draws the nav row, the slot count (never a claim about readable replies),
1343
- * the tail warning when the reader reported one, and the windowed rows. The returned window is what
1344
- * the App clamps `↑`/`↓` against; `focus` is the focused slot's number.
1367
+ * Page 5's list block. It draws the nav row, the page's one-line self-description (what this page
1368
+ * holds and who publishes into it), the slot count (never a claim about readable replies), the tail
1369
+ * warning when the reader reported one, and the windowed rows. The returned window is what the App
1370
+ * clamps `↑`/`↓` against; `focus` is the focused slot's number.
1345
1371
  */
1346
1372
  function replyListBlock(ctx: Ctx): Block | null {
1347
1373
  const { s, blocks, deg, view } = ctx
@@ -1358,7 +1384,10 @@ function replyListBlock(ctx: Ctx): Block | null {
1358
1384
  replyList: win,
1359
1385
  summary: { line: truncLine(ln(seg(` ${s.replyHeading}`, 'heading')), ctx.width) },
1360
1386
  })
1361
- const lines: PlacedLine[] = [replyNavLine(ctx, innerW)]
1387
+ const lines: PlacedLine[] = [
1388
+ replyNavLine(ctx, innerW),
1389
+ { line: truncLine(ln(seg(` ${s.replyPageNote}`, 'dim')), innerW) },
1390
+ ]
1362
1391
  if (!data || deg.has('reply_list')) {
1363
1392
  lines.push({ line: truncLine(ln(seg(` ${data ? s.dash : s.replyLoading}`, 'dim')), innerW) })
1364
1393
  return build(lines, { focus: 0, offset: 0, visible: 0, count: 0 })
@@ -1526,18 +1555,18 @@ function replySummaryBlock(ctx: Ctx): Block | null {
1526
1555
  // sentences, so the column only has to hold the longest of them (zh is the wide language here;
1527
1556
  // a longer en label is cut by `cell()`, the same rule the key names followed).
1528
1557
  const SETTINGS_LABEL_W = 22
1529
- const SETTINGS_AUDIT_LINES = 3
1530
1558
  /** P232: the policy migration diagnosis is shown above the audit tail; the rest is counted. */
1531
1559
  const SETTINGS_DIAG_LINES = 2
1532
1560
  /** P232: how many frame lines one diagnosis line may wrap to before it is cut with an ellipsis. */
1533
1561
  const SETTINGS_DIAG_WRAP = 2
1534
- // The tail the block draws under its row window: the CLI hint, a blank, the audit heading and up to
1535
- // `SETTINGS_AUDIT_LINES` audit lines (the heading always has one line under it — a dash when the
1536
- // command's log is empty), plus `SETTINGS_COUNT_ROWS`, the pessimistic reservation for the two
1537
- // hidden-row counts (`↑n`/`↓n`). Reserving **both** counts is what keeps the block inside the frame
1538
- // once the list is longer than the window: with only the tail reserved, a full window plus a full
1539
- // audit tail overflowed and the whole view degraded to its one-line summary (measured in M55's
1540
- // pairlist route: the seats block the route had just focused disappeared from the frame).
1562
+ // The tail the block draws under its row window: the focused row's CLI hint and, when the command
1563
+ // reports one, the policy migration diagnosis (P266: the audit tail is no longer drawn here — the
1564
+ // log stays readable through `team config list`'s own footer and `team config log`, and the console
1565
+ // is deliberately not one of its readers), plus `SETTINGS_COUNT_ROWS`, the pessimistic reservation
1566
+ // for the two hidden-row counts (`↑n`/`↓n`). Reserving **both** counts is what keeps the block inside
1567
+ // the frame once the list is longer than the window: with only the tail reserved, a full window
1568
+ // plus a full tail overflowed and the whole view degraded to its one-line summary (measured in
1569
+ // M55's pairlist route: the seats block the route had just focused disappeared from the frame).
1541
1570
  //
1542
1571
  // P32 (the user's second report, 2026-09-22): the reservation is a *ceiling*, not a fixed cost. The
1543
1572
  // window spends what the tail does not need (a count line is only drawn when the window really
@@ -1546,14 +1575,13 @@ const SETTINGS_DIAG_WRAP = 2
1546
1575
  const SETTINGS_COUNT_ROWS = 2
1547
1576
 
1548
1577
  /**
1549
- * The sum M55 calibrated: the two count lines, the CLI hint, a blank, the audit heading and the audit
1550
- * tail. The row list treats it as a ceiling and hands back what it does not draw (P32); the two pickers
1551
- * keep it as the bound of their own *paged* list (title + interval + the two hidden-count lines + blank
1552
- * + hint, then the entries) — a long vocabulary shows a `↑n`/`↓n` window that scrolls instead of
1553
- * flooding the pane, which is what the archived `choices` fixture calibrates its twenty-eight model
1554
- * records against. Their cards still fill (the pad below), so the key band stays the frame's last row.
1578
+ * The two pickers' *paged* list bound (M55's calibrated value, kept: a picker covers the row list, so
1579
+ * this reservation is its own chrome — title + interval + the two hidden-count lines + blank + hint).
1580
+ * A long vocabulary shows a `↑n`/`↓n` window that scrolls instead of flooding the pane, which is what
1581
+ * the archived `choices` fixture calibrates its twenty-eight model records against. Their cards still
1582
+ * fill (the pad below), so the key band stays the frame's last row.
1555
1583
  */
1556
- const SETTINGS_TAIL_ROWS = SETTINGS_COUNT_ROWS + 1 + 1 + 1 + SETTINGS_AUDIT_LINES
1584
+ const SETTINGS_TAIL_ROWS = SETTINGS_COUNT_ROWS + 6
1557
1585
 
1558
1586
  /** One drawn row of the project-settings view (group headings are not focusable). */
1559
1587
  export type SettingsRow =
@@ -1575,6 +1603,18 @@ export function settingsClassLabel(s: Strings, cls: string): string {
1575
1603
  * shout in green while the user's question is "does this need a restart?". Colour is never the only
1576
1604
  * channel: the badge's word always carries the class (the panel's standing rule).
1577
1605
  */
1606
+ /**
1607
+ * The declared marker the owning command puts at the start of a fixture-only key's note
1608
+ * (`memory-and-deps` owns the marker). The hiding rule reads the read's data and nothing else: no
1609
+ * key list is baked into the bundle, so a fixture key added to the schema stays hidden and one whose
1610
+ * marker is removed comes back without rebuilding `panel.js`.
1611
+ */
1612
+ const SETTINGS_FIXTURE_ONLY_MARKER = 'fixture-only: '
1613
+
1614
+ function settingsKeyHidden(k: SettingsKey): boolean {
1615
+ return String(k.route ?? '').startsWith(SETTINGS_FIXTURE_ONLY_MARKER)
1616
+ }
1617
+
1578
1618
  function settingsClassTone(cls: string): Tone {
1579
1619
  if (cls === 'restart') return 'warn'
1580
1620
  if (cls === 'refuse') return 'dim'
@@ -1631,8 +1671,12 @@ export function settingsViewRows(block: SettingsBlock | undefined, filter: strin
1631
1671
  needle === '' || parts.some((p) => String(p ?? '').toLowerCase().includes(needle))
1632
1672
  // The label first (what the row shows), then the raw key and the value — the three inputs a
1633
1673
  // user may type into `/` (the label's words, `TEAM_…`, or the value on screen).
1634
- const shown = block.keys.filter((k) =>
1635
- match(keyLabel(s, k.name), k.name, k.value, k.default, k.comment, k.warning, k.route ?? ''),
1674
+ // P266: a key the read marks fixture-only is not a row at all — no row, no heading of its own and
1675
+ // no `/` hit (it is dropped before the match, so not even its label or raw name can reach it).
1676
+ const shown = block.keys.filter(
1677
+ (k) =>
1678
+ !settingsKeyHidden(k) &&
1679
+ match(keyLabel(s, k.name), k.name, k.value, k.default, k.comment, k.warning, k.route ?? ''),
1636
1680
  )
1637
1681
  const ungrouped: SettingsKey[] = []
1638
1682
  let openToken: string | null = null
@@ -1659,8 +1703,10 @@ export function settingsViewRows(block: SettingsBlock | undefined, filter: strin
1659
1703
  out.push({ kind: 'group', label: s.settingsGroupCategories, tone: 'heading' })
1660
1704
  for (const c of categories) out.push({ kind: 'category', category: c })
1661
1705
  }
1706
+ // P266: the command's diagnostic is deliberately not searchable here — it never reaches the
1707
+ // screen, so `/` must not find a row for a string the user cannot see anywhere.
1662
1708
  const assignments = (block.models?.assignments ?? []).filter((a) =>
1663
- match(a.agent, a.task, a.category, a.model, a.sid, a.selected_via, a.launch_via, a.diagnostic),
1709
+ match(a.agent, a.task, a.category, a.model, a.sid, a.selected_via, a.launch_via),
1664
1710
  )
1665
1711
  const launch = block.models?.pm_launch ?? {}
1666
1712
  const launchShown =
@@ -1804,6 +1850,9 @@ function settingsAssignmentLine(ctx: Ctx, a: SettingsAssignment, focused: boolea
1804
1850
  innerW,
1805
1851
  ).map((x) => x),
1806
1852
  )
1853
+ // P266: the command's diagnostic string never reaches the screen. The two plain reasons are chosen
1854
+ // from the read's own fact (`record_present`): no record file at all vs. a record that exists but
1855
+ // cannot be read — a seat that was used is never told it never was.
1807
1856
  const note = a.assigned
1808
1857
  ? fill(s.settingsAssignmentNote, {
1809
1858
  task: a.task || s.dash,
@@ -1812,7 +1861,9 @@ function settingsAssignmentLine(ctx: Ctx, a: SettingsAssignment, focused: boolea
1812
1861
  selected: settingsSourceLabel(s, a.selected_via),
1813
1862
  launch: settingsSourceLabel(s, a.launch_via),
1814
1863
  })
1815
- : fill(s.settingsAssignmentNone, { diagnostic: a.diagnostic || s.dash })
1864
+ : a.record_present === false
1865
+ ? s.settingsAssignmentNone
1866
+ : s.settingsAssignmentUnreadable
1816
1867
  line.push(seg(` ${truncateW(note, Math.max(8, innerW - dispWidth(textOf(line)) - 2))}`, a.assigned ? 'dim' : 'warn'))
1817
1868
  return { line }
1818
1869
  }
@@ -1851,7 +1902,7 @@ function settingsCliHint(s: Strings, rows: SettingsRow[], focus: number): string
1851
1902
  if (row.kind === 'pm-launch') return s.settingsPmLaunchHint
1852
1903
  const key = row.key
1853
1904
  if (key.known === false) return fill(s.settingsUnknownHint, { key: key.name })
1854
- if (key.class === 'refuse') return fill(s.settingsRefusedHint, { key: key.name })
1905
+ if (key.class === 'refuse') return s.settingsRefusedHint
1855
1906
  // The whole-map row is not composed here: its editor is the categories block, and the command
1856
1907
  // line the requirement names is the per-category one (P232).
1857
1908
  if (String(key.kind ?? '') === 'task-model-map') return s.settingsCategoryMapHint
@@ -1898,9 +1949,6 @@ function settingsBlock(ctx: Ctx): Block | null {
1898
1949
  const room = Math.max(3, ctx.settingsRows ?? 12)
1899
1950
  const focus = Math.max(0, Math.min(Math.max(0, count - 1), ctx.view.settingsFocus ?? 0))
1900
1951
  const explicitOffset = ctx.view.settingsOffset
1901
- // The tail under the window: the CLI hint, a blank, the audit heading and its tail (the heading
1902
- // always has one line under it — a dash when the command's log is empty).
1903
- const audit = (block.audit ?? []).slice(-SETTINGS_AUDIT_LINES)
1904
1952
  // P232: the command's own policy diagnosis (missing/retired keys, an unmapped category map) is
1905
1953
  // part of the view: a legacy contract must say so, with the CLI route the command itself names.
1906
1954
  const diagnosis = String(block.models?.diagnostic ?? '')
@@ -1911,7 +1959,9 @@ function settingsBlock(ctx: Ctx): Block | null {
1911
1959
  const diagRest = diagnosis.length - diagShown.length
1912
1960
  const diagChunks = diagShown.map((d) => diagnoseChunks(d, Math.max(8, width - 3), SETTINGS_DIAG_WRAP))
1913
1961
  const diagLines = diagChunks.length ? diagChunks.reduce((n, c) => n + c.length, 0) + 1 + (diagRest > 0 ? 1 : 0) : 0
1914
- const tailLines = 1 + 1 + 1 + Math.max(1, audit.length) + diagLines
1962
+ // P266: the tail is the focused row's CLI hint plus the diagnosis when there is one; the audit
1963
+ // tail that used to sit here is no longer drawn (and no longer reads the log).
1964
+ const tailLines = 1 + diagLines
1915
1965
  // The row cap: each row costs at least its own line, and the tail is already spoken for.
1916
1966
  const desired = Math.max(1, Math.min(Math.max(1, count), Math.max(1, room - tailLines)))
1917
1967
  const maxOffset = Math.max(0, count - desired)
@@ -2114,12 +2164,6 @@ function settingsBlock(ctx: Ctx): Block | null {
2114
2164
  if (diagRest > 0) put(ln(seg(` ${fill(s.laneHiddenBelow, { n: String(diagRest) })}`, 'dim')))
2115
2165
  }
2116
2166
 
2117
- // The audit footer: at most three lines, newest last (the CLI's own tail).
2118
- put(ln(seg('')))
2119
- put(ln(seg(` ${s.settingsAuditHeading}`, 'heading')))
2120
- if (!audit.length) put(ln(seg(` ${s.dash}`, 'dim')))
2121
- for (const a of audit) put(ln(seg(` ${a}`, 'dim')))
2122
-
2123
2167
  // P32 (the bounded-frame rule's last resort, the detail view's own): the space the rows did not
2124
2168
  // use stays **inside** the card, so the card fills the pane it was handed and the key band stays
2125
2169
  // the frame's last row. With a full list that is nothing; with a filter, the tail of the list or
@@ -2148,6 +2192,91 @@ function changeTasksLine(ch: ChangeRow, width: number): PlacedLine | null {
2148
2192
  return widthOf(line) <= width ? { line } : null
2149
2193
  }
2150
2194
 
2195
+ /**
2196
+ * P249 · the work page's preview blocks: the changes/specs/decisions rows are focusable on the same
2197
+ * terms as the board rows (one cursor, a two-stage click, a stop in the page-wide drawn order), and
2198
+ * the source a row hands to the detail view is fixed by the block it was drawn in.
2199
+ */
2200
+
2201
+ /** The duplicate ordinal of each focusable key in a preview block (the board's `dupOrdinals` twin). */
2202
+ function previewOrdinals(keys: string[]): number[] {
2203
+ const seen = new Map<string, number>()
2204
+ return keys.map((key) => {
2205
+ const nth = seen.get(key) ?? 0
2206
+ seen.set(key, nth + 1)
2207
+ return nth
2208
+ })
2209
+ }
2210
+
2211
+ /**
2212
+ * The focused key's index: the exact (id, nth) when it names one of this block's rows, the id's first
2213
+ * row when the duplicate it named left, else the first drawn row. A ref scoped to another block (or to
2214
+ * a board lane) never lights a row here — each block only draws its own focus.
2215
+ */
2216
+ function previewFocusIndex(ctx: Ctx, scope: string, keys: string[], ordinals: number[]): number {
2217
+ const f = ctx.view.focus
2218
+ if (f && f.lane === scope) {
2219
+ const nth = Math.max(0, f.nth ?? 0)
2220
+ const exact = keys.findIndex((id, i) => id === f.id && ordinals[i] === nth)
2221
+ if (exact >= 0) return exact
2222
+ const first = keys.indexOf(f.id)
2223
+ if (first >= 0) return first
2224
+ return 0
2225
+ }
2226
+ // No focus, or a focus the board owns: this block draws no cursor (the page has exactly one).
2227
+ return -1
2228
+ }
2229
+
2230
+ /** The detail source a work-page focus lane addresses (P249); a board lane stays the entry source. */
2231
+ export function rowSourceOf(lane: string): DetailSource {
2232
+ if (lane === 'changes') return 'change'
2233
+ if (lane === 'specs') return 'spec'
2234
+ if (lane === 'decisions') return 'decision'
2235
+ return 'entry'
2236
+ }
2237
+
2238
+ /**
2239
+ * One preview block's drawn rows with the P249 focus kit: a row whose `key` is a string is a stop —
2240
+ * drawn with the cursor and the `selected` tone when focused, one `open-focused`/`focus` target, and
2241
+ * one entry in the block's drawn-row order (the assembly concatenates the blocks' orders into the
2242
+ * page order); a row whose key is null is drawn but is not a stop (there is nothing to open).
2243
+ */
2244
+ function previewLines(
2245
+ ctx: Ctx,
2246
+ scope: string,
2247
+ drawn: { key: string | null; content: Line }[],
2248
+ width: number,
2249
+ ): { lines: PlacedLine[]; order: FocusRef[] } {
2250
+ const keys = drawn.filter((d) => d.key !== null).map((d) => d.key as string)
2251
+ const ordinals = previewOrdinals(keys)
2252
+ const focusIdx = keys.length ? previewFocusIndex(ctx, scope, keys, ordinals) : -1
2253
+ const lines: PlacedLine[] = []
2254
+ const order: FocusRef[] = []
2255
+ let k = -1
2256
+ for (const d of drawn) {
2257
+ if (d.key === null) {
2258
+ lines.push({ line: truncLine(d.content, width) })
2259
+ continue
2260
+ }
2261
+ k++
2262
+ const nth = ordinals[k]
2263
+ const focused = k === focusIdx
2264
+ order.push({ lane: scope, id: d.key, nth })
2265
+ const line = ln(focused ? seg(`${FOCUS_CURSOR} `, 'selected') : seg(' '), ...d.content)
2266
+ const action: Action = focused
2267
+ ? { kind: 'open-focused', lane: scope }
2268
+ : { kind: 'focus', lane: scope, id: d.key, nth }
2269
+ lines.push(placedWithHits(line, ctx.view.tui ? [{ start: 0, end: widthOf(line), action }] : undefined, width))
2270
+ }
2271
+ return { lines, order }
2272
+ }
2273
+
2274
+ /** The `D<n>` a decision heading names; a heading without one is drawn but not openable. */
2275
+ function decisionIdOf(title: string): string | null {
2276
+ const m = /^D([0-9]+)(?![0-9])/.exec(String(title).trim())
2277
+ return m ? `D${m[1]}` : null
2278
+ }
2279
+
2151
2280
  function changesBlock(ctx: Ctx): Block | null {
2152
2281
  const { s, blocks, deg, width } = ctx
2153
2282
  const c = blocks.changes
@@ -2156,22 +2285,20 @@ function changesBlock(ctx: Ctx): Block | null {
2156
2285
  return { id: 'changes', title: s.changesHeading, right: true, priority: 11, lines: [{ line: ln(seg(` ${s.dash}`, 'dim')) }] }
2157
2286
  }
2158
2287
  if (!c.changes.length) return null // an empty block collapses and yields its space
2159
- const lines: PlacedLine[] = []
2288
+ const drawn: { key: string | null; content: Line }[] = []
2160
2289
  for (const ch of c.changes as ChangeRow[]) {
2161
- lines.push({
2162
- line: truncLine(
2163
- ln(
2164
- seg(' '),
2165
- seg(cell(ch.id, 18), 'accent'),
2166
- seg(fill(s.changeLine, { done: ch.done, total: ch.total, phase: changePhaseText(ch.phase, s) })),
2167
- ),
2168
- width,
2169
- ),
2290
+ drawn.push({
2291
+ key: ch.id,
2292
+ content: [
2293
+ seg(cell(ch.id, 18), 'accent'),
2294
+ seg(fill(s.changeLine, { done: ch.done, total: ch.total, phase: changePhaseText(ch.phase, s) })),
2295
+ ],
2170
2296
  })
2171
2297
  const toks = changeTasksLine(ch, width)
2172
- if (toks) lines.push(toks)
2298
+ if (toks) drawn.push({ key: null, content: toks.line })
2173
2299
  }
2174
- return { id: 'changes', title: fill(s.changesHeadingCount, { n: c.count }), right: true, priority: 11, lines, summary: { line: truncLine(ln(seg(` ${fill(s.changesHeadingCount, { n: c.count })}`, 'heading')), width) } }
2300
+ const { lines, order } = previewLines(ctx, 'changes', drawn, width)
2301
+ return { id: 'changes', title: fill(s.changesHeadingCount, { n: c.count }), right: true, priority: 11, lines, order, summary: { line: truncLine(ln(seg(` ${fill(s.changesHeadingCount, { n: c.count })}`, 'heading')), width) } }
2175
2302
  }
2176
2303
 
2177
2304
  function specsBlock(ctx: Ctx): Block | null {
@@ -2181,13 +2308,16 @@ function specsBlock(ctx: Ctx): Block | null {
2181
2308
  if (deg.has('specs') || !sp.available) {
2182
2309
  return { id: 'specs', title: s.specsHeading, right: true, priority: 13, lines: [{ line: ln(seg(` ${s.dash}`, 'dim')) }] }
2183
2310
  }
2311
+ const drawn = (sp.specs ?? []).slice(0, 6).map((row) => ({
2312
+ key: row.name,
2313
+ content: [seg(cell(row.name, Math.max(8, width - 10)), 'text'), seg(` ${row.requirements}`, 'dim')],
2314
+ }))
2315
+ const { lines: rows, order } = previewLines(ctx, 'specs', drawn, width)
2184
2316
  const lines: PlacedLine[] = [
2185
2317
  { line: truncLine(ln(seg(fill(s.specsCount, { specs: sp.count, reqs: sp.requirements }), 'dim')), width) },
2318
+ ...rows,
2186
2319
  ]
2187
- for (const row of (sp.specs ?? []).slice(0, 6)) {
2188
- lines.push({ line: truncLine(ln(seg(' '), seg(cell(row.name, Math.max(8, width - 10)), 'text'), seg(` ${row.requirements}`, 'dim')), width) })
2189
- }
2190
- return { id: 'specs', title: s.specsHeading, right: true, priority: 13, lines, summary: { line: truncLine(ln(seg(` ${s.specsHeading}`, 'heading')), width) } }
2320
+ return { id: 'specs', title: s.specsHeading, right: true, priority: 13, lines, order, summary: { line: truncLine(ln(seg(` ${s.specsHeading}`, 'heading')), width) } }
2191
2321
  }
2192
2322
 
2193
2323
  function decisionsBlock(ctx: Ctx): Block | null {
@@ -2197,12 +2327,16 @@ function decisionsBlock(ctx: Ctx): Block | null {
2197
2327
  if (deg.has('decisions')) {
2198
2328
  return { id: 'decisions', title: s.decisionsHeading, right: true, priority: 14, lines: [{ line: ln(seg(` ${s.dash}`, 'dim')) }] }
2199
2329
  }
2330
+ const drawn: { key: string | null; content: Line }[] = d.recent
2331
+ .slice(0, 3)
2332
+ .map((r) => ({ key: decisionIdOf(r), content: [seg(r, 'dim')] }))
2333
+ const { lines: rows, order } = previewLines(ctx, 'decisions', drawn, width)
2200
2334
  const lines: PlacedLine[] = [
2201
2335
  { line: truncLine(ln(seg(fill(s.decisionsCountSuffix, { n: d.count }), 'dim')), width) },
2202
2336
  ]
2203
2337
  if (!d.recent.length) lines.push({ line: ln(seg(` ${s.decisionsEmpty}`, 'dim')) })
2204
- for (const r of d.recent.slice(0, 3)) lines.push({ line: truncLine(ln(seg(` ${r}`, 'dim')), width) })
2205
- return { id: 'decisions', title: s.decisionsHeading, right: true, priority: 14, lines, summary: { line: truncLine(ln(seg(` ${s.decisionsHeading}`, 'heading')), width) } }
2338
+ lines.push(...rows)
2339
+ return { id: 'decisions', title: s.decisionsHeading, right: true, priority: 14, lines, order, summary: { line: truncLine(ln(seg(` ${s.decisionsHeading}`, 'heading')), width) } }
2206
2340
  }
2207
2341
 
2208
2342
  // ------------------------------------------------------------------ body blocks (page 3)
@@ -2737,14 +2871,16 @@ export function layout(input: LayoutInput): Frame {
2737
2871
  const rightBlocks = middle.filter((b) => !b.full && b.right)
2738
2872
 
2739
2873
  const framed = isFramed(ctx)
2740
- let boardOrder: FocusRef[] | undefined
2741
- const place = (block: Block, remaining: number, colWidth: number): PlacedLine[] => {
2874
+ // P249: the work page's drawn-row order is **page-wide** — each block that really draws its rows
2875
+ // reports them in the order it drew them and the assembly concatenates the blocks in placement
2876
+ // order (left column top-to-bottom, then the right column). A block degraded to its summary line
2877
+ // draws no row and contributes nothing.
2878
+ let pageOrder: FocusRef[] = []
2879
+ const place = (block: Block, remaining: number, colWidth: number, sink: FocusRef[] | null): PlacedLine[] => {
2742
2880
  const kind = pickChrome(block, remaining, framed)
2743
2881
  if (kind === null) return []
2744
2882
  if (kind === 'summary') return [summaryLine(block, colWidth)]
2745
- // The order is only reported for a block that really draws its rows: a block degraded to its
2746
- // summary line has no row to focus (P20/B5).
2747
- if (block.order) boardOrder = block.order
2883
+ if (block.order && sink) sink.push(...block.order)
2748
2884
  return wrapBlock(block, colWidth, kind)
2749
2885
  }
2750
2886
 
@@ -2778,7 +2914,7 @@ export function layout(input: LayoutInput): Frame {
2778
2914
  if (block.id === 'settings' && block.settings) settingsWindow = block.settings
2779
2915
  if (block.id === 'reply_list' && block.replyList) replyListWindow = block.replyList
2780
2916
  if (block.id === 'reply_viewer' && block.replyDoc) replyDocWindow = block.replyDoc
2781
- const chunk = place(block, budget - fullRows.length, width)
2917
+ const chunk = place(block, budget - fullRows.length, width, null)
2782
2918
  for (const l of chunk) fullRows.push(l)
2783
2919
  }
2784
2920
  add(fullRows)
@@ -2791,6 +2927,8 @@ export function layout(input: LayoutInput): Frame {
2791
2927
  // One placement pass over the page's body blocks; `cards` is re-derived so pass 2 can carry a
2792
2928
  // board with more history visible.
2793
2929
  const placeColumns = (cards: Block[]): [PlacedLine[], PlacedLine[]] => {
2930
+ // Each pass starts a fresh page order; the final pass is the one whose rows are rendered.
2931
+ pageOrder = []
2794
2932
  const columns: [PlacedLine[], PlacedLine[]] = [[], []]
2795
2933
  const ordered = [
2796
2934
  ...cards.filter((b) => !b.right).map((b) => ({ b, slot: 0 as 0 | 1 })),
@@ -2804,7 +2942,7 @@ export function layout(input: LayoutInput): Frame {
2804
2942
  // had a full column of empty width. `pickChrome` keeps every column within `bodyBudget`, so
2805
2943
  // the flush below still ends both columns on the same row.
2806
2944
  const used = columns[slot].length
2807
- const chunk = place(b, bodyBudget - used, colW)
2945
+ const chunk = place(b, bodyBudget - used, colW, pageOrder)
2808
2946
  for (const l of chunk) columns[slot].push(l)
2809
2947
  }
2810
2948
  return columns
@@ -2865,9 +3003,10 @@ export function layout(input: LayoutInput): Frame {
2865
3003
  } else {
2866
3004
  const columnW = width
2867
3005
  let used = 0
3006
+ pageOrder = []
2868
3007
  const ordered = [...leftBlocks, ...rightBlocks].sort((x, y) => x.priority - y.priority)
2869
3008
  for (const b of ordered) {
2870
- const chunk = place(b, bodyBudget - used, columnW)
3009
+ const chunk = place(b, bodyBudget - used, columnW, pageOrder)
2871
3010
  for (const l of chunk) rows.push({ line: truncLine(l.line, columnW), hits: l.hits })
2872
3011
  used += chunk.length
2873
3012
  }
@@ -2886,11 +3025,12 @@ export function layout(input: LayoutInput): Frame {
2886
3025
  }
2887
3026
  }
2888
3027
 
2889
- // The work page's row chips are rebuilt after placement: they exist only while the board block
2890
- // really draws rows, so a degraded work page has no clickable row key that cannot open anything
2891
- // (P20/B5). Both variants are one line, so the budget above is unaffected.
3028
+ // The work page's row chips are rebuilt after placement: they exist only while at least one block
3029
+ // really draws a focusable row, so a degraded work page has no clickable row key that cannot open
3030
+ // anything (P20/B5, generalised to the preview blocks in P249). Both variants are one line, so the
3031
+ // budget above is unaffected.
2892
3032
  const footerShown =
2893
- ctx.view.page === 2 && !ctx.view.detail && !ctx.view.overlay && !boardOrder ? keyBandBlock(ctx, false) : footer
3033
+ ctx.view.page === 2 && !ctx.view.detail && !ctx.view.overlay && !pageOrder.length ? keyBandBlock(ctx, false) : footer
2894
3034
 
2895
3035
  // The footer is the last row; when the height cannot even hold it, it is the only row kept.
2896
3036
  if (height > 0 && rows.length + footerShown.lines.length > height) {
@@ -2931,7 +3071,7 @@ export function layout(input: LayoutInput): Frame {
2931
3071
  ...(replyListWindow ? { replyList: replyListWindow } : {}),
2932
3072
  ...(replyDocWindow ? { replyDoc: replyDocWindow } : {}),
2933
3073
  ...(settingsWindow ? { settings: settingsWindow } : {}),
2934
- ...(boardOrder ? { boardOrder } : {}),
3074
+ ...(pageOrder.length ? { boardOrder: pageOrder } : {}),
2935
3075
  }
2936
3076
  }
2937
3077
 
@@ -54,7 +54,7 @@ import { fill, stringsFor } from './strings/index.js'
54
54
  import { PANEL_CONF_FILE, PANEL_PAGE_FILE, readPage, readSettings, writePage, writeSettings } from './settings.js'
55
55
  import type { Settings } from './settings.js'
56
56
  import { contrastPairs, PALETTES, resolveTheme } from './theme.js'
57
- import type { FrameInput, PageId, ViewState } from './types.js'
57
+ import type { FrameInput, PageId, ViewState, DetailSource } from './types.js'
58
58
 
59
59
  /** The Kitty keyboard protocol's pop/push pair, written around the editor handoff (design §6). */
60
60
  const KITTY_POP = '\u001b[<u'
@@ -168,6 +168,14 @@ const pageArg = argOf('page')
168
168
  const langArg = argOf('lang')
169
169
  /** `--detail <ID>`: render the read-only detail view in a snapshot (the overlay's sibling exit). */
170
170
  const detailArg = argOf('detail') || ''
171
+ /**
172
+ * `--detail-source entry|spec|change|decision`: the source the snapshot's detail view addresses.
173
+ * Read-only and snapshot-only — the live console passes its source through `api.setDetail`. An
174
+ * unrecognised value is ignored (entry), so the argument cannot open a way out of the closed set.
175
+ */
176
+ const detailSourceRaw = argOf('detail-source') || ''
177
+ const detailSourceArg =
178
+ detailSourceRaw === 'spec' || detailSourceRaw === 'change' || detailSourceRaw === 'decision' ? detailSourceRaw : 'entry'
171
179
  /**
172
180
  * Page 5's snapshot/demand knobs (pulse-key-replies). `--reply-no N` opens that number's viewer,
173
181
  * `--reply-before N` pins the list cursor and `--reply-focus N` pins the focused slot, so the
@@ -186,7 +194,7 @@ if (has('help')) {
186
194
  out(
187
195
  'usage: panel.js [--root DIR] [--state-dir DIR] [--print|--json|--once|--headless|--snapshot|--palette]\n' +
188
196
  ' [--width N] [--height N] [--activity|--no-activity] [--events N] [--refresh N]\n' +
189
- ' [--no-pulse] [--theme dark|light] [--page 1|2|3|4|5] [--lang zh|en] [--overlay] [--detail ID]\n' +
197
+ ' [--no-pulse] [--theme dark|light] [--page 1|2|3|4|5] [--lang zh|en] [--overlay] [--detail ID] [--detail-source entry|spec|change|decision]\n' +
190
198
  ' [--reply-no N] [--reply-before N] [--reply-focus N] [--version]\n',
191
199
  )
192
200
  process.exit(0)
@@ -346,6 +354,7 @@ async function main(): Promise<void> {
346
354
  activity: rawActivityOn,
347
355
  events,
348
356
  detailId: detailArg || null,
357
+ detailSource: detailArg ? detailSourceArg : null,
349
358
  replyListOpen: page === 5 && !replyNoArg,
350
359
  replyBefore: replyBeforeArg || null,
351
360
  replyNo: page === 5 && replyNoArg ? replyNoArg : null,
@@ -491,12 +500,19 @@ async function main(): Promise<void> {
491
500
  return ''
492
501
  }
493
502
  }
494
- function writeDraft(text: string): void {
503
+ /**
504
+ * Write `state/draft.md`. Returns whether the write landed: the send settle empties the file first
505
+ * and must know the result before it may drop the in-memory draft (change
506
+ * panel-preview-and-compose — memory and disk never disagree about the draft).
507
+ */
508
+ function writeDraft(text: string): boolean {
495
509
  try {
496
510
  mkdirSync(stateDir, { recursive: true })
497
511
  writeFileSync(draftFile, String(text ?? ''))
512
+ return true
498
513
  } catch {
499
514
  /* a state directory the console cannot write must not kill the panel */
515
+ return false
500
516
  }
501
517
  }
502
518
 
@@ -784,7 +800,7 @@ async function main(): Promise<void> {
784
800
  const api: PanelApi = {
785
801
  readDraft,
786
802
  writeDraft,
787
- clearDraft: () => writeDraft(''),
803
+ clearDraft: (): boolean => writeDraft(''),
788
804
  send,
789
805
  flushQueue,
790
806
  setStandby,
@@ -797,7 +813,8 @@ async function main(): Promise<void> {
797
813
  const read = await readClipboard(clipRunner)
798
814
  if (!read) return { kind: 'none' as const, value: '' }
799
815
  if (read.kind === 'text') return { kind: 'text' as const, value: read.text }
800
- const file = writePasteFile(read.bytes, read.mime)
816
+ // P309: the paste path uses the resolved temp root the data layer reports (no second resolution).
817
+ const file = writePasteFile(read.bytes, read.mime, cache.snapshot().data?.capacity?.temp_root)
801
818
  if (!file) return { kind: 'none' as const, value: '' }
802
819
  return { kind: 'path' as const, value: file }
803
820
  },
@@ -819,16 +836,24 @@ async function main(): Promise<void> {
819
836
  opts.activity = on
820
837
  refreshNow()
821
838
  },
822
- setDetail: (id: string | null, file?: string | null) => {
839
+ setDetail: (id: string | null, file?: string | null, source?: DetailSource | null) => {
823
840
  const nextId = id ?? null
824
841
  const nextFile = nextId ? file ?? null : null
825
- if ((opts.detailId ?? null) === nextId && (opts.detailFile ?? null) === nextFile) return
842
+ const nextSource: DetailSource = nextId ? source ?? 'entry' : 'entry'
843
+ if (
844
+ (opts.detailId ?? null) === nextId &&
845
+ (opts.detailFile ?? null) === nextFile &&
846
+ (opts.detailSource ?? 'entry') === nextSource
847
+ )
848
+ return
826
849
  opts.detailId = nextId
827
850
  opts.detailFile = nextFile
851
+ opts.detailSource = nextSource
828
852
  // The detail block is off the tick path: only the view's own open/tab-switch forces a build.
829
853
  if (!nextId) return
830
854
  // The cached block already serves this file (the open returns the first file without
831
- // `--file`): record the option and rebuild nothing, so the effect can stay idempotent.
855
+ // `--file`): record the option and rebuild nothing, so the effect can stay idempotent. The
856
+ // source is part of the identity — the same id from two sources is two different reads.
832
857
  const cached = cache.snapshot().blocks?.detail
833
858
  if (cached?.id === nextId && nextFile && cached.file === nextFile) return
834
859
  void cache.refresh({ force: true, only: ['detail'] }).then(adopt)