{"draft":null,"from":4,"to":5,"files":[{"path":"client/src/issues.ts","added":63,"removed":11,"diff":"--- a/client/src/issues.ts\n+++ b/client/src/issues.ts\n@@ -5,7 +5,9 @@\n // In review, and publish --done closes it. Other agents' and people's words\n // are quoted as JSON, so none can print as another line (#30).\n \n-import type { Api, Ask, Draft, DraftBody, IssuePage, IssueRow } from \"./api.ts\";\n+import { readFileSync, statSync } from \"node:fs\";\n+import { basename, resolve } from \"node:path\";\n+import type { Api, Ask, Attachment, Draft, DraftBody, IssuePage, IssueRow } from \"./api.ts\";\n import { bool, type Parsed, str, UsageError } from \"./args.ts\";\n import { type Env, type Output, open, plural } from \"./commands.ts\";\n import { type Config, readMachineServers, trustedServers } from \"./config.ts\";\n@@ -107,8 +109,48 @@\n \t\t\t\t.filter((v) => v !== \"\");\n }\n \n+/** The most one attachment may be: the Issues Worker's cap, checked here before sending (abso issue 171). */\n+const ATTACH_MAX = 10 * 1024 * 1024;\n+\n+/** Uploads each file --attach names (comma-separated), in order, and answers their ids. Nothing is sent if a file is missing or too big. */\n+async function uploadAttachments(api: Api, cwd: string, value: string | undefined): Promise<string[]> {\n+\tif (value === undefined) return [];\n+\tconst paths = listOf(value);\n+\tif (paths.length === 0) throw new UsageError(\"--attach names files, comma-separated: --attach shot.png,after.png\");\n+\tconst files = paths.map((p) => {\n+\t\tconst full = resolve(cwd, p);\n+\t\tlet size: number;\n+\t\ttry {\n+\t\t\tsize = statSync(full).size;\n+\t\t} catch {\n+\t\t\tthrow new UsageError(`--attach ${p}: no such file`);\n+\t\t}\n+\t\tif (size > ATTACH_MAX)\n+\t\t\tthrow new UsageError(`--attach ${p} is ${sizeText(size)}; one attachment is at most ${sizeText(ATTACH_MAX)}`);\n+\t\treturn { full, name: basename(full) };\n+\t});\n+\tconst ids: string[] = [];\n+\tfor (const f of files) ids.push((await api.attachmentUpload(readFileSync(f.full), f.name)).id);\n+\treturn ids;\n+}\n+\n+function sizeText(n: number): string {\n+\treturn n < 1024 ? `${n} B` : n < 1024 * 1024 ? `${Math.round(n / 1024)} KB` : `${(n / (1024 * 1024)).toFixed(1)} MB`;\n+}\n+\n+/** Attachments as lines under what carries them: name, size and where it's served. */\n+function attachmentLines(\n+\tapi: Pick<Api, \"attachmentUrl\"> | undefined,\n+\tfiles: readonly Attachment[] | undefined,\n+\tindent: string,\n+): string[] {\n+\treturn (files ?? []).map(\n+\t\t(a) => `${indent}attached ${a.id}: ${q(a.name)}, ${sizeText(a.size)}${api ? `, ${api.attachmentUrl(a.id)}` : \"\"}`,\n+\t);\n+}\n+\n /** An issue's page, as text. */\n-export function issuePage(p: IssuePage): string[] {\n+export function issuePage(p: IssuePage, api?: Pick<Api, \"attachmentUrl\">): string[] {\n \tconst i = p.issue;\n \tconst facts = [\n \t\ti.parent !== null ? `Under issue ${i.parent}.` : \"\",\n@@ -128,14 +170,16 @@\n \t\tfacts.join(\" \"),\n \t\t...(i.lines ? [`From ${i.lines.file} lines ${i.lines.from}-${i.lines.to} at version ${i.lines.version}.`] : []),\n \t\t...(i.description !== \"\" ? [\"\", ...i.description.split(\"\\n\").map((l) => `  ${l}`)] : []),\n+\t\t...attachmentLines(api, i.attachments, \"  \"),\n \t\t...(p.asks.length > 0 ? [\"\", \"Asks:\", ...p.asks.map(askLine)] : []),\n \t\t...(p.comments.length > 0\n \t\t\t? [\n \t\t\t\t\t\"\",\n \t\t\t\t\t\"Comments:\",\n-\t\t\t\t\t...p.comments.map(\n-\t\t\t\t\t\t(c) => `  ${c.by}${c.kind === \"objection\" ? \" objects\" : \"\"}, ${shortWhen(c.at)}: ${q(c.text)}`,\n-\t\t\t\t\t),\n+\t\t\t\t\t...p.comments.flatMap((c) => [\n+\t\t\t\t\t\t`  ${c.by}${c.kind === \"objection\" ? \" objects\" : \"\"}, ${shortWhen(c.at)}: ${q(c.text)}`,\n+\t\t\t\t\t\t...attachmentLines(api, c.attachments, \"    \"),\n+\t\t\t\t\t]),\n \t\t\t\t]\n \t\t\t: []),\n \t\t...((p.edits ?? []).length > 0 ? [\"\", \"Edits:\", ...p.edits.map(editLine)] : []),\n@@ -286,8 +330,13 @@\n \t\t\tthrow new UsageError(\n \t\t\t\t'avcs issue new \"<title>\" [--description \"...\"] [--parent <N>] [--lines <file>:<from>-<to>@<version>] [--agent <agent>] [--blocked-by <N,N>] [--notify <who,who>] [--label <l,l>]',\n \t\t\t);\n-\t\tconst r = await api.issueOpen({ ...openFields(args, rest.join(\" \")), title: rest.join(\" \") });\n-\t\treturn { text: `Opened issue ${r.id}. avcs start \"...\" --issue ${r.id} starts on it.`, json: { id: r.id } };\n+\t\tconst fields = { ...openFields(args, rest.join(\" \")), title: rest.join(\" \") };\n+\t\tconst attachments = await uploadAttachments(api, env.cwd, str(args, \"attach\"));\n+\t\tconst r = await api.issueOpen({ ...fields, ...(attachments.length > 0 ? { attachments } : {}) });\n+\t\treturn {\n+\t\t\ttext: `Opened issue ${r.id}${attachments.length > 0 ? ` with ${plural(attachments.length, \"attachment\")} (${attachments.join(\", \")})` : \"\"}. avcs start \"...\" --issue ${r.id} starts on it.`,\n+\t\t\tjson: { id: r.id, ...(attachments.length > 0 ? { attachments } : {}) },\n+\t\t};\n \t}\n \tif (first === undefined || rest.length > 0)\n \t\tthrow new UsageError(\n@@ -340,11 +389,14 @@\n \t\tthrow new UsageError(\n \t\t\t\"--quiet and --notify go with an edit (--title, --description, --parent, --agent, --blocked-by, --label or --unlabel)\",\n \t\t);\n+\tif (str(args, \"attach\") !== undefined && comment === undefined && object === undefined)\n+\t\tthrow new UsageError(\"--attach goes with avcs issue new or --comment (or --object)\");\n \tif (comment !== undefined || object !== undefined) {\n-\t\tconst r = await api.issueComment(id, (comment ?? object)!, object !== undefined);\n+\t\tconst attachments = await uploadAttachments(api, env.cwd, str(args, \"attach\"));\n+\t\tconst r = await api.issueComment(id, (comment ?? object)!, object !== undefined, attachments);\n \t\treturn {\n-\t\t\ttext: `${object !== undefined ? \"Objected\" : \"Commented\"} on issue ${id}. Its agents hear it.`,\n-\t\t\tjson: { id: r.id, issue: id },\n+\t\t\ttext: `${object !== undefined ? \"Objected\" : \"Commented\"} on issue ${id}${attachments.length > 0 ? ` with ${plural(attachments.length, \"attachment\")} (${attachments.join(\", \")})` : \"\"}. Its agents hear it.`,\n+\t\t\tjson: { id: r.id, issue: id, ...(attachments.length > 0 ? { attachments } : {}) },\n \t\t};\n \t}\n \tif (bool(args, \"drop\")) {\n@@ -373,7 +425,7 @@\n \t\t};\n \t}\n \tconst page = await api.issue(id);\n-\treturn { text: issuePage(page).join(\"\\n\"), json: { ...page } };\n+\treturn { text: issuePage(page, api).join(\"\\n\"), json: { ...page } };\n }\n \n export async function runAsk(args: Parsed, env: Env): Promise<Output> {"}],"unmatched":[]}