Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
Merge upstream/main into feat/fast-mode-1657
zszz30465dc509a68
diff --cc crates/host-core/src/db.rsindex 7511d4ae7,0ec286825..26eb28cfb--- a/crates/host-core/src/db.rs+++ b/crates/host-core/src/db.rs@@@ -7,7 -7,7 +7,7 @@@ pub(crate) use serde_json::Valuepub(crate) use std::path::{Path, PathBuf};/// Current SQLite schema version.--pub const SCHEMA_VERSION: i64 = 25;++pub const SCHEMA_VERSION: i64 = 26;/// Absolute approval deadline for a newly submitted Plan or Goal proposal.pub const PLAN_APPROVAL_TIMEOUT_MS: i64 = 30 * 60 * 1000;@@@ -44,7 -44,6 +45,7 @@@ pub(crate) use repositories::OBSOLETE_PLAN_APPROVAL_PERMISSION_MODE,};pub(crate) use schema::{PLAN_APPROVALS_SCHEMA, SCHEMA_LATEST, SESSION_TODO_DDL};- pub(crate) use session_fast_mode_migration::migrate_v24_to_v25;++pub(crate) use session_fast_mode_migration::migrate_v25_to_v26;pub(crate) use session_title_source_migration::migrate_v22_to_v23;pub(crate) use worktree_migration::{migrate_v23_to_v24, WORKTREE_DDL};diff --cc crates/host-core/src/db/repositories.rsindex 2f5ee3a0f,178e1cb55..1354344aa--- a/crates/host-core/src/db/repositories.rs+++ b/crates/host-core/src/db/repositories.rs@@@ -208,8 -208,8 +208,11 @@@ impl Databasemigrate_v23_to_v24(&conn, path)?;}24 => {- migrate_v24_to_v25(&conn, path)?;+ super::model_discovery_migration::migrate(&conn, path)?;+ }++ 25 => {++ migrate_v25_to_v26(&conn, path)?;+ }legacy @ 1..=6 => {let _ = conn.execute_batch("PRAGMA wal_checkpoint(TRUNCATE);");drop(conn);@@@ -263,7 -263,7 +266,11 @@@migrated_version = conn.query_row("PRAGMA user_version", [], |row| row.get(0))?;}if migrated_version == 24 {- migrate_v24_to_v25(&conn, path)?;+ super::model_discovery_migration::migrate(&conn, path)?;++ migrated_version = conn.query_row("PRAGMA user_version", [], |row| row.get(0))?;++ }++ if migrated_version == 25 {++ migrate_v25_to_v26(&conn, path)?;}let db = Self { conn, data_dir };db.boot_maintenance()?;diff --cc crates/host-core/src/db/session_fast_mode_migration.rsindex 5e942819a,000000000..4a22f3ed9mode 100644,000000..100644--- a/crates/host-core/src/db/session_fast_mode_migration.rs+++ b/crates/host-core/src/db/session_fast_mode_migration.rs@@@ -1,33 -1,0 +1,33 @@@+use super::{create_migration_backup, Connection, Context, Path, Result};+use rusqlite::Transaction;+- /// v25 stores the per-session `/fast` switch (ADR 0334). Every existing++/// v26 stores the per-session `/fast` switch (ADR 0334). Every existing+/// session keeps the default service tier.- fn migrate_v24_to_v25_tx(tx: &Transaction<'_>) -> Result<()> {++fn migrate_v25_to_v26_tx(tx: &Transaction<'_>) -> Result<()> {+ let has_fast_mode: bool = tx.query_row(+ "SELECT EXISTS(SELECT 1 FROM pragma_table_info('sessions') WHERE name = 'fast_mode')",+ [],+ |row| row.get(0),+ )?;+ if !has_fast_mode {+ tx.execute_batch(+ "ALTER TABLE sessions ADD COLUMN fast_mode INTEGER NOT NULL DEFAULT 0+ CHECK (fast_mode IN (0, 1));",+ )?;+ }- tx.pragma_update(None, "user_version", 25i64)?;++ tx.pragma_update(None, "user_version", 26i64)?;+ Ok(())+}+- pub(crate) fn migrate_v24_to_v25(conn: &Connection, path: &Path) -> Result<()> {- let backup = create_migration_backup(conn, path, 24)?;++pub(crate) fn migrate_v25_to_v26(conn: &Connection, path: &Path) -> Result<()> {++ let backup = create_migration_backup(conn, path, 25)?;+ let tx = conn.unchecked_transaction()?;- migrate_v24_to_v25_tx(&tx)?;++ migrate_v25_to_v26_tx(&tx)?;+ tx.commit().with_context(|| {+ format!(- "commit schema v24 to v25 migration; backup {} remains",++ "commit schema v25 to v26 migration; backup {} remains",+ backup.display()+ )+ })?;+ Ok(())+}diff --cc crates/host-core/src/db/tests.rsindex 66608e39f,205fd8597..b35c6dd52--- a/crates/host-core/src/db/tests.rs+++ b/crates/host-core/src/db/tests.rs@@@ -427,47 -427,10 +427,47 @@@ fn worktree_registry_enforces_one_row_p);}- /// v21 owns the session checklist. A real v20 database has neither the- /// `sessions` stamps nor the `session_todo` table, so the upgrade must add- /// both, keep the v20 rows, leave a readable pre-migration backup, and stay- /// idempotent when a fixture downgrades the same file in place.- /// v25 adds the per-session `/fast` column (ADR 0334). Existing sessions keep++/// v26 adds the per-session `/fast` column (ADR 0334). Existing sessions keep+/// their configuration, default to the normal tier, and a backup remains.+#[test]- fn v24_database_gains_session_fast_mode_defaulting_off() {++fn v25_database_gains_session_fast_mode_defaulting_off() {+ let dir = tempfile::tempdir().unwrap();+ let path = dir.path().join("pi.sqlite");+ let session_id = {+ let db = Database::open(&path).unwrap();+ let session = crate::sessions::create_session_with_thinking(+ &db,+ Some("Kept".into()),+ None,+ None,+ None,+ None,+ Some("high".into()),+ )+ .unwrap();+ db.conn()+ .execute_batch("ALTER TABLE sessions DROP COLUMN fast_mode;")+ .unwrap();- db.conn().pragma_update(None, "user_version", 24).unwrap();++ db.conn().pragma_update(None, "user_version", 25).unwrap();+ session.id+ };++ let db = Database::open(&path).unwrap();+ assert_eq!(schema_version(db.conn()), SCHEMA_VERSION);- assert!(migration_backup_path(&path, 24).exists());++ assert!(migration_backup_path(&path, 25).exists());+ let summary = crate::sessions::get_session(&db, &session_id)+ .unwrap()+ .unwrap()+ .summary;+ assert_eq!(summary.title, "Kept");+ assert_eq!(summary.thinking_level, "high");+ assert!(!summary.fast_mode);+}++ /// v21 owns the session checklist. A real v20 database has neither the+ /// `sessions` stamps nor the `session_todo` table, so the upgrade must add+ /// both, keep the v20 rows, leave a readable pre-migration backup, and stay+ /// idempotent when a fixture downgrades the same file in place.#[test]fn v20_database_migrates_the_session_checklist_with_a_backup() {let dir = tempfile::tempdir().unwrap();diff --cc crates/host-core/src/plugins/providers/tests.rsindex 433aa876c,6278a8e98..5f1b269c5--- a/crates/host-core/src/plugins/providers/tests.rs+++ b/crates/host-core/src/plugins/providers/tests.rs@@@ -99,10 -99,10 +99,11 @@@ fn a_new_database_carries_the_owner_collet (_dir, db, _secrets) = test_context();// v17 added the owner column, v18 the turn-queue priority column,// v19 session omit, v21 the session Todo checklist, and v22 the- // session-list index, v23 the session title source, and v24 the worktree- // registry; v25 adds model discovery state. A fresh database is stamped with the newest version, so the+ // session-list index, v23 the session title source, v24 the worktree- // registry, and v25 the session Fast mode switch. A fresh database is- // stamped with the newest version, so the column set is the current one.- assert_eq!(SCHEMA_VERSION, 25);++ // registry, v25 model discovery state, and v26 the session Fast mode++ // switch. A fresh database is stamped with the newest version, so the+ // column set is the current one.- assert_eq!(SCHEMA_VERSION, 25);++ assert_eq!(SCHEMA_VERSION, 26);let version: i64 = db.conn().query_row("PRAGMA user_version", [], |row| row.get(0))diff --cc crates/host-core/src/turn_queue.rsindex 6ca93814e,6ca93814e..d64b6e53b--- a/crates/host-core/src/turn_queue.rs+++ b/crates/host-core/src/turn_queue.rs@@@ -532,7 -532,7 +532,7 @@@ mod testsassert_eq!(entries[0].content, "existing");assert!(entries[0].user_message_id.is_none());assert!(entries[0].voice_origin.is_none());-- assert_eq!(crate::db::SCHEMA_VERSION, 25);++ assert_eq!(crate::db::SCHEMA_VERSION, 26);}#[test]diff --cc docs/adr/0334-openai-fast-mode.mdindex f9a177d2a,000000000..c396fa070mode 100644,000000..100644--- a/docs/adr/0334-openai-fast-mode.md+++ b/docs/adr/0334-openai-fast-mode.md@@@ -1,72 -1,0 +1,72 @@@+# ADR 0334: OpenAI Fast mode as a per-session switch gated by model settings++- Status: Accepted+- Date: 2026-10-17+- Deciders: PI-Desktop maintainers+- Related: [ADR 0329](0329-session-worktree-isolation.md) ·+ [03-runtime/11-provider-model-system](../spec/03-runtime/11-provider-model-system.md) ·+ [04-ux/04-builtin-commands](../spec/04-ux/04-builtin-commands.md) ·+ issue #1657 · E2E-FAST-MODE++## Context++OpenAI serves a faster priority tier that Codex CLI and the OpenAI API call+Fast mode. On the wire it is the Responses body field `service_tier:+"priority"`; the Codex backend rejects `"fast"`. The tier costs more: a ChatGPT+subscription spends its plan limits faster, and the OpenAI API bills a higher+per-token price. PI-Desktop never asked for a tier. pi-ai's Responses and+Codex adapters already accept `serviceTier` and price the tier the response+reports, but `streamSimple` dropped the option while building its base options.++The cost is a decision about one conversation, while whether an endpoint+honors the field is something only the user knows for a relay. Issue #1657 asks+for the subscription speed-up; maintainers asked that capability be configured+in model settings.++## Decision++1. **Model settings own capability.** `ModelBinding.fastModeAllowed` is an+ opt-in, stored in the existing provider `config_json` like+ `nativeWebSearch`, so it needs no migration. The checkbox is enabled only+ for Responses wires (`openai_codex_responses`, `responses`), including+ relays; its hint names the cost on that wire.+2. **`/fast` owns the session switch.** A new builtin `builtin.session.fast`- (`/fast`) toggles a persisted `sessions.fast_mode` column (schema v25,- additive, v24 backup). `session.create` and `session.configure` accept an++ (`/fast`) toggles a persisted `sessions.fast_mode` column (schema v26,++ additive, v25 backup). `session.create` and `session.configure` accept an+ optional boolean `fastMode`; omission keeps the stored value. Forks copy it;+ scheduled runs and delegated workers start off. A draft carries it into the+ session its first prompt creates. Remote sessions refuse it.+3. **`/fast` only works on a configured model.** When the selected model's+ wire cannot carry the tier or the model is not allowed, `/fast` stores+ nothing and points to Settings → Models → Advanced, in either direction. A+ stale stored switch on such a model is inert because launch also requires+ the opt-in.+4. **The launcher resolves; the runtime only stamps the wire.** Session launch+ sends `fastMode: true` to the sidecar only when the session switch is on and+ the user's stored binding allows it. The runtime passes pi-ai's native+ `serviceTier: "priority"` on main turns whose resolved wire is+ `openai-codex-responses` or `openai-responses`; the existing pi-ai patch+ forwards `serviceTier` through `streamSimple`, so the adapters also apply+ their own tier pricing. Subagents, compaction, and one-shot plugin requests+ build their own options and keep the default tier.++## Alternatives++- **Per-model switch only (no session state).** Avoids a migration, but turns+ a per-conversation cost into a global one: enabling Fast for one task speeds+ up and costs every conversation on that model.+- **Hard-coded capability rule (official OpenAI host only).** Removes a+ setting, but excludes relays the user knows support the field and hides the+ decision in code.+- **Generic request-parameter injection with presets.** More flexible, but an+ arbitrary body-field channel needs its own validation and permission story,+ which is larger than this need.++## Consequences+- - Schema v25 adds one column; older apps opening a v25 database refuse it as++- Schema v26 adds one column; older apps opening a v26 database refuse it as+ newer, the existing downgrade behavior.+- The capability can be wrong for a relay that ignores or rebills the field;+ the settings hint states that risk, and the user owns the opt-in.+- The Composer model chip shows a Fast mark while the switch is on for an+ allowed model, so the cost is visible at send time.diff --cc docs/spec/03-runtime/04-data-storage.mdindex dae3d391c,8bc6deda6..6473056ef--- a/docs/spec/03-runtime/04-data-storage.md+++ b/docs/spec/03-runtime/04-data-storage.md@@@ -1,4 -1,4 +1,4 @@@--# 04. Data Storage (Schema v25)++# 04. Data Storage (Schema v26)## 0. Ownership decision@@@ -1573,7 -1580,7 +1582,7 @@@ truncating at a guessed position- JSON columns are read blind on hot paths (shipped to the renderer as-is);anything filtered or summed is a promoted column by rule.- ## 7. Versioning, v7 reset, and v8-to-v25 migration-## 7. Versioning, v7 reset, and v8-to-v23 migration++## 7. Versioning, v7 reset, and v8-to-v26 migration- `PRAGMA user_version` stays the schema authority; future structural changesadd ordered Rust migration fns again, each in one transaction, with a@@@ -1584,7 -1591,7 +1593,7 @@@Sessions, providers, and settings from the old file are not carried over;the archive remains for manual recovery. All pre-v7 migration code(v1 `settings.sqlite` import, v2→v6 chain) is deleted.--- Fresh installs run the full v25 DDL directly.++- Fresh installs run the full v26 DDL directly.- **Schema v7 first reaches v8, then uses the guarded path.** The v7→v8migration is followed by the same guarded v8→v15 migration; schema-v9 andschema-v10 databases take the same guarded path and receive an exact readable@@@ -1648,13 -1655,6 +1657,15 @@@- **Schema v23 is additive.** It adds `sessions.title_source` with default`legacy`. Pre-existing v22 titles remain `legacy`, safely protecting deliberaterenames from automatic replacement. The migration keeps a v22 backup.+- **Schema v24 is additive.** It adds the `worktrees` registry and+ `projects.worktree_setup_command` for isolated sessions (ADR 0329). The+ migration keeps a v23 backup.- - **Schema v25 is additive.** It adds `sessions.fast_mode` (ADR 0334), the++- **Schema v25 is additive.** It adds nullable `models.discovery_state` (§ 4).++ The migration keeps a v24 backup.++- **Schema v26 is additive.** It adds `sessions.fast_mode` (ADR 0334), the+ session `/fast` switch, defaulting to `0` for every existing session. Forks+ copy it; scheduled runs and delegated workers start at `0`. The migration- keeps a v24 backup.++ keeps a v25 backup.- **Schema v14 is additive.** It adds nullable `sessions.deleted_at`, thepartial deletion index, and `session_import_origins`. Existing sessions stayactive and have no origin rows. The migration runs in the same guardeddiff --cc docs/spec/06-delivery/04-e2e-test-plan.mdindex 4eaa14ccc,0b6ed5423..4b279209d--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@@ -18636,37 -18723,6 +18723,37 @@@ host-created files. The full app's file`apps/desktop/test/main-wiring-contract.test.mjs`; the interactive Electronscenario remains a manual validation run.+### E2E-FAST-MODE: `/fast` asks for the priority tier only on an allowed model++- **Preconditions**: A ChatGPT subscription (Codex) account and a Responses+ API-key provider, each with two configured models. No real provider is+ required for the automated path; the manual path uses a capturing local+ endpoint or the user's authorized account.+- **Steps**:+ 1. In Settings → Models, check **Fast mode** on one model of each provider.+ Confirm the checkbox is disabled on a Chat Completions provider.+ 2. Start a new task on the allowed Codex model, type `/fast`, send a prompt.+ 3. Send `/fast` again, then send another prompt.+ 4. Switch the session to the model without the opt-in and send `/fast`.+ 5. Fork the session while Fast is on; restart the app and reopen both.+- **Expected**: Step 1 persists `fastModeAllowed` on the binding only. Step 2+ shows the Fast mark on the model chip and the request body carries+ `service_tier: "priority"`; a Responses API-key model shows the per-token+ price toast instead. Step 3 clears the mark and the field. Step 4 refuses+ with the model-settings hint and stores nothing. Step 5 keeps the switch on+ the fork and across restart. Subagent and compaction requests never carry+ the field. Remote sessions refuse `/fast`.+- **Specs linked**: `03-runtime/11-provider-model-system.md`,- `03-runtime/04-data-storage.md` (v25), `04-ux/04-builtin-commands.md`,++ `03-runtime/04-data-storage.md` (v26), `04-ux/04-builtin-commands.md`,+ ADR 0334, issue #1657.+- **Status**: Automated coverage: `apps/desktop/test/fast-mode-command.test.mjs`+ (draft → created session, toggle, refusals, remote, chip),+ `apps/desktop/test/fast-mode-session-launch.test.mjs` (launch resolution),+ `packages/agent-runtime/src/fast-mode.test.ts` (request body through the real+ pi-ai Responses and Completions adapters), host-core migration, RPC and fork+ tests. The full settings → `/fast` → captured request path is a manual+ validation scenario.+### E2E-PROVIDER-optional-client-certificate- **Preconditions:** The locked Electron 43 runtime, built workspace packages,diff --cc docs/zh-CN/spec/03-runtime/04-data-storage.mdindex f9c188209,3ec3db405..b747bd035--- a/docs/zh-CN/spec/03-runtime/04-data-storage.md+++ b/docs/zh-CN/spec/03-runtime/04-data-storage.md@@@ -1,4 -1,4 +1,4 @@@- # 04. 数据存储(架构 v25)-# 04. 数据存储(架构 v23)++# 04. 数据存储(架构 v26)> **翻译说明:** 本页是与 [英文源规格](/spec/03-runtime/04-data-storage) 一一对应的机器辅助翻译。代码、协议字段和标识符保持原文;如翻译与英文源事实有歧义,以英文版本为准。@@@ -1168,7 -1166,7 +1168,7 @@@ outbox 排空。渲染器侧的停止�- JSON 列在热路径上盲读(按原样发送到渲染器);任何过滤或求和的内容都是按规则提升的列。- ## 7. 版本控制、v7 重置和 v8 到 v25 迁移-## 7. 版本控制、v7 重置和 v8 到 v23 迁移++## 7. 版本控制、v7 重置和 v8 到 v26 迁移- `PRAGMA user_version` 保留模式权限;未来的结构性变化再次添加有序的 Rust 迁移 fns,每个都在一个事务中,并带有一个@@@ -1179,7 -1177,7 +1179,7 @@@旧文件中的会话、提供程序和设置不会保留;存档仍保留以供手动恢复。所有 v7 之前的迁移代码(v1 `settings.sqlite` 导入,v2→v6 链)被删除。- - 全新安装直接运行完整的 v25 DDL。-- 全新安装直接运行完整的 v23 DDL。++- 全新安装直接运行完整的 v26 DDL。- **架构 v15 是增量的。** 它增加 `turn_queue` 表及其两个索引(D386 / ADR 0213),使 Host拥有的回合队列在重启后存活;不改动任何已有行,迁移前保留 `pi.sqlite.v14.bak`。- **架构 v16 是增量的。** 它增加会话协作 link 和投递表、生命周期索引,以及可为空的@@@ -1192,11 -1190,6 +1192,12 @@@v22 标题保留为 `legacy`,防止主动重命名被自动覆盖。迁移前保留 v22 备份。v15→v16 会话协作步骤现在写入 `16`(它自己的版本)而不是最新的架构常量,因此 v15 文件可以在一次启动中走完两个步骤。+- **架构 v24 是增量的。** 它为隔离会话增加 `worktrees` 登记表和+ `projects.worktree_setup_command`(ADR 0329)。迁移前保留 v23 备份。- - **架构 v25 是增量的。** 它增加 `sessions.fast_mode`(ADR 0334),即会话的 `/fast`++- **架构 v25 是增量的。** 它增加可空的 `models.discovery_state`。迁移前保留 v24 备份。++- **架构 v26 是增量的。** 它增加 `sessions.fast_mode`(ADR 0334),即会话的 `/fast`+ 开关,所有已有会话默认为 `0`。fork 会复制该值;定时任务运行和委托子会话从 `0` 开始。- 迁移前保留 v24 备份。++ 迁移前保留 v25 备份。- **架构 v7 首先到达 v8,然后使用受保护的路径。** v7→v8迁移之后是相同的受保护的 v8→v15 迁移;架构-v9 和schema-v10 数据库采用相同的受保护路径并接收精确的可读数据diff --cc docs/zh-CN/spec/06-delivery/04-e2e-test-plan.mdindex 81dd8fc4f,0d853866b..8de977442--- a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md@@@ -9942,24 -9942,6 +9942,24 @@@ host-created files. The full app's file- **验收**:项目折叠时仍能回答“这里是否有正在运行的工作”,且两种提示可从持久化设置独立控制。- **状态**:草稿。现有 `apps/desktop/test/sidebar-project-runs.test.mjs` 覆盖数量分类、总开关与子开关门控、两种渲染入口,以及主题令牌和减少动态效果保证;它不覆盖设置 API 缺省值规范化或完整交互,相关场景仍需在可用环境手动验证。+### E2E-FAST-MODE:`/fast` 只在允许的模型上请求优先档位++- **前置条件**:一个 ChatGPT 订阅(Codex)账号和一个 Responses API key 提供商,各配置两个模型。+ 自动化路径不需要真实提供商;手动路径使用可捕获请求的本地端点或用户授权的账号。+- **步骤**:+ 1. 在「设置 → 模型」中为每个提供商的一个模型勾选 **Fast 模式**;确认 Chat Completions 提供商上该勾选框不可用。+ 2. 在允许的 Codex 模型上新建任务,输入 `/fast`,发送一条提示。+ 3. 再次发送 `/fast`,然后再发送一条提示。+ 4. 把会话切换到未允许的模型,发送 `/fast`。+ 5. 在 Fast 开启时 fork 会话;重启应用后重新打开两个会话。+- **预期**:第 1 步只在 binding 上保存 `fastModeAllowed`。第 2 步模型芯片显示 Fast 标识,请求体带有+ `service_tier: "priority"`;Responses API key 模型改为提示按 token 计费的价格。第 3 步清除标识和该字段。+ 第 4 步给出模型设置提示并拒绝,不保存任何状态。第 5 步 fork 和重启后开关保持开启。子代理和压缩请求+ 从不携带该字段。远程会话拒绝 `/fast`。- - **关联规格**:`03-runtime/11-provider-model-system.md`、`03-runtime/04-data-storage.md`(v25)、++- **关联规格**:`03-runtime/11-provider-model-system.md`、`03-runtime/04-data-storage.md`(v26)、+ `04-ux/04-builtin-commands.md`、ADR 0334、issue #1657。+- **状态**:自动化覆盖见英文版。完整的设置 → `/fast` → 捕获请求路径为手动验证场景。+#### E2E-PROVIDER-reasoning-effort-override: Preserve an explicit gateway reasoning parameter- **Setup:** A custom Chat Completions provider with a DeepSeek-family model;