pre-pr-greptile
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePre-PR Greptile Review
PR创建前的Greptile审查
A pre-PR review gate. Greptile reviews the committed branch's diff on its own cloud
(≈$0 Claude tokens, ~$1/review after the monthly free tier), and this skill triages the
result and drives the PR. It is a GATE, not blind automation: the review output is
verified and risky findings are proposed, not auto-applied.
Mirrors Greptile's own official skill (whoami → primary,
fallback, findings ranked by severity) and adapts its iterate-until-clean idea
to the LOCAL CLI (greploop itself drives the PR bot via , not the local review).
cli-review--json--agentgreploopgh这是一个PR创建前的审查关卡。Greptile会在其云端对已提交分支的代码差异进行审查(每月免费额度之外,每次审查约1美元,Claude令牌成本约为0),本Skill会对审查结果进行分类处理并推进PR创建流程。这是一个关卡机制,而非盲目自动化:审查输出会被验证,高风险的发现仅会提出建议,不会自动应用。
本Skill镜像了Greptile官方的 Skill(通过作为主要方式,作为 fallback,发现的问题按严重程度排序),并将其的“迭代直至无问题”理念适配到本地CLI(greploop本身通过驱动PR机器人,而非本地审查)。
cli-reviewgreptile whoami --json--agentgreploopghPrerequisites
前提条件
- Preflight (mirrors greptile's official ):
cli-review(confirm you're in a repo) →git rev-parse --show-toplevel(CLI present) →command -v greptile(auth). Greptile has NOgreptile whoami/apply command — it only PRODUCES findings; the agent applies the fixes (exactly like the official--fixskill, which edits files itself).greploop - Auth (do NOT from an agent/wrapped shell). Check with a non-interactive
greptile login. If unauthenticated, STOP and tell the user to rungreptile whoamiin a native terminal (the browser-OAuth callback is unreliable in wrapped/non-interactive shells — it fails with a malformedgreptile login). Headless fallback:redirect_uriorexport GREPTILE_API_KEY=…(never pass the key as a CLI arg — shell history/process list).echo "$GREPTILE_API_KEY" | greptile login --api-key - greptile installed (). If absent/down/rate-limited → STOP and surface to the user; never hang and never silently open the PR (see Fail-open).
command -v greptile
- 预检查(与Greptile官方一致):执行
cli-review(确认当前处于仓库目录)→git rev-parse --show-toplevel(检查CLI是否存在)→command -v greptile(验证身份)。Greptile没有greptile whoami/应用命令——它仅生成问题发现结果;由Agent来应用修复(与官方--fixSkill完全相同,后者会自行编辑文件)。greploop - 身份验证(请勿从Agent/封装Shell中执行)。通过非交互式的
greptile login检查。如果未通过验证,请停止操作并告知用户在原生终端中执行greptile whoami(在封装/非交互式Shell中,浏览器OAuth回调不可靠——会因greptile login格式错误而失败)。无界面环境的 fallback 方案:redirect_uri或export GREPTILE_API_KEY=…(切勿将密钥作为CLI参数传递——会被记录到Shell历史/进程列表中)。echo "$GREPTILE_API_KEY" | greptile login --api-key - 已安装Greptile(通过检查)。如果未安装/服务不可用/触发速率限制→停止操作并告知用户;切勿挂起或静默创建PR(参见故障开放机制)。
command -v greptile
The flow
流程步骤
- Be on a feature branch with the work committed. If on a trunk/base branch
(,
testing,main) createdevelopfirst. Greptile reviews the branch diff vs its base, so the work must be committed. Keep every commit SSH-signed (neverfeature|bugfix|hotfix/<ticket>-slug, never--no-gpg-sign).--no-verify - Resolve the base branch explicitly — never assume . In this org PRs target
main(the trunk); confirm per repo.testingdefaults to the repo's default branch, which may be wrong — passgreptile reviewto match the intended PR base.-b <base> - Run the review: (primary; introspect the shape with
greptile review -b <base> --json— the JSON schema is undocumented, do not hard-code field names). Fall back tojq 'keys'(plain text) if JSON fails.greptile review -b <base> --agent - VERIFY the review matches THIS branch before trusting ANY finding. Compare the
review's referenced files against (three-dot = merge-base, the PR diff). The review's files must be a subset of the branch diff. If they don't overlap, or the review returns in under ~10s (a cache hit), it is a STALE / different-repo review — discard it, run ONCE more fresh, and if it still mismatches, STOP and surface. NEVER apply fixes from an unverified review. (This guard exists because a first-call greptile review was observed returning a cached review of a completely different repository.)
git diff <base>...HEAD --name-only - Triage findings (verified review only): rank by severity. Tier each finding:
- Mechanical / low-risk (unused import, typo, missing null-guard, docs/test gap): safe to fix directly.
- Risky (auth, crypto, injection, data-loss, concurrency, or ANY logic/behavior change): do NOT auto-apply — propose the diff and get explicit user approval first.
- False positive / intent-conflicting: do not apply; record the rationale (for the PR body / a later thread reply). Never weaken correctness or security to silence a nit.
- Apply fixes, mind the SDD gate. Editing production source () fires the global
.py/.ts/.vue/…PreToolUse hook, which BLOCKS when the repo is an OpenSpec project with no active change — which is the normal state at PR time (all taskssdd_gate). If a production-source fix is blocked: surface it and let the user decide (keep a task open, reopen a change, or apply manually). Do not auto-set- [x]— that defeats the user's spec-first discipline. Fixes underSDD_HOOKS_DISABLED=1, tests,docs/, and.claude/are exempt and apply freely.openspec/ - Re-commit the fixes (signed; prefer + autosquash or a small focused commit so the PR history stays clean), then re-run a FRESH
--fixupand re-do step 4's diff-match.greptile reviewis ONLY for continuing a crashed/interrupted review — it does NOT re-review a new commit, so never use it after applying fixes.--resume - Loop to convergence, cap at 3 reviews. Stop early when only nits/false-positives remain or a finding recurs (the fix didn't satisfy it → human call). Count BILLABLE reviews (initial + every re-run + any stale re-run) — each is ~$1 after the free tier, so don't re-run gratuitously. If not clean after 3, STOP, do NOT create the PR, and surface the remaining findings.
- Ensure the correct gh account, push, then open the PR. ; if it drifted,
gh auth status(a wrong account → push/gh auth switch --user <correct-account>404 "Repository not found").gh pr create(signed) the branch, thengit push— no Claude/Anthropic co-author trailer, no "Generated with Claude Code" footer, nevergh pr create --base <base>. Never merge the base into the feature branch.--no-verify
- 切换到已完成工作提交的功能分支。如果当前处于主干/基础分支(如、
testing、main),请先创建develop格式的分支。Greptile会审查该分支与基础分支的差异,因此工作内容必须已提交。确保每个提交都通过SSH签名(切勿使用feature|bugfix|hotfix/<ticket>-slug或--no-gpg-sign)。--no-verify - 明确指定基础分支——切勿默认假设为。在本组织中,PR目标分支为
main(主干);请根据仓库确认。testing默认使用仓库的默认分支,这可能不符合需求——需传递greptile review参数以匹配预期的PR基础分支。-b <base> - 执行审查:(主要方式;可通过
greptile review -b <base> --json查看JSON结构——该JSON schema未公开,请勿硬编码字段名)。如果JSON方式失败, fallback 到jq 'keys'(纯文本格式,供Agent使用)。greptile review -b <base> --agent - 在信任任何发现结果之前,验证审查是否匹配当前分支。将审查中提及的文件与(三点表示合并基准,即PR的代码差异)的结果进行对比。审查中的文件必须是分支差异文件的子集。如果两者不重叠,或者审查在约10秒内返回(缓存命中),则说明这是过期/来自其他仓库的审查结果——请丢弃该结果,重新执行一次全新的审查;如果仍然不匹配,请停止操作并告知用户。切勿应用未经验证的审查结果中的修复方案。(设置此防护是因为曾观察到首次调用Greptile审查时,返回的是完全不同仓库的缓存审查结果。)
git diff <base>...HEAD --name-only - 分类处理发现的问题(仅针对已验证的审查结果):按严重程度排序。将每个发现分为以下层级:
- 机械性/低风险问题(未使用的导入、拼写错误、缺失空值校验、文档/测试缺口):可直接安全修复。
- 高风险问题(认证、加密、注入、数据丢失、并发问题,或任何逻辑/行为变更):请勿自动应用修复——先提出差异方案并获得用户明确批准。
- 误报/与意图冲突的问题:请勿应用;记录理由(用于PR正文或后续线程回复)。切勿为了消除无关建议而削弱正确性或安全性。
- 应用修复方案,注意SDD关卡。编辑生产源代码()会触发全局
.py/.ts/.vue/…PreToolUse钩子,当仓库是OpenSpec项目且没有活跃变更时(这是PR阶段的正常状态,所有任务均已标记sdd_gate),该钩子会阻止操作。如果生产源代码修复被阻止:告知用户并让其决定(保留一个未完成任务、重新开启变更或手动应用修复)。请勿自动设置- [x]——这会违背用户的“先规范后代码”原则。SDD_HOOKS_DISABLED=1、测试文件、docs/和.claude/下的修复不受限制,可自由应用。openspec/ - 重新提交修复内容(需签名;优先使用+自动压缩或小型聚焦提交,以保持PR历史整洁),然后**重新执行一次全新的
--fixup**并重复步骤4的差异匹配检查。greptile review仅用于恢复崩溃/中断的审查——它不会重新审查新的提交,因此在应用修复后切勿使用。--resume - 循环直至收敛,最多执行3次审查。当仅剩下无关建议/误报,或者某个问题反复出现(修复方案未满足要求→需人工决策)时,提前停止。统计计费审查次数(初始审查+每次重新审查+任何针对过期结果的重新审查)——免费额度之外每次约1美元,因此请勿 gratuitously 重复执行。如果3次审查后仍未达到“无问题”状态,请停止操作,不要创建PR,并告知用户剩余的问题。
- 确保使用正确的gh账户,推送分支后创建PR。执行;如果账户漂移,执行
gh auth status(错误账户会导致推送/gh auth switch --user <correct-account>时出现404“仓库未找到”错误)。推送(已签名)分支,然后执行gh pr create——不要添加Claude/Anthropic联合作者信息,不要添加“Generated with Claude Code”页脚,切勿使用gh pr create --base <base>。切勿将基础分支合并到功能分支中。--no-verify
Definition of "clean"
“无问题”的定义
Zero unresolved findings you agreed with. Nits, suggestions, and documented false
positives do NOT block. Persist skipped-finding rationale so the loop stops re-fighting the
same false positive and the gate can pass with recorded waivers.
零未解决且你认可的问题。无关建议、改进建议和已记录的误报不会阻碍流程。保留跳过问题的理由,以便循环停止重复处理同一误报,且关卡可在记录豁免的情况下通过。
Fail-open / fail-safe
故障开放/故障安全机制
A gate must neither deadlock nor silently bypass. If greptile is missing, unauthenticated
(in this shell), erroring, or rate-limited: STOP and hand the decision to the user — never
hang, never open the PR silently. If the user explicitly says to skip the review, honor it
and note in the PR body that the greptile pre-flight was skipped.
关卡既不能死锁也不能静默绕过。如果Greptile缺失、未通过身份验证(在当前Shell中)、报错或触发速率限制:停止操作并将决策权交给用户——切勿挂起或静默创建PR。如果用户明确要求跳过审查,请遵从并在PR正文中注明已跳过Greptile预检查。
Guardrails
防护规则
- Never act on a review that fails the diff-match check (step 4). Sub-10s return = suspect.
- Never auto-apply security/behavior-changing findings — propose for approval.
- Never bypass the SDD gate or commit signing to make the loop proceed.
- Keep fixes minimal and on-topic; don't scope-creep the branch to satisfy unrelated nits.
- The optional post-PR summary comment must not publicly expose reasoning about security issues you chose not to fix — keep it to resolved items or scrub sensitive detail.
- Each auto-fix edit also triggers whatever PostToolUse hooks and the
Stopare configured in this environment — budget for that latency and let those tests be part of "clean".test_gate
- 切勿对未通过差异匹配检查(步骤4)的审查结果采取行动。10秒内返回的结果应视为可疑。
- 切勿自动应用涉及安全/行为变更的修复方案——仅提出建议等待批准。
- 切勿绕过SDD关卡或提交签名要求以推进循环。
- 修复方案应尽可能精简且紧扣主题;不要为了满足无关建议而扩大分支范围。
- 可选的PR后总结评论不得公开暴露关于你选择不修复的安全问题的推理过程——仅提及已解决的问题或删除敏感细节。
- 每次自动修复编辑还会触发当前环境中配置的所有PostToolUse钩子和
Stop——请考虑延迟问题,并将这些测试视为“无问题”状态的一部分。test_gate
Commands
命令
bash
greptile whoami # auth check (never `greptile login` from a wrapped shell)
greptile review -b testing --json # primary: machine-readable, explicit base
greptile review -b testing --agent # fallback: plain text for agents
git diff testing...HEAD --name-only # the diff the review MUST match (step 4)
greptile review show <id> # reopen a past review
gh auth switch --user <account> # fix account drift before push / gh pr createbash
greptile whoami # 身份验证检查(切勿从封装Shell中执行`greptile login`)
greptile review -b testing --json # 主要方式:机器可读格式,明确指定基础分支
greptile review -b testing --agent # fallback:供Agent使用的纯文本格式
git diff testing...HEAD --name-only # 审查结果必须匹配的代码差异(步骤4)
greptile review show <id> # 重新查看过往审查结果
gh auth switch --user <account> # 在推送/执行gh pr create前修复账户漂移问题