- MCP
- blame on this site's /mcp
- CLI
- abso blame scripts/autosettle/extract.ts --json
- JSON
- /christopher/abso-core/blame/scripts/autosettle/extract.ts?format=json
196 linesautosettle 100%Last change autosettle in version 195,
196 lines from 5 changes in 3 versions.
autosettle190Jev auto-settle (#19): extract.ts builds test cases from a project's past settles through a seat's own abso client (review --json, show <version>:<file>).Compare1// Build scored test cases from a project's past settles (#19), read through the
2// abso client in a seat folder joined to that project (a reader seat is enough).
3//
4// node scripts/autosettle/extract.ts <seat folder> <cases.json> [--since 8d]
5//
autosettle195Auto-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.Compare6// 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.
autosettle190Jev auto-settle (#19): extract.ts builds test cases from a project's past settles through a seat's own abso client (review --json, show <version>:<file>).Compare11
12import { execFileSync } from "node:child_process";
autosettle195Auto-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.Compare13import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
14import { tmpdir } from "node:os";
15import { join } from "node:path";
autosettle190Jev auto-settle (#19): extract.ts builds test cases from a project's past settles through a seat's own abso client (review --json, show <version>:<file>).Compare16
17const [seat, out] = process.argv.slice(2);
18if (!seat || !out) {
19 console.error("usage: node scripts/autosettle/extract.ts <seat folder> <cases.json> [--since 8d]");
20 process.exit(2);
21}
22const since = process.argv.includes("--since") ? process.argv[process.argv.indexOf("--since") + 1]! : "8d";
23const abso = (...args: string[]): string =>
24 execFileSync("abso", args, { cwd: seat, encoding: "utf8", maxBuffer: 1 << 28, shell: process.platform === "win32" });
26const fileAt = (version: number, file: string): string[] | null => {
27 try {
28 return abso("show", `${version}:${file}`).split(/\r?\n/);
29 } catch {
30 return null;
31 }
32};
34interface Settled {
35 file: string;
36 kept: "yours" | "theirs" | "both" | "rewrote";
37 theirs: { agent: string; version: number };
38 version: number;
39 held?: string;
40}
autosettle195Auto-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.Compare41interface Change {
42 agent?: string;
43 author?: string;
44 message?: string;
45 settled: Settled[];
46 versions?: { version: number; message: string }[];
47}
48const review = JSON.parse(abso("review", "--since", since, "--json")) as { changes: Change[] };
autosettle190Jev auto-settle (#19): extract.ts builds test cases from a project's past settles through a seat's own abso client (review --json, show <version>:<file>).Compare49const messages = new Map<number, string>();
50for (const c of review.changes) for (const v of c.versions ?? []) messages.set(v.version, v.message);
51const messageOf = (v: number): string | undefined => {
52 if (!messages.has(v)) {
53 try {
54 const head = abso("show", String(v)).split(/\r?\n/).slice(0, 6).join("\n");
55 messages.set(v, /"([^"]*)"/.exec(head)?.[1] ?? head.split("\n")[0]!);
56 } catch {
57 return undefined;
58 }
59 }
60 return messages.get(v);
61};
autosettle195Auto-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.Compare63interface 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;
autosettle190Jev auto-settle (#19): extract.ts builds test cases from a project's past settles through a seat's own abso client (review --json, show <version>:<file>).Compare69}
autosettle195Auto-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.Compare71/** Line hunks from a to b, by git's diff. */
72function 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;
autosettle190Jev auto-settle (#19): extract.ts builds test cases from a project's past settles through a seat's own abso client (review --json, show <version>:<file>).Compare99}
autosettle195Auto-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.Compare100
101/** Where a line of b sits in a, given the hunks from a to b. */
102const 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);
autosettle190Jev auto-settle (#19): extract.ts builds test cases from a project's past settles through a seat's own abso client (review --json, show <version>:<file>).Compare106
autosettle195Auto-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.Compare107/**
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 */
111function 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}
autosettle191Auto-settle (#19): a Workers AI settler. scripts/autosettle/workers-ai is a Worker (wrangler dev --port 8845) that asks Llama 3.3 70B, in JSON mode, for one of keep yours, keep theirs, keep both or needs an agent, plus a confidence and a one-line reason. settle-one and score use it by default (--via jev for Jev). On the commonmark hold (nesting 64 vs 1000) it picks needs an agent, 0.90, in 2.5 s.Compare137const cases: { kept: string; yours: string[] | null }[] = [];
autosettle195Auto-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.Compare138const groups = new Map<string, { change: Change; settled: Settled[] }>();
139for (const c of review.changes)
autosettle190Jev auto-settle (#19): extract.ts builds test cases from a project's past settles through a seat's own abso client (review --json, show <version>:<file>).Compare140 for (const s of c.settled) {
autosettle195Auto-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.Compare141 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 }
146for (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) => {
autosettle190Jev auto-settle (#19): extract.ts builds test cases from a project's past settles through a seat's own abso client (review --json, show <version>:<file>).Compare155 const notes: string[] = [];
autosettle195Auto-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.Compare156 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`);
autosettle190Jev auto-settle (#19): extract.ts builds test cases from a project's past settles through a seat's own abso client (review --json, show <version>:<file>).Compare163 let yours: string[] | null = null;
autosettle195Auto-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.Compare164 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}`);
autosettle190Jev auto-settle (#19): extract.ts builds test cases from a project's past settles through a seat's own abso client (review --json, show <version>:<file>).Compare170 cases.push({
autosettle195Auto-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.Compare171 id: `${s.version}-${s.file}#${i + 1}`,
autosettle190Jev auto-settle (#19): extract.ts builds test cases from a project's past settles through a seat's own abso client (review --json, show <version>:<file>).Compare172 file: s.file,
173 kind: "lines",
174 settler: {
175 agent: c.agent ?? c.author ?? "?",
176 heldMessage: s.held,
177 settleVersion: s.version,
178 settleMessage: messageOf(s.version),
179 },
180 theirs: { agent: s.theirs.agent, version: s.theirs.version, message: messageOf(s.theirs.version) },
autosettle195Auto-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.Compare181 base: r?.base ?? null,
autosettle190Jev auto-settle (#19): extract.ts builds test cases from a project's past settles through a seat's own abso client (review --json, show <version>:<file>).Compare182 yours,
autosettle195Auto-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.Compare183 theirsLines: r?.theirs ?? null,
184 context: r?.context ?? { before: [], after: [] },
185 result: r?.result ?? null,
autosettle190Jev auto-settle (#19): extract.ts builds test cases from a project's past settles through a seat's own abso client (review --json, show <version>:<file>).Compare186 kept: s.kept,
187 issue: null,
188 notes: notes.join("; "),
autosettle195Auto-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.Compare189 } as (typeof cases)[number]);
190 });
autosettle190Jev auto-settle (#19): extract.ts builds test cases from a project's past settles through a seat's own abso client (review --json, show <version>:<file>).Compare191}
192writeFileSync(out, JSON.stringify(cases, null, "\t"));
193const count = (k: string) => cases.filter((c) => c.kept === k).length;
194console.log(
195 `${cases.length} settled collisions: yours ${count("yours")}, theirs ${count("theirs")}, both ${count("both")}, rewrote ${count("rewrote")}; ${cases.filter((c) => c.yours !== null).length} with both sides recoverable.`,
196);