teamsmith 0.0.0-stage → 0.1.2
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/LICENSE +21 -0
- package/README.md +158 -2
- package/bin/team.mjs +59 -0
- package/install.sh +94 -0
- package/package.json +37 -4
- package/skills/teamsmith/CHANGELOG.md +763 -0
- package/skills/teamsmith/SKILL.md +312 -0
- package/skills/teamsmith/extension/team-bg.ts +435 -0
- package/skills/teamsmith/extension/team-inbox-watch.ts +1412 -0
- package/skills/teamsmith/extension/team-notify.ts +663 -0
- package/skills/teamsmith/references/agent-adapters.md +643 -0
- package/skills/teamsmith/references/config.md +477 -0
- package/skills/teamsmith/references/meeting.md +124 -0
- package/skills/teamsmith/references/memory.md +133 -0
- package/skills/teamsmith/references/migration.md +227 -0
- package/skills/teamsmith/references/openspec.md +222 -0
- package/skills/teamsmith/references/philosophy.md +95 -0
- package/skills/teamsmith/references/protocol.md +712 -0
- package/skills/teamsmith/references/troubleshooting.md +1384 -0
- package/skills/teamsmith/references/workflows.md +448 -0
- package/skills/teamsmith/scripts/lib/cmd-agents.sh +1709 -0
- package/skills/teamsmith/scripts/lib/cmd-bg.sh +284 -0
- package/skills/teamsmith/scripts/lib/cmd-bootstrap.sh +311 -0
- package/skills/teamsmith/scripts/lib/cmd-config.sh +1156 -0
- package/skills/teamsmith/scripts/lib/cmd-death.sh +562 -0
- package/skills/teamsmith/scripts/lib/cmd-docs.sh +149 -0
- package/skills/teamsmith/scripts/lib/cmd-draft.sh +124 -0
- package/skills/teamsmith/scripts/lib/cmd-init.sh +212 -0
- package/skills/teamsmith/scripts/lib/cmd-meeting.sh +904 -0
- package/skills/teamsmith/scripts/lib/cmd-outbox.sh +196 -0
- package/skills/teamsmith/scripts/lib/cmd-project.sh +642 -0
- package/skills/teamsmith/scripts/lib/cmd-review.sh +1393 -0
- package/skills/teamsmith/scripts/lib/cmd-status.sh +1399 -0
- package/skills/teamsmith/scripts/lib/cmd-update.sh +191 -0
- package/skills/teamsmith/scripts/lib/cmd-watch.sh +1681 -0
- package/skills/teamsmith/scripts/lib/common.sh +4964 -0
- package/skills/teamsmith/scripts/lib/draft-entry.sh +51 -0
- package/skills/teamsmith/scripts/lib/outbox.sh +2042 -0
- package/skills/teamsmith/scripts/lib/tmux-argv.sh +165 -0
- package/skills/teamsmith/scripts/monitor.mjs +616 -0
- package/skills/teamsmith/scripts/panel/README.md +192 -0
- package/skills/teamsmith/scripts/panel/build.sh +47 -0
- package/skills/teamsmith/scripts/panel/bun.lock +109 -0
- package/skills/teamsmith/scripts/panel/draft-send.sh +68 -0
- package/skills/teamsmith/scripts/panel/package.json +24 -0
- package/skills/teamsmith/scripts/panel/panel.js +388 -0
- package/skills/teamsmith/scripts/panel/src/App.tsx +2150 -0
- package/skills/teamsmith/scripts/panel/src/clipboard.ts +154 -0
- package/skills/teamsmith/scripts/panel/src/compose.ts +691 -0
- package/skills/teamsmith/scripts/panel/src/data.ts +555 -0
- package/skills/teamsmith/scripts/panel/src/format.ts +50 -0
- package/skills/teamsmith/scripts/panel/src/layout.ts +2562 -0
- package/skills/teamsmith/scripts/panel/src/main.tsx +894 -0
- package/skills/teamsmith/scripts/panel/src/markdown.ts +340 -0
- package/skills/teamsmith/scripts/panel/src/sanitize.ts +42 -0
- package/skills/teamsmith/scripts/panel/src/settings.ts +154 -0
- package/skills/teamsmith/scripts/panel/src/strings/en.ts +416 -0
- package/skills/teamsmith/scripts/panel/src/strings/index.ts +65 -0
- package/skills/teamsmith/scripts/panel/src/strings/types.ts +9 -0
- package/skills/teamsmith/scripts/panel/src/strings/zh.ts +414 -0
- package/skills/teamsmith/scripts/panel/src/theme.ts +116 -0
- package/skills/teamsmith/scripts/panel/src/types.ts +652 -0
- package/skills/teamsmith/scripts/panel/src/width.ts +105 -0
- package/skills/teamsmith/scripts/panel/tsconfig.json +16 -0
- package/skills/teamsmith/scripts/shim/signal-gate +156 -0
- package/skills/teamsmith/scripts/shim/tmux +403 -0
- package/skills/teamsmith/scripts/team +143 -0
- package/skills/teamsmith/templates/AGENTS.section.md.tmpl +147 -0
- package/skills/teamsmith/templates/BOARD.md.tmpl +18 -0
- package/skills/teamsmith/templates/DECISIONS.md.tmpl +22 -0
- package/skills/teamsmith/templates/OWNERSHIP.md.tmpl +25 -0
- package/skills/teamsmith/templates/PROTOCOL.md.tmpl +84 -0
- package/skills/teamsmith/templates/ROADMAP.md.tmpl +29 -0
- package/skills/teamsmith/templates/config.sh.tmpl +106 -0
- package/skills/teamsmith/templates/memory-seed.md.tmpl +46 -0
- package/skills/teamsmith/templates/pm-prompt.md.tmpl +110 -0
- package/skills/teamsmith/templates/report.md.tmpl +36 -0
- package/skills/teamsmith/templates/task.md.tmpl +65 -0
- package/skills/teamsmith/templates/threads-README.md +17 -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 +800 -0
- package/skills/teamsmith/tests/config-cli.sh +1562 -0
- package/skills/teamsmith/tests/container-tmux.sh +493 -0
- package/skills/teamsmith/tests/coverage-inventory.sh +173 -0
- package/skills/teamsmith/tests/death-cause.sh +564 -0
- package/skills/teamsmith/tests/delivery-truth.sh +1231 -0
- package/skills/teamsmith/tests/fake-tui.py +450 -0
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/README.md +60 -0
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/judge-second.py +139 -0
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/mock-server.py +29 -0
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/observe.ts +20 -0
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/run-case.sh +79 -0
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/scenario.sh +175 -0
- package/skills/teamsmith/tests/fixtures/p55/flip-p49.sh +229 -0
- package/skills/teamsmith/tests/fixtures/p71-incident/README.md +22 -0
- package/skills/teamsmith/tests/fixtures/p71-incident/dev2.seen +8 -0
- package/skills/teamsmith/tests/fixtures/p71-incident/dev2.wake +9 -0
- package/skills/teamsmith/tests/fixtures/p71-incident/pm-nudges.wake +3 -0
- package/skills/teamsmith/tests/fixtures/signal-lint-cases.txt +40 -0
- package/skills/teamsmith/tests/flip-glue.sh +162 -0
- package/skills/teamsmith/tests/flip-m12-26c.sh +129 -0
- package/skills/teamsmith/tests/flip-m12.sh +185 -0
- package/skills/teamsmith/tests/flip-m16.sh +166 -0
- package/skills/teamsmith/tests/flip-m17.sh +204 -0
- package/skills/teamsmith/tests/flip-m33.sh +284 -0
- package/skills/teamsmith/tests/flip-m34.sh +96 -0
- package/skills/teamsmith/tests/flip-m37.sh +185 -0
- package/skills/teamsmith/tests/flip-m4.3.sh +375 -0
- package/skills/teamsmith/tests/flip-m43.sh +128 -0
- package/skills/teamsmith/tests/flip-m44.sh +262 -0
- package/skills/teamsmith/tests/flip-m45.sh +244 -0
- package/skills/teamsmith/tests/flip-m46.sh +238 -0
- package/skills/teamsmith/tests/flip-m48.sh +304 -0
- package/skills/teamsmith/tests/flip-m6.2.sh +205 -0
- package/skills/teamsmith/tests/flip-m6.3.sh +283 -0
- package/skills/teamsmith/tests/flip-m6.4.sh +267 -0
- package/skills/teamsmith/tests/flip-m6.5.sh +113 -0
- package/skills/teamsmith/tests/flip-m7.1.sh +135 -0
- package/skills/teamsmith/tests/flip-m7.2.sh +321 -0
- package/skills/teamsmith/tests/flip-p144.sh +112 -0
- package/skills/teamsmith/tests/flip-p156.sh +133 -0
- package/skills/teamsmith/tests/flip-p158.sh +301 -0
- package/skills/teamsmith/tests/flip-p160.sh +182 -0
- package/skills/teamsmith/tests/flip-p171.sh +249 -0
- package/skills/teamsmith/tests/flip-p18.1.sh +95 -0
- package/skills/teamsmith/tests/flip-p20.sh +286 -0
- package/skills/teamsmith/tests/flip-p201.sh +249 -0
- package/skills/teamsmith/tests/flip-p210.sh +239 -0
- package/skills/teamsmith/tests/flip-p211.sh +152 -0
- package/skills/teamsmith/tests/flip-p217.sh +288 -0
- package/skills/teamsmith/tests/flip-p22.sh +123 -0
- package/skills/teamsmith/tests/flip-p23.sh +239 -0
- package/skills/teamsmith/tests/flip-p25.sh +165 -0
- package/skills/teamsmith/tests/flip-p71.sh +184 -0
- package/skills/teamsmith/tests/flip-p72.sh +202 -0
- package/skills/teamsmith/tests/frames/README.md +176 -0
- package/skills/teamsmith/tests/frames/p78-conversation-rule-below-box.txt +6 -0
- package/skills/teamsmith/tests/frames/p78-cursor-mid-draft.txt +6 -0
- package/skills/teamsmith/tests/frames/p78-draft-rule-below-cursor-line.txt +6 -0
- package/skills/teamsmith/tests/frames/p78-draft-rule-below-cursor.txt +6 -0
- package/skills/teamsmith/tests/frames/p78-draft-rule-blank-region.txt +6 -0
- package/skills/teamsmith/tests/frames/p78-draft-rule-only.txt +5 -0
- package/skills/teamsmith/tests/frames/p78-spinner-row-below-cursor.txt +6 -0
- package/skills/teamsmith/tests/frames/p78-wider-rule-below-cursor.txt +6 -0
- package/skills/teamsmith/tests/frames/p86-f1-mixed-width-disjoint-box.txt +8 -0
- package/skills/teamsmith/tests/frames/p86-f1-narrower-width-disjoint-box.txt +8 -0
- package/skills/teamsmith/tests/frames/p86-f1-spinner-top-disjoint-box.txt +8 -0
- package/skills/teamsmith/tests/frames/pi-0.85.1-update-banner.txt +30 -0
- package/skills/teamsmith/tests/frames/pi-0.87.0-draft-half-sentence.txt +30 -0
- package/skills/teamsmith/tests/frames/pi-0.87.0-empty-box.txt +30 -0
- package/skills/teamsmith/tests/frames/pi-0.87.0-one-line-draft.txt +30 -0
- package/skills/teamsmith/tests/frames/pi-0.87.0-project-trust-prompt.txt +30 -0
- package/skills/teamsmith/tests/frames/pi-0.99.2-empty-editor.txt +32 -0
- package/skills/teamsmith/tests/frames/pi-0.99.2-human-draft.txt +32 -0
- package/skills/teamsmith/tests/frames/pi-1.0.0-git-error-in-box.txt +32 -0
- package/skills/teamsmith/tests/gate-guard.sh +112 -0
- package/skills/teamsmith/tests/guard-matrix.sh +233 -0
- package/skills/teamsmith/tests/install-shape.sh +731 -0
- package/skills/teamsmith/tests/ledger-ban.sh +612 -0
- package/skills/teamsmith/tests/lib/box-judge.sh +68 -0
- package/skills/teamsmith/tests/lib/checkout-shape.sh +129 -0
- package/skills/teamsmith/tests/lib/loop-scan.awk +114 -0
- package/skills/teamsmith/tests/lib/pty-wait.sh +676 -0
- package/skills/teamsmith/tests/lib/section-guard.sh +855 -0
- package/skills/teamsmith/tests/lib/shell-lex.pl +261 -0
- package/skills/teamsmith/tests/lib/tmp-root.sh +528 -0
- package/skills/teamsmith/tests/lib/tmux-cap.sh +35 -0
- package/skills/teamsmith/tests/lib/tmux-iso-call-probe.sh +81 -0
- package/skills/teamsmith/tests/lib/tmux-iso-probe.sh +46 -0
- package/skills/teamsmith/tests/lib/tmux-iso.sh +381 -0
- package/skills/teamsmith/tests/load-experiment.sh +290 -0
- package/skills/teamsmith/tests/loop-inventory.tsv +84 -0
- package/skills/teamsmith/tests/panel-b2-slow-stub.sh +19 -0
- package/skills/teamsmith/tests/panel-b2.sh +1183 -0
- package/skills/teamsmith/tests/panel-b3-pty-mouse.py +240 -0
- package/skills/teamsmith/tests/panel-b3-pty-tmux-mouse.py +138 -0
- package/skills/teamsmith/tests/panel-b3-stub.sh +279 -0
- package/skills/teamsmith/tests/panel-b3.sh +1301 -0
- package/skills/teamsmith/tests/panel-choices.sh +572 -0
- package/skills/teamsmith/tests/panel-clipboard-model.ts +187 -0
- package/skills/teamsmith/tests/panel-compose-model.ts +290 -0
- package/skills/teamsmith/tests/panel-contrast.mjs +81 -0
- package/skills/teamsmith/tests/panel-cpu-premise.sh +173 -0
- package/skills/teamsmith/tests/panel-cpu.sh +391 -0
- package/skills/teamsmith/tests/panel-flip-m54.sh +207 -0
- package/skills/teamsmith/tests/panel-flip-p123.sh +278 -0
- package/skills/teamsmith/tests/panel-flip-p125.sh +318 -0
- package/skills/teamsmith/tests/panel-flip-p128.sh +259 -0
- package/skills/teamsmith/tests/panel-keyprobe-pty.py +99 -0
- package/skills/teamsmith/tests/panel-keyprobe-stub.sh +41 -0
- package/skills/teamsmith/tests/panel-keyprobe.sh +82 -0
- package/skills/teamsmith/tests/panel-keyprobe.tsx +116 -0
- package/skills/teamsmith/tests/panel-knobs.sh +83 -0
- package/skills/teamsmith/tests/panel-p21.sh +2181 -0
- package/skills/teamsmith/tests/panel-snapshots.sh +802 -0
- package/skills/teamsmith/tests/panel-strings.mjs +195 -0
- package/skills/teamsmith/tests/perf.sh +740 -0
- package/skills/teamsmith/tests/pm-box-real.sh +350 -0
- package/skills/teamsmith/tests/pulse-nudge-key.sh +563 -0
- package/skills/teamsmith/tests/routes.sh +1652 -0
- package/skills/teamsmith/tests/section-budgets.tsv +150 -0
- package/skills/teamsmith/tests/section-guard.sh +231 -0
- package/skills/teamsmith/tests/section-needs-audit.sh +94 -0
- package/skills/teamsmith/tests/section-paths.tsv +142 -0
- package/skills/teamsmith/tests/section-select.sh +655 -0
- package/skills/teamsmith/tests/signal-gate.sh +366 -0
- package/skills/teamsmith/tests/signal-lint-legacy.txt +14 -0
- package/skills/teamsmith/tests/signal-lint.pl +416 -0
- package/skills/teamsmith/tests/skill-load.mjs +65 -0
- package/skills/teamsmith/tests/smoke.sh +19711 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-120-detail.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-120-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-120.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-160-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-160.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-59-detail.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-59-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-59.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-99-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-99.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-120-detail.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-120-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-120.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-160-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-160.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-59-detail.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-59-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-59.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-99-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-99.txt +32 -0
- package/skills/teamsmith/tests/spec-ledger-refs.tsv +78 -0
- package/skills/teamsmith/tests/spec-refs.sh +826 -0
- package/skills/teamsmith/tests/task-header-model.sh +267 -0
- package/skills/teamsmith/tests/team-bg-flip.sh +239 -0
- package/skills/teamsmith/tests/team-bg-harness.mjs +392 -0
- package/skills/teamsmith/tests/team-bg-stop.sh +434 -0
- package/skills/teamsmith/tests/team-inbox-watch-flip.sh +191 -0
- package/skills/teamsmith/tests/team-inbox-watch-harness.mjs +1559 -0
- package/skills/teamsmith/tests/tmp-hygiene.sh +1190 -0
- package/skills/teamsmith/tests/tmux-lint-legacy.txt +31 -0
- package/skills/teamsmith/tests/tmux-lint.pl +604 -0
- package/skills/teamsmith-init/SKILL.md +100 -0
- package/skills/teamsmith-init/references/bootstrap.md +74 -0
- package/skills/teamsmith-init/templates/bootstrap-prompt.md.tmpl +46 -0
|
@@ -0,0 +1,1709 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# teamsmith · agent 生命周期:add-agent / dispatch / say / notify / teardown
|
|
3
|
+
|
|
4
|
+
team_worktree_add() { # <agent> [--create] [--no-install]
|
|
5
|
+
local agent="$1"; shift || true
|
|
6
|
+
local noinstall=0 do_create="${TEAM_CREATE_WORKTREE:-0}"
|
|
7
|
+
while [ $# -gt 0 ]; do
|
|
8
|
+
case "$1" in
|
|
9
|
+
--create) do_create=1; shift ;;
|
|
10
|
+
--print-only|--print) do_create=0; shift ;;
|
|
11
|
+
--no-install) noinstall=1; shift ;;
|
|
12
|
+
*) team_usage_die "add-agent: 未知参数 $1" ;;
|
|
13
|
+
esac
|
|
14
|
+
done
|
|
15
|
+
team_require_agent "$agent"
|
|
16
|
+
local wt branch; wt="$(team_agent_worktree "$agent")"; branch="$(team_agent_branch "$agent")"
|
|
17
|
+
|
|
18
|
+
# 幂等的 git worktree add —— 由 PM 执行(skill 不碰 git);--create 才代建
|
|
19
|
+
if [ "$do_create" != "1" ]; then
|
|
20
|
+
team_dim " 需要 PM 执行(本命令不代做 git):"
|
|
21
|
+
if [ -d "$wt" ]; then
|
|
22
|
+
printf ' (已存在,无需创建)%s\n' "$wt"
|
|
23
|
+
else
|
|
24
|
+
printf ' git -C %s worktree add -b %s %s %s\n' "$TEAM_MAIN_ROOT" "$branch" "$wt" "$TEAM_PROTECTED_BRANCH"
|
|
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
|
+
return 0
|
|
31
|
+
fi
|
|
32
|
+
mkdir -p "$(dirname "$wt")"
|
|
33
|
+
if [ -d "$wt" ]; then
|
|
34
|
+
team_ok "worktree 已存在:$wt"
|
|
35
|
+
elif team_branch_mode_is_task; then
|
|
36
|
+
# task 模式:worktree 先 detached 在保护分支上(`git switch -c task/<ID>-…` 由 dispatch 做);
|
|
37
|
+
# 不能直接 checkout 保护分支 —— 主工作树已经占着它。
|
|
38
|
+
team_git_main worktree add --detach "$wt" "$TEAM_PROTECTED_BRANCH" >/dev/null
|
|
39
|
+
team_ok "worktree $wt ← detached@$TEAM_PROTECTED_BRANCH(任务分支由 dispatch 建)"
|
|
40
|
+
else
|
|
41
|
+
if team_git_main show-ref --verify -q "refs/heads/$branch"; then
|
|
42
|
+
team_git_main worktree add "$wt" "$branch" >/dev/null
|
|
43
|
+
else
|
|
44
|
+
team_git_main worktree add -b "$branch" "$wt" "$TEAM_PROTECTED_BRANCH" >/dev/null
|
|
45
|
+
fi
|
|
46
|
+
team_ok "worktree $wt ← 分支 $branch"
|
|
47
|
+
fi
|
|
48
|
+
team_scan_invalidate git # M50:工作树集变了,同进程后续读必须重列
|
|
49
|
+
|
|
50
|
+
if [ "$noinstall" != "1" ] && [ -n "$TEAM_INSTALL_CMD" ]; then
|
|
51
|
+
team_info "install: $TEAM_INSTALL_CMD(在 $wt)"
|
|
52
|
+
( cd "$wt" && eval "$TEAM_INSTALL_CMD" ) || team_warn "install 失败,先手动装依赖再派单"
|
|
53
|
+
fi
|
|
54
|
+
|
|
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
|
+
return 0
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
team_pi_args() { # <model> → 打印已转义的 pi 参数
|
|
63
|
+
local model="$1" provider piargs=()
|
|
64
|
+
provider="${model%%/*}"
|
|
65
|
+
piargs=(--provider "$provider" --model "${model#*/}")
|
|
66
|
+
piargs+=(-e "$TEAM_SKILL_DIR/extension/team-notify.ts")
|
|
67
|
+
# M27:团队后台车道与 notify 并列注入(worker 的长门禁/长构建用它,收割纪律写在提示词里)
|
|
68
|
+
piargs+=(-e "$TEAM_SKILL_DIR/extension/team-bg.ts")
|
|
69
|
+
# M30:投递换道 —— 收件箱监视唤醒(worker 也收 `team say`;装了它就不再有任何输入框粘贴)
|
|
70
|
+
piargs+=(-e "$TEAM_SKILL_DIR/extension/team-inbox-watch.ts")
|
|
71
|
+
[ -d "$TEAM_SKILL_DIR" ] && piargs+=(--skill "$TEAM_SKILL_DIR")
|
|
72
|
+
if [ -n "$TEAM_EXTRA_PI_ARGS" ]; then
|
|
73
|
+
# 允许项目追加参数(空格分隔,不支持带空格的值)
|
|
74
|
+
# shellcheck disable=SC2206
|
|
75
|
+
piargs+=($TEAM_EXTRA_PI_ARGS)
|
|
76
|
+
fi
|
|
77
|
+
printf '%q ' "${piargs[@]}"
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
# 派单提示词:把 CEP 的「不半途停、小步提交、必写报告、被阻塞就 notify」固化成模板。
|
|
81
|
+
# P140:第 7/8 参可给本次**解析出的任务分支**与它的来源(dispatch 传入;其它调用方留空则不提)。
|
|
82
|
+
team_build_prompt() { # <agent> <ID> <taskfile-abs> <worktree> <model> [<session_id>] [<branch>] [<branch-source>]
|
|
83
|
+
local agent="$1" id="$2" taskfile="$3" wt="$4" model="$5" sid="${6:-$TEAM_SESSION-$1}" br="${7:-}" br_src="${8:-}"
|
|
84
|
+
local issue="" cli="$TEAM_SKILL_DIR/scripts/team" rel abs_docs rel_report rel_note notify_block="" bg_block=""
|
|
85
|
+
case "$taskfile" in
|
|
86
|
+
"$TEAM_MAIN_ROOT"/*) rel="${taskfile#"$TEAM_MAIN_ROOT"/}" ;;
|
|
87
|
+
*) rel="" ;;
|
|
88
|
+
esac
|
|
89
|
+
# 只有真的在项目里才敢叫它 repo-relative(M6.3 F15:绝对路径被标成 repo-relative,
|
|
90
|
+
# 而同一份提示词又命令 worker 只在本项目里干活)。
|
|
91
|
+
if [ -n "$rel" ]; then rel_note=" (same file, repo-relative path: \`$rel\`)"
|
|
92
|
+
else rel_note=" (absolute path; it is outside the project main worktree)"; fi
|
|
93
|
+
abs_docs="$TEAM_DOCS_ABS"
|
|
94
|
+
rel_report="$TEAM_DOCS_DIR/reports/$id-$agent.md"
|
|
95
|
+
grep -qE '^[[:space:]]*issue:' "$taskfile" 2>/dev/null && \
|
|
96
|
+
issue="$(grep -E '^[[:space:]]*issue:' "$taskfile" | head -1 | grep -oE '[0-9]+' | head -1 || true)"
|
|
97
|
+
|
|
98
|
+
# 交付步骤与 forge 无关:skill 不假设任何 forge CLI(gh/glab/tea/curl 都行,由 PM 决定)
|
|
99
|
+
local pr_step
|
|
100
|
+
case "$TEAM_VCS" in
|
|
101
|
+
local|"") pr_step="本仓库是 local 模式(没有远端):**不用 push**,把分支留在本地即可,PM 复验后本地合并" ;;
|
|
102
|
+
*) pr_step="交付方式由 PM 决定:把分支 push 到你们的远端(如有),开 PR/MR 与否听 PM 安排
|
|
103
|
+
(skill 不代做、也不假设 gh/glab;需要你手动调 API 时按 PM 给的方式做,token 不要读进上下文)" ;;
|
|
104
|
+
esac
|
|
105
|
+
|
|
106
|
+
# 通知段(F1/F7/F8):worker 的摘要是**数据**,永远走文件通道 —— 提示词里不含任何 worker 文本,
|
|
107
|
+
# 而 worker 要跑的命令是 teamsmith 渲染好的固定行(无需替换/引号/加参数)。
|
|
108
|
+
# 「不是 Pi、没有自动通知」只属于自定义 adapter(F7:内置 Pi 路径下这句话就是诳 worker)。
|
|
109
|
+
# 模板不可用(坏占位符/多行/纯空白/首词不可执行)时整段换成「写进报告」,不给半截命令(F8)。
|
|
110
|
+
# 只有「启动命令也是自定义 adapter」时才需要 worker 手动通知:内置 Pi 有自己的扩展,
|
|
111
|
+
# 把额外命令塞给它只会诱导重复通知(F7 / V3.0 d6);那种配置由 dispatch/doctor 警告「没生效」。
|
|
112
|
+
if [ -n "${TEAM_AGENT_NOTIFY_CMD:-}" ] && [ -n "$(team_trim "${TEAM_AGENT_CMD:-}")" ]; then
|
|
113
|
+
local notify_issues="" sfile why ncmd
|
|
114
|
+
notify_issues="$(team_agent_notify_issues)"
|
|
115
|
+
if [ -n "$notify_issues" ]; then
|
|
116
|
+
notify_block="$(printf '\n**Notify the PM when your turn ends**: the notify configuration of this project is unusable (%s), so there is\nnothing for you to run. Put your one-line summary (what you delivered / status / next step) into the report\n`%s` instead -- the PM reads reports.\n' \
|
|
117
|
+
"$(printf '%s' "$notify_issues" | tr '\n' '; ')" "$rel_report")"
|
|
118
|
+
else
|
|
119
|
+
sfile="$(team_agent_summary_file "$agent" "$id")"
|
|
120
|
+
if [ -n "${TEAM_AGENT_CMD:-}" ]; then
|
|
121
|
+
why="This project runs a custom agent CLI, not Pi, so there is no automatic notification."
|
|
122
|
+
else
|
|
123
|
+
why="Your CLI is the built-in Pi, whose notify extension already tells the PM when your turn ends; run the command below only if the PM asked you to."
|
|
124
|
+
fi
|
|
125
|
+
ncmd="$(team_agent_notify_cmd "$agent" "$sid" "$wt" "$sfile")"
|
|
126
|
+
notify_block="$(printf '\n**Notify the PM when your turn ends.** %s Write your one-line summary (what you delivered /\nstatus / next step) into this file with whatever file-writing you normally do (create or overwrite it):\n\n %s\n\nthen run exactly this command, with no substitutions, no extra arguments and no quotes:\n\n %s\n' \
|
|
127
|
+
"$why" "$sfile" "$ncmd")"
|
|
128
|
+
fi
|
|
129
|
+
fi
|
|
130
|
+
|
|
131
|
+
# M27 · 后台车道纪律:只在「这个 harness 真的会拿到 team-bg 扩展」时说 ——
|
|
132
|
+
# 内置 Pi(TEAM_AGENT_CMD 空)由 teamsmith 挂 -e;自定义模板写了 {bg_ext} 的算作者已经挂上。
|
|
133
|
+
# 其它 adapter 不提:工具不存在,教了只会让 worker 白找。
|
|
134
|
+
case "${TEAM_AGENT_CMD:-}" in
|
|
135
|
+
''|*'{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 `team_bg_wait <id>` (the result comes back inline). **Harvest every job\nbefore your turn ends** -- an unharvested job wakes you once when it finishes, and that costs a turn.\n')" ;;
|
|
137
|
+
esac
|
|
138
|
+
|
|
139
|
+
cat <<PROMPT
|
|
140
|
+
You are agent:$agent for the **$TEAM_PROJECT** project, dispatched by the PM through teamsmith. Your worktree is
|
|
141
|
+
\`$wt\`; run every command there.${br:+
|
|
142
|
+
Your task branch is \`$br\` (source: $br_src) -- stay on it, do not switch branches.} **Do not** touch the main worktree ($TEAM_MAIN_ROOT) and **do not** switch to main or
|
|
143
|
+
anyone else's branch.
|
|
144
|
+
|
|
145
|
+
Read these first, in order:
|
|
146
|
+
1. \`AGENTS.md\` (contains the teamsmith team protocol section)
|
|
147
|
+
2. Your thread \`$abs_docs/threads/$agent.md\` (the PM may have added instructions before you started)
|
|
148
|
+
3. The task brief \`$taskfile\`$rel_note -- the single source of scope and acceptance commands
|
|
149
|
+
|
|
150
|
+
Scope discipline: do only what the brief says, and only change directories that OWNERSHIP assigns to you.
|
|
151
|
+
For cross-directory work, do not do it yourself: write \`BLOCKED:\` in your report naming who should change what,
|
|
152
|
+
then end the turn.
|
|
153
|
+
|
|
154
|
+
Red lines: never push $TEAM_PROTECTED_BRANCH, never force-push, never merge PR/MRs, never rebase or delete other
|
|
155
|
+
branches, never change repository settings. Never write tokens/secrets into code, logs or commit messages; never
|
|
156
|
+
read credential files (such as ~/.pi/agent/auth.json).
|
|
157
|
+
|
|
158
|
+
**Cross-project boundary (never act outside this project)**: work only inside $TEAM_MAIN_ROOT, your own worktree,
|
|
159
|
+
and this team's tmux session ($TEAM_SESSION). Do not message windows in other projects or sessions, do not read or
|
|
160
|
+
write other projects' repositories or session files, and do not change or merge other projects' code. If you need
|
|
161
|
+
another project's help (cross-repo dependency, shared library change), write \`BLOCKED:\` in your report naming who
|
|
162
|
+
needs to do what -- **cross-project communication is the PM's job via \`$cli meeting\` (peer exchange: interfaces,
|
|
163
|
+
advice, problem reports); workers do not attend**. Only decisions that need the user's call go through the user.
|
|
164
|
+
|
|
165
|
+
**Never stop mid-task to ask for confirmation**: end the turn in exactly two situations --
|
|
166
|
+
(a) every acceptance command in the brief has been run + the report is written + the branch is pushed + the PR/MR is
|
|
167
|
+
open (or, in local mode, the branch state is settled);
|
|
168
|
+
(b) you are hard-blocked (missing dependency, missing permission, someone else's bug): notify the PM with
|
|
169
|
+
\`$cli notify $agent "<one line>"\`, state \`BLOCKED:\` clearly in the report, then end the turn.
|
|
170
|
+
**Never work around a boundary on your own.**
|
|
171
|
+
|
|
172
|
+
Delivery process:
|
|
173
|
+
1. Actually run the acceptance commands from the brief. **Never claim something passed without running it** (the PM
|
|
174
|
+
re-verifies independently; a false report fails the task).
|
|
175
|
+
2. Commit every verifiable small step (\`git commit\`, Conventional Commits + task ID + trailer \`Agent: $agent\`${issue:+ + \`Refs #$issue\`}); never one big dump at the end.
|
|
176
|
+
3. Write the report \`$rel_report\` and commit it on your branch (format: the AGENTS.md report template; include the
|
|
177
|
+
real commands and their output tails).
|
|
178
|
+
For **defect-fix** tasks the report must contain **flip evidence**: red before -> green after, or
|
|
179
|
+
"break the implementation -> the guard test must fail -> restore it"
|
|
180
|
+
(the PM checks this section with \`$cli review $id --strong\` and will send it back if missing).
|
|
181
|
+
4. \`git push -u $TEAM_REMOTE HEAD\`.
|
|
182
|
+
5. $pr_step.
|
|
183
|
+
|
|
184
|
+
Task: **$id**${issue:+ (issue #$issue)}. The brief \`$taskfile\` is the PM's read-only file -- do not modify it.${bg_block}${notify_block}
|
|
185
|
+
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.
|
|
187
|
+
PROMPT
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
team_cmd_add_agent() {
|
|
191
|
+
local agent="" extra=()
|
|
192
|
+
local register=0 has_model=0 model="" fp=""
|
|
193
|
+
while [ $# -gt 0 ]; do
|
|
194
|
+
case "$1" in
|
|
195
|
+
--register) register=1; shift ;;
|
|
196
|
+
--model) model="${2:?--model 需要 <provider/model> 或 -}"; has_model=1; shift 2 ;;
|
|
197
|
+
--model=*) model="${1#*=}"; has_model=1; shift ;;
|
|
198
|
+
--fingerprint) fp="${2:?--fingerprint 需要 sha256}"; shift 2 ;;
|
|
199
|
+
--fingerprint=*) fp="${1#*=}"; shift ;;
|
|
200
|
+
--no-install) extra+=(--no-install); shift ;;
|
|
201
|
+
--create) extra+=(--create); shift ;; # 明确要求代建 worktree(默认只打印 git 命令)
|
|
202
|
+
--print-only|--print) extra+=(--print-only); shift ;;
|
|
203
|
+
-*) team_usage_die "add-agent: 未知参数 $1" ;;
|
|
204
|
+
*) [ -z "$agent" ] || team_usage_die "add-agent: 多余参数 $1"
|
|
205
|
+
agent="$1"; shift ;;
|
|
206
|
+
esac
|
|
207
|
+
done
|
|
208
|
+
[ -n "$agent" ] || team_usage_die "add-agent <agent> [--register] [--model <provider/model>|-] [--fingerprint <sha256>] [--create] [--no-install] [--print]"
|
|
209
|
+
|
|
210
|
+
# ① 模型形状先判:可预测的错误写不进任何东西(P99/D2 的写序)
|
|
211
|
+
if [ "$has_model" = "1" ] && [ "$model" != "-" ] && ! team_config_model_shape_ok "$model"; then
|
|
212
|
+
team_err "add-agent --model:模型必须是 provider/model 形状($(team_config_model_violation "$model")):$model"
|
|
213
|
+
return "$TEAM_CONFIG_EXIT_INVALID"
|
|
214
|
+
fi
|
|
215
|
+
|
|
216
|
+
# ①′ 席位名是一个 token(P105/F1):名册值规则判的是**结果值**,而 `api 1` 加进去会变成两个各自
|
|
217
|
+
# 合法的 token(value rule 不会响)—— 必须在任何写入之前先拒。写入器里有同一份守卫(team_config_
|
|
218
|
+
# seat_violation);这里提前一层是为了给出两条真能用的路线而不是一个干巴巴的 4。
|
|
219
|
+
local seat_why
|
|
220
|
+
if ! seat_why="$(team_config_seat_violation "$agent")"; then
|
|
221
|
+
team_err "add-agent:$seat_why"
|
|
222
|
+
team_dim " 席位名要能当工作树目录名/窗口名/state 文件名,接受形状 [A-Za-z0-9][A-Za-z0-9._-]*(一个 token)。两条真能用的路线:" >&2
|
|
223
|
+
team_dim " · 换成形状合法的名字再跑:$TEAM_CLI add-agent <名字> --register" >&2
|
|
224
|
+
team_dim " · 或手改 $TEAM_MAIN_ROOT/.pi/team/config.sh 里的 TEAM_AGENTS(名字同样要匹配这个形状)" >&2
|
|
225
|
+
return "$TEAM_CONFIG_EXIT_INVALID"
|
|
226
|
+
fi
|
|
227
|
+
|
|
228
|
+
# ② 名册:--register 走契约的审计写入器(唯一授权入口);没有旗标的未知席位 → exit 5 +
|
|
229
|
+
# 两条真能用的路线,且不碰窗口/worktree/state/契约(P99/R2)。
|
|
230
|
+
if [ "$register" = "1" ]; then
|
|
231
|
+
local rrc=0
|
|
232
|
+
team_config_write_roster add "$agent" "$fp" 0 || rrc=$?
|
|
233
|
+
[ "$rrc" -eq 0 ] || return "$rrc"
|
|
234
|
+
elif ! team_agent_known "$agent"; then
|
|
235
|
+
team_err "未知 agent:$agent(名册:$(team_config_roster_text))"
|
|
236
|
+
team_dim " 名册只由显式入口改,两条真能用的路线:" >&2
|
|
237
|
+
team_dim " · $TEAM_CLI add-agent $agent --register(走契约的审计写入器)" >&2
|
|
238
|
+
team_dim " · 或手改 $TEAM_MAIN_ROOT/.pi/team/config.sh 里的 TEAM_AGENTS" >&2
|
|
239
|
+
team_dim " 本次什么都没做:没有开窗、没有工作树、没有 state、契约未动" >&2
|
|
240
|
+
return "$TEAM_CONFIG_EXIT_REFUSE"
|
|
241
|
+
fi
|
|
242
|
+
|
|
243
|
+
# ③ 席位模型(--model):同一个写入器 + 同一个 pairlist 序列化器(D4)
|
|
244
|
+
if [ "$has_model" = "1" ]; then
|
|
245
|
+
local mrc=0
|
|
246
|
+
team_cmd_config_set_agent_model "$agent" "$model" || mrc=$?
|
|
247
|
+
[ "$mrc" -eq 0 ] || return "$mrc"
|
|
248
|
+
fi
|
|
249
|
+
|
|
250
|
+
# ④ 既有工作树步骤
|
|
251
|
+
if [ "${#extra[@]}" -gt 0 ]; then team_worktree_add "$agent" "${extra[@]}"; else team_worktree_add "$agent"; fi
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
# 这个分支属不属于这个任务:
|
|
255
|
+
# task 模式 → task/<ID>-<任意 slug>(slug 由标题生成、可能改过,所以不要求逐字符相等)
|
|
256
|
+
# agent 模式 → agent/<name>(长期分支,就是 team_branch_for_agent 算出来的那个)
|
|
257
|
+
# 注意:只接受**同一个 ID**;task/P2-smoke 永远不会被当成 P1 的分支。
|
|
258
|
+
team_branch_is_for_task() { # <branch> <agent> <ID>
|
|
259
|
+
local br="$1" agent="$2" id="$3" want
|
|
260
|
+
[ -n "$br" ] || return 1
|
|
261
|
+
want="$(team_branch_for_agent "$agent" "$id")"
|
|
262
|
+
[ "$br" = "$want" ] && return 0
|
|
263
|
+
if team_branch_mode_is_task; then
|
|
264
|
+
case "$br" in "task/$id-"*) return 0 ;; esac
|
|
265
|
+
fi
|
|
266
|
+
return 1
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
# P140(dispatch-friction · R1):本次派单期望分支的**一条声明**与它的来源。
|
|
270
|
+
# 解析顺序(design D2):--branch <name>(PM 显式声明,最高优先)> 任务书 `branch:` 行 > 由标题推导。
|
|
271
|
+
# 推导本身只有一份(team_task_branch_for_id / team_agent_branch),不与 `team task` 各算各的。
|
|
272
|
+
# → 0 = stdout `<name>\x1f<来源>`;1 = stdout 一行拒绝原因(名字不属于本任务)。
|
|
273
|
+
# 来源文本:`--branch` / `任务书 branch: 行` / `由标题 "<title>" 推导` / `agent 模式:agent/<agent>`。
|
|
274
|
+
team_dispatch_branch_decl() { # <agent> <ID> <任务书> <--branch 值>
|
|
275
|
+
local agent="$1" id="$2" brief="$3" flag="${4:-}" name="" src="" raw="" title=""
|
|
276
|
+
if [ -n "$flag" ]; then
|
|
277
|
+
name="$flag"; src="--branch"
|
|
278
|
+
else
|
|
279
|
+
raw="$(team_brief_field_raw "$brief" branch | head -1)"
|
|
280
|
+
if [ -n "$raw" ]; then
|
|
281
|
+
name="$raw"; src="任务书 branch: 行"
|
|
282
|
+
elif team_branch_mode_is_task; then
|
|
283
|
+
title="$(team_task_title "$id" 2>/dev/null || true)"
|
|
284
|
+
name="$(team_task_branch_for_id "$id")"
|
|
285
|
+
src="由标题 \"$title\" 推导"
|
|
286
|
+
else
|
|
287
|
+
name="$(team_agent_branch "$agent")"; src="agent 模式:agent/<agent>"
|
|
288
|
+
fi
|
|
289
|
+
fi
|
|
290
|
+
if ! team_branch_is_for_task "$name" "$agent" "$id"; then
|
|
291
|
+
printf '%s 不属于本任务(%s)\n' "$name" "$id"
|
|
292
|
+
return 1
|
|
293
|
+
fi
|
|
294
|
+
printf '%s\x1f%s\n' "$name" "$src"
|
|
295
|
+
return 0
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
# ---------------------------------------------------------------- P140 · 工作树判定(finding 产出器)
|
|
299
|
+
# 两个判定分开(dispatch-friction · R4/R5):脏工作树、分支身份各自是一个阻塞项;
|
|
300
|
+
# 工作树不存在时 driver 不调这两个(前提缺失 → 说明项,不冒充“查过了”)。
|
|
301
|
+
# 脏工作树:同一任务的断点续跑允许脏;换任务先收尾(原文案与字段不变,只多了 修法: 行)。
|
|
302
|
+
team_dispatch_judge_worktree_dirty() { # <agent> <ID> <wt>
|
|
303
|
+
local agent="$1" id="$2" wt="$3" dirty prev_task dl
|
|
304
|
+
dirty="$(git -C "$wt" status --porcelain 2>/dev/null | wc -l | tr -d ' ')"
|
|
305
|
+
[ "${dirty:-0}" -gt 0 ] 2>/dev/null || return 0
|
|
306
|
+
prev_task="$(team_state_get "$agent" task '')"
|
|
307
|
+
if [ "$prev_task" = "$id" ]; then
|
|
308
|
+
# 同一个任务的「断点续跑」允许脏工作区:那些改动正是它没提交完的活。
|
|
309
|
+
team_df_dim " 断点续跑:$wt 有 $dirty 个未提交改动,属于本任务($id),允许继续"
|
|
310
|
+
return 0
|
|
311
|
+
fi
|
|
312
|
+
team_df_err "$wt 有 $dirty 个未提交改动(属于上一个任务 ${prev_task:-?}):先收尾(提交或丢弃),再派新任务"
|
|
313
|
+
dl="$(git -C "$wt" status --short 2>/dev/null | head -8 || true)"
|
|
314
|
+
[ -n "$dl" ] && team_df_lines_raw_err "$dl"
|
|
315
|
+
team_df_dim " 想直接续跑同一个任务:$TEAM_CLI resume --agent $agent(或 dispatch 同一个 ID)"
|
|
316
|
+
team_df_dim " (git 归 PM:skill 不替你 stash/commit)"
|
|
317
|
+
team_df_dim "$(printf ' 修法:git -C %q stash push -u -m %q' "$wt" "收尾:上一个任务 ${prev_task:-?} 的未提交改动")"
|
|
318
|
+
return 1
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
# 分支身份(M6.3 F16 + P140):
|
|
322
|
+
# · 保护分支 / detached HEAD:先切到任务分支;
|
|
323
|
+
# · `--branch` 的显式声明:工作树必须正好停在它上面(同任务的另一个 slug 也不静默替换);
|
|
324
|
+
# · 任务书 branch: 行 / 标题推导:工作树停在**本任务**的任意分支都放行(slug 是显示细节),
|
|
325
|
+
# 两个名字都打印;别的任务的分支照旧拒绝。
|
|
326
|
+
# 成功时把实际检查到的分支写进 TEAM_CHECKED_BRANCH(state/审核的目标)。
|
|
327
|
+
team_dispatch_judge_worktree_branch() { # <agent> <ID> <wt> <声明分支> <来源>
|
|
328
|
+
local agent="$1" id="$2" wt="$3" want="$4" decl_src="$5" cur
|
|
329
|
+
cur="$(git -C "$wt" rev-parse --abbrev-ref HEAD 2>/dev/null || echo '?')"
|
|
330
|
+
case "$cur" in
|
|
331
|
+
"$TEAM_PROTECTED_BRANCH")
|
|
332
|
+
team_df_warn "$agent 的工作树还在 $TEAM_PROTECTED_BRANCH 上:PM 该先建分支再派单"
|
|
333
|
+
team_df_dim "$(printf ' 修法:git -C %q switch -c %q %q' "$wt" "$want" "$TEAM_PROTECTED_BRANCH")"
|
|
334
|
+
return 1 ;;
|
|
335
|
+
HEAD)
|
|
336
|
+
if [ -n "$want" ]; then
|
|
337
|
+
team_df_warn "$agent 的工作树是 detached HEAD:先切到任务分支"
|
|
338
|
+
team_df_dim "$(printf ' 修法:git -C %q switch -c %q %q' "$wt" "$want" "$TEAM_PROTECTED_BRANCH")"
|
|
339
|
+
return 1
|
|
340
|
+
fi ;;
|
|
341
|
+
esac
|
|
342
|
+
if [ -n "$want" ] && [ "$cur" != "$want" ]; then
|
|
343
|
+
if [ "$decl_src" = "--branch" ]; then
|
|
344
|
+
# P140:显式声明赢 —— 同任务的另一个 slug 也不静默替换。
|
|
345
|
+
team_df_err "$wt 不在 --branch 声明的分支上:"
|
|
346
|
+
team_df_err " 现在的分支:$cur | --branch 声明:$want"
|
|
347
|
+
if git -C "$wt" show-ref --verify --quiet "refs/heads/$want"; then
|
|
348
|
+
team_df_dim "$(printf ' 修法:git -C %q switch %q' "$wt" "$want")"
|
|
349
|
+
else
|
|
350
|
+
team_df_dim "$(printf ' 修法:git -C %q switch -c %q %q' "$wt" "$want" "$TEAM_PROTECTED_BRANCH")"
|
|
351
|
+
team_df_dim " (替代方案:让 --branch 指向一条已存在的本任务分支;显式声明赢)"
|
|
352
|
+
fi
|
|
353
|
+
return 1
|
|
354
|
+
fi
|
|
355
|
+
if team_branch_is_for_task "$cur" "$agent" "$id"; then
|
|
356
|
+
# P140:同一个任务的续跑 —— slug 可能因为标题改过而不一致(实测摩擦:task/P134-p134 vs 推导名);
|
|
357
|
+
# 分支确实属于本任务(同一 ID)就放行,两个名字都打印出来。
|
|
358
|
+
team_df_dim " 续跑:$wt 的分支 $cur 属于本任务($id;解析名 $want),继续"
|
|
359
|
+
if [ -n "$want" ] && git -C "$wt" show-ref --verify --quiet "refs/heads/$want"; then
|
|
360
|
+
team_df_dim "$(printf ' (想让工作树也叫解析名:git -C %q switch %q)' "$wt" "$want")"
|
|
361
|
+
fi
|
|
362
|
+
else
|
|
363
|
+
team_df_err "$wt 停在不属于本任务($id)的分支上:"
|
|
364
|
+
team_df_err " 现在的分支:$cur | 本任务要的分支:$want"
|
|
365
|
+
if git -C "$wt" show-ref --verify --quiet "refs/heads/$want"; then
|
|
366
|
+
team_df_dim "$(printf ' 修法:git -C %q switch %q' "$wt" "$want")"
|
|
367
|
+
else
|
|
368
|
+
team_df_dim "$(printf ' 修法:git -C %q switch -c %q %q' "$wt" "$want" "$TEAM_PROTECTED_BRANCH")"
|
|
369
|
+
fi
|
|
370
|
+
team_df_dim " (拒绝的理由:复验/交付记录会以工作树的分支为证据,不能张冠李戴)"
|
|
371
|
+
return 1
|
|
372
|
+
fi
|
|
373
|
+
fi
|
|
374
|
+
TEAM_CHECKED_BRANCH="$cur"
|
|
375
|
+
return 0
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
# 工作树存在(不存在 = 阻塞项,修法是 PM 该跑的那条 git 命令)。
|
|
379
|
+
team_dispatch_judge_worktree_present() { # <agent> <声明分支>
|
|
380
|
+
local agent="$1" decl="$2" wt
|
|
381
|
+
wt="$(team_agent_worktree "$agent")"
|
|
382
|
+
[ -d "$wt" ] && return 0
|
|
383
|
+
team_df_err "worktree 不存在:$wt(skill 不代做 git)"
|
|
384
|
+
team_df_dim "$(printf ' 修法:git -C %q worktree add -b %q %q %q' "$TEAM_MAIN_ROOT" "$decl" "$wt" "$TEAM_PROTECTED_BRANCH")"
|
|
385
|
+
return 1
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
# ---------------------------------------------------------------- 派单前的会话规模守卫(M4.3 A)
|
|
389
|
+
# 复用大会话 + 小窗口模型 = 必然 wedge(现场见 DECISIONS D9 事件 A:361k tok 的会话配 272k 窗口的模型
|
|
390
|
+
# → 立刻 Context full / 连接错误循环,而 roster 仍显示「pi 在跑」)。
|
|
391
|
+
# 默认**拒绝**并给出 --fresh;确实要复用(例如换成窗口更大的模型)时用 --allow-overflow 显式放行。
|
|
392
|
+
# 口径写入消息:token ≈ 会话 JSONL 字节 / 4(粗糙);窗口解析不到时明说用的是保守阈值。
|
|
393
|
+
team_guard_resume_session() { # <agent> <model> <sid> <worktree> <fresh> <allow-overflow> [<ID> <task-file>]
|
|
394
|
+
local agent="$1" model="$2" sid="$3" wt="$4" fresh="${5:-0}" allow="${6:-0}" id="${7:-}" taskfile="${8:-}"
|
|
395
|
+
[ "$fresh" = "1" ] && return 0 # --fresh = 新会话,历史留在旧文件里
|
|
396
|
+
local f b t w limit note mb
|
|
397
|
+
f="$(team_session_file "$sid" "$wt" 2>/dev/null || true)"
|
|
398
|
+
[ -n "$f" ] || return 0 # 没有历史会话:没什么可复用的
|
|
399
|
+
b="$(team_file_bytes "$f")"
|
|
400
|
+
t="$(team_session_tokens_est "$b")"
|
|
401
|
+
[ "$t" -gt 0 ] || return 0
|
|
402
|
+
mb="$(awk -v b="$b" 'BEGIN{printf "%.1f", b/1048576}')"
|
|
403
|
+
w="$(team_model_window "$model")"
|
|
404
|
+
if [ -n "$w" ]; then
|
|
405
|
+
limit="$w"; note="模型 $model 的窗口 $w tok"
|
|
406
|
+
else
|
|
407
|
+
limit="${TEAM_SESSION_WARN_TOKENS:-200000}"
|
|
408
|
+
case "$limit" in ''|*[!0-9]*) limit=200000 ;; esac # 配置写成垃圾值时退回默认,而不是静默不守
|
|
409
|
+
note="解析不到 $model 的窗口(Pi 的模型目录里没有它)→ 保守阈值 $limit tok"
|
|
410
|
+
fi
|
|
411
|
+
[ "$t" -gt "$limit" ] || return 0
|
|
412
|
+
local size="~$(team_tokens_human "$t") tok(估算:JSONL ${mb}MB ÷ 4,粗糙)"
|
|
413
|
+
if [ "$allow" = "1" ]; then
|
|
414
|
+
team_warn "你显式放行了偏大的会话:$size > $note"
|
|
415
|
+
team_dim " 若它 wedge(Context full / 连接错误循环):杀掉窗口后用 --fresh 重派(roster 仍会显示「pi 在跑」)"
|
|
416
|
+
return 0
|
|
417
|
+
fi
|
|
418
|
+
team_err "拒绝复用这个会话:$size > $note"
|
|
419
|
+
team_dim " 会话文件:$f" >&2
|
|
420
|
+
team_dim " 复用它极可能直接 Context full / 连接错误循环,而 roster 还会显示「pi 在跑」" >&2
|
|
421
|
+
team_dim " 两条出路(P140:带具体 ID/任务书的可粘命令)" >&2
|
|
422
|
+
if [ -n "$id" ] && [ -n "$taskfile" ]; then
|
|
423
|
+
team_dim " 修法:$TEAM_CLI dispatch $agent $id $taskfile --fresh" >&2
|
|
424
|
+
team_dim " (换新会话,推荐;旧历史仍在原文件里)" >&2
|
|
425
|
+
team_dim " 修法:$TEAM_CLI dispatch $agent $id $taskfile --allow-overflow" >&2
|
|
426
|
+
team_dim " (确认要复用;显式放行会醒目警告)" >&2
|
|
427
|
+
else
|
|
428
|
+
# 没有具体 ID/任务书时给的是**模板**,不是可粘路线 —— 因此不带 `修法:` 标记(不许把占位符
|
|
429
|
+
# 冒充成一条能跑的命令)。
|
|
430
|
+
team_dim " · 换新会话(推荐;旧历史仍在原文件里):$TEAM_CLI dispatch <agent> <ID> <task-file> --fresh" >&2
|
|
431
|
+
team_dim " · 确认要复用(例如换成窗口更大的模型):$TEAM_CLI dispatch <agent> <ID> <task-file> --allow-overflow" >&2
|
|
432
|
+
fi
|
|
433
|
+
return 1
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
# ---------------------------------------------------------------- 派单启动校验(M4.3 B)
|
|
437
|
+
# 启动证据:窗口里的 harness 在**跑 agent 之前**把 "<nonce> <pane-shell-pid>" 写进这个文件。
|
|
438
|
+
# 为什么需要:旧实现只要 `tmux new-window` 返回 0 就报成功 —— 命令要是被一个卡死的进程的输入缓冲
|
|
439
|
+
# 吃掉(现场 D9 事件 B:新 session id 从未出现、什么都没跑),派单照样「成功」。
|
|
440
|
+
# nonce 只在**我们的 harness 真的在窗口里执行了**时才出现:换窗口、打字进旧进程、别的进程占着
|
|
441
|
+
# 窗口都不会产生它(F30 的 spawn 证据同源)。
|
|
442
|
+
team_dispatch_spawn_file() { printf '%s\n' "$TEAM_STATE_DIR/dispatch-$1.spawn"; }
|
|
443
|
+
|
|
444
|
+
# 退出证据:窗口 harness 在 agent 进程返回后立刻把 "<本轮 nonce> <退出码>" 写进这个文件。
|
|
445
|
+
# 为什么需要它(M7.5 的 flake):旧实现是「睡 ALIVE_SEC 后**采样一次** team_pane_busy」——
|
|
446
|
+
# 那是一个瞬时判断,而 agent 退出后窗口要经过一段**非确定性的 shell 回退过程**
|
|
447
|
+
# (本容器实测:bash -lc → 交互 bash 读 ~/.bashrc → `exec /usr/bin/zsh -l` → 登录 zsh 启动
|
|
448
|
+
# churn:conda hook / 前台子进程换进程组),期间 pane_current_command 与前台进程组来回变;
|
|
449
|
+
# 采样点落进那一段就会把「已经退出」误报成「还在跑」→ 通知整条消失(同一提交 904/2 与 906/0
|
|
450
|
+
# 交替出现)。退出码由 agent 的**父 shell** 亲手写下,是事件而不是采样:与 shell 启动快慢无关。
|
|
451
|
+
team_dispatch_exit_file() { printf '%s\n' "$TEAM_STATE_DIR/dispatch-$1.exit"; }
|
|
452
|
+
|
|
453
|
+
# 等退出证据。成功 → stdout 打印退出码;窗口里还没退出(或本轮没写)→ 非 0。
|
|
454
|
+
team_wait_agent_exit() { # <agent> <nonce> [秒]
|
|
455
|
+
local agent="$1" nonce="$2" wait="${3:-${TEAM_DISPATCH_ALIVE_SEC:-1}}" steps got code i=0
|
|
456
|
+
case "$wait" in ''|*[!0-9]*) wait=1 ;; esac
|
|
457
|
+
[ "$wait" -gt 0 ] || return 1
|
|
458
|
+
steps=$((wait * 20)); [ "$steps" -gt 0 ] || steps=20
|
|
459
|
+
while [ "$i" -lt "$steps" ]; do
|
|
460
|
+
[ "$i" -gt 0 ] && sleep 0.05
|
|
461
|
+
got="$(head -1 "$(team_dispatch_exit_file "$agent")" 2>/dev/null || true)"
|
|
462
|
+
case "$got" in
|
|
463
|
+
"$nonce "*) code="${got#* }"
|
|
464
|
+
case "$code" in ''|*[!0-9]*) : ;; *) printf '%s\n' "$code"; return 0 ;; esac ;;
|
|
465
|
+
esac
|
|
466
|
+
i=$((i + 1))
|
|
467
|
+
done
|
|
468
|
+
return 1
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
# 等启动证据。成功 → stdout 打印 pane shell 的 pid;失败 → 非 0。
|
|
472
|
+
team_wait_launch_proof() { # <agent> <nonce> [秒]
|
|
473
|
+
local agent="$1" nonce="$2" wait="${3:-${TEAM_DISPATCH_VERIFY_SEC:-8}}" steps got pid i=0
|
|
474
|
+
case "$wait" in ''|*[!0-9]*) wait=8 ;; esac
|
|
475
|
+
steps=$((wait * 4)); [ "$steps" -gt 0 ] || steps=4
|
|
476
|
+
while [ "$i" -lt "$steps" ]; do
|
|
477
|
+
[ "$i" -gt 0 ] && sleep 0.25
|
|
478
|
+
got="$(head -1 "$(team_dispatch_spawn_file "$agent")" 2>/dev/null || true)"
|
|
479
|
+
case "$got" in
|
|
480
|
+
"$nonce "*) pid="${got#* }"
|
|
481
|
+
case "$pid" in ''|*[!0-9]*) : ;; *) printf '%s\n' "$pid"; return 0 ;; esac ;;
|
|
482
|
+
esac
|
|
483
|
+
i=$((i + 1))
|
|
484
|
+
done
|
|
485
|
+
return 1
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
# ---------------------------------------------------------------- 启动失败诊断(M8.2)
|
|
489
|
+
# 尾屏:harness 在 agent 退出那一刻自己抓一份(见 team_cmd_dispatch 里的 inner)——
|
|
490
|
+
# CLI 退出后容器 shell 的启动链可能清屏,事后再从外面 capture 也许只剩空屏(PM 侧 M8.1 实测过)。
|
|
491
|
+
team_dispatch_tail_file() { printf '%s\n' "$TEAM_STATE_DIR/dispatch-$1-tail.txt"; }
|
|
492
|
+
|
|
493
|
+
# 启动失败诊断:worker 侧的 sibling of state/pm-launch-failed.log(M8.1)。按 agent 分文件,
|
|
494
|
+
# 两个 worker 同时失败不会互相覆盖。
|
|
495
|
+
team_dispatch_launch_failed_log() { printf '%s\n' "$TEAM_STATE_DIR/dispatch-$1-launch-failed.log"; }
|
|
496
|
+
|
|
497
|
+
# worker 窗口的尾屏(M8.2):与 PM 侧 team_pm_pane_tail 同一形状(有界重试 + 归一化),
|
|
498
|
+
# 只是目标是 worker 窗口。窗口不存在/始终空白 → 空(不编造内容)。
|
|
499
|
+
team_agent_pane_tail() { # <agent> [<重试次数>] → stdout
|
|
500
|
+
local agent="${1:-}" tries="${2:-12}" i=0 out="" t
|
|
501
|
+
[ -n "$agent" ] || return 0
|
|
502
|
+
team_agent_window_exists "$agent" || return 0
|
|
503
|
+
t="$TEAM_SESSION:$agent"
|
|
504
|
+
while :; do
|
|
505
|
+
out="$(tmux capture-pane -p -t "$t" -S -200 2>/dev/null || true)"
|
|
506
|
+
team_text_has_content "$out" && break
|
|
507
|
+
[ "$i" -ge "$tries" ] && break
|
|
508
|
+
i=$((i + 1)); sleep 0.1
|
|
509
|
+
done
|
|
510
|
+
team_text_has_content "$out" || return 0
|
|
511
|
+
printf '%s\n' "$out" | team_pane_tail_normalize
|
|
512
|
+
return 0
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
# 把「agent 没跑起来」的现场写进 state/dispatch-<agent>-launch-failed.log(PM 侧 pm-launch-failed.log 的 sibling):
|
|
516
|
+
# 渲染出的命令 + 解析到的可执行文件 + harness 记下的退出码 + 窗口尾屏(优先用 harness 自抓的那份)。
|
|
517
|
+
team_dispatch_launch_diag() { # <agent> <ID> <渲染出的命令> <解析到的可执行文件> <退出码> → 诊断文件路径(追加)
|
|
518
|
+
local agent="$1" id="$2" cmd="$3" bin="$4" rc="$5" f tailf pane src i=0
|
|
519
|
+
f="$(team_dispatch_launch_failed_log "$agent")"; mkdir -p "$TEAM_STATE_DIR"
|
|
520
|
+
tailf="$(team_dispatch_tail_file "$agent")"; pane=""; src=""
|
|
521
|
+
# harness 写下退出证据**之后**才抓尾屏(事件语义优先:退出码不能等抓屏),所以文件可能还差一拍:
|
|
522
|
+
# 有界等它出现(最多 ~1s)——那一份是 agent 退出那一刻的屏幕;始终没有则从外面重抓(见下)。
|
|
523
|
+
while [ "$i" -lt 20 ]; do
|
|
524
|
+
if [ -s "$tailf" ] && grep -q '[^[:space:]]' "$tailf" 2>/dev/null; then break; fi
|
|
525
|
+
i=$((i + 1)); sleep 0.05
|
|
526
|
+
done
|
|
527
|
+
{
|
|
528
|
+
printf '==== %s · agent 启动失败 ====\n' "$(team_timestamp)"
|
|
529
|
+
printf 'agent : %s\n' "$agent"
|
|
530
|
+
printf 'task : %s\n' "$id"
|
|
531
|
+
printf 'target : %s:%s\n' "$TEAM_SESSION" "$agent"
|
|
532
|
+
printf 'cmd : TEAM_AGENT_CMD=%s\n' "$(printf '%q' "${TEAM_AGENT_CMD:-}")"
|
|
533
|
+
printf 'bin : %s\n' "$bin"
|
|
534
|
+
printf 'exit : %s(窗口 harness 记录的 agent 退出码)\n' "$rc"
|
|
535
|
+
[ -n "$cmd" ] && printf 'render : %s\n' "$cmd"
|
|
536
|
+
printf 'pane : %s(%s 字节)\n' "$tailf" "$(wc -c < "$tailf" 2>/dev/null | tr -dc '0-9' || echo 0)"
|
|
537
|
+
if [ -s "$tailf" ] && grep -q '[^[:space:]]' "$tailf" 2>/dev/null; then
|
|
538
|
+
src="agent 退出那一刻,harness 自抓"
|
|
539
|
+
pane="$(team_pane_tail_normalize < "$tailf")"
|
|
540
|
+
else
|
|
541
|
+
src="重新抓取"
|
|
542
|
+
pane="$(team_agent_pane_tail "$agent")"
|
|
543
|
+
fi
|
|
544
|
+
if team_text_has_content "$pane"; then
|
|
545
|
+
printf -- '--- pane(%s)---\n%s\n--- end ---\n' "$src" "$pane"
|
|
546
|
+
else
|
|
547
|
+
printf -- '--- pane ---\n(窗口已不存在或始终空白:用上面的 render 命令手工跑一次看它的报错)\n'
|
|
548
|
+
fi
|
|
549
|
+
} >> "$f"
|
|
550
|
+
printf '%s\n' "$f"
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
# ---------------------------------------------------------------- P55 · 死 pane:座位状况,不是活座位
|
|
554
|
+
# 判据与证据字段全部来自 tmux 的 pane census(pane_dead / pane_dead_status / pane_dead_signal /
|
|
555
|
+
# pane_dead_time),实测记录见 openspec/changes/agent-pane-survivability/design.md D3/D6 与
|
|
556
|
+
# docs/team/reports/P49/。两条纪律:
|
|
557
|
+
# ① 读 pane census 一律用 list-panes:目标不存在 = 报错 = 空输出 = 失败关闭;display-message
|
|
558
|
+
# 对坏目标会静默回退到当前窗口(M6.3 6k⑤ 的教训),绝不用它当证据。
|
|
559
|
+
# ② 死 pane 永不以「活座位」身份出现(running 仍要 M6.5/M37 的 pane 进程树证明),也永不是
|
|
560
|
+
# 投递目标(send-keys 对遗体返回 0 但文字落进虚空 —— 探针 P5)。
|
|
561
|
+
|
|
562
|
+
# 字段间用 | 分隔:pane_dead_status/pane_dead_signal 互斥为空,空白分隔会让 read 串列(空字段被吃掉)
|
|
563
|
+
team_pane_dead_fields() { # <session:window> → "dead|status|signal|time";目标不在/读不到 → 非 0、无输出
|
|
564
|
+
local t="${1:-}" out
|
|
565
|
+
[ -n "$t" ] || return 1
|
|
566
|
+
out="$(tmux list-panes -t "$t" -F '#{pane_dead}|#{pane_dead_status}|#{pane_dead_signal}|#{pane_dead_time}' 2>/dev/null | head -1)"
|
|
567
|
+
[ -n "$out" ] || return 1
|
|
568
|
+
printf '%s\n' "$out"
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
team_pane_evidence_text() { # <status> <signal> → "signal=9" / "status=3" / 空(证据未知时绝不编)
|
|
572
|
+
if [ -n "${2:-}" ]; then printf 'signal=%s\n' "$2"
|
|
573
|
+
elif [ -n "${1:-}" ]; then printf 'status=%s\n' "$1"
|
|
574
|
+
fi
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
team_pane_dead_time_text() { # <epoch> → 人读时间;取不到 → 空
|
|
578
|
+
local t="${1:-}"
|
|
579
|
+
case "$t" in ''|*[!0-9]*) return 0 ;; esac
|
|
580
|
+
date -d "@$t" '+%Y-%m-%d %H:%M:%S %Z' 2>/dev/null || true
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
team_agent_scene_lines() { # → 现场行数(TEAM_AGENT_SCENE_LINES,默认 40;非数字回落 40)
|
|
584
|
+
local n="${TEAM_AGENT_SCENE_LINES:-40}"
|
|
585
|
+
case "$n" in ''|*[!0-9]*) n=40 ;; esac
|
|
586
|
+
printf '%s\n' "$n"
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
team_agent_pane_dead_file() { printf '%s\n' "$TEAM_STATE_DIR/dispatch-$1-pane-dead.txt"; }
|
|
590
|
+
|
|
591
|
+
team_agent_pane_dead() { # <agent> → 0=该席位的窗口在、且 pane 已死(遗体);窗口不在/活着 → 1
|
|
592
|
+
local a="${1:-}" w f
|
|
593
|
+
[ -n "$a" ] || return 1
|
|
594
|
+
w="$(team_state_get "$a" window "$a")"
|
|
595
|
+
team_tmux_has_window "$TEAM_SESSION" "$w" || return 1
|
|
596
|
+
f="$(team_pane_dead_fields "$TEAM_SESSION:$w" 2>/dev/null || true)"
|
|
597
|
+
if [ "${f%%|*}" = "1" ]; then return 0; fi
|
|
598
|
+
return 1
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
team_agent_pane_evidence() { # <agent> → 死 pane 的退出证据("signal=9");不是死 pane/证据未知 → 非 0、无输出
|
|
602
|
+
local a="${1:-}" w f dead status signal dtime ev
|
|
603
|
+
[ -n "$a" ] || return 1
|
|
604
|
+
w="$(team_state_get "$a" window "$a")"
|
|
605
|
+
f="$(team_pane_dead_fields "$TEAM_SESSION:$w" 2>/dev/null || true)"
|
|
606
|
+
[ -n "$f" ] || return 1
|
|
607
|
+
IFS='|' read -r dead status signal dtime <<< "$f"
|
|
608
|
+
[ "$dead" = "1" ] || return 1
|
|
609
|
+
ev="$(team_pane_evidence_text "$status" "$signal")"
|
|
610
|
+
[ -n "$ev" ] || return 1
|
|
611
|
+
printf '%s\n' "$ev"
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
# 死 pane 的画面抓取(唯一实现:复用留证与 status 的现场块共用):capture-pane -S -
|
|
615
|
+
# (可见屏幕可能丢最后一行,scrollback 才是全量 —— 探针 P10),逐行去尾空白、丢掉 tmux 自己画在
|
|
616
|
+
# 屏幕上的「Pane is dead (…)」通知行(它是元数据,退出证据与时刻由 census 单列),再去掉末尾空行,
|
|
617
|
+
# 最后截到 TEAM_AGENT_SCENE_LINES 行 —— 于是「最后 N 行」落在 agent 的真实内容上。
|
|
618
|
+
team_agent_corpse_scene() { # <session:window> → 最后 N 行画面(抓不到 → 空)
|
|
619
|
+
local t="${1:-}"
|
|
620
|
+
[ -n "$t" ] || return 1
|
|
621
|
+
tmux capture-pane -p -S - -t "$t" 2>/dev/null \
|
|
622
|
+
| sed -e 's/[[:space:]]*$//' -e '/^Pane is dead (/d' \
|
|
623
|
+
| awk '{ if (NF) last=NR; line[NR]=$0 } END { for (i=1; i<=last; i++) print line[i] }' \
|
|
624
|
+
| tail -n "$(team_agent_scene_lines)"
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
# 复用留证(design D5):替换遗体窗口之前,先把「座位/窗口/时刻/退出证据/最后画面」落盘。
|
|
628
|
+
# 文件格式:头部五行 + "--- scene ---" + 画面行(status <ID> 的现场块按这个结构回读)。
|
|
629
|
+
team_agent_capture_corpse() { # <agent> → 打印落盘路径;不是死 pane/写不出 → 非 0
|
|
630
|
+
local a="${1:-}" w f dead status signal dtime out
|
|
631
|
+
w="$(team_state_get "$a" window "$a")"
|
|
632
|
+
team_tmux_has_window "$TEAM_SESSION" "$w" || return 1
|
|
633
|
+
f="$(team_pane_dead_fields "$TEAM_SESSION:$w" 2>/dev/null || true)"
|
|
634
|
+
IFS='|' read -r dead status signal dtime <<< "${f:- }"
|
|
635
|
+
[ "$dead" = "1" ] || return 1
|
|
636
|
+
out="$(team_agent_pane_dead_file "$a")"
|
|
637
|
+
{
|
|
638
|
+
printf 'seat: %s\n' "$a"
|
|
639
|
+
printf 'window: %s:%s\n' "$TEAM_SESSION" "$w"
|
|
640
|
+
printf 'captured: %s\n' "$(date -Is)"
|
|
641
|
+
printf 'exit: %s\n' "$(team_pane_evidence_text "$status" "$signal")"
|
|
642
|
+
printf 'dead_time: %s\n' "$(team_pane_dead_time_text "$dtime")"
|
|
643
|
+
printf '%s\n' '--- scene ---'
|
|
644
|
+
team_agent_corpse_scene "$TEAM_SESSION:$w"
|
|
645
|
+
} > "$out" 2>/dev/null || return 1
|
|
646
|
+
printf '%s\n' "$out"
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
# ---------------------------------------------------------------- 派单不许叠任务(M9.3 / DECISIONS D16)
|
|
650
|
+
# 现场(PM 自己的事故):M9.2 还在 dev 手上,PM 又把 P2 派给同一个 agent —— 新派单接管了它的窗口与 state,
|
|
651
|
+
# M9.2 只好临时换人交接。工具当时**知道**那个 agent 的任务与分支(state/<agent>.env、BOARD、工作树),
|
|
652
|
+
# 却什么都没说。这条守卫把「派单前先看它手上有没有没结束的活」从纪律变成机制(D16 的工具侧)。
|
|
653
|
+
# 三条信号同时成立才拒绝(缺一条就照旧派单,不猜):
|
|
654
|
+
# ① state 记着这个 agent 的另一个任务 X(`task=`);
|
|
655
|
+
# ② X 还没结束(M9.2 的交付证据 + 看板裁决 —— team_task_open_reason);
|
|
656
|
+
# ③ 工作树能定位,且确实停在一条任务分支上(不是保护分支、不是 detached)。
|
|
657
|
+
# 不拦:派的就是 X 自己(resume / 断点续跑是「继续」,不是「叠」);X 已经结束;判不出来(说清缺哪个信号)。
|
|
658
|
+
# `--force` 是显式覆盖:把「覆盖了什么」打进输出(不静默接管),真实派单时再落一条审计日志。
|
|
659
|
+
# ---------------------------------------------------------------- P140(dispatch-friction · R4/R5)· 一次派单前检查
|
|
660
|
+
# 所有「无需副作用即可判定」的守卫都产出 finding;driver 把整趟跑完,输出**一份**拒绝:
|
|
661
|
+
# · 守卫用 df_err/df_warn/df_dim 写缓冲区(不是终端)→ 消息体逐字节保留;
|
|
662
|
+
# · 守卫 rc≠0 = 阻塞项,rc=0 = 说明/警告(不阻塞);
|
|
663
|
+
# · 报告顺序:阻塞项(守卫顺序)→ 说明 → 计行;第一行就是第一个阻塞项自己的首行(没有额外横幅);
|
|
664
|
+
# · 只有报告没有阻塞项时,driver 才允许写 state / 打计划 / 开窗。
|
|
665
|
+
# 数组元素编码:<stderr 文本>\x1f<stdout 文本>(两个流分开保留,重放时各回各的流)。
|
|
666
|
+
_TEAM_DF_BLOCKS=()
|
|
667
|
+
_TEAM_DF_NOTES=()
|
|
668
|
+
_TEAM_DF_N=0
|
|
669
|
+
_TEAM_DF_RUN_RC=0
|
|
670
|
+
_TEAM_DF_ERR=""
|
|
671
|
+
_TEAM_DF_OUT=""
|
|
672
|
+
team_df_reset() { _TEAM_DF_BLOCKS=(); _TEAM_DF_NOTES=(); _TEAM_DF_N=0; _TEAM_DF_RUN_RC=0; _TEAM_DF_ERR=""; _TEAM_DF_OUT=""; }
|
|
673
|
+
team_df_err() { _TEAM_DF_ERR="${_TEAM_DF_ERR}$(printf '%s✗%s' "$C_RED" "$C_RESET") $*"$'\n'; }
|
|
674
|
+
team_df_warn() { _TEAM_DF_ERR="${_TEAM_DF_ERR}$(printf '%s!%s' "$C_YEL" "$C_RESET") $*"$'\n'; }
|
|
675
|
+
team_df_dim() { _TEAM_DF_OUT="${_TEAM_DF_OUT}$(printf '%s%s%s' "$C_DIM" "$*" "$C_RESET")"$'\n'; }
|
|
676
|
+
team_df_hint() { _TEAM_DF_OUT="${_TEAM_DF_OUT}$(printf '%s⚠%s' "$C_YEL" "$C_RESET") $*"$'\n'; }
|
|
677
|
+
team_df_raw_err() { _TEAM_DF_ERR="${_TEAM_DF_ERR}${1:-}"$'\n'; }
|
|
678
|
+
# 整段多行文本按行进缓冲(行内已有前缀时不再加)——**不用管道**:管道子 shell 改不到全局。
|
|
679
|
+
team_df_lines_raw_err() { local t="${1:-}" line; [ -n "$t" ] || return 0; while IFS= read -r line; do team_df_raw_err "$line"; done <<< "$t"; }
|
|
680
|
+
team_df_lines_err() { local t="${1:-}" line; [ -n "$t" ] || return 0; while IFS= read -r line; do team_df_err "$line"; done <<< "$t"; }
|
|
681
|
+
team_df_lines_dim() { local t="${1:-}" line; [ -n "$t" ] || return 0; while IFS= read -r line; do team_df_dim "$line"; done <<< "$t"; }
|
|
682
|
+
# 一个守卫跑一趟:_TEAM_DF_RUN_RC = 这次守卫的 rc(driver 据此判「前提缺失 → 判不了」,不冒充查过)。
|
|
683
|
+
team_df_run() { # <守卫函数> [参数…]
|
|
684
|
+
_TEAM_DF_ERR=""; _TEAM_DF_OUT=""
|
|
685
|
+
local rc=0; "$@" || rc=$?
|
|
686
|
+
_TEAM_DF_RUN_RC="$rc"
|
|
687
|
+
if [ "$rc" -eq 0 ]; then _TEAM_DF_NOTES+=("$_TEAM_DF_ERR"$'\x1f'"$_TEAM_DF_OUT")
|
|
688
|
+
else _TEAM_DF_BLOCKS+=("$_TEAM_DF_ERR"$'\x1f'"$_TEAM_DF_OUT"); _TEAM_DF_N=$((_TEAM_DF_N + 1)); fi
|
|
689
|
+
return 0
|
|
690
|
+
}
|
|
691
|
+
# 库守卫(team_mem_guard / team_model_guard / team_guard_resume_session / team_agent_check_launch):
|
|
692
|
+
# 它们没有必须留在父进程的副作用,输出用命令替换捕获(子 shell 里 team_die 不会带走派单)。
|
|
693
|
+
team_df_run_lib() { # <函数> [参数…]
|
|
694
|
+
_TEAM_DF_ERR=""; _TEAM_DF_OUT=""
|
|
695
|
+
local rc=0 out=""
|
|
696
|
+
out="$("$@" 2>&1)" || rc=$?
|
|
697
|
+
_TEAM_DF_RUN_RC="$rc"
|
|
698
|
+
[ -n "$out" ] && out="$out"$'\n'
|
|
699
|
+
if [ "$rc" -eq 0 ]; then _TEAM_DF_NOTES+=("$out"$'\x1f'"")
|
|
700
|
+
else _TEAM_DF_BLOCKS+=("$out"$'\x1f'""); _TEAM_DF_N=$((_TEAM_DF_N + 1)); fi
|
|
701
|
+
return 0
|
|
702
|
+
}
|
|
703
|
+
# driver 自己的说明行(“判不了”“adapter 配置坏了 → 可执行文件判不了”)。
|
|
704
|
+
team_df_say() { # <一行说明>
|
|
705
|
+
_TEAM_DF_ERR=""; _TEAM_DF_OUT=""
|
|
706
|
+
team_df_dim "$*"
|
|
707
|
+
_TEAM_DF_NOTES+=("$_TEAM_DF_ERR"$'\x1f'"$_TEAM_DF_OUT")
|
|
708
|
+
_TEAM_DF_ERR=""; _TEAM_DF_OUT=""
|
|
709
|
+
}
|
|
710
|
+
# 一份拒绝:阻塞项 → 说明 → 计行(末行);没有阻塞项时只重放说明并返回 0。
|
|
711
|
+
team_df_report() { # → 0=继续 / 1=拒绝
|
|
712
|
+
local rec err out
|
|
713
|
+
for rec in ${_TEAM_DF_BLOCKS[@]+"${_TEAM_DF_BLOCKS[@]}"}; do
|
|
714
|
+
err="${rec%%$'\x1f'*}"; out="${rec#*$'\x1f'}"
|
|
715
|
+
[ -n "$err" ] && printf '%s' "$err" >&2
|
|
716
|
+
[ -n "$out" ] && printf '%s' "$out"
|
|
717
|
+
done
|
|
718
|
+
for rec in ${_TEAM_DF_NOTES[@]+"${_TEAM_DF_NOTES[@]}"}; do
|
|
719
|
+
err="${rec%%$'\x1f'*}"; out="${rec#*$'\x1f'}"
|
|
720
|
+
[ -n "$err" ] && printf '%s' "$err" >&2
|
|
721
|
+
[ -n "$out" ] && printf '%s' "$out"
|
|
722
|
+
done
|
|
723
|
+
[ "$_TEAM_DF_N" -gt 0 ] || return 0
|
|
724
|
+
team_err "共 $_TEAM_DF_N 个阻塞项 —— 修好上面每一项后重新派单(--force 只覆盖允许覆盖的项)"
|
|
725
|
+
return 1
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
# 叠任务判定(原 team_dispatch_stack_guard;P140 起是一个 finding 产出器,rc=1 = 阻塞项)。
|
|
729
|
+
# 判定与消息体逐字不变,只多了两条 `修法:` 路线(resume / --force,带具体 ID 与任务书路径)。
|
|
730
|
+
team_dispatch_judge_stack() { # <agent> <ID> <任务书> <force> → 0=继续 / 1=拒绝(原因已写入收集器)
|
|
731
|
+
local agent="$1" id="$2" brief="$3" force="${4:-0}"
|
|
732
|
+
local prev wt wt_branch prev_branch reason st
|
|
733
|
+
TEAM_DISPATCH_STACK_PREV="" # 只有真的覆盖了才置位(同一进程里连续派单也不串台)
|
|
734
|
+
prev="$(team_state_get "$agent" task '')"
|
|
735
|
+
if [ -z "$prev" ]; then
|
|
736
|
+
team_df_dim " $agent 没有在飞的任务记录(state/$agent.env 的 task= 为空或文件不存在):判不出它手上有没有没结束的活,这次不拦"
|
|
737
|
+
return 0
|
|
738
|
+
fi
|
|
739
|
+
[ "$prev" = "$id" ] && return 0 # 同一个任务 = resume / 断点续跑:这是「继续」,不是「叠」
|
|
740
|
+
wt="$(team_state_get "$agent" worktree '')"
|
|
741
|
+
if [ -z "$wt" ] || [ ! -d "$wt" ]; then wt="$(team_agent_worktree "$agent")"; fi
|
|
742
|
+
if [ ! -d "$wt" ]; then
|
|
743
|
+
team_df_dim " $agent 记着的任务 $prev 找不到工作树($wt):判不出它是否还压在这个任务上,这次不拦"
|
|
744
|
+
return 0
|
|
745
|
+
fi
|
|
746
|
+
wt_branch="$(git -C "$wt" rev-parse --abbrev-ref HEAD 2>/dev/null || true)"
|
|
747
|
+
if [ -z "$wt_branch" ] || [ "$wt_branch" = "HEAD" ]; then
|
|
748
|
+
team_df_dim " $agent 的工作树 $wt 不在任何分支上(detached 或不是 git 仓库):判不出它是否还压着 $prev,这次不拦"
|
|
749
|
+
return 0
|
|
750
|
+
fi
|
|
751
|
+
if [ "$wt_branch" = "$TEAM_PROTECTED_BRANCH" ]; then
|
|
752
|
+
# 保护分支上的工作树本来就不允许开工(工作树判定会给出该跑的 git 命令):
|
|
753
|
+
# 这里不重复报同一件事,只把「它手上还有 X」说出来
|
|
754
|
+
team_df_dim " $agent 的工作树在 $TEAM_PROTECTED_BRANCH 上,而它手上还有没结束的任务 $prev:先收尾再派(下面按常规守卫处理)"
|
|
755
|
+
return 0
|
|
756
|
+
fi
|
|
757
|
+
if reason="$(team_task_open_reason "$prev")"; then return 0; fi # X 已结束:输出与以前逐字相同
|
|
758
|
+
prev_branch="$(team_state_get "$agent" branch '')"
|
|
759
|
+
st="$(team_board_status "$prev")"
|
|
760
|
+
if [ "$force" = "1" ]; then
|
|
761
|
+
team_df_warn "显式覆盖(--force):$agent 上还有没结束的任务 $prev —— 这次派 $id 会接管它的窗口与 state"
|
|
762
|
+
team_df_dim " 被让位的任务:$prev |看板:${st:-没有这一行} |分支:$wt_branch(state 记的是 ${prev_branch:-未记})"
|
|
763
|
+
team_df_dim " 它还没结束:$reason"
|
|
764
|
+
TEAM_DISPATCH_STACK_PREV="$prev" # 真实派单路径据此写审计(--print 不写)
|
|
765
|
+
return 0
|
|
766
|
+
fi
|
|
767
|
+
team_df_err "拒绝派单:$agent 上还有一个没结束的任务($prev)—— 这样会把这次的任务叠上去,接管它的窗口与 state"
|
|
768
|
+
team_df_err " 任务 :$prev(看板状态:${st:-BOARD 里没有这一行})"
|
|
769
|
+
if [ "$wt_branch" = "$prev_branch" ] || team_branch_is_for_task "$wt_branch" "$agent" "$prev"; then
|
|
770
|
+
team_df_err " 分支 :$wt_branch(工作树 $wt 还停在它上面)"
|
|
771
|
+
else
|
|
772
|
+
team_df_err " 分支 :工作树 $wt 停在 $wt_branch(state 记的是 ${prev_branch:-没有记录})"
|
|
773
|
+
fi
|
|
774
|
+
team_df_err " 没结束 :$reason"
|
|
775
|
+
team_df_err " 修法:$TEAM_CLI resume --agent $agent"
|
|
776
|
+
team_df_err " (先收尾 $prev;复验/合并后再 team board set $prev done)"
|
|
777
|
+
team_df_err " 修法:$TEAM_CLI dispatch $agent $id $brief --force"
|
|
778
|
+
team_df_err " (显式覆盖:警告 + 一行审计)"
|
|
779
|
+
return 1
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
# 任务书歧义(M9.3 ⑥;P140 起是 finding 产出器):同一个 ID 有多份任务书 = 认不出这次的 scope。
|
|
783
|
+
# 判定与消息体逐字保留;修法是「把过期的那份改名出 glob」——保留历史,也不动正在派的那一份。
|
|
784
|
+
team_dispatch_judge_briefs() { # <ID> <briefs(每行一个)> <数量> <本次要派的那一份>
|
|
785
|
+
local id="$1" briefs="$2" n="${3:-0}" want="${4:-}" b rel stale=""
|
|
786
|
+
[ "${n:-0}" -gt 1 ] || return 0
|
|
787
|
+
team_df_err "拒绝派单:$id 有多份任务书($n 份)—— 认不出哪一份是这次的 scope,不猜"
|
|
788
|
+
while IFS= read -r b; do
|
|
789
|
+
[ -n "$b" ] || continue
|
|
790
|
+
rel="${b#"$TEAM_MAIN_ROOT"/}"
|
|
791
|
+
team_df_err " $rel"
|
|
792
|
+
done <<< "$briefs"
|
|
793
|
+
team_df_err " 旧实现按 glob 顺序取第一份:分支名可能算成旧 slug(撞名 fatal: a branch named … already exists),"
|
|
794
|
+
team_df_err " 更糟的是把旧任务书的 scope 派出去。"
|
|
795
|
+
# 修法:把本次**不是**的那份改名出 glob(保留历史);一份一条可粘贴命令。
|
|
796
|
+
while IFS= read -r b; do
|
|
797
|
+
[ -n "$b" ] || continue
|
|
798
|
+
[ "$b" = "$want" ] && continue
|
|
799
|
+
[ -n "$stale" ] && continue
|
|
800
|
+
stale="$b"
|
|
801
|
+
done <<< "$briefs"
|
|
802
|
+
[ -n "$stale" ] && team_df_dim "$(printf ' 修法:git -C %q mv %q %q' "$TEAM_MAIN_ROOT" "$stale" "$stale.bak")"
|
|
803
|
+
[ -n "$stale" ] && team_df_dim " (把过期的那份改名出 glob;保留历史)"
|
|
804
|
+
team_df_err " 确定性做法:只留一份 —— 把过期的那份改名/删掉(或给它自己的 ID),再派单。"
|
|
805
|
+
return 1
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
# ---------------------------------------------------------------- P23(D31)· change 为中心的派单纪律(P140:finding 化)
|
|
809
|
+
# 四条规则各自是一个 finding 产出器(原 team_dispatch_change_guard 的判定、覆盖闀与审计不变):
|
|
810
|
+
# 规则 1 · 一个任务最多一个 change id(没有逃生门:一个任务实现两个 change 是派错单)
|
|
811
|
+
# 规则 B · change-less 的任务必须声明能解析的锚(specs:#需求 或 anchor: none (infra) — 理由)
|
|
812
|
+
# 规则 2 · 同一 change 的两个未结束任务不得写同一个 delta 文件(单写者)
|
|
813
|
+
# 规则 3 · verify 任务的 agent 不能是该 change 的 apply 作者
|
|
814
|
+
# driver 把规则 1 的结果(change)传给 B/2/3;规则 1 失败就不调它们(判不出的事在报告里说清)。
|
|
815
|
+
# `--force` 覆盖处打印警告并往 TEAM_DISPATCH_AUDIT_LINES 追加**一行**审计
|
|
816
|
+
# (真正落盘在派单成功之后,`--print` 不写 state)。
|
|
817
|
+
# 「判不出来」信号(兄弟的 deltas: 坏/缺 agent:)一律吵但不是拒绝 —— 不把未知冒充成干净。
|
|
818
|
+
team_dispatch_judge_change_shape() { # <ID> <任务书>;合法 → _TEAM_DF_CHANGE=<值>
|
|
819
|
+
local id="$1" brief="$2" val lead example body raw1
|
|
820
|
+
_TEAM_DF_CHANGE=""
|
|
821
|
+
if val="$(team_task_change_value "$brief")"; then _TEAM_DF_CHANGE="$val"; return 0; fi
|
|
822
|
+
# P140(R2):第一行就带合法示例(值里第一个合法 id 前缀,否则 `-`)与具体原因。
|
|
823
|
+
raw1="$(team_brief_field_raw "$brief" change | head -1)"
|
|
824
|
+
lead="$(printf '%s' "$raw1" | sed -n 's/^\([A-Za-z0-9][A-Za-z0-9._-]*\).*/\1/p')"
|
|
825
|
+
if [ -n "$lead" ]; then example="change: $lead(或 change: -)"; else example="change: -"; fi
|
|
826
|
+
team_df_err "拒绝派单:$id 的任务书 change: 行不合法 —— $(printf '%s' "$val" | head -1);合法示例:$example"
|
|
827
|
+
body="$(printf '%s\n' "$val" | tail -n +2 | sed 's/^/ /')"
|
|
828
|
+
[ -n "$body" ] && team_df_lines_raw_err "$body"
|
|
829
|
+
team_df_err " 接受的形式:"
|
|
830
|
+
team_df_err " · change: <一个 change id> 例:change: change-centric-discipline"
|
|
831
|
+
team_df_err " · change: - 不属于任何 change(但要在 specs:/anchor: 里声明锚)"
|
|
832
|
+
team_df_err " 改行:change: ${lead:--}"
|
|
833
|
+
team_df_err " 规则 1 没有 --force 逃生门:一个任务实现两个 change 是派错单,不是偏好。"
|
|
834
|
+
return 1
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
team_dispatch_judge_anchor() { # <agent> <ID> <任务书> <change> <force>
|
|
838
|
+
local agent="$1" id="$2" brief="$3" change="$4" force="${5:-0}" out body rel
|
|
839
|
+
[ "$change" = "-" ] || return 0
|
|
840
|
+
rel="${brief#"$TEAM_MAIN_ROOT"/}"
|
|
841
|
+
if out="$(team_task_anchor "$brief")"; then return 0; fi
|
|
842
|
+
if [ "$force" = "1" ]; then
|
|
843
|
+
team_df_warn "显式覆盖(--force):$id 没有 change:,锚也缺失/不解析 —— 这次照常派单"
|
|
844
|
+
body="$(printf '%s\n' "$out" | sed 's/^/ /')"
|
|
845
|
+
team_df_lines_raw_err "$body"
|
|
846
|
+
TEAM_DISPATCH_AUDIT_LINES="${TEAM_DISPATCH_AUDIT_LINES}dispatch $agent: --force 覆盖锚缺失($id 无 change 且 $rel 的 specs:/anchor: 解析不了)"$'\n'
|
|
847
|
+
return 0
|
|
848
|
+
fi
|
|
849
|
+
team_df_err "拒绝派单:$id 没有 change: 行(或值是 \`-\`),必须声明它的锚"
|
|
850
|
+
body="$(printf '%s\n' "$out" | sed 's/^/ /')"
|
|
851
|
+
team_df_lines_raw_err "$body"
|
|
852
|
+
team_df_err " 编辑 $rel 的 specs:/anchor: 行(specs: <capability>#<requirement> 或 anchor: none (infra) — <非空理由>;改完重派)"
|
|
853
|
+
team_df_err " 修法:$TEAM_CLI dispatch $agent $id $brief --force"
|
|
854
|
+
team_df_err " (警告 + 一行审计:覆盖的是「没有 change 也没有锚」这一项)"
|
|
855
|
+
return 1
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
team_dispatch_judge_deltas_shape() { # <ID> <任务书>
|
|
859
|
+
local id="$1" brief="$2" out body sug
|
|
860
|
+
if out="$(team_task_deltas "$brief")"; then return 0; fi
|
|
861
|
+
sug="$(team_task_deltas_suggestion "$brief")"
|
|
862
|
+
# P140(R3):第一行就带合法示例与具体原因(哪个分隔符 / 哪一项为空)。
|
|
863
|
+
team_df_err "拒绝派单:$id 的 deltas: 行不合法 —— $(printf '%s' "$out" | head -1);合法示例:deltas: panel, verification(或 deltas: -)"
|
|
864
|
+
body="$(printf '%s\n' "$out" | tail -n +2)"
|
|
865
|
+
[ -n "$body" ] && team_df_lines_raw_err "$body"
|
|
866
|
+
team_df_err " 改行:deltas: $sug"
|
|
867
|
+
team_df_err " (deltas: 决定 delta 单写者检查,不能静默当空集;缺行 = 读作整个 change 的 delta 集)"
|
|
868
|
+
return 1
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
team_dispatch_judge_delta_writer() { # <agent> <ID> <任务书> <change> <force>
|
|
872
|
+
local agent="$1" id="$2" brief="$3" change="$4" force="${5:-0}"
|
|
873
|
+
[ "$change" != "-" ] || return 0
|
|
874
|
+
local mine mine_decl mine_text sib sde sdt sib_text shared sid sphase sst sreason sbrief
|
|
875
|
+
local -a conf_items=()
|
|
876
|
+
if ! mine="$(team_task_delta_targets "$brief" "$change")"; then
|
|
877
|
+
team_df_dim " deltas: 行不合法 → change $change 的 delta 单写者检查判不了(见上一项)"
|
|
878
|
+
return 0
|
|
879
|
+
fi
|
|
880
|
+
mine_decl="$(team_task_deltas "$brief")"
|
|
881
|
+
case "$mine_decl" in
|
|
882
|
+
'*') mine_text='(没有 deltas: 行 → 读作整个 change 的 delta 集)' ;;
|
|
883
|
+
'') mine_text='deltas: -(不写 delta)' ;;
|
|
884
|
+
*) mine_text="deltas: $(printf '%s' "$mine_decl" | tr '\n' ',')" ;;
|
|
885
|
+
esac
|
|
886
|
+
while IFS=$'\t' read -r sid sphase sst sreason sbrief; do
|
|
887
|
+
[ -n "$sid" ] || continue
|
|
888
|
+
[ "$sid" = "$id" ] && continue
|
|
889
|
+
if ! sde="$(team_task_delta_targets "$sbrief" "$change")"; then
|
|
890
|
+
team_df_warn " delta 单写者检查:兄弟 $sid(看板 $sst)的 deltas: 行不合法 —— 它的目标集判不出来,不冒充干净"
|
|
891
|
+
continue
|
|
892
|
+
fi
|
|
893
|
+
sdt="$(team_task_deltas "$sbrief")"
|
|
894
|
+
case "$sdt" in
|
|
895
|
+
'*') sib_text='(没有 deltas: 行 → 读作整个 change 的 delta 集)' ;;
|
|
896
|
+
'') sib_text='deltas: -(不写 delta)' ;;
|
|
897
|
+
*) sib_text="deltas: $(printf '%s' "$sdt" | tr '\n' ',')" ;;
|
|
898
|
+
esac
|
|
899
|
+
shared=""
|
|
900
|
+
while IFS= read -r sib; do
|
|
901
|
+
[ -n "$sib" ] || continue
|
|
902
|
+
if printf '%s\n' "$mine" | grep -qxF -- "$sib"; then shared="${shared:+$shared }$sib"; fi
|
|
903
|
+
done <<< "$sde"
|
|
904
|
+
if [ -z "$shared" ]; then
|
|
905
|
+
team_df_dim " change $change 的 delta 单写者检查:兄弟 $sid(看板 $sst,$sib_text)|本次 $mine_text → 无重叠"
|
|
906
|
+
continue
|
|
907
|
+
fi
|
|
908
|
+
if [ "$force" = "1" ]; then
|
|
909
|
+
team_df_warn "显式覆盖(--force):change $change 的 delta 单写者冲突 —— $sid(看板 $sst)与 $id 都会写 $shared"
|
|
910
|
+
team_df_dim " $sid 的声明:$sib_text | 本次声明:$mine_text"
|
|
911
|
+
TEAM_DISPATCH_AUDIT_LINES="${TEAM_DISPATCH_AUDIT_LINES}dispatch $agent: --force 覆盖 delta 单写者($sid 与 $id 共享 $shared)"$'\n'
|
|
912
|
+
continue
|
|
913
|
+
fi
|
|
914
|
+
# F4:不在第一个冲突兄弟处 return —— 先收集,循环结束后**一次列全**
|
|
915
|
+
#(编号 i/n 与总数 n 同源,逐条数与总数自洽)。
|
|
916
|
+
conf_items+=("$(printf '兄弟任务:%s |阶段 %s |看板 %s\n它没结束:%s\n共享文件:%s\n它的声明:%s\n本次声明:%s' \
|
|
917
|
+
"$sid" "${sphase:--}" "$sst" "$sreason" "$shared" "$sib_text" "$mine_text")")
|
|
918
|
+
done < <(team_change_unfinished "$change")
|
|
919
|
+
if [ "${#conf_items[@]}" -gt 0 ]; then
|
|
920
|
+
local n="${#conf_items[@]}" i=0 item line
|
|
921
|
+
team_df_err "拒绝派单:change $change 的同一个 delta 文件被 $n 个未结束的兄弟任务声明(单写者规则)"
|
|
922
|
+
for item in "${conf_items[@]}"; do
|
|
923
|
+
i=$((i + 1))
|
|
924
|
+
while IFS= read -r line; do
|
|
925
|
+
[ -n "$line" ] && team_df_err " 冲突 $i/$n:$line"
|
|
926
|
+
done <<< "$item"
|
|
927
|
+
done
|
|
928
|
+
team_df_err " 列全自对账:上面的编号 1..$n 与计数 $n 同源(逐条数 = 总数)"
|
|
929
|
+
team_df_err " 等这些兄弟结束(done/closed/交付证据)再派,或把两边的 deltas: 写成互不相交的 capability"
|
|
930
|
+
team_df_err " 修法:$TEAM_CLI dispatch $agent $id $brief --force"
|
|
931
|
+
team_df_err " (显式覆盖:警告 + 一行审计;每个冲突兄弟一行审计)"
|
|
932
|
+
return 1
|
|
933
|
+
fi
|
|
934
|
+
return 0
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
team_dispatch_judge_verify_seat() { # <agent> <ID> <任务书> <change> <phase> <force>
|
|
938
|
+
local agent="$1" id="$2" brief="$3" change="$4" phase="$5" force="${6:-0}"
|
|
939
|
+
[ "$phase" = "verify" ] && [ "$change" != "-" ] || return 0
|
|
940
|
+
local authors kind aid aauth authored="" dropped="" missing=""
|
|
941
|
+
authors="$(team_change_apply_authors "$change")"
|
|
942
|
+
while IFS=$'\t' read -r kind aauth aid _why; do
|
|
943
|
+
[ -n "$kind" ] || continue
|
|
944
|
+
case "$kind" in
|
|
945
|
+
agent) [ "$aauth" = "$agent" ] && authored="${authored:+$authored、}$aid" ;;
|
|
946
|
+
dropped) dropped="${dropped:+$dropped、}$aid" ;;
|
|
947
|
+
missing) missing="${missing:+$missing、}$aid(${_why:-缺 agent:})" ;;
|
|
948
|
+
esac
|
|
949
|
+
done <<< "$authors"
|
|
950
|
+
[ -n "$dropped" ] && team_df_dim " 已排除(看板 dropped):$dropped"
|
|
951
|
+
[ -n "$missing" ] && team_df_warn " 作者信号缺失:$missing —— 判不出它们的作者,不当作干净(照常派单)"
|
|
952
|
+
if [ -n "$authored" ]; then
|
|
953
|
+
if [ "$force" = "1" ]; then
|
|
954
|
+
team_df_warn "显式覆盖(--force):verification 不再独立 —— $agent 写过 change $change 的 apply 任务($authored),又要 verify $id"
|
|
955
|
+
TEAM_DISPATCH_AUDIT_LINES="${TEAM_DISPATCH_AUDIT_LINES}dispatch $agent: --force 覆盖自验(change $change 的 apply 作者 $authored 来 verify $id)"$'\n'
|
|
956
|
+
else
|
|
957
|
+
team_df_err "拒绝派单:verification 不独立 —— $agent 写过 change $change 的 apply 任务($authored),不能自己验自己"
|
|
958
|
+
team_df_err " change:$change | agent:$agent | 它写过的任务:$authored"
|
|
959
|
+
team_df_err " 换一个没写过这些 apply 任务的 agent 来 verify(独立验证不换人就不成立)"
|
|
960
|
+
team_df_err " 修法:$TEAM_CLI dispatch $agent $id $brief --force"
|
|
961
|
+
team_df_err " (显式覆盖:警告 + 一行审计)"
|
|
962
|
+
return 1
|
|
963
|
+
fi
|
|
964
|
+
fi
|
|
965
|
+
return 0
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
# 分支声明不合法(--branch 或任务书 branch: 行不属于本任务):拒绝 + 一条可粘的修法。
|
|
969
|
+
team_dispatch_judge_branch_decl() { # <agent> <ID> <任务书> <原因行> <--branch 值>
|
|
970
|
+
local agent="$1" id="$2" brief="$3" reason="$4" flag="${5:-}" derived
|
|
971
|
+
derived="$(team_branch_for_agent "$agent" "$id")"
|
|
972
|
+
team_df_err "拒绝派单:分支声明不属于本任务($id)—— $reason"
|
|
973
|
+
team_df_err " 接受形状:task/$id-<slug>(或 agent/$agent)"
|
|
974
|
+
if [ -n "$flag" ]; then
|
|
975
|
+
team_df_err " 修法:$TEAM_CLI dispatch $agent $id $brief --branch $derived"
|
|
976
|
+
else
|
|
977
|
+
team_df_err " 改行:branch: $derived"
|
|
978
|
+
fi
|
|
979
|
+
return 1
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
# agent 可执行文件可解析(P140:原 team_die 变成阻塞项,与其他判定同一份报告)。
|
|
983
|
+
team_dispatch_judge_agent_bin() { # <agent>
|
|
984
|
+
local agent_bin probe
|
|
985
|
+
if [ -n "${TEAM_AGENT_CMD:-}${TEAM_AGENT_BIN:-}" ]; then
|
|
986
|
+
# 自定义 adapter(codex/opencode/…):只看配好的可执行文件能不能解析到
|
|
987
|
+
agent_bin="$(team_agent_bin_path)"
|
|
988
|
+
case "$agent_bin" in /*) ;; *) team_df_warn "agent 可执行文件不是绝对路径($agent_bin):窗口里可能 PATH 未就绪,建议用 TEAM_AGENT_BIN 写死绝对路径";; esac
|
|
989
|
+
if ! command -v "$agent_bin" >/dev/null 2>&1; then
|
|
990
|
+
probe="${TEAM_AGENT_CMD%% *}"; [ -n "$probe" ] || probe="$(basename "$agent_bin")"
|
|
991
|
+
team_df_err "找不到 agent 可执行文件:$agent_bin(检查 TEAM_AGENT_BIN 或 TEAM_AGENT_CMD 的首词)"
|
|
992
|
+
team_df_err " 修法:$TEAM_CLI config set TEAM_AGENT_BIN \"$(command -v "$probe")\""
|
|
993
|
+
team_df_err " (把可执行文件指到真的路径;command -v $probe 找不到就得先装/先修 PATH)"
|
|
994
|
+
return 1
|
|
995
|
+
fi
|
|
996
|
+
else
|
|
997
|
+
agent_bin="$TEAM_PI_BIN"
|
|
998
|
+
case "$agent_bin" in /*) ;; *) team_df_warn "TEAM_PI_BIN 不是绝对路径($agent_bin):窗口里可能 PATH 未就绪,建议写死绝对路径";; esac
|
|
999
|
+
if ! command -v "$TEAM_PI_BIN" >/dev/null 2>&1; then
|
|
1000
|
+
team_df_err "找不到 pi 可执行文件:TEAM_PI_BIN=$TEAM_PI_BIN(设成绝对路径再派单)"
|
|
1001
|
+
team_df_err " 修法:$TEAM_CLI config set TEAM_PI_BIN \"$(command -v pi)\""
|
|
1002
|
+
team_df_err " (指向真的 pi;command -v 找不到就得先装/先修 PATH)"
|
|
1003
|
+
return 1
|
|
1004
|
+
fi
|
|
1005
|
+
fi
|
|
1006
|
+
return 0
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
# ---------------------------------------------------------------- P151(F3)· 容量拒绝的可粘修法
|
|
1010
|
+
# 容量守卫(team_mem_guard)只做判定与诊断,不知道自己在为谁派单 —— 修法要含真的 agent / ID /
|
|
1011
|
+
# 任务书路径,所以由 driver 这侧补上(判定与覆盖语义一字不动:这里只是多打印两条能跑的命令,
|
|
1012
|
+
# 且只打开真正拦住的那条硬线)。
|
|
1013
|
+
team_dispatch_mem_fix_cmd() { # <agent> <ID> <任务书> <守卫输出> → 覆盖命令
|
|
1014
|
+
local agent="$1" id="$2" taskfile="$3" out="$4" knobs=""
|
|
1015
|
+
case "$out" in *"MemAvailable 只剩"*) knobs="$knobs TEAM_MIN_AVAIL_MB=0" ;; esac
|
|
1016
|
+
case "$out" in *"磁盘 swap 只剩"*) knobs="$knobs TEAM_MIN_FREE_SWAP_MB=0" ;; esac
|
|
1017
|
+
case "$out" in *"MemAvailable + 磁盘 swap 空闲仅"*) knobs="$knobs TEAM_MIN_TOTAL_MB=0" ;; esac
|
|
1018
|
+
[ -n "$knobs" ] || knobs=" TEAM_MIN_AVAIL_MB=0 TEAM_MIN_FREE_SWAP_MB=0 TEAM_MIN_TOTAL_MB=0"
|
|
1019
|
+
printf '%s %s dispatch %s %s %s\n' "${knobs# }" "$TEAM_CLI" "$agent" "$id" "$(printf '%q' "$taskfile")"
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
team_dispatch_judge_mem() { # <agent> <ID> <任务书>(team_df_run_lib 守卫:透传 team_mem_guard 的判定)
|
|
1023
|
+
local agent="$1" id="$2" taskfile="$3" out rc=0
|
|
1024
|
+
out="$(team_mem_guard 2>&1)" || rc=$?
|
|
1025
|
+
[ -n "$out" ] && printf '%s\n' "$out"
|
|
1026
|
+
[ "$rc" -eq 0 ] && return 0
|
|
1027
|
+
local override_line override_note
|
|
1028
|
+
override_line=" 修法:$(team_dispatch_mem_fix_cmd "$agent" "$id" "$taskfile" "$out")"
|
|
1029
|
+
override_note=" (显式降低底线:拿机器稳定性冒险;确认余量真的够再用)"
|
|
1030
|
+
printf '%s\n' " 等一个席位结束后再重派($TEAM_CLI ps 看谁在跑;这行不是可粘路线,只是建议)" \
|
|
1031
|
+
"$override_line" "$override_note"
|
|
1032
|
+
return 1
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
# ---------------------------------------------------------------- P140(dispatch-friction · R6)· 席位上一轮预提示
|
|
1036
|
+
# 两条腿各自独立、都可缺(判不出来一律沉默,不猜):
|
|
1037
|
+
# · 死因腿:agent-death-reason 的读取器给出 quota/balance —— 点名分类、来源、时间与原文;
|
|
1038
|
+
# · 零产出腿:state/<agent>.env 里上一轮记的 sid/sid_bytes 与同一个会话文件**现在的字节数相等**
|
|
1039
|
+
# (启动时记下的值,下一轮没长过)—— 用工具自己的粗粒度词汇 `0 bytes ≈ 0 tokens`。
|
|
1040
|
+
# 永远不阻断、不改退出码;两个腿都判不出来 → 一行都不打印。
|
|
1041
|
+
team_dispatch_judge_seat_hint() { # <agent> <worktree>
|
|
1042
|
+
local agent="$1" wt="$2" fields cat source time raw sid rec_bytes f now_bytes
|
|
1043
|
+
fields="$(team_seat_death_fields "$agent" 2>/dev/null || true)"
|
|
1044
|
+
if [ -n "$fields" ]; then
|
|
1045
|
+
IFS=$'\t' read -r cat source time raw <<< "$fields"
|
|
1046
|
+
case "$cat" in
|
|
1047
|
+
quota|balance)
|
|
1048
|
+
if [ -n "$time" ] && [ "$time" != "-" ]; then
|
|
1049
|
+
team_df_hint "这个席位上一次死于 $cat(来源:$source · $time)· 原文:${raw:--} —— 重派前先确认额度/余额(或换模型)"
|
|
1050
|
+
else
|
|
1051
|
+
team_df_hint "这个席位上一次死于 $cat(来源:$source)· 原文:${raw:--} —— 重派前先确认额度/余额(或换模型)"
|
|
1052
|
+
fi ;;
|
|
1053
|
+
esac
|
|
1054
|
+
fi
|
|
1055
|
+
sid="$(team_state_get "$agent" sid '')"
|
|
1056
|
+
rec_bytes="$(team_state_get "$agent" sid_bytes '')"
|
|
1057
|
+
if [ -n "$sid" ] && [ -n "$rec_bytes" ]; then
|
|
1058
|
+
f="$(team_session_file "$sid" "$wt" 2>/dev/null || true)"
|
|
1059
|
+
if [ -n "$f" ] && [ -f "$f" ]; then
|
|
1060
|
+
now_bytes="$(team_file_bytes "$f")"
|
|
1061
|
+
case "$rec_bytes" in ''|*[!0-9]*) : ;; *)
|
|
1062
|
+
if [ "$now_bytes" = "$rec_bytes" ]; then
|
|
1063
|
+
team_df_hint "这个席位上一轮没有产出:0 bytes ≈ 0 tokens(上一轮会话 $sid 的文件 $f 从启动起一个字节没长)"
|
|
1064
|
+
fi ;;
|
|
1065
|
+
esac
|
|
1066
|
+
fi
|
|
1067
|
+
fi
|
|
1068
|
+
return 0
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
team_cmd_dispatch() {
|
|
1072
|
+
team_require_cmd tmux "agent 在 tmux 窗口里跑,PM 需要能旁观与追问"
|
|
1073
|
+
local agent="" id="" taskfile="" model="" branch_flag="" fresh=0 printonly=0 overflow=0 force=0
|
|
1074
|
+
while [ $# -gt 0 ]; do
|
|
1075
|
+
case "$1" in
|
|
1076
|
+
--model) model="${2:?}"; shift 2 ;;
|
|
1077
|
+
--branch)
|
|
1078
|
+
[ $# -ge 2 ] || team_usage_die "dispatch: --branch 需要 <分支名>"
|
|
1079
|
+
[ -n "$2" ] || team_usage_die "dispatch: --branch 需要 <分支名>"
|
|
1080
|
+
branch_flag="$2"; shift 2 ;;
|
|
1081
|
+
--branch=*)
|
|
1082
|
+
[ -n "${1#*=}" ] || team_usage_die "dispatch: --branch 需要 <分支名>"
|
|
1083
|
+
branch_flag="${1#*=}"; shift ;;
|
|
1084
|
+
--fresh) fresh=1; shift ;;
|
|
1085
|
+
--allow-overflow) overflow=1; shift ;;
|
|
1086
|
+
--force) force=1; shift ;;
|
|
1087
|
+
--print) printonly=1; shift ;;
|
|
1088
|
+
-*) team_usage_die "dispatch: 未知参数 $1" ;;
|
|
1089
|
+
*) if [ -z "$agent" ]; then agent="$1"
|
|
1090
|
+
elif [ -z "$id" ]; then id="$1"
|
|
1091
|
+
elif [ -z "$taskfile" ]; then taskfile="$1"
|
|
1092
|
+
else team_usage_die "dispatch: 多余参数 $1"; fi
|
|
1093
|
+
shift ;;
|
|
1094
|
+
esac
|
|
1095
|
+
done
|
|
1096
|
+
[ -n "$agent" ] && [ -n "$id" ] && [ -n "$taskfile" ] || \
|
|
1097
|
+
team_usage_die "dispatch <agent> <ID> <task-file> [--model m] [--branch <name>] [--fresh] [--allow-overflow] [--force] [--print]"
|
|
1098
|
+
team_require_agent "$agent"
|
|
1099
|
+
|
|
1100
|
+
# 任务书路径:先按 cwd 解析,再按主工作树解析
|
|
1101
|
+
[ -f "$taskfile" ] || taskfile="$TEAM_MAIN_ROOT/$taskfile"
|
|
1102
|
+
[ -f "$taskfile" ] || team_die "找不到任务书:$taskfile"
|
|
1103
|
+
taskfile="$(cd "$(dirname "$taskfile")" && pwd)/$(basename "$taskfile")"
|
|
1104
|
+
# M6.3 F15:任务书必须在项目主工作树里。提示词命令 worker「work only inside <project>」,
|
|
1105
|
+
# 却把 /tmp/... 称为 "repo-relative path"(自相矛盾);而且项目外的文件不归项目管。
|
|
1106
|
+
case "$taskfile" in
|
|
1107
|
+
"$TEAM_MAIN_ROOT"/*) ;;
|
|
1108
|
+
*)
|
|
1109
|
+
team_err "任务书不在本项目里:$taskfile"
|
|
1110
|
+
team_dim " 项目主工作树:$TEAM_MAIN_ROOT"
|
|
1111
|
+
team_dim " 把任务书放进项目再派单(例如 $TEAM_DOCS_DIR/tasks/):worker 只被授权在项目内工作" >&2
|
|
1112
|
+
return 1 ;;
|
|
1113
|
+
esac
|
|
1114
|
+
|
|
1115
|
+
# M9.3 ⑥ + P140(dispatch-friction · R4/R5):认错任务书与所有“无需副作用即可判定”的守卫
|
|
1116
|
+
# 在一趟里判完,输出**一份**拒绝(--force 不适用认错任务:认错 scope 不是「你说了算」的事)。
|
|
1117
|
+
local briefs nbrief
|
|
1118
|
+
briefs="$(team_task_briefs "$id")"
|
|
1119
|
+
nbrief="$(printf '%s\n' "$briefs" | grep -c . || true)"
|
|
1120
|
+
|
|
1121
|
+
team_df_reset
|
|
1122
|
+
TEAM_CHECKED_BRANCH=""
|
|
1123
|
+
TEAM_DISPATCH_AUDIT_LINES=""
|
|
1124
|
+
TEAM_DISPATCH_STACK_PREV=""
|
|
1125
|
+
|
|
1126
|
+
# ① 任务书歧义
|
|
1127
|
+
team_df_run team_dispatch_judge_briefs "$id" "$briefs" "$nbrief" "$taskfile"
|
|
1128
|
+
|
|
1129
|
+
# ② 分支声明(--branch > 任务书 branch: 行 > 由标题推导)
|
|
1130
|
+
local br_out="" br_name="" br_src="" br_decl_ok=1
|
|
1131
|
+
if br_out="$(team_dispatch_branch_decl "$agent" "$id" "$taskfile" "$branch_flag")"; then
|
|
1132
|
+
br_name="${br_out%%$'\x1f'*}"; br_src="${br_out#*$'\x1f'}"
|
|
1133
|
+
else
|
|
1134
|
+
br_decl_ok=0
|
|
1135
|
+
team_df_run team_dispatch_judge_branch_decl "$agent" "$id" "$taskfile" "$(printf '%s' "$br_out" | head -1)" "$branch_flag"
|
|
1136
|
+
fi
|
|
1137
|
+
|
|
1138
|
+
# ③ 头部规则(change 形状 / 锚 / deltas 形状 / 单写者 / verify 席位)
|
|
1139
|
+
team_df_run team_dispatch_judge_change_shape "$id" "$taskfile"
|
|
1140
|
+
local df_change="${_TEAM_DF_CHANGE:-}"
|
|
1141
|
+
local df_phase; df_phase="$(team_brief_field "$taskfile" phase)"
|
|
1142
|
+
case "$df_phase" in explore|propose|apply|verify|archive) ;; *) df_phase="" ;; esac
|
|
1143
|
+
team_df_run team_dispatch_judge_anchor "$agent" "$id" "$taskfile" "$df_change" "$force"
|
|
1144
|
+
team_df_run team_dispatch_judge_deltas_shape "$id" "$taskfile"
|
|
1145
|
+
team_df_run team_dispatch_judge_delta_writer "$agent" "$id" "$taskfile" "$df_change" "$force"
|
|
1146
|
+
team_df_run team_dispatch_judge_verify_seat "$agent" "$id" "$taskfile" "$df_change" "$df_phase" "$force"
|
|
1147
|
+
|
|
1148
|
+
# ④ 叠任务(resume / up --agents 也走这里:同一任务短路,那两扇门的语义不变)
|
|
1149
|
+
team_df_run team_dispatch_judge_stack "$agent" "$id" "$taskfile" "$force"
|
|
1150
|
+
|
|
1151
|
+
# ⑤ 工作树存在 / 脏 / 分支身份(前提缺失时后面的判定说「判不了」,不冒充查过)
|
|
1152
|
+
local wt; wt="$(team_agent_worktree "$agent")"
|
|
1153
|
+
team_df_run team_dispatch_judge_worktree_present "$agent" "${br_name:-$(team_branch_for_agent "$agent" "$id")}"
|
|
1154
|
+
if [ "$_TEAM_DF_RUN_RC" -ne 0 ]; then
|
|
1155
|
+
team_df_say " 工作树不在 → 脏工作树与分支身份判不了(先按上面的修法建工作树)"
|
|
1156
|
+
else
|
|
1157
|
+
team_df_run team_dispatch_judge_worktree_dirty "$agent" "$id" "$wt"
|
|
1158
|
+
if [ "$br_decl_ok" = "1" ]; then
|
|
1159
|
+
team_df_run team_dispatch_judge_worktree_branch "$agent" "$id" "$wt" "$br_name" "$br_src"
|
|
1160
|
+
else
|
|
1161
|
+
team_df_say " 分支声明不合法 → 工作树的分支身份判不了(见上面那一项)"
|
|
1162
|
+
fi
|
|
1163
|
+
fi
|
|
1164
|
+
|
|
1165
|
+
# ⑥ 启动前置(容量 / 模型并发 / 会话 vs 窗口 / agent 可执行文件)
|
|
1166
|
+
# M14:解析顺序 = --model 显式参数 > 配置(TEAM_AGENT_MODELS 的 per-agent > TEAM_DEFAULT_MODEL)。
|
|
1167
|
+
# 名册 state 里的 model 只是「上次用了什么」的展示记录(roster/ps 标注来源用),不再当默认来源 ——
|
|
1168
|
+
# 旧行为(state 优先)让配置改了也不生效:名册里的 deepseek 旧记录压过了新配的 k3-256k。
|
|
1169
|
+
local model_src="config"
|
|
1170
|
+
if [ -z "$model" ]; then model="$(team_agent_model "$agent")"; else model_src="explicit"; fi
|
|
1171
|
+
local provider="${model%%/*}"
|
|
1172
|
+
local sid="$TEAM_SESSION-$agent"
|
|
1173
|
+
[ "$fresh" = "1" ] && sid="$sid-$(date +%s)"
|
|
1174
|
+
|
|
1175
|
+
team_df_run_lib team_dispatch_judge_mem "$agent" "$id" "$taskfile"
|
|
1176
|
+
# P144:磁盘/inode 腿 —— 判的是这个 worker 真正要写的两个文件系统(临时根 + 它的工作树,
|
|
1177
|
+
# 不是共享的 worktrees 根),在**任何开窗动作之前**(--print 也在内),并且是 P140 的启动前
|
|
1178
|
+
# 那一趟里的一个 finding(拒绝时和别的阻塞项一起交底,不抢自己的单独出口)。
|
|
1179
|
+
local disk_tmp="${TMPDIR:-/tmp}"
|
|
1180
|
+
team_df_run_lib team_disk_guard "$disk_tmp" "$wt"
|
|
1181
|
+
# 读数是一条「说明」(rc=0 的 finding):放行时在启动前那一趟里打印;被拒时由拒绝本身带读数。
|
|
1182
|
+
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"
|
|
1184
|
+
# M4.3 A:会话规模 vs 模型窗口(默认拒绝,--fresh / --allow-overflow 是出路)
|
|
1185
|
+
team_df_run_lib team_guard_resume_session "$agent" "$model" "$sid" "$wt" "$fresh" "$overflow" "$id" "$taskfile"
|
|
1186
|
+
# agent adapter:空配置 = 内置 Pi(老路径,报错文案也不变);die 被捕获成阻塞项,不带走其他判定
|
|
1187
|
+
team_df_run_lib team_agent_check_launch
|
|
1188
|
+
if [ "$_TEAM_DF_RUN_RC" -eq 0 ]; then
|
|
1189
|
+
team_df_run team_dispatch_judge_agent_bin "$agent"
|
|
1190
|
+
else
|
|
1191
|
+
team_df_say " adapter 配置不合法 → agent 可执行文件判不了(见上面那一项)"
|
|
1192
|
+
fi
|
|
1193
|
+
|
|
1194
|
+
# ⑦ R6 席位预提示(⚠ 行;只有判得出来才打印,不阻断、不改退出码)
|
|
1195
|
+
team_df_run team_dispatch_judge_seat_hint "$agent" "$wt"
|
|
1196
|
+
|
|
1197
|
+
# ⑧ 报告:一份拒绝(阻塞项 → 说明 → 计行);通过才继续
|
|
1198
|
+
if ! team_df_report; then
|
|
1199
|
+
return 1
|
|
1200
|
+
fi
|
|
1201
|
+
|
|
1202
|
+
# 报告通过:这时才允许写 state / 打计划 / 开窗
|
|
1203
|
+
# 必需依赖体检(D10):缺依赖**不拒绝**派单(worker 照样能干活),但 PM 必须知道证据/spec 层是缺的。
|
|
1204
|
+
# 一行、每次派单只说一次。
|
|
1205
|
+
local dep_issues; dep_issues="$(team_required_dep_issues)"
|
|
1206
|
+
[ -n "$dep_issues" ] && team_warn "依赖缺失(不阻塞派单):$(printf '%s' "$dep_issues" | tr '\n' '; ')"
|
|
1207
|
+
local agent_bin; agent_bin="$(team_agent_bin_path)"
|
|
1208
|
+
# W3:提示词必须写守卫**实际接受**的那条分支(工作树已属于本任务时就是它),并与 state 的
|
|
1209
|
+
# `branch=` 同源;解析名与来源照旧单独打印(R1 的可观测面不变)。
|
|
1210
|
+
local task_branch="${TEAM_CHECKED_BRANCH:-$br_name}" task_branch_src="$br_src"
|
|
1211
|
+
if [ -n "$task_branch" ] && [ "$task_branch" != "$br_name" ]; then
|
|
1212
|
+
task_branch_src="worktree (this task's other slug; resolved name $br_name via $br_src)"
|
|
1213
|
+
fi
|
|
1214
|
+
# P140:解析出的分支名与来源(--branch / 任务书 branch: 行 / 由标题推导)在开窗前可见;--print 同样有。
|
|
1215
|
+
team_info " 分支:$br_name(来源:$br_src)"
|
|
1216
|
+
[ -n "$task_branch" ] && [ "$task_branch" != "$br_name" ] \
|
|
1217
|
+
&& team_info " 工作树实际分支:$task_branch(守卫接受的是它;提示词与 state 都按它写)"
|
|
1218
|
+
local prompt prompt_file agent_cmd inner
|
|
1219
|
+
prompt="$(team_build_prompt "$agent" "$id" "$taskfile" "$wt" "$model" "$sid" "$task_branch" "$task_branch_src")"
|
|
1220
|
+
# 提示词落盘:模板里的 {prompt_file} 用它,排查“到底派了什么”也看它(state/ 已 gitignore)
|
|
1221
|
+
prompt_file="$(team_agent_prompt_file "$agent" "$id")"
|
|
1222
|
+
mkdir -p "$TEAM_STATE_DIR"
|
|
1223
|
+
printf '%s\n' "$prompt" > "$prompt_file"
|
|
1224
|
+
agent_cmd="$(team_agent_launch_cmd "$agent" "$sid" "$wt" "$prompt_file" "$model")"
|
|
1225
|
+
|
|
1226
|
+
# notify 模板坏掉时不阻塞派单,但必须说清楚(否则 worker 回合结束没人知道);
|
|
1227
|
+
# 提示词那侧会用同一个判断把通知段换成「写进报告」(F8)。
|
|
1228
|
+
if [ -n "${TEAM_AGENT_NOTIFY_CMD:-}" ]; then
|
|
1229
|
+
local nre=""
|
|
1230
|
+
if ! nre="$(team_agent_notify_check)"; then
|
|
1231
|
+
team_warn "TEAM_AGENT_NOTIFY_CMD 看起来不可用:$(printf '%s' "$nre" | tr '\n' '; ')(提示词会把通知段换成「写进报告」)"
|
|
1232
|
+
fi
|
|
1233
|
+
fi
|
|
1234
|
+
|
|
1235
|
+
if [ "$printonly" = "1" ]; then
|
|
1236
|
+
printf '=== agent 命令(adapter: %s)===\n' "$(team_agent_adapter_label)"
|
|
1237
|
+
# M40:身份环境单独一行(真窗口里它在 cd 之前执行;这里不许破 `^cd ` 的行契约)
|
|
1238
|
+
printf '身份环境(启动前先执行):%s\n' "$(team_identity_env_prefix "$wt")"
|
|
1239
|
+
printf 'cd %q && %s\n' "$wt" "$agent_cmd"
|
|
1240
|
+
printf ' (命令里的 "$0" = 窗口 harness 以 argv[0] 传入的提示词;模板里写 {prompt} 就是它)\n'
|
|
1241
|
+
printf ' prompt file(模板里的 {prompt_file}):%s\n' "$prompt_file"
|
|
1242
|
+
if [ -n "${TEAM_AGENT_NOTIFY_CMD:-}" ]; then
|
|
1243
|
+
local nfile; nfile="$(team_agent_summary_file "$agent" "$id")"
|
|
1244
|
+
printf ' 回合结束通知(TEAM_AGENT_NOTIFY_CMD;worker 先把摘要写进 %s,再原样跑下面这条):\n %s\n' \
|
|
1245
|
+
"$nfile" "$(team_agent_notify_cmd "$agent" "$sid" "$wt" "$nfile")"
|
|
1246
|
+
fi
|
|
1247
|
+
printf '\n=== 提示词(%s 字) ===\n%s\n' "${#prompt}" "$prompt"
|
|
1248
|
+
return 0
|
|
1249
|
+
fi
|
|
1250
|
+
|
|
1251
|
+
# F5:取字节的时点必须在 **worker 能跑之前**(这时同会话文件还是上一轮结束时的大小)。旧实现把它
|
|
1252
|
+
# 放在 respawn 之后 —— 新一轮已经写进去的字节被算成「上一轮的产出」,上一轮真算出东西的席位会被
|
|
1253
|
+
# 说成 0 bytes(假陈述)。读不到就记空:下一轮的零产出腿要求非空记录,空 = 沉默,不猜。
|
|
1254
|
+
local sid_bytes_at_launch=""
|
|
1255
|
+
sid_bytes_at_launch="$(team_session_bytes "$sid" "$wt" 2>/dev/null || true)"
|
|
1256
|
+
team_tmux_ensure_session
|
|
1257
|
+
# 启动 + 校验(M4.3 B):最多两次(第一次没证据 → 杀窗口重试一次)。
|
|
1258
|
+
# 只有拿到**本轮 nonce** 的启动证据才算「发出去了」;失败则如实报告并杀掉窗口(不留半启动现场)。
|
|
1259
|
+
local marker exitfile nonce inner pid="" attempt=0 exit_code="" observed=0 tailfile
|
|
1260
|
+
marker="$(team_dispatch_spawn_file "$agent")"
|
|
1261
|
+
exitfile="$(team_dispatch_exit_file "$agent")"
|
|
1262
|
+
tailfile="$(team_dispatch_tail_file "$agent")"
|
|
1263
|
+
mkdir -p "$TEAM_STATE_DIR"
|
|
1264
|
+
while [ "$attempt" -lt 2 ] && [ -z "$pid" ]; do
|
|
1265
|
+
attempt=$((attempt + 1))
|
|
1266
|
+
if team_agent_window_exists "$agent"; then
|
|
1267
|
+
if [ "$attempt" = "1" ]; then
|
|
1268
|
+
# P55(遗体复用留证):窗口还在但 pane 已死 = 上一轮死在里面 —— 先把现场落盘再替换
|
|
1269
|
+
# (那次事故「死因不明」的直接原因就是现场没了;探针 P6:kill-window 才真的带走遗体)。
|
|
1270
|
+
if team_agent_pane_dead "$agent"; then
|
|
1271
|
+
local corpse_f; corpse_f="$(team_agent_capture_corpse "$agent" 2>/dev/null || true)"
|
|
1272
|
+
team_warn "窗口 $TEAM_SESSION:$agent 已存在:上一个 pane 已死($(team_agent_pane_evidence "$agent" 2>/dev/null || echo '证据缺失'))→ 替换${corpse_f:+(现场已存 $corpse_f)}"
|
|
1273
|
+
else
|
|
1274
|
+
team_warn "窗口 $TEAM_SESSION:$agent 已存在 → 替换(旧回合会被打断)"
|
|
1275
|
+
fi
|
|
1276
|
+
else team_dim " (重试:窗口还在 → 先杀掉)"; fi
|
|
1277
|
+
team_tmux_kill_window "$TEAM_SESSION:$agent" >/dev/null 2>&1 || true
|
|
1278
|
+
sleep 0.5
|
|
1279
|
+
fi
|
|
1280
|
+
# 每轮换 nonce:证据必须来自这一轮的启动(上一轮留在盘上的不算数)
|
|
1281
|
+
nonce="$(date +%s)-$$-$RANDOM-$attempt"
|
|
1282
|
+
rm -f "$marker" "$exitfile" "$tailfile"
|
|
1283
|
+
# 命令里写死绝对路径 + 短暂等待(窗口 shell 可能刚起、PATH/rc 还没就绪);
|
|
1284
|
+
# 拿到可执行文件后先写下 (nonce, pid),再跑 agent —— 这一行就是「harness 真的执行了」的证据。
|
|
1285
|
+
# agent 返回后**立刻**把 (nonce, $?) 写进退出证据文件,然后才 exec 回 shell:
|
|
1286
|
+
# 证据属于「agent 退了」这个事件(M7.5),不依赖窗口回 shell 的快慢。
|
|
1287
|
+
# M8.2:退出那一刻再自抓一份尾屏(有界重试到非空白)—— CLI 退出后 shell 启动链可能清屏,
|
|
1288
|
+
# 事后再从外面 capture 也许只剩空屏(PM 侧 M8.1 实测过);失败诊断靠它保留 CLI 自己的报错。
|
|
1289
|
+
inner="$(printf '%scd %q\nfor _i in 1 2 3 4 5 6 7 8 9 10; do [ -x %q ] && break; sleep 0.3; done\nprintf "%%s %%s\\n" %s %s > %q\nprintf "\\033[2mteamsmith agent:%s → %s\\033[0m\\n"\n%s\nprintf "%%s %%s\\n" %s "$?" > %q\nif [ -n "${TMUX_PANE:-}" ] && command -v tmux >/dev/null 2>&1; then _n=0; while [ "$_n" -lt 10 ]; do tmux capture-pane -p -t "$TMUX_PANE" -S -200 > %q 2>/dev/null; grep -q "[^[:space:]]" %q && break; _n=$((_n + 1)); sleep 0.1; done; fi\nexec bash' \
|
|
1290
|
+
"$(team_identity_env_prefix "$wt")" "$wt" "$agent_bin" "$(printf '%q' "$nonce")" '$$' "$marker" "$agent" "$id" "$agent_cmd" "$(printf '%q' "$nonce")" "$exitfile" "$(printf '%q' "$tailfile")" "$(printf '%q' "$tailfile")")"
|
|
1291
|
+
# P55(remain-on-exit 的时机是红线):占位命令先持窗 → 设选项并读回 → 才把 pane 交给 harness。
|
|
1292
|
+
# 顺序不能反:harness 先跑时它若秒退,窗口在设选项之前就没了(探针 P1/P3 = 2026-09-22 事故形状)。
|
|
1293
|
+
# respawn-pane 用 argv 形式(不经 shell 解析):harness 原样保留「bash -lc $inner $prompt-as-$0」。
|
|
1294
|
+
tmux new-window -t "$TEAM_SESSION" -n "$agent" -d 'sleep 30' >/dev/null 2>&1 || true
|
|
1295
|
+
if team_agent_window_exists "$agent"; then
|
|
1296
|
+
tmux set-window-option -t "$TEAM_SESSION:$agent" remain-on-exit on >/dev/null 2>&1 || true
|
|
1297
|
+
local roe; roe="$(tmux show-options -w -v -t "$TEAM_SESSION:$agent" remain-on-exit 2>/dev/null || true)"
|
|
1298
|
+
if [ "$roe" = "on" ]; then
|
|
1299
|
+
tmux respawn-pane -k -t "$TEAM_SESSION:$agent" bash -lc "$inner" "$prompt" >/dev/null 2>&1 || true
|
|
1300
|
+
else
|
|
1301
|
+
# 读回失败 = 这一轮的启动作废:窗口留给下一轮的重用分支杀(没有下一轮则由失败路径杀),
|
|
1302
|
+
# 绝不 return —— 否则「重试一次 + 失败诊断」的既有契约会被这条新守卫短路。
|
|
1303
|
+
team_err "窗口 $TEAM_SESSION:$agent 的 remain-on-exit 没设上(读回是 ${roe:-空}):不留遗体的窗口不派单,本轮作废"
|
|
1304
|
+
fi
|
|
1305
|
+
fi
|
|
1306
|
+
pid="$(team_wait_launch_proof "$agent" "$nonce" 2>/dev/null || true)"
|
|
1307
|
+
# 额外观察(不复报成功就完事):启动证据拿到后,agent 可能立刻退出(可执行文件/模型/provider 起不来)。
|
|
1308
|
+
# M8.2:**adapter 路径也看这条事件** —— 裸名字解析失败(exit 127)时 harness 确实跑了,
|
|
1309
|
+
# 但 agent 没跑起来;旧实现只给内置 Pi 路径一句提醒,adapter 连提醒都没有(派单照样 ✓)。
|
|
1310
|
+
if [ -n "$pid" ]; then
|
|
1311
|
+
local alive_sec="${TEAM_DISPATCH_ALIVE_SEC:-1}"
|
|
1312
|
+
case "$alive_sec" in ''|*[!0-9]*) alive_sec=1 ;; esac
|
|
1313
|
+
# 等的是「agent 进程返回」这条事件(上一条证据行),不是「看一眼 pane 忙不忙」的采样;
|
|
1314
|
+
# ALIVE_SEC 现在= 最多等它多久(0 = 不等,直接按「还在跑」报)。
|
|
1315
|
+
[ "$alive_sec" -gt 0 ] && exit_code="$(team_wait_agent_exit "$agent" "$nonce" "$alive_sec" 2>/dev/null || true)"
|
|
1316
|
+
observed=1
|
|
1317
|
+
fi
|
|
1318
|
+
done
|
|
1319
|
+
if [ -z "$pid" ]; then
|
|
1320
|
+
team_err "派单已发出但未能确认启动:${TEAM_DISPATCH_VERIFY_SEC:-8} s 内没等到窗口里的启动证据($marker 里没有本轮 nonce)"
|
|
1321
|
+
# 终态必须已知且是真的:把残留窗口真的杀掉(不是只在文案里说「已杀掉」——
|
|
1322
|
+
# 「状态即承诺」同样适用于失败路径)。
|
|
1323
|
+
if team_agent_window_exists "$agent"; then
|
|
1324
|
+
team_tmux_kill_window "$TEAM_SESSION:$agent" >/dev/null 2>&1 || true
|
|
1325
|
+
team_warn "已重试 1 次,并把窗口 $TEAM_SESSION:$agent 杀掉:不留半启动的现场(roster 会显示「无窗口」)"
|
|
1326
|
+
else
|
|
1327
|
+
team_warn "已重试 1 次;没有留下半启动的窗口(roster 会显示「无窗口」)"
|
|
1328
|
+
fi
|
|
1329
|
+
team_dim " 排查:tmux 里手动跑一次 —— cd $wt 然后跑 dispatch --print 打出的那条命令;看 agent 自己的报错"
|
|
1330
|
+
team_dim " 常见原因:可执行文件/模型/provider 不可用;旧会话楔死(换新会话:--fresh);内存/磁盘不足"
|
|
1331
|
+
team_dim " 重派:$TEAM_CLI dispatch $agent $id $taskfile --fresh"
|
|
1332
|
+
return 1
|
|
1333
|
+
fi
|
|
1334
|
+
|
|
1335
|
+
# 「harness 起来了」≠「agent 跑起来了」(M8.2):自定义 adapter 立刻以非 0 退出就是派单失败。
|
|
1336
|
+
# 为什么只对 adapter 严格:内置 Pi 路径的契约允许启动用例指向短命 CLI(M4.3 B3:假 pi `exit 3`
|
|
1337
|
+
# 仍算派单成立,只如实提醒退出码);而 adapter 模板跑的就是**要干活的 CLI**,它秒退非 0
|
|
1338
|
+
# 只能意味着没跑起来(裸名字 127、参数错、CLI 自己拒绝启动)。
|
|
1339
|
+
# 为什么秒退但 0 不算失败:脚本型 adapter 干完活就退是正常的(下面如实说出来,不假装它还在跑)。
|
|
1340
|
+
if [ -n "$pid" ] && [ -n "${TEAM_AGENT_CMD:-}" ] && [ -n "$exit_code" ] && [ "$exit_code" != "0" ]; then
|
|
1341
|
+
local diag
|
|
1342
|
+
diag="$(team_dispatch_launch_diag "$agent" "$id" "$agent_cmd" "$agent_bin" "$exit_code")"
|
|
1343
|
+
team_err "派单失败:harness 起来了,但 agent 立刻退出了(exit=$exit_code)—— agent 没跑起来"
|
|
1344
|
+
team_dim " 不写任务/分支记录(roster 不会显示它接过这个任务);窗口保留,CLI 自己的报错还在屏幕上"
|
|
1345
|
+
team_err " 诊断(窗口尾屏 + 渲染出的命令 + 解析到的可执行文件)已写入:$diag"
|
|
1346
|
+
team_dim " 手工复现:cd $(printf '%q' "$wt") && $agent_cmd"
|
|
1347
|
+
team_dim " 常见原因:首词不在窗口(登录 bash)的 PATH 里(现在会被解析成绝对路径,除非 TEAM_AGENT_BIN 指向别的名字);CLI 参数/认证被拒"
|
|
1348
|
+
team_dim " 重派:$TEAM_CLI dispatch $agent $id $taskfile"
|
|
1349
|
+
return 1
|
|
1350
|
+
fi
|
|
1351
|
+
|
|
1352
|
+
team_state_set "$agent" model "$model"
|
|
1353
|
+
team_state_set "$agent" model_src "$model_src"
|
|
1354
|
+
team_state_set "$agent" window "$agent"
|
|
1355
|
+
team_state_set "$agent" worktree "$wt"
|
|
1356
|
+
team_state_set "$agent" task "$id"
|
|
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
|
|
1365
|
+
|
|
1366
|
+
# M9.3:`--force` 接管了另一个没结束的任务 —— 审计里留一条(输出里已经写明,这里落盘)
|
|
1367
|
+
if [ -n "${TEAM_DISPATCH_STACK_PREV:-}" ]; then
|
|
1368
|
+
team_wlog "dispatch $agent: 显式覆盖叠任务(${TEAM_DISPATCH_STACK_PREV} 让位给 $id)"
|
|
1369
|
+
fi
|
|
1370
|
+
# P23:change 守卫的 --force 覆盖(规则 B/2/3)逐条落盘(每处一行;输出里已经写明)
|
|
1371
|
+
if [ -n "${TEAM_DISPATCH_AUDIT_LINES:-}" ]; then
|
|
1372
|
+
while IFS= read -r _p23line; do
|
|
1373
|
+
[ -n "$_p23line" ] && team_wlog "$_p23line"
|
|
1374
|
+
done <<< "$TEAM_DISPATCH_AUDIT_LINES"
|
|
1375
|
+
TEAM_DISPATCH_AUDIT_LINES=""
|
|
1376
|
+
fi
|
|
1377
|
+
team_ok "dispatched $id → $TEAM_SESSION:$agent(含启动校验:proof=spawn pid=$pid;provider=$provider model=${model#*/} session=$sid)"
|
|
1378
|
+
# 观察结论也要说出来(不是只报“成功”):内建 Pi 路径下,agent 是「已经退出」还是「还在跑」,
|
|
1379
|
+
# PM 都要拿到**观察到的事实**(退出码来自窗口 harness 写下的事件证据,不是猜的;也不再假设
|
|
1380
|
+
# 「窗口一定已经回到 shell」——那正是 M7.5 里被环境 churn 打脸的那句话)。
|
|
1381
|
+
if [ "$observed" = "1" ]; then
|
|
1382
|
+
if [ -n "$exit_code" ]; then
|
|
1383
|
+
if [ -n "${TEAM_AGENT_CMD:-}" ]; then
|
|
1384
|
+
# adapter 秒退但 0:脚本型 CLI 干完活就退是正常的 —— 如实说出来(不假装它还在跑,也不算失败)
|
|
1385
|
+
team_dim " 窗口里的 agent 已经跑完并退出(exit code 0):$TEAM_CLI roster 会显示「$(team_agent_cli_name) 已退出」"
|
|
1386
|
+
else
|
|
1387
|
+
team_warn "但窗口里的 agent 已经退出(exit code $exit_code):$TEAM_CLI roster 会显示「$(team_agent_cli_name) 已退出」(续跑:$TEAM_CLI resume --agent $agent)"
|
|
1388
|
+
fi
|
|
1389
|
+
else
|
|
1390
|
+
team_dim " 窗口里的 agent 还在跑(${TEAM_DISPATCH_ALIVE_SEC:-1}s 内没等到退出证据)"
|
|
1391
|
+
fi
|
|
1392
|
+
fi
|
|
1393
|
+
team_dim " 旁观:tmux attach -t $TEAM_SESSION | 追问:$TEAM_CLI say $agent \"...\""
|
|
1394
|
+
}
|
|
1395
|
+
|
|
1396
|
+
team_pane_snapshot() { # <target> → pane 内容指纹(用于确认投递真的落到 TUI)
|
|
1397
|
+
team_tmux_target_required "capture-pane" "${1:-}" || return 1
|
|
1398
|
+
tmux capture-pane -p -t "$1" 2>/dev/null | tail -c 400 | cksum | tr -d ' \n'
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
# agent 没在跑时:消息仍然要落到收件箱(durable),但绝不打字(空提示符会当命令执行)
|
|
1402
|
+
team_say_offline() { # <agent> <msg> <原因>
|
|
1403
|
+
local agent="$1" msg="$2" why="$3"
|
|
1404
|
+
team_inbox_append "$agent" pm "(PM 消息,agent 未在跑:$why)$msg"
|
|
1405
|
+
team_warn "say: $agent 没在跑($why)—— 消息已落收件箱($TEAM_DOCS_DIR/inbox/$agent.md)"
|
|
1406
|
+
team_dim " 他起来后(或 $TEAM_CLI resume --agent $agent 续跑后)会读到;要立刻投递先让他跑起来"
|
|
1407
|
+
return 0
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1410
|
+
# 收件人必须是名册里的 agent,或者特殊收件人 pm(PM 自己的收件箱)。
|
|
1411
|
+
# 为什么:say devv 会把消息写进 inbox/devv.md,而那个名字从来没窗口、没人读 ——
|
|
1412
|
+
# 打错一个字母就等于消息静默蒸发(M6.3 F18)。--any 是显式越权:允许,但必须留痕。
|
|
1413
|
+
team_require_recipient() { # <recipient> <是否 --any> <命令名>
|
|
1414
|
+
local r="$1" any="${2:-0}" what="${3:-say}"
|
|
1415
|
+
[ -n "$r" ] || return 0
|
|
1416
|
+
[ "$r" = "pm" ] && return 0
|
|
1417
|
+
team_agent_known "$r" && return 0
|
|
1418
|
+
if [ "$any" = "1" ]; then
|
|
1419
|
+
printf '%s %s -> %s(非名册收件人,--any 强制)\n' "$(team_timestamp)" "$what" "$r" >> "$(team_state_dir)/inbox-unknown.log"
|
|
1420
|
+
team_warn "$what:$r 不在名册里 —— --any 已按要求投递,并记入 state/inbox-unknown.log"
|
|
1421
|
+
return 0
|
|
1422
|
+
fi
|
|
1423
|
+
team_err "$what:收件人 '$r' 不在名册里(没有它的窗口,也没有人会读它的收件箱 → 消息会变成死信)"
|
|
1424
|
+
team_dim " 名册:$(team_agents | tr '\n' ' ')| PM 自己的收件箱:pm" >&2
|
|
1425
|
+
team_dim " 确认要投给这个名字:$TEAM_CLI $what $r --any \"...\"(越权投递会记进 state/inbox-unknown.log)" >&2
|
|
1426
|
+
return 1
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
team_cmd_say() {
|
|
1430
|
+
local agent="" msg="" verify=1 any=0 now=0
|
|
1431
|
+
while [ $# -gt 0 ]; do
|
|
1432
|
+
case "$1" in
|
|
1433
|
+
--no-verify) verify=0; shift ;;
|
|
1434
|
+
--any) any=1; shift ;;
|
|
1435
|
+
--now) now=1; shift ;;
|
|
1436
|
+
-*) team_usage_die "say: 未知参数 $1" ;;
|
|
1437
|
+
*) if [ -z "$agent" ]; then agent="$1"; elif [ -z "$msg" ]; then msg="$1"; else msg="$msg $1"; fi; shift ;;
|
|
1438
|
+
esac
|
|
1439
|
+
done
|
|
1440
|
+
[ -n "$agent" ] && [ -n "$msg" ] || team_usage_die "say <agent> <单行消息> [--no-verify] [--any] [--now]"
|
|
1441
|
+
case "$msg" in *$'\n'*) team_die "say 只能发单行:多行请写进文件,然后让 agent 去读" ;; esac
|
|
1442
|
+
team_require_recipient "$agent" "$any" say || return 1
|
|
1443
|
+
local w; w="$(team_state_get "$agent" window "$agent")"
|
|
1444
|
+
local target="$TEAM_SESSION:$w"
|
|
1445
|
+
# M30 · pi 通道不经过 tmux:有活的收件箱监视器(inbox-watch 扩展)时,窗口/pane 的检查都不必要
|
|
1446
|
+
# —— 「pi 通道零 tmux 调用」是 M30 的验收判据之一(消息写 durable 收件箱 + spool,由扩展唤醒)。
|
|
1447
|
+
if ! team_inbox_watch_route "$target" >/dev/null 2>&1; then
|
|
1448
|
+
team_tmux_has_window "$TEAM_SESSION" "$w" \
|
|
1449
|
+
|| { team_say_offline "$agent" "$msg" "窗口 $TEAM_SESSION:$w 不在"; return 0; }
|
|
1450
|
+
# P55(投递换道):死 pane 不是投递目标 —— send-keys 返回 0 但文字落进虚空(探针 P5),
|
|
1451
|
+
# 「提示框非空确认送达」永远等不到(画面不再变)。消息走收件箱,输出点名座位已死与退出证据。
|
|
1452
|
+
if team_agent_pane_dead "$agent"; then
|
|
1453
|
+
local ev; ev="$(team_agent_pane_evidence "$agent" 2>/dev/null || echo '证据未知')"
|
|
1454
|
+
team_inbox_append "$agent" pm "(PM 消息,座位已死:$ev)$msg"
|
|
1455
|
+
team_warn "say: $agent 的 pane 已死($ev)—— 没有按任何键;消息已落 $TEAM_DOCS_DIR/inbox/$agent.md"
|
|
1456
|
+
team_dim " 现场:$TEAM_CLI status <ID>(或 tmux capture-pane -p -S - -t $target);恢复:$TEAM_CLI resume --agent $agent(会先抓现场再替换遗体)"
|
|
1457
|
+
return 0
|
|
1458
|
+
fi
|
|
1459
|
+
# 安全:空提示符时把消息 send-keys 进去会被 shell 当命令执行
|
|
1460
|
+
if team_is_shell_cmd "$(team_pane_cmd "$TEAM_SESSION:$w")" && ! team_pane_busy "$TEAM_SESSION:$w"; then
|
|
1461
|
+
team_say_offline "$agent" "$msg" "$(team_agent_cli_name) 已退出(空提示符)"
|
|
1462
|
+
return 0
|
|
1463
|
+
fi
|
|
1464
|
+
fi
|
|
1465
|
+
|
|
1466
|
+
# 投递一律走守卫(delivery-guard):输入框里有草稿 → 不写一个键,消息进 state/outbox/ 排队。
|
|
1467
|
+
# --now 是人的显式逃生门(故意重建旧行为,留审计);--no-verify 保留旧语义。
|
|
1468
|
+
local sargs=()
|
|
1469
|
+
[ "$verify" = "1" ] || sargs+=(--no-verify)
|
|
1470
|
+
[ "$now" = "1" ] && sargs+=(--now)
|
|
1471
|
+
team_send_guarded "$target" "$msg" say --from pm --inbox "$agent" ${sargs[@]+"${sargs[@]}"}
|
|
1472
|
+
case "$TEAM_SEND_OUTCOME" in
|
|
1473
|
+
delivered)
|
|
1474
|
+
team_ok "said to $target: $msg(已确认送达)"
|
|
1475
|
+
return 0 ;;
|
|
1476
|
+
watched)
|
|
1477
|
+
# M30 · pi 监视通道:durable 收件箱行已写,spool 指针已落;会话里的扩展读到就唤醒
|
|
1478
|
+
team_ok "said to $target: $msg(pi 监视通道:已写收件箱 $TEAM_DOCS_DIR/inbox/$agent.md + 唤醒指针;输入框零按键)"
|
|
1479
|
+
return 0 ;;
|
|
1480
|
+
queued)
|
|
1481
|
+
# 契约:排队 ≠ 送达 —— 输出里只许有 queued,绝不能写「已确认送达」
|
|
1482
|
+
team_ok "queued for $target: $msg(目标输入框里有草稿:没有写任何键;条目已入 state/outbox/,清空后自动投递)"
|
|
1483
|
+
team_dim " 原因/条目:$TEAM_CLI outbox list | 投递未确认的兜底:消息已在 $TEAM_DOCS_DIR/inbox/$agent.md"
|
|
1484
|
+
return 0 ;;
|
|
1485
|
+
held)
|
|
1486
|
+
# delivery-truth D1/D2:geometry-untrusted / queue-stalled —— 一个键都没发,报 held + 原因 +
|
|
1487
|
+
# durable 条目 + 恢复命令并非零退出(“退出 0 + 永不兑现的承诺”就是本 change 要消灭的假绿)。
|
|
1488
|
+
team_err "held for $target: $msg(reason=${TEAM_SEND_REASON:--}:目标框的几何/进展无法可信确认,没有写任何键)"
|
|
1489
|
+
team_dim " 条目:$(basename "${TEAM_SEND_ENTRY:--}")|durable 全文:$(team_outbox_durable_path "${TEAM_SEND_ENTRY:--}" 2>/dev/null || printf '%s' -)(payload 与条目头未改)|原因:$TEAM_CLI outbox list |恢复:$(team_outbox_recovery_hint "${TEAM_SEND_REASON:--}")"
|
|
1490
|
+
return 1 ;;
|
|
1491
|
+
forced)
|
|
1492
|
+
team_ok "said to $target: $msg(--now:跳过守卫直投,记入 outbox/forced.log)"
|
|
1493
|
+
return 0 ;;
|
|
1494
|
+
unknown-sent)
|
|
1495
|
+
team_ok "said to $target: $msg(输入框形状未知:按旧行为投递)"
|
|
1496
|
+
return 0 ;;
|
|
1497
|
+
unknown-failed)
|
|
1498
|
+
team_inbox_append "$agent" pm "(PM 消息,投递未确认)$msg"
|
|
1499
|
+
team_err "投递未确认:$target(输入框形状未知且 pane 无变化;消息已写入收件箱 $TEAM_DOCS_DIR/inbox/$agent.md)"
|
|
1500
|
+
return 1 ;;
|
|
1501
|
+
*)
|
|
1502
|
+
team_say_offline "$agent" "$msg" "$(team_agent_cli_name) 已退出(空提示符)"
|
|
1503
|
+
return 0 ;;
|
|
1504
|
+
esac
|
|
1505
|
+
}
|
|
1506
|
+
|
|
1507
|
+
team_inbox_append() { # <agent> <tag> <msg> [<sender>]
|
|
1508
|
+
local dir; dir="$(team_inbox_dir)"
|
|
1509
|
+
mkdir -p "$dir"
|
|
1510
|
+
# P82:第 4 参可选 = **发送者**(notify 传解析出来的发送者,收件人只当文件名);
|
|
1511
|
+
# say/draft/pulse 不传,沿用「owner 标签」(它们另有 --from/标签语义,本次不动)。
|
|
1512
|
+
printf -- '- %s [%s] agent:%s · %s\n' "$(team_timestamp)" "$2" "${4:-$1}" "$3" >> "$dir/$1.md"
|
|
1513
|
+
}
|
|
1514
|
+
|
|
1515
|
+
# notify 的去重键:内容 + 长度(同一份通知在 TEAM_NOTIFY_DEDUP_SEC 内只入队/投递一次)。
|
|
1516
|
+
# 扩展走的是它自己的键(<agent>|<tag>|<summary>|<len>:<hash>),两边都进同一个队列条目。
|
|
1517
|
+
team_notify_dedup_key() { # <agent> <msg>
|
|
1518
|
+
local len sum
|
|
1519
|
+
len="$(printf '%s' "$2" | wc -c | tr -d ' ')"
|
|
1520
|
+
sum="$(printf '%s' "$2" | cksum | awk '{print $1}')"
|
|
1521
|
+
printf 'notify|%s|%s:%s\n' "$1" "$len" "$sum"
|
|
1522
|
+
}
|
|
1523
|
+
|
|
1524
|
+
# P160 F3 · 任务标识的证据:<ID> 必须在 state/<sender>.env 的 task=、看板行或任务书里真的存在。
|
|
1525
|
+
# 席位名(agent/<席位> 这类分支的后缀)不是任务 —— 没有证据就什么都不盖(不编造)。
|
|
1526
|
+
team_notify_task_proven() { # <sender> <id> → 0 = 这个 ID 有任务证据
|
|
1527
|
+
local sender="$1" id="$2" cur=""
|
|
1528
|
+
[ -n "$id" ] || return 1
|
|
1529
|
+
cur="$(team_state_get "$sender" task '' 2>/dev/null || true)"
|
|
1530
|
+
if [ -n "$cur" ] && [ "$cur" = "$id" ]; then return 0; fi
|
|
1531
|
+
if team_board_has "$id"; then return 0; fi
|
|
1532
|
+
if [ -n "$(team_task_briefs "$id")" ]; then return 0; fi
|
|
1533
|
+
return 1
|
|
1534
|
+
}
|
|
1535
|
+
|
|
1536
|
+
# R2/P160 · 发送方工作树里的修订标识(<ID> 取自分支,tip 取自 HEAD):
|
|
1537
|
+
# 只有**能证明**是任务分支才盖:分支形如 task/<ID>-…(agent/* 与其它分支没有任务语义,一律不盖),
|
|
1538
|
+
# 且 <ID> 在 state/<sender>.env 的 task=、看板行或任务书里存在;推不出来就什么都不写。
|
|
1539
|
+
# 绝不编造:工作树外的手工 notify 没有标识,不是「按收件人猜一个」。
|
|
1540
|
+
# P160 F2:tip = HEAD 的**前 12 个十六进制字符**,工具自己截 —— 不用 `--short`(它服从 core.abbrev
|
|
1541
|
+
# 与对象数,同一 HEAD 会在 CLI 与扩展两处盖出不同拼写)。接收方不需要 checkout:reviews/<ID>.md 里记的
|
|
1542
|
+
# HEAD 与 tip **互为前缀**(两边指向同一个 revision)就算这个修订已经判过(`team review` 今天写 9 位,
|
|
1543
|
+
# 12 位的 wire 形状让这个判定不受 Git 设置影响),见 references/protocol.md 与 change 的 notify-and-inbox 规格。
|
|
1544
|
+
team_notify_rev_stamp() { # <sender> → "task=<ID> tip=<12-hex>" | 空
|
|
1545
|
+
local sender="${1:-}" wt="" branch="" task="" id="" tip=""
|
|
1546
|
+
case "$sender" in
|
|
1547
|
+
""|-) return 0 ;;
|
|
1548
|
+
pm) wt="$TEAM_MAIN_ROOT" ;;
|
|
1549
|
+
*) wt="$TEAM_MAIN_ROOT/$TEAM_WORKTREES_DIR/$sender" ;;
|
|
1550
|
+
esac
|
|
1551
|
+
[ -d "$wt" ] || return 0
|
|
1552
|
+
branch="$(team_worktree_branch "$wt" 2>/dev/null || true)"
|
|
1553
|
+
case "$branch" in
|
|
1554
|
+
task/*) ;;
|
|
1555
|
+
*) return 0 ;;
|
|
1556
|
+
esac
|
|
1557
|
+
task="${branch#task/}"
|
|
1558
|
+
id="${task%%-*}"
|
|
1559
|
+
team_notify_task_proven "$sender" "$id" || return 0
|
|
1560
|
+
tip="$(git -C "$wt" rev-parse HEAD 2>/dev/null | cut -c1-12 || true)"
|
|
1561
|
+
[ -n "$id" ] && [ -n "$tip" ] && printf 'task=%s tip=%s\n' "$id" "$tip"
|
|
1562
|
+
return 0
|
|
1563
|
+
}
|
|
1564
|
+
|
|
1565
|
+
team_cmd_notify() {
|
|
1566
|
+
local from_file="" msg="" agent="" any=0 claim="" claim_set=0 have_msg=0
|
|
1567
|
+
# P82:--from <名字> 是**发送者**的显式声明(收件人永远只是收件人)。参数顺序自由,
|
|
1568
|
+
# 其余位置参数拼成摘要(保持「notify <收件人> <单行消息>」的老形状)。
|
|
1569
|
+
while [ $# -gt 0 ]; do
|
|
1570
|
+
case "$1" in
|
|
1571
|
+
--any) any=1; shift ;;
|
|
1572
|
+
--from) [ $# -ge 2 ] || team_usage_die "notify --from 需要发送者名字"; claim="$2"; claim_set=1; shift 2 ;;
|
|
1573
|
+
--from=*) claim="${1#*=}"; claim_set=1; shift ;;
|
|
1574
|
+
--from-file) [ $# -ge 2 ] || team_usage_die "notify --from-file 需要摘要文件路径"; from_file="$2"; shift 2 ;;
|
|
1575
|
+
--from-file=*) from_file="${1#*=}"; shift ;;
|
|
1576
|
+
-*) team_usage_die "notify: 未知参数 $1" ;;
|
|
1577
|
+
*) if [ -z "$agent" ]; then agent="$1"; else msg="${msg:+$msg }$1"; have_msg=1; fi; shift ;;
|
|
1578
|
+
esac
|
|
1579
|
+
done
|
|
1580
|
+
[ -n "$agent" ] || team_usage_die "notify <agent> <单行消息> | notify <agent> --from-file <摘要文件> [--from <发送者>]"
|
|
1581
|
+
# 名字是一个词(席位名/目录名):空白/换行会把 `agent:<名字> ·` 这行弄成两行(账本行的形状要守得住)
|
|
1582
|
+
if [ "$claim_set" = "1" ]; then
|
|
1583
|
+
case "$claim" in
|
|
1584
|
+
"") team_usage_die "notify --from 的发送者名字不能为空" ;;
|
|
1585
|
+
*[[:space:]]*) team_usage_die "notify --from 的发送者名字里有空白('$claim'):名字是一个词,摘要请走 --from-file" ;;
|
|
1586
|
+
esac
|
|
1587
|
+
fi
|
|
1588
|
+
# 摘要只有一个来源:位置文本与 --from-file 同时给 = 含糊输入,拒绝(不静默挑一个)
|
|
1589
|
+
if [ -n "$from_file" ] && [ "$have_msg" = "1" ]; then
|
|
1590
|
+
team_usage_die "notify:位置摘要与 --from-file 不能同时给(摘要只有一个来源,请二选一)"
|
|
1591
|
+
fi
|
|
1592
|
+
# 发送者先解析(fail closed):未解析就在这里停住 —— 收件箱行、knock、outbox 条目一个都不写。
|
|
1593
|
+
local sender; sender="$(team_sender_resolve "$claim")" || return 1
|
|
1594
|
+
[ -n "$sender" ] || return 1
|
|
1595
|
+
# 摘要始终是**数据**:--from-file 从文件读(worker 的文本不经过 shell);两种路径都归一化成单行,
|
|
1596
|
+
# 但除换行/回车/尾部空白外**逐字节保留**(引号、$、反引号、{} 都原样进收件箱)。
|
|
1597
|
+
if [ -n "$from_file" ]; then
|
|
1598
|
+
[ -f "$from_file" ] || team_die "notify --from-file:文件不存在($from_file)——worker 要先把摘要写进去"
|
|
1599
|
+
msg="$(team_one_line "$(cat "$from_file")")"
|
|
1600
|
+
else
|
|
1601
|
+
[ "$have_msg" = "1" ] || team_usage_die "notify <agent> <单行消息> | notify <agent> --from-file <摘要文件> [--from <发送者>]"
|
|
1602
|
+
msg="$(team_one_line "$msg")"
|
|
1603
|
+
fi
|
|
1604
|
+
if [ -z "$(team_trim "$msg")" ]; then
|
|
1605
|
+
if [ -n "$from_file" ]; then team_die "notify --from-file:摘要文件是空的($from_file)"
|
|
1606
|
+
else team_die "notify:摘要不能为空(收到空参数;如果用 \"\$(cat <摘要文件>)\" 取摘要,先确认那个文件写好且非空)"; fi
|
|
1607
|
+
fi
|
|
1608
|
+
team_require_recipient "$agent" "$any" notify || return 1
|
|
1609
|
+
# R2:能证明就带修订标识(inbox 行与 knock 载荷同一个后缀;摘要本身逐字节不变)
|
|
1610
|
+
local stamp="" revsuffix=""
|
|
1611
|
+
stamp="$(team_notify_rev_stamp "$sender")"
|
|
1612
|
+
[ -n "$stamp" ] && revsuffix=" · $stamp"
|
|
1613
|
+
local knock_payload="[manual] agent:$sender · $msg$revsuffix"
|
|
1614
|
+
# P82:发送者进 durable 收件箱行(第 4 参),收件人仍是文件名
|
|
1615
|
+
# delivery-truth D3(P147):durable 写入是**声明的前提** —— 写不进去就在这里非零退出,
|
|
1616
|
+
# 不敲门、不写任何 inbox-written 声明(否则 wake 会指向一个不存在的文件)。
|
|
1617
|
+
team_inbox_append "$agent" manual "$msg$revsuffix" "$sender" || {
|
|
1618
|
+
team_err "notify:收件箱行写不进去($TEAM_DOCS_DIR/inbox/$agent.md)—— 不敲门、不声明已写(退出非零)"
|
|
1619
|
+
return 1
|
|
1620
|
+
}
|
|
1621
|
+
local target="$TEAM_SESSION:$TEAM_PM_WINDOW"
|
|
1622
|
+
local knock_rc=0
|
|
1623
|
+
# M30 · pi 通道优先:目标有**活的**收件箱监视器时,敲门交给它(注册里的 pid+cwd 就是「PM 会话活着」
|
|
1624
|
+
# 的证据,比 tmux/pane 启发式直接),而且这条链不需要 tmux、不碰输入框。
|
|
1625
|
+
# delivery-truth D3:--inbox-written <recipient> = 上面写的就是收件人的 durable 文件;wake 的
|
|
1626
|
+
# 全文路径必须指同它(旧实现写死 pm → 收件人 dev 时 wake 指向不存在的 pm.md)。
|
|
1627
|
+
if [ "$TEAM_NOTIFY_TMUX" = "1" ] && team_inbox_watch_route "$target" >/dev/null 2>&1; then
|
|
1628
|
+
team_send_guarded "$target" "$knock_payload" knock --from "$sender" \
|
|
1629
|
+
--dedup "$(team_notify_dedup_key "$agent" "$msg$revsuffix")" --inbox-written "$agent"
|
|
1630
|
+
case "$TEAM_SEND_OUTCOME" in
|
|
1631
|
+
watched) team_dim " pi 监视通道:收件箱已写,会话里的监视扩展负责唤醒(输入框零按键)" ;;
|
|
1632
|
+
queued) team_dim " pi 监视通道投递没落地(条目入队):$TEAM_CLI outbox list" ;;
|
|
1633
|
+
held) knock_rc=1; team_warn " 敲门被阻碍(reason=${TEAM_SEND_REASON:--}):held/,唤醒未发;消息仍在 docs/team/inbox/$agent.md" ;;
|
|
1634
|
+
duplicate) team_dim " duplicate:同一份通知在 ${TEAM_NOTIFY_DEDUP_SEC:-20}s 内已经投过(没有重复入队)" ;;
|
|
1635
|
+
offline|unknown-failed) team_warn "敲门没落地(pi 通道写不进去):消息只落收件箱" ;;
|
|
1636
|
+
esac
|
|
1637
|
+
elif [ "$TEAM_NOTIFY_TMUX" = "1" ] && team_have_cmd tmux && [ -n "${TMUX:-}" ] \
|
|
1638
|
+
&& team_pm_alive; then
|
|
1639
|
+
# 只给「正在跑 pi 的 PM」打字:PM 没在跑时写进 shell 会被当命令执行。
|
|
1640
|
+
# 敲门也走投递守卫:输入框里有草稿 → 入队,草稿不动(规格 notify-and-inbox 的 dirty-PM 场景)
|
|
1641
|
+
team_send_guarded "$target" "$knock_payload" knock --from "$sender" \
|
|
1642
|
+
--dedup "$(team_notify_dedup_key "$agent" "$msg$revsuffix")" --inbox-written "$agent"
|
|
1643
|
+
case "$TEAM_SEND_OUTCOME" in
|
|
1644
|
+
queued) team_dim " PM 输入框里有草稿:敲门入队($TEAM_CLI outbox list),清空后自动投递" ;;
|
|
1645
|
+
held) knock_rc=1; team_warn " 敲门被阻碍(reason=${TEAM_SEND_REASON:--}):held/,唤醒未发;消息仍在 docs/team/inbox/$agent.md" ;;
|
|
1646
|
+
duplicate) team_dim " duplicate:同一份通知在 ${TEAM_NOTIFY_DEDUP_SEC:-20}s 内已经投过(没有重复入队)" ;;
|
|
1647
|
+
offline|unknown-failed) team_warn "敲门没落地(PM 窗口不可投):消息只落收件箱" ;;
|
|
1648
|
+
esac
|
|
1649
|
+
elif [ "$TEAM_NOTIFY_TMUX" = "1" ] && [ -n "${TMUX:-}" ] && team_have_cmd tmux && ! team_pm_alive; then
|
|
1650
|
+
team_warn "PM 不在运行:消息只落收件箱(pulse 会把 PM 拉起后读到)"
|
|
1651
|
+
elif [ "$TEAM_NOTIFY_TMUX" = "1" ] && { [ -z "${TMUX:-}" ] || ! team_have_cmd tmux; }; then
|
|
1652
|
+
# V7-F6:敲门依赖 TMUX 环境变量——不设就静默整条跳过是不行的;明说,收件箱记录不受影响
|
|
1653
|
+
team_warn "不在 tmux 会话里(TMUX 未设置):敲门不试、不入队,消息只落收件箱"
|
|
1654
|
+
fi
|
|
1655
|
+
team_ok "notified pm: $msg"
|
|
1656
|
+
return "$knock_rc"
|
|
1657
|
+
}
|
|
1658
|
+
|
|
1659
|
+
team_cmd_teardown() {
|
|
1660
|
+
local agent="" all=0 purge=0 force=0 register=0 fp=""
|
|
1661
|
+
while [ $# -gt 0 ]; do
|
|
1662
|
+
case "$1" in
|
|
1663
|
+
--agent) agent="${2:?}"; shift 2 ;;
|
|
1664
|
+
--all) all=1; shift ;;
|
|
1665
|
+
--purge) purge=1; shift ;;
|
|
1666
|
+
--force) force=1; shift ;;
|
|
1667
|
+
--register) register=1; shift ;;
|
|
1668
|
+
--fingerprint) fp="${2:?--fingerprint 需要 sha256}"; shift 2 ;;
|
|
1669
|
+
--fingerprint=*) fp="${1#*=}"; shift ;;
|
|
1670
|
+
*) team_usage_die "teardown: 未知参数 $1" ;;
|
|
1671
|
+
esac
|
|
1672
|
+
done
|
|
1673
|
+
if [ "$register" = "1" ] && [ "$all" = "1" ]; then
|
|
1674
|
+
team_usage_die "teardown: --all 不能和 --register 一起用(一次只从名册移除一个席位)"
|
|
1675
|
+
fi
|
|
1676
|
+
local targets=()
|
|
1677
|
+
if [ "$all" = "1" ]; then mapfile -t targets < <(team_agents); else
|
|
1678
|
+
[ -n "$agent" ] || team_usage_die "teardown --agent <a> | --all [--purge] [--force]"
|
|
1679
|
+
targets=("$agent")
|
|
1680
|
+
fi
|
|
1681
|
+
# P99/R2:--register 先缩名册(审计写入器),再走今天的窗口/state/worktree 清理;
|
|
1682
|
+
# 名册里没有这个席位就 exit 5、什么都不动。不带旗标时名册逐字节不变(今天的行为是默认)。
|
|
1683
|
+
if [ "$register" = "1" ]; then
|
|
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
|
|
1689
|
+
for a in "${targets[@]}"; do
|
|
1690
|
+
w="$(team_state_get "$a" window "$a")"
|
|
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
|
|
1706
|
+
done
|
|
1707
|
+
[ "$purge" != "1" ] && team_dim "worktree 仍保留(加 --purge 删除);分支保留,需要时 git branch -d"
|
|
1708
|
+
return 0
|
|
1709
|
+
}
|