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
MCP
show on this site's /mcp
CLI
abso show 6 --json
JSON
/christopher/abso-core/versions/6?format=json

A big publish spends less on the changed-definition rule (abso issue 158, under 157).

of shared·engine··Not checked

Measured on gig-replay-2's a3 PR 309 publish, five versions behind shared, through the Worker's project layer with text read back from the log, as live runs it. Cloud measured 9 s of CPU on staging. Two costs in the definition rule:

  1. For every line a draft wrote, it walked the atom's runs to find the run holding the line, and each run's length meant reading its text back from the log. Each atom's run ends are now worked out once per check (definition-rule.ts).
  2. It scanned data files for definitions. A 23,000-line JSON fixture was read line by line for names it can't define, and its keys could pass for uses of code names. JSON, CSV, lock and SVG files now count as holding no code, like prose (names.ts holdsNoCode).

The publish through EngineProject takes about 0.84-1.1 s locally (was 1.9 s); what's left is mostly expressing moves within the layout budget.

Tests: a new definitions test (data files hold no definitions); the changed-definition tests pass. Check passes (695), and the project tests also pass with AVCS_TEXT_FROM_LOG=1 (217). The replay gate passed on 33 live projects (ef9edb7) with these same three files in abso's folder.

Version 5 · Files at version 6

4 files, 42 lines added, 14 removed.

--- a/worker/project/definition-rule.ts
+++ b/worker/project/definition-rule.ts
@@ -7,7 +7,7 @@
77import { type AtomId, type Graph, joinLines, type LineId, type View } from "../../src/engine/index.ts";
88import { type Origin, touchedFiles } from "./collisions.ts";
99import { type Definition, definitionsIn, importsOf, usedNames } from "./definitions.ts";
10−import { codeOfLines, declaredIn, isProse } from "./names.ts";
10+import { codeOfLines, declaredIn, holdsNoCode } from "./names.ts";
1111import { definitionText } from "./news.ts";
1212import type { Collision } from "./project.ts";
1313
@@ -30,6 +30,12 @@
3030
3131const EMPTY_NAMES: ReadonlySet<string> = new Set();
3232
33+/** Where one of an atom's inserted runs ends (its lines' k), and the node it hangs off. */
34+interface RunEnd {
35+ readonly end: number;
36+ readonly parent: string;
37+}
3339export class DefinitionRule {
3440 readonly #graph: Graph;
3541 readonly #origin: (atom: AtomId, spaceName: string) => Origin;
@@ -46,20 +52,20 @@
4652 * replaced the block of lines the atom deleted just before it in `base`.
4753 * A pure insertion replaced nothing.
4854 */
49− #replacedNames(line: LineId, base: View): ReadonlySet<string> {
55+ #replacedNames(line: LineId, base: View, runsOf: Map<AtomId, readonly RunEnd[]>): ReadonlySet<string> {
5056 const g = this.#graph;
5157 const info = g.line(line);
5258 if (!info) return EMPTY_NAMES;
5359 const atom = g.atom(info.atom);
54− let k = 0;
55− let parent: string | undefined;
56− for (const run of atom.inserts) {
57− if (info.k < k + run.lines.length) {
58− parent = run.parent;
59− break;
60− }
61− k += run.lines.length;
60+ // Where each of the atom's runs ends, worked out once per check (abso issue 158): reading a run's
61+ // lines can mean reading its text back from the log, so not once per line of a big change.
62+ let runs = runsOf.get(atom.id);
63+ if (!runs) {
64+ let k = 0;
65+ runs = atom.inserts.map((run) => ({ end: (k += run.lines.length), parent: run.parent }));
66+ runsOf.set(atom.id, runs);
6267 }
68+ const parent = runs.find((r) => info.k < r.end)?.parent;
6369 if (parent === undefined || parent.startsWith("^") || !g.deletersOf(parent).includes(atom.id)) return EMPTY_NAMES;
6470 const key = `${atom.id} ${parent}`;
6571 let names = this.#replacedCache.get(key);
@@ -100,10 +106,11 @@
100106 if (draft.size === 0 || newer.size === 0) return [];
101107 const uses = new Map<string, { file: string; index: number }[]>();
102108 const declared = new Set<string>();
109+ const runsOf = new Map<AtomId, readonly RunEnd[]>();
103110 // Only files the draft wrote lines in can hold its lines.
104111 const draftFiles = touchedFiles(this.#graph, draft, [view]);
105112 for (const file of [...draftFiles].sort()) {
106− if (isProse(file) || !view.hasFile(file)) continue;
113+ if (holdsNoCode(file) || !view.hasFile(file)) continue;
107114 const visible = view.lines(file);
108115 if (!visible.some((l) => draft.has(l.atom))) continue;
109116 const code = codeOfLines(visible.map((l) => l.text));
@@ -111,7 +118,7 @@
111118 if (!draft.has(line.atom)) return;
112119 for (const name of declaredIn(code[i]!)) declared.add(name);
113120 // Only names the change added: a use already on the lines it replaced is not the draft's to answer for.
114− const before = this.#replacedNames(line.id, baseView);
121+ const before = this.#replacedNames(line.id, baseView, runsOf);
115122 for (const name of usedNames(code[i]!)) {
116123 if (before.has(name)) continue;
117124 const list = uses.get(name);
--- a/worker/project/definitions.ts
+++ b/worker/project/definitions.ts
@@ -20,7 +20,7 @@
2020// that defines it (project.ts, #definitionCore).
2121
2222import type { LineId, View } from "../../src/engine/index.ts";
23−import { codeOfLines, isCommonName, isProse } from "./names.ts";
23+import { codeOfLines, holdsNoCode, isCommonName } from "./names.ts";
2424
2525export interface Definition {
2626 readonly name: string;
@@ -119,7 +119,7 @@
119119}
120120
121121function definitionsInFile(view: View, file: string, keepCommon = false): Definition[] {
122− if (isProse(file) || !view.hasFile(file)) return [];
122+ if (holdsNoCode(file) || !view.hasFile(file)) return [];
123123 const out: Definition[] = [];
124124 const visible = view.lines(file);
125125 const code = codeOfLines(visible.map((l) => l.text));
--- a/worker/project/names.ts
+++ b/worker/project/names.ts
@@ -64,6 +64,21 @@
6464]);
6565
6666/** Files of prose, whose words are not code: Markdown, plain text, READMEs and the like. */
67+/** Data files: no code defines or uses a name in them, however big they are (abso issue 158). */
68+const DATA_EXTENSIONS = new Set(["json", "jsonc", "json5", "jsonl", "ndjson", "geojson", "csv", "tsv", "lock", "svg"]);
70+/**
71+ * Whether the definition rule passes over a file: prose, or data. Scanning a
72+ * 23,000-line JSON fixture for definitions it can't hold cost a big publish
73+ * hundreds of milliseconds, and its keys could pass for uses of code names.
74+ */
75+export function holdsNoCode(path: string): boolean {
76+ if (isProse(path)) return true;
77+ const base = path.slice(path.lastIndexOf("/") + 1).toLowerCase();
78+ const dot = base.lastIndexOf(".");
79+ return dot > 0 && DATA_EXTENSIONS.has(base.slice(dot + 1));
80+}
6782export function isProse(path: string): boolean {
6883 const base = path.slice(path.lastIndexOf("/") + 1).toLowerCase();
6984 const dot = base.lastIndexOf(".");
--- a/worker/project/test/definitions.test.ts
+++ b/worker/project/test/definitions.test.ts
@@ -62,3 +62,9 @@
6262 Span: ["pub struct Span {\n start: usize,\n}"],
6363 });
6464});
66+test("data files hold no definitions: JSON, CSV and lock files are passed over, however code-like a line looks (abso issue 158)", () => {
67+ const codeLike = "export function parsePattern(text: string): Node {\n return compileNode(text);\n}\n";
68+ assert.deepEqual(defs({ "fixtures/a.json": codeLike, "data/b.csv": codeLike, "c.lock": codeLike }), {});
69+ assert.deepEqual(Object.keys(defs({ "src/a.ts": codeLike })), ["parsePattern"]);
70+});