feat(code-review): draft PR comment blocks for gitea-pr to publish

- code-review: new step 8 drafts review-body.md and inline-comments.json
  when the target is an open PR; finding-schema section 4 defines contents
  (all non-rejected findings), inline/body placement, record/issue
  follow-up routing, and SHA-scoped finding identity across re-reviews.
  code-review never posts, keeping it a read-only inspector.
- gitea-pr: new step 6 publishes the block as one comment-only review
  pinned with --commit, after owner approval; gt-pulls recipe adds
  head_sha staleness, pending-review, and duplicate-SHA guards and forbids
  --approve, --request-changes, and --yes. Findings routed to an issue get
  one via gitea-plan first so the comment links to tracked work.
- pr-lifecycle: triage keeps the published ID, disposition, and route labels.
- tests: contract test asserting code-review has no posting commands and
  the gitea-pr publish recipe keeps its guards ahead of the post command.

Motivated by lg-smtv-mcp PR #6, where nits were posted manually as a
top-level comment on request.
This commit is contained in:
kiskaadee committed 2026-11-15 14:11:59 -05:00
1 parent c7a720e968
commit a11d942554
6 files changed
+110 -1

No files matched your search

+3
View File
@@ -27,9 +27,11 @@ description: >-
5. **Aggregate without silent resolution.** When multiple reviewers or passes disagree, keep the disagreement visible under `Unresolved` until evidence settles it.
6. **Emit executable runtime checks.** For stateful or high-risk paths that static inspection cannot prove, emit runnable fenced shell commands for `verify-slice` following the Step 6 contract in [finding-schema](references/finding-schema.md) (stating purpose, `local` vs. `live-infra` scope classification, explicit pass condition, and explicit failure signal).
7. **Present the review summary.** Group findings by axis and apply the decision matrix from [axes](references/axes.md): `Needs Rework` (confirmed defects require changes), `Blocked` (unresolved Critical/High risks or unestablished scope), or `Ready` (all four axes completed, no confirmed or unresolved blocking findings remain, and exact covered revisions plus working-tree state are recorded). Static review establishes static provenance for that diff only; never authorize release.
8. **Draft the PR comment block.** When the target is an open pull request, draft `review-body.md` and `inline-comments.json` per section 4 of [finding-schema](references/finding-schema.md), proposing `inline`/`body` placement and `record`/`issue` follow-up for each non-rejected finding. Never post to Gitea yourself: hand the block to `gitea-pr`.
## Your call
- **Handling findings**: decide whether confirmed findings block merge, trigger a rework loop, or become tracked follow-up issues.
- **Publishing findings**: decide whether the PR comment block is posted, and confirm each finding's placement and follow-up route.
- **Adjudicating unresolved disagreements**: resolve conflicting reviewer perspectives or accepted architectural trade-offs.
- **Authorizing release**: verification and review evidence inform decisions, but the human owner remains the sole release authority.
@@ -40,3 +42,4 @@ description: >-
- `diagnose`: when a finding exposes a root cause that requires deeper troubleshooting.
- `verify-slice`: to execute behavioral and runtime verification scenarios.
- `git-manager`: when branching, committing review fixes, or rebasing.
- `gitea-pr`: to publish the drafted PR comment block on the pull request after owner approval.
@@ -93,3 +93,50 @@ systemctl reload app-daemon.service && systemctl is-active --quiet app-daemon.se
- **Status**: `Ready` | `Needs Rework` | `Blocked`
- **Next Action**: State whether to hand off to `verify-slice` for runtime verification, `diagnose` for root-cause fixes, or present to human owner for adjudication. Static provenance and runtime verification remain distinct inputs; neither authorizes release on its own.
```
## 4. PR Comment Block (Drafted Here, Published by `gitea-pr`)
When the review target is an open pull request, `code-review` also drafts a PR comment block so the findings stay attached to the change they describe. `code-review` never posts it: it hands the block to `gitea-pr`, which publishes it after the human owner approves.
### What goes in
- Every finding except `Rejected` ones (those stay in the local ledger only).
- Zero eligible findings: draft nothing. A clean review is not posted unless the owner asks.
### Per-finding routing (proposed here, decided by the owner)
| Field | Values | Rule |
| :--- | :--- | :--- |
| **Placement** | `inline` or `body` | `inline` only when the location is a committed line inside a diff hunk at the reviewed head SHA. Unstaged, staged, file-level, or cross-cutting findings go in `body`. |
| **Follow-up** | `record` or `issue` | `record`: the comment is the whole record (accepted nit, trade-off). `issue`: the owner intends to fix it later, so it needs a tracked issue (created via `gitea-plan`) and the comment links to it. A PR comment is a record, not a task tracker. |
### Identity across re-reviews
Finding IDs (`CR-01`) are only unique within one review. The block header names the reviewed head SHA, and any cross-review reference uses `<short-sha>/CR-01`. `gitea-pr` uses the header SHA to avoid posting the same review twice.
### Files
Write both files to an untracked scratch location (never inside the repository tree):
`review-body.md`:
```markdown
**Code review @ `<short-head-sha>`** (`<base-ref>`..`<head-ref>`): `<Ready | Needs Rework | Blocked>`
Covered state: `<Clean | fingerprint>`. Tier: `<tier>`. Static provenance only; merge authority stays with the owner.
| ID | Axis | Severity | Disposition | Placement | Follow-up |
| :--- | :--- | :--- | :--- | :--- | :--- |
| CR-01 | Standards & Smells | Low | Accepted Trade-off | inline | record |
### Body-placed findings
- **CR-02** (`<location>`): <invariant, impact, and suggested change>.
```
`inline-comments.json` (the `gt pr review --comments-file` format; `new_position` is the line number in the new version of the file and must fall inside a diff hunk):
```json
[
{
"path": "src/pkg/config.py",
"new_position": 40,
"body": "**CR-01** (Low, Accepted Trade-off, record): <invariant and impact>. <Suggested change>."
}
]
```
Every inline entry also appears in the body table, so the record stays complete if inline placement is rejected and the entry moves to the body.
+10 -1
View File
@@ -13,6 +13,7 @@ description: >-
- Opening or updating a pull request on Gitea after implementing an issue or feature.
- Synthesizing static code review and runtime verification evidence into a reviewable PR.
- Tracking review comments, requested changes, and CI checks toward merge readiness.
- Publishing a `code-review` PR comment block (findings and nits) onto an open pull request.
- Not for static code inspection: use `code-review`.
- Not for runtime behavioral verification: use `verify-slice`.
- Not for branch creation, committing, rebasing, or local history integration: use `git-manager`.
@@ -41,7 +42,13 @@ description: >-
[references/gt-pulls.md](references/gt-pulls.md):
`gt pr create -t "<title>" -B "<base>" -H "<branch>" -F <body-file> --json number,url`.
Pass `--draft` if work remains in progress. Extract verified PR number and URL.
6. **Track review feedback and merge readiness.** Inspect status checks (`gt pr checks <number>`),
6. **Publish review findings (when a `code-review` comment block exists).** Follow
[references/gt-pulls.md](references/gt-pulls.md) section 3: confirm the remote PR head equals
the reviewed head SHA (else stop and re-run `code-review`), confirm no pending review and no
prior review for that SHA exists, show the body and inline list for approval, then post one
`--comment` review pinned with `--commit`. Never `--approve` or `--request-changes`. Findings
routed `issue` get their issue (via `gitea-plan`) before posting so the comment links to it.
7. **Track review feedback and merge readiness.** Inspect status checks (`gt pr checks <number>`),
mergeability (`gt pr view <number> --json mergeable,review_decision`), and review comments
(`gt pr review comments <number>`). When all checks pass and review feedback is resolved,
report `Ready for Merge`.
@@ -49,6 +56,7 @@ description: >-
## Your call
- **PR title and description approval**: review and approve the draft PR content and issue linkage.
- **Publishing review findings**: approve the comment block and each finding's placement and follow-up route before it is posted.
- **Review feedback triage**: decide how to address review comments (rework, clarification, deferral).
- **Merge and release authorization**: decide when to merge the PR into the target base branch.
@@ -60,3 +68,4 @@ description: >-
- `code-review`: if the diff changes and needs renewed static inspection.
- `verify-slice`: if new code requires runtime verification.
- `git-manager`: to commit review fixes, rebase, or update the branch against upstream base.
- `gitea-plan`: to create the follow-up issue for a finding routed `issue` before publishing.
+23
View File
@@ -86,6 +86,29 @@ gt pr review resolve <comment-id>
gt pr review unresolve <comment-id>
```
### Publish a `code-review` Comment Block
Input: `review-body.md` and `inline-comments.json` drafted by `code-review` (section 4 of its `finding-schema.md`), plus the reviewed head SHA from the block header.
```bash
# 1. Staleness: the PR head must equal the reviewed head SHA. Mismatch: stop, re-run code-review.
gt pr view <number> --json head_sha -q .head_sha
# 2. Duplicates and pending state: stop if any review is PENDING (posting would publish its
# inline comments too) or if a review already exists for the reviewed SHA from this block.
gt pr review list <number> --json id,state,commit,body
# 3. After owner approval: one comment-only review, pinned to the reviewed commit.
gt pr review <number> --comment --commit <reviewed-head-sha> \
-F review-body.md --comments-file inline-comments.json --json id,url
# Body-only block (no inline entries): omit --comments-file.
```
- Never pass `--approve` or `--request-changes`: the verdict in the body is informational, and merge authority stays with the owner (Gitea also refuses approval on your own PR).
- Never pass `--yes`: it exists to publish a pending review, which step 2 already rules out.
- If Gitea rejects an inline entry (line outside a diff hunk), confirm with step 2 that no review was created, move that entry into the body, and retry once.
- Record the returned review `id` and `url`. Later fixes use `gt pr review reply` with `Fixed in <sha>` and `gt pr review resolve`, per the triage workflow in `pr-lifecycle.md`.
---
## 4. Closing and Merging Pull Requests
@@ -68,6 +68,7 @@ When comments or change requests arrive on a PR:
- *Defects & Invariants*: Logic errors, broken tests, edge-case crashes (require code fix).
- *Spec & Scope Clarifications*: Questions about intent or architectural fit (require response or doc update).
- *Nits / Polish*: Minor style preferences that do not violate repo standards (human owner decides priority).
Findings published from a `code-review` comment block arrive pre-labelled with their ID, disposition, and follow-up route (`record` or `issue`); keep those labels instead of re-categorizing.
3. **Implement fixes on the feature branch**:
- Use `tdd` or direct edits.
- Commit fixes incrementally following `git-manager` conventions (e.g. `fix(gitea-pr): address review feedback`).
+26
View File
@@ -13,6 +13,7 @@ Verifies:
7. Deviation reporting on skipped checks
8. Strict dry-run zero-mutation invariants
9. Skill inventory, line count (<= 80), em-dash absence, and path portability
10. Review comment publishing ownership (code-review drafts, gitea-pr posts with guards)
"""
import os
@@ -361,6 +362,31 @@ class TestSkillsBehavioralContracts(unittest.TestCase):
# But during execution, zero new commits and zero external branch creation
self.assertEqual(initial_commit, current_commit)
def test_review_comment_publishing_ownership(self):
"""Proves code-review only drafts the PR comment block and gitea-pr alone posts it, guarded."""
cr_dir = REPO_ROOT / "skills" / "code-review"
cr_text = "\n".join(p.read_text() for p in cr_dir.rglob("*.md"))
# code-review drafts the block but never contains a posting command
self.assertIn("review-body.md", cr_text)
self.assertIn("inline-comments.json", cr_text)
self.assertIsNone(
re.search(r"gt pr (comment|review)\s+<", cr_text),
"code-review must not contain gt posting commands; gitea-pr owns publishing",
)
pr_skill = (REPO_ROOT / "skills" / "gitea-pr" / "SKILL.md").read_text()
recipes = (REPO_ROOT / "skills" / "gitea-pr" / "references" / "gt-pulls.md").read_text()
self.assertIn("Publish review findings", pr_skill)
publish = recipes.split("### Publish a `code-review` Comment Block", 1)[1].split("\n## ", 1)[0]
post_cmd = re.search(r"gt pr review <number> --comment[^\n]*\n[^\n]*", publish).group(0)
# pinned to the reviewed commit, comment-only, no blanket confirmation
self.assertIn("--commit <reviewed-head-sha>", post_cmd)
for forbidden in ("--approve", "--request-changes", "--yes"):
self.assertNotIn(forbidden, post_cmd)
# staleness and duplicate guards precede posting
self.assertLess(publish.index("head_sha"), publish.index(post_cmd))
self.assertLess(publish.index("gt pr review list"), publish.index(post_cmd))
def test_skill_inventory_and_skeletons(self):
"""Proves all 17 active skills meet line count (<= 80), em-dash, and path portability rules."""
for skill_name in EXPECTED_SKILLS: