Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed

Versions 192 to 193

Compare

+74 −6 in 4 places
Lines 8–15 at 193 (were 8–14 at 192)
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";
1213
1314function open(env: Env): { root: string; api: Api; agent: string } {
1415 const root = findRoot(env.cwd);
Lines 51–76 at 193 (were 50–55 at 192)
5051 return p === null ? "not pushed" : `version ${p.version} by ${byWhom(p)} (${when(p.time)}): "${p.message}"`;
5152}
5253
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);
58+}
60+function gitLines(o: GitOrigin): string[] {
61+ return [` From git: commit ${o.commit}${o.author ? ` by ${o.author}` : ""}${o.time ? `, ${o.time}` : ""}.`];
62+}
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;
69+ return long
70+ ? `${where} by ${who} (${when(s.publish?.time ?? s.time)}): "${subject}"`
71+ : `${where} (${who}, "${subject}")`;
72+}
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>]");
Lines 93–103 at 193 (were 72–78 at 192)
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}` : ""})`
99+ : a.publish.message;
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);
77102 }
78103 const whose =
Lines 137–190 at 193 (were 112–122 at 192)
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;
116158 const lines = [
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)}.`]
162+ : [
163+ `Written by ${lead.author} (${when(lead.time)}), pushed in ${pushed(lead.publish, w.gitIssues)}.`,
164+ ` It read: ${lead.text.trim()}`,
165+ ]),
166+ ...(origin ? gitLines(origin) : []),
167+ ...issueLinks(`${w.text}\n${origin?.message ?? ""}`, origin?.issues).map((l) => ` ${l}`),
168+ ...(skipped.length > 0
169+ ? [
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"}.`,
171+ ]
172+ : []),
173+ ...(earlier.length > 0
174+ ? [
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;
179+ return [
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()}`] : []),
182+ ];
183+ }),
184+ ]
185+ : []),
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
121189 ? [
122190 w.settledBy
MCP
compare on this site's /mcp
CLI
abso diff 192 193 client/src/history.ts --json
JSON
/christopher/abso-core/compare/192..193?file=client%2Fsrc%2Fhistory.ts&format=json