UNPKG

@code-yeongyu/senpi

Version:

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

83 lines • 6.08 kB
import type { DelegationDescriptor } from "./delegation-record.ts"; import { type DelegationResolution } from "./delegation-resolve.ts"; import { type RpcRemoteOrigin } from "./remote-origin.ts"; /** * Connection roles (senpi#3811): the capabilities that say who a connection speaks for, which is what * authority checks read. A role belongs to one connection, never to a session: a shared host serves every * connection attached to a session through one binding. Only the client's own `set_client_info` declares a * role; launch defaults (`SENPI_RPC_CLIENT_CAPABILITIES`, a host's connection options) never do, so a client * can still declare after it attached. Once a connection declared, a different declaration is refused. * * On a host-mode delegated connection (omo-relay-daemon#307) a claim belongs to one incarnation of the socket and * counts only while that incarnation's authority word still holds the role and is not retired. A claim for an * incarnation is created only by a declaration that carries that incarnation while it is the record's current, open * one: `declare` is the single place that check runs, and `isStale` is its side-effect-free preflight. */ export declare const CONNECTION_ROLE_CAPABILITIES: readonly string[]; /** The one connection of a single-session `--mode rpc` process. */ export declare const SOLE_CONNECTION = "sole-connection"; /** * The key a connection's roles are kept under. A stdio host (and a worker isolate serving it) reads lines * with no connection id; its one client is the sole connection, so the role is still declared once and fixed. */ export declare function roleConnection(connectionId: string | undefined): string; export declare const CONNECTION_ROLE_FIXED = "connection_role_fixed: interactive_user and task_parent cannot change after they are declared"; export declare const DELEGATION_INCARNATION_STALE = "delegation_incarnation_stale: this declaration was made before detach_connection; declare again"; export type RoleDeclaration = "declared" | "fixed" | "stale"; /** What the roles need of a delegated connection: its principal, mode and current incarnation. */ export interface DelegatedConnectionView { readonly descriptor: DelegationDescriptor; readonly closed: boolean; } export declare class ConnectionRoles { private readonly claims; private readonly origins; /** A worker isolate's first-seen delegation per connection (`retain`), kept for the worker's life. */ private readonly retained; /** A worker isolate's connections whose bind or command carried a delegation (a legacy one is never retained). */ private readonly carried; private source; /** The host reads each connection's live record from its writer's delegations. */ useDelegations(source: (connectionId: string) => DelegatedConnectionView | undefined): void; private viewOf; /** * Whether a declaration carrying `incarnation` must be refused as stale, with no side effect. On the host the * record's current, open incarnation is the only one that may claim; in a worker an incarnation older than the one it * retained is stale (the host's answer stays authoritative). Without a host-mode record only an untagged one proceeds. */ isStale(connectionId: string, incarnation: number | undefined): boolean; /** Records the roles a `set_client_info` carries for one incarnation, or why it may not. */ declare(connectionId: string, capabilities: readonly string[], incarnation?: number): RoleDeclaration; private claimsOf; /** The roles declared for `incarnation` (untagged when omitted), or undefined while none were (no id = stdio). */ rolesOf(connectionId: string | undefined, incarnation?: number): readonly string[] | undefined; /** Takes a declaration made on the host, unless this incarnation already declared; drops older incarnations' claims. */ adopt(connectionId: string, roles: readonly string[], incarnation?: number): void; /** Worker isolate: resolves a bind/command's carried delegation against the one retained for the connection. */ retain(connectionId: string, wire: DelegationDescriptor): DelegationResolution; /** Whether `origin` may be declared: none yet or the same again (senpi#5475); a delegated one is its principal. */ acceptsOrigin(connectionId: string, origin: RpcRemoteOrigin): boolean; /** Records the remote device a local connection speaks for; a delegated connection's origin is never declared. */ declareOrigin(connectionId: string, origin: RpcRemoteOrigin): void; /** Whether the forwarder stated this delegated connection's device is the host's own account (senpi#6342). */ sameAccount(connectionId: string | undefined): boolean; /** The remote device this connection speaks for: a delegated connection's principal, else its declared origin. */ originOf(connectionId: string | undefined): RpcRemoteOrigin | undefined; /** Whether the connection is delegated (a remote device's): on the host, retained by a worker, or carried to one. */ isDelegated(connectionId: string | undefined): boolean; /** * Whether the forwarder itself granted `role` to this connection (senpi#6305): only a host-mode delegation's live, * unretired authority word counts. No client claim, legacy-mode delegation or local connection can satisfy it. */ grantedByForwarder(connectionId: string | undefined, role: string): boolean; has(connectionId: string | undefined, role: string): boolean; /** A logical detach: drops claims of earlier incarnations of a delegated socket, and everything of a local one. */ release(connectionId: string): void; /** The socket is gone: nothing of it is kept. */ forget(connectionId: string): void; /** Worker isolate: a bind or command for `connectionId` carried a delegation, in either mode. */ noteCarriedDelegation(connectionId: string): void; /** Forgets every connection, for a worker isolate whose session ends. */ clear(): void; } //# sourceMappingURL=connection-roles.d.ts.map