Skip to content

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

fix(mcp): accept a system/local_command record as a command witness

Jack Rudenko9e79bc8d7e39
diff --git a/packages/cli/src/pane/pane-session.integration.test.ts b/packages/cli/src/pane/pane-session.integration.test.ts
index a2f1c184..1b1bd38e 100644
--- a/packages/cli/src/pane/pane-session.integration.test.ts
+++ b/packages/cli/src/pane/pane-session.integration.test.ts
@@ -408,9 +408,11 @@ describe.skipIf(!MAGMUX)(
await r.s.ready;
expect(r.s.send("/compact").ok).toBe(true);
expect(r.s.send("/model haiku").ok).toBe(true);
+ expect(r.s.send("/color yellow").ok).toBe(true);
expect(r.s.send("Reply with exactly KIWI.").ok).toBe(true);
- await until(r, (s) => s.turnsCompleted === 3 && s.state === "AWAITING_INPUT");
+ await until(r, (s) => s.turnsCompleted === 4 && s.state === "AWAITING_INPUT");
expect(r.turns.map((t) => t.settledBy)).toEqual([
+ "local_command",
"local_command",
"local_command",
"turn_duration",
@@ -418,7 +420,8 @@ describe.skipIf(!MAGMUX)(
expect(r.turns[0]?.answer).toBe("Compacted (ctrl+o to see full summary)");
expect(r.turns[0]?.delivery.mode).toBe("command");
expect(r.turns[1]?.answer).toBe("Set model to `haiku`");
- expect(r.turns[2]?.answer).toBe(`ANSWER fake-answer ${sha8("Reply with exactly KIWI.")}`);
+ expect(r.turns[2]?.answer).toBe("Session color set to: yellow");
+ expect(r.turns[3]?.answer).toBe(`ANSWER fake-answer ${sha8("Reply with exactly KIWI.")}`);
r.s.cancel();
await finish(r);
},
diff --git a/packages/cli/src/pane/test-helpers/fake-interactive-child.ts b/packages/cli/src/pane/test-helpers/fake-interactive-child.ts
index a3293733..84025dd2 100755
--- a/packages/cli/src/pane/test-helpers/fake-interactive-child.ts
+++ b/packages/cli/src/pane/test-helpers/fake-interactive-child.ts
@@ -714,7 +714,7 @@ async function screenOnlyTurn(line: string): Promise<void> {
}
/** Local commands the fake runs the way 2.1.291 does: their own records, no model turn. */
-const LOCAL_COMMANDS = new Set(["compact", "model"]);
+const LOCAL_COMMANDS = new Set(["compact", "model", "color"]);
async function localCommandTurn(name: string, args: string): Promise<void> {
S.history.push(`❯ /${name}${args ? ` ${args}` : ""}`);
@@ -730,7 +730,8 @@ async function localCommandTurn(name: string, args: string): Promise<void> {
stdout = "\u001b[2mCompacted (ctrl+o to see full summary)\u001b[22m";
}
S.working = null;
- rec.localCommand(name, args, stdout);
+ if (name === "color") stdout = `Session color set to: ${args}`;
+ rec.localCommand(name, args, stdout, name === "color" ? "system" : "user");
// biome-ignore lint/suspicious/noControlCharactersInRegex: the ANSI the stdout carries
showHistory(` ⎿ ${stdout.replace(/\x1b\[[0-9;]*m/g, "")}`);
}
diff --git a/packages/cli/src/pane/transcript-follower.test.ts b/packages/cli/src/pane/transcript-follower.test.ts
index 742cf1e6..ce00365a 100644
--- a/packages/cli/src/pane/transcript-follower.test.ts
+++ b/packages/cli/src/pane/transcript-follower.test.ts
@@ -657,6 +657,18 @@ describe("local commands", () => {
expect(cur(v2[0]).localCommandOutput).toBe("Compacted (ctrl+o to see full summary)");
});
+ test("/color (2.1.291): the witness and the stdout are system/local_command records", () => {
+ const n = "local-commands";
+ const recs = transcriptRecords(n);
+ const at = recs.findIndex((r) => r.subtype === "local_command");
+ expect(recs[at]?.type).toBe("system");
+ const { views } = run(n, [{ at, witness: { kind: "command", name: "color" } }], {
+ upTo: at + 2,
+ });
+ expect(cur(views[0]).acceptedAt).toBe(recs[at]!.timestamp);
+ expect(cur(views[0]).localCommandOutput).toBe("Session color set to: yellow");
+ });
+
test("a prompt command (/pear) carries no local output: it settles on its assistant turn", () => {
const n = "slash-and-reads";
const at = transcriptRecords(n).findIndex((r) => textOf(r).includes("<command-name>/pear"));
diff --git a/packages/cli/src/pane/transcript-follower.ts b/packages/cli/src/pane/transcript-follower.ts
index 059b37cd..67fb9596 100644
--- a/packages/cli/src/pane/transcript-follower.ts
+++ b/packages/cli/src/pane/transcript-follower.ts
@@ -230,7 +230,16 @@ function taskIdOf(text: string): string | null {
return m ? (m[1] ?? "").trim() : null;
}
+/** A `system/local_command` record (2.1.287+ `/color`): the command line or its stdout. */
+function isLocalCommandSystem(r: Rec): boolean {
+ return r.type === "system" && r.subtype === "local_command" && !r.isSidechain;
+}
+
function matchesWitness(r: Rec, w: Witness): boolean {
+ // Some local commands are written as system records, not user records (captured:
+ // 2.1.291 `/color yellow` → two `system/local_command` records).
+ if (w.kind === "command" && isLocalCommandSystem(r))
+ return String(r.content ?? "").includes(`<command-name>/${w.name}</command-name>`);
if (!isMainUser(r) || hasToolResult(r)) return false;
const text = userText(r);
if (w.kind === "text") return !r.isMeta && text.trim() === w.text.trim();
@@ -500,6 +509,7 @@ export function applyRecord(
if (r.type === "assistant") applyAssistant(state, t, r, offset);
else if (r.type === "user") applyUser(t, r, offset);
+ else if (isLocalCommandSystem(r)) applyLocalCommandRecord(t, String(r.content ?? ""), offset);
else if (r.type === "system" && r.subtype === "stop_hook_summary") {
if (t.lastAssistant) t.stopHookAfterLast = true;
} else if (r.type === "system" && r.subtype === "turn_duration") applyTurnDuration(state, t, r);