Skip to content

Commit 15b4a5e

Browse files
committed
feat(code-review-kit): add code review, conventional commits and PR description plugin
1 parent d569003 commit 15b4a5e

9 files changed

Lines changed: 379 additions & 1 deletion

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "code-review-kit",
3+
"version": "0.1.0",
4+
"description": "Structured code review, conventional commits and PR descriptions performed by the agent on local git diffs. No API keys, no external services - the agent reads your diff, applies a severity-ordered checklist and reports actionable findings.",
5+
"description_i18n": {
6+
"en": "Structured code review, conventional commits and PR descriptions performed by the agent on local git diffs. No API keys, no external services - the agent reads your diff, applies a severity-ordered checklist and reports actionable findings.",
7+
"zh-CN": "基于本地 git diff 的结构化代码评审、约定式提交信息与 PR 描述生成,全部由 agent 完成。无需 API 密钥、无需外部服务--agent 阅读你的改动,按严重程度逐项检查清单,并给出可执行的评审结论。"
8+
},
9+
"author": { "name": "Ajay Sharma" },
10+
"keywords": [
11+
"code-review",
12+
"git",
13+
"commit",
14+
"pull-request",
15+
"conventional-commits"
16+
],
17+
"skills": "./skills",
18+
"commands": "./commands"
19+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# code-review-kit
2+
3+
[中文文档](./README_CN.md)
4+
5+
Structured code review, commit messages and pull-request descriptions for ZCode - performed entirely by the agent on local git diffs. No API keys, no external services, no runtime dependencies: every capability is a skill or slash command that instructs the agent, so reviews run on any machine where ZCode runs.
6+
7+
## What it does
8+
9+
| Capability | How to invoke | What you get |
10+
| --- | --- | --- |
11+
| Code review | `/review` command, or just ask "review my changes" | Severity-grouped findings (`file:line - issue - why - fix`) and a merge verdict |
12+
| Conventional commit | `/commit` command | A Conventional Commits message derived from the staged diff, checked for secrets and debug leftovers before committing |
13+
| PR description | `/pr` command | Copy-ready PR title and body: summary, changes grouped by area, testing steps, risks |
14+
15+
The `code-review` skill also triggers automatically whenever you ask ZCode to review a diff, check recent edits, or audit changes before committing.
16+
17+
## How it works
18+
19+
The agent is the reviewer. The commands and skill teach it a method:
20+
21+
1. **Establish the change set** - staged diff, unstaged diff, or an explicit `base..head` range / branch / files.
22+
2. **Read for context, not just diff** - full file around every hunk; callers are checked when a signature or behavior changes.
23+
3. **Severity-ordered checklist** - 🔴 correctness and security (ship-blockers), 🟡 reliability, performance and test coverage, 🔵 maintainability.
24+
4. **Actionable report** - one line per finding, explicit "no findings" per severity, and a final verdict on what must be fixed before merge.
25+
26+
Reviews are read-only: nothing is modified unless you ask for fixes afterward. If the diff contains a secret, the report redacts it and advises rotating the credential.
27+
28+
## Structure
29+
30+
```text
31+
code-review-kit/
32+
├── .zcode-plugin/
33+
│ └── plugin.json # Manifest (required)
34+
├── commands/
35+
│ ├── review.md # /review - severity-grouped diff review
36+
│ ├── commit.md # /commit - conventional commit from staged diff
37+
│ └── pr.md # /pr - PR title and description
38+
├── skills/
39+
│ ├── code-review/
40+
│ │ └── SKILL.md # Full review methodology (context-triggered)
41+
│ └── conventional-commits/
42+
│ └── SKILL.md # Commit message format reference
43+
├── README.md
44+
└── README_CN.md
45+
```
46+
47+
Component fields in the manifest (`commands` / `skills`) are declared explicitly and point at the standard paths above.
48+
49+
## Usage examples
50+
51+
```text
52+
/review # review staged (or, if none, unstaged) changes
53+
/review main..HEAD # review the whole branch against main
54+
/review src/auth/ # review specific paths
55+
/commit # stage-aware conventional commit
56+
/pr # PR description vs the repo's default branch
57+
/pr develop # PR description against a chosen base
58+
```
59+
60+
The report language follows the conversation language; commit messages themselves stay in Conventional Commits form so tooling can parse them.
61+
62+
## Privacy
63+
64+
The plugin sends nothing anywhere. Diffs are read locally with git, and review output is produced in the session. Whether conversation content leaves your machine is governed by your ZCode/model-provider settings, not by this plugin.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# code-review-kit
2+
3+
[English](./README.md)
4+
5+
面向 ZCode 的结构化代码评审、提交信息与 PR 描述生成——完全由 agent 在本地 git diff 上完成。无需 API 密钥、无需外部服务、无运行时依赖:所有能力都以技能或斜杠命令的形式指导 agent 工作,因此任何能运行 ZCode 的机器都可以使用。
6+
7+
## 功能一览
8+
9+
| 能力 | 调用方式 | 输出 |
10+
| --- | --- | --- |
11+
| 代码评审 | `/review` 命令,或直接说"帮我评审改动" | 按严重程度分组的发现(`file:line — 问题 — 影响 — 建议修复`)与合并结论 |
12+
| 约定式提交 | `/commit` 命令 | 基于暂存 diff 生成的 Conventional Commits 提交信息,提交前检查密钥泄露与调试残留 |
13+
| PR 描述 | `/pr` 命令 | 可直接复制的 PR 标题与正文:摘要、按模块分组的变更、测试步骤、风险说明 |
14+
15+
当你让 ZCode 评审 diff、检查最近的改动或在提交前审计代码时,`code-review` 技能也会自动触发。
16+
17+
## 工作原理
18+
19+
评审者就是 agent 本身。命令与技能教会它一套方法:
20+
21+
1. **确定变更集** —— 暂存 diff、未暂存 diff,或显式指定的 `base..head` 区间 / 分支 / 文件。
22+
2. **读上下文,而不是只看 diff** —— 读取每个 hunk 周围的完整文件;签名或行为变化时检查所有调用方。
23+
3. **按严重程度排序的检查清单** —— 🔴 正确性与安全性(阻塞发布)、🟡 可靠性、性能与测试覆盖、🔵 可维护性。
24+
4. **可执行的报告** —— 每个发现一行,每个严重级别明确说明"无发现",最后给出合并前必须修复的结论。
25+
26+
评审是只读的:除非你要求修复,否则不会修改任何文件。如果 diff 中出现密钥,报告会将其脱敏并建议轮换该凭据。
27+
28+
## 目录结构
29+
30+
```text
31+
code-review-kit/
32+
├── .zcode-plugin/
33+
│ └── plugin.json # 清单(必需)
34+
├── commands/
35+
│ ├── review.md # /review —— 按严重程度分组的 diff 评审
36+
│ ├── commit.md # /commit —— 基于暂存 diff 的约定式提交
37+
│ └── pr.md # /pr —— PR 标题与描述
38+
├── skills/
39+
│ ├── code-review/
40+
│ │ └── SKILL.md # 完整评审方法(按上下文触发)
41+
│ └── conventional-commits/
42+
│ └── SKILL.md # 提交信息格式参考
43+
├── README.md
44+
└── README_CN.md
45+
```
46+
47+
清单中的组件字段(`commands` / `skills`)为显式声明,指向上述标准路径。
48+
49+
## 使用示例
50+
51+
```text
52+
/review # 评审暂存改动(若为空则评审未暂存改动)
53+
/review main..HEAD # 对照 main 评审整个分支
54+
/review src/auth/ # 评审指定路径
55+
/commit # 感知暂存状态的约定式提交
56+
/pr # 针对仓库默认分支生成 PR 描述
57+
/pr develop # 针对指定基础分支生成 PR 描述
58+
```
59+
60+
报告语言跟随对话语言;提交信息本身保持 Conventional Commits 形式(英文类型与主题),以便工具链解析。
61+
62+
## 隐私
63+
64+
本插件不向任何地方发送数据。diff 通过 git 在本地读取,评审输出在会话内生成。对话内容是否会离开你的机器由你的 ZCode / 模型服务方设置决定,与本插件无关。
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
description: Commit staged changes with a Conventional Commits message generated from the diff
3+
---
4+
5+
Create a git commit for the currently staged changes.
6+
7+
1. Run `git status --short` and `git diff --cached --stat`.
8+
- If nothing is staged, show the user what is unstaged/untracked and ask which files to stage. Do not stage files on your own initiative.
9+
2. Read the full staged diff (`git diff --cached`). Before proposing a message, check it for:
10+
- Secrets (API keys, tokens, passwords, private keys, connection strings with credentials). If found: stop, warn, advise removing them and rotating anything already exposed. Do not commit.
11+
- Debug leftovers (`console.log`, `debugger`, `print` debugging, commented-out code). Mention them; commit anyway unless the user says otherwise.
12+
3. Compose the message in Conventional Commits format: `type(scope): subject`.
13+
- Types: feat, fix, refactor, docs, test, perf, style, build, ci, chore. Pick the dominant change; use scope only when it is obvious (module or package name).
14+
- Subject: imperative mood ("add", not "added"), max 72 characters, no trailing period.
15+
- Body: only when the *why* is not obvious from the diff; wrap at 72 characters.
16+
- Footer: `BREAKING CHANGE: <explanation>` when a public API or behavior contract changed.
17+
4. Commit using a heredoc so quotes and newlines survive the shell:
18+
```
19+
git commit -m "$(cat <<'EOF'
20+
<type>(<scope>): <subject>
21+
22+
<optional body>
23+
EOF
24+
)"
25+
```
26+
5. Confirm with `git log -1 --stat` and report the hash, subject and file count. Explain the reasoning in the user's language; the commit message itself stays in Conventional Commits form (English type and subject).
27+
28+
Never push, never amend without being asked, and never use `--force` or `--no-verify` unless the user explicitly requests it.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
description: Generate a pull request title and description from the branch diff and commit history
3+
argument-hint: [base branch] (defaults to the repo's default branch)
4+
---
5+
6+
Generate a PR title and description for the current branch.
7+
8+
1. Determine the base branch: the argument if given; otherwise `git symbolic-ref --short refs/remotes/origin/HEAD 2>/dev/null` (strip the `origin/` prefix); fall back to `main`, then `master`. If none exist, ask the user.
9+
2. Gather the material: `git log --oneline <base>..HEAD`, `git diff <base>...HEAD --stat`, then the full diff - read the full file wherever a hunk lacks context.
10+
3. Write the PR body as markdown:
11+
12+
- **Title** - one line in conventional style (`type(scope): summary`), max 72 characters, covering the dominant change rather than listing files.
13+
- **Summary** - 2–4 sentences: what changed and why it matters to the product or the team.
14+
- **Changes** - bullets grouped by area or module, each describing the concrete behavior change, not file names.
15+
- **Testing** - how a reviewer verifies this: exact commands to run and their expected results. Note explicitly which paths are untested.
16+
- **Risks & notes** - breaking changes, migration steps, follow-up work. Omit the section entirely if empty.
17+
18+
4. Output the finished title and body as a copy-ready markdown block, written in the user's language (match the conversation). The title keeps Conventional Commits form.
19+
5. Then offer next steps without executing them: create the PR with `gh pr create` if the `gh` CLI is available, or print the `git push` command with the right upstream. Push and PR creation happen only after the user confirms.
20+
21+
Never push, and never create the PR, without an explicit confirmation from the user.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
description: Review code changes for bugs, security issues and quality problems before they ship
3+
argument-hint: [base..head | branch | file paths] (defaults to staged changes)
4+
---
5+
6+
Review the code changes the user asked for. Do not modify any files - this is a review-only pass; fix things afterward only if asked.
7+
8+
**Pick the target, in this order of precedence:**
9+
10+
1. If arguments were given ($ARGUMENTS), use them: a `base..head` range, a branch name, a commit, or file paths.
11+
2. Otherwise use staged changes: `git diff --cached`.
12+
3. If that is empty, use unstaged changes: `git diff`.
13+
4. If that is empty too, tell the user there are no changes to review and list what could be reviewed instead (recent commits via `git log --oneline -10`, local branches) - do not guess a target.
14+
15+
**Method:**
16+
17+
- Run the diff with enough context (`git diff -U10` or higher) and read the full file around every hunk. Never judge a hunk in isolation.
18+
- When a function signature or behavior changed, check its callers across the repo before claiming it is safe.
19+
- Apply the checklist below in severity order; ignore flagrant-only style rules unless the user asked for a style pass.
20+
21+
**Checklist:**
22+
23+
- 🔴 Correctness: logic errors, broken edge cases (null/empty/zero/huge input), off-by-one, wrong error handling, race conditions, resource leaks, breaking changes to public APIs.
24+
- 🔴 Security: hardcoded credentials or tokens, SQL/command/XSS injection, path traversal, missing authorization checks, unsafe deserialization, secrets reaching logs.
25+
- 🟡 Reliability & performance: unbounded loops or queries (N+1), hot-path allocations, missing timeouts/retries, swallowed errors, silent fallbacks that hide failures.
26+
- 🟡 Tests: behavior changed without a corresponding test change; new code paths with no coverage.
27+
- 🔵 Maintainability: misleading names, dead code, duplicated logic - only what a teammate would flag.
28+
29+
**Output:**
30+
31+
- Group findings under severity headings. Each finding on one line: `file:line - issue - why it matters - suggested fix`.
32+
- For each severity with no findings, say so explicitly in one line.
33+
- End with a verdict paragraph: overall risk, what must be fixed before merge, what can wait.
34+
- Write the report in the user's language, matching the language of the conversation.
35+
- If the diff contains a secret, redact it to its first 4 characters in the output, warn prominently at the top of the report, and advise rotating it.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
name: code-review
3+
description: Review code changes for correctness, security, performance and maintainability issues. Use when the user asks to review code, check a diff, look over recent edits, audit changes before committing, or find bugs in what changed.
4+
---
5+
6+
# Code review methodology
7+
8+
This skill is the full review method; the /review, /commit and /pr commands apply shorter versions of it. The reviewer is the agent itself - every conclusion must come from actually reading the code, never from pattern-matching the diff shape.
9+
10+
## 1. Establish the change set
11+
12+
- Staged changes: `git diff --cached`. Unstaged: `git diff`. Branch vs base: `git diff <base>...HEAD -U10`.
13+
- Outside a git repository, review only the files the user named and say that repo-level checks (callers, history) were skipped.
14+
- Note the change size up front. Over ~400 changed lines, review in passes: correctness first, then security, then everything else.
15+
16+
## 2. Read for context, not just diff
17+
18+
- Read the full file around each hunk; a hunk that looks fine in isolation is often wrong in context.
19+
- When a function signature, return shape, or error behavior changes, grep for its callers and check each one.
20+
- Check adjacent code the diff touches but does not show (initialization, cleanup, config) before declaring a bug or clearing one.
21+
22+
## 3. Checklist, in severity order
23+
24+
**🔴 Correctness (ship-blockers)**
25+
26+
- Logic errors and inverted conditions; edge cases: null/undefined/empty/zero/negative/huge input, unicode, concurrent access.
27+
- Error handling: caught-and-swallowed errors, wrong error types, promises without rejection handling, missing timeouts.
28+
- Resource leaks: files, connections, subscribers, locks not released on every path including the error path.
29+
- Public API or persisted-data changes that break existing consumers.
30+
31+
**🔴 Security (ship-blockers)**
32+
33+
- Hardcoded credentials, tokens, private keys; secrets interpolated into logs or error messages.
34+
- Injection: SQL, shell, XPath, XSS (unsanitized output), path traversal on user-supplied paths.
35+
- Missing authorization checks on new endpoints or actions; trusting client-side data.
36+
- Unsafe deserialization; crypto misuse (weak algorithms, non-random IVs, homegrown schemes).
37+
38+
**🟡 Reliability & performance**
39+
40+
- Unbounded work: N+1 queries, loops growing with request size, unpaginated list endpoints.
41+
- Hot-path allocations, repeated recomputation of loop-invariant values.
42+
- Missing retry/backoff on network calls; silent fallbacks that turn failures into wrong results.
43+
44+
**🟡 Tests**
45+
46+
- Behavior changed with no test change; new branches with no coverage. Suggest the specific missing test case, not "add tests".
47+
48+
**🔵 Maintainability**
49+
50+
- Misleading names, dead code, duplicated logic, magic constants. Only flag what a teammate would; skip personal style.
51+
52+
## 4. Report
53+
54+
- One line per finding: `file:line - issue - why it matters - suggested fix`. The fix must be concrete enough to act on.
55+
- Group by severity; explicitly state when a severity has no findings.
56+
- End with a verdict: overall risk, the short list that must be fixed before merge, what can wait.
57+
- Write the report in the user's language, matching the language of the conversation.
58+
- Review only. Do not edit files unless asked. If a secret appears in the diff, redact it to its first 4 characters, put the warning at the very top of the report, and advise rotation.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
name: conventional-commits
3+
description: Write git commit messages in Conventional Commits format derived from the actual diff. Use when creating a commit, writing a commit message, or when the user asks for commit message help.
4+
---
5+
6+
# Conventional Commits
7+
8+
Format: `<type>(<scope>): <subject>` followed by optional body and footers.
9+
10+
## Type - pick the one that describes the dominant change
11+
12+
- `feat` - new user-visible capability
13+
- `fix` - bug fix
14+
- `perf` - performance change with no behavior change
15+
- `refactor` - neither fixes a bug nor adds a feature
16+
- `docs`, `test`, `style`, `build`, `ci`, `chore` - the obvious counterparts
17+
18+
A change that both fixes and adds is `feat` if users would call the result new behavior, otherwise `fix`.
19+
20+
## Subject
21+
22+
- Imperative mood: "add filter", not "added filter" or "adds filter".
23+
- Max 72 characters, no trailing period, no capitalization of the first letter beyond what a proper noun forces.
24+
- Describe the change, not the symptom: "reject expired tokens in auth middleware", not "auth bugfix".
25+
26+
## Scope
27+
28+
Optional, in parentheses. Use it when the repository has natural module boundaries and the change is contained in one; omit it rather than inventing one.
29+
30+
## Body
31+
32+
Only when the _why_ is not obvious from the diff. Explain motivation and trade-offs, wrap at 72 characters, blank line after the subject.
33+
34+
## Breaking changes
35+
36+
Either a `BREAKING CHANGE: <explanation>` footer or a `!` after the type (`feat!:`), never both. State what breaks and the migration path.
37+
38+
## Examples
39+
40+
```
41+
feat(search): support quoted phrases in query parser
42+
43+
Queries like "error handling" now match the exact phrase instead of
44+
any of the words, matching user expectations from the support tickets.
45+
```
46+
47+
```
48+
fix(api): return 404 instead of 500 for deleted project ids
49+
50+
Deleted projects were raising NotFoundError inside a generic handler
51+
that mapped unknown errors to 500.
52+
```
53+
54+
Derive the message from `git diff --cached` (or the range being committed), never from the file list alone - file names hide the actual behavior change.
55+
56+
Explain your choices to the user in their language; the commit message itself stays in Conventional Commits form (English type and subject) so tooling can parse it.

0 commit comments

Comments
 (0)