teamsmith 0.0.0-stage → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (245) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +158 -2
  3. package/bin/team.mjs +59 -0
  4. package/install.sh +94 -0
  5. package/package.json +37 -4
  6. package/skills/teamsmith/CHANGELOG.md +763 -0
  7. package/skills/teamsmith/SKILL.md +312 -0
  8. package/skills/teamsmith/extension/team-bg.ts +435 -0
  9. package/skills/teamsmith/extension/team-inbox-watch.ts +1412 -0
  10. package/skills/teamsmith/extension/team-notify.ts +663 -0
  11. package/skills/teamsmith/references/agent-adapters.md +643 -0
  12. package/skills/teamsmith/references/config.md +477 -0
  13. package/skills/teamsmith/references/meeting.md +124 -0
  14. package/skills/teamsmith/references/memory.md +133 -0
  15. package/skills/teamsmith/references/migration.md +227 -0
  16. package/skills/teamsmith/references/openspec.md +222 -0
  17. package/skills/teamsmith/references/philosophy.md +95 -0
  18. package/skills/teamsmith/references/protocol.md +712 -0
  19. package/skills/teamsmith/references/troubleshooting.md +1384 -0
  20. package/skills/teamsmith/references/workflows.md +448 -0
  21. package/skills/teamsmith/scripts/lib/cmd-agents.sh +1709 -0
  22. package/skills/teamsmith/scripts/lib/cmd-bg.sh +284 -0
  23. package/skills/teamsmith/scripts/lib/cmd-bootstrap.sh +311 -0
  24. package/skills/teamsmith/scripts/lib/cmd-config.sh +1156 -0
  25. package/skills/teamsmith/scripts/lib/cmd-death.sh +562 -0
  26. package/skills/teamsmith/scripts/lib/cmd-docs.sh +149 -0
  27. package/skills/teamsmith/scripts/lib/cmd-draft.sh +124 -0
  28. package/skills/teamsmith/scripts/lib/cmd-init.sh +212 -0
  29. package/skills/teamsmith/scripts/lib/cmd-meeting.sh +904 -0
  30. package/skills/teamsmith/scripts/lib/cmd-outbox.sh +196 -0
  31. package/skills/teamsmith/scripts/lib/cmd-project.sh +642 -0
  32. package/skills/teamsmith/scripts/lib/cmd-review.sh +1393 -0
  33. package/skills/teamsmith/scripts/lib/cmd-status.sh +1399 -0
  34. package/skills/teamsmith/scripts/lib/cmd-update.sh +191 -0
  35. package/skills/teamsmith/scripts/lib/cmd-watch.sh +1681 -0
  36. package/skills/teamsmith/scripts/lib/common.sh +4964 -0
  37. package/skills/teamsmith/scripts/lib/draft-entry.sh +51 -0
  38. package/skills/teamsmith/scripts/lib/outbox.sh +2042 -0
  39. package/skills/teamsmith/scripts/lib/tmux-argv.sh +165 -0
  40. package/skills/teamsmith/scripts/monitor.mjs +616 -0
  41. package/skills/teamsmith/scripts/panel/README.md +192 -0
  42. package/skills/teamsmith/scripts/panel/build.sh +47 -0
  43. package/skills/teamsmith/scripts/panel/bun.lock +109 -0
  44. package/skills/teamsmith/scripts/panel/draft-send.sh +68 -0
  45. package/skills/teamsmith/scripts/panel/package.json +24 -0
  46. package/skills/teamsmith/scripts/panel/panel.js +388 -0
  47. package/skills/teamsmith/scripts/panel/src/App.tsx +2150 -0
  48. package/skills/teamsmith/scripts/panel/src/clipboard.ts +154 -0
  49. package/skills/teamsmith/scripts/panel/src/compose.ts +691 -0
  50. package/skills/teamsmith/scripts/panel/src/data.ts +555 -0
  51. package/skills/teamsmith/scripts/panel/src/format.ts +50 -0
  52. package/skills/teamsmith/scripts/panel/src/layout.ts +2562 -0
  53. package/skills/teamsmith/scripts/panel/src/main.tsx +894 -0
  54. package/skills/teamsmith/scripts/panel/src/markdown.ts +340 -0
  55. package/skills/teamsmith/scripts/panel/src/sanitize.ts +42 -0
  56. package/skills/teamsmith/scripts/panel/src/settings.ts +154 -0
  57. package/skills/teamsmith/scripts/panel/src/strings/en.ts +416 -0
  58. package/skills/teamsmith/scripts/panel/src/strings/index.ts +65 -0
  59. package/skills/teamsmith/scripts/panel/src/strings/types.ts +9 -0
  60. package/skills/teamsmith/scripts/panel/src/strings/zh.ts +414 -0
  61. package/skills/teamsmith/scripts/panel/src/theme.ts +116 -0
  62. package/skills/teamsmith/scripts/panel/src/types.ts +652 -0
  63. package/skills/teamsmith/scripts/panel/src/width.ts +105 -0
  64. package/skills/teamsmith/scripts/panel/tsconfig.json +16 -0
  65. package/skills/teamsmith/scripts/shim/signal-gate +156 -0
  66. package/skills/teamsmith/scripts/shim/tmux +403 -0
  67. package/skills/teamsmith/scripts/team +143 -0
  68. package/skills/teamsmith/templates/AGENTS.section.md.tmpl +147 -0
  69. package/skills/teamsmith/templates/BOARD.md.tmpl +18 -0
  70. package/skills/teamsmith/templates/DECISIONS.md.tmpl +22 -0
  71. package/skills/teamsmith/templates/OWNERSHIP.md.tmpl +25 -0
  72. package/skills/teamsmith/templates/PROTOCOL.md.tmpl +84 -0
  73. package/skills/teamsmith/templates/ROADMAP.md.tmpl +29 -0
  74. package/skills/teamsmith/templates/config.sh.tmpl +106 -0
  75. package/skills/teamsmith/templates/memory-seed.md.tmpl +46 -0
  76. package/skills/teamsmith/templates/pm-prompt.md.tmpl +110 -0
  77. package/skills/teamsmith/templates/report.md.tmpl +36 -0
  78. package/skills/teamsmith/templates/task.md.tmpl +65 -0
  79. package/skills/teamsmith/templates/threads-README.md +17 -0
  80. package/skills/teamsmith/tests/bg-ledger-harness.mjs +682 -0
  81. package/skills/teamsmith/tests/bg-ledger.sh +307 -0
  82. package/skills/teamsmith/tests/checkout-shape-probe.sh +800 -0
  83. package/skills/teamsmith/tests/config-cli.sh +1562 -0
  84. package/skills/teamsmith/tests/container-tmux.sh +493 -0
  85. package/skills/teamsmith/tests/coverage-inventory.sh +173 -0
  86. package/skills/teamsmith/tests/death-cause.sh +564 -0
  87. package/skills/teamsmith/tests/delivery-truth.sh +1231 -0
  88. package/skills/teamsmith/tests/fake-tui.py +450 -0
  89. package/skills/teamsmith/tests/fixtures/delivery-truth-real/README.md +60 -0
  90. package/skills/teamsmith/tests/fixtures/delivery-truth-real/judge-second.py +139 -0
  91. package/skills/teamsmith/tests/fixtures/delivery-truth-real/mock-server.py +29 -0
  92. package/skills/teamsmith/tests/fixtures/delivery-truth-real/observe.ts +20 -0
  93. package/skills/teamsmith/tests/fixtures/delivery-truth-real/run-case.sh +79 -0
  94. package/skills/teamsmith/tests/fixtures/delivery-truth-real/scenario.sh +175 -0
  95. package/skills/teamsmith/tests/fixtures/p55/flip-p49.sh +229 -0
  96. package/skills/teamsmith/tests/fixtures/p71-incident/README.md +22 -0
  97. package/skills/teamsmith/tests/fixtures/p71-incident/dev2.seen +8 -0
  98. package/skills/teamsmith/tests/fixtures/p71-incident/dev2.wake +9 -0
  99. package/skills/teamsmith/tests/fixtures/p71-incident/pm-nudges.wake +3 -0
  100. package/skills/teamsmith/tests/fixtures/signal-lint-cases.txt +40 -0
  101. package/skills/teamsmith/tests/flip-glue.sh +162 -0
  102. package/skills/teamsmith/tests/flip-m12-26c.sh +129 -0
  103. package/skills/teamsmith/tests/flip-m12.sh +185 -0
  104. package/skills/teamsmith/tests/flip-m16.sh +166 -0
  105. package/skills/teamsmith/tests/flip-m17.sh +204 -0
  106. package/skills/teamsmith/tests/flip-m33.sh +284 -0
  107. package/skills/teamsmith/tests/flip-m34.sh +96 -0
  108. package/skills/teamsmith/tests/flip-m37.sh +185 -0
  109. package/skills/teamsmith/tests/flip-m4.3.sh +375 -0
  110. package/skills/teamsmith/tests/flip-m43.sh +128 -0
  111. package/skills/teamsmith/tests/flip-m44.sh +262 -0
  112. package/skills/teamsmith/tests/flip-m45.sh +244 -0
  113. package/skills/teamsmith/tests/flip-m46.sh +238 -0
  114. package/skills/teamsmith/tests/flip-m48.sh +304 -0
  115. package/skills/teamsmith/tests/flip-m6.2.sh +205 -0
  116. package/skills/teamsmith/tests/flip-m6.3.sh +283 -0
  117. package/skills/teamsmith/tests/flip-m6.4.sh +267 -0
  118. package/skills/teamsmith/tests/flip-m6.5.sh +113 -0
  119. package/skills/teamsmith/tests/flip-m7.1.sh +135 -0
  120. package/skills/teamsmith/tests/flip-m7.2.sh +321 -0
  121. package/skills/teamsmith/tests/flip-p144.sh +112 -0
  122. package/skills/teamsmith/tests/flip-p156.sh +133 -0
  123. package/skills/teamsmith/tests/flip-p158.sh +301 -0
  124. package/skills/teamsmith/tests/flip-p160.sh +182 -0
  125. package/skills/teamsmith/tests/flip-p171.sh +249 -0
  126. package/skills/teamsmith/tests/flip-p18.1.sh +95 -0
  127. package/skills/teamsmith/tests/flip-p20.sh +286 -0
  128. package/skills/teamsmith/tests/flip-p201.sh +249 -0
  129. package/skills/teamsmith/tests/flip-p210.sh +239 -0
  130. package/skills/teamsmith/tests/flip-p211.sh +152 -0
  131. package/skills/teamsmith/tests/flip-p217.sh +288 -0
  132. package/skills/teamsmith/tests/flip-p22.sh +123 -0
  133. package/skills/teamsmith/tests/flip-p23.sh +239 -0
  134. package/skills/teamsmith/tests/flip-p25.sh +165 -0
  135. package/skills/teamsmith/tests/flip-p71.sh +184 -0
  136. package/skills/teamsmith/tests/flip-p72.sh +202 -0
  137. package/skills/teamsmith/tests/frames/README.md +176 -0
  138. package/skills/teamsmith/tests/frames/p78-conversation-rule-below-box.txt +6 -0
  139. package/skills/teamsmith/tests/frames/p78-cursor-mid-draft.txt +6 -0
  140. package/skills/teamsmith/tests/frames/p78-draft-rule-below-cursor-line.txt +6 -0
  141. package/skills/teamsmith/tests/frames/p78-draft-rule-below-cursor.txt +6 -0
  142. package/skills/teamsmith/tests/frames/p78-draft-rule-blank-region.txt +6 -0
  143. package/skills/teamsmith/tests/frames/p78-draft-rule-only.txt +5 -0
  144. package/skills/teamsmith/tests/frames/p78-spinner-row-below-cursor.txt +6 -0
  145. package/skills/teamsmith/tests/frames/p78-wider-rule-below-cursor.txt +6 -0
  146. package/skills/teamsmith/tests/frames/p86-f1-mixed-width-disjoint-box.txt +8 -0
  147. package/skills/teamsmith/tests/frames/p86-f1-narrower-width-disjoint-box.txt +8 -0
  148. package/skills/teamsmith/tests/frames/p86-f1-spinner-top-disjoint-box.txt +8 -0
  149. package/skills/teamsmith/tests/frames/pi-0.85.1-update-banner.txt +30 -0
  150. package/skills/teamsmith/tests/frames/pi-0.87.0-draft-half-sentence.txt +30 -0
  151. package/skills/teamsmith/tests/frames/pi-0.87.0-empty-box.txt +30 -0
  152. package/skills/teamsmith/tests/frames/pi-0.87.0-one-line-draft.txt +30 -0
  153. package/skills/teamsmith/tests/frames/pi-0.87.0-project-trust-prompt.txt +30 -0
  154. package/skills/teamsmith/tests/frames/pi-0.99.2-empty-editor.txt +32 -0
  155. package/skills/teamsmith/tests/frames/pi-0.99.2-human-draft.txt +32 -0
  156. package/skills/teamsmith/tests/frames/pi-1.0.0-git-error-in-box.txt +32 -0
  157. package/skills/teamsmith/tests/gate-guard.sh +112 -0
  158. package/skills/teamsmith/tests/guard-matrix.sh +233 -0
  159. package/skills/teamsmith/tests/install-shape.sh +731 -0
  160. package/skills/teamsmith/tests/ledger-ban.sh +612 -0
  161. package/skills/teamsmith/tests/lib/box-judge.sh +68 -0
  162. package/skills/teamsmith/tests/lib/checkout-shape.sh +129 -0
  163. package/skills/teamsmith/tests/lib/loop-scan.awk +114 -0
  164. package/skills/teamsmith/tests/lib/pty-wait.sh +676 -0
  165. package/skills/teamsmith/tests/lib/section-guard.sh +855 -0
  166. package/skills/teamsmith/tests/lib/shell-lex.pl +261 -0
  167. package/skills/teamsmith/tests/lib/tmp-root.sh +528 -0
  168. package/skills/teamsmith/tests/lib/tmux-cap.sh +35 -0
  169. package/skills/teamsmith/tests/lib/tmux-iso-call-probe.sh +81 -0
  170. package/skills/teamsmith/tests/lib/tmux-iso-probe.sh +46 -0
  171. package/skills/teamsmith/tests/lib/tmux-iso.sh +381 -0
  172. package/skills/teamsmith/tests/load-experiment.sh +290 -0
  173. package/skills/teamsmith/tests/loop-inventory.tsv +84 -0
  174. package/skills/teamsmith/tests/panel-b2-slow-stub.sh +19 -0
  175. package/skills/teamsmith/tests/panel-b2.sh +1183 -0
  176. package/skills/teamsmith/tests/panel-b3-pty-mouse.py +240 -0
  177. package/skills/teamsmith/tests/panel-b3-pty-tmux-mouse.py +138 -0
  178. package/skills/teamsmith/tests/panel-b3-stub.sh +279 -0
  179. package/skills/teamsmith/tests/panel-b3.sh +1301 -0
  180. package/skills/teamsmith/tests/panel-choices.sh +572 -0
  181. package/skills/teamsmith/tests/panel-clipboard-model.ts +187 -0
  182. package/skills/teamsmith/tests/panel-compose-model.ts +290 -0
  183. package/skills/teamsmith/tests/panel-contrast.mjs +81 -0
  184. package/skills/teamsmith/tests/panel-cpu-premise.sh +173 -0
  185. package/skills/teamsmith/tests/panel-cpu.sh +391 -0
  186. package/skills/teamsmith/tests/panel-flip-m54.sh +207 -0
  187. package/skills/teamsmith/tests/panel-flip-p123.sh +278 -0
  188. package/skills/teamsmith/tests/panel-flip-p125.sh +318 -0
  189. package/skills/teamsmith/tests/panel-flip-p128.sh +259 -0
  190. package/skills/teamsmith/tests/panel-keyprobe-pty.py +99 -0
  191. package/skills/teamsmith/tests/panel-keyprobe-stub.sh +41 -0
  192. package/skills/teamsmith/tests/panel-keyprobe.sh +82 -0
  193. package/skills/teamsmith/tests/panel-keyprobe.tsx +116 -0
  194. package/skills/teamsmith/tests/panel-knobs.sh +83 -0
  195. package/skills/teamsmith/tests/panel-p21.sh +2181 -0
  196. package/skills/teamsmith/tests/panel-snapshots.sh +802 -0
  197. package/skills/teamsmith/tests/panel-strings.mjs +195 -0
  198. package/skills/teamsmith/tests/perf.sh +740 -0
  199. package/skills/teamsmith/tests/pm-box-real.sh +350 -0
  200. package/skills/teamsmith/tests/pulse-nudge-key.sh +563 -0
  201. package/skills/teamsmith/tests/routes.sh +1652 -0
  202. package/skills/teamsmith/tests/section-budgets.tsv +150 -0
  203. package/skills/teamsmith/tests/section-guard.sh +231 -0
  204. package/skills/teamsmith/tests/section-needs-audit.sh +94 -0
  205. package/skills/teamsmith/tests/section-paths.tsv +142 -0
  206. package/skills/teamsmith/tests/section-select.sh +655 -0
  207. package/skills/teamsmith/tests/signal-gate.sh +366 -0
  208. package/skills/teamsmith/tests/signal-lint-legacy.txt +14 -0
  209. package/skills/teamsmith/tests/signal-lint.pl +416 -0
  210. package/skills/teamsmith/tests/skill-load.mjs +65 -0
  211. package/skills/teamsmith/tests/smoke.sh +19711 -0
  212. package/skills/teamsmith/tests/snapshots/zh-dark-120-detail.txt +32 -0
  213. package/skills/teamsmith/tests/snapshots/zh-dark-120-p4.txt +32 -0
  214. package/skills/teamsmith/tests/snapshots/zh-dark-120.txt +32 -0
  215. package/skills/teamsmith/tests/snapshots/zh-dark-160-p4.txt +32 -0
  216. package/skills/teamsmith/tests/snapshots/zh-dark-160.txt +32 -0
  217. package/skills/teamsmith/tests/snapshots/zh-dark-59-detail.txt +32 -0
  218. package/skills/teamsmith/tests/snapshots/zh-dark-59-p4.txt +32 -0
  219. package/skills/teamsmith/tests/snapshots/zh-dark-59.txt +32 -0
  220. package/skills/teamsmith/tests/snapshots/zh-dark-99-p4.txt +32 -0
  221. package/skills/teamsmith/tests/snapshots/zh-dark-99.txt +32 -0
  222. package/skills/teamsmith/tests/snapshots/zh-light-120-detail.txt +32 -0
  223. package/skills/teamsmith/tests/snapshots/zh-light-120-p4.txt +32 -0
  224. package/skills/teamsmith/tests/snapshots/zh-light-120.txt +32 -0
  225. package/skills/teamsmith/tests/snapshots/zh-light-160-p4.txt +32 -0
  226. package/skills/teamsmith/tests/snapshots/zh-light-160.txt +32 -0
  227. package/skills/teamsmith/tests/snapshots/zh-light-59-detail.txt +32 -0
  228. package/skills/teamsmith/tests/snapshots/zh-light-59-p4.txt +32 -0
  229. package/skills/teamsmith/tests/snapshots/zh-light-59.txt +32 -0
  230. package/skills/teamsmith/tests/snapshots/zh-light-99-p4.txt +32 -0
  231. package/skills/teamsmith/tests/snapshots/zh-light-99.txt +32 -0
  232. package/skills/teamsmith/tests/spec-ledger-refs.tsv +78 -0
  233. package/skills/teamsmith/tests/spec-refs.sh +826 -0
  234. package/skills/teamsmith/tests/task-header-model.sh +267 -0
  235. package/skills/teamsmith/tests/team-bg-flip.sh +239 -0
  236. package/skills/teamsmith/tests/team-bg-harness.mjs +392 -0
  237. package/skills/teamsmith/tests/team-bg-stop.sh +434 -0
  238. package/skills/teamsmith/tests/team-inbox-watch-flip.sh +191 -0
  239. package/skills/teamsmith/tests/team-inbox-watch-harness.mjs +1559 -0
  240. package/skills/teamsmith/tests/tmp-hygiene.sh +1190 -0
  241. package/skills/teamsmith/tests/tmux-lint-legacy.txt +31 -0
  242. package/skills/teamsmith/tests/tmux-lint.pl +604 -0
  243. package/skills/teamsmith-init/SKILL.md +100 -0
  244. package/skills/teamsmith-init/references/bootstrap.md +74 -0
  245. package/skills/teamsmith-init/templates/bootstrap-prompt.md.tmpl +46 -0
@@ -0,0 +1,572 @@
1
+ #!/usr/bin/env bash
2
+ # panel-choices.sh — headless fixtures for M55 `settings-choice-editors` (memory-and-deps delta):
3
+ #
4
+ # R1 `team config list --json` reports each key's choice set, derived from the schema row
5
+ # R2 the model vocabulary is this project's data (the pm seat included), never the machine's
6
+ # Pi model catalogue
7
+ # the gate: every value the read offers is a value the writer's validator accepts
8
+ #
9
+ # bash skills/teamsmith/tests/panel-choices.sh # every section
10
+ # bash skills/teamsmith/tests/panel-choices.sh read known walk # selected sections
11
+ # TEAM_CHOICES_TREE=<tree> bash ... # run against another checkout (flip)
12
+ # TEAM_CHOICES_KEEP=1 bash ... # keep the fixture directory
13
+ #
14
+ # Sections: read known walk read-equality catalogue flip-drop-pm flip-suggest
15
+ # Exit: 0 every selected section green / 1 at least one assertion failed / 3 setup failure.
16
+ #
17
+ # Nothing here touches the caller's project: every fixture is a fresh git repo under $TMPDIR, the
18
+ # caller's TEAM_*/TMUX identity is stripped first, and every `team` call runs from inside a fixture.
19
+ set -uo pipefail
20
+
21
+ # ── 身份隔离(必须最先做):绝不继承调用者的团队身份 ──────────────────────────────
22
+ # (自己声明的树参数先存下来:下面的清理会把 TEAM_* 全清掉)
23
+ _tree_arg="${TEAM_CHOICES_TREE:-}"
24
+ _keep_arg="${TEAM_CHOICES_KEEP:-0}"
25
+ while IFS='=' read -r _v _; do
26
+ case "$_v" in TEAM_*) unset "$_v" 2>/dev/null || true ;; esac
27
+ done < <(env)
28
+ unset _v 2>/dev/null || true
29
+ unset TMUX TMUX_PANE 2>/dev/null || true
30
+
31
+ here="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
32
+ # P53:临时根的唯一创建者(${TMPDIR:-/tmp} + owned 家族 + 回收)
33
+ . "$here/lib/tmp-root.sh"
34
+ tree="${_tree_arg:-$(cd -P "$here/../../.." && pwd)}"
35
+ skill="$tree/skills/teamsmith"
36
+ team="$skill/scripts/team"
37
+ cmd_config="$skill/scripts/lib/cmd-config.sh"
38
+
39
+ keep="${_keep_arg:-0}"
40
+ [ "$keep" = "1" ] && export TEAM_TMP_KEEP=1
41
+ tmp="$(tmp_root_create panel-choice)" || exit 3
42
+ PASS=0
43
+ FAIL=0
44
+
45
+ cleanup() {
46
+ [ "${BASHPID:-$$}" = "$$" ] || return 0
47
+ if [ "$keep" = "1" ]; then printf '\n保留夹具目录:%s\n' "$tmp"
48
+ else tmp_root_reap_all; fi
49
+ }
50
+ trap cleanup EXIT
51
+
52
+ section() { printf '\n\033[1m== %s ==\033[0m\n' "$1"; }
53
+ ok() { printf ' \033[32m✓\033[0m %s\n' "$1"; PASS=$((PASS + 1)); }
54
+ bad() { printf ' \033[31m✗\033[0m %s\n' "$1"; FAIL=$((FAIL + 1)); }
55
+ assert_eq() { [ "$2" = "$3" ] && ok "$1" || bad "$1(期望 [$3],实际 [$2])"; }
56
+
57
+ run_in() { local d="$1"; shift; ( cd "$d" && bash "$team" "$@" 2>&1 ); }
58
+
59
+ # new_proj <name> [agents] → 打印 fixture 项目目录(已 init)
60
+ new_proj() {
61
+ local name="$1" agents="${2:-dev verify}" p
62
+ p="$tmp/$name"
63
+ mkdir -p "$p"
64
+ ( cd "$p" && git init -q -b main && git config user.email pc@teamsmith && git config user.name pc \
65
+ && printf '{"name":"%s","scripts":{"verify":"true"}}\n' "$name" > package.json \
66
+ && git add -A && git commit -qm init ) >/dev/null 2>&1
67
+ if ! ( cd "$p" && bash "$team" init --session "pc-$name" --agents "$agents" --vcs local \
68
+ --gates "true" --docs docs/team ) >"$tmp/$name-init.log" 2>&1; then
69
+ printf 'panel-choices: 夹具 %s 的 team init 失败\n' "$name" >&2
70
+ tail -5 "$tmp/$name-init.log" >&2
71
+ return 1
72
+ fi
73
+ printf '%s\n' "$p"
74
+ }
75
+
76
+ sha_of() { sha256sum "$1" 2>/dev/null | awk '{print $1}'; }
77
+
78
+ # json_check <json> <label> <python expression over d>
79
+ json_check() {
80
+ local json="$1" label="$2" expr="$3"
81
+ if printf '%s' "$json" | python3 -c '
82
+ import json, sys
83
+ try:
84
+ d = json.load(sys.stdin)
85
+ except Exception as e:
86
+ print("parse-error: %s" % e); sys.exit(0)
87
+ ok = False
88
+ try:
89
+ ok = bool(eval(sys.argv[1], {"d": d}))
90
+ except Exception as e:
91
+ print("eval-error: %s" % e); sys.exit(0)
92
+ print("ok" if ok else "no")
93
+ ' "$expr" | grep -q '^ok$'; then
94
+ ok "$label"
95
+ else
96
+ bad "$label(表达式:$expr)"
97
+ fi
98
+ }
99
+
100
+ [ -f "$team" ] || { printf 'panel-choices: 没有 CLI:%s\n' "$team" >&2; exit 3; }
101
+ [ -f "$cmd_config" ] || { printf 'panel-choices: 没有 schema:%s\n' "$cmd_config" >&2; exit 3; }
102
+ command -v python3 >/dev/null 2>&1 || { printf 'panel-choices: 需要 python3(JSON 断言)\n' >&2; exit 3; }
103
+
104
+ SECTIONS=("$@")
105
+ [ "${#SECTIONS[@]}" -gt 0 ] || SECTIONS=(read known walk read-equality catalogue flip-drop-pm flip-suggest)
106
+ want() { local s; for s in "${SECTIONS[@]}"; do [ "$s" = "$1" ] && return 0; done; return 1; }
107
+
108
+ # ---------------------------------------------------------------- read
109
+ if want read; then
110
+ section "read · choices 逐 kind(R1:读给出的域 = schema 的行,不是第二张选项表)"
111
+ p="$(new_proj read)" || exit 3
112
+ cfg="$p/.pi/team/config.sh"
113
+ # 文件里手加一个 schema 不认识的键:它也要有记录,但 source=none。
114
+ printf '\nTEAM_HAND_ADDED="hand"\n' >> "$cfg"
115
+ json="$(run_in "$p" config list --json)"
116
+ json_check "$json" "TEAM_BRANCH_MODE(enum,refuse)→ constraints task,agent 原序" \
117
+ '[k for k in d["keys"] if k["name"]=="TEAM_BRANCH_MODE"][0]["choices"]=={"source":"schema","values":["task","agent"],"min":"","max":"","empty":False,"note":""}'
118
+ json_check "$json" "TEAM_MONITOR_UI(enum)→ auto,tui,text 原序" \
119
+ '[k for k in d["keys"] if k["name"]=="TEAM_MONITOR_UI"][0]["choices"]["values"]==["auto","tui","text"]'
120
+ json_check "$json" "TEAM_NOTIFY_TMUX(bool)→ 两个规范值 1,0" \
121
+ '[k for k in d["keys"] if k["name"]=="TEAM_NOTIFY_TMUX"][0]["choices"]=={"source":"schema","values":["1","0"],"min":"","max":"","empty":False,"note":""}'
122
+ json_check "$json" "TEAM_PULSE_INTERVAL(seconds)→ min 60 / max '' / empty false / 建议列原序" \
123
+ '[k for k in d["keys"] if k["name"]=="TEAM_PULSE_INTERVAL"][0]["choices"]=={"source":"schema","values":["300","900","1800","3600"],"min":"60","max":"","empty":False,"note":""}'
124
+ json_check "$json" "TEAM_ZRAM_WARN_PCT(pct)→ min 0 / max 100(有上界)" \
125
+ '[k for k in d["keys"] if k["name"]=="TEAM_ZRAM_WARN_PCT"][0]["choices"]["min"]=="0" and [k for k in d["keys"] if k["name"]=="TEAM_ZRAM_WARN_PCT"][0]["choices"]["max"]=="100"'
126
+ json_check "$json" "TEAM_AGENT_BIN(path exec,opt)→ empty true + note 带存在性规则 exec" \
127
+ '[k for k in d["keys"] if k["name"]=="TEAM_AGENT_BIN"][0]["choices"]=={"source":"none","values":[],"min":"","max":"","empty":True,"note":"exec"}'
128
+ json_check "$json" "TEAM_PI_BIN(path exec,必填)→ empty false" \
129
+ '[k for k in d["keys"] if k["name"]=="TEAM_PI_BIN"][0]["choices"]["empty"] is False'
130
+ json_check "$json" "TEAM_GATES(cmd)→ source none、values 空(「打开自由输入并写明原因」的那类)" \
131
+ '[k for k in d["keys"] if k["name"]=="TEAM_GATES"][0]["choices"]=={"source":"none","values":[],"min":"","max":"","empty":True,"note":""}'
132
+ json_check "$json" "TEAM_DEFAULT_MODEL(model)→ source known,值 = models.known" \
133
+ '[k for k in d["keys"] if k["name"]=="TEAM_DEFAULT_MODEL"][0]["choices"]["source"]=="known" and [k for k in d["keys"] if k["name"]=="TEAM_DEFAULT_MODEL"][0]["choices"]["values"]==d["models"]["known"]'
134
+ json_check "$json" "schema 不认识的键也有 choices(source none、known false)" \
135
+ '[k for k in d["keys"] if k["name"]=="TEAM_HAND_ADDED"][0]["known"] is False and [k for k in d["keys"] if k["name"]=="TEAM_HAND_ADDED"][0]["choices"]["source"]=="none"'
136
+ json_check "$json" "每个记录都带 choices,且旧字段一个不少(只增不改;未知键本来就没有 route)" \
137
+ 'all(set(["name","class","kind","form","value","default","set","comment","warning","known","choices"]) <= set(k) for k in d["keys"])'
138
+ json_check "$json" "非数值类的 min/max 恒为空(数值类的走查比对 constraints)" \
139
+ 'all((k["choices"]["min"]=="" and k["choices"]["max"]=="") for k in d["keys"] if k["kind"] not in ("int","seconds","mb","bytes","pct"))'
140
+ json_check "$json" "path 行的 note 是存在性规则 file|dir|exec|any" \
141
+ 'all(k["choices"]["note"] in ("file","dir","exec","any") for k in d["keys"] if k["kind"]=="path")'
142
+ # 人读表与其它机读出口不动:表头还是 KEY CLASS KIND VALUE,也不出现 choices 字样。
143
+ human="$(run_in "$p" config list)"
144
+ case "$human" in
145
+ *"KEY"*"CLASS"*"KIND"*"VALUE"*) ok "人读表表头 KEY CLASS KIND VALUE 未变" ;;
146
+ *) bad "人读表表头变了($(printf '%s' "$human" | sed -n '5p'))" ;;
147
+ esac
148
+ case "$human" in *choices*) bad "人读表多了 choices 字样" ;; *) ok "人读表没有 choices 列(加法不碰人读面)" ;; esac
149
+ mon="$(run_in "$p" monitor --json)"
150
+ case "$mon" in *'"choices"'*) bad "team monitor --json 长出了 choices 字段(机读出口必须逐字节不动)" ;;
151
+ *) ok "team monitor --json 不带 choices(机读出口没动)" ;; esac
152
+ fi
153
+
154
+ # ---------------------------------------------------------------- known
155
+ if want known; then
156
+ section "known · 模型词汇表是本项目的数据(R2:含 pm 席位,记录与解析都在,绝不读机器目录)"
157
+ p="$(new_proj known)" || exit 3
158
+ cfg="$p/.pi/team/config.sh"
159
+ state="$p/.pi/team/state"
160
+ python3 - "$cfg" <<'PY'
161
+ import re, sys
162
+ p = sys.argv[1]
163
+ s = open(p, encoding='utf-8').read()
164
+ s = s.replace('TEAM_AGENT_MODELS=""', 'TEAM_AGENT_MODELS="dev=deepseek/deepseek-flash verify=openrouter/stealth/union-alpha"')
165
+ s = re.sub(r'^TEAM_PM_MODEL=.*$', 'TEAM_PM_MODEL="kimi-coding/k3-256k"', s, count=1, flags=re.M)
166
+ open(p, 'w', encoding='utf-8').write(s)
167
+ PY
168
+ mkdir -p "$state"
169
+ printf 'model=openai-codex/gpt-5.6-terra:xhigh\n' > "$state/dev.env"
170
+ json="$(run_in "$p" config list --json)"
171
+ json_check "$json" "known = 配置 default + 席位记录 + pm 的 TEAM_PM_MODEL(各一次)" \
172
+ 'sorted(d["models"]["known"])==["deepseek/deepseek-flash","kimi-coding/k3-256k","openai-codex/gpt-5.6-terra:xhigh","openrouter/stealth/union-alpha"]'
173
+ json_check "$json" "三段 id 逐字进 known 与 model/pairlist 的 choices.values" \
174
+ '"openrouter/stealth/union-alpha" in d["models"]["known"] and "openrouter/stealth/union-alpha" in [k for k in d["keys"] if k["name"]=="TEAM_DEFAULT_MODEL"][0]["choices"]["values"] and "openrouter/stealth/union-alpha" in [k for k in d["keys"] if k["name"]=="TEAM_AGENT_MODELS"][0]["choices"]["values"]'
175
+ json_check "$json" "三段 id 的席位行也逐字(verify 行)" \
176
+ '[s for s in d["models"]["seats"] if s["agent"]=="verify"][0]["model"]=="openrouter/stealth/union-alpha"'
177
+ out="$(run_in "$p" config set-agent-model verify openrouter/stealth/union-alpha --dry-run)"; rc=$?
178
+ assert_eq "三段 id 被写路径校验器接受(set-agent-model --dry-run → 0)" "$rc" "0"
179
+ json_check "$json" "pm 的模型恰好出现一次(去重)" 'd["models"]["known"].count("kimi-coding/k3-256k")==1'
180
+ json_check "$json" "models.seats 的 pm 行 = TEAM_PM_MODEL 且 override=true" \
181
+ '[s for s in d["models"]["seats"] if s["agent"]=="pm"][0]["model"]=="kimi-coding/k3-256k" and [s for s in d["models"]["seats"] if s["agent"]=="pm"][0]["override"] is True'
182
+ json_check "$json" "TEAM_PM_MODEL 的 choices.values 含 pm 的模型" \
183
+ '"kimi-coding/k3-256k" in [k for k in d["keys"] if k["name"]=="TEAM_PM_MODEL"][0]["choices"]["values"]'
184
+ # 去掉 TEAM_PM_MODEL:pm 回退默认,席位记录仍在 known,每个模型仍只出现一次。
185
+ python3 - "$cfg" <<'PY'
186
+ import re, sys
187
+ p = sys.argv[1]
188
+ s = open(p, encoding='utf-8').read()
189
+ s = re.sub(r'^TEAM_PM_MODEL=.*$', 'TEAM_PM_MODEL=""', s, count=1, flags=re.M)
190
+ open(p, 'w', encoding='utf-8').write(s)
191
+ PY
192
+ json="$(run_in "$p" config list --json)"
193
+ json_check "$json" "去掉 TEAM_PM_MODEL 后 pm 回退默认,记录席位的模型仍在 known 且各一次" \
194
+ '[s for s in d["models"]["seats"] if s["agent"]=="pm"][0]["model"]=="deepseek/deepseek-flash" and sorted(d["models"]["known"])==["deepseek/deepseek-flash","openai-codex/gpt-5.6-terra:xhigh","openrouter/stealth/union-alpha"] and d["models"]["known"].count("openai-codex/gpt-5.6-terra:xhigh")==1'
195
+ fi
196
+
197
+ # ---------------------------------------------------------------- walk(门禁)
198
+ # 读给出的值与写入校验是同一个域:choices.values / suggest 列的每个值都要能被
199
+ # `team config set <KEY> <value> --dry-run` 接受(0 = 合法,7 = 合法但危险,--allow-danger 才写);
200
+ # choices.empty 要与校验器对 '' 的判定一致。token 类(pairlist/winlist/pattern)的 values 是**词表**,
201
+ # 按视图自己的组合规则(seat=model / model=1)走查 —— 裸 token 被拒正是它带 N 的一端。
202
+ walk_section() { # <tree> <label>
203
+ local wt="$1" label="$2"
204
+ local wp json out rc
205
+ wp="$(new_proj "walk-$label")" || exit 3
206
+ # model-id-shape R1:走查的 known 里必须带一个三段 id —— 它进 model/pairlist 的 choices.values,
207
+ # 走查作业逐条拿它去 `team config set … --dry-run`(旧校验器会在这里红,这是闸门要抓回归的方向)。
208
+ run_in "$wp" config set TEAM_DEFAULT_MODEL openrouter/amazon/nova-lite-v1 --yes >/dev/null || exit 3
209
+ json="$(run_in "$wp" config list --json)"
210
+ printf '%s' "$json" > "$tmp/walk-list.json"
211
+ local sha_before; sha_before="$(sha_of "$wp/.pi/team/config.sh")"
212
+ python3 - "$wt" "$tmp" > "$tmp/walk-static.log" 2>&1 <<'PY'
213
+ import json, re, sys
214
+ tree, tmp = sys.argv[1], sys.argv[2]
215
+ schema = open(tree + "/skills/teamsmith/scripts/lib/cmd-config.sh", encoding="utf-8").read()
216
+ m = re.search(r"team_config_schema\(\) \{\n cat <<'EOF'\n(.*?)\nEOF\n\}", schema, re.S)
217
+ if not m:
218
+ sys.exit("panel-choices: 读不出 schema")
219
+ rows = {}
220
+ for line in m.group(1).splitlines():
221
+ if not line or line.startswith('#'):
222
+ continue
223
+ f = line.split('|')
224
+ rows[f[0]] = f
225
+ d = json.load(open(tmp + "/walk-list.json", encoding="utf-8"))
226
+ seats = [s["agent"] for s in d["models"]["seats"]]
227
+ jobs, empties, problems = [], [], []
228
+ seen_keys = 0
229
+ for k in d["keys"]:
230
+ name, ch = k["name"], k["choices"]
231
+ f = rows.get(name)
232
+ if not f:
233
+ if ch["values"] or ch["source"] != "none" or ch["empty"]:
234
+ problems.append("未知键 %s 的 choices 不是 none/空:%s" % (name, json.dumps(ch)))
235
+ continue
236
+ seen_keys += 1
237
+ cls, kind, spec = f[1], f[2], (f[3] if len(f) > 3 else "")
238
+ suggest = f[8] if len(f) > 8 else ""
239
+ if kind in ("int", "seconds", "mb", "bytes", "pct"):
240
+ lo, _, hi = spec.partition(",")
241
+ if ch["min"] != lo or ch["max"] != hi:
242
+ problems.append("%s 的 min/max (%r,%r) ≠ constraints (%r,%r)" % (name, ch["min"], ch["max"], lo, hi))
243
+ want = [v for v in suggest.split(",") if v]
244
+ if ch["values"] != want:
245
+ problems.append("%s 的 values ≠ 建议列 %s" % (name, json.dumps(want)))
246
+ for v in want:
247
+ if not v.isdigit():
248
+ problems.append("%s 的建议值 %s 不是非负整数" % (name, v))
249
+ continue
250
+ if lo and int(v) < int(lo):
251
+ problems.append("%s 的建议值 %s 低于最小值 %s" % (name, v, lo))
252
+ if hi and int(v) > int(hi):
253
+ problems.append("%s 的建议值 %s 超过最大值 %s" % (name, v, hi))
254
+ elif kind == "enum":
255
+ want = [v for v in spec.split(",") if v]
256
+ if ch["values"] != want:
257
+ problems.append("%s 的 values ≠ constraints %s" % (name, json.dumps(want)))
258
+ elif kind == "bool":
259
+ if ch["values"] != ["1", "0"]:
260
+ problems.append("%s 的 values ≠ [1,0]" % name)
261
+ elif kind in ("model", "pairlist", "winlist", "pattern"):
262
+ if ch["values"] != d["models"]["known"]:
263
+ problems.append("%s 的 values ≠ models.known" % name)
264
+ if cls == "refuse":
265
+ # 只读行没有写路径:不走查(走查只针对可写键),静态形状仍照查。
266
+ continue
267
+ empties.append("%s\t%s" % (name, "true" if ch["empty"] else "false"))
268
+ for v in ch["values"]:
269
+ if kind == "pairlist":
270
+ if not seats:
271
+ problems.append("%s 的 pairlist 词表没有席位可用(夹具缺少名册)" % name)
272
+ continue
273
+ whole = "%s=%s" % (seats[0], v)
274
+ elif kind in ("winlist", "pattern"):
275
+ whole = "%s=1" % v
276
+ else:
277
+ whole = v
278
+ jobs.append("%s\t%s\t%s" % (name, whole, v))
279
+ with open(tmp + "/walk-jobs.tsv", "w", encoding="utf-8") as fh:
280
+ fh.write("\n".join(jobs) + ("\n" if jobs else ""))
281
+ with open(tmp + "/walk-empty.tsv", "w", encoding="utf-8") as fh:
282
+ fh.write("\n".join(empties) + ("\n" if empties else ""))
283
+ for p in problems:
284
+ print("PROBLEM\t" + p)
285
+ print("COUNTS\t%d\t%d\t%d" % (len(jobs), seen_keys, len(rows)))
286
+ PY
287
+ local static_bad
288
+ static_bad="$(grep -c '^PROBLEM' "$tmp/walk-static.log" 2>/dev/null || true)"
289
+ [ -n "$static_bad" ] || static_bad=0
290
+ if [ "$static_bad" -gt 0 ]; then
291
+ bad "走查($label):schema 与 choices 的静态一致性有 $static_bad 条问题"
292
+ grep '^PROBLEM' "$tmp/walk-static.log" | head -5 | sed 's/^/ /'
293
+ else
294
+ ok "走查($label):schema 与 choices 的静态一致性(values/min/max/known)全过"
295
+ fi
296
+ local jobs_count=0 seen_count=0 schema_count=0
297
+ read -r _ jobs_count seen_count schema_count <<< "$(grep '^COUNTS' "$tmp/walk-static.log" 2>/dev/null | tail -1)" || true
298
+ if [ "$schema_count" -gt 0 ] && [ "$seen_count" -eq "$schema_count" ] && [ "$jobs_count" -ge 60 ]; then
299
+ ok "走查($label):$jobs_count 条 options 作业,覆盖 $seen_count/$schema_count 个 schema 键"
300
+ else
301
+ bad "走查($label):作业 $jobs_count 条 / 覆盖 $seen_count of $schema_count 个 schema 键(太少,走查没覆盖 schema)"
302
+ fi
303
+ local n=0 refused=0
304
+ while IFS=$'\t' read -r key whole v; do
305
+ [ -n "$key" ] || continue
306
+ n=$((n + 1))
307
+ out="$(run_in "$wp" config set "$key" "$whole" --dry-run)"; rc=$?
308
+ case "$rc" in
309
+ 0|7) ;;
310
+ *)
311
+ refused=$((refused + 1))
312
+ bad "走查($label):$key 的选项 [$v](组合成 [$whole])被校验器拒绝(rc=$rc):$(printf '%s' "$out" | head -1)"
313
+ ;;
314
+ esac
315
+ done < "$tmp/walk-jobs.tsv"
316
+ [ "$refused" -eq 0 ] && ok "走查($label):$n 条 options 全部被 team config set 接受(0,或 7 = danger)"
317
+ local mism=0
318
+ while IFS=$'\t' read -r key want_v; do
319
+ [ -n "$key" ] || continue
320
+ out="$(run_in "$wp" config set "$key" "" --dry-run)"; rc=$?
321
+ local got=false
322
+ [ "$rc" -eq 0 ] && got=true
323
+ if [ "$got" != "$want_v" ]; then
324
+ mism=$((mism + 1))
325
+ bad "走查($label):$key 的 choices.empty=$want_v 与校验器对 '' 的判定($got, rc=$rc)不一致"
326
+ fi
327
+ done < "$tmp/walk-empty.tsv"
328
+ [ "$mism" -eq 0 ] && ok "走查($label):每个键的 choices.empty = 校验器对空值的判定"
329
+ assert_eq "走查($label):dry-run 走查没有写契约(sha 不变)" "$(sha_of "$wp/.pi/team/config.sh")" "$sha_before"
330
+ printf ' 走查(%s):%s 条 options 作业 + 空值判定走完\n' "$label" "$n"
331
+ }
332
+
333
+ if want walk; then
334
+ section "walk · 读给出的值 = 校验器接受的值(R1 的诚实闸门:不静默过滤,接受域不一致就红)"
335
+ walk_section "$tree" real
336
+ fi
337
+
338
+ # ---------------------------------------------------------------- read-equality
339
+ # M65/Q3(M2 的修法):读路径的重写(一次 awk 扫描 + 纯 bash 查表 + 写变量的 *_set 孪生)必须逐字节
340
+ # 忠实于契约。判据不是"再写一遍实现",而是一份**独立**的 python 解析器:直接读 fixture 契约的原始
341
+ # 字节,按 references/config.md 的规则(同名取第一行、引号内的 # 不是注释、双引号里的 \ 转义、值去
342
+ # 首尾空白与一层引号、注释含 # 前的空白)算出每条记录的(值、行内注释、set、known)与记录顺序
343
+ # (schema 顺序 + 文件顺序的未知键,重复行各一条),再与 `team config list --json` 逐条比对。
344
+ # 红侧(翻转):把扫描器的引号规则改坏(引号里的 # 也当注释)→ 值的字节不同 → 本节红(报告里给原始输出)。
345
+ if want read-equality; then
346
+ section "read-equality · 读出的字节 = 独立解析器(顺序/值/注释/set/未知键/重复行)"
347
+ p="$(new_proj read-equality)" || exit 3
348
+ cfg="$p/.pi/team/config.sh"
349
+ python3 - "$cfg" <<'PY'
350
+ import sys
351
+ p = sys.argv[1]
352
+ lines = [
353
+ '',
354
+ '# ---- read-equality fixture:读路径必须逐字节复现的形态 ----',
355
+ 'TEAM_HAND_ONE="hand # not a comment"',
356
+ "export TEAM_HAND_TWO='exported single'",
357
+ 'TEAM_HAND_THREE=plain # trailing comment',
358
+ 'TEAM_HAND_EMPTY=',
359
+ 'TEAM_HAND_HASH="a # b" # real comment here',
360
+ 'TEAM_HAND_EQ="a=b"',
361
+ '\tTEAM_HAND_TAB="tabbed" # leading tab + comment',
362
+ 'TEAM_HAND_ONE="second wins never"',
363
+ 'TEAM_ZARR_COMMENT="x" # 中文注释 # 带井号',
364
+ "TEAM_HAND_QUOTE='a\"b'",
365
+ 'TEAM_HAND_BACKSLASH="a\\\\b" # escaped backslash then comment',
366
+ 'TEAM_HAND_SPACE=" padded "',
367
+ ]
368
+ open(p, 'a', encoding='utf-8').write('\n'.join(lines) + '\n')
369
+ PY
370
+ run_in "$p" config list --json > "$tmp/read-equality.json"
371
+ python3 - "$cmd_config" "$cfg" "$tmp/read-equality.json" > "$tmp/read-equality.log" 2>&1 <<'PY'
372
+ import json, re, sys
373
+
374
+ schema_file, cfg, js = sys.argv[1], sys.argv[2], sys.argv[3]
375
+ src = open(schema_file, encoding="utf-8").read()
376
+ m = re.search(r"team_config_schema\(\) \{\n cat <<'EOF'\n(.*?)\nEOF\n\}", src, re.S)
377
+ if not m:
378
+ print("PROBLEM\t读不出 schema 表")
379
+ sys.exit(0)
380
+ rows = []
381
+ for line in m.group(1).splitlines():
382
+ if not line or line.startswith('#'):
383
+ continue
384
+ rows.append(line.split('|'))
385
+ schema = {f[0]: f for f in rows}
386
+
387
+ WS = ' \t\r\v\f\n'
388
+
389
+ def parse(line):
390
+ """契约一行的(key, value, comment);与 bash 侧的规则独立实现。"""
391
+ mm = re.match(r'^[ \t]*(?:export[ \t]+)?([A-Za-z_][A-Za-z0-9_]*)=(.*)$', line)
392
+ if not mm:
393
+ return None
394
+ key, s = mm.group(1), mm.group(2)
395
+ i, n, q, comment = 0, len(mm.group(2)), 0, ''
396
+ while i < n:
397
+ ch = s[i]
398
+ if q == 0:
399
+ if ch == '"':
400
+ q = 2
401
+ elif ch == "'":
402
+ q = 1
403
+ elif ch == '#':
404
+ g = i
405
+ while g > 0 and s[g - 1] in ' \t':
406
+ g -= 1
407
+ comment = s[g:]
408
+ s = s[:g]
409
+ break
410
+ elif q == 1:
411
+ if ch == "'":
412
+ q = 0
413
+ else:
414
+ if ch == '\\':
415
+ i += 1
416
+ elif ch == '"':
417
+ q = 0
418
+ i += 1
419
+ s = s.strip(WS)
420
+ if len(s) >= 2 and s[0] == s[-1] and s[0] in ('"', "'"):
421
+ s = s[1:-1]
422
+ return key, s, comment
423
+
424
+ first, order = {}, []
425
+ for line in open(cfg, encoding="utf-8").read().split('\n'):
426
+ got = parse(line)
427
+ if not got:
428
+ continue
429
+ key, value, comment = got
430
+ order.append(key)
431
+ if key not in first:
432
+ first[key] = (value, comment)
433
+
434
+ expected = []
435
+ for f in rows:
436
+ key = f[0]
437
+ if key in first:
438
+ expected.append((key, first[key][0], first[key][1], True, True))
439
+ else:
440
+ expected.append((key, '', '', False, True))
441
+ for key in order:
442
+ if key in schema:
443
+ continue
444
+ expected.append((key, first[key][0], first[key][1], True, False))
445
+
446
+ d = json.load(open(js, encoding="utf-8"))
447
+ got = [(k["name"], k["value"], k["comment"], bool(k["set"]), bool(k["known"])) for k in d["keys"]]
448
+
449
+ problems = []
450
+ if len(got) != len(expected):
451
+ problems.append("记录数 %d ≠ 期望 %d(多/少一条 = 顺序或重复行没复现)" % (len(got), len(expected)))
452
+ for i, (g, e) in enumerate(zip(got, expected)):
453
+ if g != e:
454
+ problems.append("第 %d 条不同:读 %r ≠ 期望 %r" % (i, g, e))
455
+ if len(problems) >= 8:
456
+ break
457
+ for prob in problems:
458
+ print("PROBLEM\t" + prob)
459
+ print("COUNTS\t%d\t%d" % (len(got), len(expected)))
460
+ PY
461
+ eq_bad="$(grep -c '^PROBLEM' "$tmp/read-equality.log" 2>/dev/null || true)"
462
+ [ -n "$eq_bad" ] || eq_bad=0
463
+ read -r _ eq_got eq_exp <<< "$(grep '^COUNTS' "$tmp/read-equality.log" 2>/dev/null | tail -1)" || true
464
+ if [ "$eq_bad" -eq 0 ] && [ -n "$eq_got" ]; then
465
+ ok "read-equality:$eq_got 条记录的顺序/值/注释/set/known 与独立解析器逐条一致(期望 $eq_exp 条)"
466
+ else
467
+ bad "read-equality:$eq_bad 条记录与独立解析器不一致(见 read-equality.log)"
468
+ grep '^PROBLEM' "$tmp/read-equality.log" 2>/dev/null | head -5 | sed 's/^/ /'
469
+ fi
470
+ # 三处最容易被"顺手优化"改坏的形状,逐条点名(不靠总长度撞上):
471
+ json_check "$(cat "$tmp/read-equality.json")" "引号里的 # 不是注释:值原样、注释为空" \
472
+ '[k for k in d["keys"] if k["name"]=="TEAM_HAND_ONE"][0]["value"]=="hand # not a comment" and [k for k in d["keys"] if k["name"]=="TEAM_HAND_ONE"][0]["comment"]==""'
473
+ json_check "$(cat "$tmp/read-equality.json")" "行内注释原样保留(# 前的空白也算)" \
474
+ '[k for k in d["keys"] if k["name"]=="TEAM_HAND_THREE"][0]["comment"]==" # trailing comment" and [k for k in d["keys"] if k["name"]=="TEAM_ZARR_COMMENT"][0]["comment"]==" # 中文注释 # 带井号"'
475
+ json_check "$(cat "$tmp/read-equality.json")" "空值仍是 set=true、value=''(不是 unset)" \
476
+ '[k for k in d["keys"] if k["name"]=="TEAM_HAND_EMPTY"][0]["set"] is True and [k for k in d["keys"] if k["name"]=="TEAM_HAND_EMPTY"][0]["value"]==""'
477
+ json_check "$(cat "$tmp/read-equality.json")" "未知键重复行各出一条记录(文件顺序,值取第一行)" \
478
+ '[k["value"] for k in d["keys"] if k["name"]=="TEAM_HAND_ONE"]==["hand # not a comment","hand # not a comment"]'
479
+ json_check "$(cat "$tmp/read-equality.json")" "双引号里的反斜杠转义照旧(值里的 \\ 不被吃掉)" \
480
+ '[k for k in d["keys"] if k["name"]=="TEAM_HAND_BACKSLASH"][0]["value"]=="a\\\\b"'
481
+ fi
482
+
483
+ # ---------------------------------------------------------------- catalogue
484
+ if want catalogue; then
485
+ section "catalogue · 机器目录不是选项来源(R2:sub2api 那个已下线 provider 不许出现)"
486
+ p="$(new_proj catalogue)" || exit 3
487
+ home="$tmp/catalogue-home"
488
+ mkdir -p "$home/.pi/agent"
489
+ cat > "$home/.pi/agent/models-store.json" <<'JSON'
490
+ {
491
+ "sub2api": {"models": {"gpt-5.6-luna": {"name": "gpt-5.6-luna", "baseUrl": "http://127.0.0.1:8080/v1"}}},
492
+ "openrouter": {"models": {"anthropic/claude-x": {"name": "claude-x"}}}
493
+ }
494
+ JSON
495
+ json="$(cd "$p" && HOME="$home" bash "$team" config list --json 2>&1)"
496
+ case "$json" in *sub2api*) bad "机器目录里的 sub2api 泄漏进了读(choices/known)" ;; *) ok "读里没有机器目录的 sub2api" ;; esac
497
+ case "$json" in *openrouter*) bad "机器目录里的 openrouter 泄漏进了读" ;; *) ok "读里没有机器目录的 openrouter" ;; esac
498
+ json_check "$json" "known 只有本项目配置/记录的模型(夹具 default)" \
499
+ 'd["models"]["known"]==["deepseek/deepseek-flash"]'
500
+ json_check "$json" "model/pairlist/winlist/pattern 四类的 values 都不含目录里的 provider" \
501
+ 'all(all(not v.startswith("sub2api/") and not v.startswith("openrouter/") for v in k["choices"]["values"]) for k in d["keys"] if k["kind"] in ("model","pairlist","winlist","pattern"))'
502
+ fi
503
+
504
+ # ---------------------------------------------------------------- flip-drop-pm(F-A)
505
+ if want flip-drop-pm; then
506
+ section "flip F-A · 从 known 里去掉 pm 席位 → known 断言必须红且点名 pm;恢复 → 绿"
507
+ ft="$tmp/flip-drop-pm"
508
+ mkdir -p "$ft/skills/teamsmith"
509
+ cp -a "$skill/scripts" "$ft/skills/teamsmith/scripts"
510
+ cp -a "$skill/templates" "$skill/references" "$ft/skills/teamsmith/"
511
+ python3 - "$ft/skills/teamsmith/scripts/lib/cmd-config.sh" <<'PY'
512
+ import sys
513
+ p = sys.argv[1]
514
+ s = open(p, encoding="utf-8").read()
515
+ # P47/R4:席位行改成字段安全拆读(team_config_seat_split)——翻转仍锚在「known 走查里的 pm 席位」这一行
516
+ old = ' team_config_seat_split "$(team_config_seat_state "$a")" seat_model _src _override'
517
+ assert old in s, "找不到 pm 席位解析那一行"
518
+ s = s.replace(old, " [ \"$a\" = \"pm\" ] && continue\n" + old, 1)
519
+ open(p, "w", encoding="utf-8").write(s)
520
+ PY
521
+ TEAM_CHOICES_TREE="$ft" bash "$here/panel-choices.sh" known > "$tmp/flip-drop-pm-red.log" 2>&1
522
+ rc_red=$?
523
+ TEAM_CHOICES_TREE="$tree" bash "$here/panel-choices.sh" known > "$tmp/flip-drop-pm-green.log" 2>&1
524
+ rc_green=$?
525
+ if [ "$rc_red" -ne 0 ] && grep -a '✗' "$tmp/flip-drop-pm-red.log" | grep -q 'pm'; then
526
+ ok "F-A:去掉 pm 的解析后 known 断言红且点名 pm(rc=$rc_red)"
527
+ else
528
+ bad "F-A:去掉 pm 的解析后 known 断言没红/没点名 pm(rc=$rc_red)"
529
+ fi
530
+ [ "$rc_green" -eq 0 ] && ok "F-A:恢复真树后 known 断言绿" || bad "F-A:真树也红了(rc=$rc_green)"
531
+ printf ' --- 红侧尾部 ---\n'
532
+ { grep -aE '✗|== 结果' "$tmp/flip-drop-pm-red.log" || true; } | tail -6 | sed 's/^/ /'
533
+ fi
534
+
535
+ # ---------------------------------------------------------------- flip-suggest(F-D)
536
+ if want flip-suggest; then
537
+ section "flip F-D · 建议值落在最小之外(30 < 60)→ 走查必须红且点名;恢复 → 绿"
538
+ ft="$tmp/flip-suggest"
539
+ mkdir -p "$ft/skills/teamsmith"
540
+ cp -a "$skill/scripts" "$ft/skills/teamsmith/scripts"
541
+ cp -a "$skill/templates" "$skill/references" "$ft/skills/teamsmith/"
542
+ flip_cfg="$ft/skills/teamsmith/scripts/lib/cmd-config.sh"
543
+ cp -a "$cmd_config" "$flip_cfg"
544
+ python3 - "$flip_cfg" <<'PY'
545
+ import sys
546
+ p = sys.argv[1]
547
+ s = open(p, encoding="utf-8").read()
548
+ old = "TEAM_PULSE_INTERVAL|restart|seconds|60,|plain|900|低于 60 秒 = 巡检转成忙等||300,900,1800,3600"
549
+ new = "TEAM_PULSE_INTERVAL|restart|seconds|60,|plain|900|低于 60 秒 = 巡检转成忙等||30,900,1800,3600"
550
+ assert old in s, "找不到 TEAM_PULSE_INTERVAL 的 schema 行"
551
+ open(p, "w", encoding="utf-8").write(s.replace(old, new, 1))
552
+ PY
553
+ TEAM_CHOICES_TREE="$ft" bash "$here/panel-choices.sh" walk > "$tmp/flip-suggest-red.log" 2>&1
554
+ rc_red=$?
555
+ if [ "$rc_red" -ne 0 ]; then ok "F-D:建议值 30 让走查变红(rc=$rc_red)"; else bad "F-D:建议值 30 的走查居然绿(闸门失效)"; fi
556
+ if grep -a '✗' "$tmp/flip-suggest-red.log" | grep -q 'TEAM_PULSE_INTERVAL' && grep -a '✗' "$tmp/flip-suggest-red.log" | grep -q '30'; then
557
+ ok "F-D:红侧点名 TEAM_PULSE_INTERVAL 与 30"
558
+ else
559
+ bad "F-D:红侧没有点名 TEAM_PULSE_INTERVAL / 30"
560
+ fi
561
+ # 恢复原始 schema(只在这个 scratch 副本里翻转,真树不动)
562
+ cp -a "$cmd_config" "$flip_cfg"
563
+ TEAM_CHOICES_TREE="$ft" bash "$here/panel-choices.sh" walk > "$tmp/flip-suggest-green.log" 2>&1
564
+ rc_green=$?
565
+ [ "$rc_green" -eq 0 ] && ok "F-D:恢复建议列后走查变绿" || bad "F-D:恢复后走查仍红(rc=$rc_green)"
566
+ printf ' --- 红侧尾部 ---\n'
567
+ { grep -aE '✗|== 结果' "$tmp/flip-suggest-red.log" || true; } | tail -6 | sed 's/^/ /'
568
+ fi
569
+
570
+ printf '\n\033[1m== 结果 ==\033[0m ✓ %d ✗ %d\n' "$PASS" "$FAIL"
571
+ [ "$FAIL" -eq 0 ] && exit 0
572
+ exit 1