How to Access the Egonex-AI Understand Anything Plugin API: A Complete Guide
Import the skill builders from @understand-anything/plugin and load the knowledge graph with GraphBuilder from the core package to programmatically drive chat, diff, and explanation workflows.
The Egonex-AI Understand Anything plugin provides a TypeScript-based API for integrating code understanding capabilities into custom tools and CI pipelines. This guide covers how to access the Egonex-AI Understand Anything plugin API using the barrel exports from the plugin entry point and the core package utilities. All public functions are re-exported from understand-anything-plugin/src/index.ts, providing a clean interface for building LLM prompts and analyzing codebases.
Plugin API Entry Point and Core Exports
The plugin exposes its functionality through a barrel file that aggregates builders from individual skill modules. This design allows you to import everything from the top-level module while maintaining tree-shaking compatibility.
Barrel File Structure
The main entry point at understand-anything-plugin/src/index.ts re-exports high-level builder functions for each skill:
| Export | Purpose | Source File |
|---|---|---|
buildChatContext / formatContextForPrompt / ChatContext |
Build structured context for the /understand-chat skill |
src/context-builder.ts |
buildChatPrompt |
Assemble the final prompt string for chat interactions | src/understand-chat.ts |
buildDiffContext / formatDiffAnalysis / DiffContext |
Generate diff-aware context for the /understand-diff skill |
src/diff-analyzer.ts |
buildExplainContext / formatExplainPrompt / ExplainContext |
Create file-explanation context for /understand-explain |
src/explain-builder.ts |
buildOnboardingGuide |
Produce onboarding tours for new developers | src/onboard-builder.ts |
Import these functions in a single statement:
import {
buildChatContext,
buildChatPrompt,
buildDiffContext,
formatDiffAnalysis,
buildExplainContext,
formatExplainPrompt,
buildOnboardingGuide,
} from "@understand-anything/plugin";
Core Package Sub-Paths
The core package (understand-anything-plugin/packages/core) provides shared utilities via sub-path exports (@understand-anything/core/*). This architecture allows browser environments to import only browser-safe modules without pulling in Node-specific code.
Key core utilities include:
- Graph schema validation –
src/schema.tsexportsKnowledgeGraphSchemaandvalidateGraph - Tree-sitter parsing –
src/plugins/tree-sitter-plugin.tshandles deterministic AST extraction - Language detection –
src/languages/index.tsauto-detects project languages and frameworks - Semantic search –
src/search.tsandsrc/embedding-search.tspower vector-based code search
Loading the Knowledge Graph
Before invoking any skill builders, you must load the persisted knowledge graph generated by the /understand command. The GraphBuilder class in the core package handles this operation.
import { GraphBuilder } from "@understand-anything/core";
const graph = await GraphBuilder.loadFromFile(
"./.understand-anything/knowledge-graph.json"
);
This method returns a graph instance that serves as the primary input for all skill builder functions. The graph contains nodes and edges representing your codebase's structure, dependencies, and semantic relationships.
Skill Builder Functions
Each skill in the Understand Anything ecosystem corresponds to a specific builder function that transforms the knowledge graph into LLM-ready prompts or structured outputs.
Chat Context and Prompt Building
The buildChatContext function creates a structured context object containing relevant code snippets and relationships based on your query. The buildChatPrompt function then formats this context into a prompt string suitable for any LLM.
const chatCtx = await buildChatContext({ graph, query: "How does the payment flow work?" });
const prompt = buildChatPrompt(chatCtx);
// Send `prompt` to Claude, OpenAI, or your preferred model
Diff Analysis
For analyzing code changes, use buildDiffContext to identify affected nodes and edges in the knowledge graph, then formatDiffAnalysis to generate human-readable impact reports.
const diffCtx = await buildDiffContext({ graph, changedFiles: ["src/auth.ts"] });
const report = formatDiffAnalysis(diffCtx);
File Explanation
The buildExplainContext and formatExplainPrompt functions create detailed explanations of specific files or modules by extracting relevant subgraphs and formatting them for LLM consumption.
Onboarding Generation
The buildOnboardingGuide function generates step-by-step tours through the codebase tailored for new team members, utilizing the graph's module hierarchy and dependency information.
Complete Implementation Examples
Running a Chat Query Against the Codebase
This example demonstrates loading the graph and executing a natural language query:
import {
buildChatContext,
buildChatPrompt,
} from "@understand-anything/plugin";
import { GraphBuilder } from "@understand-anything/core";
async function askQuestion(question: string) {
// Load the persisted knowledge graph
const graph = await GraphBuilder.loadFromFile(
"./.understand-anything/knowledge-graph.json"
);
// Build the LLM-ready context
const ctx = await buildChatContext({ graph, query: question });
// Assemble the final prompt string
const prompt = buildChatPrompt(ctx);
// Pass `prompt` to your LLM
console.log("Prompt for LLM:", prompt);
}
askQuestion("How does the authentication flow work?");
Generating a Diff Impact Report
Analyze the impact of code changes by passing modified file paths to the diff analyzer:
import {
buildDiffContext,
formatDiffAnalysis,
} from "@understand-anything/plugin";
import { GraphBuilder } from "@understand-anything/core";
async function diffReport(changedFiles: string[]) {
const graph = await GraphBuilder.loadFromFile(
"./.understand-anything/knowledge-graph.json"
);
// Build a diff-aware context (provides affected nodes & edges)
const diffCtx = await buildDiffContext({ graph, changedFiles });
// Human-readable analysis
const report = formatDiffAnalysis(diffCtx);
console.log(report);
}
// Example usage
diffReport(["src/auth/login.ts", "src/services/payment.ts"]);
Creating an Onboarding Tour
Generate automated onboarding documentation for new developers:
import { buildOnboardingGuide } from "@understand-anything/plugin";
import { GraphBuilder } from "@understand-anything/core";
async function generateTour() {
const graph = await GraphBuilder.loadFromFile(
"./.understand-anything/knowledge-graph.json"
);
const tour = await buildOnboardingGuide({ graph });
console.log("Onboarding steps:", tour);
}
generateTour();
Key Source Files and Architecture
Understanding the internal file structure helps when debugging or extending the API:
| File Path | Role |
|---|---|
understand-anything-plugin/src/index.ts |
Public API barrel – re-exports all skill builders |
understand-anything-plugin/src/context-builder.ts |
Generates chat contexts from the knowledge graph |
understand-anything-plugin/src/diff-analyzer.ts |
Diff-aware context creation and formatting |
understand-anything-plugin/src/explain-builder.ts |
File-explanation context and prompt formatting |
understand-anything-plugin/src/onboard-builder.ts |
Generates onboarding tours |
understand-anything-plugin/packages/core/src/index.ts |
Core utilities (graph loading, schema validation) |
understand-anything-plugin/packages/core/src/schema.ts |
Knowledge-graph schema definitions |
understand-anything-plugin/packages/core/src/plugins/tree-sitter-plugin.ts |
Deterministic AST extraction using Web-Tree-Sitter |
understand-anything-plugin/packages/core/src/languages/index.ts |
Language and framework detection |
Summary
- Import from the barrel file: Use
@understand-anything/pluginto accessbuildChatContext,buildDiffContext,buildOnboardingGuide, and other skill builders. - Load the graph first: Always call
GraphBuilder.loadFromFile()from@understand-anything/coreto initialize the knowledge graph before running queries. - Core vs. Plugin separation: The core package provides low-level graph operations and parsing, while the plugin package provides high-level LLM prompt builders.
- Type-safe API: All exports include TypeScript definitions for
ChatContext,DiffContext, andExplainContextto ensure compile-time safety. - Sub-path imports: Use
@understand-anything/core/*imports to access browser-safe modules without Node dependencies.
Frequently Asked Questions
What is the difference between @understand-anything/plugin and @understand-anything/core?
@understand-anything/plugin provides the high-level skill builders like buildChatContext and buildDiffContext that create LLM prompts. @understand-anything/core contains the underlying utilities such as GraphBuilder, schema validation, and Tree-sitter parsers. The core package supports sub-path imports so you can import only the specific utilities you need without bundling Node-only code.
Do I need to run the /understand command before using the API?
Yes. The skill builders require a persisted knowledge graph generated by the /understand multi-agent pipeline. This command creates .understand-anything/knowledge-graph.json, which you must load using GraphBuilder.loadFromFile() before passing the graph instance to any builder functions.
Can I use the Understand Anything API in a browser environment?
Yes, but you must import only browser-safe modules from the core package using sub-path imports like @understand-anything/core/graph or @understand-anything/core/schema. Avoid importing the full core package or plugin package in browsers, as these may include Node-specific dependencies like file system utilities.
How do I customize the prompts generated by the skill builders?
The skill builders return context objects (e.g., ChatContext, DiffContext) that contain structured data about your codebase. You can either use the provided prompt formatters like buildChatPrompt() or extract the context data and format it according to your own prompt templates. The context objects expose the raw nodes, edges, and code snippets discovered in the knowledge graph.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →