singularity-forge/.plans
Flux Labs 77309207ce feat: dynamic model routing for token consumption optimization (#579)
* feat: dynamic model routing for token consumption optimization (#575)

Add complexity-based model routing that classifies units into light/standard/heavy
tiers and routes to cheaper models when appropriate. Reduces token consumption
by 20-50% for users on capped plans.

- Complexity classifier with heuristic-based tier assignment (no LLM call)
- Model router with downgrade-only semantics (user's config is ceiling)
- Budget-pressure-aware routing (more aggressive as budget fills)
- Cross-provider cost comparison via bundled cost table
- Hook classification support
- Escalation on failure (light → standard → heavy)
- Full preference validation and merge support
- Metrics tracking with tier and downgrade fields
- 40 new tests (classifier, router, cost table)

Closes #575

* feat: phases 2-4 — dashboard, adaptive learning, task introspection

Phase 2 — Observability & Dashboard:
- Tier badge [L]/[S]/[H] displayed in progress widget next to phase label
- Dynamic routing savings summary shown in footer when units have been downgraded
- Tier and modelDowngraded fields passed through snapshotUnitMetrics

Phase 3 — Adaptive Learning:
- New routing-history.ts: tracks success/failure per tier per unit-type pattern
- Rolling window of 50 entries per pattern to prevent stale data
- User feedback support (over/under/ok) with 2x weight vs automatic
- Failure rate >20% auto-bumps tier for that pattern
- Tag-specific patterns (e.g. execute-task:docs) for granular learning
- History persists to .gsd/routing-history.json
- Classifier consults adaptive history before finalizing tier

Phase 4 — Task Plan Introspection:
- Code block counting in task plans (5+ blocks → heavy)
- Complexity keyword detection: migration, architecture, security,
  performance, concurrency, compatibility
- Multiple complexity keywords (2+) → heavy, single → standard
- New codeBlockCount and complexityKeywords fields in TaskMetadata

Tests: 16 new tests (routing history + introspection), 419 total passing
2026-03-16 07:53:53 -06:00
..
dynamic-model-discovery.md feat: dynamic model discovery & provider management UX (#581) 2026-03-16 06:23:18 -06:00
issue-125-provider-fallback.md feat: add cross-provider fallback when rate/quota limits are hit (#125) 2026-03-14 15:45:44 -05:00
issue-524-git2-migration.md feat: move git operations to Rust via git2 crate (#572) 2026-03-15 20:02:10 -06:00
issue-575-dynamic-model-routing.md feat: dynamic model routing for token consumption optimization (#579) 2026-03-16 07:53:53 -06:00
native-perf-optimizations.md feat: native perf optimizations — deriveState, JSONL, paths, parsing (#576) 2026-03-15 20:16:42 -06:00
preferences-wizard-completeness.md feat: dynamic model discovery & provider management UX (#581) 2026-03-16 06:23:18 -06:00
startup-performance.md Perf/gsd startup speed (#497) 2026-03-15 13:33:43 -06:00