UNPKG

@code-yeongyu/senpi

Version:

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

53 lines • 1.64 kB
/** Selected mirror admission only: 128 records / 1 MiB before activation; no uncharged lines[]. */ export const MIRROR_PENDING_LIMITS = { entries: 128, bytes: 1024 * 1024 }; export class MirrorPending { constructor() { this.records = []; this.bytes = 0; this.active = false; } status() { return { entries: this.records.length, bytes: this.bytes }; } enqueue(line, deliver, drop) { if (this.reason) { drop?.(); return; } if (this.active) { deliver(); return; } const bytes = Buffer.byteLength(line); if (this.records.length >= MIRROR_PENDING_LIMITS.entries || this.bytes + bytes > MIRROR_PENDING_LIMITS.bytes) { this.reason = "admission_limit"; this.clear(); drop?.(); return; } this.bytes += bytes; this.records.push({ deliver, drop }); } /** Synchronous ownership transfer into the already installed actor barrier, never a second producer. */ activate() { if (this.reason || this.active) return; this.active = true; const records = this.records; this.records = []; this.bytes = 0; for (const record of records) record.deliver(); } retire(reason = "attempt_cancelled") { this.reason ??= reason; this.clear(); } clear() { for (const record of this.records) record.drop?.(); this.records = []; this.bytes = 0; } } //# sourceMappingURL=compact-mirror-pending.js.map