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
@@ -11,21 +11,15 @@
11
11
  # env -u TMUX + 私有 TMUX_TMPDIR,或包一层隔离包装)。
12
12
  #
13
13
  # 格式:<sha256> <未隔离条数> <仓库相对路径> # 理由
14
- 6655f47fffe9ac23955fba2ec541edb36a23c50d1ceb080b57f740d55713787b 8 docs/team/reports/M23-dev2/pkg/namespace-demo.sh # M23-dev2 证据包(M28 之前;BEFORE/AFTER 两段里 BEFORE 就是要演示不隔离的形状)
15
- 60162dc4c274b87594148a751cdca014e418463c3acd0cb61026a217bb1f78d9 1 docs/team/reports/M3.3-dev2/pkg/20-control.sh # M3.3-dev2 证据包(M28 之前)
16
- d51b83de98a6e433ab36216b730568ab46210fd33765de2230a1e3e4855105e5 1 docs/team/reports/M3.3-dev2/pkg/40-regression.sh # M3.3-dev2 证据包(M28 之前)
17
- f330c14df7766435767269d5801468bd5b5becb21776ce11c1216ae94e9fbef4 3 docs/team/reports/M3.3-dev2/pkg/lib.sh # M3.3-dev2 证据包(M28 之前)
18
- 1789bc5928faaabce960632b313cba58f27ba4c34ba33724a3031cd3f7560da6 1 docs/team/reports/V3.0/pkg/40-doctor-dispatch.sh # V3.0 证据包(M28 之前)
19
- bea9627472fba160ce6bfe831f8cc0e688bbce9a0782be005f16fc71f2e18bec 1 docs/team/reports/V3.0/pkg/60-liveness.sh # V3.0 证据包(M28 之前)
20
- 26dde2cdbcf0fd0b26bba9f61380d9a9963c8766480182e28acaee74d5af2468 2 docs/team/reports/V3.0/pkg/lib.sh # V3.0 证据包(M28 之前)
21
- 083b41f001bee7e6a061b27c5878829f26cb468da55668917ac76fe4080abb50 1 docs/team/reports/V3.0/pkg/run.sh # V3.0 证据包(M28 之前)
22
- bfd5ed3cff3a826f8c240dc755a9833858627f019332a7fa47a88d70c6dc9090 6 docs/team/reports/V4.0/pkg/30-dispatch.sh # V4.0 证据包(M28 之前;靠 PATH shim,没有调用点证据)
23
- 476d32468178247f5440b9a9349991fb96a2a7061dd0202c5feb7cdbda7c69f0 2 docs/team/reports/V4.0/pkg/40-notify.sh # V4.0 证据包(M28 之前)
24
- af9fd1083c0bad1621ce1fb92bd430de1ca9dc9e1e8a0225d4fd31104139308a 2 docs/team/reports/V4.0/pkg/80-watchdog.sh # V4.0 证据包(M28 之前)
25
- 08a0497eca5b24343fb41da92c48b45fdd0002f697888582c832991681b7321d 3 docs/team/reports/V4.0/pkg/90-boundary.sh # V4.0 证据包(M28 之前)
26
- eaad9afcfccfb80d2514ebcc160ff645effc2e2337d58d38f21b16bd65499663 2 docs/team/reports/V4.0/pkg/flip.sh # V4.0 证据包(M28 之前)
27
- a342b43bbb4e8db297a3c975ca318167dc4d35c89ce80ec8a9f3df58800e98a8 1 docs/team/reports/V4.0/pkg/run.sh # V4.0 证据包(M28 之前)
28
- # M41 追加的绝对路径禁令把下面两个历史证据包里的 kill 判红了 —— 它们写于 M28/M41 的隔离纪律成型之前,
29
- # 不能改(改了就是动别人验过的账本),按同一 sha256 冻结口径豁免:
30
- 91bcf10dbb0dd15498309801865e54b084f5b1750f6a4a3e9e786aa59a18ea20 1 docs/team/reports/V4.0/pkg/lib.sh # V4.0 证据包(M28 之前;M41 之前的绝对路径 `/usr/bin/tmux -L $V40_SOCKET kill-server`)
31
- 66c3441789c3671e72ecd5493ad6681b2a1f52fa3a3c3611c511934cdd675e70 1 docs/team/reports/M9.3-dev2/pkg/run.sh # M9.3-dev2 证据包(M28 之前;M41 之前的绝对路径 `/usr/bin/tmux -L $TMUX_SOCK kill-server`)
14
+ #
15
+ # ── 2026-10-17 · P308:清单已清空(当前 0 条豁免)────────────────────────────────────────────────
16
+ # 上一版的 16 条全部指向 `docs/team/reports/{M23-dev2,M3.3-dev2,M9.3-dev2,V3.0,V4.0}/pkg/*.sh`,而这些
17
+ # 文件在当前历史里一条都不在(`git ls-files docs/team/reports | grep -c '/pkg/'` → 0)。它们只留在
18
+ # 改写前的旧历史里(`git merge-base --is-ancestor 914c334d HEAD` → 非祖先;`v1.19.0` 才含它),
19
+ # 也就是说当前树里没有任何可豁免的对象,每轮门禁都因此红在 `baseline —— …文件不在了`。
20
+ # 按本文件自己的规则「清单里的文件不在了(删文件就同时删豁免行)」删掉这 16 行:豁免的语义是
21
+ # 「不许就地改别人验过的**存在**的文件」,文件不在了就没有对象;从旧 tag 把证据包复活塞回当前树
22
+ # 等于把仓库改写时摘掉的账本内容重新发布,那不是测试基础设施该做的事。
23
+ # 现状:`perl skills/teamsmith/tests/tmux-lint.pl` 真树扫描 0 条红(`--selftest` 仍覆盖本机制:
24
+ # 哈希锁定 → 净、文件一改 → 红、条数不对 → 红)。新增豁免仍按上面的口径:先证明该文件确实该豁免,
25
+ # 再按 sha256 冻结写进来。
@@ -0,0 +1,537 @@
1
+ #!/usr/bin/env bash
2
+ # P255 · 升级配方(references/migration.md §6)的每一步可证伪。
3
+ #
4
+ # 为什么有这一套:用户 2026-10-14 拿一个 0.1.2 的项目照文档升级,第一步就撞在身份拒绝上 —— §6 当时
5
+ # 还写着「git pull 一个 checkout」,而 0.2.0 起技能来源是 npm 包;配置迁移、PM 启动身份、席位续跑、
6
+ # 回滚这些步骤文档里也没有。文档承诺的东西必须有人守:本夹具把 §6 的每一步落成一条可跑、可证伪的断言。
7
+ #
8
+ # 三件事:
9
+ # ① 文档面:§6 必须仍然承诺每条步骤(DOC_LITERALS),并且不许出现把 `--no-migrate` 与推导命令
10
+ # 无条件连起来的旧句子(DOC_FORBIDDEN);删掉任一步或让它回潮 → 这里红。
11
+ # ② 工具面:每条承诺都要能在真 CLI 上兑现(promise:文档承诺的串 → 工具真的打印它);
12
+ # 反向对照(promise_red)证明这个探针能红,不是恒真。
13
+ # ③ 现场:在一个 0.1.x 形状的临时项目里走完整条配方 —— 工具升级(夹具桩)→ 备份 → 迁移前被拒 →
14
+ # `team up` 自动迁移(私有 tmux + 假 PM,绝不碰共享 server)→ 迁移后 `config list` rc=0 →
15
+ # 身份(缺记录自动登记 / 记录不符两条出路 / --fresh-pm 的 fresh 判定)→ 收尾验证 → 回滚。
16
+ #
17
+ # 分组:--select doc,walk,identity,rollback,selftest(默认全跑)。
18
+ # 退出码:0 = 全绿;1 = 有失败;2 = 用法错误;3 = 建不出临时根。
19
+ set -uo pipefail
20
+
21
+ here="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
22
+ # shellcheck source=tests/lib/tmp-root.sh
23
+ source "$here/lib/tmp-root.sh"
24
+ # shellcheck source=tests/lib/tmux-iso.sh
25
+ source "$here/lib/tmux-iso.sh"
26
+
27
+ TREE="${TEAM_RECIPE_TREE:-$(cd "$here/../../.." && pwd)}"
28
+ SKILL="$TREE/skills/teamsmith"
29
+ CLI="$SKILL/scripts/team"
30
+ DOC="$SKILL/references/migration.md"
31
+
32
+ SELECT='doc,walk,identity,rollback,selftest'
33
+ while [ $# -gt 0 ]; do
34
+ case "$1" in
35
+ --select) SELECT="${2:?}"; shift 2 ;;
36
+ *) printf 'unknown option: %s\n' "$1"; exit 2 ;;
37
+ esac
38
+ done
39
+ for g in ${SELECT//,/ }; do
40
+ case "$g" in doc|walk|identity|rollback|selftest) ;; *) printf 'unknown group: %s\n' "$g"; exit 2 ;; esac
41
+ done
42
+ has() { case ",$SELECT," in *",$1,"*) return 0 ;; esac; return 1; }
43
+ # identity / rollback 的现场是 walk 的产物(迁移后的配置 + 启动记录):选它们就把 walk 一并拉进来。
44
+ if has identity || has rollback; then
45
+ case ",$SELECT," in *",walk,"*) ;; *) SELECT="$SELECT,walk" ;; esac
46
+ fi
47
+
48
+ # 绝不继承父进程的 TEAM_*(门禁是嵌套跑的);身份一律按 cwd 推导。
49
+ while IFS='=' read -r k _; do case "$k" in TEAM_*) unset "$k" 2>/dev/null || true ;; esac; done < <(env)
50
+ # M36 闸门在 PATH 里的那一格也属于「调用者身份」(smoke.sh 文件头同一条纪律,原因见那里):
51
+ # 从 PM/worker 会话派生的夹具里 `command -v tmux` 会解析到 scripts/shim/tmux 而不是真 tmux ——
52
+ # 本夹具要拿真身来建私有 server(P255 实测:没剥掉时 tmux_iso_probe 里的 `tmux ls` 卡死不动)。
53
+ _rcp=""; _rcifs="$IFS"; IFS=:
54
+ for _rcd in $PATH; do case "$_rcd" in */scripts/shim) ;; *) _rcp="${_rcp:+$_rcp:}$_rcd" ;; esac; done
55
+ IFS="$_rcifs"; [ -n "$_rcp" ] && PATH="$_rcp"; export PATH; unset _rcp _rcifs _rcd
56
+ unset TEAM_ALLOW_DESTRUCTIVE_TMUX TEAM_TMUX_CALLS_LOG TEAM_TMUX_REAL TEAM_SIGNAL_CALLS_LOG \
57
+ TEAM_SIGNAL_REAL TEAM_TMUX_ISO_LOG 2>/dev/null || true
58
+ unset TEAM_TMP_RUN_ID TEAM_TMP_LEDGER 2>/dev/null || true
59
+ [ -n "${RECIPE_TMP_RUN_ID:-}" ] || export RECIPE_TMP_RUN_ID="recipe-$$-$(date +%s)"
60
+ TMP="$(tmp_root_create upgrade-recipe)" || exit 3
61
+ unset TMUX TMUX_PANE
62
+ export HOME="$TMP/home"; mkdir -p "$HOME"
63
+ PASS=0; FAIL=0; LIVE_SOCKET=''
64
+ cleanup() {
65
+ [ "${BASHPID:-$$}" = "$$" ] || return 0
66
+ if [ -n "$LIVE_SOCKET" ] && tmux_iso_guard_soft recipe cleanup \
67
+ --tmpdir "${TMUX_TMPDIR:-}" --sock-name "$LIVE_SOCKET" --own-root "$TMP" --own-root "$TMUX_TMPDIR"; then
68
+ tmux -L "$LIVE_SOCKET" kill-server 2>/dev/null || true
69
+ fi
70
+ tmp_root_reap_all
71
+ }
72
+ trap cleanup EXIT
73
+
74
+ pass() { PASS=$((PASS + 1)); printf 'PASS %s\n' "$1"; }
75
+ fail() { FAIL=$((FAIL + 1)); printf 'FAIL %s\n' "$1"; }
76
+ check() { local n="$1"; shift; if "$@"; then pass "$n"; else fail "$n"; fi; }
77
+ not() { ! "$@"; } # 否定一条 shell 函数断言(不能用 bash -c:新 shell 里没有这些函数)
78
+ eq() { [ "$1" = "$2" ]; }
79
+ contains() { [[ "$1" == *"$2"* ]]; }
80
+ # 迁移拒绝里**完整推导映射**的判据:`--task-models '…'` 的值串里没有占位符(`<`)。
81
+ complete_map_line() { grep -qE -- "--task-models '[^<]*'" "$1"; }
82
+ sha() { if [ -f "$1" ]; then sha256sum "$1" | cut -d' ' -f1; else printf absent; fi; }
83
+ section6_of() { sed -n '/^## 6\. Upgrade recipe/,/^## 7\./p' "$1"; }
84
+ # 各组共享的工具输出文件(单独 --select 某组时它们不存在,负向对照就自然判红)。
85
+ UP_PRINT_OLD=''; UP_NOMIGRATE=''; UP_REAL=''; UP_CONT=''; UP_FRESH=''; UP_MISMATCH=''; UP_NOREC=''
86
+ CONFIG_LIST=''; DISPATCH=''; VERSION=''; ROLLBACK_LIST=''; ORIG_SHA=''
87
+
88
+ # ── ① 文档面:§6 必须承诺的每一步(删一步 → 这里红)──────────────────────────────────────────
89
+ # 每条对应任务书「升级配方」里的一步;值取 §6 里逐字出现的片段(改动 §6 的措辞时同步这里)。
90
+ DOC_LITERALS=(
91
+ 'npm i -g teamsmith@' # 1 工具升级:npm 包路线
92
+ 'install.sh' # 1 刷新共享软链
93
+ 'readlink -f' # 1 验证技能来源
94
+ 'team version' # 1 版本自检
95
+ 'cp .pi/team/config.sh' # 2 迁移前先备份
96
+ 'team up --print' # 2 只看不写
97
+ 'team up --no-migrate' # 2 拒绝并给可粘贴命令
98
+ 'team config upgrade-models' # 2 手工路线
99
+ '--dry-run' # 2 手工路线预览
100
+ '--yes' # 2 手工路线唯一一次写
101
+ 'team config list' # 2 形状确认 / 5 收尾验证
102
+ 'state/pm-launch.env' # 3 PM 启动身份是什么
103
+ '--fresh-pm' # 3 新对话出路
104
+ '--adopt-pm-identity' # 3 认领记录出路
105
+ 'team up --agents' # 4 席位一并拉起
106
+ 'team resume' # 4 续跑清单
107
+ 'team doctor' # 5 收尾验证
108
+ 'team dispatch --print' # 5 category: 与模型解析
109
+ 'TEAM_CONFIG_VERSION' # 2 形状号
110
+ 'migration_required' # 6 回滚后旧形状复现
111
+ 'placeholder route' # 2(F1)推导停住时给的是占位符路线,不是推导命令
112
+ 'bracketed placeholder' # 2(F1)占位符路线的形态(文档侧的字面,工具侧判据与语言无关)
113
+ 'whichever of the two command forms' # 2(F3)`--no-migrate` 那句也把两种形态写出来,不是无条件承诺推导命令
114
+ 'team pulse up' # 4(F2)巡检窗口由 pulse up 建立,不是 team up 重建
115
+ )
116
+ doc_coverage_check() { # <file> → 0 = §6 里每一步都在
117
+ local t lit; t="$(section6_of "$1")"
118
+ for lit in "${DOC_LITERALS[@]}"; do case "$t" in *"$lit"*) ;; *) return 1 ;; esac; done
119
+ return 0
120
+ }
121
+ doc_missing() { # <file> → 逐行打印 §6 缺的片段
122
+ local t lit; t="$(section6_of "$1")"
123
+ for lit in "${DOC_LITERALS[@]}"; do case "$t" in *"$lit"*) ;; *) printf '%s\n' "$lit" ;; esac; done
124
+ }
125
+ # F3(V40 第二轮):这些片段把 `--no-migrate` 与「推导出来的命令」无条件连起来 —— §6 里不许再出现。
126
+ # 同一条承诺的条件形态由 DOC_LITERALS 的 `whichever of the two command forms` 正向钉住,这里是反向。
127
+ DOC_FORBIDDEN=(
128
+ 'manual command derived' # F3 旧句子:prints the manual command derived from *your* configuration
129
+ )
130
+ doc_forbidden_check() { # <file> → 0 = §6 里一个禁列短语都不出现
131
+ local t ph; t="$(section6_of "$1")"
132
+ for ph in "${DOC_FORBIDDEN[@]}"; do case "$t" in *"$ph"*) return 1 ;; esac; done
133
+ return 0
134
+ }
135
+ doc_forbidden_hits() { # <file> → 逐行打印 §6 命中的禁列短语
136
+ local t ph; t="$(section6_of "$1")"
137
+ for ph in "${DOC_FORBIDDEN[@]}"; do case "$t" in *"$ph"*) printf '%s\n' "$ph" ;; esac; done
138
+ }
139
+ # ② 工具面:文档承诺的片段(doc-literal)+ 工具真的打印的串(want)都要成立。
140
+ promise_check() { # <doc-literal> <工具输出文件> <want> → 0 = 两半都成立
141
+ grep -qF -- "$1" "$DOC" || return 1
142
+ grep -qF -- "$3" "$2" || return 1
143
+ return 0
144
+ }
145
+ promise_red() { ! promise_check "$1" "$2" "$3"; } # 反向对照:探针必须能红
146
+ promise() { # <name> <doc-literal> <输出文件> <want>
147
+ local name="$1" lit="$2" f="$3" want="$4"
148
+ if ! grep -qF -- "$lit" "$DOC"; then fail "doc-promise:$name(§6 不再承诺 $lit)"; return; fi
149
+ if ! grep -qF -- "$want" "$f"; then fail "doc-promise:$name(§6 承诺 $lit,但工具没有打印 $want)"; return; fi
150
+ pass "doc-promise:$name"
151
+ }
152
+
153
+ CLEAN_ENV=(env -u TEAM_ROOT -u TEAM_MAIN_ROOT -u TEAM_ROOT_SOURCE -u TEAM_ROOT_WAS -u TEAM_PROJECT \
154
+ -u TEAM_SESSION -u TEAM_SESSION_FROM -u TEAM_PM_WINDOW -u TEAM_AGENTS -u TEAM_DOCS_DIR \
155
+ -u TEAM_WORKTREES_DIR -u TEAM_GATES -u TEAM_VCS -u TEAM_CONFIG -u TEAM_CONFIG_FILE \
156
+ -u TEAM_STATE_DIR -u TEAM_SKILL_DIR -u TEAM_PULSE_WINDOW -u TEAM_MODEL_RETIRED_ENV -u TEAM_UPDATE_CHECK)
157
+ run() { # <dir> -- <team args…>:真 CLI、干净环境、私有 PATH(私有 tmux + pi 桩)
158
+ local d="$1"; shift
159
+ [ "${1:-}" = '--' ] && shift
160
+ printf 'RUN %s %s\n' "$d" "$*" # 挂住时这一行就是最后一个线索
161
+ RC=0; OUT="$( cd "$d" && "${CLEAN_ENV[@]}" timeout "${RECIPE_CMD_TIMEOUT:-120}" bash "$CLI" "$@" 2>&1 )" || RC=$?
162
+ printf 'command=%q ' "$@"; printf '\nrc=%s\n%s\n' "$RC" "$OUT"
163
+ }
164
+ capture() { printf '%s\n' "$OUT" > "$1"; }
165
+ cmd_line() { grep -F '完整命令:' "$1" | head -1; }
166
+
167
+ # ── ① 文档面 ────────────────────────────────────────────────────────────────────────────
168
+ if has doc; then
169
+ check doc-section-present test -f "$DOC"
170
+ check doc-coverage doc_coverage_check "$DOC"
171
+ if ! doc_coverage_check "$DOC"; then
172
+ printf ' §6 缺的片段:\n'
173
+ doc_missing "$DOC" | sed 's/^/ /'
174
+ fi
175
+ check doc-forbidden-phrases doc_forbidden_check "$DOC"
176
+ if ! doc_forbidden_check "$DOC"; then
177
+ printf ' §6 命中的禁列短语:\n'
178
+ doc_forbidden_hits "$DOC" | sed 's/^/ /'
179
+ fi
180
+ fi
181
+
182
+ # ── ③ 现场:0.1.x 形状的临时项目 ─────────────────────────────────────────────────────────
183
+ R="$TMP/repo"; BIN="$TMP/bin"
184
+ if has walk || has identity || has rollback; then
185
+ mkdir -p "$R/.pi/team" "$R/docs/team/tasks" "$R/docs/team/reports" "$R/docs/team/threads" \
186
+ "$R/docs/team/inbox" "$R/docs/team/reviews" "$BIN"
187
+ ( cd "$R" && git init -q -b main && git config user.name fixture && git config user.email fixture@example.invalid \
188
+ && printf '# upgrade recipe fixture\n' > README.md && git add -A && git commit -qm fixture ) >/dev/null 2>&1
189
+
190
+ # 工具升级那一步用夹具桩:假 npm(记 argv、答 root -g)+ 包内 install.sh(记运行),
191
+ # 再加一条 ~/.agents/skills/teamsmith → 包内技能的软链,配方第 1 步的 readlink 验证才有对象。
192
+ NPMROOT="$R/npmroot"; TOOL="$R/toolbin"
193
+ mkdir -p "$TOOL" "$NPMROOT/teamsmith/skills/teamsmith" "$HOME/.agents/skills"
194
+ cat > "$TOOL/npm" <<EOF
195
+ #!/usr/bin/env bash
196
+ printf '%s\n' "\$*" >> "$R/npm-args.log"
197
+ if [ "\${1:-}" = root ] && [ "\${2:-}" = -g ]; then printf '%s\n' "$NPMROOT"; exit 0; fi
198
+ exit 0
199
+ EOF
200
+ chmod +x "$TOOL/npm"
201
+ cat > "$NPMROOT/teamsmith/install.sh" <<EOF
202
+ #!/usr/bin/env bash
203
+ printf 'install.sh %s\n' "\$*" >> "$R/install-ran.log"
204
+ exit 0
205
+ EOF
206
+ chmod +x "$NPMROOT/teamsmith/install.sh"
207
+ ln -sfn "$NPMROOT/teamsmith/skills/teamsmith" "$HOME/.agents/skills/teamsmith"
208
+
209
+ # pi 桩(doctor 的 pi 检查看 PATH);假 openspec + 假 settings(必需依赖的确定性夹具)。
210
+ cat > "$BIN/pi" <<'EOF'
211
+ #!/usr/bin/env bash
212
+ case "${1:-}" in
213
+ --version) printf '0.99.0-recipe-fixture\n'; exit 0 ;;
214
+ --help) printf 'Usage: pi [options]\n --session-id <id>\n'; exit 0 ;;
215
+ esac
216
+ exit 0
217
+ EOF
218
+ chmod +x "$BIN/pi"
219
+ mkdir -p "$R/deps/npm/node_modules/@cortexkit/pi-magic-context" "$R/openspec"
220
+ printf '{"packages":["npm:@cortexkit/pi-magic-context"]}\n' > "$R/deps/settings.json"
221
+ printf '{"name":"@cortexkit/pi-magic-context","version":"9.9.9"}\n' \
222
+ > "$R/deps/npm/node_modules/@cortexkit/pi-magic-context/package.json"
223
+ cat > "$R/deps/openspec" <<'EOF'
224
+ #!/usr/bin/env bash
225
+ [ "${1:-}" = "--version" ] && printf 'openspec 9.9.9 (recipe-fixture)\n'
226
+ exit 0
227
+ EOF
228
+ chmod +x "$R/deps/openspec"
229
+ # 真 `team up` 起的「PM」:记 argv 后长睡(绝不起真 pi、不连 provider)。
230
+ cat > "$R/recording-pi" <<EOF
231
+ #!/usr/bin/env bash
232
+ printf '%s\n' "\$@" >> "$R/pi-argv.log"
233
+ sleep 180
234
+ EOF
235
+ chmod +x "$R/recording-pi"
236
+
237
+ # 0.1.x 形状的配置:退休键 TEAM_AGENT_MODELS / TEAM_DEFAULT_MODEL,没有 TEAM_CONFIG_VERSION。
238
+ cat > "$R/.pi/team/config.sh" <<EOF
239
+ TEAM_PROJECT='recipe-fixture'
240
+ TEAM_SESSION='recipe-fixture'
241
+ TEAM_PM_WINDOW='pm'
242
+ TEAM_DOCS_DIR='docs/team'
243
+ TEAM_AGENTS='dev verify'
244
+ TEAM_AGENT_MODELS='dev=vendor/light verify=vendor/strong:high'
245
+ TEAM_DEFAULT_MODEL='vendor/base'
246
+ TEAM_PM_MODEL='vendor/pm:high'
247
+ TEAM_WORKTREES_DIR='.worktrees'
248
+ TEAM_VCS='local'
249
+ TEAM_GATES='true'
250
+ TEAM_MIN_FREE_SWAP_MB=0
251
+ TEAM_MIN_TOTAL_MB=0
252
+ TEAM_MIN_AVAIL_MB=0
253
+ TEAM_TMP_MIN_FREE_MB=0
254
+ TEAM_TMP_MIN_FREE_INODES=0
255
+ TEAM_MODEL_LIMITS=''
256
+ TEAM_UPDATE_CHECK=0
257
+ TEAM_PI_BIN='$R/recording-pi'
258
+ TEAM_PI_SETTINGS_FILE='$R/deps/settings.json'
259
+ TEAM_OPENSPEC_BIN='$R/deps/openspec'
260
+ TEAM_SPEC_DIR='$R/openspec'
261
+ EOF
262
+ cat > "$R/docs/team/tasks/H1-fixture.md" <<'EOF'
263
+ # H1 · fixture
264
+ agent: dev
265
+ phase: apply
266
+ category: default
267
+ change: -
268
+ anchor: none (infra) — isolated upgrade-recipe fixture
269
+ branch: task/H1-fixture
270
+ ## Scope
271
+ fixture only
272
+ EOF
273
+ mkdir -p "$R/.worktrees"
274
+ ( cd "$R" && git worktree add -qb task/H1-fixture .worktrees/dev ) >/dev/null 2>&1
275
+ fi
276
+
277
+ if has walk; then
278
+ ORIG_SHA="$(sha "$R/.pi/team/config.sh")"
279
+
280
+ # 配方第 1 步(逐字照 §6 的代码块跑;npm 与 install.sh 是上面的桩)。
281
+ ( export PATH="$TOOL:$PATH" HOME="$HOME"
282
+ npm i -g teamsmith@0.2.0 --registry https://registry.npmjs.org
283
+ bash "$(npm root -g)/teamsmith/install.sh" ) >/dev/null 2>&1
284
+ check tool-upgrade-npm grep -qF -- 'i -g teamsmith@0.2.0 --registry https://registry.npmjs.org' "$R/npm-args.log"
285
+ check tool-upgrade-installer test -f "$R/install-ran.log"
286
+ check tool-upgrade-link eq "$(readlink -f "$HOME/.agents/skills/teamsmith")" \
287
+ "$NPMROOT/teamsmith/skills/teamsmith"
288
+
289
+ # 迁移前的写路径被拒(形状不明时不许写),配置一个字节都不动。
290
+ run "$R" -- config set TEAM_MONITOR_REFRESH 5
291
+ check pre-migration-write-refused bash -c '[ "$1" != 0 ]' _ "$RC"
292
+ check pre-migration-write-names-route contains "$OUT" 'upgrade-models'
293
+ check pre-migration-write-pure eq "$(sha "$R/.pi/team/config.sh")" "$ORIG_SHA"
294
+
295
+ # 配方第 2 步:--print 只预告;--no-migrate 拒绝并给可粘贴命令;粘回去 --dry-run 必须绿。
296
+ run "$R" -- up --print
297
+ UP_PRINT_OLD="$TMP/up-print-old.log"; capture "$UP_PRINT_OLD"
298
+ check preview-rc eq "$RC" 0
299
+ check preview-pairs contains "$OUT" 'TEAM_AGENT_MODELS dev=vendor/light → TEAM_TASK_MODELS dev=vendor/light'
300
+ check preview-default-pair contains "$OUT" 'TEAM_DEFAULT_MODEL vendor/base → TEAM_TASK_MODELS default=vendor/base'
301
+ check preview-backup-line contains "$OUT" '备份:'
302
+ check preview-restore-line contains "$OUT" '还原:cp '
303
+ check preview-identity-line contains "$OUT" '身份预告:此前没有启动记录'
304
+ check preview-pure eq "$(sha "$R/.pi/team/config.sh")" "$ORIG_SHA"
305
+
306
+ run "$R" -- up --no-migrate
307
+ UP_NOMIGRATE="$TMP/up-nomigrate.log"; capture "$UP_NOMIGRATE"
308
+ check nomigrate-refused bash -c '[ "$1" != 0 ]' _ "$RC"
309
+ check nomigrate-names-route contains "$OUT" 'config upgrade-models'
310
+ check nomigrate-pure eq "$(sha "$R/.pi/team/config.sh")" "$ORIG_SHA"
311
+ derived_map="$(printf '%s\n' "$OUT" | awk -F"'" '/^ *--task-models /{print $2}' | head -1)"
312
+ derived_pm="$(printf '%s\n' "$OUT" | awk -F"'" '/^ *--pm-model /{print $2}' | head -1)"
313
+ check nomigrate-derived bash -c '[ -n "$1" ] && [ -n "$2" ]' _ "$derived_map" "$derived_pm"
314
+ run "$R" -- config upgrade-models --task-models "$derived_map" --pm-model "$derived_pm" --dry-run
315
+ check nomigrate-pasted-dryrun eq "$RC" 0
316
+ check nomigrate-pasted-dryrun-pure eq "$(sha "$R/.pi/team/config.sh")" "$ORIG_SHA"
317
+
318
+ # F1(V40 返修):三种「推导停住」的形状都必须给**占位符路线**,不是推导命令 —— 返修的起因就是这里
319
+ # 文档说错了一半(拒绝一律给推导命令)。每条形状:拒绝 + 点名障碍 + 占位符 + 没有 `dev=` 推导映射。
320
+ SHAPE_KEEP="$R/.pi/team/config.sh.keep"; cp -p "$R/.pi/team/config.sh" "$SHAPE_KEEP"
321
+ shape_refusal() { # <名字> <sed 表达式>
322
+ sed -i "$2" "$R/.pi/team/config.sh"
323
+ local after_sed; after_sed="$(sha "$R/.pi/team/config.sh")"
324
+ run "$R" -- up --print
325
+ local log="$TMP/refusal-$1.log"; capture "$log"
326
+ check "refusal-$1-rejected" bash -c '[ "$1" != 0 ]' _ "$RC"
327
+ check "refusal-$1-names-obstacle" contains "$OUT" '启动迁移拒绝'
328
+ check "refusal-$1-placeholder" contains "$OUT" "--pm-model '<独立模型>'"
329
+ check "refusal-$1-no-complete-map" not complete_map_line "$log"
330
+ check "refusal-$1-pure" eq "$(sha "$R/.pi/team/config.sh")" "$after_sed"
331
+ cp -p "$SHAPE_KEEP" "$R/.pi/team/config.sh"
332
+ }
333
+ shape_refusal not-locatable 's|^TEAM_DEFAULT_MODEL=.*$|TEAM_DEFAULT_MODEL="${MISSING:-vendor/base}"|'
334
+ shape_refusal fallback-collision "s|^TEAM_AGENT_MODELS=.*|TEAM_AGENT_MODELS='default=vendor/light'|"
335
+ shape_refusal invalid-value "s|^TEAM_AGENT_MODELS=.*|TEAM_AGENT_MODELS='dev=vendor/light verify=not-a-model'|"
336
+ check refusal-shape-restored eq "$(sha "$R/.pi/team/config.sh")" "$ORIG_SHA"
337
+ # 部分推导:非法值那一条保留已推出的对(dev=…),非法的那一对用占位符 —— 正是文档承诺的形态。
338
+ check refusal-invalid-value-partial-marker grep -qF -- '<非法那一对用占位符>' "$TMP/refusal-invalid-value.log"
339
+ check refusal-invalid-value-keeps-resolved grep -qF -- 'dev=vendor/light' "$TMP/refusal-invalid-value.log"
340
+ rm -f "$SHAPE_KEEP"
341
+
342
+ # 配方第 2 步:先备份配置,再让第一次 team up 自己迁移(私有 tmux + 假 PM,绝不碰共享 server)。
343
+ cp -p "$R/.pi/team/config.sh" "$R/.pi/team/config.sh.pre-upgrade"
344
+ check backup-copy eq "$(sha "$R/.pi/team/config.sh.pre-upgrade")" "$ORIG_SHA"
345
+ if command -v tmux >/dev/null 2>&1; then
346
+ LIVE_SOCKET="recipe-${BASHPID}-${RANDOM}"
347
+ # P309:socket 基址要短(见 tmp-root.sh 的 tmp_root_socket_dir);放不下才退回临时根下
348
+ TMUX_TMPDIR="$(tmp_root_socket_dir tmux "tmux-$(id -u)/default")" || TMUX_TMPDIR="$TMP/tmux"
349
+ export TMUX_TMPDIR; mkdir -p "$TMUX_TMPDIR"
350
+ REAL_TMUX="$(command -v tmux)"
351
+ printf '#!/usr/bin/env bash\nexec %q -L %q "$@"\n' "$REAL_TMUX" "$LIVE_SOCKET" > "$BIN/tmux"
352
+ chmod +x "$BIN/tmux"
353
+ export PATH="$BIN:$PATH"
354
+ tmux_iso_require recipe launch --tmpdir "$TMUX_TMPDIR" --sock-name "$LIVE_SOCKET" --own-root "$TMP" --own-root "$TMUX_TMPDIR"
355
+ run "$R" -- up
356
+ UP_REAL="$TMP/up-real.log"; capture "$UP_REAL"
357
+ check auto-migrate-rc eq "$RC" 0
358
+ check auto-migrate-pairs contains "$OUT" 'TEAM_AGENT_MODELS verify=vendor/strong:high → TEAM_TASK_MODELS verify=vendor/strong:high'
359
+ check auto-migrate-backup-line contains "$OUT" '备份:'
360
+ check auto-migrate-restore-line contains "$OUT" '还原:cp '
361
+ check auto-migrate-commit contains "$OUT" 'committed: before='
362
+ check auto-migrate-registration contains "$OUT" \
363
+ '已登记本次启动身份:model=vendor/pm:high resume_key=default mode=continued'
364
+ check auto-migrate-task-models grep -qxF \
365
+ "TEAM_TASK_MODELS='dev=vendor/light verify=vendor/strong:high default=vendor/base'" "$R/.pi/team/config.sh"
366
+ check auto-migrate-shape-number grep -qxF "TEAM_CONFIG_VERSION='2'" "$R/.pi/team/config.sh"
367
+ check auto-migrate-retired-gone bash -c '! grep -qE "^TEAM_(AGENT_MODELS|DEFAULT_MODEL)=" "$1"' _ "$R/.pi/team/config.sh"
368
+ check auto-migrate-backup-count eq \
369
+ "$(find "$R/.pi/team/state/config-backups" -maxdepth 1 -type f -name 'config.sh.pre-*' | wc -l | tr -d ' ')" 1
370
+ check auto-migrate-backup-bytes bash -c 'cmp -s "$1" "$2"' _ \
371
+ "$(find "$R/.pi/team/state/config-backups" -maxdepth 1 -type f -name 'config.sh.pre-*' | head -1)" \
372
+ "$R/.pi/team/config.sh.pre-upgrade"
373
+ check auto-migrate-audit contains "$(tail -1 "$R/.pi/team/state/config.log")" 'actor=up-migration'
374
+ check auto-migrate-record bash -c 'grep -qx "model=vendor/pm:high" "$1" && grep -qx "mode=continued" "$1"' _ \
375
+ "$R/.pi/team/state/pm-launch.env"
376
+ # F2(V40 返修):`team up` 只起 PM;巡检窗口(pulse)不在它的产物里 —— 建它的是 `team pulse up`。
377
+ UP_WINDOWS="$("$REAL_TMUX" -L "$LIVE_SOCKET" list-windows -t recipe-fixture -F '#{window_name}' 2>/dev/null || true)"
378
+ check up-creates-pm-window contains "$UP_WINDOWS" 'pm'
379
+ check up-leaves-pulse-to-pulse-up bash -c '! grep -qx -- pulse <<<"$1"' _ "$UP_WINDOWS"
380
+ else
381
+ printf 'SKIP auto-route(本机没有 tmux:真 up 的自动迁移子用例跳过;预览 / 拒绝 / 手工路线仍然跑)\n'
382
+ fi
383
+
384
+ # 迁移后:config list rc=0 且不再要求迁移;doctor 绿;dispatch --print 证明 category 解析生效。
385
+ run "$R" -- config list
386
+ CONFIG_LIST="$TMP/config-list.log"; capture "$CONFIG_LIST"
387
+ check config-list-rc eq "$RC" 0
388
+ check config-list-task-models contains "$OUT" 'TEAM_TASK_MODELS'
389
+ check config-list-no-migration bash -c '! grep -qF "migration_required" "$1"' _ "$CONFIG_LIST"
390
+ run "$R" -- doctor
391
+ DOCTOR="$TMP/doctor.log"; capture "$DOCTOR"
392
+ check doctor-rc eq "$RC" 0
393
+ run "$R" -- version
394
+ VERSION="$TMP/version.log"; capture "$VERSION"
395
+ check version-rc eq "$RC" 0
396
+ run "$R" -- dispatch dev H1 docs/team/tasks/H1-fixture.md --print
397
+ DISPATCH="$TMP/dispatch.log"; capture "$DISPATCH"
398
+ check dispatch-rc eq "$RC" 0
399
+ check dispatch-category contains "$OUT" 'category=default model=vendor/base'
400
+
401
+ # ② 文档承诺 → 工具兑现(“文档写了但工具不做”就在这里红)。
402
+ promise preview-migration 'team up --print' "$UP_PRINT_OLD" '检测到旧形状配置'
403
+ promise preview-restore 'cp "<the backup path the migration printed>"' "$UP_PRINT_OLD" '还原:cp '
404
+ promise nomigrate-pastable 'team config upgrade-models' "$UP_NOMIGRATE" 'config upgrade-models'
405
+ if [ -n "$UP_REAL" ]; then
406
+ promise registration 'state/pm-launch.env' "$UP_REAL" \
407
+ '已登记本次启动身份:model=vendor/pm:high resume_key=default mode=continued'
408
+ else
409
+ printf 'SKIP doc-promise:registration(自动迁移子用例跳过:没有 tmux,登记行不产生)\n'
410
+ fi
411
+ promise config-list-clean 'team config list' "$CONFIG_LIST" 'TEAM_TASK_MODELS'
412
+ promise dispatch-category 'team dispatch --print' "$DISPATCH" 'category=default model=vendor/base'
413
+ promise version-line 'team version' "$VERSION" 'teamsmith '
414
+ # F1:文档承诺的两种形态必须在工具输出里成对成立(推导停住 → **未填**的映射,而不是推导命令)。
415
+ # 两侧都不依赖语言:文档侧的字面是 `placeholder route`;工具侧的判据是「`--task-models` 的引号里
416
+ # 以 `<` 开头」——推导命令的值是 `dev=…`,占位符路线的值以占位符开头,两者一眼可分。
417
+ promise refusal-placeholder-route 'placeholder route' "$TMP/refusal-fallback-collision.log" \
418
+ "upgrade-models --task-models '<"
419
+ fi
420
+
421
+ # ── ③ 现场:PM 启动身份(缺记录 / 记录不符 / --fresh-pm)──────────────────────────────────
422
+ if has identity; then
423
+ # 记录与解析一致 → 完整预览 + continued 判定;迁移预告不再出现。
424
+ run "$R" -- up --print
425
+ UP_CONT="$TMP/up-continued.log"; capture "$UP_CONT"
426
+ check identity-matches-rc eq "$RC" 0
427
+ check identity-matches-line contains "$OUT" '身份预告:记录与当前解析一致'
428
+ check identity-continued-verdict contains "$OUT" '会话判定:continued:pi -c(本目录上一个会话)'
429
+ check identity-complete-command contains "$OUT" '完整命令:'
430
+ check identity-continued-has-c contains "$(cmd_line "$UP_CONT")" ' -c '
431
+ check identity-no-migration-preview bash -c '! grep -qF "检测到旧形状配置" "$1"' _ "$UP_CONT"
432
+
433
+ # --fresh-pm → 这一次新开会话(不带 -c);记录一个字节都不动。
434
+ REC0="$(sha "$R/.pi/team/state/pm-launch.env")"
435
+ run "$R" -- up --print --fresh-pm
436
+ UP_FRESH="$TMP/up-fresh.log"; capture "$UP_FRESH"
437
+ check identity-fresh-rc eq "$RC" 0
438
+ check identity-fresh-verdict contains "$OUT" '会话判定:fresh:--fresh-pm'
439
+ check identity-fresh-no-c bash -c '! grep -qF -- " -c " <<<"$(grep -F "完整命令:" "$1" | head -1)"' _ "$UP_FRESH"
440
+ check identity-fresh-record-untouched eq "$(sha "$R/.pi/team/state/pm-launch.env")" "$REC0"
441
+
442
+ # 记录存在但与现在解析不一致 → 拒绝,并点名两条出路;记录不动。
443
+ sed -i "s|^TEAM_PM_MODEL='vendor/pm:high'|TEAM_PM_MODEL='vendor/pm:other'|" "$R/.pi/team/config.sh"
444
+ run "$R" -- up --print
445
+ UP_MISMATCH="$TMP/up-mismatch.log"; capture "$UP_MISMATCH"
446
+ check identity-mismatch-refused bash -c '[ "$1" != 0 ]' _ "$RC"
447
+ check identity-mismatch-named contains "$OUT" 'PM launch identity changed'
448
+ check identity-mismatch-exit1 contains "$OUT" '出路 ①'
449
+ check identity-mismatch-exit1-cmd contains "$OUT" '--fresh-pm'
450
+ check identity-mismatch-exit2 contains "$OUT" '出路 ②'
451
+ check identity-mismatch-exit2-cmd contains "$OUT" '--adopt-pm-identity --yes'
452
+ check identity-mismatch-record-pure eq "$(sha "$R/.pi/team/state/pm-launch.env")" "$REC0"
453
+ sed -i "s|^TEAM_PM_MODEL='vendor/pm:other'|TEAM_PM_MODEL='vendor/pm:high'|" "$R/.pi/team/config.sh"
454
+
455
+ # 0.1.x 升上来的项目就是缺这条记录:--print 预告「会登记」,且不预写文件。
456
+ mv "$R/.pi/team/state/pm-launch.env" "$TMP/pm-launch.saved"
457
+ run "$R" -- up --print
458
+ UP_NOREC="$TMP/up-norecord.log"; capture "$UP_NOREC"
459
+ check identity-missing-rc eq "$RC" 0
460
+ check identity-missing-will-register contains "$OUT" '身份预告:此前没有启动记录'
461
+ check identity-missing-line contains "$OUT" '这次启动会登记 model=vendor/pm:high resume_key=default mode=continued'
462
+ check identity-missing-not-precreated bash -c '[ ! -e "$1" ]' _ "$R/.pi/team/state/pm-launch.env"
463
+ mv "$TMP/pm-launch.saved" "$R/.pi/team/state/pm-launch.env"
464
+
465
+ # 承诺 → 工具:两条出路与 fresh 判定都真的打出来。
466
+ promise identity-mismatch-exits '--adopt-pm-identity' "$UP_MISMATCH" '--adopt-pm-identity --yes'
467
+ promise fresh-verdict '--fresh-pm' "$UP_FRESH" '会话判定:fresh:--fresh-pm'
468
+ promise missing-record 'state/pm-launch.env' "$UP_NOREC" '身份预告:此前没有启动记录'
469
+ fi
470
+
471
+ # ── ③ 现场:回滚(配置回 cp 备份;旧形状复现)──────────────────────────────────────────────
472
+ if has rollback; then
473
+ cp -p "$R/.pi/team/config.sh.pre-upgrade" "$R/.pi/team/config.sh"
474
+ check rollback-bytes eq "$(sha "$R/.pi/team/config.sh")" "$ORIG_SHA"
475
+ run "$R" -- config list
476
+ ROLLBACK_LIST="$TMP/rollback-list.log"; capture "$ROLLBACK_LIST"
477
+ check rollback-rc eq "$RC" 0
478
+ check rollback-shape-back contains "$OUT" 'migration_required'
479
+ promise rollback-shape 'migration_required' "$ROLLBACK_LIST" 'migration_required'
480
+ fi
481
+
482
+ # ── ① 红侧:删掉 §6 的任一步 → 文档面必须红(探针不是恒真)────────────────────────────────
483
+ if has selftest; then
484
+ SB="$TMP/selftest"; mkdir -p "$SB"
485
+ cp "$DOC" "$SB/migration.md"
486
+ check selftest-green doc_coverage_check "$SB/migration.md"
487
+
488
+ # 删掉 §6 的一步 → 文档面必须红,并点名缺的那一步
489
+ sed -i '/team up --no-migrate/d' "$SB/migration.md"
490
+ check selftest-red-missing-step not doc_coverage_check "$SB/migration.md"
491
+ check selftest-names-the-step eq "$(doc_missing "$SB/migration.md" | head -1)" 'team up --no-migrate'
492
+ cp "$DOC" "$SB/migration.md"
493
+ check selftest-restored doc_coverage_check "$SB/migration.md"
494
+
495
+ # 再删一步(工具升级)→ 同样红(不是只钉住某一行)
496
+ sed -i '/npm i -g teamsmith@/d' "$SB/migration.md"
497
+ check selftest-red-tool-upgrade not doc_coverage_check "$SB/migration.md"
498
+ cp "$DOC" "$SB/migration.md"
499
+ check selftest-restored-2 doc_coverage_check "$SB/migration.md"
500
+
501
+ # F1/F2 的两条新断言也必须能红:把承诺句子删掉 → 文档面红,且 doc_missing 点名缺的是它们。
502
+ sed -i '/placeholder route/d; /team pulse up/d' "$SB/migration.md"
503
+ F1F2_MISSING="$(doc_missing "$SB/migration.md")"
504
+ check selftest-red-f1f2 not doc_coverage_check "$SB/migration.md"
505
+ check selftest-red-f1f2-names contains "$F1F2_MISSING" 'placeholder route'
506
+ check selftest-red-f1f2-names-pulse contains "$F1F2_MISSING" 'team pulse up'
507
+ cp "$DOC" "$SB/migration.md"
508
+ check selftest-restored-3 doc_coverage_check "$SB/migration.md"
509
+
510
+ # F3(V40 第二轮):把 §6 里 `--no-migrate` 那句换回旧的无条件承诺(“推导出来的命令”)→ 文档面必须
511
+ # 两侧都红:正向 needle 丢失(doc_missing 点名它)+ 禁列短语命中(doc_forbidden_hits 点名它)。
512
+ awk '/is the same promise from the other side:/{print;
513
+ print "it refuses, writes nothing, and prints the manual command derived from *your* configuration.";
514
+ drop=1; next}
515
+ drop && /the placeholder route when it is not\./{drop=0; next}
516
+ drop{next}
517
+ {print}' "$DOC" > "$SB/migration.md"
518
+ check selftest-red-f3 not doc_coverage_check "$SB/migration.md"
519
+ F3_MISSING="$(doc_missing "$SB/migration.md")"
520
+ check selftest-red-f3-needle contains "$F3_MISSING" 'whichever of the two command forms'
521
+ check selftest-red-f3-forbidden not doc_forbidden_check "$SB/migration.md"
522
+ check selftest-red-f3-names eq "$(doc_forbidden_hits "$SB/migration.md" | head -1)" 'manual command derived'
523
+ cp "$DOC" "$SB/migration.md"
524
+ check selftest-restored-f3 doc_coverage_check "$SB/migration.md"
525
+ check selftest-restored-f3-forbidden doc_forbidden_check "$SB/migration.md"
526
+
527
+ # 承诺探针的反向对照(自带的合成工具输出,不依赖 walk 组是否跑过):
528
+ # ① 文档承诺了、工具输出里没有 → 红;② 文档根本没承诺 → 红;③ 两半都在 → 绿。
529
+ printf 'teamsmith 0.2.0\nno restore line here\n' > "$SB/tool-output.txt"
530
+ check selftest-promise-positive promise_check 'team version' "$SB/tool-output.txt" 'teamsmith '
531
+ check selftest-promise-negative promise_red 'team up --print' "$SB/tool-output.txt" '还原:cp '
532
+ check selftest-promise-negative-doc promise_red 'THIS STRING IS NOT IN THE GUIDE' "$SB/tool-output.txt" 'teamsmith '
533
+ fi
534
+
535
+ printf '\nRESULT pass=%d fail=%d\n' "$PASS" "$FAIL"
536
+ [ "$FAIL" -eq 0 ] || exit 1
537
+ exit 0