@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
78 lines • 4.5 kB
TypeScript
export declare const ENDPOINT_RESERVATION_SCHEMA = 2;
export type ReservationRole = "supervisor" | "host";
export type ReservationState = "pending" | "cancelling" | "serving";
export type RoleStatus = "offered" | "claimed" | "granted" | "released" | "revoked";
export type ReservationRejection = "store_insecure" | "store_busy" | "schema_unsupported" | "generation_unknown" | "generation_cancelled" | "generation_not_pending" | "endpoint_mismatch" | "role_not_offered" | "role_already_offered" | "role_not_expected" | "role_already_claimed" | "role_not_claimed" | "role_not_granted" | "nonce_mismatch" | "participant_mismatch" | "issuer_mismatch" | "commitment_invalid" | "roles_not_granted";
/** A typed refusal; `reason` is machine-readable and the message never carries a nonce. */
export declare class EndpointReservationError extends Error {
readonly code = "endpoint-reservation-rejected";
readonly reason: ReservationRejection;
constructor(reason: ReservationRejection, detail: string);
}
/** What a wrapper may forward: no nonce, no credential. */
export interface ReservationLocator {
readonly endpoint: string;
readonly generation: string;
readonly role: ReservationRole;
}
export interface ReservationRow {
readonly endpoint: string;
readonly generation: string;
readonly state: ReservationState;
readonly revision: number;
readonly owner: string;
}
export interface RoleRow {
readonly role: ReservationRole;
readonly status: RoleStatus;
readonly issuer: string;
readonly participant: string | null;
}
interface Statement {
run(...params: unknown[]): unknown;
get(...params: unknown[]): unknown;
all(...params: unknown[]): unknown[];
}
interface Database {
exec(sql: string): void;
prepare(sql: string): Statement;
close(): void;
}
export declare function openEndpointReservationStore(path: string): Promise<EndpointReservationStore>;
export declare class EndpointReservationStore {
#private;
constructor(database: Database);
close(): void;
/**
* Creates a pending generation that expects exactly `expectedRoles` (design 4.2a, the minimum record). The ensure path,
* which admits a supervisor that admits a host, expects both; a self-reserving direct supervisor expects only its host
* child; a standalone public host, reserving itself with no child hop, expects (and self-offers) only "host". Unknown
* or absent roles are refused. The caller holds the endpoint lock.
*/
reserve(endpoint: string, owner: string, expectedRoles: readonly ReservationRole[]): string;
/** Offers `role` with a fresh nonce, issued by `issuer`, before the launcher spawns it. */
offer(generation: string, role: ReservationRole, issuer: string): void;
/** The claimant reads its role's nonce from the store itself, never from a wrapper or an inherited channel. */
readOffer(locator: ReservationLocator): Buffer;
/**
* Consumes the role's nonce once, recording `participant`. A retry by the participant already recorded answers
* `already_claimed_by_caller` without a nonce; that is safe only because callers pass an identity they read from the
* OS for themselves (PID and exact start time), never one taken from another process. Anyone else is refused.
*/
claim(locator: ReservationLocator, nonce: Uint8Array, participant: string): "claimed" | "already_claimed_by_caller";
/** The issuer grants the recorded participant, bound to the SHA-256 commitment of the credential it established. */
grant(generation: string, role: ReservationRole, issuer: string, participant: string, commitment: Uint8Array): void;
/**
* The durable cancellation fence: revokes every outstanding offer and keeps claimed and granted identities. It also
* fences a `serving` generation, which recovery does to an abandoned generation before its retirement census.
*/
cancel(generation: string): void;
/** Commits `serving` only when the generation's expected roles are known and non-empty, each is granted, and every offered row is granted. */
markServing(generation: string): void;
/** A granted participant's own `released` commit: its authority ended. */
release(generation: string, role: ReservationRole, participant: string): void;
reservation(generation: string): ReservationRow;
roleRow(locator: ReservationLocator): RoleRow | undefined;
}
export {};
//# sourceMappingURL=endpoint-reservation-store.d.ts.map