codex-supervisor-mcp 0.9.7 → 0.10.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/README.md +24 -5
- package/package.json +6 -1
- package/skills/codex-supervisor/SKILL.md +24 -11
- package/src/acceptance.js +14 -1
- package/src/cleanup-hint.js +3 -3
- package/src/cleanup-plan.js +98 -0
- package/src/cleanup.js +38 -150
- package/src/codex-runner.js +209 -16
- package/src/context-compiler.js +86 -0
- package/src/handoff.js +2 -3
- package/src/mcp-config.js +35 -0
- package/src/mcp-server.js +341 -2
- package/src/overview-delta.js +34 -0
- package/src/side-chat.js +2 -22
- package/src/task-store.js +419 -10
- package/src/worker-preflight.js +111 -0
package/README.md
CHANGED
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
| worker 说做完了其实没有 | 派单给 `acceptance` 验收命令,worker 退出后 supervisor 在它的 worktree 里跑,失败 `land` 拒绝 |
|
|
33
33
|
| 看不见一批活现在到哪了 | `codex-supervisor-web` 开一个看板,按 session 看每路 worker 在干什么 |
|
|
34
34
|
| 改动留在本地没上线 | 收活默认 `land_codex_worker` 合回主分支;主线程自己的改动必须 commit + push;部署前用远端 SHA 核对文件真的在线上 |
|
|
35
|
-
| worktree / 分支越堆越多 |
|
|
35
|
+
| worktree / 分支越堆越多 | `verify_delivery_push` 后自动生成 cleanup plan;只对 `push_verified + clean` 判 SAFE,主线程显式 `apply_cleanup` 才删 worktree,branch/证据永远保留 |
|
|
36
36
|
|
|
37
37
|
worker 跑的是 `codex exec`,`model` 透传:主线程留在 Claude,worker 可以挂 DeepSeek 或任何 Codex 配了 provider 的模型,账单分开算。
|
|
38
38
|
|
|
@@ -117,6 +117,8 @@ npx -p codex-supervisor-mcp codex-supervisor-web
|
|
|
117
117
|
|
|
118
118
|
```
|
|
119
119
|
search_works 查这批活派过没有
|
|
120
|
+
preflight_codex_worker 同环境跑 probe,确认 sandbox / guard / base / cache 真可用
|
|
121
|
+
get_worker_preflight 核 probe 的实际 command evidence;passed 才能派目标 worker
|
|
120
122
|
create_codex_worker 一步一个 worker,同一个 session_id,ownedPaths 不重叠
|
|
121
123
|
wait_codex_workers 60 秒一轮,compact: true,没完接着调
|
|
122
124
|
get_worker_result 它说自己做了什么,verification 里是它真跑过的命令
|
|
@@ -144,13 +146,16 @@ land_codex_worker 核过了,落进集成分支
|
|
|
144
146
|
|
|
145
147
|
## 工具
|
|
146
148
|
|
|
147
|
-
|
|
149
|
+
30 个。
|
|
148
150
|
|
|
149
151
|
| 工具 | 入参 | 作用 |
|
|
150
152
|
|---|---|---|
|
|
151
153
|
| `check_workers` | 无参 | 交付新终态、验收失败和需处理goal;新格式第1轮lost/no_work自动恢复一次,未变返回quiet;用宿主定时唤醒调用,每个主线程设独立CODEX_SUPERVISOR_OBSERVER_ID可在重启后接回 |
|
|
154
|
+
| `overview_delta` | `cursor` | 主线程默认轮询入口:只返回 active / needs_attention / ready_to_land / ready_to_clean、cursor 后变化和 next_cursor;不返回全量历史、prompt、diff、event 或 worker capsule |
|
|
152
155
|
| `check_acceptance` | `cwd`, `acceptance`, `baseRef`, `timeoutMs` | 派单前实际运行给定验收命令,不建 worker,不证明 worker 完成;数量 grep 会提示不能证明失败名单和必跑执行 |
|
|
153
|
-
| `
|
|
156
|
+
| `preflight_codex_worker` | `cwd`, `ownedPaths`, `probeCommands`, `baseRef`, `sandbox`, `allowedCommands`, `context`, `contracts`, `networkAccess`, `writableRoots` | 用与目标 worker 相同的 base/sandbox/guard 起短 probe worker;它必须实际跑完每条 probe command。等终态后读 `get_worker_preflight` |
|
|
157
|
+
| `get_worker_preflight` | `task_id` | 返回 probe 的实际 command evidence、运行环境 contract hash 和 `running/passed/failed`;只有 `passed` 才能复用 |
|
|
158
|
+
| `create_codex_worker` | `task`, `cwd`, **`ownedPaths`**, **`goal`**, `preflight_id`, `forbid`, `allowedCommands`, `context`, `contracts`, `externalOutputs`, `networkAccess`, `writableRoots`, `maxRunMs`, `maxTotalMs`, `acceptance`, `session_id`, `session_title`, `session_note`, `dependsOn`, `baseRef`, `sandbox`, `model`, `reasoningEffort`, `title`, `skipGitRepoCheck` | 起一个 worker。`preflight_id` 给了就必须是通过的同环境 probe,base/guard/context 任何变化都会拒绝派工。`dependsOn` 是硬门禁:上游须同项目、成功结算、验收通过(如配置)、已 land,且本路 base 包含其 landed head |
|
|
154
159
|
| `create_codex_followup_worker` | `task_id`, `followup_prompt`, `session_id`, 其余同上 | 开一个新会话,把老 worker 的 prompt、状态、近期事件拼进去 |
|
|
155
160
|
| `resume_codex_worker` | `task_id`, `prompt`, `rebaseOnto`, `acceptance`, `context` | 接同一个 Codex 会话继续跑,`thread_id` 不变。`rebaseOnto` 先把 worktree 挪到主线新头(stash、跳过已合入补丁、重放新增提交、放回),冲突原样退回不起 worker |
|
|
156
161
|
| `wait_codex_workers` | `task_ids`, `mode`(any/all), `timeoutMinutes`, `timeoutMs`, `compact`, `includeEvents`, `eventLimit`, `eventMaxChars`, `eventKinds` | 等终态。默认 60 秒,到点带快照返回,worker 照跑;`compact` 每路只回一行,带 `idle_seconds` / `command_running`,分得清长命令和卡住 |
|
|
@@ -159,9 +164,15 @@ land_codex_worker 核过了,落进集成分支
|
|
|
159
164
|
| `get_worker_diff` | `task_id`, `maxChars`, `paths` | worker 实际改了什么:从 worktree 起点到工作区的 patch,提交没提交都算。`maxChars` 管总量,超了的文件只列名 |
|
|
160
165
|
| `ask_codex_worker` | `task_id`, `question`, `timeoutMs`, `maxChars`, `fresh`, `end` | 旁路问 worker 一句。线程 fork 成只读侧会话,没网络、没 MCP 工具,worker 本身不动。worker 被 resume 过会自动换新 fork,`fresh` 强制换,`end` 删 |
|
|
161
166
|
| `land_codex_worker` | `task_id`, `onto`, `commitMessage`, `ignoreAcceptance`, `allowOutsideOwned` | 把 worker 在 `codex/<id>` 上的提交 cherry-pick 到派单目录的当前分支。目标要干净,冲突回滚,验收 `failed` 拒绝。`commitMessage` 先替它把未提交的改动提交成一笔,`ignoreAcceptance` 放行 |
|
|
167
|
+
| `verify_delivery_push` | `task_id`, `remote`, `branch` | fetch 指定 remote branch 并证明 `landed_head` 已可达;只读验证,不会 push 或部署。通过后记录 `push_verified` 并生成 cleanup plan |
|
|
168
|
+
| `cleanup_plan` | `task_ids`, `project_root` | 生成 15 分钟有效的 SAFE / REVIEW / BLOCKED 计划,含原因、fingerprint 与回收空间估算;SAFE 会进入 `cleanup_eligible` |
|
|
169
|
+
| `apply_cleanup` | `plan_id`, `item_ids` | 只在未过期计划上二次校验 SAFE item 后执行 `git worktree remove/prune`;保留 branch、task、events、JSONL、artifacts |
|
|
170
|
+
| `cleanup_history` | `task_id`, `limit` | 查询 cleanup 的计划、理由、fingerprint 和实际回收记录 |
|
|
162
171
|
| `get_worker_summary` | `task_id` | 一段话:goal、状态、改动、最后一条命令和消息 |
|
|
163
172
|
| `get_codex_worker_status` | `task_id`, `includePrompt`, `promptMaxChars` | 单个 worker 的状态细节 |
|
|
164
173
|
| `get_codex_worker_events` | `task_id`, `limit`, `maxChars`, `kinds` | 原始事件流 |
|
|
174
|
+
| `get_context_snapshot_meta` | `task_id` | 只读 worker context 的 snapshot ID、fact IDs、token 估算和排除项;不返回 capsule 正文或历史记录 |
|
|
175
|
+
| `get_fact` | `fact_id` | 按 ID 审计一条 candidate/verified fact;不会自动扩展进主线程上下文 |
|
|
165
176
|
| `get_worker_goal` | `task_id` | 派单时记的 goal + Codex 原生 goal(token、用时) |
|
|
166
177
|
| `list_codex_workers` | `status`, `includeHistory`, `includeDetails` | 列 worker,默认只看在跑的 |
|
|
167
178
|
| `get_session_works` | `session_id` | 一个 session 的全部 worker。主线程重启后靠它找回那批活 |
|
|
@@ -172,7 +183,15 @@ land_codex_worker 核过了,落进集成分支
|
|
|
172
183
|
|
|
173
184
|
必填的两个:`ownedPaths`(派单前和在跑的 worker 求交集,重叠就拒,只在派单时查)和 `goal.objective`(worker 会建成 Codex 原生 goal)。`session_id` 不传就归不了组,一批活传同一个值。
|
|
174
185
|
|
|
175
|
-
`acceptance` 在 Bash 中启用 `errexit` 和 `pipefail`:未处理的失败会停止检查,`npm test | tail`
|
|
186
|
+
`acceptance` 在 Bash 中启用 `errexit` 和 `pipefail`:未处理的失败会停止检查,`npm test | tail` 中的测试失败也会保留。写 worker 不能只用 `test -s`、`test -f` 或 `[ -e ]` 这类文件存在性命令交付;要加真实 test、endpoint probe 或结构化执行证据。识别到的 test runner 输出 `no tests to run` / `[no test files]` 时,即使退出码是 0 也判失败。预期失败用 `if` 或 `||` 显式处理;超时始终判失败,即使命令收到终止信号后退出 0。Windows 需要 Git for Windows 的 Bash;找不到会报错。显示的输出会裁剪,退出码不会因此改变。
|
|
187
|
+
|
|
188
|
+
普通 worker 启动时会关闭它继承到的 `codex-supervisor` MCP,不能再派 worker、resume、cancel 或改编排状态;主线程是唯一编排者。其他业务 MCP 不受影响;旁问 fork 仍关闭全部 MCP,因为它只允许只读回答。
|
|
189
|
+
|
|
190
|
+
`session_id` 只负责批次、默认门禁和审批,不再把同批 worker 的标题、汇报或 session objective 自动塞进新 worker。worker 只收到内部编译的 context capsule:自身身份/任务、显式依赖和路径/SHA 命中的 verified facts;raw event、完整 diff、历史报告、candidate facts 都只可按需读取。主线程只看 `get_context_snapshot_meta`,需要证据时再显式 `get_fact` / `get_worker_result` / `get_worker_diff`。
|
|
191
|
+
|
|
192
|
+
worker 的最终 JSON 报告会先记录为该 run 的 `candidate` fact,不能跨 work 自动注入;supervisor acceptance 通过后才生成当前 work 的 `verified` outcome,并带 report/acceptance event 来源、base SHA 与 watched paths。验收失败、未配置验收或 worker 自报完成都不会升级成共享真相。
|
|
193
|
+
|
|
194
|
+
交付状态分开:acceptance 通过只是 `verified`,`land_codex_worker` 只是 `landed`,仍不代表远端有这笔提交。需要显式 `verify_delivery_push` fetch 并校验 `landed_head` 已在目标 remote branch 上,才是 `push_verified`;它会自动生成 cleanup plan,SAFE 项进入 `cleanup_eligible`,但永远不会自己删除。该工具绝不代替用户执行 push 或部署。
|
|
176
195
|
|
|
177
196
|
验收命令的环境包含 `CODEX_SUPERVISOR_TASK_ID`、`CODEX_SUPERVISOR_BASE_COMMIT` 和 `CODEX_SUPERVISOR_RUN`;分别是当前任务、当前运行基线和运行次数,rebase/resume 后会更新。
|
|
178
197
|
|
|
@@ -206,7 +225,7 @@ workspace-write默认networkAccess:false;需要ssh/联网验证显式true,
|
|
|
206
225
|
|
|
207
226
|
ownedPaths预留和任务入库在同一事务内,跨MCP并发派单/恢复不能抢同一输出;验收或退出尚未结算时仍保留归属。Git工作区隔离创建失败明确报错,不退回主目录执行。
|
|
208
227
|
|
|
209
|
-
|
|
228
|
+
清理先 `cleanup_plan`(CLI 对应 `npm run cleanup -- --dry-run`)分类 SAFE / REVIEW / BLOCKED;SAFE 要求 `push_verified`、干净、无活跃依赖、Git 注册和路径归属可证明。`apply_cleanup`(CLI `--apply`)会在删除前重验 fingerprint,只执行 `git worktree remove`/`prune`。branch、task row、event、JSONL、artifact 永远保留;脏、未合、未 push、lost/failed 和证明不足的一律不删。
|
|
210
229
|
|
|
211
230
|
## 和 Claude Code 的 subagent 有什么区别
|
|
212
231
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codex-supervisor-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.2",
|
|
4
4
|
"mcpName": "io.github.zriyox/codex-supervisor-mcp",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "MCP server that dispatches and supervises parallel Codex CLI workers, one isolated Git worktree each, with a persisted work state machine.",
|
|
@@ -55,6 +55,11 @@
|
|
|
55
55
|
"src/paths.js",
|
|
56
56
|
"src/prompt.js",
|
|
57
57
|
"src/cleanup.js",
|
|
58
|
+
"src/cleanup-plan.js",
|
|
59
|
+
"src/worker-preflight.js",
|
|
60
|
+
"src/mcp-config.js",
|
|
61
|
+
"src/context-compiler.js",
|
|
62
|
+
"src/overview-delta.js",
|
|
58
63
|
"src/monitor.jsx",
|
|
59
64
|
"src/web-server.js",
|
|
60
65
|
"src/web-app.js",
|
|
@@ -14,29 +14,33 @@ description: 把 Codex CLI 当并行 worker 派活、盯进度、收结果。用
|
|
|
14
14
|
## 派单
|
|
15
15
|
|
|
16
16
|
1. 先 `search_works` 搜一下,别重复派。
|
|
17
|
-
2.
|
|
18
|
-
3. `create_codex_worker`
|
|
19
|
-
4.
|
|
17
|
+
2. 拆功能包。每路写清楚:干什么、能写哪些文件、依赖谁、怎么算做完和谁负责集成。改同一批文件就串行;文件不重叠只是并行前提,不等于依赖已满足。
|
|
18
|
+
3. 写 worker 先 `preflight_codex_worker`:用目标同一份 `baseRef` / `ownedPaths` / `sandbox` / `allowedCommands` / `context` / `networkAccess` / `writableRoots` 跑必要命令。等它终态后 `get_worker_preflight` 必须 `passed`,再把它的 `task_id` 填进 `create_codex_worker.preflight_id`。contract 变了重跑,不能拿宿主 `check_acceptance` 冒充 worker 环境成功。
|
|
19
|
+
4. `create_codex_worker` 派出去。回执只有 `id`、`worktree_path`、`branch`、`owned_paths`、`status`,不回传任务原文。
|
|
20
|
+
5. 长任务配宿主 `/loop 5m check_workers` 定时收活,没变化 quiet,有新结果按 next_step 收。工具会按规则恢复一次,但不会唤醒关闭的主窗口;每个主线程设独立 `CODEX_SUPERVISOR_OBSERVER_ID` 可重启接回。短等用 `wait_codex_workers` 的 `timeoutMs: 60000`、`compact: true`,到点继续同批 task_ids。
|
|
21
|
+
|
|
22
|
+
worker 默认不是调度员:启动时会禁用它继承到的 `codex-supervisor` MCP,不能再派 worker、resume、cancel 或改 session。要拆新路只能主线程决定并派;业务 MCP 仍按原配置可用。旁问 fork 则关闭全部 MCP。
|
|
20
23
|
|
|
21
24
|
| 参数 | 怎么填 |
|
|
22
25
|
|---|---|
|
|
23
26
|
| `task` | 这一路具体干什么。要能直接开工,别写"优化一下"。汇报格式 supervisor 已经附在 task 后面(结论 / 验证 / 没做的),别再要它列改动文件,diff 自己看 |
|
|
24
27
|
| `cwd` | 项目根目录。worker 在自己的 worktree 里干活,不动你的工作区 |
|
|
25
|
-
| `acceptance` | 这一步"做完了"的判据,
|
|
28
|
+
| `acceptance` | 这一步"做完了"的判据,worker 退出后 supervisor 在它的 worktree 里逐条跑。写 worker 不能只用 `test -s/-f`、`[ -e ]` 这类文件存在性检查;要有真实 test、endpoint probe 或结构化执行证据。识别到的 test runner 输出 `no tests to run` / `[no test files]` 即使 exit 0 也失败。必跑用例、skip、旧报告和失败身份用 `{command,reportPath,baseline}` 结构化验收证明;远端机器的检查包进 `ssh` |
|
|
26
29
|
| `forbid` / `allowedCommands` | 原样声明红线与验证命令;守卫拒绝未声明Shell程序,编辑用apply_patch |
|
|
27
30
|
| `writableRoots` | 只有需要凭据目录时才传(绝对路径、已存在、自动解析软链、只对 workspace-write 生效):ssh/远程测试 → `["~/.ssh"]`;kubectl → `["~/.kube"]`;推私有镜像 → `["~/.docker"]`;aws cli → `["~/.aws"]`;签名提交 → `["~/.gnupg"]`。缓存目录不用写,已经自动加 |
|
|
28
31
|
| `ownedPaths` | 必填。这路允许写的路径,和在跑的 worker 重叠会被拒(**读不排他**,多路读同一份共享文件合法)。冲突是好事,说明该改拆法。传 `[]` 表示这路不落地:只读验证或研究 |
|
|
29
32
|
| `goal.objective` | 必填。一句话说目标,worker 会建成 Codex 原生 goal |
|
|
30
|
-
| `session_id` |
|
|
31
|
-
| `dependsOn` | 有先后依赖填上游的 `task_id` |
|
|
33
|
+
| `session_id` | 同一批传同一个值。只管批次、默认验收和审批,不是上下文继承边界;第一路顺手带 `session_title`(30 字内,看板和 `get_session_works` 显示它),漏了用 `describe_session` 补 |
|
|
34
|
+
| `dependsOn` | 有先后依赖填上游的 `task_id`,它是硬门禁:上游必须同 `project_root`、成功结算、配置了 acceptance 就已通过、已 `land_codex_worker`,并且本路实际 `baseRef` 包含上游 `landed_head`。没满足先集成/修验收,不会启动下游 |
|
|
32
35
|
| `baseRef` | worktree 从哪个提交切,默认 `HEAD`。第 N+1 步要建立在第 N 步上,填 `codex/<第 N 步 task_id>` |
|
|
36
|
+
| `preflight_id` | 写 worker 必填。先跑 `preflight_codex_worker`,它实际在目标 sandbox/guard 里执行 `probeCommands`;`get_worker_preflight.status` 必须是 `passed`。base、ownedPaths、命令、context、contracts、network、可写根有变化就重跑 |
|
|
33
37
|
| `sandbox` | 默认 `workspace-write`,worker 提交不了(Codex 把 `.git` 设成只读)。要它自己提交就 `danger-full-access`,否则收活时让 supervisor 替它提交 |
|
|
34
38
|
|
|
35
|
-
验收用 Bash 的 `errexit` + `pipefail`:`npm test | tail`
|
|
39
|
+
验收用 Bash 的 `errexit` + `pipefail`:`npm test | tail` 不能吞失败;文件存在只可做附加门禁,不能单独证明业务完成。预期失败用 `if` / `||` 显式判。超时、`no tests to run`、`[no test files]` 都失败,别只看退出码 0。Windows 要有 Git for Windows Bash;缺失先修工具,别换回 cmd。
|
|
36
40
|
|
|
37
41
|
验收取当前身份用 `CODEX_SUPERVISOR_TASK_ID` / `CODEX_SUPERVISOR_BASE_COMMIT` / `CODEX_SUPERVISOR_RUN`;不要在命令里写死旧 base,rebase/resume 后这些值会更新。
|
|
38
42
|
|
|
39
|
-
|
|
43
|
+
`check_acceptance` 只是在宿主权限跑验收命令,预检通过不代表 worker sandbox/guard/PATH/cache/network 可用;写 worker 的实际环境预检必须走上面的 `preflight_codex_worker`。已知失败必须按结构化 baseline 的用例名/类型/签名比,必跑项写 required;报告必须标本次 `CODEX_SUPERVISOR_CHECK_ID`,给 complete/identity/failures/executed/skipped,缺失、跳过和旧报告都不算过。reportPath 用工作区内忽略的临时目录,验收报告别混进业务提交。
|
|
40
44
|
|
|
41
45
|
同批公共门禁用 `describe_session.default_acceptance`,自动追加本路验收;更新目标/门禁传 `expected_revision`,避免旧窗口覆盖。需要用户拍板时设 `approval_state: waiting_user`,不得自动resume;获批改approved并同步宿主goal。回执host_goal_sync给当前策略的/goal命令;宿主已有原生goal时,用/goal替换条件,支持ProposeGoal时提议同一condition并走宿主批准。这个条件要求读取最新session revision,批准旧失败或waiting_user后不再追旧目标;工具不偷偷改/禁用Stop hook。
|
|
42
46
|
|
|
@@ -100,7 +104,9 @@ Codex需0.162+支持hooks/output-schema,能力不够派单start_failed先修CL
|
|
|
100
104
|
2. **主线程自己的改动必须 add + commit + push**:`git add <paths> && git commit -m ... && git push`。跳过任何一步都要显式说明,不允许说"改好了"然后留在工作区。
|
|
101
105
|
3. **上线前核对远端,不认本地**:部署或重启服务前先 `git fetch`,再确认目标提交里真有那些改动 —— `git log --oneline origin/<branch> -1`、`git ls-tree -r --name-only origin/<branch> | rg <新文件>`、必要时 `git show origin/<branch>:<path>`。线上报 `NoSuchBeanDefinition`、找不到类/模块、404,先查这一条,再查代码逻辑。
|
|
102
106
|
4. **交付报告三件套**:本地改动 → commit SHA → push 后的远端 SHA(以及部署状态)。缺远端 SHA 就不算完成。
|
|
103
|
-
5.
|
|
107
|
+
5. **push 后计划清理**:`land_codex_worker` 只到本地集成;用户 push 后先 `verify_delivery_push`,它会生成 15 分钟有效的 `cleanup_plan`。只对「push_verified + worktree 干净 + 无活跃依赖 + Git 注册/归属可证明」标 SAFE,并进 `cleanup_eligible`;主线程复核 item 后才 `apply_cleanup(plan_id,item_ids)`。apply 前再验 fingerprint,只执行 `git worktree remove/prune`;**branch、task、event、JSONL、artifact 永远保留**。脏、未合、未 push、lost、failed、证明不足是 BLOCKED/REVIEW,禁止强删。`check_workers` 只提醒,不执行删除。
|
|
108
|
+
|
|
109
|
+
`land_codex_worker` 只到本地集成 `landed`,不是远端交付。用户已经 push 后,主线程调 `verify_delivery_push({task_id,remote:"origin"})`,它只 fetch + 祖先校验、不替你 push/部署;通过才记 `push_verified`,后续才可进入安全 cleanup 候选。
|
|
104
110
|
|
|
105
111
|
典型事故:两个实现类只存在于主线程的 worktree 里,没 add / 没 commit / 没 push,线上跑的还是上一个提交,Spring 找不到 bean 启动失败 —— 不是代码错,是没上线。
|
|
106
112
|
|
|
@@ -111,16 +117,23 @@ Codex需0.162+支持hooks/output-schema,能力不够派单start_failed先修CL
|
|
|
111
117
|
|
|
112
118
|
| 想干什么 | 用哪个 |
|
|
113
119
|
|---|---|
|
|
114
|
-
|
|
|
120
|
+
| 主线程日常增量 | `overview_delta`,保存 `next_cursor`;只看计数和变化 task 摘要 |
|
|
121
|
+
| 全部 worker 的状态 | `get_orchestration_overview`,只在需要全量状态时用 |
|
|
115
122
|
| 一路的完整结论 | `get_worker_result` |
|
|
116
123
|
| 一路改了什么 | `get_worker_diff`;只要文件名用 `get_worker_result` 带 `includeFiles: true` |
|
|
117
124
|
| 活着还是完了 | `get_worker_summary` |
|
|
118
125
|
| 过程 | `get_codex_worker_events`,`kinds` 先滤、`limit` 限条数、`maxChars` 截长串,先看 `available_kinds` |
|
|
119
126
|
| 一路的状态细节 | `get_codex_worker_status`,`current_action` 是它正在跑的命令 |
|
|
120
127
|
| 验收过没过 | 每个读都带 `acceptance`;命令和每条的输出在 `get_worker_result.acceptance.checks` |
|
|
128
|
+
| worker 吃了哪些上下文 | `get_context_snapshot_meta`,只看 fact IDs/token/排除项,不会回 capsule 正文 |
|
|
129
|
+
| 一条共享事实的来源 | `get_fact`,按 ID 精确读;不要把一批 facts 全拉进主线程 |
|
|
121
130
|
|
|
122
131
|
默认读回来的长文本都是裁过的(`current_action` 300 字、`prompt` 300 字、`last_message` 400 字),别把裁剪当成活没干。全量在库里。别一次 `limit: 200` 拉全量事件。
|
|
123
132
|
|
|
133
|
+
worker 的 capsule 只在内部 create/resume 时生成:自身 L0 身份、当前 work 的 verified facts、显式 `dependsOn` 的摘要、路径命中且 SHA 有效的 repo facts。`session_id` peers、raw event、完整 diff/报告、candidate facts 一律不自动注入。主线程只能看 snapshot 元数据;要查证据按 ID 读,不能把自己变成 worker。
|
|
134
|
+
|
|
135
|
+
worker 最终 JSON 只是 `candidate`:先留在本 run 做审计,绝不因为它自己说“完成”就变共享事实。supervisor acceptance 通过才会派生当前 work 的 `verified` outcome;验收失败/未配置、脏 diff、未 land/push 都不是 verified 交付证据。
|
|
136
|
+
|
|
124
137
|
## 断了怎么接
|
|
125
138
|
|
|
126
139
|
| 情况 | 用什么 |
|
|
@@ -145,7 +158,7 @@ overview、派单回执、`wait` 返回里出现 `update` 且 `update_available:
|
|
|
145
158
|
- worktree 只隔离工作区,端口和数据库是共用的。
|
|
146
159
|
- `resume_codex_worker` 不会再建 goal。`cancel_codex_worker` 跨进程靠 pid,要求那个 pid 的命令行里带 `codex`。
|
|
147
160
|
|
|
148
|
-
收尾先 `npm run cleanup -- --dry-run`
|
|
161
|
+
收尾先 `cleanup_plan` 看 SAFE / REVIEW / BLOCKED;只有 push_verified、干净、无活跃依赖且 fingerprint 未变化的 SAFE item 才可 `apply_cleanup`。CLI 对应 `npm run cleanup -- --dry-run` / `--apply`。branch、task、event、JSONL、artifact 保留;脏、未合、未 push、lost/failed和证明不了的一律不删。
|
|
149
162
|
|
|
150
163
|
## 看板
|
|
151
164
|
|
package/src/acceptance.js
CHANGED
|
@@ -23,6 +23,18 @@ export const DEFAULT_ACCEPTANCE_TIMEOUT_MS = 10 * 60 * 1000;
|
|
|
23
23
|
export const MAX_ACCEPTANCE_COMMANDS = 10;
|
|
24
24
|
const OUTPUT_TAIL_BYTES = 2000;
|
|
25
25
|
const KILL_GRACE_MS = 3000;
|
|
26
|
+
const ARTIFACT_ONLY = /^(?:test\s+-[efsd]\s+[^;&|]+|\[\[?\s+-[efsd]\s+[^\]]+\]\]?)$/;
|
|
27
|
+
const TEST_COMMAND = /(?:^|\s)(?:go\s+test|node\s+--test|npm\s+(?:run\s+)?test|pnpm\s+(?:run\s+)?test|yarn\s+test|vitest|jest|pytest|python(?:3)?\s+-m\s+pytest|mvn\s+(?:test|verify)|gradle(?:w)?\s+(?:test|check))(?:\s|$)/i;
|
|
28
|
+
const EMPTY_TEST_OUTPUT = /(?:no\s+tests?\s+to\s+run|no\s+test\s+files|\[no\s+test\s+files\]|0\s+tests?\s+(?:found|collected|run))/i;
|
|
29
|
+
|
|
30
|
+
export function isArtifactOnlyAcceptance(check) {
|
|
31
|
+
const command = typeof check === "string" ? check : check?.command;
|
|
32
|
+
return typeof command === "string" && ARTIFACT_ONLY.test(command.trim());
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function isTestCommand(command) {
|
|
36
|
+
return typeof command === "string" && TEST_COMMAND.test(command);
|
|
37
|
+
}
|
|
26
38
|
|
|
27
39
|
// One string or a list; blanks dropped; an empty list is "not configured".
|
|
28
40
|
export function normalizeAcceptance(value) {
|
|
@@ -242,7 +254,8 @@ export async function runAcceptance(commands, { cwd, env = process.env, timeoutM
|
|
|
242
254
|
}
|
|
243
255
|
});
|
|
244
256
|
control.kill = null;
|
|
245
|
-
result.
|
|
257
|
+
result.empty_test_run = isTestCommand(command) && EMPTY_TEST_OUTPUT.test(result.output_tail ?? "");
|
|
258
|
+
result.passed = result.exit_code === 0 && !result.timed_out && !result.cancelled && !result.empty_test_run;
|
|
246
259
|
if (typeof check !== "string" && result.passed) Object.assign(result, await readCheckEvidence(check, cwd, checkId, baseCommit));
|
|
247
260
|
checks.push(result);
|
|
248
261
|
if (result.cancelled) {
|
package/src/cleanup-hint.js
CHANGED
|
@@ -21,9 +21,9 @@ export async function cleanupHint({ list = readdir, root = supervisorRoot, dir =
|
|
|
21
21
|
return {
|
|
22
22
|
worktrees: entries,
|
|
23
23
|
threshold,
|
|
24
|
-
command: `SUPERVISOR_HOME=${root} npm run cleanup -- --
|
|
25
|
-
apply: `SUPERVISOR_HOME=${root} npm run cleanup -- --
|
|
26
|
-
note: "
|
|
24
|
+
command: `SUPERVISOR_HOME=${root} npm run cleanup -- --dry-run`,
|
|
25
|
+
apply: `SUPERVISOR_HOME=${root} npm run cleanup -- --apply`,
|
|
26
|
+
note: "only push-verified, clean worktrees become SAFE; apply retains branches and evidence"
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
29
|
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
+
import { lstat, realpath, stat } from "node:fs/promises";
|
|
3
|
+
import { execFileSync } from "node:child_process";
|
|
4
|
+
import { isAbsolute, relative, resolve } from "node:path";
|
|
5
|
+
import { ACTIVE_STATUSES } from "./status.js";
|
|
6
|
+
import { worktreesDir } from "./paths.js";
|
|
7
|
+
import { readTasks } from "./task-store.js";
|
|
8
|
+
|
|
9
|
+
export const CLEANUP_PLAN_TTL_MS = 15 * 60 * 1000;
|
|
10
|
+
|
|
11
|
+
function git(cwd, args) {
|
|
12
|
+
return execFileSync(process.env.GIT_BIN?.trim() || "git", ["--no-optional-locks", "-C", cwd, ...args], {
|
|
13
|
+
encoding: "utf8",
|
|
14
|
+
timeout: 15000,
|
|
15
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
16
|
+
}).trim();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function hash(value) {
|
|
20
|
+
return createHash("sha256").update(value).digest("hex");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function directoryBytes(path) {
|
|
24
|
+
try {
|
|
25
|
+
const output = execFileSync("du", ["-sk", path], { encoding: "utf8", timeout: 30000, stdio: ["ignore", "pipe", "ignore"] }).trim();
|
|
26
|
+
const kib = Number(output.split(/\s+/)[0]);
|
|
27
|
+
return Number.isFinite(kib) ? kib * 1024 : 0;
|
|
28
|
+
} catch {
|
|
29
|
+
return 0;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function taskVerdict(task, tasks) {
|
|
34
|
+
if (task.status !== "completed") return { verdict: "blocked", reasons: ["worker is unfinished, failed, cancelled or lost"] };
|
|
35
|
+
if (task.acceptance_results && task.acceptance_results.passed !== true) return { verdict: "blocked", reasons: ["acceptance is not passed"] };
|
|
36
|
+
if (tasks.some((other) => ACTIVE_STATUSES.has(other.status) && (other.depends_on ?? []).includes(task.id))) return { verdict: "blocked", reasons: ["an active dependent still needs this work"] };
|
|
37
|
+
if (!task.worktree_path || !task.project_root) return { verdict: "review", reasons: ["no registered isolated worktree"] };
|
|
38
|
+
if (!task.landed_at || !task.landed_head) return { verdict: "blocked", reasons: ["work has not been landed"] };
|
|
39
|
+
if (!task.push_verified_at) return { verdict: "blocked", reasons: ["remote delivery has not been verified"] };
|
|
40
|
+
try {
|
|
41
|
+
const path = resolve(task.worktree_path);
|
|
42
|
+
if (path !== resolve(worktreesDir, task.id)) return { verdict: "review", reasons: ["worktree is outside its managed task directory"] };
|
|
43
|
+
const info = await lstat(path);
|
|
44
|
+
if (info.isSymbolicLink()) return { verdict: "review", reasons: ["worktree is a symlink"] };
|
|
45
|
+
if (await realpath(path) !== await realpath(resolve(worktreesDir, task.id))) return { verdict: "review", reasons: ["worktree realpath is unexpected"] };
|
|
46
|
+
const branch = git(path, ["symbolic-ref", "--short", "HEAD"]);
|
|
47
|
+
if (branch !== `codex/${task.id}`) return { verdict: "review", reasons: ["worktree branch ownership is unexpected"] };
|
|
48
|
+
const registrations = git(task.project_root, ["worktree", "list", "--porcelain", "-z"]).split("\0").filter((line) => line.startsWith("worktree "));
|
|
49
|
+
let registered = false;
|
|
50
|
+
for (const line of registrations) if (await realpath(line.slice(9)) === await realpath(path)) registered = true;
|
|
51
|
+
if (!registered) return { verdict: "review", reasons: ["git worktree registration is missing"] };
|
|
52
|
+
if (git(path, ["status", "--porcelain", "--untracked-files=all"])) return { verdict: "blocked", reasons: ["worktree has uncommitted or untracked files"] };
|
|
53
|
+
if (git(path, ["ls-files", "--others", "--ignored", "--exclude-standard"])) return { verdict: "blocked", reasons: ["worktree has ignored artifacts"] };
|
|
54
|
+
if (task.attention_reason) return { verdict: "blocked", reasons: [`unresolved attention: ${task.attention_reason}`] };
|
|
55
|
+
if (task.run_evidence?.external_outputs?.length) return { verdict: "blocked", reasons: ["shared output evidence is retained"] };
|
|
56
|
+
return {
|
|
57
|
+
verdict: "safe",
|
|
58
|
+
reasons: ["acceptance passed", "landed", "remote delivery verified", "worktree clean", "no active dependent"],
|
|
59
|
+
fingerprint: hash(JSON.stringify({ path, branch, head: git(path, ["rev-parse", "HEAD"]), landed: task.landed_head, push: task.push_verified_at }))
|
|
60
|
+
};
|
|
61
|
+
} catch (error) {
|
|
62
|
+
return { verdict: "review", reasons: [`cleanup proof failed: ${error.message.split("\n")[0]}`] };
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export async function createCleanupPlan({ taskIds = null, projectRoot = null, now = Date.now() } = {}) {
|
|
67
|
+
const tasks = await readTasks();
|
|
68
|
+
const selected = tasks.filter((task) => (!taskIds || taskIds.includes(task.id)) && (!projectRoot || resolve(task.project_root) === resolve(projectRoot)));
|
|
69
|
+
const items = [];
|
|
70
|
+
for (const task of selected) {
|
|
71
|
+
const result = await taskVerdict(task, tasks);
|
|
72
|
+
const bytes = result.verdict === "safe" ? await directoryBytes(task.worktree_path) : 0;
|
|
73
|
+
items.push({ task_id: task.id, verdict: result.verdict, reasons: result.reasons, fingerprint: result.fingerprint ?? null, reclaimable_bytes: bytes, eligible_after: result.verdict === "safe" ? new Date(now).toISOString() : null });
|
|
74
|
+
}
|
|
75
|
+
const summary = {
|
|
76
|
+
safe: items.filter((item) => item.verdict === "safe").length,
|
|
77
|
+
review: items.filter((item) => item.verdict === "review").length,
|
|
78
|
+
blocked: items.filter((item) => item.verdict === "blocked").length,
|
|
79
|
+
reclaimable_bytes: items.reduce((sum, item) => sum + item.reclaimable_bytes, 0)
|
|
80
|
+
};
|
|
81
|
+
return {
|
|
82
|
+
id: randomUUID(),
|
|
83
|
+
project_root: projectRoot ? resolve(projectRoot) : null,
|
|
84
|
+
generated_at: new Date(now).toISOString(),
|
|
85
|
+
expires_at: new Date(now + CLEANUP_PLAN_TTL_MS).toISOString(),
|
|
86
|
+
policy: "explicit_apply_keep_evidence_and_branch",
|
|
87
|
+
summary,
|
|
88
|
+
items
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export async function removePlannedWorktree(task, fingerprint) {
|
|
93
|
+
const result = await taskVerdict(task, await readTasks());
|
|
94
|
+
if (result.verdict !== "safe") throw new Error(`worktree is no longer safe: ${result.reasons.join("; ")}`);
|
|
95
|
+
if (result.fingerprint !== fingerprint) throw new Error("worktree changed since cleanup plan; create a new plan");
|
|
96
|
+
git(task.project_root, ["worktree", "remove", task.worktree_path]);
|
|
97
|
+
try { git(task.project_root, ["worktree", "prune"]); } catch { /* best effort */ }
|
|
98
|
+
}
|
package/src/cleanup.js
CHANGED
|
@@ -1,47 +1,20 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { execFileSync } from "node:child_process";
|
|
5
|
-
import { deleteTasks, readTasks, vacuumStore } from "./task-store.js";
|
|
6
|
-
import { runsDir, worktreesDir } from "./paths.js";
|
|
7
|
-
import { ACTIVE_STATUSES, TERMINAL_STATUSES } from "./status.js";
|
|
2
|
+
import { createCleanupPlan, removePlannedWorktree } from "./cleanup-plan.js";
|
|
3
|
+
import { appendTaskEvent, getTask, markCleanupPlanItemApplied, saveCleanupPlan, updateWorkItemDelivery, runIdFor } from "./task-store.js";
|
|
8
4
|
|
|
9
5
|
function parseArgs(argv) {
|
|
10
|
-
const options = {
|
|
11
|
-
days: 14,
|
|
12
|
-
dryRun: true,
|
|
13
|
-
includeFailed: true,
|
|
14
|
-
keepRecords: false,
|
|
15
|
-
vacuum: false
|
|
16
|
-
};
|
|
17
|
-
|
|
6
|
+
const options = { apply: false, taskIds: [] };
|
|
18
7
|
for (let index = 0; index < argv.length; index += 1) {
|
|
19
8
|
const arg = argv[index];
|
|
20
|
-
if (arg === "--
|
|
21
|
-
|
|
9
|
+
if (arg === "--apply") options.apply = true;
|
|
10
|
+
else if (arg === "--dry-run") options.apply = false;
|
|
11
|
+
else if (arg === "--task") {
|
|
12
|
+
options.taskIds.push(argv[index + 1]);
|
|
22
13
|
index += 1;
|
|
23
|
-
} else if (arg === "--
|
|
24
|
-
|
|
25
|
-
} else if (arg === "--dry-run") {
|
|
26
|
-
options.dryRun = true;
|
|
27
|
-
} else if (arg === "--keep-failed") {
|
|
28
|
-
options.includeFailed = false;
|
|
29
|
-
} else if (arg === "--keep-records") {
|
|
30
|
-
// Remove the directory and the branch, keep the task row and its run log:
|
|
31
|
-
// the work is merged, but the ledger of what ran stays.
|
|
32
|
-
options.keepRecords = true;
|
|
33
|
-
} else if (arg === "--vacuum") {
|
|
34
|
-
options.vacuum = true;
|
|
35
|
-
} else if (arg === "--help" || arg === "-h") {
|
|
36
|
-
options.help = true;
|
|
37
|
-
} else {
|
|
38
|
-
throw new Error(`Unknown argument: ${arg}`);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (!Number.isFinite(options.days) || options.days < 0) {
|
|
43
|
-
throw new Error("--days must be a non-negative number");
|
|
14
|
+
} else if (arg === "--help" || arg === "-h") options.help = true;
|
|
15
|
+
else throw new Error(`Unknown argument: ${arg}`);
|
|
44
16
|
}
|
|
17
|
+
if (options.taskIds.some((id) => !id)) throw new Error("--task requires a task id");
|
|
45
18
|
return options;
|
|
46
19
|
}
|
|
47
20
|
|
|
@@ -49,74 +22,13 @@ function printHelp() {
|
|
|
49
22
|
console.log(`Usage: npm run cleanup -- [options]
|
|
50
23
|
|
|
51
24
|
Options:
|
|
52
|
-
--dry-run
|
|
53
|
-
--apply
|
|
54
|
-
--
|
|
55
|
-
--keep-failed Preserve failed/cancelled tasks even when older than --days.
|
|
56
|
-
--keep-records Remove the worktree and branch but keep the task row and run log.
|
|
57
|
-
--vacuum Vacuum SQLite after deleting rows.
|
|
25
|
+
--dry-run Create and print a SAFE / REVIEW / BLOCKED plan. Default.
|
|
26
|
+
--apply Remove every SAFE worktree in the generated plan.
|
|
27
|
+
--task <task_id> Limit the plan to one task; repeatable.
|
|
58
28
|
-h, --help Show help.
|
|
59
|
-
`);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function isTerminal(task) {
|
|
63
|
-
return TERMINAL_STATUSES.has(task.status);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function isDeleteCandidate(task, cutoffMs, includeFailed) {
|
|
67
|
-
if (!isTerminal(task)) return false;
|
|
68
|
-
if (!includeFailed && ["failed", "cancelled", "lost"].includes(task.status)) return false;
|
|
69
|
-
const completedAt = Date.parse(task.completed_at ?? task.updated_at ?? task.created_at);
|
|
70
|
-
return Number.isFinite(completedAt) && completedAt < cutoffMs;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
async function safeDeleteFile(path, dryRun) {
|
|
74
|
-
try {
|
|
75
|
-
const rel = relative(await realpath(runsDir), await realpath(path));
|
|
76
|
-
if (rel === ".." || rel.startsWith(`..${process.platform === "win32" ? "\\" : "/"}`) || isAbsolute(rel)) return false;
|
|
77
|
-
const info = await lstat(path);
|
|
78
|
-
if (!info.isFile() || info.isSymbolicLink()) return false;
|
|
79
|
-
if (!dryRun) await rm(path, { force: true });
|
|
80
|
-
return true;
|
|
81
|
-
} catch {
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
29
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
async function cleanupReason(task, tasks) {
|
|
91
|
-
if (task.status !== "completed") return "unfinished, failed or lost work is preserved";
|
|
92
|
-
if (task.acceptance_results && task.acceptance_results.passed !== true) return "acceptance is not passed";
|
|
93
|
-
if (tasks.some((other) => ACTIVE_STATUSES.has(other.status) && (other.depends_on ?? []).includes(task.id))) return "active dependent still needs this worktree";
|
|
94
|
-
if (!task.worktree_path || !task.project_root) return "no registered isolated worktree";
|
|
95
|
-
try {
|
|
96
|
-
const path = resolve(task.worktree_path);
|
|
97
|
-
if (path !== resolve(worktreesDir, task.id)) return "worktree is outside its managed task directory";
|
|
98
|
-
if ((await lstat(path)).isSymbolicLink()) return "symlink worktree is preserved";
|
|
99
|
-
if (await realpath(path) !== await realpath(resolve(worktreesDir, task.id))) return "unexpected worktree path";
|
|
100
|
-
const branch = git(path, ["symbolic-ref", "--short", "HEAD"]);
|
|
101
|
-
if (branch !== `codex/${task.id}`) return "unexpected branch ownership";
|
|
102
|
-
const registrations = git(task.project_root, ["worktree", "list", "--porcelain", "-z"]).split("\0").filter((line) => line.startsWith("worktree "));
|
|
103
|
-
let registered = false;
|
|
104
|
-
for (const line of registrations) {
|
|
105
|
-
if (await realpath(line.slice(9)) === await realpath(path)) registered = true;
|
|
106
|
-
}
|
|
107
|
-
if (!registered) return "worktree registration is missing";
|
|
108
|
-
if (git(path, ["status", "--porcelain", "--untracked-files=all"])) return "dirty worktree contains uncommitted files";
|
|
109
|
-
if (git(path, ["ls-files", "--others", "--ignored", "--exclude-standard"])) return "ignored artifacts are preserved";
|
|
110
|
-
if (task.attention_reason) return `unresolved attention: ${task.attention_reason}`;
|
|
111
|
-
if (task.externalOutputs?.length || task.run_evidence?.external_outputs?.length) return "shared output evidence is preserved";
|
|
112
|
-
if (!task.landed_at || !task.base_commit) return "unlanded work is preserved";
|
|
113
|
-
// Patch equivalence covers cherry-pick landing even when ancestry differs.
|
|
114
|
-
const remaining = git(path, ["cherry", task.project_root ? git(task.project_root, ["rev-parse", "HEAD"]) : "HEAD", "HEAD", task.base_commit]);
|
|
115
|
-
if (remaining.split("\n").some((line) => line.startsWith("+"))) return "unlanded commits remain";
|
|
116
|
-
return null;
|
|
117
|
-
} catch (error) {
|
|
118
|
-
return `cleanup proof failed: ${error.message.split("\n")[0]}`;
|
|
119
|
-
}
|
|
30
|
+
Cleanup never removes branches, task rows, events, JSONL logs or artifacts.
|
|
31
|
+
`);
|
|
120
32
|
}
|
|
121
33
|
|
|
122
34
|
const options = parseArgs(process.argv.slice(2));
|
|
@@ -125,60 +37,36 @@ if (options.help) {
|
|
|
125
37
|
process.exit(0);
|
|
126
38
|
}
|
|
127
39
|
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
const
|
|
40
|
+
const plan = await createCleanupPlan({ taskIds: options.taskIds.length ? options.taskIds : null });
|
|
41
|
+
await saveCleanupPlan(plan);
|
|
42
|
+
const applied = [];
|
|
131
43
|
const skipped = [];
|
|
132
|
-
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
else candidates.push(task);
|
|
136
|
-
}
|
|
137
|
-
const taskIds = candidates.map((task) => task.id);
|
|
138
|
-
|
|
139
|
-
const deleted = {
|
|
140
|
-
tasks: 0,
|
|
141
|
-
jsonl: 0,
|
|
142
|
-
worktrees: 0
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
const removedIds = [];
|
|
146
|
-
for (const task of candidates) {
|
|
147
|
-
if (!options.dryRun) {
|
|
148
|
-
const current = (await readTasks()).find((item) => item.id === task.id);
|
|
149
|
-
const reason = current ? await cleanupReason(current, await readTasks()) : "task disappeared";
|
|
150
|
-
if (reason) { skipped.push({ id: task.id, reason }); continue; }
|
|
44
|
+
if (options.apply) {
|
|
45
|
+
for (const item of plan.items.filter((entry) => entry.verdict === "safe")) {
|
|
46
|
+
const task = await getTask(item.task_id);
|
|
151
47
|
try {
|
|
152
|
-
|
|
153
|
-
|
|
48
|
+
await removePlannedWorktree(task, item.fingerprint);
|
|
49
|
+
const now = await markCleanupPlanItemApplied(item.id, "cleanup_cli");
|
|
50
|
+
await updateWorkItemDelivery(task.id, "cleanup_removed");
|
|
51
|
+
await appendTaskEvent(task.id, { type: "supervisor.cleanup_removed", plan_id: plan.id, item_id: item.id, removed_at: now, retained: ["branch", "task", "events", "jsonl", "artifacts"] }, {
|
|
52
|
+
runId: runIdFor(task.id, task.run_count ?? 1), actor: "supervisor"
|
|
53
|
+
});
|
|
54
|
+
applied.push({ task_id: task.id, worktree_path: task.worktree_path, removed_at: now });
|
|
154
55
|
} catch (error) {
|
|
155
|
-
skipped.push({
|
|
156
|
-
continue;
|
|
56
|
+
skipped.push({ task_id: item.task_id, reason: error.message.split("\n")[0] });
|
|
157
57
|
}
|
|
158
58
|
}
|
|
159
|
-
deleted.worktrees += 1;
|
|
160
|
-
const logPath = task.run_log ?? join(runsDir, `${task.id}.jsonl`);
|
|
161
|
-
if (!options.keepRecords) {
|
|
162
|
-
if (await safeDeleteFile(logPath, options.dryRun)) deleted.jsonl += 1;
|
|
163
|
-
removedIds.push(task.id);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
if (!options.dryRun && !options.keepRecords && removedIds.length > 0) {
|
|
168
|
-
await deleteTasks(removedIds);
|
|
169
|
-
}
|
|
170
|
-
deleted.tasks = removedIds.length;
|
|
171
|
-
|
|
172
|
-
if (!options.dryRun && options.vacuum) {
|
|
173
|
-
await vacuumStore();
|
|
174
59
|
}
|
|
175
60
|
|
|
176
61
|
console.log(JSON.stringify({
|
|
177
|
-
dry_run: options.
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
62
|
+
dry_run: !options.apply,
|
|
63
|
+
plan_id: plan.id,
|
|
64
|
+
generated_at: plan.generated_at,
|
|
65
|
+
expires_at: plan.expires_at,
|
|
66
|
+
policy: plan.policy,
|
|
67
|
+
summary: plan.summary,
|
|
68
|
+
items: plan.items,
|
|
69
|
+
applied,
|
|
182
70
|
skipped,
|
|
183
|
-
|
|
71
|
+
retained: ["branch", "task", "events", "jsonl", "artifacts"]
|
|
184
72
|
}, null, 2));
|