// Spike web UI: pipeline list + run detail over the live WebSocket protocol. // Deliberately small and DOM-only (no framework, no build step). Every value // that came from the server is set with textContent, never innerHTML. import { PipelinesClient } from "./client.js"; import { PipelinesRepository } from "./repository.js"; import { validateServerUrl, resolveArtifactUrl } from "./serverUrl.js"; import { ArtifactKind, artifactCaptureNotes, artifactGroups, artifactKind, artifactKindLabel, artifactsHeader, artifactsSummary, artifactViewerPositionLabel, displayVisit, humanBytes, pagedArtifacts, pagedIndex, presentedArtifacts, resolvedArtifactUrl, sessionExportArtifact, viewerIndexByUrl, } from "./artifacts.js"; import { PIPELINE_GRAPH_EMPTY, mount as mountGraph, } from "./graph.js"; import { PIPELINE_SORTS, PIPELINE_DETAIL_TABS, RUN_PRESENCES, RUN_STATUS_FILTERS, EMPTY_PIPELINE_FILTERS, filterPipelines, graphNote, latestRunByPipeline, pipelineFilterCount, pipelineListEmptyState, pipelineSubtitle, pipelineUpdatedLine, runBadge, runBadgeMetaLine, sortPipelines, summaryFields, versionRow, } from "./pipelines.js"; import { RUN_STATES, RUN_TIME_RANGES, RUN_SORTS, DEFAULT_RUN_SORT, runStateOf, runIdentity, versionLabel, progressText, metaText, formatDuration, localDayKey, filterRuns, groupRunsByDay, runComparator, pipelineFilterOptions, runListEntries, defaultRunFilters, runFiltersActiveCount, } from "./runs.js"; import { effectiveStageType, templateCard, templateDetailName, templateGalleryName, templateGraphNote, templateStageCountLabel, templateStageSummary, TEMPLATE_UNPARSED_SOURCE_NOTE, } from "./templates.js"; import { RENDERED_RUN_TABS, EMPTY_INPUT_MESSAGE, EMPTY_OUTPUT_MESSAGE, EMPTY_TIMELINE_MESSAGE, NO_STAGE_DETAILS_MESSAGE, fieldSections, summaryRows, runIdentityLine, runLabelFor, runDurationText, runTimeline, nodeLabel, headlineFields, runStepFields, stageSectionSpecs, clampVisitIndex, referencedVerdictArtifacts, verdictReasonSegments, outcomeColorToken, stateGlyph, } from "./runDetail.js"; const STORAGE_KEY = "pipelines.web.serverUrl.v2"; /** Shown where tiles exist but the configured server URL cannot resolve them. */ const ARTIFACT_SERVER_HINT = "Set the server URL in Settings to open or copy artifact links."; /** * The page is normally served by serve.mjs, which also proxies /connect to the * Pipelines server. Defaulting to this page's own origin therefore points at * that proxy and keeps the page and the WebSocket same-origin — the server * rejects a cross-origin upgrade with 403. Nothing is hardcoded: the value is * derived from wherever the page was loaded, and the user can override it. */ function defaultServerUrl() { if (typeof location === "undefined" || !location.host) return ""; const scheme = location.protocol === "https:" ? "wss" : "ws"; return `${scheme}://${location.host}/connect`; } const client = new PipelinesClient(); const repo = new PipelinesRepository(client); const state = { view: "pipelines", url: localStorage.getItem(STORAGE_KEY) ?? defaultServerUrl(), connection: client.state, pipelines: [], runs: [], usage: null, pipelineDetail: null, runDetail: null, selectedPipelineId: null, selectedRunId: null, // Pipelines view: client-side filter/sort/detail-tab state. The run history is // fetched alongside the pipelines so the list can show each pipeline's last // run; runsLoaded tells a genuinely empty history apart from one not in hand. pipelineFilters: { ...EMPTY_PIPELINE_FILTERS }, pipelineSort: "server_order", pipelineMenu: null, pipelineTab: "summary", // The mounted workflow graph (P6) and whether its panel is expanded. The // handle is dropped on every re-render so its listeners can never leak. pipelineGraph: null, pipelineGraphExpanded: false, versionsExpanded: false, pipelinesLoaded: false, runsLoaded: false, templates: [], templateLoading: false, // key -> graph|null: the parsed definition, cached once per template key. A // failed/absent validate stores null so the card/detail say "unavailable". templateGraphs: new Map(), selectedTemplateKey: null, templateTab: "summary", loading: false, error: "", runFilters: defaultRunFilters(), runSort: DEFAULT_RUN_SORT, openMenu: null, // Run detail: the selected tab (Summary by default) and the per-run // expand/collapse choices for the input/output field sections and the summary // artifacts section. The stage pane is the timeline's per-visit panel; its // section expansion is reseeded each time a pane is opened. runTab: "summary", runSections: new Set(), runStagePane: null, runStageSections: new Set(), }; let runPoll = null; // One shared live clock for the runs list: it ticks only while a shown run is // executing, and each running row reads its elapsed from it rather than starting // a timer of its own. Elapsed is derived from the server's start timestamp, so // it stays correct after a reconnect; a finished history never ticks. let listClock = null; let listNow = Date.now(); // The run detail's own live clock: it ticks only while the shown run is // executing, updating just the Duration row in place (never a full re-render, so // an open stage pane is not torn down), exactly as the runs list does. let detailClock = null; let detailNow = Date.now(); // --------------------------------------------------------------------------- // DOM helpers // --------------------------------------------------------------------------- function h(tag, props = {}, ...children) { const node = document.createElement(tag); for (const [key, value] of Object.entries(props)) { if (value == null || value === false) continue; if (key === "class") node.className = value; else if (key === "text") node.textContent = value; else if (key.startsWith("on") && typeof value === "function") { node.addEventListener(key.slice(2).toLowerCase(), value); } else node.setAttribute(key, value === true ? "" : String(value)); } for (const child of children.flat()) { if (child == null || child === false) continue; node.append(child instanceof Node ? child : document.createTextNode(String(child))); } return node; } function isExecuting(run) { return Boolean(run && run.executing); } // --------------------------------------------------------------------------- // Rendering // --------------------------------------------------------------------------- const header = h("header", { class: "topbar" }); const content = h("main", { id: "content" }); document.body.append(header, content); function renderHeader() { header.replaceChildren( h("div", { class: "brand" }, h("strong", { text: "Pipelines" }), h("span", { class: "muted", text: "web spike" })), h( "div", { class: "connbar" }, h("input", { id: "url", type: "text", placeholder: "ws://HOST:PORT/connect", value: state.url, spellcheck: "false", oninput: (e) => { state.url = e.target.value; }, }), h("button", { id: "connectBtn", text: state.connection.kind === "connected" ? "Disconnect" : "Connect", onclick: onConnectClicked, }), h("span", { class: "state", id: "stateBadge" }, connectionLabel()), ), ); } function connectionLabel() { const c = state.connection; switch (c.kind) { case "connected": return h("span", { class: "dot ok" }, "connected"); case "connecting": return h("span", { class: "dot warn" }, `connecting… (attempt ${c.attempt})`); case "disconnected": return h("span", { class: "dot bad" }, `disconnected${c.reason ? ` — ${c.reason}` : ""}${c.retrying ? " (retrying)" : ""}`); default: return h("span", { class: "dot idle" }, "idle"); } } function render() { renderHeader(); renderContent(); } function renderContent() { // The graph owns wheel/pointer/resize listeners; drop the previous mount // before rebuilding the DOM so a re-render, tab switch or view switch never // leaves an observer or listener behind. if (state.pipelineGraph) { state.pipelineGraph.unmount(); state.pipelineGraph = null; } const nodes = []; if (state.error) { nodes.push(h("div", { class: "banner error" }, h("strong", { text: "Error: " }), state.error)); } nodes.push( h( "nav", { class: "tabs" }, tabButton("pipelines", `Pipelines (${state.pipelines.length})`), tabButton("runs", `Runs (${state.runs.length})`), tabButton("templates", "Templates"), h("span", { class: "spacer" }), h("button", { class: "ghost", text: "Refresh", onclick: () => loadCurrentView(true) }), ), ); const split = h("div", { class: "split" }); if (state.view === "pipelines") { split.append(renderPipelineList(), renderPipelineDetail()); } else if (state.view === "runs") { split.append(renderRunList(), renderRunDetail()); } else { split.append(renderTemplateGallery(), renderTemplateDetail()); } nodes.push(split); content.replaceChildren(...nodes); if (state.view === "runs") { refreshListClock(); refreshDetailClock(); } else { stopListClock(); stopDetailClock(); } } function tabButton(view, label) { return h("button", { class: `tab${state.view === view ? " active" : ""}`, text: label, onclick: () => { state.view = view; state.error = ""; renderContent(); if (view === "runs" && !state.runs.length) loadCurrentView(); if (view === "pipelines" && !state.pipelines.length) loadCurrentView(); if (view === "templates" && !state.templates.length) loadCurrentView(); }, }); } function renderPipelineList() { const list = h("div", { class: "list" }); list.append(renderPipelineControls()); const rows = h("div", { id: "pipelineRows" }); fillPipelineRows(rows); list.append(rows); return list; } /** * The list's filter + sort toolbar and (when open) the matching menu panel. The * rows themselves live in the separate `#pipelineRows` container so a keystroke * in the name filter can refresh just the rows without rebuilding (and so * blurring) the input the operator is typing in. */ function renderPipelineControls() { const filters = state.pipelineFilters; const count = pipelineFilterCount(filters); const panel = state.pipelineMenu; const controls = h( "div", { class: "list-controls" }, h( "div", { class: "list-toolbar" }, h( "button", { id: "filterToggle", class: `control${panel === "filter" ? " active" : ""}`, onclick: () => { state.pipelineMenu = panel === "filter" ? null : "filter"; renderContent(); }, }, h("span", { text: "Filter" }), h("span", { id: "filterCount", class: "count", text: count ? ` (${count})` : "" }), ), h("button", { id: "sortToggle", class: `control${panel === "sort" ? " active" : ""}`, text: `Sort: ${pipelineSortLabel(state.pipelineSort)}`, onclick: () => { state.pipelineMenu = panel === "sort" ? null : "sort"; renderContent(); }, }), h("button", { id: "clearFilters", class: "ghost clear", text: "Clear filters", hidden: count === 0, onclick: clearPipelineFilters, }), ), ); if (panel === "filter") controls.append(renderFilterPanel()); if (panel === "sort") controls.append(renderSortPanel()); return controls; } function renderFilterPanel() { const filters = state.pipelineFilters; const panel = h("div", { class: "menu-panel filter-panel" }); panel.append(h("div", { class: "filter-section", text: "Name" })); panel.append( h( "label", { class: "filter-field" }, h("span", { class: "filter-field-label", text: "Pipeline name contains" }), h("input", { id: "pipelineNameFilter", type: "text", value: filters.name, spellcheck: "false", oninput: (e) => { state.pipelineFilters = { ...state.pipelineFilters, name: e.target.value }; // Targeted refresh: the input keeps focus and its value while the // list narrows behind it. refreshPipelineRows(); }, }), ), ); panel.append(h("div", { class: "filter-section", text: "Runs" })); for (const presence of RUN_PRESENCES) { panel.append( h( "label", { class: "filter-item" }, h("input", { type: "radio", name: "runPresence", checked: filters.presence === presence.key, onchange: () => { state.pipelineFilters = { ...state.pipelineFilters, presence: presence.key }; renderContent(); }, }), h("span", { text: presence.label }), ), ); } panel.append(h("div", { class: "filter-section", text: "Last run status" })); for (const status of RUN_STATUS_FILTERS) { panel.append( h( "label", { class: "filter-item" }, h("input", { id: `status-${status}`, type: "checkbox", checked: filters.lastRunStatuses.includes(status), onchange: (e) => { const next = e.target.checked ? [...state.pipelineFilters.lastRunStatuses, status] : state.pipelineFilters.lastRunStatuses.filter((s) => s !== status); state.pipelineFilters = { ...state.pipelineFilters, lastRunStatuses: next }; renderContent(); }, }), h("span", { text: status }), ), ); } panel.append( h("div", { class: "filter-actions" }, h("button", { class: "ghost", text: "Clear filters", onclick: clearPipelineFilters })), ); return panel; } function renderSortPanel() { const panel = h("div", { class: "menu-panel sort-panel" }); for (const option of PIPELINE_SORTS) { panel.append( h("button", { class: `sort-option${state.pipelineSort === option.key ? " active" : ""}`, text: option.label, onclick: () => { state.pipelineSort = option.key; state.pipelineMenu = null; renderContent(); }, }), ); } panel.append( h( "div", { class: "filter-actions" }, h("button", { class: "ghost", text: "Reset", onclick: () => { state.pipelineSort = "server_order"; state.pipelineMenu = null; renderContent(); }, }), ), ); return panel; } /** Re-renders the rows and the toolbar's active-filter badge after a filter change. */ function refreshPipelineRows() { const rows = document.getElementById("pipelineRows"); if (rows) fillPipelineRows(rows); const count = pipelineFilterCount(state.pipelineFilters); const badge = document.getElementById("filterCount"); if (badge) badge.textContent = count ? ` (${count})` : ""; const clear = document.getElementById("clearFilters"); if (clear) clear.hidden = count === 0; } /** Sorts, filters and renders the pipeline rows (or the matching empty state) into `rowsEl`. */ function fillPipelineRows(rowsEl) { const latestRuns = latestRunByPipeline(state.runs); const runsKnown = state.runsLoaded; const now = Date.now(); const nodes = []; if (state.loading && !state.pipelines.length) { nodes.push(h("div", { class: "muted pad", text: "Loading pipelines…" })); } else if (!state.pipelinesLoaded) { nodes.push(h("div", { class: "muted pad", text: "Connect to the server to load pipelines." })); } else { const sorted = sortPipelines(state.pipelines, state.pipelineSort, latestRuns); const items = filterPipelines(sorted, state.pipelineFilters, latestRuns, runsKnown); if (items.length) { for (const pipeline of items) nodes.push(renderPipelineRow(pipeline, latestRuns, runsKnown, now)); } else { const empty = pipelineListEmptyState(state.pipelines, items, state.pipelineFilters); const box = h("div", { class: "empty pad" }, h("div", { class: "muted", text: empty.message })); if (empty.clearAction) { box.append(h("button", { class: "ghost", text: empty.clearAction, onclick: clearPipelineFilters })); } nodes.push(box); } } rowsEl.replaceChildren(...nodes); } function renderPipelineRow(pipeline, latestRuns, runsKnown, now) { const children = [ h("span", { class: "row-title", text: pipeline.name || `pipeline ${pipeline.id}` }), h("span", { class: "row-meta", text: pipelineSubtitle(pipeline) }), ]; const updated = pipelineUpdatedLine(pipeline); if (updated) children.push(h("span", { class: "row-meta", text: updated })); if (runsKnown) { const run = latestRuns.get(pipeline.id); if (!run) { children.push(h("span", { class: "row-meta muted", text: "no runs recorded" })); } else { const badge = runBadge(run, now); children.push( h( "span", { class: "row-run" }, h("span", { class: `chip chip-${badge.state}`, text: badge.state }), h("span", { class: "row-meta", text: runBadgeMetaLine(badge) }), ), ); } } return h( "button", { class: `row${state.selectedPipelineId === pipeline.id ? " selected" : ""}`, onclick: () => selectPipeline(pipeline) }, ...children, ); } function renderPipelineDetail() { const d = state.pipelineDetail; const pane = h("div", { class: "detail" }); if (!d) { pane.append(h("div", { class: "muted pad", text: "Select a pipeline." })); return pane; } pane.append(h("h2", { text: d.name || `pipeline ${d.id}` })); pane.append( h( "div", { class: "detail-tabs" }, ...PIPELINE_DETAIL_TABS.map((tab) => h("button", { class: `detail-tab${state.pipelineTab === tab.key ? " active" : ""}`, text: tab.label, onclick: () => { state.pipelineTab = tab.key; renderContent(); }, }), ), ), ); if (state.pipelineTab === "graph") { pane.append(h("p", { class: "graph-note muted", text: graphNote() })); const stages = d.graph?.stages ?? []; if (!stages.length) { pane.append(h("div", { class: "muted pad", text: PIPELINE_GRAPH_EMPTY })); return pane; } const host = h("div", { class: "graph-host" }); pane.append(host); state.pipelineGraph = mountGraph(host, d.graph, { expanded: state.pipelineGraphExpanded, onExpandedChange: (value) => { state.pipelineGraphExpanded = value; }, }); return pane; } if (state.pipelineTab === "source") { pane.append(h("pre", { class: "source-code" }, h("code", { text: d.source || "" }))); return pane; } pane.append(h("div", { class: "detail-subtitle muted", text: pipelineSubtitle({ ...d, stages: d.graph?.stages?.length ?? d.stages }) })); const rows = h("div", { class: "kv" }); for (const field of summaryFields(d)) { rows.append( h( "div", { class: "kv-row" }, h("span", { class: "kv-key", text: field.key }), h("span", { class: `kv-val${field.monospace ? " monospace" : ""}`, text: field.value }), ), ); } pane.append(rows); pane.append( h( "button", { class: "section-toggle", onclick: () => { state.versionsExpanded = !state.versionsExpanded; renderContent(); }, }, h("span", { class: "chevron", text: state.versionsExpanded ? "\u25be" : "\u25b8" }), h("span", { text: "Versions" }), ), ); if (state.versionsExpanded) { const versions = d.versions ?? []; const body = h("div", { class: "section-body versions-list" }); if (!versions.length) { body.append(h("div", { class: "muted", text: "No versions recorded." })); } else { for (const version of versions) { const row = versionRow(version); body.append( h( "div", { class: "version-row" }, h("span", { class: "version-title", text: row.versionLabel }), h("span", { class: "muted", text: row.stagesText }), row.createdText ? h("span", { class: "muted", text: row.createdText }) : null, ), ); } } pane.append(body); } return pane; } // --- Templates ------------------------------------------------------------- /** The cached parsed graph for a template key, or null when it did not parse. */ function templateGraphFor(key) { return state.templateGraphs.has(key) ? state.templateGraphs.get(key) : null; } function renderTemplateGallery() { const pane = h("div", { class: "list gallery" }); pane.append( h( "div", { class: "pane-head" }, h("h2", { text: "Templates" }), h("button", { class: "ghost", text: "Refresh templates", onclick: () => loadTemplates(true) }), ), ); if (state.templateLoading && !state.templates.length) { pane.append(h("div", { class: "muted pad", text: "Loading templates…" })); return pane; } if (!state.templates.length) { pane.append(h("div", { class: "muted pad", text: "No templates are available on this server." })); return pane; } const cards = h("div", { class: "cards" }); for (const entry of state.templates) { const card = templateCard(entry, templateGraphFor(entry.key)); cards.append( h( "button", { class: `card${state.selectedTemplateKey === entry.key ? " selected" : ""}`, onclick: () => selectTemplate(entry.key), }, h("span", { class: "card-name", text: templateGalleryName(card.name) }), h("span", { class: "card-desc", text: card.description }), h("span", { class: "card-meta", text: templateStageCountLabel(card.stageCount) }), ), ); } pane.append(cards); return pane; } function renderTemplateDetail() { const pane = h("div", { class: "detail" }); const entry = state.templates.find((t) => t.key === state.selectedTemplateKey); if (!entry) { pane.append(h("div", { class: "muted pad", text: "Select a template." })); return pane; } const graph = templateGraphFor(entry.key); pane.append( h( "div", { class: "tabstrip" }, templateTabButton("summary", "Summary"), templateTabButton("graph", "Graph"), templateTabButton("source", "Source"), ), ); if (state.templateTab === "graph") pane.append(renderTemplateGraphTab(graph)); else if (state.templateTab === "source") pane.append(renderTemplateSourceTab(entry, graph)); else pane.append(renderTemplateSummaryTab(entry, graph)); return pane; } function templateTabButton(tab, label) { return h("button", { class: `minitab${state.templateTab === tab ? " active" : ""}`, text: label, onclick: () => { state.templateTab = tab; renderContent(); }, }); } function renderTemplateSummaryTab(entry, graph) { const wrap = h("div", { class: "tabbody" }); wrap.append(h("h2", { text: templateDetailName(entry) })); if ((entry.description ?? "").trim()) { wrap.append(h("p", { class: "body", text: entry.description })); } wrap.append(h("div", { class: "kv" }, kvMono("Key", entry.key))); wrap.append( h("div", { class: "meta-line", text: templateStageCountLabel(graph?.stages?.length ?? null) }), ); if (entry.scheduled) wrap.append(h("div", { class: "meta-line", text: "Includes a schedule" })); const summary = templateStageSummary(graph); if (summary.note) { wrap.append(h("div", { class: "muted pad", text: summary.note })); return wrap; } wrap.append(h("h3", { text: "Stages" })); const ul = h("ul", { class: "stages" }); for (const stage of summary.stages) { ul.append( h( "li", {}, h("code", { text: stage.key }), h("span", { class: "chip", text: effectiveStageType(stage.type) }), ), ); } wrap.append(ul); return wrap; } function renderTemplateGraphTab(graph) { const wrap = h("div", { class: "tabbody" }); wrap.append(h("p", { class: "muted", text: templateGraphNote(graph) })); return wrap; } function renderTemplateSourceTab(entry, graph) { const wrap = h("div", { class: "tabbody" }); if (graph == null) { wrap.append(h("p", { class: "muted", text: TEMPLATE_UNPARSED_SOURCE_NOTE })); } wrap.append( h( "div", { class: "codeblock" }, h("div", { class: "codeblock-label", text: "Definition source" }), h("pre", { class: "codeblock-body", text: entry.source ?? "" }), ), ); return wrap; } function pipelineSortLabel(key) { return (PIPELINE_SORTS.find((option) => option.key === key) ?? PIPELINE_SORTS[0]).label; } function clearPipelineFilters() { state.pipelineFilters = { ...EMPTY_PIPELINE_FILTERS }; renderContent(); } function renderRunList() { const pane = h("div", { class: "list runs" }); pane.append(renderRunToolbar()); const scroll = h("div", { class: "run-scroll" }); if (state.loading && !state.runs.length) { scroll.append(h("div", { class: "muted pad", text: "Loading…" })); pane.append(scroll); return pane; } const filters = state.runFilters; const today = localDayKey(new Date()); const filtered = filterRuns(state.runs, filters, today); const groups = groupRunsByDay(filtered, today, undefined, runComparator(state.runSort)); const entries = runListEntries( state.usage, state.runs.length === 0, filtered.length === 0 && state.runs.length > 0, groups, "", ); for (const entry of entries) { switch (entry.kind) { case "usage": scroll.append(renderUsage(entry.usage)); break; case "empty": scroll.append(renderEmptyState(entry)); break; case "day": scroll.append(h("div", { class: "day-header", text: entry.label })); break; case "run": scroll.append(renderRunRow(entry.run)); break; case "error": scroll.append(h("div", { class: "run-list-error", text: entry.message })); break; } } pane.append(scroll); return pane; } function renderUsage(usage) { const metrics = h("div", { class: "metrics" }); metrics.append(metric("Total", String(usage.total ?? 0), "total")); if ((usage.average_seconds ?? 0) > 0) { metrics.append(metric("Average", formatDuration(usage.average_seconds), "average")); } metrics.append(metric("Succeeded", String(usage.succeeded ?? 0), "succeeded")); metrics.append(metric("Failed", String(usage.failed ?? 0), "failed")); metrics.append(metric("Canceled", String(usage.canceled ?? 0), "canceled")); metrics.append(metric("Interrupted", String(usage.interrupted ?? 0), "interrupted")); metrics.append(metric("Active", String(usage.active ?? 0), "active")); return metrics; } function metric(label, value, cls) { return h( "div", { class: `metric metric-${cls}` }, h("span", { class: "metric-value", text: value }), h("span", { class: "metric-label", text: label }), ); } function renderEmptyState(entry) { const wrap = h("div", { class: "empty-state" }, h("span", { text: entry.message })); if (entry.actionLabel) { wrap.append(h("button", { class: "ghost", text: entry.actionLabel, onclick: clearRunFilters })); } return wrap; } /** * One run row, in the app's exact hierarchy: status chip (+ spinner while * executing); primary line = stored title else pipeline name, carrying the * version chip when there is no title; the pipeline name + version chip on a * second line only when a title exists; the progress line; the meta line; and * the diagnostic line, in the error colour only on a failure. Every * server-provided string is set with textContent. */ function renderRunRow(run) { const status = runStateOf(run.status); const identity = runIdentity(run.title, run.name); const row = h("button", { class: `row run-row${state.selectedRunId === run.id ? " selected" : ""}`, onclick: () => selectRun(run.id), }); const head = h("span", { class: "run-row-head" }); head.append(h("span", { class: `chip chip-${status}`, text: status })); if (run.executing) head.append(h("span", { class: "spinner", "aria-hidden": "true" })); head.append(h("span", { class: "run-row-title", text: identity.label })); if (identity.pipeline == null) head.append(versionChip(run.version)); row.append(head); if (identity.pipeline != null) { row.append( h( "span", { class: "run-row-pipeline" }, h("span", { class: "run-row-pipeline-name", text: identity.pipeline }), versionChip(run.version), ), ); } row.append(h("span", { class: "run-row-progress", text: progressText(run) })); row.append( h("span", { class: "run-row-meta", "data-run-id": String(run.id), text: metaText(run, listNow), }), ); if (String(run.diagnostic ?? "").trim()) { row.append( h("span", { class: `run-row-diag${status === "failed" ? " error" : ""}`, text: run.diagnostic, }), ); } return row; } function versionChip(version) { return h("span", { class: "version-chip", text: versionLabel(version) }); } function renderRunToolbar() { const activeCount = runFiltersActiveCount(state.runFilters); const filterLabel = activeCount > 0 ? `Filter (${activeCount})` : "Filter"; const sortLabel = (RUN_SORTS.find((s) => s.value === state.runSort) ?? RUN_SORTS[0]).label; const toolbar = h("div", { class: "run-toolbar" }); toolbar.append( h( "div", { class: "menu-anchor" }, h("button", { id: "runFilterBtn", class: `ghost filter-btn${activeCount > 0 ? " active" : ""}`, title: activeCount > 0 ? `${activeCount} active filter${activeCount === 1 ? "" : "s"}` : "Filter runs", text: filterLabel, "data-active-count": String(activeCount), onclick: () => toggleMenu("filter"), }), state.openMenu === "filter" ? renderFilterMenu() : null, ), h( "div", { class: "menu-anchor" }, h("button", { id: "runSortBtn", class: "ghost sort-btn", title: "Sort runs", text: `Sort: ${sortLabel}`, onclick: () => toggleMenu("sort"), }), state.openMenu === "sort" ? renderSortMenu() : null, ), h("span", { class: "spacer" }), ); return toolbar; } function renderFilterMenu() { const filters = state.runFilters; const menu = h("div", { class: "menu filter-menu", id: "runFilterMenu" }); menu.append(h("div", { class: "menu-section", text: "Status" })); for (const status of RUN_STATES) { menu.append( filterCheck(status, filters.statuses.has(status), () => toggleStatusFilter(status), { "data-status": status, }), ); } menu.append(h("div", { class: "menu-divider" })); menu.append(h("div", { class: "menu-section", text: "Pipeline" })); menu.append( filterCheck("Any pipeline", filters.pipelineId == null, () => setPipelineFilter(null), { "data-pipeline": "any", }), ); for (const option of pipelineFilterOptions(state.runs)) { menu.append( filterCheck(option.name, filters.pipelineId === option.id, () => setPipelineFilter(option.id), { "data-pipeline": String(option.id), }), ); } menu.append(h("div", { class: "menu-divider" })); menu.append(h("div", { class: "menu-section", text: "Time range" })); for (const range of RUN_TIME_RANGES) { menu.append( filterCheck(range.label, filters.timeRange === range.value, () => setTimeRangeFilter(range.value), { "data-time": range.value, }), ); } menu.append( h( "div", { class: "menu-actions" }, h("button", { class: "ghost", text: "Clear filters", onclick: clearRunFilters }), h("button", { class: "ghost", text: "Done", onclick: closeMenu }), ), ); return menu; } function filterCheck(label, checked, onclick, data = {}) { return h( "label", { class: "filter-check" }, h("input", { type: "checkbox", checked: checked ? "checked" : null, onchange: onclick, ...data, }), h("span", { text: label }), ); } function renderSortMenu() { const menu = h("div", { class: "menu sort-menu", id: "runSortMenu" }); for (const option of RUN_SORTS) { menu.append( h("button", { class: `menu-item${state.runSort === option.value ? " selected" : ""}`, text: option.label, onclick: () => { state.runSort = option.value; closeMenu(); }, }), ); } menu.append(h("div", { class: "menu-divider" })); menu.append( h("button", { class: "menu-item", text: "Reset", onclick: () => { state.runSort = DEFAULT_RUN_SORT; closeMenu(); }, }), ); return menu; } function toggleStatusFilter(status) { const next = new Set(state.runFilters.statuses); if (next.has(status)) next.delete(status); else next.add(status); state.runFilters = { ...state.runFilters, statuses: next }; renderContent(); } function setPipelineFilter(pipelineId) { state.runFilters = { ...state.runFilters, pipelineId }; closeMenu(); } function setTimeRangeFilter(timeRange) { state.runFilters = { ...state.runFilters, timeRange }; closeMenu(); } function clearRunFilters() { state.runFilters = defaultRunFilters(); closeMenu(); } function toggleMenu(name) { state.openMenu = state.openMenu === name ? null : name; renderContent(); } function closeMenu() { state.openMenu = null; renderContent(); } /** * The run detail: a tab strip (Summary / Input / Output / Timeline) over the * selected tab's body, wired from the pure helpers in runDetail.js. Summary is * the default and carries the run's identity, key/value rows and diagnostic; * Input/Output are one collapsed section per recorded field; the Timeline is one * compact row per visit that opens the stage pane. Every server string is set * with textContent, never innerHTML. */ function renderRunDetail() { const d = state.runDetail; const pane = h("div", { class: "detail run-detail" }); if (!d) { pane.append(h("div", { class: "muted pad", text: "Select a run." })); return pane; } pane.append( h( "div", { class: "detail-tabs" }, ...RENDERED_RUN_TABS.map((tab) => h("button", { class: `detail-tab${state.runTab === tab.key ? " active" : ""}`, text: tab.label, onclick: () => { state.runTab = tab.key; renderContent(); }, }), ), ), ); if (state.runTab === "input") { pane.append(renderRunFieldTab(d.input, "input", EMPTY_INPUT_MESSAGE)); } else if (state.runTab === "output") { pane.append(renderRunFieldTab(d.output, "output", EMPTY_OUTPUT_MESSAGE)); } else if (state.runTab === "steps") { pane.append(renderRunTimelineTab(d)); } else { pane.append(renderRunSummaryTab(d)); } if (state.runStagePane) pane.append(renderStagePane(d)); return pane; } /** The Summary tab: identity, chip row, key/value rows, diagnostic and gallery. */ function renderRunSummaryTab(d) { const wrap = h("div", { class: "run-tab-body" }); wrap.append(h("h2", { class: "run-detail-title", text: runLabelFor(d) })); const status = runStateOf(d.status); const chips = h("div", { class: "run-chip-row" }); chips.append(h("span", { class: `chip chip-${status}`, text: d.status || status })); if (String(d.outcome ?? "").trim()) chips.append(h("span", { class: "muted", text: `outcome ${d.outcome}` })); if (d.executing) chips.append(h("span", { class: "muted", text: "executing" })); wrap.append(chips); wrap.append(h("div", { class: "run-identity muted", text: runIdentityLine(d) })); const rows = h("div", { class: "kv" }); for (const row of summaryRows(d, detailNow)) { if (row.kind === "wait") rows.append(h("div", { class: "run-wait", text: row.value })); else if (row.kind === "duration") rows.append(renderDurationRow(d, row)); else if (row.kind === "block") rows.append(renderCodeBlock(row.key, row.value)); else rows.append(renderKvRow(row)); } wrap.append(rows); // The run-level artifacts gallery (parity R8), collapsed by default like the // Android summary. Its header alone says what was captured until expanded. wrap.append( renderCollapsible("summary-artifacts", artifactsHeader(d.steps ?? [], isExecuting(d)), () => renderArtifactGallery(d.steps ?? []), ), ); return wrap; } /** The Duration row, tagged so the detail clock can update it in place. */ function renderDurationRow(d, row) { return h( "div", { class: "kv-row" }, h("span", { class: "kv-key", text: row.key }), h("span", { class: "kv-val run-duration", "data-run-id": String(d.id), text: row.value }), ); } /** One key/value row from a summary row model. */ function renderKvRow(row) { return h( "div", { class: "kv-row" }, h("span", { class: "kv-key", text: row.key }), h("span", { class: `kv-val${row.monospace ? " monospace" : ""}`, text: row.value }), ); } /** A themed monospace block with a label header. */ function renderCodeBlock(label, text) { return h( "div", { class: "codeblock" }, h("div", { class: "codeblock-label", text: label }), h("pre", { class: "codeblock-body", text }), ); } /** One stage-pane field as either the code card (blocks) or a key/value row. */ function renderStageField(field) { if (field.block) return renderCodeBlock(field.label, field.value); return h( "div", { class: "kv-row" }, h("span", { class: "kv-key", text: field.label }), h("span", { class: `kv-val${field.mono ? " monospace" : ""}`, text: field.value }), ); } /** One collapsible input/output field section (expanded body is a code block). */ function renderRunFieldTab(map, keyPrefix, emptyMessage) { const wrap = h("div", { class: "run-tab-body" }); const sections = fieldSections(map, keyPrefix); if (!sections.length) { wrap.append(h("div", { class: "run-empty muted", text: emptyMessage })); return wrap; } for (const section of sections) { const key = `${keyPrefix}-${section.key}`; wrap.append( renderCollapsible(key, section.title, () => h("pre", { class: "field-block" }, h("code", { text: section.value })), ), ); } return wrap; } /** * One collapsible section of the run detail's field/summary body. Expanded state * is keyed in `state.runSections`, so the operator's choices survive a re-render. */ function renderCollapsible(key, title, bodyFn) { const expanded = state.runSections.has(key); const wrap = h("div", { class: "collapsible" }); wrap.append( h( "button", { class: "section-toggle", type: "button", "aria-expanded": expanded ? "true" : "false", onclick: () => { state.runSections = new Set(state.runSections); if (state.runSections.has(key)) state.runSections.delete(key); else state.runSections.add(key); renderContent(); }, }, h("span", { class: "chevron", text: expanded ? "\u25be" : "\u25b8" }), h("span", { class: "section-title", text: title }), ), ); if (expanded) wrap.append(h("div", { class: "section-body" }, bodyFn())); return wrap; } /** The Timeline tab: one compact row per visit, in step order. */ function renderRunTimelineTab(d) { const wrap = h("div", { class: "run-tab-body" }); const timeline = runTimeline(d.steps ?? []); if (!timeline.entries.length) { wrap.append(h("div", { class: "run-empty muted", text: EMPTY_TIMELINE_MESSAGE })); return wrap; } const list = h("div", { class: "timeline" }); for (const entry of timeline.entries) list.append(renderTimelineRow(entry)); wrap.append(list); return wrap; } /** * One timeline row: a stage-outcome glyph, the `{stage} · visit {n}` line with * the outcome chip, a paperclip when the visit recorded artifacts, the duration, * and the one-line description. Clicking (or Enter/Space) opens the stage pane. */ function renderTimelineRow(entry) { const state_ = runStateOf(entry.outcomeLabel); const chipLabel = entry.outcomeLabel || state_.label; const tone = outcomeClass(entry.step.outcome, entry.step.status); const open = () => openStagePane(entry.stageKey, entry.visitIndex); const row = h("div", { class: "timeline-row", role: "button", tabindex: "0", "data-stage-key": entry.stageKey, "data-visit-index": String(entry.visitIndex), }); row.addEventListener("click", open); row.addEventListener("keydown", (event) => { if (event.key === "Enter" || event.key === " ") { event.preventDefault(); open(); } }); row.append(h("span", { class: `timeline-glyph ${tone}`, text: stateGlyph(state_) })); const head = h("div", { class: "timeline-head" }); head.append(h("span", { class: "timeline-title", text: `${entry.stageKey} · visit ${entry.visit}` })); head.append(h("span", { class: `outcome-chip ${tone}`, text: chipLabel })); if (entry.hasArtifacts) { head.append( h("span", { class: "timeline-paperclip", title: "Recorded artifacts", "aria-label": "has recorded artifacts", text: "\u{1F4CE}" }), ); } if (entry.duration) head.append(h("span", { class: "timeline-duration muted", text: entry.duration })); const body = h("div", { class: "timeline-main" }, head); if (entry.description) body.append(h("span", { class: "timeline-desc muted", text: entry.description })); row.append(body); return row; } /** A CSS class naming a stage-outcome colour (status palette, else flow). */ function outcomeClass(outcome, status) { const [kind, value] = outcomeColorToken(outcome, status).split(" "); return `outcome-${kind}-${value}`; } // --- Stage pane ------------------------------------------------------------ /** * The stage pane: a closable dialog for one visit, opened from a timeline row. * It leads with the verdict block (when the server recorded one), then the * always-visible headline rows, then the visit's collapsible sections in the * Android order (Artifacts, Session, Output, Input, This run, Stage definition). * Escape, the Back button and a backdrop click close it. */ function renderStagePane(d) { const stageKey = state.runStagePane.stageKey; const timeline = runTimeline(d.steps ?? []); const runSteps = timeline.visitsByStage.get(stageKey) ?? []; const visitIndex = clampVisitIndex(state.runStagePane.visitIndex, runSteps.length); const step = runSteps[visitIndex] ?? null; const graph = d.graph ?? { stages: [] }; const specs = stageSectionSpecs(stageKey, graph, runSteps, visitIndex, true); const fields = step ? runStepFields(step) : []; const headline = headlineFields(fields); const overlay = h("div", { class: "stage-pane", role: "dialog", "aria-modal": "true", "aria-label": nodeLabel(stageKey), }); overlay.addEventListener("click", (event) => { if (event.target === overlay) closeStagePane(); }); const bar = h( "div", { class: "stage-pane-bar" }, h("button", { class: "stage-pane-back", type: "button", "aria-label": "Back", text: "\u2190 Back", onclick: closeStagePane, }), h( "div", { class: "stage-pane-titles" }, h("span", { class: "stage-pane-title", text: nodeLabel(stageKey) }), h("span", { class: "stage-pane-run muted", text: runLabelFor(d) }), ), ); const body = h("div", { class: "stage-pane-body" }); if (step) { const verdict = renderVerdictBlock(step); if (verdict) body.append(verdict); } for (const field of headline) body.append(renderStageField(field)); if (headline.length === 0 && specs.length === 0) { body.append(h("div", { class: "run-empty muted", text: NO_STAGE_DETAILS_MESSAGE })); } for (const spec of specs) body.append(renderStageSection(spec, step)); overlay.append(h("div", { class: "stage-pane-sheet" }, bar, body)); return overlay; } /** One stage-pane section, using the pane's own expansion state. */ function renderStageSection(spec, step) { const expanded = state.runStageSections.has(spec.key); const wrap = h("div", { class: "collapsible stage-section" }); wrap.append( h( "button", { class: "section-toggle", type: "button", "aria-expanded": expanded ? "true" : "false", onclick: () => { state.runStageSections = new Set(state.runStageSections); if (state.runStageSections.has(spec.key)) state.runStageSections.delete(spec.key); else state.runStageSections.add(spec.key); renderContent(); }, }, h("span", { class: "chevron", text: expanded ? "\u25be" : "\u25b8" }), h("span", { class: "section-title", text: spec.title }), ), ); if (!expanded) return wrap; const body = h("div", { class: "section-body" }); if (spec.artifacts && step) body.append(renderVisitArtifacts(step)); else if (spec.session && step) body.append(renderSessionExport(step)); else for (const field of spec.fields) body.append(renderStageField(field)); wrap.append(body); return wrap; } /** * The verdict block: heading "Verdict", the option as an outcome-coloured chip, * the reason as body text with inline artifact links, and the referenced * artifacts as compact chips. Nothing renders when the server recorded no * option and no reason. */ function renderVerdictBlock(step) { const verdict = step.verdict; if (!verdict) return null; const option = String(verdict.option ?? ""); const reason = String(verdict.reason ?? ""); if (option.trim() === "" && reason.trim() === "") return null; const wrap = h("div", { class: "verdict" }); const head = h("div", { class: "verdict-head" }, h("span", { class: "verdict-title", text: "Verdict" })); if (option.trim() !== "") { head.append(h("span", { class: `outcome-chip ${outcomeClass(step.outcome, step.status)}`, text: option })); } wrap.append(head); const references = referencedVerdictArtifacts(verdict, presentedArtifacts(step)); if (reason.trim() !== "") { const body = h("p", { class: "verdict-reason" }); for (const segment of verdictReasonSegments(reason, references)) { if (!segment.artifact) body.append(document.createTextNode(segment.text)); else body.append(renderVerdictLink(segment.text, segment.artifact, step)); } wrap.append(body); } if (references.length) { const refs = h("div", { class: "verdict-refs" }); for (const artifact of references) refs.append(renderVerdictRef(artifact, step)); wrap.append(refs); } return wrap; } /** One inline artifact reference in a verdict reason (media opens the viewer). */ function renderVerdictLink(text, artifact, step) { const resolved = resolvedArtifactUrl(artifact, state.url); if (!resolved) return h("span", { class: "verdict-link disabled", text }); const link = h("a", { class: "verdict-link", href: resolved, target: "_blank", rel: "noreferrer", text }); link.addEventListener("click", (event) => { event.preventDefault(); openArtifactFromVerdict(artifact, step, resolved); }); return link; } /** One compact chip naming a referenced artifact. */ function renderVerdictRef(artifact, step) { const resolved = resolvedArtifactUrl(artifact, state.url); const chip = h("button", { class: "verdict-ref", type: "button", text: artifact.name || "(unnamed artifact)", }); chip.addEventListener("click", () => openArtifactFromVerdict(artifact, step, resolved)); return chip; } /** Open a referenced artifact: media in the viewer, everything else externally. */ function openArtifactFromVerdict(artifact, step, resolved) { if (!resolved) return; const group = { stageKey: step.stage, visit: displayVisit(step, 0), artifacts: presentedArtifacts(step) }; const viewable = pagedArtifacts([group]); const viewerIndexOf = viewerIndexByUrl([group]); const at = viewerIndexOf.get(artifact.url); const kind = artifactKind(artifact.content_type, artifact.name); const media = kind === ArtifactKind.Image || kind === ArtifactKind.Video; if (media && at != null) openArtifactViewer(viewable, at); else window.open(resolved, "_blank", "noopener,noreferrer"); } /** Open the stage pane for one visit of a stage and move focus into it. */ function openStagePane(stageKey, visitIndex) { state.runStagePane = { stageKey, visitIndex }; state.runStageSections = new Set(); renderContent(); document.querySelector(".stage-pane-back")?.focus(); } /** Close the stage pane, returning focus to the timeline row that opened it. */ function closeStagePane() { const closing = state.runStagePane; if (!closing) return; state.runStagePane = null; state.runStageSections = new Set(); renderContent(); const row = [...document.querySelectorAll(".timeline-row")].find( (node) => node.dataset.stageKey === closing.stageKey && node.dataset.visitIndex === String(closing.visitIndex), ); row?.focus(); } /** Whether the configured server URL can resolve a server-relative artifact. */ function artifactsResolvable() { return resolveArtifactUrl(state.url, "/artifacts/0/0/probe") != null; } /** * The run-level gallery: one header per (stage, visit) and one grid of tiles per * visit, in the gallery order (stages first-appearance, visits by sequence). A * run with no artifacts shows the header (which already says why) and nothing * else, so the section is never blank. */ function renderArtifactGallery(steps) { const wrap = h("div", { class: "artifact-gallery" }); const groups = artifactGroups(steps); if (!groups.length) return wrap; if (!artifactsResolvable()) { wrap.append(h("div", { class: "muted artifact-hint", text: ARTIFACT_SERVER_HINT })); } const viewable = pagedArtifacts(groups); const viewerIndexOf = viewerIndexByUrl(groups); for (const group of groups) { wrap.append( h("div", { class: "artifact-group-head", text: `${group.stageKey} · visit ${group.visit}` }), renderArtifactGrid(group.artifacts, viewable, viewerIndexOf), ); } return wrap; } /** * The per-visit artifacts section shown inside one step: the summary line, the * capture notes, the no-server-URL hint and a headerless grid of that visit's * tiles (matching the Android ArtifactsSection). Its viewer pages only through * that visit's media, exactly as the Android section does. */ function renderVisitArtifacts(step) { const wrap = h("div", { class: "artifacts" }); wrap.append(h("div", { class: "artifacts-summary", text: artifactsSummary(step) })); for (const note of artifactCaptureNotes(step)) { wrap.append(h("div", { class: "artifacts-note muted", text: note })); } const artifacts = presentedArtifacts(step); if (artifacts.length) { if (!artifactsResolvable()) { wrap.append(h("div", { class: "muted artifact-hint", text: ARTIFACT_SERVER_HINT })); } const group = { stageKey: step.stage, visit: displayVisit(step, 0), artifacts }; wrap.append( renderArtifactGrid(artifacts, pagedArtifacts([group]), viewerIndexByUrl([group])), ); } return wrap; } /** One visit's tiles in a CSS grid. */ function renderArtifactGrid(artifacts, viewable, viewerIndexOf) { const grid = h("div", { class: "artifact-grid" }); for (const artifact of artifacts) { grid.append(renderArtifactTile(artifact, viewable, viewerIndexOf)); } return grid; } /** * One gallery tile: an image thumbnail, a video poster with a play marker (never * a