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
MCP
code on this site's /mcp
CLI
none: the JSON below is the answer
JSON
/christopher/abso-core/files/client/src/issues.ts?version=18&format=json
518 linesFirst import 79% · pinch 12% · review 5% · infra-split 4%Last change review in version 17, 5 versions changed it

You're reading version 18. The newest is 318, and 17 versions since then changed this file. Go to the newestCompare with 318

1// Issues (#54): abso issues, abso issue, abso ask, abso waiting and avcs
2// 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
4// an issue (abso start --issue N) puts it In progress, an open ask Blocked or
5// In review, and publish --done closes it. Other agents' and people's words
6// are quoted as JSON, so none can print as another line (#30).
7
8import { readFileSync, statSync } from "node:fs";
9import { basename, resolve } from "node:path";
10import type { Api, Ask, Attachment, Draft, DraftBody, IssuePage, IssueRow } from "./api.ts";
11import { bool, type Parsed, str, UsageError } from "./args.ts";
12import { type Env, type Output, open, plural } from "./commands.ts";
13import { type Config, readMachineServers, trustedServers } from "./config.ts";
14import { issuesServerFor, tokenGoesTo } from "./core.ts";
15import { seenText, shortWhen } from "./times.ts";
17const q = (s: string): string => JSON.stringify(s);
19/** The folder, with its Api pointed at the Issues Worker: the token goes only where tokenGoesTo allows, as for the avcs server. */
20function openIssues(env: Env): { config: Config; api: Api } {
21 const { config, api } = open(env);
22 const server = env.env.AVCS_ISSUES_SERVER || issuesServerFor(config.server, readMachineServers(env.env));
23 if (server === undefined)
24 throw new UsageError(
25 `${config.server} has no Issues Worker beside it that abso knows; ~/.abso/servers.json or AVCS_ISSUES_SERVER names one`,
26 );
27 if (config.token !== undefined && !tokenGoesTo(server, trustedServers(env.env))) {
28 throw new UsageError(
29 `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.`,
30 );
31 }
32 api.issuesServer = server;
33 return { config, api };
36function issueNumber(word: string | undefined, what = "an issue number"): number {
37 if (word === undefined || !/^#?\d+$/.test(word)) throw new UsageError(`${what} is a number, like 12`);
38 return Number(word.replace("#", ""));
41/** One issue as a line. */
42export function issueLine(i: IssueRow): string {
43 const detail = [
44 i.agent !== null && !i.agents.includes(i.agent) ? `for ${i.agent}` : "",
45 i.agents.length > 0 ? i.agents.join(", ") : "",
46 i.blockedBy.length > 0 ? `blocked by ${i.blockedBy.join(", ")}` : "",
47 (i.labels ?? []).length > 0 ? `labels ${i.labels.join(", ")}` : "",
48 i.versions.length > 0 ? `${i.versions.length === 1 ? "version" : "versions"} ${i.versions.join(", ")}` : "",
49 i.waitingOn.length > 0 ? `waiting on ${i.waitingOn.join(", ")}` : "",
50 i.parent !== null ? `under ${i.parent}` : "",
51 i.children > 0 ? plural(i.children, "sub-issue") : "",
52 `updated ${shortWhen(i.updated)}`,
53 ].filter((d) => d !== "");
54 return ` ${String(i.id).padStart(3)} ${i.status.padEnd(11)} ${q(i.title)}${detail.length > 0 ? ` (${detail.join("; ")})` : ""}`;
57function askLine(a: Ask & { title?: string | null }): string {
58 const what = a.review ? "a review" : a.kind === "task" ? "a task" : "a question";
59 const where = a.issue === null ? "" : ` on issue ${a.issue}${a.title ? ` (${q(a.title)})` : ""}`;
60 const extra = [
61 // Who answered, and when, on the ask's own line, so a handled ask can't pass for an open one.
62 a.answer
63 ? `${a.outcome === "withdrawn" ? "withdrawn" : "answered"} by ${a.answer.by}, ${shortWhen(a.answer.at)}`
64 : "",
65 !a.answer && a.seen !== undefined ? seenText(a.seen) : "",
66 a.due ? `due ${a.due}` : "",
67 a.blocks.length > 0 ? `blocks ${a.blocks.join(", ")}` : "",
68 ].filter((x) => x !== "");
69 const head = ` ask ${a.id}: ${a.by}, ${shortWhen(a.at)}, asks ${a.of} ${what}${where}${extra.length > 0 ? ` (${extra.join("; ")})` : ""}: ${q(a.question)}`;
70 const lines = [head];
71 if (a.options.length > 0) lines.push(` options: ${a.options.map((o, i) => `${i + 1}. ${q(o)}`).join(", ")}`);
72 if (a.recommendation) lines.push(` ${a.recommendation.by} recommends: ${q(a.recommendation.text)}`);
73 if (a.answer && a.outcome === "withdrawn") {
74 if (a.answer.words !== "") lines.push(` why: ${q(a.answer.words)}`);
75 } else if (a.answer) lines.push(` answer: ${q(a.answer.words)}`);
76 return lines.join("\n");
79/** One edit in an issue's activity: what changed, and who was told. */
80function editLine(e: IssuePage["edits"][number]): string {
81 const c = e.changes;
82 const said = [
83 c.title ? `title ${q(String(c.title.from))} to ${q(String(c.title.to))}` : "",
84 c.description ? "the description" : "",
85 c.parent ? (c.parent.to === null ? "no parent" : `parent issue ${String(c.parent.to)}`) : "",
86 c.agent ? (c.agent.to === null ? "no Agent" : `Agent ${String(c.agent.to)}`) : "",
87 c.blockedBy
88 ? (c.blockedBy.to as number[]).length === 0
89 ? "blocked by nothing"
90 : `blocked by ${(c.blockedBy.to as number[]).join(", ")}`
91 : "",
92 c.labels
93 ? (c.labels.to as string[]).length === 0
94 ? "no labels"
95 : `labels ${(c.labels.to as string[]).join(", ")}`
96 : "",
97 ].filter((x) => x !== "");
98 return ` ${e.by}, ${shortWhen(e.at)}: ${said.join("; ")} (${e.notified.length > 0 ? `told ${e.notified.join(", ")}` : "told nobody"})`;
101/** Labels as typed, lower-cased, since the Worker refuses upper case (Security): --label Friction means friction. */
102function labelList(value: string): string[] {
103 return listOf(value).map((l) => l.toLowerCase());
106/** A comma-separated list of names or issue numbers; "none" is the empty list. */
107function listOf(value: string): string[] {
108 return value.trim() === "none"
109 ? []
110 : value
111 .split(",")
112 .map((v) => v.trim())
113 .filter((v) => v !== "");
116/** The most one attachment may be: the Issues Worker's cap, checked here before sending (abso issue 171). */
117const ATTACH_MAX = 10 * 1024 * 1024;
119/** Uploads each file --attach names (comma-separated), in order, and answers their ids. Nothing is sent if a file is missing or too big. */
120async function uploadAttachments(api: Api, cwd: string, value: string | undefined): Promise<string[]> {
121 if (value === undefined) return [];
122 const paths = listOf(value);
123 if (paths.length === 0) throw new UsageError("--attach names files, comma-separated: --attach shot.png,after.png");
124 const files = paths.map((p) => {
125 const full = resolve(cwd, p);
126 let size: number;
127 try {
128 size = statSync(full).size;
129 } catch {
130 throw new UsageError(`--attach ${p}: no such file`);
131 }
132 if (size > ATTACH_MAX)
133 throw new UsageError(`--attach ${p} is ${sizeText(size)}; one attachment is at most ${sizeText(ATTACH_MAX)}`);
134 return { full, name: basename(full) };
135 });
136 const ids: string[] = [];
137 for (const f of files) ids.push((await api.attachmentUpload(readFileSync(f.full), f.name)).id);
138 return ids;
141function sizeText(n: number): string {
142 return n < 1024 ? `${n} B` : n < 1024 * 1024 ? `${Math.round(n / 1024)} KB` : `${(n / (1024 * 1024)).toFixed(1)} MB`;
145/** Attachments as lines under what carries them: name, size and where it's served. */
146function attachmentLines(
147 api: Pick<Api, "attachmentUrl"> | undefined,
148 files: readonly Attachment[] | undefined,
149 indent: string,
150): string[] {
151 return (files ?? []).map(
152 (a) => `${indent}attached ${a.id}: ${q(a.name)}, ${sizeText(a.size)}${api ? `, ${api.attachmentUrl(a.id)}` : ""}`,
153 );
156/** An issue's page, as text. */
157export function issuePage(p: IssuePage, api?: Pick<Api, "attachmentUrl">): string[] {
158 const i = p.issue;
159 const facts = [
160 i.parent !== null ? `Under issue ${i.parent}.` : "",
161 `Opened by ${i.opened.by}, ${shortWhen(i.opened.at)}.`,
162 i.agent !== null ? `Agent: ${i.agent}.` : "",
163 i.agents.length > 0 ? `Working on it: ${i.agents.join(", ")}.` : "",
164 i.blockedBy.length > 0 ? `Blocked by: issue${i.blockedBy.length === 1 ? "" : "s"} ${i.blockedBy.join(", ")}.` : "",
165 (i.labels ?? []).length > 0 ? `Labels: ${i.labels.join(", ")}.` : "",
166 i.versions.length > 0 ? `Versions: ${i.versions.join(", ")}.` : "",
167 i.waitingOn.length > 0 ? `Waiting on: ${i.waitingOn.join(", ")}.` : "",
168 i.closed
169 ? `${i.closed.how === "done" ? "Done" : "Dropped"} by ${i.closed.by}${i.closed.version !== null ? ` in version ${i.closed.version}` : ""}, ${shortWhen(i.closed.at)}.`
170 : "",
171 ].filter((f) => f !== "");
172 return [
173 `Issue ${i.id}: ${q(i.title)} [${i.status}]`,
174 facts.join(" "),
175 ...(i.lines ? [`From ${i.lines.file} lines ${i.lines.from}-${i.lines.to} at version ${i.lines.version}.`] : []),
176 ...(i.description !== "" ? ["", ...i.description.split("\n").map((l) => ` ${l}`)] : []),
177 ...attachmentLines(api, i.attachments, " "),
178 ...(p.asks.length > 0 ? ["", "Asks:", ...p.asks.map(askLine)] : []),
179 ...(p.comments.length > 0
180 ? [
181 "",
182 "Comments:",
183 ...p.comments.flatMap((c) => [
184 ` ${c.by}${c.kind === "objection" ? " objects" : ""}, ${shortWhen(c.at)}: ${q(c.text)}`,
185 ...attachmentLines(api, c.attachments, " "),
186 ]),
187 ]
188 : []),
189 ...((p.edits ?? []).length > 0 ? ["", "Edits:", ...p.edits.map(editLine)] : []),
190 ...(p.children.length > 0 ? ["", "Sub-issues:", ...p.children.map(issueLine)] : []),
191 ...((i.watchers ?? []).length > 0 ? ["", `Watchers: ${i.watchers.join(", ")}.`] : []),
192 "",
193 `abso start "..." --issue ${i.id} starts on it; abso issue ${i.id} --comment "..." comments; abso ask <who> "..." --issue ${i.id} asks.`,
194 ];
197export async function runIssues(args: Parsed, env: Env): Promise<Output> {
198 if (args.positionals.length > 0)
199 throw new UsageError(
200 "issues takes no words: abso issues [--open] [--status <s>] [--agent <a>] [--parent <N>] [--label <l,l>] | abso issues --labels; abso issue <N> shows one",
201 );
202 const { api } = openIssues(env);
203 if (bool(args, "drafts")) {
204 const { drafts } = await api.drafts();
205 return {
206 text:
207 drafts.length === 0
208 ? 'No drafts. abso issue draft "<title>" saves one: only you see it, and nobody hears of it.'
209 : [
210 `${plural(drafts.length, "draft")}, newest first (only you see them):`,
211 ...drafts.map(draftLine),
212 "abso issue draft <D> --open opens one as an issue; --delete deletes it.",
213 ].join("\n"),
214 json: { drafts },
215 };
216 }
217 if (bool(args, "labels")) {
218 const { labels } = await api.issueLabels();
219 return {
220 text:
221 labels.length === 0
222 ? 'No labels yet. abso issue new "<title>" --label friction labels a new issue; abso issue <N> --label <l> labels one.'
223 : [
224 `${plural(labels.length, "label")} in use:`,
225 ...labels.map((l) => ` ${l.label}: ${l.open} open of ${l.total}`),
226 "abso issues --label <label> lists a label's issues.",
227 ].join("\n"),
228 json: { labels },
229 };
230 }
231 const parent = str(args, "parent");
232 const filter = {
233 ...(str(args, "status") ? { status: str(args, "status")! } : {}),
234 ...(str(args, "agent") ? { agent: str(args, "agent")! } : {}),
235 ...(parent !== undefined ? { parent: issueNumber(parent, "--parent") } : {}),
236 ...(str(args, "label") !== undefined ? { labels: labelList(str(args, "label")!) } : {}),
237 open: bool(args, "open"),
238 };
239 const { issues } = await api.issues(filter);
240 const scope = [
241 filter.open ? "open " : "",
242 filter.status ? `${filter.status} ` : "",
243 filter.labels ? `${filter.labels.join(", ")} ` : "",
244 ].join("");
245 return {
246 text:
247 issues.length === 0
248 ? `No ${scope}issues${filter.agent ? ` for ${filter.agent}` : ""}${parent !== undefined ? ` under ${parent}` : ""}. abso issue new "<title>" opens one.`
249 : [
250 `${plural(issues.length, `${scope}issue`)}, most recently updated first:`,
251 ...issues.map(issueLine),
252 "abso issue <N> shows one.",
253 ].join("\n"),
254 json: { issues },
255 };
258/** A new issue's fields from the command line, as open and drafts take them; `title` only when words were given. */
259function openFields(args: Parsed, title: string): DraftBody {
260 const lines = str(args, "lines");
261 const at = lines === undefined ? undefined : /^(.+):(\d+)(?:-(\d+))?@(\d+)$/.exec(lines);
262 if (lines !== undefined && !at)
263 throw new UsageError("--lines is <file>:<from>-<to>@<version>, like src/a.ts:10-14@140");
264 const parent = str(args, "parent");
265 return {
266 ...(title !== "" ? { title } : {}),
267 ...(str(args, "description") ? { description: str(args, "description")! } : {}),
268 ...(parent !== undefined ? { parent: issueNumber(parent, "--parent") } : {}),
269 ...(at ? { lines: { file: at[1]!, from: Number(at[2]), to: Number(at[3] ?? at[2]), version: Number(at[4]) } } : {}),
270 ...(str(args, "agent") ? { agent: str(args, "agent")! } : {}),
271 ...(str(args, "blocked-by") !== undefined
272 ? { blockedBy: listOf(str(args, "blocked-by")!).map((b) => issueNumber(b, "--blocked-by")) }
273 : {}),
274 ...(str(args, "notify") !== undefined ? { notify: listOf(str(args, "notify")!) } : {}),
275 ...(str(args, "label") !== undefined ? { labels: labelList(str(args, "label")!) } : {}),
276 };
279/** One draft as a line: its number, title, and what else it holds. */
280function draftLine(d: Draft): string {
281 const b = d.body;
282 const more = [
283 b.agent ? `for ${b.agent}` : "",
284 b.parent ? `under ${b.parent}` : "",
285 (b.labels ?? []).length > 0 ? `labels ${b.labels!.join(", ")}` : "",
286 b.description ? "a description" : "",
287 ].filter((m) => m !== "");
288 return ` draft ${d.id}: ${b.title ? q(b.title) : "(no title yet)"}${more.length > 0 ? ` (${more.join("; ")})` : ""}, saved ${shortWhen(d.saved)}`;
291/**
292 * Drafts (abso issue 3): an issue not opened yet, this agent's alone, with no
293 * number and no news. `abso issue draft "<title>" [fields]` saves a new one;
294 * `abso issue draft <D> [fields]` changes one; --open opens it as an issue;
295 * --delete deletes it. `abso issues --drafts` lists them.
296 */
297async function runDraft(api: Api, args: Parsed, words: string[]): Promise<Output> {
298 const [d, ...more] = words;
299 if (d !== undefined && /^\d+$/.test(d) && more.length === 0) {
300 const id = Number(d);
301 if (bool(args, "delete") && bool(args, "open")) throw new UsageError("--open or --delete, not both");
302 if (bool(args, "delete")) {
303 await api.deleteDraft(id);
304 return { text: `Deleted draft ${id}.`, json: { draft: id, deleted: true } };
305 }
306 if (bool(args, "open")) {
307 const r = await api.openDraft(id, openFields(args, ""));
308 return {
309 text: `Opened draft ${id} as issue ${r.id}. abso start "..." --issue ${r.id} starts on it.`,
310 json: { draft: id, id: r.id },
311 };
312 }
313 // Saving replaces the draft's body, so the fields given go over what it holds.
314 const found = (await api.drafts()).drafts.find((x) => x.id === id);
315 if (!found) throw new UsageError(`you have no draft ${id}; abso issues --drafts lists yours`);
316 await api.saveDraft({ ...found.body, ...openFields(args, ""), id });
317 return { text: `Saved draft ${id}.`, json: { draft: id } };
318 }
319 if (bool(args, "open") || bool(args, "delete"))
320 throw new UsageError("--open and --delete take a draft's number: abso issue draft <D> --open");
321 const r = await api.saveDraft(openFields(args, words.join(" ")));
322 return {
323 text: `Saved draft ${r.id}. Only you see it, and nobody hears of it. abso issue draft ${r.id} --open opens it as an issue.`,
324 json: { draft: r.id },
325 };
328export async function runIssue(args: Parsed, env: Env): Promise<Output> {
329 const [first, ...rest] = args.positionals;
330 const { api } = openIssues(env);
331 if (first === "draft") return runDraft(api, args, rest);
332 if (first === "new") {
333 if (rest.length === 0)
334 throw new UsageError(
335 'abso issue new "<title>" [--description "..."] [--parent <N>] [--lines <file>:<from>-<to>@<version>] [--agent <agent>] [--blocked-by <N,N>] [--notify <who,who>] [--label <l,l>]',
336 );
337 const fields = { ...openFields(args, rest.join(" ")), title: rest.join(" ") };
338 const attachments = await uploadAttachments(api, env.cwd, str(args, "attach"));
339 const r = await api.issueOpen({ ...fields, ...(attachments.length > 0 ? { attachments } : {}) });
340 return {
341 text: `Opened issue ${r.id}${attachments.length > 0 ? ` with ${plural(attachments.length, "attachment")} (${attachments.join(", ")})` : ""}. abso start "..." --issue ${r.id} starts on it.`,
342 json: { id: r.id, ...(attachments.length > 0 ? { attachments } : {}) },
343 };
344 }
345 if (first === undefined || rest.length > 0)
346 throw new UsageError(
347 'abso issue <N> [--comment "..." | --object "..." | --drop | --reopen | --done [--done-by <version>] | an edit], or abso issue new "<title>"',
348 );
349 const id = issueNumber(first);
350 const comment = str(args, "comment");
351 const object = str(args, "object");
352 const doneBy = str(args, "done-by");
353 const markingDone = bool(args, "done") || doneBy !== undefined;
354 const edits = ["title", "description", "parent", "agent", "blocked-by", "label", "unlabel"].filter(
355 (f) => str(args, f) !== undefined,
356 );
357 if (
358 [
359 comment !== undefined,
360 object !== undefined,
361 bool(args, "drop"),
362 bool(args, "reopen"),
363 markingDone,
364 edits.length > 0,
365 ].filter(Boolean).length > 1
366 )
367 throw new UsageError("one of --comment, --object, --drop, --reopen, --done or an edit at a time");
368 if (edits.length > 0) {
369 const parent = str(args, "parent");
370 const agent = str(args, "agent");
371 const blockedBy = str(args, "blocked-by");
372 const r = await api.issueEdit(id, {
373 ...(str(args, "title") !== undefined ? { title: str(args, "title")! } : {}),
374 ...(str(args, "description") !== undefined ? { description: str(args, "description")! } : {}),
375 ...(parent !== undefined ? { parent: parent === "none" ? null : issueNumber(parent, "--parent") } : {}),
376 ...(agent !== undefined ? { agent: agent === "none" ? null : agent } : {}),
377 ...(blockedBy !== undefined ? { blockedBy: listOf(blockedBy).map((b) => issueNumber(b, "--blocked-by")) } : {}),
378 ...(bool(args, "quiet") ? { notify: false } : {}),
379 ...(str(args, "notify") !== undefined ? { also: listOf(str(args, "notify")!) } : {}),
380 ...(str(args, "label") !== undefined ? { addLabels: labelList(str(args, "label")!) } : {}),
381 ...(str(args, "unlabel") !== undefined ? { removeLabels: labelList(str(args, "unlabel")!) } : {}),
382 // A labels-only edit tells nobody unless --notify names people.
383 ...(edits.every((f) => f === "label" || f === "unlabel") && str(args, "notify") !== undefined
384 ? { notify: true }
385 : {}),
386 });
387 return {
388 text: `Edited issue ${id}. ${r.notified.length > 0 ? `Told ${r.notified.join(", ")}.` : "Told nobody."}`,
389 json: { issue: id, edit: r.edit, notified: r.notified },
390 };
391 }
392 if (bool(args, "quiet") || str(args, "notify") !== undefined)
393 throw new UsageError(
394 "--quiet and --notify go with an edit (--title, --description, --parent, --agent, --blocked-by, --label or --unlabel)",
395 );
396 if (str(args, "attach") !== undefined && comment === undefined && object === undefined)
397 throw new UsageError("--attach goes with abso issue new or --comment (or --object)");
398 if (comment !== undefined || object !== undefined) {
399 const attachments = await uploadAttachments(api, env.cwd, str(args, "attach"));
400 const r = await api.issueComment(id, (comment ?? object)!, object !== undefined, attachments);
401 return {
402 text: `${object !== undefined ? "Objected" : "Commented"} on issue ${id}${attachments.length > 0 ? ` with ${plural(attachments.length, "attachment")} (${attachments.join(", ")})` : ""}. Its agents hear it.`,
403 json: { id: r.id, issue: id, ...(attachments.length > 0 ? { attachments } : {}) },
404 };
405 }
406 if (bool(args, "drop")) {
407 await api.issueDrop(id);
408 return { text: `Dropped issue ${id}.`, json: { issue: id, dropped: true } };
409 }
410 if (bool(args, "reopen")) {
411 await api.issueReopen(id);
412 return { text: `Reopened issue ${id}.`, json: { issue: id, reopened: true } };
413 }
414 if (markingDone) {
415 let version: number | null = null;
416 if (doneBy !== undefined) {
417 version = issueNumber(doneBy, "--done-by");
418 if (version < 1) throw new UsageError("--done-by is a published version, 1 or more");
419 try {
420 await api.show(version, { draft: null });
421 } catch {
422 throw new UsageError(`no version ${version}`);
423 }
424 }
425 await api.issueDone(id, version);
426 return {
427 text: version === null ? `Marked issue ${id} done.` : `Marked issue ${id} done in version ${version}.`,
428 json: { issue: id, done: true, ...(version !== null ? { version } : {}) },
429 };
430 }
431 const page = await api.issue(id);
432 return { text: issuePage(page, api).join("\n"), json: { ...page } };
435export async function runAsk(args: Parsed, env: Env): Promise<Output> {
436 const withdraw = str(args, "withdraw");
437 if (withdraw !== undefined) return withdrawAsk(args, env, withdraw);
438 if (str(args, "note") !== undefined)
439 throw new UsageError('--note goes with --withdraw: abso ask --withdraw <ask> --note "why"');
440 const [of, ...words] = args.positionals;
441 if (of === undefined || words.length === 0)
442 throw new UsageError(
443 '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>',
444 );
445 const { api } = openIssues(env);
446 if (bool(args, "review") && bool(args, "task")) throw new UsageError("an ask is a review or a task, not both");
447 const issue = str(args, "issue");
448 const blocks = str(args, "blocks");
449 const options = str(args, "options");
450 const r = await api.ask({
451 of,
452 question: words.join(" "),
453 ...(issue !== undefined ? { issue: issueNumber(issue, "--issue") } : {}),
454 ...(bool(args, "review") ? { review: true } : {}),
455 ...(bool(args, "task") ? { kind: "task" as const } : {}),
456 ...(str(args, "due") ? { due: str(args, "due")! } : {}),
457 ...(blocks !== undefined ? { blocks: blocks.split(",").map((b) => issueNumber(b.trim(), "--blocks")) } : {}),
458 ...(options !== undefined
459 ? {
460 options: options
461 .split("|")
462 .map((o) => o.trim())
463 .filter((o) => o !== ""),
464 }
465 : {}),
466 });
467 return { text: `Asked ${of} (ask ${r.id}). They hear it; abso waiting shows what's open.`, json: { id: r.id } };
470/** abso ask --withdraw <ask> [--note "why"]: the asker takes an ask back. It closes like an answer, and the one asked hears it. */
471async function withdrawAsk(args: Parsed, env: Env, word: string): Promise<Output> {
472 const others = ["issue", "due", "blocks", "options"].filter((f) => str(args, f) !== undefined);
473 if (args.positionals.length > 0 || others.length > 0 || bool(args, "review") || bool(args, "task"))
474 throw new UsageError('abso ask --withdraw <ask> [--note "why"] takes nothing else: it takes back an ask you made');
475 const id = issueNumber(word, "the ask number");
476 const { api } = openIssues(env);
477 const note = str(args, "note");
478 const r = await api.withdraw(id, note !== undefined ? { note } : {});
479 return { text: `Withdrew ask ${id}. ${r.ask.of} hears it, and it no longer waits on them.`, json: { ask: r.ask } };
482export async function runWaiting(args: Parsed, env: Env): Promise<Output> {
483 if (args.positionals.length > 0)
484 throw new UsageError("waiting takes no words: abso waiting [--of <agent or person:id>] [--mine]");
485 const { api, config } = openIssues(env);
486 const mine = bool(args, "mine") || str(args, "of") === config.agent;
487 const of = mine ? config.agent : str(args, "of");
488 const { asks } = mine ? await api.waitingMine() : await api.waiting(of);
489 return {
490 text:
491 asks.length === 0
492 ? `Nothing is waiting${of ? ` on ${of}` : ""}.`
493 : [
494 `${plural(asks.length, "open ask")}${of ? ` of ${of}` : ""}, soonest due first:`,
495 ...asks.map(askLine),
496 'abso answer <ask> "..." answers one asked of you.',
497 ].join("\n"),
498 json: { asks },
499 };
502export async function runAnswer(args: Parsed, env: Env): Promise<Output> {
503 const [first, ...words] = args.positionals;
504 const id = issueNumber(first, "the ask number");
505 const option = str(args, "option");
506 const done = bool(args, "done");
507 if (words.length === 0 && option === undefined && !done)
508 throw new UsageError('abso answer <ask> "<words>" | --option <N> [--note "..."] | --done [--note "..."]');
509 const { api } = openIssues(env);
510 const note = str(args, "note");
511 const r = await api.answer(id, {
512 ...(words.length > 0 ? { words: words.join(" ") } : {}),
513 ...(option !== undefined ? { option: /^\d+$/.test(option) ? Number(option) - 1 : option } : {}),
514 ...(done ? { done: true } : {}),
515 ...(note !== undefined ? { note } : {}),
516 });
517 return { text: `Answered ask ${id}. ${r.ask.by} hears it.`, json: { ask: r.ask } };