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

feat: add Knowledge View as default sidebar, with Files tab toggle

nash_su60f40815b349
diff --git a/src/components/layout/app-layout.tsx b/src/components/layout/app-layout.tsx
index 209ab837..9c4b380f 100644
--- a/src/components/layout/app-layout.tsx
+++ b/src/components/layout/app-layout.tsx
@@ -2,7 +2,7 @@ import { useCallback, useEffect, useRef, useState } from "react"
import { useWikiStore } from "@/stores/wiki-store"
import { listDirectory } from "@/commands/fs"
import { IconSidebar } from "./icon-sidebar"
-import { FileTree } from "./file-tree"
+import { SidebarPanel } from "./sidebar-panel"
import { ContentArea } from "./content-area"
import { PreviewPanel } from "./preview-panel"
import { ActivityPanel } from "./activity-panel"
@@ -82,7 +82,7 @@ export function AppLayout({ onSwitchProject }: AppLayoutProps) {
style={{ width: leftWidth }}
>
<div className="flex-1 overflow-hidden">
- <FileTree />
+ <SidebarPanel />
</div>
<ActivityPanel />
</div>
diff --git a/src/components/layout/knowledge-tree.tsx b/src/components/layout/knowledge-tree.tsx
new file mode 100644
index 00000000..5e9a2172
--- /dev/null
+++ b/src/components/layout/knowledge-tree.tsx
@@ -0,0 +1,288 @@
+import { useState, useEffect, useCallback } from "react"
+import {
+ FileText, Users, Lightbulb, BookOpen, HelpCircle, GitMerge, BarChart3, ChevronRight, ChevronDown, Layout,
+} from "lucide-react"
+import { ScrollArea } from "@/components/ui/scroll-area"
+import { useWikiStore } from "@/stores/wiki-store"
+import { readFile, listDirectory } from "@/commands/fs"
+import type { FileNode } from "@/types/wiki"
+
+interface WikiPageInfo {
+ path: string
+ title: string
+ type: string
+ tags: string[]
+}
+
+const TYPE_CONFIG: Record<string, { icon: typeof FileText; label: string; color: string; order: number }> = {
+ overview: { icon: Layout, label: "Overview", color: "text-yellow-500", order: 0 },
+ entity: { icon: Users, label: "Entities", color: "text-blue-500", order: 1 },
+ concept: { icon: Lightbulb, label: "Concepts", color: "text-purple-500", order: 2 },
+ source: { icon: BookOpen, label: "Sources", color: "text-orange-500", order: 3 },
+ synthesis: { icon: GitMerge, label: "Synthesis", color: "text-red-500", order: 4 },
+ comparison: { icon: BarChart3, label: "Comparisons", color: "text-emerald-500",order: 5 },
+ query: { icon: HelpCircle, label: "Queries", color: "text-green-500", order: 6 },
+}
+
+const DEFAULT_CONFIG = { icon: FileText, label: "Other", color: "text-muted-foreground", order: 99 }
+
+export function KnowledgeTree() {
+ const project = useWikiStore((s) => s.project)
+ const selectedFile = useWikiStore((s) => s.selectedFile)
+ const setSelectedFile = useWikiStore((s) => s.setSelectedFile)
+ const fileTree = useWikiStore((s) => s.fileTree)
+ const [pages, setPages] = useState<WikiPageInfo[]>([])
+ const [expandedTypes, setExpandedTypes] = useState<Set<string>>(new Set(["overview", "entity", "concept", "source"]))
+
+ const loadPages = useCallback(async () => {
+ if (!project) return
+ try {
+ const wikiTree = await listDirectory(`${project.path}/wiki`)
+ const mdFiles = flattenMdFiles(wikiTree)
+
+ const pageInfos: WikiPageInfo[] = []
+ for (const file of mdFiles) {
+ // Skip index.md and log.md
+ if (file.name === "index.md" || file.name === "log.md") continue
+ try {
+ const content = await readFile(file.path)
+ const info = parsePageInfo(file.path, file.name, content)
+ pageInfos.push(info)
+ } catch {
+ pageInfos.push({
+ path: file.path,
+ title: file.name.replace(".md", "").replace(/-/g, " "),
+ type: "other",
+ tags: [],
+ })
+ }
+ }
+
+ setPages(pageInfos)
+ } catch {
+ setPages([])
+ }
+ }, [project])
+
+ // Reload when file tree changes (after ingest writes new pages)
+ useEffect(() => {
+ loadPages()
+ }, [loadPages, fileTree])
+
+ if (!project) {
+ return (
+ <div className="flex h-full items-center justify-center p-4 text-sm text-muted-foreground">
+ No project open
+ </div>
+ )
+ }
+
+ // Group pages by type
+ const grouped = new Map<string, WikiPageInfo[]>()
+ for (const page of pages) {
+ const list = grouped.get(page.type) ?? []
+ list.push(page)
+ grouped.set(page.type, list)
+ }
+
+ // Sort groups by configured order
+ const sortedGroups = [...grouped.entries()].sort((a, b) => {
+ const orderA = TYPE_CONFIG[a[0]]?.order ?? DEFAULT_CONFIG.order
+ const orderB = TYPE_CONFIG[b[0]]?.order ?? DEFAULT_CONFIG.order
+ return orderA - orderB
+ })
+
+ function toggleType(type: string) {
+ setExpandedTypes((prev) => {
+ const next = new Set(prev)
+ if (next.has(type)) next.delete(type)
+ else next.add(type)
+ return next
+ })
+ }
+
+ return (
+ <ScrollArea className="h-full">
+ <div className="p-2">
+ <div className="mb-2 px-2 text-xs font-semibold uppercase text-muted-foreground">
+ {project.name}
+ </div>
+
+ {sortedGroups.length === 0 && (
+ <div className="px-2 py-4 text-center text-xs text-muted-foreground">
+ No wiki pages yet. Import sources to get started.
+ </div>
+ )}
+
+ {sortedGroups.map(([type, items]) => {
+ const config = TYPE_CONFIG[type] ?? DEFAULT_CONFIG
+ const Icon = config.icon
+ const isExpanded = expandedTypes.has(type)
+
+ return (
+ <div key={type} className="mb-1">
+ <button
+ onClick={() => toggleType(type)}
+ className="flex w-full items-center gap-1.5 rounded-md px-2 py-1.5 text-sm hover:bg-accent/50"
+ >
+ {isExpanded ? (
+ <ChevronDown className="h-3.5 w-3.5 shrink-0 text-muted-foreground" />
+ ) : (
+ <ChevronRight className="h-3.5 w-3.5 shrink-0 text-muted-foreground" />
+ )}
+ <Icon className={`h-3.5 w-3.5 shrink-0 ${config.color}`} />
+ <span className="flex-1 text-left font-medium">{config.label}</span>
+ <span className="text-xs text-muted-foreground">{items.length}</span>
+ </button>
+
+ {isExpanded && (
+ <div className="ml-3">
+ {items.map((page) => {
+ const isSelected = selectedFile === page.path
+ return (
+ <button
+ key={page.path}
+ onClick={() => setSelectedFile(page.path)}
+ className={`flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-sm ${
+ isSelected
+ ? "bg-accent text-accent-foreground"
+ : "text-muted-foreground hover:bg-accent/50 hover:text-accent-foreground"
+ }`}
+ title={page.path}
+ >
+ <span className="truncate">{page.title}</span>
+ </button>
+ )
+ })}
+ </div>
+ )}
+ </div>
+ )
+ })}
+
+ {/* Raw sources quick access */}
+ <RawSourcesSection />
+ </div>
+ </ScrollArea>
+ )
+}
+
+function RawSourcesSection() {
+ const project = useWikiStore((s) => s.project)
+ const setSelectedFile = useWikiStore((s) => s.setSelectedFile)
+ const selectedFile = useWikiStore((s) => s.selectedFile)
+ const [expanded, setExpanded] = useState(false)
+ const [sources, setSources] = useState<FileNode[]>([])
+
+ useEffect(() => {
+ if (!project) return
+ listDirectory(`${project.path}/raw/sources`)
+ .then((tree) => setSources(flattenAllFiles(tree)))
+ .catch(() => setSources([]))
+ }, [project])
+
+ if (sources.length === 0) return null
+
+ return (
+ <div className="mt-2 border-t pt-2">
+ <button
+ onClick={() => setExpanded(!expanded)}
+ className="flex w-full items-center gap-1.5 rounded-md px-2 py-1.5 text-sm hover:bg-accent/50"
+ >
+ {expanded ? (
+ <ChevronDown className="h-3.5 w-3.5 shrink-0 text-muted-foreground" />
+ ) : (
+ <ChevronRight className="h-3.5 w-3.5 shrink-0 text-muted-foreground" />
+ )}
+ <BookOpen className="h-3.5 w-3.5 shrink-0 text-amber-600" />
+ <span className="flex-1 text-left font-medium text-muted-foreground">Raw Sources</span>
+ <span className="text-xs text-muted-foreground">{sources.length}</span>
+ </button>
+ {expanded && (
+ <div className="ml-3">
+ {sources.map((file) => {
+ const isSelected = selectedFile === file.path
+ return (
+ <button
+ key={file.path}
+ onClick={() => setSelectedFile(file.path)}
+ className={`flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-sm ${
+ isSelected
+ ? "bg-accent text-accent-foreground"
+ : "text-muted-foreground hover:bg-accent/50 hover:text-accent-foreground"
+ }`}
+ >
+ <span className="truncate">{file.name}</span>
+ </button>
+ )
+ })}
+ </div>
+ )}
+ </div>
+ )
+}
+
+function parsePageInfo(path: string, fileName: string, content: string): WikiPageInfo {
+ let type = "other"
+ let title = fileName.replace(".md", "").replace(/-/g, " ")
+ const tags: string[] = []
+
+ // Parse YAML frontmatter
+ const fmMatch = content.match(/^---\n([\s\S]*?)\n---/)
+ if (fmMatch) {
+ const fm = fmMatch[1]
+ const typeMatch = fm.match(/^type:\s*(.+)$/m)
+ if (typeMatch) type = typeMatch[1].trim().toLowerCase()
+
+ const titleMatch = fm.match(/^title:\s*["']?(.+?)["']?\s*$/m)
+ if (titleMatch) title = titleMatch[1].trim()
+
+ const tagsMatch = fm.match(/^tags:\s*\[(.+?)\]/m)
+ if (tagsMatch) {
+ tags.push(...tagsMatch[1].split(",").map((t) => t.trim().replace(/["']/g, "")))
+ }
+ }
+
+ // Fallback: try first heading if no frontmatter title
+ if (title === fileName.replace(".md", "").replace(/-/g, " ")) {
+ const headingMatch = content.match(/^#\s+(.+)$/m)
+ if (headingMatch) title = headingMatch[1].trim()
+ }
+
+ // Fallback: infer type from path
+ if (type === "other") {
+ if (path.includes("/entities/")) type = "entity"
+ else if (path.includes("/concepts/")) type = "concept"
+ else if (path.includes("/sources/")) type = "source"
+ else if (path.includes("/queries/")) type = "query"
+ else if (path.includes("/comparisons/")) type = "comparison"
+ else if (path.includes("/synthesis/")) type = "synthesis"
+ else if (fileName === "overview.md") type = "overview"
+ }
+
+ return { path, title, type, tags }
+}
+
+function flattenMdFiles(nodes: FileNode[]): FileNode[] {
+ const files: FileNode[] = []
+ for (const node of nodes) {
+ if (node.is_dir && node.children) {
+ files.push(...flattenMdFiles(node.children))
+ } else if (!node.is_dir && node.name.endsWith(".md")) {
+ files.push(node)
+ }
+ }
+ 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/components/layout/sidebar-panel.tsx b/src/components/layout/sidebar-panel.tsx
new file mode 100644
index 00000000..ca1890d0
--- /dev/null
+++ b/src/components/layout/sidebar-panel.tsx
@@ -0,0 +1,39 @@
+import { useState } from "react"
+import { useTranslation } from "react-i18next"
+import { KnowledgeTree } from "./knowledge-tree"
+import { FileTree } from "./file-tree"
+
+export function SidebarPanel() {
+ const { t } = useTranslation()
+ const [mode, setMode] = useState<"knowledge" | "files">("knowledge")
+
+ return (
+ <div className="flex h-full flex-col">
+ <div className="flex shrink-0 border-b">
+ <button
+ onClick={() => setMode("knowledge")}
+ className={`flex-1 px-3 py-1.5 text-xs font-medium transition-colors ${
+ mode === "knowledge"
+ ? "border-b-2 border-primary text-foreground"
+ : "text-muted-foreground hover:text-foreground"
+ }`}
+ >
+ Knowledge
+ </button>
+ <button
+ onClick={() => setMode("files")}
+ className={`flex-1 px-3 py-1.5 text-xs font-medium transition-colors ${
+ mode === "files"
+ ? "border-b-2 border-primary text-foreground"
+ : "text-muted-foreground hover:text-foreground"
+ }`}
+ >
+ Files
+ </button>
+ </div>
+ <div className="flex-1 overflow-hidden">
+ {mode === "knowledge" ? <KnowledgeTree /> : <FileTree />}
+ </div>
+ </div>
+ )
+}