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 <noreply@continue.dev> Co-authored-by: Username <dallin@continue.dev> * fix: better examples when prompt is not provided --------- Co-authored-by: Continue Agent <agent@continue.dev> Co-authored-by: Continue <noreply@continue.dev> Co-authored-by: Username <dallin@continue.dev> Co-authored-by: Dallin Romney <dallinromney@gmail.com>
This commit is contained in:
parent
3c630d70af
commit
f7e69d85db
2 changed files with 34 additions and 3 deletions
|
|
@ -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",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue