UNPKG

@code-yeongyu/senpi

Version:

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

70 lines • 2.59 kB
import { randomUUID } from "node:crypto"; /** Commands whose handlers may run extension effects receive a captured owner; control commands never do. */ export function carriesExtensionOwner(command) { const type = "type" in command ? String(command.type) : ""; return type === "extension_request" || type.startsWith("eval_cells."); } /** One attachment's shared effect gate plus isolate-local cancellation notification. */ export class ExtensionOwner { constructor(wire) { this.cancellation = new AbortController(); this.wire = wire; this.state = new Int32Array(wire.retirement); this.context = Object.freeze({ ownerId: wire.ownerId, disconnectSignal: this.cancellation.signal, admit: (dispatch) => { // The atomic observation is the admission point, not abort-message delivery. if (Atomics.load(this.state, 0) !== 0) throw new DOMException("RPC owner retired", "AbortError"); return dispatch(); }, }); } get retired() { return Atomics.load(this.state, 0) !== 0; } retire() { Atomics.store(this.state, 0, 1); this.cancellation.abort(); } } /** Minted once per actual transport registration, independently of its reusable routing ID. */ export class ExtensionTransportOwner { constructor() { this.ownerId = randomUUID(); this.bindings = new Map(); this.closed = false; } get retired() { return this.closed; } capture(bindingGeneration) { if (this.closed) throw new DOMException("RPC transport retired", "AbortError"); const existing = this.bindings.get(bindingGeneration); if (existing) return existing; const owner = new ExtensionOwner({ ownerId: this.ownerId, bindingGeneration, retirement: new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT), }); this.bindings.set(bindingGeneration, owner); return owner; } /** The gate already issued for a generation, without minting one. */ peek(bindingGeneration) { return this.closed ? undefined : this.bindings.get(bindingGeneration); } retireBinding(bindingGeneration) { this.bindings.get(bindingGeneration)?.retire(); } retire() { this.closed = true; for (const owner of this.bindings.values()) owner.retire(); this.bindings.clear(); } } //# sourceMappingURL=extension-owner.js.map