Formal verification
MomongaCode embeds formal verification directly in the runtime and CLI: a built-in Z3 SMT solver for permission rules, skill contracts, and taint reachability, 44 TLA+ specifications checked with TLC, and live operating-system sandbox checks.
Z3 permission verification
MomongaCode compiles Z3 to WebAssembly inside the binary and checks permission rule sets across all modelled paths, commands, and MCP tools before a run starts or on demand from the shell.
Offline verification of external settings files
You do not need an API key, a configured model, or a running daemon to verify permission rules. Inside momonga, run /policy verify --file (or momonga policy verify --file from the shell for scripts and CI) against any MomongaCode or Claude Code settings.json, or an OpenCode opencode.json / opencode.jsonc:
# Inside momonga:
/policy verify --file .claude/settings.json
/policy verify --file ~/.claude/settings.json --file .claude/settings.local.json
/policy verify --file opencode.jsonc --format opencode-json
# Or from the shell for scripts and CI:
momonga policy verify --file .claude/settings.json- Auto-detection and merging.
--format auto(the default) detectssettings-json(permissions) oropencode-json(permission). Repeating--filemerges layers in order while keeping each rule's source file. - No hidden state. Offline file verification runs in-process, touches no user settings, and works in untrusted folders with no model configured.
- Honest boundaries. Unsupported tools and unmodelled patterns (such as
WebFetch(domain:...)) are listed explicitly underOutside the proof:instead of being dropped silently.
What Z3 checks
| Property | What it proves |
|---|---|
deny-precedence | No allow rule overrides a deny rule on any modelled path, command, or MCP tool. |
secret-reach | No allow rule opens ~/.ssh, ~/.aws, ~/.gnupg, ~/.azure, ~/.kube, ~/.config/gcloud, ~/.config/gh, ~/.docker/config.json, ~/.netrc, ~/.npmrc, ~/.pypirc, ~/.git-credentials, MomongaCode's home folder, the OS key store, or any path passed with --secret. |
rule-consistency | Every rule can take effect rather than being shadowed or redundant. |
bash-admission | Modelled Bash allow and deny rules agree without unintended overlap. |
superseded-forms | With --mandate, flags Bash allow rules superseded by dedicated Git/forge operations. |
mandate-holds | With --mandate, checks that operations requiring a person remain gated. |
vigil-contracts | Checks that active skill policy: frontmatter and tracePolicies parse cleanly, narrow monotonically over existing deny rules, have feasible require_before prerequisites, and remain enforced under security.vigil. |
skill-guard-reach | Proves that under security.skillGuard (fractional or binary), tainted runs cannot reach secret reads, protected writes, outside-folder writes, or unconfined/bypassed network egress sinks. |
Every counterexample Z3 finds is replayed immediately against the real TypeScript decision function (decide), reporting a model mismatch if the solver model and implementation ever disagree.
TLA+ model checking
Core daemon, model routing, supervisor, memory, and sandbox protocols are specified in TLA+ under specs/tla/ and model-checked with TLC in the test suite (44 TLA+ modules, 579 configurations—196 check rows and 383 evidence rows—covering 284,320,150 distinct states).
| Area | Modules |
|---|---|
| Daemon lifecycle & updates | Handover, UpdateSwitch, ManagedServer, RunLock, RunRecord, RunRecovery, StopProtocol |
| Policy, approvals & credentials | CredentialKey, HeldApproval, PlanCredential, PlanSignIn, AutoProbe, VigilSkillGuard |
| Execution & completion | BackgroundJob, CompletionGate, ExecutionLedger, ObservedEffect, OutputDrain, ProcessMarker, ProcessStop, LeftoverCleanup |
| Model routing, budgets & resilience | BudgetLedger, ModelRef, ModelResend, RequestBreaker, InheritRef, SettingsHealth, SettingsSwap |
| Context, memory & terminal UI | CompactAt, DerivedRepair, FactsSweeper, FidelityMemo, GroupFollowers, MemoryAuthority, MemoryAutoReview, RequestPrefix, Retention, RipgrepExtract, TerminalModes, TerminalPrepare |
Real defects caught by verification
- Refresh token reuse on persist failure (
PlanCredential). A persist fault in the two-generationPlanCredentialmodel showed TLC violatingSingleUsein43,443states: one generation wrote a rotated refresh token to memory, failed to persist to disk, released the store lock, and a second generation re-read and resent the spent token. - Mandate secret-reach refutation (
shipped-dataset-mandates). Z3 refuted all six shippedevaldataset mandates withsecret-reachbecause bareRead,Glob, andGrepallow rules opened secret locations (~/.ssh, keychains, and MomongaCode's home folder), tightening them to workspace-scoped rules (Read(./**)). - Terminal reply drain across exit paths (
TerminalModes). TLA+ modelling across start, replies, suspend, external editor, handover, and exit paths ensured terminal replies are drained on every exit transition.
Live OS sandbox check
Run /sandbox check in an interactive momonga session (or momonga sandbox check / momonga sandbox check --json from the shell) to verify the operating-system sandbox and egress proxy on the current machine inside an isolated temporary workspace (never touching real credentials or ~/.momonga):
# Inside momonga:
/sandbox check
# Or from the shell for scripts and CI:
momonga sandbox check
momonga sandbox check --json- Write outside workspace. Attempts to write outside the allowed workspace root and confirms kernel denial plus host non-existence.
- Read denied secret path. Attempts to read a sentinel file guarded by the same
readDeniedrules as~/.sshand MomongaCode's home folder, confirming kernel denial and zero sentinel output. - Direct outbound network (
deny). Attempts an outbound TCP connection to an ephemeral loopback listener undernetwork: 'deny', confirming0connections arrive. - Egress proxy & SNI enforcement. Verifies that direct loopback bypass fails, an ungranted host
CONNECTreceives HTTP403, and aCONNECTtunnel carrying a mismatched TLS SNI (evil.example) is closed with0bytes forwarded upstream. - Unix domain socket access. Attempts to connect to an ephemeral host Unix socket with
unixSocketAllow: [], confirming0connections arrive.
On macOS (seatbelt) and Linux (bubblewrap), all five probes run. On Windows (mxc), momonga sandbox check checks the PowerShell MXC sandbox (scope: PowerShell only; Bash runs unsandboxed): it probes MXC availability and runs probes 1–3 (write-outside, read-denied, and network-deny), while marking egress-proxy and unix-socket as [N/A ] because MXC refuses named-host proxy policies fail-closed and does not restrict Unix domain sockets; it exits 0 when all three applicable boundaries are [BLOCKED], and exits non-zero when MXC is unavailable or any applicable check fails. On other platforms with no OS sandbox, all five probes are marked [SKIPPED] and the command exits non-zero rather than reporting an unverified pass.