自動化代碼審查,檢查程式碼品質、架構合規性、編碼標準,並與規格定義進行比對。
/plugin marketplace add knowlet/skills/plugin install knowlet-skills@knowlet/skillsThis skill inherits all available tools. When active, it can use any tool Claude has access to.
multi-model-reviewer 協作時architecture_checks:
layer_dependency:
name: "依賴方向"
rule: "外層只能依賴內層,內層不得依賴外層"
layers:
- adapter (外) → usecase → entity (內)
violations:
- "Entity 不得 import UseCase"
- "UseCase 不得 import Adapter"
package_structure:
name: "套件結構"
rule: "符合 {aggregate}/{layer}/{component} 結構"
expected:
- "{aggregate}/adapter/in/web/"
- "{aggregate}/adapter/out/persistence/"
- "{aggregate}/entity/"
- "{aggregate}/usecase/port/"
- "{aggregate}/usecase/service/"
ddd_checks:
aggregate_root:
name: "Aggregate Root 識別"
rule: "Aggregate Root 必須控制子實體的生命週期"
markers:
- "@AggregateRoot annotation"
- "private constructor for child entities"
value_object:
name: "Value Object 不變性"
rule: "Value Object 必須 immutable"
checks:
- "record class 或 final fields"
- "no setters"
- "equals/hashCode based on all fields"
domain_event:
name: "Domain Event 標準"
rule: "符合 domain-event-standard.yaml"
checks:
- "sealed interface DomainEvent"
- "includes standard metadata"
- "occurredOn timestamp"
參考對應的編碼標準:
| 語言 | 參考文件 |
|---|---|
| Java | coding-standards/references/JAVA_CLEAN_ARCH.md |
| TypeScript | coding-standards/references/TYPESCRIPT.md |
| Go | coding-standards/references/GOLANG.md |
| Rust | coding-standards/references/RUST.md |
usecase_checks:
- id: UC1
name: "單一職責"
rule: "一個 Service 只處理一個 Use Case"
- id: UC2
name: "Port 依賴"
rule: "透過 Port interface 依賴外部資源"
- id: UC3
name: "輸入驗證"
rule: "Input DTO 在 UseCase 層驗證"
- id: UC4
name: "Domain Event 發布"
rule: "狀態變更後發布對應 Domain Event"
- id: UC5
name: "交易邊界"
rule: "Aggregate 操作在單一交易內完成"
aggregate_checks:
- id: AG1
name: "Invariant 保護"
rule: "所有 public 方法必須維護 invariants"
- id: AG2
name: "私有建構子"
rule: "Child Entity 使用 private/package constructor"
- id: AG3
name: "狀態封裝"
rule: "不直接暴露可變集合"
- id: AG4
name: "Factory Method"
rule: "複雜物件使用 Factory 創建"
adapter_checks:
- id: AD1
name: "Port 實作"
rule: "Adapter 必須實作對應的 Port interface"
- id: AD2
name: "依賴注入"
rule: "透過 Constructor Injection"
- id: AD3
name: "錯誤轉換"
rule: "Infrastructure 錯誤轉換為 Domain 錯誤"
╔═══════════════════════════════════════════════════════════════════╗
║ CODE REVIEW REPORT ║
╠═══════════════════════════════════════════════════════════════════╣
║ File: CreateWorkflowService.java ║
║ Aggregate: Workflow ║
║ Layer: usecase/service ║
╠═══════════════════════════════════════════════════════════════════╣
║ ║
║ ✅ UC1: Single Responsibility PASS ║
║ ✅ UC2: Port Dependency PASS ║
║ ✅ UC3: Input Validation PASS ║
║ ⚠️ UC4: Domain Event Publication WARNING ║
║ └─ Event 'WorkflowCreated' missing 'metadata' field ║
║ ✅ UC5: Transaction Boundary PASS ║
║ ║
╠═══════════════════════════════════════════════════════════════════╣
║ TOTAL: 4/5 PASS, 1 WARNING ║
╚═══════════════════════════════════════════════════════════════════╝
review_issues:
- id: CR-001
file: "CreateWorkflowService.java"
line: 45
severity: warning
check: UC4
message: "Domain Event 'WorkflowCreated' missing 'metadata' field"
current_code: |
return new WorkflowCreated(
workflow.getId(),
workflow.getBoardId(),
workflow.getName()
);
suggested_fix: |
return new WorkflowCreated(
workflow.getId(),
workflow.getBoardId(),
workflow.getName(),
EventMetadata.now() // Add metadata
);
spec_reference: "aggregate.yaml#domain_events.WorkflowCreated"
┌─────────────────────┐
│ code-reviewer │ ◄── 本 Skill
│ (代碼審查) │
└──────────┬──────────┘
│
┌───────────────────┼───────────────────┐
│ │ │
▼ ▼ ▼
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ arch-guard │ │coding-standards │ │ multi-model- │
│ (架構守護) │ │ (編碼標準) │ │ reviewer │
└─────────────────┘ └─────────────────┘ └─────────────────┘
# 審查單一檔案
python ~/.claude/skills/code-reviewer/scripts/review.py \
--file src/workflow/usecase/service/CreateWorkflowService.java
# 審查目錄
python ~/.claude/skills/code-reviewer/scripts/review.py \
--dir src/workflow/
# 比對規格
python ~/.claude/skills/code-reviewer/scripts/review.py \
--file src/workflow/usecase/service/CreateWorkflowService.java \
--spec docs/specs/create-workflow/
# PR 審查模式
python ~/.claude/skills/code-reviewer/scripts/review.py \
--git-diff origin/main..HEAD
language: java
architecture: clean-architecture
checks:
architecture:
enabled: true
strict: true
coding_standards:
enabled: true
config: ".coding-standards.yaml"
spec_compliance:
enabled: true
spec_dir: "docs/specs/"
ignore:
files:
- "**/test/**"
- "**/generated/**"
rules:
- UC5 # Skip transaction check for specific cases
severity_thresholds:
error: 0 # Block if any errors
warning: 5 # Block if > 5 warnings
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.