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: move ingest progress to activity panel, keep chat for user interaction

nash_su93913af6fdde
diff --git a/src/components/layout/activity-panel.tsx b/src/components/layout/activity-panel.tsx
new file mode 100644
index 00000000..a431d552
--- /dev/null
+++ b/src/components/layout/activity-panel.tsx
@@ -0,0 +1,78 @@
+import { useState } from "react"
+import { ChevronUp, ChevronDown, Loader2, CheckCircle2, AlertCircle, X } from "lucide-react"
+import { useActivityStore, type ActivityItem } from "@/stores/activity-store"
+
+export function ActivityPanel() {
+ const items = useActivityStore((s) => s.items)
+ const clearDone = useActivityStore((s) => s.clearDone)
+ const [expanded, setExpanded] = useState(false)
+
+ const runningCount = items.filter((i) => i.status === "running").length
+ const hasItems = items.length > 0
+
+ if (!hasItems) return null
+
+ const latestItem = items[0]
+
+ return (
+ <div className="border-t bg-muted/30">
+ <button
+ onClick={() => setExpanded(!expanded)}
+ className="flex w-full items-center gap-2 px-3 py-1.5 text-xs text-muted-foreground hover:bg-accent/50"
+ >
+ {runningCount > 0 ? (
+ <Loader2 className="h-3 w-3 animate-spin shrink-0" />
+ ) : (
+ <CheckCircle2 className="h-3 w-3 shrink-0 text-emerald-500" />
+ )}
+ <span className="flex-1 truncate text-left">
+ {runningCount > 0
+ ? `Processing: ${latestItem?.title ?? "..."}`
+ : `Done: ${latestItem?.title ?? "All tasks complete"}`}
+ </span>
+ {expanded ? (
+ <ChevronDown className="h-3 w-3 shrink-0" />
+ ) : (
+ <ChevronUp className="h-3 w-3 shrink-0" />
+ )}
+ </button>
+
+ {expanded && (
+ <div className="max-h-48 overflow-y-auto border-t">
+ {items.map((item) => (
+ <ActivityRow key={item.id} item={item} />
+ ))}
+ {items.some((i) => i.status !== "running") && (
+ <button
+ onClick={clearDone}
+ className="w-full px-3 py-1 text-center text-[10px] text-muted-foreground hover:underline"
+ >
+ Clear completed
+ </button>
+ )}
+ </div>
+ )}
+ </div>
+ )
+}
+
+function ActivityRow({ item }: { item: ActivityItem }) {
+ return (
+ <div className="flex items-start gap-2 px-3 py-1.5 text-xs">
+ <div className="mt-0.5 shrink-0">
+ {item.status === "running" && <Loader2 className="h-3 w-3 animate-spin text-primary" />}
+ {item.status === "done" && <CheckCircle2 className="h-3 w-3 text-emerald-500" />}
+ {item.status === "error" && <AlertCircle className="h-3 w-3 text-destructive" />}
+ </div>
+ <div className="min-w-0 flex-1">
+ <div className="truncate font-medium">{item.title}</div>
+ <div className="truncate text-muted-foreground">{item.detail}</div>
+ {item.filesWritten.length > 0 && item.status === "done" && (
+ <div className="mt-0.5 text-muted-foreground">
+ {item.filesWritten.length} file{item.filesWritten.length !== 1 ? "s" : ""} written
+ </div>
+ )}
+ </div>
+ </div>
+ )
+}
diff --git a/src/components/layout/app-layout.tsx b/src/components/layout/app-layout.tsx
index c75c1958..8903adaa 100644
--- a/src/components/layout/app-layout.tsx
+++ b/src/components/layout/app-layout.tsx
@@ -4,6 +4,7 @@ import { listDirectory } from "@/commands/fs"
import { IconSidebar } from "./icon-sidebar"
import { FileTree } from "./file-tree"
import { ContentArea } from "./content-area"
+import { ActivityPanel } from "./activity-panel"
interface AppLayoutProps {
onSwitchProject: () => void
@@ -62,10 +63,13 @@ export function AppLayout({ onSwitchProject }: AppLayoutProps) {
<IconSidebar onSwitchProject={onSwitchProject} />
<div ref={containerRef} className="flex min-w-0 flex-1 overflow-hidden">
<div
- className="shrink-0 overflow-hidden border-r"
+ className="flex shrink-0 flex-col overflow-hidden border-r"
style={{ width: sidebarWidth }}
>
- <FileTree />
+ <div className="flex-1 overflow-hidden">
+ <FileTree />
+ </div>
+ <ActivityPanel />
</div>
<div
className="w-1.5 shrink-0 cursor-col-resize bg-border/40 transition-colors hover:bg-primary/30 active:bg-primary/40"
diff --git a/src/components/sources/sources-view.tsx b/src/components/sources/sources-view.tsx
index a3db499a..0c0a023c 100644
--- a/src/components/sources/sources-view.tsx
+++ b/src/components/sources/sources-view.tsx
@@ -91,14 +91,14 @@ export function SourcesView() {
setImporting(false)
await loadSources()
- // Auto-ingest each imported file
+ // Auto-ingest each imported file (runs in background, progress shown in activity panel)
if (llmConfig.apiKey || llmConfig.provider === "ollama") {
- setChatExpanded(true)
- setActiveView("wiki")
for (const sourcePath of paths) {
const fileName = sourcePath.split("/").pop() || sourcePath.split("\\").pop() || "unknown"
const destPath = `${project.path}/raw/sources/${fileName}`
- await autoIngest(project.path, destPath, llmConfig)
+ autoIngest(project.path, destPath, llmConfig).catch((err) =>
+ console.error(`Failed to auto-ingest ${fileName}:`, err)
+ )
}
}
}
diff --git a/src/lib/ingest.ts b/src/lib/ingest.ts
index 75c0f70d..1f25899a 100644
--- a/src/lib/ingest.ts
+++ b/src/lib/ingest.ts
@@ -3,6 +3,7 @@ import { streamChat } from "@/lib/llm-client"
import type { LlmConfig } from "@/stores/wiki-store"
import { useWikiStore } from "@/stores/wiki-store"
import { useChatStore } from "@/stores/chat-store"
+import { useActivityStore } from "@/stores/activity-store"
import { useReviewStore, type ReviewItem } from "@/stores/review-store"
const FILE_BLOCK_REGEX = /---FILE:\s*([^\n-]+?)\s*---\n([\s\S]*?)---END FILE---/g
@@ -17,11 +18,15 @@ export async function autoIngest(
llmConfig: LlmConfig,
signal?: AbortSignal,
): Promise<string[]> {
- const store = getStore()
- store.setMode("ingest")
- store.setIngestSource(sourcePath)
- store.clearMessages()
- store.setStreaming(false)
+ const activity = useActivityStore.getState()
+ const fileName = sourcePath.split("/").pop() ?? sourcePath
+ const activityId = activity.addItem({
+ type: "ingest",
+ title: fileName,
+ status: "running",
+ detail: "Reading source...",
+ filesWritten: [],
+ })
const [sourceContent, schema, purpose, index] = await Promise.all([
tryReadFile(sourcePath),
@@ -30,57 +35,11 @@ export async function autoIngest(
tryReadFile(`${projectPath}/wiki/index.md`),
])
- const fileName = sourcePath.split("/").pop() ?? sourcePath
-
- const systemPrompt = [
- "You are a wiki maintainer. You will read a source document and directly produce wiki files.",
- "",
- "## Output Format",
- "",
- "Output wiki files in this format:",
- "",
- "---FILE: wiki/sources/filename.md---",
- "(complete file content with YAML frontmatter)",
- "---END FILE---",
- "",
- "For each source, produce:",
- "1. A source summary page in wiki/sources/",
- "2. Entity pages in wiki/entities/ for key entities (people, organizations, products)",
- "3. Concept pages in wiki/concepts/ for key concepts (theories, methods, techniques)",
- "4. An updated wiki/index.md with new entries added to existing categories",
- "5. A log entry for wiki/log.md (just the new entry to append)",
- "",
- "Use YAML frontmatter on every page. Use [[wikilink]] syntax for cross-references.",
- "Use kebab-case filenames.",
- "",
- "## Review Items",
- "",
- "After the FILE blocks, if you find anything that needs human judgment, output REVIEW blocks:",
- "",
- "---REVIEW: type | Title---",
- "Description of what needs attention.",
- "OPTIONS: Option A | Option B | Option C",
- "PAGES: wiki/page1.md, wiki/page2.md",
- "---END REVIEW---",
- "",
- "Review types: contradiction, duplicate, missing-page, suggestion",
- "Only create reviews for things that genuinely need human input. Examples:",
- "- Contradiction: new source conflicts with existing wiki content",
- "- Duplicate: an entity/concept might already exist under a different name",
- "- Missing page: an important concept is referenced but has no dedicated page yet",
- "- Suggestion: ideas for further research or sources to look for",
- "",
- purpose ? `## Wiki Purpose\n${purpose}` : "",
- schema ? `## Wiki Schema\n${schema}` : "",
- index ? `## Current Wiki Index (add to this, don't remove existing entries)\n${index}` : "",
- ].filter(Boolean).join("\n")
+ activity.updateItem(activityId, { detail: "Generating wiki pages..." })
+ const systemPrompt = buildAutoIngestPrompt(schema, purpose, index)
const userMessage = `Ingest this source into the wiki:\n\n**File:** ${fileName}\n\n---\n\n${sourceContent.length > 50000 ? sourceContent.slice(0, 50000) + "\n\n[...truncated...]" : sourceContent}`
- store.addMessage("system", `Auto-ingesting: ${fileName}`)
- store.addMessage("user", userMessage)
- store.setStreaming(true)
-
let accumulated = ""
await streamChat(
@@ -92,43 +51,50 @@ export async function autoIngest(
{
onToken: (token) => {
accumulated += token
- getStore().appendStreamToken(token)
- },
- onDone: () => {
- getStore().finalizeStream(accumulated)
},
+ onDone: () => {},
onError: (err) => {
- getStore().finalizeStream(`Error during auto-ingest: ${err.message}`)
+ activity.updateItem(activityId, { status: "error", detail: err.message })
},
},
signal,
)
+ // If errored, stop here
+ if (useActivityStore.getState().items.find((i) => i.id === activityId)?.status === "error") {
+ return []
+ }
+
// Parse and write files
+ activity.updateItem(activityId, { detail: "Writing wiki pages..." })
const writtenPaths = await writeFileBlocks(projectPath, accumulated)
+ // Refresh file tree
if (writtenPaths.length > 0) {
- const fileList = writtenPaths.map((p) => `- ${p}`).join("\n")
- getStore().addMessage("system", `✓ Wiki updated (${writtenPaths.length} files):\n${fileList}`)
-
- // Refresh file tree
try {
const tree = await listDirectory(projectPath)
useWikiStore.getState().setFileTree(tree)
} catch {
// ignore
}
- } else {
- getStore().addMessage("system", "No wiki files were generated.")
}
// Parse and add review items
const reviewItems = parseReviewBlocks(accumulated, sourcePath)
if (reviewItems.length > 0) {
useReviewStore.getState().addItems(reviewItems)
- getStore().addMessage("system", `📋 ${reviewItems.length} item(s) added to Review for your attention.`)
}
+ const detail = writtenPaths.length > 0
+ ? `${writtenPaths.length} files written${reviewItems.length > 0 ? `, ${reviewItems.length} review item(s)` : ""}`
+ : "No files generated"
+
+ activity.updateItem(activityId, {
+ status: writtenPaths.length > 0 ? "done" : "error",
+ detail,
+ filesWritten: writtenPaths,
+ })
+
return writtenPaths
}
@@ -216,6 +182,47 @@ function parseReviewBlocks(
return items
}
+function buildAutoIngestPrompt(schema: string, purpose: string, index: string): string {
+ return [
+ "You are a wiki maintainer. You will read a source document and directly produce wiki files.",
+ "",
+ "## Output Format",
+ "",
+ "Output wiki files in this format:",
+ "",
+ "---FILE: wiki/sources/filename.md---",
+ "(complete file content with YAML frontmatter)",
+ "---END FILE---",
+ "",
+ "For each source, produce:",
+ "1. A source summary page in wiki/sources/",
+ "2. Entity pages in wiki/entities/ for key entities (people, organizations, products)",
+ "3. Concept pages in wiki/concepts/ for key concepts (theories, methods, techniques)",
+ "4. An updated wiki/index.md with new entries added to existing categories",
+ "5. A log entry for wiki/log.md (just the new entry to append)",
+ "",
+ "Use YAML frontmatter on every page. Use [[wikilink]] syntax for cross-references.",
+ "Use kebab-case filenames.",
+ "",
+ "## Review Items",
+ "",
+ "After the FILE blocks, if you find anything that needs human judgment, output REVIEW blocks:",
+ "",
+ "---REVIEW: type | Title---",
+ "Description of what needs attention.",
+ "OPTIONS: Option A | Option B | Option C",
+ "PAGES: wiki/page1.md, wiki/page2.md",
+ "---END REVIEW---",
+ "",
+ "Review types: contradiction, duplicate, missing-page, suggestion",
+ "Only create reviews for things that genuinely need human input.",
+ "",
+ purpose ? `## Wiki Purpose\n${purpose}` : "",
+ schema ? `## Wiki Schema\n${schema}` : "",
+ index ? `## Current Wiki Index (add to this, don't remove existing entries)\n${index}` : "",
+ ].filter(Boolean).join("\n")
+}
+
function getStore() {
return useChatStore.getState()
}
diff --git a/src/stores/activity-store.ts b/src/stores/activity-store.ts
new file mode 100644
index 00000000..5647659a
--- /dev/null
+++ b/src/stores/activity-store.ts
@@ -0,0 +1,55 @@
+import { create } from "zustand"
+
+export interface ActivityItem {
+ id: string
+ type: "ingest" | "lint" | "query"
+ title: string
+ status: "running" | "done" | "error"
+ detail: string
+ filesWritten: string[]
+ createdAt: number
+}
+
+interface ActivityState {
+ items: ActivityItem[]
+ addItem: (item: Omit<ActivityItem, "id" | "createdAt">) => string
+ updateItem: (id: string, updates: Partial<Pick<ActivityItem, "status" | "detail" | "filesWritten">>) => void
+ appendDetail: (id: string, text: string) => void
+ clearDone: () => void
+}
+
+let counter = 0
+
+export const useActivityStore = create<ActivityState>((set, get) => ({
+ items: [],
+
+ addItem: (item) => {
+ const id = `activity-${++counter}`
+ set((state) => ({
+ items: [
+ { ...item, id, createdAt: Date.now() },
+ ...state.items,
+ ],
+ }))
+ return id
+ },
+
+ updateItem: (id, updates) =>
+ set((state) => ({
+ items: state.items.map((item) =>
+ item.id === id ? { ...item, ...updates } : item
+ ),
+ })),
+
+ appendDetail: (id, text) =>
+ set((state) => ({
+ items: state.items.map((item) =>
+ item.id === id ? { ...item, detail: item.detail + text } : item
+ ),
+ })),
+
+ clearDone: () =>
+ set((state) => ({
+ items: state.items.filter((i) => i.status === "running"),
+ })),
+}))