← Back to Docs

Codebase Audit

Autonomous codebase health analysis powered by the trace graph. Get architecture reports, gap analysis, tech debt summaries, and actionable recommendations — all generated from your existing enrichment data.

Overview

AutoAudit analyzes your trace graph (nodes, edges, augmentations, epistemic enrichment, modules, and atlas) to produce structured findings and optional LLM-generated reports. It is a finalize pipeline stage (stage 14 of 15, running in finalize wave 2 after deep enrichment), so it runs automatically when the project's finalize group is set to auto — and you can also re-trigger it on demand via the dashboard Audit panel, the MCP prep_audit tool, or the REST stage-run endpoint.

AutoAudit V2 transforms SourcePrep from a "passive observer" into an "active taskmaster". Findings are categorized into flat tabs (Architecture, Quality, Coverage, Tech Debt), prioritized, and include concrete actionable items. You can select findings and click "Copy AI Command" to instantly hand off the context assembly to your AI via MCP.

6 findings total

1 critical · 2 warning · 2 info

Last run: 7/20/2026, 5:59:15 PM

1 critical2 warning2 info1 suggestion
AI Synthesis Available

Top Findings

GraphEnrichmentPipeline.tsx exceeds 58KB — extract stage componentsP0
SIZE-1
Action: Extract each pipeline stage into its own component.
Circular dependency between search/ and trace/ modulesP1
ARCH-1
Action: Create a shared results/ module for SearchResultsList.
GoalpostsPanel is hidden but still ships in the bundleP1
QUAL-1
Action: Use React.lazy() for sunset panels, or remove the import entirely.
Inconsistent naming: "Panel" vs "Card" vs "Widget" suffixesP2
NAME-1
Action: Standardize: use "Panel" for full-height, "Card" for compact.
No test coverage for FolderTreePanel scope-dropdown flowP2
COV-1
Action: Add integration tests with mock scope callbacks.

By Module

trace1 findings
search1 findings
goalposts1 findings
dashboard1 findings
project1 findings

Live preview: AutoAudit findings organized by severity and category with AI handoff.

Two Tiers

Tier 1 — Analyzers

Pure graph queries. No LLM needed. Runs in <2 seconds. Produces structured findings (JSON).

Tier 2 — Synthesis

LLM-generated markdown reports. Uses your configured large model. Produces 5 documents.

Quick Start

CLI

Audits are triggered via the MCP prep_audit tool, the REST API, or the dashboard's Audit panel — not a direct CLI command. To read findings from the most recent run from a terminal, use prep opportunities:

# List actionable findings from the latest audit
prep opportunities

# Filter by minimum priority
prep opportunities --priority P1

# Export as SARIF for CI ingestion
prep opportunities --format sarif

# Pipe a high-priority subset to an AI agent prompt
prep opportunities --priority P0 --format ai_prompt
claude — my-project

What a PR-sanity audit looks like when an agent calls prep_audit mid-review.

MCP Tool

One MCP tool, prep_audit, exposes all audit functionality across Cursor, Windsurf, Claude Code, and any MCP-compatible editor. The behavior is selected via the action parameter:

ActionWhat it does
scan (default)Run analyzers and return structured findings. Set synthesize: true to also generate LLM reports.
reportRead a specific generated report by name (AUDIT_SUMMARY, ARCHITECTURE_ANALYSIS, GAP_ANALYSIS, COMPONENT_INVENTORY, TECH_DEBT_REPORT).
refactorContext-assembly handoff. Pass finding_ids (e.g. ["ARCH-1", "QUAL-2"]) and get back the structural trace graph for all affected files, priming the AI for an immediate refactor.
verifyRe-run a named subset of analyzers to confirm recent edits actually resolved the finding.
antibodiesList immune-system defenses derived from concept assertions.

Findings can also be passed in via the findings parameter to enrich external lint output (ruff, eslint, semgrep, SARIF) with structural context — see the Audit Enrichment guide.

REST API

MethodEndpointPurpose
POST/projects/{id}/pipeline/stages/audit/runTrigger audit as a finalize stage through the orchestrator (runs Tier 1, then attempts Tier 2 synthesis; Tier 2 is skipped only on synthesis failure)
GET/projects/{id}/audit/statusCheck progress and last run metadata
GET/projects/{id}/audit/findingsRaw structured findings (filterable)
GET/projects/{id}/audit/reportsList generated report documents
GET/projects/{id}/audit/report/{name}Read a specific report

Built-in Analyzers

AutoAudit ships with 11 analyzers. Each reads the trace graph and produces structured findings — no LLM, no side effects.

AnalyzerCategoryWhat It Finds
large_filessizeFiles over configurable line thresholds
circular_depsarchitectureImport cycles (Tarjan's SCC algorithm)
misplaced_importsarchitectureCross-module dependency bottlenecks
hub_bottlenecksarchitectureFiles with disproportionate fan-in (z-score outliers)
dead_codequalityFiles with zero importers that aren't entry points
duplicate_logicqualityFiles with suspiciously similar summaries (Jaccard)
tech_debtqualityAggregated tech debt from epistemic enrichment
stalenessqualityEnrichments that are out of date
test_coveragetestingSource files with no associated test file
naming_consistencynamingLanguage-specific naming convention violations
api_surfacecoveragePublic symbols missing docstrings

Generated Reports

When you run an audit with synthesize: true (via the MCPprep_audit tool or the REST API), an LLM generates 5 markdown documents from the findings:

  • AUDIT_SUMMARY — Health grade (A–F), critical findings, top recommendations
  • ARCHITECTURE_ANALYSIS — Module dependency flow, bottlenecks, boundary violations
  • GAP_ANALYSIS — Misplaced concerns, duplicated logic, missing abstractions
  • COMPONENT_INVENTORY — Every file with purpose, module, summary, in-degree
  • TECH_DEBT_REPORT — Debt items by module with remediation roadmap

Output Location

All audit output is stored inside the project's index directory:

# Standalone mode (default):
~/.local/share/sourceprep/projects/{project-id}/audit/
  ├── findings.json            # Raw structured findings
  ├── audit_manifest.json      # Run metadata (timestamps, counts)
  ├── AUDIT_SUMMARY.md         # LLM-generated (if synthesized)
  ├── ARCHITECTURE_ANALYSIS.md
  ├── GAP_ANALYSIS.md
  ├── COMPONENT_INVENTORY.md
  └── TECH_DEBT_REPORT.md

# Embedded mode:
/path/to/project/.sourceprep/audit/
  └── (same files)

These files are served via the audit REST API (GET /projects/{id}/audit/reports, GET /projects/{id}/audit/report/{name}) and through the MCPprep_audit tool with action report, so your AI tools can retrieve them by name. (In embedded mode the .sourceprep/audit/ directory is excluded from the walker, so reports are not surfaced via prep_search.)

Settings

Audit behavior is configurable via the audit_config section inui_config.json (edit the file directly; thresholds are read at audit-run time):

SettingDefaultDescription
large_file_threshold_bytes80,000File size for "critical" severity (~2000 lines)
large_file_warning_bytes40,000File size for "warning" severity (~1000 lines)
hub_z_threshold2.0Z-score for hub bottleneck detection
similarity_threshold0.65Jaccard threshold for duplicate logic detection
6 opportunitiesLast: 7/20/2026, 7:59:15 PM
1 critical2 warning3 info
4 actionable
large files1circular deps1dead code1test coverage1todo scanner1advisor1
P0criticallarge
OPP-001Health Scanner1 file
Action: Create trace/stages/ directory with one component per pipeline stage.
P1warningmedium
OPP-002Health Scanner2 files
Action: Extract SearchResultsList into a shared results/ module.
P1warningsmall
OPP-003Health Scanner2 files
Action: Use React.lazy() or remove from registry entirely.
P2infomedium
OPP-004Health Scanner1 file
Action: Write tests with mock scope create/rename/delete callbacks.
P2infosmall
OPP-005TODOs1 file
Action: Add exponential backoff retry with max 3 attempts.
P2infolarge
OPP-006Advisor2 files
Action: Create a shared auth/ package with middleware and token validation.
Export: prep opportunities --format sarif | json | csv | ai_promptMCP: prep_audit

Live preview: Opportunities panel consolidating all improvement items with filters and Pi Agent status.

Pipeline Connection

AutoAudit is a finalize pipeline stage. The connection:

  1. The enrichment pipeline runs to completion and produces trace_nodes, trace_augmented, trace_epistemic, trace_modules, and atlas.json.
  2. You trigger an audit (via the MCP prep_audit tool, the REST stage-run endpoint, or the dashboard Audit panel) when you want insights. The audit reads all that data and produces findings + reports.
  3. If the per-project auto_config.finalize is set to auto, the audit stage runs automatically (Tier 1 + Tier 2) when deep enrichment completes, as part of the finalize group.
  4. Audit reports are served via the audit REST API (GET /projects/{id}/audit/reports, GET /projects/{id}/audit/report/{name}) and through the MCP prep_audit tool with action report, so your AI tools can retrieve them by name.