Skip to content

Claude Code. Any Model. The most powerful AI coding agent now speaks every language.

fix(tui): label route probe hops by tier, not a provider map

Jack Rudenko72ae5e654cc8
diff --git a/packages/cli/src/providers/qwen-coding-plan.test.ts b/packages/cli/src/providers/qwen-coding-plan.test.ts
index 8bb06ccb..cb90882e 100644
--- a/packages/cli/src/providers/qwen-coding-plan.test.ts
+++ b/packages/cli/src/providers/qwen-coding-plan.test.ts
@@ -17,10 +17,11 @@
import { describe, expect, test } from "bun:test";
import { buildProviderChoices } from "../model-selector.js";
-import { PROVIDER_REASONS } from "../tui/components/RoutingContent.js";
+import { probeRowLabel } from "../tui/components/RoutingContent.js";
import { API_KEY_MAP } from "./api-key-map.js";
import { describeMissingCredential, getProviderByName } from "./provider-definitions.js";
import { getProviderApiKeyEnv } from "./routing-hints.js";
+import { TIER_LABEL } from "./routing-rules.js";
const CODING = "qwen-coding";
const TOKEN = "qwen-token-plan";
@@ -55,11 +56,18 @@ describe("qwen-coding — every hand-written table that shadows the definition",
});
test("the config TUI's routing panel names all three products", () => {
- // Absent, a row renders its bare uid as its own explanation — not visibly
- // broken, which is why it needs a test rather than a look.
- expect(PROVIDER_REASONS[CODING]).toBe("Alibaba Coding Plan");
- expect(PROVIDER_REASONS[TOKEN]).toBe("Alibaba Token Plan");
- expect(PROVIDER_REASONS[PAYG]).toBe("Alibaba PAYG");
+ for (const name of [CODING, TOKEN, PAYG]) {
+ const def = getProviderByName(name)!;
+ expect(def.tier).toBeDefined();
+ expect(
+ probeRowLabel({
+ displayName: def.displayName,
+ status: "pending",
+ tier: def.tier,
+ position: "candidate",
+ })
+ ).toBe(`${def.displayName} · ${TIER_LABEL[def.tier!]}`);
+ }
});
test("a 401 names the other two silos' keys as not-accepted-here", () => {
diff --git a/packages/cli/src/tui/components/RoutingContent.tsx b/packages/cli/src/tui/components/RoutingContent.tsx
index 6159f3de..5813d93e 100644
--- a/packages/cli/src/tui/components/RoutingContent.tsx
+++ b/packages/cli/src/tui/components/RoutingContent.tsx
@@ -2,7 +2,7 @@ import type { ScrollBoxRenderable } from "@opentui/core";
/** @jsxImportSource @opentui/react */
import { useEffect, useRef } from "react";
import type { ClaudishProfileConfig } from "../../profile-config.js";
-import { DEFAULT_FALLBACK_PROVIDER } from "../../providers/routing-rules.js";
+import { DEFAULT_FALLBACK_PROVIDER, TIER_LABEL } from "../../providers/routing-rules.js";
import { DETAIL_H, getChainProviders } from "../constants.js";
import { deriveProbeOutcome } from "../probe-outcome.js";
import { providerIsReady } from "../providers.js";
@@ -76,38 +76,56 @@ function chainStr(chain: string[]): string {
return chain.join(" → ");
}
+/** The native passthrough's hop label: it has no tier; Claude Code's own auth serves it. */
+const NATIVE_HOP_LABEL = "Claude Code's own auth";
+
/**
- * Reasons shown beneath each probe entry.
+ * A probe row's hop label: `TIER_LABEL` for the tier of the provider holding
+ * the hop, or "fallback" for the fallback POSITION whichever provider holds it,
+ * the rule `describeRouteExplanation` applies to the first hop.
*
- * Exported for the drift test only. A provider missing from here renders its
- * bare uid (`entry.provider`) as its own explanation — which is not an error and
- * not visibly wrong, so the three Alibaba rows would silently read
- * "qwen-token-plan / qwen-coding / qwen-payg" instead of naming the three
- * products the user is choosing between. Nothing is DERIVED from this map; it
- * only labels. The Alibaba labels equal each definition's `displayName`, and
- * `qwen-coding-plan.test.ts` holds them to it.
+ * Derived, never a per-provider table. The map this replaces (19 hand-written
+ * reasons) labelled OpenRouter "Fallback" wherever it stood in a chain, and any
+ * provider it did not list read as its bare uid; a tier label is right for a
+ * provider added tomorrow with no edit here.
*/
-export const PROVIDER_REASONS: Record<string, string> = {
- litellm: "LiteLLM proxy",
- "opencode-zen": "Free tier (OpenCode Zen)",
- "opencode-zen-go": "Zen Go plan",
- kimi: "Native Kimi API",
- "kimi-coding": "Kimi Coding Plan",
- minimax: "Native MiniMax API",
- "minimax-coding": "MiniMax Coding Plan",
- glm: "Native GLM API",
- "glm-coding": "GLM Coding Plan",
- "qwen-token-plan": "Alibaba Token Plan",
- "qwen-coding": "Alibaba Coding Plan",
- "qwen-payg": "Alibaba PAYG",
- google: "Direct Gemini API",
- openai: "Direct OpenAI API",
- "openai-codex": "OpenAI Codex (Responses API)",
- zai: "Z.AI API",
- ollamacloud: "Cloud Ollama",
- vertex: "Vertex AI (ADC)",
- openrouter: "Fallback: 580+ models",
-};
+export function hopLabel(entry: Pick<ProbeEntry, "status" | "tier" | "position">): string {
+ if (entry.status === "unverified") return NATIVE_HOP_LABEL;
+ if (entry.position === "fallback") return TIER_LABEL.fallback;
+ return entry.tier ? TIER_LABEL[entry.tier] : "unregistered provider";
+}
+
+/**
+ * The text of a probe row's second line: the provider's display name, which the
+ * first line truncates (the three Alibaba products are the definitions' own
+ * names: "Alibaba Coding Plan", "Alibaba Token Plan", "Alibaba PAYG"), then its
+ * hop label.
+ */
+export function probeRowLabel(
+ entry: Pick<ProbeEntry, "displayName" | "status" | "tier" | "position">
+): string {
+ return `${entry.displayName} · ${hopLabel(entry)}`;
+}
+
+/** The hop label's colour, read from `C` at render time, never snapshotted. */
+function hopLabelColor(entry: ProbeEntry): string {
+ if (entry.status === "dropped") return C.dim;
+ if (entry.status === "unverified") return C.cyan;
+ if (entry.position === "fallback") return C.yellow;
+ switch (entry.tier) {
+ case "subscription":
+ case "dynamic-subscription":
+ return C.green;
+ case "native":
+ return C.cyan;
+ case "gateway":
+ return C.blue;
+ case "fallback":
+ return C.yellow;
+ default:
+ return C.dim;
+ }
+}
interface RoutingContentProps {
config: ClaudishProfileConfig;
@@ -318,7 +336,6 @@ export function RoutingContent({
const isSelected = entry.status === "success" && probeMode === "done";
const status = rowStatusView(entry);
const nameCol = entry.displayName.padEnd(18).substring(0, 18);
- const reason = PROVIDER_REASONS[entry.provider] ?? entry.provider;
return (
<box key={`${idx}:${entry.provider}`} flexDirection="column">
@@ -341,8 +358,11 @@ export function RoutingContent({
)}
</text>
<text>
+ {/* probeRowLabel's two parts, the label in its tier colour */}
<span fg={C.dim}>{" ↳ "}</span>
- <span fg={isDropped ? C.dim : C.fgMuted}>{reason}</span>
+ <span fg={isDropped ? C.dim : C.fgMuted}>{entry.displayName}</span>
+ <span fg={C.dim}>{" · "}</span>
+ <span fg={hopLabelColor(entry)}>{hopLabel(entry)}</span>
</text>
</box>
);