- MCP
- blame on this site's /mcp
- CLI
- abso blame client/src/fetch.ts --json
- JSON
- /christopher/abso-core/blame/client/src/fetch.ts?format=json
92 linesFirst import 97% · review 2% · infra-split 1%Last change infra-split in version 37,
92 lines from 4 changes in 4 versions.
init0Start the project1// abso fetch <glob...> and abso run --fetch <glob>: bring files the box made
infra-split37Comments and test names give each reason in plain words, without naming who raised it
Notes like "(#37, Builder 5)" or "(AVCS - Security)" become "(#37)" or go, and a private commit hash after a name goes with it. Issue numbers and references such as git's CVE-2019-1353 stay. Only comments and test names change; no behavior changes.Compare2// back into the folder (#37). Only paths abso ignores are written,
init0Start the project3// so a fetched file never becomes an edit; the rest are named and left alone.
4// Every path is screened as a sync's are (safety.ts): the box runs whatever
5// the folder held, so its files are not trusted any more than the server's.
7import { chmodSync, mkdirSync } from "node:fs";
8import { dirname } from "node:path";
9import type { Api } from "./api.ts";
10import { UsageError } from "./args.ts";
11import { isLocalOnly } from "./core.ts";
12import { absolute, loadIgnore, writeFileAtomic } from "./folder.ts";
13import { type Refused, throughLink, unsafePath } from "./safety.ts";
14import { untarGz } from "./tar.ts";
16export interface Fetched {
17 readonly written: string[];
18 /** Matched in the box but not written, and why. */
19 readonly skipped: Refused[];
20 /** Globs that matched nothing (or the box had stopped). */
21 readonly empty: string[];
22}
24/** Whether abso leaves `rel` out: itself, or a folder on its way (git's rule: nothing under an ignored folder counts). */
25export function ignoredHere(ignore: ReturnType<typeof loadIgnore>, rel: string, isDir = false): boolean {
26 const parts = rel.split("/");
27 for (let i = 1; i < parts.length; i++) if (ignore(parts.slice(0, i).join("/"), true)) return true;
28 return ignore(rel, isDir);
29}
31export async function fetchFromBox(root: string, api: Api, globs: readonly string[]): Promise<Fetched> {
32 if (globs.length === 0) throw new UsageError('name what to fetch: abso fetch <glob...>, like abso fetch "out/*.png"');
33 const ignore = loadIgnore(root);
34 const written: string[] = [];
35 const skipped: Refused[] = [];
36 const empty: string[] = [];
37 const seen = new Set<string>();
38 for (const glob of globs) {
39 const gz = await api.boxFiles(glob);
40 if (gz === null) {
41 empty.push(glob);
42 continue;
43 }
44 for (const e of untarGz(gz)) {
45 if (seen.has(e.path)) continue;
46 seen.add(e.path);
47 const why =
48 unsafePath(e.path) ??
review17New folders keep their state in .abso/, and the machine's sign-in, servers and admin token are read from ~/.abso/ first, then ~/.avcs/. A folder made before, with only .avcs/, is untouched: it keeps working, is never half-moved, and no older client or mod loses it. stateDir(root) and homeFile/homeWritePath are in the new client/src/state-dir.ts and replace the old AVCS_DIR constant everywhere. abso login writes only to ~/.abso/ and leaves ~/.avcs/ alone; logout removes both copies. The edit mod and the view mod read either folder. .abso is skipped like .avcs (including its odd spellings), the git exclude names whichever folder is in use, and the messages name .abso. Not changed: avcs.json (the server reads that name, so abso.json needs the server to learn it first), .avcsignore, env var names and wire headers. Tests: 709 run, 708 pass (one is skipped), including new ones for the folder choice, the home-file order and box sign-in; biome ci has no errors.Compare49 (isLocalOnly(e.path) ? "it is under .git, .claude, .abso or node_modules, which stay local" : undefined) ??
init0Start the project50 (throughLink(root, e.path) ? "a folder on its way is a link" : undefined) ??
51 (e.link !== undefined ? "it is a link; fetch makes none" : undefined) ??
52 (!ignoredHere(ignore, e.path)
review27Client: ABSO_ environment names (AVCS_ still read), .absoignore (.avcsignore still read), .abso-export.json, shot files; READMEs say abso (abso 224)Compare53 ? "abso records it, so writing it would make an edit; add it to .absoignore to fetch it"
55 if (why !== undefined) {
56 skipped.push({ path: e.path, why });
57 continue;
58 }
59 const path = absolute(root, e.path);
60 mkdirSync(dirname(path), { recursive: true });
61 writeFileAtomic(path, e.data);
62 if (e.mode !== undefined && (e.mode & 0o111) !== 0) {
63 try {
64 chmodSync(path, 0o755);
65 } catch {
66 // The bit is a convenience here.
67 }
68 }
69 written.push(e.path);
70 }
71 }
72 return { written: written.sort(), skipped: skipped.sort((a, b) => a.path.localeCompare(b.path)), empty };
73}
75/** What a fetch says: what it wrote, what it left alone and why, and globs that found nothing. */
76export function fetchedText(f: Fetched): string[] {
77 const shown = (list: readonly string[]) =>
78 list.length <= 8 ? list.join(", ") : `${list.slice(0, 8).join(", ")}, and ${list.length - 8} more`;
79 return [
80 ...(f.written.length > 0
81 ? [
82 `Fetched ${f.written.length === 1 ? "1 file" : `${f.written.length} files`} from the box: ${shown(f.written)}.`,
83 ]
84 : []),
85 ...(f.skipped.length > 0
86 ? [`Not fetched (${f.skipped.length}):`, ...f.skipped.map((s) => ` ${s.path}: ${s.why}`)]
87 : []),
88 ...f.empty.map(
89 (g) => `Nothing in the box matches ${g} (or the box has stopped: it keeps /w only until it idles out).`,
90 ),
91 ];
92}