code-knowledge-graph-create
Installation
Review the source and dependencies with a prompt. A package is available to download.
Install with an AI assistant
Copy the prompt so your assistant can review the pinned revision and dependencies first.
View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "code-knowledge-graph-create" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-46021a5c82ab79022d1840809c0a86ec54f5741e4462d559c3046fb6f4e2889e. Verify the upstream source and version against https://skillhub.cn/skills/user_b30f8db8/code-knowledge-graph-create before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.
Source and setup
skillhub.cn
Setup guidance pending
See the original source for supported tools, dependencies, and permissions.
Installation test pending
Used when you need to create/generate a code knowledge graph and upload it to a remote Neo4j database. Parses Python source code statically with tree‑sitter (generate_kg.py) to produce the graph, then uploads it via import_to_neo4j.py, with connection settings auto‑loaded from .neo4j-config.json in the project root. Triggers on requests like “create knowledge graph,” “generate code graph,” “build and upload graph,” “import code relationships to Neo4j,” or “rebuild graph.”
Introduction source: third_party · user_b30f8db8 · 1.0.2 Reference
SkillPi interpretation
- Tasks
- Translation pending; see source documentation.
- Software, accounts and paid services
- Translation pending; see source documentation.
- Testing
- Not tested
Browse files
Frontmatter
name: code-knowledge-graph-create
description: 当需要"创建 / 生成代码知识图谱"并将其上传到远程 Neo4j 图数据库时使用。基于 tree-sitter 对 Python 源码做静态解析(generate_kg.py)生成图谱,再通过 import_to_neo4j.py 上传,连接配置自动从根目录 .neo4j-config.json 加载。当用户要求"创建知识图谱"、"生成代码图谱"、"构建并上传图谱"、"把代码关系导入 Neo4j"、"重建图谱"时触发。代码知识图谱创建(生成 + 上传)
概述
本技能负责知识图谱的创建与上传这一完整流水线:
- 创建(generate):使用
tree-sitter对项目中所有 Python 源文件做静态解析(无需运行项目),抽取模块、类、函数、导入及它们之间的调用 / 继承 / 实例化关系,生成kg.cypher。脚本为项目根目录的generate_kg.py。 - 上传(import):将
kg.cypher上传到远程 Neo4j 图数据库。脚本为项目根目录的import_to_neo4j.py,其连接配置(uri / user / password / database)自动从项目根目录的.neo4j-config.json加载。
本技能是自包含的:核心脚本已随技能打包在 scripts/ 目录内,不依赖项目根目录恰好存在这些脚本。技能提供一个编排脚本 scripts/build_kg.py,可一键完成"创建 + 上传",并自动发现项目根目录与配置文件。
本技能与
code-knowledge-graph技能互补:本技能负责创建/上传图谱,后者负责查询/分析图谱。
何时使用本技能
- "帮我创建/生成知识图谱"
- "把代码关系上传到 Neo4j"
- "重建一下图谱"(代码库结构变了,需要重新生成)
- "生成一个 kg.cypher 文件并导入"
- "构建并上传代码知识图谱"
前置依赖
pip install tree-sitter tree-sitter-python neo4j
- 创建(解析)阶段仅需
tree-sitter+tree-sitter-python - 上传阶段仅需
neo4j驱动
配置文件(根目录 .neo4j-config.json)
import_to_neo4j.py 会自动查找并加载项目根目录(或任意上级目录)下的 .neo4j-config.json,无需手动传参。配置示例(当前项目已存在):
{
"uri": "bolt://localhost:7687",
"user": "neo4j",
"password": "your-password",
"database": "neo4j"
}
连接参数优先级(高 → 低):命令行参数(--uri / --user / --password / --database) > 环境变量(NEO4J_URI 等) > .neo4j-config.json > 内置默认值。
使用方式
方式 A:一键创建 + 上传(推荐)
直接使用编排脚本,项目根目录会被自动发现,.neo4j-config.json 自动加载:
# 从项目任意位置运行
python3 .codebuddy/skills/code-knowledge-graph-create/scripts/build_kg.py
常用选项:
python3 .codebuddy/skills/code-knowledge-graph-create/scripts/build_kg.py --dry-run # 仅创建并打印导入计划,不写库
python3 .codebuddy/skills/code-knowledge-graph-create/scripts/build_kg.py --clear # 先清空远程图谱,再重建(避免重复边)
python3 .codebuddy/skills/code-knowledge-graph-create/scripts/build_kg.py --skip-import # 只创建 kg.cypher,不上传
python3 .codebuddy/skills/code-knowledge-graph-create/scripts/build_kg.py --skip-generate --file other.cypher # 只上传指定文件
方式 B:分步执行(等价于方式 A)
如果希望逐步控制,也可直接调用根目录脚本:
步骤 1 — 创建 Cypher(tree-sitter 静态解析):
python3 generate_kg.py --output kg.cypher --root . --verbose
脚本会自动排除 .venv、__pycache__、.git、data、images 等目录,并跳过自身(generate_kg.py / import_to_neo4j.py / verify_kg.py)。
步骤 2 — 上传到远程 Neo4j(配置自动从 .neo4j-config.json 加载):
python3 import_to_neo4j.py --file kg.cypher
无需传 --uri / --password:脚本会从根目录 .neo4j-config.json 读取。也可显式覆盖:
python3 import_to_neo4j.py --file kg.cypher --uri bolt://host:7687 --user neo4j --password xxx
支持 --mode shell(使用 cypher-shell CLI)、--dry-run(仅统计语句数)、--database(指定库名)。
图谱 Schema
创建器产出的图谱结构(节点 / 关系)由 generate_kg.py 决定:
- 节点:
Module、Class、Function、Import - 关系:
IMPORTS、IMPORTS_FROM、DEFINES_CLASS、DEFINES_FUNCTION、DEFINES_METHOD、INHERITS、CALLS、INSTANTIATES、CALLS_METHOD
详细的节点属性与关系方向说明见 code-knowledge-graph 技能的 references/schema.md。
重要:关系非幂等
- 节点使用
MERGE(幂等,可重复导入)。 - 关系使用
CREATE(非幂等)。重复执行import_to_neo4j.py会在已存在节点间产生重复的关系边。
因此,在代码发生较大变更、需要重建图谱时,建议先清空远程数据库再重新导入:
python3 .codebuddy/skills/code-knowledge-graph-create/scripts/build_kg.py --clear
或手动:
python3 .codebuddy/skills/code-knowledge-graph/scripts/query_graph.py custom --cypher "MATCH (n) DETACH DELETE n"
python3 generate_kg.py --output kg.cypher --verbose
python3 import_to_neo4j.py --file kg.cypher
资源
scripts/(本技能内置)
- build_kg.py:编排脚本。自动发现项目根目录与
.neo4j-config.json,一键完成"创建 + 上传",并提供--dry-run/--clear/--skip-generate/--skip-import等选项。 - generate_kg.py:基于 tree-sitter 的图谱创建器(随技能打包)。解析项目 Python 源码输出
kg.cypher。build_kg.py会以--root <项目根目录>调用它。 - import_to_neo4j.py:图谱上传器(随技能打包)。将
kg.cypher导入远程 Neo4j(支持driver/shell两种模式、--dry-run、自动加载.neo4j-config.json)。
verify_kg.py(项目根目录,非技能资源)
图谱校验脚本,未打包进技能——它内部硬编码了本项目的预期类 / 函数(如 main.XianyuLive、XianyuAgent.PriceAgent),仅适用于当前项目。上传后可用于回归检查:
python3 verify_kg.pyCurrent listing version
1.0.2
Safety and assessment details
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Highlights
- 提供完整的代码知识图谱创建与上传流水线,解决开发者对代码结构可视化的实际需求
- 基于 tree-sitter 静态解析,无需运行项目即可生成图谱,安全可靠
Highlights
- 触发词覆盖全面,包括"创建知识图谱"、"生成代码图谱"、"构建并上传图谱"等多种表达
- 边界清晰,不易与其他 Skill 混淆
Highlights
- 文档结构清晰,分章节详细说明使用方式、配置、Schema 等重要信息
- 提供一键编排与分步执行两种模式,示例命令完整,便于用户快速上手
Highlights
- 工具依赖明确,配置文件自动加载机制完善
- 针对关系非幂等问题提供 --clear 解决方案,支持 dry-run 避免误操作
The arithmetic mean of the first four original scores, rounded to a whole number.
Static text checks
100 / 100 · skillpi-20261123-no-r3-v1
No current rules matched the text.
This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.
Permissions and checks before use
Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.
-
Install or fetch external dependencies
Use official sources and pin versions. Check install scripts in an isolated environment. This document check does not cover code downloaded later.
Mentioned in main document · lines 30
Security rating and access scope
safe · Static evidence review; not a runtime safety guarantee.
Translation pending; see source documentation.
Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.
User discussion
No verified reviews yet.