@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
339 lines • 12.3 kB
TypeScript
import type { RpcRemoteOrigin } from "./remote-origin.ts";
import type { DelegationDescriptor } from "./delegation-record.ts";
import type { BrowserEngine } from "../../core/browser-engine.ts";
import type { McpFormInput, McpFormOutcome } from "../../core/mcp-form-types.ts";
import type { RecoveryCarrier } from "../../core/session-recovery-identity.ts";
import type { ThreadSettledBy } from "../../core/session-settled.ts";
import type { TranscriptTransition } from "../../core/session-transcript-journal.ts";
import type { PromptSurface } from "../../core/dynamic-prompt/types.ts";
import type { MirroredLimits } from "../../core/subscription-limits/limit-store.ts";
import type { CliRuntimeConfiguration } from "../../main.ts";
import type { CanonicalRecord } from "./compact-lane-transitions.ts";
import type { ExtensionOwnerIdentity, ExtensionOwnerWire } from "./extension-owner.ts";
import type { RpcSessionState } from "./rpc-types.ts";
import type { SealedAnswer, SealedAnswerReply, SecretInputOutcome } from "./secret-input-requests.ts";
import type { SessionBootstrap } from "./session-acceptance-lane.ts";
import type { RpcSessionLaunchProfile } from "./session-registry.ts";
export declare const SESSION_WORKER_LIMITS: {
readonly workers: 20;
readonly requests: 64;
readonly controlRequests: 4;
readonly controlBytes: number;
readonly requestBytes: number;
readonly outputBytes: number;
readonly reservations: 64;
readonly openMs: 30000;
readonly controlMs: 5000;
readonly secretFrameBytes: number;
readonly secretInputs: 64;
readonly secretIds: number;
};
/** A transition over the frame limit leaves its epoch's transcript unavailable; S12 transfers it in fragments. */
export declare function withinFrameLimit(transitions: readonly TranscriptTransition[]): TranscriptTransition[];
/**
* Wire values the host writes into a worker's wait signal; `conflict` is the generic denial. `stale`
* (omo-relay-daemon#307) answers a `capabilities` declaration captured under an incarnation that is no longer the
* connection's current one: the worker refuses that one command and lives on.
*/
export declare const WORKER_CREDIT_CODES: {
readonly granted: 1;
readonly conflict: 2;
readonly limit: 3;
readonly stale: 4;
};
/** Host decision on a worker's session-write path request. */
export type SessionWriteGrant = Exclude<WorkerCreditAnswer, "stale">;
/** Every answer the host writes into a worker's wait signal. */
export type WorkerCreditAnswer = keyof typeof WORKER_CREDIT_CODES;
export interface WorkerSnapshot {
state: RpcSessionState;
/** Canonicalized by the owning worker, never by the transport thread. */
sessionPath?: string;
/** Every canonical path this worker's live session writers still own. */
liveSessionPaths: readonly string[];
busy: boolean;
/** Turn/request activity, excluding durable wake-source holds. */
handoffBusy?: boolean;
streaming: boolean;
/** The session file's archived flag, read in the isolate that owns the file. */
archived: boolean;
/** The session file's Done flag and how it was reached, read like `archived`. */
settled: boolean;
settledBy?: ThreadSettledBy;
}
import type { AdmissionReplyScope } from "./compact-admission-reply.ts";
export type HostToSessionWorker = {
type: "prepare";
request: number;
configuration: CliRuntimeConfiguration;
profile: RpcSessionLaunchProfile;
/** The host's subscription limit records when the isolate starts (senpi#3695). */
subscriptionLimits: readonly MirroredLimits[];
}
/**
* `acceptance`: the host owns an acceptance lane, so the isolate sends a bootstrap and ordered output frames;
* `permits`: then the incarnation's payload permit block, already holding its fixed initial credit (S12b).
*/
| {
type: "commit";
request: number;
acceptance?: true;
recoveryEpoch?: string;
permits?: SharedArrayBuffer;
} | {
type: "bind";
request: number;
sessionId: string;
capabilities: readonly string[];
connection?: string;
/** Roles the connection explicitly declared on the host (senpi#3811); the isolate adopts them. */
roles?: readonly string[];
/** The delegation the attaching line captured (omo-relay-daemon#307). */
delegation?: DelegationDescriptor;
mcpFormsEnforced?: boolean;
} | {
type: "mcp_form_bound";
id: string;
epoch: string;
version?: string;
} | {
type: "mcp_form_availability";
epoch: string;
version?: string;
id?: string;
} | {
type: "mcp_form_settlement";
id: string;
epoch: string;
settlementId: string;
outcome: McpFormOutcome;
} | {
type: "command";
admissionReply?: AdmissionReplyScope;
request: number;
command: object;
connection?: string;
roles?: readonly string[];
/** The remote device the connection declared on the host (senpi#5475); the isolate adopts it. */
origin?: RpcRemoteOrigin;
/** The gate the host captured at ingress, before its first await (#4728). */
owner?: ExtensionOwnerWire;
/** The delegation the command's line captured at its start, and its forwarder's `relayExec` (#307). */
delegation?: DelegationDescriptor;
exec?: number;
}
/** Gates the host already retired atomically; the isolate only wakes their waiters. */
| {
type: "owners_retired";
owners: readonly ExtensionOwnerIdentity[];
} | {
type: "prompt_surface";
request: number;
surface: PromptSurface;
} | {
type: "browser_engine";
request: number;
engine: BrowserEngine;
} | {
type: "permission_preset";
request: number;
preset: string;
} | {
type: "cancel_ui";
} | {
type: "cancel_grant";
id: string;
} | {
type: "cancel_secret";
id: string;
}
/** A sealed answer the host authenticated (D11 secret phase 5.5); the isolate runs 7.1 steps 3 and 6 on it. */
| {
type: "secret_sealed_answer";
request: number;
answer: SealedAnswer;
}
/** A change to the host's subscription limit records after `prepare`, mirrored into the isolate (senpi#3695). */
| {
type: "subscription_limits";
accounts: readonly MirroredLimits[];
} | {
type: "close";
};
export type SessionWorkerToHost = {
type: "secret_select";
id: string;
connection?: string;
decision: SharedArrayBuffer;
signal: SharedArrayBuffer;
} | {
type: "secret_frame";
id: string;
record: object;
signal: SharedArrayBuffer;
} | {
type: "secret_settled";
id: string;
signal: SharedArrayBuffer;
/** The outcome and winning grant, so the host settles the request's sealed holders (5.5). */
outcome?: SecretInputOutcome;
winnerGrant?: string;
} | {
type: "secret_forget";
id: string;
signal: SharedArrayBuffer;
} | {
type: "secret_sealed_result";
request: number;
reply: SealedAnswerReply;
} | {
type: "secret_handshake";
capabilities: readonly string[];
signal: SharedArrayBuffer;
} | {
type: "mcp_form_bind";
id: string;
durableId: string;
} | {
type: "mcp_form_ready";
id: string;
epoch: string;
} | {
type: "mcp_form_release";
epoch: string;
} | {
type: "mcp_form_cancel";
id: string;
epoch: string;
lifetime: "operation" | "presentation";
} | {
type: "mcp_form_create";
id: string;
epoch: string;
version: string;
operationFence: SharedArrayBuffer;
input: Omit<McpFormInput, "operationSignal" | "operationCurrent" | "presentationSignal">;
} | {
type: "prepared";
request: number;
sessionPath: string;
} | {
type: "ready";
request: number;
snapshot: WorkerSnapshot;
bootstrap?: SessionBootstrap;
} | {
type: "result";
request: number;
error?: string;
} | {
type: "reserve";
path: string;
signal: SharedArrayBuffer;
} | {
type: "snapshot";
snapshot: WorkerSnapshot;
signal: SharedArrayBuffer;
settled?: boolean;
} | {
type: "control_done";
control: "cancel_ui";
} | {
type: "output";
admissionReply?: AdmissionReplyScope;
/** One per output frame of this worker incarnation, from 0; continuity only, never the accepted sequence. */
ordinal?: number;
record: object;
/** A record nested past the protocol depth limit travels as its JSON text (`record` is then `{}`): the host parses
* text without recursion, where its structured-clone reader drops a deep frame (Node ~4,000 levels; RULING-68). */
recordText?: string;
recovery?: RecoveryCarrier;
/** A bridge-started call's `tool_execution_start`: the key its producer minted with it (RULING-127 (b)). */
callKey?: string;
/** Transcript transitions the isolate's manager committed before this record, accepted just before it. */
transitions?: readonly TranscriptTransition[];
/** The next incarnation's baseline, on the `session_replaced` record that starts it. */
bootstrap?: SessionBootstrap;
/** The record's canonical projection, folded in the same unit; `firstOrdinal` is the producer's binding. */
canonical?: CanonicalRecord;
/** The isolate refused this event's canonical record at the protocol depth limit and already sent that refusal. */
canonicalRefused?: true;
firstOrdinal?: number;
connection?: string;
/** The command's captured incarnation; targeted output never downgrades to the routing string. */
owner?: ExtensionOwnerIdentity;
signal: SharedArrayBuffer;
activity: Pick<WorkerSnapshot, "busy" | "handoffBusy" | "streaming">;
snapshot?: WorkerSnapshot;
}
/** A block control: a canonical-only unit taking the next frame ordinal, never delivered to a legacy destination. */
| {
type: "canonical";
ordinal: number;
firstOrdinal: number;
recovery: RecoveryCarrier;
record: CanonicalRecord;
signal: SharedArrayBuffer;
}
/**
* The isolate lost a canonical record before framing it; the host lane's compact state for the epoch ends, unless
* `limit` says the record was refused at that protocol depth limit (RULING-59 C), which the host counts instead.
*/
| {
type: "canonical_unavailable";
ordinal: number;
reason: string;
limit?: number | undefined;
signal: SharedArrayBuffer;
} | {
type: "capabilities";
connection?: string;
capabilities: readonly string[];
/** The incarnation the declaring command captured, never looked up when sent or received (#307). */
incarnation?: number;
signal: SharedArrayBuffer;
} | {
type: "loaded_surfaces";
previous?: string;
digest: string;
signal: SharedArrayBuffer;
}
/**
* One piece of a payload message too large for one frame (S12b): at most D stored bytes of its JSON (signals left out)
* at `offset` of `length`, both in stored bytes. Ordered pieces take consecutive physical ordinals; the final piece is
* the commit frame and carries the message's own ordinal, binding and signals (RULING-64).
*/
| {
type: "fragment";
/** The type of the message the fragments carry, so a refused transfer names its event (RULING-80 (3a)). */
of: string;
length: number;
offset: number;
text: string;
ordinal?: number;
firstOrdinal?: number;
signal?: SharedArrayBuffer;
epochSignal?: SharedArrayBuffer;
} | {
type: "request_close";
}
/** A record a turn in the isolate reported, mirrored into the host's store (senpi#3695). */
| {
type: "subscription_limits";
limits: MirroredLimits;
} | {
type: "failure";
error: string;
};
/**
* A worker's refusal crosses the thread boundary as text. An `open_failed: <reason>` refusal is rebuilt as the typed
* registry error, so a worker host answers `open_session` exactly as the in-process registry does (senpi#2898).
*/
export declare function typedWorkerRefusal(cause: unknown): never;
/**
* Whether an open step failed only because its worker died: the worker's request channel rejects what is pending
* with a plain `session_closing` / `session_worker_exited`, and the claims and grants it held report a typed
* `session_closing` (senpi#4037).
*/
export declare function closedByWorkerDeath(cause: unknown): boolean;
//# sourceMappingURL=session-worker-protocol.d.ts.map