The Code Slob Cleanup process follows a rigorous lifecycle to ensure that code is cleaned effectively and safely. The agent chooses between two main workflows based on your request.
Before starting, the agent determines if you want to Refactor new code or Revert a previous cleanup.
In this phase, the toolchain identifies potential “code slob” candidates and prepares a temporary workspace for refactoring.
code-slob-cleanup.json (auto-generating it if it does not exist) to strictly exclude specific paths or functions.scripts/clean_untested.py script is used to remove code that is not executed by a provided test suite.scripts/identify.py to find complex or verbose functions using static analysis. It supports flags to target specific slob identifiers:
--global-variables: Detect non-constant global variables.--complexity: Analyze cyclomatic complexity.--lloc: Analyze logical lines of code.--public-private: Identify public members that should be private.--duplicates: Analyze code duplication (functional clones)..code-slob-tmp/) along with their dependencies and type hints.The tool applies clean, idiomatic Python patterns to the extracted “original” code.
refactored.py version of the code that is easier to read, maintain, and more efficient.This is the most critical phase. The toolchain uses property-based testing to prove that Original(input) == Refactored(input).
Original and Refactored functions are executed with the same inputs using Hypothesis.Once a function passes verification, it is moved back into the main codebase.
edits dictionary in code-slob-cleanup.json, storing the function identifier and the parent commit hash. This enables future reverts.The temporary workspace .code-slob-tmp/ is deleted, leaving the codebase clean.
If you ask to “revert” or “undo” a cleanup, the agent follows this path:
edits map in code-slob-cleanup.json to find the functions, classes, files, or folders you mentioned.git show, the agent retrieves the original version of the code as it existed before the cleanup.edits dictionary.