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 116 to 318

Compare

+98 −9 in 5 places
Lines 8–21 at 318 (were 8–20 at 116)
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, type WhyAnswer } from "./history-answers.ts";
1213
1314function open(env: Env): { root: string; api: Api; agent: string } {
1415 const root = findRoot(env.cwd);
1516 if (root === undefined)
1617 throw new UsageError(`${env.cwd} is not in an abso folder (no .abso/config.json here or above)`);
17− const config = readConfig(root, env.env);
18+ const config = readConfig(root, env.env, env.tokenFile === true);
1819 return { root, api: new Api(config), agent: config.agent };
1920}
2021
Lines 51–87 at 318 (were 50–55 at 116)
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+/** "1 formatting change and 2 moves": what why skipped. */
65+function skippedKinds(steps: readonly TrailStep[]): string {
66+ const moves = steps.filter((s) => s.movedFrom !== undefined).length;
67+ const formatting = steps.length - moves;
68+ return [
69+ ...(formatting > 0 ? [`${formatting} formatting change${formatting === 1 ? "" : "s"}`] : []),
70+ ...(moves > 0 ? [`${moves} move${moves === 1 ? "" : "s"}`] : []),
71+ ].join(" and ");
72+}
74+/** A trail step in a few words: its version (or that it isn't pushed), who, and the first line of why. */
75+function stepName(s: TrailStep, long = false): string {
76+ const first = (s.publish ? (gitOrigin(s.publish)?.message ?? s.publish.message) : s.message).split("\n")[0]!;
77+ const subject = first.length > 100 ? `${first.slice(0, 97).trimEnd()}...` : first;
78+ const where = s.publish === null ? "not pushed" : `version ${s.publish.version}`;
79+ const who = s.publish ? byWhom(s.publish) : s.author;
80+ return long
81+ ? `${where} by ${who} (${when(s.publish?.time ?? s.time)}): "${subject}"`
82+ : `${where} (${who}, "${subject}")`;
83+}
5385export async function runBlame(args: Parsed, env: Env): Promise<Output> {
5486 if (args.positionals.length !== 1)
5587 throw new UsageError("blame takes one file: abso blame <file> [--from <n>] [--to <n>]");
Lines 104–114 at 318 (were 72–78 at 116)
72104 for (const a of b.atoms) {
73105 if (a.publish === null) continue;
74106 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}`;
107+ const origin = gitOrigin(a.publish);
108+ const message = origin
109+ ? `${origin.message.split("\n")[0]} (from git commit ${origin.commit.slice(0, 12)}${origin.author ? ` by ${origin.author}` : ""})`
110+ : a.publish.message;
111+ const line = ` v${a.publish.version} by ${byWhom(a.publish)}, ${when(a.publish.time)}: ${message}${own}`;
76112 if (!versions.has(a.publish.version) || own) versions.set(a.publish.version, line);
77113 }
78114 const whose =
Lines 148–217 at 318 (were 112–128 at 116)
112148 throw new UsageError("why takes a file and a line: abso why <file>:<line>");
113149 const { root, api, agent } = open(env);
114150 const file = fileArg(root, env.cwd, typed);
115− const w = await api.why(file, lineNumber(raw, "the line")!, viewOf(args, agent));
151+ const rawAt = str(args, "at");
152+ if (rawAt !== undefined && !/^\d+$/.test(rawAt))
153+ throw new UsageError(`--at is a version number (got ${JSON.stringify(rawAt)})`);
154+ const at = rawAt === undefined ? undefined : Number(rawAt);
155+ const view = viewOf(args, agent);
156+ if (at !== undefined && "agent" in view)
157+ throw new UsageError("--mine reads your view as it is now; it takes no --at");
158+ const w = await api.why(file, lineNumber(raw, "the line")!, view, at);
159+ if (at !== undefined && w.version !== at)
160+ throw new UsageError(`this server doesn't read why at a version yet; abso blame ${w.file} --version ${at} does`);
161+ return { text: whyText(w, { at, all: bool(args, "all") }), json: { ...w } };
162+}
164+/**
165+ * What abso why prints for an answer. The line's changes (abso-core issue
166+ * 20): the newest one that changed what it does leads, past formatting-only
167+ * ones, unless `all`.
168+ */
169+export function whyText(w: WhyAnswer, { at, all = false }: { at?: number; all?: boolean } = {}): string {
170+ const trail = w.trail ?? [];
171+ const lead = (all ? trail[0] : trail.find((s) => !s.formatting)) ?? trail[0];
172+ const leadAt = lead === undefined ? 0 : trail.indexOf(lead);
173+ const skipped = trail.slice(0, leadAt);
174+ const earlier = trail.slice(leadAt + 1).filter((s) => all || !s.formatting);
175+ const origin = lead?.publish ? gitOrigin(lead.publish, w.gitIssues) : undefined;
116176 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}"`] : []),
177+ `${w.file} line ${w.line}${at !== undefined ? ` at version ${at}` : ""}: ${w.text}`,
178+ ...(lead === undefined || leadAt === 0
179+ ? [`Written by ${w.change.author} (${when(w.change.time)}), pushed in ${pushed(w.publish, w.gitIssues)}.`]
180+ : [
181+ `Written by ${lead.author} (${when(lead.time)}), pushed in ${pushed(lead.publish, w.gitIssues)}.`,
182+ ...(lead.text.trim() !== w.text.trim() ? [` It read: ${lead.text.trim()}`] : []),
183+ ]),
184+ ...(origin ? gitLines(origin) : []),
185+ ...issueLinks(`${w.text}\n${origin?.message ?? ""}`, origin?.issues).map((l) => ` ${l}`),
186+ ...(skipped.length > 0
187+ ? [
188+ `Skipped ${skippedKinds(skipped)} since: ${skipped.map((s) => `${stepName(s)}${s.movedFrom ? `, moved from ${s.movedFrom}` : ""}`).join("; ")}. abso why --all shows ${skipped.length === 1 ? "it" : "them"}.`,
189+ ]
190+ : []),
191+ ...(earlier.length > 0
192+ ? [
193+ "Earlier changes, newest first:",
194+ ...earlier.flatMap((s, i) => {
195+ const newer = i === 0 ? lead! : earlier[i - 1]!;
196+ const o = s.publish ? gitOrigin(s.publish, w.gitIssues) : undefined;
197+ return [
198+ ` ${stepName(s, true)}${s.movedFrom ? ` (moved from ${s.movedFrom})` : s.formatting ? " (formatting only)" : ""}${o ? `, from git commit ${o.commit.slice(0, 12)}${o.author ? ` by ${o.author}` : ""}` : ""}`,
199+ ...(s.text.trim() !== newer.text.trim() ? [` It read: ${s.text.trim()}`] : []),
200+ ];
201+ }),
202+ ]
203+ : []),
204+ ...(w.trailMore ? [" (it goes back further than why follows)"] : []),
205+ ...(w.change.message && leadAt === 0 ? [`The change says: "${w.change.message}"`] : []),
120206 ...(w.settled.length > 0
121207 ? [
122− "It settled a collision between:",
208+ w.settledBy
209+ ? `It was kept when ${w.settledBy.author} settled a collision between:`
210+ : "It settled a collision between:",
123211 ...w.settled.map(
124212 (s) => ` ${s.author}, ${published(s.publish)}${s.message ? ` (the change: "${s.message}")` : ""}`,
125213 ),
214+ ...(w.held ? [` ${w.held.agent}, a held push: "${w.held.message}"`] : []),
126215 ]
127216 : []),
128217 ...(w.reasons.length > 0
Lines 227–233 at 318 (were 138–144 at 116)
138227 ]
139228 : []),
140229 ];
141− return { text: lines.join("\n"), json: { ...w } };
230+ return lines.join("\n");
142231}
143232
144233function ranges(rs: readonly [number, number][]): string {
MCP
compare on this site's /mcp
CLI
abso diff 116 318 client/src/history.ts --json
JSON
/christopher/abso-core/compare/116..318?file=client%2Fsrc%2Fhistory.ts&format=json