feat: add multi-run fusion and session change walkthroughs

Fuse two to five completed multi-run entries into one synthesized session,
and explain a session's diff as ordered walkthrough stops cached by diff hash.

- Multi-run fusion service, persistence, routes and FuseRunDialog
- Change walkthrough service, persistence, routes and ChangesWalkthroughDialog
- Shared unified-diff parser plus bounded text generation, json-extract,
  text-truncate and service-error helpers
This commit is contained in:
Chris Scott committed 2026-10-06 15:27:14 -04:00
1 parent 90c6ccf236
commit b36d412ca2
66 files changed
+6228 -468

No files matched your search

+117
View File
@@ -0,0 +1,117 @@
export interface DiffLine {
type: "add" | "remove" | "context" | "header" | "hunk";
content: string;
oldLineNumber?: number;
newLineNumber?: number;
}
export interface DiffHunk {
header: string;
text: string;
}
export function parseDiffLines(diff: string): DiffLine[] {
const lines = diff.split("\n");
const result: DiffLine[] = [];
let oldLine = 0;
let newLine = 0;
let oldRemaining = 0;
let newRemaining = 0;
let inHunk = false;
for (const line of lines) {
if (
line.startsWith("diff --git") ||
line.startsWith("index ") ||
line.startsWith("Index:") ||
line.startsWith("===")
) {
inHunk = false;
if (line.startsWith("diff --git") || line.startsWith("index ")) {
result.push({ type: "header", content: line });
}
continue;
}
if (line.startsWith("@@")) {
const match = line.match(/@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);
if (match) {
oldLine = parseInt(match[1]!, 10);
newLine = parseInt(match[3]!, 10);
oldRemaining = match[2] === undefined ? 1 : parseInt(match[2], 10);
newRemaining = match[4] === undefined ? 1 : parseInt(match[4], 10);
}
inHunk = true;
result.push({ type: "hunk", content: line });
continue;
}
if (!inHunk && (line.startsWith("---") || line.startsWith("+++"))) {
result.push({ type: "header", content: line });
continue;
}
if (line.startsWith("+")) {
result.push({
type: "add",
content: line.substring(1),
newLineNumber: newLine,
});
newLine++;
newRemaining--;
} else if (line.startsWith("-")) {
result.push({
type: "remove",
content: line.substring(1),
oldLineNumber: oldLine,
});
oldLine++;
oldRemaining--;
} else if (line.startsWith(" ") || line === "") {
result.push({
type: "context",
content: line.substring(1) || "",
oldLineNumber: oldLine,
newLineNumber: newLine,
});
oldLine++;
newLine++;
oldRemaining--;
newRemaining--;
} else {
continue;
}
if (inHunk && oldRemaining <= 0 && newRemaining <= 0) {
inHunk = false;
}
}
return result;
}
export function splitDiffHunks(patch: string): DiffHunk[] {
const hunks: DiffHunk[] = [];
let current: string[] | null = null;
for (const line of patch.split("\n")) {
if (line.startsWith("@@")) {
if (current) {
hunks.push(toHunk(current));
}
current = [line];
} else if (current) {
current.push(line);
}
}
if (current) {
hunks.push(toHunk(current));
}
return hunks;
}
function toHunk(lines: string[]): DiffHunk {
return { header: lines[0]!, text: lines.join("\n") };
}