Something went wrong. Try again.
fork of prime agent with changes i want but are not upstreamable probqbly (and some fixes)
Something went wrong. Try again.
527 B · 27 lines
TypeScript
at main
12345678910111213141516171819202122232425262728/** * Generic undo stack with clone-on-push semantics. * * Stores cloned state snapshots. Popped snapshots are returned directly * since they are already detached. */export class UndoStack<S> { private stack: S[] = [];
constructor(private readonly clone: (state: S) => S = structuredClone) {}
push(state: S): void { this.stack.push(this.clone(state)); }
pop(): S | undefined { return this.stack.pop(); }
clear(): void { this.stack.length = 0; }
get length(): number { return this.stack.length; }}