Skip to content

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

fix(cli): tell --models --provider users which vocabulary their slug is from

Jack Rudenkoa01f759834f7
diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts
index 45131354..9d400411 100644
--- a/packages/cli/src/cli.ts
+++ b/packages/cli/src/cli.ts
@@ -61,6 +61,7 @@ import { fetchOllamaModels } from "./providers/ollama-discovery.js";
import { type ProbeResult, describeProbeState } from "./providers/probe-live.js";
import { pinProbeModelSpec, probeProviderRoute } from "./providers/probe-runner.js";
import { BUILTIN_PROVIDERS, getProviderByName } from "./providers/provider-definitions.js";
+import { resolveProviderSlug } from "./providers/provider-slug-resolve.js";
import {
buildRoutingChain,
loadRoutingRules,
@@ -616,9 +617,25 @@ export async function parseArgs(args: string[]): Promise<ClaudishConfig> {
// Pick up --provider <slug> anywhere in the argv. We DON'T consume it
// from the loop — it's read-once here and harmless to let the outer
// passthrough swallow it later because we exit before that.
+ //
+ // Both spellings are read. `--provider=x-ai` used to match nothing, so
+ // the flag was silently dropped and the FULL top-100 printed — a wrong
+ // answer that looks like a right one, which is the same failure class as
+ // the empty-for-a-valid-slug case below.
const providerIdx = args.indexOf("--provider");
- const providerSlug =
- providerIdx !== -1 && providerIdx + 1 < args.length ? args[providerIdx + 1] : null;
+ const inlineProvider = args.find((a) => a.startsWith("--provider="));
+ let providerSlug: string | null = null;
+ if (inlineProvider) {
+ providerSlug = inlineProvider.slice("--provider=".length);
+ } else if (providerIdx !== -1) {
+ const next = args[providerIdx + 1];
+ providerSlug = next && !next.startsWith("--") ? next : "";
+ }
+ if (providerSlug === "") {
+ console.error("--provider needs a slug: claudish --models --provider <slug>");
+ console.error("Run `claudish --providers` for the full list.");
+ process.exit(1);
+ }
if (forceUpdate) clearAllModelCaches();
@@ -1051,12 +1068,86 @@ async function printTop100(jsonOutput: boolean): Promise<void> {
console.log("");
}
+/**
+ * Say what the typed token IS, rather than reporting an empty catalog.
+ *
+ * Three facts, each printed only when true: the near-miss slugs, the routing
+ * prefix the token really belongs to, and where the full vocabulary lives. The
+ * `--json` form carries the same three so a script does not have to scrape
+ * prose, and both exit non-zero — this is a user error, not an empty result.
+ */
+function printUnknownProviderSlug(
+ typedSlug: string,
+ resolved: ReturnType<typeof resolveProviderSlug>,
+ catalogSize: number,
+ jsonOutput: boolean
+): void {
+ if (jsonOutput) {
+ console.log(
+ JSON.stringify(
+ {
+ error: `"${typedSlug}" is not a provider slug in the model catalog`,
+ provider: typedSlug,
+ suggestions: resolved.suggestions.map((s) => s.slug),
+ routingPrefixOwner: resolved.routingOwner,
+ validSlugs: catalogSize,
+ },
+ null,
+ 2
+ )
+ );
+ return;
+ }
+
+ console.error(`\n❌ "${typedSlug}" is not a provider slug in the model catalog.`);
+ if (resolved.suggestions.length > 0) {
+ const list = resolved.suggestions
+ .map((s) => `${s.slug} (${s.count} active model${s.count === 1 ? "" : "s"})`)
+ .join(", ");
+ console.error(`\n Did you mean: ${list}`);
+ }
+ if (resolved.routingOwner) {
+ console.error(
+ `\n "${typedSlug}" IS a claudish routing prefix for the "${resolved.routingOwner}" provider —` +
+ `\n use it with --model: claudish --model ${typedSlug}@<model-id>` +
+ "\n Routing prefixes and catalog vendor slugs are different vocabularies."
+ );
+ }
+ console.error(`\n claudish --providers lists all ${catalogSize} catalog slugs`);
+ console.error(
+ ` claudish -s ${typedSlug}${" ".repeat(Math.max(1, 12 - typedSlug.length))}searches model ids instead\n`
+ );
+}
+
/**
* Print the Firebase catalog filtered to a single provider slug. No local
* footer — this view is explicitly scoped by the user and cross-cutting
* probes would be noise.
*/
-async function printByProvider(providerSlug: string, jsonOutput: boolean): Promise<void> {
+async function printByProvider(typedSlug: string, jsonOutput: boolean): Promise<void> {
+ // Validate against the catalog's OWN vocabulary before querying it. An
+ // unknown token used to produce "No active models found for provider X",
+ // which states a fact about the catalog that is false for every token from a
+ // different vocabulary — `moonshot` is a routing prefix, and the vendor is in
+ // the catalog as `moonshotai`. See providers/provider-slug-resolve.ts.
+ //
+ // A failure to fetch the list is NOT a validation failure: `resolveProviderSlug`
+ // fails open on an empty list, so a catalog outage degrades to the old
+ // behaviour rather than to a confident rejection.
+ let catalogProviders: Awaited<ReturnType<typeof getProviderList>> = [];
+ try {
+ catalogProviders = await getProviderList();
+ } catch {
+ // Fail open — the query below still runs.
+ }
+
+ const resolved = resolveProviderSlug(typedSlug, catalogProviders);
+ if (resolved.kind === "unknown") {
+ printUnknownProviderSlug(typedSlug, resolved, catalogProviders.length, jsonOutput);
+ process.exit(1);
+ }
+
+ const providerSlug = resolved.canonical ?? typedSlug;
let models: ModelDoc[];
try {
models = await getModelsByProvider(providerSlug, 200);
@@ -1076,9 +1167,12 @@ async function printByProvider(providerSlug: string, jsonOutput: boolean): Promi
}
if (models.length === 0) {
+ // A KNOWN slug with nothing active is a different fact from an unknown
+ // slug, and has a different remedy, so it keeps its own wording.
console.log(
- `\nNo active models found for provider "${providerSlug}". Try \`claudish -s <query>\` to search the full catalog.\n`
+ `\nProvider "${providerSlug}" is in the catalog but has no active models right now.`
);
+ console.log("Try `claudish -s <query>` to search the full catalog.\n");
return;
}
diff --git a/packages/cli/src/providers/provider-slug-resolve.test.ts b/packages/cli/src/providers/provider-slug-resolve.test.ts
new file mode 100644
index 00000000..79cb3ab2
--- /dev/null
+++ b/packages/cli/src/providers/provider-slug-resolve.test.ts
@@ -0,0 +1,78 @@
+import { describe, expect, it } from "bun:test";
+
+import { BUILTIN_PROVIDERS } from "./provider-definitions.js";
+import { type CatalogProvider, resolveProviderSlug } from "./provider-slug-resolve.js";
+
+/**
+ * A stand-in for `getProviderList()`. Shaped like the live answer — slug plus
+ * active-model count — but fixed, so the assertions are about the resolver and
+ * not about what the catalog happens to hold today.
+ */
+const CATALOG: CatalogProvider[] = [
+ { slug: "qwen", count: 314 },
+ { slug: "google", count: 121 },
+ { slug: "openai", count: 104 },
+ { slug: "z-ai", count: 46 },
+ { slug: "x-ai", count: 23 },
+ { slug: "moonshotai", count: 6 },
+ { slug: "openrouter", count: 15 },
+];
+
+describe("resolveProviderSlug", () => {
+ it("matches a catalog slug and hands back the catalog's own spelling", () => {
+ expect(resolveProviderSlug("x-ai", CATALOG)).toMatchObject({
+ kind: "match",
+ canonical: "x-ai",
+ });
+ });
+
+ it("canonicalizes case rather than rejecting it", () => {
+ expect(resolveProviderSlug("MoonshotAI", CATALOG)).toMatchObject({
+ kind: "match",
+ canonical: "moonshotai",
+ });
+ });
+
+ it("calls a routing prefix unknown, and names the vendor it plausibly meant", () => {
+ // The reported defect: `--provider moonshot` answered "no active models",
+ // which is a false claim about the catalog — the vendor is in it as
+ // `moonshotai`, with 6 active models.
+ const resolved = resolveProviderSlug("moonshot", CATALOG);
+ expect(resolved.kind).toBe("unknown");
+ expect(resolved.suggestions.map((s) => s.slug)).toEqual(["moonshotai"]);
+ });
+
+ it("names the builtin that owns the token as a routing prefix", () => {
+ const resolved = resolveProviderSlug("moonshot", CATALOG);
+ // Not pinned to a literal: the owner is whatever BUILTIN_PROVIDERS says
+ // today, and the assertion is that the answer is a real builtin.
+ expect(resolved.routingOwner).not.toBeNull();
+ expect(BUILTIN_PROVIDERS.map((p) => p.name)).toContain(resolved.routingOwner as string);
+ });
+
+ it("reports no routing owner for a token that is not one", () => {
+ expect(resolveProviderSlug("nope-vendor-xyz", CATALOG).routingOwner).toBeNull();
+ });
+
+ it("offers nothing rather than a confident wrong guess", () => {
+ const resolved = resolveProviderSlug("nope-vendor-xyz", CATALOG);
+ expect(resolved.kind).toBe("unknown");
+ expect(resolved.suggestions).toEqual([]);
+ });
+
+ it("ranks a substring match above a shared prefix, and busier vendors first", () => {
+ const resolved = resolveProviderSlug("open", CATALOG);
+ expect(resolved.kind).toBe("unknown");
+ expect(resolved.suggestions.map((s) => s.slug)).toEqual(["openai", "openrouter"]);
+ });
+
+ it("fails OPEN when the provider list could not be fetched", () => {
+ // A validator that rejects when it cannot reach its own vocabulary would
+ // turn a catalog outage into "that is not a provider".
+ expect(resolveProviderSlug("x-ai", [])).toMatchObject({
+ kind: "match",
+ canonical: "x-ai",
+ suggestions: [],
+ });
+ });
+});
diff --git a/packages/cli/src/providers/provider-slug-resolve.ts b/packages/cli/src/providers/provider-slug-resolve.ts
new file mode 100644
index 00000000..5f6a5caf
--- /dev/null
+++ b/packages/cli/src/providers/provider-slug-resolve.ts
@@ -0,0 +1,129 @@
+/**
+ * Resolve what a user typed after `--models --provider` against the catalog's
+ * own provider vocabulary.
+ *
+ * ── Why this exists ─────────────────────────────────────────────────────────
+ *
+ * Three vocabularies name providers and they are NOT the same list
+ * (`ai-docs/architecture/routing.md`):
+ *
+ * 1. the catalog's VENDOR SLUG — `moonshotai`, `z-ai`, `x-ai` — which is what
+ * `--providers` lists and what the hosted `?provider=` query matches;
+ * 2. claudish's ROUTING PREFIX — `moonshot@`, `kimi@`, `gk@` — which is what
+ * `--model` takes;
+ * 3. the picker's display label.
+ *
+ * `--provider moonshot` answered
+ *
+ * No active models found for provider "moonshot".
+ *
+ * which states a fact about the CATALOG that is not true — the vendor is in it,
+ * under `moonshotai`, with 6 active models. `moonshot` is vocabulary 2: a
+ * routing shortcut for the `kimi` builtin. The message sent a user to look for
+ * missing data instead of at the spelling, and an empty answer for a name that
+ * works everywhere else in the CLI reads as a claudish bug.
+ *
+ * So the resolver answers three DIFFERENT questions separately, because they
+ * have three different remedies: the slug matched (query it), the slug is not
+ * in the catalog's vocabulary (name what is), or the slug is a routing prefix
+ * the user is entitled to think is a provider name (say which vocabulary it
+ * belongs to).
+ *
+ * Nothing here is hardcoded. The valid slugs come from the live catalog and the
+ * routing tokens from `reservedNamespaceOwner`, which builds itself from
+ * `BUILTIN_PROVIDERS` at call time.
+ */
+
+import { reservedNamespaceOwner } from "./reserved-namespace.js";
+
+/** One row of the catalog's provider list, as `getProviderList()` returns it. */
+export interface CatalogProvider {
+ slug: string;
+ count: number;
+}
+
+export interface ProviderSlugResolution {
+ /**
+ * `"match"` — query the catalog with `canonical`.
+ * `"unknown"` — the catalog's vocabulary does not contain this token.
+ */
+ kind: "match" | "unknown";
+ /** The catalog's OWN spelling of the slug, for a match. */
+ canonical: string | null;
+ /** Catalog slugs worth suggesting, best first, at most `SUGGESTION_LIMIT`. */
+ suggestions: CatalogProvider[];
+ /**
+ * The builtin provider that answers to this token as a ROUTING prefix, when
+ * one does. `moonshot` → `kimi`. Set even for a match (`openai` is both), so
+ * the caller decides when it is worth mentioning.
+ */
+ routingOwner: string | null;
+}
+
+const SUGGESTION_LIMIT = 5;
+/** Shortest shared prefix worth calling a near miss. `z-a` → `z-ai`, not `x` → everything. */
+const MIN_PREFIX_OVERLAP = 3;
+
+function sharedPrefixLength(a: string, b: string): number {
+ let n = 0;
+ while (n < a.length && n < b.length && a[n] === b[n]) n++;
+ return n;
+}
+
+/**
+ * Rank the catalog slugs that a typed token plausibly meant.
+ *
+ * Substring relatedness first (`moonshot` ↔ `moonshotai`), then a shared
+ * prefix, then by active-model count so the busiest vendor leads. Deliberately
+ * NOT an edit-distance search: a fuzzy match that confidently suggests the
+ * wrong vendor is worse than suggesting nothing, and `--providers` is one line
+ * away.
+ */
+function rankSuggestions(typed: string, providers: CatalogProvider[]): CatalogProvider[] {
+ const needle = typed.toLowerCase();
+ const scored: Array<{ provider: CatalogProvider; score: number }> = [];
+ for (const provider of providers) {
+ const slug = provider.slug.toLowerCase();
+ let score = 0;
+ if (slug.includes(needle) || needle.includes(slug)) {
+ score = 2;
+ } else if (sharedPrefixLength(slug, needle) >= MIN_PREFIX_OVERLAP) {
+ score = 1;
+ }
+ if (score > 0) scored.push({ provider, score });
+ }
+ scored.sort((a, b) => b.score - a.score || b.provider.count - a.provider.count);
+ return scored.slice(0, SUGGESTION_LIMIT).map((s) => s.provider);
+}
+
+/**
+ * Decide how to treat `typed` against the catalog's provider list.
+ *
+ * `providers` empty means the list could not be fetched. The resolver then
+ * FAILS OPEN — `kind: "match"` with the token as given — so a catalog outage
+ * degrades to the old behaviour (ask the backend and print what it says) rather
+ * than to a confident "that is not a provider". A validator that rejects when
+ * it cannot reach its own vocabulary is worse than no validator.
+ */
+export function resolveProviderSlug(
+ typed: string,
+ providers: CatalogProvider[]
+): ProviderSlugResolution {
+ const routingOwner = reservedNamespaceOwner(typed) ?? null;
+
+ if (providers.length === 0) {
+ return { kind: "match", canonical: typed, suggestions: [], routingOwner };
+ }
+
+ const exact = providers.find((p) => p.slug.toLowerCase() === typed.toLowerCase());
+ if (exact) {
+ return { kind: "match", canonical: exact.slug, suggestions: [], routingOwner };
+ }
+
+ return {
+ kind: "unknown",
+ canonical: null,
+ suggestions: rankSuggestions(typed, providers),
+ routingOwner,
+ };
+}