Documentation
¶
Overview ¶
Package leda provides dependency-graph context isolation for LLM tools. Given a codebase and a natural-language prompt, leda builds a directed dependency graph from source files, seeds entry points from the prompt, and traverses the graph to return only the files the LLM actually needs.
Index ¶
- Variables
- type Context
- type Edge
- type FanOutEntry
- type Graph
- func (g *Graph) AddEdge(from, to string)
- func (g *Graph) AddNode(info NodeInfo)
- func (g *Graph) Edges() []Edge
- func (g *Graph) IsolateContext(prompt string, opts ...QueryOption) *Context
- func (g *Graph) NodeInfos() []NodeInfo
- func (g *Graph) Nodes() []string
- func (g *Graph) RootDir() string
- func (g *Graph) Save(w io.Writer) error
- func (g *Graph) SaveToFile(path string) error
- func (g *Graph) Stats() GraphStats
- type GraphStats
- type NodeInfo
- type Option
- type QueryOption
- type SeedStrategy
Constants ¶
This section is empty.
Variables ¶
var DefaultExclude = []string{
".git", "node_modules", "vendor", ".next",
"__pycache__", ".tox", "dist", "build",
}
DefaultExclude contains directory names skipped by default during graph building.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct {
Files []string // absolute paths of isolated files
Seeds []string // which nodes were entry points
TokenCount int // estimated token count
TraceGraph *Graph // subgraph showing only the traversed portion
}
Context is the result of IsolateContext.
func (*Context) Contents ¶
Contents reads and concatenates all isolated files with filepath headers.
func (*Context) ContentsWithBudget ¶
ContentsWithBudget is like Contents but stops at approximately maxTokens. A maxTokens of 0 means no limit.
func (*Context) FormatForLLM ¶
FormatForLLM returns a structured prompt-ready string with file manifest + contents.
type FanOutEntry ¶
FanOutEntry pairs a file with its edge count.
type Graph ¶
type Graph struct {
// contains filtered or unexported fields
}
Graph is a directed dependency graph of source files.
func BuildGraph ¶
BuildGraph walks rootDir, parses all recognized source files, and returns a dependency graph.
func LoadFromFile ¶
LoadFromFile is a convenience that loads a graph from a file.
func (*Graph) IsolateContext ¶
func (g *Graph) IsolateContext(prompt string, opts ...QueryOption) *Context
IsolateContext returns the minimal set of files relevant to the prompt.
func (*Graph) SaveToFile ¶
SaveToFile is a convenience that saves the graph to a file.
func (*Graph) Stats ¶
func (g *Graph) Stats() GraphStats
Stats returns summary statistics about the graph.
type GraphStats ¶
type GraphStats struct {
NodeCount int
EdgeCount int
Components int
TopFanOut []FanOutEntry
TopFanIn []FanOutEntry
}
GraphStats summarizes a graph.
type NodeInfo ¶
type NodeInfo struct {
Path string
RelPath string
Extension string
Symbols []string
Size int64
TokenEstimate int
}
NodeInfo holds metadata about a file node in the graph.
type Option ¶
type Option func(*buildConfig)
Option configures graph building.
func WithExclude ¶
WithExclude adds glob patterns to exclude from graph building.
func WithExtensions ¶
WithExtensions limits parsing to these file extensions.
func WithGitIgnore ¶
WithGitIgnore controls whether .gitignore files are respected during graph building. Enabled by default.
func WithMaxDepth ¶
WithMaxDepth limits directory recursion depth.
func WithParsers ¶
WithParsers overrides the default parser registry.
func WithResolver ¶
WithResolver overrides the default import resolver.
type QueryOption ¶
type QueryOption func(*queryConfig)
QueryOption configures context isolation.
func WithCustomSeeder ¶
func WithCustomSeeder(fn func(prompt string, nodes []NodeInfo) []string) QueryOption
WithCustomSeeder provides a custom seed function.
func WithMaxFiles ¶
func WithMaxFiles(n int) QueryOption
WithMaxFiles caps the result set to n files.
func WithMaxTokens ¶
func WithMaxTokens(n int) QueryOption
WithMaxTokens caps estimated tokens in the result.
func WithSeedStrategy ¶
func WithSeedStrategy(s SeedStrategy) QueryOption
WithSeedStrategy sets the strategy for mapping prompt terms to graph nodes.
type SeedStrategy ¶
type SeedStrategy int
SeedStrategy controls how prompt terms map to graph nodes.
const ( // SeedFilename matches prompt words against file basenames. SeedFilename SeedStrategy = iota // SeedSymbol matches against exported symbols. SeedSymbol // SeedPath matches against full relative paths. SeedPath // SeedCustom uses a user-provided seed function. SeedCustom )