diff --git a/desktop/src-tauri/src/kernel_commands/agent.rs b/desktop/src-tauri/src/kernel_commands/agent.rs index 01fcd7d..5aacd74 100644 --- a/desktop/src-tauri/src/kernel_commands/agent.rs +++ b/desktop/src-tauri/src/kernel_commands/agent.rs @@ -7,7 +7,7 @@ use zclaw_types::{AgentConfig, AgentId, AgentInfo}; use super::{validate_agent_id, KernelState}; use crate::intelligence::validation::validate_string_length; -use crate::intelligence::identity::IdentityManagerState; +use crate::intelligence::identity::{IdentityFile, IdentityManagerState}; // --------------------------------------------------------------------------- // Request / Response types @@ -235,6 +235,7 @@ pub async fn agent_delete( #[tauri::command] pub async fn agent_update( state: State<'_, KernelState>, + identity_state: State<'_, IdentityManagerState>, agent_id: String, updates: AgentUpdateRequest, ) -> Result { @@ -253,6 +254,20 @@ pub async fn agent_update( // Apply updates if let Some(name) = updates.name { + // Sync name to identity soul so next session's system prompt includes it + let mut identity_mgr = identity_state.lock().await; + let current_soul = identity_mgr.get_file(&agent_id, IdentityFile::Soul); + let updated_soul = if current_soul.is_empty() { + format!("# ZCLAW 人格\n\n你的名字是{}。\n\n你是一个成长性的中文 AI 助手。", name) + } else if current_soul.contains("你的名字是") { + let re = regex::Regex::new(r"你的名字是[^\n]+").unwrap(); + re.replace(¤t_soul, format!("你的名字是{}", name)).to_string() + } else { + format!("你的名字是{}。\n\n{}", name, current_soul) + }; + let _ = identity_mgr.update_file(&agent_id, "soul", &updated_soul); + drop(identity_mgr); + config.name = name; } if let Some(description) = updates.description {