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): report missing tool files explicitly
vastsab555ebdf096b
diff --cc crates/host-core/src/tools/mod.rsindex 27592bc54,0479585e2..3ff3d7d57--- a/crates/host-core/src/tools/mod.rs+++ b/crates/host-core/src/tools/mod.rs@@@ -63,7 -64,7 +64,6 @@@ use windows_sys::Win32::System::JobObjestruct ProcessOwnership {job: Option<HANDLE>,}--#[cfg(not(windows))]#[derive(Debug, Default)]struct ProcessOwnership;@@@ -189,7 -190,7 +189,6 @@@ impl ProcessOwnership}}}--#[cfg(windows)]// Windows kernel handles are process-wide and safe to move between Tokio// worker threads; the ownership wrapper closes exactly one job handle.@@@ -1357,13 -1411,12 +1424,17 @@@ fn tool_editlet (resolved, root_kind) =resolve_tool_path_with_external(root, scratch, path, allow_external_paths).map_err(|e| hashline::ToolError::new(e.clone(), e))?;+ if ignore_rules::is_sensitive_path(&resolved) {+ let (code, message) = ignore_rules::denied_error(path);+ return Err(hashline::ToolError::new(code, message));+ }- let live = std::fs::read(&resolved)- .map_err(|e| hashline::ToolError::new("TOOL_FAILED", format!("read failed: {e}")))?;+ let live = std::fs::read(&resolved).map_err(|e| {+ if e.kind() == std::io::ErrorKind::NotFound {+ hashline::ToolError::new("FILE_NOT_FOUND", format!("File not found: {path}"))+ } else {+ hashline::ToolError::new("TOOL_FAILED", format!("read failed: {e}"))+ }+ })?;let display = display_tool_path(root_kind, root, &resolved);let canonical = hashline::canonical_key(&resolved);let (file, success) = hashline::apply_edit(@@@ -4087,71 -4432,4 +4450,70 @@@ mod testslet written = std::fs::read_to_string(&target).unwrap();assert_eq!(written, "line one\r\nline TWO replaced\r\nline three\r\n");}++ #[tokio::test]+ async fn read_missing_file_reports_file_not_found() {+ let dir = tempfile::tempdir().unwrap();+ let result = execute_tool(+ Some(dir.path()),+ None,+ "Read",+ &serde_json::json!({ "path": "no-such-file.txt" }),+ 5_000,+ )+ .await;+ assert!(!result.ok, "read of missing file must fail");+ assert_eq!(result.error_code.as_deref(), Some("FILE_NOT_FOUND"));+ // execute_tool_with_path_access serializes tool errors under content["error"]+ let msg = result.content["error"].as_str().unwrap_or_default();+ assert!(+ msg.contains("no-such-file.txt"),+ "diagnostic should name the path: {msg}"+ );+ }++ #[tokio::test]+ async fn write_creates_missing_parent_directories() {+ // Write intentionally creates missing parent dirs (create_dir_all),+ // so a missing parent is not FILE_NOT_FOUND.+ let dir = tempfile::tempdir().unwrap();+ let result = execute_tool(+ Some(dir.path()),+ None,+ "Write",+ &serde_json::json!({ "path": "no/such/dir/file.txt", "content": "x" }),+ 5_000,+ )+ .await;+ assert!(+ result.ok,+ "write under missing parent should create dirs: {:?}",+ result.content+ );+ assert!(dir.path().join("no/such/dir/file.txt").is_file());+ }++ #[tokio::test]+ async fn edit_missing_file_reports_file_not_found() {+ let dir = tempfile::tempdir().unwrap();+ let result = execute_tool(+ Some(dir.path()),+ None,+ "Edit",+ &serde_json::json!({+ "path": "no-such-file.txt",+ "tag": "abcd",+ "ops": "..."+ }),+ 5_000,+ )+ .await;+ assert!(!result.ok, "edit of missing file must fail");+ assert_eq!(result.error_code.as_deref(), Some("FILE_NOT_FOUND"));+ let msg = result.content["error"].as_str().unwrap_or_default();+ assert!(+ msg.contains("no-such-file.txt"),+ "diagnostic should name the path: {msg}"+ );+ }}-diff --cc docs/spec/03-runtime/08-error-codes.mdindex c56d487b1,7d939ae5e..5a8f80c8e--- a/docs/spec/03-runtime/08-error-codes.md+++ b/docs/spec/03-runtime/08-error-codes.md@@@ -91,8 -126,8 +126,9 @@@ does not turn temporary thread pressur| `TOOL_DENIED` | no | permission denied / mode forbidden || `TOOL_TIMEOUT` | yes | tool execution timeout || `TOOL_FAILED` | maybe | tool executed but failed |+| `FILE_NOT_FOUND` | no | Read/Write/Edit target path does not exist (distinct from `TOOL_DENIED`) |- | `MUTATION_RETRY_BUDGET_EXHAUSTED` | yes | the repeat guard ended the turn after same-path `Edit` or shell patch failures; carries `details.kind` (`edit` or `patch-command`) and the last tool error code |+ | `TOOL_ABORTED` | no | the tool was cancelled by a user stop or a turn abort before it finished |+ | `MUTATION_RETRY_BUDGET_EXHAUSTED` | yes | the repeat guard ended the turn after same-path `Edit` or shell patch failures; carries `details.kind` (`edit` or `patch-command`), the last tool error code, and a class-specific `details.recovery` hint || `PROCESS_RESOURCE_EXHAUSTED` | yes | shell process could not start because the OS temporarily exhausted process resources || `SHELL_NOT_FOUND` | no | no effective platform shell is available after catalog fallback; message carries guidance || `COMMAND_SHELL_CHANGED` | no | pinned shell ID or dialect changed before execution |diff --cc docs/zh-CN/spec/03-runtime/08-error-codes.mdindex c0282a2e3,03b5864e0..15d2f9385--- a/docs/zh-CN/spec/03-runtime/08-error-codes.md+++ b/docs/zh-CN/spec/03-runtime/08-error-codes.md@@@ -90,7 -128,7 +128,8 @@@ stdio 与 Tokio 的动态阻塞池隔�| `TOOL_DENIED` | 不 | 权限被拒绝/模式被禁止 || `TOOL_TIMEOUT` | 是的 | 工具执行超时 || `TOOL_FAILED` | 也许 | 工具已执行但失败 |+| `FILE_NOT_FOUND` | 不 | Read/Write/Edit 目标路径不存在(与 `TOOL_DENIED` 可区分) |+ | `TOOL_ABORTED` | 不 | 工具在完成前被用户停止或回合中止取消 || `MUTATION_RETRY_BUDGET_EXHAUSTED` | 是 | 重复保护在同路径 `Edit` 或 shell patch 反复失败后终止了本轮;携带 `details.kind`(`edit` 或 `patch-command`)与最后一个工具错误代码 || `PROCESS_RESOURCE_EXHAUSTED` | 是的 | shell 进程无法启动,因为操作系统暂时耗尽了进程资源 || `SHELL_NOT_FOUND` | 不 | 目录回退后没有有效的平台 shell 可用;消息承载指引 |