代码库语义图引擎

Nexus是一个为Claude Code设计的语义代码库图引擎,通过MCP协议实现代码库的即时感知,无需手动粘贴上下文或处理过时文件。

  • by Obelus-Labs-LLC
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 Obelus-Labs-LLC/Nexus

使用说明

纽带

语义代码库图引擎 克劳德代码. 通过MCP让Claude即时了解您的整个代码库——无需手动 上下文粘贴,没有过时的切换文件。

Nexus使用树状图扫描您的项目,构建符号图,并进行排名 BM25F+PageRank+RRF融合的文件。每个Claude Code会话都会启动 前面有正确的代码。

标题

针对Nexus回购运行内置令牌效率基准 自身:

度量 值
中位上下文缩减与初始grep 93.4%
源语料库 77个文件,572K个字符
查询 8个现实的开发任务
平均初始上下文(grep+读取) 300625个字符
平均Nexus打包上下文 16043个字符

复制它:

python benchmarks/efficiency.py --project .

看 benchmarks/README.md 方法论和如何 针对任何项目运行它。

特性

  • 12种语言开箱即用 --Python、Rust、TypeScript、JavaScript、C, Go、Java、Ruby、PHP、Kotlin、Swift、Zig、Solidity(树形图+插件)
  • BM25F+PageRank+RRF+近距融合 --正确的文件首先出现
  • 代码感知标记器 --分裂 camelCase, snake_case,以及 PascalCase 所以 getUser 火柴 get_user_by_id
  • Python的编译器级查找 — nexus_lsp 随着 definition / references / signatures / infer 通过绝地
  • 语义编辑 — nexus_extract, nexus_inline, nexus_move 为了 手术重构,默认情况下具有差异预览和模拟运行
  • 概念图 — nexus_concept 存储长期存在的建筑笔记 除了7天的会议记忆(nexus_remember)
  • 多跳探索 — nexus_explore 遵循调用/导入图 用于代理深潜(RLM模式)
  • 可选语义搜索 --插入 fastembed 融合嵌入 与BM25+PageRank的相似性
  • 跨项目集群 --跨相关存储库跟踪导入
  • 增量重新索引 --每个文件SHA-256更改检测,不完全重新扫描
  • 零后台进程 --stdio MCP传输,仅在Claude时运行 调用工具
  • SQLite WAL存储 --快速、并发、零配置

安装

pip install -e ".[rank]"

可选附加功能: [dev] 对于pytest和linting, [embed] 拉入 fastembed 对于语义搜索, [docstring] 使能够 nexus_docstring 通过克劳德·海库。

设置

1.注册为MCP服务器(一次性):

claude mcp add --transport stdio --scope user nexus -- python -m nexus serve

2.创建项目注册表:

cp nexus.toml.example nexus.toml
# edit nexus.toml with your project paths

3.扫描您的项目:

python -m nexus scan /path/to/your/project
python -m nexus scan /path/to/rust/project --languages rust

4.将Nexus策略添加到每个项目的 CLAUDE.md:

复制 templates/NEXUS_CLAUDE_POLICY.md 进入每个项目的顶部 CLAUDE.md.这个告诉打电话 nexus_start 每次会议都是第一次。

就是这样。Claude Code现在打开每个已经知道你的代码库的会话。

MCP工具(共32个)

检索

工具 目的
nexus_start 强制性首次通话。 激活项目,返回排序后的上下文+会话内存
nexus_retrieve 在活动项目中进行有针对性的搜索
nexus_read 读取文件或特定符号(path/file.py::ClassName)
nexus_symbols 在索引中按名称搜索符号
nexus_explore BM25种子的多跳图行走(RLM模式)
nexus_summarize 使用会话记忆总结活动上下文

代码智能

工具 目的
nexus_lsp 编译器等级 definition / references / signatures / infer (Python,绝地武士)
nexus_enrich 运行SCIP索引器以获得跨文件编译器的精确引用
nexus_deps 依赖关系图:进口、进口商、出口、循环存款
nexus_diff 显示当前文件和索引状态之间的漂移

重构

工具 目的
nexus_rename 跨文件符号重命名(Python为绳索,其他为文本)
nexus_extract 通过调用站点修复将一组线路提升到新功能中
nexus_inline 在所有调用站点内联Python单返回助手
nexus_move 将符号移动到另一个文件,更新导入
nexus_docstring 通过Claude Haiku自动生成文档字符串

记忆

工具 目的
nexus_remember 短期会话决策(20个字,7天TTL)
nexus_concept 长期概念图:模式、约定、不变量
nexus_feedback 自动调谐器的记录检索质量反馈

项目/分析

工具 目的
nexus_scan 完整项目扫描/重新索引
nexus_watch 文件保存时自动重新索引(监视器)
nexus_register_edit 编辑后重新索引文件
nexus_stats 项目统计(文件、符号、边、语言)
nexus_analytics 查询历史记录、热/冷文件、置信度统计
nexus_cross_project 解决集群项目之间的依赖关系

外部集成

工具 目的
nexus_integrations 列出已配置的集成
nexus_security OSV漏洞扫描依赖关系
nexus_vcs GitHub状态(PR、问题)
nexus_ci GitHub操作/CircleCI/TTravis状态
nexus_packages npm/PyPI/CDNJS查找
nexus_news 通过NewsAPI/GNews获取技术新闻
nexus_nlp NLP分析(Datamuse/NLPCloud/WolframAlpha)
nexus_ext_analytics 敏锐的IO/Wikidata分析

建筑

src/nexus/
  server/
    mcp.py            — MCP stdio server orchestrator
    state.py          — Shared state, project activation, validation
    tools_index.py    — scan, read, symbols, register_edit, watch
    tools_query.py    — start, retrieve, stats, analytics, deps, explore, ...
    tools_refactor.py — rename, enrich, extract, inline, move, lsp, concept, ...
    tools_integrations.py — security, vcs, ci, packages, news, nlp, ...
  index/
    scanner.py        — File discovery, .gitignore, SHA-256 change detection
    parser.py         — Tree-sitter extractors (12 languages)
    graph.py          — Edge building (contains, imports, calls, references)
    pipeline.py       — scan -> parse -> graph orchestrator
    scip.py           — SCIP integration for compiler-accurate enrichment
    cross_project.py  — Cross-project dependency resolution
    plugins.py        — Parser plugin system (Kotlin, PHP, Ruby, Swift, Zig, Solidity)
  rank/
    bm25.py           — BM25S with BM25F field boosts + code-aware tokenizer
    pagerank.py       — Undirected PageRank via fast-pagerank
    fusion.py         — RRF fusion (BM25 + PageRank + recency + embed)
    packer.py         — Context packing with granularity fallback
    embed.py          — Optional fastembed semantic search (BAAI/bge-small-en)
    explore.py        — Multi-hop graph walk (RLM)
    tuner.py          — Auto-tuning from query analytics
  refactor/
    rename.py         — rope-based symbol rename
    semantic_edit.py  — extract / inline / move primitives
    lsp.py            — jedi-backed goto/refs/signatures/infer
  session/
    tracker.py        — Read/edit/query action logging
    memory.py         — 7-day session memory
    concepts.py       — Long-lived concept graph
    analytics.py      — Query history analysis
  integrations/       — 8 external API modules (stdlib urllib only)
  store/
    db.py             — SQLite WAL + migrations
    schema.sql        — 12 tables
  util/
    identifiers.py    — camelCase/snake_case splitter
    config.py         — nexus.toml registry parser

排名是如何运作的

  1. BM25F --每个文件都被索引为增强令牌文档:name(3x), 签名(2x)、文档字符串(1x)、正文(1x)。标识符分为 子令牌因此 UserService 匹配两者 user 和 service.
  2. 网页排名 --按符号图连接性对文件进行评分;流行模块 上升到顶部。
  3. 近期性 --在当前会话中最近读取或编辑的文件将获得 焕然一新。
  4. 嵌入 (可选)——fastembed向量融合语义相似性 与BM25并列。
  5. RRF融合 --组合信号: score = Σ w_s / (60 + rank_s) 跨越bm25/pagerank/新/嵌入。
  6. 上下文打包器 --背包适合具有粒度的char预算 回退(完整文件→ 签名→ 名字→ 仅路径)和 中间丢失排序(开始和结束时命中率最高)。

跨会话内存

两层持久性知识,都在Claude会话中存在:

  • nexus_remember --7天TTL的短期决定,≤20个字。 非常适合“别忘了我们决定了X”信号。
  • nexus_concept --长期概念图:模式、约定、, 建筑笔记,不变量。将概念与类型关系联系起来 (related_to, depends_on, refines, implements, ...)并附上它们 特定文件或符号。可通过BFS穿越。

项目集群

跨项目导入解决方案的组相关项目:

[cluster.mystack]
cross_project = true

[cluster.mystack.project.core]
root = "/path/to/core"
languages = ["rust"]

[cluster.mystack.project.api]
root = "/path/to/api"
languages = ["python"]

然后 nexus_cross_project(cluster="mystack") 显示谁进口什么。

测试

pip install -e ".[rank,dev]"
pytest tests/ -q

187个测试,跳过1个(真正的fastembed测试仅在以下情况下运行 fastembed 是 安装)。

许可证

麻省理工学院

作者

Obelus实验室有限责任公司