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: keep CJK ingest filenames in target language

nash_su50ec6a396e54
diff --git a/src/lib/ingest-parse.test.ts b/src/lib/ingest-parse.test.ts
index d59eb006..501f59aa 100644
--- a/src/lib/ingest-parse.test.ts
+++ b/src/lib/ingest-parse.test.ts
@@ -27,6 +27,7 @@ import {
sourceSummaryMediaRefsForExternalMarkdown,
aggregatePathsNeedingRepair,
filterAggregateRepairOutput,
+ rewriteIngestPathFromTitleForTargetLanguage,
} from "./ingest"
// ── Happy paths ─────────────────────────────────────────────────────
@@ -589,3 +590,38 @@ describe("generated ingest dates", () => {
expect(prompt).not.toContain("created: 2026-04-29")
})
})
+
+describe("rewriteIngestPathFromTitleForTargetLanguage", () => {
+ it("uses the CJK page title for generated page filenames when the target language is CJK", () => {
+ const content = [
+ "---",
+ "type: concept",
+ "title: 反硝化除磷技术",
+ "created: 2026-06-18",
+ "---",
+ "",
+ "# 反硝化除磷技术",
+ "",
+ "正文。",
+ ].join("\n")
+
+ expect(
+ rewriteIngestPathFromTitleForTargetLanguage(
+ "wiki/concepts/denitrifying-phosphorus-removal.md",
+ content,
+ "Chinese",
+ ),
+ ).toBe("wiki/concepts/反硝化除磷技术.md")
+ })
+
+ it("does not rewrite source summaries or aggregate pages", () => {
+ const content = "---\ntitle: 反硝化除磷技术\n---\n# 反硝化除磷技术"
+
+ expect(
+ rewriteIngestPathFromTitleForTargetLanguage("wiki/sources/source-slug.md", content, "Chinese"),
+ ).toBe("wiki/sources/source-slug.md")
+ expect(
+ rewriteIngestPathFromTitleForTargetLanguage("wiki/index.md", content, "Chinese"),
+ ).toBe("wiki/index.md")
+ })
+})
diff --git a/src/lib/ingest.ts b/src/lib/ingest.ts
index bb4c84df..69dda850 100644
--- a/src/lib/ingest.ts
+++ b/src/lib/ingest.ts
@@ -26,6 +26,8 @@ import { checkIngestCache, saveIngestCache } from "@/lib/ingest-cache"
import { sanitizeIngestedFileContent } from "@/lib/ingest-sanitize"
import { mergePageContent, type MergeFn } from "@/lib/page-merge"
import { withProjectLock } from "@/lib/project-mutex"
+import { parseFrontmatter } from "@/lib/frontmatter"
+import { makeQuerySlug } from "@/lib/wiki-filename"
import type { FileNode } from "@/types/wiki"
import {
extractAndSaveSourceImages,
@@ -1205,6 +1207,48 @@ function isListingPath(relativePath: string): boolean {
)
}
+const CJK_OUTPUT_LANGUAGES = new Set(["Chinese", "Traditional Chinese", "Japanese", "Korean"])
+
+function containsCjk(text: string): boolean {
+ return /[\u3400-\u9fff\u3040-\u30ff\uac00-\ud7af]/u.test(text)
+}
+
+function extractGeneratedPageTitle(content: string): string | null {
+ const title = parseFrontmatter(content).frontmatter?.title
+ if (typeof title === "string" && title.trim()) return title.trim()
+ const heading = content.match(/^#\s+(.+)$/m)?.[1]?.trim()
+ return heading || null
+}
+
+export function rewriteIngestPathFromTitleForTargetLanguage(
+ relativePath: string,
+ content: string,
+ targetLang: string | undefined,
+): string {
+ if (!targetLang || targetLang === "auto" || !CJK_OUTPUT_LANGUAGES.has(targetLang)) {
+ return relativePath
+ }
+ if (
+ isLogPath(relativePath) ||
+ isListingPath(relativePath) ||
+ relativePath.startsWith("wiki/sources/")
+ ) {
+ return relativePath
+ }
+ const title = extractGeneratedPageTitle(content)
+ if (!title || !containsCjk(title)) return relativePath
+
+ const slash = relativePath.lastIndexOf("/")
+ const dir = slash >= 0 ? relativePath.slice(0, slash + 1) : ""
+ const fileName = slash >= 0 ? relativePath.slice(slash + 1) : relativePath
+ if (containsCjk(fileName)) return relativePath
+
+ const slug = makeQuerySlug(title)
+ if (!containsCjk(slug)) return relativePath
+ const nextPath = `${dir}${slug}.md`
+ return isSafeIngestPath(nextPath) ? nextPath : relativePath
+}
+
export function aggregatePathsNeedingRepair(writtenPaths: string[], warnings: string[]): string[] {
const written = new Set(writtenPaths.map((path) => normalizePath(path)))
const warningText = warnings.join("\n")
@@ -1518,6 +1562,7 @@ async function writeFileBlocks(
if (sourceSummaryPath && relativePath === sourceSummaryPath) {
content = sourceSummaryMediaRefsForExternalMarkdown(content)
}
+ relativePath = rewriteIngestPathFromTitleForTargetLanguage(relativePath, content, targetLang)
if (
projectSchemaRouting &&