Transform codebases into comprehensive documentation using AI-powered analysis
pip install codewiki-plus==5.16.6 Copy PIP instructions
用 AI IDE 驱动的代码仓库文档生成与知识管理工具 AI IDE-Driven Code Documentation Generator & Knowledge Engine
CodeWiki-Plus 是一个由 AI IDE(CodeBuddy、Cursor、Claude Desktop 等)自身模型驱动的仓库知识引擎:无需配置任何大模型 API,即可完成 Wiki 文档生成,并在此基础上提供检索、笔记、任务记忆、团队遥测等完整知识管理能力。
项目最初 fork 自 FSoft-AI4Code/CodeWiki 并在其工具链(Tree-sitter AST 解析、依赖图构建、拓扑排序、Mermaid 校验)基础上独立演进,现已发展为架构定位不同的独立项目——详见致谢。
原版 CodeWiki 是一个非常优秀的仓库级文档生成框架,它通过 Tree-sitter AST 解析、依赖图构建、拓扑排序等工具链实现高质量的代码文档生成。但它有一个使用门槛:必须自行配置 LLM API(申请 API Key、选择 provider、处理模型兼容性),且整个生成过程是黑盒的,用户无法中途干预。
实际上,CodeWiki 的核心工具链——AST 解析、依赖图、Mermaid 校验——完全不需要 LLM。真正需要 LLM 智能的 4 个环节(模块聚类、文档撰写、子模块递归、总览合成),恰好是 AI IDE 的 Agent 最擅长做的事情。
因此,我们将 CodeWiki 的 MCP Server 从"黑盒式一键生成"拆分为53 个细粒度工具,让它退化为纯工具链服务器。AI IDE 的 Agent 通过 MCP 协议调用这些工具,用自己的推理能力完成全部文档生成工作:
改造前: IDE → generate_docs(repo) → [CodeWiki 内部调用 LLM API] → 结果 改造后: IDE Agent → analyze_repo → read_code → (Agent 自己推理) → write_doc → overview ↑ 纯工具 ↑ 纯工具 ↑ IDE 自身模型 ↑ 纯工具 与上游 CodeWiki 的差异 能力维度 上游 CodeWiki CodeWiki-Plus LLM 配置 必须自行配置 API Key 零配置,IDE 自身模型驱动 生成模式 黑盒一键生成 53 个细粒度工具,Agent 全程可控 文档质量 通用描述 Evidence-Based 断言(代码引用 + 置信度) 生成效率 所有组件同等处理 代码路由分类,boilerplate 仅保留签名 上下文精度 模块内组件 BFS 1-hop 调用图扩展 + 约束索引表 增量更新 文件级 Git diff 方法级 content_hash 精确检测 知识管理 无 结构化 Wiki + 笔记飞轮 + 外部文档管理 知识可信度 无 置信分层(strong/weak/shadow)+ 冲突案卷 + 使用结果信号(outcome 遥测) 任务记忆 无 跨会话任务上下文 + 任务记忆 + 条目级检索 + 自动压缩 搜索能力 无 BM25 + wikilink 图谱多跳 + 渐进式阅读 跨服务分析 无 Monorepo 子服务检测 + 跨服务调用追踪 质量保障 无 25 项 lint 检查 + health score + 问题追踪 前置条件 Python 3.12+ Node.js(用于 Mermaid 图表校验,不安装则图表校验会静默跳过) 一个支持 MCP 的 AI IDE(CodeBuddy、Cursor、Claude Desktop 等) 快速开始(以 CodeBuddy 为例) 整个过程只需 3 步,不需要任何 API Key。
codewiki --version 开发者选项:如需从源码开发(获取最新未发布改动),推荐使用 uv 按 uv.lock 精确复现开发环境(pyproject.toml:106 tool.uv.default-groups = ["dev"] 已包含 dev 工具):
git clone https://github.com/mambo-wang/CodeWiki-Plus.git cd CodeWiki-Plus uv sync --frozen # 按 uv.lock 复现完整开发环境(含 dev 依赖,hatchling 构建) uv run codewiki --version # 通过 uv 环境运行 CLI uv run pytest tests/ -q # 运行测试(addopts 已移除 --cov,无需覆盖) # 需要覆盖率时:uv run pytest --cov=codewiki --cov-report=term-missing 没有 uv 时也可 pip install -e .[dev],但依赖解析不受 uv.lock 锁定。
一键接线(推荐):跑 codewiki setup 可一次完成 hook 与会话采集接线、项目根 .mcp.json 创建/合并、以及 codewiki-* 技能文件生成(--lang zh|en 可注入 CODEWIKI_LANG 并决定技能语言,--dry-run 预览)。生成的 MCP 配置解释器按平台选择(Windows python,mac/Linux python3)。以下为其手工等价步骤。
在 CodeBuddy 的 MCP 设置中添加以下配置(通常在设置界面的"工具"或"MCP"板块):
"codewiki": { "command": "python", "args": [ "-m", "codewiki.mcp.server" ], "maxOutputLength": 500000, "timeout": 36000000, "disabled": false } 配置完成后,CodeBuddy 的 MCP 工具列表中应出现 codewiki 相关的 53 个工具。
CodeWiki-Plus 开箱即用,默认无需设置任何环境变量。少数偏好项与逃生门通过环境变量控制,但它们必须由 MCP Server 的启动进程读取——写在 .bashrc / 系统环境变量里对 MCP 进程不可见。设置方式是在 MCP 配置 JSON 的 mcpServers. 下加 env 块(即上面的第 2 步配置里追加):
{ "mcpServers": { "codewiki": { "command": "python", "args": [ "-m", "codewiki.mcp.server" ], "maxOutputLength": 500000, "timeout": 36000000, "env": { "CODEWIKI_LANG": "en", "CODEWIKI_USER": "your-pseudonym" } } } } 改完重启 MCP Server 生效。修改环境变量后,必须重启 MCP Server(进程只在启动时读取一次)。
注意取值语义三套并存,勿套惯性:CODEWIKI_TEAM_MEMORY_HOOK 严格等于 "1";CODEWIKI_RAW_TOOL_DETAIL 是反向黑名单(0/off/false/no/none 关);CODEWIKI_NO_KEYRING / CODEWIKI_CBM_DISABLED 是正向集合(1/true/yes 开/关)。CODEWIKI_HOOK_EVENT_FILE 为 hook 内部传参,用户不要手动设置。
打开 CodeBuddy 的 Agent 模式,用 CodeBuddy 打开你要生成文档的目标项目,然后输入:
帮我分析当前仓库并生成 Wiki 文档,输出到 repowiki 目录。请使用中文撰写文档。 Agent 会自动按照以下流程工作:
阶段 1: 调用 analyze_repo → 得到组件索引、叶节点列表 (自动检测 monorepo 子服务,构建跨服务调用关系) ↓ 阶段 2: 调用 get_prompt("cluster") 获取聚类规则 调用 read_code_components 阅读源码 自主推理,将组件分组为 3-8 个逻辑模块 调用 save_module_tree 保存聚类结果 ↓ 阶段 3: 按叶优先顺序逐模块生成文档 每个叶模块:read_code → 分析推理 → write_doc_file (prompt 自动注入 BFS 调用上下文 + 约束索引表 + 业务规则提取指令) 每个父模块:读取子文档 → 合成总览 → write_doc_file ↓ 阶段 4: 生成仓库总览 overview.md ↓ 阶段 5: 调用 close_session 释放资源,构建搜索索引 生成的文档结构:
repowiki/ ├── wiki/ # LLM Wiki 结构化知识库 │ ├── overview.md # 仓库总览(从这里开始阅读) │ ├── index.md # 自动生成的文档目录索引(按类型分区) │ ├── log.md # 操作日志(记录每次写入/编辑) │ ├── schema.yaml # 项目文档规范(含 purpose 定位 + page_types 路由表 + 代码路由规则) │ ├── doctrine.md # 团队工作方式共识(L3,由共识笔记晋级) │ ├── modules/ # 模块文档(含组件约束索引表 + Evidence-Based 断言) │ │ ├── module1.md │ │ └── module2.md │ ├── entities/ # 实体页面(类、接口、数据库表等) │ ├── concepts/ # 概念页面(设计模式、业务概念等) │ ├── scenarios/ # L2 场景块(可复用工作方法归纳,带容量上限) │ ├── sources/ # 外部文档摘要(第三方文档导入) │ ├── comparisons/ # 对比分析页面 │ └── queries/ # 研究查询页面 ├── conflicts/ # 冲突案卷(两条笔记矛盾的声明与裁决,ADR-0007) ├── skills/ # 技能草稿区(SKILL.md 编译产物,进索引进 lint、不生效) ├── raw/ │ ├── conversations/ # 采集的对话转录(暂存,蒸馏后清理) │ └── sources/ # 第三方文档原始文件 ├── notes/ # 开发知识笔记(draft → stable → deprecated 状态流转 + 置信分层) │ ├── decision-xxx.md # 架构决策记录 │ ├── pitfall-xxx.md # 踩坑记录 │ ├── workaround-xxx.md # 临时方案 │ └── ... ├── tasks/ # 任务记忆(跨会话长线工作上下文) │ ├── .index.json # 任务索引 │ └── / # task.md + memories/ .md(按用户分文件)+ memories-archive/ ├── .meta/ │ ├── project.json # 项目映射(repo_path/output_dir/cache_db 路径) │ ├── symbol_map.json # 符号→源文件映射(SQLite 主存储的 JSON 兼容副本) │ ├── issues.json # 质量问题追踪(health score 依据) │ ├── source_registry.json # 外部文档注册表 │ ├── cross_service_links.json # 跨服务调用拓扑(monorepo) │ ├── overview_refs.json # overview 引用模块列表(精确 stale 判定) │ ├── telemetry/ # 团队遥测(hit/adopted/outcome 事件流,per-user jsonl) │ └── task_bindings/ # 会话 ↔ 任务绑定 ├── module_tree.json # 模块层级结构 ├── first_module_tree.json # 初始聚类结果 └── metadata.json # 生成元数据 MCP 工具速查 所有工具均不需要 LLM 配置,由 IDE Agent 通过 MCP 协议调用。MCP Server 内置 instructions(能力概览与工作流指南)、23 个工作流 Prompt(覆盖初始化、生成、增量、搜索、质检、跨服务、团队记忆融合、任务记忆等全流程)和 6 个 Resource(prompts/catalog、capabilities、page-types 3 个静态 + wiki catalog / module-tree / index-status 3 个模板)。
另有 2 个遗留工具(generate_docs、get_module_tree)保留向后兼容,需先通过 codewiki config set 配置 LLM API。
CodeWiki-Plus 在 Prompt 层和引擎层做了系统性优化,显著提升生成文档的精度和效率。
### 业务规则 - **订单金额不可为负** [confidence: 0.95] > evidence: `OrderService.java:L142` — `if (amount reason: 创建订单时强制校验金额非负 lint_wiki 新增 unsupported_claims 检查:当页面中超过 30% 的业务断言缺少 evidence 时报告警告,帮助识别潜在的 LLM 幻觉。
### Component Constraint Index | Component | Type | Key Constraints | Dependencies | |-----------|------|-----------------|--------------| | OrderService | business | 金额校验、状态机流转 | PaymentClient, OrderRepo | | OrderDTO | boilerplate | 字段映射 | — | 代码路由分类 analyze_repo 阶段自动将组件分为三类,差异化处理:
典型 Java/Spring 仓库可减少 30%+ 的 LLM token 消耗。用户可在 schema.yaml 的 code_routing 配置节自定义分类规则。
文档生成 Prompt 中自动注入 1-hop 调用上下文( 块),为每个核心组件附带直接调用者/被调用者的签名摘要,帮助 LLM 理解跨模块关系:
## Neighbors of OrderService.createOrder - [caller] PaymentController.initiatePayment(PaymentRequest req) - [callee] InventoryClient.deductStock(String skuId, int qty) 增量更新 analyze_repo 内置三层增量优化:
方法级精确检测:文件变更后,逐组件比较 content_hash(SHA256 前 16 位),只有真正变化的方法/类才被标记为 stale。get_stale_components() 返回 added / modified / deleted 三类变更列表,支持级联失效关联的 Wiki 页面。
选择性重解析:仅重新解析变更文件,未变更文件的组件直接从 SQLite 缓存加载合并。skip_file_paths 参数贯穿全链路(DependencyGraphBuilder → DependencyParser → AnalysisService → CallGraphAnalyzer)。
Overview stale 精确判定:通过解析 overview.md 中的链接提取引用模块列表(持久化到 .meta/overview_refs.json),只有当 overview 实际引用了受影响模块时才标记为 stale。
analyze_repo 自动检测 monorepo 中的子服务(5 阶段启发式:docker-compose → Dockerfile → 构建清单 → 约定目录 → Spring Boot),为每个子服务分配独立标签,在依赖图上运行 CrossServiceMatcher 识别 HTTP/MQ 跨服务调用关系。
检测流程: docker-compose.yml 服务定义 → Dockerfile 构建目标 → pom.xml / build.gradle / package.json 构建清单 → src/main, app/, cmd/ 等约定目录 → Spring Boot @SpringBootApplication 入口 输出: .meta/cross_service_links.json — 跨服务调用拓扑 query_cross_service 工具可按 service/method/path/trace 维度查询 知识飞轮 笔记系统遵循 OKF v0.2 的 draft → stable → deprecated 生命周期,并叠加置信分层(confidence_level:strong / weak / shadow,与状态正交),确保 LLM 自动沉淀的知识经过研发确认:
LLM 发现跨功能约束 → ingest_note(status=draft, confidence=weak) 写入 notes/ → query_wiki 返回时标注 [unconfirmed] → 研发确认:confirm_note → 升级为 stable,记录 verified 审核事件 └ 带证据确认(test_ref/commit_ref/reviewed_by)→ 置信升 strong → 研发否决:reject_note → 标记 deprecated、置信降 shadow,默认不再被搜索返回(保留记录) 检索排序叠加置信权重(strong +0.10 / weak 0 / shadow −0.30);wiki_stats 的 confidence 段监控 strong 占比(北极星指标 >60%)。使用侧还有第三环信号——outcome 遥测:任务收尾时 report_outcome 报告成败,失败用例自动进入蒸馏提示(negative_examples),让「用错的知识」在新知识提取时被规避。
旧版词汇(candidate/confirmed/rejected/superseded)在读取端自动归一化,存量笔记无需立即迁移。两条笔记矛盾时可 flag_conflict 立案(顶级 conflicts/ 案卷),adjudicate_conflict 裁决后败方自动降级。
借鉴 Team-Agent-Memory 的"从对话中提取可检索经验"能力,融合进知识飞轮,让 Agent 与研发的日常对话也能沉淀为可检索的实践经验。
隐私语义(T2 团队遥测): query_wiki 的检索命中与 capture_conversation 的采纳记录会以 user_id(优先 CODEWIKI_USER 环境变量,其次仓库本地身份钉 repowiki/.meta/user_id,再回退 git config user.email / git config user.name / 系统登录名)署名写入 repowiki/.meta/telemetry/ .jsonl 并随仓库共享——此前这是 gitignore 的本机私有数据。user_id 不做鉴权(信任模型与 confirm 闸门一致:能提交即团队可信成员),仅作命名空间;不愿以 git 真名署名的成员可用 CODEWIKI_USER 设置花名,或在 schema.yaml 中设 conventions.telemetry.enabled: false 退回纯本机模式(写入 repowiki/.meta/telemetry-local/,已 gitignore,聚合逻辑不变)。
身份钉为什么存在: 解析链的其余每一环都是进程环境的函数——%APPDATA%/HOME 决定机器缓存和 git config 读不读得到,读不到就落到 os.getlogin()。同一台机器上 IDE 服务态拉起的 MCP 进程与登录 shell 因此会解析出两个 user_id,把同一个人切成 tasks/ /memories/ 下两个分片。克隆是唯一每个通道都必然共享的工件,所以每次由 git -C config user.email(回退 user.name)验证过的身份都会写进 repowiki/.meta/user_id(已 gitignore、可重建),后续通道一律继承;机器缓存与登录名不允许写钉——缓存只是过去某次派生的记忆化,而那次派生本身可能就是退化通道的登录名兜底,把它钉到克隆上会把错误身份永久固化。get_task_context / add_task_memory 会回显 user 与 user_source(env|pin|git-email|git-name|cache|login|local),来源异常即可见;换身份 = 删这个文件。
任务记忆解决"长线工作跨会话断片"的问题:一个任务往往持续数天、横跨多个会话,Agent 每次重启都要从零了解"上次做到哪了"。任务记忆与 Wiki 笔记互补——Wiki 笔记沉淀跨任务的通用经验,任务记忆保存任务范围内的进度知识(本次做了什么、下一步、待办)。
会话开始: list_tasks(status="active") → 选择关联已有任务或新建 → set_session_task 绑定会话(后续采集自动携带 task_id) → get_task_context 拉取任务描述 + 分层记忆 + 关联笔记 → 若 pending_raw_count > 0:委托「蒸馏 worker」subagent 后台补蒸馏,不阻塞开始工作 → 若 compaction_due:顺手 compact_task_memories 压缩旧记忆(原文进 archive,可逆) 会话过程中: distill_conversation 双轨产出: notes → 通用知识笔记(走 confirm_note 评审) memories → 任务进度记忆(直写落盘,ADR-0002:可逆操作免确认闸门) → 需要找回旧条目时 search_task_memories(条目级检索,archive 可搜) 存储结构:
repowiki/ ├── tasks/ │ ├── .index.json # 任务索引 │ └── / │ ├── task.md # 任务描述 │ ├── memories/ .md # 按用户分文件的任务记忆(追加式原子写,git 冲突隔离) │ └── memories-archive/ .md # 压缩后的原文(append-only,可找回) └── .meta/ └── task_bindings/ # 会话 ↔ 任务绑定 关键约束:
query_wiki 支持三种消费模式,让 Agent 按需逐层深入,避免一次性加载过多内容:
Agent 消费路径: query_wiki(mode=overview) → 了解项目 → query_wiki(mode=directory) → 找到目标页面 → query_wiki(query="xxx", expand=true) → 深入阅读 存储架构 CodeWiki-Plus 采用 SQLite 主存储 + JSON 兼容副本 的双层架构:
SQLite({repo}/.codewiki/analysis_cache.db):组件索引(含 content_hash)、文件指纹、依赖关系、BM25 搜索索引(token 级倒排)、符号映射(symbol_map)、路由表均存储在 SQLite 中,支持高效查询和增量更新。
JSON 兼容副本(output_dir/.meta/):symbol_map.json、module_tree.json 等保留精简 JSON 副本,供外部工具直接读取。
持久化项目映射(.meta/project.json):analyze_repo 执行后自动写入 repo_path、output_dir、cache_db 的绝对路径映射。这使得 query_wiki、ingest_note 等知识管理工具在无活跃 session 时也能通过 project.json 定位 SQLite 数据库,走 BM25 索引搜索。
搜索路径优先级: 活跃 session.cache → .meta/project.json → cache_db → SQLite BM25 ↘ 回退:output_dir.parent/.codewiki/analysis_cache.db ↘ 最终回退:.meta/search_index.json(全量遍历) LLM Wiki 知识系统 除了文档生成,CodeWiki-Plus 还内置了 LLM Wiki 知识管理能力,让生成出的 Wiki 持续演进为项目的活知识库。
所有 Wiki 内容按页面类型(page type)组织在 wiki/ 子目录下,由 page_router.py 统一路由:
write_doc_file 工具的 page_type 参数指定类型即可自动路由到正确目录。
schema.yaml 是项目的文档"宪法",包含项目定位(purpose 字段)、命名规范、必需章节、文档维度、lint 设置、page_types 路由表、以及 code_routing 代码路由规则。CodeWiki-Plus 安装目录下的 schema.yaml 是与语言无关的默认模板,首次 analyze_repo 时会读取它生成项目级 schema.yaml。
自定义:将安装目录的 schema.yaml 拷贝到项目的 output_dir(如 repowiki/schema.yaml)并修改,即可覆盖默认值;增量更新时自动合并保留自定义字段。
query_wiki 搜索结果为每条结果标注 source_type,帮助 Agent 判断信息可信度:
通过 ingest_source 和 retract_source 管理第三方文档(API 文档、设计规范、RFC 等)的完整生命周期:
// 导入外部文档(必填 source_ref:源文件的绝对路径) { "name": "rfc-7519-jwt", "source_type": "rfc", "source_ref": "/path/to/rfc7519.txt", "description": "JWT 规范", "related_pages": ["auth-module"] } // 撤回外部文档(两种模式,必填 name:ingest_source 注册的标识) { "name": "rfc-7519-jwt", "mode": "flag_stale" } // 标记过期,保留文件 { "name": "rfc-7519-jwt", "mode": "remove_refs" } // 删除文件,清理所有引用 文档健康检查 lint_wiki 提供 25 项检查(error 6 / warning 11 / info 8),覆盖结构完整性和内容质量:
lint_wiki 返回 health_score(0-100),计算方式为 100 - Σ(error×10 + warning×3 + info×1)。
生成的 Wiki 遵循谷歌 Open Knowledge Format v0.2 规范,每个 Markdown 页面携带标准化 frontmatter:
存量旧版 Wiki 可用一次性迁移脚本升级:python scripts/migrate_okf.py (幂等、可 --dry-run 预览)。
MCP Server 内置 23 个工作流 Prompt,在 AI IDE 中通过 Prompt 面板直接触发,Agent 自动编排多工具调用:
帮我分析当前仓库并生成 Wiki 文档,输出到 repowiki 目录。请使用中文撰写文档。 场景 2:增量更新
代码有改动,帮我更新受影响的模块文档。 Agent 调用 analyze_repo,自动检测变更文件和 stale 组件,只重新生成受影响的模块。
搜索项目中关于"订单状态机"的所有知识。 Agent 调用 query_wiki(query="订单状态机", hop=1),返回相关文档 + 图谱关联页面。
记录一个踩坑:Redis 连接池在高并发下偶尔超时,根因是 maxTotal 设置过低。 Agent 调用 ingest_note(note_type="pitfall", status="draft"),写入笔记待确认(检索带 [unconfirmed] 前缀)。
确认 notes/pitfall-redis-connection-pool.md 这条笔记。 Agent 调用 confirm_note(note_file="pitfall-redis-connection-pool.md"),升级为 stable 正式知识(可带 test_ref/commit_ref 证据升 strong 置信)。
把 docs/stripe-api-reference.md 导入 Wiki,关联支付模块。 场景 7:检查文档健康度
检查一下 Wiki 文档的健康状况。 Agent 调用 lint_wiki,返回 25 项诊断报告和 health_score。
分析这个 monorepo 里各服务之间的调用关系。 Agent 调用 analyze_repo(自动检测子服务)→ query_cross_service(filter_type="all")。
继续上次的"支付重构"任务。 Agent 调用 list_tasks 找到任务 → set_session_task 绑定会话 → get_task_context 恢复上下文(做了什么、下一步),若有未蒸馏对话委托「蒸馏 worker」subagent 后台补蒸馏(不阻塞),然后无缝继续工作。
除 CodeBuddy 外,任何支持 MCP stdio 协议的 AI IDE 均可使用:
Claude Desktop:在 ~/Library/Application Support/Claude/claude_desktop_config.json(macOS)中添加 MCP 配置。
其他 IDE:指定 command: "codewiki", args: ["mcp"] 即可。
对话采集 Hook(team-memory-hook)按家族归并支持多种智能体。下表由注册表 codewiki/hooks.yaml 经 hook_registry.support_matrix_markdown() 生成(单一事实来源是注册表——增减智能体/改档位请改 hooks.yaml,勿手改本表):
"已验证"指日常使用背书;"理论支持"指家族归并推导、未经真机验证——接线后请按 team-memory-hook prompt 的模拟事件步骤验证。不支持 hook 的运行时可用 capture_conversation MCP 工具手动采集。
档位 × 采集开关 选择表(决策树见 docs/接线档位选择设计方案.md §3.12,先用 codewiki install-hooks --status 看支持性与当前采集状态):
主动沉淀(ADR-0014)固定启用:任务记忆唯一通道是 add_task_memory 直写,蒸馏固定只产经验笔记(memories_skipped_reason=channel_exclusive)。
选择入口:codewiki install-hooks [--capture on|off] [--status]。档位由 hooks.yaml 注册表自动判定——支持 SessionStart 的宿主走 hook 档,不支持的(qwenwork)走 prompt 档,无手动覆盖(--mode 已移除,传入即硬报错)。
无 MCP 环境的检索:codewiki query " " CLI 命令输出 Agent 友好的定界文本块(与 query_wiki 同一引擎),配合 codewiki/agents/wiki-recall.md subagent 定义(拷入各工具的 agents 目录),任何能执行 shell 命令的 Agent 均可消费团队知识库。
如果你更习惯命令行一键生成,原始的 CLI 方式完全不受影响。需要先配置 LLM API:
codewiki config set \ --provider openai-compatible \ --api-key YOUR_KEY \ --base-url https://api.example.com \ --main-model claude-sonnet-4 \ --cluster-model claude-sonnet-4 codewiki generate 支持 OpenAI、Anthropic、Azure OpenAI、AWS Bedrock 等 API 模式(订阅模式的历史用法可参考上游项目 README)。
Python、Java、JavaScript、TypeScript、C、C++、C#、Kotlin、Go、PHP
CodeWiki-Plus 的核心工具链(Tree-sitter AST 解析、依赖图构建、拓扑排序、Mermaid 校验)源自 FSoft-AI4Code/CodeWiki,本项目在其基础上独立演进,感谢原作者团队的开拓性工作。以下开源项目的设计思路对我们产生了重要影响:
我们在上游基础上将 MCP Server 从黑盒模式拆分为 53 个细粒度工具,并新增结构化 Wiki、Evidence-Based 断言、代码路由分类、知识飞轮(OKF v0.2 + 置信分层 + 冲突治理 + 使用结果信号)、渐进式阅读、方法级增量检测、monorepo 跨服务分析、团队记忆融合(采集 → 蒸馏 → 归纳 → 技能编译)、任务记忆(条目级检索 + 自动压缩)等能力。
上游论文:CodeWiki: Evaluating AI's Ability to Generate Holistic Documentation for Large-Scale Codebases
@misc{hoang2025codewikievaluatingaisability, title={CodeWiki: Evaluating AI's Ability to Generate Holistic Documentation for Large-Scale Codebases}, author={Anh Nguyen Hoang and Minh Le-Anh and Bach Le and Nghi D. Q. Bui}, year={2025}, eprint={2510.24428}, archivePrefix={arXiv}, primaryClass={cs.SE}, url={https://arxiv.org/abs/2510.24428}, }
CodeWiki-Plus is a repository knowledge engine driven entirely by the AI IDE's own model (CodeBuddy, Cursor, Claude Desktop, etc.) via MCP (Model Context Protocol): zero LLM configuration for Wiki generation, plus a full knowledge management engine on top — retrieval, notes, task memory, and team telemetry.
The project originated as a fork of FSoft-AI4Code/CodeWiki and has since evolved independently on top of its toolchain (Tree-sitter AST parsing, dependency graph construction, topological sort, Mermaid validation) into a standalone project with a different architectural focus — see Acknowledgements.
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.
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.
We refactored CodeWiki's MCP Server from a "one-click black box" into 53 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:
Before: IDE → generate_docs(repo) → [CodeWiki calls LLM API internally] → result After: IDE Agent → analyze_repo → read_code → (Agent reasons) → write_doc → overview ↑ pure tool ↑ pure tool ↑ IDE's own model ↑ pure tool Differences from upstream CodeWiki Dimension Upstream CodeWiki CodeWiki-Plus LLM config Must configure API key Zero-config, IDE model driven Generation mode Black-box one-click 53 fine-grained tools, full Agent control Doc quality Generic descriptions Evidence-Based assertions (code quotes + confidence) Generation efficiency All components equal Code routing: boilerplate gets signature-only Context precision Intra-module components BFS 1-hop call graph + constraint index table Incremental update File-level Git diff Method-level content_hash detection Knowledge management None Structured Wiki + note flywheel + external docs Knowledge trust None Confidence levels (strong/weak/shadow) + conflict cases + outcome telemetry Task memory None Cross-session task context + entry-level recall + auto-compaction Search None BM25 + wikilink graph multi-hop + progressive reading Cross-service None Monorepo sub-service detection + call tracing Quality assurance None 25 lint checks + health score + issue tracking Prerequisites Python 3.12+ Node.js (for Mermaid diagram validation; without it, validation is silently skipped) An MCP-compatible AI IDE (CodeBuddy, Cursor, Claude Desktop, etc.) Quick Start (CodeBuddy Example) 3 steps, no API key needed.
codewiki --version For developers (latest unreleased changes) — uv is recommended to reproduce the dev environment exactly as locked by uv.lock (tool.uv.default-groups = ["dev"] includes dev tools):
One-shot wiring (recommended): run codewiki setup to wire hooks + session capture, create/merge the project-root .mcp.json, and generate the codewiki-* skill files in a single pass (--lang zh|en injects CODEWIKI_LANG and picks the skill language; --dry-run previews). The generated MCP interpreter is platform-specific (python on Windows, python3 on macOS/Linux). The steps below are the manual equivalent.
Add the following to your CodeBuddy MCP settings:
Open the target project in CodeBuddy, switch to Agent mode, and enter:
Analyze the current repository and generate Wiki documentation into the repowiki directory. Write docs in English. The Agent follows a 5-stage pipeline:
Stage 1: Call analyze_repo → get component index, leaf nodes (auto-detects monorepo sub-services, builds cross-service topology) Stage 2: Call get_prompt("cluster") for clustering rules Read source code, reason about grouping, call save_module_tree Stage 3: Document each module leaf-first Leaf modules: read_code → reason → write_doc_file (prompt auto-injects BFS call context + constraint index + business rules extraction) Parent modules: read child docs → synthesize → write_doc_file Stage 4: Generate repository overview (overview.md) Stage 5: Call close_session to free resources, build search index MCP Tools All tools require zero LLM config. The IDE Agent invokes them via MCP. The server includes built-in instructions, 23 Workflow Prompts (covering init, generation, incremental update, search, quality check, cross-service analysis, team memory fusion, task memory), and 6 Resources (3 static + 3 templates).
2 legacy tools (generate_docs, get_module_tree) retained for backward compatibility.
Module documentation prompts require LLM to provide code evidence for each business rule:
### Business Rules - **Order amount must be non-negative** [confidence: 0.95] > evidence: `OrderService.java:L142` — `if (amount reason: Enforced validation on order creation lint_wiki includes unsupported_claims check: warns when >30% of business assertions lack evidence.
Components are classified into three categories for differentiated processing:
Reduces LLM token consumption by 30%+ on typical Java/Spring repos. Customizable via code_routing in schema.yaml.
Prompts auto-inject 1-hop call context ( block) with caller/callee signatures for each core component.
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.
Notes follow the OKF v0.2 draft → stable → deprecated lifecycle, augmented with confidence levels (strong/weak/shadow, orthogonal to status):
LLM discovers cross-cutting constraint → ingest_note(status=draft, confidence=weak) → query_wiki annotates [unconfirmed] → Developer confirms: confirm_note → promoted to stable, records a verified event └ with evidence (test_ref/commit_ref/reviewed_by) → confidence promoted to strong → Developer rejects: reject_note → marked deprecated, confidence drops to shadow, excluded from search (record preserved) Retrieval ranking folds confidence weight (strong +0.10 / weak 0 / shadow −0.30); wiki_stats tracks the strong ratio as a north-star metric (>60%). A third usage signal closes the loop — outcome telemetry: report_outcome records whether using a doc led to success or failure at task wrap-up; recent failures feed distillation prompts (negative_examples) so the same misuse patterns are avoided when extracting new knowledge.
Contradictory notes can be filed as conflict cases (flag_conflict → top-level conflicts/) and adjudicated (adjudicate_conflict), with the losing side automatically demoted.
Inspired by Team-Agent-Memory's "extract retrievable experience from conversations", this capability is fused into the Knowledge Flywheel so day-to-day dialog between the Agent and developers also becomes retrievable practical knowledge.
Privacy semantics (T2 team telemetry): query_wiki retrieval hits and capture_conversation adoption records are written to repowiki/.meta/telemetry/ .jsonl (committed to the repo) under a user_id resolved from the CODEWIKI_USER env var, then the repo-local identity pin repowiki/.meta/user_id, then git config user.email / git config user.name / the OS login name — this data used to be a gitignored local file. The user_id is not an auth mechanism (trust model equals the confirm gate: anyone who can commit is a trusted teammate), it is a namespace only. Members who prefer not to sign telemetry with their git name can set a pseudonym via CODEWIKI_USER, or set conventions.telemetry.enabled: false in schema.yaml to fall back to local-only mode (written to repowiki/.meta/telemetry-local/, gitignored; aggregation is unchanged).
Why the pin exists: every other rung of that chain is a function of the process environment — %APPDATA%/HOME decide whether the machine cache and git config are readable at all, and when they are not the resolver drops to os.getlogin(). An MCP server spawned by the IDE therefore resolves a different user_id than a login shell on the same machine, splitting one person across two tasks/ /memories/ shards. The clone is the one artifact every channel certainly shares, so every identity verified on the spot by git -C config user.email (falling back to user.name) is written to repowiki/.meta/user_id (gitignored, rebuildable) and later channels inherit it. Neither the machine cache nor the login name may pin: the cache only memoizes some past derivation, and that derivation may itself have been a degraded channel's login-name fallback, so pinning it would freeze the wrong identity onto the clone. get_task_context / add_task_memory echo user and user_source (env|pin|git-email|git-name|cache|login|local) so an unexpected source is visible; to change identity, delete the file.
Task Memory solves the "cross-session amnesia" problem for long-running work: a task often spans days and multiple sessions, and the Agent normally restarts from zero. Task Memory complements Wiki notes — Wiki notes capture cross-task general knowledge, while task memories hold task-scoped progress (what was done, what's next, todos).
Session start: list_tasks(status="active") → pick an existing task or create one → set_session_task binds the session (captures carry task_id automatically) → get_task_context restores description + layered memories + related notes → if pending_raw_count > 0: catch-up distillation before working → if compaction_due: compact_task_memories (originals archived, reversible) During the session: distill_conversation produces two tracks: notes → general knowledge notes (confirm_note review) memories → task progress memories (direct write per ADR-0002: reversible, no confirm gate) → search_task_memories recalls old/truncated entries when needed (archives searchable) Storage layout:
repowiki/ ├── tasks/ │ ├── .index.json # task index │ └── / # task.md + memories/ .md + memories-archive/ └── .meta/ └── task_bindings/ # session ↔ task bindings Key constraints:
The MCP server includes 23 built-in workflow prompts that can be triggered from the AI IDE's prompt panel. The Agent automatically orchestrates multi-tool calls:
The core toolchain (Tree-sitter AST parsing, dependency graph, topological sort, Mermaid validation) originated from FSoft-AI4Code/CodeWiki; CodeWiki-Plus has evolved independently on top of it — many thanks to the original authors. Influenced by:
Paper: CodeWiki: Evaluating AI's Ability to Generate Holistic Documentation for Large-Scale Codebases
ai code-analysis developer-tools documentation llm mcp
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
None of the files in this release were uploaded with provenance metadata.
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.




