import { agentCapabilities } from '../capabilities.js';
import { DEFAULT_MODEL_OPTION } from './shared.js';
export const claudeAgentDef = {
    id: 'claude',
    name: 'Claude Code',
    bin: 'claude',
    // Drop-in forks that ship a CLI argv-compatible with `claude`. Tried in
    // order if `claude` itself isn't on PATH, so users on a single-binary
    // install (e.g. only OpenClaude — https://github.com/Gitlawb/openclaude
    // — issue #235) get auto-detected without writing wrapper scripts.
    fallbackBins: ['openclaude'],
    versionArgs: ['--version'],
    helpArgs: ['-p', '--help'],
    capabilityFlags: {
        // Flag string -> capability key. After probing `--help`, we set
        // `agentCapabilities[id][key] = true` for each substring that matches.
        // `--add-dir` and `--include-partial-messages` live under `claude -p`
        // subcommand, so we probe `claude -p --help` instead of `claude --help`.
        // Fixes issue #430: --add-dir never detected because it wasn't in global help.
        '--include-partial-messages': 'partialMessages',
        '--add-dir': 'addDir',
    },
    // `claude` has no list-models subcommand; the CLI accepts both short
    // aliases (sonnet/opus/haiku) and the full ids, so we ship both as
    // hints. Users who want a non-shipped model can paste it via the
    // Settings dialog's custom-model input.
    fallbackModels: [
        DEFAULT_MODEL_OPTION,
        { id: 'sonnet', label: 'Sonnet (alias)' },
        { id: 'opus', label: 'Opus (alias)' },
        { id: 'haiku', label: 'Haiku (alias)' },
        { id: 'claude-opus-4-5', label: 'claude-opus-4-5' },
        { id: 'claude-sonnet-4-5', label: 'claude-sonnet-4-5' },
        { id: 'claude-haiku-4-5', label: 'claude-haiku-4-5' },
    ],
    // Prompt delivered via stdin to avoid both Linux `spawn E2BIG`
    // (MAX_ARG_STRLEN caps a single argv entry at ~128 KB) and Windows
    // `spawn ENAMETOOLONG` (CreateProcess caps the full command line at
    // ~32 KB direct, ~8 KB via .cmd shim). `claude -p` with no positional
    // prompt reads the prompt from stdin under `--input-format text` (the
    // default), which has no length cap. Mirrors the codex/gemini/opencode/
    // cursor/qwen entries below.
    buildArgs: (_prompt, _imagePaths, extraAllowedDirs = [], options = {}) => {
        const caps = agentCapabilities.get('claude') || {};
        // `--input-format stream-json` lets the daemon stream multiple JSONL
        // messages into stdin instead of closing it after the initial prompt.
        // This is what lets us answer Claude's `AskUserQuestion` tool calls
        // with a real `tool_result` block — without it claude-code auto errors
        // the tool because it cannot prompt the user interactively in headless
        // mode, and the model falls back to a markdown duplicate of the same
        // options.
        const args = ['-p', '--input-format', 'stream-json', '--output-format', 'stream-json', '--verbose'];
        // `--include-partial-messages` lands richer streaming events but only
        // exists in newer Claude Code builds. Older installs reject it with
        // "unknown option" and exit 1, killing the chat. Gate on the probe.
        if (caps.partialMessages) {
            args.push('--include-partial-messages');
        }
        if (options.model && options.model !== 'default') {
            args.push('--model', options.model);
        }
        const dirs = (extraAllowedDirs || []).filter((d) => typeof d === 'string' && d.length > 0);
        // `--add-dir` is older but still gate it for symmetry — old/forked
        // builds may lack it.
        if (dirs.length > 0 && caps.addDir !== false) {
            args.push('--add-dir', ...dirs);
        }
        args.push('--permission-mode', 'bypassPermissions');
        return args;
    },
    promptViaStdin: true,
    promptInputFormat: 'stream-json',
    streamFormat: 'claude-stream-json',
};
//# sourceMappingURL=claude.js.map