Documentation
¶
Overview ¶
Package compound provides high-level compound analysis tools that aggregate multiple lower-level analysis primitives into a single result.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BodyAnalysis ¶
type BodyAnalysis struct {
ErrorExits int `json:"error_exits"` // panic/return err patterns
HasDeferCleanup bool `json:"has_defer_cleanup"`
HasTODO bool `json:"has_todo"`
}
BodyAnalysis contains additional analysis of a symbol's implementation.
func AnalyzeBody ¶
func AnalyzeBody(ctx context.Context, client *oxcodes.Client, root string, sym *parser.Symbol) *BodyAnalysis
AnalyzeBody uses ox-codes to examine a symbol's internal patterns. Searches are scoped to the symbol's file via file_glob for efficiency.
type CallRef ¶
type CallRef struct {
Name string `json:"name"`
File string `json:"file"`
Line uint32 `json:"line"`
Receiver string `json:"receiver,omitempty"`
}
CallRef is a reference to a called/calling function.
type DeadCodeScoreLookup ¶
type DeadCodeScoreLookup interface {
LoadDeadCodeScore(ctx context.Context, repoKey, name, file string) (float32, bool)
}
DeadCodeScoreLookup is the narrow interface for fetching a single symbol's dead-code CE reranker score. *codegraph.Store satisfies it.
type LearningsLookup ¶
type LearningsLookup interface {
Nearest(ctx context.Context, repo, symbol string, k int) ([]learnings.Record, error)
}
LearningsLookup is the narrow interface compound.Understand uses to fetch prior review learnings for a (repo, symbol). *learnings.Store satisfies it. Kept local to the package so tests can supply an in-memory fake without spinning up Postgres.
type MatchRef ¶
type MatchRef struct {
Name string `json:"name"`
Kind string `json:"kind"`
File string `json:"file"`
Line uint32 `json:"line"`
Receiver string `json:"receiver,omitempty"`
}
MatchRef is a lightweight symbol descriptor used in disambiguation responses.
type PrepareChangeOpts ¶
type PrepareChangeOpts struct {
MaxDepth int // max impact traversal depth (default 5)
// Graph optionally surfaces community and pagerank signals for the target
// and its direct callers. When nil the new fields stay zero and are omitted.
Graph graphx.Analytics
// Repo is the user-supplied repo key (host-facing form).
Repo string
// Root is the container-resolved repo path used to key the persistent
// graph. When set, takes precedence over Repo for graph lookups because
// the graph is indexed under the resolved path, not the user-facing one.
Root string
}
PrepareChangeOpts configures pre-change analysis.
type PrepareChangeResult ¶
type PrepareChangeResult struct {
Found bool `json:"found"`
Symbol SymbolInfo `json:"symbol,omitempty"`
Impact *impact.Result `json:"impact,omitempty"`
IsDead bool `json:"is_dead"`
DeadCode *deadcode.Result `json:"dead_code_summary,omitempty"`
Tier string `json:"tier"`
Warnings []string `json:"warnings,omitempty"`
// CommunitiesCrossed is the count of distinct Louvain community IDs among
// the target symbol and its direct callers. Zero when Graph is cold
// (all Found=false) — omitted from JSON output in that case.
CommunitiesCrossed int `json:"communities_crossed,omitempty"`
// HighPRCallers names direct callers whose PageRank is in the repo-level
// top decile (top 10% by TopPageRank). Nil when Graph is cold or no
// caller qualifies — omitted from JSON output in that case.
HighPRCallers []string `json:"high_pagerank_callers,omitempty"`
}
PrepareChangeResult is the output of pre-change risk assessment.
func PrepareChange ¶
func PrepareChange(ctx context.Context, cg *callgraph.CallGraph, symbolName string, opts PrepareChangeOpts) *PrepareChangeResult
PrepareChange runs pre-change risk assessment for a named symbol. It aggregates impact analysis (blast radius) and dead code detection.
type SymbolInfo ¶
type SymbolInfo struct {
Name string `json:"name"`
Kind string `json:"kind"`
File string `json:"file"`
StartLine uint32 `json:"start_line"`
EndLine uint32 `json:"end_line"`
Signature string `json:"signature,omitempty"`
Complexity int `json:"complexity,omitempty"`
Receiver string `json:"receiver,omitempty"`
}
SymbolInfo is a summary of a symbol for compound tool output.
type SymbolRanker ¶
type SymbolRanker interface {
SymbolStructuralRank(ctx context.Context, repoKey, name, file string, pagerank float64) string
}
SymbolRanker computes a human-readable structural importance rank for a symbol. *codegraph.Store satisfies it.
type UnderstandOpts ¶
type UnderstandOpts struct {
IncludeCallers bool
MaxCallees int // default 20
MaxCallers int // default 20
// OxCodes enables body analysis via ox-codes scoped search. Optional.
OxCodes *oxcodes.Client
// Root is the repository root path, required when OxCodes is set.
Root string
// Repo is the user-supplied repo key (slug, URL, or host path) used to
// look up prior learnings. Must match the value persisted by
// review_pr (dry_run=false) for lookups to succeed.
Repo string
// Learnings optionally sources prior review findings for the symbol.
// When nil (not configured) or Nearest returns no rows, the result's
// PriorLearnings field stays empty and is omitted from JSON output.
Learnings LearningsLookup
// Graph optionally surfaces pagerank/community/surprise for the symbol.
// When nil or the graph has no snapshot, GraphSignals.Found stays false.
Graph graphx.Analytics
// Refs optionally sources cross-reference edges from the AGE graph.
// Used to surface tested_by coverage edges. When nil, tested_by is omitted.
Refs graphx.CrossRefs
// DeadCodeScores optionally sources CE reranker scores for dead-code detection.
// When nil, dead_code_score is omitted from the result.
DeadCodeScores DeadCodeScoreLookup
// SymbolRanker optionally computes a human-readable structural importance rank.
// When nil, structural_rank is omitted from the result.
SymbolRanker SymbolRanker
}
UnderstandOpts configures the understand compound analysis.
type UnderstandResult ¶
type UnderstandResult struct {
Symbol SymbolInfo `json:"symbol"`
Callees []CallRef `json:"callees,omitempty"`
Callers []CallRef `json:"callers,omitempty"`
Tier string `json:"tier"`
Warnings []string `json:"warnings,omitempty"`
Body *BodyAnalysis `json:"body_analysis,omitempty"`
PriorLearnings []learnings.Record `json:"prior_learnings,omitempty"`
// GraphSignals holds pagerank/community/surprise when the persistent graph
// has them. Signals.Found==false means the graph is cold; omitted from output.
GraphSignals *graphx.Signals `json:"graph_signals,omitempty"`
// DeadCodeScore is the CE reranker confidence that this symbol is genuine dead code.
// Only present when the symbol has no callers and code_graph has pre-scored it.
// Negative float; closer to 0 means more likely to be genuine dead code.
DeadCodeScore *float32 `json:"dead_code_score,omitempty"`
// DeadCodeNote explains the score when DeadCodeScore is set.
DeadCodeNote string `json:"dead_code_note,omitempty"`
// TestedBy lists test functions that directly cover this symbol via AGE TESTED_BY edges.
TestedBy []graphx.SymbolRef `json:"tested_by,omitempty"`
// StructuralRank is a human-readable summary of the symbol's architectural centrality.
// e.g. "Top 2% (6th of 4040 symbols by structural centrality)"
// Only present when the graph has pagerank data for this symbol.
StructuralRank string `json:"structural_rank,omitempty"`
}
UnderstandResult is the output of the understand compound tool.
func Understand ¶
func Understand(ctx context.Context, sym *parser.Symbol, cg *callgraph.CallGraph, opts UnderstandOpts) *UnderstandResult
Understand performs a deep-dive analysis of a single symbol.