Skip to content

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

fix(mcp): end a panel command's admission without a turn after Esc

Jack Rudenko581042fa2906
diff --git a/packages/cli/src/pane/pane-session.integration.test.ts b/packages/cli/src/pane/pane-session.integration.test.ts
index 1b1bd38e..a0e67b9b 100644
--- a/packages/cli/src/pane/pane-session.integration.test.ts
+++ b/packages/cli/src/pane/pane-session.integration.test.ts
@@ -429,6 +429,34 @@ describe.skipIf(!MAGMUX)(
);
});
+ describe.concurrent("panel commands", () => {
+ test(
+ "/cost opens a panel that writes no record: Esc at once, no turn, the next prompt is not held",
+ async () => {
+ const r = await start("answer", {
+ shape: "interactive",
+ initialPrompt: undefined,
+ decide: () => "continue",
+ });
+ await r.s.ready;
+ const at = Date.now();
+ expect(r.s.send("/cost").ok).toBe(true);
+ expect(r.s.send("Reply with exactly KIWI.").ok).toBe(true);
+ const s = await until(r, (x) => x.turnsCompleted === 1 && x.state === "AWAITING_INPUT");
+ expect(Date.now() - at).toBeLessThan(10_000); // well inside the 30 s admission bound
+ expect(s.anomalies).toContain("panel_dismissed");
+ expect(s.anomalies).toContain("panel_command");
+ expect(s.anomalies).not.toContain("send_not_accepted");
+ expect(r.turns.map((t) => t.answer)).toEqual([
+ `ANSWER fake-answer ${sha8("Reply with exactly KIWI.")}`,
+ ]);
+ r.s.cancel();
+ await finish(r);
+ },
+ T
+ );
+ });
+
describe.concurrent("blocked, interrupts and permission", () => {
test(
"ask_user (team): FAILED blocked with the question text, in one net transition",
diff --git a/packages/cli/src/pane/pane-session.ts b/packages/cli/src/pane/pane-session.ts
index 95e5f37b..c7204bc9 100644
--- a/packages/cli/src/pane/pane-session.ts
+++ b/packages/cli/src/pane/pane-session.ts
@@ -114,6 +114,8 @@ export const RESEND_AFTER_MS = 10_000;
export const DEGRADED_ENTRY_MS = 10_000;
/** Degraded settle: no change above the box for 2 × this. */
export const SCREEN_SETTLE_QUIET_MS = 3_000;
+/** A panel command's screen must have been up this long after delivery before Esc. */
+const PANEL_SETTLE_MS = 500;
/** The REPL box must read empty this long before boot is ready. */
const REPL_STABLE_MS = 500;
/** A dialog or choice screen static this long blocks boot. */
@@ -910,6 +912,7 @@ export class PaneSessionImpl implements PaneSession, RegisteredPane {
}
const now = Date.now();
const since = adm.deliveredAt ? now - adm.deliveredAt : 0;
+ if (adm.deliveredAt && adm.plan.mode === "command" && this.panelCommand(adm, since)) return;
if (adm.deliveredAt && since >= this.t("resendAfterMs", RESEND_AFTER_MS)) this.nudge(adm);
if (
adm.deliveredAt &&
@@ -920,6 +923,42 @@ export class PaneSessionImpl implements PaneSession, RegisteredPane {
if (now - adm.startedAt >= (this.o.admitTimeoutMs ?? ADMIT_TIMEOUT_MS)) this.admitExpired(adm);
}
+ /** A full-screen panel: no input box, no choice dialog, and its `Esc to cancel` footer. */
+ private panelOpen(): boolean {
+ return (
+ !inputBox(this.screen) &&
+ !hasChoiceDialog(this.screen) &&
+ /Esc to cancel/.test(screenText(this.screen))
+ );
+ }
+
+ /**
+ * A delivered panel command (`/cost`, `/usage`, `/config`, …) writes no transcript record
+ * and swallows input until Esc (phase2-captures §3, §10), so it can never be witnessed.
+ * Once it is on screen it is dismissed at once, and when the empty box is back the
+ * admission ends without a turn: a later prompt is not held for the 30 s admission bound.
+ * True when this step handled the admission.
+ */
+ private panelCommand(adm: Admission, since: number): boolean {
+ if (!adm.panelEscaped) {
+ if (since < PANEL_SETTLE_MS || !this.panelOpen()) return false;
+ adm.panelEscaped = true;
+ this.anomaly("panel_dismissed");
+ void this.key("escape");
+ return true;
+ }
+ const box = inputBox(this.screen);
+ if (!box || box.text !== "" || this.panelOpen()) return false;
+ this.admission = null;
+ this.anomaly("panel_command");
+ if (adm.initial)
+ this.fire("admit_deadline", {
+ detail: `${adm.text.trim()} opened a panel and wrote no transcript record`,
+ });
+ else this.fire("admit_abandoned");
+ return true;
+ }
+
/** +10 s without a witness: the line still in the box → Enter again; a panel → Esc. */
private nudge(adm: Admission): void {
const box = inputBox(this.screen);