Skip to content

Commit f7e69d8

Browse files
continue[bot]sestinjContinueRomneyDa
authored
Fix: Allow --agent flag without prompt in headless mode (#8227)
* Fix: Allow --agent flag without prompt in headless mode - Modified prompt validation to check for --agent flag presence - Agent files can provide their own prompts, so no user prompt is required - Added example usage with --agent flag to error message - Added test case to verify --agent flag bypasses prompt requirement Fixes issue where 'cn -p --agent owner/package' incorrectly required a prompt Generated with [Continue](https://continue.dev) Co-Authored-By: Continue <[email protected]> Co-authored-by: Username <[email protected]> * fix: better examples when prompt is not provided --------- Co-authored-by: Continue Agent <[email protected]> Co-authored-by: Continue <[email protected]> Co-authored-by: Username <[email protected]> Co-authored-by: Dallin Romney <[email protected]>
1 parent 3c630d7 commit f7e69d8

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

extensions/cli/src/e2e/headless-missing-prompt.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,32 @@ models:
147147
"A prompt is required when using the -p/--print flag",
148148
);
149149
});
150+
151+
it("should not require prompt when using --agent flag with -p", async () => {
152+
await createTestConfig(
153+
context,
154+
`name: Test Assistant
155+
version: 1.0.0
156+
schema: v1
157+
models:
158+
- model: gpt-4
159+
provider: openai
160+
apiKey: test-key
161+
roles:
162+
- chat`,
163+
);
164+
165+
const result = await runCLI(context, {
166+
args: ["-p", "--config", context.configPath, "--agent", "test/agent"],
167+
env: { OPENAI_API_KEY: "test-key" },
168+
expectError: true, // Will fail trying to load agent from hub, but should pass prompt validation
169+
timeout: 5000,
170+
});
171+
172+
// Should NOT show the "prompt required" error message
173+
const output = result.stderr + result.stdout;
174+
expect(output).not.toContain(
175+
"A prompt is required when using the -p/--print flag",
176+
);
177+
});
150178
});

extensions/cli/src/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,15 +216,18 @@ addCommonOptions(program)
216216
}
217217
}
218218

219-
// In headless mode, ensure we have a prompt
220-
if (options.print && !prompt) {
219+
// In headless mode, ensure we have a prompt unless using --agent flag
220+
// Agent files can provide their own prompts
221+
if (options.print && !prompt && !options.agent) {
221222
safeStderr(
222-
"Error: A prompt is required when using the -p/--print flag.\n\n",
223+
"Error: A prompt is required when using the -p/--print flag, unless --prompt or --agent is provided.\n\n",
223224
);
224225
safeStderr("Usage examples:\n");
225226
safeStderr(' cn -p "please review my current git diff"\n');
226227
safeStderr(' echo "hello" | cn -p\n');
227228
safeStderr(' cn -p "analyze the code in src/"\n');
229+
safeStderr(" cn -p --agent my-org/my-agent\n");
230+
safeStderr(" cn -p --prompt my-org/my-prompt\n");
228231
await gracefulExit(1);
229232
}
230233

0 commit comments

Comments
 (0)