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
release: v0.5.3 bug fixes
nash_su89a98fdd4283
diff --git a/package-lock.json b/package-lock.jsonindex aa3ec55a..9c337b48 100644--- a/package-lock.json+++ b/package-lock.json@@ -1,12 +1,12 @@{"name": "llm-wiki",- "version": "0.5.2",+ "version": "0.5.3","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "llm-wiki",- "version": "0.5.2",+ "version": "0.5.3","dependencies": {"@base-ui/react": "^1.3.0","@fontsource-variable/geist": "^5.2.8",diff --git a/package.json b/package.jsonindex 15fdc482..76aa2b93 100644--- a/package.json+++ b/package.json@@ -1,7 +1,7 @@{"name": "llm-wiki","private": true,- "version": "0.5.2",+ "version": "0.5.3","type": "module","scripts": {"dev": "vite",diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lockindex 1a271889..ec69274e 100644--- a/src-tauri/Cargo.lock+++ b/src-tauri/Cargo.lock@@ -4461,7 +4461,7 @@ checksum = "11d3d7f243d5c5a8b9bb5d6dd2b1602c0cb0b9db1621bafc7ed66e35ff9fe092"[[package]]name = "llm-wiki"-version = "0.5.2"+version = "0.5.3"dependencies = ["arrow-array","arrow-schema",diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.tomlindex 4a1e14d8..d90ba20b 100644--- a/src-tauri/Cargo.toml+++ b/src-tauri/Cargo.toml@@ -1,6 +1,6 @@[package]name = "llm-wiki"-version = "0.5.2"+version = "0.5.3"description = "LLM Wiki - A personal knowledge base for LLM concepts"authors = []edition = "2021"diff --git a/src-tauri/src/api_server.rs b/src-tauri/src/api_server.rsindex ee6935ba..90f74005 100644--- a/src-tauri/src/api_server.rs+++ b/src-tauri/src/api_server.rs@@ -1036,13 +1036,22 @@ fn normalize_review_title(title: &str) -> String {"重复页面","疑似重复",] {- if lower.starts_with(prefix) {- rest = &trimmed[prefix.len()..];- rest = rest.trim_start_matches(|ch: char| ch == ':' || ch == ':' || ch.is_whitespace());+ if !lower.starts_with(prefix) {+ continue;+ }+ let suffix = &trimmed[prefix.len()..];+ let Some(delimiter) = suffix.chars().next() else {+ continue;+ };+ if delimiter == ':' || delimiter == ':' {+ rest = suffix[delimiter.len_utf8()..].trim_start();break;}}- rest.split_whitespace().collect::<Vec<_>>().join(" ").to_lowercase()+ rest.split_whitespace()+ .collect::<Vec<_>>()+ .join(" ")+ .to_lowercase()}fn review_id_for_parts(item_type: &str, title: &str) -> String {@@ -1079,9 +1088,26 @@ fn load_review_items(project_path: &str, query: &ReviewQuery) -> Result<Vec<Valu.as_array().ok_or_else(|| "Invalid review state JSON: expected an array".to_string())?;- let mut reviews: Vec<Value> = Vec::new();+ let mut normalized: Vec<Value> = Vec::new();let mut index_by_id: BTreeMap<String, usize> = BTreeMap::new();for item in items {+ let sanitized = sanitize_review_item(item);+ let id = sanitized+ .get("id")+ .and_then(Value::as_str)+ .map(str::to_string);+ if let Some(id) = id {+ if let Some(existing_idx) = index_by_id.get(&id).copied() {+ merge_sanitized_review(&mut normalized[existing_idx], &sanitized);+ continue;+ }+ index_by_id.insert(id, normalized.len());+ }+ normalized.push(sanitized);+ }++ let mut reviews: Vec<Value> = Vec::new();+ for item in normalized {let resolved = item.get("resolved").and_then(Value::as_bool)@@ -1094,23 +1120,10 @@ fn load_review_items(project_path: &str, query: &ReviewQuery) -> Result<Vec<Valucontinue;}}- let sanitized = sanitize_review_item(item);- let id = sanitized.get("id").and_then(Value::as_str).map(str::to_string);- if let Some(id) = id {- if let Some(existing_idx) = index_by_id.get(&id).copied() {- merge_sanitized_review(&mut reviews[existing_idx], &sanitized);- continue;- }- if reviews.len() >= query.limit {- break;- }- index_by_id.insert(id, reviews.len());- reviews.push(sanitized);- } else if reviews.len() < query.limit {- reviews.push(sanitized);- } else {+ if reviews.len() >= query.limit {break;}+ reviews.push(item);}Ok(reviews)@@ -1156,7 +1169,10 @@ fn merge_sanitized_review(existing: &mut Value, incoming: &Value) {if resolved && !existing.contains_key("resolvedAction") {if let Some(action) = incoming.get("resolvedAction").and_then(Value::as_str) {- existing.insert("resolvedAction".to_string(), Value::String(action.to_string()));+ existing.insert(+ "resolvedAction".to_string(),+ Value::String(action.to_string()),+ );}}@@ -1182,11 +1198,18 @@ fn merge_sanitized_review(existing: &mut Value, incoming: &Value) {.get("createdAt").and_then(Value::as_f64).unwrap_or(incoming_created);- existing.insert("createdAt".to_string(), json!(existing_created.min(incoming_created)));+ existing.insert(+ "createdAt".to_string(),+ json!(existing_created.min(incoming_created)),+ );}}-fn merge_string_array_field(existing: &mut Map<String, Value>, incoming: &Map<String, Value>, key: &str) {+fn merge_string_array_field(+ existing: &mut Map<String, Value>,+ incoming: &Map<String, Value>,+ key: &str,+) {let mut values = existing.get(key).and_then(Value::as_array)@@ -1476,9 +1499,9 @@ fn resolve_review_items(for item in items.iter_mut() {let raw_id = item.get("id").and_then(Value::as_str);let stable_id = stable_review_id(item);- let matched_request = ids.iter().find(|id| {- raw_id == Some(id.as_str()) || stable_id.as_deref() == Some(id.as_str())- });+ let matched_request = ids+ .iter()+ .find(|id| raw_id == Some(id.as_str()) || stable_id.as_deref() == Some(id.as_str()));let Some(requested_id) = matched_request else {continue;};@@ -1496,7 +1519,11 @@ fn resolve_review_items(}// Preserve the caller's input order; dedupe is implicit via `found`.- let resolved: Vec<String> = ids.iter().filter(|id| found.contains(*id)).cloned().collect();+ let resolved: Vec<String> = ids+ .iter()+ .filter(|id| found.contains(*id))+ .cloned()+ .collect();let not_found: Vec<String> = ids.iter().filter(|id| !found.contains(*id))@@ -1512,7 +1539,10 @@ fn apply_resolution(item: &mut Value, resolved: bool, action: Option<&str>) {if !resolved {obj.remove("resolvedAction");} else if let Some(action) = action {- obj.insert("resolvedAction".to_string(), Value::String(action.to_string()));+ obj.insert(+ "resolvedAction".to_string(),+ Value::String(action.to_string()),+ );}}}@@ -1918,6 +1948,43 @@ mod tests {let _ = fs::remove_dir_all(root);}+ #[test]+ fn review_title_normalization_requires_a_prefix_delimiter() {+ assert_eq!(+ normalize_review_title("Missing page: Attention"),+ "attention"+ );+ assert_eq!(+ normalize_review_title(" Missing page: Attention"),+ "attention"+ );+ assert_eq!(+ normalize_review_title("Missing page Attention"),+ "missing page attention"+ );+ assert_eq!(normalize_review_title("疑似重复 注意力"), "疑似重复 注意力");+ assert_ne!(+ review_id_for_parts("missing-page", "Missing page: Attention"),+ review_id_for_parts("missing-page", "Missing page Attention")+ );+ assert_eq!(+ review_id_for_parts("missing-page", "Missing page: Attention"),+ "review-dbdcf949"+ );+ assert_eq!(+ review_id_for_parts("missing-page", " Missing page: Attention"),+ "review-dbdcf949"+ );+ assert_eq!(+ review_id_for_parts("missing-page", "Missing page Attention"),+ "review-fa5d9960"+ );+ assert_eq!(+ review_id_for_parts("missing-page", "疑似重复 注意力"),+ "review-d2dacda0"+ );+ }+#[test]fn review_query_filters_by_type_status_and_limit() {let root = test_project_dir();@@ -1993,7 +2060,10 @@ mod tests {reviews[0].get("id").and_then(Value::as_str),Some(review_id_for_parts("missing-page", "Attention").as_str()));- assert_eq!(reviews[0].get("resolved").and_then(Value::as_bool), Some(true));+ assert_eq!(+ reviews[0].get("resolved").and_then(Value::as_bool),+ Some(true)+ );assert_eq!(reviews[0].get("resolvedAction").and_then(Value::as_str),Some("user-resolved")@@ -2005,7 +2075,52 @@ mod tests {.map(|pages| pages.iter().filter_map(Value::as_str).collect::<Vec<_>>()),Some(vec!["a.md", "b.md"]));- assert_eq!(reviews[0].get("createdAt").and_then(Value::as_f64), Some(2.0));+ assert_eq!(+ reviews[0].get("createdAt").and_then(Value::as_f64),+ Some(2.0)+ );+ let _ = fs::remove_dir_all(root);+ }++ #[test]+ fn review_query_filters_status_after_stable_id_merge() {+ let root = test_project_dir();+ let state_dir = root.join(".llm-wiki");+ fs::create_dir_all(&state_dir).unwrap();+ fs::write(+ state_dir.join("review.json"),+ json!([+ {+ "id": "review-old-unresolved",+ "type": "missing-page",+ "title": "Attention",+ "resolved": false,+ "createdAt": 5+ },+ {+ "id": "review-old-resolved",+ "type": "missing-page",+ "title": "Missing page: Attention",+ "resolved": true,+ "resolvedAction": "Done",+ "createdAt": 6+ }+ ])+ .to_string(),+ )+ .unwrap();++ let unresolved = parse_review_query("status=unresolved").unwrap();+ let unresolved_reviews = load_review_items(root.to_str().unwrap(), &unresolved).unwrap();+ assert!(unresolved_reviews.is_empty());++ let all = parse_review_query("status=all").unwrap();+ let all_reviews = load_review_items(root.to_str().unwrap(), &all).unwrap();+ assert_eq!(all_reviews.len(), 1);+ assert_eq!(+ all_reviews[0].get("resolved").and_then(Value::as_bool),+ Some(true)+ );let _ = fs::remove_dir_all(root);}@@ -2050,7 +2165,10 @@ mod tests {.find(|i| i.get("id").and_then(Value::as_str) == Some("r1")).unwrap();assert_eq!(r1.get("resolved").and_then(Value::as_bool), Some(true));- assert_eq!(r1.get("resolvedAction").and_then(Value::as_str), Some("Skip"));+ assert_eq!(+ r1.get("resolvedAction").and_then(Value::as_str),+ Some("Skip")+ );assert_eq!(r1.get("internalSecret").and_then(Value::as_str),Some("keep-me")@@ -2085,9 +2203,15 @@ mod tests {let parsed = read_reviews(&root);let item = &parsed.as_array().unwrap()[0];- assert_eq!(item.get("id").and_then(Value::as_str), Some(stable_id.as_str()));+ assert_eq!(+ item.get("id").and_then(Value::as_str),+ Some(stable_id.as_str())+ );assert_eq!(item.get("resolved").and_then(Value::as_bool), Some(true));- assert_eq!(item.get("resolvedAction").and_then(Value::as_str), Some("API"));+ assert_eq!(+ item.get("resolvedAction").and_then(Value::as_str),+ Some("API")+ );let _ = fs::remove_dir_all(root);}@@ -2155,16 +2279,28 @@ mod tests {.find(|i| i.get("id").and_then(Value::as_str) == Some(id)).unwrap()};- assert_eq!(by_id("r1").get("resolved").and_then(Value::as_bool), Some(true));+ assert_eq!(+ by_id("r1").get("resolved").and_then(Value::as_bool),+ Some(true)+ );assert_eq!(by_id("r1").get("resolvedAction").and_then(Value::as_str),Some("Bulk"));// Unsanitized field survives the bulk write-back too.- assert_eq!(by_id("r1").get("internalSecret").and_then(Value::as_str), Some("a"));- assert_eq!(by_id("r3").get("resolved").and_then(Value::as_bool), Some(true));+ assert_eq!(+ by_id("r1").get("internalSecret").and_then(Value::as_str),+ Some("a")+ );+ assert_eq!(+ by_id("r3").get("resolved").and_then(Value::as_bool),+ Some(true)+ );// r2 was not in the request — untouched.- assert_eq!(by_id("r2").get("resolved").and_then(Value::as_bool), Some(false));+ assert_eq!(+ by_id("r2").get("resolved").and_then(Value::as_bool),+ Some(false)+ );let _ = fs::remove_dir_all(root);}@@ -2200,10 +2336,19 @@ mod tests {assert_eq!(not_found, vec!["missing".to_string()]);let parsed = read_reviews(&root);let items = parsed.as_array().unwrap();- assert_eq!(items[0].get("id").and_then(Value::as_str), Some(ids[0].as_str()));- assert_eq!(items[0].get("resolved").and_then(Value::as_bool), Some(true));+ assert_eq!(+ items[0].get("id").and_then(Value::as_str),+ Some(ids[0].as_str())+ );+ assert_eq!(+ items[0].get("resolved").and_then(Value::as_bool),+ Some(true)+ );assert_eq!(items[1].get("id").and_then(Value::as_str), Some("review-2"));- assert_eq!(items[1].get("resolved").and_then(Value::as_bool), Some(false));+ assert_eq!(+ items[1].get("resolved").and_then(Value::as_bool),+ Some(false)+ );let _ = fs::remove_dir_all(root);}@@ -2211,7 +2356,8 @@ mod tests {fn resolve_review_items_missing_file_reports_all_not_found() {let root = test_project_dir();let ids = vec!["r1".to_string(), "r2".to_string()];- let (resolved, not_found) = resolve_review_items(root.to_str().unwrap(), &ids, None).unwrap();+ let (resolved, not_found) =+ resolve_review_items(root.to_str().unwrap(), &ids, None).unwrap();assert!(resolved.is_empty());assert_eq!(not_found, ids);let _ = fs::remove_dir_all(root);diff --git a/src-tauri/src/commands/claude_cli.rs b/src-tauri/src/commands/claude_cli.rsindex 011da7d0..140f44fc 100644--- a/src-tauri/src/commands/claude_cli.rs+++ b/src-tauri/src/commands/claude_cli.rs@@ -428,17 +428,23 @@ async fn resolve_claude_working_directory(value: Option<String>) -> Result<PathB.map(str::trim).filter(|v| !v.is_empty()).map(str::to_string)- .ok_or_else(|| "Claude Code CLI requires an active project working directory".to_string())?;+ .ok_or_else(|| {+ "Claude Code CLI requires an active project working directory".to_string()+ })?;let path = Path::new(raw.as_str());if !path.is_absolute() {- return Err("Claude Code CLI working directory must be an absolute project path".to_string());+ return Err(+ "Claude Code CLI working directory must be an absolute project path".to_string(),+ );}let path_meta = tokio::fs::metadata(path).await.map_err(|e| {eprintln!("[claude-cli] failed to read working directory metadata {raw}: {e}");format!("Claude Code CLI working directory does not exist or cannot be read: {raw}")})?;if !path_meta.is_dir() {- return Err(format!("Claude Code CLI working directory is not a directory: {raw}"));+ return Err(format!(+ "Claude Code CLI working directory is not a directory: {raw}"+ ));}let index_path = path.join("wiki").join("index.md");let index_meta = tokio::fs::metadata(&index_path).await.map_err(|e| {@@ -568,10 +574,12 @@ mod tests {.await.unwrap_err().contains("active project"));- assert!(resolve_claude_working_directory(Some("relative/path".to_string()))- .await- .unwrap_err()- .contains("absolute"));+ assert!(+ resolve_claude_working_directory(Some("relative/path".to_string()))+ .await+ .unwrap_err()+ .contains("absolute")+ );let dir = std::env::temp_dir().join(format!("llm-wiki-claude-cwd-{}-{}",diff --git a/src-tauri/src/commands/codex_cli.rs b/src-tauri/src/commands/codex_cli.rsindex 37dc06f7..2d6dcfa7 100644--- a/src-tauri/src/commands/codex_cli.rs+++ b/src-tauri/src/commands/codex_cli.rs@@ -259,7 +259,9 @@ pub async fn codex_cli_spawn(if !stderr_text.is_empty() {stderr_text.push('\n');}- stderr_text.push_str(&format!("Codex CLI timed out after {timeout_minutes} minutes."));+ stderr_text.push_str(&format!(+ "Codex CLI timed out after {timeout_minutes} minutes."+ ));} else if stderr_text.len() >= STDERR_LIMIT_BYTES {stderr_text.push_str("\n[stderr truncated]");}@@ -287,9 +289,10 @@ pub async fn codex_cli_spawn(}fn codex_spawn_timeout_minutes(value: Option<u64>) -> u64 {- value- .unwrap_or(DEFAULT_CODEX_SPAWN_TIMEOUT_MINUTES)- .clamp(MIN_CODEX_SPAWN_TIMEOUT_MINUTES, MAX_CODEX_SPAWN_TIMEOUT_MINUTES)+ value.unwrap_or(DEFAULT_CODEX_SPAWN_TIMEOUT_MINUTES).clamp(+ MIN_CODEX_SPAWN_TIMEOUT_MINUTES,+ MAX_CODEX_SPAWN_TIMEOUT_MINUTES,+ )}fn build_codex_cli_args(model: &str, isolate_local_config: bool) -> Vec<String> {@@ -331,7 +334,9 @@ async fn resolve_codex_working_directory(value: Option<String>) -> Result<PathBuformat!("Codex CLI working directory does not exist or cannot be read: {raw}")})?;if !path_meta.is_dir() {- return Err(format!("Codex CLI working directory is not a directory: {raw}"));+ return Err(format!(+ "Codex CLI working directory is not a directory: {raw}"+ ));}let index_path = path.join("wiki").join("index.md");let index_meta = tokio::fs::metadata(&index_path).await.map_err(|e| {@@ -395,7 +400,10 @@ mod tests {codex_spawn_timeout_minutes(None),DEFAULT_CODEX_SPAWN_TIMEOUT_MINUTES);- assert_eq!(codex_spawn_timeout_minutes(Some(0)), MIN_CODEX_SPAWN_TIMEOUT_MINUTES);+ assert_eq!(+ codex_spawn_timeout_minutes(Some(0)),+ MIN_CODEX_SPAWN_TIMEOUT_MINUTES+ );assert_eq!(codex_spawn_timeout_minutes(Some(42)), 42);assert_eq!(codex_spawn_timeout_minutes(Some(999)),@@ -455,25 +463,25 @@ mod tests {.await.unwrap_err().contains("requires an active project"));- assert!(resolve_codex_working_directory(Some("relative/project".to_string()))- .await- .unwrap_err()- .contains("absolute"));+ assert!(+ resolve_codex_working_directory(Some("relative/project".to_string()))+ .await+ .unwrap_err()+ .contains("absolute")+ );- let missing = std::env::temp_dir().join(format!(- "llm-wiki-codex-cli-missing-{}",- std::process::id()- ));+ let missing =+ std::env::temp_dir().join(format!("llm-wiki-codex-cli-missing-{}", std::process::id()));let _ = std::fs::remove_dir_all(&missing);- assert!(resolve_codex_working_directory(Some(missing.to_string_lossy().to_string()))- .await- .unwrap_err()- .contains("does not exist or cannot be read"));+ assert!(+ resolve_codex_working_directory(Some(missing.to_string_lossy().to_string()))+ .await+ .unwrap_err()+ .contains("does not exist or cannot be read")+ );- let file_path = std::env::temp_dir().join(format!(- "llm-wiki-codex-cli-file-{}",- std::process::id()- ));+ let file_path =+ std::env::temp_dir().join(format!("llm-wiki-codex-cli-file-{}", std::process::id()));let _ = std::fs::remove_file(&file_path);std::fs::write(&file_path, "not a directory").expect("temp file");struct TestFile(PathBuf);@@ -483,31 +491,35 @@ mod tests {}}let _file_guard = TestFile(file_path.clone());- assert!(resolve_codex_working_directory(Some(file_path.to_string_lossy().to_string()))- .await- .unwrap_err()- .contains("not a directory"));+ assert!(+ resolve_codex_working_directory(Some(file_path.to_string_lossy().to_string()))+ .await+ .unwrap_err()+ .contains("not a directory")+ );- let dir = std::env::temp_dir().join(format!(- "llm-wiki-codex-cli-test-{}",- std::process::id()- ));+ let dir =+ std::env::temp_dir().join(format!("llm-wiki-codex-cli-test-{}", std::process::id()));let _ = std::fs::remove_dir_all(&dir);std::fs::create_dir_all(&dir).expect("tempdir");let _guard = TestDir(dir.clone());- assert!(resolve_codex_working_directory(Some(dir.to_string_lossy().to_string()))- .await- .unwrap_err()- .contains("wiki/index.md"));+ assert!(+ resolve_codex_working_directory(Some(dir.to_string_lossy().to_string()))+ .await+ .unwrap_err()+ .contains("wiki/index.md")+ );let wiki_dir = dir.join("wiki");std::fs::create_dir_all(&wiki_dir).expect("wiki dir");let index_dir = wiki_dir.join("index.md");std::fs::create_dir_all(&index_dir).expect("index dir");- assert!(resolve_codex_working_directory(Some(dir.to_string_lossy().to_string()))- .await- .unwrap_err()- .contains("wiki/index.md"));+ assert!(+ resolve_codex_working_directory(Some(dir.to_string_lossy().to_string()))+ .await+ .unwrap_err()+ .contains("wiki/index.md")+ );std::fs::remove_dir_all(&index_dir).expect("remove index dir");std::fs::write(wiki_dir.join("index.md"), "# Index\n").expect("index");let resolved = resolve_codex_working_directory(Some(dir.to_string_lossy().to_string()))diff --git a/src-tauri/src/commands/fs.rs b/src-tauri/src/commands/fs.rsindex b83c38d3..4ea8bbb8 100644--- a/src-tauri/src/commands/fs.rs+++ b/src-tauri/src/commands/fs.rs@@ -2067,7 +2067,10 @@ mod tests {// The dotfolder's children come through too.let claude = shown.iter().find(|n| n.name == ".claude").unwrap();- let kids = claude.children.as_ref().expect(".claude should have children");+ let kids = claude+ .children+ .as_ref()+ .expect(".claude should have children");assert!(kids.iter().any(|n| n.name == "CLAUDE.md"));let _ = fs::remove_dir_all(root);diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.jsonindex 2cc66a59..d9239482 100644--- a/src-tauri/tauri.conf.json+++ b/src-tauri/tauri.conf.json@@ -1,7 +1,7 @@{"$schema": "https://schema.tauri.app/config/2","productName": "LLM Wiki",- "version": "0.5.2",+ "version": "0.5.3","identifier": "com.llmwiki.app","build": {"beforeDevCommand": "npm run dev",diff --git a/src/components/chat/chat-message.tsx b/src/components/chat/chat-message.tsxindex 058e077f..aa8b3bb8 100644--- a/src/components/chat/chat-message.tsx+++ b/src/components/chat/chat-message.tsx@@ -31,6 +31,7 @@ import { MermaidDiagram, unwrapMermaidPre } from "@/components/mermaid-diagram"import { inferWikiTypeFromPath } from "@/lib/wiki-page-types"import { cleanAssistantContentForWikiSave, titleFromCleanAssistantContent } from "@/lib/chat-save-to-wiki"import type { ChatAgentEvent, ChatAgentEventStage, ChatAgentStep } from "@/lib/chat-agent"+import { filterRawSourceTree } from "@/lib/source-filter"// Module-level cache of source file nameslet cachedSourceFiles: string[] = []@@ -42,6 +43,7 @@ export function useSourceFiles() {if (!project) returnconst pp = normalizePath(project.path)listDirectory(`${pp}/raw/sources`, true)+ .then(filterRawSourceTree).then((tree) => {cachedSourceFiles = flattenNames(tree)})diff --git a/src/components/layout/knowledge-tree.tsx b/src/components/layout/knowledge-tree.tsxindex a51fd307..93b0d14a 100644--- a/src/components/layout/knowledge-tree.tsx+++ b/src/components/layout/knowledge-tree.tsx@@ -10,6 +10,7 @@ import type { FileNode } from "@/types/wiki"import { normalizePath } from "@/lib/path-utils"import { cascadeDeleteWikiPagesWithRefs } from "@/lib/wiki-page-delete"import { inferWikiTypeFromPath, wikiTypeLabel } from "@/lib/wiki-page-types"+import { filterRawSourceTree } from "@/lib/source-filter"interface WikiPageInfo {path: string@@ -252,7 +253,7 @@ function RawSourcesSection() {useEffect(() => {if (!project) returnconst pp = normalizePath(project.path)- listDirectory(`${pp}/raw/sources`, true)+ listDirectory(`${pp}/raw/sources`, true).then(filterRawSourceTree).then((tree) => setSources(flattenAllFiles(tree))).catch(() => setSources([]))}, [project])diff --git a/src/components/sources/sources-view.tsx b/src/components/sources/sources-view.tsxindex ba51a43c..3f102f85 100644--- a/src/components/sources/sources-view.tsx+++ b/src/components/sources/sources-view.tsx@@ -19,6 +19,7 @@ import {importSourceFiles,importSourceFolder,} from "@/lib/source-lifecycle"+import { filterRawSourceTree } from "@/lib/source-filter"const SOURCE_TREE_INITIAL_ROWS = 160const SOURCE_TREE_LOAD_BATCH = 160@@ -66,10 +67,7 @@ export function SourcesView() {const pp = normalizePath(project.path)try {const tree = await listDirectory(`${pp}/raw/sources`, true)- // Keep user-added dotfolders (.claude, .codex) but drop ingest- // noise (.cache, .DS_Store) — see filterTree.- const filtered = filterTree(tree)- setSources(filtered)+ setSources(filterRawSourceTree(tree))setRefreshError(null)} catch (err) {setRefreshError(String(err))@@ -365,23 +363,6 @@ interface SourceTreeRow {depth: number}-// Ingest-generated noise hidden from the sources tree even though the-// listing now includes dot entries. User-added dotfolders (.claude,-// .codex) pass through; only these internal artifacts are dropped.-const HIDDEN_SOURCE_ENTRIES = new Set([".cache", ".DS_Store"])--function filterTree(nodes: FileNode[]): FileNode[] {- return nodes- .filter((n) => !HIDDEN_SOURCE_ENTRIES.has(n.name))- .map((n) => {- if (n.is_dir && n.children) {- return { ...n, children: filterTree(n.children) }- }- return n- })- .filter((n) => !n.is_dir || (n.children && n.children.length > 0))-}-function countFiles(nodes: FileNode[]): number {let count = 0for (const node of nodes) {diff --git a/src/lib/chat-agent.ts b/src/lib/chat-agent.tsindex 1f7ac78e..0010a33b 100644--- a/src/lib/chat-agent.ts+++ b/src/lib/chat-agent.ts@@ -11,6 +11,7 @@ import { resolveSearchConfig, webSearch, type WebSearchResult } from "@/lib/web-import type { LlmConfig, SearchApiConfig } from "@/stores/wiki-store"import type { MessageReference } from "@/stores/chat-store"import type { FileNode } from "@/types/wiki"+import { filterRawSourceTree } from "@/lib/source-filter"export type ChatAgentAction =| "answer"@@ -898,7 +899,9 @@ async function runProjectFilesTool(args: {const maxEntries = args.llmConfig.maxContextSize > 180_000 ? 160 : 80const [wikiTree, rawTree] = await Promise.all([listDirectory(`${args.projectPath}/wiki`).catch(() => [] as FileNode[]),- listDirectory(`${args.projectPath}/raw/sources`, true).catch(() => [] as FileNode[]),+ listDirectory(`${args.projectPath}/raw/sources`, true)+ .then(filterRawSourceTree)+ .catch(() => [] as FileNode[]),])const wikiEntries = flattenFileTree(wikiTree, "wiki").slice(0, maxEntries)const rawEntries = flattenFileTree(rawTree, "raw/sources").slice(0, Math.floor(maxEntries / 2))diff --git a/src/lib/raw-source-resolver.ts b/src/lib/raw-source-resolver.tsindex f6b010a1..d1509a06 100644--- a/src/lib/raw-source-resolver.ts+++ b/src/lib/raw-source-resolver.ts@@ -25,6 +25,7 @@ import {sourceSummarySlugCandidatesFromIdentity,} from "@/lib/source-identity"import type { FileNode } from "@/types/wiki"+import { filterRawSourceTree } from "@/lib/source-filter"export async function findRawSourceForImage(imageUrl: string,@@ -41,7 +42,7 @@ export async function findRawSourceForImage(let tree: FileNode[]try {- tree = await listDirectory(`${normalizedProjectPath}/raw/sources`, true)+ tree = filterRawSourceTree(await listDirectory(`${normalizedProjectPath}/raw/sources`, true))} catch {return null}diff --git a/src/lib/review-utils.test.ts b/src/lib/review-utils.test.tsindex 7537344a..6df34cb0 100644--- a/src/lib/review-utils.test.ts+++ b/src/lib/review-utils.test.ts@@ -10,6 +10,14 @@ describe("normalizeReviewTitle", () => {expect(normalizeReviewTitle("Missing page: Attention")).toBe("attention")})+ it("strips recognized prefixes after leading whitespace", () => {+ expect(normalizeReviewTitle(" Missing page: Attention")).toBe("attention")+ })++ it("does not strip English prefix-like words without a colon delimiter", () => {+ expect(normalizeReviewTitle("Missing page Attention")).toBe("missing page attention")+ })+it("strips hyphenated 'Missing-Page:' prefix", () => {expect(normalizeReviewTitle("Missing-Page: Attention")).toBe("attention")})@@ -34,6 +42,10 @@ describe("normalizeReviewTitle", () => {expect(normalizeReviewTitle("重复页面:大模型")).toBe("大模型")})+ it("does not strip Chinese prefix-like words without a colon delimiter", () => {+ expect(normalizeReviewTitle("疑似重复 注意力")).toBe("疑似重复 注意力")+ })+it("strips 'Possible duplicate:' prefix", () => {expect(normalizeReviewTitle("Possible duplicate: Graph RAG")).toBe("graph rag")})diff --git a/src/lib/review-utils.ts b/src/lib/review-utils.tsindex 29e56760..0c3b5bb0 100644--- a/src/lib/review-utils.ts+++ b/src/lib/review-utils.ts@@ -20,6 +20,7 @@ const REVIEW_TITLE_PREFIX_RE =*/export function normalizeReviewTitle(title: string): string {return title+ .trimStart().replace(REVIEW_TITLE_PREFIX_RE, "").replace(/\s+/g, " ").trim()diff --git a/src/lib/scheduled-import.test.ts b/src/lib/scheduled-import.test.tsindex d0493882..b4f4e91d 100644--- a/src/lib/scheduled-import.test.ts+++ b/src/lib/scheduled-import.test.ts@@ -42,6 +42,7 @@ import {resolveImportPath,scheduledImportDestinationForFile,scanAndImport,+ shouldSkipScheduledImportConfigFile,shouldSkipScheduledImportFile,} from "./scheduled-import"import { useWikiStore } from "@/stores/wiki-store"@@ -144,6 +145,14 @@ describe("scheduled import path handling", () => {),).toBe(true)})++ it("skips config-like files for unattended scheduled import", () => {+ expect(shouldSkipScheduledImportConfigFile("/Users/me/inbox/data.json")).toBe(true)+ expect(shouldSkipScheduledImportConfigFile("/Users/me/inbox/secrets.yaml")).toBe(true)+ expect(shouldSkipScheduledImportConfigFile("/Users/me/inbox/settings.yml")).toBe(true)+ expect(shouldSkipScheduledImportConfigFile("/Users/me/inbox/config.xml")).toBe(true)+ expect(shouldSkipScheduledImportConfigFile("/Users/me/inbox/notes.md")).toBe(false)+ })})describe("scanAndImport failure handling", () => {@@ -242,4 +251,26 @@ describe("scanAndImport failure handling", () => {expect(mocks.copyFile).not.toHaveBeenCalled()expect(mocks.enqueueSourceIngest).not.toHaveBeenCalled()})++ it("does not copy unattended json/yaml/xml config files", async () => {+ mocks.listDirectory.mockResolvedValueOnce([+ { name: "secrets.yaml", path: "/Users/me/inbox/secrets.yaml", is_dir: false },+ { name: "notes.md", path: "/Users/me/inbox/notes.md", is_dir: false },+ ])+ mocks.enqueueSourceIngest.mockResolvedValue(["task-1"])++ await scanAndImport(project, "/Users/me/inbox")++ expect(mocks.copyFile).toHaveBeenCalledTimes(1)+ expect(mocks.copyFile).toHaveBeenCalledWith(+ "/Users/me/inbox/notes.md",+ "/Users/me/wiki-project/raw/sources/scheduled-import/notes.md",+ )+ expect(mocks.copyFile).not.toHaveBeenCalledWith("/Users/me/inbox/secrets.yaml", expect.anything())+ expect(mocks.enqueueSourceIngest).toHaveBeenCalledWith(+ project,+ ["/Users/me/wiki-project/raw/sources/scheduled-import/notes.md"],+ expect.any(Object),+ )+ })})diff --git a/src/lib/scheduled-import.ts b/src/lib/scheduled-import.tsindex e11ad72e..543c653f 100644--- a/src/lib/scheduled-import.ts+++ b/src/lib/scheduled-import.ts@@ -55,7 +55,7 @@ const DB_PATH = ".llm-wiki/scheduled-import-db.json"const LEGACY_DB_DIR = ".llm-wiki-imported"const SCHEDULED_IMPORT_DIR = "scheduled-import"const MAX_SCHEDULED_IMPORT_BYTES = 100 * 1024 * 1024-const SENSITIVE_CONFIG_EXTENSIONS = new Set(["json", "yaml", "yml", "xml"])+const SCHEDULED_IMPORT_CONFIG_EXTENSIONS = new Set(["json", "yaml", "yml", "xml"])const RESERVED_WINDOWS_NAMES = new Set(["con","prn",@@ -227,10 +227,10 @@ export function shouldSkipScheduledImportFile(return name.startsWith(".")}-function isSensitiveConfigFile(path: string): boolean {+export function shouldSkipScheduledImportConfigFile(path: string): boolean {const name = normalizePath(path).split("/").pop() ?? ""const ext = name.includes(".") ? name.split(".").pop()?.toLowerCase() : ""- return Boolean(ext && SENSITIVE_CONFIG_EXTENSIONS.has(ext))+ return Boolean(ext && SCHEDULED_IMPORT_CONFIG_EXTENSIONS.has(ext))}export function resolveImportPath(projectPath: string, configPath: string): string {@@ -364,7 +364,7 @@ export async function scanAndImport(const sourcePath = normalizePath(file.path)if (shouldSkipScheduledImportFile(projectPath, sourcePath) ||- isSensitiveConfigFile(sourcePath) ||+ shouldSkipScheduledImportConfigFile(sourcePath) ||!isIngestableSourcePath(sourcePath)) {continuediff --git a/src/lib/source-filter.test.ts b/src/lib/source-filter.test.tsnew file mode 100644index 00000000..0a3e9e52--- /dev/null+++ b/src/lib/source-filter.test.ts@@ -0,0 +1,61 @@+import { describe, expect, it } from "vitest"++import { filterRawSourceTree, isSensitiveConfigSourceFile } from "./source-filter"+import type { FileNode } from "@/types/wiki"++describe("source-filter", () => {+ it("removes raw source cache noise without dropping user dotfolders", () => {+ const tree: FileNode[] = [+ {+ name: ".cache",+ path: "/project/raw/sources/.cache",+ is_dir: true,+ children: [+ { name: "source.pdf.txt", path: "/project/raw/sources/.cache/source.pdf.txt", is_dir: false },+ ],+ },+ { name: ".DS_Store", path: "/project/raw/sources/.DS_Store", is_dir: false },+ {+ name: ".claude",+ path: "/project/raw/sources/.claude",+ is_dir: true,+ children: [+ { name: "notes.md", path: "/project/raw/sources/.claude/notes.md", is_dir: false },+ { name: "settings.json", path: "/project/raw/sources/.claude/settings.json", is_dir: false },+ ],+ },+ {+ name: "empty-after-filter",+ path: "/project/raw/sources/empty-after-filter",+ is_dir: true,+ children: [+ { name: ".DS_Store", path: "/project/raw/sources/empty-after-filter/.DS_Store", is_dir: false },+ ],+ },+ ]++ expect(filterRawSourceTree(tree)).toEqual([+ {+ name: ".claude",+ path: "/project/raw/sources/.claude",+ is_dir: true,+ children: [+ { name: "notes.md", path: "/project/raw/sources/.claude/notes.md", is_dir: false },+ ],+ },+ ])+ })++ it("identifies config-like files that should not be imported from hidden tool folders", () => {+ expect(isSensitiveConfigSourceFile("/external/.claude/settings.json")).toBe(true)+ expect(isSensitiveConfigSourceFile("/external/.codex/config.yaml")).toBe(true)+ expect(isSensitiveConfigSourceFile("/external/.codex/config.toml")).toBe(true)+ expect(isSensitiveConfigSourceFile("/external/.cursor/rules.yml")).toBe(true)+ expect(isSensitiveConfigSourceFile("/external/.gemini/config.xml")).toBe(true)+ expect(isSensitiveConfigSourceFile("/external/.mcp/.env")).toBe(true)+ expect(isSensitiveConfigSourceFile("/external/.mcp/servers.json")).toBe(true)+ expect(isSensitiveConfigSourceFile("/external/.CLAUDE/Settings.JSON")).toBe(true)+ expect(isSensitiveConfigSourceFile("/external/data.json")).toBe(false)+ expect(isSensitiveConfigSourceFile("/external/.claude/research.md")).toBe(false)+ })+})diff --git a/src/lib/source-filter.ts b/src/lib/source-filter.tsnew file mode 100644index 00000000..0ff4da3c--- /dev/null+++ b/src/lib/source-filter.ts@@ -0,0 +1,40 @@+import type { FileNode } from "@/types/wiki"+import { normalizePath } from "@/lib/path-utils"++const HIDDEN_SOURCE_ENTRY_NAMES = new Set([".cache", ".DS_Store"])+const SENSITIVE_CONFIG_EXTENSIONS = new Set(["env", "json", "toml", "yaml", "yml", "xml"])+const SENSITIVE_CONFIG_DIR_NAMES = new Set([+ ".claude",+ ".codex",+ ".cursor",+ ".gemini",+ ".mcp",+])++export function isHiddenRawSourceEntryName(name: string): boolean {+ return HIDDEN_SOURCE_ENTRY_NAMES.has(name)+}++export function filterRawSourceTree(nodes: FileNode[]): FileNode[] {+ return nodes+ .filter((node) =>+ !isHiddenRawSourceEntryName(node.name) &&+ (node.is_dir || !isSensitiveConfigSourceFile(node.path))+ )+ .map((node) => {+ if (!node.is_dir) return node+ return { ...node, children: filterRawSourceTree(node.children ?? []) }+ })+ .filter((node) => !node.is_dir || (node.children && node.children.length > 0))+}++export function isSensitiveConfigSourceFile(path: string): boolean {+ const parts = normalizePath(path).split("/").filter(Boolean)+ const name = parts[parts.length - 1] ?? ""+ const ext = name.includes(".") ? name.split(".").pop()?.toLowerCase() : ""+ return Boolean(+ ext &&+ SENSITIVE_CONFIG_EXTENSIONS.has(ext) &&+ parts.some((part) => SENSITIVE_CONFIG_DIR_NAMES.has(part.toLowerCase())),+ )+}diff --git a/src/lib/source-lifecycle.test.ts b/src/lib/source-lifecycle.test.tsindex 2af9abba..072aa556 100644--- a/src/lib/source-lifecycle.test.ts+++ b/src/lib/source-lifecycle.test.ts@@ -30,6 +30,7 @@ vi.mock("@/lib/ingest-queue", () => ({}))import {+ enqueueSourceIngest,folderContextForSourcePath,importSourceFiles,importSourceFolder,@@ -112,6 +113,59 @@ describe("source-lifecycle path helpers", () => {])})+ it("does not import config-like files from hidden tool folders", async () => {+ mocks.listDirectory.mockResolvedValue([+ {+ name: ".claude",+ path: "/external/imported/.claude",+ is_dir: true,+ children: [+ { name: "settings.json", path: "/external/imported/.claude/settings.json", is_dir: false },+ { name: "research.md", path: "/external/imported/.claude/research.md", is_dir: false },+ ],+ },+ {+ name: ".codex",+ path: "/external/imported/.codex",+ is_dir: true,+ children: [+ { name: "config.yaml", path: "/external/imported/.codex/config.yaml", is_dir: false },+ ],+ },+ ])++ const copied = await importSourceFolder(+ { id: "p1", name: "Project", path: "/project" },+ "/external/imported",+ {+ provider: "openai",+ endpoint: "https://api.example.com/v1",+ apiKey: "key",+ model: "model",+ customModel: "",+ reasoning: { enabled: false, effort: "low" },+ } as never,+ {+ enabled: true,+ autoIngest: true,+ includeExtensions: ["json", "yaml", "md"],+ excludeExtensions: [],+ excludeDirs: [],+ excludeGlobs: [],+ maxFileSizeMb: 100,+ },+ )++ expect(copied).toEqual(["/project/raw/sources/imported/.claude/research.md"])+ expect(mocks.copyFile).toHaveBeenCalledTimes(1)+ expect(mocks.copyFile).toHaveBeenCalledWith(+ "/external/imported/.claude/research.md",+ "/project/raw/sources/imported/.claude/research.md",+ )+ expect(mocks.copyFile).not.toHaveBeenCalledWith("/external/imported/.claude/settings.json", expect.anything())+ expect(mocks.copyFile).not.toHaveBeenCalledWith("/external/imported/.codex/config.yaml", expect.anything())+ })+it("rejects importing the project folder or folders inside it", async () => {await expect(importSourceFolder(@@ -182,6 +236,33 @@ describe("source-lifecycle path helpers", () => {])})+ it("skips sensitive tool config files at the shared ingest enqueue boundary", async () => {+ const queued = await enqueueSourceIngest(+ { id: "p1", name: "Project", path: "/project" },+ [+ "/project/raw/sources/.claude/settings.json",+ "/project/raw/sources/.codex/config.yaml",+ "/project/raw/sources/notes.md",+ ],+ {+ provider: "openai",+ endpoint: "https://api.example.com/v1",+ apiKey: "key",+ model: "model",+ customModel: "",+ reasoning: { enabled: false, effort: "low" },+ } as never,+ )++ expect(queued).toEqual(["task"])+ expect(mocks.enqueueBatch).toHaveBeenCalledWith("p1", [+ {+ sourcePath: "/project/raw/sources/notes.md",+ folderContext: "",+ },+ ])+ })+it("naturally orders imported folder files before enqueueing ingest tasks", async () => {mocks.listDirectory.mockResolvedValue([{ name: "10.md", path: "/external/imported/10.md", is_dir: false },diff --git a/src/lib/source-lifecycle.ts b/src/lib/source-lifecycle.tsindex 4d863246..55e1ceab 100644--- a/src/lib/source-lifecycle.ts+++ b/src/lib/source-lifecycle.ts@@ -34,6 +34,7 @@ import {} from "@/lib/wiki-cleanup"import { collectAllFilesIncludingDot } from "@/lib/sources-tree-delete"import { isPathAllowedBySourceWatch, normalizeSourceWatchConfig } from "@/lib/source-watch-config"+import { isSensitiveConfigSourceFile } from "@/lib/source-filter"import { naturalCompare } from "@/lib/natural-sort"import type { SourceWatchConfig } from "@/stores/wiki-store"@@ -140,7 +141,10 @@ export async function enqueueSourceIngest(): Promise<string[]> {if (!hasUsableLlm(llmConfig)) return []const files = sourcePaths- .filter(isIngestableSourcePath)+ .filter((sourcePath) =>+ isIngestableSourcePath(sourcePath) &&+ !isSensitiveConfigSourceFile(sourcePath)+ ).map((sourcePath) => ({sourcePath,folderContext: withRootContext(@@ -165,6 +169,9 @@ export async function importSourceFiles(for (const sourcePath of sourcePaths) {const originalName = getFileName(sourcePath) || "unknown"+ if (isSensitiveConfigSourceFile(sourcePath)) {+ continue+ }let allowed = isPathAllowedBySourceWatch(sourcePath, cfg)if (allowed) {try {@@ -207,15 +214,18 @@ export async function importSourceFolder(const maxBytes = cfg.maxFileSizeMb * 1024 * 1024const allowedFiles: string[] = []// include hidden: a user importing a folder into raw/sources may- // legitimately want its dotfolders (.claude, .codex). Non-source- // noise is still filtered downstream by the source-watch allowlist- // and max-size check below.+ // legitimately want dotfolder notes. Config-like files under known+ // agent/tool config folders are still filtered before copy so API+ // keys / tool config do not enter ingest.const sourceFiles = flattenFiles(await listDirectory(selectedFolder, true))for (const file of sourceFiles) {const relativeSourcePath = getRelativePath(file.path, sourceRoot)const destPath = `${destDir}/${relativeSourcePath}`const relPath = `raw/sources/${folderName}/${relativeSourcePath}`+ if (isSensitiveConfigSourceFile(file.path)) {+ continue+ }let allowed = isPathAllowedBySourceWatch(relPath, cfg)if (allowed) {try {diff --git a/src/lib/sources-tree-delete.ts b/src/lib/sources-tree-delete.tsindex f4475c09..241986b2 100644--- a/src/lib/sources-tree-delete.ts+++ b/src/lib/sources-tree-delete.ts@@ -13,8 +13,8 @@ import type { FileNode } from "@/types/wiki"/*** Recursively collect every leaf (non-directory) file under* `folder`. Walks `folder.children` rather than re-reading the- * file system — the parent already filtered dotfiles out via- * `filterTree` before the tree reached the UI, so this preserves+ * file system — the parent already filters hidden source noise before+ * the tree reaches the UI, so this preserves* the "delete exactly what the user saw" invariant.** Skips empty folders (returns no entries for them) but recursesdiff --git a/src/stores/review-store.test.ts b/src/stores/review-store.test.tsindex 478b0109..cc3a565f 100644--- a/src/stores/review-store.test.ts+++ b/src/stores/review-store.test.ts@@ -24,6 +24,15 @@ describe("reviewIdFor — content-stable id", () => {.toBe(reviewIdFor({ type: "missing-page", title: "缺失页面: Attention" }))})+ it("matches the API stable-id fixtures", () => {+ expect(reviewIdFor({ type: "missing-page", title: "Missing page: Attention" }))+ .toBe("review-dbdcf949")+ expect(reviewIdFor({ type: "missing-page", title: "Missing page Attention" }))+ .toBe("review-fa5d9960")+ expect(reviewIdFor({ type: "missing-page", title: "疑似重复 注意力" }))+ .toBe("review-d2dacda0")+ })+it("differs across types", () => {expect(reviewIdFor({ type: "missing-page", title: "Attention" })).not.toBe(reviewIdFor({ type: "duplicate", title: "Attention" }))