Governance framework that makes AI coding agents trustworthy
pip install soma-governance==0.104.0 Copy PIP instructions
Soma makes AI agents trustworthy by providing observably traceable governance — evidence-based rule selection, AST analysis tools, and adaptive rule lifecycle management. Rules that stop proving themselves expire. Rules that keep proving themselves get promoted. Claims that don't match evidence are caught.
The Problem: Ungoverned AI coding agents waste significant portions of tokens in circular rework loops, hallucinated API calls, and broken assumptions. Static rule files (.cursorrules, CLAUDE.md) help but never adapt, and the agent can simply ignore them.
The Solution: Soma provides JIT context injection, adaptive rule lifecycle, and pre-commit enforcement hooks to reduce waste. Rules are scored by Wilson-bounded fitness intervals and pruned when they stop proving value.
Internal naming convention: Soma uses a biological metaphor internally (genome, organs, cells) to model rule evolution — see the codebase for details.
See the NOTICE and PRIVACY.md files for our full Data Privacy Statement.
# Clone git clone https://github.com/nseney1/Soma-Governance.git && cd Soma-Governance # Install the CLI (Python 3.9+) pip install -e . # Or install from PyPI pip install soma-governance # Set up governance (auto-detects Gemini, Claude Code, Cursor, or Copilot) soma init --yes # See what's active soma status soma: command not found (common under zsh after pip install --user)? Run python3 -m soma_cli doctor for the exact PATH line for your shell, or see QUICKSTART.md.
# Global install via Makefile (Gemini / Antigravity) make install # Install rules for specific platforms soma install --platform gemini # Google Gemini soma install --platform copilot # GitHub Copilot soma install --platform claude # Claude Code soma install --platform kiro # AWS Kiro soma install --platform mcp # Any MCP-compatible agent MCP Server (Recommended) Add Soma as an MCP server in your AI agent's config. Set SOMA_WORKSPACE to the governed project (the directory containing .soma/). No API key is needed because the host agent supplies the model.
{ "mcpServers": { "soma": { "command": "python3", "args": ["-m", "soma_mcp"], "env": { "SOMA_WORKSPACE": "/path/to/your/project", "SOMA_EXECUTION_ENABLED": "1" } } } } Works with Gemini Antigravity, Claude Code, Cursor, and any MCP-compatible agent.
Capabilities: With SOMA_EXECUTION_ENABLED omitted, the server exposes eleven read tools and four write tools. Write tools are discoverable but require a receipt. Setting SOMA_EXECUTION_ENABLED=1 additionally exposes four execute tools, which also require receipts.
Receipts expire after 300 seconds and are single-use. They are bound to the current MCP session, canonical workspace, operation, exact arguments, target-file state, and governance rule state. If a target file or any active rule changes before redemption, request a new receipt. Receipts authorize a specific state-bound operation; they do not authenticate a person. Reusing the same soma_report_outcome idempotency key with the same payload is a no-op; changing the payload for that key fails closed.
Asynchronous verification: For long-running adversarial Layer 2 checks, soma_verify_changes accepts async_mode: true. The tool immediately returns a job_token, executing verification in a background worker thread. Host agents can poll job status and retrieve signed receipts via the read-only soma_poll_verification tool without blocking.
pip install soma-governance from soma_sdk import Governance gov = Governance(project_root='.') landscape = gov.fitness_landscape(bayesian=True) coverage = gov.coverage_report() grade = gov.grade() gov.signal('wall-gae-truncation', 'tp', metric={'survival_day': 12}) CLI Commands All governance workflows are available via the soma CLI:
# Quick quality check before committing soma checkpoint # AST analysis (Layer 1) soma verify # Rule health dashboard soma oracle --json # See what rules earned promotion soma promote --dry-run Architecture Soma models governance as a layered system of rules, skills, and automation. Every component maps to a specific role:
┌──────────────────────────────────────────────────────────────────────┐ │ 📐 CORE RULES (genome/) 18 Rules — inherited defaults │ │ 🔧 AGENT SKILLS (organs/) 15 Skills — complex behaviors │ │ ⚙️ CORE & CLI (soma_core/, soma_cli/) Pure Python Governance & CLI │ ├──────────────────────────────────────────────────────────────────────┤ │ 🛡️ VERIFICATION AST analysis tools │ │ Layer 1: AST-based checks (import guards, complexity, coverage) │ ├──────────────────────────────────────────────────────────────────────┤ │ 📋 ADAPTIVE RULES (.soma/cells/) → Per-Repo Governance │ │ Vacuoles · Chloroplasts · Walls · Membranes · Plasmodesmata │ └──────────────────────────────────────────────────────────────────────┘ Layer Directory What It Contains Core Rules genome/ 18 rules — inherited behavioral defaults, rarely changed. Agent Skills organs/ 15 skills — complex multi-step behaviors like adaptive-reviewer, genesis, security-audit. Core & CLI soma_core/, soma_cli/ Pure Python governance engine, cross-platform CLI, and evidence pipeline. Verification immune_system/ AST analysis tools for code checking. Adaptive Rules .soma/cells/ Per-repo adaptive invariants. Generated, tested, evolved, or retired. 📐 Core Rules The system's foundational rules — 19 rules that define inherited behavior. Always-on rules are loaded every session; conditional rules activate on demand.
Complex multi-step behaviors — each skill performs a specialized function.
Adaptive rules are the per-repository governance layer — atomic, dynamically generated invariants that live exclusively inside your repository (.soma/cells/).
Adaptive rules operate on an evidence-based lifecycle:
Generate → Score (Confidence Decay) → Adapt → Differentiate → Prune / Retire → Promote ↑ | └──────────────────────── External Fitness Signals (CI/CD, tests, metrics) ─────┘ Lifecycle operators: Differentiation (vacuoles harden into walls), Confidence Decay (confidence decays unless reinforced), Retirement (immediate eviction on excess false positives), Horizontal Transfer (cross-project sharing with probation), Version History (provenance tracking).
Fitness scoring: Wilson-bounded fitness scoring with credible intervals — rules are scored by true positive rate using Wilson score intervals for statistically rigorous confidence bounds. Laplace smoothing (tp + 1) / (triggers + 2) provides the point estimate; Wilson bounds determine promotion and pruning thresholds. The Python SDK and CLI use the canonical parse_cell_file parser; the dependency-light MCP path uses its documented standard-library frontmatter parser.
Credit assignment: Scope-narrowed credit assignment with per-file conservation — when multiple rules match the same changed file, each rule's fitness signal is weighted by 1/N (where N = matching rules for that file). Fractional credit is stored deterministically rather than randomly rounded. Canonical events are recorded in .soma/evidence/signals.jsonl with credit and provenance metadata.
Structured crossover: Structured field-level rule merging — two high-fitness rules can be crossed to produce offspring with combined hypotheses, max impact weight, merged target paths (union), and reset fitness counters. Lineage tracking records parent IDs, generation number, and creation method.
Tournament selection: Tournament selection for rule competition — random k-sample selection identifies the highest-fitness rule per round. Read-only operation preserves rule state. Handles null fitness, oversized k, and empty rule directories gracefully.
Tiered enforcement: Rules earn their enforcement tier through demonstrated defect prevention — advisory (prompt injection) → mechanical (pre-commit block) → gate (CI block). Enforcement ladder evaluates rule invariants and applies tier-appropriate blocking.
Quorum sensing: Multi-rule consensus for high-confidence decisions — when ≥N rules trigger simultaneously on the same changed files, Soma detects a systemic issue and escalates the review mode to the highest minimum_mode among triggered rules. Quorum events are logged to JSONL for trend analysis.
Gate enforcement DSL: Rules can declare invariants in frontmatter (e.g., import_banned, file_must_exist) that are evaluated against changed files. Violations are enforced according to the rule's enforcement tier: advisory warns without blocking, gate exits non-zero in CI.
Planned features: See ROADMAP.md for upcoming work.
Soma is implemented as a pure-Python governance system with zero runtime dependencies. See SCRIPTS.md for the complete reference catalog of CLI commands, verification scripts, SDK modules, and core engines.
Copy soma.conf.example → soma.conf to customize.
Windows Support: As of v0.93.0, Windows PowerShell 5.1, PowerShell 7, and Git Bash have full parity with native lifecycle hooks (soma hook) and UTF-8 encoding (BUG-014, BUG-032). Details: Known Issues — Windows.
Soma replaces passive prompt files with active lifecycle-managed governance: JIT context loading prevents bloat, adaptive rules trap repo-specific bugs, and AST analysis catches violations deterministically.
make test # Full validation + pytest make validate # Shell syntax, Python compilation, JSON templates make doctor # System health check See CONTRIBUTING.md for test guidelines and execution instructions.
GitHub Actions runs on ubuntu-latest, macos-latest, and windows-latest:
Every feature claim in this README is tracked in docs/project/CLAIM_REGISTRY.json. A claim can only appear in README when:
Features that are planned but not yet shipped are listed in ROADMAP.md.
Remove installed governance rules and configuration across platforms:
soma uninstall # Remove Soma files for active platform soma uninstall --platform gemini # Target a specific platform (gemini, kiro, copilot, claude, mcp) soma uninstall --dry-run # Preview what would be removed without deleting soma uninstall --local # Remove from project-local directory Or via Makefile:
ai-governance agent-alignment evolutionary-rules code-review ai-coding-assistant token-optimization
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 7, 2026.




