web: put the work first and the audit evidence behind a door

- Turn files (input/memory/output/session) are system artifacts now: they are
  never tiles in the run or stage galleries. Shared public files are attributed
  to the visit that first recorded them, so a run counts 3 stage artifacts, not
  one copy of each per later stage.
- Audit & debug opens a dialog with vertical Input / Output / Memory / Session /
  Definition tabs, for a visit from the stage pane or the run Summary.
- Run tabs are Summary / Graph / Timeline; Input and Output are Summary sections
  with Artifacts, Files changed and Audit. Each stage pane gains Files changed.
- Artifacts gain a gallery/list switch (remembered) and full-name wrapping; the
  copy/share actions are hover-or-focus icon buttons.
- Status badge above the run title; no live badges on the run surfaces. The runs
  list leads with the pipeline name and the stored task title beneath it.
- Chat rows: title + coloured status word only, then directory, then model; no
  operator or closed chips, no dot. The more/star cluster is a hover/focus
  overlay so the title uses the row's width, and an open menu stacks above rows.
  Closed chats collapse behind a chevron. Sessions can be starred locally and
  sort in a Starred group. The chat header no longer repeats status/dir/model.
- A visible rail divider separates Search from the destinations; the page has a
  real favicon/apple-touch icon and the rail brand wears it.
- Smoke updated: no live badges, 3 detail tabs, field hits open Summary sections,
  closed chats expand for checks, the fixture viewer uses shot.png/missing.txt
  and the audit for markdown.
This commit is contained in:
2026-10-20 01:00:01 +01:00
parent ca28d08269
commit d130615fae
25 changed files with 1167 additions and 366 deletions
+17 -1
View File
@@ -26,6 +26,8 @@ import {
import { SERVER_URL_STORAGE_KEY, readServerUrl, readWorkspace, writeServerUrl } from "./settings.js";
import { layoutGraph } from "./graph.js";
import { readGraphExpanded } from "./graphPrefs.js";
import { readArtifactView } from "./artifactViewPrefs.js";
import { readChatStars } from "./chatStars.js";
import { DEFAULT_ROUTE, parseRoute, serializeRoute } from "./routes.js";
import { EMPTY_PIPELINE_FILTERS, PIPELINE_DETAIL_TABS } from "./pipelines.js";
import {
@@ -158,6 +160,12 @@ const state = {
pipelineGraph: null,
// Expanded by default; a collapse is remembered (graphPrefs.js).
pipelineGraphExpanded: readGraphExpanded(),
// Gallery or list for run artifacts; a per-operator choice (artifactViewPrefs.js).
artifactView: readArtifactView(),
// Starred chat sessions (chatStars.js): local, always sorted first.
chatStars: readChatStars(),
// Whether the CLOSED chats group is expanded (the chevron beside its name).
chatClosedOpen: false,
// The mounted run-mode graph (R5) on the run detail's Graph tab. Dropped on
// every re-render and on a run change, so its wheel/pointer/resize listeners
// and its elapsed timer can never leak.
@@ -503,10 +511,18 @@ const appRail = h(
h(
"div",
{ class: "rail-brand" },
h("span", { class: "rail-brand-mark", "aria-hidden": "true", text: "P" }),
h("img", {
class: "rail-brand-icon",
src: "/favicon.svg",
alt: "",
width: "26",
height: "26",
"aria-hidden": "true",
}),
h("span", { text: "Pipelines" }),
),
railSearch,
h("div", { class: "rail-divider rail-divider-visible", role: "presentation" }),
railDestinations,
h("div", { class: "rail-divider", role: "presentation" }),
railSections,
+20
View File
@@ -0,0 +1,20 @@
// The run artifacts' view preference: a gallery of tiles (the default) or a
// compact list. It belongs to the operator, not the run, so it survives reloads.
export const ARTIFACT_VIEW_KEY = "pipelines.web.artifactView.v1";
export function readArtifactView(storage = globalThis.localStorage) {
try {
return storage?.getItem(ARTIFACT_VIEW_KEY) === "list" ? "list" : "gallery";
} catch {
return "gallery";
}
}
export function writeArtifactView(value, storage = globalThis.localStorage) {
try {
storage?.setItem(ARTIFACT_VIEW_KEY, value === "list" ? "list" : "gallery");
} catch {
// Storage may be unavailable; the in-memory choice still applies.
}
}
+73 -7
View File
@@ -145,6 +145,34 @@ export function presentedArtifacts(step) {
);
}
/**
* The files the turn protocol itself writes for every visit. They are audit
* evidence, not stage output: the artifact surfaces lead with what the stage
* actually produced, and these live behind Audit & debug. Names are the exact
* server-recorded ones.
*/
export const SYSTEM_ARTIFACT_NAMES = Object.freeze([
"input.md",
"memory.md",
"output.md",
"session.html",
]);
/** True for a turn-owned file (input/memory/output/session). Pure. */
export function isSystemArtifact(artifact) {
return SYSTEM_ARTIFACT_NAMES.includes(String(artifact?.name ?? ""));
}
/** A visit's stage-produced artifacts: everything except the system files. */
export function stageArtifacts(step) {
return presentedArtifacts(step).filter((artifact) => !isSystemArtifact(artifact));
}
/** A visit's system files, newest-listing order preserved. */
export function systemArtifacts(step) {
return presentedArtifacts(step).filter(isSystemArtifact);
}
/** How many files the capture excluded for `step` (absent means none). */
export function artifactsSkipped(step) {
return Number(step?.artifacts_skipped ?? 0) || 0;
@@ -253,8 +281,34 @@ export function displayVisit(step, index) {
return Number(visit) > 0 ? Number(visit) : index + 1;
}
/** True for a shared public file's recorded name (`public/...`). */
function isPublicName(name) {
return String(name ?? "").startsWith("public/");
}
/**
* Groups a run's artifacts by stage and visit. Stages keep first-appearance
* A visit's stage artifacts, with each shared public file attributed to the first
* visit that recorded it. The server records the whole public directory on every
* model visit so a resume can rebuild each turn's file list; the artifact surface
* must not repeat every shared file once per later stage.
*/
export function visitArtifacts(step, runSteps) {
const all = stageArtifacts(step);
if (!step || !runSteps?.length) return all;
const seen = new Set();
const ordered = [...runSteps].sort((a, b) => (a?.sequence ?? 0) - (b?.sequence ?? 0));
for (const candidate of ordered) {
if (candidate === step || candidate?.sequence === step.sequence) break;
for (const artifact of stageArtifacts(candidate)) {
if (isPublicName(artifact?.name)) seen.add(artifact.name);
}
}
return all.filter((artifact) => !isPublicName(artifact?.name) || !seen.has(artifact.name));
}
/**
* Groups a run's artifacts by stage and visit, attributing each shared public file
* to the visit that first recorded it. Stages keep first-appearance
* order and each stage's visits are ordered by sequence, with the display visit
* number above. Only visits that recorded at least one presented artifact
* produce a group, so an empty capture never yields an empty group and an
@@ -266,6 +320,18 @@ export function artifactGroups(steps) {
if (list.length === 0) return [];
// groupBy(stage) keeps first-appearance order (a Map preserves insertion
// order); each stage's visits are then ordered by sequence.
const orderedSteps = [...list].sort((a, b) => (a?.sequence ?? 0) - (b?.sequence ?? 0));
const attributed = new Map();
const seenPublic = new Set();
for (const step of orderedSteps) {
const artifacts = stageArtifacts(step).filter((artifact) => {
if (!isPublicName(artifact?.name)) return true;
if (seenPublic.has(artifact.name)) return false;
seenPublic.add(artifact.name);
return true;
});
attributed.set(step, artifacts);
}
const visitsByStage = new Map();
for (const step of list) {
const stage = step?.stage ?? "";
@@ -276,7 +342,7 @@ export function artifactGroups(steps) {
for (const [stageKey, visits] of visitsByStage) {
const ordered = [...visits].sort((a, b) => (a?.sequence ?? 0) - (b?.sequence ?? 0));
ordered.forEach((step, index) => {
const artifacts = presentedArtifacts(step);
const artifacts = attributed.get(step) ?? [];
if (artifacts.length === 0) return;
groups.push({ stageKey, visit: displayVisit(step, index), artifacts });
});
@@ -306,7 +372,7 @@ export function artifactsEmptyMessage(executing) {
*/
export function artifactsHeader(steps, executing) {
const list = steps ?? [];
const recorded = list.reduce((sum, step) => sum + presentedArtifacts(step).length, 0);
const recorded = artifactGroups(list).reduce((sum, group) => sum + group.artifacts.length, 0);
if (recorded === 0) return artifactsEmptyMessage(executing);
const partial = list.some((step) => artifactsSkipped(step) > 0 || artifactsTruncated(step) > 0);
let label = `${recorded === 1 ? "Artifact" : "Artifacts"} · ${recorded} recorded`;
@@ -320,13 +386,13 @@ export function artifactsHeader(steps, executing) {
* otherwise the recorded count plus " · partial capture" when files were
* excluded or omitted. Mirrors Format.kt artifactsSummary.
*/
export function artifactsSummary(step) {
const artifacts = presentedArtifacts(step);
if (artifacts.length === 0) {
export function artifactsSummary(step, count = null) {
const recorded = count ?? stageArtifacts(step).length;
if (recorded === 0) {
const state = step?.status === "running" ? ARTIFACT_CAPTURE_PENDING : "not recorded for this visit";
return `Artifacts · ${state}`;
}
let label = `Artifacts · ${artifacts.length} recorded`;
let label = `Artifacts · ${recorded} recorded`;
if (artifactsSkipped(step) > 0 || artifactsTruncated(step) > 0) label += " · partial capture";
return label;
}
+1 -1
View File
@@ -560,7 +560,7 @@ export function sessionActivityBadge(activity, open) {
if (activity === "streaming") return "Streaming";
if (activity === "new") return "New";
if (activity === "idle" && open) return "Open";
return null;
return "Idle";
}
/**
+22
View File
@@ -0,0 +1,22 @@
// The operator's starred chats. A star is a local preference, not part of the
// server's chat record, so it survives reloads on this device and never mutates
// the session. Starred sessions sort above everything else.
export const CHAT_STARS_KEY = "pipelines.web.chatStars.v1";
export function readChatStars(storage = globalThis.localStorage) {
try {
const parsed = JSON.parse(storage?.getItem(CHAT_STARS_KEY) ?? "[]");
return new Set(Array.isArray(parsed) ? parsed.filter((id) => typeof id === "string" && id !== "") : []);
} catch {
return new Set();
}
}
export function writeChatStars(stars, storage = globalThis.localStorage) {
try {
storage?.setItem(CHAT_STARS_KEY, JSON.stringify([...stars]));
} catch {
// Storage may be unavailable; the in-memory choice still applies.
}
}
+22 -27
View File
@@ -27,8 +27,8 @@ import {
formatLocalTimestamp,
runStateOf,
} from "./runs.js";
import { presentedArtifacts, sessionExportArtifact, displayVisit } from "./artifacts.js";
import { changeStat, parseUnifiedPatch } from "./changes.js";
import { presentedArtifacts, sessionExportArtifact, stageArtifacts, visitArtifacts, displayVisit } from "./artifacts.js";
import { changeStat, parseUnifiedPatch, runChanges, runChangesHeader } from "./changes.js";
import { effectiveStageType } from "./templates.js";
// ---------------------------------------------------------------------------
@@ -49,8 +49,16 @@ export const RUN_DETAIL_TABS = [
{ key: "steps", label: "Timeline" },
];
/** The tabs the browser renders: all of them, including the Graph body (R5). */
export const RENDERED_RUN_TABS = RUN_DETAIL_TABS;
/**
* The tabs the browser renders. Input and Output are run Summary sections now
* (alongside Artifacts and Files changed), not separate tabs; the stable keys
* `input`/`output` remain in RUN_DETAIL_TABS for Android parity and old routes.
*/
export const RENDERED_RUN_TABS = [
{ key: "summary", label: "Summary" },
{ key: "graph", label: "Graph" },
{ key: "steps", label: "Timeline" },
];
// The empty-state sentences, exactly as the app spells them.
export const EMPTY_INPUT_MESSAGE = "No input recorded.";
@@ -640,34 +648,21 @@ export function looksLikeMarkdown(value) {
return /^#{1,6}\s/m.test(text) || /```/.test(text) || /^\s*(?:[-*]|\d+\.)\s+/m.test(text) || /^\|.+\|/m.test(text);
}
export function stageSectionSpecs(stageKey, graph, runSteps, visitIndex, runContext) {
/**
* The stage pane's body sections for one visit: what the stage produced (its
* non-system artifacts) and what it changed. The turn files, session export and
* stage definition live behind Audit & debug, so the pane stays about the work.
*/
export function stageSectionSpecs(stageKey, graph, runSteps, visitIndex, runContext, allSteps = null) {
const specs = [];
const stage = (graph?.stages ?? []).find((candidate) => candidate?.key === stageKey);
const definition = stage ? stageDefinitionFields(stage) : terminalFields(graph, stageKey);
const steps = runSteps ?? [];
const selectedStep = steps[clampVisitIndex(visitIndex, steps.length)];
if (runContext && selectedStep != null) {
const runFields = runStepFields(selectedStep);
const session = sessionExportArtifact(selectedStep) != null;
// The collapsible's title carries the count so the operator sees how many
// artifacts this visit recorded without expanding it.
const presented = presentedArtifacts(selectedStep).length;
const artifactsTitle = `${STAGE_ARTIFACTS_TITLE} · ${presented} recorded`;
specs.push({ key: "artifacts", title: artifactsTitle, fields: [], artifacts: true, session: false });
if (session) {
specs.push({ key: "session", title: STAGE_SESSION_TITLE, fields: [], artifacts: false, session: true });
const used = visitArtifacts(selectedStep, allSteps ?? steps).length;
specs.push({ key: "artifacts", title: `${STAGE_ARTIFACTS_TITLE} · ${used} recorded`, artifacts: true });
if (selectedStep.file_changes != null) {
specs.push({ key: "changes", title: runChangesHeader(runChanges([selectedStep])), changes: true });
}
const output = runFields.filter((entry) => entry.label === "Output");
if (output.length > 0) specs.push({ key: "output", title: "Output", fields: output, artifacts: false, session: false });
const input = runFields.filter((entry) => entry.label === "Input");
if (input.length > 0) specs.push({ key: "input", title: "Input", fields: input, artifacts: false, session: false });
const evidence = evidenceFields(runFields);
if (evidence.length > 0) {
specs.push({ key: "run", title: STAGE_EVIDENCE_TITLE, fields: evidence, artifacts: false, session: false });
}
}
if (definition.length > 0) {
specs.push({ key: "definition", title: STAGE_DEFINITION_TITLE, fields: definition, artifacts: false, session: false });
}
return specs;
}
+70 -57
View File
@@ -3,7 +3,8 @@
// slash commands, notices and the local rename/hide/seen store. Pure models live
// in chat.js and markdown.js; this module owns the DOM and the chat wire wiring.
import { h, renderLiveBadge } from "../dom.js";
import { h } from "../dom.js";
import { writeChatStars } from "../chatStars.js";
import { describeError } from "../format.js";
import { SHELL_OUTPUT_LIMIT, newChatOperationId } from "../repository.js";
import { codeBlockLabel, parseInline, parseMarkdown } from "../markdown.js";
@@ -89,13 +90,11 @@ import {
chatCreateSucceeded,
chatFirstScroll,
chatFollowsAt,
chatHeaderMeta,
chatNoMatchMessage,
chatNoticeLabel,
chatOpensAtNewest,
chatShowJumpToLatest,
chatStartInLabel,
chatStreamState,
closeChatConfirmation,
composerAction,
composerCanSend,
@@ -135,9 +134,6 @@ import {
seedChatSeen,
sessionActivity,
sessionActivityBadge,
sessionChipLabel,
sessionMeta,
sessionStatusLabel,
selectChatDirectory as selectChatDirectoryModel,
sessionTitle,
sessionWorkLabel,
@@ -1532,11 +1528,20 @@ function fillChatRows(rows) {
return;
}
const active = filtered.filter((session) => !session.closed);
const starred = filtered.filter(
(session) => !session.closed && state.chatStars?.has?.(session.id) === true,
);
const active = filtered.filter(
(session) => !session.closed && state.chatStars?.has?.(session.id) !== true,
);
const closed = filtered.filter((session) => session.closed);
// Titles are often repeated ("New chat"); compute the duplicates once so the
// per-row actions name can include the session id only when it is needed.
const duplicateTitles = duplicateChatTitles(filtered);
if (starred.length > 0) {
rows.append(h("div", { class: "chat-group-header", text: "Starred" }));
for (const session of starred) rows.append(renderChatRow(session, duplicateTitles));
}
const groups = groupSessionsByDirectory(active);
if (groups.length > 1) {
for (const group of groups) {
@@ -1547,8 +1552,25 @@ function fillChatRows(rows) {
for (const session of active) rows.append(renderChatRow(session, duplicateTitles));
}
if (closed.length > 0) {
rows.append(h("div", { class: "chat-group-header", text: CLOSED_SECTION_LABEL }));
for (const session of closed) rows.append(renderChatRow(session, duplicateTitles));
const open = state.chatClosedOpen === true;
const toggle = h("button", {
class: "chat-group-toggle",
type: "button",
"aria-expanded": open ? "true" : "false",
"aria-label": `${open ? "Collapse" : "Expand"} ${CLOSED_SECTION_LABEL.toLowerCase()} chats`,
});
toggle.append(
h("span", { class: "chat-group-label", text: CLOSED_SECTION_LABEL }),
h("span", { class: "chevron", text: open ? "\u25be" : "\u25b8" }),
);
toggle.addEventListener("click", () => {
state.chatClosedOpen = !open;
renderContent();
});
rows.append(toggle);
if (open) {
for (const session of closed) rows.append(renderChatRow(session, duplicateTitles));
}
}
if (state.chatError) {
rows.append(h("div", { class: "chat-error muted", text: state.chatError }));
@@ -1571,6 +1593,16 @@ function chatEmpty(message) {
return h("div", { class: "empty" }, h("span", { class: "muted", text: message }));
}
/** Toggle one session's local star, then repaint the list in its new order. */
function toggleChatStar(id) {
const next = new Set(state.chatStars ?? []);
if (next.has(id)) next.delete(id);
else next.add(id);
state.chatStars = next;
writeChatStars(next);
renderContent();
}
/**
* One session row: title, kind chip, a Closed chip only when closed, the
* activity badge word, the work-label meta line and the close/reopen action.
@@ -1591,7 +1623,7 @@ function renderChatRow(session, duplicateTitles = new Set()) {
// The row is a plain container (M6): the session title/meta area is the native
// button and the Chat actions control is its sibling, not a child.
const row = h("div", {
class: `row chat-row${open ? " selected" : ""}`,
class: `row chat-row${open ? " selected" : ""}${state.chatMenu === session.id ? " menu-open" : ""}`,
"data-session": session.id,
});
// Keep background and programmatic clicks opening the session, but never
@@ -1611,24 +1643,22 @@ function renderChatRow(session, duplicateTitles = new Set()) {
});
const head = h("span", { class: "row-head" });
head.append(h("span", { class: "row-title chat-row-title", text: sessionTitle(session) }));
const chip = sessionChipLabel(session);
if (chip) head.append(h("span", { class: "chip chat-kind-chip", text: chip }));
if (session.closed) head.append(h("span", { class: "chip chat-closed-chip", text: CLOSED_CHIP_LABEL }));
if (badge) {
head.append(
h("span", { class: `chat-activity chat-activity-${activity}` },
h("span", { class: "chat-activity-dot", "aria-hidden": "true" }),
h("span", { class: "chat-activity-word", text: badge }),
),
);
// Only the status word, coloured, with no dot and no operator chip. A closed
// session says so here instead of carrying a second chip.
const statusWord = session.closed ? "Closed" : badge;
const statusClass = session.closed ? "chat-activity-closed" : `chat-activity-${activity}`;
if (statusWord) {
head.append(h("span", { class: `chat-activity ${statusClass}`, text: statusWord }));
}
sessionButton.append(head);
sessionButton.append(
h("span", {
class: "row-meta chat-row-meta",
text: sessionMeta(session, sessionWorkLabel(session.busy === true, thread)),
}),
);
const directory = String(session.directory ?? "").trim();
if (directory !== "") {
sessionButton.append(h("span", { class: "row-meta chat-row-meta", text: directory }));
}
const model = String(session.model ?? "").trim();
if (model !== "") {
sessionButton.append(h("span", { class: "row-meta chat-row-model muted", text: model }));
}
row.append(sessionButton, renderChatActionsMenu(session, duplicateTitles));
return row;
}
@@ -1759,6 +1789,20 @@ function renderChatCreate() {
*/
function renderChatActionsMenu(session, duplicateTitles = new Set()) {
const wrap = h("div", { class: "chat-row-actions chat-menu-wrap" });
const starred = state.chatStars?.has?.(session.id) === true;
const star = h("button", {
class: `ghost chat-star${starred ? " starred" : ""}`,
type: "button",
text: starred ? "\u2605" : "\u2606",
"aria-pressed": starred ? "true" : "false",
"aria-label": starred ? "Unstar chat" : "Star chat",
title: starred ? "Unstar chat" : "Star chat",
});
star.addEventListener("click", (event) => {
event.stopPropagation();
toggleChatStar(session.id);
});
wrap.append(star);
const expanded = state.chatMenu === session.id;
const title = sessionTitle(session);
const actionLabel = duplicateTitles.has(title)
@@ -1851,12 +1895,6 @@ function renderChatConversation() {
// The open conversation is the route's one h1; the list heading above becomes
// its h2 while the detail is open.
titles.append(h("h1", { class: "chat-bar-title", id: "detailTitle", tabindex: "-1", text: title }));
const meta = chatHeaderMeta({
model: session?.model,
tag: session?.tag,
directory: session?.directory,
});
if (meta !== "") titles.append(h("div", { class: "chat-bar-meta muted", text: meta }));
bar.append(titles);
if (thread?.hasMore) {
bar.append(
@@ -1875,31 +1913,6 @@ function renderChatConversation() {
if (awaiting) bar.append(approvalJumpButton());
pane.append(bar);
// The context line: the kind chip, the activity word and directory · model.
const context = h("div", { class: "chat-context" });
const chip = session ? sessionChipLabel(session) : null;
if (chip) context.append(h("span", { class: "chip chat-kind-chip", text: chip }));
context.append(
h("span", {
class: "chat-context-activity",
text: sessionStatusLabel(thread?.running === true, session?.closed === true),
}),
);
// The live-stream badge (C5): live while this session is subscribed, the same
// words as the run badge (`live` / `reconnecting` / `not live`).
context.append(
renderLiveBadge({
...chatStreamState(state.connection.kind, state.chatSubscriptions.has(state.chatActiveId)),
title: "Live chat stream",
}),
);
const contextMeta = [session?.directory, session?.model]
.map((value) => String(value ?? "").trim())
.filter((value) => value !== "")
.join(" · ");
if (contextMeta !== "") context.append(h("span", { class: "chat-context-meta muted", text: contextMeta }));
pane.append(context);
// The background-tasks bar (C11) sits above the transcript, outside the
// scroller so the C14 scroll positions are untouched. It is present only while
// a shell is still running and disappears with the last exit.
+100
View File
@@ -816,6 +816,105 @@ function openArtifactViewer(viewable, startIndex, trigger = null) {
});
}
/**
* The Audit & debug dialog: a stage's turn-owned evidence behind vertical tabs
* (Input, Output, Memory, Session, Stage definition), the chosen section's body
* on the right. It is the only place the system files are shown, so the artifact
* surfaces stay focused on what the stage actually produced.
*/
function openStageAudit({ title = "Audit", subtitle = "", tabs = [], trigger = null } = {}) {
const available = (tabs ?? []).filter((tab) => typeof tab?.body === "function");
if (!available.length) return;
const close = () => modal.close("stage-audit");
const overlay = h("div", {
class: "audit-viewer",
role: "dialog",
"aria-modal": "true",
"aria-label": title,
});
overlay.addEventListener("click", (event) => {
if (event.target === overlay) close();
});
const closeButton = h("button", {
class: "audit-close",
type: "button",
text: "Close",
onclick: close,
});
const panel = h("div", { class: "audit-panel" });
panel.append(
h(
"div",
{ class: "audit-head" },
h(
"div",
{ class: "audit-titles" },
h("h2", { class: "audit-title", text: title }),
subtitle ? h("p", { class: "audit-subtitle muted", text: subtitle }) : null,
),
closeButton,
),
);
const nav = h("nav", {
class: "audit-tabs",
role: "tablist",
"aria-orientation": "vertical",
"aria-label": "Audit sections",
});
const body = h("div", {
class: "audit-body",
id: "auditBody",
role: "tabpanel",
tabindex: "0",
});
panel.append(h("div", { class: "audit-layout" }, nav, body));
overlay.append(panel);
let active = available[0].key;
const renderTabs = () => {
nav.replaceChildren(
...available.map((tab) => {
const selected = tab.key === active;
return h("button", {
class: `audit-tab${selected ? " active" : ""}`,
type: "button",
role: "tab",
"aria-selected": selected ? "true" : "false",
"aria-controls": "auditBody",
"data-audit-tab": tab.key,
tabindex: selected ? "0" : "-1",
text: tab.label,
onclick: () => {
active = tab.key;
renderTabs();
},
onkeydown: (event) => {
const index = available.findIndex((entry) => entry.key === tab.key);
let next = -1;
if (event.key === "ArrowDown") next = (index + 1) % available.length;
else if (event.key === "ArrowUp") next = (index - 1 + available.length) % available.length;
else if (event.key === "Home") next = 0;
else if (event.key === "End") next = available.length - 1;
if (next < 0) return;
event.preventDefault();
active = available[next].key;
renderTabs();
nav.querySelector(`[data-audit-tab="${active}"]`)?.focus();
},
});
}),
);
const current = available.find((tab) => tab.key === active) ?? available[0];
body.replaceChildren(current.body());
};
renderTabs();
modal.open("stage-audit", overlay, {
onClose: () => close(),
trigger,
fallbackSelectors: ["#detailTitle", "#pane-main"],
});
}
return {
closeChangeViewer,
openChangeViewer,
@@ -831,5 +930,6 @@ function openArtifactViewer(viewable, startIndex, trigger = null) {
dismissActionError,
closeArtifactViewer,
openArtifactViewer,
openStageAudit,
};
}
+289 -46
View File
@@ -3,9 +3,8 @@
// the run's artifact gallery. Pure models live in runDetail.js, changes.js,
// artifacts.js and actions.js; dialogs are delegated to dialogs.js.
import { h, kvMono, renderLiveBadge, canCopyLink, canShare, copyArtifactLink, shareArtifact } from "../dom.js";
import { h, kvMono, canCopyLink, canShare, copyArtifactLink, shareArtifact } from "../dom.js";
import { isExecuting, changeKindTone, describeError } from "../format.js";
import { liveBadgeState } from "../connection.js";
import { resolveArtifactUrl } from "../serverUrl.js";
import { runStateOf } from "../runs.js";
import { PIPELINE_GRAPH_EMPTY, RUN_GRAPH_MISSING, mount as mountGraph } from "../graph.js";
@@ -27,6 +26,8 @@ import {
headlineFields,
runStepFields,
stageSectionSpecs,
stageDefinitionFields,
terminalFields,
clampVisitIndex,
referencedVerdictArtifacts,
verdictReasonSegments,
@@ -50,8 +51,12 @@ import {
presentedArtifacts,
resolvedArtifactUrl,
sessionExportArtifact,
stageArtifacts,
systemArtifacts,
visitArtifacts,
viewerIndexByUrl,
} from "../artifacts.js";
import { writeArtifactView } from "../artifactViewPrefs.js";
import {
BINARY_DIFF_MESSAGE,
NO_LINE_CHANGES_MESSAGE,
@@ -105,6 +110,7 @@ export function createRunDetailView(rt) {
const renderConfirmDialog = (...args) => rt.views.dialogs.renderConfirmDialog(...args);
const renderActionFailedDialog = (...args) => rt.views.dialogs.renderActionFailedDialog(...args);
const openArtifactViewer = (...args) => rt.views.dialogs.openArtifactViewer(...args);
const showStageAudit = (...args) => rt.views.dialogs.openStageAudit(...args);
const selectPipeline = (...args) => rt.selectPipeline(...args);
/**
@@ -127,6 +133,14 @@ function renderRunDetail(now = Date.now()) {
// the Android run detail does, so opening the run is enough — no tab hunt.
const decision = pendingDecision(d);
if (decision) pane.append(renderDecisionCard(decision));
const status = runStateOf(d.status);
const kicker = h("div", { class: "run-kicker" });
kicker.append(h("span", { class: `chip chip-${status}`, text: d.status || status }));
if (String(d.outcome ?? "").trim()) {
kicker.append(h("span", { class: "muted", text: `outcome ${d.outcome}` }));
}
if (d.executing) kicker.append(h("span", { class: "muted", text: "executing" }));
pane.append(kicker);
pane.append(
h("h1", {
class: "run-detail-title",
@@ -195,17 +209,108 @@ function latestVisitIndex(d, key) {
return Math.max(0, visits.length - 1);
}
/** The Summary tab: identity, chip row, key/value rows, diagnostic and gallery. */
/** 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: "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));
}
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…" }));
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);
})
.catch((error) => {
body.replaceChildren(h("div", { class: "muted", text: describeError(error) }));
});
return body;
}
/** 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;
}
/** The Summary tab: identity, key/value rows, diagnostic and the sections. */
function renderRunSummaryTab(d, now) {
const wrap = h("div", { class: "run-tab-body" });
wrap.append(renderRunTitleRow(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" }));
chips.append(renderLiveBadge(liveBadgeState(state.runStream)));
wrap.append(chips);
wrap.append(h("div", { class: "run-identity muted", text: runIdentityLine(d) }));
const rows = h("div", { class: "kv" });
@@ -218,24 +323,41 @@ function renderRunSummaryTab(d, now) {
}
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.
// Stage-produced artifacts first: the turn's own input/memory/output/session
// files are audit evidence and live behind Audit & debug instead.
wrap.append(
renderCollapsible("summary-artifacts", artifactsHeader(d.steps ?? [], isExecuting(d)), () =>
renderArtifactGallery(d.steps ?? []),
renderCollapsible(
"summary-artifacts",
artifactsHeader(d.steps ?? [], isExecuting(d)),
() => renderArtifactGallery(d.steps ?? []),
{ actions: artifactViewToggle() },
),
);
// The run-level Changes (parity R4), collapsed by default like the Android
// summary: the observed final-state workspace diff. Only a succeeded run has a
// settled final state to present; a failed run keeps its evidence in each
// visit's own capture (a deliberate divergence from Android, see PARITY R4).
// The run-level Changes (parity R4): the observed final-state workspace diff.
// Only a succeeded run has a settled final state to present; a failed run keeps
// its evidence in each visit's own capture.
if (showRunChangesSummary(d.status)) {
const changes = runChanges(d.steps ?? []);
wrap.append(
renderCollapsible("summary-changes", runChangesHeader(changes), () => renderChangesBody(changes)),
);
}
// Input and Output are sections of the summary now, not tabs.
wrap.append(
renderCollapsible("summary-input", "Input", () =>
renderRunFieldBody(d.input, "input", EMPTY_INPUT_MESSAGE),
),
);
wrap.append(
renderCollapsible("summary-output", "Output", () =>
renderRunFieldBody(d.output, "output", EMPTY_OUTPUT_MESSAGE),
),
);
// Everything the system wrote for each visit, behind one explicit door.
wrap.append(renderRunAuditSection(d));
return wrap;
}
@@ -337,7 +459,12 @@ function renderStageField(field) {
/** 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" });
return h("div", { class: "run-tab-body" }, renderRunFieldBody(map, keyPrefix, emptyMessage));
}
/** The input/output body itself, shared by the old tab and the summary sections. */
function renderRunFieldBody(map, keyPrefix, emptyMessage) {
const wrap = h("div", { class: "run-field-body" });
const sections = fieldSections(map, keyPrefix);
if (!sections.length) {
wrap.append(h("div", { class: "run-empty muted", text: emptyMessage }));
@@ -363,10 +490,11 @@ function renderRunFieldTab(map, keyPrefix, emptyMessage) {
* 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) {
function renderCollapsible(key, title, bodyFn, { actions = null } = {}) {
const expanded = state.runSections.has(key);
const wrap = h("div", { class: "collapsible" });
wrap.append(
const head = h("div", { class: "section-row" });
head.append(
h(
"button",
{
@@ -384,6 +512,8 @@ function renderCollapsible(key, title, bodyFn) {
h("span", { class: "section-title", text: title }),
),
);
if (actions) head.append(actions);
wrap.append(head);
if (expanded) wrap.append(h("div", { class: "section-body" }, bodyFn()));
return wrap;
}
@@ -520,7 +650,7 @@ function renderStagePane(d) {
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 specs = stageSectionSpecs(stageKey, graph, runSteps, visitIndex, true, d.steps ?? []);
const fields = step ? runStepFields(step) : [];
const headline = headlineFields(fields);
@@ -560,7 +690,22 @@ function renderStagePane(d) {
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));
for (const spec of specs) body.append(renderStageSection(spec, step, d.steps ?? []));
if (step) {
body.append(
h(
"div",
{ class: "stage-pane-audit" },
h("button", {
class: "ghost audit-open",
type: "button",
text: "Audit & debug",
title: "Input, output, memory, session and definition",
onclick: () => openAuditFor(d, step, stageKey, visitIndex),
}),
),
);
}
overlay.append(h("div", { class: "stage-pane-sheet" }, bar, body));
modal.stage("stage-pane", overlay, {
onClose: () => closeStagePane(),
@@ -583,7 +728,7 @@ function renderStagePane(d) {
}
/** One stage-pane section, using the pane's own expansion state. */
function renderStageSection(spec, step) {
function renderStageSection(spec, step, allSteps = null) {
const expanded = state.runStageSections.has(spec.key);
const wrap = h("div", { class: "collapsible stage-section" });
wrap.append(
@@ -606,9 +751,9 @@ function renderStageSection(spec, step) {
);
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));
if (spec.artifacts && step) body.append(renderVisitArtifacts(step, allSteps));
else if (spec.changes && step) body.append(renderChangesBody(runChanges([step])));
else for (const field of spec.fields ?? []) body.append(renderStageField(field));
wrap.append(body);
return wrap;
}
@@ -857,13 +1002,48 @@ function artifactsResolvable() {
* run with no artifacts shows the header (which already says why) and nothing
* else, so the section is never blank.
*/
/** The gallery/list switch in the artifacts section header. */
function artifactViewToggle() {
const group = h("div", {
class: "view-toggle",
role: "group",
"aria-label": "Artifact view",
});
for (const [key, label] of [
["gallery", "Gallery"],
["list", "List"],
]) {
group.append(
h("button", {
class: `view-toggle-button${state.artifactView === key ? " active" : ""}`,
type: "button",
"aria-pressed": state.artifactView === key ? "true" : "false",
text: label,
onclick: () => {
state.artifactView = key;
writeArtifactView(key);
renderContent();
},
}),
);
}
return group;
}
function renderArtifactGallery(steps) {
const wrap = h("div", { class: "artifact-gallery" });
const groups = artifactGroups(steps);
if (!groups.length) return wrap;
if (!groups.length) {
wrap.append(h("div", { class: "muted artifact-hint", text: "No stage artifacts recorded." }));
return wrap;
}
if (!artifactsResolvable()) {
wrap.append(h("div", { class: "muted artifact-hint", text: ARTIFACT_SERVER_HINT }));
}
if (state.artifactView === "list") {
wrap.append(renderArtifactList(groups));
return wrap;
}
const viewable = pagedArtifacts(groups);
const viewerIndexOf = viewerIndexByUrl(groups);
for (const group of groups) {
@@ -875,6 +1055,48 @@ function renderArtifactGallery(steps) {
return wrap;
}
/** The list form of the run's artifacts: one full-name row per file. */
function renderArtifactList(groups) {
const list = h("div", { class: "artifact-list" });
const viewable = pagedArtifacts(groups);
const viewerIndexOf = viewerIndexByUrl(groups);
for (const group of groups) {
list.append(
h("div", { class: "artifact-group-head", text: `${group.stageKey} · visit ${group.visit}` }),
);
for (const artifact of group.artifacts) {
list.append(renderArtifactListRow(artifact, viewable, viewerIndexOf));
}
}
return list;
}
/** One artifact list row: kind, full name, size, and hover-only actions. */
function renderArtifactListRow(artifact, viewable, viewerIndexOf) {
const resolved = resolvedArtifactUrl(artifact, state.url);
const kind = artifactKind(artifact.content_type, artifact.name);
const media = kind === ArtifactKind.Image || kind === ArtifactKind.Video;
const opensViewer = isViewerArtifact(artifact.content_type, artifact.name);
const name = artifact.name || "(unnamed artifact)";
const wrap = h("div", { class: "artifact-list-row" });
const open = h("button", {
class: "artifact-list-open",
type: "button",
"aria-label": `Open ${name}`,
title: name,
});
open.append(h("span", { class: "artifact-kind", text: artifactKindLabel(kind) }));
open.append(h("span", { class: "artifact-list-name", text: name }));
open.append(h("span", { class: "artifact-size", text: humanBytes(artifact.size_bytes) }));
open.addEventListener("click", () => {
const at = viewerIndexOf.get(artifact.url);
if (opensViewer && at != null) openArtifactViewer(viewable, at, open);
else if (resolved) window.open(resolved, "_blank", "noopener,noreferrer");
});
wrap.append(open, renderTileActions(resolved, media));
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
@@ -882,12 +1104,14 @@ function renderArtifactGallery(steps) {
* that visit's viewable artifacts (media and markdown), exactly as the Android
* section does.
*/
function renderVisitArtifacts(step) {
function renderVisitArtifacts(step, allSteps = null) {
const wrap = h("div", { class: "artifacts" });
const artifacts = presentedArtifacts(step);
const artifacts = visitArtifacts(step, allSteps ?? [step]);
// The section title already carries the count, so the body repeats it only when
// there is nothing to show and the reason itself is the useful part.
if (artifacts.length === 0) wrap.append(h("div", { class: "artifacts-summary", text: artifactsSummary(step) }));
if (artifacts.length === 0) {
wrap.append(h("div", { class: "artifacts-summary", text: artifactsSummary(step, 0) }));
}
for (const note of artifactCaptureNotes(step)) {
wrap.append(h("div", { class: "artifacts-note muted", text: note }));
}
@@ -934,6 +1158,7 @@ function renderArtifactTile(artifact, viewable, viewerIndexOf) {
"data-artifact-name": artifact.name ?? "",
"data-artifact-kind": kind,
"data-artifact-url": artifact.url ?? "",
title: name,
});
const openViewer = () => {
const at = viewerIndexOf.get(artifact.url);
@@ -973,7 +1198,7 @@ function renderArtifactTile(artifact, viewable, viewerIndexOf) {
return wrap;
}
/** The compact per-tile actions: copy-link (non-media tiles) and share. */
/** The compact per-tile actions: icon-only link/share, shown on hover or focus. */
function renderTileActions(resolved, media) {
const actions = h("div", { class: "artifact-actions" });
const stop = (fn) => (event) => {
@@ -982,27 +1207,45 @@ function renderTileActions(resolved, media) {
};
if (!media) {
actions.append(
h("button", {
class: "artifact-action",
type: "button",
text: "Copy link",
disabled: !resolved || !canCopyLink(),
onclick: stop(() => copyArtifactLink(resolved)),
}),
artifactAction("link", "Copy link", !resolved || !canCopyLink(), stop(() => copyArtifactLink(resolved))),
);
}
actions.append(
h("button", {
class: "artifact-action",
type: "button",
text: "Share",
disabled: !resolved || !canShare(),
onclick: stop(() => shareArtifact(resolved)),
}),
artifactAction("share", "Share", !resolved || !canShare(), stop(() => shareArtifact(resolved))),
);
return actions;
}
const ARTIFACT_SVG_NS = "http://www.w3.org/2000/svg";
/** One icon-only artifact action (24px target, accessible name, hover-visible). */
function artifactAction(kind, label, disabled, onclick) {
const button = h("button", {
class: "artifact-action",
type: "button",
"aria-label": label,
title: label,
disabled,
onclick,
});
const svg = document.createElementNS(ARTIFACT_SVG_NS, "svg");
svg.setAttribute("viewBox", "0 0 24 24");
svg.setAttribute("aria-hidden", "true");
svg.setAttribute("focusable", "false");
const path = document.createElementNS(ARTIFACT_SVG_NS, "path");
path.setAttribute("d", kind === "link"
? "M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"
: "M4 12v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8M16 6l-4-4-4 4M12 2v13");
path.setAttribute("fill", "none");
path.setAttribute("stroke", "currentColor");
path.setAttribute("stroke-width", "2");
path.setAttribute("stroke-linecap", "round");
path.setAttribute("stroke-linejoin", "round");
svg.append(path);
button.append(svg);
return button;
}
/**
* The step's session export: a link opening the read-only session.html in a new
* tab, or the plain notice when the visit exported nothing (parity R9).
+7 -13
View File
@@ -2,7 +2,7 @@
// menus. The pure filtering, sorting and formatting live in runs.js; this module
// owns the DOM and the page's run-list state.
import { h, renderLiveBadge } from "../dom.js";
import { h } from "../dom.js";
import {
RUN_STATES,
RUN_TIME_RANGES,
@@ -23,7 +23,6 @@ import {
DEFAULT_RUN_SORT,
defaultRunFilters,
} from "../runs.js";
import { liveBadgeState } from "../connection.js";
export function createRunsView(rt) {
const { state } = rt;
@@ -128,19 +127,15 @@ function renderRunRow(run, now) {
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));
// The pipeline is the list's anchor: it names what ran, before the task title.
head.append(
h("span", { class: "run-row-pipeline-name", text: identity.pipeline ?? identity.label }),
);
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-title", text: identity.label }));
}
row.append(h("span", { class: "run-row-progress", text: progressText(run) }));
@@ -199,7 +194,6 @@ function renderRunToolbar() {
state.openMenu === "sort" ? renderSortMenu() : null,
),
h("span", { class: "spacer" }),
renderLiveBadge(liveBadgeState(state.runStream)),
);
return toolbar;
}
+7 -1
View File
@@ -592,7 +592,13 @@ async function routeSearchResult(hit) {
await selectRun(target.runId);
if (!state.runDetail) return;
const resolved = resolveRunTarget(target, target.runId, state.runDetail.steps ?? []);
if (resolved.tab) {
if (resolved.tab === "input" || resolved.tab === "output") {
// Input and Output are run Summary sections now, so a field hit opens the
// Summary with the matching section expanded rather than a dead tab.
state.runTab = "summary";
state.runSections = new Set([...state.runSections, `summary-${resolved.tab}`]);
renderContent();
} else if (resolved.tab) {
state.runTab = resolved.tab;
renderContent();
} else if (resolved.stageKey != null) {