A full-stack system that transforms 28 raw candidate nodes into a structured, token-efficient context string that fits within a hard 4,000-token ceiling.
cd backend
pip3 install fastapi uvicorn supabase python-dotenv tiktoken
uvicorn main:app --reload --port 8000cd frontend
npm install
npm run dev
# Opens at http://localhost:3000Edit .env with your Supabase URL and key. Without it, the app uses local JSON data.
| Module | File | Purpose |
|---|---|---|
| Token Counter | token_counter.py |
tiktoken 3-source counting (BEFORE API call) |
| Importance Scorer | importance_scorer.py |
Dual retrieval + injection weights |
| Block Assembler | block_assembler.py |
8-block fixed-order structure |
| Compressor | compressor.py |
Distance-weighted levels + CONSTRAINT protection |
| Budget Fitter | budget_fitter.py |
Iterative compression loop |
| Context Builder | context_builder.py |
Final string assembly |
28 nodes → Dual Importance Scoring → 8-Block Assembly
→ Distance-Weighted Compression → 3-Source Token Count
→ Iterative Budget Fitting → Context String Output
- CONSTRAINTs are ALWAYS FULL — never compressed regardless of distance or budget
- 3 sources counted BEFORE API call: system prompt + context + user reserve
- 8-block order is LOCKED: 1→2→3→4→5→6→7→8, never reordered
- Block 7 (Stale) only appears when REVIEW_REQUIRED nodes exist
- Lowest injection_weight non-CONSTRAINT compressed first
- 28 candidate nodes with 3 compression levels
- tiktoken cl100k_base token counting
- ALL THREE sources counted before API call
- 8 blocks in correct locked order
- CONSTRAINT nodes always FULL
- Iterative compression with CONSTRAINT protection
- Dual importance weights visible per node
- Compression log pass-by-pass
- Budget slider (1000–6000) with live recomposition
- Context string viewer modal
- Block 8 CAPTURE instruction
- docs/architecture.md