UNPKG

@code-yeongyu/senpi

Version:

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

50 lines • 2.32 kB
/** * The producer half of RULING-36a/40: one lifetime ordinal per acceptance unit (on a worker, the S04a output-frame * ordinal itself, never reset) and each message's first canonical ordinal, bound by the producer until its outer end. * Every message ends with a legacy `message_end` (completion, error and abort alike), so that record releases the * binding even when no canonical terminal paired with it; an epoch's end releases them all. */ export class CompactProducerStamp { constructor() { this.next = 0; this.first = new Map(); this.last = { ordinal: -1, }; } stamp(carrier, canonical, legacy) { const ordinal = this.next++; this.last = { ordinal }; if (!carrier) return { ordinal }; const ends = canonical?.type === "message_end" || (legacy !== undefined && Reflect.get(legacy, "type") === "message_end"); const firstOrdinal = canonical ? (this.first.get(carrier.messageId) ?? ordinal) : undefined; if (ends) this.first.delete(carrier.messageId); else if (firstOrdinal !== undefined) this.first.set(carrier.messageId, firstOrdinal); this.last = { ordinal, firstOrdinal, messageId: carrier.messageId }; return firstOrdinal === undefined ? { ordinal } : { ordinal, firstOrdinal }; } /** * The unit stamped last becomes the final commit frame of a transfer whose `prefix` fragment frames take the ordinals * before it (RULING-64): its ordinal moves past them, and so does a first-ordinal binding it started itself. */ defer(prefix) { const { ordinal, firstOrdinal, messageId } = this.last; const moved = ordinal + prefix; this.next += prefix; if (firstOrdinal === undefined) return { ordinal: moved }; if (firstOrdinal !== ordinal) return { ordinal: moved, firstOrdinal }; if (messageId !== undefined && this.first.get(messageId) === ordinal) this.first.set(messageId, moved); return { ordinal: moved, firstOrdinal: moved }; } /** A replacement starts a new epoch, in which no message of the old one continues. */ forget() { this.first.clear(); } } //# sourceMappingURL=compact-producer-stamp.js.map