Skip to content

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

fix(probe): name the Muse login that signed each probe request

Jack Rudenkoa7a765500b56
diff --git a/packages/cli/src/auth/credentials/muse-code-credential.ts b/packages/cli/src/auth/credentials/muse-code-credential.ts
index 851ca7a3..65075df6 100644
--- a/packages/cli/src/auth/credentials/muse-code-credential.ts
+++ b/packages/cli/src/auth/credentials/muse-code-credential.ts
@@ -18,6 +18,7 @@ import {
ensureMuseCredentialReady,
isMuseCredentialConfigured,
museCredentialStatusFromFiles,
+ museSignerLabel,
refreshMuseCredentialStatus,
requestPathMayPrompt,
resetMuseCredentialState,
@@ -70,7 +71,12 @@ export class MuseCodeCredentialProvider implements CredentialProvider {
/** A confirmed key; the request path may use the Keychain only in an interactive launch. */
async getRequestAuth(): Promise<RequestAuth> {
const state = await ensureMuseCredentialReady({ prompt: requestPathMayPrompt() });
- return { headers: { Authorization: `Bearer ${state.key}` }, arm: "oauth" };
+ return {
+ headers: { Authorization: `Bearer ${state.key}` },
+ arm: "oauth",
+ // The source and tier of THIS state, captured with the key it signs with.
+ signer: museSignerLabel(state),
+ };
}
invalidate(): void {
diff --git a/packages/cli/src/auth/credentials/types.ts b/packages/cli/src/auth/credentials/types.ts
index e1908caa..60a88164 100644
--- a/packages/cli/src/auth/credentials/types.ts
+++ b/packages/cli/src/auth/credentials/types.ts
@@ -147,6 +147,13 @@ export interface RequestAuth {
* hiding a real bill. See `OpenAICodexTransport.refreshAuth`.
*/
arm?: CredentialArm;
+ /**
+ * A display-safe name of the credential that signed (no secret in it), for
+ * a provider with several login sources: Muse Code's
+ * `Muse Code borrowed copy · Muse Code Power Usage`. A transport returns it
+ * from `signingCredential()`, and `--probe` reads it off the response.
+ */
+ signer?: string;
}
export interface CredentialProvider {
diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts
index 0774135b..7d1eac35 100644
--- a/packages/cli/src/cli.ts
+++ b/packages/cli/src/cli.ts
@@ -1585,12 +1585,18 @@ async function probeModelRouting(
/**
* The Muse Code credential as a provenance record, through `effectiveLabel`
- * (the channel for a credential that is not an env var). Present:
- * `Key Muse Code borrowed copy · Muse Code Power Usage (signed the probe request)`.
- * Absent: `Key no Muse Code login (<the §4.2 login instruction>)`.
+ * (the channel for a credential that is not an env var). `probe` is THIS
+ * hop's own result: read after the request, its `signedWith` names the login
+ * that signed it. Lines (`describeMuseSigningSource`):
+ * `Key Muse Code borrowed copy · Muse Code Power Usage (signed this probe request)`,
+ * `Key Muse Code login rejected (Meta rejected the Muse Code login (HTTP 401): …)`,
+ * `Key no claudish Muse Code login (this process reads login files only, …)`.
*/
- function museKeyProvenance(): KeyProvenance {
- const muse = describeMuseSigningSource();
+ function museKeyProvenance(probe?: ProbeResult): KeyProvenance {
+ const muse = describeMuseSigningSource({
+ ...(probe?.signedWith ? { signedWith: probe.signedWith } : {}),
+ probed: probe !== undefined,
+ });
return {
envVar: "",
hasValue: muse.present,
@@ -1601,6 +1607,18 @@ async function probeModelRouting(
};
}
+ /**
+ * The chain's provenance was read BEFORE the live requests. A muse@ hop's is
+ * read again AFTER them, from that hop's own probe result, so its Key line
+ * names the login that signed THAT request (or that it was rejected). Both
+ * the `--json` and the TUI/printer paths call this once their probes settle.
+ */
+ function refreshMuseProvenance(chain: ProbeChainLink[]): void {
+ for (const link of chain) {
+ if (link.provider === "meta-muse-code") link.provenance = museKeyProvenance(link.probe);
+ }
+ }
+
/**
* The remedy a credential-less row shows.
*
@@ -1851,6 +1869,7 @@ async function probeModelRouting(
link.probe = probes[i];
});
}
+ refreshMuseProvenance(probe.chain);
const wiring = await computeWiring(probe.chain, probe.explanation.routedModel);
results.push(chainProbeOf(probe, wiring));
@@ -2040,12 +2059,7 @@ async function probeModelRouting(
const printable: PrintableModelResult[] = [];
const results: ProbeModelResult[] = [];
for (const probe of modelProbes) {
- // The chain's provenance was read BEFORE the live requests. A muse@ hop's
- // is read again now, so its Key line names the source and tier the
- // probe request actually signed with (the proxy is in this process).
- for (const link of probe.chain) {
- if (link.provider === "meta-muse-code") link.provenance = museKeyProvenance();
- }
+ refreshMuseProvenance(probe.chain);
const wiring = await computeWiring(probe.chain, probe.explanation.routedModel);
const fields = routingFieldsFrom(probe.explanation);
printable.push({
diff --git a/packages/cli/src/handlers/composed-handler.ts b/packages/cli/src/handlers/composed-handler.ts
index 3a68355d..76e16d0f 100644
--- a/packages/cli/src/handlers/composed-handler.ts
+++ b/packages/cli/src/handlers/composed-handler.ts
@@ -2424,8 +2424,9 @@ export class ComposedHandler implements ModelHandler {
// ones, which is the bug being fixed. Claudish's own internal callers
// (mcp-server.ts:235, probe-live.ts:139) both send `stream: true`
// explicitly, so this changes nothing for them.
- if (payload?.stream === true) return streamed;
- return sseResponseToJson(streamed, this.bareModelName);
+ const signed = withSignerHeader(streamed, this.provider.signingCredential?.());
+ if (payload?.stream === true) return signed;
+ return sseResponseToJson(signed, this.bareModelName);
}
/**
@@ -2943,6 +2944,34 @@ export class ComposedHandler implements ModelHandler {
* Nothing is inferred from the credential itself — see the branch for why the
* key's own bytes are deliberately not read.
*/
+/**
+ * Name the credential that signed THIS request on its response, as
+ * `x-claudish-signed-with` (URI-encoded: a tier name need not be a valid
+ * header byte string), for a provider with several login sources (muse@: own
+ * login, borrowed copy, Keychain). Per response, so `--probe` names the signer
+ * of its own request and never a process-wide guess.
+ *
+ * Set on the returned Response, not through `c.header()`: the Responses stream
+ * parser builds its own `new Response`, which never sees the context's headers.
+ * Headers a stream parser built are mutable; a frozen set is copied instead.
+ */
+function withSignerHeader(response: Response, signer: string | undefined): Response {
+ if (!signer) return response;
+ const value = encodeURIComponent(signer);
+ try {
+ response.headers.set("x-claudish-signed-with", value);
+ return response;
+ } catch {
+ const headers = new Headers(response.headers);
+ headers.set("x-claudish-signed-with", value);
+ return new Response(response.body, {
+ status: response.status,
+ statusText: response.statusText,
+ headers,
+ });
+ }
+}
+
export function getRecoveryHint(
status: number,
errorText: string,
diff --git a/packages/cli/src/providers/meta-muse/muse-credentials.ts b/packages/cli/src/providers/meta-muse/muse-credentials.ts
index 90a1b92a..2170a4b6 100644
--- a/packages/cli/src/providers/meta-muse/muse-credentials.ts
+++ b/packages/cli/src/providers/meta-muse/muse-credentials.ts
@@ -114,6 +114,12 @@ let generation = 0;
const deadKeys = new Set<string>();
let inFlightResolve: Promise<MuseState> | null = null;
let lastFailure: string | undefined;
+/**
+ * The rejected-login message of the last resolve, when every login file it
+ * tried was rejected by Meta; cleared by a confirmed mint or a reset. Read by
+ * `--probe` after its request (`describeMuseSigningSource`).
+ */
+let lastRejection: string | undefined;
/**
* The invalidation epoch. A reset (login, logout, `credentials.invalidate`)
* bumps it; a resolve that started in an older epoch may finish, but it never
@@ -139,6 +145,7 @@ export function resetMuseCredentialState(): void {
deadKeys.clear();
inFlightResolve = null;
lastFailure = undefined;
+ lastRejection = undefined;
}
/** The installed state, if any. Never contains a secret that was not confirmed. */
@@ -182,6 +189,7 @@ function install(
generation: ++generation,
};
lastFailure = undefined;
+ lastRejection = undefined;
// A mint that confirmed this key revives it: the service may hand back the
// key it just rejected, and a dead mark on it would re-mint every request.
deadKeys.delete(mint.apiKey);
@@ -220,6 +228,8 @@ async function tryFileSource(
}
async function resolveFromSources(prompt: boolean, startEpoch: number): Promise<MuseState> {
+ // Each resolve states its own outcome; an older rejection must not outlive it.
+ if (startEpoch === epoch) lastRejection = undefined;
const rejections: number[] = [];
const own = await tryFileSource("claudish-login", startEpoch, rejections);
if (own) return own;
@@ -271,7 +281,9 @@ async function resolveFromSources(prompt: boolean, startEpoch: number): Promise<
// `never` one blames the team slot / MCP session, which a `-p` run is not.
// The files are kept either way.
if (rejections.length > 0) {
- throw new MuseCredentialError(museLoginRejectedMessage(rejections[0]));
+ const message = museLoginRejectedMessage(rejections[0]);
+ if (startEpoch === epoch) lastRejection = message;
+ throw new MuseCredentialError(message);
}
if (role === "never") throw new MuseCredentialError(MUSE_NON_INTERACTIVE_MESSAGE);
throw new MuseCredentialError(MUSE_NO_LOGIN_MESSAGE);
@@ -436,11 +448,21 @@ const SOURCE_LABELS: Record<MuseSource, string> = {
keychain: "Muse Code CLI Keychain login",
};
+/**
+ * The display name of the credential a state signs with:
+ * `Muse Code <source> · <tier>`. Display-safe (no token), so it travels with
+ * the request's artifact (`RequestAuth.signer`) and back to `--probe` on the
+ * response; see {@link describeMuseSigningSource}.
+ */
+export function museSignerLabel(signer: Pick<MuseState, "source" | "subsTierName">): string {
+ return `Muse Code ${SOURCE_LABELS[signer.source]} · ${signer.subsTierName ?? "tier unknown"}`;
+}
+
/** What `--probe`'s Key line says about the Muse Code credential. */
export interface MuseSigningDescription {
- /** False when no source is known: no state in this process and neither file. */
+ /** False when nothing can sign here: rejected, or no login this process may use. */
present: boolean;
- /** `Muse Code <source> · <tier>`, or `no Muse Code login`. */
+ /** `Muse Code <source> · <tier>`, `Muse Code login rejected`, or the no-login label. */
label: string;
/** Where that came from: the request that signed, the file, or the remedy. */
detail: string;
@@ -452,23 +474,34 @@ function displayPath(path: string): string {
}
/**
- * The source and tier a muse@ request signs (or would sign) with, for
- * `--probe` (contract §4.3 item 5 / R2-F28: a silent switch between the own
- * login and a borrowed one must be visible).
+ * What `--probe` says about a muse@ hop's credential (contract §4.3 item 5 /
+ * R2-F28: a silent switch between the own login and a borrowed one must be
+ * visible). Read AFTER the probe request, and in this order:
+ *
+ * 1. `signedWith` — the signer THIS probe request's response named
+ * (`x-claudish-signed-with`). Per request, so concurrent probes in one
+ * process cannot borrow each other's answer.
+ * 2. A probe that ran and was refused because every login file was rejected
+ * by Meta: `Muse Code login rejected`, with the rejection message.
+ * 3. The files, in the order the resolve tries them, with the tier the
+ * confirming mint wrote: what a request WOULD sign with (no probe sent, or
+ * it failed for another reason).
+ * 4. No file: worded for the role. A `never` process (team slot, MCP, `-p`,
+ * `--probe`) reads files only, so a Muse Code CLI Keychain login may exist
+ * but cannot be used here, and the line says so. In a role that may read
+ * the Keychain, an item the attribute-only presence memo already saw is
+ * reported present.
*
- * Files and process state ONLY — never a Keychain read of any kind, so it is
- * safe in role `never`. The installed state wins: it is the source and tier
- * the last request in THIS process actually signed with (the probe's own proxy
- * runs in-process). Without one, the files are read in the order the resolve
- * tries them, and the tier is the `subs_tier_name` the confirming mint wrote.
+ * Files and memos ONLY: never a Keychain question of any kind.
*/
-export function describeMuseSigningSource(): MuseSigningDescription {
- if (state) {
- return {
- present: true,
- label: `Muse Code ${SOURCE_LABELS[state.source]} · ${state.subsTierName ?? "tier unknown"}`,
- detail: "signed the probe request",
- };
+export function describeMuseSigningSource(
+ opts: { signedWith?: string; probed?: boolean } = {}
+): MuseSigningDescription {
+ if (opts.signedWith) {
+ return { present: true, label: opts.signedWith, detail: "signed this probe request" };
+ }
+ if (opts.probed && lastRejection) {
+ return { present: false, label: "Muse Code login rejected", detail: lastRejection };
}
for (const [kind, source] of [
["own-login", "claudish-login"],
@@ -477,10 +510,29 @@ export function describeMuseSigningSource(): MuseSigningDescription {
const record = deps.readStore(kind, deps.dir());
if (!record) continue;
const tier = typeof record.subs_tier_name === "string" ? record.subs_tier_name : undefined;
+ const path = displayPath(museStorePath(kind, deps.dir()));
+ return {
+ present: true,
+ label: museSignerLabel({ source, subsTierName: tier }),
+ detail: opts.probed
+ ? `${path}; the probe request did not confirm it`
+ : `${path}, not yet confirmed in this process`,
+ };
+ }
+ if (credentialPromptRole() === "never") {
+ return {
+ present: false,
+ label: "no claudish Muse Code login",
+ detail:
+ "this process reads login files only, so a Muse Code CLI Keychain login cannot be used here: " +
+ "run `claudish login muse`, or one interactive `claudish --model muse@<model>` and allow Keychain access",
+ };
+ }
+ if (museKeychainPresenceCached() === "present") {
return {
present: true,
- label: `Muse Code ${SOURCE_LABELS[source]} · ${tier ?? "tier unknown"}`,
- detail: `${displayPath(museStorePath(kind, deps.dir()))}, not yet confirmed in this process`,
+ label: museSignerLabel({ source: "keychain" }),
+ detail: "in the macOS Keychain; read on first use, after you allow access",
};
}
return { present: false, label: "no Muse Code login", detail: MUSE_NO_LOGIN_MESSAGE };
diff --git a/packages/cli/src/providers/probe-live.ts b/packages/cli/src/providers/probe-live.ts
index 978c42de..852eed42 100644
--- a/packages/cli/src/providers/probe-live.ts
+++ b/packages/cli/src/providers/probe-live.ts
@@ -53,6 +53,12 @@ export interface ProbeResult {
* streaming = latencyMs - ttftMs (token generation)
*/
timing?: ProbeTiming;
+ /**
+ * The credential that signed THIS probe request, when the provider has
+ * several login sources (muse@): `Muse Code borrowed copy · <tier>`. Read off
+ * the response's `x-claudish-signed-with`, so it is per request.
+ */
+ signedWith?: string;
}
/**
@@ -301,12 +307,24 @@ export async function probeLink(
...rest,
latencyMs: totalMs,
timing,
+ ...signedWithOf(response),
},
link.provider,
isOAuth
);
}
+/** The `x-claudish-signed-with` the proxy set on this response (ComposedHandler). */
+function signedWithOf(response: Response): { signedWith?: string } {
+ const raw = response.headers.get("x-claudish-signed-with");
+ if (!raw) return {};
+ try {
+ return { signedWith: decodeURIComponent(raw) };
+ } catch {
+ return {};
+ }
+}
+
/**
* Attach a login hint when an OAuth provider failed authentication. The
* `gemini` / `vertex` transports authenticate via cached tokens, so a 401 or
diff --git a/packages/cli/src/providers/transport/meta-muse-code.ts b/packages/cli/src/providers/transport/meta-muse-code.ts
index db6f200a..dbf11195 100644
--- a/packages/cli/src/providers/transport/meta-muse-code.ts
+++ b/packages/cli/src/providers/transport/meta-muse-code.ts
@@ -71,6 +71,11 @@ export class MuseCodeTransport extends OpenAIProviderTransport {
this.auth = await credentials.getRequestAuth("meta-muse-code", { model: this.modelName });
}
+ /** The source and tier of the login whose key signed the last request. */
+ signingCredential(): string | undefined {
+ return this.auth?.signer;
+ }
+
getContextWindow(): number {
return this.window;
}
diff --git a/packages/cli/src/providers/transport/types.ts b/packages/cli/src/providers/transport/types.ts
index 47a89779..a00517a9 100644
--- a/packages/cli/src/providers/transport/types.ts
+++ b/packages/cli/src/providers/transport/types.ts
@@ -116,6 +116,14 @@ export interface ProviderTransport {
*/
forceRefreshAuth?(ctx?: { rejectedHeaders?: Record<string, string> }): Promise<void>;
+ /**
+ * Optional: a display-safe name of the credential that signed the request
+ * just sent (`RequestAuth.signer`), for a provider with several login
+ * sources. ComposedHandler returns it on a successful response as
+ * `x-claudish-signed-with` (URI-encoded), which `--probe` reads per request.
+ */
+ signingCredential?(): string | undefined;
+
/**
* Optional per-provider verdict on whether an error response is TERMINAL
* (won't recover on retry) — the transport's own reading of its provider's