Skip to content

Commit bbba16d

Browse files
committed
merge: 解决 develop 冲突——移除 tests/* 忽略及两个例外
develop 在 merge-base 后新增 !tests/test_review_changes.py 例外(依附于 tests/* 规则)。按 PR #16 意图(stop ignoring tests/),tests 规则与 两个例外一并删除,tests/ 下所有文件均被 git 跟踪。
2 parents 50d55de + 644ee24 commit bbba16d

23 files changed

Lines changed: 2440 additions & 410 deletions

‎CONTEXT.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ memories,生命周期挂在任务上:一条任务记忆无论多老都只对
1818
**memory archive** — 被压缩条目的原文存放地(memories-archive.md,append-only)。永不
1919
进入任何自动加载路径,仅供人查证或压缩返工时回溯。
2020

21+
**review axes** — review_changes 代码审查的四类评审依据的规范短名,focus 枚举、上下文包
22+
evidence 键、报告 axis 字段三处统一使用:`spec`(SPEC/设计文档)、`convention`(项目
23+
Wiki 规范 + Doctrine)、`module_knowledge`(模块历史笔记)、`general`(内置通用
24+
checklist)。评审对象 = 同一次 git 变更(since 或未提交),工具只做确定性收集与落盘,
25+
推理外置给调用方 Agent(Doctrine 约束)。
26+
2127
**frontmatter module** — the deep module at `codewiki/src/frontmatter.py` that owns
2228
repowiki page frontmatter read/write (`parse_frontmatter` / `render_frontmatter` /
2329
`update`) and page-type routing (`route_page_type`, backed by `PAGE_TYPE_DIRS`).

‎codewiki/mcp/prompts.py‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,59 @@ def _prompt_impact_review(args: dict[str, str]) -> str:
541541
使用 get_prompt(prompt_type="impact_review") 获取更详细的解读指南。"""
542542

543543

544+
def _prompt_change_review(args: dict[str, str]) -> str:
545+
repo_path = _resolve_path(args.get("repo_path", ""))
546+
since = args.get("since", "")
547+
if since:
548+
mode_call = f"analyze_changes(repo_path='{repo_path}', since='{since}')"
549+
mode_desc = f"已提交范围 `{since}..HEAD`(git diff 行级解析)"
550+
else:
551+
mode_call = f"analyze_changes(repo_path='{repo_path}', worktree=true)"
552+
mode_desc = "未提交变更(暂存 + 未暂存 + 新增文件)"
553+
return f"""请对最近代码变更做影响范围评估(修改后分析)。按以下步骤执行:
554+
555+
## 步骤 1: 确定变更范围
556+
- 本次分析模式:{mode_desc}
557+
- 调用 {mode_call}
558+
- 该工具从 SQLite 缓存自动加载依赖图谱,无需先跑 analyze_repo
559+
- 需要其他遍历方向时加 direction='depends_on' / 'both',限制深度加 max_depth=<N>
560+
561+
## 步骤 2: 理解分析结果
562+
- changed_components: 变更行命中的函数/类(行级 diff 定位,不是整个文件)
563+
- affected_components: 传递性影响的所有组件(含调用链与深度)
564+
- suggested_tests: 按命名约定建议的回归测试文件
565+
- summary: total_affected / changed_files / changed_components / source 规模概览
566+
- 边界情况(不是错误):
567+
- file_level_changes: 变更行落在组件外(如 import/装饰器),退化为文件级
568+
- deleted_unlocated: 被删除的函数(按旧版本解析定位)
569+
- untracked_files: 新增未跟踪文件不在图谱内,需先 analyze_repo 增量纳入
570+
571+
## 步骤 3: 回归测试计划
572+
- 对 suggested_tests 中实际存在的测试文件,明确建议运行
573+
- 对 affected_components 中高风险组件(5+ 直接依赖者)建议补充回归测试
574+
- 受影响组件分布在 3+ 模块时,提示需要集成测试
575+
576+
## 步骤 4: 深挖(可选)
577+
```
578+
# 对某个受影响组件做修改前式细查(看谁调用它)
579+
analyze_impact(repo_path='{repo_path}', component_ids=['<affected_id>'], direction='depended_by')
580+
581+
# 模块级依赖视图
582+
list_dependencies(repo_path='{repo_path}', module_level=true)
583+
```
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)。
594+
"""
595+
596+
544597
def _prompt_architecture_review(args: dict[str, str]) -> str:
545598
repo_path = _resolve_path(args.get("repo_path", ""))
546599
return f"""请通过依赖图分析代码库的高层架构。按以下步骤执行:
@@ -1322,6 +1375,30 @@ async def list_prompts() -> list:
13221375
),
13231376
],
13241377
),
1378+
Prompt(
1379+
name="change-review",
1380+
title="变更评估与代码评审(修改后)",
1381+
description=(
1382+
"对最近代码变更(commit 范围或未提交变更)执行影响范围分析与代码评审:"
1383+
"git diff 行级解析定位变更函数,传递性影响半径 + 回归测试建议;"
1384+
"再经 review_changes 按四轴(spec/convention/module_knowledge/general)"
1385+
"收集评审依据,检查变更是否正确、是否符合规范与历史教训。"
1386+
"与 impact-review 互补:impact-review 用于修改前对指定组件评估,"
1387+
"change-review 用于修改后对 diff 评估与评审。"
1388+
),
1389+
arguments=[
1390+
PromptArgument(
1391+
name="repo_path",
1392+
description="代码仓库路径(须已执行过 analyze_repo 或 code-analysis)",
1393+
required=False,
1394+
),
1395+
PromptArgument(
1396+
name="since",
1397+
description="已提交范围 git diff <since>..HEAD(如 HEAD~1 或 commit hash);留空默认分析未提交变更(worktree)",
1398+
required=False,
1399+
),
1400+
],
1401+
),
13251402
Prompt(
13261403
name="architecture-review",
13271404
title="架构审查与热点分析",
@@ -1511,6 +1588,7 @@ async def get_prompt(name: str, arguments: dict[str, str] | None) -> Any:
15111588
"quality-check": _prompt_quality_check,
15121589
"code-analysis": _prompt_code_analysis,
15131590
"impact-review": _prompt_impact_review,
1591+
"change-review": _prompt_change_review,
15141592
"architecture-review": _prompt_architecture_review,
15151593
"workspace-analysis": _prompt_workspace_analysis,
15161594
"cross-service-trace": _prompt_cross_service_trace,

‎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)