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 74 to 318

Compare

+59 −0 in 1 place
new file, 59 lines
1+import type { Graph } from "../graph.ts";
2+
3+/** Private host-owned lifetime. The host closes it in commit/rollback finally blocks. */
4+export class ProjectionReadScope {
5+ readonly #graph: Graph;
6+ readonly #source: () => unknown;
7+ readonly #identity: unknown;
8+ readonly #parent: () => void;
9+ readonly #onClose: () => void;
10+ #active = true;
11+ #epoch = 0;
12+ #child = false;
13+ constructor(graph: Graph, source: () => unknown, parent = () => {}, onClose = () => {}) {
14+ this.#graph = graph;
15+ this.#source = source;
16+ this.#identity = source();
17+ this.#parent = parent;
18+ this.#onClose = onClose;
19+ }
20+ #check(): void {
21+ this.#parent();
22+ if (!this.#active || this.#source() !== this.#identity) throw Error("expired projection read scope");
23+ }
24+ /** Capture this exact graph revision and scope generation, not a mutable validity flag. */
25+ guard(graph: Graph): () => void {
26+ this.#check();
27+ if (graph !== this.#graph || this.#child) throw Error("projection read scope mismatch");
28+ const epoch = this.#epoch,
29+ size = graph.size;
30+ return () => {
31+ this.#check();
32+ if (this.#child || this.#epoch !== epoch || graph.size !== size) throw Error("stale projection reader");
33+ };
34+ }
35+ nested(): ProjectionReadScope {
36+ this.#check();
37+ if (this.#child) throw Error("projection child scope already active");
38+ this.#child = true;
39+ const epoch = ++this.#epoch;
40+ return new ProjectionReadScope(
41+ this.#graph,
42+ this.#source,
43+ () => {
44+ this.#check();
45+ if (this.#epoch !== epoch) throw Error("expired projection parent scope");
46+ },
47+ () => {
48+ this.#child = false;
49+ this.#epoch++;
50+ },
51+ );
52+ }
53+ close(): void {
54+ if (!this.#active) return;
55+ this.#active = false;
56+ this.#epoch++;
57+ this.#onClose();
58+ }
59+}
MCP
compare on this site's /mcp
CLI
abso diff 74 318 src/engine/experimental/projection-read-scope.ts --json
JSON
/christopher/abso-core/compare/74..318?file=src%2Fengine%2Fexperimental%2Fprojection-read-scope.ts&format=json