From b478846399a1a06ba38751e5a953e2bd638ab46a Mon Sep 17 00:00:00 2001 From: syui Date: Tue, 24 Mar 2026 17:09:09 +0900 Subject: [PATCH] fix(headless): use bot_data_dir for memory path, add HOME fallback for containers --- src/config.rs | 4 ++-- src/headless.rs | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/config.rs b/src/config.rs index 75118c5..986efb7 100644 --- a/src/config.rs +++ b/src/config.rs @@ -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 { diff --git a/src/headless.rs b/src/headless.rs index 0e838ab..62a42f6 100644 --- a/src/headless.rs +++ b/src/headless.rs @@ -575,14 +575,14 @@ fn save_to_aigpt_memory(decision: &str, agents: &[serde_json::Value]) { } fn aigpt_memory_dir() -> Option { - 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 {