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

rank

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2026 License: MIT Imports: 6 Imported by: 0

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

View Source
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

type Changes struct {
	Modified  map[string]bool
	Diffed    map[string]bool
	Committed map[string]bool
}

Changes holds the file sets for each git relevance tier, keyed by slash-separated paths relative to the repository root.

func NewChanges

func NewChanges() *Changes

NewChanges returns an empty Changes.

func (*Changes) Score

func (c *Changes) Score(path string) float64

Score returns the highest tier score matching path.

type Commit

type Commit struct {
	Short   string
	Hash    string
	Subject string
}

Commit identifies a git commit in the short form used by delta dumps.

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 New

func New(dir string) *Git

New returns a Git handle rooted at dir.

func (*Git) AnalyzeCommitHistory

func (g *Git) AnalyzeCommitHistory(depth int) map[string]string

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) Available

func (g *Git) Available() bool

Available reports whether rootDir is inside a git repository.

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

func (g *Git) ChangedBetween(from, to string) []string

ChangedBetween returns the paths changed between two refs.

func (*Git) ChangedSinceRef

func (g *Git) ChangedSinceRef(ref string) []string

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

func (g *Git) ChangesFor(ref string) *Changes

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

func (g *Git) CommitsBetween(from, to string) []Commit

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

func (g *Git) GetChurnFrequency(n int) map[string]int

GetChurnFrequency counts how many of the last n commits touched each path. Empty path lines (commit separators) are ignored.

func (*Git) Head

func (g *Git) Head() (short, subject string)

Head returns the short hash and subject of the current HEAD commit.

func (*Git) Parent

func (g *Git) Parent(ref string) string

Parent returns the short hash of ref's first parent, or "" when ref has no parent (e.g. the repository root commit).

func (*Git) RawPatch

func (g *Git) RawPatch(from, to string) string

RawPatch returns the unified diff between from and to.

func (*Git) Ref

func (g *Git) Ref(ref string) (short, subject string)

Ref returns the short hash and subject of the given ref.

func (*Git) Score

func (g *Git) Score(rootDir string, paths []string) map[string]float64

Score returns a score for every given relative path. When the directory is not a git repository every path gets the baseline score.

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.

Jump to

Keyboard shortcuts

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