UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

52 lines • 3.44 kB
import { type SessionManager } from "../session-manager.ts"; import { type MoveId } from "./ownership.ts"; /** * State an extension keeps outside the session folder (task records, logs, finished child sessions) and wants to * follow a moved session (senpi#3676, design v7 section 4). The sender's extensions write it into a staging folder at * the `move` release, while their runtime is still live (`session_move_export`); export bundles that folder as the * `extension-state` payload; import unpacks it next to the session (`movedStateDir`); and the next open hands it to the * receiver's extensions once (`session_move_import`), then records `session_move_state_restored` and removes it. * * Every hand-over is per attempt (senpi#3681 delta review): a handler the host stopped waiting on can keep running, * so each release attempt stages into its own folder and only the attempt recorded in the seal is bundled, and each * import delivery hands out its own copy. A late write therefore only ever lands in a dead attempt's folder. */ export declare const EXTENSION_STATE_PAYLOAD = "extension-state"; export declare const MOVED_STATE_RESTORED = "session_move_state_restored"; /** The `session_released` field naming the release attempt whose staged state the move bundles. */ export declare const STATE_ATTEMPT_FIELD = "state_attempt"; /** Every release attempt of `moveId` stages under this folder; finish removes it whole. */ export declare function outgoingStateDir(sessionFile: string, moveId: MoveId): string; export declare function movedStateDir(sessionFile: string, moveId: MoveId): string; /** The folder of the release attempt that sealed the session for `moveId`, if that release staged one. */ export declare function sealedOutgoingStateDir(sessionFile: string, moveId: MoveId): Promise<string | undefined>; /** * Creates a fresh, empty folder for one release attempt. Earlier attempts of the move that never sealed the session * are dead and removed (a handler still running for one of them may recreate its own folder, which is never read). */ export declare function prepareOutgoingState(sessionFile: string, moveId: MoveId): Promise<{ readonly attempt: string; readonly dir: string; }>; /** * The state the last move into this session left for its extensions, if it has not been handed over yet. Only the * newest `session_moved_in` counts, and only until a `session_move_state_restored` for that move is written. */ export declare function pendingMovedState(sessionFile: string): Promise<{ readonly moveId: MoveId; readonly dir: string; } | undefined>; export interface MovedStateDelivery { readonly moveId: MoveId; readonly dir: string; readonly redelivered: boolean; } /** * Hands pending moved state to the session's extensions: `deliver` runs the import handlers on a fresh copy and * resolves `true` when every one of them restored it; only then is the restored marker written and the state removed. * A failed handler, or a crash before the marker, delivers it again on the next open with `redelivered` set (handlers * must be idempotent). The copy is removed once `deliver` returns, so a handler still running past its budget can * never change what a later delivery sees. */ export declare function restoreMovedState(sessionManager: SessionManager, deliver: (event: MovedStateDelivery) => Promise<boolean>): Promise<void>; //# sourceMappingURL=extension-state.d.ts.map