@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
46 lines • 1.56 kB
JavaScript
import { serializeJsonLine } from "./jsonl.js";
/** Linked-queue mutations own the retained totals; in-flight records are counted by the writer. */
export class SessionRecordAccounting {
constructor() {
this.count = 0;
this.bytes = 0;
}
append(queue, value, key, resolve, reject) {
const line = serializeJsonLine(value);
const byteLength = Buffer.byteLength(line);
const node = { value, line, byteLength, key, previous: queue.tail, resolve, reject };
if (queue.tail)
queue.tail.next = node;
else
queue.head = node;
queue.tail = node;
this.count++;
this.bytes += byteLength;
return node;
}
replace(node, value) {
const line = serializeJsonLine(value);
const byteLength = Buffer.byteLength(line);
this.bytes += byteLength - node.byteLength;
node.value = value;
node.line = line;
node.byteLength = byteLength;
}
unlink(queue, node) {
if (node.previous)
node.previous.next = node.next;
else
queue.head = node.next;
if (node.next)
node.next.previous = node.previous;
else
queue.tail = node.previous;
if (node.key && queue.latestByKey.get(node.key) === node)
queue.latestByKey.delete(node.key);
node.previous = undefined;
node.next = undefined;
this.count--;
this.bytes -= node.byteLength;
}
}
//# sourceMappingURL=session-record-accounting.js.map