/**
 * Recorder helpers for ProposedToolCall lifecycle. Pure types live in
 * src/native/protocol/task-permission-types.ts; this file owns the
 * mutation API consumed by the conversation dispatch loop.
 */
export function recordProposal(list, args) {
    const initial = args.riskClass === 'safe' ? 'not_needed' : 'needed';
    const entry = {
        tool: args.tool,
        riskClass: args.riskClass,
        permissionState: initial,
        proposedAtIter: args.iteration,
        postGrantEvidence: [],
    };
    if (args.toolUseId !== undefined)
        entry.toolUseId = args.toolUseId;
    list.push(entry);
    return entry;
}
export function recordPermissionRequested(tc) {
    if (tc.permissionState === 'needed') {
        tc.permissionState = 'requested';
    }
}
export function recordPermissionGranted(tc, args) {
    if (tc.permissionState !== 'needed' && tc.permissionState !== 'requested')
        return;
    tc.permissionState = 'granted';
    tc.grantEvent = {
        ts: Date.now(),
        mode: args.mode,
        iteration: args.iteration,
    };
}
export function recordPermissionDenied(tc) {
    if (tc.permissionState !== 'needed' && tc.permissionState !== 'requested')
        return;
    tc.permissionState = 'denied';
}
export function recordExecutionStart(tc, iteration) {
    if (tc.permissionState !== 'granted' && tc.permissionState !== 'not_needed')
        return;
    tc.startedAtIter = iteration;
}
export function recordSettlement(tc, iteration) {
    if (tc.startedAtIter === undefined)
        return;
    tc.completedAtIter = iteration;
}
export function recordPostGrantEvidence(tc, args) {
    if (tc.permissionState !== 'granted' && tc.permissionState !== 'not_needed')
        return;
    tc.postGrantEvidence.push({
        kind: args.kind,
        detail: args.detail,
        ts: Date.now(),
    });
}
export function derivedLifecycle(tc) {
    if (tc.permissionState === 'denied')
        return 'denied';
    if (tc.completedAtIter !== undefined)
        return 'settled';
    if (tc.startedAtIter !== undefined)
        return 'executing';
    if (tc.permissionState === 'granted')
        return 'granted_idle';
    if (tc.permissionState === 'requested')
        return 'awaiting';
    return 'proposed';
}
//# sourceMappingURL=turn-permission-state.js.map