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: normalize deep research wikilinks

nash_su48fcb30dd558
diff --git a/src/lib/deep-research.test.ts b/src/lib/deep-research.test.ts
index e2b21f48..df99fee4 100644
--- a/src/lib/deep-research.test.ts
+++ b/src/lib/deep-research.test.ts
@@ -1,6 +1,7 @@
import { describe, expect, it, vi } from "vitest"
import {
citedResearchSourceIndexes,
+ buildResearchPageContent,
collectResearchSources,
makeDeepResearchFileName,
noResearchSourcesTaskPatch,
@@ -58,6 +59,25 @@ describe("makeDeepResearchFileName", () => {
})
})
+describe("buildResearchPageContent", () => {
+ it("normalizes path-prefixed page links without changing code or embeds", () => {
+ const content = buildResearchPageContent(
+ "AI research",
+ "2026-08-20",
+ [
+ "See [[concepts/adaptation|adaptation]] and [[entities/person#work]].",
+ "Keep `[[concepts/code-example]]` and ![[media/chart.png]].",
+ ].join("\n"),
+ "1. [Source](https://example.com)",
+ )
+
+ expect(content).toContain("[[adaptation|adaptation]]")
+ expect(content).toContain("[[person#work]]")
+ expect(content).toContain("`[[concepts/code-example]]`")
+ expect(content).toContain("![[media/chart.png]]")
+ })
+})
+
describe("validateResearchSynthesis", () => {
const substantiveChinese = [
"解离是一类涉及记忆、身份、意识与环境感知连续性受扰的心理现象。[1]",
diff --git a/src/lib/deep-research.ts b/src/lib/deep-research.ts
index eb52eb8b..829e9777 100644
--- a/src/lib/deep-research.ts
+++ b/src/lib/deep-research.ts
@@ -10,6 +10,7 @@ import { buildLanguageDirective } from "@/lib/output-language"
import { makeQueryFileName } from "@/lib/wiki-filename"
import { refreshProjectFileTree } from "@/lib/project-file-tree-refresh"
import { useReviewStore } from "@/stores/review-store"
+import { stripBodyWikilinkPathPrefixes } from "./page-merge"
const MAX_RESEARCH_SOURCES = 20
const MIN_RESEARCH_CONTENT_CHARS = 120
@@ -22,6 +23,32 @@ export interface ResearchSynthesisValidation {
error: string | null
}
+export function buildResearchPageContent(
+ topic: string,
+ date: string,
+ synthesis: string,
+ references: string,
+): string {
+ return stripBodyWikilinkPathPrefixes([
+ "---",
+ "type: query",
+ `title: "Research: ${topic.replace(/"/g, '\\"')}"`,
+ `created: ${date}`,
+ "origin: deep-research",
+ "tags: [research]",
+ "---",
+ "",
+ `# Research: ${topic}`,
+ "",
+ synthesis,
+ "",
+ "## References",
+ "",
+ references,
+ "",
+ ].join("\n"))
+}
+
interface ResearchSourceDeps {
webSearch: typeof webSearch
anyTxtSearch: typeof anyTxtSearchSmart
@@ -423,24 +450,12 @@ async function executeResearch(
})
.join("\n")
- const pageContent = [
- "---",
- `type: query`,
- `title: "Research: ${topic.replace(/"/g, '\\"')}"`,
- `created: ${date}`,
- `origin: deep-research`,
- `tags: [research]`,
- "---",
- "",
- `# Research: ${topic}`,
- "",
+ const pageContent = buildResearchPageContent(
+ topic,
+ date,
validation.cleaned,
- "",
- "## References",
- "",
references,
- "",
- ].join("\n")
+ )
await writeFile(filePath, pageContent)
const savedPath = `wiki/queries/${fileName}`
diff --git a/src/lib/page-merge.ts b/src/lib/page-merge.ts
index 4d244541..8132c91b 100644
--- a/src/lib/page-merge.ts
+++ b/src/lib/page-merge.ts
@@ -209,7 +209,7 @@ export async function mergePageContent(
* `[[clients/foo-overview]]`; merge prompts intentionally preserve existing
* links, so the application must repair those targets deterministically.
*/
-function stripBodyWikilinkPathPrefixes(content: string): string {
+export function stripBodyWikilinkPathPrefixes(content: string): string {
const frontmatter = content.match(/^---\r?\n[\s\S]*?\r?\n---(?:\r?\n|$)/)
if (!frontmatter) return content