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
@@ -91,7 +91,7 @@ team_watch_reexec_if_stale() { # <启动指纹> <子命令> [子命令参数…]
91
91
  # 窗口里的巡检进程是什么时候起来的(watchdog-status 用它报「代码快照过旧」)。
92
92
  team_watch_process_start_epoch() { # <tmux 目标> → 进程启动的 epoch 秒(判不出 → 空)
93
93
  local pid et
94
- pid="$(tmux display-message -p -t "$1" '#{pane_pid}' 2>/dev/null | head -1 || true)"
94
+ pid="$(team_tmux display-message -p -t "$1" '#{pane_pid}' 2>/dev/null | head -1 || true)"
95
95
  case "${pid:-}" in ''|*[!0-9]*) return 0 ;; esac
96
96
  et="$(ps -o etimes= -p "$pid" 2>/dev/null | tr -d ' ' || true)"
97
97
  case "${et:-}" in ''|*[!0-9]*) return 0 ;; esac
@@ -123,16 +123,189 @@ team_pm_same_dir_warn() {
123
123
  team_dim " 建议:先退出它;或者在干净的新会话里跑 $TEAM_CLI up --fresh-pm(本次新开一场对话)"
124
124
  }
125
125
 
126
+
127
+ # ---------------------------------------------------------------- 启动自愈(P261 · startup-self-heal)
128
+ # 落点分工(design §1):纯决策在 cmd-config.sh(team_config_migration_*),这里只做编排:打印、备份、
129
+ # 复用同一个写入器、exec 自己、身份预告、版本提示。一个字节都不写的承诺由纯决策层保证。
130
+ team_up_migration_rows_text() { # 逐键 before → after(值可见)
131
+ local row old_key old_val new_key new_val note
132
+ while IFS='|' read -r old_key old_val new_key new_val note; do
133
+ [ -n "$old_key" ] || continue
134
+ printf ' %s %s → %s %s%s\n' "$old_key" "$old_val" "$new_key" "$new_val" "${note:+($note)}"
135
+ done <<< "${TEAM_MIGRATION_ROWS:-}"
136
+ }
137
+ team_up_migration_backup_line() { # 备份与还原命令(同一份文本给成功路径与失败路径)
138
+ local backup="$1" cfg="$2"
139
+ printf ' 备份:%s\n 还原:cp %q %q\n' "$backup" "$backup" "$cfg"
140
+ }
141
+ # 迁移可用(action=apply)时的逐键表 + 备份路径 + 为什么。
142
+ team_up_migration_preview() { # <cfg> <备份路径> → stdout 预告块
143
+ printf 'i 检测到旧形状配置(迁移 %s:形状 %s → %s,%s 引入);值一个都不改:\n' \
144
+ "${TEAM_MIGRATION_ROW:-m1}" "${TEAM_MIGRATION_FROM:-1}" "${TEAM_MIGRATION_TO:-2}" "${TEAM_MIGRATION_INTRODUCED:-0.2.0}"
145
+ team_up_migration_rows_text
146
+ team_up_migration_backup_line "$2" "$1"
147
+ [ -z "$TEAM_MIGRATION_NOTES" ] || printf ' 推导说明:%s\n' "$TEAM_MIGRATION_NOTES"
148
+ printf ' 为什么:0.2.0 起派单按任务类别选模型(brief 的 category: 行);这两个退休键不再被读取。\n'
149
+ }
150
+ # 迁移决策与编排(design §1 的 1/1a/1b/1c)。0 = 继续;1 = 拒绝(已打印);10 = 已在 print 下预告了迁移
151
+ team_up_migration_step() { # <print|no-migrate|real> <argv…>
152
+ local mode="$1"; shift
153
+ local cfg; cfg="$(team_config_contract_path)" || return 1
154
+ if ! team_config_migration_plan "$cfg"; then
155
+ team_err "启动迁移拒绝(${TEAM_MIGRATION_SHAPE:-unknown}):${TEAM_MIGRATION_WHY}"
156
+ team_dim " 一个字节都没写(不写配置、不建备份、不写审计)" >&2
157
+ if [ -n "${TEAM_MIGRATION_PARTIAL_MAP:-}" ]; then
158
+ printf ' 其余已推导出的对可以先手工提交(非法那一对用占位符):\n %s config upgrade-models \\\n --task-models '"'"'%s'"'"' \\\n --pm-model '"'"'<独立模型>'"'"' --dry-run\n' \
159
+ "$TEAM_CLI" "$TEAM_MIGRATION_PARTIAL_MAP"
160
+ fi
161
+ team_dim " 手工路线:$TEAM_CLI config upgrade-models --task-models '<完整映射>' --pm-model '<独立模型>' --dry-run" >&2
162
+ return 1
163
+ fi
164
+ [ "$TEAM_MIGRATION_ACTION" = 'apply' ] || return 0
165
+ local ts; ts="$(date -u +%Y%m%dT%H%M%SZ)"
166
+ local backup="$TEAM_MIGRATION_BACKUP_HINT"
167
+ [ -n "$backup" ] || backup="$(team_config_backup_dir)/$(team_config_backup_name "$cfg" "$ts")"
168
+ if [ "$mode" = 'print' ]; then
169
+ team_up_migration_preview "$cfg" "$backup"
170
+ return 10
171
+ fi
172
+ if [ "$mode" = 'no-migrate' ]; then
173
+ team_err "--no-migrate:不写盘,也不启动(旧形状配置还在)"
174
+ printf ' 修法(建议·按你现在的配置推导,类别名可以改):\n %s config upgrade-models \\\n --task-models '"'"'%s'"'"' \\\n --pm-model '"'"'%s'"'"' --dry-run\n' \
175
+ "$TEAM_CLI" "$TEAM_MIGRATION_MAP" "$TEAM_MIGRATION_PM"
176
+ [ -z "$TEAM_MIGRATION_NOTES" ] || printf ' (推导说明:%s)\n' "$TEAM_MIGRATION_NOTES"
177
+ team_dim " 手工事务路线(去掉 --no-migrate 就是自动):$TEAM_CLI config upgrade-models --task-models '<完整映射>' --pm-model '<独立模型>' --yes" >&2
178
+ return 1
179
+ fi
180
+ # 真实迁移:计划 → 备份 → 同一个写入器(actor=up-migration,附形状号)→ 结果/还原 → exec 自己
181
+ team_up_migration_preview "$cfg" "$backup"
182
+ mkdir -p "$TEAM_STATE_DIR" 2>/dev/null || true
183
+ local fp; fp="$(team_config_fingerprint "$cfg")"
184
+ if ! backup="$(team_config_backup_write "$cfg" "$ts")"; then
185
+ team_err "迁移中止:备份写不出来($backup)—— 配置一个字节都没动"
186
+ return 1
187
+ fi
188
+ local rc=0
189
+ team_with_lock "config:$cfg" team_config_locked_call team_config_upgrade_transaction \
190
+ "$cfg" "$TEAM_MIGRATION_MAP" "$TEAM_MIGRATION_PM" 0 "$fp" 'up-migration' \
191
+ "TEAM_CONFIG_VERSION=$TEAM_CONFIG_SHAPE_CURRENT" || rc=$?
192
+ if [ "$rc" != 0 ]; then
193
+ team_err "迁移写入失败(rc=$rc):配置保持原样(或已由事务回滚)"
194
+ team_up_migration_backup_line "$backup" "$cfg" >&2
195
+ return 1
196
+ fi
197
+ team_up_migration_backup_line "$backup" "$cfg"
198
+ team_ok "迁移完成(审计已写):重新执行 up 读取新配置"
199
+ export TEAM_MIGRATION_BACKUP="$backup"
200
+ exec bash "$TEAM_SKILL_DIR/scripts/team" up "$@"
201
+ }
202
+ # 迁移之后仍失败:信息里带上本次迁移的备份与还原命令(design §5;--print 不设置该变量)。
203
+ team_up_backup_note() {
204
+ [ -n "${TEAM_MIGRATION_BACKUP:-}" ] || return 0
205
+ team_dim " 本次迁移的还原命令:cp $(printf '%q' "$TEAM_MIGRATION_BACKUP") $(printf '%q' "$TEAM_CONFIG")" >&2
206
+ }
207
+ # --print 的身份预告(design §7):不写盘;缺记录 → 打印将要登记的那一行;不一致 → 两边值 + 拒绝。
208
+ team_pm_identity_preview() { # → 0 = 一致/将登记;1 = 不一致(已打印两边值)
209
+ local want_model want_resume
210
+ want_model="$(team_pm_model_resolve)"; want_resume="$(team_pm_resume_key)"
211
+ if [ ! -f "$TEAM_STATE_DIR/pm-launch.env" ]; then
212
+ printf 'i 身份预告:此前没有启动记录;这次启动会登记 model=%s resume_key=%s mode=%s(要换 PM 模型必须 --fresh-pm)\n' \
213
+ "$want_model" "$want_resume" "$(case "$(team_pm_continuity)" in continued:*) printf continued ;; *) printf fresh ;; esac)"
214
+ return 0
215
+ fi
216
+ if ! team_pm_metadata_load; then
217
+ team_err "身份预告:已有记录不可读/不属于本项目本窗口/是旧版本(${TEAM_IDENTITY_DIAGNOSTIC:-unreadable})→ 启动时会拒绝"
218
+ return 1
219
+ fi
220
+ if [ "$TEAM_PM_SELECTED_MODEL" != "$want_model" ] || [ "$TEAM_PM_RECORDED_RESUME_KEY" != "$want_resume" ]; then
221
+ team_err "身份预告:recorded model=$TEAM_PM_SELECTED_MODEL(suffix 显式)≠ 现在 model=$want_model;recorded resume_key=$TEAM_PM_RECORDED_RESUME_KEY ≠ 现在 resume_key=$want_resume → 启动时会拒绝(--fresh-pm 或 --adopt-pm-identity --yes)"
222
+ return 1
223
+ fi
224
+ printf 'i 身份预告:记录与当前解析一致(model=%s resume_key=%s)\n' "$want_model" "$want_resume"
225
+ return 0
226
+ }
227
+
228
+ # 版本提示(design §8):只在 team up 真实运行时触发;有界 ≤2s、缓存 24h、除「本地落后」外一律静默、不改 rc。
229
+ team_version_newer() { # <local> <published> → 0 = published 的数字段严格更大
230
+ local -a ls ps; local i a b
231
+ IFS=. read -r -a ls <<< "${1%%[-+]*}"
232
+ IFS=. read -r -a ps <<< "${2%%[-+]*}"
233
+ for i in 0 1 2; do
234
+ a="${ls[$i]:-0}"; b="${ps[$i]:-0}"
235
+ case "$a$b" in *[!0-9]*) return 1 ;; esac
236
+ [ "$b" -gt "$a" ] && return 0
237
+ [ "$b" -lt "$a" ] && return 1
238
+ done
239
+ return 1
240
+ }
241
+ team_update_lookup() { # → stdout npm 上的最新版本(严格 ^[0-9]+.[0-9]+.[0-9]+$);查不到 → 空
242
+ command -v npm >/dev/null 2>&1 || return 0
243
+ local tmp rc=0 pid i=0 out
244
+ team_tmp_root_prepare >/dev/null 2>&1 || true
245
+ team_tmp_root_prepare >/dev/null 2>&1 || true
246
+ tmp="$(mktemp "$(team_tmp_root)/teamsmith-npm.$(team_project_ns).XXXXXX" 2>/dev/null)" || return 0
247
+ if command -v timeout >/dev/null 2>&1; then
248
+ timeout 2 npm view teamsmith version --registry https://registry.npmjs.org >"$tmp" 2>/dev/null || rc=$?
249
+ else
250
+ npm view teamsmith version --registry https://registry.npmjs.org >"$tmp" 2>/dev/null &
251
+ pid=$!
252
+ while [ "$i" -lt 20 ]; do kill -0 "$pid" 2>/dev/null || break; sleep 0.1; i=$((i+1)); done
253
+ if kill -0 "$pid" 2>/dev/null; then kill -TERM "$pid" 2>/dev/null || true; rc=124; fi
254
+ wait "$pid" 2>/dev/null || { [ "$rc" != 0 ] || rc=1; }
255
+ fi
256
+ out="$(tr -d '[:space:]' < "$tmp" 2>/dev/null || true)"
257
+ rm -f "$tmp"
258
+ [ "$rc" = 0 ] || return 0
259
+ case "$out" in
260
+ [0-9]*.[0-9]*.[0-9]*) case "$out" in *[!0-9.]*) return 0 ;; esac; printf '%s\n' "$out" ;;
261
+ *) return 0 ;;
262
+ esac
263
+ }
264
+ team_update_cache_write() { # <epoch> <latest|-> <local>(原子写;失败也不影响启动)
265
+ local f="$TEAM_STATE_DIR/update-check.env" tmp
266
+ mkdir -p "$TEAM_STATE_DIR" 2>/dev/null || return 0
267
+ tmp="$f.tmp.$$"
268
+ if printf 'CHECKED_AT=%s\nLATEST=%s\nLOCAL=%s\n' "$1" "$2" "$3" > "$tmp" 2>/dev/null; then
269
+ mv -f "$tmp" "$f" 2>/dev/null || rm -f "$tmp"
270
+ else
271
+ rm -f "$tmp"
272
+ fi
273
+ return 0
274
+ }
275
+ team_update_check_notice() { # 真实 up 的版本提示:打一行或什么都不打;任何失败都不改 rc
276
+ [ "${TEAM_UPDATE_CHECK:-1}" = "0" ] && return 0
277
+ local cache="$TEAM_STATE_DIR/update-check.env" now checked='' latest='' local_v="${TEAM_VERSION:-0.0.0}"
278
+ now="$(date +%s)"
279
+ if [ -f "$cache" ]; then
280
+ checked="$(sed -n 's/^CHECKED_AT=//p' "$cache" 2>/dev/null | head -1)"
281
+ latest="$(sed -n 's/^LATEST=//p' "$cache" 2>/dev/null | head -1)"
282
+ fi
283
+ case "$checked" in ''|*[!0-9]*) checked=0 ;; esac
284
+ if [ "$checked" = 0 ] || [ $((now - checked)) -ge 86400 ] || [ -z "$latest" ]; then
285
+ latest="$(team_update_lookup)"
286
+ [ -n "$latest" ] || latest='-'
287
+ team_update_cache_write "$now" "$latest" "$local_v"
288
+ fi
289
+ [ "$latest" = '-' ] && return 0
290
+ team_version_newer "$local_v" "$latest" || return 0
291
+ printf 'i 本地 teamsmith %s,npm 上已有 %s(工具从不自己安装):npm i -g teamsmith@%s --registry https://registry.npmjs.org && bash "$(npm root -g)/teamsmith/install.sh"\n' \
292
+ "$local_v" "$latest" "$latest"
293
+ return 0
294
+ }
295
+
126
296
  # ---------------------------------------------------------------- team up
127
297
  # 人来跑的工具:把 PM 恢复起来。
128
298
  # agent 归 PM 管,所以默认不动 agent;要顺手把停了的 agent 也续起来就加 --agents。
129
299
  team_cmd_up() {
130
- local with_agents=0 show_prompt=0 pm_fail=0 pm_fresh=0
300
+ local with_agents=0 show_prompt=0 pm_fail=0 pm_fresh=0 no_migrate=0 adopt_pm=0 register=0
301
+ local -a up_argv=("$@")
131
302
  while [ $# -gt 0 ]; do
132
303
  case "$1" in
133
304
  --agents) with_agents=1; shift ;;
134
305
  --fresh-pm) pm_fresh=1; shift ;;
135
306
  --print) show_prompt=1; shift ;;
307
+ --no-migrate) no_migrate=1; shift ;;
308
+ --adopt-pm-identity) adopt_pm=1; shift ;;
136
309
  -*) team_usage_die "up: 未知参数 $1" ;;
137
310
  *) team_usage_die "up: 多余参数 $1" ;;
138
311
  esac
@@ -141,14 +314,40 @@ team_cmd_up() {
141
314
  # 导出给同一次启动里的 team_pm_pi_args / team_pm_launch_cmd / team_pm_continuity。
142
315
  [ "$pm_fresh" = "1" ] && export TEAM_PM_FRESH_LAUNCH=1
143
316
 
317
+ # P261 ①(design §1):迁移决策在所有其它步骤**之前**(身份守卫之前、建场地之前、拉起 PM 之前)。
318
+ local up_mode=real mig=0
319
+ [ "$show_prompt" = "1" ] && up_mode=print
320
+ [ "$no_migrate" = "1" ] && up_mode=no-migrate
321
+ # 建议命令里打印的是**将要使用的**备份路径(真跑时才创建);plan 已就绪时先算出来。
322
+ TEAM_MIGRATION_BACKUP_HINT=''
323
+ team_up_migration_step "$up_mode" "${up_argv[@]}" || mig=$?
324
+ if [ "$mig" = 1 ]; then
325
+ team_up_backup_note
326
+ return 1
327
+ fi
328
+
144
329
  if [ "$show_prompt" = "1" ]; then
145
- team_pm_identity_guard || return 1
330
+ if [ "$mig" = 10 ]; then
331
+ # 旧配置的 --print:只预告(逐键表 + 备份路径 + 身份预告),不打印基于**未迁移**值的启动命令,
332
+ # 也不为预览开 guard 投影通道(design §6 裁定点 7);迁移可用时退 0。
333
+ team_pm_identity_preview || true
334
+ printf '\n(迁移后重跑 %s up --print 才有完整启动预览;迁移可用时 --print 退 0)\n' "$TEAM_CLI"
335
+ printf '(本可检查 npm 上的新版本:--print 下不联网、不写缓存)\n'
336
+ return 0
337
+ fi
338
+ if ! team_pm_identity_guard; then
339
+ # --print 不写盘(design §6/§7):adopt 的写入只发生在真实启动路径上。
340
+ [ "$adopt_pm" != 1 ] || team_dim " --print 不写盘:--adopt-pm-identity 的写入只发生在真实启动时(去掉 --print 重跑)" >&2
341
+ team_up_backup_note; return 1
342
+ fi
343
+ team_pm_identity_preview || true
146
344
  team_pm_prompt
147
345
  # P36(A):--print 是「看清这一次启动」的地方 —— 会话判定(fresh:/continued:/lost:)与渲染出的
148
346
  # 完整命令都要看得见、能断言(有没有 -c 一眼可见)。不写任何状态、不动 tmux。
149
347
  printf '\n—— 本次启动 ——\n会话判定:%s\n完整命令:%s\n' \
150
348
  "$(team_pm_continuity)" \
151
349
  "$(team_pm_launch_cmd "$(team_pm_prompt_file)" "$(team_pm_spawn_file)")"
350
+ printf '(本可检查 npm 上的新版本:--print 下不联网、不写缓存)\n'
152
351
  return 0
153
352
  fi
154
353
 
@@ -158,12 +357,27 @@ team_cmd_up() {
158
357
  team_hdr "teamsmith up · $TEAM_PROJECT(只负责 PM)"
159
358
 
160
359
  # Running/starting PM is never restarted by a policy edit. Otherwise guard BEFORE windows.
161
- case "$(team_pm_state)" in running:*|starting:*) ;; *) team_pm_identity_guard || return 1 ;; esac
360
+ case "$(team_pm_state)" in
361
+ running:*|starting:*)
362
+ # P261:adopt 声明的是**这次续跑**的身份,而运行中的 PM 的身份就是记录里那一个(政策改变不重启它)。
363
+ # 这时写记录会把它改成「没有在跑的那个模型」,下一次续跑就接着一份对不上的会话 —— 拒绝,并给两条路。
364
+ if [ "$adopt_pm" = "1" ]; then
365
+ team_err "--adopt-pm-identity:PM 正在运行/正在起($(team_pm_state)),它的身份是记录里那一个;这次不写记录"
366
+ team_dim " 要换续跑身份:等 PM 停了再 $TEAM_CLI up --adopt-pm-identity [--yes];要换 PM 模型:$TEAM_CLI up --fresh-pm" >&2
367
+ return 1
368
+ fi ;;
369
+ *)
370
+ if [ "$adopt_pm" = "1" ]; then
371
+ team_pm_identity_adopt "${TEAM_ASSUME_YES:-0}" || { team_up_backup_note; return 1; }
372
+ fi
373
+ team_pm_identity_guard || { team_up_backup_note; return 1; }
374
+ register=0; [ "${TEAM_PM_IDENTITY_REGISTER:-0}" = 1 ] && register=1 ;;
375
+ esac
162
376
  # 1) tmux 场地:人跑 up 就是明确要求“把工地建起来”,所以这里允许建 session/窗口
163
377
  if ! team_tmux_has_session "$TEAM_SESSION"; then
164
378
  team_warn "tmux session '$TEAM_SESSION' 不存在:重建"
165
379
  team_tmux_ensure_session
166
- tmux set-option -t "$TEAM_SESSION" destroy-unattached off >/dev/null 2>&1 || true
380
+ team_tmux set-option -t "$TEAM_SESSION" destroy-unattached off >/dev/null 2>&1 || true
167
381
  fi
168
382
  if ! team_pm_window_exists; then
169
383
  team_tmux_new_window "$TEAM_SESSION" "$TEAM_PM_WINDOW" || true
@@ -225,13 +439,29 @@ team_cmd_up() {
225
439
  team_dim " agent 不归 pulse/up 管:需要续跑时跑 $TEAM_CLI resume [--dry-run]"
226
440
  fi
227
441
 
442
+ # P261 ②(design §7):缺记录时登记本次启动身份并说明(写入由成功启动后的 publish 完成);
443
+ # --adopt-pm-identity 的声明行由 team_pm_identity_adopt 打印(那一刻就写完了)。
444
+ if [ "$register" = 1 ] && [ "$pm_fail" != 1 ]; then
445
+ if team_pm_metadata_load 2>/dev/null; then
446
+ printf 'i 此前没有启动记录;已登记本次启动身份:model=%s resume_key=%s mode=%s(要换 PM 模型必须 --fresh-pm)\n' \
447
+ "$TEAM_PM_SELECTED_MODEL" "$TEAM_PM_RECORDED_RESUME_KEY" "$TEAM_PM_RECORDED_MODE"
448
+ else
449
+ printf 'i 此前没有启动记录;本次启动的身份登记未确认(记录读不回来)\n'
450
+ fi
451
+ fi
452
+
228
453
  if team_in_standby; then
229
454
  team_warn "注意:当前 standby on(原因:$(team_standby_reason || echo -))。pulse 不会自动叫醒 PM;处理好后跑 $TEAM_CLI standby off"
230
455
  fi
231
456
 
232
457
  team_info ""
233
458
  team_capacity_line
459
+ # P276:孤儿席位进程读数(启动决策**之后**的一行;只读、不发信号)
460
+ team_orphan_up_line
234
461
  team_dim " 旁观:tmux attach -t $TEAM_SESSION | 待办:$TEAM_CLI digest"
462
+ # P261 ③(design §8):版本提示在启动决策**之后**,任何失败都不改 rc、不启动/停止任何东西。
463
+ team_update_check_notice || true
464
+ team_up_backup_note
235
465
  # 状态就是承诺:PM 没起来就不许退 0(否则脚本里的 `team up && …` 会把失败当成功)
236
466
  [ "$pm_fail" = "1" ] && return 1
237
467
  return 0
@@ -430,7 +660,7 @@ team_watch_once() {
430
660
  if ! team_tmux_has_session "$TEAM_SESSION"; then
431
661
  team_wlog "tmux session 丢失,重建(TEAM_PULSE_REBUILD_TMUX=1)"
432
662
  team_tmux_ensure_session
433
- tmux set-option -t "$TEAM_SESSION" destroy-unattached off >/dev/null 2>&1 || true
663
+ team_tmux set-option -t "$TEAM_SESSION" destroy-unattached off >/dev/null 2>&1 || true
434
664
  fi
435
665
  if ! team_pm_window_exists; then
436
666
  team_wlog "PM 窗口丢失,重建(TEAM_PULSE_REBUILD_TMUX=1)"
@@ -617,7 +847,8 @@ team_panel_capacity_json() {
617
847
  fi
618
848
  [ -n "${ram:-}" ] || ram=0
619
849
  local p t a it iff id seen=" " entries="" avail_json ino_json readable
620
- for p in "${TMPDIR:-/tmp}" "${TEAM_MAIN_ROOT:-$PWD}/${TEAM_WORKTREES_DIR:-.worktrees}"; do
850
+ local temp_root; temp_root="$(team_tmp_root 2>/dev/null || true)"
851
+ for p in "$temp_root" "${TEAM_MAIN_ROOT:-$PWD}/${TEAM_WORKTREES_DIR:-.worktrees}"; do
621
852
  [ -n "$p" ] || continue
622
853
  team__disk_stats "$p"; t="$_D_T"; a="$_D_A"; it="$_D_IT"; iff="$_D_IFF"; id="$_D_ID"
623
854
  if [ -n "$id" ]; then
@@ -631,9 +862,11 @@ team_panel_capacity_json() {
631
862
  fi
632
863
  entries="$entries${entries:+, }{\"path\": $(team_panel_json_str "$p"), \"avail_mb\": $avail_json, \"free_inodes\": $ino_json, \"readable\": $readable}"
633
864
  done
634
- printf '{"ram_avail_mb": %s, "swap_free_mb": %s, "agents": %s, "disk": [%s], "spark": %s}\n' \
865
+ printf '{"ram_avail_mb": %s, "swap_free_mb": %s, "agents": %s, "temp_root": %s, "temp_root_source": %s, "disk": [%s], "spark": %s}\n' \
635
866
  "$(team_panel_num "$ram")" "$(team_panel_num "$diskfree")" \
636
- "$(team_panel_num "$(team_agent_capacity)")" "$entries" "$spark"
867
+ "$(team_panel_num "$(team_agent_capacity)")" \
868
+ "$(team_panel_json_str "${temp_root:-}")" "$(team_panel_json_str "$(team_tmp_root_source 2>/dev/null || printf 'default')")" \
869
+ "$entries" "$spark"
637
870
  [ "$degraded" = "0" ]
638
871
  }
639
872
 
@@ -1009,6 +1242,11 @@ team_panel_change_tasks_json() { # <change id> → "tasks": [...], "tasks_more":
1009
1242
  team_panel_changes_json() {
1010
1243
  local spec_dir dir bin listed="" src="dir" out="[" first=1 id done total age phase n_changes=0
1011
1244
  spec_dir="$(team_spec_dir_abs)"; dir="$spec_dir/changes"
1245
+ # F3:`openspec`(或它到项目根之间的段)或 `openspec/changes` 是软链时,本块不列任何条目 ——
1246
+ # 只读预览的合同是「只读 openspec 目录内、不得读穿」,列表跟详情一样按同一条判据拒绝。
1247
+ if team_panel_detail_symlink_hit "$spec_dir" "$dir" >/dev/null; then
1248
+ printf '{"available": false, "source": "none", "changes": [], "count": 0}'; return 0
1249
+ fi
1012
1250
  bin="$(team_openspec_bin_path 2>/dev/null || true)"
1013
1251
  if [ -n "$bin" ] && command -v "$bin" >/dev/null 2>&1 && [ -d "$TEAM_MAIN_ROOT" ]; then
1014
1252
  listed="$(cd "$TEAM_MAIN_ROOT" && "$bin" list 2>/dev/null | sed -n 's/^[[:space:]]\{2,\}\([^[:space:]]*\)[[:space:]]\{1,\}\([0-9][0-9]*\)\/\([0-9][0-9]*\).*/\1\t\2\t\3/p' || true)"
@@ -1048,6 +1286,10 @@ team_panel_changes_json() {
1048
1286
  team_panel_specs_json() {
1049
1287
  local spec_dir bin listed="" src="dir" out="[" first=1 name reqs count=0 total=0 line
1050
1288
  spec_dir="$(team_spec_dir_abs)"
1289
+ # F3:同 changes —— `openspec`(含到项目根之间的段)或 `openspec/specs` 是软链时不列。
1290
+ if team_panel_detail_symlink_hit "$spec_dir" "$spec_dir/specs" >/dev/null; then
1291
+ printf '{"available": false, "count": 0, "requirements": 0, "specs": []}'; return 0
1292
+ fi
1051
1293
  bin="$(team_openspec_bin_path 2>/dev/null || true)"
1052
1294
  if [ -n "$bin" ] && command -v "$bin" >/dev/null 2>&1 && [ -d "$TEAM_MAIN_ROOT" ]; then
1053
1295
  listed="$(cd "$TEAM_MAIN_ROOT" && "$bin" list --specs 2>/dev/null | sed -n 's/^[[:space:]]\{2,\}\([^[:space:]]*\)[[:space:]]\{1,\}requirements[[:space:]]\{1,\}\([0-9][0-9]*\).*/\1\t\2/p' || true)"
@@ -1082,6 +1324,10 @@ team_panel_specs_json() {
1082
1324
 
1083
1325
  team_panel_decisions_json() { # DECISIONS.md:标题数 + 最新三条(新→旧)
1084
1326
  local f="$TEAM_DOCS_ABS/DECISIONS.md" out="[" first=1 line count=0
1327
+ # F3:`docs`(或它到项目根之间的段)是软链时,条目不列(详情面会点名那一段)。
1328
+ if team_panel_detail_symlink_hit "$TEAM_DOCS_ABS" "$f" >/dev/null; then
1329
+ printf '{"count": 0, "recent": []}'; return 0
1330
+ fi
1085
1331
  [ -f "$f" ] || { printf '{"count": 0, "recent": []}'; return 0; }
1086
1332
  count="$(grep -c '^## ' "$f" 2>/dev/null || true)"
1087
1333
  while IFS= read -r line; do
@@ -1181,57 +1427,275 @@ team_panel_settings_json() {
1181
1427
  # `--file` 只服务**发现集里的**路径:任何别的路径都非 0 且不打印内容——面板不会变成任意文件读取器。
1182
1428
  # 正文上限 128 KiB(超出截断并带 truncated 标记),UTF-8 边界用 iconv -c 收尾。
1183
1429
 
1184
- # 发现记录:每行 `<相对路径>\t<tab 名>\t<字节数>`,顺序 = 任务书 → 报告 → 复验。
1185
- team_panel_detail_records() { # <id>
1430
+ # 发现记录:每行 `<相对路径>\t<tab 名>\t<字节数>\t<软链 0|1>`,顺序 = 树上/账本上的呈现序。
1431
+ # source 缺省 entry(既有语义逐字不变);spec/change/decision 三类见各自函数。
1432
+ # 软链的路径照旧出现在记录里但带 `1` 标记:json 把它排除出发现集(`--file` 选不到它)并在 reason 里点名。
1433
+ team_panel_detail_rel() { # <绝对路径> → 相对 main root(不在 root 下时原样)
1434
+ local f="$1"
1435
+ case "$f" in "$TEAM_MAIN_ROOT"/*) printf '%s' "${f#"$TEAM_MAIN_ROOT"/}" ;; *) printf '%s' "$f" ;; esac
1436
+ }
1437
+
1438
+ # F1 返修:目录段软链与叶软链一视同仁 —— 只挡叶节点时,`changes/<id>` / `specs/<cap>` 这一层是指向
1439
+ # 根外(读穿 openspec 根)或根内另一个 change / `archive/`(越权服务)的软链,都会被当成正常路径。
1440
+ # F3 返修:锚点从**源根**提到**项目根** —— `openspec` 本身、`docs` 本身也在被读路径上,必须一起判;
1441
+ # 只从源根往下走,项目根到源根之间的段是软链时四类预览照样读树外正文。
1442
+ # 沿**项目根 → 候选路径**逐段判定:命中软链就打印**那一段**(相对 main root)并退 0;整条路径没有软链退 1。
1443
+ # 包含关系仍按调用方给的允许根判(`p` 必须在 `root` 之下);项目根自己(`p == TEAM_MAIN_ROOT`)不判 ——
1444
+ # 项目根本身是软链属于本机布局,不在本合同的拒绝面里(路径前缀由 `read_nofollow` 的物理路径比对处理)。
1445
+ team_panel_detail_symlink_hit() { # <允许根 abs> <候选路径 abs>
1446
+ local root="$1" p="$2" rel cur c
1447
+ case "$root" in "$TEAM_MAIN_ROOT"|"$TEAM_MAIN_ROOT"/*) ;; *) return 1 ;; esac
1448
+ case "$p" in "$root"|"$root"/*) ;; *) return 1 ;; esac
1449
+ rel="${p#"$TEAM_MAIN_ROOT"/}"
1450
+ [ "$rel" != "$p" ] || return 1
1451
+ cur="$TEAM_MAIN_ROOT"
1452
+ local IFS=/
1453
+ for c in $rel; do
1454
+ [ -n "$c" ] || continue
1455
+ cur="$cur/$c"
1456
+ if [ -L "$cur" ]; then team_panel_detail_rel "$cur"; return 0; fi
1457
+ done
1458
+ return 1
1459
+ }
1460
+
1461
+ team_panel_detail_source_root() { # <source> → 该 source 的允许根(entry/decision 不走软链目录判定)
1462
+ case "$1" in
1463
+ spec) printf '%s/specs' "$(team_spec_dir_abs)" ;;
1464
+ change) printf '%s/changes' "$(team_spec_dir_abs)" ;;
1465
+ esac
1466
+ }
1467
+
1468
+ # `设备:inode` 读数:GNU(-c)优先、BSD/macOS(-f)兜底(仓里既有写法,如 common.sh 的 `stat -c … || stat -f …`)。
1469
+ # follow = -L(跟到目标,软链给的是目标身份);nofollow = 不跟(lstat,软链给的是**链接自己**的 inode)。
1470
+ team_panel_detail_stat_id() { # <follow|nofollow> <路径>
1471
+ case "$1" in
1472
+ follow) stat -Lc '%d:%i' -- "$2" 2>/dev/null || stat -Lf '%d:%i' -- "$2" 2>/dev/null ;;
1473
+ nofollow) stat -c '%d:%i' -- "$2" 2>/dev/null || stat -f '%d:%i' -- "$2" 2>/dev/null ;;
1474
+ esac
1475
+ }
1476
+
1477
+ # F2 返修:把「判」与「读」合成原子 —— 一次 open,之后只从**同一个 fd** 读。
1478
+ # 两轮动过的三种窗口都在这一个函数里关掉:
1479
+ # ① fd 打开到的目标(`stat -L`)必须等于 ② 路径此刻的不跟随身份(`stat`)—— 叶节点在 open 前/后被换成
1480
+ # 软链、或被换成另一个文件,两者必不相同(第一轮承诺的「发现之后、读之前被换也不读」在这里才成立);
1481
+ # ③ 路径的每一段(含允许根本身)此刻都不是软链 —— 中间目录在 open 之后被换成软链也会命中(① 对
1482
+ # 中间段无能为力:lstat 会跟完前缀,两侧拿到的都是树外那个目标)。
1483
+ # 正文只从 ① 里那个 fd 读,所以「判据作用的对象」与「读出的内容」是同一个 inode。
1484
+ # rc=0 读到(可能空正文 —— 与今天 `head -c` 打不开同形);rc=3 被换/命中软链(调用者按「软链拒绝」点名);
1485
+ # rc=4 既没有 /proc/self/fd 也没有 /dev/fd:拿不到 fd 身份就不读(宁可拒,也不拿可能被换过的路径去读)。
1486
+ # `<cap>` 写 `-` = 读到 EOF(决策源要拿到整篇才能切片)。
1487
+ team_panel_detail_read_nofollow() { # <允许根|-> <abs> <cap>
1488
+ local root="$1" abs="$2" cap="$3" id_fd="" id_path="" p
1489
+ { exec 9<"$abs"; } 2>/dev/null || return 0
1490
+ for p in /proc/self/fd/9 /dev/fd/9; do
1491
+ id_fd="$(team_panel_detail_stat_id follow "$p")"
1492
+ [ -n "$id_fd" ] && break
1493
+ done
1494
+ if [ -z "$id_fd" ]; then exec 9<&-; return 4; fi
1495
+ id_path="$(team_panel_detail_stat_id nofollow "$abs")"
1496
+ if [ -z "$id_path" ] || [ "$id_fd" != "$id_path" ]; then exec 9<&-; return 3; fi
1497
+ # F3/F4 返修:判据作用于**读的那个对象** —— 句柄自己解析出的路径(open 那一刻固定)必须逐字节等于
1498
+ # 「锚点真实路径 + 字面相对路径」。锚点默认是**项目根**,所以 `openspec`/`docs` 本身、中间目录、叶节点
1499
+ # 在 open 时是不是软链,在这一条里一次性可见(F2 的「读前再判一次」是按路径名走的,中间段换回真目录
1500
+ # 就放行)。允许根不在项目树内(例如绝对路径的 TEAM_DOCS_DIR)时退回允许根做锚点:那类布局没有更外层
1501
+ # 的可信锚点,仍按叶/前缀的物理路径比对。拿不到 fd 路径或锚点就拒绝(fail-closed)。
1502
+ local fd_real root_real rel_real anchor="$TEAM_MAIN_ROOT"
1503
+ case "$root" in
1504
+ -|'') anchor="" ;;
1505
+ "$TEAM_MAIN_ROOT"|"$TEAM_MAIN_ROOT"/*) ;;
1506
+ *) anchor="$root" ;;
1507
+ esac
1508
+ # 判据无条件生效(没有「某条件不满足就跳过」的旁路):候选路径**必须**落在锚点之下,且句柄解析出的
1509
+ # 路径**必须逐字节等于**「锚点真实路径 + 字面相对路径」。现有调用图里 abs 全部由允许根与发现集拼出,
1510
+ # 前缀不匹配这条分支不可达;把它写成拒绝(而不是跳过)是为了让未来的调用方出错时也 fail-closed。
1511
+ if [ -n "$anchor" ]; then
1512
+ case "$abs" in "$anchor"/*) rel_real="${abs#"$anchor"/}" ;; *) exec 9<&-; return 3 ;; esac
1513
+ fd_real="$(readlink /proc/self/fd/9 2>/dev/null || readlink /dev/fd/9 2>/dev/null)"
1514
+ root_real="$(cd "$anchor" 2>/dev/null && pwd -P)"
1515
+ if [ -z "$fd_real" ] || [ -z "$root_real" ] || [ "$fd_real" != "$root_real/$rel_real" ]; then
1516
+ exec 9<&-; return 3
1517
+ fi
1518
+ fi
1519
+ if [ -n "$root" ] && [ "$root" != - ] && team_panel_detail_symlink_hit "$root" "$abs" >/dev/null; then
1520
+ exec 9<&-; return 3
1521
+ fi
1522
+ if [ "$cap" = - ]; then
1523
+ iconv -c -f UTF-8 -t UTF-8 <&9 2>/dev/null || true
1524
+ else
1525
+ head -c "$cap" <&9 2>/dev/null | iconv -c -f UTF-8 -t UTF-8 2>/dev/null || true
1526
+ fi
1527
+ exec 9<&-
1528
+ return 0
1529
+ }
1530
+
1531
+ team_panel_detail_records_entry() { # <id>
1186
1532
  local LC_ALL=C
1187
- local id="$1" f name suffix tab size rel first
1533
+ local id="$1" f name suffix tab size rel first=1 refused=0 hit
1534
+ # F3:`docs`(或它到项目根之间的段)是软链时,整条发现集拒绝并点名那一段(与 spec/change 同形)。
1535
+ if hit="$(team_panel_detail_symlink_hit "$TEAM_DOCS_ABS" "$TEAM_DOCS_ABS")"; then
1536
+ printf '%s\t%s\t%s\t%s\n' "$hit" "brief" "0" "1"
1537
+ return 0
1538
+ fi
1188
1539
  [ -d "$TEAM_DOCS_ABS" ] || return 0
1189
- first=1
1190
1540
  for f in "$TEAM_DOCS_ABS/tasks/$id"-*.md; do
1191
1541
  [ -f "$f" ] || continue
1192
1542
  name="${f##*/}"; suffix="${name#"$id"-}"; suffix="${suffix%.md}"
1193
1543
  tab="brief"; [ "$first" = 1 ] || tab="brief:$suffix"; first=0
1194
1544
  size="$(wc -c < "$f" 2>/dev/null | tr -d ' ')"
1195
- rel="${f#"$TEAM_MAIN_ROOT"/}"
1196
- printf '%s\t%s\t%s\n' "$rel" "$tab" "${size:-0}"
1545
+ rel="$(team_panel_detail_rel "$f")"
1546
+ refused=0; [ -L "$f" ] && refused=1
1547
+ printf '%s\t%s\t%s\t%s\n' "$rel" "$tab" "${size:-0}" "$refused"
1197
1548
  done
1198
1549
  for f in "$TEAM_DOCS_ABS/reports/$id"-*.md; do
1199
1550
  [ -f "$f" ] || continue
1200
1551
  name="${f##*/}"; suffix="${name#"$id"-}"; suffix="${suffix%.md}"
1201
1552
  size="$(wc -c < "$f" 2>/dev/null | tr -d ' ')"
1202
- rel="${f#"$TEAM_MAIN_ROOT"/}"
1203
- printf '%s\t%s\t%s\n' "$rel" "report:$suffix" "${size:-0}"
1553
+ rel="$(team_panel_detail_rel "$f")"
1554
+ refused=0; [ -L "$f" ] && refused=1
1555
+ printf '%s\t%s\t%s\t%s\n' "$rel" "report:$suffix" "${size:-0}" "$refused"
1204
1556
  done
1205
1557
  f="$TEAM_DOCS_ABS/reviews/$id.md"
1206
1558
  if [ -f "$f" ]; then
1207
1559
  size="$(wc -c < "$f" 2>/dev/null | tr -d ' ')"
1208
- rel="${f#"$TEAM_MAIN_ROOT"/}"
1209
- printf '%s\t%s\t%s\n' "$rel" "review" "${size:-0}"
1560
+ rel="$(team_panel_detail_rel "$f")"
1561
+ refused=0; [ -L "$f" ] && refused=1
1562
+ printf '%s\t%s\t%s\t%s\n' "$rel" "review" "${size:-0}" "$refused"
1210
1563
  fi
1211
1564
  for f in "$TEAM_DOCS_ABS/reviews/$id"-*.md; do
1212
1565
  [ -f "$f" ] || continue
1213
1566
  name="${f##*/}"; suffix="${name#"$id"-}"; suffix="${suffix%.md}"
1214
1567
  size="$(wc -c < "$f" 2>/dev/null | tr -d ' ')"
1215
- rel="${f#"$TEAM_MAIN_ROOT"/}"
1216
- printf '%s\t%s\t%s\n' "$rel" "review:$suffix" "${size:-0}"
1568
+ rel="$(team_panel_detail_rel "$f")"
1569
+ refused=0; [ -L "$f" ] && refused=1
1570
+ printf '%s\t%s\t%s\t%s\n' "$rel" "review:$suffix" "${size:-0}" "$refused"
1571
+ done
1572
+ return 0
1573
+ }
1574
+
1575
+ # source spec:`<spec_dir>/specs/<capability>/spec.md`(唯一的那个文件,tab `spec`)。
1576
+ team_panel_detail_records_spec() { # <capability>
1577
+ local id="$1" f size rel refused=0 root hit
1578
+ root="$(team_spec_dir_abs)/specs"
1579
+ f="$root/$id/spec.md"
1580
+ # 目录段软链先判(`-f` 会跟随它):目标在不在都拒绝并点名,不拿软链之外的正文充数。
1581
+ if hit="$(team_panel_detail_symlink_hit "$root" "$f")"; then
1582
+ printf '%s\t%s\t%s\t%s\n' "$hit" "spec" "0" "1"
1583
+ return 0
1584
+ fi
1585
+ [ -f "$f" ] || return 0
1586
+ size="$(wc -c < "$f" 2>/dev/null | tr -d ' ')"
1587
+ rel="$(team_panel_detail_rel "$f")"
1588
+ [ -L "$f" ] && refused=1
1589
+ printf '%s\t%s\t%s\t%s\n' "$rel" "spec" "${size:-0}" "$refused"
1590
+ }
1591
+
1592
+ # source change:该 change 自己的 proposal/design/tasks(按此序,缺的不补;archive 到不了)。
1593
+ team_panel_detail_records_change() { # <change id>
1594
+ local id="$1" dir f name size rel refused=0 root hit
1595
+ root="$(team_spec_dir_abs)/changes"
1596
+ dir="$root/$id"
1597
+ # 同上:`changes/<id>` 是软链(指根外、指别的 change、指 archive/)时整条拒绝并点名那一段。
1598
+ if hit="$(team_panel_detail_symlink_hit "$root" "$dir")"; then
1599
+ printf '%s\t%s\t%s\t%s\n' "$hit" "change" "0" "1"
1600
+ return 0
1601
+ fi
1602
+ [ -d "$dir" ] || return 0
1603
+ for name in proposal design tasks; do
1604
+ f="$dir/$name.md"
1605
+ [ -f "$f" ] || continue
1606
+ size="$(wc -c < "$f" 2>/dev/null | tr -d ' ')"
1607
+ rel="$(team_panel_detail_rel "$f")"
1608
+ refused=0; [ -L "$f" ] && refused=1
1609
+ printf '%s\t%s\t%s\t%s\n' "$rel" "$name" "${size:-0}" "$refused"
1217
1610
  done
1611
+ }
1612
+
1613
+ # 决策切片:条目标题 = `##`/`###` 且 id 后跟非数字;正文到「同层或更浅的下一个标题」为止,
1614
+ # 同 id 的更深层补记(`### D7 补记`)留在正文里。查无此号 → 无输出(由 json 给空表 + reason)。
1615
+ team_panel_detail_decision_slice() { # <D编号> [文件](缺省账本;`-` = 从 stdin 读)
1616
+ local id="$1" f="${2:-$TEAM_DOCS_ABS/DECISIONS.md}"
1617
+ [ "$f" = - ] || [ -f "$f" ] || return 0
1618
+ awk -v want="$id" '
1619
+ { lines[NR] = $0 }
1620
+ END {
1621
+ start = 0; level = 0
1622
+ for (i = 1; i <= NR; i++) {
1623
+ lv = 0
1624
+ if (lines[i] ~ /^### /) lv = 3; else if (lines[i] ~ /^## /) lv = 2
1625
+ if (lv == 0) continue
1626
+ h = lines[i]; sub(/^#+[ \t]+/, "", h)
1627
+ if (h ~ ("^" want "([^0-9]|$)")) { start = i; level = lv; break }
1628
+ }
1629
+ if (start == 0) { exit }
1630
+ end = NR
1631
+ for (i = start + 1; i <= NR; i++) {
1632
+ lv = 0
1633
+ if (lines[i] ~ /^### /) lv = 3; else if (lines[i] ~ /^## /) lv = 2
1634
+ if (lv > 0 && lv <= level) { end = i - 1; break }
1635
+ }
1636
+ for (i = start; i <= end; i++) print lines[i]
1637
+ }' "$f"
1638
+ }
1639
+
1640
+ # source decision:只服务所请求条目的切片(不提供整文件出口)。
1641
+ team_panel_detail_records_decision() { # <D编号>
1642
+ local id="$1" f="$TEAM_DOCS_ABS/DECISIONS.md" slice size rel refused=0 hit
1643
+ # F3:`docs`(或它到项目根之间的段)是软链时,账本条目整条拒绝并点名那一段(正文更是一个字节不读)。
1644
+ if hit="$(team_panel_detail_symlink_hit "$TEAM_DOCS_ABS" "$f")"; then
1645
+ printf '%s\t%s\t%s\t%s\n' "$hit" "$id" "0" "1"
1646
+ return 0
1647
+ fi
1648
+ [ -f "$f" ] || return 0
1649
+ slice="$(team_panel_detail_decision_slice "$id")"
1650
+ [ -n "$slice" ] || return 0
1651
+ size="$(printf '%s\n' "$slice" | wc -c | tr -d ' ')"
1652
+ rel="$(team_panel_detail_rel "$f")"
1653
+ [ -L "$f" ] && refused=1
1654
+ printf '%s\t%s\t%s\t%s\n' "$rel" "$id" "${size:-0}" "$refused"
1655
+ }
1656
+
1657
+ team_panel_detail_records() { # <id> [source]
1658
+ case "${2:-entry}" in
1659
+ entry) team_panel_detail_records_entry "$1" ;;
1660
+ spec) team_panel_detail_records_spec "$1" ;;
1661
+ change) team_panel_detail_records_change "$1" ;;
1662
+ decision) team_panel_detail_records_decision "$1" ;;
1663
+ esac
1218
1664
  return 0
1219
1665
  }
1220
1666
 
1221
1667
  # 详情块:文件清单 + 被服务文件的正文(默认第一份;`--file` 指定时必须已在发现集里)。
1222
- team_panel_detail_json() { # <id> [file]
1223
- local id="${1:-}" want="${2:-}" cap="${TEAM_PANEL_DETAIL_CAP:-131072}"
1668
+ # `--source`(第三参)决定发现集;缺省 entry 与今天逐字一致。目标缺失不是错误:空文件表 + reason。
1669
+ team_panel_detail_json() { # <id> [file] [source]
1670
+ local id="${1:-}" want="${2:-}" source="${3:-entry}" cap="${TEAM_PANEL_DETAIL_CAP:-131072}"
1224
1671
  [ -n "$id" ] || { printf 'team: __panel-data --block detail 需要 --id <ID>\n' >&2; return 2; }
1225
- # id 直接进 glob:只接受字母数字与 . _ -(挡掉通配符与路径穿越;`board` 的 id 就长这样)。
1226
- case "$id" in
1227
- *[!A-Za-z0-9._-]*) printf 'team: __panel-data --block detail: 非法的 --id %s\n' "$id" >&2; return 2 ;;
1672
+ case "$source" in
1673
+ ''|entry|spec|change|decision) source="${source:-entry}" ;;
1674
+ *) printf 'team: __panel-data --block detail: 未知的 --source %s\n' "$source" >&2; return 2 ;;
1228
1675
  esac
1676
+ # id 直接进路径/glob:decision 只接受 `D<数字>`,其余 source 只接受字母数字与 . _ -,
1677
+ # 且明确拒绝 `.`/`..`(前者是 glob 通配符与穿越字符,后者会从 specs/<id>/ 爬上一层)。
1678
+ if [ "$source" = decision ]; then
1679
+ case "$id" in
1680
+ D[0-9]*) ;;
1681
+ *) printf 'team: __panel-data --block detail: 非法的 --id %s(decision 只接受 D<数字>)\n' "$id" >&2; return 2 ;;
1682
+ esac
1683
+ case "${id#D}" in
1684
+ ''|*[!0-9]*) printf 'team: __panel-data --block detail: 非法的 --id %s(decision 只接受 D<数字>)\n' "$id" >&2; return 2 ;;
1685
+ esac
1686
+ else
1687
+ case "$id" in
1688
+ *[!A-Za-z0-9._-]*|.|..) printf 'team: __panel-data --block detail: 非法的 --id %s\n' "$id" >&2; return 2 ;;
1689
+ esac
1690
+ fi
1229
1691
  local -a paths=() tabs=() sizes=()
1230
- local path tab size
1231
- while IFS=$'\t' read -r path tab size; do
1692
+ local path tab size flag refused=""
1693
+ while IFS=$'\t' read -r path tab size flag; do
1232
1694
  [ -n "$path" ] || continue
1695
+ # 软链不进发现集(`--file` 选不到、正文永不读穿),但在 reason 里点名。
1696
+ if [ "${flag:-0}" = 1 ]; then refused="${refused:+$refused · }$path"; continue; fi
1233
1697
  paths+=("$path"); tabs+=("$tab"); sizes+=("${size:-0}")
1234
- done < <(team_panel_detail_records "$id")
1698
+ done < <(team_panel_detail_records "$id" "$source")
1235
1699
  local n="${#paths[@]}" i pick=0
1236
1700
  if [ -n "$want" ]; then
1237
1701
  local found=-1
@@ -1252,15 +1716,68 @@ team_panel_detail_json() { # <id> [file]
1252
1716
  out="$out{\"tab\": $(team_panel_json_str "${tabs[$i]}"), \"name\": $(team_panel_json_str "${paths[$i]##*/}"), \"path\": $(team_panel_json_str "${paths[$i]}"), \"size\": $(team_panel_num "${sizes[$i]}"), \"truncated\": $t}"
1253
1717
  done
1254
1718
  out="$out]"
1255
- local file="" text="" truncated=false
1719
+ local file="" text="" truncated=false abs read_hit="" read_unchecked="" read_root="-" read_rc=0 decision_rel="" decision_body=""
1256
1720
  if [ "$n" -gt 0 ]; then
1257
1721
  file="${paths[$pick]}"
1258
- text="$(head -c "$cap" "$TEAM_MAIN_ROOT/$file" 2>/dev/null | iconv -c -f UTF-8 -t UTF-8 2>/dev/null || true)"
1722
+ case "$file" in /*) abs="$file" ;; *) abs="$TEAM_MAIN_ROOT/$file" ;; esac
1723
+ # 路径级复判(发现与读取两处都判):发现之后、读之前路径被换成软链也不读 —— 这里顺手点名命中的那一段。
1724
+ # F3:entry/decision 两类也判(锚点是项目根:`docs` 本身是软链时点名 `docs`)。
1725
+ case "$source" in
1726
+ spec|change)
1727
+ if read_hit="$(team_panel_detail_symlink_hit "$(team_panel_detail_source_root "$source")" "$abs")"; then
1728
+ file=""
1729
+ fi ;;
1730
+ entry|decision)
1731
+ if read_hit="$(team_panel_detail_symlink_hit "$TEAM_DOCS_ABS" "$abs")"; then
1732
+ file=""
1733
+ fi ;;
1734
+ esac
1735
+ if [ -n "$read_hit" ]; then
1736
+ : # 命中软链:正文一个字节都不读(下面 reason 里点名)
1737
+ elif [ "$source" = decision ]; then
1738
+ # 决策源也是「发现到的路径」(合同把三类 source 的软链都点名了):先原子读账本,再从**读到的那份正文**
1739
+ # 切片 —— 账本在发现之后被换成软链,切出来的一样不是树外内容。
1740
+ decision_rel="$(team_panel_detail_rel "$TEAM_DOCS_ABS/DECISIONS.md")"
1741
+ decision_body="$(team_panel_detail_read_nofollow "$TEAM_DOCS_ABS" "$TEAM_DOCS_ABS/DECISIONS.md" -)" || read_rc=$?
1742
+ case "$read_rc" in
1743
+ 3) read_hit="$decision_rel"; file="" ;;
1744
+ 4) read_unchecked="$decision_rel"; file="" ;;
1745
+ *) text="$(printf '%s\n' "$decision_body" | team_panel_detail_decision_slice "$id" - | head -c "$cap" | iconv -c -f UTF-8 -t UTF-8 2>/dev/null || true)" ;;
1746
+ esac
1747
+ else
1748
+ # 读面原子化(F2):判据与读取作用于同一个 inode(open 一次 + fd 身份 + 逐段现查)。
1749
+ case "$source" in
1750
+ spec|change) read_root="$(team_panel_detail_source_root "$source")" ;;
1751
+ entry) read_root="$TEAM_DOCS_ABS" ;;
1752
+ esac
1753
+ text="$(team_panel_detail_read_nofollow "$read_root" "$abs" "$cap")" || read_rc=$?
1754
+ case "$read_rc" in
1755
+ 3) read_hit="$file"; file="" ;;
1756
+ 4) read_unchecked="$file"; file="" ;;
1757
+ esac
1758
+ fi
1259
1759
  [ "${sizes[$pick]}" -gt "$cap" ] && truncated=true
1260
1760
  fi
1261
- printf '{"id": %s, "count": %s, "file": %s, "text": %s, "truncated": %s, "files": %s}\n' \
1761
+ # 被拒的软链点名;目标根本不存在时给可读原因(不是错误帧,也不拿邻居的正文充数)。
1762
+ local reason=""
1763
+ if [ -n "$read_hit" ]; then
1764
+ reason="软链拒绝:$read_hit"
1765
+ elif [ -n "$read_unchecked" ]; then
1766
+ reason="读取身份无法确认(没有 /proc/self/fd 也没有 /dev/fd):$read_unchecked"
1767
+ elif [ -n "$refused" ]; then
1768
+ reason="软链拒绝:$refused"
1769
+ elif [ "$n" -eq 0 ]; then
1770
+ case "$source" in
1771
+ spec) reason="${TEAM_SPEC_DIR:-openspec}/specs/$id/spec.md 不存在" ;;
1772
+ change) reason="${TEAM_SPEC_DIR:-openspec}/changes/$id/ 下没有 proposal/design/tasks" ;;
1773
+ decision) reason="DECISIONS.md 里没有 $id" ;;
1774
+ esac
1775
+ fi
1776
+ local reason_json=""
1777
+ [ -n "$reason" ] && reason_json=", \"reason\": $(team_panel_json_str "$reason")"
1778
+ printf '{"id": %s, "count": %s, "file": %s, "text": %s, "truncated": %s, "files": %s%s}\n' \
1262
1779
  "$(team_panel_json_str "$id")" "$(team_panel_num "$n")" "$(team_panel_json_str "$file")" \
1263
- "$(team_panel_json_str_ml "$text")" "$truncated" "$out"
1780
+ "$(team_panel_json_str_ml "$text")" "$truncated" "$out" "$reason_json"
1264
1781
  }
1265
1782
 
1266
1783
  # ---- 关键回复块(change: pulse-key-replies):三个 console-only 只读块,直接进 helper。
@@ -1298,7 +1815,7 @@ team_panel_reply_body_json() { # <no>
1298
1815
 
1299
1816
  # 块分发:一个块一个子进程(panel.js 用 --block 起一片),源坏时打印尽力而为的片段并返回非 0,
1300
1817
  # 由渲染层把那一块画成 `—`,其余块照常渲染。
1301
- team_panel_block() { # <块名> <activity 1|0> <events> [id] [file] [before] [no]
1818
+ team_panel_block() { # <块名> <activity 1|0> <events> [id] [file] [before] [no] [source]
1302
1819
  case "$1" in
1303
1820
  frame) team_panel_frame_json ;;
1304
1821
  pm) team_panel_pm_json ;;
@@ -1315,7 +1832,7 @@ team_panel_block() { # <块名> <activity 1|0> <events> [id] [file] [before] [no
1315
1832
  inbox) team_panel_inbox_json ;;
1316
1833
  patrol) team_panel_patrol_json ;;
1317
1834
  health) team_panel_health_json ;;
1318
- detail) team_panel_detail_json "${4:-}" "${5:-}" ;;
1835
+ detail) team_panel_detail_json "${4:-}" "${5:-}" "${8:-}" ;;
1319
1836
  settings) team_panel_settings_json ;;
1320
1837
  reply_summary) team_panel_reply_summary_json ;;
1321
1838
  reply_list) team_panel_reply_list_json "${6:-}" ;;
@@ -1328,7 +1845,7 @@ team_panel_block() { # <块名> <activity 1|0> <events> [id] [file] [before] [no
1328
1845
  # 内部命令:给 panel.js 一个 JSON({panel, activity})或一个块(--block <名>)。
1329
1846
  # 名字带 __ 前缀 = 不是给人用的命令面。
1330
1847
  team_cmd_panel_data() {
1331
- local activity=1 events="${TEAM_MONITOR_EVENTS:-4}" block="" did="" dfile="" rbefore="" rno=""
1848
+ local activity=1 events="${TEAM_MONITOR_EVENTS:-4}" block="" did="" dfile="" rbefore="" rno="" dsource=""
1332
1849
  while [ $# -gt 0 ]; do
1333
1850
  case "$1" in
1334
1851
  --no-activity) activity=0; shift ;;
@@ -1337,6 +1854,7 @@ team_cmd_panel_data() {
1337
1854
  --block) block="${2:?__panel-data: --block 需要块名}"; shift 2 ;;
1338
1855
  --id) did="${2:?__panel-data: --id 需要入口 id}"; shift 2 ;;
1339
1856
  --file) dfile="${2:?__panel-data: --file 需要路径}"; shift 2 ;;
1857
+ --source) dsource="${2:?__panel-data: --source 需要取值}"; shift 2 ;;
1340
1858
  --before) rbefore="${2:?__panel-data: --before 需要编号}"; shift 2 ;;
1341
1859
  --no) rno="${2:?__panel-data: --no 需要编号}"; shift 2 ;;
1342
1860
  -*) team_usage_die "__panel-data: 未知参数 $1" ;;
@@ -1354,7 +1872,7 @@ team_cmd_panel_data() {
1354
1872
  pending) team_scan_warm --reports ;;
1355
1873
  *) team_scan_warm ;;
1356
1874
  esac
1357
- team_panel_block "$block" "$activity" "$events" "$did" "$dfile" "$rbefore" "$rno"
1875
+ team_panel_block "$block" "$activity" "$events" "$did" "$dfile" "$rbefore" "$rno" "$dsource"
1358
1876
  return $?
1359
1877
  fi
1360
1878
  if [ "$activity" = "1" ]; then
@@ -1509,7 +2027,7 @@ team_pulse_shape() { # console | headless | unknown
1509
2027
  local w pane args
1510
2028
  w="$(team_pulse_backend_window)"
1511
2029
  team_tmux_has_window "$TEAM_SESSION" "$w" || { printf 'unknown'; return 0; }
1512
- pane="$(tmux list-panes -t "$TEAM_SESSION:$w" -F '#{pane_pid}' 2>/dev/null | head -1)"
2030
+ pane="$(team_tmux list-panes -t "$TEAM_SESSION:$w" -F '#{pane_pid}' 2>/dev/null | head -1)"
1513
2031
  case "${pane:-}" in ''|*[!0-9]*) printf 'unknown'; return 0 ;; esac
1514
2032
  args="$(ps -o args= -p "$pane" 2>/dev/null || true)"
1515
2033
  case "$args" in
@@ -1539,13 +2057,13 @@ team_pulse_tmux_up() {
1539
2057
  # (那样的窗口会被 pulse status 当成「在跑」,是 D19 明确要避免的假绿)
1540
2058
  team_require_js_runtime "team pulse up"
1541
2059
  team_tmux_ensure_session
1542
- tmux set-option -t "$TEAM_SESSION" destroy-unattached off >/dev/null 2>&1 || true
2060
+ team_tmux set-option -t "$TEAM_SESSION" destroy-unattached off >/dev/null 2>&1 || true
1543
2061
  local w st lw shape; w="$(team_pulse_window)"; st="$(team_pulse_window_state)"
1544
2062
  if [ "$st" = "running" ]; then
1545
2063
  # 无界面形态(q 收起过)→ 同一窗口原地恢复控制台,不开第二个窗口。
1546
2064
  shape="$(team_pulse_shape)"
1547
2065
  if [ "$shape" = "headless" ]; then
1548
- tmux respawn-window -k -t "$TEAM_SESSION:$w" -- bash -c "$(team_pulse_window_cmd)"
2066
+ team_tmux respawn-window -k -t "$TEAM_SESSION:$w" -- bash -c "$(team_pulse_window_cmd)"
1549
2067
  sleep 1.5
1550
2068
  if [ "$(team_pulse_window_state)" = "running" ] && [ "$(team_pulse_shape)" = "console" ]; then
1551
2069
  team_ok "已把无界面巡检恢复成控制台($TEAM_SESSION:$w)"
@@ -1562,8 +2080,8 @@ team_pulse_tmux_up() {
1562
2080
  team_warn "旧窗口 $TEAM_SESSION:$lw 仍在跑 → $TEAM_CLI pulse restart 换成 $TEAM_SESSION:$w(up 不开第二个巡检)"
1563
2081
  return 0
1564
2082
  fi
1565
- [ "$st" = "idle" ] && { team_warn "窗口 $w 停在空提示符:重开"; tmux kill-window -t "$TEAM_SESSION:$w" 2>/dev/null || true; }
1566
- tmux new-window -t "$TEAM_SESSION" -n "$w" -d -- bash -c "$(team_pulse_window_cmd)"
2083
+ [ "$st" = "idle" ] && { team_warn "窗口 $w 停在空提示符:重开"; team_tmux kill-window -t "$TEAM_SESSION:$w" 2>/dev/null || true; }
2084
+ team_tmux new-window -t "$TEAM_SESSION" -n "$w" -d -- bash -c "$(team_pulse_window_cmd)"
1567
2085
  sleep 1.5
1568
2086
  st="$(team_pulse_window_state)"
1569
2087
  if [ "$st" = "running" ]; then
@@ -1577,11 +2095,11 @@ team_pulse_tmux_up() {
1577
2095
  team_pulse_tmux_down() {
1578
2096
  local w found=0; w="$(team_pulse_window)"
1579
2097
  if team_tmux_has_window "$TEAM_SESSION" "$w"; then
1580
- tmux kill-window -t "$TEAM_SESSION:$w" 2>/dev/null && { team_ok "已关掉巡检窗口:$TEAM_SESSION:$w"; found=1; } || team_warn "关窗口失败"
2098
+ team_tmux kill-window -t "$TEAM_SESSION:$w" 2>/dev/null && { team_ok "已关掉巡检窗口:$TEAM_SESSION:$w"; found=1; } || team_warn "关窗口失败"
1581
2099
  fi
1582
2100
  # 别名期:结束巡检 = 两个名字都结束(旧窗口里可能是升级前的进程)
1583
2101
  if [ "$w" != "watchdog" ] && team_tmux_has_window "$TEAM_SESSION" watchdog; then
1584
- tmux kill-window -t "$TEAM_SESSION:watchdog" 2>/dev/null && { team_ok "已关掉旧名巡检窗口:$TEAM_SESSION:watchdog"; found=1; } || team_warn "关旧名窗口失败"
2102
+ team_tmux kill-window -t "$TEAM_SESSION:watchdog" 2>/dev/null && { team_ok "已关掉旧名巡检窗口:$TEAM_SESSION:watchdog"; found=1; } || team_warn "关旧名窗口失败"
1585
2103
  fi
1586
2104
  [ "$found" = "0" ] && team_dim "没有巡检窗口($TEAM_SESSION:$w)"
1587
2105
  return 0
@@ -1590,7 +2108,7 @@ team_pulse_tmux_down() {
1590
2108
  team_pulse_tmux_logs() { # 打印面板最近若干行(pane 快照;旧名窗口也是后端,迁移前照样能看)
1591
2109
  local w; w="$(team_pulse_backend_window)"
1592
2110
  team_tmux_has_window "$TEAM_SESSION" "$w" || { team_err "没有巡检窗口($TEAM_SESSION:$w);$TEAM_CLI pulse up 起一个"; return 1; }
1593
- tmux capture-pane -p -t "$TEAM_SESSION:$w" -S -60 2>/dev/null | sed '/^$/d' | tail -60
2111
+ team_tmux capture-pane -p -t "$TEAM_SESSION:$w" -S -60 2>/dev/null | sed '/^$/d' | tail -60
1594
2112
  }
1595
2113
 
1596
2114
  # `q` 收起控制台:同一个窗口原地 respawn 成无界面循环。窗口在、形态是 console 才动手。
@@ -1606,7 +2124,7 @@ team_pulse_tmux_collapse() {
1606
2124
  team_dim "巡检窗口已经是无界面形态($shape):不需要收起"
1607
2125
  return 0
1608
2126
  fi
1609
- tmux respawn-window -k -t "$TEAM_SESSION:$w" -- bash -c "$(team_pulse_window_cmd --headless)"
2127
+ team_tmux respawn-window -k -t "$TEAM_SESSION:$w" -- bash -c "$(team_pulse_window_cmd --headless)"
1610
2128
  team_ok "已收起控制台:$TEAM_SESSION:$w 改为无界面巡检(tick 继续,$TEAM_CLI pulse up 恢复)"
1611
2129
  }
1612
2130