2
0

fix(headless): use bot_data_dir for memory path, add HOME fallback for containers

This commit is contained in:
2026-03-24 17:09:09 +09:00
parent b8649b00f2
commit b478846399
2 changed files with 10 additions and 10 deletions

View File

@@ -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 {

View File

@@ -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 {