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: stop generating LLM frontmatter wrapped in ```yaml fences (3-layer defense)

nash_su11d6c6c6fd8d
diff --git a/src/lib/frontmatter.test.ts b/src/lib/frontmatter.test.ts
index 7bf78f2c..811612c4 100644
--- a/src/lib/frontmatter.test.ts
+++ b/src/lib/frontmatter.test.ts
@@ -116,6 +116,60 @@ describe("parseFrontmatter", () => {
expect(r.frontmatter?.sources).toEqual(["research--2026-04-07.md"])
})
+ it("locates a frontmatter block prefixed by a stray code fence line (LLM corruption)", () => {
+ const content =
+ "```yaml\n---\ntype: entity\ntitle: \"Accumulibacter\"\n---\n\n# Accumulibacter\n\nbody\n```"
+ const r = parseFrontmatter(content)
+ expect(r.frontmatter?.type).toBe("entity")
+ expect(r.frontmatter?.title).toBe("Accumulibacter")
+ // Body retains the trailing closing fence — that's a renderer
+ // problem (markdown shows it as an unbalanced ```) not the
+ // parser's job. We only commit to extracting frontmatter.
+ expect(r.body.startsWith("# Accumulibacter")).toBe(true)
+ })
+
+ it("locates a frontmatter block prefixed by a `frontmatter:` key (LLM corruption)", () => {
+ const content =
+ "frontmatter:\n---\ntype: entity\ntitle: LSTM\n---\n\n# LSTM\n\nbody"
+ const r = parseFrontmatter(content)
+ expect(r.frontmatter?.type).toBe("entity")
+ expect(r.frontmatter?.title).toBe("LSTM")
+ })
+
+ it("does not pick up a `---` horizontal rule deep in the body as frontmatter", () => {
+ // The fallback-search window is small enough to skip horizontal
+ // rules used as section dividers below paragraphs of body text.
+ const content =
+ "# Heading\n\nfirst paragraph\n\nsecond paragraph\n\n---\n\nthird paragraph after rule"
+ const r = parseFrontmatter(content)
+ expect(r.frontmatter).toBeNull()
+ expect(r.body).toBe(content)
+ })
+
+ it("repairs `key: [[a]], [[b]]` (LLM-emitted invalid wikilink list) via retry", () => {
+ const content =
+ "---\ntype: entity\ntitle: LTTC\nrelated: [[riyuu-jiaoben]], [[zi-yuan-bu]], [[wai-wu]]\n---\nbody"
+ const r = parseFrontmatter(content)
+ expect(r.frontmatter?.type).toBe("entity")
+ expect(r.frontmatter?.related).toEqual([
+ "[[riyuu-jiaoben]]",
+ "[[zi-yuan-bu]]",
+ "[[wai-wu]]",
+ ])
+ })
+
+ it("doesn't mangle a legitimate nested-array YAML value during repair", () => {
+ // Repair only fires when the FIRST yaml.load throws. Legitimate
+ // nested arrays parse on the first pass and are left alone.
+ const content = `---\nmatrix: [[1, 2], [3, 4]]\n---\nbody`
+ const r = parseFrontmatter(content)
+ // Nested arrays come through normalize as a JSON-stringified
+ // string per element, which is acceptable surface behavior — the
+ // important part is we didn't crash or corrupt the structure.
+ expect(r.frontmatter).not.toBeNull()
+ expect(r.body).toBe("body")
+ })
+
it("matches the real BOD entity frontmatter (quoted wikilink items in block array)", () => {
const content =
`---\ntype: entity\ntitle: BOD(生化需氧量)\ncreated: 2026-04-07\nupdated: 2026-04-07\ntags: [水质指标, 环境监测, 污水处理, 核心参数]\nrelated:\n - "[[nh3-n]]"\n - "[[soft-sensor-watertreatment]]"\n - "[[ai-effluent-water-quality-prediction]]"\n - "[[digital-twin-wastewater]]"\nsources: ["research-ai-2026-04-07.md"]\n---\n\n# Body`
diff --git a/src/lib/frontmatter.ts b/src/lib/frontmatter.ts
index 98053d47..5934a72b 100644
--- a/src/lib/frontmatter.ts
+++ b/src/lib/frontmatter.ts
@@ -16,33 +16,45 @@ export interface FrontmatterParseResult {
rawBlock: string
}
-// Single, generic detector. Both fence lines must be on their own
-// line (anchored with `^...$` under the `m` flag); content between
-// is delegated to a real YAML parser. We do NOT try to special-case
-// trailing whitespace, BOMs, alternative fence markers, or LLM
-// corruption patterns here — that path leads to ever-growing regex
-// patches with no real progress. If the file isn't a standard
-// `---\n…\n---` document, we treat it as "no frontmatter" and let
-// the body render in full.
-const FM_BLOCK_RE = /^---\s*\r?\n([\s\S]*?)\r?\n---\s*(?:\r?\n|$)/
+// Strict, anchored detector. Both fence lines must be on their own
+// line; content between is delegated to js-yaml. Used as the first
+// step before falling back to the locator below.
+const FM_BLOCK_STRICT_RE = /^---\s*\r?\n([\s\S]*?)\r?\n---\s*(?:\r?\n|$)/
+
+// Same shape as STRICT but unanchored — used only when STRICT
+// failed. LLM-generated pages often prepend an extra line or two
+// before the real frontmatter (a stray `\`\`\`yaml` wrapper line, a
+// `frontmatter:` key from a misformatted nested-document attempt,
+// etc.). Rather than enumerating every such prefix, we look for
+// the FIRST `---\n…\n---` block whose OPENING fence sits in the
+// top few lines. The closing fence can land anywhere — long
+// frontmatter lists are common — but capping the open-line means
+// a `---` horizontal rule used as a section divider deep in the
+// body can't be mistaken for frontmatter.
+const FM_BLOCK_ANYWHERE_RE = /\n---\s*\r?\n([\s\S]*?)\r?\n---\s*(?:\r?\n|$)/
+const MAX_PREFIX_LINES_BEFORE_FRONTMATTER = 6
export function parseFrontmatter(content: string): FrontmatterParseResult {
- const match = content.match(FM_BLOCK_RE)
- if (!match) return { frontmatter: null, body: content, rawBlock: "" }
+ const located = locateFrontmatterBlock(content)
+ if (!located) return { frontmatter: null, body: content, rawBlock: "" }
- const yamlPayload = match[1]
- const rawBlock = match[0]
- const body = content.slice(rawBlock.length)
+ const { yamlPayload, rawBlock, body } = located
+ // Two-pass YAML parse: try the payload as-is first, then on
+ // failure run a single round of "wikilink-list" repair (LLMs
+ // sometimes emit `related: [[a]], [[b]], [[c]]` which is not
+ // valid YAML — wrap each `[[…]]` in quotes so it parses as a
+ // string list). This is the only fixup we apply; anything
+ // beyond that is reported as no-frontmatter.
let parsed: unknown
try {
parsed = yaml.load(yamlPayload, { schema: yaml.JSON_SCHEMA })
} catch {
- // Malformed YAML — degrade gracefully. Treat the file as having
- // no parseable frontmatter, but keep stripping the fence block
- // so the user doesn't see a wall of `key: value` text in the
- // rendered body.
- return { frontmatter: null, body, rawBlock }
+ try {
+ parsed = yaml.load(repairWikilinkLists(yamlPayload), { schema: yaml.JSON_SCHEMA })
+ } catch {
+ return { frontmatter: null, body, rawBlock }
+ }
}
return {
@@ -52,6 +64,92 @@ export function parseFrontmatter(content: string): FrontmatterParseResult {
}
}
+/**
+ * Find the first `---…---` frontmatter block. Strict (top-of-file)
+ * match is preferred; if it fails we scan a small window for an
+ * unanchored block, which lets us recover from common LLM-corrupted
+ * pages that put a junk line or two before the real frontmatter
+ * (e.g. wrapping the file in a code fence, or emitting
+ * `frontmatter:\n---\n…\n---\n`). Returns null when neither finds
+ * anything plausible.
+ */
+function locateFrontmatterBlock(
+ content: string,
+): { yamlPayload: string; rawBlock: string; body: string } | null {
+ const strict = content.match(FM_BLOCK_STRICT_RE)
+ if (strict) {
+ return {
+ yamlPayload: strict[1],
+ rawBlock: strict[0],
+ body: content.slice(strict[0].length),
+ }
+ }
+
+ // Scan the entire content (not just a head window) so a long
+ // frontmatter list still resolves. The lazy match picks the
+ // FIRST `---…---` pair, and we then guard against false
+ // positives by checking that the OPENING `---` is within the
+ // first few lines — that excludes section-divider HRs deep in
+ // the body without limiting how long the frontmatter itself
+ // can be.
+ const fallback = content.match(FM_BLOCK_ANYWHERE_RE)
+ if (!fallback || fallback.index === undefined) return null
+
+ const openIdx = fallback.index + 1 // skip the leading `\n`
+ if (lineNumberAt(content, openIdx) > MAX_PREFIX_LINES_BEFORE_FRONTMATTER) {
+ return null
+ }
+
+ const rawBlock = content.slice(openIdx, openIdx + fallback[0].length - 1)
+ return {
+ yamlPayload: fallback[1],
+ rawBlock,
+ body: content.slice(openIdx + rawBlock.length),
+ }
+}
+
+/** 1-based line number that a given character index sits on. */
+function lineNumberAt(s: string, index: number): number {
+ let line = 1
+ for (let i = 0; i < index && i < s.length; i++) {
+ if (s.charCodeAt(i) === 10) line++
+ }
+ return line
+}
+
+/**
+ * Repair a YAML payload where the author wrote a list of Obsidian
+ * wikilinks without the outer brackets:
+ *
+ * related: [[a]], [[b]], [[c]]
+ *
+ * which YAML rejects. We rewrite each line that matches that shape
+ * into a quoted-string flow array so js-yaml can parse it:
+ *
+ * related: ["[[a]]", "[[b]]", "[[c]]"]
+ *
+ * Only touches lines that look exactly like that pattern; anything
+ * else is passed through unchanged so a legitimate nested-array
+ * value (`tags: [[red, blue], [green]]`) isn't mangled.
+ */
+function repairWikilinkLists(payload: string): string {
+ return payload
+ .split("\n")
+ .map((line) => {
+ const m = line.match(/^(\s*[A-Za-z_][\w-]*\s*:\s*)(\[\[[^\]]+\]\](?:\s*,\s*\[\[[^\]]+\]\])+)\s*$/)
+ if (!m) return line
+ const prefix = m[1]
+ const items = m[2]
+ .split(",")
+ .map((s) => s.trim())
+ .filter(Boolean)
+ .map((s) => `"${s}"`)
+ .join(", ")
+ return `${prefix}[${items}]`
+ })
+ .join("\n")
+}
+
/**
* Coerce js-yaml's output into the shape FrontmatterPanel consumes:
* a flat `Record<string, string | string[]>`. Nested objects and
diff --git a/src/lib/ingest-sanitize.test.ts b/src/lib/ingest-sanitize.test.ts
new file mode 100644
index 00000000..6e1074e3
--- /dev/null
+++ b/src/lib/ingest-sanitize.test.ts
@@ -0,0 +1,90 @@
+import { describe, it, expect } from "vitest"
+import { sanitizeIngestedFileContent } from "./ingest-sanitize"
+
+describe("sanitizeIngestedFileContent", () => {
+ it("returns clean content unchanged", () => {
+ const input = `---\ntype: entity\ntitle: Foo\n---\n\n# Foo\n\nbody`
+ expect(sanitizeIngestedFileContent(input)).toBe(input)
+ })
+
+ it("strips a ```yaml-wrapped document and leaves the frontmatter block standard", () => {
+ const input =
+ "```yaml\n---\ntype: entity\ntitle: Accumulibacter\n---\n\n# Body\n```"
+ const out = sanitizeIngestedFileContent(input)
+ expect(out).toBe("---\ntype: entity\ntitle: Accumulibacter\n---\n\n# Body")
+ })
+
+ it("strips a ```md-wrapped document", () => {
+ const input = "```md\n---\ntype: x\n---\nbody\n```"
+ const out = sanitizeIngestedFileContent(input)
+ expect(out).toBe("---\ntype: x\n---\nbody")
+ })
+
+ it("strips a ```markdown-wrapped document", () => {
+ const input = "```markdown\n---\ntype: x\n---\nbody\n```"
+ expect(sanitizeIngestedFileContent(input)).toBe("---\ntype: x\n---\nbody")
+ })
+
+ it("strips a bare ```-wrapped document (no lang)", () => {
+ const input = "```\n---\ntype: x\n---\nbody\n```"
+ expect(sanitizeIngestedFileContent(input)).toBe("---\ntype: x\n---\nbody")
+ })
+
+ it("does NOT strip a non-fence-wrapped document containing a fenced code block in the body", () => {
+ const input =
+ "---\ntype: x\n---\n\n# Heading\n\n```js\nconsole.log('hi')\n```\n\nmore body"
+ // The leading line is `---`, not a fence opener, so stripping
+ // doesn't fire. Body fences are preserved verbatim.
+ expect(sanitizeIngestedFileContent(input)).toBe(input)
+ })
+
+ it("does NOT strip a partially-fenced document (open fence but no matching close)", () => {
+ const input = "```yaml\n---\ntype: x\n---\nbody"
+ expect(sanitizeIngestedFileContent(input)).toBe(input)
+ })
+
+ it("strips a leading `frontmatter:` key prefix when followed by a real --- block", () => {
+ const input =
+ "frontmatter:\n---\ntype: entity\ntitle: LSTM\n---\n\n# Body"
+ expect(sanitizeIngestedFileContent(input)).toBe(
+ "---\ntype: entity\ntitle: LSTM\n---\n\n# Body",
+ )
+ })
+
+ it("does NOT strip the word `frontmatter:` when it appears mid-document (in prose)", () => {
+ const input = "---\ntype: x\n---\n\nThe frontmatter: of this doc is above."
+ expect(sanitizeIngestedFileContent(input)).toBe(input)
+ })
+
+ it("repairs an invalid `key: [[a]], [[b]]` wikilink list inside frontmatter", () => {
+ const input =
+ "---\ntype: entity\nrelated: [[a]], [[b]], [[c]]\n---\n\nbody"
+ expect(sanitizeIngestedFileContent(input)).toBe(
+ `---\ntype: entity\nrelated: ["[[a]]", "[[b]]", "[[c]]"]\n---\n\nbody`,
+ )
+ })
+
+ it("doesn't touch a single `key: [[a]]` (not a list — leave the user's intent alone)", () => {
+ const input = `---\nrelated: [[a]]\n---\nbody`
+ // Single-element nested-array form is rare but legal YAML;
+ // we only repair the multi-comma form which is unambiguously
+ // an LLM mistake.
+ expect(sanitizeIngestedFileContent(input)).toBe(input)
+ })
+
+ it("doesn't touch wikilink-style text that appears in the body", () => {
+ const input = "---\ntype: x\n---\n\nrelated: [[a]], [[b]] in body prose"
+ // Repair only fires inside the frontmatter block; body
+ // content is verbatim.
+ expect(sanitizeIngestedFileContent(input)).toBe(input)
+ })
+
+ it("composes all three repairs on a real-corpus-shaped input", () => {
+ const input =
+ "```yaml\nfrontmatter:\n---\ntype: entity\nrelated: [[a]], [[b]]\n---\n\n# Body\n```"
+ const out = sanitizeIngestedFileContent(input)
+ expect(out).toBe(
+ `---\ntype: entity\nrelated: ["[[a]]", "[[b]]"]\n---\n\n# Body`,
+ )
+ })
+})
diff --git a/src/lib/ingest-sanitize.ts b/src/lib/ingest-sanitize.ts
new file mode 100644
index 00000000..d6a6bcf6
--- /dev/null
+++ b/src/lib/ingest-sanitize.ts
@@ -0,0 +1,135 @@
+/**
+ * Clean up an LLM-generated wiki page body before it hits disk.
+ *
+ * Audit of one real corpus (67 entity pages from `/Test321/wiki/entities`)
+ * showed 30/67 pages had frontmatter that couldn't be parsed strictly.
+ * Three recurring shapes the model emits:
+ *
+ * 1. The whole page wrapped in a `\`\`\`yaml … \`\`\`` (or `\`\`\`md`,
+ * `\`\`\`markdown`) code fence, e.g.
+ *
+ * ```yaml
+ * ---
+ * type: entity
+ * ---
+ * # Body
+ * ```
+ *
+ * — looks fine in the generation context but has no place in a
+ * real .md file.
+ *
+ * 2. A leading `frontmatter:` key that turns the document into a
+ * malformed nested-yaml shape, e.g.
+ *
+ * frontmatter:
+ * ---
+ * type: entity
+ * ---
+ *
+ * 3. Inline wikilink lists without the outer brackets, e.g.
+ *
+ * related: [[a]], [[b]], [[c]]
+ *
+ * — semantically what the model wanted (a list of wikilinks),
+ * but not valid YAML flow syntax.
+ *
+ * This sanitizer rewrites all three shapes into the standard
+ * `---\n…\n---\n` frontmatter form before write. It's deliberately
+ * conservative: each pattern is anchored at the very start of the
+ * document (or at top-level frontmatter scope), so a legitimate
+ * fenced code block deep in the body or a `frontmatter:` mention
+ * inside prose is left alone.
+ *
+ * The read-time parser still retains its fallback paths so old,
+ * already-written corrupt files render correctly. Sanitizing on
+ * write means newly-generated files never need that fallback,
+ * which means re-ingesting an old file once cleans it up
+ * permanently.
+ */
+export function sanitizeIngestedFileContent(content: string): string {
+ let cleaned = content
+
+ // (1) Strip an outer code fence wrapping the whole document.
+ // We only act when the FIRST non-empty line is an opening fence
+ // (`\`\`\`yaml`, `\`\`\`md`, `\`\`\`markdown`, or just `\`\`\``)
+ // AND the LAST non-empty line is a matching closing fence. This
+ // avoids touching pages that legitimately end with an unclosed
+ // fence (we don't try to "fix" mid-stream truncation here).
+ cleaned = stripOuterCodeFence(cleaned)
+
+ // (2) Strip a stray `frontmatter:` line that prefixes the real
+ // `---` block. Some prompts seem to make the model interpret
+ // the request as "produce a YAML document with a `frontmatter`
+ // key" rather than "produce a markdown document with a
+ // frontmatter block".
+ cleaned = stripFrontmatterKeyPrefix(cleaned)
+
+ // (3) Repair `key: [[a]], [[b]], [[c]]` lines inside the
+ // frontmatter block so they're valid YAML. Body wikilinks are
+ // left alone — those render fine via the wikilink → markdown
+ // link transform applied at read time.
+ cleaned = repairWikilinkListsInFrontmatter(cleaned)
+
+ return cleaned
+}
+
+/** Top-level fence wrapper. Removes the open + close fence lines. */
+function stripOuterCodeFence(content: string): string {
+ const open = content.match(/^[ \t]*```(?:yaml|md|markdown)?[ \t]*\r?\n/)
+ if (!open) return content
+ const afterOpen = content.slice(open[0].length)
+
+ // Closing fence: a final ``` on its own line, ignoring trailing
+ // whitespace/newlines after it.
+ const close = afterOpen.match(/\r?\n[ \t]*```[ \t]*\r?\n?\s*$/)
+ if (!close) return content
+ return afterOpen.slice(0, close.index)
+}
+
+/**
+ * Strip a leading `frontmatter:` line followed by the real
+ * frontmatter block. Only acts when the next non-empty line is
+ * `---`, so a body that legitimately mentions the word
+ * "frontmatter:" in prose is unaffected.
+ */
+function stripFrontmatterKeyPrefix(content: string): string {
+ const m = content.match(/^[ \t]*frontmatter\s*:\s*\r?\n(?=[ \t]*---\s*\r?\n)/)
+ if (!m) return content
+ return content.slice(m[0].length)
+}
+
+/**
+ * Inside the frontmatter block (between the opening `---` and the
+ * closing `---`), rewrite invalid wikilink-list lines. Lines
+ * outside the frontmatter block are left untouched.
+ */
+function repairWikilinkListsInFrontmatter(content: string): string {
+ const fmRe = /^---\s*\r?\n([\s\S]*?)\r?\n---\s*(\r?\n|$)/
+ const m = content.match(fmRe)
+ if (!m) return content
+
+ const repairedPayload = m[1]
+ .split("\n")
+ .map((line) => {
+ const lm = line.match(
+ /^(\s*[A-Za-z_][\w-]*\s*:\s*)(\[\[[^\]]+\]\](?:\s*,\s*\[\[[^\]]+\]\])+)\s*$/,
+ )
+ if (!lm) return line
+ const items = lm[2]
+ .split(",")
+ .map((s) => s.trim())
+ .filter(Boolean)
+ .map((s) => `"${s}"`)
+ .join(", ")
+ return `${lm[1]}[${items}]`
+ })
+ .join("\n")
+
+ // Replace ONLY the payload between fences; preserve the original
+ // fence lines and trailing newline shape.
+ return (
+ content.slice(0, m.index! + 4) + // up to and including "---\n"
+ repairedPayload +
+ content.slice(m.index! + 4 + m[1].length)
+ )
+}
diff --git a/src/lib/ingest.ts b/src/lib/ingest.ts
index a30e3225..d7154ede 100644
--- a/src/lib/ingest.ts
+++ b/src/lib/ingest.ts
@@ -7,6 +7,7 @@ import { useActivityStore } from "@/stores/activity-store"
import { useReviewStore, type ReviewItem } from "@/stores/review-store"
import { getFileName, normalizePath } from "@/lib/path-utils"
import { checkIngestCache, saveIngestCache } from "@/lib/ingest-cache"
+import { sanitizeIngestedFileContent } from "@/lib/ingest-sanitize"
import { withProjectLock } from "@/lib/project-mutex"
import {
extractAndSaveSourceImages,
@@ -770,7 +771,17 @@ async function writeFileBlocks(
const targetLang = useWikiStore.getState().outputLanguage
- for (const { path: relativePath, content } of blocks) {
+ for (const { path: relativePath, content: rawContent } of blocks) {
+ // Sanitize at the boundary — strip stray code-fence wrappers,
+ // `frontmatter:` prefixes, and repair invalid wikilink-list
+ // YAML lines so the file we write is canonical regardless of
+ // what shape the model emitted. See `ingest-sanitize.ts` for
+ // the recurring corruption shapes this fixes; without this
+ // step ~45% of generated entity pages went to disk with
+ // unparseable frontmatter and the read-time fallback had to
+ // paper over it forever.
+ const content = sanitizeIngestedFileContent(rawContent)
+
// Language guard: reject individual FILE blocks whose body contradicts
// the user-set target language. Skip:
// - log.md (structural, short)
@@ -986,25 +997,49 @@ export function buildGenerationPrompt(schema: string, purpose: string, index: st
"5. A log entry for wiki/log.md (just the new entry to append, format: ## [YYYY-MM-DD] ingest | Title)",
"6. An updated wiki/overview.md — a high-level summary of what the entire wiki covers, updated to reflect the newly ingested source. This should be a comprehensive 2-5 paragraph overview of ALL topics in the wiki, not just the new source.",
"",
- "## Frontmatter Rules (CRITICAL)",
+ "## Frontmatter Rules (CRITICAL — parser is strict)",
"",
- "Every page MUST have YAML frontmatter with these fields:",
- "```yaml",
- "---",
- "type: source | entity | concept | comparison | query | synthesis",
- "title: Human-readable title",
- "created: YYYY-MM-DD",
- "updated: YYYY-MM-DD",
- "tags: []",
- "related: []",
- `sources: [\"${sourceFileName}\"] # MUST contain the original source filename`,
- "---",
- "```",
+ "Every page begins with a YAML frontmatter block. Format rules, in order of importance:",
+ "",
+ "1. The VERY FIRST line of the file MUST be exactly `---` (three hyphens, nothing else).",
+ " Do NOT wrap the file in a ```yaml ... ``` code fence.",
+ " Do NOT prefix it with a `frontmatter:` key or any other line.",
+ "2. Each frontmatter line is a `key: value` pair on its own line.",
+ "3. The frontmatter ends with another `---` line on its own.",
+ "4. The next line after the closing `---` is the start of the page body.",
+ "5. Arrays use the standard YAML inline form `[a, b, c]` (no outer brackets around each item).",
+ " Wikilinks belong in the BODY only — never write `related: [[a]], [[b]]` (invalid YAML);",
+ " write `related: [a, b]` with bare slugs.",
+ "",
+ "Required fields and types:",
+ " • type — one of: source | entity | concept | comparison | query | synthesis",
+ " • title — string (quote it if it contains a colon, e.g. `title: \"Foo: Bar\"`)",
+ " • created — date in YYYY-MM-DD form (no quotes)",
+ " • updated — same as created",
+ " • tags — array of bare strings: `tags: [microbiology, ai]`",
+ " • related — array of bare wiki page slugs: `related: [foo, bar-baz]`. Do NOT include",
+ " `wiki/`, `.md`, or `[[…]]` here — slugs only.",
+ ` • sources — array of source filenames; MUST include "${sourceFileName}".`,
+ "",
+ "Concrete example of a complete, parseable page (everything between the two `---` lines",
+ "is the frontmatter; the heading and prose below are the body):",
+ "",
+ " ---",
+ " type: entity",
+ " title: Example Entity",
+ " created: 2026-04-29",
+ " updated: 2026-04-29",
+ " tags: [example, demo]",
+ " related: [related-slug-1, related-slug-2]",
+ ` sources: ["${sourceFileName}"]`,
+ " ---",
+ "",
+ " # Example Entity",
"",
- `The \`sources\` field MUST always contain "${sourceFileName}" — this links the wiki page back to the original uploaded document.`,
+ " Body content goes here. Use [[wikilink]] syntax in the body for cross-references.",
"",
"Other rules:",
- "- Use [[wikilink]] syntax for cross-references between pages",
+ "- Use [[wikilink]] syntax in the BODY for cross-references between pages",
"- Use kebab-case filenames",
"- Follow the analysis recommendations on what to emphasize",
"- If the analysis found connections to existing pages, add cross-references",