# The loop 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 and Linux: `curl -LsSf https://stoic-lang.org/install.sh | sh` - Windows, in PowerShell: `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. ```stoic title=fees.stoic =1, +=500, -=0, -=1.5, +=>="{ ok: true }", -=>="{ ok: false, error: 'AMOUNT' }" ) /> fee="52" =>"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. ```sh $ 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 error =3, +"ab", -"a b") /> ``` ## 3. Lock ```sh $ 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. ```sh $ 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: ```sh $ stoic harness --lang node --out support/stoic-results.cjs wrote support/stoic-results.cjs ``` ```text // in a test: observe('fee600', 'fee', fee(600).fee); writes: pass fee600 fee = 52 ``` ## 5. Verify ```sh $ 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: ```sh $ 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](/docs/glyphs/): the seventeen marks that make up the language. - [Tests](/docs/tests/): examples, checked values, givens, and why every rule needs a witness. - [Lock and verify](/docs/lock-and-verify/): every verdict, code no locked test runs, and how to gate CI with them. - [Agents](/docs/agents/): briefs, the gate that keeps the spec first, the agent skill, disputes, owner review, and several agents on one codebase. --- # Start with an agent You don't have to learn Stoic before your agent uses it. Paste the prompt below into Claude Code, Codex, Gemini CLI, Cursor, Copilot or any other coding agent, in the root of your repository. It sets the project up, writes a spec of what the code does now, stops to have you read that spec back, and only then locks it and writes the tests. ## The prompt ```prompt Set this repository up with Stoic, a small spec language whose toolchain locks tests and checks every change against them. Its docs, as Markdown, start at https://stoic-lang.org/llms.txt 1. If `stoic --version` fails, install it. On macOS or Linux: curl -LsSf https://stoic-lang.org/install.sh | sh On Windows (PowerShell): irm https://stoic-lang.org/install.ps1 | iex Or, with Rust: cargo install stoic-lang Each puts stoic in ~/.cargo/bin; add it to PATH if it isn't there. Before Stoic's first release, only this works: cargo install --git https://github.com/stoic-lang/stoic stoic-lang 2. In the repository root, run `stoic init`, then `stoic gate --install all git`. That writes an example spec.stoic, a CI workflow, hooks that make agent tools ask `stoic gate` before they write code, an AGENTS.md section, the Stoic agent skill and a git pre-commit hook. Read the AGENTS.md section and the skill (`stoic guide --skill`) before you go on. Then write stoic.code beside the lock: one glob per line for the implementation code (src/**, say). 3. Replace the example spec.stoic with a spec of what this project does now, one module or feature at a time: the things it has, the rules on each field with an example on each side of every limit, and tests that check values. Run `stoic check .` until it passes. 4. Show me what the compiler reads back (`stoic spec.stoic`) and ask me whether it says what I mean. Change the spec until I say it does. 5. Then run `stoic lock .` and implement every test `stoic brief .` lists, in this project's test framework. The tests write results.txt through the reporter `stoic harness --lang node --out stoic-results.cjs` prints (or --lang python, or --lang sh). Set TEST_COMMAND and the install URL in .github/workflows/stoic-verify.yml. 6. Run `stoic verify results.txt --run "" --strict` until it passes, then commit the spec, stoic.lock, stoic.code and the tests. From then on, every change starts in the spec: edit it, `stoic check .`, `stoic lock .`, then write the code. When `stoic gate` refuses a write, do what its `next:` line says. Never edit stoic.lock by hand. If a locked test looks wrong, have it record `dispute ID: why` and tell me. ``` Step 4 is the one that matters. The compiler's reading is plain English, so you can tell whether the agent understood your project before a single test exists. Everything after it is checked by the toolchain, not by the agent's good intentions. ## What it sets up ```sh $ stoic init created spec.stoic created .gitattributes created CODEOWNERS.stoic.example created .github/workflows/stoic-verify.yml $ stoic gate --install all git 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/ created .git/hooks/pre-commit ``` Three layers, each catching what the one before can miss: - **The hooks** run `stoic gate --hook` before every file the agent writes. Until this ticket's spec change is locked, implementation code is refused, and the refusal tells the model the one next step. - **The AGENTS.md section and the skill** tell the agent the loop before it starts, so it rarely hits the gate at all. The skill is listed by name and read only when a task needs it. - **Git's pre-commit hook and CI** check what is committed, whatever wrote it. CI runs `stoic verify --against` the base branch, which no prompt can talk around. The gate and verify are explained in full on [Agents](/docs/agents/). ## Per tool **Claude Code.** The hook is in `.claude/settings.json` and the skill in `.claude/skills/stoic/`. Claude Code reads `AGENTS.md` only when the project has no `CLAUDE.md`; if yours keeps one, add a line `@AGENTS.md` to it so the section is read too. **Codex.** The hook is in `.codex/hooks.json`, and Codex runs it once you trust it (`/hooks` in Codex). Codex reads `AGENTS.md`, and the skill from `.agents/skills/stoic/`. **Gemini CLI.** The hook is in `.gemini/settings.json`, before `write_file` and `replace`, and the skill comes from `.agents/skills/stoic/`. Gemini CLI reads `GEMINI.md` by default: add `AGENTS.md` to `context.fileName` in `.gemini/settings.json`, or add the section to `GEMINI.md`. For some accounts Google has replaced Gemini CLI with Antigravity CLI, which Stoic installs no hook for; check its docs. **Factory Droid.** The hook is in `.factory/hooks.json`. Droid reads `AGENTS.md`, and the skill from `.agents/skills/stoic/`. **Cursor.** Cursor has a hook before tool calls, but Stoic doesn't install one for it yet: its docs don't name the field that holds the written file. So the `AGENTS.md` section, the pre-commit hook and CI are the gate. Cursor reads `AGENTS.md`, and the skill from `.agents/skills/stoic/`. **GitHub Copilot.** Copilot has hooks (in the CLI, the cloud agent and VS Code), but Stoic doesn't install one for them yet, for the same reason: the pre-commit hook and CI are the gate. Copilot's agents read `AGENTS.md`, and the skill from `.agents/skills/` or `.claude/skills/`. **Kiro.** Kiro reads `AGENTS.md`, and the skill from `.kiro/skills/stoic/`. Stoic installs no hook for it, so the pre-commit hook and CI are the gate. **Anything else.** If the tool reads `AGENTS.md`, it has the loop. If it loads Agent Skills from another folder, `stoic guide --skill` prints the skill to put there. If it reads neither, give it the prompt above, or `stoic brief spec/` for a single task: the brief is the whole job in one page. ## When the agent joins an existing Stoic project The prompt above is for adopting Stoic. In a repository that already has a spec, an agent needs much less: ```text This project uses Stoic. Run `stoic brief spec/` (add `--as ` 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. ``` ## For the agent itself Every page of these docs has a Markdown twin: add `.md` to its path, as in [/docs/start-with-an-agent.md](/docs/start-with-an-agent.md). [/llms.txt](/llms.txt) lists them all, and [/llms-full.txt](/llms-full.txt) is every page in one file. On each docs page, "Copy page" puts the Markdown on your clipboard, ready to paste into a chat. --- # The glyphs Stoic has no vocabulary. Every tag, field, event, handler and capability is a word you choose, passed through verbatim for the reader to interpret, person or agent. What is fixed is a small set of glyphs, and each has exactly one job. Most are borrowed from things you already read: HTML's angle brackets, a shell's `&`, a pointer's `->`. They fall into four families: **structure** (what exists), **behaviour** (what happens), **firmness** (how strictly it holds) and **tests** (how we'll know). ## Element `` or ` children ` is a thing. A button, a table, a service, a pipeline step, a module's method. Leaving one unclosed at the end of a file is a warning. ```stoic ``` ## Name `:name` names an element, so it can be reused with `->`, tested with ``, or referred to by a field. Names are unique within a file, and within one lock a name is defined once. ```stoic ``` ## Bind `=` after a tag binds an element to data or state. On a field, `=` gives a value, and when that value names another element it is a reference, not a copy. ```stoic ``` ## Reuse `->` makes a copy of another element to adjust, in this file or another (`->ui.buttons.primary` is `primary` in `ui/buttons.stoic`). `#-name` and `@-name` leave a field or event out. ```stoic =3) @crash="page oncall" /> api @-crash /> ``` ## Repeat `*` after a tag means one per entry of the parent's data. The parent's actions apply to each one. ```stoic ``` ## Field `#name(…)` is a property and its rules: limits (`>=3`), quoted matches (`"email"`), must-not-contain (`!" "`), capabilities (`sort`, `filter`) and actions (`[add, remove]`). ```stoic
=3, <=20, !" ") #created(sort, filter) /> ``` ## Event `@name="…"` is a trigger and what it does, in plain words. `@*` is every event. The handler is passed to the implementer verbatim, so write it the way you'd say it. ```stoic ``` ## Note A quoted string touching a word, with no space, fine-tunes that word. Notes go wherever detail matters: tags, events, fields, capabilities and actions. With a space it's an error, so you can't attach one by accident. ```stoic ``` ## How it runs {#modifiers} Between `@` and the event: `~` is an animation (`~+` quick, `~-` slow) and `&` runs in the background, like `&` in a shell. They combine: `@&~click`. ```stoic ``` ## Strict `!` touching a name: no exceptions. On an element, it's the default for everything inside it. ```stoic 0) #note(<=140) /> ``` ## Can bend {#bend} `?` touching a name: a preference, not a rule. Tests don't bend: a `?` field's examples are still tests. ```stoic =1) /> ``` ## Or-value {#or} `|value` is a value the field takes whatever its limits say: `#cycles(>=1, |null)` reads "must be at least 1, or null". ```stoic =1, <=5, |null) /> ``` ## Examples `+"…"` must be accepted and `-"…"` rejected. `+=1` and `-=1.5` are values rather than text. Each example is a test, with an ID like `signup_username_rejects_ad`. `+=>="…"` and `-=>="…"` say what accepting and rejecting reports, as checked values. ```stoic =3, +"ada", -"ad", +=>="'ok'", -=>="'TOO_SHORT'") /> ``` ## Given `^"…"` is a step that has already happened before a test's action, as many as it takes, in order. Among a field's arguments, it's how each of the field's examples is tried. ```stoic ="'FULL'" /> ``` ## Expect `=>"…"` is what must happen and `=>!"…"` what must not. These are guidance for whoever writes the test: verify only sees whether it passed. They're marked *(not checked)* everywhere they're printed, honestly. ```stoic "saved" =>!"error shown" =>status="201" /> ``` ## Checked value {#checked} `=>="…"` (or `=>label="…"` when a test has several) is the glyph that does the enforcing. The test reports the value it observed, and verify compares it with the locked one, as a value: numbers by value, objects in any key order. A test body can be wrong. Its observation can't hide. ```stoic fee="52" /> ``` ## Kept comment {#kept} `` is private and never appears in any output. `` is kept: guidance for the implementer, for what a rule can't say. It belongs to the element it's in or right before, or to the whole file when it stands alone. ```stoic ``` ## Your words {#yours} Everything else is yours. ``, ``, `@tap`, `@clk` and `#vibe` are as valid as `` and `@click`. Stoic never checks a name against a vocabulary, because the reader, a person or a model, already knows what a gallery is. ```stoic ``` --- # Everywhere Stoic began as a way to describe interfaces, and turned out to describe almost anything. The pieces don't change: elements are things, fields are properties, `=` on a field points at another thing, events are triggers, and handlers are plain-words instructions. Only the words do. That matters more than it sounds. An agent working on a feature touches the interface, the table behind it, the service that serves it and the pipeline that ships it. One language for all four means one review habit, one lock and one verify gate. ## Interfaces Components, states and interactions. Notes carry the taste that usually lives in a designer's head. ```stoic title=feed.stoic ``` ## Data Tables, relations and the rules on each column. `#user=users` refers to the `users` table rather than copying it. ```stoic title=db.stoic "lowercased">
=0) #status("pending | paid | shipped")> ``` ## Infrastructure Services, their limits, and what happens when things fail. `->` reuses a service; `@-crash` leaves out what the copy shouldn't inherit. ```stoic title=infra.stoic =3, <=10) #cpu(<=2) #region("eu-west-1") @deploy="roll out one zone at a time" @crash="restart and page oncall" /> api @-crash #replicas(>=1, <=4) @&message="process jobs from the queue" /> ``` ## CI/CD A pipeline is a list of steps, each a plain-words instruction with what to do when it fails. ```stoic title=ci.stoic
``` ## Modules This is where Stoic is strictest, because it's where agents write the most code. Methods, errors in the order they're checked, and examples that are tests, each reporting a value verify compares. ```stoic title=cart.stoic =1, <=99, +=1, +=99, -=0, -=100, +=>="{ ok: true }", -=>="{ ok: false, error: 'QTY' }" ) /> ="{ ok: false, error: 'QTY' }" /> ``` ## Stacks Languages, frameworks and versions, written once. Keep a shared `stack.stoic` and point each app at it with `->stack.shop`, overriding what differs. ```stoic title=stack.stoic =20) /> shop #runtime="bun 1.2" /> ``` ## Across files A reference says where to look, so there are no import lines: `->buttons.like` is `like` in `buttons.stoic` next to this file, and `->ui.buttons.like` is in `ui/buttons.stoic`. Tests can bind to an element in another file with `=file.name`. ```stoic source title=feed.stoic ui.buttons.like /> count="1" /> ``` --- # Tests A spec without tests is a wish. In Stoic the spec defines the tests, the implementer writes them in whatever language the project uses, and verify checks the run against the lock. There are two ways to define one: **examples** on a field, and **test elements**. ## Examples `+"…"` on a field must be accepted and `-"…"` rejected. Each one becomes a test with a stable ID. A `^"…"` among the field's arguments says how each example is tried. ```stoic =3, <=20, !" ", +"ada", -"ad", -"a b", +"twenty_chars_exactly", -"twenty_one_characters", +=>="'ok'", -=>="'INVALID'" ) /> ``` Text and values are different things: `+"1"` is the text "1" and `+=1` is the number. The kind is part of the test. ## Test elements Any element with expectations is a test. It's bound to what it tests (`=signup`), takes inputs as fields, has exactly one action, and says what must and must not happen. ```stoic =3) #email("email") @submit="create account" /> "welcome email queued" =>account="'created'" /> ``` ## Checked values This is the distinction the rest of Stoic is built on. An expectation like `=>"welcome email queued"` is guidance: verify only ever sees whether the test passed, so a test body that asserts the wrong thing still passes. Stoic says so wherever it prints one: *(not checked)*. A **checked value**, `=>="…"` or `=>label="…"`, is different. The test reports what it observed (`pass fee600 fee = 53`), and verify compares that with the value in the spec, as a value: ```sh WRONG fee600 fee: expected 52, observed 53 ``` So the test body no longer decides what's right. If someone edits it to agree with a bug, the observation still disagrees with the lock. A test element with nothing checked gets a warning, and `stoic verify --strict` makes it an error. One checked value is enough. ```stoic total="7200" =>"shows the discount line" /> ``` ## Givens `^"…"` on a test is a step that has happened before its action. Use as many as it takes, in order. They're part of the test: change one and the test changed. ```stoic ="{ ok: false, error: 'ALREADY_REFUNDED' }" /> ``` ## Or-values Sometimes a field takes one value its limits don't describe: `null`, `-1`, `"auto"`. Say it after `|`, and give it an example. ```stoic =1, <=5, |null, +=1, +=5, +=null, -=0, -=6, +=>="true", -=>="false") /> ``` ## No rule without a witness A rule is enforced only if dropping it would fail a test. So each formal rule on a field with examples needs examples at its edge: `>=1` needs an accepted 1 (or anything at or inside the bound) and a rejected 0, *just* outside. `!" "` needs a rejected example containing a space. The compiler names the one to add: ```stoic =1, <=99, +=1, -=0, +=>="true", -=>="false") /> ``` That's a warning while you write and an error under `stoic verify --strict`, the check CI runs. It's the difference between "we have a rule" and "we'd notice if it broke". ## How many tests Write the fewest that pin the behaviour down. One per rule, and one per boundary on each side: 99 accepted and 100 rejected, not every number between. If two tests would fail for the same reason, keep one. The [writing guide](/docs/writing/) has more. --- # Lock and verify A spec is a promise. The lock is the promise written down where it can't quietly change, and verify is the moment it's checked. Everything else in Stoic exists to make these two steps trustworthy. ## Lock ```sh $ stoic lock spec/ locked 4 tests from 1 file(s) into stoic.lock ``` `stoic.lock` records every test, two hashes for each (its whole definition, and its own text alone), each checked value, and a hash of every spec. Commit it and review it like code. Paths in it always use `/`, and line endings don't count: a checkout where git writes `\r\n` hashes, verifies and formats exactly as one with `\n`, so a lock written on Windows is the one written on macOS or Linux. Relocking prints what changed, test by test, and every checked value that moved. Here the rounding changed on purpose: ```sh $ stoic lock spec/ locked 4 tests from 1 file(s) into stoic.lock ~ fee600 test of `fee`: given nothing; on call with "600"; expect `fee` exactly "53" (reported back and compared); expect "52.5 rounds up to 53" (not checked) value fee600 fee: 52 -> 53 (spec/fees.stoic:15) tests: 1 changed, 0 only through their target, 0 added, 0 removed ``` A relock never fails on a changed value, because changing behaviour on purpose means changing a value. It just can't do it quietly. A test renamed in the same edit would otherwise read as one test removed and an unrelated one added, its old and new values never side by side. So a removed test and an added one in the same file, testing the same target, that differ only in their IDs and checked values are paired as one rename: ```sh $ stoic lock spec/ locked 4 tests from 1 file(s) into stoic.lock ~ fee600 -> fee600_round test of `fee`: given nothing; on call with "600"; expect `fee` exactly "53" (reported back and compared); expect "52.5 rounds to the even 52" (not checked) value fee600 -> fee600_round fee: 52 -> 53 (spec/fees.stoic:15) tests: 0 changed, 0 only through their target, 0 added, 0 removed, 1 renamed ``` Nothing pairs loosely: when two removed or two added tests could pair, none do. ## Verify ```sh $ stoic verify results.txt --run "npm test" --strict ``` `--run` deletes the old results, runs your tests (with `sh -c`, or `cmd /S /C` on Windows, so `--run "npm test"` works on both), and reads the fresh file they wrote, so nothing stale or hand-written counts. It sets `STOIC_RESULTS` to the results file you named, and Stoic's reporters write there. Then every locked test gets a line, and the run gets a verdict that says how much the pass proves: ```sh verified: 4/4 locked tests passed (4 checked, 0 asserted only, 0 examples) ``` A run that isn't verified ends with one more line, so the last line alone (`stoic verify … | tail -1`) says what went wrong and what to do: how many lines of each kind it printed, and the one next step. ```sh 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. ``` ## Every verdict | Line | Means | | --- | --- | | `pass` | Ran, passed, and reported the locked value if it has one. | | `WRONG` | Passed, but a value it reported isn't the locked one. | | `MISSING` | A locked test isn't in the results at all. | | `FAILED` / `SKIPPED` | The test said so itself. | | `DRIFT` | The spec or a test changed since the lock (a renamed test says so, with its old and new ID), or the lock differs from the trusted one. | | `VALUE` | Which checked value a drifted test moved, from what to what. | | `DISPUTE` | A test objected that it looks wrong. Listed first; fails until an owner settles it, with [`stoic review`](/docs/agents/#owner-review). | | `UNKNOWN` | With `--strict`: results name a test that isn't locked. | | `SCOPE` | With segments: a part of the spec changed, and no relock by its owner or claim holder made the change. | | `STALE` | With claims: a relock made under a claim that has since been taken over or released. Its `next:` line says to stop and report it, and names the `stoic claim … --take-over` that would hand the segment back once the claim expires. | | `UNSPECIFIED` | With `--coverage`: implementation lines changed since `--against` that no locked test runs. `--strict` fails on them. | | `ERROR` | A lock that names a spec out of sight (outside its folder, in a hidden folder, through a symlink), or a name two locked files both define. With `--strict`: a rule with no witness, a test with nothing checked, a spec the lock doesn't cover. | Exit codes mean what they say: `0` verified, `1` not, `2` a bad call. Each command takes only its own options, so a flag meant for another command is an error, never silently ignored. ## Drift: what changed, and who changed it Verify tells two kinds of change apart. A test whose **own text** changed (an expectation, an input, a step) gets its own line, because that's where tests get loosened. Tests that changed **only through what they test** (a field's rule moved) share one line per target, so you review the spec change once. ```sh DRIFT spec/fees.stoic: the spec changed since it was locked DRIFT test `fee600` changed since it was locked VALUE fee600 fee: 52 -> 53 (spec/fees.stoic:15) ``` A renamed test is paired as the relock pairs it, so its values still sit side by side: ```sh DRIFT test `fee600` in spec/fees.stoic was renamed `fee600_round` (same target and steps) VALUE fee600 -> fee600_round fee: 52 -> 53 (spec/fees.stoic:15) ``` ## Trust the lock on main An agent can run `stoic lock` too. So in CI, verify against the lock that was reviewed, not the one in the branch: ```sh $ stoic verify results.txt --run "npm test" --strict --against origin/main DRIFT spec/fees.stoic: the spec changed since it was locked DRIFT test `fee600` changed since it was locked DRIFT stoic.lock differs from origin/main: relocking needs review VALUE fee600 fee: 52 -> 53 (spec/fees.stoic:15) pass fee_amount_accepts_500 pass fee_amount_rejects_0 pass fee_amount_rejects_1_5 pass fee600 NOT verified: 4/4 locked tests passed (4 checked, 0 asserted only, 0 examples), 3 change(s) since the lock (tests: 1 changed, 0 only through their target, 0 added, 0 removed) next: 3 DRIFT, 1 VALUE above. Stop: stoic.lock changed since origin/main (1 value change(s)); this needs review before going on. Report the DRIFT and VALUE lines and wait; don't relock, or edit a spec or a test, to make this pass. ``` Every test passed, and it still isn't verified: the branch relocked a value, and only a review can accept that. So under `--against` the next step is a stop. An agent is told to report the change and wait, not to relock its way past it. When several agents share a codebase, `stoic.segments` and claims let verify say whose change it was; see [Agents](/docs/agents/#many-agents-one-truth). `stoic init` writes a GitHub Actions workflow that does exactly this on pull requests, pinned to the base commit (add `--coverage` to it to fail a pull request that adds code no locked test runs), plus a `.gitattributes` rule so lock conflicts are relocked rather than merged line by line, and a CODEOWNERS example so the lock needs an owner's review. ## Code no locked test runs A spec can only enforce what its tests run. A new function, a branch an agent added "while it was there", another agent's quiet change: code that no locked test runs passes every test and verifies, unspecified. `--coverage` catches it, whoever wrote it and in whatever order. The tests' run writes an LCOV report, and git says which lines changed since the reviewed base: ```sh $ stoic verify results.txt --strict --against origin/main --coverage lcov.info --run "node --test --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=lcov.info" pass fee_amount_accepts_500 pass fee_amount_rejects_0 pass fee_amount_rejects_1_5 pass fee600 pass fee_minimum UNSPECIFIED src/fees.js:6-7 (changed since origin/main; no locked test runs it) coverage: 3/5 changed line(s) in 1 implementation file(s) since origin/main run by locked tests NOT verified: 5/5 locked tests passed (5 checked, 0 asserted only, 0 examples), 2 changed line(s) no locked test runs next: 1 UNSPECIFIED above. Specify the behaviour first: add or change a test in the spec that runs this code and relock (after review), or remove the code; a test that isn't locked doesn't count. ``` Every locked test passed, and two new lines still ran under none of them. The way out is the spec: a test that runs that code, locked after review, or no code. With the branch gone: ```sh coverage: 1/1 changed line(s) in 1 implementation file(s) since origin/main run by locked tests verified: 5/5 locked tests passed (5 checked, 0 asserted only, 0 examples) ``` The rules are decided once. It needs `--against`: the lines checked are the ones changed since the reviewed base, because a total percentage enforces nothing. The report must be fresh: `--run` deletes it before the tests run, so one left from another run can't count. A report that can't be read whole fails closed. Give `--coverage` once per report (one per package or per language) and their hits add up. A changed file the report lacks is unspecified whole, since no test even loaded it. Only implementation counts, and `stoic.code` beside the lock says what that is, with the same globs as [the gate](/docs/agents/#spec-first-as-the-agent-writes). Paths are from the project root, the git work tree's top folder, so a lock in `spec/` checks the code in `src/`. Without `stoic.code`, it's every file but specs, Stoic's own files, tests, `*.md`, hidden paths and what git ignores. Every mainstream coverage tool writes LCOV. `stoic help verify` prints the command for each: | Runner | Writes LCOV with | | --- | --- | | node 22+ | `node --test --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=lcov.info` | | c8, Jest, Vitest | `c8 --reporter=lcovonly`, `jest --coverage --coverageReporters=lcovonly`, `vitest run --coverage.enabled --coverage.reporter=lcovonly` (to `coverage/lcov.info`) | | Python | `coverage run -m pytest && coverage lcov -o lcov.info`, or `pytest --cov=. --cov-report=lcov:lcov.info` | | Rust | `cargo llvm-cov --lcov --output-path lcov.info` | | Go | `go test -coverprofile=cover.out ./...`, then `gcov2lcov -infile=cover.out -outfile=lcov.info` | Two limits, by construction. Coverage counts whatever the run executes, so a test that isn't locked covers code too: keep the test command to the locked tests (`--strict` lists any reported test that isn't locked as `UNKNOWN`). And a diff is by line, so a new line identical to the one it replaced reads as unchanged. ## Before you relock `stoic check` is the one call to make first: it compiles every spec, checks formatting, and shows what changed since the lock. ```sh $ stoic check spec checked 1 file(s): they compile, are formatted and match stoic.lock ``` ## What verify can't do Stoic is honest about its edges, so we will be too. Verify sees results and, with `--coverage`, which changed lines ran; it never reads what the code does. An expectation in words, `=>"shows a toast"`, is only as good as the test someone wrote for it, which is why checked values exist and why `--strict` insists on them. And the results file is only as trustworthy as whoever ran the tests, which is why `--run` exists and why CI should be the one running it. --- # Agents 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 ```sh $ 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. ```sh $ 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: ```sh $ 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: ```sh $ 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: ```sh $ 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](https://agentskills.io/specification) 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. ```sh $ 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 ``` ```text 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: ```text 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](#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: ```text # 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: ```sh $ 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. ```sh $ 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: ```sh $ 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: ```sh $ 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: ```text This project uses Stoic. Run `stoic brief spec/` (add `--as ` 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). --- # Writing a Stoic spec A short guide for whoever turns a task into a spec, person or agent. docs/REFERENCE.md has the whole language; this is what you need to write a good spec quickly. Print it any time with `stoic guide`. ## The loop ```sh stoic spec.stoic # compile: fix every error before going on stoic fmt spec.stoic # tidy stoic lock spec.stoic # freeze the tests in stoic.lock stoic brief spec.stoic # the exact direction to implement from # implement it; the tests write results.txt stoic verify results.txt --strict ``` The spec is the plan. The compiler is the guard: it refuses a spec whose examples contradict their own rules, whose tests name a field or event that doesn't exist, or whose rejecting input says nothing about what must not happen. Once it compiles and is locked, implement from the brief. It is the whole contract. ## What a spec says Say everything the implementer needs and nothing twice: - the file, its export and how it's called; - each operation: its arguments, what it returns, its errors in check order, and its side effects; - every rule, limit, rounding and ordering, once, where it applies; - what is deliberately left open. Aim for a spec no longer than about twice the task. If it's longer, you're restating rules in several places or writing long setups. ## A module, method by method Nothing is a keyword: tags, field and event names are yours. This shape works well for code modules: ```html =1, <=99, +=1, +=99, -=0, -=100, -=1.5, -"2", +=>="{ ok: true }", -=>="{ ok: false, error: 'QTY' }")> ="{ ok: false, error: 'QTY' }" =>!"the line changes" /> ``` - **Strict where it matters.** `` makes everything inside strict; use `?` on anything that may bend. - **Rules go on fields.** Limits (`>=1`), quoted rules (`"an integer"`), a value (`#tax="…"`), or a note (`#qty"whole units"(…)`). A value the limits don't cover goes after `|`: `#cycles(>=1, |null)` reads "must be at least 1, or null", so `+=null` is a valid example, not prose. - **Behaviour goes in the handler.** `@call="…"` is passed to the implementer verbatim, so write it as you would say it. - **Guidance goes in kept comments.** `` reaches the implementer on the element it's in or before, or at file level when it stands alone. Ordinary `` comments are private. ## Tests Every test is locked, and each is something the implementer must build and pass. Write the fewest that pin the behaviour down: - **One test per rule, and one per boundary on each side**: 99 accepted and 100 rejected, a balance of 499 allowed and 500 blocked. Not every value in between. On a field with examples the compiler checks it: a limit needs a rejected example just past its bound (`-=100` for `<=99`, `-"ad"` for a length `>=3`), `!" "` a rejected one containing a space, `|null` an accepted `+=null`; `untested-rule: …; add -=100` names the one missing. - **Check order only where two errors can apply at once.** Test the pairs that can really collide, not every adjacent pair. - **Field examples are the cheap tests.** `+=1`, `-=100`, `-"2"` on a field, with one `^"…"` step saying how each is tried. Bare values are values and quoted ones are text, so `-=1.5` and `-"2"` are different tests. Say what accepting and rejecting one shows, `+=>="{ ok: true }"` and `-=>="{ ok: false, error: 'QTY' }"`, so each example reports what the code returned and verify, not the test, decides; an example may say its own (`-=1.5=>="…"`). - **Examples are single values or text.** A bare example is a number, `true`, `false`, `null`, `NaN` or `Infinity`; `+"[1]"` is the text `[1]`, not an array. An array or object input goes in a test element's action instead: `="…" />`. - **Test elements are for behaviour across calls**: `label="…" =>!"…">`. The target is a named element, the inputs are its fields, and the action is one of its events. A test in another file binds to it there (`=cart.add`): define each name once per lock, or `stoic lock` refuses the second. - **Keep setups short.** Define shorthand once in a file-level kept comment (``), then write `^"m1 borrowed b1 on day 0"`. - **Every test checks a value.** Words can't be verified, so a test with only `=>"…"` can quietly assert something else and still pass (its summary says `(not checked)`, and compiling warns). `=>="{ ok: false, error: 'QTY' }"` makes the test report what it observed (`pass ID = …`), and verify fails it unless that equals the locked value. To check several, label each: `=>total="1800" =>cycles="1"`. Work every number out before you lock. A value compares whole, so when the code returns more than the spec states (`{ ok: true, line }` for `+=>="{ ok: true }"`), say in the step or a kept comment what the test reports (`report { ok } alone`), or check only what matters with a label (`=>ok="true"`). `stoic verify --strict` fails a test without one. - **Values compare as Stoic values:** numbers by value (`1.0` is `1`), strings in either quote, objects by key set, so `{"ok":false}` matches `{ ok: false }`. Quote text (`=>="'QTY'"`): a bare word isn't a value, so it is compared as text, whitespace between symbols aside. `stoic harness --lang node|python|sh` prints the reporter the tests write these lines with. Save the node one outside `test/` and `*.test.*` names (next to the spec), or `node --test` runs it as a test. It appends, so a run starts from a clean results file only once you delete it (`stoic verify --run` does). - **Say what must not happen** (`=>!"…"`) when an input breaks a rule. The compiler insists. ## Leaving things open If the task doesn't decide something, don't invent a rule and don't test it. Say so once, in a file-level kept comment: ```html ``` ## Changing a spec later Edit the spec in place, then before relocking see exactly what your edit did: ```sh stoic check spec # compile, formatting and what changed since the lock stoic verify /dev/null --no-against # every locked test's state against the edited spec ``` It lists tests added, removed and changed. A test whose own steps and expectations changed is a real edit, so make sure each one is intended. A test that changed only because the element it tests changed should still hold as written; check that it does. Then `stoic lock`, which lists the same split: edited tests one per line, the rest as one line per target, and each checked value it changed (`value fee500: 44 -> 45 (spec/fees.stoic:5)`): say which in your report. A test whose behaviour the change removes is deleted, and its replacement gets a new name that says what it now checks. ## Several agents on one spec Give each agent a segment in `stoic.segments`, beside the lock: ```text billing @agent-a: invoice money cart @agent-b: cart checkout ``` A segment lists top-level elements, with what's nested in them and their tests. Keep each file to one segment, and draw segments so few tests reuse (`->`) another's elements. An agent relocks with `stoic lock spec --as agent-b`, which refuses any change outside its segments. Put rules a ticket mustn't change in an owner's segment (`rules @product: refund`): another agent, on a different ticket in parallel, can't relock them. Blocked by one, an implementer reports `dispute ID: why`, and the owner settles it with `stoic review --as product`. ## Before you lock - [ ] `stoic spec.stoic` compiles with no errors. - [ ] Every rule in the task is stated once, and has a test or an example at each of its boundaries. - [ ] Every expected number was worked out, not guessed. - [ ] Shorthand used in steps is defined in a kept comment. - [ ] Open points are listed as left open, with no tests. - [ ] `stoic brief spec.stoic` reads as a complete instruction: you could build exactly the right thing from it alone. --- # Stoic reference The whole language and toolchain: every command, the syntax and grammar, tests, locking, results, verifying, several agents, the gate, CI, editors. For a first look, read the [README](../README.md); to write a spec quickly, the [guide](WRITING.md) (`stoic guide`). Every command also prints its own usage and options: `stoic help COMMAND`. ## Contents - [Commands](#commands) - [Syntax](#syntax) - [Fine-tuning with notes](#fine-tuning-with-notes) - [Kept comments](#kept-comments) - [Strictness: strict and can bend](#strictness-strict-and-can-bend) - [Binding data](#binding-data) - [Nothing is a keyword](#nothing-is-a-keyword) - [Beyond UI: data, databases, infra, CI/CD](#beyond-ui-data-databases-infra-cicd) - [Frameworks and dependencies](#frameworks-and-dependencies) - [Reuse](#reuse) - [Grammar](#grammar) - [JSON output](#json-output) - [Tests: locked and enforced](#tests-locked-and-enforced) - [Defining tests](#defining-tests) - [Or-values: a value the limits don't cover](#or-values-a-value-the-limits-dont-cover) - [Locking](#locking) - [What verify can't enforce](#what-verify-cant-enforce) - [No rule without a witness](#no-rule-without-a-witness) - [Results](#results) - [Stoic values](#stoic-values) - [Reporters](#reporters) - [Verifying](#verifying) - [Diff coverage: new code a locked test must run](#diff-coverage-new-code-a-locked-test-must-run) - [Working with several agents](#working-with-several-agents) - [Segments: who owns what](#segments-who-owns-what) - [Claims and fencing tokens](#claims-and-fencing-tokens) - [Handing a spec to an agent](#handing-a-spec-to-an-agent) - [Spec first, as agents write: `stoic gate`](#spec-first-as-agents-write-stoic-gate) - [CI](#ci) - [Editor support](#editor-support) - [Starting a project](#starting-a-project) - [Formatting](#formatting) - [Architecture](#architecture) - [Stoic specifies itself](#stoic-specifies-itself) ## Commands Each release has an installer for macOS and Linux (`curl --proto '=https' --tlsv1.2 -LsSf https://github.com/stoic-lang/stoic/releases/latest/download/stoic-lang-installer.sh | sh`), one for Windows (`powershell -ExecutionPolicy Bypass -c "irm https://github.com/stoic-lang/stoic/releases/latest/download/stoic-lang-installer.ps1 | iex"`), a Homebrew formula (`brew install stoic-lang/tap/stoic`) and a crate (`cargo install stoic-lang`, which installs the command `stoic`). They work once the first release is published; before that, or for an unreleased commit, build from the repository. ```sh cargo install --git https://github.com/stoic-lang/stoic stoic-lang # or, in a clone: cargo install --path . stoic FILE.stoic # prose (default) stoic FILE.stoic --format spec # bullet tree stoic FILE.stoic --format json # resolved model, for tooling: {"elements": [...], "comments": [...]} stoic < FILE.stoic # stdin (a bare `stoic` on a terminal prints the usage instead) stoic spec/*.stoic # several files (or a folder), each after a `==> FILE <==` line stoic --version # or -V stoic tests FILE.stoic # list the tests FILE defines, by ID stoic tests . # …or every .stoic file under a folder stoic lock FILE.stoic... # freeze tests + spec into stoic.lock (files or folders) stoic lock . --per-test # …listing each changed test on its own line, never grouped by target stoic lock . --as agent-b # …only the segments agent-b owns in stoic.segments (refuses any other change) stoic lock spec --lock spec/stoic.lock # …specs in spec/, locked beside them (every command that reads a lock takes --lock) stoic lock . --force-unlock # …past a guard another host left over 10 minutes ago (see Locking) stoic verify results.txt # check test results against the lock stoic verify results.txt --strict # …also failing on unlocked tests and what verify can't enforce (CI's check) stoic verify results.txt --run CMD # …running the tests (CMD) first, so only fresh results count stoic verify results.txt --against origin/main # …against the lock committed there stoic verify results.txt --against origin/main --coverage lcov.info # …and fail on new code no locked test runs (with --strict) stoic verify /dev/null --no-against # …the working copy's lock, said explicitly: every test's state stoic verify results.txt --watch # rerun on every change to the results or specs stoic verify results.txt --per-test # one DRIFT line per test, never grouped by target stoic verify results.txt --as agent-b # …counting agent-b's tests apart from others' stoic check spec # before relocking: compile, fmt --check and drift, in one call stoic gate src/app.js # spec first: may an agent write this file now? exit 0 allow, 2 deny stoic gate --staged # …for what git has staged (git's pre-commit hook) stoic gate --hook claude-code # …answering an agent tool's pre-write hook event on stdin stoic gate --install all git # write those hooks: Claude Code, Codex, Gemini CLI, Factory, AGENTS.md, the skill, git stoic gate --install skill # …or just the agent skill (.claude/skills, .agents/skills, .kiro/skills) stoic gate --refactor "why" # declare a ticket that changes no behaviour, so code may change stoic segments # who owns what (stoic.segments), claims, and the reuse between segments stoic claim billing --as agent-a # claim a segment on the stoic-claims branch, with a fencing token stoic claim billing --as agent-b --take-over # …once it expired (--ttl 30m sets how long a claim lasts) stoic release billing --as agent-a # …and end the claim stoic review results.txt --as product # for an owner: what waits in its segments (changes, disputes, WRONG tests) stoic review results.txt --as product --approve # …relock them as product (--reject: say what to revert) stoic review results.txt --as product --accept-observed ID # …take ID's observed values into the spec, then relock stoic merge-lock --install # merge stoic.lock by key when git merges branches (this clone) stoic merge-lock --check # …then, once the specs are merged: tests changed only in combination stoic merge-lock BASE OURS THEIRS [PATH] # the driver git runs: THEIRS merged into OURS by key stoic brief FILE.stoic... # instructions for an AI coding agent (files or folders) stoic brief FILE.stoic --role owner # …for an agent that owns the spec and changes it first stoic brief FILE.stoic --as agent-b # …saying which elements agent-b owns and must leave alone stoic harness --lang node # a results reporter for the tests (node, python or sh) stoic harness --lang node --out stoic-results.cjs # …written to a file stoic fmt . # format every .stoic file in place (--check for CI, - for stdin) stoic init [DIR] # start a project: example spec, CI workflow, lock merge rule (--force overwrites) stoic guide # the short guide to writing a spec (docs/WRITING.md) stoic guide --skill # the agent skill (SKILL.md) that teaches an agent the loop stoic lsp # language server on stdio (--stdio is accepted, for editors that pass it) stoic help [COMMAND] # every command and option, or just COMMAND's (as stoic COMMAND --help) ``` New to writing specs? Start with [the guide](WRITING.md) (`stoic guide`): the loop, the shape that works for code modules, how many tests to write, and how to change a spec later. Diagnostics go to stderr. The exit code is 1 when there are errors (or `stoic verify` fails) and 2 on bad arguments, which print the error and then that command's help. Each command takes only its own options, so one meant for another is a bad argument, not silently ignored: `stoic lock . --strict` says `stoic lock doesn't take --strict; it takes --lock, --force-unlock, --per-test, --as`. So does a format a command doesn't print: compiling takes `--format prose|spec|json`, `stoic tests` and `stoic brief` take `prose` (their usual output) or `json`. Compiling several files, or a folder, compiles each in turn: prose and spec print each after a `==> PATH <==` line, json prints one array of `{"file": …, "spec": …}`, and any file with errors makes the exit 1 (the others are still printed). `stoic --help` (or `stoic help`) lists every command and option; `stoic help lock` (or `stoic lock --help`) shows just one command's usage and options. ## Syntax | Syntax | Meaning | | --- | --- | | `` or ` children ` | an element; leaving it unclosed at end of file is a warning | | ``, `` | element bound to data / state (quotes optional for one word) | | `@click=increment`, `@click="increment x"` | a handler: name or plain-words instruction, passed through verbatim | | `@clk`, `@swipe_left`, … | any event name; passed through verbatim for the reader to interpret | | `@*` | every event | | `@~hover` | an animation on hover; `@~+click` quick, `@~-click` slow | | `@&submit="save draft"` | runs in the background (doesn't block), like `&` in a shell; combine as `@&~click` | | `` | repeats once per entry of the parent's data | | `#id(sort, filter, pin)` | field with capabilities, passed through verbatim: "supports `sort`, `filter`, and `pin`" | | `#more([add, remove, update])` | actions (on each repeated child, if there is one) | | `#name(>1, <=32)` | limits: `>` `>=` `<` `<=` `=`; "must be more than 1 and at most 32". Length, count or value is for the reader to infer | | `#name(!" ")` | must not contain `" "` | | `#cycles(>=1, \|null)` | or a value: "must be at least 1, or null"; the field takes `null` whatever its limits say (see [Or-values](#or-values-a-value-the-limits-dont-cover)) | | `#email!("email")`, ``, `@submit!=save` | strict: "must strictly match", "(strict)" (see [Strictness](#strictness-strict-and-can-bend)) | | `#bio?(<=500)`, ``, `@~hover?` | can bend: "should be at most 500 (can bend)" | | `#email("email")`, `#region("eu-west-1")` | must match, passed through verbatim | | `#react="^19"`, `#vitest(dev)="^3"` | a value: "Field `react` is `^19`"; `=` goes before or after `( )` | | `#user=users`, `#database=db.users` | when the value names an element (here or in another file), it's a reference: "refers to `users`", without copying it | | `#name->"lowercased + sanitized"` | transform, described in words | | `#lastname->firstname` | inherit `firstname`'s rules and transform | | `` | a named element, so it can be reused or tested | | `like>`, `ui.buttons.primary>` | reuse: a copy of `like` (here or in another file), to adjust | | `api #-database @-crash>` | reuse `api` without its `database` field or `crash` event (see [Reuse](#reuse)) | | ``, `@click"debounce 300ms"`, `#email"work only"`, `sort"newest first"` | a note: a quoted string touching a word fine-tunes that word, passed through verbatim | | `#username(+"ada", -"a b")` | examples: "ada" must be accepted, "a b" rejected. Each one is a test | | `#qty(+=1, -=-1, -=1.5, -=NaN)` | examples that are values, not text: the number 1 must be accepted, -1, 1.5 and NaN rejected (`+"1"` is the text "1") | | `#qty(^"on a fresh cart, add('penny', value)", +=1)` | how each of the field's examples is tried: a given step (any number, in order) | | `#qty(+=1, -=0, +=>="{ ok: true }", -=>="{ ok: false }", -=1.5=>="NOPE")` | what accepting and rejecting an example shows, checked like `=>="…"`; an example may say its own | | `"account exists" =>!"error shown">` | a test of `signup`: inputs, one action, what must and must not happen | | `^"ada signed up"`, `@add="'c', 199"` | in a test: a step that has happened before the action (any number, in order), and what the action is called with | | `` | comment: private, never in any output | | `` | a kept comment: guidance shown to the implementer, on the element it's in or before (see [Kept comments](#kept-comments)) | ### Fine-tuning with notes A quoted string written right against a word, with no space, is a note on that word. Notes go wherever detail matters: elements, events, fields, capabilities and actions. ```html =12) /> ``` > A button ("pill shaped, brand color") that does "save draft" on click > ("debounce 300ms"), with a quick animation. … Field `created` supports > `sort` ("newest first") and `filter`. Field `more` provides actions on each > row: refund ("needs manager approval") and view. … With a space it isn't a note: `