Skip to main content

Code forensics tool - investigate your codebase like a crime scene

Project description

Black Box Unlock

CI License: MIT Python 3.10+ Ruff

Black Box Unlock

Mischief. Mayhem. Merge conflicts. Exposed.

Code forensics tool based on Adam Tornhill's "Your Code as a Crime Scene".

Key insight: 2-8% of files cause 60-90% of defects. Built for AI coding agents: forensic signals as MCP tools and a Claude Code plugin, so reviews and refactors are prioritized by evidence.

For agents (MCP + plugin)

uv tool install black-box-unlock   # provides bbu and bbu-mcp

Register the MCP server in Claude Code (.mcp.json):

{ "mcpServers": { "black-box-unlock": { "command": "bbu-mcp" } } }

Tools: get_hotspots, get_file_forensics, get_coupled_files, get_ownership, get_ci_failures, get_flaky_steps, xray_file.

The Claude Code plugin in this repo adds /analyze, /hotspots, a git-forensics agent, and an ambient coupling guard that warns when you edit one half of a temporally coupled file pair. Install it via the self-hosted marketplace:

/plugin marketplace add michael-denyer/black-box-unlock
/plugin install black-box-unlock@black-box-unlock

Both bbu and bbu-mcp must be on PATH for the plugin and MCP server to work.

CLI

Installation

uv pip install -e .

CI failure analysis additionally uses the gh CLI when available (skip with --no-ci).

Usage

# Analyze last 30 days of git history, output JSON
bbu analyze-repo --days=30

# Generate interactive HTML report
bbu analyze-repo --days=30 --output=html > report.html

# Adjust coupling detection threshold (default 0.3)
bbu analyze-repo --min-coupling=0.5 --output=html > report.html

# Skip CI failure analysis (faster, no GitHub access needed)
bbu analyze-repo --no-ci --output=html > report.html

# Analyze a different repository
bbu analyze-repo --repo /path/to/repo --output=html > report.html

# Per-function churn for one file (Tornhill's X-Ray)
bbu xray src/hot_file.py --days 365

Features

Signal Description
Hotspot Score commits × indentation complexity - identifies unstable complex code
Temporal Coupling Files changing together >30% reveal hidden dependencies
Ownership Risk >3 authors + high churn = coordination problems
Build Failures Files appearing in CI failures = fragile code
Bug-fix Density Count of defect-repair commits per file
Flaky Steps CI steps that failed then passed on re-run
Function X-Ray Per-function churn × complexity for hot files (docs/XRAY.md)

Does the ranking actually predict bugs?

Measured with bbu validate (split-history: rank hotspots on the older half, count bug-fix commits in the newer half): median Spearman rho 0.46 across six real repos (click, flask, pydantic, rich, fastapi, httpx); the top 10% of ranked files attracted a median 46% of subsequent bug-fix touches — uniform would be 10%. Method, per-repo numbers, and limitations: docs/VALIDATION.md.

bbu validate --repo /path/to/repo --days 730

HTML report

The HTML report includes three interactive views:

  • Table - Sortable file metrics with severity coloring
  • Hotspots - Plotly treemap showing file churn by directory
  • Coupling - Cytoscape.js network graph of temporal coupling

The HTML report is feature-frozen; new signals land in JSON and MCP only.

flowchart LR
    Git[Git History] --> Analyze[bbu analyze-repo]
    CI[GitHub Actions] --> Analyze
    Analyze --> JSON[JSON Output]
    Analyze --> HTML[HTML Report]
    HTML --> Treemap[Hotspot Treemap]
    HTML --> Graph[Coupling Graph]

Architecture

See docs/ARCHITECTURE.md for full details.

src/black_box_unlock/
├── cli.py              # Typer CLI
├── complexity.py       # Indentation-depth complexity proxy
├── analysis.py         # Orchestration
├── core/               # Pydantic models, exceptions, logging
├── git/                # Churn, coupling, ownership, defects, log extraction
├── cicd/               # CI/CD forensics (build failures, flaky steps via gh CLI)
└── visualization/      # HTML, treemap, coupling graph (frozen)

Development

# Run tests
uv run pytest -v

# Lint and format
uv run ruff check . && uv run ruff format .

# Verbose output for debugging
bbu --verbose analyze-repo

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

black_box_unlock-1.1.0.tar.gz (1.7 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

black_box_unlock-1.1.0-py3-none-any.whl (42.1 kB view details)

Uploaded Python 3

File details

Details for the file black_box_unlock-1.1.0.tar.gz.

File metadata

  • Download URL: black_box_unlock-1.1.0.tar.gz
  • Upload date:
  • Size: 1.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for black_box_unlock-1.1.0.tar.gz
Algorithm Hash digest
SHA256 d51ef206b00fb2f3ca84e3c5cba0eabc8a13754cf02440c10d71c516b034ea8e
MD5 292a11f8f62beda30cd5a3e63a440742
BLAKE2b-256 4c940458154e8102fde9a7bcb608d9e99afc1ccd53103a6451bbd630778c3b99

See more details on using hashes here.

Provenance

The following attestation bundles were made for black_box_unlock-1.1.0.tar.gz:

Publisher: release.yml on michael-denyer/black-box-unlock

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file black_box_unlock-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for black_box_unlock-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 70c6a50ecff0a5e6b60ca1434b49a3d5df29dfb988689dbc14b739248ce293ea
MD5 ae1a80d4fca6791e67b69d56779bf744
BLAKE2b-256 431a27a864d519be222bdf998669b0f9233a779572e8389ccfacd783449336e3

See more details on using hashes here.

Provenance

The following attestation bundles were made for black_box_unlock-1.1.0-py3-none-any.whl:

Publisher: release.yml on michael-denyer/black-box-unlock

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page