pi-smart-router 1.3.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/.pi/extensions/smart-router/delegate-stream.ts +36 -4
  2. package/.pi/extensions/smart-router/route-and-delegate.ts +111 -17
  3. package/README.md +29 -17
  4. package/config/benchmark-profiles.json +76 -44
  5. package/dist/config/pi-model-mapper.d.ts.map +1 -1
  6. package/dist/config/pi-model-mapper.js +3 -0
  7. package/dist/config/pi-model-mapper.js.map +1 -1
  8. package/dist/domain/delegation/degenerate-output.d.ts +36 -0
  9. package/dist/domain/delegation/degenerate-output.d.ts.map +1 -0
  10. package/dist/domain/delegation/degenerate-output.js +75 -0
  11. package/dist/domain/delegation/degenerate-output.js.map +1 -0
  12. package/dist/domain/pipeline/local-zero-stage.d.ts +4 -0
  13. package/dist/domain/pipeline/local-zero-stage.d.ts.map +1 -1
  14. package/dist/domain/pipeline/local-zero-stage.js +23 -3
  15. package/dist/domain/pipeline/local-zero-stage.js.map +1 -1
  16. package/dist/domain/pipeline/low-intensity-stage.d.ts +3 -0
  17. package/dist/domain/pipeline/low-intensity-stage.d.ts.map +1 -1
  18. package/dist/domain/pipeline/low-intensity-stage.js +96 -14
  19. package/dist/domain/pipeline/low-intensity-stage.js.map +1 -1
  20. package/dist/domain/pipeline/router-pipeline.d.ts.map +1 -1
  21. package/dist/domain/pipeline/router-pipeline.js +39 -7
  22. package/dist/domain/pipeline/router-pipeline.js.map +1 -1
  23. package/dist/domain/pipeline/turn-envelope-stage.d.ts +1 -0
  24. package/dist/domain/pipeline/turn-envelope-stage.d.ts.map +1 -1
  25. package/dist/domain/pipeline/turn-envelope-stage.js +59 -2
  26. package/dist/domain/pipeline/turn-envelope-stage.js.map +1 -1
  27. package/dist/domain/routing/cross-provider-handoff.d.ts +39 -0
  28. package/dist/domain/routing/cross-provider-handoff.d.ts.map +1 -0
  29. package/dist/domain/routing/cross-provider-handoff.js +66 -0
  30. package/dist/domain/routing/cross-provider-handoff.js.map +1 -0
  31. package/dist/domain/routing/flash-class.d.ts +32 -0
  32. package/dist/domain/routing/flash-class.d.ts.map +1 -0
  33. package/dist/domain/routing/flash-class.js +58 -0
  34. package/dist/domain/routing/flash-class.js.map +1 -0
  35. package/dist/index.d.ts +1 -0
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +1 -0
  38. package/dist/index.js.map +1 -1
  39. package/dist/infrastructure/delegation/provider-error.d.ts.map +1 -1
  40. package/dist/infrastructure/delegation/provider-error.js +12 -4
  41. package/dist/infrastructure/delegation/provider-error.js.map +1 -1
  42. package/dist/infrastructure/gateway/gateway-dispatch.d.ts +31 -6
  43. package/dist/infrastructure/gateway/gateway-dispatch.d.ts.map +1 -1
  44. package/dist/infrastructure/gateway/gateway-dispatch.js +154 -13
  45. package/dist/infrastructure/gateway/gateway-dispatch.js.map +1 -1
  46. package/package.json +3 -3
  47. package/src/config/pi-model-mapper.ts +3 -0
  48. package/src/domain/delegation/degenerate-output.ts +124 -0
  49. package/src/domain/pipeline/local-zero-stage.ts +29 -3
  50. package/src/domain/pipeline/low-intensity-stage.ts +136 -19
  51. package/src/domain/pipeline/router-pipeline.ts +57 -7
  52. package/src/domain/pipeline/turn-envelope-stage.ts +81 -2
  53. package/src/domain/routing/cross-provider-handoff.ts +104 -0
  54. package/src/domain/routing/flash-class.ts +95 -0
  55. package/src/index.ts +11 -0
  56. package/src/infrastructure/delegation/provider-error.ts +13 -4
  57. package/src/infrastructure/gateway/gateway-dispatch.ts +193 -13
@@ -13,6 +13,8 @@ import {
13
13
  parseAssistantMessageError,
14
14
  extractUsageActuals,
15
15
  resolveAdaptiveReasoning,
16
+ DEGENERATE_OUTPUT_ERROR_CODE,
17
+ isDegenerateOutput,
16
18
  } from '../../../src/index.js';
17
19
  import type {
18
20
  AdaptiveReasoningResult,
@@ -271,6 +273,19 @@ export function commitPipedTerminal(
271
273
  outer.end(endMessage);
272
274
  }
273
275
 
276
+ export function resolveFailoverProviderError(
277
+ message: AssistantMessage,
278
+ ): ReturnType<typeof parseAssistantMessageError> {
279
+ const parsed = parseAssistantMessageError(message);
280
+ if (parsed) {
281
+ return parsed;
282
+ }
283
+ if (message.stopReason === 'error' && message.errorMessage) {
284
+ return { message: message.errorMessage };
285
+ }
286
+ return undefined;
287
+ }
288
+
274
289
  function recordDelegateOutcome(
275
290
  targetModel: Model<Api>,
276
291
  deps: StreamDelegationDeps,
@@ -299,11 +314,28 @@ function recordDelegateOutcome(
299
314
  }
300
315
  }
301
316
 
302
- if (result.failed) {
303
- const parsed = parseAssistantMessageError(result.finalMessage);
304
- deps.router.dispatch.recordOutcome(targetModel.id, parsed);
317
+ const degenerate = isDegenerateOutput(result.finalMessage);
318
+ if (result.failed || degenerate) {
319
+ const providerError = degenerate
320
+ ? {
321
+ code: DEGENERATE_OUTPUT_ERROR_CODE,
322
+ message: 'Model produced degenerate output',
323
+ truncated: true,
324
+ }
325
+ : resolveFailoverProviderError(result.finalMessage) ?? {
326
+ message: `Delegation failed (${result.finalMessage.stopReason})`,
327
+ };
328
+ if (requestId === undefined) {
329
+ deps.router.dispatch.recordOutcome(targetModel.id, providerError);
330
+ } else {
331
+ deps.router.dispatch.recordOutcome(targetModel.id, providerError, requestId);
332
+ }
305
333
  } else {
306
- deps.router.dispatch.recordOutcome(targetModel.id);
334
+ if (requestId === undefined) {
335
+ deps.router.dispatch.recordOutcome(targetModel.id);
336
+ } else {
337
+ deps.router.dispatch.recordOutcome(targetModel.id, undefined, requestId);
338
+ }
307
339
  if (sessionId) {
308
340
  deps.executionLedger.recordSuccess(sessionId, modelToExecutionModel(targetModel));
309
341
  }
@@ -18,7 +18,6 @@ import {
18
18
  isGoogleGeminiProfile,
19
19
  resolveEffectiveFleet,
20
20
  isGeminiThoughtSignatureAssistantError,
21
- parseAssistantMessageError,
22
21
  GEMINI_REPLAY_INCOMPATIBLE,
23
22
  shouldFailoverOnProviderError,
24
23
  } from '../../../src/index.js';
@@ -32,8 +31,14 @@ import type {
32
31
  import {
33
32
  commitPipedTerminal,
34
33
  delegateWithOutcome,
34
+ resolveFailoverProviderError,
35
35
  type PipedDelegatedStreamResult,
36
36
  } from './delegate-stream.js';
37
+ import {
38
+ DEGENERATE_OUTPUT,
39
+ DEGENERATE_OUTPUT_ERROR_CODE,
40
+ isDegenerateOutput,
41
+ } from '../../../src/index.js';
37
42
  import {
38
43
  createErrorMessage,
39
44
  findFleetProfile,
@@ -65,19 +70,6 @@ function isRoutingLogEnabled(): boolean {
65
70
  return process.env.SMART_ROUTER_LOG_ROUTING === '1';
66
71
  }
67
72
 
68
- function resolveFailoverProviderError(
69
- message: AssistantMessage,
70
- ): ReturnType<typeof parseAssistantMessageError> {
71
- const parsed = parseAssistantMessageError(message);
72
- if (parsed) {
73
- return parsed;
74
- }
75
- if (message.stopReason === 'error' && message.errorMessage) {
76
- return { message: message.errorMessage };
77
- }
78
- return undefined;
79
- }
80
-
81
73
  function logRoutingDecision(
82
74
  decision: RoutingDecision,
83
75
  delegate?: { provider: string; modelId: string; api: Api },
@@ -175,6 +167,21 @@ function isZeroOutputLengthStop(message: AssistantMessage): boolean {
175
167
  return message.stopReason === 'length' && message.usage.output === 0;
176
168
  }
177
169
 
170
+ type DelegationProviderError = NonNullable<ReturnType<typeof resolveFailoverProviderError>>;
171
+
172
+ function isSameRequestCaused4xx(
173
+ current: DelegationProviderError,
174
+ previous: DelegationProviderError,
175
+ ): boolean {
176
+ return (
177
+ current.statusCode !== undefined &&
178
+ current.statusCode === previous.statusCode &&
179
+ current.statusCode >= 400 &&
180
+ current.statusCode < 500 &&
181
+ current.statusCode !== 429
182
+ );
183
+ }
184
+
178
185
  /** Minimal model identity for degraded terminal messages when no Model resolved. */
179
186
  interface DegradedModelRef {
180
187
  readonly api: Api;
@@ -463,8 +470,10 @@ export async function routeAndDelegate(
463
470
  });
464
471
 
465
472
  const failedModelIds: string[] = [];
473
+ const failedAttempts: Array<{ modelId: string; error: DelegationProviderError }> = [];
466
474
  const headroomExcludedModelIds: string[] = [];
467
475
  let geminiReplayFailoverAttempted = false;
476
+ let degenerateOutputFailoverAttempted = false;
468
477
  const estimatedInputTokens =
469
478
  request.estimated_input_tokens ?? request.prompt_text.length;
470
479
  let pendingFailoverInfo: FailoverNoticeInfo | undefined;
@@ -593,6 +602,63 @@ export async function routeAndDelegate(
593
602
  }
594
603
  }
595
604
 
605
+ if (result.finalMessage && isDegenerateOutput(result.finalMessage)) {
606
+ // SP-325 / #181: discard the repetitive terminal, count it through the
607
+ // SP-322 model-failure policy (in recordDelegateOutcome), and retry the
608
+ // original context. The bad assistant turn was never added to that context.
609
+ if (!failedModelIds.includes(targetModel.id)) {
610
+ failedModelIds.push(targetModel.id);
611
+ }
612
+ const selectedFailover = degenerateOutputFailoverAttempted
613
+ ? undefined
614
+ : deps.router.dispatch.selectFailover(
615
+ decision,
616
+ failedModelIds,
617
+ effectiveFleet,
618
+ );
619
+ // Bound this post-stream retry independently of selector behavior. A
620
+ // repetitive alternate must terminate instead of cycling indefinitely.
621
+ degenerateOutputFailoverAttempted = true;
622
+ const failover = selectedFailover
623
+ ? { ...selectedFailover, reason_code: DEGENERATE_OUTPUT }
624
+ : undefined;
625
+ const alternateModel = failover ? resolveTargetModel(deps, failover) : undefined;
626
+
627
+ if (failover && alternateModel && alternateModel.id !== targetModel.id) {
628
+ console.warn(
629
+ '[smart-router] degenerate output, failing over to alternate model',
630
+ JSON.stringify({
631
+ reason_code: DEGENERATE_OUTPUT,
632
+ failed_model_id: targetModel.id,
633
+ selected_model_id: alternateModel.id,
634
+ }),
635
+ );
636
+ pendingFailoverInfo = {
637
+ failedModelId: targetModel.id,
638
+ alternateModelId: alternateModel.id,
639
+ errorObj: {
640
+ code: DEGENERATE_OUTPUT_ERROR_CODE,
641
+ message: 'Model produced degenerate output',
642
+ },
643
+ };
644
+ decision = failover;
645
+ deps.onRoutingDecision?.(decision);
646
+ targetModel = alternateModel;
647
+ continue;
648
+ }
649
+
650
+ decision = { ...decision, reason_code: DEGENERATE_OUTPUT };
651
+ deps.onRoutingDecision?.(decision);
652
+ emitDegradedFailure(
653
+ outer,
654
+ targetModel,
655
+ targetModel.id,
656
+ DEGENERATE_OUTPUT,
657
+ 'Model produced degenerate output; no failover model available',
658
+ );
659
+ return;
660
+ }
661
+
596
662
  if (
597
663
  result.failed &&
598
664
  result.finalMessage &&
@@ -659,12 +725,37 @@ export async function routeAndDelegate(
659
725
  if (result.failed && result.finalMessage) {
660
726
  const providerError = resolveFailoverProviderError(result.finalMessage);
661
727
  const failedProfile = findFleetProfile(effectiveFleet, targetModel.id);
728
+ if (providerError) {
729
+ const currentTargetModelId = targetModel.id;
730
+ if (
731
+ failedAttempts.some(
732
+ (attempt) =>
733
+ attempt.modelId !== currentTargetModelId &&
734
+ isSameRequestCaused4xx(providerError, attempt.error),
735
+ )
736
+ ) {
737
+ // The same status on a distinct alternate points to the request,
738
+ // not either model. Undo all non-infra counts from this request.
739
+ deps.router.dispatch.recordRequestCausedFailure(decision.request_id);
740
+ console.warn(
741
+ '[smart-router] matching alternate 4xx, treating failure as request-caused',
742
+ JSON.stringify({
743
+ request_id: request.request_id,
744
+ status_code: providerError.statusCode,
745
+ }),
746
+ );
747
+ commitPipedTerminal(result, { sanitizeErrors: true });
748
+ return;
749
+ }
750
+ failedAttempts.push({ modelId: currentTargetModelId, error: providerError });
751
+ }
662
752
  if (
663
753
  providerError &&
664
754
  shouldFailoverOnProviderError(providerError, failedProfile)
665
755
  ) {
666
- deps.router.dispatch.recordOutcome(targetModel.id, providerError);
667
- failedModelIds.push(targetModel.id);
756
+ if (!failedModelIds.includes(targetModel.id)) {
757
+ failedModelIds.push(targetModel.id);
758
+ }
668
759
  const failover = deps.router.dispatch.selectFailover(
669
760
  decision,
670
761
  failedModelIds,
@@ -682,7 +773,9 @@ export async function routeAndDelegate(
682
773
  }
683
774
 
684
775
  console.warn(
685
- '[smart-router] infra error, failing over to alternate model',
776
+ failover.reason_code === 'model_repeated_failure'
777
+ ? '[smart-router] repeated model failure, failing over to alternate model'
778
+ : '[smart-router] infra error, failing over to alternate model',
686
779
  alternateModel.id,
687
780
  );
688
781
  // Discard held terminal from the failed attempt — do not forward to outer.
@@ -693,6 +786,7 @@ export async function routeAndDelegate(
693
786
  };
694
787
  decision = failover;
695
788
  targetModel = alternateModel;
789
+ deps.onRoutingDecision?.(decision);
696
790
  continue;
697
791
  }
698
792
  }
package/README.md CHANGED
@@ -24,14 +24,14 @@ request → hardware probe → loop escalation → turn envelope → typed judgm
24
24
 
25
25
  The pipeline runs **12 stages sequentially with early exit** — the moment any stage reaches a routing decision, subsequent stages are skipped. Every decision includes the stage name, reason code, candidates considered, estimated cost, and routing latency for full observability.
26
26
 
27
- \* `typed_judgment` is an additional **opt-in, non-deciding** stage (default off) that runs between turn envelope and the context-fit gate when enabled — it records judge answers for later consumers and never decides. See [Typed judgment (opt-in)](#typed-judgment-opt-in-183).
27
+ \* `typed_judgment` is an additional **opt-in, non-deciding** stage (default off) that runs between turn envelope and the context-fit gate when enabled — it records judge answers and never selects a model itself. Its [#188](https://github.com/beettlle/pi-smart-router/issues/188) consumers can use those answers for planning classification, tier hints, and local safety gates. See [Typed judgment (opt-in)](#typed-judgment-opt-in-183).
28
28
 
29
29
  | Stage | Budget | What it does |
30
30
  |-------|--------|--------------|
31
31
  | Hardware Probe | — | Checks platform/RAM/battery to gate local inference |
32
32
  | Loop Escalation | — | Detects repeated identical tool failures; escalates session to frontier |
33
33
  | Turn Envelope | <2ms | Classifies turn type: tool_result, planning, subagent, main_loop |
34
- | Typed Judgment (opt-in) | ~385–990ms per judged user turn when enabled; 0 otherwise | **Non-deciding** (default off): asks a Jev-compatible judge six questions about the turn and records the answers — never decides |
34
+ | Typed Judgment (opt-in) | ~385–990ms per judged user turn when enabled; 0 otherwise | **Non-deciding** (default off): asks a Jev-compatible judge six questions and records the answers; downstream #188 consumers may use them for planning, tier hints, and local gates |
35
35
  | Context-Fit Gate | — | Filters fleet to models whose context window fits estimated input tokens |
36
36
  | Low-Intensity Gate | — | Structural tier hint, cluster match, and P(success) expected-cost scoring |
37
37
  | Session Pin | <1ms | Returns pinned model if session has one; breaks pin on compaction or overflow |
@@ -322,7 +322,7 @@ When you use `smart-router/auto`, the extension does **not** read `config/models
322
322
  4. **Route** — `createRouterFromFleet()` runs the 12-stage pipeline on each request.
323
323
  5. **Delegate** — The extension resolves the chosen model in the registry and forwards the stream via pi-ai's built-in provider APIs.
324
324
 
325
- Unknown models receive conservative economical-cloud defaults. Local providers (`lmstudio`, `ollama`) map to `zero-tier`. Cursor provider models (`cursor/*`, `composer-*`, opaque id `default`) map to `frontier-cloud` with explicit capability defaults (SP-086, SP-098). Benchmark-grounded capability vectors (including multi-fleet `github-copilot/*`, Gemini, and Anthropic dogfood IDs, aliased family-by-family) are documented in the [capability profile coverage report](docs/capability-profile-coverage.md) ([#108](https://github.com/beettlle/pi-smart-router/issues/108) / [#124](https://github.com/beettlle/pi-smart-router/issues/124)).
325
+ Unknown models receive conservative economical-cloud defaults. Local providers (`lmstudio`, `ollama`) map to `zero-tier`. Cursor provider models (`cursor/*`, `composer-*`, opaque id `default`) map to `frontier-cloud` with explicit capability defaults (SP-086, SP-098). **v1.4.0 fleet coverage:** Kimi K3 / K3.1 Pro ids (`k3`, `k3.1-pro`, `kimi-k3`, …) map to `frontier-cloud` via pattern rules; `k3.1-pro` is benchmark-grounded when leaderboard scores exist (aliases cover highspeed / provider-prefixed forms). Gemini 4 `carbon` and `hydrogen` match the existing Gemini 4+ frontier rule like `argon` and stay on `pattern_default` in `provenance.ungrounded_fleet_ids` until public scores appear. Benchmark-grounded capability vectors (including multi-fleet `github-copilot/*`, Gemini, and Anthropic dogfood IDs, aliased family-by-family) are documented in the [capability profile coverage report](docs/capability-profile-coverage.md) ([#108](https://github.com/beettlle/pi-smart-router/issues/108) / [#124](https://github.com/beettlle/pi-smart-router/issues/124)).
326
326
 
327
327
  To refresh after auth or settings changes, restart pi or `/reload` extensions.
328
328
 
@@ -569,18 +569,30 @@ Floor/ceiling bind only what the policy itself derives. An explicit operator `/t
569
569
 
570
570
  ### Typed judgment (opt-in) (#183)
571
571
 
572
- Typed judgment is an **opt-in, non-deciding** pipeline stage (`typed_judgment`, directly after `turn_envelope` and before `context_fit`) that asks a Jev-compatible “systemone” semantic judge six structured questions about each user-prompt turn and records the normalized answers on the routing context. **In v1.3.0 the answers are recorded only — they do not change routing decisions.** Downstream consumers (tier hints, capability gating, adaptive reasoning) land in later trains ([#188](https://github.com/beettlle/pi-smart-router/issues/188)–[#190](https://github.com/beettlle/pi-smart-router/issues/190)); do not expect any routing behavior change from enabling the stage today.
572
+ Typed judgment is an **opt-in, non-deciding** pipeline stage (`typed_judgment`, directly after `turn_envelope` and before `context_fit`) that asks a Jev-compatible “systemone” semantic judge six structured questions about each user-prompt turn and records the normalized answers on the routing context. The stage itself never selects a model. With [#188](https://github.com/beettlle/pi-smart-router/issues/188) landed, enabling the stage allows downstream `turn_envelope`, `low_intensity`, and `local_zero` consumers to use those answers as described below. The default remains **off**, and a missing judgment preserves the deterministic / regex fallback behavior.
573
573
 
574
- The six questions (stable ids):
574
+ The six questions (stable ids), their normalized forms, and their consumers:
575
575
 
576
- | Question id | Kind | What it asks |
577
- |-------------|------|--------------|
578
- | `task_kind` | choice (10 anchored options) | The single kind of work the user message asks for: `plan`, `implement`, `debug`, `refactor`, `review`, `research`, `explain`, `operate`, `write`, `chat` |
579
- | `capability_deserved` | score 0–3 | Setting price aside, how much model capability the request deserves |
580
- | `needs_deep_reasoning` | noul (yes/no) | Whether the turn needs extended multi-step reasoning rather than recall, lookup, or a short direct edit |
581
- | `code_gen` | score 0–3 | How much code or configuration must be written or modified |
582
- | `tool_use` | score 0–3 | How much tool execution (shell, file, search, agentic calls) the turn requires |
583
- | `destructive` | noul (yes/no) | Whether satisfying the request could destroy, overwrite, or irreversibly modify data, state, or history |
576
+ | Question id | Kind | What it asks | Normalized signal and consumer |
577
+ |-------------|------|--------------|--------------------------------|
578
+ | `task_kind` | choice (10 anchored options) | The single kind of work the user message asks for: `plan`, `implement`, `debug`, `refactor`, `review`, `research`, `explain`, `operate`, `write`, `chat` | `task_kind` plus `task_kind_confidence`; consumed by `turn_envelope` for planning classification (#188) |
579
+ | `capability_deserved` | score 0–3 | Setting price aside, how much model capability the request deserves | `0`, `1/3`, `2/3`, or `1`; consumed by `low_intensity` for tier hints and capability filtering (#188) |
580
+ | `needs_deep_reasoning` | noul (yes/no) | Whether the turn needs extended multi-step reasoning rather than recall, lookup, or a short direct edit | `deep_reasoning_p` (0–1); recorded only — the adaptive-reasoning consumer remains [#190](https://github.com/beettlle/pi-smart-router/issues/190) |
581
+ | `code_gen` | score 0–3 | How much code or configuration must be written or modified | `0`, `1/3`, `2/3`, or `1`; recorded only — the HyDRA requirement-source consumer remains [#189](https://github.com/beettlle/pi-smart-router/issues/189) |
582
+ | `tool_use` | score 0–3 | How much tool execution (shell, file, search, agentic calls) the turn requires | `0`, `1/3`, `2/3`, or `1`; consumed by the `local_zero` capability gate (#188) |
583
+ | `destructive` | noul (yes/no) | Whether satisfying the request could destroy, overwrite, or irreversibly modify data, state, or history | `destructive_p` (0–1); consumed by the `local_zero` safety gate (#188) |
584
+
585
+ **Landed #188 consumer behavior:**
586
+
587
+ | Consumer | Judgment field | Behavior and attribution |
588
+ |----------|----------------|--------------------------|
589
+ | `turn_envelope` | `task_kind` | At confidence ≥ `typed_judgment.min_confidence`, `plan`, `debug`, or `review` selects planning classification. A confident non-planning answer can replace only regex-derived planning when the host did not explicitly set `turn_type`. A positive judgment-driven planning override uses reason code `typed_judgment_planning`. |
590
+ | `low_intensity` | `capability_deserved` | Level 0 hints `zero-tier`, level 1 (`1/3`) hints `economical-cloud`, and levels 2–3 (`≥2/3`) hint `frontier-cloud`. Any non-zero level removes zero-tier and flash-class candidates when another healthy candidate remains. At confidence ≥ `min_confidence` the judgment may replace the prior hint in either direction; below the threshold it may only raise a tier. Session-depth and loop-escalation frontier floors still win, and context-fit constraints remain authoritative. Explain attribution uses `typed_judgment_tier_zero-tier`, `typed_judgment_tier_economical-cloud`, or `typed_judgment_tier_frontier-cloud`. |
591
+ | `local_zero` | `destructive`, `tool_use` | `destructive_p ≥ 0.7` or judged `tool_use` above the effective local ceiling skips local dispatch with `typed_judgment_destructive` or `typed_judgment_tool_use_shortfall`. The ceiling is `min(local model tool_use capability, local_zero.max_tool_use_requirement)`. These safety gates may skip local dispatch even below `min_confidence`; a missing `tool_use` answer retains the legacy cue-count gate, and a null judgment retains prior behavior. |
592
+
593
+ **Remaining Sprint 2 work:** [#189](https://github.com/beettlle/pi-smart-router/issues/189) (typed judgment as a HyDRA requirement source), [#190](https://github.com/beettlle/pi-smart-router/issues/190) (adaptive reasoning from `needs_deep_reasoning`), and [#191](https://github.com/beettlle/pi-smart-router/issues/191) (eval comparison and latency benchmark). Epic [#183](https://github.com/beettlle/pi-smart-router/issues/183) therefore remains open; enabling #188 does **not** change those consumers or flip any encoder, requirement-source, frugality, or reasoning default.
594
+
595
+ **Observability:** explain and `LOG_ROUTING` expose the normalized signal in `features.typed_judgment` (including confidences, `skip_reason`, and `latency_ms`), tier attribution in `features.tier_hint_reason_code`, and local gate outcomes in `features.tier_selection.local_zero_skip_reasons`.
584
596
 
585
597
  **Default off.** `typed_judgment.enabled` defaults to `false` — existing installs make no judge call and pay zero added latency. When enabled, the stage runs only on user-prompt turns: `tool_result` turns, acknowledgement-only turns, and explicit `force_model_id` turns skip it, and any timeout or judge error **fails open** — routing proceeds exactly as if the stage were unwired. Skip/failure reason codes recorded on the routing context: `typed_judgment_disabled`, `typed_judgment_tool_result`, `typed_judgment_acknowledgement`, `typed_judgment_force_model`, `typed_judgment_timeout`, `typed_judgment_error` (plus `typed_judgment_remote_key_missing` when a remote endpoint has no API key available — see privacy note below).
586
598
 
@@ -602,7 +614,7 @@ The six questions (stable ids):
602
614
  | `samples` | `SMART_ROUTER_TYPED_JUDGMENT_SAMPLES` | `1` | Judge samples per question (OpenJev self-consistency extension; omitted for hosted Jev) |
603
615
  | `api_key_env` | `SMART_ROUTER_TYPED_JUDGMENT_API_KEY_ENV` | `TYPESAFE_API_KEY` | **Name** of the env var holding the API key — never the key itself |
604
616
  | `allow_remote` | `SMART_ROUTER_TYPED_JUDGMENT_ALLOW_REMOTE` | `false` | Permit non-loopback (hosted) endpoints; default false = fail closed to local judge only |
605
- | `min_confidence` | `SMART_ROUTER_TYPED_JUDGMENT_MIN_CONFIDENCE` | `0.6` | Minimum answer confidence for a judgment to influence routing (consumed by later trains; defined now to stabilize the config shape) |
617
+ | `min_confidence` | `SMART_ROUTER_TYPED_JUDGMENT_MIN_CONFIDENCE` | `0.6` | Confidence threshold for `task_kind` planning overrides and `capability_deserved` tier replacement; below it, capability judgments may raise but never lower a tier. The `local_zero` safety gates still apply |
606
618
 
607
619
  Invalid env overrides (e.g. a remote endpoint without `allow_remote`) fail closed: the base config stays intact and disabled, and no judge call is made.
608
620
 
@@ -1608,7 +1620,7 @@ Named profiles (`agents.profiles` + `agents.activeProfile`) and `agents.escalate
1608
1620
 
1609
1621
  | Role | Model | Thinking |
1610
1622
  |------|--------|----------|
1611
- | Worker | `kimi-coding/k3` | `high` |
1623
+ | Worker | `kimi-coding/k3.1-pro` | `high` |
1612
1624
  | Plan review | `zai/glm-5.3-flash` | `low` |
1613
1625
  | Code review | `kimi-coding/kimi-for-coding` | `high` |
1614
1626
  | Final review | `google/gemini-3.1-pro-preview` | `high` |
@@ -1637,8 +1649,8 @@ spine settings set agents.activeProfile default
1637
1649
 
1638
1650
  | Role | Model | Thinking |
1639
1651
  |------|--------|----------|
1640
- | Worker | `kimi-coding/k3` | `high` |
1641
- | Plan | `kimi-coding/kimi-for-coding` | `medium` |
1652
+ | Worker | `anthropic/claude-opus-5-5` | `high` |
1653
+ | Plan | `google/gemini-flash-latest` | `medium` |
1642
1654
  | Code | `google/gemini-3.1-pro-preview` | `high` |
1643
1655
  | Final | `google/gemini-3.1-pro-preview` | `high` |
1644
1656
 
@@ -3,25 +3,36 @@
3
3
  "provenance": {
4
4
  "source_urls": {
5
5
  "swebench_verified": "https://www.swebench.com/",
6
+ "swe_marathon": "https://www.kimi.ai/blog/kimi-k3-1-pro",
6
7
  "terminal_bench": "https://www.tbench.ai/leaderboard",
7
8
  "livecodebench": "https://livecodebench.github.io/leaderboard.html",
8
9
  "bfcl": "https://gorilla.cs.berkeley.edu/leaderboard.html"
9
10
  },
10
- "scrape_date": "2026-11-01",
11
- "catalog_freeze_date": "2026-11-01",
11
+ "scrape_date": "2026-11-16",
12
+ "catalog_freeze_date": "2026-11-16",
12
13
  "ungrounded_fleet_ids": [
13
14
  "anthropic/claude-fable-5-1",
14
15
  "claude-fable-5-1",
15
16
  "gemini-3.1-pro-preview",
16
17
  "gemini-3.1-pro-preview-customtools",
17
18
  "gemini-4-argon",
19
+ "gemini-4-carbon",
20
+ "gemini-4-hydrogen",
18
21
  "gemini-flash-latest",
19
22
  "gemini-flash-lite-latest",
20
23
  "google/gemini-3.1-pro-preview",
21
24
  "google/gemini-3.1-pro-preview-customtools",
22
25
  "google/gemini-4-argon",
26
+ "google/gemini-4-carbon",
27
+ "google/gemini-4-hydrogen",
23
28
  "google/gemini-flash-latest",
24
- "google/gemini-flash-lite-latest"
29
+ "google/gemini-flash-lite-latest",
30
+ "k3",
31
+ "k3-256k",
32
+ "kimi-coding/k3",
33
+ "kimi-coding/k3-256k",
34
+ "kimi-coding/kimi-k3",
35
+ "kimi-k3"
25
36
  ]
26
37
  },
27
38
  "aliases": {
@@ -71,7 +82,18 @@
71
82
  "gpt-5": "gpt-5.3-codex",
72
83
  "gpt-5-codex": "gpt-5.3-codex",
73
84
  "gpt-5.3": "gpt-5.3-codex",
74
- "gpt-5.5": "gpt-5.3-codex"
85
+ "gpt-5.5": "gpt-5.3-codex",
86
+ "k3.1-pro-highspeed": "k3.1-pro",
87
+ "kimi-coding/k3.1-pro": "k3.1-pro",
88
+ "kimi-coding/k3.1-pro-highspeed": "k3.1-pro",
89
+ "kimi-coding/kimi-k3.1-pro": "k3.1-pro",
90
+ "kimi-coding/kimi-k3.1-pro-highspeed": "k3.1-pro",
91
+ "kimi-k3.1-pro": "k3.1-pro",
92
+ "kimi-k3.1-pro-highspeed": "k3.1-pro",
93
+ "moonshotai/k3.1-pro": "k3.1-pro",
94
+ "moonshotai/k3.1-pro-highspeed": "k3.1-pro",
95
+ "moonshotai/kimi-k3.1-pro": "k3.1-pro",
96
+ "moonshotai/kimi-k3.1-pro-highspeed": "k3.1-pro"
75
97
  },
76
98
  "models": [
77
99
  {
@@ -121,22 +143,22 @@
121
143
  {
122
144
  "model_id": "claude-opus-4-5",
123
145
  "capabilities": {
124
- "reasoning": 0.767,
125
- "code_gen": 0.7915,
126
- "tool_use": 0.8035
146
+ "reasoning": 0.7585,
147
+ "code_gen": 0.708,
148
+ "tool_use": 0.7498
127
149
  },
128
150
  "benchmark_sources": {
129
151
  "bfcl": {
130
- "raw_score": 88.2,
131
- "normalized": 0.882
152
+ "raw_score": 77.47,
153
+ "normalized": 0.7746999999999999
132
154
  },
133
155
  "livecodebench": {
134
- "raw_score": 77.4,
135
- "normalized": 0.774
156
+ "raw_score": 62.4,
157
+ "normalized": 0.624
136
158
  },
137
159
  "swebench_verified": {
138
- "raw_score": 80.9,
139
- "normalized": 0.809
160
+ "raw_score": 79.2,
161
+ "normalized": 0.792
140
162
  },
141
163
  "terminal_bench": {
142
164
  "raw_score": 72.5,
@@ -147,22 +169,22 @@
147
169
  {
148
170
  "model_id": "claude-sonnet-4-6",
149
171
  "capabilities": {
150
- "reasoning": 0.738,
151
- "code_gen": 0.7635,
152
- "tool_use": 0.7625
172
+ "reasoning": 0.724,
173
+ "code_gen": 0.681,
174
+ "tool_use": 0.7062
153
175
  },
154
176
  "benchmark_sources": {
155
177
  "bfcl": {
156
- "raw_score": 84.5,
157
- "normalized": 0.845
178
+ "raw_score": 73.24,
179
+ "normalized": 0.7323999999999999
158
180
  },
159
181
  "livecodebench": {
160
- "raw_score": 73.1,
161
- "normalized": 0.731
182
+ "raw_score": 59.4,
183
+ "normalized": 0.594
162
184
  },
163
185
  "swebench_verified": {
164
- "raw_score": 79.6,
165
- "normalized": 0.7959999999999999
186
+ "raw_score": 76.8,
187
+ "normalized": 0.768
166
188
  },
167
189
  "terminal_bench": {
168
190
  "raw_score": 68,
@@ -173,22 +195,22 @@
173
195
  {
174
196
  "model_id": "gemini-2.5-flash",
175
197
  "capabilities": {
176
- "reasoning": 0.5295,
177
- "code_gen": 0.5525,
178
- "tool_use": 0.5735
198
+ "reasoning": 0.3827,
199
+ "code_gen": 0.5192,
200
+ "tool_use": 0.5202
179
201
  },
180
202
  "benchmark_sources": {
181
203
  "bfcl": {
182
- "raw_score": 66.9,
183
- "normalized": 0.669
204
+ "raw_score": 56.24,
205
+ "normalized": 0.5624
184
206
  },
185
207
  "livecodebench": {
186
- "raw_score": 52.4,
187
- "normalized": 0.524
208
+ "raw_score": 75.1,
209
+ "normalized": 0.7509999999999999
188
210
  },
189
211
  "swebench_verified": {
190
- "raw_score": 58.1,
191
- "normalized": 0.581
212
+ "raw_score": 28.73,
213
+ "normalized": 0.2873
192
214
  },
193
215
  "terminal_bench": {
194
216
  "raw_score": 47.8,
@@ -217,28 +239,38 @@
217
239
  {
218
240
  "model_id": "gpt-5.3-codex",
219
241
  "capabilities": {
220
- "reasoning": 0.796,
221
- "code_gen": 0.833,
222
- "tool_use": 0.8215
242
+ "reasoning": 0.743,
243
+ "code_gen": 0.744,
244
+ "tool_use": 0.742
223
245
  },
224
246
  "benchmark_sources": {
225
- "bfcl": {
226
- "raw_score": 90.1,
227
- "normalized": 0.9009999999999999
228
- },
229
- "livecodebench": {
230
- "raw_score": 81.6,
231
- "normalized": 0.816
232
- },
233
247
  "swebench_verified": {
234
- "raw_score": 85,
235
- "normalized": 0.85
248
+ "raw_score": 74.4,
249
+ "normalized": 0.7440000000000001
236
250
  },
237
251
  "terminal_bench": {
238
252
  "raw_score": 74.2,
239
253
  "normalized": 0.742
240
254
  }
241
255
  }
256
+ },
257
+ {
258
+ "model_id": "k3.1-pro",
259
+ "capabilities": {
260
+ "reasoning": 0.557,
261
+ "code_gen": 0.517,
262
+ "tool_use": 0.597
263
+ },
264
+ "benchmark_sources": {
265
+ "swe_marathon": {
266
+ "raw_score": 51.7,
267
+ "normalized": 0.517
268
+ },
269
+ "terminal_bench": {
270
+ "raw_score": 59.7,
271
+ "normalized": 0.597
272
+ }
273
+ }
242
274
  }
243
275
  ]
244
276
  }
@@ -1 +1 @@
1
- {"version":3,"file":"pi-model-mapper.d.ts","sourceRoot":"","sources":["../../src/config/pi-model-mapper.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAOH,OAAO,KAAK,EACV,iBAAiB,EACjB,WAAW,EAGX,YAAY,EACZ,IAAI,EACL,MAAM,6BAA6B,CAAC;AAErC,oFAAoF;AACpF,eAAO,MAAM,+BAA+B,QAA+C,CAAC;AAE5F,6FAA6F;AAC7F,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG,iBAAiB,CAAC;AAE/D,yEAAyE;AACzE,MAAM,WAAW,kBAAmB,SAAQ,YAAY;IACtD,QAAQ,CAAC,iBAAiB,EAAE,gBAAgB,CAAC;IAC7C;;;;;OAKG;IACH,QAAQ,CAAC,kBAAkB,CAAC,EAAE,WAAW,CAAC;CAC3C;AAkCD;;GAEG;AACH,wBAAgB,gCAAgC,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAG9E;AAED,iEAAiE;AACjE,wBAAgB,mCAAmC,IAAI,IAAI,CAG1D;AAmDD;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAM/D;AA6BD;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,MAAM,GAAG,iBAAiB,GAAG,SAAS,CAW1F;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kCAAkC,CAChD,QAAQ,EAAE,iBAAiB,EAC3B,a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C3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,CAAC,EAAE,cAAc,CAAC;IAC/B,oFAAoF;IACpF,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,yEAAyE;IACzE,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AASD,yFAAyF;AACzF,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,WAAW,CAAC,CAIpE,CAAC;AAEF,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,IAAI,GAAG,WAAW,CAE/D;AAwDD;;;;;GAKG;AACH,eAAO,MAAM,gCAAgC,IAAM,CAAC;AA4NpD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,YAAY,GAAG,kBAAkB,CA2B3E;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,SAAS,YAAY,EAAE,GAAG,kBAAkB,EAAE,CAE1F"}
@@ -337,6 +337,9 @@ const MODEL_PATTERN_RULES = [
337
337
  // adapters (SP-243) pair with sensible economical-tier capability defaults.
338
338
  { pattern: /^glm[-_.]?\d/i, defaults: ECONOMICAL_DEFAULTS },
339
339
  { pattern: /deepseek/i, defaults: ECONOMICAL_DEFAULTS },
340
+ // SP-314 / #195: Kimi K3 / K3.1 are frontier models; require a version or
341
+ // suffix boundary so substring-only ids such as foo-k30 stay unknown.
342
+ { pattern: /^(kimi[-_.]?)?k3(\.\d+)?(-|$)/i, defaults: FRONTIER_DEFAULTS },
340
343
  { pattern: /^composer[-_]/i, defaults: COMPOSER_DEFAULTS },
341
344
  { pattern: /^cursor\//i, defaults: CURSOR_AUTO_DEFAULTS },
342
345
  ];