跳到正文
Skillpedia
分析与电子表格81k · #1639

kg-extract

它能做什么

这项技能读取源文件,把类、函数和模块转化为它们之间关系的地图。适合需要了解代码库结构、以及改动可能如何扩散的开发者。

适用场景

  • ✓当你想了解代码库各部分如何相互依赖时。
  • ✓当你需要判断一项改动可能波及多远时。
  • ✓当大规模改动之后,你想更新代码地图时。

技能链接

https://github.com/ruvnet/ruflo/blob/main/plugins/ruflo-knowledge-graph/skills/kg-extract/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/ruvnet/ruflo/blob/main/plugins/ruflo-knowledge-graph/skills/kg-extract/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请绘制我项目主要部分的地图,以及它们之间的依赖关系。”

每周 5 个新技能,1 分钟读完。

工作原理

这项技能读取源文件,识别类、函数、模块和类型,然后记录它们之间的关系,例如通过导入和继承。结果以图的形式存入项目的记忆库。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

KG Extract

Extract entities (classes, functions, modules, types, concepts) and their relations (imports, extends, implements, depends-on, calls) from source files, then store them as a knowledge graph in AgentDB.

When to use

When you need to build or update a knowledge graph from source code or documentation. Useful for understanding codebase structure, dependency analysis, and impact assessment.

Steps

  1. Scan files -- use Glob and Read to enumerate and read source files at the given path

  2. Identify entities -- extract classes, functions, modules, types, and config references from each file

  3. Map relations -- for each entity, determine its relations to other entities. Critical: TypeScript import type and inline type specifiers (import { type Foo, bar }) are erased at compile time and MUST NOT be counted as value imports -- they're a separate, weaker relation. Misclassifying them produces phantom runtime cycles (see ruvnet/ruflo#2049).

    • imports: value imports (import { x } from '...', require(...)) -- weight 0.9
    • type-depends-on: TypeScript type-only imports (import type { Foo } from '...' and import { type Foo, value } from '...') -- weight 0.1, never used for cycle detection or runtime impact analysis
    • extends: class inheritance -- weight 0.9
    • implements: interface implementations -- weight 0.7
    • depends-on: constructor dependencies, injected services -- weight 0.8
    • calls: function/method invocations -- weight 0.7
    • references: documentation mentions, comments -- weight 0.3

    Regex hint for classifying TS imports (so a naive from '...' grep doesn't conflate the two):

    ^\s*import\s+type\s+               → type-depends-on (entire import is type-only)
    ^\s*import\s*\{[^}]*\btype\s+\w+   → split: type specifiers → type-depends-on, value specifiers → imports
    ^\s*import\s+[^{]*\bfrom\s+        → imports (value)
    
  4. Store in AgentDB -- call mcp__plugin_ruflo-core_ruflo__agentdb_hierarchical-store for each entity with metadata (name, type, file, line, description)

  5. Create edges -- call mcp__plugin_ruflo-core_ruflo__agentdb_causal-edge for each relation with source, target, relation type, and weight

  6. Report -- summarize: total entities by type, total relations by type, files scanned

CLI alternative

npx @claude-flow/cli@latest memory store --namespace knowledge-graph --key "entity-NAME" --value "METADATA_JSON"
npx @claude-flow/cli@latest memory search --query "entities in auth module" --namespace knowledge-graph
常见问题

仅用于类型的导入会被算作运行时的联系吗?

不会。仅用于类型的导入会作为较弱的关系保留,且不用于循环检测。

记录哪些关系?

导入、继承、实现和依赖关系,每种都有一个权重。

图存在哪里?

它存放在 AgentDB 中,这是该技能使用的记忆库。

详情

作者的原始描述

Extract entities and relations from source files to build a knowledge graph

repo: ruvnet/ruflo

热度

GitHub 星标
81k
排名
#1639
许可证
MIT
更新时间
2026/11/2

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能