import { DEFAULT_MODEL_OPTION, clampCodexReasoning } from './shared.js';
export const codexAgentDef = {
    id: 'codex',
    name: 'Codex CLI',
    bin: 'codex',
    versionArgs: ['--version'],
    // Codex doesn't have a `models` subcommand; ship the most common ids
    // as a hint. Users can supply other ids via the custom-model input.
    fallbackModels: [
        DEFAULT_MODEL_OPTION,
        { id: 'gpt-5.5', label: 'gpt-5.5' },
        { id: 'gpt-5.4', label: 'gpt-5.4' },
        { id: 'gpt-5.4-mini', label: 'gpt-5.4-mini' },
        { id: 'gpt-5.3-codex', label: 'gpt-5.3-codex' },
        { id: 'gpt-5.1', label: 'gpt-5.1' },
        { id: 'gpt-5.1-codex-mini', label: 'gpt-5.1-codex-mini' },
        { id: 'gpt-5-codex', label: 'gpt-5-codex' },
        { id: 'gpt-5', label: 'gpt-5' },
        { id: 'o3', label: 'o3' },
        { id: 'o4-mini', label: 'o4-mini' },
    ],
    reasoningOptions: [
        { id: 'default', label: 'Default' },
        { id: 'none', label: 'None' },
        { id: 'minimal', label: 'Minimal' },
        { id: 'low', label: 'Low' },
        { id: 'medium', label: 'Medium' },
        { id: 'high', label: 'High' },
        { id: 'xhigh', label: 'XHigh' },
    ],
    // Prompt is delivered via stdin pipe (gated by `promptViaStdin: true`
    // below) to avoid Windows `spawn ENAMETOOLONG` while keeping Codex on
    // its structured JSON stream. Recent Codex CLI versions reject a bare
    // `-` argv sentinel — passing both the pipe and `-` produces
    // `error: unexpected argument '-' found` and the agent exits with
    // code 2 before any prompt is read (see issue #237). The pipe alone
    // is sufficient for stdin delivery.
    buildArgs: (_prompt, _imagePaths, extraAllowedDirs = [], options = {}, runtimeContext = {}) => {
        // Codex CLI's `workspace-write` sandbox blocks shell invocations on
        // Windows ("powershell.exe ... rejected: blocked by policy", #1721),
        // because Codex has no working OS-level sandbox on Windows and falls
        // back to a coarse policy that rejects any shell. macOS (Seatbelt)
        // and Linux (Landlock+seccomp) keep workspace-write because their
        // sandbox enforcement permits shell while restricting writes.
        const isWindows = process.platform === 'win32';
        const args = isWindows
            ? ['exec', '--json', '--skip-git-repo-check', '--sandbox', 'danger-full-access']
            : [
                'exec',
                '--json',
                '--skip-git-repo-check',
                '--sandbox',
                'workspace-write',
                '-c',
                'sandbox_workspace_write.network_access=true',
            ];
        if (process.env.OD_CODEX_DISABLE_PLUGINS === '1') {
            args.push('--disable', 'plugins');
        }
        if (runtimeContext.cwd) {
            args.push('-C', runtimeContext.cwd);
        }
        const dirs = (extraAllowedDirs || []).filter((d) => typeof d === 'string' && d.length > 0);
        for (const d of dirs) {
            args.push('--add-dir', d);
        }
        if (options.model && options.model !== 'default') {
            args.push('--model', options.model);
        }
        if (options.reasoning && options.reasoning !== 'default') {
            const effort = clampCodexReasoning(options.model, options.reasoning);
            // Codex accepts `-c key=value` config overrides; reasoning effort
            // is exposed as `model_reasoning_effort`.
            args.push('-c', `model_reasoning_effort="${effort}"`);
        }
        return args;
    },
    promptViaStdin: true,
    streamFormat: 'json-event-stream',
    eventParser: 'codex',
};
//# sourceMappingURL=codex.js.map