@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
67 lines • 3.84 kB
TypeScript
/**
* What the interactive mode installs on its session so an extension can register a control
* endpoint. It is the only piece loaded at startup: the endpoint itself is imported on the first
* registration (a plain TUI never loads it), and it holds at most one endpoint per process.
*
* It also turns editor callbacks into the two editor edges. `draft_cleared` must not fire for a
* submission, and the editor clears itself (`onChange("")`) synchronously BEFORE it calls
* `onSubmit`, so the clear is judged one microtask later, after the submission had its chance to
* claim it.
*
* A delivery never runs ahead of input the user already submitted. Every submission opens a
* ticket, and admission is held while any ticket is open. A branch whose input still has to reach
* the runtime claims the ticket (`claimHandoff`) - text buffered for the main loop, a steer into a
* running turn - and releases it when the runtime took the input (its prompt reported a
* disposition, or the prompt call ended). Every other submission has been handed to the runtime
* (`session.prompt`, which holds admission itself from its entry - see
* `ExternalAdmission.beginInput`) or to a built-in, once the handler's synchronous part returns, so
* its ticket is released right there: a long-running `!` command never holds deliveries for its
* whole runtime, while an extension command stays held by its prompt until it submitted its text or
* its handler settled. Turn starts release
* nothing: a turn can start (an extension's, the previous input's) while a later input is still
* buffered. The last ticket's release is the `submission` edge.
*/
import type { RegisterControlEndpointOptions, SessionControlRegistration } from "../../core/extensions/types.ts";
import type { ControlEndpointHost } from "../../core/session-control-actions.ts";
import type { TuiControlContext } from "./session-control-lifecycle.ts";
interface ControlledEditor<SubmitDetails extends readonly unknown[]> {
onChange?: (text: string) => void;
onSubmit?: (text: string, ...details: SubmitDetails) => void;
}
export interface SubmissionTicket {
/** Idempotent: the runtime took this input (or it will never reach the runtime). */
release(): void;
}
export declare class TuiSessionControlHost implements ControlEndpointHost {
private active;
private editorRevision;
private hadDraft;
private submitting;
private openTickets;
private bufferedElsewhere;
private handoff;
private registering;
private readonly context;
constructor(context: () => Omit<TuiControlContext, "editorRevision">);
/**
* One registration at a time: one still opening when another starts (a retiring extension
* generation's, still in flight across a reload, and the new generation's) would otherwise finish
* last and replace `active`, leaving the other endpoint serving with no host tracking it (senpi#3246).
*/
register(options: RegisterControlEndpointOptions): Promise<SessionControlRegistration>;
private registerNow;
/** Wraps the editor's callbacks; call after both are assigned. `hasDraft` reads the composer now. */
attachEditor<SubmitDetails extends readonly unknown[]>(editor: ControlledEditor<SubmitDetails>, hasDraft: () => boolean): void;
/** Called synchronously by a submit branch whose input still has to reach the runtime. */
claimHandoff(): SubmissionTicket | undefined;
submissionInFlight(): boolean;
/** Input the TUI buffers outside the main loop (the compaction queue) holds admission the same way. */
noteBufferedElsewhere(held: boolean): void;
questionsChanged(): void;
disposeActive(): Promise<void>;
private openTicket;
private wakeIfUnheld;
private editorChanged;
}
export {};
//# sourceMappingURL=session-control-host.d.ts.map