feat(code-agent): use PR template for pr_body in structured output#56
feat(code-agent): use PR template for pr_body in structured output#56rh-hemartin wants to merge 1 commit into
Conversation
Teach the code agent to discover repo PR templates and write a template-structured pr_body field in code-result.json. The post-script uses pr_body verbatim as the PR description, falling back to the commit body when absent. Changes: - Add optional pr_body field to code-result.schema.json (maxLength: 65536) - Add pr_body reading logic to post-code.sh with printf-safe piping - Tighten Closes-line stripping to only match GitHub ref forms - Add PR template discovery step to SKILL.md (step 3 item 5) - Replace heredoc examples with jq -n pattern (safe from shell expansion) - Add pr_body test cases to post-code-test.sh Migrated from fullsend-ai/fullsend#2979. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Hector Martinez <hemartin@redhat.com>
PR Summary by QodoUse repo PR templates to populate structured pr_body for PR creation
AI Description
Diagram
High-Level Assessment
Files changed (4)
|
|
🤖 Finished Review · ❌ Failure · Started 7:24 AM UTC · Completed 7:38 AM UTC |
Code Review by Qodo
Context used✅ Compliance rules (platform):
55 rules 1. Protected paths modified (scripts/, skills/)
|
| echo "Creating PR..." | ||
|
|
||
| COMMIT_SUBJECT="$(git log -1 --format='%s' HEAD)" | ||
| COMMIT_BODY_RAW="$(git log -1 --format='%b' HEAD | sed '/^Signed-off-by:/d' | sed '/^Closes #/d' | sed -e :a -e '/^\n*$/{ $d; N; ba; }')" | ||
|
|
||
| COMMIT_BODY="$(echo "${COMMIT_BODY_RAW}" | awk ' | ||
| /^$/ { if (buf) print buf; print; buf=""; next } | ||
| /^[-*#>]|^ / { if (buf) print buf; buf=""; print; next } | ||
| /^Closes / { if (buf) print buf; buf=""; print; next } | ||
| { buf = (buf ? buf " " $0 : $0) } | ||
| END { if (buf) print buf } | ||
| ')" | ||
|
|
||
| # Read pr_body from agent output. Fall back to commit body if absent. | ||
| PR_BODY_FROM_RESULT="" | ||
| if [ -n "${RESULT_FILE}" ]; then | ||
| PR_BODY_FROM_RESULT="$(jq -r '.pr_body // empty' "${RESULT_FILE}" 2>/dev/null || true)" | ||
| fi | ||
|
|
||
| if [ -n "${PR_BODY_FROM_RESULT}" ]; then | ||
| # Agent provided pr_body (template-aware or best-effort). | ||
| # Strip Signed-off-by and Closes lines so the script appends them once. | ||
| COMMIT_BODY="$(printf '%s\n' "${PR_BODY_FROM_RESULT}" | sed '/^Signed-off-by:/d' | sed '/^Closes #/d; /^Closes [a-zA-Z0-9_.-]*\/[a-zA-Z0-9_.-]*#/d' | sed -e :a -e '/^\n*$/{ $d; N; ba; }')" | ||
| else |
There was a problem hiding this comment.
1. Protected paths modified (scripts/, skills/) 📜 Skill insight § Compliance
This PR modifies protected governance/infrastructure paths (scripts/ and skills/), which require explicit human review and must not be auto-approved. Ensure the PR has explicit justification/authorization and is routed for human approval.
Agent Prompt
## Issue description
Protected paths were modified in this PR; per policy this must not be auto-approved and needs explicit justification/authorization plus human review.
## Issue Context
The repository treats changes under `scripts/` and `skills/` as protected governance/infrastructure modifications.
## Fix Focus Areas
- scripts/post-code.sh[446-470]
- scripts/post-code-test.sh[127-157]
- skills/code-implementation/SKILL.md[167-176]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| # Read pr_body from agent output. Fall back to commit body if absent. | ||
| PR_BODY_FROM_RESULT="" | ||
| if [ -n "${RESULT_FILE}" ]; then | ||
| PR_BODY_FROM_RESULT="$(jq -r '.pr_body // empty' "${RESULT_FILE}" 2>/dev/null || true)" |
There was a problem hiding this comment.
2. jq failure ignored for pr_body 📜 Skill insight ☼ Reliability
scripts/post-code.sh suppresses JSON parse/read failures when extracting .pr_body by using 2>/dev/null || true, causing a silent fallthrough to the commit-body path. This violates the requirement that inter-component/guard failure paths be handled explicitly rather than ignored.
Agent Prompt
## Issue description
`jq` failures while reading `.pr_body` from the agent result are silenced (`2>/dev/null || true`), which can hide a broken producer/consumer contract and silently change runtime behavior.
## Issue Context
This is an inter-component contract: the agent produces `code-result.json`, and `post-code.sh` consumes it to build the PR body.
## Fix Focus Areas
- scripts/post-code.sh[450-454]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| "pr_body": { | ||
| "type": "string", | ||
| "maxLength": 65536, | ||
| "description": "PR description used as PR body instead of commit body. Supports markdown formatting and template-compliant structure without gitlint line-length constraints." | ||
| } |
There was a problem hiding this comment.
3. Docs contradict pr_body support 📜 Skill insight ⚙ Maintainability
Repository documentation about code-result.json is stale and internally contradictory: it still describes structured output as containing only target_branch (and even “exactly one field”) despite the schema and scripts now supporting an optional pr_body. This mismatch creates misleading guidance for agents and reviewers about whether pr_body is permitted and how validation behaves.
Agent Prompt
## Issue description
Documentation describing structured output for `code-result.json` is now stale and contradictory because the schema (and consumer behavior) supports an optional `pr_body`, yet parts of the docs still claim the output must contain exactly one field and/or only `target_branch` is allowed.
## Issue Context
- The harness schema (`schemas/code-result.schema.json`) has been extended to allow optional `pr_body` alongside `target_branch`.
- `skills/code-implementation/SKILL.md` is internally inconsistent: step 3 instructs writing `{target_branch, pr_body}`, but the later “Validate structured output” step 11 still says the JSON must contain exactly one field and that any extra fields fail validation.
- `agents/code.md` still describes structured output primarily/only in terms of target-branch selection, which is now incomplete.
- Goal: align docs with the current schema and validation rules (including that `additionalProperties: false` still applies, but both keys are allowed and `pr_body` is optional).
## Fix Focus Areas
- schemas/code-result.schema.json[15-19]
- skills/code-implementation/SKILL.md[810-820]
- agents/code.md[95-101]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| # Read pr_body from agent output. Fall back to commit body if absent. | ||
| PR_BODY_FROM_RESULT="" | ||
| if [ -n "${RESULT_FILE}" ]; then | ||
| PR_BODY_FROM_RESULT="$(jq -r '.pr_body // empty' "${RESULT_FILE}" 2>/dev/null || true)" | ||
| fi | ||
|
|
||
| if [ -n "${PR_BODY_FROM_RESULT}" ]; then | ||
| # Agent provided pr_body (template-aware or best-effort). | ||
| # Strip Signed-off-by and Closes lines so the script appends them once. | ||
| COMMIT_BODY="$(printf '%s\n' "${PR_BODY_FROM_RESULT}" | sed '/^Signed-off-by:/d' | sed '/^Closes #/d; /^Closes [a-zA-Z0-9_.-]*\/[a-zA-Z0-9_.-]*#/d' | sed -e :a -e '/^\n*$/{ $d; N; ba; }')" | ||
| else |
There was a problem hiding this comment.
4. Over-broad pr_body stripping 🐞 Bug ☼ Reliability
When pr_body is present, scripts/post-code.sh deletes any line that starts at column 0 with Signed-off-by: or Closes ... before using it as the PR description. This can unintentionally remove legitimate visible content (e.g., a template prompt/example or a code block line) that happens to begin with those exact prefixes.
Agent Prompt
### Issue description
The `pr_body` path is meant to be used largely verbatim, but the current `sed '/^Signed-off-by:/d'` and `sed '/^Closes .../d'` deletes matching lines anywhere in the PR body. If a repo PR template contains a visible “Closes #…” prompt/example, or a markdown code block includes a line that begins with `Closes #`, that line will be silently removed.
### Issue Context
- `post-code.sh` appends its own `Closes #<ISSUE_NUMBER>` footer, so it’s reasonable to remove *footer* `Closes` lines from agent-provided text.
- The current implementation removes these lines regardless of position.
### Fix Focus Areas
- scripts/post-code.sh[450-470]
- scripts/post-code-test.sh[127-157]
### What to change
- Change sanitization to only remove `Signed-off-by:` / `Closes ...` lines when they are part of the trailing footer block (e.g., strip only contiguous matching lines at the end, after trimming trailing blank lines).
- Update `post-code-test.sh`’s `build_pr_body` helper to match the production logic.
- Add a test where `pr_body` contains a code block or example line starting with `Closes #...` *not at the end* and assert it remains present.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
ReviewVerdict: comment · 1 medium, 3 low findings Clean feature migration. The architecture (agent writes Findings1. [medium] [stale-instructions]
|
Summary
pr_bodysupport from feat(code-agent): uses PR template if found fullsend#2979 to the agents repopr_bodyfield incode-result.jsonpr_bodyverbatim as PR description, falling back to commit body when absentprintfoverecho, tightenedsedpatterns,maxLengthconstraint,jq -nexamples, if/else clarityTest plan
post-code-test.shpasses all 62 tests including newpr_bodycasespr_bodyfield in CIMigrated from fullsend-ai/fullsend#2979.
🤖 Generated with Claude Code