Skip to content

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

fix(team)!: run `team run` as panes when --grid is not given

Jack Rudenko3a356804b3a7
diff --git a/packages/cli/src/team-cli-run-mode.test.ts b/packages/cli/src/team-cli-run-mode.test.ts
new file mode 100644
index 00000000..00b12aef
--- /dev/null
+++ b/packages/cli/src/team-cli-run-mode.test.ts
@@ -0,0 +1,164 @@
+/**
+ * CLI team mode/input regressions through the real entry, with the signal test's
+ * hermetic pane environment and fake interactive child. No real model is called.
+ */
+
+import { afterEach, beforeEach, describe, expect, it } from "bun:test";
+import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
+import { join } from "node:path";
+import { setupSession } from "./team-orchestrator.js";
+import {
+ MAGMUX,
+ NO_MAGMUX_MESSAGE,
+ type PaneTestEnv,
+ finishPaneTest,
+ makePaneTestEnv,
+} from "./test-helpers/team-pane.js";
+
+if (!MAGMUX) console.warn(NO_MAGMUX_MESSAGE);
+
+const ENTRY = join(import.meta.dir, "index.ts");
+const TASK = Buffer.from("Review the team CLI mode and input handling.\n", "utf8");
+
+let t: PaneTestEnv;
+
+beforeEach(() => {
+ t = makePaneTestEnv({ CONTRACT_FAKE_MAX_MS: "60000" });
+});
+
+afterEach(async () => {
+ const report = await finishPaneTest(t);
+ expect(report).toEqual({ processes: [], files: [] });
+});
+
+async function runCli(cwd: string, sessionPath: string, extraArgs: string[] = []) {
+ // Grid commands invoke `claudish` by name rather than CLAUDISH_BIN. Keep that
+ // path hermetic too: forward it to the same fake child used by the pane path.
+ const binDir = join(t.tmp, "bin");
+ mkdirSync(binDir, { recursive: true });
+ writeFileSync(
+ join(binDir, "claudish"),
+ `#!${process.execPath}
+const fake = process.env.CLAUDISH_BIN;
+if (!fake) process.exit(70);
+const proc = Bun.spawn([fake, ...process.argv.slice(2)], {
+ env: process.env, stdin: "inherit", stdout: "inherit", stderr: "inherit",
+});
+process.exit(await proc.exited);
+`,
+ { mode: 0o755 }
+ );
+
+ const proc = Bun.spawn(
+ [
+ process.execPath,
+ ENTRY,
+ "team",
+ "run",
+ "--path",
+ sessionPath,
+ "--models",
+ "contract-fake-a",
+ // Bound only the defective grid path; pane mode does not use this timeout.
+ "--timeout",
+ "1",
+ ...extraArgs,
+ ],
+ {
+ cwd,
+ env: { ...t.env, PATH: `${binDir}:${t.env.PATH ?? ""}` },
+ stdin: "ignore",
+ stdout: "pipe",
+ stderr: "pipe",
+ }
+ );
+ const stdout = new Response(proc.stdout).text();
+ const stderr = new Response(proc.stderr).text();
+ let timer: ReturnType<typeof setTimeout> | undefined;
+
+ try {
+ const code = await Promise.race([
+ proc.exited,
+ new Promise<never>((_, reject) => {
+ timer = setTimeout(() => reject(new Error("team run did not exit within 30 s")), 30_000);
+ }),
+ ]);
+ return { code, stdout: await stdout, stderr: await stderr };
+ } finally {
+ if (timer !== undefined) clearTimeout(timer);
+ if (proc.exitCode === null) proc.kill("SIGKILL");
+ await proc.exited;
+ }
+}
+
+describe.skipIf(!MAGMUX)("claudish team run — mode and existing input", () => {
+ it("bare run uses panes and preserves input.md byte for byte", async () => {
+ // REGRESSION: claudish team run without --grid ran the grid and emptied input.md — Fixed in /dev:fix session dev-fix-20261016-224933-5e5cb5a4
+ // validateSessionPath requires the session under the CLI's cwd.
+ const cwd = join(t.tmp, "work");
+ const sessionPath = join(cwd, "review");
+ mkdirSync(sessionPath, { recursive: true });
+ writeFileSync(join(sessionPath, "input.md"), TASK);
+
+ await runCli(cwd, sessionPath);
+
+ const status = JSON.parse(readFileSync(join(sessionPath, "status.json"), "utf8")) as {
+ models: Record<string, { pane?: unknown }>;
+ };
+ const rows = Object.values(status.models);
+ expect(rows).toHaveLength(1);
+ expect({
+ gridfileExists: existsSync(join(sessionPath, "gridfile.txt")),
+ pane: rows[0]?.pane ?? null,
+ inputBytes: readFileSync(join(sessionPath, "input.md")).toString("hex"),
+ }).toEqual({
+ gridfileExists: false,
+ pane: expect.anything(),
+ inputBytes: TASK.toString("hex"),
+ });
+ }, 60_000);
+
+ it("refuses an unknown mode with exit 2 before writing session files", async () => {
+ // REGRESSION: claudish team run without --grid ran the grid and emptied input.md — Fixed in /dev:fix session dev-fix-20261016-224933-5e5cb5a4
+ const cwd = join(t.tmp, "work");
+ mkdirSync(cwd, { recursive: true });
+ const sessionPath = join(cwd, "review");
+
+ const result = await runCli(cwd, sessionPath, ["--mode", "bogus"]);
+ const errorOutput = `${result.stderr}\n${result.stdout}`;
+
+ expect({
+ code: result.code,
+ namesDefault: /\bdefault\b/.test(errorOutput),
+ namesInteractive: /\binteractive\b/.test(errorOutput),
+ namesJson: /\bjson\b/.test(errorOutput),
+ manifestExists: existsSync(join(sessionPath, "manifest.json")),
+ statusExists: existsSync(join(sessionPath, "status.json")),
+ }).toEqual({
+ code: 2,
+ namesDefault: true,
+ namesInteractive: true,
+ namesJson: true,
+ manifestExists: false,
+ statusExists: false,
+ });
+ }, 60_000);
+});
+
+it("setupSession keeps absent input; explicit empty input documents the grid call-site hazard", () => {
+ // REGRESSION: claudish team run without --grid ran the grid and emptied input.md — Fixed in /dev:fix session dev-fix-20261016-224933-5e5cb5a4
+ const absentPath = join(t.tmp, "absent-input");
+ const emptyPath = join(t.tmp, "empty-input");
+ for (const sessionPath of [absentPath, emptyPath]) {
+ mkdirSync(sessionPath, { recursive: true });
+ writeFileSync(join(sessionPath, "input.md"), TASK);
+ }
+
+ setupSession(absentPath, ["contract-fake-a"], undefined);
+ expect(readFileSync(join(absentPath, "input.md"))).toEqual(TASK);
+
+ // Documents the call-site hazard, not desired absent-input behaviour: today's
+ // grid caller passes input ?? "", which explicitly replaces the existing task.
+ setupSession(emptyPath, ["contract-fake-a"], "");
+ expect(readFileSync(join(emptyPath, "input.md"))).toEqual(Buffer.alloc(0));
+});
diff --git a/packages/cli/src/team-cli.ts b/packages/cli/src/team-cli.ts
index 6807432e..3080b32e 100644
--- a/packages/cli/src/team-cli.ts
+++ b/packages/cli/src/team-cli.ts
@@ -14,8 +14,9 @@ import {
} from "./team-orchestrator.js";
/**
- * `claudish team run|run-and-judge` (json mode) runs every slot as an interactive pane,
- * like the MCP `team` tool (they share `runModels`). The refusals come first, before
+ * `claudish team run|run-and-judge` (json mode, the default) runs every slot as an
+ * interactive pane, like the MCP `team` tool (they share `runModels`); only `run --grid`
+ * (or `--mode default` / `--interactive`) takes the magmux grid. The refusals come first, before
* the session directory is written: a bad flag exits 2, a missing magmux or a full pane
* limit exits 1. Ctrl-C (and SIGTERM / SIGHUP) reaps every pane in ≤ 3 s, then exits
* 128 + the signal number — 130 for Ctrl-C.
@@ -89,6 +90,8 @@ Options (run / run-and-judge):
json mode runs each model as an interactive pane in a headless
magmux (>= 0.14.0; darwin and linux).
--grid Show all models in a magmux grid with live output + status bar
+ --mode <m> run only: json (default, panes), default (the grid, as --grid)
+ or interactive (as --interactive)
Options (judge / run-and-judge):
--judges <a,b,...> Comma-separated judge model IDs (default: same as runners)
@@ -133,7 +136,14 @@ export async function teamCommand(args: string[]): Promise<void> {
}
const modelsRaw = getFlag(args, "--models");
const judgesRaw = getFlag(args, "--judges");
- const mode = (getFlag(args, "--mode") ?? "default") as "default" | "interactive" | "json";
+ // A bare `team run` runs panes (json); `default` is the magmux grid. An unknown value
+ // exits 2 before anything is written, rather than silently picking a mode.
+ const modeRaw = getFlag(args, "--mode") ?? "json";
+ if (modeRaw !== "default" && modeRaw !== "interactive" && modeRaw !== "json") {
+ console.error(`Error: invalid --mode "${modeRaw}" (expected default, interactive or json)`);
+ process.exit(2);
+ }
+ const mode: "default" | "interactive" | "json" = modeRaw;
const timeoutStr = getFlag(args, "--timeout");
const timeout = timeoutStr ? Number.parseInt(timeoutStr, 10) : 300;