use std::path::{Path, PathBuf};
use crate::cli::output::{print_blank_line, print_field, print_heading, print_info, print_success};
use crate::cli::prompts::{prompt_confirm, prompt_project_name, prompt_store_path_default};
use crate::config::{Config, ConfigDraft};
use crate::error::Result;
use crate::types::{ProjectName, StorePath};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct OnboardingResult {
pub config: Config,
pub config_path: PathBuf,
}
pub fn run_onboarding() -> Result<OnboardingResult> {
let cwd = std::env::current_dir()?;
run_onboarding_in(&cwd)
}
pub fn run_onboarding_in(project_root: &Path) -> Result<OnboardingResult> {
print_heading("Agent Memory Setup");
print_info("Create a local project memory store.");
print_blank_line();
let project_name = prompt_project_name()?;
let default_store = Config::project_store_path(project_root);
let store_path = prompt_store_path_default(default_store)?;
let draft = ConfigDraft::new(project_name.clone(), store_path.clone());
print_blank_line();
preview(&project_name, &store_path, project_root);
let confirmed = prompt_confirm("Create configuration now?", true)?;
if !confirmed {
return Err(crate::error::AgentMemoryError::internal(
"onboarding cancelled by user",
));
}
let config = draft.finalize()?;
let config_path = Config::project_config_path(project_root);
config.save(&config_path)?;
print_blank_line();
print_success("Configuration created.");
print_field("Config file", &config_path.display().to_string());
print_field("Store file", &store_path.to_string());
Ok(OnboardingResult {
config,
config_path,
})
}
fn preview(project_name: &ProjectName, store_path: &StorePath, project_root: &Path) {
let config_path = Config::project_config_path(project_root);
print_heading("Preview");
print_field("Project", project_name.as_str());
print_field("Config file", &config_path.display().to_string());
print_field("Store file", &store_path.to_string());
}