AI Slop Cleaner: AST-Powered Dead Code Removal with Test-Verified Rollback

View on GitHub

Pipeline Architecture

The Problem

Every codebase accumulates drift - imports left behind after refactors, functions no one calls anymore, helpers that quietly doubled in complexity. Manual sweeps are tedious and regex-based cleanups delete the wrong thing and break production.

NEO built AI Slop Cleaner to detect and safely remove that drift using tree-sitter AST analysis, with an atomic patch-and-verify pipeline that rolls back automatically when tests fail.

Five-Phase Pipeline, Tree-Sitter Throughout

AI Slop Cleaner ships two CLI entry points - slop-audit for read-only scanning and slop-clean for full pipeline execution. Both walk Python and TypeScript/TSX files through tree-sitter parsers rather than regex, so aliased imports, string annotations, decorators, and multi-line import blocks are all resolved against the actual syntax tree.

PhaseModuleResponsibility
1. Auditengines/auditor.pyTree-sitter parse, flag unused imports (HIGH) and complex functions (MEDIUM)
2. Analyzeengines/analyzer.pyBuild call graphs across symbols, mark dead functions and classes
3. Cleanengines/cleaner.pyApply HIGH-confidence patches atomically with file backups
4. Verifyengines/verifier.pyRun pytest; rollback every change if the suite fails
5. Documentengines/documenter.pyEmit ARCHITECTURE.md, FUNCTION_MAP.md, SLOP_REPORT.md

Only HIGH-confidence changes get applied automatically. Dead functions and high-complexity hot spots are flagged in the report rather than silently deleted, so a reviewer decides.

CLI Shape and CI Integration

# Read-only scan - exit 0 if clean, 1 if issues (CI-friendly)
slop-audit <target> [--output JSON] [--threshold N] [--verbose]

# Full pipeline with atomic patches and rollback
slop-clean <target> [--output DIR] [--threshold N] [--dry-run] [--verbose]

The default cyclomatic-complexity threshold is 10; pass --threshold 12 to loosen it for legacy code. --dry-run prints the patch set without touching disk. Because slop-audit returns non-zero on any finding, dropping it into a CI step fails the build when slop lands in a PR.

git clone https://github.com/dakshjain-1616/Ai_Slop_Cleaner
cd Ai_Slop_Cleaner
python3 -m venv .venv && source .venv/bin/activate
pip install -e .

slop-audit examples/todo_app/ --verbose
slop-clean examples/todo_app/ --dry-run
slop-clean examples/todo_app/

What Gets Rewritten vs. Flagged

Unused imports in from foo import a, b, c where only b is referenced get surgically rewritten to from foo import b. Entirely-unused multi-line import blocks are deleted as a unit. Single-line unused imports are removed outright. Across every rewrite, the cleaner writes a backup of the file first; if the post-clean pytest run reports a failure, every backup is restored, so a broken test suite is never left behind.

Flagged-but-not-auto-fixed findings (dead functions, high-complexity methods, unreferenced classes) land in SLOP_REPORT.md with file and line references, and the call-graph view lives in FUNCTION_MAP.md. Dependencies stay minimal: tree-sitter >= 0.25, tree-sitter-python, tree-sitter-typescript, and rich for the CLI output.

How to Build This with NEO

Open NEO in VS Code or Cursor and describe what you want to build. A good starting prompt for this project:

"Build a Python CLI called slop-cleaner with two entry points, slop-audit and slop-clean, that walks Python and TypeScript/TSX files through tree-sitter parsers. Implement a five-phase pipeline: audit (flag unused imports and functions over a cyclomatic complexity threshold), analyze (build a call graph to identify dead code), clean (apply HIGH-confidence patches atomically with per-file backups), verify (run pytest and rollback all changes if it fails), and document (emit ARCHITECTURE.md, FUNCTION_MAP.md, and SLOP_REPORT.md). Support --dry-run, --threshold, --verbose, and return non-zero exit codes when issues are found so it works in CI."

Build with NEO →

NEO scaffolds the parsers, the phase engines, and the CLI wiring. From there you iterate - add a Go or Rust parser, wire in coverage data to raise confidence on dead-code flags, or emit a GitHub Actions workflow that opens a cleanup PR automatically. Each turn builds on the scaffolding already in place.

To run the finished project:

git clone https://github.com/dakshjain-1616/Ai_Slop_Cleaner
cd Ai_Slop_Cleaner
python3 -m venv .venv && source .venv/bin/activate
pip install -e .
slop-clean examples/todo_app/

Point it at a directory and every HIGH-confidence cleanup is applied, verified, and rolled back on failure - everything else lands in the report for a human to look at.

NEO built a safe, AST-aware cleanup pass that turns periodic dead-code purges into a single command. See what else NEO ships at heyneo.com.


Try NEO in Your IDE

Install the NEO extension to bring AI-powered development directly into your workflow: