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 5 --json
JSON
/christopher/abso-core/versions/5?format=json

abso issue new and abso issue N --comment take --attach <file,file> (abso issue 171). Each file goes up to the Issues Worker first (POST /p/:project/a/:agent/attachments, the bytes as the body and the name URI-encoded in X-Avcs-Name), and the write carries the ids the uploads answered. Nothing is sent if a file is missing or over 10 MB. --attach anywhere else is refused. The issue's page lists each attachment under the issue or comment carrying it: id, name, size and its link. The wire types gain Attachment and attachments?. MCP's issue tool takes attach too, since its parameters come from the flags. The server side is abso 621 (off until Cloud binds the bucket). Tests: client/test/attach.test.ts, against a stand-in Issues server. Checked: biome ci, npm run check (698 pass).

of shared·pinch··Not checked

Version 4 · Files at version 5

5 files, 292 lines added, 19 removed.

--- a/client/src/api.ts
+++ b/client/src/api.ts
@@ -50,7 +50,7 @@
5050 WhereAnswer,
5151 WhyAnswer,
5252} from "./history-answers.ts";
53−import type { Ask, Draft, DraftBody, News as IssueNews, IssuePage, IssueRow } from "./issues-wire.ts";
53+import type { Ask, Attachment, Draft, DraftBody, News as IssueNews, IssuePage, IssueRow } from "./issues-wire.ts";
5454import type { Modes } from "./modes.ts";
5555
5656export * from "./api-answers.ts";
@@ -65,7 +65,7 @@
6565} from "./box-run.ts";
6666export * from "./ci-answers.ts";
6767export * from "./history-answers.ts";
68−export type { Ask, Draft, DraftBody, IssueNews, IssuePage, IssueRow };
68+export type { Ask, Attachment, Draft, DraftBody, IssueNews, IssuePage, IssueRow };
6969
7070/**
7171 * How long a call may take: the base, plus 1 s for each 100 KB it sends
@@ -400,10 +400,39 @@
400400 }
401401 }
402402
403− issueOpen(body: DraftBody & { title: string }): Promise<{ id: number; news?: IssueNews }> {
403+ issueOpen(body: DraftBody & { title: string; attachments?: string[] }): Promise<{ id: number; news?: IssueNews }> {
404404 return this.#issues("POST", this.agentPath("issue"), body);
405405 }
406406
407+ /** Uploads an image to the Issues Worker (abso issue 171): it checks the type by the bytes, strips metadata and answers its id. */
408+ async attachmentUpload(bytes: Uint8Array, name: string): Promise<Attachment> {
409+ if (this.issuesServer === undefined)
410+ throw new ApiError(`${this.config.server} has no Issues Worker beside it; AVCS_ISSUES_SERVER names one`);
411+ const path = this.agentPath("attachments");
412+ let res: Response;
413+ try {
414+ res = await fetch(this.url(path, this.issuesServer), {
415+ method: "POST",
416+ headers: { ...this.headers("application/octet-stream"), "x-avcs-name": encodeURIComponent(name) },
417+ body: bytes as Uint8Array<ArrayBuffer>,
418+ signal: AbortSignal.timeout(Math.max(this.timeoutMs, 120_000)),
419+ });
420+ } catch (err) {
421+ const e = err as Error;
422+ throw new ApiError(
423+ `could not reach ${this.issuesServer}: ${(e.cause as Error | undefined)?.message ?? e.message}`,
424+ );
425+ }
426+ const text = await res.text();
427+ if (!res.ok) throw new ApiError(`uploading ${name} answered ${res.status}: ${errorSentence(text)}`, res.status);
428+ return JSON.parse(text) as Attachment;
429+ }
431+ /** Where an attachment is served. */
432+ attachmentUrl(id: string): string {
433+ return this.url(`/attachments/${id}`, this.issuesServer);
434+ }
407436 /** An edit (abso issue 3): it tells the issue's watchers, and `also`, unless `notify` is false. null clears a parent or Agent. */
408437 issueEdit(
409438 id: number,
@@ -422,8 +451,17 @@
422451 return this.#issues("POST", this.agentPath(`issue/${id}/edit`), body);
423452 }
424453
425− issueComment(id: number, text: string, objection = false): Promise<{ id: number; news?: IssueNews }> {
426− return this.#issues("POST", this.agentPath(`issue/${id}/comment`), { text, ...(objection ? { objection } : {}) });
454+ issueComment(
455+ id: number,
456+ text: string,
457+ objection = false,
458+ attachments: readonly string[] = [],
459+ ): Promise<{ id: number; news?: IssueNews }> {
460+ return this.#issues("POST", this.agentPath(`issue/${id}/comment`), {
461+ text,
462+ ...(objection ? { objection } : {}),
463+ ...(attachments.length > 0 ? { attachments } : {}),
464+ });
427465 }
428466
429467 issueDrop(id: number): Promise<{ news?: IssueNews }> {
--- a/client/src/issues-wire.ts
+++ b/client/src/issues-wire.ts
@@ -45,8 +45,19 @@
4545 kind: "comment" | "objection";
4646 text: string;
4747 at: number;
48+ /** Images it carries (abso issue 171); left out when none. */
49+ attachments?: Attachment[];
4850}
4951
52+/** An image on an issue or comment (abso issue 171): GET /p/:project/attachments/<id> serves it. */
53+export interface Attachment {
54+ /** "a" and the first 12 hex of its sha256: what a text points at. */
55+ id: string;
56+ name: string;
57+ type: string;
58+ size: number;
59+}
5061export interface Ask {
5162 id: number;
5263 /** The issue it's on; none for a decision that belongs to no issue. */
@@ -74,7 +85,7 @@
7485}
7586
7687export interface IssuePage {
77− issue: IssueRow & { description: string; lines: Lines | null; watchers: string[] };
88+ issue: IssueRow & { description: string; lines: Lines | null; watchers: string[]; attachments?: Attachment[] };
7889 comments: Comment[];
7990 edits: Edit[];
8091 asks: Ask[];
--- a/client/src/issues.ts
+++ b/client/src/issues.ts
@@ -5,7 +5,9 @@
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 type { Api, Ask, Draft, DraftBody, IssuePage, IssueRow } from "./api.ts";
8+import { readFileSync, statSync } from "node:fs";
9+import { basename, resolve } from "node:path";
10+import type { Api, Ask, Attachment, Draft, DraftBody, IssuePage, IssueRow } from "./api.ts";
911import { bool, type Parsed, str, UsageError } from "./args.ts";
1012import { type Env, type Output, open, plural } from "./commands.ts";
1113import { type Config, readMachineServers, trustedServers } from "./config.ts";
@@ -107,8 +109,48 @@
107109 .filter((v) => v !== "");
108110}
109111
112+/** The most one attachment may be: the Issues Worker's cap, checked here before sending (abso issue 171). */
113+const ATTACH_MAX = 10 * 1024 * 1024;
115+/** Uploads each file --attach names (comma-separated), in order, and answers their ids. Nothing is sent if a file is missing or too big. */
116+async function uploadAttachments(api: Api, cwd: string, value: string | undefined): Promise<string[]> {
117+ if (value === undefined) return [];
118+ const paths = listOf(value);
119+ if (paths.length === 0) throw new UsageError("--attach names files, comma-separated: --attach shot.png,after.png");
120+ const files = paths.map((p) => {
121+ const full = resolve(cwd, p);
122+ let size: number;
123+ try {
124+ size = statSync(full).size;
125+ } catch {
126+ throw new UsageError(`--attach ${p}: no such file`);
127+ }
128+ if (size > ATTACH_MAX)
129+ throw new UsageError(`--attach ${p} is ${sizeText(size)}; one attachment is at most ${sizeText(ATTACH_MAX)}`);
130+ return { full, name: basename(full) };
131+ });
132+ const ids: string[] = [];
133+ for (const f of files) ids.push((await api.attachmentUpload(readFileSync(f.full), f.name)).id);
134+ return ids;
135+}
137+function sizeText(n: number): string {
138+ return n < 1024 ? `${n} B` : n < 1024 * 1024 ? `${Math.round(n / 1024)} KB` : `${(n / (1024 * 1024)).toFixed(1)} MB`;
139+}
141+/** Attachments as lines under what carries them: name, size and where it's served. */
142+function attachmentLines(
143+ api: Pick<Api, "attachmentUrl"> | undefined,
144+ files: readonly Attachment[] | undefined,
145+ indent: string,
146+): string[] {
147+ return (files ?? []).map(
148+ (a) => `${indent}attached ${a.id}: ${q(a.name)}, ${sizeText(a.size)}${api ? `, ${api.attachmentUrl(a.id)}` : ""}`,
149+ );
150+}
110152/** An issue's page, as text. */
111−export function issuePage(p: IssuePage): string[] {
153+export function issuePage(p: IssuePage, api?: Pick<Api, "attachmentUrl">): string[] {
112154 const i = p.issue;
113155 const facts = [
114156 i.parent !== null ? `Under issue ${i.parent}.` : "",
@@ -128,14 +170,16 @@
128170 facts.join(" "),
129171 ...(i.lines ? [`From ${i.lines.file} lines ${i.lines.from}-${i.lines.to} at version ${i.lines.version}.`] : []),
130172 ...(i.description !== "" ? ["", ...i.description.split("\n").map((l) => ` ${l}`)] : []),
173+ ...attachmentLines(api, i.attachments, " "),
131174 ...(p.asks.length > 0 ? ["", "Asks:", ...p.asks.map(askLine)] : []),
132175 ...(p.comments.length > 0
133176 ? [
134177 "",
135178 "Comments:",
136− ...p.comments.map(
137− (c) => ` ${c.by}${c.kind === "objection" ? " objects" : ""}, ${shortWhen(c.at)}: ${q(c.text)}`,
138− ),
179+ ...p.comments.flatMap((c) => [
180+ ` ${c.by}${c.kind === "objection" ? " objects" : ""}, ${shortWhen(c.at)}: ${q(c.text)}`,
181+ ...attachmentLines(api, c.attachments, " "),
182+ ]),
139183 ]
140184 : []),
141185 ...((p.edits ?? []).length > 0 ? ["", "Edits:", ...p.edits.map(editLine)] : []),
@@ -286,8 +330,13 @@
286330 throw new UsageError(
287331 'avcs issue new "<title>" [--description "..."] [--parent <N>] [--lines <file>:<from>-<to>@<version>] [--agent <agent>] [--blocked-by <N,N>] [--notify <who,who>] [--label <l,l>]',
288332 );
289− const r = await api.issueOpen({ ...openFields(args, rest.join(" ")), title: rest.join(" ") });
290− return { text: `Opened issue ${r.id}. avcs start "..." --issue ${r.id} starts on it.`, json: { id: r.id } };
333+ const fields = { ...openFields(args, rest.join(" ")), title: rest.join(" ") };
334+ const attachments = await uploadAttachments(api, env.cwd, str(args, "attach"));
335+ const r = await api.issueOpen({ ...fields, ...(attachments.length > 0 ? { attachments } : {}) });
336+ return {
337+ text: `Opened issue ${r.id}${attachments.length > 0 ? ` with ${plural(attachments.length, "attachment")} (${attachments.join(", ")})` : ""}. avcs start "..." --issue ${r.id} starts on it.`,
338+ json: { id: r.id, ...(attachments.length > 0 ? { attachments } : {}) },
339+ };
291340 }
292341 if (first === undefined || rest.length > 0)
293342 throw new UsageError(
@@ -340,11 +389,14 @@
340389 throw new UsageError(
341390 "--quiet and --notify go with an edit (--title, --description, --parent, --agent, --blocked-by, --label or --unlabel)",
342391 );
392+ if (str(args, "attach") !== undefined && comment === undefined && object === undefined)
393+ throw new UsageError("--attach goes with avcs issue new or --comment (or --object)");
343394 if (comment !== undefined || object !== undefined) {
344− const r = await api.issueComment(id, (comment ?? object)!, object !== undefined);
395+ const attachments = await uploadAttachments(api, env.cwd, str(args, "attach"));
396+ const r = await api.issueComment(id, (comment ?? object)!, object !== undefined, attachments);
345397 return {
346− text: `${object !== undefined ? "Objected" : "Commented"} on issue ${id}. Its agents hear it.`,
347− json: { id: r.id, issue: id },
398+ text: `${object !== undefined ? "Objected" : "Commented"} on issue ${id}${attachments.length > 0 ? ` with ${plural(attachments.length, "attachment")} (${attachments.join(", ")})` : ""}. Its agents hear it.`,
399+ json: { id: r.id, issue: id, ...(attachments.length > 0 ? { attachments } : {}) },
348400 };
349401 }
350402 if (bool(args, "drop")) {
@@ -373,7 +425,7 @@
373425 };
374426 }
375427 const page = await api.issue(id);
376− return { text: issuePage(page).join("\n"), json: { ...page } };
428+ return { text: issuePage(page, api).join("\n"), json: { ...page } };
377429}
378430
379431export async function runAsk(args: Parsed, env: Env): Promise<Output> {
--- a/client/src/main.ts
+++ b/client/src/main.ts
@@ -365,11 +365,12 @@
365365 unlabel: "string",
366366 open: "boolean",
367367 delete: "boolean",
368+ attach: "string",
368369 },
369370 usage:
370− 'avcs issue <N> [--comment "..." | --object "..." | --drop | --reopen | --done [--done-by <version>]] | avcs 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] | avcs issue new "<title>" [--description "..."] [--parent <N>] [--lines <file>:<from>-<to>@<version>] [--agent <agent>] [--blocked-by <N,N>] [--notify <who,who>] [--label <l,l>]',
371+ 'avcs issue <N> [--comment "..." [--attach <file,file>] | --object "..." | --drop | --reopen | --done [--done-by <version>]] | avcs 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] | avcs 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>]',
371372 about:
372− "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. avcs 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. avcs issue draft \"<title>\" [the same fields] saves a draft instead: yours alone, with no number and no news; avcs issue draft <D> [fields] changes it, --open opens it as an issue, --delete deletes it.",
373+ "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. avcs 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), and prints each one's id for the text to point at; the issue's page lists them with a link. avcs issue draft \"<title>\" [the same fields] saves a draft instead: yours alone, with no number and no news; avcs issue draft <D> [fields] changes it, --open opens it as an issue, --delete deletes it.",
373374 run: runIssue,
374375 },
375376 ask: {
--- /dev/null
+++ b/client/test/attach.test.ts
@@ -0,0 +1,171 @@
1+// --attach (abso issue 171): images go up to the Issues Worker before the
2+// write that carries them, and the issue's page lists them. The Issues server
3+// here is a stand-in that keeps what it was sent.
4+
5+import assert from "node:assert/strict";
6+import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
7+import { createServer, type Server } from "node:http";
8+import type { AddressInfo } from "node:net";
9+import { tmpdir } from "node:os";
10+import { join } from "node:path";
11+import { after, before, describe, it } from "node:test";
12+import { issuePage } from "../src/issues.ts";
13+import type { IssuePage } from "../src/issues-wire.ts";
14+import { main } from "../src/main.ts";
15+import { type Fake, startFake } from "./fake-server.ts";
17+const TOKEN = "test-token-not-secret";
18+let fake: Fake;
19+let issues: Server;
20+let issuesUrl: string;
21+const seen: { method: string; url: string; headers: Record<string, string | string[] | undefined>; body: Buffer }[] =
22+ [];
23+const dirs: string[] = [];
25+before(async () => {
26+ fake = await startFake(0, TOKEN);
27+ issues = createServer((req, res) => {
28+ const parts: Buffer[] = [];
29+ req.on("data", (c: Buffer) => parts.push(c));
30+ req.on("end", () => {
31+ const body = Buffer.concat(parts);
32+ seen.push({ method: req.method!, url: req.url!, headers: req.headers, body });
33+ const json = (o: unknown) => res.writeHead(200, { "content-type": "application/json" }).end(JSON.stringify(o));
34+ if (req.url!.endsWith("/attachments"))
35+ return json({
36+ id: `a${String(seen.length).padStart(12, "0")}`,
37+ name: "x",
38+ type: "image/png",
39+ size: body.length,
40+ });
41+ if (req.url!.endsWith("/issue")) return json({ id: 7 });
42+ if (/\/issue\/\d+\/comment$/.test(req.url!)) return json({ id: 3 });
43+ res.writeHead(404).end("{}");
44+ });
45+ });
46+ await new Promise<void>((ok) => issues.listen(0, "127.0.0.1", ok));
47+ issuesUrl = `http://127.0.0.1:${(issues.address() as AddressInfo).port}`;
48+});
49+after(async () => {
50+ await fake.close();
51+ await new Promise((ok) => issues.close(ok));
52+ for (const d of dirs) rmSync(d, { recursive: true, force: true, maxRetries: 5 });
53+});
55+const ENV = (): Record<string, string> => ({
56+ AVCS_TOKEN: TOKEN,
57+ AVCS_HOOK_FORCE: "1",
58+ AVCS_ISSUES_SERVER: issuesUrl,
59+ AVCS_SERVERS_FILE: "no-servers.json",
60+});
62+async function avcs(cwd: string, argv: string[]): Promise<{ exit: number; out: string; json?: unknown }> {
63+ const r = await main([...argv, "--json"], { cwd, env: ENV(), write: () => {} });
64+ let json: unknown;
65+ try {
66+ json = JSON.parse(r.stdout);
67+ } catch {}
68+ return { exit: r.exit, out: r.stdout + r.stderr, json };
69+}
71+let n = 0;
72+async function folder(): Promise<string> {
73+ const dir = mkdtempSync(join(tmpdir(), "abso-attach-"));
74+ dirs.push(dir);
75+ const r = await avcs(dir, ["init", "--server", fake.url, "--project", `attach${++n}`, "--agent", "ann"]);
76+ assert.equal(r.exit, 0, r.out);
77+ writeFileSync(join(dir, "shot.png"), Buffer.from([0x89, 0x50, 0x4e, 0x47, 1, 2, 3]));
78+ writeFileSync(join(dir, "after.png"), Buffer.from([0x89, 0x50, 0x4e, 0x47, 4, 5]));
79+ return dir;
80+}
82+describe("--attach (abso issue 171)", () => {
83+ it("uploads each file, then opens the issue carrying their ids", async () => {
84+ const dir = await folder();
85+ const from = seen.length;
86+ const r = await avcs(dir, ["issue", "new", "The page after the fix", "--attach", "shot.png,after.png"]);
87+ assert.equal(r.exit, 0, r.out);
88+ const calls = seen.slice(from);
89+ assert.deepEqual(
90+ calls.map((c) => `${c.method} ${c.url.replace(/^\/p\/[^/]+/, "")}`),
91+ ["POST /a/ann/attachments", "POST /a/ann/attachments", "POST /a/ann/issue"],
92+ );
93+ assert.equal(calls[0]!.headers["x-avcs-name"], "shot.png");
94+ assert.equal(calls[0]!.headers["content-type"], "application/octet-stream");
95+ assert.deepEqual([...calls[0]!.body], [0x89, 0x50, 0x4e, 0x47, 1, 2, 3]);
96+ const opened = JSON.parse(calls[2]!.body.toString()) as { title: string; attachments: string[] };
97+ assert.equal(opened.title, "The page after the fix");
98+ assert.equal(opened.attachments.length, 2);
99+ assert.deepEqual((r.json as { attachments: string[] }).attachments, opened.attachments);
100+ });
102+ it("goes on a comment too, and nowhere else", async () => {
103+ const dir = await folder();
104+ const from = seen.length;
105+ const r = await avcs(dir, ["issue", "7", "--comment", "after", "--attach", "shot.png"]);
106+ assert.equal(r.exit, 0, r.out);
107+ const comment = JSON.parse(seen.at(-1)!.body.toString()) as { text: string; attachments: string[] };
108+ assert.equal(comment.text, "after");
109+ assert.equal(comment.attachments.length, 1);
110+ assert.equal(seen.length - from, 2);
111+ const alone = await avcs(dir, ["issue", "7", "--attach", "shot.png"]);
112+ assert.equal(alone.exit, 1);
113+ assert.match(alone.out, /--attach goes with avcs issue new or --comment/);
114+ });
116+ it("sends nothing when a file is missing", async () => {
117+ const dir = await folder();
118+ const from = seen.length;
119+ const r = await avcs(dir, ["issue", "new", "T", "--attach", "shot.png,nope.png"]);
120+ assert.equal(r.exit, 1);
121+ assert.match(r.out, /--attach nope.png: no such file/);
122+ assert.equal(seen.length, from);
123+ });
125+ it("an issue's page lists its attachments and each comment's, with links", () => {
126+ const page = {
127+ issue: {
128+ id: 7,
129+ title: "T",
130+ status: "open",
131+ opened: { by: "ann", at: 0 },
132+ agent: null,
133+ agents: [],
134+ blockedBy: [],
135+ labels: [],
136+ versions: [],
137+ waitingOn: [],
138+ parent: null,
139+ children: 0,
140+ updated: 0,
141+ closed: null,
142+ description: "",
143+ lines: null,
144+ watchers: [],
145+ attachments: [{ id: "a0123456789ab", name: "shot.png", type: "image/png", size: 2048 }],
146+ },
147+ comments: [
148+ {
149+ id: 1,
150+ by: "bob",
151+ kind: "comment",
152+ text: "same here",
153+ at: 0,
154+ attachments: [{ id: "a00000000000f", name: "mine.png", type: "image/png", size: 3 * 1024 * 1024 }],
155+ },
156+ ],
157+ edits: [],
158+ asks: [],
159+ claims: [],
160+ children: [],
161+ } as unknown as IssuePage;
162+ const text = issuePage(page, {
163+ attachmentUrl: (id: string) => `https://issues.example/p/x/attachments/${id}`,
164+ }).join("\n");
165+ assert.match(
166+ text,
167+ /attached a0123456789ab: "shot.png", 2 KB, https:\/\/issues.example\/p\/x\/attachments\/a0123456789ab/,
168+ );
169+ assert.match(text, /\n {4}attached a00000000000f: "mine.png", 3.0 MB/);
170+ });
171+});