agentleFS
marinvchmarinvch/Cortex/tools/AGENTS.md

Cortex / tools

AGENTS.md1 starsChanged 2 months agoMITView on GitHub

Read docs/changing-cortex.md first; it holds the invariants that apply to every package. This file owns what is specific to tools/. These are the scripts a person runs, not the ones a ritual imports. core/, index/ and mcp/ are the product; this is the maintenance shelf around it — installers, the viewer generator, the version stamper, the checks that keep the repo honest about itself. Nothing here is imported by the product, which is why core/test/architecture.test.js does not walk this directory.…

  • Deletes or force-pushes

The file

We split this AGENTS.md into the rules it gives an agent

3 rules. About 0 are common, 0 are distinctive, and 3 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.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Read docs/changing-cortex.md first.

    line 3
  2. Very specific:

    .sh: when a *user* runs it on a machine that may not have Node.

    line 14
  3. Very specific:

    .mjs: when the script reads structured state the product already models — the version sites, the capability floors, the profile policy.

    line 16

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

tools/ — the scripts around the product

Read docs/changing-cortex.md first; it holds the invariants that apply to every package. This file owns what is specific to tools/.

These are the scripts a person runs, not the ones a ritual imports. core/, index/ and mcp/ are the product; this is the maintenance shelf around it — installers, the viewer generator, the version stamper, the checks that keep the repo honest about itself. Nothing here is imported by the product, which is why core/test/architecture.test.js does not walk this directory. That freedom is the reason the rules below have to be written down: the layering test will not catch a mistake here.

.sh or .mjs — decided by the reader, not by taste

  • .sh when a user runs it on a machine that may not have Node. cortex-init.sh is curl-pipeable into any repo; that is the whole reason it exists in bash.
  • .mjs when the script reads structured state the product already models — the version sites, the capability floors, the profile policy. It imports that model instead of re-deriving it. cortex-preflight.mjs is the clearest case: reimplementing core/profile.js in bash would be a fourth copy of the firewall rule.

Importing from core/ is fine and expected. Importing from index/ or mcp/ is a smell — it means a tool is reaching into a leaf, and the shared piece probably belongs in core/.

Two tools run from inside a target repo, not this one. cortex-preflight.mjs and cortex-placeholders.mjs are called by rituals as ${CLAUDE_PLUGIN_ROOT}/tools/... with the target as cwd. Anything they read from Cortex (templates) or print as a command resolves from import.meta.url, never from cwd. Preflight used to print node index/cortex-index.mjs ., a path that does not exist in the repo it was printed to.

The copies that are deliberate, and the tests that pin them

Four rules exist in more than one place on purpose, because the files needing them cannot share code. cortex-init.sh is a zero-dependency installer copied into other repos and parses no JSON. tools/server/cortex-cron.sh lands on a server beside only server-setup.sh. The viewer's slug runs in a browser. Each hook template is stamped alone into a repo that has no library to source.

RuleCopiesPinned by
the slugmcp/lib/slug.js (canonical), _cortex-lib.sh, cortex-init.sh, the browser-side slug() in cortex.shmcp/test/slug-parity.test.js
the clock_cortex-lib.sh, cortex-init.sh, cortex-cron.shtools/test/date-parity.test.sh
the Core plugin tierCORE_PLUGINS in cortex-init.sh, plugins/cortex-core-plugins.jsonmcp/test/manifest-parity.test.js
the hook-input readertemplates/loop/protected-paths.sh, templates/loop/format-changed.sh, templates/team/test-paths.shtools/test/test-paths.test.sh

Never "improve" one copy alone. The parity test is what makes the duplication safe; without it these drift into two behaviours nobody can tell apart. A new shared helper goes in _cortex-lib.sh and is sourced. A copy with no parity test is not a pattern, it is the failure the parity tests were written about.

A destructive tool routes its target through resolve_in_root

_cortex-lib.sh holds it — the shell counterpart of core/paths.js. Not a string-prefix check: a symlink out of the root passes any prefix comparison and is still an escape. ADR 0010.

destructive-guard.test.sh asserts that over every script here, not over the one the ADR was written about. cortex-sync-skills.sh did rm -rf "${DST:?}/$name" and never sourced the lib; the :? proves the variable is non-empty and resolves nothing, so with .claude/skills pointing out of the repo the loop deleted a directory outside the root and copied canonical into the hole. The test counts a move as destructive too — ADR 0010's original finding was a mv, and a scan watching only rm would have missed the case the rule was written about.

A tool whose deletions cannot take a caller-supplied path opts out in its own header:

# cortex:no-root-guard — <why no path here needs resolving>

The reason is the point, and the test requires one. Four scripts carry it today and each argues a different case (the lib defines the guard; cortex.sh deletes its own mktemp -d; scan-projects deletes $VAULT/projects/$slug.md where slugify() cannot emit a /; vault-extract walks two fixed in-file lists). That last claim used to live in a plan document from 2026-08-18, where no reader of the script would ever find it. A marker on a file that has stopped deleting anything is a failure too — a blanket permission nobody re-reads, the same rule dormant-exemptions.test.sh applies to the secrets marker.

Tests: behaviour, not syntax

bash tools/test/run.sh (add <filter> for one file). Add a case when you touch anything here. bash -n and shellcheck never run a script, which is how four real bugs shipped in tools/server/. Tests build real git repos in temp dirs — a bare repo on disk is a complete remote, so no network.

Four assertions in _helpers.sh, deliberately. A test framework that grows features is a dependency by another name; if a test wants a fifth helper, it is usually the test that wants simplifying.

Every fragment runs under pipefail, set by run.sh where the fragment cannot see it — so nothing pipes into grep -q. grep -q exits at its first match; a writer still flushing takes SIGPIPE, and the pipeline reports 141 for a match that is there. It depends on the scheduler, which is how destructive-guard.test.sh failed once on CI for a file nobody touched (#433). Write grep -q PAT <<<"$(producer)". pipefail-grep.test.sh holds every fragment and every tool that sets pipefail to it.

A *.test.sh file is a fragment run.sh sources, not a script — and it refuses to run alone. The runner exports $WORK and $REPO_ROOT and cds into a fresh temp dir. Standalone, both are empty: cd "$WORK/proj" becomes cd "", which fails without stopping the script, so the git init, the > README.md and the git add -A && git commit after it run against the repository you are in. That is not a hypothetical — on 2026-09-05 bash tools/test/cortex-view.test.sh, typed in exactly the form the briefs above print, put two fixture commits on master, replaced README.md with # readme and rewrote the git identity, all while reporting nothing. So the gate is the first thing in _helpers.sh, every fragment sources it as its first line of code, and every cd carries || exit 1. fragment-guard.test.sh runs every fragment the wrong way on purpose, in a throwaway git repo, and asserts the tree is untouched — plus that a fragment written tomorrow cannot skip the line, which under the runner would otherwise be invisible.

Every test touching the home directory must override the variable the platform actually reads. os.homedir() answers USERPROFILE on Windows and HOME elsewhere, so a fixture that sets only HOME leaves a Windows run reading the developer's real machine — and passing for the wrong reason. plugin-check.test.sh sets both, through one as_home() helper, and hands node a native path because node resolves a bare /tmp/... against the current drive on Windows.

The self-checks, and why each one exists

Each of these guards a failure with no error state — the repo keeps working while quietly lying about itself, so nothing surfaces until a reader is misled.

RunFails when
cortex-version.mjs --checkthe seven version sites disagree. Never hand-edit one; --set writes them all
cortex-capability.mjsa ritual declares no capability floor
cortex-frontmatter.mjs --checka ritual's frontmatter is not flat key: value — the one exception is a metadata: map holding only capability and reached-by — lacks name/description, or holds a value YAML would misread — a block-scalar description parses to | and the skill is never suggested. Strict, with no warn mode. The one frontmatter parser here; cortex-capability.mjs and cortex-skill-graph.mjs import it
cortex-skill-graph.mjs --checka ritual has no edges at all, in either direction, and declares no metadata: reached-by:
test/cortex-follows-its-own-rules.test.shthe claude-setup/ findings Cortex reports on other repos find anything in this one. Fix the repo, not the checker
cortex-skill-usage.mjs --unused(reports, does not fail) which skills the session record shows nobody ever reached
cortex-plugin-check.mjs --checkthe running plugin is behind the repo, so a correct fix looks broken
cortex-sync-skills.sh --checkthe gitignored .claude/skills/ mirror has drifted from skills/

The graph check cannot see a front door. It fails only on out.length === 0 && in.length === 0 (cortex-skill-graph.mjs:110), so a ritual keeps passing however thoroughly its inbound edges are stripped — one outbound edge is enough. Keep that &&: a router like /cortex-next is nearly all outbound and a shared discipline like /writing-for-agents nearly all inbound, so failing on a low inbound count would force exactly the decorative "see also" edges that make a graph look healthier than it is. The consequence is worth stating plainly, because the surrounding prose implies more: the check proves a ritual is wired to something, not that anything leads to it. It catches total disconnection, which is real and worth catching, and nothing short of it.

Inbound edges are also not equal, and counting them hides that. /connect-brain and /migrate-engine have one each — from /setup-plugins and /install-project, both causally correct, and both from rituals the session record shows at 0/0. A door behind a door nobody opens. cortex-skill-usage.mjs is the instrument for that half; no static graph can answer it.

A tool added here that answers a question about the repo should get a --check mode and a test. The report is the point; the exit code is what lets CI or a ritual act on it.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.