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(chat): explain queue admission while preserving pending guards
yuxino6c1d5e5e47c1
diff --cc apps/desktop/src/features/chat/composer/ComposerStatus.tsxindex 0ebe4369b,c104aa84f..46b915161--- a/apps/desktop/src/features/chat/composer/ComposerStatus.tsx+++ b/apps/desktop/src/features/chat/composer/ComposerStatus.tsx@@@ -100,15 -105,15 +105,21 @@@ export function ComposerStatus(><IconArrowDown size={13} aria-hidden /></TooltipButton>-- <button++ <TooltipButtontype="button"className="composer-queued-prompt-send-now"++ tooltip={actionLabel(t("chat.sendNow"))}++ ariaLabel={actionLabel(t("chat.sendNow"))}disabled={sendNowLocked}aria-disabled={sendNowLocked}onClick={() => void sendQueuedNow(item.id)}>-- {promoted ? t("chat.sendNowPending") : t("chat.sendNow")}-- </button>++ {promoted++ ? t("chat.sendNowPending")++ : pending++ ? t("common.saving")++ : t("chat.sendNow")}++ </TooltipButton><TooltipButtontype="button"className="composer-queued-prompt-action composer-queued-prompt-edit"diff --cc apps/desktop/test/composer-send-state.test.mjsindex a4bfe505b,3e5b8272b..728b9d150--- a/apps/desktop/test/composer-send-state.test.mjs+++ b/apps/desktop/test/composer-send-state.test.mjs@@@ -136,15 -136,15 +136,15 @@@ test("running prompts use a removable passert.match(composer, /disabled=\{sendNowLocked\}/);assert.match(composer,-- /\{promoted \? t\("chat\.sendNowPending"\) : t\("chat\.sendNow"\)\}/,++ /\{promoted\s*\? t\("chat\.sendNowPending"\)\s*: pending\s*\? t\("common\.saving"\)\s*: t\("chat\.sendNow"\)\}/,);assert.equal(- (composer.match(/disabled=\{promoted\}/g) ?? []).length,+ (composer.match(/disabled=\{actionsLocked\}/g) ?? []).length,8,- "four promoted rows set disabled and aria-disabled on move up/down, edit, and remove",+ "four pending or promoted row actions set disabled and aria-disabled on move up/down, edit, and remove",);assert.equal(- (composer.match(/aria-disabled=\{promoted\}/g) ?? []).length,+ (composer.match(/aria-disabled=\{actionsLocked\}/g) ?? []).length,4,"each locked action carries its own aria-disabled state",);diff --cc apps/desktop/test/queue-pending-actions.test.mjsindex 000000000,ad9883cfb..2724d9235mode 000000,100644..100644--- a/apps/desktop/test/queue-pending-actions.test.mjs+++ b/apps/desktop/test/queue-pending-actions.test.mjs@@@ -1,0 -1,82 +1,121 @@@+ import assert from "node:assert/strict";+ import test from "node:test";+ import { fileURLToPath } from "node:url";+ import { createElement } from "react";+ import { renderToStaticMarkup } from "react-dom/server";+ import { createServer } from "vite";+ import { IPC } from "@pi-desktop/shared";++ test("pending queue actions stay locked until admission succeeds", async (t) => {+ const server = await createServer({+ root: fileURLToPath(new URL("..", import.meta.url)),+ configFile: false,+ server: { middlewareMode: true, hmr: false, ws: false },+ esbuild: { jsx: "automatic" },+ appType: "custom",+ optimizeDeps: { noDiscovery: true, include: [] },+ });+ const previousWindow = globalThis.window;+ try {+ const { createQueueSlice } = await server.ssrLoadModule("/src/stores/slices/queue-slice.ts");+ const { ComposerStatus } = await server.ssrLoadModule("/src/features/chat/composer/ComposerStatus.tsx");+ for (const action of ["removeQueuedPrompt", "editQueuedPrompt"]) {+ await t.test(action, async () => {+ let resolvePush;+ const admission = new Promise((resolve) => { resolvePush = resolve; });+ let entries = [];+ const removed = [];+ globalThis.window = { piDesktop: { invoke: async (channel, payload) => {+ if (channel === IPC.invoke.agentQueuePush) {+ await admission;+ const entry = { ...payload, id: "durable-turn", createdAt: "2026-09-21T00:00:00Z" };+ entries = [entry];+ return { ok: true, data: entry };+ }+ if (channel === IPC.invoke.agentQueueList) return { ok: true, data: { entries } };+ if (channel === IPC.invoke.agentQueueRemove) {+ removed.push(payload.turnId);+ entries = entries.filter((entry) => entry.id !== payload.turnId);+ return { ok: true, data: {} };+ }+ throw new Error(`Unexpected IPC: ${channel}`);+ } } };+ let state = { activeSessionId: "session-a", queuedPrompts: {}, showToast: assert.fail };+ const slice = createQueueSlice({+ get: () => state,+ set: (patch) => { state = { ...state, ...(typeof patch === "function" ? patch(state) : patch) }; },+ promptAttachmentsFromDraft: () => [],+ });+ Object.assign(state, slice);+ const draft = { text: "Please review this file", fileReferences: [{ path: "/test/example.ts", name: "example.ts" }] };+ const saving = slice.enqueuePrompt(draft.text, draft);+ const pending = state.queuedPrompts["session-a"][0];+ const renderButtons = () => renderToStaticMarkup(createElement(ComposerStatus, {+ t: (key) => key, queuedPrompts: state.queuedPrompts["session-a"] ?? [],+ ...slice, approvalPending: false, enhancementError: null, droppedDirectories: [],+ })).match(/<button\b[^>]*>/g) ?? [];+ const pendingButtons = renderButtons();+ assert.equal(pendingButtons.length, 5);+ assert.ok(pendingButtons.every((button) => / disabled=""/.test(button)), "all pending row actions must be disabled");++ assert.ok(pendingButtons.every((button) => /aria-label="[^"]*common.saving/.test(button)), "every pending action must explain that admission is still saving");++ const pendingMarkup = renderToStaticMarkup(createElement(ComposerStatus, {++ t: (key) => key, queuedPrompts: [pending], ...slice,++ approvalPending: false, enhancementError: null, droppedDirectories: [],++ }));++ assert.match(pendingMarkup, /class="composer-queued-prompt-send-now"[^>]*>common.saving<\/button>/);+ slice[action](pending.id);+ assert.deepEqual(state.queuedPrompts["session-a"], [pending], "pending row must not appear deleted");+ assert.equal(state.composerPrefill, undefined, "pending edit must not restore a second draft");+ assert.deepEqual(removed, []);+ resolvePush();+ assert.equal(await saving, true);+ await slice.refreshQueuedPrompts("session-a");+ assert.ok(renderButtons().every((button) => !/ disabled=""/.test(button)), "acknowledged row actions unlock");++ assert.ok(renderButtons().every((button) => !button.includes("common.saving")), "saving labels clear after acknowledgement");+ slice[action]("durable-turn");+ await slice.refreshQueuedPrompts("session-a");+ assert.deepEqual(removed, ["durable-turn"]);+ assert.deepEqual(entries, []);+ assert.deepEqual(state.queuedPrompts["session-a"] ?? [], []);+ if (action === "editQueuedPrompt") {+ assert.deepEqual(state.composerPrefill, { sessionId: "session-a", ...draft });+ }+ });+ }++ await t.test("failed admission clears the pending row and permits another submission", async () => {++ let rejectPush;++ const admission = new Promise((_, reject) => { rejectPush = reject; });++ const errors = [];++ let entries = [];++ globalThis.window = { piDesktop: { invoke: async (channel, payload) => {++ if (channel === IPC.invoke.agentQueuePush) {++ if (!errors.length) await admission;++ const entry = { ...payload, id: "retried-turn", createdAt: "2026-09-21T00:00:00Z" };++ entries = [entry];++ return { ok: true, data: entry };++ }++ if (channel === IPC.invoke.agentQueueList) return { ok: true, data: { entries } };++ throw new Error(`Unexpected IPC: ${channel}`);++ } } };++ let state = { activeSessionId: "session-a", queuedPrompts: {}, showToast: (message) => errors.push(message) };++ const slice = createQueueSlice({++ get: () => state,++ set: (patch) => { state = { ...state, ...(typeof patch === "function" ? patch(state) : patch) }; },++ promptAttachmentsFromDraft: () => [],++ });++ Object.assign(state, slice);++ const saving = slice.enqueuePrompt("Retry this prompt");++ assert.equal(state.queuedPrompts["session-a"].length, 1);++ rejectPush(new Error("host RPC timeout: session.queuePush"));++ assert.equal(await saving, false, "composer must receive rejection so it can restore the draft");++ assert.deepEqual(state.queuedPrompts["session-a"] ?? [], []);++ assert.deepEqual(errors, ["host RPC timeout: session.queuePush"]);++ assert.equal(await slice.enqueuePrompt("Retry this prompt"), true);++ await slice.refreshQueuedPrompts("session-a");++ assert.equal(state.queuedPrompts["session-a"][0].id, "retried-turn");++ });+ } finally {+ globalThis.window = previousWindow;+ await server.close();+ }+ });diff --cc docs/spec/04-ux/08-component-spec.mdindex f98334ccf,a99b4ea5e..e01aac822--- a/docs/spec/04-ux/08-component-spec.md+++ b/docs/spec/04-ux/08-component-spec.md@@@ -2741,6 -2733,10 +2741,10 @@@ reasoning-level controlcurrent reply/tool batch completes normally, before every waiting row. Thefirst promoted row starts the turn and the rest join it as adjacent usermessages, so the block is answered once. When idle it starts immediately.+ - A pending queue row is locked until Host admission returns its durable id: move- up/down, Send now, edit, and remove are disabled. Edit/remove tooltips explain- that it is saving. Direct edit/remove actions leave the pending row and draft++ up/down, Send now, edit, and remove are disabled. All five tooltips explain++ that it is saving; Send now also displays the localized Saving label. Direct edit/remove actions leave the pending row and draft+ unchanged; after admission, ordinary waiting-row actions become available.- A promoted row is locked: move up/down, edit, and remove are disabled withtheir tooltip and `aria-disabled` state intact, and the Send now button readsas already decided (`chat.sendNowPending`). The row carries a distinctdiff --cc docs/spec/04-ux/09-interaction-patterns.mdindex bb0595e27,6a44c11fe..25a0f59f1--- a/docs/spec/04-ux/09-interaction-patterns.md+++ b/docs/spec/04-ux/09-interaction-patterns.md@@@ -724,7 -724,9 +724,10 @@@ may be retained while exactly one worksappend to that session's Host-owned, persisted FIFO queue; session switchingnever moves or clears another session's queue.- The queue renders above the composer. Each row has an independently- keyboard-reachable Remove action and a Send now action.+ keyboard-reachable Remove action and a Send now action once Host admission+ returns a durable id. While admission is pending, row actions are disabled- and edit/remove leave both the queue and composer draft unchanged.++ with Saving tooltips and a Saving label on Send now; edit/remove leave both++ the queue and composer draft unchanged.- Send now moves its row to the head and requests the new `agent/stop` channel.The current assistant response and completed tool batch finish normally;after `agent_end` and durable turn finalization, the promoted row isdiff --cc docs/spec/06-delivery/04-e2e-test-plan.mdindex 633af017f,de38db785..e6fbc9513--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@@ -1380,7 -1381,9 +1381,10 @@@ identify the platform validation stillfollow-ups through their turn boundaries. Repeat with a provider error and animmediate abort. 9) With waiting rows, use move up and move down and confirmthe persisted order follows. 10) Edit a waiting row while the composer holds- text, then with an empty composer.+ text, then with an empty composer. 11) Delay Host queue admission. Attempt to+ edit/remove the pending row, release admission, then edit/remove the durable- row. Repeat with a captured file-reference draft.++ row. Repeat with a captured file-reference draft. 12) Withhold a local Host++ queue-save request until its existing RPC deadline expires, then retry.- **Expected**: The single submit slot contains exactly one button in everystate: disabled Send while idle and empty, enabled Send while running withcontent (which queues the prompt), and Stop while running with an empty@@@ -1402,7 -1405,10 +1406,12 @@@is pending; each subsequent turn starts once in FIFO order, without anotherclick or session switch. Repeated terminal handling does not double-dispatch.Other sessions' queues remain unchanged, and quitting while finalization is- pending preserves queued work without starting another turn.+ pending preserves queued work without starting another turn. Pending-admission- rows disable all five actions and remain visible without restoring a second- draft. Once acknowledged, remove deletes the durable row and edit restores- exactly its captured draft; neither row reappears after refresh.++ rows disable all five actions, explain Saving in each tooltip, show Saving++ on Send now, and remain visible without restoring a second draft. Once acknowledged, remove deletes the durable row and edit restores++ exactly its captured draft; neither row reappears after refresh. A local Host++ admission timeout clears the pending row, reports the error, and restores++ the rejected composer draft; retry can queue normally.- **Specs linked**: `03-runtime/01-ipc-protocol.md` (§5.6),`04-ux/08-component-spec.md` (§11),`04-ux/09-interaction-patterns.md` (§3.4), ADR 0118, ADR 0213, ADR 0265diff --cc docs/zh-CN/spec/04-ux/08-component-spec.mdindex c0109e072,4395e52bc..023a9d62e--- a/docs/zh-CN/spec/04-ux/08-component-spec.md+++ b/docs/zh-CN/spec/04-ux/08-component-spec.md@@@ -1970,6 -1964,9 +1970,10 @@@ MainChat 底部的输入区域,用于顶掉它。随后请求 `agent/stop`,当前回复/工具批次正常结束后释放优先区块,并先于所有等待条目启动。第一条优先行启动回合,其余作为相邻的用户消息加入同一回合,因此整块只被回复一次。会话空闲时立即启动。+ - 入队尚未完成的行在 Host 返回持久化 id 前保持锁定:上移/下移、立即发送、编辑和删除- 均禁用,编辑/删除提示说明正在保存。直接调用编辑/删除也不改变该行或草稿;++ 均禁用,五个操作的提示均说明正在保存,立即发送按钮同时显示本地化的“正在保存”。++ 直接调用编辑/删除也不改变该行或草稿;+ 入队确认后恢复普通等待行的操作。- 被提升的行会被锁定:上移/下移、编辑和删除均被禁用,但仍保留 tooltip 与`aria-disabled` 状态,立即发送按钮显示为已决定(`chat.sendNowPending`)。该行使用不同的提升外观,避免被误认为普通等待行。diff --cc docs/zh-CN/spec/04-ux/09-interaction-patterns.mdindex bc480ebea,84dfadeb9..d90d876e6--- a/docs/zh-CN/spec/04-ux/09-interaction-patterns.md+++ b/docs/zh-CN/spec/04-ux/09-interaction-patterns.md@@@ -601,6 -601,8 +601,9 @@@### 3.5 向当前回合补充指令-- Host 入队尚未返回持久化 id 时,排队行操作保持禁用;编辑和删除不会改变条目或++- Host 入队尚未返回持久化 id 时,排队行操作保持禁用,五个操作均提示正在保存,++ 立即发送按钮也显示正在保存;编辑和删除不会改变条目或+ 输入框草稿,确认完成后恢复普通等待行的操作。- 运行中普通发送和回车发送仍将 follow-up 加入 Host 持久 FIFO。`Alt+Enter` 将可见草稿立即提交到当前回合,macOS 对应 `Option+Enter`。开启或关闭回车发送均可使用,且优先于已打开的自动完成菜单;空闲时正常发送。diff --cc docs/zh-CN/spec/06-delivery/04-e2e-test-plan.mdindex 75ac12b71,61fb0193f..2f38aa1b0--- a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md@@@ -8518,35 -8492,13 +8518,48 @@@ the latest destination. These assertionscripts/e2e-scheduled-workspace.mjs`, using production Electron dispatch andreal 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-011f 补充:入队确认前的操作锁定++ - **前提**:会话正在回复,可控制 Host 入队请求的完成时刻。+ - **步骤**:发送一条后续消息,暂停入队;尝试编辑或删除;释放入队后再次编辑或删除,- 然后刷新队列。用带文件引用的草稿重复。-- **预期**:未确认时五个行操作都禁用,条目不消失,也不回填第二份草稿;++ 然后刷新队列。用带文件引用的草稿重复;让本地 Host 入队请求超过现有 RPC 超时后重试。++- **预期**:未确认时五个行操作都禁用且提示正在保存,立即发送按钮也显示正在保存,++ 条目不消失,也不回填第二份草稿;+ 确认后删除能移除持久化条目,编辑完整回填草稿及文件引用,刷新不会恢复已移除条目。++ 本地 Host 超时后移除未确认行、显示错误并恢复被拒绝的草稿,重试可正常入队。+ - **规格**:`04-ux/08-component-spec.md`、`04-ux/09-interaction-patterns.md`。+ - **验收 / 里程碑**:C、Quality / M6+。+ - **状态**:组件与状态层用户路径由 `queue-pending-actions.test.mjs` 覆盖。