Skip to main content

omp-graph

An OMP plugin for manual graph construction and LLM context synthesis from source code.

Build knowledge graphs of your codebase, define tasks, and generate rich context for AI-powered development workflows.

Repository

๐Ÿ“ฆ GitHub: thinmanj/oh-my-graph

# Clone the repository
git clone https://github.com/thinmanj/oh-my-graph.git

# Navigate into the project
cd oh-my-graph

# Install in development mode
pip install -e .[dev]

Overview

omp-graph lets you:

  1. Scan codebases using graphify extractors to discover code symbols
  2. Build graphs manually via an interactive TUI โ€” define nodes and edges with precise control
  3. Generate LLM context from graphs, focusing on specific nodes with configurable depth
  4. Integrate with OMP tasks to feed structured context to AI agents

Unlike fully-automatic graph tools, omp-graph emphasizes manual control โ€” you decide which symbols to include and how they relate. This is essential when handling large codebases where precision matters.

Installation

From PyPI (when published)

pip install omp-graph

From Source

pip install -e .

Dependencies

  • duckdb โ€” Persistent graph storage (analytical engine)
  • graphify โ€” Multi-language symbol extraction (Python, JS/TS, Java, C/C++, and more)
  • rich โ€” TUI for interactive graph building
  • networkx โ€” Graph algorithms and traversals
  • pydantic โ€” Data validation

Quick Start

Interactive Builder

# Launch the interactive builder
omp-graph

# Commands in the TUI:
#   1. Scan codebase โ€” discover symbols via graphify
#   2. Add manual node โ€” create custom nodes
#   3. Create edge โ€” connect nodes with typed relationships
#   4. View graph โ€” inspect nodes, edges, communities
#   5. Validate graph โ€” check for orphaned nodes and broken references
#   6. Save graph โ€” persist to DuckDB
#   7. Load graph โ€” restore from storage
#   8. Export context โ€” generate LLM prompt from graph
#   9. View workflow log

Programmatic Usage

from omp_graph.builder import create_builder
from omp_graph.context import build_llm_context
from omp_graph.storage import GraphStorage

# Create a builder
builder = create_builder()

# Scan a codebase
builder.scan_and_populate("/path/to/project", recursive=True)

# Add a manual node
node_id = builder.add_manual_node(
    title="Architecture Decision: User Auth",
    content="Use JWT tokens for stateless authentication",
    source_path="docs/architecture.md"
)

# Create edges between symbols
builder.create_edge(
    "app/main.py::main_function",
    "auth/jwt.py::generate_token",
    edge_type="CALLS",
    confidence=0.95,
    rationale="main() calls generate_token() during login"
)

# Validate graph
issues = builder.validate_graph()

# Generate LLM context
context = build_llm_context(
    builder.graph,
    target_node_id="app/main.py::main_function",
    depth=2
)
print(context)

# Save to storage
storage = GraphStorage("/path/to/graph.db")
builder.save_to_storage(storage, "my-project-graph")

Graph Model

Nodes

Nodes represent code symbols (functions, classes, modules) or manual concepts.

Field Type Description
id str Stable unique identifier
title str Display name
content str Content or description
source_path str? File path if code symbol
symbol str? Code symbol name
tags List[str] Classification tags (e.g., "function", "class")
community str|int? Grouping/clustering
metadata Dict Arbitrary key-value metadata
parent_id str? ID of parent node (hierarchical)
children List[str] IDs of child nodes

Edges

Edges represent relationships between nodes.

Field Type Description
source_id str Source node ID
target_id str Target node ID
edge_type str Relationship type (CALLS, DEPENDS_ON, IMPLEMENTS, etc.)
confidence float 0.0โ€“1.0 confidence score
rationale str Human-readable explanation

Edge Types

Type Meaning
DEPENDS_ON General dependency
CALLS Function/method call
IMPLEMENTS Implementation/interface relationship
CONTAINS Containment (e.g., module contains class)
IMPORTS Import statement
EXTENDS Inheritance/extension
USES Usage relationship

Scanner Integration

The built-in scanner wraps graphify's extractors for these languages:

Extension Language
.py Python
.js, .mjs JavaScript
.ts TypeScript
.tsx TypeScript + JSX
.java Java
.cpp, .cc, .cxx C++
.h, .hpp C/C++ header

LLM Context Formats

The context builder supports multiple output formats:

Code Analysis Format (default)

=== CODE ANALYSIS CONTEXT ===
TARGET: main_function
Type: code_symbol
Location: app/main.py
...
=== CONTEXT END ===

OpenAI Chat Format

builder.format_for_openai(graph, target_node_id="...", depth=1)
# Returns: [{"role": "system", "content": ...}, {"role": "user", "content": ...}]

Claude Format

builder.format_for_claude(graph, target_node_id="...", depth=1)
# Returns: "system prompt\n\nuser prompt"

Storage

Graphs are persisted using DuckDB with a fallback in-memory storage mode.

Schema

-- Nodes table
CREATE TABLE nodes (
    id VARCHAR PRIMARY KEY,
    title VARCHAR,
    content VARCHAR,
    source_path VARCHAR,
    symbol VARCHAR,
    parent_id VARCHAR,
    depth INTEGER,
    community VARCHAR,
    metadata JSON
);

-- Edges table
CREATE TABLE edges (
    source_id VARCHAR,
    target_id VARCHAR,
    edge_type VARCHAR,
    confidence DOUBLE,
    rationale VARCHAR,
    metadata JSON
);

Storage API

from omp_graph.storage import GraphStorage

# Auto-connects to omp_graph.db in current directory
storage = GraphStorage()

# Use a custom path
storage = GraphStorage("/path/to/graph.db")

# Save and load
storage.save_graph(graph)
loaded_graph = storage.load_graph()

# Export to JSON
json_data = storage.export_as_json()

# Import from JSON
graph = storage.import_from_json(json_data)

OMP Plugin Integration

The plugin exposes the following commands via the OMP plugin system:

Command Description
graph build Launch interactive graph builder CLI
graph scan Scan codebase and populate graph
graph context Generate LLM context from graph
graph validate Validate graph integrity
graph save Save current graph to storage
graph load Load graph from storage

Development

# Install in development mode
pip install -e .[dev]

# Run all tests
pytest tests/ -v

# Run specific test file
pytest tests/test_models_storage.py -v

# Format code
black omp_graph/ tests/

# Lint
ruff check omp_graph/ tests/

# Type check
mypy omp_graph/

Running Tests

# Run full test suite
pytest tests/ -v

# Run with coverage
pytest tests/ --cov=omp_graph --cov-report=html

TODO / Future Work

  • Publish to PyPI
  • Automated graph building from CI/CD
  • Team collaboration features
  • Visualization export (GraphML, Neo4j)
  • Incremental updates to existing graphs

Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    OMP Plugin System                        โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  omp_graph/plugin.py                                        โ”‚
โ”‚                                                             โ”‚
โ”‚  Commands:                                                  โ”‚
โ”‚  โ€ข omp-graph scan   โ†’ scan_and_populate()                   โ”‚
โ”‚  โ€ข omp-graph build  โ†’ launch CLI                            โ”‚
โ”‚  โ€ข omp-graph context โ†’ build_llm_context()                  โ”‚
โ”‚  โ€ข omp-graph save/load โ†’ GraphStorage                       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
               โ”‚
    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚                     โ”‚               โ”‚               โ”‚
    โ–ผ                     โ–ผ               โ–ผ               โ–ผ
  builder.py          scanner.py      context.py       storage.py
  (manual graph)   (graphify       (LLM context       (DuckDB
                    extraction)      synthesis)        backend)
                    
    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚                      โ”‚
    โ–ผ                      โ–ผ
  models.py           cli.py
  (Node, Edge,        (Rich TUI)
   Graph)

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

omp_graph-0.1.0.tar.gz (19.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

omp_graph-0.1.0-py3-none-any.whl (28.3 kB view details)

Uploaded Python 3

File details

Details for the file omp_graph-0.1.0.tar.gz.

File metadata

  • Download URL: omp_graph-0.1.0.tar.gz
  • Upload date:
  • Size: 19.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for omp_graph-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4d5b22b038fb17cb3755931b036a1bc6c3bfa1f090a07fe928bbc0f6a2dc29e5
MD5 301342c1923936fdb804d87acc14d702
BLAKE2b-256 6bc9f3c106b395920d5e7874279ca75adfff8232c6e381f5a195de985e82d3f2

See more details on using hashes here.

File details

Details for the file omp_graph-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: omp_graph-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 28.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for omp_graph-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c0c9d009c6c0dfbb93bdc490a576662d792b6f418fef55fb3e30317e45870434
MD5 b115431f461ed30b03768a6b61bba078
BLAKE2b-256 8a9670d865bc14501f1cc023d19d7a2f1e110cb809afc5b119c97520e8c6a17e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page