analyzer

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 17 Imported by: 0

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

View Source
const (
	TierSafe     = "SAFE"
	TierReview   = "REVIEW"
	TierTest     = "TEST"
	TierCritical = "CRITICAL"
)

RiskTier constants.

View Source
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

func AssignRiskTier(score int) string

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:

  1. Base score by status (added/modified/deleted/renamed)
  2. Structural risk for modified files (importers, co-change, fragility, mutual deps, cycles)
  3. Coverage adjustment (direct tests reduce, no tests increase)
  4. 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 New

func New(idx *db.Index, cfg Config) *Analyzer

New creates an Analyzer.

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

type MustReadEntryRef struct {
	File        string
	Symbols     []string
	Definitions *[]string
}

MustReadEntryRef holds references to a MustReadEntry's fields for enrichment.

Jump to

Keyboard shortcuts

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