web: shared chat stars, pipeline mini graphs and agent questions

- Persist chat stars in the operator-session registry (chat_star) so every
  browser/device shows the same Starred group; migrate old local stars once.
- Add a compact pipeline graph shape to list responses and draw a lightweight
  list miniature; replace the cryptic id/version line with the stage count.
- Surface OpenCode form questions as a chat card (chat_answer), replay a
  pending form to late subscribers, and notify for background questions.
- Make the mobile dock's Search cell equal to every destination, keep the
  tab row visible with 100svh, and let Source use the full pane height.
- Let a fresh sign-in auto-connect to its own origin; use a Lax session cookie
  with Expires so Remember me survives app/link launches.
- Keep shipped starters and the skill agnostic: no repository paths, project
  areas or personal device commands; add Diagnose/Fix and Research starters.
- Refresh the installed skill and document the new browser conventions.
This commit is contained in:
2026-10-20 03:11:37 +01:00
parent caae8a8038
commit 526c19fc21
46 changed files with 1547 additions and 611 deletions
+60 -10
View File
@@ -27,7 +27,6 @@ import { SERVER_URL_STORAGE_KEY, readServerUrl, readWorkspace, writeServerUrl }
import { layoutGraph } from "./graph.js";
import { readGraphExpanded } from "./graphPrefs.js";
import { readArtifactView } from "./artifactViewPrefs.js";
import { readChatStars } from "./chatStars.js";
import { readLayoutPrefs, writeLayoutPrefs } from "./layoutPrefs.js";
import { DEFAULT_ROUTE, parseRoute, serializeRoute } from "./routes.js";
import { EMPTY_PIPELINE_FILTERS, PIPELINE_DETAIL_TABS } from "./pipelines.js";
@@ -179,8 +178,8 @@ const state = {
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(),
// Starred chat sessions: filled from chat_sessions (server-shared).
chatStars: new Set(),
// The collapsed rail/list choices (layoutPrefs.js), restored per device.
...readLayoutPrefs(),
// Whether the CLOSED chats group is expanded (the chevron beside its name).
@@ -466,6 +465,7 @@ const railDestinations = h(
),
);
const dockTabs = DESTINATIONS.filter((destination) => destination.key !== "settings");
const dockDestinations = h(
"div",
{
@@ -474,9 +474,7 @@ const dockDestinations = h(
role: "tablist",
"aria-label": "Destinations",
},
...DESTINATIONS.filter((destination) => destination.key !== "settings").map((destination) =>
destinationTab(destination, "dock"),
),
...dockTabs.map((destination) => destinationTab(destination, "dock")),
);
const railSearch = h(
@@ -605,7 +603,9 @@ const dock = h(
h("div", { class: "dock-status-row" }, dockStatus, dockSettings),
// The destinations come first and Search sits on the right; every item takes
// an equal share of the bar on a phone.
h("div", { class: "dock-row" }, dockDestinations, dockSearch),
// One equal share per destination; Search is one more share of the same row,
// so the whole bar divides evenly however many destinations exist.
h("div", { class: "dock-row", style: `--dock-count: ${dockTabs.length}` }, dockDestinations, dockSearch),
);
// The attention sheet lives in its own layer so it can overlay any view without
// being torn down by a content re-render; renderAttentionSheet rebuilds it.
@@ -2431,6 +2431,35 @@ client.addEventListener("state", (event) => {
// transcript (C5) folds the frame itself, and the composer's own bookkeeping
// clears the queued notice and releases the Stop control. A frame for any other
// type is ignored.
/**
* A question raised by an agent chat is as urgent as a failing run: if the page
* is not showing that conversation, raise the browser notification the operator
* already enabled for run alerts. Clicking it opens the chat with the question.
*/
function notifyChatQuestion(frame) {
const form = frame?.form;
if (!form?.id) return;
if (typeof globalThis.Notification !== "function") return;
if (globalThis.isSecureContext !== true || globalThis.Notification.permission !== "granted") return;
if (state.view === "chat" && state.chatActiveId === frame.session_id) return;
const session = state.chatSessions.find((row) => row.id === frame.session_id);
const title = String(session?.title ?? "Chat").trim() || "Chat";
try {
const notification = new Notification(`${title} needs your answer`, {
body: String(form.title ?? "The agent asked a question."),
tag: `chat-question:${form.id}`,
});
notification.onclick = () => {
window.focus();
state.view = "chat";
render();
openChatSession(frame.session_id);
};
} catch {
// The in-page question card remains available.
}
}
client.addEventListener("frame", (event) => {
const message = event.detail;
if (!message) return;
@@ -2465,7 +2494,17 @@ client.addEventListener("frame", (event) => {
}
if (message.type !== Protocol.CHAT_EVENT) return;
const frame = message[ChatKeys.EVENT];
if (frame) onChatEvent(frame);
if (frame) {
if (
frame.kind === "form" &&
frame.form?.kind === "question" &&
frame.form.resolved !== true &&
frame.form.cancelled !== true
) {
notifyChatQuestion(frame);
}
onChatEvent(frame);
}
onChatFrame(message);
});
@@ -2560,5 +2599,16 @@ window.addEventListener("resize", () => {
}, 120);
});
// A previously configured endpoint re-opens on load (see bootServerUrl).
if (bootServerUrl) openConfiguredEndpoint({ surfaceError: false });
// A previously configured endpoint re-opens on load (see bootServerUrl). When
// nothing is stored, the page's own origin is the supported default proxy: use
// it instead of leaving a freshly signed-in device on a "Not configured" screen
// and making the operator find the same URL in Settings.
if (bootServerUrl) {
openConfiguredEndpoint({ surfaceError: false });
} else {
const sameOrigin = defaultServerUrl();
if (validateServerUrl(sameOrigin).valid) {
state.url = sameOrigin;
openConfiguredEndpoint({ surfaceError: false });
}
}
+16 -2
View File
@@ -94,7 +94,7 @@ export function attentionBadgeLabel(count) {
* An entry the operator explicitly dismissed never returns. A run status that
* asks nobody is dropped, so the surface can only ever hold actionable work.
*/
export function attentionEntries(runs, dismissed) {
export function attentionEntries(runs, dismissed, { since = 0 } = {}) {
const dismissedKeys =
dismissed instanceof Set ? dismissed : new Set(Array.isArray(dismissed) ? dismissed : []);
return (runs ?? [])
@@ -105,13 +105,16 @@ export function attentionEntries(runs, dismissed) {
if (dismissedKeys.has(key)) return null;
const title = String(run.title ?? "").trim();
const finished = String(run.finished_at ?? "");
const recency = finished.trim() !== "" ? finished : String(run.created_at ?? "");
const at = Date.parse(recency);
if (since > 0 && Number.isFinite(at) && at < since) return null;
return {
runId: run.id,
pipeline: String(run.name ?? ""),
label: title !== "" ? title : String(run.name ?? ""),
kind,
detail: attentionDetail(kind, run),
recency: finished.trim() !== "" ? finished : String(run.created_at ?? ""),
recency,
key,
};
})
@@ -124,6 +127,17 @@ export function attentionEntries(runs, dismissed) {
);
}
/**
* The start of the operator's local day in epoch ms. "Needs you" is a to-do list
* for what changed now; yesterday's failures are history, not a badge that
* follows every device and browser session for ever.
*/
export function startOfLocalDay(now = Date.now()) {
const date = new Date(now);
date.setHours(0, 0, 0, 0);
return date.getTime();
}
/**
* Captures the entries shown when the sheet opens. Bulk dismissal uses this
* snapshot so entries that arrive while the sheet is open are not removed. A
+31
View File
@@ -1133,6 +1133,7 @@ export const EVENT_STEP = "step";
export const EVENT_USAGE = "usage";
export const EVENT_USER = "user";
export const EVENT_SHELL = "shell";
export const EVENT_FORM = "form";
/** ChatStep.Status values. `ended` is the one status that settles a turn. */
export const STEP_ENDED = "ended";
@@ -1324,6 +1325,9 @@ export function newChatThread(sessionId = "") {
// derive from the two (see `approvalCard`).
permission: null,
permissionAnswer: "",
// The agent's pending structured question/form (OpenCode form.created). The
// card is derived from this frame; answers are local until submitted.
form: null,
// The reason a refused `chat_reply` left on the thread's error line, kept
// apart from any other error so a later accepted answer clears only this one.
permissionError: "",
@@ -1487,6 +1491,31 @@ export function threadPhase(thread, nowMillis) {
return turnPhase(threadRunningTools(thread.messages));
}
/**
* Folds one form frame into a conversation. A new form replaces the previous
* one; a resolved/cancelled update clears it; an update for a different id is
* ignored rather than reviving a dismissed card. The form is kept as data so the
* question card and every other client derive the same state.
*/
export function applyChatForm(thread, form) {
const current = thread ?? newChatThread(str(form?.session_id));
const id = str(form?.id);
if (id === "") return current;
const existing = current.form ?? null;
if (form?.cancelled === true) {
if (str(existing?.id) !== id) return current;
return { ...current, form: null };
}
if (form?.resolved === true) {
if (str(existing?.id) !== id) return current;
return { ...current, form: { ...existing, ...form, resolved: true } };
}
if (str(existing?.id) === id) {
return { ...current, form: { ...existing, ...form } };
}
return { ...current, form };
}
/**
* Applies one pushed `chat_event` frame to a conversation and returns the next
* thread. Any frame clears `queued` (the turn moved on); `user` echoes another
@@ -1515,6 +1544,8 @@ export function applyChatEvent(thread, frame, now = Date.now()) {
// that outlives the turn keeps showing after the turn's own indicator is gone.
case EVENT_SHELL:
return { ...current, shells: mergeShellFrame(current.shells, frame?.shell) };
case EVENT_FORM:
return applyChatForm(current, frame?.form);
// `usage` is recognised but not folded; it still cleared `queued` above.
case EVENT_USAGE:
default:
+3
View File
@@ -60,6 +60,7 @@ export const Protocol = Object.freeze({
CHAT_MESSAGES: "chat_messages",
CHAT_CLOSE: "chat_close",
CHAT_REOPEN: "chat_reopen",
CHAT_STAR: "chat_star",
// The shared live stream (C5). `chat_subscribe` attaches this connection to one
// session's stream (body: the session id); the server then pushes `chat_event`
// frames without a matching request id, so every client watching a session sees
@@ -67,6 +68,7 @@ export const Protocol = Object.freeze({
// detaches a subscription when the connection closes.
CHAT_SUBSCRIBE: "chat_subscribe",
CHAT_EVENT: "chat_event",
CHAT_ANSWER: "chat_answer",
// The composer's own commands (C8/C9). `chat_prompt` carries its body in
// `chat_prompt` (`{session_id,text,files?,operation_id}`) and its reply echoes
// `chat_queued` when the prompt waits behind an in-flight turn; `chat_interrupt`
@@ -111,6 +113,7 @@ export const ChatKeys = Object.freeze({
// unsolicited pushed frame on the shared stream).
SUBSCRIBE: "chat_subscribe",
EVENT: "chat_event",
ANSWER: "chat_answer",
// The composer's payloads (C8/C9). `chat_interrupt` deliberately has no key of
// its own: its body is the same `chat_query` the other session-scoped commands
// carry (internal/protocol/chat.go ChatQuery, Chat.kt interruptRequest), so a
+24
View File
@@ -347,6 +347,30 @@ export class PipelinesRepository {
return { session: response[ChatKeys.SESSION] ?? null, close: response[ChatKeys.CLOSE] ?? null };
}
/**
* Records the shared star on the server (chat_star), so every browser and
* device lists the same Starred group. Returns the updated session row.
*/
async starChat(sessionId, starred) {
const response = await this.#client.call({
type: Protocol.CHAT_STAR,
[ChatKeys.QUERY]: { session_id: sessionId, starred: Boolean(starred) },
});
return response[ChatKeys.SESSION] ?? null;
}
/**
* Answers one OpenCode form (the question tool's form). Answers is keyed by
* the form field key; the server forwards it to the paused tool call and the
* resolved form arrives on the normal chat_event stream.
*/
async answerChatForm(sessionId, formId, answers) {
return this.#client.call({
type: Protocol.CHAT_ANSWER,
[ChatKeys.ANSWER]: { session_id: sessionId, form_id: formId, answers },
});
}
/** Clears the closed state again, so a finished chat can be resumed. */
async reopenChat(sessionId) {
const response = await this.#client.call({
+4 -3
View File
@@ -12,6 +12,7 @@ import {
attentionDismissalSnapshot,
attentionEntries,
attentionRowDescription,
startOfLocalDay,
decodeAttentionDismissals,
encodeAttentionDismissals,
} from "../attention.js";
@@ -100,7 +101,7 @@ function renderAttentionBell() {
/** The number of entries the attention surface currently holds. */
function attentionCount() {
return attentionEntries(state.runs, state.attentionDismissed).length;
return attentionEntries(state.runs, state.attentionDismissed, { since: startOfLocalDay() }).length;
}
/**
@@ -154,7 +155,7 @@ function renderAttentionSheet() {
modal.close("attention-sheet");
return;
}
const entries = attentionEntries(state.runs, state.attentionDismissed);
const entries = attentionEntries(state.runs, state.attentionDismissed, { since: startOfLocalDay() });
const overlay = h("div", {
class: "attention-sheet",
role: "dialog",
@@ -259,7 +260,7 @@ function renderAttentionRow(entry, labelCounts = null) {
function openAttentionSheet() {
state.attentionSheetOpen = true;
state.attentionSnapshot = attentionDismissalSnapshot(
attentionEntries(state.runs, state.attentionDismissed),
attentionEntries(state.runs, state.attentionDismissed, { since: startOfLocalDay() }),
);
render();
}
+199 -12
View File
@@ -4,7 +4,7 @@
// in chat.js and markdown.js; this module owns the DOM and the chat wire wiring.
import { h } from "../dom.js";
import { writeChatStars } from "../chatStars.js";
import { readChatStars, writeChatStars } from "../chatStars.js";
import { describeError } from "../format.js";
import { SHELL_OUTPUT_LIMIT, newChatOperationId } from "../repository.js";
import { codeBlockLabel, parseInline, parseMarkdown } from "../markdown.js";
@@ -371,6 +371,23 @@ async function loadChatSessions(force = false) {
renderContent();
try {
const listed = await repo.chatSessions();
// One-time migration from the old local-only stars: upload this device's
// saved set, then let the server's shared set be authoritative everywhere.
const localStars = readChatStars();
if (localStars.size) {
for (const id of localStars) {
const session = listed.find((entry) => entry.id === id);
if (!session || session.starred) continue;
try {
const updated = await repo.starChat(id, true);
if (updated) Object.assign(session, updated);
} catch {
// Keep going: a missing session or a transient failure must not block
// the rest of the list.
}
}
writeChatStars(new Set());
}
// Keep this page's own verification chats, which the server intentionally
// never returns, at the head of the in-memory list (memory-only; see
// chatEphemeralIds). Everything else is the server's list, in its order.
@@ -379,6 +396,7 @@ async function loadChatSessions(force = false) {
state.chatEphemeralIds.has(session.id) && !listed.some((entry) => entry.id === session.id),
);
state.chatSessions = [...held, ...listed];
syncChatStarsFromSessions();
state.chatLoaded = true;
rt.touchView?.("chat");
// Fold this device's seen state in: the active chat has been read, and every
@@ -670,6 +688,26 @@ async function answerPermission(sessionId, requestId, decision) {
}
}
/**
* Answer the agent's pending question. The answer map is keyed by the form
* field's own key and mirrors OpenCode's form.reply body; the resolved form
* arrives on the stream and clears the card for every watching client.
*/
async function answerChatQuestion(sessionId, form, answers) {
if (!form?.id) return;
try {
await repo.answerChatForm(sessionId, form.id, answers);
const current = state.chatThreads.get(sessionId);
if (current?.form && current.form.id === form.id) {
setThread(sessionId, { form: { ...current.form, resolved: true } });
}
renderContent();
} catch (error) {
state.actionError = describeError(error);
renderContent();
}
}
/**
* The reconnect repair (C5): re-attach the open chat's stream and replace its
* conversation with the newest history page wholesale. Everything the gap could
@@ -884,10 +922,17 @@ async function reopenChatSession(id) {
}
/** Apply the echoed session (or the local closed flag) to the held row. */
function syncChatStarsFromSessions(sessions = state.chatSessions) {
state.chatStars = new Set(
(sessions ?? []).filter((session) => session.starred === true).map((session) => session.id),
);
}
function applyChatSessionUpdate(id, updated, closed) {
state.chatSessions = state.chatSessions.map((session) =>
session.id === id ? { ...session, ...(updated ?? {}), closed } : session,
);
syncChatStarsFromSessions();
}
// ---------------------------------------------------------------------------
@@ -1596,13 +1641,24 @@ 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);
/** Toggle one session's shared star on the server, then repaint its group. */
async function toggleChatStar(id) {
const wasStarred = state.chatStars?.has?.(id) === true;
state.chatSessions = state.chatSessions.map((session) =>
session.id === id ? { ...session, starred: !wasStarred } : session,
);
syncChatStarsFromSessions();
renderContent();
try {
const updated = await repo.starChat(id, !wasStarred);
if (updated) applyChatSessionUpdate(id, updated, updated.closed === true);
} catch (error) {
state.chatSessions = state.chatSessions.map((session) =>
session.id === id ? { ...session, starred: wasStarred } : session,
);
syncChatStarsFromSessions();
state.actionError = describeError(error);
}
renderContent();
}
@@ -1891,7 +1947,11 @@ function renderChatConversation() {
// answer. While it is actionable the chat pane offers a jump control and the
// running indicator stands down (a turn blocked on a decision is not generating).
const approval = approvalCard(thread?.permission, thread?.permissionAnswer);
const awaiting = approval?.actionable === true;
const form =
thread?.form && thread.form.resolved !== true && thread.form.cancelled !== true
? thread.form
: null;
const awaiting = approval?.actionable === true || form != null;
const bar = h("div", { class: "chat-bar" });
const titles = h("div", { class: "chat-bar-titles" });
@@ -1942,11 +2002,11 @@ function renderChatConversation() {
// blocked on a decision is not generating, so neither the spinner nor its clock
// shows. The composer's Stop control stays governed by thread.running.
const running = thread?.running === true && !awaiting;
if (rows.length === 0 && notices.length === 0 && !running && !approval) {
if (rows.length === 0 && notices.length === 0 && !running && !approval && !form) {
pane.append(h("div", { class: "chat-transcript-empty muted", text: CONVERSATION_EMPTY }));
} else {
pane.append(
renderChatTranscript(state.chatActiveId, rows, { notices, running, now: Date.now(), approval }),
renderChatTranscript(state.chatActiveId, rows, { notices, running, now: Date.now(), approval, form }),
);
}
if (thread?.error && thread?.loaded) {
@@ -2187,7 +2247,7 @@ function renderBackgroundTaskDetail(thread, shell) {
function renderChatTranscript(
sessionId,
rows,
{ notices = [], running = false, now = Date.now(), approval = null } = {},
{ notices = [], running = false, now = Date.now(), approval = null, form = null } = {},
) {
const wrap = h("div", { class: "chat-transcript-wrap" });
const transcript = h("div", {
@@ -2219,6 +2279,7 @@ function renderChatTranscript(
// after the running indicator when it is shown — so the pane's jump control
// and a fresh card both land at the end.
if (approval) transcript.append(renderChatApproval(sessionId, approval));
if (form) transcript.append(renderChatQuestion(sessionId, form));
wrap.append(transcript);
wrap.append(
h("button", {
@@ -2303,6 +2364,132 @@ function renderChatApproval(sessionId, card) {
return node;
}
/**
* The agent's structured question (OpenCode form with kind=question). Each form
* field is rendered with its options (single-select buttons or multi-select
* toggles) and, when the field is free-form or allows Other, a text input.
* Answers stay local until Send answer; the tool call is paused until then.
*/
function renderChatQuestion(sessionId, form) {
const node = h("div", {
class: "chat-question",
id: "chatQuestion",
"data-form-id": form.id,
});
const head = h("div", { class: "chat-question-head" });
head.append(h("div", { class: "chat-question-title", text: form.title || "Question" }));
head.append(
h("div", { class: "chat-question-status muted", text: "The agent is waiting for your answer." }),
);
node.append(head);
const answers = {};
const parts = [];
for (const field of form.fields ?? []) {
const key = String(field.key ?? "");
if (key === "") continue;
const options = Array.isArray(field.options) ? field.options : [];
const multi = field.type === "multiselect";
const part = h("div", { class: "chat-question-field" });
part.append(
h("div", { class: "chat-question-label", text: field.title || field.description || key }),
);
if (field.description && field.description !== field.title) {
part.append(h("div", { class: "chat-question-desc muted", text: field.description }));
}
if (options.length) {
const rows = h("div", { class: "chat-question-options" });
const buttons = [];
const chosen = () => (multi ? (Array.isArray(answers[key]) ? answers[key] : []) : [answers[key]].filter(Boolean));
const paint = () => {
const selected = new Set(chosen());
for (const button of buttons) {
const on = selected.has(button.dataset.value);
button.classList.toggle("selected", on);
button.setAttribute("aria-pressed", on ? "true" : "false");
}
};
for (const option of options) {
const value = String(option.value ?? option.label ?? "");
if (value === "") continue;
const button = h(
"button",
{
class: "chat-question-option",
type: "button",
"data-value": value,
"aria-pressed": "false",
text: option.label || value,
},
option.description
? h("span", { class: "chat-question-option-desc", text: option.description })
: null,
);
button.addEventListener("click", () => {
if (multi) {
const next = new Set(chosen());
if (next.has(value)) next.delete(value);
else next.add(value);
answers[key] = [...next];
} else {
answers[key] = value;
}
paint();
});
buttons.push(button);
rows.append(button);
}
part.append(rows);
}
if (field.custom === true || options.length === 0) {
const input = h("input", {
class: "chat-question-input",
type: "text",
placeholder: options.length ? "Type another answer" : "Your answer",
autocomplete: "off",
});
input.addEventListener("input", () => {
const value = input.value.trim();
if (value === "") delete answers[key];
else answers[key] = value;
});
part.append(input);
}
parts.push(part);
}
node.append(...parts);
const error = h("div", { class: "chat-question-error", role: "alert", hidden: true });
node.append(error);
const controls = h("div", { class: "chat-question-controls" });
const submit = h("button", {
class: "primary chat-question-submit",
type: "button",
text: "Send answer",
});
let sent = false;
submit.addEventListener("click", () => {
if (sent) return;
const missing = (form.fields ?? []).some((field) => {
if (!field.required) return false;
const value = answers[field.key];
return Array.isArray(value) ? value.length === 0 : !value;
});
if (missing) {
error.hidden = false;
error.textContent = "Answer the required questions before sending.";
return;
}
sent = true;
submit.disabled = true;
submit.textContent = "Sending…";
answerChatQuestion(sessionId, form, answers);
});
controls.append(submit);
node.append(controls);
return node;
}
/**
* The app's amber outlined Shield (`Icons.Outlined.Shield`): an inline SVG stroked
* with `currentColor` so the palette's warn hue actually tints it, unlike the
+73 -2
View File
@@ -20,10 +20,11 @@ import {
runBadge,
runBadgeMetaLine,
sortPipelines,
stageCountText,
summaryFields,
versionRow,
} from "../pipelines.js";
import { PIPELINE_GRAPH_EMPTY, mount as mountGraph } from "../graph.js";
import { PIPELINE_GRAPH_EMPTY, layoutGraph, mount as mountGraph } from "../graph.js";
import { statusIcon } from "../statusIcon.js";
import { writeGraphExpanded } from "../graphPrefs.js";
@@ -236,6 +237,69 @@ function fillPipelineRows(rowsEl) {
rowsEl.replaceChildren(...nodes);
}
// A list row's graph is a shape cue, not a reading surface: tiny nodes and
// straight routes, no labels or chips. The detail Graph tab is the real one.
const MINI_GRAPH_METRICS = Object.freeze({
nodeWidth: 26,
nodeHeight: 12,
hGap: 12,
pad: 2,
laneSpacing: 8,
terminalGap: 8,
trackStep: 6,
portSpacing: 4,
labelCharWidth: 0,
labelPadding: 0,
labelHeight: 0,
labelGap: 0,
});
const SVG_NS = "http://www.w3.org/2000/svg";
/** The pipeline's stages and their stage-to-stage routes, without terminals. */
function miniGraphShape(graph) {
const stages = graph?.stages ?? [];
const keys = new Set(stages.map((stage) => stage.key));
return {
stages: stages.map((stage) => ({
...stage,
edges: Object.fromEntries(
Object.entries(stage.edges ?? {}).filter(([, target]) => keys.has(target)),
),
})),
};
}
function renderPipelineMiniGraph(pipeline) {
const shape = pipeline.shape ?? pipeline.graph;
if (!shape?.stages?.length) return null;
const layout = layoutGraph(miniGraphShape(shape), MINI_GRAPH_METRICS);
if (!layout.nodes.length || !layout.width || !layout.height) return null;
const svg = document.createElementNS(SVG_NS, "svg");
svg.setAttribute("class", "pipeline-mini-graph");
svg.setAttribute("viewBox", `0 0 ${Math.ceil(layout.width)} ${Math.ceil(layout.height)}`);
svg.setAttribute("preserveAspectRatio", "xMidYMid meet");
svg.setAttribute("aria-hidden", "true");
svg.setAttribute("focusable", "false");
for (const edge of layout.edges) {
if (edge.points.length < 2) continue;
const line = document.createElementNS(SVG_NS, "polyline");
line.setAttribute("class", "pipeline-mini-edge");
line.setAttribute("points", edge.points.map((point) => `${point.x},${point.y}`).join(" "));
svg.append(line);
}
for (const node of layout.nodes) {
const rect = document.createElementNS(SVG_NS, "rect");
rect.setAttribute("class", "pipeline-mini-node");
rect.setAttribute("x", String(node.x));
rect.setAttribute("y", String(node.y));
rect.setAttribute("width", String(node.width));
rect.setAttribute("height", String(node.height));
rect.setAttribute("rx", "3");
svg.append(rect);
}
return h("span", { class: "pipeline-mini", "aria-hidden": "true" }, svg);
}
function renderPipelineRow(pipeline, latestRuns, runsKnown, now) {
const children = [
h(
@@ -244,8 +308,15 @@ function renderPipelineRow(pipeline, latestRuns, runsKnown, now) {
pipelineGlyph(),
h("span", { class: "row-title", text: pipeline.name || `pipeline ${pipeline.id}` }),
),
h("span", { class: "row-meta", text: pipelineSubtitle(pipeline) }),
];
const mini = renderPipelineMiniGraph(pipeline);
if (mini) children.push(mini);
children.push(
h("span", {
class: "row-meta",
text: stageCountText(pipeline.stages ?? pipeline.shape?.stages?.length ?? 0),
}),
);
const updated = pipelineUpdatedLine(pipeline);
if (updated) children.push(h("span", { class: "row-meta", text: updated }));
if (runsKnown) {