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: reconcile excluded scheduled sources

nash_su2ceec370a1b2
diff --git a/src/lib/scheduled-import.test.ts b/src/lib/scheduled-import.test.ts
index 76bcdf1c..88ad2fdf 100644
--- a/src/lib/scheduled-import.test.ts
+++ b/src/lib/scheduled-import.test.ts
@@ -17,6 +17,7 @@ const mocks = vi.hoisted(() => ({
loadScheduledImportConfig: vi.fn(),
saveScheduledImportConfig: vi.fn(),
getRecentProjects: vi.fn(),
+ loadSourceWatchConfig: vi.fn(),
enqueueInactiveProjectBatch: vi.fn(),
folderContextForSourcePath: vi.fn(),
}))
@@ -48,6 +49,7 @@ vi.mock("@/lib/project-store", () => ({
loadScheduledImportConfig: mocks.loadScheduledImportConfig,
saveScheduledImportConfig: mocks.saveScheduledImportConfig,
getRecentProjects: mocks.getRecentProjects,
+ loadSourceWatchConfig: mocks.loadSourceWatchConfig,
}))
import {
@@ -229,6 +231,18 @@ describe("scanAndImport failure handling", () => {
vi.clearAllMocks()
useWikiStore.setState({
project,
+ sourceWatchConfig: {
+ enabled: true,
+ autoIngest: true,
+ persistExtractedMarkdown: true,
+ parsingConcurrency: 2,
+ ingestConcurrency: 2,
+ includeExtensions: [],
+ excludeExtensions: [],
+ excludeDirs: [],
+ excludeGlobs: [],
+ maxFileSizeMb: 100,
+ },
llmConfig: {
provider: "openai",
apiKey: "test-key",
@@ -256,6 +270,9 @@ describe("scanAndImport failure handling", () => {
interval: 60,
lastScan: null,
})
+ mocks.loadSourceWatchConfig.mockResolvedValue(
+ useWikiStore.getState().sourceWatchConfig,
+ )
mocks.saveScheduledImportConfig.mockResolvedValue(undefined)
mocks.enqueueInactiveProjectBatch.mockResolvedValue(["background-task-1"])
mocks.folderContextForSourcePath.mockReturnValue("scheduled-import")
@@ -480,4 +497,92 @@ describe("scanAndImport failure handling", () => {
expect.any(Object),
)
})
+
+ it("cleans an imported source after a source-watch directory exclusion is added", async () => {
+ useWikiStore.setState({
+ sourceWatchConfig: {
+ ...useWikiStore.getState().sourceWatchConfig,
+ excludeDirs: ["archive"],
+ },
+ })
+ mocks.fileExists.mockResolvedValue(true)
+ mocks.readFile.mockResolvedValue(JSON.stringify({
+ version: 1,
+ directories: {
+ "/Users/me/inbox": {
+ files: { "/Users/me/inbox/archive/old.pdf": "old-md5" },
+ lastScan: 123,
+ },
+ },
+ }))
+ mocks.listDirectory.mockResolvedValue([
+ {
+ name: "archive",
+ path: "/Users/me/inbox/archive",
+ is_dir: true,
+ children: [
+ {
+ name: "old.pdf",
+ path: "/Users/me/inbox/archive/old.pdf",
+ is_dir: false,
+ },
+ ],
+ },
+ ])
+
+ await scanAndImport(project, "/Users/me/inbox")
+
+ const mirror = "/Users/me/wiki-project/raw/sources/scheduled-import/archive/old.pdf"
+ expect(mocks.discardTasksForSources).toHaveBeenCalledWith([mirror])
+ expect(mocks.deleteSourceFile).toHaveBeenCalledWith(
+ project.path,
+ mirror,
+ expect.objectContaining({
+ logReason: "scheduled import source removed or excluded",
+ }),
+ )
+ })
+
+ it("applies an inactive project's persisted source-watch exclusions", async () => {
+ useWikiStore.setState({
+ project: {
+ id: "active-project",
+ name: "Active",
+ path: "/Users/me/active-project",
+ },
+ })
+ mocks.loadSourceWatchConfig.mockResolvedValue({
+ ...useWikiStore.getState().sourceWatchConfig,
+ excludeGlobs: ["*.draft.pdf"],
+ })
+ mocks.listDirectory.mockResolvedValue([
+ {
+ name: "paper.draft.pdf",
+ path: "/Users/me/inbox/paper.draft.pdf",
+ is_dir: false,
+ },
+ ])
+
+ await scanAndImport(project, "/Users/me/inbox", { allowInactive: true })
+
+ expect(mocks.loadSourceWatchConfig).toHaveBeenCalledWith(project.id)
+ expect(mocks.getFileSize).not.toHaveBeenCalled()
+ expect(mocks.copyFile).not.toHaveBeenCalled()
+ expect(mocks.enqueueInactiveProjectBatch).not.toHaveBeenCalled()
+ })
+
+ it("uses the lower scheduled-import and source-watch file size limit", async () => {
+ useWikiStore.setState({
+ sourceWatchConfig: {
+ ...useWikiStore.getState().sourceWatchConfig,
+ maxFileSizeMb: 5,
+ },
+ })
+ mocks.getFileSize.mockResolvedValue(6 * 1024 * 1024)
+
+ await scanAndImport(project, "/Users/me/inbox")
+
+ expect(mocks.getFileMd5).not.toHaveBeenCalled()
+ expect(mocks.copyFile).not.toHaveBeenCalled()
+ })
})
diff --git a/src/lib/scheduled-import.ts b/src/lib/scheduled-import.ts
index 7cd6f6ec..ca3d766e 100644
--- a/src/lib/scheduled-import.ts
+++ b/src/lib/scheduled-import.ts
@@ -10,12 +10,17 @@ import {
import type { FileNode, WikiProject } from "@/types/wiki"
import { isAbsolutePath, normalizePath } from "@/lib/path-utils"
import { useWikiStore } from "@/stores/wiki-store"
-import type { ScheduledImportConfig } from "@/stores/wiki-store"
+import type { ScheduledImportConfig, SourceWatchConfig } from "@/stores/wiki-store"
import {
loadScheduledImportConfig,
+ loadSourceWatchConfig,
saveScheduledImportConfig,
getRecentProjects,
} from "@/lib/project-store"
+import {
+ isPathAllowedBySourceWatch,
+ normalizeSourceWatchConfig,
+} from "@/lib/source-watch-config"
import {
deleteSourceFile,
enqueueSourceIngest,
@@ -44,6 +49,7 @@ interface ImportDbStore {
type ScanOptions = {
runId?: number
allowInactive?: boolean
+ sourceWatchConfig?: SourceWatchConfig
}
const EMPTY_DB: ImportDb = {
@@ -449,6 +455,13 @@ export async function scanAndImport(
}
const tree = await listDirectory(importRoot)
+ const sourceWatchConfig = normalizeSourceWatchConfig(
+ options.sourceWatchConfig ??
+ (isCurrentProject(project.id)
+ ? useWikiStore.getState().sourceWatchConfig
+ : await loadSourceWatchConfig(project.id)),
+ )
+ const maxFileSizeBytes = sourceWatchConfig.maxFileSizeMb * 1024 * 1024
const db = await loadImportDb(projectPath, importRoot)
const nextDb: ImportDb = { files: {}, lastScan: Date.now() }
const changedFiles: Array<{ key: string; md5: string; destPath: string }> = []
@@ -460,6 +473,7 @@ export async function scanAndImport(
if (
shouldSkipScheduledImportFile(projectPath, sourcePath) ||
shouldSkipScheduledImportConfigFile(sourcePath) ||
+ !isPathAllowedBySourceWatch(sourcePath, sourceWatchConfig) ||
!isIngestableSourcePath(sourcePath)
) {
continue
@@ -472,9 +486,10 @@ export async function scanAndImport(
}
const size = await getFileSize(sourcePath)
- if (size > MAX_SCHEDULED_IMPORT_BYTES) {
+ if (size > Math.min(MAX_SCHEDULED_IMPORT_BYTES, maxFileSizeBytes)) {
+ const limitMb = Math.min(100, sourceWatchConfig.maxFileSizeMb)
console.warn(
- `[scheduled-import] skipping ${sourcePath}: ${(size / 1024 / 1024).toFixed(1)} MB exceeds 100 MB limit`,
+ `[scheduled-import] skipping ${sourcePath}: ${(size / 1024 / 1024).toFixed(1)} MB exceeds ${limitMb} MB limit`,
)
continue
}