@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
59 lines • 2.98 kB
TypeScript
/**
* A session's persistence lifecycle across process restarts: take the per-session lease, restore
* the persisted monitors on a detached promise (session_start never waits on a grace window), and
* deliver ONE decided digest through a slot that holds it until a model is bound. A live foreign
* holder defers everything: the footer says who holds the monitors, and a lease keeper takes the
* session over the moment that process exits, running the same restore exactly once. Monitors
* created while waiting are queued and reach the manifest after the takeover.
*/
import type { ExtensionAPI, ExtensionContext } from "../../types.ts";
import { type LeaseKeeper } from "./lease-keeper.ts";
import { type DigestSlot } from "./restore-digest.ts";
import type { TerminalSessionBundle } from "./session-bundle.ts";
import { TerminalManifestWriter } from "./terminal-manifest.ts";
import type { TerminalToolContext } from "./tools/context.ts";
export declare const RESTORE_STATUS_KEY = "terminal-restore";
/** Test-only timing overrides; production uses the modules' own defaults. */
export declare const restoreSessionTestHooks: {
keeperIntervalMs?: number;
graceMs?: number;
};
export interface PersistenceState {
ctx: ExtensionContext | undefined;
readonly settings: {
readonly notify: string;
};
bundle: TerminalSessionBundle | null;
lease: {
path: string;
pid: number;
token: string;
} | null;
manifestWriter: TerminalManifestWriter | null;
ensurePersistence: (() => Promise<void>) | null;
recordedBackgroundIds: Set<string>;
keeper: LeaseKeeper | null;
digestSlot: DigestSlot;
generation: number;
restoreInFlight: Promise<void>;
}
/** Settles once this session's current generation has decided its restore (or had nothing to decide). */
export declare function whenRestoreDecided(sessionKey: string): Promise<void>;
export declare function flushRestoreDigest(pi: ExtensionAPI, state: PersistenceState): void;
interface StartOptions {
readonly pi: ExtensionAPI;
readonly state: PersistenceState;
readonly toolCtx: TerminalToolContext;
readonly sessionKey: string;
}
/** Non-reload session_start (and a reload that does not hold the lease): take ownership or wait for it. */
export declare function startPersistence({ pi, state, toolCtx, sessionKey }: StartOptions): Promise<void>;
/**
* session_shutdown (not reload): stop waiting, finish any restore, suspend and flush, release. A graceful close
* (`closed`, oh-my-openagent#14313) records nothing to restore instead of suspending.
*/
export declare function stopPersistence(state: PersistenceState, sessionKey: string, closed?: boolean): Promise<void>;
/** Detach the manifest recorder without writing (a reload keeps live state instead). */
export declare function detachPersistence(state: PersistenceState, sessionKey: string | undefined): void;
export {};
//# sourceMappingURL=restore-session.d.ts.map