Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed

Versions 161 to 162

Compare

+68 −0 in 1 place
new file, 68 lines
1+/** Incremental UTF-16 cursor over canonical log chunks. */
2+export class JsonChunkCursor {
3+ readonly #input: Iterator<string>;
4+ #chunk = "";
5+ #offset = 0;
6+ constructor(chunks: Iterable<string>) {
7+ this.#input = chunks[Symbol.iterator]();
8+ }
9+ peek(): string | undefined {
10+ while (this.#offset === this.#chunk.length) {
11+ const next = this.#input.next();
12+ if (next.done) return undefined;
13+ if (typeof next.value !== "string" || next.value.length > 600000) throw Error("invalid JSON input chunk");
14+ this.#chunk = next.value;
15+ this.#offset = 0;
16+ }
17+ return this.#chunk[this.#offset];
18+ }
19+ take(): string {
20+ const char = this.peek();
21+ if (char === undefined) throw Error("truncated JSON input");
22+ this.#offset++;
23+ return char;
24+ }
25+ /** Consume one quoted JSON string, yielding bounded decoded text. */
26+ *stringChunks(): IterableIterator<string> {
27+ if (this.take() !== '"') throw Error("expected JSON string");
28+ let buffer = "";
29+ for (;;) {
30+ let char = this.take();
31+ if (char === '"') {
32+ if (buffer) yield buffer;
33+ return;
34+ }
35+ if (char.charCodeAt(0) < 32) throw Error("unescaped JSON control character");
36+ if (char === "\\") {
37+ const escape = this.take();
38+ const simple: Record<string, string> = {
39+ '"': '"',
40+ "\\": "\\",
41+ "/": "/",
42+ b: "\b",
43+ f: "\f",
44+ n: "\n",
45+ r: "\r",
46+ t: "\t",
47+ };
48+ if (escape === "u") {
49+ let hex = "";
50+ for (let i = 0; i < 4; i++) hex += this.take();
51+ if (!/^[0-9a-fA-F]{4}$/.test(hex)) throw Error("invalid JSON Unicode escape");
52+ char = String.fromCharCode(Number.parseInt(hex, 16));
53+ } else {
54+ if (!Object.hasOwn(simple, escape)) throw Error("invalid JSON escape");
55+ char = simple[escape]!;
56+ }
57+ }
58+ buffer += char;
59+ if (buffer.length === 16384) {
60+ yield buffer;
61+ buffer = "";
62+ }
63+ }
64+ }
65+ close(): void {
66+ this.#input.return?.();
67+ }
68+}
MCP
compare on this site's /mcp
CLI
abso diff 161 162 server/src/json-chunk-cursor.ts --json
JSON
/christopher/abso-core/compare/161..162?file=server%2Fsrc%2Fjson-chunk-cursor.ts&format=json