- Documented current LLM architecture (types, runtime, retry layers)
- Documented JSONL session storage format and performance characteristics
- Analyzed opencode's SQLite schema as reference
- Analyzed 9Router's DB adapter chain and RTK compression
- Created task_plan.md and findings.md
- Implemented ComboEngine with safe streaming fallback semantics
- Error classification: pre_stream, post_stream, auth, rate_limit, timeout, context_overflow, capacity, invalid_request, abort, unknown
- Safety invariant: no fallback after first content event
- Cooldown mechanism and budget controls
- Comprehensive tests for error classification
- Commit:
541f4b8feat(llm): add ComboEngine with safe streaming fallback semantics
- Added ProviderAdapter interface: auth, headers, capabilities, body transform, error classification
- Added DefaultProviderAdapter for generic OpenAI-compatible providers
- Added ProviderAdapterRegistry for adapter management
- Added OpenRouterAdapter: reasoning_details, prompt_cache, tool freeze
- Added NvidiaAdapter: prompt_cache_key omission, header customization
- Added OpenCodeAdapter: fingerprint tools, stream forcing, x-opencode headers
- Commit:
b8e97f4feat(llm): add Provider Adapter separation
- Added RTKCompressor engine with pluggable filter system
- Added CompressionResult with rawOutputRef for original content recovery
- Added ArtifactStore interface + InMemoryArtifactStore
- Added filters: BashOutput, GrepResult, GitDiff, FileRead, DirectoryListing, Default
- Commit:
f3220abfeat(rtk): add RTK Token Saver
- Added UsageTracker: per-request token/retry/failure recording
- Added QuotaManager: atomic reserve + settle
- Added PricingService: versioned pricing table
- Added SessionLogger: structured logging with session context
- Commit:
78265e8feat(llm): add Usage/Quota tracking and Session-aware logging
- Added SessionStore with WAL mode
- Schema: sessions + messages tables (inspired by opencode)
- CRUD operations, pagination, conversation chain retrieval
- Batch migration tool for JSONL → SQLite
- Commit:
ccb270bfeat(db): add SQLite SessionStore
All 6 phases complete. 5 commits, ~3000 lines of new code.
src/services/llm/
├── runtime/
│ ├── ComboEngine.ts + test
├── adapters/
│ ├── ProviderAdapter.ts
│ ├── OpenRouterAdapter.ts
│ ├── NvidiaAdapter.ts
│ └── OpenCodeAdapter.ts
├── usage/
│ ├── UsageTracker.ts
│ ├── QuotaManager.ts
│ └── PricingService.ts
src/services/db/
│ ├── SessionStore.ts + test
│ └── migrateSessions.ts
src/services/rtk/
│ ├── RTKCompressor.ts
│ └── filters/index.ts
src/utils/
│ └── SessionLogger.ts
- Phase 2 (P4): Translator Registry — only if new protocols needed
- Integration: wire ComboEngine into QueryEngine
- Integration: wire RTK into ToolUseContext
- Production ArtifactStore: file-based or SQLite