teamsmith 0.1.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/README.md +13 -7
  2. package/package.json +1 -1
  3. package/skills/teamsmith/CHANGELOG.md +67 -0
  4. package/skills/teamsmith/SKILL.md +26 -8
  5. package/skills/teamsmith/extension/team-notify.ts +37 -6
  6. package/skills/teamsmith/extension/team.ts +438 -0
  7. package/skills/teamsmith/references/agent-adapters.md +7 -7
  8. package/skills/teamsmith/references/config.md +65 -18
  9. package/skills/teamsmith/references/migration.md +220 -34
  10. package/skills/teamsmith/references/protocol.md +250 -25
  11. package/skills/teamsmith/references/troubleshooting.md +124 -7
  12. package/skills/teamsmith/references/workflows.md +66 -20
  13. package/skills/teamsmith/scripts/lib/cmd-agents.sh +525 -90
  14. package/skills/teamsmith/scripts/lib/cmd-bootstrap.sh +71 -10
  15. package/skills/teamsmith/scripts/lib/cmd-config.sh +562 -128
  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-draft.sh +4 -4
  19. package/skills/teamsmith/scripts/lib/cmd-help.sh +677 -0
  20. package/skills/teamsmith/scripts/lib/cmd-init.sh +157 -5
  21. package/skills/teamsmith/scripts/lib/cmd-interrupt.sh +461 -0
  22. package/skills/teamsmith/scripts/lib/cmd-meeting.sh +2 -25
  23. package/skills/teamsmith/scripts/lib/cmd-project.sh +149 -105
  24. package/skills/teamsmith/scripts/lib/cmd-reap.sh +277 -0
  25. package/skills/teamsmith/scripts/lib/cmd-reply.sh +96 -0
  26. package/skills/teamsmith/scripts/lib/cmd-review.sh +188 -40
  27. package/skills/teamsmith/scripts/lib/cmd-status.sh +268 -30
  28. package/skills/teamsmith/scripts/lib/cmd-update.sh +36 -7
  29. package/skills/teamsmith/scripts/lib/cmd-watch.sh +634 -54
  30. package/skills/teamsmith/scripts/lib/common.sh +1560 -109
  31. package/skills/teamsmith/scripts/lib/gate-lock.sh +544 -0
  32. package/skills/teamsmith/scripts/monitor.mjs +34 -3
  33. package/skills/teamsmith/scripts/panel/README.md +22 -11
  34. package/skills/teamsmith/scripts/panel/draft-send.sh +11 -1
  35. package/skills/teamsmith/scripts/panel/panel.js +226 -224
  36. package/skills/teamsmith/scripts/panel/src/App.tsx +478 -184
  37. package/skills/teamsmith/scripts/panel/src/clipboard.ts +11 -5
  38. package/skills/teamsmith/scripts/panel/src/compose.ts +6 -3
  39. package/skills/teamsmith/scripts/panel/src/data.ts +95 -7
  40. package/skills/teamsmith/scripts/panel/src/layout.ts +703 -152
  41. package/skills/teamsmith/scripts/panel/src/main.tsx +129 -19
  42. package/skills/teamsmith/scripts/panel/src/settings.ts +1 -1
  43. package/skills/teamsmith/scripts/panel/src/strings/en.ts +76 -31
  44. package/skills/teamsmith/scripts/panel/src/strings/zh.ts +78 -33
  45. package/skills/teamsmith/scripts/panel/src/types.ts +204 -17
  46. package/skills/teamsmith/scripts/replies.mjs +896 -0
  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 +20 -6
  52. package/skills/teamsmith/templates/AGENTS.section.md.tmpl +23 -3
  53. package/skills/teamsmith/templates/BOARD.md.tmpl +2 -2
  54. package/skills/teamsmith/templates/OWNERSHIP.md.tmpl +7 -3
  55. package/skills/teamsmith/templates/PROTOCOL.md.tmpl +17 -0
  56. package/skills/teamsmith/templates/config.sh.tmpl +29 -5
  57. package/skills/teamsmith/templates/memory-seed.md.tmpl +3 -0
  58. package/skills/teamsmith/templates/pm-prompt.md.tmpl +41 -1
  59. package/skills/teamsmith/templates/report.md.tmpl +12 -0
  60. package/skills/teamsmith/templates/task.md.tmpl +4 -0
  61. package/skills/teamsmith/tests/bg-ledger-harness.mjs +464 -40
  62. package/skills/teamsmith/tests/bg-ledger.sh +168 -10
  63. package/skills/teamsmith/tests/checkout-shape-probe.sh +3 -1
  64. package/skills/teamsmith/tests/config-cli.sh +320 -300
  65. package/skills/teamsmith/tests/death-cause.sh +5 -2
  66. package/skills/teamsmith/tests/fixtures/delivery-truth-real/scenario.sh +7 -1
  67. package/skills/teamsmith/tests/fixtures/p287/lint-good.sh.in +3 -0
  68. package/skills/teamsmith/tests/fixtures/p287/lint-hardcoded.sh.in +3 -0
  69. package/skills/teamsmith/tests/fixtures/p287/lint-no-ns.sh.in +3 -0
  70. package/skills/teamsmith/tests/fixtures/p55/flip-p49.sh +18 -6
  71. package/skills/teamsmith/tests/flip-m33.sh +5 -3
  72. package/skills/teamsmith/tests/flip-m37.sh +4 -1
  73. package/skills/teamsmith/tests/flip-m4.3.sh +4 -1
  74. package/skills/teamsmith/tests/flip-m6.3.sh +4 -1
  75. package/skills/teamsmith/tests/flip-m6.5.sh +4 -1
  76. package/skills/teamsmith/tests/flip-m7.2.sh +4 -1
  77. package/skills/teamsmith/tests/flip-p158.sh +2 -1
  78. package/skills/teamsmith/tests/flip-p210.sh +4 -1
  79. package/skills/teamsmith/tests/flip-p217.sh +4 -1
  80. package/skills/teamsmith/tests/flip-p287-lock.sh +342 -0
  81. package/skills/teamsmith/tests/flip-p287-name.sh +279 -0
  82. package/skills/teamsmith/tests/flip-p304-read-side.sh +98 -0
  83. package/skills/teamsmith/tests/flip-p308-skip-not-pass.sh +151 -0
  84. package/skills/teamsmith/tests/flip-p309-p162-deep.sh +122 -0
  85. package/skills/teamsmith/tests/flip-p310-lock.sh +216 -0
  86. package/skills/teamsmith/tests/flip-p310-socket.sh +125 -0
  87. package/skills/teamsmith/tests/help-surface.sh +1664 -0
  88. package/skills/teamsmith/tests/install-shape.sh +283 -22
  89. package/skills/teamsmith/tests/key-replies-pty.sh +374 -0
  90. package/skills/teamsmith/tests/key-replies-ui.sh +325 -0
  91. package/skills/teamsmith/tests/key-replies.sh +1314 -0
  92. package/skills/teamsmith/tests/ledger-ban.sh +9 -8
  93. package/skills/teamsmith/tests/ledger-claim.sh +248 -0
  94. package/skills/teamsmith/tests/lib/bounded-spin.sh +90 -0
  95. package/skills/teamsmith/tests/lib/model-policy.sh +30 -0
  96. package/skills/teamsmith/tests/lib/model-routing-boundary.sh +420 -0
  97. package/skills/teamsmith/tests/lib/model-routing-expansion.sh +155 -0
  98. package/skills/teamsmith/tests/lib/model-routing-flips.py +187 -0
  99. package/skills/teamsmith/tests/lib/model-routing-roles.sh +250 -0
  100. package/skills/teamsmith/tests/lib/proc-io.sh +103 -0
  101. package/skills/teamsmith/tests/lib/reply-fixture.sh +367 -0
  102. package/skills/teamsmith/tests/lib/section-guard.sh +258 -13
  103. package/skills/teamsmith/tests/lib/tmp-root.sh +139 -27
  104. package/skills/teamsmith/tests/lib/tmux-cap.sh +10 -1
  105. package/skills/teamsmith/tests/lib/tmux-iso.sh +39 -13
  106. package/skills/teamsmith/tests/loop-inventory.tsv +59 -47
  107. package/skills/teamsmith/tests/panel-b2.sh +107 -4
  108. package/skills/teamsmith/tests/panel-b3-stub.sh +139 -4
  109. package/skills/teamsmith/tests/panel-b3.sh +189 -29
  110. package/skills/teamsmith/tests/panel-choices.sh +81 -63
  111. package/skills/teamsmith/tests/panel-cpu.sh +3 -2
  112. package/skills/teamsmith/tests/panel-knobs.sh +7 -1
  113. package/skills/teamsmith/tests/panel-p21.sh +445 -241
  114. package/skills/teamsmith/tests/panel-snapshots.sh +41 -225
  115. package/skills/teamsmith/tests/panel-strings.mjs +33 -18
  116. package/skills/teamsmith/tests/perf.sh +122 -31
  117. package/skills/teamsmith/tests/pm-box-real.sh +1 -1
  118. package/skills/teamsmith/tests/pulse-nudge-key.sh +1 -1
  119. package/skills/teamsmith/tests/routes.sh +364 -109
  120. package/skills/teamsmith/tests/seat-interrupt.sh +1002 -0
  121. package/skills/teamsmith/tests/seat-visibility.sh +675 -0
  122. package/skills/teamsmith/tests/section-budgets.tsv +26 -12
  123. package/skills/teamsmith/tests/section-guard.sh +6 -1
  124. package/skills/teamsmith/tests/section-needs-audit.sh +24 -7
  125. package/skills/teamsmith/tests/section-paths.tsv +42 -26
  126. package/skills/teamsmith/tests/section-select.sh +90 -7
  127. package/skills/teamsmith/tests/slash-team-e2e.sh +323 -0
  128. package/skills/teamsmith/tests/slash-team.sh +617 -0
  129. package/skills/teamsmith/tests/smoke.sh +3762 -628
  130. package/skills/teamsmith/tests/snapshots/zh-dark-120-detail.txt +2 -2
  131. package/skills/teamsmith/tests/snapshots/zh-dark-120-p4.txt +2 -2
  132. package/skills/teamsmith/tests/snapshots/zh-dark-120.txt +9 -9
  133. package/skills/teamsmith/tests/snapshots/zh-dark-160-p4.txt +2 -2
  134. package/skills/teamsmith/tests/snapshots/zh-dark-160.txt +9 -9
  135. package/skills/teamsmith/tests/snapshots/zh-dark-59-detail.txt +1 -1
  136. package/skills/teamsmith/tests/snapshots/zh-dark-59-p4.txt +1 -1
  137. package/skills/teamsmith/tests/snapshots/zh-dark-59.txt +5 -5
  138. package/skills/teamsmith/tests/snapshots/zh-dark-99-p4.txt +2 -2
  139. package/skills/teamsmith/tests/snapshots/zh-dark-99.txt +5 -5
  140. package/skills/teamsmith/tests/snapshots/zh-light-120-detail.txt +2 -2
  141. package/skills/teamsmith/tests/snapshots/zh-light-120-p4.txt +2 -2
  142. package/skills/teamsmith/tests/snapshots/zh-light-120.txt +9 -9
  143. package/skills/teamsmith/tests/snapshots/zh-light-160-p4.txt +2 -2
  144. package/skills/teamsmith/tests/snapshots/zh-light-160.txt +9 -9
  145. package/skills/teamsmith/tests/snapshots/zh-light-59-detail.txt +1 -1
  146. package/skills/teamsmith/tests/snapshots/zh-light-59-p4.txt +1 -1
  147. package/skills/teamsmith/tests/snapshots/zh-light-59.txt +5 -5
  148. package/skills/teamsmith/tests/snapshots/zh-light-99-p4.txt +2 -2
  149. package/skills/teamsmith/tests/snapshots/zh-light-99.txt +5 -5
  150. package/skills/teamsmith/tests/task-header-model.sh +2 -1
  151. package/skills/teamsmith/tests/task-model-routing.sh +1511 -0
  152. package/skills/teamsmith/tests/tmp-hygiene.sh +782 -45
  153. package/skills/teamsmith/tests/tmux-identity-leak.sh +773 -0
  154. package/skills/teamsmith/tests/tmux-lint-legacy.txt +12 -18
  155. package/skills/teamsmith/tests/upgrade-recipe.sh +537 -0
  156. package/skills/teamsmith-init/SKILL.md +43 -43
  157. package/skills/teamsmith-init/references/bootstrap.md +8 -6
  158. package/skills/teamsmith-init/templates/bootstrap-prompt.md.tmpl +9 -5
@@ -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,17 @@ 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). Deriving it here again would be a second
93
+ * implementation of the resolution order (`process.env.TMPDIR || tmpdir()` was exactly that), and
94
+ * two answers is how the paste file ends up outside the root `--status`/`--sweep` judge.
95
+ */
96
+ export function pasteFilePath(mime: string, dir: string | undefined, uuid?: string): string | null {
91
97
  const ext = imageExt(mime)
92
- if (!ext) return null
98
+ if (!ext || !dir) return null
93
99
  return join(dir, `teamsmith-paste-${uuid ?? randomUUID()}.${ext}`)
94
100
  }
95
101
 
@@ -97,7 +103,7 @@ export function pasteFilePath(mime: string, dir = process.env.TMPDIR || tmpdir()
97
103
  * Write the clipboard image bytes to the temporary path and return it. The panel never deletes the
98
104
  * file (the requirement) and the path is the whole edit the console makes.
99
105
  */
100
- export function writePasteFile(bytes: Buffer, mime: string, dir?: string, uuid?: string): string | null {
106
+ export function writePasteFile(bytes: Buffer, mime: string, dir: string | undefined, uuid?: string): string | null {
101
107
  const file = pasteFilePath(mime, dir, uuid)
102
108
  if (!file) return null
103
109
  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_*`.
@@ -77,6 +77,13 @@ export const BLOCK_NAMES = [
77
77
  // P22/B2: the project-settings view's on-demand reader (`team config list --json`). Same rule:
78
78
  // never wanted unless the view is open.
79
79
  'settings',
80
+ // pulse-key-replies: the three console-only reply readers over the bounded helper. The summary is
81
+ // the one scheduled everywhere (the overview renders it); the list is wanted only on page 5 and
82
+ // the body only while the reply viewer is open (`opts.replyBefore` / `opts.replyNo`), so a parked
83
+ // console spawns no list/body child at all.
84
+ 'reply_summary',
85
+ 'reply_list',
86
+ 'reply_body',
80
87
  ] as const
81
88
  export type BlockName = (typeof BLOCK_NAMES)[number]
82
89
 
@@ -113,10 +120,22 @@ export interface DataOptions {
113
120
  blocks?: readonly BlockName[]
114
121
  /** The detail view's entry id; while set, `detail` joins the wanted set (null/absent = parked). */
115
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
116
129
  /** True while the project-settings view is open; only then does `settings` join the wanted set. */
117
130
  settingsOpen?: boolean
118
131
  /** The detail file to serve with `--file` (must be one of the discovered paths). */
119
132
  detailFile?: string | null
133
+ /** True while page 5's list is the surface in view (the demand flag, beside the cursor). */
134
+ replyListOpen?: boolean
135
+ /** Page 5's list cursor (`--before <no>`); null/absent = the newest page. */
136
+ replyBefore?: number | null
137
+ /** The open reply viewer's number (`--no <no>`); null/absent = the viewer is closed. */
138
+ replyNo?: number | null
120
139
  }
121
140
 
122
141
  export interface DataResult {
@@ -174,20 +193,38 @@ const BLOCK_SPECS: Record<BlockName, BlockSpec> = {
174
193
  patrol: { ttlMs: 15000, timeoutMs: 10000 },
175
194
  health: { ttlMs: 600000, timeoutMs: 30000 },
176
195
  // The detail reader rides the open view: the App forces it on open and on a tab switch, so its TTL
177
- // only covers a stale refresh while the view stays open. The `--id`/`--file` arguments come from
178
- // the live options; both are cleared when the view closes.
196
+ // only covers a stale refresh while the view stays open. The `--id`/`--source`/`--file` arguments
197
+ // come from the live options; all are cleared when the view closes. The `entry` source stays
198
+ // implicit so an existing caller's argv is byte-identical.
179
199
  detail: {
180
200
  ttlMs: 15000,
181
201
  timeoutMs: 10000,
182
202
  extraArgs: (opts) => {
183
203
  if (!opts.detailId) return []
184
204
  const args = ['--id', String(opts.detailId)]
205
+ if (opts.detailSource && opts.detailSource !== 'entry') args.push('--source', opts.detailSource)
185
206
  if (opts.detailFile) args.push('--file', String(opts.detailFile))
186
207
  return args
187
208
  },
188
209
  },
189
210
  // The project-settings reader rides the open view exactly like `detail` (P22/B2).
190
211
  settings: { ttlMs: 15000, timeoutMs: 10000 },
212
+ // Key replies (pulse-key-replies). The summary refreshes on the background cadence; the list is
213
+ // a demand read whose TTL only covers a re-render (its request key changes with the cursor and
214
+ // clears the cached value); the body is requested once per open number and only while the viewer
215
+ // is up. Budgets (design §4): summary 16 KiB / list 512 KiB / body 1 MiB of child stdout — the
216
+ // output cap below is the 32 MiB frame-wide backstop, the readers' own caps are the real bound.
217
+ reply_summary: { ttlMs: 15000, timeoutMs: 10000 },
218
+ reply_list: {
219
+ ttlMs: 15000,
220
+ timeoutMs: 10000,
221
+ extraArgs: (opts) => (opts.replyBefore ? ['--before', String(opts.replyBefore)] : []),
222
+ },
223
+ reply_body: {
224
+ ttlMs: 15000,
225
+ timeoutMs: 10000,
226
+ extraArgs: (opts) => (opts.replyNo ? ['--no', String(opts.replyNo)] : []),
227
+ },
191
228
  }
192
229
 
193
230
 
@@ -221,6 +258,7 @@ function runBlock(
221
258
  opts: DataOptions,
222
259
  cli: string,
223
260
  children?: Set<ReturnType<typeof spawn>>,
261
+ onChild?: (child: ReturnType<typeof spawn>) => void,
224
262
  ): Promise<BlockOutcome> {
225
263
  const timeoutMs = opts.timeoutMs ?? spec.timeoutMs
226
264
  const extra = spec.extraArgs ? spec.extraArgs(opts) : []
@@ -230,6 +268,7 @@ function runBlock(
230
268
  try {
231
269
  child = spawn('bash', args, { cwd: opts.root, env: cleanIdentityEnv(), stdio: ['ignore', 'pipe', 'pipe'] })
232
270
  children?.add(child)
271
+ onChild?.(child)
233
272
  } catch (e) {
234
273
  resolve({ ok: false, error: (e as Error).message })
235
274
  return
@@ -344,6 +383,8 @@ interface BlockState {
344
383
  /** Epoch ms of the last successful build (0 = never). */
345
384
  at: number
346
385
  error?: string
386
+ /** The request key the cached value was built for (`reply_list` cursor / `reply_body` number). */
387
+ key?: string
347
388
  }
348
389
 
349
390
  const PANEL_BLOCK_NAMES: readonly BlockName[] = [
@@ -357,6 +398,9 @@ const PANEL_BLOCK_NAMES: readonly BlockName[] = [
357
398
  'health',
358
399
  'detail',
359
400
  'settings',
401
+ 'reply_summary',
402
+ 'reply_list',
403
+ 'reply_body',
360
404
  ]
361
405
 
362
406
  function isPanelBlock(name: BlockName): boolean {
@@ -388,8 +432,29 @@ export function createPanelCache(opts: DataOptions): PanelCache {
388
432
  const live = new Set<BlockName>()
389
433
  if (opts.detailId) live.add('detail')
390
434
  if (opts.settingsOpen) live.add('settings')
391
- return BLOCK_NAMES.filter((name) => (name === 'detail' || name === 'settings' ? live.has(name) : true))
435
+ if (opts.replyListOpen) live.add('reply_list')
436
+ if (opts.replyNo) live.add('reply_body')
437
+ const demand = new Set<BlockName>(['detail', 'settings', 'reply_list', 'reply_body'])
438
+ return BLOCK_NAMES.filter((name) => (demand.has(name) ? live.has(name) : true))
392
439
  }
440
+
441
+ /**
442
+ * The **request key** of one block (`reply_list` = its cursor, `reply_body` = its number).
443
+ * Changing it clears the cached value and the error, cancels the child still in flight and makes
444
+ * any late response for the old key a no-op: a late page or body must never replace the selection
445
+ * the user is looking at (design §4).
446
+ */
447
+ const requestKey = (name: BlockName): string => {
448
+ switch (name) {
449
+ case 'reply_list':
450
+ return `open:${opts.replyListOpen ? 1 : 0}:before:${opts.replyBefore ?? 'newest'}`
451
+ case 'reply_body':
452
+ return `no:${opts.replyNo ?? 'none'}`
453
+ default:
454
+ return ''
455
+ }
456
+ }
457
+ const blockChildren: Partial<Record<BlockName, ReturnType<typeof spawn>>> = {}
393
458
  const state: Record<string, BlockState> = {}
394
459
  for (const name of BLOCK_NAMES) state[name] = { at: 0 }
395
460
  let inFlight: Partial<Record<BlockName, Promise<void>>> = {}
@@ -427,9 +492,12 @@ export function createPanelCache(opts: DataOptions): PanelCache {
427
492
  return { ok: true, data, activity, blocks, degraded, errors }
428
493
  }
429
494
 
430
- function build(name: BlockName): Promise<void> {
431
- return runBlock(BLOCK_SPECS[name], name, opts, cli as string, children).then((outcome) => {
495
+ function build(name: BlockName, key: string): Promise<void> {
496
+ return runBlock(BLOCK_SPECS[name], name, opts, cli as string, children, (child) => {
497
+ blockChildren[name] = child
498
+ }).then((outcome) => {
432
499
  const s = state[name]
500
+ if (requestKey(name) !== key) return // a late response for a superseded request is dropped
433
501
  if (outcome.ok) {
434
502
  s.value = outcome.value
435
503
  s.at = Date.now()
@@ -451,11 +519,31 @@ export function createPanelCache(opts: DataOptions): PanelCache {
451
519
  if (!wanted.includes(name)) continue
452
520
  if (only && !only.has(name)) continue
453
521
  const s = state[name]
522
+ const key = requestKey(name)
523
+ if (key !== s.key) {
524
+ // The request key changed (page 5's cursor, the viewer's number): the cached value belongs
525
+ // to the old key, the child that is still running does too — kill it, drop the cache and
526
+ // rebuild against the new selection.
527
+ const old = blockChildren[name]
528
+ if (old) {
529
+ try {
530
+ old.kill('SIGKILL')
531
+ } catch {
532
+ /* already gone */
533
+ }
534
+ delete blockChildren[name]
535
+ }
536
+ s.key = key
537
+ s.value = undefined
538
+ s.at = 0
539
+ s.error = undefined
540
+ }
454
541
  const due = refreshOpts.force || s.at === 0 || now - s.at >= BLOCK_SPECS[name].ttlMs
455
542
  if (!due) continue
456
543
  if (inFlight[name]) continue
457
- inFlight[name] = build(name).finally(() => {
544
+ inFlight[name] = build(name, key).finally(() => {
458
545
  delete inFlight[name]
546
+ delete blockChildren[name]
459
547
  })
460
548
  }
461
549
  // Already-running builds count as this refresh's work: the caller wants a settled snapshot.