web: keep chat stable while streaming and refresh Settings

Preserve scroll intent for touch scrolling, coalesce live frames into one paint,
keep stable dialogs mounted across re-renders, and add a Settings refresh that
pings the server for a fresh build/time card.
This commit is contained in:
2026-10-20 03:35:45 +01:00
parent d5cda887ee
commit 4072698731
5 changed files with 82 additions and 4 deletions
+1
View File
@@ -165,6 +165,7 @@ to it, but the server never lists it and a reload drops it.
| B2 | Pipeline list mini graph | `list_pipelines` (`shape`) | done — each summary now carries the current version's parsed graph as `shape`; the browser draws a label-free miniature from the real `layoutGraph` with terminal-free stage routes. The row shows the name, the shape and only `{N stages}`; the cryptic `id {n} · v{n} · …` line is gone. Verified at 390×844 against the live server: 9 rows, 9 miniatures, and the detail still owns the full Graph tab. Additive field; older clients ignore it. |
| B3 | Equal phone dock cells | — | done — the narrow dock is a four-cell grid (one cell per destination plus Search) with a subgrid for the tablist, so every control has the same width and height. At 390×844 the measured widths are 92/92/92/92 and the row is 48px high. The phone shell uses `100svh` so a browser toolbar cannot hide the tab row while leaving only the Connected/Settings status row visible. |
| B4 | Full-height pipeline Source | — | done — the Source block no longer caps itself at `60vh`; it is as tall as its content and the detail pane owns the scroll. Verified at 390×844: a 4386px definition sits in the full pane (656px viewport) and scrolls. |
| B9 | Scroll intent, stable overlays and a Settings refresh | — | done — a touch/pointer scroll now marks operator intent, so scrolling up during streaming is not snapped back by the next frame (verified: scrollTop stayed at the top while a synthetic text frame arrived). Open rename/close dialogs are marked `data-modal-stable`; the modal controller keeps the mounted panel, focus, typed value and selection across streaming re-renders, so the rename no longer blinks/reappears and its `modal-in` animation runs once. Bursts of chat frames are coalesced to one paint per animation frame. Settings gained a `Refresh` action that pings the server and repaints the build/time card. |
| B8 | Composer keeps focus and the running line stays stable | — | done — a live frame re-renders the transcript, so the composer now captures and restores its focus, value and selection (verified in a real browser: a synthetic `chat_event` arrived while the caret sat at 8–14 and the input stayed focused with the same value/selection). The running indicator is one ellipsised line that updates in place for the longest-running tool instead of adding/removing a line per call; measured height stayed 52px across tool start/finish until the step ended. Pipeline-list miniatures are right-aligned at the row's trailing edge. |
| B7 | Chat detail is a real history entry with a compact Back | `/chat/:id` | done — opening a session pushes `/chat/:id`, so Android's back gesture/browser Back returns to the chat list instead of the previous destination. The conversation header now owns a 32px back control matching the create pane (the full-width "Back to list" row is gone for chat; it remains on the other detail panes). Verified at 390×844: the header control reads `Back to chats`, the URL changes to `/chat/ses_…`, pressing it returns to `/chat` with the list restored, and `history.back()` from a reopened chat does the same. |
| B6 | Agent questions are answerable in the browser | `chat_event` (`form`), `chat_answer` | done — OpenCode's question tool pauses inside a `form.created` event; the broker now maps `form.created` / `form.replied` / `form.cancelled` to a `form` chat_event, the browser renders a question card with the form's options and free-text fields, and `chat_answer` posts the field-keyed answer to `/api/session/{id}/form/{id}/reply`. A question for a backgrounded chat also raises the existing browser notification. Verified end to end with a real model turn: the card appeared with a `Demo colour` field, selecting Red and pressing `Send answer` cleared it and the same turn completed with "You chose Red for the demo."; the OpenCode form normalizer is unit-tested. |
+10
View File
@@ -109,3 +109,13 @@
.settings-card-text { display: block; flex: 1; min-width: 0; }
.settings-card-chevron { color: var(--muted); font-size: 20px; line-height: 1; }
.settings-card .card-desc { display: block; -webkit-line-clamp: unset; }
/* Settings has no list to reload; its Refresh asks the server for a fresh
build/time pong and repaints the connection card. */
.settings-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: var(--space-s);
}
.settings-refresh { flex: 0 0 auto; }
+10
View File
@@ -389,6 +389,16 @@ export function createModalController(options = {}) {
entry.options = { ...entry.options, ...staged.options };
if (entry.trigger == null && staged.trigger) entry.trigger = staged.trigger;
if (entry.panel === staged.panel) return false;
// A stable dialog keeps its mounted panel across streaming re-renders. A
// rebuild would restart the modal-in animation (the rename dialog visibly
// blinked/reappeared on every chat frame) and discard whatever the operator
// had typed into it.
if (
entry.panel?.getAttribute?.("data-modal-stable") === "true" &&
staged.panel?.getAttribute?.("data-modal-stable") === "true"
) {
return false;
}
const remembered = rememberFocus(entry.panel);
const oldPanel = entry.panel;
if (typeof oldPanel.replaceWith === "function" && oldPanel.parentElement) {
+28 -3
View File
@@ -628,6 +628,25 @@ function settleChatThreads() {
* ignored); the server only pushes frames for sessions this connection subscribed
* to, so this is a no-op in practice until a chat is opened.
*/
let chatRenderScheduled = false;
/**
* Coalesce a burst of pushed frames into one paint. A turn can emit many text
* and tool frames in the same animation frame; rebuilding the transcript for
* each one made the text flicker and restarted in-flight animations. State is
* folded immediately; only the DOM paint is deferred.
*/
function scheduleChatRender() {
if (chatRenderScheduled) return;
chatRenderScheduled = true;
const paint = () => {
chatRenderScheduled = false;
renderContent();
};
if (typeof requestAnimationFrame === "function") requestAnimationFrame(paint);
else setTimeout(paint, 0);
}
function onChatEvent(frame) {
const sessionId = String(frame?.session_id ?? "").trim();
if (!sessionId || !state.chatThreads.has(sessionId)) return;
@@ -641,7 +660,7 @@ function onChatEvent(frame) {
// 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();
scheduleChatRender();
if (!knownTurn) scheduleHistorySync(sessionId, messageId);
}
@@ -693,7 +712,7 @@ function onChatPermission(frame) {
next.permissionError = "";
}
state.chatThreads.set(sessionId, next);
if (sessionId === state.chatActiveId) renderContent();
if (sessionId === state.chatActiveId) scheduleChatRender();
}
/**
@@ -1175,7 +1194,7 @@ function onChatFrame(message) {
const running = runningAfterFrame(thread.running, frame);
if (queued === thread.queued && running === thread.running) return;
setThread(sessionId, { queued, running });
if (sessionId === state.chatActiveId) renderContent();
if (sessionId === state.chatActiveId) scheduleChatRender();
}
/** Add one local command line to a conversation's transcript. */
@@ -2125,6 +2144,7 @@ function renderChatRenameDialog(session) {
role: "dialog",
"aria-modal": "true",
"aria-label": CHAT_RENAME_TITLE,
"data-modal-stable": "true",
});
overlay.addEventListener("click", (event) => {
if (event.target === overlay) dismissChatRename();
@@ -3336,6 +3356,7 @@ function renderChatCloseDialog(session) {
role: "dialog",
"aria-modal": "true",
"aria-label": CLOSE_CHAT_TITLE,
"data-modal-stable": "true",
});
overlay.addEventListener("click", (event) => {
if (event.target === overlay) dismissChatClose();
@@ -3444,6 +3465,10 @@ function afterChatRender() {
// scrolls therefore leaves the intent alone.
let gesture = false;
const beginGesture = () => {
// A touch/pointer scroll is the operator's own intent, exactly like a wheel.
// Without this, a phone scroll up never cleared `chatFollowing`, so the next
// streamed frame snapped the transcript back to the bottom.
state.chatUserIntent = true;
gesture = true;
};
const endGesture = () => {
+33 -1
View File
@@ -49,7 +49,18 @@ export function createSettingsView(rt) {
function renderSettingsView() {
const pane = h("div", { class: "settings" });
pane.append(
h("h1", { class: "settings-page-title", id: "detailTitle", tabindex: "-1", text: "Settings" }),
h(
"div",
{ class: "settings-head" },
h("h1", { class: "settings-page-title", id: "detailTitle", tabindex: "-1", text: "Settings" }),
h("button", {
id: "settingsRefresh",
class: "ghost settings-refresh",
type: "button",
text: "Refresh",
onclick: () => refreshSettingsStatus(),
}),
),
renderSettingsConnection(),
renderSettingsWorkspace(),
renderSettingsNotifications(),
@@ -261,6 +272,27 @@ function serverUrlSupportingText() {
* aria-invalid and the error tint) so an invalid Connect never needs a full
* re-render and the field being typed in is never rebuilt.
*/
/**
* Refresh the Settings page's live server facts. The page has no list to reload
* (its fields are local and its cards derive from the connection), so this sends
* the same ping the first connection uses and repaints the status card with the
* server's current build/time. It never reconnects or mutates a setting.
*/
async function refreshSettingsStatus() {
if (state.connection.kind === "connected") {
try {
const reply = await repo.ping();
state.serverProtocol = reply?.protocol ?? null;
state.serverBuild = reply?.build ?? null;
state.serverTime = reply?.time ?? null;
} catch {
// The connection card already carries the honest socket state; a ping
// failure must not replace it with a second, stale error line.
}
}
renderContent();
}
function refreshServerUrlError() {
const field = document.getElementById("settingsServerUrl");
const helper = document.getElementById("settingsUrlHelper");