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): align permission risk tiers with permissions matrix
Totopo27857749d30dc2
diff --git a/apps/desktop/src/features/plugins/model.ts b/apps/desktop/src/features/plugins/model.tsindex 2d02271b8..d483cde5c 100644--- a/apps/desktop/src/features/plugins/model.ts+++ b/apps/desktop/src/features/plugins/model.ts@@ -49,11 +49,15 @@ export const PERMISSION_RISK: Record<string, RiskTier> = {"agent.extension": "high",// Its code runs in the app's own document, so the grant is the boundary."renderer.extension": "high",+ "provider.register": "high",// The isolated plugin callback can read its own encrypted OAuth credentials."provider.oauth": "high","desktop.control": "high",+ "project.create": "high","session.read": "high","session.autoTitle": "high",+ "session.import": "high",+ "session.delete.own": "high","browser.cdp": "high",// Reading is a tier below writing because what makes a read dangerous is// where the data can go, and outbound requests are declared separately.@@ -65,7 +69,10 @@ export const PERMISSION_RISK: Record<string, RiskTier> = {"shell.openExternal": "medium","mcp.server.local": "high","mcp.server.remote": "high",- "background.service": "high",+ "background.service": "medium",+ "session.read.own": "medium",+ "session.update.own": "medium",+ "composer.transform": "medium",// Per-turn counters and session titles only, per the usage.read matrix row."usage.read": "medium",// Two capabilities that reach outside PI-Desktop's own window or read its@@ -78,9 +85,12 @@ export const PERMISSION_RISK: Record<string, RiskTier> = {"bus.publish": "medium","bus.subscribe": "medium","ui.panel": "low",- "ui.microphone": "medium",+ "ui.view": "low","ui.theme": "low",- notify: "low",+ "ui.settings": "low",+ "ui.window.appearance": "low",+ "ui.microphone": "medium",+ "notify": "low",};/** Display order for capability badges: what it adds before what it runs. */diff --git a/apps/desktop/test/plugin-runtime-risk.test.mjs b/apps/desktop/test/plugin-runtime-risk.test.mjsindex a516b6c0b..0058f8361 100644--- a/apps/desktop/test/plugin-runtime-risk.test.mjs+++ b/apps/desktop/test/plugin-runtime-risk.test.mjs@@ -98,6 +98,7 @@ test("the plugins page shows the file scope behind a file permission", () => {// so the row has to carry it or the user is approving a blank cheque.assert.match(pageSrc, /"fs\.write": "high"/);assert.match(pageSrc, /"fs\.read": "medium"/);+ assert.match(pageSrc, /"background\.service": "medium"/);assert.match(pageSrc, /function FsScopeChips\(/);assert.match(pageSrc, /t\("plugins\.fsAsksEachTime"\)/);assert.match(pageSrc, /t\("plugins\.legacyFsDowngraded"\)/);@@ -262,3 +263,35 @@ test("verified trust is not something a catalog entry can grant itself", () => {assert.match(pageSrc, /\{showsVerifiedBadge\(item\) \?/);assert.match(pageSrc, /\{showsVerifiedBadge\(detail\) \?/);});++test("PERMISSION_RISK mirrors every permission tier in the permissions matrix (#1480)", () => {+ const matrixPath = join(repoRoot, "docs/spec/07-plugins/13-plugin-permissions-matrix.md");+ const matrixContent = readFileSync(matrixPath, "utf8");+ const matrixEntries = [...matrixContent.matchAll(/^\| `([A-Za-z0-9.]+)` \| (low|medium|high) \|/gm)].map((m) => ({+ permission: m[1],+ risk: m[2],+ }));++ assert.ok(matrixEntries.length > 0, "permissions matrix must contain permission rows");++ const matrixMap = Object.fromEntries(matrixEntries.map((e) => [e.permission, e.risk]));+ const modelEntries = [...pageSrc.matchAll(/"([a-zA-Z0-9.]+)":\s*"(low|medium|high)"/g)].map((m) => ({+ permission: m[1],+ risk: m[2],+ }));+ const modelMap = Object.fromEntries(modelEntries.map((e) => [e.permission, e.risk]));++ for (const [permission, expectedRisk] of Object.entries(matrixMap)) {+ assert.equal(+ modelMap[permission],+ expectedRisk,+ `PERMISSION_RISK["${permission}"] should be "${expectedRisk}" as defined in permissions matrix`,+ );+ }++ assert.deepEqual(+ Object.keys(modelMap).sort(),+ Object.keys(matrixMap).sort(),+ "PERMISSION_RISK must define exactly the set of permissions from the permissions matrix",+ );+});diff --git a/docs/spec/07-plugins/13-plugin-permissions-matrix.md b/docs/spec/07-plugins/13-plugin-permissions-matrix.mdindex 4e737cb93..81626a97c 100644--- a/docs/spec/07-plugins/13-plugin-permissions-matrix.md+++ b/docs/spec/07-plugins/13-plugin-permissions-matrix.md@@ -11,6 +11,7 @@ Provide a permission–capability–risk–default-policy reference table for re| `ui.panel` | low | Open the plugin panel | Granted at install | Needed by almost all UI plugins || `ui.view` | low | `contributes.views` are listed in the work panel and may be opened | Granted at install | Same isolation as a panel window: sandboxed page, per-plugin partition, `net.domains` egress. Filtered by activation scope || `ui.theme` | low | `contributes.themes` CSS is loaded and offered in Settings; runtime `pi.themes.upsert` / `remove` / `list` and `pi.app.setTheme` (ADR 0260) | Granted at install | CSS is sanitized by the host; it cannot script. Declared `assets` are served over the host's read-only `plugin-asset:` scheme. `setTheme` may only select a built-in preference or a currently registered plugin theme. There is no per-plugin theme count cap |+| `ui.settings` | low | `contributes.settingsDestinations` adds a sandboxed Settings entry in Extensions | Granted at install | Rendered only in host Extensions group; isolated view host with same sandbox as panel views (ADR 0261) || `ui.window.appearance` | low | `contributes.windowAppearance` sets the native window background and Windows main-window corner radius while one of the plugin's themes is selected | Granted at install | `#rrggbb` / `#rrggbbaa` background and integer `cornerRadius` 0..24 DIP; restores host background and the global 12 DIP `--radius-md` radius when the theme is gone. macOS keeps vibrancy and native corners || `clipboard.read` | medium | `clipboard.readText`, `clipboard.getHistory` | Confirm on first use | May read sensitive information and retained clipboard history || `clipboard.write` | medium | `clipboard.writeText` | Confirm on first use | Prevents clipboard pollution |diff --git a/docs/zh-CN/spec/07-plugins/13-plugin-permissions-matrix.md b/docs/zh-CN/spec/07-plugins/13-plugin-permissions-matrix.mdindex a1d230c26..e59af06d5 100644--- a/docs/zh-CN/spec/07-plugins/13-plugin-permissions-matrix.md+++ b/docs/zh-CN/spec/07-plugins/13-plugin-permissions-matrix.md@@ -14,6 +14,7 @@| `ui.panel` | 低 | 打开插件面板 | 安装时授予 | 几乎所有 UI 插件都需要 || `ui.view` | 低 | `contributes.views` 在工作面板中列出并可打开 | 安装时授予 | 与面板窗口同级隔离:沙箱页面、按插件划分的会话分区、`net.domains` 出口限制。按激活范围过滤 || `ui.theme` | 低 | `contributes.themes` CSS 已在“设置”中加载并提供 | 安装时授予 | CSS 由主机清理;它无法编写脚本。已声明的 `assets` 通过主机的只读 `plugin-asset:` 协议提供 |+| `ui.settings` | 低 | `contributes.settingsDestinations` 在“扩展”中添加沙盒设置项 | 安装时授予 | 仅在宿主“扩展”分组中呈现;使用与面板视图相同沙箱的隔离视图宿主(ADR 0261) || `ui.window.appearance` | 低 | 该插件主题被选中时,用 `contributes.windowAppearance` 设置原生窗口背景 | 安装时授予 | 仅接受 `#rrggbb` / `#rrggbbaa`;按解析后的明暗生效,主题消失后回到宿主默认值。macOS 保持 vibrancy || `clipboard.read` | 中等 | `clipboard.readText`、`clipboard.getHistory` | 首次使用时确认 | 可能会读取敏感信息和保留的剪贴板历史 || `clipboard.write` | 中等 | `clipboard.writeText` | 首次使用时确认 | 防止剪贴板污染 |