teamsmith 0.1.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -7
- package/package.json +1 -1
- package/skills/teamsmith/CHANGELOG.md +67 -0
- package/skills/teamsmith/SKILL.md +26 -8
- package/skills/teamsmith/extension/team-notify.ts +37 -6
- package/skills/teamsmith/extension/team.ts +438 -0
- package/skills/teamsmith/references/agent-adapters.md +7 -7
- package/skills/teamsmith/references/config.md +65 -18
- package/skills/teamsmith/references/migration.md +220 -34
- package/skills/teamsmith/references/protocol.md +250 -25
- package/skills/teamsmith/references/troubleshooting.md +124 -7
- package/skills/teamsmith/references/workflows.md +66 -20
- package/skills/teamsmith/scripts/lib/cmd-agents.sh +525 -90
- package/skills/teamsmith/scripts/lib/cmd-bootstrap.sh +71 -10
- package/skills/teamsmith/scripts/lib/cmd-config.sh +562 -128
- package/skills/teamsmith/scripts/lib/cmd-death.sh +2 -15
- package/skills/teamsmith/scripts/lib/cmd-docs.sh +6 -3
- package/skills/teamsmith/scripts/lib/cmd-draft.sh +4 -4
- package/skills/teamsmith/scripts/lib/cmd-help.sh +677 -0
- package/skills/teamsmith/scripts/lib/cmd-init.sh +157 -5
- package/skills/teamsmith/scripts/lib/cmd-interrupt.sh +461 -0
- package/skills/teamsmith/scripts/lib/cmd-meeting.sh +2 -25
- package/skills/teamsmith/scripts/lib/cmd-project.sh +149 -105
- package/skills/teamsmith/scripts/lib/cmd-reap.sh +277 -0
- package/skills/teamsmith/scripts/lib/cmd-reply.sh +96 -0
- package/skills/teamsmith/scripts/lib/cmd-review.sh +188 -40
- package/skills/teamsmith/scripts/lib/cmd-status.sh +268 -30
- package/skills/teamsmith/scripts/lib/cmd-update.sh +36 -7
- package/skills/teamsmith/scripts/lib/cmd-watch.sh +634 -54
- package/skills/teamsmith/scripts/lib/common.sh +1560 -109
- package/skills/teamsmith/scripts/lib/gate-lock.sh +544 -0
- package/skills/teamsmith/scripts/monitor.mjs +34 -3
- package/skills/teamsmith/scripts/panel/README.md +22 -11
- package/skills/teamsmith/scripts/panel/draft-send.sh +11 -1
- package/skills/teamsmith/scripts/panel/panel.js +226 -224
- package/skills/teamsmith/scripts/panel/src/App.tsx +478 -184
- package/skills/teamsmith/scripts/panel/src/clipboard.ts +11 -5
- package/skills/teamsmith/scripts/panel/src/compose.ts +6 -3
- package/skills/teamsmith/scripts/panel/src/data.ts +95 -7
- package/skills/teamsmith/scripts/panel/src/layout.ts +703 -152
- package/skills/teamsmith/scripts/panel/src/main.tsx +129 -19
- package/skills/teamsmith/scripts/panel/src/settings.ts +1 -1
- package/skills/teamsmith/scripts/panel/src/strings/en.ts +76 -31
- package/skills/teamsmith/scripts/panel/src/strings/zh.ts +78 -33
- package/skills/teamsmith/scripts/panel/src/types.ts +204 -17
- package/skills/teamsmith/scripts/replies.mjs +896 -0
- package/skills/teamsmith/scripts/shim/tmux +18 -0
- package/skills/teamsmith/scripts/strings/commands.tsv +86 -0
- package/skills/teamsmith/scripts/strings/help.en.tsv +503 -0
- package/skills/teamsmith/scripts/strings/help.zh.tsv +489 -0
- package/skills/teamsmith/scripts/team +20 -6
- package/skills/teamsmith/templates/AGENTS.section.md.tmpl +23 -3
- package/skills/teamsmith/templates/BOARD.md.tmpl +2 -2
- package/skills/teamsmith/templates/OWNERSHIP.md.tmpl +7 -3
- package/skills/teamsmith/templates/PROTOCOL.md.tmpl +17 -0
- package/skills/teamsmith/templates/config.sh.tmpl +29 -5
- package/skills/teamsmith/templates/memory-seed.md.tmpl +3 -0
- package/skills/teamsmith/templates/pm-prompt.md.tmpl +41 -1
- package/skills/teamsmith/templates/report.md.tmpl +12 -0
- package/skills/teamsmith/templates/task.md.tmpl +4 -0
- package/skills/teamsmith/tests/bg-ledger-harness.mjs +464 -40
- package/skills/teamsmith/tests/bg-ledger.sh +168 -10
- package/skills/teamsmith/tests/checkout-shape-probe.sh +3 -1
- package/skills/teamsmith/tests/config-cli.sh +320 -300
- package/skills/teamsmith/tests/death-cause.sh +5 -2
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/scenario.sh +7 -1
- package/skills/teamsmith/tests/fixtures/p287/lint-good.sh.in +3 -0
- package/skills/teamsmith/tests/fixtures/p287/lint-hardcoded.sh.in +3 -0
- package/skills/teamsmith/tests/fixtures/p287/lint-no-ns.sh.in +3 -0
- package/skills/teamsmith/tests/fixtures/p55/flip-p49.sh +18 -6
- package/skills/teamsmith/tests/flip-m33.sh +5 -3
- package/skills/teamsmith/tests/flip-m37.sh +4 -1
- package/skills/teamsmith/tests/flip-m4.3.sh +4 -1
- package/skills/teamsmith/tests/flip-m6.3.sh +4 -1
- package/skills/teamsmith/tests/flip-m6.5.sh +4 -1
- package/skills/teamsmith/tests/flip-m7.2.sh +4 -1
- package/skills/teamsmith/tests/flip-p158.sh +2 -1
- package/skills/teamsmith/tests/flip-p210.sh +4 -1
- package/skills/teamsmith/tests/flip-p217.sh +4 -1
- package/skills/teamsmith/tests/flip-p287-lock.sh +342 -0
- package/skills/teamsmith/tests/flip-p287-name.sh +279 -0
- package/skills/teamsmith/tests/flip-p304-read-side.sh +98 -0
- package/skills/teamsmith/tests/flip-p308-skip-not-pass.sh +151 -0
- package/skills/teamsmith/tests/flip-p309-p162-deep.sh +122 -0
- package/skills/teamsmith/tests/flip-p310-lock.sh +216 -0
- package/skills/teamsmith/tests/flip-p310-socket.sh +125 -0
- package/skills/teamsmith/tests/help-surface.sh +1664 -0
- package/skills/teamsmith/tests/install-shape.sh +283 -22
- package/skills/teamsmith/tests/key-replies-pty.sh +374 -0
- package/skills/teamsmith/tests/key-replies-ui.sh +325 -0
- package/skills/teamsmith/tests/key-replies.sh +1314 -0
- package/skills/teamsmith/tests/ledger-ban.sh +9 -8
- package/skills/teamsmith/tests/ledger-claim.sh +248 -0
- package/skills/teamsmith/tests/lib/bounded-spin.sh +90 -0
- package/skills/teamsmith/tests/lib/model-policy.sh +30 -0
- package/skills/teamsmith/tests/lib/model-routing-boundary.sh +420 -0
- package/skills/teamsmith/tests/lib/model-routing-expansion.sh +155 -0
- package/skills/teamsmith/tests/lib/model-routing-flips.py +187 -0
- package/skills/teamsmith/tests/lib/model-routing-roles.sh +250 -0
- package/skills/teamsmith/tests/lib/proc-io.sh +103 -0
- package/skills/teamsmith/tests/lib/reply-fixture.sh +367 -0
- package/skills/teamsmith/tests/lib/section-guard.sh +258 -13
- package/skills/teamsmith/tests/lib/tmp-root.sh +139 -27
- package/skills/teamsmith/tests/lib/tmux-cap.sh +10 -1
- package/skills/teamsmith/tests/lib/tmux-iso.sh +39 -13
- package/skills/teamsmith/tests/loop-inventory.tsv +59 -47
- package/skills/teamsmith/tests/panel-b2.sh +107 -4
- package/skills/teamsmith/tests/panel-b3-stub.sh +139 -4
- package/skills/teamsmith/tests/panel-b3.sh +189 -29
- package/skills/teamsmith/tests/panel-choices.sh +81 -63
- package/skills/teamsmith/tests/panel-cpu.sh +3 -2
- package/skills/teamsmith/tests/panel-knobs.sh +7 -1
- package/skills/teamsmith/tests/panel-p21.sh +445 -241
- package/skills/teamsmith/tests/panel-snapshots.sh +41 -225
- package/skills/teamsmith/tests/panel-strings.mjs +33 -18
- package/skills/teamsmith/tests/perf.sh +122 -31
- package/skills/teamsmith/tests/pm-box-real.sh +1 -1
- package/skills/teamsmith/tests/pulse-nudge-key.sh +1 -1
- package/skills/teamsmith/tests/routes.sh +364 -109
- package/skills/teamsmith/tests/seat-interrupt.sh +1002 -0
- package/skills/teamsmith/tests/seat-visibility.sh +675 -0
- package/skills/teamsmith/tests/section-budgets.tsv +26 -12
- package/skills/teamsmith/tests/section-guard.sh +6 -1
- package/skills/teamsmith/tests/section-needs-audit.sh +24 -7
- package/skills/teamsmith/tests/section-paths.tsv +42 -26
- package/skills/teamsmith/tests/section-select.sh +90 -7
- package/skills/teamsmith/tests/slash-team-e2e.sh +323 -0
- package/skills/teamsmith/tests/slash-team.sh +617 -0
- package/skills/teamsmith/tests/smoke.sh +3762 -628
- package/skills/teamsmith/tests/snapshots/zh-dark-120-detail.txt +2 -2
- package/skills/teamsmith/tests/snapshots/zh-dark-120-p4.txt +2 -2
- package/skills/teamsmith/tests/snapshots/zh-dark-120.txt +9 -9
- package/skills/teamsmith/tests/snapshots/zh-dark-160-p4.txt +2 -2
- package/skills/teamsmith/tests/snapshots/zh-dark-160.txt +9 -9
- package/skills/teamsmith/tests/snapshots/zh-dark-59-detail.txt +1 -1
- package/skills/teamsmith/tests/snapshots/zh-dark-59-p4.txt +1 -1
- package/skills/teamsmith/tests/snapshots/zh-dark-59.txt +5 -5
- package/skills/teamsmith/tests/snapshots/zh-dark-99-p4.txt +2 -2
- package/skills/teamsmith/tests/snapshots/zh-dark-99.txt +5 -5
- package/skills/teamsmith/tests/snapshots/zh-light-120-detail.txt +2 -2
- package/skills/teamsmith/tests/snapshots/zh-light-120-p4.txt +2 -2
- package/skills/teamsmith/tests/snapshots/zh-light-120.txt +9 -9
- package/skills/teamsmith/tests/snapshots/zh-light-160-p4.txt +2 -2
- package/skills/teamsmith/tests/snapshots/zh-light-160.txt +9 -9
- package/skills/teamsmith/tests/snapshots/zh-light-59-detail.txt +1 -1
- package/skills/teamsmith/tests/snapshots/zh-light-59-p4.txt +1 -1
- package/skills/teamsmith/tests/snapshots/zh-light-59.txt +5 -5
- package/skills/teamsmith/tests/snapshots/zh-light-99-p4.txt +2 -2
- package/skills/teamsmith/tests/snapshots/zh-light-99.txt +5 -5
- package/skills/teamsmith/tests/task-header-model.sh +2 -1
- package/skills/teamsmith/tests/task-model-routing.sh +1511 -0
- package/skills/teamsmith/tests/tmp-hygiene.sh +782 -45
- package/skills/teamsmith/tests/tmux-identity-leak.sh +773 -0
- package/skills/teamsmith/tests/tmux-lint-legacy.txt +12 -18
- package/skills/teamsmith/tests/upgrade-recipe.sh +537 -0
- package/skills/teamsmith-init/SKILL.md +43 -43
- package/skills/teamsmith-init/references/bootstrap.md +8 -6
- package/skills/teamsmith-init/templates/bootstrap-prompt.md.tmpl +9 -5
|
@@ -1,102 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
# teamsmith · init / doctor / help
|
|
3
3
|
|
|
4
|
-
team_help() {
|
|
5
|
-
|
|
6
|
-
teamsmith — 用 Pi Agent 组建一个可复用的多 Agent 团队(PM 编排 + worker 并行)
|
|
7
|
-
|
|
8
|
-
用法: team <command> [args...] [--yes]
|
|
9
|
-
|
|
10
|
-
── 第一次使用 ─────────────────────────────────────────────
|
|
11
|
-
bootstrap [--agents "dev verify"] [--print] **推荐**:一条命令把项目初始化到可派单状态
|
|
12
|
-
(探测当前 tmux session/窗口 → 写配置 + 文档骨架 + AGENTS 段落 → 把 skill 装进项目
|
|
13
|
-
.pi/skills/ → 建 agent worktree → 起巡检窗口 → 打印下一步清单);幂等,可反复跑
|
|
14
|
-
init 只做配置/文档骨架 + 把 skill 装进项目 .pi/skills/(bootstrap 的其中一步)
|
|
15
|
-
--copy 复制一份(默认软链,跟随包更新);--no-skills 跳过装 skill;--force 覆盖冲突条目
|
|
16
|
-
doctor 环境自检(git/tmux/pi/门禁/forge/容量/容器)
|
|
17
|
-
|
|
18
|
-
── 观察 ───────────────────────────────────────────────────
|
|
19
|
-
roster 名册:agent、窗口是否在跑、分支、脏文件、领先提交数
|
|
20
|
-
status [ID] roster + 任务/report 状态;给 ID 时只显示该任务
|
|
21
|
-
ps 容量:RAM/swap/还能再跑几个 agent + 模型并发占用(派单前看)
|
|
22
|
-
bg list|stop <id> 后台作业车道:list 看本项目记录到的作业(pid/启动指纹/命令);stop 只按记录里的
|
|
23
|
-
(pid, 启动时间指纹) 停那一个作业(组内子孙一起;身份对不上就拒)
|
|
24
|
-
digest 给 PM 的待办摘要:收件箱未处理项 + 待复验报告 + 任务状态
|
|
25
|
-
inbox [agent] 打印收件箱(agent 在回合结束时自动追加)
|
|
26
|
-
paths 打印当前解析出的路径/ session(JSON),排障用
|
|
27
|
-
config list|set|log|set-agent-model
|
|
28
|
-
项目契约(.pi/team/config.sh)的读写面:list 列每个键的效果类(apply/restart/refuse)
|
|
29
|
-
与默认值;set 是**唯一写入口**(值校验 + sha256 指纹 CAS + 原子写 + 审计);
|
|
30
|
-
log 看审计尾部;set-agent-model 按席位改模型(- 移除覆盖)
|
|
31
|
-
|
|
32
|
-
── 文档契约(PM 维护) ─────────────────────────────────────
|
|
33
|
-
task ID --title ... [--agent a] [--deps ...] [--issue N]
|
|
34
|
-
生成任务书 <docs>/tasks/ID-slug.md 并在 BOARD.md 建行
|
|
35
|
-
board add|assign|set|row|ls BOARD.md 行管理(add [--allow-dup] / assign ID agent / set ID 状态 / row ID / ls)
|
|
36
|
-
change status <id> [--json]
|
|
37
|
-
change 的 readiness 视图(只读):任务/阶段/agent/看板/证据、delta 写者、阻塞项;
|
|
38
|
-
ready(至少一个任务且全部结束)→ 退出码 0,否则 1
|
|
39
|
-
thread <agent> ["msg"] 追加 / 读取往来记录(append-only)
|
|
40
|
-
report ID <agent> [--force] 生成报告骨架
|
|
41
|
-
|
|
42
|
-
── 派单与协作 ─────────────────────────────────────────────
|
|
43
|
-
add-agent <a> [--register] [--model m] [--create] [--no-install] [--print] 建长期 worktree(分支 agent/<a>);
|
|
44
|
-
名册:--register 走审计写入器(不带旗标的未知席位会被拒,并给出两条真路线)
|
|
45
|
-
dispatch <a> <ID> <task-file> [--model m] [--branch <name>] [--fresh] [--allow-overflow] [--print]
|
|
46
|
-
在 tmux 窗口起一个交互式 pi(默认复用会话,可断点续跑);--branch 声明这次必须用的任务分支
|
|
47
|
-
say <a> "<一句话>" [--now] 往 agent 窗口发消息;目标输入框里有草稿就**延后投递**(state/outbox/
|
|
48
|
-
+ 返回 queued);--now = 故意跳过守卫粘字(记入 outbox/forced.log)
|
|
49
|
-
notify <a> "<一句话>" [--from <发送者>] agent → PM 一句话(发送者按运行时目录解析;写收件箱 + 唤醒 PM 窗口)
|
|
50
|
-
draft [pm] 人的草稿入口:开/复用 draft 窗口跑 $EDITOR,保存退出后自动入队(不抢焦点)
|
|
51
|
-
draft send [<文件>] [--now] 无头形式:把草稿文件整段投递(守卫路径)
|
|
52
|
-
outbox [list] 延后队列:待投递条目(活动 + held,编号供 drop)
|
|
53
|
-
outbox flush [--now] 立刻排水(--now = 跳过守卫直投,留审计)
|
|
54
|
-
outbox drop <n|all> 人显式丢弃队列条目
|
|
55
|
-
|
|
56
|
-
── 定时巡检(pulse 由 PM 配置和维护) ────────────────────
|
|
57
|
-
pulse up|down|restart|status|logs [--print]
|
|
58
|
-
巡检(同 session 的 pulse 窗口跑 monitor + 定时巡检;只有一个后端,无容器依赖)
|
|
59
|
-
watchdog …/watchdog-status/install-watchdog/uninstall-watchdog
|
|
60
|
-
pulse 的旧名(别名期保留到 v2.0.0;先印一行弃用提示,再转交 pulse)
|
|
61
|
-
monitor [--once] [--print|--json] [--width N] [--height N] [--interval N] [--events K] [--no-pulse]
|
|
62
|
-
状态面板(pulse 窗口跑的就是它):默认 TUI(Ink),管道/--print 出纯文本,--json 出机读对象;
|
|
63
|
-
非 TTY 自动走纯文本;按周期顺带跑巡检(--no-pulse = 只看不巡)。需要 node/bun/tsx(D19)
|
|
64
|
-
watch [--once] [--interval N] [--ui] 手动/前台巡检(--ui = monitor)
|
|
65
|
-
standby [on|off|status] [--reason "..."] PM 主动停工:on 之后 pulse 不再叫醒(人处理完 off)
|
|
66
|
-
|
|
67
|
-
── 跨项目会议(PM 对 PM 的 peer 交流,不是指令通道) ─────────
|
|
68
|
-
meeting open <slug> --with <项目>[:<session>] --topic "…" [--ttl 72] [--yes]
|
|
69
|
-
meeting say <slug> --intent <info|question|report|proposal|request> "…" [--knock]
|
|
70
|
-
meeting read <slug> [--since N] [--peek] | meeting inbox | meeting list [--all]
|
|
71
|
-
meeting propose <slug> "…" | meeting agree <slug> <A1> [--note "…"] | meeting close <slug>
|
|
72
|
-
up [--agents] [--print] [--fresh-pm]
|
|
73
|
-
恢复 PM:建 tmux 场地 + 把 PM 拉起来(默认 pi -c 续上本目录上一个会话)
|
|
74
|
-
--fresh-pm = 本次启动新开一场对话(不 -c;旧会话文件原样留在历史里,作为开工记录);
|
|
75
|
-
它最优先:这一次启动里 TEAM_PM_SESSION_ID / TEAM_PM_RESUME_ARGS 都不生效,且只影响
|
|
76
|
-
这一次启动、不写进配置(守护/巡检按配置拉起 PM 时照旧续跑;--print 会打出判定与命令)
|
|
77
|
-
resume [--agent a] [--all] [--dry-run] PM 的工具:把停了但没交活的 agent 续跑
|
|
78
|
-
|
|
79
|
-
── 复验 / 合并 / 收尾 ─────────────────────────────────────
|
|
80
|
-
review ID --dir <独立checkout> [--no-gates] [--strong] [--allow-unresolved-branch]
|
|
81
|
-
独立 detached worktree 上 checkout 分支 → 跑门禁 → 写
|
|
82
|
-
<docs>/reviews/ID.md(PM 复验证据,不接受 agent 自述)
|
|
83
|
-
脏树 / 被忽略产物 / --branch 解析不到 → 默认拒绝(覆盖开关 TEAM_REVIEW_ALLOW_*)
|
|
84
|
-
close ID 收尾:更新 BOARD、关窗口、保留 worktree(git 由 PM 做)
|
|
85
|
-
teardown [--agent a] [--all] [--purge] [--force] [--register] 关窗口 / 删 worktree(--purge 才删 worktree);
|
|
86
|
-
--register = 先从名册移除该席位(同样走审计写入器)
|
|
87
|
-
|
|
88
|
-
smoke 在临时仓库里端到端自测这套工具(不碰当前项目)
|
|
89
|
-
perf 性能判定(交互首帧 / 帧装配 / 稳态窗格 CPU):默认在参考镜像里跑;--host = 宿主(非参考环境)
|
|
90
|
-
── 版本与更新(skill 更新怎么拿到) ─────────────────────────
|
|
91
|
-
mark-loaded [--version X] 记录本会话加载的 skill 版本(PM 开局跑一次)
|
|
92
|
-
version [--check] 看磁盘版本 / SKILL.md 版本 / CHANGELOG / 本会话加载版本;--check 给结论
|
|
93
|
-
changelog [--since X] 看 skill 变更史
|
|
94
|
-
reload [--done] 请求重载(在 Pi 里 /reload 或 /teamsmith-reload 立即生效)
|
|
95
|
-
version / help
|
|
96
|
-
|
|
97
|
-
配置:项目根 .pi/team/config.sh(见 references/config.md)。
|
|
98
|
-
协议:<docs>/PROTOCOL.md 或 SKILL.md 里的一页速览。
|
|
99
|
-
EOF
|
|
4
|
+
team_help() { # 兼容入口:`team help` 的三级路由在 scripts/lib/cmd-help.sh(唯一渲染器)
|
|
5
|
+
team_help_route 0 help "$@"
|
|
100
6
|
}
|
|
101
7
|
|
|
102
8
|
# ---------------------------------------------------------------- init
|
|
@@ -159,8 +65,66 @@ team_detect_vcs() {
|
|
|
159
65
|
esac
|
|
160
66
|
}
|
|
161
67
|
|
|
68
|
+
# ---------------------------------------------------------------- 模型策略(P235 · S3)
|
|
69
|
+
# 退休的席位/全局默认模型键:只要文件里还有真赋值行(注释里提不算),init/bootstrap 就停下并
|
|
70
|
+
# 指向唯一升级事务 —— 这不是「零变化重入」,而是未完成迁移的项目。
|
|
71
|
+
team_config_legacy_model_keys() { # <file> → 每行一个仍在文件里的退休键;没有则空
|
|
72
|
+
local f="${1:-}" k
|
|
73
|
+
[ -n "$f" ] && [ -f "$f" ] || return 0
|
|
74
|
+
for k in TEAM_DEFAULT_MODEL TEAM_AGENT_MODELS; do
|
|
75
|
+
grep -vE '^[[:space:]]*#' "$f" 2>/dev/null \
|
|
76
|
+
| grep -Eq "(^|[^A-Za-z0-9_])$k([[:space:]]*=|[[:space:]])" && printf '%s\n' "$k"
|
|
77
|
+
done
|
|
78
|
+
return 0
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
# init/bootstrap 的模型输入解析:显式输入 > 文件里的合法新策略(重入)。
|
|
82
|
+
# 两个键都是必填;没有可继承的合法值就拒绝,拒绝发生在任何写入之前。
|
|
83
|
+
# 显式值用与唯一 writer 同一个校验器(team_config_validate_value)验,拒绝时给真路线。
|
|
84
|
+
team_init_model_policy_resolve() { # <cfg> <task_models|''> <pm_model|''> <task_models_set 0|1> <pm_model_set 0|1> <cmd 名>
|
|
85
|
+
local cfg="${1:-}" in_map="${2:-}" in_pm="${3:-}" map_set="${4:-0}" pm_set="${5:-0}" cmd="${6:-init}"
|
|
86
|
+
local file_map="" file_pm="" file_map_ok=0 file_pm_ok=0 reason=""
|
|
87
|
+
if [ -n "$cfg" ] && [ -f "$cfg" ]; then
|
|
88
|
+
file_map="$(team_config_file_value "$cfg" TEAM_TASK_MODELS 2>/dev/null || true)"
|
|
89
|
+
file_pm="$(team_config_file_value "$cfg" TEAM_PM_MODEL 2>/dev/null || true)"
|
|
90
|
+
team_task_map_violation "$file_map" >/dev/null 2>&1 && file_map_ok=1
|
|
91
|
+
team_config_model_shape_ok "$file_pm" && file_pm_ok=1
|
|
92
|
+
fi
|
|
93
|
+
if [ "$map_set" = "1" ]; then
|
|
94
|
+
if ! reason="$(team_config_validate_value TEAM_TASK_MODELS "$in_map")"; then
|
|
95
|
+
team_err "$cmd: --task-models 不合法:$reason"
|
|
96
|
+
team_dim " 形如 'routine=provider/light analysis=provider/strong verify=provider/strong'(类别 [a-z][a-z0-9-]*,模型 provider/model,第一个 / 分 provider)" >&2
|
|
97
|
+
return 4
|
|
98
|
+
fi
|
|
99
|
+
elif [ "$file_map_ok" = "1" ]; then
|
|
100
|
+
in_map="$file_map"
|
|
101
|
+
else
|
|
102
|
+
team_err "$cmd: 缺少 --task-models(项目类别映射是必填输入;没有默认模型可猜)"
|
|
103
|
+
team_dim " 新项目:$TEAM_CLI init --task-models '<category=provider/model …>' --pm-model '<provider/model>'
|
|
104
|
+
已有项目:$TEAM_CLI config set-task-model <category> <model>(或 config set TEAM_TASK_MODELS '<完整映射>' --yes;破坏式升级走 config upgrade-models)" >&2
|
|
105
|
+
return 4
|
|
106
|
+
fi
|
|
107
|
+
if [ "$pm_set" = "1" ]; then
|
|
108
|
+
if ! reason="$(team_config_validate_value TEAM_PM_MODEL "$in_pm")"; then
|
|
109
|
+
team_err "$cmd: --pm-model 不合法:$reason"
|
|
110
|
+
team_dim " 独立 PM 模型:provider/model(可选 :suffix),例如 provider/strong-model:high" >&2
|
|
111
|
+
return 4
|
|
112
|
+
fi
|
|
113
|
+
elif [ "$file_pm_ok" = "1" ]; then
|
|
114
|
+
in_pm="$file_pm"
|
|
115
|
+
else
|
|
116
|
+
team_err "$cmd: 缺少 --pm-model(独立 PM 模型是必填输入;PM 不再回落到任何 worker/默认模型)"
|
|
117
|
+
team_dim " 新项目:$TEAM_CLI init --task-models '<category=provider/model …>' --pm-model '<provider/model>'
|
|
118
|
+
已有项目:$TEAM_CLI config set TEAM_PM_MODEL '<provider/model>' --yes(破坏式升级走 config upgrade-models)" >&2
|
|
119
|
+
return 4
|
|
120
|
+
fi
|
|
121
|
+
printf '%s\n%s\n' "$in_map" "$in_pm"
|
|
122
|
+
return 0
|
|
123
|
+
}
|
|
124
|
+
|
|
162
125
|
team_cmd_init() {
|
|
163
|
-
local session="" agents="" vcs="" gates="" docs="" pmwin=""
|
|
126
|
+
local session="" agents="" vcs="" gates="" docs="" pmwin="" force=0 install_mode=""
|
|
127
|
+
local task_models="" pm_model="" task_models_set=0 pm_model_set=0
|
|
164
128
|
while [ $# -gt 0 ]; do
|
|
165
129
|
case "$1" in
|
|
166
130
|
--session) session="${2:?}"; shift 2 ;;
|
|
@@ -169,7 +133,13 @@ team_cmd_init() {
|
|
|
169
133
|
--gates) gates="${2:?}"; shift 2 ;;
|
|
170
134
|
--docs) docs="${2:?}"; shift 2 ;;
|
|
171
135
|
--pm-window) pmwin="${2:?}"; shift 2 ;;
|
|
172
|
-
--
|
|
136
|
+
--task-models) task_models="${2:?}"; task_models_set=1; shift 2 ;;
|
|
137
|
+
--pm-model) pm_model="${2:?}"; pm_model_set=1; shift 2 ;;
|
|
138
|
+
--model|--default-model)
|
|
139
|
+
team_err "init: $1 已退休:项目不再有席位/全局默认模型"
|
|
140
|
+
team_dim " 新项目:$TEAM_CLI init --task-models '<category=provider/model …>' --pm-model '<provider/model>'"
|
|
141
|
+
team_dim " 已有项目升级:$TEAM_CLI config upgrade-models --task-models '<完整映射>' --pm-model '<独立模型>' --dry-run"
|
|
142
|
+
return 2 ;;
|
|
173
143
|
--copy) install_mode="--copy"; shift ;;
|
|
174
144
|
--no-skills) install_mode="--no-skills"; shift ;;
|
|
175
145
|
--force) force=1; shift ;;
|
|
@@ -183,7 +153,42 @@ team_cmd_init() {
|
|
|
183
153
|
vcs="${vcs:-$(team_detect_vcs)}"
|
|
184
154
|
docs="${docs:-docs/team}"
|
|
185
155
|
pmwin="${pmwin:-pm}"
|
|
186
|
-
|
|
156
|
+
local cfg="$TEAM_MAIN_ROOT/.pi/team/config.sh" had_config=0; [ -f "$cfg" ] && had_config=1
|
|
157
|
+
|
|
158
|
+
# 0) 模型策略闸门(P235):退休键 / 缺输入 / 非法值都在**任何写入之前**停住。
|
|
159
|
+
# 已有合法新策略允许不带输入重入(保留策略);退休键则连 --force 都不能当迁移捷径。
|
|
160
|
+
if [ "$had_config" = "1" ]; then
|
|
161
|
+
local legacy_keys; legacy_keys="$(team_config_legacy_model_keys "$cfg")"
|
|
162
|
+
if [ -n "$legacy_keys" ]; then
|
|
163
|
+
team_err "init: $cfg 还在用退休的模型键($(printf '%s' "$legacy_keys" | tr '\n' ' '))—— 任何写入之前停住"
|
|
164
|
+
team_dim " 项目模型策略是破坏式升级:init / init --force / bootstrap 都不是迁移路径"
|
|
165
|
+
team_legacy_model_route_lines "$cfg"
|
|
166
|
+
return 1
|
|
167
|
+
fi
|
|
168
|
+
fi
|
|
169
|
+
local _policy _rc=0
|
|
170
|
+
_policy="$(team_init_model_policy_resolve "$cfg" "$task_models" "$pm_model" "$task_models_set" "$pm_model_set" init)" || _rc=$?
|
|
171
|
+
[ "$_rc" -eq 0 ] || return "$_rc"
|
|
172
|
+
task_models="$(printf '%s\n' "$_policy" | sed -n '1p')"
|
|
173
|
+
pm_model="$(printf '%s\n' "$_policy" | sed -n '2p')"
|
|
174
|
+
# 已有配置(不带 --force)原样保留:显式输入与现有策略不同就拒绝,不静默忽略。
|
|
175
|
+
if [ "$had_config" = "1" ] && [ "$force" != "1" ]; then
|
|
176
|
+
local cur_map cur_pm
|
|
177
|
+
cur_map="$(team_config_file_value "$cfg" TEAM_TASK_MODELS 2>/dev/null || true)"
|
|
178
|
+
cur_pm="$(team_config_file_value "$cfg" TEAM_PM_MODEL 2>/dev/null || true)"
|
|
179
|
+
if [ "$task_models_set" = "1" ] && [ "$task_models" != "$cur_map" ]; then
|
|
180
|
+
team_err "init: 现有配置会被保留(skip),但 --task-models 与现有映射不同 —— 不静默忽略"
|
|
181
|
+
team_dim " 改一个类别:$TEAM_CLI config set-task-model <category> <model>;整映射:$TEAM_CLI config set TEAM_TASK_MODELS '<完整映射>' --yes"
|
|
182
|
+
team_dim " 或 --force 重渲染整份契约(其它键会回到模板值)"
|
|
183
|
+
return 4
|
|
184
|
+
fi
|
|
185
|
+
if [ "$pm_model_set" = "1" ] && [ "$pm_model" != "$cur_pm" ]; then
|
|
186
|
+
team_err "init: 现有配置会被保留(skip),但 --pm-model 与现有值不同 —— 不静默忽略"
|
|
187
|
+
team_dim " 改 PM 模型:$TEAM_CLI config set TEAM_PM_MODEL '<provider/model>' --yes;或 --force 重渲染"
|
|
188
|
+
return 4
|
|
189
|
+
fi
|
|
190
|
+
fi
|
|
191
|
+
|
|
187
192
|
# --force = 重渲染整份契约:此时不把**旧契约读回来的** TEAM_GATES 当模板值 —— 它是旧值,
|
|
188
193
|
# 不是这次要渲染的模板值(P99 身份 note 承诺的代价:其它键回到模板值)。真正从环境继承
|
|
189
194
|
# (export 过)的值仍算显式覆盖,照旧优先。
|
|
@@ -216,16 +221,29 @@ team_cmd_init() {
|
|
|
216
221
|
|
|
217
222
|
# 1) 配置
|
|
218
223
|
TEAM_AGENTS="$agents"; TEAM_DOCS_DIR="$docs"
|
|
219
|
-
local
|
|
224
|
+
local tmpl; tmpl="$(team_tmpl_dir)/config.sh.tmpl"
|
|
220
225
|
if [ -f "$cfg" ] && [ "$force" != "1" ]; then
|
|
221
226
|
team_dim "skip $cfg(已存在,--force 覆盖)"
|
|
222
227
|
else
|
|
223
228
|
mkdir -p "$(dirname "$cfg")"
|
|
224
|
-
team_render "$tmpl" \
|
|
229
|
+
if ! team_render "$tmpl" \
|
|
225
230
|
"PROJECT=$project" "SESSION=$session" "PM_WINDOW=$pmwin" \
|
|
226
231
|
"DOCS_DIR=$docs" "AGENTS=$agents" "GATES=$(team_escape_dq "$gates")" "VCS=$vcs" \
|
|
227
|
-
"
|
|
228
|
-
"DETECTED_VCS=$(team_detect_vcs)" "TODAY=$(date +%F)"
|
|
232
|
+
"SKILL_DIR=$TEAM_SKILL_DIR" \
|
|
233
|
+
"DETECTED_VCS=$(team_detect_vcs)" "TODAY=$(date +%F)" \
|
|
234
|
+
"CONFIG_VERSION=$TEAM_CONFIG_SHAPE_CURRENT" > "$cfg"; then
|
|
235
|
+
team_err "init: 渲染配置失败:$tmpl"
|
|
236
|
+
rm -f "$cfg"
|
|
237
|
+
return 1
|
|
238
|
+
fi
|
|
239
|
+
# 模型两键走同一个加固写入器(值已用同一个校验器验过):不是模板插值、没有默认值可猜。
|
|
240
|
+
# 任一步失败就删掉这次的半成品配置,绝不留下缺键的契约。
|
|
241
|
+
if ! team_config_set_in_file "$cfg" TEAM_TASK_MODELS "$task_models" \
|
|
242
|
+
|| ! team_config_set_in_file "$cfg" TEAM_PM_MODEL "$pm_model"; then
|
|
243
|
+
team_err "init: 模型策略写入失败,已删除这次的半成品配置"
|
|
244
|
+
rm -f "$cfg"
|
|
245
|
+
return 1
|
|
246
|
+
fi
|
|
229
247
|
team_ok "write $cfg"
|
|
230
248
|
fi
|
|
231
249
|
chmod 0644 "$cfg"
|
|
@@ -281,8 +299,9 @@ team_cmd_init() {
|
|
|
281
299
|
printf '\n'
|
|
282
300
|
team_hdr "下一步"
|
|
283
301
|
printf ' 1) %s doctor\n' "$TEAM_CLI"
|
|
284
|
-
printf ' 2) 编辑 %s/.pi/team/config.sh(名册 TEAM_AGENTS、门禁 TEAM_GATES
|
|
285
|
-
printf '
|
|
302
|
+
printf ' 2) 编辑 %s/.pi/team/config.sh(名册 TEAM_AGENTS、门禁 TEAM_GATES、任务类别映射)\n' "$project"
|
|
303
|
+
printf ' 改一个类别:%s config set-task-model <category> <model>;整映射:%s config set TEAM_TASK_MODELS <完整映射> --yes\n' "$TEAM_CLI" "$TEAM_CLI"
|
|
304
|
+
printf ' 3) %s task T1.1 --title "第一个任务" --category <类别> --agent dev\n' "$TEAM_CLI"
|
|
286
305
|
printf ' 4) %s dispatch dev T1.1 %s/tasks/T1.1-*.md\n' "$TEAM_CLI" "$docs"
|
|
287
306
|
printf ' 5) %s digest # PM 看板\n' "$TEAM_CLI"
|
|
288
307
|
}
|
|
@@ -383,6 +402,21 @@ team_cmd_doctor() {
|
|
|
383
402
|
check "tmux 闸门退役键"; printf '%s\n' "SKIP:没有 tmux,无法探测 server 全局环境"
|
|
384
403
|
fi
|
|
385
404
|
|
|
405
|
+
# P304 · 本项目身份在运行中 server 全局环境里的残留(**只读**报告,绝不代改):残留会让同一 server 上
|
|
406
|
+
# **别的项目**新开的窗口继承本项目的身份(用户 2026-10-15 报的形状:server 死了重开,在别的项目里
|
|
407
|
+
# 被自己的身份守卫拒掉)。本 change 落地后产品路径不再新增它;这份只读行是「人自己决定清不清」的
|
|
408
|
+
# 出口(清它 = 改共享 server 的全局环境,属用户的管辖)。判据与读侧归因同源。
|
|
409
|
+
if team_have_cmd tmux; then
|
|
410
|
+
local id_residue="" id_vars="" id_route=""
|
|
411
|
+
id_residue="$(team_identity_server_residue_vars)"
|
|
412
|
+
if [ -n "$id_residue" ]; then
|
|
413
|
+
id_vars="$(printf '%s\n' "$id_residue" | awk -F= 'NF { printf "%s%s", (NR > 1 ? " " : ""), $1 }')"
|
|
414
|
+
id_route="$(team_identity_residue_route $id_vars)"
|
|
415
|
+
check "tmux 身份残留"
|
|
416
|
+
warn "运行中的 tmux server 全局环境里还有本项目的身份残留($(printf '%s' "$id_residue" | tr '\n' ' '))——它会让同一 server 上别的项目新开的窗口继承本项目的身份;只报告不代改,清掉(改共享 server,时机由你定):$id_route"
|
|
417
|
+
fi
|
|
418
|
+
fi
|
|
419
|
+
|
|
386
420
|
check "pi"; if [ -n "${TEAM_AGENT_CMD:-}" ]; then
|
|
387
421
|
pass "本项目用自定义 agent adapter:不需要 pi"
|
|
388
422
|
elif team_have_cmd pi; then
|
|
@@ -621,6 +655,16 @@ team_cmd_doctor() {
|
|
|
621
655
|
esac
|
|
622
656
|
fi
|
|
623
657
|
|
|
658
|
+
# P270:项目本地的 `/team` 扩展(同一条 warn-don't-fail 线,同一个「没装就不刷行」的口径)。
|
|
659
|
+
local ext_row; ext_row="$(team_project_extension_install_row)"
|
|
660
|
+
if [ -n "$ext_row" ]; then
|
|
661
|
+
check "/team 扩展安装"
|
|
662
|
+
case "$ext_row" in
|
|
663
|
+
pass\ *) pass "${ext_row#pass }" ;;
|
|
664
|
+
warn\ *) warn "${ext_row#warn }" ;;
|
|
665
|
+
esac
|
|
666
|
+
fi
|
|
667
|
+
|
|
624
668
|
check "陈旧 state"; local stale=0 a w
|
|
625
669
|
for a in $(team_agents); do
|
|
626
670
|
w="$(team_state_get "$a" window "$a")"
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
# teamsmith · team reap(P276 · change: orphan-visibility · delta: boundary)
|
|
2
|
+
#
|
|
3
|
+
# 合同:openspec/changes/orphan-visibility/specs/boundary/spec.md 的
|
|
4
|
+
# `Orphan seat processes of this project are reaped by pid, with an audit and no pattern`。
|
|
5
|
+
#
|
|
6
|
+
# 为什么它是一个**独立命令**而不是 `ps`/`status` 的副作用:读命令一个信号都不发。清理是破坏性动作,
|
|
7
|
+
# 只能由人在 argv 上显式授权(`--yes`),并且在每个目标**发信号之前**再验一遍——从普查到发信号之间
|
|
8
|
+
# 有 TOCTOU 窗口,一个刚被回收的 pid 可能是别人的进程、一个刚被重派的席位可能已经有活 pane。
|
|
9
|
+
# 既有纪律(`boundary#Signals go to a recorded pid, never to a name or a pattern`)要的正是「对象是
|
|
10
|
+
# 证明过的那个」,所以复验是**判据的一部分**,不是防御性装饰。
|
|
11
|
+
#
|
|
12
|
+
# 三条硬边界:
|
|
13
|
+
# ① **只按 pid 选**:没有 pkill/killall/名字/模式匹配;argv 里给的永远是显式 pid(或 `--orphans`
|
|
14
|
+
# 这一条由普查列出的计划),发信号永远 `kill <pid>`。
|
|
15
|
+
# ② `--yes` 是**唯一**授权:不看 TEAM_CONFIRM_WRITES、不看 TEAM_ASSUME_YES、不看任何继承值——
|
|
16
|
+
# 环境变量与配置键都不能让一个信号默认发出(合同明文)。
|
|
17
|
+
# ③ 跨项目零点名:别的项目的 pid/项目名/席位名/路径一个都不打印(这份读数会被抄进公开账本)。
|
|
18
|
+
|
|
19
|
+
# 审计日志的行格式:时间戳 / pid / 席位 / 信号 / 结果。**每个信号恰好一行**(SIGTERM 一行;有界等待后
|
|
20
|
+
# 仍活着才再发 SIGKILL,那也是一行)。计划态**不写**这个文件。
|
|
21
|
+
team_reap_log_path() { printf '%s\n' "${TEAM_STATE_DIR:-}/reap.log"; }
|
|
22
|
+
|
|
23
|
+
# 有界等待的秒数(SIGTERM 之后等这么久,然后再 SIGKILL)。它是个**有界**上界,不是睡眠:进程一退出
|
|
24
|
+
# 就立刻返回。合同只要求「有界」,没给它一个契约键,所以留在实现里(写进命令页)。
|
|
25
|
+
team_reap_grace() { printf '%s\n' "${TEAM_REAP_GRACE_SEC:-5}"; }
|
|
26
|
+
|
|
27
|
+
team_reap_log_open() { # 授权后打开审计日志(创建 state/ 与 reap.log;计划态绝不调它)
|
|
28
|
+
local d f
|
|
29
|
+
d="$(team_state_dir)"
|
|
30
|
+
f="$d/reap.log"
|
|
31
|
+
: >> "$f" 2>/dev/null || { team_err "reap: 审计日志写不了($f)—— 没有授权就没有动作"; return 1; }
|
|
32
|
+
return 0
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
team_reap_log_line() { # <pid> <seat> <signal> <outcome>
|
|
36
|
+
local f; f="$(team_reap_log_path)"
|
|
37
|
+
printf '%s pid=%s seat=%s signal=%s outcome=%s\n' \
|
|
38
|
+
"$(date -u +%Y-%m-%dT%H:%M:%SZ)" "${1:-?}" "${2:--}" "${3:-?}" "${4:-?}" >> "$f"
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
# 调用者自己或它的祖先(/proc/<pid>/stat 第 4 字段是 ppid)。**自己与祖先**永远不许杀:那是自杀/杀
|
|
42
|
+
# 起它的那个壳,与「孤儿」无关。走 /proc,不依赖 ps 的格式。
|
|
43
|
+
team_reap_is_self_or_ancestor() { # <pid>
|
|
44
|
+
local p="${1:-}" cur="$$" depth=0
|
|
45
|
+
case "$p" in ''|*[!0-9]*) return 1 ;; esac
|
|
46
|
+
[ "$p" = "$$" ] && return 0
|
|
47
|
+
while [ "$depth" -lt 64 ]; do
|
|
48
|
+
cur="$(awk '{print $4}' "/proc/$cur/stat" 2>/dev/null || true)"
|
|
49
|
+
case "$cur" in ''|*[!0-9]*) break ;; esac
|
|
50
|
+
[ "$cur" = "0" ] && break
|
|
51
|
+
[ "$cur" = "$p" ] && return 0
|
|
52
|
+
depth=$((depth + 1))
|
|
53
|
+
done
|
|
54
|
+
return 1
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
# 一个 pid 的 argv 快照(真 /proc 用一次 ps;夹具根读 cmdline)。形状判据自己也会读,但复验要的是
|
|
58
|
+
# **同一次**读到的快照——两次读之间有 execve 的窗口(M39 的既有教训)。
|
|
59
|
+
team_reap_argv_of() { # <pid> → argv 快照
|
|
60
|
+
local pid="${1:-}" root out
|
|
61
|
+
[ -n "$pid" ] || return 1
|
|
62
|
+
root="$(team_orphan_proc_root)"
|
|
63
|
+
if [ "$root" = "/proc" ]; then
|
|
64
|
+
out="$(ps -ww -o args= -p "$pid" 2>/dev/null | head -1)"
|
|
65
|
+
[ -n "$out" ] || return 1
|
|
66
|
+
printf '%s\n' "$out"
|
|
67
|
+
return 0
|
|
68
|
+
fi
|
|
69
|
+
team_orphan_read_cmdline "$pid"
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
team_reap_usage() {
|
|
73
|
+
printf '用法:team reap --orphans [--yes] | team reap <pid> [--yes]\n'
|
|
74
|
+
printf ' 计划态(没有 --yes):打印目标与将发的信号,一个信号都不发,退 0。\n'
|
|
75
|
+
printf ' 执行态(--yes):每个目标发信号前**再验一遍**(仍是本项目席位 / 仍没有活 pane / 启动时刻\n'
|
|
76
|
+
printf ' 与计划时一致),先 SIGTERM,有界等待后仍活着才 SIGKILL;每个信号一行 state/reap.log。\n'
|
|
77
|
+
printf ' --yes 是唯一授权:配置键、TEAM_ASSUME_YES、继承的环境变量都不能让它默认开。\n'
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
# 目标的第一段判定:这个 pid 现在是什么(own/foreign/anon/orphan/live/unjudged)。印出记录或非 0。
|
|
81
|
+
team_reap_target_record() { # <pid> → 一条普查记录
|
|
82
|
+
local pid="${1:-}" args
|
|
83
|
+
args="$(team_reap_argv_of "$pid" 2>/dev/null || true)"
|
|
84
|
+
[ -n "$args" ] || return 1
|
|
85
|
+
team_orphan_record_for "$pid" "$args"
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
# 复验:发信号**之前**,用与普查同一个判据再读一次;任何一条不成立都拒发并说明原因(写进 REAP_REASON)。
|
|
89
|
+
team_reap_verify() { # <pid> <计划时的 start> → 0 = 复验通过
|
|
90
|
+
local pid="${1:-}" planned="${2:-}" rec kind seat task start rss judge
|
|
91
|
+
REAP_REASON=""
|
|
92
|
+
rec="$(team_reap_target_record "$pid" 2>/dev/null || true)"
|
|
93
|
+
if [ -z "$rec" ]; then
|
|
94
|
+
REAP_REASON="它不再是席位形状的进程(命令行不再命中本项目配置的 agent/PM 可执行文件,或身份/命令行读不到)"
|
|
95
|
+
return 1
|
|
96
|
+
fi
|
|
97
|
+
IFS=$'\t' read -r _ kind seat task start rss judge <<< "$rec"
|
|
98
|
+
case "$kind" in
|
|
99
|
+
foreign) REAP_REASON="它的身份属于**别的项目**(跨项目零点名:这里不打印它的项目名)"; return 1 ;;
|
|
100
|
+
anon) REAP_REASON="它没有 teamsmith 身份(可能是人工起的同形进程)"; return 1 ;;
|
|
101
|
+
own) ;;
|
|
102
|
+
*) REAP_REASON="它的归属判不出来($kind)"; return 1 ;;
|
|
103
|
+
esac
|
|
104
|
+
case "$judge" in
|
|
105
|
+
live) REAP_REASON="它的 pane 又活了——现在不是孤儿了"; return 1 ;;
|
|
106
|
+
unjudged) REAP_REASON="它自己那个 tmux server 查询不到——判不了就不猜(未判定)"; return 1 ;;
|
|
107
|
+
orphan) ;;
|
|
108
|
+
*) REAP_REASON="它的孤儿判据给不出结论($judge)"; return 1 ;;
|
|
109
|
+
esac
|
|
110
|
+
if [ "$start" != "$planned" ]; then
|
|
111
|
+
REAP_REASON="进程启动时刻与计划时不一致(计划=$planned 现在=$start:pid 可能已被内核回收)"
|
|
112
|
+
return 1
|
|
113
|
+
fi
|
|
114
|
+
REAP_SEAT="$seat"
|
|
115
|
+
return 0
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
# 发信号:SIGTERM → 有界等待 → 仍活着再 SIGKILL。每个信号一行审计。
|
|
119
|
+
team_reap_signal() { # <pid> <seat> → 0 = 目标已退出
|
|
120
|
+
local pid="${1:-}" seat="${2:--}" grace ticks i alive=0
|
|
121
|
+
grace="$(team_reap_grace)"
|
|
122
|
+
case "$grace" in ''|*[!0-9]*) grace=5 ;; esac
|
|
123
|
+
if ! kill -TERM "$pid" 2>/dev/null; then
|
|
124
|
+
team_reap_log_line "$pid" "$seat" SIGTERM "failed"
|
|
125
|
+
team_err "reap: pid $pid(席位=$seat)SIGTERM 发不出去(进程刚好消失了?)"
|
|
126
|
+
return 1
|
|
127
|
+
fi
|
|
128
|
+
ticks=$(( grace * 10 ))
|
|
129
|
+
i=0
|
|
130
|
+
while [ "$i" -lt "$ticks" ]; do
|
|
131
|
+
kill -0 "$pid" 2>/dev/null || break
|
|
132
|
+
sleep 0.1
|
|
133
|
+
i=$((i + 1))
|
|
134
|
+
done
|
|
135
|
+
if ! kill -0 "$pid" 2>/dev/null; then
|
|
136
|
+
team_reap_log_line "$pid" "$seat" SIGTERM gone
|
|
137
|
+
team_ok "reap: pid $pid(席位=$seat)SIGTERM → 已退出"
|
|
138
|
+
return 0
|
|
139
|
+
fi
|
|
140
|
+
team_reap_log_line "$pid" "$seat" SIGTERM "alive→SIGKILL"
|
|
141
|
+
if ! kill -KILL "$pid" 2>/dev/null; then
|
|
142
|
+
team_reap_log_line "$pid" "$seat" SIGKILL failed
|
|
143
|
+
team_err "reap: pid $pid(席位=$seat)SIGKILL 发不出去"
|
|
144
|
+
return 1
|
|
145
|
+
fi
|
|
146
|
+
i=0
|
|
147
|
+
while [ "$i" -lt 100 ]; do
|
|
148
|
+
kill -0 "$pid" 2>/dev/null || break
|
|
149
|
+
sleep 0.1
|
|
150
|
+
i=$((i + 1))
|
|
151
|
+
done
|
|
152
|
+
if kill -0 "$pid" 2>/dev/null; then
|
|
153
|
+
team_reap_log_line "$pid" "$seat" SIGKILL "still-alive"
|
|
154
|
+
team_err "reap: pid $pid(席位=$seat)SIGKILL 之后仍然活着(不可中断/D 状态?)"
|
|
155
|
+
return 1
|
|
156
|
+
fi
|
|
157
|
+
team_reap_log_line "$pid" "$seat" SIGKILL gone
|
|
158
|
+
team_ok "reap: pid $pid(席位=$seat)SIGTERM 之后仍活着 → SIGKILL → 已退出"
|
|
159
|
+
return 0
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
team_cmd_reap() {
|
|
163
|
+
# `--yes` 是**唯一**授权:只看这一次 argv 上有没有它(scripts/team 的全局解析器把 TEAM_YES_ARGV 落成 1)。
|
|
164
|
+
# 显式不看 TEAM_CONFIRM_WRITES、不看继承来的 TEAM_ASSUME_YES——它们都不是「人这次说了要动手」的证据。
|
|
165
|
+
local yes=0 orphans=0 pid="" a
|
|
166
|
+
[ "${TEAM_YES_ARGV:-0}" = "1" ] && yes=1
|
|
167
|
+
while [ $# -gt 0 ]; do
|
|
168
|
+
case "$1" in
|
|
169
|
+
--yes) yes=1; shift ;;
|
|
170
|
+
--orphans) orphans=1; shift ;;
|
|
171
|
+
-h|--help) team_reap_usage; return 0 ;;
|
|
172
|
+
-*) team_usage_die "reap: 未知参数 $1" ;;
|
|
173
|
+
*)
|
|
174
|
+
case "$1" in *[!0-9]*) team_usage_die "reap: 目标只能是显式 pid 或 --orphans(收到 '$1')——本命令不接受名字或模式" ;; esac
|
|
175
|
+
[ -z "$pid" ] || team_usage_die "reap: 多余参数 $1"
|
|
176
|
+
pid="$1"; shift ;;
|
|
177
|
+
esac
|
|
178
|
+
done
|
|
179
|
+
if [ "$orphans" = 1 ] && [ -n "$pid" ]; then team_usage_die "reap: --orphans 与 <pid> 不同用"; fi
|
|
180
|
+
if [ "$orphans" != 1 ] && [ -z "$pid" ]; then
|
|
181
|
+
team_usage_die "reap: 需要 --orphans 或一个 pid(team reap --orphans [--yes] | team reap <pid> [--yes])"
|
|
182
|
+
fi
|
|
183
|
+
if [ "$orphans" = 1 ] && [ "${TEAM_ORPHAN_SCAN:-1}" != "1" ]; then
|
|
184
|
+
team_err "reap: 普查被关闭(TEAM_ORPHAN_SCAN=0)——列不出孤儿;用显式 pid(team reap <pid>)"
|
|
185
|
+
return 2
|
|
186
|
+
fi
|
|
187
|
+
|
|
188
|
+
team_orphan_ctx_init
|
|
189
|
+
local -a tpids=() tseats=() tmems=() tstarts=()
|
|
190
|
+
|
|
191
|
+
if [ -n "$pid" ]; then
|
|
192
|
+
# ── 单个 pid:先把它读成一条记录(拒绝集合在这里就落地) ──
|
|
193
|
+
local rec="" kind seat task start rss judge
|
|
194
|
+
rec="$(team_reap_target_record "$pid" 2>/dev/null || true)"
|
|
195
|
+
if [ -z "$rec" ]; then
|
|
196
|
+
team_err "reap: pid $pid 不是席位形状的进程(命令行不命中本项目配置的 agent/PM 可执行文件,或它的身份/命令行读不到)——一个信号都不发"
|
|
197
|
+
return 2
|
|
198
|
+
fi
|
|
199
|
+
IFS=$'\t' read -r _ kind seat task start rss judge <<< "$rec"
|
|
200
|
+
case "$kind" in
|
|
201
|
+
foreign) team_err "reap: pid $pid 属于**别的项目**的席位——拒发(跨项目零点名:它的项目名/席位名/路径都不打印)"; return 2 ;;
|
|
202
|
+
anon) team_err "reap: pid $pid 没有 teamsmith 身份——拒发(它可能不是任何项目的席位)"; return 2 ;;
|
|
203
|
+
esac
|
|
204
|
+
if team_reap_is_self_or_ancestor "$pid"; then
|
|
205
|
+
team_err "reap: pid $pid 是调用者自己或它的祖先——拒发(那不是孤儿,是起你的那个壳)"
|
|
206
|
+
return 2
|
|
207
|
+
fi
|
|
208
|
+
if [ "$judge" != "orphan" ]; then
|
|
209
|
+
case "$judge" in
|
|
210
|
+
live)
|
|
211
|
+
# F2(V52 返修轮次 1):这句拒绝必须**点名另一条入口** —— protocol §4a 的合约是「每个拒绝都
|
|
212
|
+
# 点名另一个入口」(interrupt 侧早已指向 `team reap --orphans`),而 reap 侧此前全文件
|
|
213
|
+
# `grep -c interrupt` = 0:一个活着的席位上被拒,用户拿着一个正确的拒绝却不知道该换哪条命令。
|
|
214
|
+
# 席位名读得到就给具体的(`team interrupt dev --reason …`),读不到(`-`)给占位。
|
|
215
|
+
local who="$seat"; [ "$who" != "-" ] || who="<seat>"
|
|
216
|
+
team_err "reap: pid $pid 不是孤儿(它的 pane 还活着)——它在跑一个回合,要结束它走 team interrupt $who --reason <一句话>;一个信号都不发" ;;
|
|
217
|
+
unjudged) team_err "reap: pid $pid 判不了(它自己那个 tmux server 查询不到)——不猜、不发" ;;
|
|
218
|
+
*) team_err "reap: pid $pid 的孤儿判据给不出结论($judge)——不发" ;;
|
|
219
|
+
esac
|
|
220
|
+
return 2
|
|
221
|
+
fi
|
|
222
|
+
tpids+=("$pid"); tseats+=("$seat"); tmems+=("$rss"); tstarts+=("$start")
|
|
223
|
+
else
|
|
224
|
+
# ── --orphans:普查列出的**本项目**孤儿就是计划 ──
|
|
225
|
+
while IFS=$'\t' read -r p kind seat task start rss judge; do
|
|
226
|
+
[ -n "$p" ] || continue
|
|
227
|
+
[ "$kind" = "own" ] || continue
|
|
228
|
+
[ "$judge" = "orphan" ] || continue
|
|
229
|
+
if team_reap_is_self_or_ancestor "$p"; then
|
|
230
|
+
team_warn "reap: 跳过 pid $p——它是调用者自己或它的祖先(不是孤儿)"
|
|
231
|
+
continue
|
|
232
|
+
fi
|
|
233
|
+
tpids+=("$p"); tseats+=("$seat"); tmems+=("$rss"); tstarts+=("$start")
|
|
234
|
+
done < <(team_orphan_census)
|
|
235
|
+
fi
|
|
236
|
+
|
|
237
|
+
local n=${#tpids[@]} i
|
|
238
|
+
local grace; grace="$(team_reap_grace)"
|
|
239
|
+
case "$grace" in ''|*[!0-9]*) grace=5 ;; esac
|
|
240
|
+
|
|
241
|
+
if [ "$n" -eq 0 ]; then
|
|
242
|
+
if [ "$yes" = 1 ]; then
|
|
243
|
+
team_reap_log_open || return 1
|
|
244
|
+
team_info "reap:没有本项目孤儿席位进程(一个信号都没发;审计日志 $(team_reap_log_path) 已就绪)"
|
|
245
|
+
else
|
|
246
|
+
team_info "reap:没有本项目孤儿席位进程(计划为空;一个信号都不会发)"
|
|
247
|
+
fi
|
|
248
|
+
return 0
|
|
249
|
+
fi
|
|
250
|
+
|
|
251
|
+
if [ "$yes" != 1 ]; then
|
|
252
|
+
printf 'reap 计划(%s 个目标;**未授权**——一个信号都不会发;加 --yes 执行):\n' "$n"
|
|
253
|
+
for i in "${!tpids[@]}"; do
|
|
254
|
+
printf ' %s 席位=%s 内存=%s 启动=%s → 先 SIGTERM,%ss 后仍活着再 SIGKILL\n' \
|
|
255
|
+
"${tpids[$i]}" "${tseats[$i]}" "$(team_orphan_rss_text "${tmems[$i]}")" \
|
|
256
|
+
"$(team_orphan_ts "${tstarts[$i]}")" "$grace"
|
|
257
|
+
done
|
|
258
|
+
printf ' 审计:%s(执行时每个信号一行)\n' "$(team_reap_log_path)"
|
|
259
|
+
return 0
|
|
260
|
+
fi
|
|
261
|
+
|
|
262
|
+
# ── 执行态:先开审计日志(授权之后才写盘),然后逐个「复验 → 发信号」 ──
|
|
263
|
+
team_reap_log_open || return 1
|
|
264
|
+
printf 'reap 执行(--yes;%s 个目标;每个目标发信号前**再验一遍**):\n' "$n"
|
|
265
|
+
local rc=0 seat2
|
|
266
|
+
for i in "${!tpids[@]}"; do
|
|
267
|
+
if ! team_reap_verify "${tpids[$i]}" "${tstarts[$i]}"; then
|
|
268
|
+
team_err "reap: pid ${tpids[$i]} 复验不过,拒发:$REAP_REASON"
|
|
269
|
+
rc=1
|
|
270
|
+
continue
|
|
271
|
+
fi
|
|
272
|
+
seat2="${REAP_SEAT:-${tseats[$i]}}"
|
|
273
|
+
team_reap_signal "${tpids[$i]}" "$seat2" || rc=1
|
|
274
|
+
done
|
|
275
|
+
[ "$rc" = 0 ] || team_err "reap: 有目标没有收干净(见上面的逐条结论)"
|
|
276
|
+
return "$rc"
|
|
277
|
+
}
|