# Granular Review Protocol: Codebase Curation

This protocol defines the mandatory procedure for auditing and modifying files during the Phase 5 Heavy Curation. It is designed to minimize entropy and prevent regression propagation.

## 1. File-by-File Audit Cycle

For every `.py` file identified for curation:

1.  **Dependency Check:** Use `derive_code_path` and `py_get_imports` to identify all upstream and downstream dependencies.
2.  **State Verification:** Consult the `MUTATION_MATRIX_PHASE5.md` to identify any global state modifications performed by the file.
3.  **Redundancy Identification:** Cross-reference the file against `CULLING_CANDIDATES_PHASE5.md`.
4.  **Proposed Change Log:** Before editing, document the specific lines/symbols to be removed or refactored and the technical justification (e.g., "Superseded by theme_2.py").
5.  **Surgical Edit:** Use the `replace` tool for targeted deletions. Avoid bulk file overwrites.
6.  **Style Verification:** Immediately run `scripts/ai_style_formatter.py` on the modified file to ensure indentation and formatting standards are maintained.

## 2. Regression Guardrails

- **Functional Parity:** After every major deletion (e.g., removing a redundant module), run the associated unit tests (if any).
- **Simulation Verification:** For changes to core pipelines (AI loop, Aggregation), run at least one relevant simulation (e.g., `simulation/ping_pong.py`) to verify end-to-end behavior.
- **Human-in-the-Loop:** Significant refactors (e.g., the `aggregate.py` rework) MUST be presented to the user with a detailed diff before final commitment.

## 3. Culling Justification Standards

- **"Unused"**: Symbol has 0 project-wide references in the audit.
- **"Redundant"**: Logic exists in a superior or more modern form elsewhere (e.g., `theme.py`).
- **"Slop"**: Code that adds complexity without contributing to performance, configuration, or a specified feature.
