Skip to content

feat(kiro): fix PRD creation and add model selection#194

Merged
subsy merged 9 commits intosubsy:mainfrom
medhatgalal:pr/multi-cli-support
Jan 22, 2026
Merged

feat(kiro): fix PRD creation and add model selection#194
subsy merged 9 commits intosubsy:mainfrom
medhatgalal:pr/multi-cli-support

Conversation

@medhatgalal
Copy link
Copy Markdown
Contributor

@medhatgalal medhatgalal commented Jan 22, 2026

Summary

This PR fixes two issues with the Kiro CLI agent and adds model selection support.

Bug Fixes

1. Auto-load bundled PRD skill from agent's skills directory

The create-prd command now automatically loads the ralph-tui-prd skill from the agent's configured skills directory (e.g., ~/.kiro/skills/). This ensures the AI agent receives proper formatting instructions for generating PRDs with ### US-XXX: sections that ralph-tui can parse.

Changes:

  • Add loadBundledPrdSkill() to load skill from agent.meta.skillsPaths
  • Auto-load skill in runChatMode() when no custom skill specified

2. Strip ANSI codes from PRD content before saving

Agents like Kiro output colored text with ANSI escape codes. These codes were being saved to the PRD markdown file, causing the parser to fail when looking for ### US-XXX: patterns.

Changes:

  • Use existing stripAnsiCodes() from output-formatting.ts (no duplication)
  • Strip ANSI codes before writing PRD file and updating state

New Feature

3. Kiro model selection support

Kiro CLI supports --model flag for per-session model selection. This adds model configuration to the Kiro agent plugin.

Changes:

  • Add model property and initialize from config
  • Add --model flag to buildArgs when model is configured
  • Add model setup question with valid Kiro model choices
  • Update validateModel to check valid model names

Valid models: auto, claude-sonnet4, claude-sonnet4.5, claude-haiku4.5, claude-opus4.5

Usage:

ralph-tui run --agent kiro --model claude-opus4.5

Testing

  • 24 new tests for create-prd command (argument parsing, skill loading)
  • 21 new tests for output formatting utilities
  • 8 new tests for Kiro model support
  • All 44 Kiro agent tests pass
  • Coverage: 40.47% function coverage (meets 40% threshold)

Manual Testing

Tested full workflow:

  1. ralph-tui setup - selected Kiro agent
  2. ralph-tui create-prd --timeout 0 - PRD generated with proper ### US-XXX: format
  3. ralph-tui convert --to json - converted successfully
  4. ralph-tui run --prd ./tasks/prd.json - executed tasks

Fixes PRD parsing error: "PRD has no user stories"

Summary by CodeRabbit

  • New Features

    • Auto-load bundled PRD skills from personal or repo directories when no custom skill is provided.
    • Kiro agent model selection during setup with validated choices.
  • Improvements

    • PRD content cleaned of ANSI codes before saving and in-memory.
    • Beads conversion always injects baseline label and clarifies label precedence.
    • Wizard skill installation is agent-aware with clearer reporting and target-path handling.
  • Tests

    • Expanded coverage for PRD command, skill-loading, agent models, conversion labels and formatting utilities.
  • Chores

    • Personal context directory added to .gitignore.

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel
Copy link
Copy Markdown

vercel bot commented Jan 22, 2026

@medhatgalal is attempting to deploy a commit to the plgeek Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jan 22, 2026

Walkthrough

Auto-loads a bundled ralph-tui-prd SKILL.md when no custom PRD skill is provided, adds model selection/validation for the Kiro agent and passes --model to the CLI, strips ANSI escape codes from PRD content before saving/state, reworks agent-aware skill installation flow, and adds comprehensive tests for these behaviours.

Changes

Cohort / File(s) Summary
PRD Skill Auto-Loading
src/commands/create-prd.tsx, tests/commands/create-prd.test.ts
Added loadBundledPrdSkill(agent) that checks agent skillsPaths (personal ~/.kiro/skills/... then repo .kiro/skills/...) for ralph-tui-prd/SKILL.md; runChatMode() auto-loads and sets parsedArgs.prdSkillSource when found. Tests cover precedence, HOME expansion and fallbacks.
Kiro Agent Model Selection
src/plugins/agents/builtin/kiro.ts, tests/plugins/kiro-agent.test.ts
Introduced VALID_KIRO_MODELS, persisted model field, added a setup select question and validateModel(model), and pass --model in buildArgs when configured. Tests updated for validation, setup question, and CLI args.
PRD Content Sanitisation
src/tui/components/PrdChatApp.tsx, tests/tui/prd-chat-app.test.ts
Strip ANSI escape codes from PRD content via stripAnsiCodes before writing to disk and updating in-memory state; added tests for ANSI sequences and formatting helpers.
Beads Labels / Convert CLI
src/commands/convert.ts
Always include ralph label and construct --labels argument from CLI then config; updated help text and precedence behaviour.
Skills Installation / Wizard
src/setup/wizard.ts, src/setup/wizard.test.ts
Reworked Step 4 to be agent-aware using skillsPaths; replaced per-skill APIs with agent-scoped installSkillsForAgent, isSkillInstalledAt, resolveSkillsPath; updated wizard flow and mocks/tests.
Tests — PRD/TUI & Commands
tests/...
Added/expanded test suites: tests/commands/create-prd.test.ts, tests/tui/prd-chat-app.test.ts, tests/plugins/kiro-agent.test.ts to validate new behaviours and edge cases.
Repo Config / Ignore
.gitignore
Added .kiro/ to ignore personal context directories.
CI
.github/workflows/ci.yml
Split setup test batch to isolate wizard.test.ts, added separate coverage artifacts to avoid mock leakage.

Sequence Diagram(s)

sequenceDiagram
  participant CLI as runChatMode(parsedArgs)
  participant Agent as AgentPlugin
  participant FS as Filesystem
  participant Log as Logger

  CLI->>Agent: request skillsPaths
  Agent-->>CLI: returns skillsPaths (personal, repo) or undefined
  alt skillsPaths present
    CLI->>FS: check personal `~/.kiro/skills/ralph-tui-prd/SKILL.md` (expand HOME)
    FS-->>CLI: file exists? / content
    alt personal found & non-empty
      CLI->>CLI: set parsedArgs.prdSkillSource = personal path
      CLI->>Log: log success message (rgba(40,167,69,0.5))
    else
      CLI->>FS: check repo `.kiro/skills/ralph-tui-prd/SKILL.md`
      FS-->>CLI: file exists? / content
      alt repo found & non-empty
        CLI->>CLI: set parsedArgs.prdSkillSource = repo path
        CLI->>Log: log success message (rgba(40,167,69,0.5))
      else
        CLI->>Log: no bundled skill found
      end
    end
  else
    CLI->>Log: agent has no skillsPaths
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

🐰 I hopped through SKILLs both near and far,
I found the PRD and polished each bar.
Models chosen kindly, ANSI dust swept clean,
Tests danced around, a tidy little scene.
A rabbit's nod — the pipeline's serene 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main objectives: it mentions both the PRD creation fix and the new model selection feature for the Kiro agent.
Docstring Coverage ✅ Passed Docstring coverage is 87.50% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing touches
  • 📝 Generate docstrings

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 Jan 22, 2026

Codecov Report

❌ Patch coverage is 53.78151% with 55 lines in your changes missing coverage. Please review.
✅ Project coverage is 43.87%. Comparing base (40ba620) to head (6793648).
⚠️ Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
src/setup/wizard.ts 17.64% 42 Missing ⚠️
src/commands/create-prd.tsx 71.42% 10 Missing ⚠️
src/plugins/agents/builtin/kiro.ts 90.90% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #194      +/-   ##
==========================================
- Coverage   44.87%   43.87%   -1.00%     
==========================================
  Files          79       83       +4     
  Lines       22988    23963     +975     
==========================================
+ Hits        10316    10514     +198     
- Misses      12672    13449     +777     
Files with missing lines Coverage Δ
src/plugins/agents/builtin/kiro.ts 64.42% <90.90%> (+5.10%) ⬆️
src/commands/create-prd.tsx 21.56% <71.42%> (ø)
src/setup/wizard.ts 57.89% <17.64%> (-1.47%) ⬇️

... and 6 files with indirect coverage changes

🚀 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.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/plugins/agents/builtin/kiro.ts (1)

169-239: Centralise model selection configuration to avoid inconsistency between choices and validation.

The model choice value uses '' (empty string) for "Auto" but validateModel includes 'auto' in its allowlist. If someone manually configured model: "auto", it would pass validation but then add --model auto to the CLI—potentially mismatched with the UI intent. The model list is also duplicated across the choices array and the validModels check. Extract both to a shared constant and ensure consistency (e.g., use 'auto' consistently across choices and validation).

🤖 Fix all issues with AI agents
In `@src/commands/create-prd.tsx`:
- Around line 128-162: The repo-skill lookup in loadBundledPrdSkill currently
hardcodes process.cwd(), causing bundled skills to be missed when create-prd is
run with --cwd; update the function to resolve the repo path from the agent
context (e.g., use a repoRoot = agent.meta.cwd || agent.meta.root ||
process.cwd()) and join skillsPaths.repo against that repoRoot instead of
process.cwd() when constructing the repo skillFile (refer to loadBundledPrdSkill
and the skillsPaths.repo usage); make the same change for the similar lookup
around lines noted (the other repo lookup block) so both repo-skill searches
respect the provided --cwd.
🧹 Nitpick comments (1)
src/plugins/agents/builtin/kiro.ts (1)

46-62: Validate and normalise the configured model before use.
At the moment any non-empty string is accepted; a stale config will be passed through to the CLI and fail later. Consider trimming and checking via validateModel during initialise so invalid values are caught early.

💡 Suggested adjustment
-    if (typeof config.model === 'string' && config.model.length > 0) {
-      this.model = config.model;
-    }
+    if (typeof config.model === 'string') {
+      const model = config.model.trim();
+      if (model) {
+        const error = this.validateModel(model);
+        if (!error) {
+          this.model = model;
+        }
+      }
+    }

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.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/plugins/agents/builtin/kiro.ts`:
- Around line 66-71: Currently an invalid config.model value is silently
ignored; change the logic in the initialization block that checks config.model
so that when typeof config.model === 'string' and the trimmed model fails
this.validateModel(model) you propagate an error instead of dropping it: throw a
descriptive Error (or rethrow a validation error) that includes the invalid
model string so callers see the failure, otherwise set this.model when
validation passes. Reference symbols: config.model, this.validateModel,
this.model in the kiro initialization code.

medhatgalal and others added 7 commits January 22, 2026 22:54
The create-prd command now automatically loads the ralph-tui-prd skill
from the agent's configured skills directory (e.g., ~/.kiro/skills/).
This ensures the AI agent receives proper formatting instructions for
generating PRDs with ### US-XXX: sections that ralph-tui can parse.

Changes:
- Add loadBundledPrdSkill() to load skill from agent.meta.skillsPaths
- Auto-load skill in runChatMode() when no custom skill specified
- Export function for testing

Test coverage:
- Add tests/commands/create-prd.test.ts with 19 tests
- Tests for parseCreatePrdArgs argument parsing
- Tests for loadBundledPrdSkill with mock file system
Agents like Kiro output colored text with ANSI escape codes. These codes
were being saved to the PRD markdown file, causing the parser to fail
when looking for '### US-XXX:' patterns.

Changes:
- Use existing stripAnsiCodes() from output-formatting.ts (no duplication)
- Strip ANSI codes before writing PRD file and updating state
- Add tests/tui/prd-chat-app.test.ts with 7 tests for ANSI stripping

Fixes PRD parsing error: 'PRD has no user stories'
- Add tests for printCreatePrdHelp and --stories argument parsing
- Add tests for repo skills fallback path in loadBundledPrdSkill
- Add tests for output formatting functions (formatToolName, formatPath, etc.)
- Add tests for PRD questions module (getQuestionCount, getQuestionById)

Coverage: 40.47% function coverage (was 39.13%)
Kiro CLI supports --model flag for per-session model selection.
This adds model configuration to the Kiro agent plugin.

Changes:
- Add model property and initialize from config
- Add --model flag to buildArgs when model is configured
- Add model setup question with valid Kiro model choices
- Update validateModel to check valid model names

Valid models: auto, claude-sonnet4, claude-sonnet4.5, claude-haiku4.5, claude-opus4.5

Usage:
  ralph-tui run --agent kiro --model claude-opus4.5
- Extract VALID_KIRO_MODELS constant to avoid duplication
- Validate and trim model during initialize (fail early)
- Remove 'auto' from valid models (empty string = Auto)
- Update error message to clarify empty string option
…label

- Replace deprecated installSkill()/isSkillInstalled() with
  installSkillsForAgent()/isSkillInstalledAt() in setup wizard
- Skills now install to the selected agent's personal directory
  (e.g., ~/.kiro/skills/ for Kiro, ~/.claude/skills/ for Claude)
- Ensure 'ralph' label is always included in beads conversion while
  preserving the config.toml labels fallback
- Update wizard tests to mock the new agent-aware functions
@subsy subsy force-pushed the pr/multi-cli-support branch from 88c5b71 to 3db7ef6 Compare January 22, 2026 22:57
AI Agent added 2 commits January 22, 2026 23:24
wizard.test.ts mocks skill-installer.js via bun's process-level
mock.module(). When both run in the same batch (bun test src/setup/),
the mock leaks into skill-installer.test.ts despite mock.restore().

Fix: Run wizard.test.ts in its own batch, matching the established
pattern used for beads-bv and beads-rust isolation.
PrdChatApp.tsx only uses parsePrdMarkdown from the prd module, but
was importing from the barrel (prd/index.js) which transitively loads
prd/wizard.ts and prd/generator.ts. These unused modules counted as
0% covered in the tests/ batch, dragging function coverage below 40%.

Import directly from prd/parser.js to avoid this side effect.
@vercel
Copy link
Copy Markdown

vercel bot commented Jan 22, 2026

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

1 Skipped Deployment
Project Deployment Review Updated (UTC)
ralph-tui Ignored Ignored Preview Jan 22, 2026 11:36pm

Request Review

@subsy subsy merged commit 708d7c6 into subsy:main Jan 22, 2026
9 checks passed
@subsy
Copy link
Copy Markdown
Owner

subsy commented Jan 22, 2026

Thanks @medhatgalal

Two behavioral fixes per review feedback:

  1. loadBundledPrdSkill now accepts an explicit cwd param — previously hardcoded process.cwd() for repo-relative skill lookup, which broke --cwd flag usage. The resolved
    cwd from parsedArgs is now threaded through.
  2. kiro.ts initialize now throws on invalid model — previously validateModel() returned an error string but initialize() silently swallowed it, making typos invisible. Now
    throws immediately with the descriptive message (e.g. "Invalid model. Must be one of: claude-sonnet4, ...").

Merged!

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.

3 participants