UNPKG

@code-yeongyu/senpi

Version:

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

42 lines • 2.8 kB
/** * The drain of a graceful close (`unload_session { graceful: true }`, oh-my-openagent#14313), shared by a host and a * terminal's control endpoint. The fence comes first and in one synchronous step: automatic turns wait as notices * (the running turn is the session's last), admission refuses every new delivery typed `session_closing`, and the * queued input leaves the session at once, handed back to its senders unread. The running turn and its tool calls * then end on their own; nothing is aborted. A drain that outlives its bound reopens the session as it was. */ import type { AgentSession } from "../../core/agent-session.ts"; import type { SessionClosedRecord } from "../../core/session-closed.ts"; import { type ReleaseDropped } from "./session-release-interrupt.ts"; export interface GracefulDrainPort { /** What still keeps the session from closing (a run, a prompt in preflight, bash, compaction, a request); empty when quiet. */ busy(): readonly string[]; /** Work that settles as the session quiets: prompts in preflight and other requests for it. */ settling(): readonly Promise<unknown>[]; } export interface GracefulDrain { readonly dropped: ReleaseDropped; readonly startedAt: number; } export declare function gracefulWaitMs(requested: number | undefined): number; export declare function fenceForClose(session: AgentSession): GracefulDrain; /** A drain that did not end in a close leaves the session open and admitting, as before the fence. */ export declare function reopenAfterDrain(session: AgentSession): void; /** * Resolves `true` once `port.busy()` is empty, `false` when `waitMs` passes first. It wakes on every session event and * on the settling work, re-checking each time; nothing polls. It subscribes once: `subscribe` replays standing events * (a selected settings source, a resume slice) to the new listener at once, and a listener taken per pass would count * that replay as a change and spin the host's loop until the deadline, so the turn it waits for could never stream. */ export declare function drainUntilQuiet(session: Pick<AgentSession, "subscribe" | "waitForIdle">, port: GracefulDrainPort, waitMs: number): Promise<boolean>; export declare function drainFacts(session: AgentSession, drain: GracefulDrain): { turn: number; waited_ms: number; }; /** * The quiet session's clean stop, in the same synchronous step as the close claim that follows it: the closing hold is * released (a reopen replays no pause), the `session-closed` record is written, and the teardown's `session_shutdown` * will carry `closed: true`. Answers the record. */ export declare function recordGracefulClose(session: AgentSession, drain: GracefulDrain): SessionClosedRecord; //# sourceMappingURL=session-graceful-close.d.ts.map