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

Versions 4 to 5

Compare

+63 −11 in 6 places
Lines 5–13 at 5 (were 5–11 at 4)
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";
Lines 109–156 at 5 (were 107–114 at 4)
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}.` : "",
Lines 170–185 at 5 (were 128–141 at 4)
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)] : []),
Lines 330–342 at 5 (were 286–293 at 4)
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(
Lines 389–402 at 5 (were 340–350 at 4)
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")) {
Lines 425–431 at 5 (were 373–379 at 4)
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> {
MCP
compare on this site's /mcp
CLI
abso diff 4 5 client/src/issues.ts --json
JSON
/christopher/abso-core/compare/4..5?file=client%2Fsrc%2Fissues.ts&format=json