codex-supervisor-mcp 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +6 -1
- package/README.md +6 -1
- package/package.json +2 -2
- package/skills/codex-supervisor/SKILL.md +4 -2
- package/src/app/cancel.js +11 -14
- package/src/app/cleanup-facts.js +14 -12
- package/src/app/cleanup-plan.js +19 -18
- package/src/app/compose.js +13 -3
- package/src/app/dispatch.js +12 -12
- package/src/app/followup.js +5 -0
- package/src/app/resume.js +15 -18
- package/src/app/side-chat.js +41 -20
- package/src/app/worktree-setup.js +43 -2
- package/src/domain/failure-class.js +34 -2
- package/src/domain/prompt.js +7 -3
- package/src/domain/status.js +8 -4
- package/src/domain/worker-preflight.js +6 -2
- package/src/infra/crash-guard.js +44 -0
- package/src/infra/git.js +35 -4
- package/src/infra/stage-store.js +1 -1
- package/src/infra/store/event-body.js +82 -0
- package/src/infra/store/events.js +7 -5
- package/src/infra/store/runner-readers.js +1 -1
- package/src/infra/store/tasks.js +15 -1
- package/src/infra/worktree.js +25 -5
- package/src/interface/bin/web-server.js +2 -0
- package/src/interface/mcp/handlers/dispatch.js +3 -0
- package/src/interface/mcp/handlers/overview.js +4 -1
- package/src/interface/mcp/handlers/results.js +11 -4
- package/src/interface/mcp/handlers/wait.js +5 -3
- package/src/interface/mcp/server.js +3 -0
- package/src/interface/mcp/tools/dispatch.js +7 -5
- package/src/interface/mcp/tools/shapes.js +1 -0
- package/src/interface/web/app.js +2 -2
- package/src/interface/web/views.js +5 -3
- package/src/run-host/entry.js +3 -0
- package/src/run-host/finalize.js +8 -1
- package/src/run-host/launch.js +5 -19
- package/src/run-host/live-run.js +4 -1
- package/src/run-host/streams.js +35 -9
- package/src/run-host/track.js +8 -4
- package/src/runners/claude/adapter.js +118 -0
- package/src/runners/claude/events.js +100 -0
- package/src/runners/claude/tool-guard.js +48 -0
- package/src/runners/codex/adapter.js +57 -0
- package/src/runners/codex/mcp-config.js +4 -0
- package/src/runners/contract-check.js +82 -0
- package/src/runners/contract.js +53 -0
- package/src/runners/registry.js +45 -0
- package/web/dist/assets/{index-fJQbspTY.js → index-BnV-AYYI.js} +1 -1
- package/web/dist/assets/index-f8esISCp.css +2 -0
- package/web/dist/index.html +2 -2
- package/web/dist/assets/index-DI1hLMxE.css +0 -2
package/README.en.md
CHANGED
|
@@ -18,6 +18,8 @@ codex-supervisor-mcp is an MCP server. A main thread (Claude Code, Codex, or any
|
|
|
18
18
|
|
|
19
19
|
*30 seconds, recorded live: three workers in their own worktrees in parallel, then the main thread collects three diffs and makes one commit.*
|
|
20
20
|
|
|
21
|
+
> **Upgrading from 0.x to 1.x**: 39 tools became 14, with new names and arguments and no aliases for the old ones. Finish the workers in flight first, then reopen the session after upgrading so the new skill loads. The tool table is in the [reference](docs/reference.en.md); what changed is in the [1.0.0 release](https://github.com/zriyox/codex-supervisor-mcp/releases/tag/v1.0.0).
|
|
22
|
+
|
|
21
23
|
## What it solves
|
|
22
24
|
|
|
23
25
|
| Problem | What it does |
|
|
@@ -30,7 +32,9 @@ codex-supervisor-mcp is an MCP server. A main thread (Claude Code, Codex, or any
|
|
|
30
32
|
| Changes sit on a local branch | `land_worker` merges into the integration branch; `verify_push` proves the commit is on the remote |
|
|
31
33
|
| Worktrees pile up | Landed or unchanged ones are removed during polling. Unlanded work is kept for 7 days, and its uncommitted edits are committed to its branch before the worktree goes. Branches and evidence stay |
|
|
32
34
|
|
|
33
|
-
A worker is a `codex exec` process and `model` is passed straight through. Keep the main thread on Claude, put the workers on DeepSeek or another provider, and the bills stay separate.
|
|
35
|
+
A worker is a `codex exec` process by default and `model` is passed straight through. Keep the main thread on Claude, put the workers on DeepSeek or another provider, and the bills stay separate.
|
|
36
|
+
|
|
37
|
+
A worker can also be Claude Code: pass `runner: "claude"` to `create_worker`. It has no OS sandbox, so it runs only in a git worktree or read-only, and it has no side chat (`ask_worker`); dispatch, acceptance, resume, landing and cleanup are the same. To add another CLI, see [docs/runner.md](docs/runner.md).
|
|
34
38
|
|
|
35
39
|
## Five minutes to a running batch
|
|
36
40
|
|
|
@@ -169,6 +173,7 @@ rm -rf ~/.claude/skills/codex-supervisor ~/.agents/skills/codex-supervisor ~/.co
|
|
|
169
173
|
| `codex only resolved to a shell shim` | Windows found only the `.cmd`; the package entry is gone | Reinstall `@openai/codex`, or point `CODEX_BIN` at `codex.js` |
|
|
170
174
|
| `Cannot find module 'node:sqlite'` | Node older than 22.13.0 | Upgrade Node |
|
|
171
175
|
| Worker is `lost` | The worker or its run process was killed | Read the events, then `resume_worker` |
|
|
176
|
+
| Worker is `timed_out` | Its time budget ran out and it was stopped | Read what it left; `resume_worker` after a per-run limit, `followup_of` with new `limits` after the total one |
|
|
172
177
|
| `git add` fails with `index.lock: Operation not permitted` | The sandbox makes `.git` read-only. That is the intended boundary | Let `land_worker` commit with `commit_message` |
|
|
173
178
|
| `owned_paths overlap with active worker(s)` | Two workers claimed the same paths | Split the work differently, or cancel the one holding them |
|
|
174
179
|
| The board is empty | The board and the MCP server use different `SUPERVISOR_HOME` | Point both at the same directory |
|
package/README.md
CHANGED
|
@@ -18,6 +18,8 @@ codex-supervisor-mcp 是一个 MCP server。主线程(Claude Code、Codex 或
|
|
|
18
18
|
|
|
19
19
|
*30 秒真跑:派 3 个 worker,各自 worktree 并行,主线程收 3 份 diff 合成一次 commit。*
|
|
20
20
|
|
|
21
|
+
> **从 0.x 升级到 1.x**:工具从 39 个收成 14 个,名字和参数都换了,旧名不留别名。升级前先把在跑的 worker 收完,升级后重开会话让新 skill 生效。对照表在[参考手册](docs/reference.md),变更说明在 [1.0.0 release](https://github.com/zriyox/codex-supervisor-mcp/releases/tag/v1.0.0)。
|
|
22
|
+
|
|
21
23
|
## 解决什么
|
|
22
24
|
|
|
23
25
|
| 问题 | 做法 |
|
|
@@ -30,7 +32,9 @@ codex-supervisor-mcp 是一个 MCP server。主线程(Claude Code、Codex 或
|
|
|
30
32
|
| 改动留在本地没上线 | `land_worker` 合回主分支,`verify_push` 核对远端真有这笔提交 |
|
|
31
33
|
| worktree 越堆越多 | 已合入或没有改动的在轮询时自动清;没合入的留 7 天,删之前先把未提交的改动存进它的分支。分支和证据不删 |
|
|
32
34
|
|
|
33
|
-
worker
|
|
35
|
+
worker 默认跑 `codex exec`,`model` 透传。主线程留在 Claude,worker 挂 DeepSeek 或别的 provider,账单分开算。
|
|
36
|
+
|
|
37
|
+
worker 也可以是 Claude Code:`create_worker` 带 `runner: "claude"`。它没有系统级沙箱,所以只能在 git worktree 或只读模式下跑,也不支持旁问(`ask_worker`);其余派单、验收、续跑、合入、清理都一样。想接别的 CLI,看 [docs/runner.md](docs/runner.md)。
|
|
34
38
|
|
|
35
39
|
## 五分钟跑起来
|
|
36
40
|
|
|
@@ -168,6 +172,7 @@ rm -rf ~/.claude/skills/codex-supervisor ~/.agents/skills/codex-supervisor ~/.co
|
|
|
168
172
|
| `codex only resolved to a shell shim` | Windows 只找到 `.cmd`,包入口没了 | 重装 `@openai/codex`,或 `CODEX_BIN` 指到 `codex.js` |
|
|
169
173
|
| `Cannot find module 'node:sqlite'` | Node 低于 22.13.0 | 升 Node |
|
|
170
174
|
| worker `lost` | worker 或它的运行进程被杀了 | 查事件,`resume_worker` 接回 |
|
|
175
|
+
| worker `timed_out` | 时间预算用完被停掉 | 看已有改动;单轮超时 `resume_worker`,总预算用完用 `followup_of` 带新 `limits` 接续 |
|
|
171
176
|
| `git add` 报 `index.lock: Operation not permitted` | 沙箱把 `.git` 设成只读,这是正常边界 | 让 `land_worker` 带 `commit_message` 代提交 |
|
|
172
177
|
| `owned_paths overlap with active worker(s)` | 两路认领了同一片路径 | 改拆法,或取消占着的那路 |
|
|
173
178
|
| 看板是空的 | 看板和 MCP 的 `SUPERVISOR_HOME` 不一样 | 两边指同一个目录 |
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codex-supervisor-mcp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"mcpName": "io.github.zriyox/codex-supervisor-mcp",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"description": "MCP server that
|
|
6
|
+
"description": "MCP server that runs parallel Codex CLI or Claude Code workers from any MCP client: one Git worktree each, 14 tools to dispatch, track, check, land and clean up, state on disk.",
|
|
7
7
|
"homepage": "https://codex-supervisor.zriyo.com",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"repository": {
|
|
@@ -37,7 +37,7 @@ description: 用 Codex CLI 并行做可独立验收的功能包,每路一个 G
|
|
|
37
37
|
|
|
38
38
|
## create_worker 的参数
|
|
39
39
|
|
|
40
|
-
顶层:`task`、`cwd`、`owned_paths`、`goal`、`title`、`followup_of`、`depends_on`、`preflight_id`、`model`、`reasoning_effort`。其余按组放进对象:
|
|
40
|
+
顶层:`task`、`cwd`、`owned_paths`、`goal`、`title`、`followup_of`、`depends_on`、`preflight_id`、`runner`、`model`、`reasoning_effort`。其余按组放进对象:
|
|
41
41
|
|
|
42
42
|
```json
|
|
43
43
|
{
|
|
@@ -73,6 +73,7 @@ description: 用 Codex CLI 并行做可独立验收的功能包,每路一个 G
|
|
|
73
73
|
| `acceptance.commands` | worker 退出后由 supervisor 在 worktree 里执行,全部退出 0 才算过。worker 自查统一跑 `node "$AGENT_SUPERVISOR_ACCEPTANCE_CLI"`,不要手抄命令 |
|
|
74
74
|
| `depends_on` | 上游 task id。上游必须已结算、验收通过并 land,且本路 base 包含它 |
|
|
75
75
|
| `followup_of` | 接着一路已结束的 worker 干:从它的分支切新 worktree,没给的参数沿用它的 |
|
|
76
|
+
| `runner` | 用哪个 CLI 当 worker:`codex`(默认)或 `claude`。`claude` 没有系统沙箱:只能 `git_worktree` 或 `read_only_in_place`,shell 只放行只读命令和 `sandbox.allowed_commands` 里声明的命令,不支持 `ask_worker`。preflight 和正式派单要用同一个 runner |
|
|
76
77
|
| `preflight_id` | 写 worker 必填。base、workspace、sandbox、owned_paths、context 有任何变化都要重跑 preflight |
|
|
77
78
|
|
|
78
79
|
回执不回传 task 原文,带 `id`、`worktree_path`、`branch`、`owned_paths`、`status`。
|
|
@@ -112,8 +113,9 @@ description: 用 Codex CLI 并行做可独立验收的功能包,每路一个 G
|
|
|
112
113
|
|---|---|
|
|
113
114
|
| 主线程挂了 | worker 的独立进程会继续记录日志、状态和验收。新窗口用 `find_works` 按 session 接回 |
|
|
114
115
|
| worker 变 `lost` | 确实中断才 `resume_worker`;worktree、改动和线程都保留 |
|
|
116
|
+
| worker 变 `timed_out` | 时间预算用完被停掉,不会自动重试。先看已有改动;`run_time_limit` 可以 `resume_worker`(每轮重新计时),`total_time_limit` 只能 `followup_of` 带新 `limits` 接续 |
|
|
115
117
|
| worktree 落后主线 | `resume_worker` 带 `rebase_onto: "HEAD"` |
|
|
116
|
-
| worker 失败 | 先看 `failure
|
|
118
|
+
| worker 失败 | 先看 `failure`:`source` 是 `auth`(登录或 key,重试没用)、`provider`(上游,`retryable` 为 true 就等一会再 resume)、`runner_config`(配置或模型名)、`workspace_setup`、`model_output`、`acceptance`、`time_limit`、`worker_process`。进程非零退出时 `failure.detail` 是它 stderr 的最后一行 |
|
|
117
119
|
| worktree 被清掉了 | 照常 `resume_worker` / `land_worker` / `get_worker_diff` / `ask_worker`,会从分支切回来 |
|
|
118
120
|
|
|
119
121
|
审批、认证、权限、quota 和时间限制造成的停顿不会被自动重试。
|
package/src/app/cancel.js
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
1
|
import "./compose.js";
|
|
2
2
|
import { describeProcess } from "../infra/process.js";
|
|
3
3
|
import { getTask, upsertTask } from "../infra/store/tasks.js";
|
|
4
|
-
import {
|
|
4
|
+
import { loadRunner } from "../runners/registry.js";
|
|
5
5
|
import { acceptanceRuns, cancelledTasks, processes } from "./run-state.js";
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
7
|
+
// A pid on a row may have been reused; only a process that looks like this runner's CLI is signalled.
|
|
8
|
+
const isWorkerProcess = (task, runner) => runner.ownsPid(task.pid, describeProcess);
|
|
10
9
|
|
|
11
10
|
// Ends a worker and, on Windows, its whole process tree: the direct child there
|
|
12
11
|
// is the JS wrapper around the native Codex binary, so terminating it alone
|
|
13
12
|
// would leave the real CLI running and the task stuck in `running`.
|
|
14
|
-
export function terminateChild(child) {
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function terminatePid(pid) {
|
|
19
|
-
codexRunner.cancelPid(pid);
|
|
13
|
+
export function terminateChild(child, runner) {
|
|
14
|
+
runner.cancelChild(child);
|
|
20
15
|
}
|
|
21
16
|
|
|
22
17
|
export async function cancelCodexWorker(taskId) {
|
|
@@ -26,21 +21,23 @@ export async function cancelCodexWorker(taskId) {
|
|
|
26
21
|
acceptance.kill?.();
|
|
27
22
|
return { cancelled: true, via: "acceptance", pid: null };
|
|
28
23
|
}
|
|
24
|
+
const task = await getTask(taskId);
|
|
25
|
+
// A runner from outside the package may not be loaded in this process yet.
|
|
26
|
+
const runner = await loadRunner(task?.worker);
|
|
29
27
|
const child = processes.get(taskId);
|
|
30
28
|
if (child) {
|
|
31
29
|
cancelledTasks.add(taskId);
|
|
32
|
-
terminateChild(child);
|
|
30
|
+
terminateChild(child, runner);
|
|
33
31
|
return { cancelled: true, via: "process_handle", pid: child.pid ?? null };
|
|
34
32
|
}
|
|
35
33
|
// Another MCP process owns the handle; fall back to the pid recorded on disk.
|
|
36
|
-
const task = await getTask(taskId);
|
|
37
34
|
if (task?.acceptance_results?.status === "running" && await isPidAlive(task.acceptance_results.supervisor_pid)) {
|
|
38
35
|
await upsertTask({ ...task, cancel_requested_at: new Date().toISOString(), updated_at: new Date().toISOString() });
|
|
39
36
|
return { cancelled: true, via: "acceptance", pid: null };
|
|
40
37
|
}
|
|
41
|
-
if (task?.pid && (await isPidAlive(task.pid)) &&
|
|
38
|
+
if (task?.pid && (await isPidAlive(task.pid)) && isWorkerProcess(task, runner)) {
|
|
42
39
|
try {
|
|
43
|
-
|
|
40
|
+
runner.cancelPid(task.pid);
|
|
44
41
|
return { cancelled: true, via: "pid", pid: task.pid };
|
|
45
42
|
} catch (error) {
|
|
46
43
|
return { cancelled: false, reason: "kill_failed", message: error.message, pid: task.pid };
|
package/src/app/cleanup-facts.js
CHANGED
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
import { branchOf } from "../domain/worker-branch.js";
|
|
3
3
|
import "./compose.js";
|
|
4
4
|
import { ACTIVE_STATUSES, TERMINAL_STATUSES, runIsOver } from "../domain/status.js";
|
|
5
|
-
import {
|
|
5
|
+
import { gitSucceedsAsync, runGitAsync } from "../infra/git.js";
|
|
6
6
|
import { worktreesDir } from "../infra/paths.js";
|
|
7
|
-
import { isPidAlive } from "../infra/store/tasks.js";
|
|
7
|
+
import { isGroupAlive, isPidAlive } from "../infra/store/tasks.js";
|
|
8
8
|
import { parsePorcelainLine, resolveWorktreeBase, workspaceSetupIgnorePaths, worktreeRef } from "../infra/worktree.js";
|
|
9
9
|
import { lstat, realpath } from "node:fs/promises";
|
|
10
10
|
import { resolve } from "node:path";
|
|
11
11
|
|
|
12
12
|
// Raw output: porcelain status lines start with a significant space, and a
|
|
13
13
|
// quoted path would never match a setup path. Callers trim single values.
|
|
14
|
-
const git = (cwd, args) =>
|
|
14
|
+
const git = (cwd, args) => runGitAsync(cwd, args, { timeout: 15000, noOptionalLocks: true, rawPaths: true, trim: false });
|
|
15
15
|
const lines = (text) => text.split("\n").filter(Boolean);
|
|
16
16
|
|
|
17
17
|
function activeReason(task) {
|
|
@@ -19,6 +19,8 @@ function activeReason(task) {
|
|
|
19
19
|
const settled = runIsOver(task);
|
|
20
20
|
if (!settled && task.pid && isPidAlive(task.pid)) return "worker process is still active";
|
|
21
21
|
if (!settled && task.run_host_pid && isPidAlive(task.run_host_pid)) return "run host process is still active";
|
|
22
|
+
// A lost run can leave a process behind that still writes in the worktree; only a recorded exit rules that out.
|
|
23
|
+
if (task.exit_code == null && isGroupAlive(task.run_host_pid)) return "a process of the worker's run is still active";
|
|
22
24
|
const acceptance = task.acceptance_results;
|
|
23
25
|
if (acceptance?.status === "running" || (acceptance?.supervisor_pid && isPidAlive(acceptance.supervisor_pid))) return "acceptance process is still active";
|
|
24
26
|
return null;
|
|
@@ -34,9 +36,9 @@ async function identityProblem(task) {
|
|
|
34
36
|
const info = await lstat(path);
|
|
35
37
|
if (info.isSymbolicLink()) return "worktree is a symlink";
|
|
36
38
|
if (await realpath(path) !== await realpath(managed)) return "worktree realpath is unexpected";
|
|
37
|
-
const branch = git(path, ["symbolic-ref", "--short", "HEAD"]).trim();
|
|
39
|
+
const branch = (await git(path, ["symbolic-ref", "--short", "HEAD"])).trim();
|
|
38
40
|
if (branch !== branchOf(task)) return "worktree branch ownership is unexpected";
|
|
39
|
-
const registered = git(task.project_root, ["worktree", "list", "--porcelain", "-z"]).split("\0").filter((line) => line.startsWith("worktree "));
|
|
41
|
+
const registered = (await git(task.project_root, ["worktree", "list", "--porcelain", "-z"])).split("\0").filter((line) => line.startsWith("worktree "));
|
|
40
42
|
const own = await realpath(path);
|
|
41
43
|
for (const line of registered) {
|
|
42
44
|
// A registration whose directory someone deleted has no realpath; it is not ours either way.
|
|
@@ -58,20 +60,20 @@ function setupFilter(task) {
|
|
|
58
60
|
function isLanded(task) {
|
|
59
61
|
if (!task.landed_at || !task.landed_head) return false;
|
|
60
62
|
const target = task.landed_branch ? `refs/heads/${task.landed_branch}` : "HEAD";
|
|
61
|
-
return
|
|
63
|
+
return gitSucceedsAsync(task.project_root, ["merge-base", "--is-ancestor", task.landed_head, target]);
|
|
62
64
|
}
|
|
63
65
|
|
|
64
|
-
function worktreeState(task) {
|
|
66
|
+
async function worktreeState(task) {
|
|
65
67
|
const path = resolve(task.worktree_path);
|
|
66
68
|
const keep = setupFilter(task);
|
|
67
|
-
const status = lines(git(path, ["status", "--porcelain", "--untracked-files=all"]));
|
|
69
|
+
const status = lines(await git(path, ["status", "--porcelain", "--untracked-files=all"]));
|
|
68
70
|
const uncommittedPaths = status.map(parsePorcelainLine).filter((entry) => entry && keep(entry));
|
|
69
71
|
// Without the base the worker's own commits cannot be counted, and "nothing
|
|
70
72
|
// to keep" could not be told from "cannot tell".
|
|
71
73
|
const base = resolveWorktreeBase(path, worktreeRef(task));
|
|
72
74
|
if (!base) throw new Error("the commit this worker started from is unknown");
|
|
73
|
-
const unlandedCommits = lines(git(path, ["rev-list", `${base}..HEAD`])).length;
|
|
74
|
-
return { uncommittedPaths, unlandedCommits, head: git(path, ["rev-parse", "HEAD"]).trim() };
|
|
75
|
+
const unlandedCommits = lines(await git(path, ["rev-list", `${base}..HEAD`])).length;
|
|
76
|
+
return { uncommittedPaths, unlandedCommits, head: (await git(path, ["rev-parse", "HEAD"])).trim() };
|
|
75
77
|
}
|
|
76
78
|
|
|
77
79
|
export async function cleanupFacts(task, tasks) {
|
|
@@ -86,8 +88,8 @@ export async function cleanupFacts(task, tasks) {
|
|
|
86
88
|
facts.identity = await identityProblem(task);
|
|
87
89
|
if (facts.identity) return facts;
|
|
88
90
|
try {
|
|
89
|
-
const state = worktreeState(task);
|
|
90
|
-
facts.landed = isLanded(task);
|
|
91
|
+
const state = await worktreeState(task);
|
|
92
|
+
facts.landed = await isLanded(task);
|
|
91
93
|
facts.uncommittedPaths = state.uncommittedPaths;
|
|
92
94
|
facts.uncommitted = state.uncommittedPaths.length;
|
|
93
95
|
facts.unlandedCommits = state.unlandedCommits;
|
package/src/app/cleanup-plan.js
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
import { branchOf } from "../domain/worker-branch.js";
|
|
6
6
|
import "./compose.js";
|
|
7
7
|
import { cleanupVerdict, holdMsFrom } from "../domain/cleanup-policy.js";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { gitSucceedsAsync, runGitAsync } from "../infra/git.js";
|
|
9
|
+
import { runFile } from "../infra/process.js";
|
|
10
10
|
import { runIdFor } from "../infra/store/db.js";
|
|
11
11
|
import { appendTaskEvent } from "../infra/store/events.js";
|
|
12
12
|
import { markCleanupPlanItemApplied, updateWorkItemDelivery } from "../infra/store/records.js";
|
|
@@ -22,17 +22,18 @@ export const CLEANUP_PLAN_TTL_MS = 15 * 60 * 1000;
|
|
|
22
22
|
export const CLEANUP_POLICY = "keep_branch_and_evidence_checkpoint_before_removal";
|
|
23
23
|
const RETAINED = ["branch", "task", "events", "jsonl", "artifacts"];
|
|
24
24
|
|
|
25
|
-
const git = (cwd, args, options = {}) =>
|
|
25
|
+
const git = (cwd, args, options = {}) => runGitAsync(cwd, args, { timeout: 15000, noOptionalLocks: true, ...options });
|
|
26
26
|
const holdMs = () => holdMsFrom(process.env.AGENT_SUPERVISOR_CLEANUP_HOLD_DAYS);
|
|
27
27
|
|
|
28
|
+
// The size is a hint for the reader of a plan. Where du is missing or slow
|
|
29
|
+
// the answer is 0, never a failed plan.
|
|
28
30
|
function directoryBytes(path) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
31
|
+
return new Promise((resolveSize) => {
|
|
32
|
+
runFile("du", ["-sk", path], { encoding: "utf8", timeout: 30000 }, (error, stdout) => {
|
|
33
|
+
const kib = error ? NaN : Number(stdout.trim().split(/\s+/)[0]);
|
|
34
|
+
resolveSize(Number.isFinite(kib) ? kib * 1024 : 0);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
// A plan item is only applied to the worktree it was made for: same commit,
|
|
@@ -60,7 +61,7 @@ export async function createCleanupPlan({ taskIds = null, projectRoot = null, no
|
|
|
60
61
|
reasons: result.reasons,
|
|
61
62
|
checkpoint: result.checkpoint,
|
|
62
63
|
fingerprint: result.fingerprint,
|
|
63
|
-
reclaimable_bytes: result.verdict === "safe" ? directoryBytes(task.worktree_path) : 0,
|
|
64
|
+
reclaimable_bytes: result.verdict === "safe" ? await directoryBytes(task.worktree_path) : 0,
|
|
64
65
|
eligible_after: result.eligible_after ?? (result.verdict === "safe" ? new Date(now).toISOString() : null)
|
|
65
66
|
});
|
|
66
67
|
}
|
|
@@ -78,13 +79,13 @@ export async function createCleanupPlan({ taskIds = null, projectRoot = null, no
|
|
|
78
79
|
|
|
79
80
|
// Saves the worker's uncommitted edits as one commit on its branch. Setup
|
|
80
81
|
// links are left out; hooks are skipped because nobody is there to answer them.
|
|
81
|
-
function checkpointUncommitted(task) {
|
|
82
|
+
async function checkpointUncommitted(task) {
|
|
82
83
|
const path = resolve(task.worktree_path);
|
|
83
84
|
const env = { ...process.env, GIT_TERMINAL_PROMPT: "0", GIT_EDITOR: "true", ...identityEnv(path) };
|
|
84
85
|
const exclude = workspaceSetupIgnorePaths(task).map((entry) => `:(exclude)${entry}`);
|
|
85
|
-
git(path, ["add", "-A", "--", ".", ...exclude], { env });
|
|
86
|
-
if (
|
|
87
|
-
git(path, ["commit", "-q", "--no-verify", "-m", `Checkpoint before worktree cleanup (${task.id})`], { env });
|
|
86
|
+
await git(path, ["add", "-A", "--", ".", ...exclude], { env });
|
|
87
|
+
if (await gitSucceedsAsync(path, ["diff", "--cached", "--quiet"])) return null;
|
|
88
|
+
await git(path, ["commit", "-q", "--no-verify", "-m", `Checkpoint before worktree cleanup (${task.id})`], { env });
|
|
88
89
|
return git(path, ["rev-parse", "HEAD"]);
|
|
89
90
|
}
|
|
90
91
|
|
|
@@ -101,12 +102,12 @@ export async function removeSafeWorktree(task, fingerprint) {
|
|
|
101
102
|
if (result.fingerprint !== fingerprint) throw new Error("worktree changed since cleanup plan; create a new plan");
|
|
102
103
|
// The same lock that creating and restoring a worktree takes.
|
|
103
104
|
return await withWorktreeCreationLock(task.project_root, async () => {
|
|
104
|
-
const checkpoint = result.checkpoint ? checkpointUncommitted(task) : null;
|
|
105
|
+
const checkpoint = result.checkpoint ? await checkpointUncommitted(task) : null;
|
|
105
106
|
// What is left now is setup links and ignored build output, neither of
|
|
106
107
|
// which is the worker's work; a plain remove would refuse them.
|
|
107
|
-
git(task.project_root, ["worktree", "remove", "--force", task.worktree_path]);
|
|
108
|
+
await git(task.project_root, ["worktree", "remove", "--force", task.worktree_path]);
|
|
108
109
|
try {
|
|
109
|
-
git(task.project_root, ["worktree", "prune"]);
|
|
110
|
+
await git(task.project_root, ["worktree", "prune"]);
|
|
110
111
|
} catch {
|
|
111
112
|
// pruning is housekeeping; the worktree is already gone
|
|
112
113
|
}
|
package/src/app/compose.js
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
|
-
// Composition root: wires the
|
|
1
|
+
// Composition root: wires the runners into the layers that may not import them.
|
|
2
2
|
// Every process entry imports this before it touches the store.
|
|
3
3
|
import { registerRunnerReaders } from "../infra/store/runner-readers.js";
|
|
4
4
|
import { extractAgentMessage } from "../runners/codex/event-parser.js";
|
|
5
|
-
import {
|
|
5
|
+
import { DEFAULT_RUNNER, runnerNames, getRunner } from "../runners/registry.js";
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
// A row names its runner. One whose runner is not loaded in this process, or
|
|
8
|
+
// has no native goal, simply has none to show.
|
|
9
|
+
function nativeGoal(threadId, runnerName = DEFAULT_RUNNER) {
|
|
10
|
+
const name = runnerName ?? DEFAULT_RUNNER;
|
|
11
|
+
if (!runnerNames().includes(name)) return null;
|
|
12
|
+
const runner = getRunner(name);
|
|
13
|
+
return runner.capabilities.native_goal ? runner.nativeGoal(threadId) : null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Stored events are in the supervisor's vocabulary whatever CLI produced them.
|
|
17
|
+
registerRunnerReaders({ nativeGoal, agentMessage: extractAgentMessage });
|
package/src/app/dispatch.js
CHANGED
|
@@ -11,7 +11,8 @@ import { resolveWritableRoot } from "../infra/sandbox-roots.js";
|
|
|
11
11
|
import { getSession, upsertSession } from "../infra/store/sessions.js";
|
|
12
12
|
import { getTask, reserveTaskOwnership, taskRunPath, upsertTask } from "../infra/store/tasks.js";
|
|
13
13
|
import { isGitCheckout, prepareWorkspace } from "../infra/workspace-kind.js";
|
|
14
|
-
import {
|
|
14
|
+
import { assertWorkspaceAllowed } from "../runners/contract.js";
|
|
15
|
+
import { DEFAULT_RUNNER, loadRunner } from "../runners/registry.js";
|
|
15
16
|
import { DEFAULT_ACCEPTANCE_TIMEOUT_MS, isArtifactOnlyAcceptance, normalizeAcceptance } from "./acceptance.js";
|
|
16
17
|
import { findOwnershipConflicts, normalizeOwnedPaths, ownershipConflictError } from "./ownership.js";
|
|
17
18
|
import { allowedReasoningEfforts } from "./run-state.js";
|
|
@@ -88,14 +89,11 @@ async function validateDependencies(dependsOn, projectRoot, baseCommit) {
|
|
|
88
89
|
}
|
|
89
90
|
|
|
90
91
|
function coded(code, message, details = undefined) {
|
|
91
|
-
|
|
92
|
-
error.code = code;
|
|
93
|
-
if (details !== undefined) error.details = details;
|
|
94
|
-
return error;
|
|
92
|
+
return Object.assign(new Error(message), { code }, details === undefined ? {} : { details });
|
|
95
93
|
}
|
|
96
94
|
|
|
97
95
|
const DISPATCH_DEFAULTS = {
|
|
98
|
-
sessionId: null, sessionTitle: null, sessionNote: null, sandbox: "workspace-write", model: null, reasoningEffort: "high",
|
|
96
|
+
runner: DEFAULT_RUNNER, sessionId: null, sessionTitle: null, sessionNote: null, sandbox: "workspace-write", model: null, reasoningEffort: "high",
|
|
99
97
|
skipGitRepoCheck: true, dependsOn: [], followupOf: null, workspaceKind: null, inPlaceAuthorization: null, workspaceSetup: null,
|
|
100
98
|
baseRef: null, preflightId: null, preflight: null, acceptance: null, acceptanceTimeoutMs: null, forbid: [], allowedCommands: [],
|
|
101
99
|
context: [], contracts: [], externalOutputs: [], networkAccess: false, writableRoots: [], maxRunMs: null, maxTotalMs: null
|
|
@@ -174,6 +172,7 @@ async function claimWorkspace(input, id, acceptanceCommands) {
|
|
|
174
172
|
const normalizedOwnedPaths = normalizeOwnedPaths([...ownedPaths, ...externalOutputs.map((entry) => entry.path)], projectRoot);
|
|
175
173
|
const normalizedWorkspaceSetup = normalizeWorkspaceSetup(workspaceSetup, projectRoot);
|
|
176
174
|
if (normalizedWorkspaceSetup && workspace.kind !== "git_worktree") throw new Error("workspace.setup is only supported for git_worktree workers");
|
|
175
|
+
assertWorkspaceAllowed(input.runner, input.confined, workspace.kind);
|
|
177
176
|
const conflicts = await findOwnershipConflicts(normalizedOwnedPaths);
|
|
178
177
|
if (conflicts.length > 0) throw ownershipConflictError(conflicts);
|
|
179
178
|
return { workspace, projectRoot, normalizedOwnedPaths, normalizedWorkspaceSetup };
|
|
@@ -246,7 +245,7 @@ function buildGuard(input, place, worktree, resolvedWritableRoots) {
|
|
|
246
245
|
contracts,
|
|
247
246
|
workspaceSetup: normalizedWorkspaceSetup,
|
|
248
247
|
workspaceKind: workspace.kind,
|
|
249
|
-
workspaceManifestSha256: workspace.beforeManifest?.sha256 ?? null
|
|
248
|
+
workspaceManifestSha256: workspace.beforeManifest?.sha256 ?? null, runner: input.runner
|
|
250
249
|
});
|
|
251
250
|
const preflightMetadata = preflight
|
|
252
251
|
? createPreflightMetadata(runtimeContract, preflight.probeCommands)
|
|
@@ -263,7 +262,7 @@ function buildRecord(input, parts) {
|
|
|
263
262
|
const record = {
|
|
264
263
|
id,
|
|
265
264
|
title: title || task.split("\n").find(Boolean)?.slice(0, 80) || "Codex worker",
|
|
266
|
-
worker:
|
|
265
|
+
worker: input.runner,
|
|
267
266
|
status: "queued",
|
|
268
267
|
phase: null,
|
|
269
268
|
cwd: effectiveCwd,
|
|
@@ -358,9 +357,10 @@ async function admitWorker(record, { dependsOn, preflightId }, { workspace, proj
|
|
|
358
357
|
}
|
|
359
358
|
|
|
360
359
|
export async function createCodexWorker(rawInput) {
|
|
361
|
-
const
|
|
360
|
+
const runner = await loadRunner(rawInput.runner ?? DEFAULT_RUNNER);
|
|
361
|
+
const input = { ...withDispatchDefaults(rawInput), runner: runner.name, confined: runner.capabilities.os_sandbox };
|
|
362
362
|
const { acceptanceCommands, validatedGoal, resolvedWritableRoots } = await validateDispatch(input);
|
|
363
|
-
const id =
|
|
363
|
+
const id = `${runner.name}-${Date.now()}-${randomUUID().slice(0, 8)}`;
|
|
364
364
|
const place = await claimWorkspace(input, id, acceptanceCommands);
|
|
365
365
|
const { session, combinedAcceptance } = await sessionPolicy(input, acceptanceCommands);
|
|
366
366
|
requireDependencySetup({ kind: place.workspace.kind, projectRoot: place.projectRoot, setup: place.normalizedWorkspaceSetup,
|
|
@@ -372,14 +372,14 @@ export async function createCodexWorker(rawInput) {
|
|
|
372
372
|
await admitWorker(record, input, { ...place, worktree, runtimeContract: guard.runtimeContract });
|
|
373
373
|
|
|
374
374
|
const { sandbox, model, reasoningEffort, skipGitRepoCheck, task } = input;
|
|
375
|
-
const args =
|
|
375
|
+
const args = runner.startArgs({ cwd: effectiveCwd, sandbox, model, reasoningEffort, skipGitRepoCheck });
|
|
376
376
|
const job = {
|
|
377
377
|
record,
|
|
378
378
|
args,
|
|
379
379
|
prompt: frameWorkerPrompt(task, {
|
|
380
380
|
objective: validatedGoal.objective,
|
|
381
381
|
tokenBudget: validatedGoal.tokenBudget
|
|
382
|
-
}, { acceptance: combinedAcceptance, outputSchema: true }),
|
|
382
|
+
}, { acceptance: combinedAcceptance, outputSchema: true, nativeGoal: runner.capabilities.native_goal }),
|
|
383
383
|
logPath: record.run_log,
|
|
384
384
|
outputSchema: true,
|
|
385
385
|
// --cd tells Codex where the agent works. The shell/tool process must also
|
package/src/app/followup.js
CHANGED
|
@@ -66,12 +66,17 @@ export async function createFollowupWorker(options) {
|
|
|
66
66
|
const { ownedPaths, goal, baseRef, acceptance, acceptanceTimeoutMs, workspaceKind, inPlaceAuthorization, workspaceSetup } = options;
|
|
67
67
|
const parent = await getTask(taskId);
|
|
68
68
|
if (!parent) throw new Error(`task not found: ${taskId}`);
|
|
69
|
+
// A follow-up continues the parent's session, which only the parent's CLI can open.
|
|
70
|
+
if (options.runner && options.runner !== (parent.worker ?? "codex")) {
|
|
71
|
+
throw Object.assign(new Error(`a follow-up runs on its parent's runner (${parent.worker}); dispatch a new worker to use ${options.runner}`), { code: "invalid_arguments" });
|
|
72
|
+
}
|
|
69
73
|
const inheritedBaseRef = followupBaseRef(parent, baseRef);
|
|
70
74
|
const recentEvents = await readTaskEvents(taskId, 20);
|
|
71
75
|
const inheritedAcceptance = parent.session_policy_revision == null ? parent.acceptance : parent.acceptance_local;
|
|
72
76
|
|
|
73
77
|
return createCodexWorker({
|
|
74
78
|
title: title ?? `Follow-up for ${parent.id}`,
|
|
79
|
+
runner: parent.worker,
|
|
75
80
|
task: followupTaskText(parent, recentEvents, followupPrompt),
|
|
76
81
|
sessionId: sessionId ?? parent.session_id ?? null,
|
|
77
82
|
sessionTitle,
|
package/src/app/resume.js
CHANGED
|
@@ -6,9 +6,9 @@ import { ACTIVE_STATUSES, runIsOver } from "../domain/status.js";
|
|
|
6
6
|
import { buildHandoff } from "../infra/handoff.js";
|
|
7
7
|
import { appendTaskEvent } from "../infra/store/events.js";
|
|
8
8
|
import { getSession } from "../infra/store/sessions.js";
|
|
9
|
-
import { claimTaskRun, getTask, readTasks, releaseTaskRun, upsertTask } from "../infra/store/tasks.js";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
9
|
+
import { claimTaskRun, getTask, isGroupAlive, readTasks, releaseTaskRun, upsertTask } from "../infra/store/tasks.js";
|
|
10
|
+
import { unsupported } from "../runners/contract.js";
|
|
11
|
+
import { getRunner, loadRunner } from "../runners/registry.js";
|
|
12
12
|
import { DEFAULT_ACCEPTANCE_TIMEOUT_MS, normalizeAcceptance } from "./acceptance.js";
|
|
13
13
|
import { isPidAlive } from "./cancel.js";
|
|
14
14
|
import { rebaseWorktree } from "./rebase.js";
|
|
@@ -74,16 +74,6 @@ async function rebaseBeforeResume(task, rebaseOnto) {
|
|
|
74
74
|
return { task: moved, rebase };
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
// Only a thread with no native goal, or one explicitly stored as complete,
|
|
78
|
-
// can safely resume with a structured output schema. Paused, blocked,
|
|
79
|
-
// usage-limited and budget-limited goals are not complete; Codex can still
|
|
80
|
-
// activate their goal turn and reject the incompatible schema.
|
|
81
|
-
function resumeAllowsOutputSchema(threadId) {
|
|
82
|
-
const goalRead = readNativeGoalState(threadId);
|
|
83
|
-
return ["missing_goal", "missing_database"].includes(goalRead.state)
|
|
84
|
-
|| (goalRead.state === "available" && goalRead.goal?.storage_status === "complete");
|
|
85
|
-
}
|
|
86
|
-
|
|
87
77
|
// Where a resumed worker runs. It is the directory it ran in before, and never
|
|
88
78
|
// a stand-in: falling back to the project root would let a worker that was
|
|
89
79
|
// confined to a scratch directory or a worktree write into the source tree.
|
|
@@ -104,7 +94,7 @@ async function resumeClaimed(claimed, { prompt, rebaseOnto, acceptance }) {
|
|
|
104
94
|
let task = await refreshAcceptance(claimed, session, acceptance);
|
|
105
95
|
if (!task.thread_id) {
|
|
106
96
|
throw new Error(
|
|
107
|
-
`task ${task.id} has no
|
|
97
|
+
`task ${task.id} has no thread_id recorded. Only workers created by this version of codex-supervisor-mcp can be resumed; use create_worker with followup_of otherwise.`
|
|
108
98
|
);
|
|
109
99
|
}
|
|
110
100
|
await ensureTaskWorktree(task);
|
|
@@ -112,15 +102,16 @@ async function resumeClaimed(claimed, { prompt, rebaseOnto, acceptance }) {
|
|
|
112
102
|
if (rebaseOnto) ({ task, rebase } = await rebaseBeforeResume(task, rebaseOnto));
|
|
113
103
|
|
|
114
104
|
const cwd = await resumeCwd(task);
|
|
115
|
-
const
|
|
116
|
-
const
|
|
105
|
+
const runner = getRunner(task.worker);
|
|
106
|
+
const args = runner.resumeArgs(task);
|
|
107
|
+
const outputSchema = runner.capabilities.structured_report && (runner.resumeAllowsOutputSchema?.(task.thread_id) ?? true);
|
|
117
108
|
const started = await startTrackedRun({
|
|
118
109
|
record: { ...task, resumed_from: task.resumed_from ?? task.id },
|
|
119
110
|
args,
|
|
120
111
|
prompt: frameWorkerPrompt(prompt, {
|
|
121
112
|
objective: task.goal_objective ?? task.title ?? task.id,
|
|
122
113
|
resume: true
|
|
123
|
-
}, { acceptance: task.acceptance, outputSchema }),
|
|
114
|
+
}, { acceptance: task.acceptance, outputSchema, nativeGoal: runner.capabilities.native_goal }),
|
|
124
115
|
logPath: task.run_log,
|
|
125
116
|
outputSchema,
|
|
126
117
|
spawnOptions: { cwd }
|
|
@@ -132,6 +123,8 @@ export async function resumeCodexWorker({ taskId, prompt, rebaseOnto = null, acc
|
|
|
132
123
|
if (!prompt || typeof prompt !== "string") throw new Error("prompt is required");
|
|
133
124
|
let task = await getTask(taskId);
|
|
134
125
|
if (!task) throw new Error(`task not found: ${taskId}`);
|
|
126
|
+
const runner = await loadRunner(task.worker);
|
|
127
|
+
if (!runner.capabilities.resume) throw unsupported(runner, "resume", "resuming a worker");
|
|
135
128
|
if (task.guard_policy?.maxTotalMs && Date.now() - Date.parse(task.created_at) >= task.guard_policy.maxTotalMs) {
|
|
136
129
|
throw coded("time_quota_exceeded", "total time quota exceeded; inspect partial work and explicitly dispatch a revised budget");
|
|
137
130
|
}
|
|
@@ -159,7 +152,11 @@ export async function recoverEligibleRuns() {
|
|
|
159
152
|
|| /401|403|unauthori[sz]ed|not logged|permission denied|approval|rate.?limit|429/i.test(task.error ?? "")
|
|
160
153
|
|| /time_limit|quota/.test(`${task.attention_reason ?? ""} ${task.error ?? ""}`)
|
|
161
154
|
// Once the run is over its pids may belong to anyone.
|
|
162
|
-
|| (!runIsOver(task) && (await isPidAlive(task.pid) || await isPidAlive(task.run_host_pid)))
|
|
155
|
+
|| (!runIsOver(task) && (await isPidAlive(task.pid) || await isPidAlive(task.run_host_pid)))
|
|
156
|
+
// Something of the dead run is still alive and holds the session;
|
|
157
|
+
// resuming now fails with "already has an active writer". A later poll retries.
|
|
158
|
+
// A recorded exit is the one thing that rules a survivor out.
|
|
159
|
+
|| (task.exit_code == null && isGroupAlive(task.run_host_pid))) continue;
|
|
163
160
|
const session = task.session_id ? await getSession(task.session_id) : null;
|
|
164
161
|
if (session?.approval_state === "waiting_user") continue;
|
|
165
162
|
try {
|