Skip to content

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

fix(agent-runtime): integrate lifecycle bounds with current main

hui455fcc82aac6858
diff --cc docs/spec/06-delivery/04-e2e-test-plan.md
index 633af017f,9af2c591e..5382665db
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@@ -14340,56 -14234,21 +14340,75 @@@ the latest destination. These assertion
- **Coverage**: `chat-links.test.mjs`; native desktop click-through with the normal browser destination.
- **Specs linked**: `04-ux/08-component-spec.md` §8.3.
+#### E2E-IME-escape: Composition cancellation preserves drafts
+
+- **Steps**: Edit a user message; type a draft; dispatch composing Escape and Cmd/Ctrl+Enter. Open global search and dispatch composing Escape from its input. Repeat with legacy keyCode 229, then ordinary Escape and retry shortcuts.
+- **Expected**: Composition events neither discard the edit nor close search nor submit a retry. Ordinary Escape still cancels/closes, including search focus outside its input; ordinary Cmd/Ctrl+Enter still retries.
+- **Coverage**: `node scripts/e2e-ime-escape.mjs` exercises production components with bubbling DOM keyboard events and host-boundary fixtures. This does not verify an operating system IME candidate window.
+
+### E2E-SCHEDULED-manual-to-hourly
+
+- **Preconditions:** Built host candidate, isolated data directory, no provider.
+- **Steps:** Through `tools.execute`, create a paused Manual task, update only
+ its id and cadence to Hourly, rename it, restart, and list tasks again.
+- **Expected:** Update succeeds without calendar fields; the next occurrence is
+ one hour away. Prompt, paused state and saved configuration survive. Rename
+ does not reset the interval. RPC tests also cover required Daily/Weekly times
+ and retention of an existing custom schedule.
+- **Specs:** 04-ux/01-ui-ia §3.4.
+- **Acceptance:** C / F — task configuration and persistence.
+- **Milestone:** Maintenance.
+- **Status:** `node scripts/e2e-scheduled-hourly-update.mjs` exercises the real
+ Rust host, permission path, stdio and SQLite; no model inference or desktop UI.
+
+### E2E-SCHEDULED-manual-workspace-binding
+
+- **Preconditions:** Built request candidate; isolated host data and two project
+ directories. No provider credentials or paid API.
+- **Steps:** Create Manual and Hourly tasks in project A and without a project;
+ restart the host, switch to B, Run now, rename through the editor payload,
+ and Run now again.
+- **Expected:** Each result session and edited task retain the original binding,
+ including no-project tasks. Legacy cadence-only tasks keep their previous
+ fallback until explicitly configured (covered by host RPC tests).
+- **Specs:** 04-ux/01-ui-ia §3.4.
+- **Acceptance:** Saved workspace binding across run, edit and restart.
+- **Milestone:** Maintenance.
+- **Status:** Automated by `node --experimental-strip-types
+ scripts/e2e-scheduled-workspace.mjs`, using production Electron dispatch and
+ real Rust/stdio/SQLite. Only external inference is replaced with an observer.
+
+### E2E-SESSION-temporary-attachment-fork: Preview and independent branch inputs
+
+- **Steps**: In a task without a project, paste text above the long-paste
+ threshold, send it, and click its transcript attachment. Return from the
+ preview, create a branch, and open the same attachment in the child. Delete
+ the source task and reopen the child attachment; branch the child again.
+- **Expected**: Every preview shows the original saved bytes. Each branch path
+ belongs to that branch's scratch input directory. No project is required, and
+ no access to another task's scratch directory is granted. A bounded fork
+ excludes later-only and unreferenced inputs.
+- **Automation**: `scripts/e2e-composer-paste.mjs` covers long-text save, real
+ Electron file read, temporary-task preview, and back navigation. Host tests
+ `fork_preserves_referenced_pasted_files_independently` and `sessions::fork_files`
+ cover ownership, deletion, repeated/bounded forks, retained checkpoint paths,
+ expired inputs, rollback, and symlink rejection.
++
+ ### E2E-HOOKS-cancel-and-dispose
+
+ - **Preconditions:** An isolated Desktop profile, deterministic local provider,
+ and a trusted plugin with a waiting preflight handler.
+ - **Steps:** Start a prompt; stop while the handler waits; release the old
+ handler; send another prompt. Repeat with runtime disposal. Load another
+ fixture with stalled startup/shutdown handlers and a deferred event.
+ - **Expected:** No provider request starts for the stopped/disposed prompt;
+ the next prompt completes. Late results cannot restart work. Shutdown runs
+ once, waits time out per handler, and deferred registrations are diagnosed
+ without disabling supported handlers.
+ - **Specs:** 07-plugins/16 §6.
+ - **Acceptance:** Responsive cancellation and bounded extension lifecycle waits.
+ - **Milestone:** Hooks P0.
+ - **Status:** Runner and real Runtime/local-HTTP integration automated in
+ `extensions/runner.test.ts` and `extensions/runtime-lifecycle.test.ts`.
+ Electron wiring is covered by the existing trusted-extension E2E suite;
+ this stop/dispose scenario is not yet driven through the renderer.
diff --cc docs/spec/08-meta/decisions-log.md
index f8a3ef64c,90b63fd86..b5c514218
--- a/docs/spec/08-meta/decisions-log.md
+++ b/docs/spec/08-meta/decisions-log.md
@@@ -6531,28 -6531,16 +6531,42 @@@ that was sitting at the bottom — incl
`plugin.stdio` audit stream is otherwise unchanged.
- See `07-plugins/05-plugin-lifecycle.md` §3.1.
+## 2026-09-20 — The Create project name defaults to the primary folder (D609)
+
+- The Create project dialog required a typed name before Create became
+ available, so a local folder pick could not be confirmed without inventing a
+ title; the git source already seeded the field from the repository name
+ (D438, ADR 0273).
+- The name field is now optional for both sources. It seeds from the picked
+ source — the first selected folder's name for a local pick, the repository
+ name for a git checkout — and stops following the source as soon as the user
+ types their own name. Create is gated by the source alone (one folder, or a
+ parsed URL plus a destination), and a field left empty falls back to the same
+ derived name.
+- Derived names are cut to `MAX_PROJECT_NAME_CHARS` (80) so the persisted
+ sidebar preference and the name field accept them unchanged. Folder-name
+ parsing moves to `apps/desktop/src/lib/project-name.ts` and is shared with the
+ dialog's folder rows.
+- Renderer only: no protocol, storage, host, permission, or migration change,
+ and no new default. See `04-ux/08-component-spec.md`, ADR 0233, ADR 0273, and
+ E2E-012a / E2E-256.
+## 2026-09-21 — A stored model binding array is read entry by entry (D610, issue #784)
+
+- `config_json.models` is the only place a provider's model list lives, and it has more than one writer: a settings save, a plugin declaration, and an external edit of the stored row. It was decoded as a single `Vec<ModelBinding>`, so one entry that no longer matched the schema discarded every sibling — after which the provider read back as the single legacy default model derived from `defaultModelId`, every other configured model gone, and nothing said about why. The report reproduced it by deleting one binding's `maxTokens`: 12 stored bindings read back as 1.
+- `contextWindow` and `maxTokens` are therefore optional on the wire, and each entry of the array is decoded on its own. An absent key, or an explicit `0`, reads as zero and is seeded with the generic default (128,000 / 8,192) by the normalisation that already existed for the explicit zero — the same value a record carrying only `defaultModelId` is materialized with, and the same value a plugin manifest that declares no limits already produces. The two paths now agree instead of one rejecting what the other accepts.
+- An entry that still fails to decode costs itself, not the array: the readable entries survive in their stored order, and the failure is reported on the host log with the provider id, the entry's index and the reason, so it is locatable rather than silent. An absent `models` key, an empty array, and an array whose every entry was unreadable all still read as the legacy binding, so a provider stays selectable whatever its stored shape; only the third is reported, because an empty array is a legal state and an absent one predates bindings.
+- Nothing is rewritten on disk and the write path remains explicit: `providers.update` still persists exactly the bindings the client sends. Before accepting an explicit model-array replacement, the host checks the stored value and rejects it with `MODEL_BINDINGS_DEGRADED` when the value is degraded, so a partial settings view cannot erase unreadable entries; unrelated provider fields remain updatable. See `03-runtime/12-provider-config-schema.md` §2.
++
+ ## 2026-09-21 — Bound Desktop trusted-extension lifecycle waits
+
+ - Apply the existing 30-second handler budget to notification, startup and
+ shutdown handlers as well as result handlers; module loading and factory
+ initialization each use the same budget. This changes previously unbounded
+ waits, including event handlers waiting for a UI answer.
+ - Abort retires current waits; disposal rejects new dispatches and runs shutdown
+ once. Late settlements cannot supply results to the retired dispatch. Existing
+ fail-open error handling, result folding, plugin ownership and permissions
+ remain unchanged. In-process code is not forcibly terminated.
+ - Deferred events remain registrable and now appear in existing diagnostics.
+ See `07-plugins/16-trusted-extensions.md` §6 and
+ `E2E-HOOKS-cancel-and-dispose`.
diff --cc docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
index 75ac12b71,4c8d2699b..1ea91e79b
--- a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
@@@ -8480,73 -8406,16 +8480,87 @@@ the latest destination. These assertion
- **覆盖**:`chat-links.test.mjs`;桌面端通过正常浏览器目标实际点击验证。
- **链接规格**:`04-ux/08-component-spec.md` §8.3。
+#### E2E-IME-escape: 取消组词保留草稿
+
+- **步骤**:编辑用户消息并输入草稿,派发组词中的 Escape 和 Cmd/Ctrl+Enter;打开全局搜索,从输入框派发组词中的 Escape。对 legacy keyCode 229 重复检查,再验证普通 Escape 和重试快捷键。
+- **预期**:组词事件不会丢弃编辑、关闭搜索或重试发送;普通 Escape 仍取消或关闭(包括搜索输入框之外的焦点),普通 Cmd/Ctrl+Enter 仍重试。
+- **覆盖**:`node scripts/e2e-ime-escape.mjs` 使用真实组件、冒泡 DOM 键盘事件及宿主边界测试数据;不代表已验证操作系统输入法候选窗口。
+
+### E2E-SCHEDULED-manual-to-hourly
+
+- **Preconditions:** Built host candidate, isolated data directory, no provider.
+- **Steps:** Through `tools.execute`, create a paused Manual task, update only
+ its id and cadence to Hourly, rename it, restart, and list tasks again.
+- **Expected:** Update succeeds without calendar fields; the next occurrence is
+ one hour away. Prompt, paused state and saved configuration survive. Rename
+ does not reset the interval. RPC tests also cover required Daily/Weekly times
+ and retention of an existing custom schedule.
+- **Specs:** 04-ux/01-ui-ia §3.4.
+- **Acceptance:** C / F — task configuration and persistence.
+- **Milestone:** Maintenance.
+- **Status:** `node scripts/e2e-scheduled-hourly-update.mjs` exercises the real
+ Rust host, permission path, stdio and SQLite; no model inference or desktop UI.
+
+### E2E-SCHEDULED-manual-workspace-binding
+
+- **Preconditions:** Built request candidate; isolated host data and two project
+ directories. No provider credentials or paid API.
+- **Steps:** Create Manual and Hourly tasks in project A and without a project;
+ restart the host, switch to B, Run now, rename through the editor payload,
+ and Run now again.
+- **Expected:** Each result session and edited task retain the original binding,
+ including no-project tasks. Legacy cadence-only tasks keep their previous
+ fallback until explicitly configured (covered by host RPC tests).
+- **Specs:** 04-ux/01-ui-ia §3.4.
+- **Acceptance:** Saved workspace binding across run, edit and restart.
+- **Milestone:** Maintenance.
+- **Status:** Automated by `node --experimental-strip-types
+ scripts/e2e-scheduled-workspace.mjs`, using production Electron dispatch and
+ real Rust/stdio/SQLite. Only external inference is replaced with an observer.
+
+#### E2E-PROVIDER-stored-binding-array-reads-entry-by-entry:存储的模型绑定数组逐条读取
+
+- **前置条件**:一次性数据目录与 host-core 可执行文件;通过 `providers.create`
+ 建立一个至少含三条完整绑定的提供商;不使用真实提供商或凭据。
+- **步骤**:调用 `providers.list`,确认全部绑定都返回。编辑存储的
+ `config_json`,删掉其中一个绑定的 `maxTokens`,再次 list。补回该字段后再
+ list。最后把某个绑定的 `contextWindow` 改成字符串,再 list 一次;用可读子集
+ 携带一个无关字段变更调用 `providers.update`。
+- **预期**:除损坏条目外,三条绑定都按存储顺序返回。丢失 `maxTokens` 的绑定以
+ 通用默认输出上限读出,补回字段后数值恢复。宿主日志为无法解码的条目带上提供商
+ id、条目下标与原因。显式模型数组更新返回 `MODEL_BINDINGS_DEGRADED`,而存储的
+ `config_json` 保持不变。
+- **链接规格**:`03-runtime/12-provider-config-schema.md` §2、
+ `08-meta/decisions-log.md` D610
+- **验收**:F(持久化)、品质
+- **状态**:单元覆盖(`providers::catalog::tests`、
+ `providers::tests::a_stored_array_survives_an_entry_that_lost_a_field`);
+ 宿主 RPC 路径由 `scripts/e2e-smoke.mjs` 覆盖提供商的创建与列举,但没有套件
+ 驱动手工编辑的 `config_json`。
+
+### E2E-SESSION-temporary-attachment-fork:临时任务预览与独立分支附件
+
+- **步骤**:在没有项目的任务中粘贴超过长文本阈值的内容并发送,点击对话中的附件。
+ 返回后创建分支并打开同一附件;删除原任务,再打开分支附件,并继续创建分支。
+- **预期**:每次预览均显示原始文件内容;各分支引用自身的 scratch 输入目录,
+ 不需要打开项目,也不授予跨任务读取权限。按消息截断的分支不复制后续消息独有
+ 或未引用的输入文件。
+- **自动化**:`scripts/e2e-composer-paste.mjs` 覆盖长文本保存、真实 Electron
+ 文件读取、临时任务预览及返回。主机测试
+ `fork_preserves_referenced_pasted_files_independently` 和 `sessions::fork_files`
+ 覆盖附件归属、删除、重复与截断分支、保留的压缩检查点引用、过期输入、失败回滚
+ 及符号链接拒绝。
++
+ ### E2E-HOOKS-cancel-and-dispose
+
+ - **前置条件:** 隔离 Desktop 配置、本地确定性模型,以及含等待型请求前处理器的可信插件。
+ - **步骤:** 发送消息,在处理器等待时停止,释放旧处理器后再次发送。另测等待时销毁
+ Runtime,并加载启动/关闭挂起以及注册未接通事件的夹具。
+ - **预期:** 被停止或销毁的请求不调用模型,后续消息正常完成。迟到结果不能重启工作。
+ 关闭只执行一次,各处理器等待有界,未接通事件产生诊断但不禁用正常处理器。
+ - **规范:** 07-plugins/16 §6。
+ - **验收:** 取消及时生效,扩展生命周期等待有界。
+ - **里程碑:** Hooks P0。
+ - **状态:** Runner 与真实 Runtime/本地 HTTP 集成通过
+ `extensions/runner.test.ts`、`extensions/runtime-lifecycle.test.ts` 自动验证。
+ 现有可信扩展 E2E 覆盖 Electron 接线;本停止/销毁场景尚未由渲染层驱动。
diff --cc docs/zh-CN/spec/08-meta/decisions-log.md
index 8e23d82c5,1e9f84665..d925ea846
--- a/docs/zh-CN/spec/08-meta/decisions-log.md
+++ b/docs/zh-CN/spec/08-meta/decisions-log.md
@@@ -4630,22 -4630,11 +4630,31 @@@ that amendment are retired by ADR 0268
既有的 `plugin.stdio` 审计流保持不变。
- 见 `07-plugins/05-plugin-lifecycle.md` §3.1。
+## 2026-09-20 —— 新建项目的名称默认取主要文件夹(D609)
+
+- 新建项目对话框原本要求先填名称才能创建,本地选文件夹时不得不先编一个标题;
+ Git 来源此前已用仓库名预填该字段(D438、ADR 0273)。
+- 名称字段现在对两种来源都可选。它按所选来源预填——本地来源取第一个(主要)
+ 文件夹的名称,Git 来源取仓库名——用户一旦自己输入就不再跟随来源。创建按钮
+ 只由来源决定是否可用(一个文件夹,或解析成功的地址加保存位置),字段留空时
+ 回退为同一个默认名。
+- 派生名称会截断到 `MAX_PROJECT_NAME_CHARS`(80),以保证侧边栏偏好持久化和
+ 名称字段都能原样接受。文件夹名解析移到
+ `apps/desktop/src/lib/project-name.ts`,与对话框的文件夹行共用。
+- 仅渲染器改动:不改协议、存储、宿主、权限或迁移,也不新增默认值。见
+ `04-ux/08-component-spec.md`、ADR 0233、ADR 0273、E2E-012a / E2E-256。
+## 2026-09-21 —— 存储的模型绑定数组逐条读取(D610,issue #784)
+
+- `config_json.models` 是提供商模型列表唯一的存放处,而它不止一个写入方:设置保存、插件声明,以及对存储行的外部编辑。此前它被当作单个 `Vec<ModelBinding>` 解码,于是只要有条目不再符合 schema,全部兄弟条目都会被丢弃——之后该提供商读回来只剩由 `defaultModelId` 派生的那一个 legacy 默认模型,其它已配置模型全部消失,且没有任何说明。报告的复现正是删掉某一个绑定的 `maxTokens`:库里 12 条绑定,读回来 1 条。
+- 因此 `contextWindow` 与 `maxTokens` 在线为可选,并且数组逐条解码。缺失的键、或显式的 `0`,都读作 0 并由既有的零值归一化补上通用默认值(128,000 / 8,192)——这与只带 `defaultModelId` 的记录被物化时用的是同一个值,也与未声明限额的插件清单已经产生的值相同。两条路径从此一致,而不是一条拒绝另一条接受的东西。
+- 仍然解码失败的条目只损失自己,不损失整个数组:可读条目按存储顺序保留,失败会在宿主日志里上报,带上提供商 id、条目下标与原因,因此可定位而不是静默。缺失的 `models` 键、空数组、以及所有条目都不可读的数组,都仍旧读作 legacy 绑定,使提供商无论存储形态如何都保持可选;只有第三种会被上报,因为空数组是合法状态,而缺失键则是早于绑定机制的记录。
+- 不改写磁盘上的任何内容,写路径仍是显式的:`providers.update` 依旧只持久化客户端发来的绑定。接受显式模型数组替换前,host 会检查存储值;若已降级则以 `MODEL_BINDINGS_DEGRADED` 拒绝,避免设置页的部分视图擦除不可读条目;不涉及模型数组的提供商字段仍可更新。见 `03-runtime/12-provider-config-schema.md` §2。
++
+ ## 2026-09-21 — 限制 Desktop 可信扩展生命周期等待
+
+ - 现有 30 秒处理器预算扩展到通知、启动和关闭事件;模块加载、工厂初始化分别使用
+ 同一预算。此前无界的等待变为有界,事件内等待 UI 回答也受此限制。
+ - 中止使当前等待失效;销毁拒绝新派发且只执行一次关闭。迟到完成不能向旧派发提供
+ 结果。既有失败继续、结果归并、插件归属和权限不变,不强制终止进程内代码。
+ - 未接通事件仍可注册,并在现有诊断中显示。参见
+ `07-plugins/16-trusted-extensions.md` §6 与 `E2E-HOOKS-cancel-and-dispose`。