---
name: code-reviewer
version: 1.0.0
description: 程式碼審查，包裝 PAL MCP 的 codereview 功能
author: miles990
tags:
  - code-review
  - quality
  - security
  - performance
dependencies:
  mcp:
    - package: "pal-mcp-server"
      required: true
      note: "使用 pal.codereview 進行審查"
interface:
  input:
    - name: files
      type: array
      description: "要審查的檔案路徑列表"
      required: true
    - name: review_type
      type: string
      description: "審查類型：full, security, performance, quick"
      required: false
      default: "full"
    - name: context
      type: object
      description: "額外上下文（如變更原因）"
      required: false
  output:
    - name: review_result
      type: object
      description: "審查結果"
    - name: issues
      type: array
      description: "發現的問題列表"
    - name: next_action
      type: string
      description: "建議的下一步"
triggers:
  - pattern: "程式碼審查"
    description: "需要審查程式碼時"
  - pattern: "Milestone 完成"
    description: "Milestone 完成後自動審查"
  - pattern: "提交前"
    description: "git commit 前審查"
title: code-reviewer
canonical_url: https://skilld.dev/gh/miles990/skillpkg/code-reviewer
last_updated: 2026-10-04T16:35:54.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> If the user asked to install this Skill, run `npx skilld install miles990/skillpkg/code-reviewer`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/code-reviewer`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/miles990/skillpkg/code-reviewer) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/code-reviewer`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/code-reviewer --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/code-reviewer --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Code Reviewer

> 審查程式碼 → 找出問題 → 提供建議

## 核心理念

```
┌─────────────────────────────────────────────────────────────────┐
│  不重複造輪子，直接使用 PAL MCP 的專業審查能力                  │
│                                                                 │
│  本 Skill 職責：                                                │
│  • 定義何時觸發審查                                             │
│  • 準備審查所需的上下文                                         │
│  • 整理審查結果                                                 │
│  • 與其他 Skill 協作                                            │
└─────────────────────────────────────────────────────────────────┘
```

## 使用方式

### 基本審查

```javascript
// 調用 PAL codereview
await mcp__pal__codereview({
  step: "審查 M1 完成的程式碼",
  step_number: 1,
  total_steps: 2,
  next_step_required: true,
  findings: "初始審查",
  relevant_files: [
    "/path/to/file1.js",
    "/path/to/file2.js"
  ],
  review_type: "full",
  model: "gemini-2.5-pro"
})
```

### 審查類型

| 類型 | 說明 | 適用時機 |
|------|------|----------|
| `full` | 完整審查（品質、安全、效能、架構） | Milestone 完成後 |
| `security` | 安全專項審查 | 處理敏感資料時 |
| `performance` | 效能專項審查 | 優化相關變更 |
| `quick` | 快速審查 | 小幅修改 |

### 審查標準

```markdown
PAL codereview 會檢查：

品質 (Quality)：
• 程式碼可讀性
• 命名規範
• 註解完整性
• 錯誤處理

安全 (Security)：
• 輸入驗證
• SQL 注入
• XSS 防護
• 敏感資料處理

效能 (Performance)：
• 複雜度分析
• 資源使用
• 快取策略
• N+1 問題

架構 (Architecture)：
• 設計模式
• 模組化程度
• 依賴管理
• 可維護性
```

## 審查流程

```
┌─────────────────────────────────────────────────────────────────┐
│  1. 收集檔案列表                                                │
│     → 從 plan 或手動指定要審查的檔案                            │
│                                                                 │
│  2. 準備上下文                                                  │
│     → 變更原因、相關需求、已知限制                              │
│                                                                 │
│  3. 調用 PAL codereview                                         │
│     → 執行審查，取得結果                                        │
│                                                                 │
│  4. 整理結果                                                    │
│     → 按嚴重程度排序問題                                        │
│                                                                 │
│  5. 輸出建議                                                    │
│     → 需要修正的問題、改進建議                                  │
└─────────────────────────────────────────────────────────────────┘
```

## 輸出格式

```yaml
review_result:
  summary: "審查摘要"
  files_reviewed: 5
  total_issues: 3

  issues:
    - severity: "high"
      type: "security"
      file: "/path/to/file.js"
      line: 42
      description: "未驗證用戶輸入"
      suggestion: "加入輸入驗證"

    - severity: "medium"
      type: "quality"
      file: "/path/to/file.js"
      line: 100
      description: "函式過長"
      suggestion: "考慮拆分成多個小函式"

  positives:
    - "錯誤處理完整"
    - "命名清晰易懂"

  next_action: "修正 high severity 問題"
```

## 與其他 Skill 的協作

```
┌─────────────────────────────────────────────────────────────────┐
│  在 PDCA 循環中的位置                                           │
│                                                                 │
│  Plan → Do → [Check: code-reviewer] → Act                      │
│               ↓                         ↓                       │
│           發現問題                   修正問題                    │
│               ↓                         ↓                       │
│          回到 Do                    繼續下一步                   │
└─────────────────────────────────────────────────────────────────┘
```

## 最小範例

```markdown
用戶：審查這個檔案
AI：

1. 收集檔案：src/api/user.js
2. 調用 PAL codereview
3. 結果：

審查結果：
┌─────────────────────────────────────────────────────┐
│  📋 Code Review 完成                                │
│                                                     │
│  檔案：src/api/user.js                              │
│  問題：2 個                                         │
│                                                     │
│  🔴 High: 第 42 行 - 未驗證用戶輸入                 │
│     建議：加入 validation middleware                │
│                                                     │
│  🟡 Medium: 第 100 行 - 函式過長（150 行）          │
│     建議：拆分成多個小函式                          │
│                                                     │
│  ✅ 優點：                                          │
│     • 錯誤處理完整                                  │
│     • API 設計符合 RESTful                          │
│                                                     │
│  建議：先修正 High 嚴重度問題                       │
└─────────────────────────────────────────────────────┘

需要我幫您修正這些問題嗎？
```

## 設計原則

1. **不重複造輪子** - 直接使用 PAL codereview 的能力
2. **適時觸發** - 在正確的時機進行審查
3. **結構化輸出** - 方便追蹤和處理問題
4. **嚴重程度分級** - 優先處理重要問題
5. **正面回饋** - 也指出做得好的地方

## 限制與邊界

- 依賴 PAL MCP 的可用性
- 審查品質取決於 PAL codereview 的能力
- 大型專案需要分批審查
- 無法取代人工審查，只是輔助
