From 3a0ce830e5398868ed2de32182fb22c9ff11d0d8 Mon Sep 17 00:00:00 2001 From: A <258483684+la14-1@users.noreply.github.com> Date: Wed, 18 Feb 2026 12:24:37 -0800 Subject: [PATCH] fix: resolve unknown --default flag in CLI picker (#1449) Add --default to KNOWN_FLAGS so it is recognized even if the `spawn pick` early-return path is bypassed (e.g. due to Bun kqueue/TTY errors on certain platforms). Also wrap cmdPick in a try/catch so TTY errors produce a clean error message instead of an unhandled rejection. Sync test copies of KNOWN_FLAGS that had drifted: unknown-flags.test.ts was missing --debug, --headless, --output, --clear, -a, -c, --agent, --cloud; index-dispatch-routing.test.ts had the same gaps. Fix an incorrect test that expected --output to be flagged as unknown (it has been a known flag since --headless/--output were added). Fixes #1447 Agent: code-health Co-authored-by: B <6723574+louisgv@users.noreply.github.com> Co-authored-by: Claude Sonnet 4.5 --- cli/package.json | 2 +- .../__tests__/index-dispatch-routing.test.ts | 14 ++++++++-- cli/src/__tests__/unknown-flags.test.ts | 26 +++++++++++++++++-- cli/src/index.ts | 10 ++++++- 4 files changed, 46 insertions(+), 6 deletions(-) diff --git a/cli/package.json b/cli/package.json index c7768ff2..f15c9cfa 100644 --- a/cli/package.json +++ b/cli/package.json @@ -1,6 +1,6 @@ { "name": "@openrouter/spawn", - "version": "0.5.3", + "version": "0.5.4", "type": "module", "bin": { "spawn": "cli.js" diff --git a/cli/src/__tests__/index-dispatch-routing.test.ts b/cli/src/__tests__/index-dispatch-routing.test.ts index 954696e2..14a7fcd1 100644 --- a/cli/src/__tests__/index-dispatch-routing.test.ts +++ b/cli/src/__tests__/index-dispatch-routing.test.ts @@ -200,7 +200,12 @@ const KNOWN_FLAGS = new Set([ "--version", "-v", "-V", "--prompt", "-p", "--prompt-file", "-f", "--dry-run", "-n", + "--debug", + "--headless", + "--output", + "--default", "-a", "-c", "--agent", "--cloud", + "--clear", ]); // ═════════════════════════════════════════════════════════════════════════════ @@ -974,8 +979,13 @@ describe("KNOWN_FLAGS completeness", () => { "--prompt", "-p", "--prompt-file", "-f", "--dry-run", "-n", + "--debug", + "--headless", + "--output", + "--default", "-a", "-c", "--agent", "--cloud", + "--clear", ]; for (const flag of expectedFlags) { @@ -991,8 +1001,8 @@ describe("KNOWN_FLAGS completeness", () => { expect(KNOWN_FLAGS.has("--force")).toBe(false); }); - it("should have exactly 15 known flags", () => { - expect(KNOWN_FLAGS.size).toBe(15); + it("should have exactly 20 known flags", () => { + expect(KNOWN_FLAGS.size).toBe(20); }); }); diff --git a/cli/src/__tests__/unknown-flags.test.ts b/cli/src/__tests__/unknown-flags.test.ts index d7995a01..d705965b 100644 --- a/cli/src/__tests__/unknown-flags.test.ts +++ b/cli/src/__tests__/unknown-flags.test.ts @@ -12,6 +12,12 @@ const KNOWN_FLAGS = new Set([ "--version", "-v", "-V", "--prompt", "-p", "--prompt-file", "-f", "--dry-run", "-n", + "--debug", + "--headless", + "--output", + "--default", + "-a", "-c", "--agent", "--cloud", + "--clear", ]); /** Replicated from index.ts for testability - returns the first unknown flag or null */ @@ -41,8 +47,8 @@ describe("Unknown Flag Detection", () => { expect(findUnknownFlag(["list", "-x"])).toBe("-x"); }); - it("should detect --output as unknown", () => { - expect(findUnknownFlag(["agents", "--output", "json"])).toBe("--output"); + it("should detect --force as unknown", () => { + expect(findUnknownFlag(["agents", "--force"])).toBe("--force"); }); it("should detect --verbose as unknown", () => { @@ -102,6 +108,22 @@ describe("Unknown Flag Detection", () => { it("should allow -n (short form of --dry-run)", () => { expect(findUnknownFlag(["claude", "sprite", "-n"])).toBeNull(); }); + + it("should allow --default (used by spawn pick)", () => { + expect(findUnknownFlag(["--default", "us-central1-a"])).toBeNull(); + }); + + it("should allow --output", () => { + expect(findUnknownFlag(["claude", "sprite", "--output", "json"])).toBeNull(); + }); + + it("should allow --headless", () => { + expect(findUnknownFlag(["claude", "sprite", "--headless"])).toBeNull(); + }); + + it("should allow --debug", () => { + expect(findUnknownFlag(["claude", "sprite", "--debug"])).toBeNull(); + }); }); describe("ignores positional arguments", () => { diff --git a/cli/src/index.ts b/cli/src/index.ts index 1c2e33de..50705096 100644 --- a/cli/src/index.ts +++ b/cli/src/index.ts @@ -72,6 +72,7 @@ const KNOWN_FLAGS = new Set([ "--debug", "--headless", "--output", + "--default", "-a", "-c", "--agent", "--cloud", "--clear", ]); @@ -106,6 +107,9 @@ function checkUnknownFlags(args: string[]): void { console.error(` ${pc.cyan("--help, -h")} Show help information`); console.error(` ${pc.cyan("--version, -v")} Show version`); console.error(); + console.error(` For ${pc.cyan("spawn pick")}:`); + console.error(` ${pc.cyan("--default")} Pre-selected value in the picker`); + console.error(); console.error(` For ${pc.cyan("spawn list")}:`); console.error(` ${pc.cyan("-a, --agent")} Filter history by agent`); console.error(` ${pc.cyan("-c, --cloud")} Filter history by cloud`); @@ -524,7 +528,11 @@ async function main(): Promise { // Must be handled before expandEqualsFlags / resolvePrompt so that pick's // own --prompt flag is not mistakenly consumed by the top-level prompt logic. if (rawArgs[0] === "pick") { - await cmdPick(expandEqualsFlags(rawArgs.slice(1))); + try { + await cmdPick(expandEqualsFlags(rawArgs.slice(1))); + } catch (err) { + handleError(err); + } return; }