export function buildPiLaunch(input) {
    const command = input.runtimeSettings?.command?.mode === "replace" && input.runtimeSettings.command.argv[0]
        ? input.runtimeSettings.command.argv
        : input.command;
    const argv = [...command];
    if (!hasModeRpc(argv)) {
        argv.push("--mode", "rpc");
    }
    if (input.session.model) {
        argv.push("--model", input.session.model);
    }
    if (input.session.thinkingOptionId) {
        argv.push("--thinking", input.session.thinkingOptionId);
    }
    if (input.session.session) {
        argv.push("--session", input.session.session);
    }
    const systemPrompt = input.session.systemPrompt?.trim();
    if (systemPrompt) {
        argv.push("--append-system-prompt", systemPrompt);
    }
    if (input.session.mcpConfigPath) {
        argv.push("--mcp-config", input.session.mcpConfigPath);
    }
    for (const extensionPath of input.session.extensionPaths ?? []) {
        argv.push("--extension", extensionPath);
    }
    return {
        cwd: input.session.cwd,
        argv,
        env: input.runtimeSettings?.env || input.session.env
            ? {
                ...input.runtimeSettings?.env,
                ...input.session.env,
            }
            : undefined,
        model: input.session.model,
        thinkingOptionId: input.session.thinkingOptionId,
        session: input.session.session,
        systemPrompt,
        mcpConfigPath: input.session.mcpConfigPath,
        extensionPaths: input.session.extensionPaths,
    };
}
function hasModeRpc(argv) {
    for (let i = 0; i < argv.length; i += 1) {
        if (argv[i] === "--mode" && argv[i + 1] === "rpc") {
            return true;
        }
        if (argv[i] === "--mode=rpc") {
            return true;
        }
    }
    return false;
}
//# sourceMappingURL=runtime.js.map