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 195 --json
JSON
/christopher/abso-core/versions/195?format=json

Auto-settle (#19): score it on project abso's own past settles. extract.ts now finds each collided region with git's line diff (before theirs, theirs, the settle's result) instead of one span over the whole file. rules.ts turns down a keep-both that holds one statement in two versions (an import from the same module with different names): on abso's history the model picked keep both there at 1.00, which wouldn't have compiled.

of shared·autosettle··Not checked

Version 194 · Files at version 195

2 files, 133 lines added, 65 removed.

--- a/scripts/autosettle/extract.ts
+++ b/scripts/autosettle/extract.ts
@@ -3,13 +3,16 @@
33//
44// node scripts/autosettle/extract.ts <seat folder> <cases.json> [--since 8d]
55//
6−// Each settled collision gives: the file before theirs (their version - 1, the
7−// best guess at what both started from), theirs, and the settle's result.
8−// The held agent's own lines are only recoverable from the result when it kept
9−// yours or both; otherwise "yours" is null and score.ts skips the case.
6+// For each settle: the file before theirs (their version - 1, the best guess at
7+// what both started from), theirs, and the settle's result. git's line diff
8+// finds each of their hunks that the settler's change touched. The held agent's
9+// own lines are only recoverable from the result when it kept yours or both;
10+// otherwise "yours" is null and score.ts skips the case.
1011
1112import { execFileSync } from "node:child_process";
12−import { writeFileSync } from "node:fs";
13+import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
14+import { tmpdir } from "node:os";
15+import { join } from "node:path";
1316
1417const [seat, out] = process.argv.slice(2);
1518if (!seat || !out) {
@@ -35,15 +38,14 @@
3538 version: number;
3639 held?: string;
3740}
38−const review = JSON.parse(abso("review", "--since", since, "--json")) as {
39− changes: {
40− agent?: string;
41− author?: string;
42− message?: string;
43− settled: Settled[];
44− versions?: { version: number; message: string }[];
45− }[];
46−};
41+interface Change {
42+ agent?: string;
43+ author?: string;
44+ message?: string;
45+ settled: Settled[];
46+ versions?: { version: number; message: string }[];
47+}
48+const review = JSON.parse(abso("review", "--since", since, "--json")) as { changes: Change[] };
4749const messages = new Map<number, string>();
4850for (const c of review.changes) for (const v of c.versions ?? []) messages.set(v.version, v.message);
4951const messageOf = (v: number): string | undefined => {
@@ -58,59 +60,115 @@
5860 return messages.get(v);
5961};
6062
61−/** The span where `a` and `b` differ, by common prefix and suffix. */
62−function hunk(a: string[], b: string[]): { start: number; aEnd: number; bEnd: number } {
63− let start = 0;
64− while (start < a.length && start < b.length && a[start] === b[start]) start++;
65− let tail = 0;
66− while (tail < a.length - start && tail < b.length - start && a[a.length - 1 - tail] === b[b.length - 1 - tail])
67− tail++;
68− return { start, aEnd: a.length - tail, bEnd: b.length - tail };
63+interface Hunk {
64+ /** 0-based start and length on each side; a length of 0 is an insertion before (or deletion at) start. */
65+ aStart: number;
66+ aLen: number;
67+ bStart: number;
68+ bLen: number;
6969}
7070
71−/** The lines of `r` between the context above and below a hunk of `t`, found by a few anchor lines. */
72−function regionIn(r: string[], t: string[], start: number, end: number): string[] | null {
73− const above = t.slice(Math.max(0, start - 3), start);
74− const below = t.slice(end, end + 3);
75− const find = (needle: string[], from: number) => {
76− if (needle.length === 0) return -1;
77− for (let i = from; i + needle.length <= r.length; i++) if (needle.every((l, j) => r[i + j] === l)) return i;
78− return -2;
79− };
80− const a = find(above, 0);
81− const from = above.length === 0 ? 0 : a < 0 ? -1 : a + above.length;
82− if (from < 0) return null;
83− const b = find(below, from);
84− const to = below.length === 0 ? r.length : b < 0 ? -1 : b;
85− return to < 0 ? null : r.slice(from, to);
71+/** Line hunks from a to b, by git's diff. */
72+function hunks(a: string[], b: string[]): Hunk[] {
73+ const dir = mkdtempSync(join(tmpdir(), "autosettle-"));
74+ writeFileSync(join(dir, "a"), a.join("\n"));
75+ writeFileSync(join(dir, "b"), b.join("\n"));
76+ let text = "";
77+ try {
78+ text = execFileSync("git", ["diff", "--no-index", "-U0", "--no-color", join(dir, "a"), join(dir, "b")], {
79+ encoding: "utf8",
80+ maxBuffer: 1 << 28,
81+ });
82+ } catch (e) {
83+ // git diff --no-index exits 1 when the files differ.
84+ text = (e as { stdout?: string }).stdout ?? "";
85+ }
86+ rmSync(dir, { recursive: true, force: true });
87+ const list: Hunk[] = [];
88+ for (const m of text.matchAll(/^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/gm)) {
89+ const aLen = m[2] === undefined ? 1 : Number(m[2]);
90+ const bLen = m[4] === undefined ? 1 : Number(m[4]);
91+ list.push({
92+ aStart: aLen === 0 ? Number(m[1]) : Number(m[1]) - 1,
93+ aLen,
94+ bStart: bLen === 0 ? Number(m[3]) : Number(m[3]) - 1,
95+ bLen,
96+ });
97+ }
98+ return list;
8699}
87100
101+/** Where a line of b sits in a, given the hunks from a to b. */
102+const backTo = (hs: Hunk[], bAt: number) =>
103+ hs
104+ .filter((h) => h.bStart + h.bLen <= bAt && !(h.bLen === 0 && h.bStart === bAt))
105+ .reduce((n, h) => n - (h.bLen - h.aLen), bAt);
107+/**
108+ * The collisions a settle went through in one file: each of their hunks (before to theirs) that the
109+ * settler's own change (theirs to result) touches, with the lines on every side.
110+ */
111+function regions(before: string[], theirs: string[], result: string[]) {
112+ const d1 = hunks(before, theirs);
113+ const d2 = hunks(theirs, result);
114+ const touches = (h: Hunk, g: Hunk) => g.aStart <= h.bStart + h.bLen && h.bStart <= g.aStart + g.aLen;
115+ const found = [];
116+ for (const h of d1) {
117+ const near = d2.filter((g) => touches(h, g));
118+ if (near.length === 0) continue;
119+ const tStart = Math.min(h.bStart, ...near.map((g) => g.aStart));
120+ const tEnd = Math.max(h.bStart + h.bLen, ...near.map((g) => g.aStart + g.aLen));
121+ const rStart = d2
122+ .filter((g) => g.aStart + g.aLen <= tStart && !near.includes(g))
123+ .reduce((n, g) => n + (g.bLen - g.aLen), tStart);
124+ const rEnd = rStart + (tEnd - tStart) + near.reduce((n, g) => n + (g.bLen - g.aLen), 0);
125+ const bStart = backTo(d1, tStart);
126+ const bEnd = bStart + (tEnd - tStart) - (h.bLen - h.aLen);
127+ found.push({
128+ base: before.slice(bStart, bEnd),
129+ theirs: theirs.slice(tStart, tEnd),
130+ result: result.slice(rStart, rEnd),
131+ context: { before: theirs.slice(Math.max(0, tStart - 15), tStart), after: theirs.slice(tEnd, tEnd + 15) },
132+ });
133+ }
134+ return found;
135+}
88137const cases: { kept: string; yours: string[] | null }[] = [];
89−for (const c of review.changes) {
138+const groups = new Map<string, { change: Change; settled: Settled[] }>();
139+for (const c of review.changes)
90140 for (const s of c.settled) {
91− const before = fileAt(s.theirs.version - 1, s.file);
92− const theirs = fileAt(s.theirs.version, s.file);
93− const result = fileAt(s.version, s.file);
141+ const key = `${s.version} ${s.file}`;
142+ const g = groups.get(key) ?? { change: c, settled: [] };
143+ g.settled.push(s);
144+ groups.set(key, g);
145+ }
146+for (const { change: c, settled } of groups.values()) {
147+ const first = settled[0]!;
148+ const before = fileAt(first.theirs.version - 1, first.file);
149+ const theirs = fileAt(first.theirs.version, first.file);
150+ const result = fileAt(first.version, first.file);
151+ const found = before && theirs && result ? regions(before, theirs, result) : [];
152+ // Marker blocks the settler changed, in file order; a block where it kept theirs left no trace to find.
153+ const changed = settled.filter((s) => s.kept !== "theirs");
154+ settled.forEach((s, i) => {
94155 const notes: string[] = [];
95− let base: string[] | null = null;
96− let theirsLines: string[] | null = null;
97− let region: string[] | null = null;
98− let context = { before: [] as string[], after: [] as string[] };
99− if (before && theirs && result) {
100− const h = hunk(before, theirs);
101− base = before.slice(h.start, h.aEnd);
102− theirsLines = theirs.slice(h.start, h.bEnd);
103− context = { before: theirs.slice(Math.max(0, h.start - 15), h.start), after: theirs.slice(h.bEnd, h.bEnd + 15) };
104− region = regionIn(result, theirs, h.start, h.bEnd);
105− if (region === null) notes.push("couldn't find the region in the settled file");
106− if (theirsLines.length > 80) notes.push(`their change spans ${theirsLines.length} lines`);
107− } else notes.push("a version of the file couldn't be read");
156+ const r = s.kept === "theirs" ? undefined : found[changed.indexOf(s)];
157+ if (!before || !theirs || !result) notes.push("a version of the file couldn't be read");
158+ else if (s.kept === "theirs")
159+ notes.push("kept theirs: the region and yours aren't recoverable from versions alone");
160+ else if (!r) notes.push(`found ${found.length} changed regions for ${changed.length} settled blocks`);
161+ if (r && found.length !== changed.length)
162+ notes.push(`found ${found.length} changed regions for ${changed.length} settled blocks: the pairing may be off`);
108163 let yours: string[] | null = null;
109− if (region && s.kept === "yours") yours = region;
110− else if (region && theirsLines && s.kept === "both") yours = region.slice(0, region.length - theirsLines.length);
111− else notes.push(`yours isn't recoverable from the result when the agent kept ${s.kept}`);
164+ if (r && s.kept === "yours") yours = r.result;
165+ else if (r && s.kept === "both") {
166+ const tail = r.result.slice(r.result.length - r.theirs.length);
167+ if (tail.join("\n") === r.theirs.join("\n")) yours = r.result.slice(0, r.result.length - r.theirs.length);
168+ else notes.push("kept both, but the result doesn't end with theirs");
169+ } else if (r) notes.push(`yours isn't recoverable from the result when the agent kept ${s.kept}`);
112170 cases.push({
113− id: `${s.version}-${s.file}`,
171+ id: `${s.version}-${s.file}#${i + 1}`,
114172 file: s.file,
115173 kind: "lines",
116174 settler: {
@@ -120,16 +178,16 @@
120178 settleMessage: messageOf(s.version),
121179 },
122180 theirs: { agent: s.theirs.agent, version: s.theirs.version, message: messageOf(s.theirs.version) },
123− base,
181+ base: r?.base ?? null,
124182 yours,
125− theirsLines,
126− context,
127− result: region,
183+ theirsLines: r?.theirs ?? null,
184+ context: r?.context ?? { before: [], after: [] },
185+ result: r?.result ?? null,
128186 kept: s.kept,
129187 issue: null,
130188 notes: notes.join("; "),
131− });
132− }
189+ } as (typeof cases)[number]);
190+ });
133191}
134192writeFileSync(out, JSON.stringify(cases, null, "\t"));
135193const count = (k: string) => cases.filter((c) => c.kept === k).length;
--- a/scripts/autosettle/rules.ts
+++ b/scripts/autosettle/rules.ts
@@ -31,5 +31,15 @@
3131 const clash = solid(h.yours)
3232 .map(key)
3333 .find((k) => k && theirKeys.has(k));
34− return clash ? `keeping both would set ${clash} twice` : undefined;
34+ if (clash) return `keeping both would set ${clash} twice`;
35+ // Two versions of one statement, such as an import from the same module with a different list of names:
36+ // most of the names on one side are on the other too.
37+ const names = (lines: readonly string[]) => new Set(lines.join(" ").match(/[A-Za-z_$][\w$]{2,}/g) ?? []);
38+ const a = names(h.yours);
39+ const b = names(h.theirs);
40+ const shared = [...a].filter((n) => b.has(n)).length;
41+ const share = shared / Math.max(1, Math.min(a.size, b.size));
42+ return share >= 0.5
43+ ? `keeping both would repeat one statement in two versions (${shared} names on both sides)`
44+ : undefined;
3545}