Documentation
¶
Overview ¶
Package rank scores files by git relevance so an LLM gets the most important context first when a token budget is in play. Scores follow the review plan: modified files 1.0, recently diffed 0.8, recently committed 0.5, everything else a low baseline.
Index ¶
- Constants
- type Changes
- type Commit
- type FileScoreResult
- type Git
- func (g *Git) AnalyzeCommitHistory(depth int) map[string]string
- func (g *Git) Available() bool
- func (g *Git) CalculateUnifiedScores(rootDir string, params []ScoringParams, w Weights) map[string]FileScoreResult
- func (g *Git) ChangedBetween(from, to string) []string
- func (g *Git) ChangedSinceRef(ref string) []string
- func (g *Git) ChangesFor(ref string) *Changes
- func (g *Git) CommitsBetween(from, to string) []Commit
- func (g *Git) GetChurnFrequency(n int) map[string]int
- func (g *Git) Head() (short, subject string)
- func (g *Git) Parent(ref string) string
- func (g *Git) RawPatch(from, to string) string
- func (g *Git) Ref(ref string) (short, subject string)
- func (g *Git) Score(rootDir string, paths []string) map[string]float64
- type ScoreSignals
- type ScoringParams
- type Weights
Constants ¶
const ( // ScoreBaseline is the score for files with no git signal. ScoreBaseline = 0.1 // ScoreModified is the score for files with uncommitted changes. ScoreModified = 1.0 // ScoreDiffed is the score for files touched by the recent diff. ScoreDiffed = 0.8 // ScoreCommitted is the score for files in the latest commit. ScoreCommitted = 0.5 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Changes ¶
Changes holds the file sets for each git relevance tier, keyed by slash-separated paths relative to the repository root.
type FileScoreResult ¶
type FileScoreResult struct {
Score float64
PreferredMode string // "full", "signatures", or "skip"
Reason string
Signals ScoreSignals
}
FileScoreResult is the outcome of the unified scoring engine for one file.
type Git ¶
type Git struct {
// contains filtered or unexported fields
}
Git runs git against rootDir.
func (*Git) AnalyzeCommitHistory ¶
AnalyzeCommitHistory inspects the last depth commits plus the working tree and recommends an output mode per touched file. Bulk commits (>10 files) yield signatures; focused commits (<=10 files) yield full content, and working-tree edits force full. Newer commits override older ones. Returns an empty map outside a git repository or on any git error, so callers can fall back to full content.
func (*Git) CalculateUnifiedScores ¶
func (g *Git) CalculateUnifiedScores(rootDir string, params []ScoringParams, w Weights) map[string]FileScoreResult
CalculateUnifiedScores evaluates every file, combining git recency, churn frequency, import centrality, file role, and compression yield into one continuous score. The score drives both mode selection (bands above) and budget trimming, which sorts by it. Role weights come from the lang registry's classification, so the numbers exist in exactly one place.
func (*Git) ChangedBetween ¶
ChangedBetween returns the paths changed between two refs.
func (*Git) ChangedSinceRef ¶
ChangedSinceRef returns the paths that differ between the working tree and ref, including uncommitted changes and commits made after ref. With the default ref (HEAD) this is exactly the uncommitted working tree.
func (*Git) ChangesFor ¶
ChangesFor computes the relevance tiers for ref (default HEAD):
- Modified: uncommitted working-tree or staged changes.
- Diffed: files touched between ref and its first parent.
- Committed: files in the latest commit at ref.
The three git invocations run concurrently since they are independent.
func (*Git) CommitsBetween ¶
CommitsBetween lists the commits in the range from..to, newest first, in short form. The range is empty when to is not an ancestor of HEAD.
func (*Git) GetChurnFrequency ¶
GetChurnFrequency counts how many of the last n commits touched each path. Empty path lines (commit separators) are ignored.
func (*Git) Parent ¶
Parent returns the short hash of ref's first parent, or "" when ref has no parent (e.g. the repository root commit).
type ScoreSignals ¶
type ScoreSignals struct {
Recency float64 `json:"recency"`
Churn float64 `json:"churn"`
Centrality float64 `json:"centrality"`
Role float64 `json:"role"`
}
ScoreSignals exposes the normalized inputs to the composite score. Keeping these values alongside the result makes selection reports explainable and gives callers enough detail to tune the weights without reverse-engineering a single opaque score.
type ScoringParams ¶
type ScoringParams struct {
Path string
TokensFull int
TokensSig int
DidCompress bool
FanInCount int
}
ScoringParams is the per-file input to CalculateUnifiedScores.
type Weights ¶
type Weights struct {
RecencyWeight float64
ChurnWeight float64
CentralityWeight float64
RoleWeight float64
FullBand float64
SkipBand float64
}
Weights tunes the relevance composite. Zero fields fall back to the defaults below, so callers can override only the knobs they care about. Role knowledge (what each role is worth) lives in internal/lang, not here.
func DefaultWeights ¶
func DefaultWeights() Weights
DefaultWeights returns the stock scoring weights.