JohnXu22786/codegraph

用于代理工具(dsh)的代码知识图谱插件:将符号、调用点和导入索引到SQLite中,通过CLI或stdio MCP工具服务器回答调用/依赖问题。

Project Overview项目介绍

CodeGraph is a code knowledge graph tool that parses a target codebase into a queryable on-disk index. It enables AI agents to answer structural code questions like which functions call a given target, or what modules a given file depends on. It is distributed as a Python package that you can install via pip, either as an editable install for local development or directly run from the repository without installing. It ships with a command-line interface, a Python API, and an MCP-style stdio JSON-RPC 2.0 server that works with any plugin-based agent harness, including DeepSeek Harness.

To use CodeGraph, first navigate to your project directory, run codegraph init to create a starter configuration file, then run codegraph index to build or refresh the graph index. By default, it uses incremental indexing that only re-parses files that have changed since the last build, so it’s very fast for incremental updates. After building the index, you can run queries directly from the CLI to get callers, callees, dependencies, dependents, run full-text searches over code symbols, or get a full transitive impact analysis for any symbol. It is designed for AI coding agents that need structural code context, and developers who want to explore unfamiliar large codebases.

CodeGraph requires Python 3.10 or newer, and has no mandatory third-party dependencies outside the Python standard library and SQLite, which ships with most Python installations. You can optionally install the tree-sitter engine for more precise parse results, which is done by running pip install -e ".[treesitter]" after cloning the repository. It currently supports six popular programming languages: Python, JavaScript, TypeScript, Go, Java, and Rust. It is released under the open-source MIT license, and has a few minor known limitations that only affect edge cases, like the regex engine not distinguishing between code and strings in comments.

CodeGraph 是一个独立的代码知识图谱工具,可将代码库解析为可查询的索引,支持代理回答诸如「谁调用了这个函数」「该模块依赖哪些内容」这类结构性问题,帮助开发者快速理解大型代码库,也可在修改代码前做变更风险筛查。它提供 CLI、Python API 和 MCP 风格的 JSON-RPC 2.0 标准输入输出工具服务端,可被任意基于插件的代理框架加载,同时支持 DSH 集成。

典型使用流程为,先在目标项目根目录初始化配置,然后构建索引,它默认开启增量索引,仅重新解析修改过的文件,删除的文件也会自动清理,之后就可以通过调用图谱查询接口,获取调用关系、依赖关系、全文搜索和变更影响分析结果,也可导出 DOT 或 JSON 格式的图谱用于可视化。适合需要梳理大型项目结构的开发人员,或是需要代码结构信息的 AI 开发代理使用。

CodeGraph 基于 Python 开发,要求 Python 版本不低于 3.10,仅依赖 Python 标准库和 SQLite,可选安装 tree-sitter 获得更精确的解析结果,目前支持 Python、JS/TS、Go、Java、Rust 六种语言,采用 MIT 开源许可。它存在一些已知限制,比如正则解析引擎不区分字符串和注释,跨文件调用解析依赖启发式规则,部分动态调用无法解析。

Pre-install check安装前体检Compatibility · Security兼容性 · 安全性 1 warning1 项注意
  • Only 3 stars - very few users, little community feedback星标只有 3,几乎没人在用,遇到问题缺少社区反馈
DSH walks through these 9 checksDSH 会逐条核对这 9 项

Compatibility兼容性

  • DSH, Node, OS and profile requirementsDSH 版本 / Node 版本 / 操作系统 / profile 是否满足要求
  • External dependencies and runtimes (Electron / Python / Docker, ...)外部依赖与运行时(Electron / Python / Docker 等)是否齐备
  • Conflicts with installed plugins: command names, skill / tool names, ports, duplicate MCP registration与已装插件是否冲突:命令名、skill / tool 重名、端口占用、重复 MCP 注册

Security安全性

  • Repo matches the facts registered here; archived or abandoned?仓库是否与页面登记一致,是否归档或长期停更
  • Safety of preinstall / install / postinstall and install.sh / setup.ps1preinstall / install / postinstall 与 install.sh、setup.ps1 是否安全
  • curl|bash, download-then-execute, obfuscation, unrelated domains → stop immediatelycurl|bash、下载即执行、混淆代码、无关域名 → 立刻停止
  • Typosquatting or unmaintained packages among the new dependencies新增依赖里有没有 typosquatting 或无人维护的包
  • Requested permissions vs. what the feature actually needs申请了哪些权限、是否超出功能所需(filesystem / network / shell / clipboard)
  • Any sudo / admin requirement, plus uninstall and rollback是否要求 sudo / 管理员权限,以及卸载与回滚方式

Anything uncertain must be marked unknown with a note on how to confirm it. This site's signal screen is a static snapshot, not a security audit.拿不准的必须标「未知」并说明要我怎么确认。本站的信号筛查是静态快照,不能替代安全审计。

Or use CLI install (for developers)或使用命令行安装(适合开发者)

CLI Install命令行安装

dsh plugin --profile demo add github:JohnXu22786/codegraph

把 JohnXu22786/codegraph 加入你的 DSH 配置(web profile)即可启用。

READMEREADME

简体中文

CodeGraph

A code knowledge graph plugin: parses a codebase into a queryable index, so agents can answer structural questions like "who calls this function" or "what does this module depend on". Good for quickly understanding large codebases, or as a risk-screening tool before making changes.

Self-contained implementation: Python standard library + SQLite, no mandatory third-party dependencies. Ships a CLI, a Python API, and a stdio tool server (MCP-style JSON-RPC 2.0) that any plugin-based harness can load as a subprocess.

Features

  • Call graph: callers / callees — who calls a given function/method, and what it calls
  • Dependency graph: deps / dependents — what a module or file imports and who imports it (internal resolution vs. external dependencies)
  • Full-text search: search — local full-text search over symbol names, docstrings and signatures (SQLite FTS5, no external service)
  • Impact analysis: impact — transitive closure listing "who would be affected if this symbol changed"
  • Incremental indexing: content-hash comparison re-parses only changed files; deleted files are cleaned up automatically
  • Visualization export: export dot|json — Graphviz DOT / JSON, ready to drop into visualization tools
  • Query cache: the tool server caches read-only queries with a 30-second TTL
  • Two parse engines: tree-sitter (precise, optional install) and a regex scanner (zero-dependency fallback), chosen automatically

How it works

file discovery (include/exclude/size limit)
   → syntax extraction (symbols, call sites, import statements)
   → SQLite storage (files / symbols / calls / imports + FTS5)
   → cross-file resolution (call targets → symbols, imports → files)
   → queries (CLI / tool server / Python API)

Cross-file resolution is heuristic and tries, in priority order: exact match in the same file → files reachable by import → same package/module family → globally unique name. Call sites that fail to resolve keep their raw text and are marked unresolved (external code, standard library, third-party packages).

Installation

# Option A: install as a Python package (provides the codegraph command)
pip install -e .

# Optional: install tree-sitter grammar packages for markedly better parse precision
pip install -e ".[treesitter]"

Showing the opening section of the README — the full document lives in the repository以上为 README 开头摘要,完整文档在仓库内 · View the full README on GitHub →在 GitHub 查看完整 README →

← 上一个 Prev dsh-musage-card 下一个 Next dsh-auto-approve →