Repository navigation
feat: add model registry, preferences, routing, and cost ledger - #10
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces the Model Registry and Cost Ledger functionality to the CodeHands backend. It establishes the foundation for managing AI model configurations, selecting models dynamically based on user preferences, handling model fallbacks, tracking usage costs, and synchronizing model preferences across devices.
1. Model Registry
models.yamlas the central configuration file for available AI models.2. Model Preferences
3. Model Router and Fallback Mechanism
4. Cost Ledger and Cost Calculation
SyncChangerecords while ensuring compatibility with the existing sync data guard.4b . Daemon Budget Enforcement (watcher.ts): Connected claimTasks() to pickModel("implement", failedModels, preferences) so sessions.model is populated via the router. Implemented recordSessionCost() as an atomic SQLite transaction that increments sessions.cost_usd, appends a cost.recorded event, and calls checkAndEnforceSpendCap(). When cost_usd ≥ budgetUsd (default $0.50), the session transitions from running → stopped with reason "budget $X.XX reached at ". Implemented recoverSessions() to transition only running sessions to failed on daemon restart, preserving stopped, queued, and other terminal states.
5. Sync API Integration
6. Two-Laptop Synchronization Testing
7. Package Manager Migration
pnpm-lock.yamland configured the project to use[email protected].demo:syncscript for running the synchronization demo.Testing and Verification
All relevant tests passed successfully.
Test results:
Test coverage includes:
TypeScript verification:
Result: Passed with no TypeScript errors.
Test command:
Result: All 61 tests passed.
Outcome
This implementation establishes the backend foundation for model configuration, preference-driven model selection, automatic fallback handling, AI usage cost tracking, and cross-device synchronization of model preferences.
It provides a validated and extensible structure for integrating model selection and cost tracking into the CodeHands execution workflow.