fix: use jq for review body JSON to prevent double-escaped newlines#80
Conversation
|
/describe |
|
✅ PR description has been generated and updated! |
There was a problem hiding this comment.
Review Summary
Assessment: 🔴 CRITICAL
Summary
This PR improves the agent instructions by replacing echo-based JSON construction with jq to prevent double-escaped newlines. However, the provided example code has a critical logic error that would cause it to lose all but the last comment when processing multiple findings.
Critical Issues Found
- HIGH: The
jqcomment-building pattern overwrites the temp file on each iteration - MEDIUM: The example uses literal placeholder text without showing variable substitution
Recommendation
The fix is correct in principle (using jq instead of echo), but the example implementation needs revision to handle multiple findings correctly. Consider either:
- Building all comments in a single
jqinvocation - Using append operations instead of overwrite (
>) - Making the example more explicit about variable substitution
- Initialize empty JSON array, then append each finding with jq instead of overwriting the file on each iteration (loses all but last comment) - Replace literal ISSUE/DETAILS placeholders with $file_path, $line_number, $comment_body variables to clarify substitution
|
/review |
There was a problem hiding this comment.
Review Summary
Assessment: 🟢 APPROVE
This PR improves JSON payload construction by replacing manual echo-based string building with jq-based construction, which correctly handles newline escaping. This is a documentation improvement that will help prevent double-escaped newlines in GitHub review posts.
Summary
The changes update agent instructions to use jq for JSON construction rather than manual string building. One minor documentation issue was found in the example code - the loop structure comment references variables without showing how they should be populated from previous steps.
1 finding | 0 critical | 0 high | 0 medium | 1 low
krissetto
left a comment
There was a problem hiding this comment.
we could probably use a custom tool definition to format things a bit more reliably compared to just prompting 🤔
Summary
The PR review agent was constructing its GitHub API payload by manually building JSON strings with
echo, which caused\nsequences to be double-escaped and rendered as literal text rather than real newlines in posted reviews. This fix updates the agent's instructions inreview-pr/agents/pr-review.yamlto usejqfor JSON construction, ensuring newlines are properly escaped.Changes
review-pr/agents/pr-review.yaml: Replaces theecho-based JSON payload construction with ajq-based approach. The new instructions direct the agent to assign the review body using a heredoc/variable (with real newlines), build the comments array viajq -n --arg/--argjson, and assemble the final payload withjq --slurpfilebefore piping togh api.How to Test
### Assessment:appears on its own line rather than\n### Assessment:).\ncharacters appearing in the GitHub UI.