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: search and chat now include raw source documents, not just wiki summaries
nash_sucb5651e9e303
diff --git a/src/components/chat/chat-panel.tsx b/src/components/chat/chat-panel.tsxindex 659427cc..00ce63ad 100644--- a/src/components/chat/chat-panel.tsx+++ b/src/components/chat/chat-panel.tsx@@ -83,8 +83,9 @@ export function ChatPanel() {}}- // If search found nothing, read all wiki pages (for small wikis)+ // If search found nothing, read all wiki pages + raw sources (for small wikis)if (relevantPages.length === 0) {+ // Read all wiki pagestry {const wikiTree = await listDirectory(`${project.path}/wiki`)const allFiles = flattenMdFiles(wikiTree)@@ -101,6 +102,59 @@ export function ChatPanel() {} catch {// ignore}+ // Also read raw sources+ try {+ const rawTree = await listDirectory(`${project.path}/raw/sources`)+ const rawFiles = flattenAllFiles(rawTree)+ for (const file of rawFiles.slice(0, 5)) {+ try {+ const content = await readFile(file.path)+ // Truncate large source files to avoid overwhelming context+ const truncated = content.length > 20000+ ? content.slice(0, 20000) + "\n\n[...truncated...]"+ : content+ relevantPages.push({+ title: `[Source] ${file.name}`,+ path: `raw/sources/${file.name}`,+ content: truncated,+ })+ } catch {+ // skip+ }+ }+ } catch {+ // ignore+ }+ }++ // Always include matching raw sources in context (search results may include them)+ const rawSourcePaths = relevantPages+ .filter((p) => p.path.startsWith("raw/"))+ .map((p) => p.path)++ // If no raw sources found via search, add them for context+ if (rawSourcePaths.length === 0) {+ try {+ const rawTree = await listDirectory(`${project.path}/raw/sources`)+ const rawFiles = flattenAllFiles(rawTree)+ for (const file of rawFiles.slice(0, 3)) {+ try {+ const content = await readFile(file.path)+ const truncated = content.length > 15000+ ? content.slice(0, 15000) + "\n\n[...truncated...]"+ : content+ relevantPages.push({+ title: `[Source] ${file.name}`,+ path: `raw/sources/${file.name}`,+ content: truncated,+ })+ } catch {+ // skip+ }+ }+ } catch {+ // ignore+ }}// Get source file list@@ -125,10 +179,11 @@ export function ChatPanel() {systemMessages.push({role: "system",content: [- "You are a knowledgeable wiki assistant. Answer questions based on the wiki content provided below.",+ "You are a knowledgeable wiki assistant. Answer questions based on the wiki pages and source documents provided below.","","## Rules",- "- Answer based ONLY on the wiki page content provided below. Do not make up information.",+ "- Answer based on the wiki pages AND raw source documents provided below.",+ "- Pages marked [Source] are the user's original uploaded documents — they contain the full detail.","- If the provided pages don't contain enough information, say so honestly.","- Use [[wikilink]] syntax to reference wiki pages you cite.","- At the VERY END of your response, add a hidden comment listing source files used:",@@ -140,7 +195,7 @@ export function ChatPanel() {purpose ? `## Wiki Purpose\n${purpose}` : "",`## Source Files\n${sourceFileList}`,index ? `## Wiki Index\n${index}` : "",- `## Relevant Wiki Pages (use these to answer)\n\n${pagesContext}`,+ `## Relevant Pages & Source Documents (use these to answer)\n\n${pagesContext}`,].filter(Boolean).join("\n"),})}@@ -267,3 +322,15 @@ function flattenMdFiles(nodes: FileNode[]): FileNode[] {}return files}++function flattenAllFiles(nodes: FileNode[]): FileNode[] {+ const files: FileNode[] = []+ for (const node of nodes) {+ if (node.is_dir && node.children) {+ files.push(...flattenAllFiles(node.children))+ } else if (!node.is_dir) {+ files.push(node)+ }+ }+ return files+}diff --git a/src/lib/search.ts b/src/lib/search.tsindex 0fd836be..1e14f8c7 100644--- a/src/lib/search.ts+++ b/src/lib/search.ts@@ -56,21 +56,39 @@ export async function searchWiki(): Promise<SearchResult[]> {if (!query.trim()) return []- const wikiRoot = `${projectPath}/wiki`- let tree: FileNode[]+ const lowerQuery = query.toLowerCase()+ const titleMatches: SearchResult[] = []+ const contentMatches: SearchResult[] = []++ // Search wiki pagestry {- tree = await listDirectory(wikiRoot)+ const wikiTree = await listDirectory(`${projectPath}/wiki`)+ const wikiFiles = flattenMdFiles(wikiTree)+ await searchFiles(wikiFiles, lowerQuery, query, titleMatches, contentMatches)} catch {- return []+ // no wiki directory}- const wikiFiles = flattenMdFiles(tree)- const lowerQuery = query.toLowerCase()+ // Also search raw sources (extracted text)+ try {+ const rawTree = await listDirectory(`${projectPath}/raw/sources`)+ const rawFiles = flattenAllFiles(rawTree)+ await searchFiles(rawFiles, lowerQuery, query, titleMatches, contentMatches)+ } catch {+ // no raw sources+ }- const titleMatches: SearchResult[] = []- const contentMatches: SearchResult[] = []+ return [...titleMatches, ...contentMatches].slice(0, MAX_RESULTS)+}- for (const file of wikiFiles) {+async function searchFiles(+ files: FileNode[],+ lowerQuery: string,+ query: string,+ titleMatches: SearchResult[],+ contentMatches: SearchResult[],+): Promise<void> {+ for (const file of files) {let content = ""try {content = await readFile(file.path)@@ -103,6 +121,16 @@ export async function searchWiki(contentMatches.push(result)}}+}- return [...titleMatches, ...contentMatches].slice(0, MAX_RESULTS)+function flattenAllFiles(nodes: FileNode[]): FileNode[] {+ const files: FileNode[] = []+ for (const node of nodes) {+ if (node.is_dir && node.children) {+ files.push(...flattenAllFiles(node.children))+ } else if (!node.is_dir) {+ files.push(node)+ }+ }+ return files}