@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
60 lines • 3.69 kB
TypeScript
import { type SocketFileIdentity } from "./socket-ownership.ts";
export interface EndpointOwnerToken {
readonly v: 1;
readonly endpoint: string;
readonly instanceId: string;
readonly generation: number;
readonly pid: number;
/** Fresh per claim: two claims by one generation are still two different tokens. */
readonly nonce: string;
}
export interface FenceHooks {
/** Test seam: the fence was held by another writer when this one asked for it. */
readonly onFenceBusy?: () => void;
}
export declare function endpointOwnerToken(endpoint: string, instanceId: string, generation: number): EndpointOwnerToken;
/** The current owner token; `undefined` when none was claimed or it cannot be read as one. */
export declare function readEndpointOwner(socket: string): Promise<EndpointOwnerToken | undefined>;
/**
* An initial start: binds the public name (`bind`, with its stale-entry preparation) and claims it. The fence is
* taken only when an owner token already exists. A first start has no predecessor whose late rename or remove it
* could race, and the ensure lock its launcher holds already serialises concurrent first starts of this endpoint, so
* skipping the fence there keeps the SQLite driver out of every supervisor's boot (`rpc-supervisor-footprint`).
*/
export declare function claimEndpoint(socket: string, token: EndpointOwnerToken, bind?: () => Promise<void>): Promise<void>;
/**
* A successor takes the public name over. Inside the fence: the launcher's grant must still stand, the owner token
* must still name the expected predecessor (when the predecessor participates in the fence at all), the entry must
* still be the one the handoff was decided against; then the rename and the new token, awaited.
*/
export declare function adoptEndpoint(options: {
readonly bindSocket: string;
readonly publicSocket: string;
readonly expected: SocketFileIdentity | undefined;
/** The predecessor's instanceId; `undefined` for a predecessor that does not advertise the fence (senpi#4602 Q1). */
readonly expectedOwner: string | undefined;
readonly token: EndpointOwnerToken;
/** Whether the launcher's publication grant still stands; absent for an uncoordinated launch. */
readonly granted?: () => Promise<boolean>;
readonly hooks?: FenceHooks;
}): Promise<void>;
/**
* A generation removes its public entry: only while the owner token does not name another generation, and only
* the entry `identity` describes. Its own token goes with it.
*/
export declare function unlinkOwnedEndpoint(socket: string, identity: SocketFileIdentity | undefined, instanceId: string, log: (message: string) => void, hooks?: {
readonly afterValidate?: () => Promise<void>;
}): Promise<void>;
/**
* Closes a listener bound to `socket` with the entry shielded from libuv's close-time unlink of the NAME. The
* shield moves whatever entry is there aside and puts that same entry back: inside the fence, so no adoption can
* land in between and be overwritten by the restore.
*/
export declare function closeShieldedEndpoint(socket: string, close: () => Promise<void>): Promise<void>;
/**
* A successor's launcher, after its attempt failed: revoke the publication grant, then read who owns the public
* name. An adoption that started inside its window but committed after the deadline is a COMPLETED handoff, never
* rolled back; one that did not commit before the revocation can no longer commit at all.
*/
export declare function settleCandidateAdoption(socket: string, candidate: string, revoke: () => Promise<void>): Promise<"completed" | "not_adopted">;
//# sourceMappingURL=host-endpoint-owner.d.ts.map