Skip to main content
Glama
forensic-contracts

forensic-contracts

README.md
# `forensic-contracts`

[![CI](https://github.com/JavierFrancoLeal/forensic-contracts/actions/workflows/ci.yml/badge.svg)](https://github.com/JavierFrancoLeal/forensic-contracts/actions/workflows/ci.yml)
[![License: Apache-2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](LICENSE)

**Make AI-generated code explain itself in hours, not weeks — and mechanically block any function that escapes its declared `@blast-radius` cage.**

![forensic-contracts terminal demo](assets/demo-terminal.svg)

`forensic-contracts` is the 5th flagship in the open-source Agent Governance suite (alongside [`casebook`](https://github.com/JavierFrancoLeal/casebook), [`dual-brain-guard`](https://github.com/JavierFrancoLeal/dual-brain-guard), [`autonomy-ladder`](https://github.com/JavierFrancoLeal/autonomy-ladder), and [`governed-browser`](https://github.com/JavierFrancoLeal/governed-browser)). It compiles the forensic code-archaeology doctrine from `jfranco-forensic-contracts` and the literal `sourcePin` verifier from `jfranco-apices` into a **zero-dependency Node.js CLI, stdio MCP Server, and portable plugin**.

---

## What `forensic-contracts` Enforces

1. **The 5-Line Forensic Contract (`@forensic-contract`):**
   Every critical function carries `@id`, `@origin`, `@invariant`, `@blast-radius`, and `@golden-test`. Missing tags trigger `FORENSIC-CONTRACT-INCOMPLETE`.
2. **The Blast-Radius Cage Enforcer (`FORENSIC-CAGE-*`):**
   Scans the function body below each contract and exits `2` (`CRITICAL_BLOCKER`) if a function declared `pure` or `zero-network` calls `fetch()`/`requests.get()`, if a `read-only`/`no-fs` function mutates the filesystem, or if a `no-shell` function spawns a subprocess.
3. **Dangerous-Primitive Gate (`FORENSIC-SEC-*`):**
   Blocks `eval()`, `new Function()`, `nodeIntegration: true`, `contextIsolation: false`, and raw shell execution.
4. **Literal `sourcePin` Verifier (`RED_PARAPHRASE`):**
   Verifies character-by-character that any quote cited by an AI agent exists literally in the target source document. Paraphrases exit `2` (`RED`).

---

## 30-Second Quickstart

```bash
git clone https://github.com/JavierFrancoLeal/forensic-contracts.git
cd forensic-contracts
npm test

# 1. Audit a file or directory for @forensic-contract completeness and blast-radius cages
node src/cli.mjs scan src/

# 2. Verify a literal quote character-by-character against a source document (sourcePin)
node src/cli.mjs source-pin --file skills/forensic-contracts/SKILL.md --quote "Never Sign a Paraphrase"
```

---

## MCP Server Integration (Claude Code / Cursor / Gemini CLI / Antigravity)

```json
{
  "mcpServers": {
    "forensic-contracts": {
      "command": "node",
      "args": ["/absolute/path/to/forensic-contracts/src/mcp-server.mjs"]
    }
  }
}
```

Exposed MCP tools:
- `forensic_audit_codebase` — audits files/directories for `@forensic-contract` completeness, `@blast-radius` cage compliance, and dangerous primitives
- `forensic_verify_source_pin` — verifies character-by-character literal quotes (`GREEN` vs `RED_PARAPHRASE`)
- `forensic_generate_contract_stub` — generates a canonical 5-line `@forensic-contract` header for JS/TS or Python

---

## Technical Essay

Read the full engineering rationale in [**Code Archaeology for AI-Written Software: Why Comments Must Become Executable Cages**](docs/ESSAY_CODE_ARCHAEOLOGY_AND_BLAST_RADIUS_CAGES.md).

---

## Open-Source Agent Governance Suite

| Repository | Role | Status |
| :--- | :--- | :--- |
| **[`casebook`](https://github.com/JavierFrancoLeal/casebook)** | Bounded-entropy 4-tier constitutional memory, Open Symptoms Radar & 5-to-1 compaction oracle | **`v1.0.1` Live** |
| **[`dual-brain-guard`](https://github.com/JavierFrancoLeal/dual-brain-guard)** | Harness-agnostic mechanical Proposer != Verifier cross-model guard (`CLI + MCP + hooks`) | **`v1.1.1` Live** |
| **[`autonomy-ladder`](https://github.com/JavierFrancoLeal/autonomy-ladder)** | Evidence-based Traffic-Light autonomy grader (`🟢 / ⚑ / 🟡 / 🔴` & `A/B/C/D` trust scores) | **`v1.0.2` Live** |
| **[`governed-browser`](https://github.com/JavierFrancoLeal/governed-browser)** | Constitutional commit-click brake (`🛑 RED` on Send/Pay/Delete) & SHA-256 hash-chained audit trail | **`v1.0.1` Live** |
| **[`forensic-contracts`](https://github.com/JavierFrancoLeal/forensic-contracts)** | 5-line `@forensic-contract` linter, `@blast-radius` cage enforcer & literal `sourcePin` verifier | **`v1.0.1` Live** |
| **[`agent-governance`](https://github.com/JavierFrancoLeal/agent-governance)** | Complete 26-plugin DeepSeek Harness governance suite (mother repository) | **`v1.0.0` Live** |
| **[`best-security-governance-architects`](https://github.com/JavierFrancoLeal/best-security-governance-architects)** | CPU-first pre-merge security & governance suite (`ECOSYSTEM_CONTRACT v1.2.0`) | **`v1.2.0` Live** |
| **[`best-ui-ux-designers`](https://github.com/JavierFrancoLeal/best-ui-ux-designers)** | Adversarial UI/UX design judgment suite — 12 Barbell design minds & 4 Via Negativa auditors | **`v1.2.0` Live** |

---

## License

Apache-2.0 — see [LICENSE](LICENSE).