xiaohongshu
xiaohongshu
cognitive-review
認知負擔 Code Review 工具。用認知負擔視角進行程式碼審查。用於: (1) 程式碼品質評估, (2) 命名品質檢查, (3) 複雜度熱點識別, (4) 重構建議
Full skill instructions
好的程式碼不需要讀者額外的認知努力就能理解
Code Review 的目標不只是找出錯誤,更重要的是確保程式碼對未來的閱讀者友善。
檢查問題:這段程式碼需要閱讀者同時記住幾個變數的狀態?
| 變數數 | 評估 | 建議 |
|---|---|---|
| 1-3 | 優良 | 維持 |
| 4-5 | 可接受 | 考慮提取函式 |
| > 5 | 需重構 | 拆分為更小的函式 |
檢查問題:理解這段程式碼需要追蹤幾層呼叫?
| 層級 | 評估 | 建議 |
|---|---|---|
| 1-2 | 優良 | 維持 |
| 3 | 可接受 | 考慮扁平化 |
| > 3 | 需重構 | 提取中間函式或使用組合 |
檢查問題:不看實作,能從名稱理解意圖嗎?
| 問題類型 | 範例 | 改善建議 |
|---|---|---|
| 縮寫不明 | btn, mgr | button, manager |
| 含義模糊 | data, info | 具體化:userData, bookInfo |
| 動作不清 | handle(), process() | validateInput(), calculateTotal() |
| 過長冗餘 | getTheUserDataFromDatabase | fetchUser |
檢查問題:需要考慮幾條執行路徑?
| 分支數 | 評估 | 建議 |
|---|---|---|
| 1-2 | 優良 | 維持 |
| 3-4 | 可接受 | 考慮策略模式或早期返回 |
| > 4 | 需重構 | 使用策略模式或狀態模式 |
檢查問題:這個函式做了幾件事?
| 行數 | 評估 | 建議 |
|---|---|---|
| 5-10 | 優良 | 維持 |
| 11-20 | 可接受 | 考慮拆分 |
| > 20 | 需重構 | 必須拆分 |
檢查問題:呼叫者需要記住幾個參數的順序和意義?
| 參數數 | 評估 | 建議 |
|---|---|---|
| 0-2 | 優良 | 維持 |
| 3 | 可接受 | 考慮參數物件 |
| > 3 | 需重構 | 使用參數物件或建造者模式 |
| 熱點類型 | 識別方法 | 影響 |
|---|---|---|
| 長函式 | > 20 行 | 難以一次理解 |
| 深巢狀 | > 3 層縮排 | 上下文難追蹤 |
| 多參數 | > 3 個參數 | 呼叫時容易出錯 |
| 副作用 | 修改外部狀態 | 行為不可預測 |
| 隱藏依賴 | 內部 new 物件 | 難以測試和理解 |
| 優先級 | 類型 | 處理方式 |
|---|---|---|
| P0 | 副作用 | 立即修復 |
| P1 | 深巢狀 | 本次 PR 修復 |
| P2 | 長函式 | 建立技術債 Ticket |
| P3 | 多參數 | 視情況處理 |
## 認知負擔 Code Review 報告
### 檔案: {檔案路徑}
### 整體評估
| 維度 | 評分 | 說明 |
|------|------|------|
| 變數管理 | {1-5} | {說明} |
| 呼叫層級 | {1-5} | {說明} |
| 命名品質 | {1-5} | {說明} |
| 函式設計 | {1-5} | {說明} |
| **總評** | **{1-5}** | **{說明}** |
### 熱點清單
| 行號 | 類型 | 問題 | 建議 | 優先級 |
|------|------|------|------|--------|
| {行} | {類型} | {問題} | {建議} | {P0-P3} |
### 命名問題
| 原名 | 問題 | 建議名稱 |
|------|------|---------|
| {原名} | {問題} | {建議} |
### 重構建議
1. **{建議標題}**
- 位置: {行號範圍}
- 問題: {問題描述}
- 方案: {重構方案}
- 預期效果: {效果描述}
### 優點
- {優點1}
- {優點2}
### 結論
- **可以合併**: {是/否/需修改後}
- **必須修改**: {列表}
- **建議修改**: {列表}
/cognitive-review {檔案路徑}
/cognitive-review pr {PR 編號}
/cognitive-review scan {目錄}
識別:函式超過 20 行
常見原因:
改善方法:
識別:超過 3 層縮排
常見原因:
改善方法:
識別:使用 data, info, value, result 等詞
常見原因:
改善方法:
識別:函式名稱是查詢,但會修改狀態
常見原因:
改善方法:
Last Updated: 2026-01-23 Version: 1.0.0
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience