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: 将会话 scratch 路径移到系统提示末段
geng yued06c4436ebee
diff --git a/docs/spec/03-runtime/02-agent-runtime.md b/docs/spec/03-runtime/02-agent-runtime.mdindex 373f3be4d..d91e42b32 100644--- a/docs/spec/03-runtime/02-agent-runtime.md+++ b/docs/spec/03-runtime/02-agent-runtime.md@@ -2029,3 +2029,7 @@ parent turn open. Delegation report delivery and resumability retain theirexisting lifecycle. Runtime capability probing is connection-scoped; olderHosts and remote workspaces explicitly report Bash controls unavailable,while delegation controls remain usable. Transport and Host failures propagate.++### Shared prefix and scratch identity (#1926)++The base runtime system section keeps shell dialect, scratch-variable syntax and temporary-file policy stable across sessions. The exact scratch directory is appended after project/memory context rather than embedded twice in the leading runtime rules. Bash tool descriptions retain their exact path guidance. This preserves a shared system-text prefix, without promising provider cache hits or changing history reconstruction.diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.mdindex 12473a3dc..ad4db0a54 100644--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@ -20399,3 +20399,7 @@ While a checkpoint estimate supplies context occupancy, use its recorded provide- Specs: `03-runtime/02-agent-runtime.md`, Session job controls.- Acceptance: wait, report re-read and running-delegate cancellation completethrough the real tool loop. Milestone: maintenance. Status: automated.++#### E2E-ISSUE-1926-scratch-prefix++Build two actual runtimes with identical configuration and different scratch directories. Their leading runtime system sections match; each trailing context retains its own path. Check PowerShell/POSIX guidance and custom system prompt behavior. Coverage: runtime.test.ts. No paid provider requests or cache-hit claims.diff --git a/docs/zh-CN/spec/03-runtime/02-agent-runtime.md b/docs/zh-CN/spec/03-runtime/02-agent-runtime.mdindex e010adcdb..c1abec17a 100644--- a/docs/zh-CN/spec/03-runtime/02-agent-runtime.md+++ b/docs/zh-CN/spec/03-runtime/02-agent-runtime.md@@ -1331,3 +1331,7 @@ Bash 等待返回状态、可空退出码、停止请求标记及分别最多 8Bash 由 Host 管理,完成后不自动投递结果或延长父回合。原委派报告交付和恢复规则继续生效。能力按连接探测;旧 Host 和远程工作区明确返回后台 Bash 控制不可用,委派操作仍可用。其他传输或 Host 错误会正常呈现。等待时限包含能力探测和在途请求。超时返回最近一次已观察的快照。如果首次观察尚未返回,工具返回作业引用和 `snapshotAvailable: false`,省略进程状态。聊天记录区分显式 Bash 目标,混合作业列表显示后台命令数量。++### 公共提示前缀与 scratch(#1926)++基础 runtime 段保留 shell、scratch 变量及临时文件规则,具体路径移到项目/记忆上下文之后,Bash 工具描述继续提供路径。改善跨会话系统文本公共前缀,不承诺供应商缓存命中,不更改历史重建。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 918e091b6..944dceaf8 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@@ -10420,3 +10420,7 @@ Electron 一侧——工具自动签发、指示器、"停止"中止轮次、绘#### E2E-ISSUE-2164压缩估算作为占用时使用检查点模型容量,旧检查点使用当前会话完整绑定;历史请求用量不变,未知容量标记估算。验证 20,619 / 1,000,000 为 2%、未知路由、旧记录及新请求恢复。++#### E2E-ISSUE-1926-scratch-prefix++创建配置相同但 scratch 不同的真实 runtime,基础提示段相同且尾部各保留自身路径;验证 shell 语法和自定义提示兼容,不调用真实供应商。diff --git a/packages/agent-runtime/src/runtime.test.ts b/packages/agent-runtime/src/runtime.test.tsindex d7c3f6f70..98bfe9e92 100644--- a/packages/agent-runtime/src/runtime.test.ts+++ b/packages/agent-runtime/src/runtime.test.ts@@ -2699,6 +2699,19 @@ describe("DesktopAgentRuntime configuration matching", () => {await runtime.dispose();});+ it("keeps session scratch paths behind the shared system prefix (#1926)", async () => {+ const first = createRuntime({ scratchDir: "/fixture/scratch/one", projectMemory: "shared memory" });+ const second = createRuntime({ scratchDir: "/fixture/scratch/two", projectMemory: "shared memory" });+ const firstPrompt = first as unknown as { composedSections: Record<string, string> };+ const secondPrompt = second as unknown as { composedSections: Record<string, string> };+ expect(firstPrompt.composedSections.runtime).toBe(secondPrompt.composedSections.runtime);+ expect(firstPrompt.composedSections.runtime).not.toContain("/fixture/scratch/one");+ expect(firstPrompt.composedSections.context).toContain("/fixture/scratch/one");+ expect(secondPrompt.composedSections.context).toContain("/fixture/scratch/two");+ await first.dispose();+ await second.dispose();+ });+it("sends the default Bash timeout and preserves explicit overrides", async () => {const host = {call: vi.fn().mockResolvedValue({ ok: true, content: "done" }),diff --git a/packages/agent-runtime/src/runtime.ts b/packages/agent-runtime/src/runtime.tsindex 5cc1e776d..0a568bf73 100644--- a/packages/agent-runtime/src/runtime.ts+++ b/packages/agent-runtime/src/runtime.ts@@ -2129,11 +2129,11 @@ Do not invent objections or turn speculative risks into blockers. Stop when the// Editing workflow.`Editing workflow: inside the advertised workspace, use Edit for small, uniquely anchored changes and Write for new files or intentional whole-file rewrites. Never modify the same path concurrently. Do not use shell apply_patch, git apply, patch, or hand-edited unified-diff files. On failure, diagnose the cause, refresh content or anchors with Read or a complete tool-provided reveal when needed, and correct the payload before retrying. After three failed edit attempts on the same path in one user turn, stop editing that path, report the exact error, and continue unblocked work. For an authorized worktree outside the advertised workspace, use a guarded, deterministic Bash edit that aborts on unexpected content, then verify the diff.`,// Shell dialect and scratch variable are selected by host-core.- commandShellGuidance(this.commandShell, this.scratchDir),+ commandShellGuidance(this.commandShell),// Session scratch directory (D114)....(this.scratchDir? [- `Your scratch directory for this session is \`${formatScratchDirForShell(this.commandShell, this.scratchDir)}\` (in Bash: ${shellScratchVariable(this.commandShell)}). Store ad-hoc temporary and intermediate files there using absolute paths. Workspace writes must be task-related project files or required toolchain outputs. Scratch persists across turns and is deleted with the session.`,+ `Store ad-hoc temporary and intermediate files in the session scratch directory using ${shellScratchVariable(this.commandShell)}. Workspace writes must be task-related project files or required toolchain outputs. Scratch persists across turns and is deleted with the session.`,]: []),// Inline visualizations (ADR gen-ui-inline-visualization).@@ -2505,6 +2505,9 @@ Do not invent objections or turn speculative risks into blockers. Stop when the...(optionalToolsPrompt ? [optionalToolsPrompt] : []),...(projectPrompt ? [projectPrompt] : []),...(memoryPrompt ? [memoryPrompt] : []),+ ...(this.scratchDir ? [+ `Your scratch directory for this session is \`${formatScratchDirForShell(this.commandShell, this.scratchDir)}\` (in Bash: ${shellScratchVariable(this.commandShell)}).`,+ ] : []),].join("\n\n")),};const composed = Object.values(this.composedSections).filter(Boolean).join("\n\n");