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,173 @@
1
+ #!/usr/bin/env bash
2
+ # P26/G3 · panel-cpu.sh 的**负载前提**夹具:四种形状,逐个钉退出码。
3
+ #
4
+ # bash skills/teamsmith/tests/panel-cpu-premise.sh
5
+ #
6
+ # 为什么单独一个脚本:每个用例都要真起一个 tmux 私有 server + 真面板,全跑 ~1 分钟,所以它不进
7
+ # FAST 段;smoke 的 §36 在**全量模式**里调它(FAST 模式显式 SKIP)。
8
+ #
9
+ # 用例(panel#Frame assembly is asynchronous… MODIFIED):
10
+ # a) 夹具负载 > 前提 + 真越线的首帧 → **exit 4**(跳过:打印首帧 ms、窗格 CPU%、load)
11
+ # b) 夹具负载 ≤ 前提 + 同一个越线首帧 → exit 2(红线没有被前提拿走)
12
+ # c) 夹具负载 ≤ 前提 + 健康首帧 → exit 0
13
+ # d) 真路径(不开 TEAM_SMOKE_FIXTURE):两个夹具旋钮被忽略且打印,判定不受影响(不是 4)
14
+ #
15
+ # 真机负载本身就超前提时,本脚本**可见地跳过**(exit 4)——那是机器忙,不是夹具坏了。
16
+ # 环境缺少树 CPU 图要的 GNU time(`/usr/bin/time`)时也一样**可见跳过**(exit 4):`panel-cpu.sh`
17
+ # 自己会因此跳过,下面的四个期望(4 / 2 / 0 / 2)就都无从判起 —— 把环境缺口算成面板红是假红
18
+ # (M51 的 CI 红就是这个形状)。
19
+ set -uo pipefail
20
+
21
+ here="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
22
+ # P53:临时根的唯一创建者(${TMPDIR:-/tmp} + owned 家族 + 回收)
23
+ . "$here/lib/tmp-root.sh"
24
+ tree="${TEAM_PANEL_CPU_TREE:-$(cd -P "$here/../../.." && pwd)}"
25
+ cpu="$here/panel-cpu.sh"
26
+ window="${TEAM_PANEL_CPU_SECS:-6}" # 太短的窗口会把启动尾巴算进 CPU 均值(实测 3s → 1.6%,6s → 0.4%)
27
+ tmp="$(tmp_root_create panel-cpu-premise)" || exit 3
28
+ trap 'tmp_root_reap_all' EXIT
29
+ # 缺 GNU time → 可见跳过(与 panel-cpu.sh 的 exit 4 同一个语义:没结论,不是通过也不是红)。
30
+ # 解析口径与 panel-cpu.sh 逐字一致(`/usr/bin/time`,否则 PATH 上的 `time`)。
31
+ p26_time_ok=0
32
+ for _p26c in /usr/bin/time "$(command -v time || true)"; do [ -x "$_p26c" ] && { p26_time_ok=1; break; }; done
33
+ if [ "$p26_time_ok" != "1" ]; then
34
+ printf 'panel-cpu-premise: SKIP(树 CPU 图需要 GNU time = /usr/bin/time,本环境没装 → panel-cpu.sh 会可见跳过,四个用例无从判定)\n'
35
+ exit 4
36
+ fi
37
+ PASS=0; FAIL=0; FIND=0
38
+ ok() { printf ' \033[32m✓\033[0m %s\n' "$1"; PASS=$((PASS + 1)); }
39
+ bad() { printf ' \033[31m✗\033[0m %s\n' "$1"; FAIL=$((FAIL + 1)); }
40
+ finding() { printf ' \033[33mfinding\033[0m %s\n' "$1"; FIND=$((FIND + 1)); }
41
+
42
+ cores="$(nproc 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null || printf 0)"
43
+ case "$cores" in ''|*[!0-9]*) cores=0 ;; esac
44
+ real_load="$(cut -d' ' -f1 /proc/loadavg 2>/dev/null || printf '?')"
45
+ if [ "$cores" -le 0 ]; then
46
+ printf 'panel-cpu-premise: SKIP(读不到逻辑核数)\n'; exit 4
47
+ fi
48
+ FACTOR="${TEAM_PANEL_CPU_PREMISE_FACTOR:-0.25}" # 与 panel-cpu.sh 同一个旋钮/同一个默认值
49
+ case "$FACTOR" in ''|*[!0-9.]*) FACTOR=0.25 ;; esac
50
+ thr="$(awk -v c="$cores" -v f="$FACTOR" 'BEGIN { printf "%.2f", f * c }')"
51
+ above="$(awk -v t="$thr" 'BEGIN { printf "%.2f", t + 1.0 }')"
52
+ below="$(awk -v t="$thr" 'BEGIN { printf "%.2f", (t > 1.0) ? t - 1.0 : 0.0 }')"
53
+ # 真机安静与否只影响**用例 c** 的严格程度(它真的在量这台机器),不再直接退出:
54
+ # a/b/d 的读数由夹具注入,任何真机负载下都有意义。
55
+ if awk -v l="$real_load" -v t="$thr" 'BEGIN { exit !(l <= t) }'; then
56
+ printf '== 前提:真机 loadavg %s ≤ %s(%s × %s 核)→ 用例 c 用**严格**期望(exit 0)\n' \
57
+ "$real_load" "$thr" "$FACTOR" "$cores"
58
+ else
59
+ printf '== 前提:真机 loadavg %s > %s(%s × %s 核)→ 用例 c 只允许「0 或 2+实测数」并把 2 记成 finding\n' \
60
+ "$real_load" "$thr" "$FACTOR" "$cores"
61
+ fi
62
+ printf '== 用例读数用 above=%s / below=%s(夹具注入);阈值 %s = %s × %s 核\n' "$above" "$below" "$thr" "$FACTOR" "$cores"
63
+
64
+ run_case() { # <名字> <期望 rc | `-` 表示不断言> <env…> -- <断言用的 pattern…>
65
+ local name="$1" want="$2"; shift 2
66
+ local envs=(); while [ $# -gt 0 ] && [ "$1" != "--" ]; do envs+=("$1"); shift; done
67
+ [ "${1:-}" = "--" ] && shift
68
+ local out="$tmp/$name.log"
69
+ ( cd "$tree" && env -u TMUX -u TMUX_PANE ${envs[@]+"${envs[@]}"} TEAM_PANEL_CPU_SECS="$window" \
70
+ timeout 300 bash "$cpu" ) >"$out" 2>&1
71
+ local rc=$?
72
+ LAST_RC=$rc
73
+ printf ' %s:rc=%s(期望 %s);尾部:%s\n' "$name" "$rc" "$want" "$(sed -n 's/^panel-cpu: //p' "$out" | tail -1)"
74
+ if [ "$want" = "-" ]; then
75
+ ok "panel-cpu-premise $name:退出码 $rc(本条不断言,调用方接着判)"
76
+ elif [ "$rc" = "$want" ]; then ok "panel-cpu-premise $name:退出码 $rc"; else
77
+ bad "panel-cpu-premise $name:期望退出码 $want,实际 $rc(见 $out)"
78
+ sed -n '/^== /p;/^panel-cpu:/p' "$out" | tail -4 | sed 's/^/ /'
79
+ fi
80
+ local pat
81
+ for pat in "$@"; do
82
+ if grep -aqE -- "$pat" "$out"; then ok "panel-cpu-premise $name:输出里有 /$pat/"; else
83
+ bad "panel-cpu-premise $name:输出里没有 /$pat/"; fi
84
+ done
85
+ LAST_OUT="$out"
86
+ }
87
+
88
+ # a) 负载超前提 + 真越线的首帧 → 4(注入 2500ms:三次 spawn 的中位必然 > 2000,不做时序假设)
89
+ run_case a-above 4 TEAM_SMOKE_FIXTURE=1 TEAM_PANEL_CPU_LOADAVG="$above" TEAM_PANEL_CPU_CORES="$cores" \
90
+ TEAM_PANEL_CPU_FRAME_DELAY_MS=2500 -- 'load premise: loadavg .* > ' 'SKIP \(exit 4' 'first frame: .*-> median (never|[0-9]+) \(budget 2000ms\)'
91
+ # `never` 也属于「越线」(>2000ms):夹具的轮询预算 ~3.1s,注入把首帧推到它之后
92
+ grep -aqE 'first frame: .*-> median (never|2[0-9]{3}|[3-9][0-9]{3})' "$LAST_OUT" \
93
+ && ok "panel-cpu-premise a-above:注入真的把首帧抬过 2000ms($(sed -n 's/^== first frame: //p' "$LAST_OUT" | head -1))" \
94
+ || bad "panel-cpu-premise a-above:注入没造出越线的首帧($(sed -n 's/^== first frame: //p' "$LAST_OUT" | head -1))"
95
+
96
+ # b) 负载低于前提 + 同一个越线首帧 → 2(红线没被前提拿走)
97
+ run_case b-below 2 TEAM_SMOKE_FIXTURE=1 TEAM_PANEL_CPU_LOADAVG="$below" TEAM_PANEL_CPU_CORES="$cores" \
98
+ TEAM_PANEL_CPU_FRAME_DELAY_MS=2500 -- 'load premise: loadavg .* <= ' 'panel-cpu: RED'
99
+
100
+ # c) 负载低于前提 + 健康首帧 → 0。注意:这条**真的**在量这台机器的 CPU/首帧(前提只管负载,不管别的
101
+ # 重活儿)—— 同机的全量门禁/复验正在跑时,它会读到越线的首帧或 CPU(实测:与 P24 的全量 smoke
102
+ # 并发时 CPU 1.6%;load 17 时首帧 2294ms)。
103
+ # 口径(PM 复验 2026-09-20T13:33Z 的教训,与 d 同理):
104
+ # * 机器安静(load ≤ 0.5 × 阈值):**严格**要求 exit 0;
105
+ # * 机器不安静:只允许 0(仍绿) 或 2(本机读数越线 → 记 finding,把首帧/CPU/load 写出来);
106
+ # 决不允许 4(负载低于前提时不该走跳过)也决不允许别的码。
107
+ quiet_gate="$(awk -v t="$thr" 'BEGIN { printf "%.2f", 0.5 * t }')" # 严格期望只在这条线以内给
108
+ machine_quiet=0
109
+ awk -v l="$real_load" -v t="$quiet_gate" 'BEGIN { exit !(l <= t) }' && machine_quiet=1
110
+ run_case c-healthy - TEAM_SMOKE_FIXTURE=1 TEAM_PANEL_CPU_LOADAVG="$below" TEAM_PANEL_CPU_CORES="$cores" -- \
111
+ 'load premise: loadavg .* <= '
112
+ C_OUT="$LAST_OUT" # M58:c-healthy 的原始日志(给 tests/perf.sh 的机读读数用;d-* 会把 LAST_OUT 改掉)
113
+ C_FF="$(sed -n 's/.*-> median \(never\|[0-9]*\) (budget.*/\1/p' "$LAST_OUT" | head -1)"
114
+ C_PANE="$(sed -n 's/.*-> median \([0-9.]*\)% (overall.*/\1/p' "$LAST_OUT" | tail -1)"
115
+ C_RC="${LAST_RC:-?}"
116
+ if [ "$C_RC" = "0" ]; then
117
+ ok "panel-cpu-premise c-healthy:健康帧 + 前提成立 → 退出码 0(首帧 ${C_FF:-?}ms,窗格 CPU ${C_PANE:-?}%)"
118
+ elif [ "$C_RC" = "2" ] && [ "$machine_quiet" = "0" ]; then
119
+ finding "panel-cpu-premise c-healthy:机器不安静(真机 loadavg ${real_load} > ${quiet_gate})时判红:首帧 ${C_FF:-?}ms、窗格 CPU ${C_PANE:-?}% —— 是这台机器的读数(安静时同夹具 0.4% / ~1.5s),不是面板回归;不给健康结论也不冤枉面板"
120
+ elif [ "$C_RC" = "2" ]; then
121
+ bad "panel-cpu-premise c-healthy:机器安静(loadavg ${real_load} ≤ ${quiet_gate})却判红(首帧 ${C_FF:-?}ms、CPU ${C_PANE:-?}%)—— 机器安静时这是真红"
122
+ else
123
+ bad "panel-cpu-premise c-healthy:退出码 $C_RC 不在 {0, 2} 里(负载低于前提时不该出现跳过/其他码)"
124
+ fi
125
+
126
+ # d) 真路径:夹具旋钮被忽略(打印忽略行)且**判定不受影响**。
127
+ #
128
+ # PM 复验(2026-09-20T13:33Z,load≈20)抓到这里的期望写错了:原来写死 `0`,等于假设机器安静 ——
129
+ # 在前提之内但机器忙/面板真慢时,真路径会诚实地判红(exit 2),那是**判定**,不是后门。
130
+ # 现在分两层:
131
+ # ① 期望集合 **{0,4}**(健康:0;真机负载超前提:4);
132
+ # ② 若得到 2(前提内但判红),跑一次**不带旋钮的对照抛** —— 两边同为 2 ⇒ 是这台机器/面板的读数
133
+ # (记 finding);两边不同 ⇒ 旋钮改了判定,才是后门(红)。
134
+ # 反后门的三条断言(两个「忽略」行 + premise 行必须反映**真实**读数)无条件保留。
135
+ run_case d-realpath - TEAM_PANEL_CPU_LOADAVG=9999 TEAM_PANEL_CPU_CORES=1 TEAM_PANEL_CPU_FRAME_DELAY_MS=99999 -- \
136
+ '忽略 TEAM_PANEL_CPU_LOADAVG=9999' '忽略 TEAM_PANEL_CPU_CORES=1' '忽略 TEAM_PANEL_CPU_FRAME_DELAY_MS=99999' \
137
+ 'load premise: loadavg [0-9.]+ (<=|>) [0-9.]+ \([0-9.]+ x [0-9]+ cores\)'
138
+ # premise 行里不允许出现注入值(9999 / 1 核)——「必须反映真实读数」的可机检形式
139
+ grep -aqE 'load premise: loadavg 9999|0\.75 x 1 cores' "$LAST_OUT" \
140
+ && bad "panel-cpu-premise d-realpath:premise 行里出现了注入值(旋钮漏进了真路径!)" \
141
+ || ok "panel-cpu-premise d-realpath:premise 行只反映真实读数(没有 9999 / 1 核)"
142
+ D_FF="$(sed -n 's/.*-> median \(never\|[0-9]*\) (budget.*/\1/p' "$LAST_OUT" | head -1)"
143
+ D_PANE="$(sed -n 's/.*-> median \([0-9.]*\)% (overall.*/\1/p' "$LAST_OUT" | tail -1)"
144
+ D_RC="$LAST_RC"
145
+ case "$D_RC" in
146
+ 0|4) ok "panel-cpu-premise d-realpath:真路径退出码 $D_RC ∈ {0,4}(旋钮没有改变判定)" ;;
147
+ 2)
148
+ # 真路径判红。**反后门不靠跨跑比较**(两次跑之间机器可能变忙/变闲 —— 跨跑比较会冤枉实现):
149
+ # 它由上面三条**同一次跑内**的断言保证(三个「忽略…」行 + premise 行只反映真实读数)。
150
+ # 对照跑只作为日志读数打印,判红本身记 finding。
151
+ run_case d-control 2 -- 'load premise: loadavg [0-9.]+ <='
152
+ finding "panel-cpu-premise d-realpath:真路径判红(exit 2):首帧 ${D_FF:-?}ms、窗格 CPU ${D_PANE:-?}%、load $(cut -d' ' -f1 /proc/loadavg) —— 这台机器的读数(对照跑 rc=${LAST_RC:-?} 仅作参考;反后门由本次跑内的三条断言负责)"
153
+ ;;
154
+ *) bad "panel-cpu-premise d-realpath:退出码 $D_RC 既不是 0/4(期望集合)也不是 2(可解释)" ;;
155
+ esac
156
+
157
+ # M58:给 tests/perf.sh 的机读读数(**附加输出**:不改任何断言/期望/退出码语义)。
158
+ # c-healthy 是「真机 + 注入前提成立」的测量案例 —— 它的首帧/窗格 CPU 中位就是红线判定 ①③ 的读数;
159
+ # 上面的 ok/finding/bad 行是给人读的,这里给套件一份稳定形状。
160
+ printf '== perf-readings ==\n'
161
+ printf 'first_frame_line=%s\n' "$(sed -n 's/^== first frame: //p' "${C_OUT:-}" 2>/dev/null | head -1)"
162
+ printf 'pane_cpu_line=%s\n' "$(sed -n 's/^== pane CPU thirds: //p' "${C_OUT:-}" 2>/dev/null | tail -1)"
163
+
164
+ printf '\n== 结果 == ✓ %d ✗ %d finding %d\n' "$PASS" "$FAIL" "$FIND"
165
+ if [ "$FAIL" -gt 0 ]; then
166
+ printf '\033[31mpanel-cpu-premise 有失败项\033[0m\n'; exit 1
167
+ fi
168
+ if [ "$FIND" -gt 0 ]; then
169
+ # 只有 finding(典型:机器被别的门禁占着,窗格 CPU 读不出干净的数)→ **exit 4**(没结论),
170
+ # 与 panel-cpu.sh 的负载跳过同一个码:既不是通过也不是红,调用方据此可见地 SKIP。
171
+ printf '\033[33mpanel-cpu-premise:有 finding(机器不够安静)→ 退出 4(没结论)\033[0m\n'; exit 4
172
+ fi
173
+ printf '\033[32mpanel-cpu-premise 全绿\033[0m\n'; exit 0
@@ -0,0 +1,391 @@
1
+ #!/usr/bin/env bash
2
+ # CPU red-line fixture (pulse-console B1, tasks.md 1.5).
3
+ #
4
+ # bash skills/teamsmith/tests/panel-cpu.sh [tree] [seconds]
5
+ # TEAM_PANEL_CPU_PAGE=4 bash skills/teamsmith/tests/panel-cpu.sh # park it on the board page
6
+ # TEAM_PANEL_CPU_DETAIL=1 bash skills/teamsmith/tests/panel-cpu.sh # open the markdown detail view
7
+ # TEAM_PANEL_CPU_COMPOSE=1 bash skills/teamsmith/tests/panel-cpu.sh # hold the compose line open
8
+ # TEAM_PANEL_CPU_VIEW=1 bash skills/teamsmith/tests/panel-cpu.sh # keep the project-settings view open
9
+ # TEAM_PANEL_CPU_VIEW=1 TEAM_PANEL_CPU_EDIT=1 bash ... # …and an editor holding a typed draft
10
+ #
11
+ # P26/G3(panel#Frame assembly is asynchronous… MODIFIED):2000ms 与 1% 是**面板**的判定,不是机器的
12
+ # 判定 —— 它们只在**测量前提**成立时判:`loadavg_1m ≤ factor × 逻辑核数`(核数取 `nproc`,否则
13
+ # `getconf _NPROCESSORS_ONLN`)。前提不成立就打印实测的三个数(首帧 ms、窗格 CPU%、load)并退出 **4**。
14
+ #
15
+ # **本文件用 factor = 0.25**(`TEAM_PANEL_CPU_PREMISE_FACTOR` 可覆盖)—— 与 smoke 27-d 的 0.75 不同,
16
+ # 因为两者量的东西不同:27-d 是 5 次采样的**中位**(实测到 0.62 × 核仍 1.2–1.7s,M49 的红在
17
+ # 0.81–1.0 × 核),而这里的交互首帧是**单进程冷启动**量出来的,实测(32 核机器,median-of-3):
18
+ # 0.22 × 核(load 6.9)首帧中位 1542ms ✓ | 0.40 × 核(load 13.0)2005ms ✗ | 0.71 × 核(load 22.8)3919ms ✗
19
+ # 也就是绿→红的交叉在 0.22–0.40 × 核之间;取 0.25 × 核(本机 load 8)落在交叉之下、实测绿之上。
20
+ # 代价说明:机器忙时这条断言会可见地 SKIP(退出 4),而不是给出一个机器欠的假红。
21
+ # 红线本身**没有动**:前提成立时判法与阈值与以前逐字一致(超 2000ms 或 CPU ≥ 1% → 退出 2)。
22
+ #
23
+ # **中位 of 3**(PM 口径决定,2026-09-20 第二批返工):首帧与窗格 CPU% 都取三次测量的中位,三个样本
24
+ # 都打印出来 —— 单次采样把机器自己的启动抖动算进了面板的账(实测:安静时 ~1.5s,load 4.5 时单次
25
+ # 2141ms,load 13 时 2279ms;同一台机器同一天里 1.697% 与 0.399% 都出现过)。首帧是三次**独立 spawn**
26
+ # (每次都是「窗口创建 → 第一帧可见」);CPU% 是把同一个采样窗口**三等分**后的三个子窗均值(不额外
27
+ # 加长采样时间)。阈值不缩放:中位 ≥ 2000ms 或中位 ≥ 1% 仍是红。
28
+ #
29
+ # 环境姿态(M51):树 CPU 图用 `/usr/bin/time -o/-f` 读,缺这个工具时**可见跳过**(exit 4,打印原因)——
30
+ # 它是附带读数,不是判定依据(判定只看首帧与窗格 CPU);把它当搭建失败(exit 3)会在缺工具的环境里
31
+ # 造出假红(CI 的 M51 红就是这个形状)。门禁镜像里有它(ci/Containerfile 的构建期断言)。
32
+ #
33
+ # Exit: 0 窗格进程 < 1% 单核且首帧在预算内
34
+ # 2 红线破了(首帧 ≥ 2000ms 或窗格进程 ≥ 1%)
35
+ # 3 搭建失败(没有 tmux / node / bundle)
36
+ # 4 **跳过**(既不是通过也不是红;包装器不能把 4 当成 0):负载前提不成立,或环境缺 GNU time
37
+ #
38
+ # 夹具旋钮(**只在 `TEAM_SMOKE_FIXTURE=1` 时生效**,裸设一律忽略并打印):
39
+ # TEAM_PANEL_CPU_LOADAVG=<数> 替掉 /proc/loadavg 的读数
40
+ # TEAM_PANEL_CPU_CORES=<整数> 替掉核数
41
+ # TEAM_PANEL_CPU_FRAME_DELAY_MS=<ms> 在面板进程启动前睡一觉(造一个真越线的首帧)
42
+ set -uo pipefail
43
+
44
+ here="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
45
+ # P53/P68:临时根的唯一创建者(固定中性测量目标就建在它下面)
46
+ . "$here/lib/tmp-root.sh"
47
+ # P162:破坏性调用(kill-server/kill-session/kill-window)动手前先证明私有 socket 生效
48
+ . "$here/lib/tmux-iso.sh"
49
+ tree="${1:-$(cd -P "$here/../../.." && pwd)}"
50
+ secs="${2:-${TEAM_PANEL_CPU_SECS:-60}}"
51
+
52
+ # ── 测量前提(P26/G3)───────────────────────────────────────────────────────────────────────
53
+ # 夹具旋钮只有在 TEAM_SMOKE_FIXTURE=1 时被采信 —— 否则“负载前提”会退化成“想跳就跳”的后门
54
+ # (PM 审查要点②:真路径下的 TEAM_PANEL_CPU_* 注入不得改变判定)。
55
+ PREMISE_FACTOR="${TEAM_PANEL_CPU_PREMISE_FACTOR:-0.25}"
56
+ case "$PREMISE_FACTOR" in ''|*[!0-9.]*) PREMISE_FACTOR=0.25 ;; esac
57
+ pc_fixture_on() { [ "${TEAM_SMOKE_FIXTURE:-0}" = "1" ]; }
58
+ pc_notice() { printf ' 忽略 %s=%s(只有 TEAM_SMOKE_FIXTURE=1 时夹具旋钮才生效;真实路径读真值)\n' "$1" "$2" >&2; }
59
+ pc_load() {
60
+ if [ -n "${TEAM_PANEL_CPU_LOADAVG:-}" ]; then
61
+ if pc_fixture_on; then printf '%s\n' "$TEAM_PANEL_CPU_LOADAVG"; return 0; fi
62
+ pc_notice TEAM_PANEL_CPU_LOADAVG "$TEAM_PANEL_CPU_LOADAVG"
63
+ fi
64
+ cut -d' ' -f1 /proc/loadavg 2>/dev/null || printf '?'
65
+ }
66
+ pc_cores() {
67
+ if [ -n "${TEAM_PANEL_CPU_CORES:-}" ]; then
68
+ if pc_fixture_on; then printf '%s\n' "$TEAM_PANEL_CPU_CORES"; return 0; fi
69
+ pc_notice TEAM_PANEL_CPU_CORES "$TEAM_PANEL_CPU_CORES"
70
+ fi
71
+ nproc 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null || printf '0'
72
+ }
73
+ # → 0 前提成立(照判)/ 1 不成立(跳过)。同时把前提一行打给人看。
74
+ pc_premise() {
75
+ local load cores thr
76
+ load="$(pc_load)"; cores="$(pc_cores)"
77
+ case "$cores" in ''|*[!0-9]*) cores=0 ;; esac
78
+ thr="$(awk -v c="$cores" -v f="$PREMISE_FACTOR" 'BEGIN { printf "%.2f", f * c }')"
79
+ if [ "$cores" -gt 0 ] && awk -v l="$load" -v t="$thr" 'BEGIN { exit !(l <= t) }'; then
80
+ printf '== load premise: loadavg %s <= %s (%s x %s cores) -> hold (judging)\n' "$load" "$thr" "$PREMISE_FACTOR" "$cores"
81
+ return 0
82
+ fi
83
+ printf '== load premise: loadavg %s > %s (%s x %s cores) -> NOT held (skip)\n' "$load" "$thr" "$PREMISE_FACTOR" "$cores"
84
+ return 1
85
+ }
86
+ # ── 前提自述模式(M58/B1 1.7):只打印前提行与每个注入旋钮的忽略行,**不测量、不起任何进程**。
87
+ # 这是 d-realpath 承诺的时间无关形态(正确性门禁每轮都跑它,经 tests/panel-knobs.sh):夹具开关关着时,
88
+ # 注入的 TEAM_PANEL_CPU_* 必须被忽略并打印,前提行必须反映真读数。它不判任何时长,退出 0。
89
+ if [ "${TEAM_PANEL_CPU_PREMISE_ONLY:-0}" = "1" ]; then
90
+ # pc_premise 自己会把注入的 LOADAVG / CORES 走 pc_load/pc_cores 读一遍(真路径即打印忽略行)。
91
+ if [ -n "${TEAM_PANEL_CPU_FRAME_DELAY_MS:-}" ]; then
92
+ if pc_fixture_on; then :; else pc_notice TEAM_PANEL_CPU_FRAME_DELAY_MS "$TEAM_PANEL_CPU_FRAME_DELAY_MS"; fi
93
+ fi
94
+ pc_premise || true # 前提一行(真读数;不成立也照打)
95
+ printf 'panel-cpu: premise-only 模式(裸读数 + 旋钮忽略声明;没有起进程、没有测量、没有判定)\n'
96
+ exit 0
97
+ fi
98
+
99
+ refresh="${TEAM_PANEL_CPU_REFRESH:-3}"
100
+ interval=5
101
+ sock="p12cpu-$$"
102
+ sess="p12cpu-$$"
103
+ js="${TEAM_JS_BIN:-$(command -v node || true)}"
104
+ [ -n "$js" ] || js="$(command -v bun || true)"
105
+ rc=3
106
+
107
+ cleanup() {
108
+ # P162:收尾先证明私有 socket 生效(不成立就拒绝;cleanup 里不许 exit)
109
+ tmux_iso_guard_soft "panel-cpu" "收尾:私有 server" --tmpdir "${TMUX_TMPDIR:-}" --sock-name "$sock" \
110
+ && tmux -L "$sock" kill-server 2>/dev/null || true
111
+ # tmux 在服务器已死时会把 socket 文件留在 /tmp/tmux-<uid>/:夹具自己收干净
112
+ rm -f "${TMUX_TMPDIR:-/tmp}/tmux-$(id -u)/$sock" 2>/dev/null || true
113
+ rm -rf "${time_out:-}.state" 2>/dev/null || true
114
+ tmp_root_reap_all # P68:中性测量目标(owned 家族)也收掉
115
+ }
116
+ trap cleanup EXIT
117
+
118
+ if ! command -v tmux >/dev/null 2>&1; then
119
+ printf 'panel-cpu: tmux is required (the fixture needs a real pane)\n' >&2
120
+ exit 3
121
+ fi
122
+ if [ -z "$js" ]; then
123
+ printf 'panel-cpu: no node/bun runtime\n' >&2
124
+ exit 3
125
+ fi
126
+ time_bin=""
127
+ for cand in /usr/bin/time "$(command -v time || true)"; do
128
+ [ -x "$cand" ] && { time_bin="$cand"; break; }
129
+ done
130
+ if [ -z "$time_bin" ]; then
131
+ printf 'panel-cpu: SKIP — the tree CPU figure needs GNU time (/usr/bin/time) and it is not installed here; the 2000ms / 1%% red line was not judged (exit 4; the gate image pins the tool)\n' >&2
132
+ exit 4
133
+ fi
134
+
135
+ panel="$tree/skills/teamsmith/scripts/panel/panel.js"
136
+ [ -f "$panel" ] || { printf 'panel-cpu: no bundle at %s\n' "$panel" >&2; exit 3; }
137
+
138
+ # ── P68/fixture-waits-for-landed-reads:测量目标固定 ────────────────────────────────────────────
139
+ # 面板首帧取决于项目的数据量,不取决于面板代码。旧形状把 `--root` 指到**调用者的工作树**,于是同一个
140
+ # bundle 在积累态的仓库里 3683 ms、在全新项目里 391 ms(P52 F4)——数字描述那个 checkout,不是面板;
141
+ # 从两个工作树跑同一个命令会得到两个结论。现在夹具自己建一个中性参考项目(tmp-root 的 owned 家族 +
142
+ # 真 `team init`,与其它夹具同形),`--root` 只指它;bundle 与 CLI 仍来自**被测代码树**,两个名字都
143
+ # 印出来(requirement:A measuring fixture measures a fixed tree, not the caller's worktree)。
144
+ neut_root="$(tmp_root_create panel-cpu-target)" \
145
+ || { printf 'panel-cpu: 建不出中性测量目标(tmp_root_create)\n' >&2; exit 3; }
146
+ # `team init` 不能继承调用者的团队身份(同其它夹具的首步隔离;这里只对 init 这一个子进程降掉)。
147
+ pc_init_clean=(env -u TEAM_ROOT -u TEAM_MAIN_ROOT -u TEAM_ROOT_SOURCE -u TEAM_ROOT_WAS -u TEAM_PROJECT \
148
+ -u TEAM_SESSION -u TEAM_SESSION_FROM -u TEAM_PM_WINDOW -u TEAM_AGENTS -u TEAM_DOCS_DIR -u TEAM_WORKTREES_DIR \
149
+ -u TEAM_GATES -u TEAM_VCS -u TEAM_CONFIG_FILE -u TEAM_ALLOW_FOREIGN_SESSION -u TEAM_PULSE_WINDOW \
150
+ -u TEAM_WATCH_WINDOW -u TEAM_STATE_DIR -u TEAM_JS_BIN)
151
+ ( cd "$neut_root" && git init -q -b main && git config user.email panel-cpu@teamsmith && git config user.name panel-cpu ) \
152
+ >/dev/null 2>&1
153
+ ( cd "$neut_root" && "${pc_init_clean[@]}" bash "$tree/skills/teamsmith/scripts/team" init \
154
+ --session "$sess" --agents "dev verify" --vcs local --gates "true" --docs docs/team ) \
155
+ >"$neut_root/init.log" 2>&1 \
156
+ || { printf 'panel-cpu: 中性测量目标的 team init 失败(见 %s/init.log)\n' "$neut_root" >&2; tail -3 "$neut_root/init.log" >&2; exit 3; }
157
+ printf '== measured project root: %s (neutral fixture project — not the caller worktree) ==\n' "$neut_root"
158
+ printf '== console bundle under test: %s (tree under test %s) ==\n' "$panel" "$tree"
159
+
160
+ hz="$(getconf CLK_TCK 2>/dev/null || echo 100)"
161
+ time_out="$(mktemp "${TMPDIR:-/tmp}/p12cpu.XXXXXX")"
162
+ # TEAM_PANEL_CPU_PAGE=<1|2|3|4> parks the measured console on that page (the board page's kanban is
163
+ # the heaviest layout, so the red line is checked there too — P18/B2 item 6.4).
164
+ page_flag=""
165
+ case "${TEAM_PANEL_CPU_PAGE:-}" in 1|2|3|4) page_flag=" --page ${TEAM_PANEL_CPU_PAGE}" ;; esac
166
+ # TEAM_PANEL_CPU_DETAIL=1 measures the markdown detail view's own steady state (P18/B3): the knob
167
+ # opens page 4 + the focused card's detail after warm-up. It runs with a private state dir, because
168
+ # sending keys must never write the real project's panel-page/panel.conf files.
169
+ # TEAM_PANEL_CPU_COMPOSE=1 (P20/B1 1.8) keeps the compose line open with a typed draft for the
170
+ # sampling window: the insertion point, the window and the cursor placement must not cost more than
171
+ # the idle console (same private state dir — the draft must never land in the real project).
172
+ detail_flag=""
173
+ compose_flag=""
174
+ state_flag=""
175
+ compose_env=""
176
+ if [ "${TEAM_PANEL_CPU_DETAIL:-0}" = "1" ] || [ "${TEAM_PANEL_CPU_COMPOSE:-0}" = "1" ]; then
177
+ [ "${TEAM_PANEL_CPU_DETAIL:-0}" = "1" ] && detail_flag=1
178
+ [ "${TEAM_PANEL_CPU_COMPOSE:-0}" = "1" ] && compose_flag=1
179
+ state_dir="${time_out}.state"
180
+ mkdir -p "$state_dir"
181
+ state_flag=" --state-dir $state_dir"
182
+ fi
183
+ if [ -n "$compose_flag" ]; then
184
+ # The C-v press must not read the real clipboard: a failing fake pair keeps the probe local and
185
+ # instant (the red line is about the frame, not about what the clipboard holds).
186
+ fakebin="${time_out}.fakebin"
187
+ mkdir -p "$fakebin"
188
+ printf '#!/usr/bin/env bash\nexit 1\n' > "$fakebin/wl-paste"
189
+ printf '#!/usr/bin/env bash\nexit 1\n' > "$fakebin/xclip"
190
+ chmod +x "$fakebin/wl-paste" "$fakebin/xclip"
191
+ compose_env="PATH=$fakebin:\$PATH "
192
+ fi
193
+ pane_cmd="cd '$neut_root' && ${compose_env}exec '$time_bin' -o '$time_out' -f 'P12CPU user=%U sys=%S elapsed=%e' -- '$js' '$panel' --root '$neut_root' --team-cli '$tree/skills/teamsmith/scripts/team' --no-pulse --refresh $refresh${page_flag}${state_flag}"
194
+ # 夹具注入(P26/G3):在面板进程启动前睡一觉 → 造一个**真越线**的首帧(只在夹具模式下)
195
+ if [ -n "${TEAM_PANEL_CPU_FRAME_DELAY_MS:-}" ]; then
196
+ if pc_fixture_on; then
197
+ case "$TEAM_PANEL_CPU_FRAME_DELAY_MS" in
198
+ ''|*[!0-9]*) : ;;
199
+ *) pane_cmd="$(awk -v ms="$TEAM_PANEL_CPU_FRAME_DELAY_MS" 'BEGIN { printf "sleep %.2f\n", ms / 1000 }')"$'\n'"$pane_cmd" ;;
200
+ esac
201
+ else
202
+ pc_notice TEAM_PANEL_CPU_FRAME_DELAY_MS "$TEAM_PANEL_CPU_FRAME_DELAY_MS"
203
+ fi
204
+ fi
205
+ tmux -L "$sock" new-session -d -s "$sess" -x 140 -y 34 -c "$neut_root" "sleep 600"
206
+ pc_premise || true # 前提一行先打(不成立也照测,因为退出 4 时要把实测三个数一起打出来)
207
+ # 首帧:三次独立 spawn 各量一次「窗口创建 → 第一帧可见」,取中位(中位 of 3)。
208
+ # `never` = 轮询预算内没出现(> 2000ms 的一种形态),记成 9999 参与中位,但打印时保留 `never`。
209
+ first_frames=()
210
+ ff_never=0
211
+ measure_first_frame() { # → 毫秒数(没出现 → 9999)
212
+ local ms="" t0
213
+ tmux -L "$sock" kill-window -t "$sess:console" 2>/dev/null || true
214
+ sleep 0.4
215
+ t0="$(date +%s%3N)"
216
+ tmux -L "$sock" new-window -d -t "$sess" -n console -c "$neut_root" "$pane_cmd" 2>/dev/null || true
217
+ # F8: the interactive first frame is measured, not promised — poll the pane for the title band.
218
+ for _ in $(seq 1 20); do
219
+ sleep 0.1
220
+ if tmux -L "$sock" capture-pane -p -t "$sess:console" 2>/dev/null | grep -q 'teamsmith pulse'; then
221
+ ms=$(( $(date +%s%3N) - t0 )); break
222
+ fi
223
+ done
224
+ if [ -z "$ms" ]; then
225
+ sleep 1 # one last look before judging it `never`
226
+ tmux -L "$sock" capture-pane -p -t "$sess:console" 2>/dev/null | grep -q 'teamsmith pulse' \
227
+ && ms=$(( $(date +%s%3N) - t0 ))
228
+ fi
229
+ if [ -z "$ms" ]; then printf '9999\n'; else printf '%s\n' "$ms"; fi
230
+ }
231
+ for _ffi in 1 2 3; do
232
+ ff="$(measure_first_frame)"
233
+ first_frames+=("$ff")
234
+ done
235
+ first_frame_ms="$(printf '%s\n' "${first_frames[@]}" | sort -n | awk '{a[NR] = $1} END {print a[int((NR + 1) / 2)]}')"
236
+ for f in "${first_frames[@]}"; do [ "$f" = "9999" ] && ff_never=$((ff_never + 1)); done
237
+ ff_txt="$(printf '%s ' "${first_frames[@]}" | sed 's/9999/never/g; s/ $//')"
238
+ printf '== first frame: %s -> median %s (budget 2000ms)%s ==\n' \
239
+ "$ff_txt" "$([ "$first_frame_ms" = "9999" ] && echo never || echo "$first_frame_ms")" \
240
+ "$([ "$ff_never" -gt 0 ] && printf ' [%s 次 never = 超过轮询预算]' "$ff_never")"
241
+ sleep 8 # warm-up: Ink startup, the first assembly, the first TTL cycle
242
+
243
+ if [ -n "$detail_flag" ]; then
244
+ tmux -L "$sock" send-keys -t "$sess:console" 4 2>/dev/null || true
245
+ sleep 1
246
+ tmux -L "$sock" send-keys -t "$sess:console" Enter 2>/dev/null || true
247
+ sleep 3
248
+ printf '== detail view open for the sampling window (page 4 + Enter; %s) ==\n' \
249
+ "$(tmux -L "$sock" capture-pane -p -t "$sess:console" 2>/dev/null | grep -c '详情' | tr -d ' ')"
250
+ fi
251
+
252
+ # P22/B2-B3: the project-settings view's own steady state (and its editor's) — the same red line.
253
+ if [ "${TEAM_PANEL_CPU_VIEW:-0}" = "1" ]; then
254
+ tmux -L "$sock" send-keys -t "$sess:console" , 2>/dev/null || true
255
+ sleep 0.8
256
+ tmux -L "$sock" send-keys -t "$sess:console" Down Down Down Down Down 2>/dev/null || true
257
+ sleep 0.6
258
+ tmux -L "$sock" send-keys -t "$sess:console" Enter 2>/dev/null || true
259
+ sleep 3
260
+ if [ "${TEAM_PANEL_CPU_EDIT:-0}" = "1" ]; then
261
+ tmux -L "$sock" send-keys -t "$sess:console" / 2>/dev/null || true
262
+ sleep 0.5
263
+ tmux -L "$sock" send-keys -l -t "$sess:console" 'TEAM_PULSE_NUDGE_GAP' 2>/dev/null || true
264
+ sleep 0.5
265
+ tmux -L "$sock" send-keys -t "$sess:console" Enter 2>/dev/null || true
266
+ sleep 0.9
267
+ tmux -L "$sock" send-keys -t "$sess:console" Enter 2>/dev/null || true
268
+ sleep 1.2
269
+ tmux -L "$sock" send-keys -l -t "$sess:console" '1200' 2>/dev/null || true
270
+ sleep 0.6
271
+ fi
272
+ printf '== project-settings view open for the sampling window (%s)%s ==\n' \
273
+ "$(tmux -L "$sock" capture-pane -p -t "$sess:console" 2>/dev/null | grep -c '项目设置' | tr -d ' ')" \
274
+ "$([ "${TEAM_PANEL_CPU_EDIT:-0}" = "1" ] && printf ' + an editor holding a typed draft (nothing written)')"
275
+ fi
276
+
277
+ if [ -n "$compose_flag" ]; then
278
+ tmux -L "$sock" send-keys -t "$sess:console" m 2>/dev/null || true
279
+ sleep 1
280
+ tmux -L "$sock" send-keys -l -t "$sess:console" 'a draft used to hold the compose line open for the red-line sample' 2>/dev/null || true
281
+ sleep 1
282
+ tmux -L "$sock" send-keys -t "$sess:console" C-v 2>/dev/null || true
283
+ sleep 1
284
+ printf '== compose line open for the sampling window (draft typed; %s) ==\n' \
285
+ "$(tmux -L "$sock" capture-pane -p -t "$sess:console" 2>/dev/null | grep -c 'Enter 发送' | tr -d ' ')"
286
+ fi
287
+
288
+ time_pid="$(tmux -L "$sock" list-panes -t "$sess:console" -F '#{pane_pid}' 2>/dev/null | head -1)"
289
+ pane_pid="$(pgrep -P "${time_pid:-0}" 2>/dev/null | head -1)"
290
+ if [ -z "$time_pid" ] || [ -z "$pane_pid" ]; then
291
+ printf 'panel-cpu: the console pane did not start (time=%s node=%s)\n' "$time_pid" "$pane_pid" >&2
292
+ exit 3
293
+ fi
294
+
295
+ cpu_ticks_of() { # <pid>
296
+ local f="/proc/$1/stat"
297
+ [ -r "$f" ] || { printf '0'; return; }
298
+ awk '{print $14 + $15}' "$f" 2>/dev/null || printf '0'
299
+ }
300
+
301
+ printf '== console CPU over %ss (pane %s → node %s, refresh %ss, hz %s; three equal sub-windows) ==\n' \
302
+ "$secs" "$time_pid" "$pane_pid" "$refresh" "$hz"
303
+ printf '== measured process: %s\n' "$(ps -o args= -p "$pane_pid" 2>/dev/null | cut -c1-120)"
304
+ printf '%s\n' " t ps_lifetime% pane_delta% tree_now%"
305
+ t0="$(date +%s%3N)"
306
+ pane_prev="$(cpu_ticks_of "$pane_pid")"
307
+ pane_total=0
308
+ # 三等分:每个子窗算自己的均值(同一个采样总时长,不额外加长),中位 of 3 就是判红用的数。
309
+ secs_third=$(( secs / 3 )); [ "$secs_third" -lt 1 ] && secs_third=1
310
+ sub_pcts=()
311
+ for _sub in 1 2 3; do
312
+ sub_end=$(( $(date +%s%3N) + secs_third * 1000 ))
313
+ sub_start="$(date +%s%3N)"
314
+ sub_ticks=0
315
+ while :; do
316
+ now="$(date +%s%3N)"
317
+ remain_ms=$(( sub_end - now ))
318
+ [ "$remain_ms" -le 0 ] && break
319
+ nap="$(awk -v r="$remain_ms" -v i="$(( interval * 1000 ))" 'BEGIN { printf "%.1f", (r < i ? r : i) / 1000 }')"
320
+ sleep "$nap"
321
+ now="$(date +%s%3N)"
322
+ pane_now="$(cpu_ticks_of "$pane_pid")"
323
+ dt=$(( now - sub_start )); [ "$dt" -gt 0 ] || dt=1
324
+ pane_pct="$(awk -v d="$((pane_now - pane_prev))" -v hz="$hz" -v ms="$dt" 'BEGIN{printf "%.2f", (d/hz)/(ms/1000)*100}')"
325
+ ps_pct="$(ps -o %cpu= -p "$pane_pid" 2>/dev/null | tr -d ' ' || echo '?')"
326
+ printf '%4ss %-12s %-11s %s\n' "$(( (now - t0) / 1000 ))" "$ps_pct" "$pane_pct" "$pane_pct"
327
+ sub_ticks=$(( sub_ticks + (pane_now - pane_prev) ))
328
+ pane_total=$(( pane_total + (pane_now - pane_prev) ))
329
+ pane_prev="$pane_now"
330
+ sub_start="$now"
331
+ done
332
+ sub_span=$(( $(date +%s%3N) - (sub_end - secs_third * 1000) ))
333
+ [ "$sub_span" -gt 0 ] || sub_span=$(( secs_third * 1000 ))
334
+ sub_pcts+=("$(awk -v d="$sub_ticks" -v hz="$hz" -v ms="$sub_span" 'BEGIN{printf "%.2f", (d/hz)/(ms/1000)*100}')")
335
+ done
336
+ span_ms=$(( $(date +%s%3N) - t0 ))
337
+
338
+ # Ask the console to quit so `/usr/bin/time` can report the tree total. `q` collapses the window into
339
+ # the headless loop (B3), which leaves the wrapper killed by the respawn and the summary unwritten —
340
+ # so the fixture signals the console process directly instead of relying on a key.
341
+ for _ in $(seq 1 20); do
342
+ kill -TERM "$pane_pid" 2>/dev/null || true
343
+ sleep 0.5
344
+ pgrep -P "$time_pid" >/dev/null 2>&1 || break
345
+ done
346
+ sleep 1
347
+ summary="$(grep -m1 'P12CPU' "$time_out" 2>/dev/null || true)"
348
+ printf '== /usr/bin/time (%s) ==\n%s\n' "$time_out" "${summary:-(no summary line)}"
349
+
350
+ pane_avg="$(printf '%s\n' "${sub_pcts[@]}" | sort -n | awk '{a[NR] = $1} END {print a[int((NR + 1) / 2)]}')"
351
+ pane_overall="$(awk -v d="$pane_total" -v hz="$hz" -v ms="$span_ms" 'BEGIN{printf "%.3f", (d/hz)/(ms/1000)*100}')"
352
+ tree_avg="?"
353
+ if [ -n "$summary" ]; then
354
+ user="$(sed -n 's/.*user=\([0-9.]*\).*/\1/p' <<< "$summary")"
355
+ sys="$(sed -n 's/.*sys=\([0-9.]*\).*/\1/p' <<< "$summary")"
356
+ elapsed="$(sed -n 's/.*elapsed=\([0-9.]*\).*/\1/p' <<< "$summary")"
357
+ if [ -n "$user" ] && [ -n "$sys" ] && [ -n "$elapsed" ]; then
358
+ tree_avg="$(awk -v u="$user" -v s="$sys" -v e="$elapsed" 'BEGIN{printf "%.3f", (u+s)/e*100}')"
359
+ fi
360
+ fi
361
+ printf '== pane CPU thirds: %s -> median %s%% (overall %s%% over %ss) of one core · reader tree %s%% ==\n' \
362
+ "$(printf '%s ' "${sub_pcts[@]}" | sed 's/ $//')" "$pane_avg" "$pane_overall" "$((span_ms / 1000))" "$tree_avg"
363
+
364
+ # ── P26/G3:前提先于判定。不成立就打印实测三数并退出 4(既不是通过也不是红)。
365
+ # 注意:前提一行在**采样前**就打过一次;这里再打一次结果行,让日志尾部自带结论。
366
+ # P68:每条结论都带上量测目标与被测 bundle 两个名字(读者不必翻源码就知道数字描述什么)。
367
+ pc_target="measured root $neut_root · bundle $panel"
368
+ if ! pc_premise >/dev/null 2>&1; then
369
+ printf '== load premise: loadavg %s > %s x %s cores -> SKIP (exit 4; the red line was not judged)\n' \
370
+ "$(pc_load)" "$PREMISE_FACTOR" "$(pc_cores)" >&2
371
+ ff_txt="never appeared" # 顶层语句:不能用 local(只在函数里合法)
372
+ [ -n "$first_frame_ms" ] && ff_txt="${first_frame_ms}ms"
373
+ printf 'panel-cpu: SKIP — first frame %s, pane CPU %s%%, loadavg %s over the premise (%s x %s cores); the 2000ms / 1%% thresholds are unchanged (%s)\n' \
374
+ "$ff_txt" "$pane_avg" "$(pc_load)" "$PREMISE_FACTOR" "$(pc_cores)" "$pc_target" >&2
375
+ exit 4
376
+ fi
377
+
378
+ if [ -z "$first_frame_ms" ]; then
379
+ printf 'panel-cpu: RED — the first frame never appeared within 2.1s of the window spawn (%s)\n' "$pc_target" >&2
380
+ rc=2
381
+ elif [ "$first_frame_ms" -ge 2000 ]; then
382
+ printf 'panel-cpu: RED — the interactive first frame took %sms (budget 2000ms, the 2s assembly line) (%s)\n' "$first_frame_ms" "$pc_target" >&2
383
+ rc=2
384
+ elif awk -v v="$pane_avg" 'BEGIN{exit !(v < 1)}'; then
385
+ printf 'panel-cpu: OK — the pane process is under 1%% of one core and the first frame is in budget (%s)\n' "$pc_target"
386
+ rc=0
387
+ else
388
+ printf 'panel-cpu: RED — the pane process is %s%% of one core (red line: <1%%) (%s)\n' "$pane_avg" "$pc_target" >&2
389
+ rc=2
390
+ fi
391
+ exit "$rc"