graph

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildEdges

func BuildEdges(symbols []core.SymbolRecord) []core.Edge

BuildEdges constructs all 8 edge types from the symbol set.

Edge construction order (matches Implementation Plan §3.1):

  1. defines (file → symbol) confidence 1.0
  2. contains (parent → child) confidence 1.0
  3. imports (file → import:path) confidence 0.9
  4. extends (subtype → supertype) confidence 0.85
  5. implements (concrete → interface/trait) confidence 0.85
  6. uses-type (symbol → referenced type) confidence 0.5
  7. calls (caller → callee) confidence 0.85 same-file, 0.6 cross-file
  8. tests (test sym → tested sym) confidence 0.8

"calls" and "uses-type" are scoped to same-file + imported-file symbols per the non-negotiable accuracy rule in the plan.

func DetectConflicts

func DetectConflicts(a, b core.IsolatedChangeRegion) core.ConflictResult

DetectConflicts checks whether two ICRs have overlapping exclusive symbols or files.

func DiffSymbols added in v0.6.0

func DiffSymbols(before, after []core.SymbolRecord) core.GraphDiff

DiffSymbols computes the structural delta between two symbol snapshots (typically: the graph before and after a merge or reindex).

Symbols are matched by stable identity — file path + qualified name + kind — not by symbol ID: IDs embed the file content SHA, so any edit changes every ID in the file and an ID-based diff would report whole-file churn for a one-line change. A symbol whose span moved but whose signature and body are unchanged is not reported at all; that is what makes the diff usable as a drift signal ("the ground shifted under you") rather than a line-number echo.

Same-key collisions (e.g. C++ overloads sharing a qualified name) are paired positionally in document order; surplus entries on either side surface as added/removed.

Types

type CodeGraph

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

func New

func New() *CodeGraph

func (*CodeGraph) ComputeICR

func (g *CodeGraph) ComputeICR(intent string) core.IsolatedChangeRegion

ComputeICR computes an Isolated Change Region for the given intent string. When no symbol matches the intent, the region is empty with floor confidence and no lock keys: an arbitrary fallback region (the previous behaviour seeded from the first 20 symbols alphabetically) would make two unrelated no-match intents lock and conflict on the same random files.

func (*CodeGraph) Deps

func (g *CodeGraph) Deps(filePath string) []core.Edge

Deps returns all edges that touch the given file path. Uses exact-prefix matching: edges from "file:<path>" or whose node ID begins with "<path>::" (symbol IDs in that file).

func (*CodeGraph) FileSymbols added in v0.6.1

func (g *CodeGraph) FileSymbols(filePath string) []core.SymbolRecord

FileSymbols returns deep copies of the symbols defined in filePath (slash-separated, repo-relative), ordered by span. Cheap relative to Snapshot: only the one file's symbols are copied.

func (*CodeGraph) Impact

func (g *CodeGraph) Impact(query string, maxDepth int) []core.SymbolRecord

Impact returns all symbols reachable from the seed (identified by query) by traversing inbound edges up to maxDepth. "Inbound" means: things that call, test, or contain the seed symbol — i.e., the blast radius if the seed changes.

func (*CodeGraph) Replace

func (g *CodeGraph) Replace(symbols []core.SymbolRecord, filesIndexed int)

func (*CodeGraph) ReplaceWithEdges added in v0.5.0

func (g *CodeGraph) ReplaceWithEdges(symbols []core.SymbolRecord, extraEdges []core.Edge, filesIndexed int)

func (*CodeGraph) ReplaceWithStoredEdges added in v0.6.0

func (g *CodeGraph) ReplaceWithStoredEdges(symbols []core.SymbolRecord, edges []core.Edge, filesIndexed int)

ReplaceWithStoredEdges installs a previously-computed edge set verbatim — the edges persisted by the last index are already the merged (baseline + native) set, so rehydration must not pay the BuildEdges cost again. Databases written before edges were persisted (symbols but no edges) fall back to a full rebuild.

func (*CodeGraph) Search

func (g *CodeGraph) Search(query string, limit int) []core.SymbolRecord

Search returns symbols matching the query (case-insensitive), ranked by match quality: exact name > exact qualified name > name prefix > name substring > qualified-name substring > path/signature substring. Ranking matters because results are truncated at limit — with the previous alphabetical-by-path ordering, the exact-name match for a common query could be cut off by substring hits in files that happened to sort earlier.

func (*CodeGraph) SemanticSearch

func (g *CodeGraph) SemanticSearch(query string, limit int) []embeddings.Scored

SemanticSearch ranks symbols against a free-text intent using the configured embedding backend (Model2Vec by default; TF-IDF if GROVE_EMBEDDINGS=tfidf). Documents are constructed from (name + qualifiedName + signature + docstring + parent). The engine is built lazily and cached until the next Replace().

func (*CodeGraph) Snapshot

func (g *CodeGraph) Snapshot() ([]core.SymbolRecord, []core.Edge)

func (*CodeGraph) Status

func (g *CodeGraph) Status() core.Status

func (*CodeGraph) TestsFor

func (g *CodeGraph) TestsFor(query string) []core.SymbolRecord

TestsFor returns all test symbols that cover the given query target. Resolution order:

  1. If the query matches an existing symbol name, walk the full inbound dependency closure (calls/contains/implements/extends/uses-type/tests) and gather every test symbol that reaches any node in that closure.
  2. Fallback: substring search in test files (for free-text queries).

Jump to

Keyboard shortcuts

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