teamsmith 0.1.2 → 0.2.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 (97) hide show
  1. package/README.md +13 -7
  2. package/package.json +1 -1
  3. package/skills/teamsmith/CHANGELOG.md +39 -0
  4. package/skills/teamsmith/SKILL.md +18 -7
  5. package/skills/teamsmith/references/agent-adapters.md +7 -7
  6. package/skills/teamsmith/references/config.md +29 -15
  7. package/skills/teamsmith/references/migration.md +38 -2
  8. package/skills/teamsmith/references/protocol.md +81 -13
  9. package/skills/teamsmith/references/workflows.md +31 -19
  10. package/skills/teamsmith/scripts/lib/cmd-agents.sh +210 -70
  11. package/skills/teamsmith/scripts/lib/cmd-bootstrap.sh +70 -9
  12. package/skills/teamsmith/scripts/lib/cmd-config.sh +222 -70
  13. package/skills/teamsmith/scripts/lib/cmd-death.sh +2 -15
  14. package/skills/teamsmith/scripts/lib/cmd-docs.sh +6 -3
  15. package/skills/teamsmith/scripts/lib/cmd-project.sh +134 -17
  16. package/skills/teamsmith/scripts/lib/cmd-reply.sh +96 -0
  17. package/skills/teamsmith/scripts/lib/cmd-review.sh +13 -10
  18. package/skills/teamsmith/scripts/lib/cmd-status.sh +42 -13
  19. package/skills/teamsmith/scripts/lib/cmd-watch.sh +75 -13
  20. package/skills/teamsmith/scripts/lib/common.sh +797 -71
  21. package/skills/teamsmith/scripts/monitor.mjs +34 -3
  22. package/skills/teamsmith/scripts/panel/README.md +22 -11
  23. package/skills/teamsmith/scripts/panel/panel.js +217 -215
  24. package/skills/teamsmith/scripts/panel/src/App.tsx +421 -164
  25. package/skills/teamsmith/scripts/panel/src/data.ts +84 -4
  26. package/skills/teamsmith/scripts/panel/src/layout.ts +502 -91
  27. package/skills/teamsmith/scripts/panel/src/main.tsx +97 -12
  28. package/skills/teamsmith/scripts/panel/src/settings.ts +1 -1
  29. package/skills/teamsmith/scripts/panel/src/strings/en.ts +56 -21
  30. package/skills/teamsmith/scripts/panel/src/strings/zh.ts +56 -21
  31. package/skills/teamsmith/scripts/panel/src/types.ts +178 -16
  32. package/skills/teamsmith/scripts/replies.mjs +893 -0
  33. package/skills/teamsmith/scripts/team +1 -0
  34. package/skills/teamsmith/templates/AGENTS.section.md.tmpl +15 -2
  35. package/skills/teamsmith/templates/BOARD.md.tmpl +2 -2
  36. package/skills/teamsmith/templates/OWNERSHIP.md.tmpl +7 -3
  37. package/skills/teamsmith/templates/PROTOCOL.md.tmpl +17 -0
  38. package/skills/teamsmith/templates/config.sh.tmpl +10 -5
  39. package/skills/teamsmith/templates/memory-seed.md.tmpl +3 -0
  40. package/skills/teamsmith/templates/pm-prompt.md.tmpl +20 -1
  41. package/skills/teamsmith/templates/report.md.tmpl +12 -0
  42. package/skills/teamsmith/templates/task.md.tmpl +4 -0
  43. package/skills/teamsmith/tests/config-cli.sh +162 -288
  44. package/skills/teamsmith/tests/death-cause.sh +5 -2
  45. package/skills/teamsmith/tests/install-shape.sh +4 -2
  46. package/skills/teamsmith/tests/key-replies-pty.sh +375 -0
  47. package/skills/teamsmith/tests/key-replies-ui.sh +332 -0
  48. package/skills/teamsmith/tests/key-replies.sh +1075 -0
  49. package/skills/teamsmith/tests/ledger-ban.sh +4 -4
  50. package/skills/teamsmith/tests/ledger-claim.sh +247 -0
  51. package/skills/teamsmith/tests/lib/model-policy.sh +26 -0
  52. package/skills/teamsmith/tests/lib/model-routing-boundary.sh +420 -0
  53. package/skills/teamsmith/tests/lib/model-routing-expansion.sh +155 -0
  54. package/skills/teamsmith/tests/lib/model-routing-flips.py +136 -0
  55. package/skills/teamsmith/tests/lib/model-routing-roles.sh +250 -0
  56. package/skills/teamsmith/tests/lib/proc-io.sh +103 -0
  57. package/skills/teamsmith/tests/lib/reply-fixture.sh +372 -0
  58. package/skills/teamsmith/tests/lib/tmux-iso.sh +8 -0
  59. package/skills/teamsmith/tests/panel-b2.sh +1 -1
  60. package/skills/teamsmith/tests/panel-b3-stub.sh +27 -0
  61. package/skills/teamsmith/tests/panel-b3.sh +14 -10
  62. package/skills/teamsmith/tests/panel-choices.sh +74 -61
  63. package/skills/teamsmith/tests/panel-cpu.sh +1 -1
  64. package/skills/teamsmith/tests/panel-p21.sh +311 -190
  65. package/skills/teamsmith/tests/perf.sh +1 -1
  66. package/skills/teamsmith/tests/pm-box-real.sh +1 -1
  67. package/skills/teamsmith/tests/pulse-nudge-key.sh +1 -1
  68. package/skills/teamsmith/tests/routes.sh +43 -22
  69. package/skills/teamsmith/tests/section-budgets.tsv +8 -4
  70. package/skills/teamsmith/tests/section-paths.tsv +26 -16
  71. package/skills/teamsmith/tests/section-select.sh +82 -6
  72. package/skills/teamsmith/tests/smoke.sh +782 -180
  73. package/skills/teamsmith/tests/snapshots/zh-dark-120-detail.txt +2 -2
  74. package/skills/teamsmith/tests/snapshots/zh-dark-120-p4.txt +2 -2
  75. package/skills/teamsmith/tests/snapshots/zh-dark-120.txt +9 -9
  76. package/skills/teamsmith/tests/snapshots/zh-dark-160-p4.txt +2 -2
  77. package/skills/teamsmith/tests/snapshots/zh-dark-160.txt +9 -9
  78. package/skills/teamsmith/tests/snapshots/zh-dark-59-detail.txt +1 -1
  79. package/skills/teamsmith/tests/snapshots/zh-dark-59-p4.txt +1 -1
  80. package/skills/teamsmith/tests/snapshots/zh-dark-59.txt +5 -5
  81. package/skills/teamsmith/tests/snapshots/zh-dark-99-p4.txt +2 -2
  82. package/skills/teamsmith/tests/snapshots/zh-dark-99.txt +5 -5
  83. package/skills/teamsmith/tests/snapshots/zh-light-120-detail.txt +2 -2
  84. package/skills/teamsmith/tests/snapshots/zh-light-120-p4.txt +2 -2
  85. package/skills/teamsmith/tests/snapshots/zh-light-120.txt +9 -9
  86. package/skills/teamsmith/tests/snapshots/zh-light-160-p4.txt +2 -2
  87. package/skills/teamsmith/tests/snapshots/zh-light-160.txt +9 -9
  88. package/skills/teamsmith/tests/snapshots/zh-light-59-detail.txt +1 -1
  89. package/skills/teamsmith/tests/snapshots/zh-light-59-p4.txt +1 -1
  90. package/skills/teamsmith/tests/snapshots/zh-light-59.txt +5 -5
  91. package/skills/teamsmith/tests/snapshots/zh-light-99-p4.txt +2 -2
  92. package/skills/teamsmith/tests/snapshots/zh-light-99.txt +5 -5
  93. package/skills/teamsmith/tests/task-header-model.sh +2 -1
  94. package/skills/teamsmith/tests/task-model-routing.sh +1014 -0
  95. package/skills/teamsmith-init/SKILL.md +38 -38
  96. package/skills/teamsmith-init/references/bootstrap.md +6 -4
  97. package/skills/teamsmith-init/templates/bootstrap-prompt.md.tmpl +9 -5
@@ -21,8 +21,12 @@
21
21
  # 换行、`#` 一律拒绝;notify 扩展那 8 个扁平读取器解析的键出现 ' 也拒绝(那个读取器没有转义)。
22
22
  # * 原子写:同目录临时文件 → bash -n 复核 → 保留权限 → mv;任何失败都留下原字节、不留临时文件。
23
23
  # 返回 0 = 已写入;非 0 = 拒绝/写失败(原因在 stderr)。
24
- team_config_set_in_file() { # <file> <KEY> <value>
25
- local f="$1" k="$2" v="${3-}"
24
+ team_config_set_in_file() {
25
+ if [ "${TEAM_CONFIG_LOCKED:-0}" = 1 ]; then team_config_set_in_file_unlocked "$@"
26
+ else team_with_lock "config:$(readlink -m "$1")" team_config_locked_call team_config_set_in_file_unlocked "$@"; fi
27
+ }
28
+ team_config_set_in_file_unlocked() { # <file> <KEY> <value> [remove]
29
+ local f="$1" k="$2" v="${3-}" remove="${4:-}"
26
30
  [ -n "$f" ] && [ -n "$k" ] || { printf 'config writer: 缺少文件或键名\n' >&2; return 1; }
27
31
  case "$k" in
28
32
  ''|[!A-Za-z_]*|*[!A-Za-z0-9_]*) printf 'config writer: 非法键名 %s\n' "$k" >&2; return 1 ;;
@@ -62,13 +66,17 @@ team_config_set_in_file() { # <file> <KEY> <value>
62
66
  if [ "$found" = "0" ] && [[ "$line" =~ ^[[:space:]]*(export[[:space:]]+)?$k= ]]; then
63
67
  found=1
64
68
  comment="$(printf '%s' "$line" | team_config_inline_comment_of_line)"
65
- newline="${form}${k}='${quoted}'${comment}"
66
- out+=("$newline")
69
+ if [ "$remove" = remove ]; then
70
+ [ -z "$comment" ] || out+=("$comment")
71
+ else
72
+ newline="${form}${k}='${quoted}'${comment}"
73
+ out+=("$newline")
74
+ fi
67
75
  else
68
76
  out+=("$line")
69
77
  fi
70
78
  done
71
- if [ "$found" = "0" ]; then
79
+ if [ "$found" = "0" ] && [ "$remove" != remove ]; then
72
80
  newline="${form}${k}='${quoted}'"
73
81
  out+=("$newline")
74
82
  had_nl=1
@@ -153,12 +161,20 @@ team_detect_install_cmd() {
153
161
 
154
162
  team_cmd_bootstrap() {
155
163
  local agents="" session="" pmwin="" with_pulse=1 print_only=0
164
+ local task_models="" pm_model="" task_models_set=0 pm_model_set=0
156
165
  while [ $# -gt 0 ]; do
157
166
  case "$1" in
158
167
  --agents) agents="${2:?}"; shift 2 ;;
159
168
  --create-worktrees) TEAM_CREATE_WORKTREE=1; shift ;;
160
169
  --session) session="${2:?}"; shift 2 ;;
161
170
  --pm-window) pmwin="${2:?}"; shift 2 ;;
171
+ --task-models) task_models="${2:?}"; task_models_set=1; shift 2 ;;
172
+ --pm-model) pm_model="${2:?}"; pm_model_set=1; shift 2 ;;
173
+ --model|--default-model)
174
+ team_err "bootstrap: $1 已退休:项目不再有席位/全局默认模型"
175
+ team_dim " 新项目:$TEAM_CLI bootstrap --agents 'dev verify' --task-models '<category=provider/model …>' --pm-model '<provider/model>'"
176
+ team_dim " 已有项目升级:$TEAM_CLI config upgrade-models --task-models '<完整映射>' --pm-model '<独立模型>' --dry-run"
177
+ return 2 ;;
162
178
  --no-pulse) with_pulse=0; shift ;;
163
179
  --no-watchdog) with_pulse=0; shift ;; # 旧旗标(别名期保留到 v2.0.0):与 --no-pulse 同义
164
180
  --print) print_only=1; shift ;;
@@ -171,6 +187,44 @@ team_cmd_bootstrap() {
171
187
  local project; project="$(basename "$TEAM_MAIN_ROOT")"
172
188
  local had_config=0; [ -n "$TEAM_CONFIG" ] && had_config=1
173
189
 
190
+ # ⓪ 模型策略闸门(P235):退休键/非法策略/缺失输入都在**任何写入**(install/账本/worktree/pulse)
191
+ # 之前停住;--print 只诊断、不写。已有合法新策略允许不带输入重入(保留策略)。
192
+ if [ "$had_config" = "1" ]; then
193
+ local legacy_keys; legacy_keys="$(team_config_legacy_model_keys "$TEAM_CONFIG")"
194
+ if [ -n "$legacy_keys" ]; then
195
+ team_err "bootstrap: $TEAM_CONFIG 还在用退休的模型键($(printf '%s' "$legacy_keys" | tr '\n' ' '))—— 任何写入之前停住"
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"
198
+ return 1
199
+ fi
200
+ fi
201
+ local _policy _prc=0
202
+ if [ "$print_only" = "1" ] && [ "$had_config" != "1" ]; then
203
+ # 新鲜项目的 --print:只预览,模型输入必填这件事写在计划里(真跑才拒,且拒绝在任何写入之前)
204
+ :
205
+ else
206
+ _policy="$(team_init_model_policy_resolve "${TEAM_CONFIG:-}" "$task_models" "$pm_model" "$task_models_set" "$pm_model_set" bootstrap)" || _prc=$?
207
+ [ "$_prc" -eq 0 ] || return "$_prc"
208
+ task_models="$(printf '%s\n' "$_policy" | sed -n '1p')"
209
+ pm_model="$(printf '%s\n' "$_policy" | sed -n '2p')"
210
+ fi
211
+ # 已有配置(不带 --force)原样保留:显式输入与现有策略不同就拒绝,不静默忽略。
212
+ if [ "$had_config" = "1" ] && [ -n "$task_models" ]; then
213
+ local cur_map cur_pm
214
+ cur_map="$(team_config_file_value "$TEAM_CONFIG" TEAM_TASK_MODELS 2>/dev/null || true)"
215
+ cur_pm="$(team_config_file_value "$TEAM_CONFIG" TEAM_PM_MODEL 2>/dev/null || true)"
216
+ if [ "$task_models_set" = "1" ] && [ "$task_models" != "$cur_map" ]; then
217
+ team_err "bootstrap: 现有配置会被保留,但 --task-models 与现有映射不同 —— 不静默忽略"
218
+ team_dim " 改一个类别:$TEAM_CLI config set-task-model <category> <model>;整映射:$TEAM_CLI config set TEAM_TASK_MODELS '<完整映射>' --yes"
219
+ return 4
220
+ fi
221
+ if [ "$pm_model_set" = "1" ] && [ "$pm_model" != "$cur_pm" ]; then
222
+ team_err "bootstrap: 现有配置会被保留,但 --pm-model 与现有值不同 —— 不静默忽略"
223
+ team_dim " 改 PM 模型:$TEAM_CLI config set TEAM_PM_MODEL '<provider/model>' --yes"
224
+ return 4
225
+ fi
226
+ fi
227
+
174
228
  # ① 探测 PM 自己所在的 tmux session/窗口
175
229
  local det_sess="" det_win="" det_cwd=""
176
230
  if [ -n "${TMUX:-}" ] && team_have_cmd tmux; then
@@ -223,13 +277,20 @@ team_cmd_bootstrap() {
223
277
  if [ -n "$rename_note" ]; then printf ' %s\n' "$rename_note"; fi
224
278
  if [ -n "$rename_cmd" ]; then printf ' %s\n' "改名:$rename_cmd"; fi
225
279
  printf ' 名册 %s\n' "$agents"
280
+ printf ' 模型策略 %s [独立 PM:%s]\n' "${task_models:-<新鲜项目必填:--task-models '<category=provider/model …>'>}" "${pm_model:-<必填:--pm-model '<provider/model>'>}"
226
281
  printf ' 版本控制 %s | 门禁 %s | 安装 %s\n' "$vcs" "${gates:-<无>}" "${install_cmd:-<无>}"
227
282
  printf ' 巡检 %s\n' "$([ "$with_pulse" = "1" ] && echo "tmux 窗口 $(team_slug "$session" 2>/dev/null || echo ''):$(team_pulse_window)(同 session)" || echo '跳过')"
228
283
 
229
284
  if [ "$print_only" = "1" ]; then
230
285
  printf '\n(--print:只看计划,什么都没改)\n'
231
286
  printf '计划步骤:\n'
232
- printf ' 1. %s init --session %s --pm-window %s --agents "%s" --vcs %s\n' "$TEAM_CLI" "$session" "$pmwin" "$agents" "$vcs"
287
+ local plan_models
288
+ if [ -n "$task_models" ] && [ -n "$pm_model" ]; then
289
+ plan_models="--task-models $(printf '%q' "$task_models") --pm-model $(printf '%q' "$pm_model")"
290
+ else
291
+ plan_models="--task-models '<category=provider/model …>' --pm-model '<provider/model>'(新鲜项目必填)"
292
+ fi
293
+ printf ' 1. %s init --session %s --pm-window %s --agents "%s" --vcs %s %s\n' "$TEAM_CLI" "$session" "$pmwin" "$agents" "$vcs" "$plan_models"
233
294
  printf ' 1b. 把 skill 装进项目 %s(%s init 的同一实现;已存在则 skip —— 老项目的升级路径)\n' '.pi/skills/' "$TEAM_CLI"
234
295
  printf ' 2. 把门禁/安装命令写进 .pi/team/config.sh(%s / %s)\n' "${gates:-无}" "${install_cmd:-无}"
235
296
  printf ' 3. 为每个 agent 建 worktree:%s\n' "$(printf 'add-agent %s; ' $agents)"
@@ -245,7 +306,7 @@ team_cmd_bootstrap() {
245
306
  # (cmd-init.sh 的 team_init_install_skills);冲突会响亮失败,不静默替换。
246
307
  team_init_install_skills || return 1
247
308
  else
248
- team_cmd_init --session "$session" --pm-window "$pmwin" --agents "$agents" --vcs "$vcs" ${gates:+--gates "$gates"}
309
+ team_cmd_init --session "$session" --pm-window "$pmwin" --agents "$agents" --vcs "$vcs" ${gates:+--gates "$gates"} --task-models "$task_models" --pm-model "$pm_model"
249
310
  team_load_config # 重新加载(init 刚写了配置)
250
311
  fi
251
312
  team_require_docs
@@ -301,8 +362,8 @@ team_cmd_bootstrap() {
301
362
  printf '\n'
302
363
  team_hdr "下一步(PM 的活)"
303
364
  printf ' 1) 填 %s/ROADMAP.md(目标/里程碑/退出标准)与 OWNERSHIP.md(目录归属)\n' "$TEAM_DOCS_DIR"
304
- printf ' 2) 建第一个任务:%s task T1.1 --title "…" --agent %s\n' "$TEAM_CLI" "$(printf '%s' "$agents" | awk '{print $1}')"
305
- printf ' → 编辑任务书(背景/交付物/边界/可复制验收命令)\n'
365
+ printf ' 2) 建第一个任务:%s task T1.1 --title "…" --category <类别> --agent %s\n' "$TEAM_CLI" "$(printf '%s' "$agents" | awk '{print $1}')"
366
+ printf ' → 编辑任务书(背景/交付物/边界/可复制验收命令);category 决定派单用哪个模型(%s config set-task-model)\n' "$TEAM_CLI"
306
367
  printf ' 3) 派单:%s dispatch %s T1.1 %s/tasks/T1.1-*.md\n' "$TEAM_CLI" "$(printf '%s' "$agents" | awk '{print $1}')" "$TEAM_DOCS_DIR"
307
368
  printf ' 4) 看板:%s digest | 巡检:%s pulse status\n' "$TEAM_CLI" "$TEAM_CLI"
308
369
  printf ' 5) 建议把脚手架提交:git add -A && git commit -m "chore: teamsmith 初始化"\n'
@@ -91,10 +91,9 @@ TEAM_PI_BIN|apply|path|exec|plain|pi|-|||roster
91
91
  TEAM_AGENT_BIN|apply|path|exec,opt|plain||-|内部接缝(frozen):为将来非 Pi 适配预留,不承诺兼容;不在 init 问卷里问||roster
92
92
  TEAM_OPENSPEC_BIN|apply|path|exec|plain|openspec|-|||roster
93
93
  TEAM_JS_BIN|apply|path|exec,opt|plain||-|||roster
94
- # ---- 按席位模型(restart:运行中的席位保住旧模型,下一次 dispatch/resume 才换)----
95
- TEAM_DEFAULT_MODEL|restart|model|req|plain|deepseek/deepseek-flash|-|模型:下一个 spawn 生效(dispatch/resume/team up)||seat-model
96
- TEAM_AGENT_MODELS|restart|pairlist||plain||-|按席位模型:team config set-agent-model <seat> <model>||seat-model
97
- TEAM_PM_MODEL|restart|model|opt|plain||-|PM 席位模型:team up 重建 PM 后生效||seat-model
94
+ # ---- Future policy, separate from committed assignments ----
95
+ TEAM_TASK_MODELS|apply|task-model-map|req|plain||-|新任务类别:team config set-task-model <category> <model>;恢复保留已派身份||task-model
96
+ TEAM_PM_MODEL|restart|model|req|plain||-|独立 PM 模型:team up 启动受 fresh-pm 守卫||task-model
98
97
  # ---- 工作流与门禁(apply)----
99
98
  TEAM_GATES|apply|cmd||plain||-|||workflow
100
99
  TEAM_INSTALL_CMD|apply|cmd||plain||-|||workflow
@@ -219,7 +218,7 @@ team_config_choices_set() { # <row> [known models: 每行一个] → CFG_CHOICES
219
218
  src="schema"
220
219
  IFS=, read -r min max _ <<< "$spec"
221
220
  val_list="${suggest//,/$'\n'}" ;;
222
- model|pairlist|winlist|pattern)
221
+ model|task-model-map|pairlist|winlist|pattern)
223
222
  src="known"; val_list="$known" ;;
224
223
  path)
225
224
  local typ="${spec%%,*}"; note="${typ:-any}" ;;
@@ -380,6 +379,8 @@ team_config_validate_value() {
380
379
  local mwhy
381
380
  if mwhy="$(team_config_model_violation "$val")"; then return 0; fi
382
381
  printf '%s\n' "$mwhy"; return 1 ;;
382
+ task-model-map)
383
+ team_task_map_violation "$val" ;;
383
384
  pairlist)
384
385
  local tok seat model r mwhy; r=0
385
386
  for tok in $val; do
@@ -714,47 +715,49 @@ team_config_list_json() {
714
715
  team_config_scan "$path"
715
716
  # models 块的 known 先算:它也是模型类键的 choices 词表(choices 必须随键记录一起输出,所以
716
717
  # 不能等键循环结束)。token 与顺序和原来逐字一致;每个席位的**显示**模型也在表里(R2)。
717
- local default_model known_models="" known_list="" seen=" " firstk=1
718
- default_model="$(team_config_file_value "$path" TEAM_DEFAULT_MODEL 2>/dev/null || true)"
719
- [ -n "$default_model" ] || default_model="$(team_config_field "$(team_config_row TEAM_DEFAULT_MODEL)" 6)"
720
- local tok
721
- for tok in $default_model ${TEAM_AGENT_MODELS:-}; do
722
- case "$tok" in
723
- *=*) tok="${tok#*=}" ;;
724
- esac
725
- [ -n "$tok" ] || continue
726
- case "$seen" in *" $tok "*) continue ;; esac
727
- seen="$seen$tok "
728
- known_models="$known_models$tok"$'\n'
729
- [ "$firstk" = "1" ] || known_list="$known_list,"
730
- firstk=0
731
- team_config_json_escape_set "$tok"; known_list="$known_list\"$CFG_ESC\""
732
- done
733
- local a state_model
718
+ local known_models="" known_list="" seen=' ' tok a
719
+ local categories='' assignments='' policy_pm='' pm_launch='{}'
720
+ if team_task_map_violation "${TEAM_TASK_MODELS:-}" >/dev/null; then
721
+ for tok in $TEAM_TASK_MODELS; do
722
+ team_config_json_escape_set "${tok%%=*}"; local ec="$CFG_ESC"
723
+ team_config_json_escape_set "${tok#*=}"; local em="$CFG_ESC"
724
+ categories="${categories:+$categories,}{\"category\":\"$ec\",\"model\":\"$em\"}"
725
+ known_models="$known_models${tok#*=}"$'\n'
726
+ done
727
+ fi
728
+ if team_config_model_shape_ok "${TEAM_PM_MODEL:-}"; then
729
+ policy_pm="$TEAM_PM_MODEL"; known_models="$known_models$policy_pm"$'\n'
730
+ fi
734
731
  for a in $(team_agents); do
735
- state_model="$(team_state_get "$a" model '' 2>/dev/null || true)"
736
- [ -n "$state_model" ] || continue
737
- case "$seen" in *" $state_model "*) continue ;; esac
738
- seen="$seen$state_model "
739
- known_models="$known_models$state_model"$'\n'
740
- [ "$firstk" = "1" ] || known_list="$known_list,"
741
- firstk=0
742
- team_config_json_escape_set "$state_model"; known_list="$known_list\"$CFG_ESC\""
743
- done
744
- # R2:每个席位的显示模型都在词汇表里。名册席位由上面的解析/记录两支覆盖;pm 席位没有 state
745
- # 记录(team_pm_start 不写),它的显示模型走 seats 块同一支 team_config_seat_state
746
- # (TEAM_PM_MODEL > TEAM_DEFAULT_MODEL)—— 视图的选项与 seats 块不会各说各话。
747
- local seat_model _src _override
748
- for a in $(team_agents) pm; do
749
- team_config_seat_split "$(team_config_seat_state "$a")" seat_model _src _override
750
- [ -n "$seat_model" ] || continue
751
- case "$seen" in *" $seat_model "*) continue ;; esac
752
- seen="$seen$seat_model "
753
- known_models="$known_models$seat_model"$'\n'
754
- [ "$firstk" = "1" ] || known_list="$known_list,"
755
- firstk=0
756
- team_config_json_escape_set "$seat_model"; known_list="$known_list\"$CFG_ESC\""
732
+ local assigned=false diagnostic='' fields='' field val
733
+ if team_assignment_load "$a"; then
734
+ assigned=true
735
+ # P228/R6(OBS1):未交付的模型不进「已知模型」,也不当成该席位的模型
736
+ if team_identity_delivered model; then known_models="$known_models${TEAM_ASSIGN[model]}"$'\n'
737
+ else diagnostic='template delivered no model identity'; fi
738
+ else diagnostic="$TEAM_ASSIGN_DIAGNOSTIC"; fi
739
+ for field in task category model selected_via launch_via sid; do
740
+ val=''; [ "$assigned" = false ] || val="${TEAM_ASSIGN[$field]}"
741
+ if [ "$field" = model ] && ! team_identity_delivered model; then val=''; fi
742
+ team_config_json_escape_set "$val"; fields="$fields,\"$field\":\"$CFG_ESC\""
743
+ done
744
+ val=''; [ "$assigned" = false ] || val="$(team_identity_delivered_set)"
745
+ team_config_json_escape_set "$val"; fields="$fields,\"identity_via\":\"$CFG_ESC\""
746
+ team_config_json_escape_set "$diagnostic"; local ed="$CFG_ESC"
747
+ team_config_json_escape_set "$a"
748
+ assignments="${assignments:+$assignments,}{\"agent\":\"$CFG_ESC\",\"assigned\":$assigned$fields,\"diagnostic\":\"$ed\"}"
757
749
  done
750
+ if team_pm_metadata_load; then
751
+ pm_launch="$TEAM_PM_METADATA_JSON"; known_models="$known_models$TEAM_PM_SELECTED_MODEL"$'\n'
752
+ fi
753
+ local dedup=''
754
+ while IFS= read -r tok; do
755
+ [ -n "$tok" ] || continue
756
+ case "$seen" in *" $tok "*) continue ;; esac
757
+ seen="$seen$tok "; dedup="$dedup$tok"$'\n'
758
+ team_config_json_escape_set "$tok"; known_list="${known_list:+$known_list,}\"$CFG_ESC\""
759
+ done <<< "$known_models"
760
+ known_models="$dedup"
758
761
 
759
762
  local schema_keys="|"
760
763
  local -a f=()
@@ -770,9 +773,10 @@ team_config_list_json() {
770
773
  comment="${CFG_SCAN_COMMENT[$key]}"
771
774
  set="true"
772
775
  fi
773
- if [ "$key" = "TEAM_AGENT_MODELS" ] && [ -n "$value" ]; then
774
- local unknown; unknown="$(team_config_pairlist_unknown_seats "$value" | tr '\n' ' ')"
775
- [ -n "$unknown" ] && warning="未知席位(名册没有,静默不生效):${unknown% }"
776
+ if [ "$key" = TEAM_TASK_MODELS ]; then
777
+ local why; if ! why="$(team_task_map_violation "$value")"; then warning="$why"; fi
778
+ elif [ "$key" = TEAM_PM_MODEL ]; then
779
+ local why; if ! why="$(team_config_model_violation "$value")"; then warning="$why"; fi
776
780
  fi
777
781
  # P99/R1:名册的读侧 warning 与写侧的值规则是同一份判定(team_config_list_violation)——
778
782
  # 手改出一个非法 token 时,读给出警告、写入器拒绝的是同一条规则。
@@ -807,17 +811,6 @@ team_config_list_json() {
807
811
  out="$out,{\"name\":\"$u_key\",\"class\":\"refuse\",\"kind\":\"text\",\"form\":\"plain\",\"value\":\"$u_val\",\"default\":\"\",\"set\":true,\"comment\":\"$u_com\",\"warning\":\"不是已知的项目设置(见 references/config.md);手改 .pi/team/config.sh\",\"choices\":$CFG_CHOICES_JSON,\"group\":\"\",\"known\":false}"
808
812
  done <<< "$CFG_SCAN_ORDER"
809
813
 
810
- local seats="" firsts=1
811
- for a in $(team_agents) pm; do
812
- team_config_seat_split "$(team_config_seat_state "$a")" model src override
813
- case "$override" in true) ;; *) override="false" ;; esac # override 永远是 JSON 布尔值(P47/R5)
814
- # 空模型也要出这一行(seats 覆盖每个名册席位 + pm):空模型序列化成 "",不是无值字段也不是丢行。
815
- team_config_json_escape_set "$a"; local s_agent="$CFG_ESC"
816
- team_config_json_escape_set "$model"; local s_model="$CFG_ESC"
817
- [ "$firsts" = "1" ] || seats="$seats,"
818
- firsts=0
819
- seats="$seats{\"agent\":\"$s_agent\",\"model\":\"$s_model\",\"source\":\"$(team_config_seat_source_token "$src")\",\"override\":$override}"
820
- done
821
814
 
822
815
  local audit="" firsta=1 l
823
816
  while IFS= read -r l; do
@@ -828,10 +821,10 @@ team_config_list_json() {
828
821
  done < <(team_config_audit_tail 10)
829
822
 
830
823
  team_config_json_escape_set "$path"; local e_path="$CFG_ESC"
831
- team_config_json_escape_set "$default_model"; local e_default="$CFG_ESC"
832
- printf '{"path":"%s","fingerprint":"%s","mtime":"%s","keys":[%s],"models":{"default":"%s","known":[%s],"seats":[%s]},"audit":[%s]}\n' \
833
- "$e_path" "$fingerprint" "$mtime" "$out" \
834
- "$e_default" "$known_list" "$seats" "$audit"
824
+ team_config_json_escape_set "$policy_pm"; local e_pm="$CFG_ESC"
825
+ team_config_json_escape_set "$(team_model_policy_issues)"; local e_diag="$CFG_ESC"
826
+ printf '{"path":"%s","fingerprint":"%s","mtime":"%s","keys":[%s],"models":{"policy":{"categories":[%s],"pm":"%s"},"assignments":[%s],"pm_launch":%s,"known":[%s],"diagnostic":"%s"},"audit":[%s]}\n' \
827
+ "$e_path" "$fingerprint" "$mtime" "$out" "$categories" "$e_pm" "$assignments" "$pm_launch" "$known_list" "$e_diag" "$audit"
835
828
  }
836
829
 
837
830
  team_cmd_config_list() {
@@ -860,6 +853,8 @@ team_cmd_config_list() {
860
853
  if value="$(team_config_file_value "$path" "$key")"; then set=1; else value="$def"; set=0; fi
861
854
  printf '%-42s %-8s %-10s %s%s\n' "$key" "$class" "$kind" "$value" "$([ "$set" = "0" ] && printf ' (unset · default)')"
862
855
  done < <(team_config_schema)
856
+ local issues; issues="$(team_model_policy_issues)"
857
+ [ -z "$issues" ] || printf '\n%s\n' "$issues"
863
858
  printf '\n审计 %s\n' "$(team_config_audit_file)"
864
859
  team_config_audit_tail 5 | sed 's/^/ /'
865
860
  }
@@ -884,7 +879,15 @@ TEAM_CONFIG_EXIT_DANGER=7
884
879
 
885
880
  # 共用的写路径:<KEY> <value> <actor> <dry> <fp> <allow_danger>
886
881
  # 返回值就是机器契约的退出码。
887
- team_config_write_checked() { # <KEY> <value> <actor> <dry> <fp> <allow_danger>
882
+ team_config_locked_call() { local TEAM_CONFIG_LOCKED=1; "$@"; }
883
+ team_config_write_checked() {
884
+ if [ "${4:-0}" = 1 ] || [ "${TEAM_CONFIG_LOCKED:-0}" = 1 ]; then team_config_write_checked_unlocked "$@"
885
+ else
886
+ local path; path="$(team_config_contract_path)" || return 1
887
+ team_with_lock "config:$path" team_config_locked_call team_config_write_checked_unlocked "$@"
888
+ fi
889
+ }
890
+ team_config_write_checked_unlocked() { # <KEY> <value> <actor> <dry> <fp> <allow_danger>
888
891
  local key="$1" val="$2" actor="$3" dry="$4" fp="$5" allow_danger="$6"
889
892
  local path; path="$(team_config_contract_path)" || return 1
890
893
  local row; row="$(team_config_row "$key" 2>/dev/null || true)"
@@ -892,7 +895,9 @@ team_config_write_checked() { # <KEY> <value> <actor> <dry> <fp> <allow_danger>
892
895
 
893
896
  if [ -z "$row" ]; then
894
897
  team_err "$key 不是已知的项目设置键"
895
- team_dim " 已知键:$TEAM_CLI config list;自定义键请手改 $path" >&2
898
+ case "$key" in TEAM_DEFAULT_MODEL|TEAM_AGENT_MODELS)
899
+ team_dim " retired: $TEAM_CLI config set-task-model <category> <model>;config set TEAM_PM_MODEL <model>;config upgrade-models" >&2 ;;
900
+ *) team_dim " 已知键:$TEAM_CLI config list;自定义键请手改 $path" >&2 ;; esac
896
901
  [ "$dry" = "1" ] || team_config_audit_write refused "$actor" "$key" "$old" "$val" || true
897
902
  return "$TEAM_CONFIG_EXIT_REFUSE"
898
903
  fi
@@ -952,7 +957,17 @@ team_config_write_checked() { # <KEY> <value> <actor> <dry> <fp> <allow_danger>
952
957
  # 3 指纹冲突 / 4 值不合法 / 5 remove 的席位不在名册 / 6 写失败。
953
958
  # 席位名合法性只对**结果值**判:移掉一个手改进来的非法 token 是合法的(结果干净),
954
959
  # 加进去才非法 —— 一条规则,读写同一份(team_config_list_violation)。
955
- team_config_write_roster() { # <add|remove> <seat> [<fingerprint>] [<dry>] → 详见上面的退出码
960
+ team_config_write_roster() {
961
+ if [ "${4:-0}" = 1 ] || [ "${TEAM_CONFIG_LOCKED:-0}" = 1 ]; then team_config_write_roster_unlocked "$@"
962
+ else
963
+ local path; path="$(team_config_contract_path)" || return 1
964
+ local rc=0
965
+ team_with_lock "config:$path" team_config_locked_call team_config_write_roster_unlocked "$@" || rc=$?
966
+ [ "$rc" != 0 ] || TEAM_AGENTS="$(team_config_file_value "$path" TEAM_AGENTS)"
967
+ return "$rc"
968
+ fi
969
+ }
970
+ team_config_write_roster_unlocked() { # <add|remove> <seat> [fingerprint] [dry]
956
971
  local op="$1" seat="$2" fp="${3:-}" dry="${4:-0}"
957
972
  local path; path="$(team_config_contract_path)" || return 1
958
973
  local old; old="$(team_config_file_value "$path" TEAM_AGENTS 2>/dev/null || true)"
@@ -1128,6 +1143,139 @@ team_cmd_config_set_agent_model() {
1128
1143
  return $rc
1129
1144
  }
1130
1145
 
1146
+ # Category edit is a read/modify/write under the SAME file lock as whole-map writes.
1147
+ team_cmd_config_set_task_model() {
1148
+ local cat='' model='' dry=0 fp='' allow_danger=0 actor="${TEAM_ACTOR:-cli}"
1149
+ while [ $# -gt 0 ]; do
1150
+ case "$1" in
1151
+ --dry-run) dry=1; shift ;; --yes|-y) shift ;;
1152
+ --fingerprint) fp="${2:?}"; shift 2 ;; --fingerprint=*) fp="${1#*=}"; shift ;;
1153
+ --actor) actor="${2:?}"; shift 2 ;; --actor=*) actor="${1#*=}"; shift ;;
1154
+ --allow-danger|--allow-dangerous) allow_danger=1; shift ;;
1155
+ -) if [ -z "$cat" ]; then cat='-'; elif [ -z "$model" ]; then model='-'; else team_usage_die 'set-task-model: 多余参数'; fi; shift ;;
1156
+ -*) team_usage_die "set-task-model: 未知参数 $1" ;;
1157
+ *) if [ -z "$cat" ]; then cat="$1"; elif [ -z "$model" ]; then model="$1"; else team_usage_die 'set-task-model: 多余参数'; fi; shift ;;
1158
+ esac
1159
+ done
1160
+ local path reason; path="$(team_config_contract_path)" || return 1
1161
+ if ! team_category_valid "$cat" || [[ "$model" == *=* ]]; then reason='set-task-model requires category provider/model (no removal/fallback)'
1162
+ elif ! reason="$(team_config_model_violation "$model")"; then :
1163
+ else reason=''; fi
1164
+ if [ -n "$reason" ]; then
1165
+ team_err "$reason"
1166
+ [ "$dry" = 1 ] || team_config_audit_write invalid "$actor" TEAM_TASK_MODELS "$(team_config_file_value "$path" TEAM_TASK_MODELS)" "$cat=$model" "$(team_config_fingerprint "$path")" || true
1167
+ return 4
1168
+ fi
1169
+ if [ "$dry" = 1 ]; then team_config_task_upsert "$path" "$cat" "$model" "$actor" "$dry" "$fp" "$allow_danger"
1170
+ else team_with_lock "config:$path" team_config_locked_call team_config_task_upsert "$path" "$cat" "$model" "$actor" "$dry" "$fp" "$allow_danger"; fi
1171
+ }
1172
+ team_config_task_upsert() {
1173
+ local path="$1" cat="$2" model="$3" actor="$4" dry="$5" fp="$6" allow_danger="${7:-0}" old new
1174
+ old="$(team_config_file_value "$path" TEAM_TASK_MODELS)"
1175
+ [ -z "$old" ] || team_task_map_violation "$old" >/dev/null || { team_err '现有映射非法;请 config set TEAM_TASK_MODELS <完整映射> 修复'; return 4; }
1176
+ new="$(team_config_pairlist_upsert "$old" "$cat" "$model")"
1177
+ team_config_write_checked TEAM_TASK_MODELS "$new" "$actor" "$dry" "$fp" "$allow_danger"
1178
+ }
1179
+
1180
+ # Only the four relevant keys are located; unsafe Bash shapes are NOT rewritten.
1181
+ team_config_model_source_shape() {
1182
+ local path="$1" line n=0 key rhs comment quote ch i depth=0 seen=' '
1183
+ while IFS= read -r line || [ -n "$line" ]; do
1184
+ n=$((n + 1))
1185
+ [[ "$line" =~ ^[[:space:]]*# ]] && continue
1186
+ case "$line" in *TEAM_DEFAULT_MODEL*|*TEAM_AGENT_MODELS*|*TEAM_TASK_MODELS*|*TEAM_PM_MODEL*) ;;
1187
+ *)
1188
+ [[ "$line" =~ ^[[:space:]]*(if|case|for|while|until|function)[[:space:]] ]] && depth=$((depth+1))
1189
+ [[ "$line" =~ ^[[:space:]]*(fi|esac|done)([[:space:];]|$) ]] && depth=$((depth>0 ? depth-1 : 0))
1190
+ continue ;;
1191
+ esac
1192
+ if ! [[ "$line" =~ ^(TEAM_DEFAULT_MODEL|TEAM_AGENT_MODELS|TEAM_TASK_MODELS|TEAM_PM_MODEL)= ]] || [ "$depth" -gt 0 ]; then
1193
+ team_err "$path:$n: unsupported relevant source shape;请手工规范为顶层唯一 KEY='literal' 后重试"; return 5
1194
+ fi
1195
+ key="${BASH_REMATCH[1]}"
1196
+ case "$seen" in *" $key "*) team_err "$path:$n: duplicate $key;请手工规范"; return 5 ;; esac
1197
+ seen="$seen$key "
1198
+ comment="$(printf '%s' "$line" | team_config_inline_comment_of_line)"
1199
+ rhs="${line#*=}"; [ -z "$comment" ] || rhs="${rhs%"$comment"}"
1200
+ rhs="$(team_trim "$rhs")"
1201
+ quote=''; i=0
1202
+ if [[ "$rhs" == \"* ]]; then
1203
+ [[ "$rhs" == *\" ]] && [ "${#rhs}" -ge 2 ] || { team_err "$path:$n: multiline/unclosed literal"; return 5; }
1204
+ rhs="${rhs:1:${#rhs}-2}"
1205
+ case "$rhs" in *'$'*|*'`'*|*'\\'*|*'"'*) team_err "$path:$n: expanding double quote;请规范单行 literal"; return 5 ;; esac
1206
+ elif [[ "$rhs" == "'"* ]]; then
1207
+ while [ "$i" -lt "${#rhs}" ]; do
1208
+ ch="${rhs:i:1}"
1209
+ if [ "$quote" = single ]; then [ "$ch" != "'" ] || quote=''
1210
+ else
1211
+ if [ "$ch" = "'" ]; then quote=single
1212
+ elif [ "${rhs:i:2}" = "\\'" ]; then i=$((i+1))
1213
+ else team_err "$path:$n: unsupported literal concatenation"; return 5; fi
1214
+ fi
1215
+ i=$((i+1))
1216
+ done
1217
+ [ -z "$quote" ] || { team_err "$path:$n: multiline/unclosed literal"; return 5; }
1218
+ elif ! [[ "$rhs" =~ ^[a-zA-Z0-9_./:=+-]+$ ]]; then
1219
+ team_err "$path:$n: dynamic/indirect value;请规范顶层单行 literal"; return 5
1220
+ fi
1221
+ done < "$path"
1222
+ }
1223
+ team_cmd_config_upgrade_models() {
1224
+ local map='' pm='' dry=1 yes="${TEAM_UPGRADE_CONFIRMED:-0}" fp='' actor="${TEAM_ACTOR:-cli}"
1225
+ [ "$yes" != 1 ] || dry=0
1226
+ while [ $# -gt 0 ]; do
1227
+ case "$1" in
1228
+ --task-models) map="${2:?}"; shift 2 ;; --pm-model) pm="${2:?}"; shift 2 ;;
1229
+ --dry-run) dry=1; shift ;; --yes|-y) yes=1; dry=0; shift ;;
1230
+ --fingerprint) fp="${2:?}"; shift 2 ;; --fingerprint=*) fp="${1#*=}"; shift ;;
1231
+ --actor) actor="${2:?}"; shift 2 ;; *) team_usage_die "upgrade-models: 未知参数 $1" ;;
1232
+ esac
1233
+ done
1234
+ [ -n "$map" ] && [ -n "$pm" ] || { team_err 'upgrade-models requires --task-models <完整映射> --pm-model <独立模型>;默认 preview,--yes 才写'; return 4; }
1235
+ local path; path="$(team_config_contract_path)" || return 1
1236
+ if [ "$dry" = 1 ]; then team_config_upgrade_transaction "$path" "$map" "$pm" "$dry" "$fp" "$actor"
1237
+ else team_with_lock "config:$path" team_config_locked_call team_config_upgrade_transaction "$path" "$map" "$pm" "$dry" "$fp" "$actor"; fi
1238
+ }
1239
+ team_config_upgrade_transaction() {
1240
+ local path="$1" map="$2" pm="$3" dry="$4" fp="$5" actor="$6" before after tmp rc=0
1241
+ before="$(team_config_fingerprint "$path")"
1242
+ if ! team_task_map_violation "$map" || ! team_config_model_violation "$pm"; then
1243
+ [ "$dry" = 1 ] || team_config_audit_write invalid "$actor" model-upgrade "$before" '' || true
1244
+ return 4
1245
+ fi
1246
+ if [ -n "$fp" ] && [ "$before" != "$fp" ]; then
1247
+ [ "$dry" = 1 ] || team_config_audit_write conflict "$actor" model-upgrade "$before" '' "$fp" "$before" || true
1248
+ team_err 'upgrade-models: 指纹不符,未写'; return 3
1249
+ fi
1250
+ if ! team_config_model_source_shape "$path"; then
1251
+ [ "$dry" = 1 ] || team_config_audit_write refused "$actor" model-upgrade "$before" '' || true
1252
+ return 5
1253
+ fi
1254
+ printf 'upgrade-models: remove TEAM_DEFAULT_MODEL TEAM_AGENT_MODELS; TEAM_TASK_MODELS=%s; TEAM_PM_MODEL=%s; before=%s\n' "$map" "$pm" "$before"
1255
+ [ "$dry" != 1 ] || { printf 'dry-run: no config/audit mutation; --yes to commit\n'; return 0; }
1256
+ tmp="$(mktemp "$(dirname "$path")/.model-upgrade.XXXXXX")" || {
1257
+ team_config_audit_write write-error "$actor" model-upgrade "$before" '' || true; return 6;
1258
+ }
1259
+ cp -p "$path" "$tmp" || {
1260
+ rm -f "$tmp"; team_config_audit_write write-error "$actor" model-upgrade "$before" '' || true; return 6;
1261
+ }
1262
+ team_config_set_in_file "$tmp" TEAM_DEFAULT_MODEL '' remove &&
1263
+ team_config_set_in_file "$tmp" TEAM_AGENT_MODELS '' remove &&
1264
+ team_config_set_in_file "$tmp" TEAM_TASK_MODELS "$map" &&
1265
+ team_config_set_in_file "$tmp" TEAM_PM_MODEL "$pm" && bash -n "$tmp" || rc=6
1266
+ if [ "$rc" = 0 ] && [ "$(team_config_fingerprint "$path")" != "$before" ]; then rc=3; fi
1267
+ if [ "$rc" = 0 ]; then mv -f "$tmp" "$path" || rc=6; fi
1268
+ rm -f "$tmp"
1269
+ if [ "$rc" != 0 ]; then
1270
+ local result=write-error; [ "$rc" != 3 ] || result=conflict
1271
+ team_config_audit_write "$result" "$actor" model-upgrade "$before" '' || true
1272
+ return "$rc"
1273
+ fi
1274
+ after="$(team_config_fingerprint "$path")"
1275
+ team_config_audit_write ok "$actor" 'TEAM_DEFAULT_MODEL,TEAM_AGENT_MODELS,TEAM_TASK_MODELS,TEAM_PM_MODEL' "$before" "$after" "$before" "$after" || true
1276
+ printf 'committed: before=%s after=%s\n' "$before" "$after"
1277
+ }
1278
+
1131
1279
  # ---------------------------------------------------------------- 子命令分发
1132
1280
  team_cmd_config() {
1133
1281
  local sub="${1:-}"
@@ -1136,21 +1284,25 @@ team_cmd_config() {
1136
1284
  list) team_cmd_config_list "$@" ;;
1137
1285
  set) team_cmd_config_set "$@" ;;
1138
1286
  log) team_cmd_config_log "$@" ;;
1139
- set-agent-model) team_cmd_config_set_agent_model "$@" ;;
1287
+ set-task-model) team_cmd_config_set_task_model "$@" ;;
1288
+ upgrade-models) team_cmd_config_upgrade_models "$@" ;;
1289
+ set-agent-model) team_err "retired: use $TEAM_CLI config set-task-model <category> <model> or config set TEAM_PM_MODEL <model>"; return 5 ;;
1140
1290
  ''|help|-h|--help)
1141
1291
  cat <<EOF
1142
- 用法: $TEAM_CLI config <list|set|log|set-agent-model> …
1292
+ 用法: $TEAM_CLI config <list|set|log|set-task-model|upgrade-models> …
1143
1293
 
1144
1294
  $TEAM_CLI config list [--json] 列出契约里每个键(class/kind/当前值/默认值)与
1145
- models 块(按席位模型 + 来源三态)
1295
+ models 块(未来策略与已提交启动身份)
1146
1296
  $TEAM_CLI config set <KEY> <VALUE> [--dry-run] 唯一写入口:校验 → 指纹 CAS → 原子写 → 审计
1147
1297
  [--fingerprint <sha256>] [--actor <name>] [--allow-danger]
1148
- $TEAM_CLI config set-agent-model <seat> <model|-> 按席位改模型(- 移除覆盖,回到 TEAM_DEFAULT_MODEL)
1298
+ $TEAM_CLI config set-task-model <category> <model> 新增/修改类别模型,不改已派身份
1299
+ $TEAM_CLI config upgrade-models --task-models <map> --pm-model <model> [--dry-run] [--yes]
1300
+ [--fingerprint <sha256>] [--actor <name>] 显式四键事务升级
1149
1301
  $TEAM_CLI config log [N] 审计尾部(默认 10 行)
1150
1302
 
1151
1303
  退出码: 0 写入/校验通过 | 3 指纹冲突 | 4 值不合法 | 5 键只读 | 6 写失败 | 7 危险值需 --allow-danger
1152
1304
  EOF
1153
1305
  ;;
1154
- *) team_usage_die "config: 未知子命令 $sub(list|set|log|set-agent-model)" ;;
1306
+ *) team_usage_die "config: 未知子命令 $sub(list|set|log|set-task-model|upgrade-models)" ;;
1155
1307
  esac
1156
1308
  }
@@ -146,21 +146,8 @@ team_death_identity() { # <seat> <分类> <锚> → 身份哈希
146
146
  # `--fresh` 的 `*_<sid>-<epoch>.jsonl`;这里补上(design D2/D9:不复用共享函数,免得静默改变
147
147
  # roster/ps 的会话大小语义)。
148
148
  team_agent_session_latest() { # <agent> → 文件路径 | 非 0
149
- local a="${1:-}" wt d sid f best="" bestm=-1 m
150
- [ -n "$a" ] || return 1
151
- wt="$(team_agent_worktree "$a")"
152
- [ -d "$wt" ] || return 1
153
- d="$(team_pi_session_dir "$wt")"
154
- [ -d "$d" ] || return 1
155
- sid="$TEAM_SESSION-$a"
156
- for f in "$d"/*_"$sid".jsonl "$d"/*_"$sid"-*.jsonl; do
157
- [ -f "$f" ] || continue
158
- m="$(team_death_file_mtime "$f")"
159
- case "$m" in ''|*[!0-9]*) continue ;; esac
160
- if [ "$m" -gt "$bestm" ]; then best="$f"; bestm="$m"; fi
161
- done
162
- [ -n "$best" ] || return 1
163
- printf '%s\n' "$best"
149
+ team_assignment_load "${1:-}" || return 1
150
+ team_session_file "${TEAM_ASSIGN[sid]}" "${TEAM_ASSIGN[worktree]}"
164
151
  }
165
152
 
166
153
  # 有界尾部(默认 64 KiB)里**最后**一条 assistant + stopReason=error 的 errorMessage。
@@ -3,7 +3,7 @@
3
3
 
4
4
  team_cmd_task() {
5
5
  team_require_docs
6
- local id="" title="" agent="" deps="-" issue="" slug=""
6
+ local id="" title="" agent="" deps="-" issue="" slug="" category=""
7
7
  while [ $# -gt 0 ]; do
8
8
  case "$1" in
9
9
  --title) title="${2:?}"; shift 2 ;;
@@ -11,11 +11,14 @@ team_cmd_task() {
11
11
  --deps) deps="${2:?}"; shift 2 ;;
12
12
  --issue) issue="${2:?}"; shift 2 ;;
13
13
  --slug) slug="${2:?}"; shift 2 ;;
14
+ --category) category="${2:?}"; shift 2 ;;
14
15
  -*) team_usage_die "task: 未知参数 $1" ;;
15
16
  *) id="$1"; shift ;;
16
17
  esac
17
18
  done
18
19
  [ -n "$id" ] || team_usage_die "task <ID> --title \"...\" [--agent a] [--deps ...] [--issue N]"
20
+ team_category_valid "$category" || team_usage_die 'task requires --category <project category>'
21
+ team_task_policy_model "$category" >/dev/null || team_die "category 未映射:$category;config set-task-model $category <model>"
19
22
  [ -n "$title" ] || title="<未命名>"
20
23
  agent="${agent:-$(team_agents | head -1)}"
21
24
  slug="${slug:-$(team_slug "$title")}"
@@ -32,8 +35,8 @@ team_cmd_task() {
32
35
  "ID=$id" "TITLE=$title" "AGENT=$agent" "DEPS=$deps" "ISSUE=$issue" "SLUG=$slug" \
33
36
  "PROJECT=$TEAM_PROJECT" "DOCS_DIR=$TEAM_DOCS_DIR" "GATES=${TEAM_GATES:-<未配置:先跟 PM 约定验收命令>}" \
34
37
  "DATE=$(date +%F)" \
35
- | awk -v br="$branch_name" '
36
- !done && /^agent:/ { print; print "branch: " br; done=1; next }
38
+ | awk -v br="$branch_name" -v cat="$category" '
39
+ !done && /^agent:/ { print; print "branch: " br; print "category: " cat; done=1; next }
37
40
  { print }' > "$file"
38
41
  team_ok "write $file"
39
42
  team_dim " 分支:$branch_name(dispatch 按它检查工作树;--branch 可显式覆盖)"