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
@@ -36,6 +36,7 @@ import type {
36
36
  Frame,
37
37
  FrameInput,
38
38
  Hit,
39
+ Impediment,
39
40
  LaneWindow,
40
41
  Line,
41
42
  PageId,
@@ -45,18 +46,22 @@ import type {
45
46
  PlacedLine,
46
47
  PrefName,
47
48
  QueueEntry,
48
- Impediment,
49
+ ReplyDocWindow,
50
+ ReplyEntry,
51
+ ReplyWindow,
49
52
  Segment,
53
+ SettingsAssignment,
50
54
  SettingsBlock,
55
+ SettingsCategory,
51
56
  SettingsChoiceEntry,
52
57
  SettingsKey,
53
- SettingsSeat,
58
+ SettingsPmLaunch,
54
59
  SettingsWindow,
55
60
  Tone,
56
61
  ViewState,
57
62
  } from './types.js'
58
63
  import { toneSgr, type Palette } from './theme.js'
59
- import { cell, dispWidth, rule, truncateW, truncateWStart } from './width.js'
64
+ import { cell, charWidth, dispWidth, rule, truncateW, truncateWStart } from './width.js'
60
65
 
61
66
  export const WIDTH_TWO_WIDE = 160
62
67
  export const WIDTH_TWO_COMPACT = 100
@@ -245,6 +250,10 @@ interface Block {
245
250
  detail?: DetailWindow
246
251
  /** The project-settings view's row window as rendered (P22/B2). */
247
252
  settings?: SettingsWindow
253
+ /** Page 5's list window as rendered (the App's arrows/wheel clamp against it). */
254
+ replyList?: ReplyWindow
255
+ /** The open reply viewer's document window as rendered. */
256
+ replyDoc?: ReplyDocWindow
248
257
  /** The work page's board rows in the order it drew them (P20/B5: the App's `↑`/`↓` walk this). */
249
258
  order?: FocusRef[]
250
259
  }
@@ -284,6 +293,10 @@ interface Ctx {
284
293
  * assembly's real budget: the view spends it on the row window, its tail and blank fill, so the
285
294
  * card fills the pane — P32). */
286
295
  settingsRows?: number
296
+ /** Rows page 5's reply list may draw (the assembly's budget: more pane = more rows). */
297
+ replyRows?: number
298
+ /** Document rows the open reply viewer may draw. */
299
+ replyDocRows?: number
287
300
  }
288
301
 
289
302
  export interface LayoutInput extends FrameInput {
@@ -1288,20 +1301,236 @@ function detailBlock(ctx: Ctx): Block | null {
1288
1301
  return one(rows, { index, total: doc.length, visible: Math.min(available, Math.max(0, doc.length - offset)), offset })
1289
1302
  }
1290
1303
 
1304
+
1305
+ // ------------------------------------------------------------------ key replies (pulse-key-replies)
1306
+ //
1307
+ // Page 5 reads the bounded `key-replies` store through three console-only blocks. The list is a
1308
+ // page of numbered slots (metadata only); the viewer renders one committed body through the same
1309
+ // markdown renderer and width plan the detail view uses. Focus is a **stable number**, the window
1310
+ // follows it, and the older chain is an explicit list of cursors — nothing here ever loads the
1311
+ // whole history, and nothing here writes (the readers are observation-only).
1312
+
1313
+ const REPLY_LIST_ROWS_DEFAULT = 12
1314
+ const REPLY_DOC_ROWS_DEFAULT = 16
1315
+
1316
+ /** The `#no title` cell of one list row. */
1317
+ function replyRowLabel(e: ReplyEntry): string {
1318
+ return e.available ? `#${e.no} ${e.title}` : ''
1319
+ }
1320
+
1321
+ /** The nav row of page 5: Older / Newer / `r` (the same actions `←`/`→` and `r` fire). */
1322
+ function replyNavLine(ctx: Ctx, innerW: number): PlacedLine {
1323
+ const { s } = ctx
1324
+ const line: Line = [seg(' ')]
1325
+ const hits: Hit[] = []
1326
+ let x = 1
1327
+ const chip = (text: string, action: Action): void => {
1328
+ const start = x
1329
+ line.push(seg(text, 'accent'))
1330
+ x += dispWidth(text)
1331
+ hits.push({ start, end: x, action })
1332
+ line.push(seg(' '))
1333
+ x += 1
1334
+ }
1335
+ chip(`\u2039 ${s.replyOlder}`, { kind: 'reply-page', dir: -1 })
1336
+ chip(`${s.replyNewer} \u203a`, { kind: 'reply-page', dir: 1 })
1337
+ chip(s.keyReplyReset, { kind: 'reply-reset' })
1338
+ return placedWithHits(line, hits, innerW)
1339
+ }
1340
+
1341
+ /**
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.
1345
+ */
1346
+ function replyListBlock(ctx: Ctx): Block | null {
1347
+ const { s, blocks, deg, view } = ctx
1348
+ const innerW = blockInnerW(ctx)
1349
+ const data = blocks.reply_list
1350
+ const budget = Math.max(2, ctx.replyRows ?? REPLY_LIST_ROWS_DEFAULT)
1351
+ const build = (lines: PlacedLine[], win?: ReplyWindow): Block => ({
1352
+ id: 'reply_list',
1353
+ full: true,
1354
+ priority: 1,
1355
+ separator: 'none',
1356
+ title: data ? fill(s.replyHeadingCount, { n: data.total_slots }) : s.replyHeading,
1357
+ lines,
1358
+ replyList: win,
1359
+ summary: { line: truncLine(ln(seg(` ${s.replyHeading}`, 'heading')), ctx.width) },
1360
+ })
1361
+ const lines: PlacedLine[] = [replyNavLine(ctx, innerW)]
1362
+ if (!data || deg.has('reply_list')) {
1363
+ lines.push({ line: truncLine(ln(seg(` ${data ? s.dash : s.replyLoading}`, 'dim')), innerW) })
1364
+ return build(lines, { focus: 0, offset: 0, visible: 0, count: 0 })
1365
+ }
1366
+ // An empty store says so in one line: the slot count would only repeat "0" (and it is never a
1367
+ // claim about readable replies when the store does have slots).
1368
+ if (data.state !== 'empty') {
1369
+ lines.push({ line: truncLine(ln(seg(` ${fill(s.replyTotalSlots, { n: data.total_slots })}`, 'dim')), innerW) })
1370
+ }
1371
+ if ((data.warnings ?? []).some((w) => w.kind === 'partial-tail')) {
1372
+ lines.push({ line: truncLine(ln(seg(` ${s.replyTailWarning}`, 'warn')), innerW) })
1373
+ }
1374
+ const entries = Array.isArray(data.entries) ? data.entries : []
1375
+ if (!entries.length) {
1376
+ lines.push({ line: truncLine(ln(seg(` ${s.replyEmpty}`, 'dim')), innerW) })
1377
+ return build(lines, { focus: 0, offset: 0, visible: 0, count: 0 })
1378
+ }
1379
+ const room = Math.max(1, budget - lines.length)
1380
+ const wanted = view.replyFocus ?? 0
1381
+ let focus = entries.findIndex((e) => e.no === wanted)
1382
+ if (focus < 0) focus = 0
1383
+ const follow = Math.max(0, focus - room + 1)
1384
+ const offset = Math.max(0, Math.min(Math.max(0, entries.length - room), Math.floor(view.replyOffset ?? follow) || 0))
1385
+ for (let i = offset; i < Math.min(entries.length, offset + room); i++) {
1386
+ const e = entries[i]
1387
+ const active = i === focus
1388
+ const cursor = active ? s.settingsCursor : ' '
1389
+ const head = ` ${cursor} `
1390
+ const bodyLine: Line = e.available
1391
+ ? ln(
1392
+ seg(head, 'accent'),
1393
+ seg(replyRowLabel(e), active ? 'selected' : 'text'),
1394
+ seg(` · ${e.from}`, 'dim'),
1395
+ )
1396
+ : ln(
1397
+ seg(head, 'accent'),
1398
+ seg(fill(s.replySlotUnavailable, { no: e.no }), 'warn'),
1399
+ seg(`(${e.reason})`, 'dim'),
1400
+ )
1401
+ lines.push({
1402
+ line: truncLine(bodyLine, innerW),
1403
+ hits: ctx.view.tui ? [{ start: 1, end: Math.min(innerW, widthOf(bodyLine) + 1), action: { kind: 'reply-click', index: i } }] : undefined,
1404
+ })
1405
+ }
1406
+ return build(lines, {
1407
+ focus: entries[focus].no,
1408
+ offset,
1409
+ visible: Math.min(room, entries.length - offset),
1410
+ count: entries.length,
1411
+ })
1412
+ }
1413
+
1414
+ /**
1415
+ * The open reply viewer: the committed body rendered as markdown, its declared metadata above it,
1416
+ * and a local unavailable notice when the body is missing or corrupt (the same return route either
1417
+ * way). It never fetches links, executes text or offers an editing action.
1418
+ */
1419
+ function replyViewerBlock(ctx: Ctx): Block | null {
1420
+ const no = ctx.view.replyBody
1421
+ if (!no) return null
1422
+ const { s, blocks, deg } = ctx
1423
+ const innerW = blockInnerW(ctx)
1424
+ const budget = Math.max(2, ctx.replyDocRows ?? REPLY_DOC_ROWS_DEFAULT)
1425
+ const data = blocks.reply_body
1426
+ const build = (lines: PlacedLine[], doc?: ReplyDocWindow): Block => ({
1427
+ id: 'reply_viewer',
1428
+ full: true,
1429
+ priority: 1,
1430
+ separator: 'none',
1431
+ title: `#${no} ${s.replyHeading}`,
1432
+ lines,
1433
+ replyDoc: doc,
1434
+ summary: { line: truncLine(ln(seg(` ${s.replyHeading} #${no}`, 'heading')), ctx.width) },
1435
+ })
1436
+ const nav = replyNavLine(ctx, innerW)
1437
+ const back: Line = ln(seg(` ${s.replyBack}`, 'accent'), seg(` · ${s.keyDetailClose}`, 'dim'))
1438
+ const backLine: PlacedLine = {
1439
+ line: truncLine(back, innerW),
1440
+ hits: ctx.view.tui ? [{ start: 1, end: 1 + dispWidth(s.replyBack) + 2, action: { kind: 'reply-close' } }] : undefined,
1441
+ }
1442
+ if (!data || data.no !== no) {
1443
+ // A failed read says so and keeps its return route; only a read that is still in flight spins.
1444
+ const failed = ctx.view.replyBodyFailed === true || deg.has('reply_body')
1445
+ const notice = failed ? seg(` ${s.replyBodyMissing}`, 'warn') : seg(` ${s.replyLoading}`, 'dim')
1446
+ return build([nav, { line: truncLine(ln(notice), innerW) }, backLine], { no, total: 0, visible: 0, offset: 0 })
1447
+ }
1448
+ if (data.available === false) {
1449
+ return build([nav, { line: truncLine(ln(seg(` ${s.replyBodyMissing}`, 'warn')), innerW) }, backLine], { no, total: 0, visible: 0, offset: 0 })
1450
+ }
1451
+ const meta: PlacedLine[] = [
1452
+ { line: truncLine(ln(seg(` ${data.title}`, 'heading')), innerW) },
1453
+ { line: truncLine(ln(seg(` ${fill(s.replyDeclared, { from: data.from, at: data.at })}`, 'dim')), innerW) },
1454
+ { line: truncLine(ln(seg(` ${s.replyBodyHint} · ${data.bytes} B`, 'dim')), innerW) },
1455
+ ]
1456
+ const doc = markdownMemo(`reply:${no}`, data.display_text ?? '', innerW)
1457
+ const available = Math.max(1, budget - nav0Length(meta))
1458
+ const maxStart = Math.max(0, doc.length - available)
1459
+ const offset = Math.max(0, Math.min(maxStart, Math.floor(ctx.view.replyScroll ?? 0) || 0))
1460
+ const lines: PlacedLine[] = [nav, ...meta]
1461
+ for (let i = offset; i < Math.min(doc.length, offset + available); i++) lines.push(doc[i])
1462
+ lines.push(backLine)
1463
+ return build(lines, { no, total: doc.length, visible: Math.min(available, Math.max(0, doc.length - offset)), offset })
1464
+ }
1465
+
1466
+ /** The rows the viewer spends before its document (meta + nav + the back row). */
1467
+ function nav0Length(meta: PlacedLine[]): number {
1468
+ return meta.length + 2
1469
+ }
1470
+
1471
+ /** The overview's latest-reply entry: number, safe title and declared publisher, or empty/unavailable. */
1472
+ function replySummaryBlock(ctx: Ctx): Block | null {
1473
+ if (!ctx.view.tui) return null // console-only: `--print`/`--json` render the overview without it
1474
+ const { s, blocks, deg, width } = ctx
1475
+ const d = blocks.reply_summary
1476
+ const hint = ` ${s.replyLatest} `
1477
+ const line: Line = [seg(hint, 'heading')]
1478
+ const hits: Hit[] = []
1479
+ let x = dispWidth(hint)
1480
+ hits.push({ start: 1, end: x, action: { kind: 'page', page: 5 } })
1481
+ const entry = d && d.available && d.state === 'ok' ? d.entry : undefined
1482
+ if (!d || deg.has('reply_summary')) {
1483
+ line.push(seg(s.dash, 'dim'))
1484
+ } else if (entry && entry.available) {
1485
+ const text = `#${entry.no} ${entry.title} · ${entry.from}`
1486
+ line.push(seg(text, 'text'))
1487
+ hits.push({ start: x, end: x + dispWidth(text), action: { kind: 'reply-open-latest', no: entry.no } })
1488
+ x += dispWidth(text)
1489
+ const at = ` · ${entry.at}`
1490
+ line.push(seg(at, 'dim'))
1491
+ x += dispWidth(at)
1492
+ } else if (d.state === 'empty') {
1493
+ line.push(seg(s.replyEmpty, 'dim'))
1494
+ } else {
1495
+ line.push(seg(s.replyUnavailable, 'warn'))
1496
+ const reason = d.reason ? `(${d.reason})` : ''
1497
+ if (reason) line.push(seg(reason, 'dim'))
1498
+ }
1499
+ const chip = ` [5] `
1500
+ hits.push({ start: x + 1, end: x + 1 + dispWidth(chip), action: { kind: 'page', page: 5 } })
1501
+ line.push(seg(chip, 'accent'))
1502
+ return {
1503
+ id: 'reply_summary',
1504
+ title: s.replyLatest,
1505
+ priority: 9,
1506
+ lines: [placedWithHits(line, hits, width)],
1507
+ summary: { line: truncLine(ln(seg(` ${s.replyLatest}`, 'heading')), width) },
1508
+ }
1509
+ }
1510
+
1291
1511
  // ------------------------------------------------------------------ project settings (P22/B2)
1292
1512
  //
1293
1513
  // The view is a listing of the contract: one row per schema key plus one per key the file carries
1294
1514
  // that the schema does not know, grouped by the functional domain the **command** reports on the
1295
- // row's `group` (P30 — the console owns no second table), then the model seats block. Rows, groups
1296
- // and classes come from the `settings` block's JSON at render time; a key added to the command's
1297
- // schema shows up without rebuilding `panel.js`. The list is windowed against the height the
1298
- // assembly hands over (the bounded-frame rule: more pane means more rows, never more blank).
1515
+ // row's `group` (P30 — the console owns no second table). Under the keys the view carries the two
1516
+ // halves of the model policy the command reports (P232): the **future** policy's category rows
1517
+ // (editable, one `set-task-model` per row) and the **committed** assignments plus the PM launch
1518
+ // record (read-only). The two halves are rendered under separate headings and never merged: a
1519
+ // future category model is never displayed as a seat's actual model.
1520
+ //
1521
+ // Rows, groups and classes come from the `settings` block's JSON at render time; a key added to the
1522
+ // command's schema shows up without rebuilding `panel.js`. The list is windowed against the height
1523
+ // the assembly hands over (the bounded-frame rule: more pane means more rows, never more blank).
1299
1524
 
1300
1525
  // The row's identity column is a **label** (M49), not the key name: the table's labels are human
1301
1526
  // sentences, so the column only has to hold the longest of them (zh is the wide language here;
1302
1527
  // a longer en label is cut by `cell()`, the same rule the key names followed).
1303
1528
  const SETTINGS_LABEL_W = 22
1304
1529
  const SETTINGS_AUDIT_LINES = 3
1530
+ /** P232: the policy migration diagnosis is shown above the audit tail; the rest is counted. */
1531
+ const SETTINGS_DIAG_LINES = 2
1532
+ /** P232: how many frame lines one diagnosis line may wrap to before it is cut with an ellipsis. */
1533
+ const SETTINGS_DIAG_WRAP = 2
1305
1534
  // The tail the block draws under its row window: the CLI hint, a blank, the audit heading and up to
1306
1535
  // `SETTINGS_AUDIT_LINES` audit lines (the heading always has one line under it — a dash when the
1307
1536
  // command's log is empty), plus `SETTINGS_COUNT_ROWS`, the pessimistic reservation for the two
@@ -1330,8 +1559,9 @@ const SETTINGS_TAIL_ROWS = SETTINGS_COUNT_ROWS + 1 + 1 + 1 + SETTINGS_AUDIT_LINE
1330
1559
  export type SettingsRow =
1331
1560
  | { kind: 'group'; label: string; tone: Tone }
1332
1561
  | { kind: 'key'; key: SettingsKey }
1333
- | { kind: 'seat-group'; label: string }
1334
- | { kind: 'seat'; seat: SettingsSeat }
1562
+ | { kind: 'category'; category: SettingsCategory }
1563
+ | { kind: 'assignment'; assignment: SettingsAssignment }
1564
+ | { kind: 'pm-launch'; launch: SettingsPmLaunch }
1335
1565
 
1336
1566
  export function settingsClassLabel(s: Strings, cls: string): string {
1337
1567
  if (cls === 'restart') return s.settingsBadgeRestart
@@ -1361,23 +1591,37 @@ function groupLabel(s: Strings, token: string): string {
1361
1591
  return typeof label === 'string' && label.length > 0 ? label : token
1362
1592
  }
1363
1593
 
1364
- /** The CLI's own three source labels (the console invents no fourth state). */
1594
+ /**
1595
+ * The CLI's own three source labels (the console invents no fourth state).
1596
+ *
1597
+ * The committed record's provenance: `selected_via`/`launch_via` are the CLI's own closed tokens
1598
+ * (`explicit`/`policy`/`assignment`, plus the legacy spellings it still reports). The console only
1599
+ * spells them; it never derives them.
1600
+ */
1365
1601
  export function settingsSourceLabel(s: Strings, source: string): string {
1366
1602
  if (source === 'explicit') return s.seatSourceExplicit
1603
+ if (source === 'policy') return s.seatSourcePolicy
1604
+ if (source === 'assignment') return s.seatSourceAssignment
1367
1605
  if (source === 'record') return s.seatSourceRecord
1368
- return s.seatSourceConfig
1606
+ return source || s.dash
1369
1607
  }
1370
1608
 
1371
1609
  /**
1372
1610
  * The view's filtered row list: the contract's keys grouped by the **record's** `group` (P30/D1-D3),
1373
- * in the read's own order, then the seats. Pure and exported: the App walks exactly this list when
1374
- * it moves the focus, so the keys can never disagree with what is on screen.
1611
+ * in the read's own order, then the future policy's category rows and the committed assignments.
1612
+ * Pure and exported: the App walks exactly this list when it moves the focus, so the keys can never
1613
+ * disagree with what is on screen.
1375
1614
  *
1376
1615
  * The bundle owns no key→group table and no group list: the walk opens a heading whenever the
1377
1616
  * token changes, so a key (or a whole group) added to the command's schema appears under its
1378
1617
  * reported heading with the committed bundle. Rows whose token is empty — a schema row that
1379
1618
  * declares none, or a key the file carries and the schema does not know — are never dropped: they
1380
- * collect into one visible trailing fallback heading, before the seats block.
1619
+ * collect into one visible trailing fallback heading, before the categories block.
1620
+ *
1621
+ * P232: the categories block (the future policy) comes before the assignments block (the committed
1622
+ * records), each with its own heading, so "what the next task will use" and "what is actually
1623
+ * running" are never read as the same list. A seat with no complete record still gets a row that
1624
+ * says so — it is never filled in from the policy above.
1381
1625
  */
1382
1626
  export function settingsViewRows(block: SettingsBlock | undefined, filter: string, s: Strings): SettingsRow[] {
1383
1627
  const out: SettingsRow[] = []
@@ -1408,16 +1652,33 @@ export function settingsViewRows(block: SettingsBlock | undefined, filter: strin
1408
1652
  out.push({ kind: 'group', label: s.settingsGroupUngrouped, tone: 'heading' })
1409
1653
  for (const k of ungrouped) out.push({ kind: 'key', key: k })
1410
1654
  }
1411
- const seats = (block.models?.seats ?? []).filter((x) =>
1412
- match(x.agent, x.model, settingsSourceLabel(s, x.source)),
1655
+ const categories = (block.models?.policy?.categories ?? []).filter((c) =>
1656
+ match(fill(s.settingsCategoryRow, { category: c.category }), c.category, c.model),
1413
1657
  )
1414
- if (seats.length) {
1415
- out.push({ kind: 'seat-group', label: s.settingsGroupSeats })
1416
- for (const x of seats) out.push({ kind: 'seat', seat: x })
1658
+ if (categories.length) {
1659
+ out.push({ kind: 'group', label: s.settingsGroupCategories, tone: 'heading' })
1660
+ for (const c of categories) out.push({ kind: 'category', category: c })
1661
+ }
1662
+ 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),
1664
+ )
1665
+ const launch = block.models?.pm_launch ?? {}
1666
+ const launchShown =
1667
+ Object.keys(launch).length > 0 &&
1668
+ match(s.settingsPmLaunchLabel, String(launch.model ?? ''), String(launch.mode ?? ''), String(launch.window ?? ''))
1669
+ if (assignments.length || launchShown) {
1670
+ out.push({ kind: 'group', label: s.settingsGroupAssignments, tone: 'heading' })
1671
+ for (const a of assignments) out.push({ kind: 'assignment', assignment: a })
1672
+ if (launchShown) out.push({ kind: 'pm-launch', launch })
1417
1673
  }
1418
1674
  return out
1419
1675
  }
1420
1676
 
1677
+ /** True for the rows the focus walk may stop on (headings are not focusable). */
1678
+ export function settingsRowFocusable(row: SettingsRow): row is Exclude<SettingsRow, { kind: 'group' }> {
1679
+ return row.kind !== 'group'
1680
+ }
1681
+
1421
1682
  /**
1422
1683
  * The badge + value column shared by a key row and a seat row. The class tone covers the **badge
1423
1684
  * only** (P30/D4): the value beside it stays in the plain text tone, because a class meaning is
@@ -1452,37 +1713,148 @@ function settingsKeyLine(ctx: Ctx, row: SettingsKey, focused: boolean, innerW: n
1452
1713
  return { line }
1453
1714
  }
1454
1715
 
1455
- function settingsSeatLine(ctx: Ctx, seat: SettingsSeat, focused: boolean, innerW: number): PlacedLine {
1716
+ /**
1717
+ * One policy-diagnosis line, wrapped to at most `maxLines` frame lines (P232). The command's lines
1718
+ * are long — the reason, the retired key and the CLI route in one sentence — and a plain tail
1719
+ * truncation cut exactly the route off (measured: `…修法:team config upgrade-mo…` on a 160-column
1720
+ * pane). The text is therefore drawn **verbatim** across lines, and only a line that still does not
1721
+ * fit inside `maxLines` is cut, with a visible ellipsis on its last drawn line.
1722
+ */
1723
+ /**
1724
+ * Cut to at most `w` columns **without** the `…` `truncateW` appends: the wrapping primitive below
1725
+ * draws every cell itself and only marks a line that really had to be dropped.
1726
+ */
1727
+ function cutW(s: string, w: number): string {
1728
+ let used = 0
1729
+ let out = ''
1730
+ for (const ch of String(s)) {
1731
+ const cw = charWidth(ch)
1732
+ if (used + cw > w) break
1733
+ used += cw
1734
+ out += ch
1735
+ }
1736
+ return out
1737
+ }
1738
+
1739
+ /**
1740
+ * One policy-diagnosis line, wrapped to at most `maxLines` frame lines (P232). The command's lines
1741
+ * are long — the reason, the retired key and the CLI route in one sentence — and a plain tail
1742
+ * truncation cut exactly the route off (measured: `…修法:team config upgrade-mo…` on a 160-column
1743
+ * pane). The text is therefore drawn **verbatim** across lines, broken at a whitespace when there
1744
+ * is one inside the width (so a command name stays whole instead of splitting mid-word); only text
1745
+ * that still does not fit inside `maxLines` is dropped, marked with a visible `…`.
1746
+ */
1747
+ function diagnoseChunks(text: string, width: number, maxLines: number): string[] {
1748
+ const out: string[] = []
1749
+ let rest = text
1750
+ while (rest !== '' && out.length < maxLines) {
1751
+ if (dispWidth(rest) <= width) {
1752
+ out.push(rest)
1753
+ rest = ''
1754
+ break
1755
+ }
1756
+ let chunk = cutW(rest, width)
1757
+ if (chunk === '') break
1758
+ // Mid-word cuts only happen when no whitespace is available inside the width (a long path).
1759
+ if (rest.slice(chunk.length, chunk.length + 1) !== '' && rest.slice(chunk.length, chunk.length + 1) !== ' ') {
1760
+ const space = chunk.lastIndexOf(' ')
1761
+ if (space > 0) chunk = chunk.slice(0, space + 1)
1762
+ }
1763
+ out.push(chunk)
1764
+ rest = rest.slice(chunk.length)
1765
+ }
1766
+ if (rest !== '') {
1767
+ const last = out[out.length - 1] ?? ''
1768
+ out[out.length - 1] = cutW(last, Math.max(1, width - 1)) + '…'
1769
+ }
1770
+ return out
1771
+ }
1772
+
1773
+ /**
1774
+ * One future-policy category row (P232). The category token is the row's identity (the project
1775
+ * defines it; there is no table entry for a project's own vocabulary), the value is the model the
1776
+ * next new task of that category will get, and the badge says "new tasks" so the row cannot be
1777
+ * read as a running seat. The command line under the list names the one write it offers.
1778
+ */
1779
+ function settingsCategoryLine(ctx: Ctx, cat: SettingsCategory, focused: boolean, innerW: number): PlacedLine {
1456
1780
  const { s } = ctx
1457
- const model = seat.model || s.dash
1458
- const policy = seat.override ? s.seatOverride : s.seatFallback
1459
1781
  const line = ln(
1460
1782
  seg(`${focused ? s.settingsCursor : ' '} `, 'accent'),
1461
- seg(cell(seat.agent, SETTINGS_LABEL_W), focused ? 'selected' : 'heading'),
1462
- ...settingsRight(ctx, `${model} · ${settingsSourceLabel(s, seat.source)} · ${policy}`, '', 'dim', innerW).map((x) => x),
1783
+ seg(cell(fill(s.settingsCategoryRow, { category: cat.category }), SETTINGS_LABEL_W), focused ? 'selected' : 'heading'),
1784
+ ...settingsRight(ctx, cat.model || s.dash, s.settingsCategoryBadge, 'text', innerW).map((x) => x),
1463
1785
  )
1464
1786
  return { line }
1465
1787
  }
1466
1788
 
1467
1789
  /**
1468
- * The focused row as the command line names it (M49): the row's label is for reading, the raw key
1469
- * is what the user types — this line is the CLI-alignment half of the pair. A key the command does
1470
- * not know (schema unknown) and a read-only key are said out loud rather than offered as a command
1471
- * that would be refused; a seat gets its own `set-agent-model` route. '' when nothing is focusable.
1790
+ * One read-only committed assignment row (P232): the seat, its actual model, the origin tokens the
1791
+ * CLI recorded and — on the note — the task, category and SID. `assigned=false` shows the command's
1792
+ * own diagnostic instead of inventing a model from the policy above.
1472
1793
  */
1473
- function settingsCliHint(s: Strings, rows: SettingsRow[], focus: number): string {
1474
- const focusable = rows.filter(
1475
- (r): r is { kind: 'key'; key: SettingsKey } | { kind: 'seat'; seat: SettingsSeat } => r.kind === 'key' || r.kind === 'seat',
1794
+ function settingsAssignmentLine(ctx: Ctx, a: SettingsAssignment, focused: boolean, innerW: number): PlacedLine {
1795
+ const { s } = ctx
1796
+ const line = ln(
1797
+ seg(`${focused ? s.settingsCursor : ' '} `, 'accent'),
1798
+ seg(cell(a.agent, SETTINGS_LABEL_W), focused ? 'selected' : 'heading'),
1799
+ ...settingsRight(
1800
+ ctx,
1801
+ a.assigned ? a.model || s.dash : s.dash,
1802
+ s.settingsReadOnlyBadge,
1803
+ 'dim',
1804
+ innerW,
1805
+ ).map((x) => x),
1476
1806
  )
1807
+ const note = a.assigned
1808
+ ? fill(s.settingsAssignmentNote, {
1809
+ task: a.task || s.dash,
1810
+ category: a.category || s.dash,
1811
+ sid: a.sid || s.dash,
1812
+ selected: settingsSourceLabel(s, a.selected_via),
1813
+ launch: settingsSourceLabel(s, a.launch_via),
1814
+ })
1815
+ : fill(s.settingsAssignmentNone, { diagnostic: a.diagnostic || s.dash })
1816
+ line.push(seg(` ${truncateW(note, Math.max(8, innerW - dispWidth(textOf(line)) - 2))}`, a.assigned ? 'dim' : 'warn'))
1817
+ return { line }
1818
+ }
1819
+
1820
+ /** The PM's own last launch record, read-only — never a worker seat and never a policy row. */
1821
+ function settingsPmLaunchLine(ctx: Ctx, launch: SettingsPmLaunch, focused: boolean, innerW: number): PlacedLine {
1822
+ const { s } = ctx
1823
+ const line = ln(
1824
+ seg(`${focused ? s.settingsCursor : ' '} `, 'accent'),
1825
+ seg(cell(s.settingsPmLaunchLabel, SETTINGS_LABEL_W), focused ? 'selected' : 'heading'),
1826
+ ...settingsRight(ctx, launch.model || s.dash, s.settingsReadOnlyBadge, 'dim', innerW).map((x) => x),
1827
+ )
1828
+ const note = fill(s.settingsPmLaunchNote, {
1829
+ window: launch.window || s.dash,
1830
+ mode: launch.mode || s.dash,
1831
+ time: launch.time || s.dash,
1832
+ })
1833
+ line.push(seg(` ${truncateW(note, Math.max(8, innerW - dispWidth(textOf(line)) - 2))}`, 'dim'))
1834
+ return { line }
1835
+ }
1836
+
1837
+ /**
1838
+ * The focused row as the command line names it (M49/P232): the row's label is for reading, the raw
1839
+ * key or the category token is what the user types — this line is the CLI-alignment half of the
1840
+ * pair. A key the command does not know (schema unknown) and a read-only key are said out loud
1841
+ * rather than offered as a command that would be refused; a category names its own `set-task-model`
1842
+ * route, and a committed assignment says it is the dispatch's decision, never a console write.
1843
+ * '' when nothing is focusable.
1844
+ */
1845
+ function settingsCliHint(s: Strings, rows: SettingsRow[], focus: number): string {
1846
+ const focusable = rows.filter(settingsRowFocusable)
1477
1847
  const row = focusable[focus]
1478
1848
  if (!row) return ''
1479
- if (row.kind === 'seat') return fill(s.settingsSeatHint, { seat: row.seat.agent })
1849
+ if (row.kind === 'category') return fill(s.settingsCategoryHint, { category: row.category.category })
1850
+ if (row.kind === 'assignment') return s.settingsAssignmentHint
1851
+ if (row.kind === 'pm-launch') return s.settingsPmLaunchHint
1480
1852
  const key = row.key
1481
1853
  if (key.known === false) return fill(s.settingsUnknownHint, { key: key.name })
1482
1854
  if (key.class === 'refuse') return fill(s.settingsRefusedHint, { key: key.name })
1483
- // The pairlist row is not composed here: its editor is the seats block, and the command line the
1484
- // requirement names is the per-seat one (M55).
1485
- if (String(key.kind ?? '') === 'pairlist') return s.settingsPairlistHint
1855
+ // The whole-map row is not composed here: its editor is the categories block, and the command
1856
+ // line the requirement names is the per-category one (P232).
1857
+ if (String(key.kind ?? '') === 'task-model-map') return s.settingsCategoryMapHint
1486
1858
  return fill(s.settingsCliHint, { key: key.name })
1487
1859
  }
1488
1860
 
@@ -1518,7 +1890,7 @@ function settingsBlock(ctx: Ctx): Block | null {
1518
1890
  }
1519
1891
  const rows = settingsViewRows(block, ctx.view.settingsFilter ?? '', s)
1520
1892
  let count = 0
1521
- for (const r of rows) if (r.kind === 'key' || r.kind === 'seat') count += 1
1893
+ for (const r of rows) if (settingsRowFocusable(r)) count += 1
1522
1894
  // P32: the block's budget is the **lines** it may draw below the card frame — the assembly hands
1523
1895
  // over everything the page's other blocks leave (`budget - fullRows - the frame's two rows`), and
1524
1896
  // the tail is spent out of that same budget, so what the tail does not need goes to real rows
@@ -1529,7 +1901,17 @@ function settingsBlock(ctx: Ctx): Block | null {
1529
1901
  // The tail under the window: the CLI hint, a blank, the audit heading and its tail (the heading
1530
1902
  // always has one line under it — a dash when the command's log is empty).
1531
1903
  const audit = (block.audit ?? []).slice(-SETTINGS_AUDIT_LINES)
1532
- const tailLines = 1 + 1 + 1 + Math.max(1, audit.length)
1904
+ // P232: the command's own policy diagnosis (missing/retired keys, an unmapped category map) is
1905
+ // part of the view: a legacy contract must say so, with the CLI route the command itself names.
1906
+ const diagnosis = String(block.models?.diagnostic ?? '')
1907
+ .split('\n')
1908
+ .map((l) => l.trim())
1909
+ .filter((l) => l !== '')
1910
+ const diagShown = diagnosis.slice(0, SETTINGS_DIAG_LINES)
1911
+ const diagRest = diagnosis.length - diagShown.length
1912
+ const diagChunks = diagShown.map((d) => diagnoseChunks(d, Math.max(8, width - 3), SETTINGS_DIAG_WRAP))
1913
+ 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
1533
1915
  // The row cap: each row costs at least its own line, and the tail is already spoken for.
1534
1916
  const desired = Math.max(1, Math.min(Math.max(1, count), Math.max(1, room - tailLines)))
1535
1917
  const maxOffset = Math.max(0, count - desired)
@@ -1551,7 +1933,7 @@ function settingsBlock(ctx: Ctx): Block | null {
1551
1933
  const units: { heading: number }[] = []
1552
1934
  let pendingHeading = 0
1553
1935
  for (const r of rows) {
1554
- if (r.kind === 'group' || r.kind === 'seat-group') {
1936
+ if (!settingsRowFocusable(r)) {
1555
1937
  pendingHeading = 1
1556
1938
  continue
1557
1939
  }
@@ -1643,7 +2025,17 @@ function settingsBlock(ctx: Ctx): Block | null {
1643
2025
  }
1644
2026
  return marks.length ? `${base} · ${marks.join(' · ')}` : base
1645
2027
  }
1646
- put(ln(seg(` ${fill(s.settingsChoiceTitle, { label: keyLabel(s, choice.key), key: choice.key })}`, 'heading')))
2028
+ put(
2029
+ ln(
2030
+ seg(
2031
+ choice.category
2032
+ ? ` ${fill(s.settingsCategoryPickerTitle, { category: choice.key })}`
2033
+ : ` ${fill(s.settingsChoiceTitle, { label: keyLabel(s, choice.key), key: choice.key })}`,
2034
+ 'heading',
2035
+ ),
2036
+ ),
2037
+ )
2038
+ if (choice.category) put(ln(seg(` ${s.settingsCategoryPickerHint}`, 'dim')))
1647
2039
  if (choice.interval) {
1648
2040
  put(
1649
2041
  ln(
@@ -1669,40 +2061,13 @@ function settingsBlock(ctx: Ctx): Block | null {
1669
2061
  const entryHiddenBelow = Math.max(0, entries.length - (entryOffset + entryVisible))
1670
2062
  if (entryHiddenBelow > 0) put(ln(seg(` ${fill(s.laneHiddenBelow, { n: String(entryHiddenBelow) })}`, 'dim')))
1671
2063
  put(ln(seg('')))
1672
- put(ln(seg(` ${s.settingsChoiceHint}`, 'dim')))
2064
+ put(ln(seg(` ${choice.category ? s.settingsCategoryPickerHint : s.settingsChoiceHint}`, 'dim')))
1673
2065
  // P32: a picker covers the row list, so what its own entries do not use stays inside the card
1674
2066
  // (the fill rule below); a short picker must not leave the pane half blank either.
1675
2067
  while (lines.length < room) put(ln(seg('')))
1676
2068
  return one(lines, { focus: sel, offset: entryOffset, visible: entryVisible, count: entries.length })
1677
2069
  }
1678
2070
 
1679
- // The seat picker (P22/B4): the models the command reports as known, then the removal and the
1680
- // free-text line — the editor opens on whichever is chosen.
1681
- const picker = ctx.view.seatPicker
1682
- if (picker) {
1683
- const options = [...picker.models, '-', '']
1684
- const sel = Math.max(0, Math.min(options.length - 1, picker.index))
1685
- const lines: PlacedLine[] = []
1686
- const put = (line: Line): void => {
1687
- lines.push({ line: truncLine(line, width) })
1688
- }
1689
- put(ln(seg(` ${fill(s.seatPickerTitle, { seat: picker.agent })}`, 'heading')))
1690
- options.forEach((opt, i) => {
1691
- const label = opt === '-' ? s.seatPickerRemove : opt === '' ? s.seatPickerFree : opt
1692
- const row = ln(
1693
- seg(`${i === sel ? s.settingsCursor : ' '} `, 'accent'),
1694
- seg(label, i === sel ? 'selected' : opt === '' || opt === '-' ? 'dim' : 'text'),
1695
- )
1696
- const action: Action = { kind: 'seat-pick', index: i }
1697
- const rowW = Math.max(2, Math.min(width, 1 + dispWidth(textOf(row))))
1698
- lines.push(placedWithHits(row, ctx.view.tui ? [{ start: 1, end: rowW, action }] : undefined, width))
1699
- })
1700
- put(ln(seg('')))
1701
- put(ln(seg(` ${s.seatPickerHint}`, 'dim')))
1702
- while (lines.length < room) put(ln(seg('')))
1703
- return one(lines, { focus: sel, offset: 0, visible: options.length, count: options.length })
1704
- }
1705
-
1706
2071
  const lines: PlacedLine[] = []
1707
2072
  const hiddenAbove = offset
1708
2073
  const hiddenBelow = Math.max(0, count - (offset + visible))
@@ -1713,11 +2078,18 @@ function settingsBlock(ctx: Ctx): Block | null {
1713
2078
 
1714
2079
  let idx = -1
1715
2080
  for (const r of rows) {
1716
- if (r.kind === 'key' || r.kind === 'seat') {
2081
+ if (settingsRowFocusable(r)) {
1717
2082
  idx += 1
1718
2083
  if (idx < offset || idx >= offset + visible) continue
1719
2084
  const focused = idx === focus
1720
- const placed = r.kind === 'key' ? settingsKeyLine(ctx, r.key, focused, width) : settingsSeatLine(ctx, r.seat, focused, width)
2085
+ const placed =
2086
+ r.kind === 'key'
2087
+ ? settingsKeyLine(ctx, r.key, focused, width)
2088
+ : r.kind === 'category'
2089
+ ? settingsCategoryLine(ctx, r.category, focused, width)
2090
+ : r.kind === 'assignment'
2091
+ ? settingsAssignmentLine(ctx, r.assignment, focused, width)
2092
+ : settingsPmLaunchLine(ctx, r.launch, focused, width)
1721
2093
  // The whole row is a target: a click on an unfocused row moves the focus, a second click on
1722
2094
  // the focused row opens it (the kanban's rule).
1723
2095
  const action: Action = focused ? { kind: 'settings-open', index: idx } : { kind: 'settings-focus', index: idx }
@@ -1728,19 +2100,20 @@ function settingsBlock(ctx: Ctx): Block | null {
1728
2100
  // A heading draws only when the next focusable row is inside the window.
1729
2101
  const next = idx + 1
1730
2102
  if (next < offset || next >= offset + visible) continue
1731
- if (r.kind === 'group' || r.kind === 'seat-group') {
1732
- // P32 (the user's first report): a heading indented like a row reads as one more row. It is a
1733
- // **section rule** instead — `── 身份与账本布局 ────…`, the shape the non-framed blocks already
1734
- // use — so a heading and a key row cannot be confused in a monochrome capture either, and
1735
- // consecutive groups are separated by their own headings without spending a second line.
1736
- put(ruleTitle(r.label, width, r.kind === 'group' ? r.tone : 'accent'))
1737
- }
2103
+ put(ruleTitle(r.label, width, r.tone))
1738
2104
  }
1739
2105
  if (hiddenBelow > 0) put(ln(seg(` ${fill(s.laneHiddenBelow, { n: String(hiddenBelow) })}`, 'dim')))
1740
2106
 
1741
2107
  // The CLI-alignment line (M49): the row's label is for reading, the raw key is for typing.
1742
2108
  put(ln(seg(` ${settingsCliHint(s, rows, focus)}`, 'dim')))
1743
2109
 
2110
+ // The policy's migration diagnosis (P232): visible, and the CLI route it names is the route.
2111
+ if (diagShown.length) {
2112
+ put(ln(seg(` ${s.settingsDiagnosisHeading}`, 'warn')))
2113
+ for (const chunks of diagChunks) for (const d of chunks) put(ln(seg(` ${d}`, 'warn')))
2114
+ if (diagRest > 0) put(ln(seg(` ${fill(s.laneHiddenBelow, { n: String(diagRest) })}`, 'dim')))
2115
+ }
2116
+
1744
2117
  // The audit footer: at most three lines, newest last (the CLI's own tail).
1745
2118
  put(ln(seg('')))
1746
2119
  put(ln(seg(` ${s.settingsAuditHeading}`, 'heading')))
@@ -2034,12 +2407,6 @@ function keyBandBlock(ctx: Ctx, rowsAvailable = true): Block {
2034
2407
  { text: s.keyOpen, action: { kind: 'choice-pick', index: -1 } },
2035
2408
  { text: s.keyDetailClose, action: { kind: 'choice-close' } },
2036
2409
  ]
2037
- : ctx.view.seatPicker
2038
- ? [
2039
- { text: s.keyRows, action: { kind: 'seat-move', delta: 1 } },
2040
- { text: s.keySeatPick, action: { kind: 'seat-pick', index: -1 } },
2041
- { text: s.keyDetailClose, action: { kind: 'settings-close' } },
2042
- ]
2043
2410
  : [
2044
2411
  { text: s.keyRows, action: { kind: 'settings-scroll', delta: 1 } },
2045
2412
  { text: s.keyOpen, action: { kind: 'settings-open', index: -1 } },
@@ -2060,6 +2427,20 @@ function keyBandBlock(ctx: Ctx, rowsAvailable = true): Block {
2060
2427
  { text: s.keyPages, action: { kind: 'page-cycle' } },
2061
2428
  { text: s.keyQuit, action: { kind: 'quit' } },
2062
2429
  ]
2430
+ : ctx.view.page === 5
2431
+ ? ctx.view.replyBody
2432
+ ? [
2433
+ { text: s.keyDetailScroll, action: { kind: 'reply-scroll', delta: 1 } },
2434
+ { text: s.keyDetailClose, action: { kind: 'reply-close' } },
2435
+ { text: s.keyPages, action: { kind: 'page-cycle' } },
2436
+ ]
2437
+ : [
2438
+ { text: s.keyReplies, action: { kind: 'reply-page', dir: -1 } },
2439
+ { text: s.keyOpen, action: { kind: 'reply-open' } },
2440
+ { text: s.keyReplyReset, action: { kind: 'reply-reset' } },
2441
+ { text: s.keyPages, action: { kind: 'page-cycle' } },
2442
+ { text: s.keyQuit, action: { kind: 'quit' } },
2443
+ ]
2063
2444
  : ctx.view.page === 4
2064
2445
  ? [
2065
2446
  { text: s.keyLanes, action: { kind: 'lane-move', delta: 1 } },
@@ -2136,20 +2517,27 @@ function pageTabsBlock(ctx: Ctx): Block | null {
2136
2517
  const line: Line = []
2137
2518
  const hits: Hit[] = []
2138
2519
  let x = 1
2139
- const tabs: { page: PageId; text: string }[] = [
2140
- { page: 1, text: s.pageOverview },
2141
- { page: 2, text: s.pageWork },
2142
- { page: 3, text: s.pageMessages },
2143
- { page: 4, text: s.pageBoard },
2520
+ const tabs: { page: PageId; text: string; short: string }[] = [
2521
+ { page: 1, text: s.pageOverview, short: s.pageOverviewShort },
2522
+ { page: 2, text: s.pageWork, short: s.pageWorkShort },
2523
+ { page: 3, text: s.pageMessages, short: s.pageMessagesShort },
2524
+ { page: 4, text: s.pageBoard, short: s.pageBoardShort },
2525
+ { page: 5, text: s.pageReplies, short: s.pageRepliesShort },
2144
2526
  ]
2145
2527
  const boxed = isFramed(ctx)
2528
+ // 59-column tiers: the five full labels do not fit, so the band falls back to `<n><short label>`
2529
+ // for every page (the active one keeps its number *and* its visible label, and all five stay
2530
+ // reachable without horizontal overflow — the narrow-tabs requirement).
2531
+ const full = tabs.map((t) => fill(s.pageTab, { name: t.text })).join(' ')
2532
+ const narrow = dispWidth(full) > ctx.width
2146
2533
  for (const tab of tabs) {
2147
2534
  const active = ctx.view.page === tab.page
2535
+ const label = narrow ? `${tab.page}${tab.short}` : tab.text
2148
2536
  const text = active
2149
2537
  ? boxed
2150
- ? `[${tab.text}]`
2151
- : fill(s.pageTabActive, { name: tab.text })
2152
- : fill(s.pageTab, { name: tab.text })
2538
+ ? `[${label}]`
2539
+ : fill(s.pageTabActive, { name: label })
2540
+ : fill(s.pageTab, { name: label })
2153
2541
  const start = x
2154
2542
  line.push(seg(text, active ? 'accent' : 'dim'))
2155
2543
  x += dispWidth(text)
@@ -2176,7 +2564,15 @@ function overlayPrefs(ctx: Ctx): { pref: string; label: string; value: string }[
2176
2564
  }
2177
2565
 
2178
2566
  function pageName(page: PageId, s: Strings): string {
2179
- return page === 1 ? s.pageOverview : page === 2 ? s.pageWork : page === 3 ? s.pageMessages : s.pageBoard
2567
+ return page === 1
2568
+ ? s.pageOverview
2569
+ : page === 2
2570
+ ? s.pageWork
2571
+ : page === 3
2572
+ ? s.pageMessages
2573
+ : page === 4
2574
+ ? s.pageBoard
2575
+ : s.pageReplies
2180
2576
  }
2181
2577
 
2182
2578
  /** The overlay's cursor column (` › ` / ` `) and the separator that keeps the two columns apart. */
@@ -2254,6 +2650,7 @@ function pageDefinitions(ctx: Ctx): Block[] {
2254
2650
  statusBlock(ctx),
2255
2651
  capacityBlock(ctx),
2256
2652
  progressBlock(ctx),
2653
+ replySummaryBlock(ctx),
2257
2654
  deliveriesBlock(ctx),
2258
2655
  agentsBlock(left()),
2259
2656
  eventsBlock(right()),
@@ -2274,6 +2671,10 @@ function pageDefinitions(ctx: Ctx): Block[] {
2274
2671
  // The detail view replaces the kanban's blocks (the title band, tabs and key band stay).
2275
2672
  blocks.push(ctx.view.detail ? detailBlock(ctx) : kanbanBlock(ctx))
2276
2673
  break
2674
+ case 5:
2675
+ // The reply viewer replaces the list exactly the way the detail view replaces the kanban.
2676
+ blocks.push(ctx.view.replyBody ? replyViewerBlock(ctx) : replyListBlock(ctx))
2677
+ break
2277
2678
  default:
2278
2679
  blocks.push(queueBlock(left()), inboxBlock(right()), patrolBlock(right()), trendBlock(right()), healthBlock(right()))
2279
2680
  break
@@ -2351,6 +2752,8 @@ export function layout(input: LayoutInput): Frame {
2351
2752
  let laneWindows: LaneWindow[] | undefined
2352
2753
  let detailWindow: DetailWindow | undefined
2353
2754
  let settingsWindow: SettingsWindow | undefined
2755
+ let replyListWindow: ReplyWindow | undefined
2756
+ let replyDocWindow: ReplyDocWindow | undefined
2354
2757
  for (const b of fullBlocks) {
2355
2758
  // The board page's lanes are told how many rows they may use (the frame is bounded): the lane
2356
2759
  // windows then grow with the pane instead of showing blank card space (the bounded-frame rule).
@@ -2365,10 +2768,16 @@ export function layout(input: LayoutInput): Frame {
2365
2768
  ? (detailBlock({ ...ctx, detailRows: Math.max(2, budget - fullRows.length - (framed ? 2 : 0)) }) ?? b)
2366
2769
  : height > 0 && b.id === 'settings'
2367
2770
  ? (settingsBlock({ ...ctx, settingsRows: Math.max(3, budget - fullRows.length - (framed ? 2 : 0)) }) ?? b)
2771
+ : height > 0 && b.id === 'reply_list'
2772
+ ? (replyListBlock({ ...ctx, replyRows: Math.max(2, budget - fullRows.length - (framed ? 2 : 0)) }) ?? b)
2773
+ : height > 0 && b.id === 'reply_viewer'
2774
+ ? (replyViewerBlock({ ...ctx, replyDocRows: Math.max(2, budget - fullRows.length - (framed ? 2 : 0)) }) ?? b)
2368
2775
  : b
2369
2776
  if (block.id === 'kanban' && block.lanes) laneWindows = block.lanes
2370
2777
  if (block.id === 'detail' && block.detail) detailWindow = block.detail
2371
2778
  if (block.id === 'settings' && block.settings) settingsWindow = block.settings
2779
+ if (block.id === 'reply_list' && block.replyList) replyListWindow = block.replyList
2780
+ if (block.id === 'reply_viewer' && block.replyDoc) replyDocWindow = block.replyDoc
2372
2781
  const chunk = place(block, budget - fullRows.length, width)
2373
2782
  for (const l of chunk) fullRows.push(l)
2374
2783
  }
@@ -2519,6 +2928,8 @@ export function layout(input: LayoutInput): Frame {
2519
2928
  targets,
2520
2929
  ...(laneWindows ? { lanes: laneWindows } : {}),
2521
2930
  ...(detailWindow ? { detail: detailWindow } : {}),
2931
+ ...(replyListWindow ? { replyList: replyListWindow } : {}),
2932
+ ...(replyDocWindow ? { replyDoc: replyDocWindow } : {}),
2522
2933
  ...(settingsWindow ? { settings: settingsWindow } : {}),
2523
2934
  ...(boardOrder ? { boardOrder } : {}),
2524
2935
  }