diff --git a/pm-stack/aggregator/src/render.ts b/pm-stack/aggregator/src/render.ts index e426152093..43c938f1dd 100644 --- a/pm-stack/aggregator/src/render.ts +++ b/pm-stack/aggregator/src/render.ts @@ -412,6 +412,42 @@ window.__dashAfter = window.__dashAfter || function (form, msg) { window.dispatchEvent(new CustomEvent("dashrefresh")); if (!document.querySelector("[data-frag]")) location.reload(); }; +window.__dashAuthorPickers = window.__dashAuthorPickers || function () { + var fill = function (list) { + document.querySelectorAll("select[name=author][data-author-picker]").forEach(function (s) { + if (s.dataset.hydrated) return; + var cur = s.value; + var frag = document.createDocumentFragment(); + list.forEach(function (i) { + var o = document.createElement("option"); + o.value = i.kind + "|" + i.id + "|" + (i.sessionId || ""); + o.textContent = i.label + (i.kind === "agent" ? " (agent)" : ""); + if (i.id === "drew") o.defaultSelected = true; + frag.appendChild(o); + }); + s.replaceChildren(frag); + s.value = cur; + s.dataset.hydrated = "1"; + }); + }; + if (window.__dashIdentities) { fill(window.__dashIdentities); return; } + if (window.__dashIdentitiesPromise) return; + window.__dashIdentitiesPromise = fetch("/api/author-identities") + .then(function (r) { return r.json(); }) + .then(function (d) { window.__dashIdentities = (d && d.identities) || []; fill(window.__dashIdentities); }) + .catch(function () { window.__dashIdentitiesPromise = null; }); +}; +if (!window.__dashAuthorPickerHook) { + window.__dashAuthorPickerHook = true; + document.addEventListener("pointerdown", function (ev) { + var t = ev.target; + if (t && t.closest && t.closest("select[name=author][data-author-picker], .actbox, .cbox")) window.__dashAuthorPickers(); + }); + document.addEventListener("focusin", function (ev) { + var t = ev.target; + if (t && t.matches && t.matches("select[name=author][data-author-picker]")) window.__dashAuthorPickers(); + }); +} `; /** @@ -696,14 +732,30 @@ export interface CommentFormOpts { identities: AuthorIdentity[]; } -export function commentFormHtml(objectRef: string, opts: CommentFormOpts): string { - const ghRefs = opts.githubRefs ?? []; - const authorOptions = opts.identities +/** + * The author picker's server-rendered options (#1179): the standing + * identities only. Session identities (one per registry session -- + * ~700 and growing) used to be inlined into every card's picker, + * which made list pages quadratic: /program shipped 351 copies of a + * ~123 KB option list (44 MB of HTML), /board 94 copies (12.9 MB). + * The full list now loads on demand from /api/author-identities the + * first time any picker on the page is touched and is applied to + * every picker at once (see DASH_AFTER_JS). Pickers keep working + * without that fetch -- standing identities are the common case. + */ +export function authorOptionsHtml(identities: AuthorIdentity[]): string { + return identities + .filter((i) => !i.sessionId) .map( (i) => ``, ) .join(""); +} + +export function commentFormHtml(objectRef: string, opts: CommentFormOpts): string { + const ghRefs = opts.githubRefs ?? []; + const authorOptions = authorOptionsHtml(opts.identities); const ghTarget = ghRefs.length ? `` : ""; @@ -711,7 +763,7 @@ export function commentFormHtml(objectRef: string, opts: CommentFormOpts): strin ? `` : ""; return `
- +
@@ -896,18 +948,13 @@ export function cardCommentHtml( const list = comments?.length ? comments.map((c) => dashCommentHtml(c)).join("") : `

No comments on this card yet.

`; - const authorOptions = opts.identities - .map( - (i) => - ``, - ) - .join(""); + const authorOptions = authorOptionsHtml(opts.identities); const ghBox = ghRef ? `` : `No GitHub issue on this card — the comment stays internal.`; return `
💬 Comments for the orchestrator${comments?.length ? ` (${comments.length})` : ""}${list} - +
${ghBox}
`; @@ -976,13 +1023,7 @@ export function quickBarHtml(objectRef: string, tier: "needs-drew" | "needs-orch } function authorSelectHtml(identities: AuthorIdentity[]): string { - const options = identities - .map( - (i) => - ``, - ) - .join(""); - return `
`; + return `
`; } interface AFormSpec { diff --git a/pm-stack/aggregator/src/server.ts b/pm-stack/aggregator/src/server.ts index 8e00564e68..31aec37400 100644 --- a/pm-stack/aggregator/src/server.ts +++ b/pm-stack/aggregator/src/server.ts @@ -497,6 +497,14 @@ async function handler(req: Request): Promise { const prov = () => source.provenance(); const provDetail = () => source.provenanceDetail?.(); + // --- Author identities for the on-demand picker (#1179) ------------------ + // List pages render author pickers with the standing identities only; + // the full standing + per-session list is fetched once, on first use. + if (req.method === "GET" && path === "/api/author-identities") { + const records = await source.registry().catch(() => []); + return json({ identities: identitiesFromRecords(records) }); + } + // --- Dashboard comment writes (#906 §2) -------------------------------- if (req.method === "POST" && path === "/api/comments") { try { diff --git a/pm-stack/aggregator/test/author-picker-1179.test.ts b/pm-stack/aggregator/test/author-picker-1179.test.ts new file mode 100644 index 0000000000..bdfb49f697 --- /dev/null +++ b/pm-stack/aggregator/test/author-picker-1179.test.ts @@ -0,0 +1,133 @@ +import { afterAll, beforeAll, describe, expect, test } from "bun:test"; +import { spawn, type Subprocess } from "bun"; +import { mkdtemp } from "node:fs/promises"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { authorOptionsHtml, cardCommentHtml, commentFormHtml, statusRequestHtml } from "../src/render.ts"; +import { STANDING_IDENTITIES, type AuthorIdentity } from "../src/registry.ts"; +import { FIXTURE_REGISTRY } from "../src/sources/fixtures.ts"; + +// #1179: list pages were quadratic in the session-registry size -- +// every card's author picker inlined one '); + expect(html).toContain("Muse"); + expect(html).toContain("Orchestrator (orchestration-pass) (agent)"); + expect(html).not.toContain("ses_fake"); + expect(html.match(/