Documentation
¶
Overview ¶
Package scoring parses unified diffs and scores diff lines against AI candidate data. It is a pure domain package with no infrastructure dependencies. It receives parsed data and returns scores.
Index ¶
- func BuildNormalizedSet(aiLines map[string]map[string]struct{}) map[string]map[string]struct{}
- func NormalizeWhitespace(s string) string
- func ScoreFiles(diff DiffResult, aiLines map[string]map[string]struct{}, ...) ([]FileScore, MatchStats)
- type AddedGroup
- type DiffResult
- type FileDiff
- type FileScore
- type MatchStats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildNormalizedSet ¶
BuildNormalizedSet derives a whitespace-stripped line set from the AI candidate set. Each trimmed line is stripped of all whitespace and stored per file path.
func NormalizeWhitespace ¶
NormalizeWhitespace removes all whitespace characters from s. Used as a second-tier match when exact trimmed comparison fails, catching formatter/linter modifications like:
"func foo(){" vs "func foo() {"
"return x+y" vs "return x + y"
func ScoreFiles ¶
func ScoreFiles( diff DiffResult, aiLines map[string]map[string]struct{}, providerTouchedFiles map[string]string, fileProvider map[string]string, ) ([]FileScore, MatchStats)
ScoreFiles matches AI candidate maps against a parsed diff and returns per-file scores with match statistics.
Parameters are plain maps. Callers unpack candidate data into these maps.
Matching is three-tier:
- Tier 1 (exact): trimmed line matches AI output exactly
- Tier 2 (formatted): matches after whitespace normalization
- Tier 3 (modified): in a contiguous group with tier 1 or 2 overlap
Types ¶
type AddedGroup ¶
type AddedGroup struct {
Lines []string // "+" lines with prefix stripped
}
AddedGroup is a contiguous block of added lines within a diff hunk.
type DiffResult ¶
type DiffResult struct {
Files []FileDiff // all files present in the diff
FilesCreated []string // paths created (from /dev/null)
FilesDeleted []string // paths deleted (to /dev/null)
}
DiffResult holds the parsed output of a unified diff.
func ParseDiff ¶
func ParseDiff(diffBytes []byte) DiffResult
ParseDiff parses a unified diff (as produced by "git diff") into per-file added lines, and identifies newly created and deleted files.
It recognizes:
- "--- /dev/null" + "+++ b/path" -> file created
- "--- a/path" + "+++ /dev/null" -> file deleted
- Lines starting with "+" (excluding the +++ header) -> added lines
type FileDiff ¶
type FileDiff struct {
Path string // repo-relative file path
Groups []AddedGroup // contiguous groups of added lines
DeletedNonBlank int // count of deleted non-blank lines
}
FileDiff holds the added lines for a single file in a unified diff, grouped into contiguous runs.
type FileScore ¶
type FileScore struct {
Path string
TotalLines int
ExactLines int
FormattedLines int
ModifiedLines int
HumanLines int
ProviderLines map[string]int // provider -> AI lines for this file
}
FileScore holds per-file attribution scores.
type MatchStats ¶
MatchStats collects match counters from scoring. Callers combine these with EventStats from the events package.