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 108 to 109

Compare

+43 −0 in 1 place
new file, 43 lines
1+import { DatabaseSync } from "node:sqlite";
2+import type { GraphStateStorage } from "../state-source.ts";
3+
4+export class SqlState implements GraphStateStorage {
5+ readonly db = new DatabaseSync(":memory:");
6+ reads = 0;
7+ writes = 0;
8+ scans = 0;
9+ failWrite = Infinity;
10+ constructor() {
11+ this.db.exec("CREATE TABLE state (collection TEXT, key TEXT, value TEXT, PRIMARY KEY(collection,key))");
12+ }
13+ read(collection: string, key: string): unknown {
14+ this.reads++;
15+ const row = this.db.prepare("SELECT value FROM state WHERE collection = ? AND key = ?").get(collection, key);
16+ return row ? JSON.parse(row.value as string).value : undefined;
17+ }
18+ write(collection: string, key: string, value: unknown): void {
19+ if (++this.writes === this.failWrite) throw new Error("injected storage failure");
20+ this.db.prepare("INSERT OR REPLACE INTO state VALUES (?, ?, ?)").run(collection, key, JSON.stringify({ value }));
21+ }
22+ remove(collection: string, key: string): void {
23+ this.db.prepare("DELETE FROM state WHERE collection = ? AND key = ?").run(collection, key);
24+ }
25+ *entries(collection: string): Iterable<readonly [string, unknown]> {
26+ this.scans++;
27+ for (const row of this.db
28+ .prepare("SELECT key, value FROM state WHERE collection = ? ORDER BY key")
29+ .iterate(collection))
30+ yield [row.key as string, JSON.parse(row.value as string).value];
31+ }
32+ transaction<T>(body: () => T): T {
33+ this.db.exec("SAVEPOINT graph_change");
34+ try {
35+ const value = body();
36+ this.db.exec("RELEASE graph_change");
37+ return value;
38+ } catch (error) {
39+ this.db.exec("ROLLBACK TO graph_change; RELEASE graph_change");
40+ throw error;
41+ }
42+ }
43+}
MCP
compare on this site's /mcp
CLI
abso diff 108 109 src/engine/test/storage-helper.ts --json
JSON
/christopher/abso-core/compare/108..109?file=src%2Fengine%2Ftest%2Fstorage-helper.ts&format=json