codex-supervisor-mcp 1.1.0 → 1.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.en.md +5 -1
- package/README.md +5 -1
- package/package.json +2 -2
- package/skills/codex-supervisor/SKILL.md +2 -1
- package/src/app/cancel.js +11 -14
- 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 +9 -16
- package/src/app/side-chat.js +41 -20
- package/src/domain/prompt.js +7 -3
- package/src/domain/worker-preflight.js +4 -1
- package/src/infra/stage-store.js +1 -1
- package/src/infra/store/runner-readers.js +1 -1
- package/src/infra/store/tasks.js +1 -1
- package/src/infra/update/auto-update-worker.js +44 -2
- package/src/infra/update/handover.js +125 -0
- package/src/infra/worktree.js +25 -5
- package/src/interface/mcp/handlers/dispatch.js +3 -0
- package/src/interface/mcp/handlers/results.js +11 -4
- package/src/interface/mcp/tools/dispatch.js +7 -5
- package/src/interface/mcp/tools/shapes.js +1 -0
- package/src/interface/mcp/update-state.js +10 -4
- package/src/interface/web/app.js +2 -2
- package/src/interface/web/views.js +2 -2
- package/src/run-host/launch.js +5 -19
- package/src/run-host/live-run.js +2 -1
- package/src/run-host/streams.js +9 -6
- package/src/run-host/track.js +3 -2
- 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/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
|
+
> **This package is now [agent-supervisor-mcp](https://www.npmjs.com/package/agent-supervisor-mcp).** This is the last release under the old name. A global install needs nothing from you: it installs the new package in the background, replaces the MCP registration and the skill, and the next session starts on the new package with the state directory where it was. Where that does not happen (started through npx, a source checkout), run `npm install -g agent-supervisor-mcp`.
|
|
22
|
+
>
|
|
21
23
|
> **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
24
|
|
|
23
25
|
## What it solves
|
|
@@ -32,7 +34,9 @@ codex-supervisor-mcp is an MCP server. A main thread (Claude Code, Codex, or any
|
|
|
32
34
|
| Changes sit on a local branch | `land_worker` merges into the integration branch; `verify_push` proves the commit is on the remote |
|
|
33
35
|
| 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 |
|
|
34
36
|
|
|
35
|
-
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.
|
|
37
|
+
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.
|
|
38
|
+
|
|
39
|
+
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).
|
|
36
40
|
|
|
37
41
|
## Five minutes to a running batch
|
|
38
42
|
|
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
|
+
> **这个包已改名为 [agent-supervisor-mcp](https://www.npmjs.com/package/agent-supervisor-mcp)。** 这是旧名字下的最后一版。全局安装的机器不用动手:它会在后台装好新包、换掉 MCP 注册和 skill,下次开会话就在新包上,状态目录原地不动。没自动换成的(npx 启动、源码检出)手动跑 `npm install -g agent-supervisor-mcp`。
|
|
22
|
+
>
|
|
21
23
|
> **从 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
24
|
|
|
23
25
|
## 解决什么
|
|
@@ -32,7 +34,9 @@ codex-supervisor-mcp 是一个 MCP server。主线程(Claude Code、Codex 或
|
|
|
32
34
|
| 改动留在本地没上线 | `land_worker` 合回主分支,`verify_push` 核对远端真有这笔提交 |
|
|
33
35
|
| worktree 越堆越多 | 已合入或没有改动的在轮询时自动清;没合入的留 7 天,删之前先把未提交的改动存进它的分支。分支和证据不删 |
|
|
34
36
|
|
|
35
|
-
worker
|
|
37
|
+
worker 默认跑 `codex exec`,`model` 透传。主线程留在 Claude,worker 挂 DeepSeek 或别的 provider,账单分开算。
|
|
38
|
+
|
|
39
|
+
worker 也可以是 Claude Code:`create_worker` 带 `runner: "claude"`。它没有系统级沙箱,所以只能在 git worktree 或只读模式下跑,也不支持旁问(`ask_worker`);其余派单、验收、续跑、合入、清理都一样。想接别的 CLI,看 [docs/runner.md](docs/runner.md)。
|
|
36
40
|
|
|
37
41
|
## 五分钟跑起来
|
|
38
42
|
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codex-supervisor-mcp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"mcpName": "io.github.zriyox/codex-supervisor-mcp",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"description": "MCP server that runs parallel Codex CLI
|
|
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`。
|
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/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
|
@@ -7,8 +7,8 @@ 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
9
|
import { claimTaskRun, getTask, isGroupAlive, readTasks, releaseTaskRun, upsertTask } from "../infra/store/tasks.js";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
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
|
}
|
package/src/app/side-chat.js
CHANGED
|
@@ -26,9 +26,9 @@ import { ensureTaskWorktree } from "./restore-worktree.js";
|
|
|
26
26
|
import "./compose.js";
|
|
27
27
|
import { answerOf, partsFromChunks, turnView } from "../domain/side-turn-view.js";
|
|
28
28
|
import { closeSideSession, getSideSession, insertSideTurn, interruptRunningSideTurns, openSideSession, readSideTurns, setSideSessionFork, updateSideTurn } from "../infra/store/sessions.js";
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
31
|
-
import {
|
|
29
|
+
import { getTask } from "../infra/store/tasks.js";
|
|
30
|
+
import { unsupported } from "../runners/contract.js";
|
|
31
|
+
import { loadRunner, runnerOf } from "../runners/registry.js";
|
|
32
32
|
import { endStream, sseHead, writeChunk } from "./sse.js";
|
|
33
33
|
import { randomUUID } from "node:crypto";
|
|
34
34
|
|
|
@@ -55,12 +55,9 @@ export function sideQuestionText(question) {
|
|
|
55
55
|
// Codex config is switched off for the turn. Sub-tables
|
|
56
56
|
// ([mcp_servers.x.env]) are not servers and are skipped.
|
|
57
57
|
//
|
|
58
|
-
//
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
// the whole config then fails to load.
|
|
62
|
-
export function sideTurnConfigArgs(configText) {
|
|
63
|
-
return disableMcpServerArgs(configText);
|
|
58
|
+
// A side question runs with none of the user's MCP servers: it only reads.
|
|
59
|
+
export function sideTurnConfigArgs(configText, runner = runnerOf(null)) {
|
|
60
|
+
return runner.sideChat.disableMcpServerArgs(configText);
|
|
64
61
|
}
|
|
65
62
|
|
|
66
63
|
// The session to ask on. A fork taken before the worker was resumed no
|
|
@@ -141,10 +138,12 @@ export function attachToTurn(taskId, res) {
|
|
|
141
138
|
}
|
|
142
139
|
|
|
143
140
|
function startSideChild(target, task, session) {
|
|
144
|
-
const
|
|
145
|
-
|
|
141
|
+
const runner = runnerOf(task);
|
|
142
|
+
const side = runner.sideChat;
|
|
143
|
+
const forkArgs = side.forkArgs({ forkThreadId: session.fork_thread_id, workerThreadId: task.thread_id, model: task.model });
|
|
144
|
+
const args = side.withConfig(forkArgs, sideTurnConfigArgs(side.configText(), runner));
|
|
146
145
|
const cwd = task.worktree_path || task.project_root || process.cwd();
|
|
147
|
-
return
|
|
146
|
+
return runner.start(target, args, {
|
|
148
147
|
cwd,
|
|
149
148
|
stdio: ["pipe", "pipe", "pipe"],
|
|
150
149
|
env: { ...process.env, NO_COLOR: "1" },
|
|
@@ -158,7 +157,8 @@ async function openLiveTurn(task, text, child) {
|
|
|
158
157
|
const turnId = `turn-${Date.now()}-${randomUUID().slice(0, 8)}`;
|
|
159
158
|
const startedAt = new Date().toISOString();
|
|
160
159
|
const state = { toolsSeen: new Set(), completed: false, failed: false, usage: null };
|
|
161
|
-
const live = { turnId, child, chunks: [], watchers: new Set(), startedAt, question: text, state, stderr: "", stoppedBy: null, persistTimer: null
|
|
160
|
+
const live = { turnId, child, chunks: [], watchers: new Set(), startedAt, question: text, state, stderr: "", stoppedBy: null, persistTimer: null,
|
|
161
|
+
chunksFor: runnerOf(task).sideChat.chunksFor };
|
|
162
162
|
const persistSoon = () => {
|
|
163
163
|
if (live.persistTimer) return;
|
|
164
164
|
live.persistTimer = setTimeout(() => {
|
|
@@ -173,7 +173,7 @@ async function openLiveTurn(task, text, child) {
|
|
|
173
173
|
};
|
|
174
174
|
live.stop = (reason) => {
|
|
175
175
|
live.stoppedBy = reason;
|
|
176
|
-
|
|
176
|
+
runnerOf(task).cancelChild(child);
|
|
177
177
|
};
|
|
178
178
|
running.set(task.id, live);
|
|
179
179
|
await insertSideTurn({ id: turnId, task_id: task.id, question: text, status: "running", chunks: [], started_at: startedAt });
|
|
@@ -200,7 +200,7 @@ function pipeSideOutput(child, live, session, taskId) {
|
|
|
200
200
|
session.fork_thread_id = event.thread_id;
|
|
201
201
|
setSideSessionFork(taskId, event.thread_id).catch(() => {});
|
|
202
202
|
}
|
|
203
|
-
for (const part of chunksFor(event, live.state)) live.broadcast(part);
|
|
203
|
+
for (const part of live.chunksFor(event, live.state)) live.broadcast(part);
|
|
204
204
|
}
|
|
205
205
|
});
|
|
206
206
|
child.stderr.setEncoding("utf8");
|
|
@@ -234,13 +234,30 @@ async function settleSideTurn(live, taskId, code, signal) {
|
|
|
234
234
|
return status;
|
|
235
235
|
}
|
|
236
236
|
|
|
237
|
+
// For a caller that only wants to know whether to offer the question box.
|
|
238
|
+
export function supportsSideChat(task) {
|
|
239
|
+
try {
|
|
240
|
+
return runnerOf(task).capabilities.side_chat === true;
|
|
241
|
+
} catch {
|
|
242
|
+
return false; // a runner this process has not loaded
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// Checked before a session row is opened, so a runner without a side chat leaves nothing behind.
|
|
247
|
+
export async function requireSideChat(task) {
|
|
248
|
+
const runner = await loadRunner(task.worker);
|
|
249
|
+
if (!runner.capabilities.side_chat) throw unsupported(runner, "side_chat", "asking a worker a side question");
|
|
250
|
+
return runner;
|
|
251
|
+
}
|
|
252
|
+
|
|
237
253
|
// Start a turn. `res` (optional) becomes the first watcher. Resolves when the
|
|
238
254
|
// turn has ended, however it ended.
|
|
239
255
|
export async function runSideTurn({ task, text, res = null, fresh = false }) {
|
|
240
256
|
await sweepOnce();
|
|
241
|
-
|
|
257
|
+
const runner = await requireSideChat(task);
|
|
258
|
+
if (!task.thread_id) throw Object.assign(new Error("this worker recorded no thread_id, so there is no thread to fork"), { code: "no_thread" });
|
|
242
259
|
if (running.has(task.id)) throw Object.assign(new Error("a side turn is already running for this worker"), { code: "busy" });
|
|
243
|
-
const target =
|
|
260
|
+
const target = runner.resolveTarget();
|
|
244
261
|
if (target.error) throw Object.assign(new Error(target.error), { code: "codex_missing" });
|
|
245
262
|
|
|
246
263
|
const { session, refreshed } = await prepareSideSession(task, { fresh });
|
|
@@ -296,6 +313,7 @@ export async function latestSideTurn(taskId) {
|
|
|
296
313
|
export async function askWorker({ task, question, timeoutMs = 110000, fresh = false }) {
|
|
297
314
|
// Decided here, before the race, so a turn that outruns the budget still
|
|
298
315
|
// reports whether the fork was taken anew.
|
|
316
|
+
await requireSideChat(task);
|
|
299
317
|
const { refreshed } = await prepareSideSession(task, { fresh });
|
|
300
318
|
const turn = runSideTurn({ task, text: question });
|
|
301
319
|
// runSideTurn throws synchronously-ish (rejected promise) for no_thread,
|
|
@@ -334,12 +352,15 @@ export async function endSideSession(taskId) {
|
|
|
334
352
|
if (!row) return { ended: false };
|
|
335
353
|
let deleted = false;
|
|
336
354
|
if (row.fork_thread_id) {
|
|
337
|
-
|
|
355
|
+
// The task may be gone and its runner not loaded here; then the fork is left to the CLI's own housekeeping.
|
|
356
|
+
const stored = await getTask(taskId);
|
|
357
|
+
const runner = stored ? await loadRunner(stored.worker).catch(() => null) : null;
|
|
358
|
+
const target = runner?.capabilities.side_chat ? runner.resolveTarget() : { error: "no runner" };
|
|
338
359
|
if (!target.error) {
|
|
339
360
|
deleted = await new Promise((resolve) => {
|
|
340
361
|
// --force: without a terminal codex asks for confirmation and exits.
|
|
341
|
-
const child =
|
|
342
|
-
const t = setTimeout(() => {
|
|
362
|
+
const child = runner.start(target, runner.sideChat.deleteArgs(row.fork_thread_id), { stdio: "ignore", windowsHide: true, env: { ...process.env, NO_COLOR: "1" } });
|
|
363
|
+
const t = setTimeout(() => { runner.cancelChild(child); resolve(false); }, 15000);
|
|
343
364
|
child.on("exit", (code) => { clearTimeout(t); resolve(code === 0); });
|
|
344
365
|
child.on("error", () => { clearTimeout(t); resolve(false); });
|
|
345
366
|
});
|
package/src/domain/prompt.js
CHANGED
|
@@ -116,7 +116,7 @@ export function buildReportPreamble({ resume = false, acceptance = null, outputS
|
|
|
116
116
|
}
|
|
117
117
|
return withAcceptance([
|
|
118
118
|
"Final report (your last message), under 2000 characters, in the language of the task. Quoted command output does not count toward the limit.",
|
|
119
|
-
`Return JSON with exactly result:string, verification:string[], not_done:string[]; ${outputSchema ? "
|
|
119
|
+
`Return JSON with exactly result:string, verification:string[], not_done:string[]; ${outputSchema ? "an output schema enforces these fields" : "no output schema is active, so follow this shape exactly"}. Cover the following content in those fields.`,
|
|
120
120
|
"Write that JSON value on its own: no markdown code fences and nothing before or after it.",
|
|
121
121
|
"Keep each verification entry concise: command name, exit code and key evidence; avoid embedding long quoted shell source. Ensure arrays and the object are fully closed and all strings use valid JSON escaping.",
|
|
122
122
|
"1. Result: what is done, in two or three sentences. Say plainly what is not done.",
|
|
@@ -134,8 +134,12 @@ export function withGoalPreamble(prompt, goalOptions) {
|
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
// The whole frame: goal in front, task text, report format at the end.
|
|
137
|
-
|
|
138
|
-
|
|
137
|
+
// nativeGoal false is a CLI with no goal of its own: it is told the objective
|
|
138
|
+
// in a line, not to call goal tools it does not have.
|
|
139
|
+
export function frameWorkerPrompt(prompt, goalOptions, { acceptance = null, outputSchema = true, nativeGoal = true } = {}) {
|
|
140
|
+
const plainObjective = !goalOptions?.resume && goalOptions?.objective ? `Objective: ${goalOptions.objective}\n\n${prompt}` : prompt;
|
|
141
|
+
const framed = nativeGoal ? withGoalPreamble(prompt, goalOptions) : plainObjective;
|
|
142
|
+
return `${framed}\n\n${buildReportPreamble({ resume: Boolean(goalOptions?.resume), acceptance, outputSchema })}`;
|
|
139
143
|
}
|
|
140
144
|
|
|
141
145
|
// Claude's native /goal owns its Stop condition. MCP cannot silently replace
|
|
@@ -64,9 +64,12 @@ export function buildRuntimeContract({
|
|
|
64
64
|
contracts,
|
|
65
65
|
workspaceSetup = null,
|
|
66
66
|
workspaceKind = "git_worktree",
|
|
67
|
-
workspaceManifestSha256 = null
|
|
67
|
+
workspaceManifestSha256 = null,
|
|
68
|
+
runner = "codex"
|
|
68
69
|
}) {
|
|
69
70
|
return stableValue({
|
|
71
|
+
// Named only when it is not the default, so contracts made before runners existed still match.
|
|
72
|
+
...(runner && runner !== "codex" ? { runner } : {}),
|
|
70
73
|
version: PREFLIGHT_VERSION,
|
|
71
74
|
project_root: resolve(projectRoot),
|
|
72
75
|
base_commit: baseCommit ?? null,
|
package/src/infra/stage-store.js
CHANGED
|
@@ -3,7 +3,7 @@ import { join } from "node:path";
|
|
|
3
3
|
import { stagesDir } from "./paths.js";
|
|
4
4
|
|
|
5
5
|
function validate(taskId, stage, detail) {
|
|
6
|
-
if (!/^
|
|
6
|
+
if (!/^[a-z][a-z0-9-]*-[A-Za-z0-9-]+$/.test(String(taskId ?? ""))) throw new Error("invalid task id for stage checkpoint");
|
|
7
7
|
const name = String(stage ?? "").trim();
|
|
8
8
|
if (!name || name.length > 200) throw new Error("stage must be 1-200 characters");
|
|
9
9
|
const note = detail == null ? null : String(detail).trim();
|
|
@@ -12,5 +12,5 @@ export function registerRunnerReaders({ nativeGoal, agentMessage }) {
|
|
|
12
12
|
readers.agentMessage = agentMessage;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export const readNativeGoal = (threadId) => readers.nativeGoal(threadId);
|
|
15
|
+
export const readNativeGoal = (threadId, runnerName) => readers.nativeGoal(threadId, runnerName);
|
|
16
16
|
export const extractAgentMessage = (event) => readers.agentMessage(event);
|
package/src/infra/store/tasks.js
CHANGED
|
@@ -9,7 +9,7 @@ import { join, resolve } from "node:path";
|
|
|
9
9
|
|
|
10
10
|
export function rowToTask(row) {
|
|
11
11
|
if (!row) return null;
|
|
12
|
-
const nativeGoal = readNativeGoal(row.thread_id);
|
|
12
|
+
const nativeGoal = readNativeGoal(row.thread_id, row.worker);
|
|
13
13
|
return {
|
|
14
14
|
...row,
|
|
15
15
|
workspace_kind: row.workspace_kind ?? "legacy",
|
|
@@ -22,15 +22,16 @@ const LOCK_STALE_MS = 10 * 60 * 1000;
|
|
|
22
22
|
const NPM_TIMEOUT_MS = 10 * 60 * 1000;
|
|
23
23
|
|
|
24
24
|
function parseArgs(argv) {
|
|
25
|
-
const options = { version: null, packageRoot: null, registry: null };
|
|
25
|
+
const options = { version: null, packageRoot: null, registry: null, successor: null };
|
|
26
26
|
for (let index = 0; index < argv.length; index += 1) {
|
|
27
27
|
const arg = argv[index];
|
|
28
28
|
if (arg === "--version") options.version = argv[++index];
|
|
29
29
|
else if (arg === "--package-root") options.packageRoot = argv[++index];
|
|
30
30
|
else if (arg === "--registry") options.registry = argv[++index];
|
|
31
|
+
else if (arg === "--successor") options.successor = argv[++index];
|
|
31
32
|
else throw new Error(`Unknown argument: ${arg}`);
|
|
32
33
|
}
|
|
33
|
-
if (!options.version || !options.packageRoot) throw new Error("--
|
|
34
|
+
if ((!options.version && !options.successor) || !options.packageRoot) throw new Error("--package-root and one of --version, --successor are required");
|
|
34
35
|
return options;
|
|
35
36
|
}
|
|
36
37
|
|
|
@@ -118,8 +119,49 @@ function samePath(a, b) {
|
|
|
118
119
|
}
|
|
119
120
|
}
|
|
120
121
|
|
|
122
|
+
// Installs the package this one was renamed to. Its own install step does the
|
|
123
|
+
// rest: registers it, removes this package's registration, retires its skill.
|
|
124
|
+
async function installSuccessor(options) {
|
|
125
|
+
const handoverPath = join(dataDir, "handover.json");
|
|
126
|
+
const record = async (patch) => {
|
|
127
|
+
await mkdir(dataDir, { recursive: true });
|
|
128
|
+
await writeFile(handoverPath, JSON.stringify({ ...patch, pid: process.pid, updated_at: new Date().toISOString() }, null, 2));
|
|
129
|
+
};
|
|
130
|
+
if (!(await acquireLock())) {
|
|
131
|
+
console.log(`handover: another installer holds ${lockPath}; leaving it to that one`);
|
|
132
|
+
return 0;
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
await record({ state: "running" });
|
|
136
|
+
const { stdout: rootOut } = await npm(["root", "-g"], { registry: options.registry, timeout: 60_000 });
|
|
137
|
+
const globalRoot = rootOut.trim();
|
|
138
|
+
if (!samePath(join(globalRoot, PACKAGE_NAME), options.packageRoot)) {
|
|
139
|
+
await record({ state: "skipped", reason: `the running copy (${options.packageRoot}) is not npm's global install; nothing was changed` });
|
|
140
|
+
return 0;
|
|
141
|
+
}
|
|
142
|
+
try {
|
|
143
|
+
await npm(["install", "-g", `${options.successor}@latest`], { registry: options.registry });
|
|
144
|
+
} catch (error) {
|
|
145
|
+
const tail = `${error.stdout ?? ""}${error.stderr ?? ""}`.trim().split("\n").slice(-12).join("\n");
|
|
146
|
+
await record({ state: "failed", reason: `npm install exited ${error.code ?? "?"}`, log: tail });
|
|
147
|
+
return 1;
|
|
148
|
+
}
|
|
149
|
+
const installedAt = join(globalRoot, options.successor);
|
|
150
|
+
if (!existsSync(join(installedAt, "package.json"))) {
|
|
151
|
+
await record({ state: "failed", reason: `npm reported success but ${installedAt} is not there` });
|
|
152
|
+
return 1;
|
|
153
|
+
}
|
|
154
|
+
await record({ state: "done", installed_path: installedAt });
|
|
155
|
+
console.log(`handover: installed ${options.successor} at ${installedAt}`);
|
|
156
|
+
return 0;
|
|
157
|
+
} finally {
|
|
158
|
+
await rm(lockPath, { force: true });
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
121
162
|
async function main() {
|
|
122
163
|
const options = parseArgs(process.argv.slice(2));
|
|
164
|
+
if (options.successor) return installSuccessor(options);
|
|
123
165
|
const stamp = { version: options.version, pid: process.pid, started_at: new Date().toISOString() };
|
|
124
166
|
|
|
125
167
|
if (!(await acquireLock())) {
|