Lines 23–56 at 318 (were 23–47 at 76)
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"; 2727import { fromEnv } from "./env-names.ts"; 2828import { ignoredHere } from "./fetch.ts"; 2929import { loadIgnore, relativeTo } from "./folder.ts"; 3030import type { AskReply } from "./issues-wire.ts"; 31+import { isLocal, LOCAL_BASE } from "./local-store.ts"; 3132import { queuedLines, standing } from "./queue.ts"; 3233import { seenText, shortWhen } from "./times.ts"; 3435const q = (s: string): string => JSON.stringify(s); 3637/** The folder, with its Api pointed at the Issues Worker: the token goes only where tokenGoesTo allows, as for the avcs server. */ 37−function openIssues(env: Env): { root: string; config: Config; api: Api } {
38+export function openIssues(env: Env): { root: string; config: Config; api: Api } { 3839 const { root, config, api } = open(env); 39− const server = fromEnv(env.env, "ISSUES_SERVER") || issuesServerFor(config.server, readMachineServers(env.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)); 4049 if (server === undefined) 4150 throw new UsageError( 4251 `${config.server} has no Issues Worker beside it that abso knows; ~/.abso/servers.json or ABSO_ISSUES_SERVER names one`, 44− if (config.token !== undefined && !tokenGoesTo(server, trustedServers(env.env))) {
53+ if (config.token !== undefined && !tokenGoesToIssues(server, trustedServers(env.env))) { 4554 throw new UsageError( 4655 `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.`, Lines 613–639 at 318 (were 604–614 at 76)
604613 if (str(args, "attach") !== undefined && comment === undefined && object === undefined) 605614 throw new UsageError("--attach goes with abso issue new or --comment (or --object)"); 606615 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!); 607622 const attachments = await uploadAttachments(api, env.cwd, str(args, "attach")); 608− 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(", ")})` : ""; 610− text: `${object !== undefined ? "Objected" : "Commented"} on issue ${id}${attachments.length > 0 ? ` with ${plural(attachments.length, "attachment")} (${attachments.join(", ")})` : ""}. Its agents hear it.`,
611− 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 } : {}), 614639 if (bool(args, "drop")) { Lines 648–654 at 318 (were 623–629 at 76)
623648 let version: number | null = null; 624649 if (doneBy !== undefined) { 625650 version = issueNumber(doneBy, "--done-by"); 626− 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"); 628653 await api.show(version, { draft: null }); Lines 902–967 at 318 (were 877–879 at 76)
877902 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;