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: Windows path handling — normalize at FFI boundary and fix abs-path check

nash_subcd4d2c0aa3b
diff --git a/src-tauri/src/commands/fs.rs b/src-tauri/src/commands/fs.rs
index 33fe13c2..e8dccdcf 100644
--- a/src-tauri/src/commands/fs.rs
+++ b/src-tauri/src/commands/fs.rs
@@ -703,7 +703,12 @@ fn build_tree(dir: &Path, depth: usize, max_depth: usize) -> Result<Vec<FileNode
.to_str()
.unwrap_or("")
.to_string();
- let path_str = entry_path.to_string_lossy().to_string();
+ // Always return forward-slash paths so the TS layer can compare
+ // and compose paths consistently across Windows and Unix. Windows
+ // APIs accept forward slashes, so normalizing here is safe and
+ // prevents a whole class of bugs where TS-constructed `/` paths
+ // fail to match Rust-returned `\` paths.
+ let path_str = entry_path.to_string_lossy().replace('\\', "/");
let is_dir = entry_path.is_dir();
let children = if is_dir {
@@ -784,7 +789,9 @@ pub fn copy_directory(source: String, destination: String) -> Result<Vec<String>
fs::copy(&path, &dest_path).map_err(|e| {
format!("Failed to copy '{}': {}", path.display(), e)
})?;
- files.push(dest_path.to_string_lossy().to_string());
+ // Normalize to forward slashes for consistent cross-
+ // platform handling in the TS layer (see fs.rs build_tree).
+ files.push(dest_path.to_string_lossy().replace('\\', "/"));
}
}
Ok(())
@@ -888,7 +895,9 @@ fn collect_related_pages(dir: &Path, source_name: &str, results: &mut Vec<String
};
if sources_match || is_source_summary || frontmatter_match {
- results.push(path.to_string_lossy().to_string());
+ // Normalize to forward slashes — matches build_tree /
+ // copy_directory so TS-side comparisons work on Windows.
+ results.push(path.to_string_lossy().replace('\\', "/"));
}
}
}
diff --git a/src-tauri/src/commands/project.rs b/src-tauri/src/commands/project.rs
index 270c00ec..2f138359 100644
--- a/src-tauri/src/commands/project.rs
+++ b/src-tauri/src/commands/project.rs
@@ -231,7 +231,8 @@ related: []
Ok(WikiProject {
name,
- path: root.to_string_lossy().to_string(),
+ // Forward slashes for cross-platform consistency in the TS layer.
+ path: root.to_string_lossy().replace('\\', "/"),
})
}
@@ -268,7 +269,11 @@ pub fn open_project(path: String) -> Result<WikiProject, String> {
.unwrap_or("Unknown")
.to_string();
- Ok(WikiProject { name, path })
+ Ok(WikiProject {
+ name,
+ // Forward slashes for cross-platform consistency in the TS layer.
+ path: path.replace('\\', "/"),
+ })
})
}
diff --git a/src/components/layout/activity-panel.tsx b/src/components/layout/activity-panel.tsx
index 94bf908a..3aa17bc9 100644
--- a/src/components/layout/activity-panel.tsx
+++ b/src/components/layout/activity-panel.tsx
@@ -6,7 +6,7 @@ import {
} from "lucide-react"
import { useActivityStore, type ActivityItem } from "@/stores/activity-store"
import { useWikiStore } from "@/stores/wiki-store"
-import { normalizePath, getFileName } from "@/lib/path-utils"
+import { normalizePath, getFileName, isAbsolutePath } from "@/lib/path-utils"
import { getQueue, getQueueSummary, retryTask, cancelTask, type IngestTask } from "@/lib/ingest-queue"
const FILE_TYPE_ICONS: Record<string, typeof FileText> = {
@@ -223,7 +223,9 @@ function ActivityRow({ item, onCancel }: { item: ActivityItem; onCancel?: () =>
function handleFileClick(filePath: string) {
if (!project) return
const pp = normalizePath(project.path)
- const fullPath = filePath.startsWith("/") ? normalizePath(filePath) : `${pp}/${filePath}`
+ const fullPath = isAbsolutePath(filePath)
+ ? normalizePath(filePath)
+ : `${pp}/${filePath}`
setSelectedFile(fullPath)
}
diff --git a/src/components/sources/sources-view.tsx b/src/components/sources/sources-view.tsx
index 515c6ca5..1087ebc8 100644
--- a/src/components/sources/sources-view.tsx
+++ b/src/components/sources/sources-view.tsx
@@ -157,8 +157,13 @@ export function SourcesView() {
"csv", "json", "html", "htm", "rtf", "xml", "yaml", "yml"].includes(ext)
})
.map((filePath) => {
- // Build folder context from relative path
- const relPath = filePath.replace(destDir + "/", "")
+ // Build folder context from relative path. On Windows the
+ // Rust-returned filePath uses backslashes while destDir was
+ // composed with forward slashes — normalize both sides before
+ // the replace so this works on every platform.
+ const normFilePath = normalizePath(filePath)
+ const normDestDir = normalizePath(destDir)
+ const relPath = normFilePath.replace(normDestDir + "/", "")
const parts = relPath.split("/")
parts.pop() // remove filename
const context = parts.length > 0
diff --git a/src/lib/ingest-queue.ts b/src/lib/ingest-queue.ts
index 1a4e41af..9e1ec861 100644
--- a/src/lib/ingest-queue.ts
+++ b/src/lib/ingest-queue.ts
@@ -1,7 +1,7 @@
import { readFile, writeFile } from "@/commands/fs"
import { autoIngest } from "./ingest"
import { useWikiStore } from "@/stores/wiki-store"
-import { normalizePath } from "@/lib/path-utils"
+import { normalizePath, isAbsolutePath } from "@/lib/path-utils"
// ── Types ─────────────────────────────────────────────────────────────────
@@ -155,7 +155,9 @@ export async function cancelTask(projectPath: string, taskId: string): Promise<v
const { deleteFile } = await import("@/commands/fs")
for (const filePath of lastWrittenFiles) {
try {
- const fullPath = filePath.startsWith("/") ? filePath : `${normalizePath(projectPath)}/${filePath}`
+ const fullPath = isAbsolutePath(filePath)
+ ? normalizePath(filePath)
+ : `${normalizePath(projectPath)}/${filePath}`
await deleteFile(fullPath)
} catch {
// file may not exist
@@ -317,8 +319,8 @@ async function processNext(projectPath: string): Promise<void> {
return
}
- const fullSourcePath = next.sourcePath.startsWith("/")
- ? next.sourcePath
+ const fullSourcePath = isAbsolutePath(next.sourcePath)
+ ? normalizePath(next.sourcePath)
: `${pp}/${next.sourcePath}`
console.log(`[Ingest Queue] Processing: ${next.sourcePath} (${queue.filter((t) => t.status === "pending").length} remaining)`)
diff --git a/src/lib/path-utils.test.ts b/src/lib/path-utils.test.ts
index d22661f9..c447fa0c 100644
--- a/src/lib/path-utils.test.ts
+++ b/src/lib/path-utils.test.ts
@@ -1,5 +1,12 @@
import { describe, it, expect } from "vitest"
-import { normalizePath, joinPath, getFileName, getFileStem, getRelativePath } from "./path-utils"
+import {
+ normalizePath,
+ joinPath,
+ getFileName,
+ getFileStem,
+ getRelativePath,
+ isAbsolutePath,
+} from "./path-utils"
describe("normalizePath", () => {
it("converts backslashes to forward slashes", () => {
@@ -110,3 +117,37 @@ describe("getRelativePath", () => {
expect(getRelativePath("/projector/a", "/project")).toBe("/projector/a")
})
})
+
+describe("isAbsolutePath", () => {
+ it("recognizes Unix absolute paths", () => {
+ expect(isAbsolutePath("/")).toBe(true)
+ expect(isAbsolutePath("/home/user")).toBe(true)
+ expect(isAbsolutePath("/a/b/c.md")).toBe(true)
+ })
+
+ it("recognizes Windows drive-letter paths with both separators", () => {
+ expect(isAbsolutePath("C:\\Users\\nash")).toBe(true)
+ expect(isAbsolutePath("C:/Users/nash")).toBe(true)
+ expect(isAbsolutePath("D:\\")).toBe(true)
+ expect(isAbsolutePath("z:/project/file.pdf")).toBe(true)
+ })
+
+ it("recognizes Windows UNC paths", () => {
+ expect(isAbsolutePath("\\\\server\\share")).toBe(true)
+ expect(isAbsolutePath("//server/share")).toBe(true)
+ })
+
+ it("rejects relative paths", () => {
+ expect(isAbsolutePath("")).toBe(false)
+ expect(isAbsolutePath("foo")).toBe(false)
+ expect(isAbsolutePath("foo/bar.md")).toBe(false)
+ expect(isAbsolutePath("./foo")).toBe(false)
+ expect(isAbsolutePath("../foo")).toBe(false)
+ expect(isAbsolutePath("wiki/concepts/attention.md")).toBe(false)
+ })
+
+ it("rejects drive-letter WITHOUT a separator (ambiguous)", () => {
+ // "C:foo" is a Windows drive-relative path, not absolute.
+ expect(isAbsolutePath("C:foo")).toBe(false)
+ })
+})
diff --git a/src/lib/path-utils.ts b/src/lib/path-utils.ts
index e468d87e..758e940d 100644
--- a/src/lib/path-utils.ts
+++ b/src/lib/path-utils.ts
@@ -44,3 +44,21 @@ export function getRelativePath(fullPath: string, basePath: string): string {
}
return normalFull
}
+
+/**
+ * Cross-platform absolute-path detection.
+ *
+ * Unix: "/foo/bar"
+ * Windows: "C:\foo", "C:/foo", "\\server\share", "//server/share"
+ *
+ * A bare `.startsWith("/")` check wrongly treats Windows paths like
+ * "C:/project/file.pdf" as relative, which produced double-joined
+ * garbage like "C:/project/C:/project/file.pdf" in the ingest queue.
+ */
+export function isAbsolutePath(p: string): boolean {
+ if (!p) return false
+ if (p.startsWith("/")) return true
+ if (/^[A-Za-z]:[\\/]/.test(p)) return true
+ if (p.startsWith("\\\\") || p.startsWith("//")) return true
+ return false
+}
diff --git a/src/lib/search.ts b/src/lib/search.ts
index 8a4ff7cc..64d7414b 100644
--- a/src/lib/search.ts
+++ b/src/lib/search.ts
@@ -1,6 +1,6 @@
import { readFile, listDirectory } from "@/commands/fs"
import type { FileNode } from "@/types/wiki"
-import { normalizePath } from "@/lib/path-utils"
+import { normalizePath, getFileStem } from "@/lib/path-utils"
export interface SearchResult {
path: string
@@ -196,14 +196,15 @@ export async function searchWiki(
let boosted = 0
let added = 0
- const existingPaths = new Set(results.map((r) => r.path))
+ // Normalize existing paths to forward slashes so Windows backslash
+ // paths from the filesystem match the forward-slash paths we
+ // construct for tryPath below.
+ const existingPaths = new Set(results.map((r) => normalizePath(r.path)))
for (const vr of vectorResults) {
- // Check if already in results
- const existing = results.find((r) => {
- const fileName = r.path.split("/").pop()?.replace(/\.md$/, "") ?? ""
- return fileName === vr.id
- })
+ // Check if already in results. getFileStem handles both / and \
+ // separators so this works on Windows.
+ const existing = results.find((r) => getFileStem(r.path) === vr.id)
if (existing) {
// Boost score of existing result