UNPKG

@code-yeongyu/senpi

Version:

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

109 lines • 6.1 kB
import type { EngineOrdinal } from "../../core/engine-build-identity.ts"; import { type DaemonPidFile } from "../../utils/process-identity.ts"; import { type HostDaemonPaths, type HostGenerationPaths } from "./host-daemon-paths.ts"; /** Who wrote a registration: the process identity a later stop must match to be allowed. */ export interface HostPidFileWriter { readonly pid: number; readonly startTime: string | null; } /** What an ensure knows about the generation it just spawned. */ export interface HostRegistration { readonly record: DaemonPidFile; readonly socket: string; readonly instanceId: string; readonly generation: number; /** The profile the spawned host was launched with, for a client comparing two generations. */ readonly launchProfileId: string; /** * The build of the process this record names. Absent while it is not known yet (a handoff's * successor before it answers): the record then claims no engine version rather than the writer's. */ readonly build?: { readonly text: string; readonly ordinal: EngineOrdinal; }; } export interface RegisteredHost { readonly record: DaemonPidFile; readonly writer?: HostPidFileWriter; /** The endpoint this record is about. Absent in records written before the field existed. */ readonly socket?: string; readonly instanceId: string; readonly generation: number; } /** * The generation the pointer names, or nothing. A pointer without a readable generation record * describes no process, so it authorizes nothing - the next ensure overwrites it. */ export declare function readHostRegistration(paths: HostDaemonPaths): Promise<RegisteredHost | undefined>; /** * One NAMED generation's record, whatever the pointer says: a caller asking a superseded generation * to drain addresses it by instance id (#3653). The record proves nothing by itself; `provenOwner` * still decides whether it names a live process serving this endpoint. */ export declare function readGenerationRegistration(paths: HostDaemonPaths, instanceId: string): Promise<RegisteredHost | undefined>; /** * Registers a generation and points the daemon directory at it, under this process's writer stamp. * The stamp is what authorizes a later stop: only the process that wrote a record may signal the * host it names, and the recorded start time keeps a recycled pid from inheriting that right. * * `fresh` says the directory cannot hold an earlier generation (a terminal's endpoint, named by a * socket built from a new instance id), so there is nothing to prune. */ export declare function writeHostRegistration(paths: HostDaemonPaths, registration: HostRegistration, options?: { readonly fresh?: boolean; }): Promise<void>; /** * Records ONE generation's process in its own directory without moving the pointer. A handoff writes * this the moment its successor is spawned: until the rename lands the pointer must keep naming the * predecessor, yet the successor is already running, and `host gc` has to see that from its own record * rather than judge the endpoint by a predecessor that may have died. */ export declare function writeGenerationRecord(paths: HostDaemonPaths, registration: HostRegistration): Promise<{ generation: HostGenerationPaths; writer: HostPidFileWriter; }>; /** Drops the pointer, the generation it names and the boot settings: the host behind them is gone. */ export declare function clearHostRegistration(paths: HostDaemonPaths): Promise<void>; /** * Drops ONE generation's registration while the files still name it. After a handoff the pointer * belongs to the successor, so a draining predecessor removes only its own directory - taking the * pointer with it would leave every client reading no daemon at all while one is serving. * * A generation whose public socket another one TOOK (`superseded`) removes only its own directory, * whatever the pointer says. The pointer and `settings.json` are then the replacer's to move: a handoff * rewrites the settings before its successor boots and repoints the pointer only after it saw the rename * land, and a predecessor that noticed the rename first would read "still mine" and remove both just as, * or just after, the handoff moved them - leaving the successor serving with no registration (#2536). */ export declare function releaseGeneration(paths: HostDaemonPaths, owner: { readonly instanceId: string; readonly pid: number; readonly superseded?: boolean; }): Promise<void>; /** * Drops the pointer and the boot settings while the pointer still names `instanceId`, and leaves that * generation's directory to the generation itself: `host stop` signals a supervisor that still reads * its stop intent from there before it releases it. */ export declare function releaseRegistrationPointer(paths: HostDaemonPaths, instanceId: string): Promise<void>; /** * The generation serving this socket, when - and only when - its record PROVES which process that * is. An owner nobody can prove may not be signalled at all (I1), so an unreadable identity, a * missing guard or a record about another endpoint all read as "no owner". */ export declare function provenOwner(registered: RegisteredHost | undefined, socket: string): Promise<{ pid: number; processStartTime: string; instanceId: string; } | undefined>; /** * I1 in one predicate: the registration names a host THIS process started. A writer that cannot be * proven ours reads as foreign, so the worst case of an unreadable identity is a refusal rather * than a signal sent to another owner's host. */ export declare function writtenByThisProcess(writer: HostPidFileWriter | undefined, readStartTime?: (pid: number) => Promise<string | undefined>): Promise<boolean>; export declare function thisProcessStartTime(): Promise<string | null>; /** A caller-supplied instance id names a directory under `generations/`: never a path of its own. */ export declare function isGenerationId(instanceId: string): boolean; //# sourceMappingURL=host-daemon-registration.d.ts.map