Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
docs(workflow): reuse host environment for e2e
vastsa4e04e49889c6
diff --git a/AGENTS.md b/AGENTS.mdindex 3dcdac89e..8901560b8 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -1,6 +1,6 @@# AGENTS.md-Policy-Sync: 2026-09-21.1+Policy-Sync: 2026-09-21.2Mandatory rules for AI coding agents working in PI-Desktop.@@ -235,6 +235,21 @@ cd <worktree-path>All implementation, targeted validation, conflict resolution, andtask-candidate E2E happen inside the task's dedicated worktree.+### E2E environment reuse++Task-candidate E2E runs from the dedicated request worktree but reuses the+host development environment already provisioned in the primary checkout.+Reuse the host Node/pnpm toolchain, compatible `node_modules`, Electron,+Rust/Cargo targets, package-manager stores, build caches, and ignored local+configuration by reference or link when needed.++Do not run `pnpm install`, `npm install`, or create a second dependency or+runtime environment solely to execute E2E. Keep only mutable test state+(temporary profiles, data directories, sockets, ports, logs, and artifacts)+isolated to the request worktree or its scratch directory. Install or rebuild+dependencies only when the host environment is missing or incompatible, and+record that reason. Clean CI and release runners may install from lockfiles.+### Before candidate validationRefresh the task against the latest remote `main`.diff --git a/CLAUDE.md b/CLAUDE.mdindex b9d670562..78ac22147 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -1,6 +1,6 @@# CLAUDE.md-Policy-Sync: 2026-09-21.1+Policy-Sync: 2026-09-21.2Instructions for Claude Code CLI and Claude Cowork on PI-Desktop.@@ -92,6 +92,19 @@ Environment:If a required suite cannot run, report `NOT RUN` with reason, alternative validation, and remaining risk. Never report a skipped command as passing.+### E2E environment reuse++Task-candidate E2E uses the host development environment already provisioned+in the primary checkout. Reuse its Node/pnpm toolchain, compatible+`node_modules`, Electron, Rust/Cargo targets, stores, caches, and ignored+configuration by reference or link when needed.++Never run `pnpm install` or `npm install`, or create a second dependency or+runtime environment, solely for E2E. Keep temporary profiles, data, sockets,+ports, logs, and artifacts isolated. Install or rebuild only for missing or+incompatible host dependencies, and record the reason; clean CI/release+runners may install from lockfiles.+### Architecture (frozen)```textdiff --git a/docs/spec/06-delivery/03-ai-development-workflow.md b/docs/spec/06-delivery/03-ai-development-workflow.mdindex 56ac50fcb..10d0b7a9a 100644--- a/docs/spec/06-delivery/03-ai-development-workflow.md+++ b/docs/spec/06-delivery/03-ai-development-workflow.md@@ -56,8 +56,14 @@ The rules below govern every change to the PI-Desktop codebase and documentationtoolchains, package-manager stores, build caches, and ignored localenvironment configuration remain the canonical environment. Reference orlink those resources into the request worktree when required; do not copy- environment state into tracked files. Install or generate worktree-local- state only when isolation or version compatibility requires it.+ environment state into tracked files. Generate other worktree-local state only+ when isolation or version compatibility requires it.+- Task-candidate E2E runs from the request worktree but must reuse the host+ dependency/runtime environment already provisioned in the primary checkout.+ Do not run `pnpm install`, `npm install`, or create a second environment+ solely for E2E. Keep temporary profiles, data directories, sockets, ports,+ logs, and artifacts isolated; install or rebuild only when host dependencies+ are missing or incompatible, and record the reason.- Development commits and direct pushes on `main` are forbidden.- A commit request does not itself authorize remote publishing. If remotedelivery has not been authorized, stop after the request-branch commit in the@@ -295,6 +301,12 @@ Every change follows this sequence. Steps may be iterated if the implementationa PR/MR is opened, and must run the union of suites required by the affectedregression surfaces. The available commands are defined by the root`package.json` and the selection matrix in `04-e2e-test-plan.md`.+- Task-candidate E2E may use the request worktree's source, but it must use the+ host dependency/runtime environment described in R4. Do not reinstall the+ repository environment for each run; only missing or incompatible host+ dependencies justify installation or rebuild, and that reason must be+ recorded. Temporary profiles, data, sockets, ports, logs, and artifacts+ remain isolated from the host's mutable runtime state.- Development-time iteration remains risk-based: an E2E run on a stale requestbranch may be used for debugging, but only a run after incorporating`origin/main` satisfies this policy.@@ -452,10 +464,13 @@ worktree directly from the fetched `origin/main`. Never discard, stash, move,or overwrite unrelated work merely to satisfy this sequence.Environment reuse is resource-specific. Package-manager stores and language-toolchains are normally shared automatically. Ignored local configuration or a-compatible dependency tree may be referenced or linked from the primary-checkout when a task needs it. Build outputs that can race, mutable runtime-data, and incompatible dependency trees must remain worktree-local.+toolchains are normally shared automatically. A compatible dependency tree+and Electron/Rust build targets should be referenced or linked from the+primary checkout when a task needs them; do not run `pnpm install` or+`npm install` merely because the request uses a separate worktree. Build+outputs that can race, mutable runtime data, temporary E2E profiles, and+incompatible dependency trees must remain worktree-local. Clean CI and release+runners are the exception and may install from lockfiles.Typical authorized GitHub delivery (use the hosting platform's equivalent whenneeded; synchronize and clean up from the clean primary checkout after merge):diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.mdindex 7359c94bd..618029e12 100644--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@ -194,6 +194,20 @@ passes. An E2E run on a branch that is behind `origin/main` is exploratory anddoes not satisfy this gate. Do not merge the task into local `main` to createthe candidate.+### E2E environment reuse++Task-candidate E2E runs from the request worktree after the candidate is+prepared, but uses the host development environment already provisioned in the+primary checkout. Reuse the compatible Node/pnpm toolchain, `node_modules`,+Electron, Rust/Cargo targets, package-manager stores, build caches, and ignored+configuration by reference or link when needed.++Do not run `pnpm install`, `npm install`, or create a second dependency/runtime+environment solely for E2E. Isolate only mutable test state: temporary+profiles, data directories, sockets, ports, logs, and artifacts. Install or+rebuild dependencies only when the host environment is missing or incompatible+and record the reason. Clean CI and release runners may install from lockfiles.+Use the root `package.json` as the source of truth for executable commands.The minimum selection is:diff --git a/docs/spec/06-delivery/05-change-checklist.md b/docs/spec/06-delivery/05-change-checklist.mdindex 9365af2d7..4e063d515 100644--- a/docs/spec/06-delivery/05-change-checklist.md+++ b/docs/spec/06-delivery/05-change-checklist.md@@ -68,10 +68,11 @@ Before editing any file for a new request:worktree is clean.- [ ] A dedicated `<type>/<short-description>` request branch and worktree arecreated from that updated `main` commit.-- [ ] The request worktree reuses the primary checkout's toolchains, package- stores, caches, and ignored local configuration where safe.-- [ ] Mutable, incompatible, or concurrency-sensitive environment state stays- worktree-local and ignored.+- [ ] The request worktree reuses the primary checkout's host toolchains,+ compatible dependency tree, package stores, caches, and ignored local+ configuration where safe; no separate environment is installed for E2E.+- [ ] Only mutable, incompatible, or concurrency-sensitive environment state+ stays worktree-local and ignored.- [ ] The current branch is not `main` before implementation begins.- [ ] Delivery scope is recorded: a commit request stays on the requestbranch; a push request includes PR-based remote `main` integration after@@ -126,6 +127,10 @@ After implementation (or alongside it):opened, or before a commit-only delivery was declared complete; requiredvalidation needs no separate user request. Documentation-only changes retaintheir existing exemption.+- [ ] Task-candidate E2E used the host development environment already+ provisioned in the primary checkout; no `pnpm install`/`npm install` or+ second dependency/runtime environment was created solely for E2E. Any+ missing/incompatible-host exception is recorded with its reason.- [ ] Results apply to the commit the gate ran on, and the affected suites werererun when the landed executable content changed. Any required suite not runis recorded with its reason, alternative validation, and remaining risk;diff --git a/docs/zh-CN/spec/06-delivery/03-ai-development-workflow.md b/docs/zh-CN/spec/06-delivery/03-ai-development-workflow.mdindex 35026bc7b..a58da7840 100644--- a/docs/zh-CN/spec/06-delivery/03-ai-development-workflow.md+++ b/docs/zh-CN/spec/06-delivery/03-ai-development-workflow.md@@ -45,7 +45,9 @@- 编辑前保留未提交工作,获取 `origin/main`,工作树干净时快进本地 `main`,并从该提交创建请求分支和工作树。不得为了开新请求而移动、藏匿或覆盖主工作区里的现有工作。- 每个请求使用一个短期分支,命名为 `<type>/<short-description>`。- 每个请求使用一个专用工作树。不要在主工作区或别人的工作树里实现新请求。-- 在安全的情况下复用主工作区的工具链、包存储和缓存。+- 在安全的情况下复用主工作区的宿主开发环境:工具链、兼容的+ `node_modules`、Electron、Rust/Cargo 目标、包存储、缓存和忽略的本地配置。+ 必要时通过引用或链接使用,不要为 E2E 单独安装第二套环境。- 禁止在 `main` 上开发或直接推送。- 仅请求提交并不授权远程发布。未获远程授权时,停在任务分支提交;不要为了跑 E2E 把任务合进本地 `main`。- 打开或更新 PR/MR 之前,获取 `origin/main` 并确认它是请求 head 的祖先(`git merge-base --is-ancestor origin/main HEAD` 或 `pnpm check:pr-base`)。私有分支用 rebase;已共享且不宜改写历史时用非破坏性合并。不得打开或更新落后于 `origin/main` 的 PR。@@ -175,6 +177,7 @@- E2E 场景文档和 E2E 执行是不同的问题。 R3依然需要场景更新以实现用户可见或协议可见的行为。- 每个代码 PR 或本地 `main` 集成都必须运行至少一个相关 E2E 套件,并运行受影响回归面所需套件的并集。可用命令由根目录 `package.json` 和 `04-e2e-test-plan.md` 中的选择说明定义。+- task-candidate E2E 可以使用请求工作树中的源码,但必须使用 R4 所述的宿主依赖/运行时环境。不要每次运行都重新安装仓库环境;仅当宿主依赖缺失或不兼容时才安装或重建,并记录原因。临时 profile、数据、socket、端口、日志和工件仍须与宿主可变运行时状态隔离。- 开发迭代仍然基于风险:小改动不需要每次都运行全部套件,但合入前所有相关 E2E 必须通过。- 如果本地环境无法运行必需套件,必须记录套件、原因、替代验证和剩余风险。在具备条件且可信的环境中通过前,分支不具备合入条件。- 托管平台在运行后自动启动所需的 E2E 作业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 d47163dc0..a841c7da8 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@@ -99,6 +99,12 @@ unit/integration 测试;代码 pull request 使用有选择且高价值的 E2E每个代码 pull request 都必须在打开或更新前,在已经包含最新 `origin/main` 的候选上通过与其回归面相关的 E2E(`pnpm check:pr-base`)。不得打开落后于 `origin/main` 的 PR。不要为了跑 E2E 把任务合进本地 `main`。代码变更包括渲染器、Electron Main、Preload、Agent Runtime、Rust host-core、会话、转录、计划、插件、MCP、权限、供应商/模型运行时、持久化、进程生命周期、打包/启动,以及影响应用执行的构建或 CI 行为。仅文档更改在不影响可执行行为时可豁免。+### E2E 环境复用++task-candidate E2E 从请求工作树运行,但使用主工作区已经准备好的宿主开发环境。必要时通过引用或链接复用兼容的 Node/pnpm 工具链、`node_modules`、Electron、Rust/Cargo 目标、包存储、构建缓存和忽略的配置。++不得为了 E2E 单独运行 `pnpm install`、`npm install`,或创建第二套依赖/运行时环境。只隔离可变测试状态:临时 profile、数据目录、socket、端口、日志和工件。仅当宿主环境缺失或不兼容时才安装或重建依赖,并记录原因;干净的 CI 和发布 runner 可以按 lockfile 安装。+根目录 `package.json` 是可执行命令的事实来源。最低选择如下:- 跨域运行时、host 或 IPC:`pnpm test:e2e`。diff --git a/docs/zh-CN/spec/06-delivery/05-change-checklist.md b/docs/zh-CN/spec/06-delivery/05-change-checklist.mdindex 0e6aa8ed3..9416c0ea9 100644--- a/docs/zh-CN/spec/06-delivery/05-change-checklist.md+++ b/docs/zh-CN/spec/06-delivery/05-change-checklist.md@@ -53,10 +53,8 @@工作树是干净的。- [ ] 专用的 `<type>/<short-description>` 请求分支和工作树是从更新的 `main` 提交创建。-- [ ] 请求工作树重用主结帐的工具链、包- 在安全的情况下存储、缓存和忽略本地配置。-- [ ] 保持可变、不兼容或并发敏感的环境状态- worktree-local 并被忽略。+- [ ] 请求工作树在安全的情况下复用主工作区的宿主工具链、兼容依赖树、包存储、缓存和忽略的本地配置;不为 E2E 安装单独环境。+- [ ] 只有可变、不兼容或并发敏感的环境状态保留在工作树本地并被忽略。- [ ] 在执行开始之前,当前分支不是 `main`。---@@ -100,12 +98,10 @@跨组件回归风险使它们成为必要。- [ ] 通过的最小必要目标本地检查或本地验证被评估为不必要,无需单独批准或豁免。-- [ ] 除非用户明确请求 E2E,否则不会运行 E2E 套件或命令- 验证。-- [ ] 如果用户请求 E2E 验证,则请求的套件及其结果- 都记录在移交中。-- [ ] 自动触发的远程 E2E 作业被视为合并门,但- 如果没有明确的用户请求,则不会手动调度或重新运行。+- [ ] 相关 E2E 套件在包含最新 `origin/main` 的候选上选择并通过,并记录实际结果。+- [ ] task-candidate E2E 使用主工作区已经准备好的宿主开发环境;没有为 E2E 单独运行 `pnpm install`/`npm install` 或创建第二套依赖/运行时环境。+- [ ] 只有宿主依赖缺失或不兼容时才安装或重建,并记录原因;临时 profile、数据、socket、端口、日志和工件保持隔离。+- [ ] 自动触发的远程 E2E 作业被观察并报告;只有当落地的可执行内容变化时才重新运行受影响套件。---diff --git a/scripts/check-agent-policy-sync.mjs b/scripts/check-agent-policy-sync.mjsindex 66b103d7a..b6bc71053 100644--- a/scripts/check-agent-policy-sync.mjs+++ b/scripts/check-agent-policy-sync.mjs@@ -99,6 +99,13 @@ const REQUIRED_ANCHORS = [id: "task-candidate-e2e",anyOf: ["task-candidate e2e"],},+ {+ id: "host-e2e-environment",+ anyOf: [+ "do not run `pnpm install`, `npm install`, or create a second dependency or runtime environment solely to execute e2e",+ "never run `pnpm install` or `npm install`, or create a second dependency or runtime environment, solely for e2e",+ ],+ },{id: "architecture-ratchet-hotspots",anyOf: [