From f7e69d85db332e883aa35870336a926bb87787d5 Mon Sep 17 00:00:00 2001 From: "continue[bot]" <230936708+continue[bot]@users.noreply.github.com> Date: Mon, 13 Oct 2025 22:02:32 -0700 Subject: [PATCH] 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 Co-authored-by: Username * fix: better examples when prompt is not provided --------- Co-authored-by: Continue Agent Co-authored-by: Continue Co-authored-by: Username Co-authored-by: Dallin Romney --- .../src/e2e/headless-missing-prompt.test.ts | 28 +++++++++++++++++++ extensions/cli/src/index.ts | 9 ++++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/extensions/cli/src/e2e/headless-missing-prompt.test.ts b/extensions/cli/src/e2e/headless-missing-prompt.test.ts index 18d38f7cd..762461312 100644 --- a/extensions/cli/src/e2e/headless-missing-prompt.test.ts +++ b/extensions/cli/src/e2e/headless-missing-prompt.test.ts @@ -147,4 +147,32 @@ models: "A prompt is required when using the -p/--print flag", ); }); + + it("should not require prompt when using --agent flag with -p", async () => { + await createTestConfig( + context, + `name: Test Assistant +version: 1.0.0 +schema: v1 +models: + - model: gpt-4 + provider: openai + apiKey: test-key + roles: + - chat`, + ); + + const result = await runCLI(context, { + args: ["-p", "--config", context.configPath, "--agent", "test/agent"], + env: { OPENAI_API_KEY: "test-key" }, + expectError: true, // Will fail trying to load agent from hub, but should pass prompt validation + timeout: 5000, + }); + + // Should NOT show the "prompt required" error message + const output = result.stderr + result.stdout; + expect(output).not.toContain( + "A prompt is required when using the -p/--print flag", + ); + }); }); diff --git a/extensions/cli/src/index.ts b/extensions/cli/src/index.ts index 4946604dd..b1aa39c28 100644 --- a/extensions/cli/src/index.ts +++ b/extensions/cli/src/index.ts @@ -216,15 +216,18 @@ addCommonOptions(program) } } - // In headless mode, ensure we have a prompt - if (options.print && !prompt) { + // In headless mode, ensure we have a prompt unless using --agent flag + // Agent files can provide their own prompts + if (options.print && !prompt && !options.agent) { safeStderr( - "Error: A prompt is required when using the -p/--print flag.\n\n", + "Error: A prompt is required when using the -p/--print flag, unless --prompt or --agent is provided.\n\n", ); safeStderr("Usage examples:\n"); safeStderr(' cn -p "please review my current git diff"\n'); safeStderr(' echo "hello" | cn -p\n'); safeStderr(' cn -p "analyze the code in src/"\n'); + safeStderr(" cn -p --agent my-org/my-agent\n"); + safeStderr(" cn -p --prompt my-org/my-prompt\n"); await gracefulExit(1); }