web: give chat details a real back route

Opening a chat now pushes /chat/:id, so Android/browser Back returns to the
chat list rather than the previous destination. The conversation header owns a
compact Back to chats control matching the create pane, replacing the
full-width Back to list row on phones.
This commit is contained in:
2026-10-20 03:25:31 +01:00
parent 526c19fc21
commit c291327610
6 changed files with 90 additions and 10 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. |
| 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. |
| B5 | Sign-in reaches the app, and stays signed in | — | done — a successful `POST /login` redirects to the requested path; a fresh browser with no saved endpoint now connects to its own origin instead of stopping on Settings/"Not configured". The session cookie is `SameSite=Lax` (a Strict cookie was withheld when the installed app or another app opened the page) and carries both `Max-Age` and `Expires` for Remember me. Verified in headless Chrome: login with `next=/pipelines` reached the connected list, and a closed/reopened page stayed signed in with no local endpoint. **iOS Safari/PWA itself was not directly exercised**, so the toolbar/cookie fixes are targeted at that report rather than claimed as device-verified. |
+8
View File
@@ -889,3 +889,11 @@
.chat-question-error { color: var(--bad); font-size: 12px; }
.chat-question-controls { display: flex; gap: 10px; }
.chat-question-submit { padding: 6px 12px; }
/* The conversation's own compact Back control, matching the create pane. The
narrow layout is where the chat list is covered; wide keeps the two panes. */
.chat-bar-lead { display: flex; align-items: flex-start; gap: 8px; min-width: 0; flex: 1 1 auto; }
.chat-back { display: none; }
@media (max-width: 599px) {
.chat-back { display: inline-flex; }
}
+34 -6
View File
@@ -1004,9 +1004,9 @@ function closeDetail(view) {
? { root: ".list.runs", attribute: "data-run-id", value: String(state.selectedRunId) }
: null;
if (view === "chat") {
state.chatActiveId = null;
state.chatCreate = null;
renderContent();
const route = { kind: "chat" };
pushRoute(route);
applyRoute(route);
restoreListFocus(restore);
return;
}
@@ -1204,7 +1204,9 @@ function renderContent() {
// The transcript, not the pane, is chat's one scroller, so its detail body
// is not wrapped in a second pane-scroll.
const pane = h("section", { class: "detail-pane", "aria-label": "Chat detail" });
if (detailOpen) pane.append(backControl(view));
// The conversation and create panes each put their own compact Back control
// in the chat bar; the generic full-width pane-back row is for the other
// detail panes, which have no header of their own.
pane.append(state.chatCreate ? renderChatCreate() : renderChatConversation());
layout.append(pane);
}
@@ -1458,6 +1460,8 @@ function viewForRoute(route) {
return "runs";
case "template":
return "templates";
case "chatSession":
return "chat";
case "runs":
case "chat":
case "settings":
@@ -1674,9 +1678,32 @@ async function applyRoute(route) {
return;
}
if (r.kind === "chat") {
renderContent();
if (r.kind === "chat" || r.kind === "chatSession") {
state.view = "chat";
if (!state.chatLoaded) await loadCurrentView();
if (r.kind === "chat") {
state.chatActiveId = null;
state.chatCreate = null;
renderContent();
return;
}
// A chat detail is a real history entry: opening one pushes /chat/:id, so
// Back (including Android's back gesture) returns to the chat list rather
// than the previous destination. An id the server no longer lists falls
// back to the list instead of leaving a dead pane.
const known =
state.chatThreads.has(r.id) || state.chatSessions.some((session) => session.id === r.id);
if (!connected() || !known) {
state.chatActiveId = null;
if (`${location.pathname}${location.search}` !== "/chat") {
replaceRoute({ kind: "chat" });
}
renderContent();
return;
}
state.chatActiveId = r.id;
renderContent();
await openChatSession(r.id, { updateRoute: false });
return;
}
@@ -2318,6 +2345,7 @@ const runtime = {
setServerUrlDraft,
pushRoute,
applyRoute,
closeDetail,
openConfiguredEndpoint,
onReconnectClicked,
selectPipeline,
+20 -2
View File
@@ -12,7 +12,8 @@
// /runs Runs list
// /runs/:id run detail (optional ?action=decide)
// /runs/:id/stage/:key[?visit=N] one visit's stage pane
// /chat Chat
// /chat Chat list
// /chat/:id one chat session
// /templates template gallery
// /templates/:key template detail
// /settings Settings
@@ -47,6 +48,12 @@ function parseId(value) {
}
/** A non-negative safe integer (a pipeline version; 0 means latest), or null. */
/** A chat session id segment: nonempty, bounded, URL-safe. */
function parseChatId(value) {
const id = String(value ?? "");
return id !== "" && id.length <= 200 && /^[A-Za-z0-9_-]+$/.test(id) ? id : null;
}
function parseVersion(value) {
if (!ID_PATTERN.test(value)) return null;
const version = Number(value);
@@ -131,7 +138,14 @@ export function parseRoute(pathname, search = "") {
if (head === "pipelines" && second == null) return { kind: "pipelines" };
if (head === "runs" && second == null) return { kind: "runs" };
if (head === "chat" && second == null) return { kind: "chat" };
if (head === "chat") {
if (second == null) return { kind: "chat" };
if (third == null) {
const id = parseChatId(second);
return id == null ? { ...DEFAULT_ROUTE } : { kind: "chatSession", id };
}
return { ...DEFAULT_ROUTE };
}
if (head === "settings" && second == null) return { kind: "settings" };
if (head === "templates") {
if (second == null) return { kind: "templates" };
@@ -230,6 +244,10 @@ export function serializeRoute(route) {
return "/runs";
case "chat":
return "/chat";
case "chatSession": {
const id = parseChatId(r.id);
return id == null ? "/chat" : `/chat/${encode(id)}`;
}
case "settings":
return "/settings";
case "templates":
+23 -2
View File
@@ -256,6 +256,7 @@ export function createChatView(rt) {
let chatNow = Date.now();
const renderContent = (...args) => rt.renderContent(...args);
const focusDetailHeading = (...args) => rt.focusDetailHeading(...args);
const closeDetail = (...args) => rt.closeDetail?.(...args);
const renderActionFailedDialog = (...args) => rt.views.dialogs.renderActionFailedDialog(...args);
/** Remember one conversation's scroll position (index of the first visible row). */
@@ -491,7 +492,9 @@ async function createNewChat() {
}
/** Open a session: select it, subscribe its stream and load its newest history page. */
async function openChatSession(id) {
async function openChatSession(id, { updateRoute = true } = {}) {
if (updateRoute) rt.pushRoute({ kind: "chatSession", id });
state.view = "chat";
if (state.chatActiveId === id && state.chatThreads.get(id)?.loaded) return;
// Remember where the operator left the conversation being closed.
const leaving = document.getElementById("chatTranscript");
@@ -1954,11 +1957,29 @@ function renderChatConversation() {
const awaiting = approval?.actionable === true || form != null;
const bar = h("div", { class: "chat-bar" });
const lead = h("div", { class: "chat-bar-lead" });
// A compact back control in the conversation header, matching the create
// pane's own. The narrow layout is where the list is covered; on wide screens
// the list is still visible, so CSS hides it there.
lead.append(
h(
"button",
{
class: "ghost chat-create-back chat-back",
type: "button",
"aria-label": "Back to chats",
title: "Back to chats",
onclick: () => closeDetail("chat"),
},
h("span", { class: "chat-create-back-glyph", "aria-hidden": "true", text: "←" }),
),
);
const titles = h("div", { class: "chat-bar-titles" });
// The open conversation is the route's one h1; the list heading above becomes
// its h2 while the detail is open.
titles.append(h("h1", { class: "chat-bar-title", id: "detailTitle", tabindex: "-1", text: title }));
bar.append(titles);
lead.append(titles);
bar.append(lead);
if (thread?.hasMore) {
bar.append(
h("button", {
+4
View File
@@ -50,6 +50,9 @@ test("top-level destinations", () => {
assert.deepEqual(parseRoute("/pipelines"), { kind: "pipelines" });
assert.deepEqual(parseRoute("/runs"), { kind: "runs" });
assert.deepEqual(parseRoute("/chat"), { kind: "chat" });
assert.deepEqual(parseRoute("/chat/ses_abc123"), { kind: "chatSession", id: "ses_abc123" });
assert.deepEqual(parseRoute("/chat/ses_a/b"), { kind: "pipelines" });
assert.deepEqual(parseRoute("/chat/"), { kind: "chat" });
assert.deepEqual(parseRoute("/settings"), { kind: "settings" });
assert.deepEqual(parseRoute("/templates"), { kind: "templates" });
});
@@ -207,6 +210,7 @@ test("serialisation is idempotent and parse(serialize(route)) preserves every ro
{ kind: "pipelines" },
{ kind: "runs" },
{ kind: "chat" },
{ kind: "chatSession", id: "ses_abc123" },
{ kind: "settings" },
{ kind: "templates" },
{ kind: "template", key: "plan" },