Documentation
¶
Overview ¶
Package analyzer implements the context analysis engine. It traverses the dependency graph, scores candidates, and produces a ranked context bundle per ADR-0007 and ADR-0009.
Index ¶
- Constants
- func AssignRiskTier(score int) string
- func ComputeRiskScore(file model.ChangedFile, analysis *model.AnalysisOutput, idx *db.Index, ...) (int, []string)
- func FormatCompact(output *model.AnalysisOutput) string
- func FormatCompactChange(report *model.ChangeReport) string
- func FormatRiskBadge(report *model.ChangeReport) string
- func FormatRiskTriage(report *model.ChangeReport) string
- func GenerateNarrative(file model.ChangedFile, analysis *model.AnalysisOutput, idx *db.Index) string
- func GenerateTestSuggestions(changedFiles []model.ChangedFile, analyses map[string]*model.AnalysisOutput) []model.TestSuggestion
- type Analyzer
- type Caps
- type Config
- type MustReadEntryRef
Constants ¶
const ( TierSafe = "SAFE" TierReview = "REVIEW" TierTest = "TEST" TierCritical = "CRITICAL" )
RiskTier constants.
const (
// SchemaVersion is the current output schema version for analysis bundles.
SchemaVersion = "3.2"
)
Schema and threshold constants.
Variables ¶
This section is empty.
Functions ¶
func AssignRiskTier ¶ added in v1.0.7
AssignRiskTier maps a risk score to a tier label.
func ComputeRiskScore ¶ added in v1.0.7
func ComputeRiskScore(file model.ChangedFile, analysis *model.AnalysisOutput, idx *db.Index, changedPaths []string, maxIndegree int) (int, []string)
ComputeRiskScore calculates a per-file risk score (0-100).
Formula:
- Base score by status (added/modified/deleted/renamed)
- Structural risk for modified files (importers, co-change, fragility, mutual deps, cycles)
- Coverage adjustment (direct tests reduce, no tests increase)
- Clamp to [0, 100]
func FormatCompact ¶ added in v1.0.7
func FormatCompact(output *model.AnalysisOutput) string
FormatCompact produces a token-optimized text summary of an analysis output. Targets ~60-75% fewer tokens than full JSON while preserving all essential information.
func FormatCompactChange ¶ added in v1.0.7
func FormatCompactChange(report *model.ChangeReport) string
FormatCompactChange produces a token-optimized text summary of a change report.
func FormatRiskBadge ¶ added in v1.0.7
func FormatRiskBadge(report *model.ChangeReport) string
FormatRiskBadge produces a human-readable risk summary for CI output. Designed to be understood without knowledge of the scoring system.
func FormatRiskTriage ¶ added in v1.0.7
func FormatRiskTriage(report *model.ChangeReport) string
FormatRiskTriage produces a structured risk triage output for a change report.
func GenerateNarrative ¶ added in v1.0.7
func GenerateNarrative(file model.ChangedFile, analysis *model.AnalysisOutput, idx *db.Index) string
GenerateNarrative produces a human-readable risk explanation for a file. idx is optional — when provided, Go files use package-level importer counts.
func GenerateTestSuggestions ¶ added in v1.0.7
func GenerateTestSuggestions(changedFiles []model.ChangedFile, analyses map[string]*model.AnalysisOutput) []model.TestSuggestion
GenerateTestSuggestions creates test suggestions for high-risk untested files.
Types ¶
type Analyzer ¶
type Analyzer struct {
// contains filtered or unexported fields
}
Analyzer orchestrates graph traversal, scoring, categorization, and explanation.
func (*Analyzer) Analyze ¶
func (a *Analyzer) Analyze(filePath string) (*model.AnalysisOutput, error)
Analyze produces a context bundle for the given file path. The filePath must be repo-relative and present in the index.
func (*Analyzer) AnalyzeMulti ¶
func (a *Analyzer) AnalyzeMulti(filePaths []string) (*model.AnalysisOutput, error)
AnalyzeMulti produces a merged context bundle for multiple files. It calls Analyze() for each file and merges the results: deduped must_read, combined likely_modify, tests, related, and conservative blast_radius.
type Caps ¶
type Caps struct {
MaxMustRead int // default 10
MaxRelated int // default 10
MaxLikelyModify int // default 15
MaxTests int // default 5
Mode string // workflow mode: plan, implement, review (adjusts defaults)
TokenBudget int // target token budget (overrides caps to fit)
}
Caps controls the maximum number of entries in each output section. Zero values use defaults.
type Config ¶
type Config struct {
RepoConfig *config.Config
StableThreshold int // Files with indegree >= this are marked stable. 0 = use adaptive default.
OmitExternal bool // When true, omit external dependencies from output.
Caps Caps // Output section caps. Zero values use defaults.
Signatures bool // When true, include code signatures for must_read symbols.
RepoRoot string // Repository root path (required for signatures to read files).
}
Config configures the analyzer.
type MustReadEntryRef ¶
MustReadEntryRef holds references to a MustReadEntry's fields for enrichment.