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
@@ -0,0 +1,1664 @@
1
+ #!/usr/bin/env bash
2
+ # help-surface.sh — the checks behind the help surface (change: cli-help · specs/help-surface).
3
+ #
4
+ # The gate checks the help surface's **logic**; wording, typography, page depth and the language
5
+ # tables' completeness are design/review questions (user ruling D170, recorded in the change's
6
+ # design.md and in the task brief's scope revision). The groups:
7
+ #
8
+ # coverage the manifest ↔ the dispatcher ↔ the three levels: every label has a page, every
9
+ # group page lists its commands, every page prints exactly its manifest row's usage
10
+ # lines, aliases reach their primary (byte-identical)
11
+ # lang the language *mechanism*: English by default, TEAM_LANG=zh switches, an invalid
12
+ # value prints one visible warning and falls back, a missing key renders a visible
13
+ # marker (never blank, never a crash), and no machine exit moves with the language
14
+ # locale one tree, one TEAM_LANG and one TEAM_HELP_WIDTH render the same bytes under
15
+ # LC_ALL=C and LC_ALL=C.UTF-8; every run is valid UTF-8; no line exceeds the width the
16
+ # surface wraps to (the fixture's own locale-independent counter, not the renderer's)
17
+ # claims the declared effect / authorization / reversibility values: closed vocabularies,
18
+ # one probe per value, and each probe run against a real fixture asserting the effect.
19
+ # For `idempotent` the probe turns a *named* recorded-time field into a canary
20
+ # (IDEMPOTENT_TIME_FIELDS) so its verdict cannot depend on the wall clock (P290),
21
+ # requires the second run's exit code to equal the first run's, and exercises the
22
+ # record-without-that-field shape: a missing timestamp is not an error (V46 F1)
23
+ # invariants command names, flag names and the literals other specs name: unchanged; the
24
+ # pre-change (command, flag) set is still printed; the retired --model is not
25
+ # route the three levels, byte-identical entries, unknown tokens exit 2 and are named, the
26
+ # help paths need no project, and asking for help executes nothing
27
+ #
28
+ # Usage:
29
+ # bash skills/teamsmith/tests/help-surface.sh [--all] [--select <group[,group…]>]
30
+ # bash skills/teamsmith/tests/help-surface.sh --flip # the red sides, in scratch copies
31
+ # knobs:
32
+ # TEAM_HELP_SURFACE_TREE=<tree> tree under test (default: this checkout)
33
+ # TEAM_HELP_SURFACE_KEEP=1 keep the scratch root and print it
34
+ # TEAM_HELP_SURFACE_TIMEOUT=<s> per-probe timeout, default 60
35
+ # Exit: 0 all selected groups green; 1 at least one finding; 3 setup failure.
36
+ # Containment: everything runs under one owned temp root with a recording tmux shim first on PATH;
37
+ # the caller's project is never read or written.
38
+ set -uo pipefail
39
+
40
+ _tree_arg="${TEAM_HELP_SURFACE_TREE:-}"
41
+ _keep_arg="${TEAM_HELP_SURFACE_KEEP:-}"
42
+ _timeout_arg="${TEAM_HELP_SURFACE_TIMEOUT:-}"
43
+ _only_arg="${TEAM_HELP_SURFACE_ONLY:-}"
44
+ _flipdry_arg="${TEAM_HELP_SURFACE_FLIP_DRY:-}"
45
+ _fliponly_arg="${TEAM_HELP_SURFACE_FLIP_ONLY:-}"
46
+ while IFS='=' read -r _v _; do
47
+ case "$_v" in TEAM_*) unset "$_v" 2>/dev/null || true ;; esac
48
+ done < <(env)
49
+ unset _v 2>/dev/null || true
50
+ # the surface's own knobs survive the TEAM_* scrub (they are this fixture's, not the project's)
51
+ export TEAM_HELP_SURFACE_TREE="$_tree_arg"
52
+ export TEAM_HELP_SURFACE_ONLY="$_only_arg"
53
+ export TEAM_HELP_SURFACE_FLIP_DRY="$_flipdry_arg"
54
+ export TEAM_HELP_SURFACE_FLIP_ONLY="$_fliponly_arg"
55
+
56
+ here="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
57
+ # P309:临时根只有一处解析(product 的 team_tmp_root)。这份夹具以前自己写 ${TMPDIR:-/tmp},
58
+ # 现在必须把解析器 source 进来 —— 否则 team_tmp_root 不存在、拼出来的路径是空根(`/.teamsmith-…`)。
59
+ . "$here/lib/tmp-root.sh"
60
+ tree="${_tree_arg:-$(cd -P "$here/../../.." && pwd)}"
61
+ skill="$tree/skills/teamsmith"
62
+ team="$skill/scripts/team"
63
+ str="$skill/scripts/strings"
64
+ timeout_sec="${_timeout_arg:-60}"
65
+ case "$timeout_sec" in ''|*[!0-9]*) timeout_sec=60 ;; esac
66
+ keep="$_keep_arg"
67
+
68
+ # render mode: this file re-invokes itself to render one page in parallel with its siblings
69
+ if [ "${1:-}" = "--render-one" ]; then
70
+ _lang="$2"; _spec="$3"; _dir="$4"; _loc="${5:-}"; _w="${6:-}"
71
+ _kind="${_spec%%:*}"; _label="${_spec#*:}"
72
+ [ "$_label" = "-" ] && _label="menu"
73
+ case "$_kind" in
74
+ menu) _argv=() ;;
75
+ group) _argv=(help "$_label") ;;
76
+ command) _argv=(help "$_label") ;;
77
+ *) exit 3 ;;
78
+ esac
79
+ # _loc / _w are empty for every pre-existing caller: those renders keep inheriting the caller's
80
+ # locale and width exactly as before (the locale group is the only caller that pins them).
81
+ _env=()
82
+ [ -n "$_loc" ] && _env=(LC_ALL="$_loc")
83
+ _rtmp="$(team_tmp_root)/.teamsmith-help-surface-render.$$"
84
+ mkdir -p "$_rtmp" "$_dir"
85
+ ( cd "$_rtmp" && env "${_env[@]}" TEAM_LANG="$_lang" ${_w:+TEAM_HELP_WIDTH="$_w"} \
86
+ bash "$team" "${_argv[@]}" ) > "$_dir/$_kind--$_label.txt" 2>/dev/null
87
+ _rrc=$?
88
+ rm -rf "$_rtmp"
89
+ exit $_rrc
90
+ fi
91
+
92
+ # the selectable groups: a name outside this list used to print "command not found" and still exit 0
93
+ # (a misspelled or retired group name was a silent green), so the selector now refuses it by name
94
+ KNOWN_SECTIONS="coverage locale lang claims invariants route"
95
+
96
+ SECTIONS=()
97
+ FLIP=0
98
+ for a in "$@"; do
99
+ case "$a" in
100
+ --all) SECTIONS=($KNOWN_SECTIONS) ;;
101
+ --flip) FLIP=1 ;;
102
+ --select) : ;;
103
+ --select=*) IFS=',' read -r -a SECTIONS <<< "${a#*=}" ;;
104
+ -*) printf 'help-surface: 未知参数 %s\n' "$a" >&2; exit 2 ;;
105
+ *) IFS=',' read -r -a SECTIONS <<< "$a" ;;
106
+ esac
107
+ done
108
+ [ "${#SECTIONS[@]}" -gt 0 ] || SECTIONS=($KNOWN_SECTIONS)
109
+ _bad_sel=""
110
+ for _s in "${SECTIONS[@]}"; do
111
+ case " $KNOWN_SECTIONS " in *" $_s "*) ;; *) _bad_sel="$_bad_sel $_s" ;; esac
112
+ done
113
+ if [ -n "$_bad_sel" ]; then
114
+ printf 'help-surface: 未知的选段%s(可用:%s)\n' "$_bad_sel" "${KNOWN_SECTIONS// /, }" >&2
115
+ exit 2
116
+ fi
117
+ want() { local s; for s in "${SECTIONS[@]}"; do [ "$s" = "$1" ] && return 0; done; return 1; }
118
+
119
+ [ -f "$team" ] || { printf 'help-surface: 没有 CLI:%s\n' "$team" >&2; exit 3; }
120
+ [ -f "$str/commands.tsv" ] || { printf 'help-surface: 没有命令清单:%s\n' "$str/commands.tsv" >&2; exit 3; }
121
+
122
+ TIMEOUT_BIN=""
123
+ command -v timeout >/dev/null 2>&1 && TIMEOUT_BIN=timeout
124
+ PASS=0; FIND=0; SKIP=0
125
+ section() { printf '\n\033[1m== %s ==\033[0m\n' "$1"; }
126
+ ok() { printf ' \033[32m✓\033[0m %s\n' "$1"; PASS=$((PASS + 1)); }
127
+ finding() { printf ' \033[31m✗\033[0m %s\n' "$1"; FIND=$((FIND + 1)); }
128
+ skip() { printf ' \033[33mSKIP\033[0m %s\n' "$1"; SKIP=$((SKIP + 1)); }
129
+
130
+ # ---------------------------------------------------------------- owned scratch root
131
+ tmp="$(team_tmp_root)/.teamsmith-help-surface.$$"
132
+ rm -rf "$tmp"; mkdir -p "$tmp/logs" "$tmp/fx"
133
+ cleanup() {
134
+ [ "${BASHPID:-$$}" = "$$" ] || return 0
135
+ # any pane command the shim really ran is killed with the fixture
136
+ if [ -d "$tmp/pane-pids" ]; then
137
+ local _f
138
+ for _f in "$tmp/pane-pids"/*; do [ -f "$_f" ] || continue; kill "$(cat "$_f")" 2>/dev/null || true; done
139
+ fi
140
+ if [ "$keep" = "1" ]; then printf '\n保留夹具目录:%s\n' "$tmp"; else rm -rf "$tmp"; fi
141
+ }
142
+ trap cleanup EXIT
143
+
144
+ # ---------------------------------------------------------------- recording tmux shim + fake agent
145
+ SHIM="$tmp/shim"; mkdir -p "$SHIM"
146
+ cat > "$SHIM/tmux" <<'SHIM'
147
+ #!/usr/bin/env bash
148
+ printf '%s\n' "$*" >> "${HS_TMUX_LOG:-/dev/null}" 2>/dev/null || true
149
+ win="${HS_WINDOWS:-/dev/null}"
150
+ sub="" t="" name=""
151
+ while [ $# -gt 0 ]; do
152
+ case "$1" in
153
+ -L|-S|-f|-T|-c) shift 2 ;;
154
+ -*) shift ;;
155
+ *) sub="$1"; shift; break ;;
156
+ esac
157
+ done
158
+ rest=("$@")
159
+ _i=0
160
+ while [ "$_i" -lt ${#rest[@]} ]; do
161
+ case "${rest[$_i]}" in
162
+ -t) t="${rest[$((_i+1))]:-}"; _i=$((_i+2)) ;;
163
+ -n) name="${rest[$((_i+1))]:-}"; _i=$((_i+2)) ;;
164
+ *) _i=$((_i+1)) ;;
165
+ esac
166
+ done
167
+ reg() { [ -n "$1" ] || return 0; grep -qxF "$1" "$win" 2>/dev/null || printf '%s\n' "$1" >> "$win"; }
168
+ unreg() { [ -n "$1" ] || return 0; [ -f "$win" ] || return 0; grep -vxF "$1" "$win" > "$win.tmp" 2>/dev/null || true; mv "$win.tmp" "$win"; }
169
+ case "$sub" in
170
+ has-session) exit 1 ;;
171
+ list-windows)
172
+ [ -f "$win" ] || exit 0
173
+ if [ -n "$t" ]; then awk -F: -v s="$t" '$1==s{print $2}' "$win"; else cat "$win"; fi
174
+ exit 0 ;;
175
+ new-window) reg "${t:-?}:$name"; exit 0 ;;
176
+ respawn-pane)
177
+ # the dispatch harness runs the pane's command for real (a real tmux would): the launcher's own
178
+ # script writes the launch proof and runs the agent, so the probe sees a genuine launch.
179
+ _j=0
180
+ while [ "$_j" -lt ${#rest[@]} ]; do
181
+ case "${rest[$_j]}" in
182
+ -k|-d) _j=$((_j+1)) ;;
183
+ -t|-c) _j=$((_j+2)) ;;
184
+ *) break ;;
185
+ esac
186
+ done
187
+ if [ "$_j" -lt ${#rest[@]} ]; then
188
+ setsid "${rest[@]:$_j}" </dev/null >/dev/null 2>&1 &
189
+ printf '%s\n' "$!" > "${HS_PANE_PIDS:-/dev/null}.$$" 2>/dev/null || true
190
+ fi
191
+ exit 0 ;;
192
+ kill-window) unreg "${t:-?}"; exit 0 ;;
193
+ list-panes)
194
+ # P292:interrupt 探针把「pane 里的 agent 进程」指到一个**真** stub(私有 pid 文件,见 probe_env_of)。
195
+ # 不设这个变量的探针读到的东西与从前逐字节相同('0')。
196
+ if [ -n "${HS_PANE_PID_FILE:-}" ] && [ -r "$HS_PANE_PID_FILE" ]; then
197
+ _p="$(head -1 "$HS_PANE_PID_FILE" 2>/dev/null)"
198
+ case "$_p" in ''|*[!0-9]*) ;; *) printf '1 %s\n' "$_p"; exit 0 ;; esac
199
+ fi
200
+ printf '0\n'; exit 0 ;;
201
+ display-message)
202
+ case "$*" in
203
+ *pane_current_command*) case "$t" in *pulse*) printf 'node\n' ;; esac ;;
204
+ esac
205
+ exit 0 ;;
206
+ list-sessions|set-window-option|capture-pane) exit 0 ;;
207
+ show-options) printf 'on\n'; exit 0 ;;
208
+ esac
209
+ exit 0
210
+ SHIM
211
+ chmod +x "$SHIM/tmux"
212
+ # the fake agent: records its own invocation and exits at once
213
+ printf '#!/usr/bin/env bash\nprintf "%%s\\n" "$*" >> "${HS_LAUNCH_LOG:-/dev/null}"\nexit 0\n' > "$SHIM/fakeagent"
214
+ chmod +x "$SHIM/fakeagent"
215
+ # P292:interrupt 探针的「席位」——一个**真**的长回合进程(身份写在它自己的 environ 里,argv[0] 的
216
+ # basename 命中探针配置的 TEAM_AGENT_BIN);TERM = 回合结束(退出 0)。它由探针现场起,收尾由 cleanup
217
+ # 按 pane-pids 台账兜底。
218
+ # P313:长回合 stub 由 lib/bounded-spin.sh 一处实现三条边界(TERM 就退 / 父没了就退 / 硬上限)——
219
+ # 「永远不退出的 while :」是被打断的夹具运行会永久泄漏的那种形状(现场:78 个孤儿 / 11.98 GB)。
220
+ # 父 pid 显式给:stub 经 setsid 拉起、要比拉起它的子 shell 活得久。
221
+ {
222
+ printf '#!/usr/bin/env bash\n'
223
+ printf '. %q\n' "$skill/tests/lib/bounded-spin.sh"
224
+ cat <<'STUB'
225
+ bounded_spin 0.2 1800 - - "${HS_STUB_PARENT:-$PPID}"
226
+ STUB
227
+ } > "$SHIM/interrupt-agent"
228
+ chmod +x "$SHIM/interrupt-agent"
229
+ printf '#!/usr/bin/env bash\nexec bash %q "$@"\n' "$team" > "$SHIM/team"
230
+ chmod +x "$SHIM/team"
231
+ : > "$tmp/tmux-calls.log"; : > "$tmp/windows.reg"; : > "$tmp/launch.log"
232
+
233
+ mkdir -p "$tmp/pane-pids"
234
+ export HS_TMUX_LOG="$tmp/tmux-calls.log" HS_WINDOWS="$tmp/windows.reg" HS_LAUNCH_LOG="$tmp/launch.log" HS_PANE_PIDS="$tmp/pane-pids/pane"
235
+ export TEAM_MEETINGS_DIR="$tmp/meetings"; mkdir -p "$TEAM_MEETINGS_DIR"
236
+
237
+ # ---------------------------------------------------------------- reading the manifest
238
+ # mg <name> <field> → one field of a command row (field names as in the manifest header)
239
+ declare -A MG_NAME=() MG_GROUP=() MG_USAGE=() MG_FLAGS=() MG_SUBS=() MG_ALIASES=() MG_TERMS=() \
240
+ MG_FACES=() MG_EFFECT=() MG_AUTH=() MG_UNDO=() MG_CLAIMS=() MG_PROBE=() MG_EXAMPLE=()
241
+ declare -a MG_ORDER=() MG_GROUPS=() MG_BEGIN=()
242
+ load_manifest() {
243
+ local line f
244
+ local -a col=()
245
+ while IFS= read -r line; do
246
+ case "$line" in ''|'#'*) continue ;; esac
247
+ IFS=$'\t' read -r -a col <<< "$line"
248
+ case "${col[0]}" in
249
+ group) MG_GROUPS+=("${col[1]}") ;;
250
+ begin) MG_BEGIN=("${col[@]:1}") ;;
251
+ cmd)
252
+ local n="${col[1]}"
253
+ MG_ORDER+=("$n")
254
+ MG_GROUP[$n]="${col[2]}"; MG_USAGE[$n]="${col[3]}"; MG_FLAGS[$n]="${col[4]}"
255
+ MG_SUBS[$n]="${col[5]}"; MG_ALIASES[$n]="${col[6]}"; MG_TERMS[$n]="${col[7]}"
256
+ MG_FACES[$n]="${col[8]}"; MG_EFFECT[$n]="${col[9]}"; MG_AUTH[$n]="${col[10]}"
257
+ MG_UNDO[$n]="${col[11]}"; MG_CLAIMS[$n]="${col[12]}"; MG_PROBE[$n]="${col[13]}"
258
+ MG_EXAMPLE[$n]="${col[14]}" ;;
259
+ esac
260
+ done < "$1"
261
+ }
262
+ # mt <file> <key> → the value of one prose key
263
+ mt() { awk -F'\t' -v k="$2" '$1==k {print substr($0, index($0,"\t")+1); found=1; exit} END{if(!found) exit 1}' "$1"; }
264
+ # prose_keys <file> → the key set
265
+ prose_keys() { awk -F'\t' '!/^#/ && NF>0 {print $1}' "$1" | sort; }
266
+
267
+ # page <language> <argv…> → render a page from the tree under test (never loads a project)
268
+ page() {
269
+ local lang="$1"; shift
270
+ ( cd "$tmp" && env -u TMUX -u TMUX_PANE TEAM_LANG="$lang" TEAM_SKILL_DIR="$skill" \
271
+ PATH="$SHIM:$PATH" ${TIMEOUT_BIN:+"$TIMEOUT_BIN" "$timeout_sec"} bash "$team" "$@" </dev/null 2>/dev/null )
272
+ }
273
+
274
+ # cells <text> — display cells (mirrors the renderer's rule; a CJK-wide character counts two)
275
+ cells() { printf '%s' "$1" | python3 -c 'import sys,unicodedata; s=sys.stdin.read(); print(sum(2 if unicodedata.east_asian_width(c) in "WF" else 1 for c in s))'; }
276
+
277
+ # has_cjk <text> → 0 when the text carries a CJK code point. Not `grep '[一-龥]'`: under LC_ALL=C that
278
+ # bracket expression is a byte range that matches almost any byte, so the very same menu came out
279
+ # "Chinese" in one locale and English in the other. A verdict that moves with the caller's locale is
280
+ # the defect this change removes from the surface — the checker must not reintroduce it.
281
+ has_cjk() {
282
+ python3 -c '
283
+ import sys
284
+ data = sys.stdin.buffer.read().decode("utf-8", "replace")
285
+ sys.exit(0 if any("\u3400" <= c <= "\u9fff" or "\uf900" <= c <= "\ufaff" for c in data) else 1)
286
+ '
287
+ }
288
+
289
+ # the dispatcher's internal labels: the case arms of scripts/team whose name begins with `__`
290
+ team_internal_labels() {
291
+ awk '
292
+ /^case "\$CMD" in/ { inb=1; next }
293
+ inb && /^esac/ { inb=0 }
294
+ inb && /^[[:space:]]+__[A-Za-z0-9_'"'"'|.-]*\)/ {
295
+ line=$0; sub(/^[[:space:]]+/,"",line); sub(/\).*/,"",line)
296
+ n=split(line,a,"|"); for (i=1;i<=n;i++){ if (a[i] !~ /^__/) continue; gsub(/[^a-z0-9_-]/,"",a[i]); if(a[i]!="") printf "%s\n", a[i] }
297
+ }' "$skill/scripts/team" | sort -u
298
+ }
299
+
300
+ # the dispatcher's own labels (the case arms of scripts/team), minus the internal data path
301
+ team_labels() {
302
+ awk '
303
+ /^case "\$CMD" in/ { inb=1; next }
304
+ inb && /^esac/ { inb=0 }
305
+ inb && /^[[:space:]]+[A-Za-z0-9_'"'"'|.-]+\)/ {
306
+ line=$0; sub(/^[[:space:]]+/,"",line); sub(/\).*/,"",line)
307
+ n=split(line,a,"|"); for (i=1;i<=n;i++){ if (a[i] ~ /^__/) continue; gsub(/[^a-z0-9-]/,"",a[i]); if(a[i]!="") printf "%s\n", a[i] }
308
+ }' "$skill/scripts/team" | sort -u
309
+ }
310
+
311
+ # ---------------------------------------------------------------- fixtures for the probes
312
+ declare -A FP_NAMES=()
313
+ fp_dir() { # <dir> → the tree's shape (type, path, size, symlink target) plus its file contents
314
+ local d="$1"
315
+ [ -e "$d" ] || { printf 'absent\n'; return 0; }
316
+ { find "$d" -mindepth 1 -printf '%y %P %s %l\n' 2>/dev/null | sort
317
+ find "$d" -type f -print0 2>/dev/null | sort -z | xargs -0 -r cat 2>/dev/null
318
+ } | sha256sum | cut -c1-16
319
+ }
320
+ fp_face() { # <dir> <face> → a fingerprint of that face
321
+ local d="$1" face="$2"
322
+ case "$face" in
323
+ state) fp_dir "$d/.pi/team/state" ;;
324
+ docs) fp_dir "$d/docs" ;;
325
+ config) fp_dir "$d/.pi/team/config.sh" ;;
326
+ worktree)
327
+ # F1(V52 返修轮次 1):旧指纹只摘**结构**(`worktree list` + 本地分支 ref),看不见「往席位
328
+ # 工作树里写一个文件」这种漂移 —— 而 interrupt 的规格明写工作树逐字节不变,claims 探针却对
329
+ # 它一直瞎。现在取结构 **加内容**,内容取两处并集:
330
+ # ① `.worktrees/` 约定目录(浅现场里席位工作树就在这里,未必登记进 git);
331
+ # ② `git worktree list` 登记的每个**非主检出**工作树(worktree 放到仓外时也看得见)。
332
+ # 主检出本身不整体哈希:它的内容按面拆开(state / docs / config / skills 各有一份指纹),
333
+ # 否则任何命令写任意一个面都会同时把 worktree 点亮,反向判据就分不出是哪个面了。
334
+ {
335
+ git -C "$d" worktree list --porcelain 2>/dev/null
336
+ git -C "$d" for-each-ref --format='%(refname)' refs/heads 2>/dev/null
337
+ fp_dir "$d/.worktrees"
338
+ local _main _wt
339
+ _main="$(cd -P "$d" 2>/dev/null && pwd)"
340
+ while IFS= read -r _wt; do
341
+ case "$_wt" in ''|"$_main") continue ;; esac
342
+ fp_dir "$_wt"
343
+ done < <(git -C "$d" worktree list --porcelain 2>/dev/null | awk '/^worktree /{print substr($0,10)}')
344
+ } | sha256sum | cut -c1-16 ;;
345
+ skills) fp_dir "$d/.pi/skills" ;;
346
+ meetings) fp_dir "${TEAM_MEETINGS_DIR:-$tmp/meetings}" ;;
347
+ *) printf 'unknown\n' ;;
348
+ esac
349
+ }
350
+ fp_all() { # <dir> → every face's fingerprint
351
+ local f
352
+ for f in state docs config worktree skills meetings; do printf '%s %s\n' "$f" "$(fp_face "$1" "$f")"; done
353
+ }
354
+
355
+ # ---------------------------------------------------------------- recorded-time fields (P290)
356
+ # A command whose manifest row declares `idempotent` must leave the state byte-identical after a
357
+ # second identical run. One field shape is legitimately *about* time: the record of when the command
358
+ # ran (`AT=` in `.pi/team/state/pm-loaded.env`). It is not exempt from the assertion — it is *named* here, and
359
+ # the probe turns it into a canary: after the first run the fixture overwrites the named field with a
360
+ # sentinel value no clock produces, runs the command again, and requires every byte (sentinel
361
+ # included) to survive. Without the sentinel the verdict would depend on the wall clock — a rewrite
362
+ # inside the same second is invisible — and that is the host-green/container-red flake this table
363
+ # exists to remove (P290). A second run that rewrites a clock field is a defect for *every* command
364
+ # that declares `idempotent`, so a field must be named here rather than silently excused; a line
365
+ # naming a field the first run did not write is itself a finding, so a stale entry cannot sit here.
366
+ # An exclusion-only comparison was rejected on purpose: it would make this probe blind to exactly
367
+ # the rewrite the declaration forbids.
368
+ declare -A IDEMPOTENT_TIME_FIELDS=(
369
+ [mark-loaded]=".pi/team/state/pm-loaded.env:AT"
370
+ )
371
+ IDEMPOTENT_SENTINEL="sentinel-not-a-clock"
372
+
373
+ idem_fields() { # <cmd> → one `relpath:field` per line (nothing when the command declares none)
374
+ case "${IDEMPOTENT_TIME_FIELDS[$1]+x}" in x) printf '%s\n' ${IDEMPOTENT_TIME_FIELDS[$1]} ;; esac
375
+ return 0
376
+ }
377
+
378
+ idem_stamp() { # <cmd> <dir> <outfile> — overwrite each declared recorded-time field with the sentinel
379
+ local cmd="$1" d="$2" out="$3" spec rel field f
380
+ while IFS= read -r spec; do
381
+ [ -n "$spec" ] || continue
382
+ rel="${spec%%:*}"; field="${spec#*:}"
383
+ f="$d/$rel"
384
+ if [ ! -f "$f" ] || ! grep -q "^$field=" "$f" 2>/dev/null; then
385
+ finding "claims: $cmd 声明的记录时间字段 $field 不在 $rel 里(声明过期:不静默通过,见 IDEMPOTENT_TIME_FIELDS)"
386
+ continue
387
+ fi
388
+ if awk -v k="$field" -v v="$IDEMPOTENT_SENTINEL" 'index($0, k"=") == 1 { print k"="v; next } { print }' "$f" > "$f.p290"; then
389
+ mv "$f.p290" "$f"
390
+ printf '%s\n' "$spec" >> "$out"
391
+ else
392
+ rm -f "$f.p290"
393
+ finding "claims: $cmd 声明的记录时间字段 $field 没盖上哨兵(夹具写入失败)"
394
+ fi
395
+ done < <(idem_fields "$cmd")
396
+ return 0
397
+ }
398
+
399
+ idem_names() { # <stamped-file> → ` AT(.pi/team/state/pm-loaded.env)` — names the fields in the result line
400
+ local s out=""
401
+ while IFS= read -r s; do
402
+ [ -n "$s" ] || continue
403
+ out="$out ${s#*:}(${s%%:*})"
404
+ done < "$1"
405
+ printf '%s' "$out"
406
+ }
407
+
408
+ new_repo() { # <name> → a fresh git repository
409
+ local d="$tmp/fx/$1"
410
+ rm -rf "$d"; mkdir -p "$d"
411
+ ( cd "$d" && git init -q -b main && git config user.email hs@teamsmith && git config user.name hs \
412
+ && printf '{"name":"%s","scripts":{"verify":"true"}}\n' "$1" > package.json \
413
+ && git add -A && git commit -qm init ) >/dev/null 2>&1
414
+ printf '%s\n' "$d"
415
+ }
416
+
417
+ env_run() { # <dir> <argv…> → the CLI in the fixture; HS_OUT / HS_RC
418
+ # HS_ENV carries extra VAR=VAL words for this call, HS_STDIN the stdin source (default /dev/null)
419
+ local d="$1"; shift
420
+ local out rc
421
+ out="$( cd "$d" && env -u TMUX -u TMUX_PANE -u TEAM_ROOT -u TEAM_MAIN_ROOT -u TEAM_PROJECT -u TEAM_SESSION \
422
+ PATH="$SHIM:$PATH" TEAM_PI_BIN="$SHIM/fakeagent" \
423
+ TEAM_MEETINGS_DIR="$TEAM_MEETINGS_DIR" TEAM_PI_AGENT_DIR="$tmp/pi-agent" \
424
+ ${HS_ENV:-} \
425
+ ${TIMEOUT_BIN:+"$TIMEOUT_BIN" "$timeout_sec"} bash "$team" "$@" <"${HS_STDIN:-/dev/null}" 2>&1 )"
426
+ rc=$?
427
+ HS_OUT="$out"; HS_RC="$rc"
428
+ }
429
+
430
+ setup_fixture() { # <setup-id> <dir>
431
+ local id="$1" d="$2" sess="$3"
432
+ case "$id" in
433
+ repo) : ;;
434
+ proj|task|wt|live|seat)
435
+ env_run "$d" init --no-skills --session "$sess" --agents "dev verify" --vcs local --gates true \
436
+ --docs docs/team --task-models 'code=provider/model-fast' --pm-model 'provider/model-strong' \
437
+ --pm-window pm > "$tmp/logs/$sess-init.log" 2>&1 || {
438
+ printf 'init failed for %s:\n%s\n' "$sess" "$(tail -3 "$tmp/logs/$sess-init.log")" >&2; return 1; }
439
+ ;;
440
+ *) printf 'unknown setup %s\n' "$id" >&2; return 1 ;;
441
+ esac
442
+ case "$id" in
443
+ seat)
444
+ # P292 · interrupt 探针的浅现场:“一条席位”的派单记录(窗口 / 工作树 / sid)+ 窗口表里的一行 +
445
+ # 一个**真**的 stub agent 进程(argv[0] 命中探针的 TEAM_AGENT_BIN,身份在它自己的 environ 里)。
446
+ # pane 由记录器 shim 回答(HS_PANE_PID_FILE,见 probe_env_of);进程是真的,所以证明链读到的
447
+ # 是内核里的 /proc(cmdline / environ / stat),不是夹具编的。
448
+ local wt="$d/.worktrees/dev"
449
+ mkdir -p "$wt" "$d/.pi/team/state" "$d/docs/team/threads" "$d/docs/team/inbox" "$d/docs/team/tasks"
450
+ grep -qxF "$sess:dev" "$tmp/windows.reg" 2>/dev/null || printf '%s\n' "$sess:dev" >> "$tmp/windows.reg"
451
+ printf 'assignment_version=1\ntask=T1\ntaskfile=%s\ncategory=code\nbranch=task/T1-first-task\nworktree=%s\nwindow=dev\nseat=dev\nmodel=provider/model-fast\nselected_via=policy\nlaunch_via=policy\nsid=p-interrupt-sid\nlaunch_nonce=probe-nonce\nstarted=2026-01-01T00:00:00Z\nsid_bytes=0\nmode=continued\nidentity_via=provider,model,session_id\n' \
452
+ "$d/docs/team/tasks/T1-first-task.md" "$wt" > "$d/.pi/team/state/dev.env" || {
453
+ printf 'interrupt 现场:写不进派单记录(%s)\n' "$d/.pi/team/state/dev.env" >&2; return 1; }
454
+ setsid env TEAM_MAIN_ROOT="$d" TEAM_ROOT="$wt" HS_STUB_PARENT="$$" \
455
+ "$SHIM/interrupt-agent" </dev/null >/dev/null 2>&1 &
456
+ printf '%s\n' "$!" > "$tmp/pane-pids/interrupt"
457
+ return 0
458
+ ;;
459
+ esac
460
+ case "$id" in
461
+ task|wt|live)
462
+ env_run "$d" task T1 --title "First task" --category code --agent dev > "$tmp/logs/$sess-task.log" 2>&1 || return 1
463
+ # the brief needs a resolvable anchor (the dispatch refuses a bare `-`); rewrite the line
464
+ # the template carries instead of adding a second one (two anchor lines are refused too)
465
+ local brief="$d/docs/team/tasks/T1-first-task.md"
466
+ if [ -f "$brief" ]; then
467
+ awk '{ if ($0 ~ /^anchor:/) { print "anchor: none (infra) — the probe fixture"; next } ; print }' "$brief" > "$brief.tmp" && mv "$brief.tmp" "$brief"
468
+ fi
469
+ ;;
470
+ esac
471
+ case "$id" in
472
+ wt|live)
473
+ git -C "$d" worktree add -q -b task/T1-first-task "$d/.worktrees/dev" main >/dev/null 2>&1 || true
474
+ ;;
475
+ esac
476
+ case "$id" in
477
+ live)
478
+ ( cd "$d/.worktrees/dev" 2>/dev/null || cd "$d" ) || true
479
+ env_run "$d" dispatch dev T1 docs/team/tasks/T1-first-task.md --branch task/T1-first-task > "$tmp/logs/$sess-dispatch.log" 2>&1 || true
480
+ ;;
481
+ esac
482
+ return 0
483
+ }
484
+
485
+ # the probe recipes: one per command — <setup>|<argv>
486
+ probe_recipe() {
487
+ case "$1" in
488
+ help) printf 'repo|help\n' ;;
489
+ bootstrap) printf 'repo|bootstrap --agents dev --task-models code=provider/model-fast --pm-model provider/model-strong --pm-window pm\n' ;;
490
+ init) printf 'repo|init --session PROBE --agents dev --vcs local --gates true --docs docs/team --task-models code=provider/model-fast --pm-model provider/model-strong --pm-window pm\n' ;;
491
+ doctor) printf 'proj|doctor\n' ;;
492
+ roster) printf 'proj|roster\n' ;;
493
+ status) printf 'proj|status\n' ;;
494
+ ps) printf 'proj|ps\n' ;;
495
+ bg) printf 'proj|bg list\n' ;;
496
+ reap) printf 'proj|reap --orphans --yes\n' ;;
497
+ interrupt) printf 'seat|interrupt dev --reason probe --yes\n' ;;
498
+ digest) printf 'proj|digest\n' ;;
499
+ inbox) printf 'proj|inbox\n' ;;
500
+ paths) printf 'proj|paths\n' ;;
501
+ config) printf 'proj|config set TEAM_PULSE_INTERVAL 600 --yes\n' ;;
502
+ task) printf 'proj|task T1 --title "First task" --category code --agent dev\n' ;;
503
+ board) printf 'task|board set T1 wip\n' ;;
504
+ change) printf 'task|change status T1\n' ;;
505
+ thread) printf 'proj|thread dev "one line"\n' ;;
506
+ report) printf 'task|report T1 dev\n' ;;
507
+ add-agent) printf 'proj|add-agent dev --create\n' ;;
508
+ dispatch) printf 'wt|dispatch dev T1 docs/team/tasks/T1-first-task.md --branch task/T1-first-task\n' ;;
509
+ say) printf 'wt|say dev "one line" --now\n' ;;
510
+ notify) printf 'proj|notify pm "one line"\n' ;;
511
+ draft) printf 'proj|draft send DRAFT --now\n' ;;
512
+ outbox) printf 'proj|outbox list\n' ;;
513
+ reply) printf 'proj|reply post --from pm --title "decision" --stdin\n' ;;
514
+ pulse) printf 'proj|pulse up\n' ;;
515
+ monitor) printf 'proj|monitor --print --no-activity --once\n' ;;
516
+ watch) printf 'proj|watch --once\n' ;;
517
+ standby) printf 'proj|standby on --reason "probe"\n' ;;
518
+ meeting) printf 'proj|meeting open probe --with other:other --topic topic --yes\n' ;;
519
+ up) printf 'proj|up --fresh-pm\n' ;;
520
+ resume) printf 'live|resume --agent dev\n' ;;
521
+ review) printf 'wt|review T1 --dir REVIEWDIR --no-gates\n' ;;
522
+ close) printf 'live|close T1\n' ;;
523
+ teardown) printf 'wt|teardown --agent dev --purge\n' ;;
524
+ smoke) printf 'proj|smoke --select 0\n' ;;
525
+ perf) printf 'proj|perf --host\n' ;;
526
+ merge) printf 'proj|merge\n' ;;
527
+ pr) printf 'proj|pr\n' ;;
528
+ gh) printf 'proj|gh\n' ;;
529
+ gl) printf 'proj|gl\n' ;;
530
+ mark-loaded) printf 'proj|mark-loaded --version 0.0.0\n' ;;
531
+ version) printf 'proj|version\n' ;;
532
+ changelog) printf 'proj|changelog\n' ;;
533
+ reload) printf 'proj|reload\n' ;;
534
+ *) return 1 ;;
535
+ esac
536
+ }
537
+
538
+ # probe_prepare <cmd> <dir> <setup> — the per-command extras a recipe needs before it runs
539
+ probe_prepare() {
540
+ local cmd="$1" d="$2"
541
+ case "$cmd" in
542
+ draft) printf '# note\n' > "$d/draft.md" ;;
543
+ review) git -C "$d" worktree add -q -b task/P1 "$d/../$cmd-autoreview" main >/dev/null 2>&1 || true ;;
544
+ esac
545
+ return 0
546
+ }
547
+
548
+ # usage_entries <page-file> → one line per usage entry: an indent-2 line starts one, deeper lines
549
+ # continue it. This is the same shape tests/routes.sh reads, so both fixtures judge the same thing.
550
+ usage_entries() {
551
+ awk '
552
+ { line=$0
553
+ if (line ~ /^[ \t]*$/) next
554
+ n=match(line, /[^ ]/); ind=n-1
555
+ if (ind == 2) { if (cur != "") print cur; cur = substr(line, 3); next }
556
+ if (ind == 4 && cur != "") { cur = cur " " substr(line, 5); next }
557
+ if (cur != "") { print cur; cur = "" }
558
+ }
559
+ END { if (cur != "") print cur }
560
+ ' "$1"
561
+ }
562
+
563
+ # manifest_fragments <command> → the usage fragments the manifest declares, one per line
564
+ manifest_fragments() {
565
+ awk -F'\t' -v c="$1" '$1=="cmd" && $2==c {n=split($4,f," ;; "); for(i=1;i<=n;i++) print f[i]}' "$str/commands.tsv"
566
+ }
567
+
568
+ # manifest_group_commands <group> → the commands the manifest puts in that group, in order
569
+ manifest_group_commands() {
570
+ awk -F'\t' -v g="$1" '$1=="cmd" && $3==g {print $2}' "$str/commands.tsv"
571
+ }
572
+
573
+ # ---------------------------------------------------------------- pages (rendered once, checked many times)
574
+ pages_tsv="$tmp/pages.tsv"; : > "$pages_tsv"
575
+ # page_list → the pages this fixture renders: the menu, every group page and every command page
576
+ page_list() {
577
+ local g c
578
+ if [ -n "${TEAM_HELP_SURFACE_ONLY:-}" ]; then
579
+ for c in ${TEAM_HELP_SURFACE_ONLY}; do printf 'command\t%s\n' "$c"; done
580
+ return 0
581
+ fi
582
+ printf 'menu\t-\n'
583
+ for g in "${MG_GROUPS[@]}"; do printf 'group\t%s\n' "$g"; done
584
+ for c in "${MG_ORDER[@]}"; do printf 'command\t%s\n' "$c"; done
585
+ }
586
+
587
+ # render_into <dir> <lang> [<locale>] [<width>] — renders the whole page list into <dir>
588
+ render_into() {
589
+ local dir="$1" lang="$2" loc="${3:-}" w="${4:-}"
590
+ mkdir -p "$dir"
591
+ page_list | awk -F'\t' '{printf "%s:%s\n", $1, $2}' \
592
+ | xargs -P 6 -I@ bash "$0" --render-one "$lang" @ "$dir" "$loc" "$w" >/dev/null 2>&1
593
+ }
594
+
595
+ render_pages() { # <lang>
596
+ local lang="$1" dir jobs
597
+ dir="$tmp/pages/$lang"; jobs="$tmp/jobs-$lang.txt"
598
+ mkdir -p "$dir"; : > "$jobs"
599
+ page_list > "$jobs"
600
+ awk -F'\t' '{printf "%s:%s\n", $1, $2}' "$jobs" \
601
+ | xargs -P 6 -I@ bash "$0" --render-one "$lang" @ "$dir" >/dev/null 2>&1
602
+ while IFS=$'\t' read -r kind label; do
603
+ [ "$label" = "-" ] && label=menu
604
+ printf '%s\t%s\t%s\t%s/%s--%s.txt\n' "$kind" "$label" "$lang" "$dir" "$kind" "$label" >> "$pages_tsv"
605
+ done < "$jobs"
606
+ }
607
+
608
+ # page_text <lang> <kind> <label> → the rendered page
609
+ page_text() { cat "$tmp/pages/$1/$2--$3.txt"; }
610
+
611
+ # ---------------------------------------------------------------- locale and width
612
+ # This group's oracle is the fixture's own locale-independent counter (python3's unicodedata) and
613
+ # never the renderer's functions: the point is that an independent reader disagrees with a renderer
614
+ # that takes its display widths from the locale.
615
+ locale_diff() { # <a> <b> <tag> → one line naming the first differing line
616
+ python3 - "$1" "$2" "$3" <<'PYEOF'
617
+ import sys
618
+ a = open(sys.argv[1], 'rb').read().split(b'\n')
619
+ b = open(sys.argv[2], 'rb').read().split(b'\n')
620
+ for i, (x, y) in enumerate(zip(a, b), 1):
621
+ if x != y:
622
+ print("%s: line %d differs" % (sys.argv[3], i))
623
+ break
624
+ else:
625
+ if len(a) != len(b):
626
+ print("%s: line count %d vs %d" % (sys.argv[3], len(a), len(b)))
627
+ PYEOF
628
+ }
629
+
630
+ locale_violations() { # <width> <tag-prefix> <file…> → one line per over-wide line or invalid byte
631
+ python3 - "$@" <<'PYEOF'
632
+ import sys, unicodedata
633
+ width = int(sys.argv[1]); prefix = sys.argv[2]
634
+ for path in sys.argv[3:]:
635
+ name = path.rsplit('/', 1)[-1][:-4]
636
+ data = open(path, 'rb').read()
637
+ try:
638
+ text = data.decode('utf-8')
639
+ except UnicodeDecodeError as exc:
640
+ print("%s%s: not valid UTF-8 (%s)" % (prefix, name, exc))
641
+ continue
642
+ for i, line in enumerate(text.split('\n'), 1):
643
+ w = sum(2 if unicodedata.east_asian_width(c) in 'WF' else 1 for c in line)
644
+ if w > width:
645
+ print("%s%s: line %d is %d cells, over %d (%s)" % (prefix, name, i, w, width, line.strip()[:40]))
646
+ PYEOF
647
+ }
648
+
649
+ check_locale() {
650
+ section "locale · 同一输入在任何 locale 下同一份字节、每行不超过 TEAM_HELP_WIDTH、输出合法 UTF-8"
651
+ if ! command -v python3 >/dev/null 2>&1; then
652
+ skip "locale: 没有 python3(本组用它自己的 unicodedata 计数,不调用渲染器)"
653
+ return 0
654
+ fi
655
+ local dw=100 aw=64 lang page run w n bad first
656
+ local -a pages=() langs=(en zh)
657
+ while IFS=$'\t' read -r _k _l; do
658
+ [ "$_l" = "-" ] && _l=menu
659
+ pages+=("$_k--$_l")
660
+ done < <(page_list)
661
+ if [ "${#pages[@]}" = "0" ]; then finding "locale: 页面清单是空的"; return 0; fi
662
+ for lang in "${langs[@]}"; do
663
+ render_into "$tmp/locale/$lang/C/$dw" "$lang" C "$dw"
664
+ render_into "$tmp/locale/$lang/C.UTF-8/$dw" "$lang" C.UTF-8 "$dw"
665
+ render_into "$tmp/locale/$lang/C.UTF-8/$aw" "$lang" C.UTF-8 "$aw"
666
+ done
667
+ for lang in "${langs[@]}"; do
668
+ # ① one tree, one TEAM_LANG, one TEAM_HELP_WIDTH → the same bytes under LC_ALL=C and C.UTF-8
669
+ n=0; bad=""
670
+ for page in "${pages[@]}"; do
671
+ cmp -s "$tmp/locale/$lang/C/$dw/$page.txt" "$tmp/locale/$lang/C.UTF-8/$dw/$page.txt" && continue
672
+ n=$((n + 1))
673
+ if [ "$n" -le 3 ]; then
674
+ bad="$bad $page[$(locale_diff "$tmp/locale/$lang/C/$dw/$page.txt" \
675
+ "$tmp/locale/$lang/C.UTF-8/$dw/$page.txt" x | sed 's/^x: //')]"
676
+ fi
677
+ done
678
+ if [ "$n" = "0" ]; then ok "locale($lang): ${#pages[@]} 个页面在 LC_ALL=C 与 LC_ALL=C.UTF-8 下逐字节相同"
679
+ else finding "locale($lang): $n 个页面随 locale 变:$bad"; fi
680
+ # ② every run is valid UTF-8 and every line fits the width it was rendered with
681
+ for run in "C/$dw" "C.UTF-8/$dw" "C.UTF-8/$aw"; do
682
+ case "$run" in */"$aw") w="$aw" ;; *) w="$dw" ;; esac
683
+ local -a files=()
684
+ for page in "${pages[@]}"; do files+=("$tmp/locale/$lang/$run/$page.txt"); done
685
+ n=0; bad=""
686
+ while IFS= read -r first; do
687
+ [ -n "$first" ] || continue
688
+ n=$((n + 1))
689
+ [ "$n" -le 3 ] && bad="$bad $first"
690
+ done < <(locale_violations "$w" "" "${files[@]}")
691
+ if [ "$n" = "0" ]; then ok "locale($lang, $run): ${#pages[@]} 个页面都是合法 UTF-8 且每行 ≤ $w 格"
692
+ else finding "locale($lang, $run): $n 个页面越界或不是合法 UTF-8:$bad"; fi
693
+ done
694
+ done
695
+ return 0
696
+ }
697
+
698
+ # ---------------------------------------------------------------- coverage
699
+ check_coverage() {
700
+ section "coverage · 清单 ↔ dispatcher ↔ 三级渲染"
701
+ local labels; labels="$( { printf 'help\n'; team_labels; } | sort -u )"
702
+ local missing=0 n
703
+ for n in $labels; do
704
+ if [ -n "${MG_GROUP[$n]+x}" ]; then continue; fi
705
+ local aliased=0 c a
706
+ for c in "${MG_ORDER[@]}"; do
707
+ for a in ${MG_ALIASES[$c]}; do [ "$a" = "$n" ] && aliased=1; done
708
+ done
709
+ if [ "$aliased" = "0" ]; then finding "dispatcher 接受的 $n 在清单里没有记录(也没有别名声明)"; missing=1; fi
710
+ done
711
+ [ "$missing" = "0" ] && ok "dispatcher 的每个标签都有记录或别名声明($(printf '%s\n' $labels | wc -l) 个标签)"
712
+ local orphan=0
713
+ for c in "${MG_ORDER[@]}"; do
714
+ printf '%s\n' $labels | grep -qx "$c" || { finding "清单里的 $c 不是一个 dispatcher 标签"; orphan=1; }
715
+ done
716
+ [ "$orphan" = "0" ] && ok "清单里每个命令都被 dispatcher 接受"
717
+ # group ids resolve and do not collide with a command name
718
+ local g collide=0
719
+ for g in "${MG_GROUPS[@]}"; do
720
+ [ -n "${MG_GROUP[$g]+x}" ] && { finding "分组 id $g 与命令名冲突"; collide=1; }
721
+ grep -q "^ " "$tmp/pages/en/group--$g.txt" 2>/dev/null || { finding "分组 $g 的组页是空的"; collide=1; }
722
+ done
723
+ [ "$collide" = "0" ] && ok "每个分组 id 都能解析到组页,且不与命令名冲突"
724
+ # every command has a page whose usage block names its own path
725
+ local bad=0
726
+ for c in "${MG_ORDER[@]}"; do
727
+ local pg="$tmp/pages/en/command--$c.txt"
728
+ [ -s "$pg" ] || { finding "命令 $c 没有页"; bad=1; continue; }
729
+ grep -q "^ $c\( \|$\)" "$pg" || { finding "命令 $c 的页没有以它自己开头的用法行"; bad=1; }
730
+ done
731
+ [ "$bad" = "0" ] && ok "每个命令都有页,且用法块里以自己开头(${#MG_ORDER[@]} 个命令)"
732
+ # no page may print a missing-key marker: a marker means the surface is incomplete, and the
733
+ # key-set checks below make a genuinely missing key impossible on a clean tree
734
+ local markers=0
735
+ for c in "${MG_ORDER[@]}"; do
736
+ local pg="$tmp/pages/en/command--$c.txt"
737
+ local hits; hits="$(grep -c 'missing key' "$pg" 2>/dev/null || true)"
738
+ [ "${hits:-0}" -gt 0 ] || continue
739
+ finding "命令 $c 的页打印了缺键标记:$(grep -m1 'missing key' "$pg" | sed 's/^ *//' | cut -c1-60)"
740
+ markers=1
741
+ done
742
+ for g in "${MG_GROUPS[@]}"; do
743
+ local pg="$tmp/pages/en/group--$g.txt"
744
+ local hits; hits="$(grep -c 'missing key' "$pg" 2>/dev/null || true)"
745
+ [ "${hits:-0}" -gt 0 ] || continue
746
+ finding "组页 $g 打印了缺键标记"
747
+ markers=1
748
+ done
749
+ if grep -q 'missing key' "$tmp/pages/en/menu--menu.txt" 2>/dev/null; then
750
+ finding "菜单打印了缺键标记"; markers=1
751
+ fi
752
+ [ "$markers" = "0" ] && ok "没有任何页面打印缺键标记(清单字段与散文键一一对上)"
753
+
754
+ # a command with no flags prints no argument row, and one with flags prints exactly one per flag
755
+ local argrow=0
756
+ for c in "${MG_ORDER[@]}"; do
757
+ local pg="$tmp/pages/en/command--$c.txt" rows
758
+ rows="$(awk '
759
+ { line=$0; if (line ~ /^[ \t]*$/) next
760
+ n=match(line, /[^ ]/); ind=n-1
761
+ if (ind == 6) { inargs = (line ~ /^ *Arguments/) }
762
+ if (inargs && ind == 10 && line !~ /^ *$/) print line }
763
+ ' "$pg" | wc -l)"
764
+ local want=0
765
+ [ "${MG_FLAGS[$c]}" = "-" ] || want="$(printf '%s\n' ${MG_FLAGS[$c]} | grep -c . || true)"
766
+ if [ "$rows" != "$want" ]; then
767
+ finding "命令 $c 的 Arguments 有 $rows 行,清单声明 $want 个旗标"
768
+ argrow=1
769
+ fi
770
+ done
771
+ [ "$argrow" = "0" ] && ok "每个命令页的 Arguments 行数与该命令的旗标数相同(${#MG_ORDER[@]} 个命令)"
772
+
773
+ # the pages print exactly the usage lines the manifest declares (both directions)
774
+ local drift=0
775
+ for c in "${MG_ORDER[@]}"; do
776
+ local pg="$tmp/pages/en/command--$c.txt" want got
777
+ want="$(manifest_fragments "$c" | sort)"
778
+ got="$(usage_entries "$pg" | sort)"
779
+ if [ "$want" != "$got" ]; then
780
+ finding "命令 $c 的页与清单不一致($(diff <(printf '%s\n' "$want") <(printf '%s\n' "$got") | grep '^[<>]' | head -2 | paste -sd ' ' -))"
781
+ drift=1
782
+ fi
783
+ done
784
+ [ "$drift" = "0" ] && ok "每个命令页打印的用法行与清单逐条相同(${#MG_ORDER[@]} 个命令 × 全部用法片段)"
785
+ # every group page prints exactly its group's usage lines, in the manifest's order
786
+ local gdrift=0
787
+ for g in "${MG_GROUPS[@]}"; do
788
+ local pg="$tmp/pages/en/group--$g.txt" want got
789
+ want="$(manifest_group_commands "$g" | while read -r c2; do manifest_fragments "$c2" | head -1; done)"
790
+ got="$(usage_entries "$pg")"
791
+ if [ "$want" != "$got" ]; then
792
+ finding "组页 $g 与清单不一致($(diff <(printf '%s\n' "$want") <(printf '%s\n' "$got") | grep '^[<>]' | head -2 | paste -sd ' ' -))"
793
+ gdrift=1
794
+ fi
795
+ done
796
+ [ "$gdrift" = "0" ] && ok "每个组页打印的用法行与清单逐条相同(${#MG_GROUPS[@]} 个组)"
797
+ # aliases reach their primary with an alias line
798
+ local aw=0
799
+ for c in "${MG_ORDER[@]}"; do
800
+ for a in ${MG_ALIASES[$c]}; do
801
+ [ "$a" = "-" ] && continue
802
+ local out extra
803
+ out="$(page en "$a" --help)"
804
+ extra="$(diff <(page en "$c" --help) <(printf '%s\n' "$out") | grep '^>' | sed 's/^> //')"
805
+ if [ "$(printf '%s\n' "$extra" | grep -c .)" != "1" ]; then
806
+ finding "别名 $a 打印的页比 $c 的页多了 $(printf '%s\n' "$extra" | grep -c .) 行(应只多一条别名行)"; aw=1
807
+ elif ! printf '%s' "$extra" | grep -q "$a" || ! printf '%s' "$extra" | grep -q "$c"; then
808
+ finding "别名 $a 的别名行没有同时点名别名与主命令"; aw=1
809
+ fi
810
+ done
811
+ done
812
+ [ "$aw" = "0" ] && ok "每个别名都打印主命令的页并点名该别名"
813
+
814
+ # O2 · the dispatcher's internal entries are a closed set, declared in one place (here)
815
+ local internal="__inbox-write __panel-data"
816
+ local found want nm extra="" miss="" n
817
+ found="$(team_internal_labels)"
818
+ want="$(printf '%s\n' $internal | sort -u)"
819
+ for n in $found; do printf '%s\n' $want | grep -qx "$n" || extra="$extra $n"; done
820
+ for n in $want; do printf '%s\n' $found | grep -qx "$n" || miss="$miss $n"; done
821
+ if [ -n "$extra" ]; then finding "内部入口清单:dispatcher 的 __ 标签$extra 不在声明清单里"; fi
822
+ if [ -n "$miss" ]; then finding "内部入口清单:声明清单里的$miss 已经不是 dispatcher 的 __ 标签"; fi
823
+ if [ -z "$extra" ] && [ -z "$miss" ]; then
824
+ ok "内部入口清单与 dispatcher 的 __ 标签双向相等($(printf '%s\n' $want | grep -c . ) 个)"
825
+ fi
826
+ local leak=0 d hits
827
+ for d in "$tmp/pages/en" "$tmp/pages/zh"; do
828
+ [ -d "$d" ] || continue
829
+ for n in $internal; do
830
+ hits="$(grep -rl -e "$n" "$d" 2>/dev/null | head -3 | while read -r f; do basename "$f"; done | paste -sd ' ' -)"
831
+ [ -n "$hits" ] && { finding "页面打印了内部入口 $n:$hits"; leak=1; }
832
+ done
833
+ done
834
+ [ "$leak" = "0" ] && ok "没有任何页面打印内部入口的名字(菜单/组页/命令页,两种语言)"
835
+ local pre=0
836
+ for n in "${MG_ORDER[@]}"; do
837
+ case "$n" in __*) finding "清单里的命令名 $n 以 __ 开头(内部入口不许进清单)"; pre=1 ;; esac
838
+ done
839
+ [ "$pre" = "0" ] && ok "清单里没有以 __ 开头的命令名"
840
+
841
+ # O6 · reachability is judged from the manifest: the menu names every declared group and no other,
842
+ # and every command is listed by a group page whose group the menu has an entry point for
843
+ local declared named g c unreach rg=0
844
+ declared="$(printf '%s\n' "${MG_GROUPS[@]}" | sort -u)"
845
+ named="$(awk '/^──/{exit} /^ [^ ]/{print $1}' "$tmp/pages/en/menu--menu.txt" 2>/dev/null | sort -u)"
846
+ for g in $declared; do
847
+ printf '%s\n' "$named" | grep -qx "$g" && continue
848
+ unreach="$(manifest_group_commands "$g" | paste -sd ' ' -)"
849
+ finding "分组 $g 在菜单里没有入口,它下面的命令${unreach:-(无)}变成不可达"
850
+ rg=1
851
+ done
852
+ for g in $named; do
853
+ printf '%s\n' "$declared" | grep -qx "$g" || { finding "菜单点名了清单没有声明的分组 $g"; rg=1; }
854
+ done
855
+ [ "$rg" = "0" ] && ok "菜单的分组入口与清单的分组表双向相等(${#MG_GROUPS[@]} 个组)"
856
+ local reach=0
857
+ for c in "${MG_ORDER[@]}"; do
858
+ g="${MG_GROUP[$c]}"
859
+ if ! printf '%s\n' "$declared" | grep -qx "$g"; then
860
+ finding "命令 $c 不可达:它的分组 $g 没有声明,没有组页会列它"; reach=1; continue
861
+ fi
862
+ if ! printf '%s\n' "$named" | grep -qx "$g"; then
863
+ finding "命令 $c 不可达:它的分组 $g 在菜单里没有入口"; reach=1; continue
864
+ fi
865
+ grep -q "^ $c\( \|$\)" "$tmp/pages/en/group--$g.txt" 2>/dev/null \
866
+ || { finding "命令 $c 不可达:组页 $g 没有列出它"; reach=1; }
867
+ done
868
+ [ "$reach" = "0" ] && ok "每个命令都能从菜单经组页在三级内到达(${#MG_ORDER[@]} 个命令)"
869
+
870
+ # G4 · an undeclared `{…}` token must fail the render instead of being printed (scratch copy)
871
+ local g4="$tmp/g4-guard"
872
+ rm -rf "$g4"; mkdir -p "$g4/skills"
873
+ cp -a "$skill" "$g4/skills/teamsmith"
874
+ if python3 - "$g4/skills/teamsmith/scripts/strings/help.en.tsv" <<'PYEOF'
875
+ import sys
876
+ p = sys.argv[1]
877
+ s = open(p, encoding="utf-8").read()
878
+ key = "cmd.dispatch.what\t"
879
+ i = s.index(key) + len(key)
880
+ j = s.index("\n", i)
881
+ open(p, "w", encoding="utf-8").write(s[:j] + " {undeclared}" + s[j:])
882
+ PYEOF
883
+ then
884
+ local g4out g4rc
885
+ g4out="$( cd "$tmp" && TEAM_LANG=en bash "$g4/skills/teamsmith/scripts/team" help dispatch 2>&1 )"; g4rc=$?
886
+ if [ "$g4rc" = "0" ]; then
887
+ finding "G4:表里出现未声明的 {undeclared} 时渲染仍 exit 0(那一页会把它原样打出来)"
888
+ elif ! printf '%s' "$g4out" | grep -qF '{undeclared}'; then
889
+ finding "G4:渲染非零退出(rc=$g4rc)但没有点名 {undeclared}"
890
+ elif ! printf '%s' "$g4out" | grep -qF 'help.en.tsv'; then
891
+ finding "G4:点名了 token 却没说它来自哪张表($(printf '%s' "$g4out" | head -1 | cut -c1-60))"
892
+ elif printf '%s' "$g4out" | grep -q 'Usage'; then
893
+ finding "G4:渲染失败却仍打印了那一页"
894
+ else
895
+ ok "G4:未声明的 {undeclared} 让渲染非零退出(rc=$g4rc)、点名 token 与来源表、且不打印那一页"
896
+ fi
897
+ else
898
+ finding "G4:夹具没能把 {undeclared} 写进 scratch 副本"
899
+ fi
900
+ rm -rf "$g4"
901
+ return 0
902
+ }
903
+
904
+ # ---------------------------------------------------------------- language
905
+ check_lang() {
906
+ section "lang · 默认英文、TEAM_LANG 的机制(切中文 / 非法值告警回退 / 缺键可见)、机器出口"
907
+ local en zh
908
+ en="$(page en help)"; zh="$(page zh help)"
909
+ if printf '%s' "$en" | has_cjk; then finding "缺省语言不是英文(菜单里有 CJK 字符)"; else ok "缺省语言是英文"; fi
910
+ if printf '%s' "$zh" | has_cjk; then ok "TEAM_LANG=zh 切到中文"; else finding "TEAM_LANG=zh 没有切到中文"; fi
911
+ # the structure is byte-identical between the languages: the usage lines must be
912
+ local same=1
913
+ for c in "${MG_ORDER[@]}"; do
914
+ diff -q <(page en help "$c" | grep -E '^ [^ ]') <(page zh help "$c" | grep -E '^ [^ ]') >/dev/null 2>&1 || {
915
+ finding "命令 $c 的用法行在两种语言下不相同"; same=1; }
916
+ done
917
+ [ "$same" = "1" ] && ok "命令路径、旗标与用法片段在两种语言下逐字节相同"
918
+ # invalid value: one warning naming it, English surface, status unchanged
919
+ local warn out rc
920
+ out="$( cd "$tmp" && TEAM_LANG=fr bash "$team" help 2>"$tmp/hs-warn.txt" )"; rc=$?
921
+ warn="$(cat "$tmp/hs-warn.txt")"
922
+ if [ "$rc" = "0" ] && printf '%s' "$warn" | grep -q 'TEAM_LANG=fr' && [ "$(printf '%s\n' "$warn" | grep -c .)" = "1" ]; then
923
+ ok "非法 TEAM_LANG 打印一行点名告警、状态不变(rc=0)"
924
+ else
925
+ finding "非法 TEAM_LANG 没有可见告警或状态变了(rc=$rc):$warn"
926
+ fi
927
+ printf '%s' "$out" | has_cjk && finding "非法 TEAM_LANG 没有回退英文"
928
+ # a missing key is visible: in a scratch copy whose Chinese table lacks one key, the page names
929
+ # that key in a marker and prints the other language's value (never blank, never a crash)
930
+ local mut2="$tmp/mut-lang"; rm -rf "$mut2"; mkdir -p "$mut2"
931
+ cp -a "$skill" "$mut2/teamsmith"
932
+ awk -F'\t' 'BEGIN{OFS="\t"} $1=="cmd.status.what"{next} {print}' \
933
+ "$mut2/teamsmith/scripts/strings/help.zh.tsv" > "$mut2/zh.tmp" \
934
+ && mv "$mut2/zh.tmp" "$mut2/teamsmith/scripts/strings/help.zh.tsv"
935
+ local mo
936
+ mo="$( cd "$tmp" && TEAM_LANG=zh TEAM_SKILL_DIR="$mut2/teamsmith" \
937
+ ${TIMEOUT_BIN:+"$TIMEOUT_BIN" "$timeout_sec"} bash "$mut2/teamsmith/scripts/team" help status 2>&1 )"
938
+ if printf '%s' "$mo" | grep -qE 'missing key: cmd\.status\.what» [A-Za-z]'; then
939
+ ok "缺键渲染可见:标记点名 cmd.status.what,并用英文值兜底(不空白、不崩)"
940
+ else
941
+ finding "缺键没有渲染出可见标记或没有另一语言兜底:$(printf '%s' "$mo" | grep -i 'missing' | head -1 | cut -c1-60)"
942
+ fi
943
+
944
+ # machine exits: identical under en, zh and a mutated table
945
+ local mut="$tmp/mut-help"; rm -rf "$mut"; mkdir -p "$mut"
946
+ cp -a "$str" "$mut/strings"
947
+ awk -F'\t' 'BEGIN{OFS="\t"} $1=="cmd.help.what" {$2=$2" MUTATED"} {print}' "$mut/strings/help.en.tsv" > "$mut/strings/help.en.tsv.new" \
948
+ && mv "$mut/strings/help.en.tsv.new" "$mut/strings/help.en.tsv"
949
+ local d; d="$(new_repo lang-machine)"
950
+ setup_fixture proj "$d" lang-machine || return 1
951
+ local a b c3
952
+ a="$( cd "$d" && TEAM_LANG=en PATH="$SHIM:$PATH" TEAM_PI_BIN="$SHIM/fakeagent" bash "$team" paths 2>&1 )"
953
+ b="$( cd "$d" && TEAM_LANG=zh PATH="$SHIM:$PATH" TEAM_PI_BIN="$SHIM/fakeagent" bash "$team" paths 2>&1 )"
954
+ if [ "$a" = "$b" ]; then ok "team paths --json 在两种语言下逐字节相同"; else finding "语言改变了 team paths 的输出"; fi
955
+ # the panel is a human view: it carries a clock and machine numbers, so compare it modulo the
956
+ # volatile fields (a time, a count) — a language-dependent difference must not survive that.
957
+ local m1 m2
958
+ # warm-up: the first panel in a fresh fixture fills its capacity line asynchronously, and that
959
+ # artefact must not be mistaken for a language difference
960
+ ( cd "$d" && TEAM_LANG=en PATH="$SHIM:$PATH" TEAM_PI_BIN="$SHIM/fakeagent" bash "$team" monitor --print --no-activity --once >/dev/null 2>&1 ) || true
961
+ m1="$( cd "$d" && TEAM_LANG=en PATH="$SHIM:$PATH" TEAM_PI_BIN="$SHIM/fakeagent" bash "$team" monitor --print --no-activity --once 2>&1 | volatile_scrub )"
962
+ m2="$( cd "$d" && TEAM_LANG=zh PATH="$SHIM:$PATH" TEAM_PI_BIN="$SHIM/fakeagent" bash "$team" monitor --print --no-activity --once 2>&1 | volatile_scrub )"
963
+ if [ "$m1" = "$m2" ]; then ok "team monitor --print 在两种语言下相同(已抹去时钟与计数这类易变字段)"
964
+ else
965
+ printf '%s\n' "$m1" > "$tmp/monitor-en.txt"; printf '%s\n' "$m2" > "$tmp/monitor-zh.txt"
966
+ finding "语言改变了 team monitor 的输出:$(diff "$tmp/monitor-en.txt" "$tmp/monitor-zh.txt" | head -2 | tr '\n' ' ' | cut -c1-70)(两份输出留在 $tmp)"
967
+ fi
968
+ return 0
969
+ }
970
+
971
+ help_width() { printf '%s\n' "${TEAM_HELP_WIDTH:-100}"; }
972
+
973
+ # volatile_scrub — the fields a human view carries that change between two runs (a clock, a count)
974
+ volatile_scrub() { sed -E 's/[0-9]{2}:[0-9]{2}:[0-9]{2}/TIME/g; s/[0-9]+/N/g'; }
975
+
976
+ # ---------------------------------------------------------------- claims (declarations + probes)
977
+ FACE_VOCAB="state docs config worktree skills meetings"
978
+ # mirrors scripts/lib/cmd-help.sh's declaration; the checker compares the two below
979
+ TEAM_HELP_AUTH_CONDITIONS="TEAM_CONFIRM_WRITES"
980
+ EFFECT_VOCAB="read-only writes-<face> starts-process"
981
+ # commands whose real run is a whole suite: the probe judges a bounded window (never a silent skip)
982
+ BOUNDED_PROBES="smoke perf"
983
+
984
+ probe_is_bounded() { case " $BOUNDED_PROBES " in *" $1 "*) return 0 ;; esac; return 1; }
985
+
986
+ check_vocabulary() {
987
+ local bad=0 c eff face
988
+ for c in "${MG_ORDER[@]}"; do
989
+ eff="${MG_EFFECT[$c]}"
990
+ case "$eff" in
991
+ read-only|starts-process) ;;
992
+ writes-*) face="${eff#writes-}"
993
+ case " $FACE_VOCAB " in *" $face "*) ;; *) finding "claims: $c 的 effect=$eff 用了词表外的面"; bad=1 ;; esac ;;
994
+ *) finding "claims: $c 声明了词表外的 effect=$eff"; bad=1 ;;
995
+ esac
996
+ for face in ${MG_FACES[$c]}; do
997
+ [ "$face" = "-" ] && continue
998
+ case " $FACE_VOCAB " in *" $face "*) ;; *) finding "claims: $c 的触碰面 $face 不在词表里"; bad=1 ;; esac
999
+ done
1000
+ case "${MG_AUTH[$c]}" in
1001
+ none|needs-yes) ;;
1002
+ needs-yes:*) local cond="${MG_AUTH[$c]#needs-yes:}"
1003
+ case " $TEAM_HELP_AUTH_CONDITIONS " in *" $cond "*) ;; *) finding "claims: $c 的授权条件 $cond 不在词表里"; bad=1 ;; esac ;;
1004
+ *) finding "claims: $c 声明了词表外的 auth=${MG_AUTH[$c]}"; bad=1 ;;
1005
+ esac
1006
+ case "${MG_UNDO[$c]}" in
1007
+ idempotent|undo-by-*) ;;
1008
+ not-reversible:*) [ -n "${MG_UNDO[$c]#not-reversible:}" ] || { finding "claims: $c 的 not-reversible 没有理由"; bad=1; } ;;
1009
+ *) finding "claims: $c 声明了词表外的 undo=${MG_UNDO[$c]}"; bad=1 ;;
1010
+ esac
1011
+ [ -n "${MG_EFFECT[$c]}" ] && [ -n "${MG_AUTH[$c]}" ] && [ -n "${MG_UNDO[$c]}" ] || { finding "claims: $c 三类字段不齐"; bad=1; }
1012
+ # every declared value names a probe: the probe id must exist in this file's recipe table
1013
+ probe_recipe "${MG_PROBE[$c]}" >/dev/null || { finding "claims: $c 的探针 id ${MG_PROBE[$c]} 没有配方"; bad=1; }
1014
+ done
1015
+ # the renderer's own closed set of authorization conditions must be the one this checker knows
1016
+ local declared; declared="$(grep -o 'TEAM_HELP_AUTH_CONDITIONS="[^"]*"' "$skill/scripts/lib/cmd-help.sh" | head -1 | sed 's/.*="//; s/"$//')"
1017
+ [ "$declared" = "$TEAM_HELP_AUTH_CONDITIONS" ] || { finding "claims: 渲染器声明的授权条件($declared)与夹具认识的($TEAM_HELP_AUTH_CONDITIONS)不一致"; bad=1; }
1018
+ [ "$bad" = "0" ] && ok "三类声明齐备、取值都在封闭词表里,且每个命令名到一条探针(${#MG_ORDER[@]} 个命令)"
1019
+ return 0
1020
+ }
1021
+
1022
+ probe_env_of() { # <cmd> → extra env assignments for this probe
1023
+ case "$1" in
1024
+ close) printf 'TEAM_BOARD_DONE_FORCE=1 TEAM_BOARD_DONE_REASON=probe\n' ;;
1025
+ # P276:普查读的是主机 /proc;探针把它指到一个空夹具根 —— 确定性、且绝不碰真机器上的进程。
1026
+ reap) printf 'TEAM_ORPHAN_PROC_ROOT=%s/empty-proc\n' "$tmp" ;;
1027
+ # P292:interrupt 探针的对象是一个真的 stub 席位进程(TEAM_AGENT_BIN 指到它,argv[0] 的 basename
1028
+ # 因此命中)与窗口表里的一行;pane_pid 由 shim 从这个 pid 文件回答。
1029
+ interrupt) printf 'TEAM_AGENT_BIN=%s/interrupt-agent HS_PANE_PID_FILE=%s/pane-pids/interrupt\n' "$SHIM" "$tmp" ;;
1030
+ esac
1031
+ }
1032
+
1033
+ probe_stdin_of() { # <cmd> <dir> → the stdin source for this probe (default /dev/null)
1034
+ case "$1" in
1035
+ reply) printf '%s\n' "$2/reply-body.md" ;;
1036
+ *) printf '\n' ;;
1037
+ esac
1038
+ }
1039
+
1040
+ probe_stdin_prepare() { # <cmd> <dir>
1041
+ case "$1" in
1042
+ reply) printf 'the probe body for team reply post\n' > "$2/reply-body.md" ;;
1043
+ esac
1044
+ return 0
1045
+ }
1046
+
1047
+ probe_prepare_extra() { # <cmd> <dir> <tmp> — the per-command extras that need the fixture's branches
1048
+ local cmd="$1" d="$2"
1049
+ case "$cmd" in
1050
+ review)
1051
+ rm -rf "$tmp/review-$cmd"
1052
+ git -C "$d" worktree add -q --detach "$tmp/review-$cmd" task/T1-first-task >/dev/null 2>&1 || true ;;
1053
+ esac
1054
+ return 0
1055
+ }
1056
+
1057
+ probe_prepare() { # <cmd> <dir> <setup>
1058
+ local cmd="$1" d="$2" setup="$3"
1059
+ case "$cmd" in
1060
+ draft) printf '# note\n' > "$d/draft.md" ;;
1061
+ reap) mkdir -p "$tmp/empty-proc" ;;
1062
+ resume) # a seat with unfinished work whose window is gone
1063
+ grep -v "^p-$cmd:dev$" "$tmp/windows.reg" > "$tmp/windows.reg.tmp" 2>/dev/null || true
1064
+ mv "$tmp/windows.reg.tmp" "$tmp/windows.reg" 2>/dev/null || true ;;
1065
+ esac
1066
+ return 0
1067
+ }
1068
+
1069
+ probe_args() { # <cmd> → the argv with the per-probe placeholders resolved
1070
+ local cmd="$1" d="$2" rec
1071
+ rec="$(probe_recipe "$cmd")"; rec="${rec#*|}"
1072
+ rec="${rec//PROBE/$3}"
1073
+ rec="${rec//DRAFT/$d/draft.md}"
1074
+ rec="${rec//REVIEWDIR/$tmp/review-$cmd}"
1075
+ printf '%s\n' "$rec"
1076
+ }
1077
+
1078
+ run_probe() { # <cmd> → ok/finding
1079
+ local cmd="$1" rec setup d argv envs
1080
+ rec="$(probe_recipe "$cmd")" || { finding "claims: $cmd 没有探针配方"; return 1; }
1081
+ setup="${rec%%|*}"
1082
+ d="$(new_repo "p-$cmd")"
1083
+ if ! setup_fixture "$setup" "$d" "p-$cmd" >"$tmp/logs/p-$cmd.setup" 2>&1; then
1084
+ finding "claims: $cmd 的夹具($setup)搭不起来:$(tail -1 "$tmp/logs/p-$cmd.setup")"
1085
+ return 1
1086
+ fi
1087
+ argv="$(probe_args "$cmd" "$d" "p-$cmd")"
1088
+ envs="$(probe_env_of "$cmd")"
1089
+ HS_ENV="$envs"
1090
+ HS_STDIN="$(probe_stdin_of "$cmd" "$d")"
1091
+ probe_prepare "$cmd" "$d" "$setup"
1092
+ probe_stdin_prepare "$cmd" "$d"
1093
+ probe_prepare_extra "$cmd" "$d"
1094
+ mkdir -p "$tmp/probe-tmp/$cmd"
1095
+ local eff="${MG_EFFECT[$cmd]}" faces="${MG_FACES[$cmd]}" before after i face changed missing
1096
+ before="$(fp_all "$d")"
1097
+ local launch_before launch_after
1098
+ launch_before="$(cat "$tmp/tmux-calls.log" "$tmp/launch.log" 2>/dev/null | wc -l)"
1099
+
1100
+ if probe_is_bounded "$cmd"; then
1101
+ # a whole-suite command: judge a bounded window and say so
1102
+ ( cd "$d" && env -u TMUX -u TMUX_PANE PATH="$SHIM:$PATH" TMPDIR="$tmp/probe-tmp/$cmd" \
1103
+ TEAM_PI_BIN="$SHIM/fakeagent" TEAM_MEETINGS_DIR="$TEAM_MEETINGS_DIR" \
1104
+ TEAM_PI_AGENT_DIR="$tmp/pi-agent" $envs \
1105
+ ${TIMEOUT_BIN:+"$TIMEOUT_BIN" 300} bash "$team" $argv </dev/null >"$tmp/logs/p-$cmd.out" 2>&1 )
1106
+ after="$(fp_all "$d")"
1107
+ if [ "$before" = "$after" ]; then
1108
+ ok "claims: $cmd 只读(上限 300s 内调用者未被改动;整段套件按窗口判定,见报告)"
1109
+ else
1110
+ finding "claims: $cmd 在有界窗口内改动了调用者:$(diff <(printf '%s\n' "$before") <(printf '%s\n' "$after") | head -2 | tr '\n' ' ')"
1111
+ fi
1112
+ return 0
1113
+ fi
1114
+
1115
+ if [ "${MG_AUTH[$cmd]}" = "needs-yes" ]; then
1116
+ env_run "$d" $(printf '%s' "$argv" | sed 's/--yes//') >/dev/null 2>&1
1117
+ local rc_ny="$HS_RC" out_ny="$HS_OUT" face
1118
+ after="$(fp_all "$d")"
1119
+ changed=""
1120
+ while read -r face _; do
1121
+ [ "$(printf '%s\n' "$before" | grep "^$face ")" = "$(printf '%s\n' "$after" | grep "^$face ")" ] || changed="$changed $face"
1122
+ done <<< "$after"
1123
+ changed="${changed# }"
1124
+ # 「没有 --yes 就不动手」有两种诚实形状:① 拒绝(rc≠0;既有:meeting 的条件授权);② **计划态**
1125
+ # (rc=0;interrupt 的边界规格明文写着「计划态退 0、零写盘」)。共同的不变量是「一个字都不写」
1126
+ # 加上「点名 --yes」:声明了 needs-yes 却照样动手(面有变化)或对 --yes 只字不提,都还是红。
1127
+ # (旧臂只认 ①,而且它的 case 词写成了 `$MG_AUTH[$cmd]`(没有花括号)—— 一个从不执行的死行:
1128
+ # bare needs-yes 第一次被真用到时它就以 `MG_AUTH: unbound variable` 崩掉,本段替掉它。)
1129
+ if [ -n "$changed" ]; then
1130
+ finding "claims: $cmd 声明 needs-yes,但没有 --yes 时照样动手(改了:$changed)"
1131
+ elif ! printf '%s' "$out_ny" | grep -q -- '--yes'; then
1132
+ finding "claims: $cmd 声明 needs-yes,但没有 --yes 时既不拒绝、也不点名 --yes(rc=$rc_ny)"
1133
+ elif [ "$rc_ny" = "0" ]; then
1134
+ ok "claims: $cmd 没有 --yes 时只给计划:一个字不写、点名 --yes(rc=0;计划态不是执行)"
1135
+ else
1136
+ ok "claims: $cmd 没有 --yes 时拒绝(rc=$rc_ny)、点名 --yes 且一个字不写"
1137
+ fi
1138
+ argv="$argv --yes"
1139
+ fi
1140
+
1141
+ env_run "$d" $argv >/dev/null 2>&1
1142
+ local rc="$HS_RC"
1143
+ printf '%s\n' "$HS_OUT" > "$tmp/logs/p-$cmd.out"
1144
+ after="$(fp_all "$d")"
1145
+ changed=""
1146
+ while read -r face _; do
1147
+ grep -q "^$face " <<< "$after" || continue
1148
+ [ "$(printf '%s\n' "$before" | grep "^$face ")" = "$(printf '%s\n' "$after" | grep "^$face ")" ] || changed="$changed $face"
1149
+ done <<< "$after"
1150
+ changed="${changed# }"
1151
+ launch_after="$(cat "$tmp/tmux-calls.log" "$tmp/launch.log" 2>/dev/null | wc -l)"
1152
+
1153
+ printf ' \033[2m·\033[0m 探针 %-11s rc=%-3s 变化=%-28s\n' "$cmd" "$rc" "${changed:-(无)}"
1154
+ case "$eff" in
1155
+ read-only)
1156
+ if [ -z "$changed" ]; then ok "claims: $cmd 只读(跑完后状态指纹不变)"
1157
+ else finding "claims: $cmd 声明 read-only,但它改了:$changed"; fi ;;
1158
+ starts-process)
1159
+ if [ "$launch_after" -gt "$launch_before" ]; then ok "claims: $cmd 起进程(记录器里有启动:$((launch_after - launch_before)) 条)"
1160
+ else finding "claims: $cmd 声明 starts-process,但记录器里没有启动(rc=$rc,$(head -1 "$tmp/logs/p-$cmd.out" | cut -c1-60))"; fi ;;
1161
+ writes-*)
1162
+ if [ -n "$changed" ]; then ok "claims: $cmd 写了声明的面($changed)"
1163
+ else finding "claims: $cmd 声明 $eff,但没有任何面发生变化(rc=$rc,$(head -1 "$tmp/logs/p-$cmd.out" | cut -c1-60))"; fi ;;
1164
+ esac
1165
+ # every declared touched face must have moved
1166
+ for face in $faces; do
1167
+ [ "$face" = "-" ] && continue
1168
+ case " $changed " in *" $face "*) ;; *) finding "claims: $cmd 声明触碰 $face,但该面没有变化";; esac
1169
+ done
1170
+ # F1(V52 返修轮次 1):反向判据 —— **动了的面必须都在声明里**。没有这一条,无论声明里删掉一个面
1171
+ # (`state docs` → `state`),还是实现多写一个未声明的面(真去写 `config`),探针都照样全绿:
1172
+ # 它只能证伪「声明了却没动」,不能证伪「动了却没声明」。声明的集合 = `faces` 列 ∪ `writes-<face>`
1173
+ # 效应点名的那个面;`read-only` 的「居然改了」由上面的分支判定,不在这里重复报一遍。
1174
+ if [ "$eff" != "read-only" ]; then
1175
+ for face in $changed; do
1176
+ case " $faces " in *" $face "*) continue ;; esac
1177
+ [ "$eff" = "writes-$face" ] && continue
1178
+ finding "claims: $cmd 动了没有声明的面 $face"
1179
+ done
1180
+ fi
1181
+ # undo
1182
+ case "${MG_UNDO[$cmd]}" in
1183
+ idempotent)
1184
+ # the declared recorded-time fields (IDEMPOTENT_TIME_FIELDS) get the sentinel before the second
1185
+ # run: the field is named, not excused, and the verdict cannot depend on the wall clock
1186
+ local base again stamped n_stamped lost="" s rc2 rc_missing wrote f field
1187
+ stamped="$tmp/logs/p-$cmd.stamped"; : > "$stamped"; n_stamped=0
1188
+ if [ -n "$(idem_fields "$cmd")" ]; then
1189
+ idem_stamp "$cmd" "$d" "$stamped"
1190
+ n_stamped="$(grep -c . "$stamped" 2>/dev/null || true)"
1191
+ fi
1192
+ base="$(fp_all "$d")"
1193
+ # The sentinel above covers the fields somebody *declared*. A clock-derived value nobody declared
1194
+ # is still invisible inside one second: run 1 and run 2 write the same bytes. Sleeping past a
1195
+ # second boundary makes the probe judge "a later run changed nothing" instead of "a run inside
1196
+ # the same second changed nothing" — the verdict stops depending on how fast the machine is,
1197
+ # which is exactly the clock the P290 flake hid behind (host green, container red). Cost: ~1.1s
1198
+ # per idempotent command, and only in the full gate (FAST does not run `claims`).
1199
+ sleep 1.1
1200
+ env_run "$d" $argv >/dev/null 2>&1
1201
+ rc2="$HS_RC"
1202
+ again="$(fp_all "$d")"
1203
+ # O1(V46):第二次跑的退出码也要判——「第二次失败、不写盘」若只看字节会被当成幂等(假绿)。
1204
+ # 判据是「与第一次一致」而不是「必须为 0」:夹具里 gh/gl/pr 这类命令在没有远端时本来就以非零
1205
+ # 退出(只读拒绝),要求全部为 0 会把它们判红。rc 打进输出,红时点名两次的数。
1206
+ printf ' \033[2m·\033[0m 幂等 %-11s rc=%s → %s\n' "$cmd" "$rc" "$rc2"
1207
+ if [ "$rc2" = "$rc" ]; then
1208
+ ok "claims: $cmd 幂等:第二次跑退出码与第一次一致(rc $rc → $rc2)"
1209
+ else
1210
+ finding "claims: $cmd 声明幂等,但两次跑的退出码不同(rc $rc → $rc2):第二次跑失败不算「什么都没变」"
1211
+ fi
1212
+ if [ "$base" = "$again" ]; then
1213
+ if [ "$n_stamped" = "0" ]; then
1214
+ ok "claims: $cmd 幂等(第二次跑逐字节不变)"
1215
+ else
1216
+ ok "claims: $cmd 幂等(第二次跑逐字节不变;指名的记录时间字段$(idem_names "$stamped") 经哨兵验证未被重写)"
1217
+ fi
1218
+ else
1219
+ while IFS= read -r s; do
1220
+ [ -n "$s" ] || continue
1221
+ grep -q "^${s#*:}=$IDEMPOTENT_SENTINEL$" "$d/${s%%:*}" 2>/dev/null || lost="$lost ${s#*:}(${s%%:*})"
1222
+ done < "$stamped"
1223
+ if [ -n "$lost" ]; then
1224
+ finding "claims: $cmd 声明幂等,但第二次跑重写了指名的记录时间字段$lost:哨兵值被覆盖"
1225
+ else
1226
+ finding "claims: $cmd 声明幂等,但第二次跑改了状态"
1227
+ fi
1228
+ fi
1229
+ # F1(V46 返修轮次 1):记录在、但没有指名的记录时间字段时,「没有可保留的时间」等于
1230
+ # 「没有记录」——命令必须照旧把字段补全并 rc=0。守卫若用裸赋值接一个没命中的 grep,在
1231
+ # set -e 下会把整个 CLI 带走(rc=1、一字不写):既有的 smoke §17 用的就是这个形状。
1232
+ if [ "$n_stamped" != "0" ]; then
1233
+ while IFS= read -r s; do
1234
+ [ -n "$s" ] || continue
1235
+ f="$d/${s%%:*}"; field="${s#*:}"
1236
+ grep -v "^$field=" "$f" > "$f.p290m" 2>/dev/null || true
1237
+ mv "$f.p290m" "$f"
1238
+ env_run "$d" $argv >/dev/null 2>&1
1239
+ rc_missing="$HS_RC"; wrote=no
1240
+ grep -q "^$field=" "$f" 2>/dev/null && wrote=yes
1241
+ if [ "$rc_missing" = "0" ] && [ "$wrote" = "yes" ]; then
1242
+ ok "claims: $cmd 记录里缺指名的记录时间字段 $field 时补全并 rc=0(缺时间戳不是错误)"
1243
+ else
1244
+ finding "claims: $cmd 记录里缺指名的记录时间字段 $field 时 rc=$rc_missing、字段写回=$wrote(静默失败与不补全都算缺陷)"
1245
+ fi
1246
+ done < "$stamped"
1247
+ fi ;;
1248
+ undo-by-*)
1249
+ local undo_cmd="${MG_UNDO[$cmd]#undo-by-}"
1250
+ HS_ENV=""; HS_STDIN=/dev/null
1251
+ env_run "$d" "$undo_cmd" $( [ "$undo_cmd" = "pulse" ] && printf 'down' ) >/dev/null 2>&1
1252
+ local back; back="$(fp_all "$d")"
1253
+ [ "$before" = "$back" ] && ok "claims: $cmd 的撤销命令 `team $undo_cmd` 把状态放回去了" \
1254
+ || finding "claims: $cmd 声明 undo-by-$undo_cmd,但跑完之后状态没有复原" ;;
1255
+ esac
1256
+ return 0
1257
+ }
1258
+
1259
+ check_claims() {
1260
+ section "claims · 封闭词表 + 逐命令探针(断言效应;幂等臂另判两次退出码一致)"
1261
+ check_vocabulary
1262
+ local c
1263
+ if [ -n "${TEAM_HELP_SURFACE_ONLY:-}" ]; then
1264
+ for c in ${TEAM_HELP_SURFACE_ONLY}; do run_probe "$c"; done
1265
+ return 0
1266
+ fi
1267
+ for c in "${MG_ORDER[@]}"; do
1268
+ run_probe "$c"
1269
+ done
1270
+ return 0
1271
+ }
1272
+
1273
+ # ---------------------------------------------------------------- content
1274
+ BASELINE_FLAGS=$(cat <<'EOF'
1275
+ add-agent --create --no-install --print --register
1276
+ board --allow-dup
1277
+ bootstrap --agents --pm-model --print --task-models
1278
+ changelog --since
1279
+ change --json
1280
+ dispatch --allow-overflow --branch --fresh --model --print
1281
+ draft --now
1282
+ mark-loaded --version
1283
+ meeting --all --intent --knock --note --peek --since --topic --ttl --with --yes
1284
+ monitor --events --height --interval --json --no-pulse --once --print --width
1285
+ notify --from
1286
+ outbox --now
1287
+ perf --host
1288
+ pulse --print
1289
+ reload --done
1290
+ reply --from --stdin --title
1291
+ report --force
1292
+ resume --agent --all --dry-run
1293
+ review --allow-unresolved-branch --dir --no-gates --strong
1294
+ say --now
1295
+ standby --reason
1296
+ task --agent --category --deps --issue --title
1297
+ teardown --agent --all --force --purge --register
1298
+ up --agents --fresh-pm --print
1299
+ version --check
1300
+ watch --interval --once --ui
1301
+ EOF
1302
+ )
1303
+
1304
+ check_invariants() {
1305
+ section "invariants · 命令名/旗标名/跨规格字面量一个不改(逻辑)"
1306
+ # the literals other specs expect
1307
+ local init_page; init_page="$tmp/pages/en/command--init.txt"
1308
+ local n=0
1309
+ grep -q '\.pi/skills' "$init_page" || { finding "invariants: init 页没有点名 .pi/skills"; n=1; }
1310
+ grep -q -- '--copy' "$init_page" || { finding "invariants: init 行没有 --copy"; n=1; }
1311
+ grep -q -- '--no-skills' "$init_page" || { finding "invariants: init 行没有 --no-skills"; n=1; }
1312
+ local aa; aa="$tmp/pages/en/command--add-agent.txt"
1313
+ for f in --register --create --no-install --print; do
1314
+ grep -q -- "$f" "$aa" || { finding "invariants: add-agent 行没有 $f"; n=1; }
1315
+ done
1316
+ grep -q -- '--model' "$aa" && { finding "invariants: add-agent 行打印了退休的 --model"; n=1; }
1317
+ grep -q -- '--register' "$tmp/pages/en/command--teardown.txt" || { finding "invariants: teardown 行没有 --register"; n=1; }
1318
+ grep -q -- '--branch <name>' "$tmp/pages/en/command--dispatch.txt" || { finding "invariants: dispatch 行没有 --branch <name>"; n=1; }
1319
+ [ "$n" = "0" ] && ok "跨规格字面量(init/add-agent/teardown/dispatch)逐条成立"
1320
+ # the pre-change flag set is a subset of the new one
1321
+ local nb=0 line cname fl
1322
+ while IFS= read -r line; do
1323
+ [ -n "$line" ] || continue
1324
+ cname="${line%% *}"
1325
+ for fl in ${line#* }; do
1326
+ grep -q -- "$fl" "$tmp/pages/en/command--$cname.txt" || { finding "invariants: $cname 的页不再打印 $fl(旧面打印过它)"; nb=1; }
1327
+ done
1328
+ done <<< "$BASELINE_FLAGS"
1329
+ [ "$nb" = "0" ] && ok "改动前的每条 (命令,旗标) 声明都还在新面里"
1330
+ return 0
1331
+ }
1332
+
1333
+ # ---------------------------------------------------------------- route
1334
+ check_route() {
1335
+ section "route · 三级可达、两条入口逐字节相同、未知 token exit 2、无项目可用"
1336
+ local rc
1337
+ page en help >/dev/null; [ $? = 0 ] && ok "team help 是菜单(rc=0)"
1338
+ ( cd "$tmp" && bash "$team" >/dev/null 2>&1 ); [ $? = 0 ] && ok "team(无参)是菜单(rc=0)"
1339
+ local g
1340
+ for g in "${MG_GROUPS[@]}"; do
1341
+ local out; out="$(page en help "$g")"
1342
+ printf '%s\n' "$out" | grep -q "^ " || { finding "route: 组页 $g 没有命令"; continue; }
1343
+ done
1344
+ ok "每个分组页都列出命令"
1345
+ local c same=0
1346
+ for c in "${MG_ORDER[@]}"; do
1347
+ if ! diff -q <(page en help "$c") <(page en "$c" --help) >/dev/null 2>&1; then
1348
+ finding "route: $c 的两条入口不逐字节相同"; same=1
1349
+ fi
1350
+ if ! diff -q <(page en help "$c") <(page en "$c" -h) >/dev/null 2>&1; then
1351
+ finding "route: $c 的 -h 入口与 help 页不同"; same=1
1352
+ fi
1353
+ done
1354
+ [ "$same" = "0" ] && ok "team help <命令> 与 team <命令> --help/-h 逐字节相同(${#MG_ORDER[@]} 个命令)"
1355
+ # a page never falls back to the menu
1356
+ local dpage; dpage="$(page en dispatch --help)"
1357
+ case "$dpage" in
1358
+ "teamsmith · dispatch"*) ok "命令页以自己的标题开头(没有退回菜单)" ;;
1359
+ *) finding "route: 命令页退回了菜单:$(printf '%s' "$dpage" | head -1 | cut -c1-60)" ;;
1360
+ esac
1361
+ # unknown tokens
1362
+ local d; d="$(new_repo route-refusal)"
1363
+ setup_fixture proj "$d" route-refusal >/dev/null 2>&1
1364
+ local before after
1365
+ before="$(fp_all "$d")"
1366
+ for spec in "frobnicate --help" "help frobnicate" "help not-a-group" "-h frobnicate"; do
1367
+ env_run "$d" $spec
1368
+ local out="$HS_OUT" rc2="$HS_RC"
1369
+ if [ "$rc2" != "2" ]; then finding "route: team $spec 的退出码是 $rc2(应为 2)"; continue; fi
1370
+ if ! printf '%s' "$out" | grep -q 'frobnicate\|not-a-group'; then finding "route: team $spec 没有点名 token"; continue; fi
1371
+ printf '%s' "$out" | grep -q 'team help' || { finding "route: team $spec 没有指回 team help"; continue; }
1372
+ done
1373
+ after="$(fp_all "$d")"
1374
+ [ "$before" = "$after" ] && ok "未知 token:exit 2、点名 token、指回 team help,且不写状态" \
1375
+ || finding "route: 未知 token 的拒绝写了状态"
1376
+ # a name the dispatcher accepts is never refused this way
1377
+ local nope=0 c2
1378
+ for c2 in "${MG_ORDER[@]}"; do
1379
+ env_run "$d" "$c2" --help
1380
+ [ "$HS_RC" = "0" ] || { finding "route: 已知命令 $c2 的 --help 退出码是 $HS_RC"; nope=1; }
1381
+ done
1382
+ for c2 in "${MG_ORDER[@]}"; do
1383
+ for a in ${MG_ALIASES[$c2]}; do
1384
+ [ "$a" = "-" ] && continue
1385
+ env_run "$d" "$a" --help
1386
+ [ "$HS_RC" = "0" ] || { finding "route: 别名 $a 被拒绝(rc=$HS_RC)"; nope=1; }
1387
+ done
1388
+ done
1389
+ [ "$nope" = "0" ] && ok "dispatcher 接受的每个名字(含别名)都不会被当成未知 token"
1390
+ # a known parent with an unknown subcommand: the page plus a refusal naming the sub
1391
+ env_run "$d" config frobnicate --help
1392
+ if [ "$HS_RC" = "2" ] && printf '%s' "$HS_OUT" | grep -q 'frobnicate'; then
1393
+ ok "team <命令> <未知子命令> --help:打印该页并在页首点名子命令、exit 2"
1394
+ else
1395
+ finding "route: 未知子命令的形态不对(rc=$HS_RC)"
1396
+ fi
1397
+ # no project: every help entry works and writes nothing
1398
+ local nd="$tmp/no-project"; rm -rf "$nd"; mkdir -p "$nd"
1399
+ local w=0
1400
+ for spec in "help" "help dispatch" "dispatch --help" "help seats"; do
1401
+ ( cd "$nd" && env -u TMUX -u TMUX_PANE PATH="$SHIM:$PATH" TEAM_PI_BIN="$SHIM/fakeagent" \
1402
+ ${TIMEOUT_BIN:+"$TIMEOUT_BIN" "$timeout_sec"} bash "$team" $spec </dev/null >/dev/null 2>&1 )
1403
+ [ "$?" = "0" ] || { finding "route: 无项目目录时 team $spec 失败"; w=1; }
1404
+ done
1405
+ [ "$(find "$nd" -mindepth 1 | wc -l)" = "0" ] || { finding "route: 帮助路径在无项目目录里写了文件"; w=1; }
1406
+ [ "$w" = "0" ] && ok "帮助路径不需要项目:无 git、无契约的目录里四个入口都 exit 0 且不写文件"
1407
+ # requesting help never runs the helped command
1408
+ local lb; lb="$(cat "$tmp/tmux-calls.log" "$tmp/launch.log" 2>/dev/null | wc -l)"
1409
+ page en help dispatch >/dev/null
1410
+ page en dispatch --help >/dev/null
1411
+ local la; la="$(cat "$tmp/tmux-calls.log" "$tmp/launch.log" 2>/dev/null | wc -l)"
1412
+ [ "$lb" = "$la" ] && ok "请求帮助不执行被帮助的命令(记录器没有新调用)" \
1413
+ || finding "route: 请求帮助起了进程"
1414
+ return 0
1415
+ }
1416
+
1417
+ # ---------------------------------------------------------------- red sides (--flip)
1418
+ flip_copy() { # <name> → a scratch tree with its own copy of the skill
1419
+ local name="$1" c
1420
+ c="$tmp/flip/$name"
1421
+ rm -rf "$c"; mkdir -p "$c/skills"
1422
+ cp -a "$skill" "$c/skills/teamsmith"
1423
+ printf '%s\n' "$c"
1424
+ }
1425
+
1426
+ flip_run() { # <label> <copy> <select> <expected substring> [only-command]
1427
+ local label="$1" copy="$2" sel="$3" expect="$4" only="${5:-}"
1428
+ local out rc fx="$0"
1429
+ # A mutation inside the fixture itself (the declared internal-entry list) only takes effect if the
1430
+ # copy's own checker runs; every other mutation is in the product, and the copy's fixture is
1431
+ # byte-identical to this one, so running it is the same check either way.
1432
+ [ -f "$copy/skills/teamsmith/tests/help-surface.sh" ] && fx="$copy/skills/teamsmith/tests/help-surface.sh"
1433
+ out="$(TEAM_HELP_SURFACE_TREE="$copy" TEAM_HELP_SURFACE_ONLY="$only" \
1434
+ bash "$fx" --select "$sel" 2>&1)"; rc=$?
1435
+ if [ "$rc" = "0" ]; then
1436
+ finding "翻转 $label 没有红(检查看不见这个破坏)"
1437
+ elif ! printf '%s' "$out" | grep -qF -e "$expect"; then
1438
+ finding "翻转 $label 红了,但没有点名「$expect」:$(printf '%s' "$out" | grep '✗' | head -1 | sed 's/\x1b\[[0-9;]*m//g' | cut -c1-70)"
1439
+ else
1440
+ # the evidence line prefers the finding this side was aimed at, and falls back to the first red
1441
+ local ev
1442
+ ev="$(printf '%s' "$out" | grep '✗' | grep -v '== 结果 ==' | grep -F -e "$expect" | head -1)"
1443
+ [ -n "$ev" ] || ev="$(printf '%s' "$out" | grep '✗' | grep -v '== 结果 ==' | head -1)"
1444
+ ok "翻转 $label:$(printf '%s' "$ev" | sed 's/\x1b\[[0-9;]*m//g' | cut -c1-90)"
1445
+ fi
1446
+ if [ "$keep" = "1" ]; then printf '\n保留翻转副本:%s\n' "$copy"; else rm -rf "$copy"; fi
1447
+ }
1448
+
1449
+ flip_edit() { # <file> <python-expression on the text> — rewrites a file in place; must change it
1450
+ local file="$1" code="$2"
1451
+ python3 -c '
1452
+ import sys
1453
+ p, code = sys.argv[1], sys.argv[2]
1454
+ s = open(p, encoding="utf-8").read()
1455
+ ns = {"s": s}
1456
+ exec(code, ns)
1457
+ if ns["s"] == s:
1458
+ sys.exit("flip_edit: the mutation changed nothing (stale pattern in %s)" % p)
1459
+ open(p, "w", encoding="utf-8").write(ns["s"])
1460
+ ' "$file" "$code"
1461
+ }
1462
+
1463
+ flip_wanted() { # <id> — does this red side belong to the requested --flip-only subset?
1464
+ [ -z "${TEAM_HELP_SURFACE_FLIP_ONLY:-}" ] && return 0
1465
+ case " $TEAM_HELP_SURFACE_FLIP_ONLY " in *" $1 "*) return 0 ;; esac
1466
+ return 1
1467
+ }
1468
+
1469
+ # flip_case <id> <label> <file-relative-to-the-copy> <python> <select> <expected> [only-command]
1470
+ # One red side end to end: copy the tree, mutate (asserted), run the check, judge the finding.
1471
+ flip_case() {
1472
+ local id="$1" label="$2" rel="$3" code="$4" sel="$5" expect="$6" only="${7:-}"
1473
+ flip_wanted "$id" || return 0
1474
+ local c s
1475
+ c="$(flip_copy "flip-$id")"
1476
+ s="$c/skills/teamsmith/$rel"
1477
+ if ! flip_edit "$s" "$code" 2>"$tmp/flip-$id.err"; then
1478
+ finding "翻转 $label:变异没落地(夹具缺陷)—— $(head -1 "$tmp/flip-$id.err")"
1479
+ rm -rf "$c"
1480
+ return 0
1481
+ fi
1482
+ if [ "${TEAM_HELP_SURFACE_FLIP_DRY:-0}" = "1" ]; then
1483
+ ok "翻转 $label:变异落地(dry 模式只审模式)"
1484
+ rm -rf "$c"
1485
+ return 0
1486
+ fi
1487
+ flip_run "$label" "$c" "$sel" "$expect" "$only"
1488
+ }
1489
+
1490
+ do_flips() {
1491
+ section "flip · 每条红侧:破坏 → 指定用例红 → 还原 → 全绿(只留逻辑类)"
1492
+ local dry="${TEAM_HELP_SURFACE_FLIP_DRY:-0}"
1493
+
1494
+ # ③ a command disappears from its group page (its usage line survives only on its own page)
1495
+ flip_case "group-missing" "①组页漏一条命令" "scripts/lib/cmd-help.sh" \
1496
+ 's = s.replace(""" [ "${_TH_GROUP[$i]}" = "$g" ] || continue""", """ [ "${_TH_GROUP[$i]}" = "$g" ] || continue
1497
+ [ "${_TH_NAMES[$i]}" != "status" ] || continue""", 1)' \
1498
+ coverage "与清单不一致"
1499
+
1500
+ # ④ one manifest row is deleted (the dispatcher still accepts the command)
1501
+ flip_case "row-deleted" "②删一条命令记录" "scripts/strings/commands.tsv" \
1502
+ 's = "\n".join(l for l in s.split("\n") if not l.startswith("cmd\tbg\t"))' \
1503
+ coverage "bg"
1504
+
1505
+ # ⑤ an unknown token is answered with exit 0
1506
+ flip_case "unknown-zero" "③未知 token 走成 exit 0" "scripts/lib/cmd-help.sh" \
1507
+ 's = s.replace("team_help_refuse \"$token\"; return $?", "team_help_menu; return 0", 1)' \
1508
+ route "退出码是 0"
1509
+
1510
+ # ⑥ the help path loads the project contract before answering
1511
+ flip_case "help-loads-config" "④帮助路径读配置" "scripts/team" \
1512
+ 's = s.replace("""if [ "$_TEAM_HELP_REQ" = "1" ]; then""", """team_load_config || exit 1
1513
+ if [ "$_TEAM_HELP_REQ" = "1" ]; then""", 1)' \
1514
+ route "无项目目录"
1515
+
1516
+ # ⑦ an invalid TEAM_LANG is silent
1517
+ flip_case "lang-silent" "⑤非法 TEAM_LANG 静默" "scripts/lib/cmd-help.sh" \
1518
+ 's = s.replace(""" *) printf \x27teamsmith: TEAM_LANG=%s is not a known language (en, zh); printing English\\n\x27 "$TEAM_LANG" >&2 ;;""", " *) ;;", 1)' \
1519
+ lang "非法 TEAM_LANG"
1520
+
1521
+ # ⑧ one Chinese key is missing (the page must name it and fall back)
1522
+ flip_case "key-silent" "⑥缺键静默(不渲染标记)" "scripts/lib/cmd-help.sh" \
1523
+ 's = s.replace(" printf \x27%s\x27 \"$(team_help_marker \"$key\")\"", " :", 1)' \
1524
+ lang "缺键没有渲染出可见标记"
1525
+
1526
+ # ⑩ a machine exit starts carrying language-dependent output
1527
+ flip_case "machine-drift" "⑦机器出口跟着语言走" "scripts/lib/common.sh" \
1528
+ 's = s.replace("team_paths_json() {", "team_paths_json() {" + chr(10) + " [ -z \"${TEAM_LANG:-}\" ] || printf \x27%s\x27 \"$TEAM_LANG\" >&2", 1)' \
1529
+ lang "语言改变了 team paths"
1530
+
1531
+ # ⑰b a declared flag with no prose key → the page prints a missing-key marker
1532
+ flip_case "arg-key-missing" "⑧声明的旗标没有散文键" "scripts/strings/help.en.tsv" \
1533
+ 's = "\n".join(l for l in s.split("\n") if not l.startswith("cmd.dispatch.arg.--fresh\t"))' \
1534
+ coverage "missing key"
1535
+
1536
+ # ── help-robustness (P278) ────────────────────────────────────────────────────────────────────
1537
+ # O1: the width classification reads the locale again — the old `$'\uXXXX'` brace ranges made one
1538
+ # CJK character three cells under LC_ALL=C, so the same page wrapped differently in the two locales
1539
+ flip_case "locale-dependent-width" "⑨宽度计算退回 locale 依赖" "scripts/lib/cmd-help.sh" \
1540
+ 's = s.replace(""" if [ "$cp" -ge "${r%-*}" ] && [ "$cp" -le "${r#*-}" ]; then _TH_CELLS=2; return 0; fi""", """ if [ "$cp" -ge "${r%-*}" ] && [ "$cp" -le "${r#*-}" ]; then
1541
+ case "${LC_ALL:-${LANG:-}}" in *UTF-8*|*utf8*) _TH_CELLS=2 ;; *) _TH_CELLS=3 ;; esac
1542
+ return 0
1543
+ fi""", 1)' \
1544
+ locale "随 locale 变" dispatch
1545
+
1546
+ # O2a: one more `__`-prefixed dispatcher label than the declared internal set names
1547
+ flip_case "internal-undeclared" "⑩dispatcher 多一个 __ 标签" "scripts/team" \
1548
+ 's = s.replace(""" __panel-data) team_cmd_panel_data "$@" ;;""", """ __probe-x) exit 0 ;;
1549
+ __panel-data) team_cmd_panel_data "$@" ;;""", 1)' \
1550
+ coverage "__probe-x"
1551
+
1552
+ # O2b: the declared internal set names one entry that is no longer a dispatcher label
1553
+ flip_case "internal-list-short" "⑪声明清单里删一个内部名" "tests/help-surface.sh" \
1554
+ 's = s.replace("__inbox-write __panel-data", "__panel-data", 1)' \
1555
+ coverage "__inbox-write"
1556
+
1557
+ # O6a: a declared group disappears from the manifest while its commands still name it
1558
+ flip_case "group-row-deleted" "⑫清单删一条分组记录(命令仍声明它)" "scripts/strings/commands.tsv" \
1559
+ 's = "\n".join(l for l in s.split("\n") if l != "group\tversions")' \
1560
+ coverage "versions"
1561
+
1562
+ # O6b: the menu renderer skips one declared group (the group page still lists its commands)
1563
+ flip_case "menu-skips-group" "⑬菜单渲染器跳过一个已声明的分组" "scripts/lib/cmd-help.sh" \
1564
+ 's = s.replace(" local title purpose cells pad line", """ local title purpose cells pad line
1565
+ [ $g = versions ] && continue""", 1)' \
1566
+ coverage "versions"
1567
+
1568
+ # G4: the placeholder check disappears → the guard's scratch copy prints the token literally
1569
+ flip_case "placeholder-check-gone" "⑭去掉未声明占位符的检查" "scripts/lib/cmd-help.sh" \
1570
+ 's = s.replace(""" [ "$_bad" = "0" ] || return 1""", """ [ "$_bad" = "0" ] || :""", 1)' \
1571
+ coverage "{undeclared}"
1572
+
1573
+ # ── P290 · 幂等探针的红侧(声明与行为不一致的三种形状) ──────────────────
1574
+ # ①a command that really writes on every run while its row declares `idempotent`
1575
+ flip_case "idem-writes" "⑮幂等命令第二次跑仍然写状态" "scripts/lib/cmd-status.sh" \
1576
+ 's = s.replace("""team_cmd_status() {\n team_require_docs""", """team_cmd_status() {\n team_require_docs\n mkdir -p \"$TEAM_STATE_DIR\"; printf \x27%s\\n\x27 \"$(wc -l < \"$TEAM_STATE_DIR/probe-idem.txt\" 2>/dev/null || true)\" >> \"$TEAM_STATE_DIR/probe-idem.txt\"""", 1)' \
1577
+ claims "声明幂等,但第二次跑改了状态" status
1578
+
1579
+ # ②the recorded-time field is rewritten on every run again — the P290 flake's exact shape; the
1580
+ # sentinel makes this red no matter how fast the two runs are (no clock, no sleep)
1581
+ flip_case "mark-loaded-rewrites" "⑯去掉「无变化不重写」的守卫(P290 的时钟缺陷回退)" "scripts/lib/cmd-update.sh" \
1582
+ 's = s.replace(""" if [ -n "$stored_at" ] && [ "$stored_core" = "$core" ]; then""", " if false; then", 1)' \
1583
+ claims "重写了指名的记录时间字段" mark-loaded
1584
+
1585
+ # ③the declared field is no longer written at all: the table's entry must be a finding, not a
1586
+ # silently passing no-op
1587
+ flip_case "time-field-gone" "⑰声明的记录时间字段不再被写(声明过期必红)" "scripts/lib/cmd-update.sh" \
1588
+ 's = s.replace(""" printf \x27AT=%s\\n\x27 \"$(team_timestamp)\"\n""", "", 1)' \
1589
+ claims "声明过期" mark-loaded
1590
+
1591
+ # ⑱ a clock field nobody declared, with the declaration table emptied for mark-loaded: the sentinel
1592
+ # cannot see that pair, so the only thing that makes the rewrite visible is the 1.1s gap — this is
1593
+ # the red side that shows the gap is load-bearing rather than decoration, and it is the exact shape
1594
+ # of the P290 defect (an undeclared clock field, invisible on a fast same-second host)
1595
+ if flip_wanted "clock-undeclared"; then
1596
+ local c18
1597
+ c18="$(flip_copy "flip-clock-undeclared")"
1598
+ if flip_edit "$c18/skills/teamsmith/scripts/lib/cmd-update.sh" \
1599
+ 's = s.replace(""" if [ -n "$stored_at" ] && [ "$stored_core" = "$core" ]; then""", " if false; then", 1)' 2>"$tmp/flip-18a.err" \
1600
+ && flip_edit "$c18/skills/teamsmith/tests/help-surface.sh" \
1601
+ 's = s.replace(" [mark-loaded]=\".pi/team/state/pm-loaded.env:AT\"\n", "", 1)' 2>"$tmp/flip-18b.err"; then
1602
+ flip_run "⑱未指名的时钟字段(只有 1.1s 间隔抓得住)" "$c18" claims "第二次跑改了状态" mark-loaded
1603
+ else
1604
+ finding "翻转 ⑱:变异没落地(夹具缺陷)—— $(head -1 "$tmp/flip-18b.err" 2>/dev/null || head -1 "$tmp/flip-18a.err")"
1605
+ rm -rf "$c18"
1606
+ fi
1607
+ fi
1608
+
1609
+ # ── P290 · 返修轮次 1(V46 的 F1 与 O1)─────────────────────────────────────
1610
+ # ⑲ F1 的形状回退:守卫改回裸赋值接一个没命中的 grep,set -e 把 CLI 带走。记录里没有指名的
1611
+ # 时间字段时必须补全并 rc=0——这条红侧证明夹具里那条新臂是承重的(V46 F1 的真实形状)。
1612
+ flip_case "missing-time-field" "⑲记录缺 AT= 行时静默失败(V46 F1 的回退)" "scripts/lib/cmd-update.sh" \
1613
+ 's = s.replace(""" stored_at="$(grep -s -m1 \x27^AT=\x27 "$f" 2>/dev/null || true)"\n fi""", """ stored_at="$(grep -s \x27^AT=\x27 "$f" | head -1)"\n fi""", 1)' \
1614
+ claims "记录里缺指名的记录时间字段 AT" mark-loaded
1615
+
1616
+ # ⑳ O1:第二次跑以非零退出、且不写盘(V46 的 m3)——只看字节会判绿,退出码断言是唯一抓手。
1617
+ flip_case "second-run-fails" "⑳第二次跑失败但不写盘(退出码盲区)" "scripts/lib/cmd-update.sh" \
1618
+ 's = s.replace(""" team_ok "本会话 skill 版本未变化:$ver(指纹 $hash;保留 $(basename "$f") 里记录的时间)"\n return 0""", """ team_ok "本会话 skill 版本未变化:$ver(指纹 $hash;保留 $(basename "$f") 里记录的时间)"\n return 1""", 1)' \
1619
+ claims "两次跑的退出码不同" mark-loaded
1620
+
1621
+ # ── P292 · 返修轮次 1(V52 的 F1)────────────────────────────────────────────────────────────
1622
+ # ㉑ 少声明:interrupt 的 `faces` 删掉 docs。旧探针只判「声明的面都动了」,这一改照样全绿(V52 §2.5);
1623
+ # 反向判据必须红并点名那个没被声明的面。
1624
+ flip_case "interrupt-face-unlisted" "㉑命令页少写一个已触碰的面" "scripts/strings/commands.tsv" \
1625
+ 's = s.replace("\tseat\tstate docs\twrites-state\t", "\tseat\tstate\twrites-state\t", 1)' \
1626
+ claims "动了没有声明的面 docs" interrupt
1627
+
1628
+ # ㉒ 多写未声明面:实现真去写 `config`(V52 §2.6 的同一形状)—— 反向判据必须红并点名 config。
1629
+ # 声明侧一个字没动:红只能来自「变了的面没在声明里」,不能来自探针变瞎。
1630
+ flip_case "interrupt-writes-undeclared" "㉒实现多写一个没有声明的面" "scripts/lib/cmd-interrupt.sh" \
1631
+ 's = s.replace(""" "${7:--}" "${8:--}" "${9:--}" >> "$f" || return 1""", """ "${7:--}" "${8:--}" "${9:--}" >> "$f" || return 1
1632
+ printf \x27# probe mutation\n\x27 >> .pi/team/config.sh""", 1)' \
1633
+ claims "动了没有声明的面 config" interrupt
1634
+
1635
+ # ㉓ 写工作树:实现往席位工作树里写一个文件(`interrupt` 的规格明写工作树逐字节不变)。旧指纹只有
1636
+ # `worktree list` + 分支 ref,对内容和写盘是盲的(V52 §2.6 尾);现在 worktree 面含内容 → 必须红。
1637
+ flip_case "interrupt-writes-worktree" "㉓实现往席位工作树里写文件" "scripts/lib/cmd-interrupt.sh" \
1638
+ 's = s.replace(""" "${7:--}" "${8:--}" "${9:--}" >> "$f" || return 1""", """ "${7:--}" "${8:--}" "${9:--}" >> "$f" || return 1
1639
+ printf \x27# probe mutation\n\x27 > .worktrees/dev/probe-mut.txt""", 1)' \
1640
+ claims "动了没有声明的面 worktree" interrupt
1641
+
1642
+ return 0
1643
+ }
1644
+
1645
+ # ---------------------------------------------------------------- result
1646
+ load_manifest "$str/commands.tsv"
1647
+ _need_pages=0
1648
+ for _s in coverage invariants; do want "$_s" && _need_pages=1; done
1649
+ [ "$FLIP" = "1" ] && _need_pages=1
1650
+ if [ "$_need_pages" = "1" ]; then
1651
+ render_pages en
1652
+ [ -n "${TEAM_HELP_SURFACE_ONLY:-}" ] || render_pages zh
1653
+ fi
1654
+ if want coverage; then check_coverage; fi
1655
+ if want locale; then check_locale; fi
1656
+ if want lang; then check_lang; fi
1657
+ if want claims; then check_claims; fi
1658
+ if want invariants; then check_invariants; fi
1659
+ if want route; then check_route; fi
1660
+ if [ "$FLIP" = "1" ]; then do_flips; fi
1661
+
1662
+ printf '\n\033[1m== 结果 ==\033[0m ✓ %d ✗ %d SKIP %d\n' "$PASS" "$FIND" "$SKIP"
1663
+ [ "$FIND" -eq 0 ] && exit 0
1664
+ exit 1