diff --git a/README.md b/README.md index 59a7095..157298f 100644 --- a/README.md +++ b/README.md @@ -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. - **Dependencies (pinned):** `@modelcontextprotocol/sdk` (mandated SDK) and `zod` (the SDK's tool-schema API). Dev: `typescript`, `@types/node`. Nothing else. diff --git a/commands/massa.md b/commands/massa.md index 054c7dd..2fbc62d 100644 --- a/commands/massa.md +++ b/commands/massa.md @@ -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] --- diff --git a/src/cli.ts b/src/cli.ts index 86ece7a..83ba49c 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -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. */ @@ -45,7 +45,9 @@ Usage: codex-orchestrator run --project-dir [--goal-file PROJECT_GOAL.md] [--verify "" ...] [--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 ...] + [--mode mcp-server|exec|mock] [--dry-run] codex-orchestrator review --project-dir [--goal-file PROJECT_GOAL.md] [--verify "" ...] codex-orchestrator task --project-dir --prompt "" [--thread-id ] [--mode ...] [--dry-run] codex-orchestrator status --project-dir --run-id @@ -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 }, @@ -74,7 +78,7 @@ const options = { function resolveMode(values: Record): CodexMode { if (values['dry-run']) return 'mock'; - const m = (values.mode as string) ?? 'mcp-server'; + const m = (values.mode as string) ?? 'exec'; if (m === 'mock' || m === 'mcp-server' || m === 'exec') return m; throw new Error(`Invalid --mode "${m}" (mock|mcp-server|exec)`); } @@ -114,7 +118,13 @@ async function cmdRun(values: Record): Promise { 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(); diff --git a/src/codex-client.ts b/src/codex-client.ts index 8b424af..933fe54 100644 --- a/src/codex-client.ts +++ b/src/codex-client.ts @@ -332,17 +332,19 @@ export class ExecCodexClient implements CodexClient { async runTask(input: CodexTaskInput): Promise { const cwd = path.resolve(input.projectDir); - // First turn: codex exec [--json -s -a ] "" - // Continuation: codex exec resume [--json -s ... -a ...] "" - // `resume` MUST come immediately after `exec`. + // First turn: codex exec --json -c sandbox_mode=... -c approval_policy=... "" + // Continuation: codex exec resume --json -c ... "" + // `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}"`), ); // Prompt passed via a single-quoted arg; runCommand uses a shell. parts.push(shellQuote(input.prompt)); diff --git a/src/loop.ts b/src/loop.ts index d4dc21e..c20c468 100644 --- a/src/loop.ts +++ b/src/loop.ts @@ -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; } @@ -86,6 +92,7 @@ export class LoopController { private readonly taskTimeoutMs: number; private readonly verifyTimeoutMs: number; private readonly autoApproveGuards: boolean; + private readonly allowedGuards: Set; private readonly onEvent: (line: string) => void; private state!: RunState; private deadline = Number.POSITIVE_INFINITY; @@ -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 ?? (() => {}); } @@ -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 { const projectDir = path.resolve(this.params.projectDir); @@ -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); @@ -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); diff --git a/src/mcp-server.ts b/src/mcp-server.ts index 24e8a02..41cced8 100644 --- a/src/mcp-server.ts +++ b/src/mcp-server.ts @@ -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) */ @@ -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)`); } diff --git a/src/verifier.ts b/src/verifier.ts index 7bd1bc0..b803d1a 100644 --- a/src/verifier.ts +++ b/src/verifier.ts @@ -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 = '';