Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
fix(browser): recognize scheme-less hosts with ports
yuxino8b2845004cf3
diff --git a/apps/desktop/electron/main/browser-view.ts b/apps/desktop/electron/main/browser-view.tsindex 48c2af1d6..12fafc59d 100644--- a/apps/desktop/electron/main/browser-view.ts+++ b/apps/desktop/electron/main/browser-view.ts@@ -25,7 +25,12 @@ const LIVE_RELOAD_DEBOUNCE_MS = 250;export function normalizeUrl(raw: string): string | null {const trimmed = raw.trim();if (!trimmed) return null;- const withScheme = /^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(trimmed)+ const hasScheme = /^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(trimmed);+ // A dotted hostname or localhost followed by a numeric port is an HTTP+ // address, not a custom scheme. Keep other schemes subject to the allowlist.+ const hasHostPort =+ /^(?:localhost|(?:[a-zA-Z0-9-]+\.)+[a-zA-Z0-9-]+):\d+(?:[/?#]|$)/i.test(trimmed);+ const withScheme = hasScheme && !hasHostPort? trimmed: `http://${trimmed}`;try {@@ -53,8 +58,8 @@ function isWithinRoot(path: string, root: string): boolean {* Resolve user input to a previewable file inside the workspace: a file://* URL, an absolute path, or a workspace-relative path (./demo/index.html,* index.html). Returns null unless the target exists as a file within the- * root — inputs like "localhost:3000/a.html" then fall through to URL- * handling instead of a broken file load.+ * root. A missing relative file (for example, "localhost:3000/a.html")+ * returns null so the caller can try HTTP URL normalization.*/export function resolveLocalFile(raw: string, root: string | null): string | null {const trimmed = raw.trim();diff --git a/apps/desktop/test/browser-pane-navigation.test.mjs b/apps/desktop/test/browser-pane-navigation.test.mjsindex e8a57d6d1..21ceae7de 100644--- a/apps/desktop/test/browser-pane-navigation.test.mjs+++ b/apps/desktop/test/browser-pane-navigation.test.mjs@@ -1,5 +1,7 @@import assert from "node:assert/strict";import { register, registerHooks } from "node:module";+import { tmpdir } from "node:os";+import { join } from "node:path";import test from "node:test";// Electron is the external boundary; all navigation and timeout logic below@@ -35,7 +37,7 @@ registerHooks({ resolve(specifier, context, next) {return specifier === "electron" ? { url: electron, shortCircuit: true } : next(specifier, context);} });register(new URL("./helpers/ts-import-hooks.mjs", import.meta.url));-const { BrowserPane } = await import("../electron/main/browser-view.ts");+const { BrowserPane, normalizeUrl } = await import("../electron/main/browser-view.ts");const { WebContentsView } = await import("electron");const settled = () => new Promise(setImmediate);@@ -48,6 +50,33 @@ function harness(t) {return { pane, wc, request };}+test("address-bar host and port inputs normalize to HTTP without accepting other schemes", () => {+ assert.equal(normalizeUrl("localhost:3000"), "http://localhost:3000/");+ assert.equal(normalizeUrl("localhost:3000/index.html"), "http://localhost:3000/index.html");+ assert.equal(normalizeUrl("example.com:8080"), "http://example.com:8080/");+ assert.equal(normalizeUrl("127.0.0.1:3000"), "http://127.0.0.1:3000/");+ assert.equal(normalizeUrl("example.com"), "http://example.com/");+ assert.equal(normalizeUrl("http://localhost:3000/index.html"), "http://localhost:3000/index.html");+ assert.equal(normalizeUrl("file:///tmp/demo.html"), null);+ assert.equal(normalizeUrl("javascript:alert(1)"), null);+ assert.equal(normalizeUrl("custom:8080"), null);+});++test("submitting a localhost address with a workspace root loads and publishes the HTTP URL", async (t) => {+ const { mkdtempSync, rmSync } = await import("node:fs");+ const root = mkdtempSync(join(tmpdir(), "browser-host-port-"));+ t.after(() => rmSync(root, { recursive: true, force: true }));+ const published = [];+ const pane = new BrowserPane((state) => published.push(state));+ const request = pane.navigateAndWait("localhost:3000/index.html", root);+ const wc = WebContentsView.instances.at(-1).webContents;+ assert.equal(wc.pendingLoads[0].url, "http://localhost:3000/index.html");+ assert.equal(published.at(-1).url, "http://localhost:3000/index.html");+ wc.url = "http://localhost:3000/index.html";+ wc.pendingLoads.shift().resolve();+ assert.equal((await request).url, "http://localhost:3000/index.html");+});+test("timing out a new preview does not return the previous document as ready", async (t) => {const { request, wc } = harness(t);wc.pendingLoads[0].resolve(); // An old document finishing cannot satisfy this load.diff --git a/docs/spec/04-ux/08-component-spec.md b/docs/spec/04-ux/08-component-spec.mdindex 63ec1467f..926ddcfe3 100644--- a/docs/spec/04-ux/08-component-spec.md+++ b/docs/spec/04-ux/08-component-spec.md@@ -1063,6 +1063,12 @@ entirely inside the plugin's isolated page:main-frame wait shows a retryable error, with the old guest hidden. Supersededand cancelled requests cannot publish over the new navigation.+- Browser address input accepts HTTP(S) URLs and scheme-less web hosts. A+ `localhost` or dotted hostname followed by a numeric port (for example,+ `localhost:3000/index.html` or `example.com:8080`) is treated as an HTTP+ address rather than a custom URL scheme. Unsupported schemes remain blocked;+ workspace file previews continue to use the in-root file path gate.+- Opening an HTTP(S) link in the work panel creates an additional Browserresource tab instead of replacing the previous URL. Each tab owns a host-retained WebContents, address, title and navigationhistory. Switching hides/shows pages without reloading, preserving live form,diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.mdindex 2cbcbec72..cfd153d85 100644--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@ -3737,7 +3737,10 @@ identify the platform validation still needed.#### E2E-059: Embedded browser preview isolation and overlays- **Preconditions**: A local dev server is running; a URL or BrowserPreview artifact exists.-- **Steps**: 1) Activate the artifact, enter `localhost:<port>` without a scheme, and submit.+- **Steps**: 1) Activate the artifact, enter `localhost:<port>` and+ `localhost:<port>/index.html` without a scheme, and submit each. Enter a+ dotted host with a port (for example, `example.com:8080`), then verify an+ explicit HTTP(S) URL and a rejected `javascript:` URL.2) Navigate site links; use back/forward/reload/stop. 3) Trigger a`window.open` popup and a permission-requesting page (e.g. notificationprompt). 4) Open global search, then rename a session from the left sidebar;