Skip to main content Switch to mobile version codewiki-plus 5.16.3 Transform codebases into comprehensive documentation using AI-powered analysis
pip install codewiki-plus==5.16.3 Copy PIP instructions
用 AI IDE 驱动的代码仓库文档生成与知识管理工具 AI IDE-Driven Code Documentation Generator & Knowledge Engine
「迎风追日 / WanderingBug」公众号发布的本项目系列技术专栏,欢迎阅读:
专栏开篇词:从代码文档到 AI 知识引擎(2026-07-26)
第 2 篇:双层 Prompt 架构同时服务人和模型(2026-08-01)
第 4 篇:知识写入方式全景(2026-08-09)
第 5 篇:OKF 0.2 规范介绍和实战(2026-08)
第 6 篇:借助 HOOKS 机制实现跨会话记忆和任务管理(2026-08)
第 7 篇:记忆/经验分层提取——自生长的团队知识库(2026-08)
第 8 篇:四维代码评审——让踩过的坑自动变成 CHECKLIST(2026-08)
第 9 篇:多仓Harness集中式管理方案(2026-09)
第 10 篇:如何让AI写的Wiki可信——项目知识全生命周期管理(2026-09)
第 11 篇:从对话中提炼经验编译成技能——谷歌 WikiSkill 落地实践(2026-09-09)
第 12 篇:本地知识库团队化改造(2026-09-21)
第 13 篇:CodeWiki-Plus 全景回顾——一个自进化代码知识库的自我修养(2026-10)
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 的差异
Node.js(用于 Mermaid 图表校验,不安装则图表校验会静默跳过)
一个支持 MCP 的 AI IDE(CodeBuddy、Cursor、Claude Desktop 等)
pip install codewiki-plus 验证安装:
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(进程只在启动时读取一次)。
真正需要用户设置的只有 2 个(其余均有合理默认值):
注意取值语义三套并存,勿套惯性: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 层和引擎层做了系统性优化,显著提升生成文档的精度和效率。
生成模块文档时,Prompt 要求 LLM 对每条业务规则提供代码证据:
### 业务规则 - **订单金额不可为负** [confidence: 0.95] > evidence: `OrderService.java:L142` — `if (amount reason: 创建订单时强制校验金额非负 lint_wiki 新增 unsupported_claims 检查:当页面中超过 30% 的业务断言缺少 evidence 时报告警告,帮助识别潜在的 LLM 幻觉。
每个模块文档自动生成结构化的约束索引表,方便 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) 增量更新
Git 策略(优先):通过 git diff 比对当前 HEAD 与上次生成时的 commit,识别变更文件
SHA256 指纹策略(回退):通过文件内容哈希(前 64KB)+ mtime 双重检测变更
方法级精确检测:文件变更后,逐组件比较 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 Memory Fusion)
借鉴 Team-Agent-Memory 的"从对话中提取可检索经验"能力,融合进知识飞轮,让 Agent 与研发的日常对话也能沉淀为可检索的实践经验。
capture_conversation:将对话转录采集到 repowiki/raw/(仅落盘、不蒸馏),支持 session 覆盖去重。可由 IDE 的 SessionEnd 事件自动触发(默认关闭,通过 team-memory-hook Prompt 启用)。
distill_conversation:将 raw 对话蒸馏为结构化 Wiki 笔记(标题/类型/关联模块)。采用 Mode C 协议——prepare 取出 transcript+system prompt → Agent 自行提取 → submit 交回 distilled JSON,全程无状态、不自动发生。产出入库为 status=draft,需 confirm_note 确认才成正式知识。
自动采集 Hook 只落 raw,永不自动蒸馏;蒸馏须显式调用 distill_conversation。
repowiki/raw/ 是暂存区,不进 query_wiki 检索;蒸馏完成后由工具自动清理(除非 keep_raw)。
触发形态为 both:手动命令(主)+ IDE Hook(可选)。
自动采集/任务引导 Hook 接线支持 CodeBuddy(.codebuddy/)、Qoder(.qoder/)、Claude Code(.claude/)、TRAE(.trae/,配置文件为 hooks.json);千问办公(QwenWork)无 shell hook 机制,走 prompt 档(只注入 AGENTS.md 引导段 + 主动沉淀协议块,用 --ide qwenwork 显式触发)。启用时运行 codewiki install-hooks --repo-path 自动检测项目根目录存在哪些 IDE 配置目录,检测到哪些就为哪些接线(拷贝 hook 脚本与 distill-worker subagent、幂等合并 settings.json/hooks.json、写入 AGENTS.md 引导段);采集脚本对事件载荷做了通用化处理。配置中的命令路径一律用项目相对形式(如 python ".codebuddy/hooks/task_session_start.py"),不写机器相关绝对路径、也不用各宿主的 $*_PROJECT_DIR 占位符(实测展开不可靠)——文件随仓库共享,队友克隆到任意目录都能工作;历史遗留的绝对路径/占位符条目重跑 install-hooks 会原地迁移。显式 --ide 默认要求该 IDE 配置目录已存在——仓库只为实际在用的工具接线;确需为尚未初始化的工具创建配置目录时,须显式加 --create-dir(防止 Agent 代跑命令时越权新建 .qoder/.claude 等目录)。
隐私语义(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/ # 会话 ↔ 任务绑定 关键约束:
task_id 由标题 slugify 生成且不可变;同名任务被拒绝;无重命名(删除后重建)。
任务记忆直写落盘(ADR-0002)——可逆操作(archive 兜底)不设确认闸门,与笔记评审闸门刻意区分:笔记是跨任务共享知识须评审,记忆是任务内进度事实。
记忆超阈值(40 条 / 24KB)自动压缩:get_task_context 携带 compaction_action 派发指令,由异步子代理跑 prepare→写摘要→submit,待压条目不进主 Agent 上下文,无需用户确认。
可选的 IDE SessionStart Hook(默认关闭)在会话开始时自动提示关联任务。
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)并修改,即可覆盖默认值;增量更新时自动合并保留自定义字段。
交叉链接注入:write_doc_file 根据组件级依赖关系自动在文档末尾注入"相关模块"章节(Depends on / Used by),通过 schema.yaml 中的 auto_crosslink 开关控制
别名(aliases):文档 frontmatter 中可声明 aliases 列表,搜索时别名获得 3× BM25 权重提升
来源引用(source_refs):正文中使用 [^src:name:line_range] 标记第三方文档出处
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:
type(必填):页面类型,如 Module / Entity / Concept / Source,由 write_doc_file 自动注入
generated:{ by: codewiki/5.2.0, at: } 生产者溯源(actor 约定: / 、human: 、process: )
status:生命周期状态 draft → stable → deprecated,笔记默认 draft,经 confirm_note 确认后升级为 stable
stale_after:知识保鲜期(默认 90 天,schema.yaml 的 conventions.default_stale_days 可调),过期由 lint 提示复核
verified:confirm_note 追加 {by, at} 审核事件,支撑 machine-confirmed / human-reviewed 信任分级
sources:引用外部文档时自动从 source_registry.json 生成 {id, resource, title} 列表
wiki/index.md 声明 okf_version: "0.2" 并采用 §8 列表格式,log.md 采用 §9 按日期分组格式
存量旧版 Wiki 可用一次性迁移脚本升级:python scripts/migrate_okf.py (幂等、可 --dry-run 预览)。
类型过滤:type_filter 限定搜索范围(module/entity/concept/source/comparison/query)
作用域前缀:scope 支持目录前缀(如 wiki/entities、notes)
权重增强:aliases 3× boost、severity 2× boost
图谱多跳扩展:hop(0-3)沿 wikilink 有向边 BFS 发现关联页面,decay 控制衰减
深度阅读:expand=true 返回完整页面内容(≤ 3000 字符)
渐进模式:mode=overview/directory/detail 分层消费
状态过滤:默认跳过 deprecated/shadow 笔记(include_shadow 显式开启),draft 标注 [unconfirmed]
get_prompt 支持 23 种 prompt_type:
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 均可使用:
Cursor:在 Settings → MCP 中添加相同的 Server 配置。
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 工具手动采集。
trae:无 SessionEnd 事件、Stop 每轮触发但不携带 transcript_path,hook 采集无正文可落盘;但 SessionStart / UserPromptSubmit 完整注入(hookSpecificOutput.additionalContext)。主动沉淀固定启用(ADR-0014):会话停顿点直写任务记忆/草稿笔记(下轮零延迟),对话捕获由 Agent 收尾轮 norm 兜底。
cursor:家族归并推导(verified: false),接线后必须跑模拟事件验证;该家族 stop 事件不带 transcript_path,无正文可采、不落盘,采集降级。
qwenwork:无 shell hook 机制,走 prompt 档 + 主动沉淀(固定启用),全靠注入文件自动加载 + Agent 中介执行。
档位 × 采集开关 选择表(决策树见 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 以及 Claude Code / Codex 订阅模式(此模式的历史用法可参考上游项目 README)。
Python、Java、JavaScript、TypeScript、C、C++、C#、Kotlin、Go、PHP
CodeWiki-Plus 的核心工具链(Tree-sitter AST 解析、依赖图构建、拓扑排序、Mermaid 校验)源自 FSoft-AI4Code/CodeWiki,本项目在其基础上独立演进,感谢原作者团队的开拓性工作。以下开源项目的设计思路对我们产生了重要影响:
codebase-memory-mcp — SQLite 持久化缓存架构、跨会话复用、三层降级模式
nashsu/llm_wiki — 结构化知识层设计、页面类型路由、交叉链接
Tencent/WeKnora — 外部文档管理、文档健康检查、自适应分块思路
CodingHub — MCP Server 最佳实践(instructions / prompts / resources)
我们在上游基础上将 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.
Why not just use the original?
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
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.
Step 1: Install CodeWiki-Plus
pip install codewiki-plus Verify:
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):
Step 2: Configure MCP Server
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).
Code Analysis & Review (10):
Documentation Pipeline (6):
Knowledge Management (13):
Cross-Service Analysis (1):
2 legacy tools (generate_docs, get_module_tree) retained for backward compatibility.
Documentation Quality Enhancements
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.
Three layers of incremental optimization:
Git strategy (preferred): git diff against stored commit
SHA256 fingerprint (fallback): Content hash + mtime dual detection
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.
Monorepo Cross-Service Analysis
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.
capture_conversation: Capture conversation transcripts into repowiki/raw/ (persistence only, no distillation); supports session-level supersede dedup. Can be triggered automatically by the IDE's SessionEnd event (off by default; enable via the team-memory-hook prompt).
distill_conversation: Distill raw conversations into structured Wiki notes (title/type/related modules). Uses Mode C protocol — prepare returns transcript + system prompt → Agent extracts → submit returns the distilled JSON. Fully stateless, never runs automatically. Output is ingested as status=draft and requires confirm_note to become live knowledge.
The automatic capture hook only writes raw; it never distills. Distillation must be invoked explicitly via distill_conversation.
repowiki/raw/ is a staging area excluded from query_wiki; it is cleaned up after distillation automatically (unless keep_raw).
Trigger form is both: manual command (primary) + IDE hook (optional).
The capture / task-guidance hooks are wired for CodeBuddy (.codebuddy/), Qoder (.qoder/) and Claude Code (.claude/). To enable, run codewiki install-hooks --repo-path : it auto-detects which IDE config dirs exist in the project root and wires each one found (copies the hook scripts and the distill-worker subagent, idempotently merges settings.json hook registrations, and upserts the AGENTS.md task-guidance section). The capture script parses generic event payloads. Hook command paths are emitted in a portable per-IDE form (CodeBuddy $CODEBUDDY_PROJECT_DIR/..., Qoder repo-relative, Claude Code ${CLAUDE_PROJECT_DIR}/...) — never a machine-specific absolute path — so the committed settings.json works from any teammate's checkout location; pre-existing absolute-path entries are upgraded in place on re-run. Explicit --ide requires that IDE's config dir to already exist — a repo is wired only for tools actually used in it; to deliberately create a not-yet-initialised config dir you must pass --create-dir (guards against agents conjuring .qoder/.claude dirs in repos that never used those tools).
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:
task_id is slugified from the title and immutable; duplicate titles are rejected; no rename (delete and recreate).
Task memories are written directly (ADR-0002) — reversible operations (archive-backed) skip the confirm gate, deliberately distinct from the note review gate: notes are shared cross-task knowledge and need review, memories are task-scoped progress facts.
Memories beyond the thresholds (40 entries / 24KB) are auto-compacted: get_task_context carries a compaction_action directive, and an async worker subagent runs prepare → writes the summary → submits, so the entries to compress never enter the main agent's context — no user confirmation needed.
An optional IDE SessionStart hook (off by default) can prompt task association at session start.
Progressive Reading Protocol
query_wiki supports three consumption modes:
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:
codebase-memory-mcp — SQLite persistent cache, cross-session reuse
nashsu/llm_wiki — Structured knowledge layer, page type routing
Tencent/WeKnora — External doc management, health checks
CodingHub — MCP Server best practices
Paper: CodeWiki: Evaluating AI's Ability to Generate Holistic Documentation for Large-Scale Codebases
Author: CodeWiki Contributors
ai code-analysis developer-tools documentation llm mcp
Development Status 4 - Beta
Intended Audience Developers
License OSI Approved :: MIT License
Programming Language Python :: 3
Topic Software Development :: Documentation
Software Development :: Libraries :: Python Modules
Release files for codewiki-plus 5.16.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
Built distribution (wheel)
Total release size: 18.9 MB
Release files / codewiki_plus-5.16.3.tar.gz
Release files / codewiki_plus-5.16.3-py3-none-any.whl
Security for codewiki-plus 5.16.3
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.
A note on package security
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.
Release history Release notifications | RSS feed
Dec 1, 2026 2 release files No provenance
Nov 30, 2026 2 release files No provenance
Nov 28, 2026 2 release files No provenance
Nov 26, 2026 2 release files No provenance
Nov 2, 2026 2 release files No provenance
Oct 30, 2026 2 release files No provenance
Oct 28, 2026 2 release files No provenance
Oct 26, 2026 2 release files No provenance
Oct 22, 2026 2 release files No provenance
Oct 21, 2026 2 release files No provenance
Oct 15, 2026 2 release files No provenance
Sep 28, 2026 2 release files No provenance
Sep 27, 2026 2 release files No provenance
Sep 23, 2026 2 release files No provenance
Sep 21, 2026 2 release files No provenance
Sep 20, 2026 2 release files No provenance
Sep 14, 2026 2 release files No provenance
Sep 10, 2026 2 release files No provenance
Sep 8, 2026 2 release files No provenance
Sep 7, 2026 2 release files No provenance
Sep 5, 2026 2 release files No provenance
Sep 4, 2026 2 release files No provenance
Aug 30, 2026 2 release files No provenance
Aug 29, 2026 2 release files No provenance
Aug 27, 2026 2 release files No provenance
Aug 25, 2026 2 release files No provenance
Aug 24, 2026 2 release files No provenance
Aug 23, 2026 2 release files No provenance
Aug 16, 2026 2 release files No provenance
Aug 11, 2026 2 release files No provenance
Aug 3, 2026 2 release files No provenance
Aug 2, 2026 2 release files No provenance
Aug 1, 2026 2 release files No provenance
Jul 31, 2026 2 release files No provenance
"PyPI", "Python Package Index", and the blocks logos are registered trademarks of the Python Software Foundation.
© 2026 Python Software Foundation




