import { withAudit } from '../../autopilot/audit-logger.js';
import { execSync } from 'node:child_process';
async function handler(ctx) {
    const { projectPath, newStatus, validateScore } = ctx;
    if (!projectPath) {
        return;
    }
    if (process.env.PLANU_ENABLE_AUTOCOMMIT !== 'true') {
        return;
    }
    // Guard: only auto-stage when validateScore is non-null (matches original inline guard)
    if (validateScore === null) {
        return;
    }
    await withAudit(projectPath, `update_status(${newStatus})`, 'gitAutoStage', () => {
        execSync('git add planu/specs/ planu/conventions.json', {
            cwd: projectPath,
            stdio: 'pipe',
        });
        return Promise.resolve();
    }).catch(() => {
        /* best-effort — non-blocking */
    });
}
export const gitAutoStageHook = {
    id: 'git-auto-stage',
    triggers: ['done'], // only on done
    requiresProjectPath: true,
    label: 'Auto-stage planu/ source-of-truth files on done (SPEC-466)',
    handler,
};
//# sourceMappingURL=git-auto-stage.hook.js.map