LLM Wiki is a cross-platform desktop application that turns your documents into an organized, interlinked knowledge base — automatically. Instead of traditional RAG (retrieve-and-answer from scratch every time), the LLM incrementally builds and maintains a persistent wiki from your sources。
TypeScript
perf: defer heavy project startup hydration
nash_suf1f37377c033
diff --git a/src-tauri/src/commands/fs.rs b/src-tauri/src/commands/fs.rsindex 4ea8bbb8..324ca520 100644--- a/src-tauri/src/commands/fs.rs+++ b/src-tauri/src/commands/fs.rs@@ -1076,8 +1076,10 @@ fn entry_is_visible(name: &str, include_hidden: bool) -> bool {pub async fn list_directory(path: String,include_hidden: Option<bool>,+ max_depth: Option<usize>,) -> Result<Vec<FileNode>, String> {let include_hidden = include_hidden.unwrap_or(false);+ let max_depth = max_depth.unwrap_or(30).clamp(1, 30);tauri::async_runtime::spawn_blocking(move || {run_guarded("list_directory", || {let p = Path::new(&path);@@ -1087,7 +1089,7 @@ pub async fn list_directory(if !p.is_dir() {return Err(format!("Path is not a directory: '{}'", path));}- let nodes = build_tree(p, 0, 30, include_hidden)?;+ let nodes = build_tree(p, 0, max_depth, include_hidden)?;Ok(nodes)})})@@ -2076,6 +2078,30 @@ mod tests {let _ = fs::remove_dir_all(root);}+ #[test]+ fn build_tree_respects_max_depth_for_shallow_listing() {+ let root = make_temp_dir("build-tree-depth");+ fs::create_dir_all(root.join("a/b")).unwrap();+ fs::write(root.join("a/b/deep.md"), "x").unwrap();++ let shallow = build_tree(&root, 0, 1, false).unwrap();+ let a = shallow.iter().find(|n| n.name == "a").unwrap();+ assert!(a.is_dir);+ assert!(a.children.is_none(), "max_depth=1 must not load grandchildren");++ let deeper = build_tree(&root, 0, 3, false).unwrap();+ let a = deeper.iter().find(|n| n.name == "a").unwrap();+ let b = a+ .children+ .as_ref()+ .and_then(|children| children.iter().find(|n| n.name == "b"))+ .expect("max_depth=3 should include nested directory");+ let files = b.children.as_ref().expect("b should include deep file");+ assert!(files.iter().any(|n| n.name == "deep.md"));++ let _ = fs::remove_dir_all(root);+ }+#[test]fn reject_relative_write_paths_before_touching_cwd() {assert!(require_absolute_path("write_file", "wiki/sources/stray.md").is_err());diff --git a/src/App.tsx b/src/App.tsxindex e151aa6b..0d9b1575 100644--- a/src/App.tsx+++ b/src/App.tsx@@ -8,7 +8,7 @@ import { useReviewStore } from "@/stores/review-store"import { useLintStore } from "@/stores/lint-store"import { useChatStore } from "@/stores/chat-store"import { BASE_FONT_SIZE_PX, useZoomStore } from "@/stores/zoom-store"-import { listDirectory, openProject } from "@/commands/fs"+import { openProject } from "@/commands/fs"import { getLastProject, getRecentProjects, saveLastProject, loadLlmConfig, loadLanguage, loadSearchApiConfig, loadEmbeddingConfig, loadMineruConfig, loadMultimodalConfig, loadOutputLanguage, loadProviderConfigs, loadActivePresetId, loadProxyConfig, loadScheduledImportConfig, saveScheduledImportConfig, loadSourceWatchConfig, loadApiConfig, loadGeneralConfig, loadZoomLevel } from "@/lib/project-store"import { loadReviewItems, loadLintItems, loadChatHistory, loadChatPreferences } from "@/lib/persist"import { setupAutoSave } from "@/lib/auto-save"@@ -32,6 +32,46 @@ function App() {const [showCreateDialog, setShowCreateDialog] = useState(false)const [loading, setLoading] = useState(true)+ function isCurrentProject(proj: WikiProject): boolean {+ const current = useWikiStore.getState().project+ return current?.id === proj.id && current.path === proj.path+ }++ async function hydrateProjectSideStores(proj: WikiProject): Promise<void> {+ try {+ const savedReview = await loadReviewItems(proj.path)+ if (savedReview.length > 0 && isCurrentProject(proj)) {+ useReviewStore.getState().setItems(savedReview)+ }+ } catch (err) {+ console.warn("[startup] failed to load review items:", err)+ }++ try {+ const savedLint = await loadLintItems(proj.path)+ if (savedLint.length > 0 && isCurrentProject(proj)) {+ useLintStore.getState().setItems(savedLint)+ }+ } catch (err) {+ console.warn("[startup] failed to load lint items:", err)+ }++ try {+ const savedChat = await loadChatHistory(proj.path)+ if (!isCurrentProject(proj)) return+ if (savedChat.conversations.length > 0) {+ useChatStore.getState().setConversations(savedChat.conversations)+ useChatStore.getState().setMessages(savedChat.messages)+ const sorted = [...savedChat.conversations].sort((a, b) => b.updatedAt - a.updatedAt)+ if (sorted[0]) {+ useChatStore.getState().setActiveConversation(sorted[0].id)+ }+ }+ } catch (err) {+ console.warn("[startup] failed to load chat history:", err)+ }+ }+// Set up auto-save and clip watcher once on mountuseEffect(() => {setupAutoSave()@@ -324,6 +364,7 @@ function App() {const projectOutputLang = await loadOutputLanguage(proj.id)useWikiStore.getState().setOutputLanguage(projectOutputLang ?? "auto")setSelectedFile(null)+ setFileTree([])setActiveView("wiki")// Bump data version so any cached graphs/views invalidateuseWikiStore.getState().bumpDataVersion()@@ -409,45 +450,14 @@ function App() {body: JSON.stringify({ projects }),}).catch(() => {})}).catch(() => {})- try {- const tree = await listDirectory(proj.path)- setFileTree(tree)- } catch (err) {- console.error("Failed to load file tree:", err)- }- // Load persisted review items- try {- const savedReview = await loadReviewItems(proj.path)- if (savedReview.length > 0) {- useReviewStore.getState().setItems(savedReview)- }- } catch {- // ignore, start fresh- }- // Load persisted lint items- useLintStore.getState().setItems([])- try {- const savedLint = await loadLintItems(proj.path)- useLintStore.getState().setItems(savedLint)- } catch {- useLintStore.getState().setItems([])- }- // Load persisted chat history+ // Load lightweight chat preferences before first paint so the chat+ // controls reflect the user's saved tool toggles. The heavier per-+ // conversation history load is deferred below.try {const savedChatPreferences = await loadChatPreferences(proj.path)useChatStore.getState().setUseWebSearch(savedChatPreferences.useWebSearch)useChatStore.getState().setUseAnyTxtSearch(savedChatPreferences.useAnyTxtSearch)useChatStore.getState().setAgentMode(savedChatPreferences.agentMode)- const savedChat = await loadChatHistory(proj.path)- if (savedChat.conversations.length > 0) {- useChatStore.getState().setConversations(savedChat.conversations)- useChatStore.getState().setMessages(savedChat.messages)- // Set most recent conversation as active- const sorted = [...savedChat.conversations].sort((a, b) => b.updatedAt - a.updatedAt)- if (sorted[0]) {- useChatStore.getState().setActiveConversation(sorted[0].id)- }- }} catch {// ignore, start fresh}@@ -459,6 +469,10 @@ function App() {setFileTree([])setSelectedFile(null)})+ // Heavy side-store hydration happens after the project shell is allowed+ // to render. Each write has a stale-project guard so a fast project switch+ // cannot apply old review/lint/chat state to the new project.+ void hydrateProjectSideStores(proj)}async function handleSelectRecent(proj: WikiProject) {diff --git a/src/commands/fs.ts b/src/commands/fs.tsindex 2eefe6b1..a5031f14 100644--- a/src/commands/fs.ts+++ b/src/commands/fs.ts@@ -40,11 +40,24 @@ export async function writeFileAtomic(path: string, contents: string): Promise<v* only for the `raw/sources` content area, where dotfolders are* legitimate user-added sources. See `entry_is_visible` in fs.rs.*/+export interface ListDirectoryOptions {+ includeHidden?: boolean+ maxDepth?: number+}+export async function listDirectory(path: string,- includeHidden = false,+ includeHiddenOrOptions: boolean | ListDirectoryOptions = false,): Promise<FileNode[]> {- return invoke<FileNode[]>("list_directory", { path, includeHidden })+ const options =+ typeof includeHiddenOrOptions === "boolean"+ ? { includeHidden: includeHiddenOrOptions }+ : includeHiddenOrOptions+ return invoke<FileNode[]>("list_directory", {+ path,+ includeHidden: options.includeHidden,+ maxDepth: options.maxDepth,+ })}export async function copyFile(diff --git a/src/lib/reset-project-state.ts b/src/lib/reset-project-state.tsindex d94b2fd5..75b0b876 100644--- a/src/lib/reset-project-state.ts+++ b/src/lib/reset-project-state.ts@@ -10,6 +10,7 @@import { useChatStore } from "@/stores/chat-store"import { useReviewStore } from "@/stores/review-store"+import { useLintStore } from "@/stores/lint-store"import { useActivityStore } from "@/stores/activity-store"import { useResearchStore } from "@/stores/research-store"@@ -32,6 +33,10 @@ export async function resetProjectState(): Promise<void> {items: [],})+ useLintStore.setState({+ items: [],+ })+useActivityStore.setState({items: [],})