Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ reports progress. See [The /massa command](#the-massa-command-for-claude-code).

- **Runtime:** TypeScript / Node (ESM), built with `tsc`. Tests use the built-in
`node:test` runner — no extra test dependency.
- **Integration path:** **`codex mcp-server`** is the primary worker transport
(driven via the MCP SDK client over stdio). **`codex exec --json`** is the
fallback. Both sit behind one `CodexClient` interface alongside a **mock** impl.
- **Integration path:** **`codex exec --json`** is the default worker transport
(codex-cli 0.155+ removed `codex mcp-server`, which remains available via
`--mode mcp-server` for older CLIs). Both sit behind one `CodexClient` interface alongside a **mock** impl.
Comment on lines +49 to +51

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Update the remaining worker-mode documentation

After announcing exec as the default and stating that Codex 0.155 removed mcp-server, the same README still labels mcp-server as the primary path at lines 249-250, tells users to verify it at lines 280-281, says the default real example uses it at lines 440-442, and describes exec as merely a fallback at lines 458-465. A user following the 0.155 setup instructions will therefore run a removed command and receive an inaccurate explanation of the actual transport; update those sections together with this compatibility statement.

Useful? React with 👍 / 👎.

- **Dependencies (pinned):** `@modelcontextprotocol/sdk` (mandated SDK) and
`zod` (the SDK's tool-schema API). Dev: `typescript`, `@types/node`. Nothing else.

Expand Down
2 changes: 1 addition & 1 deletion commands/massa.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
description: Run the Codex Massa build flow — clarify the goal, then orchestrate OpenAI Codex to build it autonomously via the codex-orchestrator MCP server.
description: Run the Codex Massa build flow (OpenAI Codex backend) — clarify the goal, then orchestrate OpenAI Codex to build it autonomously via the codex-orchestrator MCP server.
argument-hint: [optional one-line idea]
---

Expand Down
18 changes: 14 additions & 4 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* status Print a run's status (get_loop_status).
* stop Request a cooperative stop of a run (stop_loop).
*
* Worker mode defaults to "mcp-server"; pass --dry-run (or --mode mock) to use
* Worker mode defaults to "exec"; pass --dry-run (or --mode mock) to use
* the mock worker with no network / no real Codex call.
*/

Expand Down Expand Up @@ -45,7 +45,9 @@ Usage:
codex-orchestrator run --project-dir <dir> [--goal-file PROJECT_GOAL.md]
[--verify "<cmd>" ...] [--max-iterations N]
[--sandbox workspace-write] [--approval-policy never]
[--max-runtime-ms N] [--mode mcp-server|exec|mock] [--dry-run]
[--max-runtime-ms N] [--task-timeout-ms N]
[--allow-guard <guard-name> ...]
[--mode mcp-server|exec|mock] [--dry-run]
codex-orchestrator review --project-dir <dir> [--goal-file PROJECT_GOAL.md] [--verify "<cmd>" ...]
codex-orchestrator task --project-dir <dir> --prompt "<text>" [--thread-id <id>] [--mode ...] [--dry-run]
codex-orchestrator status --project-dir <dir> --run-id <id>
Expand All @@ -62,6 +64,8 @@ const options = {
verify: { type: 'string' as const, multiple: true },
'max-iterations': { type: 'string' as const },
'max-runtime-ms': { type: 'string' as const },
'task-timeout-ms': { type: 'string' as const },
'allow-guard': { type: 'string' as const, multiple: true },
sandbox: { type: 'string' as const },
'approval-policy': { type: 'string' as const },
mode: { type: 'string' as const },
Expand All @@ -74,7 +78,7 @@ const options = {

function resolveMode(values: Record<string, unknown>): CodexMode {
if (values['dry-run']) return 'mock';
const m = (values.mode as string) ?? 'mcp-server';
const m = (values.mode as string) ?? 'exec';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Reject nonzero exits before making exec the default

When codex exec exits nonzero after writing an authentication, configuration, quota, or model error only to stderr, runCommand leaves res.error unset and ExecCodexClient.runTask (src/codex-client.ts:353-361) parses the empty stdout and returns a placeholder response. With this line selecting exec by default, task consequently reports status: "ok", while project loops verify and retry as though Codex responded; check exitCode and propagate stderr before promoting this transport.

Useful? React with 👍 / 👎.

if (m === 'mock' || m === 'mcp-server' || m === 'exec') return m;
throw new Error(`Invalid --mode "${m}" (mock|mcp-server|exec)`);
}
Expand Down Expand Up @@ -114,7 +118,13 @@ async function cmdRun(values: Record<string, unknown>): Promise<number> {
codexMode: mode,
},
createCodexClient({ mode }),
{ onEvent: out },
{
onEvent: out,
taskTimeoutMs: values['task-timeout-ms']
? parseInt(values['task-timeout-ms'] as string, 10)
: undefined,
allowedGuards: (values['allow-guard'] as string[] | undefined) ?? [],
},
);

await controller.init();
Expand Down
16 changes: 9 additions & 7 deletions src/codex-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,17 +332,19 @@ export class ExecCodexClient implements CodexClient {

async runTask(input: CodexTaskInput): Promise<CodexTaskResult> {
const cwd = path.resolve(input.projectDir);
// First turn: codex exec [--json -s <sandbox> -a <approval>] "<prompt>"
// Continuation: codex exec resume <id> [--json -s ... -a ...] "<prompt>"
// `resume` MUST come immediately after `exec`.
// First turn: codex exec --json -c sandbox_mode=... -c approval_policy=... "<prompt>"
// Continuation: codex exec resume <id> --json -c ... "<prompt>"
// `resume` MUST come immediately after `exec`. Sandbox and approval go in as
// -c overrides: Codex 0.155 dropped `-a` from exec and never had `-s` on
// `exec resume`, but both accept -c.
const parts = [this.cli.bin, ...this.cli.execArgs];
if (input.threadId) parts.push('resume', input.threadId);
parts.push(
this.cli.execJsonFlag,
'-s',
input.sandbox,
'-a',
input.approvalPolicy,
'-c',
shellQuote(`sandbox_mode="${input.sandbox}"`),
'-c',
shellQuote(`approval_policy="${input.approvalPolicy}"`),
Comment on lines +344 to +347

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject approval policies removed in Codex 0.155

When an API or CLI caller selects the still-advertised untrusted or on-failure policy, this override causes the targeted Codex 0.155 executable to reject its configuration before running the task. The 0.155 AskForApproval schema accepts only on-request, a granular object, or never, while this repository's CLI types and MCP schema continue accepting all four strings; validate policies according to the selected transport/version rather than forwarding unsupported values.

Useful? React with 👍 / 👎.

);
// Prompt passed via a single-quoted arg; runCommand uses a shell.
parts.push(shellQuote(input.prompt));
Expand Down
21 changes: 19 additions & 2 deletions src/loop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ export interface LoopOptions {
* only be set by an explicit human-in-the-loop approval path; default false.
*/
autoApproveGuards?: boolean;
/**
* Guard names a human explicitly approved for this run (CLI --allow-guard).
* Their blocks are downgraded to warnings and still logged; every other
* guard keeps pausing the loop.
*/
allowedGuards?: string[];
/** Optional progress callback (used by the CLI to stream output). */
onEvent?: (line: string) => void;
}
Expand All @@ -86,6 +92,7 @@ export class LoopController {
private readonly taskTimeoutMs: number;
private readonly verifyTimeoutMs: number;
private readonly autoApproveGuards: boolean;
private readonly allowedGuards: Set<string>;
private readonly onEvent: (line: string) => void;
private state!: RunState;
private deadline = Number.POSITIVE_INFINITY;
Expand All @@ -104,6 +111,7 @@ export class LoopController {
this.taskTimeoutMs = opts.taskTimeoutMs ?? DEFAULT_CODEX_TASK_TIMEOUT_MS;
this.verifyTimeoutMs = opts.verifyTimeoutMs ?? DEFAULT_VERIFY_TIMEOUT_MS;
this.autoApproveGuards = opts.autoApproveGuards ?? false;
this.allowedGuards = new Set(opts.allowedGuards ?? []);
this.onEvent = opts.onEvent ?? (() => {});
}

Expand All @@ -113,6 +121,15 @@ export class LoopController {

// ---- initialization ----------------------------------------------------

/** Downgrade human-approved guards (allowedGuards) from block to warn. */
private soften(results: GuardResult[]): GuardResult[] {
return results.map((r) =>
r.severity === 'block' && this.allowedGuards.has(r.guard)
? { ...r, severity: 'warn', message: `${r.message} (allowed for this run by --allow-guard)` }
: r,
);
}

/** Steps 1–3: read goal, gather context, build + persist the checklist. */
async init(): Promise<RunState> {
const projectDir = path.resolve(this.params.projectDir);
Expand Down Expand Up @@ -243,7 +260,7 @@ export class LoopController {
: buildFollowupPrompt(this.state);

// GUARD: outgoing prompt intent.
const promptGuards = guardPrompt(prompt);
const promptGuards = this.soften(guardPrompt(prompt));
guardResults.push(...promptGuards);
if (hasBlock(promptGuards) && !this.autoApproveGuards) {
const rec = this.baseRecord(iteration, startedAt, prompt, '', [], undefined, guardResults);
Expand Down Expand Up @@ -291,7 +308,7 @@ export class LoopController {

// Step 6: review git diff against checklist + GUARD the diff.
const diff = await getDiffStat(this.state.projectDir);
const diffGuards = guardDiff(this.state.projectDir, diff, this.thresholds);
const diffGuards = this.soften(guardDiff(this.state.projectDir, diff, this.thresholds));
guardResults.push(...diffGuards);
if (diffGuards.some((g) => g.triggered)) {
await this.store.appendEvent('guard', iteration, 'diff guard(s) triggered', diffGuards);
Expand Down
4 changes: 2 additions & 2 deletions src/mcp-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
* The worker mode (mock | mcp-server | exec) and the max-runtime limit are NOT
* tool inputs (the spec fixes the inputs); they come from environment variables:
* CODEX_ORCHESTRATOR_MODE default "mcp-server"
* CODEX_ORCHESTRATOR_MODE default "exec"
* CODEX_ORCHESTRATOR_MAX_RUNTIME_MS default 1800000 (30 min)
*/

Expand All @@ -39,7 +39,7 @@ import * as path from 'node:path';
import { fileURLToPath } from 'node:url';

function resolveMode(): CodexMode {
const m = (process.env.CODEX_ORCHESTRATOR_MODE ?? 'mcp-server').trim();
const m = (process.env.CODEX_ORCHESTRATOR_MODE ?? 'exec').trim();
if (m === 'mock' || m === 'mcp-server' || m === 'exec') return m;
throw new Error(`Invalid CODEX_ORCHESTRATOR_MODE="${m}" (mock|mcp-server|exec)`);
}
Expand Down
3 changes: 3 additions & 0 deletions src/verifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export function runCommand(
shell: true,
detached: true, // own process group so we can kill descendants on timeout
env: process.env,
// stdin closed: `codex exec` (0.155+) reads extra prompt input from stdin
// and would otherwise wait on the open pipe forever.
stdio: ['ignore', 'pipe', 'pipe'],
});
let stdout = '';
let stderr = '';
Expand Down
Loading