# statewright/statewright — AlpLab Radar Static Code Audit

- Ring: `adopt`
- Category: `agents`
- Overall score: `4.0/5`
- Implementation check: `verified`
- Maturity: `active`
- Audited commit: `714e8209db36` (read-only; nothing from the repository was executed)
- Reviewed at: 2026-12-01T20:26:55Z
- Repository: https://github.com/statewright/statewright
- Radar entry: https://radar.alplab.co/#repo/statewright/statewright
- License: `NOASSERTION`
- CI workflows: `.github/workflows`
- Tags: `agent-guardrails`, `state-machine`, `mcp`, `claude-code`, `codex`, `rust`

## Summary

A Rust state-machine engine plus FSL-licensed MCP gateway and host plugins (Claude Code, Codex, Pi, OpenCode, Cursor, OMX) that enforce per-phase tool allowlists, shell-command classification, approval gates, interrupts/fork-join, and per-state model routing on AI coding agents, with a direct-to-Ollama agent binary and self-hosted PocketBase stack.

## Implementation Check

Every headline README claim maps to working code I read: engine transitions/guards/validation in crates/engine/src/{transition,guard,validate}.rs, the ten advertised MCP tools in crates/mcp-gateway/src/custom_tools.rs (statewright_run_agent, statewright_force_state gated on meta.debug in gateway.rs), the starter workflow at workflows/agentic-engineering.json, and the native Claude plugin at plugins/claude-code/hook.sh — with the README itself hedging its research (5-task subset) and model-routing claims.

## When to Use

Use when you want deterministic, per-phase tool enforcement, human approval gates, and model routing for AI coding agents across Claude Code, Codex, Pi, OpenCode, Cursor, or OMX, or as an embeddable Apache-2.0 state-machine crate. Not when you need an OSI license for the gateway/plugins (FSL-1.1-ALv2 until 2029) or want zero infrastructure: full features need the managed cloud or a self-hosted PocketBase/Postgres gateway, and enforcement quality depends on each host's hook surface.

## Sub-scores

| Dimension | Score |
|---|---|
| quality | 4.5/5 |
| usability | 4.0/5 |
| reliability | 3.0/5 |
| security | 4.0/5 |
| integration | 4.5/5 |

## Code Evidence

crates/engine/src/transition.rs resolve_transition implements exact, target-name-fuzzy, substring, and safe_next fallback matching with ~30 inline unit tests; crates/engine/src/validate.rs validate_definition does BFS reachability, guard resolution, and delivery-policy coherence checks; crates/engine/src/guard.rs evaluate_guard covers eq/neq/gt/gte/lt/lte/in/contains/exists. crates/mcp-gateway/src/bash_classifier.rs is a serious fail-closed shell classifier: simple_command_tokens rejects unquoted ;|&><`$ expansion, has_nested_shell_execution detects $() and backticks, runtime_injection_environment blocks BASH_ENV/LD_*/NODE_OPTIONS/CARGO_* assignments, network_pseudo_device_target rejects /dev/tcp redirect targets, and OpClass::required_tools maps redirects to Write and destructive ops to always-blocked sentinels. crates/agent/src/tool_enforcer.rs enforce_tools gives disallowed_tools precedence over allowlists and classifies exploratory_read_only intent conservatively. crates/agent/src/orchestrator.rs runs invoke sub-machines with max_depth recursion guards, tested against in-process mock HTTP servers. plugins/claude-code/hook.sh passes bearer tokens to curl via a config stream (-K) instead of argv, parses gateway URLs with a strict WHATWG-aware regex (statewright_url_parts), and the adapter pre-tool path fails closed (deny on missing/malformed decision). crates/mcp-gateway/src/remote.rs streamable_session_key isolates tenants by API-key fingerprint with UUIDv5 client/branch scoping, and revalidates the key against PocketBase on every request. .github/workflows/ci.yml runs cargo check/test/build plus a plugin-contract matrix (npm ci, node --test, task test:plugin-release). workflows/agentic-engineering.json is a real 11-state workflow whose APPROVED transitions are guarded on recorded validation evidence.

## Issues Found

plugins/claude-code/hook.sh user-prompt handler deletes the state cache when the gateway is unreachable ('Running without workflow enforcement this turn'), making the legacy direct-MCP pre-tool path fail-open; crates/mcp-gateway/src/remote.rs handle_approval_callback skips bearer authentication entirely when APPROVAL_CALLBACK_SECRET is unset and only fails closed for native_ sessions, so a default self-hosted deployment (self-hosted/docker-compose.yml sets no secret) accepts unauthenticated approval approve/reject callbacks on the exposed 3001 port; 49 unpinned third-party GitHub Actions across .github/workflows are a supply-chain hygiene gap; crates/cli/src/main.rs (691KB) and crates/mcp-gateway/src/gateway.rs (480KB) are unmaintainable monoliths.

## Key Risks

Nothing was executed — 'tests exist' was verified by reading inline #[cfg(test)] modules and CI config, not by running them. The docs site (docs.statewright.ai) and managed cloud are off-repo and unverifiable here. Licensing is mixed: engine/agent are Apache-2.0 but the MCP gateway and all plugins are FSL-1.1-ALv2 (source-available, converts to Apache-2.0 in 2029), matching the NOASSERTION license signal. Single maintainer (top_author_share 1.0) with extreme churn (573 commits/90d) is a bus-factor risk. README research results are a 5-task SWE-bench subset, disclosed as such. Monolithic files (crates/cli/src/main.rs 691KB, crates/mcp-gateway/src/gateway.rs 480KB) will slow maintenance. Bash discernment strength varies by path: the Rust classifier/gateway and managed executor paths are strict, while the legacy direct-MCP Claude hook path uses weaker grep heuristics and fails open when the gateway is unreachable.

## Reviewed Files

- `README.md`
- `Cargo.toml`
- `crates/engine/Cargo.toml`
- `crates/engine/README.md`
- `crates/engine/src/lib.rs`
- `crates/engine/src/transition.rs`
- `crates/engine/src/guard.rs`
- `crates/engine/src/validate.rs`
- `crates/engine/src/interrupt.rs`
- `crates/agent/src/tool_enforcer.rs`
- `crates/agent/src/orchestrator.rs`
- `crates/agent/src/ollama_client.rs`
- `crates/cli/Cargo.toml`
- `crates/mcp-gateway/Cargo.toml`
- `crates/mcp-gateway/src/lib.rs`
- `crates/mcp-gateway/src/bash_classifier.rs`
- `crates/mcp-gateway/src/remote.rs`
- `crates/mcp-gateway/src/gateway.rs`
- `workflows/agentic-engineering.json`
- `.github/workflows/ci.yml`
- `.gitleaksignore`
- `plugins/claude-code/plugin.json`
- `plugins/claude-code/hook.sh`
- `plugins/claude-code/install.sh`
- `plugins/omx/install.sh`
- `self-hosted/docker-compose.yml`
