knowledge

package
v0.9.0-beta.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 12, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Edge

type Edge struct {
	Metadata    map[MetadataType]interface{} `json:"metadata"`
	Annotations map[string]string            `json:"annotations"`
	Source      string                       `json:"source"`
	Target      string                       `json:"target"`
	Type        EdgeType                     `json:"type"`
}

Edge represents a relationship between nodes

type EdgeType

type EdgeType string

EdgeType represents the type of relationship between nodes

const (
	// Common edge types across languages
	EdgeCalls            EdgeType = "calls"
	EdgeImports          EdgeType = "imports"
	EdgeImplements       EdgeType = "implements"
	EdgeExtends          EdgeType = "extends"
	EdgeDependsOn        EdgeType = "depends_on"
	EdgeCommunicatesWith EdgeType = "communicates_with"
	EdgeDefines          EdgeType = "defines"
	EdgeUses             EdgeType = "uses"
	EdgeDecorates        EdgeType = "decorates"
)

type FileType

type FileType int

FileType represents a supported file type

const (
	TypeUnknown FileType = iota
	TypeGo
	TypePython
	TypeJavaScript
	TypeTypeScript
	TypeRust
	TypeConfig   // For yaml, json, toml files
	TypeLockfile // For package manager lock files
)

type Graph

type Graph struct {
	// contains filtered or unexported fields
}

Graph represents the project's knowledge graph

func NewGraph

func NewGraph() *Graph

NewGraph creates a new knowledge graph

func (*Graph) AddCallGraphData

func (g *Graph) AddCallGraphData(callGraphData []byte) error

AddCallGraphData integrates call graph data into the knowledge graph

func (*Graph) BuildFromAnalysis

func (g *Graph) BuildFromAnalysis(ctx context.Context, projectAnalysis *types.ProjectAnalysis) error

BuildFromAnalysis constructs the graph from project analysis

func (*Graph) GetAPIs

func (g *Graph) GetAPIs() []*Node

GetAPIs returns all API endpoint nodes

func (*Graph) GetNodeNeighbors

func (g *Graph) GetNodeNeighbors(nodeID string) ([]*Node, error)

GetNodeNeighbors returns all nodes connected to a given node

func (*Graph) ToJSON

func (g *Graph) ToJSON() ([]byte, error)

ToJSON serializes the graph to JSON, excluding sensitive data

func (*Graph) UpdateFromAnalysis

func (g *Graph) UpdateFromAnalysis(ctx context.Context, projectAnalysis *types.ProjectAnalysis) error

UpdateFromAnalysis incrementally updates the graph with new analysis data

type LLMContext

type LLMContext struct {
	ProjectStructure map[string]interface{} `json:"project_structure"`
	Dependencies     map[string]string      `json:"dependencies"`
	Languages        map[string]interface{} `json:"languages"`
	Frameworks       map[string]interface{} `json:"frameworks"`
	Resources        map[string]interface{} `json:"resources"`
	Network          map[string]interface{} `json:"network"`
	Storage          map[string]interface{} `json:"storage"`
	APIEndpoints     []interface{}          `json:"api_endpoints"`
	PodFlows         []interface{}          `json:"pod_flows"`
	Patterns         []interface{}          `json:"patterns"`
}

LLMContext represents the enriched context for LLM interactions

type LLMEnricher

type LLMEnricher struct {
	// contains filtered or unexported fields
}

LLMEnricher enriches the knowledge graph with LLM metadata

func NewLLMEnricher

func NewLLMEnricher(graph *Graph, metadataDir string) *LLMEnricher

NewLLMEnricher creates a new LLM metadata enricher with optimized caching

func (*LLMEnricher) EnrichContext

func (e *LLMEnricher) EnrichContext(ctx context.Context, yamlConfig *yaml.NexlayerYAML) (*LLMContext, error)

EnrichContext enriches the context with information from the configuration

func (*LLMEnricher) GeneratePrompt

func (e *LLMEnricher) GeneratePrompt(ctx context.Context, basePrompt string, yamlConfig *yaml.NexlayerYAML) (string, error)

GeneratePrompt generates a prompt for the LLM

func (*LLMEnricher) LoadMetadata

func (e *LLMEnricher) LoadMetadata() error

LoadMetadata loads LLM metadata from the tools directory with caching

func (*LLMEnricher) QueryLLM

func (e *LLMEnricher) QueryLLM(ctx context.Context, prompt string, config *yaml.NexlayerYAML) (*LLMResult, error)

QueryLLM queries the LLM with a prompt and configuration

func (*LLMEnricher) QueryLLMAsync

func (e *LLMEnricher) QueryLLMAsync(ctx context.Context, prompt string, config *yaml.NexlayerYAML) (<-chan *LLMResult, <-chan error)

QueryLLMAsync queries the LLM asynchronously

func (*LLMEnricher) Shutdown

func (e *LLMEnricher) Shutdown(ctx context.Context)

Shutdown gracefully shuts down the LLM enricher

type LLMResult

type LLMResult struct {
	Result    string    `json:"result"`
	Timestamp time.Time `json:"timestamp"`
	Source    string    `json:"source"` // "cache" or "api"
}

LLMResult represents the result of an LLM query with metadata

type MetadataType

type MetadataType string

MetadataType represents the type of metadata stored in node properties

const (
	// Metadata types for deployment and configuration
	MetadataLocation   MetadataType = "location"   // File location info
	MetadataVisibility MetadataType = "visibility" // Public/private/exported
	MetadataDeployment MetadataType = "deployment" // Deployment-specific info
	MetadataResource   MetadataType = "resource"   // Resource requirements
	MetadataNetwork    MetadataType = "network"    // Network configuration
	MetadataAuth       MetadataType = "auth"       // Authentication requirements
	MetadataStorage    MetadataType = "storage"    // Storage requirements
)

type Node

type Node struct {
	Metadata    map[MetadataType]interface{} `json:"metadata"`
	Annotations map[string]string            `json:"annotations"`
	ID          string                       `json:"id"`
	Type        NodeType                     `json:"type"`
	Name        string                       `json:"name"`
	Path        string                       `json:"path,omitempty"`
	Language    string                       `json:"language,omitempty"`
}

Node represents a code entity in the knowledge graph

type NodeType

type NodeType string

NodeType represents the type of a node in the knowledge graph

const (
	// Common node types across languages
	TypeFunction    NodeType = "function"
	TypeClass       NodeType = "class"
	TypeMethod      NodeType = "method"
	TypeModule      NodeType = "module"
	TypePackage     NodeType = "package"
	TypeDependency  NodeType = "dependency"
	TypeAPIEndpoint NodeType = "api_endpoint"
	TypeFile        NodeType = "file"
	TypeConfigFile  NodeType = "config"
	TypeVariable    NodeType = "variable"
	TypeType        NodeType = "type"
	TypeInterface   NodeType = "interface"
	TypeConstant    NodeType = "constant"
	TypeAnnotation  NodeType = "annotation"
	TypeDecorator   NodeType = "decorator"
)

type Watcher

type Watcher struct {
	// contains filtered or unexported fields
}

Watcher monitors project files for changes and updates the knowledge graph

func NewWatcher

func NewWatcher(graph *Graph, projectDir string, analyzer func(string) (*types.ProjectAnalysis, error)) (*Watcher, error)

NewWatcher creates a new file system watcher

func (*Watcher) Start

func (w *Watcher) Start(ctx context.Context) error

Start begins watching for file changes

func (*Watcher) Stop

func (w *Watcher) Stop() error

Stop stops watching for file changes

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL