Claude Code. Any Model. The most powerful AI coding agent now speaks every language.
fix(meta-muse-code): send the Muse login only to api.meta.ai
Jack Rudenkof08e5d97c433
diff --git a/README.md b/README.mdindex 88b36831..56c93f2c 100644--- a/README.md+++ b/README.md@@ -456,7 +456,6 @@ Every one of these also accepts `CUSTOM_<NAME>_KEY` as an alias, and any of them| `QWEN_TOKEN_PLAN_BASE_URL` | Alibaba Token Plan | `https://token-plan.ap-southeast-1.maas.aliyuncs.com` || `DASHSCOPE_BASE_URL` | Alibaba PAYG | `https://dashscope-intl.aliyuncs.com` || `META_BASE_URL` | Meta Model API (`meta@`) | `https://api.meta.ai` |-| `MUSE_CODE_BASE_URL` | Muse Code subscription (`muse@`) | `https://api.meta.ai` || `OLLAMACLOUD_BASE_URL` | OllamaCloud | `https://ollama.com` || `OPENCODE_BASE_URL` | OpenCode Zen | `https://opencode.ai/zen` || `LITELLM_BASE_URL` | LiteLLM proxy server | _(required with LITELLM_API_KEY)_ |diff --git a/ai-docs/architecture/providers/meta-muse-code.md b/ai-docs/architecture/providers/meta-muse-code.mdindex bb943fd9..8624ac3b 100644--- a/ai-docs/architecture/providers/meta-muse-code.md+++ b/ai-docs/architecture/providers/meta-muse-code.md@@ -227,6 +227,18 @@ POST https://auth.meta.com/oidc/device/token/ (form)- Logout deletes both files and revokes nothing remotely. The shape of `muse-code/logout` wasnever captured.+## One host, with no override++The `dca:` login, the minted key and every Muse request go only to `https://api.meta.ai`+(`MUSE_CODE_BASE_URL`, a constant in `providers/meta-muse/muse-mint.ts`); the definition declares+no `baseUrlEnvVars`. An earlier cut honoured an environment override, then an opt-in variable for+a non-Meta host, then the opt-in only from the inherited environment. Each was bypassable: Bun loads+`.env`, `.env.local` and `.env.<NODE_ENV>` from the working directory before the first claudish+module runs (measured on Bun 1.4.0), so any repository the user runs claudish in could set both+variables and receive the login, which may be the one copied from the Muse Code CLI's Keychain+item. No environment-based switch can be trusted, so there is none. Tests use the mint's injected+`fetch` seam.+## The mint is the entitlement evidence```diff --git a/docs/settings-reference.md b/docs/settings-reference.mdindex 49aacb52..4f69f0f1 100644--- a/docs/settings-reference.md+++ b/docs/settings-reference.md@@ -269,7 +269,6 @@ If none of them answers, the error says so and names both remedies (`VERTEX_PROJ| `QWEN_CODING_PLAN_BASE_URL` | Alibaba Coding Plan endpoint | `https://coding-intl.dashscope.aliyuncs.com` || `DASHSCOPE_BASE_URL` | Alibaba PAYG endpoint; repoint here for a mainland-China account | `https://dashscope-intl.aliyuncs.com` || `META_BASE_URL` | Meta Model API (`meta@`) | `https://api.meta.ai` |-| `MUSE_CODE_BASE_URL` | Muse Code subscription (`muse@`): the `/v1/responses`, `/muse-code/key` and `/muse-code/models` host | `https://api.meta.ai` || `OLLAMACLOUD_BASE_URL` | OllamaCloud hosted API | `https://ollama.com` || `OPENCODE_BASE_URL` | OpenCode Zen API (base; `/v1/chat/completions` appended) | `https://opencode.ai/zen` || `LITELLM_BASE_URL` | LiteLLM proxy server URL (**required** to enable LiteLLM routing) | none |diff --git a/docs/usage/muse-code.md b/docs/usage/muse-code.mdindex 3e885a1e..a4d4468e 100644--- a/docs/usage/muse-code.md+++ b/docs/usage/muse-code.md@@ -156,6 +156,12 @@ minutes, so a lapsed subscription stops within 30 minutes even in a long sessionIf your Muse Code login expires mid-session, the request stops with a login message. claudish doesnot move the request to a metered provider.+## Where your login goes++claudish sends your Muse Code login, the key it mints from it, and every `muse@` request only to+`https://api.meta.ai`. There is no setting to change that host: a `.env` file in a project folder+could otherwise redirect your login to someone else's server.+## Logging out```bashdiff --git a/packages/cli/src/env-snapshot.ts b/packages/cli/src/env-snapshot.tsdeleted file mode 100644index 250b22bd..00000000--- a/packages/cli/src/env-snapshot.ts+++ /dev/null@@ -1,11 +0,0 @@-/**- * Side-effect module: snapshot environment variables that must never be- * satisfiable from a cwd `.env`, BEFORE `index.ts` calls `dotenv.config()`.- *- * ES modules evaluate every import before the importing module's body runs,- * and `index.ts` calls `config()` in its body, so importing this module from- * `index.ts`'s import list is what makes the snapshot pre-dotenv.- */-import { captureInheritedMuseEnv } from "./providers/meta-muse/muse-env-trust.js";--captureInheritedMuseEnv();diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.tsindex 18aec91a..45279cc1 100644--- a/packages/cli/src/index.ts+++ b/packages/cli/src/index.ts@@ -8,9 +8,6 @@ import {assertPaneChildInteractive,paneChildBootNotes,} from "./pane/child-env.js";-// Before `.env` loading: the variables that decide where the Muse Code login may-// be sent are read from the INHERITED environment only (env-snapshot.ts).-import "./env-snapshot.js";// Load .env file before anything else (quiet mode to suppress verbose output)import { config } from "dotenv";diff --git a/packages/cli/src/providers/meta-muse/muse-env-trust.ts b/packages/cli/src/providers/meta-muse/muse-env-trust.tsdeleted file mode 100644index bc6536cd..00000000--- a/packages/cli/src/providers/meta-muse/muse-env-trust.ts+++ /dev/null@@ -1,44 +0,0 @@-/**- * The two Muse Code host variables as the process INHERITED them, before- * `index.ts` loads a `.env` from the current directory.- *- * `MUSE_CODE_BASE_URL` decides where the Muse Code login is sent, and- * `CLAUDISH_MUSE_CODE_ALLOW_CUSTOM_HOST` permits a host other than- * api.meta.ai. If either could come from a cwd `.env`, a cloned repository- * could ship both and redirect the login. So `museTrustedBaseUrl` honours the- * opt-in only from this snapshot, and refuses a non-Meta base URL that the- * snapshot does not carry (it came from `.env`).- *- * Captured by an explicit call that `index.ts` makes from its import list,- * which ES modules evaluate before the module body calls `dotenv.config()`.- * When nothing captured it, the snapshot is unknown and the opt-in is- * unavailable: the safe answer.- */--export interface InheritedMuseEnv {- baseUrl: string | undefined;- allowCustomHost: string | undefined;-}--let snapshot: InheritedMuseEnv | null = null;--/** Record the inherited values. Only the first call counts. */-export function captureInheritedMuseEnv(- env: Record<string, string | undefined> = process.env-): void {- if (snapshot) return;- snapshot = {- baseUrl: env.MUSE_CODE_BASE_URL,- allowCustomHost: env.CLAUDISH_MUSE_CODE_ALLOW_CUSTOM_HOST,- };-}--/** The inherited values, or null when nothing captured them. */-export function inheritedMuseEnv(): InheritedMuseEnv | null {- return snapshot;-}--/** Test seam: forget the snapshot. */-export function _resetInheritedMuseEnvForTest(): void {- snapshot = null;-}diff --git a/packages/cli/src/providers/meta-muse/muse-mint.ts b/packages/cli/src/providers/meta-muse/muse-mint.tsindex a0f4678c..9fe43b76 100644--- a/packages/cli/src/providers/meta-muse/muse-mint.ts+++ b/packages/cli/src/providers/meta-muse/muse-mint.ts@@ -42,10 +42,18 @@import { markOwnTimeout } from "../../handlers/shared/connection-error.js";import { VERSION } from "../../version.js";-import { inheritedMuseEnv } from "./muse-env-trust.js";-/** The default base host. `MUSE_CODE_BASE_URL` overrides it (the provider's `baseUrlEnvVars`). */-export const MUSE_CODE_DEFAULT_BASE_URL = "https://api.meta.ai";+/**+ * The ONLY host the Muse Code login, the minted key and Muse requests go to.+ *+ * Fixed, with no environment override. Bun loads the cwd `.env` before any+ * claudish code runs (measured on Bun 1.4.0), so a variable that redirected+ * this host — or one that opted into redirecting it — could be set by any+ * repository the user runs claudish in, and would send the durable `dca:`+ * login (possibly the one copied from the Muse Code CLI's Keychain item) to+ * that repository's server. Tests use the injected `fetch` seam instead.+ */+export const MUSE_CODE_BASE_URL = "https://api.meta.ai";/** Meta's subscribe page, used when the mint names no `action_url` of its own. */export const MUSE_CODE_SUBSCRIBE_URL = "https://accountscenter.meta.com/muse_code/?ep=no_payg";@@ -113,81 +121,12 @@ export class MuseMintTransientError extends Error {}}-/** The only host the Muse Code login is sent to without an explicit opt-in. */-export const MUSE_CODE_TRUSTED_HOST = "api.meta.ai";--/** The env var that permits a `MUSE_CODE_BASE_URL` on any other host (a test rig, a proxy you run). */-export const MUSE_CODE_ALLOW_CUSTOM_HOST_ENV = "CLAUDISH_MUSE_CODE_ALLOW_CUSTOM_HOST";--/**- * The base URL the `dca:` login (the mint) and the minted key (the model list- * and `/v1/responses`) may be sent to.- *- * WHY THIS REFUSES. The `dca:` token is the account's durable login, possibly- * the one copied from the Muse Code CLI's Keychain item, and it mints keys until- * Meta revokes it. `index.ts` loads a `.env` from whatever directory claudish- * runs in, so a cloned repository could set `MUSE_CODE_BASE_URL` (and the- * opt-in) and redirect the login to its own host. The rules:- *- * - `https://api.meta.ai`, with no userinfo, query or fragment, is honoured- * from anywhere; the result is the URL's origin plus its path, nothing else.- * - Any other host needs `CLAUDISH_MUSE_CODE_ALLOW_CUSTOM_HOST=1` in the- * environment the process INHERITED (`muse-env-trust.ts`, snapshotted before- * dotenv runs), AND the base URL itself must be the inherited value: a `.env`- * can supply neither. Plain `http://` is then accepted only for loopback.- *- * Every refusal is terminal and names the variable. When `env` is not- * `process.env` (the injected test seam), it is treated as inherited.- */-export function museTrustedBaseUrl(env: Record<string, string | undefined> = process.env): string {- const raw = env.MUSE_CODE_BASE_URL?.trim();- if (!raw) return MUSE_CODE_DEFAULT_BASE_URL;- let url: URL;- try {- url = new URL(raw);- } catch {- throw new MuseMintProtocolError(`MUSE_CODE_BASE_URL is not a URL: ${raw}`);- }- if (url.username || url.password || url.search || url.hash) {- throw new MuseMintProtocolError(- "MUSE_CODE_BASE_URL may not carry credentials, a query or a fragment."- );- }- const base = `${url.origin}${url.pathname.replace(/\/+$/, "")}`;- if (url.protocol === "https:" && url.hostname === MUSE_CODE_TRUSTED_HOST) return base;-- const inherited =- env === process.env- ? inheritedMuseEnv()- : { baseUrl: env.MUSE_CODE_BASE_URL, allowCustomHost: env[MUSE_CODE_ALLOW_CUSTOM_HOST_ENV] };- const fromDotenv = inherited?.baseUrl?.trim() !== raw;- if (inherited?.allowCustomHost !== "1" || fromDotenv) {- throw new MuseMintProtocolError(- `MUSE_CODE_BASE_URL points at ${url.protocol}//${url.host}, not https://${MUSE_CODE_TRUSTED_HOST}: claudish will not send your Muse Code login there. ${- fromDotenv- ? "It was not set by your shell (a .env in the current directory may not redirect the login)."- : `Unset it, or export ${MUSE_CODE_ALLOW_CUSTOM_HOST_ENV}=1 in your shell (a .env does not count) if you run that host yourself.`- }`- );- }- const loopback = ["localhost", "127.0.0.1", "[::1]", "::1"].includes(url.hostname);- if (url.protocol !== "https:" && !(url.protocol === "http:" && loopback)) {- throw new MuseMintProtocolError(- `MUSE_CODE_BASE_URL must be https:// (plain http:// only for a loopback test server): ${raw}`- );- }- return base;-}--/** The mint endpoint for the configured base host (see {@link museTrustedBaseUrl}). */-export function museMintUrl(env: Record<string, string | undefined> = process.env): string {- return `${museTrustedBaseUrl(env)}/muse-code/key`;-}+/** The mint endpoint (fixed: see {@link MUSE_CODE_BASE_URL}). */+export const MUSE_MINT_URL = `${MUSE_CODE_BASE_URL}/muse-code/key`;/** Injectable `fetch`, so the mint is testable without a network. */export interface MuseMintDeps {fetch: typeof fetch;- env: Record<string, string | undefined>;}/**@@ -200,7 +139,7 @@ export async function mintMuseApiKey(deps: Partial<MuseMintDeps> = {}): Promise<MuseMint> {const doFetch = deps.fetch ?? fetch;- const url = museMintUrl(deps.env ?? process.env);+ const url = MUSE_MINT_URL;let response: Response;try {diff --git a/packages/cli/src/providers/meta-muse/muse-models.ts b/packages/cli/src/providers/meta-muse/muse-models.tsindex 17e39f7b..74b9931e 100644--- a/packages/cli/src/providers/meta-muse/muse-models.ts+++ b/packages/cli/src/providers/meta-muse/muse-models.ts@@ -24,7 +24,7 @@import { credentials } from "../../auth/credentials/authority.js";import { VERSION } from "../../version.js";import type { DiscoveredModel, FetcherResult } from "../model-discovery.js";-import { museTrustedBaseUrl } from "./muse-mint.js";+import { MUSE_CODE_BASE_URL } from "./muse-mint.js";const FETCH_TIMEOUT_MS = 15_000;@@ -33,12 +33,8 @@ function oneLine(text: string, max = 200): string {return flat.length > max ? `${flat.slice(0, max)}…` : flat;}-/** The models endpoint for the configured base host. */-export function museModelsUrl(env: Record<string, string | undefined> = process.env): string {- // The same host rule as the mint: the minted key goes only where the login may.- const base = museTrustedBaseUrl(env);- return `${base}/muse-code/models`;-}+/** The models endpoint: the minted key goes only to the fixed Muse Code host. */+export const MUSE_MODELS_URL = `${MUSE_CODE_BASE_URL}/muse-code/models`;interface MuseModelMetadata {name?: unknown;@@ -92,15 +88,7 @@ export function parseMuseModels(body: unknown): DiscoveredModel[] | null {/** The `muse-code-models` fetcher. Never throws. */export async function fetchMuseCodeModelsCatalog(): Promise<FetcherResult> {- let endpoint: string;- try {- endpoint = museModelsUrl();- } catch (err) {- return {- kind: "failed",- failure: { kind: "no-credentials", detail: oneLine((err as Error).message) },- };- }+ const endpoint = MUSE_MODELS_URL;let headers: Record<string, string>;try {const auth = await credentials.getRequestAuth("meta-muse-code", { model: "" });diff --git a/packages/cli/src/providers/provider-definitions.ts b/packages/cli/src/providers/provider-definitions.tsindex 278c85ad..fe815138 100644--- a/packages/cli/src/providers/provider-definitions.ts+++ b/packages/cli/src/providers/provider-definitions.ts@@ -712,10 +712,10 @@ export const BUILTIN_PROVIDERS: TieredProviderDefinition[] = [transport: "meta-muse-code",tokenStrategy: "delta-aware",baseUrl: "https://api.meta.ai",- // The mint and the model list honour MUSE_CODE_BASE_URL only on- // https://api.meta.ai unless CLAUDISH_MUSE_CODE_ALLOW_CUSTOM_HOST=1: the- // login is never sent to a host a cwd `.env` named (`museTrustedBaseUrl`).- baseUrlEnvVars: ["MUSE_CODE_BASE_URL"],+ // No baseUrlEnvVars, deliberately: the login, the minted key and every+ // request go only to https://api.meta.ai. Bun loads a cwd `.env` before any+ // claudish code runs, so an override could be set by any repository+ // (`MUSE_CODE_BASE_URL` in providers/meta-muse/muse-mint.ts).apiPath: "/v1/responses",// MUST stay empty, as for gk@/ag@/dv@: a non-empty value makes the generic// loop register an api-key provider and lets proxy-server cache a minteddiff --git a/packages/cli/src/providers/transport/meta-muse-code.ts b/packages/cli/src/providers/transport/meta-muse-code.tsindex 691c4669..db6f200a 100644--- a/packages/cli/src/providers/transport/meta-muse-code.ts+++ b/packages/cli/src/providers/transport/meta-muse-code.ts@@ -23,7 +23,7 @@import { credentials } from "../../auth/credentials/authority.js";import type { RequestAuth } from "../../auth/credentials/types.js";import { forceRefreshMuseApiKey, requestPathMayPrompt } from "../meta-muse/muse-credentials.js";-import { museTrustedBaseUrl } from "../meta-muse/muse-mint.js";+import { MUSE_CODE_BASE_URL } from "../meta-muse/muse-mint.js";import { discoverContextWindow } from "../model-discovery.js";import { OpenAIProviderTransport } from "./openai.js";@@ -43,19 +43,15 @@ export class MuseCodeTransport extends OpenAIProviderTransport {private windowRetryAt = 0;/**- * The base URL `/v1/responses` goes to, under the same host rule as the mint- * (`museTrustedBaseUrl`): the request carries the minted key and the prompt.- * Resolved in refreshAuth, so a refused host is a terminal answer at the auth- * site rather than a throw out of getEndpoint.+ * `/v1/responses` on the fixed Muse Code host, whatever the provider's base+ * URL says: the request carries the minted key and the prompt, and nothing in+ * the environment may redirect them (`MUSE_CODE_BASE_URL` in muse-mint.ts).*/- private trustedBase?: string;-override getEndpoint(): string {- return this.trustedBase ? `${this.trustedBase}/v1/responses` : super.getEndpoint();+ return `${MUSE_CODE_BASE_URL}/v1/responses`;}async refreshAuth(): Promise<void> {- this.trustedBase = museTrustedBaseUrl();this.auth = await credentials.getRequestAuth("meta-muse-code", { model: this.modelName });if (!this.window && Date.now() >= this.windowRetryAt) {this.window = (await discoverContextWindow("meta-muse-code", this.modelName)) ?? 0;