web: show the turn files in the audit, with raw and rendered views

- The audit Input/Output/Memory tabs fetch the actual input.md/output.md/
  memory.md, so the outcome section is visible and each document has a
  Rendered/Raw switch plus an Open raw file link. The Session tab renders the
  exported HTML in place with the same link.
- The audit's selected tab uses the normal selected surface, not the accent tint.
- The run Summary no longer carries an Audit & debug section; the stage pane's
  Audit & debug button is the one door.
- Search results all lead with one 56px tile: image thumbnails, artifact type
  tiles, or a kind glyph (pipeline/version/run/step/field); no text kind labels.
- Chat star and more sit on the row's top-right and bottom-right corners, revealed
  on hover/focus, and the row menu opens below them without losing clicks.
- The chat spinner starts at the wall-clock animation phase, so frequent
  streaming re-renders no longer snap it back to the animation start.
This commit is contained in:
2026-10-20 01:15:09 +01:00
parent d130615fae
commit 2a8a5bf334
5 changed files with 232 additions and 88 deletions
+101 -65
View File
@@ -209,93 +209,131 @@ function latestVisitIndex(d, key) {
return Math.max(0, visits.length - 1);
}
/** The summary's Audit & debug section: one audit door per visit. */
function renderRunAuditSection(d) {
return renderCollapsible("summary-audit", "Audit & debug", () => {
const timeline = runTimeline(d.steps ?? []);
const body = h("div", { class: "audit-list" });
if (!timeline.entries.length) {
body.append(h("div", { class: "muted", text: EMPTY_TIMELINE_MESSAGE }));
return body;
}
for (const entry of timeline.entries) {
const used = systemArtifacts(entry.step).length;
const row = h("div", { class: "audit-row" });
row.append(
h("span", {
class: "audit-row-label",
text: `${entry.stageKey} · visit ${entry.visitIndex + 1}`,
}),
h("span", { class: "audit-row-meta muted", text: `${used} system file${used === 1 ? "" : "s"}` }),
);
const open = h("button", {
class: "ghost audit-open",
type: "button",
text: "Audit",
});
open.addEventListener("click", () => openAuditFor(d, entry.step, entry.stageKey, entry.visitIndex));
row.append(open);
body.append(row);
}
return body;
});
}
/** 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;
const fields = runStepFields(step);
const valueOf = (label) => fields.find((field) => field.label === label)?.value ?? "";
showStageAudit({
title: `${nodeLabel(stageKey)} audit`,
subtitle: `Visit ${visitIndex + 1} · ${runLabelFor(d)}`,
tabs: [
{ key: "input", label: "Input", body: () => auditDocument(valueOf("Input"), EMPTY_INPUT_MESSAGE) },
{ key: "output", label: "Output", body: () => auditDocument(valueOf("Output"), EMPTY_OUTPUT_MESSAGE) },
{ key: "memory", label: "Memory", body: () => auditMemory(step) },
{ key: "session", label: "Session", body: () => renderSessionExport(step) },
{ key: "input", label: "Input", body: () => auditArtifact(step, "input.md", EMPTY_INPUT_MESSAGE) },
{ 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) },
],
});
}
/** One audit tab body: a markdown document, or the honest empty sentence. */
function auditDocument(text, emptyMessage) {
const value = String(text ?? "").trim();
if (value === "") return h("div", { class: "muted", text: emptyMessage });
if (looksLikeMarkdown(value)) {
return h("div", { class: "audit-doc field-markdown" }, rt.views.chat.renderMarkdown(value));
/**
* One turn file in the audit: the raw bytes and the rendered markdown, with a
* Rendered/Raw switch and a link to the file on the server. The file is fetched
* (not the step's field map), so the outcome section is visible exactly as the
* stage wrote it.
*/
function auditArtifact(step, name, emptyMessage) {
const artifact = systemArtifacts(step).find((entry) => entry.name === name);
const wrap = h("div", { class: "audit-doc" });
if (!artifact) {
wrap.append(h("div", { class: "muted", text: emptyMessage }));
return wrap;
}
return h("pre", { class: "field-block" }, h("code", { text: value }));
}
/** The memory.md of this visit, rendered once it loads. */
function auditMemory(step) {
const artifact = systemArtifacts(step).find((entry) => entry.name === "memory.md");
if (!artifact) return h("div", { class: "muted", text: "No memory recorded for this visit." });
const resolved = resolvedArtifactUrl(artifact, state.url);
if (!resolved) return h("div", { class: "muted", text: ARTIFACT_SERVER_HINT });
const body = h("div", { class: "audit-doc" }, h("div", { class: "muted", text: "Loading memory…" }));
if (!resolved) {
wrap.append(h("div", { class: "muted", text: ARTIFACT_SERVER_HINT }));
return wrap;
}
let text = "";
let mode = "rendered";
const bar = h("div", { class: "audit-doc-bar" });
const toggle = h("div", { class: "audit-doc-toggle", role: "group", "aria-label": "Document view" });
const out = h("div", { class: "audit-doc-body" });
const draw = () => {
toggle.replaceChildren(
...[
["rendered", "Rendered"],
["raw", "Raw"],
].map(([key, label]) =>
h("button", {
class: `audit-doc-mode${mode === key ? " active" : ""}`,
type: "button",
"aria-pressed": mode === key ? "true" : "false",
text: label,
onclick: () => {
mode = key;
draw();
},
}),
),
);
out.replaceChildren();
if (mode === "raw" || !looksLikeMarkdown(text)) {
out.append(h("pre", { class: "field-block" }, h("code", { text })));
return;
}
out.append(h("div", { class: "field-markdown" }, rt.views.chat.renderMarkdown(text)));
};
bar.append(
toggle,
h("a", {
class: "audit-doc-open",
href: resolved,
target: "_blank",
rel: "noreferrer",
text: "Open raw file",
}),
);
wrap.append(bar, out);
out.append(h("div", { class: "muted", text: "Loading…" }));
fetch(resolved)
.then((response) => {
if (!response.ok) throw new Error(`The server answered ${response.status}.`);
return response.text();
})
.then((text) => {
if (text.trim() === "") {
body.replaceChildren(h("div", { class: "muted", text: "No completed turns were recorded before this visit." }));
return;
}
const article = h("div", { class: "field-markdown" });
article.append(rt.views.chat.renderMarkdown(text));
body.replaceChildren(article);
.then((body) => {
text = body;
draw();
})
.catch((error) => {
body.replaceChildren(h("div", { class: "muted", text: describeError(error) }));
out.replaceChildren(h("div", { class: "muted", text: describeError(error) }));
});
return body;
return wrap;
}
/** The exported session, rendered in place, with the raw file one click away. */
function auditSession(step) {
const artifact = systemArtifacts(step).find((entry) => entry.name === "session.html");
if (!artifact) return renderSessionExport(step);
const resolved = resolvedArtifactUrl(artifact, state.url);
const wrap = h("div", { class: "audit-session" });
if (!resolved) {
wrap.append(h("div", { class: "muted", text: ARTIFACT_SERVER_HINT }));
return wrap;
}
wrap.append(
h(
"div",
{ class: "audit-doc-bar" },
h("a", {
class: "audit-doc-open",
href: resolved,
target: "_blank",
rel: "noreferrer",
text: "Open raw file",
}),
),
);
wrap.append(
h("iframe", {
class: "audit-session-frame",
src: resolved,
title: `Session export · ${step.stage}`,
sandbox: "",
}),
);
return wrap;
}
/** The stage's own definition (prompt, tools, configs, edges) in the audit. */
@@ -356,8 +394,6 @@ function renderRunSummaryTab(d, now) {
),
);
// Everything the system wrote for each visit, behind one explicit door.
wrap.append(renderRunAuditSection(d));
return wrap;
}