Documentation
¶
Overview ¶
Package graph is the in-memory code graph: nodes keyed by qualified name, edges, and the adjacency indexes that power callers/callees/impact queries. It is rebuilt from scratch on each service start, so there is no persistence layer here — at ~10^3-10^4 nodes a full re-parse is cheap.
Index ¶
- func DisplayTitle(n *Node) string
- type DumpEdge
- type DumpNode
- type Edge
- type Graph
- func (g *Graph) AttrKeysByKind() map[string]map[string]int
- func (g *Graph) Build(repos ...RepoGraph) LinkStats
- func (g *Graph) Callees(qn string, relation string) []Edge
- func (g *Graph) Callers(qn string, relation string) []Edge
- func (g *Graph) Dump() GraphDump
- func (g *Graph) Get(qn string) (*Node, bool)
- func (g *Graph) ImpactRadius(seeds []string, maxDepth, maxNodes int) []ImpactNode
- func (g *Graph) Nodes() []*Node
- func (g *Graph) NodesForFile(file string) []*Node
- func (g *Graph) Risk(qn string, maxDepth, maxNodes int) RiskReport
- func (g *Graph) SetVec(qn string, vec []float32)
- func (g *Graph) Stats() Stats
- type GraphDump
- type ImpactNode
- type LinkStats
- type Node
- type RepoGraph
- type RiskReport
- type Stats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DisplayTitle ¶
Dump exports the whole graph as titles + edges for a force-directed UI. It emits an edge only when BOTH endpoints are real nodes — the same reasoning as ImpactRadius skipping non-node call targets: unresolved bare symbols (e.g. a common "Get") aren't nodes, and rendering them as phantom hubs would merge unrelated call sites and clutter the layout. Read-only; takes the read lock. DisplayTitle is a node's name as every surface prints it: qualified by its parent when it has one. A child's bare Name is not unique — sibling sets repeat it under every parent — so an unqualified title renders distinct nodes as duplicates. Single definition of the rule: index.nodeTitle calls this.
Types ¶
type DumpEdge ¶
type DumpEdge struct {
Source string `json:"source"`
Target string `json:"target"`
Kind string `json:"kind"`
}
DumpEdge is one directed edge in a GraphDump. Both endpoints are guaranteed to be real nodes in the same dump (see Dump).
type DumpNode ¶
type DumpNode struct {
QN string `json:"qn"`
Repo string `json:"repo,omitempty"`
Kind string `json:"kind"`
Title string `json:"title"`
File string `json:"file"`
Line int `json:"line"`
Lang string `json:"lang,omitempty"`
}
DumpNode is one node in a GraphDump — identity + placement, no body.
type Edge ¶
type Edge struct {
Kind string
Source string
Target string
File string
Line int
// Extra is the extractor's hints for the edge (parser.EdgeInfo.Extra),
// carried through linking so a reader of the graph sees what the extractor
// recorded — a compose env key's inline value, a SQL reference's kind —
// rather than only its endpoints. Shared with the parsed result; read-only.
Extra map[string]string
}
Edge is a stored directed relationship.
type Graph ¶
type Graph struct {
// contains filtered or unexported fields
}
Graph holds the whole code graph. It is read-mostly after Build; the mutex guards the rare full rebuild.
func (*Graph) AttrKeysByKind ¶
AttrKeysByKind reports, per node kind, the attribute keys its nodes carry and how many carry each. Kinds whose nodes carry no attribute (every parsed code kind) are absent, so a code map's stats say nothing new. It is the vocabulary a caller needs BEFORE asking a catalog map to filter or order by an attribute: the team map was ordered by "experience" when the key was "years", and nothing short of reading a node back with get_graph_node could have said so.
func (*Graph) Build ¶
Build atomically swaps in a graph assembled from one or more repositories, running cross-file call resolution so calls edges point at qualified nodes instead of bare names. Lock-free readers see the old graph until the swap completes. It returns resolution stats.
func (*Graph) ImpactRadius ¶
func (g *Graph) ImpactRadius(seeds []string, maxDepth, maxNodes int) []ImpactNode
ImpactRadius runs a bidirectional BFS from the given seed qualified names over dependency edge kinds (calls/imports/inherits/implements/references — see impactEdgeKinds), up to maxDepth, capped at maxNodes. This is the in-memory equivalent of code-review-graph's recursive-CTE blast-radius query.
func (*Graph) NodesForFile ¶
NodesForFile returns all nodes declared in the given file path.
func (*Graph) Risk ¶
func (g *Graph) Risk(qn string, maxDepth, maxNodes int) RiskReport
Risk scores the change risk of one symbol. Thresholds are deliberately simple (caller count + module spread, not a weighted model) — the goal is a quick triage signal, not a precise estimate.
type GraphDump ¶
GraphDump is the lean whole-graph export for visualization: node titles + edges, with no node bodies (Body/Content are omitted — the UI lazy-fetches a single node's full content via /node on click). At ~10^3 nodes this serializes to a few hundred KB, small enough for the UI to fetch once and lay out locally.
type ImpactNode ¶
ImpactNode is a node reached by an impact-radius BFS, with its distance.
type LinkStats ¶
type LinkStats struct {
CallEdges int
ResolvedCalls int // rewritten to a qualified node QN
ExternalCalls int // stdlib / third-party / unresolvable (kept as-is)
ResolvedRatio float64
// ResolvedByRule splits ResolvedCalls by the linker rule that produced each
// edge (pkg, chain, recvPkg, recvType, bare — see link.go), so a build
// shows which declared evidence its edges rest on.
ResolvedByRule map[string]int
// SQLRefs counts SQL references edges resolved to a declared schema object;
// DroppedSQLRefs those that named no single declaration (see sqllink.go).
SQLRefs int
DroppedSQLRefs int
// TypeRefs counts declared type-name references (Java fields, parameters,
// locals); ResolvedTypeRefs those resolved to a class (see typelink.go).
TypeRefs int
ResolvedTypeRefs int
}
LinkStats reports how call-edge resolution went, for observability.
type Node ¶
type Node struct {
parser.NodeInfo
Repo string // owning repository label (multi-repo serving)
QN string // repo-qualified name (cached); unique across repos
Vec []float32 // embedding, nil until indexed
}
Node is a stored code symbol plus its embedding (set after indexing).
type RiskReport ¶
type RiskReport struct {
QN string
Level string // LOW, MEDIUM, HIGH
DirectCallers int
ModuleSpread int
ImpactedCount int
Modules []string
}
RiskReport buckets a symbol's change risk into a coarse LOW/MEDIUM/HIGH signal, derived from its direct caller count and how many distinct modules (directories) its blast radius reaches. It is a heuristic, not a precise cost model — it exists so a caller gets a signal instead of having to eyeball a raw impact list themselves.
type Stats ¶
Stats reports node/edge counts by kind.
func (Stats) DependencyEdges ¶
DependencyEdges counts the edges impact and risk traverse (impactEdgeKinds). Zero means the map is structure-only — contains edges alone, as in a document collection — and a blast radius is not defined for it.