import { debug, internalWarn } from "../../engine/core/logger.js";
import { lazyLLM, lazyIO } from "./lazy_loaders.js";
import { listToolInvocationContracts } from "../../engine/contracts/tool_invocation_contract_registry.js";
import { registerClassifyExpandTools } from "./tool_groups/classify_expand.js";
import { registerVerifyLearnTools } from "./tool_groups/verify_learn.js";
import { registerStatusPlanTools, registerAnalyzeReviewTools } from "./tool_groups/status_plan_analyze_review.js";
import { registerScaffoldAcceptTools, registerDeliverTools } from "./tool_groups/scaffold_accept_deliver.js";
import { registerAuxiliaryTools } from "./tool_groups/auxiliary.js";
import { registerKnowledgeTools } from "./tool_groups/knowledge.js";
import { registerAdminTools } from "./tool_groups/admin.js";
export { requiresDecisionSovereignty, requiresDetailDiscipline, requiresFirstPrinciples, requiresBrainstorm, checkDecisionSovereigntyGate, checkDetailDisciplineGate, checkFirstPrinciplesGate, checkBrainstormGate, } from "./cep_assessment.js";
export { checkWriteToolPlanGate, checkArchitectureDecisionWorkshopGate, checkDesignArtifactWriteGate, } from "./gate_checks.js";
/**
 * 注册所有 SoloForge MCP 工具到服务器实例。
 * @param server - McpServer 实例
 * @param deps - 工具依赖项（配置、知识索引、任务上下文）
 */
export async function registerTools(server, deps) {
    debug("工具注册", "开始注册 MCP 工具...");
    const { config, knowledgeIndex, taskContext } = deps;
    const projectPath = config._projectPath || process.cwd();
    // H1: LLM Gateway — Token 预算熔断，防止单任务 Token 超支
    const gateway = deps.gateway ?? new (await lazyLLM()).LLMGateway();
    // H4: IO Controller — 工作区互斥锁，防止外部修改导致的静默覆盖
    const ioController = new (await lazyIO()).IOController(projectPath);
    const ctx = {
        server,
        config,
        knowledgeIndex,
        taskContext,
        gateway,
        ioController,
        projectPath,
    };
    debug("工具注册", "批量注册核心/辅助/知识维护工具...");
    await registerClassifyExpandTools(ctx);
    await registerVerifyLearnTools(ctx);
    await registerStatusPlanTools(ctx);
    await registerAnalyzeReviewTools(ctx);
    await registerScaffoldAcceptTools(ctx);
    await registerDeliverTools(ctx);
    await registerAuxiliaryTools(ctx);
    await registerKnowledgeTools(ctx);
    await registerAdminTools(ctx);
    // ── 启动时工具契约覆盖预检 ──
    debug("工具注册", "执行工具契约覆盖预检...");
    const contracts = listToolInvocationContracts();
    const contractNames = new Set(contracts.map((c) => c.tool_name));
    // 已注册的工具名称列表（来自各 tool_groups 的 registerSafeTool 调用）
    const registeredTools = [
        "sf_classify", "sf_expand",
        "sf_verify", "sf_learn", "sf_record_verification_execution",
        "sf_status", "sf_plan", "sf_plan_advance",
        "sf_analyze", "sf_review",
        "sf_scaffold", "sf_accept",
        "sf_deliver",
        "sf_debug", "sf_explore", "sf_feasibility_check",
        "sf_test_guide", "sf_test_quality", "sf_dependency_scan",
        "sf_debt_report", "sf_contract_check", "sf_coord_check",
        "sf_navigation", "sf_observability", "sf_team_status",
        "sf_governance_report", "sf_escape_report",
        "sf_knowledge_add", "sf_knowledge_update", "sf_knowledge_audit",
        "sf_capability_update",
        "sf_onboard", "sf_resume_workspace", "sf_migration_check",
        "sf_audit_integration", "sf_audit_sample",
    ];
    // 检查 1: 每个已注册工具都有对应的 invocation contract
    for (const toolName of registeredTools) {
        if (!contractNames.has(toolName)) {
            internalWarn("工具契约预检", `工具 ${toolName} 已注册但无对应的 invocation contract`);
        }
    }
    // 检查 2: 每个 invocation contract 都有对应的已注册工具
    for (const contractName of contractNames) {
        if (!registeredTools.includes(contractName)) {
            internalWarn("工具契约预检", `invocation contract ${contractName} 无对应的已注册工具`);
        }
    }
    debug("工具注册", "工具契约覆盖预检完成。");
}
//# sourceMappingURL=index.js.map