teamsmith 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/README.md +4 -4
  2. package/package.json +1 -1
  3. package/skills/teamsmith/CHANGELOG.md +28 -0
  4. package/skills/teamsmith/SKILL.md +14 -7
  5. package/skills/teamsmith/extension/team-notify.ts +37 -6
  6. package/skills/teamsmith/extension/team.ts +438 -0
  7. package/skills/teamsmith/references/config.md +39 -6
  8. package/skills/teamsmith/references/migration.md +197 -47
  9. package/skills/teamsmith/references/protocol.md +176 -19
  10. package/skills/teamsmith/references/troubleshooting.md +124 -7
  11. package/skills/teamsmith/references/workflows.md +36 -2
  12. package/skills/teamsmith/scripts/lib/cmd-agents.sh +318 -23
  13. package/skills/teamsmith/scripts/lib/cmd-bootstrap.sh +2 -2
  14. package/skills/teamsmith/scripts/lib/cmd-config.sh +349 -67
  15. package/skills/teamsmith/scripts/lib/cmd-draft.sh +4 -4
  16. package/skills/teamsmith/scripts/lib/cmd-help.sh +677 -0
  17. package/skills/teamsmith/scripts/lib/cmd-init.sh +157 -5
  18. package/skills/teamsmith/scripts/lib/cmd-interrupt.sh +461 -0
  19. package/skills/teamsmith/scripts/lib/cmd-meeting.sh +2 -25
  20. package/skills/teamsmith/scripts/lib/cmd-project.sh +30 -103
  21. package/skills/teamsmith/scripts/lib/cmd-reap.sh +277 -0
  22. package/skills/teamsmith/scripts/lib/cmd-reply.sh +3 -3
  23. package/skills/teamsmith/scripts/lib/cmd-review.sh +175 -30
  24. package/skills/teamsmith/scripts/lib/cmd-status.sh +226 -17
  25. package/skills/teamsmith/scripts/lib/cmd-update.sh +36 -7
  26. package/skills/teamsmith/scripts/lib/cmd-watch.sh +564 -46
  27. package/skills/teamsmith/scripts/lib/common.sh +773 -48
  28. package/skills/teamsmith/scripts/lib/gate-lock.sh +544 -0
  29. package/skills/teamsmith/scripts/panel/draft-send.sh +11 -1
  30. package/skills/teamsmith/scripts/panel/panel.js +207 -207
  31. package/skills/teamsmith/scripts/panel/src/App.tsx +58 -21
  32. package/skills/teamsmith/scripts/panel/src/clipboard.ts +11 -5
  33. package/skills/teamsmith/scripts/panel/src/compose.ts +6 -3
  34. package/skills/teamsmith/scripts/panel/src/data.ts +11 -3
  35. package/skills/teamsmith/scripts/panel/src/layout.ts +209 -69
  36. package/skills/teamsmith/scripts/panel/src/main.tsx +33 -8
  37. package/skills/teamsmith/scripts/panel/src/strings/en.ts +39 -29
  38. package/skills/teamsmith/scripts/panel/src/strings/zh.ts +41 -31
  39. package/skills/teamsmith/scripts/panel/src/types.ts +28 -3
  40. package/skills/teamsmith/scripts/replies.mjs +4 -1
  41. package/skills/teamsmith/scripts/shim/tmux +18 -0
  42. package/skills/teamsmith/scripts/strings/commands.tsv +86 -0
  43. package/skills/teamsmith/scripts/strings/help.en.tsv +503 -0
  44. package/skills/teamsmith/scripts/strings/help.zh.tsv +489 -0
  45. package/skills/teamsmith/scripts/team +19 -6
  46. package/skills/teamsmith/templates/AGENTS.section.md.tmpl +8 -1
  47. package/skills/teamsmith/templates/config.sh.tmpl +20 -1
  48. package/skills/teamsmith/templates/pm-prompt.md.tmpl +21 -0
  49. package/skills/teamsmith/tests/bg-ledger-harness.mjs +464 -40
  50. package/skills/teamsmith/tests/bg-ledger.sh +168 -10
  51. package/skills/teamsmith/tests/checkout-shape-probe.sh +3 -1
  52. package/skills/teamsmith/tests/config-cli.sh +160 -14
  53. package/skills/teamsmith/tests/fixtures/delivery-truth-real/scenario.sh +7 -1
  54. package/skills/teamsmith/tests/fixtures/p287/lint-good.sh.in +3 -0
  55. package/skills/teamsmith/tests/fixtures/p287/lint-hardcoded.sh.in +3 -0
  56. package/skills/teamsmith/tests/fixtures/p287/lint-no-ns.sh.in +3 -0
  57. package/skills/teamsmith/tests/fixtures/p55/flip-p49.sh +18 -6
  58. package/skills/teamsmith/tests/flip-m33.sh +5 -3
  59. package/skills/teamsmith/tests/flip-m37.sh +4 -1
  60. package/skills/teamsmith/tests/flip-m4.3.sh +4 -1
  61. package/skills/teamsmith/tests/flip-m6.3.sh +4 -1
  62. package/skills/teamsmith/tests/flip-m6.5.sh +4 -1
  63. package/skills/teamsmith/tests/flip-m7.2.sh +4 -1
  64. package/skills/teamsmith/tests/flip-p158.sh +2 -1
  65. package/skills/teamsmith/tests/flip-p210.sh +4 -1
  66. package/skills/teamsmith/tests/flip-p217.sh +4 -1
  67. package/skills/teamsmith/tests/flip-p287-lock.sh +342 -0
  68. package/skills/teamsmith/tests/flip-p287-name.sh +279 -0
  69. package/skills/teamsmith/tests/flip-p304-read-side.sh +98 -0
  70. package/skills/teamsmith/tests/flip-p308-skip-not-pass.sh +151 -0
  71. package/skills/teamsmith/tests/flip-p309-p162-deep.sh +122 -0
  72. package/skills/teamsmith/tests/flip-p310-lock.sh +216 -0
  73. package/skills/teamsmith/tests/flip-p310-socket.sh +125 -0
  74. package/skills/teamsmith/tests/help-surface.sh +1664 -0
  75. package/skills/teamsmith/tests/install-shape.sh +279 -20
  76. package/skills/teamsmith/tests/key-replies-pty.sh +9 -10
  77. package/skills/teamsmith/tests/key-replies-ui.sh +0 -7
  78. package/skills/teamsmith/tests/key-replies.sh +240 -1
  79. package/skills/teamsmith/tests/ledger-ban.sh +5 -4
  80. package/skills/teamsmith/tests/ledger-claim.sh +2 -1
  81. package/skills/teamsmith/tests/lib/bounded-spin.sh +90 -0
  82. package/skills/teamsmith/tests/lib/model-policy.sh +4 -0
  83. package/skills/teamsmith/tests/lib/model-routing-flips.py +51 -0
  84. package/skills/teamsmith/tests/lib/reply-fixture.sh +4 -9
  85. package/skills/teamsmith/tests/lib/section-guard.sh +258 -13
  86. package/skills/teamsmith/tests/lib/tmp-root.sh +139 -27
  87. package/skills/teamsmith/tests/lib/tmux-cap.sh +10 -1
  88. package/skills/teamsmith/tests/lib/tmux-iso.sh +31 -13
  89. package/skills/teamsmith/tests/loop-inventory.tsv +59 -47
  90. package/skills/teamsmith/tests/panel-b2.sh +106 -3
  91. package/skills/teamsmith/tests/panel-b3-stub.sh +112 -4
  92. package/skills/teamsmith/tests/panel-b3.sh +175 -19
  93. package/skills/teamsmith/tests/panel-choices.sh +11 -6
  94. package/skills/teamsmith/tests/panel-cpu.sh +2 -1
  95. package/skills/teamsmith/tests/panel-knobs.sh +7 -1
  96. package/skills/teamsmith/tests/panel-p21.sh +156 -73
  97. package/skills/teamsmith/tests/panel-snapshots.sh +41 -225
  98. package/skills/teamsmith/tests/panel-strings.mjs +33 -18
  99. package/skills/teamsmith/tests/perf.sh +121 -30
  100. package/skills/teamsmith/tests/routes.sh +327 -93
  101. package/skills/teamsmith/tests/seat-interrupt.sh +1002 -0
  102. package/skills/teamsmith/tests/seat-visibility.sh +675 -0
  103. package/skills/teamsmith/tests/section-budgets.tsv +20 -10
  104. package/skills/teamsmith/tests/section-guard.sh +6 -1
  105. package/skills/teamsmith/tests/section-needs-audit.sh +24 -7
  106. package/skills/teamsmith/tests/section-paths.tsv +19 -13
  107. package/skills/teamsmith/tests/section-select.sh +8 -1
  108. package/skills/teamsmith/tests/slash-team-e2e.sh +323 -0
  109. package/skills/teamsmith/tests/slash-team.sh +617 -0
  110. package/skills/teamsmith/tests/smoke.sh +2972 -440
  111. package/skills/teamsmith/tests/task-model-routing.sh +507 -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-init/SKILL.md +12 -12
  117. package/skills/teamsmith-init/references/bootstrap.md +3 -3
@@ -53,6 +53,12 @@ PERF_SAMPLES=5
53
53
  here="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
54
54
  # P53:临时根的唯一创建者(${TMPDIR:-/tmp} + owned 家族 + 回收)
55
55
  . "$here/lib/tmp-root.sh"
56
+ # P287:门禁锁的伴生锁路径与「记录读哪一份」只在 scripts/lib/gate-lock.sh 里实现一次 ——
57
+ # 只读探活要按新位置读(互斥在伴生锁上,发布路径是兼容声明;旧写入者的记录仍在发布路径边上)
58
+ if [ -f "$here/../scripts/lib/gate-lock.sh" ]; then
59
+ # shellcheck source=../scripts/lib/gate-lock.sh
60
+ . "$here/../scripts/lib/gate-lock.sh"
61
+ fi
56
62
  self="$here/perf.sh"
57
63
  ORIG_ARGS=("$@")
58
64
  tree=""
@@ -164,51 +170,129 @@ perf_require_pinned_container() {
164
170
 
165
171
  # ── 锁:自己一把(TEAM_PERF_LOCK),绝不拿门禁锁 ─────────────────────────────────────────────
166
172
  # 两次性能运行必须串行(夹具量的是真 pane / CPU 份额,互相测量会让数字失去意义)。
167
- # 用与 smoke 同形的 `flock --close` 包住整个脚本(重新 exec 自己):锁挂在 flock 那个父进程上,
168
- # 套件与它的子孙都不继承 fd —— 夹具留下的后台进程也就不会漏锁。
173
+ # P287(D4 裁定「性能套件那把锁一并」):与正确性门禁**同一套锁机器** ——
174
+ # ① 两把锁、顺序固定(发布路径 = 兼容声明 → 伴生锁 = 运行互斥;同行同目录、`.machine`、点开头);
175
+ # 性能锁没有外部旧写入者,但同一套纪律买的是同一件事:别人的清理命令够不着互斥。
176
+ # ② 取锁的进程自己握 fd,套件跑在它的**子进程**里、两个锁 fd 关掉(`8>&- 9>&-`)——
177
+ # M23 的漏锁教训在这里同样是构造性关掉的;收尾只删**自己的记录**,锁文件永不 unlink。
178
+ # ③ 记录写在伴生锁边上(`<companion>.holder`),带 `lock_identity=fd|path` 与 `lock_dev_ino`。
179
+ # ④ 运行期间互斥被破坏(伴生锁被删/被换)⇒ 读数不可信:打印一行 + 判红(exit 2)。
180
+ perf_lock_companion() { printf '%s\n' "$(gate_lock_companion_path "${1:-${TEAM_PERF_LOCK:-$(team_tmp_root)/teamsmith-perf.lock}}")"; }
169
181
  perf_lock_or_continue() {
170
- [ "${TEAM_PERF_LOCK_WRAPPED:-0}" = "1" ] && return 0
182
+ [ "${PERF_LOCK_TAKEN:-0}" = "1" ] && return 0 # 子进程(真正跑套件的那个):锁由父进程取到了
183
+ # 容器里的那一层由**宿主这一层**持锁(引擎是 P0 的子进程,锁 fd 已被 8>&- 9>&- 关掉):
184
+ # 不再取锁、也不认领(认领判据在宿主那层已经判过)。
185
+ [ "${TEAM_PERF_LOCK_HELD_BY_RUNNER:-0}" = "1" ] && { note "性能锁由调用方(宿主运行)持有 → 容器内不再取锁"; return 0; }
171
186
  [ "${TEAM_PERF_NO_LOCK:-0}" = "1" ] && { note "TEAM_PERF_NO_LOCK=1 → 不与别的性能运行串行(自担并发干扰)"; return 0; }
172
187
  if ! command -v flock >/dev/null 2>&1; then
173
188
  note "本机没有 flock → 不与别的性能运行串行(自担并发干扰)"
174
189
  return 0
175
190
  fi
176
- local lock="${TEAM_PERF_LOCK:-${TMPDIR:-/tmp}/teamsmith-perf.lock}" wait_s="${TEAM_PERF_LOCK_WAIT:-1800}"
191
+ local lock="${TEAM_PERF_LOCK:-$(team_tmp_root)/teamsmith-perf.lock}" wait_s="${TEAM_PERF_LOCK_WAIT:-1800}"
177
192
  case "$wait_s" in ''|*[!0-9]*) wait_s=1800 ;; esac
193
+ local comp; comp="$(perf_lock_companion "$lock")"
178
194
  mkdir -p "$(dirname "$lock")" 2>/dev/null || true
179
195
  : >>"$lock" 2>/dev/null || { note "锁文件 $lock 建不了 → 不串行"; return 0; }
180
- if ! flock -n "$lock" true 2>/dev/null; then
181
- say "另一个性能运行正在跑($(cat "$lock.holder" 2>/dev/null || printf '持有者未知'));本次排队,最多等 ${wait_s}s"
182
- fi
183
- export TEAM_PERF_LOCK_WRAPPED=1
184
- # 用 flock 包住**重新执行的自己**(--close:子进程不继承 fd,夹具留下的后台进程不会漏锁)。
185
- # 不用 exec:等待上限到了要留一句可读的话(exec 之后脚本已经不在了)。性能套件自己的退出码是
186
- # 0/2/3/4,所以 flock 的 1 只可能是「等锁超时」。
187
- local rc=0
188
- flock --close -w "$wait_s" "$lock" bash "$self" "${ORIG_ARGS[@]}" || rc=$?
189
- if [ "$rc" = "1" ]; then
190
- # 套件自己的退出码只有 0/2/3/4 —— 1 只可能是「等锁超时」(无并发测量,视作没结论)→ exit 3。
191
- printf 'perf: 等待 %ss 仍拿不到性能锁(持有者:%s)—— 另一个性能运行还没结束;不并发测量(exit 3)\n' \
192
- "$wait_s" "$(cat "$lock.holder" 2>/dev/null || printf '未知')" >&2
193
- exit 3
196
+ # 有界轮询取两把锁(每轮重算上限:持有者公布的 expected 优先,缺则 wait_s)——
197
+ # 上限到点留下可读的一句(性能套件的退出码是 0/2/3/4,拿不到锁 = 没结论 → exit 3)。
198
+ local rc=0 t0 queued=0 cap wait_used=0
199
+ t0="$(date +%s)"
200
+ while :; do
201
+ rc=0; gate_lock_acquire_pair "$lock" || rc=$?
202
+ [ "$rc" = "0" ] && break
203
+ if [ "$rc" = "2" ]; then
204
+ note "锁文件 $lock 建不了 → 不串行"; return 0
205
+ fi
206
+ IFS=$'\t' read -r cap _ _ _ < <(gate_lock_cap_pair "$lock" "$wait_s")
207
+ case "$cap" in ''|*[!0-9]*) cap="$wait_s" ;; esac
208
+ if [ "$queued" = "0" ]; then
209
+ queued=1
210
+ say "另一个性能运行正在跑($(gate_lock_describe_pair "$lock"));本次排队,最多等 ${cap}s"
211
+ fi
212
+ wait_used=$(( $(date +%s) - t0 ))
213
+ if [ "$wait_used" -ge "$cap" ]; then
214
+ printf 'perf: 等待 %ss 仍拿不到性能锁(持有者:%s)—— 另一个性能运行还没结束;不并发测量(exit 3)\n' \
215
+ "$wait_used" "$(gate_lock_describe_pair "$lock")" >&2
216
+ exit 3
217
+ fi
218
+ sleep 1
219
+ done
220
+ # 记录由**取锁的进程**(本 shell)写;两把锁的 mtime 刷一次(按 age 的清理器不该删活锁)
221
+ touch "$lock" "$comp" 2>/dev/null || true
222
+ local ident ino
223
+ IFS=$'\t' read -r ident ino < <(gate_lock_claim_identity "$comp")
224
+ gate_lock_write_holder "$comp" "$$" top "perf.sh" "perf" "$PWD" "$(date +%s)" - - - 0 - - "$ident" "$ino" || true
225
+ export PERF_LOCK_TAKEN=1 PERF_LOCK_CLAIMER_PID="$$" PERF_LOCK_CLAIMER_IDENTITY="$ident" PERF_LOCK_CLAIMER_DEV_INO="$ino"
226
+ export PERF_LOCK="$lock" PERF_LOCK_COMPANION="$comp"
227
+ local rc2=0
228
+ bash "$self" "${ORIG_ARGS[@]}" 8>&- 9>&- || rc2=$?
229
+ # 收尾:只删自己的记录;两把锁文件都留着(unlink 一个还有等待者阻塞在它 inode 上的锁,正是要消灭的静默分裂)
230
+ if gate_lock_holder_claimable "$comp" "$$"; then gate_lock_remove_holder "$comp"; fi
231
+ rmdir "$comp.runs" 2>/dev/null || true
232
+ exit "$rc2"
233
+ }
234
+ # 子进程认领:两条独立证据(记录里活着的是它 / 它的 /proc 里真有一个身份相符的锁描述符),
235
+ # 环境变量单独不作数;认领人还必须是**我的严格祖辈**(子套件那一层)。
236
+ perf_lock_claim_from_parent() {
237
+ [ "${PERF_LOCK_TAKEN:-0}" = "1" ] || return 0
238
+ [ -n "${PERF_LOCK_CLAIMER_PID:-}" ] || return 0
239
+ PERF_LOCK="${PERF_LOCK:-${TEAM_PERF_LOCK:-$(team_tmp_root)/teamsmith-perf.lock}}"
240
+ PERF_LOCK_COMPANION="$(perf_lock_companion "$PERF_LOCK")"
241
+ local p q ok=0
242
+ for q in $(gate_lock_ancestry_chain "$$"); do [ "$q" = "$PERF_LOCK_CLAIMER_PID" ] && ok=1 && break; done
243
+ [ "$ok" = "1" ] || { printf 'perf: 锁认领人 pid=%s 不在我的进程链上 → 按未持锁处理\n' "$PERF_LOCK_CLAIMER_PID" >&2; PERF_LOCK_TAKEN=0; return 0; }
244
+ if [ -s "$(gate_lock_holder_file "$PERF_LOCK_COMPANION")" ] \
245
+ && [ "$(gate_lock_record_get "$(gate_lock_holder_file "$PERF_LOCK_COMPANION")" pid)" = "$PERF_LOCK_CLAIMER_PID" ] \
246
+ && gate_lock_record_live "$(gate_lock_holder_file "$PERF_LOCK_COMPANION")"; then
247
+ PERF_LOCK_DEV_INO="$(gate_lock_record_get "$(gate_lock_holder_file "$PERF_LOCK_COMPANION")" lock_dev_ino)"
248
+ PERF_LOCK_IDENTITY="$(gate_lock_record_get "$(gate_lock_holder_file "$PERF_LOCK_COMPANION")" lock_identity)"
249
+ elif [ -n "${PERF_LOCK_CLAIMER_DEV_INO:-}" ] \
250
+ && gate_lock_pid_holds_path "$PERF_LOCK_CLAIMER_PID" "$PERF_LOCK_COMPANION" "$PERF_LOCK_CLAIMER_DEV_INO"; then
251
+ PERF_LOCK_DEV_INO="$PERF_LOCK_CLAIMER_DEV_INO"; PERF_LOCK_IDENTITY="${PERF_LOCK_CLAIMER_IDENTITY:-fd}"
252
+ else
253
+ printf 'perf: 自述持锁(pid=%s)但记录与 /proc 都对不上 → 按未持锁处理(不并发测量)\n' "$PERF_LOCK_CLAIMER_PID" >&2
254
+ PERF_LOCK_TAKEN=0
194
255
  fi
195
- exit "$rc"
196
256
  }
257
+ # 运行期间互斥被破坏 ⇒ 读数不可信(判红,exit 2)
258
+ perf_lock_identity_check() {
259
+ [ "${PERF_LOCK_TAKEN:-0}" = "1" ] && [ -n "${PERF_LOCK_DEV_INO:-}" ] || return 0
260
+ local r; r="$(gate_lock_snapshot "$PERF_LOCK_COMPANION" "${PERF_LOCK_IDENTITY:-fd}" "$PERF_LOCK_DEV_INO" "$PERF_LOCK_CLAIMER_PID")"
261
+ case "$r" in
262
+ ok|'') return 0 ;;
263
+ *) printf '\n \033[31m✗\033[0m perf:运行期间性能锁的互斥被破坏(%s)—— 本次读数不可信(exit 2)\n' "$(printf '%s' "$r" | tr '\t' ' ')"
264
+ return 2 ;;
265
+ esac
266
+ }
267
+ if [ "${PERF_LOCK_TAKEN:-0}" = "1" ]; then perf_lock_claim_from_parent; fi
197
268
  # --in-container 先验身份信号:缺了在这里就 exit 3,锁、临时目录、测量一样不沾。
198
269
  if [ "$IN_CONTAINER" = "1" ]; then perf_require_pinned_container; fi
199
270
  perf_lock_or_continue
200
- if [ "${TEAM_PERF_LOCK_WRAPPED:-0}" = "1" ]; then
201
- PERF_LOCK="${TEAM_PERF_LOCK:-${TMPDIR:-/tmp}/teamsmith-perf.lock}"
202
- printf '%s pid=%s cmd=perf.sh\n' "$(date -Is)" "$$" > "$PERF_LOCK.holder" 2>/dev/null || true
271
+ if [ "${PERF_LOCK_TAKEN:-0}" = "1" ]; then
272
+ printf ' · 性能锁:互斥在伴生锁 %s(发布路径 %s 是兼容声明;两把都永不 unlink)\n' \
273
+ "$PERF_LOCK_COMPANION" "$PERF_LOCK"
203
274
  fi
204
275
 
205
276
  # 只读探活门禁锁:门禁在跑时性能读数会被它影响,打印持有者;**不排队等它**(性能锁独立)。
206
277
  perf_smoke_lock_probe() {
207
- local lock="${TEAM_SMOKE_LOCK:-${TMPDIR:-/tmp}/teamsmith-smoke.lock}"
208
- [ -e "$lock" ] || return 0
209
- if command -v flock >/dev/null 2>&1 && ! flock -n "$lock" true 2>/dev/null; then
210
- note "正确性门禁正在跑($(cat "$lock.holder" 2>/dev/null || printf '持有者未知'))—— 本次性能读数可能受它影响(性能锁独立,不等它)"
278
+ local lock="${TEAM_SMOKE_LOCK:-$(team_tmp_root)/teamsmith-smoke.lock}" comp probe busy=0
279
+ comp="$lock"
280
+ if declare -F gate_lock_companion_path >/dev/null 2>&1; then comp="$(gate_lock_companion_path "$lock")"; fi
281
+ if ! command -v flock >/dev/null 2>&1; then return 0; fi
282
+ # P287:互斥在**伴生锁**上(发布路径是兼容声明,P287 之前的写入者只认它)—— 两把都只读探一次,
283
+ # 任一把被持有就算「门禁在跑」;记录按 pair 读(伴生锁边上优先,退回发布路径那条并标 version=legacy)。
284
+ for probe in "$comp" "$lock"; do
285
+ [ -e "$probe" ] || continue
286
+ flock -n "$probe" true 2>/dev/null || { busy=1; break; }
287
+ done
288
+ [ "$busy" = "1" ] || return 0
289
+ local who
290
+ if declare -F gate_lock_describe_pair >/dev/null 2>&1; then
291
+ who="$(gate_lock_describe_pair "$lock")"
292
+ else
293
+ who="$(cat "$lock.holder" 2>/dev/null || printf '持有者未知')"
211
294
  fi
295
+ note "正确性门禁正在跑($who)—— 本次性能读数可能受它影响(性能锁独立,不等它)"
212
296
  }
213
297
 
214
298
  # ── 夹具旋钮(只在 TEAM_PERF_FIXTURE=1 时生效;真路径忽略且打印)────────────────────────────
@@ -328,8 +412,10 @@ perf_run_in_container() {
328
412
  eng_env=(-e HOME=/tmp -e TEAM_PERF_MODE=container -e "TEAM_PERF_REV=$(git -C "$tree" rev-parse --short HEAD 2>/dev/null || printf 'unknown')")
329
413
  # 夹具旋钮与锁身份透传进容器(A1 的注入翻转就在容器里跑)。
330
414
  local k
415
+ # 锁的身份**不**透传:容器那一层不取锁(宿主持有),只带一句「锁由调用方持有」。
416
+ TEAM_PERF_LOCK_HELD_BY_RUNNER=1
331
417
  for k in TEAM_PERF_FIXTURE TEAM_PERF_LOADAVG TEAM_PERF_CORES TEAM_PERF_FRAME_DELAY_MS \
332
- TEAM_PERF_LOCK_WRAPPED TEAM_PERF_NO_LOCK TEAM_PANEL_CPU_SECS; do
418
+ TEAM_PERF_NO_LOCK TEAM_PANEL_CPU_SECS TEAM_PERF_LOCK_HELD_BY_RUNNER; do
333
419
  [ -n "${!k:-}" ] && eng_env+=(-e "$k=${!k}")
334
420
  done
335
421
  say "参考环境:镜像 $PERF_IMAGE(引擎 ${PERF_ENGINE[*]})"
@@ -575,7 +661,7 @@ perf_self_tests() {
575
661
  st "挂载判定:mounts 表读不到 → 这一条判不了,不据此拒绝" 1 "$st_rc"
576
662
  local wir_rc wir_log="$PERF_TMP/m66-wiring.log"
577
663
  wir_rc=0
578
- timeout 10 env -u TEAM_PERF_PINNED_CONTAINER -u TEAM_PERF_LOCK_WRAPPED -u TEAM_PERF_NO_LOCK \
664
+ timeout 10 env -u TEAM_PERF_PINNED_CONTAINER -u TEAM_PERF_LOCK_HELD_BY_RUNNER -u PERF_LOCK_TAKEN -u TEAM_PERF_NO_LOCK \
579
665
  bash "$self" --in-container >"$wir_log" 2>&1 || wir_rc=$?
580
666
  st "入口接线:缺信号 → 真 CLI 可见拒绝 exit 3" 3 "$wir_rc"
581
667
  if [ "$wir_rc" = "3" ] && grep -q 'TEAM_PERF_PINNED_CONTAINER' "$wir_log" && grep -q -- '--host' "$wir_log"; then
@@ -585,14 +671,14 @@ perf_self_tests() {
585
671
  SELFTEST_FAIL=$((SELFTEST_FAIL + 1))
586
672
  fi
587
673
  wir_rc=0
588
- timeout 10 env -u TEAM_PERF_LOCK_WRAPPED -u TEAM_PERF_NO_LOCK TEAM_PERF_PINNED_CONTAINER=0 \
674
+ timeout 10 env -u TEAM_PERF_LOCK_HELD_BY_RUNNER -u PERF_LOCK_TAKEN -u TEAM_PERF_NO_LOCK TEAM_PERF_PINNED_CONTAINER=0 \
589
675
  bash "$self" --in-container >"$wir_log" 2>&1 || wir_rc=$?
590
676
  st "入口接线:错信号(=0)→ 真 CLI 可见拒绝 exit 3" 3 "$wir_rc"
591
677
  # M69 接线:ENV 信号齐全但标识文件缺失/不符(= M64 F2 的宿主伪造形状)也必须瞬时拒绝。
592
678
  # 在真镜像里文件本就在 —— 换成钉「镜像里的文件逐字节等于 token」(镜像构建错了在这里红)。
593
679
  if [ ! -e "$PERF_IMAGE_IDENTITY_FILE" ]; then
594
680
  wir_rc=0
595
- timeout 10 env -u TEAM_PERF_LOCK_WRAPPED -u TEAM_PERF_NO_LOCK TEAM_PERF_PINNED_CONTAINER=1 \
681
+ timeout 10 env -u TEAM_PERF_LOCK_HELD_BY_RUNNER -u PERF_LOCK_TAKEN -u TEAM_PERF_NO_LOCK TEAM_PERF_PINNED_CONTAINER=1 \
596
682
  bash "$self" --in-container >"$wir_log" 2>&1 || wir_rc=$?
597
683
  st "入口接线:有 ENV 信号但缺标识文件(宿主伪造形状)→ 真 CLI 可见拒绝 exit 3" 3 "$wir_rc"
598
684
  if [ "$wir_rc" = "3" ] && grep -q 'teamsmith-gate-image' "$wir_log"; then
@@ -709,7 +795,12 @@ perf_run_suite() { # <mode-label> <reference yes|no> [unavailable]
709
795
  perf_judge_assembly
710
796
  perf_judge_panel
711
797
  perf_self_tests
798
+ # 运行期间互斥被破坏 ⇒ 读数不可信:判红(exit 2),不再输出一份看起来正常的结论
799
+ if ! perf_lock_identity_check; then
800
+ perf_lock_broken=1
801
+ fi
712
802
  perf_summary
803
+ [ "${perf_lock_broken:-0}" = "1" ] && return 2
713
804
  }
714
805
 
715
806
  # ── 入口 ────────────────────────────────────────────────────────────────────────────────────