- MCP
- blame on this site's /mcp
- CLI
- abso blame scripts/autosettle/replay.ts --json
- JSON
- /christopher/abso-core/blame/scripts/autosettle/replay.ts?format=json
221 linesautosettle 100%Last change autosettle in version 199,
221 lines from 3 changes in 2 versions.
autosettle197Auto-settle (#19): replay.ts recovers each past hold's lines from a project's raw log (the owner-only export): the held agent's draft edits up to its refused push, theirs' edits, and the groups that wrote the same lines, paired with the settle's blocks in file order. That recovers the held agent's side even when it kept theirs or edited by hand, which no version shows. Tried on a local hold where the agent kept theirs: before 100, yours 64, theirs 1000, all recovered.Compare1// Recover each past hold's lines from a project's raw log (#19): the held agent's own lines survive in its draft
2// entries even after it kept theirs or edited by hand, which no version shows.
3//
autosettle199Auto-settle (#19): replay.ts rebuilds a past hold's three files with the engine from a project's raw log (the held agent's base plus its draft at the refused push, its base, theirs' version) and cuts them with git merge-file --diff3, as a pull would. On project abso's log it recovers 33 of 35 settled blocks.Compare4// node --max-old-space-size=8192 scripts/autosettle/replay.ts <log.ndjson> <cases.json> <out.json>
autosettle197Auto-settle (#19): replay.ts recovers each past hold's lines from a project's raw log (the owner-only export): the held agent's draft edits up to its refused push, theirs' edits, and the groups that wrote the same lines, paired with the settle's blocks in file order. That recovers the held agent's side even when it kept theirs or edited by hand, which no version shows. Tried on a local hold where the agent kept theirs: before 100, yours 64, theirs 1000, all recovered.Compare5//
6// <log.ndjson> is GET /p/<project>/export (one raw log entry per line; owner-only). <cases.json> comes from
autosettle199Auto-settle (#19): replay.ts rebuilds a past hold's three files with the engine from a project's raw log (the held agent's base plus its draft at the refused push, its base, theirs' version) and cuts them with git merge-file --diff3, as a pull would. On project abso's log it recovers 33 of 35 settled blocks.Compare7// extract.ts, which says which settles to look for and what was kept. For each settle, the engine rebuilds three
8// files from the log: the held agent's at its refused push (its base plus its draft), its base, and theirs' version.
9// git merge-file --diff3 cuts them into blocks as a pull would, and the blocks pair with the settle's in order.
autosettle197Auto-settle (#19): replay.ts recovers each past hold's lines from a project's raw log (the owner-only export): the held agent's draft edits up to its refused push, theirs' edits, and the groups that wrote the same lines, paired with the settle's blocks in file order. That recovers the held agent's side even when it kept theirs or edited by hand, which no version shows. Tried on a local hold where the agent kept theirs: before 100, yours 64, theirs 1000, all recovered.Compare10
11import { execFileSync } from "node:child_process";
autosettle199Auto-settle (#19): replay.ts rebuilds a past hold's three files with the engine from a project's raw log (the held agent's base plus its draft at the refused push, its base, theirs' version) and cuts them with git merge-file --diff3, as a pull would. On project abso's log it recovers 33 of 35 settled blocks.Compare12import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
13import { tmpdir } from "node:os";
14import { join } from "node:path";
15import { Graph } from "../../src/engine/graph.ts";
16import type { Atom } from "../../src/engine/types.ts";
17import { View } from "../../src/engine/view.ts";
autosettle197Auto-settle (#19): replay.ts recovers each past hold's lines from a project's raw log (the owner-only export): the held agent's draft edits up to its refused push, theirs' edits, and the groups that wrote the same lines, paired with the settle's blocks in file order. That recovers the held agent's side even when it kept theirs or edited by hand, which no version shows. Tried on a local hold where the agent kept theirs: before 100, yours 64, theirs 1000, all recovered.Compare18
19type Entry = {
20 type: string;
21 agent?: string;
autosettle199Auto-settle (#19): replay.ts rebuilds a past hold's three files with the engine from a project's raw log (the held agent's base plus its draft at the refused push, its base, theirs' version) and cuts them with git merge-file --diff3, as a pull would. On project abso's log it recovers 33 of 35 settled blocks.Compare22 space?: string | null;
autosettle197Auto-settle (#19): replay.ts recovers each past hold's lines from a project's raw log (the owner-only export): the held agent's draft edits up to its refused push, theirs' edits, and the groups that wrote the same lines, paired with the settle's blocks in file order. That recovers the held agent's side even when it kept theirs or edited by hand, which no version shows. Tried on a local hold where the agent kept theirs: before 100, yours 64, theirs 1000, all recovered.Compare23 version?: number;
24 time?: number;
25 atom?: Atom;
26 tie?: Atom;
autosettle199Auto-settle (#19): replay.ts rebuilds a past hold's three files with the engine from a project's raw log (the held agent's base plus its draft at the refused push, its base, theirs' version) and cuts them with git merge-file --diff3, as a pull would. On project abso's log it recovers 33 of 35 settled blocks.Compare27 atoms?: string[];
28 changes?: string[];
29 collisions?: { file: string }[];
30};
autosettle197Auto-settle (#19): replay.ts recovers each past hold's lines from a project's raw log (the owner-only export): the held agent's draft edits up to its refused push, theirs' edits, and the groups that wrote the same lines, paired with the settle's blocks in file order. That recovers the held agent's side even when it kept theirs or edited by hand, which no version shows. Tried on a local hold where the agent kept theirs: before 100, yours 64, theirs 1000, all recovered.Compare31interface Case {
32 id: string;
33 file: string;
34 settler: { agent: string; heldMessage?: string; settleVersion: number; settleMessage?: string };
35 theirs: { agent: string; version: number; message?: string };
36 kept: string;
37 [k: string]: unknown;
38}
autosettle199Auto-settle (#19): replay.ts rebuilds a past hold's three files with the engine from a project's raw log (the held agent's base plus its draft at the refused push, its base, theirs' version) and cuts them with git merge-file --diff3, as a pull would. On project abso's log it recovers 33 of 35 settled blocks.Compare40const [logPath, casesPath, out] = process.argv.slice(2);
41if (!logPath || !casesPath || !out) {
42 console.error(
43 "usage: node --max-old-space-size=8192 scripts/autosettle/replay.ts <log.ndjson> <cases.json> <out.json>",
44 );
autosettle197Auto-settle (#19): replay.ts recovers each past hold's lines from a project's raw log (the owner-only export): the held agent's draft edits up to its refused push, theirs' edits, and the groups that wrote the same lines, paired with the settle's blocks in file order. That recovers the held agent's side even when it kept theirs or edited by hand, which no version shows. Tried on a local hold where the agent kept theirs: before 100, yours 64, theirs 1000, all recovered.Compare45 process.exit(2);
46}
47const entries: Entry[] = readFileSync(logPath, "utf8")
48 .split("\n")
49 .filter((l) => l.trim() !== "")
50 .map((l) => JSON.parse(l) as Entry);
51const cases = JSON.parse(readFileSync(casesPath, "utf8")) as Case[];
autosettle199Auto-settle (#19): replay.ts rebuilds a past hold's three files with the engine from a project's raw log (the held agent's base plus its draft at the refused push, its base, theirs' version) and cuts them with git merge-file --diff3, as a pull would. On project abso's log it recovers 33 of 35 settled blocks.Compare53// Every atom into one graph, and shared's set after each version.
54const graph = new Graph();
55const added = (a: Atom | undefined) => {
56 if (a && !graph.has(a.id)) graph.add(a);
57};
58const sharedAt = new Map<number, Set<string>>();
59const versionAt = new Map<number, number>();
60let shared = new Set<string>();
autosettle197Auto-settle (#19): replay.ts recovers each past hold's lines from a project's raw log (the owner-only export): the held agent's draft edits up to its refused push, theirs' edits, and the groups that wrote the same lines, paired with the settle's blocks in file order. That recovers the held agent's side even when it kept theirs or edited by hand, which no version shows. Tried on a local hold where the agent kept theirs: before 100, yours 64, theirs 1000, all recovered.Compare61entries.forEach((e, i) => {
autosettle199Auto-settle (#19): replay.ts rebuilds a past hold's three files with the engine from a project's raw log (the held agent's base plus its draft at the refused push, its base, theirs' version) and cuts them with git merge-file --diff3, as a pull would. On project abso's log it recovers 33 of 35 settled blocks.Compare62 added(e.atom);
63 added(e.tie);
64 if (e.type === "init" && e.atom) {
65 shared.add(e.atom.id);
66 sharedAt.set(0, new Set(shared));
67 }
68 const intoShared = (e.type === "publish" && !e.space) || e.type === "land";
69 if (intoShared && typeof e.version === "number") {
70 shared = new Set(shared);
71 for (const id of e.changes ?? []) shared.add(id);
72 if (e.tie) shared.add(e.tie.id);
73 sharedAt.set(e.version, shared);
74 versionAt.set(e.version, i);
autosettle197Auto-settle (#19): replay.ts recovers each past hold's lines from a project's raw log (the owner-only export): the held agent's draft edits up to its refused push, theirs' edits, and the groups that wrote the same lines, paired with the settle's blocks in file order. That recovers the held agent's side even when it kept theirs or edited by hand, which no version shows. Tried on a local hold where the agent kept theirs: before 100, yours 64, theirs 1000, all recovered.Compare75 }
autosettle199Auto-settle (#19): replay.ts rebuilds a past hold's three files with the engine from a project's raw log (the held agent's base plus its draft at the refused push, its base, theirs' version) and cuts them with git merge-file --diff3, as a pull would. On project abso's log it recovers 33 of 35 settled blocks.Compare76});
77const textOf = (set: Set<string>, file: string): string[] => {
78 const view = new View(graph, set);
79 return view.hasFile(file) ? view.lines(file).map((l) => l.text) : [];
autosettle197Auto-settle (#19): replay.ts recovers each past hold's lines from a project's raw log (the owner-only export): the held agent's draft edits up to its refused push, theirs' edits, and the groups that wrote the same lines, paired with the settle's blocks in file order. That recovers the held agent's side even when it kept theirs or edited by hand, which no version shows. Tried on a local hold where the agent kept theirs: before 100, yours 64, theirs 1000, all recovered.Compare80};
autosettle199Auto-settle (#19): replay.ts rebuilds a past hold's three files with the engine from a project's raw log (the held agent's base plus its draft at the refused push, its base, theirs' version) and cuts them with git merge-file --diff3, as a pull would. On project abso's log it recovers 33 of 35 settled blocks.Compare82/** The agent's base version and its unpublished draft atoms just before log index `end`. */
83function draftBefore(agent: string, end: number): { base: number; draft: string[] } {
84 let base = 0;
autosettle197Auto-settle (#19): replay.ts recovers each past hold's lines from a project's raw log (the owner-only export): the held agent's draft edits up to its refused push, theirs' edits, and the groups that wrote the same lines, paired with the settle's blocks in file order. That recovers the held agent's side even when it kept theirs or edited by hand, which no version shows. Tried on a local hold where the agent kept theirs: before 100, yours 64, theirs 1000, all recovered.Compare85 let start = 0;
86 for (let i = end - 1; i >= 0; i--) {
87 const e = entries[i]!;
autosettle199Auto-settle (#19): replay.ts rebuilds a past hold's three files with the engine from a project's raw log (the held agent's base plus its draft at the refused push, its base, theirs' version) and cuts them with git merge-file --diff3, as a pull would. On project abso's log it recovers 33 of 35 settled blocks.Compare88 if (e.agent !== agent) continue;
89 if (base === 0 && (e.type === "sync" || e.type === "join") && typeof e.version === "number") base = e.version;
90 if ((e.type === "publish" && !e.space) || e.type === "land") {
91 if (base === 0 && typeof e.version === "number") base = e.version;
autosettle197Auto-settle (#19): replay.ts recovers each past hold's lines from a project's raw log (the owner-only export): the held agent's draft edits up to its refused push, theirs' edits, and the groups that wrote the same lines, paired with the settle's blocks in file order. That recovers the held agent's side even when it kept theirs or edited by hand, which no version shows. Tried on a local hold where the agent kept theirs: before 100, yours 64, theirs 1000, all recovered.Compare92 start = i + 1;
93 break;
94 }
95 }
autosettle199Auto-settle (#19): replay.ts rebuilds a past hold's three files with the engine from a project's raw log (the held agent's base plus its draft at the refused push, its base, theirs' version) and cuts them with git merge-file --diff3, as a pull would. On project abso's log it recovers 33 of 35 settled blocks.Compare96 const draft: string[] = [];
97 for (const e of entries.slice(start, end)) {
98 if (e.agent !== agent) continue;
99 if (e.type === "draft" && e.atom) draft.push(e.atom.id);
100 if (e.type === "discard")
101 for (const id of e.atoms ?? []) draft.splice(draft.indexOf(id), draft.includes(id) ? 1 : 0);
102 }
103 return { base, draft };
autosettle197Auto-settle (#19): replay.ts recovers each past hold's lines from a project's raw log (the owner-only export): the held agent's draft edits up to its refused push, theirs' edits, and the groups that wrote the same lines, paired with the settle's blocks in file order. That recovers the held agent's side even when it kept theirs or edited by hand, which no version shows. Tried on a local hold where the agent kept theirs: before 100, yours 64, theirs 1000, all recovered.Compare104}
autosettle199Auto-settle (#19): replay.ts rebuilds a past hold's three files with the engine from a project's raw log (the held agent's base plus its draft at the refused push, its base, theirs' version) and cuts them with git merge-file --diff3, as a pull would. On project abso's log it recovers 33 of 35 settled blocks.Compare106interface Block {
107 yours: string[];
108 base: string[];
109 theirs: string[];
110 /** Where the block starts in theirs. */
111 at: number;
112}
113/** git's three-way merge of the files, as marker blocks with each side's lines. */
114function blocks(yours: string[], base: string[], theirs: string[]): Block[] {
115 const dir = mkdtempSync(join(tmpdir(), "autosettle-"));
116 const path = (n: string) => join(dir, n);
117 writeFileSync(path("yours"), `${yours.join("\n")}\n`);
118 writeFileSync(path("base"), `${base.join("\n")}\n`);
119 writeFileSync(path("theirs"), `${theirs.join("\n")}\n`);
120 let merged = "";
autosettle197Auto-settle (#19): replay.ts recovers each past hold's lines from a project's raw log (the owner-only export): the held agent's draft edits up to its refused push, theirs' edits, and the groups that wrote the same lines, paired with the settle's blocks in file order. That recovers the held agent's side even when it kept theirs or edited by hand, which no version shows. Tried on a local hold where the agent kept theirs: before 100, yours 64, theirs 1000, all recovered.Compare121 try {
autosettle199Auto-settle (#19): replay.ts rebuilds a past hold's three files with the engine from a project's raw log (the held agent's base plus its draft at the refused push, its base, theirs' version) and cuts them with git merge-file --diff3, as a pull would. On project abso's log it recovers 33 of 35 settled blocks.Compare122 merged = execFileSync("git", ["merge-file", "-p", "--diff3", path("yours"), path("base"), path("theirs")], {
123 encoding: "utf8",
124 maxBuffer: 1 << 28,
125 });
126 } catch (e) {
127 // git merge-file exits with the number of conflicts.
128 merged = (e as { stdout?: string }).stdout ?? "";
129 }
130 rmSync(dir, { recursive: true, force: true });
131 const found: Block[] = [];
132 let side: "out" | "yours" | "base" | "theirs" = "out";
133 let cur: Block = { yours: [], base: [], theirs: [], at: 0 };
134 let theirsLine = 0;
135 for (const line of merged.split("\n")) {
136 if (line.startsWith("<<<<<<< ")) {
137 side = "yours";
138 cur = { yours: [], base: [], theirs: [], at: theirsLine };
139 } else if (side === "yours" && line.startsWith("||||||| ")) side = "base";
140 else if (side === "base" && line === "=======") side = "theirs";
141 else if (side === "theirs" && line.startsWith(">>>>>>> ")) {
142 found.push(cur);
143 side = "out";
144 } else if (side === "out") theirsLine++;
145 else {
146 cur[side].push(line);
147 if (side === "theirs") theirsLine++;
autosettle197Auto-settle (#19): replay.ts recovers each past hold's lines from a project's raw log (the owner-only export): the held agent's draft edits up to its refused push, theirs' edits, and the groups that wrote the same lines, paired with the settle's blocks in file order. That recovers the held agent's side even when it kept theirs or edited by hand, which no version shows. Tried on a local hold where the agent kept theirs: before 100, yours 64, theirs 1000, all recovered.Compare148 }
autosettle199Auto-settle (#19): replay.ts rebuilds a past hold's three files with the engine from a project's raw log (the held agent's base plus its draft at the refused push, its base, theirs' version) and cuts them with git merge-file --diff3, as a pull would. On project abso's log it recovers 33 of 35 settled blocks.Compare149 }
150 return found;
autosettle197Auto-settle (#19): replay.ts recovers each past hold's lines from a project's raw log (the owner-only export): the held agent's draft edits up to its refused push, theirs' edits, and the groups that wrote the same lines, paired with the settle's blocks in file order. That recovers the held agent's side even when it kept theirs or edited by hand, which no version shows. Tried on a local hold where the agent kept theirs: before 100, yours 64, theirs 1000, all recovered.Compare151}
153const results: unknown[] = [];
154const byGroup = new Map<string, Case[]>();
155for (const c of cases) {
156 const key = `${c.settler.settleVersion} ${c.file}`;
157 byGroup.set(key, [...(byGroup.get(key) ?? []), c]);
158}
159for (const group of byGroup.values()) {
160 const c0 = group[0]!;
autosettle199Auto-settle (#19): replay.ts rebuilds a past hold's three files with the engine from a project's raw log (the held agent's base plus its draft at the refused push, its base, theirs' version) and cuts them with git merge-file --diff3, as a pull would. On project abso's log it recovers 33 of 35 settled blocks.Compare161 const settleAt = versionAt.get(c0.settler.settleVersion);
162 const theirSet = sharedAt.get(c0.theirs.version);
163 if (settleAt === undefined || !theirSet) {
autosettle197Auto-settle (#19): replay.ts recovers each past hold's lines from a project's raw log (the owner-only export): the held agent's draft edits up to its refused push, theirs' edits, and the groups that wrote the same lines, paired with the settle's blocks in file order. That recovers the held agent's side even when it kept theirs or edited by hand, which no version shows. Tried on a local hold where the agent kept theirs: before 100, yours 64, theirs 1000, all recovered.Compare164 for (const c of group) results.push({ ...c, yours: null, notes: "the settle or theirs isn't in this log" });
165 continue;
166 }
167 const notes: string[] = [];
168 let refusedAt = -1;
169 for (let i = settleAt - 1; i >= 0; i--) {
170 const e = entries[i]!;
autosettle199Auto-settle (#19): replay.ts rebuilds a past hold's three files with the engine from a project's raw log (the held agent's base plus its draft at the refused push, its base, theirs' version) and cuts them with git merge-file --diff3, as a pull would. On project abso's log it recovers 33 of 35 settled blocks.Compare171 if (e.type === "refused" && e.agent === c0.settler.agent && (e.collisions ?? []).some((x) => x.file === c0.file)) {
172 refusedAt = i;
173 break;
174 }
175 }
176 // No refusal on record (older holds): the draft just before the agent's first pull past theirs.
177 let end = refusedAt;
178 if (end < 0) {
179 notes.push("no refused push on record; used the draft before the agent pulled theirs");
180 const theirsAt = versionAt.get(c0.theirs.version)!;
181 end = settleAt;
182 for (let i = theirsAt + 1; i < settleAt; i++) {
183 const e = entries[i]!;
184 if (e.agent === c0.settler.agent && e.type === "sync" && (e.version ?? 0) >= c0.theirs.version) {
185 end = i;
autosettle197Auto-settle (#19): replay.ts recovers each past hold's lines from a project's raw log (the owner-only export): the held agent's draft edits up to its refused push, theirs' edits, and the groups that wrote the same lines, paired with the settle's blocks in file order. That recovers the held agent's side even when it kept theirs or edited by hand, which no version shows. Tried on a local hold where the agent kept theirs: before 100, yours 64, theirs 1000, all recovered.Compare186 break;
187 }
188 }
189 }
autosettle199Auto-settle (#19): replay.ts rebuilds a past hold's three files with the engine from a project's raw log (the held agent's base plus its draft at the refused push, its base, theirs' version) and cuts them with git merge-file --diff3, as a pull would. On project abso's log it recovers 33 of 35 settled blocks.Compare190 const { base, draft } = draftBefore(c0.settler.agent, end);
191 const baseSet = sharedAt.get(base);
192 if (!baseSet) {
193 for (const c of group) results.push({ ...c, yours: null, notes: `no shared version ${base} in this log` });
194 continue;
autosettle197Auto-settle (#19): replay.ts recovers each past hold's lines from a project's raw log (the owner-only export): the held agent's draft edits up to its refused push, theirs' edits, and the groups that wrote the same lines, paired with the settle's blocks in file order. That recovers the held agent's side even when it kept theirs or edited by hand, which no version shows. Tried on a local hold where the agent kept theirs: before 100, yours 64, theirs 1000, all recovered.Compare195 }
autosettle199Auto-settle (#19): replay.ts rebuilds a past hold's three files with the engine from a project's raw log (the held agent's base plus its draft at the refused push, its base, theirs' version) and cuts them with git merge-file --diff3, as a pull would. On project abso's log it recovers 33 of 35 settled blocks.Compare196 const yoursText = textOf(new Set([...baseSet, ...draft]), c0.file);
197 const baseText = textOf(baseSet, c0.file);
198 const theirText = textOf(theirSet, c0.file);
199 const found = blocks(yoursText, baseText, theirText);
200 if (found.length !== group.length) notes.push(`git found ${found.length} blocks for ${group.length} settled`);
autosettle197Auto-settle (#19): replay.ts recovers each past hold's lines from a project's raw log (the owner-only export): the held agent's draft edits up to its refused push, theirs' edits, and the groups that wrote the same lines, paired with the settle's blocks in file order. That recovers the held agent's side even when it kept theirs or edited by hand, which no version shows. Tried on a local hold where the agent kept theirs: before 100, yours 64, theirs 1000, all recovered.Compare201 group.forEach((c, i) => {
autosettle199Auto-settle (#19): replay.ts rebuilds a past hold's three files with the engine from a project's raw log (the held agent's base plus its draft at the refused push, its base, theirs' version) and cuts them with git merge-file --diff3, as a pull would. On project abso's log it recovers 33 of 35 settled blocks.Compare202 const b = found.length === group.length ? found[i] : undefined;
autosettle197Auto-settle (#19): replay.ts recovers each past hold's lines from a project's raw log (the owner-only export): the held agent's draft edits up to its refused push, theirs' edits, and the groups that wrote the same lines, paired with the settle's blocks in file order. That recovers the held agent's side even when it kept theirs or edited by hand, which no version shows. Tried on a local hold where the agent kept theirs: before 100, yours 64, theirs 1000, all recovered.Compare203 results.push({
204 ...c,
autosettle199Auto-settle (#19): replay.ts rebuilds a past hold's three files with the engine from a project's raw log (the held agent's base plus its draft at the refused push, its base, theirs' version) and cuts them with git merge-file --diff3, as a pull would. On project abso's log it recovers 33 of 35 settled blocks.Compare205 base: b?.base ?? null,
206 yours: b?.yours ?? null,
207 theirsLines: b?.theirs ?? null,
208 context: b
209 ? {
210 before: theirText.slice(Math.max(0, b.at - 15), b.at),
211 after: theirText.slice(b.at + b.theirs.length, b.at + b.theirs.length + 15),
212 }
213 : { before: [], after: [] },
214 notes: [...notes, ...(b ? [] : ["blocks don't pair one to one, so none is used"])].join("; "),
autosettle197Auto-settle (#19): replay.ts recovers each past hold's lines from a project's raw log (the owner-only export): the held agent's draft edits up to its refused push, theirs' edits, and the groups that wrote the same lines, paired with the settle's blocks in file order. That recovers the held agent's side even when it kept theirs or edited by hand, which no version shows. Tried on a local hold where the agent kept theirs: before 100, yours 64, theirs 1000, all recovered.Compare215 recoveredBy: "replay",
216 });
217 });
218}
219writeFileSync(out, JSON.stringify(results, null, "\t"));
220const ok = results.filter((r) => (r as { yours: unknown }).yours !== null).length;
221console.log(`${results.length} settled blocks; ${ok} with both sides recovered from the log.`);