The loop

Install Stoic, write a spec, hear it read back, lock it, hand it to an agent and verify the result. Four minutes, five verbs.

An agent that can change the code can change the tests too, so a suite can stay green and stop saying what you agreed. Stoic keeps what you agreed where no one can quietly change it: a small language for saying what software must do, and a toolchain that holds the code to it. You'll use five verbs, in a loop: write, read back, lock, build, verify. This page walks through all five on one real example. It takes about four minutes.

Install

Stoic is a single binary, written in Rust, for macOS, Linux and Windows, and you don't need Rust to install it. Nothing runs in the background and nothing phones home.

macOS & Linux

curl -LsSf https://stoic-lang.org/install.sh | sh

Windows

powershell -c "irm https://stoic-lang.org/install.ps1 | iex"

Homebrew

brew install stoic-lang/tap/stoic

Cargo

cargo install stoic-lang

These work once the first release is published. Until then, cargo install --git https://github.com/stoic-lang/stoic stoic-lang builds it from the repository.

Then stoic --version checks it is on your PATH. With Cargo, the crate is stoic-lang and the command stoic.

To start a project with an example spec, a CI workflow and a merge rule for the lock, run stoic init. To have your agent's tools refuse implementation code until its spec change is locked, and give them the skill that teaches the loop, run stoic gate --install all.

1. Write

Say what it must do. A spec is made of elements (things), fields (their properties and rules), events (triggers, with what they do in plain words) and tests. None of the words are keywords: method, fee and call are ours, not Stoic's.

fees.stoicStoic
<!--! Amounts are integer cents. A failed call changes nothing. -->
<method:fee
  @call="fee(amount): 8.75% of amount, rounded half to even"
  #amount(
    "an integer",
    ^"call fee(value)",
    >=1,
    +=500,
    -=0,
    -=1.5,
    +=>="{ ok: true }",
    -=>="{ ok: false, error: 'AMOUNT' }"
  )
/>
<test:fee600=fee @call="600" =>fee="52" =>"52.5 rounds to the even 52" />
The compiler reads it back

A method fee that does "fee(amount): 8.75% of amount, rounded half to even" on call. Note: Amounts are integer cents. A failed call changes nothing. Field amount must be at least 1, must match "an integer", accepts 500, and rejects 0 and 1.5. Each example is tried given call fee(value). Each accepted example reports exactly "{ ok: true }"; each rejected one, exactly "{ ok: false, error: 'AMOUNT' }". A quoted example is text; a bare one is that value.

A test fee600 of fee: on call with "600", expect fee exactly "52" (reported back and compared) and expect "52.5 rounds to the even 52".

Rules sit on the fields they constrain. +=500 and -=0 are examples, an accepted one and a rejected one, and each is a test. =>fee="52" is a checked value: the test must report what fee(600) really returned, and verify will compare it with 52.

2. Read back

Run the compiler on the file. It answers in English. Hover any name in the example above to see the sentence it became.

 stoic fees.stoic

This is the cheapest review you'll ever do. If the compiler misread you, you find out now, before any code exists. It also refuses specs that can't be right: limits that contradict each other, an example that breaks its own field's rule, a test that names a field that isn't there.

Stoic
<form:signup #username(>=3, +"ab", -"a b") />
The compiler refuses
error: example +"ab" breaks `username`'s rule `>= 3`
 --> <stdin>:1:14
  |
1 | <form:signup #username(>=3, +"ab", -"a b") />
  |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: nothing in `username`'s rules rejects "a b"; add a rule it breaks, or a quoted rule or note that explains why
 --> <stdin>:1:14
  |
1 | <form:signup #username(>=3, +"ab", -"a b") />
  |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: #username's accepted examples have nothing verify can compare; add +=>="…" (what an accepted example reports)
 --> <stdin>:1:14
  |
1 | <form:signup #username(>=3, +"ab", -"a b") />
  |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: #username's rejected examples have nothing verify can compare; add -=>="…" (what a rejected example reports)
 --> <stdin>:1:14
  |
1 | <form:signup #username(>=3, +"ab", -"a b") />
  |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

3. Lock

 stoic lock fees.stoic
locked 4 tests from 1 file(s) into stoic.lock

stoic.lock freezes every test and a hash of the spec. Commit it. From now on, a test can't be dropped, skipped or loosened without a diff someone has to review. Put the lock under code review (stoic init writes a CODEOWNERS example) and only a person can relax a promise.

4. Build

Hand the work to whoever builds it: you, someone on your team or an agent, in any language.

 stoic brief fees.stoic

The brief is the whole contract in one page: the spec in plain English, every test ID to implement, and the exact verify command. The tests record their results with a reporter Stoic prints for your language:

 stoic harness --lang node --out support/stoic-results.cjs
wrote support/stoic-results.cjs
// in a test:  observe('fee600', 'fee', fee(600).fee);   writes:  pass fee600 fee = 52

5. Verify

 stoic verify results.txt --run "npm test" --strict
pass     fee_amount_accepts_500
pass     fee_amount_rejects_0
pass     fee_amount_rejects_1_5
pass     fee600

verified: 4/4 locked tests passed (4 checked, 0 asserted only, 0 examples)

--run deletes the old results and runs your tests itself, so a stale or hand-written file can't count. Now imagine someone "simplifies" the rounding to Math.round. Every test still passes. Stoic doesn't need them to fail, because each one reports what it saw:

 stoic verify results.txt --run "npm test" --strict
pass     fee_amount_accepts_500
pass     fee_amount_rejects_0
pass     fee_amount_rejects_1_5
WRONG    fee600 fee: expected 52, observed 53

NOT verified: 3/4 locked tests passed (4 checked, 0 asserted only, 0 examples)
next: 1 WRONG above. Fix the code until every locked test runs under its ID, passes and reports the values it checks; don't edit a spec or the lock to make this pass.

The test passed, as far as it knew. But it reported what it saw, and the lock remembered what you said. That gap is the whole idea.

Where next

  • The glyphs: the seventeen marks that make up the language.
  • Tests: examples, checked values, givens, and why every rule needs a witness.
  • Lock and verify: every verdict, code no locked test runs, and how to gate CI with them.
  • Agents: briefs, the gate that keeps the spec first, the agent skill, disputes, owner review, and several agents on one codebase.

All 2 examples on this page were compiled by Stoic at build time.