/**
 * @internal
 * G7 constitution-coverage — blocking gate for `plan` + `execute` (C14).
 *
 * Verifies that every AGENTS.md principle is addressed in spec.md, either by
 * keyword evidence or an explicit `- [id] N/A: <reason>` opt-out inside a
 * dedicated `## Constitution Coverage` section.
 *
 * Status mapping:
 *   - AGENTS.md missing      → skip  ("no constitution — greenfield")
 *   - spec.md missing        → skip  ("spec.md not yet produced")
 *   - any principle missing  → fail  (evidence lists missing ids + summary)
 *   - otherwise              → pass
 *
 * Severity is `blocking` — when `plan` or `execute` fires this gate with a
 * non-greenfield project, a missing principle halts the skill until the
 * spec.md addresses it (or the operator runs with --force --reason per C2).
 */
import { join } from 'node:path';
import { checkCoverage } from '../../constitution/coverage.mjs';
import { registerGate } from '../registry.mjs';
const gate = {
    id: 'constitution-coverage',
    description: 'Every AGENTS.md principle is covered or explicitly N/A in the task spec.md',
    severity: 'blocking',
    skills: ['plan', 'execute'],
    async check(ctx) {
        const agentsPath = join(ctx.sharedRoot, 'AGENTS.md');
        const specPath = join(ctx.taskDir, 'spec.md');
        const result = checkCoverage({ agentsPath, specPath });
        const inputs = [agentsPath, specPath];
        if (result.status === 'skip') {
            return {
                status: 'skip',
                reason: result.reason,
                inputs,
            };
        }
        if (result.status === 'fail') {
            const missingIds = result.principles.filter((p) => p.status === 'missing').map((p) => p.id);
            return {
                status: 'fail',
                reason: result.reason,
                evidence: {
                    summary: result.summary,
                    missing: missingIds,
                },
                inputs,
            };
        }
        return {
            status: 'pass',
            reason: result.reason,
            evidence: { summary: result.summary },
            inputs,
        };
    },
};
registerGate(gate);
export default gate;
//# sourceMappingURL=constitution-coverage.mjs.map