import { recordStatusChange } from '../../autopilot/state-updater.js';
import { withAudit } from '../../autopilot/audit-logger.js';
import { appendAutopilotLogEntry } from '../../../storage/autopilot-log-store.js';
import { hashProjectPath } from '../../../storage/base-store.js';
async function handler(ctx) {
    const { projectPath, projectId, specId, newStatus, currentStatus } = ctx;
    if (!projectPath) {
        return;
    }
    const start = Date.now();
    try {
        await withAudit(projectPath, `update_status(${newStatus})`, 'recordStatusChange', () => recordStatusChange(projectPath, projectId, specId, currentStatus, newStatus));
    }
    catch (err) {
        const error = err instanceof Error ? err.message : String(err);
        void appendAutopilotLogEntry(hashProjectPath(projectPath), {
            specId,
            hookName: 'status-json',
            result: 'fail',
            error,
            timestamp: new Date().toISOString(),
            durationMs: Date.now() - start,
        });
        // Do NOT re-throw — cascade must continue with remaining hooks
    }
}
export const statusJsonHook = {
    id: 'status-json',
    triggers: [], // any status change + release_completed
    requiresProjectPath: true,
    label: 'Auto-update external project status with spec counts (SPEC-459/776)',
    handler,
};
//# sourceMappingURL=status-json.hook.js.map