diff --git a/docs/tasks.md b/docs/tasks.md index ac33a5a..76b870e 100644 --- a/docs/tasks.md +++ b/docs/tasks.md @@ -45,7 +45,7 @@ 8. [ ] setup cli commands. 1. [x] Organize all the params. 2. [x] Remove old cli. - 3. [ ] add an actual config file. + 3. [x] add an actual config file. 4. [ ] set up the cli. 9. [ ] fix ui overlap, and consistency issue. 10. [ ] intensive integration test. diff --git a/src/config.rs b/src/config.rs index 6a66ff0..a2f849e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -41,7 +41,7 @@ impl Default for BoxConfig { Self { cpu_count: default_cpu_count(), ram_mb: default_ram_mb(), - mounts: Vec::new(), + mounts: default_mounts(), } } } @@ -71,6 +71,24 @@ fn default_auto_shutdown_ms() -> u64 { DEFAULT_AUTO_SHUTDOWN_MS } +fn default_mounts() -> Vec { + let home = match std::env::var("HOME") { + Ok(home) => PathBuf::from(home), + Err(_) => return Vec::new(), + }; + + let mut mounts = Vec::new(); + let codex_host = home.join(".codex"); + if codex_host.exists() { + mounts.push("~/.codex:/usr/local/codex:read-write".to_string()); + } + let claude_host = home.join(".claude"); + if claude_host.exists() { + mounts.push("~/.claude:/usr/local/claude:read-write".to_string()); + } + mounts +} + pub fn config_path(project_root: &Path) -> PathBuf { project_root.join(CONFIG_FILENAME) } diff --git a/src/vm.rs b/src/vm.rs index d8d4361..43207d3 100644 --- a/src/vm.rs +++ b/src/vm.rs @@ -83,7 +83,7 @@ impl DirectoryShare { if parts.len() < 2 || parts.len() > 3 { return Err(format!("Invalid mount spec: {spec}").into()); } - let host = PathBuf::from(parts[0]); + let host = expand_tilde_path(parts[0]); let guest = PathBuf::from(parts[1]); let read_only = if parts.len() == 3 { match parts[2] { @@ -117,6 +117,19 @@ impl DirectoryShare { } } +fn expand_tilde_path(value: &str) -> PathBuf { + if let Some(stripped) = value.strip_prefix("~/") { + if let Ok(home) = env::var("HOME") { + return PathBuf::from(home).join(stripped); + } + } else if value == "~" { + if let Ok(home) = env::var("HOME") { + return PathBuf::from(home); + } + } + PathBuf::from(value) +} + pub struct VmArg { pub cpu_count: usize, pub ram_bytes: u64, @@ -206,17 +219,6 @@ where ); directory_shares.push(mise_directory_share); - - // Add default shares, if they exist - for share in [ - DirectoryShare::new(home.join(".codex"), "/usr/local/codex".into(), false), - DirectoryShare::new(home.join(".claude"), "/usr/local/claude".into(), false), - ] - .into_iter() - .flatten() - { - directory_shares.push(share) - } } directory_shares.extend(extra_directory_shares); diff --git a/vibebox.toml b/vibebox.toml index 86f0a63..2371ee3 100644 --- a/vibebox.toml +++ b/vibebox.toml @@ -1,7 +1,10 @@ [box] cpu_count = 2 ram_mb = 2048 -mounts = [] +mounts = [ + "~/.codex:/usr/local/codex:read-write", + "~/.claude:/usr/local/claude:read-write", +] [supervisor] auto_shutdown_ms = 20000