fix(headless): use bot_data_dir for memory path, add HOME fallback for containers
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
use serde::Deserialize;
|
||||
use std::path::Path;
|
||||
|
||||
/// OS standard config directory.
|
||||
/// OS standard config directory. Matches dirs::config_dir() behavior.
|
||||
pub fn config_dir() -> String {
|
||||
let home = std::env::var("HOME").unwrap_or_default();
|
||||
let home = std::env::var("HOME").unwrap_or_else(|_| "/root".to_string());
|
||||
if cfg!(target_os = "macos") {
|
||||
format!("{home}/Library/Application Support")
|
||||
} else {
|
||||
|
||||
@@ -575,14 +575,14 @@ fn save_to_aigpt_memory(decision: &str, agents: &[serde_json::Value]) {
|
||||
}
|
||||
|
||||
fn aigpt_memory_dir() -> Option<String> {
|
||||
let config_path = config::config_path();
|
||||
let content = std::fs::read_to_string(&config_path).ok()?;
|
||||
let config: serde_json::Value = serde_json::from_str(&content).ok()?;
|
||||
|
||||
let path = config["bot"]["path"].as_str()?;
|
||||
let did = config["bot"]["did"].as_str()?;
|
||||
let expanded = expand_tilde(path);
|
||||
Some(format!("{expanded}/{did}/ai.syui.gpt.memory"))
|
||||
let base = config::bot_data_dir();
|
||||
let dir = format!("{base}/ai.syui.gpt.memory");
|
||||
if std::path::Path::new(&base).exists() || std::fs::create_dir_all(&dir).is_ok() {
|
||||
Some(dir)
|
||||
} else {
|
||||
eprintln!(" warn: memory dir not available: {dir}");
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn chrono_now() -> String {
|
||||
|
||||
Reference in New Issue
Block a user