UNPKG

@code-yeongyu/senpi

Version:

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

62 lines • 3.46 kB
import { RpcSessionRegistryError } from "./session-registry-types.js"; export const SESSION_WORKER_LIMITS = { workers: 20, requests: 64, controlRequests: 4, controlBytes: 1024 * 1024, requestBytes: 16 * 1024 * 1024, outputBytes: 16 * 1024 * 1024, reservations: 64, openMs: 30_000, controlMs: 5_000, // Secret frames ride the control exchange, outside `outputBytes`, so the host bounds them itself (senpi#5192). // One `secret_frame` record: a secret prompt's title and placeholder are a few hundred bytes, so 64 KiB is // generous for any real prompt yet keeps the side channel far below the 16 MiB payload frame. secretFrameBytes: 64 * 1024, // Unsettled secret inputs per worker: one per waiting tool call or command, so the same 64 as `requests`. secretInputs: 64, // Every secret id the host tracks per worker: the 1024 settled receipts `SecretInputRequests` keeps for // answer replay, plus `secretInputs` open ones. secretIds: 1024 + 64, }; /** The bytes a transition carries: its entry, plus the owned message copies of the flow it journals (senpi#4460). */ function transitionBytes(transition) { const entry = transition.kind === "append" ? Buffer.byteLength(transition.entry ?? "") : 0; const flow = transition.kind === "append" || transition.kind === "leaf" ? transition.flow : undefined; return entry + (flow ? Buffer.byteLength(JSON.stringify(flow)) : 0); } /** A transition over the frame limit leaves its epoch's transcript unavailable; S12 transfers it in fragments. */ export function withinFrameLimit(transitions) { // Reserve fixed metadata space; content is charged in the same raw UTF-8 bytes as the accepted tail. const entryOverhead = 1024; return transitions.map((transition) => transitionBytes(transition) + entryOverhead > SESSION_WORKER_LIMITS.outputBytes ? { kind: "unavailable", reason: "transition_over_worker_frame_limit" } : transition); } /** * 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 const WORKER_CREDIT_CODES = { granted: 1, conflict: 2, limit: 3, stale: 4 }; /** * 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 function typedWorkerRefusal(cause) { const message = cause instanceof Error ? cause.message : String(cause); if (message.startsWith("open_failed: ")) throw new RpcSessionRegistryError("open_failed", message.slice(13)); throw cause; } /** * 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 function closedByWorkerDeath(cause) { if (cause instanceof RpcSessionRegistryError) return cause.code === "session_closing"; return cause instanceof Error && (cause.message === "session_closing" || cause.message === "session_worker_exited"); } //# sourceMappingURL=session-worker-protocol.js.map