UNPKG

@code-yeongyu/senpi

Version:

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

60 lines • 1.8 kB
export class DeferredTurnClaim { #resolve; constructor() { this.disposition = new Promise((resolve) => { this.#resolve = resolve; }); } resolve(disposition) { const resolve = this.#resolve; if (!resolve) return; this.#resolve = undefined; resolve(disposition); } } export class AgentSettledDelivery { #generation; #actions = []; #turnClaims = []; /** True while `agent_settled` handlers run: a turn they trigger is deferred until the window closes. */ get active() { return this.#generation !== undefined; } begin(userAbortGeneration) { this.#generation = userAbortGeneration; this.#actions = []; this.#turnClaims = []; } defer(action) { if (this.#generation === undefined) return false; this.#actions.push(action); return true; } deferTriggerTurn(action) { if (this.#generation === undefined) return false; const claim = new DeferredTurnClaim(); this.#turnClaims.push(claim); this.#actions.push(() => action(claim)); return true; } finish(userAbortGeneration) { const batch = this.#generation === userAbortGeneration ? { actions: this.#actions, turnClaims: this.#turnClaims } : { actions: [], turnClaims: [] }; this.#generation = undefined; this.#actions = []; this.#turnClaims = []; return batch; } cancel() { for (const claim of this.#turnClaims) claim.resolve("finished-without-start"); this.#generation = undefined; this.#actions = []; this.#turnClaims = []; } } //# sourceMappingURL=agent-settled-delivery.js.map