From 1c0029001d60bd41f1e8e6b8cb3f49f293774beb Mon Sep 17 00:00:00 2001 From: iven Date: Thu, 23 Apr 2026 14:17:36 +0800 Subject: [PATCH] =?UTF-8?q?fix(identity):=20agent=5Fupdate=20=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E5=86=99=E5=85=A5=20soul.md=20=E2=80=94=20=E8=B7=A8?= =?UTF-8?q?=E4=BC=9A=E8=AF=9D=E5=90=8D=E5=AD=97=E8=AE=B0=E5=BF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit config.name 更新后新会话的 system prompt 看不到名字,因为 pre_conversation_hook 只读 soul.md。现在 agent_update 在 name 变更时同步更新 soul.md(含/替换"你的名字是X"),确保下次 会话的 system prompt 包含身份信息。 --- desktop/src-tauri/src/kernel_commands/agent.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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 {