codeintel

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildGraph

func BuildGraph(workDir string, parsers []Parser) (*ImportGraph, []*FileInfo, error)

BuildGraph parses all source files in workDir and builds the import graph. It resolves local imports to relative file paths where possible. Uses a worker pool parallelized across available CPUs for faster indexing.

func IsExported

func IsExported(name string, language string) bool

IsExported reports whether a symbol name is exported in its language. For Go: starts with uppercase. For others: heuristic based on leading underscore.

Types

type FileInfo

type FileInfo struct {
	Path     string
	Language string
	Imports  []ImportInfo
	Exports  []SymbolInfo
	Funcs    []FuncSignature
	Types    []TypeInfo
}

FileInfo is the parsed representation of a single source file.

type FuncSignature

type FuncSignature struct {
	Name     string
	Receiver string // non-empty for methods (e.g. "*Engine")
	Params   string // parameter list as display string
	Returns  string // return type(s) as display string
	Exported bool
}

FuncSignature represents a function or method signature.

type GoParser

type GoParser struct{}

GoParser uses Go's standard go/ast package for full-fidelity parsing.

func (*GoParser) CanParse

func (p *GoParser) CanParse(path string) bool

func (*GoParser) Language

func (p *GoParser) Language() string

func (*GoParser) Parse

func (p *GoParser) Parse(path string, content []byte) (*FileInfo, error)

type ImportGraph

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

ImportGraph is a directed dependency graph between source files.

func NewImportGraph

func NewImportGraph() *ImportGraph

NewImportGraph creates an empty import graph.

func (*ImportGraph) AddNode

func (g *ImportGraph) AddNode(path string, imports []string, language string)

AddNode adds a file to the graph with its imports. All paths must be relative to the working directory. If the node already exists as a stub (from a reverse edge), it is updated.

func (*ImportGraph) AllPaths

func (g *ImportGraph) AllPaths() []string

AllPaths returns all file paths in the graph, sorted.

func (*ImportGraph) Downstream

func (g *ImportGraph) Downstream(path string, depth int) []string

Downstream returns all files that depend on `path`, up to `depth` levels. depth=1 returns direct importers only. depth=0 means unlimited.

func (*ImportGraph) HasNode

func (g *ImportGraph) HasNode(path string) bool

HasNode reports whether the graph contains a node for the given path.

func (*ImportGraph) Neighbors

func (g *ImportGraph) Neighbors(path string) (imports []string, importedBy []string)

Neighbors returns direct imports and direct importers of a file.

func (*ImportGraph) NodeCount

func (g *ImportGraph) NodeCount() int

NodeCount returns the number of nodes in the graph.

func (*ImportGraph) Upstream

func (g *ImportGraph) Upstream(path string, depth int) []string

Upstream returns all files that `path` depends on, up to `depth` levels. depth=1 returns direct imports only. depth=0 means unlimited.

type ImportInfo

type ImportInfo struct {
	Path       string // raw import path (e.g. "fmt", "./utils", "github.com/foo/bar")
	ResolvedTo string // resolved local file path (populated during graph build)
}

ImportInfo represents a single import declaration in a source file.

type Indexer

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

Indexer provides a unified API for codebase intelligence: parsing, import graph traversal, symbol lookup, and relevance scoring.

func NewIndexer

func NewIndexer(workDir string) *Indexer

NewIndexer creates a new codebase indexer for the given working directory. The indexer is lazy — call Build() before using query methods. When USE_EFIE=true, the EFIE backend is used instead.

func (*Indexer) Build

func (idx *Indexer) Build(ctx context.Context) error

Build parses all source files in the working directory and builds the import graph, symbol index, and relevance scorer.

func (*Indexer) BuiltAt

func (idx *Indexer) BuiltAt() time.Time

BuiltAt returns when the indexer was last built.

func (*Indexer) Define

func (idx *Indexer) Define(symbol string) []SymbolLocation

Define returns where a symbol is defined.

func (*Indexer) Downstream

func (idx *Indexer) Downstream(path string, depth int) []string

Downstream returns files that depend on the given path, up to depth levels.

func (*Indexer) FileCount

func (idx *Indexer) FileCount() int

FileCount returns the number of parsed source files.

func (*Indexer) FileSymbols

func (idx *Indexer) FileSymbols(path string) []SymbolInfo

FileSymbols returns all symbols defined in a file.

func (*Indexer) FormatContext

func (idx *Indexer) FormatContext(targetFiles []string, description string, topN int, maxBytes int) string

FormatContext generates an LLM-ready text summary of relevant codebase intelligence for a set of target files and a task description. The output is capped at maxBytes.

func (*Indexer) IsBuilt

func (idx *Indexer) IsBuilt() bool

IsBuilt reports whether the indexer has been built.

func (*Indexer) Neighbors

func (idx *Indexer) Neighbors(path string) (imports []string, importedBy []string)

Neighbors returns direct imports and importers of a file.

func (*Indexer) ProjectSummary

func (idx *Indexer) ProjectSummary(maxBytes int) string

ProjectSummary returns a high-level summary of the project structure suitable for the plan phase context.

func (*Indexer) RelevantFiles

func (idx *Indexer) RelevantFiles(targetFiles []string, description string, topN int) []ScoredFile

RelevantFiles returns the top-N files most relevant to a task described by target files and a text description.

func (*Indexer) SymbolCount

func (idx *Indexer) SymbolCount() int

SymbolCount returns the number of unique symbols.

func (*Indexer) SymbolsMatching

func (idx *Indexer) SymbolsMatching(query string) []string

SymbolsMatching returns symbols whose names contain the query substring.

func (*Indexer) Upstream

func (idx *Indexer) Upstream(path string, depth int) []string

Upstream returns files that the given path depends on, up to depth levels.

type Node

type Node struct {
	Path       string
	Imports    []string // files this file imports (direct edges)
	ImportedBy []string // files that import this file (reverse edges)

	Language string
	// contains filtered or unexported fields
}

Node represents a single file in the import graph.

type Parser

type Parser interface {
	Language() string
	CanParse(path string) bool
	Parse(path string, content []byte) (*FileInfo, error)
}

Parser extracts structured information from a source file.

func AllParsers

func AllParsers() []Parser

AllParsers returns the default set of language parsers.

func ParserForFile

func ParserForFile(path string, parsers []Parser) Parser

ParserForFile returns the first parser that can handle the given file, or nil.

type PythonParser

type PythonParser struct{}

PythonParser extracts imports, classes, and functions from Python files.

func (*PythonParser) CanParse

func (p *PythonParser) CanParse(path string) bool

func (*PythonParser) Language

func (p *PythonParser) Language() string

func (*PythonParser) Parse

func (p *PythonParser) Parse(path string, content []byte) (*FileInfo, error)

type RelevanceScorer

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

RelevanceScorer ranks files by how relevant they are to a given task.

func NewRelevanceScorer

func NewRelevanceScorer(graph *ImportGraph, index *SymbolIndex) *RelevanceScorer

NewRelevanceScorer creates a scorer backed by the given graph and index.

func (*RelevanceScorer) Score

func (s *RelevanceScorer) Score(targetFiles []string, taskDescription string, topN int) []ScoredFile

Score computes relevance scores for all files relative to a set of target files and a task description. Returns the top-N files sorted by score.

type RustParser

type RustParser struct{}

RustParser extracts use statements, pub items, and type definitions from Rust files.

func (*RustParser) CanParse

func (p *RustParser) CanParse(path string) bool

func (*RustParser) Language

func (p *RustParser) Language() string

func (*RustParser) Parse

func (p *RustParser) Parse(path string, content []byte) (*FileInfo, error)

type ScoredFile

type ScoredFile struct {
	Path    string
	Score   float64
	Reasons []string
}

ScoredFile represents a file ranked by relevance to a task.

type SymbolIndex

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

SymbolIndex maps symbol names to their definitions and files to their symbols.

func BuildIndex

func BuildIndex(files []*FileInfo) *SymbolIndex

BuildIndex creates a symbol index from a list of parsed file infos.

func NewSymbolIndex

func NewSymbolIndex() *SymbolIndex

NewSymbolIndex creates an empty symbol index.

func (*SymbolIndex) AddFile

func (idx *SymbolIndex) AddFile(info *FileInfo)

AddFile indexes all symbols from a parsed file.

func (*SymbolIndex) AllSymbols

func (idx *SymbolIndex) AllSymbols() []string

AllSymbols returns all unique symbol names in the index.

func (*SymbolIndex) Define

func (idx *SymbolIndex) Define(name string) []SymbolLocation

Define returns all locations where a symbol is defined.

func (*SymbolIndex) DefineInFile

func (idx *SymbolIndex) DefineInFile(name, file string) *SymbolLocation

DefineInFile returns the definition of a symbol in a specific file, or nil.

func (*SymbolIndex) FileCount

func (idx *SymbolIndex) FileCount() int

FileCount returns the number of indexed files.

func (*SymbolIndex) FileSymbols

func (idx *SymbolIndex) FileSymbols(path string) []SymbolInfo

FileSymbols returns all symbols defined in a file.

func (*SymbolIndex) FindFuncs

func (idx *SymbolIndex) FindFuncs(name string) []SymbolLocation

FindFuncs returns all function definitions matching the name.

func (*SymbolIndex) FindTypes

func (idx *SymbolIndex) FindTypes(name string) []SymbolLocation

FindTypes returns all type/struct/interface/class/enum definitions matching the name.

func (*SymbolIndex) SymbolCount

func (idx *SymbolIndex) SymbolCount() int

SymbolCount returns the number of unique symbols.

func (*SymbolIndex) SymbolsMatching

func (idx *SymbolIndex) SymbolsMatching(query string) []string

SymbolsMatching returns symbols whose names contain the given substring (case-insensitive).

type SymbolInfo

type SymbolInfo struct {
	Name     string
	Kind     string // "func", "type", "interface", "const", "var", "class", "enum", "trait"
	Exported bool
}

SymbolInfo represents a named symbol exported or defined in a file.

type SymbolLocation

type SymbolLocation struct {
	File string
	Kind string // "func", "type", "interface", "class", "struct", "const", "var"
}

SymbolLocation identifies where a symbol is defined.

type TypeInfo

type TypeInfo struct {
	Name    string
	Kind    string // "struct", "interface", "type", "class", "enum", "trait"
	Fields  []string
	Methods []string
}

TypeInfo represents a struct, interface, class, or enum definition.

type TypeScriptParser

type TypeScriptParser struct{}

TypeScriptParser extracts imports, exports, functions, and types from TypeScript and JavaScript files using regex patterns.

func (*TypeScriptParser) CanParse

func (p *TypeScriptParser) CanParse(path string) bool

func (*TypeScriptParser) Language

func (p *TypeScriptParser) Language() string

func (*TypeScriptParser) Parse

func (p *TypeScriptParser) Parse(path string, content []byte) (*FileInfo, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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