drift

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package drift provides spec-to-code drift detection.

Drift detection compares the reconciled spec.md with the actual codebase to identify requirements that haven't been implemented, code that exists without spec coverage, and mismatches between spec and implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Analyzer

type Analyzer struct{}

Analyzer performs spec-to-code comparison.

func (*Analyzer) Compare

func (a *Analyzer) Compare(requirements []SpecRequirement, implementations []CodeImplementation) []DriftItem

Compare finds drift between requirements and implementations.

func (*Analyzer) ExtractImplementations

func (a *Analyzer) ExtractImplementations(ctx *context.AggregatedContext) []CodeImplementation

ExtractImplementations analyzes codebase context for implementations.

func (*Analyzer) ExtractRequirements

func (a *Analyzer) ExtractRequirements(specContent string) []SpecRequirement

ExtractRequirements parses spec.md and extracts requirements.

type Category

type Category string

Category groups drift items by type.

const (
	CategoryAPI    Category = "api"
	CategoryData   Category = "data"
	CategoryUI     Category = "ui"
	CategoryInfra  Category = "infra"
	CategoryConfig Category = "config"
	CategoryOther  Category = "other"
)

type CodeImplementation

type CodeImplementation struct {
	ID          string
	Description string
	Type        string // api, data, feature
	File        string
	Line        int
}

CodeImplementation represents a feature found in the codebase.

type DetectOptions

type DetectOptions struct {
	MinSeverity  Severity    // Only report items at or above this severity
	Categories   []Category  // Only report items in these categories (empty = all)
	ExcludeTypes []DriftType // Exclude these drift types
}

DetectOptions configures drift detection.

func DefaultOptions

func DefaultOptions() DetectOptions

DefaultOptions returns sensible defaults.

type Detector

type Detector struct{}

Detector performs drift detection.

func NewDetector

func NewDetector() *Detector

NewDetector creates a new drift detector.

func (*Detector) Detect

func (d *Detector) Detect(specContent string, ctx *context.AggregatedContext, opts DetectOptions) (*DriftReport, error)

Detect compares spec content against codebase context.

type DriftItem

type DriftItem struct {
	ID          string    `json:"id"`
	Type        DriftType `json:"type"`
	Severity    Severity  `json:"severity"`
	Category    Category  `json:"category"`
	Description string    `json:"description"`
	SpecRef     string    `json:"spec_ref,omitempty"` // Reference to spec section
	CodeRef     string    `json:"code_ref,omitempty"` // Reference to code file:line
	Suggestion  string    `json:"suggestion,omitempty"`
}

DriftItem represents a single drift finding.

type DriftReport

type DriftReport struct {
	Project     string       `json:"project"`
	GeneratedAt time.Time    `json:"generated_at"`
	Items       []DriftItem  `json:"items"`
	Summary     DriftSummary `json:"summary"`
}

DriftReport contains all drift findings for a project.

func (*DriftReport) FilterByCategory

func (r *DriftReport) FilterByCategory(categories ...Category) []DriftItem

FilterByCategory returns items in the given categories.

func (*DriftReport) FilterBySeverity

func (r *DriftReport) FilterBySeverity(minSeverity Severity) []DriftItem

FilterBySeverity returns items at or above the given severity.

func (*DriftReport) HasBlockers

func (r *DriftReport) HasBlockers() bool

HasBlockers returns true if there are critical or high severity items.

func (*DriftReport) HasDrift

func (r *DriftReport) HasDrift() bool

HasDrift returns true if any drift was detected.

type DriftSummary

type DriftSummary struct {
	TotalItems    int               `json:"total_items"`
	ByType        map[DriftType]int `json:"by_type"`
	BySeverity    map[Severity]int  `json:"by_severity"`
	ByCategory    map[Category]int  `json:"by_category"`
	CriticalCount int               `json:"critical_count"`
	HighCount     int               `json:"high_count"`
	HasBlockers   bool              `json:"has_blockers"`
}

DriftSummary provides aggregate drift statistics.

type DriftType

type DriftType string

DriftType categorizes the type of drift detected.

const (
	// DriftUnimplemented indicates a spec requirement not found in code.
	DriftUnimplemented DriftType = "unimplemented"

	// DriftUndocumented indicates code that exists without spec coverage.
	DriftUndocumented DriftType = "undocumented"

	// DriftMismatch indicates both spec and code exist but differ.
	DriftMismatch DriftType = "mismatch"
)

type RenderFormat

type RenderFormat string

RenderFormat specifies the output format.

const (
	FormatText     RenderFormat = "text"
	FormatJSON     RenderFormat = "json"
	FormatMarkdown RenderFormat = "markdown"
)

type Renderer

type Renderer struct {
	// contains filtered or unexported fields
}

Renderer renders drift reports.

func NewRenderer

func NewRenderer(format RenderFormat) *Renderer

NewRenderer creates a renderer with the specified format.

func (*Renderer) Render

func (r *Renderer) Render(w io.Writer, report *DriftReport) error

Render writes the drift report to the writer.

type Severity

type Severity string

Severity indicates how critical the drift is.

const (
	SeverityCritical Severity = "critical"
	SeverityHigh     Severity = "high"
	SeverityMedium   Severity = "medium"
	SeverityLow      Severity = "low"
)

type SpecRequirement

type SpecRequirement struct {
	ID          string
	Description string
	Type        string // api, data, feature, etc.
	Section     string // Section of spec where found
}

SpecRequirement represents a requirement extracted from spec.md.

Jump to

Keyboard shortcuts

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