
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="a42b6662-1103-5579-9a5c-6debfa42ce82")}catch(e){}}();
function canReturnToRunning(reason) {
    return reason === "attention" || reason === "hook" || reason === "error";
}
function asReviewState(reason) {
    if (reason === "interrupted") {
        return "interrupted";
    }
    return "awaiting_review";
}
export function reduceSessionTransition(summary, event) {
    switch (event.type) {
        case "hook.to_review": {
            if (summary.state !== "running") {
                return { changed: false, patch: {}, clearAttentionBuffer: false };
            }
            return {
                changed: true,
                patch: {
                    state: "awaiting_review",
                    reviewReason: "hook",
                },
                clearAttentionBuffer: true,
            };
        }
        case "hook.to_in_progress":
        case "agent.prompt-ready": {
            if (summary.state !== "awaiting_review" || !canReturnToRunning(summary.reviewReason)) {
                return { changed: false, patch: {}, clearAttentionBuffer: false };
            }
            return {
                changed: true,
                patch: {
                    state: "running",
                    reviewReason: null,
                },
                clearAttentionBuffer: true,
            };
        }
        case "process.exit": {
            let reason = event.exitCode === 0 ? "exit" : "error";
            if (event.interrupted) {
                reason = "interrupted";
            }
            return {
                changed: true,
                patch: {
                    state: asReviewState(reason),
                    reviewReason: reason,
                    exitCode: event.exitCode,
                    pid: null,
                },
                clearAttentionBuffer: false,
            };
        }
        default: {
            return { changed: false, patch: {}, clearAttentionBuffer: false };
        }
    }
}
//# sourceMappingURL=session-state-machine.js.map
//# debugId=a42b6662-1103-5579-9a5c-6debfa42ce82
