mcpField
G
graphify

graphify

github.com/ariadoss数据与数据库1277 次安装1 天前更新
代码仓库

关于 graphify

graphify 是一项将文件夹内容整理为可浏览知识图谱的技能,适用于研究资料、代码和笔记等混合语料。它保留图谱数据,并标记关系来源,还可通过社区检测发现跨文件关联。

主要功能

  1. 01从文件夹构建知识图谱
  2. 02标注关系的提取状态
  3. 03检测跨文档社区
  4. 04增量处理变更文件
  5. 05导出 HTML、JSON 和报告

适用场景

  1. 01梳理代码库中的概念关系
  2. 02连接不同文档中的相关主题
  3. 03更新已有图谱而不重跑全部文件

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/ariadoss/superskills --skill graphify

安装后在 Claude Code 中输入/graphify确认已加载。

详细介绍

/graphify

将任意文件夹转换为可浏览的知识图谱,支持社区检测,提供真实的审计跟踪,并生成三个输出文件:graph.html、graph.json 和 GRAPH_REPORT.md。

来源:safishamsi/graphify

用法

/graphify                         # full pipeline on current directory
/graphify <path>                  # full pipeline on specific path
/graphify <path> --mode deep      # thorough extraction, richer INFERRED edges
/graphify <path> --update         # incremental — re-process only changed files
/graphify <path> --no-viz         # skip HTML visualization, just report + JSON
/graphify <path> --svg            # also export graph.svg (embeds in Notion, GitHub)
/graphify <path> --neo4j          # generate cypher.txt for Neo4j import
/graphify <path> --watch          # watch folder, auto-rebuild on code changes
/graphify <path> --wiki           # build agent-crawlable wiki (index.md + per-community articles)
/graphify add <url>               # fetch URL, save to ./raw, update graph
/graphify query "<question>"      # BFS traversal — broad context
/graphify query "<question>" --dfs  # DFS — trace a specific path
/graphify explain "<Node>"        # plain-language explanation of a node
/graphify path "A" "B"            # shortest path between two concepts

graphify 的用途

graphify 围绕 Andrej Karpathy 的 /raw 文件夹工作流构建:将任何内容放入文件夹——论文、代码、屏幕截图、笔记——即可生成结构化知识图谱,展示你未曾意识到有关联的内容。

它能做到 Claude 单独无法做到的三件事:

  1. 持久化图谱 — 关系存储在 graphify-out/graph.json 中,并会跨会话保留
  2. 真实的审计跟踪 — 每条边都标记为 EXTRACTED、INFERRED 或 AMBIGUOUS
  3. 跨文档的意外发现 — 社区检测能找到不同文件之间的关联,而你可能从未想到要查询这些关联

步骤 1 — 确认 graphify 已安装

# Detect the correct Python interpreter
PYTHON=""
GRAPHIFY_BIN=$(which graphify 2>/dev/null)
if [ -z "$PYTHON" ] && command -v uv >/dev/null 2>&1; then
    _UV_PY=$(uv tool run graphifyy python -c "import sys; print(sys.executable)" 2>/dev/null)
    if [ -n "$_UV_PY" ]; then PYTHON="$_UV_PY"; fi
fi
if [ -z "$PYTHON" ] && [ -n "$GRAPHIFY_BIN" ]; then
    _SHEBANG=$(head -1 "$GRAPHIFY_BIN" | tr -d '#!')
    case "$_SHEBANG" in
        *[!a-zA-Z0-9/_.-]*) ;;
        *) "$_SHEBANG" -c "import graphify" 2>/dev/null && PYTHON="$_SHEBANG" ;;
    esac
fi
if [ -z "$PYTHON" ]; then PYTHON="python3"; fi
"$PYTHON" -c "import graphify" 2>/dev/null \
  || "$PYTHON" -m pip install graphifyy -q 2>/dev/null \
  || "$PYTHON" -m pip install graphifyy -q --break-system-packages 2>&1 | tail -3
mkdir -p graphify-out
"$PYTHON" -c "import sys; open('graphify-out/.graphify_python', 'w').write(sys.executable)"

如果尚未安装 graphify,且 pip 安装失败,请告知用户安装:

uv tool install graphifyy   # recommended
# or: pipx install graphifyy
# or: pip install graphifyy

在所有后续步骤中,将 python3 替换为 $(cat graphify-out/.graphify_python)。

步骤 2 — 检测文件

$(cat graphify-out/.graphify_python) -c "
import json
from graphify.detect import detect
from pathlib import Path
result = detect(Path('INPUT_PATH'))
print(json.dumps(result))
" > graphify-out/.graphify_detect.json

将 INPUT_PATH 替换为用户提供的路径(默认为 .)。静默读取 JSON,并以清晰易读的方式呈现摘要:

Corpus: X files · ~Y words
  code:    N files (.py .ts .go ...)
  docs:    N files (.md .txt ...)
  images:  N files

省略文件数为 0 的类别。然后:

  • 如果 total_files 为 0:停止并显示“No supported files found in [path].”
  • 如果 total_words > 2,000,000 或 total_files > 200:按文件数列出前 5 个子目录,并询问用户要对哪个子文件夹运行。等待用户答复。
  • 否则:继续步骤 3。

步骤 3 — 构建图谱

$(cat graphify-out/.graphify_python) -m graphify INPUT_PATH [FLAGS]

传递用户指定的任何标志(--mode deep、--update、--no-viz 等)。这将运行完整流程:AST 提取、通过 Claude 子 Agent 提取 LLM 概念和关系、Leiden 社区检测以及导出。

流式输出,让用户查看进度。大型语料库的处理可能需要几分钟。

步骤 4 — 报告结果

流程完成后,读取 graphify-out/GRAPH_REPORT.md 并呈现:

  1. 核心节点 — 连接最多的概念(代码库的结构骨干)
  2. 意外关联 — 你原本会认为互不相关的概念之间的边
  3. 社区摘要 — 每个集群包含的内容
  4. 建议问题 — 报告中推荐的查询

然后告知用户:

  • graphify-out/graph.html — 在任意浏览器中打开以交互式探索
  • graphify-out/graph.json — 持久化图谱,可通过 /graphify query 查询
  • graphify-out/GRAPH_REPORT.md — 通俗易懂的审计报告

询问:“要我添加一条规则,让 Claude 在未来的会话中引用此图谱吗?”如果是,则创建 .claude/rules/graphify.md,内容如下:

Reference graphify-out/graph.json and graphify-out/GRAPH_REPORT.md for knowledge graph context.
Use /graphify query "<question>" to traverse the graph before exploring unfamiliar code paths.

如有需要,创建 .claude/rules/。

提示

  • 使用 --update 进行增量运行——只重新处理发生变化的文件
  • 对较小的语料库使用 --mode deep,以提取更丰富的关系
  • graphify add <url> 会获取 URL 内容并将其加入图谱,无需完整重建
  • .graphifyignore 用于排除路径(语法与 .gitignore 相同)
  • 图谱会跨会话保留——graph.json 是可查询的索引

评论

支持 Markdown