teamsmith 0.1.1 → 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 (104) hide show
  1. package/README.md +16 -8
  2. package/package.json +1 -1
  3. package/skills/teamsmith/CHANGELOG.md +55 -0
  4. package/skills/teamsmith/SKILL.md +18 -7
  5. package/skills/teamsmith/extension/team-bg.ts +47 -11
  6. package/skills/teamsmith/extension/team-notify.ts +143 -4
  7. package/skills/teamsmith/references/agent-adapters.md +7 -7
  8. package/skills/teamsmith/references/config.md +29 -15
  9. package/skills/teamsmith/references/migration.md +38 -2
  10. package/skills/teamsmith/references/openspec.md +23 -9
  11. package/skills/teamsmith/references/protocol.md +81 -13
  12. package/skills/teamsmith/references/workflows.md +31 -19
  13. package/skills/teamsmith/scripts/lib/cmd-agents.sh +210 -70
  14. package/skills/teamsmith/scripts/lib/cmd-bootstrap.sh +70 -9
  15. package/skills/teamsmith/scripts/lib/cmd-config.sh +222 -70
  16. package/skills/teamsmith/scripts/lib/cmd-death.sh +2 -15
  17. package/skills/teamsmith/scripts/lib/cmd-docs.sh +6 -3
  18. package/skills/teamsmith/scripts/lib/cmd-project.sh +134 -17
  19. package/skills/teamsmith/scripts/lib/cmd-reply.sh +96 -0
  20. package/skills/teamsmith/scripts/lib/cmd-review.sh +13 -10
  21. package/skills/teamsmith/scripts/lib/cmd-status.sh +42 -13
  22. package/skills/teamsmith/scripts/lib/cmd-watch.sh +75 -13
  23. package/skills/teamsmith/scripts/lib/common.sh +797 -71
  24. package/skills/teamsmith/scripts/monitor.mjs +34 -3
  25. package/skills/teamsmith/scripts/panel/README.md +22 -11
  26. package/skills/teamsmith/scripts/panel/panel.js +217 -215
  27. package/skills/teamsmith/scripts/panel/src/App.tsx +421 -164
  28. package/skills/teamsmith/scripts/panel/src/data.ts +84 -4
  29. package/skills/teamsmith/scripts/panel/src/layout.ts +502 -91
  30. package/skills/teamsmith/scripts/panel/src/main.tsx +97 -12
  31. package/skills/teamsmith/scripts/panel/src/settings.ts +1 -1
  32. package/skills/teamsmith/scripts/panel/src/strings/en.ts +56 -21
  33. package/skills/teamsmith/scripts/panel/src/strings/zh.ts +56 -21
  34. package/skills/teamsmith/scripts/panel/src/types.ts +178 -16
  35. package/skills/teamsmith/scripts/replies.mjs +893 -0
  36. package/skills/teamsmith/scripts/team +1 -0
  37. package/skills/teamsmith/templates/AGENTS.section.md.tmpl +15 -2
  38. package/skills/teamsmith/templates/BOARD.md.tmpl +2 -2
  39. package/skills/teamsmith/templates/OWNERSHIP.md.tmpl +7 -3
  40. package/skills/teamsmith/templates/PROTOCOL.md.tmpl +17 -0
  41. package/skills/teamsmith/templates/config.sh.tmpl +10 -5
  42. package/skills/teamsmith/templates/memory-seed.md.tmpl +3 -0
  43. package/skills/teamsmith/templates/pm-prompt.md.tmpl +20 -1
  44. package/skills/teamsmith/templates/report.md.tmpl +12 -0
  45. package/skills/teamsmith/templates/task.md.tmpl +4 -0
  46. package/skills/teamsmith/tests/bg-ledger-harness.mjs +682 -0
  47. package/skills/teamsmith/tests/bg-ledger.sh +307 -0
  48. package/skills/teamsmith/tests/checkout-shape-probe.sh +287 -58
  49. package/skills/teamsmith/tests/config-cli.sh +162 -288
  50. package/skills/teamsmith/tests/death-cause.sh +5 -2
  51. package/skills/teamsmith/tests/install-shape.sh +4 -2
  52. package/skills/teamsmith/tests/key-replies-pty.sh +375 -0
  53. package/skills/teamsmith/tests/key-replies-ui.sh +332 -0
  54. package/skills/teamsmith/tests/key-replies.sh +1075 -0
  55. package/skills/teamsmith/tests/ledger-ban.sh +5 -5
  56. package/skills/teamsmith/tests/ledger-claim.sh +247 -0
  57. package/skills/teamsmith/tests/lib/checkout-shape.sh +66 -14
  58. package/skills/teamsmith/tests/lib/model-policy.sh +26 -0
  59. package/skills/teamsmith/tests/lib/model-routing-boundary.sh +420 -0
  60. package/skills/teamsmith/tests/lib/model-routing-expansion.sh +155 -0
  61. package/skills/teamsmith/tests/lib/model-routing-flips.py +136 -0
  62. package/skills/teamsmith/tests/lib/model-routing-roles.sh +250 -0
  63. package/skills/teamsmith/tests/lib/proc-io.sh +103 -0
  64. package/skills/teamsmith/tests/lib/reply-fixture.sh +372 -0
  65. package/skills/teamsmith/tests/lib/tmux-iso.sh +8 -0
  66. package/skills/teamsmith/tests/panel-b2.sh +1 -1
  67. package/skills/teamsmith/tests/panel-b3-stub.sh +27 -0
  68. package/skills/teamsmith/tests/panel-b3.sh +14 -10
  69. package/skills/teamsmith/tests/panel-choices.sh +74 -61
  70. package/skills/teamsmith/tests/panel-cpu.sh +1 -1
  71. package/skills/teamsmith/tests/panel-p21.sh +311 -190
  72. package/skills/teamsmith/tests/perf.sh +1 -1
  73. package/skills/teamsmith/tests/pm-box-real.sh +1 -1
  74. package/skills/teamsmith/tests/pulse-nudge-key.sh +1 -1
  75. package/skills/teamsmith/tests/routes.sh +43 -22
  76. package/skills/teamsmith/tests/section-budgets.tsv +9 -5
  77. package/skills/teamsmith/tests/section-paths.tsv +26 -16
  78. package/skills/teamsmith/tests/section-select.sh +99 -16
  79. package/skills/teamsmith/tests/smoke.sh +930 -216
  80. package/skills/teamsmith/tests/snapshots/zh-dark-120-detail.txt +2 -2
  81. package/skills/teamsmith/tests/snapshots/zh-dark-120-p4.txt +2 -2
  82. package/skills/teamsmith/tests/snapshots/zh-dark-120.txt +9 -9
  83. package/skills/teamsmith/tests/snapshots/zh-dark-160-p4.txt +2 -2
  84. package/skills/teamsmith/tests/snapshots/zh-dark-160.txt +9 -9
  85. package/skills/teamsmith/tests/snapshots/zh-dark-59-detail.txt +1 -1
  86. package/skills/teamsmith/tests/snapshots/zh-dark-59-p4.txt +1 -1
  87. package/skills/teamsmith/tests/snapshots/zh-dark-59.txt +5 -5
  88. package/skills/teamsmith/tests/snapshots/zh-dark-99-p4.txt +2 -2
  89. package/skills/teamsmith/tests/snapshots/zh-dark-99.txt +5 -5
  90. package/skills/teamsmith/tests/snapshots/zh-light-120-detail.txt +2 -2
  91. package/skills/teamsmith/tests/snapshots/zh-light-120-p4.txt +2 -2
  92. package/skills/teamsmith/tests/snapshots/zh-light-120.txt +9 -9
  93. package/skills/teamsmith/tests/snapshots/zh-light-160-p4.txt +2 -2
  94. package/skills/teamsmith/tests/snapshots/zh-light-160.txt +9 -9
  95. package/skills/teamsmith/tests/snapshots/zh-light-59-detail.txt +1 -1
  96. package/skills/teamsmith/tests/snapshots/zh-light-59-p4.txt +1 -1
  97. package/skills/teamsmith/tests/snapshots/zh-light-59.txt +5 -5
  98. package/skills/teamsmith/tests/snapshots/zh-light-99-p4.txt +2 -2
  99. package/skills/teamsmith/tests/snapshots/zh-light-99.txt +5 -5
  100. package/skills/teamsmith/tests/task-header-model.sh +2 -1
  101. package/skills/teamsmith/tests/task-model-routing.sh +1014 -0
  102. package/skills/teamsmith-init/SKILL.md +38 -38
  103. package/skills/teamsmith-init/references/bootstrap.md +6 -4
  104. package/skills/teamsmith-init/templates/bootstrap-prompt.md.tmpl +9 -5
@@ -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 可显式覆盖)"