Skip to main content

pixie_pi/
config.rs

1//! Configuration paths and environment variables.
2
3use std::path::{Path, PathBuf};
4
5use crate::tools::util::expand_tilde;
6
7/// Resolve the agent config directory (~/.config/pixie-pi/agent or `$PIXIE_PI_AGENT_DIR`).
8pub fn agent_dir() -> PathBuf {
9    if let Ok(env) = std::env::var("PIXIE_PI_AGENT_DIR") {
10        if !env.is_empty() {
11            return expand_tilde(&env);
12        }
13    }
14    let base = dirs::config_dir()
15        .or_else(dirs::home_dir)
16        .unwrap_or_else(|| PathBuf::from("."));
17    base.join("pixie-pi").join("agent")
18}
19
20/// A short, stable directory name for a project (cwd). Mirrors pi's per-project
21/// session grouping.
22pub fn project_session_dir(cwd: &Path) -> PathBuf {
23    use std::collections::hash_map::DefaultHasher;
24    use std::hash::{Hash, Hasher};
25    let abs = std::fs::canonicalize(cwd).unwrap_or_else(|_| cwd.to_path_buf());
26    let mut hasher = DefaultHasher::new();
27    abs.hash(&mut hasher);
28    let hash = format!("{:016x}", hasher.finish());
29    agent_dir().join("sessions").join(format!("--{hash}--"))
30}
31
32/// Path to the active session JSONL file for a project.
33pub fn session_file(cwd: &Path) -> PathBuf {
34    project_session_dir(cwd).join("session.jsonl")
35}