π₯ PHANTOM Surgical Repair Plan
Date: 2026-01-07 Objective: Modularize the codebase, separate concerns (Vertex AI vs. Core Logic), fix critical bugs, and establish robust health checks.
π Current Status & Diagnosisβ
| Component | Status | Issues Identified |
|---|---|---|
CLI (cerebro) | β οΈ Partial | ingest fails with Error 400 (Batch Size). query returns empty if no data. Missing health check. |
| RAG Engine | β Broken | VertexAIEmbeddings used without batching. 1184 docs sent > 250 limit. Tightly coupled to LangChain/Vertex. |
| Tests | β οΈ Weak | Unit tests mock everything. No integration tests to catch API limits. |
| Architecture | πΈοΈ Monolithic | src/phantom/core mixes logic. No clear API boundaries. |
| CI/CD | π’ Basic | Runs scripts/ci-test.sh. Needs expansion. |
π οΈ Execution Planβ
Phase 1: Stabilization & Diagnostics (Completed)β
- Document Missing Coverage: Created
docs/COVERAGE_GAP.md. - Implement Health Check:
- Created
phantom ops healthcommand. - Check: Write permissions, Vertex AI connectivity (ping), Vector DB accessibility.
- Created
- Fix Critical Bug (
ingest):- Implemented batching (chunk_size=20) in
RigorousRAGEngine.ingest. - Added exponential backoff for Rate Limits.
- Fixed Analysis engine (Indentation + TreeSitter fallback).
- Verified fix with
just ingestand Integration Tests.
- Implemented batching (chunk_size=20) in
Phase 2: Modularization (The Surgery)β
- Define Interfaces (Abstract Base Classes):
src/phantom/interfaces/llm.py:LLMProvidersrc/phantom/interfaces/vector_store.py:VectorStoreProvider
- Refactor
core/rag:- Move Vertex AI specific code to
src/phantom/providers/gcp/. - Move Chroma specific code to
src/phantom/providers/chroma/. RigorousRAGEngineshould depend on Interfaces, not concrete classes.
- Move Vertex AI specific code to
- Decouple "Credit Burner" from "RAG":
- Ensure
VertexAIusage for RAG (Trial Credits) is distinct from any production API usage.
- Ensure
Phase 3: Testing & Quality Assuranceβ
- Integration Tests:
- Create
tests/integration/test_vertex_limits.py(Real API call with batching).
- Create
- Unit Tests:
- Update tests to mock the new Interfaces.
- CI Pipeline:
- Update
.github/workflows/ci.ymlto run linting (ruff) and integration tests (if secrets present).
- Update
Phase 4: Documentation & Polishβ
- API Documentation: Document the new Interfaces.
- Developer Guide: Update
CONTRIBUTING.mdwith new module structure. - Justfile: Update recipes to support
just health,just test-integration.
π Next Stepβ
Awaiting approval to begin Phase 1: Stabilization & Diagnostics.