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): clarify Bash timeout and format scratch dir for POSIX
ZxlDragonDoctor53a1eb10e0b3
diff --git a/crates/host-core/src/tools/mod.rs b/crates/host-core/src/tools/mod.rsindex 4e12c6ba6..a57f182d3 100644--- a/crates/host-core/src/tools/mod.rs+++ b/crates/host-core/src/tools/mod.rs@@ -2770,7 +2770,12 @@ async fn tool_bash(program: invocation.program,args: invocation.args,workspace: root.to_path_buf(),- scratch_dir: scratch.map(Path::to_path_buf),+ scratch_dir: scratch.map(|path| {+ shell::format_scratch_dir_for_shell(+ shell::dialect_for_id(&options.command_shell_id),+ path,+ )+ }),env_path: shell::user_login_path().map(str::to_string),};let SpawnedToolRunner {@@ -2853,7 +2858,15 @@ async fn tool_bash(notifier.finish();match stop {- BashStop::TimedOut => Err(("TOOL_TIMEOUT".into(), "bash timed out".into())),+ BashStop::TimedOut => Err((+ "TOOL_TIMEOUT".into(),+ format!(+ "bash timed out after {timeout_ms}ms and was stopped; \+ the command did not finish within the Bash tool's timeoutMs budget. \+ Raise timeoutMs for a legitimately long command, or split the work \+ into shorter commands that each finish inside the budget"+ ),+ )),BashStop::Aborted => Err(("TOOL_ABORTED".into(), "bash aborted".into())),BashStop::LifecycleFailed(error) => Err(("TOOL_FAILED".into(),@@ -4687,6 +4700,85 @@ mod tests {assert!(scratch.is_dir(), "scratch dir created for Bash");}+ #[tokio::test]+ async fn bash_timeout_error_names_the_budget() {+ let dir = tempfile::tempdir().unwrap();+ let shell_id = shell::catalog(None)+ .effective+ .expect("test platform must have a command shell")+ .id;+ let dialect = shell::dialect_for_id(&shell_id).unwrap_or("posix");+ let command = match dialect {+ "powershell" => "Start-Sleep -Seconds 5",+ "cmd" => "ping -n 6 127.0.0.1 >NUL",+ _ => "sleep 5",+ };+ let result = execute_tool_with_options(+ Some(dir.path()),+ None,+ "Bash",+ &serde_json::json!({ "command": command }),+ Some(1_000),+ Some(BashExecutionOptions {+ session_id: "timeout-session".into(),+ tool_call_id: "timeout-call".into(),+ command_shell_id: shell_id,+ timeout_ms: Some(1_000),+ cancellation: None,+ output_tx: None,+ }),+ )+ .await;+ assert!(!result.ok, "expected a timeout, got: {:?}", result.content);+ assert_eq!(result.is_error, Some(true));+ assert_eq!(result.error_code.as_deref(), Some("TOOL_TIMEOUT"));+ let message = result.content["error"].as_str().unwrap_or_default();+ assert!(+ message.contains("1000ms"),+ "timeout message names the budget: {message:?}"+ );+ assert!(+ message.contains("timeoutMs"),+ "timeout message says how to extend the budget: {message:?}"+ );+ }++ #[cfg(windows)]+ #[tokio::test]+ async fn bash_scratch_dir_env_is_posix_formatted_for_git_bash() {+ if shell::resolve_shell(shell::GIT_BASH_ID).is_err() {+ eprintln!("git-bash is not installed; skipping the posix scratch env test");+ return;+ }+ let ws = tempfile::tempdir().unwrap();+ let data = tempfile::tempdir().unwrap();+ let scratch = data.path().join("scratch").join("session-dialect");+ std::fs::create_dir_all(&scratch).unwrap();+ let result = execute_tool_with_options(+ Some(ws.path()),+ Some(&scratch),+ "Bash",+ &serde_json::json!({ "command": "printf %s \"$PI_SCRATCH_DIR\"" }),+ Some(15_000),+ Some(BashExecutionOptions {+ session_id: "dialect-session".into(),+ tool_call_id: "dialect-call".into(),+ command_shell_id: shell::GIT_BASH_ID.into(),+ timeout_ms: Some(15_000),+ cancellation: None,+ output_tx: None,+ }),+ )+ .await;+ assert!(result.ok, "bash failed: {:?}", result.content);+ let stdout = result.content["stdout"].as_str().unwrap_or_default();+ let expected = scratch.to_str().unwrap().replace('\\', "/");+ assert_eq!(+ stdout, expected,+ "PI_SCRATCH_DIR must be a path the posix shell can use directly"+ );+ }+#[tokio::test]async fn bash_output_accumulator_is_bounded_and_reports_omissions() {let dir = tempfile::tempdir().unwrap();diff --git a/crates/host-core/src/tools/shell.rs b/crates/host-core/src/tools/shell.rsindex bafbd64cb..b7fb807e0 100644--- a/crates/host-core/src/tools/shell.rs+++ b/crates/host-core/src/tools/shell.rs@@ -111,6 +111,19 @@ pub fn dialect_for_id(id: &str) -> Option<&'static str> {}}+/// Format a scratch directory for the shell that will read `PI_SCRATCH_DIR`.+///+/// Mirrors `formatScratchDirForShell` in `agent-runtime`: POSIX shells+/// (including Git Bash on Windows) can only consume forward-slash paths, so+/// the env value must match the forward-slash path the prompt advertises.+pub fn format_scratch_dir_for_shell(dialect: Option<&str>, path: &Path) -> PathBuf {+ if dialect == Some("posix") {+ PathBuf::from(path.to_string_lossy().replace('\\', "/"))+ } else {+ path.to_path_buf()+ }+}+/// Build a public catalog using a caller-supplied availability probe. This/// pure seam keeps catalog/default/fallback tests independent of the host OS.pub fn catalog_for_platform(