// engine/heal/policy.ts — SPEC-745
// Classifies a file into heal tier: 1 (auto-fix) | 2 (propose-only) | 3 (never-touch)
import { hasCustomMarker, isInAllowlist } from './markers.js';
import { detectAndRepairJsonSyntax } from './recipes/json-syntax.js';
import { checkOutOfRange } from './recipes/out-of-range.js';
/**
 * Classify a planu file into a heal tier.
 * Tier-3 (never-touch) is checked first; then tier-1 (broken JSON); then tier-2 (out-of-range).
 * Returns tier-3/skipped if the file is clean.
 */
export function classifyFile(filePath, allowlist) {
    // --- Tier-3 checks (highest priority) ---
    if (isInAllowlist(filePath, allowlist)) {
        return { tier: 3, reason: 'allowlist' };
    }
    if (hasCustomMarker(filePath)) {
        return { tier: 3, reason: 'custom marker' };
    }
    // --- Tier-1: broken JSON syntax ---
    if (filePath.endsWith('.json')) {
        const jsonResult = detectAndRepairJsonSyntax(filePath);
        if (jsonResult.needsHeal && jsonResult.repaired !== undefined) {
            return {
                tier: 1,
                reason: `broken-syntax: ${jsonResult.reason ?? 'invalid JSON'}`,
                repairedContent: jsonResult.repaired,
            };
        }
        // --- Tier-2: out-of-range values ---
        const rangeResult = checkOutOfRange(filePath);
        if (rangeResult.hasViolations && rangeResult.proposedContent) {
            return {
                tier: 2,
                reason: `out-of-range: ${rangeResult.violations.map((v) => v.field).join(', ')}`,
                proposedContent: rangeResult.proposedContent,
                violations: rangeResult.violations,
            };
        }
    }
    // File is clean — skip
    return { tier: 3, reason: 'clean' };
}
//# sourceMappingURL=policy.js.map