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: ground generated entity pages
nash_su773587db568d
diff --git a/src/lib/ingest.prompt.test.ts b/src/lib/ingest.prompt.test.tsindex 7be7f884..8b72bc97 100644--- a/src/lib/ingest.prompt.test.ts+++ b/src/lib/ingest.prompt.test.ts@@ -2,6 +2,7 @@ import { describe, it, expect, beforeEach } from "vitest"import {buildReviewSuggestionPrompt,buildAnalysisPrompt,+ buildChunkAnalysisSystemPrompt,buildGenerationPrompt,buildPageMergeSystemPrompt,computeIngestGenerationMaxTokens,@@ -57,6 +58,19 @@ describe("buildAnalysisPrompt language directive", () => {expect(prompt).toContain("Do not transfer claims, limits, or evaluations")})+ it("applies a significance and canonical-name threshold to entities", () => {+ const prompt = buildAnalysisPrompt("", "", "")++ expect(prompt).toContain("standalone-page significance threshold")+ expect(prompt).toContain("passing mentions")+ expect(prompt).toContain("ordinary story props")+ expect(prompt).toContain("unnamed or generic-role people")+ expect(prompt).toContain("Page-worthy: yes")+ expect(prompt).toContain("reuse the exact title of an existing wiki page first")+ expect(prompt).toContain("never invent or phonetically guess a name")+ expect(prompt).not.toContain("central vs. peripheral")+ })+it("injects the project schema so analysis can recommend custom-typed pages", () => {const schema = "## Page Types\n| goal | wiki/goals/ | Outcomes |\n| habit | wiki/habits/ | Behaviours |"const prompt = buildAnalysisPrompt("", "", "", schema)@@ -144,6 +158,34 @@ describe("buildGenerationPrompt language directive", () => {expect(prompt).toContain("cite which source/frontmatter `sources` entry supports that statement")})+ it("requires standalone entity pages to establish identity without promoting incidental mentions", () => {+ const prompt = buildGenerationPrompt("", "", "", "source.pdf")++ expect(prompt).toContain("only for a candidate explicitly marked `Page-worthy: yes`")+ expect(prompt).toContain("wikilinks only when the target already exists")+ expect(prompt).toContain("opening paragraph of every entity page must answer what the subject is")+ expect(prompt).toContain("stable, high-confidence public knowledge")+ expect(prompt).toContain("independently verifiable background in the mandatory output language")+ expect(prompt).toContain("do not create the standalone page")+ expect(prompt).toContain("reuse the exact title of an existing wiki page first")+ expect(prompt).toContain("Final Global Digest is authoritative")+ })++ it("defers long-source entity significance decisions to the global digest", () => {+ const prompt = buildChunkAnalysisSystemPrompt("", "", "", "long source")+ const chunkStart = prompt.indexOf("## Chunk Analysis")+ const digestStart = prompt.indexOf("## Updated Global Digest")+ const entityRules = prompt.indexOf("Entity handling rules:")++ expect(chunkStart).toBeGreaterThanOrEqual(0)+ expect(digestStart).toBeGreaterThan(chunkStart)+ expect(entityRules).toBeGreaterThan(digestStart)+ expect(prompt).toContain("without making a final standalone-page decision from one chunk alone")+ expect(prompt).toContain("accumulate recurrence across chunks")+ expect(prompt).toContain("supporting chunks")+ expect(prompt).toContain("Page-worthy: yes")+ })+it("makes project schema routing authoritative over default entity and concept folders", () => {const prompt = buildGenerationPrompt("Use wiki/people/ for people. Use wiki/technologies/ for technical methods.",diff --git a/src/lib/ingest.ts b/src/lib/ingest.tsindex ddd8f3f7..5e2d33aa 100644--- a/src/lib/ingest.ts+++ b/src/lib/ingest.ts@@ -2208,6 +2208,26 @@ function shouldRunDedicatedReviewStage(generation: string): boolean {|| /---REVIEW:\s*[\w-]+\s*\|[\s\S]*$/i.test(generation)}+const ENTITY_ANALYSIS_RULES = [+ "Apply a standalone-page significance threshold: page-worthy subjects are central to the source, recur meaningfully, carry substantive claims, or are reusable across the wiki.",+ "Do not mark passing mentions, ordinary story props, unnamed or generic-role people, chapter/part labels, or internal workflow artifacts as page-worthy unless the source makes them independently important knowledge subjects.",+ "For every candidate, output `Page-worthy: yes` or `Page-worthy: no` plus one short justification. Keep non-page-worthy candidates only as context for the source summary.",+ "Canonical naming priority: reuse the exact title of an existing wiki page first; otherwise preserve the source spelling. Widely used localized names may be recorded as aliases, but never invent or phonetically guess a name.",+] as const++const ENTITY_PAGE_RULES = [+ "Create a standalone entity page only for a candidate explicitly marked `Page-worthy: yes`. Keep other mentions as plain prose in the source summary, or as wikilinks only when the target already exists in the current wiki index.",+ "Canonical naming priority: reuse the exact title of an existing wiki page first; otherwise preserve the source spelling. A widely used localized name may be an alias, but never invent or phonetically guess a name.",+ "The opening paragraph of every entity page must answer what the subject is, not merely describe its role in this source.",+ "Prefer an identity supported by the source or existing wiki. If one short identity sentence must use stable, high-confidence public knowledge to identify a well-known subject, clearly label it as independently verifiable background in the mandatory output language so it is not attributed to the imported source. Never add uncertain details; when neither the source nor existing wiki establishes an unambiguous identity, do not create the standalone page.",+] as const++const LONG_SOURCE_ENTITY_RULES = [+ "In each Chunk Analysis, record named-subject mentions and identity evidence without making a final standalone-page decision from one chunk alone.",+ "In Updated Global Digest > Entities, accumulate recurrence across chunks and output for each candidate: canonical name, identity, supporting chunks, significance evidence, and `Page-worthy: yes` or `Page-worthy: no`.",+ ...ENTITY_ANALYSIS_RULES,+] as const+/*** Step 1 prompt: AI reads the source and produces a structured analysis.* This is the "discussion" step — the AI reasons about the source before writing wiki pages.@@ -2227,10 +2247,11 @@ export function buildAnalysisPrompt("Your analysis should cover:","","## Key Entities",- "List people, organizations, products, datasets, tools mentioned. For each:",+ "List candidate named people, organizations, products, datasets, and tools. For each:","- Name and type",- "- Role in the source (central vs. peripheral)",+ "- Role and significance in the source","- Whether it likely already exists in the wiki (check the index)",+ ...ENTITY_ANALYSIS_RULES,"","## Key Concepts","List theories, methods, techniques, phenomena. For each:",@@ -2317,6 +2338,8 @@ export function buildGenerationPrompt("2. Entity or schema-defined typed pages for key named things identified in the analysis. Prefer schema-defined directories when present; otherwise use wiki/entities/.","3. Concept or schema-defined typed pages for key ideas, methods, techniques, and abstractions. Prefer schema-defined directories when present; otherwise use wiki/concepts/.","4. A log entry for wiki/log.md (just the new entry to append, format: ## [YYYY-MM-DD] ingest | Title)",+ ...ENTITY_PAGE_RULES,+ "For consolidated long-document analyses, the Final Global Digest is authoritative for `Page-worthy` decisions; per-chunk mention notes are evidence, not page-creation instructions.","Do not generate wiki/index.md or wiki/overview.md. The application maintains aggregate navigation separately so large wikis are never rewritten through model output.","","## Frontmatter Rules (CRITICAL — parser is strict)",@@ -2873,7 +2896,7 @@ function extractMarkedSection(raw: string, heading: string): string {return re.exec(raw)?.[1]?.trim() ?? ""}-function buildChunkAnalysisSystemPrompt(+export function buildChunkAnalysisSystemPrompt(purpose: string,schema: string,index: string,@@ -2901,6 +2924,8 @@ function buildChunkAnalysisSystemPrompt("## Updated Global Digest","A compact document-level digest that incorporates this chunk and preserves prior cross-chunk context.","Keep this digest structured under: Summary, Entities, Concepts, Schema-Typed Candidates, Claims, Evidence, Contradictions, Open Questions, Cross-Chunk Relations.",+ "Entity handling rules:",+ ...LONG_SOURCE_ENTITY_RULES.map((rule) => `- ${rule}`),"Use schema-defined types only when the source actually supports them; never invent goals, habits, journal entries, decisions, or similar user-authored records that are not present in the source.","","Stable project context follows. It changes rarely and should be treated as background:",