GitNexus

📅 2026/7/30 15:05:57 👁️ 阅读次数 📝 编程学习
GitNexus

GitNexus 能帮你搭一个本地、可持续更新的“微服务代码知识库”,并生成对 Copilot 很有价值的跨服务影响参考图谱。

Repo

GitHub - abhigyanpatwari/GitNexus: GitNexus: The Zero-Server Code Intelligence Engine - GitNexus is a client-side knowledge graph creator that runs entirely in your browser. Drop in a GitHub repo or ZIP file, and get an interactive knowledge graph wit a built in Graph RAG Agent. Perfect for code exploration

Steps

先把每个微服务都做本地索引
npminstall-ggitnexus gitnexus setupcdservice-a&&gitnexus analyze--embeddingscd../service-b&&gitnexus analyze--embeddingscd../service-c&&gitnexus analyze--embeddings

这样每个仓库都会生成本地.gitnexus索引,并注册到 ~/.gitnexus/registry.json。

把所有微服务编成一个 group
gitnexus group create company gitnexus list gitnexus groupaddcompany biz/user user-service gitnexus groupaddcompany biz/order order-service gitnexus groupaddcompany biz/payment payment-service gitnexus groupsynccompany

这里的关键是group sync:它会抽取跨仓 contract 并建立 cross-links,这一步才是“微服务知识图谱”的核心。

把 group.yaml 当成你的架构事实源补全

GitNexus 能自动识别很多静态关系,但你最好在 ~/.gitnexus/groups/company/group.yaml 里明确配置:

  • repos: 服务分组路径
  • detect: http/grpc/topics/shared_libs/thrift
  • links: 对动态 URL、消息队列、网关转发、服务发现这类代码里不容易静态推断的关系,手工补链路
    这一步很重要:GitNexus 更像“静态代码图谱 + contract 图谱”,不是运行时 service mesh。
    如果你们大量用 Kafka、RocketMQ、Nacos、动态路由、字符串拼 URL,就要靠 links 补齐。
把它接到 Copilot 的改代码流程里

最理想是你的 Copilot 客户端支持 MCP,让它连 gitnexus mcp。之后要求它在动手前固定执行:

  • impact:看某个 symbol/API 改动的上下游影响
  • context:看 360 度上下文
  • query:看跨服务执行流
  • 跨仓时把 repo 指到 @company 或 @company/ 你可以把这类约束写进 Copilot 的仓库指令里,例如: 在修改接口、DTO、service、client、controller 前,先用 GitNexus 的 impact/context/query 做 cross-repo 分析;如果命中 group,先给出受影响服务列表,再开始改代码。
把图谱变成“人可读”的本地知识库
  • 浏览图谱:gitnexus serve
  • 生成文档/wiki:gitnexus wiki
  • 查 contract:gitnexus group contracts company
  • 查改单点波及面:
    gitnexus group impact company --target CreateOrder --repo biz/order

常用命令

gitnexus group contracts

作用:查看某个 group 里已经抽取出来的 contracts 和它们之间的 cross-links。

你可以把它理解成:“当前 GitNexus 识别到了哪些服务接口/依赖契约,以及哪些仓之间连上了”。

典型输出会分两段:

  • Contracts:每条 contract 属于哪个 repo、是 provider 还是 consumer、对应什么 contractId

  • Cross-links:哪一个 repo 指向哪一个 repo,匹配类型和置信度是多少

常用过滤:

gitnexus group contracts company--typehttp gitnexus group contracts company--repobiz/order gitnexus group contracts company--unmatchedgitnexus group contracts company--json

适合场景:

  • 检查 group sync company 后有没有识别出你期望的 HTTP/gRPC/Thrift 契约

  • 看哪些服务已经连起来了

  • 用 --unmatched 找“明明有接口,但还没匹配上的链路”,方便补 group.yaml 的 links

gitnexus group impact

作用:从某个 group 成员仓里的一个 symbol 或文件 出发,分析它的 本地影响 + 跨仓 fan-out。

你可以把它理解成:“如果我改这里,会影响哪些上下游服务”。

最基本用法:

gitnexus group impact company --target CreateOrder --repo biz/order

这里最容易搞错的是:

  • company:group 名
  • –target:你要分析的符号名或文件名
  • –repo:group.yaml 里的 groupPath
  • 不是 registry 里的仓库名

比如你在 group.yaml 里写的是:

repos: biz/order: order-service biz/payment: payment-service

那就要用:

gitnexus group impact company --target CreateOrder --repo biz/order

而不是:

gitnexus group impact company --target CreateOrder --repo order-service

常用参数:

gitnexus group impact company--targetCreateOrder--repobiz/order--directionupstream gitnexus group impact company--targetCreateOrder--repobiz/order--directiondownstream gitnexus group impact company--targetCreateOrder--repobiz/order --max-depth4gitnexus group impact company--targetCreateOrder--repobiz/order --cross-depth2gitnexus group impact company--targetCreateOrder--repobiz/order --min-confidence0.8gitnexus group impact company--targetCreateOrder--repobiz/order --include-tests gitnexus group impact company--targetCreateOrder--repobiz/order--json

参数含义:

  • –direction upstream|downstream - upstream:谁依赖我、我改了会影响谁
  • downstream:我依赖谁、我会受谁影响
  • –max-depth:本仓代码关系向外查几层
  • –cross-depth:跨仓 contract bridge 最多跳几层
  • –min-confidence:过滤低置信度关系
  • –service:单仓里如果是 monorepo,可限定某个服务目录
  • –subgroup:只让某个路径前缀下的仓参与跨仓扩散