{"draft":null,"from":71,"to":72,"files":[{"path":"client/src/issues.ts","added":103,"removed":6,"diff":"--- a/client/src/issues.ts\n+++ b/client/src/issues.ts\n@@ -27,6 +27,7 @@\n import { fromEnv } from \"./env-names.ts\";\n import { ignoredHere } from \"./fetch.ts\";\n import { loadIgnore, relativeTo } from \"./folder.ts\";\n+import type { AskReply } from \"./issues-wire.ts\";\n import { queuedLines, standing } from \"./queue.ts\";\n import { seenText, shortWhen } from \"./times.ts\";\n \n@@ -70,16 +71,35 @@\n \treturn `  ${String(i.id).padStart(3)}  ${i.status.padEnd(11)}  ${q(i.title)}${detail.length > 0 ? ` (${detail.join(\"; \")})` : \"\"}`;\n }\n \n-function askLine(a: Ask & { title?: string | null }, api?: Pick<Api, \"attachmentUrl\">): string {\n+/** The first line of a reply, for lists; abso ask <N> shows it whole. */\n+const firstLine = (text: string): string => {\n+\tconst line = text.split(\"\\n\")[0]!;\n+\treturn line.length < text.length ? `${line} ...` : line;\n+};\n+\n+/** One reply in an ask's thread. */\n+function replyLine(r: AskReply, indent: string, whole: boolean): string {\n+\treturn `${indent}${r.by}, ${shortWhen(r.at)}${r.question ? \", a question\" : \"\"}: ${q(whole ? r.text : firstLine(r.text))}`;\n+}\n+\n+/**\n+ * An ask: its head line, its files and options, then, in a list, its newest reply, or with `thread`, every\n+ * reply, oldest first; then its answer. Older servers send no thread, only the one asked's acknowledgement.\n+ */\n+function askLine(a: Ask & { title?: string | null }, api?: Pick<Api, \"attachmentUrl\">, thread = false): string {\n \tconst what = a.review ? \"a review\" : a.kind === \"task\" ? \"a task\" : \"a question\";\n \tconst where = a.issue === null ? \"\" : ` on issue ${a.issue}${a.title ? ` (${q(a.title)})` : \"\"}`;\n+\tconst replies = a.replies;\n \tconst extra = [\n \t\t// Who answered, and when, on the ask's own line, so a handled ask can't pass for an open one.\n \t\ta.answer\n \t\t\t? `${a.outcome === \"withdrawn\" ? \"withdrawn\" : \"answered\"} by ${a.answer.by}, ${shortWhen(a.answer.at)}`\n \t\t\t: \"\",\n-\t\t!a.answer && a.ack ? `acknowledged ${shortWhen(a.ack.at)}, not answered yet` : \"\",\n+\t\t!a.answer && a.ack && replies === undefined ? `acknowledged ${shortWhen(a.ack.at)}, not answered yet` : \"\",\n \t\t!a.answer && !a.ack && a.seen !== undefined ? seenText(a.seen) : \"\",\n+\t\treplies && replies.length > 0 ? (replies.length === 1 ? \"1 reply\" : `${replies.length} replies`) : \"\",\n+\t\t// Whose turn it is, when it isn't the one asked's: they asked something back.\n+\t\t!a.answer && a.waitingOn && a.waitingOn !== a.of ? `waiting on ${a.waitingOn}` : \"\",\n \t\ta.due ? `due ${a.due}` : \"\",\n \t\ta.blocks.length > 0 ? `blocks ${a.blocks.join(\", \")}` : \"\",\n \t].filter((x) => x !== \"\");\n@@ -87,7 +107,10 @@\n \tconst lines = [head, ...attachmentLines(api, a.attachments, \"    \")];\n \tif (a.options.length > 0) lines.push(`    options: ${a.options.map((o, i) => `${i + 1}. ${q(o)}`).join(\", \")}`);\n \tif (a.recommendation) lines.push(`    ${a.recommendation.by} recommends: ${q(a.recommendation.text)}`);\n-\tif (!a.answer && a.ack && a.ack.note !== \"\") lines.push(`    ${a.of} acknowledged: ${q(a.ack.note)}`);\n+\tif (replies === undefined) {\n+\t\tif (!a.answer && a.ack && a.ack.note !== \"\") lines.push(`    ${a.of} acknowledged: ${q(a.ack.note)}`);\n+\t} else if (thread) lines.push(...replies.map((r) => replyLine(r, \"    \", true)));\n+\telse if (replies.length > 0) lines.push(replyLine(replies[replies.length - 1]!, \"    last: \", false));\n \tif (a.answer && a.outcome === \"withdrawn\") {\n \t\tif (a.answer.words !== \"\") lines.push(`    why: ${q(a.answer.words)}`);\n \t} else if (a.answer)\n@@ -624,6 +647,7 @@\n \tif (str(args, \"note\") !== undefined)\n \t\tthrow new UsageError('--note goes with --withdraw: abso ask --withdraw <ask> --note \"why\"');\n \tconst [of, ...words] = args.positionals;\n+\tif (of !== undefined && words.length === 0 && /^\\d+$/.test(of)) return showAsk(args, env, of);\n \tif (of === undefined || words.length === 0)\n \t\tthrow new UsageError(\n \t\t\t'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>',\n@@ -659,6 +683,49 @@\n \t};\n }\n \n+/** abso ask <N>: one ask, open or closed, with its whole thread, its answer and whose turn it is. */\n+async function showAsk(args: Parsed, env: Env, word: string): Promise<Output> {\n+\tconst others = [\"issue\", \"due\", \"blocks\", \"options\", \"attach\"].filter((f) => str(args, f) !== undefined);\n+\tif (others.length > 0 || bool(args, \"review\") || bool(args, \"task\"))\n+\t\tthrow new UsageError('abso ask <N> shows ask N; to ask, say who and what: abso ask <who> \"<question>\"');\n+\tconst id = issueNumber(word, \"the ask number\");\n+\tconst { api, config } = openIssues(env);\n+\tconst { ask } = await api.askThread(id);\n+\tconst side = ask.of === config.agent || ask.by === config.agent;\n+\tconst turn = ask.waitingOn === config.agent ? \"you\" : ask.waitingOn;\n+\tconst steps = !side\n+\t\t? \"\"\n+\t\t: ask.answer\n+\t\t\t? `abso reply ${id} \"...\" still adds to it.`\n+\t\t\t: ask.of === config.agent\n+\t\t\t\t? `abso reply ${id} \"...\" adds to it; abso answer ${id} \"...\" answers and closes it.`\n+\t\t\t\t: `abso reply ${id} \"...\" adds to it.`;\n+\tconst next = [!ask.answer && turn ? `It waits on ${turn}.` : \"\", steps].join(\" \");\n+\treturn {\n+\t\ttext: [askLine(ask, api, true), next.trim()].filter((l) => l !== \"\").join(\"\\n\"),\n+\t\tjson: { ask },\n+\t};\n+}\n+\n+/** abso reply <ask> \"<words>\" [--question]: add to an ask's thread, as its asker or the one asked. */\n+export async function runReply(args: Parsed, env: Env): Promise<Output> {\n+\tconst [first, ...words] = args.positionals;\n+\tconst id = issueNumber(first, \"the ask number\");\n+\tif (words.length === 0)\n+\t\tthrow new UsageError(\n+\t\t\t`abso reply <ask> \"<words>\" [--question]: adds to an ask's thread, as its asker or the one asked`,\n+\t\t);\n+\tconst { api, config } = openIssues(env);\n+\tconst question = bool(args, \"question\");\n+\tconst r = await api.reply(id, { text: words.join(\" \"), ...(question ? { question: true } : {}) });\n+\tconst other = r.ask.by === config.agent ? r.ask.of : r.ask.by;\n+\tconst turn =\n+\t\t!r.ask.answer && r.ask.waitingOn\n+\t\t\t? ` It waits on ${r.ask.waitingOn === config.agent ? \"you\" : r.ask.waitingOn}.`\n+\t\t\t: \"\";\n+\treturn { text: `Replied on ask ${id}. ${other} hears it.${turn}`, json: { ask: r.ask } };\n+}\n+\n /** abso ask --withdraw <ask> [--note \"why\"]: the asker takes an ask back. It closes like an answer, and the one asked hears it. */\n async function withdrawAsk(args: Parsed, env: Env, word: string): Promise<Output> {\n \tconst others = [\"issue\", \"due\", \"blocks\", \"options\", \"attach\"].filter((f) => str(args, f) !== undefined);\n@@ -708,7 +775,8 @@\n \n export async function runWaiting(args: Parsed, env: Env): Promise<Output> {\n \tif (args.positionals.length > 0)\n-\t\tthrow new UsageError(\"waiting takes no words: abso waiting [--of <agent or person:id>] [--mine]\");\n+\t\tthrow new UsageError(\"waiting takes no words: abso waiting [--of <agent or person:id>] [--mine] [--asked]\");\n+\tif (bool(args, \"asked\")) return askedOf(args, env);\n \tconst { api, config } = openIssues(env);\n \tconst mine = bool(args, \"mine\") || str(args, \"of\") === config.agent;\n \tconst of = mine ? config.agent : str(args, \"of\");\n@@ -728,7 +796,7 @@\n \t\t\t\t: [\n \t\t\t\t\t\t`${plural(asks.length, \"open ask\")}${of ? ` of ${of}` : \"\"}, soonest due first:`,\n \t\t\t\t\t\t...asks.map((a) => askLine(a, api)),\n-\t\t\t\t\t\t'abso answer <ask> \"...\" answers one asked of you.',\n+\t\t\t\t\t\t'abso ask <N> shows one with its thread; abso reply <N> \"...\" adds to it; abso answer <N> \"...\" answers one asked of you.',\n \t\t\t\t\t]),\n \t\t].join(\"\\n\"),\n \t\tjson: {\n@@ -740,6 +808,35 @@\n \t};\n }\n \n+/** abso waiting --asked: the asks you sent, open ones first, then the latest answered, each with its newest reply. */\n+async function askedOf(args: Parsed, env: Env): Promise<Output> {\n+\tif (bool(args, \"mine\") || str(args, \"of\") !== undefined)\n+\t\tthrow new UsageError(\"--asked lists the asks you sent; it takes no --mine or --of\");\n+\tconst { api, config } = openIssues(env);\n+\tconst { asks } = await api.asked();\n+\tconst open = asks.filter((a) => !a.answer);\n+\tconst closed = asks.filter((a) => a.answer);\n+\treturn {\n+\t\ttext: [\n+\t\t\t...(asks.length === 0\n+\t\t\t\t? [`${config.agent} hasn't asked anything yet.`]\n+\t\t\t\t: [\n+\t\t\t\t\t\t...(open.length > 0\n+\t\t\t\t\t\t\t? [`${plural(open.length, \"open ask\")} you sent:`, ...open.map((a) => askLine(a, api))]\n+\t\t\t\t\t\t\t: []),\n+\t\t\t\t\t\t...(closed.length > 0\n+\t\t\t\t\t\t\t? [\n+\t\t\t\t\t\t\t\t\t`${closed.length === 1 ? \"The latest answered\" : `The latest ${closed.length} answered`}:`,\n+\t\t\t\t\t\t\t\t\t...closed.map((a) => askLine(a, api)),\n+\t\t\t\t\t\t\t\t]\n+\t\t\t\t\t\t\t: []),\n+\t\t\t\t\t\t\"abso ask <N> shows one with its whole thread.\",\n+\t\t\t\t\t]),\n+\t\t].join(\"\\n\"),\n+\t\tjson: { asks },\n+\t};\n+}\n+\n /** abso ack <ask> [\"note\"]: tell the asker you have it, and answer later. The ask stays open until abso answer. */\n export async function runAck(args: Parsed, env: Env): Promise<Output> {\n \tconst [first, ...words] = args.positionals;\n@@ -748,7 +845,7 @@\n \tconst note = words.join(\" \");\n \tconst r = await api.ack(id, note !== \"\" ? { note } : {});\n \treturn {\n-\t\ttext: `Acknowledged ask ${id}. ${r.ask.by} hears it; the ask stays open until abso answer ${id} \"...\".`,\n+\t\ttext: `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} \"...\".`,\n \t\tjson: { ask: r.ask },\n \t};\n }"}],"unmatched":[]}