collect

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultBudgetChars = 100_000

Variables

This section is empty.

Functions

func IsCopyPasteIntent

func IsCopyPasteIntent(intent, diffText string) bool

IsCopyPasteIntent returns true if the intent is suspiciously similar to the diff.

func IsEmptyIntent

func IsEmptyIntent(intent string) bool

IsEmptyIntent returns true if the intent text is too short to be useful.

func ParseDiffFromFile

func ParseDiffFromFile(path string) ([]*gitdiff.File, error)

ParseDiffFromFile reads a unified diff from a file path.

func ParseDiffFromGit

func ParseDiffFromGit(base, head string) ([]*gitdiff.File, error)

ParseDiffFromGit runs git diff between base and head refs and parses the result.

func ParseDiffFromReader

func ParseDiffFromReader(r io.Reader) ([]*gitdiff.File, error)

ParseDiffFromReader reads a unified diff from an io.Reader.

func ReadIntentFromFile

func ReadIntentFromFile(path string) (string, string, error)

ReadIntentFromFile reads PR description text from a markdown file.

func ReadIntentFromPRJSON

func ReadIntentFromPRJSON(path string) (string, string, error)

ReadIntentFromPRJSON reads title and body from gh pr view --json output.

func ReadIntentFromStdin

func ReadIntentFromStdin(r io.Reader) (string, string, error)

ReadIntentFromStdin reads PR description from stdin.

func RiskOrder

func RiskOrder(r RiskTag) int

RiskOrder returns a numeric priority for sorting (lower = higher risk).

Types

type ChangedFile

type ChangedFile struct {
	Path      string       `json:"path"`
	Category  FileCategory `json:"category"`
	Risk      RiskTag      `json:"risk"`
	Added     int          `json:"added"`
	Deleted   int          `json:"deleted"`
	IsBinary  bool         `json:"is_binary"`
	HunkText  string       `json:"hunk_text,omitempty"`
	Truncated bool         `json:"truncated,omitempty"`
}

ChangedFile represents a single file from the diff with classification metadata.

func FilesToChangedFiles

func FilesToChangedFiles(files []*gitdiff.File) []ChangedFile

FilesToChangedFiles converts parsed gitdiff files into our ChangedFile type.

func TruncateFiles

func TruncateFiles(files []ChangedFile, budget int) (included []ChangedFile, excluded []string, truncated bool)

TruncateFiles applies the diff truncation strategy: 1. Exclude generated/vendor/binary/lockfile 2. Sort remaining by risk (high risk first) 3. Truncate low-risk hunks to fit within char budget

type CollectResult

type CollectResult struct {
	Intent        string        `json:"intent"`
	IntentSource  string        `json:"intent_source"`
	Files         []ChangedFile `json:"files"`
	TotalAdded    int           `json:"total_added"`
	TotalDeleted  int           `json:"total_deleted"`
	ExcludedFiles []string      `json:"excluded_files,omitempty"`
	Truncated     bool          `json:"truncated"`
	DiffChars     int           `json:"diff_chars"`
	BudgetChars   int           `json:"budget_chars"`
}

CollectResult is the output of the Collect stage, ready for the Analyze stage.

type FileCategory

type FileCategory string

FileCategory classifies a changed file by its role in the project.

const (
	CategorySource    FileCategory = "source"
	CategoryTest      FileCategory = "test"
	CategoryConfig    FileCategory = "config"
	CategoryDocs      FileCategory = "docs"
	CategoryGenerated FileCategory = "generated"
	CategoryVendor    FileCategory = "vendor"
	CategoryBinary    FileCategory = "binary"
	CategoryLockfile  FileCategory = "lockfile"
)

func ClassifyFile

func ClassifyFile(path string) FileCategory

ClassifyFile determines the FileCategory for a given file path.

type RiskTag

type RiskTag string

RiskTag indicates the risk level of a changed file based on its path.

const (
	RiskAuth  RiskTag = "auth"
	RiskAPI   RiskTag = "api"
	RiskData  RiskTag = "data"
	RiskInfra RiskTag = "infra"
	RiskOther RiskTag = "other"
)

func TagRisk

func TagRisk(path string) RiskTag

TagRisk assigns a risk tag to a file based on its path.

Jump to

Keyboard shortcuts

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