跳转到主要内容

CGEF 导入与合并

导入 Codeweb Graph Exchange Format 格式的外部图谱数据,并与本地分析结果合并。

为什么需要 CGEF

CGEF(Codeweb Graph Exchange Format)是 codeweb 定义的 JSON 图谱交换格式,用于承接 codeweb 之外的图谱数据——例如无法提供源码扫描的私有 ERP 存储过程调用关系。先导入为独立 store,再与本地分析合并,即可跨边界追溯链路。

文档结构

CGEF 文档是一个 JSON 文件,顶层字段如下:

{
  "format_version": 1,
  "metadata": {
    "source": "erp-system",
    "generated_at": "2026-04-28T10:00:00Z"
  },
  "node_schemas": {},
  "edge_schemas": {},
  "nodes": [],
  "edges": []
}
字段必填含义
format_version是格式版本;当前为 1
metadata是source 来源标识与 ISO 8601 generated_at 时间戳
node_schemas否自定义节点类型声明
edge_schemas否自定义边类型声明
nodes是节数组(可为空)
edges是边数组(可为空)

标准节点类型覆盖 codeweb 全部内置对象(procedure、function、table、view、mapped_statement、java_method、java_class、java_sql、package、trigger、type、sequence、index、materialized_view 等)。每种类型的 key 字段规范见 CGEF 用户指南与 JSON Schema。

自定义类型

没有内置等价物的节点/边类型,在 node_schemas / edge_schemas 中声明(显示名、key 字段、属性定义)。其边以 CustomEdge 导入,其节点以 custom 标签导入,在 trace、impact、export 中与一等节点同等对待。

导入

codeweb import --file enterprise-graph.json --output erp-store.bincode
codeweb import --file enterprise-graph.json --output erp.json --prefix "/opt/erp/src" --name "erp"
codeweb import --file broken.json --output erp.bincode --force
参数含义
--fileCGEF JSON 输入
--output输出 store:.bincode 或 .json
--prefix为所有相对文件路径添加的前缀
--name导入 store 的项目名
--force存在校验或解析错误时仍强制导入

合并

codeweb merge -o full-graph.bincode my-project.bincode erp-store.bincode
codeweb merge -o full-graph.bincode --name "combined" my-project.bincode erp-store.bincode

合并会对多个 store 做节点/边去重,本地分析与 CGEF 导入的同一张表会收敛为一个节点。合并后的 store 在 trace、serve、export 中与本地 store 完全等价。

查看完整指南

中文指南 docs/cgef-user-guide.md 提供了完整实操示例,包括 OP Excel 血缘转换器(lib/op-lineage.py)。