Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions extensions/cli/src/e2e/headless-missing-prompt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
);
});
});
9 changes: 6 additions & 3 deletions extensions/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Loading