delusional
by madebyshun
README.md
# delusional
> make the implicit explicit, then try to break it.

A zero-dependency 5-mode engineering auditor, Agent Skill, MCP server, x402-monetized API (Base Mainnet USDC), and light-mode Web Playground for Solidity & TypeScript — inspired by `@poteto` and `@dannypostma` (Tobi Lütke).
## The 5 Modes
1. **`invariants`** — Find implicit invariants (balance accounting underflows, tick/range clamping, period truncation, one-sided deltas, unbounded ETH pushes, division-before-multiplication, `tx.origin`, zero slippage, float money, unchecked `[0]`) and hunt for runnable counterexamples.
2. **`bugs-to-props`** — Extract historical bug-fix commits from `git log` and turn them into generalized property/fuzz tests.
3. **`state-machines`** — Detect implicit state machines (boolean soup, zero-vs-nonzero guards) and emit explicit Mermaid `stateDiagram-v2` graphs + illegal-transition checks.
4. **`halve`** — Flag oversized modules, stale `TODO`/`FIXME`/`DEPRECATED` markers, and commented-out code blocks removable without breaking tests.
5. **`100x`** — Flag serial I/O inside loops, nested quadratic loops, O(n) lookups inside loops, and uncached Solidity array `.length` reads.
## Install
```bash
# run instantly (no install)
npx delusional scan . --mode all
# or install globally
npm i -g delusional
delusional --help
```
## Quick Start
```bash
# 1. Scan any Solidity or TypeScript repo (text, json, or markdown)
node ./bin/delusional.mjs scan /path/to/repo --mode all
node ./bin/delusional.mjs scan /path/to/repo --format md
node ./bin/delusional.mjs scan /path/to/repo --fail-on high
# 2. Scan a single file
node ./bin/delusional.mjs analyze ./contracts/Backstop.sol --mode invariants
# 3. Compile a proof-enforced engineering prompt
node ./bin/delusional.mjs prompt invariants "Backstop.sol tick clamping" --context "Foundry 0.8.26, Base Mainnet"
# 4. Start Web Playground + API (free local demo mode)
npm run serve:demo
# open http://127.0.0.1:4020
# 5. Start Production x402 Paid Server (Base Mainnet USDC)
PAY_TO=0xD5C1dFc036F9911348EA8065F73c8123f4013FAB npm run serve
# 6. Run as MCP Server
npm run mcp
# 7. Run test suite
npm test
```
## x402 API (Base Mainnet USDC)
- **Discovery:** `GET /catalog` and `GET /.well-known/x402.json`
- **Health:** `GET /health`
- **Paid Analysis (`$0.05` USDC):** `POST /api/analyze` — enforces HTTP `402 Payment Required` with `PAYMENT-REQUIRED` header, verifies via `${X402_FACILITATOR_URL}/verify`, settles via `/settle`, and returns base64 `X-PAYMENT-RESPONSE`.
- **Prompt Compiler (`$0.01` USDC when `GATE_COMPILE=true`, free otherwise):** `POST /api/compile`
See `.env.example` for all environment variables (`PORT`, `HOST`, `FREE_MODE`, `PAY_TO`, `GATE_COMPILE`, `X402_FACILITATOR_URL`, `X402_SETTLE`, `X402_TEST_BYPASS`).
## MCP Server
Exposes 3 tools (`delusional_scan_repo`, `delusional_analyze_code`, `delusional_compile_prompt`) and 5 native prompts (`delusional-invariants`, `delusional-bugs-to-props`, `delusional-state-machines`, `delusional-halve`, `delusional-100x`):
```json
{
"mcpServers": {
"delusional": {
"command": "npx",
"args": ["-y", "delusional", "mcp"]
}
}
}
```
## Agent Skill
Copy or point your agent (Antigravity, Claude Code, Codex, Cursor) to:
`skills/delusional/SKILL.md`
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessOutdated data