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