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.
- package/README.md +16 -8
- package/package.json +1 -1
- package/skills/teamsmith/CHANGELOG.md +55 -0
- package/skills/teamsmith/SKILL.md +18 -7
- package/skills/teamsmith/extension/team-bg.ts +47 -11
- package/skills/teamsmith/extension/team-notify.ts +143 -4
- package/skills/teamsmith/references/agent-adapters.md +7 -7
- package/skills/teamsmith/references/config.md +29 -15
- package/skills/teamsmith/references/migration.md +38 -2
- package/skills/teamsmith/references/openspec.md +23 -9
- package/skills/teamsmith/references/protocol.md +81 -13
- package/skills/teamsmith/references/workflows.md +31 -19
- package/skills/teamsmith/scripts/lib/cmd-agents.sh +210 -70
- package/skills/teamsmith/scripts/lib/cmd-bootstrap.sh +70 -9
- package/skills/teamsmith/scripts/lib/cmd-config.sh +222 -70
- package/skills/teamsmith/scripts/lib/cmd-death.sh +2 -15
- package/skills/teamsmith/scripts/lib/cmd-docs.sh +6 -3
- package/skills/teamsmith/scripts/lib/cmd-project.sh +134 -17
- package/skills/teamsmith/scripts/lib/cmd-reply.sh +96 -0
- package/skills/teamsmith/scripts/lib/cmd-review.sh +13 -10
- package/skills/teamsmith/scripts/lib/cmd-status.sh +42 -13
- package/skills/teamsmith/scripts/lib/cmd-watch.sh +75 -13
- package/skills/teamsmith/scripts/lib/common.sh +797 -71
- package/skills/teamsmith/scripts/monitor.mjs +34 -3
- package/skills/teamsmith/scripts/panel/README.md +22 -11
- package/skills/teamsmith/scripts/panel/panel.js +217 -215
- package/skills/teamsmith/scripts/panel/src/App.tsx +421 -164
- package/skills/teamsmith/scripts/panel/src/data.ts +84 -4
- package/skills/teamsmith/scripts/panel/src/layout.ts +502 -91
- package/skills/teamsmith/scripts/panel/src/main.tsx +97 -12
- package/skills/teamsmith/scripts/panel/src/settings.ts +1 -1
- package/skills/teamsmith/scripts/panel/src/strings/en.ts +56 -21
- package/skills/teamsmith/scripts/panel/src/strings/zh.ts +56 -21
- package/skills/teamsmith/scripts/panel/src/types.ts +178 -16
- package/skills/teamsmith/scripts/replies.mjs +893 -0
- package/skills/teamsmith/scripts/team +1 -0
- package/skills/teamsmith/templates/AGENTS.section.md.tmpl +15 -2
- package/skills/teamsmith/templates/BOARD.md.tmpl +2 -2
- package/skills/teamsmith/templates/OWNERSHIP.md.tmpl +7 -3
- package/skills/teamsmith/templates/PROTOCOL.md.tmpl +17 -0
- package/skills/teamsmith/templates/config.sh.tmpl +10 -5
- package/skills/teamsmith/templates/memory-seed.md.tmpl +3 -0
- package/skills/teamsmith/templates/pm-prompt.md.tmpl +20 -1
- package/skills/teamsmith/templates/report.md.tmpl +12 -0
- package/skills/teamsmith/templates/task.md.tmpl +4 -0
- package/skills/teamsmith/tests/bg-ledger-harness.mjs +682 -0
- package/skills/teamsmith/tests/bg-ledger.sh +307 -0
- package/skills/teamsmith/tests/checkout-shape-probe.sh +287 -58
- package/skills/teamsmith/tests/config-cli.sh +162 -288
- package/skills/teamsmith/tests/death-cause.sh +5 -2
- package/skills/teamsmith/tests/install-shape.sh +4 -2
- package/skills/teamsmith/tests/key-replies-pty.sh +375 -0
- package/skills/teamsmith/tests/key-replies-ui.sh +332 -0
- package/skills/teamsmith/tests/key-replies.sh +1075 -0
- package/skills/teamsmith/tests/ledger-ban.sh +5 -5
- package/skills/teamsmith/tests/ledger-claim.sh +247 -0
- package/skills/teamsmith/tests/lib/checkout-shape.sh +66 -14
- package/skills/teamsmith/tests/lib/model-policy.sh +26 -0
- package/skills/teamsmith/tests/lib/model-routing-boundary.sh +420 -0
- package/skills/teamsmith/tests/lib/model-routing-expansion.sh +155 -0
- package/skills/teamsmith/tests/lib/model-routing-flips.py +136 -0
- package/skills/teamsmith/tests/lib/model-routing-roles.sh +250 -0
- package/skills/teamsmith/tests/lib/proc-io.sh +103 -0
- package/skills/teamsmith/tests/lib/reply-fixture.sh +372 -0
- package/skills/teamsmith/tests/lib/tmux-iso.sh +8 -0
- package/skills/teamsmith/tests/panel-b2.sh +1 -1
- package/skills/teamsmith/tests/panel-b3-stub.sh +27 -0
- package/skills/teamsmith/tests/panel-b3.sh +14 -10
- package/skills/teamsmith/tests/panel-choices.sh +74 -61
- package/skills/teamsmith/tests/panel-cpu.sh +1 -1
- package/skills/teamsmith/tests/panel-p21.sh +311 -190
- package/skills/teamsmith/tests/perf.sh +1 -1
- package/skills/teamsmith/tests/pm-box-real.sh +1 -1
- package/skills/teamsmith/tests/pulse-nudge-key.sh +1 -1
- package/skills/teamsmith/tests/routes.sh +43 -22
- package/skills/teamsmith/tests/section-budgets.tsv +9 -5
- package/skills/teamsmith/tests/section-paths.tsv +26 -16
- package/skills/teamsmith/tests/section-select.sh +99 -16
- package/skills/teamsmith/tests/smoke.sh +930 -216
- package/skills/teamsmith/tests/snapshots/zh-dark-120-detail.txt +2 -2
- package/skills/teamsmith/tests/snapshots/zh-dark-120-p4.txt +2 -2
- package/skills/teamsmith/tests/snapshots/zh-dark-120.txt +9 -9
- package/skills/teamsmith/tests/snapshots/zh-dark-160-p4.txt +2 -2
- package/skills/teamsmith/tests/snapshots/zh-dark-160.txt +9 -9
- package/skills/teamsmith/tests/snapshots/zh-dark-59-detail.txt +1 -1
- package/skills/teamsmith/tests/snapshots/zh-dark-59-p4.txt +1 -1
- package/skills/teamsmith/tests/snapshots/zh-dark-59.txt +5 -5
- package/skills/teamsmith/tests/snapshots/zh-dark-99-p4.txt +2 -2
- package/skills/teamsmith/tests/snapshots/zh-dark-99.txt +5 -5
- package/skills/teamsmith/tests/snapshots/zh-light-120-detail.txt +2 -2
- package/skills/teamsmith/tests/snapshots/zh-light-120-p4.txt +2 -2
- package/skills/teamsmith/tests/snapshots/zh-light-120.txt +9 -9
- package/skills/teamsmith/tests/snapshots/zh-light-160-p4.txt +2 -2
- package/skills/teamsmith/tests/snapshots/zh-light-160.txt +9 -9
- package/skills/teamsmith/tests/snapshots/zh-light-59-detail.txt +1 -1
- package/skills/teamsmith/tests/snapshots/zh-light-59-p4.txt +1 -1
- package/skills/teamsmith/tests/snapshots/zh-light-59.txt +5 -5
- package/skills/teamsmith/tests/snapshots/zh-light-99-p4.txt +2 -2
- package/skills/teamsmith/tests/snapshots/zh-light-99.txt +5 -5
- package/skills/teamsmith/tests/task-header-model.sh +2 -1
- package/skills/teamsmith/tests/task-model-routing.sh +1014 -0
- package/skills/teamsmith-init/SKILL.md +38 -38
- package/skills/teamsmith-init/references/bootstrap.md +6 -4
- package/skills/teamsmith-init/templates/bootstrap-prompt.md.tmpl +9 -5
|
@@ -23,10 +23,6 @@ team_worktree_add() { # <agent> [--create] [--no-install]
|
|
|
23
23
|
else
|
|
24
24
|
printf ' git -C %s worktree add -b %s %s %s\n' "$TEAM_MAIN_ROOT" "$branch" "$wt" "$TEAM_PROTECTED_BRANCH"
|
|
25
25
|
fi
|
|
26
|
-
team_state_set "$agent" model "$(team_agent_model "$agent")"
|
|
27
|
-
team_state_set "$agent" model_src config
|
|
28
|
-
team_state_set "$agent" window "$agent"
|
|
29
|
-
team_state_set "$agent" worktree "$wt"
|
|
30
26
|
return 0
|
|
31
27
|
fi
|
|
32
28
|
mkdir -p "$(dirname "$wt")"
|
|
@@ -52,10 +48,6 @@ team_worktree_add() { # <agent> [--create] [--no-install]
|
|
|
52
48
|
( cd "$wt" && eval "$TEAM_INSTALL_CMD" ) || team_warn "install 失败,先手动装依赖再派单"
|
|
53
49
|
fi
|
|
54
50
|
|
|
55
|
-
team_state_set "$agent" model "$(team_agent_model "$agent")"
|
|
56
|
-
team_state_set "$agent" model_src config
|
|
57
|
-
team_state_set "$agent" window "$agent"
|
|
58
|
-
team_state_set "$agent" worktree "$wt"
|
|
59
51
|
return 0
|
|
60
52
|
}
|
|
61
53
|
|
|
@@ -70,9 +62,10 @@ team_pi_args() { # <model> → 打印已转义的 pi 参数
|
|
|
70
62
|
piargs+=(-e "$TEAM_SKILL_DIR/extension/team-inbox-watch.ts")
|
|
71
63
|
[ -d "$TEAM_SKILL_DIR" ] && piargs+=(--skill "$TEAM_SKILL_DIR")
|
|
72
64
|
if [ -n "$TEAM_EXTRA_PI_ARGS" ]; then
|
|
73
|
-
#
|
|
74
|
-
#
|
|
75
|
-
|
|
65
|
+
# Match the ownership guard's literal grammar; never re-split/glob the
|
|
66
|
+
# original text, which would turn quote characters into argv data.
|
|
67
|
+
team_literal_argv "$TEAM_EXTRA_PI_ARGS" || return 1
|
|
68
|
+
piargs+=("${TEAM_LITERAL_TOKENS[@]}")
|
|
76
69
|
fi
|
|
77
70
|
printf '%q ' "${piargs[@]}"
|
|
78
71
|
}
|
|
@@ -133,7 +126,7 @@ team_build_prompt() { # <agent> <ID> <taskfile-abs> <worktree> <model> [<session
|
|
|
133
126
|
# 其它 adapter 不提:工具不存在,教了只会让 worker 白找。
|
|
134
127
|
case "${TEAM_AGENT_CMD:-}" in
|
|
135
128
|
''|*'{bg_ext}'*)
|
|
136
|
-
bg_block="$(printf '\n**Long jobs (a gate, a build)**: start them with `team_bg_run` (it returns a job id immediately and keeps\nworking while you go on), then harvest with
|
|
129
|
+
bg_block="$(printf '\n**Long jobs (a gate, a build)**: start them with `team_bg_run` (it returns a job id immediately and keeps\nworking while you go on), then **end your turn** -- the completion wake-up is the normal harvest point: when the\njob finishes you are woken once (several jobs finishing together arrive as one message) and harvest it with\n`team_bg_wait <id>` (the exit code and the log tail come back inline). **In-turn waiting is the bounded\nexception**: use it only when all three hold -- the job is expected to finish within the inline-wait budget (about 2 minutes),\nits result blocks your immediate next step, and no other task work can advance meanwhile.\n')" ;;
|
|
137
130
|
esac
|
|
138
131
|
|
|
139
132
|
cat <<PROMPT
|
|
@@ -162,11 +155,15 @@ another project's help (cross-repo dependency, shared library change), write \`B
|
|
|
162
155
|
needs to do what -- **cross-project communication is the PM's job via \`$cli meeting\` (peer exchange: interfaces,
|
|
163
156
|
advice, problem reports); workers do not attend**. Only decisions that need the user's call go through the user.
|
|
164
157
|
|
|
165
|
-
**Never stop mid-task to ask for confirmation**: end the turn in exactly
|
|
166
|
-
(a) every acceptance command in the brief has been run + the report is written + the branch is pushed + the PR/MR is
|
|
158
|
+
**Never stop mid-task to ask for confirmation**: end the turn in exactly three situations --
|
|
159
|
+
(a) **delivered**: every acceptance command in the brief has been run + the report is written + the branch is pushed + the PR/MR is
|
|
167
160
|
open (or, in local mode, the branch state is settled);
|
|
168
|
-
(b)
|
|
169
|
-
\`$cli notify $agent "<one line>"\`, state \`BLOCKED:\` clearly in the report, then end the turn
|
|
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;
|
|
163
|
+
(c) **suspended on background jobs**: jobs this session started are still running and every step that does not depend
|
|
164
|
+
on their results is done. A suspension is neither a delivery nor a blockage -- do not write the report's final
|
|
165
|
+
verdict and do not notify \`BLOCKED:\` for it; end the turn with its **last line** naming every job you are
|
|
166
|
+
waiting on (\`waiting on: <id>[, <id>…]\`), so the PM can see the ending was deliberate.
|
|
170
167
|
**Never work around a boundary on your own.**
|
|
171
168
|
|
|
172
169
|
Delivery process:
|
|
@@ -183,7 +180,8 @@ Delivery process:
|
|
|
183
180
|
|
|
184
181
|
Task: **$id**${issue:+ (issue #$issue)}. The brief \`$taskfile\` is the PM's read-only file -- do not modify it.${bg_block}${notify_block}
|
|
185
182
|
If this is a resumed run: start with \`git status\` / \`git log --oneline -5\` to see how far you got, and continue
|
|
186
|
-
from that point instead of starting over.
|
|
183
|
+
from that point instead of starting over. A previous session's wake-ups died with its process, so jobs it left
|
|
184
|
+
running will never wake you: check \`state/bg.log\` and \`team bg list\` before you await or re-run their results.
|
|
187
185
|
PROMPT
|
|
188
186
|
}
|
|
189
187
|
|
|
@@ -193,8 +191,7 @@ team_cmd_add_agent() {
|
|
|
193
191
|
while [ $# -gt 0 ]; do
|
|
194
192
|
case "$1" in
|
|
195
193
|
--register) register=1; shift ;;
|
|
196
|
-
--model)
|
|
197
|
-
--model=*) model="${1#*=}"; has_model=1; shift ;;
|
|
194
|
+
--model|--model=*) team_err 'add-agent --model retired;使用 task category 和 config set-task-model'; return 2 ;;
|
|
198
195
|
--fingerprint) fp="${2:?--fingerprint 需要 sha256}"; shift 2 ;;
|
|
199
196
|
--fingerprint=*) fp="${1#*=}"; shift ;;
|
|
200
197
|
--no-install) extra+=(--no-install); shift ;;
|
|
@@ -1052,8 +1049,10 @@ team_dispatch_judge_seat_hint() { # <agent> <worktree>
|
|
|
1052
1049
|
fi ;;
|
|
1053
1050
|
esac
|
|
1054
1051
|
fi
|
|
1055
|
-
|
|
1056
|
-
|
|
1052
|
+
# Even zero-output hints must use the same complete trusted identity as size,
|
|
1053
|
+
# activity and death reads; never stitch partial fields onto the current cwd.
|
|
1054
|
+
team_assignment_load "$agent" || return 0
|
|
1055
|
+
sid="${TEAM_ASSIGN[sid]}"; rec_bytes="${TEAM_ASSIGN[sid_bytes]}"; wt="${TEAM_ASSIGN[worktree]}"
|
|
1057
1056
|
if [ -n "$sid" ] && [ -n "$rec_bytes" ]; then
|
|
1058
1057
|
f="$(team_session_file "$sid" "$wt" 2>/dev/null || true)"
|
|
1059
1058
|
if [ -n "$f" ] && [ -f "$f" ]; then
|
|
@@ -1068,7 +1067,123 @@ team_dispatch_judge_seat_hint() { # <agent> <worktree>
|
|
|
1068
1067
|
return 0
|
|
1069
1068
|
}
|
|
1070
1069
|
|
|
1071
|
-
|
|
1070
|
+
# Public front door: immutable preflight, then seat/admission serialization.
|
|
1071
|
+
team_cmd_dispatch() (
|
|
1072
|
+
local -a original=("$@") positional=()
|
|
1073
|
+
local seat='' printonly=0 arg cfg_fp state_fp task_fp output rc=0
|
|
1074
|
+
while [ $# -gt 0 ]; do
|
|
1075
|
+
case "$1" in
|
|
1076
|
+
--model|--branch) [ $# -ge 2 ] || team_usage_die "dispatch: $1 needs a value"; shift 2 ;;
|
|
1077
|
+
--print) printonly=1; shift ;;
|
|
1078
|
+
--*) shift ;; *) positional+=("$1"); [ -n "$seat" ] || seat="$1"; shift ;;
|
|
1079
|
+
esac
|
|
1080
|
+
done
|
|
1081
|
+
cfg_fp="$(team_config_fingerprint "$TEAM_CONFIG")"
|
|
1082
|
+
[ "${TEAM_CONFIG_LOADED_FP:-$cfg_fp}" = "$cfg_fp" ] || { team_err 'dispatch: config changed after load;重新读取后重试,未写/未启动'; return 1; }
|
|
1083
|
+
if [ "$printonly" = 1 ]; then team_dispatch_execute "${original[@]}"; return $?; fi
|
|
1084
|
+
state_fp="$(team_launch_state_fingerprint "$seat")"
|
|
1085
|
+
task_fp="$(team_launch_task_fingerprint "$seat" "${positional[1]:-}")"
|
|
1086
|
+
output="$( _TEAM_DISPATCH_PREFLIGHT_ONLY=1 team_dispatch_execute "${original[@]}" 2>&1)" || rc=$?
|
|
1087
|
+
[ "$rc" = 0 ] || { printf '%s\n' "$output"; return "$rc"; }
|
|
1088
|
+
local _TEAM_DISPATCH_CONFIG_FP="$cfg_fp" _TEAM_DISPATCH_STATE_FP="$state_fp" _TEAM_DISPATCH_TASK_FP="$task_fp" _TEAM_DISPATCH_TASK_ID="${positional[1]:-}"
|
|
1089
|
+
team_with_lock "seat:$seat" team_with_lock worker-admission team_with_lock "config:$TEAM_CONFIG" team_dispatch_execute "${original[@]}"
|
|
1090
|
+
)
|
|
1091
|
+
team_launch_state_fingerprint() {
|
|
1092
|
+
local f
|
|
1093
|
+
for f in "$TEAM_STATE_DIR/$1.env" "$TEAM_STATE_DIR/$1.pending"; do
|
|
1094
|
+
printf '%s\n' "$f"; [ ! -f "$f" ] || sha256sum "$f"
|
|
1095
|
+
done | sha256sum | cut -d' ' -f1
|
|
1096
|
+
}
|
|
1097
|
+
team_launch_task_fingerprint() {
|
|
1098
|
+
local f wt; wt="$(team_agent_worktree "$1")"
|
|
1099
|
+
{
|
|
1100
|
+
while IFS= read -r f; do [ -z "$f" ] || { printf '%s\n' "$f"; sha256sum "$f"; }; done < <(team_task_briefs "$2")
|
|
1101
|
+
git -C "$wt" symbolic-ref -q HEAD 2>/dev/null || true
|
|
1102
|
+
git -C "$wt" rev-parse HEAD 2>/dev/null || true
|
|
1103
|
+
} | sha256sum | cut -d' ' -f1
|
|
1104
|
+
}
|
|
1105
|
+
team_dispatch_final_snapshot() {
|
|
1106
|
+
[ "$(team_config_fingerprint "$TEAM_CONFIG")" = "$_TEAM_DISPATCH_CONFIG_FP" ] &&
|
|
1107
|
+
[ "$(team_launch_state_fingerprint "$1")" = "$_TEAM_DISPATCH_STATE_FP" ] &&
|
|
1108
|
+
[ "$(team_launch_task_fingerprint "$1" "$_TEAM_DISPATCH_TASK_ID")" = "$_TEAM_DISPATCH_TASK_FP" ] || {
|
|
1109
|
+
team_err 'dispatch: policy/assignment/brief/branch changed during preflight;重新预览后重试,未写/未启动'; return 1;
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
team_dispatch_select_identity() {
|
|
1113
|
+
local agent="$1" id="$2" taskfile="$3" wt="$4" branch="$5" override="$6" fresh="$7"
|
|
1114
|
+
local declarations category oldtask complete=0 matching=0 oldmodel='' oldsid='' origin=''
|
|
1115
|
+
declarations="$(grep -E '^category:' "$taskfile" || true)"
|
|
1116
|
+
[ "$(printf '%s\n' "$declarations" | grep -c .)" = 1 ] || { team_err 'brief 必须唯一 category: header;显式 override 不豁免'; return 1; }
|
|
1117
|
+
category="$(team_trim "${declarations#category:}")"
|
|
1118
|
+
team_category_valid "$category" || { team_err "category 不合法:$category"; return 1; }
|
|
1119
|
+
team_model_policy_guard || return 1
|
|
1120
|
+
team_identity_extra_guard "${TEAM_EXTRA_PI_ARGS:-}" || return 1
|
|
1121
|
+
if team_assignment_load "$agent"; then
|
|
1122
|
+
complete=1; oldtask="${TEAM_ASSIGN[task]}"; oldmodel="${TEAM_ASSIGN[model]}"; oldsid="${TEAM_ASSIGN[sid]}"; origin="${TEAM_ASSIGN[selected_via]}"
|
|
1123
|
+
if [ "$oldtask" = "$id" ] && [ "${TEAM_ASSIGN[taskfile]}" = "$taskfile" ] && [ "${TEAM_ASSIGN[category]}" = "$category" ] &&
|
|
1124
|
+
[ "${TEAM_ASSIGN[branch]}" = "$branch" ] && [ "${TEAM_ASSIGN[worktree]}" = "$wt" ]; then matching=1; fi
|
|
1125
|
+
# P241/B3:只有**自称是 assignment 记录**的文件才在这里被拒(legacy/损坏/半条记录)。
|
|
1126
|
+
# 一份只有无关记账键的文件(旧实现由 `team inbox --ack` 写出来的 `inbox_lines=N`)不是记录,
|
|
1127
|
+
# 按「没有记录」继续派单;否则该席位会被无故要求 --fresh。
|
|
1128
|
+
elif [ "$fresh" != 1 ] && team_assignment_record_present "$agent"; then
|
|
1129
|
+
team_err "$agent: $TEAM_ASSIGN_DIAGNOSTIC;保留磁盘交接,dispatch $agent $id $taskfile --fresh"; return 1
|
|
1130
|
+
fi
|
|
1131
|
+
if [ -f "$TEAM_STATE_DIR/$agent.pending" ]; then
|
|
1132
|
+
local pending_nonce; pending_nonce="$(awk -F= '$1=="launch_nonce"{print substr($0,14)}' "$TEAM_STATE_DIR/$agent.pending")"
|
|
1133
|
+
if [ "$complete" != 1 ] || [ "$pending_nonce" != "${TEAM_ASSIGN[launch_nonce]}" ]; then
|
|
1134
|
+
[ "$fresh" = 1 ] || { team_err 'interrupted pending launch;保存诊断并 --fresh 接管'; return 1; }
|
|
1135
|
+
else team_warn 'committed nonce matches pending;保留完整身份,检查 BOARD 清理故障'; fi
|
|
1136
|
+
fi
|
|
1137
|
+
if [ "$complete" = 1 ] && [ "$oldtask" = "$id" ] && [ "$matching" != 1 ] && [ "$fresh" != 1 ]; then
|
|
1138
|
+
team_err '同任务 brief/category/branch/worktree 身份变化;必须 --fresh'; return 1
|
|
1139
|
+
fi
|
|
1140
|
+
if [ "$matching" = 1 ]; then
|
|
1141
|
+
if [ -n "$override" ] && [ "$override" != "$oldmodel" ] && [ "$fresh" != 1 ]; then
|
|
1142
|
+
team_err '同任务不同完整 model(包括 thinking suffix)必须 --fresh'; return 1
|
|
1143
|
+
fi
|
|
1144
|
+
if [ -z "$override" ] || [ "$override" = "$oldmodel" ]; then
|
|
1145
|
+
TEAM_SELECTED_MODEL="$oldmodel"; TEAM_SELECTED_SID="$oldsid"; TEAM_SELECTED_ORIGIN="$origin"; TEAM_LAUNCH_VIA=assignment
|
|
1146
|
+
if [ -n "$override" ]; then TEAM_SELECTED_ORIGIN=explicit; TEAM_LAUNCH_VIA=explicit; fi
|
|
1147
|
+
[ "$fresh" != 1 ] || TEAM_SELECTED_SID="$(team_unique_sid "$agent" "$wt")" || return 1
|
|
1148
|
+
TEAM_SELECTED_CATEGORY="$category"; TEAM_SELECTED_MODE=continued; [ "$fresh" != 1 ] || TEAM_SELECTED_MODE=fresh
|
|
1149
|
+
return 0
|
|
1150
|
+
fi
|
|
1151
|
+
fi
|
|
1152
|
+
local policy_model; policy_model="$(team_task_policy_model "$category")" || { team_err "category 未映射:$category;config set-task-model $category <model>(override 仍须映射)"; return 1; }
|
|
1153
|
+
TEAM_SELECTED_MODEL="${override:-$policy_model}"; team_config_model_shape_ok "$TEAM_SELECTED_MODEL" || { team_err 'override model 不合法'; return 1; }
|
|
1154
|
+
TEAM_SELECTED_SID="$(team_unique_sid "$agent" "$wt")" || return 1
|
|
1155
|
+
TEAM_SELECTED_ORIGIN=policy; TEAM_LAUNCH_VIA=policy
|
|
1156
|
+
[ -z "$override" ] || { TEAM_SELECTED_ORIGIN=explicit; TEAM_LAUNCH_VIA=explicit; }
|
|
1157
|
+
TEAM_SELECTED_CATEGORY="$category"; TEAM_SELECTED_MODE=fresh
|
|
1158
|
+
}
|
|
1159
|
+
team_dispatch_identity_refusal() { team_err "$1"; return 1; }
|
|
1160
|
+
team_dispatch_prepare_record() {
|
|
1161
|
+
local seat="$1" task="$2" brief="$3" wt="$4" branch="$5" model="$6" origin="$7" via="$8" category="$9"
|
|
1162
|
+
shift 9
|
|
1163
|
+
local sid="$1" nonce="$2" bytes="$3" mode="$4" delivered="$5" field
|
|
1164
|
+
TEAM_ASSIGN_TMP="$TEAM_STATE_DIR/.assignment-$seat-$nonce"
|
|
1165
|
+
{
|
|
1166
|
+
printf 'assignment_version=1\ntask=%s\ntaskfile=%s\ncategory=%s\nbranch=%s\nworktree=%s\nwindow=%s\nseat=%s\nmodel=%s\nselected_via=%s\nlaunch_via=%s\nsid=%s\nlaunch_nonce=%s\nstarted=%s\nsid_bytes=%s\nmode=%s\nidentity_via=%s\n' \
|
|
1167
|
+
"$task" "$brief" "$category" "$branch" "$wt" "$seat" "$seat" "$model" "$origin" "$via" "$sid" "$nonce" "$(team_timestamp)" "$bytes" "$mode" "$delivered"
|
|
1168
|
+
} > "$TEAM_ASSIGN_TMP" || return 1
|
|
1169
|
+
if ! team_assignment_load "$seat" "$TEAM_ASSIGN_TMP"; then
|
|
1170
|
+
team_err "planned assignment rejected: $TEAM_ASSIGN_DIAGNOSTIC"; rm -f "$TEAM_ASSIGN_TMP"; return 1
|
|
1171
|
+
fi
|
|
1172
|
+
if [ -f "$TEAM_STATE_DIR/$seat.pending" ]; then
|
|
1173
|
+
local prior_nonce; prior_nonce="$(awk -F= '$1=="launch_nonce"{print substr($0,14)}' "$TEAM_STATE_DIR/$seat.pending")"
|
|
1174
|
+
[[ "$prior_nonce" =~ ^[A-Za-z0-9._-]+$ ]] || prior_nonce="unknown-$(sha256sum "$TEAM_STATE_DIR/$seat.pending" | cut -c1-16)"
|
|
1175
|
+
cp "$TEAM_STATE_DIR/$seat.pending" "$TEAM_STATE_DIR/dispatch-$seat.interrupted-$prior_nonce" || { rm -f "$TEAM_ASSIGN_TMP"; return 1; }
|
|
1176
|
+
fi
|
|
1177
|
+
cp "$TEAM_ASSIGN_TMP" "$TEAM_STATE_DIR/$seat.pending" || { rm -f "$TEAM_ASSIGN_TMP"; return 1; }
|
|
1178
|
+
}
|
|
1179
|
+
team_dispatch_attempt_fail() {
|
|
1180
|
+
local seat="$1" nonce="$2" reason="$3"
|
|
1181
|
+
printf '%s nonce=%s failed=%s\n' "$(team_timestamp)" "$nonce" "$reason" >> "$TEAM_STATE_DIR/dispatch-$seat.attempts.log"
|
|
1182
|
+
[ ! -f "$TEAM_STATE_DIR/$seat.pending" ] || mv "$TEAM_STATE_DIR/$seat.pending" "$TEAM_STATE_DIR/dispatch-$seat.failed-$nonce"
|
|
1183
|
+
rm -f "${TEAM_ASSIGN_TMP:-/nonexistent}"
|
|
1184
|
+
team_tmux_kill_window "$TEAM_SESSION:$seat" >/dev/null 2>&1 || true
|
|
1185
|
+
}
|
|
1186
|
+
team_dispatch_execute() {
|
|
1072
1187
|
team_require_cmd tmux "agent 在 tmux 窗口里跑,PM 需要能旁观与追问"
|
|
1073
1188
|
local agent="" id="" taskfile="" model="" branch_flag="" fresh=0 printonly=0 overflow=0 force=0
|
|
1074
1189
|
while [ $# -gt 0 ]; do
|
|
@@ -1100,7 +1215,7 @@ team_cmd_dispatch() {
|
|
|
1100
1215
|
# 任务书路径:先按 cwd 解析,再按主工作树解析
|
|
1101
1216
|
[ -f "$taskfile" ] || taskfile="$TEAM_MAIN_ROOT/$taskfile"
|
|
1102
1217
|
[ -f "$taskfile" ] || team_die "找不到任务书:$taskfile"
|
|
1103
|
-
taskfile="$(
|
|
1218
|
+
taskfile="$(readlink -f "$taskfile")"
|
|
1104
1219
|
# M6.3 F15:任务书必须在项目主工作树里。提示词命令 worker「work only inside <project>」,
|
|
1105
1220
|
# 却把 /tmp/... 称为 "repo-relative path"(自相矛盾);而且项目外的文件不归项目管。
|
|
1106
1221
|
case "$taskfile" in
|
|
@@ -1166,11 +1281,24 @@ team_cmd_dispatch() {
|
|
|
1166
1281
|
# M14:解析顺序 = --model 显式参数 > 配置(TEAM_AGENT_MODELS 的 per-agent > TEAM_DEFAULT_MODEL)。
|
|
1167
1282
|
# 名册 state 里的 model 只是「上次用了什么」的展示记录(roster/ps 标注来源用),不再当默认来源 ——
|
|
1168
1283
|
# 旧行为(state 优先)让配置改了也不生效:名册里的 deepseek 旧记录压过了新配的 k3-256k。
|
|
1169
|
-
local
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1284
|
+
local identity_ok=1 identity_output=''
|
|
1285
|
+
local TEAM_SELECTED_MODEL='' TEAM_SELECTED_SID='' TEAM_SELECTED_ORIGIN='' TEAM_LAUNCH_VIA='' TEAM_SELECTED_CATEGORY='' TEAM_SELECTED_MODE=''
|
|
1286
|
+
# Execute in this shell so the accepted identity is not lost through a subshell.
|
|
1287
|
+
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"
|
|
1289
|
+
else
|
|
1290
|
+
team_dispatch_select_identity "$agent" "$id" "$taskfile" "$wt" "${TEAM_CHECKED_BRANCH:-$br_name}" "$model" "$fresh" >/dev/null || return 1
|
|
1291
|
+
model="$TEAM_SELECTED_MODEL"
|
|
1292
|
+
fi
|
|
1293
|
+
local provider="${model%%/*}" sid="$TEAM_SELECTED_SID"
|
|
1294
|
+
local model_src="$TEAM_SELECTED_ORIGIN"
|
|
1295
|
+
# P228/R6(OBS1):本次启动的模板**实际交付**哪些身份字段(发布不得多于它)。内建 Pi = 三个全交;
|
|
1296
|
+
# 自定义模板 = 模板里已绑定的 selector(角色守卫在预检时已证过);opaque = 空。发布路径与记录都用它。
|
|
1297
|
+
local identity_via
|
|
1298
|
+
if ! identity_via="$(team_launch_identity_fields worker "${TEAM_AGENT_CMD:-}" "${TEAM_SELECTED_MODE:-fresh}")"; then
|
|
1299
|
+
team_df_run_lib team_dispatch_identity_refusal '无法判定模板交付的身份字段(模板不合法)'
|
|
1300
|
+
identity_ok=0; identity_via=''
|
|
1301
|
+
fi
|
|
1174
1302
|
|
|
1175
1303
|
team_df_run_lib team_dispatch_judge_mem "$agent" "$id" "$taskfile"
|
|
1176
1304
|
# P144:磁盘/inode 腿 —— 判的是这个 worker 真正要写的两个文件系统(临时根 + 它的工作树,
|
|
@@ -1180,12 +1308,13 @@ team_cmd_dispatch() {
|
|
|
1180
1308
|
team_df_run_lib team_disk_guard "$disk_tmp" "$wt"
|
|
1181
1309
|
# 读数是一条「说明」(rc=0 的 finding):放行时在启动前那一趟里打印;被拒时由拒绝本身带读数。
|
|
1182
1310
|
if [ "$_TEAM_DF_RUN_RC" -eq 0 ]; then team_df_run_lib team_capacity_line "$disk_tmp" "$wt"; fi
|
|
1183
|
-
team_df_run_lib team_model_guard "$model"
|
|
1311
|
+
[ "$identity_ok" != 1 ] || team_df_run_lib team_model_guard "$model" "$agent"
|
|
1184
1312
|
# M4.3 A:会话规模 vs 模型窗口(默认拒绝,--fresh / --allow-overflow 是出路)
|
|
1185
|
-
team_df_run_lib team_guard_resume_session "$agent" "$model" "$sid" "$wt" "$fresh" "$overflow" "$id" "$taskfile"
|
|
1313
|
+
[ "$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"
|
|
1186
1314
|
# agent adapter:空配置 = 内置 Pi(老路径,报错文案也不变);die 被捕获成阻塞项,不带走其他判定
|
|
1187
1315
|
team_df_run_lib team_agent_check_launch
|
|
1188
1316
|
if [ "$_TEAM_DF_RUN_RC" -eq 0 ]; then
|
|
1317
|
+
team_df_run_lib team_template_identity_guard launch "${TEAM_AGENT_CMD:-}" "${TEAM_SELECTED_MODE:-fresh}"
|
|
1189
1318
|
team_df_run team_dispatch_judge_agent_bin "$agent"
|
|
1190
1319
|
else
|
|
1191
1320
|
team_df_say " adapter 配置不合法 → agent 可执行文件判不了(见上面那一项)"
|
|
@@ -1199,6 +1328,10 @@ team_cmd_dispatch() {
|
|
|
1199
1328
|
return 1
|
|
1200
1329
|
fi
|
|
1201
1330
|
|
|
1331
|
+
[ "${_TEAM_DISPATCH_PREFLIGHT_ONLY:-0}" != 1 ] || return 0
|
|
1332
|
+
if [ "$printonly" != 1 ]; then
|
|
1333
|
+
team_dispatch_final_snapshot "$agent" || return 1
|
|
1334
|
+
fi
|
|
1202
1335
|
# 报告通过:这时才允许写 state / 打计划 / 开窗
|
|
1203
1336
|
# 必需依赖体检(D10):缺依赖**不拒绝**派单(worker 照样能干活),但 PM 必须知道证据/spec 层是缺的。
|
|
1204
1337
|
# 一行、每次派单只说一次。
|
|
@@ -1219,9 +1352,10 @@ team_cmd_dispatch() {
|
|
|
1219
1352
|
prompt="$(team_build_prompt "$agent" "$id" "$taskfile" "$wt" "$model" "$sid" "$task_branch" "$task_branch_src")"
|
|
1220
1353
|
# 提示词落盘:模板里的 {prompt_file} 用它,排查“到底派了什么”也看它(state/ 已 gitignore)
|
|
1221
1354
|
prompt_file="$(team_agent_prompt_file "$agent" "$id")"
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1355
|
+
if [ "$printonly" != 1 ]; then
|
|
1356
|
+
mkdir -p "$TEAM_STATE_DIR"; printf '%s\n' "$prompt" > "$prompt_file"
|
|
1357
|
+
fi
|
|
1358
|
+
agent_cmd="$(team_agent_launch_cmd "$agent" "$sid" "$wt" "$prompt_file" "$model")" || return 1
|
|
1225
1359
|
|
|
1226
1360
|
# notify 模板坏掉时不阻塞派单,但必须说清楚(否则 worker 回合结束没人知道);
|
|
1227
1361
|
# 提示词那侧会用同一个判断把通知段换成「写进报告」(F8)。
|
|
@@ -1233,6 +1367,15 @@ team_cmd_dispatch() {
|
|
|
1233
1367
|
fi
|
|
1234
1368
|
|
|
1235
1369
|
if [ "$printonly" = "1" ]; then
|
|
1370
|
+
# P228/R6(OBS1):只发布模板真的交付了的身份字段(未交付的不写成已启动身份);全交付时与旧行逐字节相同。
|
|
1371
|
+
local id_line="identity: category=$TEAM_SELECTED_CATEGORY"
|
|
1372
|
+
team_identity_field_in model "$identity_via" && id_line="$id_line model=$model"
|
|
1373
|
+
id_line="$id_line selected_via=$model_src launch_via=$TEAM_LAUNCH_VIA mode=$TEAM_SELECTED_MODE"
|
|
1374
|
+
team_identity_field_in session_id "$identity_via" && id_line="$id_line sid=$sid"
|
|
1375
|
+
printf '%s\n' "$id_line"
|
|
1376
|
+
local id_undelivered; id_undelivered="$(team_identity_undelivered_text "$identity_via")"
|
|
1377
|
+
[ -z "$id_undelivered" ] || printf 'identity-delivery: 未交付 %s(模板没有绑定这些身份占位符:不当作已启动身份发布)\n' "$id_undelivered"
|
|
1378
|
+
[ "$TEAM_SELECTED_MODE" != fresh ] || printf 'fresh preview SID is a non-reserved candidate; actual launch allocates a new SID\n'
|
|
1236
1379
|
printf '=== agent 命令(adapter: %s)===\n' "$(team_agent_adapter_label)"
|
|
1237
1380
|
# M40:身份环境单独一行(真窗口里它在 cd 之前执行;这里不许破 `^cd ` 的行契约)
|
|
1238
1381
|
printf '身份环境(启动前先执行):%s\n' "$(team_identity_env_prefix "$wt")"
|
|
@@ -1263,6 +1406,9 @@ team_cmd_dispatch() {
|
|
|
1263
1406
|
mkdir -p "$TEAM_STATE_DIR"
|
|
1264
1407
|
while [ "$attempt" -lt 2 ] && [ -z "$pid" ]; do
|
|
1265
1408
|
attempt=$((attempt + 1))
|
|
1409
|
+
nonce="$(date +%s)-$BASHPID-$RANDOM-$RANDOM-$attempt"
|
|
1410
|
+
team_dispatch_prepare_record "$agent" "$id" "$taskfile" "$wt" "$task_branch" "$model" "$model_src" "$TEAM_LAUNCH_VIA" "$TEAM_SELECTED_CATEGORY" "$sid" "$nonce" "$sid_bytes_at_launch" "$TEAM_SELECTED_MODE" "$identity_via" || return 1
|
|
1411
|
+
printf '%s nonce=%s sid=%s attempt=%s\n' "$(team_timestamp)" "$nonce" "$sid" "$attempt" >> "$TEAM_STATE_DIR/dispatch-$agent.attempts.log"
|
|
1266
1412
|
if team_agent_window_exists "$agent"; then
|
|
1267
1413
|
if [ "$attempt" = "1" ]; then
|
|
1268
1414
|
# P55(遗体复用留证):窗口还在但 pane 已死 = 上一轮死在里面 —— 先把现场落盘再替换
|
|
@@ -1278,7 +1424,6 @@ team_cmd_dispatch() {
|
|
|
1278
1424
|
sleep 0.5
|
|
1279
1425
|
fi
|
|
1280
1426
|
# 每轮换 nonce:证据必须来自这一轮的启动(上一轮留在盘上的不算数)
|
|
1281
|
-
nonce="$(date +%s)-$$-$RANDOM-$attempt"
|
|
1282
1427
|
rm -f "$marker" "$exitfile" "$tailfile"
|
|
1283
1428
|
# 命令里写死绝对路径 + 短暂等待(窗口 shell 可能刚起、PATH/rc 还没就绪);
|
|
1284
1429
|
# 拿到可执行文件后先写下 (nonce, pid),再跑 agent —— 这一行就是「harness 真的执行了」的证据。
|
|
@@ -1329,6 +1474,7 @@ team_cmd_dispatch() {
|
|
|
1329
1474
|
team_dim " 排查:tmux 里手动跑一次 —— cd $wt 然后跑 dispatch --print 打出的那条命令;看 agent 自己的报错"
|
|
1330
1475
|
team_dim " 常见原因:可执行文件/模型/provider 不可用;旧会话楔死(换新会话:--fresh);内存/磁盘不足"
|
|
1331
1476
|
team_dim " 重派:$TEAM_CLI dispatch $agent $id $taskfile --fresh"
|
|
1477
|
+
team_dispatch_attempt_fail "$agent" "$nonce" 'no nonce proof'
|
|
1332
1478
|
return 1
|
|
1333
1479
|
fi
|
|
1334
1480
|
|
|
@@ -1346,22 +1492,15 @@ team_cmd_dispatch() {
|
|
|
1346
1492
|
team_dim " 手工复现:cd $(printf '%q' "$wt") && $agent_cmd"
|
|
1347
1493
|
team_dim " 常见原因:首词不在窗口(登录 bash)的 PATH 里(现在会被解析成绝对路径,除非 TEAM_AGENT_BIN 指向别的名字);CLI 参数/认证被拒"
|
|
1348
1494
|
team_dim " 重派:$TEAM_CLI dispatch $agent $id $taskfile"
|
|
1495
|
+
team_dispatch_attempt_fail "$agent" "$nonce" "custom exit=$exit_code"
|
|
1349
1496
|
return 1
|
|
1350
1497
|
fi
|
|
1351
1498
|
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
team_state_set "$agent" taskfile "$taskfile"
|
|
1358
|
-
[ -n "$task_branch" ] && team_state_set "$agent" branch "$task_branch"
|
|
1359
|
-
team_state_set "$agent" started "$(team_timestamp)"
|
|
1360
|
-
# P140(R6)/ P151(F5):记下这一轮的会话 id 与**启动时**(worker 能跑之前)的会话文件字节数
|
|
1361
|
-
# —— 下一轮据此判「一个字节没长」。只在派单真的成功之后才落盘。
|
|
1362
|
-
team_state_set "$agent" sid "$sid"
|
|
1363
|
-
team_state_set "$agent" sid_bytes "$sid_bytes_at_launch"
|
|
1364
|
-
team_board_set "$id" wip 2>/dev/null || true
|
|
1499
|
+
if ! mv -f "$TEAM_ASSIGN_TMP" "$TEAM_STATE_DIR/$agent.env"; then
|
|
1500
|
+
team_dispatch_attempt_fail "$agent" "$nonce" 'publication failed'; return 1
|
|
1501
|
+
fi
|
|
1502
|
+
if team_board_set "$id" wip; then rm -f "$TEAM_STATE_DIR/$agent.pending"
|
|
1503
|
+
else team_warn 'assignment 已完整提交;BOARD 更新失败,pending nonce 保留诊断,不撤销启动'; fi
|
|
1365
1504
|
|
|
1366
1505
|
# M9.3:`--force` 接管了另一个没结束的任务 —— 审计里留一条(输出里已经写明,这里落盘)
|
|
1367
1506
|
if [ -n "${TEAM_DISPATCH_STACK_PREV:-}" ]; then
|
|
@@ -1374,7 +1513,7 @@ team_cmd_dispatch() {
|
|
|
1374
1513
|
done <<< "$TEAM_DISPATCH_AUDIT_LINES"
|
|
1375
1514
|
TEAM_DISPATCH_AUDIT_LINES=""
|
|
1376
1515
|
fi
|
|
1377
|
-
team_ok "dispatched $id → $TEAM_SESSION:$agent(含启动校验:proof=spawn pid=$pid
|
|
1516
|
+
team_ok "dispatched $id → $TEAM_SESSION:$agent(含启动校验:proof=spawn pid=$pid;$(team_dispatch_identity_claim "$identity_via" "$provider" "${model#*/}" "$sid"))"
|
|
1378
1517
|
# 观察结论也要说出来(不是只报“成功”):内建 Pi 路径下,agent 是「已经退出」还是「还在跑」,
|
|
1379
1518
|
# PM 都要拿到**观察到的事实**(退出码来自窗口 harness 写下的事件证据,不是猜的;也不再假设
|
|
1380
1519
|
# 「窗口一定已经回到 shell」——那正是 M7.5 里被环境 churn 打脸的那句话)。
|
|
@@ -1656,6 +1795,27 @@ team_cmd_notify() {
|
|
|
1656
1795
|
return "$knock_rc"
|
|
1657
1796
|
}
|
|
1658
1797
|
|
|
1798
|
+
team_teardown_seat_locked() {
|
|
1799
|
+
local a="$1" purge="$2" force="$3" register="$4" fp="$5" w wt
|
|
1800
|
+
if [ "$register" = 1 ]; then team_config_write_roster remove "$a" "$fp" 0 || return $?; fi
|
|
1801
|
+
w="$(team_state_get "$a" window "$a")"
|
|
1802
|
+
if team_tmux_has_window "$TEAM_SESSION" "$w"; then
|
|
1803
|
+
tmux kill-window -t "$TEAM_SESSION:$w" 2>/dev/null || return 1
|
|
1804
|
+
team_ok "kill window $TEAM_SESSION:$w"
|
|
1805
|
+
fi
|
|
1806
|
+
team_state_clear "$a"
|
|
1807
|
+
rm -f "$TEAM_STATE_DIR/$a.pending" "$TEAM_STATE_DIR"/.assignment-"$a"-*
|
|
1808
|
+
if [ "$purge" = 1 ]; then
|
|
1809
|
+
wt="$(team_agent_worktree "$a")"
|
|
1810
|
+
if [ -d "$wt" ]; then
|
|
1811
|
+
if [ "$force" != 1 ] && [ -n "$(git -C "$wt" status --porcelain 2>/dev/null)" ]; then
|
|
1812
|
+
team_warn "worktree 有未提交改动,保留:$wt(要强删:--force)"; return 0
|
|
1813
|
+
fi
|
|
1814
|
+
team_git worktree remove --force "$wt" 2>/dev/null && team_ok "remove worktree $wt" || team_warn "worktree 删除失败:$wt"
|
|
1815
|
+
team_scan_invalidate git
|
|
1816
|
+
fi
|
|
1817
|
+
fi
|
|
1818
|
+
}
|
|
1659
1819
|
team_cmd_teardown() {
|
|
1660
1820
|
local agent="" all=0 purge=0 force=0 register=0 fp=""
|
|
1661
1821
|
while [ $# -gt 0 ]; do
|
|
@@ -1680,29 +1840,9 @@ team_cmd_teardown() {
|
|
|
1680
1840
|
fi
|
|
1681
1841
|
# P99/R2:--register 先缩名册(审计写入器),再走今天的窗口/state/worktree 清理;
|
|
1682
1842
|
# 名册里没有这个席位就 exit 5、什么都不动。不带旗标时名册逐字节不变(今天的行为是默认)。
|
|
1683
|
-
|
|
1684
|
-
local rrc=0
|
|
1685
|
-
team_config_write_roster remove "$agent" "$fp" 0 || rrc=$?
|
|
1686
|
-
[ "$rrc" -eq 0 ] || return "$rrc"
|
|
1687
|
-
fi
|
|
1688
|
-
local a w wt
|
|
1843
|
+
local a
|
|
1689
1844
|
for a in "${targets[@]}"; do
|
|
1690
|
-
|
|
1691
|
-
if team_tmux_has_window "$TEAM_SESSION" "$w"; then
|
|
1692
|
-
tmux kill-window -t "$TEAM_SESSION:$w" 2>/dev/null && team_ok "kill window $TEAM_SESSION:$w"
|
|
1693
|
-
fi
|
|
1694
|
-
team_state_clear "$a"
|
|
1695
|
-
if [ "$purge" = "1" ]; then
|
|
1696
|
-
wt="$(team_agent_worktree "$a")"
|
|
1697
|
-
if [ -d "$wt" ]; then
|
|
1698
|
-
if [ "$force" != "1" ] && [ -n "$(git -C "$wt" status --porcelain 2>/dev/null)" ]; then
|
|
1699
|
-
team_warn "worktree 有未提交改动,保留:$wt(要强删:--force)"
|
|
1700
|
-
continue
|
|
1701
|
-
fi
|
|
1702
|
-
team_git worktree remove --force "$wt" 2>/dev/null && team_ok "remove worktree $wt" || team_warn "worktree 删除失败:$wt"
|
|
1703
|
-
team_scan_invalidate git # M50
|
|
1704
|
-
fi
|
|
1705
|
-
fi
|
|
1845
|
+
team_with_lock "seat:$a" team_with_lock worker-admission team_teardown_seat_locked "$a" "$purge" "$force" "$register" "$fp" || return $?
|
|
1706
1846
|
done
|
|
1707
1847
|
[ "$purge" != "1" ] && team_dim "worktree 仍保留(加 --purge 删除);分支保留,需要时 git branch -d"
|
|
1708
1848
|
return 0
|
|
@@ -21,8 +21,12 @@
|
|
|
21
21
|
# 换行、`#` 一律拒绝;notify 扩展那 8 个扁平读取器解析的键出现 ' 也拒绝(那个读取器没有转义)。
|
|
22
22
|
# * 原子写:同目录临时文件 → bash -n 复核 → 保留权限 → mv;任何失败都留下原字节、不留临时文件。
|
|
23
23
|
# 返回 0 = 已写入;非 0 = 拒绝/写失败(原因在 stderr)。
|
|
24
|
-
team_config_set_in_file() {
|
|
25
|
-
|
|
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
|
-
|
|
66
|
-
|
|
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
|
-
|
|
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 ' →
|
|
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'
|