Skip to content

Feature/routing flagship implementation#57

Merged
ihabkhaled merged 12 commits into
mainfrom
feature/routing-flagship-implementation
May 24, 2026
Merged

Feature/routing flagship implementation#57
ihabkhaled merged 12 commits into
mainfrom
feature/routing-flagship-implementation

Conversation

@ihabkhaled
Copy link
Copy Markdown
Owner

@ihabkhaled ihabkhaled commented May 24, 2026

Summary

Brief description of changes.

Type

  • Feature
  • Bug Fix
  • Refactor
  • Documentation
  • Test

Checklist

  • npm run lint passes
  • npm run build passes
  • npm run test passes
  • Documentation updated (if applicable)
  • No secrets in code

ihabkhaled and others added 12 commits May 24, 2026 04:17
…nv additions

Master index + dependency graph + release slicing for the 13-stream routing
flagship pack at plan-prompts/ClawAI_routing_implementation_flagship_pack/.

Includes:
- INDEX.md: stream-to-doc map + activation sequence
- 00-master-plan.md: dependency graph, owners, migration order, rollback strategy
- PRISMA_FUTURE_MODELS.md: scaffold-marker for future Prisma additions per stream
  (UserCostBudget, OrgProviderRule, OrgRateLimit, language columns, modality columns,
   workflow columns, UserFineTunePreference, RouterRegionPreference, UserCostQualitySlider)
- ENV_ADDITIONS.md: per-stream feature flags (all default off; rollback in seconds)

Scope: scaffolding only. No production wiring, no DB migrations, no tests.
Each stream activates behind its own ROUTING_R*_*_ENABLED flag.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Stream 01 of the routing flagship pack. Scaffolds for closing the learning
loop so RouterLearnedScore + RouterTopicProfile data actually biases the
hot path (currently only the v2 evaluator reads them).

Files added (all SCAFFOLD: stubs throwing NotImplementedError):
- managers/learned-bias.manager.ts — applyBias(input) → re-ranked candidates
- types/learned-bias.types.ts — BiasInput / BiasOutput / AppliedBiasMetadata
- constants/learned-bias.constants.ts — reason tags + cache TTL
- utilities/learned-bias-applier.utility.ts — pure bias math
- utilities/confidence-calibrator.utility.ts — rolling 30-day hit-rate calibration

Behind ROUTING_R1_LEARNED_BIAS_ENABLED flag (default false).
Hot path unchanged until flag flipped.
Doc: docs/15-ai-context/routing-flagship-streams/01-r1-learning-loop.md

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Stream 02 — scaffolds for promoting route-evaluator v2 from shadow-only
to canary primary for a small percentage of traffic, with guardrails
and instant rollback.

Files added:
- managers/canary-bucket.manager.ts — isV2Bucket(input) stable per-user/org
- utilities/canary-hash.utility.ts — SHA-256 hash to 0..99 bucket
- utilities/decision-comparator.utility.ts — v1 vs v2 disagreement detector
- types/canary.types.ts — input/result/comparison types
- constants/canary.constants.ts — rolling window, fallback reasons, guardrail metrics

Behind ROUTING_V2_PRIMARY_ENABLED + ROUTING_V2_CANARY_PERCENT flags.
ROUTING_V2_ROLLBACK_SWITCH=true bypasses canary in milliseconds.
Guardrails: regression %, cost increase %, confidence drop, failure rate.
Doc: docs/15-ai-context/routing-flagship-streams/02-r1r3-v2-evaluator-canary.md

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Stream 03 — NEW module modality-detection/ that detects YouTube/PDF/video/
audio/spreadsheet/web/image/tool-calling/streaming/embedding intents
and tags RoutingDecision with detectedModalities + workflowHint.

20 TS files including module/controller/service/5 managers/dto/types/
8 constants files (per MIME or keyword group)/utility.

Endpoint: POST /api/v1/routing/detect-modality
Behind ROUTING_R2_MODALITY_DETECTION_ENABLED + per-modality flags.
Doc: docs/15-ai-context/routing-flagship-streams/03-r2-multimodal-intent-detection.md

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Stream 04 — workflow-orchestrator.manager + 13 IWorkflowHandler stubs
(direct-llm, search-first, extract-first, pdf-extraction, youtube-transcript,
image-analysis, image-generation, video-analysis, audio-transcribe,
file-generation, code-review, compare-ensemble, judge-pipeline) + types/
constants/handler interface.

Each handler implements canHandle/plan/confidence; orchestrator picks
highest-priority match using WORKFLOW_PRIORITY constant.

JUDGE_PIPELINE highest priority for medical/legal safety.
Behind ROUTING_R3_WORKFLOWS_ENABLED + per-workflow flags.

Doc: docs/15-ai-context/routing-flagship-streams/04-r3-workflow-orchestrator.md

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Stream 05 — NEW cost-budget/ module: per-user (+ optional per-org) monthly
caps, pre-routing budget gate, spend tracker, monthly reset cron, warnings.

Files: module/controller/service/4 managers (budget-gate/spend-tracker/
budget-warning/budget-reset cron)/repository/3 dtos/types/constants.

Endpoints: GET/PATCH /me, POST /check, admin CRUD.
Schema additions in PRISMA_FUTURE_MODELS.md (UserCostBudget + CostBudget* enums).
Behind ROUTING_R4_COST_BUDGET_ENABLED flag.

Blocker B2: free-tier awareness needs connector-service exposing freeTierRemaining.

Doc: docs/15-ai-context/routing-flagship-streams/05-r4-cost-budget-intelligence.md

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Stream 06 — NEW playground/ backend module: POST /routing/playground/evaluate
returns v1 + v2 + Ollama decision + score breakdown without executing chat.

Frontend pages (playground / circuit-breakers / taxonomy / policy-compare /
routing-history-mine + 'why this model?' inline component) are documented
but NOT scaffolded — implementer needs to add hooks + i18n + auth wiring.

Behind ROUTING_R5_PLAYGROUND_ENABLED + per-surface flags.
Doc: docs/15-ai-context/routing-flagship-streams/06-r5-operator-playground.md

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Stream 07 — doc-only (no module scaffolds; extends existing routing/policies).
Adds nullable orgId to RoutingPolicy + new OrgProviderRule + OrgRateLimit
tables (see PRISMA_FUTURE_MODELS.md). Policy resolution order:
1. user override → 2. privacy hard constraint → 3. org DENY → 4. org policy →
5. org ALLOW list → 6. global policy → 7. safe defaults.

Blocker B4: requires User.orgId end-to-end in auth-service first.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…plan

Stream 08 — NEW language-detection/ module: cld3-based language classifier
(8 ISO-639-1 locales: en/ar/de/es/fr/it/pt/ru), code-mixed detector
(Arabic+English technical terms), RTL detection.

Adds detectedLanguage + languageConfidence + isCodeMixed to RoutingDecision
(see PRISMA_FUTURE_MODELS.md). RouterModelRegistry extended with
languageStrengthJson (per-language quality score) for scoring engine.

Translated keyword arrays for ar/es/de in initial release (other locales
on roadmap). Doc includes language-strength seed values per model.

Behind ROUTING_R7_LANGUAGE_DETECTION_ENABLED flag.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Stream 09 — NEW intelligence/ umbrella module with 9 sub-feature managers:
- 9.1 prompt-length-guard (filter context-window-insufficient candidates)
- 9.2 latency-circuit-breaker (open on p95 latency breach)
- 9.3 mid-stream-switcher (kill + reroute when first chunk too slow)
- 9.4 fine-tune-preference (boost user fine-tunes per domain)
- 9.5 region-router (EU/US/APAC GDPR-aware)
- 9.6 multi-intent-splitter (N intents → N parallel calls)
- 9.7 embedding-router (vector-task routing)
- 9.8 consensus-mode (3-model ensemble with agreement score)
- 9.9 cost-quality-slider (user-set 0..100 quality weight)

Each behind its own ROUTING_R8_<feature>_ENABLED flag — independently
activatable. Schema additions: UserFineTunePreference, RouterRegionPreference,
UserCostQualitySlider (PRISMA_FUTURE_MODELS.md).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…business roadmap

Stream 10 (R.9 quality + reliability hardening):
- Test coverage targets: 80% initial, 92% final per module
- 500-prompt regression suite, k6 load test, drift detector, provider mocks
- CI integration (block PR on regression / coverage drop)
- Release gate doc

Stream 11 (quick wins backlog): 10 single-day tickets that move the needle
without requiring full streams. Activation in any order; mostly independent.

Stream 12 (business positioning): 6-release roadmap mapping streams to
demos + metrics + sales pitches. 1-sentence positioning + long-term moat
analysis (learning loop is proprietary; competitors need 12+ months data).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Address all CI errors reported on feature/routing-flagship-implementation:

LINT ERRORS:
- user-cost-budget.repository.ts: repositories must not throw — switched all
  4 methods to return null/[] with logger.warn (repository rule compliance)
- modality-detection.controller.ts: combined duplicate dto imports into one
  using inline type import syntax (import-x/no-duplicates)
- attachment-intent.manager.ts + url-intent.manager.ts: extracted inline
  Pick<...> string-literal unions into named result types in
  modality-detection.types.ts (no-restricted-syntax)
- url-intent.manager.ts: removed unused DetectedUrl import
- learned-bias-applier.utility.ts: extracted LearnedSignal type to
  learned-bias.types.ts (no-inline-type-alias rule for utility files)
- confidence-calibrator.utility.ts: extracted CalibrationSignal +
  CalibrationSample to new calibration.types.ts

TYPECHECK ERRORS:
- cost-budget services/managers: added this.logger.warn() before each throw
  so the declared logger is referenced (no unused-private check)
- modality-detection.service.ts: void-referenced all 5 injected managers
  in the stub method body so unused-private-field check passes; managers
  are still injected and registered, ready for the implementer to wire up

All changes maintain scaffold semantics: every public method still throws
SCAFFOLD-Rx with a doc pointer. Stream activation behind feature flags
unchanged.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ihabkhaled ihabkhaled merged commit 9377c35 into main May 24, 2026
59 checks passed
@ihabkhaled ihabkhaled deleted the feature/routing-flagship-implementation branch May 24, 2026 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant