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
feat: add Rust file system and project commands
nash_sua01b5c552183
diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lockindex 7a83c099..f9cc4b3a 100644--- a/src-tauri/Cargo.lock+++ b/src-tauri/Cargo.lock@@ -451,8 +451,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "c673075a2e0e5f4a1dde27ce9dee1ea4558c7ffe648f576438a20ca1d2acc4b0"dependencies = ["iana-time-zone",+ "js-sys","num-traits","serde",+ "wasm-bindgen","windows-link 0.2.1",]@@ -1993,6 +1995,7 @@ checksum = "92daf443525c4cce67b150400bc2316076100ce0b3686209eb8cf3c31612e6f0"name = "llm-wiki"version = "0.1.0"dependencies = [+ "chrono","serde","serde_json","tauri",diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.tomlindex ba93c59f..0f6b22af 100644--- a/src-tauri/Cargo.toml+++ b/src-tauri/Cargo.toml@@ -23,6 +23,7 @@ tauri = { version = "2", features = [] }tauri-plugin-opener = "2"serde = { version = "1", features = ["derive"] }serde_json = "1"+chrono = { version = "0.4", features = ["clock"] }[profile.release]codegen-units = 1diff --git a/src-tauri/src/commands/fs.rs b/src-tauri/src/commands/fs.rsnew file mode 100644index 00000000..43a4a8d8--- /dev/null+++ b/src-tauri/src/commands/fs.rs@@ -0,0 +1,100 @@+use std::fs;+use std::path::Path;++use crate::types::wiki::FileNode;++#[tauri::command]+pub fn read_file(path: String) -> Result<String, String> {+ fs::read_to_string(&path).map_err(|e| format!("Failed to read file '{}': {}", path, e))+}++#[tauri::command]+pub fn write_file(path: String, contents: String) -> Result<(), String> {+ let p = Path::new(&path);+ if let Some(parent) = p.parent() {+ fs::create_dir_all(parent)+ .map_err(|e| format!("Failed to create parent dirs for '{}': {}", path, e))?;+ }+ fs::write(&path, contents).map_err(|e| format!("Failed to write file '{}': {}", path, e))+}++#[tauri::command]+pub fn list_directory(path: String) -> Result<Vec<FileNode>, String> {+ let p = Path::new(&path);+ if !p.exists() {+ return Err(format!("Path does not exist: '{}'", path));+ }+ if !p.is_dir() {+ return Err(format!("Path is not a directory: '{}'", path));+ }+ let nodes = build_tree(p, 0, 3)?;+ Ok(nodes)+}++fn build_tree(dir: &Path, depth: usize, max_depth: usize) -> Result<Vec<FileNode>, String> {+ if depth >= max_depth {+ return Ok(vec![]);+ }++ let mut entries: Vec<_> = fs::read_dir(dir)+ .map_err(|e| format!("Failed to read directory '{}': {}", dir.display(), e))?+ .filter_map(|entry| entry.ok())+ .filter(|entry| {+ // Skip dotfiles+ entry+ .file_name()+ .to_str()+ .map(|n| !n.starts_with('.'))+ .unwrap_or(false)+ })+ .collect();++ // Sort: directories first, then alphabetical within each group+ entries.sort_by(|a, b| {+ let a_is_dir = a.path().is_dir();+ let b_is_dir = b.path().is_dir();+ match (a_is_dir, b_is_dir) {+ (true, false) => std::cmp::Ordering::Less,+ (false, true) => std::cmp::Ordering::Greater,+ _ => a.file_name().cmp(&b.file_name()),+ }+ });++ let mut nodes = Vec::new();+ for entry in entries {+ let entry_path = entry.path();+ let name = entry+ .file_name()+ .to_str()+ .unwrap_or("")+ .to_string();+ let path_str = entry_path.to_string_lossy().to_string();+ let is_dir = entry_path.is_dir();++ let children = if is_dir {+ let kids = build_tree(&entry_path, depth + 1, max_depth)?;+ if kids.is_empty() {+ None+ } else {+ Some(kids)+ }+ } else {+ None+ };++ nodes.push(FileNode {+ name,+ path: path_str,+ is_dir,+ children,+ });+ }++ Ok(nodes)+}++#[tauri::command]+pub fn create_directory(path: String) -> Result<(), String> {+ fs::create_dir_all(&path)+ .map_err(|e| format!("Failed to create directory '{}': {}", path, e))+}diff --git a/src-tauri/src/commands/mod.rs b/src-tauri/src/commands/mod.rsnew file mode 100644index 00000000..35450a2f--- /dev/null+++ b/src-tauri/src/commands/mod.rs@@ -0,0 +1,2 @@+pub mod fs;+pub mod project;diff --git a/src-tauri/src/commands/project.rs b/src-tauri/src/commands/project.rsnew file mode 100644index 00000000..289b7912--- /dev/null+++ b/src-tauri/src/commands/project.rs@@ -0,0 +1,230 @@+use std::fs;+use std::path::Path;++use chrono::Local;++use crate::types::wiki::WikiProject;++#[tauri::command]+pub fn create_project(name: String, path: String) -> Result<WikiProject, String> {+ let root = Path::new(&path);++ // Create all required subdirectories+ let dirs = [+ "raw/sources",+ "raw/assets",+ "wiki/entities",+ "wiki/concepts",+ "wiki/sources",+ "wiki/queries",+ "wiki/comparisons",+ "wiki/synthesis",+ ];+ for dir in &dirs {+ fs::create_dir_all(root.join(dir))+ .map_err(|e| format!("Failed to create directory '{}': {}", dir, e))?;+ }++ let today = Local::now().format("%Y-%m-%d").to_string();++ // schema.md+ let schema_content = format!(+ r#"# Wiki Schema++## Page Types++| Type | Directory | Purpose |+|------|-----------|---------|+| entity | wiki/entities/ | Named things (models, companies, people, datasets) |+| concept | wiki/concepts/ | Ideas, techniques, phenomena |+| source | wiki/sources/ | Papers, articles, talks, blog posts |+| query | wiki/queries/ | Open questions under investigation |+| comparison | wiki/comparisons/ | Side-by-side analysis of related entities |+| synthesis | wiki/synthesis/ | Cross-cutting summaries and conclusions |++## Naming Conventions++- Files: `kebab-case.md`+- Entities: match official name where possible (e.g., `gpt-4.md`, `openai.md`)+- Concepts: descriptive noun phrases (e.g., `chain-of-thought.md`)+- Sources: `author-year-slug.md` (e.g., `wei-2022-chain-of-thought.md`)+- Queries: question as slug (e.g., `does-scale-improve-reasoning.md`)++## Frontmatter++All pages must include YAML frontmatter:++```yaml+---+type: entity | concept | source | query | comparison | synthesis | overview+title: Human-readable title+tags: []+related: []+created: YYYY-MM-DD+updated: YYYY-MM-DD+---+```++Source pages also include:+```yaml+authors: []+year: YYYY+url: ""+venue: ""+```++## Index Format++`wiki/index.md` lists all pages grouped by type. Each entry:+```+- [[page-slug]] — one-line description+```++## Log Format++`wiki/log.md` records research activity in reverse chronological order:+```+## YYYY-MM-DD++- Action taken / finding noted+```++## Cross-referencing Rules++- Use `[[page-slug]]` syntax to link between wiki pages+- Every entity and concept should appear in `wiki/index.md`+- Queries link to the sources and concepts they draw on+- Synthesis pages cite all contributing sources via `related:`++## Contradiction Handling++When sources contradict each other:+1. Note the contradiction in the relevant concept or entity page+2. Create or update a query page to track the open question+3. Link both sources from the query page+4. Resolve in a synthesis page once sufficient evidence exists+"#+ );+ write_file_inner(root.join("schema.md"), &schema_content)?;++ // purpose.md+ let purpose_content = r#"# Project Purpose++## Goal++<!-- What are you trying to understand or build? -->++## Key Questions++<!-- List the primary questions driving this research -->++1.+2.+3.++## Scope++<!-- What is in scope? What is explicitly out of scope? -->++**In scope:**+-++**Out of scope:**+-++## Thesis++<!-- Your current working hypothesis or conclusion (update as research progresses) -->++> TBD+"#;+ write_file_inner(root.join("purpose.md"), purpose_content)?;++ // wiki/index.md+ let index_content = r#"# Wiki Index++## Entities++## Concepts++## Sources++## Queries++## Comparisons++## Synthesis+"#;+ write_file_inner(root.join("wiki/index.md"), index_content)?;++ // wiki/log.md+ let log_content = format!(+ r#"# Research Log++## {today}++- Project created+"#+ );+ write_file_inner(root.join("wiki/log.md"), &log_content)?;++ // wiki/overview.md+ let overview_content = r#"---+type: overview+title: Project Overview+tags: []+related: []+---++# Overview++<!-- Provide a high-level summary of what this wiki covers and its current state. Update regularly as understanding deepens. -->+"#;+ write_file_inner(root.join("wiki/overview.md"), overview_content)?;++ Ok(WikiProject { name, path })+}++#[tauri::command]+pub fn open_project(path: String) -> Result<WikiProject, String> {+ let root = Path::new(&path);++ if !root.exists() {+ return Err(format!("Path does not exist: '{}'", path));+ }+ if !root.is_dir() {+ return Err(format!("Path is not a directory: '{}'", path));+ }++ // Validate that this looks like a wiki project+ if !root.join("schema.md").exists() {+ return Err(format!(+ "Not a valid wiki project (missing schema.md): '{}'",+ path+ ));+ }+ if !root.join("wiki").is_dir() {+ return Err(format!(+ "Not a valid wiki project (missing wiki/ directory): '{}'",+ path+ ));+ }++ // Derive project name from the directory name+ let name = root+ .file_name()+ .and_then(|n| n.to_str())+ .unwrap_or("Unknown")+ .to_string();++ Ok(WikiProject { name, path })+}++fn write_file_inner(path: std::path::PathBuf, contents: &str) -> Result<(), String> {+ if let Some(parent) = path.parent() {+ fs::create_dir_all(parent)+ .map_err(|e| format!("Failed to create parent dirs for '{}': {}", path.display(), e))?;+ }+ fs::write(&path, contents)+ .map_err(|e| format!("Failed to write file '{}': {}", path.display(), e))+}diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rsindex a74da47c..3911bf55 100644--- a/src-tauri/src/lib.rs+++ b/src-tauri/src/lib.rs@@ -1,8 +1,18 @@+mod commands;+mod types;+#[cfg_attr(mobile, tauri::mobile_entry_point)]pub fn run() {tauri::Builder::default().plugin(tauri_plugin_opener::init())- .invoke_handler(tauri::generate_handler![])+ .invoke_handler(tauri::generate_handler![+ commands::fs::read_file,+ commands::fs::write_file,+ commands::fs::list_directory,+ commands::fs::create_directory,+ commands::project::create_project,+ commands::project::open_project,+ ]).run(tauri::generate_context!()).expect("error while running tauri application");}