Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

Merge remote-tracking branch 'origin/main' into feat/mode-definitions

vastsa116145d3b938
diff --cc docs/spec/06-delivery/04-e2e-test-plan.md
index 7599c5539,4b2df7c3e..78f1fccaf
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@@ -20382,26 -20392,19 +20392,42 @@@ Bounded tail pages include compactions
While a checkpoint estimate supplies context occupancy, use its recorded provider/model capacity, or the current exact session binding for legacy checkpoints. Keep historical request usage unchanged. Unknown capacity is marked approximate. Verify 20,619 / 1,000,000 = 2%, unknown routes, legacy records and usage after a newer request with `compaction-context-usage.test.mjs`.
+
+## User-defined mode workflow acceptance
+
+Candidate command: `PI_DESKTOP_HOST_BIN=<candidate-host> node scripts/e2e-mode-definitions.mjs`
+with `PI_SCRATCH_DIR` set to an isolated test directory. No model API is called.
+
+1. Configure a session with a two-stage definition snapshot. Start a durable
+ turn and claim the first contract stage.
+2. Request completion without its required artifact; observe a failed gate.
+3. Supply the artifact through stage completion; verify its exact disk content
+ and the waiting-for-approval state.
+4. Settle the first turn, approve with the current revision and claim the next
+ stage with approval provenance.
+5. Submit the stage's command gate. A changed command must fail with
+ `MODE_GATE_MISMATCH` before execution.
+6. Execute the exact command through `tools.execute`; consume the Host-recorded
+ result and observe finished, no open run, and session mode Agent.
+
+Companion tests: `mode_runs::*` and `rpc::modes_rpc::tests::*` cover migration,
+recovery, CAS, budget and permission caps; desktop `mode-definitions-user-path`,
+`mode-definitions-renderer` and `mode-runs-main` cover source editing, selection,
+run controls and Main dispatch. Runtime `modes/*` covers stage completion and
+compaction injection.
+ #### E2E-ISSUE-2173: Redundant delegation job selectors
+
+ - Entry: build shared/agent-runtime/host-runtime and Host, then run
+ `PI_DESKTOP_HOST_BIN=<candidate-host> node scripts/e2e-task-job-selectors.mjs`.
+ - Preconditions: isolated Host data/workspace and a deterministic localhost
+ provider; production parent and delegate loops, with no external model account.
+ - Steps: start a delegate; wait with both its job reference and matching
+ delegationIds; re-read with empty delegationIds and single-job mode/minCompleted;
+ start another delegate, hold its provider response, stop it with both selectors,
+ and confirm its stopped state through TaskWait.
+ - Expected: reports remain readable, redundant selectors do not cause errors,
+ single-job mode/minCompleted are ignored, and cancellation settles the target.
+ Unit tests also reject conflicting/malformed IDs and mixed Bash selectors.
+ - Specs: `03-runtime/02-agent-runtime.md`, Session job controls.
+ - Acceptance: wait, report re-read and running-delegate cancellation complete
+ through the real tool loop. Milestone: maintenance. Status: automated.
diff --cc docs/zh-CN/spec/03-runtime/04-data-storage.md
index d234c28a4,d234c28a4..6454289c3
--- a/docs/zh-CN/spec/03-runtime/04-data-storage.md
+++ b/docs/zh-CN/spec/03-runtime/04-data-storage.md
@@@ -1489,3 -1489,3 +1489,20 @@@ Task remain separate optional transcrip
有界末尾页包含最后一条消息之后追加的压缩记录,重新打开或重启后立即返回
最新检查点和上下文估算。历史中间页只保留生效的检查点及页内记录,不读取全链。
++
++
++## User-defined mode runs (schema 29)
++
++ADR `mode-definitions` adds one v28-to-v29 migration. It backs up the existing
++database before adding `mode_snapshots`, `mode_runs`, `mode_gate_results` and
++`sessions.mode_snapshot_hash`. Existing sessions and Plan approvals are retained.
++Mode ids remain in `sessions.mode`; `chat` still normalizes to `plan`.
++
++A run references an immutable definition snapshot, its current stage, revision,
++claim, permission origin, budgets, token usage and completed-round count.
++Gate results record the stage, action, outcome and bounded evidence. At most
++one open run exists per session. Restart clears in-flight claims and pauses
++those runs without replaying work. Deleting a session cascades its run records.
++
++Host-started turns evaluate Auto as Accept edits. A run's original snapshot
++remains authoritative even when its source file changes.
diff --cc docs/zh-CN/spec/03-runtime/06-host-rpc-protocol.md
index c1ab1f45b,c1ab1f45b..01a16fad1
--- a/docs/zh-CN/spec/03-runtime/06-host-rpc-protocol.md
+++ b/docs/zh-CN/spec/03-runtime/06-host-rpc-protocol.md
@@@ -1183,3 -1183,3 +1183,29 @@@ timeoutMs 为 0–1000 的整数,默�
终态和最终输出在同一作业锁下读取。读操作不消耗输出,进行中的观察持有作业句柄直至有界请求结束,历史淘汰不会拆散这次读取。等待后重新校验会话。放弃请求不会停止进程。旧 Host 能力缺失会明确报告,其他错误不会转为空列表。桌面原 RPC 结构保持兼容。
监管任务优先处理已观察到的进程退出,并在排空管道时保留退出结果。终态和最终输出发布时固定运行耗时。
++
++
++## User-defined mode run RPC
++
++ADR `mode-definitions` adds the following Host methods. Parameters use camelCase.
++
++| Method | Parameters | Result |
++| --- | --- | --- |
++| `modes.get` | `sessionId` | `{ run }`, null when no open run exists |
++| `modes.start` | `sessionId, input, turnId` | `{ claimed, run, enteredStage, definition }` |
++| `modes.claimTurn` | `sessionId, runId, expectedRevision, turnId, origin` | claim result; origins: user, approval, host |
++| `modes.completeStage` | `sessionId, runId, turnId, summary, artifacts?` | failed, run, awaiting_approval, advanced, goto, blocked or finished outcome |
++| `modes.gateResult` | `sessionId, runId, turnId, gateIndex, toolCallId` | next stage outcome |
++| `modes.settleTurn` | `sessionId, runId, turnId, tokens, outcome, error?` | `{ run, continue }` |
++| `modes.control` | `sessionId, runId, expectedRevision, action` | `{ run, continue }`; pause, resume or stop |
++| `modes.resolve` | `sessionId, runId, expectedRevision, action` | `{ run, continue }`; approve or reject |
++
++`session.configure` accepts an optional validated `modeSnapshot`. Custom mode
++ids require a snapshot. Agent and Plan retain their builtin policies. Host
++notifications use `modes.changed { sessionId, run }`. Renderer catalog editing
++uses the `pi-desktop/modes/*` IPC channels and never writes SQLite directly.
++
++`tools.execute` accepts `modeGate { runId, gateIndex }` only for the exact
++pending Bash gate command. The Host records the exit code; a model-supplied
++verdict cannot pass a command gate. Stage completion may write only declared
++artifacts within the workspace. Staged runs reject remote workspaces.
diff --cc docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
index 918e091b6,fce9e9c3a..ec77bb1aa
--- a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
@@@ -10420,3 -10427,3 +10427,43 @@@ MCP All 在创建、导入、安装时�
#### E2E-ISSUE-2164
压缩估算作为占用时使用检查点模型容量,旧检查点使用当前会话完整绑定;历史请求用量不变,未知容量标记估算。验证 20,619 / 1,000,000 为 2%、未知路由、旧记录及新请求恢复。
++
++
++## User-defined mode workflow acceptance
++
++Candidate command: `PI_DESKTOP_HOST_BIN=<candidate-host> node scripts/e2e-mode-definitions.mjs`
++with `PI_SCRATCH_DIR` set to an isolated test directory. No model API is called.
++
++1. Configure a session with a two-stage definition snapshot. Start a durable
++ turn and claim the first contract stage.
++2. Request completion without its required artifact; observe a failed gate.
++3. Supply the artifact through stage completion; verify its exact disk content
++ and the waiting-for-approval state.
++4. Settle the first turn, approve with the current revision and claim the next
++ stage with approval provenance.
++5. Submit the stage's command gate. A changed command must fail with
++ `MODE_GATE_MISMATCH` before execution.
++6. Execute the exact command through `tools.execute`; consume the Host-recorded
++ result and observe finished, no open run, and session mode Agent.
++
++Companion tests: `mode_runs::*` and `rpc::modes_rpc::tests::*` cover migration,
++recovery, CAS, budget and permission caps; desktop `mode-definitions-user-path`,
++`mode-definitions-renderer` and `mode-runs-main` cover source editing, selection,
++run controls and Main dispatch. Runtime `modes/*` covers stage completion and
++compaction injection.
++#### E2E-ISSUE-2173: Redundant delegation job selectors
++
++- Entry: build shared/agent-runtime/host-runtime and Host, then run
++ `PI_DESKTOP_HOST_BIN=<candidate-host> node scripts/e2e-task-job-selectors.mjs`.
++- Preconditions: isolated Host data/workspace and a deterministic localhost
++ provider; production parent and delegate loops, with no external model account.
++- Steps: start a delegate; wait with both its job reference and matching
++ delegationIds; re-read with empty delegationIds and single-job mode/minCompleted;
++ start another delegate, hold its provider response, stop it with both selectors,
++ and confirm its stopped state through TaskWait.
++- Expected: reports remain readable, redundant selectors do not cause errors,
++ single-job mode/minCompleted are ignored, and cancellation settles the target.
++ Unit tests also reject conflicting/malformed IDs and mixed Bash selectors.
++- Specs: `03-runtime/02-agent-runtime.md`, Session job controls.
++- Acceptance: wait, report re-read and running-delegate cancellation complete
++ through the real tool loop. Milestone: maintenance. Status: automated.