teamsmith 0.1.1 → 0.2.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 (104) hide show
  1. package/README.md +16 -8
  2. package/package.json +1 -1
  3. package/skills/teamsmith/CHANGELOG.md +55 -0
  4. package/skills/teamsmith/SKILL.md +18 -7
  5. package/skills/teamsmith/extension/team-bg.ts +47 -11
  6. package/skills/teamsmith/extension/team-notify.ts +143 -4
  7. package/skills/teamsmith/references/agent-adapters.md +7 -7
  8. package/skills/teamsmith/references/config.md +29 -15
  9. package/skills/teamsmith/references/migration.md +38 -2
  10. package/skills/teamsmith/references/openspec.md +23 -9
  11. package/skills/teamsmith/references/protocol.md +81 -13
  12. package/skills/teamsmith/references/workflows.md +31 -19
  13. package/skills/teamsmith/scripts/lib/cmd-agents.sh +210 -70
  14. package/skills/teamsmith/scripts/lib/cmd-bootstrap.sh +70 -9
  15. package/skills/teamsmith/scripts/lib/cmd-config.sh +222 -70
  16. package/skills/teamsmith/scripts/lib/cmd-death.sh +2 -15
  17. package/skills/teamsmith/scripts/lib/cmd-docs.sh +6 -3
  18. package/skills/teamsmith/scripts/lib/cmd-project.sh +134 -17
  19. package/skills/teamsmith/scripts/lib/cmd-reply.sh +96 -0
  20. package/skills/teamsmith/scripts/lib/cmd-review.sh +13 -10
  21. package/skills/teamsmith/scripts/lib/cmd-status.sh +42 -13
  22. package/skills/teamsmith/scripts/lib/cmd-watch.sh +75 -13
  23. package/skills/teamsmith/scripts/lib/common.sh +797 -71
  24. package/skills/teamsmith/scripts/monitor.mjs +34 -3
  25. package/skills/teamsmith/scripts/panel/README.md +22 -11
  26. package/skills/teamsmith/scripts/panel/panel.js +217 -215
  27. package/skills/teamsmith/scripts/panel/src/App.tsx +421 -164
  28. package/skills/teamsmith/scripts/panel/src/data.ts +84 -4
  29. package/skills/teamsmith/scripts/panel/src/layout.ts +502 -91
  30. package/skills/teamsmith/scripts/panel/src/main.tsx +97 -12
  31. package/skills/teamsmith/scripts/panel/src/settings.ts +1 -1
  32. package/skills/teamsmith/scripts/panel/src/strings/en.ts +56 -21
  33. package/skills/teamsmith/scripts/panel/src/strings/zh.ts +56 -21
  34. package/skills/teamsmith/scripts/panel/src/types.ts +178 -16
  35. package/skills/teamsmith/scripts/replies.mjs +893 -0
  36. package/skills/teamsmith/scripts/team +1 -0
  37. package/skills/teamsmith/templates/AGENTS.section.md.tmpl +15 -2
  38. package/skills/teamsmith/templates/BOARD.md.tmpl +2 -2
  39. package/skills/teamsmith/templates/OWNERSHIP.md.tmpl +7 -3
  40. package/skills/teamsmith/templates/PROTOCOL.md.tmpl +17 -0
  41. package/skills/teamsmith/templates/config.sh.tmpl +10 -5
  42. package/skills/teamsmith/templates/memory-seed.md.tmpl +3 -0
  43. package/skills/teamsmith/templates/pm-prompt.md.tmpl +20 -1
  44. package/skills/teamsmith/templates/report.md.tmpl +12 -0
  45. package/skills/teamsmith/templates/task.md.tmpl +4 -0
  46. package/skills/teamsmith/tests/bg-ledger-harness.mjs +682 -0
  47. package/skills/teamsmith/tests/bg-ledger.sh +307 -0
  48. package/skills/teamsmith/tests/checkout-shape-probe.sh +287 -58
  49. package/skills/teamsmith/tests/config-cli.sh +162 -288
  50. package/skills/teamsmith/tests/death-cause.sh +5 -2
  51. package/skills/teamsmith/tests/install-shape.sh +4 -2
  52. package/skills/teamsmith/tests/key-replies-pty.sh +375 -0
  53. package/skills/teamsmith/tests/key-replies-ui.sh +332 -0
  54. package/skills/teamsmith/tests/key-replies.sh +1075 -0
  55. package/skills/teamsmith/tests/ledger-ban.sh +5 -5
  56. package/skills/teamsmith/tests/ledger-claim.sh +247 -0
  57. package/skills/teamsmith/tests/lib/checkout-shape.sh +66 -14
  58. package/skills/teamsmith/tests/lib/model-policy.sh +26 -0
  59. package/skills/teamsmith/tests/lib/model-routing-boundary.sh +420 -0
  60. package/skills/teamsmith/tests/lib/model-routing-expansion.sh +155 -0
  61. package/skills/teamsmith/tests/lib/model-routing-flips.py +136 -0
  62. package/skills/teamsmith/tests/lib/model-routing-roles.sh +250 -0
  63. package/skills/teamsmith/tests/lib/proc-io.sh +103 -0
  64. package/skills/teamsmith/tests/lib/reply-fixture.sh +372 -0
  65. package/skills/teamsmith/tests/lib/tmux-iso.sh +8 -0
  66. package/skills/teamsmith/tests/panel-b2.sh +1 -1
  67. package/skills/teamsmith/tests/panel-b3-stub.sh +27 -0
  68. package/skills/teamsmith/tests/panel-b3.sh +14 -10
  69. package/skills/teamsmith/tests/panel-choices.sh +74 -61
  70. package/skills/teamsmith/tests/panel-cpu.sh +1 -1
  71. package/skills/teamsmith/tests/panel-p21.sh +311 -190
  72. package/skills/teamsmith/tests/perf.sh +1 -1
  73. package/skills/teamsmith/tests/pm-box-real.sh +1 -1
  74. package/skills/teamsmith/tests/pulse-nudge-key.sh +1 -1
  75. package/skills/teamsmith/tests/routes.sh +43 -22
  76. package/skills/teamsmith/tests/section-budgets.tsv +9 -5
  77. package/skills/teamsmith/tests/section-paths.tsv +26 -16
  78. package/skills/teamsmith/tests/section-select.sh +99 -16
  79. package/skills/teamsmith/tests/smoke.sh +930 -216
  80. package/skills/teamsmith/tests/snapshots/zh-dark-120-detail.txt +2 -2
  81. package/skills/teamsmith/tests/snapshots/zh-dark-120-p4.txt +2 -2
  82. package/skills/teamsmith/tests/snapshots/zh-dark-120.txt +9 -9
  83. package/skills/teamsmith/tests/snapshots/zh-dark-160-p4.txt +2 -2
  84. package/skills/teamsmith/tests/snapshots/zh-dark-160.txt +9 -9
  85. package/skills/teamsmith/tests/snapshots/zh-dark-59-detail.txt +1 -1
  86. package/skills/teamsmith/tests/snapshots/zh-dark-59-p4.txt +1 -1
  87. package/skills/teamsmith/tests/snapshots/zh-dark-59.txt +5 -5
  88. package/skills/teamsmith/tests/snapshots/zh-dark-99-p4.txt +2 -2
  89. package/skills/teamsmith/tests/snapshots/zh-dark-99.txt +5 -5
  90. package/skills/teamsmith/tests/snapshots/zh-light-120-detail.txt +2 -2
  91. package/skills/teamsmith/tests/snapshots/zh-light-120-p4.txt +2 -2
  92. package/skills/teamsmith/tests/snapshots/zh-light-120.txt +9 -9
  93. package/skills/teamsmith/tests/snapshots/zh-light-160-p4.txt +2 -2
  94. package/skills/teamsmith/tests/snapshots/zh-light-160.txt +9 -9
  95. package/skills/teamsmith/tests/snapshots/zh-light-59-detail.txt +1 -1
  96. package/skills/teamsmith/tests/snapshots/zh-light-59-p4.txt +1 -1
  97. package/skills/teamsmith/tests/snapshots/zh-light-59.txt +5 -5
  98. package/skills/teamsmith/tests/snapshots/zh-light-99-p4.txt +2 -2
  99. package/skills/teamsmith/tests/snapshots/zh-light-99.txt +5 -5
  100. package/skills/teamsmith/tests/task-header-model.sh +2 -1
  101. package/skills/teamsmith/tests/task-model-routing.sh +1014 -0
  102. package/skills/teamsmith-init/SKILL.md +38 -38
  103. package/skills/teamsmith-init/references/bootstrap.md +6 -4
  104. package/skills/teamsmith-init/templates/bootstrap-prompt.md.tmpl +9 -5
@@ -12,13 +12,31 @@
12
12
  import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
13
13
  import { writeSync } from 'node:fs'
14
14
  import { Box, Text, useApp, useCursor, useInput } from 'ink'
15
- import { layout, resolveFocus, focusRefOf, focusRow, rowKey, settingsViewRows } from './layout.js'
16
- import type { LayoutInput } from './layout.js'
15
+ import { layout, resolveFocus, focusRefOf, focusRow, rowKey, settingsRowFocusable, settingsViewRows } from './layout.js'
16
+ import type { LayoutInput, SettingsRow } from './layout.js'
17
17
  import { clockOf } from './format.js'
18
18
  import { fill, stringsFor, type Strings } from './strings/index.js'
19
19
  import { composeKey, cpLength, cursorView, insertAt, intake, killSpan, moveCursor, popUndo, pushKill, pushUndo, receiptLine, resetKillDirection, ringEntry, type ComposeMode, type ComposeView, type KillRing, type Receipt, type UndoSnapshot } from './compose.js'
20
20
  import type { Settings } from './settings.js'
21
- import type { Action, DetailWindow, FocusRef, FrameInput, PageId, PrefName, Segment, SettingsChoiceEntry, SettingsChoicePicker, SettingsKey, SettingsWindow, ViewState } from './types.js'
21
+ import type {
22
+ Action,
23
+ DetailWindow,
24
+ FocusRef,
25
+ FrameInput,
26
+ PageId,
27
+ PrefName,
28
+ ReplyDocWindow,
29
+ ReplyEntry,
30
+ ReplyWindow,
31
+ Segment,
32
+ SettingsBlock,
33
+ SettingsCategory,
34
+ SettingsChoiceEntry,
35
+ SettingsChoicePicker,
36
+ SettingsKey,
37
+ SettingsWindow,
38
+ ViewState,
39
+ } from './types.js'
22
40
  import type { Palette } from './theme.js'
23
41
  import { dispWidth } from './width.js'
24
42
 
@@ -27,13 +45,17 @@ const TRAY_TR = '╮'
27
45
  const TRAY_H = '─'
28
46
  const TRAY_V = '│'
29
47
 
48
+ /** The focusable row of the view as the App walks it (headings are skipped). */
49
+ type SettingsFocusRow = Extract<SettingsRow, { kind: 'key' | 'category' | 'assignment' | 'pm-launch' }>
50
+
30
51
  /**
31
52
  * The kinds whose editor is the choice picker (M55). `enum` joins only when the command reports
32
53
  * values (an enum with no constraints has no choice set: R3's visible fallback names the reason),
33
54
  * and a key the command reports without a `choices` object falls back to the compose editor — the
34
- * bundle works against an older command instead of inventing options.
55
+ * bundle works against an older command instead of inventing options. `task-model-map` is
56
+ * deliberately absent: its editor is the categories block (P232), never a composed pair list.
35
57
  */
36
- const CHOICE_KINDS = new Set(['bool', 'enum', 'int', 'seconds', 'mb', 'bytes', 'pct', 'path', 'model', 'pairlist', 'winlist', 'pattern'])
58
+ const CHOICE_KINDS = new Set(['bool', 'enum', 'int', 'seconds', 'mb', 'bytes', 'pct', 'path', 'model', 'winlist', 'pattern'])
37
59
  const NUMERIC_KINDS = new Set(['int', 'seconds', 'mb', 'bytes', 'pct'])
38
60
 
39
61
  function hasChoiceEditor(key: SettingsKey): boolean {
@@ -96,6 +118,13 @@ export interface PanelApi {
96
118
  * discovered file when omitted). Both are cached options, so an unchanged call rebuilds nothing.
97
119
  */
98
120
  setDetail(id: string | null, file?: string | null): void
121
+ /**
122
+ * Page 5's demand reads (pulse-key-replies): the list cursor (`before`, null = the newest page and
123
+ * null also drops the list from the wanted set when the page is parked) and the open viewer's
124
+ * number (`no`, null = closed). Both are request keys: changing one clears the cached block, kills
125
+ * the child still in flight and makes a late response for the old key a no-op.
126
+ */
127
+ setReply(opts: { list: boolean; before: number | null; no: number | null }): void
99
128
  /** Rebuild the patrol window as the headless tick loop (`team pulse collapse`). */
100
129
  collapse(): Promise<{ ok: boolean; line: string }>
101
130
  /** Represents one `team config set` result: the exit code (the machine contract) + one line. */
@@ -110,9 +139,9 @@ export interface PanelApi {
110
139
  * next interaction sees. Never awaited on the interaction path.
111
140
  */
112
141
  refreshSettingsSoon(): void
113
- /** One `team config set-agent-model <seat> <model|->` invocation (P22/B4). */
114
- setSeatModel(
115
- seat: string,
142
+ /** One `team config set-task-model <category> <model>` invocation (P232). */
143
+ setTaskModel(
144
+ category: string,
116
145
  model: string,
117
146
  opts: { dryRun?: boolean; fingerprint?: string | null },
118
147
  ): Promise<{ code: number; line: string }>
@@ -261,6 +290,14 @@ export function App({
261
290
  const [detailId, setDetailId] = useState<string | null>(null)
262
291
  const [detailIndex, setDetailIndex] = useState(0)
263
292
  const [detailScroll, setDetailScroll] = useState(0)
293
+ // Page 5 (pulse-key-replies): the cursor chain, the stable-number focus, the open body and the
294
+ // document's scroll. `replyStack` is the chain `Newer` walks back through — no full-history load.
295
+ const [replyFocus, setReplyFocus] = useState<number | null>(null)
296
+ const [replyCursor, setReplyCursor] = useState<number | null>(null)
297
+ const [replyStack, setReplyStack] = useState<number[]>([])
298
+ const [replyBody, setReplyBody] = useState<number | null>(null)
299
+ const [replyScroll, setReplyScroll] = useState(0)
300
+ const [replyOffset, setReplyOffset] = useState<number | null>(null)
264
301
  // P22/B2: the project-settings view (opened from the overlay's navigation row), its window and
265
302
  // its filter. The view is a view, not a page: the four-page composition and `state/panel-page`
266
303
  // keep their meaning, and `esc` lands back on the overlay row it was opened from.
@@ -276,9 +313,7 @@ export function App({
276
313
  const [settingsOffset, setSettingsOffset] = useState<number | null>(null)
277
314
  /** The pending two-step write confirmation ({danger} = the command answered 7). */
278
315
  const [settingConfirm, setSettingConfirm] = useState<{ key: string; next: string; danger: boolean } | null>(null)
279
- /** The seat picker (P22/B4): the seat, its row and the option list with the selection. */
280
- const [seatPicker, setSeatPicker] = useState<{ agent: string; row: number; models: string[]; index: number } | null>(null)
281
- /** The choice picker (M55): the key's schema-derived entries and the selection. */
316
+ /** The choice picker (M55/P232): the row's schema-derived entries and the selection. */
282
317
  const [choicePicker, setChoicePicker] = useState<SettingsChoicePicker | null>(null)
283
318
  const { exit } = useApp()
284
319
  const scrollRef = useRef(0)
@@ -299,6 +334,17 @@ export function App({
299
334
  const pasteOpenRef = useRef(false)
300
335
  const settingsRef = useRef(settings)
301
336
  const pageRef = useRef(page)
337
+ const replyFocusRef = useRef(replyFocus)
338
+ replyFocusRef.current = replyFocus
339
+ const replyCursorRef = useRef(replyCursor)
340
+ replyCursorRef.current = replyCursor
341
+ const replyStackRef = useRef(replyStack)
342
+ replyStackRef.current = replyStack
343
+ const replyBodyRef = useRef(replyBody)
344
+ replyBodyRef.current = replyBody
345
+ /** Page 5's list window / the viewer's document window as the last frame rendered them. */
346
+ const replyListRef = useRef<ReplyWindow | null>(null)
347
+ const replyDocRef = useRef<ReplyDocWindow | null>(null)
302
348
  const targetsRef = useRef<{ row: number; hit: { start: number; end: number; action: Action } }[]>([])
303
349
  const overlayIndexRef = useRef(0)
304
350
  const focusRef = useRef<FocusRef | null>(null)
@@ -316,10 +362,12 @@ export function App({
316
362
  const settingsOffsetRef = useRef<number | null>(null)
317
363
  /** The row window the last frame drew (the wheel and the focus keys clamp against it). */
318
364
  const settingsWindowRef = useRef<SettingsWindow | null>(null)
319
- /** The row the open `setting` editor writes (the fingerprint was pinned when it opened). */
320
- const settingRowRef = useRef<{ row: number; key: string; value: string; cls: string; fingerprint: string; seat?: string; kind?: string; choices?: SettingsKey['choices'] } | null>(null)
321
- const seatPickerRef = useRef<{ agent: string; row: number; models: string[]; index: number } | null>(null)
322
- seatPickerRef.current = seatPicker
365
+ /**
366
+ * The row the open `setting` editor writes (the fingerprint was pinned when it opened).
367
+ * `category` is set when the row is a task category: the same editor then writes through
368
+ * `team config set-task-model <category> <model>` instead of `team config set <KEY>` (P232).
369
+ */
370
+ const settingRowRef = useRef<{ row: number; key: string; value: string; cls: string; fingerprint: string; category?: string; kind?: string; choices?: SettingsKey['choices'] } | null>(null)
323
371
  const choicePickerRef = useRef<SettingsChoicePicker | null>(null)
324
372
  choicePickerRef.current = choicePicker
325
373
  const settingConfirmRef = useRef<{ key: string; next: string; danger: boolean } | null>(null)
@@ -360,8 +408,21 @@ export function App({
360
408
 
361
409
  const goPage = useCallback(
362
410
  (next: PageId) => {
411
+ const previous = pageRef.current
363
412
  pageRef.current = next
364
413
  setPage(next)
414
+ // Page 5's demand reads follow the page: entering it starts a fresh newest chain, leaving it
415
+ // closes the viewer — which is what drops the `reply_body` request (design §4: no body read
416
+ // after leaving page 5).
417
+ if (next === 5 && previous !== 5) {
418
+ setReplyCursor(null)
419
+ setReplyStack([])
420
+ setReplyFocus(null)
421
+ setReplyOffset(null)
422
+ setReplyBody(null)
423
+ } else if (next !== 5) {
424
+ setReplyBody(null)
425
+ }
365
426
  setViewEntry(null)
366
427
  setDetailId(null)
367
428
  setDetailIndex(0)
@@ -521,12 +582,18 @@ export function App({
521
582
  const conf = settingConfirmRef.current
522
583
  const timing =
523
584
  target.cls === 'restart' ? stringsRef.current.settingTimingRestart : stringsRef.current.settingTimingApply
524
- const isSeat = Boolean(target.seat)
525
- const seatModel = text.trim() === '' ? '-' : text.trim()
585
+ // P232: a category row keeps the same editor, but its write is the CLI's per-category
586
+ // command (`set-task-model`) — the console never composes the pair list.
526
587
  const call = (dryRun: boolean, allowDanger: boolean): Promise<{ code: number; line: string }> =>
527
- isSeat
528
- ? api.setSeatModel(target.seat as string, seatModel, { dryRun, fingerprint: target.fingerprint })
588
+ target.category
589
+ ? api.setTaskModel(target.category, text, { dryRun, fingerprint: target.fingerprint })
529
590
  : api.setSetting(target.key, text, { dryRun, fingerprint: target.fingerprint, allowDanger })
591
+ const written = (): string =>
592
+ target.category
593
+ ? fill(stringsRef.current.settingCategoryWritten, { category: target.category, value: text })
594
+ : target.key === 'TEAM_PM_MODEL'
595
+ ? fill(stringsRef.current.settingPmWritten, { value: text })
596
+ : fill(stringsRef.current.settingWritten, { key: target.key, value: text, timing })
530
597
  if (!conf) {
531
598
  const r = await call(true, false)
532
599
  if (r.code === 0) {
@@ -534,11 +601,11 @@ export function App({
534
601
  setSettingConfirm(settingConfirmRef.current)
535
602
  setReceipt(null)
536
603
  setStatus(
537
- isSeat
538
- ? fill(stringsRef.current.settingSeatConfirm, {
539
- seat: target.seat as string,
604
+ target.category
605
+ ? fill(stringsRef.current.settingCategoryConfirm, {
606
+ category: target.category,
540
607
  old: target.value || stringsRef.current.dash,
541
- next: seatModel === '-' ? stringsRef.current.dash : seatModel,
608
+ next: text,
542
609
  })
543
610
  : fill(stringsRef.current.settingConfirm, {
544
611
  key: target.key,
@@ -570,14 +637,7 @@ export function App({
570
637
  const r = await call(false, conf.danger)
571
638
  if (r.code === 0) {
572
639
  setReceipt(null)
573
- const fallback = dataRef.current.blocks?.settings?.models?.default ?? ''
574
- setStatus(
575
- isSeat
576
- ? seatModel === '-'
577
- ? fill(stringsRef.current.settingSeatRemoved, { seat: target.seat as string, value: fallback || stringsRef.current.dash })
578
- : fill(stringsRef.current.settingSeatWritten, { seat: target.seat as string, value: seatModel })
579
- : fill(stringsRef.current.settingWritten, { key: target.key, value: text, timing }),
580
- )
640
+ setStatus(written())
581
641
  settingRowRef.current = null
582
642
  settingConfirmRef.current = null
583
643
  setSettingConfirm(null)
@@ -745,9 +805,10 @@ export function App({
745
805
  next.lang = cur.lang === 'zh' ? 'en' : 'zh'
746
806
  break
747
807
  case 'defaultPage':
748
- // Four pages since P18/B2: the cycle covers 1–4 and wraps (the old three-page test let 4
749
- // fall through to 5, which the next launch rejects as out of range — a silent reset).
750
- next.defaultPage = cur.defaultPage === 4 ? 1 : ((cur.defaultPage + 1) as PageId)
808
+ // Five pages since pulse-key-replies: the cycle covers 1–5 and wraps (a cycle that still
809
+ // stopped at 4 would leave 5 unreachable as a remembered default and reset it on the next
810
+ // launch — the silent reset this branch exists to avoid).
811
+ next.defaultPage = cur.defaultPage === 5 ? 1 : ((cur.defaultPage + 1) as PageId)
751
812
  goPage(next.defaultPage)
752
813
  break
753
814
  case 'activity':
@@ -908,9 +969,9 @@ export function App({
908
969
  // ---- project settings (P22/B2): the view's focus walk, its origin and its row opening.
909
970
 
910
971
  /** The view's focusable rows as the last assembly saw them (the walk must match the screen). */
911
- const settingsRowsNow = useCallback((): ({ kind: 'key'; key: import('./types.js').SettingsKey } | { kind: 'seat'; seat: import('./types.js').SettingsSeat })[] => {
972
+ const settingsRowsNow = useCallback((): SettingsFocusRow[] => {
912
973
  const rows = settingsViewRows(dataRef.current.blocks?.settings, settingsFilterRef.current, stringsRef.current)
913
- return rows.filter((r): r is { kind: 'key'; key: import('./types.js').SettingsKey } | { kind: 'seat'; seat: import('./types.js').SettingsSeat } => r.kind === 'key' || r.kind === 'seat')
974
+ return rows.filter(settingsRowFocusable)
914
975
  }, [])
915
976
 
916
977
  const moveSettingsFocus = useCallback(
@@ -991,7 +1052,7 @@ export function App({
991
1052
  pushValue(key.value, 'current')
992
1053
  pushValue(key.default, 'default')
993
1054
  for (const v of values) pushValue(v, 'value')
994
- if (kind === 'bool' || kind === 'enum' || kind === 'pairlist') return out
1055
+ if (kind === 'bool' || kind === 'enum') return out
995
1056
  if (kind === 'path') {
996
1057
  if (ch.empty) out.push({ value: '', kind: 'clear' })
997
1058
  out.push({ value: '', kind: 'free', seed: base })
@@ -1018,6 +1079,21 @@ export function App({
1018
1079
  const choiceTarget = useCallback(
1019
1080
  (picker: SettingsChoicePicker): NonNullable<typeof settingRowRef.current> => {
1020
1081
  const rows = settingsRowsNow()
1082
+ const fingerprint = dataRef.current.blocks?.settings?.fingerprint ?? ''
1083
+ if (picker.category) {
1084
+ // P232: a category picker writes `set-task-model <category> <model>`; its "current" value is
1085
+ // the future policy's model for that category — read from the row the picker was opened on.
1086
+ const catNow = rows.find((r) => r.kind === 'category' && r.category.category === picker.key)
1087
+ return {
1088
+ row: picker.row,
1089
+ key: picker.key,
1090
+ value: catNow && catNow.kind === 'category' ? catNow.category.model : '',
1091
+ cls: 'apply',
1092
+ fingerprint,
1093
+ category: picker.key,
1094
+ kind: picker.kind,
1095
+ }
1096
+ }
1021
1097
  // By key name, not by index: the picker's row index is a focus index and the row list can be
1022
1098
  // replaced by a settle re-read while the picker is open.
1023
1099
  const rowNow = rows.find((r) => r.kind === 'key' && r.key.name === picker.key) ?? rows[picker.row]
@@ -1027,7 +1103,7 @@ export function App({
1027
1103
  key: picker.key,
1028
1104
  value: keyNow?.value ?? '',
1029
1105
  cls: keyNow?.class ?? 'apply',
1030
- fingerprint: dataRef.current.blocks?.settings?.fingerprint ?? '',
1106
+ fingerprint,
1031
1107
  kind: picker.kind,
1032
1108
  choices: keyNow?.choices,
1033
1109
  }
@@ -1051,11 +1127,23 @@ export function App({
1051
1127
  setBusy(true)
1052
1128
  const timing =
1053
1129
  target.cls === 'restart' ? stringsRef.current.settingTimingRestart : stringsRef.current.settingTimingApply
1130
+ // P232: a category accept writes through the CLI's per-category command; a key accept keeps
1131
+ // the contract-set path. Both are the owning command's subprocess — never a direct write.
1132
+ const call = (dryRun: boolean, allowDanger: boolean): Promise<{ code: number; line: string }> =>
1133
+ target.category
1134
+ ? api.setTaskModel(target.category, value, { dryRun, fingerprint: target.fingerprint })
1135
+ : api.setSetting(target.key, value, { dryRun, fingerprint: target.fingerprint, allowDanger })
1136
+ const writtenLine = (): string =>
1137
+ target.category
1138
+ ? fill(stringsRef.current.settingCategoryWritten, { category: target.category, value })
1139
+ : target.key === 'TEAM_PM_MODEL'
1140
+ ? fill(stringsRef.current.settingPmWritten, { value })
1141
+ : fill(stringsRef.current.settingWritten, { key: target.key, value, timing })
1054
1142
  try {
1055
1143
  const danger = choiceDangerRef.current
1056
1144
  const dangerAccept = Boolean(danger && danger.key === target.key && danger.value === value)
1057
1145
  if (!dangerAccept) {
1058
- const dry = await api.setSetting(target.key, value, { dryRun: true, fingerprint: target.fingerprint })
1146
+ const dry = await call(true, false)
1059
1147
  if (dry.code === 7) {
1060
1148
  choiceDangerRef.current = { key: target.key, value }
1061
1149
  setReceipt(null)
@@ -1079,15 +1167,11 @@ export function App({
1079
1167
  return
1080
1168
  }
1081
1169
  }
1082
- const r = await api.setSetting(target.key, value, {
1083
- dryRun: false,
1084
- fingerprint: target.fingerprint,
1085
- allowDanger: dangerAccept,
1086
- })
1170
+ const r = await call(false, dangerAccept)
1087
1171
  choiceDangerRef.current = null
1088
1172
  if (r.code === 0) {
1089
1173
  setReceipt(null)
1090
- setStatus(fill(stringsRef.current.settingWritten, { key: target.key, value, timing }))
1174
+ setStatus(writtenLine())
1091
1175
  settingRowRef.current = null
1092
1176
  setChoicePicker(null)
1093
1177
  choicePickerRef.current = null
@@ -1121,29 +1205,30 @@ export function App({
1121
1205
  )
1122
1206
 
1123
1207
  /**
1124
- * The pairlist row's editor is the seats block (the requirement that owns per-seat editing):
1125
- * `enter` moves the focus there, no compose editor and no option list opens. A filter that hides
1126
- * the seats is dropped, because otherwise "focus the seats block" would name a row that is not
1127
- * on screen.
1208
+ * The whole-map row's editor is the categories block (P232): `enter` moves the focus to the first
1209
+ * category row — no compose editor, no option list, and the pair list is never composed here. A
1210
+ * filter that hides the block is dropped, because otherwise "focus the categories block" would
1211
+ * name a row that is not on screen. When the policy carries no category at all (a legacy or empty
1212
+ * map) the block has nothing to focus: the CLI route is named instead, and nothing is written.
1128
1213
  */
1129
- const routePairlist = useCallback(() => {
1214
+ const routeCategories = useCallback(() => {
1130
1215
  const rows = settingsRowsNow()
1131
- let seat = rows.findIndex((r) => r.kind === 'seat')
1132
- if (seat < 0) {
1216
+ let at = rows.findIndex((r) => r.kind === 'category')
1217
+ if (at < 0) {
1133
1218
  settingsFilterRef.current = ''
1134
1219
  setSettingsFilter('')
1135
1220
  // The focus index counts focusable rows, not the group headings `settingsViewRows` also
1136
1221
  // returns — counting those would land the cursor on the wrong row (or past the end).
1137
- const all = settingsViewRows(dataRef.current.blocks?.settings, '', stringsRef.current).filter(
1138
- (r) => r.kind === 'key' || r.kind === 'seat',
1139
- )
1140
- seat = all.findIndex((r) => r.kind === 'seat')
1222
+ const all = settingsRowsNow()
1223
+ at = all.findIndex((r) => r.kind === 'category')
1141
1224
  }
1142
1225
  setChoicePicker(null)
1143
1226
  choicePickerRef.current = null
1144
- if (seat >= 0) setSettingsFocus(seat)
1227
+ if (at >= 0) setSettingsFocus(at)
1145
1228
  setReceipt(null)
1146
- setStatus(stringsRef.current.settingsChoicePairlist)
1229
+ setStatus(
1230
+ at >= 0 ? stringsRef.current.settingsCategoryMapHint : stringsRef.current.settingsCategoryMapEmpty,
1231
+ )
1147
1232
  }, [settingsRowsNow])
1148
1233
 
1149
1234
  /**
@@ -1232,8 +1317,6 @@ export function App({
1232
1317
  setSettingsOffset(null)
1233
1318
  settingsOffsetRef.current = null
1234
1319
  settingsWindowRef.current = null
1235
- setSeatPicker(null)
1236
- seatPickerRef.current = null
1237
1320
  setChoicePicker(null)
1238
1321
  choicePickerRef.current = null
1239
1322
  api.setSettingsOpen(false)
@@ -1243,9 +1326,40 @@ export function App({
1243
1326
  overlayIndexRef.current = settingsOrigin
1244
1327
  }, [api, settingsOrigin])
1245
1328
 
1329
+ /**
1330
+ * Builds the entries of a category picker (P232). The vocabulary is exactly the project's own:
1331
+ * the policy's model for the category when there is one, then the models the command reports as
1332
+ * known — plus the free-text entry. The machine's Pi catalogue is not a source here, and there is
1333
+ * no removal entry: the writer has no per-category delete, so the console must not invent one.
1334
+ */
1335
+ const buildCategoryEntries = useCallback(
1336
+ (cat: SettingsCategory): SettingsChoiceEntry[] => {
1337
+ const known = dataRef.current.blocks?.settings?.models?.known ?? []
1338
+ const synthetic: SettingsKey = {
1339
+ name: cat.category,
1340
+ class: 'apply',
1341
+ kind: 'model',
1342
+ form: 'plain',
1343
+ value: cat.model,
1344
+ default: '',
1345
+ set: cat.model !== '',
1346
+ comment: '',
1347
+ warning: '',
1348
+ route: '',
1349
+ choices: { source: 'known', values: [...known], min: '', max: '', empty: false, note: '' },
1350
+ group: 'task-model',
1351
+ known: true,
1352
+ }
1353
+ return buildChoiceEntries(synthetic)
1354
+ },
1355
+ [buildChoiceEntries],
1356
+ )
1357
+
1246
1358
  /**
1247
1359
  * Enter on a view row: a `refuse` row opens no editor and surfaces the owning command's route;
1248
- * an editable row opens the value editor (the compose line's `setting` mode, B3).
1360
+ * an editable row opens the value editor (the compose line's `setting` mode, B3); a category row
1361
+ * opens its own picker (P232); a committed assignment is read-only and only names the route that
1362
+ * decides it.
1249
1363
  */
1250
1364
  const openSettingsRow = useCallback(
1251
1365
  (index: number) => {
@@ -1255,31 +1369,49 @@ export function App({
1255
1369
  const at = index < 0 ? settingsFocusRef.current : index
1256
1370
  const row = rows[at]
1257
1371
  if (!row) return
1258
- if (row.kind === 'seat') {
1259
- // The picker: the command's known models, then the removal and the free-text line. The
1260
- // editor opens on the chosen option so the two-step confirmation has a surface.
1261
- const models = [...(dataRef.current.blocks?.settings?.models?.known ?? [])]
1262
- setSeatPicker({ agent: row.seat.agent, row: at, models, index: 0 })
1263
- seatPickerRef.current = { agent: row.seat.agent, row: at, models, index: 0 }
1372
+ if (row.kind === 'category') {
1373
+ const entries = buildCategoryEntries(row.category)
1374
+ const picker: SettingsChoicePicker = {
1375
+ row: at,
1376
+ key: row.category.category,
1377
+ kind: 'model',
1378
+ entries,
1379
+ index: 0,
1380
+ interval: null,
1381
+ category: true,
1382
+ }
1383
+ choiceDangerRef.current = null
1384
+ setChoicePicker(picker)
1385
+ choicePickerRef.current = picker
1264
1386
  setReceipt(null)
1265
1387
  setStatus(null)
1266
1388
  return
1267
1389
  }
1390
+ if (row.kind === 'assignment' || row.kind === 'pm-launch') {
1391
+ // Read-only: the actual model is the committed record's, decided by dispatch/resume. The
1392
+ // console offers no editor for it (and never a "restart this seat" action).
1393
+ setReceipt(null)
1394
+ setChoicePicker(null)
1395
+ choicePickerRef.current = null
1396
+ setStatus(row.kind === 'assignment' ? stringsRef.current.settingsAssignmentHint : stringsRef.current.settingsPmLaunchHint)
1397
+ return
1398
+ }
1268
1399
  const key = row.key
1269
1400
  if (key.class === 'refuse') {
1270
1401
  setReceipt(null)
1271
1402
  setStatus(`${key.name} · ${key.route || key.warning || stringsRef.current.settingsRefusedRoute}`)
1272
1403
  return
1273
1404
  }
1405
+ // The whole-map row's editor is the categories block, never a composed pair list (P232).
1406
+ if (String(key.kind ?? '') === 'task-model-map') {
1407
+ routeCategories()
1408
+ return
1409
+ }
1274
1410
  // M65/D11: the editor opens on the `settings` block already on screen — no `config list` or
1275
1411
  // `__panel-data` stands between the keystroke and the frame that answers it. The fingerprint
1276
1412
  // is that block's, so a contract changed underneath is the owning command's conflict verdict
1277
1413
  // (CAS), not a reason to re-read before every action.
1278
1414
  if (hasChoiceEditor(key)) {
1279
- if (String(key.kind ?? '') === 'pairlist') {
1280
- routePairlist()
1281
- return
1282
- }
1283
1415
  const entries = buildChoiceEntries(key)
1284
1416
  if (entries.length) {
1285
1417
  const kind = String(key.kind ?? '')
@@ -1300,7 +1432,7 @@ export function App({
1300
1432
  }
1301
1433
  }
1302
1434
  settingRowRef.current = {
1303
- row: index,
1435
+ row: at,
1304
1436
  key: key.name,
1305
1437
  value: key.value,
1306
1438
  cls: key.class,
@@ -1317,63 +1449,9 @@ export function App({
1317
1449
  setStatus(fill(stringsRef.current.settingsChoiceNoChoice, { kind: String(key.kind ?? '') }))
1318
1450
  }
1319
1451
  },
1320
- [buildChoiceEntries, openCompose, routePairlist, settingsRowsNow],
1452
+ [buildCategoryEntries, buildChoiceEntries, openCompose, routeCategories, settingsRowsNow],
1321
1453
  )
1322
1454
 
1323
- /**
1324
- * One picker choice: a model opens the editor holding it, `-` opens it holding the removal,
1325
- * the free-text row opens it empty. The editor's two Enter presses are the confirmation.
1326
- */
1327
- /** Resolve a picker index (or -1 = the selected one) into the picker + its option. */
1328
- const pickerIndex = useCallback(
1329
- (index: number): { picker: { agent: string; row: number; models: string[]; index: number }; option: string } | null => {
1330
- const p = seatPickerRef.current
1331
- if (!p) return null
1332
- const options = [...p.models, '-', '']
1333
- const i = index < 0 ? p.index : index
1334
- if (i < 0 || i >= options.length) return null
1335
- return { picker: p, option: options[i] }
1336
- },
1337
- [],
1338
- )
1339
-
1340
- const chooseSeatOption = useCallback(
1341
- (index: number) => {
1342
- const picker = pickerIndex(index)
1343
- if (!picker) return
1344
- const { picker: p, option } = picker
1345
- const seat = p.agent
1346
- // M65/D11: the editor opens from the block already on screen (no read on the interaction
1347
- // path); its fingerprint is that block's, so CAS catches a contract changed underneath.
1348
- const block = dataRef.current.blocks?.settings
1349
- const seatRow = (block?.models?.seats ?? []).find((x) => x.agent === seat)
1350
- const initial = option === '' ? '' : option
1351
- settingRowRef.current = {
1352
- row: p.row,
1353
- key: seat,
1354
- value: seatRow?.model ?? '',
1355
- cls: 'restart',
1356
- fingerprint: block?.fingerprint ?? '',
1357
- seat,
1358
- }
1359
- settingConfirmRef.current = null
1360
- setSettingConfirm(null)
1361
- setSeatPicker(null)
1362
- seatPickerRef.current = null
1363
- openCompose('setting', initial)
1364
- },
1365
- [openCompose, pickerIndex],
1366
- )
1367
-
1368
- const moveSeatPicker = useCallback((delta: number) => {
1369
- const p = seatPickerRef.current
1370
- if (!p) return
1371
- const count = p.models.length + 2
1372
- const next = { ...p, index: Math.max(0, Math.min(count - 1, p.index + delta)) }
1373
- seatPickerRef.current = next
1374
- setSeatPicker(next)
1375
- }, [])
1376
-
1377
1455
  /** The detail view's file tabs: `←`/`→` clamp at the ends (no wrap — the row shows the order). */
1378
1456
  const moveDetailTab = useCallback((delta: number) => {
1379
1457
  const files = dataRef.current.blocks?.detail?.files ?? []
@@ -1406,6 +1484,94 @@ export function App({
1406
1484
  api.setDetail(detailId, files[detailIndexRef.current]?.path ?? null)
1407
1485
  }, [api, detailId, detailIndex, detailBlockData])
1408
1486
 
1487
+ /** Page 5's slots as the last snapshot carries them (never a re-read of the store). */
1488
+ const replyEntries = useCallback((): ReplyEntry[] => dataRef.current.blocks?.reply_list?.entries ?? [], [])
1489
+
1490
+ /** Page 5's `↑`/`↓`: the focus walks the drawn rows; the window follows it (offset = null). */
1491
+ const moveReplyFocus = useCallback(
1492
+ (delta: number) => {
1493
+ const entries = replyEntries()
1494
+ if (!entries.length) return
1495
+ const at = entries.findIndex((e) => e.no === replyFocusRef.current)
1496
+ const next = Math.max(0, Math.min(entries.length - 1, (at < 0 ? 0 : at) + delta))
1497
+ setReplyFocus(entries[next].no)
1498
+ setReplyOffset(null)
1499
+ },
1500
+ [replyEntries],
1501
+ )
1502
+
1503
+ /**
1504
+ * Page 5's `Older`/`Newer`. Older fetches the page's own `next_before` and pushes the cursor the
1505
+ * current page was fetched with onto the chain; Newer pops it — the retained chain is what lets
1506
+ * the user walk back without a full-history load, and `0` in the chain means "the newest page".
1507
+ */
1508
+ const replyPage = useCallback(
1509
+ (dir: -1 | 1) => {
1510
+ const list = dataRef.current.blocks?.reply_list
1511
+ if (!list) return
1512
+ if (dir === 1) {
1513
+ const stack = replyStackRef.current
1514
+ if (!stack.length) return
1515
+ const back = stack[stack.length - 1]
1516
+ setReplyStack(stack.slice(0, -1))
1517
+ setReplyCursor(back === 0 ? null : back)
1518
+ } else {
1519
+ const older = list.next_before
1520
+ if (!older) return
1521
+ setReplyStack([...replyStackRef.current, replyCursorRef.current ?? 0])
1522
+ setReplyCursor(older)
1523
+ }
1524
+ setReplyFocus(null)
1525
+ setReplyOffset(null)
1526
+ },
1527
+ [],
1528
+ )
1529
+
1530
+ /** `r` on page 5: drop the chain and fetch the newest page again. */
1531
+ const replyReset = useCallback(() => {
1532
+ setReplyCursor(null)
1533
+ setReplyStack([])
1534
+ setReplyFocus(null)
1535
+ setReplyOffset(null)
1536
+ }, [])
1537
+
1538
+ /** Open a numbered body (a click on the focused row, or Enter on it). */
1539
+ const openReply = useCallback(
1540
+ (index?: number) => {
1541
+ const entries = replyEntries()
1542
+ const entry = index != null ? entries[index] : (entries.find((e) => e.no === replyFocusRef.current) ?? entries[0])
1543
+ if (!entry || !entry.available) return
1544
+ setReplyBody(entry.no)
1545
+ setReplyScroll(0)
1546
+ },
1547
+ [replyEntries],
1548
+ )
1549
+
1550
+ /** The viewer document's scroll, clamped against the window the last frame reported. */
1551
+ const scrollReply = useCallback((delta: number) => {
1552
+ const win = replyDocRef.current
1553
+ const max = win ? Math.max(0, win.total - win.visible) : 0
1554
+ setReplyScroll((v) => Math.max(0, Math.min(max, v + delta)))
1555
+ }, [])
1556
+
1557
+ /**
1558
+ * Page 5's demand reads (design §4): the list is wanted only on page 5 — and only for the cursor
1559
+ * in view — while the body is wanted only while the viewer is open. Leaving the page clears both,
1560
+ * so a parked console spawns neither child. `setReply` is idempotent for an unchanged pair, so
1561
+ * this effect (and a re-render) never forces a rebuild of what is already on screen.
1562
+ */
1563
+ const replyListData = data.blocks?.reply_list
1564
+ const replyBodyData = data.blocks?.reply_body
1565
+ useEffect(() => {
1566
+ api.setReply({ list: page === 5 && replyBody == null, before: replyCursor, no: replyBody })
1567
+ }, [api, page, replyCursor, replyBody])
1568
+
1569
+ // A body that left the store between the click and the read: keep the list usable rather than
1570
+ // pinning the viewer on a number the readers refuse (the viewer itself renders the notice).
1571
+ useEffect(() => {
1572
+ if (replyBody != null && replyBodyData == null) return
1573
+ }, [replyBody, replyBodyData])
1574
+
1409
1575
  const dispatch = useCallback(
1410
1576
  (action: Action) => {
1411
1577
  switch (action.kind) {
@@ -1426,7 +1592,7 @@ export function App({
1426
1592
  goPage(action.page)
1427
1593
  return
1428
1594
  case 'page-cycle':
1429
- goPage(pageRef.current === 3 ? 1 : ((pageRef.current + 1) as PageId))
1595
+ goPage(pageRef.current === 5 ? 1 : ((pageRef.current + 1) as PageId))
1430
1596
  return
1431
1597
  case 'scroll':
1432
1598
  updateScroll((v) => v + action.delta)
@@ -1449,6 +1615,47 @@ export function App({
1449
1615
  case 'focus':
1450
1616
  setFocus({ lane: action.lane, id: action.id, nth: action.nth ?? 0 })
1451
1617
  return
1618
+ case 'reply-click': {
1619
+ // One action, two behaviours (the kanban's rule): a click on an unfocused row focuses it,
1620
+ // a click on the already focused row opens its body.
1621
+ const entries = replyEntries()
1622
+ const entry = entries[action.index]
1623
+ if (!entry) return
1624
+ if (replyFocusRef.current === entry.no) openReply(action.index)
1625
+ else {
1626
+ setReplyFocus(entry.no)
1627
+ setReplyOffset(null)
1628
+ }
1629
+ return
1630
+ }
1631
+ case 'reply-move':
1632
+ moveReplyFocus(action.delta)
1633
+ return
1634
+ case 'reply-page':
1635
+ replyPage(action.dir)
1636
+ return
1637
+ case 'reply-reset':
1638
+ replyReset()
1639
+ return
1640
+ case 'reply-open':
1641
+ openReply(action.index)
1642
+ return
1643
+ case 'reply-scroll':
1644
+ scrollReply(action.delta)
1645
+ return
1646
+ case 'reply-close':
1647
+ // Back to the list with its cursor, focus and viewport untouched.
1648
+ setReplyBody(null)
1649
+ return
1650
+ case 'reply-open-latest':
1651
+ replyReset()
1652
+ goPage(5)
1653
+ if (action.no) {
1654
+ setReplyFocus(action.no)
1655
+ setReplyBody(action.no)
1656
+ setReplyScroll(0)
1657
+ }
1658
+ return
1452
1659
  case 'open-focused': {
1453
1660
  // One action kind, two pages: the kanban resolves its lane/card focus, the work page the
1454
1661
  // drawn row order (P20/B5).
@@ -1516,16 +1723,9 @@ export function App({
1516
1723
  case 'choice-close':
1517
1724
  closeChoicePicker()
1518
1725
  return
1519
- case 'seat-pick':
1520
- if (action.index < 0) chooseSeatOption(-1)
1521
- else chooseSeatOption(action.index)
1522
- return
1523
- case 'seat-move':
1524
- moveSeatPicker(action.delta)
1525
- return
1526
1726
  }
1527
1727
  },
1528
- [boardRows, chooseChoiceOption, closeChoicePicker, closeSettingsView, collapse, cyclePref, goPage, moveBoardFocus, moveChoicePicker, moveDetailTab, moveFocus, moveSeatPicker, moveSettingsFocus, openCompose, openDetail, openSettingsRow, openSettingsView, openWorkFocused, runAction, scrollDetail, scrollLane, scrollSettings, toggleLaneFold, updateScroll],
1728
+ [boardRows, chooseChoiceOption, closeChoicePicker, closeSettingsView, collapse, cyclePref, goPage, moveBoardFocus, moveChoicePicker, moveDetailTab, moveFocus, moveSettingsFocus, openCompose, openDetail, openSettingsRow, openSettingsView, openWorkFocused, runAction, scrollDetail, scrollLane, scrollSettings, toggleLaneFold, updateScroll],
1529
1729
  )
1530
1730
 
1531
1731
  const effectiveActivity = activityPinned ? data.activity : settings.activity
@@ -1597,8 +1797,13 @@ export function App({
1597
1797
  settingsFocus,
1598
1798
  settingsFilter,
1599
1799
  settingsOffset,
1600
- seatPicker,
1601
1800
  choicePicker,
1801
+ replyFocus,
1802
+ replyCursor,
1803
+ replyBody,
1804
+ replyScroll,
1805
+ replyOffset,
1806
+ replyBodyFailed: Boolean(data.replyBodyFailed) && replyBodyData == null,
1602
1807
  }
1603
1808
  // The geometry comes from the live terminal, not from the frame's snapshot of it: a resize must
1604
1809
  // re-lay out the next frame (the spec's "A resize re-lays out live"), and `data.width` is frozen
@@ -1619,6 +1824,8 @@ export function App({
1619
1824
  boardOrderRef.current = themed.boardOrder ?? []
1620
1825
  detailRef.current = themed.detail ?? null
1621
1826
  settingsWindowRef.current = themed.settings ?? null
1827
+ replyListRef.current = themed.replyList ?? null
1828
+ replyDocRef.current = themed.replyDoc ?? null
1622
1829
  return { frame: themed, input, hint, bottom, pad, boxed, inputView }
1623
1830
  }, [
1624
1831
  data,
@@ -1643,8 +1850,12 @@ export function App({
1643
1850
  settingsFocus,
1644
1851
  settingsFilter,
1645
1852
  settingsOffset,
1646
- seatPicker,
1647
1853
  choicePicker,
1854
+ replyFocus,
1855
+ replyCursor,
1856
+ replyBody,
1857
+ replyScroll,
1858
+ replyOffset,
1648
1859
  size,
1649
1860
  composing,
1650
1861
  mode,
@@ -1742,16 +1953,10 @@ export function App({
1742
1953
  // on the page the view was opened from (the work page's rows open it too, P20/B5).
1743
1954
  if (choicePickerRef.current) {
1744
1955
  // The choice picker's entries may outrun the budget: the wheel walks the list like
1745
- // ↑/↓ (the window follows the selection, as the seat picker's does).
1956
+ // ↑/↓ (the window follows the selection).
1746
1957
  moveChoicePicker(delta)
1747
1958
  return
1748
1959
  }
1749
- if (seatPickerRef.current) {
1750
- // P30/D5: the seat picker's wheel used to fall through to the page. It walks its
1751
- // entries now, exactly like the choice picker, and the page still does not move.
1752
- moveSeatPicker(delta)
1753
- return
1754
- }
1755
1960
  if (settingsViewRef.current) {
1756
1961
  // P30/D5: while the project-settings view is open the wheel is its region — the row
1757
1962
  // window moves one row per notch, the focus stays, and the page behind it is untouched.
@@ -1762,6 +1967,22 @@ export function App({
1762
1967
  scrollDetail(delta)
1763
1968
  return
1764
1969
  }
1970
+ if (pageRef.current === 5 && replyBodyRef.current != null) {
1971
+ // The reply viewer's document is the one scrollable region on page 5.
1972
+ scrollReply(delta)
1973
+ return
1974
+ }
1975
+ if (pageRef.current === 5) {
1976
+ // Page 5's list: the wheel moves the *viewport*, never the focus (the documented rule),
1977
+ // and never fetches hidden history.
1978
+ const win = replyListRef.current
1979
+ setReplyOffset((v) => {
1980
+ const base = v ?? win?.offset ?? 0
1981
+ const max = win ? Math.max(0, win.count - win.visible) : 0
1982
+ return Math.max(0, Math.min(max, base + delta))
1983
+ })
1984
+ return
1985
+ }
1765
1986
  // On the board page the wheel scrolls the lane under the cursor (a card hit carries its
1766
1987
  // lane, the lane's own hover target covers the rest); elsewhere it scrolls the page's list.
1767
1988
  if (pageRef.current === 4) {
@@ -1952,22 +2173,6 @@ export function App({
1952
2173
  }
1953
2174
  return
1954
2175
  }
1955
- if (seatPickerRef.current) {
1956
- if (key.escape) {
1957
- setSeatPicker(null)
1958
- seatPickerRef.current = null
1959
- return
1960
- }
1961
- if (key.upArrow || key.downArrow) {
1962
- moveSeatPicker(key.upArrow ? -1 : 1)
1963
- return
1964
- }
1965
- if (key.return) {
1966
- chooseSeatOption(-1)
1967
- return
1968
- }
1969
- return
1970
- }
1971
2176
  if (key.escape) {
1972
2177
  closeSettingsView()
1973
2178
  return
@@ -2008,16 +2213,51 @@ export function App({
2008
2213
  }
2009
2214
  // Enter adds no action here (no write operation), and the page keys stay live below.
2010
2215
  }
2216
+ // The reply viewer (page 5) is read-only and full-page: Esc or `q` backs out to the same list
2217
+ // cursor, focus and viewport — never collapses. `↑`/`↓`, PgUp/PgDn, Home/End and the wheel
2218
+ // scroll the whole document; the page keys stay live below (they replace the viewer's page).
2219
+ if (page === 5 && replyBodyRef.current != null) {
2220
+ if (key.escape || (input === 'q' && !key.ctrl)) {
2221
+ setReplyBody(null)
2222
+ return
2223
+ }
2224
+ const step = Math.max(1, (size.rows || 10) - 4)
2225
+ if (key.upArrow) {
2226
+ scrollReply(-1)
2227
+ return
2228
+ }
2229
+ if (key.downArrow) {
2230
+ scrollReply(1)
2231
+ return
2232
+ }
2233
+ if (key.pageUp) {
2234
+ scrollReply(-step)
2235
+ return
2236
+ }
2237
+ if (key.pageDown) {
2238
+ scrollReply(step)
2239
+ return
2240
+ }
2241
+ if (key.home) {
2242
+ setReplyScroll(0)
2243
+ return
2244
+ }
2245
+ if (key.end) {
2246
+ const win = replyDocRef.current
2247
+ setReplyScroll(win ? Math.max(0, win.total - win.visible) : 0)
2248
+ return
2249
+ }
2250
+ }
2011
2251
  if (input === 'q' || (key.ctrl && input === 'c')) {
2012
2252
  void collapse()
2013
2253
  return
2014
2254
  }
2015
2255
  if (busy) return
2016
2256
  if (key.tab) {
2017
- goPage(pageRef.current === 4 ? 1 : ((pageRef.current + 1) as PageId))
2257
+ goPage(pageRef.current === 5 ? 1 : ((pageRef.current + 1) as PageId))
2018
2258
  return
2019
2259
  }
2020
- if (input === '1' || input === '2' || input === '3' || input === '4') {
2260
+ if (input === '1' || input === '2' || input === '3' || input === '4' || input === '5') {
2021
2261
  goPage(Number(input) as PageId)
2022
2262
  return
2023
2263
  }
@@ -2039,12 +2279,29 @@ export function App({
2039
2279
  return
2040
2280
  }
2041
2281
  if (input === 'r') {
2042
- // `r` is the human asking for it: rebuild every block now, not "when its TTL is up".
2282
+ // `r` is the human asking for it: rebuild every block now, not "when its TTL is up". On
2283
+ // page 5 it is the documented "back to the newest page" key instead (design §5).
2284
+ if (page === 5) {
2285
+ replyReset()
2286
+ return
2287
+ }
2043
2288
  setReceipt(null)
2044
2289
  setStatus(null)
2045
2290
  api.refreshNow()
2046
2291
  return
2047
2292
  }
2293
+ if (page === 5 && (key.leftArrow || key.rightArrow)) {
2294
+ replyPage(key.leftArrow ? -1 : 1)
2295
+ return
2296
+ }
2297
+ if (page === 5 && (key.upArrow || key.downArrow)) {
2298
+ moveReplyFocus(key.upArrow ? -1 : 1)
2299
+ return
2300
+ }
2301
+ if (page === 5 && key.return) {
2302
+ openReply()
2303
+ return
2304
+ }
2048
2305
  if (page === 4 && input === 'c' && !detailId) {
2049
2306
  // P123: `c` folds/unfolds the lane the focus names. The detail view and the settings
2050
2307
  // surfaces own the page region and never reach here (their branches returned above).