@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
33 lines • 1.98 kB
JavaScript
const allowedTransitions = {
ABSENT: ["STARTING"],
STARTING: ["IDLE_SYNCED", "TAINTED", "CLOSING", "BROKEN"],
IDLE_SYNCED: ["TURN_WAITING", "TAINTED", "CLOSING", "BROKEN"],
TURN_WAITING: ["TURN_SENT", "TAINTED", "CLOSING", "BROKEN"],
TURN_SENT: ["TURN_CLAIMED", "TAINTED", "CLOSING", "BROKEN"],
TURN_CLAIMED: ["TURN_STREAMING", "TAINTED", "CLOSING", "BROKEN"],
TURN_STREAMING: ["TURN_RESULT_SEEN", "TAINTED", "CLOSING", "BROKEN"],
TURN_RESULT_SEEN: ["IDLE_SYNCED", "TAINTED", "CLOSING", "BROKEN"],
TAINTED: ["CLOSING", "BROKEN"],
CLOSING: ["CLOSED", "BROKEN"],
CLOSED: [],
BROKEN: ["CLOSING", "CLOSED"],
};
export function transitionSessionState(entry, next) {
if (!allowedTransitions[entry.state].includes(next)) {
throw new Error(`Illegal session state transition: ${entry.state} -> ${next}`);
}
entry.state = next;
return entry;
}
export const transitionToStarting = (entry) => transitionSessionState(entry, "STARTING");
export const transitionToIdleSynced = (entry) => transitionSessionState(entry, "IDLE_SYNCED");
export const transitionToTurnWaiting = (entry) => transitionSessionState(entry, "TURN_WAITING");
export const transitionToTurnSent = (entry) => transitionSessionState(entry, "TURN_SENT");
export const transitionToTurnClaimed = (entry) => transitionSessionState(entry, "TURN_CLAIMED");
export const transitionToTurnStreaming = (entry) => transitionSessionState(entry, "TURN_STREAMING");
export const transitionToTurnResultSeen = (entry) => transitionSessionState(entry, "TURN_RESULT_SEEN");
export const transitionToTainted = (entry) => transitionSessionState(entry, "TAINTED");
export const transitionToClosing = (entry) => transitionSessionState(entry, "CLOSING");
export const transitionToClosed = (entry) => transitionSessionState(entry, "CLOSED");
export const transitionToBroken = (entry) => transitionSessionState(entry, "BROKEN");
//# sourceMappingURL=session-registry-state.js.map