Dev.to AI 🤖 Ai 👁 0 📖 11 min read

Your LLM Wiki Will Eat Your Zettelkasten. I Wrote a Layer Guard for That.

On November 22, someone on X put the problem more cleanly than I have: they were struggling to integrate an LLM wiki with a Zettelkasten. The wiki, they said, is for agents. The Zettelkasten is for them — a repository of

Your LLM Wiki Will Eat Your Zettelkasten. I Wrote a Layer Guard for That.

On November 22, someone on X put the problem more cleanly than I have: they were struggling to integrate an LLM wiki with a Zettelkasten. The wiki, they said, is for agents. The Zettelkasten is for them — a repository of processed, learned knowledge. This morning a reply to a HackerNoon thread called the move from Zettelkasten to LLM wiki "a big shift."

It is a shift. It is also a collision if you treat it as a rename.

Karpathy's LLM Wiki pattern has two layers: raw sources the model must not edit, and compiled Markdown pages the model owns. That split is right for a corpus of papers and transcripts. It is the wrong split for a vault that already has a Zettelkasten in it. Those atomic notes are not raw sources. You already rewrote them in your own words, gave them stable ids, and linked them because you wanted to think with them later. They are also not wiki pages. The moment an ingest agent is told to "update related pages," it will merge two notes, flatten a hedge, and leave you with a compiled overview where an observation used to be.

This week's feed is full of drop-in "second brain" repos built on that gist. Most of them share a vault with whatever Markdown you already have. I wanted a check I could run before the agent writes, and again in CI after it does.

So this post is a ~490-line, stdlib-only Python script called layer_guard.py. It enforces a three-layer vault: sources/ for raw material, notes/ for human atomic notes, and wiki/ for compiled pages. Agents may read the first two and write only to the third. It never modifies a file. Sixteen tests pin that down.

Three vault layers: sources and human notes are read-only to agents; only wiki pages are writable, and they must cite notes instead of replacing them

A Zettelkasten is a third layer

The two-layer picture is seductive because it is simple. Everything that is not the wiki is a source, and sources are sacred. That works until your "source" is a 180-word note titled Why we rejected MQTT Sparkplug for the buoy fleet, written after a real argument, with a "reopen this if…" at the bottom. That note is finished human work. Compiling it into a radio-stack page is useful. Replacing it with the radio-stack page is how you lose the argument.

So the guard assumes three layers, not two.

  • sources/ — raw logs, papers, exports. Agents may read. They may not write.
  • notes/ — human atomic notes, one idea each, stable ids. Agents may read and cite. They may not write.
  • wiki/ — compiled pages. This is the only layer an agent may create or update.

A wiki page is allowed to summarize several notes. It is not allowed to share an id or a filename stem with one, and it is not allowed to be a near-copy of one. If the model needs a page about duty cycle, it should cite 20260522-lora-duty-cycle and say something the note does not, or it should not write the page at all.

The sample vault

The fixture in this post is made up: a fictional coastal-sensing startup I called Tidemark. These notes are not a real field log.

The clean version has ten Markdown files.

  • Six human notes under notes/, with date-prefixed ids in the usual Zettelkasten style. Salt fog drifting a humidity sensor. LoRa's duty-cycle cap, not its range, as the real constraint. Calibration as a weather window rather than a 30-day ticket. Why Sparkplug was rejected for the drifting fleet. Harbor permits taking six weeks, not two. Mooring lessons from a November blow.
  • Three compiled wiki pages that cite those notes and add the operational shape: sensor-calibration.md, radio-stack.md, field-deployment.md.
  • One raw source, a North Jetty field log excerpt, under sources/.

Then I planted the kind of mess an ingest agent actually produces.

  • A compiled overview dropped into notes/ with layer: wiki in the frontmatter. Wrong folder, wrong owner.
  • A wiki page named lora-duty-cycle.md that reuses the human note's id and, almost word for word, its body. The agent "filed" the note into the wiki by copying it and dropping the date prefix.
  • Another wiki page, sensor-drift.md, that paraphrases the salt-fog note just loosely enough to look new and just tightly enough to replace it.
  • The mooring note is still uncited. The field-deployment page even admits it: "This page does not yet cover mooring hardware. That note has not been ingested." That is a gap. It is not a rewrite, so it is a warning, not an error.

What the guard actually checks

Each check run walks every Markdown file and classifies it. Frontmatter layer: human|wiki|source wins when present. Otherwise the top-level folder decides, and the script warns that it had to infer.

Then, in this order:

Folder vs layer. A layer: wiki file in notes/ is an error. The folder is the access control you can see in a file tree; the frontmatter is what an agent will read. They have to agree.

Ids. A compiled page may not reuse a human or source id. This is the obvious one, and agents still do it because the id is a convenient slug.

Stems, including date prefixes. wiki/lora-duty-cycle.md collides with notes/20260522-lora-duty-cycle.md. Dropping YYYYMMDD- is the most common way a "file this in the wiki" step eats a Zettel. The stem check treats the date prefix as disposable and compares what is left.

Rewrites. Token Jaccard of 0.42, or 72% of the human note's tokens appearing in the wiki page, flags a copy. Short notes (under eight tokens) are skipped so a title mention does not count as a rewrite. The thresholds are conservative on purpose: I would rather catch a near-verbatim paste than debate whether a good summary is "too close."

Citations. A human note that no wiki page points at, via sources: or a wiki/markdown link, is a warning. Uncited is not a crime. It is a reminder that the wiki has not ingested that note yet, which is a different problem from having overwritten it.

None of these calls a model. That is the point: a layer boundary has to be something you can run in CI, and something an agent can be denied by before it writes.

Core of layer_guard.py (rewrite detection and the write gate)
REWRITE_JACCARD = 0.42
REWRITE_COVERAGE = 0.72  # fraction of human-note tokens found in the wiki page

def is_rewrite(note: Page, wiki: Page) -> bool:
    if len(note.tokens) < 8:
        return False
    return (
        jaccard(note.tokens, wiki.tokens) >= REWRITE_JACCARD
        or coverage(note.tokens, wiki.tokens) >= REWRITE_COVERAGE
    )

def allow_write(pages, rel, proposed_text):
    top = Path(rel).parts[0].lower()
    if top not in {"wiki", "proposals", "proposal"}:
        return denied(rel, "agents may not write here")
    if proposed_text is None:
        return allowed(rel)
    proposed = load_page_from_text(rel, proposed_text)
    # Re-run id, slug, rewrite, and layer checks as if the
    # file were already in the vault. Overwriting wiki/ is fine.
    return check_pages(others + [proposed])  # only findings on rel matter

Running it on the messy vault

I ran this on 2026-11-25 against the Tidemark fixture. The clean vault, first, so you can see what "ok" looks like. The uncited mooring note is the only warning, and the exit code is 0.

$ python3 layer_guard.py fixture-clean check
pages: 10  errors: 0  warnings: 1
WARNING UNCITED          notes/20261102-buoy-mooring-lessons.md
        no wiki page cites this note via sources: or a wiki/markdown link

The messy vault is the one that looks like an agent already "helped."

$ python3 layer_guard.py fixture check
pages: 13  errors: 5  warnings: 1
ERROR   LAYER_MISMATCH   notes/sensor-calibration-overview.md
        frontmatter says layer: wiki, but notes/ is reserved for layer: human
ERROR   ID_COLLISION     wiki/lora-duty-cycle.md  (vs notes/20260522-lora-duty-cycle.md)
        id '20260522-lora-duty-cycle' is already used by a protected page
ERROR   SLUG_COLLISION   wiki/lora-duty-cycle.md  (vs notes/20260522-lora-duty-cycle.md)
        filename stem 'lora-duty-cycle' collides with human note stem '20260522-lora-duty-cycle'
ERROR   REWRITE          wiki/lora-duty-cycle.md  (vs notes/20260522-lora-duty-cycle.md)
        body is too close to a human note (jaccard=1.00, coverage=1.00); compile and cite, do not copy
ERROR   REWRITE          wiki/sensor-drift.md  (vs notes/20260408-sensor-drift-salt-fog.md)
        body is too close to a human note (jaccard=0.90, coverage=0.90); compile and cite, do not copy
WARNING UNCITED          notes/20261102-buoy-mooring-lessons.md
        no wiki page cites this note via sources: or a wiki/markdown link

layer_guard.py check on the messy Tidemark vault: five errors for a wiki file in notes/, a copied LoRa note, and a near-verbatim salt-fog rewrite, plus a warning for the uncited mooring note

Three things I care about in that report.

The overview in notes/ is not subtle. The agent declared layer: wiki and still wrote into the human folder. If your only protection is "the model will see the frontmatter," it will not help you when the file is already in the wrong place. The folder check is the one a reviewer can see without opening the file.

The LoRa page fails three times for one action: it reused the id, it dropped the date prefix, and it copied the body. That is not a compiled radio-stack page. That is the atomic note, republished under a new path, which is how a Zettelkasten disappears without anyone deleting a file.

The salt-fog rewrite is the quieter failure. The id is new. The title is slightly different. Jaccard is 0.90, coverage is 0.90. A human skimming a diff might call it a summary. The original note's hedge — "I think the issue is salt film on the sensing polymer, not firmware" — is still in there, which means the wiki page has not added operational shape. It has just moved the observation. The clean sensor-calibration.md page, by contrast, cites two notes and tells a tech when to recalibrate. That is compilation. The guard leaves it alone.

coverage is the list of notes the wiki has not ingested yet. In both fixtures it is the same one line: notes/20261102-buoy-mooring-lessons.md. That is the next page someone should compile, not a license to paste the note into wiki/.

Deny the write before it lands

check is for after the fact, or for CI. The more useful hook is allow-write. Point it at a path, optionally with the proposed file, before the agent is allowed to touch the disk.

$ python3 layer_guard.py fixture allow-write --path notes/20260408-sensor-drift-salt-fog.md
DENIED
ERROR   WRITE_DENIED     notes/20260408-sensor-drift-salt-fog.md
        agents may not write under notes/; only wiki/ and proposals/ are writable

$ python3 layer_guard.py fixture allow-write --path wiki/permits.md --file proposed-collide.md
DENIED
ERROR   ID_COLLISION     wiki/permits.md  (vs notes/20261003-harbor-permit-lead-time.md)
        id '20261003-harbor-permit-lead-time' is already used by a protected page

$ python3 layer_guard.py fixture allow-write --path wiki/winter-mooring.md --file proposed-ok.md
ALLOWED  wiki/winter-mooring.md

allow-write rejects a path under notes/ and a wiki page that reuses a human note's id, then allows a compiled winter-mooring page that cites the uncited note

The first denial does not even need to see the content. notes/ is not a writable folder, full stop. The second one is the interesting case: the path is under wiki/, which is allowed, but the proposed frontmatter reuses a human id. A page about permits is fine. A page that is the permit note is not.

The allowed write is the page the coverage warning was asking for. It lives in wiki/, has its own id (winter-mooring), cites 20261102-buoy-mooring-lessons, and adds a rule the note was inching toward: a single 20 kg mushroom on 3:1 scope is not a winter rating. That is the ingest step I actually want from an agent.

Hook allow-write as a tool the agent must call, or as a pre-commit check on any path the agent proposes. check stays in CI so a write that bypassed the tool still fails the build. Sixteen unit tests cover the errors above, the clean-vault case, inferred vs missing layers, and the guarantee that neither command modifies a file.

Where this belongs

A folder convention in a repo is enough for one person's vault. On a team, "agents may not write this" has to be a permission, not a comment in AGENTS.md. The human notes and the compiled wiki should be able to live in the same workspace without sharing a write policy — the same idea as AI workspace permissions that already distinguish what a tool may read from what it may change.

If your vault is just a shared disk, the model that can lint a page can also overwrite it. You want knowledge base software that can put atomic notes in a space an agent can search and cannot edit, and compiled pages in a space it can. That is the difference between a chat that maintains a wiki and AI knowledge base software that treats your Zettelkasten as a source, not as a draft. And if you can run that workspace yourself — the thing people usually mean when they look for an open source Notion alternative — the layer boundary stays yours, including when the ingest agent is wrong.

What it does badly (on purpose)

It will not judge a good summary. A compiled page that shares some vocabulary with its sources will usually stay under the rewrite thresholds. If a model writes a careful synthesis that happens to reuse most of a short note's wording, you can still get a false positive. Lowering the threshold would flag more honest compiles. I would rather inspect those than miss a 0.90 copy.

Citations are lexical, not semantic. A wiki page that talks about "winter anchors" without linking the mooring note will still look uncited. That is a warning, and it is the right warning. Add the link, or leave the note uningested.

Folder names are a convention. notes/, zettel/, wiki/, and sources/ are recognized. A vault that keeps atomic notes under permanent/ or slips/ will need a one-line alias, or frontmatter on every file. I did not try to guess every Zettelkasten layout.

It does not move files. The guard reports. It does not tidy notes/sensor-calibration-overview.md back into wiki/. An automatic "fix" that relocates an agent's page is how you launder a bad write. A human should decide whether to move it, rewrite it, or delete it.

It will not scale to a dump of everything you have ever written. Thirteen pages is vault scale. Past a few thousand notes you still want these rules — especially the write gate — but you may want a real index behind citation checks. The product is the boundary, not the walker.

Try it: point layer_guard.py at a Markdown export of your own vault, run check, and read the errors before you let an ingest agent "update related pages." In the Tidemark fixture, the five errors were more useful than a newly compiled overview. The uncited mooring note was the only thing I actually wanted the agent to work on next.

📰 Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.