From 6da60042e34d40d178d3e0a9a1ae336f82c3867c Mon Sep 17 00:00:00 2001 From: Byron Wall Date: Sun, 29 Nov 2026 00:03:37 -0500 Subject: [PATCH 1/4] feat(capabilities): weak tests first, hover cards, search and folder-level unclaimed code Co-Authored-By: Claude Opus 5.5 --- client/e2e/capabilities.spec.ts | 15 +- .../src/viz/capabilities/CapabilitiesView.tsx | 788 +++++++++++++----- client/src/viz/capabilities/model.ts | 64 +- 3 files changed, 632 insertions(+), 235 deletions(-) diff --git a/client/e2e/capabilities.spec.ts b/client/e2e/capabilities.spec.ts index c5d8e03a..610c3997 100644 --- a/client/e2e/capabilities.spec.ts +++ b/client/e2e/capabilities.spec.ts @@ -35,7 +35,7 @@ function makeRepo(withMap: boolean): string { const files: Record = { "src/editor.ts": Array.from({ length: 40 }, (_, i) => `export const e${i} = ${i};`).join("\n") + "\n", "src/editor.test.ts": `import { e1 } from "./editor";\ntest("saves", () => expect(e1).toBe(1));\n`, - "src/export.ts": Array.from({ length: 20 }, (_, i) => `export const x${i} = ${i};`).join("\n") + "\n", + "src/export.ts": Array.from({ length: 200 }, (_, i) => `export const x${i} = ${i};`).join("\n") + "\n", "src/legacy.ts": "export const old = 1;\n", }; if (withMap) files["docs/capabilities/notes.yaml"] = AREA; @@ -73,6 +73,19 @@ test("a repo with a map opens on its capabilities; one without keeps the treemap await expect(page).toHaveURL(/cap=note-export/); await page.screenshot({ path: path.join(SHOTS, "capabilities.png") }); + // The rail at rest ranks the weak capability first; the weak filter and search keep it lit. + await page.keyboard.press("Escape"); + await expect(page.locator("[data-cap-weakest]")).toContainText("Export a note"); + await page.locator('[data-cap-weak="none"]').click(); + await expect(page.locator('[data-capability="note-editor"]')).toHaveClass(/cap-dim/); + await expect(page.locator('[data-capability="note-export"]')).not.toHaveClass(/cap-dim/); + await page.locator('[data-cap-weak="none"]').click(); + await page.keyboard.press("/"); + await page.keyboard.type("editor.ts"); + await expect(page.locator('[data-capability="note-export"]')).toHaveClass(/cap-dim/); + await page.keyboard.press("Enter"); + await expect(page.locator('[data-cap-detail="note-editor"]')).toBeVisible(); + const plain = makeRepo(false); await page.goto(`/?${new URLSearchParams({ repo: plain })}`); await expect(page.locator('[data-view-option="treemap"]')).toHaveAttribute("aria-checked", "true", { timeout: 60_000 }); diff --git a/client/src/viz/capabilities/CapabilitiesView.tsx b/client/src/viz/capabilities/CapabilitiesView.tsx index 15b01fa0..6474f643 100644 --- a/client/src/viz/capabilities/CapabilitiesView.tsx +++ b/client/src/viz/capabilities/CapabilitiesView.tsx @@ -1,20 +1,30 @@ -import { For, Show, createMemo, createSignal, onCleanup, onMount } from "solid-js"; -import { ChevronRight, FileCode, FlaskConical } from "lucide-solid"; +import { For, Show, createMemo, createSignal, onCleanup, onMount, type JSX } from "solid-js"; +import { Portal } from "solid-js/web"; +import { ChevronRight, FlaskConical, Search, X } from "lucide-solid"; import { ViewTools } from "../viewToolbar"; -import { Button } from "../../components/ui/Button"; import { LEVEL_STYLE, - TEST_LEVELS, UNCLAIMED, + WEAK_LEVELS, + isWeak, layout, + matches, testLevel, + unclaimedGroups, + weakest, type CapMap, type CapNode, type CapRef, + type TestLevel, } from "./model"; const fmt = (n: number) => Math.round(n).toLocaleString("en-US"); -const LABEL_PX = 18; +const LABEL_PX = 22; +/** Below this view width the rail leaves the layout and opens over the map. */ +const NARROW_PX = 980; +const HOVER_OPEN_MS = 420; +/** The scale end of the small test bars: 50 linked test lines per 100 LOC fills one. */ +const BAR_FULL = 50; function readParam(name: string): string | null { return new URLSearchParams(window.location.search).get(name); @@ -28,19 +38,42 @@ function writeParam(name: string, value: string | null) { window.history.replaceState(window.history.state, "", `${window.location.pathname}?${params}${window.location.hash}`); } +const folderOfUnclaimed = (id: string) => (id.startsWith(`${UNCLAIMED}:`) ? id.slice(UNCLAIMED.length + 1) : null); + +function splitPath(path: string): [string, string] { + const i = path.lastIndexOf("/"); + return i < 0 ? ["", path] : [path.slice(0, i + 1), path.slice(i + 1)]; +} + +/** How a node's tests read in one line. */ +function testsLine(n: CapNode): string { + const level = testLevel(n); + if (level === "group") return "No code of its own"; + if (level === "none") return n.tests.linked ? "Its linked tests do not resolve" : "No linked test"; + return `${n.tests.lines_per_100_loc} test lines per 100 LOC`; +} + /** - * The snapshot view of a repo's capabilities map: each product area is a box of its - * capabilities, sized by allocated LOC and colored by how much test code each links. A click - * selects a capability and the rail shows its promise, files and tests; an area's label zooms in. + * The snapshot view of a repo's capabilities map. Each product area is a box of its capabilities, + * sized by allocated LOC. Only weak tests get color, so they stand out at a glance. Hover a + * capability for its promise; click it for its files and tests in the rail. An area's label zooms in. */ export default function CapabilitiesView(props: { map: CapMap | undefined; onOpenAt: (at: string, line?: number) => void; }) { - let box: HTMLDivElement | undefined; + let canvas: HTMLDivElement | undefined; + let root: HTMLDivElement | undefined; + let searchInput: HTMLInputElement | undefined; const [size, setSize] = createSignal({ w: 0, h: 0 }); + const [viewWidth, setViewWidth] = createSignal(1600); const [zoom, setZoomSignal] = createSignal(readParam("capzoom")); const [selected, setSelectedSignal] = createSignal(readParam("cap")); + const [query, setQuery] = createSignal(""); + const [weakOnly, setWeakOnly] = createSignal<"thin" | "none" | null>(null); + const [hover, setHover] = createSignal<{ id: string; rect: DOMRect } | null>(null); + let hoverTimer: number | undefined; + const setZoom = (id: string | null) => { setZoomSignal(id); writeParam("capzoom", id); @@ -48,13 +81,36 @@ export default function CapabilitiesView(props: { const select = (id: string | null) => { setSelectedSignal(id); writeParam("cap", id); + setHover(null); }; onMount(() => { - if (!box) return; - const ro = new ResizeObserver(([e]) => e && setSize({ w: e.contentRect.width, h: e.contentRect.height })); - ro.observe(box); - onCleanup(() => ro.disconnect()); + const ro = new ResizeObserver(() => { + if (canvas) setSize({ w: canvas.clientWidth, h: canvas.clientHeight }); + if (root) setViewWidth(root.clientWidth); + }); + if (canvas) ro.observe(canvas); + if (root) ro.observe(root); + const onKey = (e: KeyboardEvent) => { + const typing = e.target instanceof HTMLElement && e.target.closest("input, textarea, [contenteditable]"); + if (e.key === "/" && !typing) { + e.preventDefault(); + searchInput?.focus(); + } else if (e.key === "Escape") { + if (query()) setQuery(""); + else if (weakOnly()) setWeakOnly(null); + else if (selected()) select(null); + else if (zoom()) setZoom(null); + else return; + if (typing) (e.target as HTMLElement).blur(); + } + }; + window.addEventListener("keydown", onKey); + onCleanup(() => { + ro.disconnect(); + window.removeEventListener("keydown", onKey); + window.clearTimeout(hoverTimer); + }); }); const byId = createMemo(() => new Map((props.map?.nodes ?? []).map((n) => [n.id, n]))); @@ -68,6 +124,7 @@ export default function CapabilitiesView(props: { if (!m || m.status !== "checked" || w < 10 || h < 10) return null; return layout(m, focus(), w, h, LABEL_PX); }); + const narrow = () => viewWidth() < NARROW_PX; const current = (): CapNode | null => { const id = selected(); return (id && byId().get(id)) || null; @@ -77,46 +134,104 @@ export default function CapabilitiesView(props: { for (let n = id ? byId().get(id) : undefined; n; n = n.parent ? byId().get(n.parent) : undefined) out.unshift(n); return out; }; - const weak = createMemo(() => (props.map?.nodes ?? []).filter((n) => ["thin", "none"].includes(testLevel(n))).length); + const weakCounts = createMemo(() => { + const out = { thin: 0, none: 0 }; + for (const n of props.map?.nodes ?? []) { + const l = testLevel(n); + if (l === "thin" || l === "none") out[l]++; + } + return out; + }); + /** Weak descendants (and the node itself) under an area, for its header. */ + const weakUnder = (id: string): number => { + const n = byId().get(id); + if (!n) return 0; + return (isWeak(testLevel(n)) ? 1 : 0) + n.children.reduce((s, c) => s + weakUnder(c), 0); + }; + /** A tile is lit when it matches the search and the weak-tests filter; others fade back. */ + const lit = (id: string): boolean => { + const n = byId().get(id); + if (!n) return !query() && !weakOnly(); + if (weakOnly() && testLevel(n) !== weakOnly()) return false; + return matches(n, query()); + }; + const filtering = () => !!query().trim() || !!weakOnly(); + const matchCount = createMemo(() => (filtering() ? (props.map?.nodes ?? []).filter((n) => lit(n.id) && n.loc.direct > 0).length : 0)); const errors = () => (props.map?.diagnostics ?? []).filter((d) => d.severity === "error"); + const hoverIn = (id: string, el: HTMLElement, now = false) => { + window.clearTimeout(hoverTimer); + const open = () => setHover({ id, rect: el.getBoundingClientRect() }); + if (now || hover()) open(); + else hoverTimer = window.setTimeout(open, HOVER_OPEN_MS); + }; + const hoverOut = () => { + window.clearTimeout(hoverTimer); + hoverTimer = window.setTimeout(() => setHover(null), 120); + }; + + const railOpen = () => !narrow() || selected() !== null; + return ( -
+
+ -
- + {(n) => ( <> - -
- - {(loc) => ( - - {props.map!.nodes.length} capabilities · {loc().claimed_pct}% of code claimed · {weak()} with thin or no tests - - )} - -
- Tests / 100 LOC - + + +
+ {(l) => ( - - +