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
feat(ui): open windows pick up a rebuilt frontend without a restart
rubenluetke10-beep99791d80e9ee
diff --git a/AGENTS.md b/AGENTS.mdindex 4e1d390e64..19c8149611 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -66,8 +66,10 @@ on unpinned libs; signing private keys ONLY in GH Actions secrets; no silentWorking tree is SHARED: stage only YOUR files (`git add -p`/pathspec, never`git add -A`/`.`); auto-commit each logical step (Conventional Commits); neverpush automatically; never commit secrets. App restart =-`POST /api/settings/restart-app`; desktop WebView has no F5/console — frontend-fix = `npm run build` in `jarvis/ui/web/frontend/` + in-app Restart button.+`POST /api/settings/restart-app`, for PYTHON-side changes only; desktop WebView+has no F5/console — frontend fix = `npm run build` in+`jarvis/ui/web/frontend/`, nothing else: open windows reload themselves+(`src/lib/bundleWatch.ts`). Never end a frontend change by asking for a restart.Check `MEMORY.md` before larger decisions.## 10. Run & testdiff --git a/CLAUDE.md b/CLAUDE.mdindex 4e1d390e64..19c8149611 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -66,8 +66,10 @@ on unpinned libs; signing private keys ONLY in GH Actions secrets; no silentWorking tree is SHARED: stage only YOUR files (`git add -p`/pathspec, never`git add -A`/`.`); auto-commit each logical step (Conventional Commits); neverpush automatically; never commit secrets. App restart =-`POST /api/settings/restart-app`; desktop WebView has no F5/console — frontend-fix = `npm run build` in `jarvis/ui/web/frontend/` + in-app Restart button.+`POST /api/settings/restart-app`, for PYTHON-side changes only; desktop WebView+has no F5/console — frontend fix = `npm run build` in+`jarvis/ui/web/frontend/`, nothing else: open windows reload themselves+(`src/lib/bundleWatch.ts`). Never end a frontend change by asking for a restart.Check `MEMORY.md` before larger decisions.## 10. Run & testdiff --git a/docs/agent-contract.md b/docs/agent-contract.mdindex 08b011be59..f15c611b78 100644--- a/docs/agent-contract.md+++ b/docs/agent-contract.md@@ -476,13 +476,17 @@ Detail in [`docs/BUGS.md`](BUGS.md):reload button and no dev tools, so "press Ctrl+R / F5", "hard-refresh","clear the browser cache" and "open the console" are instructions thatcannot be followed — never end a frontend change with one. A frontend fix- reaches the user in exactly two steps: `npm run build` in- `jarvis/ui/web/frontend/` (the app serves the built `dist/`, never Vite),- then the **Restart** button in the app's top bar, which is on every screen- and posts to the endpoint above. Say that, and say that a restart takes- live terminal panes with it — they reattach or resume, but it is not free.- Running from a browser against `--dev` is a contributor path, not the- maintainer's.+ reaches the user in exactly ONE step: `npm run build` in+ `jarvis/ui/web/frontend/` (the app serves the built `dist/`, never Vite).+ Every open window then picks the new bundle up by itself within seconds —+ `src/lib/bundleWatch.ts` compares the hashed assets the server would hand a+ fresh window against the ones this one is running, and reloads once the+ change has settled and the user has stopped typing. **Do not end a frontend+ change by asking for a restart**: restarting stops the voice stack and the+ live terminal panes to replace files the window fetches on its own. A+ restart is for Python-side changes (editable install, config, plugins), and+ only there. Running from a browser against `--dev` is a contributor path,+ not the maintainer's.- **New worktree:** run `pwsh scripts/preflight.ps1` before writing code;non-zero exit → fix first (BUG-006/014).- **Memory:** check `MEMORY.md` (`~/.claude/projects/.../memory/`) beforediff --git a/jarvis/ui/web/frontend/src/lib/bundleWatch.test.ts b/jarvis/ui/web/frontend/src/lib/bundleWatch.test.tsnew file mode 100644index 0000000000..fdc58f1687--- /dev/null+++ b/jarvis/ui/web/frontend/src/lib/bundleWatch.test.ts@@ -0,0 +1,222 @@+/**+ * A rebuilt frontend has to reach an open window on its own.+ *+ * The failure this covers is not a crash — it is a window that keeps running+ * the previous build and gives no sign of it, which for a long time made+ * "restart the whole application" the routine answer to a one-file frontend+ * change. See lib/bundleWatch.+ */+import { describe, expect, it, vi } from "vitest";+import {+ bundleFingerprint,+ installBundleWatch,+ shouldReload,+ type BundleWatchDeps,+} from "./bundleWatch";++function indexHtml(hash: string): string {+ return [+ "<!doctype html><html><head>",+ `<script type="module" crossorigin src="/assets/index-${hash}.js"></script>`,+ `<link rel="stylesheet" crossorigin href="/assets/index-${hash}.css">`,+ "</head><body><div id=root></div></body></html>",+ ].join("");+}++interface Harness {+ deps: BundleWatchDeps;+ serve: (html: string) => void;+ idle: (ms: number | null) => void;+ hide: (hidden: boolean) => void;+ tick: () => Promise<void>;+ reload: ReturnType<typeof vi.fn>;+ fetches: () => number;+}++function harness(initial: string): Harness {+ let html = initial;+ let idleMs: number | null = null;+ let hidden = false;+ let calls = 0;+ let scheduled: (() => void) | null = null;+ const reload = vi.fn();+ const deps: BundleWatchDeps = {+ fetchIndex: () => {+ calls += 1;+ return Promise.resolve(html);+ },+ reload,+ idleFor: () => idleMs,+ visible: () => !hidden,+ every: (fn) => {+ scheduled = fn;+ return 7;+ },+ stop: () => {+ scheduled = null;+ },+ };+ return {+ deps,+ serve: (next) => {+ html = next;+ },+ idle: (ms) => {+ idleMs = ms;+ },+ hide: (next) => {+ hidden = next;+ },+ tick: async () => {+ scheduled?.();+ // Let the fetch chain settle; the watch is promise-based throughout.+ await Promise.resolve();+ await Promise.resolve();+ await Promise.resolve();+ },+ reload,+ fetches: () => calls,+ };+}++describe("bundleFingerprint", () => {+ it("identifies a build by its hashed assets and ignores their order", () => {+ expect(bundleFingerprint(indexHtml("AAA"))).toBe(+ "/assets/index-AAA.css /assets/index-AAA.js",+ );+ expect(bundleFingerprint(indexHtml("AAA"))).not.toBe(+ bundleFingerprint(indexHtml("BBB")),+ );+ const reordered =+ '<link href="/assets/index-AAA.css"><script src="/assets/index-AAA.js">';+ expect(bundleFingerprint(reordered)).toBe(bundleFingerprint(indexHtml("AAA")));+ });++ it("has no fingerprint for a document with no bundle behind it", () => {+ // The server's placeholder page, or a failed request handed on as "".+ expect(bundleFingerprint("<html><body>starting…</body></html>")).toBe("");+ expect(bundleFingerprint("")).toBe("");+ });+});++describe("shouldReload", () => {+ const baseline = "old";++ it("waits for the same new build twice before acting on it", () => {+ // A build in progress can publish an index whose chunks are not all+ // written; reloading into that is the flicker loop preloadRecovery exists+ // for. One confirmation is the difference.+ expect(+ shouldReload({ baseline, seen: "new", confirmed: null, idleMs: null }),+ ).toBe(false);+ expect(+ shouldReload({ baseline, seen: "new", confirmed: "new", idleMs: null }),+ ).toBe(true);+ expect(+ shouldReload({ baseline, seen: "new", confirmed: "other", idleMs: null }),+ ).toBe(false);+ });++ it("does not interrupt someone who is typing", () => {+ expect(+ shouldReload({ baseline, seen: "new", confirmed: "new", idleMs: 200 }),+ ).toBe(false);+ expect(+ shouldReload({ baseline, seen: "new", confirmed: "new", idleMs: 5_000 }),+ ).toBe(true);+ });++ it("never reloads for an unchanged or unreadable answer", () => {+ expect(+ shouldReload({ baseline, seen: baseline, confirmed: baseline, idleMs: null }),+ ).toBe(false);+ expect(+ shouldReload({ baseline, seen: "", confirmed: "", idleMs: null }),+ ).toBe(false);+ expect(+ shouldReload({ baseline: "", seen: "new", confirmed: "new", idleMs: null }),+ ).toBe(false);+ });+});++describe("installBundleWatch", () => {+ it("reloads a window that is running a build the server has replaced", async () => {+ const app = harness(indexHtml("AAA"));+ installBundleWatch(app.deps);+ await app.tick();++ app.serve(indexHtml("BBB"));+ await app.tick();+ expect(app.reload).not.toHaveBeenCalled();++ await app.tick();+ expect(app.reload).toHaveBeenCalledOnce();+ });++ it("adopts whatever it loaded and stays quiet while the build does not change", async () => {+ const app = harness(indexHtml("AAA"));+ installBundleWatch(app.deps);+ await app.tick();+ await app.tick();+ await app.tick();++ expect(app.reload).not.toHaveBeenCalled();+ });++ it("waits for a typing user to pause", async () => {+ const app = harness(indexHtml("AAA"));+ installBundleWatch(app.deps);+ await app.tick();+ app.idle(150);+ app.serve(indexHtml("BBB"));+ await app.tick();+ await app.tick();+ expect(app.reload).not.toHaveBeenCalled();++ app.idle(9_000);+ await app.tick();+ expect(app.reload).toHaveBeenCalledOnce();+ });++ it("asks nothing of a hidden window and resumes when it comes back", async () => {+ const app = harness(indexHtml("AAA"));+ installBundleWatch(app.deps);+ await app.tick();+ const beforeHiding = app.fetches();++ app.hide(true);+ await app.tick();+ await app.tick();+ expect(app.fetches()).toBe(beforeHiding);++ app.hide(false);+ app.serve(indexHtml("BBB"));+ await app.tick();+ await app.tick();+ expect(app.reload).toHaveBeenCalledOnce();+ });++ it("treats a failed check as no information at all", async () => {+ const app = harness(indexHtml("AAA"));+ const failing: BundleWatchDeps = {+ ...app.deps,+ fetchIndex: () => Promise.reject(new Error("server restarting")),+ };+ installBundleWatch(failing);+ await app.tick();+ await app.tick();++ expect(app.reload).not.toHaveBeenCalled();+ });++ it("stops checking once the watch is torn down", async () => {+ const app = harness(indexHtml("AAA"));+ const stop = installBundleWatch(app.deps);+ await app.tick();+ const before = app.fetches();++ stop();+ await app.tick();+ expect(app.fetches()).toBe(before);+ });+});diff --git a/jarvis/ui/web/frontend/src/lib/bundleWatch.ts b/jarvis/ui/web/frontend/src/lib/bundleWatch.tsnew file mode 100644index 0000000000..647eeb6f89--- /dev/null+++ b/jarvis/ui/web/frontend/src/lib/bundleWatch.ts@@ -0,0 +1,128 @@+/**+ * Notice that the frontend on disk is newer than the one this window is+ * running, and pick it up without anyone restarting anything.+ *+ * The desktop window has no reload key and no dev tools, so for a long time the+ * only way to see a rebuilt frontend was the in-app Restart button — which+ * stops and starts the whole application, voice stack and agent panes included,+ * to replace files the browser would have fetched on its own. `index.html` is+ * served `no-store` and every asset carries a content hash, so a plain reload+ * has always been enough. This module is the missing trigger.+ *+ * It complements ./preloadRecovery rather than replacing it: that one heals a+ * window that has ALREADY crashed on a chunk deleted by a rebuild, which only+ * happens when the user navigates into a view that was not loaded yet. A window+ * sitting on an open view never asks for a missing chunk and stays stale+ * forever. This one asks the server what a fresh window would load.+ *+ * Two rules keep it from being worse than the problem:+ *+ * * a change must survive two consecutive polls, because a build in progress+ * publishes an `index.html` whose chunks are not all written yet, and+ * reloading into that is the flicker loop preloadRecovery was written for;+ * * the user must be idle for a moment, because a reload in the middle of a+ * sentence loses the sentence.+ */++/** How often the served bundle is checked, while the window is visible. */+export const POLL_MS = 5_000;++/** Quiet time required before a reload is allowed to interrupt. */+export const IDLE_MS = 2_000;++/**+ * What the running document would have to load to be current.+ *+ * The hashed asset URLs in `index.html` ARE the identity of a build, so a+ * rebuild that changes nothing produces the same fingerprint and nothing+ * happens. Sorted because the order of preload links is not a promise.+ */+export function bundleFingerprint(html: string): string {+ const assets = html.match(/\/assets\/[A-Za-z0-9._-]+/g);+ if (!assets) return "";+ return [...new Set(assets)].sort().join(" ");+}++export interface BundleWatchDeps {+ /** Fetch the SPA entry document the server would hand a fresh window. */+ fetchIndex: () => Promise<string>;+ /** Reload this window. */+ reload: () => void;+ /** Milliseconds since the last keystroke or pointer press, or null if none. */+ idleFor: () => number | null;+ /** Is this window on screen? A hidden window polls nothing. */+ visible: () => boolean;+ /** Schedule the repeating check. Returns a handle for {@link stop}. */+ every: (fn: () => void, ms: number) => number;+ /** Cancel a handle from {@link BundleWatchDeps.every}. */+ stop: (handle: number) => void;+}++/**+ * The decision, isolated from every timer and every fetch.+ *+ * `baseline` is what this window is running, `seen` the fingerprint just+ * fetched, `confirmed` the one already seen changed on the previous poll.+ */+export function shouldReload({+ baseline,+ seen,+ confirmed,+ idleMs,+}: {+ baseline: string;+ seen: string;+ confirmed: string | null;+ idleMs: number | null;+}): boolean {+ if (!baseline || !seen || seen === baseline) return false;+ // A build in flight can serve a half-written index; the same fingerprint+ // twice means the build finished and this is what it produced.+ if (confirmed !== seen) return false;+ // No input at all means nothing to interrupt.+ return idleMs === null || idleMs >= IDLE_MS;+}++/**+ * Start watching. Returns a function that stops the watch.+ *+ * The first successful fetch establishes what this window is running, so a+ * window that starts up during a rebuild adopts whatever it actually loaded+ * rather than reloading into it.+ */+export function installBundleWatch(deps: BundleWatchDeps): () => void {+ let baseline = "";+ let confirmed: string | null = null;+ let busy = false;++ const check = () => {+ if (busy || !deps.visible()) return;+ busy = true;+ void deps+ .fetchIndex()+ .then((html) => {+ const seen = bundleFingerprint(html);+ if (!seen) return;+ if (!baseline) {+ baseline = seen;+ return;+ }+ if (shouldReload({ baseline, seen, confirmed, idleMs: deps.idleFor() })) {+ deps.reload();+ return;+ }+ confirmed = seen === baseline ? null : seen;+ })+ .catch(() => {+ // The server restarting, a dropped socket, a machine asleep: the next+ // poll asks again. A window must never reload because a request failed.+ })+ .finally(() => {+ busy = false;+ });+ };++ check();+ const handle = deps.every(check, POLL_MS);+ return () => deps.stop(handle);+}diff --git a/jarvis/ui/web/frontend/src/main.tsx b/jarvis/ui/web/frontend/src/main.tsxindex 56b7978192..5982b37620 100644--- a/jarvis/ui/web/frontend/src/main.tsx+++ b/jarvis/ui/web/frontend/src/main.tsx@@ -6,6 +6,7 @@ import { ThemeProvider } from "./hooks/useTheme";import { ViewErrorBoundary } from "./components/ViewErrorBoundary";import { AuthGate } from "./components/AuthGate";import { installPreloadRecovery } from "./lib/preloadRecovery";+import { installBundleWatch } from "./lib/bundleWatch";import "./index.css";// When the frontend is rebuilt while the window is open, the old main bundle@@ -23,6 +24,33 @@ installPreloadRecovery({},});+// The other half of the same problem: a window sitting on an open view never+// asks for a deleted chunk, so it never notices a rebuild at all and shows an+// old UI until someone restarts the whole application. Ask the server what a+// fresh window would load, and reload when the answer has changed — a rebuild+// is then something the user watches happen instead of something they operate.+// See lib/bundleWatch for the two guards that keep this quiet.+{+ let lastInput: number | null = null;+ const noteInput = () => {+ lastInput = Date.now();+ };+ for (const kind of ["keydown", "pointerdown"] as const) {+ window.addEventListener(kind, noteInput, { capture: true, passive: true });+ }+ installBundleWatch({+ fetchIndex: () =>+ fetch("/", { cache: "no-store", headers: { Accept: "text/html" } }).then(+ (response) => (response.ok ? response.text() : ""),+ ),+ reload: () => window.location.reload(),+ idleFor: () => (lastInput === null ? null : Date.now() - lastInput),+ visible: () => document.visibilityState !== "hidden",+ every: (fn, ms) => window.setInterval(fn, ms),+ stop: (handle) => window.clearInterval(handle),+ });+}+// Say it out loud when the main thread stops answering the user. In a WebView// there is no console to notice it in, so a multi-second block shows up only as// "Not responding" in the window title and as keystrokes arriving late in a