@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
61 lines • 1.9 kB
JavaScript
/**
* A cursor over frames the owner releases once. `source` runs on the first read (`next` or `empty`): an owner that
* fixes the view at the freeze passes the frames it already built, one that fixes it at the read passes a thunk.
*/
export class FrozenFramesCursor {
constructor(source, onRelease) {
this.index = 0;
this.released = false;
this.source = source;
this.onRelease = onRelease;
}
get empty() {
return this.read().count === 0;
}
async next() {
if (this.released)
return undefined;
const frames = this.read();
if (this.index >= frames.count)
return undefined;
return frames.frame(this.index++);
}
release() {
if (this.released)
return;
this.released = true;
this.onRelease();
}
read() {
this.frames ??= this.source();
return this.frames;
}
}
/**
* A cursor whose frames are produced one at a time by an async generator over a frozen source (the compact
* current-state view). `empty` is decided synchronously by the owner from the frozen roots, so an attach with
* nothing to deliver installs no barrier; the generator starts on the first read.
*/
export class GeneratedFramesCursor {
constructor(empty, source, onRelease) {
this.released = false;
this.empty = empty;
this.source = source;
this.onRelease = onRelease;
}
async next() {
if (this.released)
return undefined;
this.frames ??= this.source();
const step = await this.frames.next();
return step.done ? undefined : step.value;
}
release() {
if (this.released)
return;
this.released = true;
void this.frames?.return(undefined);
this.onRelease();
}
}
//# sourceMappingURL=legacy-view-cursor.js.map