// ── 辅助工具注册 ──
// 从 tools.ts 第 4238-4473 行提取。
// 13 个辅助工具: sf_coord_check, sf_team_status, sf_contract_check,
// sf_onboard, sf_feasibility_check, sf_debug, sf_observability,
// sf_migration_check, sf_test_guide, sf_test_quality, sf_dependency_scan,
// sf_debt_report, sf_explore。
import { createToolRegistrar } from "../middleware.js";
import { CoordCheckSchema, TeamStatusSchema, ContractCheckSchema, OnboardSchema, FeasibilityCheckSchema, DebugSchema, ObservabilitySchema, MigrationCheckSchema, TestGuideSchema, TestQualitySchema, DependencyScanSchema, ExploreSchema, } from "../schemas.js";
import { lazyChangeCoord, lazyTeam, lazyContractGuard, lazyOnboarding, lazyFeasibility, lazyDebugger, lazyObservability, lazyCapability, lazyMigration, lazyTestGen, lazyTestQuality, lazyDepScan, lazyDebt, lazyDebtReport, lazyExploration, lazyDecision, lazyGitDeps, } from "../lazy_loaders.js";
export async function registerAuxiliaryTools(ctx) {
    const { registerSafeTool } = createToolRegistrar(ctx);
    const { taskContext, config, knowledgeIndex, projectPath } = ctx;
    // ── sf_coord_check: 预测性冲突检测和跨仓库协调提示 ──
    registerSafeTool("sf_coord_check", "预测性冲突检测和跨仓库协调提示，检查分支状态、本地变更和潜在冲突", CoordCheckSchema, async (args) => {
        const result = await (await lazyChangeCoord()).checkConflicts({
            projectPath,
            config,
            branch: args.branch,
            gitOps: (await lazyGitDeps()).realGitOps,
        });
        return {
            result: result,
        };
    });
    // ── sf_team_status: 团队活动流和工作负载查询 ──
    registerSafeTool("sf_team_status", "查询团队活动流、成员工作负载、过期分支和知识库更新状态", TeamStatusSchema, async (args) => {
        const result = await (await lazyTeam()).getTeamStatus({
            projectPath,
            config,
            since: args.since,
            gitOps: (await lazyGitDeps()).realGitOps,
            knowledgeIndex: args.include_knowledge ? knowledgeIndex : undefined,
        });
        return {
            result: result,
        };
    });
    // ── sf_contract_check: API 契约变更检测 ──
    registerSafeTool("sf_contract_check", "检测 API 契约变更（路由、DTO 字段等），评估破坏性影响和跨服务依赖", ContractCheckSchema, async (args) => {
        let changedFiles = args.changed_files;
        if (!changedFiles) {
            const ctx = await taskContext.load(args.task_id);
            changedFiles = ctx?.execution?.changed_files ?? [];
        }
        const result = await (await lazyContractGuard()).checkContractChanges({
            changedFiles,
            projectPath,
            config,
            gitOps: (await lazyGitDeps()).realGitOps,
        });
        return {
            result: result,
        };
    });
    // ── sf_onboard: 新人分步引导 ──
    registerSafeTool("sf_onboard", "新人分步引导：项目概览 → 代码导览 → 知识回顾 → 首个任务建议", OnboardSchema, async (args) => {
        const result = await (await lazyOnboarding()).onboard({
            config,
            projectPath,
            knowledgeIndex,
            gitOps: (await lazyGitDeps()).realGitOps,
            currentStep: args.step,
            reset: args.reset,
        });
        return {
            result: result,
        };
    });
    // ── sf_feasibility_check: 任务可行性评估 ──
    registerSafeTool("sf_feasibility_check", "分析任务可行性：可行/风险/不可行三档评估，纯建议不阻断流程", FeasibilityCheckSchema, async (args) => {
        const ctx = await taskContext.load(args.task_id);
        if (!ctx?.classification) {
            return {
                result: { error: "任务不存在或未完成分类，请先调用 sf_classify" },
            };
        }
        const result = (await lazyFeasibility()).checkFeasibility(ctx.classification, config);
        return {
            result: result,
        };
    });
    // ── sf_debug: 智能排障（解析错误 → 根因分析 → 修复方案） ──
    registerSafeTool("sf_debug", "智能排障：解析错误 → 追踪调用链 → 根因分析 → 修复方案 → 测试建议", DebugSchema, async (args) => {
        const projectScope = [
            ...config.scope.backend,
            ...config.scope.frontend,
        ];
        const result = (await lazyDebugger()).debugError(args.error_output, args.task_id || `debug-${Date.now()}`, projectScope);
        return {
            result: result,
        };
    });
    // ── sf_observability: 系统可观测和运行报告 ──
    registerSafeTool("sf_observability", "系统可观测：运行指标、成本估算、告警检测、能力状态、周期报告", ObservabilitySchema, async (args) => {
        const stateDir = taskContext.getStateDir();
        const result = await (await lazyObservability()).generateReport(stateDir, args.period_days);
        const capability = (await lazyCapability()).getSummary();
        const output = { ...result, capability };
        return {
            result: output,
        };
    });
    // ── sf_migration_check: 数据库迁移安全性分析 ──
    registerSafeTool("sf_migration_check", "分析数据库迁移文件安全性：检测破坏性操作（DROP/DELETE/TRUNCATE）并生成回滚建议", MigrationCheckSchema, async (args) => {
        const result = (await lazyMigration()).analyzeMigration(args.content, args.filename);
        return {
            result: result,
        };
    });
    // ── sf_test_guide: 基于变更文件生成测试指引 ──
    registerSafeTool("sf_test_guide", "根据变更文件类型生成测试指引：推荐测试类型、场景、Mock 点和断言模板", TestGuideSchema, async (args) => {
        const result = (await lazyTestGen()).generateTestGuide(args.changed_files, [], config);
        return {
            result: result,
        };
    });
    // ── sf_test_quality: 测试文件质量五维评分 ──
    registerSafeTool("sf_test_quality", "评估测试文件质量：断言密度、边界覆盖、命名、重复率、场景覆盖五维评分", TestQualitySchema, async (args) => {
        const result = (await lazyTestQuality()).analyzeTestQuality(args.content, args.filename);
        return {
            result: result,
        };
    });
    // ── sf_dependency_scan: 依赖漏洞扫描 ──
    registerSafeTool("sf_dependency_scan", "扫描依赖声明文件漏洞：已知 CVE 规则匹配、未锁定版本检测、支持 npm/maven/gradle", DependencyScanSchema, async (args) => {
        const result = (await lazyDepScan()).scanDependencies(args.content, args.filename);
        return {
            result: result,
        };
    });
    // ── sf_debt_report: 技术债务报告生成 ──
    registerSafeTool("sf_debt_report", "生成技术债务报告：按分类/严重度聚合、30 天趋势、优先级排序 Top 5", {}, async () => {
        const tracker = new (await lazyDebt()).DebtTracker(projectPath);
        const result = await (await lazyDebtReport()).generateDebtReport(tracker);
        return {
            result: result,
        };
    });
    // ── sf_explore: 自主技术选型与方案证伪 ──
    registerSafeTool("sf_explore", "自主技术选型引擎：行业基准对比 + 四维权重矩阵 + 最优解宣誓 + 方案证伪 + A/B 决策诱导。禁止凭空捏造，必须基于行业标准", ExploreSchema, async (args) => {
        let classification;
        if (args.task_id) {
            const ctx = await taskContext.load(args.task_id);
            classification = ctx?.classification;
        }
        const result = (await lazyExploration()).exploreSolutions({
            domain_query: args.domain_query,
            projectConfig: config,
            classification,
            knowledgeIndex,
        });
        // 决策契约 advisory: sf_explore 应始终通过（10 字段已内置）
        const decisionContract = (await lazyDecision()).validateDecisionOutput(result);
        const exploreExtras = {};
        if (!decisionContract.passed) {
            exploreExtras.decision_contract_advisory = decisionContract.advisory;
        }
        return { result: Object.keys(exploreExtras).length > 0 ? { ...result, ...exploreExtras } : result };
    });
}
//# sourceMappingURL=auxiliary.js.map