CodeWiki-Plus 标志

CodeWiki-Plus

社区
mambo-wang

CodeWiki-Plus is a repository knowledge engine driven entirely by the AI IDE's own model 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.

发布者mambo-wang
代码仓库CodeWiki-Plus
语言Python
复刻数
3
星标数
17
可用工具
0
传输类型stdio
分类
许可协议MIT
链接
  • 将工具接入 AI 工作流

    CodeWiki-Plus 提供 MCP 功能,可供兼容的 AI 客户端和智能体使用。

  • 0 个可用工具

    浏览下方可调用的操作;如果服务器提供了名称和描述,也会一并显示。

  • 可直接复制的配置

    使用安装配置片段,在您首选的 MCP 客户端中配置此服务器。

  • 开源社区热度

    关联的代码仓库有 17 个 Star 和 3 个 Fork。


中文

专栏文章

「迎风追日 / WanderingBug」公众号发布的本项目系列技术专栏,欢迎阅读:

这个项目是什么?

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 的差异

能力维度上游 CodeWikiCodeWiki-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。

第 1 步:安装 CodeWiki-Plus

bash
pip install codewiki-plus

验证安装:

bash
codewiki --version

开发者选项:如需从源码开发(获取最新未发布改动),推荐使用 uv 按 uv.lock 精确复现开发环境(pyproject.toml:106 tool.uv.default-groups = ["dev"] 已包含 dev 工具):

bash
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 锁定。

第 2 步:配置 MCP Server

在 CodeBuddy 的 MCP 设置中添加以下配置(通常在设置界面的"工具"或"MCP"板块):

json
{
  "mcpServers": {
    "codewiki": {
      "command": "codewiki",
      "args": ["mcp"],
      "maxOutputLength": 500000,
      "timeout": 36000000
    }
  }
}

配置完成后,CodeBuddy 的 MCP 工具列表中应出现 codewiki 相关的 53 个工具。

环境变量配置

CodeWiki-Plus 开箱即用,默认无需设置任何环境变量。少数偏好项与逃生门通过环境变量控制,但它们必须由 MCP Server 的启动进程读取——写在 .bashrc / 系统环境变量里对 MCP 进程不可见。设置方式是在 MCP 配置 JSON 的 mcpServers.<name> 下加 env 块(即上面的第 2 步配置里追加):

json
{
  "mcpServers": {
    "codewiki": {
      "command": "codewiki",
      "args": ["mcp"],
      "maxOutputLength": 500000,
      "timeout": 36000000,
      "env": {
        "CODEWIKI_LANG": "en",
        "CODEWIKI_USER": "your-pseudonym"
      }
    }
  }
}

改完重启 MCP Server 生效。修改环境变量后,必须重启 MCP Server(进程只在启动时读取一次)。

真正需要用户设置的只有 2 个(其余均有合理默认值):

变量作用取值 / 默认何时设
CODEWIKI_LANG切换 MCP 输出语言zh(默认)/ en;~/.codewiki/config.json 的 lang 字段优先级更高,会盖掉它想用英文界面时
CODEWIKI_USER遥测署名花名(避免用 git 真名)任意非空字符串;默认回退 git config user.name不想用真名署名时

以下是有条件才设(条件不满足请勿动):

变量作用触发条件
CODEWIKI_HOME指向源码 checkout 目录未 pip install codewiki、且 hook 进程 cwd 不在 checkout 内时(IDE 以项目根为 cwd 运行通常已能命中,本仓无需设)
CODEWIKI_NO_KEYRING强制文件存凭据,跳过系统密钥环无密钥环环境(CI / 容器 / headless Linux);不设也会自动回退 ~/.codewiki/credentials.json
CODEWIKI_SERVER_LOGMCP Server 生命周期日志路径排查 server 被强杀 / 掉线时;默认 ~/.codewiki/server-lifecycle.log
CODEWIKI_RAW_TOOL_DETAIL采集是否保留成功工具结果默认开;设 0/off/false/no/none 会丢弃成功调用细节,导致后续无法编译出含完整步骤的技能——除非排障否则别关
CODEWIKI_CBM_DISABLED关闭 CBM 委派CBM 委派出问题时设 1
CODEWIKI_TEAM_MEMORY_HOOK对话采集总闸正常接线无需设——codewiki install-hooks 生成的命令已自带 --enable;仅手工调用 python -m codewiki.mcp._ide_hook 不传 --enable 时才需要 =1

注意取值语义三套并存,勿套惯性: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 内部传参,用户不要手动设置。

第 3 步:在 Agent 模式中输入提示词

打开 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_id>/               #   task.md + memories/<user_id>.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 个模板)。

代码分析与评审(10 个):

工具用途
analyze_repo分析仓库,构建依赖图,返回组件索引;支持 SHA256 增量 + 方法级 content_hash 精确检测;自动检测 monorepo 子服务
analyze_workspace扫描多仓库工作区,为每个子仓库独立生成 Wiki,顶层生成跨服务总览;默认增量:未变更仓跳过、变更仓返回受影响模块清单、新仓全量
list_components组件索引查询,支持摘要模式和前缀过滤
list_dependencies查询组件/模块依赖关系,支持分页、方向过滤、高影响力组件排名
read_code_components根据组件 ID 读取源码
view_repo_file查看仓库原始源文件内容,支持行范围截取
analyze_impact修改影响范围评估(BFS 传递性遍历,模块级聚合,高风险组件识别)
analyze_changes变更检测:自上次生成以来的代码变更与受影响文档清单
review_changes四维代码评审(按团队沉淀的评审检查清单)
watch_repo仓库变更监听

文档生成管线(6 个):

工具用途
write_doc_file创建 .md 文档(自动 Mermaid 校验 + 交叉链接注入 + page_type 路由);支持无 session 模式
edit_doc_file编辑文档(替换/插入/撤销)
save_module_tree保存模块聚类结果
get_processing_order获取叶优先的文档生成顺序
get_prompt获取各阶段的提示词模板(含 23 种 prompt_type)
close_session关闭会话释放资源,构建 BM25 索引 + wikilink 图谱,写入生成元数据

知识管理(13 个):

工具用途
query_wikiBM25 全文搜索 + wikilink 图谱多跳扩展 + 渐进式阅读(mode=overview/directory/detail);返回 source_type 与 confidence 标注;默认过滤 shadow 资产(include_shadow 显式开启)
ingest_note将开发笔记归档到 notes/,支持 8 种类型 + aliases + source_ref;默认写入 draft 状态(置信 weak,检索带 [unconfirmed] 前缀)
confirm_note将 draft 笔记升级为 stable(写 verified 审核事件);可带 evidence(test_ref/commit_ref/reviewed_by)升 strong 置信
reject_note否决笔记(降为 deprecated,置信降 shadow,默认不再被检索返回)
batch_set_status批量流转笔记状态(确认/否决多条笔记一次完成)
stamp_evidence为页面断言补盖证据戳(Evidence-Based 审计链)
ingest_source导入第三方文档到 raw/sources/,注册到 source_registry.json
retract_source撤回已导入的外部文档(flag_stale / remove_refs 两种模式)
batch_ingest批量导入:一次调用处理多个笔记/文档
init_wiki初始化 Wiki 工作区目录结构与项目级 schema.yaml
wiki_statsWiki 知识库统计(检索热度、冷笔记、晋级候选、置信分布 strong 占比、outcome 成功率)
skill_creator把已确认知识(场景块 + stable pitfall/lesson/decision 笔记 + 技能 open issues)编译为 SKILL.md 行为指令草稿(repowiki/skills/ 草稿区,两区制:进索引进 lint、不生效)。Mode C:prepare 零副作用返回候选素材/冲突预检(Jaccard>0.6)/容量预警(橙 9 只 UPDATE、红 12 先合并)/写作规范提示 → Agent 撰写 → submit 校验(失败报具体规则名)落盘、写双向溯源(source_refs ⇄ compiled_into)、追加 revisions、重建索引;空产出 no_action 合法;每批最多新建 1 份。install(用户确认后):剥离管理元数据装入生效区 .codebuddy/skills/<name>/(幂等,写 installed_at/to/hash 供漂移检测);retire:草稿标 deprecated + 生效区移除(正文保留审计,需 reason)
report_outcome使用结果信号(telemetry 第三事件,与 hit「看到」/ adopted「引用」并列):任务收尾时报告用了某文档后事情成败(success/failure 二值 + 一句话 note),双挂 doc + task_id;聚合进 wiki_stats,失败用例反哺蒸馏提示

知识治理(4 个):

工具用途
consolidate_notes把已确认笔记归纳为 L2 场景块(wiki/scenarios/,Mode C prepare/submit,带容量门控与处置审计)
refresh_doctrine从共识笔记刷新团队工作方式共识(L3 doctrine.md)
flag_conflict声明两条笔记矛盾(顶级 conflicts/ 案卷,手动声明幂等,ADR-0007)
adjudicate_conflict裁决冲突案卷(keep_a / keep_b / coexist / reject,复用 reject_note 原语)

质量保障(2 个):

工具用途
lint_wiki文档-代码一致性检查:25 项检查(含 unsupported_claims 无证据断言检测、low_adoption 低采纳检测、skill 技能页检查、open_conflicts 超期冲突)
flag_issue标记 Wiki 质量问题,驱动 health score 计算

跨服务分析(1 个):

工具用途
query_cross_service查询跨服务调用关系(HTTP + MQ),支持 by_service / by_method / by_path / trace 过滤

工作区管理(3 个):

工具用途
init_workspace把当前目录初始化(或重新同步)为多仓 harness 工作区:生成 bootstrap 克隆脚本(登记表)、.gitignore、repo-map 导航骨架、AGENTS.md 工作区约定(两跳检索路由、提交纪律)与产品级 repowiki;首次初始化必须先征询用户选择知识布局(colocated/centralized)再带 layout 调用——不传时返回 needs_layout_decision 且不写任何产物,布局持久化到 repowiki/.meta/workspace.json(两种布局都写);重跑零配置幂等——痕迹齐备(bootstrap 脚本 + .gitignore + repowiki 骨架)时为 clone-only 接管:只补克隆未克隆的业务仓(存量缺配置顺带补写)、不触碰其他文件;骨架有缺失才补齐产物并强制刷新约定块;业务仓登记走 add_workspace_repo
add_workspace_repo按克隆 URL 向工作区登记业务仓(目录名自动取仓库名):事务式同步 bootstrap.sh/ps1 登记表、.gitignore、repo-map.md 四处,默认顺带 git clone(失败只警告、不回滚登记);同名同 URL 重登记为空操作
remove_workspace_repo按子目录名移除业务仓登记(bootstrap 表、.gitignore、repo-map.md 四处),按仓归属过滤 analyze_workspace 的跨仓分析缓存(.meta routes/links/infra 与生成的 overview),并删除本地目录(不可恢复)

团队记忆融合(2 个):

工具用途
capture_conversation采集对话转录到 repowiki/raw/,仅落盘不蒸馏,支持 session 覆盖去重;顺手提取采纳声明(referenced-docs)写入遥测
distill_conversation蒸馏 raw 对话为 Wiki 笔记 + 任务记忆:Mode C prepare → Agent 提取 → submit 入库(笔记 draft 待确认;任务记忆直写,ADR-0002);prepare 携带 negative_examples(近期失败用例规避提示)

任务管理(10 个):

工具用途
create_task创建长线任务(task_id 由标题 slugify 生成,不可变、不允许重名)
list_tasks列出任务,支持 status 过滤(active / completed)
get_task查看单个任务详情
get_task_context拉取任务描述 + 分层记忆(本人热层 + 他人摘要暖层)+ 关联笔记;返回 pending_raw_count 提示补蒸馏、compaction_due 提示压缩
set_session_task将当前会话绑定到任务,后续采集/蒸馏自动携带 task_id
add_task_memory向任务追加进度记忆(按用户分文件直写,ADR-0002:可逆操作免确认)
search_task_memories任务记忆条目级检索(按关键词找回被截断/已压缩的旧条目,内存 BM25,archive 参与召回,默认只搜本人)
compact_task_memories压缩旧任务记忆为摘要(保留最近 20 条原文,原文进 memories-archive/ 可找回;两阶段 prepare/submit,Agent 顺手执行)
complete_task完成任务
delete_task删除任务(级联删除任务目录与绑定,但不删已打 task_id 标签的笔记)

另有 2 个遗留工具(generate_docs、get_module_tree)保留向后兼容,需先通过 codewiki config set 配置 LLM API。

文档生成质量增强

CodeWiki-Plus 在 Prompt 层和引擎层做了系统性优化,显著提升生成文档的精度和效率。

Evidence-Based 业务断言

生成模块文档时,Prompt 要求 LLM 对每条业务规则提供代码证据:

markdown
### 业务规则

- **订单金额不可为负** [confidence: 0.95]
  > evidence: `OrderService.java:L142` — `if (amount < 0) throw new BizException(...)`
  > reason: 创建订单时强制校验金额非负

lint_wiki 新增 unsupported_claims 检查:当页面中超过 30% 的业务断言缺少 evidence 时报告警告,帮助识别潜在的 LLM 幻觉。

组件约束索引表

每个模块文档自动生成结构化的约束索引表,方便 LLM 消费者快速定位:

markdown
### Component Constraint Index

| Component | Type | Key Constraints | Dependencies |
|-----------|------|-----------------|--------------|
| OrderService | business | 金额校验、状态机流转 | PaymentClient, OrderRepo |
| OrderDTO | boilerplate | 字段映射 | — |

代码路由分类

analyze_repo 阶段自动将组件分为三类,差异化处理:

分类典型组件处理方式
businessService, Controller, Job, Handler完整源码注入 LLM,生成详细文档
boilerplateDTO, VO, Entity, Config, Mapper仅注入签名 + 字段列表,模板化输出
infraUtil, Helper, Factory, Interceptor摘要级描述

典型 Java/Spring 仓库可减少 30%+ 的 LLM token 消耗。用户可在 schema.yaml 的 code_routing 配置节自定义分类规则。

BFS 调用图上下文

文档生成 Prompt 中自动注入 1-hop 调用上下文(<CALL_CONTEXT> 块),为每个核心组件附带直接调用者/被调用者的签名摘要,帮助 LLM 理解跨模块关系:

<CALL_CONTEXT>
## Neighbors of OrderService.createOrder
- [caller] PaymentController.initiatePayment(PaymentRequest req)
- [callee] InventoryClient.deductStock(String skuId, int qty)
</CALL_CONTEXT>

增量更新

analyze_repo 内置三层增量优化:

变更检测:首次生成后再次调用时,自动比对上次生成状态:

  • 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。

Monorepo 跨服务分析

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 <repo> 自动检测项目根目录存在哪些 IDE 配置目录,检测到哪些就为哪些接线(拷贝 hook 脚本与 distill-worker subagent、幂等合并 settings.json/hooks.json、写入 AGENTS.md 引导段);采集脚本对事件载荷做了通用化处理。配置中的命令路径一律用项目相对形式(如 python ".codebuddy/hooks/task_session_start.py"),不写机器相关绝对路径、也不用各宿主的 $*_PROJECT_DIR 占位符(实测展开不可靠)——文件随仓库共享,队友克隆到任意目录都能工作;历史遗留的绝对路径/占位符条目重跑 install-hooks 会原地迁移。显式 --ide <name> 默认要求该 IDE 配置目录已存在——仓库只为实际在用的工具接线;确需为尚未初始化的工具创建配置目录时,须显式加 --create-dir(防止 Agent 代跑命令时越权新建 .qoder/.claude 等目录)。

隐私语义(T2 团队遥测): query_wiki 的检索命中与 capture_conversation 的采纳记录会以 user_id(优先 CODEWIKI_USER 环境变量,回退 git config user.name / 系统登录名)署名写入 repowiki/.meta/telemetry/<user_id>.jsonl 并随仓库共享——此前这是 gitignore 的本机私有数据。user_id 不做鉴权(信任模型与 confirm 闸门一致:能提交即团队可信成员),仅作命名空间;不愿以 git 真名署名的成员可用 CODEWIKI_USER 设置花名,或在 schema.yaml 中设 conventions.telemetry.enabled: false 退回纯本机模式(写入 repowiki/.meta/telemetry-local/,已 gitignore,聚合逻辑不变)。

任务记忆(Task Memory)

任务记忆解决"长线工作跨会话断片"的问题:一个任务往往持续数天、横跨多个会话,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_id>/
│       ├── task.md               # 任务描述
│       ├── memories/<user_id>.md # 按用户分文件的任务记忆(追加式原子写,git 冲突隔离)
│       └── memories-archive/<user_id>.md  # 压缩后的原文(append-only,可找回)
└── .meta/
    └── task_bindings/            # 会话 ↔ 任务绑定

关键约束:

  • task_id 由标题 slugify 生成且不可变;同名任务被拒绝;无重命名(删除后重建)。
  • 任务记忆直写落盘(ADR-0002)——可逆操作(archive 兜底)不设确认闸门,与笔记评审闸门刻意区分:笔记是跨任务共享知识须评审,记忆是任务内进度事实。
  • 记忆超阈值(40 条 / 24KB)自动压缩:get_task_context 携带 compaction_work,Agent 顺手 submit,无需用户确认。
  • 可选的 IDE SessionStart Hook(默认关闭)在会话开始时自动提示关联任务。

渐进式阅读协议

query_wiki 支持三种消费模式,让 Agent 按需逐层深入,避免一次性加载过多内容:

mode返回内容适用场景
overview仓库级摘要(< 500 token)Agent 初次接触项目,快速了解全貌
directory按类型分区的页面目录(< 800 token)定位目标模块/实体
detail指定页面完整内容深入阅读特定文档
默认BM25 snippet 搜索结果关键词检索
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 统一路由:

页面类型目录说明
modulewiki/modules/模块文档(含约束索引表 + Evidence-Based 断言)
entitywiki/entities/实体页面:类、接口、数据库表、配置项等
conceptwiki/concepts/概念页面:设计模式、业务概念、架构风格等
sourcewiki/sources/外部文档摘要:导入的第三方文档
comparisonwiki/comparisons/对比分析:技术选型、方案比较等
querywiki/queries/研究查询:调研结论、问题排查记录等

write_doc_file 工具的 page_type 参数指定类型即可自动路由到正确目录。

schema.yaml 与配置

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 判断信息可信度:

source_type含义消费建议
auto_generated来自 wiki/ 目录,代码分析自动生成可直接引用
developer_note来自 notes/ 目录,人工/LLM 沉淀检查时效性和确认状态
ingested_source来自 ingest_source 导入的外部文档注意版本时效

外部文档管理

通过 ingest_source 和 retract_source 管理第三方文档(API 文档、设计规范、RFC 等)的完整生命周期:

json
// 导入外部文档(必填 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),覆盖结构完整性和内容质量:

检查项等级说明
stale_refserror引用了已不存在的组件
broken_linkserror断链(wikilink 指向不存在的页面)
okf_conformanceerrorOKF v0.2 合规审计:缺失 type/frontmatter、旧版状态词、verified 格式错误、stale_after 过期、缺 okf_version
scenario_capacityerrorL2 场景块数量达到/超过容量上限(error/warning 分级),需先 MERGE 腾位再新增
skill_sectionserror草稿区技能页缺失 schema 五段骨架(工作场景/适用条件/核心 SOP/判断逻辑/禁忌与反模式)——缺章节的指令资产不可执行
skill_linterror技能页完整兜底检查:name slug / description 触发语义 / frontmatter 完整 / 正文 ≤8KB / 敏感串 / revisions 审计链;素材过期联动 possibly_stale 与 install 后草稿漂移(warning);容量红 12 / 橙 9
undocumentedwarning高影响力组件缺少文档
orphan_pageswarning没有任何页面链接到的孤立页面
stale_sourceswarning引用了已撤回外部文档的页面
overview_stalewarningoverview.md 引用了已变更的模块
unsupported_claimswarning业务断言缺少代码证据(>30% 触发警告)
stale_evidencewarning证据戳引用的代码位置已漂移
stale_noteswarning超过 90 天且 60 天内未被检索的已确认笔记
low_adoptionwarning高频召回(≥5 次)但零采纳的 stable 笔记——内容相关但不够 actionable,建议按「步骤/命令/预期结果」重写
layout_violationswarning布局违规(文件未落在 page_types 路由的目录)
team_layout_gitignorewarning团队布局下知识树未被正确 gitignore/共享
open_conflictswarning冲突案卷超期未裁决(默认 14 天,schema.yaml lint.open_conflict_max_age_days 可调)
cyclesinfo模块间循环依赖
coverageinfo文档覆盖率不足
isolated_componentsinfo零依赖零被依赖的孤立组件
no_outlinksinfo没有链接到任何其他页面的死端页面
missing_aliasesinfo实体页面缺少 aliases 声明
superseded_pagesinfo标记为已取代(superseded/deprecated)的页面
note_clustersinfo同模块同类型笔记 ≥3 条,建议合并
scenario_orphaninfo无来源标注(metadata.source_notes)且长期未被检索的孤儿场景块,可能冗余或过时

lint_wiki 返回 health_score(0-100),计算方式为 100 - Σ(error×10 + warning×3 + info×1)。

OKF v0.2 兼容

生成的 Wiki 遵循谷歌 Open Knowledge Format v0.2 规范,每个 Markdown 页面携带标准化 frontmatter:

  • type(必填):页面类型,如 Module / Entity / Concept / Source,由 write_doc_file 自动注入
  • generated:{ by: codewiki/5.2.0, at: <ISO-8601> } 生产者溯源(actor 约定:<tool>/<version>、human:<id>、process:<id>)
  • 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 <repowiki目录>(幂等、可 --dry-run 预览)。

全文搜索

query_wiki 搜索能力:

  • BM25 排序 + jieba 中文分词
  • 类型过滤: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:

prompt_type用途
cluster模块聚类规则
system_complex / system_leaf文档生成系统指令(含 Evidence-Based + 约束索引表)
user用户 prompt 模板(含代码路由 + BFS 上下文)
overview_module / overview_repo / overview_workspace总览合成(模块/仓库/工作区)
entity_page / concept_page实体/概念页面生成
source_summary外部文档摘要
comparison_page / query_page对比分析 / 研究查询
taxonomy_planWiki 分类体系规划
extraction_scan / extraction_dedup源码实体/概念候选提取 / 候选去重
code_analysis代码结构分析工作流
impact_review / architecture_review影响评估 / 架构审查
consolidate笔记归纳为场景块
reflection对话知识沉淀候选提取(四问过滤 + 路由表)
wiki_query / wiki_ingest / wiki_lint_report知识管理工作流

工作流 Prompt

MCP Server 内置 23 个工作流 Prompt,在 AI IDE 中通过 Prompt 面板直接触发,Agent 自动编排多工具调用:

Prompt 名称面向场景核心步骤
init-wiki新项目初始化 Wiki 工作区init_wiki 创建目录 + schema.yaml → 自定义 purpose → 验证 AGENTS.md
init-workspace初始化多仓 harness 工作区询问用户选知识布局 → init_workspace(layout=...) 生成 bootstrap 脚本 + .gitignore + repo-map + 工作区约定 → 克隆业务仓 → 逐个登记后按需 init_wiki/analyze_repo → analyze_workspace
add-workspace-repo登记业务仓到工作区add_workspace_repo 事务式同步 bootstrap 登记表/.gitignore/repo-map → git clone → 建仓库级 Wiki
remove-workspace-repo移除业务仓登记remove_workspace_repo 四处同步清理 + 跨仓缓存过滤
generate-wiki完整文档生成流水线analyze_repo → 聚类 save_module_tree → 逐模块 write_doc → overview → lint → close_session
code-analysis仅分析代码结构,不生成文档analyze_repo → list_components → list_dependencies → 缓存到 SQLite
incremental-update代码变更后增量更新文档analyze_repo(增量检测)→ 识别 stale 组件 → 选择性重生成 → close_session
workspace-analysis多仓库工作区分析analyze_workspace → 逐仓库生成 Wiki → RouteNode 跨服务匹配 → Mermaid 拓扑图
cross-service-trace跨服务调用链追踪query_cross_service → RouteNode 静态匹配 → trace_path 多跳语义追踪 → 架构诊断
impact-review修改影响范围评估analyze_impact(BFS 传递性遍历)→ 模块级聚合 → 高风险组件识别 → 调用链路输出
change-review变更代码评审analyze_changes → review_changes(四维清单)→ 评审报告
architecture-review架构审查与热点分析依赖图分析 → 核心层/服务层/应用层识别 → Top 5 热点 → 耦合风险 → 入口点
extract-knowledge外部文档知识提取ingest_source 导入 → extraction_scan 候选提取 → 实体/概念页面生成 → wikilink 图谱
search-wiki知识库搜索策略指引query_wiki(BM25)→ 图谱多跳扩展 → 渐进式阅读(overview → directory → detail)
quality-checkWiki 质量全面检查lint_wiki(25 项检查)→ health_score → flag_issue 标记 → 修复建议
ingest-note经验知识归档ingest_note(8 种类型)→ draft 状态 → confirm/reject 流转 → BM25 索引
promote-note笔记晋级为正式 Wiki 页面候选筛选(stable + 高采纳 + 够老)→ 生成目标页 → 回写 promoted_to
retract-source外部文档撤回retract_source(flag_stale / remove_refs)→ 引用清理
team-memory-hook对话自动采集管理检查状态 → 启用(注册 SessionEnd 事件)/ 关闭 → 验证
distill-conversations对话蒸馏提取经验prepare 取 transcript → Agent 提取知识 → submit 去重入库 → confirm/reject 评审
task-workflow任务记忆完整工作流会话开始关联任务 → 补蒸馏 → get_task_context → 工作中沉淀 memories → 压缩/检索
consolidate-knowledge笔记归纳为场景块consolidate_notes prepare → 归纳 → submit 处置审计 → 容量治理
skill-creator知识编译为技能skill_creator prepare → 撰写 SKILL.md → submit → install(用户确认)

使用场景示例

场景 1:生成仓库文档

帮我分析当前仓库并生成 Wiki 文档,输出到 repowiki 目录。请使用中文撰写文档。

场景 2:增量更新

代码有改动,帮我更新受影响的模块文档。

Agent 调用 analyze_repo,自动检测变更文件和 stale 组件,只重新生成受影响的模块。

场景 3:搜索项目知识

搜索项目中关于"订单状态机"的所有知识。

Agent 调用 query_wiki(query="订单状态机", hop=1),返回相关文档 + 图谱关联页面。

场景 4:沉淀开发经验

记录一个踩坑:Redis 连接池在高并发下偶尔超时,根因是 maxTotal 设置过低。

Agent 调用 ingest_note(note_type="pitfall", status="draft"),写入笔记待确认(检索带 [unconfirmed] 前缀)。

场景 5:确认/否决知识

确认 notes/pitfall-redis-connection-pool.md 这条笔记。

Agent 调用 confirm_note(note_file="pitfall-redis-connection-pool.md"),升级为 stable 正式知识(可带 test_ref/commit_ref 证据升 strong 置信)。

场景 6:导入外部文档

把 docs/stripe-api-reference.md 导入 Wiki,关联支付模块。

场景 7:检查文档健康度

检查一下 Wiki 文档的健康状况。

Agent 调用 lint_wiki,返回 25 项诊断报告和 health_score。

场景 8:跨服务调用分析

分析这个 monorepo 里各服务之间的调用关系。

Agent 调用 analyze_repo(自动检测子服务)→ query_cross_service(filter_type="all")。

场景 9:跨会话延续长线任务

继续上次的"支付重构"任务。

Agent 调用 list_tasks 找到任务 → set_session_task 绑定会话 → get_task_context 恢复上下文(做了什么、下一步),若有未蒸馏对话委托「蒸馏 worker」subagent 后台补蒸馏(不阻塞),然后无缝继续工作。

支持的其他 AI IDE

除 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 的智能体支持矩阵

对话采集 Hook(team-memory-hook)按家族归并支持多种智能体。下表由注册表 codewiki/hooks.yaml 经 hook_registry.support_matrix_markdown() 生成(单一事实来源是注册表——增减智能体/改档位请改 hooks.yaml,勿手改本表):

智能体家族支持等级档位
claude-codeclaude已验证hook
codebuddyclaude已验证hook
qoderclaude已验证hook
qwenworkprompt已验证prompt
traetrae已验证hook
codex-clicodex理论支持hook
cursorcursor理论支持hook
gemini-cliclaude理论支持hook
kilocodeclaude理论支持hook
opencodeclaude理论支持hook
windsurfclaude理论支持hook

"已验证"指日常使用背书;"理论支持"指家族归并推导、未经真机验证——接线后请按 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 看支持性与当前采集状态):

档位(wiring)capture产物适用任务记忆可见延迟
hookon(默认)<config_dir>/hooks/*.py + settings 注册 + 注入引导段 + 协议块采集完整宿主(codebuddy/qoder/claude-code)默认,现状批处理0(停顿点直写)+ 采集兜底
hookoff同上,但无 SessionEnd(trae 为 Stop)采集注册主动沉淀效果好、不再需要采集→蒸馏链路0(停顿点直写)
prompton仅注入文件(引导段 + 协议块)无 shell hook 宿主(qwenwork)或团队共享仓库不留脚本/settings0

主动沉淀(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 模式(仍然可用)

如果你更习惯命令行一键生成,原始的 CLI 方式完全不受影响。需要先配置 LLM API:

bash
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

bibtex
@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},
}

English

What is this project?

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

DimensionUpstream CodeWikiCodeWiki-Plus
LLM configMust configure API keyZero-config, IDE model driven
Generation modeBlack-box one-click53 fine-grained tools, full Agent control
Doc qualityGeneric descriptionsEvidence-Based assertions (code quotes + confidence)
Generation efficiencyAll components equalCode routing: boilerplate gets signature-only
Context precisionIntra-module componentsBFS 1-hop call graph + constraint index table
Incremental updateFile-level Git diffMethod-level content_hash detection
Knowledge managementNoneStructured Wiki + note flywheel + external docs
Knowledge trustNoneConfidence levels (strong/weak/shadow) + conflict cases + outcome telemetry
Task memoryNoneCross-session task context + entry-level recall + auto-compaction
SearchNoneBM25 + wikilink graph multi-hop + progressive reading
Cross-serviceNoneMonorepo sub-service detection + call tracing
Quality assuranceNone25 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.

Step 1: Install CodeWiki-Plus

bash
pip install codewiki-plus

Verify:

bash
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):

bash
git clone https://github.com/mambo-wang/CodeWiki-Plus.git
cd CodeWiki-Plus
uv sync --frozen              # reproduce the full dev environment from uv.lock (hatchling build)
uv run codewiki --version     # run the CLI inside the uv-managed environment
uv run pytest tests/ -q       # run tests (no --cov in addopts; no override needed)
# with coverage: uv run pytest --cov=codewiki --cov-report=term-missing

Without uv, pip install -e .[dev] still works, but dependency resolution is not locked by uv.lock.

Step 2: Configure MCP Server

Add the following to your CodeBuddy MCP settings:

json
{
  "mcpServers": {
    "codewiki": {
      "command": "codewiki",
      "args": ["mcp"]
    }
  }
}

Step 3: Prompt your AI Agent

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

ToolPurpose
analyze_repoParse repo, build dependency graph; SHA256 incremental + method-level content_hash; monorepo sub-service detection
analyze_workspaceScan multi-repo workspace, generate per-repo Wikis with cross-service overview; incremental by default: unchanged repos skipped, changed repos return an affected-modules list, new repos run full
list_componentsComponent index query with summary mode and prefix filtering
list_dependenciesQuery dependencies with pagination, direction filtering, high-impact ranking
read_code_componentsRead source code by component ID
view_repo_fileView raw source file content with optional line range
analyze_impactChange impact assessment (BFS transitive traversal, module aggregation, high-risk identification)
analyze_changesChange detection: code changes and affected docs since last generation
review_changesFour-dimension code review against team-deposited checklists
watch_repoRepository change watching

Documentation Pipeline (6):

ToolPurpose
write_doc_fileCreate .md docs with Mermaid validation + crosslink injection + page_type routing; sessionless mode
edit_doc_fileEdit docs (str_replace / insert / undo)
save_module_treePersist module clustering results
get_processing_orderGet leaf-first documentation order
get_promptRetrieve prompt templates (23 prompt_types)
close_sessionClose session, build BM25 index + wikilink graph, write metadata

Knowledge Management (13):

ToolPurpose
query_wikiBM25 search + wikilink graph multi-hop + progressive reading (mode=overview/directory/detail); source_type and confidence annotation; shadow assets gated behind include_shadow
ingest_noteFile structured notes (8 types) with aliases + source_ref; default draft status (weak confidence, [unconfirmed] prefix in search)
confirm_notePromote draft note to stable (records a verified event); with evidence (test_ref/commit_ref/reviewed_by) promotes confidence to strong
reject_noteReject note (deprecated + shadow confidence, excluded from search by default)
batch_set_statusBatch transition note statuses (confirm/reject multiple at once)
stamp_evidenceStamp evidence onto page assertions (Evidence-Based audit chain)
ingest_sourceImport third-party docs into raw/sources/
retract_sourceRetract imported docs (flag_stale / remove_refs)
batch_ingestBatch import multiple notes/sources in one call
init_wikiInitialize Wiki workspace directories and project-level schema.yaml
wiki_statsWiki statistics (retrieval heat, cold notes, promotion candidates, confidence distribution, outcome ratio)
skill_creatorCompile confirmed knowledge (scenario blocks + stable pitfall/lesson/decision notes + per-skill open issues) into SKILL.md behaviour-instruction drafts in repowiki/skills/ (two-zone draft area: indexed and linted, never effective). Mode C: prepare (zero side effects) returns candidates, conflict pre-check (Jaccard > 0.6), capacity warning (orange >= 9 update-only, red >= 12 merge-first) and the writing system prompt → the agent writes → submit validates (failures name the exact rule), writes the draft, records bidirectional provenance (source_refs ⇄ compiled_into), appends revisions and rebuilds the index. Empty output (no_action) is legal; at most one new skill per batch. install (after user confirmation): strip management frontmatter into the effect zone .codebuddy/skills/<name>/ (idempotent, stamps installed_at/to/hash for drift detection); retire: mark the draft deprecated + remove the effect copy (body kept for audit, reason required)
report_outcomeUsage outcome signal (third telemetry event after hit and adopted): report success/failure after actually using a doc (binary + one-line note), dual-anchored doc + task_id; feeds wiki_stats and distillation negative examples

Knowledge Governance (4):

ToolPurpose
consolidate_notesConsolidate confirmed notes into L2 scenario blocks (wiki/scenarios/, Mode C prepare/submit, capacity gating + disposition audit)
refresh_doctrineRefresh team working-conventions consensus (L3 doctrine.md) from consensus notes
flag_conflictDeclare two notes contradictory (top-level conflicts/ case file, manual idempotent declaration, ADR-0007)
adjudicate_conflictAdjudicate a conflict case (keep_a / keep_b / coexist / reject, reuses the reject_note primitive)

Quality Assurance (2):

ToolPurpose
lint_wikiDoc-code consistency: 25 checks (incl. unsupported_claims evidence detection, low_adoption utility check, skill page checks, open_conflicts aging)
flag_issueFlag quality issues, drives health score

Cross-Service Analysis (1):

ToolPurpose
query_cross_serviceQuery cross-service calls (HTTP + MQ), filter by service/method/path/trace

Workspace Management (3):

ToolPurpose
init_workspaceInitialize (or re-sync) the current directory as a multi-repo harness workspace: generates bootstrap clone scripts (registration table), .gitignore, repo-map navigation skeleton, workspace conventions in AGENTS.md (two-hop retrieval routing, commit discipline) and the product-level repowiki. FIRST init requires an explicit knowledge-layout choice (colocated/centralized) — ask the user, then pass layout=; without it the tool returns needs_layout_decision and writes nothing. The layout is persisted to repowiki/.meta/workspace.json for BOTH layouts. Re-runs are zero-config and idempotent — when every init trace is present (bootstrap scripts + .gitignore + repowiki skeleton) a re-run is clone-only: it fetches just the uncloned business repos (backfilling a missing layout config) and touches nothing else; missing skeletons are repaired and the conventions block refreshed only in that case. Register business repos via add_workspace_repo
add_workspace_repoRegister a business repo by clone URL (directory name derived from the repo name): transactionally updates the bootstrap.sh/ps1 tables, .gitignore and repo-map.md, then git-clones by default (clone failure only warns, registration is kept). Re-registering the same name+URL is a no-op
remove_workspace_repoDeregister a business repo by subdirectory name (bootstrap tables, .gitignore, repo-map.md), scrub the repo from analyze_workspace caches (.meta routes/links/infra and the generated overview), and delete the local clone directory (irreversible)

Team Memory Fusion (2):

ToolPurpose
capture_conversationCapture conversation transcripts to repowiki/raw/ (persistence only, no distillation); session-level supersede dedup; extracts adoption declarations into telemetry
distill_conversationDistill raw conversations into Wiki notes + task memories: Mode C prepare → Agent extracts → submit (notes as draft pending confirmation; task memories direct-write per ADR-0002); prepare carries negative_examples from recent outcome failures

Task Management (10):

ToolPurpose
create_taskCreate a long-running task (task_id slugified from title, immutable, no duplicates)
list_tasksList tasks with status filtering (active / completed)
get_taskInspect a single task
get_task_contextFetch task description + layered memories (own hot layer + teammates' summaries) + related notes; reports pending_raw_count for catch-up distillation and compaction_due for memory compaction
set_session_taskBind the current session to a task; subsequent captures/distillations carry task_id automatically
add_task_memoryAppend a progress memory to the task (per-user file, direct write per ADR-0002: reversible operations skip the confirm gate)
search_task_memoriesEntry-level keyword recall over one task's memories (in-memory BM25, archives searchable, defaults to own memories)
`compact_task_memorie

安装

TypingMind
{
  "mcpServers": {
    "codewiki-plus": {
      "command": "codewiki",
      "args": [
        "mcp"
      ]
    }
  }
}

将 CodeWiki-Plus MCP 与多个 AI 模型配合使用

TypingMind 在工作区级别连接 MCP 工具,因此连接 CodeWiki-Plus 后,您就可以在 TypingMind 中搭配不同的 AI 模型使用,无需为每个模型单独设置。 此 MCP 通过您设备上的 TypingMind MCP 连接器在本地运行。

本地连接器设置指南

如果 MCP 服务器需要访问您电脑上的本地文件、应用或私有资源,请选择此方式。

1

打开 MCP 设置

在 TypingMind 中,依次前往“设置”、“高级设置”和“模型上下文协议”,然后选择“设置连接器”。

  1. 在您的浏览器中打开 TypingMind。
  2. 点击“设置”图标。
  3. 进入“高级设置”。
  4. 打开“模型上下文协议”部分。
  5. 点击“设置连接器”,然后选择“此设备”。
TypingMind MCP 连接器设置界面,已选择“此设备”
2

运行连接器命令

选择“此设备”,从 TypingMind 复制命令并在终端中运行。使用 MCP 时,请保持该进程运行。

  1. 复制 TypingMind 显示的设置命令。
  2. 在 macOS 上打开“终端”,或在 Windows 上打开 Windows Terminal。
  3. 粘贴并运行命令。
  4. 如果终端询问您是否继续,请确认安装软件包。
  5. 使用 MCP 工具时,请保持终端窗口及其中的进程运行。
3

将 CodeWiki-Plus 添加为服务器

当连接器状态为“就绪”时,点击“编辑服务器”,然后粘贴 MCP 服务器配置。

  1. 等待连接器状态显示为“就绪”。
  2. 点击“编辑服务器”。
  3. 粘贴 CodeWiki-Plus MCP 服务器配置。
  4. 保存服务器列表。
  5. 如需确认连接器是否仍处于就绪状态,请刷新。
TypingMind MCP 设置界面,显示正在运行的服务器和“编辑服务器”按钮
{
  "mcpServers": {
    "codewiki-plus": {
      "command": "npx",
      "args": [
        "-y",
        "<mcp-server-package>"
      ]
    }
  }
}
4

在不同模型中使用同一连接

保存服务器列表,打开“插件”,启用 CodeWiki-Plus MCP 工具,然后在 TypingMind 中选择任意受支持的 AI 模型,即可在聊天中使用这些工具,或将其分配给智能体。

  1. 在 TypingMind 中打开“插件”页面。
  2. 启用 CodeWiki-Plus MCP 工具。
  3. 开始聊天并选择您想使用的 AI 模型。
  4. 在聊天中使用 MCP 工具,或将其分配给 AI 智能体。
  5. 根据需要随时切换到其他 AI 模型,无需重新连接 MCP。
在 TypingMind 聊天中使用已启用的 MCP 工具和选定的 AI 模型
您能使用 CodeWiki-Plus 帮我完成这项任务吗?
CodeWiki-Plus
当然。我已阅读。
以下是我使用 CodeWiki-Plus 得到的结果。

常见问题

CodeWiki-Plus MCP 服务器有什么用途?

CodeWiki-Plus 是一个 MCP 服务器,可让兼容的 AI 客户端连接外部工具并获取上下文。在 TypingMind 中,只需添加一次此 MCP 服务器,即可在您的 AI 工作区中使用其工具。

可以在 TypingMind 中让多个 AI 模型使用 CodeWiki-Plus MCP 吗?

可以。TypingMind 在工作区层面连接 MCP 工具,因此您可以让 Claude、ChatGPT、Gemini 等不同 AI 模型,或您在 TypingMind 中配置的其他模型使用 CodeWiki-Plus,而无需为每个模型单独配置 MCP 服务器。

为什么在 TypingMind 中使用 CodeWiki-Plus MCP?

TypingMind 将多个 AI 模型、提示词、插件、AI 智能体、API 密钥和 MCP 工具整合到同一个工作区中,是优秀的大语言模型聊天前端之一。连接 CodeWiki-Plus 后,您可以在偏好的不同模型中使用其 MCP 工具,同时在 TypingMind 中井然有序地管理聊天工作流程。

如何将 CodeWiki-Plus MCP 连接到 TypingMind?

CodeWiki-Plus 通过 TypingMind 本地 MCP 连接器运行。当 MCP 服务器需要访问您计算机上的本地文件、桌面应用、命令行工具或私有资源时,这种方式最合适。

CodeWiki-Plus MCP 在 TypingMind 中提供哪些工具?

CodeWiki-Plus 提供 MCP 功能,您可以在 TypingMind 的插件页面启用这些功能,然后在聊天中使用,或将其分配给 AI 智能体。

使用 CodeWiki-Plus MCP 需要向 TypingMind 提供我的 API 密钥吗?

不需要。TypingMind 采用本地优先的设计,让您自行掌控模型提供商、API 密钥、提示词和 MCP 配置。如果 CodeWiki-Plus 需要身份验证,请在创建连接时,为该 MCP 服务器添加所需的请求头、OAuth 设置或本地配置。

相关 MCP 服务器

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇