UNPKG

@code-yeongyu/senpi

Version:

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

61 lines • 3.85 kB
import { type Server } from "node:net"; import type { HostAdmission } from "./host-admission.ts"; import type { ClientOccupancy } from "./host-client-occupancy.ts"; import type { RpcPublicEndpoint } from "./rpc-public-key.ts"; import { type ListenerState, type SocketFileIdentity } from "./socket-ownership.ts"; export interface PublicProxyOptions { readonly internalSocket: string; readonly internalSecret?: Buffer; readonly internalKey?: Buffer; readonly publicSecret?: Buffer; readonly publicEndpoint?: RpcPublicEndpoint; readonly clients: ClientOccupancy; /** Shared authority for stopping, protocol replies and new-session admission. */ readonly admission: HostAdmission; /** A client went away: occupancy changed. */ readonly onDetach: () => void; /** A dropped unclassified admission breaks quiescence; a proven observing read does not. */ readonly onAdmit?: () => void; } export declare function createPublicProxy(options: PublicProxyOptions): Server; /** * Reuses an existing valid secret - including one ensureHost() just wrote - and * creates one (with its parent directories, mode 0600) when it is missing or * unusable. Reuse is required, not just an optimization: on win32 the pipe name * is derived from the socket path AND the secret, so rotating it here would * point this supervisor at a different endpoint than its caller published. * A failure names the bootstrap step and the path it could not provision. */ export declare function ensurePublicSocketSecret(publicSocket: string): Promise<Buffer>; /** * One sealed readiness probe: the internal handshake and the ready reply together, on one monotonic timer (senpi#3816 * review). A child that accepts the hop and stays silent that long is not a working host, so readiness fails at once * instead of hanging the supervisor; a host that is not listening yet is retried until the overall deadline. */ export declare const INTERNAL_READINESS_PROBE_MS = 10000; export declare function waitForListener(socketPath: string, timeoutMs: number, secret?: Uint8Array, internalKey?: Buffer, /** A coordinated start retries a silent probe on a fresh connection; its launcher decides expiry (senpi#4602). */ options?: { readonly retrySilent?: boolean; }): Promise<void>; /** Test-only seams for `prepareSocketPath`'s stale-entry check. */ export interface PrepareSocketPathHooks { /** Runs after the entry was probed dead and before it is unlinked. */ readonly afterStaleProbe?: () => Promise<void>; /** Replaces the listener probe, so a test can pin each verdict. */ readonly listenerState?: (socketPath: string) => Promise<ListenerState>; } /** * Frees `socketPath` for this process's bind, removing only a dead socket entry and refusing everything else * (#5314). No portable fd-based check exists for a socket entry: `open()` fails on one (ENXIO on Linux, * EOPNOTSUPP on macOS), `O_PATH` is Linux-only, and there is no unlink-by-fd. So every read is `lstat`, which * never follows a link, and `unlink(2)` removes the name, never a link's target. The entry is re-stamped before * the second reachability probe (which must not be steered through a swapped-in link) and again as the last step * before the unlink; reachability is re-checked after the decision because a socket bound earlier can start * listening without changing identity. */ export declare function prepareSocketPath(socketPath: string, hooks?: PrepareSocketPathHooks): Promise<void>; /** The supervisor's public bind: the same never-through-a-link publish as the socket host's (#5319). */ export declare function listen(server: Server, socketPath: string, secret?: Uint8Array): Promise<SocketFileIdentity | undefined>; export declare function closeServer(server: Server): Promise<void>; //# sourceMappingURL=host-lifecycle-proxy.d.ts.map