/**
 * 阶段前置检查函数库 — 为 MCP 工具提供独立的前置检查能力。
 *
 * 设计决策：
 * - 不依赖 stage_gate_engine.ts（已 deprecated [DC-3]）
 * - 每个 Gate 对应一个 check*() 函数
 * - 纯函数，无副作用，返回 { passed, checks, blocking_reason }
 * - 由各 MCP 工具在执行前调用
 */
/** 创建通过结果 */
function pass(gate_id, checks) {
    return { gate_id, passed: true, checks, blocking_reason_zh: null };
}
/** 创建未通过结果 */
function fail(gate_id, checks, reason) {
    return { gate_id, passed: false, checks, blocking_reason_zh: reason };
}
// ── 8 个 Gate 前置检查函数 ──
/**
 * gate-会话启动：检查 workspace 无 dirty state。
 * 当前仅做占位检查（无 sf_resume_workspace 实际状态可查询）。
 */
export function checkSessionStartup(context) {
    const checks = [
        {
            name: "无脏状态",
            passed: !context.hasActiveTask,
            message_zh: context.hasActiveTask ? "存在未完成的活跃任务" : "无活跃任务",
        },
    ];
    const allPassed = checks.every((c) => c.passed);
    return allPassed
        ? pass("gate-会话启动", checks)
        : fail("gate-会话启动", checks, "会话启动检查未通过：存在未完成的活跃任务");
}
/**
 * gate-决策研讨：检查六域决策覆盖完整性。
 */
export function checkDecisionWorkshop(context) {
    const requiredDomains = ["业务", "数据", "安全"];
    const missingDomains = requiredDomains.filter((d) => !context.decisionDomains.includes(d));
    const checks = [
        {
            name: "六域决策覆盖",
            passed: missingDomains.length === 0,
            message_zh: missingDomains.length === 0
                ? "六域决策覆盖完整"
                : `缺少决策域: ${missingDomains.join("、")}`,
        },
        {
            name: "用户确认记录",
            passed: context.hasUserConfirmation,
            message_zh: context.hasUserConfirmation ? "用户确认记录存在" : "缺少用户确认记录",
        },
    ];
    const allPassed = checks.every((c) => c.passed);
    return allPassed
        ? pass("gate-决策研讨", checks)
        : fail("gate-决策研讨", checks, `决策研讨检查未通过: ${checks.filter((c) => !c.passed).map((c) => c.message_zh).join("；")}`);
}
/**
 * gate-编码准备：检查 CodingReadiness + OOD 摘要。
 */
export function checkCodingReadiness(context) {
    const checks = [
        {
            name: "CodingReadiness 非空",
            passed: context.hasReadinessEvaluation,
            message_zh: context.hasReadinessEvaluation ? "CodingReadiness 存在" : "缺少 CodingReadiness 评估",
        },
        {
            name: "CodingReadiness 非 blocked",
            passed: !context.readinessBlocked,
            message_zh: context.readinessBlocked ? "CodingReadiness 状态为 blocked" : "CodingReadiness 状态正常",
        },
        {
            name: "OOD 摘要存在",
            passed: context.hasOodSummary,
            message_zh: context.hasOodSummary ? "OOD 摘要存在" : "缺少 OOD 设计摘要",
        },
    ];
    const allPassed = checks.every((c) => c.passed);
    return allPassed
        ? pass("gate-编码准备", checks)
        : fail("gate-编码准备", checks, `编码准备检查未通过: ${checks.filter((c) => !c.passed).map((c) => c.message_zh).join("；")}`);
}
/**
 * gate-编码实现：检查变更文件非空 + 偷懒模式。
 */
export function checkCodingImplementation(context) {
    const checks = [
        {
            name: "变更文件非空",
            passed: context.changedFiles.length > 0,
            message_zh: context.changedFiles.length > 0
                ? `变更文件数: ${context.changedFiles.length}`
                : "无变更文件",
        },
        {
            name: "偷懒模式检测",
            passed: context.lazyPatternHardFailCount === 0,
            message_zh: context.lazyPatternHardFailCount === 0
                ? "无偷懒模式"
                : `发现 ${context.lazyPatternHardFailCount} 个偷懒模式`,
        },
    ];
    const allPassed = checks.every((c) => c.passed);
    return allPassed
        ? pass("gate-编码实现", checks)
        : fail("gate-编码实现", checks, `编码实现检查未通过: ${checks.filter((c) => !c.passed).map((c) => c.message_zh).join("；")}`);
}
/**
 * gate-编码验证：检查 build 和 tests。
 * 注意：实际 build/test 执行由 sf_verify 负责，这里只做前置条件检查。
 */
export function checkCodingVerification(context) {
    const checks = [
        {
            name: "构建命令可用",
            passed: context.hasBuildCommand,
            message_zh: context.hasBuildCommand ? "构建命令可用" : "缺少构建命令",
        },
        {
            name: "测试命令可用",
            passed: context.hasTestCommand,
            message_zh: context.hasTestCommand ? "测试命令可用" : "缺少测试命令",
        },
    ];
    const allPassed = checks.every((c) => c.passed);
    return allPassed
        ? pass("gate-编码验证", checks)
        : fail("gate-编码验证", checks, `编码验证检查未通过: ${checks.filter((c) => !c.passed).map((c) => c.message_zh).join("；")}`);
}
/**
 * gate-本地验收：检查验收证据。
 */
export function checkLocalAcceptance(context) {
    const checks = [
        {
            name: "验收证据存在",
            passed: context.hasAcceptanceEvidence,
            message_zh: context.hasAcceptanceEvidence ? "验收证据存在" : "缺少验收证据",
        },
        {
            name: "用户确认记录",
            passed: context.hasUserConfirmation,
            message_zh: context.hasUserConfirmation ? "用户确认存在" : "缺少用户确认",
        },
    ];
    const allPassed = checks.every((c) => c.passed);
    return allPassed
        ? pass("gate-本地验收", checks)
        : fail("gate-本地验收", checks, `本地验收检查未通过: ${checks.filter((c) => !c.passed).map((c) => c.message_zh).join("；")}`);
}
/**
 * gate-交付：检查主链路集成和交付完备性。
 */
export function checkDelivery(context) {
    const checks = [
        {
            name: "主链路集成",
            passed: context.mainPathHardFailCount === 0,
            message_zh: context.mainPathHardFailCount === 0
                ? "主链路集成无硬失败"
                : `主链路集成有 ${context.mainPathHardFailCount} 个硬失败`,
        },
        {
            name: "交付完备性",
            passed: context.deliveryReadinessPassed,
            message_zh: context.deliveryReadinessPassed ? "交付完备性审查通过" : "交付完备性审查未通过",
        },
    ];
    const allPassed = checks.every((c) => c.passed);
    return allPassed
        ? pass("gate-交付", checks)
        : fail("gate-交付", checks, `交付检查未通过: ${checks.filter((c) => !c.passed).map((c) => c.message_zh).join("；")}`);
}
/**
 * gate-发布后观察：检查监控指标和回滚状态。
 */
export function checkPostRelease(context) {
    const checks = [
        {
            name: "监控指标正常",
            passed: context.monitoringNormal,
            message_zh: context.monitoringNormal ? "监控指标正常" : "监控指标异常",
        },
        {
            name: "无回滚触发",
            passed: context.noRollbackTriggered,
            message_zh: context.noRollbackTriggered ? "无回滚触发" : "已触发回滚",
        },
    ];
    const allPassed = checks.every((c) => c.passed);
    return allPassed
        ? pass("gate-发布后观察", checks)
        : fail("gate-发布后观察", checks, `发布后观察检查未通过: ${checks.filter((c) => !c.passed).map((c) => c.message_zh).join("；")}`);
}
//# sourceMappingURL=stage_prechecks.js.map