diff --git a/.ui-stage-definition/01-run-definition-rendered.png b/.ui-stage-definition/01-run-definition-rendered.png new file mode 100644 index 00000000..594a4507 Binary files /dev/null and b/.ui-stage-definition/01-run-definition-rendered.png differ diff --git a/.ui-stage-definition/02-run-definition-raw.png b/.ui-stage-definition/02-run-definition-raw.png new file mode 100644 index 00000000..3ddc9e99 Binary files /dev/null and b/.ui-stage-definition/02-run-definition-raw.png differ diff --git a/.ui-stage-definition/03-pipeline-definition-rendered.png b/.ui-stage-definition/03-pipeline-definition-rendered.png new file mode 100644 index 00000000..da4c9d8f Binary files /dev/null and b/.ui-stage-definition/03-pipeline-definition-rendered.png differ diff --git a/.ui-stage-definition/04-visit-definition-nested.png b/.ui-stage-definition/04-visit-definition-nested.png new file mode 100644 index 00000000..ceb9d6fb Binary files /dev/null and b/.ui-stage-definition/04-visit-definition-nested.png differ diff --git a/.ui-stage-definition/05-definition-missing-source.png b/.ui-stage-definition/05-definition-missing-source.png new file mode 100644 index 00000000..4ae5dd8a Binary files /dev/null and b/.ui-stage-definition/05-definition-missing-source.png differ diff --git a/.ui-stage-definition/06-definition-load-failed.png b/.ui-stage-definition/06-definition-load-failed.png new file mode 100644 index 00000000..6bc5690b Binary files /dev/null and b/.ui-stage-definition/06-definition-load-failed.png differ diff --git a/.ui-stage-definition/07-definition-terminal.png b/.ui-stage-definition/07-definition-terminal.png new file mode 100644 index 00000000..8942870e Binary files /dev/null and b/.ui-stage-definition/07-definition-terminal.png differ diff --git a/.ui-stage-definition/08-definition-narrow.png b/.ui-stage-definition/08-definition-narrow.png new file mode 100644 index 00000000..97baa69f Binary files /dev/null and b/.ui-stage-definition/08-definition-narrow.png differ diff --git a/.ui-stage-definition/09-definition-loading.png b/.ui-stage-definition/09-definition-loading.png new file mode 100644 index 00000000..81287603 Binary files /dev/null and b/.ui-stage-definition/09-definition-loading.png differ diff --git a/.ui-stage-definition/10-definition-missing-version.png b/.ui-stage-definition/10-definition-missing-version.png new file mode 100644 index 00000000..c8a341cc Binary files /dev/null and b/.ui-stage-definition/10-definition-missing-version.png differ diff --git a/web/PARITY.md b/web/PARITY.md index 2798250e..cd231dd4 100644 --- a/web/PARITY.md +++ b/web/PARITY.md @@ -32,6 +32,28 @@ through the real button at 1100px, and checks the rail remains hidden at 390/420px. Captures: `rail-collapsed-1100.png`, `rail-expanded-1100.png` in the directory above. Mobile and the expanded rail are unchanged. +### Stage definition popup follow-up (2026-10-20) + +P6/R5 follow-up: **partial** against the live-server parity gate; verified with +the scratch-only `node test/ui-stage-definition.mjs ../.ui-stage-definition` +browser extension. Clicking a stage in either graph now opens the managed audit +popup, without replacing the current pane or changing its route. Timeline visit +panes remain available, and their Audit & debug Definition tab shares the viewer. +Rendered uses the existing Markdown/code renderer; Raw is the exact authored +stage source slice (including whitespace, custom blocks and shorthand), not a +serialization of the normalized graph. Run definitions request `get_pipeline` +with the recorded pipeline id/version, never latest. Missing source and load +errors are explicit; terminal nodes have no authored stage definition. + +Scratch captures: `.ui-stage-definition/01-run-definition-rendered.png`, +`02-run-definition-raw.png`, `03-pipeline-definition-rendered.png`, +`04-visit-definition-nested.png`, `05-definition-missing-source.png`, +`06-definition-load-failed.png`, `07-definition-terminal.png`, and +`08-definition-narrow.png`, `09-definition-loading.png`, and +`10-definition-missing-version.png`. Real browser assertions cover exact source, pinned +version, unchanged route, nested-pane preservation, Tab trapping and Escape/focus +restoration. No deployed service, live workflow or device was used. + ### Chat audit follow-up (2026-10-20, partial — fresh UI captures pending) Codex model follow-up (partial, fixture-tested; fresh UI captures pending): diff --git a/web/src/stageDefinition.js b/web/src/stageDefinition.js new file mode 100644 index 00000000..e173b706 --- /dev/null +++ b/web/src/stageDefinition.js @@ -0,0 +1,21 @@ +// Exact source ranges, following internal/pipeline/definition.go's block rules. +// Never reserialize graph fields: defaults and authored spelling differ. +export function stageSource(source, key) { + if (typeof source !== "string") return null; + let active = false; + let start = null; + let offset = 0; + for (const line of source.match(/[^\n]*\n|[^\n]+$/g) ?? []) { + const trim = line.trim(); + if (active) { + if (trim === "```") active = false; + } else if (trim.startsWith("# stage ")) { + if (start !== null) return source.slice(start, offset); + if (trim.slice(8).trim() === key) start = offset; + } else if (trim.startsWith("```")) { + active = true; + } + offset += line.length; + } + return start === null ? null : source.slice(start); +} diff --git a/web/src/views/dialogs.js b/web/src/views/dialogs.js index 092ad8a9..0ca32a09 100644 --- a/web/src/views/dialogs.js +++ b/web/src/views/dialogs.js @@ -4,6 +4,7 @@ import { backChevronIcon, h, canCopyLink, canShare, copyArtifactLink, copyText, shareArtifact } from "../dom.js"; import { changeKindTone, describeError } from "../format.js"; +import { definitionDocument } from "./stageDefinition.js"; import { BINARY_DIFF_MESSAGE, NO_LINE_CHANGES_MESSAGE, @@ -826,6 +827,16 @@ function openArtifactViewer(viewable, startIndex, trigger = null) { }); } +/** Graph inspection reuses the audit viewer without touching pane/route state. */ +function openStageDefinition(detail, stageKey, subtitle = "") { + openStageAudit({ + title: `${stageKey} definition`, + subtitle, + tabs: [{ key: "definition", label: "Definition", body: () => + definitionDocument(detail, stageKey, (text) => rt.views.chat.renderMarkdown(text)) }], + }); +} + /** * The Audit & debug dialog: a stage's turn-owned evidence behind vertical tabs * (Input, Output, Memory, Session, Stage definition), the chosen section's body @@ -927,6 +938,7 @@ function openStageAudit({ title = "Audit", subtitle = "", tabs = [], trigger = n } return { + openStageDefinition, closeChangeViewer, openChangeViewer, openDecisionSheet, diff --git a/web/src/views/pipelines.js b/web/src/views/pipelines.js index 8f3ec2c6..5aac009c 100644 --- a/web/src/views/pipelines.js +++ b/web/src/views/pipelines.js @@ -576,6 +576,7 @@ function renderPipelineDetail() { pane.append(host); state.pipelineGraph = mountGraph(host, d.graph, { expanded: state.pipelineGraphExpanded, + onStageTap: (key) => rt.views.dialogs.openStageDefinition(d, key, `${d.name || "Pipeline"} · v${d.version}`), selectedKey: state.pipelineGraphSelection, onSelectionChange: (key) => { // The graph has already opened or closed its own definition pane; record diff --git a/web/src/views/runDetail.js b/web/src/views/runDetail.js index 4282407e..cd09fb3c 100644 --- a/web/src/views/runDetail.js +++ b/web/src/views/runDetail.js @@ -9,6 +9,7 @@ import { resolveArtifactUrl } from "../serverUrl.js"; import { runStateOf, runStatusLabel } from "../runs.js"; import { PIPELINE_GRAPH_EMPTY, RUN_GRAPH_MISSING, mount as mountGraph } from "../graph.js"; import { writeGraphExpanded } from "../graphPrefs.js"; +import { definitionDocument } from "./stageDefinition.js"; import { RENDERED_RUN_TABS, EMPTY_INPUT_MESSAGE, @@ -26,8 +27,6 @@ import { headlineFields, runStepFields, stageSectionSpecs, - stageDefinitionFields, - terminalFields, clampVisitIndex, referencedVerdictArtifacts, verdictReasonSegments, @@ -174,8 +173,8 @@ function renderRunDetail(now = Date.now()) { * The Graph tab (R5): the run's own guidance note plus the shared workflow graph * mounted in run mode, or the app's exact missing-graph sentence when the server * sent no stages. The active stage pulses with its elapsed time while the run - * executes; clicking a stage opens the existing visit pane at that stage's most - * recent visit. The mount handle is tracked in `state.runGraph` so a re-render + * executes; clicking a stage opens its authored definition without navigating. + * The mount handle is tracked in `state.runGraph` so a re-render * (or a tab/run change) always unmounts the previous wheel/pointer/resize * listeners and the elapsed timer. */ @@ -191,7 +190,9 @@ function renderRunGraphTab(d) { state.runGraph = mountGraph(host, d.graph, { runState: runGraphState(d), expanded: state.runGraphExpanded, - onStageTap: (key) => openStagePane(key, latestVisitIndex(d, key)), + onStageTap: (key) => rt.views.dialogs.openStageDefinition( + runDefinition(d), key, `Run ${d.id} · pipeline ${d.pipeline_id} · v${d.version}`, + ), onExpandedChange: (value) => { state.runGraphExpanded = value; writeGraphExpanded(value); @@ -212,8 +213,6 @@ function latestVisitIndex(d, key) { /** Open the audit dialog for one visit: its turn files, session and definition. */ function openAuditFor(d, step, stageKey, visitIndex) { if (!step) return; - const graph = d.graph ?? { stages: [] }; - const stage = (graph.stages ?? []).find((candidate) => candidate.key === stageKey) ?? null; showStageAudit({ title: `${nodeLabel(stageKey)} audit`, subtitle: `Visit ${visitIndex + 1} · ${runLabelFor(d)}`, @@ -222,7 +221,9 @@ function openAuditFor(d, step, stageKey, visitIndex) { { key: "output", label: "Output", body: () => auditArtifact(step, "output.md", EMPTY_OUTPUT_MESSAGE) }, { key: "memory", label: "Memory", body: () => auditArtifact(step, "memory.md", "No memory recorded for this visit.") }, { key: "session", label: "Session", body: () => auditSession(step) }, - { key: "definition", label: "Definition", body: () => auditDefinition(stage, stageKey, graph) }, + { key: "definition", label: "Definition", body: () => definitionDocument( + runDefinition(d), stageKey, (text) => rt.views.chat.renderMarkdown(text), + ) }, ], }); } @@ -341,13 +342,13 @@ function auditSession(step) { return wrap; } -/** The stage's own definition (prompt, tools, configs, edges) in the audit. */ -function auditDefinition(stage, stageKey, graph) { - const fields = stage ? stageDefinitionFields(stage) : terminalFields(graph, stageKey); - if (!fields.length) return h("div", { class: "muted", text: NO_STAGE_DETAILS_MESSAGE }); - const body = h("div", { class: "audit-definition" }); - for (const field of fields) body.append(renderStageField(field)); - return body; +/** Load authored source for exactly the run's recorded version. */ +function runDefinition(d) { + // Never fall back to latest: a run must show the version it executed. + if (!(Number(d.pipeline_id) > 0 && Number(d.version) > 0)) { + return Promise.reject(new Error("The run did not include its pipeline version.")); + } + return repo.getPipeline(d.pipeline_id, d.version); } /** The Summary tab: identity, key/value rows, diagnostic and the sections. */ diff --git a/web/src/views/stageDefinition.js b/web/src/views/stageDefinition.js new file mode 100644 index 00000000..af0094f7 --- /dev/null +++ b/web/src/views/stageDefinition.js @@ -0,0 +1,44 @@ +import { h } from "../dom.js"; +import { describeError } from "../format.js"; +import { stageSource } from "../stageDefinition.js"; + +/** Both modes use the same authored source, including unknown/custom blocks. */ +export function definitionDocument(detail, key, renderMarkdown) { + const wrap = h("div", { class: "audit-doc stage-definition-document" }); + const toggle = h("div", { class: "audit-doc-toggle", role: "group", "aria-label": "Definition view" }); + const out = h("div", { class: "audit-doc-body", "aria-live": "polite" }); + let mode = "rendered"; + let source = null; + const buttons = ["rendered", "raw"].map((value) => h("button", { + class: "audit-doc-mode", + type: "button", + text: value === "raw" ? "Raw" : "Rendered", + onclick: () => { mode = value; draw(); }, + })); + const draw = () => { + buttons.forEach((button, index) => { + const selected = mode === ["rendered", "raw"][index]; + button.classList.toggle("active", selected); + button.setAttribute("aria-pressed", String(selected)); + }); + if (source === null) return; + out.replaceChildren(mode === "raw" + ? h("pre", { class: "field-block" }, h("code", { text: source })) + : h("div", { class: "field-markdown" }, renderMarkdown(source))); + }; + toggle.append(...buttons); + wrap.append(h("div", { class: "audit-doc-bar" }, toggle), out); + out.append(h("div", { class: "muted", text: "Loading stage definition…" })); + draw(); + Promise.resolve(detail).then((pipeline) => { + source = stageSource(pipeline?.source, key); + if (source === null) { + out.replaceChildren(h("div", { class: "muted", text: key.startsWith("#") + ? "Terminal nodes have no authored stage definition." + : "The server did not include source for this stage. No definition has been reconstructed." })); + } else draw(); + }).catch((error) => { + out.replaceChildren(h("div", { class: "muted", text: `Could not load stage definition: ${describeError(error)}` })); + }); + return wrap; +} diff --git a/web/test/stageDefinition.test.mjs b/web/test/stageDefinition.test.mjs new file mode 100644 index 00000000..71f67b92 --- /dev/null +++ b/web/test/stageDefinition.test.mjs @@ -0,0 +1,23 @@ +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { stageSource } from "../src/stageDefinition.js"; + +test("source slices preserve authored CRLF, whitespace, custom blocks and shorthand", () => { + const first = " # stage one\r\n\r\n```custom\r\nhello\r\n```\r\n```edges\r\nsuccess -> #\r\n```\r\n\r\n"; + const last = "# stage two\r\n```prompt\r\nlast\r\n```"; + assert.equal(stageSource(first + last, "one"), first); + assert.equal(stageSource(first + last, "two"), last); +}); + +test("stage-like lines inside blocks do not terminate or create source ranges", () => { + const source = "# stage one\n```prompt\n# stage two\n```js\ntext\n```\n\n"; + assert.equal(stageSource(source + "# stage two\n", "one"), source); + assert.equal(stageSource(source, "two"), null); +}); + +test("missing source, absent stages and terminals never produce guessed definitions", () => { + for (const source of [undefined, null, "", "# stage one\n"]) { + assert.equal(stageSource(source, "missing"), null); + assert.equal(stageSource(source, "#success"), null); + } +}); diff --git a/web/test/ui-stage-definition.mjs b/web/test/ui-stage-definition.mjs new file mode 100644 index 00000000..41e4bf9a --- /dev/null +++ b/web/test/ui-stage-definition.mjs @@ -0,0 +1,134 @@ +// Scratch-only browser proof: real views/modal/graph, deterministic get_pipeline +// fixture. No deployed service, socket, workflow, model or device is contacted. +import assert from "node:assert/strict"; +import { createServer } from "node:http"; +import { readFile, mkdir } from "node:fs/promises"; +import { resolve, extname } from "node:path"; +import { fileURLToPath } from "node:url"; +import { launchChrome } from "./browser.mjs"; + +const root = fileURLToPath(new URL("../", import.meta.url)); +const out = resolve(process.argv[2] || ".ui-stage-definition"); +await mkdir(out, { recursive: true }); +const source = "# stage review\n\n```prompt\nReview **the change**.\n# stage not-a-node\n```\n\n```custom\nPreserve this authored block.\n```\n\n```edges\nsuccess -> #\n```\n\n"; +const html = `Stage definition scratch proof +${["design/tokens/tokens", "base", "shell", "lists", "run-detail", "chat", "graph", "dialogs"].map(name => ``).join("")} +

Scratch stage definition proof

+`; +const server = createServer(async (req, res) => { + try { + if (req.url === "/") { res.setHeader("content-type", "text/html"); res.end(html); return; } + const path = resolve(root, `.${new URL(req.url, "http://scratch").pathname}`); + if (!path.startsWith(root)) { res.writeHead(403); res.end(); return; } + res.setHeader("content-type", extname(path) === ".css" ? "text/css" : "text/javascript"); + res.end(await readFile(path)); + } catch { res.writeHead(404); res.end(); } +}); +await new Promise(resolve => server.listen(0, "127.0.0.1", resolve)); +let browser; +try { + browser = await launchChrome(); + const page = await browser.openPage(`http://127.0.0.1:${server.address().port}/`); + const capture = async (name) => { + await page.evaluate('Promise.all(document.getAnimations().filter(a => a.effect.getTiming().iterations !== Infinity).map(a => a.finished.catch(() => {})))'); + await page.screenshot(resolve(out, name)); + }; + await page.waitForSelector('.graph-node[data-key="review"]'); + const clickNode = async () => { + await page.evaluate('new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)))'); + await page.click('.graph-node[data-key="review"]'); + await page.waitForSelector('.stage-definition-document .field-markdown'); + }; + await clickNode(); + assert.deepEqual(await page.evaluate('requests'), [{ id: 7, version: 3 }]); + assert.equal(await page.evaluate('document.querySelector(".app-root").inert'), true); + await capture("01-run-definition-rendered.png"); + await page.clickText('.audit-doc-mode', 'Raw'); + assert.equal(await page.evaluate('document.querySelector(".stage-definition-document code").textContent === expectedSource'), true); + assert.equal(await page.evaluate('document.activeElement.textContent'), 'Raw'); + await capture("02-run-definition-raw.png"); + for (let i = 0; i < 8; i++) { + await page.pressKey('Tab'); + assert.equal(await page.evaluate('document.querySelector(".audit-viewer").contains(document.activeElement)'), true); + } + await page.pressKey('Escape'); + assert.equal(await page.evaluate('document.activeElement.dataset.key'), 'review'); + assert.equal(await page.evaluate('location.pathname'), '/'); + assert.deepEqual(await page.evaluate('routes'), []); + await page.evaluate("show('pipeline')"); + await clickNode(); + assert.deepEqual(await page.evaluate('routes'), []); + assert.equal(await page.evaluate('requests.length'), 1); + await capture("03-pipeline-definition-rendered.png"); + await page.click('.audit-close'); + await page.evaluate("show('run');pane()"); + await page.click('.audit-open'); + await page.click('[data-audit-tab="definition"]'); + await page.waitForSelector('.stage-definition-document .field-markdown'); + assert.deepEqual(await page.evaluate('rt.modal.stackIds()'), ['stage-pane','stage-audit']); + await capture("04-visit-definition-nested.png"); + await page.pressKey('Escape'); + assert.equal(await page.evaluate('!!document.querySelector(".stage-pane")'), true); + assert.equal(await page.evaluate('document.activeElement.classList.contains("audit-open")'), true); + await page.evaluate("show('run');window.missing=true"); + await page.evaluate('new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)))'); + await page.click('.graph-node[data-key="review"]'); + await page.waitForText('No definition has been reconstructed.'); + await capture("05-definition-missing-source.png"); + await page.evaluate("show('run');window.missing=false;window.fail=true"); + await page.evaluate('new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)))'); + await page.click('.graph-node[data-key="review"]'); + await page.waitForText('fixture refusal'); + await capture("06-definition-load-failed.png"); + await page.evaluate("show('run');window.fail=false"); + await page.evaluate('new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)))'); + await page.click('.graph-node[data-key="#success"]'); + await page.waitForText('Terminal nodes have no authored stage definition.'); + await capture("07-definition-terminal.png"); + await page.evaluate("show('run')"); + await clickNode(); + await page.resize(390, 844); + await capture("08-definition-narrow.png"); + await page.resize(1440, 900); + await page.evaluate("show('run');window.delay=true"); + await page.evaluate('new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)))'); + await page.click('.graph-node[data-key="review"]'); + await page.waitForText('Loading stage definition…'); + await capture("09-definition-loading.png"); + await page.clickText('.audit-doc-mode', 'Raw'); + await page.evaluate('release()'); + await page.waitForSelector('.stage-definition-document code'); + assert.equal(await page.evaluate('document.querySelector(".stage-definition-document code").textContent === expectedSource'), true); + await page.evaluate("show('run');window.delay=false;rt.state.runDetail.version=0;window.beforeRequests=requests.length"); + await page.evaluate('new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)))'); + await page.click('.graph-node[data-key="review"]'); + await page.waitForText('The run did not include its pipeline version.'); + assert.equal(await page.evaluate('requests.length === beforeRequests'), true); + await capture("10-definition-missing-version.png"); + console.log(`PASS: run/pipeline node popup, exact source, keyboard focus/escape, nested stage preservation, missing/error states; captures ${out}`); +} finally { + await browser?.close(); + await new Promise(resolve => server.close(resolve)); +}