import { readJson, writeJsonAtomic } from '../fsx.js';
import { loopCheckpointPath, loopLatestCheckpointPath } from './loop-artifacts.js';
export async function writeLoopCheckpoint(input) {
    const checkpoint = {
        schema: 'sks.loop-checkpoint.v1',
        mission_id: input.mission_id,
        loop_id: input.loop_id,
        iteration: input.iteration,
        phase: input.phase,
        state_path: input.state_path,
        proof_path: input.proof_path,
        resumable: input.resumable,
        created_at: new Date().toISOString()
    };
    await writeJsonAtomic(loopCheckpointPath(input.root, input.mission_id, input.loop_id, input.iteration, input.phase), checkpoint);
    await writeJsonAtomic(loopLatestCheckpointPath(input.root, input.mission_id, input.loop_id), checkpoint);
    return checkpoint;
}
export async function readLatestLoopCheckpoint(root, missionId, loopId) {
    return readJson(loopLatestCheckpointPath(root, missionId, loopId), null);
}
//# sourceMappingURL=loop-checkpoint.js.map