Versions 53 to 318
new file, 1,693 lines
1+// Issues for the open server (abso-core issue 17): one store per project, in SQLite, holding current state:
2+// issues, comments, labels, asks with their answers and threads, claims, the versions out for each issue,
3+// drafts, and what each reader's news has shown. Ported from the platform's issues Worker, without its
6+// Status comes from the work and nobody sets it: Done when a publish closed it (or someone marked it done),
7+// Blocked while an ask that isn't a review is open on it (or names it in `blocks`) or an issue it is blocked
8+// by is not done, In review while a review ask is open on it, In progress while a start note names it, and
11+// Watchers: who opened an issue, its Agent and any agent that claims it, its reviewer, whoever was named in
13+
30+
45+
50+
62+
73+
77+
80+
83+ * but a name character, so an email address isn't one. A sentence's full stop or dash after the name isn't
94+
106+
108+ * The tables the change count watches: what issue reads show. Not drafts (one person's), writes (the rate log),
109+ * search (kept from issues and comments) or meta. Fixed, since SCHEMA makes three triggers for each: a later
124+
126+ * The tables, as add-only migrations: the IssueProject object runs each once, in order (index.ts), so an
130+ `CREATE TABLE IF NOT EXISTS issues (id INTEGER PRIMARY KEY, parent INTEGER, title TEXT NOT NULL, description TEXT NOT NULL DEFAULT '',
133+ "CREATE TABLE IF NOT EXISTS comments (id INTEGER PRIMARY KEY, issue INTEGER NOT NULL, by TEXT NOT NULL, kind TEXT NOT NULL, text TEXT NOT NULL, at INTEGER NOT NULL)",
134+ `CREATE TABLE IF NOT EXISTS asks (id INTEGER PRIMARY KEY, issue INTEGER, by TEXT NOT NULL, of TEXT NOT NULL, kind TEXT NOT NULL, question TEXT NOT NULL,
135+ review INTEGER NOT NULL, due TEXT, recommendation TEXT, options TEXT NOT NULL, blocks TEXT NOT NULL, at INTEGER NOT NULL,
136+ answer_by TEXT, answer_words TEXT, answer_at INTEGER, seen_at INTEGER, outcome TEXT, ack_at INTEGER, ack_note TEXT, waiting_on TEXT)`,
137+ "CREATE TABLE IF NOT EXISTS claims (issue INTEGER NOT NULL, agent TEXT NOT NULL, change INTEGER NOT NULL, since INTEGER NOT NULL, PRIMARY KEY (issue, agent))",
138+ "CREATE TABLE IF NOT EXISTS versions (issue INTEGER NOT NULL, version INTEGER NOT NULL, agent TEXT NOT NULL, at INTEGER NOT NULL, PRIMARY KEY (issue, version))",
139+ "CREATE TABLE IF NOT EXISTS watchers (issue INTEGER NOT NULL, who TEXT NOT NULL, since INTEGER NOT NULL, PRIMARY KEY (issue, who))",
140+ "CREATE TABLE IF NOT EXISTS blocked_by (issue INTEGER NOT NULL, blocker INTEGER NOT NULL, PRIMARY KEY (issue, blocker))",
141+ "CREATE TABLE IF NOT EXISTS edits (id INTEGER PRIMARY KEY, issue INTEGER NOT NULL, by TEXT NOT NULL, changes TEXT NOT NULL, notified TEXT NOT NULL, at INTEGER NOT NULL)",
142+ "CREATE TABLE IF NOT EXISTS drafts (id INTEGER PRIMARY KEY, owner TEXT NOT NULL, body TEXT NOT NULL, saved_at INTEGER NOT NULL)",
145+ "CREATE TABLE IF NOT EXISTS labels (issue INTEGER NOT NULL, label TEXT NOT NULL, by TEXT NOT NULL, at INTEGER NOT NULL, PRIMARY KEY (issue, label))",
146+ // Ask threads: replies from either side while the ask is open or after. An ask's waiting_on is null while it
148+ "CREATE TABLE IF NOT EXISTS ask_replies (id INTEGER PRIMARY KEY, ask INTEGER NOT NULL, by TEXT NOT NULL, text TEXT NOT NULL, question INTEGER NOT NULL DEFAULT 0, at INTEGER NOT NULL)",
163+ // Search: every title, description and comment in a full-text index, kept in step by triggers.
164+ "CREATE VIRTUAL TABLE IF NOT EXISTS search USING fts5(issue UNINDEXED, comment UNINDEXED, field UNINDEXED, text, tokenize = 'porter unicode61')",
167+ INSERT INTO search (issue, comment, field, text) SELECT new.id, 0, 'description', new.description WHERE new.description <> '';
169+ `CREATE TRIGGER IF NOT EXISTS search_issue_edit AFTER UPDATE OF title, description ON issues BEGIN
172+ INSERT INTO search (issue, comment, field, text) SELECT new.id, 0, 'description', new.description WHERE new.description <> '';
174+ "CREATE TRIGGER IF NOT EXISTS search_issue_out AFTER DELETE ON issues BEGIN DELETE FROM search WHERE issue = old.id; END",
175+ "CREATE TRIGGER IF NOT EXISTS search_comment_in AFTER INSERT ON comments BEGIN INSERT INTO search (issue, comment, field, text) VALUES (new.issue, new.id, 'comment', new.text); END",
178+ INSERT INTO search (issue, comment, field, text) VALUES (new.issue, new.id, 'comment', new.text);
180+ "CREATE TRIGGER IF NOT EXISTS search_comment_out AFTER DELETE ON comments BEGIN DELETE FROM search WHERE comment = old.id; END",
181+ // The change count: one number that only grows, bumped by triggers on every table an issue read shows, so
182+ // every write path moves it, the seen marks waiting writes included. A reader can cache issue reads by it.
183+ "CREATE TABLE IF NOT EXISTS change_count (id INTEGER PRIMARY KEY CHECK (id = 1), n INTEGER NOT NULL)",
188+ `CREATE TRIGGER IF NOT EXISTS changed_${t}_${op.toLowerCase()} AFTER ${op} ON ${t} BEGIN UPDATE change_count SET n = n + 1 WHERE id = 1; END`,
192+
197+
212+
213+/** One issue a search found: where the best match is, a snippet around it, and how well it matched. */
225+
226+/** A search hit as the client reads it: the issue's title and the matched text, each with who wrote it. */
231+
238+
239+const UNKNOWN: ProseAuthorship = { kind: "unknown", actor: null, provenance: "unknown", authorField: null };
240+
242+ * Who wrote a text, from the column that names its writer: an agent, or a person (person:<id>). This server
247+ return { kind: by.startsWith("person:") ? "human" : "agent", actor: by, provenance: "native", authorField };
249+
260+
262+
267+
269+ * Words that reach agents on pages and in news: within `max`, with nothing a reader can't see (the engine's
272+function text(value: unknown, what: string, max: number, required = true, oneLine = false): string {
280+ if (t.length > max) throw new IssuesError(`${what} is ${t.length} characters; the most is ${max}`);
283+ throw new IssuesError(`${what} holds ${hidden}, which a reader of the page can't see; take it out`);
287+
293+
301+
312+ `${JSON.stringify(v)} isn't a label: 1-40 lower-case letters, digits, and - _ . : (like friction or area:client)`,
318+
323+
337+ throw new IssuesError("lines are {file, from, to, version}: lines from-to of a file at a version");
339+ return { file: text(l.file, "the lines' file", 1000, true, true), from: l.from!, to: l.to!, version: l.version! };
341+
343+
348+
349+ /** Over tables SCHEMA made (the object's migrations, or createTables in tests). `atomic` runs a transaction. */
355+
359+
363+
365+ * The change count: it grows with every write an issue read can show and never goes back, so a read cached
369+ return (this.rows("SELECT n FROM change_count WHERE id = 1")[0]?.n as number | undefined) ?? 0;
371+
373+ * A reader's news here, newest first, at most NEWS_MAX: answers to their asks, replies on asks they asked or
374+ * were asked, comments naming them as @name (`names`: what they go by; an agent goes by its own name), and on
375+ * issues they watch, others' comments, the edits that told them, and closes. Each is read when it is at or
381+ const mark = (this.rows("SELECT at FROM news_read WHERE who = ?", me)[0]?.at as number | undefined) ?? 0;
382+ const cut = (t: string) => (t.length > NEWS_TEXT_MAX ? `${t.slice(0, NEWS_TEXT_MAX - 1)}…` : t);
396+ `SELECT a.id, a.issue, i.title, a.answer_by AS by, a.answer_words AS text, a.answer_at AS at FROM asks a
398+ WHERE a.by = ? AND a.answer_at IS NOT NULL AND a.answer_at < ? AND a.answer_by <> ? AND (a.outcome IS NULL OR a.outcome <> 'withdrawn')
407+ `SELECT r.ask, a.issue, i.title, r.by, r.text, r.at FROM ask_replies r JOIN asks a ON a.id = r.ask
421+ `SELECT c.id, c.issue, i.title, c.by, c.text, c.at FROM comments c JOIN issues i ON i.id = c.issue
434+ `SELECT c.id, c.issue, i.title, c.by, c.text, c.at FROM comments c JOIN watchers w ON w.issue = c.issue AND w.who = ?
454+ `SELECT i.id AS issue, i.title, i.closed_by AS by, i.closed_how, i.closed_at AS at FROM issues i
456+ WHERE i.closed_at IS NOT NULL AND i.closed_at < ? AND i.closed_by <> ? ORDER BY i.closed_at DESC LIMIT ?`,
465+
469+ "INSERT INTO news_read (who, at) VALUES (?, ?) ON CONFLICT (who) DO UPDATE SET at = MAX(at, excluded.at)",
473+ return { read: this.rows("SELECT at FROM news_read WHERE who = ?", who(reader))[0]!.at as number };
475+
479+
485+
489+ if (id !== null) this.sql.exec("UPDATE issues SET updated_at = MAX(updated_at, ?) WHERE id = ?", at, id);
491+
494+ const inUse = new Set(this.rows("SELECT DISTINCT label FROM labels").map((l) => l.label as string));
498+ `this project has ${inUse.size} labels, and ${LABELS_PER_PROJECT} is the most; use one it has (abso issues --labels lists them)`,
501+
502+ /** Attachments aren't kept on this server: a write that names any is refused before anything is written. */
505+ throw new IssuesError("this server doesn't keep attachments; leave them off, or link the file instead", 501);
507+
514+ "INSERT INTO watchers (issue, who, since) VALUES (?, ?, ?) ON CONFLICT (issue, who) DO NOTHING",
520+
522+ return this.rows("SELECT who FROM watchers WHERE issue = ? ORDER BY since, who", id).map((w) => w.who as string);
524+
525+ /** Blocked by, checked: issues that exist, not `id` itself, and none already waiting on `id` (that would wait forever). */
539+
549+ for (const b of this.rows("SELECT blocker FROM blocked_by WHERE issue = ?", at)) next.push(b.blocker as number);
553+
562+ at = (this.rows("SELECT parent FROM issues WHERE id = ?", at)[0]?.parent as number | null | undefined) ?? null
564+ if (at === id) throw new IssuesError(`issue ${parent} is issue ${id} or under it, so it can't be its parent`);
568+
575+ "SELECT issue, COALESCE(waiting_on, of) AS of, review, blocks FROM asks WHERE answer_at IS NULL",
582+ held.set(id, [...(held.get(id) ?? []), { review: a.review === 1 && id === a.issue, of: a.of as string }]);
589+ versions.set(v.issue as number, [...(versions.get(v.issue as number) ?? []), v.version as number]);
591+ for (const c of this.rows("SELECT parent, COUNT(*) AS n FROM issues WHERE parent IS NOT NULL GROUP BY parent"))
599+ "SELECT blocked_by.issue, blocked_by.blocker, issues.closed_how FROM blocked_by LEFT JOIN issues ON issues.id = blocked_by.blocker ORDER BY blocked_by.blocker",
650+
654+ const where = `json_type(changes, '$.${field}') IS NOT NULL${id === undefined ? "" : " AND issue = ?"}`;
662+
663+ /** Who wrote an issue's title or description now: whoever last edited it, else whoever opened the issue. */
666+ return editor === undefined ? authored(row.opened_by, "issues.opened_by") : authored(editor, "edits.by");
668+
675+ answer: a.answer ? { ...a.answer, authorship: authored(a.answer.by, "asks.answer_by") } : null,
677+ ? { ack: { ...ack, authorship: { note: ack.note === "" ? UNKNOWN : authored(a.of, "ask_replies.by") } } }
679+ replies: a.replies.map((reply) => ({ ...reply, authorship: authored(reply.by, "ask_replies.by") })),
682+
684+
690+ filter: { status?: string; agent?: string; parent?: number; open?: boolean; labels?: readonly string[] } = {},
692+ const wanted = filter.labels === undefined ? [] : labelsOf([...filter.labels], "the labels to filter by");
696+ : this.rows("SELECT * FROM issues WHERE parent = ? ORDER BY updated_at DESC, id DESC", filter.parent);
705+
706+ /** Issues matching `q`, best first, one hit per issue at its best place. Drafts aren't searched. */
711+ "SELECT issue, comment, field, snippet(search, 3, char(1), char(2), '…', 14) AS snip, bm25(search) AS rank FROM search WHERE search MATCH ? ORDER BY rank LIMIT 500",
718+ const found = this.rows(`SELECT * FROM issues WHERE id IN (${ids.map(() => "?").join(", ")})`, ...ids);
754+
755+ /** Every label in use, with how many issues have it and how many of those are open (done and dropped aren't). */
758+ "SELECT label, COUNT(*) AS total, SUM(CASE WHEN issues.closed_how IS NULL THEN 1 ELSE 0 END) AS open FROM labels JOIN issues ON issues.id = labels.issue GROUP BY label ORDER BY label",
759+ ).map((r) => ({ label: r.label as string, open: r.open as number, total: r.total as number }));
761+
766+
769+ return this.rows("SELECT id, by, text, question, at FROM ask_replies WHERE ask = ? ORDER BY id", ask).map((r) => ({
777+
810+ claims: this.rows("SELECT agent, change, since FROM claims WHERE issue = ? ORDER BY since", id).map((c) => ({
818+
820+ * Open asks of someone (an agent's name or person:<id>), soonest due first, then oldest; every open ask without `of`.
821+ * When `reader` is the one they're asked of, each listed for the first time is marked seen now; the answer still
826+ "SELECT asks.*, issues.title FROM asks LEFT JOIN issues ON issues.id = asks.issue WHERE answer_at IS NULL";
830+ : this.rows(`${select} AND COALESCE(waiting_on, of) = ? ORDER BY due IS NULL, due, asks.id`, of);
842+
846+ "SELECT asks.*, issues.title FROM asks LEFT JOIN issues ON issues.id = asks.issue WHERE answer_at IS NOT NULL AND of = ? ORDER BY answer_at DESC LIMIT ?",
854+
855+ /** The asks someone sent: every open one, oldest first, then the latest answered or withdrawn. */
857+ const select = "SELECT asks.*, issues.title FROM asks LEFT JOIN issues ON issues.id = asks.issue WHERE asks.by = ?";
860+ ...this.rows(`${select} AND answer_at IS NOT NULL ORDER BY answer_at DESC LIMIT ?`, by, answeredLimit),
861+ ].map((r) => ({ ...this.authoredAsk(this.withFiles(askOf(r))), title: (r.title as string | null) ?? null }));
863+
867+ "SELECT asks.*, issues.title FROM asks LEFT JOIN issues ON issues.id = asks.issue WHERE asks.id = ?",
871+ return { ...this.authoredAsk(this.withFiles(askOf(r))), title: (r.title as string | null) ?? null };
873+
875+
881+ open(actor: Actor, body: Parameters<IssuesStore["openRecord"]>[1]): { id: number; news?: News } {
884+
909+ const open = this.rows("SELECT COUNT(*) AS n FROM issues WHERE closed_how IS NULL")[0]!.n as number;
911+ throw new IssuesError(`this project has ${open} open issues, the most it can hold; close some first`);
914+ "INSERT INTO issues (parent, title, description, opened_by, opened_at, updated_at, lines, agent) VALUES (?, ?, ?, ?, ?, ?, ?, ?) RETURNING id",
925+ for (const b of blockedBy) this.sql.exec("INSERT INTO blocked_by (issue, blocker) VALUES (?, ?)", id, b);
927+ this.sql.exec("INSERT INTO labels (issue, label, by, at) VALUES (?, ?, ?, ?)", id, l, who(actor), at);
930+ const to = unique([...(agent !== null ? [agent] : []), ...notify]).filter((p) => p !== who(actor));
940+ text: `${who(actor)} opened issue ${id}${parent !== null ? ` under issue ${parent}` : ""}: ${JSON.stringify(title)}${detail.length > 0 ? ` (${detail.join("; ")})` : ""}`,
945+
975+ if (title !== row.title) (changes.title = { from: row.title, to: title }), sets.push(["title", title]);
980+ (changes.description = { from: row.description, to: description }), sets.push(["description", description]);
995+ const before = this.rows("SELECT blocker FROM blocked_by WHERE issue = ? ORDER BY blocker", id).map(
1003+ if (body.labels !== undefined || body.addLabels !== undefined || body.removeLabels !== undefined) {
1004+ if (body.labels !== undefined && (body.addLabels !== undefined || body.removeLabels !== undefined))
1005+ throw new IssuesError("labels is the whole set; addLabels and removeLabels change it; send one or the other");
1013+ : labelsOf([...before.filter((l) => !drop.has(l)), ...labelsOf(body.addLabels, "addLabels")]);
1021+ throw new IssuesError("notify is true (tell the watchers, the default) or false (tell nobody)");
1023+ if (Object.keys(changes).length === 0) throw new IssuesError(`that changes nothing on issue ${id}`);
1026+ for (const [column, value] of sets) this.sql.exec(`UPDATE issues SET ${column} = ? WHERE id = ?`, value, id);
1029+ for (const b of blockedBy) this.sql.exec("INSERT INTO blocked_by (issue, blocker) VALUES (?, ?)", id, b);
1061+ this.touch(id, (row.parent as number | null) ?? null, (changes.parent?.to as number | null | undefined) ?? null);
1067+ changes.parent ? (changes.parent.to === null ? "no parent now" : `parent is issue ${changes.parent.to}`) : "",
1068+ changes.agent ? (changes.agent.to === null ? "no Agent now" : `Agent is ${changes.agent.to}`) : "",
1090+
1116+ text: `${who(actor)} ${kind === "objection" ? "objects" : "comments"} on issue ${id} (${JSON.stringify(row.title)}): ${JSON.stringify(t)}`,
1121+
1142+ const issue = body.issue === undefined || body.issue === null ? null : issueNumber(body.issue);
1154+ if (typeof body.due !== "string" || !/^\d{4}-\d{2}-\d{2}/.test(body.due) || Number.isNaN(Date.parse(body.due)))
1173+ const held = [...new Set(blocks.map((b) => issueNumber(b, "an issue it blocks")))].filter((b) => b !== issue);
1177+ "INSERT INTO asks (issue, by, of, kind, question, review, due, recommendation, options, blocks, at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id",
1199+ text: `${who(actor)} asks ${of} ${what}${where}: ${JSON.stringify(question)}${of.startsWith("person:") ? "" : ` Answer: abso answer ${a.id} "..."`}`,
1204+
1205+ /** An answer, in the answerer's own words, kept on the ask. Only the one asked answers; a task is answered "done". */
1218+ const r = this.rows("SELECT * FROM asks WHERE id = ?", issueNumber(askId, "an ask number"))[0];
1220+ if (r.of !== who(actor)) throw new IssuesError(`ask ${askId} is for ${r.of as string}, not ${who(actor)}`, 403);
1246+ text: `${who(actor)} answered ${ask.by}'s ${ask.review ? "review ask" : ask.kind}${ask.issue !== null ? ` on issue ${ask.issue}` : ""}: ${JSON.stringify(words)}`,
1251+
1254+ body: { words?: unknown; option?: unknown; expect?: unknown; note?: unknown; done?: unknown },
1259+ const pick = typeof body.option === "number" ? options[body.option] : options.find((o) => o === body.option);
1261+ throw new IssuesError(`ask ${askId}'s options are: ${options.map((o) => JSON.stringify(o)).join(", ")}`);
1264+ `ask ${askId}'s option ${Number(body.option) + 1} is ${JSON.stringify(pick)}, not the one you picked; look again`,
1276+
1279+ * blocking; it shows as acknowledged, and the asker hears it with the note. Acknowledging again updates
1283+ const r = this.rows("SELECT * FROM asks WHERE id = ?", issueNumber(askId, "an ask number"))[0];
1285+ if (r.of !== who(actor)) throw new IssuesError(`ask ${askId} is for ${r.of as string}, not ${who(actor)}`, 403);
1313+ text: `${who(actor)} has your ${ask.review ? "review ask" : ask.kind} (ask ${ask.id})${ask.issue !== null ? ` on issue ${ask.issue}` : ""} and will answer${note !== "" ? `: ${JSON.stringify(note)}` : "."}`,
1318+
1321+ * hears it. Whose turn it is: a reply from the one asked marked as a question waits on the asker; the asker's
1324+ reply(actor: Actor, askId: number, body: { text?: unknown; question?: unknown }): { ask: Ask; news: News } {
1325+ const r = this.rows("SELECT * FROM asks WHERE id = ?", issueNumber(askId, "an ask number"))[0];
1330+ `ask ${askId} is between ${r.by as string} and ${r.of as string}; only they reply on it. abso comment says something on its issue`,
1362+ text: `${me} replied on ask ${ask.id}${ask.issue !== null ? ` (issue ${ask.issue})` : ""}${question ? " with a question" : ""}: ${JSON.stringify(words)}${turn}${other.startsWith("person:") ? "" : ` abso ask ${ask.id} shows the thread.`}`,
1367+
1370+ * (answer_at set, so it leaves waiting and stops blocking), with the asker as answer_by, their note as
1374+ const r = this.rows("SELECT * FROM asks WHERE id = ?", issueNumber(askId, "an ask number"))[0];
1377+ throw new IssuesError(`ask ${askId} was asked by ${r.by as string}; only they can withdraw it`, 403);
1388+ "UPDATE asks SET answer_by = ?, answer_words = ?, answer_at = ?, outcome = 'withdrawn' WHERE id = ?",
1395+ this.withFiles(askOf({ ...r, answer_by: who(actor), answer_words: note, answer_at: at, outcome: "withdrawn" })),
1402+ text: `${who(actor)} withdrew their ${ask.review ? "review ask" : ask.kind} of ${ask.of}${ask.issue !== null ? ` on issue ${ask.issue}` : ""}${note !== "" ? `: ${JSON.stringify(note)}` : ""}`,
1407+
1412+ throw new IssuesError(`issue ${id} is ${row.closed_how === "done" ? "done" : "dropped"} already`, 409);
1414+ "UPDATE issues SET closed_how = 'dropped', closed_by = ?, closed_at = ?, updated_at = ? WHERE id = ?",
1421+ return { news: { issue: id, text: `${who(actor)} dropped issue ${id} (${JSON.stringify(row.title)})` } };
1423+
1433+ "UPDATE issues SET closed_how = NULL, closed_by = NULL, closed_version = NULL, closed_at = NULL, updated_at = ? WHERE id = ?",
1438+ return { news: { issue: id, text: `${who(actor)} reopened issue ${id} (${JSON.stringify(row.title)})` } };
1440+
1456+ "INSERT INTO versions (issue, version, agent, at) VALUES (?, ?, ?, ?) ON CONFLICT (issue, version) DO NOTHING",
1463+ "UPDATE issues SET closed_how = 'done', closed_by = ?, closed_version = ?, closed_at = ?, updated_at = ? WHERE id = ?",
1473+ news: { issue: id, text: `${by} marked issue ${id} (${JSON.stringify(row.title)}) done ${where}` },
1476+
1485+ const times = this.rows("SELECT at FROM writes WHERE who = ? ORDER BY at", who(actor)).map((w) => w.at as number);
1500+
1505+
1507+
1510+ return this.rows("SELECT * FROM drafts WHERE owner = ? ORDER BY saved_at DESC, id DESC", who(actor)).map(asDraft);
1512+
1537+ if (body.parent !== undefined && body.parent !== null) draft.parent = issueNumber(body.parent, "the parent");
1545+ draft.blockedBy = [...new Set(body.blockedBy.map((b) => issueNumber(b, "an issue it's blocked by")))];
1552+ if (saved.length > LIMITS.draft) throw new IssuesError(`a draft holds at most ${LIMITS.draft} characters`);
1555+ this.sql.exec("UPDATE drafts SET body = ?, saved_at = ? WHERE id = ?", saved, this.now(), id);
1558+ const n = this.rows("SELECT COUNT(*) AS n FROM drafts WHERE owner = ?", who(actor))[0]!.n as number;
1560+ throw new IssuesError(`you have ${n} drafts, the most there can be; open or delete some first`);
1570+
1574+
1575+ /** Opens a draft as an issue, with `body`'s fields over the draft's, and deletes the draft. The issue's news is the only news. */
1576+ openDraft(actor: Actor, id: number, body: Record<string, unknown> = {}): { id: number; news?: News } {
1582+
1594+
1595+ /** A start note names the issue (`change` is the note's log position). One that doesn't exist, or is closed, is ignored: the note stands either way. */
1600+ "INSERT INTO claims (issue, agent, change, since) VALUES (?, ?, ?, ?) ON CONFLICT (issue, agent) DO UPDATE SET change = excluded.change, since = excluded.since",
1610+
1616+
1617+ /** publish --done finished it, with that version of shared: done, and the version is one out for it. */
1623+ "INSERT INTO versions (issue, version, agent, at) VALUES (?, ?, ?, ?) ON CONFLICT (issue, version) DO NOTHING",
1632+ "UPDATE issues SET closed_how = 'done', closed_by = ?, closed_version = ?, closed_at = ? WHERE id = ?",
1640+ news: { issue: id, text: `${agent} finished issue ${id} (${JSON.stringify(row.title)}) in version ${version}` },
1644+
1652+
1653+/** A snippet with \u0001 and \u0002 around each match, as plain text and the matches' spans. */
1667+
1678+ recommendation: r.recommendation ? (JSON.parse(r.recommendation as string) as Ask["recommendation"]) : null,
1688+ r.answer_at !== null && r.answer_at !== undefined ? null : ((r.waiting_on as string | null) ?? (r.of as string)),
1691+ ...(typeof r.ack_at === "number" ? { ack: { at: r.ack_at, note: (r.ack_note as string | null) ?? "" } } : {}),
- MCP
- compare on this site's /mcp
- CLI
- abso diff 53 318 server/src/issues/store.ts --json
- JSON
- /christopher/abso-core/compare/53..318?file=server%2Fsrc%2Fissues%2Fstore.ts&format=json