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(host-core): cover Bash timeout and scratch path behavior
vastsa1ea8c5dbf428
diff --git a/crates/host-core/src/tools/shell.rs b/crates/host-core/src/tools/shell.rsindex b7fb807e0..9aa28d15a 100644--- a/crates/host-core/src/tools/shell.rs+++ b/crates/host-core/src/tools/shell.rs@@ -708,6 +708,24 @@ mod tests {);}+ #[test]+ fn scratch_dir_uses_posix_separators_only_for_posix_shells() {+ let scratch = PathBuf::from(r"C:\Users\Lan\AppData\Local\PI Desktop\scratch");++ assert_eq!(+ format_scratch_dir_for_shell(Some("posix"), &scratch).to_string_lossy(),+ "C:/Users/Lan/AppData/Local/PI Desktop/scratch"+ );+ assert_eq!(+ format_scratch_dir_for_shell(Some("powershell"), &scratch).to_string_lossy(),+ scratch.to_string_lossy()+ );+ assert_eq!(+ format_scratch_dir_for_shell(Some("cmd"), &scratch).to_string_lossy(),+ scratch.to_string_lossy()+ );+ }+#[test]fn user_login_path_probes_a_real_path() {// On any machine with a login shell the probe yields a non-emptydiff --git a/docs/spec/03-runtime/03-tools-and-permissions.md b/docs/spec/03-runtime/03-tools-and-permissions.mdindex c8ab17a1f..61793d533 100644--- a/docs/spec/03-runtime/03-tools-and-permissions.md+++ b/docs/spec/03-runtime/03-tools-and-permissions.md@@ -226,9 +226,11 @@ as binary content.- **Addressing.** In a project session, the model addresses scratch by absolutepath only; the path is advertised in the system prompt, relative tool pathsresolve against the project workspace, and `Bash` exports- `PI_SCRATCH_DIR`. In a temporary session, that same scratch directory is the- session workspace root, so relative Read/Glob/Grep/Write/Edit/Bash paths work- there without inheriting a project.+ `PI_SCRATCH_DIR`. POSIX shells, including Git Bash on Windows, receive the+ forward-slash path advertised in the prompt; PowerShell and cmd keep the+ native path spelling. In a temporary session, that same scratch directory is+ the session workspace root, so relative Read/Glob/Grep/Write/Edit/Bash paths+ work there without inheriting a project.- **Containment.** `resolve_tool_path` tries the workspace root first, thenthe scratch root, applying the identical two-layer defense (lexical `..`normalization + canonicalized-ancestor symlink check) to each. A symlink@@ -370,6 +372,8 @@ Host execution baseline:- Default cwd = the originating session's `workspaceRoot`- Confirmation required by default- Set a mandatory 60s timeout; accept a 1s–21,600s override (D329)+- A timeout returns `TOOL_TIMEOUT` with the effective `timeoutMs` budget and+ guidance to raise that budget or split the command- Stream stdout and stderr separately, then return bounded final output- Truncate large output without mixing the two streams- No interactive TTY (MVP)diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.mdindex 6c3bea880..28f21d6a3 100644--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@ -2725,12 +2725,12 @@ identify the platform validation still needed.#### E2E-019a: Scratch-directory writes stay out of the workspace (D114)- **Preconditions**: Agent mode; project open; session started.-- **Steps**: 1) Ask the agent to produce a temporary/intermediate file (e.g. a one-off script). 2) Observe where it writes and whether a permission card appears. 3) Check `git status` and the work-panel state. 4) Delete the session and check `<data_dir>/scratch/`.-- **Expected**: The file lands under `<data_dir>/scratch/<sessionId>/` without a permission card; project `git status` stays clean; no file or Review artifact tab opens for the scratch write; deleting the session removes the scratch directory.+- **Steps**: 1) Ask the agent to produce a temporary/intermediate file (e.g. a one-off script). 2) Observe where it writes and whether a permission card appears. 3) Check `git status` and the work-panel state. 4) On Windows with Git Bash selected, print `$PI_SCRATCH_DIR` and write a file through that path. 5) Delete the session and check `<data_dir>/scratch/`.+- **Expected**: The file lands under `<data_dir>/scratch/<sessionId>/` without a permission card; project `git status` stays clean; no file or Review artifact tab opens for the scratch write; Git Bash receives a directly usable forward-slash path matching the prompt, while PowerShell and cmd retain native path spelling; deleting the session removes the scratch directory.- **Specs linked**: `03-runtime/03-tools-and-permissions.md §4b`, `03-runtime/04-data-storage.md`- **Acceptance**: E (temp files isolated from workspace)- **Milestone**: M5-- **Status**: Partially automated (host-core unit tests: dual-root resolve, scratch write/read, PI_SCRATCH_DIR, sweep)+- **Status**: Partially automated (host-core unit tests: dual-root resolve, scratch write/read, Windows Git Bash `PI_SCRATCH_DIR` formatting, sweep)#### E2E-019b: Scratch containment matches workspace defenses (D114)@@ -7316,8 +7316,10 @@ must keep splitting are covered by `markdown-blocks.test.mjs`.deadline. 3) Run with an in-range override including values above 300seconds. 4) Submit zero, negative, and over-21,600-second overrides.- **Expected**: Missing timeout uses exactly 60 seconds and returns- `TOOL_TIMEOUT` after process-tree shutdown. In-range values work within- 1–21,600 seconds; out-of-range values fail validation and never spawn.+ `TOOL_TIMEOUT` after process-tree shutdown; the error names the effective+ `timeoutMs` budget and suggests raising it or splitting the command. In-range+ values work within 1–21,600 seconds; out-of-range values fail validation and+ never spawn.- **Specs linked**: `03-runtime/03-tools-and-permissions.md`,`03-runtime/06-host-rpc-protocol.md`, `03-runtime/08-error-codes.md`,`03-runtime/16-tool-result-limits.md`, `05-security/01-security.md`, ADR 0054,diff --git a/docs/zh-CN/spec/03-runtime/03-tools-and-permissions.md b/docs/zh-CN/spec/03-runtime/03-tools-and-permissions.mdindex ede9a531c..a96854fed 100644--- a/docs/zh-CN/spec/03-runtime/03-tools-and-permissions.md+++ b/docs/zh-CN/spec/03-runtime/03-tools-and-permissions.md@@ -178,7 +178,8 @@ Electron 主要低于 `<data_dir>/scratch/<sessionId>/pasted/` 之前的- **寻址。** 该模型仅通过绝对路径寻址;路径在系统提示中公布。相对刀具路径始终解析- 反对工作区。 `Bash` 还导出 `PI_SCRATCH_DIR`。+ 反对工作区。 `Bash` 还导出 `PI_SCRATCH_DIR`。POSIX shell(包括 Windows 上的+ Git Bash)收到提示中展示的正斜杠路径;PowerShell 和 cmd 保留原生路径格式。- **遏制。** `resolve_tool_path` 首先尝试工作空间根目录,然后暂存根,应用相同的两层防御(词汇 `..`规范化+规范化祖先符号链接检查)到每个。符号链接@@ -309,6 +310,7 @@ type ReviewChange = {- 默认 cwd = 原始会话的 `workspaceRoot`- 默认需要确认- 设置强制 60 秒超时;接受 1 秒至 21,600 秒覆盖(D329)+- 超时返回 `TOOL_TIMEOUT`,错误消息包含实际 `timeoutMs` 预算,并建议延长预算或拆分命令- 分别流式传输 stdout 和 stderr,然后返回有界的最终输出- 截断大输出而不混合两个流- 没有交互式 TTY (MVP)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 c5f4dba19..5256e35db 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@@ -1113,12 +1113,12 @@ task-candidate E2E 从请求工作树运行,但使用主工作区已经准备#### E2E-019a:暂存目录写入不在工作区中 (D114)- **先决条件**:Agent 模式;项目开放;会议开始。-- **步骤**: 1) 要求代理生成 temporary/intermediate 文件(例如一次性脚本)。 2)观察其书写位置以及是否出现权限卡。 3) 检查`git status` 和工作面板状态。 4) 删除会话并检查`<data_dir>/scratch/`。-- **预期**:文件在没有权限卡的情况下登陆 `<data_dir>/scratch/<sessionId>/` 下; `git status` 项目保持干净;没有文件或查看工件选项卡打开用于临时写入;删除会话会删除临时目录。+- **步骤**:1) 要求代理生成临时文件(例如一次性脚本)。2) 观察写入位置及是否出现权限卡。3) 检查 `git status` 和工作面板。4) 在 Windows 上选择 Git Bash,打印 `$PI_SCRATCH_DIR` 并通过该路径写入文件。5) 删除会话并检查 `<data_dir>/scratch/`。+- **预期**:文件在没有权限卡的情况下写入 `<data_dir>/scratch/<sessionId>/`;项目 `git status` 保持干净;临时写入不会打开文件或 Review 工件标签;Git Bash 收到与提示一致、可直接使用的正斜杠路径,而 PowerShell 和 cmd 保留原生路径格式;删除会话会删除临时目录。- **链接规格**:`03-runtime/03-tools-and-permissions.md §4b`、`03-runtime/04-data-storage.md`- **接受**:E(与工作区隔离的临时文件)- **里程碑**:M5-- **状态**:部分自动化(host-core 单元测试:双根解析、暂存 write/read、PI_SCRATCH_DIR、扫描)+- **状态**:部分自动化(host-core 单元测试:双根解析、暂存读写、Windows Git Bash `PI_SCRATCH_DIR` 路径格式、清理)#### E2E-019b:划痕遏制与工作空间防御相匹配 (D114)@@ -4390,9 +4390,9 @@ eleven-tool-round desktop paths are verified by- **步骤**:1) 在没有超时覆盖的情况下运行。 2) 观察60秒截止日期。 3) 以范围内超驰运行。 4) 提交零、负数和超过 21,600 秒的覆盖。-- **预期**:缺少超时正好使用 60 秒并返回- 进程树关闭后的 `TOOL_TIMEOUT`。范围内的值起作用- 1–21,600 秒;超出范围的值将无法验证并且永远不会生成。+- **预期**:缺少超时正好使用 60 秒,并在进程树关闭后返回+ `TOOL_TIMEOUT`;错误会注明实际 `timeoutMs` 预算,并建议延长预算或拆分命令。+ 范围内的值在 1–21,600 秒内生效;超出范围的值校验失败且不会启动进程。- **链接规格**:`03-runtime/03-tools-and-permissions.md`,`03-runtime/06-host-rpc-protocol.md`、`03-runtime/08-error-codes.md`、`03-runtime/16-tool-result-limits.md`、`05-security/01-security.md`、ADR 0054、