Claude Code. Any Model. The most powerful AI coding agent now speaks every language.
fix(config): ignore a project .claudish.json model that points at a raw URL
Jack Rudenkoa7ee35f70c63
diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.tsindex 81e9c788..c7107455 100644--- a/packages/cli/src/cli.ts+++ b/packages/cli/src/cli.ts@@ -44,7 +44,8 @@ import type {ProbeStepState,} from "./probe/probe-tui-app.js";import { startProbeTui } from "./probe/probe-tui-runtime.js";-import { getModelMapping, loadConfig, readProOnUltracode } from "./profile-config.js";+import { getRunModelMapping, loadConfig, readProOnUltracode } from "./profile-config.js";+import { usableProfileModels } from "./project-models.js";import { API_KEY_MAP } from "./providers/api-key-map.js";import { type KeyProvenance, resolveCredentialProvenance } from "./providers/api-key-provenance.js";import { normalizeNativeModelSpec } from "./providers/claude-code-aliases.js";@@ -1114,7 +1115,8 @@ export async function parseArgs(args: string[]): Promise<ClaudishConfig> {!config.modelHaiku ||!config.modelSubagent) {- const profileModels = getModelMapping(config.profile);+ // A project profile's raw-URL tiers are dropped here (project-models.ts).+ const profileModels = usableProfileModels(getRunModelMapping(config.profile));// Apply profile models only if not set by CLI flagsif (!config.modelOpus && profileModels.opus) {diff --git a/packages/cli/src/profile-config.ts b/packages/cli/src/profile-config.tsindex 63a992b5..1d7cac66 100644--- a/packages/cli/src/profile-config.ts+++ b/packages/cli/src/profile-config.ts@@ -880,18 +880,33 @@ export function setDefaultProfile(name: string, scope: ProfileScope = "global"):saveConfigForScope(config, scope);}+/** The model tiers a run takes from a profile, and where that profile came from. */+export interface RunModelMapping {+ models: ModelMapping;+ /**+ * The profile's name when it came from the project `.claudish.json`, which ships with+ * the checkout; null for the user's own config. `project-models.ts` checks a project+ * profile's tiers before a run uses them.+ */+ projectProfile: string | null;+}+/**- * Get model mapping from a profile- * Uses local-first resolution when no scope is given+ * The model tiers of the profile a run uses: `profileName`, or the default profile,+ * resolved local-first exactly as `getProfile(name)` / `getDefaultProfile()` resolve it,+ * keeping the scope those discard.*/-export function getModelMapping(profileName?: string): ModelMapping {- const profile = profileName ? getProfile(profileName) : getDefaultProfile();-- if (!profile) {- return {};+export function getRunModelMapping(profileName?: string): RunModelMapping {+ const local = loadLocalConfig();+ const name = profileName || local?.defaultProfile || undefined;+ if (name !== undefined) {+ const fromLocal = local?.profiles[name];+ if (fromLocal) return { models: fromLocal.models ?? {}, projectProfile: name };+ const fromGlobal = loadConfig().profiles[name];+ if (fromGlobal) return { models: fromGlobal.models, projectProfile: null };+ if (profileName) return { models: {}, projectProfile: null };}-- return profile.models;+ return { models: getDefaultProfile("global").models, projectProfile: null };}/**diff --git a/packages/cli/src/project-models.ts b/packages/cli/src/project-models.tsnew file mode 100644index 00000000..f5fe47c6--- /dev/null+++ b/packages/cli/src/project-models.ts@@ -0,0 +1,44 @@+/**+ * A project `.claudish.json` profile may not point a model tier at a raw URL.+ *+ * The project `.claudish.json` comes with the checkout, like its `.env`, and claudish reads+ * it with no trust step. A tier set to `https://host/v1/m` (or `custom-url@https://…`)+ * routes to the raw-URL `custom-url` provider, which needs no key, so the conversation —+ * and the code Claude Code reads — would go to a host the checkout chose. The check is+ * `modelSpecNamesRawUrl`, the same one a `.env` model pin gets (`dotenv-allowlist.ts`).+ *+ * The tier is dropped where tiers enter a run (`cli.ts`), so the next source fills it as if+ * the profile did not set it, with one stderr line naming the tiers, never the values. The+ * file is left as it is, so editing the profile keeps them. The user's own config is not+ * checked: a raw URL there is the user's choice.+ *+ * Its own module, not part of `profile-config.ts`: the parser imports the provider+ * definitions, which import `profile-config.ts`, so the config cannot import the parser+ * without an import cycle (measured: loading `provider-definitions.ts` first then throws+ * "Cannot access '_shortcutsCache' before initialization").+ */++import type { ModelMapping, RunModelMapping } from "./profile-config.js";+import { modelSpecNamesRawUrl } from "./providers/model-parser.js";++/** The tiers a run may take from `run`: a project profile's raw-URL tiers removed. */+export function usableProfileModels(run: RunModelMapping): ModelMapping {+ if (run.projectProfile === null) return run.models;+ const kept: ModelMapping = {};+ const refused: string[] = [];+ for (const [tier, spec] of Object.entries(run.models) as Array<+ [keyof ModelMapping, string | undefined]+ >) {+ if (typeof spec === "string" && modelSpecNamesRawUrl(spec)) refused.push(tier);+ else kept[tier] = spec;+ }+ if (refused.length > 0) console.error(rawUrlProfileNotice(run.projectProfile, refused));+ return kept;+}++/** The one stderr line for project-profile tiers refused as raw URLs. Names only. */+export function rawUrlProfileNotice(profileName: string, tiers: readonly string[]): string {+ const them = tiers.length === 1 ? "it" : "them";+ const models = tiers.length === 1 ? "model" : "models";+ return `[claudish] ignoring the ${tiers.join(", ")} ${models} of profile "${profileName}" in .claudish.json: a project's .claudish.json may not point a model at a raw http(s):// URL. Set ${them} in your shell, with a flag, or in your own claudish config.`;+}