teamsmith 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/README.md +4 -4
  2. package/package.json +1 -1
  3. package/skills/teamsmith/CHANGELOG.md +28 -0
  4. package/skills/teamsmith/SKILL.md +14 -7
  5. package/skills/teamsmith/extension/team-notify.ts +37 -6
  6. package/skills/teamsmith/extension/team.ts +438 -0
  7. package/skills/teamsmith/references/config.md +39 -6
  8. package/skills/teamsmith/references/migration.md +197 -47
  9. package/skills/teamsmith/references/protocol.md +176 -19
  10. package/skills/teamsmith/references/troubleshooting.md +124 -7
  11. package/skills/teamsmith/references/workflows.md +36 -2
  12. package/skills/teamsmith/scripts/lib/cmd-agents.sh +318 -23
  13. package/skills/teamsmith/scripts/lib/cmd-bootstrap.sh +2 -2
  14. package/skills/teamsmith/scripts/lib/cmd-config.sh +349 -67
  15. package/skills/teamsmith/scripts/lib/cmd-draft.sh +4 -4
  16. package/skills/teamsmith/scripts/lib/cmd-help.sh +677 -0
  17. package/skills/teamsmith/scripts/lib/cmd-init.sh +157 -5
  18. package/skills/teamsmith/scripts/lib/cmd-interrupt.sh +461 -0
  19. package/skills/teamsmith/scripts/lib/cmd-meeting.sh +2 -25
  20. package/skills/teamsmith/scripts/lib/cmd-project.sh +30 -103
  21. package/skills/teamsmith/scripts/lib/cmd-reap.sh +277 -0
  22. package/skills/teamsmith/scripts/lib/cmd-reply.sh +3 -3
  23. package/skills/teamsmith/scripts/lib/cmd-review.sh +175 -30
  24. package/skills/teamsmith/scripts/lib/cmd-status.sh +226 -17
  25. package/skills/teamsmith/scripts/lib/cmd-update.sh +36 -7
  26. package/skills/teamsmith/scripts/lib/cmd-watch.sh +564 -46
  27. package/skills/teamsmith/scripts/lib/common.sh +773 -48
  28. package/skills/teamsmith/scripts/lib/gate-lock.sh +544 -0
  29. package/skills/teamsmith/scripts/panel/draft-send.sh +11 -1
  30. package/skills/teamsmith/scripts/panel/panel.js +207 -207
  31. package/skills/teamsmith/scripts/panel/src/App.tsx +58 -21
  32. package/skills/teamsmith/scripts/panel/src/clipboard.ts +11 -5
  33. package/skills/teamsmith/scripts/panel/src/compose.ts +6 -3
  34. package/skills/teamsmith/scripts/panel/src/data.ts +11 -3
  35. package/skills/teamsmith/scripts/panel/src/layout.ts +209 -69
  36. package/skills/teamsmith/scripts/panel/src/main.tsx +33 -8
  37. package/skills/teamsmith/scripts/panel/src/strings/en.ts +39 -29
  38. package/skills/teamsmith/scripts/panel/src/strings/zh.ts +41 -31
  39. package/skills/teamsmith/scripts/panel/src/types.ts +28 -3
  40. package/skills/teamsmith/scripts/replies.mjs +4 -1
  41. package/skills/teamsmith/scripts/shim/tmux +18 -0
  42. package/skills/teamsmith/scripts/strings/commands.tsv +86 -0
  43. package/skills/teamsmith/scripts/strings/help.en.tsv +503 -0
  44. package/skills/teamsmith/scripts/strings/help.zh.tsv +489 -0
  45. package/skills/teamsmith/scripts/team +19 -6
  46. package/skills/teamsmith/templates/AGENTS.section.md.tmpl +8 -1
  47. package/skills/teamsmith/templates/config.sh.tmpl +20 -1
  48. package/skills/teamsmith/templates/pm-prompt.md.tmpl +21 -0
  49. package/skills/teamsmith/tests/bg-ledger-harness.mjs +464 -40
  50. package/skills/teamsmith/tests/bg-ledger.sh +168 -10
  51. package/skills/teamsmith/tests/checkout-shape-probe.sh +3 -1
  52. package/skills/teamsmith/tests/config-cli.sh +160 -14
  53. package/skills/teamsmith/tests/fixtures/delivery-truth-real/scenario.sh +7 -1
  54. package/skills/teamsmith/tests/fixtures/p287/lint-good.sh.in +3 -0
  55. package/skills/teamsmith/tests/fixtures/p287/lint-hardcoded.sh.in +3 -0
  56. package/skills/teamsmith/tests/fixtures/p287/lint-no-ns.sh.in +3 -0
  57. package/skills/teamsmith/tests/fixtures/p55/flip-p49.sh +18 -6
  58. package/skills/teamsmith/tests/flip-m33.sh +5 -3
  59. package/skills/teamsmith/tests/flip-m37.sh +4 -1
  60. package/skills/teamsmith/tests/flip-m4.3.sh +4 -1
  61. package/skills/teamsmith/tests/flip-m6.3.sh +4 -1
  62. package/skills/teamsmith/tests/flip-m6.5.sh +4 -1
  63. package/skills/teamsmith/tests/flip-m7.2.sh +4 -1
  64. package/skills/teamsmith/tests/flip-p158.sh +2 -1
  65. package/skills/teamsmith/tests/flip-p210.sh +4 -1
  66. package/skills/teamsmith/tests/flip-p217.sh +4 -1
  67. package/skills/teamsmith/tests/flip-p287-lock.sh +342 -0
  68. package/skills/teamsmith/tests/flip-p287-name.sh +279 -0
  69. package/skills/teamsmith/tests/flip-p304-read-side.sh +98 -0
  70. package/skills/teamsmith/tests/flip-p308-skip-not-pass.sh +151 -0
  71. package/skills/teamsmith/tests/flip-p309-p162-deep.sh +122 -0
  72. package/skills/teamsmith/tests/flip-p310-lock.sh +216 -0
  73. package/skills/teamsmith/tests/flip-p310-socket.sh +125 -0
  74. package/skills/teamsmith/tests/help-surface.sh +1664 -0
  75. package/skills/teamsmith/tests/install-shape.sh +279 -20
  76. package/skills/teamsmith/tests/key-replies-pty.sh +9 -10
  77. package/skills/teamsmith/tests/key-replies-ui.sh +0 -7
  78. package/skills/teamsmith/tests/key-replies.sh +240 -1
  79. package/skills/teamsmith/tests/ledger-ban.sh +5 -4
  80. package/skills/teamsmith/tests/ledger-claim.sh +2 -1
  81. package/skills/teamsmith/tests/lib/bounded-spin.sh +90 -0
  82. package/skills/teamsmith/tests/lib/model-policy.sh +4 -0
  83. package/skills/teamsmith/tests/lib/model-routing-flips.py +51 -0
  84. package/skills/teamsmith/tests/lib/reply-fixture.sh +4 -9
  85. package/skills/teamsmith/tests/lib/section-guard.sh +258 -13
  86. package/skills/teamsmith/tests/lib/tmp-root.sh +139 -27
  87. package/skills/teamsmith/tests/lib/tmux-cap.sh +10 -1
  88. package/skills/teamsmith/tests/lib/tmux-iso.sh +31 -13
  89. package/skills/teamsmith/tests/loop-inventory.tsv +59 -47
  90. package/skills/teamsmith/tests/panel-b2.sh +106 -3
  91. package/skills/teamsmith/tests/panel-b3-stub.sh +112 -4
  92. package/skills/teamsmith/tests/panel-b3.sh +175 -19
  93. package/skills/teamsmith/tests/panel-choices.sh +11 -6
  94. package/skills/teamsmith/tests/panel-cpu.sh +2 -1
  95. package/skills/teamsmith/tests/panel-knobs.sh +7 -1
  96. package/skills/teamsmith/tests/panel-p21.sh +156 -73
  97. package/skills/teamsmith/tests/panel-snapshots.sh +41 -225
  98. package/skills/teamsmith/tests/panel-strings.mjs +33 -18
  99. package/skills/teamsmith/tests/perf.sh +121 -30
  100. package/skills/teamsmith/tests/routes.sh +327 -93
  101. package/skills/teamsmith/tests/seat-interrupt.sh +1002 -0
  102. package/skills/teamsmith/tests/seat-visibility.sh +675 -0
  103. package/skills/teamsmith/tests/section-budgets.tsv +20 -10
  104. package/skills/teamsmith/tests/section-guard.sh +6 -1
  105. package/skills/teamsmith/tests/section-needs-audit.sh +24 -7
  106. package/skills/teamsmith/tests/section-paths.tsv +19 -13
  107. package/skills/teamsmith/tests/section-select.sh +8 -1
  108. package/skills/teamsmith/tests/slash-team-e2e.sh +323 -0
  109. package/skills/teamsmith/tests/slash-team.sh +617 -0
  110. package/skills/teamsmith/tests/smoke.sh +2972 -440
  111. package/skills/teamsmith/tests/task-model-routing.sh +507 -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-init/SKILL.md +12 -12
  117. package/skills/teamsmith-init/references/bootstrap.md +3 -3
@@ -159,7 +159,7 @@ advice, problem reports); workers do not attend**. Only decisions that need the
159
159
  (a) **delivered**: every acceptance command in the brief has been run + the report is written + the branch is pushed + the PR/MR is
160
160
  open (or, in local mode, the branch state is settled);
161
161
  (b) **hard-blocked** (missing dependency, missing permission, someone else's bug): notify the PM with
162
- \`$cli notify $agent "<one line>"\`, state \`BLOCKED:\` clearly in the report, then end the turn;
162
+ \`$cli notify pm "<one line>"\`, state \`BLOCKED:\` clearly in the report, then end the turn;
163
163
  (c) **suspended on background jobs**: jobs this session started are still running and every step that does not depend
164
164
  on their results is done. A suspension is neither a delivery nor a blockage -- do not write the report's final
165
165
  verdict and do not notify \`BLOCKED:\` for it; end the turn with its **last line** naming every job you are
@@ -499,7 +499,7 @@ team_agent_pane_tail() { # <agent> [<重试次数>] → stdout
499
499
  team_agent_window_exists "$agent" || return 0
500
500
  t="$TEAM_SESSION:$agent"
501
501
  while :; do
502
- out="$(tmux capture-pane -p -t "$t" -S -200 2>/dev/null || true)"
502
+ out="$(team_tmux capture-pane -p -t "$t" -S -200 2>/dev/null || true)"
503
503
  team_text_has_content "$out" && break
504
504
  [ "$i" -ge "$tries" ] && break
505
505
  i=$((i + 1)); sleep 0.1
@@ -560,7 +560,7 @@ team_dispatch_launch_diag() { # <agent> <ID> <渲染出的命令> <解析到的
560
560
  team_pane_dead_fields() { # <session:window> → "dead|status|signal|time";目标不在/读不到 → 非 0、无输出
561
561
  local t="${1:-}" out
562
562
  [ -n "$t" ] || return 1
563
- out="$(tmux list-panes -t "$t" -F '#{pane_dead}|#{pane_dead_status}|#{pane_dead_signal}|#{pane_dead_time}' 2>/dev/null | head -1)"
563
+ out="$(team_tmux list-panes -t "$t" -F '#{pane_dead}|#{pane_dead_status}|#{pane_dead_signal}|#{pane_dead_time}' 2>/dev/null | head -1)"
564
564
  [ -n "$out" ] || return 1
565
565
  printf '%s\n' "$out"
566
566
  }
@@ -615,7 +615,7 @@ team_agent_pane_evidence() { # <agent> → 死 pane 的退出证据("signal=9"
615
615
  team_agent_corpse_scene() { # <session:window> → 最后 N 行画面(抓不到 → 空)
616
616
  local t="${1:-}"
617
617
  [ -n "$t" ] || return 1
618
- tmux capture-pane -p -S - -t "$t" 2>/dev/null \
618
+ team_tmux capture-pane -p -S - -t "$t" 2>/dev/null \
619
619
  | sed -e 's/[[:space:]]*$//' -e '/^Pane is dead (/d' \
620
620
  | awk '{ if (NF) last=NR; line[NR]=$0 } END { for (i=1; i<=last; i++) print line[i] }' \
621
621
  | tail -n "$(team_agent_scene_lines)"
@@ -1016,8 +1016,7 @@ team_dispatch_mem_fix_cmd() { # <agent> <ID> <任务书> <守卫输出> → 覆
1016
1016
  printf '%s %s dispatch %s %s %s\n' "${knobs# }" "$TEAM_CLI" "$agent" "$id" "$(printf '%q' "$taskfile")"
1017
1017
  }
1018
1018
 
1019
- team_dispatch_judge_mem() { # <agent> <ID> <任务书>(team_df_run_lib 守卫:透传 team_mem_guard 的判定)
1020
- local agent="$1" id="$2" taskfile="$3" out rc=0
1019
+ team_dispatch_judge_mem() { # <agent> <ID> <任务书>(team_df_run_lib 守卫:透传 team_mem_guard 的判定) local agent="$1" id="$2" taskfile="$3" out rc=0
1021
1020
  out="$(team_mem_guard 2>&1)" || rc=$?
1022
1021
  [ -n "$out" ] && printf '%s\n' "$out"
1023
1022
  [ "$rc" -eq 0 ] && return 0
@@ -1029,6 +1028,33 @@ team_dispatch_judge_mem() { # <agent> <ID> <任务书>(team_df_run_lib 守卫
1029
1028
  return 1
1030
1029
  }
1031
1030
 
1031
+ # P309 · 临时根:显式选定的根不可用 = **阻塞项**(今天这种情况会走「读不到 → 不判」的沉默分支)。
1032
+ # 默认腿未创建**不是**拒绝(读侧按最近祖先判);显式根(TMPDIR / 契约的 TEAM_TMP_ROOT)不存在 /
1033
+ # 不是目录 / 不可写 → 点名路径、来源、原因与修法,且**绝不**换用另一个根。
1034
+ team_dispatch_judge_tmp_root() { # → 0 = 可用或默认腿;1 = 阻塞项(输出已打印)
1035
+ local raw src why
1036
+ src="$(team_tmp_root_source 2>/dev/null || printf 'default')"
1037
+ if ! raw="$(team_tmp_root 2>/dev/null)"; then
1038
+ # 解析器自己已经打印了具名失败(相对路径 / 空串)。这里只给一句话的方向,**不打印一条
1039
+ # 看起来能粘贴的路线**(那条路线得把值改成什么,只有操作者知道;夹具的 C1 会拒收未兑现的路线)。
1040
+ printf ' 方向:给它一个绝对路径(TEAM_TMP_ROOT=/var/tmp/… 或 TMPDIR=/abs/dir),或清掉它走平台默认\n'
1041
+ return 1
1042
+ fi
1043
+ [ "$src" = "default" ] && return 0 # 默认腿:未创建不是拒绝(地板按祖先判)
1044
+ team_tmp_root_usable "$raw" && return 0
1045
+ why="不存在"
1046
+ if [ -e "$raw" ]; then
1047
+ if [ ! -d "$raw" ]; then why="不是目录";
1048
+ elif [ ! -w "$raw" ]; then why="不可写"; fi
1049
+ fi
1050
+ printf '临时根不可用:%s(source=%s)%s —— 不可用,且不得换用别的根\n' "$raw" "$src" "$why"
1051
+ # 路线行 = 一整条**能直接跑**的命令(P151:命令与说明分行);说明留到下一行。
1052
+ printf ' 修法:mkdir -p %q\n' "$raw"
1053
+ printf ' 建好之后确认它可写;或者把 %s 指到另一个已存在的可写目录(references/config.md 的 TEAM_TMP_ROOT)\n' \
1054
+ "$([ "$src" = "tmpdir" ] && printf 'TMPDIR' || printf 'TEAM_TMP_ROOT')"
1055
+ return 1
1056
+ }
1057
+
1032
1058
  # ---------------------------------------------------------------- P140(dispatch-friction · R6)· 席位上一轮预提示
1033
1059
  # 两条腿各自独立、都可缺(判不出来一律沉默,不猜):
1034
1060
  # · 死因腿:agent-death-reason 的读取器给出 quota/balance —— 点名分类、来源、时间与原文;
@@ -1183,6 +1209,19 @@ team_dispatch_attempt_fail() {
1183
1209
  rm -f "${TEAM_ASSIGN_TMP:-/nonexistent}"
1184
1210
  team_tmux_kill_window "$TEAM_SESSION:$seat" >/dev/null 2>&1 || true
1185
1211
  }
1212
+ # P261(吸收 P253):退休键的迁移建议是一个**先出现**的块 —— 退休键没迁完,后面的派单前提(模型/身份)
1213
+ # 都无从谈。它在报告里占第一个位置(P140 的一次拒绝:谁先判谁先印),并把 TEAM_MODEL_POLICY_REPORTED
1214
+ # 置位 —— 身份步骤的 team_model_policy_guard 据此不再重印同一段文字(仍然拒绝,判据不变)。
1215
+ team_dispatch_judge_model_policy() {
1216
+ local issues
1217
+ TEAM_MODEL_POLICY_REPORTED=0
1218
+ issues="$(team_model_policy_issues)"
1219
+ [ -n "$issues" ] || return 0
1220
+ team_df_lines_err "$issues"
1221
+ TEAM_MODEL_POLICY_REPORTED=1
1222
+ return 1
1223
+ }
1224
+
1186
1225
  team_dispatch_execute() {
1187
1226
  team_require_cmd tmux "agent 在 tmux 窗口里跑,PM 需要能旁观与追问"
1188
1227
  local agent="" id="" taskfile="" model="" branch_flag="" fresh=0 printonly=0 overflow=0 force=0
@@ -1238,6 +1277,10 @@ team_dispatch_execute() {
1238
1277
  TEAM_DISPATCH_AUDIT_LINES=""
1239
1278
  TEAM_DISPATCH_STACK_PREV=""
1240
1279
 
1280
+ # ⓪ P261(吸收 P253):旧配置(退休键)是**本次派单的前提** —— 它的迁移建议先判、先印,占据这份
1281
+ # 拒绝的第一段;同一件事不再在下面的身份步骤里重印(team_model_policy_guard 认这个标记,仍然拒绝)。
1282
+ team_df_run team_dispatch_judge_model_policy
1283
+
1241
1284
  # ① 任务书歧义
1242
1285
  team_df_run team_dispatch_judge_briefs "$id" "$briefs" "$nbrief" "$taskfile"
1243
1286
 
@@ -1285,7 +1328,9 @@ team_dispatch_execute() {
1285
1328
  local TEAM_SELECTED_MODEL='' TEAM_SELECTED_SID='' TEAM_SELECTED_ORIGIN='' TEAM_LAUNCH_VIA='' TEAM_SELECTED_CATEGORY='' TEAM_SELECTED_MODE=''
1286
1329
  # Execute in this shell so the accepted identity is not lost through a subshell.
1287
1330
  if ! identity_output="$(team_dispatch_select_identity "$agent" "$id" "$taskfile" "$wt" "${TEAM_CHECKED_BRANCH:-$br_name}" "$model" "$fresh" 2>&1)"; then
1288
- identity_ok=0; team_df_run_lib team_dispatch_identity_refusal "$identity_output"
1331
+ # P261:空输出不冒充一条阻塞项(迁移块已在最前面报过时,身份步骤只静默地拒绝)。
1332
+ identity_ok=0
1333
+ if [ -n "$identity_output" ]; then team_df_run_lib team_dispatch_identity_refusal "$identity_output"; fi
1289
1334
  else
1290
1335
  team_dispatch_select_identity "$agent" "$id" "$taskfile" "$wt" "${TEAM_CHECKED_BRANCH:-$br_name}" "$model" "$fresh" >/dev/null || return 1
1291
1336
  model="$TEAM_SELECTED_MODEL"
@@ -1301,13 +1346,22 @@ team_dispatch_execute() {
1301
1346
  fi
1302
1347
 
1303
1348
  team_df_run_lib team_dispatch_judge_mem "$agent" "$id" "$taskfile"
1304
- # P144:磁盘/inode 腿 —— 判的是这个 worker 真正要写的两个文件系统(临时根 + 它的工作树,
1305
- # 不是共享的 worktrees 根),在**任何开窗动作之前**(--print 也在内),并且是 P140 的启动前
1306
- # 那一趟里的一个 finding(拒绝时和别的阻塞项一起交底,不抢自己的单独出口)。
1307
- local disk_tmp="${TMPDIR:-/tmp}"
1308
- team_df_run_lib team_disk_guard "$disk_tmp" "$wt"
1309
- # 读数是一条「说明」(rc=0 的 finding):放行时在启动前那一趟里打印;被拒时由拒绝本身带读数。
1310
- if [ "$_TEAM_DF_RUN_RC" -eq 0 ]; then team_df_run_lib team_capacity_line "$disk_tmp" "$wt"; fi
1349
+ # P309:临时根的**可用性**先判(显式选定的根不可用 = 阻塞项);地板再判它的字节/inode。
1350
+ team_df_run_lib team_dispatch_judge_tmp_root
1351
+ local tmp_ok="$_TEAM_DF_RUN_RC"
1352
+ # P144:磁盘/inode 腿 —— 判的是解析出的临时根 + 这个 worker 的工作树(不是共享的 worktrees 根),
1353
+ # 在**任何开窗动作之前**(--print 也在内)。P309:不在这里再算一遍默认值。
1354
+ local disk_tmp=""
1355
+ disk_tmp="$(team_tmp_root 2>/dev/null || true)"
1356
+ # 夹具红侧(只在 TEAM_SMOKE_FIXTURE=1 下生效):把地板指回固定的 /tmp —— 守门断言必须因此变红。
1357
+ if [ "${TEAM_SMOKE_FIXTURE:-0}" = "1" ] && [ "${TEAM_DISPATCH_FLOOR_BREAK:-}" = "fixed" ]; then disk_tmp="/tmp"; fi
1358
+ if [ "$tmp_ok" = "0" ] && [ -n "$disk_tmp" ]; then
1359
+ team_df_run_lib team_disk_guard "$disk_tmp" "$wt"
1360
+ # 读数是一条「说明」(rc=0 的 finding):放行时在启动前那一趟里打印;被拒时由拒绝本身带读数。
1361
+ if [ "$_TEAM_DF_RUN_RC" -eq 0 ]; then team_df_run_lib team_capacity_line "$disk_tmp" "$wt"; fi
1362
+ else
1363
+ team_df_say " 临时根不可用(见上面那个阻塞项)→ 磁盘余量没有可判的根,本次不判"
1364
+ fi
1311
1365
  [ "$identity_ok" != 1 ] || team_df_run_lib team_model_guard "$model" "$agent"
1312
1366
  # M4.3 A:会话规模 vs 模型窗口(默认拒绝,--fresh / --allow-overflow 是出路)
1313
1367
  [ "$identity_ok" != 1 ] || team_df_run_lib team_guard_resume_session "$agent" "$model" "$sid" "$wt" "$([ "$TEAM_SELECTED_MODE" = fresh ] && printf 1 || printf 0)" "$overflow" "$id" "$taskfile"
@@ -1329,6 +1383,8 @@ team_dispatch_execute() {
1329
1383
  fi
1330
1384
 
1331
1385
  [ "${_TEAM_DISPATCH_PREFLIGHT_ONLY:-0}" != 1 ] || return 0
1386
+ # P309:写盘前把解析出的根准备好(默认腿按需 mkdir 0700;显式根只校验,绝不代建)。--print 不创建。
1387
+ team_tmp_root_prepare >/dev/null || return 1
1332
1388
  if [ "$printonly" != 1 ]; then
1333
1389
  team_dispatch_final_snapshot "$agent" || return 1
1334
1390
  fi
@@ -1436,12 +1492,12 @@ team_dispatch_execute() {
1436
1492
  # P55(remain-on-exit 的时机是红线):占位命令先持窗 → 设选项并读回 → 才把 pane 交给 harness。
1437
1493
  # 顺序不能反:harness 先跑时它若秒退,窗口在设选项之前就没了(探针 P1/P3 = 2026-09-22 事故形状)。
1438
1494
  # respawn-pane 用 argv 形式(不经 shell 解析):harness 原样保留「bash -lc $inner $prompt-as-$0」。
1439
- tmux new-window -t "$TEAM_SESSION" -n "$agent" -d 'sleep 30' >/dev/null 2>&1 || true
1495
+ team_tmux new-window -t "$TEAM_SESSION" -n "$agent" -d 'sleep 30' >/dev/null 2>&1 || true
1440
1496
  if team_agent_window_exists "$agent"; then
1441
- tmux set-window-option -t "$TEAM_SESSION:$agent" remain-on-exit on >/dev/null 2>&1 || true
1442
- local roe; roe="$(tmux show-options -w -v -t "$TEAM_SESSION:$agent" remain-on-exit 2>/dev/null || true)"
1497
+ team_tmux set-window-option -t "$TEAM_SESSION:$agent" remain-on-exit on >/dev/null 2>&1 || true
1498
+ local roe; roe="$(team_tmux show-options -w -v -t "$TEAM_SESSION:$agent" remain-on-exit 2>/dev/null || true)"
1443
1499
  if [ "$roe" = "on" ]; then
1444
- tmux respawn-pane -k -t "$TEAM_SESSION:$agent" bash -lc "$inner" "$prompt" >/dev/null 2>&1 || true
1500
+ team_tmux respawn-pane -k -t "$TEAM_SESSION:$agent" bash -lc "$inner" "$prompt" >/dev/null 2>&1 || true
1445
1501
  else
1446
1502
  # 读回失败 = 这一轮的启动作废:窗口留给下一轮的重用分支杀(没有下一轮则由失败路径杀),
1447
1503
  # 绝不 return —— 否则「重试一次 + 失败诊断」的既有契约会被这条新守卫短路。
@@ -1534,7 +1590,7 @@ team_dispatch_execute() {
1534
1590
 
1535
1591
  team_pane_snapshot() { # <target> → pane 内容指纹(用于确认投递真的落到 TUI)
1536
1592
  team_tmux_target_required "capture-pane" "${1:-}" || return 1
1537
- tmux capture-pane -p -t "$1" 2>/dev/null | tail -c 400 | cksum | tr -d ' \n'
1593
+ team_tmux capture-pane -p -t "$1" 2>/dev/null | tail -c 400 | cksum | tr -d ' \n'
1538
1594
  }
1539
1595
 
1540
1596
  # agent 没在跑时:消息仍然要落到收件箱(durable),但绝不打字(空提示符会当命令执行)
@@ -1644,11 +1700,250 @@ team_cmd_say() {
1644
1700
  }
1645
1701
 
1646
1702
  team_inbox_append() { # <agent> <tag> <msg> [<sender>]
1647
- local dir; dir="$(team_inbox_dir)"
1648
- mkdir -p "$dir"
1703
+ local line
1649
1704
  # P82:第 4 参可选 = **发送者**(notify 传解析出来的发送者,收件人只当文件名);
1650
1705
  # say/draft/pulse 不传,沿用「owner 标签」(它们另有 --from/标签语义,本次不动)。
1651
- printf -- '- %s [%s] agent:%s · %s\n' "$(team_timestamp)" "$2" "${4:-$1}" "$3" >> "$dir/$1.md"
1706
+ line="$(printf '%s [%s] agent:%s · %s' "$(team_timestamp)" "$2" "${4:-$1}" "$3")"
1707
+ # turn-notice-merge:与扩展的合并路径共用**同一把锁**(同一收件人)。手工/队列/pulse 行的 tag 不是
1708
+ # auto 类 → 不参与合并、不进明细,但它的追加仍然落在临界区里(不会与合并的截尾重写互相丢写)。
1709
+ team_inbox_write_line "$1" "$line" >/dev/null
1710
+ }
1711
+
1712
+ # ---------------------------------------------------------------- 收件箱写入口(turn-notice-merge · 写入面)
1713
+ # 合同在 openspec/specs/notify-and-inbox(ADDED「raw events stay in a bounded detail file」+ MODIFIED 的
1714
+ # 合并键/合并行/叫醒段)。这里的实现要点:
1715
+ # ① 合并在**写入侧**、只认收件箱的**尾行**(截尾重写),锚校验不过一律追加(fail-safe);
1716
+ # ② 每收件人一把锁(flock;没有 flock 时降级为无锁,行为与历史一致);
1717
+ # ③ **先明细、后合并判定**:state/notify.log 一行一事件,所以汇总行的 `×N` 永远等于该 run 的
1718
+ # 明细记录数;明细写失败 → 本事件不合并、行带 `detail=unavailable`、日志点名,该行也不做锚;
1719
+ # ④ 只有 [auto*] 类行参与合并与明细;[manual]/[draft]/[nudge]/pulse 行原样追加。
1720
+
1721
+ # 行 → 合并键(seat|class|task|awaiting)。非 [auto*] 类 / 解析不成立 → rc 1(调用方按「不可合并」处理)。
1722
+ # awaiting 是**集合**(去重、排序;缺字段与空集是两个不同的值);task 取 task= 戳里的 ID,否则取
1723
+ # agent 后的第一个 <ID> token;branch/tip/uncommitted 不进键(它们只更新显示值)。
1724
+ team_notify_line_key() {
1725
+ local body="$1"
1726
+ case "$body" in '- '*) body="${body#- }" ;; esac
1727
+ local iso rest tag class seat fields aw nrm t
1728
+ iso="${body%% *}"
1729
+ case "$iso" in ''|*[!0-9TZ:.-]*) return 1 ;; esac
1730
+ rest="${body#"$iso" }"
1731
+ [ "$rest" != "$body" ] || return 1
1732
+ # ⚠ 前缀(未提交告警)不是键的一部分:跳过它直到 tag 的 '['
1733
+ case "$rest" in
1734
+ '['*) ;;
1735
+ '⚠'*) rest="[${rest#*\[}" ;;
1736
+ *) return 1 ;;
1737
+ esac
1738
+ rest="${rest#\[}"
1739
+ tag="${rest%%\]*}"
1740
+ rest="${rest#"$tag"\]}"
1741
+ case "$rest" in ' '*) rest="${rest# }" ;; *) return 1 ;; esac
1742
+ case "$tag" in
1743
+ auto) class=delivered ;;
1744
+ 'auto·suspended') class=suspended ;;
1745
+ 'auto·interrupted') class=interrupted ;;
1746
+ *) return 1 ;;
1747
+ esac
1748
+ case "$rest" in agent:*) ;; *) return 1 ;; esac
1749
+ rest="${rest#agent:}"
1750
+ seat="${rest%% *}"
1751
+ [ -n "$seat" ] || return 1
1752
+ rest="${rest#"$seat"}"
1753
+ case "$rest" in ' '*) rest="${rest# }" ;; *) return 1 ;; esac
1754
+ fields="${body%% :: *}"
1755
+ nrm='-'
1756
+ case "$fields" in
1757
+ *awaiting=*)
1758
+ aw="${fields#*awaiting=}"; aw="${aw%% *}"
1759
+ nrm="A:$(printf '%s' "$aw" | tr ',' '\n' | sed 's/^[[:space:]]*//; s/[[:space:]]*$//' | grep -v '^$' | LC_ALL=C sort -u | paste -sd, -)" ;;
1760
+ esac
1761
+ if [[ "$fields" =~ task=([A-Za-z0-9._-]+) ]]; then
1762
+ t="${BASH_REMATCH[1]}"
1763
+ else
1764
+ case "$rest" in '· '*) rest="${rest#· }" ;; esac
1765
+ t="${rest%% · *}"
1766
+ t="${t%% *}"
1767
+ fi
1768
+ [ -n "$t" ] || t='?'
1769
+ printf '%s|%s|%s|%s\n' "$seat" "$class" "$t" "$nrm"
1770
+ }
1771
+
1772
+ # 尾行能不能当锚:带 detail=unavailable 的行不是锚(否则下一次成功的事件会把它抹掉,缺口就不可见了)。
1773
+ team_notify_line_anchor_ok() {
1774
+ case "$1" in *'detail=unavailable'*) return 1 ;; esac
1775
+ return 0
1776
+ }
1777
+
1778
+ team_notify_line_iso() { local body="${1#- }"; printf '%s\n' "${body%% *}"; }
1779
+
1780
+ team_notify_line_iso_last() { # <行> → 字段区里 last=<ISO> 的值(没有 → 空)
1781
+ local body="${1#- }" fields v
1782
+ fields="${body%% :: *}"
1783
+ case "$fields" in
1784
+ *'last='*) v="${fields#*last=}"; v="${v%% *}" ;;
1785
+ *) v='' ;;
1786
+ esac
1787
+ printf '%s\n' "$v"
1788
+ }
1789
+
1790
+ # 行已汇总的事件数(汇总行带 `×N`;单事件行 = 1)。只读字段区(` :: ` 之前)。
1791
+ team_notify_line_events() {
1792
+ local body="${1#- }" head n
1793
+ head="${body%% :: *}"
1794
+ case "$head" in
1795
+ *'×'*)
1796
+ n="${head#*×}"; n="${n%% *}"
1797
+ case "$n" in ''|*[!0-9]*) n=1 ;; esac ;;
1798
+ *) n=1 ;;
1799
+ esac
1800
+ printf '%s\n' "$n"
1801
+ }
1802
+
1803
+ # 汇总行 = **最后一条事件的行** + 首事件时间戳 + 字段区 `×N first= last=`(branch/tip/uncommitted 自动是最后一条的值)。
1804
+ team_notify_line_merge() { # <新事件行> <首时间戳> <n> <末时间戳>
1805
+ local c="$1" first="$2" n="$3" last="$4" head tail rest
1806
+ case "$c" in
1807
+ *' :: '*) head="${c%% :: *}"; tail="${c#* :: }" ;;
1808
+ *) head="$c"; tail='' ;;
1809
+ esac
1810
+ rest="${head#* }"
1811
+ head="${first} ${rest} · ×${n} first=${first} last=${last}"
1812
+ if [ "${c%% :: *}" != "$c" ]; then printf '%s :: %s\n' "$head" "$tail"; else printf '%s\n' "$head"; fi
1813
+ }
1814
+
1815
+ team_notify_line_mark_detail() { # <行> · 字段区带 detail=unavailable(明细写失败的事件,绝不参与合并)
1816
+ local c="$1"
1817
+ case "$c" in
1818
+ *' :: '*) printf '%s · detail=unavailable :: %s\n' "${c%% :: *}" "${c#* :: }" ;;
1819
+ *) printf '%s · detail=unavailable\n' "$c" ;;
1820
+ esac
1821
+ }
1822
+
1823
+ team_notify_log_line() { # <文本>:写进扩展日志(TEAM_NOTIFY_LOG)
1824
+ local f="${TEAM_NOTIFY_LOG:-/tmp/teamsmith-notify.log}"
1825
+ printf '%s %s\n' "$(team_timestamp)" "$1" >> "$f" 2>/dev/null || true
1826
+ }
1827
+
1828
+ team_notify_detail_max() {
1829
+ local n="${TEAM_NOTIFY_DETAIL_MAX:-2048}"
1830
+ case "$n" in ''|*[!0-9]*) n=2048 ;; esac
1831
+ [ "$n" -gt 0 ] || n=2048
1832
+ printf '%s\n' "$n"
1833
+ }
1834
+
1835
+ team_notify_detail_events() { # <明细文件> → 事件行数(轮转头不算)
1836
+ local n=''
1837
+ if [ -f "$1" ]; then n="$(grep -c '^- ' "$1" 2>/dev/null)" || true; fi
1838
+ case "$n" in ''|*[!0-9]*) n=0 ;; esac
1839
+ printf '%s\n' "$n"
1840
+ }
1841
+
1842
+ # 先明细:一行一事件(内容 = 该事件单发形状的收件箱行)。越界 → 轮转一代到 <file>.1 + 新代轮转头。
1843
+ team_notify_detail_append() { # <事件行> <明细文件> → 0 = 已落盘;1 = 失败(调用方写 detail=unavailable)
1844
+ local content="$1" file="$2" dir max count
1845
+ dir="$(dirname "$file")"
1846
+ mkdir -p "$dir" || return 1
1847
+ max="$(team_notify_detail_max)"
1848
+ count="$(team_notify_detail_events "$file")"
1849
+ if [ "$count" -ge "$max" ]; then
1850
+ mv -f "$file" "$file.1" || return 1
1851
+ printf '%s\n' "# rotation $(team_timestamp) moved=${count} path=${file}.1" > "$file" || return 1
1852
+ team_notify_log_line "notify detail rotated: moved=${count} to=${file}.1"
1853
+ fi
1854
+ printf -- '- %s\n' "$content" >> "$file" 2>/dev/null || return 1
1855
+ return 0
1856
+ }
1857
+
1858
+ # 截掉尾行、写回汇总行(同一目录的临时文件 + mv,读者不会看到半行)。
1859
+ team_inbox_rewrite_last() { # <收件箱文件> <新尾行> → 0 = 已重写;1 = 没动
1860
+ local file="$1" line="$2" dir tmp
1861
+ dir="$(dirname "$file")"
1862
+ tmp="$(mktemp "$dir/.inbox-merge.XXXXXX")" || return 1
1863
+ if ! sed '$d' "$file" > "$tmp" || ! printf -- '- %s\n' "$line" >> "$tmp"; then
1864
+ rm -f "$tmp"
1865
+ return 1
1866
+ fi
1867
+ [ -f "$file" ] && chmod --reference="$file" "$tmp" 2>/dev/null || true
1868
+ if ! mv -f "$tmp" "$file" 2>/dev/null; then rm -f "$tmp"; return 1; fi
1869
+ return 0
1870
+ }
1871
+
1872
+ # 临界区(调用方持锁):先明细 → 尾行锚判定 → 截尾重写或追加 → 打印写入结果。
1873
+ team_inbox_write_locked() { # <recipient> <行> <文件> <明细> → state=new|extended first=<ISO> key=<键>
1874
+ local recipient="$1" content="$2" file="$3" detail="$4"
1875
+ local key='' detail_failed=0 newcontent="$content" state=new first='' tail_line merged n
1876
+ key="$(team_notify_line_key "$content" || true)"
1877
+ if [ -n "$key" ]; then
1878
+ if ! team_notify_detail_append "$content" "$detail"; then
1879
+ detail_failed=1
1880
+ newcontent="$(team_notify_line_mark_detail "$content")"
1881
+ team_notify_log_line "notify detail write failed: $detail(本事件不合并,行带 detail=unavailable)"
1882
+ fi
1883
+ fi
1884
+ first="$(team_notify_line_iso "$newcontent")"
1885
+ if [ -n "$key" ] && [ "$detail_failed" = 0 ] && [ -s "$file" ]; then
1886
+ tail_line="$(tail -n 1 "$file")"
1887
+ if [ -n "$tail_line" ] && team_notify_line_anchor_ok "$tail_line" \
1888
+ && [ "$(team_notify_line_key "$tail_line" 2>/dev/null || true)" = "$key" ]; then
1889
+ n=$(( $(team_notify_line_events "$tail_line") + 1 ))
1890
+ merged="$(team_notify_line_merge "$newcontent" "$(team_notify_line_iso "$tail_line")" "$n" "$first")"
1891
+ if team_inbox_rewrite_last "$file" "$merged"; then
1892
+ state=extended
1893
+ first="$(team_notify_line_iso "$tail_line")"
1894
+ fi
1895
+ fi
1896
+ fi
1897
+ if [ "$state" = new ]; then
1898
+ printf -- '- %s\n' "$newcontent" >> "$file" || return 1
1899
+ fi
1900
+ # 写入结果协议(单行一段,扩展用 ^first=/^key= 解析):state=new|extended
1901
+ printf 'state=%s\nfirst=%s\nkey=%s\n' "$state" "$first" "${key:--}"
1902
+ return 0
1903
+ }
1904
+
1905
+ # 每收件人一把锁的写入口(team_inbox_append 与扩展的 __inbox-write 共用)。
1906
+ team_inbox_write_line() { # <recipient> <行> → 打印写入结果(同 team_inbox_write_locked)
1907
+ local recipient="$1" content="$2"
1908
+ local dir file detail lockfd rc=0
1909
+ dir="$(team_inbox_dir)"; file="$dir/$recipient.md"
1910
+ local state; state="$(team_state_dir)"
1911
+ detail="$state/notify.log"
1912
+ mkdir -p "$dir" || return 1
1913
+ if command -v flock >/dev/null 2>&1; then
1914
+ # exec 加**不带命令**的重定向会永久改变当前 shell:`exec {fd}>&- 2>/dev/null` 会把 stderr 永久接到
1915
+ # /dev/null(P251 实测:say 的 team_warn 从此消失)。这里只关 fd,不带任何 stderr 重定向。
1916
+ if ! exec {lockfd}>"$state/inbox-$recipient.lock"; then return 1; fi
1917
+ if flock -w 10 "$lockfd"; then
1918
+ team_inbox_write_locked "$recipient" "$content" "$file" "$detail" || rc=$?
1919
+ else
1920
+ team_notify_log_line "inbox lock timeout: $state/inbox-$recipient.lock"
1921
+ rc=1
1922
+ fi
1923
+ exec {lockfd}>&-
1924
+ return $rc
1925
+ fi
1926
+ team_inbox_write_locked "$recipient" "$content" "$file" "$detail"
1927
+ }
1928
+
1929
+ # 内部命令(扩展消费写入结果;不进 help):--agent <席位> --from-file <单行文件>
1930
+ team_cmd_inbox_write() {
1931
+ local agent='' src=''
1932
+ while [ $# -gt 0 ]; do
1933
+ case "$1" in
1934
+ --agent) agent="${2:?--agent 需要值}"; shift 2 ;;
1935
+ --agent=*) agent="${1#*=}"; shift ;;
1936
+ --from-file) src="${2:?--from-file 需要文件}"; shift 2 ;;
1937
+ --from-file=*) src="${1#*=}"; shift ;;
1938
+ -*) team_usage_die "__inbox-write: 未知参数 $1" ;;
1939
+ *) team_usage_die "__inbox-write: 多余参数 $1" ;;
1940
+ esac
1941
+ done
1942
+ [ -n "$agent" ] || team_usage_die "__inbox-write: 需要 --agent <席位>"
1943
+ if [ -z "$src" ] || [ ! -f "$src" ]; then team_usage_die "__inbox-write: 需要 --from-file <行文件>"; fi
1944
+ local content; content="$(head -n 1 "$src")"
1945
+ if [ -z "$content" ]; then printf 'state=failed\nfirst=-\nkey=-\n'; return 1; fi
1946
+ team_inbox_write_line "$agent" "$content"
1652
1947
  }
1653
1948
 
1654
1949
  # notify 的去重键:内容 + 长度(同一份通知在 TEAM_NOTIFY_DEDUP_SEC 内只入队/投递一次)。
@@ -1800,7 +2095,7 @@ team_teardown_seat_locked() {
1800
2095
  if [ "$register" = 1 ]; then team_config_write_roster remove "$a" "$fp" 0 || return $?; fi
1801
2096
  w="$(team_state_get "$a" window "$a")"
1802
2097
  if team_tmux_has_window "$TEAM_SESSION" "$w"; then
1803
- tmux kill-window -t "$TEAM_SESSION:$w" 2>/dev/null || return 1
2098
+ team_tmux kill-window -t "$TEAM_SESSION:$w" 2>/dev/null || return 1
1804
2099
  team_ok "kill window $TEAM_SESSION:$w"
1805
2100
  fi
1806
2101
  team_state_clear "$a"
@@ -194,7 +194,7 @@ team_cmd_bootstrap() {
194
194
  if [ -n "$legacy_keys" ]; then
195
195
  team_err "bootstrap: $TEAM_CONFIG 还在用退休的模型键($(printf '%s' "$legacy_keys" | tr '\n' ' '))—— 任何写入之前停住"
196
196
  team_dim " 项目模型策略是破坏式升级:bootstrap 不是迁移路径(init --force 也不是)"
197
- team_dim " 升级(先预览):$TEAM_CLI config upgrade-models --task-models '<category=provider/model …>' --pm-model '<provider/model>' --dry-run"
197
+ team_legacy_model_route_lines "$TEAM_CONFIG"
198
198
  return 1
199
199
  fi
200
200
  fi
@@ -291,7 +291,7 @@ team_cmd_bootstrap() {
291
291
  plan_models="--task-models '<category=provider/model …>' --pm-model '<provider/model>'(新鲜项目必填)"
292
292
  fi
293
293
  printf ' 1. %s init --session %s --pm-window %s --agents "%s" --vcs %s %s\n' "$TEAM_CLI" "$session" "$pmwin" "$agents" "$vcs" "$plan_models"
294
- printf ' 1b. 把 skill 装进项目 %s(%s init 的同一实现;已存在则 skip —— 老项目的升级路径)\n' '.pi/skills/' "$TEAM_CLI"
294
+ printf ' 1b. 把 skill 与 /team 扩展装进项目 %s 与 %s(%s init 的同一实现;已存在则 skip —— 老项目的升级路径)\n' '.pi/skills/' '.pi/extensions/' "$TEAM_CLI"
295
295
  printf ' 2. 把门禁/安装命令写进 .pi/team/config.sh(%s / %s)\n' "${gates:-无}" "${install_cmd:-无}"
296
296
  printf ' 3. 为每个 agent 建 worktree:%s\n' "$(printf 'add-agent %s; ' $agents)"
297
297
  printf ' 4. %s pulse up(巡检窗口:同 session 的 %s 窗口跑 monitor + 定时巡检)\n' "$TEAM_CLI" "$(team_pulse_window)"