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.

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. 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

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

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.0.0.tar.gz (1.8 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.0.0-py3-none-any.whl (33.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: black_box_unlock-1.0.0.tar.gz
  • Upload date:
  • Size: 1.8 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.0.0.tar.gz
Algorithm Hash digest
SHA256 c6071fe9649c83bccac16135350cdf1d859e8b738c1dae20d80f1fb2b097dbdd
MD5 e109639a939676a9885ddcc0c6bc024a
BLAKE2b-256 8f2fe0d54ee68dc3d7afdf78b85ce6d8e1002f6836e2e63d876e8c29ad681f02

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for black_box_unlock-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 73cc02a18cc6f7994d9ee2d7dc29bf2f2c5e65cf0bb7b1b008c7f20d3fd3756a
MD5 0036f9c3660f0b696942b539a7292a7e
BLAKE2b-256 78186d356a2e1d6a4f3eb6875572d8c4e3380de6f126cf0eb84ba11e91783e0c

See more details on using hashes here.

Provenance

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