Merge branch 'main' into web-runs-home

# Conflicts:
#	web/src/app.js
#	web/styles.css
This commit is contained in:
2026-10-19 03:02:42 +01:00
9 changed files with 586 additions and 2 deletions
+1 -1
View File
@@ -24,7 +24,7 @@ Status legend: `todo` · `partial` (some of it works) · `done` (working + captu
| P1 | Pipeline list | `list_pipelines` | done — row: name; `id {id} · v{version} · {N stages}`; `updated d MMM HH:mm`; last-run line joined from `list_runs` (status chip + `{ago} · {duration} · run {id}`, or `no runs recorded`) |
| P2 | Filter + sort (status/name/updated) | client-side | done — Filter menu (name contains, Runs Any/Has runs/No runs, Last run status over the 7 server states, Clear filters) + Sort menu (Server order default, Name A–Z/Z–A, Most recent run, Fewest/Most stages, Reset); server order preserved |
| P3 | Pipeline detail: stages, graph, versions, last run, content hash | `get_pipeline` | done — Summary/Graph/Source tabs; Summary shows content hash (monospace), latest version (`v{n}` or blank), created/updated, and a collapsed-by-default Versions section. Graph tab shows the browser guidance note only; the rendered graph is P6 |
| P4 | Templates gallery + template detail | `list_templates` | todo |
| P4 | Templates gallery + template detail | `list_templates`, `validate` | done |
| P5 | Create pipeline from a template (validate then submit) | `validate`, `submit` | todo |
| P6 | Workflow graph rendering (nodes, edges, stage panes) | `get_pipeline` | todo |
+209 -1
View File
@@ -43,6 +43,16 @@ import {
defaultRunFilters,
runFiltersActiveCount,
} from "./runs.js";
import {
effectiveStageType,
templateCard,
templateDetailName,
templateGalleryName,
templateGraphNote,
templateStageCountLabel,
templateStageSummary,
TEMPLATE_UNPARSED_SOURCE_NOTE,
} from "./templates.js";
const STORAGE_KEY = "pipelines.web.serverUrl.v2";
@@ -92,6 +102,13 @@ const state = {
versionsExpanded: false,
pipelinesLoaded: false,
runsLoaded: false,
templates: [],
templateLoading: false,
// key -> graph|null: the parsed definition, cached once per template key. A
// failed/absent validate stores null so the card/detail say "unavailable".
templateGraphs: new Map(),
selectedTemplateKey: null,
templateTab: "summary",
loading: false,
error: "",
runFilters: defaultRunFilters(),
@@ -227,6 +244,7 @@ function renderContent() {
{ class: "tabs" },
tabButton("pipelines", `Pipelines (${state.pipelines.length})`),
tabButton("runs", `Runs (${state.runs.length})`),
tabButton("templates", "Templates"),
h("span", { class: "spacer" }),
h("button", { class: "ghost", text: "Refresh", onclick: () => loadCurrentView(true) }),
),
@@ -235,8 +253,10 @@ function renderContent() {
const split = h("div", { class: "split" });
if (state.view === "pipelines") {
split.append(renderPipelineList(), renderPipelineDetail());
} else {
} else if (state.view === "runs") {
split.append(renderRunList(), renderRunDetail());
} else {
split.append(renderTemplateGallery(), renderTemplateDetail());
}
nodes.push(split);
content.replaceChildren(...nodes);
@@ -254,6 +274,7 @@ function tabButton(view, label) {
renderContent();
if (view === "runs" && !state.runs.length) loadCurrentView();
if (view === "pipelines" && !state.pipelines.length) loadCurrentView();
if (view === "templates" && !state.templates.length) loadCurrentView();
},
});
}
@@ -573,6 +594,140 @@ function renderPipelineDetail() {
return pane;
}
// --- Templates -------------------------------------------------------------
/** The cached parsed graph for a template key, or null when it did not parse. */
function templateGraphFor(key) {
return state.templateGraphs.has(key) ? state.templateGraphs.get(key) : null;
}
function renderTemplateGallery() {
const pane = h("div", { class: "list gallery" });
pane.append(
h(
"div",
{ class: "pane-head" },
h("h2", { text: "Templates" }),
h("button", { class: "ghost", text: "Refresh templates", onclick: () => loadTemplates(true) }),
),
);
if (state.templateLoading && !state.templates.length) {
pane.append(h("div", { class: "muted pad", text: "Loading templates…" }));
return pane;
}
if (!state.templates.length) {
pane.append(h("div", { class: "muted pad", text: "No templates are available on this server." }));
return pane;
}
const cards = h("div", { class: "cards" });
for (const entry of state.templates) {
const card = templateCard(entry, templateGraphFor(entry.key));
cards.append(
h(
"button",
{
class: `card${state.selectedTemplateKey === entry.key ? " selected" : ""}`,
onclick: () => selectTemplate(entry.key),
},
h("span", { class: "card-name", text: templateGalleryName(card.name) }),
h("span", { class: "card-desc", text: card.description }),
h("span", { class: "card-meta", text: templateStageCountLabel(card.stageCount) }),
),
);
}
pane.append(cards);
return pane;
}
function renderTemplateDetail() {
const pane = h("div", { class: "detail" });
const entry = state.templates.find((t) => t.key === state.selectedTemplateKey);
if (!entry) {
pane.append(h("div", { class: "muted pad", text: "Select a template." }));
return pane;
}
const graph = templateGraphFor(entry.key);
pane.append(
h(
"div",
{ class: "tabstrip" },
templateTabButton("summary", "Summary"),
templateTabButton("graph", "Graph"),
templateTabButton("source", "Source"),
),
);
if (state.templateTab === "graph") pane.append(renderTemplateGraphTab(graph));
else if (state.templateTab === "source") pane.append(renderTemplateSourceTab(entry, graph));
else pane.append(renderTemplateSummaryTab(entry, graph));
return pane;
}
function templateTabButton(tab, label) {
return h("button", {
class: `minitab${state.templateTab === tab ? " active" : ""}`,
text: label,
onclick: () => {
state.templateTab = tab;
renderContent();
},
});
}
function renderTemplateSummaryTab(entry, graph) {
const wrap = h("div", { class: "tabbody" });
wrap.append(h("h2", { text: templateDetailName(entry) }));
if ((entry.description ?? "").trim()) {
wrap.append(h("p", { class: "body", text: entry.description }));
}
wrap.append(h("div", { class: "kv" }, kvMono("Key", entry.key)));
wrap.append(
h("div", { class: "meta-line", text: templateStageCountLabel(graph?.stages?.length ?? null) }),
);
if (entry.scheduled) wrap.append(h("div", { class: "meta-line", text: "Includes a schedule" }));
const summary = templateStageSummary(graph);
if (summary.note) {
wrap.append(h("div", { class: "muted pad", text: summary.note }));
return wrap;
}
wrap.append(h("h3", { text: "Stages" }));
const ul = h("ul", { class: "stages" });
for (const stage of summary.stages) {
ul.append(
h(
"li",
{},
h("code", { text: stage.key }),
h("span", { class: "chip", text: effectiveStageType(stage.type) }),
),
);
}
wrap.append(ul);
return wrap;
}
function renderTemplateGraphTab(graph) {
const wrap = h("div", { class: "tabbody" });
wrap.append(h("p", { class: "muted", text: templateGraphNote(graph) }));
return wrap;
}
function renderTemplateSourceTab(entry, graph) {
const wrap = h("div", { class: "tabbody" });
if (graph == null) {
wrap.append(h("p", { class: "muted", text: TEMPLATE_UNPARSED_SOURCE_NOTE }));
}
wrap.append(
h(
"div",
{ class: "codeblock" },
h("div", { class: "codeblock-label", text: "Definition source" }),
h("pre", { class: "codeblock-body", text: entry.source ?? "" }),
),
);
return wrap;
}
function pipelineSortLabel(key) {
return (PIPELINE_SORTS.find((option) => option.key === key) ?? PIPELINE_SORTS[0]).label;
}
@@ -961,6 +1116,16 @@ function kv(key, value) {
);
}
/** A key/value row whose value is monospace (a key, an id) rather than prose. */
function kvMono(key, value) {
return h(
"div",
{ class: "kv-row" },
h("span", { class: "kv-key", text: key }),
h("span", { class: "kv-val" }, h("code", { text: value })),
);
}
// ---------------------------------------------------------------------------
// Actions
// ---------------------------------------------------------------------------
@@ -1005,6 +1170,10 @@ async function loadCurrentView(force = false) {
renderContent();
return;
}
if (state.view === "templates") {
await loadTemplates(force);
return;
}
state.loading = true;
state.error = "";
renderContent();
@@ -1036,6 +1205,45 @@ async function loadCurrentView(force = false) {
}
}
/**
* Loads the template catalogue, then validates each template's source once and
* caches the parsed graph (null when it did not parse) so a card's stage count
* and the detail's stage list read the same result and can never disagree.
*/
async function loadTemplates(force = false) {
state.templateLoading = true;
state.error = "";
renderContent();
try {
state.templates = await repo.listTemplates();
for (const entry of state.templates) {
if (force || !state.templateGraphs.has(entry.key)) {
state.templateGraphs.set(entry.key, await validateTemplate(entry));
}
}
state.templateLoading = false;
renderContent();
} catch (err) {
state.templateLoading = false;
setError(err);
}
}
/** The parsed graph for a template, or null when the server cannot parse its source. */
async function validateTemplate(entry) {
try {
return await repo.validate(entry.source);
} catch {
return null;
}
}
function selectTemplate(key) {
state.selectedTemplateKey = key;
state.templateTab = "summary";
renderContent();
}
async function selectPipeline(summary) {
state.selectedPipelineId = summary.id;
state.pipelineDetail = null;
+5
View File
@@ -11,6 +11,11 @@ export const Protocol = Object.freeze({
GET_PIPELINE: "get_pipeline",
PIPELINE: "pipeline",
LIST_TEMPLATES: "list_templates",
TEMPLATES: "templates",
VALIDATE: "validate",
VALIDATED: "validated",
LIST_RUNS: "list_runs",
RUNS: "runs",
GET_RUN: "get_run",
+14
View File
@@ -43,6 +43,20 @@ export class PipelinesRepository {
return response.detail;
}
async listTemplates() {
return (await this.#client.call({ type: Protocol.LIST_TEMPLATES })).templates ?? [];
}
async validate(source) {
const response = await this.#client.call({ type: Protocol.VALIDATE, source });
// A server error envelope already rejects inside client.call, so a reply
// here is `validated`; a missing graph is still an unusable definition.
if (!response.graph) {
throw new ProtocolError("The server returned no graph.");
}
return response.graph;
}
async listRuns() {
const response = await this.#client.call({ type: Protocol.LIST_RUNS });
return { runs: response.runs ?? [], usage: response.usage ?? null };
+93
View File
@@ -0,0 +1,93 @@
// Pure Templates derivations, mirroring the Android app's ui/Templates.kt,
// ui/Format.kt and ui/graph/StageDetailPane.kt. No DOM and no protocol here, so
// the gallery/detail wording and the stage-count mapping are unit-tested without
// a browser. Every value returned is plain text (or plain data); the caller sets
// it with textContent and never with innerHTML.
/** A gallery card's name: a blank name is the explicit unnamed-template placeholder. */
export function templateGalleryName(name) {
return (name ?? "").trim() ? name : "(unnamed template)";
}
/** A detail's heading: a blank name falls back to the template's key. */
export function templateDetailName(entry) {
const name = (entry?.name ?? "").trim();
return name ? entry.name : (entry?.key ?? "");
}
/** "1 stage" / "N stages", mirroring ui/Format.kt stageCountText. */
export function stageCountText(count) {
return `${count} ${count === 1 ? "stage" : "stages"}`;
}
/**
* The card's stage-count line: the count parsed from the source, or an explicit
* "unavailable" when the source could not be parsed (never "0 stages", which
* would claim a count the client does not have).
*/
export function templateStageCountLabel(stageCount) {
return stageCount == null ? "stage count unavailable" : stageCountText(stageCount);
}
/** The effective stage type, mirroring internal/stage.EffectiveType: blank is the model stage. */
export function effectiveStageType(type) {
return (type ?? "").trim() ? type : "model";
}
/**
* One gallery card's content: the template's name and description (from the
* catalogue) and its stage count (from the graph the server parsed out of the
* source; null when the source did not parse, so the card says so rather than
* claiming zero stages).
*/
export function templateCard(entry, graph = null) {
return {
key: entry?.key ?? "",
name: entry?.name ?? "",
description: entry?.description ?? "",
stageCount: graph?.stages?.length ?? null,
};
}
/** The unparsed-source note the Summary tab shows instead of a stage list. */
export const TEMPLATE_UNPARSED_SUMMARY_NOTE =
"This template's source could not be parsed, so its stages are not listed. See the Source tab for the raw definition.";
/** The note the Summary tab shows for a parsed template that declares no stages. */
export const TEMPLATE_NO_STAGES_NOTE = "This template has no stages.";
/** The Graph tab's note when the source did not parse. */
export const TEMPLATE_UNPARSED_GRAPH_NOTE =
"This template's source could not be parsed, so there is no graph. The Source tab shows the raw definition.";
/** The Graph tab's note when the source parsed; the graph is the parsed definition. */
export const TEMPLATE_GRAPH_NOTE =
"Pinch to zoom and drag to pan. The graph is the parsed definition; nothing runs.";
/** The Source tab's note when the source did not parse on the server. */
export const TEMPLATE_UNPARSED_SOURCE_NOTE =
"This source could not be parsed on the server; showing the raw definition.";
/**
* The Summary tab's stage section: an explicit [note] and no stages when the
* source did not parse or parsed to nothing, else the stage rows (key + effective
* type). One derivation, so the note and the list can never disagree.
*/
export function templateStageSummary(graph) {
if (graph == null) {
return { note: TEMPLATE_UNPARSED_SUMMARY_NOTE, stages: [] };
}
const stages = graph.stages ?? [];
if (!stages.length) {
return { note: TEMPLATE_NO_STAGES_NOTE, stages: [] };
}
return {
note: null,
stages: stages.map((stage) => ({ key: stage.key, type: effectiveStageType(stage.type) })),
};
}
/** The Graph tab's note: the unparsed note when there is no graph, else the parsed-definition note. */
export function templateGraphNote(graph) {
return graph == null ? TEMPLATE_UNPARSED_GRAPH_NOTE : TEMPLATE_GRAPH_NOTE;
}
+53
View File
@@ -320,6 +320,59 @@ code { background: var(--surface-2); padding: 1px 6px; border-radius: 6px; font-
}
.run-list-error { padding: 12px 16px; color: var(--bad); }
/* --- Templates gallery + detail ------------------------------------------ */
.pane-head { display: flex; gap: 8px; align-items: center; justify-content: space-between; padding: 12px 12px 0; }
.pane-head h2 { margin: 0; font-size: 16px; }
.gallery { padding-bottom: 8px; }
.cards { display: grid; gap: 8px; padding: 10px 12px; }
.card {
display: block;
width: 100%;
text-align: left;
border: 1px solid var(--border);
border-radius: 10px;
background: var(--surface-2);
padding: 10px 12px;
}
.card:hover { border-color: var(--accent); }
.card.selected { box-shadow: inset 3px 0 0 var(--accent); border-color: var(--accent); }
.card-name { display: block; font-weight: 600; }
.card-desc {
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
color: var(--muted);
font-size: 12px;
margin-top: 2px;
}
.card-desc:empty { display: none; }
.card-meta { display: block; color: var(--accent); font-size: 12px; margin-top: 4px; }
.tabstrip { display: flex; gap: 4px; margin: -4px 0 12px; }
.minitab { border-color: transparent; background: transparent; padding: 5px 10px; }
.minitab.active { background: var(--surface-2); border-color: var(--border); color: var(--accent); }
.tabbody h2 { margin-top: 0; }
.tabbody .body { margin: 0 0 12px; }
.meta-line { color: var(--muted); font-size: 12px; margin-top: 4px; }
.codeblock { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; margin-top: 12px; }
.codeblock-label { padding: 6px 10px; background: var(--surface-2); border-bottom: 1px solid var(--border); color: var(--muted); font-size: 12px; }
.codeblock-body {
margin: 0;
padding: 10px;
max-height: 420px;
overflow: auto;
background: transparent;
color: var(--text);
font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
white-space: pre-wrap;
word-break: break-word;
}
/* Pipeline list: filter + sort controls. */
.list-controls { border-bottom: 1px solid var(--border); }
.list-toolbar { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; padding: 8px 12px; }
+106
View File
@@ -0,0 +1,106 @@
// Repository request-shape tests: the templates catalogue and the validate
// command, driven through the real transport against a fake WebSocket so the
// exact frames sent (and the error-envelope handling) are proven, not assumed.
import { test } from "node:test";
import assert from "node:assert/strict";
import { PipelinesClient, ProtocolError } from "../src/client.js";
import { PipelinesRepository } from "../src/repository.js";
import { validateServerUrl } from "../src/serverUrl.js";
const VALID = validateServerUrl("ws://host:8080/connect");
/** The same minimal fake the client tests use (test files are not importable). */
class FakeWebSocket {
static instances = [];
constructor(url) {
this.url = url;
this.sent = [];
this.onopen = null;
this.onmessage = null;
this.onclose = null;
this.onerror = null;
this.reply = null;
FakeWebSocket.instances.push(this);
}
send(data) {
const frame = JSON.parse(data);
this.sent.push(frame);
const response = this.reply?.(frame);
if (response !== undefined) {
this.onmessage?.({ data: JSON.stringify(response) });
}
}
close(code, reason) {
this.onclose?.({ code, reason });
}
open() {
this.onopen?.({});
}
}
function connected() {
FakeWebSocket.instances = [];
const client = new PipelinesClient({ WebSocketImpl: FakeWebSocket });
const repo = new PipelinesRepository(client);
client.connect(VALID);
const ws = FakeWebSocket.instances.at(-1);
ws.open();
return { repo, ws, client };
}
/** The last frame without the client-generated id, for an exact shape assertion. */
function lastFrame(ws) {
const { id, ...frame } = ws.sent.at(-1);
assert.match(id, /^web-\d+$/);
return frame;
}
test("listTemplates sends exactly {type:'list_templates'} and returns the catalogue", async () => {
const { repo, ws } = connected();
ws.reply = (frame) => ({
id: frame.id,
type: "templates",
templates: [{ key: "task", name: "Complete a task" }],
});
const templates = await repo.listTemplates();
assert.deepEqual(lastFrame(ws), { type: "list_templates" });
assert.equal(templates.length, 1);
assert.equal(templates[0].key, "task");
});
test("listTemplates returns [] when the reply carries no templates", async () => {
const { repo, ws } = connected();
ws.reply = (frame) => ({ id: frame.id, type: "templates" });
assert.deepEqual(await repo.listTemplates(), []);
});
test("validate sends exactly {type:'validate', source} and returns response.graph", async () => {
const { repo, ws } = connected();
const graph = { stages: [{ key: "plan" }] };
ws.reply = (frame) => ({ id: frame.id, type: "validated", graph });
const result = await repo.validate("the source");
assert.deepEqual(lastFrame(ws), { type: "validate", source: "the source" });
assert.deepEqual(result, graph);
});
test("validate rejects a server error envelope with the server's text", async () => {
const { repo, ws } = connected();
ws.reply = (frame) => ({ id: frame.id, type: "error", error: "unexpected token" });
await assert.rejects(() => repo.validate("bad source"), {
name: "ProtocolError",
message: "unexpected token",
});
});
test("validate throws when the reply has no graph", async () => {
const { repo, ws } = connected();
ws.reply = (frame) => ({ id: frame.id, type: "validated" });
await assert.rejects(() => repo.validate("empty"), ProtocolError);
});
+87
View File
@@ -0,0 +1,87 @@
// Pure Templates helper tests: wording (singular/plural, placeholders), the
// card mapping and the stage-summary/graph-note derivations. No DOM, no server.
import { test } from "node:test";
import assert from "node:assert/strict";
import {
effectiveStageType,
stageCountText,
templateCard,
templateDetailName,
templateGalleryName,
templateGraphNote,
templateStageCountLabel,
templateStageSummary,
TEMPLATE_GRAPH_NOTE,
TEMPLATE_NO_STAGES_NOTE,
TEMPLATE_UNPARSED_GRAPH_NOTE,
TEMPLATE_UNPARSED_SUMMARY_NOTE,
} from "../src/templates.js";
test("stageCountText spells one stage and many stages", () => {
assert.equal(stageCountText(1), "1 stage");
assert.equal(stageCountText(2), "2 stages");
assert.equal(stageCountText(0), "0 stages");
});
test("templateStageCountLabel says unavailable for an unknown count, never zero", () => {
assert.equal(templateStageCountLabel(null), "stage count unavailable");
assert.equal(templateStageCountLabel(undefined), "stage count unavailable");
assert.equal(templateStageCountLabel(1), "1 stage");
assert.equal(templateStageCountLabel(3), "3 stages");
});
test("a blank gallery name becomes the unnamed placeholder", () => {
assert.equal(templateGalleryName(""), "(unnamed template)");
assert.equal(templateGalleryName(" "), "(unnamed template)");
assert.equal(templateGalleryName("Review a repository"), "Review a repository");
});
test("a blank detail name falls back to the template key", () => {
assert.equal(templateDetailName({ key: "task", name: "" }), "task");
assert.equal(templateDetailName({ key: "task", name: " " }), "task");
assert.equal(templateDetailName({ key: "task", name: "Complete a task" }), "Complete a task");
});
test("effectiveStageType defaults a blank type to model", () => {
assert.equal(effectiveStageType(""), "model");
assert.equal(effectiveStageType(null), "model");
assert.equal(effectiveStageType(" "), "model");
assert.equal(effectiveStageType("human"), "human");
});
test("templateCard takes the stage count from the parsed graph, null when absent", () => {
const entry = { key: "task", name: "Complete a task", description: "Do it." };
assert.equal(templateCard(entry, null).stageCount, null);
assert.equal(templateCard(entry, { stages: [] }).stageCount, 0);
assert.equal(templateCard(entry, { stages: [{ key: "a" }, { key: "b" }] }).stageCount, 2);
assert.deepEqual(templateCard(entry, null), {
key: "task",
name: "Complete a task",
description: "Do it.",
stageCount: null,
});
});
test("templateStageSummary distinguishes unparsed, empty and populated", () => {
assert.deepEqual(templateStageSummary(null), {
note: TEMPLATE_UNPARSED_SUMMARY_NOTE,
stages: [],
});
assert.deepEqual(templateStageSummary({ stages: [] }), {
note: TEMPLATE_NO_STAGES_NOTE,
stages: [],
});
const summary = templateStageSummary({ stages: [{ key: "plan", type: "" }, { key: "review", type: "human" }] });
assert.equal(summary.note, null);
assert.deepEqual(summary.stages, [
{ key: "plan", type: "model" },
{ key: "review", type: "human" },
]);
});
test("templateGraphNote picks the unparsed or parsed note", () => {
assert.equal(templateGraphNote(null), TEMPLATE_UNPARSED_GRAPH_NOTE);
assert.equal(templateGraphNote({ stages: [] }), TEMPLATE_GRAPH_NOTE);
});
+18
View File
@@ -332,6 +332,24 @@ try {
await page.waitForSelector(".detail h2", { timeout: 25000 });
await shot("16-run-detail.png");
step("opening the Templates gallery");
await page.clickText("nav.tabs button.tab", "Templates");
await page.waitForSelector(".cards button.card", { timeout: 25000 });
shots.push(await page.screenshot(`${out}/17-templates-gallery.png`));
const templateCount = await page.evaluate(`document.querySelectorAll(".cards button.card").length`);
console.log(` templates rendered: ${templateCount}`);
step("opening a template detail (Summary)");
await page.click(".cards button.card");
await page.waitForSelector(".detail .tabstrip", { timeout: 25000 });
await page.waitForText("Key", { timeout: 25000 });
shots.push(await page.screenshot(`${out}/18-template-detail-summary.png`));
step("opening the template Source tab");
await page.clickText(".detail .tabstrip button.minitab", "Source");
await page.waitForText("Definition source", { timeout: 25000 });
shots.push(await page.screenshot(`${out}/19-template-source.png`));
console.log("\nUI SMOKE PASS");
for (const shot of shots) console.log(` ${shot}`);
} catch (error) {