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
fix: source filenames preserve original name + Chinese chars, handle conflicts
nash_su3b538775c261
diff --git a/src/components/sources/sources-view.tsx b/src/components/sources/sources-view.tsxindex 87f177f6..f1e62096 100644--- a/src/components/sources/sources-view.tsx+++ b/src/components/sources/sources-view.tsx@@ -84,15 +84,15 @@ export function SourcesView() {const importedPaths: string[] = []for (const sourcePath of paths) {- const fileName = sourcePath.split("/").pop() || sourcePath.split("\\").pop() || "unknown"- const destPath = `${project.path}/raw/sources/${fileName}`+ const originalName = sourcePath.split("/").pop() || sourcePath.split("\\").pop() || "unknown"+ const destPath = await getUniqueDestPath(`${project.path}/raw/sources`, originalName)try {await copyFile(sourcePath, destPath)importedPaths.push(destPath)// Pre-process file (extract text from PDF, etc.) for instant preview laterpreprocessFile(destPath).catch(() => {})} catch (err) {- console.error(`Failed to import ${fileName}:`, err)+ console.error(`Failed to import ${originalName}:`, err)}}@@ -264,6 +264,49 @@ export function SourcesView() {)}+/**+ * Generate a unique destination path. If file already exists, adds date/counter suffix.+ * "file.pdf" → "file.pdf" (first time)+ * "file.pdf" → "file-20260406.pdf" (conflict)+ * "file.pdf" → "file-20260406-2.pdf" (second conflict same day)+ */+async function getUniqueDestPath(dir: string, fileName: string): Promise<string> {+ const basePath = `${dir}/${fileName}`++ // Check if file exists by trying to read it+ try {+ await readFile(basePath)+ } catch {+ // File doesn't exist — use original name+ return basePath+ }++ // File exists — add date suffix+ const ext = fileName.includes(".") ? fileName.slice(fileName.lastIndexOf(".")) : ""+ const nameWithoutExt = ext ? fileName.slice(0, -ext.length) : fileName+ const date = new Date().toISOString().slice(0, 10).replace(/-/g, "")++ const withDate = `${dir}/${nameWithoutExt}-${date}${ext}`+ try {+ await readFile(withDate)+ } catch {+ return withDate+ }++ // Date suffix also exists — add counter+ for (let i = 2; i <= 99; i++) {+ const withCounter = `${dir}/${nameWithoutExt}-${date}-${i}${ext}`+ try {+ await readFile(withCounter)+ } catch {+ return withCounter+ }+ }++ // Shouldn't happen, but fallback+ return `${dir}/${nameWithoutExt}-${date}-${Date.now()}${ext}`+}+function flattenFiles(nodes: FileNode[]): FileNode[] {const files: FileNode[] = []for (const node of nodes) {diff --git a/src/lib/ingest.ts b/src/lib/ingest.tsindex fdb7fe94..2d6d6c33 100644--- a/src/lib/ingest.ts+++ b/src/lib/ingest.ts@@ -281,13 +281,8 @@ function buildAnalysisPrompt(purpose: string, index: string): string {* Step 2 prompt: AI takes its own analysis and generates wiki files + review items.*/function buildGenerationPrompt(schema: string, purpose: string, index: string, sourceFileName: string): string {- // Derive a slug from the source filename for the source summary page- const sourceSlug = sourceFileName- .replace(/\.[^.]+$/, "")- .toLowerCase()- .replace(/[^a-z0-9\s-]/g, "")- .trim()- .replace(/\s+/g, "-")+ // Use original filename (without extension) as the source summary page name+ const sourceBaseName = sourceFileName.replace(/\.[^.]+$/, "")return ["You are a wiki maintainer. Based on the analysis provided, generate wiki files.",@@ -305,7 +300,7 @@ function buildGenerationPrompt(schema: string, purpose: string, index: string, s"---END FILE---","","Generate:",- `1. A source summary page at **wiki/sources/${sourceSlug}.md** (MUST use this exact path)`,+ `1. A source summary page at **wiki/sources/${sourceBaseName}.md** (MUST use this exact path)`,"2. Entity pages in wiki/entities/ for key entities identified in the analysis","3. Concept pages in wiki/concepts/ for key concepts identified in the analysis","4. An updated wiki/index.md — add new entries to existing categories, preserve all existing entries",