From 1b9d84d027573327eaaefbfae0ab4744901e68ac Mon Sep 17 00:00:00 2001 From: msmps <7691252+msmps@users.noreply.github.com> Date: Fri, 30 Jan 2026 20:27:39 +0000 Subject: [PATCH] fix(spawn): default to client's cwd instead of daemon's Previously, spawned processes inherited the daemon's working directory, which was unpredictable (wherever the daemon happened to start from). Now the CLI sends its current directory as the default, matching user expectations. The --cwd flag remains available as an explicit override. Closes #5 --- crates/pilotty-cli/src/args.rs | 3 +-- crates/pilotty-cli/src/main.rs | 7 ++++++- crates/pilotty-core/src/protocol.rs | 6 +++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/crates/pilotty-cli/src/args.rs b/crates/pilotty-cli/src/args.rs index 916db5d..26ff834 100644 --- a/crates/pilotty-cli/src/args.rs +++ b/crates/pilotty-cli/src/args.rs @@ -132,8 +132,7 @@ pub struct SpawnArgs { #[arg(short, long)] pub name: Option, - /// Working directory for the spawned process. - /// If omitted, inherits the daemon's current directory. + /// Working directory for the spawned process [default: current directory] #[arg(long, value_name = "DIR")] pub cwd: Option, } diff --git a/crates/pilotty-cli/src/main.rs b/crates/pilotty-cli/src/main.rs index bd3d365..1814e4a 100644 --- a/crates/pilotty-cli/src/main.rs +++ b/crates/pilotty-cli/src/main.rs @@ -44,7 +44,12 @@ fn cli_to_command(cli: &Cli) -> Option { Commands::Spawn(args) => Some(Command::Spawn { command: args.command.clone(), session_name: args.name.clone(), - cwd: args.cwd.clone(), + // Default to client's cwd if --cwd not explicitly provided + cwd: args.cwd.clone().or_else(|| { + std::env::current_dir() + .ok() + .map(|p| p.to_string_lossy().into_owned()) + }), }), Commands::Kill(args) => Some(Command::Kill { session: args.session.clone(), diff --git a/crates/pilotty-core/src/protocol.rs b/crates/pilotty-core/src/protocol.rs index 5f8c02a..0342b28 100644 --- a/crates/pilotty-core/src/protocol.rs +++ b/crates/pilotty-core/src/protocol.rs @@ -27,9 +27,9 @@ pub enum Command { session_name: Option, /// Working directory for the spawned process. /// - /// If provided, the command runs in this directory. The path must be - /// an existing directory. If not provided, the process inherits the - /// daemon's working directory. + /// The CLI defaults this to the client's current directory. The path + /// must be an existing directory. If not provided by the client, the + /// process inherits the daemon's working directory. cwd: Option, }, /// Kill a session.