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
Merge pull request #826 from ffflw/feat/fix-long-source-paths
nash_su9463c92f1766
diff --cc src/lib/ingest-source-path-collision.test.tsindex 884df571,6b2b9693..78fdbaa9--- a/src/lib/ingest-source-path-collision.test.ts+++ b/src/lib/ingest-source-path-collision.test.ts@@@ -264,108 -261,39 +264,141 @@@ describe("autoIngest source summary patexpect(content).toContain("-end")})+ it.each(["before", "after"])("preserves the exact summary when a cited work appears %s it", async (order) => {+ if (!tmp) throw new Error("missing temp project")+ sourceMarkers = ["correct source summary"]+ const citationPath = "wiki/sources/the-bitter-lesson.md"+ const existingCitation = "# Existing cited work\n\nKeep this page unchanged."+ await writeFileRaw(`${tmp.path}/${citationPath}`, existingCitation)+ const citationBlock = `---FILE: ${citationPath}---\n# Wrong cited-work summary\n---END FILE---`+ if (order === "before") generationPrefix = citationBlock+ else generationSuffix = citationBlock++ const written = await autoIngest(tmp.path, `${tmp.path}/raw/sources/project-a/config.yaml`, useWikiStore.getState().llmConfig)+ const summaryPath = `wiki/sources/${sourceSummarySlugFromIdentity("project-a/config.yaml")}.md`+ const content = await fs.readFile(`${tmp.path}/${summaryPath}`, "utf8")++ expect(content).toContain("correct source summary")+ expect(content).not.toContain("Wrong cited-work summary")+ expect(written.filter((p) => p === summaryPath)).toHaveLength(1)+ expect(await fs.readFile(`${tmp.path}/${citationPath}`, "utf8")).toBe(existingCitation)+ expect(await fs.readFile(`${tmp.path}/.llm-wiki/ingest-warnings.log`, "utf8")).toContain(`Ignored unexpected source summary "${citationPath}"`)+ })++ it("preserves the first successful summary when its exact path is emitted twice", async () => {+ if (!tmp) throw new Error("missing temp project")+ sourceMarkers = ["first correct summary"]+ const summaryPath = `wiki/sources/${sourceSummarySlugFromIdentity("project-a/config.yaml")}.md`+ generationSuffix = `---FILE: ${summaryPath}---\n# Later incorrect replacement\n---END FILE---`++ await autoIngest(tmp.path, `${tmp.path}/raw/sources/project-a/config.yaml`, useWikiStore.getState().llmConfig)++ const content = await fs.readFile(`${tmp.path}/${summaryPath}`, "utf8")+ expect(content).toContain("first correct summary")+ expect(content).not.toContain("Later incorrect replacement")+ expect(await fs.readFile(`${tmp.path}/.llm-wiki/ingest-warnings.log`, "utf8")).toContain("Ignored duplicate source summary")+ })++ it("prevents schema routing from overwriting an already-written source summary", async () => {+ if (!tmp) throw new Error("missing temp project")+ sourceMarkers = ["correct source summary"]+ await writeFileRaw(`${tmp.path}/schema.md`, "## Page Types\n| source | wiki/sources/ | Source summaries |")+ const slug = sourceSummarySlugFromIdentity("project-a/config.yaml")+ generationSuffix = `---FILE: wiki/concepts/${slug}.md---\n---\ntype: source\n---\n# Wrong routed replacement\n---END FILE---`++ await autoIngest(tmp.path, `${tmp.path}/raw/sources/project-a/config.yaml`, useWikiStore.getState().llmConfig)++ expect(await fs.readFile(`${tmp.path}/wiki/sources/${slug}.md`, "utf8")).toContain("correct source summary")+ expect(await fs.readFile(`${tmp.path}/.llm-wiki/ingest-warnings.log`, "utf8")).toContain("Ignored duplicate source summary")+ })++ it("does not repair an unexpected truncated source summary onto the current source", async () => {+ if (!tmp) throw new Error("missing temp project")+ sourceMarkers = ["correct source summary"]+ generationSuffix = "---FILE: wiki/sources/cited-work.md---\n# Incomplete cited work"+ truncatedRepairResponse = "---FILE: wiki/sources/cited-work.md---\n# Wrong repair\n---END FILE---"++ await autoIngest(tmp.path, `${tmp.path}/raw/sources/project-a/config.yaml`, useWikiStore.getState().llmConfig)++ const summaryPath = `wiki/sources/${sourceSummarySlugFromIdentity("project-a/config.yaml")}.md`+ expect(await fs.readFile(`${tmp.path}/${summaryPath}`, "utf8")).toContain("correct source summary")+ await expect(fs.access(`${tmp.path}/wiki/sources/cited-work.md`)).rejects.toThrow()+ expect(mockStreamChat.mock.calls.some(([, messages]) => String(messages[0]?.content).startsWith("You are repairing truncated wiki FILE blocks"))).toBe(false)+ })++ it("protects the source summary while repairing a different truncated page", async () => {+ if (!tmp) throw new Error("missing temp project")+ sourceMarkers = ["correct source summary"]+ const summaryPath = `wiki/sources/${sourceSummarySlugFromIdentity("project-a/config.yaml")}.md`+ generationSuffix = "---FILE: wiki/concepts/recovered.md---\n# Incomplete concept"+ truncatedRepairResponse = [+ "---FILE: wiki/concepts/recovered.md---\n# Recovered concept\n---END FILE---",+ `---FILE: ${summaryPath}---\n# Wrong replacement\n---END FILE---`,+ "---FILE: wiki/sources/cited-work.md---\n# Wrong cited work\n---END FILE---",+ ].join("\n")++ const written = await autoIngest(tmp.path, `${tmp.path}/raw/sources/project-a/config.yaml`, useWikiStore.getState().llmConfig)++ expect(written).toContain("wiki/concepts/recovered.md")+ expect(await fs.readFile(`${tmp.path}/${summaryPath}`, "utf8")).toContain("correct source summary")+ await expect(fs.access(`${tmp.path}/wiki/sources/cited-work.md`)).rejects.toThrow()+ })++ it("rejects additional and duplicate source summaries during interactive writes", async () => {+ if (!tmp) throw new Error("missing temp project")+ useChatStore.getState().createConversation()+ const summaryPath = `wiki/sources/${sourceSummarySlugFromIdentity("project-a/config.yaml")}.md`+ interactiveGenerationOverride = [+ "---FILE: wiki/sources/cited-work.md---\n# Wrong cited work\n---END FILE---",+ `---FILE: ${summaryPath}---\n# Correct interactive summary\n---END FILE---`,+ `---FILE: ${summaryPath}---\n# Wrong duplicate\n---END FILE---`,+ ].join("\n")+ useChatStore.setState({ ingestSource: `${tmp.path}/raw/sources/project-a/config.yaml` })++ const written = await executeIngestWrites(tmp.path, useWikiStore.getState().llmConfig)++ expect(written).toEqual([`${tmp.path}/${summaryPath}`])+ expect(await fs.readFile(written[0], "utf8")).toContain("Correct interactive summary")+ await expect(fs.access(`${tmp.path}/wiki/sources/cited-work.md`)).rejects.toThrow()+ const warnings = await fs.readFile(`${tmp.path}/.llm-wiki/ingest-warnings.log`, "utf8")+ expect(warnings).toContain("Ignored unexpected source summary")+ expect(warnings).toContain("Ignored duplicate source summary")+ expect(useChatStore.getState().messages.some((m) => m.role === "system" && m.content.includes("Ingest warnings:"))).toBe(true)+ })++ it.each([+ `${"中文".repeat(35)}.md`,+ `${"资".repeat(30)}/${"文".repeat(70)}.md`,+ ])("ingests a long CJK source into a filesystem-safe summary: %s", async (identity) => {+ if (!tmp) throw new Error("missing temp project")+ sourceMarkers = ["long source ingested"]+ await writeFileRaw(`${tmp.path}/raw/sources/${identity}`, "Long CJK filename source.\n")++ const written = await autoIngest(tmp.path, `${tmp.path}/raw/sources/${identity}`, useWikiStore.getState().llmConfig)+ const summaryPath = `wiki/sources/${sourceSummarySlugFromIdentity(identity)}.md`++ expect(written).toContain(summaryPath)+ expect(await fs.readFile(`${tmp.path}/${summaryPath}`, "utf8")).toContain("long source ingested")+ expect(await fs.readFile(`${tmp.path}/${summaryPath}`, "utf8")).toContain(identity)+ expect(useActivityStore.getState().items.some((item) => item.status === "error")).toBe(false)+ })++ it("keeps an existing portable CJK summary at its original path", async () => {+ if (!tmp) throw new Error("missing temp project")+ const stem = "中文".repeat(35)+ const identity = `${stem}.md`+ const oldSummaryPath = `${tmp.path}/wiki/sources/${stem}.md`+ sourceMarkers = ["regenerated long source"]+ await writeFileRaw(`${tmp.path}/raw/sources/${identity}`, "Updated source.\n")+ await writeFileRaw(oldSummaryPath, `---\nsources: ["${identity}"]\n---\n# Previous summary`)++ await autoIngest(tmp.path, `${tmp.path}/raw/sources/${identity}`, useWikiStore.getState().llmConfig)++ const summaryPath = `${tmp.path}/wiki/sources/${sourceSummarySlugFromIdentity(identity)}.md`+ expect(summaryPath).toBe(oldSummaryPath)+ expect(await fs.readFile(summaryPath, "utf8")).toContain("regenerated long source")+ })+it("keeps distinct source summaries for same-basename files in different source subdirectories", async () => {if (!tmp) throw new Error("missing temp project")sourceMarkers = ["project-a config", "project-b config"]