Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
Merge remote-tracking branch 'origin/pr/1633' into codex/review-pr-1633
vastsa0c44763275ae
diff --cc apps/desktop/test/fixtures/overlay-selection-runner.cjsindex 000000000,f65e1411f..6a9a5cce4mode 000000,100644..100644--- a/apps/desktop/test/fixtures/overlay-selection-runner.cjs+++ b/apps/desktop/test/fixtures/overlay-selection-runner.cjs@@@ -1,0 -1,188 +1,199 @@@+ const { app, BrowserWindow, clipboard } = require("electron");+ const { join } = require("node:path");+ let passed = 0;+ const failures = [];+ const watchdog = setTimeout(() => { console.error("Overlay selection test exceeded 60 seconds"); app.exit(1); }, 60_000);+ app.whenReady().then(async () => {+ const win = new BrowserWindow({ width: 1100, height: 800, show: true,+ webPreferences: { sandbox: true, contextIsolation: true, backgroundThrottling: false } });+ const evaluate = (source) => win.webContents.executeJavaScript(source, true);+ const settle = () => evaluate("new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)))");+ const wait = async (source) => {+ const deadline = Date.now() + 8000;+ while (!(await evaluate(source))) {+ if (Date.now() > deadline) throw Error(`Timed out: ${source}`);+ await settle();+ }+ };+ const check = (name, result) => {+ if (result) { passed++; console.log(`PASS ${name}`); }+ else { failures.push(name); console.error(`FAIL ${name}`); }+ };+ const mouse = async (type, point, modifiers = []) => {+ win.webContents.sendInputEvent({ type, button: "left", clickCount: 1, ...point, modifiers });+ await settle();+ };+ const point = (selector, text = false) => evaluate(`(() => {+ const element = document.querySelector(${JSON.stringify(selector)});+ if (!element) throw Error('Missing ${selector}');+ let r = element.getBoundingClientRect();+ if (${text}) {+ const walker = document.createTreeWalker(element, NodeFilter.SHOW_TEXT);+ let node; while ((node = walker.nextNode())) {+ if (!node.textContent.trim()) continue;+ const offset = Math.min(5, node.textContent.length - 1);+ const range = document.createRange(); range.setStart(node, offset); range.setEnd(node, offset + 1);+ r = range.getBoundingClientRect(); break;+ }+ }+ return { x: Math.round(r.x + (${text} ? 1 : r.width / 2)), y: Math.round(r.y + r.height / 2) };+ })()`);+ const clickAt = async (p) => { await mouse("mouseMove", p); await mouse("mouseDown", p); await mouse("mouseUp", p); };+ const click = async (selector) => clickAt(await point(selector));+ const key = async (keyCode, modifiers = []) => {+ if (keyCode === "c") keyCode = "C";+ win.webContents.sendInputEvent({ type: "keyDown", keyCode, modifiers });+ if (keyCode === "Enter") win.webContents.sendInputEvent({ type: "char", keyCode: "\r", modifiers });+ win.webContents.sendInputEvent({ type: "keyUp", keyCode, modifiers });+ await settle();+ };++ const copySelection = async () => {++ clipboard.clear();++ if (process.platform === "darwin") {++ await key("c", ["meta"]);++ const copied = await evaluate("document.execCommand('copy')");++ await settle();++ return copied;++ }++ await key("c", ["control"]);++ return true;++ };+ const drag = async (start, end, held) => {+ await mouse("mouseMove", start);+ await mouse("mouseDown", start);+ for (let step = 1; step <= 8; step++) {+ await mouse("mouseMove", { x: Math.round(start.x + (end.x - start.x) * step / 8),+ y: Math.round(start.y + (end.y - start.y) * step / 8) }, ["leftButtonDown"]);+ }+ if (held) await held();+ await mouse("mouseUp", end);+ };+ const exists = (selector) => evaluate(`Boolean(document.querySelector(${JSON.stringify(selector)}))`);+ const selected = () => evaluate("document.getSelection()?.toString() ?? ''");+ const show = async (kind) => {+ await mouse("mouseMove", { x: 5, y: 5 });+ await evaluate(`window.overlayFixture.show(${JSON.stringify(kind)})`);+ if (kind === "table") await click('button[aria-label="Expand table"]');+ if (kind === "release") await wait("Boolean(document.querySelector('.release-notes-version li'))");+ await evaluate("Promise.all(document.getAnimations().filter(a => a.effect.getComputedTiming().iterations !== Infinity).map(a => a.finished.catch(() => {})))");+ };+ await win.loadFile(join(process.env.PI_OVERLAY_TEST_DIR, "index.html"));+ win.focus(); win.webContents.focus();+ await wait("Boolean(window.overlayFixture) && document.hasFocus()");+ for (const [kind, text, overlay] of [+ ["release", ".release-notes-version li", ".release-notes-overlay"],+ ["table", ".markdown-table-preview th", ".markdown-table-overlay"],+ ["instructions", ".project-instructions-dialog-project", ".project-instructions-dialog-overlay"],+ ["provider", "#provider-setup-title", ".provider-setup-overlay"],+ ]) {+ await show(kind);+ const start = await point(text, true);+ const outside = { x: 5, y: Math.min(740, start.y + 40) };+ await drag(start, outside);+ check(`${kind}: internal-to-external text drag keeps dialog open`, await exists(overlay));+ if (await exists(overlay)) {+ const selection = await selected();+ if (kind === "release" || kind === "table") check(`${kind}: native selection remains nonempty`, selection.length > 0);+ if (selection) {- await key("c", [process.platform === "darwin" ? "meta" : "control"]);- check(`${kind}: native Copy preserves the selection`, clipboard.readText().replaceAll("\r\n", "\n") === selection);++ const copied = await copySelection();++ check(`${kind}: native Copy preserves the selection`, copied && clipboard.readText().replaceAll("\r\n", "\n") === selection);+ }+ await clickAt(outside);+ check(`${kind}: subsequent deliberate backdrop click closes`, !(await exists(overlay)));+ }+ await show(kind);+ await drag({ x: 5, y: 5 }, await point(text));+ check(`${kind}: external-to-internal drag keeps dialog open`, await exists(overlay));+ await key("Escape");+ check(`${kind}: Escape still closes`, !(await exists(overlay)));+ }+ await show("table");+ await evaluate(`(() => { window.overlayFixture.keyReached = false; document.querySelector('button[aria-label="Close table preview"]').addEventListener('keydown', () => { window.overlayFixture.keyReached = true; }, { once: true }); })()`);+ await key("Enter");+ check("table: native key reaches focused control", await evaluate("window.overlayFixture.keyReached"));+ check("table: Enter activates focused close control", !(await exists(".markdown-table-overlay")));+ for (const reset of ["cancel", "blur"]) {+ await show("release");+ await mouse("mouseDown", { x: 5, y: 350 });+ await evaluate(reset === "cancel"+ ? `document.querySelector('.release-notes-overlay').dispatchEvent(new PointerEvent('pointercancel', { bubbles: true, pointerId: window.overlayFixture.pointerId }))`+ : `window.dispatchEvent(new Event('blur'))`);+ await mouse("mouseUp", { x: 5, y: 350 });+ check(`backdrop: ${reset} resets pending dismissal`, await exists(".release-notes-overlay"));+ await clickAt({ x: 5, y: 350 });+ check(`backdrop: fresh click works after ${reset}`, !(await exists(".release-notes-overlay")));+ }+ await show("provider");+ await click('.provider-setup-head-actions button');+ await wait("Boolean(document.querySelector('.provider-advanced-overlay'))");+ await drag(await point("#provider-advanced-title", true), { x: 5, y: 350 });+ check("nested advanced: drag closes neither layer", await exists(".provider-advanced-overlay") && await exists(".provider-setup-overlay"));+ if (await exists(".provider-advanced-overlay")) await clickAt({ x: 5, y: 350 });+ check("nested advanced: intentional backdrop closes only inner layer", !(await exists(".provider-advanced-overlay")) && await exists(".provider-setup-overlay"));+ await show("instructions");+ await evaluate(`(() => { const el = document.querySelector('textarea'); const setter = Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype, 'value').set; setter.call(el, el.value + ' changed'); el.dispatchEvent(new Event('input', { bubbles: true })); })()`);+ await click(".project-instructions-dialog-actions .btn-primary");+ await wait("document.querySelector('textarea').disabled");+ await clickAt({ x: 5, y: 350 }); await key("Escape");+ check("saving instructions: outside click and Escape remain blocked", await exists(".project-instructions-dialog-overlay"));+ await evaluate("window.overlayFixture.finishSave()");+ await wait("!document.querySelector('textarea').disabled");+ await click(".project-instructions-dialog-close");+ check("instructions: close button works after save", !(await exists(".project-instructions-dialog-overlay")));++ const hover = ".sidebar-session-hover-card";+ const showHover = async () => {+ await show("hover"); await mouse("mouseMove", await point("#hover-trigger"));+ await evaluate("window.overlayFixture.advance(500)");+ await wait("Boolean(document.querySelector('.sidebar-session-hover-card'))");+ await mouse("mouseMove", await point(`${hover}-title`));+ };+ await showHover();+ await drag(await point(`${hover}-title`, true), { x: 700, y: 330 }, async () => {+ await evaluate("window.overlayFixture.advance(161)");+ check("hover card: survives grace timeout during held selection", await exists(hover));+ });+ await evaluate("window.overlayFixture.advance(161)");+ check("hover card: selected text keeps card open after release", await exists(hover));+ if (await exists(hover)) {+ const selection = await selected();+ check("hover card: native selected text is nonempty", selection.length > 0);- await key("c", [process.platform === "darwin" ? "meta" : "control"]);- check("hover card: native Copy works outside card", clipboard.readText().replaceAll("\r\n", "\n") === selection && selection.length > 0);++ const copied = await copySelection();++ check("hover card: native Copy works outside card", copied && clipboard.readText().replaceAll("\r\n", "\n") === selection && selection.length > 0);+ await mouse("mouseMove", await point("#hover-trigger"));+ await mouse("mouseMove", { x: 700, y: 330 });+ await evaluate("window.overlayFixture.advance(161)");+ check("hover card: row leave cannot dismiss retained selection", await exists(hover));+ await evaluate("document.getSelection().removeAllRanges()"); await settle();+ await evaluate("window.overlayFixture.advance(161)");+ check("hover card: clearing selection resumes dismissal", !(await exists(hover)));+ }+ await showHover();+ await mouse("mouseMove", { x: 700, y: 330 });+ await evaluate("window.overlayFixture.advance(159)");+ check("hover card: ordinary leave preserves 160ms grace", await exists(hover));+ await evaluate("window.overlayFixture.advance(1)");+ check("hover card: ordinary leave dismisses at grace timeout", !(await exists(hover)));+ for (const reset of ["cancel", "blur"]) {+ await showHover();+ await mouse("mouseDown", await point(`${hover}-title`, true));+ await mouse("mouseMove", { x: 700, y: 330 }, ["leftButtonDown"]);+ await evaluate("document.getSelection().removeAllRanges()");+ await evaluate(reset === "cancel"+ ? `document.querySelector('.sidebar-session-hover-card').dispatchEvent(new PointerEvent('pointercancel', { bubbles: true, pointerId: window.overlayFixture.pointerId }))`+ : `window.dispatchEvent(new Event('blur'))`);+ await evaluate("window.overlayFixture.advance(161)");+ check(`hover card: unselected ${reset} resumes dismissal`, !(await exists(hover)));+ await mouse("mouseUp", { x: 700, y: 330 });+ }+ for (const dismiss of ["Escape", "outside press"]) {+ await showHover();+ await drag(await point(`${hover}-title`, true), { x: 700, y: 330 });+ check(`hover card: selection exists before ${dismiss}`, (await selected()).length > 0 && await exists(hover));+ if (dismiss === "Escape") await key("Escape");+ else await clickAt({ x: 700, y: 330 });+ check(`hover card: ${dismiss} closes selected card`, !(await exists(hover)));+ }+ console.log(`${passed} checks passed; ${failures.length} failed`);+ clearTimeout(watchdog); win.destroy(); app.exit(failures.length ? 1 : 0);+ }).catch((error) => { clearTimeout(watchdog); console.error(error); app.exit(1); });diff --cc docs/spec/06-delivery/04-e2e-test-plan.mdindex 02af329a0,5fc25f66c..5ec28d771--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@@ -16817,6 -16776,34 +16817,37 @@@ the latest destination. These assertion- **Status:** Automated at the runtime level; no UI driver reads the pluginpage's error text.+ ### E2E-DIALOG-native-selection-across-boundaries++ - **Preconditions:** Built renderer, isolated Electron profile, real production+ React dialogs/hover card and stylesheet; only preload IPC is stubbed. Reveal+ and dismissal delays use a controlled clock, not arbitrary sleeps.-- **Steps:** Drag from release-note/table text onto the backdrop and Copy with- the native keyboard shortcut; repeat content-to-backdrop and reverse drags in- project instructions and provider setup. Open provider Advanced, drag across- its boundary, then deliberately click its backdrop. Cancel a backdrop press- or blur the window before release, then try a fresh outside click. Save project++- **Steps:** Drag from release-note/table text onto the backdrop and copy the++ selected text with Chromium's native Copy command; repeat content-to-backdrop++ and reverse drags in project instructions and provider setup. Open provider++ Advanced, drag across its boundary, then deliberately click its backdrop.++ Cancel a backdrop press or blur the window before release, then try a fresh++ outside click. Save project+ instructions while trying outside click/Escape, then use the close button.+ Hover a session row, drag card text outside, advance past the grace period+ while held and after release, Copy, revisit/leave the row, clear selection,+ and repeat ordinary leave, cancellation, Escape and outside press.+ - **Expected:** Cross-boundary drags preserve the modal and native selection;+ deliberate backdrop clicks still dismiss. Cancelled/blurred presses never+ dismiss; the next fresh click works. Nested clicks close only Advanced and+ saving protections remain effective. The hover card survives dragging and+ remains copyable while its text selection exists; row timers cannot override+ retention. Clearing selection or ending an unselected/cancelled drag resumes+ ordinary 160ms dismissal. Escape/outside press still dismiss selected cards.+ - **Specs:** `04-ux/09-interaction-patterns.md` sections 1.10 and 9.1b;+ `04-ux/07-ui-design-system.md` section 11.4.+ - **Automation:** `pnpm test:e2e:overlay-selection`; production Chromium mouse- and keyboard input with deterministic host replies. No running user app or- real provider is used.-- **Status:** Automated on Windows; macOS/Linux native evidence pending.++ and keyboard input with deterministic host replies. On macOS the fixture uses++ Chromium's native copy command because Electron's synthetic Command+C input++ does not invoke the system clipboard. No running user app or real provider is++ used.++- **Status:** Automated on Windows and macOS; Linux native evidence pending.+### E2E-DIALOG-long-text-boundaries- **Preconditions:** Built renderer assets and an isolated Electron component