web: installable app, diff viewer history, calmer chat

- The diff viewer is a centered panel over a dim scrim (clicking outside closes),
  and the browser Back button closes the open viewer/audit/artifact viewer via a
  modal history entry. Transient sheets opt out (they must never undo an
  in-app navigation on close).
- The page is installable: web app manifest, 192/512/maskable icons, apple
  meta, and a shell service worker that never caches the socket or artifacts.
- Chat: operator bubbles are accent-tinted, agent bubbles neutral with an accent
  edge; the tool summary is a quiet line outside the message; the star and more
  controls are compact 20px corner icons inside the row.
- The Refresh button's tooltip shows the last data arrival (manual or socket),
  per destination.
This commit is contained in:
2026-10-20 01:26:20 +01:00
parent 2a8a5bf334
commit 9a450e0ebb
14 changed files with 259 additions and 23 deletions
+45
View File
@@ -77,6 +77,22 @@ function defaultServerUrl() {
const client = new PipelinesClient();
const repo = new PipelinesRepository(client);
// Register the app's shell service worker where the browser allows it (a secure
// context: https, localhost, or the desktop app). On a plain-LAN http origin the
// page still works; only installation/offline caching is unavailable there.
if (typeof navigator !== "undefined" && "serviceWorker" in navigator) {
const secure =
typeof location !== "undefined" &&
(location.protocol === "https:" ||
location.hostname === "localhost" ||
location.hostname === "127.0.0.1");
if (secure) {
window.addEventListener("load", () => {
navigator.serviceWorker.register("/sw.js").catch(() => undefined);
});
}
}
// Read the persisted settings once: the server URL falls back to the page's own
// proxy endpoint when unset, and the workspace starts blank when unset. Both the
// configured value and the draft start from storage.
@@ -166,6 +182,9 @@ const state = {
chatStars: readChatStars(),
// Whether the CLOSED chats group is expanded (the chevron beside its name).
chatClosedOpen: false,
// The last time each destination's data arrived (manual refresh or a socket
// push); the list's Refresh button shows it on hover.
lastUpdated: {},
// 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.
@@ -1102,11 +1121,32 @@ function renderContent() {
}
}
/** The last-updated words for a view, local time, or the not-yet-loaded note. */
function lastUpdatedTitle(view) {
const at = Number(state.lastUpdated?.[view] ?? 0);
if (!(at > 0)) return "Not refreshed yet";
return `Last updated ${new Date(at).toLocaleTimeString([], {
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
})}`;
}
/** Record that a view's data just arrived, and refresh the hover title in place. */
function touchView(view = state.view) {
state.lastUpdated = { ...(state.lastUpdated ?? {}), [view]: Date.now() };
if (view !== state.view) return;
const button = document.querySelector('.list-pane [data-refresh="true"]');
if (button) button.title = lastUpdatedTitle(view);
}
function refreshButton() {
return h("button", {
class: "ghost",
type: "button",
text: "Refresh",
title: lastUpdatedTitle(state.view),
"data-refresh": "true",
onclick: () => loadCurrentView(true),
});
}
@@ -1554,6 +1594,7 @@ async function loadCurrentView(force = false, { runsFresh = false } = {}) {
state.usage = usage;
state.runsLoaded = true;
}
touchView(state.view);
// The nav badge reads the pipeline count, and the Pipelines destination is
// one click away: load that list once when it has not been seen, whether the
// runs came from the watch's resync or a direct read.
@@ -1830,6 +1871,8 @@ function applyRunEvent(frame) {
} else if (fold.runs !== state.runs) {
state.runs = fold.runs;
listChanged = true;
touchView("runs");
if (state.view === "pipelines") touchView("pipelines");
renderRunState();
// A terminal transition also settles the usage aggregate (the active
// count), which the delta does not carry; one server read refreshes it. A
@@ -1844,6 +1887,7 @@ function applyRunEvent(frame) {
const detailChanged = folded !== detail;
if (detailChanged) {
state.runDetail = folded;
touchView("runs");
renderRunState();
}
if (runDetailNeedsFullSync(frame) && (detailChanged || listChanged)) {
@@ -2106,6 +2150,7 @@ const runtime = {
render,
renderContent,
renderHeader,
touchView,
focusDetailHeading,
focusListHeading,
endpointConfigured,
+50
View File
@@ -164,6 +164,7 @@ function focusElement(element) {
*/
export function createModalController(options = {}) {
const document_ = options.document ?? globalThis.document;
const window_ = options.window ?? globalThis.window;
const getLayer =
typeof options.layer === "function"
? options.layer
@@ -196,6 +197,50 @@ export function createModalController(options = {}) {
let keydownBound = false;
let focusinBound = false;
let fallbackMode = false;
// One history entry per open modal, so the browser Back button closes it the
// same way Escape and the backdrop do. A modal that closes through the UI
// pops its own entry instead of leaving a dead one behind.
let historyPushed = false;
let historyClosing = false;
function pushModalHistory(id) {
if (historyPushed || !window_?.history) return;
try {
window_.history.pushState(
{ ...(window_.history.state ?? {}), pipelinesModal: id },
"",
);
historyPushed = true;
} catch {
// A history-refusing environment simply keeps the UI close paths.
}
}
function popModalHistory() {
if (!historyPushed || historyClosing) return;
historyPushed = false;
try {
// Only pop our own entry. If the app navigated while the dialog was open,
// its route entry is on top now; calling back() here would undo that
// navigation (the dialog's own entry is buried under it).
if (window_.history?.state?.pipelinesModal == null) return;
window_.history.back();
} catch {
// Nothing to pop.
}
}
if (window_?.addEventListener) {
window_.addEventListener("popstate", () => {
if (!historyPushed) return;
historyPushed = false;
const entry = top();
if (!entry) return;
historyClosing = true;
closeEntry(entry, { restore: true });
historyClosing = false;
});
}
function layer() {
return getLayer() ?? document_?.body ?? null;
@@ -471,6 +516,7 @@ export function createModalController(options = {}) {
releaseIfEmpty();
}
if (restore && wasTop) restoreFocus(entry);
if (!stack.length) popModalHistory();
return true;
}
@@ -559,6 +605,10 @@ export function createModalController(options = {}) {
entryOptions.renderManaged !== false,
);
applyStackState();
// Only overlays that act as their own view carry a history entry (the
// viewers). A transient sheet must not, or closing it while the app
// navigates would undo that navigation with history.back().
if (entryOptions.history !== false) pushModalHistory(id);
if (entryOptions.focus !== false) focusInside(entry.panel);
return entry.panel;
}
+1
View File
@@ -177,6 +177,7 @@ function renderAttentionSheet() {
overlay.append(sheet);
attentionLayer.replaceChildren(overlay);
modal.open("attention-sheet", overlay, {
history: false,
// The sheet is rebuilt by renderAttentionSheet, not by renderContent's
// staged set, so it is managed imperatively rather than reconciled away.
renderManaged: false,
+8 -4
View File
@@ -379,6 +379,7 @@ async function loadChatSessions(force = false) {
);
state.chatSessions = [...held, ...listed];
state.chatLoaded = true;
rt.touchView?.("chat");
// Fold this device's seen state in: the active chat has been read, and every
// session seen for the first time gets a baseline so pre-existing chats are
// not all reported as new.
@@ -1079,6 +1080,7 @@ function releaseAttachments(attachments) {
function onChatFrame(message) {
const frame = message?.chat_event;
if (!frame || !frame.session_id) return;
rt.touchView?.("chat");
const sessionId = frame.session_id;
const thread = state.chatThreads.get(sessionId);
if (!thread) return;
@@ -2405,12 +2407,14 @@ function renderChatAgentTurn(turn, streaming = false, elapsedMillis = () => 0) {
const bubble = h("div", { class: "chat-bubble agent-bubble" });
const steps = turn.reasoningSteps;
if (steps.length > 0) bubble.append(renderChatReasoning(turn, streaming));
if (turn.tools.length > 0) {
const tools = renderChatToolCalls(turn, { streaming, elapsedMillis });
if (tools) bubble.append(tools);
}
if (turn.answer.trim() !== "") bubble.append(renderMarkdown(turn.answer));
wrap.append(bubble);
// The tool summary is a quiet line beside the message, not a highlighted chip
// inside it; its panel still opens right there.
if (turn.tools.length > 0) {
const tools = renderChatToolCalls(turn, { streaming, elapsedMillis });
if (tools) wrap.append(tools);
}
return wrap;
}
+3 -1
View File
@@ -88,6 +88,8 @@ function openChangeViewer(files, startIndex, trigger = null) {
"aria-modal": "true",
"aria-label": "Diff viewer",
});
const panel = h("div", { class: "change-viewer-panel" });
overlay.append(panel);
overlay.addEventListener("click", (event) => {
if (event.target === overlay) closeChangeViewer();
});
@@ -197,7 +199,7 @@ function openChangeViewer(files, startIndex, trigger = null) {
body.append(renderRenderedDiff(entry));
}
overlay.replaceChildren(head, controls, body);
panel.replaceChildren(head, controls, body);
};
renderViewer();