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
MCP
show on this site's /mcp
CLI
abso show 29 --json
JSON
/christopher/abso-core/versions/29?format=json

Client: abso issue N --save-attachments <dir> saves each attachment on an issue and its comments once (an SVG's own file beside its drawing), outside the abso folder unless the place is ignored; MCP confines the folder like attach. abso export now stamps its folder with .abso-export, one line of JSON in a file with no extension, so the exported project's own formatter and linter pass it by; a folder stamped .abso-export.json or .avcs-export.json still counts as an export.

of shared·pinch··Not checked

Version 28 · Files at version 29

8 files, 162 lines added, 28 removed.

--- a/client/README.md
+++ b/client/README.md
@@ -152,9 +152,10 @@
152152same text, so the tools and the command line can't drift apart. `json: true` on
153153a call answers with the command's JSON instead. The folder and the token come from
154154where the server runs, as for the command line; `folder` on a call points it at
155−an abso folder inside that one. A call's `folder`, and the files the `issue`
156−tool's `attach` names, must be in the folder the server started in or below it:
157−anything outside is refused. Add it to Claude Code with:
155+an abso folder inside that one. A call's `folder`, the files the `issue`
156+tool's `attach` and `clean` name, and the folder its `save-attachments` writes
157+to, must be in the folder the server started in or below it: anything outside is
158+refused. Add it to Claude Code with:
158159
159160```
160161claude mcp add abso -- node <repo>/client/abso.ts mcp
--- a/client/src/api.ts
+++ b/client/src/api.ts
@@ -517,6 +517,29 @@
517517 return this.url(`/attachments/${id}`, this.issuesServer);
518518 }
519519
520+ /** An attachment's bytes, or with `source` the svg it was drawn from; refused past `max` bytes. */
521+ async attachmentBytes(id: string, source: boolean, max: number): Promise<Uint8Array> {
522+ if (this.issuesServer === undefined)
523+ throw new ApiError(`${this.config.server} has no Issues Worker beside it; ABSO_ISSUES_SERVER names one`);
524+ const url = `${this.attachmentUrl(id)}${source ? "/source" : ""}`;
525+ let res: Response;
526+ try {
527+ res = await fetch(url, {
528+ headers: this.headers(),
529+ signal: AbortSignal.timeout(Math.max(this.timeoutMs, 120_000)),
530+ });
531+ } catch (err) {
532+ const e = err as Error;
533+ throw new ApiError(
534+ `could not reach ${this.issuesServer}: ${(e.cause as Error | undefined)?.message ?? e.message}`,
535+ );
536+ }
537+ if (!res.ok) throw new ApiError(`${url} answered ${res.status}: ${errorSentence(await res.text())}`, res.status);
538+ const bytes = new Uint8Array(await res.arrayBuffer());
539+ if (bytes.length > max) throw new ApiError(`${url} sent ${bytes.length} bytes, more than an attachment may be`);
540+ return bytes;
541+ }
520543 /** An edit (abso issue 3): it tells the issue's watchers, and `also`, unless `notify` is false. null clears a parent or Agent. */
521544 issueEdit(
522545 id: number,
--- a/client/src/export.ts
+++ b/client/src/export.ts
@@ -1,8 +1,10 @@
11// abso export <dir> [--version N]: one published version of this folder's
22// space, written to a folder of its own, for a build that doesn't move while
3−// shared does (#37, Playtester 1). The folder gets .abso-export.json (.avcs-export.json before the rename) naming
4−// the version, to stamp the build with. Exporting again replaces the folder,
5−// keeping node_modules (and what --keep names) so a build needs no new install.
3+// shared does (#37, Playtester 1). The folder gets .abso-export naming the
4+// version, to stamp the build with: JSON on one line, in a file with no
5+// extension, so the exported project's own formatter and linter pass it by.
6+// Exporting again replaces the folder, keeping node_modules (and what --keep
7+// names) so a build needs no new install.
68//
79// The version is rebuilt as `abso run --at` rebuilds it (at.ts), from the
810// known copies and one compare; the server's listing of that version (#37,
@@ -19,9 +21,9 @@
1921import { type Refused, unsafePath } from "./safety.ts";
2022
2123/** The file an export leaves in its folder: what it holds, and the sign that the folder is one export may replace. */
22−export const EXPORT_STAMP = ".abso-export.json";
23−/** The name before the rename: an export made then still counts as one. */
24−const OLD_EXPORT_STAMP = ".avcs-export.json";
24+export const EXPORT_STAMP = ".abso-export";
25+/** Its earlier names: an export made then still counts as one. A .json name drew the project's formatter. */
26+const OLD_EXPORT_STAMPS = [".abso-export.json", ".avcs-export.json"];
2527
2628/** Where an export may go: outside the abso folder, or in a part of it abso leaves out. Empty, or an earlier export. */
2729function checkTarget(root: string, target: string): void {
@@ -38,8 +40,7 @@
3840 if (!statSync(target).isDirectory()) throw new UsageError(`${target} is a file; export to a folder`);
3941 if (
4042 readdirSync(target).length > 0 &&
41− !existsSync(join(target, EXPORT_STAMP)) &&
42− !existsSync(join(target, OLD_EXPORT_STAMP))
43+ ![EXPORT_STAMP, ...OLD_EXPORT_STAMPS].some((n) => existsSync(join(target, n)))
4344 ) {
4445 throw new UsageError(
4546 `${target} has files in it; export to an empty folder (an export replaces only a folder an earlier export made)`,
@@ -137,7 +138,7 @@
137138 files: written,
138139 exportedAt: new Date().toISOString(),
139140 };
140− writeFileSync(join(target, EXPORT_STAMP), `${JSON.stringify(stamp, null, 2)}\n`);
141+ writeFileSync(join(target, EXPORT_STAMP), `${JSON.stringify(stamp)}\n`);
141142 return {
142143 text: [
143144 `Exported version ${version} of ${space} to ${target}: ${plural(written, "file")}. ${EXPORT_STAMP} there names the version; abso export to the same folder replaces it.`,
--- a/client/src/issues.ts
+++ b/client/src/issues.ts
@@ -5,8 +5,8 @@
55// In review, and publish --done closes it. Other agents' and people's words
66// are quoted as JSON, so none can print as another line (#30).
77
8−import { readFileSync, statSync } from "node:fs";
9−import { basename, resolve } from "node:path";
8+import { mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
9+import { basename, join, resolve } from "node:path";
1010import {
1111 type Api,
1212 ApiError,
@@ -25,13 +25,15 @@
2525import { type Config, readMachineServers, trustedServers } from "./config.ts";
2626import { issuesServerFor, tokenGoesTo } from "./core.ts";
2727import { fromEnv } from "./env-names.ts";
28+import { ignoredHere } from "./fetch.ts";
29+import { loadIgnore, relativeTo } from "./folder.ts";
2830import { seenText, shortWhen } from "./times.ts";
2931
3032const q = (s: string): string => JSON.stringify(s);
3133
3234/** The folder, with its Api pointed at the Issues Worker: the token goes only where tokenGoesTo allows, as for the avcs server. */
33−function openIssues(env: Env): { config: Config; api: Api } {
34− const { config, api } = open(env);
35+function openIssues(env: Env): { root: string; config: Config; api: Api } {
36+ const { root, config, api } = open(env);
3537 const server = fromEnv(env.env, "ISSUES_SERVER") || issuesServerFor(config.server, readMachineServers(env.env));
3638 if (server === undefined)
3739 throw new UsageError(
@@ -43,7 +45,7 @@
4345 );
4446 }
4547 api.issuesServer = server;
46− return { config, api };
48+ return { root, config, api };
4749}
4850
4951function issueNumber(word: string | undefined, what = "an issue number"): number {
@@ -172,6 +174,57 @@
172174 ]);
173175}
174176
177+/** A saved attachment's file name: its id, then its own name with anything but letters, digits, . - _ made _. */
178+export function savedName(id: string, name: string): string {
179+ const own = (name.split(/[\\/]/).pop() ?? "")
180+ .replace(/[^A-Za-z0-9._-]/g, "_")
181+ .replace(/^\.+/, "_")
182+ .slice(0, 100);
183+ return `${id}-${own || "file"}`;
184+}
186+/**
187+ * abso issue N --save-attachments <folder>: every attachment on the issue and
188+ * its comments, written to that folder as <id>-<name>; an svg's own file
189+ * beside the png drawn from it. Not into the abso folder unless abso leaves
190+ * that place out, or the images would be recorded as edits.
191+ */
192+async function saveAttachments(api: Api, root: string, cwd: string, dir: string, page: IssuePage): Promise<Output> {
193+ const target = resolve(cwd, dir);
194+ const inside = target === resolve(root) ? "" : relativeTo(root, target);
195+ if (inside !== undefined && (inside === "" || !ignoredHere(loadIgnore(root), inside, true)))
196+ throw new UsageError(
197+ `${dir} is inside this abso folder, so abso would record the images as your edits. Save them outside the folder, or into a folder .absoignore leaves out`,
198+ );
199+ const seen = new Set<string>();
200+ const all = [...(page.issue.attachments ?? []), ...page.comments.flatMap((c) => c.attachments ?? [])].filter(
201+ (a) => !seen.has(a.id) && seen.add(a.id),
202+ );
203+ if (all.length === 0)
204+ return {
205+ text: `Issue ${page.issue.id} has no attachments.`,
206+ json: { issue: page.issue.id, folder: target, files: [] },
207+ };
208+ mkdirSync(target, { recursive: true });
209+ const files: { id: string; path: string; size: number }[] = [];
210+ for (const a of all) {
211+ const wanted = [{ name: a.name, source: false }, ...(a.source ? [{ name: a.source.name, source: true }] : [])];
212+ for (const w of wanted) {
213+ const bytes = await api.attachmentBytes(a.id, w.source, ATTACH_MAX);
214+ const path = join(target, savedName(a.id, w.name));
215+ writeFileSync(path, bytes);
216+ files.push({ id: a.id, path, size: bytes.length });
217+ }
218+ }
219+ return {
220+ text: [
221+ `Saved ${plural(files.length, "file")} from issue ${page.issue.id} to ${target}:`,
222+ ...files.map((f) => ` ${basename(f.path)}, ${sizeText(f.size)}`),
223+ ].join("\n"),
224+ json: { issue: page.issue.id, folder: target, files },
225+ };
226+}
175228/** An issue's page, as text. */
176229export function issuePage(p: IssuePage, api?: Pick<Api, "attachmentUrl">): string[] {
177230 const i = p.issue;
@@ -416,7 +469,15 @@
416469
417470export async function runIssue(args: Parsed, env: Env): Promise<Output> {
418471 const [first, ...rest] = args.positionals;
419− const { api } = openIssues(env);
472+ const { root, api } = openIssues(env);
473+ const saveTo = str(args, "save-attachments");
474+ if (saveTo !== undefined) {
475+ const other = [...args.flags.keys()].filter((f) => f !== "save-attachments" && f !== "json");
476+ if (other.length > 0 || first === "new" || first === "draft")
477+ throw new UsageError(
478+ `--save-attachments goes alone with an issue number: abso issue <N> --save-attachments <folder>${other.length > 0 ? `, not with --${other[0]}` : ""}`,
479+ );
480+ }
420481 if (first === "draft") return runDraft(api, args, rest);
421482 if (first === "new") {
422483 if (rest.length === 0)
@@ -522,6 +583,7 @@
522583 };
523584 }
524585 const page = await api.issue(id);
586+ if (saveTo !== undefined) return saveAttachments(api, root, env.cwd, saveTo, page);
525587 return { text: issuePage(page, api).join("\n"), json: { ...page } };
526588}
527589
--- a/client/src/main.ts
+++ b/client/src/main.ts
@@ -390,11 +390,12 @@
390390 "copy-to": "string",
391391 clean: "string",
392392 "dry-run": "boolean",
393+ "save-attachments": "string",
393394 },
394395 usage:
395− 'abso issue <N> --copy-to <project> [--clean <file>] [--dry-run] | abso issue <N> [--comment "..." [--attach <file,file>] | --object "..." | --drop | --reopen | --done [--done-by <version>]] | abso issue <N> [--title "..."] [--description "..."] [--parent <N|none>] [--agent <agent|none>] [--blocked-by <N,N|none>] [--label <l,l>] [--unlabel <l,l>] [--notify <who,who> | --quiet] | abso issue new "<title>" [--description "..."] [--parent <N>] [--lines <file>:<from>-<to>@<version>] [--agent <agent>] [--blocked-by <N,N>] [--notify <who,who>] [--label <l,l>] [--attach <file,file>]',
396+ 'abso issue <N> --save-attachments <folder> | abso issue <N> --copy-to <project> [--clean <file>] [--dry-run] | abso issue <N> [--comment "..." [--attach <file,file>] | --object "..." | --drop | --reopen | --done [--done-by <version>]] | abso issue <N> [--title "..."] [--description "..."] [--parent <N|none>] [--agent <agent|none>] [--blocked-by <N,N|none>] [--label <l,l>] [--unlabel <l,l>] [--notify <who,who> | --quiet] | abso issue new "<title>" [--description "..."] [--parent <N>] [--lines <file>:<from>-<to>@<version>] [--agent <agent>] [--blocked-by <N,N>] [--notify <who,who>] [--label <l,l>] [--attach <file,file>]',
396397 about:
397− "One issue: its description, Agent, Blocked by, labels, asks, comments, edits, sub-issues and watchers. --comment comments on it and --object objects; its agents hear either. --drop drops it. --reopen opens a dropped issue again. --done marks it done by hand, and --done-by <version> names the published version that did it. publish --done still marks it done too. --title, --description, --parent, --agent and --blocked-by edit it, and the edit tells its watchers (who opened it, its Agent and agents, its Reviewer, whoever was named in Notify, and whoever commented); --notify tells more people, --quiet tells nobody. --label adds labels and --unlabel takes them off (friction, area:client: lower-case letters, digits and - _ . :); a label-only edit tells nobody unless --notify names people. An issue is Blocked until each issue it's blocked by is Done. abso issue new opens one; --lines ties it to lines at a version of shared, --agent says who it's for, --notify tells people now, and --label labels it. --attach shot.png,after.png puts images on a new issue or a comment (png, jpeg, gif or webp, 10 MB each; the server checks the type by the bytes and takes out metadata such as where a photo was taken. An svg, up to 1 MB, is drawn as a png, and its own file is kept as a download, on servers that take svg), and prints each one's id for the text to point at; the issue's page lists them with a link. --copy-to <project> copies the issue into another project, with its comments, answered asks and labels, each keeping its author and time; --dry-run shows what would go and writes nothing, and --clean <file> gives cleaned texts by source id as JSON ({title, description, comments: [{id, text}], asks: [{id, question, answer}]}; a comment left out of a given list isn't copied). Copying out of a project on a live server takes an owner of that project. abso issue draft \"<title>\" [the same fields] saves a draft instead: yours alone, with no number and no news; abso issue draft <D> [fields] changes it, --open opens it as an issue, --delete deletes it.",
398+ "One issue: its description, Agent, Blocked by, labels, asks, comments, edits, sub-issues and watchers. --comment comments on it and --object objects; its agents hear either. --drop drops it. --reopen opens a dropped issue again. --done marks it done by hand, and --done-by <version> names the published version that did it. publish --done still marks it done too. --title, --description, --parent, --agent and --blocked-by edit it, and the edit tells its watchers (who opened it, its Agent and agents, its Reviewer, whoever was named in Notify, and whoever commented); --notify tells more people, --quiet tells nobody. --label adds labels and --unlabel takes them off (friction, area:client: lower-case letters, digits and - _ . :); a label-only edit tells nobody unless --notify names people. An issue is Blocked until each issue it's blocked by is Done. abso issue new opens one; --lines ties it to lines at a version of shared, --agent says who it's for, --notify tells people now, and --label labels it. --attach shot.png,after.png puts images on a new issue or a comment (png, jpeg, gif or webp, 10 MB each; the server checks the type by the bytes and takes out metadata such as where a photo was taken. An svg, up to 1 MB, is drawn as a png, and its own file is kept as a download, on servers that take svg), and prints each one's id for the text to point at; the issue's page lists them with a link, and --save-attachments <folder> saves every one on the issue and its comments there as <id>-<name> (an svg's own file too), outside the abso folder or where abso leaves files out. --copy-to <project> copies the issue into another project, with its comments, answered asks and labels, each keeping its author and time; --dry-run shows what would go and writes nothing, and --clean <file> gives cleaned texts by source id as JSON ({title, description, comments: [{id, text}], asks: [{id, question, answer}]}; a comment left out of a given list isn't copied). Copying out of a project on a live server takes an owner of that project. abso issue draft \"<title>\" [the same fields] saves a draft instead: yours alone, with no number and no news; abso issue draft <D> [fields] changes it, --open opens it as an issue, --delete deletes it.",
398399 run: runIssue,
399400 },
400401 ask: {
--- a/client/src/mcp.ts
+++ b/client/src/mcp.ts
@@ -120,8 +120,8 @@
120120 return rel === "" || (rel !== ".." && !rel.startsWith(`..${sep}`) && !isAbsolute(rel));
121121}
122122
123−/** The tool inputs that name files on this machine to read, comma-separated: each is confined like the folder. */
124−export const FILE_INPUTS = ["attach", "clean"] as const;
123+/** The tool inputs that name files or folders on this machine to read or write, comma-separated: each is confined like the folder. */
124+export const FILE_INPUTS = ["attach", "clean", "save-attachments"] as const;
125125
126126/**
127127 * Where a tool call runs, and what it may read: its folder and
@@ -149,7 +149,7 @@
149149 .filter((x) => x !== ""))
150150 if (!inside(start, resolve(folder, p)))
151151 return {
152− refused: `--${flag} ${p} is outside ${start}, the folder this server started in; a tool reads files from there or below`,
152+ refused: `--${flag} ${p} is outside ${start}, the folder this server started in; a tool reads and writes files only there or below`,
153153 };
154154 }
155155 return { folder };
--- a/client/test/attach.test.ts
+++ b/client/test/attach.test.ts
@@ -3,7 +3,7 @@
33// here is a stand-in that keeps what it was sent.
44
55import assert from "node:assert/strict";
6−import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
6+import { mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
77import { createServer, type Server } from "node:http";
88import type { AddressInfo } from "node:net";
99import { tmpdir } from "node:os";
@@ -43,6 +43,20 @@
4343 });
4444 if (req.url!.endsWith("/issue")) return json({ id: 7 });
4545 if (/\/issue\/\d+\/comment$/.test(req.url!)) return json({ id: 3 });
46+ // Issue 8 carries an svg-drawn image on itself and again on a comment, plus one more on the comment.
47+ const logo = { id: "a00000000000b", name: "../shot one.png", type: "image/png", size: 13 };
48+ if (req.method === "GET" && /\/issue\/8$/.test(req.url!))
49+ return json({
50+ issue: { id: 8, attachments: [{ ...logo, source: { name: "logo.svg", size: 20 } }] },
51+ comments: [{ attachments: [logo, { id: "a00000000000c", name: "after.png", type: "image/png", size: 13 }] }],
52+ edits: [],
53+ asks: [],
54+ claims: [],
55+ children: [],
56+ });
57+ const served = /\/attachments\/(a[0-9a-f]{12})(\/source)?$/.exec(req.url!);
58+ if (req.method === "GET" && served)
59+ return res.writeHead(200, { "content-type": "image/png" }).end(`${served[1]}${served[2] ?? ""}`);
4660 res.writeHead(404).end("{}");
4761 });
4862 });
@@ -142,6 +156,29 @@
142156 assert.equal(seen.length, from);
143157 });
144158
159+ it("--save-attachments saves each attachment once, an svg's own file too, outside the folder", async () => {
160+ const dir = await folder();
161+ const out = mkdtempSync(join(tmpdir(), "abso-saved-"));
162+ dirs.push(out);
163+ const r = await avcs(dir, ["issue", "8", "--save-attachments", join(out, "images")]);
164+ assert.equal(r.exit, 0, r.out);
165+ const names = readdirSync(join(out, "images")).sort();
166+ assert.deepEqual(names, ["a00000000000b-logo.svg", "a00000000000b-shot_one.png", "a00000000000c-after.png"]);
167+ assert.equal(readFileSync(join(out, "images", "a00000000000b-logo.svg"), "utf8"), "a00000000000b/source");
168+ assert.equal(readFileSync(join(out, "images", "a00000000000c-after.png"), "utf8"), "a00000000000c");
169+ assert.equal((r.json as { files: unknown[] }).files.length, 3);
170+ // Into the folder only where abso leaves files out, or they'd be recorded as edits.
171+ const inside = await avcs(dir, ["issue", "8", "--save-attachments", "images"]);
172+ assert.equal(inside.exit, 1);
173+ assert.match(inside.out, /inside this abso folder/);
174+ assert.equal((await avcs(dir, ["issue", "8", "--save-attachments", "."])).exit, 1);
175+ writeFileSync(join(dir, ".absoignore"), "saved/\n");
176+ assert.equal((await avcs(dir, ["issue", "8", "--save-attachments", "saved"])).exit, 0);
177+ const mixed = await avcs(dir, ["issue", "8", "--save-attachments", out, "--comment", "x"]);
178+ assert.equal(mixed.exit, 1);
179+ assert.match(mixed.out, /--save-attachments goes alone/);
180+ });
145182 it("an issue's page lists its attachments and each comment's, with links", () => {
146183 const page = {
147184 issue: {
--- a/client/test/client.test.ts
+++ b/client/test/client.test.ts
@@ -1925,16 +1925,22 @@
19251925 const one = await avcs(tester, "export", out, "--version", "1");
19261926 assert.equal(one.exit, 0, one.out);
19271927 assert.equal(one.json.version, 1);
1928− assert.deepEqual(listAll(out), [".abso-export.json", ".absoignore", "index.html", "src/game.ts", "src/new.ts"]);
1928+ assert.deepEqual(listAll(out), [".abso-export", ".absoignore", "index.html", "src/game.ts", "src/new.ts"]);
19291929 assert.equal(read(out, "src/game.ts"), "game v1\n");
19301930 assert.equal(read(out, "index.html"), "<p>v0</p>\n", "published files, not the unpublished edit");
1931− assert.equal(JSON.parse(read(out, ".abso-export.json")).version, 1);
1932− // The newest by default; an earlier export's folder is replaced whole.
1931+ // One line, no extension: the exported project's own formatter has nothing to say about it.
1932+ const stamp = read(out, ".abso-export");
1933+ assert.equal(stamp.split("\n").length, 2, stamp);
1934+ assert.equal(JSON.parse(stamp).version, 1);
1935+ // The newest by default; an earlier export's folder is replaced whole, one stamped by an older client too.
1936+ rmSync(join(out, ".abso-export"));
1937+ write(out, { ".abso-export.json": "{}\n" });
19331938 const newest = await main(["export", out], { cwd: tester, env: ENV, write: () => {} });
19341939 assert.match(
19351940 newest.stdout,
1936− /^Exported version 2 of shared to .*build: 4 files\. \.abso-export\.json there names the version/,
1941+ /^Exported version 2 of shared to .*build: 4 files\. \.abso-export there names the version/,
19371942 );
1943+ assert.equal(existsSync(join(out, ".abso-export.json")), false);
19381944 assert.equal(read(out, "src/game.ts"), "game v2\n");
19391945 // Exporting again keeps the build's node_modules (abso never exports it) and what --keep names, and nothing else.
19401946 write(out, {
@@ -2694,6 +2700,9 @@
26942700 assert.match(refused({ folder: "sub", attach: "../../x.png" }), /is outside/);
26952701 assert.match(refused({ clean: "../clean.json" }), /^--clean \.\.\/clean\.json is outside/);
26962702 assert.deepEqual(confineCall(start, { clean: "clean.json" }), { folder: start });
2703+ // A folder a tool writes to is confined the same way.
2704+ assert.match(refused({ "save-attachments": "../images" }), /^--save-attachments \.\.\/images is outside/);
2705+ assert.deepEqual(confineCall(start, { "save-attachments": "images" }), { folder: start });
26972706 assert.deepEqual(confineCall(start, { folder: "sub", attach: "../a.txt" }), { folder: join(start, "sub") });
26982707 const server = mcp(start);
26992708 try {