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: prevent cross-project data contamination on project switch

nash_su5386ee167c9c
diff --git a/src/App.tsx b/src/App.tsx
index 8ef93edb..1e095e40 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -72,9 +72,16 @@ function App() {
}, [])
async function handleProjectOpened(proj: WikiProject) {
+ // Clear all per-project state BEFORE loading new project data
+ // to prevent cross-project contamination
+ const { resetProjectState } = await import("@/lib/reset-project-state")
+ resetProjectState()
+
setProject(proj)
setSelectedFile(null)
setActiveView("wiki")
+ // Bump data version so any cached graphs/views invalidate
+ useWikiStore.getState().bumpDataVersion()
await saveLastProject(proj)
// Restore ingest queue (resume interrupted tasks)
@@ -156,6 +163,10 @@ function App() {
}
function handleSwitchProject() {
+ // Clear all per-project state so the welcome screen doesn't leak old data
+ import("@/lib/reset-project-state").then(({ resetProjectState }) => {
+ resetProjectState()
+ })
setProject(null)
setFileTree([])
setSelectedFile(null)
diff --git a/src/lib/ingest-queue.ts b/src/lib/ingest-queue.ts
index b7ccdbd6..412a35aa 100644
--- a/src/lib/ingest-queue.ts
+++ b/src/lib/ingest-queue.ts
@@ -197,6 +197,22 @@ export function getQueueSummary(): { pending: number; processing: number; failed
}
}
+/**
+ * Clear all in-memory queue state without touching disk.
+ * Called when switching projects to prevent cross-project contamination.
+ */
+export function clearQueueState(): void {
+ // Abort any in-progress ingest
+ if (currentAbortController) {
+ currentAbortController.abort()
+ }
+ queue = []
+ processing = false
+ currentProjectPath = ""
+ currentAbortController = null
+ lastWrittenFiles = []
+}
+
// ── Restore on startup ───────────────────────────────────────────────────
/**
@@ -205,7 +221,13 @@ export function getQueueSummary(): { pending: number; processing: number; failed
*/
export async function restoreQueue(projectPath: string): Promise<void> {
const pp = normalizePath(projectPath)
+ // Always reset in-memory state FIRST to prevent cross-project contamination
+ queue = []
+ processing = false
+ currentAbortController = null
+ lastWrittenFiles = []
currentProjectPath = pp
+
const saved = await loadQueue(pp)
if (saved.length === 0) return
diff --git a/src/lib/reset-project-state.ts b/src/lib/reset-project-state.ts
new file mode 100644
index 00000000..8591cab6
--- /dev/null
+++ b/src/lib/reset-project-state.ts
@@ -0,0 +1,47 @@
+/**
+ * Centralized reset of all per-project state.
+ * MUST be called both when leaving a project and when opening a new one,
+ * to prevent cross-project data contamination.
+ */
+
+import { useChatStore } from "@/stores/chat-store"
+import { useReviewStore } from "@/stores/review-store"
+import { useActivityStore } from "@/stores/activity-store"
+import { useResearchStore } from "@/stores/research-store"
+
+export function resetProjectState() {
+ // Zustand stores — clear all per-project data
+ useChatStore.setState({
+ conversations: [],
+ messages: [],
+ activeConversationId: null,
+ mode: "chat",
+ ingestSource: null,
+ isStreaming: false,
+ streamingContent: "",
+ })
+
+ useReviewStore.setState({
+ items: [],
+ })
+
+ useActivityStore.setState({
+ items: [],
+ })
+
+ useResearchStore.setState({
+ tasks: [],
+ panelOpen: false,
+ })
+
+ // Module-level caches
+ // Ingest queue
+ import("@/lib/ingest-queue").then(({ clearQueueState }) => {
+ clearQueueState()
+ }).catch(() => {})
+
+ // Graph relevance cache
+ import("@/lib/graph-relevance").then(({ clearGraphCache }) => {
+ clearGraphCache()
+ }).catch(() => {})
+}