`
+// their Markdown forms, and block tags (``, ``, ``, ``,
+// headings) paragraphs. Only src, alt and href are read from attributes; every
+// other tag is dropped and its text kept as text. The contents of script, style
+// and similar tags are dropped. URLs still pass `safeUrl` in the renderer.
+
+// Images the server's proxy (GET /img, src/dash/server/images.ts) fetches:
+// the same hosts and path shapes. Anything else stays a link.
+const PROXIED: [string, RegExp][] = [
+ ["github.com", /^\/user-attachments\/assets\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i],
+ ["private-user-images.githubusercontent.com", /^\/./],
+ ["user-images.githubusercontent.com", /^\/./],
+ ["raw.githubusercontent.com", /^\/storytold\/./],
+ ["avatars.githubusercontent.com", /^\/./],
+];
+
+export function proxiedImage(src: string): string | null {
+ let u: URL;
+ try {
+ u = new URL(src);
+ } catch {
+ return null;
+ }
+ if (u.protocol !== "https:" || u.username || u.password || u.port) return null;
+ if (!PROXIED.some(([host, path]) => u.hostname === host && path.test(u.pathname))) return null;
+ return `/img?${new URLSearchParams({ u: u.href })}`;
+}
+
+export const safeUrl = (url: string): string => (/^(https?:|mailto:|#|\/)/i.test(url) ? url : "");
+
+// Minimal mdast shapes; the plugin builds only these.
+export type MdNode = {
+ type: string;
+ value?: string;
+ url?: string;
+ alt?: string;
+ title?: string | null;
+ children?: MdNode[];
+};
+
+const PHRASING_PARENTS = new Set(["paragraph", "heading", "tableCell", "emphasis", "strong", "delete", "link", "linkReference"]);
+const BLOCK_TAGS = new Set([
+ "p", "div", "center", "li", "ul", "ol", "details", "summary", "table", "thead", "tbody", "tr", "td", "th",
+ "blockquote", "pre", "hr", "h1", "h2", "h3", "h4", "h5", "h6", "dl", "dt", "dd", "figure", "figcaption", "section",
+]);
+const HEADINGS = new Set(["summary", "h1", "h2", "h3", "h4", "h5", "h6"]);
+// Tags whose content is not text the reader should see.
+const SKIP_CONTENT = new Set(["script", "style", "template", "iframe", "object", "embed", "svg", "math", "noscript", "textarea", "select", "head", "title"]);
+
+const TOKEN = /|$)|<(\/?)([a-zA-Z][a-zA-Z0-9-]*)((?:\s+[^\s"'>/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'>]+))?)*)\s*\/?>/g;
+const ATTR = /([^\s"'>/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>]+)))?/g;
+
+const ENTITIES: Record = { amp: "&", lt: "<", gt: ">", quot: '"', apos: "'", nbsp: " " };
+function decode(s: string): string {
+ return s.replace(/&(#x[0-9a-f]+|#\d+|[a-z]+);/gi, (m, e: string) => {
+ if (e[0] === "#") {
+ const cp = e[1] === "x" || e[1] === "X" ? parseInt(e.slice(2), 16) : parseInt(e.slice(1), 10);
+ return cp > 0 && cp <= 0x10ffff ? String.fromCodePoint(cp) : m;
+ }
+ return ENTITIES[e.toLowerCase()] ?? m;
+ });
+}
+
+function attrs(s: string): Map {
+ const out = new Map();
+ for (const m of s.matchAll(ATTR)) out.set(m[1]!.toLowerCase(), decode(m[2] ?? m[3] ?? m[4] ?? "").trim());
+ return out;
+}
+
+const fileName = (url: string) => {
+ try {
+ return decodeURIComponent(new URL(url).pathname.split("/").pop() ?? "");
+ } catch {
+ return "";
+ }
+};
+
+// Builds Markdown nodes from a run of HTML strings and ready nodes. In block
+// mode the output is paragraphs; in inline mode block tags become line breaks.
+class Builder {
+ private out: MdNode[] = [];
+ private stack: MdNode[] = [];
+ private skip: string[] = [];
+ private code: MdNode | null = null;
+ private pendingVideo: MdNode | null = null;
+ private block: boolean;
+ constructor(block: boolean) {
+ this.block = block;
+ }
+
+ private top(): MdNode {
+ if (this.stack.length === 0) {
+ const p: MdNode = this.block ? { type: "paragraph", children: [] } : { type: "fragment", children: [] };
+ this.stack.push(p);
+ }
+ return this.stack[this.stack.length - 1]!;
+ }
+
+ private add(n: MdNode) {
+ this.top().children!.push(n);
+ }
+
+ private text(s: string) {
+ if (this.skip.length) return;
+ if (this.code) {
+ this.code.value += decode(s);
+ return;
+ }
+ let t = decode(s).replace(/\s+/g, " ");
+ const empty = this.stack.length === 0 || (this.stack.length === 1 && this.stack[0]!.children!.length === 0);
+ if (empty) t = t.replace(/^ /, "");
+ if (!t) return;
+ const kids = this.top().children!;
+ const last = kids[kids.length - 1];
+ if (last?.type === "text") last.value += t;
+ else kids.push({ type: "text", value: t });
+ }
+
+ // Closes every open container and emits the paragraph (block mode) or its
+ // children (inline mode).
+ private flush() {
+ while (this.stack.length > 1) this.pop();
+ const root = this.stack.pop();
+ this.code = null;
+ if (!root) return;
+ const kids = root.children!;
+ while (kids.length && kids[kids.length - 1]!.type === "text" && !kids[kids.length - 1]!.value!.trim()) kids.pop();
+ if (!kids.length) return;
+ if (this.block) this.out.push(root);
+ else this.out.push(...kids);
+ }
+
+ private pop() {
+ const n = this.stack.pop()!;
+ if (n.type === "link" && n.children!.length === 0) n.children!.push({ type: "text", value: n.url! });
+ this.top().children!.push(n);
+ }
+
+ private popTo(type: string) {
+ const i = this.stack.findLastIndex((n) => n.type === type);
+ if (i <= 0) return;
+ while (this.stack.length > i) this.pop();
+ }
+
+ private open(type: string, extra: Partial = {}) {
+ this.top();
+ this.stack.push({ type, children: [], ...extra });
+ }
+
+ private blockBreak() {
+ if (this.block) this.flush();
+ else {
+ const kids = this.top().children!;
+ if (kids.length && kids[kids.length - 1]!.type !== "break") this.add({ type: "break" });
+ }
+ }
+
+ private tag(close: boolean, name: string, rawAttrs: string) {
+ if (this.skip.length) {
+ if (name === this.skip[this.skip.length - 1]) {
+ if (close) this.skip.pop();
+ else this.skip.push(name);
+ }
+ return;
+ }
+ if (SKIP_CONTENT.has(name)) {
+ if (!close && !/\/\s*$/.test(rawAttrs)) this.skip.push(name);
+ return;
+ }
+ if (name === "code" || name === "tt" || name === "kbd") {
+ if (close) this.code = null;
+ else if (!this.code) {
+ this.code = { type: "inlineCode", value: "" };
+ this.add(this.code);
+ }
+ return;
+ }
+ if (this.code) return;
+ const a = close ? new Map() : attrs(rawAttrs);
+ switch (name) {
+ case "img": {
+ const src = a.get("src");
+ if (src) this.add({ type: "image", url: src, alt: a.get("alt") ?? "", title: null });
+ return;
+ }
+ case "video": {
+ if (close) {
+ this.pendingVideo = null;
+ return;
+ }
+ const src = a.get("src");
+ const link: MdNode = { type: "link", url: src ?? "", title: null, children: [{ type: "text", value: "Video" }] };
+ this.pendingVideo = src ? null : link;
+ if (src) this.addVideo(link);
+ return;
+ }
+ case "source": {
+ const src = a.get("src");
+ if (this.pendingVideo && src) {
+ this.pendingVideo.url = src;
+ this.addVideo(this.pendingVideo);
+ this.pendingVideo = null;
+ }
+ return;
+ }
+ case "br":
+ if (!close) this.add({ type: "break" });
+ return;
+ case "a": {
+ if (close) return this.popTo("link");
+ const href = a.get("href");
+ if (href && !this.stack.some((n) => n.type === "link")) this.open("link", { url: href, title: null });
+ return;
+ }
+ case "b":
+ case "strong":
+ return close ? this.popTo("strong") : this.open("strong");
+ case "i":
+ case "em":
+ return close ? this.popTo("emphasis") : this.open("emphasis");
+ }
+ if (!BLOCK_TAGS.has(name)) return;
+ this.blockBreak();
+ if (close) return;
+ if (HEADINGS.has(name)) this.open("strong");
+ else if (name === "li") this.text("• ");
+ else if (name === "td" || name === "th") this.text(" ");
+ }
+
+ private addVideo(link: MdNode) {
+ const name = fileName(link.url!);
+ link.children = [{ type: "text", value: name ? `Video: ${name}` : "Video" }];
+ this.add(link);
+ }
+
+ html(s: string) {
+ let last = 0;
+ for (const m of s.matchAll(TOKEN)) {
+ if (m.index > last) this.text(s.slice(last, m.index));
+ last = m.index + m[0].length;
+ if (m[2]) this.tag(m[1] === "/", m[2].toLowerCase(), m[3] ?? "");
+ }
+ if (last < s.length) this.text(s.slice(last));
+ }
+
+ node(n: MdNode) {
+ if (this.skip.length) return;
+ if (this.code && (n.type === "text" || n.type === "inlineCode")) this.code.value += n.value ?? "";
+ else this.add(n);
+ }
+
+ done(): MdNode[] {
+ this.flush();
+ return this.out;
+ }
+}
+
+/** The nodes one block-level HTML string becomes. */
+export function htmlBlock(html: string): MdNode[] {
+ const b = new Builder(true);
+ b.html(html);
+ return b.done();
+}
+
+/** Rewrites a phrasing parent's children, where each HTML tag is its own node. */
+export function inlineChildren(children: MdNode[]): MdNode[] {
+ const b = new Builder(false);
+ for (const c of children) {
+ if (c.type === "html") b.html(c.value ?? "");
+ else b.node(c);
+ }
+ return b.done();
+}
+
+function walk(n: MdNode) {
+ const kids = n.children;
+ if (!kids) return;
+ for (const c of kids) walk(c);
+ if (!kids.some((c) => c.type === "html")) return;
+ if (PHRASING_PARENTS.has(n.type)) n.children = inlineChildren(kids);
+ else n.children = kids.flatMap((c) => (c.type === "html" ? htmlBlock(c.value ?? "") : [c]));
+}
+
+/** Remark plugin: replaces raw HTML nodes with the Markdown nodes above. */
+export function remarkHtmlToMarkdown() {
+ return (tree: MdNode) => walk(tree);
+}
From 49d719f3fa7c1f01ac135ff3ff1af91dd8e8ff50 Mon Sep 17 00:00:00 2001
From: aiongg <67543387+aiongg@users.noreply.github.com>
Date: Mon, 2 Nov 2026 19:00:28 +0000
Subject: [PATCH 2/8] Item page: real file count, discussion, timeline and
readable verdicts
The item API returns changed_files, closed/merged times and the merger; the
page shows the file count, leaves out Checks and Mergeable when the mirror has
no data, lists GitHub comments and reviews, adds opened/merged/closed to the
timeline, and spells out topics and scored reasons.
---
src/dash/api/index.ts | 7 +-
test/api.test.ts | 3 +
web/src/api/mock/fixtures.ts | 4 +
web/src/api/types.ts | 7 ++
web/src/modules/item/index.tsx | 150 +++++++++++++++++++++++++++------
5 files changed, 142 insertions(+), 29 deletions(-)
diff --git a/src/dash/api/index.ts b/src/dash/api/index.ts
index 2ba57bd2e..9d5a946d9 100644
--- a/src/dash/api/index.ts
+++ b/src/dash/api/index.ts
@@ -59,8 +59,8 @@ function trackedOnly(db: DatabaseSync, repo: string): void {
type ItemRow = {
repo: string; number: number; kind: string; state: string; title: string | null; body: string | null; author: string | null;
- created_at: string | null; updated_at: string | null; labels: string | null; additions: number | null; deletions: number | null;
- mergeable: string | null; ci_state: string | null;
+ created_at: string | null; updated_at: string | null; labels: string | null; additions: number | null; deletions: number | null; changed_files: number | null;
+ mergeable: string | null; ci_state: string | null; closed_at: string | null; merged_at: string | null; merged_by: string | null;
};
function item(db: DatabaseSync, req: Req): Item {
@@ -88,10 +88,13 @@ function item(db: DatabaseSync, req: Req): Item {
title: it.title ?? "", body: it.body ?? "", state: itemState(it.state), author: it.author ?? "",
tier: TIER[c?.tier ?? "not"] ?? "not", authorMerged: c?.merged ?? 0, authorClosedUnmerged: c?.closed ?? 0,
additions: it.additions ?? 0, deletions: it.deletions ?? 0,
+ changedFiles: it.kind === "pr" ? it.changed_files : null,
+ // The mirror stores only the rollup state and the counts, not per-file or per-check rows.
files: [], ciChecks: [],
ci: it.kind === "pr" ? (CI[it.ci_state ?? ""] ?? "none") : "none",
mergeable: MERGEABLE[it.mergeable ?? ""] ?? "unknown",
labels, createdAt: it.created_at ?? "", updatedAt: it.updated_at ?? "",
+ closedAt: it.closed_at, mergedAt: it.merged_at, mergedBy: it.merged_by,
related: relatedOf(db, repo, n), classifications: classificationsOf(db, repo, n),
stages: stages.map((s) => ({ ...s, by: s.by ?? "" })),
comments: comments.map((x) => ({ ...x, author: x.author ?? "", body: x.body ?? "" })),
diff --git a/test/api.test.ts b/test/api.test.ts
index 4c8226a28..d463cfa04 100644
--- a/test/api.test.ts
+++ b/test/api.test.ts
@@ -42,6 +42,7 @@ before(async () => {
ins.run("photocraft", 4, "issue", "OPEN", "Crash on save", "d", "dave", now, now, null);
ins.run("photocraft", 5, "issue", "OPEN", "Wave filter missing", "e", "erin", now, now, null);
ins.run("untracked-repo", 6, "pr", "OPEN", "Add wave filter elsewhere", "f", "frank", now, now, null);
+ db.prepare("UPDATE items SET additions = 40, deletions = 3, changed_files = 7 WHERE repo = 'photocraft' AND number = 1").run();
db.prepare("INSERT INTO comments (repo, number, id, kind, author, created_at, body) VALUES ('photocraft', 1, 'c1', 'comment', 'alice', ?, 'looks good')").run(now);
db.prepare("INSERT INTO classifications (repo, number, classifier, run_id, at, type_label, want, reason) VALUES ('photocraft', 1, 'haiku', 'r1', ?, 'small extra', 'yes', 'adds a filter')").run(now);
ask(db, [P1, P2, F3, P4].map((id) => {
@@ -130,6 +131,8 @@ describe("api", () => {
assert.equal((await (await signedIn("maint")).get("/api/me")).role, "viewer");
const it = await boss.get- ("/api/items/photocraft/1");
assert.equal(it.body, " body");
+ assert.deepEqual([it.changedFiles, it.additions, it.deletions], [7, 40, 3]);
+ assert.equal((await boss.get
- ("/api/items/photocraft/4")).changedFiles, null);
assert.deepEqual(it.comments.map((c) => c.body), ["looks good"]);
assert.deepEqual(it.decisionIds, [P1]);
assert.deepEqual(it.related.map((r) => [r.number, r.relation]), [[5, "fixes"]]);
diff --git a/web/src/api/mock/fixtures.ts b/web/src/api/mock/fixtures.ts
index db262bda2..ffdcddd0c 100644
--- a/web/src/api/mock/fixtures.ts
+++ b/web/src/api/mock/fixtures.ts
@@ -720,6 +720,7 @@ export function itemFor(repo: string, number: number): Item {
authorClosedUnmerged: closedUn,
additions: s.size?.[0] ?? 0,
deletions: s.size?.[1] ?? 0,
+ changedFiles: isIssue ? null : filesFor(s).length,
files: filesFor(s),
ci,
ciChecks: checks,
@@ -727,6 +728,9 @@ export function itemFor(repo: string, number: number): Item {
labels: isIssue ? ["bug"] : ["enhancement", ...(s.kind === "scope" ? ["needs-scope"] : [])],
createdAt: iso(s.ageH * H + 26 * H),
updatedAt: iso(s.ageH * H - 2 * H),
+ closedAt: null,
+ mergedAt: null,
+ mergedBy: null,
related: s.related ?? [],
classifications: d.classifications,
stages: stagesFor(s, d),
diff --git a/web/src/api/types.ts b/web/src/api/types.ts
index c697f35e4..9d20d5aee 100644
--- a/web/src/api/types.ts
+++ b/web/src/api/types.ts
@@ -156,13 +156,20 @@ export interface Item extends ItemRef {
authorClosedUnmerged: number;
additions: number;
deletions: number;
+ /** PRs: how many files the PR changes, from the mirror; null when unknown. */
+ changedFiles: number | null;
+ /** Per-file changes; empty when the mirror has none. */
files: ChangedFile[];
+ /** "none" also when the mirror has no check data for the item. */
ci: CiState;
ciChecks: { name: string; state: CiState; minutes: number }[];
mergeable: Mergeable;
labels: string[];
createdAt: string;
updatedAt: string;
+ closedAt: string | null;
+ mergedAt: string | null;
+ mergedBy: string | null;
related: RelatedItem[];
classifications: Classification[];
stages: StageEntry[];
diff --git a/web/src/modules/item/index.tsx b/web/src/modules/item/index.tsx
index 3229932b1..4df22375c 100644
--- a/web/src/modules/item/index.tsx
+++ b/web/src/modules/item/index.tsx
@@ -13,10 +13,11 @@ import {
FlagIcon,
CircleCheckIcon,
CircleSlashIcon,
+ MessageSquareIcon,
type LucideIcon,
} from "lucide-react";
import { useQuery } from "../../api/client";
-import type { CiState, Classification, Item, Stage, Tier } from "../../api/types";
+import type { CiState, Classification, Item, ItemComment, Stage, Tier } from "../../api/types";
import type { FeatureModule, ViewProps } from "../../registry/types";
import { Slot } from "../../registry/Slot";
import { Avatar } from "../../ui/Avatar";
@@ -91,6 +92,11 @@ function ItemMain({ params }: ViewProps) {
)}
+ {it.comments.length > 0 && (
+
+ )}
);
@@ -142,6 +148,9 @@ function Properties({ it }: { it: Item }) {
const total = it.additions + it.deletions;
const passing = it.ciChecks.filter((c) => c.state === "passing").length;
const [CiIcon, ciCls] = CI_ICON[it.ci];
+ // The mirror records checks and mergeability only for open PRs; without them the rows are left out.
+ const showCi = it.kind === "pr" && it.ci !== "none";
+ const showMergeable = it.kind === "pr" && it.state === "open" && it.mergeable !== "unknown";
return (
@@ -157,28 +166,34 @@ function Properties({ it }: { it: Item }) {
+{num(it.additions)} −{num(it.deletions)}
- {it.files.length} files
+ {it.changedFiles !== null && (
+
+ {num(it.changedFiles)} {it.changedFiles === 1 ? "file" : "files"}
+
+ )}
{sizeBucket(total)}
>
) : (
Issue
)}
-
-
- {it.ci === "none" ? "No checks" : it.ci[0].toUpperCase() + it.ci.slice(1)}
-
- {it.ciChecks.length > 0 && (
-
- {passing} of {it.ciChecks.length} passed
+ {showCi && (
+
+
+ {it.ci[0]!.toUpperCase() + it.ci.slice(1)}
- )}
-
-
-
- {it.mergeable === "clean" ? "No conflicts" : it.mergeable === "conflicts" ? "Has conflicts" : "Unknown"}
-
-
+ {it.ciChecks.length > 0 && (
+
+ {passing} of {it.ciChecks.length} passed
+
+ )}
+
+ )}
+ {showMergeable && (
+
+ {it.mergeable === "clean" ? "No conflicts" : "Has conflicts"}
+
+ )}
{it.labels.map((l) => (
{l}
@@ -203,6 +218,29 @@ function agreement(cls: Classification[]) {
return n === cls.length ? "all agree on type" : `${n} of ${cls.length} agree on type`;
}
+const likelihood = (p: number) => (p < 0.2 ? "unlikely" : p < 0.5 ? "possible" : p < 0.8 ? "likely" : "very likely");
+const percent = (p: number) => `${Math.round(p * 100)}%`;
+
+// Classifiers that score labels write "bugfix 0.84; security 0.03; needs decision 0.27":
+// the chosen label's probability, then flag probabilities. Other reasons are prose.
+function Reason({ reason }: { reason: string }) {
+ const parts = reason.split(";").map((x) => /^\s*([a-z][a-z -]*?)\s+(0(?:\.\d+)?|1(?:\.0+)?)\s*$/i.exec(x));
+ if (!parts.length || parts.some((m) => !m)) return <>{reason}>;
+ const [label, ...flags] = parts.map((m) => ({ name: m![1]!, p: Number(m![2]) }));
+ return (
+ <>
+
+ {label!.name} ({percent(label!.p)})
+
+ {flags.length > 0 && (
+
+ {flags.map((f) => `${f.name[0]!.toUpperCase()}${f.name.slice(1)}: ${likelihood(f.p)} (${percent(f.p)})`).join(" · ")}
+
+ )}
+ >
+ );
+}
+
const WANT: Record = { yes: "text-ok", no: "text-bad", unclear: "text-warn" };
function Verdicts({ cls }: { cls: Classification[] }) {
@@ -223,7 +261,9 @@ function Verdicts({ cls }: { cls: Classification[] }) {
{ago(c.at)}
{c.reference && Reference: {c.reference}
}
- {c.reason}
+
+
+
))}
@@ -232,8 +272,8 @@ function Verdicts({ cls }: { cls: Classification[] }) {
{ label: "Type", render: (c) => c.typeLabel, off: (c) => c.typeLabel !== typeMaj },
{ label: "Want", render: (c) => {c.want}, off: (c) => c.want !== wantMaj },
{ label: "Reference", render: (c) => c.reference ?? none },
- { label: "Topics", render: (c) => c.topics },
- { label: "Reason", render: (c) => {c.reason} },
+ { label: "Topics", render: (c) => (c.topics === "many" ? "several topics" : "one topic") },
+ { label: "Reason", render: (c) => },
];
return (
@@ -280,23 +320,79 @@ const STAGE: Record
= {
"fixed-by-us": ["Fixed by us", CircleCheckIcon],
};
+type Event = { label: string; Icon: LucideIcon; at: string; by: string; note: string | null };
+
+// GitHub's own events from the mirror, merged with the pipeline's stages.
+// A pipeline merge or close already says who did it, so GitHub's copy is left out.
+function events(it: Item): Event[] {
+ const out: Event[] = [{ label: "Opened", Icon: it.kind === "pr" ? GitPullRequestIcon : CircleDotIcon, at: it.createdAt, by: it.author, note: null }];
+ for (const s of it.stages) {
+ const [label, Icon] = STAGE[s.stage];
+ out.push({ label, Icon, at: s.at, by: s.by, note: s.note });
+ }
+ const has = (st: Stage) => it.stages.some((s) => s.stage === st);
+ if (it.state === "merged" && it.mergedAt && !has("merged")) out.push({ label: "Merged", Icon: GitMergeIcon, at: it.mergedAt, by: it.mergedBy ?? "", note: null });
+ else if (it.state === "closed" && it.closedAt && !has("closed")) out.push({ label: "Closed", Icon: CircleSlashIcon, at: it.closedAt, by: "", note: null });
+ return out.filter((e) => e.at).sort((a, b) => Date.parse(a.at) - Date.parse(b.at));
+}
+
function Timeline({ it }: { it: Item }) {
+ const evs = events(it);
return (
-
- {it.stages.map((s, i) => {
- const last = i === it.stages.length - 1;
- const [label, Icon] = STAGE[s.stage];
+ {evs.length > 1 && }
+ {evs.map((e, i) => {
+ const last = i === evs.length - 1 && evs.length > 1;
return (
-
-
+
- {label} by {s.by}
- {s.note && · {s.note}}
+ {e.label}
+ {e.by && by {e.by}}
+ {e.note && · {e.note}}
- {ago(s.at)} ago
+ {ago(e.at)} ago
+
+ );
+ })}
+
+ );
+}
+
+const REVIEW: Record = {
+ APPROVED: ["approved", "ok"],
+ CHANGES_REQUESTED: ["requested changes", "bad"],
+ COMMENTED: ["reviewed", "neutral"],
+ DISMISSED: ["review dismissed", "neutral"],
+};
+
+// GitHub comments and reviews, oldest first. Bodies are untrusted: the same Markdown renderer as the description.
+function Discussion({ comments }: { comments: ItemComment[] }) {
+ return (
+
+ {comments.map((c) => {
+ const review = c.kind === "review" ? (REVIEW[c.reviewState ?? ""] ?? REVIEW.COMMENTED!) : null;
+ return (
+ -
+
+ {c.author ?
:
}
+
{c.author || "ghost"}
+ {review &&
{review[0]}}
+
+ {c.at ? ago(c.at, false) : ""}
+
+
+
+ {c.body.trim() ? (
+
+
+
+ ) : (
+
No text.
+ )}
+
);
})}
From 79fe373bcdfafd7d73ac53bdeceda7ea1ac2e55c Mon Sep 17 00:00:00 2001
From: aiongg <67543387+aiongg@users.noreply.github.com>
Date: Mon, 2 Nov 2026 19:01:52 +0000
Subject: [PATCH 3/8] Classifiers and Cost: unknown runs, phone layout,
distinct items, unpriced models
Classifiers says when ?run= names no run, scrolls a long By repo list and
stacks both answers under the title on phones. Cost counts distinct classified
items, lists items and price per model, says "price not reported" for models
without USD, and leaves out the spend chart below three buckets.
---
src/dash/api/insight.ts | 1 +
test/insight.test.ts | 1 +
web/src/api/mock/insightFixtures.ts | 2 +-
web/src/api/types.ts | 2 ++
web/src/modules/classifiers/index.tsx | 34 ++++++++++++++----
web/src/modules/cost/index.tsx | 50 +++++++++++++++++++++++----
6 files changed, 75 insertions(+), 15 deletions(-)
diff --git a/src/dash/api/insight.ts b/src/dash/api/insight.ts
index c41c790f2..a634dd069 100644
--- a/src/dash/api/insight.ts
+++ b/src/dash/api/insight.ts
@@ -148,6 +148,7 @@ export function cost(db: DatabaseSync, req: Req): CostReport {
runs: db.prepare(`SELECT run_id AS id, MIN(started_at) AS "from", MAX(COALESCE(ended_at, started_at)) AS "to" FROM token_usage GROUP BY run_id ORDER BY MAX(COALESCE(ended_at, started_at)) DESC`).all() as CostReport["runs"],
run,
total: { ...(total as object) } as UsageTotals,
+ itemsClassified: (db.prepare(`SELECT COUNT(*) AS n FROM (SELECT DISTINCT repo, number FROM classifications WHERE ${flt})`).get(p) as { n: number }).n,
stages: q(`SELECT COALESCE(stage, '') AS stage, COALESCE(model, '') AS model, ${TOTALS} FROM token_usage WHERE ${flt} GROUP BY stage, model ORDER BY stage, model`),
repos: q(`SELECT repo, ${TOTALS} FROM token_usage WHERE ${flt} AND repo IS NOT NULL GROUP BY repo ORDER BY COALESCE(SUM(COALESCE(input_tokens, 0) + COALESCE(output_tokens, 0) + COALESCE(cache_read_tokens, 0) + COALESCE(cache_write_tokens, 0)), 0) DESC`),
series: q(`SELECT substr(COALESCE(ended_at, started_at), 1, ${len}) AS bucket,
diff --git a/test/insight.test.ts b/test/insight.test.ts
index f4e25303a..c6287985e 100644
--- a/test/insight.test.ts
+++ b/test/insight.test.ts
@@ -65,6 +65,7 @@ describe("insight", () => {
test("cost totals, wall time and series", () => {
const c = cost(db, rq("run=r1"));
assert.deepEqual(c.total, { calls: 2, items: 6, input: 150, output: 30, cacheRead: 10, cacheWrite: 0, usd: 0.25, wallSeconds: 180 });
+ assert.equal(c.itemsClassified, 6);
assert.equal(c.stages.length, 1);
assert.deepEqual(c.series, [{ bucket: "2026-11-01T10", tokens: 190, usd: 0.25 }]);
});
diff --git a/web/src/api/mock/insightFixtures.ts b/web/src/api/mock/insightFixtures.ts
index f4514a09e..abe20047c 100644
--- a/web/src/api/mock/insightFixtures.ts
+++ b/web/src/api/mock/insightFixtures.ts
@@ -122,5 +122,5 @@ export function costReport(run = ""): CostReport {
tokens: Math.round((900_000 + r() * 6_000_000) * k),
usd: Math.round((0.4 + r() * 4.5) * k * 100) / 100,
}));
- return { runs: [{ id: RUN, from: "2026-10-27T08:00:00Z", to: "2026-11-02T10:30:00Z" }, { id: "pilot-1029", from: "2026-10-29T14:00:00Z", to: "2026-10-29T15:10:00Z" }], run, total, stages, repos, series, bucketSize: "hour" };
+ return { runs: [{ id: RUN, from: "2026-10-27T08:00:00Z", to: "2026-11-02T10:30:00Z" }, { id: "pilot-1029", from: "2026-10-29T14:00:00Z", to: "2026-10-29T15:10:00Z" }], run, total, itemsClassified: Math.round(21000 * k), stages, repos, series, bucketSize: "hour" };
}
diff --git a/web/src/api/types.ts b/web/src/api/types.ts
index 9d20d5aee..8b42a12fe 100644
--- a/web/src/api/types.ts
+++ b/web/src/api/types.ts
@@ -489,6 +489,8 @@ export interface CostReport {
/** A run id, or "" for all runs. */
run: string;
total: UsageTotals;
+ /** Distinct items with a classification in the run (or all runs); `total.items` counts an item once per model. */
+ itemsClassified: number;
stages: ({ stage: string; model: string } & UsageTotals)[];
repos: ({ repo: string } & UsageTotals)[];
/** Spend per time bucket; `bucket` is an ISO hour or day. */
diff --git a/web/src/modules/classifiers/index.tsx b/web/src/modules/classifiers/index.tsx
index 2995400c7..4a230632a 100644
--- a/web/src/modules/classifiers/index.tsx
+++ b/web/src/modules/classifiers/index.tsx
@@ -93,8 +93,8 @@ function Disagreements({ r, label, band, setFilter }: { r: ClassifierReport; lab
| Item |
Title |
- {r.a} |
- {r.b} |
+ {r.a} |
+ {r.b} |
@@ -103,11 +103,24 @@ function Disagreements({ r, label, band, setFilter }: { r: ClassifierReport; lab
|
- {d.title} |
-
+ |
+ {d.title}
+ {/* Phones: the two answers under the title instead of in their own columns. */}
+
+ - {r.a}
+ -
+ {d.a.label} {prob(d.a.prob)}
+
+ - {r.b}
+ -
+ {d.b.label} {prob(d.b.prob)}
+
+
+ |
+
{d.a.label} {prob(d.a.prob)}
|
-
+ |
{d.b.label} {prob(d.b.prob)}
|
@@ -168,6 +181,11 @@ function Classifiers(_: ViewProps) {
options={cur.pairs.map((p) => ({ value: `${p.a}|${p.b}`, label: `${p.a} vs ${p.b} (${num(p.items)})` }))}
/>
+ {run && run !== r.run && (
+
+ There is no run {run}. Showing the latest run, {r.run}.
+
+ )}
Agreement on the type label, per run. Rows are grouped by {r.a}'s answer.
@@ -181,8 +199,10 @@ function Classifiers(_: ViewProps) {
({ key: x.label, n: x.n, agree: x.agree }))} picked={label} onPick={(k) => set({ label: label === k ? "" : k })} />
-
- ({ key: x.repo, n: x.n, agree: x.agree }))} />
+
+
+
({ key: x.repo, n: x.n, agree: x.agree }))} />
+
diff --git a/web/src/modules/cost/index.tsx b/web/src/modules/cost/index.tsx
index 1396d770b..6c90dce55 100644
--- a/web/src/modules/cost/index.tsx
+++ b/web/src/modules/cost/index.tsx
@@ -4,6 +4,7 @@ import { useQuery } from "../../api/client";
import type { CostReport, UsageTotals } from "../../api/types";
import type { FeatureModule, ViewProps } from "../../registry/types";
import { num } from "../../lib/format";
+import { cn } from "../../ui/cn";
import { Block, Select, Stat, Th } from "../insight/parts";
const tokens = (u: UsageTotals) => u.input + u.output + u.cacheRead + u.cacheWrite;
@@ -44,7 +45,7 @@ function UsageTable({ rows, name, subName }: { rows: Row[]; name: string; subNam
{num(u.output)} |
{num(u.cacheRead)} |
{num(u.cacheWrite)} |
- {usd(u.usd)} |
+ {u.usd === null ? "price not reported" : usd(u.usd)} |
{per(tokens(u), u.items)} |
{perUsd(u.usd, u.items)} |
{wall(u.wallSeconds)} |
@@ -86,12 +87,45 @@ function SpendChart({ r }: { r: CostReport }) {
);
}
+type ModelTotals = { model: string; items: number; usd: number | null };
+
+// Totals per model across stages. USD stays null for a model that never reported a price.
+function byModel(r: CostReport): ModelTotals[] {
+ const m = new Map();
+ for (const s of r.stages) {
+ const cur = m.get(s.model) ?? { model: s.model || "unknown model", items: 0, usd: null };
+ cur.items += s.items;
+ if (s.usd !== null) cur.usd = (cur.usd ?? 0) + s.usd;
+ m.set(s.model, cur);
+ }
+ return [...m.values()].sort((a, b) => b.items - a.items);
+}
+
+// Spend per item counts only the items of models that report a price.
+function SpendSub({ models }: { models: ModelTotals[] }) {
+ const priced = models.filter((m) => m.usd !== null);
+ const unpriced = models.filter((m) => m.usd === null);
+ return (
+ <>
+ {priced.map((m) => (
+
+ {m.model}: {perUsd(m.usd, m.items)} per item
+
+ ))}
+ {unpriced.length > 0 && {unpriced.map((m) => m.model).join(", ")}: price not reported
}
+ >
+ );
+}
+
function Cost(_: ViewProps) {
const [sp, setSp] = useSearchParams();
const run = sp.get("run") ?? "";
const { data: r } = useQuery(`cost:${run}`, (api) => api.cost(run));
if (!r) return Loading…
;
const t = r.total;
+ const models = byModel(r);
+ // Each model's calls count the same item again, so the headline uses distinct classified items.
+ const items = r.itemsClassified || Math.max(0, ...models.map((m) => m.items));
return (
@@ -107,15 +141,17 @@ function Cost(_: ViewProps) {
Token use per agent call. USD appears where the agent reported a cost.
-
-
-
+ `${m.model} ${num(m.items)}`).join(" · ")} />
+
+ } />
-
-
-
+ {r.series.length >= 3 && (
+
+
+
+ )}
({ key: s.stage, sub: s.model, u: s }))} />
From 25c695666073e1b9ac28e6f636d127b2d128a430 Mon Sep 17 00:00:00 2001
From: aiongg <67543387+aiongg@users.noreply.github.com>
Date: Mon, 2 Nov 2026 19:03:20 +0000
Subject: [PATCH 4/8] Shell: operators-only notice, role chip on all widths,
styled server pages
Viewers opening an operator page read "Operators only."; the role chip shows
on phones and tablets; the server's own pages (signed out, errors, dev sign-in)
use the dashboard's colours and the theme chosen in the dashboard; the access
audit shows old "admin" roles as operator.
---
src/dash/server/index.ts | 2 +-
src/dash/server/util.ts | 25 +++++++++++++++++--------
web/src/modules/admin/access.tsx | 6 +++++-
web/src/shell/AppShell.tsx | 15 ++++++++++++---
4 files changed, 35 insertions(+), 13 deletions(-)
diff --git a/src/dash/server/index.ts b/src/dash/server/index.ts
index ace80e816..9bd6614a8 100644
--- a/src/dash/server/index.ts
+++ b/src/dash/server/index.ts
@@ -289,7 +289,7 @@ export function createApp(opts: AppOptions & { routes: Route[] }) {
return { r: { redirect: "/auth/signed-out" }, cookies: [cookie(SESSION_COOKIE, "", 0)] };
}
if (req.method === "GET" && path === "/auth/signed-out") {
- return { r: { html: plainPage(nonce, "Signed out", `
Sign in again
`) } };
+ return { r: { html: plainPage(nonce, "Signed out", `
You are signed out of the dashboard on this device.
Sign in again
`) } };
}
if (req.method === "GET" && path === "/auth/dev/authorize" && provider instanceof FakeProvider) {
const q = url.searchParams;
diff --git a/src/dash/server/util.ts b/src/dash/server/util.ts
index 883f1e56e..bacb8ff8a 100644
--- a/src/dash/server/util.ts
+++ b/src/dash/server/util.ts
@@ -12,18 +12,27 @@ export function esc(s: unknown): string {
return String(s ?? "").replace(/[&<>"']/g, (c) => `${c.charCodeAt(0)};`);
}
-// Minimal page for the server's own responses (sign-in, errors). Pages use
-// their own layout.
+// Minimal page for the server's own responses (sign-in, sign-out, errors), in
+// the dashboard's colours. The inline script applies the theme the reader chose
+// in the dashboard (stored by web/src/shell/theme.ts); without it the page
+// follows the system setting.
export function plainPage(nonce: string, title: string, body: string): string {
return `
${esc(title)}
+
${esc(title)}
${body}`;
+:root{color-scheme:dark;--bg:#101014;--card:#141518;--fg:#f2f1ee;--muted:#9a9aa0;--line:rgba(255,255,255,.1);--link:#74aaff;--accent:#2d81ff}
+@media (prefers-color-scheme:light){:root:not([data-theme=dark]){color-scheme:light;--bg:#f2f1ee;--card:#fbfaf8;--fg:#101014;--muted:#5f5f66;--line:rgba(16,16,20,.12);--link:#1454dc;--accent:#1b63f5}}
+:root[data-theme=light]{color-scheme:light;--bg:#f2f1ee;--card:#fbfaf8;--fg:#101014;--muted:#5f5f66;--line:rgba(16,16,20,.12);--link:#1454dc;--accent:#1b63f5}
+body{background:var(--bg);color:var(--fg);font:15px/1.5 Inter,system-ui,sans-serif;margin:0;min-height:100vh;display:flex;align-items:flex-start;justify-content:center;padding:12vh 16px 2rem;box-sizing:border-box}
+main{width:100%;max-width:26rem;background:var(--card);border:1px solid var(--line);border-radius:10px;padding:24px}
+.brand{font-size:13px;font-weight:600;color:var(--muted);margin:0 0 12px}
+h1{font-size:20px;line-height:1.3;margin:0 0 8px}
+p{margin:8px 0}a{color:var(--link)}p.muted{color:var(--muted)}code{font-size:13px}
+input,button,a.button{font:inherit;min-height:40px;padding:0 14px;border-radius:6px;box-sizing:border-box}
+input{border:1px solid var(--line);background:var(--bg);color:var(--fg)}
+button,a.button{display:inline-flex;align-items:center;border:0;background:var(--accent);color:#fff;text-decoration:none;font-weight:500;cursor:pointer}
+
Craft Triage
${esc(title)}
${body}