/**
 * @internal
 * G3 all-subtasks-complete — blocking gate for `apt:verify`.
 *
 * Parses {task_dir}/implementation_plan.json and fails when any subtask's
 * status is not the literal string "completed". A missing/malformed plan is
 * also treated as a fail (the verifier cannot score what it cannot read).
 */
import { existsSync, readFileSync } from 'node:fs';
import { join } from 'node:path';
import { registerGate } from '../registry.mjs';
const gate = {
    id: 'all-subtasks-complete',
    description: 'every subtask in implementation_plan.json has status === "completed"',
    severity: 'blocking',
    skills: ['verify'],
    async check(ctx) {
        const planPath = join(ctx.taskDir, 'implementation_plan.json');
        const inputs = [planPath];
        if (!existsSync(planPath)) {
            return {
                status: 'fail',
                reason: `implementation_plan.json missing at ${planPath}`,
                inputs,
            };
        }
        let plan;
        try {
            plan = JSON.parse(readFileSync(planPath, 'utf-8'));
        }
        catch (err) {
            return {
                status: 'fail',
                reason: `implementation_plan.json does not parse: ${err.message}`,
                inputs,
            };
        }
        const subtasks = Array.isArray(plan.subtasks) ? plan.subtasks : [];
        const incomplete = subtasks.filter((s) => s?.status !== 'completed');
        if (incomplete.length > 0) {
            return {
                status: 'fail',
                reason: `${incomplete.length} subtask(s) not completed: ${incomplete
                    .map((s) => `${s.id ?? '?'}(${s.status ?? 'unknown'})`)
                    .join(', ')}`,
                evidence: { incomplete: incomplete.map((s) => ({ id: s.id, status: s.status })) },
                inputs,
            };
        }
        return {
            status: 'pass',
            reason: `${subtasks.length} subtask(s) completed`,
            inputs,
        };
    },
};
registerGate(gate);
export default gate;
//# sourceMappingURL=all-subtasks-complete.mjs.map