Skip to content

Commit 51af4fe

Browse files
committed
feat(mcp): 变更评审与代码审查增强 - 新增 review_changes/review_checklist 四轴评审工具
- review_changes: spec/convention/module_knowledge/general 四轴评审,prepare/submit 两段式 - review_checklist: 内置 Python 检查清单 + 项目覆盖 YAML - prompts: change-review prompt 追加步骤5(按清单逐条核对) - init_wiki: 模板拷贝 review_checklist.yaml 到 repowiki/ - registry: 注册 2 个新 MCP 工具 - 新增设计文档与 CodeWiki-Plus 系列文章,测试 28/28 通过
1 parent 312f3ad commit 51af4fe

20 files changed

Lines changed: 2047 additions & 413 deletions

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ htmlcov/
4040
.hypothesis/
4141
tests/*
4242
!tests/test_latest_compat.py
43+
!tests/test_review_changes.py
4344

4445
# Jupyter
4546
*.ipynb

‎codewiki/mcp/prompts.py‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,16 @@ def _prompt_change_review(args: dict[str, str]) -> str:
581581
# 模块级依赖视图
582582
list_dependencies(repo_path='{repo_path}', module_level=true)
583583
```
584+
585+
## 步骤 5: 代码评审(review_changes)
586+
调用 review_changes(mode='prepare', repo_path='{repo_path}', since=<可选,留空=未提交变更>, spec_paths=[<可选>]) 获取评审上下文包(写入 workspace)。
587+
- evidence.spec: SPEC 命中情况——逐条比对变更是否覆盖需求、有无超范围
588+
- evidence.convention: 项目规范 hits——检查变更是否违反(doctrine 为最高优先级)
589+
- evidence.module_knowledge: 历史 pitfall/lesson——检查是否重蹈覆辙
590+
- evidence.general: 通用清单——逐项过一遍
591+
四轴依据冲突时裁决顺序 spec > convention > module_knowledge > general,冲突时引用双方依据不合并。
592+
评审产出 findings 后,可选 review_changes(mode='submit', report=...) 落盘;
593+
对值得复用的发现,经用户确认后 ingest_note 沉淀(pitfall/decision)。
584594
"""
585595

586596

@@ -1367,12 +1377,14 @@ async def list_prompts() -> list:
13671377
),
13681378
Prompt(
13691379
name="change-review",
1370-
title="变更影响范围评估(修改后)",
1380+
title="变更评估与代码评审(修改后)",
13711381
description=(
1372-
"对最近代码变更(commit 范围或未提交变更)执行影响范围分析:"
1373-
"git diff 行级解析定位变更函数,传递性影响半径 + 回归测试建议。"
1382+
"对最近代码变更(commit 范围或未提交变更)执行影响范围分析与代码评审:"
1383+
"git diff 行级解析定位变更函数,传递性影响半径 + 回归测试建议;"
1384+
"再经 review_changes 按四轴(spec/convention/module_knowledge/general)"
1385+
"收集评审依据,检查变更是否正确、是否符合规范与历史教训。"
13741386
"与 impact-review 互补:impact-review 用于修改前对指定组件评估,"
1375-
"change-review 用于修改后对 diff 评估。"
1387+
"change-review 用于修改后对 diff 评估与评审。"
13761388
),
13771389
arguments=[
13781390
PromptArgument(

‎codewiki/mcp/registry.py‎

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,61 @@ def _register(schema: Tool, handler_path: str, mode: str, takes_store: bool = Tr
675675
mode="thread",
676676
)
677677

678+
_register(
679+
Tool(
680+
name="review_changes",
681+
description=(
682+
"Git-diff driven code review evidence assembly: answer 'is my change correct?' "
683+
"after editing code, against four review axes — spec (SPEC/design docs, explicit "
684+
"paths or auto-discovered under docs/specs/.scratch/openspec), convention "
685+
"(project wiki conventions + Doctrine), module_knowledge (pitfall/lesson/decision "
686+
"notes of the changed module), general (built-in engineering checklist + project "
687+
"override). Deterministic and LLM-free (Doctrine: reasoning stays with the caller): "
688+
"mode='prepare' assembles the review context package (diff + annotated changed "
689+
"sources + four-axis evidence) and writes it to the workspace; the caller agent "
690+
"reviews it and may archive the structured report with mode='submit'. "
691+
"Judgment order when axes conflict: spec > convention > module_knowledge > general. "
692+
"Same input source as analyze_changes (since range or uncommitted worktree) but "
693+
"analyze_changes answers impact, review_changes answers quality."
694+
),
695+
inputSchema={
696+
"type": "object",
697+
"properties": {
698+
"repo_path": {
699+
"type": "string",
700+
"description": "Repository path. Auto-loads from SQLite cache if a previous analysis exists.",
701+
},
702+
"mode": {
703+
"type": "string",
704+
"enum": ["prepare", "submit"],
705+
"description": "prepare (default) assembles the review context package; submit validates and archives the caller's report.",
706+
},
707+
"since": {
708+
"type": "string",
709+
"description": "Committed range: git diff <since>..HEAD (e.g. 'HEAD~1', or a commit hash). Omitted = uncommitted changes. In since mode changed sources are read from HEAD so they match the diff exactly.",
710+
},
711+
"spec_paths": {
712+
"type": "array",
713+
"items": {"type": "string"},
714+
"description": "Explicit SPEC/design doc paths (relative to repo_path or absolute). Auto-discovery runs only when no explicit path yields a readable file.",
715+
},
716+
"focus": {
717+
"type": "string",
718+
"enum": ["all", "spec", "convention", "module_knowledge", "general"],
719+
"description": "Restrict evidence assembly to one axis (default: all).",
720+
},
721+
"report": {
722+
"type": "object",
723+
"description": "Submit only: the review report {title, findings: [{id, axis, severity, file, line, title, evidence, suggestion, rule_ref}], summary}.",
724+
},
725+
},
726+
"required": ["repo_path"],
727+
},
728+
),
729+
handler_path="codewiki.mcp.tools.review_changes:handle_review_changes",
730+
mode="thread",
731+
)
732+
678733
_register(
679734
Tool(
680735
name="watch_repo",
@@ -1975,7 +2030,9 @@ def _register(schema: Tool, handler_path: str, mode: str, takes_store: bool = Tr
19752030
"Initialize a Wiki workspace for a project (zero-config bootstrap). "
19762031
"Creates the output directory structure (wiki/modules, wiki/entities, "
19772032
"wiki/concepts, wiki/sources, wiki/comparisons, wiki/queries, notes/), "
1978-
"copies the annotated schema.yaml template (preserving comments), and "
2033+
"copies the annotated schema.yaml template (preserving comments), "
2034+
"the ontology.yaml template and the review_checklist.yaml override "
2035+
"template (both skipped when already present), and "
19792036
"injects wiki usage instructions + self-reflection protocols into the "
19802037
"project's AGENTS.md. Run this ONCE before starting any wiki generation "
19812038
"or knowledge ingestion workflow. Idempotent: safe to re-run — existing "

‎codewiki/mcp/tools/init_wiki.py‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
_ONTOLOGY_TEMPLATE_PKG = Path(__file__).resolve().parents[2] / "templates" / "ontology.yaml"
2626
_ONTOLOGY_TEMPLATE = _ONTOLOGY_TEMPLATE_PKG if _ONTOLOGY_TEMPLATE_PKG.exists() else None
2727

28+
# Review checklist override template: project-level merge layer for review_changes
29+
_REVIEW_CHECKLIST_TEMPLATE_PKG = Path(__file__).resolve().parents[2] / "templates" / "review_checklist.yaml"
30+
_REVIEW_CHECKLIST_TEMPLATE = _REVIEW_CHECKLIST_TEMPLATE_PKG if _REVIEW_CHECKLIST_TEMPLATE_PKG.exists() else None
31+
2832
# Subdirectories to create under output_dir
2933
_WIKI_SUBDIRS = [
3034
"wiki/modules",
@@ -84,6 +88,7 @@ def handle_init_wiki(arguments: dict) -> str:
8488
"created_dirs": [],
8589
"schema_yaml": None,
8690
"ontology_yaml": None,
91+
"review_checklist_yaml": None,
8792
"agents_md": None,
8893
}
8994

@@ -121,6 +126,17 @@ def handle_init_wiki(arguments: dict) -> str:
121126
else:
122127
results["ontology_yaml"] = str(onto_dest) + " (already exists, skipped)"
123128

129+
# ── Step 2c: Copy review_checklist.yaml (review_changes override) ────
130+
# Skip when present: users customize this file, init must not clobber it.
131+
if _REVIEW_CHECKLIST_TEMPLATE and _REVIEW_CHECKLIST_TEMPLATE.exists():
132+
checklist_dest = output_dir_p / "review_checklist.yaml"
133+
if not checklist_dest.exists():
134+
shutil.copy2(str(_REVIEW_CHECKLIST_TEMPLATE), str(checklist_dest))
135+
results["review_checklist_yaml"] = str(checklist_dest)
136+
logger.info("Copied review_checklist.yaml template to %s", checklist_dest)
137+
else:
138+
results["review_checklist_yaml"] = str(checklist_dest) + " (already exists, skipped)"
139+
124140
# ── Step 3: Write AGENTS.md ─────────────────────────────────────────
125141
try:
126142
from codewiki.mcp.tools.agents_md import write_agents_md
@@ -142,7 +158,9 @@ def handle_init_wiki(arguments: dict) -> str:
142158
"Wiki workspace initialized. Next: "
143159
"1) Edit schema.yaml to set 'purpose' and adjust conventions; "
144160
"2) Edit ontology.yaml to define project terms and aliases for search; "
145-
"3) Run analyze_repo to parse code and generate docs; "
146-
"4) Or use ingest_note/query_wiki for knowledge management."
161+
"3) Optionally edit review_checklist.yaml to add team review rules "
162+
"(merged into review_changes, same id overrides builtin); "
163+
"4) Run analyze_repo to parse code and generate docs; "
164+
"5) Or use ingest_note/query_wiki for knowledge management."
147165
)
148166
return json.dumps(results, ensure_ascii=False, indent=2)

0 commit comments

Comments
 (0)