From e38f9c453cfc6e1ab66ebf68be6748a01f465c85 Mon Sep 17 00:00:00 2001 From: Florian Schmidt Date: Mon, 16 Nov 2026 12:32:01 +0100 Subject: [PATCH] feat(web): rework layout and quality of life (#12) - App shell: top bar with connection state and Chat/Terminal toggles, per-column scrolling, sidebar only on the Notebooks page. - Hash routes (#/notebooks/, #/hosts, #/settings) so reloads and links keep the open notebook and page. - Parameters sit beside the notebook on wide screens, collapsible, with missing-count summary and Reset; non-secret values are remembered per notebook in localStorage (secrets and undeclared names never stored). - Sticky notebook header with breadcrumbs, check summary and run-all; Ctrl/Cmd+S saves the Markdown draft. - Step cards show target, one deduplicated hint for missing values and copy feedback. - Shared Dialog, Menu and CopyButton components; notebook and host actions move into menus and modal dialogs. - Hosts page as a compact list; Settings split into cards with sign out for this browser. --- apps/web/src/App.tsx | 474 +++--- apps/web/src/ChatPanel.tsx | 17 +- apps/web/src/HostsPage.tsx | 544 ++++--- apps/web/src/NotebookList.tsx | 172 +- apps/web/src/ParamsForm.tsx | 39 +- apps/web/src/SettingsPage.tsx | 175 ++- apps/web/src/StepCard.tsx | 76 +- apps/web/src/TerminalSlot.tsx | 28 +- apps/web/src/chat.css | 49 +- apps/web/src/hosts.css | 91 +- apps/web/src/notebooks.css | 24 +- apps/web/src/paramMemory.ts | 39 + apps/web/src/route.ts | 33 + apps/web/src/settingsApi.ts | 1 + apps/web/src/style.css | 1377 +++++++++++------ apps/web/src/tests/hosts.test.tsx | 11 +- .../src/tests/notebook-management.test.tsx | 7 +- apps/web/src/tests/setup.ts | 7 +- apps/web/src/tests/ui-shell.test.tsx | 112 ++ apps/web/src/ui.tsx | 150 ++ 20 files changed, 2297 insertions(+), 1129 deletions(-) create mode 100644 apps/web/src/paramMemory.ts create mode 100644 apps/web/src/route.ts create mode 100644 apps/web/src/tests/ui-shell.test.tsx create mode 100644 apps/web/src/ui.tsx diff --git a/apps/web/src/App.tsx b/apps/web/src/App.tsx index 8e14693..186b5ca 100644 --- a/apps/web/src/App.tsx +++ b/apps/web/src/App.tsx @@ -42,6 +42,9 @@ import { ParamsForm, type ParamGroup } from "./ParamsForm"; import { HostBlockCard } from "./HostBlockCard"; import { StepCard } from "./StepCard"; import { ChatPanel } from "./ChatPanel"; +import { parseRoute, routeHash } from "./route"; +import { recallValues, rememberValues } from "./paramMemory"; +import { Dialog } from "./ui"; const TerminalSlot = lazy(() => import("./TerminalSlot").then((module) => ({ default: module.TerminalSlot })), ); @@ -68,11 +71,16 @@ function includedGroups(blocks: Block[]): ParamGroup[] { : [], ); } +/** Values that are set; unset ones stay visible as `{{name}}` in prose. */ +function setValuesOnly(values: ParamValues): ParamValues { + return Object.fromEntries(Object.entries(values).filter(([, value]) => value)); +} export function App({ api }: { api: Api }) { + const initialRoute = useRef(parseRoute(location.hash)); const [auth, setAuth] = useState<"loading" | "login" | "setup" | "ready">("loading"); - const [page, setPage] = useState("Notebooks"); + const [page, setPage] = useState(initialRoute.current.page); const [password, setPassword] = useState(""); - const [list, setList] = useState([]); + const [list, setList] = useState(); const [hosts, setHosts] = useState([]); const [doc, setDoc] = useState(); const [source, setSource] = useState(""); @@ -113,7 +121,7 @@ export function App({ api }: { api: Api }) { setConflict(false); setError(""); if (!same) { - setValues({}); + setValues(recallValues(path, next.notebook)); setEdit(false); setCheckIds([]); } @@ -123,6 +131,7 @@ export function App({ api }: { api: Api }) { }, [api], ); + const leave = () => !current.current.dirty || window.confirm("Discard unsaved edits?"); useEffect(() => { void api .me() @@ -144,7 +153,10 @@ export function App({ api }: { api: Api }) { if (!active) return; setList(notebooks.notebooks); setHosts(inventory.hosts); - if (notebooks.notebooks[0]) void load(notebooks.notebooks[0].path); + // Open the notebook from the URL, else the first one. + const wanted = initialRoute.current.notebook; + const first = notebooks.notebooks.find((n) => n.path === wanted) ?? notebooks.notebooks[0]; + if (first) void load(first.path); }) .catch((e) => setError(String(e))); const close = api.events((event: ServerEvent) => { @@ -190,6 +202,25 @@ export function App({ api }: { api: Api }) { window.addEventListener("beforeunload", guard); return () => window.removeEventListener("beforeunload", guard); }, [dirty]); + // Keep the page and notebook in the URL; back/forward navigate between them. + useEffect(() => { + if (auth !== "ready") return; + // Until the first notebook is open, keep the requested one in the URL. + if (page === "Notebooks" && !doc && list === undefined) return; + const hash = routeHash({ page, notebook: doc?.path }); + if (location.hash === hash) return; + if (location.hash) history.pushState(null, "", hash); + else history.replaceState(null, "", hash); + }, [auth, page, doc, list]); + useEffect(() => { + const follow = () => { + const route = parseRoute(location.hash); + setPage(route.page); + if (route.notebook && route.notebook !== current.current.doc?.path && leave()) void load(route.notebook); + }; + window.addEventListener("hashchange", follow); + return () => window.removeEventListener("hashchange", follow); + }, [load]); // The saved notebook comes composed from the server; a draft shows its includes after saving. const notebook = doc @@ -218,6 +249,10 @@ export function App({ api }: { api: Api }) { }; const runFor = (id: string) => session.runs[session.latest[stepKey(path, id)] ?? ""]; + function changeValues(next: ParamValues) { + setValues(next); + if (doc) rememberValues(doc.path, doc.notebook, next); + } async function start(request: StartRunRequest) { const key = stepKey(request.notebookPath, request.stepId); setPending((previous) => new Set(previous).add(key)); @@ -274,7 +309,7 @@ export function App({ api }: { api: Api }) { {renderText( block.text, - { ...runtime, ...resolved.values }, + setValuesOnly({ ...runtime, ...resolved.values }), notebook, )} @@ -360,6 +395,8 @@ export function App({ api }: { api: Api }) { ); }); } + const canSave = + dirty && !conflict && !notebook?.diagnostics.some((d) => d.severity === "error"); async function save() { if (!doc) return; try { @@ -379,15 +416,44 @@ export function App({ api }: { api: Api }) { else setError(String(e)); } } + // Ctrl/Cmd+S saves the open draft. + const saveRef = useRef(save); + saveRef.current = save; + const canSaveRef = useRef(canSave); + canSaveRef.current = canSave && edit; + useEffect(() => { + const key = (e: KeyboardEvent) => { + if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "s" && canSaveRef.current) { + e.preventDefault(); + void saveRef.current(); + } + }; + window.addEventListener("keydown", key); + return () => window.removeEventListener("keydown", key); + }, []); const keyPrompt = Object.values(session.runs).find( (run) => run.status === "hostKey" && requests.current.has(run.runId), ); + const checksBusy = notebook + ? steps(notebook.blocks).some( + (s) => + runFor(s.attrs.id)?.status === "running" || + pending.has(stepKey(path, s.attrs.id)), + ) + : false; + const openTerminal = () => { + setTerminalOpened(true); + setChat(false); + setTerminal(true); + }; if (auth === "setup") return setAuth("ready")} />; if (auth === "login") return (
-

ShellBook

-

Sign in to your workspace

+

+ ShellBookRUNBOOKS +

+

Sign in to your workspace

{ e.preventDefault(); @@ -417,193 +483,237 @@ export function App({ api }: { api: Api }) {
- {error &&

{error}

} + {error &&

{error}

}
); return ( -
- -
+
+
+ + ShellBook + {import.meta.env.VITE_MOCK === "1" && demo} + - {page === "Settings" && { setTerminalOpened(true); setTerminal(true); }} />} - {page === "Hosts" && { void api.hosts().then(result => setHosts(result.hosts)).catch(e => setError(String(e))); }} />} -
+
+ {page === "Notebooks" && ( +
- )} - {notebook && ( - <> - - setValues((previous) => ({ ...previous, [name]: value })) - } /> -
- {edit && ( -
-
- Markdown editor {dirty ? "· unsaved" : ""} - -
- Loading editor…

}> - -
-

- Live preview below. Save changes before running steps. -

-
- )} - {notebook.diagnostics.map((d, i) => ( -

- {d.line && `Line ${d.line}: `} - {d.message} -

- ))} -
+ + )} +
+ {error && ( +

+ {error} + +

+ )} + {page === "Settings" && ( + setAuth("login")} /> + )} + {page === "Hosts" && { void api.hosts().then(result => setHosts(result.hosts)).catch(e => setError(String(e))); }} />} + - + )} + {!notebook && ( +
+ {list === undefined + ? "Loading workspace…" + : list.length + ? "Select a notebook." + : "No notebooks yet. Create one with + in the sidebar, or ask Claude in Chat."} +
+ )} + {notebook && ( +
+ changeValues({ ...values, [name]: value })} + onReset={() => changeValues({})} + /> +
+
+ + {path.split("/").map((part, i, parts) => ( + + {part} + + ))} + {dirty && unsaved} + + + {checkIds.length > 0 && ( + + ✅{" "} + {checkIds.filter((id) => runFor(id)?.status === "success").length}{" "} + / {checkIds.length} · ❌{" "} + {checkIds.filter((id) => runFor(id)?.status === "failure").length} + + )} + + +
+ {edit && ( +
+
+ Markdown + + {dirty ? "Unsaved changes · Ctrl+S saves" : "Saved"} + + + {dirty && ( + + )} + +
+ Loading editor…

}> + +
+

+ Live preview below. Save changes before running steps. +

+
+ )} + {notebook.diagnostics.map((d, i) => ( +

+ {d.line && `Line ${d.line}: `} + {d.message} +

+ ))} + {blocks(notebook.blocks)} +
+
+ )} +
+
+ {chat && ( + { + if (leave()) { + setPage("Notebooks"); + void load(next); + } + }} + openTerminal={openTerminal} + onClose={() => setChat(false)} + /> )} -
- - {chat && { - if (!dirty || window.confirm("Discard unsaved edits?")) void load(path); - }} openTerminal={() => { setChat(false); setTerminalOpened(true); setTerminal(true); }} />} - {terminalOpened && ( - Loading terminal...

}> - -
- )} + {terminalOpened && ( + Loading terminal…

}> + setTerminal(false)} /> +
+ )} + {confirm && ( -
-
-

Confirm execution

-

- Run “{confirm.stepId}” with the displayed parameters? This step - can change the target host. -

+ setConfirm(undefined)}> +

+ Run “{confirm.stepId}” with the displayed parameters? This step + can change the target host. +

+
-
-
+ + )} {keyPrompt?.hostKey && new WebSocket(`${location.protocol === "ht type Message = { role: "user" | "assistant" | "tool"; text: string; path?: string }; /** notebookPath and openNotebook use app paths (relative to notebooks/); the chat wire uses workspace paths. */ -export function ChatPanel({ notebookPath, openNotebook, openTerminal, connect = connectChat }: { - notebookPath?: string; openNotebook(path: string): void; openTerminal(): void; connect?: () => ChatSocket; +export function ChatPanel({ notebookPath, openNotebook, openTerminal, onClose, connect = connectChat }: { + notebookPath?: string; openNotebook(path: string): void; openTerminal(): void; onClose?(): void; connect?: () => ChatSocket; }) { const [history, setHistory] = useState([]); const [selected, setSelected] = useState(""); @@ -68,10 +68,15 @@ export function ChatPanel({ notebookPath, openNotebook, openTerminal, connect = setError(""); setLogin(false); setSummary(""); setAllowShell(false); } function send(message: ChatClientMessage) { try { socket.current?.send(JSON.stringify(message)); } catch { setBusy(false); setError("Cannot send chat message. Reconnect to continue."); } } - return