teamsmith 0.2.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/README.md +4 -4
  2. package/package.json +1 -1
  3. package/skills/teamsmith/CHANGELOG.md +69 -0
  4. package/skills/teamsmith/SKILL.md +20 -13
  5. package/skills/teamsmith/extension/team-inbox-watch.ts +5 -3
  6. package/skills/teamsmith/extension/team-notify.ts +37 -6
  7. package/skills/teamsmith/extension/team.ts +438 -0
  8. package/skills/teamsmith/references/config.md +39 -6
  9. package/skills/teamsmith/references/migration.md +197 -47
  10. package/skills/teamsmith/references/protocol.md +201 -30
  11. package/skills/teamsmith/references/troubleshooting.md +130 -10
  12. package/skills/teamsmith/references/workflows.md +36 -2
  13. package/skills/teamsmith/scripts/lib/cmd-agents.sh +318 -23
  14. package/skills/teamsmith/scripts/lib/cmd-bootstrap.sh +2 -2
  15. package/skills/teamsmith/scripts/lib/cmd-config.sh +349 -67
  16. package/skills/teamsmith/scripts/lib/cmd-draft.sh +4 -4
  17. package/skills/teamsmith/scripts/lib/cmd-help.sh +677 -0
  18. package/skills/teamsmith/scripts/lib/cmd-init.sh +157 -5
  19. package/skills/teamsmith/scripts/lib/cmd-interrupt.sh +461 -0
  20. package/skills/teamsmith/scripts/lib/cmd-meeting.sh +2 -25
  21. package/skills/teamsmith/scripts/lib/cmd-project.sh +30 -103
  22. package/skills/teamsmith/scripts/lib/cmd-reap.sh +277 -0
  23. package/skills/teamsmith/scripts/lib/cmd-reply.sh +3 -3
  24. package/skills/teamsmith/scripts/lib/cmd-review.sh +182 -32
  25. package/skills/teamsmith/scripts/lib/cmd-status.sh +234 -21
  26. package/skills/teamsmith/scripts/lib/cmd-update.sh +36 -7
  27. package/skills/teamsmith/scripts/lib/cmd-watch.sh +564 -46
  28. package/skills/teamsmith/scripts/lib/common.sh +1004 -245
  29. package/skills/teamsmith/scripts/lib/gate-lock.sh +582 -0
  30. package/skills/teamsmith/scripts/panel/draft-send.sh +11 -1
  31. package/skills/teamsmith/scripts/panel/panel.js +211 -211
  32. package/skills/teamsmith/scripts/panel/src/App.tsx +58 -21
  33. package/skills/teamsmith/scripts/panel/src/clipboard.ts +12 -5
  34. package/skills/teamsmith/scripts/panel/src/compose.ts +6 -3
  35. package/skills/teamsmith/scripts/panel/src/data.ts +51 -5
  36. package/skills/teamsmith/scripts/panel/src/layout.ts +209 -69
  37. package/skills/teamsmith/scripts/panel/src/main.tsx +37 -8
  38. package/skills/teamsmith/scripts/panel/src/strings/en.ts +39 -29
  39. package/skills/teamsmith/scripts/panel/src/strings/zh.ts +41 -31
  40. package/skills/teamsmith/scripts/panel/src/types.ts +28 -3
  41. package/skills/teamsmith/scripts/replies.mjs +4 -1
  42. package/skills/teamsmith/scripts/shim/killall +10 -0
  43. package/skills/teamsmith/scripts/shim/pgrep +10 -0
  44. package/skills/teamsmith/scripts/shim/pidof +10 -0
  45. package/skills/teamsmith/scripts/shim/pkill +10 -0
  46. package/skills/teamsmith/scripts/shim/signal-gate +108 -31
  47. package/skills/teamsmith/scripts/shim/tmux +18 -0
  48. package/skills/teamsmith/scripts/strings/commands.tsv +86 -0
  49. package/skills/teamsmith/scripts/strings/help.en.tsv +503 -0
  50. package/skills/teamsmith/scripts/strings/help.zh.tsv +489 -0
  51. package/skills/teamsmith/scripts/team +19 -6
  52. package/skills/teamsmith/templates/AGENTS.section.md.tmpl +8 -1
  53. package/skills/teamsmith/templates/config.sh.tmpl +20 -1
  54. package/skills/teamsmith/templates/pm-prompt.md.tmpl +21 -0
  55. package/skills/teamsmith/tests/README.md +31 -0
  56. package/skills/teamsmith/tests/bg-ledger-harness.mjs +464 -40
  57. package/skills/teamsmith/tests/bg-ledger.sh +168 -10
  58. package/skills/teamsmith/tests/checkout-shape-probe.sh +83 -54
  59. package/skills/teamsmith/tests/config-cli.sh +184 -32
  60. package/skills/teamsmith/tests/fixtures/delivery-truth-real/scenario.sh +7 -1
  61. package/skills/teamsmith/tests/fixtures/p287/lint-good.sh.in +3 -0
  62. package/skills/teamsmith/tests/fixtures/p287/lint-hardcoded.sh.in +3 -0
  63. package/skills/teamsmith/tests/fixtures/p287/lint-no-ns.sh.in +3 -0
  64. package/skills/teamsmith/tests/fixtures/p55/flip-p49.sh +18 -6
  65. package/skills/teamsmith/tests/flip-m33.sh +5 -3
  66. package/skills/teamsmith/tests/flip-p158.sh +2 -1
  67. package/skills/teamsmith/tests/flip-p308-skip-not-pass.sh +151 -0
  68. package/skills/teamsmith/tests/flip-p310-lock.sh +210 -0
  69. package/skills/teamsmith/tests/flip-p310-socket.sh +125 -0
  70. package/skills/teamsmith/tests/gate-guard.sh +52 -79
  71. package/skills/teamsmith/tests/help-surface.sh +1664 -0
  72. package/skills/teamsmith/tests/install-shape.sh +359 -22
  73. package/skills/teamsmith/tests/key-replies-pty.sh +9 -10
  74. package/skills/teamsmith/tests/key-replies-ui.sh +2 -8
  75. package/skills/teamsmith/tests/key-replies.sh +281 -28
  76. package/skills/teamsmith/tests/ledger-ban.sh +5 -4
  77. package/skills/teamsmith/tests/ledger-claim.sh +2 -1
  78. package/skills/teamsmith/tests/lib/bounded-spin.sh +90 -0
  79. package/skills/teamsmith/tests/lib/model-policy.sh +4 -0
  80. package/skills/teamsmith/tests/lib/model-routing-flips.py +51 -0
  81. package/skills/teamsmith/tests/lib/pty-wait.sh +21 -111
  82. package/skills/teamsmith/tests/lib/reply-fixture.sh +4 -9
  83. package/skills/teamsmith/tests/lib/section-guard.sh +316 -164
  84. package/skills/teamsmith/tests/lib/tmp-root.sh +139 -27
  85. package/skills/teamsmith/tests/lib/tmux-cap.sh +10 -1
  86. package/skills/teamsmith/tests/lib/tmux-iso.sh +31 -13
  87. package/skills/teamsmith/tests/loop-inventory.tsv +83 -77
  88. package/skills/teamsmith/tests/panel-b2.sh +430 -352
  89. package/skills/teamsmith/tests/panel-b3-stub.sh +112 -4
  90. package/skills/teamsmith/tests/panel-b3.sh +314 -62
  91. package/skills/teamsmith/tests/panel-choices.sh +11 -6
  92. package/skills/teamsmith/tests/panel-cpu.sh +43 -130
  93. package/skills/teamsmith/tests/panel-p21.sh +251 -265
  94. package/skills/teamsmith/tests/panel-snapshots.sh +41 -225
  95. package/skills/teamsmith/tests/panel-strings.mjs +33 -18
  96. package/skills/teamsmith/tests/perf.sh +187 -396
  97. package/skills/teamsmith/tests/routes.sh +440 -117
  98. package/skills/teamsmith/tests/seat-interrupt.sh +1012 -0
  99. package/skills/teamsmith/tests/seat-visibility.sh +675 -0
  100. package/skills/teamsmith/tests/section-guard.sh +13 -102
  101. package/skills/teamsmith/tests/section-needs-audit.sh +24 -7
  102. package/skills/teamsmith/tests/section-paths.tsv +32 -18
  103. package/skills/teamsmith/tests/section-select.sh +371 -19
  104. package/skills/teamsmith/tests/signal-gate.sh +249 -27
  105. package/skills/teamsmith/tests/signal-lint-legacy.txt +4 -1
  106. package/skills/teamsmith/tests/slash-team-e2e.sh +323 -0
  107. package/skills/teamsmith/tests/slash-team.sh +617 -0
  108. package/skills/teamsmith/tests/slice-coverage.sh +206 -0
  109. package/skills/teamsmith/tests/smoke.sh +3595 -788
  110. package/skills/teamsmith/tests/task-model-routing.sh +530 -15
  111. package/skills/teamsmith/tests/team-bg-stop.sh +18 -10
  112. package/skills/teamsmith/tests/tmp-hygiene.sh +782 -45
  113. package/skills/teamsmith/tests/tmux-identity-leak.sh +773 -0
  114. package/skills/teamsmith/tests/tmux-lint-legacy.txt +12 -18
  115. package/skills/teamsmith/tests/upgrade-recipe.sh +537 -0
  116. package/skills/teamsmith/tests/workflow-entry.sh +207 -0
  117. package/skills/teamsmith-init/SKILL.md +12 -12
  118. package/skills/teamsmith-init/references/bootstrap.md +3 -3
  119. package/skills/teamsmith/tests/flip-glue.sh +0 -162
  120. package/skills/teamsmith/tests/flip-m12-26c.sh +0 -129
  121. package/skills/teamsmith/tests/flip-m12.sh +0 -185
  122. package/skills/teamsmith/tests/flip-m16.sh +0 -166
  123. package/skills/teamsmith/tests/flip-m17.sh +0 -204
  124. package/skills/teamsmith/tests/flip-m34.sh +0 -96
  125. package/skills/teamsmith/tests/flip-m37.sh +0 -185
  126. package/skills/teamsmith/tests/flip-m4.3.sh +0 -375
  127. package/skills/teamsmith/tests/flip-m43.sh +0 -128
  128. package/skills/teamsmith/tests/flip-m45.sh +0 -244
  129. package/skills/teamsmith/tests/flip-m46.sh +0 -238
  130. package/skills/teamsmith/tests/flip-m48.sh +0 -304
  131. package/skills/teamsmith/tests/flip-m6.2.sh +0 -205
  132. package/skills/teamsmith/tests/flip-m6.3.sh +0 -283
  133. package/skills/teamsmith/tests/flip-m6.4.sh +0 -267
  134. package/skills/teamsmith/tests/flip-m6.5.sh +0 -113
  135. package/skills/teamsmith/tests/flip-m7.1.sh +0 -135
  136. package/skills/teamsmith/tests/flip-m7.2.sh +0 -321
  137. package/skills/teamsmith/tests/flip-p144.sh +0 -112
  138. package/skills/teamsmith/tests/flip-p156.sh +0 -133
  139. package/skills/teamsmith/tests/flip-p160.sh +0 -182
  140. package/skills/teamsmith/tests/flip-p171.sh +0 -249
  141. package/skills/teamsmith/tests/flip-p18.1.sh +0 -95
  142. package/skills/teamsmith/tests/flip-p20.sh +0 -286
  143. package/skills/teamsmith/tests/flip-p201.sh +0 -249
  144. package/skills/teamsmith/tests/flip-p210.sh +0 -239
  145. package/skills/teamsmith/tests/flip-p211.sh +0 -152
  146. package/skills/teamsmith/tests/flip-p217.sh +0 -288
  147. package/skills/teamsmith/tests/flip-p22.sh +0 -123
  148. package/skills/teamsmith/tests/flip-p23.sh +0 -239
  149. package/skills/teamsmith/tests/flip-p25.sh +0 -165
  150. package/skills/teamsmith/tests/flip-p71.sh +0 -184
  151. package/skills/teamsmith/tests/flip-p72.sh +0 -202
  152. package/skills/teamsmith/tests/load-experiment.sh +0 -290
  153. package/skills/teamsmith/tests/panel-cpu-premise.sh +0 -173
  154. package/skills/teamsmith/tests/panel-flip-m54.sh +0 -207
  155. package/skills/teamsmith/tests/panel-flip-p123.sh +0 -278
  156. package/skills/teamsmith/tests/panel-flip-p125.sh +0 -318
  157. package/skills/teamsmith/tests/panel-flip-p128.sh +0 -259
  158. package/skills/teamsmith/tests/panel-keyprobe-stub.sh +0 -41
  159. package/skills/teamsmith/tests/panel-keyprobe.sh +0 -82
  160. package/skills/teamsmith/tests/panel-knobs.sh +0 -83
  161. package/skills/teamsmith/tests/section-budgets.tsv +0 -154
  162. package/skills/teamsmith/tests/team-bg-flip.sh +0 -239
  163. package/skills/teamsmith/tests/team-inbox-watch-flip.sh +0 -191
@@ -509,11 +509,13 @@ fi
509
509
 
510
510
  # ---------------------------------------------------------------- flip-drop-pm(F-A)
511
511
  if want flip-drop-pm; then
512
- section "flip F-A · 从 known 里去掉独立 PM 模型 → known 断言必须红且点名 pm;恢复 → 绿"
512
+ section "flip F-A · 从 known 里去掉独立 PM 模型 → known 断言必须红且点名独立 PM;恢复 → 绿"
513
513
  ft="$tmp/flip-drop-pm"
514
514
  mkdir -p "$ft/skills/teamsmith"
515
515
  cp -a "$skill/scripts" "$ft/skills/teamsmith/scripts"
516
- cp -a "$skill/templates" "$skill/references" "$ft/skills/teamsmith/"
516
+ # P315:`team init` 现在要装 `/team` 扩展(源 = <skill>/extension/team.ts),夹具的拷贝集合要跟上;
517
+ # 少拷一层时 `new_proj` 里的 init 直接退出、走查拿不到结论,红侧就是假红。
518
+ cp -a "$skill/templates" "$skill/references" "$skill/extension" "$ft/skills/teamsmith/"
517
519
  python3 - "$ft/skills/teamsmith/scripts/lib/cmd-config.sh" <<'PYPATCH'
518
520
  import sys
519
521
  p = sys.argv[1]
@@ -535,10 +537,12 @@ PYPATCH
535
537
  rc_red=$?
536
538
  TEAM_CHOICES_TREE="$tree" bash "$here/panel-choices.sh" known > "$tmp/flip-drop-pm-green.log" 2>&1
537
539
  rc_green=$?
538
- if [ "$rc_red" -ne 0 ] && grep -a '✗' "$tmp/flip-drop-pm-red.log" | grep -qi 'pm'; then
539
- ok "F-A:去掉 PM 的 known 解析后断言红且点名 pm(rc=$rc_red)"
540
+ # P315:匹配口径收窄到正文里的「独立 PM」——原来是 `grep -qi 'pm'`,而红日志里的临时路径就叫
541
+ # `teamsmith-panel-choice-pm_skills-…`,于是 `team init` 在夹具里当场失败也能把这条判成 ok(假绿)。
542
+ if [ "$rc_red" -ne 0 ] && grep -a '✗' "$tmp/flip-drop-pm-red.log" | grep -qF '独立 PM'; then
543
+ ok "F-A:去掉 PM 的 known 解析后断言红且点名独立 PM(rc=$rc_red)"
540
544
  else
541
- bad "F-A:去掉 PM 的 known 解析后断言没红/没点名 pm(rc=$rc_red)"
545
+ bad "F-A:去掉 PM 的 known 解析后断言没红/没点名独立 PM(rc=$rc_red)"
542
546
  fi
543
547
  [ "$rc_green" -eq 0 ] && ok "F-A:恢复真树后 known 断言绿" || bad "F-A:真树也红了(rc=$rc_green)"
544
548
  printf ' --- 红侧尾部 ---\n'
@@ -551,7 +555,8 @@ if want flip-suggest; then
551
555
  ft="$tmp/flip-suggest"
552
556
  mkdir -p "$ft/skills/teamsmith"
553
557
  cp -a "$skill/scripts" "$ft/skills/teamsmith/scripts"
554
- cp -a "$skill/templates" "$skill/references" "$ft/skills/teamsmith/"
558
+ # P315:与 F-A 同理 —— `team init` 要 extension/team.ts 才能装完,少拷一层就是夹具坏掉(走查 rc=3)。
559
+ cp -a "$skill/templates" "$skill/references" "$skill/extension" "$ft/skills/teamsmith/"
555
560
  flip_cfg="$ft/skills/teamsmith/scripts/lib/cmd-config.sh"
556
561
  cp -a "$cmd_config" "$flip_cfg"
557
562
  python3 - "$flip_cfg" <<'PY'
@@ -1,44 +1,22 @@
1
1
  #!/usr/bin/env bash
2
- # CPU red-line fixture (pulse-console B1, tasks.md 1.5).
2
+ # CPU / first-frame **reference readings** (pulse-console B1, tasks.md 1.5; P316).
3
3
  #
4
4
  # bash skills/teamsmith/tests/panel-cpu.sh [tree] [seconds]
5
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
6
+ # TEAM_PANEL_CPU_DETAIL=1 bash ... # open the markdown detail view
7
+ # TEAM_PANEL_CPU_COMPOSE=1 bash ... # hold the compose line open
8
+ # TEAM_PANEL_CPU_VIEW=1 bash ... # keep the project-settings view open
9
9
  # TEAM_PANEL_CPU_VIEW=1 TEAM_PANEL_CPU_EDIT=1 bash ... # …and an editor holding a typed draft
10
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**。
11
+ # 用户裁定(2026-10-19,第二条):**性能只能是参考指标,不能作为阻塞**。本夹具照旧测量首帧(三次独立
12
+ # spawn 的中位)与窗格 CPU(采样窗三等分的中位),样本与树 CPU 图都打印出来,行首是「· 参考」——
13
+ # **没有阈值判定、没有负载前提、没有 SKIP**:机器多忙都照测,数字是给人看的。
14
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)。
15
+ # Exit: 0 测到了(读数照打,不管数值多大)
16
+ # 3 搭建失败(没有 tmux / node / 面板 bundle / 窗格没起来)
22
17
  #
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> 在面板进程启动前睡一觉(造一个真越线的首帧)
18
+ # 环境姿态(M51 保留):树 CPU 图用 `/usr/bin/time -o/-f` 读;缺这个工具时只打印一行「读不到」,
19
+ # 不影响首帧/窗格 CPU 的读数,也不改变退出码(它是附带读数,本来就不是判定依据)。
42
20
  set -uo pipefail
43
21
 
44
22
  here="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
@@ -49,60 +27,19 @@ here="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
49
27
  tree="${1:-$(cd -P "$here/../../.." && pwd)}"
50
28
  secs="${2:-${TEAM_PANEL_CPU_SECS:-60}}"
51
29
 
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
30
+ # ── 机器读数(P316:只打印,不判绿红,不设前提)──────────────────────────────────────────
31
+ pc_load() { cut -d' ' -f1 /proc/loadavg 2>/dev/null || printf '?'; }
32
+ pc_cores() { nproc 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null || printf '0'; }
33
+ pc_reference_machine() {
34
+ printf '· 参考 机器:loadavg %s · %s 核 · 采样窗 %ss(本夹具不判绿红)\n' \
35
+ "$(pc_load)" "$(pc_cores)" "$secs"
85
36
  }
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
37
  refresh="${TEAM_PANEL_CPU_REFRESH:-3}"
100
38
  interval=5
101
39
  sock="p12cpu-$$"
102
40
  sess="p12cpu-$$"
103
41
  js="${TEAM_JS_BIN:-$(command -v node || true)}"
104
42
  [ -n "$js" ] || js="$(command -v bun || true)"
105
- rc=3
106
43
 
107
44
  cleanup() {
108
45
  # P162:收尾先证明私有 socket 生效(不成立就拒绝;cleanup 里不许 exit)
@@ -128,8 +65,8 @@ for cand in /usr/bin/time "$(command -v time || true)"; do
128
65
  [ -x "$cand" ] && { time_bin="$cand"; break; }
129
66
  done
130
67
  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
68
+ printf '· 参考 面板读数:没测到(缺 GNU time = /usr/bin/time;树 CPU 图是附带读数,本环境没有它)\n' >&2
69
+ exit 0
133
70
  fi
134
71
 
135
72
  panel="$tree/skills/teamsmith/scripts/panel/panel.js"
@@ -158,7 +95,8 @@ printf '== measured project root: %s (neutral fixture project — not the caller
158
95
  printf '== console bundle under test: %s (tree under test %s) ==\n' "$panel" "$tree"
159
96
 
160
97
  hz="$(getconf CLK_TCK 2>/dev/null || echo 100)"
161
- time_out="$(mktemp "${TMPDIR:-/tmp}/p12cpu.XXXXXX")"
98
+ team_tmp_root_prepare >/dev/null 2>&1 || true
99
+ time_out="$(mktemp "$(team_tmp_root)/teamsmith-p12cpu.$(tmp_root_ns).XXXXXX")"
162
100
  # TEAM_PANEL_CPU_PAGE=<1|2|3|4> parks the measured console on that page (the board page's kanban is
163
101
  # the heaviest layout, so the red line is checked there too — P18/B2 item 6.4).
164
102
  page_flag=""
@@ -191,21 +129,10 @@ if [ -n "$compose_flag" ]; then
191
129
  compose_env="PATH=$fakebin:\$PATH "
192
130
  fi
193
131
  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
132
  tmux -L "$sock" new-session -d -s "$sess" -x 140 -y 34 -c "$neut_root" "sleep 600"
206
- pc_premise || true # 前提一行先打(不成立也照测,因为退出 4 时要把实测三个数一起打出来)
133
+ pc_reference_machine # 参考机器读数(不判绿红)
207
134
  # 首帧:三次独立 spawn 各量一次「窗口创建 → 第一帧可见」,取中位(中位 of 3)。
208
- # `never` = 轮询预算内没出现(> 2000ms 的一种形态),记成 9999 参与中位,但打印时保留 `never`。
135
+ # `never` = 300s 轮询视界内没出现(读数的一种形态),记成 9999 参与中位,但打印时保留 `never`。
209
136
  first_frames=()
210
137
  ff_never=0
211
138
  measure_first_frame() { # → 毫秒数(没出现 → 9999)
@@ -215,14 +142,15 @@ measure_first_frame() { # → 毫秒数(没出现 → 9999)
215
142
  t0="$(date +%s%3N)"
216
143
  tmux -L "$sock" new-window -d -t "$sess" -n console -c "$neut_root" "$pane_cmd" 2>/dev/null || true
217
144
  # F8: the interactive first frame is measured, not promised — poll the pane for the title band.
218
- for _ in $(seq 1 20); do
145
+ # P316:上限 300s(只防死等);首帧多久都照打,不判快慢。
146
+ for _ in $(seq 1 3000); do
219
147
  sleep 0.1
220
148
  if tmux -L "$sock" capture-pane -p -t "$sess:console" 2>/dev/null | grep -q 'teamsmith pulse'; then
221
149
  ms=$(( $(date +%s%3N) - t0 )); break
222
150
  fi
223
151
  done
224
152
  if [ -z "$ms" ]; then
225
- sleep 1 # one last look before judging it `never`
153
+ sleep 1 # 最后一次确认(没等到才记 never)
226
154
  tmux -L "$sock" capture-pane -p -t "$sess:console" 2>/dev/null | grep -q 'teamsmith pulse' \
227
155
  && ms=$(( $(date +%s%3N) - t0 ))
228
156
  fi
@@ -235,9 +163,9 @@ done
235
163
  first_frame_ms="$(printf '%s\n' "${first_frames[@]}" | sort -n | awk '{a[NR] = $1} END {print a[int((NR + 1) / 2)]}')"
236
164
  for f in "${first_frames[@]}"; do [ "$f" = "9999" ] && ff_never=$((ff_never + 1)); done
237
165
  ff_txt="$(printf '%s ' "${first_frames[@]}" | sed 's/9999/never/g; s/ $//')"
238
- printf '== first frame: %s -> median %s (budget 2000ms)%s ==\n' \
166
+ printf '· 参考 首帧:%s -> 中位 %s%s\n' \
239
167
  "$ff_txt" "$([ "$first_frame_ms" = "9999" ] && echo never || echo "$first_frame_ms")" \
240
- "$([ "$ff_never" -gt 0 ] && printf ' [%s 次 never = 超过轮询预算]' "$ff_never")"
168
+ "$([ "$ff_never" -gt 0 ] && printf ' [%s 次 never = 超过等待视界]' "$ff_never")"
241
169
  sleep 8 # warm-up: Ink startup, the first assembly, the first TTL cycle
242
170
 
243
171
  if [ -n "$detail_flag" ]; then
@@ -285,8 +213,13 @@ if [ -n "$compose_flag" ]; then
285
213
  "$(tmux -L "$sock" capture-pane -p -t "$sess:console" 2>/dev/null | grep -c 'Enter 发送' | tr -d ' ')"
286
214
  fi
287
215
 
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)"
216
+ # 窗格进程树就绪(上限 300s:只防死等,不判启动快慢;P316)
217
+ for _i in $(seq 1 3000); do
218
+ time_pid="$(tmux -L "$sock" list-panes -t "$sess:console" -F '#{pane_pid}' 2>/dev/null | head -1)"
219
+ pane_pid="$(ps -o pid= --ppid "${time_pid:-0}" 2>/dev/null | head -1 | tr -d ' ')" # ps 而不是 pgrep:pgrep 是团队 shim(身份护栏),夹具里读不到子进程
220
+ [ -n "$time_pid" ] && [ -n "$pane_pid" ] && break
221
+ sleep 0.1
222
+ done
290
223
  if [ -z "$time_pid" ] || [ -z "$pane_pid" ]; then
291
224
  printf 'panel-cpu: the console pane did not start (time=%s node=%s)\n' "$time_pid" "$pane_pid" >&2
292
225
  exit 3
@@ -358,34 +291,14 @@ if [ -n "$summary" ]; then
358
291
  tree_avg="$(awk -v u="$user" -v s="$sys" -v e="$elapsed" 'BEGIN{printf "%.3f", (u+s)/e*100}')"
359
292
  fi
360
293
  fi
361
- printf '== pane CPU thirds: %s -> median %s%% (overall %s%% over %ss) of one core · reader tree %s%% ==\n' \
294
+ printf '· 参考 窗格 CPU 三等分:%s -> 中位 %s%%(整窗 %s%%,%ss)· 读进程树 %s%%\n' \
362
295
  "$(printf '%s ' "${sub_pcts[@]}" | sed 's/ $//')" "$pane_avg" "$pane_overall" "$((span_ms / 1000))" "$tree_avg"
363
296
 
364
- # ── P26/G3:前提先于判定。不成立就打印实测三数并退出 4(既不是通过也不是红)。
365
- # 注意:前提一行在**采样前**就打过一次;这里再打一次结果行,让日志尾部自带结论。
366
- # P68:每条结论都带上量测目标与被测 bundle 两个名字(读者不必翻源码就知道数字描述什么)。
297
+ # ── P316:参考读数,不是判定 ────────────────────────────────────────────────────────────
367
298
  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"
299
+ ff_txt="never appeared"
300
+ [ -n "$first_frame_ms" ] && ff_txt="${first_frame_ms}ms"
301
+ printf '· 参考 首帧:%s(3 次独立 spawn 的中位)| 窗格 CPU:%s%%(三等分中位)| 树 CPU:%s%%(%s)\n' \
302
+ "$ff_txt" "$pane_avg" "$tree_avg" "$pc_target"
303
+ printf '· 参考 机器:loadavg %s · %s 核 · 采样窗 %ss\n' "$(pc_load)" "$(pc_cores)" "$secs"
304
+ exit 0