Skip to content

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.6.8

nash_sub4b544abe0dd
diff --git a/package-lock.json b/package-lock.json
index a20882f6..c37abc64 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "llm-wiki",
- "version": "0.6.7",
+ "version": "0.6.8",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "llm-wiki",
- "version": "0.6.7",
+ "version": "0.6.8",
"dependencies": {
"@base-ui/react": "^1.3.0",
"@fontsource-variable/geist": "^5.2.8",
diff --git a/package.json b/package.json
index 3a850da4..041dc1ff 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "llm-wiki",
"private": true,
- "version": "0.6.7",
+ "version": "0.6.8",
"type": "module",
"scripts": {
"dev": "vite",
diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock
index f37f714c..65934100 100644
--- a/src-tauri/Cargo.lock
+++ b/src-tauri/Cargo.lock
@@ -72,6 +72,73 @@ dependencies = [
"libc",
]
+[[package]]
+name = "anstream"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "824a212faf96e9acacdbd09febd34438f8f711fb84e09a8916013cd7815ca28d"
+dependencies = [
+ "anstyle",
+ "anstyle-parse",
+ "anstyle-query",
+ "anstyle-wincon",
+ "colorchoice",
+ "is_terminal_polyfill",
+ "utf8parse",
+]
+
+[[package]]
+name = "anstyle"
+version = "1.0.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000"
+
+[[package]]
+name = "anstyle-parse"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "52ce7f38b242319f7cabaa6813055467063ecdc9d355bbb4ce0c68908cd8130e"
+dependencies = [
+ "utf8parse",
+]
+
+[[package]]
+name = "anstyle-query"
+version = "1.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc"
+dependencies = [
+ "windows-sys 0.61.2",
+]
+
+[[package]]
+name = "anstyle-wincon"
+version = "3.0.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d"
+dependencies = [
+ "anstyle",
+ "once_cell_polyfill",
+ "windows-sys 0.61.2",
+]
+
+[[package]]
+name = "anydoc"
+version = "0.1.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b1d88a76ba2a26a65e133879dee68acd593656e68e306488ebb162b69f37902b"
+dependencies = [
+ "calamine 0.36.1",
+ "cfb 0.14.0",
+ "csv",
+ "encoding_rs",
+ "flate2",
+ "log",
+ "pdf-inspector",
+ "quick-xml 0.41.0",
+ "zip 8.6.0",
+]
+
[[package]]
name = "anyhow"
version = "1.0.102"
@@ -672,6 +739,15 @@ dependencies = [
"generic-array",
]
+[[package]]
+name = "block-padding"
+version = "0.3.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a8894febbff9f758034a5b8e12d87918f56dfc64a8e1fe757d65e29041538d93"
+dependencies = [
+ "generic-array",
+]
+
[[package]]
name = "block2"
version = "0.6.2"
@@ -843,6 +919,24 @@ dependencies = [
"zip 7.2.0",
]
+[[package]]
+name = "calamine"
+version = "0.36.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5fa68281b1a76b54a62156474adb06bb380a67e07dd60656e3217152b42183f3"
+dependencies = [
+ "atoi_simd 0.18.1",
+ "byteorder",
+ "chrono",
+ "codepage",
+ "encoding_rs",
+ "fast-float2",
+ "log",
+ "quick-xml 0.41.0",
+ "serde",
+ "zip 8.6.0",
+]
+
[[package]]
name = "camino"
version = "1.2.2"
@@ -885,6 +979,15 @@ dependencies = [
"toml 0.9.12+spec-1.1.0",
]
+[[package]]
+name = "cbc"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "26b52a9543ae338f279b96b0b9fed9c8093744685043739079ce85cd58f289a6"
+dependencies = [
+ "cipher",
+]
+
[[package]]
name = "cc"
version = "1.2.62"
@@ -920,6 +1023,17 @@ dependencies = [
"uuid",
]
+[[package]]
+name = "cfb"
+version = "0.14.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a347dcabdae9c31b0825fd6a8bed285ec9c2acb89c47827126d52fa4f59cece3"
+dependencies = [
+ "fnv",
+ "uuid",
+ "web-time",
+]
+
[[package]]
name = "cfg-expr"
version = "0.15.8"
@@ -942,6 +1056,17 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
+[[package]]
+name = "chacha20"
+version = "0.10.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d524456ba66e72eb8b115ff89e01e497f8e6d11d78b70b1aa13c0fbd97540a81"
+dependencies = [
+ "cfg-if",
+ "cpufeatures 0.3.0",
+ "rand_core 0.10.1",
+]
+
[[package]]
name = "chrono"
version = "0.4.44"
@@ -997,6 +1122,12 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b"
+[[package]]
+name = "colorchoice"
+version = "1.0.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570"
+
[[package]]
name = "combine"
version = "4.6.7"
@@ -2282,6 +2413,15 @@ version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0881ea181b1df73ff77ffaaf9c7544ecc11e82fba9b5f27b262a3c73a332555"
+[[package]]
+name = "ecb"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1a8bfa975b1aec2145850fcaa1c6fe269a16578c44705a532ae3edc92b8881c7"
+dependencies = [
+ "cipher",
+]
+
[[package]]
name = "either"
version = "1.15.0"
@@ -2408,12 +2548,35 @@ dependencies = [
"syn 2.0.117",
]
+[[package]]
+name = "env_filter"
+version = "2.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "900d271a03799a1ee8d1ca9b19893b48ca674a9284fefcfb85f05e74ed314217"
+dependencies = [
+ "log",
+ "regex",
+]
+
[[package]]
name = "env_home"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7f84e12ccf0a7ddc17a6c41c93326024c42920d7ee630d04950e6926645c0fe"
+[[package]]
+name = "env_logger"
+version = "0.11.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "de671bd27a75a797dc9ae289ba1e77276e75e2026408aab65185384e2d5cd3f6"
+dependencies = [
+ "anstream",
+ "anstyle",
+ "env_filter",
+ "jiff",
+ "log",
+]
+
[[package]]
name = "epub"
version = "2.1.5"
@@ -2914,10 +3077,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0de51e6874e94e7bf76d726fc5d13ba782deca734ff60d5bb2fb2607c7406555"
dependencies = [
"cfg-if",
+ "js-sys",
"libc",
"r-efi 6.0.0",
+ "rand_core 0.10.1",
"wasip2",
"wasip3",
+ "wasm-bindgen",
]
[[package]]
@@ -3517,6 +3683,25 @@ dependencies = [
"zune-jpeg",
]
+[[package]]
+name = "include_dir"
+version = "0.7.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "923d117408f1e49d914f1a379a309cffe4f18c05cf4e3d12e613a15fc81bd0dd"
+dependencies = [
+ "include_dir_macros",
+]
+
+[[package]]
+name = "include_dir_macros"
+version = "0.7.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7cab85a7ed0bd5f0e76d93846e0147172bed2e2d3f859bcc33a8d9699cad1a75"
+dependencies = [
+ "proc-macro2",
+ "quote",
+]
+
[[package]]
name = "indexmap"
version = "1.9.3"
@@ -3546,7 +3731,7 @@ version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a588916bfdfd92e71cacef98a63d9b1f0d74d6599980d11894290e7ddefffcf7"
dependencies = [
- "cfb",
+ "cfb 0.7.3",
]
[[package]]
@@ -3575,6 +3760,7 @@ version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01"
dependencies = [
+ "block-padding",
"generic-array",
]
@@ -3603,6 +3789,12 @@ dependencies = [
"once_cell",
]
+[[package]]
+name = "is_terminal_polyfill"
+version = "1.70.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695"
+
[[package]]
name = "itertools"
version = "0.13.0"
@@ -4561,12 +4753,13 @@ checksum = "11d3d7f243d5c5a8b9bb5d6dd2b1602c0cb0b9db1621bafc7ed66e35ff9fe092"
[[package]]
name = "llm-wiki"
-version = "0.6.7"
+version = "0.6.8"
dependencies = [
+ "anydoc",
"arrow-array",
"arrow-schema",
"base64 0.22.1",
- "calamine",
+ "calamine 0.34.0",
"chrono",
"docx-rs",
"epub",
@@ -4626,6 +4819,37 @@ dependencies = [
"tracing-subscriber",
]
+[[package]]
+name = "lopdf"
+version = "0.41.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "67513274c50a2b51e5f75d9e682fcf4ab064a8a9c9ae2c3c59309084882bb24d"
+dependencies = [
+ "aes",
+ "bitflags 2.11.1",
+ "cbc",
+ "chrono",
+ "ecb",
+ "encoding_rs",
+ "flate2",
+ "getrandom 0.4.2",
+ "indexmap 2.14.0",
+ "itoa",
+ "jiff",
+ "log",
+ "md-5",
+ "nom 8.0.0",
+ "rand 0.10.2",
+ "rangemap",
+ "rayon",
+ "sha2",
+ "stringprep",
+ "thiserror 2.0.18",
+ "time",
+ "ttf-parser",
+ "weezl",
+]
+
[[package]]
name = "lru"
version = "0.12.5"
@@ -5333,6 +5557,12 @@ version = "1.21.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
+[[package]]
+name = "once_cell_polyfill"
+version = "1.70.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
+
[[package]]
name = "oneshot"
version = "0.1.13"
@@ -5479,6 +5709,24 @@ dependencies = [
"hmac",
]
+[[package]]
+name = "pdf-inspector"
+version = "0.1.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f7475018de0880b394b7cc50f871fac0c010aa411dcd14c64074a3e640a4c05c"
+dependencies = [
+ "env_logger",
+ "include_dir",
+ "log",
+ "lopdf",
+ "once_cell",
+ "rayon",
+ "regex",
+ "thiserror 2.0.18",
+ "ttf-parser",
+ "unicode-normalization",
+]
+
[[package]]
name = "pdfium-render"
version = "0.9.1"
@@ -5928,6 +6176,16 @@ dependencies = [
"serde",
]
+[[package]]
+name = "quick-xml"
+version = "0.41.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e660451e55124f798a69a5af3f49ccfbefbd41910eefd25caf2393e1f3473ec1"
+dependencies = [
+ "encoding_rs",
+ "memchr",
+]
+
[[package]]
name = "quinn"
version = "0.11.9"
@@ -6031,6 +6289,17 @@ dependencies = [
"rand_core 0.9.5",
]
+[[package]]
+name = "rand"
+version = "0.10.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c7f5fa3a058cd35567ef9bfa5e75732bee0f9e4c55fa90477bef2dfcdbc4be80"
+dependencies = [
+ "chacha20",
+ "getrandom 0.4.2",
+ "rand_core 0.10.1",
+]
+
[[package]]
name = "rand_chacha"
version = "0.3.1"
@@ -6069,6 +6338,12 @@ dependencies = [
"getrandom 0.3.4",
]
+[[package]]
+name = "rand_core"
+version = "0.10.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69"
+
[[package]]
name = "rand_distr"
version = "0.4.3"
@@ -7027,6 +7302,17 @@ dependencies = [
"quote",
]
+[[package]]
+name = "stringprep"
+version = "0.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7b4df3d392d81bd458a8a621b8bffbd2302a12ffe288a9d931670948749463b1"
+dependencies = [
+ "unicode-bidi",
+ "unicode-normalization",
+ "unicode-properties",
+]
+
[[package]]
name = "strsim"
version = "0.11.1"
@@ -8204,6 +8490,12 @@ version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
+[[package]]
+name = "ttf-parser"
+version = "0.25.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d2df906b07856748fa3f6e0ad0cbaa047052d4a7dd609e231c4f72cee8c36f31"
+
[[package]]
name = "twox-hash"
version = "2.1.2"
@@ -8289,12 +8581,33 @@ version = "2.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dbc4bc3a9f746d862c45cb89d705aa10f187bb96c76001afab07a0d35ce60142"
+[[package]]
+name = "unicode-bidi"
+version = "0.3.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5c1cb5db39152898a79168971543b1cb5020dff7fe43c8dc468b0885f5e29df5"
+
[[package]]
name = "unicode-ident"
version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
+[[package]]
+name = "unicode-normalization"
+version = "0.1.25"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5fd4f6878c9cb28d874b009da9e8d183b5abc80117c40bbd187a1fde336be6e8"
+dependencies = [
+ "tinyvec",
+]
+
+[[package]]
+name = "unicode-properties"
+version = "0.1.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7df058c713841ad818f1dc5d3fd88063241cc61f49f5fbea4b951e8cf5a8d71d"
+
[[package]]
name = "unicode-segmentation"
version = "1.13.2"
@@ -8371,6 +8684,12 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
+[[package]]
+name = "utf8parse"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
+
[[package]]
name = "uuid"
version = "1.23.1"
diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml
index d91cbf1e..0dfe2769 100644
--- a/src-tauri/Cargo.toml
+++ b/src-tauri/Cargo.toml
@@ -1,9 +1,13 @@
[package]
name = "llm-wiki"
-version = "0.6.7"
+version = "0.6.8"
description = "LLM Wiki - A personal knowledge base for LLM concepts"
authors = []
edition = "2021"
+# AnyDoc and its archive/spreadsheet dependencies require Rust 1.88. Declaring
+# the floor here gives contributors an immediate toolchain error instead of a
+# late, platform-dependent dependency compilation failure.
+rust-version = "1.88"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@@ -35,6 +39,7 @@ zip = "2"
calamine = "0.34.0"
docx-rs = "0.4.20"
office_oxide = "=0.1.2"
+anydoc = "0.1.6"
lancedb = "0.27.2"
# tokio provided by tauri runtime for async commands
arrow-array = "57"
diff --git a/src-tauri/src/agent/provider.rs b/src-tauri/src/agent/provider.rs
index 05ddf870..b186a5a8 100644
--- a/src-tauri/src/agent/provider.rs
+++ b/src-tauri/src/agent/provider.rs
@@ -313,6 +313,7 @@ impl LlmClient {
if include_model {
body["model"] = Value::String(self.config.model.clone());
}
+ adapt_openai_strict_completion_body(&mut body, &self.config);
apply_openai_reasoning(&mut body, &self.config);
body
}
@@ -947,6 +948,22 @@ fn apply_openai_reasoning(body: &mut Value, config: &LlmConfig) {
}
}
+fn adapt_openai_strict_completion_body(body: &mut Value, config: &LlmConfig) {
+ let custom_azure = config.provider == "custom" && is_azure_endpoint(&config.custom_endpoint);
+ let strict_model = is_openai_reasoning_model(config)
+ || (custom_azure && config.azure_model_family.as_deref() == Some("gpt5"));
+ if !strict_model || (config.provider != "openai" && config.provider != "azure" && !custom_azure)
+ {
+ return;
+ }
+ if let Some(max_tokens) = body
+ .as_object_mut()
+ .and_then(|value| value.remove("max_tokens"))
+ {
+ body["max_completion_tokens"] = max_tokens;
+ }
+}
+
fn apply_anthropic_reasoning(body: &mut Value, config: &LlmConfig) {
let Some(reasoning) = config.reasoning.as_ref() else {
return;
@@ -1240,6 +1257,66 @@ mod tests {
);
}
+ #[test]
+ fn azure_gpt5_uses_max_completion_tokens() {
+ let mut cfg = config("azure");
+ cfg.model = "deployment-name-does-not-identify-model".to_string();
+ cfg.azure_model_family = Some("gpt5".to_string());
+ let body =
+ LlmClient::new(cfg)
+ .unwrap()
+ .openai_like_body("system", "user", &[], false, false);
+
+ assert_eq!(
+ body.get("max_completion_tokens").and_then(Value::as_u64),
+ Some(DEFAULT_MAX_TOKENS as u64)
+ );
+ assert!(body.get("max_tokens").is_none());
+ }
+
+ #[test]
+ fn openai_o_series_uses_max_completion_tokens() {
+ let mut cfg = config("openai");
+ cfg.model = "o3-mini".to_string();
+ let body =
+ LlmClient::new(cfg)
+ .unwrap()
+ .openai_like_body("system", "user", &[], true, false);
+
+ assert!(body.get("max_completion_tokens").is_some());
+ assert!(body.get("max_tokens").is_none());
+ }
+
+ #[test]
+ fn ordinary_azure_model_keeps_max_tokens() {
+ let mut cfg = config("azure");
+ cfg.model = "gpt-4o".to_string();
+ cfg.azure_model_family = Some("standard".to_string());
+ let body =
+ LlmClient::new(cfg)
+ .unwrap()
+ .openai_like_body("system", "user", &[], false, false);
+
+ assert!(body.get("max_tokens").is_some());
+ assert!(body.get("max_completion_tokens").is_none());
+ }
+
+ #[test]
+ fn custom_azure_gpt5_deployment_uses_max_completion_tokens() {
+ let mut cfg = config("custom");
+ cfg.custom_endpoint =
+ "https://example.openai.azure.com/openai/deployments/prod".to_string();
+ cfg.model = "deployment-name".to_string();
+ cfg.azure_model_family = Some("gpt5".to_string());
+ let body =
+ LlmClient::new(cfg)
+ .unwrap()
+ .openai_like_body("system", "user", &[], false, false);
+
+ assert!(body.get("max_completion_tokens").is_some());
+ assert!(body.get("max_tokens").is_none());
+ }
+
#[test]
fn generic_custom_gateway_does_not_receive_openai_reasoning_fields() {
let mut cfg = config("custom");
diff --git a/src-tauri/src/agent/tools.rs b/src-tauri/src/agent/tools.rs
index caeb367f..4d41f46e 100644
--- a/src-tauri/src/agent/tools.rs
+++ b/src-tauri/src/agent/tools.rs
@@ -2452,12 +2452,22 @@ pub fn search_sources(
"pdf"
| "doc"
| "docx"
+ | "docm"
+ | "ppt"
+ | "pps"
+ | "pot"
| "pptx"
+ | "pptm"
+ | "ppsx"
+ | "ppsm"
| "xls"
| "xlsx"
+ | "xlsm"
+ | "xlsb"
| "odt"
| "ods"
| "odp"
+ | "rtf"
| "epub"
| "mobi"
) {
diff --git a/src-tauri/src/api_server.rs b/src-tauri/src/api_server.rs
index 0d8ebb83..933cd176 100644
--- a/src-tauri/src/api_server.rs
+++ b/src-tauri/src/api_server.rs
@@ -892,17 +892,7 @@ fn is_text_content_rel(rel: &str) -> bool {
.unwrap_or("");
matches!(
ext,
- "md" | "mdx"
- | "txt"
- | "csv"
- | "json"
- | "yaml"
- | "yml"
- | "xml"
- | "html"
- | "htm"
- | "rtf"
- | "log"
+ "md" | "mdx" | "txt" | "csv" | "json" | "yaml" | "yml" | "xml" | "html" | "htm" | "log"
)
}
@@ -2681,6 +2671,7 @@ mod tests {
assert!(is_text_content_rel("wiki/index.md"));
assert!(!is_text_content_rel("wiki/media/image.png"));
assert!(!is_text_content_rel("raw/sources/book.pdf"));
+ assert!(!is_text_content_rel("raw/sources/notes.rtf"));
}
#[test]
diff --git a/src-tauri/src/commands/file_history.rs b/src-tauri/src/commands/file_history.rs
index 12e61b6c..44a910b1 100644
--- a/src-tauri/src/commands/file_history.rs
+++ b/src-tauri/src/commands/file_history.rs
@@ -8,6 +8,8 @@ use uuid::Uuid;
const MAX_HISTORY_CONTENT_BYTES: usize = 512 * 1024;
const MAX_ENTRIES_PER_FILE: usize = 30;
+const MAX_HISTORY_STORE_BYTES: u64 = 128 * 1024 * 1024;
+const MAX_HISTORY_STORE_FILES: usize = 2_048;
static HISTORY_LOCK: Mutex<()> = Mutex::new(());
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -21,12 +23,21 @@ pub struct FileHistoryEntry {
pub content: String,
}
+#[derive(Debug, Clone, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub struct FileHistoryStats {
+ pub bytes: u64,
+ pub files: usize,
+ pub entries: usize,
+}
+
/// Return provenance only, never historical content, for Agent retrieval
/// briefings. Reading the same bounded store as the timeline keeps attribution
/// consistent without expanding prompt size or exposing rollback snapshots.
pub fn latest_file_version(path: &Path) -> Option<(i64, String, String)> {
let root = project_root_for(path)?;
let _guard = HISTORY_LOCK.lock().ok()?;
+ checked_history_dir(&root, false).ok()?;
let raw = fs::read_to_string(history_path(&root, path)).ok()?;
let entries: Vec<FileHistoryEntry> = serde_json::from_str(&raw).ok()?;
entries
@@ -57,6 +68,79 @@ fn history_path(root: &Path, path: &Path) -> PathBuf {
root.join(".llm-wiki/history").join(format!("{key}.json"))
}
+fn history_dir(root: &Path) -> PathBuf {
+ root.join(".llm-wiki/history")
+}
+
+fn checked_history_dir(root: &Path, create: bool) -> Result<PathBuf, String> {
+ let canonical_root = root.canonicalize().map_err(|e| e.to_string())?;
+ let metadata_dir = canonical_root.join(".llm-wiki");
+ let metadata = fs::symlink_metadata(&metadata_dir).map_err(|e| e.to_string())?;
+ if !metadata.is_dir() || metadata.file_type().is_symlink() {
+ return Err("History metadata directory must be a real project directory".to_string());
+ }
+
+ let dir = metadata_dir.join("history");
+ if create {
+ fs::create_dir_all(&dir).map_err(|e| e.to_string())?;
+ } else if !dir.exists() {
+ return Ok(dir);
+ }
+ let dir_metadata = fs::symlink_metadata(&dir).map_err(|e| e.to_string())?;
+ if !dir_metadata.is_dir() || dir_metadata.file_type().is_symlink() {
+ return Err("History directory must not be a symlink".to_string());
+ }
+ let canonical_dir = dir.canonicalize().map_err(|e| e.to_string())?;
+ if !canonical_dir.starts_with(&metadata_dir) {
+ return Err("History directory must stay inside the project".to_string());
+ }
+ Ok(canonical_dir)
+}
+
+fn history_files_oldest_first(root: &Path) -> Vec<(PathBuf, u64, std::time::SystemTime)> {
+ let Ok(entries) = fs::read_dir(history_dir(root)) else {
+ return Vec::new();
+ };
+ let mut files: Vec<_> = entries
+ .flatten()
+ .filter_map(|entry| {
+ let metadata = entry.metadata().ok()?;
+ if !metadata.is_file()
+ || entry.path().extension().and_then(|ext| ext.to_str()) != Some("json")
+ {
+ return None;
+ }
+ Some((
+ entry.path(),
+ metadata.len(),
+ metadata
+ .modified()
+ .unwrap_or(std::time::SystemTime::UNIX_EPOCH),
+ ))
+ })
+ .collect();
+ files.sort_by_key(|(_, _, modified)| *modified);
+ files
+}
+
+fn prune_history_store(root: &Path, protected_path: &Path) {
+ let files = history_files_oldest_first(root);
+ let mut total_bytes = files.iter().map(|(_, bytes, _)| *bytes).sum::<u64>();
+ let mut total_files = files.len();
+ for (path, bytes, _) in files {
+ if total_bytes <= MAX_HISTORY_STORE_BYTES && total_files <= MAX_HISTORY_STORE_FILES {
+ break;
+ }
+ if path == protected_path {
+ continue;
+ }
+ if fs::remove_file(&path).is_ok() {
+ total_bytes = total_bytes.saturating_sub(bytes);
+ total_files = total_files.saturating_sub(1);
+ }
+ }
+}
+
pub fn record_file_version(path: &Path, author: &str, tool: &str) {
let Ok(metadata) = fs::metadata(path) else {
return;
@@ -76,7 +160,13 @@ pub fn record_file_version(path: &Path, author: &str, tool: &str) {
let Ok(_guard) = HISTORY_LOCK.lock() else {
return;
};
- let store_path = history_path(&root, path);
+ let Ok(dir) = checked_history_dir(&root, true) else {
+ return;
+ };
+ let Some(file_name) = history_path(&root, path).file_name().map(ToOwned::to_owned) else {
+ return;
+ };
+ let store_path = dir.join(file_name);
let mut entries: Vec<FileHistoryEntry> = fs::read_to_string(&store_path)
.ok()
.and_then(|raw| serde_json::from_str(&raw).ok())
@@ -95,12 +185,21 @@ pub fn record_file_version(path: &Path, author: &str, tool: &str) {
if entries.len() > MAX_ENTRIES_PER_FILE {
entries.drain(..entries.len() - MAX_ENTRIES_PER_FILE);
}
- if let Some(parent) = store_path.parent() {
- let _ = fs::create_dir_all(parent);
- }
if let Ok(raw) = serde_json::to_string(&entries) {
- let _ = fs::write(store_path, raw);
+ if fs::write(&store_path, raw).is_ok() {
+ prune_history_store(&root, &store_path);
+ }
+ }
+}
+
+fn checked_project_root(project_path: &str) -> Result<PathBuf, String> {
+ let root = Path::new(project_path)
+ .canonicalize()
+ .map_err(|e| e.to_string())?;
+ if !root.join(".llm-wiki").is_dir() {
+ return Err("History project must contain .llm-wiki".to_string());
}
+ Ok(root)
}
fn checked_file(project_path: &str, file_path: &str) -> Result<(PathBuf, PathBuf), String> {
@@ -123,6 +222,8 @@ pub async fn list_file_history(
) -> Result<Vec<FileHistoryEntry>, String> {
tauri::async_runtime::spawn_blocking(move || {
let (root, file) = checked_file(&project_path, &file_path)?;
+ let _guard = HISTORY_LOCK.lock().map_err(|e| e.to_string())?;
+ checked_history_dir(&root, false)?;
let raw =
fs::read_to_string(history_path(&root, &file)).unwrap_or_else(|_| "[]".to_string());
let mut entries: Vec<FileHistoryEntry> = serde_json::from_str(&raw).unwrap_or_default();
@@ -141,16 +242,59 @@ pub async fn restore_file_history(
) -> Result<String, String> {
tauri::async_runtime::spawn_blocking(move || {
let (root, file) = checked_file(&project_path, &file_path)?;
- let raw = fs::read_to_string(history_path(&root, &file)).map_err(|e| e.to_string())?;
- let entries: Vec<FileHistoryEntry> =
- serde_json::from_str(&raw).map_err(|e| e.to_string())?;
- let entry = entries
- .into_iter()
- .find(|entry| entry.id == entry_id)
- .ok_or_else(|| "History entry not found".to_string())?;
- fs::write(&file, &entry.content).map_err(|e| e.to_string())?;
+ let content = {
+ let _guard = HISTORY_LOCK.lock().map_err(|e| e.to_string())?;
+ checked_history_dir(&root, false)?;
+ let raw = fs::read_to_string(history_path(&root, &file)).map_err(|e| e.to_string())?;
+ let entries: Vec<FileHistoryEntry> =
+ serde_json::from_str(&raw).map_err(|e| e.to_string())?;
+ let entry = entries
+ .into_iter()
+ .find(|entry| entry.id == entry_id)
+ .ok_or_else(|| "History entry not found".to_string())?;
+ fs::write(&file, &entry.content).map_err(|e| e.to_string())?;
+ entry.content
+ };
record_file_version(&file, "human", "history.restore");
- Ok(entry.content)
+ Ok(content)
+ })
+ .await
+ .map_err(|e| e.to_string())?
+}
+
+#[tauri::command]
+pub async fn get_file_history_stats(project_path: String) -> Result<FileHistoryStats, String> {
+ tauri::async_runtime::spawn_blocking(move || {
+ let root = checked_project_root(&project_path)?;
+ let _guard = HISTORY_LOCK.lock().map_err(|e| e.to_string())?;
+ checked_history_dir(&root, false)?;
+ let files = history_files_oldest_first(&root);
+ let entries = files
+ .iter()
+ .filter_map(|(path, _, _)| fs::read_to_string(path).ok())
+ .filter_map(|raw| serde_json::from_str::<Vec<FileHistoryEntry>>(&raw).ok())
+ .map(|entries| entries.len())
+ .sum();
+ Ok(FileHistoryStats {
+ bytes: files.iter().map(|(_, bytes, _)| *bytes).sum(),
+ files: files.len(),
+ entries,
+ })
+ })
+ .await
+ .map_err(|e| e.to_string())?
+}
+
+#[tauri::command]
+pub async fn clear_file_history(project_path: String) -> Result<(), String> {
+ tauri::async_runtime::spawn_blocking(move || {
+ let root = checked_project_root(&project_path)?;
+ let _guard = HISTORY_LOCK.lock().map_err(|e| e.to_string())?;
+ let dir = checked_history_dir(&root, false)?;
+ if dir.exists() {
+ fs::remove_dir_all(&dir).map_err(|e| e.to_string())?;
+ }
+ Ok(())
})
.await
.map_err(|e| e.to_string())?
@@ -199,4 +343,55 @@ mod tests {
assert_eq!(restored.first().unwrap().tool, "history.restore");
let _ = fs::remove_dir_all(root);
}
+
+ #[tokio::test]
+ async fn reports_and_clears_project_history_without_touching_current_files() {
+ let root = std::env::temp_dir().join(format!("llm-wiki-history-{}", Uuid::new_v4()));
+ fs::create_dir_all(root.join(".llm-wiki")).unwrap();
+ fs::create_dir_all(root.join("wiki")).unwrap();
+ let file = root.join("wiki/page.md");
+ fs::write(&file, "current").unwrap();
+ record_file_version(&file, "agent", "test.write");
+
+ let stats = get_file_history_stats(root.to_string_lossy().into_owned())
+ .await
+ .unwrap();
+ assert_eq!(stats.files, 1);
+ assert_eq!(stats.entries, 1);
+ assert!(stats.bytes > 0);
+
+ clear_file_history(root.to_string_lossy().into_owned())
+ .await
+ .unwrap();
+ assert_eq!(fs::read_to_string(&file).unwrap(), "current");
+ let cleared = get_file_history_stats(root.to_string_lossy().into_owned())
+ .await
+ .unwrap();
+ assert_eq!(cleared.files, 0);
+ assert_eq!(cleared.entries, 0);
+ assert_eq!(cleared.bytes, 0);
+ let _ = fs::remove_dir_all(root);
+ }
+
+ #[cfg(unix)]
+ #[test]
+ fn refuses_history_directory_symlink_escape() {
+ use std::os::unix::fs::symlink;
+
+ let root = std::env::temp_dir().join(format!("llm-wiki-history-{}", Uuid::new_v4()));
+ let outside =
+ std::env::temp_dir().join(format!("llm-wiki-history-outside-{}", Uuid::new_v4()));
+ fs::create_dir_all(root.join(".llm-wiki")).unwrap();
+ fs::create_dir_all(root.join("wiki")).unwrap();
+ fs::create_dir_all(&outside).unwrap();
+ symlink(&outside, root.join(".llm-wiki/history")).unwrap();
+ let file = root.join("wiki/page.md");
+ fs::write(&file, "current").unwrap();
+
+ record_file_version(&file, "agent", "test.write");
+
+ assert_eq!(fs::read_dir(&outside).unwrap().count(), 0);
+ let _ = fs::remove_dir_all(root);
+ let _ = fs::remove_dir_all(outside);
+ }
}
diff --git a/src-tauri/src/commands/fs.rs b/src-tauri/src/commands/fs.rs
index f6ac8bc6..da94dd18 100644
--- a/src-tauri/src/commands/fs.rs
+++ b/src-tauri/src/commands/fs.rs
@@ -12,7 +12,15 @@ use crate::panic_guard::run_guarded;
use crate::types::wiki::FileNode;
/// Known binary formats that need special extraction
-const OFFICE_EXTS: &[&str] = &["doc", "docx", "pptx", "xls", "xlsx", "odt", "ods", "odp"];
+/// Formats handled by AnyDoc's shared document model. Keep this list aligned
+/// with `anydoc::Format::from_extension`; the explicit list is still needed so
+/// arbitrary binary files never reach a parser merely because detection is
+/// permissive. PDF and EPUB intentionally remain on the existing pipelines:
+/// PDFium also extracts images, while the ebook path retains MOBI parity.
+const OFFICE_EXTS: &[&str] = &[
+ "doc", "docx", "docm", "ppt", "pps", "pot", "pptx", "pptm", "ppsx", "ppsm", "xls", "xlsx",
+ "xlsm", "xlsb", "odt", "ods", "odp", "rtf",
+];
const IMAGE_EXTS: &[&str] = &[
"png", "jpg", "jpeg", "gif", "webp", "bmp", "ico", "tiff", "tif", "avif", "heic", "heif", "svg",
];
@@ -21,7 +29,8 @@ const MEDIA_EXTS: &[&str] = &[
"m4a", "wma",
];
const EBOOK_EXTS: &[&str] = &["epub", "mobi"];
-const LEGACY_DOC_EXTS: &[&str] = &["ppt", "pages", "numbers", "key"];
+const LEGACY_DOC_EXTS: &[&str] = &["pages", "numbers", "key"];
+const OFFICE_CACHE_FORMAT: &str = "anydoc-0.1.6-v1";
fn require_absolute_path(operation: &str, path: &str) -> Result<(), String> {
if is_absolute_path_cross_platform(path) {
@@ -158,8 +167,32 @@ fn cache_path_for(original: &Path) -> std::path::PathBuf {
cache_dir.join(format!("{}.txt", file_name))
}
+fn cache_format_path_for(original: &Path) -> std::path::PathBuf {
+ let cache_path = cache_path_for(original);
+ cache_path.with_extension("txt.parser")
+}
+
+fn uses_anydoc_cache(original: &Path) -> bool {
+ original
+ .extension()
+ .and_then(|extension| extension.to_str())
+ .map(|extension| {
+ let extension = extension.to_ascii_lowercase();
+ OFFICE_EXTS.contains(&extension.as_str())
+ })
+ .unwrap_or(false)
+}
+
fn read_cache(original: &Path) -> Option<String> {
let cache_path = cache_path_for(original);
+ if uses_anydoc_cache(original)
+ && fs::read_to_string(cache_format_path_for(original))
+ .ok()?
+ .trim()
+ != OFFICE_CACHE_FORMAT
+ {
+ return None;
+ }
let original_modified = fs::metadata(original).ok()?.modified().ok()?;
let cache_modified = fs::metadata(&cache_path).ok()?.modified().ok()?;
if cache_modified >= original_modified {
@@ -182,10 +215,23 @@ pub(crate) fn read_preprocessed_cache(original: &Path) -> Option<String> {
fn write_cache(original: &Path, text: &str) -> Result<(), String> {
let cache_path = cache_path_for(original);
if let Some(parent) = cache_path.parent() {
- fs::create_dir_all(parent).ok();
+ fs::create_dir_all(parent)
+ .map_err(|e| format!("Failed to create preprocessing cache directory: {e}"))?;
}
crate::commands::file_sync::mark_app_write_path(&cache_path);
- fs::write(&cache_path, text).map_err(|e| format!("Failed to write cache: {}", e))
+ let format_path = cache_format_path_for(original);
+ if uses_anydoc_cache(original) {
+ // Remove the validity marker before replacing content. A crash or I/O
+ // error can then cause an extra rebuild, never acceptance of stale text.
+ let _ = fs::remove_file(&format_path);
+ }
+ fs::write(&cache_path, text).map_err(|e| format!("Failed to write cache: {e}"))?;
+ if uses_anydoc_cache(original) {
+ crate::commands::file_sync::mark_app_write_path(&format_path);
+ fs::write(&format_path, OFFICE_CACHE_FORMAT)
+ .map_err(|e| format!("Failed to write preprocessing cache format marker: {e}"))?;
+ }
+ Ok(())
}
/// Convert common Org syntax into Markdown-shaped text for ingestion and
@@ -546,6 +592,53 @@ fn extract_pdf_text(path: &str, include_images: bool) -> Result<String, String>
/// Extract text from Office Open XML formats, converting to Markdown.
fn extract_office_text(path: &str, ext: &str) -> Result<String, String> {
+ let mut anydoc_failure = None;
+ match anydoc::to_markdown(path) {
+ Ok(markdown) if !markdown.trim().is_empty() => return Ok(markdown),
+ Ok(_) => {
+ eprintln!(
+ "[anydoc] '{}' produced empty Markdown; trying the compatibility parser",
+ path
+ );
+ }
+ Err(anydoc::ConvertError::ResourceLimit { limit, detail }) => {
+ // Never bypass AnyDoc's abuse limits by feeding the same hostile
+ // input to a less constrained compatibility parser.
+ return Err(format!(
+ "Document exceeds the AnyDoc safety limit '{limit}': {detail}"
+ ));
+ }
+ Err(anydoc::ConvertError::Encrypted) => {
+ return Err("Encrypted or password-protected documents are not supported".to_string());
+ }
+ Err(error) => {
+ eprintln!(
+ "[anydoc] failed to parse '{}' ({}); trying the compatibility parser",
+ path, error
+ );
+ anydoc_failure = Some(error.to_string());
+ }
+ }
+
+ extract_office_text_compat(path, ext).map_err(|compat_error| match anydoc_failure {
+ Some(anydoc_error) => format!(
+ "AnyDoc failed to extract .{ext}: {anydoc_error}; compatibility parser failed: {compat_error}"
+ ),
+ None => compat_error,
+ })
+}
+
+/// Compatibility path for formats supported before AnyDoc was introduced.
+/// New AnyDoc-only variants deliberately return the original-format error
+/// rather than being read as UTF-8 or reported as a successful empty import.
+fn extract_office_text_compat(path: &str, ext: &str) -> Result<String, String> {
+ if !matches!(
+ ext,
+ "doc" | "docx" | "pptx" | "xls" | "xlsx" | "odt" | "ods" | "odp"
+ ) {
+ return Err(format!("no compatibility parser is available for .{ext}"));
+ }
+
// Spreadsheets: use calamine (supports xlsx, xls, ods)
if matches!(ext, "xlsx" | "xls" | "ods") {
return extract_spreadsheet(path);
@@ -569,7 +662,9 @@ fn extract_office_text(path: &str, ext: &str) -> Result<String, String> {
match ext {
"pptx" => extract_pptx_markdown(&mut archive),
"odt" | "odp" => extract_odf_text(&mut archive),
- _ => Ok("[Unsupported format]".to_string()),
+ _ => Err(format!(
+ "AnyDoc could not extract .{ext} and no compatibility parser is available"
+ )),
}
}
@@ -1949,11 +2044,197 @@ pub async fn get_file_md5(path: String) -> Result<String, String> {
.map_err(|e| format!("get_file_md5 blocking task join error: {e}"))?
}
+#[cfg(test)]
+#[path = "fs_anydoc_benchmark.rs"]
+mod anydoc_benchmark;
+
#[cfg(test)]
mod tests {
use super::*;
use std::io::Write;
+ fn tmp_file_with_extension(extension: &str, bytes: &[u8]) -> std::path::PathBuf {
+ let path = std::env::temp_dir().join(format!(
+ "llm-wiki-anydoc-{}.{}",
+ uuid::Uuid::new_v4(),
+ extension
+ ));
+ fs::write(&path, bytes).unwrap();
+ path
+ }
+
+ fn tmp_zip_with_entries(extension: &str, entries: &[(&str, &str)]) -> std::path::PathBuf {
+ let path = tmp_file_with_extension(extension, &[]);
+ let file = fs::File::create(&path).unwrap();
+ let mut archive = zip::ZipWriter::new(file);
+ let options = zip::write::SimpleFileOptions::default();
+ for (name, content) in entries {
+ archive.start_file(*name, options).unwrap();
+ archive.write_all(content.as_bytes()).unwrap();
+ }
+ archive.finish().unwrap();
+ path
+ }
+
+ fn minimal_docx() -> std::path::PathBuf {
+ tmp_zip_with_entries(
+ "docx",
+ &[
+ (
+ "[Content_Types].xml",
+ r#"<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/></Types>"#,
+ ),
+ (
+ "_rels/.rels",
+ r#"<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/></Relationships>"#,
+ ),
+ (
+ "word/document.xml",
+ r#"<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:body><w:p><w:r><w:t>AnyDoc 中文 Word</w:t></w:r></w:p><w:tbl><w:tr><w:tc><w:p><w:r><w:t>Name</w:t></w:r></w:p></w:tc><w:tc><w:p><w:r><w:t>Value</w:t></w:r></w:p></w:tc></w:tr><w:tr><w:tc><w:p><w:r><w:t>Alpha</w:t></w:r></w:p></w:tc><w:tc><w:p><w:r><w:t>42</w:t></w:r></w:p></w:tc></w:tr></w:tbl></w:body></w:document>"#,
+ ),
+ ],
+ )
+ }
+
+ fn minimal_pptx() -> std::path::PathBuf {
+ tmp_zip_with_entries(
+ "pptx",
+ &[
+ (
+ "[Content_Types].xml",
+ r#"<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Override PartName="/ppt/presentation.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml"/><Override PartName="/ppt/slides/slide1.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slide+xml"/></Types>"#,
+ ),
+ (
+ "_rels/.rels",
+ r#"<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="ppt/presentation.xml"/></Relationships>"#,
+ ),
+ (
+ "ppt/presentation.xml",
+ r#"<p:presentation xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><p:sldIdLst><p:sldId id="256" r:id="rId1"/></p:sldIdLst></p:presentation>"#,
+ ),
+ (
+ "ppt/_rels/presentation.xml.rels",
+ r#"<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide" Target="slides/slide1.xml"/></Relationships>"#,
+ ),
+ (
+ "ppt/slides/slide1.xml",
+ r#"<p:sld xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"><p:cSld><p:spTree><p:nvGrpSpPr><p:cNvPr id="1" name=""/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr><p:grpSpPr/><p:sp><p:nvSpPr><p:cNvPr id="2" name="Title"/><p:cNvSpPr/><p:nvPr><p:ph type="title"/></p:nvPr></p:nvSpPr><p:spPr/><p:txBody><a:bodyPr/><a:p><a:r><a:t>AnyDoc 演示文稿</a:t></a:r></a:p></p:txBody></p:sp></p:spTree></p:cSld></p:sld>"#,
+ ),
+ ],
+ )
+ }
+
+ fn minimal_xlsx() -> std::path::PathBuf {
+ tmp_zip_with_entries(
+ "xlsx",
+ &[
+ (
+ "[Content_Types].xml",
+ r#"<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/><Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/></Types>"#,
+ ),
+ (
+ "_rels/.rels",
+ r#"<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml"/></Relationships>"#,
+ ),
+ (
+ "xl/workbook.xml",
+ r#"<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><sheets><sheet name="Data" sheetId="1" r:id="rId1"/></sheets></workbook>"#,
+ ),
+ (
+ "xl/_rels/workbook.xml.rels",
+ r#"<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet1.xml"/></Relationships>"#,
+ ),
+ (
+ "xl/worksheets/sheet1.xml",
+ r#"<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><sheetData><row r="1"><c r="A1" t="inlineStr"><is><t>Metric</t></is></c><c r="B1" t="inlineStr"><is><t>Value</t></is></c></row><row r="2"><c r="A2" t="inlineStr"><is><t>安全</t></is></c><c r="B2"><v>99</v></c></row></sheetData></worksheet>"#,
+ ),
+ ],
+ )
+ }
+
+ fn minimal_odt() -> std::path::PathBuf {
+ tmp_zip_with_entries(
+ "odt",
+ &[
+ ("mimetype", "application/vnd.oasis.opendocument.text"),
+ (
+ "content.xml",
+ r#"<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"><office:body><office:text><text:h text:outline-level="1">AnyDoc ODT</text:h><text:p>跨平台开放文档内容。</text:p></office:text></office:body></office:document-content>"#,
+ ),
+ ],
+ )
+ }
+
+ #[test]
+ fn anydoc_extracts_rtf_through_the_office_pipeline() {
+ let path = tmp_file_with_extension(
+ "rtf",
+ br#"{\rtf1\ansi\deff0 {\fonttbl {\f0 Arial;}}\f0\fs24 AnyDoc \b structured\b0 text.}"#,
+ );
+ let output = extract_office_text(path.to_str().unwrap(), "rtf").unwrap();
+ fs::remove_file(&path).unwrap();
+
+ assert!(output.contains("AnyDoc"));
+ assert!(output.contains("**structured**"));
+ }
+
+ #[test]
+ fn anydoc_extracts_generated_structured_document_fixtures() {
+ let fixtures = [
+ (
+ minimal_docx(),
+ "docx",
+ &["AnyDoc 中文 Word", "Alpha", "42"][..],
+ ),
+ (minimal_pptx(), "pptx", &["AnyDoc 演示文稿"][..]),
+ (minimal_xlsx(), "xlsx", &["Metric", "安全", "99"][..]),
+ (
+ minimal_odt(),
+ "odt",
+ &["AnyDoc ODT", "跨平台开放文档内容"][..],
+ ),
+ ];
+
+ for (path, extension, expected_fragments) in fixtures {
+ let output = extract_office_text(path.to_str().unwrap(), extension).unwrap();
+ for fragment in expected_fragments {
+ assert!(
+ output.contains(fragment),
+ ".{extension} output did not contain {fragment:?}: {output}"
+ );
+ }
+ fs::remove_file(path).unwrap();
+ }
+ }
+
+ #[test]
+ fn anydoc_only_formats_do_not_report_success_after_parse_failure() {
+ let path = tmp_file_with_extension("xlsb", b"not a workbook");
+ let result = extract_office_text(path.to_str().unwrap(), "xlsb");
+ fs::remove_file(path).unwrap();
+
+ assert!(result.is_err());
+ let error = result.unwrap_err();
+ assert!(error.contains("AnyDoc failed to extract .xlsb"));
+ assert!(error.contains("no compatibility parser"));
+ }
+
+ #[test]
+ fn office_cache_requires_the_current_anydoc_format_marker() {
+ let path = tmp_file_with_extension("docx", b"source placeholder");
+ let cache_path = cache_path_for(&path);
+ fs::create_dir_all(cache_path.parent().unwrap()).unwrap();
+ fs::write(&cache_path, "legacy parser output").unwrap();
+ assert_eq!(read_cache(&path), None);
+
+ fs::write(cache_format_path_for(&path), OFFICE_CACHE_FORMAT).unwrap();
+ assert_eq!(read_cache(&path).as_deref(), Some("legacy parser output"));
+
+ fs::remove_file(&path).unwrap();
+ fs::remove_file(cache_path).unwrap();
+ fs::remove_file(cache_format_path_for(&path)).unwrap();
+ }
+
#[test]
fn org_to_markdown_preserves_common_elements_without_executing_source_blocks() {
let input = "#+TITLE: Research Notes\r\n#+AUTHOR: Ada\r\n* TODO Topic :rust:notes:\r\nParagraph with [[https://example.com][reference]] and [[file:local.pdf]].\r\n- [ ] Verify\r\n| Name | Value |\r\n|------+-------|\r\n| A | 1 |\r\n#+BEGIN_SRC sh\r\necho never-run\r\n#+END_SRC\r\n";
diff --git a/src-tauri/src/commands/fs_anydoc_benchmark.rs b/src-tauri/src/commands/fs_anydoc_benchmark.rs
new file mode 100644
index 00000000..16fef68a
--- /dev/null
+++ b/src-tauri/src/commands/fs_anydoc_benchmark.rs
@@ -0,0 +1,297 @@
+//! Local-only comparison harness for AnyDoc and the compatibility parsers.
+//!
+//! This module is compiled only for Rust tests and its benchmark is ignored by
+//! default. It never changes the production parser selection or writes into a
+//! project. Point `ANYDOC_BENCH_DIR` at a fixture corpus or real document tree:
+//!
+//! ```text
+//! ANYDOC_BENCH_DIR=/path/to/documents cargo test --lib \
+//! commands::fs::anydoc_benchmark::compare_anydoc_with_legacy -- \
+//! --ignored --nocapture
+//! ```
+
+use super::extract_office_text_compat;
+use serde::Serialize;
+use std::collections::BTreeMap;
+use std::path::{Path, PathBuf};
+use std::time::{Duration, Instant};
+
+const BENCH_EXTENSIONS: &[&str] = &[
+ "doc", "docx", "docm", "ppt", "pps", "pot", "pptx", "pptm", "ppsx", "ppsm", "xls", "xlsx",
+ "xlsm", "xlsb", "odt", "ods", "odp", "rtf",
+];
+
+#[derive(Clone, Debug, Default, Serialize)]
+#[serde(rename_all = "camelCase")]
+struct StructureStats {
+ chars: usize,
+ headings: usize,
+ list_items: usize,
+ table_rows: usize,
+ links: usize,
+ footnotes: usize,
+}
+
+#[derive(Debug, Default, Serialize)]
+#[serde(rename_all = "camelCase")]
+struct FormatSummary {
+ files: usize,
+ anydoc_ok: usize,
+ legacy_supported: usize,
+ legacy_ok: usize,
+ output_differences: usize,
+ anydoc_micros: u128,
+ legacy_micros: u128,
+ anydoc_structure: StructureStats,
+ legacy_structure: StructureStats,
+}
+
+#[derive(Debug, Serialize)]
+#[serde(rename_all = "camelCase")]
+struct FileComparison {
+ path: String,
+ extension: String,
+ anydoc_ok: bool,
+ legacy_supported: bool,
+ legacy_ok: bool,
+ anydoc_micros: u128,
+ legacy_micros: Option<u128>,
+ anydoc: Option<StructureStats>,
+ legacy: Option<StructureStats>,
+ output_equal: Option<bool>,
+ anydoc_error: Option<String>,
+ legacy_error: Option<String>,
+}
+
+#[derive(Debug, Serialize)]
+#[serde(rename_all = "camelCase")]
+struct BenchmarkReport {
+ root: String,
+ iterations: usize,
+ files: Vec<FileComparison>,
+ by_format: BTreeMap<String, FormatSummary>,
+}
+
+fn legacy_supports(extension: &str) -> bool {
+ matches!(
+ extension,
+ "doc" | "docx" | "pptx" | "xls" | "xlsx" | "odt" | "ods" | "odp"
+ )
+}
+
+fn collect_documents(root: &Path, output: &mut Vec<PathBuf>) {
+ let Ok(entries) = std::fs::read_dir(root) else {
+ return;
+ };
+ for entry in entries.flatten() {
+ let path = entry.path();
+ if path.is_dir() {
+ let name = path
+ .file_name()
+ .and_then(|name| name.to_str())
+ .unwrap_or("");
+ // Invalid/abuse corpora measure error handling rather than output
+ // quality and can dominate timing with intentional resource caps.
+ if !matches!(name, "abuse" | "malformed") {
+ collect_documents(&path, output);
+ }
+ continue;
+ }
+ let extension = path
+ .extension()
+ .and_then(|extension| extension.to_str())
+ .unwrap_or("")
+ .to_ascii_lowercase();
+ if BENCH_EXTENSIONS.contains(&extension.as_str()) {
+ output.push(path);
+ }
+ }
+}
+
+fn structure_stats(markdown: &str) -> StructureStats {
+ let mut stats = StructureStats {
+ chars: markdown.chars().count(),
+ ..Default::default()
+ };
+ for line in markdown.lines() {
+ let trimmed = line.trim_start();
+ if trimmed.starts_with('#') && trimmed.chars().take_while(|ch| *ch == '#').count() <= 6 {
+ stats.headings += 1;
+ }
+ if trimmed.starts_with("- ")
+ || trimmed.starts_with("* ")
+ || trimmed
+ .split_once(". ")
+ .is_some_and(|(prefix, _)| prefix.chars().all(|ch| ch.is_ascii_digit()))
+ {
+ stats.list_items += 1;
+ }
+ if trimmed.starts_with('|') && trimmed.ends_with('|') {
+ stats.table_rows += 1;
+ }
+ stats.links += trimmed.matches("](").count();
+ stats.footnotes += trimmed.matches("[^").count();
+ }
+ stats
+}
+
+fn add_stats(total: &mut StructureStats, next: &StructureStats) {
+ total.chars += next.chars;
+ total.headings += next.headings;
+ total.list_items += next.list_items;
+ total.table_rows += next.table_rows;
+ total.links += next.links;
+ total.footnotes += next.footnotes;
+}
+
+fn timed_best<T>(iterations: usize, mut operation: impl FnMut() -> T) -> (T, Duration) {
+ let mut best = Duration::MAX;
+ let mut final_value = None;
+ for _ in 0..iterations {
+ let started = Instant::now();
+ let value = operation();
+ best = best.min(started.elapsed());
+ final_value = Some(value);
+ }
+ (
+ final_value.expect("benchmark iterations are clamped to at least one"),
+ best,
+ )
+}
+
+fn caught_anydoc(path: &Path) -> Result<String, String> {
+ std::panic::catch_unwind(|| anydoc::to_markdown(path))
+ .map_err(|_| "panic".to_string())?
+ .map_err(|error| error.to_string())
+}
+
+fn caught_legacy(path: &Path, extension: &str) -> Result<String, String> {
+ let path = path.to_string_lossy().into_owned();
+ std::panic::catch_unwind(|| extract_office_text_compat(&path, extension))
+ .map_err(|_| "panic".to_string())?
+}
+
+#[test]
+#[ignore = "local benchmark; set ANYDOC_BENCH_DIR to a document corpus"]
+fn compare_anydoc_with_legacy() {
+ let root = std::env::var("ANYDOC_BENCH_DIR")
+ .map(PathBuf::from)
+ .expect("ANYDOC_BENCH_DIR must point to a local document corpus");
+ assert!(
+ root.is_dir(),
+ "benchmark directory does not exist: {}",
+ root.display()
+ );
+ let iterations = std::env::var("ANYDOC_BENCH_ITERATIONS")
+ .ok()
+ .and_then(|value| value.parse::<usize>().ok())
+ .unwrap_or(3)
+ .clamp(1, 20);
+
+ let mut paths = Vec::new();
+ collect_documents(&root, &mut paths);
+ paths.sort();
+ assert!(
+ !paths.is_empty(),
+ "no supported documents found under {}",
+ root.display()
+ );
+
+ let mut report = BenchmarkReport {
+ root: root.display().to_string(),
+ iterations,
+ files: Vec::with_capacity(paths.len()),
+ by_format: BTreeMap::new(),
+ };
+
+ for path in paths {
+ let extension = path
+ .extension()
+ .and_then(|extension| extension.to_str())
+ .unwrap_or("")
+ .to_ascii_lowercase();
+ let (anydoc_result, anydoc_elapsed) = timed_best(iterations, || caught_anydoc(&path));
+ let legacy_supported = legacy_supports(&extension);
+ let (legacy_result, legacy_elapsed) = if legacy_supported {
+ let (result, elapsed) = timed_best(iterations, || caught_legacy(&path, &extension));
+ (Some(result), Some(elapsed))
+ } else {
+ (None, None)
+ };
+
+ let anydoc_stats = anydoc_result
+ .as_ref()
+ .ok()
+ .map(|text| structure_stats(text));
+ let legacy_stats = legacy_result
+ .as_ref()
+ .and_then(|result| result.as_ref().ok())
+ .map(|text| structure_stats(text));
+ let output_equal = legacy_result
+ .as_ref()
+ .and_then(|legacy| Some(anydoc_result.as_ref().ok()? == legacy.as_ref().ok()?));
+
+ let summary = report.by_format.entry(extension.clone()).or_default();
+ summary.files += 1;
+ summary.anydoc_ok += usize::from(anydoc_result.is_ok());
+ summary.legacy_supported += usize::from(legacy_supported);
+ summary.legacy_ok += usize::from(legacy_result.as_ref().is_some_and(Result::is_ok));
+ summary.output_differences += usize::from(output_equal == Some(false));
+ summary.anydoc_micros += anydoc_elapsed.as_micros();
+ summary.legacy_micros += legacy_elapsed
+ .map(|elapsed| elapsed.as_micros())
+ .unwrap_or(0);
+ if let Some(stats) = &anydoc_stats {
+ add_stats(&mut summary.anydoc_structure, stats);
+ }
+ if let Some(stats) = &legacy_stats {
+ add_stats(&mut summary.legacy_structure, stats);
+ }
+
+ report.files.push(FileComparison {
+ path: path
+ .strip_prefix(&root)
+ .unwrap_or(&path)
+ .display()
+ .to_string(),
+ extension,
+ anydoc_ok: anydoc_result.is_ok(),
+ legacy_supported,
+ legacy_ok: legacy_result.as_ref().is_some_and(Result::is_ok),
+ anydoc_micros: anydoc_elapsed.as_micros(),
+ legacy_micros: legacy_elapsed.map(|elapsed| elapsed.as_micros()),
+ anydoc: anydoc_stats,
+ legacy: legacy_stats,
+ output_equal,
+ anydoc_error: anydoc_result.err(),
+ legacy_error: legacy_result.and_then(Result::err),
+ });
+ }
+
+ println!("\nAnyDoc comparison benchmark (best of {iterations})");
+ println!("format files anydoc legacy anydoc_us legacy_us chars(A/L) structure H/L/T(A/L)");
+ for (format, summary) in &report.by_format {
+ println!(
+ "{format:>5} {:>5} {:>3}/{:<3} {:>3}/{:<3} {:>9} {:>9} {:>8}/{:<8} {:>3}/{:<3} {:>3}/{:<3} {:>3}/{:<3}",
+ summary.files,
+ summary.anydoc_ok,
+ summary.files,
+ summary.legacy_ok,
+ summary.legacy_supported,
+ summary.anydoc_micros,
+ summary.legacy_micros,
+ summary.anydoc_structure.chars,
+ summary.legacy_structure.chars,
+ summary.anydoc_structure.headings,
+ summary.legacy_structure.headings,
+ summary.anydoc_structure.list_items,
+ summary.legacy_structure.list_items,
+ summary.anydoc_structure.table_rows,
+ summary.legacy_structure.table_rows,
+ );
+ }
+ println!(
+ "ANYDOC_BENCHMARK_JSON={}",
+ serde_json::to_string(&report).expect("benchmark report must serialize")
+ );
+}
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index ab2d11e3..c111e6f4 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -626,6 +626,8 @@ pub fn run() {
commands::fs::create_missing_wiki_page,
commands::file_history::list_file_history,
commands::file_history::restore_file_history,
+ commands::file_history::get_file_history_stats,
+ commands::file_history::clear_file_history,
commands::fs::list_directory,
commands::fs::copy_file,
commands::fs::copy_directory,
diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json
index 1636b2c7..a7bca30a 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.6.7",
+ "version": "0.6.8",
"identifier": "com.llmwiki.app",
"build": {
"beforeDevCommand": "npm run dev",
diff --git a/src/commands/fs.ts b/src/commands/fs.ts
index b78953c6..f35c1c2f 100644
--- a/src/commands/fs.ts
+++ b/src/commands/fs.ts
@@ -150,6 +150,20 @@ export interface FileHistoryEntry {
content: string
}
+export interface FileHistoryStats {
+ bytes: number
+ files: number
+ entries: number
+}
+
+export async function getFileHistoryStats(projectPath: string): Promise<FileHistoryStats> {
+ return invoke<FileHistoryStats>("get_file_history_stats", { projectPath })
+}
+
+export async function clearFileHistory(projectPath: string): Promise<void> {
+ return invoke<void>("clear_file_history", { projectPath })
+}
+
export async function listFileHistory(projectPath: string, filePath: string): Promise<FileHistoryEntry[]> {
return invoke<FileHistoryEntry[]>("list_file_history", { projectPath, filePath })
}
diff --git a/src/components/editor/file-preview.tsx b/src/components/editor/file-preview.tsx
index d081f0a9..d8d0f921 100644
--- a/src/components/editor/file-preview.tsx
+++ b/src/components/editor/file-preview.tsx
@@ -351,16 +351,27 @@ function extractedTextLabel(filePath: string): string {
case "doc":
return "Word DOC (extracted text)"
case "docx":
+ case "docm":
return "Word DOCX (extracted text)"
+ case "ppt":
+ case "pps":
+ case "pot":
case "pptx":
+ case "pptm":
+ case "ppsx":
+ case "ppsm":
return "PowerPoint (extracted text)"
case "xls":
case "xlsx":
+ case "xlsm":
+ case "xlsb":
return "Spreadsheet (extracted text)"
case "odt":
case "ods":
case "odp":
return "OpenDocument (extracted text)"
+ case "rtf":
+ return "Rich Text Format (extracted text)"
default:
return "Extracted text"
}
diff --git a/src/components/graph/graph-view.tsx b/src/components/graph/graph-view.tsx
index dffa2827..d2e9806e 100644
--- a/src/components/graph/graph-view.tsx
+++ b/src/components/graph/graph-view.tsx
@@ -694,13 +694,19 @@ export function GraphView() {
dismissKey?: string
} | null>(null)
const lastLoadedVersion = useRef(-1)
+ const graphLoadRequest = useRef(0)
const loadGraph = useCallback(async () => {
if (!project) return
+ const requestId = ++graphLoadRequest.current
setLoading(true)
setError(null)
try {
- const result = await buildWikiGraph(normalizePath(project.path))
+ const result = await buildWikiGraph(
+ normalizePath(project.path),
+ useWikiStore.getState().dataVersion,
+ )
+ if (requestId !== graphLoadRequest.current) return
setNodes(result.nodes)
setEdges(result.edges)
setCommunities(result.communities)
@@ -708,10 +714,11 @@ export function GraphView() {
setKnowledgeGaps(detectKnowledgeGaps(result.nodes, result.edges, result.communities))
lastLoadedVersion.current = useWikiStore.getState().dataVersion
} catch (err) {
+ if (requestId !== graphLoadRequest.current) return
const message = err instanceof Error ? err.message : "Failed to build graph"
setError(message)
} finally {
- setLoading(false)
+ if (requestId === graphLoadRequest.current) setLoading(false)
}
}, [project])
diff --git a/src/components/settings/sections/maintenance-section.tsx b/src/components/settings/sections/maintenance-section.tsx
index 440daadb..ea95a86e 100644
--- a/src/components/settings/sections/maintenance-section.tsx
+++ b/src/components/settings/sections/maintenance-section.tsx
@@ -32,7 +32,12 @@ import {
} from "@/lib/dedup-queue"
import type { DuplicateGroup } from "@/lib/dedup"
import { refreshProjectFileTree } from "@/lib/project-file-tree-refresh"
-import { openProject } from "@/commands/fs"
+import {
+ clearFileHistory,
+ getFileHistoryStats,
+ openProject,
+ type FileHistoryStats,
+} from "@/commands/fs"
import { addToRecentProjects } from "@/lib/project-store"
interface GroupUiEntry {
@@ -63,6 +68,42 @@ export function MaintenanceSection() {
const [scanCompleted, setScanCompleted] = useState(false)
const [projectToolStatus, setProjectToolStatus] = useState<string | null>(null)
const [projectToolBusy, setProjectToolBusy] = useState(false)
+ const [historyStats, setHistoryStats] = useState<FileHistoryStats | null>(null)
+ const [historyBusy, setHistoryBusy] = useState(false)
+ const [historyError, setHistoryError] = useState<string | null>(null)
+
+ const refreshHistoryStats = useCallback(async () => {
+ if (!project) {
+ setHistoryStats(null)
+ return
+ }
+ try {
+ setHistoryError(null)
+ setHistoryStats(await getFileHistoryStats(project.path))
+ } catch (error) {
+ console.warn("[Maintenance] failed to load file history stats:", error)
+ setHistoryError(String(error))
+ setHistoryStats(null)
+ }
+ }, [project])
+
+ useEffect(() => {
+ void refreshHistoryStats()
+ }, [refreshHistoryStats])
+
+ const handleClearHistory = useCallback(async () => {
+ if (!project || !window.confirm(t("settings.sections.maintenance.history.confirm"))) return
+ setHistoryBusy(true)
+ try {
+ setHistoryError(null)
+ await clearFileHistory(project.path)
+ await refreshHistoryStats()
+ } catch (error) {
+ setHistoryError(String(error))
+ } finally {
+ setHistoryBusy(false)
+ }
+ }, [project, refreshHistoryStats, t])
const handleRebuildIndex = useCallback(async () => {
if (!project) return
@@ -278,6 +319,36 @@ export function MaintenanceSection() {
{projectToolStatus && <p className="text-xs text-muted-foreground">{projectToolStatus}</p>}
</div>
+ <div className="space-y-3 rounded-lg border border-border/60 bg-muted/20 p-4">
+ <div className="flex items-center gap-2">
+ <Clock className="h-4 w-4 text-muted-foreground" />
+ <h3 className="text-sm font-semibold">
+ {t("settings.sections.maintenance.history.title")}
+ </h3>
+ </div>
+ <p className="text-xs text-muted-foreground">
+ {t("settings.sections.maintenance.history.description")}
+ </p>
+ {historyStats && (
+ <p className="text-xs text-muted-foreground">
+ {t("settings.sections.maintenance.history.usage", {
+ size: formatBytes(historyStats.bytes),
+ files: historyStats.files,
+ entries: historyStats.entries,
+ })}
+ </p>
+ )}
+ {historyError && <p className="text-xs text-destructive">{historyError}</p>}
+ <Button
+ variant="outline"
+ onClick={() => void handleClearHistory()}
+ disabled={!project || historyBusy || !historyStats || historyStats.files === 0}
+ >
+ {historyBusy ? <Loader2 className="h-4 w-4 animate-spin" /> : <Trash2 className="h-4 w-4" />}
+ {t("settings.sections.maintenance.history.clear")}
+ </Button>
+ </div>
+
<div className="space-y-3 rounded-lg border border-border/60 bg-muted/20 p-4">
<div className="flex items-center gap-2">
<Wrench className="h-4 w-4 text-muted-foreground" />
@@ -382,6 +453,12 @@ export function MaintenanceSection() {
)
}
+function formatBytes(bytes: number): string {
+ if (bytes < 1024) return `${bytes} B`
+ if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`
+ return `${(bytes / 1024 / 1024).toFixed(1)} MB`
+}
+
// --- helpers ---------------------------------------------------------------
/** A useRef variant that initializes lazily — avoids constructing a new
diff --git a/src/components/sources/sources-view.tsx b/src/components/sources/sources-view.tsx
index 5c4382ad..fa7248c0 100644
--- a/src/components/sources/sources-view.tsx
+++ b/src/components/sources/sources-view.tsx
@@ -157,7 +157,8 @@ export function SourcesView() {
extensions: [
"md", "mdx", "txt", "org", "rtf", "pdf",
"html", "htm", "xml",
- "doc", "docx", "xls", "xlsx", "ppt", "pptx",
+ "doc", "docx", "docm", "xls", "xlsx", "xlsm", "xlsb",
+ "ppt", "pps", "pot", "pptx", "pptm", "ppsx", "ppsm",
"odt", "ods", "odp", "epub", "mobi", "pages", "numbers", "key",
],
},
diff --git a/src/i18n/en.json b/src/i18n/en.json
index 4df3968f..e95acdcd 100644
--- a/src/i18n/en.json
+++ b/src/i18n/en.json
@@ -853,6 +853,13 @@
"exported": "Project exported to {{path}}",
"imported": "Imported {{name}}. Switch projects to open it."
},
+ "history": {
+ "title": "File version history",
+ "description": "Rollback snapshots are stored in .llm-wiki/history. Current files are not stored here. The app automatically retains at most 30 versions per file and bounds total project history size.",
+ "usage": "{{size}} across {{files}} history files ({{entries}} versions)",
+ "clear": "Clear version history",
+ "confirm": "Clear all rollback snapshots for this project? Current project files will not be deleted."
+ },
"dedup": {
"title": "Detect duplicate entities / concepts",
"description": "Asks the LLM to scan all entity / concept pages and group ones that likely refer to the same topic under different names (English vs Chinese, plural vs singular, abbreviation vs full form). You confirm each group before merging. Merges are queued and run one at a time so cross-references stay consistent.",
diff --git a/src/i18n/zh.json b/src/i18n/zh.json
index 62574220..3124d06e 100644
--- a/src/i18n/zh.json
+++ b/src/i18n/zh.json
@@ -853,6 +853,13 @@
"exported": "项目已导出到 {{path}}",
"imported": "已导入 {{name}},请切换项目后打开。"
},
+ "history": {
+ "title": "文件版本历史",
+ "description": "回滚快照保存在 .llm-wiki/history,当前文件不存放在这里。应用会为每个文件最多保留 30 个版本,并限制项目历史的总容量。",
+ "usage": "{{files}} 个历史文件、{{entries}} 个版本,共占用 {{size}}",
+ "clear": "清空版本历史",
+ "confirm": "确定清空此项目的全部回滚快照吗?当前项目文件不会被删除。"
+ },
"dedup": {
"title": "检测重复实体 / 概念",
"description": "让 LLM 扫描全部 entity / concept 页面,把可能指向同一主题但用了不同名字的页面分组(中英对照、单复数、缩写与全称等)。每一组都需要你确认后才会合并。合并任务会进入串行队列依次执行,避免交叉引用被并发改写覆盖。",
diff --git a/src/lib/__tests__/wiki-graph.test.ts b/src/lib/__tests__/wiki-graph.test.ts
index d832586f..9f4dd1d4 100644
--- a/src/lib/__tests__/wiki-graph.test.ts
+++ b/src/lib/__tests__/wiki-graph.test.ts
@@ -80,4 +80,56 @@ describe("buildWikiGraph frontmatter extraction", () => {
expect(graph.nodes).toHaveLength(1)
expect(graph.nodes[0]).toMatchObject({ label: "Attention: Architecture", type: "concept" })
})
+
+ it("resolves case and space variants without dropping links", async () => {
+ const buildWikiGraph = await loadBuildWikiGraph()
+ mockListDirectory.mockResolvedValue([
+ mdFile("Source.md"),
+ mdFile("target-page.md"),
+ ])
+ mockReadFile.mockImplementation(async (path: string) =>
+ path.endsWith("Source.md")
+ ? "# Source\n\n[[Target Page]]"
+ : "# Target",
+ )
+
+ const graph = await buildWikiGraph("/project")
+
+ expect(graph.edges).toEqual([
+ expect.objectContaining({ source: "Source", target: "target-page" }),
+ ])
+ })
+
+ it("prefers an exact page id when case-folded aliases collide", async () => {
+ const buildWikiGraph = await loadBuildWikiGraph()
+ mockListDirectory.mockResolvedValue([
+ mdFile("source.md"),
+ mdFile("Foo.md"),
+ mdFile("foo.md"),
+ ])
+ mockReadFile.mockImplementation(async (path: string) =>
+ path.endsWith("source.md") ? "# Source\n\n[[foo]]" : "# Target",
+ )
+
+ const graph = await buildWikiGraph("/case-project")
+
+ expect(graph.edges).toEqual([
+ expect.objectContaining({ source: "source", target: "foo" }),
+ ])
+ })
+
+ it("reuses an unchanged graph by project data version", async () => {
+ const buildWikiGraph = await loadBuildWikiGraph()
+ mockListDirectory.mockClear()
+ mockReadFile.mockClear()
+ mockListDirectory.mockResolvedValue([mdFile("cached.md")])
+ mockReadFile.mockResolvedValue("# Cached")
+
+ const first = await buildWikiGraph("/cached-project", 42)
+ const second = await buildWikiGraph("/cached-project", 42)
+
+ expect(second).toBe(first)
+ expect(mockListDirectory).toHaveBeenCalledTimes(1)
+ expect(mockReadFile).toHaveBeenCalledTimes(1)
+ })
})
diff --git a/src/lib/changelog.ts b/src/lib/changelog.ts
index 40a8a644..8fe6f7df 100644
--- a/src/lib/changelog.ts
+++ b/src/lib/changelog.ts
@@ -25,6 +25,30 @@ export interface ChangelogEntry {
}
export const CHANGELOG: ChangelogEntry[] = [
+ {
+ version: "0.6.8",
+ date: "2026-08-07",
+ highlights: {
+ en: [
+ "Integrated AnyDoc document parsing with broader Word, PowerPoint, Excel, OpenDocument, and RTF support, richer structure preservation, safe legacy fallback, and versioned extraction caches.",
+ "Improved large knowledge graph loading, caching, and community analysis performance.",
+ "Added file version history usage and cleanup controls.",
+ "Improved scheduled import cleanup when source files are removed or excluded.",
+ "Fixed incomplete Deep Research output being saved as successful and added retry support.",
+ "Improved GPT-5, OpenAI o-series, and Azure model parameter compatibility.",
+ "Improved existing features and fixed stability and compatibility issues.",
+ ],
+ zh: [
+ "集成 AnyDoc 文档解析,扩展 Word、PowerPoint、Excel、OpenDocument 和 RTF 格式支持,增强结构保留,并支持旧解析器安全回退与解析缓存版本管理。",
+ "优化大型知识图谱的加载、缓存和社区分析性能。",
+ "新增文件版本历史占用查看与清理功能。",
+ "完善定时导入源文件删除或排除后的同步清理。",
+ "修复深度研究内容不完整仍被保存为成功的问题,并支持失败重试。",
+ "改进 GPT-5、OpenAI o 系列及 Azure 模型参数兼容性。",
+ "优化现有功能,并修复稳定性与兼容性问题。",
+ ],
+ },
+ },
{
version: "0.6.6",
date: "2026-07-27",
diff --git a/src/lib/file-types.test.ts b/src/lib/file-types.test.ts
index c566540c..b97f68e1 100644
--- a/src/lib/file-types.test.ts
+++ b/src/lib/file-types.test.ts
@@ -10,8 +10,12 @@ describe("file types", () => {
it("recognizes backend-extracted document previews", () => {
expect(isExtractedTextPreviewFile("/project/raw/sources/report.doc")).toBe(true)
expect(isExtractedTextPreviewFile("/project/raw/sources/report.docx")).toBe(true)
+ expect(isExtractedTextPreviewFile("/project/raw/sources/report.docm")).toBe(true)
expect(isExtractedTextPreviewFile("/project/raw/sources/slides.pptx")).toBe(true)
+ expect(isExtractedTextPreviewFile("/project/raw/sources/slides.ppsm")).toBe(true)
expect(isExtractedTextPreviewFile("/project/raw/sources/sheet.xlsx")).toBe(true)
+ expect(isExtractedTextPreviewFile("/project/raw/sources/sheet.xlsb")).toBe(true)
+ expect(isExtractedTextPreviewFile("/project/raw/sources/notes.rtf")).toBe(true)
expect(isExtractedTextPreviewFile("/project/raw/sources/book.epub")).toBe(true)
expect(isExtractedTextPreviewFile("C:\\books\\book.MOBI")).toBe(true)
expect(isExtractedTextPreviewFile("C:\\notes\\journal.ORG")).toBe(true)
diff --git a/src/lib/file-types.ts b/src/lib/file-types.ts
index 7ef260ec..4af75c44 100644
--- a/src/lib/file-types.ts
+++ b/src/lib/file-types.ts
@@ -17,7 +17,6 @@ const EXT_MAP: Record<string, FileCategory> = {
// Text
txt: "text",
- rtf: "text",
log: "text",
// Code
@@ -105,10 +104,19 @@ const EXT_MAP: Record<string, FileCategory> = {
// Documents. Some are previewable through backend text extraction.
doc: "document",
docx: "document",
+ docm: "document",
xls: "document",
xlsx: "document",
+ xlsm: "document",
+ xlsb: "document",
ppt: "document",
+ pps: "document",
+ pot: "document",
pptx: "document",
+ pptm: "document",
+ ppsx: "document",
+ ppsm: "document",
+ rtf: "document",
odt: "document",
ods: "document",
odp: "document",
@@ -145,12 +153,22 @@ export const EXTRACTED_TEXT_PREVIEW_EXTENSIONS = new Set([
"pdf",
"doc",
"docx",
+ "docm",
+ "ppt",
+ "pps",
+ "pot",
"pptx",
+ "pptm",
+ "ppsx",
+ "ppsm",
"xls",
"xlsx",
+ "xlsm",
+ "xlsb",
"odt",
"ods",
"odp",
+ "rtf",
"epub",
"mobi",
"org",
diff --git a/src/lib/ingest-queue.test.ts b/src/lib/ingest-queue.test.ts
index a9850ac0..43586183 100644
--- a/src/lib/ingest-queue.test.ts
+++ b/src/lib/ingest-queue.test.ts
@@ -58,6 +58,7 @@ import {
retryAllFailedTasks,
cancelTask,
cancelTasks,
+ discardTasksForSources,
cancelAllTasks,
movePendingTask,
clearCompletedTasks,
@@ -271,6 +272,21 @@ describe("ingest-queue — retry & failure", () => {
})
describe("ingest-queue — cancel", () => {
+ it("permanently discards queued work for a removed source", async () => {
+ mockAutoIngest.mockImplementation(() => new Promise(() => {}))
+ await enqueueBatch(TEST_ID, [
+ { sourcePath: "raw/sources/active.md", folderContext: "" },
+ { sourcePath: "raw/sources/removed.md", folderContext: "" },
+ ])
+ await flushMicrotasks(2)
+
+ expect(
+ await discardTasksForSources([`${TEST_PATH}/raw/sources/removed.md`]),
+ ).toBe(1)
+ expect(getQueue().some((task) => task.sourcePath.endsWith("removed.md"))).toBe(false)
+ expect(getQueue().some((task) => task.sourcePath.endsWith("active.md"))).toBe(true)
+ })
+
it("cancelTask retains a pending task for restart without calling autoIngest", async () => {
mockAutoIngest.mockImplementation(() => new Promise(() => {})) // block first task
diff --git a/src/lib/ingest-queue.ts b/src/lib/ingest-queue.ts
index 4d7f3273..6f5a7cba 100644
--- a/src/lib/ingest-queue.ts
+++ b/src/lib/ingest-queue.ts
@@ -432,6 +432,55 @@ export async function cancelTasks(taskIds: readonly string[]): Promise<number> {
return targets.length
}
+/**
+ * Permanently discard active-project tasks for sources that no longer exist.
+ * Unlike cancelTasks, this does not retain restartable queue entries because
+ * scheduled-import reconciliation has already established that the mirrored
+ * source must be removed.
+ */
+export async function discardTasksForSources(
+ sourcePaths: readonly string[],
+): Promise<number> {
+ const targets = queue.filter(
+ (task) =>
+ task.projectId === currentProjectId &&
+ sourcePaths.some((sourcePath) => {
+ const source = normalizeSourcePathForQueue(sourcePath)
+ const queued = normalizeSourcePathForQueue(task.sourcePath)
+ return (
+ source === queued ||
+ (isAbsolutePath(source) && !isAbsolutePath(queued) && source.endsWith(`/${queued}`)) ||
+ (isAbsolutePath(queued) && !isAbsolutePath(source) && queued.endsWith(`/${source}`))
+ )
+ }),
+ )
+ if (targets.length === 0) return 0
+
+ const targetIds = new Set(targets.map((task) => task.id))
+ const hadProcessingTask = targets.some((task) => task.status === "processing")
+ for (const task of targets) {
+ restoredPausedTaskIds.delete(task.id)
+ if (task.status === "processing") cancelledInFlightTaskIds.add(task.id)
+ }
+ if (hadProcessingTask && currentAbortController) {
+ currentAbortController.abort()
+ currentAbortController = null
+ }
+ if (hadProcessingTask && lastWrittenFiles.length > 0) {
+ await cleanupWrittenFiles(currentProjectPath, lastWrittenFiles)
+ lastWrittenFiles = []
+ }
+
+ queue = queue.filter((task) => !targetIds.has(task.id))
+ if (!queue.some((task) => task.status === "pending" || task.status === "processing")) {
+ paused = false
+ clearUsageLimitAutoResume()
+ }
+ await saveQueue(currentProjectPath)
+ if (!hadProcessingTask) processNext(currentProjectId)
+ return targets.length
+}
+
/**
* Clear all done/failed tasks from the active project's queue.
*/
diff --git a/src/lib/parsed-source-output.test.ts b/src/lib/parsed-source-output.test.ts
index c042ccf1..03e03c56 100644
--- a/src/lib/parsed-source-output.test.ts
+++ b/src/lib/parsed-source-output.test.ts
@@ -36,6 +36,14 @@ describe("parsed source output", () => {
expect(parsedMarkdownOutputPath("/project", "/project/raw/sources/data.json")).toBeNull()
})
+ it("supports AnyDoc-only Office variants and RTF", () => {
+ for (const fileName of ["a.docm", "a.ppt", "a.ppsm", "a.xlsb", "a.rtf"]) {
+ expect(
+ parsedMarkdownOutputPath("/project", `/project/raw/sources/${fileName}`),
+ ).toBe(`/project/raw/parsed/${fileName}.md`)
+ }
+ })
+
it("creates the mirrored directory and writes atomically", async () => {
await expect(
persistParsedMarkdown(
diff --git a/src/lib/parsed-source-output.ts b/src/lib/parsed-source-output.ts
index 27c4e2cd..04e36373 100644
--- a/src/lib/parsed-source-output.ts
+++ b/src/lib/parsed-source-output.ts
@@ -5,12 +5,22 @@ const PARSED_MARKDOWN_EXTENSIONS = new Set([
"pdf",
"doc",
"docx",
+ "docm",
+ "ppt",
+ "pps",
+ "pot",
"pptx",
+ "pptm",
+ "ppsx",
+ "ppsm",
"xls",
"xlsx",
+ "xlsm",
+ "xlsb",
"odt",
"ods",
"odp",
+ "rtf",
"epub",
"mobi",
"org",
diff --git a/src/lib/scheduled-import.test.ts b/src/lib/scheduled-import.test.ts
index 4b866416..89c8f583 100644
--- a/src/lib/scheduled-import.test.ts
+++ b/src/lib/scheduled-import.test.ts
@@ -11,6 +11,8 @@ const mocks = vi.hoisted(() => ({
readFile: vi.fn(),
writeFileAtomic: vi.fn(),
enqueueSourceIngest: vi.fn(),
+ deleteSourceFile: vi.fn(),
+ discardTasksForSources: vi.fn(),
isIngestableSourcePath: vi.fn(),
loadScheduledImportConfig: vi.fn(),
saveScheduledImportConfig: vi.fn(),
@@ -28,10 +30,15 @@ vi.mock("@/commands/fs", () => ({
}))
vi.mock("@/lib/source-lifecycle", () => ({
+ deleteSourceFile: mocks.deleteSourceFile,
enqueueSourceIngest: mocks.enqueueSourceIngest,
isIngestableSourcePath: mocks.isIngestableSourcePath,
}))
+vi.mock("@/lib/ingest-queue", () => ({
+ discardTasksForSources: mocks.discardTasksForSources,
+}))
+
vi.mock("@/lib/project-store", () => ({
loadScheduledImportConfig: mocks.loadScheduledImportConfig,
saveScheduledImportConfig: mocks.saveScheduledImportConfig,
@@ -216,6 +223,11 @@ describe("scanAndImport failure handling", () => {
mocks.getFileSize.mockResolvedValue(1024)
mocks.getFileMd5.mockResolvedValue("md5-new")
mocks.copyFile.mockResolvedValue(undefined)
+ mocks.deleteSourceFile.mockResolvedValue({
+ deletedWikiPaths: [],
+ rewrittenSourcePages: 0,
+ })
+ mocks.discardTasksForSources.mockResolvedValue(0)
mocks.preprocessFile.mockResolvedValue("")
mocks.isIngestableSourcePath.mockReturnValue(true)
mocks.loadScheduledImportConfig.mockResolvedValue({
@@ -346,4 +358,79 @@ describe("scanAndImport failure handling", () => {
expect.any(Object),
)
})
+
+ it("removes mirrors and derived knowledge for deleted scheduled sources", async () => {
+ mocks.fileExists.mockImplementation(async (path: string) =>
+ path.endsWith("scheduled-import-db.json") || path.endsWith("scheduled-import/old.pdf")
+ )
+ mocks.readFile.mockResolvedValue(JSON.stringify({
+ version: 1,
+ directories: {
+ "/Users/me/inbox": {
+ files: { "/Users/me/inbox/old.pdf": "old-md5" },
+ lastScan: 123,
+ },
+ },
+ }))
+ mocks.listDirectory.mockResolvedValue([])
+
+ await scanAndImport(project, "/Users/me/inbox")
+
+ const mirror = "/Users/me/wiki-project/raw/sources/scheduled-import/old.pdf"
+ expect(mocks.discardTasksForSources).toHaveBeenCalledWith([mirror])
+ expect(mocks.deleteSourceFile).toHaveBeenCalledWith(project.path, mirror, {
+ fileAlreadyDeleted: false,
+ logReason: "scheduled import source removed or excluded",
+ })
+ expect(mocks.writeFileAtomic).toHaveBeenCalledWith(
+ "/Users/me/wiki-project/.llm-wiki/scheduled-import-db.json",
+ expect.not.stringContaining("old.pdf"),
+ )
+ })
+
+ it("keeps an existing source record when the file is temporarily unreadable", async () => {
+ mocks.fileExists.mockResolvedValue(true)
+ mocks.readFile.mockResolvedValue(JSON.stringify({
+ version: 1,
+ directories: {
+ "/Users/me/inbox": {
+ files: { "/Users/me/inbox/paper.pdf": "old-md5" },
+ lastScan: 123,
+ },
+ },
+ }))
+ mocks.getFileMd5.mockRejectedValue(new Error("sharing violation"))
+
+ await scanAndImport(project, "/Users/me/inbox")
+
+ expect(mocks.deleteSourceFile).not.toHaveBeenCalled()
+ expect(mocks.writeFileAtomic).toHaveBeenCalledWith(
+ "/Users/me/wiki-project/.llm-wiki/scheduled-import-db.json",
+ expect.stringContaining('"/Users/me/inbox/paper.pdf": "old-md5"'),
+ )
+ })
+
+ it("cleans a previously imported file that is now excluded", async () => {
+ mocks.fileExists.mockResolvedValue(true)
+ mocks.readFile.mockResolvedValue(JSON.stringify({
+ version: 1,
+ directories: {
+ "/Users/me/inbox": {
+ files: { "/Users/me/inbox/settings.json": "old-md5" },
+ lastScan: 123,
+ },
+ },
+ }))
+ mocks.listDirectory.mockResolvedValue([
+ { name: "settings.json", path: "/Users/me/inbox/settings.json", is_dir: false },
+ ])
+
+ await scanAndImport(project, "/Users/me/inbox")
+
+ expect(mocks.deleteSourceFile).toHaveBeenCalledWith(
+ project.path,
+ "/Users/me/wiki-project/raw/sources/scheduled-import/settings.json",
+ expect.any(Object),
+ )
+ })
})
diff --git a/src/lib/scheduled-import.ts b/src/lib/scheduled-import.ts
index 8313c4bc..7acddc6b 100644
--- a/src/lib/scheduled-import.ts
+++ b/src/lib/scheduled-import.ts
@@ -16,9 +16,11 @@ import {
saveScheduledImportConfig,
} from "@/lib/project-store"
import {
+ deleteSourceFile,
enqueueSourceIngest,
isIngestableSourcePath,
} from "@/lib/source-lifecycle"
+import { discardTasksForSources } from "@/lib/ingest-queue"
import { useActivityStore } from "@/stores/activity-store"
import { refreshProjectFileTree } from "@/lib/project-file-tree-refresh"
@@ -282,6 +284,58 @@ function collectFiles(nodes: FileNode[]): FileNode[] {
return files
}
+function scheduledImportDestinationForSourceKey(
+ projectPath: string,
+ importPath: string,
+ sourceKey: string,
+): string {
+ const name = normalizePath(sourceKey).split("/").pop() ?? "_"
+ return scheduledImportDestinationForFile(projectPath, importPath, {
+ name,
+ path: sourceKey,
+ })
+}
+
+async function cleanupRemovedScheduledImports(
+ project: WikiProject,
+ importRoot: string,
+ db: ImportDb,
+ observedEligibleKeys: ReadonlySet<string>,
+ nextDb: ImportDb,
+): Promise<boolean> {
+ const removedKeys = Object.keys(db.files).filter(
+ (key) => !observedEligibleKeys.has(key) && !(key in nextDb.files),
+ )
+ if (removedKeys.length === 0) return false
+
+ const destinations = removedKeys.map((key) => ({
+ key,
+ path: scheduledImportDestinationForSourceKey(project.path, importRoot, key),
+ }))
+ await discardTasksForSources(destinations.map((entry) => entry.path))
+
+ let changed = false
+ for (const destination of destinations) {
+ try {
+ const exists = await fileExists(destination.path)
+ await deleteSourceFile(project.path, destination.path, {
+ fileAlreadyDeleted: !exists,
+ logReason: "scheduled import source removed or excluded",
+ })
+ changed = true
+ } catch (err) {
+ // Preserve the old record so a later scan retries cleanup rather than
+ // silently forgetting a stale mirror or its generated wiki pages.
+ nextDb.files[destination.key] = db.files[destination.key]
+ console.warn(
+ `[scheduled-import] failed to clean removed source ${destination.path}:`,
+ err,
+ )
+ }
+ }
+ return changed
+}
+
async function loadDbStore(projectPath: string): Promise<ImportDbStore> {
const path = dbFilePath(projectPath)
try {
@@ -379,6 +433,7 @@ export async function scanAndImport(
const nextDb: ImportDb = { files: {}, lastScan: Date.now() }
const llmConfig = useWikiStore.getState().llmConfig
const changedFiles: Array<{ key: string; md5: string; destPath: string }> = []
+ const observedEligibleKeys = new Set<string>()
for (const file of collectFiles(tree)) {
try {
@@ -391,6 +446,8 @@ export async function scanAndImport(
continue
}
+ const key = dbDirectoryKey(sourcePath)
+
if (!isCurrentRun(project.id, options.runId)) {
return
}
@@ -403,7 +460,8 @@ export async function scanAndImport(
continue
}
- const key = dbDirectoryKey(sourcePath)
+ observedEligibleKeys.add(key)
+
const md5 = await getFileMd5(sourcePath)
if (db.files[key] === md5) {
@@ -417,6 +475,10 @@ export async function scanAndImport(
}
changedFiles.push({ key, md5, destPath })
} catch (err) {
+ const key = dbDirectoryKey(file.path)
+ if (db.files[key]) {
+ nextDb.files[key] = db.files[key]
+ }
console.warn(`[scheduled-import] skipped ${file.path}:`, err)
}
}
@@ -425,6 +487,18 @@ export async function scanAndImport(
return
}
+ const removedSourcesChanged = await cleanupRemovedScheduledImports(
+ project,
+ importRoot,
+ db,
+ observedEligibleKeys,
+ nextDb,
+ )
+
+ if (!isCurrentRun(project.id, options.runId)) {
+ return
+ }
+
if (changedFiles.length > 0) {
const destPaths = changedFiles.map((file) => file.destPath)
if (isCurrentRun(project.id, options.runId)) {
@@ -433,16 +507,20 @@ export async function scanAndImport(
for (const file of changedFiles) {
nextDb.files[file.key] = file.md5
}
- await refreshProjectFileTree(projectPath, {
- projectId: project.id,
- bumpDataVersion: true,
- })
} else {
console.warn("[scheduled-import] LLM is not configured; changed files were not marked imported")
}
}
}
+
+ if (removedSourcesChanged || changedFiles.some((file) => nextDb.files[file.key])) {
+ await refreshProjectFileTree(projectPath, {
+ projectId: project.id,
+ bumpDataVersion: true,
+ })
+ }
+
await saveImportDb(projectPath, importRoot, nextDb)
const currentConfig = await loadScheduledImportConfig(projectPath)
diff --git a/src/lib/source-lifecycle.test.ts b/src/lib/source-lifecycle.test.ts
index 92abce4a..086e3047 100644
--- a/src/lib/source-lifecycle.test.ts
+++ b/src/lib/source-lifecycle.test.ts
@@ -60,6 +60,18 @@ describe("source-lifecycle path helpers", () => {
expect(isIngestableSourcePath("C:\\project\\raw\\sources\\book.MOBI")).toBe(true)
})
+ it("accepts AnyDoc Office and RTF source variants", () => {
+ for (const path of [
+ "report.docm",
+ "deck.ppt",
+ "show.ppsm",
+ "workbook.xlsb",
+ "notes.rtf",
+ ]) {
+ expect(isIngestableSourcePath(`raw/sources/${path}`)).toBe(true)
+ }
+ })
+
it("derives folder context from absolute raw/sources paths without leaking the project prefix", () => {
expect(
folderContextForSourcePath("/tmp/project/raw/sources/reports/2026/report.pdf"),
diff --git a/src/lib/source-lifecycle.ts b/src/lib/source-lifecycle.ts
index 81106eb5..88c1eb33 100644
--- a/src/lib/source-lifecycle.ts
+++ b/src/lib/source-lifecycle.ts
@@ -49,8 +49,17 @@ export const INGESTABLE_SOURCE_EXTENSIONS = new Set([
"pdf",
"doc",
"docx",
+ "docm",
+ "ppt",
+ "pps",
+ "pot",
"pptx",
+ "pptm",
+ "ppsx",
+ "ppsm",
"xlsx",
+ "xlsm",
+ "xlsb",
"odt",
"odp",
"ods",
@@ -431,6 +440,11 @@ export async function deleteSourceFiles(
} catch {
// cache file may not exist
}
+ try {
+ await deleteFile(`${pp}/raw/sources/.cache/${info.fileName}.txt.parser`)
+ } catch {
+ // Version markers exist only for structured-document parser caches.
+ }
for (const cacheKey of new Set([info.identity, info.fileName])) {
try {
await removeFromIngestCache(pp, cacheKey)
diff --git a/src/lib/source-watch-config.test.ts b/src/lib/source-watch-config.test.ts
index 9fa4c113..3da401f0 100644
--- a/src/lib/source-watch-config.test.ts
+++ b/src/lib/source-watch-config.test.ts
@@ -7,6 +7,11 @@ import {
import sourceWatchDefaults from "@/lib/source-watch-defaults.json"
describe("source watch config", () => {
+ it("includes AnyDoc Office and RTF variants in the default watch set", () => {
+ for (const extension of ["docm", "ppt", "ppsm", "xlsb", "rtf"]) {
+ expect(DEFAULT_SOURCE_WATCH_CONFIG.includeExtensions).toContain(extension)
+ }
+ })
it("uses the shared default fixture", () => {
expect(DEFAULT_SOURCE_WATCH_CONFIG).toEqual(sourceWatchDefaults)
expect(normalizeSourceWatchConfig({}).persistExtractedMarkdown).toBe(false)
diff --git a/src/lib/source-watch-config.ts b/src/lib/source-watch-config.ts
index 0aaded22..5b758dc7 100644
--- a/src/lib/source-watch-config.ts
+++ b/src/lib/source-watch-config.ts
@@ -7,15 +7,15 @@ export const DEFAULT_SOURCE_WATCH_CONFIG: SourceWatchConfig = sourceWatchDefault
export const SOURCE_WATCH_FILE_TYPE_GROUPS = [
{
id: "documents",
- extensions: ["md", "mdx", "txt", "org", "pdf", "doc", "docx", "odt", "rtf", "epub", "mobi"],
+ extensions: ["md", "mdx", "txt", "org", "pdf", "doc", "docx", "docm", "odt", "rtf", "epub", "mobi"],
},
{
id: "presentations",
- extensions: ["pptx", "odp"],
+ extensions: ["ppt", "pps", "pot", "pptx", "pptm", "ppsx", "ppsm", "odp"],
},
{
id: "spreadsheets",
- extensions: ["xls", "xlsx", "ods", "csv"],
+ extensions: ["xls", "xlsx", "xlsm", "xlsb", "ods", "csv"],
},
{
id: "web",
diff --git a/src/lib/source-watch-defaults.json b/src/lib/source-watch-defaults.json
index 52c3fbb1..9fc25172 100644
--- a/src/lib/source-watch-defaults.json
+++ b/src/lib/source-watch-defaults.json
@@ -11,9 +11,18 @@
"pdf",
"doc",
"docx",
+ "docm",
+ "ppt",
+ "pps",
+ "pot",
"pptx",
+ "pptm",
+ "ppsx",
+ "ppsm",
"xls",
"xlsx",
+ "xlsm",
+ "xlsb",
"odt",
"odp",
"ods",
diff --git a/src/lib/wiki-graph-analysis.test.ts b/src/lib/wiki-graph-analysis.test.ts
new file mode 100644
index 00000000..7c47d8d9
--- /dev/null
+++ b/src/lib/wiki-graph-analysis.test.ts
@@ -0,0 +1,24 @@
+import { describe, expect, it } from "vitest"
+import { detectCommunities } from "./wiki-graph-analysis"
+
+describe("wiki graph community analysis", () => {
+ it("computes cohesion from internal edges without counting cross-community edges", () => {
+ const nodes = ["a", "b", "c", "d"].map((id) => ({
+ id,
+ label: id.toUpperCase(),
+ linkCount: id === "a" ? 3 : 1,
+ }))
+ const edges = [
+ { source: "a", target: "b", weight: 1 },
+ { source: "a", target: "c", weight: 1 },
+ { source: "b", target: "c", weight: 1 },
+ ]
+
+ const result = detectCommunities(nodes, edges)
+
+ expect(result.assignments.size).toBe(4)
+ expect(result.communities.reduce((sum, community) => sum + community.nodeCount, 0)).toBe(4)
+ expect(result.communities.every((community) => community.cohesion >= 0 && community.cohesion <= 1)).toBe(true)
+ expect(result.communities.flatMap((community) => community.topNodes)).toContain("A")
+ })
+})
diff --git a/src/lib/wiki-graph-analysis.ts b/src/lib/wiki-graph-analysis.ts
new file mode 100644
index 00000000..cf88fdb1
--- /dev/null
+++ b/src/lib/wiki-graph-analysis.ts
@@ -0,0 +1,77 @@
+import Graph from "graphology"
+import louvain from "graphology-communities-louvain"
+import type { CommunityInfo, GraphEdge } from "./wiki-graph"
+
+/** Run Louvain community detection and compute cohesion per community. */
+export function detectCommunities(
+ nodes: { id: string; label: string; linkCount: number }[],
+ edges: GraphEdge[],
+): { assignments: Map<string, number>; communities: CommunityInfo[] } {
+ if (nodes.length === 0) {
+ return { assignments: new Map(), communities: [] }
+ }
+
+ const graph = new Graph({ type: "undirected" })
+ for (const node of nodes) graph.addNode(node.id)
+ for (const edge of edges) {
+ if (!graph.hasNode(edge.source) || !graph.hasNode(edge.target)) continue
+ const key = `${edge.source}->${edge.target}`
+ if (!graph.hasEdge(key) && !graph.hasEdge(`${edge.target}->${edge.source}`)) {
+ graph.addEdgeWithKey(key, edge.source, edge.target, { weight: edge.weight })
+ }
+ }
+
+ const communityMap: Record<string, number> = louvain(graph, { resolution: 1 })
+ const assignments = new Map(
+ Object.entries(communityMap).map(([nodeId, communityId]) => [nodeId, communityId]),
+ )
+ const groups = new Map<number, string[]>()
+ for (const [nodeId, communityId] of assignments) {
+ const members = groups.get(communityId) ?? []
+ members.push(nodeId)
+ groups.set(communityId, members)
+ }
+
+ // Counting actual internal edges is O(E); comparing every member pair is
+ // O(N^2) and dominates large knowledge graphs.
+ const intraEdgesByCommunity = new Map<number, number>()
+ for (const edge of edges) {
+ const sourceCommunity = assignments.get(edge.source)
+ if (sourceCommunity !== undefined && sourceCommunity === assignments.get(edge.target)) {
+ intraEdgesByCommunity.set(
+ sourceCommunity,
+ (intraEdgesByCommunity.get(sourceCommunity) ?? 0) + 1,
+ )
+ }
+ }
+
+ const nodeInfo = new Map(
+ nodes.map((node) => [node.id, { label: node.label, linkCount: node.linkCount }]),
+ )
+ const communities: CommunityInfo[] = []
+ for (const [communityId, memberIds] of groups) {
+ const nodeCount = memberIds.length
+ const possibleEdges = nodeCount > 1 ? (nodeCount * (nodeCount - 1)) / 2 : 1
+ const cohesion = (intraEdgesByCommunity.get(communityId) ?? 0) / possibleEdges
+ const topNodes = [...memberIds]
+ .sort(
+ (left, right) =>
+ (nodeInfo.get(right)?.linkCount ?? 0) -
+ (nodeInfo.get(left)?.linkCount ?? 0),
+ )
+ .slice(0, 5)
+ .map((id) => nodeInfo.get(id)?.label ?? id)
+ communities.push({ id: communityId, nodeCount, cohesion, topNodes })
+ }
+
+ communities.sort((left, right) => right.nodeCount - left.nodeCount)
+ const idRemap = new Map<number, number>()
+ communities.forEach((community, index) => {
+ idRemap.set(community.id, index)
+ community.id = index
+ })
+ for (const [nodeId, oldId] of assignments) {
+ assignments.set(nodeId, idRemap.get(oldId) ?? 0)
+ }
+ return { assignments, communities }
+}
diff --git a/src/lib/wiki-graph-analysis.worker.ts b/src/lib/wiki-graph-analysis.worker.ts
new file mode 100644
index 00000000..178cc9ea
--- /dev/null
+++ b/src/lib/wiki-graph-analysis.worker.ts
@@ -0,0 +1,15 @@
+import type { GraphEdge } from "./wiki-graph"
+import { detectCommunities } from "./wiki-graph-analysis"
+
+interface AnalysisRequest {
+ nodes: { id: string; label: string; linkCount: number }[]
+ edges: GraphEdge[]
+}
+
+self.onmessage = (event: MessageEvent<AnalysisRequest>) => {
+ const result = detectCommunities(event.data.nodes, event.data.edges)
+ self.postMessage({
+ assignments: Array.from(result.assignments.entries()),
+ communities: result.communities,
+ })
+}
diff --git a/src/lib/wiki-graph.ts b/src/lib/wiki-graph.ts
index 4fd1eb7e..7a4dd165 100644
--- a/src/lib/wiki-graph.ts
+++ b/src/lib/wiki-graph.ts
@@ -3,8 +3,7 @@ import type { FileNode } from "@/types/wiki"
import { buildRetrievalGraph, calculateRelevance } from "./graph-relevance"
import { normalizePath } from "@/lib/path-utils"
import { parseFrontmatter } from "@/lib/frontmatter"
-import Graph from "graphology"
-import louvain from "graphology-communities-louvain"
+import { detectCommunities } from "./wiki-graph-analysis"
export interface GraphNode {
id: string
@@ -28,89 +27,48 @@ export interface CommunityInfo {
topNodes: string[] // top nodes by linkCount (labels)
}
-/** Run Louvain community detection and compute cohesion per community */
-function detectCommunities(
+export interface WikiGraphResult {
+ nodes: GraphNode[]
+ edges: GraphEdge[]
+ communities: CommunityInfo[]
+}
+
+const GRAPH_FILE_READ_CONCURRENCY = 16
+const MAX_WEIGHTED_GRAPH_NODES = 3_000
+const COMMUNITY_WORKER_THRESHOLD = 3_000
+const MAX_CACHED_PROJECT_GRAPHS = 2
+const graphCache = new Map<string, { dataVersion: number; result: WikiGraphResult }>()
+const graphBuilds = new Map<string, Promise<WikiGraphResult>>()
+
+async function analyzeCommunities(
nodes: { id: string; label: string; linkCount: number }[],
edges: GraphEdge[],
-): { assignments: Map<string, number>; communities: CommunityInfo[] } {
- if (nodes.length === 0) {
- return { assignments: new Map(), communities: [] }
+): Promise<{ assignments: Map<string, number>; communities: CommunityInfo[] }> {
+ if (nodes.length < COMMUNITY_WORKER_THRESHOLD || typeof Worker === "undefined") {
+ return detectCommunities(nodes, edges)
}
- const g = new Graph({ type: "undirected" })
- for (const node of nodes) {
- g.addNode(node.id)
- }
- for (const edge of edges) {
- if (g.hasNode(edge.source) && g.hasNode(edge.target)) {
- const key = `${edge.source}->${edge.target}`
- if (!g.hasEdge(key) && !g.hasEdge(`${edge.target}->${edge.source}`)) {
- g.addEdgeWithKey(key, edge.source, edge.target, { weight: edge.weight })
- }
+ return new Promise((resolve, reject) => {
+ const worker = new Worker(
+ new URL("./wiki-graph-analysis.worker.ts", import.meta.url),
+ { type: "module" },
+ )
+ worker.onmessage = (event: MessageEvent<{
+ assignments: [string, number][]
+ communities: CommunityInfo[]
+ }>) => {
+ worker.terminate()
+ resolve({
+ assignments: new Map(event.data.assignments),
+ communities: event.data.communities,
+ })
}
- }
-
- // Run Louvain — returns { nodeId: communityId }
- const communityMap: Record<string, number> = louvain(g, { resolution: 1 })
- const assignments = new Map(Object.entries(communityMap).map(([k, v]) => [k, v as number]))
-
- // Group nodes by community
- const groups = new Map<number, string[]>()
- for (const [nodeId, commId] of assignments) {
- const list = groups.get(commId) ?? []
- list.push(nodeId)
- groups.set(commId, list)
- }
-
- // Build edge lookup for cohesion calculation
- const edgeSet = new Set<string>()
- for (const edge of edges) {
- edgeSet.add(`${edge.source}:::${edge.target}`)
- edgeSet.add(`${edge.target}:::${edge.source}`)
- }
-
- // Build label + linkCount lookup
- const nodeInfo = new Map(nodes.map((n) => [n.id, { label: n.label, linkCount: n.linkCount }]))
-
- // Compute per-community info
- const communities: CommunityInfo[] = []
- for (const [commId, memberIds] of groups) {
- const n = memberIds.length
- // Cohesion = actual intra-community edges / possible edges
- let intraEdges = 0
- for (let i = 0; i < memberIds.length; i++) {
- for (let j = i + 1; j < memberIds.length; j++) {
- if (edgeSet.has(`${memberIds[i]}:::${memberIds[j]}`)) {
- intraEdges++
- }
- }
+ worker.onerror = (event) => {
+ worker.terminate()
+ reject(new Error(event.message || "Knowledge graph analysis worker failed"))
}
- const possibleEdges = n > 1 ? (n * (n - 1)) / 2 : 1
- const cohesion = intraEdges / possibleEdges
-
- // Top nodes by linkCount
- const sorted = [...memberIds].sort(
- (a, b) => (nodeInfo.get(b)?.linkCount ?? 0) - (nodeInfo.get(a)?.linkCount ?? 0),
- )
- const topNodes = sorted.slice(0, 5).map((id) => nodeInfo.get(id)?.label ?? id)
-
- communities.push({ id: commId, nodeCount: n, cohesion, topNodes })
- }
-
- // Sort by nodeCount descending
- communities.sort((a, b) => b.nodeCount - a.nodeCount)
-
- // Re-number community IDs sequentially (0, 1, 2, ...)
- const idRemap = new Map<number, number>()
- communities.forEach((c, idx) => {
- idRemap.set(c.id, idx)
- c.id = idx
+ worker.postMessage({ nodes, edges })
})
- for (const [nodeId, oldId] of assignments) {
- assignments.set(nodeId, idRemap.get(oldId) ?? 0)
- }
-
- return { assignments, communities }
}
const WIKILINK_REGEX = /\[\[([^\]|]+?)(?:\|[^\]]+?)?\]\]/g
@@ -157,9 +115,84 @@ function fileNameToId(fileName: string): string {
return fileName.replace(/\.md$/, "")
}
+function targetAliases(value: string): string[] {
+ const lower = value.toLowerCase()
+ return [value, lower, lower.replace(/\s+/g, "-")]
+}
+
+function buildTargetIndex(nodeIds: Iterable<string>): Map<string, string> {
+ const ids = Array.from(nodeIds)
+ const index = new Map<string, string>()
+ // Exact IDs must win over case-folded aliases. On a case-sensitive
+ // filesystem, Foo.md and foo.md are distinct pages and [[foo]] must retain
+ // the reader's exact-match behavior.
+ for (const id of ids) index.set(id, id)
+ for (const id of ids) {
+ for (const alias of targetAliases(id).slice(1)) {
+ if (!index.has(alias)) index.set(alias, id)
+ }
+ }
+ return index
+}
+
+async function mapWithConcurrency<T, R>(
+ values: readonly T[],
+ limit: number,
+ mapper: (value: T) => Promise<R>,
+): Promise<R[]> {
+ const results = new Array<R>(values.length)
+ let cursor = 0
+ const workers = Array.from(
+ { length: Math.min(limit, values.length) },
+ async () => {
+ while (cursor < values.length) {
+ const index = cursor
+ cursor += 1
+ results[index] = await mapper(values[index])
+ }
+ },
+ )
+ await Promise.all(workers)
+ return results
+}
+
export async function buildWikiGraph(
projectPath: string,
-): Promise<{ nodes: GraphNode[]; edges: GraphEdge[]; communities: CommunityInfo[] }> {
+ dataVersion?: number,
+): Promise<WikiGraphResult> {
+ const normalizedProjectPath = normalizePath(projectPath)
+ if (dataVersion !== undefined) {
+ const cached = graphCache.get(normalizedProjectPath)
+ if (cached?.dataVersion === dataVersion) return cached.result
+ }
+
+ const buildKey = `${normalizedProjectPath}\u0000${dataVersion ?? "uncached"}`
+ const pending = graphBuilds.get(buildKey)
+ if (pending) return pending
+ const build = buildWikiGraphUncached(normalizedProjectPath)
+ graphBuilds.set(buildKey, build)
+ let result: WikiGraphResult
+ try {
+ result = await build
+ } finally {
+ graphBuilds.delete(buildKey)
+ }
+ if (dataVersion !== undefined) {
+ const cached = graphCache.get(normalizedProjectPath)
+ // An older build may finish after a newer dataVersion. Never let it
+ // replace the newer cached graph.
+ if (!cached || cached.dataVersion <= dataVersion) {
+ if (!cached && graphCache.size >= MAX_CACHED_PROJECT_GRAPHS) {
+ const oldestProject = graphCache.keys().next().value
+ if (oldestProject) graphCache.delete(oldestProject)
+ }
+ graphCache.set(normalizedProjectPath, { dataVersion, result })
+ }
+ }
+ return result
+}
+
+async function buildWikiGraphUncached(projectPath: string): Promise<WikiGraphResult> {
const wikiRoot = `${normalizePath(projectPath)}/wiki`
let tree: FileNode[]
@@ -180,23 +213,27 @@ export async function buildWikiGraph(
{ id: string; label: string; type: string; path: string; links: string[] }
>()
- for (const file of mdFiles) {
- const id = fileNameToId(file.name)
- let content = ""
- try {
- content = await readFile(file.path)
- } catch {
- // Skip unreadable files
- continue
- }
-
- nodeMap.set(id, {
- id,
- label: extractTitle(content, file.name),
- type: extractType(content),
- path: file.path,
- links: extractWikilinks(content),
- })
+ const parsedFiles = await mapWithConcurrency(
+ mdFiles,
+ GRAPH_FILE_READ_CONCURRENCY,
+ async (file) => {
+ try {
+ const content = await readFile(file.path)
+ const id = fileNameToId(file.name)
+ return {
+ id,
+ label: extractTitle(content, file.name),
+ type: extractType(content),
+ path: file.path,
+ links: extractWikilinks(content),
+ }
+ } catch {
+ return null
+ }
+ },
+ )
+ for (const parsed of parsedFiles) {
+ if (parsed) nodeMap.set(parsed.id, parsed)
}
// Filter out query nodes (research results, saved chat answers) — they are
@@ -216,11 +253,12 @@ export async function buildWikiGraph(
}
const rawEdges: GraphEdge[] = []
+ const targetIndex = buildTargetIndex(nodeMap.keys())
for (const [sourceId, nodeData] of nodeMap) {
for (const targetRaw of nodeData.links) {
// Normalize target: try matching by id (case-insensitive, hyphen/space)
- const targetId = resolveTarget(targetRaw, nodeMap)
+ const targetId = resolveTarget(targetRaw, targetIndex)
if (targetId === null) continue
if (targetId === sourceId) continue
@@ -245,12 +283,14 @@ export async function buildWikiGraph(
// Calculate relevance weights using the retrieval graph
let retrievalGraph: Awaited<ReturnType<typeof buildRetrievalGraph>> | null = null
- try {
- const { useWikiStore } = await import("@/stores/wiki-store")
- const dv = useWikiStore.getState().dataVersion
- retrievalGraph = await buildRetrievalGraph(normalizePath(projectPath), dv)
- } catch {
- // ignore — weights will default to 1
+ if (nodeMap.size <= MAX_WEIGHTED_GRAPH_NODES) {
+ try {
+ const { useWikiStore } = await import("@/stores/wiki-store")
+ const dv = useWikiStore.getState().dataVersion
+ retrievalGraph = await buildRetrievalGraph(normalizePath(projectPath), dv)
+ } catch {
+ // ignore — weights will default to 1
+ }
}
const edges: GraphEdge[] = dedupedEdges.map((e) => {
@@ -272,7 +312,9 @@ export async function buildWikiGraph(
linkCount: linkCounts.get(n.id) ?? 0,
}))
- const { assignments, communities } = detectCommunities(prelimNodes, edges)
+ const { assignments, communities } = await analyzeCommunities(prelimNodes, edges).catch(
+ () => detectCommunities(prelimNodes, edges),
+ )
const nodes: GraphNode[] = Array.from(nodeMap.values()).map((n) => ({
id: n.id,
@@ -288,18 +330,11 @@ export async function buildWikiGraph(
function resolveTarget(
raw: string,
- nodeMap: Map<string, { id: string }>,
+ targetIndex: ReadonlyMap<string, string>,
): string | null {
- // Direct match
- if (nodeMap.has(raw)) return raw
-
- // Normalize: lowercase, replace spaces with hyphens and vice versa
- const normalized = raw.toLowerCase().replace(/\s+/g, "-")
- for (const id of nodeMap.keys()) {
- if (id.toLowerCase() === normalized) return id
- if (id.toLowerCase() === raw.toLowerCase()) return id
- if (id.toLowerCase().replace(/\s+/g, "-") === normalized) return id
+ for (const alias of targetAliases(raw)) {
+ const target = targetIndex.get(alias)
+ if (target) return target
}
-
return null
}