@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
53 lines • 1.91 kB
JavaScript
import { adjustBlock, appendBlock } from "./compact-active-block.js";
import { CompactValues } from "./compact-values.js";
/** Candidate payloads remain owned until publication acquires them or rejection releases them. */
export class CompactSeededDraft {
constructor(store) {
this.releases = [];
this.store = store;
this.values = new CompactValues(store);
}
/** `removeNull` reads a message-metadata change, where `null` removes the field. */
fields(value, previous = {}, removeNull = false) {
const result = { ...previous };
for (const [key, item] of Object.entries(value)) {
if (item === undefined)
continue;
if (item === null && removeNull) {
Reflect.deleteProperty(result, key);
continue;
}
const ref = this.values.own(item);
this.releases.push(() => this.store.adjust(ref.owner, -1, 0));
Object.defineProperty(result, key, { value: ref, enumerable: true, configurable: true, writable: true });
}
return result;
}
text(kind, text = "") {
const block = {
kind,
root: 0,
tail: "",
tailRoot: 0,
units: 0,
emitted: 0,
covered: 0,
witness: "",
};
this.releases.push(() => adjustBlock(this.store, block, -1));
appendBlock(this.store, block, text);
block.emitted = block.units;
return block;
}
clone(block) {
const candidate = { ...block };
adjustBlock(this.store, candidate, 1);
this.releases.push(() => adjustBlock(this.store, candidate, -1));
return candidate;
}
[Symbol.dispose]() {
for (const release of this.releases.reverse())
release();
}
}
//# sourceMappingURL=compact-seeded-draft.js.map