Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
fix(ui): return a self-reloading window to the section it was on
rubenluetke10-beepd851c675ea88
diff --git a/jarvis/ui/web/frontend/src/App.tsx b/jarvis/ui/web/frontend/src/App.tsxindex 59f07bb67a..7d85ef0834 100644--- a/jarvis/ui/web/frontend/src/App.tsx+++ b/jarvis/ui/web/frontend/src/App.tsx@@ -6,6 +6,7 @@ import { useBrainStatus } from "@/hooks/useBrainStatus";import { useVoiceStatus } from "@/hooks/useVoiceStatus";import { useAssistantNameSeed } from "@/hooks/useAssistantNameSeed";import { useCodingMode } from "@/hooks/useCodingMode";+import { useSectionUrlMemory } from "@/hooks/useSectionUrlMemory";import {Sidebar,SIDEBAR_DEFAULT_WIDTH,@@ -48,6 +49,16 @@ export default function App() {useVoiceStatus();useAssistantNameSeed();useCodingMode();+ /*+ * A reload puts the user back on the section they were on.+ *+ * The window reloads itself these days — a rebuilt frontend is picked up by+ * lib/bundleWatch instead of by restarting the application — and every one of+ * those reloads used to land on the default section, because the active one+ * lived only in the store. It is written into the address instead, which the+ * reload carries over. See hooks/useSectionUrlMemory.+ */+ useSectionUrlMemory();/** Remember which field the user is typing in, app-wide.diff --git a/jarvis/ui/web/frontend/src/hooks/useSectionUrlMemory.test.ts b/jarvis/ui/web/frontend/src/hooks/useSectionUrlMemory.test.tsnew file mode 100644index 0000000000..32b30d519f--- /dev/null+++ b/jarvis/ui/web/frontend/src/hooks/useSectionUrlMemory.test.ts@@ -0,0 +1,40 @@+import { renderHook, act } from "@testing-library/react";+import { beforeEach, describe, expect, it } from "vitest";++import { initialSectionFromSearch, useEventStore } from "@/store/events";+import { useSectionUrlMemory } from "./useSectionUrlMemory";++beforeEach(() => {+ window.history.replaceState(null, "", "/");+ useEventStore.setState({ activeSection: "chats" });+});++describe("useSectionUrlMemory", () => {+ it("puts the section a reload would need into the address", () => {+ renderHook(() => useSectionUrlMemory());++ act(() => useEventStore.getState().setActiveSection("agentic-ide"));++ expect(window.location.search).toBe("?view=agentic-ide");+ });++ it("hands the boot path the section the user was on", () => {+ // The round trip is the point: a reload keeps the address, and the store+ // reads exactly this on the way up. Asserting the query string alone would+ // pass on a parameter nothing consumes.+ renderHook(() => useSectionUrlMemory());++ act(() => useEventStore.getState().setActiveSection("sessions"));++ expect(initialSectionFromSearch(window.location.search)).toBe("sessions");+ });++ it("leaves a detached window's own flags alone", () => {+ window.history.replaceState(null, "", "/?solo=1&view=chats");+ renderHook(() => useSectionUrlMemory());++ act(() => useEventStore.getState().setActiveSection("outputs"));++ expect(window.location.search).toBe("?solo=1&view=outputs");+ });+});diff --git a/jarvis/ui/web/frontend/src/hooks/useSectionUrlMemory.ts b/jarvis/ui/web/frontend/src/hooks/useSectionUrlMemory.tsnew file mode 100644index 0000000000..861f492e9e--- /dev/null+++ b/jarvis/ui/web/frontend/src/hooks/useSectionUrlMemory.ts@@ -0,0 +1,33 @@+import { useEffect } from "react";++import { useEventStore } from "@/store/events";+import { hrefWithSection } from "@/lib/sectionUrl";++/**+ * Write the active section into the window's address, so a reload returns to it.+ *+ * Mounted at the shell, once per document, and deliberately driven by the STORE+ * rather than by the nav: a section also changes when Jarvis is told "open the+ * workspace" by voice, when a view sends the user somewhere on error, and when a+ * deep link arrives over the WebSocket. Watching the value covers all of them,+ * where hooking the click would cover one.+ *+ * See lib/sectionUrl for why the URL is the right place to keep this.+ */+export function useSectionUrlMemory(): void {+ const activeSection = useEventStore((s) => s.activeSection);++ useEffect(() => {+ const next = hrefWithSection(window.location.href, activeSection);+ if (!next) return;+ try {+ // Keep whatever history state is there; this hook owns the address, not+ // the entry. A WebView that refuses the call (file:// origins, an+ // exhausted rate limit) costs the memory of one section change and+ // nothing else, so it must not take the shell down with it.+ window.history.replaceState(window.history.state, "", next);+ } catch {+ /* the section simply does not survive the next reload */+ }+ }, [activeSection]);+}diff --git a/jarvis/ui/web/frontend/src/lib/sectionUrl.test.ts b/jarvis/ui/web/frontend/src/lib/sectionUrl.test.tsnew file mode 100644index 0000000000..65d224c827--- /dev/null+++ b/jarvis/ui/web/frontend/src/lib/sectionUrl.test.ts@@ -0,0 +1,30 @@+import { describe, expect, it } from "vitest";++import { hrefWithSection } from "./sectionUrl";++const BASE = "http://localhost:8765/";++describe("hrefWithSection", () => {+ it("names the section on an address that carries none", () => {+ expect(hrefWithSection(BASE, "agentic-ide")).toBe("/?view=agentic-ide");+ });++ it("replaces the section a previous navigation left behind", () => {+ expect(hrefWithSection(`${BASE}?view=chats`, "settings")).toBe(+ "/?view=settings",+ );+ });++ it("writes nothing when the address already names the section", () => {+ expect(hrefWithSection(`${BASE}?view=docs`, "docs")).toBeNull();+ });++ it("carries the rest of the address over untouched", () => {+ // `?solo=1` decides whether the window has chrome, `?doc=` which guide the+ // Docs view reopens, and the hash which heading it scrolls to — dropping+ // any of them would trade one lost place for another.+ expect(+ hrefWithSection(`${BASE}?solo=1&doc=agent-contract#naming`, "docs"),+ ).toBe("/?solo=1&doc=agent-contract&view=docs#naming");+ });+});diff --git a/jarvis/ui/web/frontend/src/lib/sectionUrl.ts b/jarvis/ui/web/frontend/src/lib/sectionUrl.tsnew file mode 100644index 0000000000..6c5d45d34f--- /dev/null+++ b/jarvis/ui/web/frontend/src/lib/sectionUrl.ts@@ -0,0 +1,40 @@+/**+ * Keep the section a window is showing in that window's own URL.+ *+ * The app reloads itself now: ./bundleWatch picks up a rebuilt frontend, and+ * ./preloadRecovery heals a window that crashed on a chunk a rebuild deleted.+ * Both replaced the Restart button, which is only an improvement if the user+ * comes back to the screen they were on — and until this module they did not.+ * The active section lives in the Zustand store, a reload discards it, and the+ * window came up on the default section every time: a workspace of terminals+ * still running behind a Chats screen, with the way back a trip through the nav.+ *+ * The URL is the one piece of window state a reload preserves, and this app+ * already READS `?view=` on boot — see `initialSectionFromSearch`, written so a+ * detached solo window knows which section it is. Writing the section back into+ * it adds no restore path at all; it feeds the one that exists.+ *+ * `replaceState`, never `pushState`: the desktop WebView has no back button,+ * and one history entry per section click would turn a trackpad back-swipe into+ * a walk through screens nobody navigated to.+ */++/** The query parameter `initialSectionFromSearch` reads on boot. */+export const SECTION_PARAM = "view";++/**+ * The same document address, now naming `section` — or null if it already does.+ *+ * Null means "nothing to write": a `replaceState` per store update would be a+ * needless history write on every unrelated re-render, and on some engines it is+ * rate-limited. Everything else in the address is carried over untouched, which+ * is load-bearing rather than tidy — `?solo=1` decides whether a window has+ * chrome, `?doc=` is which guide the Docs view reopens, and the hash is the+ * heading it scrolls to.+ */+export function hrefWithSection(href: string, section: string): string | null {+ const url = new URL(href);+ if (url.searchParams.get(SECTION_PARAM) === section) return null;+ url.searchParams.set(SECTION_PARAM, section);+ return `${url.pathname}${url.search}${url.hash}`;+}