{"file":"client/src/fetch.ts","version":7,"total":92,"from":1,"to":92,"lines":[{"n":1,"text":"// abso fetch <glob...> and abso run --fetch <glob>: bring files the box made","atom":"a0","author":"init","version":0},{"n":2,"text":"// back into the folder (#37, Builder 4). Only paths abso ignores are written,","atom":"a0","author":"init","version":0},{"n":3,"text":"// so a fetched file never becomes an edit; the rest are named and left alone.","atom":"a0","author":"init","version":0},{"n":4,"text":"// Every path is screened as a sync's are (safety.ts): the box runs whatever","atom":"a0","author":"init","version":0},{"n":5,"text":"// the folder held, so its files are not trusted any more than the server's.","atom":"a0","author":"init","version":0},{"n":6,"text":"","atom":"a0","author":"init","version":0},{"n":7,"text":"import { chmodSync, mkdirSync } from \"node:fs\";","atom":"a0","author":"init","version":0},{"n":8,"text":"import { dirname } from \"node:path\";","atom":"a0","author":"init","version":0},{"n":9,"text":"import type { Api } from \"./api.ts\";","atom":"a0","author":"init","version":0},{"n":10,"text":"import { UsageError } from \"./args.ts\";","atom":"a0","author":"init","version":0},{"n":11,"text":"import { isLocalOnly } from \"./core.ts\";","atom":"a0","author":"init","version":0},{"n":12,"text":"import { absolute, loadIgnore, writeFileAtomic } from \"./folder.ts\";","atom":"a0","author":"init","version":0},{"n":13,"text":"import { type Refused, throughLink, unsafePath } from \"./safety.ts\";","atom":"a0","author":"init","version":0},{"n":14,"text":"import { untarGz } from \"./tar.ts\";","atom":"a0","author":"init","version":0},{"n":15,"text":"","atom":"a0","author":"init","version":0},{"n":16,"text":"export interface Fetched {","atom":"a0","author":"init","version":0},{"n":17,"text":"\treadonly written: string[];","atom":"a0","author":"init","version":0},{"n":18,"text":"\t/** Matched in the box but not written, and why. */","atom":"a0","author":"init","version":0},{"n":19,"text":"\treadonly skipped: Refused[];","atom":"a0","author":"init","version":0},{"n":20,"text":"\t/** Globs that matched nothing (or the box had stopped). */","atom":"a0","author":"init","version":0},{"n":21,"text":"\treadonly empty: string[];","atom":"a0","author":"init","version":0},{"n":22,"text":"}","atom":"a0","author":"init","version":0},{"n":23,"text":"","atom":"a0","author":"init","version":0},{"n":24,"text":"/** Whether abso leaves `rel` out: itself, or a folder on its way (git's rule: nothing under an ignored folder counts). */","atom":"a0","author":"init","version":0},{"n":25,"text":"export function ignoredHere(ignore: ReturnType<typeof loadIgnore>, rel: string, isDir = false): boolean {","atom":"a0","author":"init","version":0},{"n":26,"text":"\tconst parts = rel.split(\"/\");","atom":"a0","author":"init","version":0},{"n":27,"text":"\tfor (let i = 1; i < parts.length; i++) if (ignore(parts.slice(0, i).join(\"/\"), true)) return true;","atom":"a0","author":"init","version":0},{"n":28,"text":"\treturn ignore(rel, isDir);","atom":"a0","author":"init","version":0},{"n":29,"text":"}","atom":"a0","author":"init","version":0},{"n":30,"text":"","atom":"a0","author":"init","version":0},{"n":31,"text":"export async function fetchFromBox(root: string, api: Api, globs: readonly string[]): Promise<Fetched> {","atom":"a0","author":"init","version":0},{"n":32,"text":"\tif (globs.length === 0) throw new UsageError('name what to fetch: abso fetch <glob...>, like abso fetch \"out/*.png\"');","atom":"a0","author":"init","version":0},{"n":33,"text":"\tconst ignore = loadIgnore(root);","atom":"a0","author":"init","version":0},{"n":34,"text":"\tconst written: string[] = [];","atom":"a0","author":"init","version":0},{"n":35,"text":"\tconst skipped: Refused[] = [];","atom":"a0","author":"init","version":0},{"n":36,"text":"\tconst empty: string[] = [];","atom":"a0","author":"init","version":0},{"n":37,"text":"\tconst seen = new Set<string>();","atom":"a0","author":"init","version":0},{"n":38,"text":"\tfor (const glob of globs) {","atom":"a0","author":"init","version":0},{"n":39,"text":"\t\tconst gz = await api.boxFiles(glob);","atom":"a0","author":"init","version":0},{"n":40,"text":"\t\tif (gz === null) {","atom":"a0","author":"init","version":0},{"n":41,"text":"\t\t\tempty.push(glob);","atom":"a0","author":"init","version":0},{"n":42,"text":"\t\t\tcontinue;","atom":"a0","author":"init","version":0},{"n":43,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":44,"text":"\t\tfor (const e of untarGz(gz)) {","atom":"a0","author":"init","version":0},{"n":45,"text":"\t\t\tif (seen.has(e.path)) continue;","atom":"a0","author":"init","version":0},{"n":46,"text":"\t\t\tseen.add(e.path);","atom":"a0","author":"init","version":0},{"n":47,"text":"\t\t\tconst why =","atom":"a0","author":"init","version":0},{"n":48,"text":"\t\t\t\tunsafePath(e.path) ??","atom":"a0","author":"init","version":0},{"n":49,"text":"\t\t\t\t(isLocalOnly(e.path) ? \"it is under .git, .claude, .avcs or node_modules, which stay local\" : undefined) ??","atom":"a0","author":"init","version":0},{"n":50,"text":"\t\t\t\t(throughLink(root, e.path) ? \"a folder on its way is a link\" : undefined) ??","atom":"a0","author":"init","version":0},{"n":51,"text":"\t\t\t\t(e.link !== undefined ? \"it is a link; fetch makes none\" : undefined) ??","atom":"a0","author":"init","version":0},{"n":52,"text":"\t\t\t\t(!ignoredHere(ignore, e.path)","atom":"a0","author":"init","version":0},{"n":53,"text":"\t\t\t\t\t? \"abso records it, so writing it would make an edit; add it to .avcsignore to fetch it\"","atom":"a0","author":"init","version":0},{"n":54,"text":"\t\t\t\t\t: undefined);","atom":"a0","author":"init","version":0},{"n":55,"text":"\t\t\tif (why !== undefined) {","atom":"a0","author":"init","version":0},{"n":56,"text":"\t\t\t\tskipped.push({ path: e.path, why });","atom":"a0","author":"init","version":0},{"n":57,"text":"\t\t\t\tcontinue;","atom":"a0","author":"init","version":0},{"n":58,"text":"\t\t\t}","atom":"a0","author":"init","version":0},{"n":59,"text":"\t\t\tconst path = absolute(root, e.path);","atom":"a0","author":"init","version":0},{"n":60,"text":"\t\t\tmkdirSync(dirname(path), { recursive: true });","atom":"a0","author":"init","version":0},{"n":61,"text":"\t\t\twriteFileAtomic(path, e.data);","atom":"a0","author":"init","version":0},{"n":62,"text":"\t\t\tif (e.mode !== undefined && (e.mode & 0o111) !== 0) {","atom":"a0","author":"init","version":0},{"n":63,"text":"\t\t\t\ttry {","atom":"a0","author":"init","version":0},{"n":64,"text":"\t\t\t\t\tchmodSync(path, 0o755);","atom":"a0","author":"init","version":0},{"n":65,"text":"\t\t\t\t} catch {","atom":"a0","author":"init","version":0},{"n":66,"text":"\t\t\t\t\t// The bit is a convenience here.","atom":"a0","author":"init","version":0},{"n":67,"text":"\t\t\t\t}","atom":"a0","author":"init","version":0},{"n":68,"text":"\t\t\t}","atom":"a0","author":"init","version":0},{"n":69,"text":"\t\t\twritten.push(e.path);","atom":"a0","author":"init","version":0},{"n":70,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":71,"text":"\t}","atom":"a0","author":"init","version":0},{"n":72,"text":"\treturn { written: written.sort(), skipped: skipped.sort((a, b) => a.path.localeCompare(b.path)), empty };","atom":"a0","author":"init","version":0},{"n":73,"text":"}","atom":"a0","author":"init","version":0},{"n":74,"text":"","atom":"a0","author":"init","version":0},{"n":75,"text":"/** What a fetch says: what it wrote, what it left alone and why, and globs that found nothing. */","atom":"a0","author":"init","version":0},{"n":76,"text":"export function fetchedText(f: Fetched): string[] {","atom":"a0","author":"init","version":0},{"n":77,"text":"\tconst shown = (list: readonly string[]) =>","atom":"a0","author":"init","version":0},{"n":78,"text":"\t\tlist.length <= 8 ? list.join(\", \") : `${list.slice(0, 8).join(\", \")}, and ${list.length - 8} more`;","atom":"a0","author":"init","version":0},{"n":79,"text":"\treturn [","atom":"a0","author":"init","version":0},{"n":80,"text":"\t\t...(f.written.length > 0","atom":"a0","author":"init","version":0},{"n":81,"text":"\t\t\t? [","atom":"a0","author":"init","version":0},{"n":82,"text":"\t\t\t\t\t`Fetched ${f.written.length === 1 ? \"1 file\" : `${f.written.length} files`} from the box: ${shown(f.written)}.`,","atom":"a0","author":"init","version":0},{"n":83,"text":"\t\t\t\t]","atom":"a0","author":"init","version":0},{"n":84,"text":"\t\t\t: []),","atom":"a0","author":"init","version":0},{"n":85,"text":"\t\t...(f.skipped.length > 0","atom":"a0","author":"init","version":0},{"n":86,"text":"\t\t\t? [`Not fetched (${f.skipped.length}):`, ...f.skipped.map((s) => `  ${s.path}: ${s.why}`)]","atom":"a0","author":"init","version":0},{"n":87,"text":"\t\t\t: []),","atom":"a0","author":"init","version":0},{"n":88,"text":"\t\t...f.empty.map(","atom":"a0","author":"init","version":0},{"n":89,"text":"\t\t\t(g) => `Nothing in the box matches ${g} (or the box has stopped: it keeps /w only until it idles out).`,","atom":"a0","author":"init","version":0},{"n":90,"text":"\t\t),","atom":"a0","author":"init","version":0},{"n":91,"text":"\t];","atom":"a0","author":"init","version":0},{"n":92,"text":"}","atom":"a0","author":"init","version":0}],"atoms":[{"atom":"a0","author":"init","message":"Start the project","time":1791506895507,"timeIso":"2026-10-09T00:48:15.507Z","publish":{"draft":null,"version":0,"agent":"init","message":"Start the project","time":1791506895507,"timeIso":"2026-10-09T00:48:15.507Z"}}]}