feat(webui): dashboard-aware chat — Archie sees the page, points you there

The web chat is now a persistent slide-over drawer available on any page
(not just the /chat route), and the agent is told which dashboard page the
operator is on so it can point them to the relevant page with a clickable chip.

Backend (gateway):
- Message gains a per-message Page field; the system prompt renders it in
  the <env> block (Current page), so Archie knows where the operator is.
- New dashboard_tools.go: a DashboardPages registry plus two web-only tools
  — page_index (lists every page and what it shows) and dashboard_navigate
  (validates a path, returns {path,label}; rejects unknown/empty paths).
- The web chat sink emits a dedicated navigate stream event when the model
  calls dashboard_navigate, independent of ShowToolCalls.

Frontend (webui):
- chat sends currentPage() (location.hash) with each stream request; a
  dashboard_navigate result renders as a clickable link chip (href=#/path).
- The chat is mounted once in a slide-over drawer with a topbar launcher,
  scrim and Esc-to-close; /chat opens the drawer instead of a second page.
- ui/dist rebuilt (committed) with the bundled changes.
- .gitignore: ignore .impeccable/ (impeccable tool critique snapshots).

New capability (per scope discipline): designed in
docs/prds/dashboard-aware-chat-navigation.md.

Tests: dashboard_tools_test (registry, resolve/reject, web-only gating),
prompt page-line cases, webui Message.Page + navigate-frame capture, and
chat-tools chip tests. task check is green.
This commit is contained in:
sam committed 2026-08-28 22:28:10 +10:00
1 parent 3ffc4df8d6
commit ea1017af94
21 files changed
+743 -15

No files matched your search

+1 -1
View File
@@ -165,7 +165,7 @@ export const api = {
chatMessage: async (channelID, text) => {
const res = await fetch("/api/chat/message", {
method: "POST", headers: { Accept: "application/json", "Content-Type": "application/json" },
body: JSON.stringify({ channel_id: channelID, source_id: randomUUID(), text }),
body: JSON.stringify({ channel_id: channelID, source_id: randomUUID(), text, page: location.hash.slice(1) || "/" }),
signal: AbortSignal.timeout(15000),
});
if (!res.ok) throw new ApiError(await errorMessage(res), res.status);
+1
View File
@@ -27,6 +27,7 @@ const paths = {
trendUp: '<path d="M4 17L10 11l4 4 6-6"/><path d="M14 7h6v6"/>',
trendDown: '<path d="M4 7l6 6 4-4 6 6"/><path d="M14 17h6v-6"/>',
check: '<path d="M4.5 12.5l5 5 10-11"/>',
close: '<path d="M6 6l12 12M18 6L6 18"/>',
help: '<circle cx="12" cy="12" r="9"/><path d="M9.6 9.4a2.5 2.5 0 1 1 3.3 2.4c-.6.2-.9.8-.9 1.4v.4"/><path d="M12 17.2h.01"/>',
};
+24
View File
@@ -42,3 +42,27 @@ function toolList(host) {
host.append(list);
return list;
}
// appendNavigateChip renders a dashboard_navigate result as a clickable chip
// that routes the operator to a dashboard page. It is an action, not a tool
// narration line: the model called dashboard_navigate to point the operator
// somewhere, so the chip is a real link (the app routes on location.hash),
// and it is the only clickable navigation surface the transcript offers. The
// label is the tool's resolved page name, never a markdown link the model
// invented.
export function appendNavigateChip(host, event) {
const path = event?.path ?? "";
const label = event?.label || path;
if (!host || !path) return null;
const chip = el("a.chat-nav-chip",
{
href: "#" + path,
title: "Go to " + label,
"aria-label": "Go to " + label,
},
el("span.chat-nav-chip-icon", { "aria-hidden": "true" }, "↗"),
el("span.chat-nav-chip-label", label),
);
toolList(host).append(chip);
return chip;
}
+31
View File
@@ -1,4 +1,7 @@
.chat-page { height: calc(100vh - 5rem); display: flex; flex-direction: column; overflow: hidden; }
/* When the chat is a drawer (shell), it fills the panel; the standalone page
keeps its viewport-minus-chrome height. */
.chat-drawer .chat-page { height: 100%; }
.chat-page-content { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; overflow: hidden; }
.chat-topbar { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.chat-kicker, .chat-workspace-label { color: var(--fg-muted); font-size: .68rem; font-weight: 700; letter-spacing: .12em; }
@@ -68,6 +71,34 @@
.chat-tool-name { color: var(--fg); font-weight: 600; }
.chat-tool.failed .chat-tool-summary { color: var(--danger); }
/* A dashboard_navigate result: a clickable chip that routes the operator to a
dashboard page. It is an action, not evidence, so it is styled as a button
beside the tool list rather than a muted log line, and it visibly invites a
click. It is the only clickable navigation surface in the transcript. */
.chat-nav-chip {
display: inline-flex;
align-items: center;
gap: .4rem;
padding: .4rem .7rem;
border-radius: 999px;
border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--border));
background: var(--accent-soft);
color: var(--accent);
font-size: .82rem;
font-weight: 600;
cursor: pointer;
transition: background var(--transition), border-color var(--transition), color var(--transition);
}
.chat-nav-chip:hover {
border-color: var(--accent);
background: color-mix(in srgb, var(--accent) 16%, var(--surface));
}
.chat-nav-chip:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
.chat-nav-chip-icon { font-size: .8rem; line-height: 1; }
.chat-compose { padding: .85rem 1rem 1rem; border-top: 1px solid var(--border); }
.chat-composer-shell { position: relative; padding: .7rem .8rem .55rem; background: var(--surface-hover); border: 1px solid var(--border-strong); border-radius: .9rem; }
.chat-composer { width: 100%; min-height: 3.3rem; resize: vertical; box-sizing: border-box; background: transparent; color: var(--fg); border: 0; padding: .25rem 0; font: inherit; }
+14 -2
View File
@@ -3,7 +3,7 @@ import { api } from "../base/api.js";
import { createChatView } from "./chat-view.js";
import { assistantBubble, chatBubble } from "./chat-render.js";
import { updateStreamingReply } from "./chat-stream.js";
import { appendToolCall } from "./chat-tools.js";
import { appendToolCall, appendNavigateChip } from "./chat-tools.js";
import { channelID } from "./chat-state.js";
import { retryChatTurn, resolveTurn } from "./chat-retry.js";
import { renderCommands, renderModels, renderSelectors, renderSessions } from "./chat-catalog.js";
@@ -12,6 +12,15 @@ import { updateUnavailableMessage } from "./chat-update-status.js";
import "./chat.css";
// currentPage is the dashboard route the operator is on right now (the hash
// minus the leading "#"). It is sent with each chat message so the agent's
// system prompt can state where the operator is looking and point them
// somewhere relevant. A future global chat drawer still reads this live from
// the URL, so it stays correct as the operator navigates.
function currentPage() {
return location.hash.slice(1) || "/";
}
export function chatPage() {
const { root, refs } = createChatView();
const { sessionList, transcript, composer, send, stop, status, persona, provider, model,
@@ -240,7 +249,7 @@ export function chatPage() {
const response = await fetch("/api/chat/stream", {
method: "POST",
headers: { "Content-Type": "application/json", Accept: "text/event-stream" },
body: JSON.stringify({ channel_id: channelID(), source_id: turn.sourceID, text: turn.text }),
body: JSON.stringify({ channel_id: channelID(), source_id: turn.sourceID, text: turn.text, page: currentPage() }),
signal: activeController.signal,
});
if (!response.ok) throw new Error((await response.text()) || `${response.status} ${response.statusText}`);
@@ -264,6 +273,9 @@ export function chatPage() {
if (event.type === "tool") {
appendToolCall(replyBubble.querySelector(".chat-bubble") ?? replyBubble, event);
}
if (event.type === "navigate") {
appendNavigateChip(replyBubble.querySelector(".chat-bubble") ?? replyBubble, event);
}
if (event.type === "done") {
finished = true;
if (!streamedText) {
+69
View File
@@ -192,6 +192,75 @@ body {
overflow-x: hidden;
}
/* ── Chat drawer ─────────────────────────────────────────────────────── */
/* The chat is a persistent slide-over, not a route: it is mounted once and
opened from the topbar, so the operator can talk to Archie from any page
without leaving the work that prompted the question. It overlays the
layout rather than replacing it, and the navigation/outlet stay interactive
behind the scrim. */
.chat-drawer {
position: fixed;
inset: var(--sp-4);
display: flex;
align-items: stretch;
justify-content: flex-end;
pointer-events: none;
z-index: 40;
}
.chat-drawer-panel {
pointer-events: auto;
position: relative;
z-index: 1;
display: grid;
grid-template-rows: auto minmax(0, 1fr);
width: min(430px, 100%);
height: 100%;
background: var(--surface);
border: 1px solid var(--border);
border-radius: var(--radius-lg);
box-shadow: var(--shadow-md);
overflow: hidden;
opacity: 0;
transform: translateX(1.2rem);
transition: opacity var(--transition), transform var(--transition);
}
/* A closed (opacity-0, still mounted) panel must not block the page behind
it: opacity does not disable hit-testing, so without this the invisible
430px panel would make the whole right column unclickable at z-index 40. */
.chat-drawer:not(.is-open) .chat-drawer-panel {
pointer-events: none;
}
.chat-drawer.is-open .chat-drawer-panel {
opacity: 1;
transform: none;
}
.chat-drawer-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: var(--sp-2);
padding: var(--sp-3) var(--sp-4);
border-bottom: 1px solid var(--border);
}
.chat-scrim {
position: fixed;
inset: 0;
background: color-mix(in srgb, var(--bg) 40%, transparent);
opacity: 0;
pointer-events: none;
transition: opacity var(--transition);
}
/* The scrim shows and closes from outside clicks only when the drawer is
open; it is driven by the drawer's own state so it can never be on top of
a closed drawer. */
.chat-drawer.is-open .chat-scrim {
opacity: 1;
pointer-events: auto;
}
body.chat-open {
overflow: hidden;
}
/* ── Constrained desktop ────────────────────────────────────────────────── */
@media (max-width: 1220px) and (min-width: 901px) {
+54 -4
View File
@@ -46,7 +46,7 @@ function currentTheme() {
return localStorage.getItem(THEME_KEY) || "dark";
}
function commandBar(onNavigate) {
function commandBar(onNavigate, onToggleChat) {
const items = new Map();
const nav = el(
@@ -113,6 +113,9 @@ function commandBar(onNavigate) {
"aria-label": "Jump to a section",
onkeydown: (e) => {
if (e.key === "Escape") {
// preventDefault so the window-level handler (chat drawer close) does
// not also fire: dismissing the search should not dismiss the drawer.
e.preventDefault();
closeMobileSearch();
e.target.blur();
return;
@@ -143,6 +146,12 @@ function commandBar(onNavigate) {
el(
"div.topbar-end",
searchWrap,
el("button.icon-btn.icon-btn-chat", {
"aria-label": "Open chat",
title: "Chat with Archie",
"aria-expanded": "false",
onclick: () => onToggleChat?.(),
}, icon("chat")),
el("button.icon-btn", { title: "Documentation", "aria-label": "Documentation" }, icon("help")),
themeBtn,
el("div.avatar", { title: "Signed in locally" }, "A"),
@@ -161,11 +170,36 @@ function start() {
applyTheme(currentTheme());
const outlet = el("main.main");
const bar = commandBar(navigate);
mount(document.getElementById("app"), el("div.shell", bar.node, outlet));
// The chat drawer lives beside the outlet, mounted once. It is closed by
// default and opened from the topbar launcher; because it is a slide-over
// rather than a route, the operator can talk to Archie from any page
// without leaving the work that prompted the question. It hosts a single
// chatPage() instance, so session state and the stream survive navigation
// and are not duplicated per page.
const chatDrawer = el("aside.chat-drawer", { "aria-label": "Chat with Archie" });
const chatClose = el("button.icon-btn.chat-drawer-close", {
"aria-label": "Close chat",
title: "Close chat",
onclick: () => toggleChat(false),
}, icon("close"));
const drawerHead = el("div.chat-drawer-head", el("strong", "Archie"), chatClose);
chatDrawer.append(el("div.chat-drawer-panel", drawerHead, chatPage()),
el("div.chat-scrim", { onclick: () => toggleChat(false) }));
const bar = commandBar(navigate, () => toggleChat());
const shell = el("div.shell", bar.node, outlet, chatDrawer);
mount(document.getElementById("app"), shell);
function toggleChat(open) {
const shouldOpen = open === undefined ? !chatDrawer.classList.contains("is-open") : open;
chatDrawer.classList.toggle("is-open", shouldOpen);
document.body.classList.toggle("chat-open", shouldOpen);
const btn = shell.querySelector(".icon-btn-chat");
if (btn) btn.setAttribute("aria-expanded", String(shouldOpen));
}
window.__archieToggleChat = toggleChat;
function navigate(path) {
if (location.hash !== `#${path}`) location.hash = path;
if (location.hash !== '#' + path) location.hash = path;
else show(path);
}
@@ -176,10 +210,26 @@ function start() {
const [path, query = ""] = rawPath.split("?", 2);
const route = routes.find((r) => r.path === path) || routes[0];
bar.highlight(route.path);
// The chat is a drawer, not a page: /chat opens it rather than mounting a
// second chatPage() (which would duplicate session state and the stream).
if (route.path === "/chat") {
mount(outlet);
toggleChat(true);
return;
}
mount(outlet, route.view ? route.view(new URLSearchParams(query)) : comingSoon(route));
// Navigating to a page dismisses the chat drawer; the operator has moved on.
toggleChat(false);
}
window.addEventListener("hashchange", () => show(location.hash.slice(1) || "/"));
window.addEventListener("keydown", (e) => {
// A focused control (the composer dismissing its command menu, or the
// topbar search) already handled Escape via preventDefault; closing the
// drawer too would make the menu impossible to dismiss alone.
if (e.defaultPrevented) return;
if (e.key === "Escape" && chatDrawer.classList.contains("is-open")) toggleChat(false);
});
show(location.hash.slice(1) || "/");
}