Cortex / mcp
AGENTS.md1 starsChanged 2 months agoMITView on GitHub
An optional Node MCP server exposing Cortex over stdio, plus the ai-os CLI. The busiest part of the repo by commit count, and — like every other part — dependency-free. - No runtime dependencies, ever. A plugin install clones the repo and never runs npm install, so a declared dependency is simply absent on the user's machine. lib/stdio.js is the ~100-line MCP transport that replaced @modelcontextprotocol/sdk for exactly this reason. core/test/install.test.js fails the build if an import creeps back in.…
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository50 other files it gives its agents.
- AGENTS.mdAGENTS.md
- core/AGENTS.mdAGENTS.md
- index/AGENTS.mdAGENTS.md
- tools/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- analyze-specSkill
- auditSkill
- captureSkill
- catch-me-upSkill
- connect-brainSkill
- cortex-auditSkill
- cortex-briefSkill
- cortex-enrichSkill
- cortex-impactSkill
- cortex-installSkill
- cortex-nextSkill
- cortex-profileSkill
- cortex-reviewSkill
- cortex-scaffoldSkill
- cortexSkill
- cortex-skillsSkill
- cortex-viewSkill
- dailySkill
- diagnosing-bugsSkill
- domain-modelingSkill
- dreamSkill
- grillingSkill
- handoffSkill
- improve-codebase-architectureSkill
- install-projectSkill
- level-upSkill
- migrate-engineSkill
- onboardSkill
- optimize-contextSkill
- optimize-promptSkill
- plugin-syncSkill
- reindexSkill
- resolving-merge-conflictsSkill
- resumeSkill
- scan-projectsSkill
- setup-pluginsSkill
- shipSkill
- site-syncSkill
- skill-auditSkill
- skill-creatorSkill
- team-addSkill
- team-initSkill
- weekly-reviewSkill
- wizardSkill
- writing-for-agentsSkill
The file
We split this AGENTS.md into the rules it gives an agent
2 rules. About 0 are common, 0 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 21
server.jsstays a thin switch: All logic lives in lib/; the transport layer is a dispatch over tool names and nothing more. - Very specific: line 155
No install step — there is nothing to install.
≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
mcp/ — the live brain
An optional Node MCP server exposing Cortex over stdio, plus the ai-os CLI. The busiest part of
the repo by commit count, and — like every other part — dependency-free.
Invariants
- No runtime dependencies, ever. A plugin install clones the repo and never runs
npm install, so a declared dependency is simply absent on the user's machine.lib/stdio.jsis the ~100-line MCP transport that replaced@modelcontextprotocol/sdkfor exactly this reason.core/test/install.test.jsfails the build if an import creeps back in. See ADR 0004. - Only protocol messages go to stdout. A stray
console.logcorrupts the JSON-RPC stream and the client reports something unrelated. Diagnostics go to stderr. - Every tool result is capped in the transport, never per tool.
capResult()inlib/stdio.jsholds a result toMAX_RESULT_CHARS(40,000 — about 10k tokens, under 14k even at 3 characters per token) and replaces an oversized one with a parseable document markedtruncated: trueplus a hint to narrow the request. Claude Code cuts MCP output at 25,000 tokens by default;recall_memoryreturned 272,000 characters on a year of memory before this. Do not raise the cap to fit a tool — give the tool a way to return less. server.jsstays a thin switch. All logic lives inlib/; the transport layer is a dispatch over tool names and nothing more.- Two modes, decided by the root — never configured.
AI_OS_ROOTending in.cortexis repo mode (recall,remember,recall_memory); anything else is vault mode (the personal-brain tools). Detection keeps the plugin manifest to one env var and makes a misconfiguration visible as a changed tool list. - Vault tools are hidden and refused in repo mode. Offering
captureorcatch_me_upthere invites an agent to writeinbox/anddaily/into someone's product repository — and a client that already knows the name never readstools/list, so hiding is not refusing. Which mode a tool runs in is a field on its declaration inlib/tools.js;toolsFor()derives the advertised list andassertAvailable()derives the guard, so the two cannot disagree and a new tool cannot be added without saying where it runs.mode.test.jsasserts the exact list for both modes and that a vault tool invoked in repo mode comes back refused with nothing written. - A tool that returns someone else's text says so in its description.
recall,recall_memory,get_project_context,list_projectsandcatch_me_upall hand the model text written outside the conversation — a teammate's committed.cortex/memory/, a note in a shared vault — and the result itself carries nothing marking it as data rather than instruction, which is the standard prompt-injection path through a retrieval tool. The description is the one place the model reliably reads, soUNTRUSTED_NOTEinlib/tools.jsis stated once and interpolated, andreturns: FOREIGN | OWNis a field on the declaration next tomode.assertWellFormed()runs at import and refuses a row that skips the question or claimsFOREIGNwithout the sentence, so the next tool cannot ship unmarked. Do not add it torememberorcapture: they take input and hand back a path, and a warning on every tool is a warning on none. - A tool that publishes is gated by its declaration, not by its caller.
writes: LOCAL | PUBLISHEDis the third field on a row inlib/tools.js, andassertPublishable()inserver.js's dispatch appliescore/scrub.jsto thecontentof everyPUBLISHEDone — the same shape asmode/assertAvailable()beside it.rememberwas gated insidecore/memory.jsbecause.cortex/memory/is committed;captureon a team commits and pushes a note to a remote other people pull and was not, becauseassertWritablehad exactly one caller and being the second was a thing you had to remember. That is the shape ADR 0007 rejected for path safety.assertWellFormed()refuses a row that omitswrites, and aPUBLISHEDrow that does not take its payload incontent— otherwise the gate reads a field that is not the one being written. A personal, non-team capture is gated too: where a capture lands is decided at runtime by a connector found by walking up from the cwd, so the call site cannot know whether it publishes, and a gate conditional on that is off exactly when nobody can see that it is off.tools.test.jsdrives the property off the table andmode.test.jsproves it over a spawned server — the unit test alone passes happily when the dispatch never calls it. The refusal stays incore/scrub.js: it refuses rather than sanitises and names only the kind. AI_OS_ROOTunset is a hard exit, not a default. Guessing a vault path would write someone's notes into the wrong place.lib/resolve.jsupholds this — it throwsNoRootErrorrather than falling back, and the three-mode spec's fallback chain was rejected on exactly these grounds (ADR 0008). One CLI command degrades instead:ai-os catch-up. It writes nothing, and with no root it reads only the git repository the cwd sits in — that repo's committed.cortex/memory/and its log — never a vault, and says inskippedwhich half it did not read. That is what a plugin install has: no vault, only the repo it was opened in, and/catch-me-upfailed on its first command there. It does not open a brain with an inferred root; it opens none (open(…, { rootOptional })inai-os.js), so nothing downstream can mistake the repo for a place to write.openBrainresolves the profile before the root for this reason — a misspeltCORTEX_PROFILEstill fails at entry. A second command wanting the same exemption must also write nothing; anything that writes stays a hard exit.capture'steamargument is an override, not the switch. The team comes fromlib/resolve.js— a repo with a.cortex/connector.jsonwrites to the team brain without the caller knowing it is on a team. Requiring the agent to passteamwas the seam leaking. Do not reintroduce it as a required argument.- The connector names the team and the project in two fields:
{ team, project, teamBrainRepo }. It used to be{ slug, teamBrainRepo }, withteam addwriting the project intoslugand the resolver reading it as the team, so every connected repo captured intoteam/<project>/, a directory that was not a clone. Old connectors are still read (legacyTeaminresolve.jsmatches the clone by itsorigin); do not reintroduce a field that means two things. catch_me_uppulls (ff-only) and reads the team's notes, not only its log. A failed pull is returned inpull, never swallowed, and the local notes still come back; team notes are bounded incatchup.jsso the result fits under the transport cap rather than being cut by it.- Every vault path goes through
lib/vault.js— not throughresolveInRootdirectly. The Vault is the only module here that joins onto a vault root or callsnode:fson one; it wrapscore/paths.jsso the guard is unavoidable rather than remembered. If you need an operation it does not have, add it to the Vault — do not reach around it. The full surface islist·entries·read·append·write·abs·exists·isFile·isDirectory·mtimeMs, all taking root-relative paths.test/vault-is-the-only-door.test.jsfails the build otherwise, and it checks twice: a scan forjoin(root, …), plus an assertion that the converted modules import nonode:fsat all — becauserecallonce bypassed the guard through a closure variable without ever writing that call, so the scan alone was blind to it. The three allowlisted files join onto the install directory or a git clone, never a vault. The Vault does not scrub: secret refusal is policy and stays incore/scrub.js, so do not add filtering here. ADR 0007. modeandaudienceare different questions.lib/mode.jsanswers what kind of brain this root is (repo vs vault);lib/resolve.jsanswers who it serves (solo · team · server). They are orthogonal — a repo-mode brain can run on a server, a vault-mode brain can belong to a team. Solo and team are detected from a.cortex/connector.jsonfound by walking up from the cwd; server is declared withCORTEX_AUDIENCE=server, because it leaves no filesystem trace and declaring beats detecting.core/profile.jsanswers a third question (home · work · lab) and reads onlyCORTEX_PROFILE— nothing here may move it.- Every adapter opens the brain at entry, through
lib/brain.js.server.jsandai-os.jsare two adapters over the same operations, so the seam between them is real and therefore a module:openBrain({ cwd, env })returnsroot · mode · isRepo · audience · team · teamClone · project · profile · policy · sources · describe(), and throwsNoRootError/UnknownProfileErrorbefore a command picks a branch. Neither adapter may readenv.AI_OS_ROOTor callresolve.js,mode.jsorcore/profile.jsitself —brain.test.jsscans both for that, because the way this rule broke was a second adapter re-deriving the answer by hand:ai-os catch-upread the root raw and passedargs.teamalone, so inside a repo with a.cortex/connector.jsonit consulted no connector, reached no team clone, and printedcommits: []as a success. That is thecaptureinvariant below, arriving through the other door.ai-os.jsresolving the profile insideteam initonly is the same shape:team addtook a typo ashomewhile the server exited on it. The record composes three answers and never merges the three questions — mode from the root string, audience from the connector orCORTEX_AUDIENCE, profile fromCORTEX_PROFILEalone. Three fields, never one enum; ADR 0008 and ADR 0015 stand unchanged. A command that reads no brain (digest,setup-plugins) does not open one — demanding a root there would be a new requirement wearing a fix's clothes. Skills reach the CLI asnode "${CLAUDE_PLUGIN_ROOT}/mcp/ai-os.js", never<vault>/mcp/…: a plugin install has no vault checkout, andtest/rituals-on-a-plugin-install.test.jsruns each command as its SKILL.md prints it, from a copy laid out like the plugin cache. - Every path that publishes must consult
policy.outwardSync— including the CLI.labexists to be permissive locally because it is sealed outward, so the seal is the load-bearing half;core/profile.jscalls alabthat still pushes "the leak with extra steps". For a while that is whatinitTeamBrainwas:capture()honoured the policy and the team-brain push did not, andai-os.jsimportedcore/profile.jsnowhere, so a misspeltCORTEX_PROFILEwas a hard exit in the server and a silent default in the CLI. Both adapters now take the policy off the recordlib/brain.jsopens at entry, which is where the profile is resolved once. A new publish path that does not is the same bug again — write locally, decline the push, and tell the caller which, the waycapture()does. mcp/never imports fromindex/.
Gotchas
lib/cortexignore.jsis a faithful port ofknowledge_files()intools/_cortex-lib.sh. The two must agree; CI diffs them incortex-init-test.yml. Change one, change both. It is also pure — it decides what the patterns mean and never reads a file; the Vault fetches the text and passes it in. The dependency only runs one way:vault.jsimports it, never the reverse.test/manifest-parity.test.jsguards a deliberate duplication:tools/cortex-init.shhardcodesCORE_PLUGINSto stay jq-free, and this test is the only thing preventing drift fromplugins/cortex-core-plugins.json.lib/gitsync.jsusesexecFileSyncwith an argument array, never a shell string, so slugged project and team names cannot inject. Keep it that way.lib/version.jsreads the repo-rootVERSIONfile. It exists becauseserver.js,package.jsonand the docs actually drifted apart once between 1.0.0 and 1.1.0.- Path handling carries Windows-specific cases; this is the primary dev platform, and CI has a Windows leg for exactly that reason.
Tests
cd mcp && npm testNo install step — there is nothing to install. smoke.test.js and mode.test.js spawn the real
server over stdio; if they time out, read the captured stderr in the failure message before
assuming a test bug. stdio.test.js drives the transport over in-memory streams instead, so the
protocol edges (notifications, framing, parse errors) are pinned without spawning anything.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

