MomongaCode

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) detects settings-json (permissions) or opencode-json (permission). Repeating --file merges 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 under Outside the proof: instead of being dropped silently.

What Z3 checks

PropertyWhat it proves
deny-precedenceNo allow rule overrides a deny rule on any modelled path, command, or MCP tool.
secret-reachNo 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-consistencyEvery rule can take effect rather than being shadowed or redundant.
bash-admissionModelled Bash allow and deny rules agree without unintended overlap.
superseded-formsWith --mandate, flags Bash allow rules superseded by dedicated Git/forge operations.
mandate-holdsWith --mandate, checks that operations requiring a person remain gated.
vigil-contractsChecks 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-reachProves 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).

AreaModules
Daemon lifecycle & updatesHandover, UpdateSwitch, ManagedServer, RunLock, RunRecord, RunRecovery, StopProtocol
Policy, approvals & credentialsCredentialKey, HeldApproval, PlanCredential, PlanSignIn, AutoProbe, VigilSkillGuard
Execution & completionBackgroundJob, CompletionGate, ExecutionLedger, ObservedEffect, OutputDrain, ProcessMarker, ProcessStop, LeftoverCleanup
Model routing, budgets & resilienceBudgetLedger, ModelRef, ModelResend, RequestBreaker, InheritRef, SettingsHealth, SettingsSwap
Context, memory & terminal UICompactAt, 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-generation PlanCredential model showed TLC violating SingleUse in 43,443 states: 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 shipped eval dataset mandates with secret-reach because bare Read, Glob, and Grep allow 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
  1. Write outside workspace. Attempts to write outside the allowed workspace root and confirms kernel denial plus host non-existence.
  2. Read denied secret path. Attempts to read a sentinel file guarded by the same readDenied rules as ~/.ssh and MomongaCode's home folder, confirming kernel denial and zero sentinel output.
  3. Direct outbound network (deny). Attempts an outbound TCP connection to an ephemeral loopback listener under network: 'deny', confirming 0 connections arrive.
  4. Egress proxy & SNI enforcement. Verifies that direct loopback bypass fails, an ungranted host CONNECT receives HTTP 403, and a CONNECT tunnel carrying a mismatched TLS SNI (evil.example) is closed with 0 bytes forwarded upstream.
  5. Unix domain socket access. Attempts to connect to an ephemeral host Unix socket with unixSocketAllow: [], confirming 0 connections 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.