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

fix: Graph auto-updates after new file ingest

nash_su253f61701010
diff --git a/src/components/graph/graph-view.tsx b/src/components/graph/graph-view.tsx
index b3508b7a..733b3a66 100644
--- a/src/components/graph/graph-view.tsx
+++ b/src/components/graph/graph-view.tsx
@@ -1,4 +1,4 @@
-import { useEffect, useCallback, useState } from "react"
+import { useEffect, useCallback, useState, useRef } from "react"
import Graph from "graphology"
import { SigmaContainer, useLoadGraph, useRegisterEvents, useSigma } from "@react-sigma/core"
import "@react-sigma/core/lib/style.css"
@@ -126,6 +126,7 @@ function EventHandler({ onNodeClick }: EventHandlerProps) {
export function GraphView() {
const project = useWikiStore((s) => s.project)
+ const dataVersion = useWikiStore((s) => s.dataVersion)
const setSelectedFile = useWikiStore((s) => s.setSelectedFile)
const setFileContent = useWikiStore((s) => s.setFileContent)
const setActiveView = useWikiStore((s) => s.setActiveView)
@@ -134,6 +135,7 @@ export function GraphView() {
const [edges, setEdges] = useState<GraphEdge[]>([])
const [loading, setLoading] = useState(false)
const [error, setError] = useState<string | null>(null)
+ const lastLoadedVersion = useRef(-1)
const loadGraph = useCallback(async () => {
if (!project) return
@@ -143,6 +145,7 @@ export function GraphView() {
const result = await buildWikiGraph(project.path)
setNodes(result.nodes)
setEdges(result.edges)
+ lastLoadedVersion.current = useWikiStore.getState().dataVersion
} catch (err) {
const message = err instanceof Error ? err.message : "Failed to build graph"
setError(message)
@@ -151,10 +154,12 @@ export function GraphView() {
}
}, [project])
- // Always load fresh data when component mounts (user switches to Graph view)
+ // Load on mount; reload if data changed since last load
useEffect(() => {
- loadGraph()
- }, [loadGraph])
+ if (dataVersion !== lastLoadedVersion.current) {
+ loadGraph()
+ }
+ }, [loadGraph, dataVersion])
const handleNodeClick = useCallback(
async (nodeId: string) => {
diff --git a/src/lib/ingest.ts b/src/lib/ingest.ts
index 4aa02479..bed31681 100644
--- a/src/lib/ingest.ts
+++ b/src/lib/ingest.ts
@@ -113,6 +113,7 @@ export async function autoIngest(
try {
const tree = await listDirectory(projectPath)
useWikiStore.getState().setFileTree(tree)
+ useWikiStore.getState().bumpDataVersion()
} catch {
// ignore
}
diff --git a/src/stores/wiki-store.ts b/src/stores/wiki-store.ts
index 73f319fe..8c1d06fc 100644
--- a/src/stores/wiki-store.ts
+++ b/src/stores/wiki-store.ts
@@ -17,6 +17,7 @@ interface WikiState {
chatExpanded: boolean
activeView: "wiki" | "sources" | "search" | "graph" | "lint" | "review" | "settings"
llmConfig: LlmConfig
+ dataVersion: number
setProject: (project: WikiProject | null) => void
setFileTree: (tree: FileNode[]) => void
@@ -25,6 +26,7 @@ interface WikiState {
setChatExpanded: (expanded: boolean) => void
setActiveView: (view: WikiState["activeView"]) => void
setLlmConfig: (config: LlmConfig) => void
+ bumpDataVersion: () => void
}
export const useWikiStore = create<WikiState>((set) => ({
@@ -42,6 +44,8 @@ export const useWikiStore = create<WikiState>((set) => ({
customEndpoint: "",
},
+ dataVersion: 0,
+
setProject: (project) => set({ project }),
setFileTree: (fileTree) => set({ fileTree }),
setSelectedFile: (selectedFile) => set({ selectedFile }),
@@ -49,6 +53,7 @@ export const useWikiStore = create<WikiState>((set) => ({
setChatExpanded: (chatExpanded) => set({ chatExpanded }),
setActiveView: (activeView) => set({ activeView }),
setLlmConfig: (llmConfig) => set({ llmConfig }),
+ bumpDataVersion: () => set((state) => ({ dataVersion: state.dataVersion + 1 })),
}))
export type { WikiState, LlmConfig }