teamsmith 0.0.0-stage → 0.1.2

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 (245) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +158 -2
  3. package/bin/team.mjs +59 -0
  4. package/install.sh +94 -0
  5. package/package.json +37 -4
  6. package/skills/teamsmith/CHANGELOG.md +763 -0
  7. package/skills/teamsmith/SKILL.md +312 -0
  8. package/skills/teamsmith/extension/team-bg.ts +435 -0
  9. package/skills/teamsmith/extension/team-inbox-watch.ts +1412 -0
  10. package/skills/teamsmith/extension/team-notify.ts +663 -0
  11. package/skills/teamsmith/references/agent-adapters.md +643 -0
  12. package/skills/teamsmith/references/config.md +477 -0
  13. package/skills/teamsmith/references/meeting.md +124 -0
  14. package/skills/teamsmith/references/memory.md +133 -0
  15. package/skills/teamsmith/references/migration.md +227 -0
  16. package/skills/teamsmith/references/openspec.md +222 -0
  17. package/skills/teamsmith/references/philosophy.md +95 -0
  18. package/skills/teamsmith/references/protocol.md +712 -0
  19. package/skills/teamsmith/references/troubleshooting.md +1384 -0
  20. package/skills/teamsmith/references/workflows.md +448 -0
  21. package/skills/teamsmith/scripts/lib/cmd-agents.sh +1709 -0
  22. package/skills/teamsmith/scripts/lib/cmd-bg.sh +284 -0
  23. package/skills/teamsmith/scripts/lib/cmd-bootstrap.sh +311 -0
  24. package/skills/teamsmith/scripts/lib/cmd-config.sh +1156 -0
  25. package/skills/teamsmith/scripts/lib/cmd-death.sh +562 -0
  26. package/skills/teamsmith/scripts/lib/cmd-docs.sh +149 -0
  27. package/skills/teamsmith/scripts/lib/cmd-draft.sh +124 -0
  28. package/skills/teamsmith/scripts/lib/cmd-init.sh +212 -0
  29. package/skills/teamsmith/scripts/lib/cmd-meeting.sh +904 -0
  30. package/skills/teamsmith/scripts/lib/cmd-outbox.sh +196 -0
  31. package/skills/teamsmith/scripts/lib/cmd-project.sh +642 -0
  32. package/skills/teamsmith/scripts/lib/cmd-review.sh +1393 -0
  33. package/skills/teamsmith/scripts/lib/cmd-status.sh +1399 -0
  34. package/skills/teamsmith/scripts/lib/cmd-update.sh +191 -0
  35. package/skills/teamsmith/scripts/lib/cmd-watch.sh +1681 -0
  36. package/skills/teamsmith/scripts/lib/common.sh +4964 -0
  37. package/skills/teamsmith/scripts/lib/draft-entry.sh +51 -0
  38. package/skills/teamsmith/scripts/lib/outbox.sh +2042 -0
  39. package/skills/teamsmith/scripts/lib/tmux-argv.sh +165 -0
  40. package/skills/teamsmith/scripts/monitor.mjs +616 -0
  41. package/skills/teamsmith/scripts/panel/README.md +192 -0
  42. package/skills/teamsmith/scripts/panel/build.sh +47 -0
  43. package/skills/teamsmith/scripts/panel/bun.lock +109 -0
  44. package/skills/teamsmith/scripts/panel/draft-send.sh +68 -0
  45. package/skills/teamsmith/scripts/panel/package.json +24 -0
  46. package/skills/teamsmith/scripts/panel/panel.js +388 -0
  47. package/skills/teamsmith/scripts/panel/src/App.tsx +2150 -0
  48. package/skills/teamsmith/scripts/panel/src/clipboard.ts +154 -0
  49. package/skills/teamsmith/scripts/panel/src/compose.ts +691 -0
  50. package/skills/teamsmith/scripts/panel/src/data.ts +555 -0
  51. package/skills/teamsmith/scripts/panel/src/format.ts +50 -0
  52. package/skills/teamsmith/scripts/panel/src/layout.ts +2562 -0
  53. package/skills/teamsmith/scripts/panel/src/main.tsx +894 -0
  54. package/skills/teamsmith/scripts/panel/src/markdown.ts +340 -0
  55. package/skills/teamsmith/scripts/panel/src/sanitize.ts +42 -0
  56. package/skills/teamsmith/scripts/panel/src/settings.ts +154 -0
  57. package/skills/teamsmith/scripts/panel/src/strings/en.ts +416 -0
  58. package/skills/teamsmith/scripts/panel/src/strings/index.ts +65 -0
  59. package/skills/teamsmith/scripts/panel/src/strings/types.ts +9 -0
  60. package/skills/teamsmith/scripts/panel/src/strings/zh.ts +414 -0
  61. package/skills/teamsmith/scripts/panel/src/theme.ts +116 -0
  62. package/skills/teamsmith/scripts/panel/src/types.ts +652 -0
  63. package/skills/teamsmith/scripts/panel/src/width.ts +105 -0
  64. package/skills/teamsmith/scripts/panel/tsconfig.json +16 -0
  65. package/skills/teamsmith/scripts/shim/signal-gate +156 -0
  66. package/skills/teamsmith/scripts/shim/tmux +403 -0
  67. package/skills/teamsmith/scripts/team +143 -0
  68. package/skills/teamsmith/templates/AGENTS.section.md.tmpl +147 -0
  69. package/skills/teamsmith/templates/BOARD.md.tmpl +18 -0
  70. package/skills/teamsmith/templates/DECISIONS.md.tmpl +22 -0
  71. package/skills/teamsmith/templates/OWNERSHIP.md.tmpl +25 -0
  72. package/skills/teamsmith/templates/PROTOCOL.md.tmpl +84 -0
  73. package/skills/teamsmith/templates/ROADMAP.md.tmpl +29 -0
  74. package/skills/teamsmith/templates/config.sh.tmpl +106 -0
  75. package/skills/teamsmith/templates/memory-seed.md.tmpl +46 -0
  76. package/skills/teamsmith/templates/pm-prompt.md.tmpl +110 -0
  77. package/skills/teamsmith/templates/report.md.tmpl +36 -0
  78. package/skills/teamsmith/templates/task.md.tmpl +65 -0
  79. package/skills/teamsmith/templates/threads-README.md +17 -0
  80. package/skills/teamsmith/tests/bg-ledger-harness.mjs +682 -0
  81. package/skills/teamsmith/tests/bg-ledger.sh +307 -0
  82. package/skills/teamsmith/tests/checkout-shape-probe.sh +800 -0
  83. package/skills/teamsmith/tests/config-cli.sh +1562 -0
  84. package/skills/teamsmith/tests/container-tmux.sh +493 -0
  85. package/skills/teamsmith/tests/coverage-inventory.sh +173 -0
  86. package/skills/teamsmith/tests/death-cause.sh +564 -0
  87. package/skills/teamsmith/tests/delivery-truth.sh +1231 -0
  88. package/skills/teamsmith/tests/fake-tui.py +450 -0
  89. package/skills/teamsmith/tests/fixtures/delivery-truth-real/README.md +60 -0
  90. package/skills/teamsmith/tests/fixtures/delivery-truth-real/judge-second.py +139 -0
  91. package/skills/teamsmith/tests/fixtures/delivery-truth-real/mock-server.py +29 -0
  92. package/skills/teamsmith/tests/fixtures/delivery-truth-real/observe.ts +20 -0
  93. package/skills/teamsmith/tests/fixtures/delivery-truth-real/run-case.sh +79 -0
  94. package/skills/teamsmith/tests/fixtures/delivery-truth-real/scenario.sh +175 -0
  95. package/skills/teamsmith/tests/fixtures/p55/flip-p49.sh +229 -0
  96. package/skills/teamsmith/tests/fixtures/p71-incident/README.md +22 -0
  97. package/skills/teamsmith/tests/fixtures/p71-incident/dev2.seen +8 -0
  98. package/skills/teamsmith/tests/fixtures/p71-incident/dev2.wake +9 -0
  99. package/skills/teamsmith/tests/fixtures/p71-incident/pm-nudges.wake +3 -0
  100. package/skills/teamsmith/tests/fixtures/signal-lint-cases.txt +40 -0
  101. package/skills/teamsmith/tests/flip-glue.sh +162 -0
  102. package/skills/teamsmith/tests/flip-m12-26c.sh +129 -0
  103. package/skills/teamsmith/tests/flip-m12.sh +185 -0
  104. package/skills/teamsmith/tests/flip-m16.sh +166 -0
  105. package/skills/teamsmith/tests/flip-m17.sh +204 -0
  106. package/skills/teamsmith/tests/flip-m33.sh +284 -0
  107. package/skills/teamsmith/tests/flip-m34.sh +96 -0
  108. package/skills/teamsmith/tests/flip-m37.sh +185 -0
  109. package/skills/teamsmith/tests/flip-m4.3.sh +375 -0
  110. package/skills/teamsmith/tests/flip-m43.sh +128 -0
  111. package/skills/teamsmith/tests/flip-m44.sh +262 -0
  112. package/skills/teamsmith/tests/flip-m45.sh +244 -0
  113. package/skills/teamsmith/tests/flip-m46.sh +238 -0
  114. package/skills/teamsmith/tests/flip-m48.sh +304 -0
  115. package/skills/teamsmith/tests/flip-m6.2.sh +205 -0
  116. package/skills/teamsmith/tests/flip-m6.3.sh +283 -0
  117. package/skills/teamsmith/tests/flip-m6.4.sh +267 -0
  118. package/skills/teamsmith/tests/flip-m6.5.sh +113 -0
  119. package/skills/teamsmith/tests/flip-m7.1.sh +135 -0
  120. package/skills/teamsmith/tests/flip-m7.2.sh +321 -0
  121. package/skills/teamsmith/tests/flip-p144.sh +112 -0
  122. package/skills/teamsmith/tests/flip-p156.sh +133 -0
  123. package/skills/teamsmith/tests/flip-p158.sh +301 -0
  124. package/skills/teamsmith/tests/flip-p160.sh +182 -0
  125. package/skills/teamsmith/tests/flip-p171.sh +249 -0
  126. package/skills/teamsmith/tests/flip-p18.1.sh +95 -0
  127. package/skills/teamsmith/tests/flip-p20.sh +286 -0
  128. package/skills/teamsmith/tests/flip-p201.sh +249 -0
  129. package/skills/teamsmith/tests/flip-p210.sh +239 -0
  130. package/skills/teamsmith/tests/flip-p211.sh +152 -0
  131. package/skills/teamsmith/tests/flip-p217.sh +288 -0
  132. package/skills/teamsmith/tests/flip-p22.sh +123 -0
  133. package/skills/teamsmith/tests/flip-p23.sh +239 -0
  134. package/skills/teamsmith/tests/flip-p25.sh +165 -0
  135. package/skills/teamsmith/tests/flip-p71.sh +184 -0
  136. package/skills/teamsmith/tests/flip-p72.sh +202 -0
  137. package/skills/teamsmith/tests/frames/README.md +176 -0
  138. package/skills/teamsmith/tests/frames/p78-conversation-rule-below-box.txt +6 -0
  139. package/skills/teamsmith/tests/frames/p78-cursor-mid-draft.txt +6 -0
  140. package/skills/teamsmith/tests/frames/p78-draft-rule-below-cursor-line.txt +6 -0
  141. package/skills/teamsmith/tests/frames/p78-draft-rule-below-cursor.txt +6 -0
  142. package/skills/teamsmith/tests/frames/p78-draft-rule-blank-region.txt +6 -0
  143. package/skills/teamsmith/tests/frames/p78-draft-rule-only.txt +5 -0
  144. package/skills/teamsmith/tests/frames/p78-spinner-row-below-cursor.txt +6 -0
  145. package/skills/teamsmith/tests/frames/p78-wider-rule-below-cursor.txt +6 -0
  146. package/skills/teamsmith/tests/frames/p86-f1-mixed-width-disjoint-box.txt +8 -0
  147. package/skills/teamsmith/tests/frames/p86-f1-narrower-width-disjoint-box.txt +8 -0
  148. package/skills/teamsmith/tests/frames/p86-f1-spinner-top-disjoint-box.txt +8 -0
  149. package/skills/teamsmith/tests/frames/pi-0.85.1-update-banner.txt +30 -0
  150. package/skills/teamsmith/tests/frames/pi-0.87.0-draft-half-sentence.txt +30 -0
  151. package/skills/teamsmith/tests/frames/pi-0.87.0-empty-box.txt +30 -0
  152. package/skills/teamsmith/tests/frames/pi-0.87.0-one-line-draft.txt +30 -0
  153. package/skills/teamsmith/tests/frames/pi-0.87.0-project-trust-prompt.txt +30 -0
  154. package/skills/teamsmith/tests/frames/pi-0.99.2-empty-editor.txt +32 -0
  155. package/skills/teamsmith/tests/frames/pi-0.99.2-human-draft.txt +32 -0
  156. package/skills/teamsmith/tests/frames/pi-1.0.0-git-error-in-box.txt +32 -0
  157. package/skills/teamsmith/tests/gate-guard.sh +112 -0
  158. package/skills/teamsmith/tests/guard-matrix.sh +233 -0
  159. package/skills/teamsmith/tests/install-shape.sh +731 -0
  160. package/skills/teamsmith/tests/ledger-ban.sh +612 -0
  161. package/skills/teamsmith/tests/lib/box-judge.sh +68 -0
  162. package/skills/teamsmith/tests/lib/checkout-shape.sh +129 -0
  163. package/skills/teamsmith/tests/lib/loop-scan.awk +114 -0
  164. package/skills/teamsmith/tests/lib/pty-wait.sh +676 -0
  165. package/skills/teamsmith/tests/lib/section-guard.sh +855 -0
  166. package/skills/teamsmith/tests/lib/shell-lex.pl +261 -0
  167. package/skills/teamsmith/tests/lib/tmp-root.sh +528 -0
  168. package/skills/teamsmith/tests/lib/tmux-cap.sh +35 -0
  169. package/skills/teamsmith/tests/lib/tmux-iso-call-probe.sh +81 -0
  170. package/skills/teamsmith/tests/lib/tmux-iso-probe.sh +46 -0
  171. package/skills/teamsmith/tests/lib/tmux-iso.sh +381 -0
  172. package/skills/teamsmith/tests/load-experiment.sh +290 -0
  173. package/skills/teamsmith/tests/loop-inventory.tsv +84 -0
  174. package/skills/teamsmith/tests/panel-b2-slow-stub.sh +19 -0
  175. package/skills/teamsmith/tests/panel-b2.sh +1183 -0
  176. package/skills/teamsmith/tests/panel-b3-pty-mouse.py +240 -0
  177. package/skills/teamsmith/tests/panel-b3-pty-tmux-mouse.py +138 -0
  178. package/skills/teamsmith/tests/panel-b3-stub.sh +279 -0
  179. package/skills/teamsmith/tests/panel-b3.sh +1301 -0
  180. package/skills/teamsmith/tests/panel-choices.sh +572 -0
  181. package/skills/teamsmith/tests/panel-clipboard-model.ts +187 -0
  182. package/skills/teamsmith/tests/panel-compose-model.ts +290 -0
  183. package/skills/teamsmith/tests/panel-contrast.mjs +81 -0
  184. package/skills/teamsmith/tests/panel-cpu-premise.sh +173 -0
  185. package/skills/teamsmith/tests/panel-cpu.sh +391 -0
  186. package/skills/teamsmith/tests/panel-flip-m54.sh +207 -0
  187. package/skills/teamsmith/tests/panel-flip-p123.sh +278 -0
  188. package/skills/teamsmith/tests/panel-flip-p125.sh +318 -0
  189. package/skills/teamsmith/tests/panel-flip-p128.sh +259 -0
  190. package/skills/teamsmith/tests/panel-keyprobe-pty.py +99 -0
  191. package/skills/teamsmith/tests/panel-keyprobe-stub.sh +41 -0
  192. package/skills/teamsmith/tests/panel-keyprobe.sh +82 -0
  193. package/skills/teamsmith/tests/panel-keyprobe.tsx +116 -0
  194. package/skills/teamsmith/tests/panel-knobs.sh +83 -0
  195. package/skills/teamsmith/tests/panel-p21.sh +2181 -0
  196. package/skills/teamsmith/tests/panel-snapshots.sh +802 -0
  197. package/skills/teamsmith/tests/panel-strings.mjs +195 -0
  198. package/skills/teamsmith/tests/perf.sh +740 -0
  199. package/skills/teamsmith/tests/pm-box-real.sh +350 -0
  200. package/skills/teamsmith/tests/pulse-nudge-key.sh +563 -0
  201. package/skills/teamsmith/tests/routes.sh +1652 -0
  202. package/skills/teamsmith/tests/section-budgets.tsv +150 -0
  203. package/skills/teamsmith/tests/section-guard.sh +231 -0
  204. package/skills/teamsmith/tests/section-needs-audit.sh +94 -0
  205. package/skills/teamsmith/tests/section-paths.tsv +142 -0
  206. package/skills/teamsmith/tests/section-select.sh +655 -0
  207. package/skills/teamsmith/tests/signal-gate.sh +366 -0
  208. package/skills/teamsmith/tests/signal-lint-legacy.txt +14 -0
  209. package/skills/teamsmith/tests/signal-lint.pl +416 -0
  210. package/skills/teamsmith/tests/skill-load.mjs +65 -0
  211. package/skills/teamsmith/tests/smoke.sh +19711 -0
  212. package/skills/teamsmith/tests/snapshots/zh-dark-120-detail.txt +32 -0
  213. package/skills/teamsmith/tests/snapshots/zh-dark-120-p4.txt +32 -0
  214. package/skills/teamsmith/tests/snapshots/zh-dark-120.txt +32 -0
  215. package/skills/teamsmith/tests/snapshots/zh-dark-160-p4.txt +32 -0
  216. package/skills/teamsmith/tests/snapshots/zh-dark-160.txt +32 -0
  217. package/skills/teamsmith/tests/snapshots/zh-dark-59-detail.txt +32 -0
  218. package/skills/teamsmith/tests/snapshots/zh-dark-59-p4.txt +32 -0
  219. package/skills/teamsmith/tests/snapshots/zh-dark-59.txt +32 -0
  220. package/skills/teamsmith/tests/snapshots/zh-dark-99-p4.txt +32 -0
  221. package/skills/teamsmith/tests/snapshots/zh-dark-99.txt +32 -0
  222. package/skills/teamsmith/tests/snapshots/zh-light-120-detail.txt +32 -0
  223. package/skills/teamsmith/tests/snapshots/zh-light-120-p4.txt +32 -0
  224. package/skills/teamsmith/tests/snapshots/zh-light-120.txt +32 -0
  225. package/skills/teamsmith/tests/snapshots/zh-light-160-p4.txt +32 -0
  226. package/skills/teamsmith/tests/snapshots/zh-light-160.txt +32 -0
  227. package/skills/teamsmith/tests/snapshots/zh-light-59-detail.txt +32 -0
  228. package/skills/teamsmith/tests/snapshots/zh-light-59-p4.txt +32 -0
  229. package/skills/teamsmith/tests/snapshots/zh-light-59.txt +32 -0
  230. package/skills/teamsmith/tests/snapshots/zh-light-99-p4.txt +32 -0
  231. package/skills/teamsmith/tests/snapshots/zh-light-99.txt +32 -0
  232. package/skills/teamsmith/tests/spec-ledger-refs.tsv +78 -0
  233. package/skills/teamsmith/tests/spec-refs.sh +826 -0
  234. package/skills/teamsmith/tests/task-header-model.sh +267 -0
  235. package/skills/teamsmith/tests/team-bg-flip.sh +239 -0
  236. package/skills/teamsmith/tests/team-bg-harness.mjs +392 -0
  237. package/skills/teamsmith/tests/team-bg-stop.sh +434 -0
  238. package/skills/teamsmith/tests/team-inbox-watch-flip.sh +191 -0
  239. package/skills/teamsmith/tests/team-inbox-watch-harness.mjs +1559 -0
  240. package/skills/teamsmith/tests/tmp-hygiene.sh +1190 -0
  241. package/skills/teamsmith/tests/tmux-lint-legacy.txt +31 -0
  242. package/skills/teamsmith/tests/tmux-lint.pl +604 -0
  243. package/skills/teamsmith-init/SKILL.md +100 -0
  244. package/skills/teamsmith-init/references/bootstrap.md +74 -0
  245. package/skills/teamsmith-init/templates/bootstrap-prompt.md.tmpl +46 -0
@@ -0,0 +1,321 @@
1
+ #!/usr/bin/env bash
2
+ # M7.2 · 独立验证包:watchdog 的「启动在飞行中」误判(红)→ starting 状态(绿)
3
+ #
4
+ # bash skills/teamsmith/tests/flip-m7.2.sh # 红 = 与 main 的分叉点,绿 = 当前树
5
+ # TEAM_FLIP_BASE=<sha> bash skills/teamsmith/tests/flip-m7.2.sh
6
+ # bash skills/teamsmith/tests/flip-m7.2.sh --probe # 只打印两份逐拍采样表(诊断证据)
7
+ #
8
+ # 为什么需要:从 `respawn-pane` 到「拿到启动证据」之间,PM 窗口里是一个正在跑启动命令的 shell
9
+ # (项目内、非 agent,`team_pm_state` 只能报 unknown/idle)。旧实现没有「正在启动」这个状态,
10
+ # 于是**另一拍**(同一个 watchdog 窗口的下一拍、并发的 `watch --once`、人跑的 `team up`)把它当成
11
+ # 「没有 PM」再 respawn 一次:刚起来的 PM 被这一下杀掉,`pm-restarts.log` 把一次启动记成两次。
12
+ #
13
+ # 这里把这一格**确定性**地造出来,对「修复前 / 修复后」两份 skill 跑同一条命令:
14
+ # * 假 agent = wrapper(sleep 3 再 exec 真 agent),所以启动证据(spawn 文件 / argv)要等一拍才有;
15
+ # * 第一拍在后台跑;pane 一换进程(respawn 完成)就立刻打第二拍,落在那 ~1s 的窗口里;
16
+ # * 旧树:第二拍又拉起一次(1 个活 PM、2 行配额、argv 里两次 @pm-prompt.md),且 pane 被换掉;
17
+ # * 新树:第二拍报「PM 正在启动 → 不重复拉起」:不拉起、不计数、不动 pane。
18
+ #
19
+ # 只写 /tmp 下的临时目录,只动自己起的 tmux session(结束时清理);不碰调用者所在的仓库/session。
20
+ set -uo pipefail
21
+
22
+ # 身份隔离(与 smoke 一样的坑):绝不继承调用者的团队身份。
23
+ # 实测踩过:TEAM_MAIN_ROOT 留在调用者仓库上,夹具仓库(/tmp 下)会被判成 foreign,整场复现不动作。
24
+ unset TEAM_ROOT TEAM_MAIN_ROOT TEAM_ROOT_SOURCE TEAM_ROOT_WAS TEAM_PROJECT \
25
+ TEAM_SESSION TEAM_SESSION_FROM TEAM_PM_WINDOW TEAM_AGENTS TEAM_DOCS_DIR \
26
+ TEAM_WORKTREES_DIR TEAM_GATES TEAM_VCS TEAM_CONFIG_FILE TEAM_ALLOW_FOREIGN_SESSION 2>/dev/null || true
27
+
28
+ SELF_DIR="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
29
+ SKILL_DIR="$(cd -P "$SELF_DIR/.." && pwd)"
30
+ # P53:临时根的唯一创建者(${TMPDIR:-/tmp} + owned 家族 + 回收)
31
+ . "$SELF_DIR/lib/tmp-root.sh"
32
+ # P162:破坏性调用(kill-server/kill-session/kill-window)动手前先证明私有 socket 生效
33
+ . "$SELF_DIR/lib/tmux-iso.sh"
34
+ REPO_ROOT="$(git -C "$SKILL_DIR" rev-parse --show-toplevel 2>/dev/null || true)"
35
+ [ -n "$REPO_ROOT" ] || { printf 'flip-m7.2: 找不到 git 仓库(本脚本需要 git archive 取修复前的树)\n' >&2; exit 2; }
36
+ command -v tmux >/dev/null 2>&1 || { printf 'flip-m7.2: 需要 tmux(本复现是 tmux 现场的)\n' >&2; exit 2; }
37
+
38
+ MODE="flip"
39
+ [ "${1:-}" = "--probe" ] && MODE="probe"
40
+ TRIES="${TEAM_FLIP_TRIES:-3}"
41
+
42
+ BASE="${TEAM_FLIP_BASE:-}"
43
+ if [ -z "$BASE" ]; then
44
+ BASE="$(git -C "$REPO_ROOT" merge-base HEAD main 2>/dev/null || true)"
45
+ fi
46
+ [ -n "$BASE" ] || BASE="$(git -C "$REPO_ROOT" rev-parse --verify -q HEAD^ 2>/dev/null || true)"
47
+ [ -n "$BASE" ] || { printf 'flip-m7.2: 解析不到修复前的 revision,用 TEAM_FLIP_BASE=<sha> 指定\n' >&2; exit 2; }
48
+
49
+ [ "${KEEP:-0}" = "1" ] && export TEAM_TMP_KEEP=1
50
+ TMP="$(tmp_root_create flip-m7.2)" || exit 3
51
+ SESS_RED="teamsmith-flip-m72-red-$$"
52
+ SESS_GREEN="teamsmith-flip-m72-green-$$"
53
+
54
+ # M28:夹具自己的 tmux 调用要有隔离证据(裸 tmux 按 $TMUX 打到调用者 server —— M23 事故形状)。
55
+ # unset TMUX + 私有 TMUX_TMPDIR;工具在私有 server 的窗口里跑,继承同一套环境。口径见 tests/tmux-lint.pl。
56
+ unset TMUX TMUX_PANE 2>/dev/null || true
57
+ TMUX_TMPDIR="$TMP/tmux"; mkdir -p "$TMUX_TMPDIR"; export TMUX_TMPDIR
58
+ cleanup() {
59
+ # P162:收尾先证明私有 socket 生效(不成立就拒绝;cleanup 里不许 exit)
60
+ if tmux_iso_guard_soft "flip-m7.2" "收尾:私有 session" --tmpdir "${TMUX_TMPDIR:-}" --own-root "$TMP"; then
61
+ tmux kill-session -t "$SESS_RED" 2>/dev/null || true
62
+ tmux kill-session -t "$SESS_GREEN" 2>/dev/null || true
63
+ fi
64
+ if [ "${TEAM_FLIP_KEEP:-0}" = "1" ]; then printf '\n保留现场:%s\n' "$TMP"
65
+ else tmp_root_reap_all; fi
66
+ }
67
+ trap cleanup EXIT
68
+
69
+ # 沙箱/反向守卫(M7.2 现场教训):夹具绝不能碰真实账本。
70
+ # 事故:夹具在调用者的 cwd 里跑 `team`,TEAM_MAIN_ROOT 落回真实仓库,于是 `notify dev` 把 9 条
71
+ # 幻影待办写进真实 `docs/team/inbox/dev.md`(watchdog 因此把 PM 叫醒 9 次)。两道守卫:
72
+ # ① 正向:每个写盘命令前先断言 `team paths` 的 main_root 就是夹具仓库(不是才允许写);
73
+ # ② 反向:跑前/跑后取真实仓库 inbox+state 的指纹,并搜索本轮夹具的**唯一签名**($SLUG)——
74
+ # 出现签名 = 真泄漏(FAIL);指纹变了但没有签名 = 真实团队自己在写(如实报告,不算本夹具的错)。
75
+ SLUG="$(basename "$TMP")"
76
+ REAL_MAIN_ROOT="$(cd "$(dirname "$(git -C "$REPO_ROOT" rev-parse --path-format=absolute --git-common-dir 2>/dev/null)")" 2>/dev/null && pwd || printf '%s' "$REPO_ROOT")"
77
+ ledger_manifest() { # <root>:inbox/state 下的文件指纹(路径 + md5),供前/后对比
78
+ local root="$1" d f
79
+ for d in "$root/docs/team/inbox" "$root/.pi/team/state"; do
80
+ [ -d "$d" ] || continue
81
+ find "$d" -type f 2>/dev/null | sort | while IFS= read -r f; do
82
+ printf '%s %s\n' "$f" "$(md5sum "$f" 2>/dev/null | cut -d' ' -f1)"
83
+ done
84
+ done
85
+ }
86
+ REAL_LEDGER_BEFORE="$TMP/real-ledger-before.txt"
87
+ ledger_manifest "$REAL_MAIN_ROOT" > "$REAL_LEDGER_BEFORE"
88
+ printf '真实账本(反向守卫):%s(指纹 %s)\n夹具签名:%s\n' \
89
+ "$REAL_MAIN_ROOT" "$(md5sum "$REAL_LEDGER_BEFORE" | cut -d' ' -f1)" "$SLUG"
90
+
91
+
92
+ mkdir -p "$TMP/red-skill"
93
+ git -C "$REPO_ROOT" archive "$BASE" skills/teamsmith | tar -x -C "$TMP/red-skill" || exit 2
94
+ RED_SKILL="$TMP/red-skill/skills/teamsmith"
95
+ # 守卫:传进来的 base 必须真的还是「修复前」(否则这个包会报一个假的「翻转」)
96
+ if grep -q 'team_pm_starting' "$RED_SKILL/scripts/lib/common.sh" 2>/dev/null; then
97
+ printf 'flip-m7.2: $BASE 已经包含 M7.2 的修复(不是修复前的树)—— 用 TEAM_FLIP_BASE=<修复前的 sha> 指定\n' >&2
98
+ exit 2
99
+ fi
100
+ printf '修复前 revision: %s(%s)\n修复后 skill: %s\n' \
101
+ "$BASE" "$(git -C "$REPO_ROOT" log -1 --format=%s "$BASE" 2>/dev/null)" "$SKILL_DIR"
102
+
103
+ ok() { printf ' \033[32m✓\033[0m %s\n' "$1"; }
104
+ bad() { printf ' \033[31m✗\033[0m %s\n' "$1"; FAIL=$((FAIL+1)); }
105
+ info() { printf ' %s\n' "$1"; }
106
+ FAIL=0
107
+
108
+ # ---- 夹具:一份独立仓库(每个 tag 一份,互不干扰) --------------------------------
109
+ make_fixture() { # <tag>
110
+ local tag="$1" repo="$TMP/repo-$1" fake="$TMP/fake-$1"
111
+ mkdir -p "$repo" "$fake"
112
+ # 假 agent:wrapper 先报一行再睡 3s,然后 exec 真 agent(再报一行)——
113
+ # 「启动证据」(spawn 文件 / argv)不会顷刻间就绪,「启动在飞行中」的窗口足够宽,
114
+ # 第二拍能稳定落进去;同时 wrapper-start 的行数就是**拉起尝试次数**(不依赖 3s 后的 exec)。
115
+ cat > "$fake/pi-slow" <<EOF
116
+ #!/usr/bin/env bash
117
+ printf 'agent-start %s\n' "\$*" >> "$TMP/pm-args-$tag.log"
118
+ sleep 600
119
+ EOF
120
+ cat > "$fake/pi-wrapper" <<EOF
121
+ #!/usr/bin/env bash
122
+ printf 'wrapper-start %s\n' "\$*" >> "$TMP/pm-args-$tag.log"
123
+ sleep 3
124
+ exec "$fake/pi-slow" "\$@"
125
+ EOF
126
+ chmod +x "$fake/pi-slow" "$fake/pi-wrapper"
127
+ ( cd "$repo" || exit 2
128
+ git init -q .; git config user.email t@t; git config user.name t
129
+ echo hi > README.md; git add -A; git commit -qm init >/dev/null; git branch -m main
130
+ TEAM_SESSION="$2" bash "$3/scripts/team" init --yes >/dev/null 2>&1
131
+ sed -i "s|^TEAM_PI_BIN=.*|TEAM_PI_BIN=\"$fake/pi-wrapper\"|" .pi/team/config.sh
132
+ if grep -q '^TEAM_AGENT_BIN=' .pi/team/config.sh; then
133
+ sed -i "s|^TEAM_AGENT_BIN=.*|TEAM_AGENT_BIN=\"$fake/pi-slow\"|" .pi/team/config.sh
134
+ else
135
+ printf 'TEAM_AGENT_BIN="%s"\n' "$fake/pi-slow" >> .pi/team/config.sh
136
+ fi ) || exit 2
137
+ # 正向沙箱断言:配置解析必须真的落在这份夹具仓库上(否则后面任何写盘命令都是污染真账本)
138
+ local mr
139
+ mr="$(cd "$repo" && TEAM_SESSION="$2" bash "$3/scripts/team" paths 2>/dev/null \
140
+ | sed -n 's/.*"main_root": "\([^"]*\)".*/\1/p')"
141
+ if [ "$mr" != "$repo" ]; then
142
+ printf 'flip-m7.2: 沙箱断言失败:team paths 的 main_root=%s(应为夹具 %s)—— 拒绝继续\n' "$mr" "$repo" >&2
143
+ exit 3
144
+ fi
145
+ printf '沙箱 %s:main_root=%s\n' "$tag" "$mr"
146
+ printf '%s\n' "$repo"
147
+ }
148
+
149
+ # ---- 一次现场:第一拍在后台,窗口里立刻打第二拍 --------------------------------
150
+ run_once() { # <tag> <skill-dir> <session> <attempt> → 打印 "second_started restarts starts pane_changed starting_seen sandbox"
151
+ local tag="$1" sk="$2" sess="$3" n="$4"
152
+ local repo="$TMP/repo-$tag" work="$TMP/run-$tag-$n"
153
+ mkdir -p "$work"
154
+ # 必须在夹具仓库里跑:TEAM_MAIN_ROOT 是从**调用时的 cwd** 算出来的(TEAM_ROOT 只用来找配置),
155
+ # 从别的仓库调用会把夹具判成 foreign(实测踩过:整场复现不动作,而且写盘落到真账本)。
156
+ cd "$repo" || exit 2
157
+ export TEAM_ROOT="$repo" TEAM_SESSION="$sess"
158
+ local TEAM="bash $sk/scripts/team"
159
+ # 正向沙箱断言(写盘之前):`team paths` 必须解析到夹具仓库,否则整轮作废、什么都不写。
160
+ bash "$sk/scripts/team" paths > "$work/paths.json" 2>&1 || true
161
+ local mr; mr="$(sed -n 's/.*"main_root": "\([^"]*\)".*/\1/p' "$work/paths.json" | head -1)"
162
+ if [ "$mr" != "$repo" ]; then
163
+ printf 'flip-m7.2: 沙箱断言失败(拒绝任何写盘):main_root=%s,应为夹具 %s\n' "$mr" "$repo" >&2
164
+ printf 'sandbox-fail main_root=%s\n' "$mr" >> "$TMP/sandbox-fail.log"
165
+ printf '0 0 0 0 0 0\n'
166
+ return 0
167
+ fi
168
+
169
+ tmux has-session -t "$sess" 2>/dev/null || tmux new-session -d -s "$sess" -n keep -c "$repo" >/dev/null 2>&1
170
+ # 「PM 窗口在、里面是空提示符」的现场(pi 退出后的样子)
171
+ tmux new-window -t "$sess" -n keep -d -c "$repo" >/dev/null 2>&1 || true
172
+ tmux list-windows -t "$sess" -F '#{window_id} #{window_name}' 2>/dev/null \
173
+ | awk '$2=="pm" {print $1}' \
174
+ | while read -r wid; do [ -n "$wid" ] && { tmux_iso_require "flip-m7.2" "收掉重建的 pm 窗口" --tmpdir "${TMUX_TMPDIR:-}" --own-root "$TMP"; tmux kill-window -t "$wid" 2>/dev/null || true; }; done
175
+ tmux new-window -t "$sess" -n pm -d -c "$repo" >/dev/null 2>&1 || true
176
+ local i cmd=""
177
+ for i in $(seq 1 20); do
178
+ cmd="$(tmux display-message -p -t "$sess:pm" '#{pane_current_command}' 2>/dev/null || true)"
179
+ case "$cmd" in zsh|bash|sh|dash|ash|ksh|fish) break ;; esac
180
+ sleep 0.3
181
+ done
182
+ sleep 0.5
183
+ rm -f "$repo/.pi/team/state/pm-restarts.log" "$repo/.pi/team/state/pm.pid" \
184
+ "$repo/.pi/team/state/pm.pid.proof" "$repo/.pi/team/state/pm.pid.spawn" \
185
+ "$repo/.pi/team/state/pm.pid.starting"
186
+ $TEAM notify dev "M7.2 flip $SLUG:有待办" >/dev/null 2>&1 || true
187
+ # 正向证据:这条待办真的落在**夹具仓库**的收件箱里(而不是别处)
188
+ local sandbox=1
189
+ grep -qF "M7.2 flip $SLUG" "$repo/docs/team/inbox/dev.md" 2>/dev/null || sandbox=0
190
+ # 逐拍采样(诊断证据;每 0.2s 记一行)
191
+ local samples="$work/samples.csv" stop="$work/stop"
192
+ ( . "$sk/scripts/lib/common.sh"; team_load_config >/dev/null 2>&1
193
+ t="$(team_pm_target)"
194
+ : > "$samples"
195
+ while [ ! -f "$stop" ]; do
196
+ ts="$(date +%s.%N)"; st="$(team_pm_state)"
197
+ al=0; team_pm_alive && al=1
198
+ bs=0; team_pane_busy "$t" && bs=1
199
+ c="$(team_pane_cmd "$t")"
200
+ pp="$(tmux display-message -p -t "$t" '#{pane_pid}' 2>/dev/null || true)"
201
+ rp="$(team_pm_recorded_pid 2>/dev/null || echo -)"; rk="-"; rc="-"
202
+ if [ "$rp" != "-" ]; then
203
+ kill -0 "$rp" 2>/dev/null && rk=1 || rk=0
204
+ rc="$(team_proc_cwd "$rp" 2>/dev/null || echo '?')"
205
+ fi
206
+ sp="$(team_pm_spawn_pid 2>/dev/null || echo -)"
207
+ mk=0; [ -f "$repo/.pi/team/state/pm.pid.starting" ] && mk=1
208
+ printf '%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s\n' \
209
+ "$ts" "$st" "$al" "$bs" "$c" "$pp" "$rp" "$rk" "$rc" "$sp" "$mk" >> "$samples"
210
+ sleep 0.2
211
+ done ) &
212
+ local SAMPLER=$!
213
+ sleep 0.3
214
+
215
+ local pre mid post wrapper_before
216
+ wrapper_before="$(grep -c '^wrapper-start' "$TMP/pm-args-$tag.log" 2>/dev/null || true)"
217
+ pre="$(tmux display-message -p -t "$sess:pm" '#{pane_pid}' 2>/dev/null || true)"
218
+ $TEAM watch --once >"$work/tick1.log" 2>&1 &
219
+ local TICK1=$!
220
+ # 等「启动在飞行中」的证据出现:新树是标记文件,旧树只有 pane 换进程
221
+ i=0
222
+ while [ "$i" -lt 60 ]; do
223
+ [ -f "$repo/.pi/team/state/pm.pid.starting" ] && break
224
+ [ "$(tmux display-message -p -t "$sess:pm" '#{pane_pid}' 2>/dev/null || true)" != "$pre" ] && break
225
+ sleep 0.05; i=$((i + 1))
226
+ done
227
+ mid="$(tmux display-message -p -t "$sess:pm" '#{pane_pid}' 2>/dev/null || true)"
228
+ $TEAM watch --once >"$work/tick2.log" 2>&1 || true
229
+ wait "$TICK1" 2>/dev/null || true
230
+ sleep 1
231
+ post="$(tmux display-message -p -t "$sess:pm" '#{pane_pid}' 2>/dev/null || true)"
232
+ touch "$stop"; wait "$SAMPLER" 2>/dev/null || true
233
+
234
+ local second_started restarts starts pane_changed starting_seen wrapper_after
235
+ second_started="$(grep -c '已拉起' "$work/tick2.log" 2>/dev/null || true)"
236
+ starting_seen="$(grep -c 'PM 正在启动' "$work/tick2.log" 2>/dev/null || true)"
237
+ restarts="$(cat "$repo/.pi/team/state/pm-restarts.log" 2>/dev/null | wc -l | tr -d ' ')"
238
+ wrapper_after="$(grep -c '^wrapper-start' "$TMP/pm-args-$tag.log" 2>/dev/null || true)"
239
+ starts=$(( ${wrapper_after:-0} - ${wrapper_before:-0} ))
240
+ if [ "$post" != "$mid" ]; then pane_changed=1; else pane_changed=0; fi
241
+ printf '%s %s %s %s %s %s\n' "${second_started:-0}" "${restarts:-0}" "${starts:-0}" "$pane_changed" "${starting_seen:-0}" "$sandbox"
242
+ }
243
+
244
+ show_changes() { # <csv>:只打印状态发生变化的那几拍(报告用的紧凑表)
245
+ awk -F'|' 'NR==1 || ($2"|"$3"|"$4"|"$5"|"$7"|"$10"|"$11)!=prev {
246
+ printf " %-17s | %-16s | %-5s %-4s | %-9s | rec=%-7s | spawn=%-9s | mark=%s\n", $1, $2, $3, $4, $5, $7, $10, $11
247
+ prev=$2"|"$3"|"$4"|"$5"|"$7"|"$10"|"$11 }' "$2"
248
+ }
249
+
250
+ red_repro=0; green_viol=0; sandbox_bad=0
251
+ make_fixture red "$SESS_RED" "$RED_SKILL" || exit 3
252
+ make_fixture green "$SESS_GREEN" "$SKILL_DIR" || exit 3
253
+ printf '\n== 场景:第一拍启动中,第二拍在同一秒里到达 ==\n'
254
+ for n in $(seq 1 "$TRIES"); do
255
+ R="$(run_once red "$RED_SKILL" "$SESS_RED" "$n")"
256
+ G="$(run_once green "$SKILL_DIR" "$SESS_GREEN" "$n")"
257
+ set -- $R; R_2ND="$1"; R_RST="$2"; R_START="$3"; R_PANE="$4"; R_STARTING="$5"; R_SB="${6:-0}"
258
+ set -- $G; G_2ND="$1"; G_RST="$2"; G_START="$3"; G_PANE="$4"; G_STARTING="$5"; G_SB="${6:-0}"
259
+ printf ' 第 %s 轮:修复前 { 第二拍已拉起=%s 配额行=%s 启动次数=%s pane被换=%s 正在启动=%s 沙箱=%s } | 修复后 { 第二拍已拉起=%s 配额行=%s 启动次数=%s pane被换=%s 正在启动=%s 沙箱=%s }\n' \
260
+ "$n" "$R_2ND" "$R_RST" "$R_START" "$R_PANE" "$R_STARTING" "$R_SB" \
261
+ "$G_2ND" "$G_RST" "$G_START" "$G_PANE" "$G_STARTING" "$G_SB"
262
+ [ "$R_2ND" -ge 1 ] && red_repro=$((red_repro + 1))
263
+ if [ "$G_2ND" -ge 1 ] || [ "$G_RST" != "1" ] || [ "$G_START" != "1" ] || [ "$G_PANE" != "0" ] || [ "$G_SB" != "1" ]; then
264
+ green_viol=$((green_viol + 1))
265
+ fi
266
+ [ "$R_SB" = "1" ] || sandbox_bad=$((sandbox_bad + 1))
267
+ if [ "$MODE" = "probe" ]; then
268
+ show_changes "$R" "$TMP/run-red-$n/samples.csv"
269
+ printf ' 修复前 tick2:%s\n' "$(grep -E '已拉起|已提醒|正在启动' "$TMP/run-red-$n/tick2.log" | head -1 | sed 's/^[[:space:]]*//')"
270
+ show_changes x "$TMP/run-green-$n/samples.csv"
271
+ printf ' 修复后 tick2:%s\n' "$(grep -E '已拉起|已提醒|正在启动' "$TMP/run-green-$n/tick2.log" | head -1 | sed 's/^[[:space:]]*//')"
272
+ fi
273
+ done
274
+
275
+ # ---- 反向守卫:真实账本没被夹具碰过 ----------------------------------------------
276
+ REAL_LEDGER_AFTER="$TMP/real-ledger-after.txt"
277
+ ledger_manifest "$REAL_MAIN_ROOT" > "$REAL_LEDGER_AFTER"
278
+ REAL_BEFORE_FP="$(md5sum "$REAL_LEDGER_BEFORE" | cut -d' ' -f1)"
279
+ REAL_AFTER_FP="$(md5sum "$REAL_LEDGER_AFTER" | cut -d' ' -f1)"
280
+ REAL_LEAK_HITS="$(grep -rlF "$SLUG" "$REAL_MAIN_ROOT/docs/team/inbox" "$REAL_MAIN_ROOT/.pi/team/state" 2>/dev/null | head -3 || true)"
281
+ REAL_LEDGER_DIFF="$(diff "$REAL_LEDGER_BEFORE" "$REAL_LEDGER_AFTER" 2>/dev/null || true)"
282
+
283
+ printf '\n== 判定 ==\n'
284
+ info "沙箱:team paths 的 main_root(见各轮 run-*/paths.json)必须等于 /tmp 下的夹具仓库"
285
+ if [ "$sandbox_bad" -eq 0 ] && [ ! -s "$TMP/sandbox-fail.log" ]; then
286
+ ok "正向断言:$((TRIES * 2)) 次现场全部在夹具仓库里跑(main_root = /tmp/teamsmith-flip-m7.2.*,每次写入前都验过)"
287
+ else
288
+ bad "正向断言失败:$sandbox_bad 轮没有落在夹具仓库(见 $TMP/sandbox-fail.log)"
289
+ fi
290
+ if [ -n "$REAL_LEAK_HITS" ]; then
291
+ bad "反向守卫:夹具的签名($SLUG)出现在真实账本里:$REAL_LEAK_HITS"
292
+ else
293
+ ok "反向守卫:真实账本($REAL_MAIN_ROOT)里搜不到本轮夹具签名 $SLUG"
294
+ fi
295
+ if [ "$REAL_BEFORE_FP" = "$REAL_AFTER_FP" ]; then
296
+ ok "反向守卫:真实账本 inbox+state 一个字节没变(指纹 $REAL_AFTER_FP)"
297
+ else
298
+ info "反向守卫:真实账本在跑动期间有别的写入(指纹 $REAL_BEFORE_FP → $REAL_AFTER_FP,无夹具签名)"
299
+ printf '%s\n' "$REAL_LEDGER_DIFF" | sed 's/^/ /' | head -12
300
+ fi
301
+ info "隔离证据:$(cat "$TMP/run-green-1/paths.json" 2>/dev/null | head -1)"
302
+ info "真实 inbox 指纹:$(md5sum "$REAL_MAIN_ROOT/docs/team/inbox"/*.md 2>/dev/null | md5sum | cut -d' ' -f1)"
303
+
304
+ if [ "$MODE" = "probe" ]; then
305
+ printf ' (--probe:只打印诊断表,不做翻转判定)\n'
306
+ exit 0
307
+ fi
308
+ if [ "$red_repro" -ge 1 ]; then
309
+ ok "修复前:$red_repro/$TRIES 轮复现「第二拍又拉起一次」(刚起来的 PM 被杀、配额记两次)"
310
+ else
311
+ bad "修复前:$TRIES 轮都没复现(夹具没造出那一格)"
312
+ fi
313
+ if [ "$green_viol" -eq 0 ]; then
314
+ ok "修复后:$TRIES 轮第二拍都报「PM 正在启动」——不重复拉起、不计数、不动 pane"
315
+ else
316
+ bad "修复后:$green_viol/$TRIES 轮仍然重复拉起/多计数/pane 被换"
317
+ fi
318
+ printf '\n'
319
+ [ "$FAIL" -eq 0 ] && { printf '\033[32mflip-m7.2:翻转已复现(红 → 绿)\033[0m\n'; exit 0; }
320
+ printf '\033[31mflip-m7.2:没有观察到预期的翻转(%d 条失败)\033[0m\n' "$FAIL"
321
+ exit 1
@@ -0,0 +1,112 @@
1
+ #!/usr/bin/env bash
2
+ # teamsmith · P144 翻转夹具:把磁盘腿拆掉 → 6b 的磁盘断言必须红;装回去 → 绿
3
+ #
4
+ # bash skills/teamsmith/tests/flip-p144.sh # 默认 FAST 侧(跳过两拍 watch --once 那段)
5
+ # bash skills/teamsmith/tests/flip-p144.sh --full # 不设 TEAM_SMOKE_FAST(含两拍 capacity.log)
6
+ # bash skills/teamsmith/tests/flip-p144.sh --keep # 保留临时目录与两侧日志
7
+ #
8
+ # 两侧跑**同一份** smoke 选段(`--select 6b`),且都在 `skills/` 的整棵副本里跑 —— 当前树一个字节不动。
9
+ # 两侧只差一处:断侧删掉启动前那一趟里的 `team_df_run_lib team_disk_guard …` 调用,正是 D67 的失明形态
10
+ # (文件系统已经贴墙也不拒绝,席位照样被 ENOSPC 打死)。判据:
11
+ # * 修好侧(对照)→ 0 个 ✗;
12
+ # * 断侧 → 非 0,且红在「磁盘不足 → 拒绝派单」这一族断言上(点名路径/读数/阈值/修法那几条)。
13
+ # 翻转证明的是「夹具真的在测这次修的那件事」,不是「有人把断言改红/改绿了」。
14
+ #
15
+ # 退出码:0 = 翻转成立(断侧红 / 修好侧绿)|1 = 期望不成立(两侧日志路径会打印)|2 = 环境缺依赖。
16
+ set -uo pipefail
17
+
18
+ SELF_DIR="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
19
+ SKILL_DIR="$(cd -P "$SELF_DIR/.." && pwd)"
20
+ # P53:临时根的唯一创建者(${TMPDIR:-/tmp} + owned 家族 + 回收)
21
+ . "$SELF_DIR/lib/tmp-root.sh"
22
+ TREE="$(cd -P "$SKILL_DIR/../.." && pwd)"
23
+ FAST=1
24
+ KEEP=0
25
+ while [ $# -gt 0 ]; do
26
+ case "$1" in
27
+ --full) FAST=0; shift ;;
28
+ --keep) KEEP=1; shift ;;
29
+ -h|--help) sed -n '2,16p' "$0"; exit 0 ;;
30
+ *) printf 'flip-p144: 未知参数 %s\n' "$1" >&2; exit 2 ;;
31
+ esac
32
+ done
33
+
34
+ command -v git >/dev/null 2>&1 || { printf 'flip-p144: 本机没有 git\n' >&2; exit 2; }
35
+ [ -f "$SKILL_DIR/tests/smoke.sh" ] || { printf 'flip-p144: 找不到 %s\n' "$SKILL_DIR/tests/smoke.sh" >&2; exit 2; }
36
+
37
+ [ "$KEEP" = "1" ] && export TEAM_TMP_KEEP=1
38
+ tmp="$(tmp_root_create flip-p144)" || exit 3
39
+ cleanup() { [ "${BASHPID:-$$}" = "$$" ] && [ "$KEEP" = "0" ] && tmp_root_reap_all; }
40
+ trap cleanup EXIT
41
+
42
+ COPY="$tmp/tree"
43
+ mkdir -p "$COPY"
44
+ cp -a "$TREE/skills" "$COPY/skills" || { printf 'flip-p144: 拷不动 %s/skills\n' "$TREE" >&2; exit 2; }
45
+ # 只有 26-a 的重建 bundle 才要依赖树;--select 6b 不重建,去掉它省几百 MB
46
+ rm -rf "$COPY/skills/teamsmith/scripts/panel/node_modules"
47
+ # 副本要是自己的 git 仓库(0d 的冲突标记守卫按 git 工作树找受检文件;拷 .git 太重)
48
+ ( cd "$COPY" && git init -q -b main && git config user.email flip@teamsmith && git config user.name flip \
49
+ && git add -A && git commit -qm 'flip-p144: skills/ 副本' ) >/dev/null 2>&1 || {
50
+ printf 'flip-p144: 副本建不成 git 仓库(0d 段会红)\n' >&2; exit 2; }
51
+ AGENTS="$COPY/skills/teamsmith/scripts/lib/cmd-agents.sh"
52
+ [ -f "$AGENTS" ] || { printf 'flip-p144: 副本里找不到 %s\n' "$AGENTS" >&2; exit 2; }
53
+
54
+ run_side() { # <日志> → 0 = 选段全绿
55
+ local log="$1"
56
+ if [ "$FAST" = "1" ]; then
57
+ ( cd "$COPY" && TEAM_SMOKE_FAST=1 bash "$COPY/skills/teamsmith/tests/smoke.sh" --select 6b </dev/null ) >"$log" 2>&1
58
+ else
59
+ ( cd "$COPY" && bash "$COPY/skills/teamsmith/tests/smoke.sh" --select 6b </dev/null ) >"$log" 2>&1
60
+ fi
61
+ }
62
+ plain() { sed 's/\x1b\[[0-9;]*m//g' "$1"; }
63
+ reds() { plain "$1" | grep -a '^ ✗' | sed 's/^ ✗ //'; }
64
+
65
+ # ── 修好侧(对照) ───────────────────────────────────────────────────────────────
66
+ run_side "$tmp/green.log"; GREEN_RC=$?
67
+ GREEN_RED="$(reds "$tmp/green.log" | wc -l | tr -d ' ')"
68
+
69
+ # ── 断侧:删掉启动前那一趟里的磁盘腿调用(D67 的失明形态) ─────────────────────
70
+ if ! grep -q 'team_df_run_lib team_disk_guard "\$disk_tmp" "\$wt"' "$AGENTS"; then
71
+ printf 'flip-p144: 断点没找到(%s 里已经没有那个 team_disk_guard 调用)\n' "$AGENTS" >&2
72
+ exit 2
73
+ fi
74
+ sed -i 's|^ team_df_run_lib team_disk_guard "\$disk_tmp" "\$wt"$| # P144 翻转:磁盘腿被拆掉(断侧)|' "$AGENTS"
75
+ if grep -q 'team_df_run_lib team_disk_guard "\$disk_tmp" "\$wt"' "$AGENTS"; then
76
+ printf 'flip-p144: 断侧没生效(%s 那一行没被改掉)\n' "$AGENTS" >&2
77
+ exit 2
78
+ fi
79
+ run_side "$tmp/red.log"; RED_RC=$?
80
+ RED_RED="$(reds "$tmp/red.log" | wc -l | tr -d ' ')"
81
+
82
+ # ── 判定 ────────────────────────────────────────────────────────────────────────
83
+ fails=0
84
+ if [ "$GREEN_RC" = "0" ] && [ "$GREEN_RED" = "0" ]; then
85
+ printf 'flip-p144: 修好侧全绿(对照成立)\n'
86
+ else
87
+ printf 'flip-p144: 修好侧没全绿(rc=%s,✗=%s)—— 先看 %s\n' "$GREEN_RC" "$GREEN_RED" "$tmp/green.log" >&2
88
+ fails=1
89
+ fi
90
+ if [ "$RED_RC" != "0" ] && [ "$RED_RED" -ge 5 ]; then
91
+ printf 'flip-p144: 断侧红 %s 条(期望 ≥5)\n' "$RED_RED"
92
+ else
93
+ printf 'flip-p144: 断侧没红够(rc=%s,✗=%s)—— 看 %s\n' "$RED_RC" "$RED_RED" "$tmp/red.log" >&2
94
+ fails=1
95
+ fi
96
+ # 红的必须是**这次修的那件事**:点名磁盘腿的断言族(不是随便哪条断言坏了)
97
+ for needle in '临时根低于磁盘底线时应当拒绝派单' '工作树低于底线时应当拒绝' '拒绝点名实测 inode 与阈值'; do
98
+ if reds "$tmp/red.log" | grep -qF -- "$needle"; then
99
+ printf 'flip-p144: 断侧红在「%s」\n' "$needle"
100
+ else
101
+ printf 'flip-p144: 断侧没有红在「%s」—— 翻转指错了地方\n' "$needle" >&2
102
+ fails=1
103
+ fi
104
+ done
105
+ printf 'flip-p144: 日志 %s(绿侧)/ %s(断侧)\n' "$tmp/green.log" "$tmp/red.log"
106
+ [ "$KEEP" = "1" ] || printf 'flip-p144: (--keep 可保留现场)\n'
107
+ if [ "$fails" = "0" ]; then
108
+ printf 'flip-p144: 翻转成立(断侧红 → 修好侧绿)\n'
109
+ exit 0
110
+ fi
111
+ printf 'flip-p144: 翻转不成立\n' >&2
112
+ exit 1
@@ -0,0 +1,133 @@
1
+ #!/usr/bin/env bash
2
+ # teamsmith · P156 翻转夹具:26-c 的归一化守卫 —— 只归一实时读数,结构照旧逐字节比
3
+ #
4
+ # bash skills/teamsmith/tests/flip-p156.sh # 三面:当前绿 / 旧归一化红 / 掏空的归一化红
5
+ # bash skills/teamsmith/tests/flip-p156.sh --keep # 保留临时根与三份日志
6
+ # TEAM_FLIP_BASE=<sha> bash …/flip-p156.sh # 自选基线(默认 merge-base HEAD main = 修复前)
7
+ #
8
+ # 三面跑**同一份** 26-c 聚焦探针(smoke 前导 + 26 段到 26-c;假 tmux,不碰真 session),只差 p10_norm:
9
+ # ① current → 绿:绿侧(只动实时读数的数值 → 归一后逐字节相同)与红侧(动字段名/行数/ESC/分隔符/
10
+ # 单位 → 必须仍然不同)都成立;
11
+ # ② base → 红,且必须红在**绿侧**(修复前的口径把实时读数当内容比:第二段采样必然不同);
12
+ # ③ gutted → 红,且必须红在**红侧**(把归一化掏空成恒等 → 结构差异也被吃掉 → 守卫没有牙)。
13
+ # 翻转证明的是「守卫真的在测这次修的那件事」:不是把断言改红,也不是让断言空跑。
14
+ #
15
+ # 只读 git(`git show BASE:…smoke.sh`);只写 /tmp 下的临时根;探针 EXIT 时自己收干净。
16
+ set -uo pipefail
17
+
18
+ SELF_DIR="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
19
+ SKILL_DIR="$(cd -P "$SELF_DIR/.." && pwd)"
20
+ # P53:临时根的唯一创建者(${TMPDIR:-/tmp} + owned 家族 + 回收)
21
+ . "$SELF_DIR/lib/tmp-root.sh"
22
+ REPO_ROOT="$(git -C "$SKILL_DIR" rev-parse --show-toplevel 2>/dev/null || true)"
23
+ [ -n "$REPO_ROOT" ] || { printf 'flip-p156: 找不到 git 仓库\n' >&2; exit 2; }
24
+ command -v python3 >/dev/null 2>&1 || { printf 'flip-p156: 需要 python3(拼接 p10_norm)\n' >&2; exit 2; }
25
+
26
+ KEEP=0
27
+ while [ $# -gt 0 ]; do
28
+ case "$1" in
29
+ --keep) KEEP=1; shift ;;
30
+ -h|--help) sed -n '2,17p' "$0"; exit 0 ;;
31
+ *) printf 'flip-p156: 未知参数 %s\n' "$1" >&2; exit 2 ;;
32
+ esac
33
+ done
34
+ [ "$KEEP" = "1" ] && export TEAM_TMP_KEEP=1
35
+ TMP="$(tmp_root_create flip-p156)" || exit 3
36
+ cleanup() { [ "${BASHPID:-$$}" = "$$" ] && [ "$KEEP" = "0" ] && tmp_root_reap_all; }
37
+ trap cleanup EXIT
38
+
39
+ CUR_SMOKE="$SKILL_DIR/tests/smoke.sh"
40
+ [ -f "$CUR_SMOKE" ] || { printf 'flip-p156: 找不到 %s\n' "$CUR_SMOKE" >&2; exit 2; }
41
+ BASE="${TEAM_FLIP_BASE:-}"
42
+ [ -n "$BASE" ] || BASE="$(git -C "$REPO_ROOT" merge-base HEAD main 2>/dev/null || true)"
43
+ [ -n "$BASE" ] || BASE="$(git -C "$REPO_ROOT" rev-parse --verify -q HEAD^ 2>/dev/null || true)"
44
+ [ -n "$BASE" ] || { printf 'flip-p156: 解析不到修复前的 revision,用 TEAM_FLIP_BASE=<sha> 指定\n' >&2; exit 2; }
45
+ git -C "$REPO_ROOT" show "$BASE:skills/teamsmith/tests/smoke.sh" > "$TMP/smoke-base.sh" 2>/dev/null \
46
+ || { printf 'flip-p156: %s 里没有 smoke.sh\n' "$BASE" >&2; exit 2; }
47
+ sed -n '/^p10_norm()/,/^}/p' "$TMP/smoke-base.sh" > "$TMP/norm-base.sh"
48
+ [ -s "$TMP/norm-base.sh" ] || { printf 'flip-p156: 基线 %s 里没有 p10_norm\n' "$BASE" >&2; exit 2; }
49
+ if grep -q 'RAM|swap' "$TMP/norm-base.sh"; then
50
+ printf 'flip-p156: BASE(%s)已经含 P156 的归一化(不是修复前的树)——用 TEAM_FLIP_BASE=<修复前的 sha>\n' "$BASE" >&2
51
+ exit 2
52
+ fi
53
+ grep -q 'RAM|swap' "$CUR_SMOKE" || { printf 'flip-p156: 当前树没有 P156 的归一化(先跑修复)\n' >&2; exit 2; }
54
+ printf 'p10_norm() { :; }\n' > "$TMP/norm-gutted.sh"
55
+
56
+ # 探针 = 前导(身份隔离 / 锁 / 临时根 / helpers)+ 26 段到 26-c;SKILL_DIR 指向当前树(产品代码不变)
57
+ build_probe() { # <src-smoke> <out>
58
+ local src="$1" out="$2"
59
+ {
60
+ awk '/^# -+ 0\. 仓库/{exit} {print}' "$src"
61
+ printf '\n# —— 26-c 聚焦探针(P156)——\n'
62
+ awk '/^section "26 · 面板(pulse-tui-panel/{f=1} /^# -+ 26-d\. --json/{exit} f{print}' "$src"
63
+ } | sed "s|^SKILL_DIR=.*|SKILL_DIR=\"$SKILL_DIR\"|" > "$out"
64
+ cat >> "$out" <<'EOS'
65
+ section "15 · 完成(26-c 聚焦探针)"
66
+ printf '\n== 结果 == ✓ %d ✗ %d\n' "$PASS" "$FAIL"
67
+ [ "$FAIL" -eq 0 ] && exit 0
68
+ exit 1
69
+ EOS
70
+ }
71
+ splice_norm() { # <probe> <replacement-file>:把探针里的 p10_norm 定义整块换掉(必须正好一处)
72
+ python3 - "$1" "$2" <<'PY'
73
+ import sys
74
+ probe, repl = sys.argv[1], sys.argv[2]
75
+ lines = open(probe, encoding='utf-8').read().split('\n')
76
+ new = open(repl, encoding='utf-8').read().rstrip('\n').split('\n')
77
+ out, i, hit = [], 0, 0
78
+ while i < len(lines):
79
+ if lines[i].startswith('p10_norm() {'):
80
+ j = i
81
+ while j < len(lines) and lines[j] != '}':
82
+ j += 1
83
+ out.extend(new); hit += 1; i = j + 1; continue
84
+ out.append(lines[i]); i += 1
85
+ open(probe, 'w', encoding='utf-8').write('\n'.join(out))
86
+ sys.exit(0 if hit == 1 else 1)
87
+ PY
88
+ }
89
+ probe_run() { # <tag> <replacement|-> <log> → rc(探针是夹具:假 tmux + 私有临时根,不排机器锁)
90
+ local tag="$1" repl="$2" log="$3"
91
+ local p="$TMP/probe-$tag.sh"
92
+ build_probe "$CUR_SMOKE" "$p" || return 3
93
+ if [ "$repl" != "-" ]; then
94
+ splice_norm "$p" "$repl" || { printf 'flip-p156: %s:p10_norm 没被替换\n' "$tag" >&2; return 3; }
95
+ fi
96
+ TEAM_SMOKE_NO_LOCK=1 bash "$p" > "$log" 2>&1
97
+ return $?
98
+ }
99
+ plain() { sed 's/\x1b\[[0-9;]*m//g' "$1"; }
100
+ reds() { plain "$1" | grep -a '^ ✗' | sed 's/^ ✗ //'; }
101
+ result_line() { plain "$1" | grep -a '== 结果 ==' | tail -1; }
102
+
103
+ printf 'P156 翻转:同一份 26-c 探针,只差 p10_norm 的实现\n BASE=%s\n 当前=%s\n' "$BASE" "$CUR_SMOKE"
104
+ fails=0
105
+ probe_run current - "$TMP/current.log"; crc=$?
106
+ probe_run base "$TMP/norm-base.sh" "$TMP/base.log"; brc=$?
107
+ probe_run gutted "$TMP/norm-gutted.sh" "$TMP/gutted.log"; grc=$?
108
+
109
+ printf '① 当前(修复后):rc=%s %s\n' "$crc" "$(result_line "$TMP/current.log")"
110
+ reds "$TMP/current.log" | sed 's/^/ /'
111
+ [ "$crc" -eq 0 ] || { printf '✗ 修复不成立:当前树在 26-c 探针上红了(看 %s)\n' "$TMP/current.log" >&2; fails=1; }
112
+
113
+ printf '② 旧归一化(BASE):rc=%s %s\n' "$brc" "$(result_line "$TMP/base.log")"
114
+ reds "$TMP/base.log" | sed 's/^/ /'
115
+ if [ "$brc" -ne 0 ] && reds "$TMP/base.log" | grep -qF '26-c P156 绿侧'; then
116
+ printf '✓ 旧口径红在绿侧(把实时读数当内容比)\n'
117
+ else
118
+ printf '✗ 旧口径没有红在绿侧 —— 翻转指错了地方(看 %s)\n' "$TMP/base.log" >&2; fails=1
119
+ fi
120
+
121
+ printf '③ 掏空的归一化:rc=%s %s\n' "$grc" "$(result_line "$TMP/gutted.log")"
122
+ reds "$TMP/gutted.log" | sed 's/^/ /'
123
+ if [ "$grc" -ne 0 ] && reds "$TMP/gutted.log" | grep -qF '26-c P156 红侧'; then
124
+ printf '✓ 掏空归一化时红侧失败(守卫不是空跑的绿)\n'
125
+ else
126
+ printf '✗ 掏空归一化后红侧没有失败 —— 守卫没有牙(看 %s)\n' "$TMP/gutted.log" >&2; fails=1
127
+ fi
128
+
129
+ printf 'flip-p156: 日志 %s(当前)/ %s(旧)/ %s(掏空)\n' "$TMP/current.log" "$TMP/base.log" "$TMP/gutted.log"
130
+ [ "$KEEP" = "1" ] || printf 'flip-p156: (--keep 可保留现场)\n'
131
+ if [ "$fails" = "0" ]; then printf 'flip-p156: 翻转成立(当前绿 → 旧口径红在绿侧 → 掏空红在红侧)\n'; exit 0; fi
132
+ printf 'flip-p156: 翻转不成立\n' >&2
133
+ exit 1