DEV Community

Cover image for Your LLM Wiki Still Cites the Old Rate Card. I Wrote a Freshness Check for That.
Vincent for AFFiNE

Posted on

Your LLM Wiki Still Cites the Old Rate Card. I Wrote a Freshness Check for That.

This week's feed treated Karpathy's LLM wiki like a solved ingest problem. A "reader" takes every link, PDF, and transcript you drop in. Claude Code runs the pattern from one folder. Stop re-explaining yourself every chat.

That is the compile step, and it is useful. The quieter failure showed up in the posts that treated compounding knowledge as the actual product: when the source materials change, the compiled pages have to change too. Otherwise the agent is not "remembering." It is citing last month's rate card with this month's confidence.

So this post is a ~670-line, stdlib-only Python script called source_fresh.py. You point it at a Markdown wiki whose compiled pages declare the source files they were built from. It records a SHA-256 for each source, and later it tells you which pages are stale, which citations never made it into frontmatter, and which files in sources/ no page claims. It never rewrites a wiki page. It never "fixes" a source. Eighteen tests pin that down.

A compiled wiki page stays marked fresh until a cited source file changes, then it joins a rebuild queue

A check is not a rebuild

The failure mode I keep seeing is "drop a new PDF in the inbox and assume the wiki moved with it." The compiled tuition page still says the late fee is $25 after the 10th. The source now says $40 after the 5th. An agent that packs or retrieves the compiled page will quote the old number, and it will do so with a citation.

A freshness check is narrower than a compiler.

  • Pages opt in with a sources: list in frontmatter. A brand-voice note with no sources is not a finding.
  • The record is a .freshness.json manifest next to the wiki, not a new wiki page. Hashes live there, not in the prose.
  • A source that two pages cite will stale both pages when it moves, and leave a third page alone if that page only cited a different file.
  • Body links into sources/ that are missing from frontmatter are undeclared citations. They are blocking by default, because the checker cannot watch a source it was not told about.
  • Files that sit in sources/ with no page declaring them are orphans. They are warnings unless you pass --fail-orphans.
  • check exits 1 when anything blocking is open, so you can hang it on CI. queue writes the rebuild list. record --page is what you run after a human actually rewrites the page.

Core of source_fresh.py (hash compare, shared sources, undeclared citations)
def inspect(root, *, fail_undeclared=True, fail_orphans=False):
    pages = load_pages(root)  # skips anything under sources/
    hashes, missing = hash_sources(root, collect_source_paths(root, pages))
    manifest = load_manifest(root)  # wiki/.freshness.json
    findings = []

    declared_anywhere = set()
    for page in pages:
        declared_anywhere.update(page.declared)
        for ref in page.cited:
            if ref not in page.declared:
                findings.append(Finding(
                    "undeclared", page.rel, ref,
                    "cited in the body but missing from frontmatter sources:",
                    blocking=fail_undeclared,
                ))
        if not page.declared:
            continue
        recorded = recorded_hashes(manifest, page.rel)
        if recorded is None:
            findings.append(Finding(
                "never_recorded", page.rel, None,
                "has sources: but no recorded hashes in .freshness.json",
            ))
            continue
        for ref in page.declared:
            if ref in missing:
                findings.append(Finding(
                    "missing_source", page.rel, ref,
                    "declared source file does not exist",
                ))
            elif recorded.get(ref) != hashes.get(ref):
                findings.append(Finding(
                    "stale", page.rel, ref,
                    "hash changed",
                ))

    for rel in hashes:
        if rel not in declared_anywhere:
            findings.append(Finding(
                "orphan_source", None, rel,
                "file in sources/ is not declared by any wiki page",
                blocking=fail_orphans,
            ))
    return findings
Enter fullscreen mode Exit fullscreen mode

The comparison is deliberately boring. SHA-256 does not know that a late fee changed. It knows that the bytes of sources/tuition-schedule-2026.md are not the bytes you recorded when the compiled page was last reviewed. That is the whole signal.

The sample vault

The fixture in this post is made up: a fictional community music school I called Larkspur Conservatory, in a made-up town named Ashmere. These pages are not a real tuition schedule or a real recital date.

The clean version has ten Markdown pages under wiki/, plus nine source files under wiki/sources/.

  • tuition-and-fees.md — term tuition is $1,280, the late fee is $25 after the 10th, rentals are billed separately. It declares both sources/tuition-schedule-2026.md and sources/instrument-rental-rates.md.
  • front-desk-script.md — the desk script for the same late fee, and only the tuition schedule as a source. This is the important one. One source file, two compiled pages.
  • room-booking.md, recital-week.md, scholarship-policy.md, accompanying.md — ordinary compiled pages, each pointing at their own sources.
  • draft-fee-waiver.md — a draft that also cites the scholarship terms. Drafts are still checked. They are just labeled.
  • brand-voice.md and cancelled-lesson-policy.md — standing notes with no sources: list. The checker leaves them alone.
  • practice-room-etiquette.md — also has no sources: list, on purpose, until the messy run.

After record, a clean check is quiet:

$ python3 source_fresh.py check fixture/wiki
# Source freshness

- generated: 2026-11-27T06:20:39Z
- wiki: fixture/wiki
- pages: 10 wiki, 7 with sources, 7 fresh, 0 need rebuild
- sources: 9 on disk, 0 missing
- findings: 0 (0 blocking)

All recorded pages still match their sources.
Enter fullscreen mode Exit fullscreen mode

Exit code 0. Seven of the ten pages opted into a source list; all seven still match.

Running it after the rate card moves

Then I did what actually happens in a vault. I replaced the tuition schedule with a "revised 1 November 2026" copy. The $1,280 term fee is unchanged. The late fee is now $40 after the 5th, and instrument insurance is required at $15 per term. I also dropped an unlinked board-minutes file into sources/, added a body link from the etiquette page to sources/studio-hours.md without putting it in frontmatter, and pointed the cancelled-lesson policy at a memo that is no longer on disk.

$ python3 source_fresh.py status fixture/wiki
# Source freshness

- generated: 2026-11-27T06:20:52Z
- wiki: fixture/wiki
- pages: 10 wiki, 8 with sources, 5 fresh, 3 need rebuild
- sources: 10 on disk, 1 missing
- findings: 6 (5 blocking)

## Pages that need a rebuild

- cancelled-lesson-policy.md — Cancelled lesson policy
  has sources: but no recorded hashes in .freshness.json
  sources/old-cancellation-memo.md: declared source file does not exist
- front-desk-script.md — Front desk payment script
  sources/tuition-schedule-2026.md: hash changed (b52b9217… → 0ab251dd…)
- tuition-and-fees.md — Tuition and fees
  sources/tuition-schedule-2026.md: hash changed (b52b9217… → 0ab251dd…)

## Undeclared citations

- practice-room-etiquette.md cites sources/studio-hours.md

## Orphan sources

- sources/board-minutes-2026-10.md (warning)
Enter fullscreen mode Exit fullscreen mode

The freshness report flags two pages that share a changed tuition schedule, a missing memo, an undeclared citation, and an orphan source file

Three things I care about in that report.

The hash is the same change, named twice. tuition-and-fees.md and front-desk-script.md both went stale because they both declared sources/tuition-schedule-2026.md. The rental-rate file did not move, so it is not listed under tuition-and-fees, even though that page also cites it. Recital week, room booking, scholarships, and accompanying stayed fresh. A naive "the vault changed, rebuild everything" pass would have queued those too.

The cancelled-lesson page is a different kind of broken. It now declares a memo that is not on disk, and it has never been recorded. The tool will not let you record that page until the file exists or you take it off the list. That is the point. A missing source is not "probably fine."

And the two findings that are easy to shrug at are the ones that silently rot a vault. The etiquette page now links to studio hours in the body but does not declare the file, so a later hours change would never stale it. The October board minutes are sitting in sources/ with no compiled page at all — ingest without a home. The orphan is a warning. The undeclared citation is blocking, because it is a source the checker was not allowed to watch.

check exits 1 on this vault. That is the CI hook.

Rebuild the page, then record it

queue turns the same report into a short work list. Here is the tuition entry:

## Tuition and fees

- page: tuition-and-fees.md
- why:
  - sources/tuition-schedule-2026.md — hash changed (b52b9217… → 0ab251dd…)
- sources to re-read:
  - sources/tuition-schedule-2026.md (present)
  - sources/instrument-rental-rates.md (present)

Rebuild the page from the sources, then run:

    python3 source_fresh.py record <wiki> --page tuition-and-fees.md
Enter fullscreen mode Exit fullscreen mode

The script does not draft the new page for you. I want a person — or a carefully gated agent — to re-read the source and edit the prose. After I updated the front-desk script to say $40 after the 5th and recorded that page alone, the next status report was smaller: six fresh, two still needing a rebuild. Tuition-and-fees was still stale. The cancelled memo was still missing. The front-desk script was off the list.

After recording a rebuilt front-desk script, the tuition page and the missing memo remain on the rebuild queue

That is the loop I want in an AGENTS.md or a CI job: fail the build when sources have moved, hand a human the queue, and only then record the pages that were actually rewritten.

Put the check in CI, not in the model's memory

A freshness file in the repo is only useful if something runs it. I would rather hang check on the same hook that already lints or tests the vault than ask the model to "remember to look at .freshness.json."

source_fresh.py check wiki/ exits 1 when a recorded page is stale, a declared source is missing, a page was never recorded, or a body citation never made it into frontmatter. That is enough for a pre-commit hook or a CI job. queue --out rebuild-queue.md can be an artifact on the failing build, so the review is a list of pages and sources rather than a wall of diffs.

For an agent session, a short AGENTS.md paragraph is a pointer, not the check itself:

# Wiki source freshness

Before you quote a compiled wiki page as current policy, run:

    python3 source_fresh.py check wiki/

If the check fails, read the rebuild queue and do not treat stale pages as fact.
Rebuild a page only from the sources it declares, then record that page:

    python3 source_fresh.py record wiki/ --page <page.md>

Do not run record on a page you have not rewritten. Do not invent a
missing source file to clear the check.
Enter fullscreen mode Exit fullscreen mode

The model can still ignore that. The hook cannot. If the rate card moved and nobody rebuilt the desk script, the build should go red before the session starts citing $25 after the 10th.

Where this belongs

A Markdown folder and a manifest are enough for one person's wiki, and they are close to how careful internal documentation already works: every important answer should name its source and have a reason to be reviewed when that source changes. The checker is the missing step between "I compiled a page from a rate card" and "I will notice when the rate card moves."

On a team, "the wiki still matches the sources" should be a property of the workspace, not a convention in a script the intern forgot to run. You want knowledge base software that can keep compiled operational pages tied to the files they came from, and surface a rebuild when those files change, without anyone grepping hashes by hand. The same need shows up when people try to build an AI knowledge base on top of those pages: retrieval is only as trustworthy as the document it retrieved, and a beautifully formatted but outdated policy is still a bad source.

If you can run that workspace yourself — including the self-hosted AI pattern of keeping the knowledge layer where your documents already live — the freshness rules stay yours. That is the difference between a chat that was handed a zip of Markdown and AI knowledge base software that treats "which compiled pages are still true" as part of the knowledge base. It is also why I still care about an open source Notion you can inspect: the rate card, the compiled page, and the record of their relationship should be files you can take with you.

What it does badly (on purpose)

A hash does not explain the edit. The report will tell you that tuition-schedule-2026.md changed from b52b9217 to 0ab251dd. It will not tell you that the late fee moved and the insurance became required. Open the file. That is the review.

It will not rewrite the compiled page. queue is a list. record is an acknowledgment. If you run record --page without editing the prose, you have only blessed the stale sentences. The tool cannot see that.

Undeclared citations have to be spelled in a way it can parse. Frontmatter sources:, Markdown links, [[wiki-links]], and a bare sources/... path are recognized. A sentence that says "see the studio hours file" with no path is invisible. If a citation matters, put it in frontmatter.

Orphans are easy to ignore. A drop-folder that accumulates PDFs will always have files no page has claimed yet. That is why they are warnings by default. If your ingest pipeline is supposed to be empty after compile, turn on --fail-orphans.

It will not notice a source the page never cited. If the new insurance rule also belongs on a financial-aid page that never declared the tuition schedule, that page stays "fresh." Freshness is about the sources you claimed, not about every page that ought to have claimed them.

It will not scale by becoming a knowledge graph. Ten pages and nine sources is vault scale. Past a few thousand files the same manifest still works — it is just JSON and SHA-256 — but you will want the record/check loop inside the workspace that already holds the documents, not as a one-off script people run when they remember.


Try it: point source_fresh.py at a Markdown export of your own wiki, add a sources: list to one compiled page, run record, then change the source the way a real rate card changes. In the Larkspur fixture, the useful part was not that the tuition page went stale. It was that the front-desk script, which cited the same file, went stale with it — and recital week did not.

Top comments (0)