Agents

Briefs, roles, the gate that keeps the spec first, the agent skill, reporters, disputes, owner review and several agents on one codebase. How Stoic turns an AI coding agent's judgement into a contract the toolchain checks.

Most ways of directing an AI agent are prose: a prompt, a README, a requirements document. Prose is read, and then it's over. Nothing in it can refuse a change, and nothing notices when the code and the words drift apart. A spec that is locked and verified does both, on every change, by every hand.

So Stoic asks less of the agent's judgement and more of the toolchain. That's also why it suits cheap models: a small model doesn't have to guess what you meant, only meet a contract that is checked for it.

The brief

 stoic brief spec/

The brief is the whole job in one page: the spec read back in English, every test ID to implement (copied, never derived), how to report results, and the exact verify command, --against included when there's a git remote. Paste it into any agent, or point the agent at the command.

Its rules are short and the toolchain backs every one:

  1. Implement the spec.
  2. Implement every listed test, in the project's language.
  3. Have the tests record their results, never by hand.
  4. Report checked values: what the code really produced.
  5. stoic verify must pass.
  6. Never edit .stoic files or stoic.lock. If a test looks wrong, dispute it.

Roles

--role owner writes a brief for an agent that owns the spec and changes it first: edit the spec, stoic check, relock, then implement. Every relock lists each changed value, so a human reviewing the owner's diff sees exactly which promises moved.

 stoic brief spec/ --role owner

Spec first, as the agent writes

"Change the spec first" is a rule in a brief, and an agent in a hurry skips it. stoic gate enforces the order at the moment a file is written. Specs, the lock, tests, docs and hidden files may always be written. Implementation code waits until this ticket's spec change compiles and is locked:

 stoic gate src/fees.js
deny   src/fees.js: implementation code (stoic.code lists it), but the spec hasn't changed since the last ticket commit (29dd860) and no locked test fails in results.txt
next: spec first: write this ticket's change in the spec, review it with stoic check spec and relock with stoic lock spec; if the code must change to meet the spec as it is, run the tests so results.txt shows the failing locked test; if nothing it does changes, stoic gate --refactor "WHY".

A refusal exits with 2 and names one next step. There are three ways forward, so real work never deadlocks: lock this ticket's spec change; run the tests, so a failing locked test shows the code is being brought to a spec that didn't change, as in a bug fix; or declare a ticket that changes no behaviour with stoic gate --refactor "WHY", committed so the review sees the claim. Here the spec gained a minimum fee, was checked and relocked:

 stoic gate src/fees.js
allow  src/fees.js: implementation code (stoic.code lists it), and the spec changed since the last ticket commit (29dd860) and is locked

What counts as implementation code is declared in stoic.code beside the lock, one glob per line from the project root (src/**). Without it, it's every file but specs, tests, docs, hidden files and what git ignores.

The agent's tools ask the gate themselves. stoic gate --install writes each tool's project config, so it runs stoic gate --hook before every file write and shows the refusal to the model:

 stoic gate --install all
created    .claude/settings.json
created    .codex/hooks.json (Codex runs it once you trust it: /hooks in Codex)
created    .gemini/settings.json
created    .factory/hooks.json
created    AGENTS.md
created    .claude/skills/stoic/
created    .agents/skills/stoic/
created    .kiro/skills/stoic/

That is Claude Code, Codex, Gemini CLI and Factory Droid, an AGENTS.md section that states the rule and the loop, and the agent skill (below). stoic gate --install git adds a pre-commit hook that checks what's staged. For a tool Stoic has no hook for, the AGENTS.md section and git's hook are the gate, and CI behind them. An existing config keeps its keys, and an existing pre-commit hook is never replaced: you get the line to add to it.

The gate checks timing, not intent. A hook sees file-writing tools, not what a shell command writes, and an agent can hand-write a fail line or a refactor declaration to get through. Both are visible. It catches an agent that forgot the order, not one set on evading it; that stays the job of stoic verify --against in CI.

The agent skill

An agent new to Stoic has to learn it before it can follow the loop. stoic gate --install skill writes an Agent Skill that teaches the loop instead, into .claude/skills/, .agents/skills/ and .kiro/skills/, the folders the common agent tools read. A tool lists only the skill's name and description, and reads the rest when a task needs it: the loop, a test that checks a value, how to read verify's next: line, the gate's three ways forward, disputes and owners. Its rules are the brief's, word for word, so the skill and the toolchain can't disagree. For any other tool, stoic guide --skill prints it.

The skill is guidance. The gate, verify and CI are what enforce.

Reporters

stoic harness prints a reporter in the tests' language that writes results in Stoic's value notation, and refuses any value it can't write faithfully (undefined, NaN, a Date) rather than writing a lossy line.

 stoic harness --lang node --out support/stoic-results.cjs
wrote support/stoic-results.cjs
 stoic harness --lang python --out support/stoic_results.py
wrote support/stoic_results.py
 stoic harness --lang sh --out support/stoic-results.sh
wrote support/stoic-results.sh
const { observe, failed, dispute } = require('../support/stoic-results.cjs');
observe('fee600', 'fee', fee(600).fee);  // pass fee600 fee = 52

Each line is appended in one write, so tests in parallel processes can share the file. A reporter writes to results.txt, or to $STOIC_RESULTS when it's set, and stoic verify --run sets it to the results file you named, so stoic verify results-a.txt --run "npm test" finds its results wherever the tests ran. Keep the reporter outside your test runner's glob (node --test picks up any file under test/), which is why these examples use support/; --out creates the folder if it's missing.

Disputes: a legitimate way to object

An agent that finds a locked test wrong has two bad options in most setups: weaken the test, or silently skip it. Stoic gives it a third. The test records a dispute:

dispute fee600: the ticket says Math.round; the spec says half to even

Verify lists disputes first and fails until the test's owner settles them: by changing the spec, by taking the value the test observed, or by telling the agent it's wrong (owner review, below). A dispute about a value can carry the value: report pass ID = VALUE beside dispute ID: why. The objection is on the record instead of in the code.

Many agents, one truth

Several agents on different parts of one system is where specs usually fall apart: one agent relocks another's half-finished edit, a failing test doesn't say whose it is, and two branches' locks collide. Stoic borrows from databases and operating systems.

Segments say who owns what. A stoic.segments file beside the lock gives each part of the spec an owner:

# segment @owner: top-level elements (nested ones follow their parent)
billing @agent-a: invoice money tax
cart @agent-b:    cart cart_item checkout

A test belongs to the segment of what it tests, whichever file it's written in, and rebinding it to something else changes both segments: moving a test out of an owned segment still needs that segment's owner. A stoic.segments with a problem (an element in two segments, a name no spec defines) stops every relock until it's fixed, so a broken file never gates less than a sound one. From then on, every failing line of stoic verify ends with (segment billing), and an agent that passes --as its name sees its own tests counted apart from everyone else's, with a reminder not to touch a failing test that isn't its own.

Only the owner relocks a segment. stoic lock spec --as agent-b recomputes agent-b's segments and what nobody owns, and copies everything else from the lock as it is. A relock that would change what another agent holds writes nothing, and says whom to ask. Here an engineer has edited a refund rule the product owner holds:

 stoic lock spec --lock spec/stoic.lock --as engineer
error: this relock, as engineer, changes what others own, so nothing was locked:
  ~ refund (segment rules, owned by product): its definition changed (rules.stoic:2)
  ~ test `refund_window` (segment rules, owned by product): changed (rules.stoic:3)
  ~ test `refund_late` (segment rules, owned by product): what it tests changed (rules.stoic:4)
this changes rules, owned by product: ask product (or report each test as `dispute ID: why`); don't relock it as someone else

Claims hand a segment over for a while. stoic claim billing --as agent-a records a claim on a stoic-claims branch, stored by compare-and-swap, so of two agents claiming at once, one wins and the other is told who holds it. Each claim carries a fencing token that only ever rises. A relock stamps its token into the lock, and if the claim has since been taken over (--take-over, once it expires) or released, stoic verify --against origin/main refuses the old branch as STALE. A change no claim or owner covers is SCOPE. A clock can only allow a takeover; it never decides what verifies.

 stoic claim billing --as agent-a --ttl 2h
 stoic lock spec --as agent-a
 stoic brief spec/ --as agent-a          # adds: the elements agent-a owns, and what it must not change
 stoic release billing --as agent-a

Locks merge by key. stoic merge-lock --install sets up a git merge driver that merges two branches' locks entry by entry, files by path, definitions by name, tests by ID, and stops on any entry both sides changed differently.

And underneath: each relock holds an OS file lock for milliseconds, so agents sharing one lock queue rather than collide; each name is defined once per lock; and --against origin/main checks every branch against the lock that was reviewed. Run each agent in its own worktree, with its own results file.

Owner review

Sometimes the ticket really does reach into what an owner holds: a new key changes the shape an owned test pins, say. The implementer can't relock that, so it reports a dispute or leaves the WRONG line, and the work waits for the owner. stoic review --as OWNER lists what waits in that owner's segments, and nothing outside them: changes only that owner may relock (CHANGE), the values they move, disputes, and owned tests that passed with other values. Its last line says what to do:

 stoic review results.txt --lock spec/stoic.lock --as product
WRONG    team_plan: expected { name: 'team', seats: 5 }, observed { name: 'team', seats: 5, trial: false } (at .trial)  (rules.stoic:2)
next: 1 WRONG above, in product's segments. Decide as product, running stoic review results.txt --lock spec/stoic.lock --as product with: --accept-observed team_plan to take the observed values into the spec and relock; --reject to say what stands and what to revert.

The owner settles it in one step. --accept-observed team_plan writes the observed value into the spec, changes nothing else in the file, and relocks as the owner:

 stoic review results.txt --lock spec/stoic.lock --as product --accept-observed team_plan
accepted team_plan: { name: 'team', seats: 5 } -> { name: 'team', seats: 5, trial: false } (rules.stoic:2)
locked 2 tests from 2 file(s) into spec/stoic.lock
  ~ team_plan  test of `plan`: given nothing; on call with "'ada'"; expect exactly "{ name: 'team', seats: 5, trial: false }" (reported back and compared)
  value team_plan: { name: 'team', seats: 5 } -> { name: 'team', seats: 5, trial: false } (spec/rules.stoic:2)
  tests: 1 changed, 0 only through their target, 0 added, 0 removed
relocked segment rules as product; every other entry is copied from spec/stoic.lock
next: approved as product; rerun the tests, then stoic verify results.txt --lock spec/stoic.lock.

--approve relocks the pending changes as they stand, exactly as stoic lock --as product would. --reject writes nothing and tells the implementer what to put back (REVERT) and which tests stand (KEEP). Accepting a value never quietly approves an edit to the rule beside it: with other changes pending, --accept-observed refuses unless --approve is given too. Like --as everywhere, the owner is a name, not a login, so CODEOWNERS on the specs and the lock still decide who may push the result.

A prompt that works

For an agent that has never seen Stoic, and has no skill installed, this is enough:

This project uses Stoic. Run `stoic brief spec/` (add `--as <your name>`
if there is a stoic.segments file) and follow it exactly. Don't edit .stoic
files or stoic.lock. When you're done, run the verify command at the end of
the brief and include its output in your report.

In your editor

stoic lsp is a language server: diagnostics as you type, hover that explains what is under the cursor, completion and go-to-definition, with the same compiler underneath. It takes each edit as it's made rather than the whole file, counts columns the way your editor does (UTF-8 bytes or UTF-16 units), checks a burst of edits once, and skips a request the editor cancelled while it waited. Formatting is stoic fmt, which puts a field too wide for its line one part per line. The repository ships a VS Code extension (no Marketplace listing yet: build it from editors/vscode and install the .vsix), a Neovim setup and a tree-sitter grammar. In both editors .stoic files get the Stoic mark as their icon (in Neovim, through nvim-web-devicons or mini.icons).