Lines 1–12 at 318 (were 1–12 at 26)
11// Issues (#54): abso issues, abso issue, abso ask, abso waiting and avcs 22// answer. The Issues Worker keeps them (avcs-issues beside avcs, or 3−// AVCS_ISSUES_SERVER), and takes the same token. Statuses come from the work: a start note naming
3+// ABSO_ISSUES_SERVER), and takes the same token. Statuses come from the work: a start note naming 44// an issue (abso start --issue N) puts it In progress, an open ask Blocked or 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 23–62 at 318 (were 23–48 at 26)
2323import { bool, type Parsed, str, UsageError } from "./args.ts"; 2424import { type Env, type Output, open, plural } from "./commands.ts"; 2525import { type Config, readMachineServers, trustedServers } from "./config.ts"; 26−import { issuesServerFor, tokenGoesTo } from "./core.ts";
26+import { issuesServerFor, tokenGoesToIssues } from "./core.ts"; 27+import { fromEnv } from "./env-names.ts"; 28+import { ignoredHere } from "./fetch.ts"; 29+import { loadIgnore, relativeTo } from "./folder.ts"; 30+import type { AskReply } from "./issues-wire.ts"; 31+import { isLocal, LOCAL_BASE } from "./local-store.ts"; 32+import { queuedLines, standing } from "./queue.ts"; 2733import { seenText, shortWhen } from "./times.ts"; 2935const q = (s: string): string => JSON.stringify(s); 3137/** The folder, with its Api pointed at the Issues Worker: the token goes only where tokenGoesTo allows, as for the avcs server. */ 32−function openIssues(env: Env): { config: Config; api: Api } {
33− const { config, api } = open(env);
34− const server = env.env.AVCS_ISSUES_SERVER || issuesServerFor(config.server, readMachineServers(env.env));
38+export function openIssues(env: Env): { root: string; config: Config; api: Api } { 39+ const { root, config, api } = open(env); 40+ // A local project's issues are in its store, where the open server keeps them: at /issues. 41+ if (isLocal(config.server)) { 42+ api.issuesServer = `${LOCAL_BASE}/issues`; 43+ return { root, config, api }; 45+ // An explicit --server goes to that server's own Issues Worker: ABSO_ISSUES_SERVER doesn't redirect it. 47+ (env.server === undefined ? fromEnv(env.env, "ISSUES_SERVER") : undefined) || 48+ issuesServerFor(config.server, readMachineServers(env.env)); 3549 if (server === undefined) 3650 throw new UsageError( 37− `${config.server} has no Issues Worker beside it that abso knows; ~/.abso/servers.json or AVCS_ISSUES_SERVER names one`,
51+ `${config.server} has no Issues Worker beside it that abso knows; ~/.abso/servers.json or ABSO_ISSUES_SERVER names one`, 39− if (config.token !== undefined && !tokenGoesTo(server, trustedServers(env.env))) {
53+ if (config.token !== undefined && !tokenGoesToIssues(server, trustedServers(env.env))) { 4054 throw new UsageError( 41− `the Issues Worker is ${server}, and abso sends your token only to its own servers and this machine. If ${server} is yours, name it in ~/.abso/servers.json or AVCS_TRUSTED_SERVERS.`,
55+ `the Issues Worker is ${server}, and abso sends your token only to its own servers and this machine. If ${server} is yours, name it in ~/.abso/servers.json or ABSO_TRUSTED_SERVERS.`, 4458 api.issuesServer = server; 45− return { config, api };
59+ return { root, config, api }; 4862function issueNumber(word: string | undefined, what = "an issue number"): number { Lines 80–129 at 318 (were 66–90 at 26)
6680 return ` ${String(i.id).padStart(3)} ${i.status.padEnd(11)} ${q(i.title)}${detail.length > 0 ? ` (${detail.join("; ")})` : ""}`; 69−function askLine(a: Ask & { title?: string | null }): string {
83+/** The first line of a reply, for lists; abso ask <N> shows it whole. */ 84+const firstLine = (text: string): string => { 85+ const line = text.split("\n")[0]!; 86+ return line.length < text.length ? `${line} ...` : line; 89+/** One reply in an ask's thread. */ 90+function replyLine(r: AskReply, indent: string, whole: boolean): string { 91+ return `${indent}${r.by}, ${shortWhen(r.at)}${r.question ? ", a question" : ""}: ${q(whole ? r.text : firstLine(r.text))}`; 95+ * An ask: its head line, its files and options, then, in a list, its newest reply, or with `thread`, every 96+ * reply, oldest first; then its answer. Older servers send no thread, only the one asked's acknowledgement. 98+function askLine(a: Ask & { title?: string | null }, api?: Pick<Api, "attachmentUrl">, thread = false): string { 7099 const what = a.review ? "a review" : a.kind === "task" ? "a task" : "a question"; 71100 const where = a.issue === null ? "" : ` on issue ${a.issue}${a.title ? ` (${q(a.title)})` : ""}`; 101+ const replies = a.replies; 73103 // Who answered, and when, on the ask's own line, so a handled ask can't pass for an open one. 75105 ? `${a.outcome === "withdrawn" ? "withdrawn" : "answered"} by ${a.answer.by}, ${shortWhen(a.answer.at)}` 77− !a.answer && a.seen !== undefined ? seenText(a.seen) : "",
107+ !a.answer && a.ack && replies === undefined ? `acknowledged ${shortWhen(a.ack.at)}, not answered yet` : "", 108+ !a.answer && !a.ack && a.seen !== undefined ? seenText(a.seen) : "", 109+ replies && replies.length > 0 ? (replies.length === 1 ? "1 reply" : `${replies.length} replies`) : "", 110+ // Whose turn it is, when it isn't the one asked's: they asked something back. 111+ !a.answer && a.waitingOn && a.waitingOn !== a.of ? `waiting on ${a.waitingOn}` : "", 78112 a.due ? `due ${a.due}` : "", 79113 a.blocks.length > 0 ? `blocks ${a.blocks.join(", ")}` : "", 80114 ].filter((x) => x !== ""); 81115 const head = ` ask ${a.id}: ${a.by}, ${shortWhen(a.at)}, asks ${a.of} ${what}${where}${extra.length > 0 ? ` (${extra.join("; ")})` : ""}: ${q(a.question)}`; 82− const lines = [head];
116+ const lines = [head, ...attachmentLines(api, a.attachments, " ")]; 83117 if (a.options.length > 0) lines.push(` options: ${a.options.map((o, i) => `${i + 1}. ${q(o)}`).join(", ")}`); 84118 if (a.recommendation) lines.push(` ${a.recommendation.by} recommends: ${q(a.recommendation.text)}`); 119+ if (replies === undefined) { 120+ if (!a.answer && a.ack && a.ack.note !== "") lines.push(` ${a.of} acknowledged: ${q(a.ack.note)}`); 121+ } else if (thread) lines.push(...replies.map((r) => replyLine(r, " ", true))); 122+ else if (replies.length > 0) lines.push(replyLine(replies[replies.length - 1]!, " last: ", false)); 85123 if (a.answer && a.outcome === "withdrawn") { 86124 if (a.answer.words !== "") lines.push(` why: ${q(a.answer.words)}`); 87− } else if (a.answer) lines.push(` answer: ${q(a.answer.words)}`);
125+ } else if (a.answer) 126+ lines.push(` answer: ${q(a.answer.words)}`, ...attachmentLines(api, a.answer.attachments, " ")); 88127 return lines.join("\n"); Lines 149–155 at 318 (were 110–116 at 26)
110149 return ` ${e.by}, ${shortWhen(e.at)}: ${said.join("; ")} (${e.notified.length > 0 ? `told ${e.notified.join(", ")}` : "told nobody"})`; 113−/** Labels as typed, lower-cased, since the Worker refuses upper case (Security): --label Friction means friction. */
152+/** Labels as typed, lower-cased, since the Worker refuses upper case: --label Friction means friction. */ 114153function labelList(value: string): string[] { 115154 return listOf(value).map((l) => l.toLowerCase()); Lines 164–183 at 318 (were 125–130 at 26)
125164 .filter((v) => v !== ""); 167+/** " with 2 attachments (a…, a…)" after a write that carried some; nothing otherwise. */ 168+function withFiles(ids: readonly string[]): string { 169+ return ids.length > 0 ? ` with ${plural(ids.length, "attachment")} (${ids.join(", ")})` : ""; 173+ * What to say when a write sent files the server didn't keep: an Issues server from before asks carried 174+ * attachments takes the words and leaves the files out. Nothing to say when it kept them, or none were sent. 176+function notKept(sent: readonly string[], kept: readonly string[] | undefined, what: string): string | undefined { 177+ if (sent.length === 0 || (kept !== undefined && sent.every((id) => kept.includes(id)))) return undefined; 178+ return `The Issues server didn't keep the ${sent.length === 1 ? "file" : "files"} on ${what}: it is older than this client. The words went; the ${sent.length === 1 ? "file goes" : "files go"} on a comment instead (abso issue <N> --comment "..." --attach ...).`; 128181/** The most one attachment may be: the Issues Worker's cap, checked here before sending (abso issue 171). */ 129182const ATTACH_MAX = 10 * 1024 * 1024; Lines 224–282 at 318 (were 171–176 at 26)
227+/** A saved attachment's file name: its id, then its own name with anything but letters, digits, . - _ made _. */ 228+export function savedName(id: string, name: string): string { 229+ const own = (name.split(/[\\/]/).pop() ?? "") 230+ .replace(/[^A-Za-z0-9._-]/g, "_") 231+ .replace(/^\.+/, "_") 233+ return `${id}-${own || "file"}`; 237+ * abso issue N --save-attachments <folder>: every attachment on the issue, its 238+ * comments and its asks and answers, written to that folder as <id>-<name>; an svg's own file 239+ * beside the png drawn from it. Not into the abso folder unless abso leaves 240+ * that place out, or the images would be recorded as edits. 242+async function saveAttachments(api: Api, root: string, cwd: string, dir: string, page: IssuePage): Promise<Output> { 243+ const target = resolve(cwd, dir); 244+ const inside = target === resolve(root) ? "" : relativeTo(root, target); 245+ if (inside !== undefined && (inside === "" || !ignoredHere(loadIgnore(root), inside, true))) 246+ throw new UsageError( 247+ `${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`, 249+ const seen = new Set<string>(); 251+ ...(page.issue.attachments ?? []), 252+ ...page.comments.flatMap((c) => c.attachments ?? []), 253+ ...page.asks.flatMap((a) => [...(a.attachments ?? []), ...(a.answer?.attachments ?? [])]), 254+ ].filter((a) => !seen.has(a.id) && seen.add(a.id)); 255+ if (all.length === 0) 257+ text: `Issue ${page.issue.id} has no attachments.`, 258+ json: { issue: page.issue.id, folder: target, files: [] }, 260+ mkdirSync(target, { recursive: true }); 261+ const files: { id: string; path: string; size: number }[] = []; 262+ for (const a of all) { 263+ const wanted = [{ name: a.name, source: false }, ...(a.source ? [{ name: a.source.name, source: true }] : [])]; 264+ for (const w of wanted) { 265+ const bytes = await api.attachmentBytes(a.id, w.source, ATTACH_MAX); 266+ const path = join(target, savedName(a.id, w.name)); 267+ writeFileSync(path, bytes); 268+ files.push({ id: a.id, path, size: bytes.length }); 273+ `Saved ${plural(files.length, "file")} from issue ${page.issue.id} to ${target}:`, 274+ ...files.map((f) => ` ${basename(f.path)}, ${sizeText(f.size)}`), 276+ json: { issue: page.issue.id, folder: target, files }, 174280/** An issue's page, as text. */ 175281export function issuePage(p: IssuePage, api?: Pick<Api, "attachmentUrl">): string[] { 176282 const i = p.issue; Lines 293–316 at 318 (were 187–199 at 26)
187293 ? `${i.closed.how === "done" ? "Done" : "Dropped"} by ${i.closed.by}${i.closed.version !== null ? ` in version ${i.closed.version}` : ""}, ${shortWhen(i.closed.at)}.` 189295 ].filter((f) => f !== ""); 296+ // The links below open for people signed in on the website; an agent's fetch of one is refused. Say the way in 297+ // before the first link, so an agent reads the files instead of hunting for them. 299+ (i.attachments ?? []).length + 300+ p.comments.reduce((n, c) => n + (c.attachments ?? []).length, 0) + 301+ p.asks.reduce((n, a) => n + (a.attachments ?? []).length + (a.answer?.attachments ?? []).length, 0); 191303 `Issue ${i.id}: ${q(i.title)} [${i.status}]`, 307+ `${files === 1 ? "1 file is" : `${files} files are`} attached below. To read ${files === 1 ? "it" : "them"}: abso issue ${i.id} --save-attachments <folder> saves ${files === 1 ? "it" : "every one"} there, then open the files. The links are for people signed in on the website.`, 193310 ...(i.lines ? [`From ${i.lines.file} lines ${i.lines.from}-${i.lines.to} at version ${i.lines.version}.`] : []), 194311 ...(i.description !== "" ? ["", ...i.description.split("\n").map((l) => ` ${l}`)] : []), 195312 ...attachmentLines(api, i.attachments, " "), 196− ...(p.asks.length > 0 ? ["", "Asks:", ...p.asks.map(askLine)] : []),
313+ ...(p.asks.length > 0 ? ["", "Asks:", ...p.asks.map((a) => askLine(a, api))] : []), 197314 ...(p.comments.length > 0 Lines 532–546 at 318 (were 415–421 at 26)
416533export async function runIssue(args: Parsed, env: Env): Promise<Output> { 417534 const [first, ...rest] = args.positionals; 418− const { api } = openIssues(env);
535+ const { root, api } = openIssues(env); 536+ const saveTo = str(args, "save-attachments"); 537+ if (saveTo !== undefined) { 538+ const other = [...args.flags.keys()].filter((f) => f !== "save-attachments" && f !== "json"); 539+ if (other.length > 0 || first === "new" || first === "draft") 540+ throw new UsageError( 541+ `--save-attachments goes alone with an issue number: abso issue <N> --save-attachments <folder>${other.length > 0 ? `, not with --${other[0]}` : ""}`, 419544 if (first === "draft") return runDraft(api, args, rest); 420545 if (first === "new") { 421546 if (rest.length === 0) Lines 613–639 at 318 (were 488–498 at 26)
488613 if (str(args, "attach") !== undefined && comment === undefined && object === undefined) 489614 throw new UsageError("--attach goes with abso issue new or --comment (or --object)"); 490615 if (comment !== undefined || object !== undefined) { 616+ // Refused before anything goes up: an objection is one comment, and a part of one would read as a whole. 617+ if (object !== undefined && object.length > COMMENT_MAX) 618+ throw new UsageError( 619+ `an objection holds up to ${COMMENT_MAX} characters, and this one has ${object.length}: say it shorter, and put the rest in a --comment`, 621+ const parts = object !== undefined ? [object] : commentParts(comment!); 491622 const attachments = await uploadAttachments(api, env.cwd, str(args, "attach")); 492− const r = await api.issueComment(id, (comment ?? object)!, object !== undefined, attachments);
623+ const ids: number[] = []; 624+ for (const [i, part] of parts.entries()) { 625+ // The attachments go on the first part, which the rest follow. 626+ ids.push((await api.issueComment(id, part, object !== undefined, i === 0 ? attachments : [])).id); 628+ const inParts = parts.length > 1 ? ` in ${parts.length} parts (comments ${ids.join(", ")})` : ""; 494− text: `${object !== undefined ? "Objected" : "Commented"} on issue ${id}${attachments.length > 0 ? ` with ${plural(attachments.length, "attachment")} (${attachments.join(", ")})` : ""}. Its agents hear it.`,
495− json: { id: r.id, issue: id, ...(attachments.length > 0 ? { attachments } : {}) },
630+ text: `${object !== undefined ? "Objected" : "Commented"} on issue ${id}${inParts}${attachments.length > 0 ? ` with ${plural(attachments.length, "attachment")} (${attachments.join(", ")})` : ""}. Its agents hear it.`, 634+ ...(parts.length > 1 ? { parts: ids } : {}), 635+ ...(attachments.length > 0 ? { attachments } : {}), 498639 if (bool(args, "drop")) { Lines 648–654 at 318 (were 507–513 at 26)
507648 let version: number | null = null; 508649 if (doneBy !== undefined) { 509650 version = issueNumber(doneBy, "--done-by"); 510− if (version < 1) throw new UsageError("--done-by is a published version, 1 or more");
651+ if (version < 1) throw new UsageError("--done-by is a pushed version, 1 or more"); 512653 await api.show(version, { draft: null }); Lines 662–668 at 318 (were 521–526 at 26)
523664 const page = await api.issue(id); 665+ if (saveTo !== undefined) return saveAttachments(api, root, env.cwd, saveTo, page); 524666 return { text: issuePage(page, api).join("\n"), json: { ...page } }; Lines 672–678 at 318 (were 530–535 at 26)
530672 if (str(args, "note") !== undefined) 531673 throw new UsageError('--note goes with --withdraw: abso ask --withdraw <ask> --note "why"'); 532674 const [of, ...words] = args.positionals; 675+ if (of !== undefined && words.length === 0 && /^\d+$/.test(of)) return showAsk(args, env, of); 533676 if (of === undefined || words.length === 0) 534677 throw new UsageError( 535678 'abso ask <who> "<question>" [--issue <N>] [--review | --task] [--due <YYYY-MM-DD>] [--blocks <N,N>] [--options "A|B|C"]; who is an agent, or person:<id>', Lines 682–688 at 318 (were 539–544 at 26)
539682 const issue = str(args, "issue"); 540683 const blocks = str(args, "blocks"); 541684 const options = str(args, "options"); 685+ const attachments = await uploadAttachments(api, env.cwd, str(args, "attach")); 542686 const r = await api.ask({ 544688 question: words.join(" "), Lines 699–759 at 318 (were 555–567 at 26)
555699 .filter((o) => o !== ""), 702+ ...(attachments.length > 0 ? { attachments } : {}), 559− return { text: `Asked ${of} (ask ${r.id}). They hear it; abso waiting shows what's open.`, json: { id: r.id } };
704+ const lost = notKept(attachments, r.attachments, `ask ${r.id}`); 706+ text: `Asked ${of} (ask ${r.id})${withFiles(attachments)}. They hear it; abso waiting shows what's open.${lost ? ` ${lost}` : ""}`, 707+ json: { id: r.id, ...(attachments.length > 0 ? { attachments } : {}), ...(lost ? { notKept: lost } : {}) }, 711+/** abso ask <N>: one ask, open or closed, with its whole thread, its answer and whose turn it is. */ 712+async function showAsk(args: Parsed, env: Env, word: string): Promise<Output> { 713+ const others = ["issue", "due", "blocks", "options", "attach"].filter((f) => str(args, f) !== undefined); 714+ if (others.length > 0 || bool(args, "review") || bool(args, "task")) 715+ throw new UsageError('abso ask <N> shows ask N; to ask, say who and what: abso ask <who> "<question>"'); 716+ const id = issueNumber(word, "the ask number"); 717+ const { api, config } = openIssues(env); 718+ const { ask } = await api.askThread(id); 719+ const side = ask.of === config.agent || ask.by === config.agent; 720+ const turn = ask.waitingOn === config.agent ? "you" : ask.waitingOn; 724+ ? `abso reply ${id} "..." still adds to it.` 725+ : ask.of === config.agent 726+ ? `abso reply ${id} "..." adds to it; abso answer ${id} "..." answers and closes it.` 727+ : `abso reply ${id} "..." adds to it.`; 728+ const next = [!ask.answer && turn ? `It waits on ${turn}.` : "", steps].join(" "); 730+ text: [askLine(ask, api, true), next.trim()].filter((l) => l !== "").join("\n"), 735+/** abso reply <ask> "<words>" [--question]: add to an ask's thread, as its asker or the one asked. */ 736+export async function runReply(args: Parsed, env: Env): Promise<Output> { 737+ const [first, ...words] = args.positionals; 738+ const id = issueNumber(first, "the ask number"); 739+ if (words.length === 0) 740+ throw new UsageError( 741+ `abso reply <ask> "<words>" [--question]: adds to an ask's thread, as its asker or the one asked`, 743+ const { api, config } = openIssues(env); 744+ const question = bool(args, "question"); 745+ const r = await api.reply(id, { text: words.join(" "), ...(question ? { question: true } : {}) }); 746+ const other = r.ask.by === config.agent ? r.ask.of : r.ask.by; 748+ !r.ask.answer && r.ask.waitingOn 749+ ? ` It waits on ${r.ask.waitingOn === config.agent ? "you" : r.ask.waitingOn}.` 751+ return { text: `Replied on ask ${id}. ${other} hears it.${turn}`, json: { ask: r.ask } }; 562754/** abso ask --withdraw <ask> [--note "why"]: the asker takes an ask back. It closes like an answer, and the one asked hears it. */ 563755async function withdrawAsk(args: Parsed, env: Env, word: string): Promise<Output> { 564− const others = ["issue", "due", "blocks", "options"].filter((f) => str(args, f) !== undefined);
756+ const others = ["issue", "due", "blocks", "options", "attach"].filter((f) => str(args, f) !== undefined); 565757 if (args.positionals.length > 0 || others.length > 0 || bool(args, "review") || bool(args, "task")) 566758 throw new UsageError('abso ask --withdraw <ask> [--note "why"] takes nothing else: it takes back an ask you made'); 567759 const id = issueNumber(word, "the ask number"); Lines 800–880 at 318 (were 608–631 at 26)
609801export async function runWaiting(args: Parsed, env: Env): Promise<Output> { 610802 if (args.positionals.length > 0) 611− throw new UsageError("waiting takes no words: abso waiting [--of <agent or person:id>] [--mine]");
803+ throw new UsageError("waiting takes no words: abso waiting [--of <agent or person:id>] [--mine] [--asked]"); 804+ if (bool(args, "asked")) return askedOf(args, env); 612805 const { api, config } = openIssues(env); 613806 const mine = bool(args, "mine") || str(args, "of") === config.agent; 614807 const of = mine ? config.agent : str(args, "of"); 615− const { asks } = mine ? await api.waitingMine() : await api.waiting(of);
808+ // With --mine, your own publishes still in the merge queue are open work too. A server without a queue, 809+ // or one that can't be read now, leaves them out rather than failing the asks. 810+ const [{ asks }, queue] = await Promise.all([ 811+ mine ? api.waitingMine() : api.waiting(of), 812+ mine ? api.queueState().catch(() => undefined) : undefined, 814+ const queued = queuedLines(queue, config.agent); 815+ const yours = (queue?.items ?? []).filter((q) => q.agent === config.agent); 617− text:
618− asks.length === 0
619− ? `Nothing is waiting${of ? ` on ${of}` : ""}.`
819+ ...(asks.length === 0 820+ ? [queued.length > 0 ? `No open asks of ${of}.` : `Nothing is waiting${of ? ` on ${of}` : ""}.`] 621822 `${plural(asks.length, "open ask")}${of ? ` of ${of}` : ""}, soonest due first:`, 622− ...asks.map(askLine),
623− 'abso answer <ask> "..." answers one asked of you.',
624− ].join("\n"),
823+ ...asks.map((a) => askLine(a, api)), 824+ 'abso ask <N> shows one with its thread; abso reply <N> "..." adds to it; abso answer <N> "..." answers one asked of you.', 829+ ...(yours.length > 0 830+ ? { queued: yours.map((q) => ({ id: q.id, message: q.message, standing: standing(queue!.items, q.id) })) } 836+/** abso waiting --asked: the asks you sent, open ones first, then the latest answered, each with its newest reply. */ 837+async function askedOf(args: Parsed, env: Env): Promise<Output> { 838+ if (bool(args, "mine") || str(args, "of") !== undefined) 839+ throw new UsageError("--asked lists the asks you sent; it takes no --mine or --of"); 840+ const { api, config } = openIssues(env); 841+ const { asks } = await api.asked(); 842+ const open = asks.filter((a) => !a.answer); 843+ const closed = asks.filter((a) => a.answer); 846+ ...(asks.length === 0 847+ ? [`${config.agent} hasn't asked anything yet.`] 850+ ? [`${plural(open.length, "open ask")} you sent:`, ...open.map((a) => askLine(a, api))] 852+ ...(closed.length > 0 854+ `${closed.length === 1 ? "The latest answered" : `The latest ${closed.length} answered`}:`, 855+ ...closed.map((a) => askLine(a, api)), 858+ "abso ask <N> shows one with its whole thread.", 865+/** abso ack <ask> ["note"]: tell the asker you have it, and answer later. The ask stays open until abso answer. */ 866+export async function runAck(args: Parsed, env: Env): Promise<Output> { 867+ const [first, ...words] = args.positionals; 868+ const id = issueNumber(first, "the ask number"); 869+ const { api } = openIssues(env); 870+ const note = words.join(" "); 871+ const r = await api.ack(id, note !== "" ? { note } : {}); 873+ text: `Acknowledged ask ${id}. ${r.ask.by} hears it; abso reply ${id} "..." adds more as you go, and the ask stays open until abso answer ${id} "...".`, 874+ json: { ask: r.ask }, 629878export async function runAnswer(args: Parsed, env: Env): Promise<Output> { 630879 const [first, ...words] = args.positionals; 631880 const id = issueNumber(first, "the ask number"); Lines 884–967 at 318 (were 635–645 at 26)
635884 throw new UsageError('abso answer <ask> "<words>" | --option <N> [--note "..."] | --done [--note "..."]'); 636885 const { api } = openIssues(env); 637886 const note = str(args, "note"); 887+ const attachments = await uploadAttachments(api, env.cwd, str(args, "attach")); 638888 const r = await api.answer(id, { 639889 ...(words.length > 0 ? { words: words.join(" ") } : {}), 640890 ...(option !== undefined ? { option: /^\d+$/.test(option) ? Number(option) - 1 : option } : {}), 641891 ...(done ? { done: true } : {}), 642892 ...(note !== undefined ? { note } : {}), 893+ ...(attachments.length > 0 ? { attachments } : {}), 644− return { text: `Answered ask ${id}. ${r.ask.by} hears it.`, json: { ask: r.ask } };
895+ const lost = notKept( 897+ r.ask.answer?.attachments?.map((a) => a.id), 898+ `your answer to ask ${id}`, 901+ text: `Answered ask ${id}${withFiles(attachments)}. ${r.ask.by} hears it.${lost ? ` ${lost}` : ""}`, 902+ json: { ask: r.ask, ...(lost ? { notKept: lost } : {}) }, 906+/** What the Issues Worker takes in one comment (its LIMITS.text). */ 907+export const COMMENT_MAX = 4000; 909+/** Room a part keeps for its "(i/n)" line and blank line, and for closing a code block it ends inside. */ 910+const PART_MARK = 12; 911+const FENCE_CLOSE = 5; 914+ * A comment too long for one, as parts that each fit, each starting with "(i/n)". A part ends at the last 915+ * paragraph break that fits, else the last line break, else the last space, else at the limit. A part that 916+ * would end inside a fenced code block closes it, and the next part opens it again with the same fence line. 918+export function commentParts(text: string, max = COMMENT_MAX): string[] { 919+ if (text.length <= max) return [text]; 920+ const bodies: string[] = []; 923+ while (rest !== "") { 924+ const room = max - PART_MARK - FENCE_CLOSE - reopen.length; 926+ if (reopen.length + rest.length <= max - PART_MARK) { 930+ const cut = cutAt(rest, room); 931+ body = rest.slice(0, cut).trimEnd(); 932+ // A space cut at goes with neither part; the line breaks between paragraphs go too. 933+ rest = rest.slice(rest[cut] === " " ? cut + 1 : cut).replace(/^\n+/, ""); 934+ if (rest.trim() === "") rest = ""; 936+ let part = reopen + body; 937+ const fence = openFence(part); 938+ if (fence && rest !== "") { 939+ part += `\n${fence.marker}`; 940+ reopen = `${fence.line}\n`; 944+ return bodies.map((b, i) => `(${i + 1}/${bodies.length})\n\n${b}`); 947+/** Where to end a part of at most `room` characters of `text`: a paragraph break, a line break, a space, or the limit. */ 948+function cutAt(text: string, room: number): number { 949+ const head = text.slice(0, room); 950+ const floor = room / 4; 951+ for (const at of [head.lastIndexOf("\n\n"), head.lastIndexOf("\n"), head.lastIndexOf(" ")]) if (at > floor) return at; 952+ // Not between the two halves of a character outside the Basic Multilingual Plane. 953+ const code = text.charCodeAt(room - 1); 954+ return code >= 0xd800 && code <= 0xdbff ? room - 1 : room; 957+/** The fence line of a code block still open at the end of `text`, and the marker that closes it, or undefined. */ 958+function openFence(text: string): { line: string; marker: string } | undefined { 959+ let open: { line: string; marker: string } | undefined; 960+ for (const line of text.split("\n")) { 961+ const m = /^\s*(`{3,}|~{3,})/.exec(line); 963+ if (!open) open = { line, marker: m[1]! }; 964+ else if (m[1]!.startsWith(open.marker) && line.trim() === m[1]) open = undefined;