con un clic
kg-extract
Extract entities and relations from source files to build a knowledge graph
Menú
Extract entities and relations from source files to build a knowledge graph
Basado en la clasificación ocupacional SOC
One-command drift detection. Composes audit-list + oia-audit + audit-trend into a single primitive — finds the most recent audit in `metaharness-audit` namespace, runs a fresh audit against the current repo, diffs them via ADR-152 §3.1 similarity, and alerts when structural distance crosses `--threshold`. Iter 53 of ADR-150 deep integration.
ADR-152 — weighted similarity between two harness fingerprints (genome + score JSON). Returns overall score in [0,1] plus per-component breakdown (cosine over 9 numerics, categorical agreement over 4 enums, jaccard over agent_topology). Unblocks ADR-151 §3.2 Recommender, §3.3 Drift Detection, §3.5 Plugin Compat. Pure-TS, no `@metaharness/*` dep — preserves ADR-150's four architectural constraints.
Composite Phase-2 audit worker (ADR-150). Bundles harness oia-manifest + threat-model + mcp-scan into one timestamped audit record stored in the `metaharness-audit` memory namespace. Designed for cron-scheduled drift detection.
7-section repo readiness report from `metaharness genome <path>`. Returns repo_type / agent_topology / risk_score / mcp_surface / test_confidence / publish_readiness. Pure-read; degrades gracefully (ADR-150).
Static security scan of a harness's declared MCP surface via `harness mcp-scan <path>`. Reads `.mcp/servers.json` + `.harness/claims.json`. Pure-read, no dispatch. Exits 1 on findings at or above `--fail-on` severity.
Scaffold a custom AI agent harness via `metaharness new <name> --template <id> --host <id>`. Defaults to DRY-RUN (no writes) unless --confirm is passed. Refuses to write to the calling repo root or anywhere inside it. Honors ADR-150 architectural constraint + ruflo's "destructive-action confirmation" pattern.
| 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__claude-flow__agentdb_hierarchical-store mcp__claude-flow__agentdb_causal-edge mcp__claude-flow__agentdb_pattern-store mcp__claude-flow__embeddings_generate Bash |
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 you need to build or update a knowledge graph from source code or documentation. Useful for understanding codebase structure, dependency analysis, and impact assessment.
Scan files -- use Glob and Read to enumerate and read source files at the given path
Identify entities -- extract classes, functions, modules, types, and config references from each file
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.9type-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 analysisextends: class inheritance -- weight 0.9implements: interface implementations -- weight 0.7depends-on: constructor dependencies, injected services -- weight 0.8calls: function/method invocations -- weight 0.7references: documentation mentions, comments -- weight 0.3Regex 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)
Store in AgentDB -- call mcp__claude-flow__agentdb_hierarchical-store for each entity with metadata (name, type, file, line, description)
Create edges -- call mcp__claude-flow__agentdb_causal-edge for each relation with source, target, relation type, and weight
Report -- summarize: total entities by type, total relations by type, files scanned
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