Skip to main content

agentmux_srv/backend/blockcontroller/shell/
spawn_cwd.rs

1// Copyright 2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4/// The directory a shell starts in: the pane's `cmd:cwd`, or for a local
5/// shell without one, the user's home. Without that default a new terminal
6/// inherited srv's own working directory: wherever the app was started from,
7/// and inside the checkout's `dist/` in a dev build
8/// (docs/specs/PLAN_SHORTCUT_KINKS_2026_10_10.md, A6). An SSH or WSL pane's
9/// directory is a path on the other side, so it gets no local default.
10pub(crate) fn spawn_cwd(pane_cwd: &str, remote: bool) -> String {
11    if !pane_cwd.is_empty() || remote {
12        return pane_cwd.to_string();
13    }
14    crate::backend::base::get_home_dir().to_string_lossy().to_string()
15}
16
17#[cfg(test)]
18mod spawn_cwd_tests {
19    use super::spawn_cwd;
20
21    #[test]
22    fn keeps_the_panes_own_directory() {
23        assert_eq!(spawn_cwd("/work/proj", false), "/work/proj");
24        assert_eq!(spawn_cwd("/work/proj", true), "/work/proj");
25    }
26
27    #[test]
28    fn a_local_shell_without_one_starts_at_home() {
29        let home = crate::backend::base::get_home_dir().to_string_lossy().to_string();
30        assert_eq!(spawn_cwd("", false), home);
31    }
32
33    #[test]
34    fn a_remote_shell_gets_no_local_default() {
35        assert_eq!(spawn_cwd("", true), "");
36    }
37}