diff --git a/skills/code-review/SKILL.md b/skills/code-review/SKILL.md index 9134fe8..61ee433 100644 --- a/skills/code-review/SKILL.md +++ b/skills/code-review/SKILL.md @@ -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. diff --git a/skills/code-review/references/finding-schema.md b/skills/code-review/references/finding-schema.md index a2e0106..66df7b1 100644 --- a/skills/code-review/references/finding-schema.md +++ b/skills/code-review/references/finding-schema.md @@ -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 `/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 @ ``** (``..``): `` + +Covered state: ``. 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** (``): . +``` + +`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): . ." + } +] +``` + +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. diff --git a/skills/gitea-pr/SKILL.md b/skills/gitea-pr/SKILL.md index cd2d387..a20ac3c 100644 --- a/skills/gitea-pr/SKILL.md +++ b/skills/gitea-pr/SKILL.md @@ -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 "" -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. diff --git a/skills/gitea-pr/references/gt-pulls.md b/skills/gitea-pr/references/gt-pulls.md index 502e3f0..2a0d0a7 100644 --- a/skills/gitea-pr/references/gt-pulls.md +++ b/skills/gitea-pr/references/gt-pulls.md @@ -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 diff --git a/skills/gitea-pr/references/pr-lifecycle.md b/skills/gitea-pr/references/pr-lifecycle.md index 206a1a3..2e6b06e 100644 --- a/skills/gitea-pr/references/pr-lifecycle.md +++ b/skills/gitea-pr/references/pr-lifecycle.md @@ -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`). diff --git a/tests/fixtures/test_skills_behavioral_contracts.py b/tests/fixtures/test_skills_behavioral_contracts.py index 8f62343..3efa8c4 100755 --- a/tests/fixtures/test_skills_behavioral_contracts.py +++ b/tests/fixtures/test_skills_behavioral_contracts.py @@ -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: