Skip to main content
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".

The useful bit from code-forensics research is concentration: 2-8% of files cause 60-90% of defects. Black Box Unlock gives AI coding agents those signals through MCP tools and a Claude Code plugin.

How it works

Coding agents ask bbu-mcp for forensic evidence before they inspect or edit code. Ranked hotspots and coupled files guide their focus, the edit hook warns about companion files, and a fresh change review returns up to three checks.

A coding agent calls bbu-mcp to read Git history, current code, and optional CI evidence. Hotspots, coupling, ownership, bug-fix history, and function X-Ray guide file inspection. The edit hook warns about coupled files; fresh review returns up to three checks and retains rename history. CLI JSON, the Claude Code plugin, and offline HTML are also available.

For agents (MCP + plugin)

The agent calls bbu-mcp before it reads or edits code, and uses the ranked evidence to decide which files to inspect first.

The coding agent queries bbu-mcp for ranked repository evidence, then inspects and edits files. The PostToolUse coupling guard warns about companion files. Explicit review_change queries return fresh, rename-aware checks.

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, review_change. The CI tools return status and errors, so a missing or partial GitHub response cannot look like a clean result. Failed-run data includes the workflow, run URL, commit, time, and paths changed in that commit. Those paths are implicated by the failed run, not proven to have caused it.

The Claude Code plugin in this repo adds /review-change, /analyze, /hotspots, a git-forensics agent, and an ambient coupling guard that warns when you edit one half of a repeatedly coupled file pair. The hook parses Claude's JSON directly and does not require jq. 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 .

analyze-repo uses the gh CLI for CI data by default; pass --no-ci to skip it. review-change queries GitHub only when a profile or --include-ci turns that signal on.

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

# Review branch commits and local work from the upstream merge base
bbu review-change --base origin/main

# Review only staged work, or only unstaged and untracked work
bbu review-change --staged
bbu review-change --working-tree

# Use a named .bbu.toml profile and retain failed workflow details
bbu review-change --profile release

# Diagnose local activation (CI and gh remain optional)
bbu doctor

Project configuration

Add .bbu.toml when the built-in path roles or review defaults do not fit the repository:

default_profile = "release"

[[path_roles]]
pattern = "app/**/*.vue"
role = "source"

[[path_roles]]
pattern = "snapshots/**"
role = "generated"

[profiles.release]
days = 180
min_coupling = 0.4
min_shared_revisions = 3
include_ci = true
max_actions = 3

Project path rules run in file order before the built-in rules. Named profiles set review defaults; command-line and MCP arguments override the selected profile. Invalid configuration stops the review with a clear error. The full format and glob rules are in docs/CONFIGURATION.md.

Features

Signal Description
Hotspot Score commits × indentation complexity - identifies unstable complex code
Temporal Coupling Files changing together above the configured threshold reveal hidden dependencies; repeated evidence ranks by a 95% Wilson lower bound and bulk commits touching >50 files are excluded
Change Review A fresh branch, staged, or working-tree review returns at most three typed actions with raw evidence
Ownership Risk More than three authors marks a coordination risk
Build Failures Failed workflow links and files changed in each failed commit, reported as implication rather than causation
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 in the four repos with enough bug-fix signal (39.5% across all six); 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 output is a self-contained investigation workspace:

  • Files - searchable, sortable metrics with a persistent evidence panel
  • Risk matrix and change landscape - two routes into the same selected file
  • Coupling evidence - confidence-first pairs with support and denominators
  • CI and signals - collection status, failed runs, flaky steps, and policy

The report opens in Code only scope: source files and migrations, with coupling limited to pairs whose two endpoints are in that scope. Tests, configuration, documentation, generated files, and repository metadata remain available through the scope selector.

Numeric evidence columns use proportional heat bars scaled to the current scope. The change landscape groups files by code area without repeating low-information repository path levels.

Pinned ECharts and Tabulator assets are embedded in the document, so opening a saved report makes no CDN requests. Charts are supplementary: the evidence needed to interpret them remains in keyboard-operable grids and text panels.

Git history and optional CI feed shared forensic analysis. bbu-mcp returns ranked evidence to the coding agent. CLI JSON and an offline HTML report expose the same analysis through searchable evidence, a risk matrix, and a repository map.

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/      # Offline HTML investigation workspace

Development

# Install development dependencies and the Git hook
uv sync --all-extras --dev
uv run prek install

# Run the same quality and security checks as CI
uv run prek run --all-files

# Run tests
uv run pytest -v

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

The prek gate covers repository hygiene, Ruff, Pyrefly, GitHub Actions linting, Markdown and link checks, workflow security, and locked-dependency auditing. Link and dependency checks need network access.

License

MIT

Metadata

Release files for black-box-unlock 1.5.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for black-box-unlock 1.5.2
File Size Uploaded
black_box_unlock-1.5.2.tar.gz 3.9 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for black-box-unlock 1.5.2
File Interpreter ABI Platform
black_box_unlock-1.5.2-py3-none-any.whl Python 3 none any Details

Total release size: 4.5 MB

Release files / black_box_unlock-1.5.2.tar.gz

Download URL black_box_unlock-1.5.2.tar.gz
Size 3.9 MB
Tags Source
SHA-256 checksum
How to use checksums
213fb21587a0483ac2871b1cc9af834dcadc957e5489ec0ca94d3ed42e43b59c
BLAKE2b-256 checksum
How to use checksums
8f1f13288726a3bafc22133d162fe4f8b912337d27d5471e9efe7cfc2c1fe5eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

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 Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 10, 2026.

Transparency log

Release files / black_box_unlock-1.5.2-py3-none-any.whl

Download URL black_box_unlock-1.5.2-py3-none-any.whl
Size 632.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fdffe8314d615cdef519ce7167f6d2e9fc5035ea02a3be9d76978cc62586b868
BLAKE2b-256 checksum
How to use checksums
f81cb78ae7009b9cdb78c3e9466e23aa1287b68d287dfb39ca0671c0d014d093
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

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 Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 10, 2026.

Transparency log

Release history Release notifications | RSS feed

2.1.0

2 release files

2.0.1

2 release files

2.0.0

2 release files

This release

1.5.2 This release

2 release files

1.5.1

2 release files

1.5.0

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page