@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
37 lines • 2.54 kB
TypeScript
/**
* The authority word of a host-mode delegated connection (omo-relay-daemon#307).
*
* One `Int32Array(SharedArrayBuffer(8))` per incarnation of a delegated socket: index 0 packs
* `epoch << 4 | retired << 3 | mask` (mask bit 0 = interactive_user, bit 1 = task_parent, bit 2 = peer_agent), index 1 is
* the incarnation,
* stamped once before the buffer is shared. The host thread is the only writer, and every write is monotone within a
* word: mask bits are only cleared, retired is only set, the epoch only grows and changes only on a real transition.
* Host and worker threads read the same memory with one `Atomics.load` per command, so the load at a command's first
* role check is its admission and the host's store is the revocation point.
*
* This module has no package imports on purpose: worker-thread tests load it directly.
*/
/** The largest incarnation slot [1] holds unchanged. */
export declare const INCARNATION_MAX = 2147483647;
export interface AuthorityState {
readonly epoch: number;
readonly retired: boolean;
readonly mask: number;
readonly roles: readonly string[];
}
export declare function maskOfRoles(roles: Iterable<string>): number;
export declare function rolesOfMask(mask: number): string[];
export declare function decodeWord(word: number): AuthorityState;
/** A new incarnation's word: epoch 1, not retired, `mask`, with `incarnation` stamped before anything shares it. */
export declare function createAuthority(incarnation: number, mask: number): SharedArrayBuffer;
export declare function readAuthority(buffer: SharedArrayBuffer): AuthorityState;
export declare function incarnationOf(buffer: SharedArrayBuffer): number;
/** Host thread only: mask ← mask ∩ roles. The epoch moves only when a bit cleared; true when it did. */
export declare function storeNarrowed(buffer: SharedArrayBuffer, roles: Iterable<string>): boolean;
/** Host thread only: sets retired and moves the epoch; a word already retired is left as it is (false). */
export declare function storeRetired(buffer: SharedArrayBuffer): boolean;
/** The successor of incarnation `k`, checked BEFORE any stamp; undefined once the counter is exhausted (never wraps). */
export declare function nextIncarnation(k: number, max?: number): number | undefined;
/** Whether a word admits `role` for a claim: claimed, not retired, and still in the mask. */
export declare function effectiveRoles(claim: readonly string[] | undefined, state: AuthorityState): string[];
//# sourceMappingURL=connection-authority.d.ts.map