import { createSeedAgents } from "../agents/index.js";
import { createOpenCodeNativeAgentHiddenConfig } from "../agents/opencode-isolation.js";
import { resolveSeedRuntimeLanguage } from "../features/language/index.js";
import { createSeedMcpDefaults, mergeMcpConfig } from "../mcp/index.js";
export function createConfigHandler(args) {
    return async function configHandler(opencodeConfig) {
        const seedAgents = createSeedAgents(args.config);
        const isolation = args.config.isolation;
        const hostAgents = opencodeConfig.agent ?? {};
        const inheritedDisableAgents = isolation.allow_host_agents ? {} : pickDisabledAgentEntries(hostAgents);
        const seedAgentIsolation = isolation.allow_host_agents
            ? {}
            : createOpenCodeNativeAgentHiddenConfig();
        opencodeConfig.agent = isolation.allow_host_agents
            ? { ...hostAgents, ...seedAgentIsolation, ...seedAgents }
            : { ...seedAgentIsolation, ...inheritedDisableAgents, ...seedAgents };
        opencodeConfig.default_agent = args.config.default_run_agent;
        const seedCommand = createSeedCommands(args.config.default_run_agent, args.config);
        const hostCommands = opencodeConfig.command ?? {};
        opencodeConfig.command = isolation.allow_host_commands ? { ...omitSeedControlCommands(hostCommands), ...seedCommand } : seedCommand;
        opencodeConfig.mcp = mergeMcpConfig(isolation.allow_host_mcp ? opencodeConfig.mcp : undefined, createSeedMcpDefaults(args.config, args.directory));
        opencodeConfig.tools = {
            ...(isolation.allow_host_tool_config ? (opencodeConfig.tools ?? {}) : {}),
            ...Object.fromEntries(args.config.disabled_tools.map((name) => [name, false])),
        };
    };
}
export function createSeedCommands(agent, config) {
    const command = (description) => ({
        description,
        agent,
        template: seedCommandTemplate(config),
    });
    return {
        seed: command("Start a SEED Lab research-agent run"),
    };
}
function pickDisabledAgentEntries(agents) {
    return Object.fromEntries(Object.entries(agents).filter(([, value]) => {
        return typeof value === "object" && value !== null && value.disable === true;
    }));
}
function omitSeedControlCommands(commands) {
    const retiredSeedCommands = new Set(["seed-status", "seed-lab-meeting", "seed-report", "seed-trace", "seed-stop", "seed-resume", "seed-intervene", "seed-meeting", "seed-meeting-now", "seed-meeting-status", "seed-meeting-enable"]);
    return Object.fromEntries(Object.entries(commands).filter(([name]) => !retiredSeedCommands.has(name)));
}
function seedCommandTemplate(config) {
    if (resolveSeedRuntimeLanguage(config) === "ko") {
        return `<seed-command>
Arguments: $ARGUMENTS

이것은 OpenCode SEED 명령입니다. Lab-Representative가 처리해야 합니다. primary OpenCode agent id는 lab-representative입니다.

교수-facing 기본 언어는 한국어입니다. 일반 응답, 진행 보고, progress.md, final_report.md, Lab Meeting 요약, 팀원 보고, 차단 사유는 교수가 명시적으로 다른 언어를 요청하지 않는 한 한국어로 작성하세요. 코드, 명령어, 파일 경로, API 이름, 패키지명, 원문 인용은 번역하지 마세요.

arguments는 교수의 작업 목표입니다. 새 SEED run을 시작하세요:
1. seed_task_*로 task state를 만들고 갱신하세요.
2. seed_trace_event와 seed_evidence_add로 durable trace를 남기세요.
3. 충분히 큰 작업이면 dynamic inline team spec을 합성하고 검증한 뒤, built-in workflow template를 가정하지 말고 seed_team_create inline_spec으로 시작하세요.
4. progress.md와 final_report.md를 최신 상태로 유지하세요.

상태 확인과 랩미팅은 이 프롬프트로 처리하지 않습니다. /seed-status와 /seed-lab-meeting은 OpenCode/SEED TUI 프레임워크가 별도 로컬 명령으로 처리합니다.
</seed-command>`;
    }
    return `<seed-command>
Arguments: $ARGUMENTS

You are receiving an OpenCode SEED command. Route this through Lab-Representative. The primary OpenCode agent id is lab-representative.

Professor-facing language: English. Write normal chat updates, progress.md, final_report.md, Lab Meeting notes, team summaries, blockers, and handoffs in English unless the professor explicitly asks for another language. Keep code, commands, paths, API names, package names, and quoted source text unchanged.

The arguments are the professor's task goal. Start a new SEED run:
1. Use seed_task_create to create a task board.
2. Use seed_trace_event and seed_evidence_add for durable trace.
3. For substantial tasks, synthesize and validate a dynamic inline team spec, then call seed_team_create with inline_spec.
4. Keep progress.md and final_report.md current through SEED progress/report tools.

Do not process status checks or Lab Meetings through this prompt. /seed-status and /seed-lab-meeting are handled by the OpenCode/SEED TUI framework as separate local commands.
</seed-command>`;
}
//# sourceMappingURL=config-handler.js.map