Merge branch 'main' into web-connection
Integrate main's run-detail Changes (R4) and Graph (R5) work with the connection banner/reconnect/foreground-recovery/live-badge work (T3/T4/T5). Conflicts resolved by keeping both independent additions: - web/styles.css: the .conn-*/.live-* rules and the .change-*/.diff-* rules are separate blocks; both retained under their own comment headers. - web/test/ui-smoke.mjs: both capture sequences retained (T3/T4/T5 writes 28-connected-banner/29-disconnected-banner/30-reconnect-recovered; R4/R5 writes its own distinct 28-34 run-change captures), so no filename collides. Checks after the merge: node --check on all touched JS/MJS; node --test test/ 225 pass / 0 fail; node test/ui-smoke.mjs --out <worktree>/captures UI SMOKE PASS against ws://127.0.0.1:8080/connect, including the connected banner + build line + live badge, the disconnected retry banner, the online-event recovery, and main's R4/R5 captures.
This commit is contained in:
+388
-14
@@ -34,6 +34,8 @@ import {
|
||||
} from "./artifacts.js";
|
||||
import {
|
||||
PIPELINE_GRAPH_EMPTY,
|
||||
RUN_GRAPH_MISSING,
|
||||
RUN_GRAPH_NOTE,
|
||||
mount as mountGraph,
|
||||
} from "./graph.js";
|
||||
import {
|
||||
@@ -97,6 +99,7 @@ import {
|
||||
runLabelFor,
|
||||
runDurationText,
|
||||
runTimeline,
|
||||
runGraphState,
|
||||
nodeLabel,
|
||||
headlineFields,
|
||||
runStepFields,
|
||||
@@ -107,6 +110,29 @@ import {
|
||||
outcomeColorToken,
|
||||
stateGlyph,
|
||||
} from "./runDetail.js";
|
||||
import {
|
||||
BINARY_DIFF_MESSAGE,
|
||||
NO_LINE_CHANGES_MESSAGE,
|
||||
TRUNCATED_PATCH_NOTE,
|
||||
ChangeKind,
|
||||
changeKindLabel,
|
||||
changeKindTitle,
|
||||
changePositionLabel,
|
||||
changeRowMeta,
|
||||
changeStat,
|
||||
changesListSummary,
|
||||
diffLineClass,
|
||||
diffLineSymbol,
|
||||
entryHasPatch,
|
||||
gutterText,
|
||||
gutterWidth,
|
||||
noChangeDetail,
|
||||
parseUnifiedPatch,
|
||||
patchUnavailableReason,
|
||||
runChanges,
|
||||
runChangesHeader,
|
||||
runChangesNote,
|
||||
} from "./changes.js";
|
||||
|
||||
const STORAGE_KEY = "pipelines.web.serverUrl.v2";
|
||||
|
||||
@@ -156,6 +182,10 @@ const state = {
|
||||
// handle is dropped on every re-render so its listeners can never leak.
|
||||
pipelineGraph: null,
|
||||
pipelineGraphExpanded: 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.
|
||||
runGraph: null,
|
||||
versionsExpanded: false,
|
||||
pipelinesLoaded: false,
|
||||
runsLoaded: false,
|
||||
@@ -311,6 +341,10 @@ function renderContent() {
|
||||
state.pipelineGraph.unmount();
|
||||
state.pipelineGraph = null;
|
||||
}
|
||||
if (state.runGraph) {
|
||||
state.runGraph.unmount();
|
||||
state.runGraph = null;
|
||||
}
|
||||
const nodes = [];
|
||||
if (state.error) {
|
||||
nodes.push(h("div", { class: "banner error" }, h("strong", { text: "Error: " }), state.error));
|
||||
@@ -1135,12 +1169,13 @@ function closeMenu() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* The run detail: a tab strip (Summary / Graph / 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;
|
||||
* the Graph tab mounts the shared workflow graph in run mode; 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;
|
||||
@@ -1165,7 +1200,9 @@ function renderRunDetail() {
|
||||
),
|
||||
),
|
||||
);
|
||||
if (state.runTab === "input") {
|
||||
if (state.runTab === "graph") {
|
||||
pane.append(renderRunGraphTab(d));
|
||||
} else 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));
|
||||
@@ -1178,6 +1215,41 @@ function renderRunDetail() {
|
||||
return pane;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* (or a tab/run change) always unmounts the previous wheel/pointer/resize
|
||||
* listeners and the elapsed timer.
|
||||
*/
|
||||
function renderRunGraphTab(d) {
|
||||
const wrap = h("div", { class: "run-tab-body" });
|
||||
const stages = d.graph?.stages ?? [];
|
||||
if (!stages.length) {
|
||||
wrap.append(h("div", { class: "run-empty muted", text: RUN_GRAPH_MISSING }));
|
||||
return wrap;
|
||||
}
|
||||
wrap.append(h("p", { class: "graph-note muted", text: RUN_GRAPH_NOTE }));
|
||||
const host = h("div", { class: "graph-host" });
|
||||
wrap.append(host);
|
||||
state.runGraph = mountGraph(host, d.graph, {
|
||||
runState: runGraphState(d),
|
||||
onStageTap: (key) => openStagePane(key, latestVisitIndex(d, key)),
|
||||
});
|
||||
return wrap;
|
||||
}
|
||||
|
||||
/**
|
||||
* The visit index the graph opens for a stage: its most recent recorded visit
|
||||
* (`visits.size - 1`, never negative), exactly as RunGraphTab computes it.
|
||||
*/
|
||||
function latestVisitIndex(d, key) {
|
||||
const visits = runTimeline(d.steps ?? []).visitsByStage.get(key) ?? [];
|
||||
return Math.max(0, visits.length - 1);
|
||||
}
|
||||
|
||||
/** The Summary tab: identity, chip row, key/value rows, diagnostic and gallery. */
|
||||
function renderRunSummaryTab(d) {
|
||||
const wrap = h("div", { class: "run-tab-body" });
|
||||
@@ -1207,6 +1279,14 @@ function renderRunSummaryTab(d) {
|
||||
renderArtifactGallery(d.steps ?? []),
|
||||
),
|
||||
);
|
||||
|
||||
// The run-level Changes (parity R4), collapsed by default like the Android
|
||||
// summary: the observed workspace diff. Its header alone states the file count
|
||||
// and aggregate stat until expanded, and every file row opens the diff viewer.
|
||||
const changes = runChanges(d.steps ?? []);
|
||||
wrap.append(
|
||||
renderCollapsible("summary-changes", runChangesHeader(changes), () => renderChangesBody(changes)),
|
||||
);
|
||||
return wrap;
|
||||
}
|
||||
|
||||
@@ -1299,6 +1379,285 @@ function renderCollapsible(key, title, bodyFn) {
|
||||
return wrap;
|
||||
}
|
||||
|
||||
// --- Changes (parity R4) ---------------------------------------------------
|
||||
|
||||
/**
|
||||
* The Changes section body: the file-list summary line, the honest capture note
|
||||
* (when the capture was not complete) and then either the no-change detail or
|
||||
* one clickable row per changed file in first-seen order. Every server string is
|
||||
* set as text, never as markup.
|
||||
*/
|
||||
function renderChangesBody(changes) {
|
||||
const body = h("div", { class: "changes" });
|
||||
body.append(h("div", { class: "changes-summary", text: changesListSummary(changes) }));
|
||||
const note = runChangesNote(changes);
|
||||
if (note.trim() !== "") body.append(h("div", { class: "changes-note muted", text: note }));
|
||||
if (changes.files.length === 0) {
|
||||
body.append(h("div", { class: "changes-empty muted", text: noChangeDetail(changes) }));
|
||||
return body;
|
||||
}
|
||||
const list = h("div", { class: "changes-list" });
|
||||
changes.files.forEach((entry, index) => list.append(renderChangeRow(entry, index, changes.files)));
|
||||
body.append(list);
|
||||
return body;
|
||||
}
|
||||
|
||||
/** The tone class for a file's kind: added green, deleted red, else neutral. */
|
||||
function changeKindTone(kind) {
|
||||
if (kind === ChangeKind.Added) return "ok";
|
||||
if (kind === ChangeKind.Deleted) return "bad";
|
||||
return "muted";
|
||||
}
|
||||
|
||||
/**
|
||||
* One changed-file row: the kind word in its hue, the path in monospace, the
|
||||
* `+N -M` stat and the `changed by …` meta line. Clicking (or Enter/Space) opens
|
||||
* the diff viewer on this file, whose position there confirms which row it is.
|
||||
*/
|
||||
function renderChangeRow(entry, index, files) {
|
||||
const open = () => openChangeViewer(files, index);
|
||||
const row = h("div", {
|
||||
class: "change-row",
|
||||
role: "button",
|
||||
tabindex: "0",
|
||||
"data-change-index": String(index),
|
||||
"aria-label": `Open ${entry.path}`,
|
||||
});
|
||||
row.addEventListener("click", open);
|
||||
row.addEventListener("keydown", (event) => {
|
||||
if (event.key === "Enter" || event.key === " ") {
|
||||
event.preventDefault();
|
||||
open();
|
||||
}
|
||||
});
|
||||
row.append(h("span", { class: `change-kind ${changeKindTone(entry.kind)}`, text: changeKindLabel(entry.kind) }));
|
||||
const main = h("div", { class: "change-main" });
|
||||
main.append(h("div", { class: "change-path monospace", text: entry.path }));
|
||||
main.append(h("div", { class: "change-meta muted", text: changeRowMeta(entry) }));
|
||||
row.append(main);
|
||||
const stat = h("div", { class: "change-stat" });
|
||||
if (entry.added > 0) stat.append(h("span", { class: "stat-add", text: `+${entry.added}` }));
|
||||
if (entry.removed > 0) stat.append(h("span", { class: "stat-del", text: `-${entry.removed}` }));
|
||||
row.append(stat);
|
||||
return row;
|
||||
}
|
||||
|
||||
let changeViewerOverlay = null;
|
||||
let changeViewerKeydown = null;
|
||||
let changeViewerIndex = null;
|
||||
|
||||
/** Close the diff viewer, returning focus to the row that opened it. */
|
||||
function closeChangeViewer() {
|
||||
if (changeViewerKeydown) {
|
||||
document.removeEventListener("keydown", changeViewerKeydown);
|
||||
changeViewerKeydown = null;
|
||||
}
|
||||
const index = changeViewerIndex;
|
||||
changeViewerOverlay?.remove();
|
||||
changeViewerOverlay = null;
|
||||
changeViewerIndex = null;
|
||||
if (index != null) {
|
||||
document.querySelector(`.change-row[data-change-index="${index}"]`)?.focus();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The full-screen diff viewer for one changed file. It pages through the run's
|
||||
* changed files exactly as the artifact viewer pages through a gallery's media
|
||||
* (one shared index, previous/next affordances, Escape/the close button/backdrop
|
||||
* dismissing), and shows both forms the brief requires, switchable from one
|
||||
* control row: the **Rendered** reading (each hunk's `@@` header, the shared
|
||||
* diff line language and the old/new gutter numbers) and the **Raw patch** (the
|
||||
* server's unified patch verbatim in monospace). A file the server could not
|
||||
* give a patch for (binary, truncated, or a capture that recorded none) shows the
|
||||
* honest reason in place of a diff rather than a fabricated one.
|
||||
*/
|
||||
function openChangeViewer(files, startIndex) {
|
||||
closeChangeViewer();
|
||||
if (!files?.length) return;
|
||||
let index = Math.min(Math.max(Number(startIndex) || 0, 0), files.length - 1);
|
||||
let form = "rendered";
|
||||
const overlay = h("div", {
|
||||
class: "change-viewer",
|
||||
role: "dialog",
|
||||
"aria-modal": "true",
|
||||
"aria-label": "Diff viewer",
|
||||
});
|
||||
overlay.addEventListener("click", (event) => {
|
||||
if (event.target === overlay) closeChangeViewer();
|
||||
});
|
||||
|
||||
const renderViewer = () => {
|
||||
const entry = files[index];
|
||||
changeViewerIndex = index;
|
||||
const stat = changeStat(entry.added, entry.removed);
|
||||
const hasPatch = entryHasPatch(entry);
|
||||
|
||||
const titles = h("div", { class: "change-viewer-titles" });
|
||||
const titleRow = h("div", { class: "change-viewer-title-row" });
|
||||
titleRow.append(
|
||||
h("span", { class: `change-kind ${changeKindTone(entry.kind)}`, text: changeKindTitle(entry.kind) }),
|
||||
);
|
||||
if (stat !== "") titleRow.append(h("span", { class: "change-viewer-stat monospace", text: stat }));
|
||||
titles.append(titleRow);
|
||||
titles.append(h("div", { class: "change-viewer-path monospace", text: entry.path }));
|
||||
titles.append(
|
||||
h("div", {
|
||||
class: "change-viewer-position muted",
|
||||
text: `${changePositionLabel(index, files.length)} · changed by ${(entry.steps ?? []).join(" → ")}`,
|
||||
}),
|
||||
);
|
||||
const head = h(
|
||||
"div",
|
||||
{ class: "change-viewer-head" },
|
||||
titles,
|
||||
h("button", {
|
||||
class: "change-viewer-copy",
|
||||
type: "button",
|
||||
text: "Copy raw patch",
|
||||
disabled: !hasPatch,
|
||||
onclick: () => copyText(entry.patch ?? ""),
|
||||
}),
|
||||
h("button", {
|
||||
class: "change-viewer-close",
|
||||
type: "button",
|
||||
text: "Close diff",
|
||||
onclick: closeChangeViewer,
|
||||
}),
|
||||
);
|
||||
|
||||
const controls = h(
|
||||
"div",
|
||||
{ class: "change-viewer-controls" },
|
||||
h("button", {
|
||||
class: `change-form${form === "rendered" ? " active" : ""}`,
|
||||
type: "button",
|
||||
"data-form": "rendered",
|
||||
text: "Rendered",
|
||||
disabled: form === "rendered",
|
||||
onclick: () => {
|
||||
form = "rendered";
|
||||
renderViewer();
|
||||
},
|
||||
}),
|
||||
h("button", {
|
||||
class: `change-form${form === "raw" ? " active" : ""}`,
|
||||
type: "button",
|
||||
"data-form": "raw",
|
||||
text: "Raw patch",
|
||||
disabled: !hasPatch,
|
||||
onclick: () => {
|
||||
form = "raw";
|
||||
renderViewer();
|
||||
},
|
||||
}),
|
||||
h("div", { class: "change-viewer-spacer" }),
|
||||
h("button", {
|
||||
class: "change-page",
|
||||
type: "button",
|
||||
"data-page": "prev",
|
||||
text: "Previous file",
|
||||
disabled: index === 0,
|
||||
onclick: () => {
|
||||
index = Math.max(index - 1, 0);
|
||||
form = "rendered";
|
||||
renderViewer();
|
||||
},
|
||||
}),
|
||||
h("button", {
|
||||
class: "change-page",
|
||||
type: "button",
|
||||
"data-page": "next",
|
||||
text: "Next file",
|
||||
disabled: index === files.length - 1,
|
||||
onclick: () => {
|
||||
index = Math.min(index + 1, files.length - 1);
|
||||
form = "rendered";
|
||||
renderViewer();
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
const body = h("div", { class: "change-viewer-body" });
|
||||
if (entry.binary || !hasPatch) {
|
||||
body.append(
|
||||
h("div", {
|
||||
class: "change-honest muted",
|
||||
text: entry.binary ? BINARY_DIFF_MESSAGE : patchUnavailableReason(entry),
|
||||
}),
|
||||
);
|
||||
} else if (form === "raw") {
|
||||
body.append(h("pre", { class: "change-raw monospace", text: entry.patch ?? "" }));
|
||||
} else {
|
||||
body.append(renderRenderedDiff(entry));
|
||||
}
|
||||
|
||||
overlay.replaceChildren(head, controls, body);
|
||||
};
|
||||
|
||||
renderViewer();
|
||||
document.body.append(overlay);
|
||||
changeViewerOverlay = overlay;
|
||||
changeViewerKeydown = (event) => {
|
||||
if (event.key === "Escape") closeChangeViewer();
|
||||
};
|
||||
document.addEventListener("keydown", changeViewerKeydown);
|
||||
}
|
||||
|
||||
/** The rendered reading: the stat line, an optional truncation note, each hunk. */
|
||||
function renderRenderedDiff(entry) {
|
||||
const wrap = h("div", { class: "change-diff" });
|
||||
const parsed = parseUnifiedPatch(entry.patch);
|
||||
const statLine = h("div", { class: "change-diff-stat" });
|
||||
if (parsed.added > 0) statLine.append(h("span", { class: "stat-add", text: `+${parsed.added}` }));
|
||||
if (parsed.removed > 0) statLine.append(h("span", { class: "stat-del", text: `-${parsed.removed}` }));
|
||||
if (parsed.added === 0 && parsed.removed === 0) {
|
||||
statLine.append(h("span", { class: "muted", text: NO_LINE_CHANGES_MESSAGE }));
|
||||
}
|
||||
wrap.append(statLine);
|
||||
if (entry.truncated) wrap.append(h("div", { class: "change-diff-note muted", text: TRUNCATED_PATCH_NOTE }));
|
||||
for (const hunk of parsed.hunks) wrap.append(renderHunk(hunk));
|
||||
return wrap;
|
||||
}
|
||||
|
||||
/**
|
||||
* One `@@` hunk: its header on a raised surface, then its lines in a
|
||||
* horizontally scrollable container, each with its old/new gutter numbers (blank
|
||||
* on the absent side and on a `\ No newline` marker) and the shared
|
||||
* `{symbol} {text}` coloured by kind.
|
||||
*/
|
||||
function renderHunk(hunk) {
|
||||
const width = gutterWidth(hunk);
|
||||
const wrap = h("div", { class: "change-hunk" });
|
||||
wrap.append(h("div", { class: "change-hunk-head", text: hunk.header }));
|
||||
const lines = h("div", { class: "change-hunk-lines" });
|
||||
for (const line of hunk.lines) {
|
||||
const gutter = line.noNewlineMarker
|
||||
? " ".repeat(width * 2 + 1)
|
||||
: `${gutterText(line.oldLine, width)} ${gutterText(line.newLine, width)}`;
|
||||
lines.append(
|
||||
h(
|
||||
"div",
|
||||
{ class: "change-line" },
|
||||
h("span", { class: "change-gutter", text: gutter }),
|
||||
h("span", { class: `change-text ${diffLineClass(line.kind)}`, text: `${diffLineSymbol(line.kind)} ${line.text}` }),
|
||||
),
|
||||
);
|
||||
}
|
||||
wrap.append(lines);
|
||||
return wrap;
|
||||
}
|
||||
|
||||
/** Copy arbitrary text (the raw patch) to the clipboard, best effort. */
|
||||
async function copyText(text) {
|
||||
if (!text || !canCopyLink()) return;
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
} catch {
|
||||
// Clipboard permission may be denied; the patch is still readable.
|
||||
}
|
||||
}
|
||||
|
||||
/** The Timeline tab: one compact row per visit, in step order. */
|
||||
function renderRunTimelineTab(d) {
|
||||
const wrap = h("div", { class: "run-tab-body" });
|
||||
@@ -1543,7 +1902,14 @@ function closeStagePane() {
|
||||
const row = [...document.querySelectorAll(".timeline-row")].find(
|
||||
(node) => node.dataset.stageKey === closing.stageKey && node.dataset.visitIndex === String(closing.visitIndex),
|
||||
);
|
||||
row?.focus();
|
||||
// A pane opened from the Timeline returns to its row; one opened from the Graph
|
||||
// returns to the stage node that opened it (there is no timeline row then).
|
||||
const focusTarget =
|
||||
row ??
|
||||
[...document.querySelectorAll(".graph-node")].find(
|
||||
(candidate) => candidate.dataset.key === closing.stageKey,
|
||||
);
|
||||
focusTarget?.focus();
|
||||
}
|
||||
|
||||
/** Whether the configured server URL can resolve a server-relative artifact. */
|
||||
@@ -2065,9 +2431,12 @@ async function selectPipeline(summary) {
|
||||
async function selectRun(id, { silent = false } = {}) {
|
||||
state.selectedRunId = id;
|
||||
if (!silent) {
|
||||
state.runDetail = null;
|
||||
// A different run reseeds the detail: Summary tab, every section closed and
|
||||
// no stage pane left over from the run the operator navigated away from.
|
||||
// no stage pane left over from the run the operator navigated away from. Drop
|
||||
// the mounted run graph first so a live run's timer can never outlive it.
|
||||
state.runGraph?.unmount();
|
||||
state.runGraph = null;
|
||||
state.runDetail = null;
|
||||
state.runTab = "summary";
|
||||
state.runSections = new Set();
|
||||
state.runStagePane = null;
|
||||
@@ -2172,11 +2541,16 @@ client.addEventListener("state", (event) => {
|
||||
render();
|
||||
});
|
||||
|
||||
// The stage pane is a modal dialog: Escape closes it (the artifact viewer, when
|
||||
// it is stacked above, owns Escape first). Registered once; it is a no-op when
|
||||
// no pane is open.
|
||||
// The stage pane is a modal dialog: Escape closes it (a stacked overlay — the
|
||||
// artifact viewer or the diff viewer, when either is above — owns Escape first).
|
||||
// Registered once; it is a no-op when no pane is open.
|
||||
document.addEventListener("keydown", (event) => {
|
||||
if (event.key === "Escape" && state.runStagePane && !document.querySelector(".artifact-viewer")) {
|
||||
if (
|
||||
event.key === "Escape" &&
|
||||
state.runStagePane &&
|
||||
!document.querySelector(".artifact-viewer") &&
|
||||
!document.querySelector(".change-viewer")
|
||||
) {
|
||||
event.preventDefault();
|
||||
closeStagePane();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user