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.2.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.2.0-py3-none-any.whl (45.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: black_box_unlock-1.2.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.2.0.tar.gz
Algorithm Hash digest
SHA256 6282f4084b152f6dff7f81f069f586ac6aa0e9b91a882cda7ec70ca48aadf4ab
MD5 fc6453a813feb9ee7e117e31f46d8dbd
BLAKE2b-256 271a9aaa8f9a0cdb4ef6e2046b142740114b3b1362679bfe2c94cd96f4cc2321

See more details on using hashes here.

Provenance

The following attestation bundles were made for black_box_unlock-1.2.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.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for black_box_unlock-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 18a0dc37213930c59702b211f50e682a1002f6d28333a13eb503f792b56a39f7
MD5 e1756505c637263f053a1f76f7043371
BLAKE2b-256 9ca7aa36ab9751766088c9817cadacc6e6244002009250b1d465e3f97ee913b5

See more details on using hashes here.

Provenance

The following attestation bundles were made for black_box_unlock-1.2.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