web: sticky sections, spotlight search, and live sync for other clients' prompts

- Sticky sections: a run/pipeline/template keeps the section you chose when you
  open another one, and the choice persists across reloads (localStorage per
  destination). A stage deep link still opens the Graph.
- Search is a Spotlight: a modal overlay opened with Ctrl+/ (Cmd+/ too), arrow keys
  move the selected result, Enter opens it, the query/kind/sort/selection resume on
  the next open, and an artifact result opens the artifact itself (media in the
  viewer, anything else in a tab) instead of the run's visit pane.
- Live sync: the server only emits a user frame for prompts sent through it, so a
  message typed in the OpenCode UI appeared only after a refresh. When a frame for
  an unknown turn arrives, the open conversation now reads the newest history once,
  which brings the user message in live.
This commit is contained in:
2026-10-19 20:45:39 +01:00
parent a7991077d2
commit ff45c0ec86
6 changed files with 261 additions and 35 deletions
+32 -6
View File
@@ -78,6 +78,29 @@ const repo = new PipelinesRepository(client);
// configured value and the draft start from storage.
const initialWorkspace = readWorkspace(localStorage);
/** The three detail section choices are sticky and survive a reload. */
const SECTION_STORAGE_KEYS = {
pipelines: "pipelines.web.pipelineTab.v1",
runs: "pipelines.web.runTab.v1",
templates: "pipelines.web.templateTab.v1",
};
function readSection(key, fallback) {
try {
return localStorage.getItem(SECTION_STORAGE_KEYS[key]) || fallback;
} catch {
return fallback;
}
}
function writeSection(key, value) {
try {
localStorage.setItem(SECTION_STORAGE_KEYS[key], value);
} catch {
// Storage may be unavailable; the in-memory choice still applies.
}
}
const state = {
view: "pipelines",
url: readServerUrl(localStorage) || defaultServerUrl(),
@@ -127,7 +150,7 @@ const state = {
pipelineFilters: { ...EMPTY_PIPELINE_FILTERS },
pipelineSort: "server_order",
pipelineMenu: null,
pipelineTab: "summary",
pipelineTab: readSection("pipelines", "summary"),
// The mounted workflow graph (P6) and whether its panel is expanded. The
// handle is dropped on every re-render so its listeners can never leak.
pipelineGraph: null,
@@ -145,7 +168,7 @@ const state = {
// failed/absent validate stores null so the card/detail say "unavailable".
templateGraphs: new Map(),
selectedTemplateKey: null,
templateTab: "summary",
templateTab: readSection("templates", "summary"),
// The create-from-template dialog (P5): whether it is open, the name being
// typed, whether a validate+submit is in flight, the server's refusal text and
// the created pipeline's name (null until a success, which is also what makes
@@ -165,7 +188,7 @@ const state = {
// expand/collapse choices for the input/output field sections and the summary
// artifacts section. The stage pane is the timeline's per-visit panel; its
// section expansion is reseeded each time a pane is opened.
runTab: "summary",
runTab: readSection("runs", "summary"),
runSections: new Set(),
runStagePane: null,
runStageSections: new Set(),
@@ -185,6 +208,8 @@ const state = {
// changes, plus the pure debounce/stale-token sequencer. Opening or closing the
// search leaves state.view, the selection and the loaded data untouched.
searchOpen: false,
// The keyboard-selected result (ArrowUp/Down) and the row Enter opens.
searchActiveIndex: 0,
searchQuery: "",
searchKind: DEFAULT_SEARCH_KIND,
searchSort: DEFAULT_SEARCH_SORT,
@@ -683,6 +708,7 @@ function selectSection(key) {
if (state.view === "pipelines") state.pipelineTab = key;
else if (state.view === "runs") state.runTab = key;
else if (state.view === "templates") state.templateTab = key;
writeSection(state.view, key);
renderContent();
focusSectionTab(key);
}
@@ -1315,7 +1341,7 @@ async function applyRoute(route) {
state.selectedPipelineId = r.id;
state.pipelineRequestedVersion = version;
state.pipelineDetail = null;
state.pipelineTab = r.kind === "pipelineStage" ? "graph" : "summary";
if (r.kind === "pipelineStage") state.pipelineTab = "graph";
state.pipelineGraphSelection = r.kind === "pipelineStage" ? r.stageKey : null;
renderContent();
if (!connected()) return;
@@ -1798,7 +1824,7 @@ function resetRunDetailState() {
state.runGraph?.unmount();
state.runGraph = null;
state.runDetail = null;
state.runTab = "summary";
// The section stays put when the operator opens another run (sticky, persisted).
state.runSections = new Set();
state.runStagePane = null;
state.runStageSections = new Set();
@@ -1846,7 +1872,7 @@ async function missingRunFallback(err) {
*/
function resetPipelineDetailState() {
state.pipelineDetail = null;
state.pipelineTab = "summary";
// The section stays put when the operator opens another pipeline.
state.pipelineGraphSelection = null;
state.versionsExpanded = false;
}
+23
View File
@@ -576,8 +576,31 @@ function onChatEvent(frame) {
if (!sessionId || !state.chatThreads.has(sessionId)) return;
markBackgroundChatUnseen(sessionId);
const thread = state.chatThreads.get(sessionId);
const messageId = String(frame?.message_id ?? "");
// The user turn of a prompt sent from another client (the OpenCode UI, not this
// page) never reaches the broker, so no `user` frame exists for it: only the
// assistant's frames arrive. When the first frame of an unknown turn arrives,
// read the newest history once so the user message (and anything else the page
// missed) appears without a manual refresh.
const knownTurn = messageId !== "" && (thread.messages ?? []).some((m) => m?.id === messageId);
state.chatThreads.set(sessionId, applyChatEvent(thread, frame, Date.now()));
renderContent();
if (!knownTurn) scheduleHistorySync(sessionId, messageId);
}
/** At most one history read per unseen turn, and only for the open conversation. */
const historySyncTimers = new Map();
const historySyncedFor = new Map();
function scheduleHistorySync(sessionId, messageId) {
if (!messageId || sessionId !== state.chatActiveId) return;
if (historySyncedFor.get(sessionId) === messageId) return;
historySyncedFor.set(sessionId, messageId);
if (historySyncTimers.has(sessionId)) return;
const timer = setTimeout(() => {
historySyncTimers.delete(sessionId);
loadChatHistory(sessionId).catch(() => {});
}, 250);
historySyncTimers.set(sessionId, timer);
}
/**
+109 -8
View File
@@ -4,6 +4,8 @@
import { h } from "../dom.js";
import { describeError } from "../format.js";
import { resolveArtifactUrl } from "../serverUrl.js";
import { ArtifactKind, artifactKind } from "../artifacts.js";
import {
DEFAULT_SEARCH_KIND,
DEFAULT_SEARCH_SORT,
@@ -28,6 +30,37 @@ export function createSearchView(rt) {
const { state, repo, searchHost } = rt;
let searchTimer = null;
let searchEdit = null;
// The last search is resumed on the next open (the field, kind, sort and the
// selected row). Persisted so it also survives a reload.
const SEARCH_STORAGE_KEY = "pipelines.web.search.v1";
function saveSearchState() {
try {
localStorage.setItem(
SEARCH_STORAGE_KEY,
JSON.stringify({
query: state.searchQuery,
kind: state.searchKind,
sort: state.searchSort,
activeIndex: state.searchActiveIndex,
}),
);
} catch {
// Storage may be unavailable; the in-memory state still resumes in this page.
}
}
function restoreSearchState() {
if (state.searchQuery !== "") return;
try {
const saved = JSON.parse(localStorage.getItem(SEARCH_STORAGE_KEY) || "null");
if (!saved || typeof saved.query !== "string") return;
state.searchQuery = saved.query;
if (SEARCH_KINDS.some((k) => k.value === saved.kind)) state.searchKind = saved.kind;
if (SEARCH_SORTS.some((k) => k.value === saved.sort)) state.searchSort = saved.sort;
state.searchActiveIndex = Number.isInteger(saved.activeIndex) ? Math.max(0, saved.activeIndex) : 0;
} catch {
// A corrupt value simply starts empty.
}
}
// Where focus goes when the panel closes: the rail or dock Search control that
// opened it, so Escape/Close never drops the operator on <body>.
let searchTriggerId = null;
@@ -45,11 +78,20 @@ function openSearch() {
if (state.searchOpen) return;
const trigger = document.activeElement;
searchTriggerId = trigger && trigger.id ? trigger.id : null;
restoreSearchState();
state.searchOpen = true;
state.searchError = "";
state.searchFocusPending = true;
renderHeader();
renderSearch();
// Resume: the previous results show immediately, and a non-blank query is
// refreshed so the list is not stale.
if (searchQuerySendable(state.searchQuery)) {
state.searchLoading = true;
const sent = state.searchSequencer.begin(state.searchSequencer.edit(state.searchQuery));
if (sent) runSearch(sent);
refreshSearch();
}
}
/**
@@ -61,15 +103,12 @@ function openSearch() {
*/
function closeSearch() {
cancelSearchDebounce();
saveSearchState();
// Recording an empty edit advances the sequencer, so a reply for a request
// still in flight can no longer be accepted.
state.searchSequencer.edit("");
state.searchOpen = false;
state.searchQuery = "";
state.searchResults = [];
state.searchLoading = false;
state.searchError = "";
state.searchLoaded = false;
state.searchFocusPending = false;
renderHeader();
renderSearch();
@@ -78,6 +117,11 @@ function closeSearch() {
if (trigger && trigger.getClientRects().length > 0) trigger.focus();
}
/** Keep the keyboard-selected row visible in the results list. */
function scrollActiveSearchRow() {
document.querySelector("#searchResults .search-row.active")?.scrollIntoView({ block: "nearest" });
}
function cancelSearchDebounce() {
if (searchTimer) {
clearTimeout(searchTimer);
@@ -165,6 +209,7 @@ async function runSearch(sent) {
return;
}
state.searchResults = Array.isArray(reply.results) ? reply.results : [];
state.searchActiveIndex = 0;
state.searchLoading = false;
state.searchError = "";
state.searchLoaded = true;
@@ -242,9 +287,23 @@ function renderSearch() {
"aria-label": "Search",
oninput: (event) => onSearchInput(event.target.value),
onkeydown: (event) => {
const shown = sortSearchResults(
filterSearchResults(state.searchResults, state.searchKind),
state.searchSort,
);
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
event.preventDefault();
if (!shown.length) return;
const delta = event.key === "ArrowDown" ? 1 : -1;
state.searchActiveIndex = (state.searchActiveIndex + delta + shown.length) % shown.length;
refreshSearch();
scrollActiveSearchRow();
return;
}
if (event.key === "Enter") {
event.preventDefault();
sendSearchNow();
if (shown.length) routeSearchResult(shown[state.searchActiveIndex] ?? shown[0]);
else sendSearchNow();
}
},
}),
@@ -278,9 +337,17 @@ function renderSearch() {
const area = h("div", { id: "searchResults", class: "search-results", "aria-live": "polite" });
fillSearchResults(area);
searchHost.replaceChildren(
h("div", { id: "searchPanel", class: "search-panel", role: "search", "aria-label": "Search" }, fieldRow, controls, area),
const panel = h(
"div",
{ id: "searchPanel", class: "search-panel", role: "dialog", "aria-modal": "true", "aria-label": "Search" },
h("div", { class: "search-modal", role: "search" }, fieldRow, controls, area),
);
// A spotlight: clicking the dimmed backdrop closes it (the modal itself stops).
panel.addEventListener("click", (event) => {
if (event.target === panel) closeSearch();
});
panel.querySelector(".search-modal")?.addEventListener("click", (event) => event.stopPropagation());
searchHost.replaceChildren(panel);
if (state.searchFocusPending) {
document.getElementById("searchInput")?.focus();
state.searchFocusPending = false;
@@ -306,7 +373,15 @@ function fillSearchResults(area) {
if (body.kind === "error") {
nodes.push(h("div", { class: "search-error", text: body.message }));
} else if (body.kind === "results") {
for (const hit of shown) nodes.push(renderSearchResultRow(hit));
state.searchActiveIndex = Math.min(Math.max(0, state.searchActiveIndex), shown.length - 1);
shown.forEach((hit, index) => {
const row = renderSearchResultRow(hit);
if (index === state.searchActiveIndex) {
row.classList.add("active");
row.setAttribute("aria-selected", "true");
}
nodes.push(row);
});
} else if (body.kind === "searching") {
nodes.push(
h(
@@ -387,6 +462,24 @@ function renderSearchResultRow(hit) {
async function routeSearchResult(hit) {
const target = searchTarget(hit);
if (!target) return;
// An artifact hit opens the artifact, not the run/visit that recorded it: media
// in the viewer, anything else in a tab. Nothing to show means no navigation.
if (hit?.kind === "artifact" && hit.artifact?.url) {
const artifact = hit.artifact;
const resolved = resolveArtifactUrl(state.url, artifact.url);
if (!resolved) return;
closeSearch();
const kind = artifactKind(artifact.content_type, artifact.name);
if (kind === ArtifactKind.Image || kind === ArtifactKind.Video) {
rt.views.dialogs.openArtifactViewer(
[{ url: artifact.url, name: artifact.name, content_type: artifact.content_type }],
0,
);
} else {
window.open(resolved, "_blank", "noopener,noreferrer");
}
return;
}
closeSearch();
state.error = "";
if (target.kind === "pipeline") {
@@ -407,6 +500,14 @@ async function routeSearchResult(hit) {
}
}
// Ctrl+/ (Cmd+/ on macOS) is the Spotlight shortcut: toggle from anywhere.
document.addEventListener("keydown", (event) => {
if (!(event.ctrlKey || event.metaKey) || event.key !== "/") return;
event.preventDefault();
if (state.searchOpen) closeSearch();
else openSearch();
});
return {
openSearch,
closeSearch,
+1 -1
View File
@@ -38,7 +38,7 @@ export function createTemplatesView(rt) {
* fields can never drift.
*/
function resetTemplateCreateState() {
state.templateTab = "summary";
// The section is sticky across template selections (it is persisted by the shell).
// A different template reseeds the create dialog, so a name typed for one
// template can never be submitted against another.
state.templateCreateOpen = false;