web: open authored stage definitions in managed graph popup
This commit is contained in:
@@ -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);
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
+16
-15
@@ -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. */
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user