Skip to content

Commit 4b3fd38

Browse files
fix(cli): preserve positional prompt arguments
1 parent ed2aa23 commit 4b3fd38

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

packages/cli/src/cli-args.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ export async function parseArguments(argv?: string[]): Promise<ParsedCliArgs> {
140140
});
141141

142142
const parsed = y.parseSync() as Record<string, unknown>;
143+
const queryRaw = parsed.query as string | string[] | undefined;
144+
const positionalPrompt = Array.isArray(queryRaw) ? queryRaw.join(" ") : queryRaw;
143145

144146
const resumeRaw = parsed.resume as string | undefined;
145147
let resume: ParsedCliArgs["resume"];
@@ -152,7 +154,7 @@ export async function parseArguments(argv?: string[]): Promise<ParsedCliArgs> {
152154
}
153155

154156
return {
155-
prompt: parsed.prompt as string | undefined,
157+
prompt: (parsed.prompt as string | undefined) ?? positionalPrompt,
156158
resume,
157159
version: parsed.version === true,
158160
help: parsed.help === true,

packages/cli/src/tests/cli-args.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@ test("parseArguments returns prompt after --prompt", async () => {
2828
assert.equal(r.prompt, "hello world");
2929
});
3030

31+
test("parseArguments returns prompt from positional query", async () => {
32+
const r = await parseArguments(["hello world"]);
33+
assert.ok(!("message" in r));
34+
assert.equal(r.prompt, "hello world");
35+
});
36+
37+
test("parseArguments joins multi-word positional query", async () => {
38+
const r = await parseArguments(["hello", "world"]);
39+
assert.ok(!("message" in r));
40+
assert.equal(r.prompt, "hello world");
41+
});
42+
3143
test("parseArguments returns undefined prompt when -p is not present", async () => {
3244
const r = await parseArguments(["--resume"]);
3345
assert.ok(!("message" in r));
@@ -140,6 +152,13 @@ test("parseArguments handles -p before --resume <id>", async () => {
140152
assert.equal(r.prompt, "hello");
141153
});
142154

155+
test("parseArguments handles --resume <id> combined with positional query", async () => {
156+
const r = await parseArguments(["--resume", "0a5cb7a5-c39d-4c39-a11b-05f8b22b8df6", "hello", "again"]);
157+
assert.ok(!("message" in r));
158+
assert.equal(r.resume, "0a5cb7a5-c39d-4c39-a11b-05f8b22b8df6");
159+
assert.equal(r.prompt, "hello again");
160+
});
161+
143162
test("parseArguments --version takes precedence over --help", async () => {
144163
const r = await parseArguments(["--version", "--help"]);
145164
assert.ok(!("message" in r));
@@ -199,6 +218,17 @@ test("parseArguments exits on empty -p value", async () => {
199218
});
200219
});
201220

221+
test("parseArguments exits when positional query is combined with -p", async () => {
222+
await withMockedExit(async (exitSpy) => {
223+
try {
224+
await parseArguments(["hello", "-p", "world"]);
225+
} catch {
226+
/* expected */
227+
}
228+
assert.ok(exitSpy.calls.length >= 1);
229+
});
230+
});
231+
202232
test("parseArguments exits on invalid --resume session ID", async () => {
203233
await withMockedExit(async (exitSpy) => {
204234
try {

0 commit comments

Comments
 (0)