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(plugins): clear card focus when closing details
yuxinoc7e6a9086c54
diff --git a/apps/desktop/src/features/plugins/usePluginsPage.ts b/apps/desktop/src/features/plugins/usePluginsPage.tsindex ca01d66a0..4ae77b0aa 100644--- a/apps/desktop/src/features/plugins/usePluginsPage.ts+++ b/apps/desktop/src/features/plugins/usePluginsPage.ts@@ -171,6 +171,12 @@ export function usePluginsPage() {};const closeDetail = () => {+ // Escape leaves the opener focused; match pointer dismissal without+ // removing the focus indicator used by subsequent keyboard navigation.+ const focused = document.activeElement;+ if (focused instanceof HTMLElement && focused.matches(".plugins-card-hit")) {+ focused.blur();+ }setSelectedId(null);setDetail(null);setSelectedVersion("");diff --git a/apps/desktop/src/styles/plugins.css b/apps/desktop/src/styles/plugins.cssindex 141580c9a..22b42a85e 100644--- a/apps/desktop/src/styles/plugins.css+++ b/apps/desktop/src/styles/plugins.css@@ -1030,6 +1030,12 @@text-align: left;}+/* Keep the keyboard focus ring inside the tile's overflow clip. */+.plugins-card-hit:focus-visible {+ outline-offset: -3px;+ border-radius: var(--radius-lg);+}+.plugins-card-head {display: flex;align-items: center;diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.mdindex 010f2ee41..087959404 100644--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@ -2352,6 +2352,8 @@ identify the platform validation still needed.- **Acceptance**: G (marketplace detail UX)- **Status**: Documented+- **Focus regression**: In light and dark themes, open a marketplace card and press Escape. Like pointer dismissal, Escape leaves no line or focus ring on the card. Then use Tab and Shift+Tab: the detail button shows a complete, unclipped ring, and Install remains separately focusable. Automated focus-state regression: `node scripts/e2e-plugin-detail-focus.mjs`; verify the rendered ring visually.+#### E2E-024F: Refresh official remote marketplace repository- **Preconditions**: Network available to GitHub raw content.diff --git a/docs/spec/07-plugins/07-plugin-marketplace.md b/docs/spec/07-plugins/07-plugin-marketplace.mdindex 1978cf394..3ef461f6a 100644--- a/docs/spec/07-plugins/07-plugin-marketplace.md+++ b/docs/spec/07-plugins/07-plugin-marketplace.md@@ -543,6 +543,11 @@ error states.Marketplace cards render a monogram glyph rather than fetching `iconUrl`; therenderer performs no remote image loads (D169).+Closing a detail sheet with Escape clears focus from its marketplace opener,+matching pointer dismissal: no line or focus ring remains on the card.+Subsequent Tab navigation still shows a complete focus ring inside the rounded+detail button in both themes, without clipping above the install footer.+## 8. Trust model| Level | Meaning |diff --git a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.mdindex 767aaba18..69f5e38c2 100644--- a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md@@ -1215,6 +1215,8 @@ unit/integration 测试;代码 pull request 使用有选择且高价值的 E2E- **接受**:G(市场详细信息用户体验)- **状态**:已记录+- **焦点回归**:在浅色和深色主题下打开市场卡片,再按 Escape。与鼠标关闭一样,Escape 关闭后卡片不残留横线或焦点框。再用 Tab 和 Shift+Tab 导航:详情按钮显示完整、未裁剪的焦点框,安装按钮仍可单独获得焦点。 自动化焦点状态回归:`node scripts/e2e-plugin-detail-focus.mjs`;焦点框外观需进行视觉验证。+#### E2E-024W:插件剪贴板历史捕获有界的文本和图片- **先决条件**:应用正在运行;测试插件声明并获授 `clipboard.read`;Composer 可以接收diff --git a/docs/zh-CN/spec/07-plugins/07-plugin-marketplace.md b/docs/zh-CN/spec/07-plugins/07-plugin-marketplace.mdindex 2be836ad7..7e805454b 100644--- a/docs/zh-CN/spec/07-plugins/07-plugin-marketplace.md+++ b/docs/zh-CN/spec/07-plugins/07-plugin-marketplace.md@@ -441,6 +441,8 @@ Extensions市场卡呈现字母组合字形,而不是获取 `iconUrl`;的渲染器不执行远程图像加载(D169)。+按 Escape 关闭详情面板时,清除市场卡片详情按钮的焦点,与鼠标关闭一致:卡片不残留横线或焦点框。随后使用 Tab 导航时,浅色和深色主题下都应在圆角详情按钮内部完整显示焦点框,不能被裁剪成安装区域上方的一条横线。+## 8. 信任模型| 级别 | 含义 |diff --git a/scripts/e2e-plugin-detail-focus.mjs b/scripts/e2e-plugin-detail-focus.mjsnew file mode 100644index 000000000..cf9b385ed--- /dev/null+++ b/scripts/e2e-plugin-detail-focus.mjs@@ -0,0 +1,38 @@+#!/usr/bin/env node+// Real marketplace components and Chromium focus; only host APIs are fixtures.+import { spawnSync } from "node:child_process";+import { createRequire } from "node:module";+import { mkdir, mkdtemp, writeFile } from "node:fs/promises";+import { dirname, join } from "node:path";+import { fileURLToPath } from "node:url";+import { resolveElectronBinary } from "./e2e/boot.mjs";++const root = join(dirname(fileURLToPath(import.meta.url)), "..");+const desktop = join(root, "apps/desktop");+const require = createRequire(join(root, "packages/agent-runtime/package.json"));+const cache = join(root, ".cache/plugin-detail-focus");+await mkdir(cache, { recursive: true });+const temp = await mkdtemp(join(cache, "run-"));+await require("esbuild").build({+ entryPoints: [join(root, "scripts/e2e/plugin-detail-focus.tsx")],+ outfile: join(temp, "renderer.js"), bundle: true, platform: "browser", format: "iife",+ loader: { ".css": "empty" }, jsx: "automatic", define: { "process.env.NODE_ENV": '"production"' },+ alias: { react: join(desktop, "node_modules/react"), "react-dom": join(desktop, "node_modules/react-dom") },+ nodePaths: [join(desktop, "node_modules")],+});+await writeFile(join(temp, "index.html"), '<!doctype html><html><body><script src="renderer.js"></script></body></html>');+await writeFile(join(temp, "main.cjs"), `+const {app,BrowserWindow}=require('electron');+app.setPath('userData',require('node:path').join(__dirname,'profile'));+app.disableHardwareAcceleration();+app.whenReady().then(async()=>{+ try {+ const win=new BrowserWindow({show:false,webPreferences:{backgroundThrottling:false,sandbox:true,contextIsolation:true}});+ await win.loadFile(require('node:path').join(__dirname,'index.html'));+ console.log(await win.webContents.executeJavaScript('globalThis.pluginDetailFocusProbe()'));+ app.exit(0);+ } catch(error) { console.error(error); app.exit(1); }+});`);+const result = spawnSync(resolveElectronBinary(root).electronBinary, [join(temp, "main.cjs")], { stdio: "inherit", timeout: 30000 });+if (result.error) throw result.error;+process.exitCode = result.status ?? 1;diff --git a/scripts/e2e/plugin-detail-focus.tsx b/scripts/e2e/plugin-detail-focus.tsxnew file mode 100644index 000000000..ae151b1aa--- /dev/null+++ b/scripts/e2e/plugin-detail-focus.tsx@@ -0,0 +1,71 @@+import React from "react";+import { createRoot } from "react-dom/client";+import { flushSync } from "react-dom";+import i18n from "i18next";+import { I18nextProvider } from "react-i18next";+import { en } from "../../packages/i18n/src/index";+import { api } from "../../apps/desktop/src/lib/api";+import { usePluginsPage } from "../../apps/desktop/src/features/plugins/usePluginsPage";+import { MarketplacePanel } from "../../apps/desktop/src/features/plugins/MarketplacePanel";+import { PluginDetailSheet } from "../../apps/desktop/src/features/plugins/PluginDetailSheet";+import { usePluginBrowseState } from "../../apps/desktop/src/features/plugins/browse-state";++const check = (ok: boolean, label: string) => { if (!ok) throw new Error(label); };+const find = (selector: string) => {+ const node = document.querySelector<HTMLElement>(selector);+ if (!node) throw new Error(`Missing ${selector}`);+ return node;+};+const settle = async (predicate: () => boolean) => {+ for (let frame = 0; frame < 120; frame++) {+ if (predicate()) return;+ await new Promise<void>((resolve) => requestAnimationFrame(() => resolve()));+ }+ throw new Error("Marketplace did not settle");+};+function Probe() {+ const model = usePluginsPage();+ return <><input aria-label="Unrelated input" /><MarketplacePanel {...model} /><PluginDetailSheet {...model} /></>;+}+Object.assign(globalThis, { pluginDetailFocusProbe: async () => {+ await i18n.init({ lng: "en", resources: { en: { translation: en } } });+ const plugin = { id: "test.focus", name: "Focus test", description: "Test marketplace card", author: "Test",+ latestVersion: "1.0.0", updatedAt: "2026-09-01T00:00:00Z", permissionSummary: [], categories: [], versions: [], permissions: [] };+ // Fixture only the IPC boundary; the hook, card, sheet and close actions are real.+ Object.assign(api, {+ listProjects: async () => ({ projects: [] }), listPlugins: async () => ({ plugins: [] }),+ listPluginServices: async () => [], marketCheckUpdates: async () => ({}),+ marketSearch: async () => ({ plugins: [plugin] }), marketGetDetail: async () => ({ plugin }),+ onPluginChanged: () => () => {}, onPluginInstallProgress: () => () => {},+ });+ usePluginBrowseState.setState({ tab: "market" });+ const container = document.createElement("div"); document.body.append(container);+ const root = createRoot(container);+ flushSync(() => root.render(<I18nextProvider i18n={i18n}><Probe /></I18nextProvider>));+ await settle(() => !!document.querySelector(".plugins-card-hit"));+ const card = find(".plugins-card-hit");+ const open = async () => {+ card.focus(); card.click();+ await settle(() => !!document.querySelector('[role="dialog"]'));+ };+ const escape = async () => {+ document.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true }));+ await settle(() => !document.querySelector('[role="dialog"]'));+ };+ for (const theme of ["light", "dark"]) {+ document.documentElement.dataset.theme = theme;+ await open(); await escape();+ check(document.activeElement !== card, `${theme}: Escape left the marketplace opener focused`);+ }+ card.focus();+ check(document.activeElement === card, "Dismissal removed keyboard focusability");+ await open();+ find(".plugins-sheet-scrim").click();+ await settle(() => !document.querySelector('[role="dialog"]'));+ check(document.activeElement !== card, "Pointer dismissal left the opener focused");+ await open();+ const input = find("input"); input.focus(); await escape();+ check(document.activeElement === input, "Dismissal stole unrelated focus");+ root.unmount(); container.remove();+ return "PASS: Escape/pointer dismissal clear opener focus; keyboard and unrelated focus remain available";+} });