Help us shape the future of Go! Take the 2026 Go Developer Survey

impact

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package impact provides syntax-aware source code change impact analysis.

Package impact provides syntax-aware source code change impact analysis.

Package impact provides syntax-aware source code change impact analysis. It measures statement counts and cyclomatic complexity deltas using Tree-sitter ASTs.

Index

Constants

View Source
const (
	// PromptActionModuleLevel is the advisory prompt for module-level documentation.
	PromptActionModuleLevel = "" /* 157-byte string literal not displayed */
	// PromptActionCrossModule is the advisory prompt for cross-module documentation.
	PromptActionCrossModule = "Ensure system-level documentation or architecture decision records (ADR) reflect this cross-cutting update if applicable."
)

Variables

This section is empty.

Functions

func AuditFileSymbols

func AuditFileSymbols(info *FileDiffInfo, req DocAuditRequirement) ([]*SymbolImpact, *DocAuditResult, error)

AuditFileSymbols analyzes the symbols in info against git diff lines and returns impacted symbols and docstring audit results.

func ExtractModule

func ExtractModule(path string) string

ExtractModule extracts normalized directory boundary representation for a file path.

func GetLanguage

func GetLanguage(extOrPath string) (*tree_sitter.Language, error)

GetLanguage returns the Tree-sitter Language for the given extension or file path.

Types

type AffectedScope

type AffectedScope struct {
	Scope        string `json:"scope"`
	Category     string `json:"category"` // "module_level" or "cross_module"
	Description  string `json:"description"`
	PromptAction string `json:"prompt_action"`
}

AffectedScope represents a scope (module or cross-module) that may require documentation updates.

type DocAuditRequirement

type DocAuditRequirement string

DocAuditRequirement specifies the required documentation level for symbol audit.

const (
	// DocAuditExported requires docstrings only for exported/public symbols (default).
	DocAuditExported DocAuditRequirement = "exported"
	// DocAuditAll requires docstrings for all symbols (both public and private).
	DocAuditAll DocAuditRequirement = "all"
	// DocAuditNone performs no docstring audit.
	DocAuditNone DocAuditRequirement = "none"
)

type DocAuditResult

type DocAuditResult struct {
	PublicCoverage    float64  `json:"public_api_doc_coverage"`
	PrivateCoverage   float64  `json:"private_api_doc_coverage"`
	MissingDocstrings []string `json:"missing_docstrings"`
}

DocAuditResult represents documentation audit metrics and missing docstrings.

type DocumentationAdvisory

type DocumentationAdvisory struct {
	RequiresIntentReview bool            `json:"requires_intent_review"`
	Reason               string          `json:"reason,omitempty"`
	AffectedScopes       []AffectedScope `json:"affected_scopes,omitempty"`
}

DocumentationAdvisory represents guidance on synchronizing external documentation.

func BuildDocumentationAdvisory

func BuildDocumentationAdvisory(symbols []*SymbolImpact, fileImpacts []*FileImpact) *DocumentationAdvisory

BuildDocumentationAdvisory evaluates module-level and cross-module structural changes and produces a DocumentationAdvisory if documentation review or update is recommended.

type FileDiffInfo

type FileDiffInfo struct {
	FilePath     string `json:"file_path"`
	OldPath      string `json:"old_path,omitempty"`
	IsNew        bool   `json:"is_new"`
	IsDeleted    bool   `json:"is_deleted"`
	AddedLines   []int  `json:"added_lines"`
	DeletedLines []int  `json:"deleted_lines"`
	OldContent   []byte `json:"old_content,omitempty"`
	NewContent   []byte `json:"new_content,omitempty"`
}

FileDiffInfo contains git diff information for a single file.

func GetGitDiff

func GetGitDiff(projectRoot string, baseRef string) ([]*FileDiffInfo, error)

GetGitDiff extracts file diff information comparing baseRef and current working tree, including untracked files, staged and unstaged changes. If baseRef is empty, "HEAD" is used as default.

type FileImpact

type FileImpact struct {
	FilePath        string         `json:"file_path,omitempty"`
	Statements      StatementDelta `json:"statements"`
	ComplexityDelta int            `json:"complexity_delta"`
	ImpactLevel     ImpactLevel    `json:"impact_level"`
}

FileImpact represents the impact analysis result for a single file.

func AnalyzeFileSource

func AnalyzeFileSource(filePath, ext string, oldSrc, newSrc []byte) (*FileImpact, error)

AnalyzeFileSource parses oldSrc and newSrc for filePath and returns a FileImpact.

func AnalyzeSource

func AnalyzeSource(ext string, oldSrc, newSrc []byte) (*FileImpact, error)

AnalyzeSource parses oldSrc and newSrc using the Tree-sitter language matching ext, and calculates the StatementDelta, ComplexityDelta, and overall ImpactLevel.

type ImpactLevel

type ImpactLevel string

ImpactLevel represents the magnitude of source code change.

const (
	// ImpactMinor indicates minor changes (statements < 20 and complexity delta <= 2).
	ImpactMinor ImpactLevel = "MINOR"
	// ImpactModerate indicates moderate changes (statements 20-60 or complexity delta > 2 with statements < 20).
	ImpactModerate ImpactLevel = "MODERATE"
	// ImpactSignificant indicates significant changes (statements 61-150).
	ImpactSignificant ImpactLevel = "SIGNIFICANT"
	// ImpactExtreme indicates extreme changes (statements > 150).
	ImpactExtreme ImpactLevel = "EXTREME"
)

func CalculateImpactLevel

func CalculateImpactLevel(statementChanges int, complexityDelta int) ImpactLevel

CalculateImpactLevel determines the ImpactLevel from statement changes and complexity delta.

type StatementDelta

type StatementDelta struct {
	Added   int `json:"added"`
	Deleted int `json:"deleted"`
}

StatementDelta represents the number of added and deleted statements.

type SymbolImpact

type SymbolImpact struct {
	File            string `json:"file"`
	SymbolPath      string `json:"symbol_path"`
	Kind            string `json:"kind"`
	Visibility      string `json:"visibility"`  // "public" or "private"
	ChangeType      string `json:"change_type"` // "added", "modified", "deleted"
	StatementsDelta int    `json:"statements_delta"`
	HasDocstring    bool   `json:"has_docstring"`
}

SymbolImpact represents impact analysis for a single symbol.

Jump to

Keyboard shortcuts

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