codex-supervisor-mcp 0.10.3 → 0.11.1
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 +25 -7
- package/README.md +26 -17
- package/package.json +3 -1
- package/skills/codex-supervisor/SKILL.md +22 -15
- package/src/cleanup-hint.js +3 -2
- package/src/cleanup-plan.js +67 -7
- package/src/cleanup.js +48 -40
- package/src/codex-runner.js +219 -120
- package/src/context-compiler.js +3 -1
- package/src/handoff.js +9 -1
- package/src/landing.js +16 -4
- package/src/mcp-server.js +383 -37
- package/src/overview-delta.js +37 -5
- package/src/paths.js +2 -0
- package/src/prompt.js +6 -3
- package/src/runner-adapter.js +100 -0
- package/src/sandbox-roots.js +19 -3
- package/src/side-chat.js +10 -38
- package/src/task-store.js +494 -67
- package/src/worker-preflight.js +15 -3
- package/src/workspace-kind.js +167 -0
package/src/worker-preflight.js
CHANGED
|
@@ -22,8 +22,16 @@ function uniqueSorted(values) {
|
|
|
22
22
|
|
|
23
23
|
export function normalizeObservedCommand(command) {
|
|
24
24
|
const text = String(command ?? "").trim();
|
|
25
|
-
const wrapped = text.match(/^(?:[^\s]+\/)?(?:zsh|bash|sh)\s+-l?c\s+([
|
|
26
|
-
|
|
25
|
+
const wrapped = text.match(/^(?:[^\s]+\/)?(?:zsh|bash|sh)\s+-l?c\s+([\s\S]+)$/);
|
|
26
|
+
if (!wrapped) return text;
|
|
27
|
+
let body = wrapped[1].trim();
|
|
28
|
+
const quote = body[0];
|
|
29
|
+
if ((quote === "'" || quote === '"') && body.at(-1) === quote) body = body.slice(1, -1);
|
|
30
|
+
// Codex displays a shell command that already contains single quotes by
|
|
31
|
+
// closing and reopening the outer quote around them: -run '"^Test$'"'.
|
|
32
|
+
// Decode that display-only wrapping before comparing it with the contract.
|
|
33
|
+
body = body.replace(/'"'/g, "'");
|
|
34
|
+
return body.trim();
|
|
27
35
|
}
|
|
28
36
|
|
|
29
37
|
export function buildRuntimeContract({
|
|
@@ -35,7 +43,9 @@ export function buildRuntimeContract({
|
|
|
35
43
|
networkAccess,
|
|
36
44
|
writableRoots,
|
|
37
45
|
context,
|
|
38
|
-
contracts
|
|
46
|
+
contracts,
|
|
47
|
+
workspaceKind = "git_worktree",
|
|
48
|
+
workspaceManifestSha256 = null
|
|
39
49
|
}) {
|
|
40
50
|
return stableValue({
|
|
41
51
|
version: PREFLIGHT_VERSION,
|
|
@@ -46,6 +56,8 @@ export function buildRuntimeContract({
|
|
|
46
56
|
allowed_commands: uniqueSorted(allowedCommands),
|
|
47
57
|
network_access: networkAccess === true,
|
|
48
58
|
writable_roots: uniqueSorted(writableRoots),
|
|
59
|
+
workspace_kind: workspaceKind,
|
|
60
|
+
workspace_manifest_sha256: workspaceManifestSha256,
|
|
49
61
|
context: (context ?? [])
|
|
50
62
|
.map((entry) => ({ path: resolve(entry.path), sha256: entry.sha256 ?? null }))
|
|
51
63
|
.sort((left, right) => left.path.localeCompare(right.path)),
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { createReadStream, existsSync } from "node:fs";
|
|
3
|
+
import { lstat, mkdir, readdir, readlink, rm } from "node:fs/promises";
|
|
4
|
+
import { execFileSync } from "node:child_process";
|
|
5
|
+
import { join, relative, resolve } from "node:path";
|
|
6
|
+
import { scratchDir } from "./paths.js";
|
|
7
|
+
|
|
8
|
+
export const WORKSPACE_KINDS = ["git_worktree", "read_only_in_place", "scratch", "in_place_write"];
|
|
9
|
+
const MAX_MANIFEST_ENTRIES = 20000;
|
|
10
|
+
|
|
11
|
+
function workspaceError(code, message) {
|
|
12
|
+
const error = new Error(message);
|
|
13
|
+
error.code = code;
|
|
14
|
+
return error;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function isInside(root, path) {
|
|
18
|
+
const rel = relative(root, path);
|
|
19
|
+
return rel === "" || (!rel.startsWith("..") && !rel.includes(`..${process.platform === "win32" ? "\\" : "/"}`));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function isGitCheckout(cwd) {
|
|
23
|
+
try {
|
|
24
|
+
return execFileSync(process.env.GIT_BIN?.trim() || "git", ["-C", cwd, "rev-parse", "--is-inside-work-tree"], {
|
|
25
|
+
encoding: "utf8",
|
|
26
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
27
|
+
timeout: 15000
|
|
28
|
+
}).trim() === "true";
|
|
29
|
+
} catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function selectedKind({ sourceRoot, workspaceKind, sandbox }) {
|
|
35
|
+
if (workspaceKind != null && !WORKSPACE_KINDS.includes(workspaceKind)) {
|
|
36
|
+
throw workspaceError("invalid_workspace_kind", `workspaceKind must be one of ${WORKSPACE_KINDS.join(", ")}`);
|
|
37
|
+
}
|
|
38
|
+
if (workspaceKind) return workspaceKind;
|
|
39
|
+
if (isGitCheckout(sourceRoot)) return "git_worktree";
|
|
40
|
+
if (sandbox === "read-only") return "read_only_in_place";
|
|
41
|
+
throw workspaceError("workspace_kind_required", "a non-Git worker that can write must declare workspaceKind: scratch or in_place_write; the supervisor never writes a user directory by default");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function validateKind({ kind, sourceRoot, sandbox, ownedPaths, networkAccess, acceptance, externalOutputs, inPlaceAuthorization, isPreflight }) {
|
|
45
|
+
if (kind === "git_worktree") {
|
|
46
|
+
if (!isGitCheckout(sourceRoot)) throw workspaceError("git_worktree_requires_git", "workspaceKind git_worktree requires a Git checkout with a resolvable commit; use read_only_in_place, scratch or explicitly authorized in_place_write for a non-Git directory");
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (kind === "read_only_in_place") {
|
|
50
|
+
if (sandbox !== "read-only" || ownedPaths.length !== 0 || networkAccess) {
|
|
51
|
+
throw workspaceError("invalid_read_only_workspace", "read_only_in_place requires sandbox read-only, ownedPaths: [] and networkAccess: false");
|
|
52
|
+
}
|
|
53
|
+
if (externalOutputs.length) throw workspaceError("invalid_read_only_workspace", "read_only_in_place cannot declare externalOutputs");
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (kind === "scratch") {
|
|
57
|
+
if (sandbox !== "workspace-write" || ownedPaths.length !== 0) {
|
|
58
|
+
throw workspaceError("invalid_scratch_workspace", "scratch requires sandbox workspace-write and ownedPaths: []; it never lands project changes");
|
|
59
|
+
}
|
|
60
|
+
if (externalOutputs.length) throw workspaceError("invalid_scratch_workspace", "scratch cannot write externalOutputs; keep generated material inside the supervisor scratch directory");
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (isGitCheckout(sourceRoot)) {
|
|
64
|
+
throw workspaceError("in_place_write_requires_non_git", "in_place_write is only for an explicitly authorized non-Git directory; use git_worktree for a Git checkout");
|
|
65
|
+
}
|
|
66
|
+
if (sandbox !== "workspace-write" || ownedPaths.length === 0 || !String(inPlaceAuthorization ?? "").trim()) {
|
|
67
|
+
throw workspaceError("invalid_in_place_workspace", "in_place_write requires sandbox workspace-write, nonempty ownedPaths and an explicit inPlaceAuthorization");
|
|
68
|
+
}
|
|
69
|
+
if (!isPreflight && (!Array.isArray(acceptance) || acceptance.length === 0)) {
|
|
70
|
+
throw workspaceError("in_place_acceptance_required", "in_place_write requires explicit acceptance; file changes in a user directory cannot be accepted by worker exit status alone");
|
|
71
|
+
}
|
|
72
|
+
for (const path of ownedPaths) {
|
|
73
|
+
if (!isInside(sourceRoot, resolve(sourceRoot, path))) {
|
|
74
|
+
throw workspaceError("in_place_path_outside_root", `in_place_write ownedPath escapes the authorized source root: ${path}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async function sha256File(path) {
|
|
80
|
+
const hash = createHash("sha256");
|
|
81
|
+
for await (const chunk of createReadStream(path)) hash.update(chunk);
|
|
82
|
+
return hash.digest("hex");
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async function manifestEntry(root, absolute, entries) {
|
|
86
|
+
if (entries.length >= MAX_MANIFEST_ENTRIES) {
|
|
87
|
+
throw workspaceError("workspace_manifest_too_large", `workspace manifest exceeds ${MAX_MANIFEST_ENTRIES} entries; narrow the declared in-place paths before dispatching`);
|
|
88
|
+
}
|
|
89
|
+
const path = relative(root, absolute) || ".";
|
|
90
|
+
let info;
|
|
91
|
+
try {
|
|
92
|
+
info = await lstat(absolute);
|
|
93
|
+
} catch (error) {
|
|
94
|
+
if (error.code === "ENOENT") {
|
|
95
|
+
entries.push({ path, type: "missing" });
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
throw error;
|
|
99
|
+
}
|
|
100
|
+
if (info.isFile()) {
|
|
101
|
+
entries.push({ path, type: "file", bytes: info.size, sha256: await sha256File(absolute) });
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (info.isSymbolicLink()) {
|
|
105
|
+
entries.push({ path, type: "symlink", target: await readlink(absolute) });
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (info.isDirectory()) {
|
|
109
|
+
entries.push({ path, type: "directory" });
|
|
110
|
+
const children = await readdir(absolute);
|
|
111
|
+
for (const child of children.sort((left, right) => left.localeCompare(right))) {
|
|
112
|
+
await manifestEntry(root, join(absolute, child), entries);
|
|
113
|
+
}
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
entries.push({ path, type: "other" });
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export async function captureWorkspaceManifest(sourceRoot, paths) {
|
|
120
|
+
const root = resolve(sourceRoot);
|
|
121
|
+
const entries = [];
|
|
122
|
+
for (const path of [...new Set(paths.map((path) => resolve(root, path)))].sort((left, right) => left.localeCompare(right))) {
|
|
123
|
+
await manifestEntry(root, path, entries);
|
|
124
|
+
}
|
|
125
|
+
const canonical = JSON.stringify(entries);
|
|
126
|
+
return {
|
|
127
|
+
algorithm: "sha256",
|
|
128
|
+
root,
|
|
129
|
+
paths: paths.map((path) => resolve(root, path)),
|
|
130
|
+
entry_count: entries.length,
|
|
131
|
+
sha256: createHash("sha256").update(canonical).digest("hex"),
|
|
132
|
+
entries
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export async function prepareWorkspace({ cwd, workspaceKind = null, sandbox, ownedPaths, networkAccess, acceptance, externalOutputs = [], inPlaceAuthorization = null, taskId, isPreflight = false }) {
|
|
137
|
+
const sourceRoot = resolve(cwd);
|
|
138
|
+
if (!existsSync(sourceRoot)) throw workspaceError("workspace_source_missing", `workspace source directory does not exist: ${sourceRoot}`);
|
|
139
|
+
const kind = selectedKind({ sourceRoot, workspaceKind, sandbox });
|
|
140
|
+
validateKind({ kind, sourceRoot, sandbox, ownedPaths, networkAccess, acceptance, externalOutputs, inPlaceAuthorization, isPreflight });
|
|
141
|
+
if (kind !== "scratch") {
|
|
142
|
+
const manifestPaths = kind === "in_place_write" ? ownedPaths : [];
|
|
143
|
+
return {
|
|
144
|
+
kind,
|
|
145
|
+
sourceRoot,
|
|
146
|
+
executionCwd: sourceRoot,
|
|
147
|
+
manifestPaths,
|
|
148
|
+
beforeManifest: manifestPaths.length ? await captureWorkspaceManifest(sourceRoot, manifestPaths) : null,
|
|
149
|
+
landable: kind === "git_worktree",
|
|
150
|
+
cleanable: kind === "git_worktree"
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
const executionCwd = join(scratchDir, taskId);
|
|
154
|
+
await mkdir(scratchDir, { recursive: true });
|
|
155
|
+
await rm(executionCwd, { recursive: true, force: true });
|
|
156
|
+
await mkdir(executionCwd, { recursive: true });
|
|
157
|
+
return {
|
|
158
|
+
kind,
|
|
159
|
+
sourceRoot,
|
|
160
|
+
executionCwd,
|
|
161
|
+
manifestPaths: [],
|
|
162
|
+
beforeManifest: null,
|
|
163
|
+
landable: false,
|
|
164
|
+
cleanable: false,
|
|
165
|
+
scratchPath: executionCwd
|
|
166
|
+
};
|
|
167
|
+
}
|