/**
 * @internal
 * G2 plan-exists — blocking gate for `apt:execute`.
 *
 * Requires {task_dir}/spec.md AND {task_dir}/implementation_plan.json to
 * exist and the JSON to parse. Matches the exact preconditions the executor
 * relies on in Section 1 of its skill.
 */
import { existsSync, readFileSync } from 'node:fs';
import { join } from 'node:path';
import { registerGate } from '../registry.mjs';
const gate = {
    id: 'plan-exists',
    description: 'spec.md and implementation_plan.json exist and parse',
    severity: 'blocking',
    skills: ['execute'],
    async check(ctx) {
        const specPath = join(ctx.taskDir, 'spec.md');
        const planPath = join(ctx.taskDir, 'implementation_plan.json');
        const inputs = [specPath, planPath];
        if (!existsSync(specPath)) {
            return {
                status: 'fail',
                reason: `spec.md missing at ${specPath}`,
                inputs,
            };
        }
        if (!existsSync(planPath)) {
            return {
                status: 'fail',
                reason: `implementation_plan.json missing at ${planPath}`,
                inputs,
            };
        }
        try {
            JSON.parse(readFileSync(planPath, 'utf-8'));
        }
        catch (err) {
            return {
                status: 'fail',
                reason: `implementation_plan.json does not parse: ${err.message}`,
                inputs,
            };
        }
        return {
            status: 'pass',
            reason: 'spec.md and implementation_plan.json present and valid',
            inputs,
        };
    },
};
registerGate(gate);
export default gate;
//# sourceMappingURL=plan-exists.mjs.map