补齐DirectProject历史完成项锚点

Thread Manager订阅在内存锚点为空时读取持久化最后item ID\n保持重启恢复与历史懒加载锚点一致
This commit is contained in:
2026-09-15 18:04:01 +08:00
committed by kdletters
parent bd0c499773
commit 9cd43b2ce8
2 changed files with 18 additions and 2 deletions
@@ -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<Option<String>, 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<LocalConversationResult, String> {
@@ -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]