codewiki-plus 5.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. codewiki_plus-5.1.0/PKG-INFO +887 -0
  2. codewiki_plus-5.1.0/README.md +822 -0
  3. codewiki_plus-5.1.0/codewiki/__init__.py +13 -0
  4. codewiki_plus-5.1.0/codewiki/__main__.py +8 -0
  5. codewiki_plus-5.1.0/codewiki/cli/__init__.py +4 -0
  6. codewiki_plus-5.1.0/codewiki/cli/adapters/__init__.py +4 -0
  7. codewiki_plus-5.1.0/codewiki/cli/adapters/doc_generator.py +351 -0
  8. codewiki_plus-5.1.0/codewiki/cli/commands/__init__.py +4 -0
  9. codewiki_plus-5.1.0/codewiki/cli/commands/config.py +845 -0
  10. codewiki_plus-5.1.0/codewiki/cli/commands/generate.py +608 -0
  11. codewiki_plus-5.1.0/codewiki/cli/config_manager.py +333 -0
  12. codewiki_plus-5.1.0/codewiki/cli/git_manager.py +227 -0
  13. codewiki_plus-5.1.0/codewiki/cli/html_generator.py +286 -0
  14. codewiki_plus-5.1.0/codewiki/cli/main.py +78 -0
  15. codewiki_plus-5.1.0/codewiki/cli/models/__init__.py +4 -0
  16. codewiki_plus-5.1.0/codewiki/cli/models/config.py +280 -0
  17. codewiki_plus-5.1.0/codewiki/cli/models/job.py +156 -0
  18. codewiki_plus-5.1.0/codewiki/cli/utils/__init__.py +4 -0
  19. codewiki_plus-5.1.0/codewiki/cli/utils/api_errors.py +140 -0
  20. codewiki_plus-5.1.0/codewiki/cli/utils/errors.py +113 -0
  21. codewiki_plus-5.1.0/codewiki/cli/utils/fs.py +190 -0
  22. codewiki_plus-5.1.0/codewiki/cli/utils/instructions.py +179 -0
  23. codewiki_plus-5.1.0/codewiki/cli/utils/logging.py +85 -0
  24. codewiki_plus-5.1.0/codewiki/cli/utils/progress.py +222 -0
  25. codewiki_plus-5.1.0/codewiki/cli/utils/repo_validator.py +210 -0
  26. codewiki_plus-5.1.0/codewiki/cli/utils/validation.py +251 -0
  27. codewiki_plus-5.1.0/codewiki/mcp/__init__.py +6 -0
  28. codewiki_plus-5.1.0/codewiki/mcp/cache.py +1419 -0
  29. codewiki_plus-5.1.0/codewiki/mcp/cbm_client.py +356 -0
  30. codewiki_plus-5.1.0/codewiki/mcp/prompts.py +862 -0
  31. codewiki_plus-5.1.0/codewiki/mcp/registry.py +1463 -0
  32. codewiki_plus-5.1.0/codewiki/mcp/resources.py +266 -0
  33. codewiki_plus-5.1.0/codewiki/mcp/server.py +178 -0
  34. codewiki_plus-5.1.0/codewiki/mcp/session.py +197 -0
  35. codewiki_plus-5.1.0/codewiki/mcp/tools/__init__.py +6 -0
  36. codewiki_plus-5.1.0/codewiki/mcp/tools/agents_md.py +290 -0
  37. codewiki_plus-5.1.0/codewiki/mcp/tools/analysis.py +908 -0
  38. codewiki_plus-5.1.0/codewiki/mcp/tools/batch_ingest.py +135 -0
  39. codewiki_plus-5.1.0/codewiki/mcp/tools/cbm_integration.py +210 -0
  40. codewiki_plus-5.1.0/codewiki/mcp/tools/close_session.py +211 -0
  41. codewiki_plus-5.1.0/codewiki/mcp/tools/code_reader.py +72 -0
  42. codewiki_plus-5.1.0/codewiki/mcp/tools/component_list.py +161 -0
  43. codewiki_plus-5.1.0/codewiki/mcp/tools/cross_service.py +155 -0
  44. codewiki_plus-5.1.0/codewiki/mcp/tools/crosslink.py +222 -0
  45. codewiki_plus-5.1.0/codewiki/mcp/tools/doc_writer.py +1065 -0
  46. codewiki_plus-5.1.0/codewiki/mcp/tools/file_param.py +58 -0
  47. codewiki_plus-5.1.0/codewiki/mcp/tools/file_viewer.py +138 -0
  48. codewiki_plus-5.1.0/codewiki/mcp/tools/html_export.py +197 -0
  49. codewiki_plus-5.1.0/codewiki/mcp/tools/impact.py +244 -0
  50. codewiki_plus-5.1.0/codewiki/mcp/tools/issue_tracker.py +149 -0
  51. codewiki_plus-5.1.0/codewiki/mcp/tools/knowledge_loop.py +1211 -0
  52. codewiki_plus-5.1.0/codewiki/mcp/tools/legacy_tools.py +205 -0
  53. codewiki_plus-5.1.0/codewiki/mcp/tools/module_tree.py +194 -0
  54. codewiki_plus-5.1.0/codewiki/mcp/tools/page_router.py +292 -0
  55. codewiki_plus-5.1.0/codewiki/mcp/tools/prompt_server.py +905 -0
  56. codewiki_plus-5.1.0/codewiki/mcp/tools/reading_guide.py +130 -0
  57. codewiki_plus-5.1.0/codewiki/mcp/tools/schema_generator.py +330 -0
  58. codewiki_plus-5.1.0/codewiki/mcp/tools/source_ingest.py +350 -0
  59. codewiki_plus-5.1.0/codewiki/mcp/tools/wiki_index.py +405 -0
  60. codewiki_plus-5.1.0/codewiki/mcp/tools/wiki_lint.py +1002 -0
  61. codewiki_plus-5.1.0/codewiki/mcp/tools/wiki_search.py +338 -0
  62. codewiki_plus-5.1.0/codewiki/mcp/tools/workspace_analyzer.py +351 -0
  63. codewiki_plus-5.1.0/codewiki/mcp/tools/workspace_result.py +109 -0
  64. codewiki_plus-5.1.0/codewiki/mcp/workspace.py +151 -0
  65. codewiki_plus-5.1.0/codewiki/py.typed +2 -0
  66. codewiki_plus-5.1.0/codewiki/run_web_app.py +16 -0
  67. codewiki_plus-5.1.0/codewiki/src/__init__.py +2 -0
  68. codewiki_plus-5.1.0/codewiki/src/be/__init__.py +2 -0
  69. codewiki_plus-5.1.0/codewiki/src/be/agent_tools/__init__.py +2 -0
  70. codewiki_plus-5.1.0/codewiki/src/be/agent_tools/deps.py +17 -0
  71. codewiki_plus-5.1.0/codewiki/src/be/agent_tools/generate_sub_module_documentations.py +98 -0
  72. codewiki_plus-5.1.0/codewiki/src/be/agent_tools/read_code_components.py +22 -0
  73. codewiki_plus-5.1.0/codewiki/src/be/agent_tools/str_replace_editor.py +815 -0
  74. codewiki_plus-5.1.0/codewiki/src/be/backend.py +67 -0
  75. codewiki_plus-5.1.0/codewiki/src/be/caw_backend.py +325 -0
  76. codewiki_plus-5.1.0/codewiki/src/be/caw_toolkit.py +316 -0
  77. codewiki_plus-5.1.0/codewiki/src/be/cluster_modules.py +191 -0
  78. codewiki_plus-5.1.0/codewiki/src/be/dependency_analyzer/__init__.py +21 -0
  79. codewiki_plus-5.1.0/codewiki/src/be/dependency_analyzer/analysis/__init__.py +1 -0
  80. codewiki_plus-5.1.0/codewiki/src/be/dependency_analyzer/analysis/analysis_service.py +371 -0
  81. codewiki_plus-5.1.0/codewiki/src/be/dependency_analyzer/analysis/call_graph_analyzer.py +869 -0
  82. codewiki_plus-5.1.0/codewiki/src/be/dependency_analyzer/analysis/cloning.py +259 -0
  83. codewiki_plus-5.1.0/codewiki/src/be/dependency_analyzer/analysis/cross_service_matcher.py +241 -0
  84. codewiki_plus-5.1.0/codewiki/src/be/dependency_analyzer/analysis/infra_scanner.py +240 -0
  85. codewiki_plus-5.1.0/codewiki/src/be/dependency_analyzer/analysis/repo_analyzer.py +128 -0
  86. codewiki_plus-5.1.0/codewiki/src/be/dependency_analyzer/analysis/service_detector.py +581 -0
  87. codewiki_plus-5.1.0/codewiki/src/be/dependency_analyzer/analysis/topology_visualizer.py +123 -0
  88. codewiki_plus-5.1.0/codewiki/src/be/dependency_analyzer/analyzers/__init__.py +1 -0
  89. codewiki_plus-5.1.0/codewiki/src/be/dependency_analyzer/analyzers/c.py +215 -0
  90. codewiki_plus-5.1.0/codewiki/src/be/dependency_analyzer/analyzers/cpp.py +676 -0
  91. codewiki_plus-5.1.0/codewiki/src/be/dependency_analyzer/analyzers/csharp.py +297 -0
  92. codewiki_plus-5.1.0/codewiki/src/be/dependency_analyzer/analyzers/go.py +557 -0
  93. codewiki_plus-5.1.0/codewiki/src/be/dependency_analyzer/analyzers/java.py +538 -0
  94. codewiki_plus-5.1.0/codewiki/src/be/dependency_analyzer/analyzers/javascript.py +705 -0
  95. codewiki_plus-5.1.0/codewiki/src/be/dependency_analyzer/analyzers/kotlin.py +505 -0
  96. codewiki_plus-5.1.0/codewiki/src/be/dependency_analyzer/analyzers/php.py +598 -0
  97. codewiki_plus-5.1.0/codewiki/src/be/dependency_analyzer/analyzers/python.py +266 -0
  98. codewiki_plus-5.1.0/codewiki/src/be/dependency_analyzer/analyzers/typescript.py +981 -0
  99. codewiki_plus-5.1.0/codewiki/src/be/dependency_analyzer/ast_parser.py +177 -0
  100. codewiki_plus-5.1.0/codewiki/src/be/dependency_analyzer/dependency_graphs_builder.py +108 -0
  101. codewiki_plus-5.1.0/codewiki/src/be/dependency_analyzer/models/__init__.py +1 -0
  102. codewiki_plus-5.1.0/codewiki/src/be/dependency_analyzer/models/analysis.py +23 -0
  103. codewiki_plus-5.1.0/codewiki/src/be/dependency_analyzer/models/core.py +67 -0
  104. codewiki_plus-5.1.0/codewiki/src/be/dependency_analyzer/models/cross_service.py +64 -0
  105. codewiki_plus-5.1.0/codewiki/src/be/dependency_analyzer/topo_sort.py +597 -0
  106. codewiki_plus-5.1.0/codewiki/src/be/dependency_analyzer/utils/__init__.py +1 -0
  107. codewiki_plus-5.1.0/codewiki/src/be/dependency_analyzer/utils/external_symbols.py +393 -0
  108. codewiki_plus-5.1.0/codewiki/src/be/dependency_analyzer/utils/logging_config.py +143 -0
  109. codewiki_plus-5.1.0/codewiki/src/be/dependency_analyzer/utils/path_canonicalizer.py +61 -0
  110. codewiki_plus-5.1.0/codewiki/src/be/dependency_analyzer/utils/patterns.py +694 -0
  111. codewiki_plus-5.1.0/codewiki/src/be/dependency_analyzer/utils/security.py +83 -0
  112. codewiki_plus-5.1.0/codewiki/src/be/documentation_generator.py +383 -0
  113. codewiki_plus-5.1.0/codewiki/src/be/llm_services.py +290 -0
  114. codewiki_plus-5.1.0/codewiki/src/be/main.py +66 -0
  115. codewiki_plus-5.1.0/codewiki/src/be/prompt_template.py +670 -0
  116. codewiki_plus-5.1.0/codewiki/src/be/pydantic_ai_backend.py +128 -0
  117. codewiki_plus-5.1.0/codewiki/src/be/utils.py +281 -0
  118. codewiki_plus-5.1.0/codewiki/src/config.py +271 -0
  119. codewiki_plus-5.1.0/codewiki/src/fe/__init__.py +26 -0
  120. codewiki_plus-5.1.0/codewiki/src/fe/background_worker.py +256 -0
  121. codewiki_plus-5.1.0/codewiki/src/fe/cache_manager.py +119 -0
  122. codewiki_plus-5.1.0/codewiki/src/fe/config.py +51 -0
  123. codewiki_plus-5.1.0/codewiki/src/fe/github_processor.py +93 -0
  124. codewiki_plus-5.1.0/codewiki/src/fe/models.py +55 -0
  125. codewiki_plus-5.1.0/codewiki/src/fe/routes.py +300 -0
  126. codewiki_plus-5.1.0/codewiki/src/fe/template_utils.py +114 -0
  127. codewiki_plus-5.1.0/codewiki/src/fe/templates.py +680 -0
  128. codewiki_plus-5.1.0/codewiki/src/fe/visualise_docs.py +269 -0
  129. codewiki_plus-5.1.0/codewiki/src/fe/web_app.py +133 -0
  130. codewiki_plus-5.1.0/codewiki/src/utils.py +46 -0
  131. codewiki_plus-5.1.0/codewiki/templates/github_pages/viewer_template.html +643 -0
  132. codewiki_plus-5.1.0/codewiki_plus.egg-info/PKG-INFO +887 -0
  133. codewiki_plus-5.1.0/codewiki_plus.egg-info/SOURCES.txt +137 -0
  134. codewiki_plus-5.1.0/codewiki_plus.egg-info/dependency_links.txt +1 -0
  135. codewiki_plus-5.1.0/codewiki_plus.egg-info/entry_points.txt +2 -0
  136. codewiki_plus-5.1.0/codewiki_plus.egg-info/requires.txt +45 -0
  137. codewiki_plus-5.1.0/codewiki_plus.egg-info/top_level.txt +1 -0
  138. codewiki_plus-5.1.0/pyproject.toml +136 -0
  139. codewiki_plus-5.1.0/setup.cfg +4 -0
@@ -0,0 +1,887 @@
1
+ Metadata-Version: 2.4
2
+ Name: codewiki-plus
3
+ Version: 5.1.0
4
+ Summary: Transform codebases into comprehensive documentation using AI-powered analysis
5
+ Author: CodeWiki Contributors
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/mambo-wang/CodeWiki-Plus
8
+ Project-URL: Documentation, https://github.com/mambo-wang/CodeWiki-Plus/blob/main/README.md
9
+ Project-URL: Repository, https://github.com/mambo-wang/CodeWiki-Plus
10
+ Project-URL: Issues, https://github.com/mambo-wang/CodeWiki-Plus/issues
11
+ Keywords: documentation,code-analysis,ai,llm,developer-tools,mcp
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Topic :: Software Development :: Documentation
18
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
+ Requires-Python: >=3.12
20
+ Description-Content-Type: text/markdown
21
+ Requires-Dist: click>=8.1.0
22
+ Requires-Dist: keyring>=24.0.0
23
+ Requires-Dist: GitPython>=3.1.40
24
+ Requires-Dist: Jinja2>=3.1.6
25
+ Requires-Dist: tree-sitter>=0.23.2
26
+ Requires-Dist: tree-sitter-language-pack>=0.8.0
27
+ Requires-Dist: tree-sitter-python>=0.23.6
28
+ Requires-Dist: tree-sitter-java>=0.23.5
29
+ Requires-Dist: tree-sitter-javascript>=0.21.4
30
+ Requires-Dist: tree-sitter-typescript>=0.21.2
31
+ Requires-Dist: tree-sitter-c>=0.21.4
32
+ Requires-Dist: tree-sitter-cpp>=0.23.4
33
+ Requires-Dist: tree-sitter-c-sharp>=0.23.1
34
+ Requires-Dist: tree-sitter-php>=0.23.0
35
+ Requires-Dist: tree-sitter-kotlin>=1.1.0
36
+ Requires-Dist: tree-sitter-go>=0.23.0
37
+ Requires-Dist: openai>=1.107.0
38
+ Requires-Dist: litellm>=1.77.0
39
+ Requires-Dist: pydantic>=2.11.7
40
+ Requires-Dist: pydantic-settings>=2.10.1
41
+ Requires-Dist: pydantic-ai>=1.0.6
42
+ Requires-Dist: requests>=2.32.4
43
+ Requires-Dist: python-dotenv>=1.1.1
44
+ Requires-Dist: rich>=14.1.0
45
+ Requires-Dist: networkx>=3.5
46
+ Requires-Dist: psutil>=7.0.0
47
+ Requires-Dist: PyYAML>=6.0.2
48
+ Requires-Dist: mermaid-parser-py>=0.0.2
49
+ Requires-Dist: mermaid-py>=0.8.0
50
+ Requires-Dist: fastapi>=0.116.0
51
+ Requires-Dist: uvicorn>=0.35.0
52
+ Requires-Dist: python-multipart>=0.0.20
53
+ Requires-Dist: colorama>=0.4.6
54
+ Requires-Dist: logfire>=4.1.0
55
+ Requires-Dist: coding-agent-wrapper>=0.1.2
56
+ Requires-Dist: mcp>=1.0.0
57
+ Requires-Dist: jieba>=0.42.1
58
+ Provides-Extra: dev
59
+ Requires-Dist: pytest>=7.4.0; extra == "dev"
60
+ Requires-Dist: pytest-cov>=4.1.0; extra == "dev"
61
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
62
+ Requires-Dist: black>=23.0.0; extra == "dev"
63
+ Requires-Dist: mypy>=1.5.0; extra == "dev"
64
+ Requires-Dist: ruff>=0.1.0; extra == "dev"
65
+
66
+ <p align="center">
67
+ <img src="img/logo-banner.png" alt="CodeWiki-Plus" width="700" />
68
+ </p>
69
+
70
+ <h1 align="center">CodeWiki-Plus</h1>
71
+
72
+ <p align="center">
73
+ <strong>用 AI IDE 驱动的代码仓库文档生成与知识管理工具</strong><br>
74
+ <strong>AI IDE-Driven Code Documentation Generator & Knowledge Engine</strong>
75
+ </p>
76
+
77
+ <p align="center">
78
+ <a href="https://python.org/"><img alt="Python version" src="https://img.shields.io/badge/python-3.12+-blue?style=flat-square" /></a>
79
+ <a href="./LICENSE"><img alt="License: MIT" src="https://img.shields.io/badge/License-MIT-green.svg?style=flat-square" /></a>
80
+ <a href="https://github.com/FSoft-AI4Code/CodeWiki"><img alt="Upstream: CodeWiki" src="https://img.shields.io/badge/upstream-FSoft--AI4Code%2FCodeWiki-orange?style=flat-square" /></a>
81
+ </p>
82
+
83
+ <p align="center">
84
+ <a href="#zh"><strong>中文</strong></a> | <a href="#en"><strong>English</strong></a>
85
+ </p>
86
+
87
+ ---
88
+
89
+ <a id="zh"></a>
90
+
91
+ ## 中文
92
+
93
+ ### 这个项目是什么?
94
+
95
+ CodeWiki-Plus 是 [FSoft-AI4Code/CodeWiki](https://github.com/FSoft-AI4Code/CodeWiki) 的增强分支,核心改动是**让 CodeWiki 无需配置任何大模型 API,直接由 AI IDE(CodeBuddy、Cursor、Claude Desktop 等)自身的模型驱动 Wiki 文档生成**,并在此基础上构建了完整的知识管理引擎。
96
+
97
+ ### 为什么要做这个改造?
98
+
99
+ 原版 CodeWiki 是一个非常优秀的仓库级文档生成框架,它通过 Tree-sitter AST 解析、依赖图构建、拓扑排序等工具链实现高质量的代码文档生成。但它有一个使用门槛:**必须自行配置 LLM API**(申请 API Key、选择 provider、处理模型兼容性),且整个生成过程是黑盒的,用户无法中途干预。
100
+
101
+ 实际上,CodeWiki 的核心工具链——AST 解析、依赖图、Mermaid 校验——完全不需要 LLM。真正需要 LLM 智能的 4 个环节(模块聚类、文档撰写、子模块递归、总览合成),恰好是 AI IDE 的 Agent 最擅长做的事情。
102
+
103
+ 因此,我们将 CodeWiki 的 MCP Server 从"黑盒式一键生成"拆分为**23 个细粒度工具**,让它退化为纯工具链服务器。AI IDE 的 Agent 通过 MCP 协议调用这些工具,用自己的推理能力完成全部文档生成工作:
104
+
105
+ ```
106
+ 改造前:
107
+ IDE → generate_docs(repo) → [CodeWiki 内部调用 LLM API] → 结果
108
+
109
+ 改造后:
110
+ IDE Agent → analyze_repo → read_code → (Agent 自己推理) → write_doc → overview
111
+ ↑ 纯工具 ↑ 纯工具 ↑ IDE 自身模型 ↑ 纯工具
112
+ ```
113
+
114
+ ### 相比原版 CodeWiki 的增强
115
+
116
+ | 能力维度 | 原版 CodeWiki | CodeWiki-Plus |
117
+ |----------|--------------|---------------|
118
+ | LLM 配置 | 必须自行配置 API Key | 零配置,IDE 自身模型驱动 |
119
+ | 生成模式 | 黑盒一键生成 | 23 个细粒度工具,Agent 全程可控 |
120
+ | 文档质量 | 通用描述 | Evidence-Based 断言(代码引用 + 置信度) |
121
+ | 生成效率 | 所有组件同等处理 | 代码路由分类,boilerplate 仅保留签名 |
122
+ | 上下文精度 | 模块内组件 | BFS 1-hop 调用图扩展 + 约束索引表 |
123
+ | 增量更新 | 文件级 Git diff | 方法级 content_hash 精确检测 |
124
+ | 知识管理 | 无 | 结构化 Wiki + 笔记飞轮 + 外部文档管理 |
125
+ | 搜索能力 | 无 | BM25 + wikilink 图谱多跳 + 渐进式阅读 |
126
+ | 跨服务分析 | 无 | Monorepo 子服务检测 + 跨服务调用追踪 |
127
+ | 质量保障 | 无 | 11 项 lint 检查 + health score + 问题追踪 |
128
+
129
+ ### 前置条件
130
+
131
+ - **Python 3.12+**
132
+ - **Node.js**(用于 Mermaid 图表校验,不安装则图表校验会静默跳过)
133
+ - 一个支持 MCP 的 AI IDE(CodeBuddy、Cursor、Claude Desktop 等)
134
+
135
+ ### 快速开始(以 CodeBuddy 为例)
136
+
137
+ 整个过程只需 3 步,不需要任何 API Key。
138
+
139
+ **第 1 步:安装 CodeWiki-Plus**
140
+
141
+ ```bash
142
+ git clone https://github.com/mambo-wang/CodeWiki-Plus.git
143
+ cd CodeWiki-Plus
144
+ pip install -e .
145
+ ```
146
+
147
+ 验证安装:
148
+
149
+ ```bash
150
+ python -c "from codewiki.mcp.server import server; print('MCP Server OK')"
151
+ ```
152
+
153
+ **第 2 步:配置 MCP Server**
154
+
155
+ 在 CodeBuddy 的 MCP 设置中添加以下配置(通常在设置界面的"工具"或"MCP"板块):
156
+
157
+ ```json
158
+ {
159
+ "mcpServers": {
160
+ "codewiki": {
161
+ "command": "python",
162
+ "args": ["-m", "codewiki.mcp.server"],
163
+ "timeout": 36000000
164
+ }
165
+ }
166
+ }
167
+ ```
168
+
169
+ 配置完成后,CodeBuddy 的 MCP 工具列表中应出现 `codewiki` 相关的 23 个工具。
170
+
171
+ **第 3 步:在 Agent 模式中输入提示词**
172
+
173
+ 打开 CodeBuddy 的 Agent 模式,用 CodeBuddy 打开你要生成文档的目标项目,然后输入:
174
+
175
+ ```
176
+ 帮我分析当前仓库并生成 Wiki 文档,输出到 repowiki 目录。请使用中文撰写文档。
177
+ ```
178
+
179
+ Agent 会自动按照以下流程工作:
180
+
181
+ ```
182
+ 阶段 1: 调用 analyze_repo → 得到组件索引、叶节点列表
183
+ (自动检测 monorepo 子服务,构建跨服务调用关系)
184
+
185
+ 阶段 2: 调用 get_prompt("cluster") 获取聚类规则
186
+ 调用 read_code_components 阅读源码
187
+ 自主推理,将组件分组为 3-8 个逻辑模块
188
+ 调用 save_module_tree 保存聚类结果
189
+
190
+ 阶段 3: 按叶优先顺序逐模块生成文档
191
+ 每个叶模块:read_code → 分析推理 → write_doc_file
192
+ (prompt 自动注入 BFS 调用上下文 + 约束索引表 + 业务规则提取指令)
193
+ 每个父模块:读取子文档 → 合成总览 → write_doc_file
194
+
195
+ 阶段 4: 生成仓库总览 overview.md
196
+
197
+ 阶段 5: 调用 close_session 释放资源,构建搜索索引
198
+ ```
199
+
200
+ 生成的文档结构:
201
+
202
+ ```
203
+ repowiki/
204
+ ├── wiki/ # LLM Wiki 结构化知识库
205
+ │ ├── overview.md # 仓库总览(从这里开始阅读)
206
+ │ ├── index.md # 自动生成的文档目录索引(按类型分区)
207
+ │ ├── log.md # 操作日志(记录每次写入/编辑)
208
+ │ ├── schema.yaml # 项目文档规范(含 page_types 路由表 + 代码路由规则)
209
+ │ ├── purpose.md # 项目用途说明(可选,增强搜索相关性)
210
+ │ ├── modules/ # 模块文档(含组件约束索引表 + Evidence-Based 断言)
211
+ │ │ ├── module1.md
212
+ │ │ └── module2.md
213
+ │ ├── entities/ # 实体页面(类、接口、数据库表等)
214
+ │ ├── concepts/ # 概念页面(设计模式、业务概念等)
215
+ │ ├── sources/ # 外部文档摘要(第三方文档导入)
216
+ │ ├── comparisons/ # 对比分析页面
217
+ │ └── queries/ # 研究查询页面
218
+ ├── raw/
219
+ │ └── sources/ # 第三方文档原始文件
220
+ ├── notes/ # 开发知识笔记(支持 candidate→confirmed→rejected 状态流转)
221
+ │ ├── decision-xxx.md # 架构决策记录
222
+ │ ├── pitfall-xxx.md # 踩坑记录
223
+ │ ├── workaround-xxx.md # 临时方案
224
+ │ └── ...
225
+ ├── .meta/
226
+ │ ├── project.json # 项目映射(repo_path/output_dir/cache_db 路径)
227
+ │ ├── symbol_map.json # 符号→源文件映射(SQLite 主存储的 JSON 兼容副本)
228
+ │ ├── issues.json # 质量问题追踪(health score 依据)
229
+ │ ├── source_registry.json # 外部文档注册表
230
+ │ ├── cross_service_links.json # 跨服务调用拓扑(monorepo)
231
+ │ └── overview_refs.json # overview 引用模块列表(精确 stale 判定)
232
+ ├── module_tree.json # 模块层级结构
233
+ ├── first_module_tree.json # 初始聚类结果
234
+ └── metadata.json # 生成元数据
235
+ ```
236
+
237
+ ### MCP 工具速查
238
+
239
+ 所有工具均不需要 LLM 配置,由 IDE Agent 通过 MCP 协议调用。MCP Server 内置 **instructions**(能力概览与工作流指南)、**7 个 Prompt 模板**(generate-wiki / extract-knowledge / search-wiki / quality-check / incremental-update / workspace-analysis / cross-service-trace)和 **6 个 Resource**(wiki-catalog / module-tree / index-status 等)。
240
+
241
+ **代码分析(6 个):**
242
+
243
+ | 工具 | 用途 |
244
+ |------|------|
245
+ | `analyze_repo` | 分析仓库,构建依赖图,返回组件索引;支持 SHA256 增量 + 方法级 content_hash 精确检测;自动检测 monorepo 子服务 |
246
+ | `analyze_workspace` | 扫描多仓库工作区,为每个子仓库独立生成 Wiki,顶层生成跨服务总览 |
247
+ | `list_components` | 组件索引查询,支持摘要模式和前缀过滤 |
248
+ | `list_dependencies` | 查询组件/模块依赖关系,支持分页、方向过滤、高影响力组件排名 |
249
+ | `read_code_components` | 根据组件 ID 读取源码 |
250
+ | `view_repo_file` | 查看仓库原始源文件内容,支持行范围截取 |
251
+
252
+ **文档生成管线(6 个):**
253
+
254
+ | 工具 | 用途 |
255
+ |------|------|
256
+ | `write_doc_file` | 创建 .md 文档(自动 Mermaid 校验 + 交叉链接注入 + page_type 路由);支持无 session 模式 |
257
+ | `edit_doc_file` | 编辑文档(替换/插入/撤销) |
258
+ | `save_module_tree` | 保存模块聚类结果 |
259
+ | `get_processing_order` | 获取叶优先的文档生成顺序 |
260
+ | `get_prompt` | 获取各阶段的提示词模板(含 16 种 prompt_type) |
261
+ | `close_session` | 关闭会话释放资源,构建 BM25 索引 + wikilink 图谱,写入生成元数据 |
262
+
263
+ **知识管理(7 个):**
264
+
265
+ | 工具 | 用途 |
266
+ |------|------|
267
+ | `query_wiki` | BM25 全文搜索 + wikilink 图谱多跳扩展 + **渐进式阅读**(mode=overview/directory/detail);返回 source_type 标注 |
268
+ | `ingest_note` | 将开发笔记归档到 notes/,支持 8 种类型 + aliases + source_ref;默认写入为 candidate 状态 |
269
+ | `confirm_note` | 将 candidate 笔记升级为 confirmed(正式领域知识) |
270
+ | `reject_note` | 否决 candidate 笔记,后续 query_wiki 不再返回 |
271
+ | `ingest_source` | 导入第三方文档到 `raw/sources/`,注册到 `source_registry.json` |
272
+ | `retract_source` | 撤回已导入的外部文档(flag_stale / remove_refs 两种模式) |
273
+ | `batch_ingest` | 批量导入:一次调用处理多个笔记/文档 |
274
+
275
+ **质量保障(2 个):**
276
+
277
+ | 工具 | 用途 |
278
+ |------|------|
279
+ | `lint_wiki` | 文档-代码一致性检查:**11 项检查**(含 unsupported_claims 无证据断言检测) |
280
+ | `flag_issue` | 标记 Wiki 质量问题,驱动 health score 计算 |
281
+
282
+ **跨服务分析(1 个):**
283
+
284
+ | 工具 | 用途 |
285
+ |------|------|
286
+ | `query_cross_service` | 查询跨服务调用关系(HTTP + MQ),支持 by_service / by_method / by_path / trace 过滤 |
287
+
288
+ > 另有 2 个遗留工具(`generate_docs`、`get_module_tree`)保留向后兼容,需先通过 `codewiki config set` 配置 LLM API。
289
+
290
+ ### 文档生成质量增强
291
+
292
+ CodeWiki-Plus 在 Prompt 层和引擎层做了系统性优化,显著提升生成文档的精度和效率。
293
+
294
+ #### Evidence-Based 业务断言
295
+
296
+ 生成模块文档时,Prompt 要求 LLM 对每条业务规则提供代码证据:
297
+
298
+ ```markdown
299
+ ### 业务规则
300
+
301
+ - **订单金额不可为负** [confidence: 0.95]
302
+ > evidence: `OrderService.java:L142` — `if (amount < 0) throw new BizException(...)`
303
+ > reason: 创建订单时强制校验金额非负
304
+ ```
305
+
306
+ `lint_wiki` 新增 `unsupported_claims` 检查:当页面中超过 30% 的业务断言缺少 evidence 时报告警告,帮助识别潜在的 LLM 幻觉。
307
+
308
+ #### 组件约束索引表
309
+
310
+ 每个模块文档自动生成结构化的约束索引表,方便 LLM 消费者快速定位:
311
+
312
+ ```markdown
313
+ ### Component Constraint Index
314
+
315
+ | Component | Type | Key Constraints | Dependencies |
316
+ |-----------|------|-----------------|--------------|
317
+ | OrderService | business | 金额校验、状态机流转 | PaymentClient, OrderRepo |
318
+ | OrderDTO | boilerplate | 字段映射 | — |
319
+ ```
320
+
321
+ #### 代码路由分类
322
+
323
+ `analyze_repo` 阶段自动将组件分为三类,差异化处理:
324
+
325
+ | 分类 | 典型组件 | 处理方式 |
326
+ |------|----------|----------|
327
+ | `business` | Service, Controller, Job, Handler | 完整源码注入 LLM,生成详细文档 |
328
+ | `boilerplate` | DTO, VO, Entity, Config, Mapper | 仅注入签名 + 字段列表,模板化输出 |
329
+ | `infra` | Util, Helper, Factory, Interceptor | 摘要级描述 |
330
+
331
+ 典型 Java/Spring 仓库可减少 30%+ 的 LLM token 消耗。用户可在 `schema.yaml` 的 `code_routing` 配置节自定义分类规则。
332
+
333
+ #### BFS 调用图上下文
334
+
335
+ 文档生成 Prompt 中自动注入 1-hop 调用上下文(`<CALL_CONTEXT>` 块),为每个核心组件附带直接调用者/被调用者的签名摘要,帮助 LLM 理解跨模块关系:
336
+
337
+ ```
338
+ <CALL_CONTEXT>
339
+ ## Neighbors of OrderService.createOrder
340
+ - [caller] PaymentController.initiatePayment(PaymentRequest req)
341
+ - [callee] InventoryClient.deductStock(String skuId, int qty)
342
+ </CALL_CONTEXT>
343
+ ```
344
+
345
+ ### 增量更新
346
+
347
+ `analyze_repo` 内置三层增量优化:
348
+
349
+ **变更检测**:首次生成后再次调用时,自动比对上次生成状态:
350
+
351
+ - **Git 策略(优先)**:通过 `git diff` 比对当前 HEAD 与上次生成时的 commit,识别变更文件
352
+ - **SHA256 指纹策略(回退)**:通过文件内容哈希(前 64KB)+ mtime 双重检测变更
353
+
354
+ **方法级精确检测**:文件变更后,逐组件比较 `content_hash`(SHA256 前 16 位),只有真正变化的方法/类才被标记为 stale。`get_stale_components()` 返回 added / modified / deleted 三类变更列表,支持级联失效关联的 Wiki 页面。
355
+
356
+ **选择性重解析**:仅重新解析变更文件,未变更文件的组件直接从 SQLite 缓存加载合并。`skip_file_paths` 参数贯穿全链路(DependencyGraphBuilder → DependencyParser → AnalysisService → CallGraphAnalyzer)。
357
+
358
+ **Overview stale 精确判定**:通过解析 overview.md 中的链接提取引用模块列表(持久化到 `.meta/overview_refs.json`),只有当 overview 实际引用了受影响模块时才标记为 stale。
359
+
360
+ ### Monorepo 跨服务分析
361
+
362
+ `analyze_repo` 自动检测 monorepo 中的子服务(5 阶段启发式:docker-compose → Dockerfile → 构建清单 → 约定目录 → Spring Boot),为每个子服务分配独立标签,在依赖图上运行 CrossServiceMatcher 识别 HTTP/MQ 跨服务调用关系。
363
+
364
+ ```
365
+ 检测流程:
366
+ docker-compose.yml 服务定义
367
+ → Dockerfile 构建目标
368
+ → pom.xml / build.gradle / package.json 构建清单
369
+ → src/main, app/, cmd/ 等约定目录
370
+ → Spring Boot @SpringBootApplication 入口
371
+
372
+ 输出:
373
+ .meta/cross_service_links.json — 跨服务调用拓扑
374
+ query_cross_service 工具可按 service/method/path/trace 维度查询
375
+ ```
376
+
377
+ ### 知识飞轮
378
+
379
+ 笔记系统引入 candidate → confirmed → rejected 状态流转,确保 LLM 自动沉淀的知识经过研发确认:
380
+
381
+ ```
382
+ LLM 发现跨功能约束
383
+ → ingest_note(status=candidate) 写入 notes/
384
+ → query_wiki 返回时标注 [unconfirmed]
385
+ → 研发确认:confirm_note → 升级为正式知识
386
+ → 研发否决:reject_note → 不再被搜索返回(保留记录)
387
+ ```
388
+
389
+ ### 渐进式阅读协议
390
+
391
+ `query_wiki` 支持三种消费模式,让 Agent 按需逐层深入,避免一次性加载过多内容:
392
+
393
+ | mode | 返回内容 | 适用场景 |
394
+ |------|----------|----------|
395
+ | `overview` | 仓库级摘要(< 500 token) | Agent 初次接触项目,快速了解全貌 |
396
+ | `directory` | 按类型分区的页面目录(< 800 token) | 定位目标模块/实体 |
397
+ | `detail` | 指定页面完整内容 | 深入阅读特定文档 |
398
+ | 默认 | BM25 snippet 搜索结果 | 关键词检索 |
399
+
400
+ ```
401
+ Agent 消费路径:
402
+ query_wiki(mode=overview) → 了解项目
403
+ → query_wiki(mode=directory) → 找到目标页面
404
+ → query_wiki(query="xxx", expand=true) → 深入阅读
405
+ ```
406
+
407
+ ### 存储架构
408
+
409
+ CodeWiki-Plus 采用 **SQLite 主存储 + JSON 兼容副本** 的双层架构:
410
+
411
+ **SQLite(`{repo}/.codewiki/analysis_cache.db`)**:组件索引(含 content_hash)、文件指纹、依赖关系、BM25 搜索索引(token 级倒排)、符号映射(symbol_map)、路由表均存储在 SQLite 中,支持高效查询和增量更新。
412
+
413
+ **JSON 兼容副本(`output_dir/.meta/`)**:`symbol_map.json`、`module_tree.json` 等保留精简 JSON 副本,供外部工具直接读取。
414
+
415
+ **持久化项目映射(`.meta/project.json`)**:`analyze_repo` 执行后自动写入 `repo_path`、`output_dir`、`cache_db` 的绝对路径映射。这使得 `query_wiki`、`ingest_note` 等知识管理工具在**无活跃 session** 时也能通过 `project.json` 定位 SQLite 数据库,走 BM25 索引搜索。
416
+
417
+ ```
418
+ 搜索路径优先级:
419
+ 活跃 session.cache → .meta/project.json → cache_db → SQLite BM25
420
+ ↘ 回退:output_dir.parent/.codewiki/analysis_cache.db
421
+ ↘ 最终回退:.meta/search_index.json(全量遍历)
422
+ ```
423
+
424
+ ### LLM Wiki 知识系统
425
+
426
+ 除了文档生成,CodeWiki-Plus 还内置了 LLM Wiki 知识管理能力,让生成出的 Wiki 持续演进为项目的活知识库。
427
+
428
+ #### 结构化知识库布局
429
+
430
+ 所有 Wiki 内容按页面类型(page type)组织在 `wiki/` 子目录下,由 `page_router.py` 统一路由:
431
+
432
+ | 页面类型 | 目录 | 说明 |
433
+ |----------|------|------|
434
+ | `module` | `wiki/modules/` | 模块文档(含约束索引表 + Evidence-Based 断言) |
435
+ | `entity` | `wiki/entities/` | 实体页面:类、接口、数据库表、配置项等 |
436
+ | `concept` | `wiki/concepts/` | 概念页面:设计模式、业务概念、架构风格等 |
437
+ | `source` | `wiki/sources/` | 外部文档摘要:导入的第三方文档 |
438
+ | `comparison` | `wiki/comparisons/` | 对比分析:技术选型、方案比较等 |
439
+ | `query` | `wiki/queries/` | 研究查询:调研结论、问题排查记录等 |
440
+
441
+ `write_doc_file` 工具的 `page_type` 参数指定类型即可自动路由到正确目录。
442
+
443
+ #### schema.yaml 与配置
444
+
445
+ `schema.yaml` 是项目的文档"宪法",包含命名规范、必需章节、文档维度、lint 设置、**page_types 路由表**、以及 **code_routing 代码路由规则**。`config.yaml`(CodeWiki-Plus 安装目录下)提供与语言无关的默认配置,首次 `analyze_repo` 时会读取它生成项目级 `schema.yaml`。
446
+
447
+ **自定义**:修改 CodeWiki-Plus 的 `config.yaml` 改变全局默认值;修改某个项目的 `schema.yaml` 只影响该项目(增量更新时自动合并保留自定义字段)。
448
+
449
+ #### 交叉链接与别名
450
+
451
+ - **交叉链接注入**:`write_doc_file` 根据组件级依赖关系自动在文档末尾注入"相关模块"章节(Depends on / Used by),通过 `schema.yaml` 中的 `auto_crosslink` 开关控制
452
+ - **别名(aliases)**:文档 frontmatter 中可声明 `aliases` 列表,搜索时别名获得 **3× BM25 权重提升**
453
+ - **来源引用(source_refs)**:正文中使用 `[^src:name:line_range]` 标记第三方文档出处
454
+
455
+ #### 来源类型标注
456
+
457
+ `query_wiki` 搜索结果为每条结果标注 `source_type`,帮助 Agent 判断信息可信度:
458
+
459
+ | source_type | 含义 | 消费建议 |
460
+ |-------------|------|----------|
461
+ | `auto_generated` | 来自 wiki/ 目录,代码分析自动生成 | 可直接引用 |
462
+ | `developer_note` | 来自 notes/ 目录,人工/LLM 沉淀 | 检查时效性和确认状态 |
463
+ | `ingested_source` | 来自 ingest_source 导入的外部文档 | 注意版本时效 |
464
+
465
+ #### 外部文档管理
466
+
467
+ 通过 `ingest_source` 和 `retract_source` 管理第三方文档(API 文档、设计规范、RFC 等)的完整生命周期:
468
+
469
+ ```json
470
+ // 导入外部文档
471
+ { "name": "rfc-7519-jwt", "source_type": "rfc", "source_path": "/path/to/rfc7519.txt",
472
+ "description": "JWT 规范", "related_pages": ["auth-module"] }
473
+
474
+ // 撤回外部文档(两种模式)
475
+ { "source_name": "rfc-7519-jwt", "mode": "flag_stale" } // 标记过期,保留文件
476
+ { "source_name": "rfc-7519-jwt", "mode": "remove_refs" } // 删除文件,清理所有引用
477
+ ```
478
+
479
+ #### 文档健康检查
480
+
481
+ `lint_wiki` 提供 **11 项检查**,覆盖结构完整性和内容质量:
482
+
483
+ | 检查项 | 说明 |
484
+ |--------|------|
485
+ | `stale_refs` | 引用了已不存在的组件 |
486
+ | `broken_links` | 断链(wikilink 指向不存在的页面) |
487
+ | `undocumented` | 高影响力组件缺少文档 |
488
+ | `cycles` | 模块间循环依赖 |
489
+ | `coverage` | 文档覆盖率不足 |
490
+ | `orphan_pages` | 没有任何页面链接到的孤立页面 |
491
+ | `no_outlinks` | 没有链接到任何其他页面的死端页面 |
492
+ | `missing_aliases` | 实体页面缺少 aliases 声明 |
493
+ | `stale_sources` | 引用了已撤回外部文档的页面 |
494
+ | `overview_stale` | overview.md 引用了已变更的模块 |
495
+ | `unsupported_claims` | 业务断言缺少代码证据(>30% 触发警告) |
496
+
497
+ `lint_wiki` 返回 **health_score**(0-100),计算方式为 `100 - Σ(error×10 + warning×3 + info×1)`。
498
+
499
+ #### 全文搜索
500
+
501
+ `query_wiki` 搜索能力:
502
+
503
+ - **BM25 排序** + jieba 中文分词
504
+ - **类型过滤**:`type_filter` 限定搜索范围(module/entity/concept/source/comparison/query)
505
+ - **作用域前缀**:`scope` 支持目录前缀(如 `wiki/entities`、`notes`)
506
+ - **权重增强**:aliases 3× boost、severity 2× boost
507
+ - **图谱多跳扩展**:`hop`(0-3)沿 wikilink 有向边 BFS 发现关联页面,`decay` 控制衰减
508
+ - **深度阅读**:`expand=true` 返回完整页面内容(≤ 3000 字符)
509
+ - **渐进模式**:`mode=overview/directory/detail` 分层消费
510
+ - **状态过滤**:自动跳过 rejected 笔记,candidate 标注 [unconfirmed]
511
+
512
+ #### 提示词模板
513
+
514
+ `get_prompt` 支持 **16 种 prompt_type**:
515
+
516
+ | prompt_type | 用途 |
517
+ |-------------|------|
518
+ | `cluster` | 模块聚类规则 |
519
+ | `system_complex` / `system_leaf` | 文档生成系统指令(含 Evidence-Based + 约束索引表) |
520
+ | `user` | 用户 prompt 模板(含代码路由 + BFS 上下文) |
521
+ | `overview_module` / `overview_repo` | 总览合成 |
522
+ | `entity_page` / `concept_page` | 实体/概念页面生成 |
523
+ | `source_summary` | 外部文档摘要 |
524
+ | `comparison_page` / `query_page` | 对比分析 / 研究查询 |
525
+ | `taxonomy_plan` | Wiki 分类体系规划 |
526
+ | `extraction_scan` | 源码实体/概念候选提取 |
527
+ | `wiki_query` / `wiki_ingest` / `wiki_lint_report` | 知识管理工作流 |
528
+
529
+ ### 使用场景示例
530
+
531
+ **场景 1:生成仓库文档**
532
+
533
+ ```
534
+ 帮我分析当前仓库并生成 Wiki 文档,输出到 repowiki 目录。请使用中文撰写文档。
535
+ ```
536
+
537
+ **场景 2:增量更新**
538
+
539
+ ```
540
+ 代码有改动,帮我更新受影响的模块文档。
541
+ ```
542
+
543
+ Agent 调用 `analyze_repo`,自动检测变更文件和 stale 组件,只重新生成受影响的模块。
544
+
545
+ **场景 3:搜索项目知识**
546
+
547
+ ```
548
+ 搜索项目中关于"订单状态机"的所有知识。
549
+ ```
550
+
551
+ Agent 调用 `query_wiki(query="订单状态机", hop=1)`,返回相关文档 + 图谱关联页面。
552
+
553
+ **场景 4:沉淀开发经验**
554
+
555
+ ```
556
+ 记录一个踩坑:Redis 连接池在高并发下偶尔超时,根因是 maxTotal 设置过低。
557
+ ```
558
+
559
+ Agent 调用 `ingest_note(note_type="pitfall", status="candidate")`,写入笔记待确认。
560
+
561
+ **场景 5:确认/否决知识**
562
+
563
+ ```
564
+ 确认 notes/pitfall-redis-connection-pool.md 这条笔记。
565
+ ```
566
+
567
+ Agent 调用 `confirm_note(note_file="pitfall-redis-connection-pool.md")`,升级为正式知识。
568
+
569
+ **场景 6:导入外部文档**
570
+
571
+ ```
572
+ 把 docs/stripe-api-reference.md 导入 Wiki,关联支付模块。
573
+ ```
574
+
575
+ **场景 7:检查文档健康度**
576
+
577
+ ```
578
+ 检查一下 Wiki 文档的健康状况。
579
+ ```
580
+
581
+ Agent 调用 `lint_wiki`,返回 11 项诊断报告和 health_score。
582
+
583
+ **场景 8:跨服务调用分析**
584
+
585
+ ```
586
+ 分析这个 monorepo 里各服务之间的调用关系。
587
+ ```
588
+
589
+ Agent 调用 `analyze_repo`(自动检测子服务)→ `query_cross_service(filter_type="all")`。
590
+
591
+ ### 支持的其他 AI IDE
592
+
593
+ 除 CodeBuddy 外,任何支持 MCP stdio 协议的 AI IDE 均可使用:
594
+
595
+ **Cursor**:在 Settings → MCP 中添加相同的 Server 配置。
596
+
597
+ **Claude Desktop**:在 `~/Library/Application Support/Claude/claude_desktop_config.json`(macOS)中添加 MCP 配置。
598
+
599
+ **其他 IDE**:指定 `command: "python"`, `args: ["-m", "codewiki.mcp.server"]` 即可。
600
+
601
+ ### 原始 CLI 模式(仍然可用)
602
+
603
+ 如果你更习惯命令行一键生成,原始的 CLI 方式完全不受影响。需要先配置 LLM API:
604
+
605
+ ```bash
606
+ codewiki config set \
607
+ --provider openai-compatible \
608
+ --api-key YOUR_KEY \
609
+ --base-url https://api.example.com \
610
+ --main-model claude-sonnet-4 \
611
+ --cluster-model claude-sonnet-4
612
+
613
+ codewiki generate
614
+ ```
615
+
616
+ 支持 OpenAI、Anthropic、Azure OpenAI、AWS Bedrock 以及 Claude Code / Codex 订阅模式。详见[上游项目 README](https://github.com/FSoft-AI4Code/CodeWiki)。
617
+
618
+ ### 支持的语言
619
+
620
+ Python、Java、JavaScript、TypeScript、C、C++、C#、Kotlin、Go、PHP
621
+
622
+ ### 致谢
623
+
624
+ 本项目的核心工具链(Tree-sitter AST 解析、依赖图构建、拓扑排序、Mermaid 校验)全部来自 [FSoft-AI4Code/CodeWiki](https://github.com/FSoft-AI4Code/CodeWiki) 上游项目。以下开源项目的设计思路对我们产生了重要影响:
625
+
626
+ - [codebase-memory-mcp](https://github.com/nicobailon/codebase-memory-mcp) — SQLite 持久化缓存架构、跨会话复用、三层降级模式
627
+ - [nashsu/llm_wiki](https://github.com/nashsu/llm_wiki) — 结构化知识层设计、页面类型路由、交叉链接
628
+ - [Tencent/WeKnora](https://github.com/Tencent/WeKnora) — 外部文档管理、文档健康检查、自适应分块思路
629
+ - [CodingHub](https://github.com/mambo-wang/CodingHub) — MCP Server 最佳实践(instructions / prompts / resources)
630
+
631
+ 我们在上游基础上将 MCP Server 从黑盒模式拆分为 **23 个细粒度工具**,并新增结构化 Wiki、Evidence-Based 断言、代码路由分类、知识飞轮、渐进式阅读、方法级增量检测、monorepo 跨服务分析等能力。
632
+
633
+ 上游论文:[CodeWiki: Evaluating AI's Ability to Generate Holistic Documentation for Large-Scale Codebases](https://arxiv.org/abs/2510.24428)
634
+
635
+ ```bibtex
636
+ @misc{hoang2025codewikievaluatingaisability,
637
+ title={CodeWiki: Evaluating AI's Ability to Generate Holistic Documentation for Large-Scale Codebases},
638
+ author={Anh Nguyen Hoang and Minh Le-Anh and Bach Le and Nghi D. Q. Bui},
639
+ year={2025},
640
+ eprint={2510.24428},
641
+ archivePrefix={arXiv},
642
+ primaryClass={cs.SE},
643
+ url={https://arxiv.org/abs/2510.24428},
644
+ }
645
+ ```
646
+
647
+ ---
648
+
649
+ <a id="en"></a>
650
+
651
+ ## English
652
+
653
+ ### What is this project?
654
+
655
+ CodeWiki-Plus is an enhanced fork of [FSoft-AI4Code/CodeWiki](https://github.com/FSoft-AI4Code/CodeWiki) that enables **zero-LLM-config Wiki generation** driven entirely by AI IDEs (CodeBuddy, Cursor, Claude Desktop, etc.) via MCP (Model Context Protocol), plus a full knowledge management engine.
656
+
657
+ ### Why this fork?
658
+
659
+ The original CodeWiki is an excellent repository-level documentation framework. However, it requires users to configure their own LLM API (API key, provider, model selection), and the generation pipeline runs as a black box with no user intervention.
660
+
661
+ In practice, CodeWiki's core toolchain—Tree-sitter AST parsing, dependency graph construction, topological sorting, and Mermaid validation—does not need an LLM at all. The 4 stages that do require LLM intelligence (module clustering, document writing, sub-module recursion, and overview synthesis) are exactly what AI IDE Agents excel at.
662
+
663
+ We refactored CodeWiki's MCP Server from a "one-click black box" into **23 fine-grained tools**, turning it into a pure toolchain server. The AI IDE's Agent calls these tools via MCP and uses its own reasoning to complete all documentation work:
664
+
665
+ ```
666
+ Before:
667
+ IDE → generate_docs(repo) → [CodeWiki calls LLM API internally] → result
668
+
669
+ After:
670
+ IDE Agent → analyze_repo → read_code → (Agent reasons) → write_doc → overview
671
+ ↑ pure tool ↑ pure tool ↑ IDE's own model ↑ pure tool
672
+ ```
673
+
674
+ ### Enhancements over upstream CodeWiki
675
+
676
+ | Dimension | Upstream CodeWiki | CodeWiki-Plus |
677
+ |-----------|------------------|---------------|
678
+ | LLM config | Must configure API key | Zero-config, IDE model driven |
679
+ | Generation mode | Black-box one-click | 23 fine-grained tools, full Agent control |
680
+ | Doc quality | Generic descriptions | Evidence-Based assertions (code quotes + confidence) |
681
+ | Generation efficiency | All components equal | Code routing: boilerplate gets signature-only |
682
+ | Context precision | Intra-module components | BFS 1-hop call graph + constraint index table |
683
+ | Incremental update | File-level Git diff | Method-level content_hash detection |
684
+ | Knowledge management | None | Structured Wiki + note flywheel + external docs |
685
+ | Search | None | BM25 + wikilink graph multi-hop + progressive reading |
686
+ | Cross-service | None | Monorepo sub-service detection + call tracing |
687
+ | Quality assurance | None | 11 lint checks + health score + issue tracking |
688
+
689
+ ### Prerequisites
690
+
691
+ - **Python 3.12+**
692
+ - **Node.js** (for Mermaid diagram validation; without it, validation is silently skipped)
693
+ - An MCP-compatible AI IDE (CodeBuddy, Cursor, Claude Desktop, etc.)
694
+
695
+ ### Quick Start (CodeBuddy Example)
696
+
697
+ 3 steps, no API key needed.
698
+
699
+ **Step 1: Install CodeWiki-Plus**
700
+
701
+ ```bash
702
+ git clone https://github.com/mambo-wang/CodeWiki-Plus.git
703
+ cd CodeWiki-Plus
704
+ pip install -e .
705
+ ```
706
+
707
+ **Step 2: Configure MCP Server**
708
+
709
+ Add the following to your CodeBuddy MCP settings:
710
+
711
+ ```json
712
+ {
713
+ "mcpServers": {
714
+ "codewiki": {
715
+ "command": "python",
716
+ "args": ["-m", "codewiki.mcp.server"],
717
+ "cwd": "/your/path/to/CodeWiki-Plus"
718
+ }
719
+ }
720
+ }
721
+ ```
722
+
723
+ > Replace `/your/path/to/CodeWiki-Plus` with the actual absolute path where you cloned CodeWiki-Plus.
724
+
725
+ **Step 3: Prompt your AI Agent**
726
+
727
+ Open the target project in CodeBuddy, switch to Agent mode, and enter:
728
+
729
+ ```
730
+ Analyze the current repository and generate Wiki documentation into the repowiki directory. Write docs in English.
731
+ ```
732
+
733
+ The Agent follows a 5-stage pipeline:
734
+
735
+ ```
736
+ Stage 1: Call analyze_repo → get component index, leaf nodes
737
+ (auto-detects monorepo sub-services, builds cross-service topology)
738
+ Stage 2: Call get_prompt("cluster") for clustering rules
739
+ Read source code, reason about grouping, call save_module_tree
740
+ Stage 3: Document each module leaf-first
741
+ Leaf modules: read_code → reason → write_doc_file
742
+ (prompt auto-injects BFS call context + constraint index + business rules extraction)
743
+ Parent modules: read child docs → synthesize → write_doc_file
744
+ Stage 4: Generate repository overview (overview.md)
745
+ Stage 5: Call close_session to free resources, build search index
746
+ ```
747
+
748
+ ### MCP Tools
749
+
750
+ All tools require zero LLM config. The IDE Agent invokes them via MCP. The server includes built-in **instructions**, **7 Prompt templates**, and **6 Resources**.
751
+
752
+ **Code Analysis (6):**
753
+
754
+ | Tool | Purpose |
755
+ |------|---------|
756
+ | `analyze_repo` | Parse repo, build dependency graph; SHA256 incremental + method-level content_hash; monorepo sub-service detection |
757
+ | `analyze_workspace` | Scan multi-repo workspace, generate per-repo Wikis with cross-service overview |
758
+ | `list_components` | Component index query with summary mode and prefix filtering |
759
+ | `list_dependencies` | Query dependencies with pagination, direction filtering, high-impact ranking |
760
+ | `read_code_components` | Read source code by component ID |
761
+ | `view_repo_file` | View raw source file content with optional line range |
762
+
763
+ **Documentation Pipeline (6):**
764
+
765
+ | Tool | Purpose |
766
+ |------|---------|
767
+ | `write_doc_file` | Create .md docs with Mermaid validation + crosslink injection + page_type routing; sessionless mode |
768
+ | `edit_doc_file` | Edit docs (str_replace / insert / undo) |
769
+ | `save_module_tree` | Persist module clustering results |
770
+ | `get_processing_order` | Get leaf-first documentation order |
771
+ | `get_prompt` | Retrieve prompt templates (16 prompt_types) |
772
+ | `close_session` | Close session, build BM25 index + wikilink graph, write metadata |
773
+
774
+ **Knowledge Management (7):**
775
+
776
+ | Tool | Purpose |
777
+ |------|---------|
778
+ | `query_wiki` | BM25 search + wikilink graph multi-hop + **progressive reading** (mode=overview/directory/detail); source_type annotation |
779
+ | `ingest_note` | File structured notes (8 types) with aliases + source_ref; default candidate status |
780
+ | `confirm_note` | Promote candidate note to confirmed knowledge |
781
+ | `reject_note` | Reject candidate note, exclude from future searches |
782
+ | `ingest_source` | Import third-party docs into `raw/sources/` |
783
+ | `retract_source` | Retract imported docs (flag_stale / remove_refs) |
784
+ | `batch_ingest` | Batch import multiple notes/sources in one call |
785
+
786
+ **Quality Assurance (2):**
787
+
788
+ | Tool | Purpose |
789
+ |------|---------|
790
+ | `lint_wiki` | Doc-code consistency: **11 checks** (incl. unsupported_claims evidence detection) |
791
+ | `flag_issue` | Flag quality issues, drives health score |
792
+
793
+ **Cross-Service Analysis (1):**
794
+
795
+ | Tool | Purpose |
796
+ |------|---------|
797
+ | `query_cross_service` | Query cross-service calls (HTTP + MQ), filter by service/method/path/trace |
798
+
799
+ > 2 legacy tools (`generate_docs`, `get_module_tree`) retained for backward compatibility.
800
+
801
+ ### Documentation Quality Enhancements
802
+
803
+ #### Evidence-Based Assertions
804
+
805
+ Module documentation prompts require LLM to provide code evidence for each business rule:
806
+
807
+ ```markdown
808
+ ### Business Rules
809
+
810
+ - **Order amount must be non-negative** [confidence: 0.95]
811
+ > evidence: `OrderService.java:L142` — `if (amount < 0) throw new BizException(...)`
812
+ > reason: Enforced validation on order creation
813
+ ```
814
+
815
+ `lint_wiki` includes `unsupported_claims` check: warns when >30% of business assertions lack evidence.
816
+
817
+ #### Code Routing
818
+
819
+ Components are classified into three categories for differentiated processing:
820
+
821
+ | Category | Typical Components | Treatment |
822
+ |----------|-------------------|-----------|
823
+ | `business` | Service, Controller, Job, Handler | Full source injected to LLM |
824
+ | `boilerplate` | DTO, VO, Entity, Config, Mapper | Signature + fields only, template output |
825
+ | `infra` | Util, Helper, Factory, Interceptor | Summary-level description |
826
+
827
+ Reduces LLM token consumption by 30%+ on typical Java/Spring repos. Customizable via `code_routing` in `schema.yaml`.
828
+
829
+ #### BFS Call Context
830
+
831
+ Prompts auto-inject 1-hop call context (`<CALL_CONTEXT>` block) with caller/callee signatures for each core component.
832
+
833
+ ### Incremental Updates
834
+
835
+ Three layers of incremental optimization:
836
+
837
+ - **Git strategy (preferred)**: `git diff` against stored commit
838
+ - **SHA256 fingerprint (fallback)**: Content hash + mtime dual detection
839
+ - **Method-level detection**: Per-component `content_hash` comparison; only truly changed methods trigger re-generation. `get_stale_components()` returns added/modified/deleted lists for cascade wiki invalidation.
840
+
841
+ ### Monorepo Cross-Service Analysis
842
+
843
+ `analyze_repo` auto-detects sub-services via 5-stage heuristics (docker-compose → Dockerfile → build manifests → convention dirs → Spring Boot), assigns independent labels, and runs CrossServiceMatcher for HTTP/MQ call relationships.
844
+
845
+ ### Knowledge Flywheel
846
+
847
+ Notes follow a candidate → confirmed → rejected lifecycle:
848
+
849
+ ```
850
+ LLM discovers cross-cutting constraint
851
+ → ingest_note(status=candidate)
852
+ → query_wiki annotates [unconfirmed]
853
+ → Developer confirms: confirm_note → promoted to verified knowledge
854
+ → Developer rejects: reject_note → excluded from search (record preserved)
855
+ ```
856
+
857
+ ### Progressive Reading Protocol
858
+
859
+ `query_wiki` supports three consumption modes:
860
+
861
+ | mode | Returns | Use case |
862
+ |------|---------|----------|
863
+ | `overview` | Repo-level summary (< 500 tokens) | First contact with project |
864
+ | `directory` | By-type page directory (< 800 tokens) | Locate target module/entity |
865
+ | `detail` | Full page content | Deep reading |
866
+ | default | BM25 snippet results | Keyword search |
867
+
868
+ ### Supported Languages
869
+
870
+ Python, Java, JavaScript, TypeScript, C, C++, C#, Kotlin, Go, PHP
871
+
872
+ ### Acknowledgements
873
+
874
+ The core toolchain (Tree-sitter AST parsing, dependency graph, topological sort, Mermaid validation) comes from [FSoft-AI4Code/CodeWiki](https://github.com/FSoft-AI4Code/CodeWiki). Influenced by:
875
+
876
+ - [codebase-memory-mcp](https://github.com/nicobailon/codebase-memory-mcp) — SQLite persistent cache, cross-session reuse
877
+ - [nashsu/llm_wiki](https://github.com/nashsu/llm_wiki) — Structured knowledge layer, page type routing
878
+ - [Tencent/WeKnora](https://github.com/Tencent/WeKnora) — External doc management, health checks
879
+ - [CodingHub](https://github.com/mambo-wang/CodingHub) — MCP Server best practices
880
+
881
+ Paper: [CodeWiki: Evaluating AI's Ability to Generate Holistic Documentation for Large-Scale Codebases](https://arxiv.org/abs/2510.24428)
882
+
883
+ ---
884
+
885
+ ## License
886
+
887
+ MIT