diff --git a/.opencode/command/code-review-graph-project-review.md b/.opencode/command/code-review-graph-project-review.md new file mode 100644 index 0000000..eb94c75 --- /dev/null +++ b/.opencode/command/code-review-graph-project-review.md @@ -0,0 +1,42 @@ +--- +description: Whole-project or single-feature code review (not diff-based) using graph-wide analysis and objective scoring. +agent: build +--- + +# Project Review + +Review the entire codebase or a single feature/module, independent of the git diff. The scope is driven by your instruction. + +$ARGUMENTS + +**Token optimization:** Before starting, call `get_docs_section_tool(section_name="project-review")` for the optimized workflow. + +## Steps + +1. **Parse the scope** from the user instruction: + - "对项目代码进行全面审查" / "全面审查" / "整个项目" → `scope=whole-project` + - "审查 <功能/模块> 的代码" (e.g. payment, auth) → `scope=feature`, target= + +2. **Ensure the graph is current** by calling `build_or_update_graph_tool()`. + +3. **Map the architecture** by calling `get_architecture_overview_tool(detail_level="minimal")` and `list_communities_tool(detail_level="minimal")`. + +4. **Scan high-risk areas** (whole-project): `get_knowledge_gaps_tool()`, `get_hub_nodes_tool()`, `get_bridge_nodes_tool()`, `find_large_functions_tool()`, `get_surprising_connections_tool()`. + +5. **Score objectively**: + - whole-project: `score_review_tool(all_files=True)` — every source file in the graph + - feature: `semantic_search_nodes_tool(query=)` + `query_graph_tool(pattern="children_of", target=)` to locate files, then `score_review_tool(changed_files=)` + `get_impact_radius_tool(changed_files=)` + +6. **Review the code** (Layer 1 chain decomposition): eight categories + gstack CRITICAL sub-pass. Produce findings with severity (blocker/major/minor), confidence (1-10), file:line, and proposed fix. + +7. **Merge findings** by calling `dedupe_findings_tool(findings=)`. + +8. **Generate the report** by calling `generate_report_tool(review_data=)` — writes `code-review-report.html` and `code-review-report.md` (default `format="both"`). + +9. **Report** the verdict (✅ PASS / ❌ FAIL), severity counts, each issue with confidence + fix, and manual-review items. + +## Important Rules + +- **READ-ONLY.** This workflow never modifies code, commits, or pushes. Every finding waits for a manual fix decision. +- **Any blocker → verdict ❌ FAIL**, regardless of other scores. +- This is **not** a diff review. For diff-based review use `/code-review-graph-unified-review`. diff --git a/.opencode/command/code-review-graph-unified-review.md b/.opencode/command/code-review-graph-unified-review.md index ab70525..2e7f52f 100644 --- a/.opencode/command/code-review-graph-unified-review.md +++ b/.opencode/command/code-review-graph-unified-review.md @@ -27,7 +27,7 @@ $ARGUMENTS 7. **Merge findings** by calling `dedupe_findings_tool(findings=)` — fingerprint dedup, multi-source confidence boost, PR quality score. -8. **Generate the report** by calling `generate_report_tool(review_data=)` — writes `code-review-report.html`. +8. **Generate the report** by calling `generate_report_tool(review_data=)` — writes `code-review-report.html` and `code-review-report.md` (default `format="both"`). 9. **Report** the verdict (✅ PASS / ❌ FAIL), severity counts, each issue with confidence + fix, and manual-review items. diff --git a/CHANGELOG.md b/CHANGELOG.md index 530b6a9..f2ee048 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,15 @@ `dedupe_findings_tool` (fingerprint dedup, multi-source confidence boost, PR quality score), and `generate_report_tool` (standalone `code-review-report.html`). See `code_review_graph/scoring.py`. +- Added the **project-review** workflow for whole-project or single-feature + code review independent of the git diff. Scope is parsed from the user + instruction (全面/整个项目 → whole-project; otherwise feature + target + keyword). `score_review_tool` gained an `all_files` parameter that scores + every source file in the graph. Ships as a skill, an MCP prompt + (`project_review`), and the `/code-review-graph:project-review` command. +- Added a Chinese Markdown review report alongside the HTML one; + `generate_report_tool` defaults to `format="both"` writing + `code-review-report.html` + `code-review-report.md`. - Added a Voyage AI embedding provider (`--provider voyage`, key from `VOYAGE_API_KEY`, opt-in request throttling via diff --git a/CLAUDE.md b/CLAUDE.md index 5dc62dd..274c23c 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -19,7 +19,7 @@ When using code-review-graph MCP tools, follow these rules: - `custom_languages.py` — Config-driven custom language support (`.code-review-graph/languages.toml`, see docs/CUSTOM_LANGUAGES.md) - `graph.py` — SQLite-backed graph store (nodes, edges, weighted-score impact analysis) - `tools/` — 31 MCP tool implementations split by domain - - `main.py` — FastMCP server entry point, registers 31 tools + 6 prompts + - `main.py` — FastMCP server entry point, registers 31 tools + 7 prompts - `incremental.py` — Git-based change detection, file watching - `embeddings.py` — Optional vector embeddings (local sentence-transformers, OpenAI-compatible endpoints, Google Gemini, MiniMax) - `visualization.py` — D3.js interactive HTML graph generator @@ -30,7 +30,7 @@ When using code-review-graph MCP tools, follow these rules: - `changes.py` — Risk-scored change impact analysis (detect-changes) - `refactor.py` — Rename preview, dead code detection, refactoring suggestions - `hints.py` — Review hint generation - - `prompts.py` — 6 MCP prompt templates (review_changes, architecture_map, debug_issue, onboard_developer, pre_merge_check, unified_review) + - `prompts.py` — 7 MCP prompt templates (review_changes, architecture_map, debug_issue, onboard_developer, pre_merge_check, unified_review, project_review) - `wiki.py` — Markdown wiki generation from community structure - `skills.py` — Multi-platform install/config generation and shipped skill metadata - `registry.py` — Multi-repo registry helpers diff --git a/README.hi-IN.md b/README.hi-IN.md index 303b155..e4d0d10 100644 --- a/README.hi-IN.md +++ b/README.hi-IN.md @@ -253,8 +253,8 @@ code-review-graph serve # MCP सर्वर शुरू करे | `list_repos_tool` | रजिस्टर्ड रिपॉज़िटरीज़ की सूची | | `cross_repo_search_tool` | सभी रजिस्टर्ड रिपॉज़िटरीज़ में सर्च करें | -**MCP प्रॉम्प्ट्स** (6 वर्कफ़्लो टेम्प्लेट): -`review_changes`, `architecture_map`, `debug_issue`, `onboard_developer`, `pre_merge_check`, `unified_review` +**MCP प्रॉम्प्ट्स** (7 वर्कफ़्लो टेम्प्लेट): +`review_changes`, `architecture_map`, `debug_issue`, `onboard_developer`, `pre_merge_check`, `unified_review`, `project_review` diff --git a/README.ja-JP.md b/README.ja-JP.md index d036d88..f7de0cf 100644 --- a/README.ja-JP.md +++ b/README.ja-JP.md @@ -255,8 +255,8 @@ code-review-graph serve # MCPサーバーの起動 | `list_repos_tool` | 登録済みリポジトリの一覧 | | `cross_repo_search_tool` | 全登録リポジトリを横断検索 | -**MCPプロンプト**(6つのワークフローテンプレート): -`review_changes`, `architecture_map`, `debug_issue`, `onboard_developer`, `pre_merge_check`, `unified_review` +**MCPプロンプト**(7つのワークフローテンプレート): +`review_changes`, `architecture_map`, `debug_issue`, `onboard_developer`, `pre_merge_check`, `unified_review`, `project_review` diff --git a/README.ko-KR.md b/README.ko-KR.md index 62bb4c9..0748778 100644 --- a/README.ko-KR.md +++ b/README.ko-KR.md @@ -255,8 +255,8 @@ code-review-graph serve # MCP 서버 시작 | `list_repos_tool` | 등록된 저장소 목록 | | `cross_repo_search_tool` | 등록된 모든 저장소에서 검색 | -**MCP 프롬프트** (6개 워크플로 템플릿): -`review_changes`, `architecture_map`, `debug_issue`, `onboard_developer`, `pre_merge_check`, `unified_review` +**MCP 프롬프트** (7개 워크플로 템플릿): +`review_changes`, `architecture_map`, `debug_issue`, `onboard_developer`, `pre_merge_check`, `unified_review`, `project_review` diff --git a/README.md b/README.md index c755e83..5ef93ad 100644 --- a/README.md +++ b/README.md @@ -321,7 +321,7 @@ The benchmark also runs an honest **co-change mode**: the predictor is seeded wi | **Wiki generation** | Auto-generate markdown wiki from community structure | | **Multi-repo registry** | Register multiple repos, search across all of them | | **Multi-repo daemon** | `crg-daemon` watches multiple repos as child processes, with health checks and auto-restart | -| **MCP prompts** | 6 workflow templates: review, architecture, debug, onboard, pre-merge, unified-review | +| **MCP prompts** | 7 workflow templates: review, architecture, debug, onboard, pre-merge, unified-review, project-review | | **Full-text search** | FTS5-powered hybrid search combining keyword and vector similarity | | **Local storage** | SQLite file in `.code-review-graph/`. Core graph storage needs no external database or cloud service. | | **Watch mode** | Continuous graph updates as you work | @@ -501,10 +501,10 @@ Your AI assistant uses these automatically once the graph is built. | `cross_repo_search_tool` | Search across all registered repositories | | `score_review_tool` | Objective Layer-2 review metrics (good/warn/fail grades) | | `dedupe_findings_tool` | Fingerprint dedup + multi-source confidence merge | -| `generate_report_tool` | Render the standalone HTML code review report | +| `generate_report_tool` | Render the HTML and/or Markdown review report | -**MCP Prompts** (6 workflow templates): -`review_changes`, `architecture_map`, `debug_issue`, `onboard_developer`, `pre_merge_check`, `unified_review` +**MCP Prompts** (7 workflow templates): +`review_changes`, `architecture_map`, `debug_issue`, `onboard_developer`, `pre_merge_check`, `unified_review`, `project_review` diff --git a/README.zh-CN.md b/README.zh-CN.md index 84eb60f..3b8b53f 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -253,8 +253,8 @@ code-review-graph serve # 启动 MCP 服务器 | `list_repos_tool` | 列出已注册的仓库 | | `cross_repo_search_tool` | 跨所有注册仓库搜索 | -**MCP 提示模板**(6 种工作流模板): -`review_changes`、`architecture_map`、`debug_issue`、`onboard_developer`、`pre_merge_check`、`unified_review` +**MCP 提示模板**(7 种工作流模板): +`review_changes`、`architecture_map`、`debug_issue`、`onboard_developer`、`pre_merge_check`、`unified_review`、`project_review` diff --git a/code_review_graph/assets/report-template.html b/code_review_graph/assets/report-template.html index 696dadb..bd2bf45 100644 --- a/code_review_graph/assets/report-template.html +++ b/code_review_graph/assets/report-template.html @@ -1,9 +1,9 @@ - + -Code Review Report +代码审查报告 + + +
+ + + diff --git a/skills/project-review/references/review-checklist.md b/skills/project-review/references/review-checklist.md new file mode 100644 index 0000000..fdc4406 --- /dev/null +++ b/skills/project-review/references/review-checklist.md @@ -0,0 +1,82 @@ +# Unified Review — Generic Checklist + +Reference for the Layer-1 chain decomposition and gstack CRITICAL sub-pass. +Load the language-specific checklist when available (`java-spring.md`, +`python-django.md`, `python-fastapi.md`, `node-express.md`, `go-gin.md`, +`csharp-dotnet.md`, `rust.md`, `php-laravel.md`, `ruby-rails.md`); otherwise +use this generic list. + +## Layer 1 — eight categories + +For each changed area mark ✅ Clean / ⚠️ Issues Found / — N/A. + +1. **Interface** — parameter validation, response conventions, HTTP status + codes, rate limiting, API versioning, protocol correctness +2. **Business** — logic aligns with requirements, state machine correctness, + idempotency design, distributed locks +3. **Data** — SQL injection, query performance, index usage, transaction + boundaries, cache invalidation +4. **Utility** — input validity, no side effects, error return values, + date/time timezone handling +5. **Error handling** — exception classification, fallback logic, error + message sanitization, retry with backoff +6. **Security** — AuthN/AuthZ, sensitive data masking, permission control, + CSRF/XSS prevention +7. **Performance** — N+1 queries, caching strategy, connection pooling, + batch operations, blocking in async paths +8. **Observability** — structured logging with correlation IDs, metrics, + health checks + +## gstack CRITICAL sub-pass (highest severity) + +### SQL & Data Safety +- String interpolation in SQL — use parameterized queries +- TOCTOU check-then-set — use atomic `WHERE` + update +- Bypassing model validations for direct DB writes +- N+1 queries — missing eager loading + +### Race Conditions & Concurrency +- Read-check-write without uniqueness constraint / duplicate-key retry +- find-or-create without a unique DB index +- Status transitions not atomic (`WHERE old_status = ? UPDATE ...`) +- Unsafe HTML rendering on user-controlled data + +### LLM Output Trust Boundary +- LLM-generated values (emails, URLs, names) written to DB without format + validation +- Structured tool output accepted without type/shape checks +- LLM-generated URLs fetched without an allowlist (SSRF) +- LLM output stored in knowledge bases without sanitization (stored prompt + injection) + +### Shell Injection +- `subprocess` with `shell=True` AND interpolated command strings +- `os.system()` with variable interpolation +- `eval()`/`exec()` on LLM-generated code without sandboxing + +### Enum & Value Completeness +- New enum/status/tier values: read (not just grep) every consumer that + switches/filters/displays the value +- Check allowlists and `case`/`if-elsif` chains for fall-through + +## Suppressions — do NOT flag +- Harmless redundancy that aids readability +- "Add a comment explaining a threshold" — thresholds drift +- Consistency-only changes +- Anything already addressed in the diff + +## Severity +- 🔴 **blocker** — must fix before merge (injection, secrets, missing + transaction, auth bypass) → verdict FAIL +- 🟡 **major** — should fix before merge (missing validation, missing + fallback, N+1, unmasked data) +- 🔵 **minor** — can optimize later (naming, duplicate code, comments) + +## Confidence calibration +- 9-10 verified by reading specific code +- 7-8 high-confidence pattern match +- 5-6 medium — show with caveat +- 3-4 low — move to appendix +- 1-2 speculation — suppress unless severity would be P0 + +Every finding: `[SEVERITY] (confidence: N/10) file:line — problem → fix`. diff --git a/skills/project-review/references/specialists/api-contract.md b/skills/project-review/references/specialists/api-contract.md new file mode 100644 index 0000000..1c9baf4 --- /dev/null +++ b/skills/project-review/references/specialists/api-contract.md @@ -0,0 +1,13 @@ +# API Contract Specialist + +Focus: API and interface contract changes in the diff. + +- [ ] Breaking changes to public endpoints (paths, params, response shape) +- [ ] Versioning compatibility (deprecations, fallbacks) +- [ ] Request/response validation matches the schema +- [ ] Error response shape is consistent +- [ ] Authentication/authorization behavior unchanged for existing consumers +- [ ] Renamed/moved functions: all callers updated + +Output JSON lines: +`{"severity":"CRITICAL|INFORMATIONAL","confidence":N,"path":"file","line":N,"category":"api-contract","summary":"...","fix":"...","source":"api-contract"}` diff --git a/skills/project-review/references/specialists/data-migration.md b/skills/project-review/references/specialists/data-migration.md new file mode 100644 index 0000000..b70be3c --- /dev/null +++ b/skills/project-review/references/specialists/data-migration.md @@ -0,0 +1,15 @@ +# Data Migration Specialist + +Focus: database schema and data migrations in the diff. + +- [ ] Migration idempotent and re-runnable +- [ ] Forward + rollback paths defined +- [ ] Backfill batched / resumable +- [ ] Type/precision changes do not truncate data +- [ ] Nullability/default changes safe for existing rows +- [ ] Application deploy compatible with old + new schema (expand/contract) + +Insurance specialist — always runs, even when silent. + +Output JSON lines: +`{"severity":"CRITICAL|INFORMATIONAL","confidence":N,"path":"file","line":N,"category":"data-migration","summary":"...","fix":"...","source":"data-migration"}` diff --git a/skills/project-review/references/specialists/maintainability.md b/skills/project-review/references/specialists/maintainability.md new file mode 100644 index 0000000..188f9db --- /dev/null +++ b/skills/project-review/references/specialists/maintainability.md @@ -0,0 +1,16 @@ +# Maintainability Specialist + +Focus: code quality and maintainability issues. + +- [ ] Dead code / unreachable branches / unused variables +- [ ] Magic numbers → named constants +- [ ] Overcomplicated abstractions (indirection without payoff) +- [ ] Copy-paste blocks that should be shared (only when it aids clarity) +- [ ] Functions too large / doing too much +- [ ] Stale comments contradicting the code + +Suppress: harmless redundancy that aids readability, comment-on-threshold +requests, consistency-only changes. + +Output JSON lines: +`{"severity":"CRITICAL|INFORMATIONAL","confidence":N,"path":"file","line":N,"category":"maintainability","summary":"...","fix":"...","source":"maintainability"}` diff --git a/skills/project-review/references/specialists/performance.md b/skills/project-review/references/specialists/performance.md new file mode 100644 index 0000000..e95dc73 --- /dev/null +++ b/skills/project-review/references/specialists/performance.md @@ -0,0 +1,14 @@ +# Performance Specialist + +Focus: performance and resource efficiency in the diff. + +- [ ] N+1 queries — missing eager loading +- [ ] Unindexed lookups in hot loops +- [ ] O(n×m) lookups in views/loops +- [ ] Blocking calls in async paths (sync subprocess, requests, sleep) +- [ ] Connection pool exhaustion, unbounded retries +- [ ] Bundle/asset size regressions (frontend) +- [ ] Redundant recomputation / missing caching + +Output JSON lines: +`{"severity":"CRITICAL|INFORMATIONAL","confidence":N,"path":"file","line":N,"category":"performance","summary":"...","fix":"...","source":"performance"}` diff --git a/skills/project-review/references/specialists/red-team.md b/skills/project-review/references/specialists/red-team.md new file mode 100644 index 0000000..38746f8 --- /dev/null +++ b/skills/project-review/references/specialists/red-team.md @@ -0,0 +1,18 @@ +# Red Team Specialist (conditional) + +Focus: find what the primary and specialist reviewers MISSED. Only dispatched +when the diff is large (>200 lines) or a specialist found a critical issue. + +Think like an attacker and a chaos engineer: + +- [ ] Cross-cutting concerns the specialist checklists do not cover +- [ ] Integration boundary failures (service-to-service, module-to-module) +- [ ] Failure modes: what breaks in production under load, restart, partial + failure +- [ ] Silent data corruption paths (wrong results without errors) +- [ ] Error handling that swallows failures +- [ ] Trust boundary violations +- [ ] Race conditions and edge cases the primary review missed + +Be adversarial. No compliments — just the problems. Tag findings with +`"source":"red-team"`. Output `NO FINDINGS` when nothing new is found. diff --git a/skills/project-review/references/specialists/security.md b/skills/project-review/references/specialists/security.md new file mode 100644 index 0000000..429c700 --- /dev/null +++ b/skills/project-review/references/specialists/security.md @@ -0,0 +1,17 @@ +# Security Specialist + +Focus: security vulnerabilities in the diff. + +- [ ] SQL injection (string interpolation, parameterized queries) +- [ ] AuthN/AuthZ bypasses, missing permission checks +- [ ] XSS (unsafe HTML rendering on user data) +- [ ] Sensitive data exposure / missing masking in logs and responses +- [ ] SSRF (fetching user/LLM-controlled URLs without allowlist) +- [ ] Command injection (`shell=True` + interpolation) +- [ ] Hardcoded secrets / credentials +- [ ] CSRF / missing rate limiting on auth endpoints + +Insurance specialist — always runs, even when silent. + +Output JSON lines: +`{"severity":"CRITICAL|INFORMATIONAL","confidence":N,"path":"file","line":N,"category":"security","summary":"...","fix":"...","source":"security"}` diff --git a/skills/project-review/references/specialists/testing.md b/skills/project-review/references/specialists/testing.md new file mode 100644 index 0000000..e1e3c84 --- /dev/null +++ b/skills/project-review/references/specialists/testing.md @@ -0,0 +1,14 @@ +# Testing Specialist + +Focus: test coverage gaps and tests that would catch the issues found. + +- [ ] Every changed function has at least a happy-path test +- [ ] Negative/error paths tested (invalid input, failure branches) +- [ ] Edge cases mirror the happy-path structure +- [ ] If the fix for a finding can be caught by a test, propose a minimal + `test_stub` (framework-detected: jest/vitest/rspec/pytest/go-test) +- [ ] Integration coverage for critical flows (DB, external calls) +- [ ] No assertion-only tests that pass trivially + +Output JSON lines: +`{"severity":"CRITICAL|INFORMATIONAL","confidence":N,"path":"file","line":N,"category":"testing","summary":"...","fix":"...","test_stub":"...","source":"testing"}` diff --git a/skills/unified-review/SKILL.md b/skills/unified-review/SKILL.md index 3d38111..32491f5 100644 --- a/skills/unified-review/SKILL.md +++ b/skills/unified-review/SKILL.md @@ -53,7 +53,7 @@ Any 🔴 blocker → verdict `❌ FAIL` regardless of other scores. Classify eac ## Step 8 - Report -Call `generate_report_tool(review_data=)` to write `code-review-report.html`. Also present the text report inline. +Call `generate_report_tool(review_data=)` to write `code-review-report.html` and `code-review-report.md` (default `format="both"`). Also present the text report inline. ## Step 9 - Persistence (optional) diff --git a/skills/unified-review/references/report-template.html b/skills/unified-review/references/report-template.html index 696dadb..bd2bf45 100644 --- a/skills/unified-review/references/report-template.html +++ b/skills/unified-review/references/report-template.html @@ -1,9 +1,9 @@ - + -Code Review Report +代码审查报告