Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🕵🏽 Code Archaeologist

Last Commit Repo Size License

Python

Philosophy: Human-Controlled, Pattern-Driven Code Auditing.


🏫 What is this Project?

Code Archaeologist is a lightweight static analysis script built for developers who maintain a "Local Source of Truth." In an era of fast AI-generated code, it is designed for small teams and solo builders who want to keep cleanup human-controlled while navigating modern Python codebases.

Instead of mass-deleting code, it treats a repository like an archaeological dig—surfacing potential "artifacts" (uncalled functions, leftover helpers, and legacy code) in a confidence report so you can inspect them and decide what stays or goes.


🧠 How it Works

Rather than maintaining an exhaustive database of every framework, the scanner combines ast analysis with practical heuristics:

1. Embedded Ignores & Decorator Protection

  • Embedded Config (EMBEDDED_CONFIG_JSON): Any function names listed in ignore_functions are treated as protected (0% dead confidence), and directories in ignore_dirs are skipped during traversal.

  • Decorator Rule: Functions with decorators (such as routes, tasks, or registered hooks) are treated as entry points (0% dead confidence).

  • Call Tracking: Function and method names seen in ast.Call nodes are marked as used (0% dead confidence).

2. Interface & Naming Signals

For functions not already protected at 0%, naming patterns adjust the score:

  • Dunder or Capitalised Names: Names starting with __ or an uppercase letter start at 100 and drop by 60 points (e.g., 40%), treating special/internal/component-style names more cautiously.

  • Leading Underscore (_helper): Adds +10 (capped at 100%), since private helpers are still worth checking when uncalled.

3. The Dead Confidence Score

Every reported item gets a Dead Confidence percentage showing how likely an uncalled function is to be unused/dead:

  • 100%: Uncalled, undecorated function with no special dunder/capitalised protection—highest priority to review.

  • 40%: Uncalled, undecorated dunder or capitalised name—lower likelihood of being dead code, worth a quick check.

  • 0% (omitted from report): Ignored via EMBEDDED_CONFIG_JSON, decorated, or matched in recorded call names.


📂 Project Structure

code_archaeologist/
├── scanner.py                 # Standalone single-file Archaeologist script
├── archaeology_report.json    # Generated JSON report (created when run)
└── [Your Project Files]       # The "Dig Site" being scanned

🚀 Usage Guide (Single-Script Workflow)

scanner.py runs as a single, standalone script using only the Python standard library—no pip install or separate configuration files required.

Prerequisites

  • Python 3.10+ (tested on Python 3.13.7)
  • A project directory containing .py files

Running a Scan

  1. Copy scanner.py into the root folder of the project you want to inspect.
  2. Open your terminal in that folder and run:
python scanner.py
  1. Review the table printed to your terminal and check archaeology_report.json in the same folder.

Customising Ignores (EMBEDDED_CONFIG_JSON)

No external archaeo.json file is needed. Edit EMBEDDED_CONFIG_JSON directly inside scanner.py whenever you want to ignore specific function names or skip extra directories:

EMBEDDED_CONFIG_JSON = """
{
    "ignore_functions": [
        "serve_layout",
        "update_dashboard"
    ],
    "ignore_dirs": [
        ".venv",
        "build",
        "dist",
        "migrations"
    ]
}
"""

Why This Approach?

  • Zero Extra Files in Target Repos: Drop in scanner.py, run it, and tweak EMBEDDED_CONFIG_JSON right inside the script without creating extra config files.

  • Zero External Dependencies: Uses Python's standard library (ast, json, logging, pathlib, typing).

  • Local & Machine-Readable Output: Prints a quick console summary and writes archaeology_report.json for easy review or feeding into cleanup workflows.


🔐 Security & Privacy

  • 100% Local: No data leaves your machine.
  • Read-Only AST Inspection: Parses .py files with ast.parse() rather than importing or executing your application code.

🛣️ Roadmap Features

  • CLI Path & Output Options: Support target directory and output path flags via argparse so scanner.py can scan other folders without copying or renaming files manually.

  • File Pattern Ignores (ignore_files): Support glob-style filename patterns (using fnmatch) inside EMBEDDED_CONFIG_JSON to skip specific files without ignoring entire directories.

  • Confidence Filter (--min-confidence): Filter terminal and JSON report output to items meeting a minimum dead-confidence threshold during triage.


  • Built by Roy Peters 😊
  • Keeping code human-controlled, one artifact at a time.
  • Thanks for stopping by. LinkedIn

Releases

Packages

Contributors

Languages