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
@@ -19,6 +19,27 @@ its line. Commands keep the bare code (`team close M12`) -- there it is a key, n
19
19
  `team digest` / `team status` / `team roster` already render the name next to the code; use the same shape in your
20
20
  own messages. Prefer the BOARD's task column as the name (that is the shared short name), not a fresh description.
21
21
 
22
+ **Answer the reader's question first, and keep only the sentences that carry their evidence.** Lead with the
23
+ conclusion and the next step; how you got there comes after. A caution, a limitation or a warning stays only when
24
+ it names something checkable — a measurement, a counterexample, a gap in the reasoning, a boundary you did not
25
+ observe; when the evidence no longer supports a claim, say what it does support rather than narrowing the claim,
26
+ and never delete a boundary sentence that carries its fact. Every finding states what it changed — the
27
+ implementation, the next step, the conclusion, or nothing; an observation that changes nothing is not part of the
28
+ answer. Delete what names nothing checkable: what stays is what the reader can verify. See
29
+ `{{SKILL_DIR}}/references/protocol.md` §11b.
30
+
31
+ **Key conclusions: replies written for the user go to the reply page first.** The reader decides what gets
32
+ published -- a landed milestone, an answer to a question, a status or progress report, a conclusion or a ruling, a
33
+ decision you ask the user for, a delivery or verification summary, and any other reply written for the user; a
34
+ short reply is published just like a long one, and a reply is never held back because it reads like process
35
+ rather than like a conclusion. Publish the complete reply -- the substance the user needs to read, not a
36
+ play-by-play of the work -- with
37
+ `team reply post --from pm --title '<short title>' --stdin < <file>`, then send that same body in the conversation.
38
+ Replies written to the patrol, to another seat, to another project's PM and tool receipts are not for the user and
39
+ stay out of the page. When it is not obvious, ask **who is this reply written for?**; if it cannot be settled, treat
40
+ the reply as written for the user. A batch of user-facing replies may be one reply. See
41
+ `{{SKILL_DIR}}/references/protocol.md` §4b.
42
+
22
43
  ## First moves (on every start / whenever the pulse raises you)
23
44
 
24
45
  ```bash
@@ -0,0 +1,31 @@
1
+ # `tests/` — 谁能判门禁,谁只是人工工具
2
+
3
+ 这个目录里有两类东西,**外观一样,性质不同**。混起来读会把「有文件」当成「有守卫」。
4
+
5
+ - **门禁夹具**:被 `smoke.sh` 的某个段、CI 步或另一个有根的夹具调用。它们每轮都跑,坏了当场红。
6
+ 一个夹具算不算这一类,只认一件事:**有没有执行点**(`section-select.sh --paths` 能给出段号,或
7
+ `smoke.sh` / `workflow-entry.sh` / 另一个有根的夹具里有一处真正的调用)。
8
+ - **人工工具**:下面这五个。**它们不在任何门禁段里**(任何段都不调用、CI 也不调用),是发布前或
9
+ 排障时**人**跑的取证/审计工具。跑绿了不代表门禁绿,跑红了也不拦合并——它值钱的地方在于它**自己**
10
+ 带红侧(把实现/现场弄坏,它必须变红),所以它的结论是一次性证据,不是长期守卫。
11
+
12
+ 判据来由:D201(「不粘锅」代码)与 P353 的普查——19 个夹具当时没有任何执行路径,其中 7 个在修复进
13
+ `main` 之后连「一次性证据」都产不出了。P354 按 PM 裁定删掉 13 个(墓碑在 `docs/team/DECISIONS.md`
14
+ 的同日条),只留下下面五个**可重跑、且守的东西确实贵**的。加新夹具时请顺手回答一句:它的执行点是哪
15
+ 一段?没有执行点、又不是人工工具的,就不该进这个目录。
16
+
17
+ ## 人工验收工具(发布前 / 排障时跑)
18
+
19
+ | 命令 | 守什么(点名事故或契约面) | 成本与前提 |
20
+ |---|---|---|
21
+ | `bash skills/teamsmith/tests/flip-m33.sh` | bg6(2026-09-18)场景目录 `$TMP` 在门禁跑动中被外部删掉 → 半红半绿、没有一条红说得清。它证明 `smoke.sh` **前导**里的哨兵(每轮都跑)**真的会咬人**:一条点名红 + 停跑(exit 2)+ `$TMP` 之外的诊断。 | 默认跑本树的**一遍 FAST smoke**(外加可选的 pre 树腿);`--break-sentinel` 是反向腿(哨兵弄瞎 → 期望必须不成立)。 |
22
+ | `bash skills/teamsmith/tests/flip-m44.sh` | M44(2026-09-19)PM 用 `add -A` 把 `merge --squash` 的冲突三件套提交进被保护分支,而当时的门禁没有任何一条断言能拦。它用九个现场(真事故 / 解掉冲突 / 未跟踪不算 / 索引侧 / 三条变异)证 §0d 的判据(不是抄一份,是同一份前导 + §0d)。 | 九条腿,约 2 分钟;不需要 tmux。 |
23
+ | `bash skills/teamsmith/tests/flip-p308-skip-not-pass.sh` | V48 F1′:`tmux-identity-leak.sh` 的收口按「PASS==0 && FAIL==0」判,于是「tmux 坏了、七段全跳过」拿到 rc=0(跳过被当成通过)。它用四条腿证收口已改按段数判(red-now / 旧判据 rc=0 的对照 / 合法单跑 / 正常环境)。 | 需要真 tmux;`green-normal` 测不了时退出码是 **77**(脚本自己也守「跳过不是通过」),不是绿。 |
24
+ | `bash skills/teamsmith/tests/section-needs-audit.sh` | P112 §5.2 的 needs 缺口(`--paths` 的结论是若干键的并集,一个键缺前提会被别的键的绿遮住),P297 实测 FAST 绿、真跑 ✗9。逐键跑 `smoke.sh --select K`,断言 K 自己的段真的跑了且 ✗0。 | **贵**:默认每个键一遍 smoke,整表以小时计。收窄用 `--keys k1,k2`;验真进程前提用 `--live`(默认 FAST 会跳过真 pane 半段)。必须顺序跑。 |
25
+ | `bash skills/teamsmith/tests/lib/tmp-root.sh --self-test` | 临时根创建者的契约:`TMPDIR` / 归属 / 回收 / 嵌套各自记账 / 不 export、不改 shell 选项。`--break=<stage>` 把某条规则变回旧行为,守门断言必须变红(翻转腿)。 | 纯逻辑,快。部分拷贝的夹具要显式给 `TEAM_TMP_SKILL_DIR` 指回真 `scripts/lib/common.sh`(解析器只有一处实现)。 |
26
+
27
+ ## 已知缺口(不要误以为有人在守)
28
+
29
+ `panel-keyprobe.sh`(刷新期间敲键不丢、草稿逐字到达)在 P354 里删掉了,**这条契约今天没有活守门人**:
30
+ §27 只守块协议,§28 只覆盖 headless 半边。面板 pty 面接进门禁(P349)时,这个场景要在那里补上;在那
31
+ 之前,它属于「没人跑、也没人替」的格子,写在这里是为了不让下一个读目录的人把它当成已覆盖。
@@ -17,7 +17,7 @@
17
17
  * 输出:每个用例一行 `BG-CASE PASS|FAIL <name> [:: detail]`;任一 FAIL → 退出码 1。
18
18
  */
19
19
  import { execFileSync, spawn } from 'node:child_process'
20
- import { existsSync, mkdirSync, readFileSync, rmSync, symlinkSync, writeFileSync } from 'node:fs'
20
+ import { existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, rmSync, symlinkSync, writeFileSync } from 'node:fs'
21
21
  import { dirname, join, resolve } from 'node:path'
22
22
 
23
23
  // ── 参数与身份隔离 ─────────────────────────────────────────────────────────────
@@ -39,8 +39,8 @@ if (!ROOT || !existsSync(join(ROOT, '.pi/team/config.sh'))) {
39
39
  console.error('bg-ledger-harness: --root <夹具仓库> 是必需的(它必须带 .pi/team/config.sh)')
40
40
  process.exit(2)
41
41
  }
42
- if ((GROUPS.has('suspend-shape') || GROUPS.has('owner-scope')) && NOTIFY === '-') {
43
- console.error('bg-ledger-harness: suspend-shape / owner-scope 需要 --notify <extension/team-notify.ts>')
42
+ if ((GROUPS.has('suspend-shape') || GROUPS.has('owner-scope') || GROUPS.has('merge') || GROUPS.has('detail') || GROUPS.has('wake')) && NOTIFY === '-') {
43
+ console.error('bg-ledger-harness: suspend-shape / owner-scope / merge / detail / wake 需要 --notify <extension/team-notify.ts>')
44
44
  process.exit(2)
45
45
  }
46
46
  for (const key of Object.keys(process.env)) {
@@ -130,7 +130,7 @@ const makeBase = (name, { ownConfigInWorktree = false, seats = ['dev'] } = {}) =
130
130
  mkdirSync(join(base, 'docs/team/inbox'), { recursive: true })
131
131
  writeFileSync(join(base, '.pi/team/config.sh'),
132
132
  `TEAM_PROJECT="bg-ledger-${name}"\nTEAM_AGENTS="${seats.join(' ')}"\nTEAM_WORKTREES_DIR=".worktrees"\n` +
133
- `TEAM_NOTIFY_LOG="${base}/.pi/team/state/notify.log"\n`)
133
+ `TEAM_NOTIFY_LOG="${base}/.pi/team/state/notify-ext.log"\n`)
134
134
  writeFileSync(join(base, 'README.md'), `# bg-ledger fixture ${name}\n`)
135
135
  git(['init', '-q', '-b', 'main'], base)
136
136
  git(['add', 'README.md'], base)
@@ -221,42 +221,8 @@ const groupWording = async () => {
221
221
  'team_bg_run.start-result': receipt.text,
222
222
  'team_bg_wait.description': String(host.tools.team_bg_wait?.description ?? ''),
223
223
  }
224
- const hasDefault = t => /end your turn/i.test(t) && /completion wake-up/i.test(t) && /normal harvest point/i.test(t)
225
- const hasBudget = t => /inline-wait budget/i.test(t) && /2 minutes/.test(t)
226
- const hasBlocked = t => /blocks your immediate next step/i.test(t)
227
- const hasExclusive = t => /no other task work/i.test(t)
228
- const hasException = t => /bounded exception/i.test(t) && hasBudget(t) && hasBlocked(t) && hasExclusive(t)
229
-
230
- check('wording: team_bg_run description presents the suspend default',
231
- hasDefault(texts['team_bg_run.description']), texts['team_bg_run.description'].slice(0, 90))
232
- check('wording: team_bg_run prompt snippet presents the suspend default',
233
- hasDefault(texts['team_bg_run.promptSnippet']), texts['team_bg_run.promptSnippet'].slice(0, 90))
234
- check('wording: team_bg_run guidelines present the suspend default and the bounded exception',
235
- hasDefault(texts['team_bg_run.promptGuidelines']) && hasException(texts['team_bg_run.promptGuidelines']),
236
- texts['team_bg_run.promptGuidelines'].slice(0, 120))
237
- check('wording: the start result presents the suspend default and the bounded exception',
238
- hasDefault(texts['team_bg_run.start-result']) && hasException(texts['team_bg_run.start-result']),
239
- texts['team_bg_run.start-result'].split('\n').at(-1)?.slice(0, 120) ?? '')
240
- check('wording: team_bg_wait description names the three exception conditions and the budget',
241
- hasDefault(texts['team_bg_wait.description']) && hasException(texts['team_bg_wait.description']),
242
- texts['team_bg_wait.description'].slice(0, 120))
243
-
244
- // 旧措辞零命中:两个被点名的退休句 + 更宽的「回合结束前必须收割」与「叫醒=损失」形状。
245
- const retired = [
246
- 'Harvest it with team_bg_wait before you end your turn',
247
- 'harvest every job with team_bg_wait before ending your turn',
248
- 'before you end your turn',
249
- 'before ending your turn',
250
- 'must not end with unharvested',
251
- 'costs a turn',
252
- ]
253
- const offenders = []
254
- for (const [name, text] of Object.entries(texts)) {
255
- for (const phrase of retired) if (text.includes(phrase)) offenders.push(`${name} :: ${phrase}`)
256
- if (/\b(cost|penalt|loss|waste)/i.test(text)) offenders.push(`${name} :: loss framing`)
257
- }
258
- check('wording: the retired duty wording is gone from every registered text',
259
- offenders.length === 0, offenders.join(' | ') || 'clean')
224
+
225
+
260
226
 
261
227
  // 完成叫醒:多条合并成一条、点名每个 id、指 team_bg_wait(既有行为,钉住)。
262
228
  // 先把回执作业收割掉(否则它会带着自己的叫醒混进下面那条合并消息的窗口)。
@@ -668,6 +634,461 @@ const groupOwnerScope = async () => {
668
634
  await bgHost.emit('session_shutdown', { reason: 'fixture' }, { cwd: ROOT })
669
635
  }
670
636
 
637
+ // ── turn-notice-merge(merge / detail / wake):写入侧合并 + 明细 + 叫醒 ──────────────
638
+ // 夹具驱动**真扩展 + 真 CLI**:扩展调 CLI 的 __inbox-write(per-recipient 锁 + 先明细后合并),
639
+ // harness 读收件箱 / state/notify.log / outbox 断言合同。CLI 路径从 --notify 派生:
640
+ // <notify 的父目录>/../scripts/team —— 所以变异树($MUT/<tag>/{extension,scripts})能同时破坏扩展
641
+ // 与 CLI,而不会因为 skillDir() 找不到 CLI 变成假红。
642
+ const CLI = () => {
643
+ const explicit = opt('cli')
644
+ return explicit ? resolve(explicit) : resolve(dirname(NOTIFY), '..', 'scripts', 'team')
645
+ }
646
+ const runCliRaw = (base, args) => execFileSync('bash', [CLI(), '--root', base, ...args], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] })
647
+ const runCliRc = (base, args) => {
648
+ try { return { rc: 0, out: runCliRaw(base, args) } }
649
+ catch (error) { return { rc: typeof error?.status === 'number' ? error.status : 1, out: `${error?.stdout ?? ''}${error?.stderr ?? ''}` } }
650
+ }
651
+ const inboxAll = (base, agent = 'dev') => {
652
+ const f = join(base, 'docs/team/inbox', `${agent}.md`)
653
+ return existsSync(f) && !lstatSync(f).isDirectory() ? readFileSync(f, 'utf8').split('\n').filter(Boolean) : []
654
+ }
655
+ const detailFileOf = base => join(base, '.pi/team/state/notify.log')
656
+ const detailRaw = base => {
657
+ const f = detailFileOf(base)
658
+ return existsSync(f) && !lstatSync(f).isDirectory() ? readFileSync(f, 'utf8') : ''
659
+ }
660
+ const detailEventCount = text => text.split('\n').filter(l => l.startsWith('- ')).length
661
+ const detailRecs = base => detailRaw(base).split('\n').filter(l => l.startsWith('- '))
662
+ const configAdd = (base, line) => writeFileSync(join(base, '.pi/team/config.sh'), `${line}\n`, { flag: 'a' })
663
+ const extLogOf = base => {
664
+ const f = join(base, '.pi/team/state/notify-ext.log')
665
+ return existsSync(f) && !lstatSync(f).isDirectory() ? readFileSync(f, 'utf8') : ''
666
+ }
667
+ const taskProof = (base, agent, id) => writeFileSync(join(base, '.pi/team/state', `${agent}.env`), `task=${id}\n`)
668
+ const liveRecord = (base, id, cwd) => {
669
+ const child = spawnSleep(30)
670
+ writeRecord(join(base, '.pi/team/state', 'bg'), id, { pid: child.pid, pgid: child.pid, start: procStartTime(child.pid), cwd })
671
+ return child.pid
672
+ }
673
+ const dropRecord = (base, id) => rmSync(join(base, '.pi/team/state', 'bg', `${id}.job`), { force: true })
674
+ const killPid = pid => { try { process.kill(pid, 'SIGKILL') } catch { /* 已经不在了 */ } }
675
+ const tipOfLine = text => /tip=([0-9a-f]+)/.exec(text)?.[1] ?? ''
676
+ const isoOfLine = text => /^- (\S+) /.exec(text)?.[1] ?? ''
677
+ // 敲门的可观察面:① 还在 outbox 里的条目(含 held/);② delivered.log(投递成功后会移出目录)。
678
+ // 只数 knock 的**行身份**(dedup 以 `line|` 开头)的条目 —— 旧键(摘要指纹)在这里则不会被数到。
679
+ const knockEntries = base => {
680
+ const dir = join(base, '.pi/team/state/outbox')
681
+ let n = 0
682
+ const log = join(dir, 'delivered.log')
683
+ if (existsSync(log)) for (const line of readFileSync(log, 'utf8').split('\n')) {
684
+ const f = line.split('\t')
685
+ if ((f[1] ?? '').startsWith('line|')) n++
686
+ }
687
+ const scan = d => {
688
+ if (!existsSync(d)) return
689
+ for (const f of readdirSync(d)) {
690
+ const p = join(d, f)
691
+ let st
692
+ try { st = lstatSync(p) } catch { continue }
693
+ if (st.isDirectory()) { if (f !== 'diagnostics') scan(p); continue }
694
+ if (!f.endsWith('.msg')) continue
695
+ try { if (/^dedup: line\|/m.test(readFileSync(p, 'utf8'))) n++ } catch { /* ignore */ }
696
+ }
697
+ }
698
+ scan(dir)
699
+ return n
700
+ }
701
+ const inboxNewCount = (base, agent = 'dev') => Number(/新 (\d+) 条/.exec(runCliRaw(base, ['inbox', agent]))?.[1] ?? 0)
702
+
703
+ // ── merge:合并键 / 合并行形状 / 尾行锚 / 既有读者 ─────────────────────────────
704
+ const groupMerge = async () => {
705
+ const notify = await newNotify()
706
+
707
+ // ① 首条事件的行逐字节形状不变;同 run 三条 → 一行 ×3 + 明细三条(首末时间点名首末事件)
708
+ {
709
+ const b = makeBase('merge-run')
710
+ taskProof(b.base, 'dev', 'P230')
711
+ resetNotify(b.base)
712
+ await notify.settle(b.wt, 'stop', 'MERGE-RUN first summary')
713
+ const l1 = inboxAll(b.base)[0] ?? ''
714
+ const shape = new RegExp('^- \\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z (⚠ 未提交 \\d+ 个文件 · )?\\[auto\\] agent:dev · P230 · branch=task/P230-merge-run · uncommitted=\\d+ · unpushed=\\d+(\\(no-upstream\\))? · task=P230 tip=[0-9a-f]{12} :: MERGE-RUN first summary$')
715
+ check('merge: a single-event line keeps today’s shape',
716
+ shape.test(l1) && !l1.includes('×') && !l1.includes('first=') && !l1.includes('last='), l1 || '(no inbox line)')
717
+ await notify.settle(b.wt, 'stop', 'MERGE-RUN second summary')
718
+ await notify.settle(b.wt, 'stop', 'MERGE-RUN third summary')
719
+ const ls = inboxAll(b.base)
720
+ const dl = detailRecs(b.base)
721
+ const line = ls[0] ?? ''
722
+ check('merge: a run of same-key notifications is one line with its window',
723
+ ls.length === 1 && /×3 first=\S+ last=\S+/.test(line) && dl.length === 3 &&
724
+ isoOfLine(line) === isoOfLine(dl[0]) && /last=(\S+)/.exec(line)?.[1] === isoOfLine(dl[2]),
725
+ `lines=${ls.length} detail=${dl.length} :: ${line}`)
726
+ check('merge: the run’s summaries stay readable in the detail file',
727
+ dl.some(r => r.includes('first summary')) && dl.some(r => r.includes('third summary')) && dl.every(r => !r.includes('×') && r.startsWith('- ')),
728
+ dl.join(' | ').slice(0, 200))
729
+ }
730
+
731
+ // ② 汇总行取**最后一条**的值(uncommitted/tip/last);取最大值、平均或第一条的值都在这里变红
732
+ {
733
+ const b = makeBase('merge-last')
734
+ taskProof(b.base, 'dev', 'P230')
735
+ resetNotify(b.base)
736
+ for (const f of ['w2.txt', 'w3.txt', 'w4.txt']) writeFileSync(join(b.wt, f), 'x\n')
737
+ await notify.settle(b.wt, 'stop', 'MERGE-LAST one')
738
+ const rec1 = detailRecs(b.base).at(-1) ?? ''
739
+ git(['add', '-A'], b.wt)
740
+ git(['-c', 'user.email=fixture@teamsmith', '-c', 'user.name=fixture', 'commit', '-qm', 'merge-last one'], b.wt)
741
+ writeFileSync(join(b.wt, 'w5.txt'), 'x\n')
742
+ await notify.settle(b.wt, 'stop', 'MERGE-LAST two')
743
+ rmSync(join(b.wt, 'w5.txt'), { force: true })
744
+ await notify.settle(b.wt, 'stop', 'MERGE-LAST three')
745
+ const rec3 = detailRecs(b.base).at(-1) ?? ''
746
+ const line = inboxAll(b.base)[0] ?? ''
747
+ const tip1 = tipOfLine(rec1); const tip3 = tipOfLine(rec3)
748
+ check('merge: the merged line carries the last event’s values',
749
+ tip1 !== '' && tip3 !== '' && tip1 !== tip3 && /uncommitted=0( |·)/.test(line) && line.includes(`tip=${tip3}`) &&
750
+ !line.includes(`tip=${tip1}`) && /last=(\S+)/.exec(line)?.[1] === isoOfLine(rec3) && line.includes('×3'),
751
+ `tip1=${tip1} tip3=${tip3} :: ${line}`)
752
+ }
753
+
754
+ // ③ 状态类变化必然新起一行(两个同 awaiting 的 suspended 不跨过 delivered 合并)
755
+ {
756
+ const b = makeBase('merge-class')
757
+ resetNotify(b.base)
758
+ const pA = liveRecord(b.base, 'J1', b.wt)
759
+ await notify.settle(b.wt, 'stop', 'MERGE-CLASS suspended one')
760
+ dropRecord(b.base, 'J1'); killPid(pA)
761
+ await notify.settle(b.wt, 'stop', 'MERGE-CLASS delivered')
762
+ const pB = liveRecord(b.base, 'J1', b.wt)
763
+ await notify.settle(b.wt, 'stop', 'MERGE-CLASS suspended two')
764
+ const ls = inboxAll(b.base)
765
+ check('merge: a state-class change starts a new line',
766
+ ls.length === 3 && ls[0].includes('[auto·suspended]') && ls[0].includes('awaiting=J1') && !ls[0].includes('×') &&
767
+ ls[1].includes('[auto] ') && !ls[1].includes('awaiting=') && !ls[1].includes('×') &&
768
+ ls[2].includes('[auto·suspended]') && ls[2].includes('awaiting=J1') && !ls[2].includes('×'),
769
+ ls.join(' || ').slice(0, 240))
770
+ // 只有类变、awaiting 集合不变:suspended → interrupted 也必须新起一行(键里的类分量单独可观测)
771
+ await notify.settle(b.wt, 'aborted', 'MERGE-CLASS interrupted same job')
772
+ const ls2 = inboxAll(b.base)
773
+ check('merge: a class change with the same awaiting set starts a new line',
774
+ ls2.length === 4 && ls2[3].includes('[auto·interrupted]') && ls2[3].includes('awaiting=J1') && !ls2[3].includes('×'),
775
+ ls2.join(' || ').slice(0, 260))
776
+ killPid(pB); dropRecord(b.base, 'J1')
777
+ }
778
+
779
+ // ④ 任务 / awaiting 集合任一变化都新起一行
780
+ {
781
+ const b = makeBase('merge-key')
782
+ taskProof(b.base, 'dev', 'P230')
783
+ resetNotify(b.base)
784
+ const p1 = liveRecord(b.base, 'X1', b.wt)
785
+ await notify.settle(b.wt, 'stop', 'MERGE-KEY awaiting one')
786
+ dropRecord(b.base, 'X1'); killPid(p1)
787
+ const p2 = liveRecord(b.base, 'X2', b.wt)
788
+ await notify.settle(b.wt, 'stop', 'MERGE-KEY awaiting two')
789
+ dropRecord(b.base, 'X2'); killPid(p2)
790
+ const p3 = liveRecord(b.base, 'X3', b.wt)
791
+ git(['checkout', '-q', '-b', 'task/P231-other'], b.wt)
792
+ await notify.settle(b.wt, 'stop', 'MERGE-KEY other task')
793
+ const ls = inboxAll(b.base)
794
+ check('merge: a different task or awaiting set starts a new line',
795
+ ls.length === 3 && ls[0].includes('awaiting=X1') && ls[1].includes('awaiting=X2') && ls[2].includes('awaiting=X3') &&
796
+ ls.every(l => !l.includes('×')), `lines=${ls.length} :: ${ls.join(' || ').slice(0, 200)}`)
797
+ killPid(p3); dropRecord(b.base, 'X3')
798
+ }
799
+
800
+ // ⑤ 跨席位:各写各的文件
801
+ {
802
+ const b = makeBase('merge-seats', { seats: ['dev', 'dev2'] })
803
+ resetNotify(b.base, 'dev'); resetNotify(b.base, 'dev2')
804
+ await notify.settle(b.wt, 'stop', 'MERGE-SEATS dev')
805
+ await notify.settle(b.wts.dev2, 'stop', 'MERGE-SEATS dev2')
806
+ const ld = inboxAll(b.base, 'dev'); const l2 = inboxAll(b.base, 'dev2')
807
+ check('merge: a different seat’s run stays in its own file',
808
+ ld.length === 1 && l2.length === 1 && ld[0].includes('agent:dev ') && !ld[0].includes('agent:dev2') && l2[0].includes('agent:dev2'),
809
+ `dev=[${ld.join('||')}] dev2=[${l2.join('||')}]`)
810
+ }
811
+
812
+ // ⑥ awaiting 是集合:夹具预置的反序锚行与扩展的排序结果必须合并
813
+ {
814
+ const b = makeBase('merge-order')
815
+ resetNotify(b.base)
816
+ const pa = liveRecord(b.base, 'aaa', b.wt); const pz = liveRecord(b.base, 'zzz', b.wt)
817
+ const branch = git(['rev-parse', '--abbrev-ref', 'HEAD'], b.wt)
818
+ writeFileSync(join(b.base, 'docs/team/inbox/dev.md'),
819
+ `- 2026-10-14T00:00:00Z [auto·suspended] agent:dev · P230 · branch=${branch} · uncommitted=1 · awaiting=zzz,aaa · unpushed=0\n`)
820
+ await notify.settle(b.wt, 'stop', 'MERGE-ORDER second settle')
821
+ const ls = inboxAll(b.base)
822
+ const line = ls[0] ?? ''
823
+ check('merge: the awaiting set’s order does not split a run',
824
+ ls.length === 1 && line.includes('×2') && line.includes('awaiting=aaa,zzz'), line)
825
+ killPid(pa); killPid(pz); dropRecord(b.base, 'aaa'); dropRecord(b.base, 'zzz')
826
+ }
827
+
828
+ // ⑦ 中间插入的手工通知结束 run,且本人逐字节不变
829
+ {
830
+ const b = makeBase('merge-break')
831
+ resetNotify(b.base)
832
+ await notify.settle(b.wt, 'stop', 'MERGE-BREAK one')
833
+ const before = inboxAll(b.base)[0] ?? ''
834
+ runCliRc(b.base, ['notify', 'dev', 'MERGE-BREAK manual notice'])
835
+ const manual = inboxAll(b.base).at(-1) ?? ''
836
+ await notify.settle(b.wt, 'stop', 'MERGE-BREAK two')
837
+ const ls = inboxAll(b.base)
838
+ check('merge: a notice appended between two events ends the run untouched',
839
+ ls.length === 3 && ls[0] === before && ls[1] === manual && ls[1].includes('[manual]') &&
840
+ ls[1].includes('MERGE-BREAK manual notice') && ls[2].includes('MERGE-BREAK two') && !ls[2].includes('×'),
841
+ ls.join(' || ').slice(0, 240))
842
+ }
843
+
844
+ // ⑧ 去重窗口内的重复 settle 既不进明细也不推 ×N
845
+ {
846
+ const b = makeBase('merge-dedup')
847
+ resetNotify(b.base)
848
+ await notify.settle(b.wt, 'stop', 'MERGE-DEDUP same text')
849
+ await notify.settle(b.wt, 'stop', 'MERGE-DEDUP same text')
850
+ const ls = inboxAll(b.base); const dl = detailRecs(b.base)
851
+ check('merge: a settle inside the dedup window neither counts nor records',
852
+ ls.length === 1 && !ls[0].includes('×') && dl.length === 1, `lines=${ls.length} detail=${dl.length}`)
853
+ }
854
+
855
+ // ⑨ 行计数读者:合并行算一行;被后续事件扩展后仍是已读
856
+ {
857
+ const b = makeBase('merge-readers')
858
+ resetNotify(b.base)
859
+ for (const t of ['one', 'two', 'three']) await notify.settle(b.wt, 'stop', `MERGE-READERS ${t}`)
860
+ const before = inboxNewCount(b.base)
861
+ runCliRc(b.base, ['inbox', 'dev', '--ack'])
862
+ await notify.settle(b.wt, 'stop', 'MERGE-READERS four')
863
+ const after = inboxNewCount(b.base)
864
+ check('merge: line-counting readers count a merged line once',
865
+ before === 1 && after === 0 && /×4/.test(inboxAll(b.base)[0] ?? ''),
866
+ `before=${before} after=${after} :: ${inboxAll(b.base)[0] ?? ''}`)
867
+ }
868
+
869
+ // ⑩ 陈旧判据在合并行上读最后一条的 tip(更早的事件从明细里判)
870
+ {
871
+ const b = makeBase('merge-stale')
872
+ taskProof(b.base, 'dev', 'P230')
873
+ resetNotify(b.base)
874
+ await notify.settle(b.wt, 'stop', 'MERGE-STALE one')
875
+ const tip1 = tipOfLine(detailRecs(b.base).at(-1) ?? '')
876
+ git(['add', '-A'], b.wt)
877
+ git(['-c', 'user.email=fixture@teamsmith', '-c', 'user.name=fixture', 'commit', '-qm', 'merge-stale one'], b.wt)
878
+ await notify.settle(b.wt, 'stop', 'MERGE-STALE two')
879
+ const tip2 = tipOfLine(detailRecs(b.base).at(-1) ?? '')
880
+ const line = inboxAll(b.base)[0] ?? ''
881
+ mkdirSync(join(b.base, 'docs/team/reviews'), { recursive: true })
882
+ writeFileSync(join(b.base, 'docs/team/reviews/P230.md'), `# P230\n\n- HEAD ${tip1}\n`)
883
+ const reviewed = new RegExp(tip1).test(readFileSync(join(b.base, 'docs/team/reviews/P230.md'), 'utf8'))
884
+ const judged = t => tip1.startsWith(t) || t.startsWith(tip1)
885
+ check('merge: a merged line is judged by its last event, not as current state',
886
+ /×2/.test(line) && tip1 !== tip2 && line.includes(`tip=${tip2}`) && !judged(tip2) && judged(tip1) && reviewed,
887
+ `tip1=${tip1} tip2=${tip2} :: ${line}`)
888
+ }
889
+ }
890
+
891
+ // ── detail:明细文件 / 轮转 / 读面缺口 ────────────────────────────────────────
892
+ const groupDetail = async () => {
893
+ const notify = await newNotify()
894
+
895
+ // ① 计数与记录一致;② 明细不是流量(记录不写收件箱行、不入队 knock)
896
+ {
897
+ const b = makeBase('detail-agree')
898
+ resetNotify(b.base)
899
+ await notify.settle(b.wt, 'stop', 'DETAIL one')
900
+ await notify.settle(b.wt, 'stop', 'DETAIL two')
901
+ await notify.settle(b.wt, 'stop', 'DETAIL three')
902
+ const dl = detailRecs(b.base)
903
+ const out = runCliRc(b.base, ['inbox', 'dev', '--detail']).out
904
+ check('detail: a run’s count and its records agree',
905
+ /×3/.test(inboxAll(b.base)[0] ?? '') && dl.length === 3 && /记录 3\/3 OK/.test(out),
906
+ `recs=${dl.length} out=${out.split('\n').slice(0, 3).join(' / ')}`)
907
+ check('detail: the detail file is not traffic',
908
+ inboxAll(b.base).length === 1 && knockEntries(b.base) === 0,
909
+ `lines=${inboxAll(b.base).length} knocks=${knockEntries(b.base)}`)
910
+ }
911
+
912
+ // ③ 轮转:搬走一代 + 新代轮转头(时间 / state/notify.log.1 / 事件数)+ 扩展日志点名
913
+ {
914
+ const b = makeBase('detail-rotate')
915
+ configAdd(b.base, 'TEAM_NOTIFY_DETAIL_MAX=2')
916
+ resetNotify(b.base)
917
+ for (const t of ['one', 'two', 'three']) await notify.settle(b.wt, 'stop', `ROTATE ${t}`)
918
+ const cur = detailRaw(b.base)
919
+ const rotated = existsSync(`${detailFileOf(b.base)}.1`) ? readFileSync(`${detailFileOf(b.base)}.1`, 'utf8') : ''
920
+ const log = existsSync(join(b.base, '.pi/team/state/notify-ext.log')) ? readFileSync(join(b.base, '.pi/team/state/notify-ext.log'), 'utf8') : ''
921
+ check('detail: a rotated generation names where the older events went',
922
+ /^# rotation \S+ moved=2 /.test(cur) && cur.includes('state/notify.log.1') && detailEventCount(cur) <= 2 && detailEventCount(rotated) === 2 && /rotated/.test(log),
923
+ `head=${cur.split('\n')[0] ?? ''} curEvents=${detailEventCount(cur)} rotEvents=${detailEventCount(rotated)}`)
924
+ for (const t of ['four', 'five', 'six', 'seven']) await notify.settle(b.wt, 'stop', `ROTATE ${t}`)
925
+ const cur2 = detailRaw(b.base)
926
+ check('detail: the bound holds as the file grows',
927
+ detailEventCount(cur2) <= 2 && !existsSync(`${detailFileOf(b.base)}.2`),
928
+ `curEvents=${detailEventCount(cur2)} generations=${existsSync(`${detailFileOf(b.base)}.1`) ? 1 : 0}`)
929
+ }
930
+
931
+ // ④ 缺文件:点名 state/notify.log 与 .1,非零退出,不假装完整
932
+ {
933
+ const b = makeBase('detail-missing')
934
+ resetNotify(b.base)
935
+ await notify.settle(b.wt, 'stop', 'GAP one')
936
+ await notify.settle(b.wt, 'stop', 'GAP two')
937
+ rmSync(detailFileOf(b.base), { force: true })
938
+ const r = runCliRc(b.base, ['inbox', 'dev', '--detail'])
939
+ check('detail: a missing record is named, not silent',
940
+ r.rc !== 0 && r.out.includes('state/notify.log') && r.out.includes('state/notify.log.1') && !/记录 2\/2 OK/.test(r.out),
941
+ `rc=${r.rc} :: ${r.out.replace(/\n/g, ' | ').slice(0, 220)}`)
942
+ }
943
+
944
+ // ⑤ 轮转后当前代缺记录:点名缺口与 .1,非零退出
945
+ {
946
+ const b = makeBase('detail-rotgap')
947
+ configAdd(b.base, 'TEAM_NOTIFY_DETAIL_MAX=2')
948
+ resetNotify(b.base)
949
+ for (const t of ['one', 'two', 'three']) await notify.settle(b.wt, 'stop', `ROTGAP ${t}`)
950
+ const r = runCliRc(b.base, ['inbox', 'dev', '--detail'])
951
+ check('detail: a rotated run’s gap is named with the older generation',
952
+ r.rc !== 0 && /缺口/.test(r.out) && r.out.includes('state/notify.log.1') && /×3/.test(r.out) && /记录 1\/3/.test(r.out),
953
+ `rc=${r.rc} :: ${r.out.replace(/\n/g, ' | ').slice(0, 240)}`)
954
+ }
955
+
956
+ // ⑥ 只读:不 ack、未读数不变
957
+ {
958
+ const b = makeBase('detail-readonly')
959
+ resetNotify(b.base)
960
+ await notify.settle(b.wt, 'stop', 'READONLY one')
961
+ await notify.settle(b.wt, 'stop', 'READONLY two')
962
+ const before = inboxNewCount(b.base)
963
+ // --detail 在有缺口时**按契约非零退出**:夹具用 rc 宽容的调用(否则破坏树会把 harness 自身搞崩)
964
+ runCliRc(b.base, ['inbox', 'dev', '--detail'])
965
+ const after = inboxNewCount(b.base)
966
+ check('detail: detail reading does not acknowledge', before === 1 && after === 1, `before=${before} after=${after}`)
967
+ }
968
+ }
969
+
970
+ // ── wake:只有写新行才入队 knock(合并的 settle 不叫醒)──────────────────────
971
+ const groupWake = async () => {
972
+ const notify = await newNotify()
973
+ const prevPane = process.env.TMUX_PANE
974
+ // 敲门要「有 PM 窗口」的形状:TMUX_PANE 在进程内设就够(子进程继承);假 tmux 由 bg-ledger.sh 在
975
+ // **启动 runner 之前**放进 PATH —— bun 在启动时缓存 PATH,运行中改 process.env.PATH 对子进程查找无效。
976
+ process.env.TMUX_PANE = 'p251-fixture-pane'
977
+ try {
978
+ // ① 交付:每个新行恰好一条 knock,同键合并的 settle 零条目
979
+ {
980
+ const b = makeBase('wake-once')
981
+ configAdd(b.base, 'TEAM_NOTIFY_DEDUP_SEC=0')
982
+ resetNotify(b.base)
983
+ await notify.settle(b.wt, 'stop', 'WAKE-ONCE one')
984
+ const k1 = knockEntries(b.base)
985
+ await notify.settle(b.wt, 'stop', 'WAKE-ONCE two')
986
+ const k2 = knockEntries(b.base)
987
+ await notify.settle(b.wt, 'stop', 'WAKE-ONCE three')
988
+ const k3 = knockEntries(b.base)
989
+ check('wake: each new line wakes exactly once', k1 === 1 && k2 === 1 && k3 === 1, `k=${k1},${k2},${k3}`)
990
+ // 合并的 settle 不敲:既不能新增条目(会被 outbox 自己的去重挡住,所以还要看扩展自己的账本)
991
+ // 也不能走「入队」那条路径 —— 扩展日志里必须是 no knock(state=extended),零次 knock queued。
992
+ const log3 = extLogOf(b.base)
993
+ check('wake: a merged settle does not wake again',
994
+ k3 === 1 && /×3/.test(inboxAll(b.base)[0] ?? '') && /no knock \(inbox write state=extended\)/.test(log3),
995
+ `k=${k3} log=${log3.split('\n').filter(Boolean).slice(-3).join(' | ')}`)
996
+ }
997
+
998
+ // ② 挂起只记录、不叫醒(用户裁定 2026-10-14):行与明细都在、queue 为空;同键合并也不叫醒
999
+ {
1000
+ const b = makeBase('wake-suspended')
1001
+ configAdd(b.base, 'TEAM_NOTIFY_DEDUP_SEC=0')
1002
+ resetNotify(b.base)
1003
+ const pid = liveRecord(b.base, 'W2', b.wt)
1004
+ await notify.settle(b.wt, 'stop', 'WAKE-SUSPENDED one')
1005
+ const k1 = knockEntries(b.base)
1006
+ const line1 = inboxAll(b.base)[0] ?? ''
1007
+ const rec1 = detailRecs(b.base).length
1008
+ await notify.settle(b.wt, 'stop', 'WAKE-SUSPENDED two')
1009
+ const k2 = knockEntries(b.base)
1010
+ const line2 = inboxAll(b.base)[0] ?? ''
1011
+ const rec2 = detailRecs(b.base).length
1012
+ check('wake: a suspended line never wakes',
1013
+ k1 === 0 && line1.includes('[auto·suspended]') && line1.includes('awaiting=W2') && rec1 === 1,
1014
+ `k=${k1} recs=${rec1} :: ${line1}`)
1015
+ check('wake: a merged suspended run never wakes',
1016
+ k2 === 0 && /×2/.test(line2) && line2.includes('awaiting=W2') && rec2 === 2,
1017
+ `k=${k2} recs=${rec2} :: ${line2}`)
1018
+ killPid(pid); dropRecord(b.base, 'W2')
1019
+ }
1020
+
1021
+ // ③ 状态类变化:挂起不叫醒,随后交付 / 中断各叫醒一次
1022
+ {
1023
+ const b = makeBase('wake-class')
1024
+ configAdd(b.base, 'TEAM_NOTIFY_DEDUP_SEC=0')
1025
+ resetNotify(b.base)
1026
+ const pid = liveRecord(b.base, 'W3', b.wt)
1027
+ await notify.settle(b.wt, 'stop', 'WAKE-CLASS suspended')
1028
+ const k0 = knockEntries(b.base)
1029
+ dropRecord(b.base, 'W3'); killPid(pid)
1030
+ await notify.settle(b.wt, 'stop', 'WAKE-CLASS delivered')
1031
+ const k1 = knockEntries(b.base)
1032
+ const pid2 = liveRecord(b.base, 'W3', b.wt)
1033
+ await notify.settle(b.wt, 'aborted', 'WAKE-CLASS interrupted')
1034
+ const k2 = knockEntries(b.base)
1035
+ check('wake: a class change away from suspended wakes once',
1036
+ k0 === 0 && k1 === 1 && k2 === 2,
1037
+ `k=${k0},${k1},${k2} :: ${inboxAll(b.base).map(l => l.slice(0, 60)).join(' || ')}`)
1038
+ killPid(pid2); dropRecord(b.base, 'W3')
1039
+ }
1040
+
1041
+ // ④ 计数抖动不叫醒:先显式清掉上一条 knock(否则 outbox 自己的去重会替实现挡住这条断言)
1042
+ {
1043
+ const b = makeBase('wake-churn')
1044
+ configAdd(b.base, 'TEAM_NOTIFY_DEDUP_SEC=0')
1045
+ resetNotify(b.base)
1046
+ await notify.settle(b.wt, 'stop', 'WAKE-CHURN one')
1047
+ const k1 = knockEntries(b.base)
1048
+ runCliRc(b.base, ['outbox', 'drop', 'all'])
1049
+ const k0 = knockEntries(b.base)
1050
+ await notify.settle(b.wt, 'stop', 'WAKE-CHURN two')
1051
+ await notify.settle(b.wt, 'stop', 'WAKE-CHURN three')
1052
+ const k2 = knockEntries(b.base)
1053
+ check('wake: count churn does not wake',
1054
+ k1 >= 1 && k2 === k0 && /×3/.test(inboxAll(b.base)[0] ?? ''),
1055
+ `afterFirst=${k1} afterDrop=${k0} afterChurn=${k2} lines=${inboxAll(b.base).length}`)
1056
+ }
1057
+
1058
+ // ⑤ 两条文本逐字相同的不同行(手工通知打断 + 夹具去掉 settle 去重簿):行身份不互吞。
1059
+ // 不去掉 outbox 的去重窗口(默认 20s):用摘要当键的破坏实现会被它摕下(这正是要红的地方)。
1060
+ // 不去掉 outbox 的去重窗口(默认 20s):用摘要当键的破坏实现会被它摕下(这正是要红的地方)。
1061
+ {
1062
+ const b = makeBase('wake-identity')
1063
+ resetNotify(b.base)
1064
+ await notify.settle(b.wt, 'stop', 'WAKE-IDENTICAL text')
1065
+ runCliRc(b.base, ['notify', 'dev', 'WAKE-IDENTICAL break'])
1066
+ rmSync(join(b.base, '.pi/team/state/notify-dedup'), { force: true })
1067
+ await notify.settle(b.wt, 'stop', 'WAKE-IDENTICAL text')
1068
+ const ls = inboxAll(b.base)
1069
+ const stripped = l => l.replace(/^- \S+ /, '')
1070
+ check('wake: two text-identical lines are not conflated',
1071
+ ls.length === 3 && knockEntries(b.base) === 2 && ls[0] !== ls[2] && stripped(ls[0]) === stripped(ls[2]),
1072
+ `lines=${ls.length} knocks=${knockEntries(b.base)} :: ${ls.join(' || ').slice(0, 200)}`)
1073
+ }
1074
+
1075
+ // ⑥ 写盘失败不叫醒(收件箱路径是个目录 → 追加必败)
1076
+ {
1077
+ const b = makeBase('wake-writefail')
1078
+ resetNotify(b.base)
1079
+ rmSync(join(b.base, 'docs/team/inbox/dev.md'), { force: true })
1080
+ mkdirSync(join(b.base, 'docs/team/inbox/dev.md'), { recursive: true })
1081
+ await notify.settle(b.wt, 'stop', 'WAKE-WRITEFAIL must not wake')
1082
+ const k = knockEntries(b.base)
1083
+ rmSync(join(b.base, 'docs/team/inbox/dev.md'), { recursive: true, force: true })
1084
+ check('wake: a failed inbox write does not wake', k === 0, `knocks=${k}`)
1085
+ }
1086
+ } finally {
1087
+ if (prevPane === undefined) delete process.env.TMUX_PANE
1088
+ else process.env.TMUX_PANE = prevPane
1089
+ }
1090
+ }
1091
+
671
1092
  // ── 主流程 ────────────────────────────────────────────────────────────────────
672
1093
  console.log(`bg-ledger-harness · root=${ROOT} · groups=${[...GROUPS].join(',')} · bg=${BG} · notify=${NOTIFY}`)
673
1094
  try {
@@ -675,6 +1096,9 @@ try {
675
1096
  if (GROUPS.has('ledger')) await groupLedger()
676
1097
  if (GROUPS.has('suspend-shape')) await groupSuspendShape()
677
1098
  if (GROUPS.has('owner-scope')) await groupOwnerScope()
1099
+ if (GROUPS.has('merge')) await groupMerge()
1100
+ if (GROUPS.has('detail')) await groupDetail()
1101
+ if (GROUPS.has('wake')) await groupWake()
678
1102
  } catch (error) {
679
1103
  check('harness: no unexpected exception', false, String(error?.stack ?? error).split('\n').slice(0, 3).join(' / '))
680
1104
  }