Capsid
Shared memory, the job queue and the GitHub access that every other project's agents work through.
- Ring
- Runs everything
- Kind
- system
- Address
- mcp.dustinedwards.info
- Source
- DrDustinEdwards/
capsid - Visibility
- Public
- Parts
- 9
- Connections
- 17
- Write-up
- Capsid on dustinedwards.info
How it connects
Used by 3
- Carrel writes to
- capsid-bench writes to
- Capsid backups reads
Inside Capsid
Runs
MCP Worker
Cloudflare Worker
MCP Worker Serves MCP, the operator routes, /health and the Portal's API. writes to capsid writes to capsid-media writes to capsid-mcp-tool-calls writes to app KV writes to OAuth KV serves Portal serves Agents writes to GitHub reads GitHub reads Search index reads capsidPortal
React, served by the Worker
Portal The admin view, behind Cloudflare Access.Five-minute tick
Workers cron trigger
Five-minute tick Auto-merge, the watcher and the daily passes. reads GitHub writes to GitHub writes to capsid writes to app KV writes to Search index
Stores
capsid
D1 with FTS5
capsid Documents, jobs, agents and the audit log.Search index
Cloudflare AI Search
Search index A meaning index of every document, derived from D1 and rebuildable from it. D1 stays the record.capsid-media
R2
capsid-media Media and the daily backups.capsid-mcp-tool-calls
R2
capsid-mcp-tool-calls Copies of the tool-call log, kept a year under a lock rule after the log prunes them.app KV
Workers KV
app KV Caches, rate-limit counters and computed documents.OAuth KV
Workers KV
OAuth KV The OAuth provider's grants and tokens, kept apart from the app KV.
Outside
Agents
Coding sessions over MCP
Agents The sessions that post, claim and work jobs.GitHub
Repos, pull requests, Actions
GitHub Where the code, the pull requests and CI live. Capsid reaches it through its GitHub App. deploys MCP Worker watches MCP Worker
Uses 14
- d1-dump installs
- devkit installs
- site-runtime installs
- Capsomer installs, coordinates
- Germomics coordinates
- dustinedwards.info coordinates
- TXASM coordinates
- julieedwards.info coordinates
- Foxing coordinates
- Foxhound coordinates
- Carrel coordinates
- Enarratio coordinates, installs
- Skills coordinates
- capsid-bench coordinates
Step by step
A job's life
One job, from the moment a session posts it to the moment Capsid checks the agent's claims against GitHub.
- Posted: a session posts a job over MCP. The Worker checks that the caller may post, picks a model, signs the job and stores it.
- Claimed: an agent claims the job. The Worker checks the signature first, then records which agent holds it.
- Worked: the agent works on one branch of one repo.
- Blocked: before a push, a deploy, a secret or a merge, the agent stops. The job waits with the exact command until a person or the signed policy approves it, and resume hands it back.
- Pull request: the agent opens a pull request through Capsid's GitHub App, and CI runs on it.
- Merged: every five minutes, Capsid merges a pull request when CI passed on its latest commit and the signed auto-merge policy allows it. The session that opened it can also merge it once CI passes.
- Deployed: the merge to master starts CI on GitHub Actions, which deploys the Worker.
- Verified: CI reads the Worker's /health page and checks that it reports the merged commit.
- Claims checked: when the job finishes, the Worker reads the pull request, its commits and CI from GitHub, and saves each claim next to what GitHub says.
A search
One question to the knowledge base, searched by keyword and by meaning. Capsid checks every match against the database before it shows it.
- Asked: an agent calls Find documents with a question. The Worker checks that the agent has read access and which namespaces it may see.
- By keyword: the Worker runs the question through SQLite's full-text search on D1 and ranks the matches with bm25.
- By meaning: the same question goes to the AI Search index, which finds documents that use different words for the same idea.
- Re-checked: the Worker rereads every meaning match from D1, so it never serves a moved or deleted document. It leaves out closed and replaced documents unless the agent asks for them.
- Answered: the agent gets one list, core documents first, each marked keyword, meaning or both. If the index fails, the agent still gets the keyword results and the reason.
- Kept fresh: every five minutes, Capsid sends the index up to 100 documents changed since its last pass. A daily pass removes documents D1 no longer has.
A session starts
How a coding session picks up where the last one stopped: it starts from the project's notes and writes back what it decides.
- Started: a coding session calls Start a session with its project's namespace.
- Gathered: the Worker reads the shared rules, the project's core.md, the decisions and rulings, the open tasks and the three latest session notes, each with the date it last changed.
- Handed over: the session gets one answer of about 40 KB. If the notes run over, the answer names what it cut.
- Written back: the session saves what it decides with Write a document. Capsid keeps the old version and logs who made the change.
- Guarded: when anyone but the admin or an agent allowed to merge edits the rules, a core.md or the decisions, Capsid holds the edit as a proposal until someone approves it.
- Remembered: the next session, on any machine, starts from the same notes.
The nightly backup
Once a day the Worker copies the whole store to R2, keeps daily, weekly and monthly copies, and trims old history only after a copy holds it. A watcher checks that the copy outside the account is fresh.
- Dumped: at 09:00 UTC, a cron job in the Worker uses d1-dump to write every table to R2, one JSON file per table, plus the schema.
- Marked complete: the Worker writes a completion marker last, and only when the dumped tables match the ones the migrations create. A run without the marker never counts as a backup.
- Mirrored: the Worker also writes every document as a plain Markdown file beside the dump.
- Pruned: the Worker keeps the newest complete run from each of the last 14 days, 8 weeks and 6 months and deletes every other run. It never deletes the newest complete run.
- Trimmed: after the dump, the Worker deletes document versions older than 90 days and audit rows older than 180, so every deleted row is in a kept copy.
- Stamped: the run records its success, and /health warns once that record is more than 26 hours old.
- Watched: every half hour, the watcher reads the newest copy stored outside the Cloudflare account and files a finding once it is more than 36 hours old.
Flows through it
- A job's life, in 9 steps: One job, from the moment a session posts it to the moment Capsid checks the agent's claims against GitHub.
- A search, in 6 steps: One question to the knowledge base, searched by keyword and by meaning. Capsid checks every match against the database before it shows it.
- A session starts, in 6 steps: How a coding session picks up where the last one stopped: it starts from the project's notes and writes back what it decides.
- The nightly backup, in 7 steps: Once a day the Worker copies the whole store to R2, keeps daily, weekly and monthly copies, and trims old history only after a copy holds it. A watcher checks that the copy outside the account is fresh.
Its riskiest functions
| Function | Module | Complexity | Covered | CRAP |
|---|---|---|---|---|
performJobAction | src/controls-perform-jobs.ts | 56 | 1% | CriticalCRAP 3126.6 |
performSiteAction | src/controls-perform-sites.ts | 50 | 1% | CriticalCRAP 2505.3 |
performAction | src/controls-perform.ts | 98 | 60% | CriticalCRAP 736 |
recordOutcomeReverts | src/merge-reverts.ts | 26 | 1% | CriticalCRAP 679.9 |
handleBenchStart | src/bench.ts | 23 | 1% | CriticalCRAP 537.9 |