From 0dda96b2bf2a038780169660a53c0c2c8f423d46 Mon Sep 17 00:00:00 2001 From: Victor Velazquez Date: Tue, 24 Nov 2026 20:13:43 +0100 Subject: [PATCH 1/2] Rebuild the inspector and comments to the design, and keep them live Phase 33 slice D. The Quality tab leads with the score against the bar and a reason line, then the categories lowest first and the issues grouped as canvas_evaluate groups them for agents, each with a "Show n nodes" link. Design system and Feedback are restyled, and the Import placeholder is gone. Comment opens a popover under the button, and a click in the preview pins the note. The panels, comments and counts refresh while the page is open. --- VISION.md | 2 +- docs/specs/PHASE-33-SPEC.md | 8 + src/viewer/client/detail.ts | 212 +++++++------- src/viewer/feedback-key.ts | 13 + src/viewer/pages/detail.ts | 403 +++++++++++++------------- src/viewer/scores.ts | 14 - src/viewer/server.ts | 16 +- src/viewer/styles.ts | 6 +- test/browser/test-viewer-detail.ts | 4 +- test/browser/test-viewer-inspector.ts | 145 +++++++++ test/e2e/test-viewer-live-mcp.ts | 81 ++++++ test/unit/test-eval-cache-key.ts | 3 +- test/unit/test-viewer-panels.ts | 14 +- test/unit/test-viewer-quality.ts | 65 +++++ 14 files changed, 654 insertions(+), 332 deletions(-) create mode 100644 src/viewer/feedback-key.ts create mode 100644 test/browser/test-viewer-inspector.ts create mode 100644 test/e2e/test-viewer-live-mcp.ts create mode 100644 test/unit/test-viewer-quality.ts diff --git a/VISION.md b/VISION.md index 490ac55..88f7f87 100644 --- a/VISION.md +++ b/VISION.md @@ -602,7 +602,7 @@ Phase 31 rebuilt the viewer as canvases and left the code alone. A design pass o - [x] Slice A — foundation: `src/viewer/` modules, tokens copied from the design system and pinned by a test, chrome that follows the system's light or dark setting, fonts served from the cache, one sidebar, tabs, menu and dialog used everywhere - [x] Slice B — gallery: thumbnail cards with a score chip against the bar, search and type filter kept in the URL, a live status, and refresh on every edit - [x] Slice C — detail shell: toolbar with state tabs, a More menu (JSON, copy ID, archive, delete), a delete dialog, and preview tools (zoom, fit, preview theme, safe area) -- [ ] Slice D — inspector and comments: the Quality tab sorted lowest first with a reason line, Design system and Feedback restyled, the Import placeholder removed, the comment popover, and panels that refresh live +- [x] Slice D — inspector and comments: the Quality tab sorted lowest first with a reason line, Design system and Feedback restyled, the Import placeholder removed, the comment popover, and panels that refresh live - [ ] Slice E — archive, docs and acceptance: the archive tree with a preview panel, README and screenshots, and each screen beside its design - [ ] Follow-up — the viewer sends `Access-Control-Allow-Origin: *` on every response, the routes that archive, delete and post comments included. It listens on 127.0.0.1 only, but a page open in the same browser can still send it a simple cross-origin POST (archive, unarchive, add or resolve a comment) without a preflight. Drop the header from mutating routes, reject requests whose `Origin` is not the viewer's own, and test both; a separate change from the visual port diff --git a/docs/specs/PHASE-33-SPEC.md b/docs/specs/PHASE-33-SPEC.md index bef436b..a2baa48 100644 --- a/docs/specs/PHASE-33-SPEC.md +++ b/docs/specs/PHASE-33-SPEC.md @@ -149,6 +149,14 @@ Its design system is the project's: seed `#B45309`, personality `technical`, 14p **Slice D — inspector and comments.** The Quality tab (FR-D1), the restyled Design system and Feedback tabs and the removed Import tab (FR-D2), the comment popover (FR-D3), and the live inspector with its route and `feedbackKey` (FR-D4). Tests rewritten: `test-viewer-panels.ts` (inspector selectors), `test-viewer-feedback.ts` (`data-tab="feedback"`, `btn-comment`, `FB_INIT`), `test-eval-cache-key.ts:104` (it reads the provenance chip from the toolbar; the chip moves into the Quality tab). New: `test/browser/test-viewer-inspector.ts`, with an MCP-driven check of FR-D4 in `test/e2e/`. +**Slice D — as built.** +- **D1: the inspector is always there.** An empty canvas used to get no inspector; it now gets one whose Quality tab says it has no score yet, so the Feedback tab is reachable on an empty canvas too. +- **D2: `/canvas/:id/inspector` returns JSON**, `{ quality, design, nodeIndex }`: the two server-rendered panels and the node index. The Feedback list stays client-rendered from `/api/canvas/:id/feedback`, so comment text never passes through `innerHTML`. `feedbackKey` lives in `src/viewer/feedback-key.ts`, shared by the page, its script and `/meta`. +- **D3: the popover is the comment mode.** It is static markup under the Comment button; opening it turns comment mode on, a click in the preview fills its anchor chips without moving it, and Cancel, Escape or a save closes it and leaves comment mode. Deleting a comment confirms in the shared dialog. +- **D4: the critique row says when the rubric asked for revision** ("Vision critique 82/100 · needs revision"), as the old toolbar chip did. +- **D5: the 80/60 helpers are gone.** `gradeFor`, `scoreColor` and `sevColor` are deleted (slice B's B5). +- **D6: the end-to-end check pins the viewer port.** Left to itself the MCP server reuses any viewer on 3001–3020, which would be the user's own, so `test/e2e/test-viewer-live-mcp.ts` sets `FRAMESMITH_VIEWER_PORT` to a free port. + **Slice E — archive, docs, acceptance.** `pages/archive.ts` (FR-E1, FR-E2), docs and screenshots (FR-E3), and the side-by-side acceptance (FR-E4). Tests rewritten: `test-archive-view.ts` (archive page half). `test/manual/test-viewer.ts` and `test-viewer-navbar.ts` follow the new markup. New: `test/browser/test-viewer-archive.ts`. Tests that read data, not markup, are untouched: `test-viewer-perf.ts`, `test-dual-theme.ts`, `test-viewer-resolves-workspace-tokens.ts`, `test-skeleton.ts`, `test-viewer-repo-aggregation.ts`, `test-viewer-repo-lifecycle.ts`, `test-viewer-watch.ts`. Each slice PR states that `test-viewer-perf.ts` still holds its 4x-store bound, since the gallery now renders more per card. diff --git a/src/viewer/client/detail.ts b/src/viewer/client/detail.ts index 52452b7..ca6ee67 100644 --- a/src/viewer/client/detail.ts +++ b/src/viewer/client/detail.ts @@ -4,6 +4,7 @@ import type { Canvas } from '../../types.js'; import { listFeedback } from '../../feedback.js'; import { evalCacheKey } from '../scores.js'; import { buildNodeIndex, scriptJson } from '../shared.js'; +import { feedbackKey as feedbackKeyOf } from '../feedback-key.js'; import { LIGHT } from '../tokens.js'; import { COMPONENTS_JS, icon } from '../components.js'; @@ -26,7 +27,8 @@ export function detailScript(canvas: Canvas, w: number, h: number, surfaceType: // Phase 21 — point-and-tell: initial feedback entries + node labels for // the breadcrumb. Kept fresh client-side via GET /api/canvas/:id/feedback. const FB_INIT = ${scriptJson(listFeedback(canvas, { includeResolved: true }))}; - const NODE_INDEX = ${scriptJson(buildNodeIndex(canvas.root))}; + let NODE_INDEX = ${scriptJson(buildNodeIndex(canvas.root))}; + let feedbackKey = ${scriptJson(feedbackKeyOf(canvas))}; // Auto-refresh polling, and the Live / Offline status (FR-C1). const liveEl = document.getElementById('live'); @@ -50,8 +52,13 @@ export function detailScript(canvas: Canvas, w: number, h: number, surfaceType: lastModified = meta.lastModified; contentKey = meta.contentKey || contentKey; refreshFrames(); + refreshInspector(); if (!document.getElementById('json-panel').hidden) loadJson(); } + if (meta.feedbackKey && meta.feedbackKey !== feedbackKey) { + feedbackKey = meta.feedbackKey; + loadFeedback(); + } } catch { setLive(false); } @@ -281,13 +288,15 @@ export function detailScript(canvas: Canvas, w: number, h: number, surfaceType: const actions = document.createElement('div'); actions.className = 'fb-actions'; const resolveBtn = document.createElement('button'); - resolveBtn.className = 'fb-btn'; + resolveBtn.type = 'button'; + resolveBtn.className = 'btn btn--secondary'; resolveBtn.textContent = 'Resolve'; resolveBtn.onclick = (e) => { e.stopPropagation(); fbAction('/feedback/' + entry.id + '/resolve', 'POST'); }; const delBtn = document.createElement('button'); - delBtn.className = 'fb-btn fb-btn--danger'; + delBtn.type = 'button'; + delBtn.className = 'btn btn--ghost'; delBtn.textContent = 'Delete'; - delBtn.onclick = (e) => { e.stopPropagation(); if (confirm('Delete this comment?')) fbAction('/feedback/' + entry.id, 'DELETE'); }; + delBtn.onclick = async (e) => { e.stopPropagation(); if (await fsDialog.open('fb-delete-dialog')) fbAction('/feedback/' + entry.id, 'DELETE'); }; actions.appendChild(resolveBtn); actions.appendChild(delBtn); card.appendChild(actions); @@ -306,12 +315,15 @@ export function detailScript(canvas: Canvas, w: number, h: number, surfaceType: function renderFeedbackPane(entries) { const pane = document.getElementById('fb-pane'); - const badge = document.getElementById('fb-badge'); if (!pane) return; pane.replaceChildren(); const open = entries.filter((e) => !e.resolvedAt); const done = entries.filter((e) => e.resolvedAt); - if (badge) { badge.textContent = String(open.length); badge.hidden = open.length === 0; } + // The open count on the Feedback tab and the Comment button. + const tabCount = document.querySelector('#tab-feedback .tab-count'); + if (tabCount) tabCount.textContent = String(open.length); + const commentCount = document.getElementById('comment-count'); + if (commentCount) { commentCount.textContent = String(open.length); commentCount.hidden = open.length === 0; } if (!open.length && !done.length) { const empty = document.createElement('div'); empty.className = 'fb-empty'; @@ -381,7 +393,7 @@ export function detailScript(canvas: Canvas, w: number, h: number, surfaceType: if (!chain.includes(id)) chain.push(id); el = el.parentElement && el.parentElement.closest('[data-node-id]'); } - openPopover(chain, e); + openPopover(chain); } function hookFrame() { @@ -392,97 +404,71 @@ export function detailScript(canvas: Canvas, w: number, h: number, surfaceType: setFrameCommentAffordance(commentMode); } - function toggleComment() { - commentMode = !commentMode; - document.getElementById('btn-comment').classList.toggle('active', commentMode); - document.getElementById('btn-comment').setAttribute('aria-pressed', commentMode ? 'true' : 'false'); - if (!commentMode) closePopover(); + // FR-D3 — Comment opens the popover under the button and turns comment + // mode on; clicking an element in the preview pins the comment to it. + const pop = document.getElementById('comment-pop'); + const chipsEl = document.getElementById('fb-chips'); + const textEl = document.getElementById('comment-text'); + let popoverSelected = null; // nodeId, or null for the whole page + + function setCommentMode(on) { + commentMode = on; + const btn = document.getElementById('btn-comment'); + btn.classList.toggle('active', on); + btn.setAttribute('aria-pressed', on ? 'true' : 'false'); + btn.setAttribute('aria-expanded', on ? 'true' : 'false'); + pop.hidden = !on; + if (on) { textEl.focus(); } else { setAnchor([]); textEl.value = ''; } hookFrame(); } + function toggleComment() { setCommentMode(!commentMode); } + function closePopover() { if (commentMode) setCommentMode(false); } - let popoverEl = null; - let popoverSelected = null; // nodeId or null = whole page - - function closePopover() { - if (popoverEl) { popoverEl.remove(); popoverEl = null; } - highlightNode(null, false); - } - - function openPopover(chain, clickEvent) { - closePopover(); + /** Fill the anchor chips from a clicked element's chain (nearest first). */ + function setAnchor(chain) { + chipsEl.replaceChildren(); popoverSelected = chain.length ? chain[0] : null; - const pop = document.createElement('div'); - pop.className = 'fb-popover'; - const chips = document.createElement('div'); - chips.className = 'fb-chips'; - const allChips = []; + chipsEl.hidden = chain.length === 0; + highlightNode(popoverSelected, !!popoverSelected); + if (!chain.length) return; + const chips = []; const makeChip = (label, nodeId, title) => { - const chip = document.createElement('span'); + const chip = document.createElement('button'); + chip.type = 'button'; chip.className = 'fb-chip'; chip.textContent = label; - if (title) chip.title = title; + chip.title = title; + chip.setAttribute('aria-pressed', nodeId === popoverSelected ? 'true' : 'false'); chip.onclick = () => { popoverSelected = nodeId; - allChips.forEach((c) => c.classList.remove('sel')); - chip.classList.add('sel'); + chips.forEach((c) => c.setAttribute('aria-pressed', c === chip ? 'true' : 'false')); highlightNode(nodeId, !!nodeId); }; - allChips.push(chip); - chips.appendChild(chip); - return chip; + chips.push(chip); + chipsEl.appendChild(chip); }; - chain.slice(0, 5).forEach((nodeId) => makeChip(nodeLabel(nodeId), nodeId, 'Anchor the comment to this element')); - makeChip('whole page', null, 'A general note not tied to one element'); - const selIdx = chain.length ? 0 : allChips.length - 1; - allChips[selIdx].classList.add('sel'); - if (popoverSelected) highlightNode(popoverSelected, true); - pop.appendChild(chips); - const ta = document.createElement('textarea'); - ta.placeholder = 'Tell the agent what to change…'; - pop.appendChild(ta); - const actions = document.createElement('div'); - actions.className = 'fb-pop-actions'; - const cancel = document.createElement('button'); - cancel.className = 'fb-btn'; - cancel.textContent = 'Cancel'; - cancel.onclick = closePopover; - const save = document.createElement('button'); - save.className = 'fb-btn'; - save.textContent = 'Save comment'; - save.onclick = async () => { - const comment = ta.value.trim(); - if (!comment) { ta.focus(); return; } - try { - const res = await fetch('/api/canvas/' + canvasId + '/feedback', { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify(popoverSelected ? { nodeId: popoverSelected, comment } : { comment }), - }); - if (!res.ok) throw new Error('Request failed: ' + res.status); - closePopover(); - loadFeedback(); - const fbTab = document.querySelector('.insp-tab[data-tab="feedback"]'); - if (fbTab) fbTab.click(); - } catch (err) { alert('Could not save comment: ' + err.message); } - }; - actions.appendChild(cancel); - actions.appendChild(save); - pop.appendChild(actions); - document.body.appendChild(pop); - popoverEl = pop; - // Position near the click, mapping iframe coords → page coords (handles - // Fit-mode scaling); clamp so the popover stays on-screen. - const frame = document.getElementById('frame'); - const rect = frame.getBoundingClientRect(); - const win = frame.contentWindow; - const sx = win && win.innerWidth ? rect.width / win.innerWidth : 1; - const sy = win && win.innerHeight ? rect.height / win.innerHeight : 1; - const px = rect.left + clickEvent.clientX * sx; - const py = rect.top + clickEvent.clientY * sy; - pop.style.left = Math.max(8, Math.min(px, window.innerWidth - 316)) + 'px'; - pop.style.top = Math.max(60, Math.min(py + 8, window.innerHeight - pop.offsetHeight - 8)) + 'px'; - ta.focus(); + chain.slice(0, 5).forEach((nodeId) => makeChip(nodeLabel(nodeId), nodeId, 'Pin the comment to this element')); + makeChip('whole page', null, 'A note about the whole page'); } + function openPopover(chain) { if (!commentMode) setCommentMode(true); setAnchor(chain); textEl.focus(); } + + document.getElementById('comment-cancel').addEventListener('click', closePopover); + pop.addEventListener('keydown', (e) => { if (e.key === 'Escape') { e.preventDefault(); closePopover(); document.getElementById('btn-comment').focus(); } }); + document.getElementById('comment-save').addEventListener('click', async () => { + const comment = textEl.value.trim(); + if (!comment) { textEl.focus(); return; } + try { + const res = await fetch('/api/canvas/' + canvasId + '/feedback', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(popoverSelected ? { nodeId: popoverSelected, comment } : { comment }), + }); + if (!res.ok) throw new Error('Request failed: ' + res.status); + closePopover(); + loadFeedback(); + document.getElementById('tab-feedback').click(); + } catch (err) { alert('Could not save comment: ' + err.message); } + }); // An Escape the menu, dialog or JSON panel already handled keeps the draft. document.addEventListener('keydown', (e) => { if (e.key === 'Escape' && !e.defaultPrevented) closePopover(); }); @@ -493,7 +479,8 @@ export function detailScript(canvas: Canvas, w: number, h: number, surfaceType: // Phase 19 Slice A — click an issue to outline its node in the preview. // The render carries data-node-id on every element; iframes are same-origin // so we toggle an outline directly in their documents. - function highlightNode(nodeId, on) { + function highlightNode(nodeId, on) { highlightNodes(on && nodeId ? [nodeId] : []); } + function highlightNodes(nodeIds) { const frames = []; const main = document.getElementById('frame'); if (main && getComputedStyle(main).display !== 'none') frames.push(main); @@ -505,33 +492,42 @@ export function detailScript(canvas: Canvas, w: number, h: number, surfaceType: doc.querySelectorAll('[data-fs-hl]').forEach((n) => { n.style.outline = ''; n.style.outlineOffset = ''; n.removeAttribute('data-fs-hl'); }); - if (on && nodeId) { + let first = null; + for (const nodeId of nodeIds) { const t = doc.querySelector('[data-node-id="' + (window.CSS && CSS.escape ? CSS.escape(nodeId) : nodeId) + '"]'); - if (t) { - t.style.outline = '2px solid ' + HIGHLIGHT; t.style.outlineOffset = '1px'; - t.setAttribute('data-fs-hl', '1'); - t.scrollIntoView({ block: 'center', behavior: 'smooth' }); - } + if (!t) continue; + t.style.outline = '2px solid ' + HIGHLIGHT; t.style.outlineOffset = '1px'; + t.setAttribute('data-fs-hl', '1'); + first = first || t; } + if (first) first.scrollIntoView({ block: 'center', behavior: 'smooth' }); } } - document.querySelectorAll('.insp-issue[data-issue-node]').forEach((el) => { - el.addEventListener('click', () => { - const wasSel = el.classList.contains('sel'); - document.querySelectorAll('.insp-issue.sel').forEach((o) => o.classList.remove('sel')); - if (wasSel) { highlightNode(null, false); return; } - el.classList.add('sel'); - highlightNode(el.getAttribute('data-issue-node'), true); - }); + // FR-D1 — "Show n nodes" outlines an issue's nodes; delegated, so it works + // after a live swap of the Quality panel. + document.getElementById('inspector').addEventListener('click', (e) => { + const btn = e.target.closest && e.target.closest('.issue-nodes'); + if (!btn) return; + const on = btn.getAttribute('aria-pressed') !== 'true'; + document.querySelectorAll('.issue-nodes[aria-pressed="true"]').forEach((b) => b.setAttribute('aria-pressed', 'false')); + btn.setAttribute('aria-pressed', on ? 'true' : 'false'); + highlightNodes(on ? JSON.parse(btn.dataset.nodes) : []); }); - // Phase 19 Slice B — inspector tab switching (Quality / Design system). - document.querySelectorAll('.insp-tab[data-tab]').forEach((tab) => { - tab.addEventListener('click', () => { - const name = tab.getAttribute('data-tab'); - document.querySelectorAll('.insp-tab[data-tab]').forEach((t) => t.classList.toggle('active', t === tab)); - document.querySelectorAll('.insp-tabpane').forEach((p) => { p.hidden = p.getAttribute('data-pane') !== name; }); - }); - }); + // FR-D4 — swap the Quality and Design system panels (and the node index) + // when the canvas changes, keeping the scroll position. + async function refreshInspector() { + try { + const res = await fetch('/canvas/' + canvasId + '/inspector', { cache: 'no-store' }); + if (!res.ok) return; + const parts = await res.json(); + const inspector = document.getElementById('inspector'); + const top = inspector.scrollTop; + document.getElementById('insp-quality').innerHTML = parts.quality; + document.getElementById('insp-design').innerHTML = parts.design; + NODE_INDEX = parts.nodeIndex; + inspector.scrollTop = top; + } catch { /* the panels keep their last state */ } + } `; } diff --git a/src/viewer/feedback-key.ts b/src/viewer/feedback-key.ts new file mode 100644 index 0000000..2cd1c42 --- /dev/null +++ b/src/viewer/feedback-key.ts @@ -0,0 +1,13 @@ +// Phase 33 slice D (FR-D4) — a key for a canvas's comments that changes when +// one is added, resolved or deleted: the total, the open count and the latest +// of every entry's \`at\` and \`resolvedAt\`. /api/canvas/:id/meta carries it and +// the detail page reloads its Feedback list when it changes. +import type { Canvas } from '../types.js'; +import { listFeedback } from '../feedback.js'; + +export function feedbackKey(canvas: Canvas): string { + const entries = listFeedback(canvas, { includeResolved: true }); + const open = entries.filter((e) => !e.resolvedAt).length; + const latest = entries.reduce((max, e) => [e.at, e.resolvedAt ?? ''].reduce((m, t) => (t > m ? t : m), max), ''); + return `${entries.length}:${open}:${latest}`; +} diff --git a/src/viewer/pages/detail.ts b/src/viewer/pages/detail.ts index 093d514..0abbf50 100644 --- a/src/viewer/pages/detail.ts +++ b/src/viewer/pages/detail.ts @@ -3,31 +3,43 @@ import type { Canvas } from '../../types.js'; import { getProject, getCanvasTokens, getProjectDesignSystem, getWorkspaceDesignSystem } from '../../workspaces.js'; import { listCanvases } from '../../scene-graph.js'; import { resolveSurface, usableSafeArea, deviceProfile, windowProfile, WINDOW_PROFILES, DEFAULT_WINDOW, DEFAULT_DEVICE, type DeviceProfile } from '../../surfaces.js'; -import { resolveGenre, type EvaluationResult, type EvaluationIssue } from '../../evaluate.js'; +import { foldIssues, resolveGenre, type EvaluationResult, type EvaluationIssue } from '../../evaluate.js'; import { isPresetName } from '../../genre.js'; import { openFeedbackCount } from '../../feedback.js'; import { withoutRetiredSeeds } from '../../variables.js'; import { baseCss, COMPONENTS_CSS } from '../styles.js'; import { TYPE_LABELS } from './project.js'; -import { FAVICON_HTML, icon, renderDialog, renderMenu } from '../components.js'; -import { artboardSize, esc, PHONE } from '../shared.js'; -import { evalFor, gradeFor, scoreColor, sevColor } from '../scores.js'; +import { FAVICON_HTML, icon, renderDialog, renderMenu, renderTabs } from '../components.js'; +import { artboardSize, buildNodeIndex, esc, PHONE } from '../shared.js'; +import { evalFor } from '../scores.js'; import { detailScript } from '../client/detail.js'; -function renderIssueCard(issue: EvaluationIssue): string { - const label = issue.tell ? `${esc(issue.category)} · ${esc(issue.tell)}` : esc(issue.category); - const clickable = typeof issue.nodeId === 'string' && issue.nodeId.length > 0; - const fixTag = issue.fix - ? `⚡ auto-fixable` : ''; +/** The evaluator's quality bar: a score above 95 is at it (FR-B2, FR-D1). */ +const BAR = 96; + +const CATEGORY_LABELS: Record = { + spacing: 'Spacing', color: 'Color', typography: 'Typography', structure: 'Structure', + consistency: 'Consistency', usability: 'Usability', coverage: 'Coverage', cliche: 'Cliché', +}; +const categoryLabel = (name: string) => CATEGORY_LABELS[name] ?? name.charAt(0).toUpperCase() + name.slice(1); +const SEVERITY_RANK: Record = { error: 0, warning: 1 }; +const severityRank = (sev: string) => SEVERITY_RANK[sev] ?? 2; + +/** One folded issue as a ruled row (FR-D1): " · ", the + * message, and a link that outlines its nodes. The suggestion is the row's + * tooltip; the agent reads it from canvas_evaluate. */ +function renderIssueRow(issue: EvaluationIssue): string { + const fixable = !!issue.fix || (issue.fixes?.length ?? 0) > 0; + const kind = issue.tell ?? (fixable ? 'auto-fixable' : issue.severity); + const nodes = issue.nodeIds?.length ? issue.nodeIds : issue.nodeId ? [issue.nodeId] : []; + const show = nodes.length + ? `` + : ''; return ` -
-
- - ${label} - ${fixTag} -
-
${esc(issue.message)}
- ${issue.suggestion ? `
${esc(issue.suggestion)}
` : ''} +
+
${esc(categoryLabel(issue.category))} · ${esc(kind)}
+
${esc(issue.message)}
+ ${show}
`; } @@ -71,10 +83,7 @@ function renderDesignSystem(canvas: Canvas): string { if (m) for (const n of Object.keys(m)) allSources.push(sourceOf(cat, n)); } if (allSources.length === 0) { - return ` - `; + return '
This canvas inherits no design tokens. Set them with set_variables or bind a design system.
'; } const dominant = mostCommon(allSources); const defaultLabel = dominant === 'default' ? 'defaults' : `from ${dominant}`; @@ -153,59 +162,81 @@ function renderDesignSystem(canvas: Canvas): string {
` : ''; - return ` - `; + const body = `${colorSec}${typeSec}${spaceSec}${radiusSec}`; + return body.trim() ? body : '
This canvas inherits no design tokens.
'; } -function renderInspector(ev: EvaluationResult, canvas: Canvas): string { - const grade = gradeFor(ev.overallScore); - const fbOpen = openFeedbackCount(canvas); - const cats = ev.categories.map((c) => ` -
- ${esc(c.name)} - - ${c.score} -
`).join(''); - const issues = ev.issues.length - ? ev.issues.map(renderIssueCard).join('') - : `
No issues — this canvas is clean.
`; +/** The Quality tab (FR-D1): the score against the bar with a reason line, + * provenance and critique, the categories lowest first, then the folded + * issues, errors first. */ +export function renderQualityPanel(ev: EvaluationResult | null, canvas: Canvas): string { + if (!ev) return '
An empty canvas has no score yet.
'; + const below = ev.overallScore < BAR; + const folded = foldIssues(ev.issues); + const ordered = [...folded].sort((a, b) => severityRank(a.severity) - severityRank(b.severity)); + const cats = [...ev.categories].sort((a, b) => a.score - b.score); + const weakest = cats.find((c) => c.score < 100); + const blocker = weakest ? ordered.find((i) => i.category === weakest.name) : undefined; + const reason = weakest + ? `${categoryLabel(weakest.name)} holds it back${blocker ? `: ${blocker.message}` : '.'}` + : 'Every category is at 100.'; + + const prov = canvas.metadata?.provenance; + const genre = resolveGenre(canvas).genre; + const built = [prov?.structure, genre, prov?.preset && ('genre' in (prov ?? {}) || isPresetName(prov.preset)) ? prov.preset : undefined].filter(Boolean) as string[]; + const crit = canvas.metadata?.critique; + + const findings = folded.reduce((n, i) => n + (i.count ?? 1), 0); return ` - + ${renderDialog({ id: 'fb-delete-dialog', title: 'Delete this comment?', body: 'The comment is removed for everyone, your agent included.', confirmLabel: 'Delete comment', destructive: true })} ${renderDialog({ id: 'delete-dialog', title: `Delete ${canvas.name}?`, body: 'The canvas is deleted for good and cannot be restored. To hide it from the gallery and keep it, archive it instead.', confirmLabel: 'Delete canvas', destructive: true })}