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

Compare

+60 −20 in 4 places
Lines 4–15 at 318 (were 4–15 at 4)
44import {
55 type AttrName,
66 type AttrSet,
7− diffLines,
7+ diffChunkedLines,
88 type EditInput,
99 type Hunk,
10+ type ReadView,
1011 type SpliceEdit,
1112 splitLines,
12− type View,
1313} from "../../src/engine/index.ts";
1414import type { AgentState, Entry, Meta, Mode } from "./project-types.ts";
1515
Lines 17–23 at 318 (were 17–23 at 4)
1717export interface RecordFileHost {
1818 addDraft(
1919 agent: AgentState,
20− view: View,
20+ view: ReadView,
2121 input: { edits: readonly EditInput[]; attrs?: readonly AttrSet[] },
2222 time: number,
2323 meta: Meta,
Lines 34–40 at 318 (were 34–40 at 4)
3434export function recordFile(
3535 host: RecordFileHost,
3636 agent: AgentState,
37− view: View,
37+ view: ReadView,
3838 path: string,
3939 text: string | null | undefined,
4040 time: number,
Lines 44–122 at 318 (were 44–82 at 4)
4444 blob?: string,
4545 hunks?: readonly Hunk[],
4646): boolean {
47− const was = view.attrs(path);
48− const exists = view.hasFile(path);
4947 const lines = text === undefined ? undefined : text === null ? "" : text;
5048 const edits: SpliceEdit[] =
51− lines === undefined || view.text(path) === lines
49+ lines === undefined || (hunks !== undefined && sameProjectedText(view, path, lines))
5250 ? []
53− : (
54− hunks ??
55− diffLines(
56− view.lines(path).map((l) => l.text),
57− splitLines(lines),
58− )
59− ).map((h) => ({ file: path, start: h.start, end: h.end, lines: h.lines }));
51+ : (hunks ?? diffChunkedLines(view.lineChunks(path), splitLines(lines))).map((h) => ({
52+ file: path,
53+ start: h.start,
54+ end: h.end,
55+ lines: h.lines,
56+ }));
57+ return recordFileChanges(
58+ host,
59+ agent,
60+ view,
61+ path,
62+ text === undefined ? "unchanged" : text === null ? "missing" : text === "" ? "empty" : "present",
63+ edits,
64+ time,
65+ meta,
66+ entries,
67+ mode,
68+ blob,
69+ );
70+}
72+/** Apply a precomputed exact text diff and the normal file attribute rules. */
73+export function recordFileChanges(
74+ host: RecordFileHost,
75+ agent: AgentState,
76+ view: ReadView,
77+ path: string,
78+ state: "unchanged" | "missing" | "empty" | "present",
79+ edits: readonly SpliceEdit[],
80+ time: number,
81+ meta: Meta,
82+ entries: Entry[],
83+ mode: Mode = {},
84+ blob?: string,
85+): boolean {
86+ const was = view.attrs(path);
87+ const exists = view.hasFile(path);
6089 const attrs: AttrSet[] = [];
6190 const set = (name: AttrName, now: string | null, value: string | null): void => {
6291 if (now !== value) attrs.push({ file: path, name, value });
6392 };
64− const link = mode.link !== undefined ? mode.link : text === null ? null : was.link;
65− if (text === null) {
93+ const link = mode.link !== undefined ? mode.link : state === "missing" ? null : was.link;
94+ if (state === "missing") {
6695 // Gone: no lines, and nothing keeps it.
6796 set("exists", was.exists ? "1" : null, null);
6897 set("exec", was.exec ? "1" : null, null);
69− } else if (text === "" && link === null && blob === undefined) {
98+ } else if (state === "empty" && link === null && blob === undefined) {
7099 // An empty file is kept by its exists attribute.
71100 set("exists", was.exists ? "1" : null, "1");
72101 }
73102 // A binary file is its blob and no lines; text, or no file, clears the blob.
74103 if (blob !== undefined) set("blob", was.blob, blob);
75− else if (text !== undefined) set("blob", was.blob, null);
76− if (mode.exec !== undefined && text !== null) set("exec", was.exec ? "1" : null, mode.exec ? "1" : null);
104+ else if (state !== "unchanged") set("blob", was.blob, null);
105+ if (mode.exec !== undefined && state !== "missing") set("exec", was.exec ? "1" : null, mode.exec ? "1" : null);
77106 set("link", was.link, link);
78107 if (edits.length === 0 && attrs.length === 0) return false;
79− if (!exists && text === null && attrs.length === 0) return false;
108+ if (!exists && state === "missing" && attrs.length === 0) return false;
80109 host.addDraft(agent, view, { edits, attrs }, time, meta, entries);
81110 return true;
82111}
113+/** Compare canonical projected text without joining or caching old lines. */
114+function sameProjectedText(view: ReadView, path: string, text: string): boolean {
115+ let offset = 0;
116+ for (const line of view.visibleLines(path)) {
117+ if (!text.startsWith(line.text, offset)) return false;
118+ offset += line.text.length;
119+ if (text[offset++] !== "\n") return false;
120+ }
121+ return offset === text.length;
122+}
MCP
compare on this site's /mcp
CLI
abso diff 4 318 worker/project/record-file.ts --json
JSON
/christopher/abso-core/compare/4..318?file=worker%2Fproject%2Frecord-file.ts&format=json