360 Secure SkillHub
360 安全技能中心

CodeGraph

通过本地 Python 脚本对项目目录做 AST 解析,在项目根目录生成 .code-graph.json 缓存,并支持 stats、functions、classes、calls、callers、file、imports、search 等查询,用于在不逐文件阅读的情况下了解代码结构与调用关系,支持 Python 和 JavaScript/TypeScript。

sg345662365-oss
sg345662365-oss
热度 82.61
最近更新 2026-06-08 13:53:32
分类:开发依赖:代码执行 / 读写文件应用场景:代码审查 / 调试排错 / 数据处理

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add codegraph
Metadata
name
code-graph
description
Build and query AST summaries + call graphs for codebases. Use when exploring a project's structure, finding function definitions, tracing call chains, understanding imports, or navigating unfamiliar code. Replaces repeated file reading with cached structural queries. Supports Python and JavaScript/TypeScript.

Code Graph

Analyze project structure via AST parsing instead of reading every file.

Quick Start

Build cache (first time or after changes)

python3 skills/code-graph/scripts/analyze.py <project_dir>

Creates .code-graph.json in the project root. Takes seconds for most projects.

Query the cache

python3 skills/code-graph/scripts/analyze.py <project_dir> --query <command> [args]

Available Queries

Query Description
stats Project overview: file counts, lines, functions, classes
functions List all functions with file + line number
classes List all classes with bases, methods, file + line
calls <func> What does func call? (outgoing edges)
callers <func> Who calls func? (incoming edges)
file <path> Full summary of one file (functions, classes, imports, calls)
imports Import graph: file → modules imported
search <pattern> Find functions/classes matching pattern

Workflow

  1. First encounter with a project: run the build to create cache
  2. Before reading files: query stats then search to find what you need
  3. Before modifying code: query callers to check impact
  4. After modifying code: rebuild cache with a fresh run (no --query)

Cache Location

  • Default: <project_dir>/.code-graph.json
  • Override: --output <path>

Rebuild

Re-run without --query to rebuild. The cache includes a fingerprint for staleness detection.

Exclude Directories

python3 skills/code-graph/scripts/analyze.py <project_dir> --exclude vendor --exclude tmp

Default excludes: node_modules, .git, pycache, .venv, dist, build, .next, coverage