UNPKG

@code-yeongyu/senpi

Version:

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

85 lines • 4.58 kB
import { LegacyRecordRefusals } from "./legacy-record-depth.js"; import { SecretInputPresentations } from "./secret-input-presentations.js"; import { RpcSecurityPresentations } from "./security-presentations.js"; import { SessionEventFanout } from "./session-event-fanout.js"; import { SessionConnectionContext } from "./session-connection-context.js"; import { SessionOpenTurns } from "./session-open-turns.js"; import { SessionRecordAccounting } from "./session-record-accounting.js"; import { SessionStatusStream } from "./session-status-stream.js"; import { SessionStructuredLanes } from "./session-structured-lanes.js"; import { SurfaceDigestDedupe } from "./session-surface-dedupe.js"; /** * Every field of the session event writer, in its original declaration order, and its constructor. * The writer's behaviour is split across the layers that extend this one (session-event-writer.ts). */ export class SessionEventWriterState { get pendingCloseRecordCount() { return this.reservedCloseRecords; } get pendingCloseByteLength() { return this.reservedCloseBytes; } constructor(writeRaw, waitOrSchedule, scheduleFlush) { this.structuredLanes = new SessionStructuredLanes(); /** Records refused at the engine's JSON depth limit on the legacy wire (RULING-68). */ this.legacyRefusals = new LegacyRecordRefusals(); this.presenterConnections = new Map(); this.presenterBindings = new Map(); this.records = new SessionRecordAccounting(); this.queues = new Map(); this.fanout = new SessionEventFanout(); this.connectionContext = new SessionConnectionContext((id) => this.fanout.get(id)?.owner, (id) => this.delegationDescriptorOf(id)); this.locality = { isRemote: (connection) => this.isRemoteConnection(connection), originOf: (connection) => this.originOf?.(connection), }; this.securityPresentations = new RpcSecurityPresentations(this.fanout, (id, task) => this.withConnection(id, task), () => this.requestFlush(), this.locality); this.workerSecurityBridge = false; this.controlQueue = { latestByKey: new Map(), ready: false }; this.readyQueues = []; this.sealedSessions = new Set(); /** Sessions whose lifecycle records stay on their attached connections (`kind: "worker"`). */ this.workerSessions = new Set(); this.openTurns = new SessionOpenTurns(); /** Host-level `subscribe_sessions` subscriptions; publishes ride each subscriber's own FIFO actor. */ this.status = new SessionStatusStream({ enqueue: (connectionId, line) => { const actor = this.fanout.get(connectionId)?.actor; if (actor === undefined) return false; actor.enqueue(line); this.requestFlush(); return true; }, pendingQuestions: (sessionId) => this.fanout.pendingQuestionCount(sessionId), }); /** F13 surface dedupe: one notice per connection per inventory transition, tracked per session. */ this.surfaceDedupe = new SurfaceDigestDedupe(); /** Per-session image persisters: bytes reach disk before the placeholder that names them is emitted. */ this.mediaPersisters = new Map(); this.flushScheduled = false; this.controlOverflowReported = false; this.closeOverflowReported = false; this.closeOverflowActors = new WeakSet(); this.reservedCloseRecords = 0; this.reservedCloseBytes = 0; this.secretPresentations = new SecretInputPresentations(this.fanout, () => this.currentConnection(), (line) => this.writeRaw(line), () => this.requestFlush(), this.locality); this.fanout.onConnectionClosed = (id) => { this.secretPresentations.detach(id); this.securityPresentations.dropConnection(id); const sender = this.presenterConnections.get(id); if (sender) this.presenterAuthority?.detach(sender); this.presenterConnections.delete(id); }; this.writeRaw = writeRaw; if (waitOrSchedule && scheduleFlush === undefined && waitOrSchedule.length > 0) { this.scheduleFlush = waitOrSchedule; } else { this.waitForBackpressure = waitOrSchedule; this.scheduleFlush = scheduleFlush ?? ((flush) => queueMicrotask(() => void flush())); } } } //# sourceMappingURL=session-event-writer-state.js.map