TokenEconomizer
Experience-Driven Black-Box Cost Control for Coding Agents
Snap Pea: a fast Rust implementation of the P language, with specs that check your application code.
Developer toolsRust · GnuplotGitHub @crowecawcawOnlineOwner unconfirmed
Have you tried it? One tap is enough. No sign-in needed.
Owners of public repositories under a personal GitHub account can sign in to verify ownership and manage the introduction themselves. No administrator approval is needed.
Sign in, generate a verification file, and commit it to this repository’s default branch within 30 minutes. Files on other branches or forks do not count. Then check the file below to manage the project without administrator approval. Keep the file to retain your access.
If needed, you will go to sign-in. After signing in, return here and press your chosen verification button again.
Run /nomorevibe verify in your project folder to verify ownership and manage the introduction yourself.
Verify in one minuteAsk about other verification options
fast formal models that also check your code
Taken from the repository README
Loading the full README.
Read the full README ↗Fast formal models that also check your code.
Find bugs in how your system behaves before they reach production. Snap Pea uses the P modeling language to explore different event orderings, failures and interactions—and report a reproducible trace when something breaks.
Use the same rules to check your design, validate events from your application tests, and check production logs. Helpers for Python, Rust, Go and Java bring those checks into your existing test suite.
Try the playground · Read the overview · Documentation
Two orders each want 2 units of stock. There are 3 available. Both read the stock before either reserves it, so both think there is enough. Together, they oversell.
A P model describes the service and the orders as state machines exchanging messages. A spec states the rule: stock must never go negative. Snap Pea explores message orderings until it finds the one that breaks that rule, then saves a trace you can replay. Changing the design to check and reserve in one operation fixes the bug.
The inventory example includes both designs. Its spec is also used by the application examples in all four languages.
snappea observe checks against your specs. See testing and production.You or an AI agent can write the model from a design document, rerun the checker after
changes, and carry the specs into implementation tests. Review the specs closely:
they state what the system must get right. snappea guide walks through that workflow,
with runnable examples (snappea guide examples); telling an agent "use P, snappea is
installed" is enough for it to find.
Install the prebuilt CLI on Linux or macOS; no Rust or Python required:
curl -fsSL https://raw.githubusercontent.com/crowecawcaw/snappea/main/scripts/install.sh | sh
export PATH="$HOME/.local/bin:$PATH"
snappea version
On Windows, in PowerShell:
irm https://raw.githubusercontent.com/crowecawcaw/snappea/main/scripts/install.ps1 | iex
The installers support Linux x86-64/ARM64 with glibc, macOS Intel/Apple silicon and Windows x86-64. See installation options for release archives, Cargo, version pinning and install locations.
With Git installed, try both inventory designs:
git clone https://github.com/crowecawcaw/snappea.git
cd snappea/examples/model
snappea tests
snappea check tcAtomicReserve
snappea check tcCheckThenReserve
The atomic design passes exhaustive checking. The model scopes coverage exceptions to check-then-reserve paths covered by the other test. The check-then-reserve design fails with exit status 1 because it oversells. The failure includes:
Assertion Failed: PSpec/inventory.p:27:7 reservation exceeds available stock
Replay: snappea replay PCheckerOutput/tcCheckThenReserve/bug.schedule
Run the printed replay command from the same directory to reproduce the bug. The
command line guide and
model-checking reference cover options, output and search strategies.
snappea check also runs model lints; snappea check lint runs them separately, and snappea check mutation runs only
mutation testing.
Each language helper records application events and checks them against P specs. Follow your language's guide for a complete example and test-framework setup.
| Language | Install | Guide and examples |
|---|---|---|
| Python | pip install pysnappea | pytest guide · Examples |
| Rust | cargo add snappea | Rust guide · Examples |
| Go | go get github.com/crowecawcaw/snappea | Go guide · Examples |
| Java | Maven io.github.crowecawcaw:snappea | Java setup, including native jars · Examples |
Snap Pea is a Rust implementation of the P toolchain that reads .p and .pproj
files directly. snappea provides concise output and parallel checking;
snappea-compat accepts upstream p options and reproduces its output formats.
In the Raft tutorial benchmark, checking 120 schedules takes 0.4 seconds with Snap Pea and 38 seconds with P 3.1.0, including compilation. See the benchmark methodology and comparison charts for context.
See coming from P, measured upstream parity and the full compatibility reference. PVerifier and foreign code written in C# or Java are not supported.
Early, but checks real models. Validation covers upstream's 424 compiler regression tests, 249 checker tests, tutorials, golden traces and PObserve outputs. Validation details explain what is checked.
See development for the crate layout, tests and benchmarks, and AGENTS.md for the project's goals and required checks. Report a bug if something breaks.
Licensed under either of Apache License, Version 2.0 or MIT license, at your option.
Parts of snappea, including the tests vendored in tests/upstream, are derived from
P and remain under
P's MIT license (Copyright (c) 2015 P Developers).
Unless you explicitly state otherwise, any contribution you submit for inclusion in this project, as defined in the Apache-2.0 license, is dual licensed as above, without any additional terms or conditions.