Claude Code. Any Model. The most powerful AI coding agent now speaks every language.
fix(mcp): redact a pane's failure detail before any owner records it
Jack Rudenko83586981361b
diff --git a/packages/cli/src/channel/session-manager.test.ts b/packages/cli/src/channel/session-manager.test.tsindex fe843ee5..93f328c0 100644--- a/packages/cli/src/channel/session-manager.test.ts+++ b/packages/cli/src/channel/session-manager.test.ts@@ -696,6 +696,33 @@ describe.skipIf(!MAGMUX)(T_PANE);+ test(+ "a credential on the child's final screen reaches no record: meta.json, output.log, frame, diagnostics",+ async () => {+ const secret = "redaction-probe-not-a-real-credential"; // what the fake's exit_secret prints+ const frames: string[] = [];+ const manager = makeManager({+ onStateChange: (_sid, e) => frames.push(JSON.stringify(e)),+ });+ const id = await create(manager, { model: "fake-exit_secret", prompt: "go" });+ await waitForState(manager, id, ["FAILED"]);+ const meta = await waitForMeta(id);+ expect(meta.terminalReason).toBe("child_exited");+ expect(String(meta.detail)).toContain("MY_SERVICE_TOKEN=***REDACTED***");+ await waitUntil(() => frames.some((f) => f.includes('"failed"')));+ const outputLog = readFileSync(join(sessionsDir, id, "output.log"), "utf-8");+ for (const text of [+ JSON.stringify(meta),+ outputLog,+ frames.join("\n"),+ JSON.stringify(manager.getDiagnostics(id)),+ JSON.stringify(manager.getSession(id)),+ ])+ expect(text).not.toContain(secret);+ },+ T_PANE+ );+test("getOutput returns the answer prose, never raw records; tail_lines returns the last N",async () => {diff --git a/packages/cli/src/pane/pane-session.ts b/packages/cli/src/pane/pane-session.tsindex f8157e04..085fd4b7 100644--- a/packages/cli/src/pane/pane-session.ts+++ b/packages/cli/src/pane/pane-session.ts@@ -21,6 +21,7 @@ import type { ChildProcess } from "node:child_process";import { readFileSync, realpathSync, rmSync, statSync, writeFileSync } from "node:fs";import { join } from "node:path";import { waitForExit } from "../process-tree.js";+import { redactSecrets } from "../redact.js";import type { CaptureResult, CaptureUnchanged, FailureReason, SlotState } from "./contract.js";import { MagmuxClient, type MagmuxConnectError } from "./magmux-client.js";import {@@ -658,11 +659,14 @@ export class PaneSessionImpl implements PaneSession, RegisteredPane {}this.phase = next;const reason = info.reason ?? EVENT_REASON[ev];+ // `detail` often carries the final screen rows: redacted HERE, once, so no owner can+ // persist or forward a credential the child printed (meta.json, output.log, frames)+ const detail = info.detail === undefined ? undefined : redactSecrets(info.detail);if (isTerminalPhase(next)) {this.reason = next === "COMPLETED" ? null : (reason ?? this.reason);- if (info.detail !== undefined) this.detail = info.detail;+ if (detail !== undefined) this.detail = detail;this.onTerminal();- } else if (info.detail !== undefined) this.detail = info.detail;+ } else if (detail !== undefined) this.detail = detail;return true;}diff --git a/packages/cli/src/pane/test-helpers/fake-interactive-child.ts b/packages/cli/src/pane/test-helpers/fake-interactive-child.tsindex d78ac515..464b8734 100755--- a/packages/cli/src/pane/test-helpers/fake-interactive-child.ts+++ b/packages/cli/src/pane/test-helpers/fake-interactive-child.ts@@ -76,6 +76,8 @@ function gap(name: string, dflt: number): number {}const sleep = (ms: number) => new Promise<void>((r) => setTimeout(r, ms));+/** The value `exit_secret` prints; a redaction test greps every record for it. */+const SECRET_ON_SCREEN = "redaction-probe-not-a-real-credential";/* ───────────────────────────── fixtures ───────────────────────────── */@@ -615,6 +617,11 @@ async function runScenario(name: string, d: Delivered): Promise<void> {case "exit_mid_turn":await sleep(300);return quit(3);+ case "exit_secret":+ // a credential the child itself echoed is on screen when it dies mid-turn+ showHistory("⏺ Bash(env | grep TOKEN)", ` ⎿ MY_SERVICE_TOKEN=${SECRET_ON_SCREEN}`);+ await sleep(300);+ return quit(3);case "exit_after_settle":case "interactive_exit_after_settle":rec.text(answerFor(c));