const SPEC_LOGIC_PATH_RE = /(?:src\/tools\/create-spec\/|src\/engine\/.*(?:assurance|validator|quality|elicitation)\/|src\/tools\/validate\.ts$)/;
const INCIDENTAL_DOMAIN_INFERENCE_RE = /\.(?:includes|match|test)\(\s*['"`](?:billing|payment|payments|auth|database|supabase|ui|frontend)['"`]\s*\)/i;
const STACK_ONLY_TRIGGER_RE = /\b(?:framework|stack|language|projectDna|dna|detectedStack)\b[^;\n]*(?:billing|payment|payments|auth|database|supabase|ui|frontend)/i;
export function evaluateNewCodeGate(files) {
    const findings = files.flatMap((file) => scanFile(file));
    return {
        passed: findings.length === 0,
        findings,
    };
}
function scanFile(file) {
    if (!SPEC_LOGIC_PATH_RE.test(file.path)) {
        return [];
    }
    const findings = [];
    const lines = file.content.split(/\r?\n/);
    lines.forEach((line, index) => {
        if (STACK_ONLY_TRIGGER_RE.test(line)) {
            findings.push({
                rule: 'new-code-stack-only-domain-trigger',
                file: file.path,
                line: index + 1,
                message: 'New code appears to trigger product-domain requirements from detected stack metadata alone.',
                evidence: line.trim(),
            });
        }
        if (INCIDENTAL_DOMAIN_INFERENCE_RE.test(line)) {
            findings.push({
                rule: 'new-code-incidental-domain-inference',
                file: file.path,
                line: index + 1,
                message: 'New code appears to infer product-domain requirements from incidental strings such as folder names.',
                evidence: line.trim(),
            });
        }
    });
    return findings;
}
//# sourceMappingURL=new-code-gate.js.map