diff --git a/pm-stack/aggregator/src/pages.ts b/pm-stack/aggregator/src/pages.ts index 9d95d5c4b2..68c8265dfc 100644 --- a/pm-stack/aggregator/src/pages.ts +++ b/pm-stack/aggregator/src/pages.ts @@ -146,6 +146,15 @@ export const PAGES: PageDef[] = [ group: "work", nav: "dropdown", }, + { + id: "search", + title: "Search", + route: "/search", + api: "/api/search.json", + blurb: "Search board and roadmap work by title or linked issue/PR ref.", + group: "work", + nav: "dropdown", + }, { id: "events", title: "Events", diff --git a/pm-stack/aggregator/src/render.ts b/pm-stack/aggregator/src/render.ts index 57756d7041..91b45a2f7b 100644 --- a/pm-stack/aggregator/src/render.ts +++ b/pm-stack/aggregator/src/render.ts @@ -108,6 +108,7 @@ import { buildEpicRollups, isEpicChildDone, type EpicRollup } from "./epics.ts"; import { effortWeight, handsLine, summarizeWeights, weightedLine } from "./weights.ts"; import { blockedSummary, depthLayout, hasGraphEdges } from "./graph.ts"; import { type AuthorIdentity } from "./registry.ts"; +import type { SearchResult } from "./search-view.ts"; export function esc(s: unknown): string { return String(s ?? "") @@ -134,6 +135,11 @@ const CSS = ` body { margin: 0; font: 14px/1.45 system-ui, -apple-system, sans-serif; background: #0e1117; color: #e6edf3; } [id] { scroll-margin-top: 96px; } nav { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 12px; padding: 8px 16px; border-bottom: 1px solid #30363d; background: #161b22; position: sticky; top: 0; } +.navsearch { display: flex; align-items: center; gap: 4px; margin-left: auto; } +.navsearch input, .search-page-form input { min-width: 12rem; padding: 7px 9px; border: 1px solid #30363d; border-radius: 6px; background: #0d1117; color: inherit; } +.navsearch button, .search-page-form button { padding: 7px 10px; border: 1px solid #30363d; border-radius: 6px; background: #21262d; color: inherit; cursor: pointer; } +.search-page-form { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin: 16px 0; } +.search-page-form input { flex: 1; } .navgroup { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; } .navgroup + .navgroup { border-left: 1px solid #30363d; padding-left: 12px; } .navlabel { color: #8b949e; font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; margin-right: 4px; } @@ -756,6 +762,10 @@ export function pageDropdown(active: string): string { return ``; } +function globalSearch(): string { + return ``; +} + function layout( title: string, body: string, @@ -775,11 +785,43 @@ function layout( return ` ${esc(title)} · aggregator -
${chipsHtml}${body} +
${chipsHtml}${body}
source detailboard: ${esc(provenance.board)} · roadmap: ${esc(provenance.roadmap)} · items: ${esc(provenance.items)} · comments: ${esc(provenance.comments)} · quota: ${esc(provenance.quota)} · usage: ${esc(provenance.usage)} · attention: ${esc(provenance.attention)} · orchestration: ${esc(provenance.orchestration)} · dns: ${esc(provenance.dns)} · registry: ${esc(provenance.registry)} · aa: ${esc(provenance.aa)}
${KEY_HINT} · tailnet: ${TAILNET_URL.replace("http://", "")}
${extra}${paletteHtml()}${KEYBOARD_SCRIPT}`; } +/** First-slice global search over board/roadmap subjects and linked refs. */ +export function renderSearch( + query: string, + results: SearchResult[], + items: Map, + provenance: Provenance, + detail?: ProvenanceDetail, +): string { + const cards = results + .map((result) => { + const badges = result.refs + .map((ref) => { + const item = items.get(ref); + return item + ? itemBadge(item) + : `${esc(ref)} · unresolved`; + }) + .join(" "); + return `
${esc(result.title)}
${result.kind} · ${esc(result.summary)}${badges ? `
${badges}
` : ""}
`; + }) + .join(""); + const body = `

Search

Search board items and roadmap rows by subject, title, or linked issue/PR ref. Linked GitHub badges show their current projected state and whether the result is fixture-only.

${query ? `

${results.length} result${results.length === 1 ? "" : "s"} for “${esc(query)}”

${cards || '

No matching work found.

'}` : '

Enter a title or issue/PR reference to search.

'}`; + return layout( + "Search", + body, + provenance, + "/search", + "", + detail ? freshnessChips(detail, ["board", "roadmap", "items"]) : "", + ); +} + // --- Dashboard comments (#906 §2) ------------------------------------------ /** Object refs: the keys dashboard comment threads hang on. */ diff --git a/pm-stack/aggregator/src/search-view.ts b/pm-stack/aggregator/src/search-view.ts new file mode 100644 index 0000000000..a2acef8ba8 --- /dev/null +++ b/pm-stack/aggregator/src/search-view.ts @@ -0,0 +1,67 @@ +import type { BoardItem, GhItem, RefKey, RoadmapRow } from "./model.ts"; + +export interface SearchResult { + kind: "board" | "roadmap"; + id: string; + title: string; + summary: string; + refs: RefKey[]; +} + +function includesQuery(query: string, values: (string | undefined)[]): boolean { + return values.some((value) => value?.toLowerCase().includes(query)); +} + +/** Search the first-slice canonical subjects and their projected GitHub refs. */ +export function searchWork( + board: BoardItem[], + rows: RoadmapRow[], + items: Map, + rawQuery: string, +): SearchResult[] { + const query = rawQuery.trim().toLowerCase(); + if (!query) return []; + + const results: SearchResult[] = []; + for (const item of board) { + const refs = item.links.map((link) => link.ref); + const projectedTitles = refs.map((ref) => items.get(ref)?.title); + if (includesQuery(query, [item.id, item.title, item.repo, item.status, item.source, ...refs, ...projectedTitles])) { + results.push({ + kind: "board", + id: item.id, + title: item.title, + summary: `${item.repo} · ${item.status}`, + refs, + }); + } + } + + for (const row of rows) { + const refs = row.links.map((link) => link.ref); + const projectedTitles = refs.map((ref) => items.get(ref)?.title); + if ( + includesQuery(query, [ + row.subject, + row.title, + row.area, + row.status, + row.horizon, + row.source, + row.notes, + ...refs, + ...projectedTitles, + ]) + ) { + results.push({ + kind: "roadmap", + id: row.subject, + title: row.title, + summary: `${row.area} · ${row.status} · ${row.horizon}`, + refs, + }); + } + } + + return results; +} diff --git a/pm-stack/aggregator/src/server.ts b/pm-stack/aggregator/src/server.ts index e243c0556e..5f8c651610 100644 --- a/pm-stack/aggregator/src/server.ts +++ b/pm-stack/aggregator/src/server.ts @@ -90,6 +90,7 @@ import { renderQueueShell, buildRoadmapDrill, renderRoadmap, + renderSearch, renderServiceDetail, renderSessions, renderToday, @@ -113,6 +114,7 @@ import { SW_SOURCE } from "./sw-source.ts"; import { renderAlerts, esc } from "./render.ts"; import { readJsonBody } from "./request-body.ts"; import { parseRegistryQuery, queryRegistry } from "./registry-view.ts"; +import { searchWork } from "./search-view.ts"; import type { Source } from "./source.ts"; import { fixtureSource } from "./sources/fixtures.ts"; import { liveSource } from "./sources/live.ts"; @@ -432,6 +434,13 @@ async function roadmapContext() { return { rows, items, pool: poolResult.pool, reconciliation, drill }; } +async function searchContext(query: string) { + const [board, rows] = await Promise.all([source.board(), source.roadmap()]); + const refs = [...new Set([...allRefs(board), ...allRefs(rows)])]; + const items = await source.items(refs); + return { query, results: searchWork(board, rows, items, query), items }; +} + // #1148: the watchdog derives NEEDS ORCHESTRATOR items from the // current diagnoses (feed age + probes via the health assembly — // its probe cache keeps this cheap — plus the orchestration @@ -1320,6 +1329,14 @@ async function handler(req: Request): Promise { ), ); } + if (path === "/search") { + const { query, results, items } = await searchContext(url.searchParams.get("q") ?? ""); + return html(renderSearch(query, results, items, prov(), provDetail())); + } + if (path === "/api/search.json") { + const { query, results } = await searchContext(url.searchParams.get("q") ?? ""); + return json({ query: query.trim(), total: results.length, results }); + } if (path === "/api/registry.json") { const records = await source.registry(); // #1209: same query pipeline as /sessions — same params, same page. diff --git a/pm-stack/aggregator/test/curation-1497.test.ts b/pm-stack/aggregator/test/curation-1497.test.ts index 493aefaa69..4b679f03a4 100644 --- a/pm-stack/aggregator/test/curation-1497.test.ts +++ b/pm-stack/aggregator/test/curation-1497.test.ts @@ -28,6 +28,7 @@ const DECISIONS: Record = { attention: "primary", board: "dropdown", roadmap: "primary", + search: "dropdown", quota: "primary", dns: "dropdown", "aa-explorer": "dropdown", diff --git a/pm-stack/aggregator/test/search-view.test.ts b/pm-stack/aggregator/test/search-view.test.ts new file mode 100644 index 0000000000..2b13a74f92 --- /dev/null +++ b/pm-stack/aggregator/test/search-view.test.ts @@ -0,0 +1,89 @@ +import { describe, expect, test } from "bun:test"; +import type { BoardItem, GhItem, Provenance, ProvenanceDetail, RefKey, RoadmapRow } from "../src/model.ts"; +import { renderSearch } from "../src/render.ts"; +import { searchWork } from "../src/search-view.ts"; + +const ref = "developing-today/code#1212" as RefKey; +const board: BoardItem[] = [ + { + id: "kaneo:pm-stack/task-1", + title: "Ship dashboard search", + repo: "developing-today/code", + source: "kaneo", + status: "in-progress", + links: [{ ref, relation: "implements" }], + }, +]; +const rows: RoadmapRow[] = [ + { + id: 4, + subject: "grist:program/roadmap/7", + title: "Aggregator findability", + area: "Work", + status: "In Progress", + horizon: "November 2026", + source: "Grist", + notes: "Search across tracked issues", + links: [{ ref, relation: "tracks" }], + }, +]; +const projected = new Map([ + [ + ref, + { + ref, + kind: "issue", + url: "https://github.com/developing-today/code/issues/1212", + title: "Add global search", + state: "open", + labels: [], + author: "octocat", + updatedAt: "2026-11-01T00:00:00Z", + resolution: "projector", + }, + ], +]); +const provenance = { + board: "live", + roadmap: "live", + items: "live", + comments: "live", + quota: "live", + usage: "live", + attention: "live", + orchestration: "live", + dns: "live", + registry: "live", + aa: "live", +} as Provenance; +const detail = Object.fromEntries( + Object.entries(provenance).map(([key, text]) => [key, { text, state: "live" }]), +) as ProvenanceDetail; + +describe("global search first slice", () => { + test("finds canonical work by linked ref and projected GitHub title", () => { + expect(searchWork(board, rows, projected, "developing-today/code#1212").map((r) => r.kind)).toEqual([ + "board", + "roadmap", + ]); + expect(searchWork(board, rows, projected, "Add global search").map((r) => r.title)).toEqual([ + "Ship dashboard search", + "Aggregator findability", + ]); + }); + + test("returns an empty result for an unknown or blank query", () => { + expect(searchWork(board, rows, projected, "nothing matches")).toEqual([]); + expect(searchWork(board, rows, projected, " ")).toEqual([]); + }); + + test("renders linked item state, global search, and freshness chips", () => { + const results = searchWork(board, rows, projected, "1212"); + const html = renderSearch("1212", results, projected, provenance, detail); + expect(html).toContain('action="/search"'); + expect(html).toContain("Search board and roadmap work"); + expect(html).toContain("Add global search"); + expect(html).toContain("developing-today/code#1212"); + expect(html).toContain("items · live"); + }); +}); diff --git a/pm-stack/aggregator/test/slice3.test.ts b/pm-stack/aggregator/test/slice3.test.ts index ba23692098..fc9214f6c9 100644 --- a/pm-stack/aggregator/test/slice3.test.ts +++ b/pm-stack/aggregator/test/slice3.test.ts @@ -735,6 +735,23 @@ afterAll(() => { }); describe("slice-3 routes", () => { + test("global search HTML and JSON share ref/title matching", async () => { + const q = encodeURIComponent("developing-today/code#902"); + const data = (await (await fetch(`http://127.0.0.1:${port}/api/search.json?q=${q}`)).json()) as { + query: string; + total: number; + results: { title: string; refs: string[] }[]; + }; + expect(data.query).toBe("developing-today/code#902"); + expect(data.total).toBeGreaterThan(0); + expect(data.results.some((result) => result.refs.includes("developing-today/code#902"))).toBe(true); + + const html = await (await fetch(`http://127.0.0.1:${port}/search?q=${q}`)).text(); + expect(html).toContain("Search board and roadmap work"); + expect(html).toContain("developing-today/code#902"); + expect(html).toContain("items · fixtures"); + }); + test("dns + sessions + pages routes serve", async () => { const dns = await (await fetch(`http://127.0.0.1:${port}/dns`)).text(); expect(dns).toContain("DNS / domain register");