Skip to content

feat: add --model and --variant flags to create-prd command#388

Merged
subsy merged 2 commits into
mainfrom
t3code/edf90f03
May 11, 2026
Merged

feat: add --model and --variant flags to create-prd command#388
subsy merged 2 commits into
mainfrom
t3code/edf90f03

Conversation

@subsy
Copy link
Copy Markdown
Owner

@subsy subsy commented May 11, 2026

Summary

  • Adds --model and --variant CLI flags to create-prd / prime command, mirroring the existing flags on ralph-tui run
  • --model is forwarded to the agent at execute time via agentOptions.flags, supporting simple names (opus), provider/model format (anthropic/claude-3-5-sonnet), and OpenRouter triple format (moonshotai/kimi-k2.6:siliconflow/fp8)
  • --variant is injected into agent plugin options during initialize() so agents like Gemini can apply reasoning-effort levels (minimal, high, max)
  • Model value is validated by the agent before the chat session opens; invalid values produce an early error
  • createPrdChatEngine and createTaskChatEngine both accept a model option and build the --model flag internally via a shared buildAgentFlags helper
  • PrdChatApp accepts and threads through the model prop; dependency array updated accordingly
  • CLI help text and docs site (create-prd.mdx) updated with new flags and usage examples

Testing

  • Unit tests added in src/chat/engine.test.ts covering createPrdChatEngine and createTaskChatEngine model propagation (with model, without model, provider/model format, OpenRouter format)
  • Unit tests added in src/commands/create-prd.test.tsx and tests/commands/create-prd.test.ts covering parseCreatePrdArgs for --model and --variant individually and in combination with --agent
  • Help output test updated to assert --model and --variant appear in the help string
  • End-to-end UI path (agent preflight + chat session with model flag) not run in CI; manual verification recommended with ralph-tui create-prd --agent claude --model opus

Summary by CodeRabbit

  • New Features

    • Added --model flag to override the AI agent model for PRD creation.
    • Added --variant flag to select model variant/reasoning effort.
    • Models are validated by the agent before sessions start.
  • Documentation

    • Updated CLI help and documentation with examples of using the new --model and --variant options.
  • Tests

    • Expanded test coverage for model and variant flag parsing and propagation across chat engines.

Review Change Stack

- Propagates --model to agent via execute flags, matching run behavior
- Propagates --variant to agent initialize options
- Validates model before chat session starts
- Updates docs and CLI help text
@vercel
Copy link
Copy Markdown

vercel Bot commented May 11, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ralph-tui Ready Ready Preview, Comment May 11, 2026 2:56pm

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 11, 2026

📝 Walkthrough

Walkthrough

This PR adds --model and --variant CLI flags to the create-prd command, allowing users to specify the AI model and reasoning variant for PRD generation. The feature propagates model selection through CLI argument parsing, agent validation, chat engine factory configuration, and TUI component props, with corresponding test coverage and user documentation.

Changes

Model Selection Feature

Layer / File(s) Summary
Type Contracts
src/commands/create-prd-utils.ts
CreatePrdArgs interface extended with optional model and variant fields.
Chat Engine Model Support
src/chat/engine.ts
New buildAgentFlags helper conditionally constructs ['--model', value] CLI flags; createPrdChatEngine and createTaskChatEngine accept optional model parameter and inject flags into agentOptions.
Engine Model Tests
src/chat/engine.test.ts
Test helper createMockAgent extended to capture execute() options; new test suites verify --model flag forwarding to agents when provided and omission when absent, for both PRD and task engines.
CLI Argument Parsing
src/commands/create-prd-utils.ts
parseCreatePrdArgs recognizes --model and --variant flags and populates CreatePrdArgs fields; printCreatePrdHelp documents new options with usage examples.
CLI Parser Tests
src/commands/create-prd.test.tsx, tests/commands/create-prd.test.ts
Added test cases for parsing --model (simple names, provider/model format, OpenRouter format) and --variant; verifies combined flags parse correctly and help output includes documentation.
Command Agent Setup
src/commands/create-prd.tsx
Refactored getAgent to accept {agent?, model?, variant?} options and validate model via agent.validateModel before initialization; runChatMode passes model and variant into agent setup and forwards model to PrdChatApp.
Component Props and Wiring
src/tui/components/PrdChatApp.tsx
PrdChatAppProps interface accepts optional model prop; component passes model to both createPrdChatEngine and createTaskChatEngine; useEffect dependency list updated to include model.
CLI Help Documentation
src/cli.tsx
Added "Create-PRD Options" section documenting --agent, --model, --variant, --output, --prd-skill, --timeout, and --force flags.
User-Facing Documentation
website/content/docs/cli/create-prd.mdx
Added --model and --variant option descriptions; new "Selecting a Model or Variant" subsection with command examples and clarification on model validation and variant forwarding behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • subsy/ralph-tui#191: Both PRs modify agent initialization configuration in create-prd to propagate additional options (model override in this PR, command/envExclude in #191) into agent setup.
  • subsy/ralph-tui#123: Both PRs add variant selection support that is injected into agent options and forwarded as CLI arguments to the agent.
  • subsy/ralph-tui#194: Both PRs modify create-prd.tsx and PrdChatApp component to add model propagation and agent.validateModel integration for per-session model selection.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarizes the main change: adding two new CLI flags (--model and --variant) to the create-prd command.
Docstring Coverage ✅ Passed Docstring coverage is 90.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 11, 2026

Codecov Report

❌ Patch coverage is 73.33333% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 48.27%. Comparing base (600491e) to head (6ddd9b8).

Files with missing lines Patch % Lines
src/chat/engine.ts 63.63% 4 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #388      +/-   ##
==========================================
+ Coverage   48.19%   48.27%   +0.07%     
==========================================
  Files         117      117              
  Lines       38496    38511      +15     
==========================================
+ Hits        18554    18590      +36     
+ Misses      19942    19921      -21     
Files with missing lines Coverage Δ
src/commands/create-prd-utils.ts 70.88% <100.00%> (+1.55%) ⬆️
src/chat/engine.ts 71.61% <63.63%> (+8.06%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (3)
src/commands/create-prd.tsx (1)

155-161: ⚡ Quick win

Consider clarifying error context when model validation fails.

When model validation fails, the specific error is printed at line 158, but returning null causes the generic "Chat mode requires an AI agent" message at lines 200-204 to also appear. While both messages are shown, the second message is slightly misleading. Consider either:

  1. Adding a distinct return code to differentiate "agent missing" from "model invalid"
  2. Exiting immediately after printing the model error

Example:

 if (options.model) {
   const modelError = agent.validateModel(options.model);
   if (modelError) {
     console.error(`Invalid --model value: ${modelError}`);
-    return null;
+    console.error('');
+    console.error('Run "ralph-tui plugins agents" to see supported models.');
+    process.exit(1);
   }
 }

This is a minor UX issue since the specific error is still visible, but improving the error flow would enhance clarity.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/commands/create-prd.tsx` around lines 155 - 161, The model validation
branch using options.model and agent.validateModel currently prints the model
error and returns null, which then triggers the generic "Chat mode requires an
AI agent" flow; instead, after logging the specific model error, exit
immediately with a non-zero status (e.g., process.exit(1)) so execution stops
and the misleading generic message does not appear — update the block around
options.model / agent.validateModel to terminate the process after printing the
error rather than returning null.
src/chat/engine.test.ts (2)

329-351: 💤 Low value

LGTM! Task engine model propagation verified.

The test suite confirms that createTaskChatEngine propagates the --model flag consistently with createPrdChatEngine. The structure mirrors the PRD tests appropriately.

♻️ Optional: More explicit assertion pattern

For line 349, same suggestion as above:

-    const flags = getCapturedOptions()?.flags;
-    expect(flags === undefined || !flags.includes('--model')).toBe(true);
+    const flags = getCapturedOptions()?.flags;
+    if (flags !== undefined) {
+      expect(flags).not.toContain('--model');
+    }

This separates the undefined check from the array membership check for improved clarity.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/chat/engine.test.ts` around lines 329 - 351, Replace the ambiguous
assertion in the second test with a clearer check: change the line that
currently does expect(flags === undefined ||
!flags.includes('--model')).toBe(true) to either two explicit assertions
(expect(flags).toBeUndefined() or expect(flags).not.toContain('--model')) or a
single clearer check like expect(flags || []).not.toContain('--model'); update
the test in the createTaskChatEngine suite (references: createTaskChatEngine,
getCapturedOptions, flags) so it explicitly verifies absence of the '--model'
flag.

291-327: 💤 Low value

LGTM! Comprehensive model propagation coverage.

The test suite thoroughly verifies that createPrdChatEngine correctly forwards the --model flag in various formats (simple names, provider/model, OpenRouter triple) and omits it when not provided. The assertions are correct and well-commented.

♻️ Optional: More explicit assertion pattern

For lines 323-325, consider a slightly more explicit pattern:

-    const flags = getCapturedOptions()?.flags;
-    // Either undefined or an array without --model is acceptable
-    expect(flags === undefined || !flags.includes('--model')).toBe(true);
+    const flags = getCapturedOptions()?.flags;
+    // Either undefined or an array without --model is acceptable
+    if (flags !== undefined) {
+      expect(flags).not.toContain('--model');
+    }

The current approach is correct and uses short-circuit evaluation properly, but separating the undefined check can improve readability.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/chat/engine.test.ts` around lines 291 - 327, Update the last test in the
describe block that uses createPrdChatEngine/getCapturedOptions/sendMessage to
make the assertion more explicit: instead of the short-circuit expect(flags ===
undefined || !flags.includes('--model')).toBe(true), split into two explicit
assertions such as first asserting flags is undefined
(expect(flags).toBeUndefined()) or, if defined, asserting it does not include
'--model' (expect(flags).not.toContain('--model')); keep using the same
getCapturedOptions().flags variable and sendMessage call so test behavior is
unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/chat/engine.test.ts`:
- Around line 329-351: Replace the ambiguous assertion in the second test with a
clearer check: change the line that currently does expect(flags === undefined ||
!flags.includes('--model')).toBe(true) to either two explicit assertions
(expect(flags).toBeUndefined() or expect(flags).not.toContain('--model')) or a
single clearer check like expect(flags || []).not.toContain('--model'); update
the test in the createTaskChatEngine suite (references: createTaskChatEngine,
getCapturedOptions, flags) so it explicitly verifies absence of the '--model'
flag.
- Around line 291-327: Update the last test in the describe block that uses
createPrdChatEngine/getCapturedOptions/sendMessage to make the assertion more
explicit: instead of the short-circuit expect(flags === undefined ||
!flags.includes('--model')).toBe(true), split into two explicit assertions such
as first asserting flags is undefined (expect(flags).toBeUndefined()) or, if
defined, asserting it does not include '--model'
(expect(flags).not.toContain('--model')); keep using the same
getCapturedOptions().flags variable and sendMessage call so test behavior is
unchanged.

In `@src/commands/create-prd.tsx`:
- Around line 155-161: The model validation branch using options.model and
agent.validateModel currently prints the model error and returns null, which
then triggers the generic "Chat mode requires an AI agent" flow; instead, after
logging the specific model error, exit immediately with a non-zero status (e.g.,
process.exit(1)) so execution stops and the misleading generic message does not
appear — update the block around options.model / agent.validateModel to
terminate the process after printing the error rather than returning null.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 1d64cde5-75be-4f2e-874a-aedae5217071

📥 Commits

Reviewing files that changed from the base of the PR and between 600491e and 6ddd9b8.

📒 Files selected for processing (9)
  • src/chat/engine.test.ts
  • src/chat/engine.ts
  • src/cli.tsx
  • src/commands/create-prd-utils.ts
  • src/commands/create-prd.test.tsx
  • src/commands/create-prd.tsx
  • src/tui/components/PrdChatApp.tsx
  • tests/commands/create-prd.test.ts
  • website/content/docs/cli/create-prd.mdx

@subsy subsy merged commit 25b7e44 into main May 11, 2026
10 checks passed
@subsy subsy deleted the t3code/edf90f03 branch May 11, 2026 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant