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: scheduled import scan logic and detection

skfan135394021e0b84f
diff --git a/src/components/settings/sections/scheduled-import-section.tsx b/src/components/settings/sections/scheduled-import-section.tsx
index d663fb44..5faf1f9f 100644
--- a/src/components/settings/sections/scheduled-import-section.tsx
+++ b/src/components/settings/sections/scheduled-import-section.tsx
@@ -7,7 +7,7 @@ import { Button } from "@/components/ui/button"
import { Folder, Play, RefreshCw } from "lucide-react"
import type { SettingsDraft, DraftSetter } from "../settings-types"
import { useWikiStore } from "@/stores/wiki-store"
-import { startScheduledImport, stopScheduledImport, scanAndImport, resolveImportPath } from "@/lib/scheduled-import"
+import { startScheduledImport, stopScheduledImport, scanAndImport } from "@/lib/scheduled-import"
interface Props {
draft: SettingsDraft
@@ -36,11 +36,9 @@ export function ScheduledImportSection({ draft, setDraft }: Props) {
const handleManualScan = useCallback(async () => {
if (!project || isScanning) return
- const resolvedPath = resolveImportPath(project.path, draft.scheduledImportPath)
-
setIsScanning(true)
try {
- await scanAndImport(project.path, resolvedPath)
+ await scanAndImport(project.path, draft.scheduledImportPath)
} catch (err) {
console.error("[Scheduled Import] Manual scan failed:", err)
} finally {
diff --git a/src/lib/scheduled-import.ts b/src/lib/scheduled-import.ts
index 7f6b184c..1e5db320 100644
--- a/src/lib/scheduled-import.ts
+++ b/src/lib/scheduled-import.ts
@@ -49,9 +49,8 @@ function isImportableFile(fileName: string): boolean {
}
/**
- * Build a map of existing sources: fileName -> lastModifiedTime.
- * We match by base filename (without directory prefix) since sources
- * are flat in raw/sources/.
+ * Build a map of existing sources: normalizedFilePath -> lastModifiedTime.
+ * Uses full normalized path as key to correctly identify files.
*/
async function buildExistingSourcesMap(projectPath: string): Promise<Map<string, { path: string; modified: number }>> {
const pp = normalizePath(projectPath)
@@ -62,10 +61,10 @@ async function buildExistingSourcesMap(projectPath: string): Promise<Map<string,
const files = collectFiles(tree)
for (const file of files) {
- const baseName = getFileName(file.path) || file.name
try {
const modified = await getFileModifiedTime(file.path)
- map.set(baseName, { path: file.path, modified })
+ const normalizedPath = normalizePath(file.path)
+ map.set(normalizedPath, { path: file.path, modified })
} catch {
// Can't get modified time, skip
}
@@ -79,6 +78,8 @@ async function buildExistingSourcesMap(projectPath: string): Promise<Map<string,
/**
* Detect changes between monitored directory and existing sources.
+ * Compares by normalized file path to avoid false positives when
+ * monitored directory overlaps with raw/sources.
*/
async function detectChanges(
monitoredPath: string,
@@ -93,18 +94,19 @@ async function detectChanges(
for (const file of files) {
if (!isImportableFile(file.name)) continue
+ const normalizedPath = normalizePath(file.path)
const baseName = getFileName(file.path) || file.name
- const existing = existingSources.get(baseName)
+ const existing = existingSources.get(normalizedPath)
if (!existing) {
- // New file
+ // New file - not in sources yet
changes.push({
type: "new",
sourcePath: file.path,
fileName: baseName,
})
- } else {
- // Check if modified
+ } else if (normalizedPath !== normalizePath(existing.path)) {
+ // Different file with same name exists in sources - treat as modified
try {
const sourceModified = await getFileModifiedTime(file.path)
if (sourceModified > existing.modified) {
@@ -118,6 +120,7 @@ async function detectChanges(
// Can't compare, skip
}
}
+ // If normalizedPath === normalizePath(existing.path), it's the same file - skip
}
} catch (err) {
console.error("[Scheduled Import] Failed to scan monitored directory:", err)
@@ -157,9 +160,14 @@ export async function scanAndImport(projectPath: string, importPath: string): Pr
for (const change of changes) {
try {
- // Copy file to sources directory
const destPath = `${pp}/raw/sources/${change.fileName}`
- await copyFile(change.sourcePath, destPath)
+ const normalizedSource = normalizePath(change.sourcePath)
+ const normalizedDest = normalizePath(destPath)
+
+ if (normalizedSource !== normalizedDest) {
+ // Source is outside raw/sources - copy it
+ await copyFile(change.sourcePath, destPath)
+ }
// Preprocess the file
preprocessFile(destPath).catch(() => {})