teamsmith 0.1.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/README.md +13 -7
  2. package/package.json +1 -1
  3. package/skills/teamsmith/CHANGELOG.md +67 -0
  4. package/skills/teamsmith/SKILL.md +26 -8
  5. package/skills/teamsmith/extension/team-notify.ts +37 -6
  6. package/skills/teamsmith/extension/team.ts +438 -0
  7. package/skills/teamsmith/references/agent-adapters.md +7 -7
  8. package/skills/teamsmith/references/config.md +65 -18
  9. package/skills/teamsmith/references/migration.md +220 -34
  10. package/skills/teamsmith/references/protocol.md +250 -25
  11. package/skills/teamsmith/references/troubleshooting.md +124 -7
  12. package/skills/teamsmith/references/workflows.md +66 -20
  13. package/skills/teamsmith/scripts/lib/cmd-agents.sh +525 -90
  14. package/skills/teamsmith/scripts/lib/cmd-bootstrap.sh +71 -10
  15. package/skills/teamsmith/scripts/lib/cmd-config.sh +562 -128
  16. package/skills/teamsmith/scripts/lib/cmd-death.sh +2 -15
  17. package/skills/teamsmith/scripts/lib/cmd-docs.sh +6 -3
  18. package/skills/teamsmith/scripts/lib/cmd-draft.sh +4 -4
  19. package/skills/teamsmith/scripts/lib/cmd-help.sh +677 -0
  20. package/skills/teamsmith/scripts/lib/cmd-init.sh +157 -5
  21. package/skills/teamsmith/scripts/lib/cmd-interrupt.sh +461 -0
  22. package/skills/teamsmith/scripts/lib/cmd-meeting.sh +2 -25
  23. package/skills/teamsmith/scripts/lib/cmd-project.sh +149 -105
  24. package/skills/teamsmith/scripts/lib/cmd-reap.sh +277 -0
  25. package/skills/teamsmith/scripts/lib/cmd-reply.sh +96 -0
  26. package/skills/teamsmith/scripts/lib/cmd-review.sh +188 -40
  27. package/skills/teamsmith/scripts/lib/cmd-status.sh +268 -30
  28. package/skills/teamsmith/scripts/lib/cmd-update.sh +36 -7
  29. package/skills/teamsmith/scripts/lib/cmd-watch.sh +634 -54
  30. package/skills/teamsmith/scripts/lib/common.sh +1560 -109
  31. package/skills/teamsmith/scripts/lib/gate-lock.sh +544 -0
  32. package/skills/teamsmith/scripts/monitor.mjs +34 -3
  33. package/skills/teamsmith/scripts/panel/README.md +22 -11
  34. package/skills/teamsmith/scripts/panel/draft-send.sh +11 -1
  35. package/skills/teamsmith/scripts/panel/panel.js +226 -224
  36. package/skills/teamsmith/scripts/panel/src/App.tsx +478 -184
  37. package/skills/teamsmith/scripts/panel/src/clipboard.ts +11 -5
  38. package/skills/teamsmith/scripts/panel/src/compose.ts +6 -3
  39. package/skills/teamsmith/scripts/panel/src/data.ts +95 -7
  40. package/skills/teamsmith/scripts/panel/src/layout.ts +703 -152
  41. package/skills/teamsmith/scripts/panel/src/main.tsx +129 -19
  42. package/skills/teamsmith/scripts/panel/src/settings.ts +1 -1
  43. package/skills/teamsmith/scripts/panel/src/strings/en.ts +76 -31
  44. package/skills/teamsmith/scripts/panel/src/strings/zh.ts +78 -33
  45. package/skills/teamsmith/scripts/panel/src/types.ts +204 -17
  46. package/skills/teamsmith/scripts/replies.mjs +896 -0
  47. package/skills/teamsmith/scripts/shim/tmux +18 -0
  48. package/skills/teamsmith/scripts/strings/commands.tsv +86 -0
  49. package/skills/teamsmith/scripts/strings/help.en.tsv +503 -0
  50. package/skills/teamsmith/scripts/strings/help.zh.tsv +489 -0
  51. package/skills/teamsmith/scripts/team +20 -6
  52. package/skills/teamsmith/templates/AGENTS.section.md.tmpl +23 -3
  53. package/skills/teamsmith/templates/BOARD.md.tmpl +2 -2
  54. package/skills/teamsmith/templates/OWNERSHIP.md.tmpl +7 -3
  55. package/skills/teamsmith/templates/PROTOCOL.md.tmpl +17 -0
  56. package/skills/teamsmith/templates/config.sh.tmpl +29 -5
  57. package/skills/teamsmith/templates/memory-seed.md.tmpl +3 -0
  58. package/skills/teamsmith/templates/pm-prompt.md.tmpl +41 -1
  59. package/skills/teamsmith/templates/report.md.tmpl +12 -0
  60. package/skills/teamsmith/templates/task.md.tmpl +4 -0
  61. package/skills/teamsmith/tests/bg-ledger-harness.mjs +464 -40
  62. package/skills/teamsmith/tests/bg-ledger.sh +168 -10
  63. package/skills/teamsmith/tests/checkout-shape-probe.sh +3 -1
  64. package/skills/teamsmith/tests/config-cli.sh +320 -300
  65. package/skills/teamsmith/tests/death-cause.sh +5 -2
  66. package/skills/teamsmith/tests/fixtures/delivery-truth-real/scenario.sh +7 -1
  67. package/skills/teamsmith/tests/fixtures/p287/lint-good.sh.in +3 -0
  68. package/skills/teamsmith/tests/fixtures/p287/lint-hardcoded.sh.in +3 -0
  69. package/skills/teamsmith/tests/fixtures/p287/lint-no-ns.sh.in +3 -0
  70. package/skills/teamsmith/tests/fixtures/p55/flip-p49.sh +18 -6
  71. package/skills/teamsmith/tests/flip-m33.sh +5 -3
  72. package/skills/teamsmith/tests/flip-m37.sh +4 -1
  73. package/skills/teamsmith/tests/flip-m4.3.sh +4 -1
  74. package/skills/teamsmith/tests/flip-m6.3.sh +4 -1
  75. package/skills/teamsmith/tests/flip-m6.5.sh +4 -1
  76. package/skills/teamsmith/tests/flip-m7.2.sh +4 -1
  77. package/skills/teamsmith/tests/flip-p158.sh +2 -1
  78. package/skills/teamsmith/tests/flip-p210.sh +4 -1
  79. package/skills/teamsmith/tests/flip-p217.sh +4 -1
  80. package/skills/teamsmith/tests/flip-p287-lock.sh +342 -0
  81. package/skills/teamsmith/tests/flip-p287-name.sh +279 -0
  82. package/skills/teamsmith/tests/flip-p304-read-side.sh +98 -0
  83. package/skills/teamsmith/tests/flip-p308-skip-not-pass.sh +151 -0
  84. package/skills/teamsmith/tests/flip-p309-p162-deep.sh +122 -0
  85. package/skills/teamsmith/tests/flip-p310-lock.sh +216 -0
  86. package/skills/teamsmith/tests/flip-p310-socket.sh +125 -0
  87. package/skills/teamsmith/tests/help-surface.sh +1664 -0
  88. package/skills/teamsmith/tests/install-shape.sh +283 -22
  89. package/skills/teamsmith/tests/key-replies-pty.sh +374 -0
  90. package/skills/teamsmith/tests/key-replies-ui.sh +325 -0
  91. package/skills/teamsmith/tests/key-replies.sh +1314 -0
  92. package/skills/teamsmith/tests/ledger-ban.sh +9 -8
  93. package/skills/teamsmith/tests/ledger-claim.sh +248 -0
  94. package/skills/teamsmith/tests/lib/bounded-spin.sh +90 -0
  95. package/skills/teamsmith/tests/lib/model-policy.sh +30 -0
  96. package/skills/teamsmith/tests/lib/model-routing-boundary.sh +420 -0
  97. package/skills/teamsmith/tests/lib/model-routing-expansion.sh +155 -0
  98. package/skills/teamsmith/tests/lib/model-routing-flips.py +187 -0
  99. package/skills/teamsmith/tests/lib/model-routing-roles.sh +250 -0
  100. package/skills/teamsmith/tests/lib/proc-io.sh +103 -0
  101. package/skills/teamsmith/tests/lib/reply-fixture.sh +367 -0
  102. package/skills/teamsmith/tests/lib/section-guard.sh +258 -13
  103. package/skills/teamsmith/tests/lib/tmp-root.sh +139 -27
  104. package/skills/teamsmith/tests/lib/tmux-cap.sh +10 -1
  105. package/skills/teamsmith/tests/lib/tmux-iso.sh +39 -13
  106. package/skills/teamsmith/tests/loop-inventory.tsv +59 -47
  107. package/skills/teamsmith/tests/panel-b2.sh +107 -4
  108. package/skills/teamsmith/tests/panel-b3-stub.sh +139 -4
  109. package/skills/teamsmith/tests/panel-b3.sh +189 -29
  110. package/skills/teamsmith/tests/panel-choices.sh +81 -63
  111. package/skills/teamsmith/tests/panel-cpu.sh +3 -2
  112. package/skills/teamsmith/tests/panel-knobs.sh +7 -1
  113. package/skills/teamsmith/tests/panel-p21.sh +445 -241
  114. package/skills/teamsmith/tests/panel-snapshots.sh +41 -225
  115. package/skills/teamsmith/tests/panel-strings.mjs +33 -18
  116. package/skills/teamsmith/tests/perf.sh +122 -31
  117. package/skills/teamsmith/tests/pm-box-real.sh +1 -1
  118. package/skills/teamsmith/tests/pulse-nudge-key.sh +1 -1
  119. package/skills/teamsmith/tests/routes.sh +364 -109
  120. package/skills/teamsmith/tests/seat-interrupt.sh +1002 -0
  121. package/skills/teamsmith/tests/seat-visibility.sh +675 -0
  122. package/skills/teamsmith/tests/section-budgets.tsv +26 -12
  123. package/skills/teamsmith/tests/section-guard.sh +6 -1
  124. package/skills/teamsmith/tests/section-needs-audit.sh +24 -7
  125. package/skills/teamsmith/tests/section-paths.tsv +42 -26
  126. package/skills/teamsmith/tests/section-select.sh +90 -7
  127. package/skills/teamsmith/tests/slash-team-e2e.sh +323 -0
  128. package/skills/teamsmith/tests/slash-team.sh +617 -0
  129. package/skills/teamsmith/tests/smoke.sh +3762 -628
  130. package/skills/teamsmith/tests/snapshots/zh-dark-120-detail.txt +2 -2
  131. package/skills/teamsmith/tests/snapshots/zh-dark-120-p4.txt +2 -2
  132. package/skills/teamsmith/tests/snapshots/zh-dark-120.txt +9 -9
  133. package/skills/teamsmith/tests/snapshots/zh-dark-160-p4.txt +2 -2
  134. package/skills/teamsmith/tests/snapshots/zh-dark-160.txt +9 -9
  135. package/skills/teamsmith/tests/snapshots/zh-dark-59-detail.txt +1 -1
  136. package/skills/teamsmith/tests/snapshots/zh-dark-59-p4.txt +1 -1
  137. package/skills/teamsmith/tests/snapshots/zh-dark-59.txt +5 -5
  138. package/skills/teamsmith/tests/snapshots/zh-dark-99-p4.txt +2 -2
  139. package/skills/teamsmith/tests/snapshots/zh-dark-99.txt +5 -5
  140. package/skills/teamsmith/tests/snapshots/zh-light-120-detail.txt +2 -2
  141. package/skills/teamsmith/tests/snapshots/zh-light-120-p4.txt +2 -2
  142. package/skills/teamsmith/tests/snapshots/zh-light-120.txt +9 -9
  143. package/skills/teamsmith/tests/snapshots/zh-light-160-p4.txt +2 -2
  144. package/skills/teamsmith/tests/snapshots/zh-light-160.txt +9 -9
  145. package/skills/teamsmith/tests/snapshots/zh-light-59-detail.txt +1 -1
  146. package/skills/teamsmith/tests/snapshots/zh-light-59-p4.txt +1 -1
  147. package/skills/teamsmith/tests/snapshots/zh-light-59.txt +5 -5
  148. package/skills/teamsmith/tests/snapshots/zh-light-99-p4.txt +2 -2
  149. package/skills/teamsmith/tests/snapshots/zh-light-99.txt +5 -5
  150. package/skills/teamsmith/tests/task-header-model.sh +2 -1
  151. package/skills/teamsmith/tests/task-model-routing.sh +1511 -0
  152. package/skills/teamsmith/tests/tmp-hygiene.sh +782 -45
  153. package/skills/teamsmith/tests/tmux-identity-leak.sh +773 -0
  154. package/skills/teamsmith/tests/tmux-lint-legacy.txt +12 -18
  155. package/skills/teamsmith/tests/upgrade-recipe.sh +537 -0
  156. package/skills/teamsmith-init/SKILL.md +43 -43
  157. package/skills/teamsmith-init/references/bootstrap.md +8 -6
  158. package/skills/teamsmith-init/templates/bootstrap-prompt.md.tmpl +9 -5
@@ -15,14 +15,28 @@
15
15
  # 2 = 用法错误、表畸形、未知 key、路径出界。
16
16
  #
17
17
  # 决定语义(保守方向永远是「多跑」):
18
- # NONE = 给的路径全在豁免类(docs/*,团队账本)且没有行声明它 → 没有段需要跑
18
+ # NONE = 给的路径全在豁免类(docs/*,团队账本)且没有被表头 ledger-scan 归属模式覆盖
19
+ # → 没有段需要跑
19
20
  # RUN = 给的路径每条都被某些行声明 → 这些 key + 前导段 + needs 闭包,按源序
20
21
  # FULL = 至少一条路径没有任何行声明、也不在豁免类 → 跑全套(兜底不可绕过)
22
+ #
23
+ # 账本(docs/team/**)的归属(P239):patterns 列**不允许**声明豁免类(--check ④ 守着这条),
24
+ # 所以账本路径的归属写在表头一行 `# ledger-scan: <key> <pattern…>`:命中的路径归那一段。
25
+ # 删掉这行(或它的归属模式)→ 账本路径回到豁免类(NONE);--check ⑦ 会对「缺头 / 指向未知段 /
26
+ # 没有模式 / 模式没盖住账本样例」逐条判红。
27
+ # P231:这行还必须**唯一**,且指向**承载账本禁令的那一段**(patterns 列声明了 $LSC_CARRIER)——
28
+ # 两份表头(旧行为:最后一行赢)或指向别的段都不再放行,**装载时就报错点名**(die,rc=2)。
21
29
  set -uo pipefail
22
30
 
23
31
  here="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
24
32
  SEL_DIR="$here"
25
33
 
34
+ # P287:临时根名字里的项目命名空间(ns)的唯一实现在 scripts/lib/common.sh —— 独立跑本脚本时补一次。
35
+ if ! declare -F team_project_ns >/dev/null 2>&1; then
36
+ [ -f "$here/../scripts/lib/common.sh" ] && . "$here/../scripts/lib/common.sh"
37
+ fi
38
+ section_select_ns() { team_project_ns 2>/dev/null || printf 'nosig-00000000\n'; }
39
+
26
40
  ROOT=""
27
41
  MODE=""
28
42
  COPY_OUT=""
@@ -90,17 +104,27 @@ CHECKOUT_SHAPE="$(checkout_shape "$ROOT")"
90
104
  # needs :必须先跑的段 key(逗号分隔);`-` = 无。选段时它们连同自己的 needs 一起进闭包。
91
105
  P_EXEMPT=""
92
106
  P_PROLOGUE=""
107
+ P_LEDGER_SCAN="" # 表头 `# ledger-scan: <key> <pattern…>`:账本(docs/team/**)的归属行(P239)
108
+ P_LEDGER_PAT="" # 上面那行的归属模式(空格分隔,同 patterns 列的 case glob 语义)
109
+ P_LEDGER_LINE="" # 上面那行的原文载荷(解析用;空 = 表里没有这行)
110
+ P_LEDGER_LNS=() # 上面那行在表里的行号(P231:>1 行 = 重复声明,装载即拒绝)
111
+ LSC_CARRIER="skills/teamsmith/tests/ledger-ban.sh" # 承载账本禁令的段:patterns 列里必须有它(P231)
93
112
  T_N=0
94
113
  T_KEY=(); T_ID=(); T_PAT=(); T_NEEDS=(); T_BASIS=()
95
114
 
96
115
  load_table() {
97
116
  [ -r "$TSV" ] || die "读不到映射表 $TSV"
98
- local line nf
117
+ local line nf ln=0
99
118
  T_N=0
100
119
  while IFS= read -r line || [ -n "$line" ]; do
120
+ ln=$((ln + 1))
101
121
  case "$line" in
102
122
  "# exempt:"*) P_EXEMPT="${line#\# exempt:}"; P_EXEMPT="${P_EXEMPT# }"; P_EXEMPT="${P_EXEMPT% }"; continue ;;
103
123
  "# prologue:"*) P_PROLOGUE="${line#\# prologue:}"; P_PROLOGUE="${P_PROLOGUE# }"; P_PROLOGUE="${P_PROLOGUE% }"; continue ;;
124
+ "# ledger-scan:"*) P_LEDGER_LINE="${line#\# ledger-scan:}"; P_LEDGER_LINE="${P_LEDGER_LINE# }"; P_LEDGER_LINE="${P_LEDGER_LINE% }"
125
+ P_LEDGER_SCAN="${P_LEDGER_LINE%% *}"; P_LEDGER_PAT="${P_LEDGER_LINE#"$P_LEDGER_SCAN"}"; P_LEDGER_PAT="${P_LEDGER_PAT# }"
126
+ P_LEDGER_LNS+=("$ln")
127
+ continue ;;
104
128
  "#"*|"") continue ;;
105
129
  esac
106
130
  IFS=$'\t' read -r -a F <<<"$line"
@@ -114,6 +138,25 @@ load_table() {
114
138
  [ "$T_N" -gt 0 ] || die "映射表是空的:$TSV"
115
139
  [ -n "$P_EXEMPT" ] || die "映射表缺 exempt 头(豁免类声明)"
116
140
  [ -n "$P_PROLOGUE" ] || die "映射表缺 prologue 头(前导段声明)"
141
+ load_table_check_ledger_head
142
+ }
143
+
144
+ # P231:ledger-scan 头的两条装载期铁律 —— 必须是**唯一**一行,且指向**承载账本禁令的那一段**
145
+ # (那一段的 patterns 列声明了 $LSC_CARRIER)。两种违反过去都能过:两份表头是最后一行赢,指向
146
+ # 别的段只看「段在不在」。现在都在装载时报错点名(文件 + 行号),不静默选一边。
147
+ load_table_check_ledger_head() {
148
+ local row
149
+ if [ "${#P_LEDGER_LNS[@]}" -gt 1 ]; then
150
+ die "映射表有 ${#P_LEDGER_LNS[@]} 行 ledger-scan 头($TSV:$(printf '%s' "${P_LEDGER_LNS[*]}" | tr ' ' ','))—— 归属只许声明一处(旧行为是最后一行赢,已拒绝)"
151
+ fi
152
+ [ -n "$P_LEDGER_SCAN" ] || return 0 # 缺头不是装载错:--check ⑦ 判红(账本路径回到 NONE)
153
+ if ! row="$(row_idx "$P_LEDGER_SCAN")"; then
154
+ die "ledger-scan 头($TSV:${P_LEDGER_LNS[0]})指向未知段 [$P_LEDGER_SCAN] —— 归属必须落在承载账本禁令的那一段(patterns 里有 $LSC_CARRIER)"
155
+ fi
156
+ case " ${T_PAT[row]} " in
157
+ *" $LSC_CARRIER "*) ;;
158
+ *) die "ledger-scan 头($TSV:${P_LEDGER_LNS[0]})指向 [$P_LEDGER_SCAN],但那一行的 patterns 列没有 $LSC_CARRIER —— 归属必须落在承载账本禁令的那一段" ;;
159
+ esac
117
160
  }
118
161
 
119
162
  # ── 门禁源码里的段(顺序 = 源序)──────────────────────────────────────────────────────────
@@ -385,7 +428,8 @@ emit_copy() { # <out>
385
428
  do_verify_copies() {
386
429
  build_groups
387
430
  local d out k n=0 bad=0 i
388
- d="$(mktemp -d "${TMPDIR:-/tmp}/teamsmith-select-copies.XXXXXX")" || die "建不了临时目录(TMPDIR=${TMPDIR:-/tmp})"
431
+ team_tmp_root_prepare >/dev/null 2>&1 || true
432
+ d="$(mktemp -d "$(team_tmp_root)/teamsmith-select-copies-$(section_select_ns).XXXXXX")" || die "建不了临时目录(TMPDIR=$(team_tmp_root))"
389
433
  trap 'rm -rf "${d:-}"' EXIT
390
434
  printf '== 段副本 bash -n 全键扫描 ==\n'
391
435
  for ((i = 0; i < T_N; i++)); do
@@ -419,6 +463,15 @@ do_paths() {
419
463
  fi
420
464
  done
421
465
  done
466
+ if [ "$claimed" = "0" ]; then
467
+ # 账本归属(P239):patterns 列不许声明豁免类,所以账本路径的归属由表头 ledger-scan 行提供。
468
+ if [ -n "$P_LEDGER_PAT" ]; then
469
+ IFS=' ' read -r -a PARR <<<"$P_LEDGER_PAT"
470
+ for pp in "${PARR[@]}"; do
471
+ if pat_match "$pp" "$p"; then claimed=1; add_key "$P_LEDGER_SCAN" "$p"; break; fi
472
+ done
473
+ fi
474
+ fi
422
475
  if [ "$claimed" = "0" ]; then
423
476
  if pat_match "$P_EXEMPT" "$p"; then exempted+=("$p"); else unclaimed+=("$p"); fi
424
477
  fi
@@ -435,7 +488,7 @@ do_paths() {
435
488
  printf 'decision=NONE\n'
436
489
  printf 'sections=%s\n' "$S_N"
437
490
  printf 'keys=0\n'
438
- for p in "${exempted[@]}"; do printf 'reason=%s ← 豁免类(%s):团队账本,门禁不为它开火\n' "$p" "$P_EXEMPT"; done
491
+ for p in "${exempted[@]}"; do printf 'reason=%s ← 豁免类(%s)且没有被账本归属(ledger-scan)覆盖:门禁不为它开火\n' "$p" "$P_EXEMPT"; done
439
492
  printf 'reason=没有段落需要运行(no section needs to run)\n'
440
493
  return 0
441
494
  fi
@@ -474,11 +527,15 @@ do_list() {
474
527
  # ① 段 ↔ 行一一对应(段没行 / 行没段 / 重复 key)
475
528
  # ② needs 存在且指向**更早**的段
476
529
  # ③ 字面模式(无通配)存在于工作树
477
- # ④ 豁免类没有任何行声明
530
+ # ④ 豁免类没有任何行声明(patterns 列)
478
531
  # ⑤ 前导段的 key 都在(否则选段会少跑前导)
479
532
  # ⑥ 段正文里点名的**真实**路径 token 必须被该行的 patterns 覆盖(token 与行号都点名);
480
- # 豁免类(docs/**)的 token 不参与该检查 —— 按 ④ 没有任何行可以声明它们(选择器对它们的
481
- # 回答是 NONE,不是某一段)
533
+ # 豁免类(docs/**)的 token 不参与该检查 —— 按 ④ 没有任何行可以声明它们(账本路径的归属由
534
+ # 表头 ledger-scan 行担当,不写进 patterns,所以这里也不参与;它有自己的 ⑦)
535
+ # ⑦ 账本归属(P239):表头 ledger-scan 行必须在、指向已存在的段、有归属模式,且模式盖住
536
+ # 每一个账本样例(缺一样 = 账本文本的改动不再选中任何段 → 红)。
537
+ # P231:「唯一 + 指向承载禁令的段」这两条在装载期就 die(load_table_check_ledger_head),
538
+ # 走到这里时它们已经成立 —— 下面「指向未知段」那一支只是防御,不是第一道门。
482
539
  # 段正文的 normalizer(与 P97 探针同一口径):$SKILL_DIR→skills/teamsmith、
483
540
  # $SKILL_INIT_DIR→skills/teamsmith-init、$SRC_ROOT/$OS_ROOT/$V94_ROOT→仓库根;
484
541
  # 裸前缀 skills/ panel/ extension/ openspec/ ci/;根文件 SCOPE.md/README.md/AGENTS.md/CHANGELOG.md。
@@ -640,6 +697,32 @@ do_check() {
640
697
  done < "$SUITE"
641
698
  [ "$tok_bad" -eq 0 ] && cok "段正文点名的真实路径 token 都被各自的行覆盖($tok_n 个 token 检查过;$ex_tok_n 个豁免类 token 不参与)"
642
699
 
700
+ # ⑦ 账本归属(P239):表头 ledger-scan 行必须在、指向已存在的段、有归属模式,且模式盖住每个账本样例。
701
+ # 缺一样 = 账本文本的改动不再选中任何段(回到 NONE);这一条是它的静态牙(行为面在 §60 的夹具里)。
702
+ local lsc_bad=0 lsc_n=0 lsc_row=""
703
+ if [ -z "$P_LEDGER_SCAN" ]; then
704
+ cbad "映射表缺 ledger-scan 头(账本路径没有归属声明处)"; lsc_bad=$((lsc_bad + 1))
705
+ else
706
+ lsc_row="$(row_idx "$P_LEDGER_SCAN" || true)"
707
+ [ -n "$lsc_row" ] || { cbad "ledger-scan 头 [$P_LEDGER_SCAN] 不在映射表里(归属指向未知段)"; lsc_bad=$((lsc_bad + 1)); }
708
+ [ -n "$P_LEDGER_PAT" ] || { cbad "ledger-scan 头没有归属模式($P_LEDGER_SCAN)"; lsc_bad=$((lsc_bad + 1)); }
709
+ fi
710
+ if [ -n "$lsc_row" ] && [ -n "$P_LEDGER_PAT" ]; then
711
+ IFS=' ' read -r -a LSPART <<<"$P_LEDGER_PAT"
712
+ for j in docs/team/BOARD.md docs/team/ROADMAP.md docs/team/reports/X.md docs/team/tasks/X.md \
713
+ docs/team/threads/dev.md docs/team/inbox/dev.md docs/team/reviews/X.md \
714
+ docs/team/OWNERSHIP.md docs/team/DECISIONS.md; do
715
+ covered=0
716
+ for pp in "${LSPART[@]}"; do pat_match "$pp" "$j" && { covered=1; break; }; done
717
+ if [ "$covered" = "0" ]; then
718
+ cbad "ledger-scan 归属模式没有覆盖 $j(改这个路径不会选中它)"; lsc_bad=$((lsc_bad + 1))
719
+ else
720
+ lsc_n=$((lsc_n + 1))
721
+ fi
722
+ done
723
+ fi
724
+ [ "$lsc_bad" -eq 0 ] && cok "账本归属(ledger-scan $P_LEDGER_SCAN)声明有效:$lsc_n/9 个账本样例被它覆盖"
725
+
643
726
  printf '== 选段自检 == ok %d bad %d SKIP %d\n' "$CHECK_OK" "$CHECK_BAD" "$CHECK_SKIP"
644
727
  [ "$CHECK_BAD" -eq 0 ] || return 1
645
728
  return 0
@@ -0,0 +1,323 @@
1
+ #!/usr/bin/env bash
2
+ # slash-team-e2e.sh — `/team` 的**端到端层**(change: slash-team · 实现:P270)
3
+ #
4
+ # bash skills/teamsmith/tests/slash-team-e2e.sh [--flip] [--keep]
5
+ #
6
+ # 真 pi(`--mode rpc --no-session --approve`)+ 夹具项目里的记录桩:
7
+ # - `PI_CODING_AGENT_DIR` 指向夹具自己的空目录(无凭据、无模型、不读 $HOME 的 pi 配置、不写 trust store)
8
+ # - 项目本地装扩展(`.pi/extensions/team.ts`,Pi 自动发现)+ `team` 桩(`.pi/skills/teamsmith/scripts/team`)
9
+ # - stdin 发 `/team …`,判 JSONL:`disposition:"handled"`、`message_start` 的 content/display、
10
+ # `extension_ui_request` 的 notifyType、桩记下的 argv/cwd/env。
11
+ #
12
+ # 判据(spec extension-slash 的场景):
13
+ # 短成功 → 只有 info 通知;多行成功 → 进正文;桩退出 3 → error 通知点名 3 + 正文带两路流;
14
+ # 表外命令 → 拒绝且桩日志里没有它;`TEAM_ASSUME_YES=1` 的会话 → 子进程环境里没有它、argv 里没有注入的 --yes。
15
+ #
16
+ # `--flip`:把扩展的正文落点改成 notify(scratch 副本装进第二个夹具)——「多行成功进正文」必须变红。
17
+ #
18
+ # 退出码:0 全绿 / 前置不满足时可见 SKIP 也 0;1 有失败;2 用法错误;3 setup 失败。
19
+ set -uo pipefail
20
+
21
+ here="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
22
+ tree="$(cd -P "$here/../../.." && pwd)"
23
+ . "$here/lib/tmp-root.sh"
24
+
25
+ # 原始 argv 先存档:守卫的 re-exec 必须拿到**没被 shift 消耗过**的那份 ——
26
+ # 直接传 "$@" 会把 `--flip` 丢掉(脚本照样绿、翻转臂静默少跑两条)。
27
+ ORIG_ARGS=("$@")
28
+ FLIP=0
29
+ KEEP=0
30
+ argc=$#
31
+ while [ $# -gt 0 ]; do
32
+ case "$1" in
33
+ --flip) FLIP=1; shift ;;
34
+ --keep) KEEP=1; export TEAM_TMP_KEEP=1; shift ;;
35
+ -h|--help) sed -n '2,20p' "$0"; exit 0 ;;
36
+ *) printf 'slash-team-e2e: 未知参数 %s(用法见 --help)\n' "$1" >&2; exit 2 ;;
37
+ esac
38
+ # 每个分支都必须 shift:`--keep` 曾经漏了 shift,脚本于是永不退出、零输出地空转
39
+ # (PM 2026-10-16 收掉过一个挂了 1h35m 的 --keep 进程)。这条守卫把同一类缺陷变成
40
+ # 立刻可见的 rc=2,而不是一个静默的死循环。
41
+ [ "$#" -lt "$argc" ] || { printf '%s: 参数循环没有前进(分支缺 shift?):%s\n' "slash-team-e2e" "$1" >&2; exit 2; }
42
+ argc=$#
43
+ done
44
+
45
+ # 兜底超时(本轮修掉的缺陷,见报告的 finding):真 pi 的 RPC 路径会等 stdin / 模型响应,子进程一旦卡在
46
+ # read 上,脚本原先可以无限等下去 —— PM 2026-10-16 收掉过一个挂了 1h35m 的 `--keep` 进程(pid 324481)。
47
+ # 现在无论谁怎么调(含 --keep、含被接到管道上),整个脚本都在这里被掐掉:先 TERM,10s 后 KILL。
48
+ # 调用方不必记得加 timeout;要换上限就给 TEAM_SLASH_E2E_GUARD(秒)。
49
+ e2e_guard() {
50
+ local sec="${TEAM_SLASH_E2E_GUARD:-300}"
51
+ if [ -z "${TEAM_SLASH_E2E_GUARDED:-}" ]; then
52
+ printf 'slash-team-e2e: 兜底超时 %ss(TEAM_SLASH_E2E_GUARD 可改);超时先 TERM 再 KILL\n' "$sec"
53
+ TEAM_SLASH_E2E_GUARDED=1 exec timeout --kill-after=10 "$sec" bash "$0" "$@"
54
+ fi
55
+ }
56
+ e2e_guard "${ORIG_ARGS[@]}"
57
+
58
+ ext="$tree/skills/teamsmith/extension/team.ts"
59
+ [ -f "$ext" ] || { printf 'slash-team-e2e: 没有扩展源 %s\n' "$ext" >&2; exit 3; }
60
+
61
+ PI_BIN="${TEAM_SLASH_PI:-}"
62
+ if [ -z "$PI_BIN" ]; then
63
+ # 裸名字不可靠(登录 shell 的 PATH 与交互 shell 不同,且门禁会把假 pi 放在 PATH 最前)——
64
+ # 先试真实安装路径,再退回 PATH 上的名字。
65
+ for cand in "$HOME/.bun/bin/pi" "$(command -v pi 2>/dev/null || true)"; do
66
+ [ -n "$cand" ] && [ -x "$cand" ] && { PI_BIN="$cand"; break; }
67
+ done
68
+ fi
69
+ if [ -z "$PI_BIN" ]; then
70
+ printf '\033[33mSKIP(前置不成立:本机没有 pi)\033[0m 端到端层跑不了(纯逻辑层仍可跑:tests/slash-team.sh)\n'
71
+ exit 0
72
+ fi
73
+ # 门禁的假 pi 不是真 pi(它只会回显参数):显式 SKIP,不把「桩没反应」当成产品失败。
74
+ if "$PI_BIN" --version 2>&1 | grep -q 'smoke-fake'; then
75
+ printf '\033[33mSKIP(前置不成立:%s 是门禁的假 pi,不是真 pi)\033[0m 端到端层跑不了;用 TEAM_SLASH_PI 指一个真 pi\n' "$PI_BIN"
76
+ exit 0
77
+ fi
78
+
79
+ tmp="$(tmp_root_create slash-team-e2e)" || exit 3
80
+ cleanup() {
81
+ [ "${BASHPID:-$$}" = "$$" ] || return 0
82
+ if [ "$KEEP" = "1" ]; then printf '\n保留夹具目录:%s\n' "$tmp"
83
+ else tmp_root_reap_all; fi
84
+ }
85
+ trap cleanup EXIT
86
+
87
+ PASS=0; FAIL=0
88
+ ok() { printf ' \033[32m✓\033[0m %s\n' "$1"; PASS=$((PASS + 1)); }
89
+ bad() { printf ' \033[31m✗\033[0m %s\n' "$1"; FAIL=$((FAIL + 1)); }
90
+ assert_eq() { [ "$2" = "$3" ] && ok "$1" || bad "$1(期望 [$3],实际 [$2])"; }
91
+ assert_has() { printf '%s' "$1" | grep -qF -- "$2" && ok "$3" || bad "$3(在 [$1] 里找不到 [$2])"; }
92
+ assert_not() { printf '%s' "$1" | grep -qF -- "$2" && bad "$3(不该出现 [$2])" || ok "$3"; }
93
+
94
+ # ---------------------------------------------------------------- 夹具
95
+ fixture() { # <dir> <扩展源>:项目本地装扩展 + 记录 argv/cwd/env 的 team 桩
96
+ local d="$1" src="$2"
97
+ mkdir -p "$d/.pi/team" "$d/.pi/extensions" "$d/.pi/skills/teamsmith/scripts" "$d/agentdir" "$d/home" "$d/sessions"
98
+ printf 'TEAM_SESSION=e2e\n' > "$d/.pi/team/config.sh"
99
+ cp "$src" "$d/.pi/extensions/team.ts"
100
+ cat > "$d/.pi/skills/teamsmith/scripts/team" <<'STUB'
101
+ #!/usr/bin/env bash
102
+ # 记录桩:每次调用追加一个 BEGIN…END 块(argv 逐 token / cwd / 三个被剥离变量的实际值)。
103
+ {
104
+ printf 'BEGIN\n'
105
+ for a in "$@"; do printf 'ARG\t%s\n' "$a"; done
106
+ printf 'CWD\t%s\n' "$PWD"
107
+ printf 'ASSUME\t%s\n' "${TEAM_ASSUME_YES-unset}"
108
+ printf 'UPGRADE\t%s\n' "${TEAM_UPGRADE_CONFIRMED-unset}"
109
+ printf 'FOREIGN\t%s\n' "${TEAM_ALLOW_FOREIGN_SESSION-unset}"
110
+ printf 'END\n'
111
+ } >> "${REC_LOG:?REC_LOG 没给}"
112
+ case "${1:-}" in
113
+ version) printf '0.1.0-stub\n' ;;
114
+ doctor) printf 'out line\n'; printf 'boom\n' >&2; exit 3 ;;
115
+ ps) printf 'a\nb\n' ;;
116
+ *) printf 'x\ny\n' ;;
117
+ esac
118
+ exit 0
119
+ STUB
120
+ chmod +x "$d/.pi/skills/teamsmith/scripts/team"
121
+ }
122
+
123
+ prompts_for() { # <文件>
124
+ cat > "$1" <<'P'
125
+ {"id":"1","type":"prompt","message":"/team version"}
126
+ {"id":"2","type":"prompt","message":"/team ps"}
127
+ {"id":"3","type":"prompt","message":"/team doctor"}
128
+ {"id":"4","type":"prompt","message":"/team dispatch dev P1 docs/team/tasks/P1.md"}
129
+ {"id":"5","type":"prompt","message":"/team meeting say alpha --intent proposal \"two words\""}
130
+ {"id":"6","type":"prompt","message":"/team config upgrade-models --task-models routine=vendor/light --pm-model vendor/strong"}
131
+ {"id":"7","type":"prompt","message":"/team config upgrade-models --task-models routine=vendor/light --pm-model vendor/strong --yes"}
132
+ P
133
+ }
134
+
135
+ run_pi() { # <proj> <prompts> <out> <err> <rec-log>
136
+ # 写完 prompt 后**不马上关 stdin**(立刻 EOF 会让 pi 只处理第一条就退出),而是等回执数到齐
137
+ # 再关;关闭 = pi 收尾退出。写端有界(250×0.2s),不让夹具挂住。
138
+ local proj="$1" prompts="$2" out="$3" err="$4" rec="$5"
139
+ local want i; want="$(grep -c . "$prompts")"
140
+ : > "$out"; : > "$err"
141
+ {
142
+ cat "$prompts"
143
+ for i in $(seq 1 150); do
144
+ [ "$(grep -c '"type":"response"' "$out" 2>/dev/null || true)" -ge "$want" ] && break
145
+ sleep 0.2
146
+ done
147
+ } | ( cd "$proj" && exec env HOME="$proj/home" PI_CODING_AGENT_DIR="$proj/agentdir" TEAM_ASSUME_YES=1 REC_LOG="$rec" \
148
+ timeout --kill-after=5 120 "$PI_BIN" --mode rpc --no-session --approve --session-dir "$proj/sessions" ) > "$out" 2> "$err"
149
+ return $?
150
+ }
151
+
152
+ # 桩日志里含 <pattern>(且不含 <exclude>,给了的话)的那个 BEGIN…END 块(找不到 → 空)
153
+ rec_block() { # <log> <pattern> [exclude]
154
+ awk -v pat="$2" -v exc="${3:-}" '
155
+ /^BEGIN$/ { buf = ""; keep = 0; seen_exc = 0; inblk = 1; next }
156
+ /^END$/ { if (inblk && keep && !seen_exc) { printf "%s", buf }; inblk = 0; next }
157
+ inblk {
158
+ buf = buf $0 "\n"
159
+ if (index($0, pat) > 0) keep = 1
160
+ if (exc != "" && index($0, exc) > 0) seen_exc = 1
161
+ }
162
+ ' "$1"
163
+ }
164
+ rec_arg_line() { # <block> <n>(第 n 个 ARG 行,1 起)
165
+ printf '%s\n' "$1" | awk -F'\t' -v n="$2" '$1 == "ARG" { c++; if (c == n) { print $2; exit } }'
166
+ }
167
+
168
+ # ---------------------------------------------------------------- 绿侧
169
+ proj="$tmp/proj"
170
+ fixture "$proj" "$ext"
171
+ prompts_for "$tmp/prompts.jsonl"
172
+ rec="$tmp/rec.log"; : > "$rec"
173
+ run_pi "$proj" "$tmp/prompts.jsonl" "$tmp/out.jsonl" "$tmp/err.log" "$rec"
174
+ rc=$?
175
+ out="$(cat "$tmp/out.jsonl" 2>/dev/null)"
176
+
177
+ printf '\n\033[1m== e2e · 真 pi RPC ==\033[0m\n'
178
+ assert_eq "pi RPC 退出码 0(夹具封闭、无模型)" "$rc" "0"
179
+ assert_eq "七条 prompt 都得到成功回执" \
180
+ "$(printf '%s\n' "$out" | grep -c '"type":"response","command":"prompt","success":true')" "7"
181
+ assert_eq "桩被调用了 6 次(表外那条不落桩)" "$(grep -c '^BEGIN$' "$rec" || true)" "6"
182
+
183
+ # ① 短成功 ⇒ 只有 info 通知,不进正文
184
+ notify_version="$(printf '%s\n' "$out" | grep '"type":"extension_ui_request"' | grep -F '0.1.0-stub')"
185
+ assert_has "$notify_version" '"notifyType":"info"' "短成功是 info 通知"
186
+ assert_has "$notify_version" '"message":"0.1.0-stub"' "通知内容就是那一行"
187
+ assert_not "$out" '$ team version' "短成功没有加正文条目"
188
+
189
+ # ② 多行成功 ⇒ 进正文(display:true),命令行 + 退出码 + 输出
190
+ msg_ps="$(printf '%s\n' "$out" | grep '"type":"message_start"' | grep -F 'teamsmith-team' | grep -F '$ team ps')"
191
+ assert_has "$msg_ps" '"display":true' "多行成功的正文 display 打开"
192
+ assert_has "$msg_ps" 'exit 0' "正文写明退出码 0"
193
+ assert_has "$msg_ps" '--- stdout ---' "正文带 stdout 段"
194
+ assert_has "$msg_ps" 'a\nb' "正文带输出"
195
+
196
+ # ③ 桩退出 3 ⇒ error 通知点名 3 + 正文带两路流
197
+ notify_doctor="$(printf '%s\n' "$out" | grep '"type":"extension_ui_request"' | grep -F 'boom' || printf '%s\n' "$out" | grep '"type":"extension_ui_request"' | grep -F 'exit 3' || printf '%s\n' "$out" | grep '"type":"extension_ui_request"' | grep -F '3')"
198
+ assert_has "$notify_doctor" '"notifyType":"error"' "失败是 error 通知"
199
+ assert_has "$notify_doctor" '3' "失败通知点名退出码 3"
200
+ msg_doctor="$(printf '%s\n' "$out" | grep '"type":"message_start"' | grep -F 'teamsmith-team' | grep -F '$ team doctor')"
201
+ assert_has "$msg_doctor" 'exit 3' "失败正文写明退出码 3"
202
+ assert_has "$msg_doctor" '--- stderr ---' "失败正文带 stderr 段"
203
+ assert_has "$msg_doctor" 'boom' "失败正文带 stderr 内容"
204
+
205
+ # ④ 表外命令 ⇒ 拒绝进正文、零子进程
206
+ msg_dispatch="$(printf '%s\n' "$out" | grep '"type":"message_start"' | grep -F 'teamsmith-team' | grep -F 'dispatch')"
207
+ assert_has "$msg_dispatch" 'dispatch' "拒绝文案点名 dispatch"
208
+ assert_has "$msg_dispatch" 'PM' "拒绝文案说明这是 PM / 席位的命令"
209
+ assert_has "$msg_dispatch" '终端' "拒绝文案给出去终端跑的出路"
210
+ assert_eq "表外命令一个子进程都没起(桩日志里没有它)" "$(printf '%s' "$(rec_block "$rec" 'ARG dispatch')" | wc -l | tr -d ' ')" "0"
211
+
212
+ # ⑤ 用户 token 逐字(双引号里的空格是一个 token)
213
+ blk_say="$(rec_block "$rec" 'ARG meeting')"
214
+ assert_eq "meeting say 的 argv 逐字(含 \"two words\")" \
215
+ "$(printf '%s\n' "$blk_say" | awk -F'\t' '$1 == "ARG" { printf "%s|", $2 }')" \
216
+ "meeting|say|alpha|--intent|proposal|two words|"
217
+
218
+ # ⑥ 环境剥离 + 不注入 --yes + cwd = 项目根
219
+ blk_cfg="$(rec_block "$rec" 'ARG config' '--yes')"
220
+ assert_has "$blk_cfg" "ASSUME unset" "会话里的 TEAM_ASSUME_YES 没进子进程"
221
+ assert_has "$blk_cfg" "UPGRADE unset" "TEAM_UPGRADE_CONFIRMED 没进子进程"
222
+ assert_has "$blk_cfg" "FOREIGN unset" "TEAM_ALLOW_FOREIGN_SESSION 没进子进程"
223
+ assert_not "$blk_cfg" "ARG --yes" "没有注入的 --yes"
224
+ assert_eq "升级命令的 argv 逐字" \
225
+ "$(printf '%s\n' "$blk_cfg" | awk -F'\t' '$1 == "ARG" { printf "%s|", $2 }')" \
226
+ "config|upgrade-models|--task-models|routine=vendor/light|--pm-model|vendor/strong|"
227
+ assert_eq "每次调用的 cwd 都是项目根" "$(grep -c "CWD $proj\$" "$rec" || true)" "6"
228
+ # ⑤b 用户自己敲的 --yes 原样过去(前门不自己加,也不自己删)
229
+ blk_yes="$(rec_block "$rec" 'ARG --yes')"
230
+ assert_eq "用户自己的 --yes 逐字过去" \
231
+ "$(printf '%s\n' "$blk_yes" | awk -F'\t' '$1 == "ARG" { printf "%s|", $2 }')" \
232
+ "config|upgrade-models|--task-models|routine=vendor/light|--pm-model|vendor/strong|--yes|"
233
+
234
+ # ⑤c 真 CLI 的那半边(spec 场景点名):会话里没有 --yes 时,升级命令必须由 CLI 自己的守卫决定
235
+ # —— 跑的是本树真 `team`(软链进夹具),断言「dry-run 字样出现在正文」+「config.sh 字节没动」。
236
+ printf '\n\033[1m== e2e · 真 CLI(前门不替 CLI 做决定)\033[0m\n'
237
+ rproj="$tmp/realcli"
238
+ mkdir -p "$rproj/.pi/team" "$rproj/.pi/extensions" "$rproj/.pi/skills" "$rproj/agentdir" "$rproj/home" "$rproj/sessions" "$rproj/docs/team"
239
+ cp "$ext" "$rproj/.pi/extensions/team.ts"
240
+ # 整棵 skill 软链(与真 `team init` 同形):CLI 按 $0 的目录找 lib/,只软链 team 脚本本身会找不到 common.sh。
241
+ ln -s "$tree/skills/teamsmith" "$rproj/.pi/skills/teamsmith"
242
+ cat > "$rproj/.pi/team/config.sh" <<'RCFG'
243
+ TEAM_SESSION=e2e
244
+ TEAM_AGENTS="dev"
245
+ TEAM_DOCS_DIR=docs/team
246
+ TEAM_DEFAULT_MODEL=vendor/old
247
+ TEAM_AGENT_MODELS="dev=vendor/old"
248
+ RCFG
249
+ ( cd "$rproj" && git init -q -b main && git -c user.email=e2e@teamsmith -c user.name=e2e add -A && git -c user.email=e2e@teamsmith -c user.name=e2e commit -q -m init ) >/dev/null 2>&1
250
+ rc_before="$(sha256sum "$rproj/.pi/team/config.sh" | cut -d' ' -f1)"
251
+ printf '{"id":"1","type":"prompt","message":"/team config upgrade-models --task-models routine=vendor/light --pm-model vendor/strong"}\n' > "$tmp/realcli-prompts.jsonl"
252
+ # 会话环境里不带 TEAM_*(真 CLI 按目录认项目);不清干净会先撞身份冲突,测不到 dry-run。
253
+ # 会话环境:只剥掉 TEAM_*/TMUX*(真 CLI 按目录认项目);不能用 `env -i` —— 本机 pi 是过 distrobox
254
+ # 回家的 shim,清空环境会 rc=127(“distrobox: not found”)。清干净的会话里 CLI 才不会先撞身份冲突。
255
+ strip=()
256
+ while IFS= read -r v; do strip+=(-u "$v"); done < <(env | sed -n 's/^\(TEAM_[A-Za-z0-9_]*\)=.*/\1/p' | sort -u)
257
+ strip+=(-u TMUX -u TMUX_PANE)
258
+ {
259
+ cat "$tmp/realcli-prompts.jsonl"
260
+ for i in $(seq 1 150); do
261
+ [ "$(grep -c '"type":"response"' "$tmp/realcli-out.jsonl" 2>/dev/null || true)" -ge 1 ] && break
262
+ sleep 0.2
263
+ done
264
+ } | ( cd "$rproj" && exec env "${strip[@]}" HOME="$rproj/home" PI_CODING_AGENT_DIR="$rproj/agentdir" \
265
+ timeout --kill-after=5 120 "$PI_BIN" --mode rpc --no-session --approve --session-dir "$rproj/sessions" ) \
266
+ > "$tmp/realcli-out.jsonl" 2> "$tmp/realcli-err.log"
267
+ rout="$(cat "$tmp/realcli-out.jsonl" 2>/dev/null)"
268
+ rc_after="$(sha256sum "$rproj/.pi/team/config.sh" | cut -d' ' -f1)"
269
+ assert_eq "真 CLI:config.sh 字节没动(前门没替人授权)" "$rc_after" "$rc_before"
270
+ msg_real="$(printf '%s\n' "$rout" | grep '"type":"message_start"' | grep -F 'teamsmith-team' | grep -F '$ team config upgrade-models')"
271
+ assert_has "$msg_real" 'dry-run' "真 CLI:正文里是 CLI 自己的 dry-run 判定(说明真跑到了)"
272
+ assert_has "$msg_real" 'exit 0' "真 CLI:正文写明退出码"
273
+ assert_has "$msg_real" 'TEAM_DEFAULT_MODEL' "真 CLI:正文点名要退役的键"
274
+ assert_not "$msg_real" '身份冲突' "真 CLI:没有先撞身份冲突(测的是产品判定)"
275
+
276
+ # ---------------------------------------------------------------- 翻转:正文落点改成 notify
277
+ if [ "$FLIP" = "1" ]; then
278
+ FLIP_PASS_BEFORE="$PASS"
279
+ printf '\n\033[1m== e2e · flip(正文落点改成 notify)\033[0m\n'
280
+ fproj="$tmp/flip"
281
+ fdir="$tmp/flip-src"; mkdir -p "$fdir"
282
+ fext="$fdir/team.ts"
283
+ python3 - "$ext" "$fext" <<'PY'
284
+ import sys
285
+ src, dst = sys.argv[1], sys.argv[2]
286
+ s = open(src, encoding='utf-8').read()
287
+ old = (" const content = formatEntry(m.tokens, res)\n"
288
+ " deps.sendMessage({ customType: CUSTOM_TYPE, content, display: true })")
289
+ new = (" const content = formatEntry(m.tokens, res)\n"
290
+ " deps.notify(content, 'info')")
291
+ if old not in s:
292
+ print('没找到正文落点(夹具没生效)', file=sys.stderr)
293
+ sys.exit(3)
294
+ open(dst, 'w', encoding='utf-8').write(s.replace(old, new, 1))
295
+ PY
296
+ if [ ! -s "$fext" ]; then
297
+ bad "flip:变异没落地(夹具没生效)"
298
+ else
299
+ fixture "$fproj" "$fext"
300
+ printf '{"id":"1","type":"prompt","message":"/team ps"}\n' > "$tmp/flip-prompts.jsonl"
301
+ frec="$tmp/flip-rec.log"; : > "$frec"
302
+ run_pi "$fproj" "$tmp/flip-prompts.jsonl" "$tmp/flip-out.jsonl" "$tmp/flip-err.log" "$frec"
303
+ fout="$(cat "$tmp/flip-out.jsonl" 2>/dev/null)"
304
+ if printf '%s\n' "$fout" | grep -q '"type":"message_start"'; then
305
+ bad "flip:正文落点改成 notify 之后仍然进了正文(判据没钉住)"
306
+ else
307
+ ok "flip:正文落点改成 notify ⇒ 多行结果不再进正文(判据会红)"
308
+ fi
309
+ if printf '%s\n' "$fout" | grep '"type":"extension_ui_request"' | grep -qF '$ team ps'; then
310
+ ok "flip:结果改走通知(现场证据)"
311
+ else
312
+ bad "flip:结果既没进正文也没进通知"
313
+ fi
314
+ fi
315
+ fi
316
+
317
+ if [ "$FLIP" = "1" ] && [ "$PASS" -le "${FLIP_PASS_BEFORE:-0}" ]; then
318
+ bad "flip:--flip 一轮没有多出任何断言(翻转臂没跑 —— argv 丢了或块没进)"
319
+ fi
320
+
321
+ printf '\n\033[1m== 结果 ==\033[0m ✓ %d ✗ %d\n' "$PASS" "$FAIL"
322
+ [ "$FAIL" -eq 0 ] && exit 0
323
+ exit 1