codex-supervisor-mcp 0.13.5 → 0.13.6

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.
Files changed (101) hide show
  1. package/package.json +18 -63
  2. package/src/{acceptance.js → app/acceptance.js} +54 -68
  3. package/src/app/cancel.js +60 -0
  4. package/src/{cleanup-plan.js → app/cleanup-plan.js} +11 -12
  5. package/src/app/compose.js +7 -0
  6. package/src/{context-compiler.js → app/context-compiler.js} +7 -13
  7. package/src/app/dispatch.js +396 -0
  8. package/src/app/followup.js +98 -0
  9. package/src/app/land-chain.js +124 -0
  10. package/src/app/landing.js +357 -0
  11. package/src/app/ownership.js +57 -0
  12. package/src/app/rebase.js +216 -0
  13. package/src/app/resume.js +164 -0
  14. package/src/app/run-state.js +26 -0
  15. package/src/app/settled.js +28 -0
  16. package/src/{side-chat.js → app/side-chat.js} +79 -265
  17. package/src/app/sse.js +20 -0
  18. package/src/app/start-run.js +77 -0
  19. package/src/app/verify-push.js +119 -0
  20. package/src/app/worktree-setup.js +176 -0
  21. package/src/{acceptance-baseline.js → domain/acceptance-baseline.js} +2 -1
  22. package/src/domain/acceptance-spec.js +30 -0
  23. package/src/domain/command-outcome.js +6 -0
  24. package/src/{overview-delta.js → domain/overview-delta.js} +5 -1
  25. package/src/domain/side-turn-view.js +73 -0
  26. package/src/{worker-preflight.js → domain/worker-preflight.js} +1 -1
  27. package/src/infra/git.js +30 -0
  28. package/src/infra/process.js +59 -0
  29. package/src/{sandbox-roots.js → infra/sandbox-roots.js} +2 -1
  30. package/src/{skill-sync.js → infra/skill-sync.js} +1 -1
  31. package/src/infra/store/db.js +265 -0
  32. package/src/infra/store/events.js +146 -0
  33. package/src/infra/store/facts.js +338 -0
  34. package/src/infra/store/reconcile.js +172 -0
  35. package/src/infra/store/records.js +160 -0
  36. package/src/infra/store/runner-readers.js +16 -0
  37. package/src/infra/store/schema.js +306 -0
  38. package/src/infra/store/sessions.js +138 -0
  39. package/src/infra/store/tasks.js +307 -0
  40. package/src/{auto-update-worker.js → infra/update/auto-update-worker.js} +4 -4
  41. package/src/{auto-update.js → infra/update/auto-update.js} +3 -3
  42. package/src/{update-check.js → infra/update/update-check.js} +4 -4
  43. package/src/{workspace-kind.js → infra/workspace-kind.js} +5 -7
  44. package/src/{worktree.js → infra/worktree.js} +56 -41
  45. package/src/{acceptance-cli.js → interface/bin/acceptance-cli.js} +7 -3
  46. package/src/{cleanup.js → interface/bin/cleanup.js} +3 -2
  47. package/src/{monitor.jsx → interface/bin/monitor.jsx} +4 -1
  48. package/src/{setup.js → interface/bin/setup.js} +7 -6
  49. package/src/{stage.js → interface/bin/stage.js} +1 -1
  50. package/src/{web-server.js → interface/bin/web-server.js} +2 -2
  51. package/src/interface/mcp/meta.js +7 -0
  52. package/src/interface/mcp/result.js +34 -0
  53. package/src/interface/mcp/schemas.js +24 -0
  54. package/src/interface/mcp/server.js +94 -0
  55. package/src/interface/mcp/tools/delivery.js +197 -0
  56. package/src/interface/mcp/tools/dispatch.js +267 -0
  57. package/src/interface/mcp/tools/facts.js +239 -0
  58. package/src/interface/mcp/tools/overview.js +202 -0
  59. package/src/interface/mcp/tools/poll.js +62 -0
  60. package/src/interface/mcp/tools/results.js +270 -0
  61. package/src/interface/mcp/tools/review.js +135 -0
  62. package/src/interface/mcp/tools/wait.js +145 -0
  63. package/src/interface/mcp/update-state.js +34 -0
  64. package/src/interface/mcp/views/overview.js +183 -0
  65. package/src/interface/mcp/views/task.js +223 -0
  66. package/src/interface/web/app.js +226 -0
  67. package/src/interface/web/views.js +224 -0
  68. package/src/mcp-server.js +3 -2223
  69. package/src/run-host/entry.js +23 -0
  70. package/src/run-host/finalize.js +236 -0
  71. package/src/run-host/launch.js +63 -0
  72. package/src/run-host/live-run.js +73 -0
  73. package/src/run-host/outcome-facts.js +61 -0
  74. package/src/run-host/streams.js +76 -0
  75. package/src/run-host/track.js +128 -0
  76. package/src/{runner-adapter.js → runners/codex/adapter.js} +6 -6
  77. package/src/runners/codex/chat-chunks.js +97 -0
  78. package/src/{event-parser.js → runners/codex/event-parser.js} +57 -55
  79. package/src/{goal-store.js → runners/codex/goal-store.js} +2 -2
  80. package/src/{mcp-config.js → runners/codex/mcp-config.js} +1 -1
  81. package/src/codex-runner.js +0 -1586
  82. package/src/landing.js +0 -507
  83. package/src/task-store.js +0 -1800
  84. package/src/web-app.js +0 -425
  85. /package/src/{failure-class.js → domain/failure-class.js} +0 -0
  86. /package/src/{owned-changes.js → domain/owned-changes.js} +0 -0
  87. /package/src/{prompt.js → domain/prompt.js} +0 -0
  88. /package/src/{status.js → domain/status.js} +0 -0
  89. /package/src/{thread-health.js → domain/thread-health.js} +0 -0
  90. /package/src/{truncate.js → domain/truncate.js} +0 -0
  91. /package/src/{worker-changes.js → domain/worker-changes.js} +0 -0
  92. /package/src/{worker-env.js → domain/worker-env.js} +0 -0
  93. /package/src/{worker-report.js → domain/worker-report.js} +0 -0
  94. /package/src/{worker-report.schema.json → domain/worker-report.schema.json} +0 -0
  95. /package/src/{bin-resolver.js → infra/bin-resolver.js} +0 -0
  96. /package/src/{cleanup-hint.js → infra/cleanup-hint.js} +0 -0
  97. /package/src/{external-output.js → infra/external-output.js} +0 -0
  98. /package/src/{handoff.js → infra/handoff.js} +0 -0
  99. /package/src/{paths.js → infra/paths.js} +0 -0
  100. /package/src/{stage-store.js → infra/stage-store.js} +0 -0
  101. /package/src/{tool-guard.js → runners/codex/tool-guard.js} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codex-supervisor-mcp",
3
- "version": "0.13.5",
3
+ "version": "0.13.6",
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.",
@@ -25,78 +25,33 @@
25
25
  ],
26
26
  "bin": {
27
27
  "codex-supervisor-mcp": "src/mcp-server.js",
28
- "codex-supervisor-accept": "src/acceptance-cli.js",
29
- "codex-supervisor-setup": "src/setup.js",
30
- "codex-supervisor-web": "src/web-server.js",
31
- "codex-supervisor-stage": "src/stage.js"
28
+ "codex-supervisor-accept": "src/interface/bin/acceptance-cli.js",
29
+ "codex-supervisor-setup": "src/interface/bin/setup.js",
30
+ "codex-supervisor-web": "src/interface/bin/web-server.js",
31
+ "codex-supervisor-stage": "src/interface/bin/stage.js"
32
32
  },
33
33
  "files": [
34
- "src/mcp-server.js",
35
- "src/bin-resolver.js",
36
- "src/setup.js",
37
- "src/skill-sync.js",
38
- "src/codex-runner.js",
39
- "src/task-store.js",
40
- "src/goal-store.js",
41
- "src/event-parser.js",
42
- "src/worktree.js",
43
- "src/landing.js",
44
- "src/acceptance.js",
45
- "src/acceptance-cli.js",
46
- "src/acceptance-baseline.js",
47
- "src/worker-changes.js",
48
- "src/owned-changes.js",
49
- "src/tool-guard.js",
50
- "src/worker-report.js",
51
- "src/worker-report.schema.json",
52
- "src/sandbox-roots.js",
53
- "src/cleanup-hint.js",
54
- "src/handoff.js",
55
- "src/external-output.js",
56
- "src/truncate.js",
57
- "src/status.js",
58
- "src/failure-class.js",
59
- "src/worker-env.js",
60
- "src/thread-health.js",
61
- "src/stage-store.js",
62
- "src/stage.js",
63
- "src/paths.js",
64
- "src/prompt.js",
65
- "src/cleanup.js",
66
- "src/cleanup-plan.js",
67
- "src/worker-preflight.js",
68
- "src/workspace-kind.js",
69
- "src/runner-adapter.js",
70
- "src/mcp-config.js",
71
- "src/context-compiler.js",
72
- "src/overview-delta.js",
73
- "src/monitor.jsx",
74
- "src/web-server.js",
75
- "src/web-app.js",
76
- "src/side-chat.js",
77
- "src/update-check.js",
78
- "src/auto-update-worker.js",
79
- "src/auto-update.js",
34
+ "src",
80
35
  "web/dist/",
81
36
  "skills/",
82
37
  "README.md",
83
38
  "LICENSE"
84
39
  ],
85
40
  "scripts": {
86
- "postinstall": "node ./src/setup.js --auto --quiet",
87
- "setup": "node ./src/setup.js",
41
+ "postinstall": "node ./src/interface/bin/setup.js --auto --quiet",
42
+ "setup": "node ./src/interface/bin/setup.js",
88
43
  "start": "node ./src/mcp-server.js",
89
- "monitor": "tsx ./src/monitor.jsx",
90
- "cleanup": "node ./src/cleanup.js",
44
+ "monitor": "tsx ./src/interface/bin/monitor.jsx",
45
+ "cleanup": "node ./src/interface/bin/cleanup.js",
91
46
  "lint": "eslint .",
92
- "test": "node ./src/bin-resolver-test.js && node ./src/truncate-test.js && node ./src/status-test.js && node ./src/migration-test.js && node ./src/setup-test.js && node ./src/setup-windows-test.js && node ./src/regression-test.js && node --test test/edge/*.test.js",
93
- "test:real": "node ./src/real-codex-test.js",
94
- "test:real:multi": "node ./src/multi-project-real-test.js",
95
- "smoke": "node ./src/smoke-test.js",
96
- "smoke:followup": "node ./src/followup-smoke-test.js",
97
- "smoke:mcp": "node ./src/mcp-smoke-test.js",
98
- "smoke:mcp-wait": "node ./src/mcp-wait-smoke-test.js",
99
- "web": "node ./src/web-server.js",
47
+ "test": "node ./test/scripts/bin-resolver-test.js && node ./test/scripts/truncate-test.js && node ./test/scripts/status-test.js && node ./test/scripts/migration-test.js && node ./test/scripts/setup-test.js && node ./test/scripts/setup-windows-test.js && node ./test/scripts/regression-test.js && node --test test/edge/*.test.js",
48
+ "test:real": "node ./test/scripts/real-codex-test.js",
49
+ "test:real:multi": "node ./test/scripts/multi-project-real-test.js",
50
+ "smoke": "node ./test/scripts/smoke-test.js",
51
+ "smoke:followup": "node ./test/scripts/followup-smoke-test.js",
52
+ "smoke:mcp": "node ./test/scripts/mcp-smoke-test.js",
53
+ "smoke:mcp-wait": "node ./test/scripts/mcp-wait-smoke-test.js",
54
+ "web": "node ./src/interface/bin/web-server.js",
100
55
  "web:install": "npm --prefix web install",
101
56
  "web:build": "npm --prefix web run build",
102
57
  "web:dev": "npm --prefix web run dev",
@@ -11,16 +11,18 @@
11
11
  // The commands are shell lines written by the main thread, so they run with
12
12
  // the supervisor's own privileges, exactly as if the main thread had run
13
13
  // them itself. That is the trust model and it is stated in the tool text.
14
- import { spawn, execFileSync } from "node:child_process";
14
+ import { runSync, spawnProcess } from "../infra/process.js";
15
15
  import { existsSync } from "node:fs";
16
16
  import { lstat, readFile, realpath } from "node:fs/promises";
17
17
  import { randomUUID } from "node:crypto";
18
18
  import { dirname, join, isAbsolute, relative, resolve } from "node:path";
19
- import { findBinaryPath } from "./bin-resolver.js";
20
- import { compareFailureBaseline } from "./acceptance-baseline.js";
19
+ import { findBinaryPath } from "../infra/bin-resolver.js";
20
+ import { compareFailureBaseline } from "../domain/acceptance-baseline.js";
21
+ import { MAX_ACCEPTANCE_COMMANDS, normalizeAcceptance } from "../domain/acceptance-spec.js";
22
+
23
+ export { MAX_ACCEPTANCE_COMMANDS, normalizeAcceptance };
21
24
 
22
25
  export const DEFAULT_ACCEPTANCE_TIMEOUT_MS = 10 * 60 * 1000;
23
- export const MAX_ACCEPTANCE_COMMANDS = 10;
24
26
  const OUTPUT_TAIL_BYTES = 2000;
25
27
  const KILL_GRACE_MS = 3000;
26
28
  const ARTIFACT_ONLY = /^(?:test\s+-[efsd]\s+[^;&|]+|\[\[?\s+-[efsd]\s+[^\]]+\]\]?)$/;
@@ -36,32 +38,6 @@ export function isTestCommand(command) {
36
38
  return typeof command === "string" && TEST_COMMAND.test(command);
37
39
  }
38
40
 
39
- // One string or a list; blanks dropped; an empty list is "not configured".
40
- export function normalizeAcceptance(value) {
41
- const list = Array.isArray(value) ? value : typeof value === "string" ? [value] : [];
42
- const commands = list.filter((entry) => entry != null && entry !== "").map((entry) => {
43
- if (typeof entry === "string") return entry.trim();
44
- if (!entry || typeof entry !== "object" || Array.isArray(entry) || typeof entry.command !== "string" || !entry.command.trim()) throw new Error("acceptance requires a command string or structured check");
45
- if (typeof entry.reportPath !== "string" || !entry.reportPath || isAbsolute(entry.reportPath) || /^[A-Za-z]:|^\\\\/.test(entry.reportPath) || entry.reportPath.split(/[\\/]/).includes("..")) throw new Error("reportPath must stay inside the worktree");
46
- const validation = compareFailureBaseline(entry.baseline, {
47
- complete: true, identity: entry.baseline?.identity,
48
- executed: [...new Set([...(entry.baseline?.required ?? []), ...(entry.baseline?.failures ?? []).map((item) => item?.test_id)])],
49
- skipped: [], failures: entry.baseline?.failures
50
- });
51
- // Validation errors concern the contract; diff results concern actual
52
- // failures, which do not exist at normalization time.
53
- if (validation.errors.length) throw new Error(`invalid acceptance baseline: ${validation.errors.join("; ")}`);
54
- return { command: entry.command.trim(), reportPath: entry.reportPath, baseline: structuredClone(entry.baseline) };
55
- }).filter(Boolean);
56
- if (commands.length === 0) return null;
57
- if (commands.length > MAX_ACCEPTANCE_COMMANDS) {
58
- const error = new Error(`acceptance lists ${commands.length} commands; at most ${MAX_ACCEPTANCE_COMMANDS} are run`);
59
- error.code = "too_many_acceptance_commands";
60
- throw error;
61
- }
62
- return commands;
63
- }
64
-
65
41
  async function readCheckEvidence(check, cwd, checkId, baseCommit) {
66
42
  try {
67
43
  const root = await realpath(cwd);
@@ -95,7 +71,7 @@ function killTree(child) {
95
71
  if (!child.pid) return;
96
72
  if (process.platform === "win32") {
97
73
  try {
98
- execFileSync("taskkill", ["/PID", String(child.pid), "/T", "/F"], { stdio: "ignore", timeout: 5000, windowsHide: true });
74
+ runSync("taskkill", ["/PID", String(child.pid), "/T", "/F"], { stdio: "ignore", timeout: 5000, windowsHide: true });
99
75
  } catch {
100
76
  child.kill();
101
77
  }
@@ -115,6 +91,50 @@ function killTree(child) {
115
91
  }, KILL_GRACE_MS).unref();
116
92
  }
117
93
 
94
+ // cmd.exe and the default POSIX sh report only the last pipeline stage. Use one
95
+ // explicit shell contract on every platform, including Windows installations
96
+ // where Git's Bash is not on a GUI client's PATH.
97
+ function resolveBash(env) {
98
+ if (process.platform !== "win32") {
99
+ if (existsSync("/bin/bash")) return "/bin/bash";
100
+ const found = findBinaryPath("bash", { env });
101
+ if (!found) throw new Error("acceptance requires Bash with pipefail; install Bash or add it to PATH");
102
+ return found;
103
+ }
104
+ const git = findBinaryPath("git", { env });
105
+ const candidates = git ? [
106
+ join(dirname(git), "..", "bin", "bash.exe"),
107
+ join(dirname(git), "..", "usr", "bin", "bash.exe"),
108
+ join(dirname(git), "bash.exe")
109
+ ] : [];
110
+ for (const root of [env.ProgramFiles, env["ProgramFiles(x86)"], env.LOCALAPPDATA && join(env.LOCALAPPDATA, "Programs")].filter(Boolean)) {
111
+ candidates.push(join(root, "Git", "bin", "bash.exe"));
112
+ }
113
+ const onPath = findBinaryPath("bash", { env });
114
+ // Windows' System32/WindowsApps launchers start WSL, which cannot run
115
+ // the worker's Windows paths and toolchain under the same contract.
116
+ if (onPath && !/[\\/](?:System32|WindowsApps)[\\/]/i.test(onPath)) candidates.push(onPath);
117
+ const bash = candidates.find((candidate) => existsSync(candidate));
118
+ if (!bash) throw new Error("acceptance requires Git for Windows Bash; install Git for Windows or add its bin directory to PATH");
119
+ return bash;
120
+ }
121
+
122
+ function spawnAcceptanceShell(cwd, env) {
123
+ const bash = resolveBash(env);
124
+ const shellEnv = { ...env };
125
+ // Non-interactive Bash reads BASH_ENV even with --noprofile/--norc. A
126
+ // user's startup file must not switch off the acceptance failure flags.
127
+ delete shellEnv.BASH_ENV;
128
+ delete shellEnv.ENV;
129
+ return spawnProcess(bash, ["--noprofile", "--norc", "-e", "-o", "pipefail", "-s"], {
130
+ cwd,
131
+ env: shellEnv,
132
+ stdio: ["pipe", "pipe", "pipe"],
133
+ windowsHide: true,
134
+ detached: process.platform !== "win32"
135
+ });
136
+ }
137
+
118
138
  function runOne(command, { cwd, env, timeoutMs, onSpawn }) {
119
139
  return new Promise((resolveRun) => {
120
140
  const startedAt = Date.now();
@@ -122,42 +142,7 @@ function runOne(command, { cwd, env, timeoutMs, onSpawn }) {
122
142
  let total = 0;
123
143
  let child;
124
144
  try {
125
- // cmd.exe and the default POSIX sh report only the last pipeline stage.
126
- // Use one explicit shell contract on every platform, including Windows
127
- // installations where Git's Bash is not on a GUI client's PATH.
128
- let bash = "/bin/bash";
129
- if (process.platform === "win32") {
130
- const git = findBinaryPath("git", { env });
131
- const candidates = git ? [
132
- join(dirname(git), "..", "bin", "bash.exe"),
133
- join(dirname(git), "..", "usr", "bin", "bash.exe"),
134
- join(dirname(git), "bash.exe")
135
- ] : [];
136
- for (const root of [env.ProgramFiles, env["ProgramFiles(x86)"], env.LOCALAPPDATA && join(env.LOCALAPPDATA, "Programs")].filter(Boolean)) {
137
- candidates.push(join(root, "Git", "bin", "bash.exe"));
138
- }
139
- const onPath = findBinaryPath("bash", { env });
140
- // Windows' System32/WindowsApps launchers start WSL, which cannot run
141
- // the worker's Windows paths and toolchain under the same contract.
142
- if (onPath && !/[\\/](?:System32|WindowsApps)[\\/]/i.test(onPath)) candidates.push(onPath);
143
- bash = candidates.find((candidate) => existsSync(candidate));
144
- if (!bash) throw new Error("acceptance requires Git for Windows Bash; install Git for Windows or add its bin directory to PATH");
145
- } else if (!existsSync(bash)) {
146
- bash = findBinaryPath("bash", { env });
147
- if (!bash) throw new Error("acceptance requires Bash with pipefail; install Bash or add it to PATH");
148
- }
149
- const shellEnv = { ...env };
150
- // Non-interactive Bash reads BASH_ENV even with --noprofile/--norc. A
151
- // user's startup file must not switch off the acceptance failure flags.
152
- delete shellEnv.BASH_ENV;
153
- delete shellEnv.ENV;
154
- child = spawn(bash, ["--noprofile", "--norc", "-e", "-o", "pipefail", "-s"], {
155
- cwd,
156
- env: shellEnv,
157
- stdio: ["pipe", "pipe", "pipe"],
158
- windowsHide: true,
159
- detached: process.platform !== "win32"
160
- });
145
+ child = spawnAcceptanceShell(cwd, env);
161
146
  } catch (error) {
162
147
  resolveRun({ command, exit_code: null, signal: null, duration_ms: 0, timed_out: false, output_tail: `spawn failed: ${error.message}` });
163
148
  return;
@@ -224,7 +209,8 @@ function runOne(command, { cwd, env, timeoutMs, onSpawn }) {
224
209
  // Runs every command in order and returns the verdict. `control.kill` is
225
210
  // filled in so a cancel can stop the command that is running; `control.isCancelled`
226
211
  // is consulted between commands.
227
- export async function runAcceptance(commands, { cwd, env = process.env, timeoutMs = DEFAULT_ACCEPTANCE_TIMEOUT_MS, run = null, taskId = null, baseCommit = null, control = {} } = {}) {
212
+ export async function runAcceptance(commands, options = {}) {
213
+ const { cwd, env = process.env, timeoutMs = DEFAULT_ACCEPTANCE_TIMEOUT_MS, run = null, taskId = null, baseCommit = null, control = {} } = options;
228
214
  const startedAt = new Date().toISOString();
229
215
  if (!cwd || !existsSync(cwd)) {
230
216
  return { status: "failed", passed: false, run, started_at: startedAt, finished_at: new Date().toISOString(), error: "cwd_missing", cwd, checks: [] };
@@ -0,0 +1,60 @@
1
+ import "./compose.js";
2
+ import { describeProcess } from "../infra/process.js";
3
+ import { getTask, upsertTask } from "../infra/store/tasks.js";
4
+ import { codexRunner } from "../runners/codex/adapter.js";
5
+ import { acceptanceRuns, cancelledTasks, processes } from "./run-state.js";
6
+
7
+ function isLikelyCodexProcess(pid) {
8
+ return codexRunner.ownsPid(pid, describeProcess);
9
+ }
10
+
11
+ // Ends a worker and, on Windows, its whole process tree: the direct child there
12
+ // is the JS wrapper around the native Codex binary, so terminating it alone
13
+ // would leave the real CLI running and the task stuck in `running`.
14
+ export function terminateChild(child) {
15
+ codexRunner.cancelChild(child);
16
+ }
17
+
18
+ function terminatePid(pid) {
19
+ codexRunner.cancelPid(pid);
20
+ }
21
+
22
+ export async function cancelCodexWorker(taskId) {
23
+ const acceptance = acceptanceRuns.get(taskId);
24
+ if (acceptance) {
25
+ acceptance.cancelled = true;
26
+ acceptance.kill?.();
27
+ return { cancelled: true, via: "acceptance", pid: null };
28
+ }
29
+ const child = processes.get(taskId);
30
+ if (child) {
31
+ cancelledTasks.add(taskId);
32
+ terminateChild(child);
33
+ return { cancelled: true, via: "process_handle", pid: child.pid ?? null };
34
+ }
35
+ // Another MCP process owns the handle; fall back to the pid recorded on disk.
36
+ const task = await getTask(taskId);
37
+ if (task?.acceptance_results?.status === "running" && await isPidAlive(task.acceptance_results.supervisor_pid)) {
38
+ await upsertTask({ ...task, cancel_requested_at: new Date().toISOString(), updated_at: new Date().toISOString() });
39
+ return { cancelled: true, via: "acceptance", pid: null };
40
+ }
41
+ if (task?.pid && (await isPidAlive(task.pid)) && isLikelyCodexProcess(task.pid)) {
42
+ try {
43
+ terminatePid(task.pid);
44
+ return { cancelled: true, via: "pid", pid: task.pid };
45
+ } catch (error) {
46
+ return { cancelled: false, reason: "kill_failed", message: error.message, pid: task.pid };
47
+ }
48
+ }
49
+ return { cancelled: false, reason: "process_not_found" };
50
+ }
51
+
52
+ export async function isPidAlive(pid) {
53
+ if (!pid) return false;
54
+ try {
55
+ process.kill(pid, 0);
56
+ return true;
57
+ } catch {
58
+ return false;
59
+ }
60
+ }
@@ -1,20 +1,19 @@
1
+ import { runGit } from "../infra/git.js";
2
+ import { runSync } from "../infra/process.js";
3
+ import "./compose.js";
1
4
  import { createHash, randomUUID } from "node:crypto";
2
5
  import { lstat, realpath } from "node:fs/promises";
3
- import { execFileSync } from "node:child_process";
4
6
  import { resolve } from "node:path";
5
- import { ACTIVE_STATUSES } from "./status.js";
6
- import { worktreesDir } from "./paths.js";
7
- import { appendTaskEvent, getTask, isPidAlive, markCleanupPlanItemApplied, readTasks, updateWorkItemDelivery, runIdFor } from "./task-store.js";
7
+ import { ACTIVE_STATUSES } from "../domain/status.js";
8
+ import { worktreesDir } from "../infra/paths.js";
9
+ import { appendTaskEvent } from "../infra/store/events.js";
10
+ import { getTask, isPidAlive, readTasks } from "../infra/store/tasks.js";
11
+ import { markCleanupPlanItemApplied, updateWorkItemDelivery } from "../infra/store/records.js";
12
+ import { runIdFor } from "../infra/store/db.js";
8
13
 
9
14
  export const CLEANUP_PLAN_TTL_MS = 15 * 60 * 1000;
10
15
 
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
- }
16
+ const git = (cwd, args) => runGit(cwd, args, { timeout: 15000, noOptionalLocks: true });
18
17
 
19
18
  function hash(value) {
20
19
  return createHash("sha256").update(value).digest("hex");
@@ -22,7 +21,7 @@ function hash(value) {
22
21
 
23
22
  async function directoryBytes(path) {
24
23
  try {
25
- const output = execFileSync("du", ["-sk", path], { encoding: "utf8", timeout: 30000, stdio: ["ignore", "pipe", "ignore"] }).trim();
24
+ const output = runSync("du", ["-sk", path], { encoding: "utf8", timeout: 30000, stdio: ["ignore", "pipe", "ignore"] }).trim();
26
25
  const kib = Number(output.split(/\s+/)[0]);
27
26
  return Number.isFinite(kib) ? kib * 1024 : 0;
28
27
  } catch {
@@ -0,0 +1,7 @@
1
+ // Composition root: wires the runner into the layers that may not import it.
2
+ // Every process entry imports this before it touches the store.
3
+ import { registerRunnerReaders } from "../infra/store/runner-readers.js";
4
+ import { extractAgentMessage } from "../runners/codex/event-parser.js";
5
+ import { readNativeGoal } from "../runners/codex/goal-store.js";
6
+
7
+ registerRunnerReaders({ nativeGoal: readNativeGoal, agentMessage: extractAgentMessage });
@@ -1,21 +1,15 @@
1
- import { buildHandoff } from "./handoff.js";
2
- import { execFileSync } from "node:child_process";
3
- import { approxTokenCount } from "./truncate.js";
4
- import { createContextSnapshot, listContextFacts, runIdFor } from "./task-store.js";
1
+ import { gitSucceeds } from "../infra/git.js";
2
+ import "./compose.js";
3
+ import { buildHandoff } from "../infra/handoff.js";
4
+ import { approxTokenCount } from "../domain/truncate.js";
5
+ import { createContextSnapshot, listContextFacts } from "../infra/store/facts.js";
6
+ import { runIdFor } from "../infra/store/db.js";
5
7
 
6
8
  const MAX_CONTEXT_TOKENS = 1500;
7
9
 
8
10
  function factAppliesToBase(task, fact) {
9
11
  if (!fact.valid_for_sha || fact.valid_for_sha === task.base_commit) return true;
10
- try {
11
- execFileSync(process.env.GIT_BIN?.trim() || "git", ["-C", task.project_root, "merge-base", "--is-ancestor", fact.valid_for_sha, task.base_commit], {
12
- stdio: "ignore",
13
- timeout: 15000
14
- });
15
- return true;
16
- } catch {
17
- return false;
18
- }
12
+ return gitSucceeds(task.project_root, ["merge-base", "--is-ancestor", fact.valid_for_sha, task.base_commit]);
19
13
  }
20
14
 
21
15
  function clip(value, max = 360) {