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 Review system for async human-in-the-loop confirmations

nash_su35a4c007b3ec
diff --git a/src/components/layout/content-area.tsx b/src/components/layout/content-area.tsx
index 74ff67a7..822e270c 100644
--- a/src/components/layout/content-area.tsx
+++ b/src/components/layout/content-area.tsx
@@ -7,6 +7,7 @@ import { FilePreview } from "@/components/editor/file-preview"
import { ChatBar } from "./chat-bar"
import { SettingsView } from "@/components/settings/settings-view"
import { SourcesView } from "@/components/sources/sources-view"
+import { ReviewView } from "@/components/review/review-view"
export function ContentArea() {
const selectedFile = useWikiStore((s) => s.selectedFile)
@@ -64,6 +65,10 @@ export function ContentArea() {
return <SourcesView />
}
+ if (activeView === "review") {
+ return <ReviewView />
+ }
+
const category = selectedFile ? getFileCategory(selectedFile) : null
const editorContent = (
diff --git a/src/components/layout/icon-sidebar.tsx b/src/components/layout/icon-sidebar.tsx
index 2931952a..729726d9 100644
--- a/src/components/layout/icon-sidebar.tsx
+++ b/src/components/layout/icon-sidebar.tsx
@@ -1,8 +1,9 @@
import {
- FileText, FolderOpen, Search, Network, ClipboardCheck, Settings, ArrowLeftRight,
+ FileText, FolderOpen, Search, Network, ClipboardCheck, Settings, ArrowLeftRight, ClipboardList,
} from "lucide-react"
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"
import { useWikiStore } from "@/stores/wiki-store"
+import { useReviewStore } from "@/stores/review-store"
import type { WikiState } from "@/stores/wiki-store"
const navItems: { view: WikiState["activeView"]; icon: typeof FileText; label: string }[] = [
@@ -11,6 +12,7 @@ const navItems: { view: WikiState["activeView"]; icon: typeof FileText; label: s
{ view: "search", icon: Search, label: "Search" },
{ view: "graph", icon: Network, label: "Graph" },
{ view: "lint", icon: ClipboardCheck, label: "Lint" },
+ { view: "review", icon: ClipboardList, label: "Review" },
{ view: "settings", icon: Settings, label: "Settings" },
]
@@ -21,6 +23,7 @@ interface IconSidebarProps {
export function IconSidebar({ onSwitchProject }: IconSidebarProps) {
const activeView = useWikiStore((s) => s.activeView)
const setActiveView = useWikiStore((s) => s.setActiveView)
+ const pendingCount = useReviewStore((s) => s.items.filter((i) => !i.resolved).length)
return (
<TooltipProvider delayDuration={300}>
@@ -30,15 +33,23 @@ export function IconSidebar({ onSwitchProject }: IconSidebarProps) {
<Tooltip key={view}>
<TooltipTrigger
onClick={() => setActiveView(view)}
- className={`flex h-10 w-10 items-center justify-center rounded-md transition-colors ${
+ className={`relative flex h-10 w-10 items-center justify-center rounded-md transition-colors ${
activeView === view
? "bg-accent text-accent-foreground"
: "text-muted-foreground hover:bg-accent/50 hover:text-accent-foreground"
}`}
>
<Icon className="h-5 w-5" />
+ {view === "review" && pendingCount > 0 && (
+ <span className="absolute -right-0.5 -top-0.5 flex h-4 min-w-4 items-center justify-center rounded-full bg-primary px-1 text-[10px] font-bold text-primary-foreground">
+ {pendingCount > 99 ? "99+" : pendingCount}
+ </span>
+ )}
</TooltipTrigger>
- <TooltipContent side="right">{label}</TooltipContent>
+ <TooltipContent side="right">
+ {label}
+ {view === "review" && pendingCount > 0 && ` (${pendingCount})`}
+ </TooltipContent>
</Tooltip>
))}
</div>
diff --git a/src/components/review/review-view.tsx b/src/components/review/review-view.tsx
new file mode 100644
index 00000000..347f12d0
--- /dev/null
+++ b/src/components/review/review-view.tsx
@@ -0,0 +1,149 @@
+import {
+ AlertTriangle,
+ Copy,
+ FileQuestion,
+ CheckCircle2,
+ Lightbulb,
+ MessageSquare,
+ X,
+ Check,
+ Trash2,
+} from "lucide-react"
+import { Button } from "@/components/ui/button"
+import { ScrollArea } from "@/components/ui/scroll-area"
+import { useReviewStore, type ReviewItem } from "@/stores/review-store"
+
+const typeConfig: Record<ReviewItem["type"], { icon: typeof AlertTriangle; label: string; color: string }> = {
+ contradiction: { icon: AlertTriangle, label: "Contradiction", color: "text-amber-500" },
+ duplicate: { icon: Copy, label: "Possible Duplicate", color: "text-blue-500" },
+ "missing-page": { icon: FileQuestion, label: "Missing Page", color: "text-purple-500" },
+ confirm: { icon: MessageSquare, label: "Needs Confirmation", color: "text-foreground" },
+ suggestion: { icon: Lightbulb, label: "Suggestion", color: "text-emerald-500" },
+}
+
+export function ReviewView() {
+ const items = useReviewStore((s) => s.items)
+ const resolveItem = useReviewStore((s) => s.resolveItem)
+ const dismissItem = useReviewStore((s) => s.dismissItem)
+ const clearResolved = useReviewStore((s) => s.clearResolved)
+
+ const pending = items.filter((i) => !i.resolved)
+ const resolved = items.filter((i) => i.resolved)
+
+ return (
+ <div className="flex h-full flex-col">
+ <div className="flex items-center justify-between border-b px-4 py-3">
+ <h2 className="text-sm font-semibold">
+ Review
+ {pending.length > 0 && (
+ <span className="ml-2 rounded-full bg-primary px-2 py-0.5 text-xs text-primary-foreground">
+ {pending.length}
+ </span>
+ )}
+ </h2>
+ {resolved.length > 0 && (
+ <Button variant="ghost" size="sm" onClick={clearResolved} className="text-xs">
+ <Trash2 className="mr-1 h-3 w-3" />
+ Clear resolved
+ </Button>
+ )}
+ </div>
+
+ <ScrollArea className="flex-1">
+ {items.length === 0 ? (
+ <div className="flex flex-col items-center justify-center gap-2 p-8 text-center text-sm text-muted-foreground">
+ <CheckCircle2 className="h-8 w-8 text-muted-foreground/30" />
+ <p>All clear — nothing to review</p>
+ </div>
+ ) : (
+ <div className="flex flex-col gap-2 p-3">
+ {pending.map((item) => (
+ <ReviewCard
+ key={item.id}
+ item={item}
+ onResolve={resolveItem}
+ onDismiss={dismissItem}
+ />
+ ))}
+ {resolved.length > 0 && pending.length > 0 && (
+ <div className="my-2 text-center text-xs text-muted-foreground">
+ — Resolved —
+ </div>
+ )}
+ {resolved.map((item) => (
+ <ReviewCard
+ key={item.id}
+ item={item}
+ onResolve={resolveItem}
+ onDismiss={dismissItem}
+ />
+ ))}
+ </div>
+ )}
+ </ScrollArea>
+ </div>
+ )
+}
+
+function ReviewCard({
+ item,
+ onResolve,
+ onDismiss,
+}: {
+ item: ReviewItem
+ onResolve: (id: string, action: string) => void
+ onDismiss: (id: string) => void
+}) {
+ const config = typeConfig[item.type]
+ const Icon = config.icon
+
+ return (
+ <div
+ className={`rounded-lg border p-3 text-sm transition-opacity ${
+ item.resolved ? "opacity-50" : ""
+ }`}
+ >
+ <div className="mb-2 flex items-start justify-between gap-2">
+ <div className="flex items-center gap-2">
+ <Icon className={`h-4 w-4 shrink-0 ${config.color}`} />
+ <span className="font-medium">{item.title}</span>
+ </div>
+ <button
+ onClick={() => onDismiss(item.id)}
+ className="shrink-0 rounded p-0.5 text-muted-foreground hover:bg-muted"
+ >
+ <X className="h-3.5 w-3.5" />
+ </button>
+ </div>
+
+ <p className="mb-3 text-xs text-muted-foreground">{item.description}</p>
+
+ {item.affectedPages && item.affectedPages.length > 0 && (
+ <div className="mb-3 text-xs text-muted-foreground">
+ Pages: {item.affectedPages.join(", ")}
+ </div>
+ )}
+
+ {!item.resolved ? (
+ <div className="flex flex-wrap gap-1.5">
+ {item.options.map((opt) => (
+ <Button
+ key={opt.action}
+ variant="outline"
+ size="sm"
+ className="h-7 text-xs"
+ onClick={() => onResolve(item.id, opt.action)}
+ >
+ {opt.label}
+ </Button>
+ ))}
+ </div>
+ ) : (
+ <div className="flex items-center gap-1 text-xs text-emerald-600">
+ <Check className="h-3 w-3" />
+ {item.resolvedAction}
+ </div>
+ )}
+ </div>
+ )
+}
diff --git a/src/lib/ingest.ts b/src/lib/ingest.ts
index d4661bb3..75c0f70d 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 { useReviewStore, type ReviewItem } from "@/stores/review-store"
const FILE_BLOCK_REGEX = /---FILE:\s*([^\n-]+?)\s*---\n([\s\S]*?)---END FILE---/g
@@ -33,7 +34,10 @@ export async function autoIngest(
const systemPrompt = [
"You are a wiki maintainer. You will read a source document and directly produce wiki files.",
- "Output ONLY wiki files in this exact format:",
+ "",
+ "## Output Format",
+ "",
+ "Output wiki files in this format:",
"",
"---FILE: wiki/sources/filename.md---",
"(complete file content with YAML frontmatter)",
@@ -49,6 +53,23 @@ export async function autoIngest(
"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}` : "",
@@ -101,6 +122,13 @@ export async function autoIngest(
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.`)
+ }
+
return writtenPaths
}
@@ -131,6 +159,63 @@ async function writeFileBlocks(projectPath: string, text: string): Promise<strin
return writtenPaths
}
+const REVIEW_BLOCK_REGEX = /---REVIEW:\s*(\w[\w-]*)\s*\|\s*(.+?)\s*---\n([\s\S]*?)---END REVIEW---/g
+
+function parseReviewBlocks(
+ text: string,
+ sourcePath: string,
+): Omit<ReviewItem, "id" | "resolved" | "createdAt">[] {
+ const items: Omit<ReviewItem, "id" | "resolved" | "createdAt">[] = []
+ const matches = text.matchAll(REVIEW_BLOCK_REGEX)
+
+ for (const match of matches) {
+ const rawType = match[1].trim().toLowerCase()
+ const title = match[2].trim()
+ const body = match[3].trim()
+
+ const type = (
+ ["contradiction", "duplicate", "missing-page", "suggestion"].includes(rawType)
+ ? rawType
+ : "confirm"
+ ) as ReviewItem["type"]
+
+ // Parse OPTIONS line
+ const optionsMatch = body.match(/^OPTIONS:\s*(.+)$/m)
+ const options = optionsMatch
+ ? optionsMatch[1].split("|").map((o) => {
+ const label = o.trim()
+ return { label, action: label }
+ })
+ : [
+ { label: "Approve", action: "Approve" },
+ { label: "Skip", action: "Skip" },
+ ]
+
+ // Parse PAGES line
+ const pagesMatch = body.match(/^PAGES:\s*(.+)$/m)
+ const affectedPages = pagesMatch
+ ? pagesMatch[1].split(",").map((p) => p.trim())
+ : undefined
+
+ // Description is the body minus OPTIONS and PAGES lines
+ const description = body
+ .replace(/^OPTIONS:.*$/m, "")
+ .replace(/^PAGES:.*$/m, "")
+ .trim()
+
+ items.push({
+ type,
+ title,
+ description,
+ sourcePath,
+ affectedPages,
+ options,
+ })
+ }
+
+ return items
+}
+
function getStore() {
return useChatStore.getState()
}
diff --git a/src/stores/review-store.ts b/src/stores/review-store.ts
new file mode 100644
index 00000000..a563e4bd
--- /dev/null
+++ b/src/stores/review-store.ts
@@ -0,0 +1,77 @@
+import { create } from "zustand"
+
+export interface ReviewOption {
+ label: string
+ action: string // identifier for the action
+}
+
+export interface ReviewItem {
+ id: string
+ type: "contradiction" | "duplicate" | "missing-page" | "confirm" | "suggestion"
+ title: string
+ description: string
+ sourcePath?: string
+ affectedPages?: string[]
+ options: ReviewOption[]
+ resolved: boolean
+ resolvedAction?: string
+ createdAt: number
+}
+
+interface ReviewState {
+ items: ReviewItem[]
+ addItem: (item: Omit<ReviewItem, "id" | "resolved" | "createdAt">) => void
+ addItems: (items: Omit<ReviewItem, "id" | "resolved" | "createdAt">[]) => void
+ resolveItem: (id: string, action: string) => void
+ dismissItem: (id: string) => void
+ clearResolved: () => void
+}
+
+let counter = 0
+
+export const useReviewStore = create<ReviewState>((set) => ({
+ items: [],
+
+ addItem: (item) =>
+ set((state) => ({
+ items: [
+ ...state.items,
+ {
+ ...item,
+ id: `review-${++counter}`,
+ resolved: false,
+ createdAt: Date.now(),
+ },
+ ],
+ })),
+
+ addItems: (items) =>
+ set((state) => ({
+ items: [
+ ...state.items,
+ ...items.map((item) => ({
+ ...item,
+ id: `review-${++counter}`,
+ resolved: false,
+ createdAt: Date.now(),
+ })),
+ ],
+ })),
+
+ resolveItem: (id, action) =>
+ set((state) => ({
+ items: state.items.map((item) =>
+ item.id === id ? { ...item, resolved: true, resolvedAction: action } : item
+ ),
+ })),
+
+ dismissItem: (id) =>
+ set((state) => ({
+ items: state.items.filter((item) => item.id !== id),
+ })),
+
+ clearResolved: () =>
+ set((state) => ({
+ items: state.items.filter((item) => !item.resolved),
+ })),
+}))
diff --git a/src/stores/wiki-store.ts b/src/stores/wiki-store.ts
index 0453c129..73f319fe 100644
--- a/src/stores/wiki-store.ts
+++ b/src/stores/wiki-store.ts
@@ -15,7 +15,7 @@ interface WikiState {
selectedFile: string | null
fileContent: string
chatExpanded: boolean
- activeView: "wiki" | "sources" | "search" | "graph" | "lint" | "settings"
+ activeView: "wiki" | "sources" | "search" | "graph" | "lint" | "review" | "settings"
llmConfig: LlmConfig
setProject: (project: WikiProject | null) => void