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

Compare

+46 −14 in 12 places
Lines 4–10 at 318 (were 4–10 at 166)
44
55import { Graph } from "./graph.ts";
66import { attrKey, gapKey, isStartNode, lineKey, parseKey, posKey, startNode, writerOf } from "./keys.ts";
7−import { diffLines, joinLines, normalizeText, splitLines } from "./text.ts";
7+import { diffChunkedLines, joinLines, normalizeText, splitLines } from "./text.ts";
88import {
99 ATTR_NAMES,
1010 type Atom,
Lines 26–58 at 318 (were 26–33 at 166)
2626/** Exact read surface used to build atoms; membership requires point lookup only. */
2727export type AtomBuildView = Pick<View, "graph" | "lines" | "sequence" | "sequenceIndex" | "parentOf"> & {
2828 readonly set: Pick<ReadonlySet<AtomId>, "has">;
29+ buildLines?: View["buildLines"];
2930};
3031
32+function buildingLines(view: AtomBuildView, path: string) {
33+ return view.buildLines ? view.buildLines(path) : view.lines(path);
34+}
36+/** Cache only within one immutable build; never retain handles across writes. */
37+function cachedBuildView(view: AtomBuildView): AtomBuildView {
38+ const files = new Map<string, ReturnType<View["lines"]>>();
39+ return {
40+ graph: view.graph,
41+ set: view.set,
42+ lines(path) {
43+ let lines = files.get(path);
44+ if (!lines) {
45+ lines = buildingLines(view, path);
46+ files.set(path, lines);
47+ }
48+ return lines;
49+ },
50+ sequence: (path) => view.sequence(path),
51+ sequenceIndex: (path, line) => view.sequenceIndex(path, line),
52+ parentOf: (line) => view.parentOf(line),
53+ };
54+}
3156/** Replace the one exact occurrence of `old` in `file` with `new`. */
3257export interface TextEdit {
3358 readonly file: string;
Lines 157–163 at 318 (were 132–137 at 166)
132157}
133158
134159function build(view: AtomBuildView, input: AtomInput, allowEmpty: boolean): Atom {
160+ view = cachedBuildView(view);
135161 const graph = view.graph;
136162 const id = graph.nextId();
137163 if (typeof input.author !== "string" || typeof input.message !== "string") {
Lines 178–191 at 318 (were 152–160 at 166)
152178 const emptiedBy = new Set<AtomId>();
153179
154180 for (const region of regions) {
155− const visible = view.lines(region.file);
156− const oldLines = visible.slice(region.start, region.end).map((l) => l.text);
157− for (const hunk of diffLines(oldLines, region.lines)) {
181+ const visible = buildingLines(view, region.file);
182+ function* oldLines() {
183+ for (let i = region.start; i < region.end; i++) {
184+ const line = visible[i]!;
185+ yield () => (line.textChunks ? line.textChunks() : [line.text]);
186+ }
187+ }
188+ for (const hunk of diffChunkedLines(oldLines(), region.lines)) {
158189 const start = region.start + hunk.start;
159190 const end = region.start + hunk.end;
160191 let parent: NodeId;
Lines 316–322 at 318 (were 285–291 at 166)
285316 if (typeof path !== "string" || path === "" || /[\n\r]/.test(path))
286317 throw new EngineError("bad-edit", `bad file path ${JSON.stringify(path)}`);
287318 }
288− const visible = view.lines(move.file);
319+ const visible = buildingLines(view, move.file);
289320 const { start, end, at } = move;
290321 if (!Number.isInteger(start) || !Number.isInteger(end) || start < 0 || end > visible.length || start >= end) {
291322 throw new EngineError(
Lines 324–330 at 318 (were 293–299 at 166)
293324 `${move.file} lines [${start}, ${end}) are not a non-empty range of its ${visible.length} visible lines`,
294325 );
295326 }
296− const dest = view.lines(move.to);
327+ const dest = buildingLines(view, move.to);
297328 if (!Number.isInteger(at) || at < 0 || at > dest.length) {
298329 throw new EngineError("bad-range", `${move.to} has no place ${at} (it has ${dest.length} visible lines)`);
299330 }
Lines 427–433 at 318 (were 396–402 at 166)
396427}
397428
398429function rangeLines(view: AtomBuildView, range: LineRange): LineId[] {
399− const visible = view.lines(range.file);
430+ const visible = buildingLines(view, range.file);
400431 if (
401432 !Number.isInteger(range.start) ||
402433 !Number.isInteger(range.end) ||
Lines 496–502 at 318 (were 465–471 at 166)
465496 throw new EngineError("bad-edit", "a text edit needs old and new strings");
466497 }
467498 const file = edit.file;
468− const visible = view.lines(file);
499+ const visible = buildingLines(view, file);
469500 const oldText = normalizeText(edit.old);
470501 const newText = normalizeText(edit.new);
471502 if (oldText === "") {
Lines 508–515 at 318 (were 477–483 at 166)
477508 }
478509 return { file, start: 0, end: 0, lines: splitLines(newText), mode, order };
479510 }
480− const text = joinLines(visible.map((l) => l.text));
511+ const texts = visible.map((line) => line.text);
512+ const text = joinLines(texts);
481513 const at = text.indexOf(oldText);
482514 if (at < 0) throw new EngineError("no-match", `old text not found in ${file}`);
483515 if (text.indexOf(oldText, at + 1) >= 0) {
Lines 520–528 at 318 (were 488–496 at 166)
488520 }
489521 const starts: number[] = [];
490522 let pos = 0;
491− for (const line of visible) {
523+ for (const text of texts) {
492524 starts.push(pos);
493− pos += line.text.length + 1;
525+ pos += text.length + 1;
494526 }
495527 const lineAt = (offset: number): number => {
496528 let lo = 0;
Lines 538–549 at 318 (were 506–517 at 166)
506538 const startLine = lineAt(at);
507539 let endLine = lineAt(end - 1);
508540 const lineStart = starts[startLine]!;
509− const lineEnd = starts[endLine]! + visible[endLine]!.text.length + 1;
541+ const lineEnd = starts[endLine]! + texts[endLine]!.length + 1;
510542 let replacement = text.slice(lineStart, at) + newText + text.slice(end, lineEnd);
511543 if (replacement !== "" && !replacement.endsWith("\n")) {
512544 if (endLine + 1 < visible.length) {
513545 endLine++;
514− replacement += `${visible[endLine]!.text}\n`;
546+ replacement += `${texts[endLine]}\n`;
515547 } else {
516548 replacement += "\n";
517549 }
Lines 552–558 at 318 (were 520–526 at 166)
520552}
521553
522554function matchSplice(view: AtomBuildView, edit: SpliceEdit, mode: Mode, order: number): Region {
523− const count = view.lines(edit.file).length;
555+ const count = buildingLines(view, edit.file).length;
524556 if (
525557 !Number.isInteger(edit.start) ||
526558 !Number.isInteger(edit.end) ||
MCP
compare on this site's /mcp
CLI
abso diff 166 318 src/engine/build.ts --json
JSON
/christopher/abso-core/compare/166..318?file=src%2Fengine%2Fbuild.ts&format=json