/**
 * 问题二十六: Detail Discipline — 细节纪律契约。
 *
 * 强制执行:
 * - detail discipline 不能停留在 checklist，必须接入验证与交付 gate
 */
/** 必须检查的维度集合 */
const REQUIRED_DIMENSIONS = new Set([
    "edge_cases", "defaults", "failure_paths", "cleanup",
    "idempotency", "overwrite_behavior", "rollback", "evidence",
]);
/**
 * 创建细节纪律契约。
 */
export function createDetailDisciplineContract(overrides) {
    return {
        target_types: ["design", "implementation", "workflow"],
        required_dimensions: [...REQUIRED_DIMENSIONS],
        ...overrides,
    };
}
/**
 * 执行细节纪律检查。
 * 对目标（设计/实现/工作流/模板/产物）进行维度检查，返回缺失细节和风险项。
 */
export function performDetailCheck(contract, targetId, targetType, providedDetails) {
    const missingDetails = [];
    let blocking = false;
    for (const dim of contract.required_dimensions) {
        const provided = providedDetails[dim];
        if (!provided || provided.length === 0) {
            missingDetails.push(dim);
            if (REQUIRED_DIMENSIONS.has(dim)) {
                blocking = true;
            }
        }
    }
    return {
        target_id: targetId,
        target_type: targetType,
        checked_dimensions: contract.required_dimensions,
        missing_details: missingDetails,
        blocking,
        detail_check_status: missingDetails.length === 0
            ? "passed"
            : blocking
                ? "failed"
                : "warning",
    };
}
/**
 * 从检查结果生成风险项列表。
 */
export function generateRiskItems(check) {
    return check.missing_details.map(dim => ({
        dimension: dim,
        description: `目标 ${check.target_id} 缺少维度: ${dim}`,
        severity: REQUIRED_DIMENSIONS.has(dim) ? "blocking" : "warning",
    }));
}
/**
 * 汇总多次检查结果。
 */
export function summarizeDetailChecks(checks) {
    const blockingItems = [];
    const warningItems = [];
    const allDimensions = new Set();
    const allMissing = new Set();
    for (const check of checks) {
        const risks = generateRiskItems(check);
        for (const risk of risks) {
            if (risk.severity === "blocking") {
                blockingItems.push(risk);
            }
            else {
                warningItems.push(risk);
            }
        }
        for (const dim of check.checked_dimensions) {
            allDimensions.add(dim);
        }
        for (const dim of check.missing_details) {
            allMissing.add(dim);
        }
    }
    return {
        passed: blockingItems.length === 0,
        blocking_items: blockingItems,
        warnings: warningItems,
        checked_dimensions: [...allDimensions],
        missing_details: [...allMissing],
    };
}
/**
 * 检查细节纪律是否接入交付 gate。
 * 如果检查结果为 blocking，交付 gate 必须阻止交付。
 */
export function checkDetailGateIntegration(check, deliveryGateActive) {
    if (check.blocking && !deliveryGateActive) {
        return { allowed: false, reason: "细节纪律检查有阻断项但未接入交付 gate" };
    }
    if (check.detail_check_status === "failed" && !deliveryGateActive) {
        return { allowed: false, reason: "细节纪律检查失败但交付 gate 未激活" };
    }
    return { allowed: true, reason: "细节纪律已正确接入交付 gate" };
}
//# sourceMappingURL=detail_discipline.js.map