- MCP
- blame on this site's /mcp
- CLI
- abso blame client/src/at.ts --json
- JSON
- /christopher/abso-core/blame/client/src/at.ts?format=json
110 linesFirst import 92% · candidates 7% · rename 1%Last change candidates in version 186,
110 lines from 3 changes in 3 versions.
2// folder's space, or old copies of a few files, in the box, without touching
3// a file in the folder (Backtracker's bisect, #25). Swapping files in by hand
4// let the edit hook record the old copies.
5//
6// The version is rebuilt from what the client already knows, in two calls:
7// the known copies are this agent's view (its base plus its recorded draft);
8// its diff gives each drafted file as it was at the base; and compare(N, base)
9// gives each file that differs between version N and the base, as it was at N.
11import type { Api, FileChange, Where } from "./api.ts";
12import { UsageError } from "./args.ts";
13import { readKnownBlobs } from "./blobs.ts";
14import { isLocalOnly } from "./core.ts";
15import { listKnown, readKnown } from "./folder.ts";
16import { type FullMode, PLAIN, readKnownModes } from "./modes.ts";
17import type { TarEntry } from "./tar.ts";
19/** One file of a version: its text, or its bytes by hash; and its mode. */
20type Held = { readonly text: string } | { readonly blob: string };
22export interface Snapshot {
23 readonly version: number;
24 readonly files: Map<string, Held>;
25 readonly modes: Map<string, FullMode>;
26}
candidates186Read a version of shared without some earlier versions: abso show <N> --without A,B shows what differs and abso export <dir> --version N --without A,B writes the files. The server's GET without?version=&versions= checks the set left exactly as asked: when a version it keeps builds on one left out, it refuses with that chain, the files and the wider set that works, and never widens it. Atoms keep their ids and authors; shared and its log don't change; the same ask gives the same tree hash.Compare28/** Each file as it is on one side of a change (`before` unless said), applied to the snapshot. */
29export function applySide(s: Snapshot, changes: readonly FileChange[], side: "before" | "after" = "before"): void {
31 if (isLocalOnly(f.path)) continue;
candidates186Read a version of shared without some earlier versions: abso show <N> --without A,B shows what differs and abso export <dir> --version N --without A,B writes the files. The server's GET without?version=&versions= checks the set left exactly as asked: when a version it keeps builds on one left out, it refuses with that chain, the files and the wider set that works, and never widens it. Atoms keep their ids and authors; shared and its log don't change; the same ask gives the same tree hash.Compare32 const blob = f.blob?.[side] ?? null;
33 const text = f[side];
candidates186Read a version of shared without some earlier versions: abso show <N> --without A,B shows what differs and abso export <dir> --version N --without A,B writes the files. The server's GET without?version=&versions= checks the set left exactly as asked: when a version it keeps builds on one left out, it refuses with that chain, the files and the wider set that works, and never widens it. Atoms keep their ids and authors; shared and its log don't change; the same ask gives the same tree hash.Compare35 else if (text !== null) s.files.set(f.path, { text });
37 s.files.delete(f.path);
38 s.modes.delete(f.path);
39 continue;
40 }
candidates186Read a version of shared without some earlier versions: abso show <N> --without A,B shows what differs and abso export <dir> --version N --without A,B writes the files. The server's GET without?version=&versions= checks the set left exactly as asked: when a version it keeps builds on one left out, it refuses with that chain, the files and the wider set that works, and never widens it. Atoms keep their ids and authors; shared and its log don't change; the same ask gives the same tree hash.Compare41 if (f.mode) s.modes.set(f.path, { exec: f.mode[side].exec === true, link: f.mode[side].link ?? null });
43}
45/** The folder's space as it was at `version`: every file, and its mode. */
46export async function snapshotAt(root: string, api: Api, version: number): Promise<Snapshot> {
47 const diff = await api.diff();
rename100abso publish is now abso push, abso sync is now abso pull (abso 427)
Commands, help, flags, messages, MCP tool names and descriptions, hook text, README, SKILL.md and tests say push and pull; "shared" stays the noun ("Pushed version N"). No aliases, no notices. A queued push that was "pulled" is now "turned back", so pull means one thing.
push -f/--force/-u/--all/--tags and pull --rebase/--ff-only/--squash refuse with one plain line naming the abso way; push and pull take no remote or branch.
Kept as stored: log entry kinds (publish, sync, pulled), HTTP route paths, the pipeline trigger on: publish, the yours (unpublished) marker, npm-publish.Compare48 if (diff.base === null) throw new UsageError("this folder has no version yet: run abso pull first");
50 // This agent's view, from its known copies.
51 const s: Snapshot = { version, files: new Map(), modes: new Map() };
52 for (const rel of listKnown(root)) {
53 if (isLocalOnly(rel)) continue;
54 const text = readKnown(root, rel);
55 if (text !== undefined) s.files.set(rel, { text });
56 }
57 for (const [rel, sha] of readKnownBlobs(root)) s.files.set(rel, { blob: sha });
58 for (const [rel, mode] of readKnownModes(root)) if (s.files.has(rel)) s.modes.set(rel, mode);
59 // Its base: the draft's changes taken back out.
candidates186Read a version of shared without some earlier versions: abso show <N> --without A,B shows what differs and abso export <dir> --version N --without A,B writes the files. The server's GET without?version=&versions= checks the set left exactly as asked: when a version it keeps builds on one left out, it refuses with that chain, the files and the wider set that works, and never widens it. Atoms keep their ids and authors; shared and its log don't change; the same ask gives the same tree hash.Compare60 applySide(s, diff.files);
candidates186Read a version of shared without some earlier versions: abso show <N> --without A,B shows what differs and abso export <dir> --version N --without A,B writes the files. The server's GET without?version=&versions= checks the set left exactly as asked: when a version it keeps builds on one left out, it refuses with that chain, the files and the wider set that works, and never widens it. Atoms keep their ids and authors; shared and its log don't change; the same ask gives the same tree hash.Compare62 if (version !== diff.base) applySide(s, (await api.compare(version, diff.base, where)).files);
64}
66/** A glob (or several, comma-separated) as a test on folder-relative paths. `**` crosses folders, `*` and `?` don't; a plain path matches itself and what is under it. */
67export function globTest(globs: string): (rel: string) => boolean {
68 const tests = globs
69 .split(",")
70 .map((g) => g.trim().replace(/\\/g, "/").replace(/^\.\//, "").replace(/\/+$/, ""))
71 .filter((g) => g !== "")
72 .map((g) => {
73 if (!/[*?[]/.test(g)) return (rel: string) => rel === g || rel.startsWith(`${g}/`);
74 let re = "";
75 for (let i = 0; i < g.length; i++) {
76 const c = g[i]!;
77 if (c === "*" && g[i + 1] === "*") {
78 re += g[i + 2] === "/" ? "(?:.*/)?" : ".*";
79 i += g[i + 2] === "/" ? 2 : 1;
80 } else if (c === "*") re += "[^/]*";
81 else if (c === "?") re += "[^/]";
82 else re += c.replace(/[.+^${}()|[\]\\]/g, "\\$&");
83 }
84 const r = new RegExp(`^${re}$`);
85 return (rel: string) => r.test(rel);
86 });
87 if (tests.length === 0) throw new UsageError('--files needs a path or a glob, like --files "src/*.ts"');
88 return (rel) => tests.some((t) => t(rel));
89}
91/** The tar entries for a snapshot's files (all of them, or those `pick` takes), fetching blob bytes. */
92export async function snapshotEntries(
93 api: Api,
94 s: Snapshot,
95 pick: (rel: string) => boolean = () => true,
96): Promise<TarEntry[]> {
97 const out: TarEntry[] = [];
98 for (const [rel, held] of [...s.files].sort(([a], [b]) => a.localeCompare(b))) {
99 if (!pick(rel)) continue;
100 const mode = s.modes.get(rel) ?? PLAIN;
101 if (mode.link !== null) {
102 out.push({ path: rel, data: new Uint8Array(0), link: mode.link });
103 continue;
104 }
105 const data = "blob" in held ? await api.getBlob(held.blob) : new TextEncoder().encode(held.text);
106 const script = data[0] === 0x23 && data[1] === 0x21;
107 out.push({ path: rel, data, ...(mode.exec || script ? { mode: 0o755 } : {}) });
108 }
109 return out;
110}