@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
59 lines • 2.92 kB
TypeScript
import type { SessionRegistryCapacityError } from "@earendil-works/pi-pty";
import type { TerminalRuntimeOptions, TerminalRuntimeSession } from "./runtime-session.ts";
export type { SessionRegistryCapacityError };
export interface TerminalManagerOptions {
readonly maxSessions?: number;
readonly scrollback?: number;
/** Scopes this manager's session ids (`bash_<scope>_N`); a tool child's manager sets it so its ids never match the host's. */
readonly idScope?: string;
}
export interface CreatedTerminalSession {
readonly id: string;
readonly runtime: TerminalRuntimeSession;
}
/**
* Owns the live terminal sessions for one agent session. Delegates id allocation,
* capacity caps, LRU-exited pruning, and tree-kill teardown to the pi-pty
* {@link SessionRegistry}, while keeping the richer {@link TerminalRuntimeSession}
* wrappers (screen model + output buffer) in lock-step.
*/
export declare class TerminalManager {
private registry;
private readonly runtimes;
/** Stable "mon_" identities bound to runtime session ids; survives PTY exit, then drops on session prune or teardown. */
private readonly monitorIds;
private readonly scrollback?;
private readonly idScope?;
private readonly maxSessions;
private readonly exited;
private reservations;
constructor(options?: TerminalManagerOptions);
get size(): number;
get activeSize(): number;
reserve(): (() => void) | null;
/** Spawn a new terminal session and register it under an allocated `bash_N` id. */
create(command: string, options: TerminalRuntimeOptions): Promise<CreatedTerminalSession>;
/** Look up a live-or-exited session, refreshing its LRU timestamp. */
get(id: string): TerminalRuntimeSession | null;
/** Bind a stable "mon_" id to its runtime session id; a later restore re-binds the same id. */
bindMonitorId(monitorId: string, sessionId: string): void;
/**
* Resolve a "mon_" monitor id to its current runtime "bash_N" (or "watch_N"), passing a
* runtime id through unchanged; undefined when neither resolves. Bindings intentionally
* outlive PTY exit for a final output read, then drop when the session is pruned or torn down.
*/
monitorIdOf(runtimeId: string): string | undefined;
resolveId(idOrMonitorId: string): string | undefined;
list(): {
id: string;
runtime: TerminalRuntimeSession;
}[];
/** Tree-kill one session; the exited entry is kept for a final output read until swept. */
stop(id: string): Promise<boolean>;
/** Tree-kill every session and dispose all runtime wrappers. */
teardown(): Promise<void>;
/** Dispose runtime wrappers whose registry entry was pruned (capacity/LRU eviction). */
private reconcileRuntimes;
}
export declare function isCapacityError(error: unknown): error is SessionRegistryCapacityError;
//# sourceMappingURL=manager.d.ts.map