Before Cairnbook: How Bishop's Memory Went From Markdown to SQL
At one point I had a hundred missions behind me, all in Markdown. Keeping track of their progress, descriptions, context, debriefs, findings and directives had become way too hard.
Cairnbook is the memory I'm building for my coding agents now, but it didn't start from nothing. Before it there was bishop-memory, a small Go and SQLite service, and before that there was a folder full of Markdown files. (Until November 2026 it was called Cairn, which is why the series is still Building Cairn.)
Where it started: Markdown in .claude/memory/
The first version of Bishop's memory was a set of Markdown files in .claude/memory/, with some generated views on top. That was the obvious place to start. Text files are easy to read, they diff cleanly, and you can open them in any editor. For one session, or a handful, they're fine.
The first file was never the problem. The hundredth was: finding the one I wanted, knowing whether it was current, and trusting it when two processes had touched it at once.
Why file-based memory breaks at scale
Four things wore it down as the system grew. None of them is dramatic on its own:
- Search. Grepping a folder is fine until you want ranked, content-aware retrieval across thousands of entries. Flat files don't give you that without bolting something on, and by then you're partly building a database anyway.
- Concurrency. When more than one agent process wants to read and write memory at the same time, plain files get into races. You end up hand-rolling locking you never wanted to maintain.
- History. A Markdown file shows you its current state. It doesn't easily tell you when a fact changed, or what a memory looked like last week. For a system that learns over time, that gap matters.
- Audit. If you want to know who wrote what and when, files alone turn it into a forensic exercise. A memory you can't ask "who recorded this?" is one you eventually stop trusting.
None of these matters much with a few files. With a hundred missions and more, they all mattered at once.
The bishop-memory service
So the memory moved into a proper service. bishop-memory was written in Go, with Gin for the HTTP layer and SQLite through modernc.org/sqlite, the pure-Go driver, so there was no C dependency to compile or ship. FTS5 gave it full-text search. By default it bound to loopback only, 127.0.0.1, so it wasn't reachable from the network unless you deliberately exposed it.
That default mattered to me more than the language did. The memory holds everything my agents have done and learned, and I didn't want any other machine on the network poking at it. If you want it exposed, you have to choose that. Cairnbook keeps the same rule.
It grew in steps. First a store and an API, then importing the old Markdown and making it searchable, then an MCP adapter so the agents could read and write memory as tools, the same way they use anything else. The adapter started with eight tools and grew well past that as the harness asked more of it.
Why SQLite
I was running all of this locally. I had several agents, and later several harnesses, talking to the memory, but there was really only one path to the database, from the Go API. Nothing needed a database server. I needed something portable and easy to operate, with no extra overhead on my own machine. My own machine was where I used this memory the most, so it couldn't be heavy. It had to be light, and it had to be portable. One SQLite file did that.
It wasn't free of surprises. When SQLite allocates space to a table or a piece of data, it keeps that space even after you delete the data, so the file grows and doesn't shrink on its own. I wrote a few Python scripts that run on a schedule to tidy that up.
It reminds me of our house in Kleinmond. It's very old, it has no damp course, and the water table in town is high. We've spent a lot of money draining water away from it, and the worst thing is we're fixing things that no one ever sees. Those scripts are the same kind of work.
The bigger job was the move itself. I was bringing across a lot of Markdown from my different harnesses, and I needed to write it in a properly structured way. The files had creation dates, but no update dates, and a lot of other information was simply missing. I had to rebuild that as it came into the database.
It was worth it. With a hundred missions in the database, the tracking that had got way too hard in Markdown became a lot easier. SQL is a structured language, and I finally had structured data to ask it about.
Inside the database
The schema ended up with 22 tables and one search index. You don't need all of them to understand the idea; they fall into four groups.
The work
| Table | What it holds |
|---|---|
missions | One row per mission: title, owner, priority, the next action and any blockers. Status (not started, in progress, blocked, complete) is kept apart from outcome (done or failed), so "finished" and "succeeded" are never confused. |
mission_steps | The steps of a mission: step, phase, agent, status and notes, one row each. |
flight_recorder | The audit log. Every state change is appended, with two times: when it happened and when it was written, so a back-dated entry shows up instead of hiding. |
crew | The registered agents, so the audit log can say which agent made each entry. |
What the crew learns
| Table | What it holds |
|---|---|
findings | The improvement ledger: what went wrong or could be better. An agent can propose a finding; only I can approve, apply or reject it. No agent tool can change its status. |
patterns | Advice the crew has noticed. Useful, but never binding. |
directives | The binding rules. Agents can read them; no agent can write one. |
service_records | Per-agent history: what each agent reported about itself, and what Bishop observed. |
Search
| Table | What it holds |
|---|---|
documents | Every Markdown and JSONL file imported from the harnesses, with a content hash so unchanged files are skipped on the next import. |
documents_fts | The FTS5 full-text index over those documents, with English stemming, so a search for "failing" also finds "failed". |
Added as the harness grew
- Triage:
harnesses,finding_categories,triage_runs,finding_triage,finding_groups,finding_recommendationsanddirective_proposals. Scheduled agents sort the findings, group the duplicates and draft recommendations. A drafted directive still waits for me. - Debriefs and grading:
mission_grades,mission_criteria,agent_mistakes,mission_deliverablesandmission_lessons. The tables in each mission's debrief, turned into rows, so I can ask which mistakes keep coming back.
Two settings matter more than any table. The database runs in WAL mode, so reading never blocks writing, and foreign keys are switched on, which SQLite leaves off by default.
Look across the tables and the same line keeps coming up: what an agent may write, and what only I may decide. That's the part I took furthest into Cairnbook.
What it taught me
bishop-memory worked. It still holds my history: missions, findings, directives and grades. But it was built for one harness, and it grew by adding what the next task needed. Some pieces were never finished: the plan was for the service to become the single source of truth, with the agents' local files rendered from it, and that renderer was deferred. The local files stayed in charge.
Three things carried straight into Cairnbook:
- The database was the easy part. SQLite needed some housekeeping, but it was never the hard problem. Deciding what an agent may write, and what only I may decide, was.
- Write the contract first.
bishop-memorygrew by adding what the next task needed. Cairnbook starts from a written contract and a test suite. - Say what isn't built. The renderer was planned and never arrived, and the local files stayed in charge. Cairnbook's roadmap shows what's done and what's still only planned.
It still worked when I decided to replace it. Why I rebuilt it instead of fixing it is the next part.
More in this series
- Next: Why I Rebuilt Bishop's Memory Instead of Fixing It, on Tuesday 19 January.
- The project: Cairnbook, with its roadmap.
- The code: cairnbook, and the service it replaces, bishop-memory.