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(desktop): stop LAN WebUI pages showing "null" and tell same-named projects apart
vastsa07d3256abbf4
diff --git a/apps/desktop/electron/main/lan-webui/workspace.ts b/apps/desktop/electron/main/lan-webui/workspace.tsindex fb4df0fdd..4f83b809a 100644--- a/apps/desktop/electron/main/lan-webui/workspace.ts+++ b/apps/desktop/electron/main/lan-webui/workspace.ts@@ -125,6 +125,23 @@ export function createLanWorkspace(deps: LanWorkspaceDeps) {return { id: group.id, label, pinned, archived, revision: revision(label, pinned, archived) };}+ /**+ * Folder-named legacy projects often share a name (several `apps`). Add the+ * parent folder name to repeated labels; never the absolute path.+ */+ function distinctViews(list: ProjectGroupRecord[], meta: LanMeta) {+ const entries = list.map((group) => ({ group, view: projectView(group, meta) }));+ const counts = new Map<string, number>();+ for (const { view } of entries) counts.set(view.label, (counts.get(view.label) ?? 0) + 1);+ for (const entry of entries) {+ if ((counts.get(entry.view.label) ?? 0) < 2) continue;+ const parts = normalizeProjectKey(entry.group.primaryPath).split("/").filter(Boolean);+ const parent = parts.length > 1 ? parts[parts.length - 2] : "";+ if (parent) entry.view = { ...entry.view, label: `${entry.view.label} · ${parent}` };+ }+ return entries;+ }+/** Root path → group id, so a session can be attributed to one project. */function rootIndex(list: ProjectGroupRecord[]): Map<string, ProjectGroupRecord> {const index = new Map<string, ProjectGroupRecord>();@@ -206,9 +223,8 @@ export function createLanWorkspace(deps: LanWorkspaceDeps) {const meta = deps.organization.read();const archivedOnly = query.get("archived") === "1";const q = (query.get("q") ?? "").trim();- const list = (await groups())- .filter((group) => access.projectIds.includes(group.id))- .map((group) => ({ group, view: projectView(group, meta) }))+ const list = distinctViews(await groups(), meta)+ .filter(({ group }) => access.projectIds.includes(group.id)).filter(({ view }) => view.archived === archivedOnly && matches(view.label, q)).sort((a, b) => Number(b.view.pinned) - Number(a.view.pinned) || b.group.lastOpenedAt - a.group.lastOpenedAt).map(({ view }) => view);@@ -411,10 +427,7 @@ export function createLanWorkspace(deps: LanWorkspaceDeps) {/** Operator-only list for the Desktop pairing dialog. */async operatorProjects(): Promise<Array<{ id: string; label: string }>> {const meta = deps.organization.read();- return (await groups()).map((group) => {- const view = projectView(group, meta);- return { id: view.id, label: view.label };- });+ return distinctViews(await groups(), meta).map(({ view }) => ({ id: view.id, label: view.label }));},async handle(request: LanRequest, key: string | null): Promise<unknown> {diff --git a/apps/desktop/resources/lan-webui/app.js b/apps/desktop/resources/lan-webui/app.jsindex f82d0f422..6c0d7baaf 100644--- a/apps/desktop/resources/lan-webui/app.js+++ b/apps/desktop/resources/lan-webui/app.js@@ -42,6 +42,8 @@for (const child of [].concat(children)) if (child) node.append(child);return node;}+ // DOM replaceChildren() turns null into the text "null"; drop empty slots first.+ const show = (...nodes) => app.replaceChildren(...nodes.filter(Boolean));let toastTimer = null;function notify(message) {toast.textContent = message;@@ -240,7 +242,7 @@}));}const empty = !list.children.length ? el("p", { class: "empty", text: filters.q ? t("noMatches") : t("noProjects") }) : null;- app.replaceChildren(+ show(header(t("projects")),toolbar((patch) => { Object.assign(filters, patch); render(); }, filters),list,@@ -284,7 +286,7 @@},}): null;- app.replaceChildren(+ show(header(title, "#/projects"),toolbar((patch) => { Object.assign(filters, patch); render(); }, filters),create,@@ -364,7 +366,7 @@// Preserve focus and the unsent draft across live refreshes.const focused = document.activeElement?.id === "composer-input";const selection = focused ? [document.activeElement.selectionStart, document.activeElement.selectionEnd] : null;- app.replaceChildren(head, conversation.modelLabel ? el("p", { class: "row-meta", text: conversation.modelLabel }) : null, messages, ...notices, queue, composer);+ show(head, conversation.modelLabel ? el("p", { class: "row-meta", text: conversation.modelLabel }) : null, messages, ...notices, queue, composer);if (focused) {const input = document.getElementById("composer-input");input?.focus();@@ -456,7 +458,7 @@status.textContent = codeName === "PAIRING_CLOSED" ? t("pairClosed") : codeName === "PAIRING_FAILED" ? t("pairFailed") : errorText(codeName);}});- app.replaceChildren(form);+ show(form);code.focus();}diff --git a/apps/desktop/test/helpers/lan-webui-fixture.mjs b/apps/desktop/test/helpers/lan-webui-fixture.mjsindex 5dd1e9d32..bb7510da1 100644--- a/apps/desktop/test/helpers/lan-webui-fixture.mjs+++ b/apps/desktop/test/helpers/lan-webui-fixture.mjs@@ -103,7 +103,7 @@ export function desktop() {return {};},});- return { workspace, calls, turns, activeTurns, queue, meta, sessions };+ return { workspace, calls, turns, activeTurns, queue, meta, sessions, groups };}/** A tiny cookie-keeping browser against the real HTTP listener. */diff --git a/apps/desktop/test/lan-webui-browser-user-path.test.mjs b/apps/desktop/test/lan-webui-browser-user-path.test.mjsindex 99e547898..924dc7ed0 100644--- a/apps/desktop/test/lan-webui-browser-user-path.test.mjs+++ b/apps/desktop/test/lan-webui-browser-user-path.test.mjs@@ -48,6 +48,7 @@ const journey = String.raw`(async () => {await wait(() => rowByTitle("Fix login"), "sessions");result.sessions = [...document.querySelectorAll(".row-title")].map((n) => n.textContent);result.projectHash = location.hash;+ result.strayText = [document.getElementById("app").innerText];// Organize from the row menu: pin.rowByTitle("Fix login").querySelector(".row-more").click();@@ -66,6 +67,7 @@ const journey = String.raw`(async () => {await wait(() => document.querySelectorAll(".msg").length >= 2 && input.isConnected === false || document.getElementById("composer-input")?.value === "", "sent");result.messages = [...document.querySelectorAll(".msg")].map((n) => n.className.split(" ")[1]);result.leaked = document.body.textContent.includes("/secret/path");+ result.strayText.push(document.getElementById("app").innerText);// Phone layout: no horizontal scroll and touch-sized controls.result.horizontalScroll = document.documentElement.scrollWidth > window.innerWidth;@@ -137,6 +139,7 @@ app.whenReady().then(async () => {assert.equal(fake.turns[0].params.sessionId, "s-new-1");assert.ok(result.messages.includes("user") && result.messages.includes("assistant"));assert.equal(result.leaked, false);+ for (const text of result.strayText) assert.doesNotMatch(text, /\bnull\b|undefined/, "no placeholder text leaks into the page");assert.equal(result.horizontalScroll, false);assert.equal(result.smallTargets, 0);assert.equal(result.backHash, "#/p/g-a");diff --git a/apps/desktop/test/lan-webui-user-path.test.mjs b/apps/desktop/test/lan-webui-user-path.test.mjsindex 41b270046..15f56d669 100644--- a/apps/desktop/test/lan-webui-user-path.test.mjs+++ b/apps/desktop/test/lan-webui-user-path.test.mjs@@ -134,6 +134,15 @@ test("scope, grants and request guards fail closed", async (t) => {assert.equal(server.devices().length, 0);});+test("projects with the same name are told apart without exposing paths", async (t) => {+ const fake = desktop();+ fake.groups.push({ id: "g-a2", name: "Alpha", primaryPath: "/elsewhere/clone/a", roots: [{ path: "/elsewhere/clone/a", name: "a", position: 0 }], pinned: false, lastOpenedAt: 0, createdAt: 0, updatedAt: 0 });+ t.after(() => fake.workspace.dispose());+ const labels = (await fake.workspace.operatorProjects()).map((p) => p.label);+ assert.deepEqual(labels, ["Alpha · work", "Beta", "Remote", "Alpha · clone"].filter((l) => l !== "Remote"));+ assert.equal(labels.some((l) => l.includes("/")), false);+});+test("temporary conversations need their own grant", async (t) => {const { phone, calls } = await setup(t, { projectIds: [], temporary: true, chat: true, organize: false });assert.deepEqual((await phone.request("GET", "/v1/sessions?projectId=__temporary__")).body.items.map((s) => s.id), ["s-tmp"]);