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: harden review wiki index updates

nash_suc00be889d03f
diff --git a/src/components/review/review-view.tsx b/src/components/review/review-view.tsx
index 2dac77bb..fde5ec30 100644
--- a/src/components/review/review-view.tsx
+++ b/src/components/review/review-view.tsx
@@ -87,7 +87,7 @@ export function ReviewView() {
const linkTarget = fileName.replace(/\.md$/, "")
const entry = `- [[queries/${linkTarget}|${title}]]`
if (indexContent.includes("## Queries")) {
- indexContent = indexContent.replace(/(## Queries\n)/, `$1${entry}\n`)
+ indexContent = indexContent.replace(/(## Queries\n)/, (match) => `${match}${entry}\n`)
} else {
indexContent = indexContent.trimEnd() + "\n\n## Queries\n" + entry + "\n"
}
@@ -104,6 +104,7 @@ export function ReviewView() {
setFileTree(tree)
useWikiStore.getState().setSelectedFile(filePath)
useWikiStore.getState().setFileContent(pageContent)
+ useWikiStore.getState().bumpDataVersion()
resolveItem(id, "Saved to Wiki")
} catch (err) {
@@ -197,7 +198,7 @@ export function ReviewView() {
const linkTarget = fileName.replace(/\.md$/, "")
const entry = `- [[${dir}/${linkTarget}|${title}]]`
if (indexContent.includes(sectionHeader)) {
- indexContent = indexContent.replace(new RegExp(`(${sectionHeader}\n)`), `$1${entry}\n`)
+ indexContent = indexContent.replace(new RegExp(`(${sectionHeader}\n)`), (match) => `${match}${entry}\n`)
} else {
indexContent = indexContent.trimEnd() + `\n\n${sectionHeader}\n${entry}\n`
}
diff --git a/src/lib/wiki-filename.test.ts b/src/lib/wiki-filename.test.ts
index 16b3c03d..aec8e481 100644
--- a/src/lib/wiki-filename.test.ts
+++ b/src/lib/wiki-filename.test.ts
@@ -58,6 +58,13 @@ describe("makeQuerySlug", () => {
expect(makeQuerySlug(long)).toHaveLength(50)
})
+ it("truncates by Unicode code point rather than leaving a lone surrogate", () => {
+ const astral = "𠀀".repeat(60)
+ const slug = makeQuerySlug(astral)
+ expect(Array.from(slug)).toHaveLength(50)
+ expect(() => encodeURIComponent(slug)).not.toThrow()
+ })
+
it("preserves case-insensitive equivalence for wikilink matching", () => {
// The codebase treats wikilinks case-insensitively (see lint.ts
// line 48 comment). Slugs are always lowercase, so two titles
diff --git a/src/lib/wiki-filename.ts b/src/lib/wiki-filename.ts
index 075bae1a..ff01684f 100644
--- a/src/lib/wiki-filename.ts
+++ b/src/lib/wiki-filename.ts
@@ -41,8 +41,8 @@ export function makeQuerySlug(title: string): string {
.replace(/-+/g, "-")
.replace(/^-|-$/g, "")
.toLowerCase()
- .slice(0, 50)
- return slug.length > 0 ? slug : "query"
+ const truncated = Array.from(slug).slice(0, 50).join("")
+ return truncated.length > 0 ? truncated : "query"
}
/** Produce the full wiki filename. Accepts an injected `now` for