feat(tui): load core personality from atproto record at startup
This commit is contained in:
30
src/tui.rs
30
src/tui.rs
@@ -683,20 +683,30 @@ fn load_identity_context() -> String {
|
||||
"[identity]\nuser: {user_handle}\nyou: {bot_handle} ({bot_did})\nnetwork: {network}\n\n"
|
||||
));
|
||||
|
||||
// Recent chat (last 2 entries for context)
|
||||
// Core personality from atproto record
|
||||
let bot_path = config["bot"]["path"].as_str().unwrap_or("");
|
||||
let expanded = expand_tilde(bot_path);
|
||||
let chat_dir = format!(
|
||||
"{}/{}/ai.syui.log.chat",
|
||||
if expanded.is_empty() { format!("{}/ai.syui.log/at", crate::config::config_dir()) } else { expanded.clone() },
|
||||
config["bot"]["did"].as_str().unwrap_or("did")
|
||||
);
|
||||
let base = if expanded.is_empty() {
|
||||
format!("{}/ai.syui.log/at", crate::config::config_dir())
|
||||
} else {
|
||||
expanded.clone()
|
||||
};
|
||||
let core_path = format!("{}/{bot_did}/ai.syui.gpt.core/self.json", base);
|
||||
if let Ok(content) = std::fs::read_to_string(&core_path) {
|
||||
if let Ok(record) = serde_json::from_str::<serde_json::Value>(&content) {
|
||||
if let Some(text) = record["value"]["content"]["text"].as_str() {
|
||||
if !text.is_empty() {
|
||||
let short: String = text.chars().take(500).collect();
|
||||
ctx.push_str(&format!("[core]\n{short}\n\n"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Recent chat (reuse base from core path)
|
||||
let chat_dir = format!("{}/{bot_did}/ai.syui.log.chat", base);
|
||||
let user_did = config["did"].as_str().unwrap_or("");
|
||||
let user_chat_dir = format!("{}/{}/ai.syui.log.chat",
|
||||
if expanded.is_empty() { format!("{}/ai.syui.log/at", crate::config::config_dir()) } else { expanded },
|
||||
user_did
|
||||
);
|
||||
let user_chat_dir = format!("{base}/{user_did}/ai.syui.log.chat");
|
||||
|
||||
for dir in [&chat_dir, &user_chat_dir] {
|
||||
if let Ok(mut entries) = std::fs::read_dir(dir) {
|
||||
|
||||
Reference in New Issue
Block a user