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(docs): align plugin theme guide with the runtime contract
xjxec76dde04b33
diff --git a/docs/README.md b/docs/README.mdindex 8f68672ee..444eb8b7a 100644--- a/docs/README.md+++ b/docs/README.md@@ -37,3 +37,8 @@ path-for-path companion for every specification. Each translated page links tothe canonical English source and preserves code, protocol fields, andidentifiers. The generated sidebar keeps both locale trees complete as thespecification set grows.++`check:locales` also checks the standalone plugin development guide's Chinese+mirror and canonical source notice. Its theme section must preserve the English+JSON/CSS examples and table structure. Other standalone guide sections are not+covered by that theme-contract comparison.diff --git a/docs/plugin-development.md b/docs/plugin-development.mdindex b0bec9f94..38527666a 100644--- a/docs/plugin-development.md+++ b/docs/plugin-development.md@@ -529,17 +529,49 @@ Declare a CSS file and `ui.theme`:"id": "midnight","label": "Midnight","path": "themes/midnight.css",- "base": "dark"+ "base": "dark",+ "assets": ["themes/background.svg"]}- ]+ ],+ "windowAppearance": {+ "backgroundColor": { "dark": "#141a24", "light": "#f5f7fa" }+ }},- "permissions": ["ui.theme"]+ "permissions": ["ui.theme", "ui.window.appearance"]}```-Override PI-Desktop design tokens in that CSS. The host sanitizes contributed-CSS, refuses imports and non-data URLs, caps each file at 256 KiB, and allows up-to eight themes per plugin. The user selects the theme in Settings.+`base` selects the built-in `light` or `dark` palette underneath the overrides;+omitting it defaults to `dark`. The user selects the contributed theme in Settings.++Match the base palette's selector when overriding design tokens:++```css+:root[data-theme="dark"] { --ds-bg-primary: #141a24; }+:root[data-theme="light"] { --ds-bg-primary: #f5f7fa; }+```++The theme stylesheet is appended after the host styles, but later source order+wins only when selector specificity is equal. The host palette selectors are+`:root[data-theme="dark"]` and `:root[data-theme="light"]`; a bare `:root`+has lower specificity and is not sufficient to override those declarations.+For a light-base theme, explicitly use `:root[data-theme="light"]`.++The host sanitizes CSS, rejects `@import` and `url()` targets other than `data:`+URIs or declared theme assets,+caps each stylesheet at 256 KiB, and allows eight themes per plugin. Optional+`assets` accepts `png`, `jpg`, `jpeg`, `webp`, `avif`, `svg`, and `woff2` files,+with a summed limit of 4 MiB. Paths may be package-relative (inside the plugin+root, without traversal or `node_modules`) or absolute. Matching CSS URLs are+rewritten to registered, read-only `plugin-asset://` URLs; unloading the plugin+revokes them. The renderer never receives the raw filesystem path.++Optional `contributes.windowAppearance.backgroundColor` supplies `light`/`dark`+colors in `#rrggbb` or `#rrggbbaa` form and requires `ui.window.appearance` in+addition to `ui.theme`. It applies only while that plugin's theme is selected;+switching away restores the host background. macOS retains its vibrancy.+See the [manifest contract](spec/07-plugins/02-plugin-manifest-schema.md) for+all theme and window-appearance fields.### 6.8 Work panel viewdiff --git a/docs/scripts/check-locales.mjs b/docs/scripts/check-locales.mjsindex 6d8c37f1b..a32bb15a7 100644--- a/docs/scripts/check-locales.mjs+++ b/docs/scripts/check-locales.mjs@@ -3,8 +3,6 @@ import path from 'node:path'import { fileURLToPath } from 'node:url'const docsRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')-const englishRoot = path.join(docsRoot, 'spec')-const chineseRoot = path.join(docsRoot, 'zh-CN/spec')function markdownFiles(directory) {return fs.readdirSync(directory, { recursive: true, withFileTypes: true })@@ -29,7 +27,13 @@ function tableShape(source) {.map((line) => [...line].filter((character) => character === '|').length)}-export function verifyLocalePairs() {+function themeSection(source) {+ return source.split(/^### 6\.7[^\n]*$/m)[1]?.split(/^### /m)[0]+}++export function verifyLocalePairs(root = docsRoot) {+ const englishRoot = path.join(root, 'spec')+ const chineseRoot = path.join(root, 'zh-CN/spec')const englishFiles = markdownFiles(englishRoot)const missing = []const invalid = []@@ -58,6 +62,28 @@ export function verifyLocalePairs() {}}+ // The standalone guide is not in spec/. Its theme contract must preserve+ // literal JSON/CSS examples, not merely the number of code fences. Other+ // guide sections are outside this theme-contract check.+ const guide = 'plugin-development.md'+ englishFiles.push(guide)+ const mirror = path.join(root, 'zh-CN', guide)+ if (!fs.existsSync(mirror)) {+ missing.push(guide)+ } else {+ const source = fs.readFileSync(mirror, 'utf8')+ const englishTheme = themeSection(fs.readFileSync(path.join(root, guide), 'utf8'))+ const chineseTheme = themeSection(source)+ const snippets = (section) => section.match(/^```[^\n]*\n[\s\S]*?^```/gm) ?? []+ if (!/^#\s+\S+/m.test(source) || !/[\u3400-\u9fff]/.test(source)+ || !source.includes('[英文源页面](/plugin-development)') || source.includes('PIHOLDTOKEN')+ || !englishTheme || !chineseTheme+ || JSON.stringify(snippets(englishTheme)) !== JSON.stringify(snippets(chineseTheme))+ || JSON.stringify(tableShape(englishTheme)) !== JSON.stringify(tableShape(chineseTheme))) {+ invalid.push(guide)+ }+ }+return { englishFiles, missing, invalid }}@@ -69,7 +95,7 @@ function main() {if (invalid.length) console.error(`Invalid Chinese source notices:\n${invalid.join('\n')}`)process.exitCode = 1} else {- console.log(`Verified ${englishFiles.length} English/Chinese specification pairs.`)+ console.log(`Verified ${englishFiles.length} English/Chinese documentation pairs.`)}}diff --git a/docs/scripts/check-locales.test.mjs b/docs/scripts/check-locales.test.mjsindex 12e9ca165..ba2877734 100644--- a/docs/scripts/check-locales.test.mjs+++ b/docs/scripts/check-locales.test.mjs@@ -1,5 +1,7 @@import assert from 'node:assert/strict'import path from 'node:path'+import fs from 'node:fs'+import os from 'node:os'import { test } from 'node:test'import { noticeRoute, verifyLocalePairs } from './check-locales.mjs'@@ -21,3 +23,32 @@ test('every English specification has a valid Chinese mirror', () => {assert.deepEqual(missing, [], 'Chinese specifications missing for the listed English pages')assert.deepEqual(invalid, [], 'Chinese pages whose source notice or structure is invalid')})++test('the plugin development guide participates in locale checks', () => {+ assert.ok(verifyLocalePairs().englishFiles.includes('plugin-development.md'))+})++test('plugin guide checks reject missing mirrors and divergent theme examples', () => {+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'pi-theme-docs-'))+ try {+ fs.mkdirSync(path.join(root, 'spec'))+ fs.mkdirSync(path.join(root, 'zh-CN/spec'), { recursive: true })+ const english = '# Plugins\n\n### 6.7 Theme\n\n```json\n{"base":"dark"}\n```\n\n### 6.8 Views\n'+ const chinese = '# 插件\n\n[英文源页面](/plugin-development)\n\n### 6.7 主题\n\n```json\n{"base":"dark"}\n```\n\n### 6.8 视图\n'+ fs.writeFileSync(path.join(root, 'plugin-development.md'), english)+ const mirror = path.join(root, 'zh-CN/plugin-development.md')+ assert.deepEqual(verifyLocalePairs(root).missing, ['plugin-development.md'])+ fs.writeFileSync(mirror, chinese)+ assert.deepEqual(verifyLocalePairs(root).invalid, [])+ for (const broken of [+ chinese.replace('"dark"', '"light"'),+ chinese.replace('### 6.7 主题', '### 6.6 主题'),+ chinese.replace('/plugin-development', '/wrong-source'),+ ]) {+ fs.writeFileSync(mirror, broken)+ assert.deepEqual(verifyLocalePairs(root).invalid, ['plugin-development.md'])+ }+ } finally {+ fs.rmSync(root, { recursive: true, force: true })+ }+})diff --git a/docs/spec/04-ux/07-ui-design-system.md b/docs/spec/04-ux/07-ui-design-system.mdindex 59d2f0cf5..e2dea2660 100644--- a/docs/spec/04-ux/07-ui-design-system.md+++ b/docs/spec/04-ux/07-ui-design-system.md@@ -16,7 +16,8 @@ The desktop shell targets a 1:1 visual match with the local Codex desktop client1. A consumer-brand identity system with vibrant gradients or playful illustrations2. A full component library spec (that is [08-component-spec.md](08-component-spec.md))3. Custom font services or CDN font hosting — use local bundling-4. Complex theme marketplace or user-customizable color palettes (MVP: system/light/dark only)+4. An interactive color-palette editor; built-in system/light/dark choices and+ plugin-contributed `ui.theme` entries are supported5. Pixel-perfect Figma handoff artifacts## 3. Visual principlesdiff --git a/docs/spec/07-plugins/04-plugin-security.md b/docs/spec/07-plugins/04-plugin-security.mdindex 4301e6915..df25d67e8 100644--- a/docs/spec/07-plugins/04-plugin-security.md+++ b/docs/spec/07-plugins/04-plugin-security.md@@ -120,7 +120,10 @@ before it is ever sent to the UI:behavior; Windows defaults to 4 DIP- The CSS is read from disk at load time and delivered whole over IPC; therenderer injects it into a single dedicated `<style>` element appended after- the app's own stylesheets, so it can override tokens but never inject markup+ the app's own stylesheets, so it can override tokens but never inject markup.+ Later source order wins only at equal selector specificity: use+ `:root[data-theme="light"]` or `:root[data-theme="dark"]` to match the base+ palette's selector; bare `:root` has lower specificity- Selecting a theme is a settings value (`plugin:<pluginId>:<themeId>`); if theproviding plugin is disabled or uninstalled the setting falls back to `system`diff --git a/docs/zh-CN/plugin-development.md b/docs/zh-CN/plugin-development.mdindex abb8e6578..e0047a4fd 100644--- a/docs/zh-CN/plugin-development.md+++ b/docs/zh-CN/plugin-development.md@@ -505,17 +505,45 @@ root 本身。`net.fetch` 接受 HTTP(S),并且只能到达 `manifest.net.doma"id": "midnight","label": "Midnight","path": "themes/midnight.css",- "base": "dark"+ "base": "dark",+ "assets": ["themes/background.svg"]}- ]+ ],+ "windowAppearance": {+ "backgroundColor": { "dark": "#141a24", "light": "#f5f7fa" }+ }},- "permissions": ["ui.theme"]+ "permissions": ["ui.theme", "ui.window.appearance"]}```-覆盖该 CSS 中的 PI-Desktop 设计标记。楼主对贡献的内容进行了清理-CSS,拒绝导入和非数据 URL,每个文件的上限为 256 KiB,并允许-每个插件有八个主题。用户在“设置”中选择主题。+`base` 选择覆盖样式所基于的内置 `light` 或 `dark` 调色板;省略时默认+为 `dark`。用户在“设置”中选择插件贡献的主题。++覆盖设计令牌时,应使用与基础调色板相同的选择器:++```css+:root[data-theme="dark"] { --ds-bg-primary: #141a24; }+:root[data-theme="light"] { --ds-bg-primary: #f5f7fa; }+```++主题样式表追加在宿主样式之后,但只有选择器特异度相同时,后写的声明才胜出。+宿主调色板使用 `:root[data-theme="dark"]` 和 `:root[data-theme="light"]`;+单独的 `:root` 特异度较低,不能保证覆盖这些声明。浅色基础主题应显式使用+`:root[data-theme="light"]`。++宿主清理 CSS,拒绝 `@import`,`url()` 目标仅允许 `data:` URI 或已声明的主题资源;每份+样式表上限 256 KiB,每个插件最多八个主题。可选 `assets` 接受 `png`、`jpg`、+`jpeg`、`webp`、`avif`、`svg`、`woff2` 文件,总大小上限 4 MiB。路径可以是插件包内+相对路径(不得逃出插件根目录或引用 `node_modules`),也可以是绝对路径。+匹配的 CSS URL 会改写为已注册、只读的 `plugin-asset://` URL;卸载插件时撤销+注册,渲染器不会收到原始文件系统路径。++可选的 `contributes.windowAppearance.backgroundColor` 为 `light`/`dark` 提供+`#rrggbb` 或 `#rrggbbaa` 颜色,除 `ui.theme` 外还需要 `ui.window.appearance`。+它仅在该插件的主题被选中时生效,切换到其他主题后恢复宿主背景;macOS 保留+系统 vibrancy。完整主题与窗口外观字段参见+[清单契约](spec/07-plugins/02-plugin-manifest-schema.md)。### 6.8 MCP 服务器diff --git a/docs/zh-CN/spec/04-ux/07-ui-design-system.md b/docs/zh-CN/spec/04-ux/07-ui-design-system.mdindex caba303ca..0e9217fb6 100644--- a/docs/zh-CN/spec/04-ux/07-ui-design-system.md+++ b/docs/zh-CN/spec/04-ux/07-ui-design-system.md@@ -19,7 +19,7 @@1. 具有充满活力的渐变或有趣的插图的消费者品牌识别系统2. 完整的组件库规范(即[08-component-spec.md](/zh-CN/spec/04-ux/08-component-spec))3. 自定义字体服务或 CDN 字体托管 — 使用本地捆绑-4. 复杂的主题市场或用户可自定义的调色板(仅限 MVP:仅限 system/light/dark)+4. 交互式调色板编辑器;已支持内置 system/light/dark 选项和插件贡献的 `ui.theme` 主题项5. 像素完美的 Figma 切换伪影## 3. 视觉原则diff --git a/docs/zh-CN/spec/07-plugins/04-plugin-security.md b/docs/zh-CN/spec/07-plugins/04-plugin-security.mdindex eb7285980..faea1cad5 100644--- a/docs/zh-CN/spec/07-plugins/04-plugin-security.md+++ b/docs/zh-CN/spec/07-plugins/04-plugin-security.md@@ -72,7 +72,10 @@永不下发颜色- CSS 在加载时从磁盘读取并通过 IPC 整体交付;的渲染器将其注入到附加在后面的单个专用 `<style>` 元素中- 应用程序自己的样式表,因此它可以覆盖令牌但从不注入标记+ 应用程序自己的样式表,因此它可以覆盖令牌但从不注入标记。+ 后写的声明只有在选择器特异度相同时才胜出;应使用+ `:root[data-theme="light"]` 或 `:root[data-theme="dark"]` 匹配基础调色板的+ 选择器,单独的 `:root` 特异度更低- 选择主题是一个设置值(`plugin:<pluginId>:<themeId>`);如果如果插件被禁用或卸载,设置将回退到 `system`