teamsmith 0.2.0 → 0.3.1

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 (163) hide show
  1. package/README.md +4 -4
  2. package/package.json +1 -1
  3. package/skills/teamsmith/CHANGELOG.md +69 -0
  4. package/skills/teamsmith/SKILL.md +20 -13
  5. package/skills/teamsmith/extension/team-inbox-watch.ts +5 -3
  6. package/skills/teamsmith/extension/team-notify.ts +37 -6
  7. package/skills/teamsmith/extension/team.ts +438 -0
  8. package/skills/teamsmith/references/config.md +39 -6
  9. package/skills/teamsmith/references/migration.md +197 -47
  10. package/skills/teamsmith/references/protocol.md +201 -30
  11. package/skills/teamsmith/references/troubleshooting.md +130 -10
  12. package/skills/teamsmith/references/workflows.md +36 -2
  13. package/skills/teamsmith/scripts/lib/cmd-agents.sh +318 -23
  14. package/skills/teamsmith/scripts/lib/cmd-bootstrap.sh +2 -2
  15. package/skills/teamsmith/scripts/lib/cmd-config.sh +349 -67
  16. package/skills/teamsmith/scripts/lib/cmd-draft.sh +4 -4
  17. package/skills/teamsmith/scripts/lib/cmd-help.sh +677 -0
  18. package/skills/teamsmith/scripts/lib/cmd-init.sh +157 -5
  19. package/skills/teamsmith/scripts/lib/cmd-interrupt.sh +461 -0
  20. package/skills/teamsmith/scripts/lib/cmd-meeting.sh +2 -25
  21. package/skills/teamsmith/scripts/lib/cmd-project.sh +30 -103
  22. package/skills/teamsmith/scripts/lib/cmd-reap.sh +277 -0
  23. package/skills/teamsmith/scripts/lib/cmd-reply.sh +3 -3
  24. package/skills/teamsmith/scripts/lib/cmd-review.sh +182 -32
  25. package/skills/teamsmith/scripts/lib/cmd-status.sh +234 -21
  26. package/skills/teamsmith/scripts/lib/cmd-update.sh +36 -7
  27. package/skills/teamsmith/scripts/lib/cmd-watch.sh +564 -46
  28. package/skills/teamsmith/scripts/lib/common.sh +1004 -245
  29. package/skills/teamsmith/scripts/lib/gate-lock.sh +582 -0
  30. package/skills/teamsmith/scripts/panel/draft-send.sh +11 -1
  31. package/skills/teamsmith/scripts/panel/panel.js +211 -211
  32. package/skills/teamsmith/scripts/panel/src/App.tsx +58 -21
  33. package/skills/teamsmith/scripts/panel/src/clipboard.ts +12 -5
  34. package/skills/teamsmith/scripts/panel/src/compose.ts +6 -3
  35. package/skills/teamsmith/scripts/panel/src/data.ts +51 -5
  36. package/skills/teamsmith/scripts/panel/src/layout.ts +209 -69
  37. package/skills/teamsmith/scripts/panel/src/main.tsx +37 -8
  38. package/skills/teamsmith/scripts/panel/src/strings/en.ts +39 -29
  39. package/skills/teamsmith/scripts/panel/src/strings/zh.ts +41 -31
  40. package/skills/teamsmith/scripts/panel/src/types.ts +28 -3
  41. package/skills/teamsmith/scripts/replies.mjs +4 -1
  42. package/skills/teamsmith/scripts/shim/killall +10 -0
  43. package/skills/teamsmith/scripts/shim/pgrep +10 -0
  44. package/skills/teamsmith/scripts/shim/pidof +10 -0
  45. package/skills/teamsmith/scripts/shim/pkill +10 -0
  46. package/skills/teamsmith/scripts/shim/signal-gate +108 -31
  47. package/skills/teamsmith/scripts/shim/tmux +18 -0
  48. package/skills/teamsmith/scripts/strings/commands.tsv +86 -0
  49. package/skills/teamsmith/scripts/strings/help.en.tsv +503 -0
  50. package/skills/teamsmith/scripts/strings/help.zh.tsv +489 -0
  51. package/skills/teamsmith/scripts/team +19 -6
  52. package/skills/teamsmith/templates/AGENTS.section.md.tmpl +8 -1
  53. package/skills/teamsmith/templates/config.sh.tmpl +20 -1
  54. package/skills/teamsmith/templates/pm-prompt.md.tmpl +21 -0
  55. package/skills/teamsmith/tests/README.md +31 -0
  56. package/skills/teamsmith/tests/bg-ledger-harness.mjs +464 -40
  57. package/skills/teamsmith/tests/bg-ledger.sh +168 -10
  58. package/skills/teamsmith/tests/checkout-shape-probe.sh +83 -54
  59. package/skills/teamsmith/tests/config-cli.sh +184 -32
  60. package/skills/teamsmith/tests/fixtures/delivery-truth-real/scenario.sh +7 -1
  61. package/skills/teamsmith/tests/fixtures/p287/lint-good.sh.in +3 -0
  62. package/skills/teamsmith/tests/fixtures/p287/lint-hardcoded.sh.in +3 -0
  63. package/skills/teamsmith/tests/fixtures/p287/lint-no-ns.sh.in +3 -0
  64. package/skills/teamsmith/tests/fixtures/p55/flip-p49.sh +18 -6
  65. package/skills/teamsmith/tests/flip-m33.sh +5 -3
  66. package/skills/teamsmith/tests/flip-p158.sh +2 -1
  67. package/skills/teamsmith/tests/flip-p308-skip-not-pass.sh +151 -0
  68. package/skills/teamsmith/tests/flip-p310-lock.sh +210 -0
  69. package/skills/teamsmith/tests/flip-p310-socket.sh +125 -0
  70. package/skills/teamsmith/tests/gate-guard.sh +52 -79
  71. package/skills/teamsmith/tests/help-surface.sh +1664 -0
  72. package/skills/teamsmith/tests/install-shape.sh +359 -22
  73. package/skills/teamsmith/tests/key-replies-pty.sh +9 -10
  74. package/skills/teamsmith/tests/key-replies-ui.sh +2 -8
  75. package/skills/teamsmith/tests/key-replies.sh +281 -28
  76. package/skills/teamsmith/tests/ledger-ban.sh +5 -4
  77. package/skills/teamsmith/tests/ledger-claim.sh +2 -1
  78. package/skills/teamsmith/tests/lib/bounded-spin.sh +90 -0
  79. package/skills/teamsmith/tests/lib/model-policy.sh +4 -0
  80. package/skills/teamsmith/tests/lib/model-routing-flips.py +51 -0
  81. package/skills/teamsmith/tests/lib/pty-wait.sh +21 -111
  82. package/skills/teamsmith/tests/lib/reply-fixture.sh +4 -9
  83. package/skills/teamsmith/tests/lib/section-guard.sh +316 -164
  84. package/skills/teamsmith/tests/lib/tmp-root.sh +139 -27
  85. package/skills/teamsmith/tests/lib/tmux-cap.sh +10 -1
  86. package/skills/teamsmith/tests/lib/tmux-iso.sh +31 -13
  87. package/skills/teamsmith/tests/loop-inventory.tsv +83 -77
  88. package/skills/teamsmith/tests/panel-b2.sh +430 -352
  89. package/skills/teamsmith/tests/panel-b3-stub.sh +112 -4
  90. package/skills/teamsmith/tests/panel-b3.sh +314 -62
  91. package/skills/teamsmith/tests/panel-choices.sh +11 -6
  92. package/skills/teamsmith/tests/panel-cpu.sh +43 -130
  93. package/skills/teamsmith/tests/panel-p21.sh +251 -265
  94. package/skills/teamsmith/tests/panel-snapshots.sh +41 -225
  95. package/skills/teamsmith/tests/panel-strings.mjs +33 -18
  96. package/skills/teamsmith/tests/perf.sh +187 -396
  97. package/skills/teamsmith/tests/routes.sh +440 -117
  98. package/skills/teamsmith/tests/seat-interrupt.sh +1012 -0
  99. package/skills/teamsmith/tests/seat-visibility.sh +675 -0
  100. package/skills/teamsmith/tests/section-guard.sh +13 -102
  101. package/skills/teamsmith/tests/section-needs-audit.sh +24 -7
  102. package/skills/teamsmith/tests/section-paths.tsv +32 -18
  103. package/skills/teamsmith/tests/section-select.sh +371 -19
  104. package/skills/teamsmith/tests/signal-gate.sh +249 -27
  105. package/skills/teamsmith/tests/signal-lint-legacy.txt +4 -1
  106. package/skills/teamsmith/tests/slash-team-e2e.sh +323 -0
  107. package/skills/teamsmith/tests/slash-team.sh +617 -0
  108. package/skills/teamsmith/tests/slice-coverage.sh +206 -0
  109. package/skills/teamsmith/tests/smoke.sh +3595 -788
  110. package/skills/teamsmith/tests/task-model-routing.sh +530 -15
  111. package/skills/teamsmith/tests/team-bg-stop.sh +18 -10
  112. package/skills/teamsmith/tests/tmp-hygiene.sh +782 -45
  113. package/skills/teamsmith/tests/tmux-identity-leak.sh +773 -0
  114. package/skills/teamsmith/tests/tmux-lint-legacy.txt +12 -18
  115. package/skills/teamsmith/tests/upgrade-recipe.sh +537 -0
  116. package/skills/teamsmith/tests/workflow-entry.sh +207 -0
  117. package/skills/teamsmith-init/SKILL.md +12 -12
  118. package/skills/teamsmith-init/references/bootstrap.md +3 -3
  119. package/skills/teamsmith/tests/flip-glue.sh +0 -162
  120. package/skills/teamsmith/tests/flip-m12-26c.sh +0 -129
  121. package/skills/teamsmith/tests/flip-m12.sh +0 -185
  122. package/skills/teamsmith/tests/flip-m16.sh +0 -166
  123. package/skills/teamsmith/tests/flip-m17.sh +0 -204
  124. package/skills/teamsmith/tests/flip-m34.sh +0 -96
  125. package/skills/teamsmith/tests/flip-m37.sh +0 -185
  126. package/skills/teamsmith/tests/flip-m4.3.sh +0 -375
  127. package/skills/teamsmith/tests/flip-m43.sh +0 -128
  128. package/skills/teamsmith/tests/flip-m45.sh +0 -244
  129. package/skills/teamsmith/tests/flip-m46.sh +0 -238
  130. package/skills/teamsmith/tests/flip-m48.sh +0 -304
  131. package/skills/teamsmith/tests/flip-m6.2.sh +0 -205
  132. package/skills/teamsmith/tests/flip-m6.3.sh +0 -283
  133. package/skills/teamsmith/tests/flip-m6.4.sh +0 -267
  134. package/skills/teamsmith/tests/flip-m6.5.sh +0 -113
  135. package/skills/teamsmith/tests/flip-m7.1.sh +0 -135
  136. package/skills/teamsmith/tests/flip-m7.2.sh +0 -321
  137. package/skills/teamsmith/tests/flip-p144.sh +0 -112
  138. package/skills/teamsmith/tests/flip-p156.sh +0 -133
  139. package/skills/teamsmith/tests/flip-p160.sh +0 -182
  140. package/skills/teamsmith/tests/flip-p171.sh +0 -249
  141. package/skills/teamsmith/tests/flip-p18.1.sh +0 -95
  142. package/skills/teamsmith/tests/flip-p20.sh +0 -286
  143. package/skills/teamsmith/tests/flip-p201.sh +0 -249
  144. package/skills/teamsmith/tests/flip-p210.sh +0 -239
  145. package/skills/teamsmith/tests/flip-p211.sh +0 -152
  146. package/skills/teamsmith/tests/flip-p217.sh +0 -288
  147. package/skills/teamsmith/tests/flip-p22.sh +0 -123
  148. package/skills/teamsmith/tests/flip-p23.sh +0 -239
  149. package/skills/teamsmith/tests/flip-p25.sh +0 -165
  150. package/skills/teamsmith/tests/flip-p71.sh +0 -184
  151. package/skills/teamsmith/tests/flip-p72.sh +0 -202
  152. package/skills/teamsmith/tests/load-experiment.sh +0 -290
  153. package/skills/teamsmith/tests/panel-cpu-premise.sh +0 -173
  154. package/skills/teamsmith/tests/panel-flip-m54.sh +0 -207
  155. package/skills/teamsmith/tests/panel-flip-p123.sh +0 -278
  156. package/skills/teamsmith/tests/panel-flip-p125.sh +0 -318
  157. package/skills/teamsmith/tests/panel-flip-p128.sh +0 -259
  158. package/skills/teamsmith/tests/panel-keyprobe-stub.sh +0 -41
  159. package/skills/teamsmith/tests/panel-keyprobe.sh +0 -82
  160. package/skills/teamsmith/tests/panel-knobs.sh +0 -83
  161. package/skills/teamsmith/tests/section-budgets.tsv +0 -154
  162. package/skills/teamsmith/tests/team-bg-flip.sh +0 -239
  163. package/skills/teamsmith/tests/team-inbox-watch-flip.sh +0 -191
@@ -12,7 +12,7 @@
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, settingsRowFocusable, settingsViewRows } from './layout.js'
15
+ import { layout, resolveFocus, focusRefOf, focusRow, rowKey, settingsRowFocusable, settingsViewRows, boardFocusRef, rowSourceOf } from './layout.js'
16
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'
@@ -21,6 +21,7 @@ import type { Settings } from './settings.js'
21
21
  import type {
22
22
  Action,
23
23
  DetailWindow,
24
+ DetailSource,
24
25
  FocusRef,
25
26
  FrameInput,
26
27
  PageId,
@@ -81,8 +82,10 @@ function composeTrayTop(title: string, width: number): string {
81
82
  /** The console's own actions, owned by main.tsx (file I/O, subprocesses, the editor relay). */
82
83
  export interface PanelApi {
83
84
  readDraft(): string
84
- writeDraft(text: string): void
85
- clearDraft(): void
85
+ /** Persist the draft; false when the file could not be written (the settle reads this). */
86
+ writeDraft(text: string): boolean
87
+ /** Empty `state/draft.md`; false when the file could not be emptied (P249). */
88
+ clearDraft(): boolean
86
89
  send(text: string): Promise<Receipt>
87
90
  flushQueue(): Promise<{ ok: boolean; line: string }>
88
91
  setStandby(on: boolean, reason: string): Promise<{ ok: boolean; line: string }>
@@ -115,9 +118,11 @@ export interface PanelApi {
115
118
  /**
116
119
  * Tell the cache which entry's detail view is open (null = closed). While an id is set the
117
120
  * `detail` block joins the wanted set; `file` selects the repo-relative path to serve (the first
118
- * discovered file when omitted). Both are cached options, so an unchanged call rebuilds nothing.
121
+ * discovered file when omitted) and `source` the read-only preview family the id addresses
122
+ * (P249; absent/`entry` is the original entry-id discovery). All three are cached options, so an
123
+ * unchanged call rebuilds nothing.
119
124
  */
120
- setDetail(id: string | null, file?: string | null): void
125
+ setDetail(id: string | null, file?: string | null, source?: DetailSource | null): void
121
126
  /**
122
127
  * Page 5's demand reads (pulse-key-replies): the list cursor (`before`, null = the newest page and
123
128
  * null also drops the list from the wanted set when the page is parked) and the open viewer's
@@ -288,6 +293,7 @@ export function App({
288
293
  // The open detail view's entry id (the board page's Enter / a click on the focused card), its
289
294
  // tab and its document scroll. The view is read-only: no key of its own beyond navigation.
290
295
  const [detailId, setDetailId] = useState<string | null>(null)
296
+ const [detailSource, setDetailSource] = useState<DetailSource>('entry')
291
297
  const [detailIndex, setDetailIndex] = useState(0)
292
298
  const [detailScroll, setDetailScroll] = useState(0)
293
299
  // Page 5 (pulse-key-replies): the cursor chain, the stable-number focus, the open body and the
@@ -425,6 +431,7 @@ export function App({
425
431
  }
426
432
  setViewEntry(null)
427
433
  setDetailId(null)
434
+ setDetailSource('entry')
428
435
  setDetailIndex(0)
429
436
  setDetailScroll(0)
430
437
  api.savePage(next)
@@ -692,14 +699,24 @@ export function App({
692
699
  setBusy(true)
693
700
  try {
694
701
  const r = await api.send(text)
695
- setReceipt(r.state === 'error' ? r : { ...r, detail: '' })
696
702
  setStatus(null)
697
- if (r.state !== 'error') {
703
+ if (r.state === 'error') {
704
+ // The error class keeps every word and stays in the editor: nothing durable holds the text,
705
+ // so the input line is the retry handle and the next Enter tries again (the receipt rides
706
+ // the hint row while the compose stays open).
707
+ setReceipt(r)
708
+ } else if (api.clearDraft()) {
709
+ // Settled and the file is empty: the input line may follow it (memory = disk).
698
710
  updateDraft('', false)
699
711
  setPoint(0)
700
- api.clearDraft()
712
+ setReceipt({ ...r, detail: '' })
713
+ setComposing(false)
714
+ } else {
715
+ // Settled, but `state/draft.md` could not be emptied: the memory copy must not be dropped
716
+ // (that was the ghost draft), so the words stay in the editor and the receipt names the
717
+ // file it could not empty.
718
+ setReceipt({ ...r, detail: fill(stringsRef.current.draftNotCleared, { file: 'state/draft.md' }) })
701
719
  }
702
- setComposing(false)
703
720
  } finally {
704
721
  sendingRef.current = false
705
722
  setBusy(false)
@@ -931,8 +948,9 @@ export function App({
931
948
  const cur = focusRef.current
932
949
  let idx = -1
933
950
  if (cur) {
934
- idx = order.findIndex((r) => r.id === cur.id && (r.nth ?? 0) === (cur.nth ?? 0))
935
- if (idx < 0) idx = order.findIndex((r) => r.id === cur.id)
951
+ // The row is matched by its block scope too: two blocks may draw the same id (P249).
952
+ idx = order.findIndex((r) => r.lane === cur.lane && r.id === cur.id && (r.nth ?? 0) === (cur.nth ?? 0))
953
+ if (idx < 0) idx = order.findIndex((r) => r.lane === cur.lane && r.id === cur.id)
936
954
  }
937
955
  if (idx < 0) {
938
956
  setFocus(order[0])
@@ -948,22 +966,27 @@ export function App({
948
966
  setLaneOffset((prev) => ({ ...prev, [lane]: Math.max(0, Math.min(max, (prev[lane] ?? (win?.offset ?? 0)) + delta)) }))
949
967
  }, [])
950
968
 
951
- /** Open an entry's detail view: the first tab, from the top (the board page's Enter / a click). */
952
- const openDetail = useCallback((id: string) => {
969
+ /** Open an entry's detail view: the first tab, from the top (the board page's Enter / a click).
970
+ * The source is fixed by the surface that opened it (P249) and rides every reader request. */
971
+ const openDetail = useCallback((id: string, source: DetailSource = 'entry') => {
953
972
  setDetailIndex(0)
954
973
  setDetailScroll(0)
974
+ setDetailSource(source)
955
975
  setDetailId(id)
956
976
  }, [])
957
977
 
958
- /** Enter on the work page: open the focused row (or the first drawn one, when it left the board). */
978
+ /** Enter on the work page: open the focused row (or the first drawn one, when it left the board).
979
+ * The page-wide order carries each row's block scope, and the scope picks the reader's source. */
959
980
  const openWorkFocused = useCallback(() => {
960
981
  const order = boardOrderRef.current
961
982
  if (!order.length) return
962
983
  const cur = focusRef.current
963
984
  const hit = cur
964
- ? order.find((r) => r.id === cur.id && (r.nth ?? 0) === (cur.nth ?? 0)) ?? order.find((r) => r.id === cur.id)
985
+ ? order.find((r) => r.lane === cur.lane && r.id === cur.id && (r.nth ?? 0) === (cur.nth ?? 0)) ??
986
+ order.find((r) => r.lane === cur.lane && r.id === cur.id)
965
987
  : undefined
966
- openDetail((hit ?? order[0]).id)
988
+ const row = hit ?? order[0]
989
+ openDetail(row.id, rowSourceOf(row.lane))
967
990
  }, [openDetail])
968
991
 
969
992
  // ---- project settings (P22/B2): the view's focus walk, its origin and its row opening.
@@ -1399,7 +1422,10 @@ export function App({
1399
1422
  const key = row.key
1400
1423
  if (key.class === 'refuse') {
1401
1424
  setReceipt(null)
1402
- setStatus(`${key.name} · ${key.route || key.warning || stringsRef.current.settingsRefusedRoute}`)
1425
+ // P266: the route speaks in plain language; the raw key only leads when the row has no other
1426
+ // name for itself (a key the schema does not know — its row's own text is that raw name).
1427
+ const named = key.known === false ? `${key.name} · ` : ''
1428
+ setStatus(`${named}${key.route || key.warning || stringsRef.current.settingsRefusedRoute}`)
1403
1429
  return
1404
1430
  }
1405
1431
  // The whole-map row's editor is the categories block, never a composed pair list (P232).
@@ -1481,8 +1507,8 @@ export function App({
1481
1507
  return
1482
1508
  }
1483
1509
  const files = detailBlockData?.files ?? []
1484
- api.setDetail(detailId, files[detailIndexRef.current]?.path ?? null)
1485
- }, [api, detailId, detailIndex, detailBlockData])
1510
+ api.setDetail(detailId, files[detailIndexRef.current]?.path ?? null, detailSource)
1511
+ }, [api, detailId, detailIndex, detailSource, detailBlockData])
1486
1512
 
1487
1513
  /** Page 5's slots as the last snapshot carries them (never a re-read of the store). */
1488
1514
  const replyEntries = useCallback((): ReplyEntry[] => dataRef.current.blocks?.reply_list?.entries ?? [], [])
@@ -1663,7 +1689,11 @@ export function App({
1663
1689
  openWorkFocused()
1664
1690
  return
1665
1691
  }
1666
- const current = resolveFocus(boardRows(), focusRef.current)
1692
+ // A preview row's ref (lane = a preview block's scope) is not a kanban card: no cursor is
1693
+ // drawn for it and Enter opens nothing; a step re-anchors to the board (P249).
1694
+ const focus = focusRef.current
1695
+ if (focus && !boardFocusRef(focus)) return
1696
+ const current = resolveFocus(boardRows(), focus)
1667
1697
  if (current) openDetail(current.id)
1668
1698
  return
1669
1699
  }
@@ -1763,6 +1793,10 @@ export function App({
1763
1793
  // command's refusal) rides the hint row *above* the input so the input line stays last
1764
1794
  // (the IME cursor anchor rule) while the editor stays open with its draft.
1765
1795
  ...(status && (mode === 'setting' || mode === 'filter') ? [status] : []),
1796
+ // P249: a message send that could not settle cleanly (the error class, or a draft file the
1797
+ // console could not empty) keeps the compose open, so its receipt rides the same row — the
1798
+ // words and the reason are visible together.
1799
+ ...(mode === 'message' && receipt ? [receiptLine(receipt, strings)] : []),
1766
1800
  mode === 'message'
1767
1801
  ? strings.composeHint
1768
1802
  : mode === 'reason'
@@ -2322,7 +2356,10 @@ export function App({
2322
2356
  return
2323
2357
  }
2324
2358
  if (page === 4 && key.return) {
2325
- const current = resolveFocus(boardRows(), focusRef.current)
2359
+ // Same rule as the click path: a preview row's ref neither draws nor opens on the kanban.
2360
+ const focus = focusRef.current
2361
+ if (focus && !boardFocusRef(focus)) return
2362
+ const current = resolveFocus(boardRows(), focus)
2326
2363
  if (current) openDetail(current.id)
2327
2364
  return
2328
2365
  }
@@ -9,7 +9,6 @@
9
9
  import { randomUUID } from 'node:crypto'
10
10
  import { spawn } from 'node:child_process'
11
11
  import { writeFileSync } from 'node:fs'
12
- import { tmpdir } from 'node:os'
13
12
  import { join } from 'node:path'
14
13
 
15
14
  /** One bounded subprocess: rc plus the stdout bytes; `null` = the executable does not exist. */
@@ -86,10 +85,18 @@ export async function readClipboard(run: ClipboardRunner): Promise<ClipboardRead
86
85
  return null
87
86
  }
88
87
 
89
- /** The temporary path the paste writes: `${TMPDIR:-/tmp}/teamsmith-paste-<uuid>.<ext>`. */
90
- export function pasteFilePath(mime: string, dir = process.env.TMPDIR || tmpdir(), uuid?: string): string | null {
88
+ /**
89
+ * The temporary path the paste writes: `<resolved temp root>/teamsmith-paste-<uuid>.<ext>`.
90
+ *
91
+ * P309: the directory is **given** by the caller — the same `team_tmp_root` answer the rest of the
92
+ * tool prints (`capacity.temp_root` in the panel data, taken even when that block degrades to `—`
93
+ * for want of a capacity log, P331). Deriving it here again would be a second
94
+ * implementation of the resolution order (`process.env.TMPDIR || tmpdir()` was exactly that), and
95
+ * two answers is how the paste file ends up outside the root `--status`/`--sweep` judge.
96
+ */
97
+ export function pasteFilePath(mime: string, dir: string | undefined, uuid?: string): string | null {
91
98
  const ext = imageExt(mime)
92
- if (!ext) return null
99
+ if (!ext || !dir) return null
93
100
  return join(dir, `teamsmith-paste-${uuid ?? randomUUID()}.${ext}`)
94
101
  }
95
102
 
@@ -97,7 +104,7 @@ export function pasteFilePath(mime: string, dir = process.env.TMPDIR || tmpdir()
97
104
  * Write the clipboard image bytes to the temporary path and return it. The panel never deletes the
98
105
  * file (the requirement) and the path is the whole edit the console makes.
99
106
  */
100
- export function writePasteFile(bytes: Buffer, mime: string, dir?: string, uuid?: string): string | null {
107
+ export function writePasteFile(bytes: Buffer, mime: string, dir: string | undefined, uuid?: string): string | null {
101
108
  const file = pasteFilePath(mime, dir, uuid)
102
109
  if (!file) return null
103
110
  writeFileSync(file, bytes)
@@ -678,13 +678,16 @@ export function parseSendResult(stdout: string): { rc: number; outcome: string;
678
678
 
679
679
  /** The one-line receipt shown under the frame, in the active language's voice. */
680
680
  export function receiptLine(receipt: Receipt, s: Strings): string {
681
+ // A settled receipt normally shows its canonical one-liner; the App puts a non-empty detail here
682
+ // for the one settle that could not go through cleanly — a draft file it could not empty — so the
683
+ // frame names the file instead of claiming the draft is gone (P249).
681
684
  switch (receipt.state) {
682
685
  case 'delivered':
683
- return s.receiptDelivered
686
+ return receipt.detail || s.receiptDelivered
684
687
  case 'queued':
685
- return s.receiptQueued
688
+ return receipt.detail || s.receiptQueued
686
689
  case 'held':
687
- return s.receiptHeld
690
+ return receipt.detail || s.receiptHeld
688
691
  default:
689
692
  return fill(s.receiptError, { detail: receipt.detail || s.sendUnconfirmed })
690
693
  }
@@ -22,7 +22,7 @@ import { appendFileSync, existsSync, readFileSync, writeFileSync } from 'node:fs
22
22
  import { dirname, join, resolve } from 'node:path'
23
23
  import { fileURLToPath } from 'node:url'
24
24
  import { sanitizeDeep } from './sanitize.js'
25
- import type { ActivityBlock, PanelBlocks, PanelData } from './types.js'
25
+ import type { ActivityBlock, DetailSource, PanelBlocks, PanelData } from './types.js'
26
26
 
27
27
  /**
28
28
  * M40 — the panel's identity is its own root (`--root`, else cwd), never an inherited `TEAM_*`.
@@ -120,6 +120,12 @@ export interface DataOptions {
120
120
  blocks?: readonly BlockName[]
121
121
  /** The detail view's entry id; while set, `detail` joins the wanted set (null/absent = parked). */
122
122
  detailId?: string | null
123
+ /**
124
+ * The read-only preview source the open detail view addresses (change:
125
+ * panel-preview-and-compose). Absent/`entry` keeps the original entry-id discovery; the other
126
+ * three become an explicit `--source` on the reader's argv.
127
+ */
128
+ detailSource?: DetailSource | null
123
129
  /** True while the project-settings view is open; only then does `settings` join the wanted set. */
124
130
  settingsOpen?: boolean
125
131
  /** The detail file to serve with `--file` (must be one of the discovered paths). */
@@ -140,6 +146,13 @@ export interface DataResult {
140
146
  blocks?: PanelBlocks
141
147
  /** Blocks whose source failed, timed out or is unreadable in this snapshot (rendered as `—`). */
142
148
  degraded?: BlockName[]
149
+ /**
150
+ * P331: the paste's temp root — the `temp_root` the **capacity** block puts in its payload. It is
151
+ * kept out of `data.capacity` on purpose: that block degrades to `—` while the project has no
152
+ * `capacity.log` (a fresh `team init` project, and the log is history written by patrol ticks),
153
+ * and the paste still needs the root there. Nothing renders it; no other block's payload is kept.
154
+ */
155
+ tempRoot?: string
143
156
  /** Why each degraded block is degraded (diagnostics; never rendered as data). */
144
157
  errors?: Partial<Record<BlockName, string>>
145
158
  error?: string
@@ -187,14 +200,16 @@ const BLOCK_SPECS: Record<BlockName, BlockSpec> = {
187
200
  patrol: { ttlMs: 15000, timeoutMs: 10000 },
188
201
  health: { ttlMs: 600000, timeoutMs: 30000 },
189
202
  // The detail reader rides the open view: the App forces it on open and on a tab switch, so its TTL
190
- // only covers a stale refresh while the view stays open. The `--id`/`--file` arguments come from
191
- // the live options; both are cleared when the view closes.
203
+ // only covers a stale refresh while the view stays open. The `--id`/`--source`/`--file` arguments
204
+ // come from the live options; all are cleared when the view closes. The `entry` source stays
205
+ // implicit so an existing caller's argv is byte-identical.
192
206
  detail: {
193
207
  ttlMs: 15000,
194
208
  timeoutMs: 10000,
195
209
  extraArgs: (opts) => {
196
210
  if (!opts.detailId) return []
197
211
  const args = ['--id', String(opts.detailId)]
212
+ if (opts.detailSource && opts.detailSource !== 'entry') args.push('--source', opts.detailSource)
198
213
  if (opts.detailFile) args.push('--file', String(opts.detailFile))
199
214
  return args
200
215
  },
@@ -241,6 +256,20 @@ interface BlockOutcome {
241
256
  ok: boolean
242
257
  value?: unknown
243
258
  error?: string
259
+ /** P331: the `temp_root` a non-zero `capacity` exit nevertheless printed (see `DataResult.tempRoot`). */
260
+ tempRoot?: string
261
+ }
262
+
263
+ /** The `temp_root` in the JSON a child printed before exiting non-zero, or undefined. */
264
+ function tempRootOf(raw: string): string | undefined {
265
+ const text = raw.trim()
266
+ if (!text) return undefined
267
+ try {
268
+ const root = (JSON.parse(text) as { temp_root?: unknown } | null)?.temp_root
269
+ return typeof root === 'string' && root ? root : undefined
270
+ } catch {
271
+ return undefined
272
+ }
244
273
  }
245
274
 
246
275
  /** One block, one child, one timeout. Never throws and never blocks the loop. */
@@ -302,7 +331,15 @@ function runBlock(
302
331
  if (settled) return
303
332
  const tail = err.trim().split('\n').filter(Boolean).slice(-2).join(' · ')
304
333
  if (code !== 0) {
305
- done({ ok: false, error: `rc=${code ?? '?'}${tail ? `: ${tail}` : ''}` })
334
+ // P331: the capacity block prints its JSON and exits 1 while the project has no
335
+ // `capacity.log` yet. The paste's temp root rides that payload and is not a capacity
336
+ // figure, so it survives the failure — one string, and only from this block. `ok: false`
337
+ // keeps the block itself degraded in the frame and in `--json`.
338
+ done({
339
+ ok: false,
340
+ error: `rc=${code ?? '?'}${tail ? `: ${tail}` : ''}`,
341
+ tempRoot: name === 'capacity' ? tempRootOf(out) : undefined,
342
+ })
306
343
  return
307
344
  }
308
345
  const raw = out.trim()
@@ -377,6 +414,8 @@ interface BlockState {
377
414
  error?: string
378
415
  /** The request key the cached value was built for (`reply_list` cursor / `reply_body` number). */
379
416
  key?: string
417
+ /** P331: the temp root a degraded capacity build printed (see `DataResult.tempRoot`). */
418
+ tempRoot?: string
380
419
  }
381
420
 
382
421
  const PANEL_BLOCK_NAMES: readonly BlockName[] = [
@@ -481,7 +520,11 @@ export function createPanelCache(opts: DataOptions): PanelCache {
481
520
  applyBlock(data, name, s.value)
482
521
  }
483
522
  mergeActivity(data, activity)
484
- return { ok: true, data, activity, blocks, degraded, errors }
523
+ // The paste's temp root: the live capacity block while it is fresh, else the string a degraded
524
+ // capacity payload carried (fresh project: no capacity.log). A capacity block that is merely
525
+ // not built yet leaves it undefined, and the paste writes nothing — never a guessed root.
526
+ const tempRoot = (data.capacity as PanelData['capacity'] | undefined)?.temp_root ?? state.capacity?.tempRoot
527
+ return { ok: true, data, activity, blocks, degraded, errors, ...(tempRoot ? { tempRoot } : {}) }
485
528
  }
486
529
 
487
530
  function build(name: BlockName, key: string): Promise<void> {
@@ -494,10 +537,13 @@ export function createPanelCache(opts: DataOptions): PanelCache {
494
537
  s.value = outcome.value
495
538
  s.at = Date.now()
496
539
  s.error = undefined
540
+ s.tempRoot = undefined
497
541
  } else {
498
542
  // A block that failed is not dressed in last week's number: it renders `—` until the
499
543
  // next successful build (the design's stale-data trade-off, made explicit).
500
544
  s.error = outcome.error || 'failed'
545
+ // P331: the one fact that outlives the failure is the paste's temp root (capacity only).
546
+ s.tempRoot = outcome.tempRoot
501
547
  }
502
548
  })
503
549
  }