← 返回 Skills 市场
babywhale

Code Graph(代码图谱)

作者 manniu · GitHub ↗ · v1.0.1 · MIT-0
cross-platform ✓ 安全检测通过
45
总下载
0
收藏
0
当前安装
2
版本数
在 OpenClaw 中安装
/install code-graph
功能描述
一键安装 GitNexus 并为当前项目构建代码知识图谱。当用户说「安装GitNexus」「设置GitNexus」「初始化GitNexus」「配置GitNexus」「用GitNexus建图」「GitNexus一键配置」时使用。
使用说明 (SKILL.md)

代码图谱(GitNexus)

为当前项目一键完成 GitNexus 安装、MCP 配置和知识图谱构建。每一步都有跳过检测,已完成的步骤不会重复执行。

语言支持

TypeScript、JavaScript、Python、Java、C、C++、C#、Go、Rust、PHP、Swift、Dart、Kotlin、Ruby 等 14 种语言。


执行流程

按顺序执行以下步骤。每步先检测当前状态,已完成则跳过。

第 1 步:定位项目根目录

gitnexus analyze 需在项目根目录下执行。首先检查当前工作目录是否即为项目根目录:

git rev-parse --show-toplevel 2>&1 && echo "已定位到项目根目录"

如果 Git 未初始化,则通过常见项目标志文件判断:

ls package.json 2>&1 || ls pom.xml 2>&1 || ls go.mod 2>&1 || ls Cargo.toml 2>&1 || ls requirements.txt 2>&1 || echo "未找到项目根目录标志文件"
  • 当前目录即为根目录 → 继续下一步
  • 检测到其他目录为根目录 → cd 到该目录
  • 找不到任何项目标志 → 询问用户项目根目录在哪,或使用 git init 初始化

第 2 步:检查 Node.js 环境

node --version

要求 Node.js >= 22。 如果版本过低或未安装:

  • 引导用户到 nodejs.org 下载 LTS 版本
  • Windows 用户也可用 winget install OpenJS.NodeJS.LTS 安装
  • 升级完成后重新执行本技能

第 3 步:安装 GitNexus

先检测,再决定是否安装:

gitnexus --version 2>&1

判断逻辑:

  • 输出类似 1.x.x 的版本号 → 已安装,跳过本步骤,直接进入第 4 步
  • 输出 command not foundnot recognized → 未安装,执行以下安装

安装命令(Windows,推荐全局安装):

set GITNEXUS_SKIP_OPTIONAL_GRAMMARS=1 && npm install -g gitnexus

安装命令(macOS / Linux):

GITNEXUS_SKIP_OPTIONAL_GRAMMARS=1 npm install -g gitnexus

GITNEXUS_SKIP_OPTIONAL_GRAMMARS=1 跳过 Dart/Proto 原生语法解析器的编译,安装只需几秒,无需 C++ 工具链。

权限不足时的回退方案 — 如果全局安装失败(EACCES / Permission denied),后续命令统一改用 npx 前缀:

npx gitnexus analyze    # 代替 gitnexus analyze
npx gitnexus setup      # 代替 gitnexus setup
npx gitnexus status     # 代替 gitnexus status

第 4 步:配置 MCP 服务

gitnexus setup 自动检测已安装的编辑器并写入 MCP 配置,全局只需执行一次。

先检测是否已配置:

gitnexus setup 2>&1

判断逻辑:

  • 输出包含 already configuredup to dateMCP configuration exists 等字样 → 已配置,跳过
  • 输出包含 wrotecreatedconfiguredUpdated 等字样 → 配置成功
  • gitnexus 命令不可用(未全局安装),使用 npx gitnexus setup

setup 是幂等的,重复执行不会产生重复配置,可安全地直接运行。

第 5 步:构建知识图谱

先检测当前项目是否已索引:

gitnexus status 2>&1

判断逻辑:

  • 输出包含 Indexedsymbolsup to datefresh 等字样 → 已索引且是最新的,跳过本步骤
  • 输出包含 Not indexedNo index foundunknown 等字样 → 未索引,执行以下命令
  • 如果 gitnexus 不可用,改用 npx gitnexus status

执行索引:

gitnexus analyze

此命令解析整个代码库、解析导入关系、追踪调用链、检测代码社区,在项目根目录生成 .gitnexus/ 索引(自动加入 .gitignore)。优先使用gitnexus analyze进行索引,若出现错误则尝试增加选项。

如果需要强制重建(已索引但过期):

gitnexus analyze --force

常用选项:

选项 用途
--embeddings 启用语义/向量搜索,速度较慢但搜索更强
--force 强制重建索引(索引过期时使用)
--skip-embeddings 跳过嵌入生成,大幅加速(默认行为)
--skip-git 允许对非 git 目录构建索引
--skip-agents-md 保留自定义的 CLAUDE.md / AGENTS.md
--verbose 输出详细日志,包括被跳过的文件
--worker-timeout 60 大型仓库增加 Worker 超时时间

预期输出:

Scanning files... ✓ (1,247 files)
Parsing code... ✓ (TypeScript, Python, etc.)
Resolving imports... ✓ (3,892 relationships)
Tracing calls... ✓ (104 processes)
Creating indexes... ✓
Done! Indexed 30,816 symbols in 12s

第 6 步:验证

gitnexus status
gitnexus list

status 确认当前项目的索引状态,list 展示全局所有已索引的仓库。


索引后可用的 MCP 工具

工具 用途
list_repos 查看所有已索引的仓库
query 混合搜索(关键词 + 语义),按执行流程分组
context 360° 符号视图(调用者、被调用、所属流程)
impact 爆炸半径分析 — 修改某个符号会影响哪些地方
detect_changes Git diff 影响映射
cypher 原始图谱查询语言
rename 多文件协调重命名

MCP 资源:

资源 用途
gitnexus://repo/{name}/context 代码库概览 + 索引新鲜度检查
gitnexus://repo/{name}/clusters 所有功能聚类
gitnexus://repo/{name}/processes 所有执行流程
gitnexus://repo/{name}/schema 图谱 Schema(Cypher 查询用)

常见问题排查

"Not inside a git repository"(不在 git 仓库中)

git init && git add . && git commit -m "initial"
gitnexus analyze

或使用 --skip-git 跳过 git 检查:

gitnexus analyze --skip-git

"Permission denied"(npm install -g 权限不足)

改用 npx 免安装运行:

npx gitnexus analyze

"Already indexed"(已索引)

索引已存在且是最新的,无需操作。如需强制重建:

gitnexus analyze --force

"Node version too old"(Node 版本过旧)

需要 Node.js >= 22,升级后重试:

  • Windows: winget install OpenJS.NodeJS.LTS
  • macOS: brew install node
  • Linux: 使用 nvm

MCP 工具未出现在 Claude Code / Cursor 中

  1. 重新执行 gitnexus setup
  2. 重启编辑器
  3. 确认 gitnexus 在 PATH 中:Windows 用 where gitnexus,Unix 用 which gitnexus

索引过期(代码变更后)

gitnexus analyze    # 增量更新,保留已有嵌入
gitnexus analyze --force  # 完全重建

对话示例

用户:"安装GitNexus"

执行:

  1. 定位项目根目录
  2. node --version → 确认 >= 22
  3. gitnexus --version → 未安装 → npm install -g gitnexus
  4. gitnexus setup → MCP 已配置则跳过
  5. gitnexus status → 未索引 → gitnexus analyze
  6. gitnexus status → 验证成功
  7. 回复用户:"已索引 N 个符号,生成知识图谱。可通过 context / impact / query 等 MCP 工具查询代码库。"
安全使用建议
Install only if you want GitNexus added to your environment and MCP/editor configuration updated. Review project contents before indexing or committing, prefer the npx or --skip-git alternatives when appropriate, and avoid git add . unless you have checked .gitignore and confirmed all files are safe to include.
能力评估
Purpose & Capability
The stated purpose is to install GitNexus, configure MCP, and build a code knowledge graph; the commands and described outputs align with that purpose.
Instruction Scope
The workflow is mostly scoped to user-triggered GitNexus setup and indexing, but troubleshooting includes broad git initialization guidance that could capture unintended files if followed casually.
Install Mechanism
The skill recommends global npm installation or npx fallback and runs gitnexus setup; these are disclosed but should ideally be preceded by explicit user confirmation.
Credentials
Writing .gitnexus indexes, updating .gitignore, and modifying MCP configuration are proportionate for a code graph setup skill, with no evidence of unrelated data access or exfiltration.
Persistence & Privilege
Persistence is limited to installed GitNexus tooling, MCP configuration, and local project index files; no hidden background worker, credential capture, or destructive persistence was found.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install code-graph
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /code-graph 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.1
- Major rewrite: Skill now provides an automated, stepwise workflow for installing, configuring, and indexing with GitNexus in a single command. - Automatic detection: Each step (project root, Node.js, GitNexus install, MCP config, index status) is checked and only runs if needed, preventing redundancy. - Updated install requirements: Node.js >= 22 is now required; global or `npx`-based installation handled with detailed detection and fallback logic. - Clearer MCP integration: Simplified and clarified MCP configuration for common editors; auto-handling of repeated/failed setup. - More robust troubleshooting: Expanded common error solutions and quick-fix guidance for permissions, environment, indexing, and MCP/editor integration. - Concise language and tool support lists; streamlined usage examples and expected output for improved user clarity.
v1.0.0
Initial release of the code-graph skill for building code knowledge graphs with GitNexus. - Enables automatic code structure and dependency analysis for AI agents. - Provides step-by-step workflow: project detection, GitNexus installation, indexing, and MCP configuration for multiple AI platforms. - Documents troubleshooting, supported languages, output locations, and post-indexing graph tools. - Supports semantic and hybrid queries, multi-file refactoring, and impact analysis through MCP interface. - Includes full CLI examples and configurations for OpenCode, Claude, OpenClaw, and Hermes agents.
元数据
Slug code-graph
版本 1.0.1
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 2
常见问题

Code Graph(代码图谱) 是什么?

一键安装 GitNexus 并为当前项目构建代码知识图谱。当用户说「安装GitNexus」「设置GitNexus」「初始化GitNexus」「配置GitNexus」「用GitNexus建图」「GitNexus一键配置」时使用。 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 45 次。

如何安装 Code Graph(代码图谱)?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install code-graph」即可一键安装,无需额外配置。

Code Graph(代码图谱) 是免费的吗?

是的,Code Graph(代码图谱) 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

Code Graph(代码图谱) 支持哪些平台?

Code Graph(代码图谱) 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Code Graph(代码图谱)?

由 manniu(@babywhale)开发并维护,当前版本 v1.0.1。

💬 留言讨论