use std::path::PathBuf;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct WorkspaceRegistry {
#[serde(default)]
pub frontiers: Vec<RegisteredFrontier>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RegisteredFrontier {
pub path: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
pub registered_at: String,
}
fn registry_path() -> Option<PathBuf> {
dirs_home().map(|h| h.join(".vela").join("frontiers.json"))
}
fn dirs_home() -> Option<PathBuf> {
std::env::var_os("HOME").map(PathBuf::from)
}
pub fn load() -> WorkspaceRegistry {
let Some(path) = registry_path() else {
return WorkspaceRegistry::default();
};
std::fs::read_to_string(path)
.ok()
.and_then(|raw| serde_json::from_str(&raw).ok())
.unwrap_or_default()
}
pub fn live_frontiers() -> Vec<PathBuf> {
load()
.frontiers
.iter()
.map(|f| PathBuf::from(&f.path))
.filter(|p| p.join(".vela").is_dir())
.collect()
}