Files
vigilar/.claude/plugins/code-review-tea/.claude-plugin/commands/code-review.md
adlee-was-taken 47c0da5959 feat(plugin): gitea/tea port of code-review command
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-27 13:30:44 -04:00

112 lines
10 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
allowed-tools: Bash(tea pulls:*), Bash(tea pulls review-comments:*), Bash(tea comment:*), Bash(tea api:*), Bash(tea issue create:*), Bash(tea issue close:*), Bash(git diff:*), Bash(git rev-parse:*), Bash(git config:*), Bash(git remote get-url:*), Bash(git remote:*)
description: Code review a Gitea pull request (tea CLI)
disable-model-invocation: false
---
<!-- Fork of Anthropic's code-review plugin (author: Boris Cherny, boris@anthropic.com),
from the claude-plugins-official marketplace. The upstream is GitHub/gh-only.
This fork adapts it to Gitea/tea. Credit for the review design (5 parallel agents,
confidence scoring, false-positive filtering) belongs to the original. -->
Provide a code review for the given Gitea pull request.
You are operating on a Gitea-hosted repository (not GitHub). All Gitea interaction goes through the `tea` CLI (NOT `gh`). The git remote is `ssh://git@git.adlee.work:2222/alee/vigilar.git`; the web host is `https://git.adlee.work`. The `alee` tea login is configured but is NOT the default, so always pass `--remote origin` to resolve repo context (fall back to `--login alee` only if that fails).
**tea api gotchas (verified):** Use `-F` (typed field) — NOT `-f` (string field) — when reading body from a file or stdin. `-f key=@file` posts the literal string `@file`; only `-F key=@file` / `-F key=@-` reads the file/stdin. Endpoints addressing a repo resource require the `/repos/` prefix after the version: `/repos/{owner}/{repo}/...` (NOT `{owner}/{repo}/...`, which 404s). `tea api` already prints JSON to stdout — do NOT pass `-o json` (that writes the body to a file named `json`).
First, make a todo list of these steps, then execute them precisely:
1. Take the PR index from the user (ask if not provided). Use a Haiku agent to fetch `tea pulls <INDEX> --remote origin --fields index,state,draft,title,mergeable,base,head,body -o json` and check if the PR (a) is closed/merged, (b) is a draft, (c) does not need a review (trivial/automated), or (d) already has a code review from you. For (d), run `tea pulls review-comments <INDEX> --remote origin -o json` and scan each comment's `body` for the marker line `### Code review` generated by a `code-review-tea` run (check `reviewer` is the bot/your account). If any of ad, do not proceed. (Note: in tea v0.14.1 the `diff`/`patch` fields come back empty even when requested — fetch the diff separately in step 3.)
2. Use another Haiku agent to give you a list of file paths to (but not the contents of) any relevant CLAUDE.md files from the codebase: the root `CLAUDE.md`, plus any `CLAUDE.md` in the directories whose files the PR modified. Determine modified dirs from the diff obtained in step 1 (parse the `+++ b/<path>` and `--- a/<path>` headers).
3. Use a Haiku agent to summarize the change from the diff. Fetch the diff locally — it is the reliable source in this tea build: `git diff origin/<base>...origin/<head>` (where `base`/`head` are the PR's branch names from step 1's JSON, e.g. `origin/main...origin/fix/issue-2-pin-unification`). Ensure both refs are fetched first (`git fetch origin` if needed).
4. Then, launch 5 parallel Sonnet agents to independently code review the change. The agents should do the following, then return a list of issues and the reason each issue was flagged (eg. CLAUDE.md adherence, bug, historical git context, etc.):
a. Agent #1: Audit the changes to make sure they comply with the CLAUDE.md. Note that CLAUDE.md is guidance for Claude as it writes code, so not all instructions will be applicable during code review.
b. Agent #2: Read the file changes in the pull request, then do a shallow scan for obvious bugs. Avoid reading extra context beyond the changes, focusing just on the changes themselves. Focus on large bugs, and avoid small issues and nitpicks. Ignore likely false positives.
c. Agent #3: Read the git blame and history of the code modified, to identify any bugs in light of that historical context.
d. Agent #4: Read previous pull requests that touched these files (`tea pulls ls --state all --remote origin` then cross-reference file paths), and check for any comments on those pull requests (`tea pulls review-comments <IDX> --remote origin`) that may also apply to the current pull request.
e. Agent #5: Read code comments in the modified files, and make sure the changes in the pull request comply with any guidance in the comments.
5. For each issue found in #4, launch a parallel Haiku agent that takes the PR index, issue description, and list of CLAUDE.md files (from step 2), and returns a score to indicate the agent's level of confidence for whether the issue is real or false positive. To do that, the agent should score each issue on a scale from 0-100, indicating its level of confidence. For issues that were flagged due to CLAUDE.md instructions, the agent should double check that the CLAUDE.md actually calls out that issue specifically. The scale is (give this rubric to the agent verbatim):
a. 0: Not confident at all. This is a false positive that doesn't stand up to light scrutiny, or is a pre-existing issue.
b. 25: Somewhat confident. This might be a real issue, but may also be a false positive. The agent wasn't able to verify that it's a real issue. If the issue is stylistic, it is one that was not explicitly called out in the relevant CLAUDE.md.
c. 50: Moderately confident. The agent was able to verify this is a real issue, but it might be a nitpick or not happen very often in practice. Relative to the rest of the PR, it's not very important.
d. 75: Highly confident. The agent double checked the issue, and verified that it is very likely it is a real issue that will be hit in practice. The existing approach in the PR is insufficient. The issue is very important and will directly impact the code's functionality, or it is an issue that is directly mentioned in the relevant CLAUDE.md.
e. 100: Absolutely certain. The agent double checked the issue, and confirmed that it is definitely a real issue, that will happen frequently in practice. The evidence directly confirms this.
6. Filter out any issues with a score less than 80. If there are no issues that meet this criteria, do not proceed.
7. Use a Haiku agent to repeat the eligibility check from #1, to make sure that the pull request is still eligible for code review.
8. Finally, post the result back to the Gitea PR as a single comment using:
```bash
printf '%s' "$BODY" | tea api --remote origin "/repos/{owner}/{repo}/issues/<INDEX>/comments" -F body=@-
```
where `<INDEX>` is the PR index and `{owner}/{repo}` are substituted by `tea api` from repo context. Note the **`-F`** (typed field, reads stdin via `@-`) — NOT `-f`, which would post the literal string `@-`. Note the **`/repos/`** prefix on the endpoint. If stdin body is rejected, write `$BODY` to `/tmp/review-tea-body.md` and use `-F body=@/tmp/review-tea-body.md`. When writing `$BODY`, keep in mind that you must:
a. Keep your output brief
b. Avoid emojis
c. Link and cite relevant code, files, and URLs — using the **Gitea** link format (NOT GitHub):
`https://git.adlee.work/alee/vigilar/src/commit/<FULL-SHA>/<path>#L<start>-L<end>`
Use the PR's head SHA (from step 1's JSON `headSha`), which is present on the remote. Never use a local-only / unpushed SHA — a commit not on the remote yields a 404 link even on a public repo. Never bash-substitute `$(git rev-parse HEAD)` into the rendered Markdown. Gitea uses `src/commit`, not `blob`.
Examples of false positives, for steps 4 and 5:
- Pre-existing issues
- Something that looks like a bug but is not actually a bug
- Pedantic nitpicks that a senior engineer wouldn't call out
- Issues that a linter, typechecker, or compiler would catch (eg. missing or incorrect imports, type errors, broken tests, formatting issues, pedantic style issues like newlines). No need to run these build steps yourself -- it is safe to assume that they will be run separately as part of CI.
- General code quality issues (eg. lack of test coverage, general security issues, poor documentation), unless explicitly required in CLAUDE.md
- Issues that are called out in CLAUDE.md, but explicitly silenced in the code (eg. due to a lint ignore comment)
- Changes in functionality that are likely intentional or are directly related to the broader change
- Real issues, but on lines that the user did not modify in their pull request
Notes:
- Do not check build signal or attempt to build or typecheck the app. These will run separately, and are not relevant to your code review.
- Use `tea` (NOT `gh`) to interact with Gitea (eg. to fetch a pull request, or to create comments), never web fetch.
- Make a todo list first
- You must cite and link each bug (eg. if referring to a CLAUDE.md, you must link it)
- For your final comment, follow the following format precisely (assuming for this example that you found 3 issues):
---
### Code review
Found 3 issues:
1. <brief description of bug> (CLAUDE.md says "<...>")
https://git.adlee.work/alee/vigilar/src/commit/<FULL-SHA>/<path>#L13-L17
2. <brief description of bug> (some/other/CLAUDE.md says "<...>")
https://git.adlee.work/alee/vigilar/src/commit/<FULL-SHA>/<path>#L23-L28
3. <brief description of bug> (bug due to <file and code snippet>)
https://git.adlee.work/alee/vigilar/src/commit/<FULL-SHA>/<path>#L44-L50
🤖 Generated with [Claude Code](https://claude.ai/code)
<sub>- If this code review was useful, please react with 👍. Otherwise, react with 👎.</sub>
---
- Or, if you found no issues:
---
### Code review
No issues found. Checked for bugs and CLAUDE.md compliance.
🤖 Generated with [Claude Code](https://claude.ai/code)
---
- When linking to code, follow this Gitea format precisely, otherwise the Markdown preview won't render correctly: `https://git.adlee.work/alee/vigilar/src/commit/<FULL-SHA>/<path>#L<start>-L<end>`
- Requires the full git sha of a **remote-present** commit (the PR head SHA from step 1's JSON `headSha`). Never `$(git rev-parse HEAD)` substituted into the rendered comment, and never a local-only/unpushed SHA — those 404 even on a public repo
- Repo path must be `alee/vigilar` (matches the git remote)
- `#L` sign after the file name
- Line range format is `<start>-<end>` (Gitea uses `L1-L3`, same as GitHub but under `src/commit`)
- Provide at least 1 line of context before and after, centered on the line you are commenting about (eg. if commenting about lines 5-6, link to `L4-L7`)