@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
66 lines • 3.75 kB
TypeScript
/** How long a client should wait before retrying a path another generation still holds. */
export declare const SESSION_PATH_RETRY_AFTER_MS = 2000;
export interface SessionPathOwner {
readonly instanceId: string;
readonly host_socket?: string;
readonly pid: number;
readonly processStartTime: string | null;
readonly sessionPath: string;
/** Whether the owner had a client attached when it last published this claim. */
readonly attached?: boolean;
/** Whether the owner is the generation the pointer names. Answered on read, never stored. */
readonly current?: boolean;
/** The owner removes this claim itself when the session leaves it, so it stands while the owner runs. */
readonly strict_transfer?: true;
}
export interface SessionPathReservations {
/** Live processes registered to this daemon, never inferred from a holder's own labels. */
holderPids?(observedStarts?: ReadonlyMap<number, number | undefined>): Promise<readonly number[]>;
/** Records this host as the holder of `sessionPath`, or reports the holder whose claim stands. */
claim(sessionPath: string, attached?: boolean): Promise<SessionPathOwner | undefined>;
/** Drops this host's claim. A claim made by another generation is never touched. */
release(sessionPath: string): Promise<void>;
/** Republishes this host's claim with the attachment state that session now has. */
setAttached(sessionPath: string, attached: boolean): void;
}
/** One published claim, as a reader of the directory finds it. */
export interface SessionPathClaim {
readonly file: string;
readonly owner: SessionPathOwner;
}
/** One claim per canonical session path, named by its hash so the file name is bounded. */
export declare function reservationFile(dir: string, sessionPath: string): string;
/**
* The claims of a host serving one ENDPOINT, or none when there is no endpoint to share. A
* supervised host is TOLD its daemon directory, because the socket it binds is a private hop rather
* than the public endpoint; a bare socket host derives it from what it listens on; a stdio host has
* no daemon directory, no successor generation and therefore nothing to publish.
*/
export declare function createEndpointReservations(host: {
readonly agentDir: string;
readonly socket: string | undefined;
readonly instanceId: string;
readonly onFailure?: (message: string) => void;
readonly publicSocket?: string;
}): SessionPathReservations | undefined;
export declare function createSessionPathReservations(options: {
/** This endpoint's daemon directory: the claims live in it, and so does the pointer they are read against. */
readonly daemonDir: string;
readonly instanceId: string;
readonly pid?: number;
readonly publicSocket?: string;
readonly onFailure?: (message: string) => void;
}): SessionPathReservations;
/** Every claim published in one reservations directory, for a reader pruning or reporting them. */
export declare function readSessionPathClaims(dir: string): Promise<readonly SessionPathClaim[]>;
/**
* A claim counts only while the process that made it is still running. The recorded start time is
* what separates "that host is still writing" from "the OS handed its pid to something else".
*/
export declare function claimOwnerIsLive(owner: SessionPathOwner): Promise<boolean>;
/**
* `proven`: the pid runs and its start time matches the claim. `gone`: the pid is dead, or runs with a
* different start time. `unproven`: the pid runs but no start time was recorded or none can be read.
*/
export declare function claimOwnerIdentity(owner: SessionPathOwner): Promise<"proven" | "gone" | "unproven">;
//# sourceMappingURL=host-reservations.d.ts.map