feat(review): add --copy flag for AI-agent-friendly output#37
Conversation
Outputs issues in a format easy to copy and paste back to AI agents for fixing. Includes severity, file:line, message, suggestion, and patch.
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds a Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/main.rs`:
- Around line 207-209: The help text for the CLI flag `copy` (the struct field
`copy` annotated with #[arg(long)]) is misleading because it says “Copy issues
to clipboard” while the implementation prints to stdout; update the doc/help
string for that flag to accurately reflect behavior—e.g., change the field's doc
comment or the #[arg(help = "...")] text to something like “Output issues in
AI-agent-friendly format (for copy/paste)” so the flag description matches the
actual stdout output.
- Around line 354-393: The formatted output in format_issues_for_copy breaks
numbered list indentation when ReviewComment.message or .suggestion contain
newlines; update format_issues_for_copy to normalize multi-line fields by
splitting message and suggestion on '\n' and writing each line prefixed with the
same indentation used for the list entry (e.g., " ") so the numbered item
remains visually nested, and apply the same per-line prefix when iterating
patch.lines() for consistency.
- Around line 1298-1302: The current early return when the copy flag is set
causes side-effects (apply_patches, post_comments, state saving used by `argus
feedback`, and `--fail-on` CI exit behavior) to be skipped; instead of returning
in the `if copy { ... }` block, call `print!("{}",
format_issues_for_copy(&result.comments));` but allow execution to continue so
later code that handles `apply_patches`, `post_comments`, state persistence, and
`--fail-on` runs normally; locate the block around the `copy` flag check in
main.rs (references: `copy`, `format_issues_for_copy`, `result.comments`) and
remove the `return Ok(())` (or replace it with a no-op) so output is emitted but
the rest of the function proceeds unchanged.
There was a problem hiding this comment.
Pull request overview
This PR adds a --copy flag to the argus review command that outputs review findings in a simplified, AI-agent-friendly format for easy copy-pasting back to AI assistants for automated fixes. This addresses issue #34 which requested a one-click way to copy flagged issues.
Changes:
- Added a new
--copyboolean flag to the Review command - Implemented
format_issues_for_copyfunction that formats ReviewComments with numbered issues, severity labels, file locations, and optional suggestions/patches - Added early-return logic in the review command handler to output the copy-friendly format and exit before other output formats are processed
Comments suppressed due to low confidence (1)
src/main.rs:1302
- The verbose output (lines 1262-1296) is printed to stderr before the copy flag check. This means when --verbose and --copy are used together, the verbose stats will be mixed with the AI-agent-friendly output on stderr/stdout. Consider either skipping the verbose output when --copy is enabled, or clarifying in documentation that --verbose should not be used with --copy for clean output.
if copy {
print!("{}", format_issues_for_copy(&result.comments));
return Ok(());
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/main.rs
Outdated
| /// Base commit SHA for incremental review (overrides saved state) | ||
| #[arg(long)] | ||
| base_sha: Option<String>, | ||
| /// Copy issues to clipboard in AI-agent-friendly format |
There was a problem hiding this comment.
The flag description says "Copy issues to clipboard" but the implementation only prints to stdout, it doesn't actually copy to clipboard. Consider either renaming the flag to better reflect what it does (e.g., '--ai-format' or '--copy-format') or updating the description to say something like "Output issues in AI-agent-friendly format for easy copying".
| /// Copy issues to clipboard in AI-agent-friendly format | |
| /// Output issues in AI-agent-friendly format for easy copying |
src/main.rs
Outdated
| // Handle --copy flag: output issues in AI-agent-friendly format | ||
| if copy { | ||
| print!("{}", format_issues_for_copy(&result.comments)); | ||
| return Ok(()); |
There was a problem hiding this comment.
The early return when the copy flag is enabled bypasses important functionality like applying patches (--apply-patches), posting comments to GitHub (--post-comments), saving review state for incremental reviews, and handling the fail-on exit code. This means users cannot combine --copy with these other flags, which may be unexpected behavior. Consider documenting this limitation in the flag description or restructuring the code to allow combining flags.
| return Ok(()); |
| fn format_issues_for_copy(comments: &[ReviewComment]) -> String { | ||
| if comments.is_empty() { | ||
| return "No issues found.".to_string(); | ||
| } | ||
|
|
||
| let mut output = String::new(); | ||
| output.push_str("Issues to fix:\n\n"); | ||
|
|
||
| for (i, c) in comments.iter().enumerate() { | ||
| let severity = match c.severity { | ||
| Severity::Bug => "BUG", | ||
| Severity::Warning => "WARNING", | ||
| Severity::Suggestion => "SUGGESTION", | ||
| Severity::Info => "INFO", | ||
| }; | ||
|
|
||
| output.push_str(&format!( | ||
| "{}. [{}] {}:{}\n", | ||
| i + 1, | ||
| severity, | ||
| c.file_path.display(), | ||
| c.line | ||
| )); | ||
| output.push_str(&format!(" {}\n", c.message)); | ||
|
|
||
| if let Some(suggestion) = &c.suggestion { | ||
| output.push_str(&format!(" Fix: {}\n", suggestion)); | ||
| } | ||
| if let Some(patch) = &c.patch { | ||
| output.push_str(" ```diff\n"); | ||
| for line in patch.lines() { | ||
| output.push_str(&format!(" {}\n", line)); | ||
| } | ||
| output.push_str(" ```\n"); | ||
| } | ||
| output.push('\n'); | ||
| } | ||
|
|
||
| output | ||
| } |
There was a problem hiding this comment.
The format_issues_for_copy function lacks unit tests, which is inconsistent with the codebase pattern where similar formatting functions have comprehensive tests. Consider adding tests to verify the function works correctly with empty comments, single comment, multiple comments with and without suggestions/patches, and different severity levels.
- Update --copy help text to say 'output' instead of 'clipboard' - Handle multi-line message/suggestion/patch with proper indentation - Remove early return so apply_patches, post_comments, state saving, and --fail-on still run
Summary
Adds a flag to that outputs issues in a format easy to copy and paste back to AI agents for fixing.
Output format
Usage
Closes #34
Summary by CodeRabbit
New Features
Chores