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

+76 −31 in 9 places
Lines 5–11 at 162 (were 5–10 at 161)
55import type { GraphStateStorage } from "../../src/engine/state-source.ts";
66import { Project, type WriterSource } from "../../worker/project/project.ts";
77import type { ProjectOptions } from "../../worker/project/project-types.ts";
8+import { withDecodedFrames } from "./decoded-frames.ts";
89import {
910 EngineProject,
1011 logParts,
Lines 13–19 at 162 (were 12–17 at 161)
1213 SqliteLog,
1314 type SqliteStorage,
1415} from "./engine-project.ts";
16+import type { SqliteHistoryHost } from "./history-host.ts";
1517
1618export class SqliteWriterState implements GraphStateStorage {
1719 readonly #storage: SqliteStorage;
Lines 147–185 at 162 (were 145–169 at 161)
145147
146148/** Domain-separated SHA-256 chain over exact canonical UTF-8 frames and their positions. */
147149export function writerFrameDigest(previous: string, seq: number, json: string): string {
148− return createHash("sha256")
150+ return writerFrameChunksDigest(previous, seq, [json]);
151+}
153+/** Same canonical digest without retaining the complete frame. */
154+export function writerFrameChunksDigest(previous: string, seq: number, chunks: Iterable<string>): string {
155+ const hash = createHash("sha256")
149156 .update("abso-writer-log-v1\n")
150157 .update(JSON.stringify([previous, seq]))
151− .update("\n")
152− .update(json, "utf8")
153− .digest("hex");
158+ .update("\n");
159+ let carry = "";
160+ for (const chunk of chunks) {
161+ const text = carry + chunk;
162+ const last = text.charCodeAt(text.length - 1);
163+ const split = last >= 0xd800 && last <= 0xdbff;
164+ carry = split ? text.slice(-1) : "";
165+ hash.update(split ? text.slice(0, -1) : text, "utf8");
166+ }
167+ if (carry) hash.update(carry, "utf8");
168+ return hash.digest("hex");
154169}
155170
156171export function advanceWriterRoot(log: SqliteLog, previous: WriterRoot, source: WriterSource): WriterRoot {
157172 let digest = previous.digest;
158173 if (source.logLength < previous.logLength) throw new Error("writer root cannot move backwards");
159174 for (let seq = previous.logLength; seq < source.logLength; seq++)
160− digest = writerFrameDigest(digest, seq, log.boundedFrame(seq, 8_000_000));
175+ digest = writerFrameChunksDigest(digest, seq, log.frameChunks(seq));
161176 return { format: 1, ...source, digest };
162177}
163178
164179/** Inactive host for explicit adoption and synchronous fenced writer operations. */
165180export interface WriterProjectionSession {
166181 readonly readViewProvider: NonNullable<ProjectOptions["readViewProvider"]>;
182+ historicalReadViewProvider?(state: GraphStateStorage): NonNullable<ProjectOptions["readViewProvider"]>;
167183 commit(project: Project, root: WriterRoot): void;
168184 /** Cleanup is inside the canonical transaction. Any failure aborts roots and receipt too. */
169185 close(): void;
Lines 192–216 at 162 (were 176–196 at 161)
176192
177193export class SqliteWriterHost {
178194 readonly #storage: SqliteStorage;
195+ readonly #namespace: string;
179196 readonly #state: SqliteWriterState;
180197 readonly #log: SqliteLog;
181198 readonly #projection?: WriterProjectionHost;
182199 readonly #indexProjectionAtoms: boolean;
200+ readonly #history?: SqliteHistoryHost;
183201 constructor(
184202 storage: SqliteStorage,
185203 namespace: string,
186204 projection?: WriterProjectionHost,
187− options: { indexProjectionAtoms?: boolean } = {},
205+ options: { indexProjectionAtoms?: boolean; history?: SqliteHistoryHost } = {},
188206 ) {
189207 this.#storage = storage;
208+ this.#namespace = namespace;
190209 this.#state = new SqliteWriterState(storage, namespace);
191210 this.#log = new SqliteLog(storage);
192211 this.#projection = projection;
193212 this.#indexProjectionAtoms = options.indexProjectionAtoms ?? false;
213+ this.#history = options.history;
194214 }
195215 #indexOptions(adopting = false) {
196216 const mode = this.#state.read("host", "projection-atom-index-mode");
Lines 266–271 at 162 (were 246–252 at 161)
246266 input.maxEntries > 256 ||
247267 !Number.isSafeInteger(input.maxBytes) ||
248268 input.maxBytes < 1 ||
249− input.maxBytes > 8_000_000 ||
250269 !(input.digest === "" || /^[a-f0-9]{64}$/.test(input.digest))
251270 )
252271 throw new Error("invalid bounded adoption request");
Lines 307–335 at 162 (were 288–317 at 161)
288307 )
289308 throw new Error("writer adoption root cursor is stale");
290309 let digest = previous?.digest ?? "";
291− const frames = function* () {
292− let bytes = 0;
293− for (let seq = from; seq < source.logLength && seq < from + limits.maxEntries; seq++) {
294− // Each frame is bounded before reading; the core also checks the
295− // cumulative byte count before applying a frame.
296− const json = log.boundedFrame(seq, limits.maxBytes);
297− const next = new TextEncoder().encode(json).byteLength;
298− if (bytes + next > limits.maxBytes && bytes > 0) return;
299− bytes += next;
300− digest = writerFrameDigest(digest, seq, json);
301− yield { seq, json };
302− }
303− };
304− const result = Project.adoptWriterPage(
305− this.#state,
306− {
307− source,
308− from,
309− frames: frames(),
310− ...limits,
311− currentSource: () => this.source(),
310+ const decoded = withDecodedFrames(
311+ this.#storage,
312+ `${this.#namespace}:decoded`,
313+ log,
314+ { from, to: source.logLength, ...limits, digest },
315+ (frames) => {
316+ const result = Project.adoptWriterPage(
317+ this.#state,
318+ {
319+ source,
320+ from,
321+ frames,
322+ ...limits,
323+ decodedFrames: true,
324+ currentSource: () => this.source(),
325+ },
326+ indexOptions,
327+ );
328+ return result;
312329 },
313− indexOptions,
314330 );
331+ const result = decoded.result;
332+ digest = decoded.digest;
315333 SqliteWriterHost.#sync(validateAuthority());
316334 this.#state.write("host", "adoption-root", { source, next: result.next, digest });
317335 if (result.ready) {
Lines 369–393 at 162 (were 351–357 at 161)
351369 readViewProvider: projection?.readViewProvider,
352370 entryAt: (index) => this.#log.since(index, 1)[0]!,
353371 });
354− const result = input.operation(new EngineProject(project, (from, limit) => this.#log.since(from, limit)));
372+ const root = this.root();
373+ const result = input.operation(
374+ new EngineProject(
375+ project,
376+ (from, limit) => this.#log.since(from, limit),
377+ undefined,
378+ this.#history
379+ ? (at, operation) =>
380+ this.#history!.read(
381+ root,
382+ () => this.root(),
383+ input.validateAuthority,
384+ at,
385+ operation,
386+ projection?.historicalReadViewProvider,
387+ )
388+ : undefined,
389+ ),
390+ );
355391 SqliteWriterHost.#sync(result);
356392 SqliteWriterHost.#sync(input.validateAuthority());
357393 if (!SqliteWriterHost.#same(source, this.source())) throw new Error("reader source changed");
Lines 410–424 at 162 (were 374–380 at 161)
374410 return this.run({
375411 ...input,
376412 operation: (project) => {
377− const calls = new EngineProject(project, (from, limit) => this.#log.since(from, limit), this.#log);
413+ const root = this.root();
414+ const calls = new EngineProject(
415+ project,
416+ (from, limit) => this.#log.since(from, limit),
417+ this.#log,
418+ this.#history
419+ ? (at, operation) => this.#history!.read(root, () => this.root(), input.validateAuthority, at, operation)
420+ : undefined,
421+ );
378422 calls.setCheckerReady(input.checkerReady);
379423 return input.operation(calls);
380424 },
Lines 457–463 at 162 (were 413–418 at 161)
413457 const committedRoot = advanceWriterRoot(this.#log, root, committed);
414458 this.#state.write("host", "canonical-root", committedRoot);
415459 SqliteWriterHost.#sync(projection?.commit(project, committedRoot));
460+ this.#history?.advance(this.#log, root, committedRoot, () => this.root(), input.validateAuthority);
416461 SqliteWriterHost.#sync(input.commitReceipt(result, committed));
417462 return result;
418463 } finally {
MCP
compare on this site's /mcp
CLI
abso diff 161 162 server/src/writer-host.ts --json
JSON
/christopher/abso-core/compare/161..162?file=server%2Fsrc%2Fwriter-host.ts&format=json