{"version":138,"agent":"codex-capacity-chair","message":"Find reason-warning neighbors without materializing file history","time":1791844690202,"timeIso":"2026-10-12T22:38:10.202Z","changes":3,"change":1284,"files":["src/engine/conflicts.ts","src/engine/test/visible-neighbours.test.ts","src/engine/view.ts"],"draft":null,"diff":[{"path":"src/engine/conflicts.ts","added":1,"removed":17,"diff":"--- a/src/engine/conflicts.ts\n+++ b/src/engine/conflicts.ts\n@@ -207,23 +207,7 @@\n function visibleNeighbours(view: View, graph: Graph, line: LineId): LineId[] {\n \tconst info = graph.line(line);\n \tif (!info) return [];\n-\tconst sequence = view.sequence(info.file);\n-\tconst at = view.sequenceIndex(info.file, line);\n-\tif (at < 0) return [];\n-\tconst out: LineId[] = [];\n-\tfor (let i = at - 1; i >= 0; i--) {\n-\t\tif (sequence[i]!.visible) {\n-\t\t\tout.push(sequence[i]!.id);\n-\t\t\tbreak;\n-\t\t}\n-\t}\n-\tfor (let i = at + 1; i < sequence.length; i++) {\n-\t\tif (sequence[i]!.visible) {\n-\t\t\tout.push(sequence[i]!.id);\n-\t\t\tbreak;\n-\t\t}\n-\t}\n-\treturn out;\n+\treturn view.visibleNeighbours(info.file, line);\n }\n \n /**"},{"path":"src/engine/test/visible-neighbours.test.ts","added":54,"removed":0,"diff":"--- /dev/null\n+++ b/src/engine/test/visible-neighbours.test.ts\n@@ -0,0 +1,54 @@\n+import assert from \"node:assert/strict\";\n+import { test } from \"node:test\";\n+import { Graph } from \"../graph.ts\";\n+import { CachedStateStorage, StableOverlaySet } from \"../state-source.ts\";\n+import { View } from \"../view.ts\";\n+import { Repo } from \"./helpers.ts\";\n+import { SqlState } from \"./storage-helper.ts\";\n+\n+test(\"visible neighbours match historical sequence without retaining it, including moves and tombstones\", (t) => {\n+\tconst source = new SqlState();\n+\ttry {\n+\t\tconst original = Array.from({ length: 256 }, (_, n) => `line ${n}\\n`).join(\"\");\n+\t\tconst repo = Repo.init({ \"a.txt\": original, \"b.txt\": \"other\\n\" });\n+\t\tconst sets = [new Set(repo.shared)];\n+\t\tconst deletion = repo.draft({ edits: [{ file: \"a.txt\", old: original, new: \"line 0\\nline 255\\n\" }] });\n+\t\trepo.graph.add(deletion);\n+\t\trepo.shared.add(deletion.id);\n+\t\tsets.push(new Set(repo.shared));\n+\t\tconst move = repo.draft({ move: { file: \"a.txt\", start: 0, end: 1, to: \"b.txt\", at: 0 } });\n+\t\trepo.graph.add(move);\n+\t\trepo.shared.add(move.id);\n+\t\tsets.push(new Set(repo.shared));\n+\t\tconst graph = new Graph({ storage: new CachedStateStorage(source) });\n+\t\tfor (const id of repo.shared) graph.add(repo.graph.atom(id));\n+\t\tconst rows = source.db.prepare(\"SELECT count(*) AS n FROM state\").get()!.n;\n+\t\tfor (const set of sets) {\n+\t\t\tconst actual = new View(graph, new StableOverlaySet(set));\n+\t\t\tconst expected = new View(repo.graph, set);\n+\t\t\tconst weight = actual.weight();\n+\t\t\tt.mock.method(actual, \"sequence\", () => {\n+\t\t\t\tthrow new Error(\"historical sequence forbidden\");\n+\t\t\t});\n+\t\t\tt.mock.method(actual, \"sequenceIndex\", () => {\n+\t\t\t\tthrow new Error(\"historical position index forbidden\");\n+\t\t\t});\n+\t\t\tfor (const path of [\"a.txt\", \"b.txt\", \"missing.txt\"]) {\n+\t\t\t\tconst sequence = expected.sequence(path);\n+\t\t\t\tfor (const line of [\"a0.0\", \"a0.127\", \"a0.255\", \"a0.256\", \"a999.0\"]) {\n+\t\t\t\t\tconst at = sequence.findIndex((item) => item.id === line);\n+\t\t\t\t\tconst before = at < 0 ? undefined : sequence.slice(0, at).findLast((item) => item.visible)?.id;\n+\t\t\t\t\tconst after = at < 0 ? undefined : sequence.slice(at + 1).find((item) => item.visible)?.id;\n+\t\t\t\t\tassert.deepEqual(\n+\t\t\t\t\t\tactual.visibleNeighbours(path, line),\n+\t\t\t\t\t\t[before, after].filter((id) => id !== undefined),\n+\t\t\t\t\t);\n+\t\t\t\t}\n+\t\t\t}\n+\t\t\tassert.equal(actual.weight(), weight, \"neighbour lookup retains no file/history projection\");\n+\t\t\tassert.equal(source.db.prepare(\"SELECT count(*) AS n FROM state\").get()!.n, rows);\n+\t\t}\n+\t} finally {\n+\t\tsource.db.close();\n+\t}\n+});"},{"path":"src/engine/view.ts","added":34,"removed":0,"diff":"--- a/src/engine/view.ts\n+++ b/src/engine/view.ts\n@@ -561,6 +561,40 @@\n \t\treturn out;\n \t}\n \n+\t/** Two visible neighbours without retaining the file's historical sequence. */\n+\tvisibleNeighbours(path: string, line: LineId): LineId[] {\n+\t\tconst graph = this.graph;\n+\t\tconst target = graph.lineN(line);\n+\t\tconst start = graph.startCodeOf(path);\n+\t\tif (target < 0 || start === undefined) return [];\n+\t\tconst scan = (nodes: Iterable<number>): LineId[] => {\n+\t\t\tlet previous: LineId | undefined;\n+\t\t\tlet found = false;\n+\t\t\tfor (const n of nodes) {\n+\t\t\t\tif (n === target) {\n+\t\t\t\t\tfound = true;\n+\t\t\t\t\tcontinue;\n+\t\t\t\t}\n+\t\t\t\tlet deleted = false;\n+\t\t\t\tfor (const seq of graph.eachDeleterSeqOf(n))\n+\t\t\t\t\tif (this.#has(seq)) {\n+\t\t\t\t\t\tdeleted = true;\n+\t\t\t\t\t\tbreak;\n+\t\t\t\t\t}\n+\t\t\t\tif (deleted) continue;\n+\t\t\t\tconst id = graph.lineIdOf(n);\n+\t\t\t\tif (found) return previous === undefined ? [id] : [previous, id];\n+\t\t\t\tprevious = id;\n+\t\t\t}\n+\t\t\treturn found && previous !== undefined ? [previous] : [];\n+\t\t};\n+\t\tif (this.#hasMoves && graph.hasOrderedChildren)\n+\t\t\treturn graph.withProjectionScratch((scratch) =>\n+\t\t\t\tscan(scratchLayoutNodes(graph, (id) => this.#has(graph.atom(id).seq), scratch, graph.nodeOf(start))),\n+\t\t\t);\n+\t\treturn scan(this.#layoutNodes(start));\n+\t}\n+\n \t/** Index of a line in `sequence(path)`, or -1. */\n \tsequenceIndex(path: string, line: LineId): number {\n \t\tconst f = this.#file(path, true);"}],"ci":null}