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

app

package
v1.1.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

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

func RankParams(files []format.FileEntry, fanIn map[string]int) []rank.ScoringParams

RankParams maps enriched entries to the ranking boundary. FanInCount is fed from the reverse import fan-in index.

func TuningFromScoring

func TuningFromScoring(s config.Scoring) selection.Tuning

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.

func WeightsFromScoring

func WeightsFromScoring(s config.Scoring) rank.Weights

WeightsFromScoring maps a config [scoring] section onto the ranker's composite weights. Zero config fields fall back to the engine defaults so an empty section behaves identically to not configuring anything.

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
}

App encapsulates the main application functionality

func New

func New(cfg *config.Config) (*App, error)

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 (*App) Close

func (a *App) Close()

Close performs cleanup, such as closing the output file if one was opened.

func (*App) Collect

func (a *App) Collect() ([]format.FileEntry, []walker.SkippedItem, error)

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

func (a *App) CollectPicker() ([]format.FileEntry, []walker.SkippedItem, error)

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

func (a *App) LogError(format string, args ...interface{})

LogError logs an error message through the app's logger.

func (*App) Output

func (a *App) Output() io.Writer

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

func (a *App) OutputPath() string

OutputPath returns the absolute path of the output file, or "" when writing to stdout.

func (*App) ReadEntry

func (a *App) ReadEntry(relativePath string) (format.FileEntry, error)

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

func (a *App) RenderFinalWithPrompt(files []format.FileEntry, skippedItems []walker.SkippedItem, duration time.Duration, runErr error, prompt string) error

RenderFinalWithPrompt renders picker output with a session-specific directive without mutating application configuration.

func (*App) RenderToClipboard

func (a *App) RenderToClipboard(files []format.FileEntry) error

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

func (a *App) RenderToClipboardWithPrompt(files []format.FileEntry, prompt string) error

RenderToClipboardWithPrompt renders clipboard output with a session-specific directive without mutating application configuration.

func (*App) Run

func (a *App) Run() error

Run executes the main application logic. It returns a non-nil error when the scan failed, including on timeout.

func (*App) SkeletonPicker

func (a *App) SkeletonPicker(ctx context.Context) ([]walker.FileMeta, []walker.SkippedItem, error)

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 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 NewRanker

func NewRanker(rootDir string) *Ranker

NewRanker returns a Ranker rooted at dir using the default scoring weights.

func NewRankerWithWeights

func NewRankerWithWeights(rootDir string, weights rank.Weights) *Ranker

NewRankerWithWeights returns a Ranker rooted at dir with explicit scoring weights. Zero weight fields fall back to the defaults.

func (*Ranker) Available

func (r *Ranker) Available() bool

Available reports whether the root is inside a git repository.

func (*Ranker) Rank

func (r *Ranker) Rank(files []format.FileEntry) map[string]rank.FileScoreResult

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.

Jump to

Keyboard shortcuts

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