Documentation
¶
Index ¶
- Constants
- Variables
- func ApplyRankScores(files []format.FileEntry, results map[string]rank.FileScoreResult)
- func ExpandChosen(files, chosen []format.FileEntry, rootDir string, budget, maxDepth int) []format.FileEntry
- func ExpandDependencies(selected, files []format.FileEntry, graph map[string][]string, maxDepth int) []format.FileEntry
- func ExpandGraphDirs(graph map[string][]string, paths []string) map[string][]string
- func FollowModes(hits []FollowHit, fullDepth int) map[string]string
- func InvertGraph(graph map[string][]string) map[string][]string
- func MergeGraphs(a, b map[string][]string) map[string][]string
- func ParseFollowDirection(s string) (string, error)
- func RankParams(files []format.FileEntry, fanIn map[string]int) []rank.ScoringParams
- func ReadPreview(root string, relativePath string, mode string, maxBytes int64, ...) (content []byte, tokens int, redactions int, language string, truncated bool, ...)
- func RelatedTestAffinity(files []format.FileEntry, graph map[string][]string) map[string]float64
- func RenderBuffer(ctx context.Context, files []format.FileEntry, prompt string, ...) ([]byte, error)
- func RenderBufferSections(ctx context.Context, files []format.FileEntry, prompt string, ...) ([]byte, []format.Section, error)
- func ResolveSeed(rootDir, seed string) (string, error)
- func Scan(ctx context.Context, root string, cfg *config.Config) ([]format.FileEntry, []walker.SkippedItem, error)
- func ScanPicker(ctx context.Context, root string, cfg *config.Config) ([]format.FileEntry, []walker.SkippedItem, error)
- func SeedPinError(seed string, wantMode string, budget int) error
- func SelectWithDependencies(req DependencyRequest) selection.Result
- func Skeleton(ctx context.Context, root string, cfg *config.Config) ([]walker.FileMeta, []walker.SkippedItem, error)
- func TuningFromScoring(s config.Scoring) selection.Tuning
- func WeightsFromScoring(s config.Scoring) rank.Weights
- type App
- func (a *App) Close()
- func (a *App) Collect() ([]format.FileEntry, []walker.SkippedItem, error)
- func (a *App) CollectPicker() ([]format.FileEntry, []walker.SkippedItem, error)
- func (a *App) Config() *config.Config
- func (a *App) EnablePickerVisibility()
- func (a *App) LogError(format string, args ...interface{})
- func (a *App) Output() io.Writer
- func (a *App) OutputPath() string
- func (a *App) ReadEntry(relativePath string) (format.FileEntry, error)
- func (a *App) Render(files []format.FileEntry, skippedItems []walker.SkippedItem, ...) error
- func (a *App) RenderFinal(files []format.FileEntry, skippedItems []walker.SkippedItem, ...) error
- func (a *App) RenderFinalToBuffer(files []format.FileEntry, prompt string) ([]byte, error)
- func (a *App) RenderFinalWithPrompt(files []format.FileEntry, skippedItems []walker.SkippedItem, ...) error
- func (a *App) RenderToClipboard(files []format.FileEntry) error
- func (a *App) RenderToClipboardWithPrompt(files []format.FileEntry, prompt string) error
- func (a *App) Run() error
- func (a *App) SkeletonPicker(ctx context.Context) ([]walker.FileMeta, []walker.SkippedItem, error)
- func (a *App) StreamPicker(ctx context.Context, emit func(format.FileEntry) error) ([]walker.SkippedItem, error)
- type DependencyRequest
- type FollowHit
- type FollowSelection
- type Ranker
- func (r *Ranker) Available() bool
- func (r *Ranker) DependencyGraph(files []format.FileEntry) map[string][]string
- func (r *Ranker) Rank(files []format.FileEntry) map[string]rank.FileScoreResult
- func (r *Ranker) RankGraph(files []format.FileEntry) (map[string]rank.FileScoreResult, map[string][]string)
Constants ¶
const ( FollowDeps = "deps" FollowDependents = "dependents" FollowBoth = "both" )
Follow directions for walking the import graph.
Variables ¶
var ErrFileSkipped = scan.ErrFileSkipped
ErrFileSkipped is returned by ReadEntry when the smart filter rejects the requested file (e.g. a lockfile or generated artifact). It aliases the processor's sentinel so callers can unwrap the underlying reason.
Functions ¶
func ApplyRankScores ¶
func ApplyRankScores(files []format.FileEntry, results map[string]rank.FileScoreResult)
ApplyRankScores writes the computed scores back into the entries.
func ExpandChosen ¶ added in v1.3.0
func ExpandChosen(files, chosen []format.FileEntry, rootDir string, budget, maxDepth int) []format.FileEntry
ExpandChosen appends dependency files of the chosen set as signature-compressed entries for render paths with a hand-picked selection (picker generate/quit-and-render). When budget > 0, dependency spend is bounded by what remains after the chosen set; non-positive budgets add the full closure. rootDir anchors module-root resolution.
func ExpandDependencies ¶ added in v1.3.0
func ExpandDependencies(selected, files []format.FileEntry, graph map[string][]string, maxDepth int) []format.FileEntry
ExpandDependencies walks the dependency graph outward from the selected set with a breadth-first search. maxDepth bounds the walk (mirroring codegrab's --max-depth); negative means unlimited, zero disables expansion. A visited set breaks import cycles. Graph targets naming directories (Go package imports) expand to every collected file beneath them. Already-selected files are never returned. Output is stable: by distance, then by path.
func ExpandGraphDirs ¶ added in v1.5.0
ExpandGraphDirs rewrites directory targets to the sorted collected files beneath them (Go package imports name directories). Targets naming neither a file nor a directory with collected files are dropped.
func FollowModes ¶ added in v1.5.0
FollowModes assigns the preferred render mode per walked path: the seed and everything within fullDepth hops renders in full, farther files as signatures. A negative fullDepth renders everything in full.
func InvertGraph ¶ added in v1.5.0
InvertGraph builds the importers adjacency: file -> files that import it. Directory targets are expected to be expanded to files first; anything left unexpanded inverts as-is.
func MergeGraphs ¶ added in v1.5.0
MergeGraphs unions two adjacencies over the same path space, sorting and de-duplicating each neighbor list so walks over the union are stable.
func ParseFollowDirection ¶ added in v1.5.0
ParseFollowDirection validates a --direction value.
func RankParams ¶
RankParams maps enriched entries to the ranking boundary. FanInCount is fed from the reverse import fan-in index.
func ReadPreview ¶ added in v1.4.0
func ReadPreview(root string, relativePath string, mode string, maxBytes int64, cfg *config.Config) (content []byte, tokens int, redactions int, language string, truncated bool, err error)
ReadPreview reads a single file inside root exactly as the picker would and returns content for mode ("full" or "sigs") capped at maxBytes with a truncation flag, the post-redaction token count, the redaction count, and the detected language. Redaction defaults on: when cfg.ForceSecrets is set the call is refused, so previews can never silently leak secrets.
func RelatedTestAffinity ¶ added in v1.3.0
RelatedTestAffinity scores each test file by the relevance of its related implementation files. Same-directory source files and resolved imports are considered; the result is normalized to the source file's existing rank.
func RenderBuffer ¶ added in v1.4.0
func RenderBuffer(ctx context.Context, files []format.FileEntry, prompt string, cfg *config.Config) ([]byte, error)
RenderBuffer renders exactly the given files (no token budget) into a buffer: secret redaction, token recount, and style rendering via the shared render core. Cancellation is honored between the redaction pass and the document write, and during the write itself.
func RenderBufferSections ¶ added in v1.4.0
func RenderBufferSections(ctx context.Context, files []format.FileEntry, prompt string, cfg *config.Config) ([]byte, []format.Section, error)
RenderBufferSections renders exactly the given files (no token budget) like RenderBuffer and additionally returns one byte range per rendered file for outline navigation. Offsets index the returned document.
func ResolveSeed ¶ added in v1.5.0
ResolveSeed maps a seed argument (root-relative or absolute) to the repo-relative slash path of a file inside rootDir. Anything else — outside the root, missing, or not a regular file — errors naming the reason.
func Scan ¶ added in v1.4.0
func Scan(ctx context.Context, root string, cfg *config.Config) ([]format.FileEntry, []walker.SkippedItem, error)
Scan walks, processes, and ranks the project at root in blocking (full content) mode, returning entries ordered by git relevance. The token budget is not applied; callers curate the selection first.
func ScanPicker ¶ added in v1.4.0
func ScanPicker(ctx context.Context, root string, cfg *config.Config) ([]format.FileEntry, []walker.SkippedItem, error)
ScanPicker walks, processes, and ranks the project at root in picker mode (full + signature content and token counts per file). It backs the TUI, the MCP pack_context tool, and the serve tree endpoint.
func SeedPinError ¶ added in v1.5.0
SeedPinError reports that the seed did not survive budgeting at its assigned mode, so there is nothing worth rendering.
func SelectWithDependencies ¶ added in v1.3.0
func SelectWithDependencies(req DependencyRequest) selection.Result
SelectWithDependencies runs the normal selection pass, expands the dependency closure of the selected set, and re-runs the optimizer over the union: first-pass selections keep their chosen modes as preferences, dependencies enter biased toward signatures (they're context, not the thing under review). One budget, one optimization — dependencies compete fairly with upgrades instead of starving on post-upgrade crumbs.
func Skeleton ¶ added in v1.4.0
func Skeleton(ctx context.Context, root string, cfg *config.Config) ([]walker.FileMeta, []walker.SkippedItem, error)
Skeleton returns file metadata (no content) for root with the caller's context, matching the files a full ScanPicker would enrich.
func TuningFromScoring ¶
TuningFromScoring converts a config [scoring] section onto the selection optimizer's tuning. Zero config fields fall back to the engine defaults; the Retention map is copied through verbatim so config can override the lang-default retention for any role.
Types ¶
type App ¶
type App struct {
// OnlyPaths, when non-nil, restricts the walk to these relative paths.
// Used by sift diff to dump a curated set of files.
OnlyPaths map[string]bool
// contains filtered or unexported fields
}
func New ¶
New creates a new App instance. It resolves color usage from the terminal and output destination and opens the configured output file; an error is returned when the output file cannot be created. Color decisions are passed explicitly to the logger and renderer rather than mutating global state.
func NewBuffered ¶ added in v1.4.0
NewBuffered creates an App that renders to buffers only. Unlike New it never creates the configured output file and never writes to stdout, so it is safe to use for serving many projects inside one process.
func (*App) Collect ¶
Collect walks and processes the configured directory, returning the collected file entries ordered by git relevance. The token budget is deliberately not applied here so callers can curate the selection first.
func (*App) CollectPicker ¶
CollectPicker walks the directory for the interactive picker. Unlike Collect it keeps both the full and signature-only content and token counts per file (plus secret counts and git rank scores) so the TUI can show live previews, token tallies, and smart auto-selection. No global compression mode is applied; callers pick the active view per file.
func (*App) Config ¶ added in v1.3.0
Config returns the resolved application configuration. It is exposed to picker orchestration so streaming rank updates use the same scoring policy as non-interactive selection.
func (*App) EnablePickerVisibility ¶
func (a *App) EnablePickerVisibility()
EnablePickerVisibility lets the interactive picker receive hidden and gitignored metadata so the TUI can reveal it without rescanning.
func (*App) Output ¶
Output returns the writer the rendered document is written to, backing the configured output file or stdout. Callers that produce output outside the standard render path (e.g. delta patches) reuse it to honor --output.
func (*App) OutputPath ¶
OutputPath returns the absolute path of the output file, or "" when writing to stdout.
func (*App) ReadEntry ¶
ReadEntry reads and processes a single relative path exactly as the picker would, returning a fully enriched entry. It backs the picker's fallback when a selected file has not finished streaming in yet, and returns ErrFileSkipped when the smart filter rejects the file.
func (*App) Render ¶
func (a *App) Render(files []format.FileEntry, skippedItems []walker.SkippedItem, duration time.Duration, runErr error) error
Render applies the token budget to files and writes the rendered document. A non-nil runErr from Collect is reported but rendering still happens so the output stays well-formed (e.g. valid JSON on timeout).
func (*App) RenderFinal ¶
func (a *App) RenderFinal(files []format.FileEntry, skippedItems []walker.SkippedItem, duration time.Duration, runErr error) error
RenderFinal renders exactly the given files without re-applying the token budget. It is used by the interactive picker, whose TUI owns budget accounting (including smart auto-selection); nothing is dropped afterwards.
func (*App) RenderFinalToBuffer ¶ added in v1.2.0
RenderFinalToBuffer renders exactly the given files (no token budget) into a newly allocated byte slice without touching the configured output destination. The interactive picker uses it to replace an output file non-destructively: the render must fully succeed before the previous dump is truncated, so a failed render never destroys the last good document.
func (*App) RenderFinalWithPrompt ¶
func (a *App) RenderFinalWithPrompt(files []format.FileEntry, skippedItems []walker.SkippedItem, duration time.Duration, runErr error, prompt string) error
directive without mutating application configuration.
func (*App) RenderToClipboard ¶
RenderToClipboard renders the given files and copies the result to the system clipboard, without writing to the configured output destination. It backs the picker's live copy action.
func (*App) RenderToClipboardWithPrompt ¶
directive without mutating application configuration.
func (*App) Run ¶
Run executes the main application logic. It returns a non-nil error when the scan failed, including on timeout.
func (*App) SkeletonPicker ¶
SkeletonPicker returns file metadata (no content) for the picker's structure-first launch. It applies the same ignore, extension, prune, and smart name rules as the full walk so the skeleton matches the files that will later be enriched. Smart-skipped entries are folded into the skip list.
func (*App) StreamPicker ¶
func (a *App) StreamPicker(ctx context.Context, emit func(format.FileEntry) error) ([]walker.SkippedItem, error)
StreamPicker walks the directory for the interactive picker without blocking: emit is called for each accepted file as soon as it is processed (possibly concurrently), and rank scores are not applied here so the caller can patch them asynchronously. The returned skip list is complete only after the walk finishes.
type DependencyRequest ¶ added in v1.3.0
type DependencyRequest struct {
Candidates []selection.Candidate
Files []format.FileEntry
Graph map[string][]string
Preferred map[string]rank.FileScoreResult
Budget int
Prompt string
Tuning selection.Tuning
MaxDepth int
}
DependencyRequest carries one selection pass plus its dependency follow-up.
type FollowHit ¶ added in v1.5.0
FollowHit is one file reached from the seed: its shortest distance in hops (the seed itself is 0) and the parent it was first discovered through.
func WalkGraph ¶ added in v1.5.0
WalkGraph breadth-first searches the adjacency from seeds. maxDepth bounds the walk in hops (0 reports the seeds only); negative means unlimited. Output is stable: seeds in order, then by distance, then by path. Cycles terminate on the visited set, so every file reports its shortest distance and the parent that first discovered it.
type FollowSelection ¶ added in v1.5.0
type FollowSelection struct {
Candidates []selection.Candidate
Hits []FollowHit
Modes map[string]string
Unanalyzed int
}
FollowSelection is the optimizer-ready form of a seed walk: one candidate per hit with distance-based mode preferences, plus the walk itself, the per-path modes, and the count of eligible files no resolver covers.
func FollowCandidates ¶ added in v1.5.0
func FollowCandidates(files []format.FileEntry, graph map[string][]string, preferred map[string]rank.FileScoreResult, seed, direction string, maxDepth, fullDepth int, modeOverride string) (FollowSelection, error)
FollowCandidates walks the import graph from the seed and builds the optimizer input, sharing one construction across the follow command, the select --follow debug flag, the MCP tool, and the serve endpoint. files are the collected entries, graph their forward adjacency, and preferred their rank results for signals. modeOverride ("" for distance-based modes) honors an explicit --mode for every hit including the seed.
type Ranker ¶
type Ranker struct {
// contains filtered or unexported fields
}
Ranker applies the unified relevance scoring to collected entries. It is the application-level adapter between processed FileEntries and the rank package, which stays free of format.FileEntry. Both the blocking collect path and the picker's streaming rank patch go through it.
func NewRankerWithContext ¶ added in v1.4.0
NewRankerWithContext returns a Ranker like NewRankerWithWeights whose git subprocesses are killed when ctx is done.
func NewRankerWithWeights ¶
NewRankerWithWeights returns a Ranker rooted at dir with explicit scoring weights. Zero weight fields fall back to the defaults.
func (*Ranker) DependencyGraph ¶ added in v1.3.0
DependencyGraph returns only the import-dependency adjacency, without running git scoring or touching the entries. Dependency expansion (ExpandChosen) discards RankGraph's scores, so routing it through RankGraph paid for git status/diff/log subprocesses on every generate just to throw the results away. It never mutates files.
func (*Ranker) Rank ¶
Rank computes unified relevance scores for files, writes them back into the entries, and stably sorts the slice by descending score so equal scores keep their original order. It returns the raw results keyed by path for callers that also need the preferred mode (e.g. the streaming picker patch). Duplicate paths collapse to a single result, which is written back to every matching entry. Fan-in centrality uses the collected content.
func (*Ranker) RankGraph ¶ added in v1.3.0
func (r *Ranker) RankGraph(files []format.FileEntry) (map[string]rank.FileScoreResult, map[string][]string)
RankGraph ranks like Rank and additionally returns the dependency adjacency retained from the fan-in pass: file path → confirmed dependency paths. Targets are resolved files, except Go package imports which name directories for the caller to expand against the collected set.