16 files, 777 lines added, 24 removed.
--- a/client/README.md
+++ b/client/README.md
@@ -137,8 +137,8 @@
137137| `abso announce [--to a,b] <text>` | Tells the project's other agents (or those named) something. Each gets "Announcement from you (as claimed): ..." once, as news on their next edit, or within 30 seconds where the mod runs. | 138138| `abso news` | The news waiting for you (collisions, changed definitions, moved lines, announcements), each item once. | 139139| `abso where` | Who is working where: each file with unpushed changes, whose they are, and which lines. | 140−| `abso blame <file> [--from n] [--to n] [--version n]` | Who wrote each line of the file as shared has it (or had it at a version), and the push that brought it in. `--draft <name>` reads a named draft; `--mine` reads your own view and marks your unpushed lines with `*`. |
141−| `abso why <file>:<line>` | Why one line of shared is the way it is: its change, its push, its reasons, and any collision it settled. Takes `--draft` and `--mine` as blame does. |
140+| `abso blame <file> [--from n] [--to n] [--version n]` | Who wrote each line of the file as shared has it (or had it at a version), and the push that brought it in. A push imported from git names its commit and author. `--draft <name>` reads a named draft; `--mine` reads your own view and marks your unpushed lines with `*`. | 141+| `abso why <file>:<line> [--at n] [--all]` | Why one line of shared is the way it is: the newest change to what it does, its push, its reasons, and any collision it settled, then the line's earlier changes, newest first, with what it read before each. A change that only touched formatting (whitespace, line wrapping, quotes, trailing commas, line-end semicolons) is skipped, and why names it; `--all` shows those too. A line imported from git names its commit and author, and `#39` in it names the old repository's issue when the import recorded where those are, or when abso.json says so with `"gitIssues": "https://github.com/owner/repo/issues"`. `--at <version>` reads the line as it was at that version, as blame's `--version` does. Takes `--draft` and `--mine` as blame does. | 142142| `abso drop <version...> -m "why" [--with-dependents]` | Takes pushed versions back out of shared as a new version, like `git revert`; history keeps them. Refused (exit 2) when later versions build on them (`--with-dependents` drops those too) or when anyone's unpushed work builds on them. | 143143| `abso pluck <draft> <version...> -m "why" [--with-dependencies]` | Takes some versions of a named draft into shared as one version, like `git cherry-pick`. The draft stays as it is. | 144144| `abso amend -m "new message"` | Corrects the message of your newest push in this space. The log keeps the first message. | --- a/client/scripts/import-git.ts
+++ b/client/scripts/import-git.ts
@@ -2,7 +2,15 @@
22// first used for #56, abso hosts abso). Each commit on the first-parent line 33// of --ref becomes a version of shared, oldest first: the first by `avcs 44// init`, each later one by a publish of that commit's tree, with the commit's 5−// message and a last line naming the commit, its author and its time.
5+// message and a last line naming the commit, its author and its time. When 6+// the repository's issues are on the web (origin on GitHub or GitLab, or 7+// --issues <url>), a line after it says where, so "#39" in the message, or 8+// in the lines it wrote, names that tracker's issue, not the project's: 10+// git 4e1a7c2b9f03, Ada Lovelace, 2026-10-06T20:36:43-05:00 11+// Issues: https://github.com/owner/repo/issues 13+// abso why and abso blame read these lines (client/src/git-origin.ts). 614// --last-only imports the last commit alone. 816// Before anything is created, the last commit is checked: abso stores text @@ -14,7 +22,9 @@
1422// What a first cut leaves for later (#58): every version's agent is the 1523// importing agent and its time is the import's (the commit's author and time 1624// are in the message); merges come in as their first parent's line; a run 17−// that stops partway goes on with --after <sha> in the same --dir.
25+// that stops partway goes on with --after <sha> in the same --dir. Version 0 26+// is made by init, which says "Start the project", so the first commit's own 27+// message and hash aren't on it: they're printed when the import starts. 1929// CI counts each imported version as seen as soon as it lands, so it never 2030// checks or bisects the history; it checks what is published after the @@ -22,7 +32,7 @@
2333// node client/scripts/import-git.ts --project <name> [--ref origin/main] 2434// [--server <url>] [--agent import] [--dir <empty folder>] 25−// [--last-only] [--check-only] [--after <sha>]
35+// [--last-only] [--check-only] [--after <sha>] [--issues <url>] 2737import { spawnSync } from "node:child_process"; 2838import { existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync } from "node:fs"; @@ -31,6 +41,7 @@
3141import { parseArgs } from "node:util"; 3242import { open } from "../src/commands.ts"; 3343import { loadIgnore } from "../src/folder.ts"; 44+import { issuesOf } from "../src/git-origin.ts"; 3445import { main } from "../src/main.ts"; 3647const { values } = parseArgs({ @@ -43,6 +54,7 @@
4354 "last-only": { type: "boolean", default: false }, 4455 "check-only": { type: "boolean", default: false }, 4556 after: { type: "string" }, 57+ issues: { type: "string" }, 4860const checkOnly = values["check-only"] === true; @@ -94,12 +106,18 @@
109+// Where "#N" in the history points: --issues, else origin's issues on GitHub or GitLab. 110+if (values.issues !== undefined && !/^https?:\/\/\S+$/.test(values.issues)) 111+ fail(`--issues is a web address, like https://github.com/owner/repo/issues (got ${JSON.stringify(values.issues)})`); 112+const tracker = values.issues ?? issuesOf(origin()); 97114const env = { cwd: dir, env: process.env, write: () => {} }; 99116for (let i = start; i < line.length; i++) { 100117 const sha = line[i]!; 101118 extract(sha, dir); 102− const message = `${git(["log", "-1", "--format=%B", sha]).trim()}\n\ngit ${sha.slice(0, 12)}, ${git(["log", "-1", "--format=%an, %aI", sha]).trim()}`;
119+ const message = `${git(["log", "-1", "--format=%B", sha]).trim()}\n\ngit ${sha.slice(0, 12)}, ${git(["log", "-1", "--format=%an, %aI", sha]).trim()}${tracker ? `\nIssues: ${tracker}` : ""}`; 120+ if (i === 0) console.log(`Version 0 is commit ${sha.slice(0, 12)}: ${message.split("\n")[0]}`); 103121 const subject = message.split("\n")[0]!.slice(0, 72); 104122 // The first commit makes the project; --as-is adds no starting .absoignore or avcs.json git never had. @@ -179,6 +197,12 @@
200+/** origin's address, or "" when there's no origin. */ 201+function origin(): string { 202+ const r = spawnSync("git", ["remote", "get-url", "origin"], { encoding: "utf8" }); 203+ return r.status === 0 ? r.stdout.trim() : ""; 182206function fail(message: string): never { 183207 console.error(message); --- a/client/src/api.ts
+++ b/client/src/api.ts
@@ -925,8 +925,8 @@
925925 return this.json("POST", this.agentPath("restore"), files === null ? { all: true } : { files }); 928− why(file: string, line: number, view: View = {}): Promise<WhyAnswer> {
929− return this.json("GET", `/why?${query({ file, line, ...view })}`);
928+ why(file: string, line: number, view: View = {}, version?: number): Promise<WhyAnswer> { 929+ return this.json("GET", `/why?${query({ file, line, version, ...view })}`); 932932 where(): Promise<WhereAnswer> { --- /dev/null
+++ b/client/src/git-origin.ts
@@ -0,0 +1,90 @@
1+// Where a push came from in git, when it was imported (abso-core issue 21). 2+// A version imported by client/scripts/import-git.ts ends its message with 3+// a line naming the commit, its author and its time, and, when the 4+// repository's issues are on the web, a line saying where: 6+// git 4e1a7c2b9f03, Ada Lovelace, 2026-10-06T20:36:43-05:00 7+// Issues: https://github.com/owner/repo/issues 9+// A commit pushed with plain git ends with "Git-Commit: <sha>" and 10+// "Author: <name>". A host may also name the commit beside the version 11+// (`commit`). Issue references like "#39" in an imported message, or in a 12+// line it wrote, mean that repository's issues, not the project's. 14+export interface GitOrigin { 15+ readonly commit: string; 16+ readonly author?: string; 17+ readonly time?: string; 18+ /** The repository's issues, as a web address, when known. */ 19+ readonly issues?: string; 20+ /** The message with these lines taken off. */ 21+ readonly message: string; 24+const IMPORTED = /^git ([0-9a-f]{7,64}), (.+), (\d{4}-\d\d-\d\dT[^,\s]+)$/; 25+const ISSUES = /^Issues: (https?:\/\/\S+)$/; 26+const PUSHED = /^Git-Commit: ([0-9a-f]{7,64})$/; 27+const PUSHED_BY = /^Author: (.+)$/; 30+ * A push's git origin, from its message's last lines or the commit its host 31+ * names, or undefined when it didn't come from git. `issues` is where "#N" 32+ * points when the message doesn't say (the project's "gitIssues"). 34+export function gitOrigin( 35+ p: { readonly message: string; readonly commit?: string; readonly author?: string }, 37+): GitOrigin | undefined { 38+ const lines = p.message.trimEnd().split("\n"); 39+ let end = lines.length; 40+ let found: Omit<GitOrigin, "message"> | undefined; 41+ const tracker = ISSUES.exec(lines[end - 1] ?? ""); 43+ const imported = IMPORTED.exec(lines[end - 1] ?? ""); 46+ found = { commit: imported[1]!, author: imported[2]!, time: imported[3]! }; 48+ const by = PUSHED_BY.exec(lines[end - 1] ?? ""); 49+ const sha = PUSHED.exec(lines[end - (by ? 2 : 1)] ?? ""); 52+ found = { commit: sha[1]!, ...(by ? { author: by[1]! } : {}) }; 55+ if (!found && p.commit !== undefined) found = { commit: p.commit, ...(p.author ? { author: p.author } : {}) }; 56+ if (!found) return undefined; 57+ const where = tracker?.[1] ?? issues; 60+ ...(where ? { issues: where.replace(/\/+$/, "") } : {}), 61+ message: lines.slice(0, end).join("\n").trimEnd(), 65+/** A git remote's issues on the web: GitHub's or GitLab's, by https or ssh; else undefined. */ 66+export function issuesOf(remote: string): string | undefined { 70+ .replace(/\.git$/, ""); 71+ const m = /^(?:https:\/\/|ssh:\/\/git@|git@)(github\.com|gitlab\.com)[:/]([\w.-]+(?:\/[\w.-]+)+)$/.exec(plain); 72+ if (!m) return undefined; 73+ return m[1] === "gitlab.com" ? `https://gitlab.com/${m[2]}/-/issues` : `https://github.com/${m[2]}/issues`; 76+/** The issues "#N" names in text, each once, in order: not "owner/repo#N", which names its own. */ 77+export function issueNumbers(text: string): number[] { 78+ const out: number[] = []; 79+ for (const m of text.matchAll(/(^|[^\w/])#(\d+)\b/g)) { 80+ const n = Number(m[2]); 81+ if (!out.includes(n)) out.push(n); 86+/** One line per "#N" in text, saying which tracker it's in. Empty without a tracker or a reference. */ 87+export function issueLinks(text: string, issues: string | undefined): string[] { 88+ if (!issues) return []; 89+ return issueNumbers(text).map((n) => `#${n} is ${issues}/${n}`); --- a/client/src/history-answers.ts
+++ b/client/src/history-answers.ts
@@ -129,6 +129,8 @@
129129 readonly agent: string; 130130 /** Who first wrote it, when the project's history was imported (abso issue 23). */ 131131 readonly author?: string; 132+ /** The git commit it came from, when its host knows it. */ 133+ readonly commit?: string; 132134 readonly message: string; 133135 readonly time: number; @@ -157,10 +159,28 @@
157159 readonly publish: Publish | null; 162+/** One change in a line's past (abso-core issue 20): the line's text after it, and whether it only changed formatting. */ 163+export interface TrailStep { 164+ readonly atom: string; 165+ readonly author: string; 166+ readonly message: string; 167+ readonly time: number; 168+ readonly text: string; 169+ readonly formatting: boolean; 170+ readonly publish: Publish | null; 160172export interface WhyAnswer { 161173 readonly file: string; 162174 readonly line: number; 175+ /** The version read (null for an agent's view); absent from an older server. */ 176+ readonly version?: number | null; 163177 readonly text: string; 178+ /** Where "#N" in history imported from git points (abso.json's "gitIssues"). */ 179+ readonly gitIssues?: string; 180+ /** The line's changes, newest first, its own first; absent from an older server. */ 181+ readonly trail?: readonly TrailStep[]; 182+ /** The trail went back further than the server follows. */ 183+ readonly trailMore?: true; 164184 readonly change: { readonly atom: string; readonly author: string; readonly message: string; readonly time: number }; 165185 readonly publish: Publish | null; 166186 readonly reasons: readonly { --- a/client/src/history.ts
+++ b/client/src/history.ts
@@ -8,7 +8,8 @@
88import type { Env, Output } from "./commands.ts"; 99import { findRoot, readConfig } from "./config.ts"; 1010import { relativeTo } from "./folder.ts"; 11−import { byWhom } from "./history-answers.ts";
11+import { type GitOrigin, gitOrigin, issueLinks } from "./git-origin.ts"; 12+import { byWhom, type TrailStep } from "./history-answers.ts"; 1314function open(env: Env): { root: string; api: Api; agent: string } { 1415 const root = findRoot(env.cwd); @@ -50,6 +51,26 @@
5051 return p === null ? "not pushed" : `version ${p.version} by ${byWhom(p)} (${when(p.time)}): "${p.message}"`; 54+/** published, with an imported push's git lines taken off its message (gitLines says them). */ 55+function pushed(p: Publish | null, issues: string | undefined): string { 56+ const origin = p ? gitOrigin(p, issues) : undefined; 57+ return p && origin ? published({ ...p, message: origin.message }) : published(p); 60+function gitLines(o: GitOrigin): string[] { 61+ return [` From git: commit ${o.commit}${o.author ? ` by ${o.author}` : ""}${o.time ? `, ${o.time}` : ""}.`]; 64+/** A trail step in a few words: its version (or that it isn't pushed), who, and the first line of why. */ 65+function stepName(s: TrailStep, long = false): string { 66+ const subject = (s.publish ? (gitOrigin(s.publish)?.message ?? s.publish.message) : s.message).split("\n")[0]!; 67+ const where = s.publish === null ? "not pushed" : `version ${s.publish.version}`; 68+ const who = s.publish ? byWhom(s.publish) : s.author; 70+ ? `${where} by ${who} (${when(s.publish?.time ?? s.time)}): "${subject}"` 71+ : `${where} (${who}, "${subject}")`; 5374export async function runBlame(args: Parsed, env: Env): Promise<Output> { 5475 if (args.positionals.length !== 1) 5576 throw new UsageError("blame takes one file: abso blame <file> [--from <n>] [--to <n>]"); @@ -72,7 +93,11 @@
7293 for (const a of b.atoms) { 7394 if (a.publish === null) continue; 7495 const own = a.message && a.message !== a.publish.message ? ` (the change itself: "${a.message}")` : ""; 75− const line = ` v${a.publish.version} by ${byWhom(a.publish)}, ${when(a.publish.time)}: ${a.publish.message}${own}`;
96+ const origin = gitOrigin(a.publish); 97+ const message = origin 98+ ? `${origin.message.split("\n")[0]} (from git commit ${origin.commit.slice(0, 12)}${origin.author ? ` by ${origin.author}` : ""})` 100+ const line = ` v${a.publish.version} by ${byWhom(a.publish)}, ${when(a.publish.time)}: ${message}${own}`; 76101 if (!versions.has(a.publish.version) || own) versions.set(a.publish.version, line); @@ -112,11 +137,54 @@
112137 throw new UsageError("why takes a file and a line: abso why <file>:<line>"); 113138 const { root, api, agent } = open(env); 114139 const file = fileArg(root, env.cwd, typed); 115− const w = await api.why(file, lineNumber(raw, "the line")!, viewOf(args, agent));
140+ const rawAt = str(args, "at"); 141+ if (rawAt !== undefined && !/^\d+$/.test(rawAt)) 142+ throw new UsageError(`--at is a version number (got ${JSON.stringify(rawAt)})`); 143+ const at = rawAt === undefined ? undefined : Number(rawAt); 144+ const view = viewOf(args, agent); 145+ if (at !== undefined && "agent" in view) 146+ throw new UsageError("--mine reads your view as it is now; it takes no --at"); 147+ const w = await api.why(file, lineNumber(raw, "the line")!, view, at); 148+ if (at !== undefined && w.version !== at) 149+ throw new UsageError(`this server doesn't read why at a version yet; abso blame ${w.file} --version ${at} does`); 150+ // The line's changes (abso-core issue 20): the newest one that changed what it does leads, past formatting-only ones. 151+ const all = bool(args, "all"); 152+ const trail = w.trail ?? []; 153+ const lead = (all ? trail[0] : trail.find((s) => !s.formatting)) ?? trail[0]; 154+ const leadAt = lead === undefined ? 0 : trail.indexOf(lead); 155+ const skipped = trail.slice(0, leadAt); 156+ const earlier = trail.slice(leadAt + 1).filter((s) => all || !s.formatting); 157+ const origin = lead?.publish ? gitOrigin(lead.publish, w.gitIssues) : undefined; 117− `${w.file} line ${w.line}: ${w.text}`,
118− `Written by ${w.change.author} (${when(w.change.time)}), pushed in ${published(w.publish)}.`,
119− ...(w.change.message ? [`The change says: "${w.change.message}"`] : []),
159+ `${w.file} line ${w.line}${at !== undefined ? ` at version ${at}` : ""}: ${w.text}`, 160+ ...(lead === undefined || leadAt === 0 161+ ? [`Written by ${w.change.author} (${when(w.change.time)}), pushed in ${pushed(w.publish, w.gitIssues)}.`] 163+ `Written by ${lead.author} (${when(lead.time)}), pushed in ${pushed(lead.publish, w.gitIssues)}.`, 164+ ` It read: ${lead.text.trim()}`, 166+ ...(origin ? gitLines(origin) : []), 167+ ...issueLinks(`${w.text}\n${origin?.message ?? ""}`, origin?.issues).map((l) => ` ${l}`), 168+ ...(skipped.length > 0 170+ `Skipped ${skipped.length} formatting change${skipped.length === 1 ? "" : "s"} since: ${skipped.map((s) => stepName(s)).join("; ")}. abso why --all shows ${skipped.length === 1 ? "it" : "them"}.`, 173+ ...(earlier.length > 0 175+ "Earlier changes, newest first:", 176+ ...earlier.flatMap((s, i) => { 177+ const newer = i === 0 ? lead! : earlier[i - 1]!; 178+ const o = s.publish ? gitOrigin(s.publish, w.gitIssues) : undefined; 180+ ` ${stepName(s, true)}${s.formatting ? " (formatting only)" : ""}${o ? `, from git commit ${o.commit.slice(0, 12)}${o.author ? ` by ${o.author}` : ""}` : ""}`, 181+ ...(s.text !== newer.text ? [` It read: ${s.text.trim()}`] : []), 186+ ...(w.trailMore ? [" (it goes back further than why follows)"] : []), 187+ ...(w.change.message && leadAt === 0 ? [`The change says: "${w.change.message}"`] : []), 120188 ...(w.settled.length > 0 --- a/client/src/main.ts
+++ b/client/src/main.ts
@@ -732,10 +732,10 @@
735− flags: { draft: "string", mine: "boolean" },
736− usage: "abso why <file>:<line> [--draft <name> | --mine]",
735+ flags: { draft: "string", mine: "boolean", at: "string", all: "boolean" }, 736+ usage: "abso why <file>:<line> [--at <version>] [--all] [--draft <name> | --mine]", 738− "Why one line of shared (or of a named draft, or your own view) is the way it is: its change, its push, its reasons, and any collision it settled.",
738+ "Why one line of shared (or of a named draft, or your own view) is the way it is: the newest change to what it does, its push, its reasons, any collision it settled, and the line's earlier changes, newest first. Changes that only touched formatting (whitespace, line wrapping, quotes, trailing commas) are skipped, and why says which; --all shows them too. A line imported from git names its commit, and #N in it names the old repository's issue when abso.json's \"gitIssues\" says where those are. --at <version> reads the line as shared (or the draft) had it then, as blame --version does.", --- a/client/test/fake-server.ts
+++ b/client/test/fake-server.ts
@@ -434,7 +434,7 @@
434434 return send(res, 200, blame(hosted.project, q.file, num(q.from), num(q.to), num(q.version), view)); 435435 const line = num(q.line); 436436 if (!line || !Number.isInteger(line)) return send(res, 400, { error: "why needs ?line=<number>" }); 437− return send(res, 200, why(hosted.project, q.file, line, view));
437+ return send(res, 200, why(hosted.project, q.file, line, { ...view, version: num(q.version) })); 439439 const code = (e as { code?: string }).code; 440440 return send(res, code === "bad-request" ? 400 : 500, { error: e instanceof Error ? e.message : String(e) }); --- /dev/null
+++ b/client/test/why-trail.test.ts
@@ -0,0 +1,144 @@
1+// abso why past formatting to the reason (abso-core issue 20), and lines 2+// imported from git naming their commit and their tracker (issue 21), from 3+// the command line: a line imported from git, then reformatted. 5+import assert from "node:assert/strict"; 6+import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; 7+import { tmpdir } from "node:os"; 8+import { join } from "node:path"; 9+import { after, before, describe, it } from "node:test"; 10+import { gitOrigin, issueLinks, issueNumbers, issuesOf } from "../src/git-origin.ts"; 11+import { main } from "../src/main.ts"; 12+import { type Fake, startFake } from "./fake-server.ts"; 14+const TOKEN = "test-token-not-secret"; 15+const ENV = { AVCS_TOKEN: TOKEN, AVCS_HOOK_FORCE: "1", AVCS_SERVERS_FILE: "no-servers.json" }; 17+ "Merge queue: check publishes in batches (#39)\n\nCap the batch at 8.\n\ngit 4e1a7c2b9f03, Ada Lovelace, 2026-10-06T20:36:43-05:00"; 20+const dirs: string[] = []; 22+ fake = await startFake(0, TOKEN); 26+ for (const d of dirs) rmSync(d, { recursive: true, force: true, maxRetries: 5 }); 29+async function run(cwd: string, ...argv: string[]): Promise<{ exit: number; out: string }> { 30+ const r = await main(argv, { cwd, env: ENV, write: () => {} }); 31+ return { exit: r.exit, out: r.stdout + r.stderr }; 35+/** v0 init; v1 a git import changes the cap line; v2 a reformat. */ 36+async function history(config = '{ "check": "true" }\n', message = IMPORTED): Promise<string> { 37+ const dir = mkdtempSync(join(tmpdir(), "abso-why-")); 39+ writeFileSync(join(dir, "abso.json"), config); 40+ writeFileSync(join(dir, "queue.ts"), "export function take(w) {\n\tconst n = Math.min(4, w);\n\treturn n;\n}\n"); 41+ const made = await run( 52+ assert.equal(made.exit, 0, made.out); 53+ const edit = (from: string, to: string) => 54+ writeFileSync(join(dir, "queue.ts"), readFileSync(join(dir, "queue.ts"), "utf8").replace(from, to)); 55+ edit("Math.min(4, w); ", "Math.min(4, w);"); 56+ edit("Math.min(4, w);", "Math.min(8, w); // #39"); 57+ let r = await run(dir, "push", "-m", message); 58+ assert.equal(r.exit, 0, r.out); 59+ edit("\tconst n = Math.min(8, w); // #39", " const n = Math.min(8, w) // #39"); 60+ r = await run(dir, "push", "-m", "Format the code"); 61+ assert.equal(r.exit, 0, r.out); 65+describe("abso why", () => { 66+ it("leads with the change that said what the line does, and says which formatting change it skipped", async () => { 67+ const dir = await history('{ "gitIssues": "https://github.com/owner/repo/issues/" }\n'); 68+ const r = await run(dir, "why", "queue.ts:2"); 69+ assert.equal(r.exit, 0, r.out); 70+ assert.match(r.out, /^queue\.ts line 2: {3}const n = Math\.min\(8, w\) \/\/ #39$/m); 71+ assert.match(r.out, /^Written by imp \(.*\), pushed in version 1 by imp \(.*\): "Merge queue: check publishes/m); 72+ assert.doesNotMatch(r.out, /pushed in version 1 [^\n]*git d9cf/, "the git line is said once, below"); 73+ assert.match(r.out, /^ {2}From git: commit 4e1a7c2b9f03 by Ada Lovelace, 2026-10-06T20:36:43-05:00\.$/m); 74+ assert.match(r.out, /^ {2}#39 is https:\/\/github\.com\/owner\/repo\/issues\/39$/m); 75+ assert.match(r.out, /^Skipped 1 formatting change since: version 2 \(imp, "Format the code"\)\./m); 78+ /^Earlier changes, newest first:\n {2}version 0 by init .*"Start the project"\n {4}It read: const n = Math\.min\(4, w\);$/m, 82+ it("--all leads with the newest change, formatting or not; --at reads an older version", async () => { 83+ const dir = await history(); 84+ const all = await run(dir, "why", "queue.ts:2", "--all"); 85+ assert.equal(all.exit, 0, all.out); 86+ assert.match(all.out, /^Written by imp .*pushed in version 2 .*"Format the code"/m); 89+ /^ {2}version 1 by imp .*"Merge queue: check publishes in batches \(#39\)", from git commit 4e1a7c2b9f03 by Ada Lovelace$/m, 91+ assert.doesNotMatch(all.out, /#39 is/, "no tracker: abso.json doesn't say where"); 92+ const at = await run(dir, "why", "queue.ts:2", "--at", "0", "--json"); 93+ assert.equal(at.exit, 0, at.out); 94+ assert.equal(JSON.parse(at.out).text, "\tconst n = Math.min(4, w);"); 97+ it("blame names an imported push's commit", async () => { 98+ const dir = await history(); 99+ const r = await run(dir, "blame", "queue.ts", "--version", "1"); 100+ assert.equal(r.exit, 0, r.out); 103+ /^ {2}v1 by imp, .*: Merge queue: check publishes in batches \(#39\) \(from git commit 4e1a7c2b9f03 by Ada Lovelace\)$/m, 108+describe("git origins", () => { 109+ it("reads import-git's lines, a git push's, or the host's commit", () => { 110+ assert.deepEqual(gitOrigin({ message: `${IMPORTED}\nIssues: https://github.com/o/r/issues` }), { 111+ commit: "4e1a7c2b9f03", 112+ author: "Ada Lovelace", 113+ time: "2026-10-06T20:36:43-05:00", 114+ issues: "https://github.com/o/r/issues", 115+ message: "Merge queue: check publishes in batches (#39)\n\nCap the batch at 8.", 117+ assert.deepEqual(gitOrigin({ message: "Fix\n\nGit-Commit: abcdef1234\nAuthor: Bo" }), { 118+ commit: "abcdef1234", 122+ assert.deepEqual(gitOrigin({ message: "Plain", commit: "abc1234", author: "Cy" }, "https://x/issues"), { 125+ issues: "https://x/issues", 128+ assert.equal(gitOrigin({ message: "Written in abso (#39)" }), undefined); 131+ it("names each #N once, and leaves owner/repo#N alone", () => { 132+ assert.deepEqual(issueNumbers("see #39 and #4, again #39; other/repo#7, a#5"), [39, 4]); 133+ assert.deepEqual(issueLinks("(#39)", "https://g/o/r/issues"), ["#39 is https://g/o/r/issues/39"]); 134+ assert.deepEqual(issueLinks("(#39)", undefined), []); 137+ it("finds a remote's issues on GitHub or GitLab, by https or ssh", () => { 138+ assert.equal(issuesOf("https://github.com/o/r.git"), "https://github.com/o/r/issues"); 139+ assert.equal(issuesOf("git@github.com:o/r.git"), "https://github.com/o/r/issues"); 140+ assert.equal(issuesOf("https://gitlab.com/g/sub/r"), "https://gitlab.com/g/sub/r/-/issues"); 141+ assert.equal(issuesOf("https://example.com/o/r.git"), undefined); 142+ assert.equal(issuesOf(""), undefined); --- a/server/src/engine-project.ts
+++ b/server/src/engine-project.ts
@@ -496,8 +496,12 @@
496496 ...(folder !== undefined ? { folder } : {}), 499− why(file: string, line: number, draft?: string, agent?: string) {
500− return why(this.project, file, line, { ...(draft ? { draft } : {}), ...(agent ? { agent } : {}) });
499+ why(file: string, line: number, draft?: string, agent?: string, version?: number) { 500+ return why(this.project, file, line, { 501+ ...(draft ? { draft } : {}), 502+ ...(agent ? { agent } : {}), 503+ ...(version !== undefined ? { version } : {}), 503507 return where(this.project); --- a/worker/project/blame.ts
+++ b/worker/project/blame.ts
@@ -2,11 +2,14 @@
22// A line's id names the atom that inserted it, so blame is a lookup per line: 33// that change's author and message, and the publish that brought it into 44// shared, with its message. Why adds the change's reasons, what it settled, 5−// and the reasons other changes give that point at it.
5+// and the reasons other changes give that point at it, and the line's 6+// earlier changes (trail.ts). 67import { type Atom, type AtomId, type LineId, type ReadView, View } from "../../src/engine/index.ts"; 78import { blocksIn, isMarkerLine } from "./markers.ts"; 89import { pathKey } from "./pathkey.ts"; 910import type { Project } from "./project.ts"; 11+import { projectFileIn } from "./project-helpers.ts"; 12+import { trail } from "./trail.ts"; 1114export interface BlameLine { @@ -225,11 +228,14 @@
225228 settled.length > 0 226229 ? heldPush(project, settle, file, Math.max(0, ...settled.map((s) => s.publish?.time ?? 0))) 231+ const gitIssues = gitIssuesOf(project.sharedView()); 235+ version: where.agent !== undefined ? null : (where.version ?? project.lastVersion(where.draft ?? null)), 238+ ...(gitIssues !== undefined ? { gitIssues } : {}), 235241 author: atom.author, @@ -245,10 +251,66 @@
245251 ...(kept ? { settledBy: { atom: kept.id, author: kept.author, publish: publishOf(project, kept.id) } } : {}), 246252 ...(held ? { held } : {}), 254+ ...lineTrail(project, view, file, line.id), 259+ * The line's changes, newest first (abso-core issue 20), its own change 260+ * first: each change that rewrote it, with the line's text after it, and 261+ * whether it only changed formatting. Several changes in one push count as 262+ * one, formatting only if all of them were. 264+function lineTrail(project: Project, view: ReadView, file: string, line: LineId) { 265+ const graph = project.graph; 266+ const { steps, more } = trail(graph, view, file, line); 273+ formatting: boolean; 274+ publish: Publish | null; 276+ for (const s of steps) { 277+ const a = graph.atom(s.atom); 278+ const publish = publishOf(project, a.id); 279+ const prev = out[out.length - 1]; 280+ if (prev && samePublish(prev.publish, publish) && (publish !== null || prev.author === a.author)) { 281+ prev.formatting &&= s.formatting; 290+ formatting: s.formatting, 294+ return { trail: out, ...(more ? { trailMore: true as const } : {}) }; 297+/** Where "#N" in history imported from git points (abso.json's "gitIssues"), when shared's project file says. */ 298+function gitIssuesOf(view: ReadView): string | undefined { 299+ const file = projectFileIn(view); 300+ if (!file) return undefined; 302+ const url = (JSON.parse(file.text) as { gitIssues?: unknown }).gitIssues; 303+ return typeof url === "string" ? url : undefined; 309+function samePublish(a: Publish | null, b: Publish | null): boolean { 310+ return a === null || b === null ? a === b : a.draft === b.draft && a.version === b.version; 252314 * Who wrote a folder (#41, F33): every line of every file under it (the 253315 * whole project for ""), counted by the agent that wrote it, most first. 254316 * Binary files and files kept whole have no lines, so they count as files --- a/worker/project/http.ts
+++ b/worker/project/http.ts
@@ -316,7 +316,7 @@
316316 return { status: 200, body: history.blame(q.file, num(q.from), num(q.to), num(q.version), draft, who) }; 317317 const line = num(q.line); 318318 if (!line || !Number.isInteger(line)) return fail(400, "why needs ?line=<number>"); 319− return { status: 200, body: history.why(q.file, line, draft, who) };
319+ return { status: 200, body: history.why(q.file, line, draft, who, num(q.version)) }; 321321 if (op === "announce" && agent === undefined) { 322322 // The sender comes from the route, like every other agent op, not from --- a/worker/project/project-api.ts
+++ b/worker/project/project-api.ts
@@ -102,7 +102,7 @@
102102export interface ProjectHistory { 103103 /** draft: a named draft's view (at version); agent: an agent's view now, its unpublished changes included. */ 104104 blame(file: string, from?: number, to?: number, version?: number, draft?: string, agent?: string): unknown; 105− why(file: string, line: number, draft?: string, agent?: string): unknown;
105+ why(file: string, line: number, draft?: string, agent?: string, version?: number): unknown; 106106 /** Who wrote a folder: its lines counted by author (#41, F33). */ 107107 folderBlame(folder: string, version?: number, draft?: string, agent?: string): unknown; 108108 /** One folder's entries with each one's last change (#41, F2, F34). */ --- a/worker/project/project-helpers.ts
+++ b/worker/project/project-helpers.ts
@@ -58,7 +58,8 @@
5858 * What's wrong with a project file (abso.json or avcs.json), or undefined: 5959 * it must be a JSON object, and the keys abso reads must have their types: 6060 * "whole" a list of globs, "queue" true or false, "review" a list of 61− * {paths, reviewer}, and CI's "setup", "build", "check" and "out" strings.
61+ * {paths, reviewer}, CI's "setup", "build", "check" and "out" strings, and 62+ * "gitIssues" (where "#N" in history imported from git points) a web address. 6364export function configProblem(text: string): string | undefined { 6465 let config: unknown; @@ -86,6 +87,8 @@
8788 if (!ok) return `has "review" that isn't a list of {"paths": [globs], "reviewer": "<agent>"}`; 90+ if (c.gitIssues !== undefined && (typeof c.gitIssues !== "string" || !/^https?:\/\/\S+$/.test(c.gitIssues))) 91+ return `has "gitIssues" that isn't a web address (like "https://github.com/owner/repo/issues")`; 8992 for (const key of ["setup", "build", "check", "out"]) 9093 if (c[key] !== undefined && typeof c[key] !== "string") return `has "${key}" that isn't a string`; --- /dev/null
+++ b/worker/project/test/trail.test.ts
@@ -0,0 +1,98 @@
1+// A line's earlier changes (abso-core issue 20): why follows a line back 2+// through the changes that rewrote it, and marks the ones that only changed 5+import assert from "node:assert/strict"; 6+import { test } from "node:test"; 7+import { why } from "../blame.ts"; 8+import { MemoryStore, Project } from "../project.ts"; 9+import { normalize, pairIn, trail } from "../trail.ts"; 11+function setup(files: Record<string, string>) { 12+ const project = new Project(new MemoryStore()); 13+ project.init(files, 0); 14+ for (const a of ["ann", "bob", "fmt"]) project.sync(a); 18+function push(p: Project, agent: string, file: string, old: string, now: string, message: string, time: number) { 20+ p.edit(agent, { file, old, new: now }, time); 21+ return p.publish(agent, message, time + 1); 24+test("normalized text ignores whitespace, wrapping, quotes, trailing commas, line-end semicolons and lone arrow parentheses", () => { 25+ assert.equal(normalize(["const a = f('x', 1);"]), normalize(['const a = f("x", 1)'])); 26+ assert.equal(normalize(["f(a, b)"]), normalize(["f(", "\ta,", "\tb,", ")"])); 27+ assert.equal(normalize(["xs.map((x) => x)"]), normalize(["xs.map(x => x)"])); 28+ assert.notEqual(normalize(["const n = 8;"]), normalize(["const n = 9;"])); 31+test("pairing: a rewrapped run pairs by its characters, a real edit by similarity, a new line with nothing", () => { 32+ assert.deepEqual(pairIn(["f(a, b);"], ["f(", " a,", " b,", ");"], 1), { index: 0, formatting: true }); 33+ assert.deepEqual(pairIn(["const n = Math.min(8, w);"], ["const n = Math.min(cap ?? 8, w);"], 0), { 37+ assert.equal(pairIn(["const n = 8;"], ["// nothing like it at all, really"], 0), undefined); 38+ assert.equal(pairIn([], ["new"], 0), undefined); 41+test("why follows a line back past a reformat to the change that said what it does", () => { 42+ const p = setup({ "q.ts": "export function take(w: number) {\n\tconst n = Math.min(8, w);\n\treturn n;\n}\n" }); 43+ push(p, "ann", "q.ts", "Math.min(8, w)", "Math.min(cap ?? 8, w)", "Cap the batch at 8, tunable per project", 10); // v1 44+ push(p, "bob", "q.ts", "\treturn n;\n", "\treturn n; // the count\n", "Say what n is", 20); // v2, beside it 49+ "\tconst n = Math.min(cap ?? 8, w);\n", 50+ " const n = Math.min(cap ?? 8, w)\n", 55+ const w = why(p, "q.ts", 2); 56+ assert.equal(w.text, " const n = Math.min(cap ?? 8, w)"); 58+ w.trail.map((s) => [s.publish?.version, s.formatting, s.text]), 60+ [3, true, " const n = Math.min(cap ?? 8, w)"], 61+ [1, false, "\tconst n = Math.min(cap ?? 8, w);"], 62+ [0, false, "\tconst n = Math.min(8, w);"], 65+ assert.equal(w.trail[1]!.publish?.message, "Cap the batch at 8, tunable per project"); 66+ assert.equal(w.trailMore, undefined); 69+test("a reformat that wraps one line onto several leads each piece back to it", () => { 70+ const p = setup({ "a.ts": "call(alpha, beta);\n" }); 71+ push(p, "fmt", "a.ts", "call(alpha, beta);\n", "call(\n\talpha,\n\tbeta,\n);\n", "Wrap", 10); // v1 72+ const w = why(p, "a.ts", 3); 74+ w.trail.map((s) => [s.publish?.version, s.formatting, s.text]), 76+ [1, true, "\tbeta,"], 77+ [0, false, "call(alpha, beta);"], 82+test("why --at reads the line as shared had it at that version", () => { 83+ const p = setup({ "a.ts": "one\ntwo\n" }); 84+ push(p, "ann", "a.ts", "one\n", "zero\none\n", "Add zero", 10); // v1 85+ assert.equal(why(p, "a.ts", 1, { version: 0 }).text, "one"); 86+ assert.equal(why(p, "a.ts", 2).text, "one"); 89+test("the trail stops after the most steps it may take, and says so", () => { 90+ const p = setup({ "a.ts": "v = 0\n" }); 91+ for (let i = 1; i <= 4; i++) push(p, "ann", "a.ts", `v = ${i - 1}`, `v = ${i}`, `to ${i}`, i * 10); 92+ const view = p.sharedView(); 93+ const line = view.lines("a.ts")[0]!.id; 94+ const t = trail(p.graph, view, "a.ts", line, 2); 95+ assert.equal(t.steps.length, 2); 96+ assert.equal(t.more, true); 97+ assert.equal(trail(p.graph, view, "a.ts", line).steps.length, 5); --- /dev/null
+++ b/worker/project/trail.ts
@@ -0,0 +1,240 @@
1+// A line's earlier changes, for why (abso-core issue 20). A line's id names 2+// the change that wrote it, so a line that was rewritten (reformatted, 3+// renamed, edited) is a new line, and the one it replaced is a deleted line 4+// in the same file. The file's full sequence keeps deleted lines where they 5+// were, so the lines a change deleted and the lines it wrote sit together: 6+// that's one hunk, and the line it replaced is the one it pairs with there. 7+// Following those pairs back gives the line's changes, newest first. A 8+// change that only touched formatting (whitespace, line wrapping, quotes, 9+// trailing commas and semicolons, parentheses around one arrow parameter) 10+// is marked, so why can skip past it to the change that said what the line 13+import type { Atom, AtomId, Graph, LineId, ReadView, SeqLine } from "../../src/engine/index.ts"; 15+/** One change in a line's past, newest first. */ 16+export interface TrailStep { 17+ /** The change that wrote the line. */ 18+ readonly atom: AtomId; 19+ /** The line it wrote, and its text then. */ 20+ readonly line: LineId; 21+ readonly text: string; 22+ /** It only changed formatting from the line it replaced. */ 23+ readonly formatting: boolean; 24+ /** The line it replaced, when it replaced one. */ 25+ readonly replaced?: LineId; 28+/** At most this many steps back. */ 29+export const TRAIL_MAX = 50; 32+ * Text with formatting taken out, for comparing two versions of the same 33+ * code: no whitespace, one kind of quote, no trailing commas before a 34+ * closing bracket, no semicolons at line ends (or before a comment there), and no parentheses around a 35+ * lone arrow parameter. Lines are normalized then joined, so a statement 36+ * wrapped onto three lines matches it on one. 38+export function normalize(lines: readonly string[]): string { 40+ .map((l) => l.replace(/;\s*(\/\/.*)?$/, "$1")) 43+ .replace(/['`]/g, '"') 44+ .replace(/,(?=[)\]}]|$)/g, "") 45+ .replace(/\(([A-Za-z_$][\w$]*)\)=>/g, "$1=>"); 48+/** Whether two runs of lines are the same code, formatted differently (or not at all). */ 49+export function sameCode(before: readonly string[], after: readonly string[]): boolean { 50+ return normalize(before) === normalize(after); 53+/** Similarity of two strings, 0 to 1: shared character pairs (Dice). */ 54+function similarity(a: string, b: string): number { 55+ if (a === b) return 1; 56+ if (a.length < 2 || b.length < 2) return 0; 57+ const pairs = new Map<string, number>(); 58+ for (let i = 0; i < a.length - 1; i++) { 59+ const p = a.slice(i, i + 2); 60+ pairs.set(p, (pairs.get(p) ?? 0) + 1); 63+ for (let i = 0; i < b.length - 1; i++) { 64+ const p = b.slice(i, i + 2); 65+ const n = pairs.get(p) ?? 0; 71+ return (2 * shared) / (a.length + b.length - 2); 74+/** Below this, a rewritten line isn't taken for the one it replaced: it was new. */ 78+ * For a run that's the same code reformatted: which old line each new line 79+ * came from, by where its characters fall in the joined, normalized text 80+ * (the old line it overlaps most). 82+function byCharacters(before: readonly string[], after: readonly string[], at: number): number | undefined { 83+ const spans = (lines: readonly string[]) => { 85+ return lines.map((l) => { 86+ const n = normalize([l]).length; 87+ const span = [from, from + n] as const; 92+ const [from, to] = spans(after)[at]!; 93+ let best: number | undefined; 95+ for (const [i, [a, b]] of spans(before).entries()) { 96+ const overlap = Math.min(to, b) - Math.max(from, a); 97+ if (overlap > most) [best, most] = [i, overlap]; 102+/** Longest common subsequence of two lists of keys: matched index pairs, in order. */ 103+function common(a: readonly string[], b: readonly string[]): [number, number][] { 106+ // Hunks are small; a full table is fine, but cap it so a whole-file rewrite stays cheap. 107+ if (n * m > 4_000_000) return []; 108+ const t: Uint32Array[] = Array.from({ length: n + 1 }, () => new Uint32Array(m + 1)); 109+ for (let i = n - 1; i >= 0; i--) 110+ for (let j = m - 1; j >= 0; j--) 111+ t[i]![j] = a[i] === b[j] ? t[i + 1]![j + 1]! + 1 : Math.max(t[i + 1]![j]!, t[i]![j + 1]!); 112+ const out: [number, number][] = []; 115+ while (i < n && j < m) { 116+ if (a[i] === b[j]) { 120+ } else if (t[i + 1]![j]! >= t[i]![j + 1]!) i++; 127+ * In one hunk, the old line a new one replaced, and whether that was only 128+ * formatting. Lines whose normalized text matches pair first; between those, 129+ * a run that's the same code rewrapped pairs by its characters; anything 130+ * else pairs with the most similar old line, if one is similar enough. 132+export function pairIn( 133+ before: readonly string[], 134+ after: readonly string[], 136+): { index: number; formatting: boolean } | undefined { 137+ if (before.length === 0) return undefined; 138+ if (sameCode(before, after)) { 139+ const index = byCharacters(before, after, at); 140+ return index === undefined ? undefined : { index, formatting: true }; 142+ const keys = (lines: readonly string[]) => lines.map((l) => normalize([l])); 143+ const a = keys(before); 144+ const b = keys(after); 145+ const anchors = common(a, b); 146+ const hit = anchors.find(([, j]) => j === at); 147+ if (hit && a[hit[0]] !== "") return { index: hit[0], formatting: true }; 148+ // The gap between anchors that holds the new line. 149+ let [i0, j0] = [0, 0]; 150+ let [i1, j1] = [before.length, after.length]; 151+ for (const [i, j] of anchors) { 152+ if (j < at) [i0, j0] = [i + 1, j + 1]; 158+ const gapBefore = before.slice(i0, i1); 159+ const gapAfter = after.slice(j0, j1); 160+ if (gapBefore.length === 0) return undefined; 161+ if (sameCode(gapBefore, gapAfter)) { 162+ const index = byCharacters(gapBefore, gapAfter, at - j0); 163+ return index === undefined ? undefined : { index: i0 + index, formatting: true }; 165+ let best: number | undefined; 167+ for (let i = i0; i < i1; i++) { 168+ const s = similarity(a[i]!, b[at]!); 169+ if (s >= most) [best, most] = [i, s]; 171+ return best === undefined ? undefined : { index: best, formatting: false }; 175+ * The line's changes, newest first: the change that wrote it, then the one 176+ * that wrote the line it replaced, and so on back to a change that wrote it 177+ * new. At most `max` steps; `more` says the trail went on. 179+export function trail( 185+): { steps: TrailStep[]; more: boolean } { 186+ const seq = view.sequence(file); 187+ const index = new Map<LineId, number>(); 188+ for (const [i, s] of seq.entries()) index.set(s.id, i); 189+ const steps: TrailStep[] = []; 190+ let current: LineId | undefined = line; 191+ while (current !== undefined && steps.length < max) { 192+ const at = index.get(current); 193+ if (at === undefined) break; 194+ const atom = graph.atom(seq[at]!.atom); 195+ const hunk = hunkOf(graph, seq, at, atom); 196+ const pair = pairIn( 197+ hunk.before.map((i) => seq[i]!.text), 198+ hunk.after.map((i) => seq[i]!.text), 199+ hunk.after.indexOf(at), 201+ const replaced = pair ? seq[hunk.before[pair.index]!]!.id : undefined; 205+ text: seq[at]!.text, 206+ formatting: pair?.formatting ?? false, 207+ ...(replaced !== undefined ? { replaced } : {}), 211+ return { steps, more: current !== undefined }; 215+ * The hunk a change made around one of its lines, as indexes into the 216+ * sequence in file order: the lines it deleted there and the lines it wrote. 217+ * Lines nobody could see when it was made (written later, or already 218+ * deleted) are passed over; a line it left alone ends the hunk. 220+function hunkOf(graph: Graph, seq: readonly SeqLine[], at: number, atom: Atom): { before: number[]; after: number[] } { 221+ const seqOf = (id: AtomId) => graph.atom(id).seq; 222+ const role = (s: SeqLine): "wrote" | "deleted" | "unseen" | "kept" => { 223+ if (s.atom === atom.id) return "wrote"; 224+ if (seqOf(s.atom) > atom.seq) return "unseen"; 225+ if (s.deletedBy.some((d) => d !== atom.id && seqOf(d) < atom.seq)) return "unseen"; 226+ return s.deletedBy.includes(atom.id) ? "deleted" : "kept"; 229+ while (first > 0 && role(seq[first - 1]!) !== "kept") first--; 231+ while (last < seq.length - 1 && role(seq[last + 1]!) !== "kept") last++; 232+ const before: number[] = []; 233+ const after: number[] = []; 234+ for (let i = first; i <= last; i++) { 235+ const r = role(seq[i]!); 236+ if (r === "deleted") before.push(i); 237+ else if (r === "wrote") after.push(i); 239+ return { before, after };