@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
69 lines • 4.41 kB
TypeScript
/** Inherited fd whose EOF means "the supervisor died"; set by the supervisor only. */
export declare const HOST_WATCH_FD_ENV = "SENPI_RPC_HOST_WATCH_FD";
/** Supervisor-owned private directory the host removes on watchdog shutdown. */
export declare const HOST_SCRATCH_DIR_ENV = "SENPI_RPC_HOST_SCRATCH_DIR";
/** Public socket path the supervisor bound; the host removes it ownership-checked. */
export declare const HOST_PUBLIC_SOCKET_ENV = "SENPI_RPC_HOST_PUBLIC_SOCKET";
/** Fallback binding when no inherited fd is available: poll this pid. */
export declare const HOST_WATCH_PPID_ENV = "SENPI_RPC_HOST_WATCH_PPID";
export declare const HOST_WATCH_PSTART_ENV = "SENPI_RPC_HOST_WATCH_PSTART";
/** Linux: the supervisor's `/proc` start ticks, compared on the boot clock (senpi#3816 review). */
export declare const HOST_WATCH_PSTART_TICKS_ENV = "SENPI_RPC_HOST_WATCH_PSTART_TICKS";
export { HOST_WATCH_LIFETIME_FIFO_ENV } from "./host-lifetime-binding.ts";
export { HOST_WATCH_BACKSTOP_INTERVAL_MS, HOST_WATCH_IDENTITY_INTERVAL_MS, HOST_WATCH_IDENTITY_ONLY_INTERVAL_MS, HOST_WATCH_PPID_BACKUP_INTERVAL_MS, HOST_WATCH_PPID_INTERVAL_MS, HOST_WATCH_SPAWNING_IDENTITY_INTERVAL_MS, } from "./host-supervisor-poll.ts";
export declare const HOST_CLEANUP_PATHS_ENV = "SENPI_RPC_HOST_CLEANUP_PATHS";
export interface HostWatchdogConfig {
readonly fd?: number;
readonly ppid?: number;
readonly processStartTime?: string;
readonly processStartTicks?: string;
readonly lifetimeFifo?: string;
readonly lifetimeFd?: number;
readonly scratchDir?: string;
readonly cleanupPaths?: readonly string[];
readonly publicSocket?: string;
/** Where the WATCHDOG record of this generation goes when the supervisor vanishes (senpi#2566). */
readonly daemonDir?: string;
readonly instanceId?: string;
/**
* Runs when the watchdog fires, BEFORE `scratchDir` and `cleanupPaths` are removed. The
* host uses it to read state that lives inside the supervisor's private directory and
* that its shutdown still needs - the public-socket ownership token above all. A
* supervisor killed while the host is still starting up leaves that token unread, and
* removing the directory first would turn the public socket into an unprovable orphan.
*/
readonly beforeCleanup?: () => Promise<void>;
}
/**
* Reads the watchdog configuration from the environment. Returns `undefined`
* when neither binding is requested, which is the case for every host launch
* that does not come from the lifecycle supervisor.
*/
export declare function readHostWatchdogConfig(env?: Readonly<Record<string, string | undefined>>): HostWatchdogConfig | undefined;
/** Same configuration, resolved through the brand-aware env prefixes. */
export declare function readHostWatchdogConfigFromBrandEnv(env?: NodeJS.ProcessEnv): HostWatchdogConfig | undefined;
/**
* Reads the supervisor binding once and removes it from `env` (senpi#3815 review L4), so no tool, shell or nested host
* this host starts inherits a binding to a supervisor that is not its own. The generation identity (instance id,
* daemon dir) stays: sessions use it to name the host they run in.
*/
export declare function consumeHostWatchdogEnv(env?: NodeJS.ProcessEnv): HostWatchdogConfig | undefined;
export declare function scrubHostWatchdogEnv(env?: NodeJS.ProcessEnv): void;
/**
* Arms the configured watchdog. `onSupervisorGone` receives the reason and is
* expected to perform the host's normal clean shutdown; the scratch directory
* (the supervisor's private socket directory, which no longer has an owner) is
* removed first so nothing is left behind even if shutdown then hangs.
*
* Takes ownership of `config.fd`: disarming (or firing) closes it, so callers
* must not close it themselves. Returns a disarm function; a no-op when no
* binding is configured.
*/
export declare function armHostWatchdog(config: HostWatchdogConfig | undefined, onSupervisorGone: (reason: string, cleanup?: Promise<void>) => void): () => void;
/**
* Removes the cleanup paths one at a time, in list order, on every platform: the supervisor puts
* the registration pointer last (host-cleanup-paths.ts), and it must not vanish before the state
* it describes (senpi#2241).
*/
export declare function cleanupWatchdogPaths(config: HostWatchdogConfig): Promise<void>;
//# sourceMappingURL=host-watchdog.d.ts.map