codex-capacity-policy's draft
CCP codex-capacity-policy on version 106. 2 files, 114 lines added, 0 removed.
src/engine/state-source.ts +25 −0
--- /dev/null
+++ b/src/engine/state-source.ts
@@ -0,0 +1,25 @@
1+import type { Atom, AtomId, Key, LineId } from "./types.ts";
2+import type { LineInfo, RelocationInfo } from "./graph.ts";
3+
4+/**
5+ * Read-only historical metadata needed by a Graph that does not retain every
6+ * accepted atom and index in its working set. This is a storage-neutral port:
7+ * it does not prescribe SQLite, D1, R2, a schema, or a persistence lifecycle.
8+ *
9+ * Reads are synchronous because today's Graph queries are synchronous. An
10+ * asynchronous D1/R2 implementation cannot be wired directly into this port;
11+ * it needs an explicitly reviewed bounded prefetch or async Graph boundary.
12+ */
13+export interface GraphStateSource {
14+ readonly atomCount: number;
15+ atomAt(seq: number): Atom | undefined;
16+ lineAt(number: number): LineInfo | undefined;
17+ lineNumber(id: LineId): number | undefined;
18+ claims(key: Key): {
19+ readonly writers: readonly AtomId[];
20+ readonly readers: readonly AtomId[];
21+ readonly holders: readonly AtomId[];
22+ };
23+ relocations(line: LineId): readonly RelocationInfo[];
24+ dependencies(id: AtomId): readonly AtomId[] | undefined;
25+}
src/engine/test/state-source.test.ts +89 −0
--- /dev/null
+++ b/src/engine/test/state-source.test.ts
@@ -0,0 +1,89 @@
1+import assert from "node:assert/strict";
2+import { describe, it } from "node:test";
3+import { type AtomId, Graph, type Key, type LineId, type LineInfo, type RelocationInfo, View } from "../index.ts";
4+import type { GraphStateSource } from "../state-source.ts";
5+import type { Atom } from "../types.ts";
6+import { Repo, lines } from "./helpers.ts";
7+
8+/** A small independent read adapter over the accepted Graph oracle. */
9+function oracleSource(graph: Graph): GraphStateSource {
10+ const atoms = graph.atoms();
11+ const lineCount = atoms.reduce((n, atom) => n + atom.inserts.reduce((m, run) => m + run.lines.length, 0), 0);
12+ return {
13+ atomCount: graph.size,
14+ atomAt(seq: number): Atom | undefined {
15+ return atoms[seq];
16+ },
17+ lineAt(number: number): LineInfo | undefined {
18+ if (!Number.isSafeInteger(number) || number < 0 || number >= lineCount) return undefined;
19+ return graph.line(graph.lineIdOf(number));
20+ },
21+ lineNumber(id: LineId): number | undefined {
22+ const n = graph.lineN(id);
23+ return n < 0 ? undefined : n;
24+ },
25+ claims(key: Key) {
26+ return { writers: graph.writersOf(key), readers: graph.readersOf(key), holders: graph.holdersOf(key) };
27+ },
28+ relocations(line: LineId): readonly RelocationInfo[] {
29+ return graph.relocationsOf(line);
30+ },
31+ dependencies(id: AtomId): readonly AtomId[] | undefined {
32+ try {
33+ return graph.atom(id).deps;
34+ } catch {
35+ return undefined;
36+ }
37+ },
38+ };
39+}
40+
41+describe("GraphStateSource oracle contract", () => {
42+ it("exposes historical atom, line, claim, relocation, and dependency facts from Graph", () => {
43+ const repo = Repo.init({ "a.txt": lines("one", "two", "three"), "b.txt": "" });
44+ const first = repo.edit({ edits: [{ file: "a.txt", old: "two", new: "TWO" }] });
45+ const moved = repo.edit({ move: { file: "a.txt", start: 1, end: 2, to: "b.txt", at: 0 } });
46+ const source = oracleSource(repo.graph);
47+
48+ assert.equal(source.atomCount, repo.graph.size);
49+ for (let seq = 0; seq < source.atomCount; seq++) {
50+ const atom = source.atomAt(seq);
51+ assert.deepEqual(atom, repo.graph.atom(`a${seq}`));
52+ assert.deepEqual(source.dependencies(atom!.id), atom!.deps);
53+ }
54+ assert.equal(source.atomAt(-1), undefined);
55+ assert.equal(source.atomAt(source.atomCount), undefined);
56+
57+ for (const id of ["a0.0", "a0.1", "a0.2", `${first.id}.0` as LineId]) {
58+ const number = source.lineNumber(id as LineId);
59+ assert.notEqual(number, undefined);
60+ assert.deepEqual(source.lineAt(number!), repo.graph.line(id as LineId));
61+ }
62+ assert.equal(source.lineAt(-1), undefined);
63+ assert.equal(source.lineAt(Number.MAX_SAFE_INTEGER), undefined);
64+ assert.equal(source.lineNumber("a999.0" as LineId), undefined);
65+
66+ const key = `L:${first.id}.0` as Key;
67+ assert.deepEqual(source.claims(key), {
68+ writers: repo.graph.writersOf(key),
69+ readers: repo.graph.readersOf(key),
70+ holders: repo.graph.holdersOf(key),
71+ });
72+ assert.ok(moved.moves?.length);
73+ const movedLine = moved.moves![0]!.line;
74+ assert.deepEqual(source.relocations(movedLine), repo.graph.relocationsOf(movedLine));
75+ });
76+
77+ it("keeps actual View layout and conflict decisions as the independent semantic oracle", () => {
78+ const repo = Repo.init({ "a.txt": lines("one", "two", "three") });
79+ const left = repo.edit({ edits: [{ file: "a.txt", old: "one", new: "ONE" }], author: "left" });
80+ const right = repo.draft({ edits: [{ file: "a.txt", old: "one", new: "uno" }], author: "right" }, ["a0"]);
81+ const source = oracleSource(repo.graph);
82+
83+ const view = new View(repo.graph, ["a0", left.id]);
84+ assert.deepEqual(view.files(), { "a.txt": "ONE\ntwo\nthree\n" });
85+ assert.deepEqual(repo.graph.writersOf(`L:a0.0` as Key), source.claims(`L:a0.0` as Key).writers);
86+ assert.equal(repo.graph.dependsOn(left.id, "a0"), source.dependencies(left.id)!.includes("a0" as AtomId));
87+ assert.equal(repo.check(right).conflicts.length, 1);
88+ });
89+});
- MCP
- draft on this site's /mcp
- CLI
- none: the JSON below is the answer
- JSON
- /christopher/abso-core/drafts/by/codex-capacity-policy?format=json