Lines 5–12 at 29 (were 5–12 at 28)
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). 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"; Lines 25–39 at 29 (were 25–37 at 28)
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"; 3032const q = (s: string): string => JSON.stringify(s); 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( Lines 45–51 at 29 (were 43–49 at 28)
4547 api.issuesServer = server; 46− return { config, api };
48+ return { root, config, api }; 4951function issueNumber(word: string | undefined, what = "an issue number"): number { Lines 174–230 at 29 (were 172–177 at 28)
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(/^\.+/, "_") 183+ return `${id}-${own || "file"}`; 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. 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`, 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), 203+ if (all.length === 0) 205+ text: `Issue ${page.issue.id} has no attachments.`, 206+ json: { issue: page.issue.id, folder: target, files: [] }, 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 }); 221+ `Saved ${plural(files.length, "file")} from issue ${page.issue.id} to ${target}:`, 222+ ...files.map((f) => ` ${basename(f.path)}, ${sizeText(f.size)}`), 224+ json: { issue: page.issue.id, folder: target, files }, 175228/** An issue's page, as text. */ 176229export function issuePage(p: IssuePage, api?: Pick<Api, "attachmentUrl">): string[] { 177230 const i = p.issue; Lines 469–483 at 29 (were 416–422 at 28)
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]}` : ""}`, 420481 if (first === "draft") return runDraft(api, args, rest); 421482 if (first === "new") { 422483 if (rest.length === 0) Lines 583–589 at 29 (were 522–527 at 28)
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 } };