Documentation
¶
Overview ¶
Package codegraph indexes the symbols and resolved call edges of a Go module and answers the queries an agent asks of a code graph: where a symbol is, who calls it, what it calls, and which tests reach it.
Index ¶
- Variables
- func CacheDir() (string, error)
- func Configure(data []byte) error
- func RefTools(ix *Index) []mcp.Tool
- func Tier2Tools(ix *Index) []mcp.Tool
- func Tier3Tools(ix *Index) []mcp.Tool
- func Tools(ix *Index) []mcp.Tool
- func Words(question string) []string
- type Hit
- type Index
- func (ix *Index) Affected(symbol string, depth, limit int) ([]Symbol, error)
- func (ix *Index) Callees(symbol string, limit int) ([]Symbol, error)
- func (ix *Index) Callers(symbol string, limit int) ([]Symbol, error)
- func (ix *Index) Expand(names []string) map[string]string
- func (ix *Index) FileNeighbors(file string, limit int) (dependencies, dependents []string)
- func (ix *Index) FileSymbols(file string) []Symbol
- func (ix *Index) Find(term string, limit int) []Symbol
- func (ix *Index) ImpactRisk(target string, limit int) ([]map[string]any, []Symbol, error)
- func (ix *Index) ImportsExports(file string) (imports, exports []string, err error)
- func (ix *Index) Neighbourhood(seeds []string, depth, nodeLimit int) (nodes []string, edges [][2]string)
- func (ix *Index) Neighbours(target string, limit int) ([]Symbol, error)
- func (ix *Index) Node(symbol string, limit int) (Symbol, string, []Symbol, error)
- func (ix *Index) Query(question string, k, budget int, skeleton bool) []Hit
- func (ix *Index) RankFiles(question string, limit int) []Hit
- func (ix *Index) References(symbol string, limit int) ([]Reference, error)
- func (ix *Index) ShortestPath(src, tgt string) ([]string, error)
- func (ix *Index) Stats() (symbols, edges int)
- func (ix *Index) TestsFor(target string, limit int) ([]Symbol, error)
- func (ix *Index) Trace(src, tgt string, k int) ([][]string, error)
- type Reference
- type Symbol
Constants ¶
This section is empty.
Variables ¶
var ErrNotConfigured = errors.New("codegraph: rules not configured; call Configure first")
ErrNotConfigured is returned by Build until Configure has been called.
Functions ¶
func Configure ¶
Configure sets the business rules from YAML the caller supplies (ranking weights, stopwords, result limits, path bounds). Build fails with ErrNotConfigured until it succeeds.
func RefTools ¶
RefTools are the reference and import tools. references covers Go only as far as the SSA form records non-call uses; imports_exports reads Go files.
func Tier2Tools ¶
Tier2Tools are the path, neighbourhood and source tools. references and imports_exports are not served: they need non-call references and import statements, which the index does not store.
func Tier3Tools ¶
Tier3Tools are the memory, workspace, risk and fetch tools. Notes are local (see package notes). Workspaces are one: this module. Options that only the hosted memory service has (profiles, sufficiency, grounding, time filters) are accepted and ignored. fetch takes a symbol name, not a repository:snapshot:node id, because this index has no snapshots.
Types ¶
type Index ¶
type Index struct {
Root string // absolute module root
Module string
Symbols map[string]Symbol
// Missing lists languages found in the module whose language server is
// not installed, so their symbols are absent.
Missing []string
// Notes is the module's local note store, used by the memory tools.
Notes *notes.Store
// contains filtered or unexported fields
}
Index is the code graph of one module.
func Build ¶
Build indexes every function in dir. Go modules are analysed with SSA and VTA. Other languages found under dir are analysed by the language server that registry.yaml names for them, when one is installed.
func BuildCached ¶
BuildCached returns the index of dir, reusing the copy saved in cacheDir when no file under dir has changed since it was saved. Otherwise it builds the index and saves it there.
func (*Index) Affected ¶
Affected lists the symbols that depend on the target through callers, up to depth hops. Each symbol appears once, at its nearest distance.
func (*Index) Expand ¶
Expand returns the source of each named symbol; names that do not resolve are reported with an empty body.
func (*Index) FileNeighbors ¶
FileNeighbors are the files this file calls into (dependencies) and the files that call into it (dependents), from the call graph.
func (*Index) FileSymbols ¶
FileSymbols are the symbols defined in a file, in source order.
func (*Index) ImpactRisk ¶
ImpactRisk ranks the files holding the target's direct callers and callees by how many of those symbols they hold, and lists the tests that reach the target.
func (*Index) ImportsExports ¶
ImportsExports lists the import paths and exported top-level names of a Go file under the module root. Other languages are not analysed.
func (*Index) Neighbourhood ¶
func (ix *Index) Neighbourhood(seeds []string, depth, nodeLimit int) (nodes []string, edges [][2]string)
Neighbourhood is the set of symbols within depth hops of the seeds, and the call edges between them, capped at nodeLimit nodes.
func (*Index) Neighbours ¶
Neighbours are the direct callers and callees of the target symbol.
func (*Index) Query ¶
Query returns the k best-matching symbols for question, with their source text cut to budget characters. skeleton drops the source.
func (*Index) References ¶
References returns the non-call uses of a symbol, sorted by location.
func (*Index) ShortestPath ¶
ShortestPath is the shortest connection between src and tgt when call edges are followed in either direction. It is nil when they are not connected.
type Reference ¶
type Reference struct {
Symbol string `json:"symbol"` // the referenced symbol
From string `json:"from"` // the symbol whose body makes the reference
File string `json:"file"`
Line int `json:"line"`
}
Reference is a use of a symbol that is not a direct call: the function is passed, stored, or captured as a value.
type Symbol ¶
type Symbol struct {
Name string // full name, e.g. "example.com/m/pkg.(*T).Method" or "src/app.py::Login.run"
File string // path relative to the module root
Line int
Language string // "go", or the registry id of a language server
IsTest bool // defined in a test file
}
Symbol is one function or method in the module.