1k code review pr

From OneKeyHQ/app-monorepo · View interactive version

1k code review pr is an AI agent skill from the GitHub repository OneKeyHQ/app-monorepo. Review OneKey PRs and diffs for security, correctness, concurrency, React/RN pitfalls, and repository-specific regressions. Use for code review or 审查 PR.

How to use this skill

Skill file

OneKey PR Code Review

输出语言: 中文

Review Scope

and gh pr diff; do not assume the active branch is the PR head.

and report the exact comparison. Branch comparisons do not include

uncommitted work.

quick-commands.md.

All checks and linked guides must use those same inputs. Read surrounding

code from the reviewed commit, index, or worktree as appropriate.

is a separate action: follow the existing standing workflow authorization

only within its agreed target and limits. An explicit request for local-only

results or no posting takes precedence. Skill steps do not grant permission.

Workflow

For a local diff without a specified PR, skip PR metadata, existing-comment

queries, and publishing. Use a local-review title and omit PR-only report fields

or mark them not applicable; retain findings, evidence, scoring, and validation.

  1. Inspect Target — Read the requested PR or local diff without switching

the active checkout. If source inspection requires a checkout, use an

isolated worktree and preserve the user's active workspace.

  1. Scope — Inspect the selected diff's changed files and change size
  2. Triage — Determine which review modules apply (see triage table)
  3. Primary Review — Read each changed file, apply relevant checks from references/
  4. Codex Cross-Review — If Codex available, run full parallel review (see below)
  5. PR Comment Analysis — For a specified PR, fetch existing comments

(bot + human) and analyze them against the reviewed source (see below)

  1. Merge Findings — Combine primary + Codex + PR comment findings, deduplicate, annotate confidence
  2. Score — Rate the PR across 4 dimensions (see Scoring System). This step is MANDATORY — every report MUST include the scoring table.
  3. Report — Generate structured report using the unified format. Follow the template exactly — every section is required.
  4. GH Comment — When publishing is authorized for this PR, post qualifying

inline comments without reconfirming. Otherwise return findings locally.

Do not run agent:check --profile commit or --profile pr for read-only review;

both can auto-fix worktree files. For remote status use --profile ci --pr <N>

(writes local logs), or read GitHub status directly.

Codex Cross-Review Integration

Check if Codex is available by confirming the codex:codex-rescue subagent type can be dispatched. If uncertain, invoke /codex:setup to check readiness.

If available:

  1. Dispatch a full independent review to Codex via Agent(subagent_type="codex:codex-rescue"):

```

Agent(

subagent_type = "codex:codex-rescue",

prompt = "Review this PR diff for the OneKey crypto wallet monorepo. Focus on:

Report each finding with: file:line, severity (Critical/High/Medium/Low), description, fix suggestion.

Diff:

${FULL_DIFF}"

)

```

  1. Parse Agent result for structured findings
  2. Merge into primary review:
  1. Add a Codex 交叉验证摘要 table in the report (see report template)

If unavailable: Skip silently. Set "Codex 交叉验证: ⏭️ 未启用" in the report header. Do NOT mention Codex anywhere else.

PR Comment Analysis

Collect ALL existing comments on the PR — bot and human — then analyze each with your local codebase context. You have full source access, type system, and dependency graph; most commenters only saw the diff. Use this asymmetry.

Fetching All Comments

Use gh api to get full user metadata (including type field for bot detection):

# Top-level PR reviews (review bodies)
gh api repos/{owner}/{repo}/pulls/{pr_number}/reviews \
  --jq '[.[] | select(.body != "") | {author: .user.login, is_bot: (.user.type == "Bot"), body: .body, state: .state, association: .author_association}]'

# Inline review comments (file:line annotations)
gh api repos/{owner}/{repo}/pulls/{pr_number}/comments \
  --jq '[.[] | {author: .user.login, is_bot: (.user.type == "Bot"), path: .path, line: .line, body: .body, association: .author_association}]'

# General PR comments (issue-level)
gh api repos/{owner}/{repo}/issues/{pr_number}/comments \
  --jq '[.[] | {author: .user.login, is_bot: (.user.type == "Bot"), body: .body, association: .author_association}]'

Bot detection — use the user.type == "Bot" field from GitHub API, not hardcoded username lists. This automatically covers any bot (current and future) without maintenance.

If no comments exist, set "PR 评论分析: ⏭️ 无评论" in the report header and skip this section.

Analysis Framework

For each substantive comment (skip empty approvals, CI status badges, pure formatting):

| Verdict | Meaning | Action |

|---------|---------|--------|

| ✅ Confirmed | Comment identifies a real issue | Include in findings, tag source [<author>] |

| 🔍 Enriched | Real issue, but analysis is shallow or fix is wrong | Include with deeper fix guidance from your codebase knowledge |

| ❌ Noise | Not an issue given full codebase context | Note in "评论误报分析" with brief explanation of why |

| 📋 Already Covered | Your primary review caught it | Record both sources; assess supporting evidence |

Your local advantages — use them aggressively:

When someone flags something vague, dig into the source to confirm or refute. When a comment misses context (e.g., a function is safely guarded upstream), explain why. When a comment is right, amplify with richer context.

Cross-Validation Rules

Security Comment Special Handling

For security-related comments (from bots like Snyk/Dependabot or from human reviewers):

Triage: Which Checks to Run

List changed files from the selected PR or local diff and match:

| Changed Files Match | Load |

|---------------------|------|

| package.json, lockfiles, node_modules patches, patches/*.patch | [security-and-supply-chain.md] — full supply-chain review |

| **/auth/**, **/vault/**, **/signing/**, **/crypto/**, manifest.json, **/manifest/*.js | [security-and-supply-chain.md] — full security review |

| Any .ts/.tsx with business logic | [code-quality-patterns.md] — hooks, race conditions, null safety |

| .android.ts(x), .ios.ts(x), .native.ts(x), .desktop.ts(x), .ext.ts(x), .web.ts(x), native modules, BigNumber usage | [onekey-platform-patterns.md] — platform crashes & numeric safety |

| Shell scripts (.sh), CI workflows (.yml) | [onekey-platform-patterns.md] — build & CI section |

Always check regardless of file type:

Import Hierarchy (ALWAYS verify)

@onekeyhq/shared     <- FORBIDDEN to import from other OneKey packages
    ↓
@onekeyhq/components <- ONLY imports shared
    ↓
@onekeyhq/core       <- ONLY imports shared
    ↓
@onekeyhq/kit-bg     <- imports shared, core (NEVER components or kit)
    ↓
@onekeyhq/kit        <- imports shared, components, kit-bg
    ↓
apps/*               <- imports all
# Inspect imports from the selected scope and source version
review_diff --name-only --diff-filter=ACMR -- '*.ts' '*.tsx' |
  while IFS= read -r f; do
    printf '%s\n' "$f"
    review_file "$f" | rg -n 'from.*@onekeyhq'
  done

Existing Implementation Reuse (ALWAYS verify)

For newly added helpers, hooks, services, components, constants, formatters, validators, or business logic:

File Risk Classification

| Risk | Patterns | Action |

|------|----------|--------|

| Critical | **/vault/**, **/signing/**, **/crypto/**, **/core/src/**, hardware wallet SDK | Line-by-line review |

| High | **/auth/**, API endpoints, state management, package.json, manifest.json | Deep review |

| Medium | UI components, platform-specific code, background services | Standard review |

| Low | Comments, type-only, formatting, tests, docs | Scan for anomalies |

Scoring System

MANDATORY — every report must include this scoring table, no exceptions.

Rate the PR on 4 dimensions (1-10 each):

| Dimension | Weight | What to evaluate |

|-----------|--------|-----------------|

| 🔒 安全性 | 35% | Secret leakage, auth bypass, supply-chain risk, input validation |

| 💎 代码质量 | 30% | Hooks safety, error handling, race conditions, null safety, DRY, reuse of existing implementations |

| 🏛️ 架构合理性 | 20% | Import hierarchy, separation of concerns, cross-platform consistency |

| ✅ 完整性 | 15% | Edge cases handled, test coverage, migration paths, docs |

Total Score = weighted average, rounded to 1 decimal.

| Score | Verdict | Action |

|-------|---------|--------|

| 8.0 - 10.0 | ✅ 可直接合入 | No blockers, minor suggestions only |

| 5.0 - 7.9 | ⚠️ 需修改后复审 | Has issues that should be fixed before merge |

| < 5.0 | ❌ 建议打回重做 | Fundamental issues in security or architecture |

Scoring anchors — to keep scores consistent:

Confidence Levels

MANDATORY — every finding must use exactly one of these three emoji tags. Do NOT use percentages, do NOT use plain text like "高/中/低" without the emoji. Always use this exact format:

| Tag | Meaning | When to use |

|-----|---------|-------------|

| 🔵 High | Confirmed, verifiable from code | Clear bug, obvious violation, reproducible |

| 🟠 Medium | Likely issue, needs context | Pattern suggests problem, might be intentional |

| ⚪ Low | Possible issue, needs human check | Heuristic match, depends on business logic |

Agreement between reviewers records multiple sources; it does not establish

🔵 High confidence. High confidence requires a concrete execution path in

the reviewed code snapshot, a regression test, or reproduction evidence that confirms

the issue. State missing conditions when evidence is incomplete.

Auto-Fix Patches

MANDATORY for these categories — if a finding matches one of these, you MUST include a diff patch:

Format — always use this exact structure:

**Auto-fix:**
\```diff
- old code
+ new code
\```

For other findings where the fix is unambiguous and doesn't require business context, also include auto-fix. When in doubt, include it — it's more useful to have a suggested fix than not.

Do NOT generate auto-fix for:

GH CLI Inline Comments

The existing automatic-comment workflow applies when user authorization covers

posting to the specified PR, including an applicable standing authorization.

Post qualifying findings in the same turn without reconfirming that permission.

If the current request prohibits posting or no publishing authorization applies,

return the findings locally. Reviewing a local diff alone does not identify an

authorized remote target. Publishing never authorizes source edits.

Comment threshold: P0 (any confidence) OR P1 with 🔵 High confidence. This means:

For a P0 with incomplete evidence, explicitly state its confidence and the

conditions that still require verification in the posted comment.

  1. List the qualifying findings that warrant PR comments
  2. Post them in the same turn as the report, using ManagePullRequest post_comment (path + line) when available, otherwise:
# Inline comment on specific file:line
gh api repos/{owner}/{repo}/pulls/{pr_number}/comments \
  --field body="**[P1] 问题标题**: 描述...

**建议修复:**
\`\`\`suggestion
修复代码
\`\`\`

_— Auto-review by Claude_" \
  --field path="path/to/file.tsx" \
  --field line=42 \
  --field side="RIGHT" \
  --field commit_id="{PR_HEAD_SHA}"

Rules:

review, recheck the affected finding and diff location before posting.

Unified Report Format

CRITICAL: Follow this template exactly. Every section marked [REQUIRED] must appear in every report. Do not skip or reorder sections.

# PR #NUMBER 代码审查报告

## 审查概要 [REQUIRED]
- **变更范围**: X 个文件, +Y / -Z 行
- **风险等级**: Critical / High / Medium / Low
- **涉及平台**: Extension / Mobile / Desktop / Web
- **Codex 交叉验证**: ✅ 已启用 / ⏭️ 未启用
- **PR 评论分析**: ✅ 已分析 (N 条评论, 其中 M 条来自 Bot) / ⏭️ 无评论

## 评分 [REQUIRED — NEVER SKIP THIS SECTION]

| 维度 | 得分 | 说明 |
|------|------|------|
| 🔒 安全性 | X/10 | 简要说明 |
| 💎 代码质量 | X/10 | 简要说明 |
| 🏛️ 架构合理性 | X/10 | 简要说明 |
| ✅ 完整性 | X/10 | 简要说明 |
| **总分** | **X.X/10** | **✅ 可直接合入 / ⚠️ 需修改后复审 / ❌ 建议打回** |

## Codex 交叉验证摘要 [REQUIRED if Codex was used, OMIT if not]

| 发现 | Primary | Codex | 状态 |
|------|---------|-------|------|
| 问题描述 | Yes/No | Yes/No | 交叉验证 / 仅 Primary / 仅 Codex |

## PR 评论分析 [REQUIRED if comments exist, OMIT if none]

| 来源 | 类型 | 发现 | 判定 | 说明 |
|------|------|------|------|------|
| Snyk | 🤖 Bot | 依赖漏洞 CVE-XXXX | ✅ Confirmed | 漏洞路径在 OneKey 中可达 |
| @reviewer | 👤 Human | 缺少 null check | 🔍 Enriched | 实际需要在上游 hook 中处理 |
| Devin | 🤖 Bot | 变量命名建议 | ❌ Noise | 命名符合项目规范 |

### 评论误报分析 [OMIT if no noise findings]
- **[来源] 误报**: 具体说明为什么这不是问题(引用源码上下文)

## 发现的问题 [REQUIRED]

### [P0] [🔵 High] 问题标题 {Cross-validated ✅}
**文件**: `path/to/file.tsx:42`
**类型**: 安全 / 构建 / 运行时 / 性能 / 规范
**描述**: 问题是什么,为什么有风险
**Auto-fix:**
\```diff
- old code
+ new code
\```

---

### [P1] [🟠 Medium] 问题标题
**文件**: `path/to/file.tsx:18`
**类型**: 运行时
**描述**: ...
**修复建议**: ...

---

## 修改清单 [REQUIRED]

| 优先级 | 置信度 | 文件 | 类型 | 描述 | Auto-fix |
|--------|--------|------|------|------|----------|
| P0 | 🔵 High | file1.tsx:42 | 安全 | 描述 | ✅ |
| P1 | 🟠 Medium | file2.tsx:18 | 运行时 | 描述 | — |

## 测试建议 [REQUIRED]
1. 测试场景
2. 测试场景

## GH 评论操作 [REQUIRED if qualifying findings exist, OMIT if none]
报告每项问题的实际状态:已发布(附评论链接)、已有评论覆盖、仅本地输出或发布失败(说明原因)。
仅在工具结果确认发布成功后,才标记为已发布。

Priority Definitions

MANDATORY — every finding must carry exactly one P0–P2 tag as its priority. Do NOT use 高/中/低 or Critical/High/Medium/Low as finding priority labels.

| Priority | Criteria | Action |

|----------|----------|--------|

| P0 | Security vulnerability, key/fund exposure, data loss, crash, runtime bug affecting users, build failure | Blocker — must fix before merge |

| P1 | Edge-case bug, concurrency risk, robustness gap, maintainability problem | Should fix before merge |

| P2 | Nice-to-have, minor inconsistency, nit (naming, comments, style) | Follow-up / optional |

Historical PR threads may still use the legacy 5-tier scale; when analyzing them, map old P1 → P0, old P2 → P1, old P3/P4 → P2.

Review Discipline

Reference Files

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.