Commit graph

4 commits

Author SHA1 Message Date
Tejas Chopra
4a655fbc6e feat: provider-aware prefix cache tracking and combined savings dashboard
Add per-provider prefix cache metrics (Anthropic/OpenAI/Google/Bedrock)
with correct economics (read discounts, write premiums, bust detection).
Model-aware bust detection excludes cold starts when switching models.
Dashboard hero metric shows combined savings (compression + cache) with
per-provider breakdown table, efficiency bar, and hit rate tracking.

- Add _CACHE_ECONOMICS dict and _build_prefix_cache_stats() helper
- Track cache_by_provider with per-model cold start awareness
- Add _merge_cost_stats() to combine compression + cache savings
- Dashboard: "Prefix Cache Impact" section with provider breakdown
- Dashboard: hero "Total Savings" shows compress + cache breakdown
- Fix ruff (unused var, quoted annotations) and mypy type errors
- Refactor code_compressor to data-driven language config

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 14:14:15 -07:00
chopratejas
9c31b22bff feat(code): add semantic symbol importance to CodeAwareCompressor
CodeAwareCompressor now analyzes intra-file symbol relationships before
compression, using tree-sitter AST walks to count references, map call
graphs, and detect public/private visibility. This replaces uniform
"keep first N body lines" compression with budget-based allocation driven
by the existing target_compression_rate config.

Key design decisions:
- Distribution-based scoring (min-max normalized within each file) so it
  adapts to any file structure: utility libs, test files, orchestrators
- Budget allocation: target_compression_rate determines total body line
  budget, distributed proportionally to importance × body size
- max_body_lines respected as a hard cap over budget allocation
- Context-aware: the existing `context` parameter now boosts symbols
  matching the user's task (word-boundary matching, not substring)
- Qualified names (ClassName.method) internally to avoid collisions
  between identically-named methods in different classes
- Omitted comments include call graph info from AST analysis
- Zero new dependencies — uses tree-sitter already in headroom[code]
- semantic_analysis=True by default, fully backward-compatible when False
2026-03-03 14:18:41 -08:00
chopratejas
2ce26438a0 Integrate DynamicContentDetector into CacheAligner (Phase 1)
- Add DynamicContentDetector integration for comprehensive dynamic content
  detection (20+ patterns vs previous 4 date patterns)
- New detection: UUIDs, API keys, JWT tokens, Unix timestamps, request/trace
  IDs, hex hashes (MD5/SHA1/SHA256), version numbers, high-entropy strings
- Add CacheAlignerConfig options: use_dynamic_detector, detection_tiers,
  extra_dynamic_labels, entropy_threshold
- Maintain backward compatibility with legacy date-only mode
- Add 25 new comprehensive tests for Phase 1 functionality
- Fix code compressor fallback test to properly mock LLMLingua availability

Expected cache hit improvement: 30-50% by extracting more dynamic content
2026-01-19 22:56:20 -08:00
chopratejas
905c229251 Add AST-based code compression and custom model configuration
CodeAwareCompressor:
- Tree-sitter based AST parsing for Python, JS, TS, Go, Rust, Java, C, C++
- Preserves imports, signatures, type annotations, error handlers
- Guarantees syntactically valid output
- Uses tree-sitter-language-pack for broad language support

ContentRouter:
- Intelligent compression orchestrator
- Auto-routes content to optimal compressor based on type detection
- Source hint support for high-confidence routing

Custom Model Configuration:
- HEADROOM_MODEL_LIMITS env var and ~/.headroom/models.json support
- Pattern-based inference for unknown models (opus/sonnet/haiku tiers)
- Support for Claude 4.5, Claude 4, o3, o3-mini
- Graceful fallback - never crashes on unknown models
2026-01-14 13:46:55 -08:00