on main help sign in
refactor: organize all the params.
commit0d7c4a7c7f8fa196750761e26ade73bf0ae24e83 authorrobcholz <84130577+robcholz@users.noreply.github.com> dateSat 7 Feb 2026, 14:56 (8 months ago) parent87f99f2
5 files changed+49−36
docs/tasks.md+5−1 src/instance.rs+5−5 src/session_manager.rs+20−16 src/vm.rs+12−9 src/vm_manager.rs+7−5
docs/tasks.md+5−1
@@ -43,7 +43,11 @@
43436. [x] VM should be separated by a per-session VM daemon process (only accepts if to shut down vm and itself).
44447. [x] setup vibebox commands
45458. [ ] setup cli commands.
46−9. [ ] fix ui overlap.
46+ 1. [x] Organize all the params.
47+ 2. [ ] Remove old cli.
48+ 3. [ ] add an actual config file.
49+ 4. [ ] set up the cli.
50+9. [ ] fix ui overlap, and consistency issue.
475110. [ ] intensive integration test.
4852
4953## Publish
src/instance.rs+5−5
@@ -20,14 +20,14 @@ use uuid::Uuid;
2020
2121use crate::{
2222 commands,
23− session_manager::{INSTANCE_DIR_NAME, INSTANCE_TOML_FILENAME},
23+ session_manager::{INSTANCE_DIR_NAME, INSTANCE_FILENAME},
2424 tui::AppState,
2525 vm::{self, LoginAction, VmInput},
2626};
2727
2828const SSH_KEY_NAME: &str = "ssh_key";
2929#[allow(dead_code)]
30−const SERIAL_LOG_NAME: &str = "serial.log";
30+pub(crate) const SERIAL_LOG_NAME: &str = "serial.log";
3131const DEFAULT_SSH_USER: &str = "vibecoder";
3232const SSH_CONNECT_RETRIES: usize = 30;
3333const SSH_CONNECT_DELAY_MS: u64 = 500;
@@ -126,7 +126,7 @@ pub(crate) fn ensure_ssh_keypair(
126126pub(crate) fn load_or_create_instance_config(
127127 instance_dir: &Path,
128128) -> Result<InstanceConfig, Box<dyn std::error::Error>> {
129− let config_path = instance_dir.join(INSTANCE_TOML_FILENAME);
129+ let config_path = instance_dir.join(INSTANCE_FILENAME);
130130 let mut config = if config_path.exists() {
131131 let raw = fs::read_to_string(&config_path)?;
132132 toml::from_str::<InstanceConfig>(&raw)?
@@ -167,7 +167,7 @@ pub fn touch_last_active(instance_dir: &Path) -> Result<(), Box<dyn std::error::
167167 let mut config = load_or_create_instance_config(instance_dir)?;
168168 let now = OffsetDateTime::now_utc().format(&Rfc3339)?;
169169 config.last_active = Some(now);
170− write_instance_config(&instance_dir.join(INSTANCE_TOML_FILENAME), &config)?;
170+ write_instance_config(&instance_dir.join(INSTANCE_FILENAME), &config)?;
171171 Ok(())
172172}
173173
@@ -379,7 +379,7 @@ fn spawn_ssh_io(
379379 let ssh_ready = Arc::new(AtomicBool::new(false));
380380 let input_tx_holder: Arc<Mutex<Option<Sender<VmInput>>>> = Arc::new(Mutex::new(None));
381381
382− let instance_path = instance_dir.join(INSTANCE_TOML_FILENAME);
382+ let instance_path = instance_dir.join(INSTANCE_FILENAME);
383383 let config_for_output = config.clone();
384384 let log_for_output = log_file.clone();
385385 let ssh_connected_for_output = ssh_connected.clone();
src/session_manager.rs+20−16
@@ -11,8 +11,7 @@ use crate::config::CONFIG_FILENAME;
1111pub const INSTANCE_DIR_NAME: &str = ".vibebox";
1212pub const GLOBAL_CACHE_DIR_NAME: &str = "vibebox";
1313pub const GLOBAL_DIR_NAME: &str = ".vibebox";
14−pub const INSTANCE_TOML_FILENAME: &str = "instance.toml";
15−pub const SESSION_TEMP_PREFIX: &str = "sessions";
14+pub const INSTANCE_FILENAME: &str = "instance.toml";
1615pub const SESSION_TOML_SUFFIX: &str = ".toml";
1716const SESSIONS_DIR_NAME: &str = "sessions";
1817
@@ -100,7 +99,8 @@ impl SessionManager {
10099 } else {
101100 tracing::warn!(
102101 directory = %directory.display(),
103− "missing session id in instance.toml"
102+ file = INSTANCE_FILENAME,
103+ "missing session id in instance file"
104104 );
105105 }
106106 }
@@ -158,7 +158,7 @@ impl SessionManager {
158158 }
159159
160160 fn session_path_for(&self, id: &str) -> PathBuf {
161− let filename = format!("{id}.toml");
161+ let filename = format!("{id}{SESSION_TOML_SUFFIX}");
162162 self.sessions_dir.join(filename)
163163 }
164164
@@ -225,9 +225,7 @@ fn read_session_file(path: &Path) -> Result<SessionEntry, SessionError> {
225225}
226226
227227fn read_instance_metadata(directory: &Path) -> Result<InstanceMetadata, SessionError> {
228− let instance_path = directory
229− .join(INSTANCE_DIR_NAME)
230− .join(INSTANCE_TOML_FILENAME);
228+ let instance_path = directory.join(INSTANCE_DIR_NAME).join(INSTANCE_FILENAME);
231229 if !instance_path.exists() {
232230 return Ok(InstanceMetadata::default());
233231 }
@@ -256,7 +254,7 @@ fn atomic_write(path: &Path, content: &[u8]) -> io::Result<()> {
256254
257255 fs::create_dir_all(parent)?;
258256 let mut temp = tempfile::Builder::new()
259− .prefix(SESSION_TEMP_PREFIX)
257+ .prefix(SESSIONS_DIR_NAME)
260258 .suffix(SESSION_TOML_SUFFIX)
261259 .tempfile_in(parent)?;
262260 temp.write_all(content)?;
@@ -285,7 +283,7 @@ mod tests {
285283 let instance_dir = project_dir.join(INSTANCE_DIR_NAME);
286284 fs::create_dir_all(&instance_dir).unwrap();
287285 let content = format!("id = \"{id}\"\nlast_active = \"{last_active}\"\n");
288− fs::write(instance_dir.join(INSTANCE_TOML_FILENAME), content).unwrap();
286+ fs::write(instance_dir.join(INSTANCE_FILENAME), content).unwrap();
289287 }
290288
291289 #[test]
@@ -306,9 +304,10 @@ mod tests {
306304 assert_eq!(dirs[0], project_dir.canonicalize().unwrap());
307305 assert!(mgr.index_path().exists());
308306
309− let session_path = mgr
310− .index_path()
311− .join("019bf290-cccc-7c23-ba1d-dce7e6d40693.toml");
307+ let session_path = mgr.index_path().join(format!(
308+ "019bf290-cccc-7c23-ba1d-dce7e6d40693{}",
309+ SESSION_TOML_SUFFIX
310+ ));
312311 assert!(session_path.exists());
313312 }
314313
@@ -329,9 +328,10 @@ mod tests {
329328 let sessions = mgr.list_sessions().unwrap();
330329 assert!(sessions.is_empty());
331330
332− let session_path = mgr
333− .index_path()
334− .join("019bf290-cccc-7c23-ba1d-dce7e6d40693.toml");
331+ let session_path = mgr.index_path().join(format!(
332+ "019bf290-cccc-7c23-ba1d-dce7e6d40693{}",
333+ SESSION_TOML_SUFFIX
334+ ));
335335 assert!(!session_path.exists());
336336 }
337337
@@ -340,7 +340,11 @@ mod tests {
340340 let temp = TempDir::new().unwrap();
341341 let mgr = manager(&temp);
342342 fs::create_dir_all(mgr.index_path()).unwrap();
343− fs::write(mgr.index_path().join("bad.toml"), "not toml").unwrap();
343+ fs::write(
344+ mgr.index_path().join(format!("bad{SESSION_TOML_SUFFIX}")),
345+ "not toml",
346+ )
347+ .unwrap();
344348
345349 let err = mgr.list_sessions().unwrap_err();
346350 assert!(matches!(err, SessionError::TomlDe(_)));
src/vm.rs+12−9
@@ -43,6 +43,10 @@ const START_TIMEOUT: Duration = Duration::from_secs(60);
4343const DEFAULT_EXPECT_TIMEOUT: Duration = Duration::from_secs(30);
4444const LOGIN_EXPECT_TIMEOUT: Duration = Duration::from_secs(120);
4545const PROVISION_SCRIPT: &str = include_str!("provision.sh");
46+const PROVISION_SCRIPT_NAME: &str = "provision.sh";
47+const DEFAULT_RAW_NAME: &str = "default.raw";
48+const INSTANCE_RAW_NAME: &str = "instance.raw";
49+const BASE_DISK_RAW_NAME: &str = "disk.raw";
4650
4751#[derive(Clone)]
4852pub(crate) enum LoginAction {
@@ -158,8 +162,8 @@ where
158162 basename_compressed.trim_end_matches(".tar.xz")
159163 ));
160164
161− let default_raw = cache_dir.join("default.raw");
162− let instance_raw = instance_dir.join("instance.raw");
165+ let default_raw = cache_dir.join(DEFAULT_RAW_NAME);
166+ let instance_raw = instance_dir.join(INSTANCE_RAW_NAME);
163167
164168 // Prepare system-wide directories
165169 fs::create_dir_all(&cache_dir)?;
@@ -212,11 +216,6 @@ where
212216 for share in [
213217 DirectoryShare::new(home.join(".codex"), "/usr/local/codex".into(), false),
214218 DirectoryShare::new(home.join(".claude"), "/usr/local/claude".into(), false),
215− DirectoryShare::new(
216− "/Users/zhangjie/Documents/Code/CompletePrograms/vibebox/.ssh".into(),
217− "/usr/local/ssh".into(),
218− true,
219− ),
220219 ]
221220 .into_iter()
222221 .flatten()
@@ -629,7 +628,11 @@ fn ensure_base_image(
629628
630629 println!("Decompressing base image...");
631630 let status = Command::new("tar")
632− .args(["-xOf", &base_compressed.to_string_lossy(), "disk.raw"])
631+ .args([
632+ "-xOf",
633+ &base_compressed.to_string_lossy(),
634+ BASE_DISK_RAW_NAME,
635+ ])
633636 .stdout(std::fs::File::create(base_raw)?)
634637 .status()?;
635638
@@ -655,7 +658,7 @@ fn ensure_default_image(
655658 println!("Configuring base image...");
656659 fs::copy(base_raw, default_raw)?;
657660
658− let provision_command = script_command_from_content("provision.sh", PROVISION_SCRIPT)?;
661+ let provision_command = script_command_from_content(PROVISION_SCRIPT_NAME, PROVISION_SCRIPT)?;
659662 run_vm(
660663 default_raw,
661664 &[Send(provision_command)],
src/vm_manager.rs+7−5
@@ -15,16 +15,18 @@ use std::{
1515};
1616
1717use crate::{
18+ instance::SERIAL_LOG_NAME,
1819 instance::{
1920 InstanceConfig, build_ssh_login_actions, ensure_instance_dir, ensure_ssh_keypair,
2021 extract_ipv4, load_or_create_instance_config, write_instance_config,
2122 },
22− session_manager::GLOBAL_DIR_NAME,
23+ session_manager::{GLOBAL_DIR_NAME, INSTANCE_FILENAME},
2324 vm::{self, DirectoryShare, LoginAction, VmInput},
2425};
2526
2627const VM_MANAGER_SOCKET_NAME: &str = "vm.sock";
2728const VM_MANAGER_LOCK_NAME: &str = "vm.lock";
29+const VM_MANAGER_LOG_NAME: &str = "vm_manager.log";
2830
2931pub fn ensure_manager(
3032 raw_args: &[std::ffi::OsString],
@@ -132,7 +134,7 @@ fn spawn_manager_process(
132134 cmd.env("VIBEBOX_LOG_NO_COLOR", "1");
133135 cmd.env("VIBEBOX_AUTO_SHUTDOWN_MS", auto_shutdown_ms.to_string());
134136 tracing::info!(auto_shutdown_ms, "vm manager process spawn requested");
135− let log_path = instance_dir.join("vm_manager.log");
137+ let log_path = instance_dir.join(VM_MANAGER_LOG_NAME);
136138 let log_file = fs::OpenOptions::new()
137139 .create(true)
138140 .write(true)
@@ -280,7 +282,7 @@ fn spawn_manager_io(
280282 vm_output_fd: std::os::unix::io::OwnedFd,
281283 vm_input_fd: std::os::unix::io::OwnedFd,
282284) -> vm::IoContext {
283− let log_path = instance_dir.join("serial.log");
285+ let log_path = instance_dir.join(SERIAL_LOG_NAME);
284286 let log_file = fs::OpenOptions::new()
285287 .create(true)
286288 .write(true)
@@ -289,7 +291,7 @@ fn spawn_manager_io(
289291 .ok()
290292 .map(|file| Arc::new(Mutex::new(file)));
291293
292− let instance_path = instance_dir.join("instance.toml");
294+ let instance_path = instance_dir.join(INSTANCE_FILENAME);
293295 let config_for_output = config.clone();
294296 let log_for_output = log_file.clone();
295297 let mut line_buf = String::new();
@@ -465,7 +467,7 @@ fn run_manager_with(
465467 let mut config = load_or_create_instance_config(&instance_dir)?;
466468 if config.vm_ipv4.is_some() {
467469 config.vm_ipv4 = None;
468− write_instance_config(&instance_dir.join("instance.toml"), &config)?;
470+ write_instance_config(&instance_dir.join(INSTANCE_FILENAME), &config)?;
469471 }
470472 let config = Arc::new(Mutex::new(config));
471473