kg-extract — скилл для Claude Code: извлечение граф знаний из кода
Скилл извлекает сущности и связи из исходников, строит граф знаний в AgentDB. Нужен для анализа структуры кодовой базы, зависимостей и оценки влияния изменений.
npx skills add ruvnet/ruflo --skill kg-extract -a claude-codeЧто делает kg-extract
kg-extract сканирует файлы по указанному пути, выделяет сущности (классы, функции, модули, типы, конфигурации) и отображает их отношения: импорты, наследование, реализацию интерфейсов, зависимости, вызовы функций. Результат сохраняется как граф в AgentDB с метаданными каждой сущности.
Скилл критично различает TypeScript value-импорты и type-only импорты: type-импорты (import type { Foo }) стираются при компиляции и не создают циклические зависимости на выполнении. Неправильная классификация даёт фантомные циклы. Связи имеют вес: value-импорты — 0.9, type-импорты — 0.1, наследование — 0.9, зависимости конструктора — 0.8, вызовы — 0.7, документирование — 0.3.
Доступны инструменты чтения файлов (Read, Glob, Grep), хранилище AgentDB и встроенные CLI-команды для сохранения и поиска сущностей в памяти агента по пространствам имён.
Какие задачи решает
- построить граф зависимостей в кодовой базе
- выявить циклические зависимости и phantom imports
- оценить влияние изменения на связанные модули
- документировать архитектуру через граф сущностей
Примеры запросов агенту
- Извлеки сущности и связи из src/ в граф знаний
- Построй граф зависимостей для всего проекта в ./
- Найди все сущности, которые зависят от auth модуля
Как установить kg-extract
1Через Skills CLI (Vercel)
npx skills add ruvnet/ruflo --skill kg-extract -a claude-code2Вручную: положить файлы
~/.claude/skills/kg-extract/SKILL.mdПапка скилла целиком; для одного проекта — .claude/skills/kg-extract/
1Через Skills CLI (Vercel)
npx skills add ruvnet/ruflo --skill kg-extract -a codex2Вручную: положить файлы
.agents/skills/kg-extract/SKILL.mdДля всех проектов — ~/.agents/skills/
1Через Skills CLI (Vercel)
npx skills add ruvnet/ruflo --skill kg-extract -a cursor2Вручную: положить файлы
.cursor/skills/kg-extract/SKILL.mdCursor читает и .agents/skills/, и .claude/skills/
1GitHub CLI
gh skill install ruvnet/ruflo kg-extract2Вручную: положить файлы
.github/skills/kg-extract/SKILL.md1Через Skills CLI (Vercel)
npx skills add ruvnet/ruflo --skill kg-extract -a gemini-cli2Командой платформы
gemini skills install https://github.com/ruvnet/ruflo --path plugins/ruflo-knowledge-graph/skills/kg-extractВручную: положить файлы
.devin/skills/kg-extract/SKILL.mdСтарый путь .windsurf/skills/ тоже читается
Через Skills CLI (Vercel)
npx skills add ruvnet/ruflo --skill kg-extract -a opencodeClaude.ai
Упакуйте папку в zip и загрузите в Settings → Capabilities → Skills
Из того же набора104
Весь набор →Похожие
Вопросы о kg-extract
Как установить kg-extract в Claude Code?
Выполни npx skills add ruvnet/ruflo --skill kg-extract -a claude-code. Скилл появится в ~/.claude/skills/kg-extract/SKILL.md.
Что делает kg-extract?
Сканирует исходники, извлекает классы, функции, модули и их отношения (импорты, наследование, зависимости), затем сохраняет граф знаний в AgentDB для анализа архитектуры и зависимостей.
Почему различаются value- и type-импорты?
Type-импорты в TypeScript стираются при компиляции и не создают runtime-циклов. Без разделения агент даст ложные циклические зависимости, что приведёт к неправильной оценке влияния изменений.
Исходный текст
SKILL.md · MIT
---
name: kg-extract
description: Extract entities and relations from source files to build a knowledge graph
argument-hint: "<path>"
allowed-tools: Read Glob Grep mcp__plugin_ruflo-core_ruflo__agentdb_hierarchical-store mcp__plugin_ruflo-core_ruflo__agentdb_causal-edge mcp__plugin_ruflo-core_ruflo__agentdb_pattern-store mcp__plugin_ruflo-core_ruflo__embeddings_generate Bash
---
# 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
```bash
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
```
© ruvnet · MIT · ruvnet/ruflo