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