diff --git a/apps/ai-game-creator-shell/src-tauri/src/agent/direct_project_history.rs b/apps/ai-game-creator-shell/src-tauri/src/agent/direct_project_history.rs index 2f3a6f62c..24b3aed74 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/agent/direct_project_history.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/agent/direct_project_history.rs @@ -530,6 +530,18 @@ pub(crate) fn read_direct_project_history_items_slice_at( Ok((items[start..end].to_vec(), start > 0)) } +pub(crate) fn read_direct_project_last_item_id_at(root: &Path) -> Result, String> { + Ok(read_direct_project_history_items_at(root)? + .into_iter() + .rev() + .find_map(|item| { + item.get("id") + .and_then(Value::as_str) + .filter(|id| !id.is_empty()) + .map(str::to_string) + })) +} + pub(crate) fn read_direct_project_chat_history_at( root: &Path, ) -> Result { diff --git a/apps/ai-game-creator-shell/src-tauri/src/commands.rs b/apps/ai-game-creator-shell/src-tauri/src/commands.rs index 0ca57dc67..b70b8c6d7 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/commands.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/commands.rs @@ -1,5 +1,5 @@ use super::*; -use crate::agent::read_direct_project_chat_history_at; +use crate::agent::{read_direct_project_chat_history_at, read_direct_project_last_item_id_at}; use crate::ui_editor::resource::font::FontAsset; use sha2::{Digest, Sha256}; use std::collections::{BTreeMap, HashSet}; @@ -5282,7 +5282,11 @@ pub(crate) fn subscribe_direct_project_thread( let root = Path::new(project_path.trim()); enforce_project_permission_policy(root, "conversation.read")?; let thread_id = root.to_string_lossy().into_owned(); - Ok(subscribe_direct_thread(&thread_id)) + let mut bootstrap = subscribe_direct_thread(&thread_id); + if bootstrap.last_completed_item_id.is_none() { + bootstrap.last_completed_item_id = read_direct_project_last_item_id_at(root)?; + } + Ok(bootstrap) } #[tauri::command]