UNPKG

@code-yeongyu/senpi

Version:

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

59 lines • 1.81 kB
/** * The public admission authority lives on the supervisor's loop. A ready probe is * informational: every open must still pass this gate, including on held sockets. */ export class HostAdmission { constructor(info) { this.stopped = false; this.listeners = new Set(); this.replies = Promise.resolve(); this.info = info; } get stopping() { return this.stopped; } protocol() { return { ...this.info, lifecycle: this.stopped ? "stopping" : "ready" }; } observe(info) { this.info = info; } /** Synchronous and monotonic; runs before any child signal or awaited teardown. */ stop() { if (this.stopped) return; this.stopped = true; this.replies = Promise.all([...this.listeners].map((listener) => listener())).then(() => { }); } /** Flush within the caller's existing five-second cleanup allowance; a stalled reader cannot pin exit. */ async flush() { let timer; try { await Promise.race([ this.replies, new Promise((resolve) => { timer = setTimeout(resolve, 2_000); }), ]); } finally { clearTimeout(timer); } } onStop(listener) { this.listeners.add(listener); return () => this.listeners.delete(listener); } } export function hostStoppingResponse(id, command, admission) { return { ...(typeof id === "string" ? { id } : {}), type: "response", command, success: false, error: "host_stopping", errorCode: "host_stopping", errorData: { instanceId: admission.protocol().instanceId }, }; } //# sourceMappingURL=host-admission.js.map