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 <noreply@anthropic.com>
This commit is contained in:
A 2026-02-18 12:24:37 -08:00 committed by GitHub
parent 7e2a7bca1e
commit 3a0ce830e5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 46 additions and 6 deletions

View file

@ -1,6 +1,6 @@
{
"name": "@openrouter/spawn",
"version": "0.5.3",
"version": "0.5.4",
"type": "module",
"bin": {
"spawn": "cli.js"

View file

@ -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);
});
});

View file

@ -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", () => {

View file

@ -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<void> {
// 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;
}