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

selection

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package selection chooses the most useful representation of collected files under a token budget. It is shared by the non-interactive CLI and the TUI.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Candidate

type Candidate struct {
	File          format.FileEntry
	PreferredMode string
	Signals       Signals
	AreaWeight    float64
	Area          string
}

Candidate is a collected file plus the mode preference supplied by history or another caller.

type Decision

type Decision struct {
	Path            string  `json:"path"`
	Area            string  `json:"area,omitempty"`
	Mode            Mode    `json:"mode"`
	Selected        bool    `json:"selected"`
	Score           float64 `json:"score"`
	Utility         float64 `json:"utility"`
	Tokens          int     `json:"tokens"`
	FullTokens      int     `json:"full_tokens"`
	SignatureTokens int     `json:"signature_tokens"`
	Role            string  `json:"role,omitempty"`
	RoleConfidence  float64 `json:"role_confidence,omitempty"`
	TaskRelevance   float64 `json:"task_relevance,omitempty"`
	Signals         Signals `json:"signals,omitempty"`
	Reason          string  `json:"reason"`
}

Decision explains the automatic decision for one candidate.

type Mode

type Mode string

Mode is the output representation selected for a file.

const (
	ModeFull       Mode = "full"
	ModeSignatures Mode = "signatures"
	ModeSkip       Mode = "skip"
)

type Report

type Report struct {
	Result  Result
	Skipped []walker.SkippedItem
}

Report contains selection decisions and optional scan skips for display.

func (Report) Print

func (r Report) Print(w io.Writer, style string, includeSkipped bool) error

Print writes a tree, JSON, or NDJSON report.

type Request

type Request struct {
	Budget    int
	MaxStates int    // zero uses the default sparse-DP state limit.
	Prompt    string // optional task text used to improve path relevance.
	// Tuning carries the optimizer's numeric knobs. The zero value means the
	// built-in defaults; config layers pass an explicit tuning to override.
	Tuning Tuning
}

Request controls automatic selection.

type Result

type Result struct {
	Decisions  []Decision
	Selected   []format.FileEntry
	UsedTokens int
	Budget     int
}

Result contains every decision and the finalized files selected for output.

func Select

func Select(candidates []Candidate, request Request) Result

Select chooses a mode for every file. With no budget it preserves the established score/filter modes. With a budget it reserves guaranteed slots for high-retention files (entrypoints, docs, config) and uses sparse dynamic programming for the rest, choosing among full, signature, and skip variants to maximize total utility rather than simply taking files in score order.

type Signals

type Signals struct {
	Recency      float64 `json:"recency,omitempty"`
	Churn        float64 `json:"churn,omitempty"`
	Centrality   float64 `json:"centrality,omitempty"`
	Role         float64 `json:"role,omitempty"`
	TestAffinity float64 `json:"test_affinity,omitempty"`
}

Signals are optional ranking inputs retained for explainable reports.

type Tuning

type Tuning struct {
	BaseMin         float64
	BaseMax         float64
	RelevanceWeight float64
	PreferenceBonus float64
	SignatureBonus  float64
	SkipMultiplier  float64
	SigQualityMin   float64
	SigQualityMax   float64
	// TestTaskBoost raises test-file utility when the prompt is test-focused.
	TestTaskBoost float64
	// RetentionFloor is the minimum retention value at or above which a file
	// is guaranteed a slot under budget (its best affordable variant is
	// reserved first). Files below the floor compete through the DP.
	RetentionFloor float64
	// AreaDiminishing reduces utility for later files in the same area.
	AreaDiminishing float64
	// AreaBudgetShare is the default maximum fraction of the total budget one
	// area may consume when several distinct areas are present.
	AreaBudgetShare float64
	// AreaRoots maps directory prefixes to explicit area names. Longest
	// matching prefix wins; this lets repositories override inferred areas.
	AreaRoots map[string]string
	// Retention overrides the lang role defaults per role name (e.g.
	// "entrypoint"). Config takes priority over the lang default.
	Retention map[string]float64
	// SkipRoles are role names that automatic selection excludes before
	// optimization. An empty list uses the conservative built-in defaults.
	SkipRoles []string
}

Tuning holds every numeric knob the utility optimizer reads. Values come from the config [scoring] section; the zero value resolves to the defaults below, so no tuning numbers are hardcoded in the DP itself.

func DefaultTuning

func DefaultTuning() Tuning

DefaultTuning returns the stock optimizer tuning.

type Variant

type Variant struct {
	Mode    Mode
	Tokens  int
	Utility float64
	Reason  string
}

Variant is one representation choice for a candidate.

Jump to

Keyboard shortcuts

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