From 518ca14fd3cbc03857f493edac874e624acdf971 Mon Sep 17 00:00:00 2001 From: robcholz <84130577+robcholz@users.noreply.github.com> Date: Sat, 7 Feb 2026 17:12:09 -0500 Subject: [PATCH] fix: removed the hardcode codex and claude form ssh.sh --- src/config.rs | 4 ++-- src/explain.rs | 40 ++++++++++++++++++++++++++++++++++------ src/instance.rs | 11 ++++++++++- src/ssh.sh | 9 --------- vibebox.toml | 4 ++-- 5 files changed, 48 insertions(+), 20 deletions(-) diff --git a/src/config.rs b/src/config.rs index 9455a3e..632f6a6 100644 --- a/src/config.rs +++ b/src/config.rs @@ -81,11 +81,11 @@ fn default_mounts() -> Vec { 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()); + mounts.push("~/.codex:/home/vibecoder/.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.push("~/.claude:/home/vibecoder/.claude:read-write".to_string()); } mounts } diff --git a/src/explain.rs b/src/explain.rs index eb1068b..7a6e1e8 100644 --- a/src/explain.rs +++ b/src/explain.rs @@ -12,8 +12,9 @@ pub fn build_mount_rows( ) -> Result, Box> { let mut rows = Vec::new(); rows.extend(default_mounts(cwd)?); + let guest_home = resolve_guest_home(cwd)?; for spec in &config.box_cfg.mounts { - rows.push(parse_mount_spec(cwd, spec, false)?); + rows.push(parse_mount_spec(cwd, spec, false, &guest_home)?); } Ok(rows) } @@ -75,6 +76,7 @@ fn parse_mount_spec( cwd: &Path, spec: &str, default_mount: bool, + guest_home: &str, ) -> Result> { let parts: Vec<&str> = spec.split(':').collect(); if parts.len() < 2 || parts.len() > 3 { @@ -99,11 +101,7 @@ fn parse_mount_spec( }; let host_display = display_host_spec(cwd, host_part); - let guest_display = if Path::new(guest_part).is_absolute() { - guest_part.to_string() - } else { - format!("/root/{guest_part}") - }; + let guest_display = resolve_guest_display(guest_part, guest_home); Ok(tui::MountListRow { host: host_display, guest: guest_display, @@ -128,6 +126,36 @@ fn display_host_spec(cwd: &Path, host: &str) -> String { } } +fn resolve_guest_home(cwd: &Path) -> Result> { + let instance_dir = cwd.join(session_manager::INSTANCE_DIR_NAME); + if let Ok(Some(user)) = instance::read_instance_ssh_user(&instance_dir) { + return Ok(format!("/home/{user}")); + } + Ok(format!("/home/{}", instance::DEFAULT_SSH_USER)) +} + +fn resolve_guest_display(guest: &str, guest_home: &str) -> String { + if guest == "~" { + return "~".to_string(); + } + if let Some(stripped) = guest.strip_prefix("~/") { + return format!("~/{stripped}"); + } + if Path::new(guest).is_absolute() { + if let Ok(stripped) = Path::new(guest).strip_prefix(guest_home) { + if stripped.components().next().is_none() { + "~".to_string() + } else { + format!("~/{}", stripped.display()) + } + } else { + guest.to_string() + } + } else { + format!("/root/{guest}") + } +} + fn display_path(path: &Path) -> String { let Ok(home) = env::var("HOME") else { return path.display().to_string(); diff --git a/src/instance.rs b/src/instance.rs index db2e03c..34f9c97 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -27,7 +27,7 @@ use crate::{ const SSH_KEY_NAME: &str = "ssh_key"; pub(crate) const SERIAL_LOG_NAME: &str = "serial.log"; -const DEFAULT_SSH_USER: &str = "vibecoder"; +pub(crate) const DEFAULT_SSH_USER: &str = "vibecoder"; const SSH_CONNECT_RETRIES: usize = 30; const SSH_CONNECT_DELAY_MS: u64 = 500; const SSH_SETUP_SCRIPT: &str = include_str!("ssh.sh"); @@ -181,6 +181,15 @@ pub fn read_instance_vm_ip( Ok(config.and_then(|cfg| cfg.vm_ipv4)) } +pub fn read_instance_ssh_user( + instance_dir: &Path, +) -> Result, Box> { + let config = read_instance_config(instance_dir)?; + Ok(config + .map(|cfg| cfg.ssh_user) + .filter(|user| !user.trim().is_empty())) +} + pub fn touch_last_active(instance_dir: &Path) -> Result<(), Box> { let mut config = load_or_create_instance_config(instance_dir)?; let now = OffsetDateTime::now_utc().format(&Rfc3339)?; diff --git a/src/ssh.sh b/src/ssh.sh index 6492cf3..40ee6ea 100644 --- a/src/ssh.sh +++ b/src/ssh.sh @@ -63,19 +63,10 @@ fi install -d -m 700 -o "$SSH_USER" -g "$SSH_USER" "/home/${SSH_USER}/.ssh" install -m 600 -o "$SSH_USER" -g "$SSH_USER" "$KEY_PATH" "/home/${SSH_USER}/.ssh/authorized_keys" -# Ensure codex/claude are visible in the user's HOME USER_HOME="$(getent passwd "$SSH_USER" | cut -d: -f6 2>/dev/null || true)" if [ -z "$USER_HOME" ]; then USER_HOME="/home/${SSH_USER}" fi -install -d -m 755 /usr/local/codex /usr/local/claude -if [ ! -e "${USER_HOME}/.codex" ]; then - ln -s /usr/local/codex "${USER_HOME}/.codex" -fi -if [ ! -e "${USER_HOME}/.claude" ]; then - ln -s /usr/local/claude "${USER_HOME}/.claude" -fi -chown -h "${SSH_USER}:${SSH_USER}" "${USER_HOME}/.codex" "${USER_HOME}/.claude" 2>/dev/null || true # Vibebox shell commands install -d -m 755 /etc/profile.d diff --git a/vibebox.toml b/vibebox.toml index 2371ee3..32cea5d 100644 --- a/vibebox.toml +++ b/vibebox.toml @@ -2,8 +2,8 @@ cpu_count = 2 ram_mb = 2048 mounts = [ - "~/.codex:/usr/local/codex:read-write", - "~/.claude:/usr/local/claude:read-write", + "~/.codex:~/.codex:read-write", + "~/.claude:~/.claude:read-write", ] [supervisor]