filediscovery

package
v0.30.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BuildWorkspaceTimeout is the absolute maximum time for workspace structure building
	BuildWorkspaceTimeout = 30 * time.Second

	// CacheDuration is how long workspace structure results are cached
	CacheDuration = 5 * time.Minute

	// ProgressEmitInterval controls how often progress events are emitted during file walk
	ProgressEmitInterval = 1000 // emit every N files

	// MaxDepth limits directory traversal depth in BuildWorkspaceStructure
	MaxDepth = 20

	// LargeWorkspaceThreshold is the file count above which limits apply
	LargeWorkspaceThreshold = 1000
)

Configurable constants for performance limits

Variables

This section is empty.

Functions

func DefaultSkipDirectories added in v0.24.2

func DefaultSkipDirectories() map[string]bool

DefaultSkipDirectories returns the directory names the index never descends into: build output, dependency stores, VCS internals, and OS/profile folders that are never project sources. Keeping this in pkg/filediscovery (not the webui handler) lets the WASM shell mirror the exact same list.

func GetIgnoreRules

func GetIgnoreRules(rootDir string) *ignore.GitIgnore

GetIgnoreRules reads ignore files (.gitignore, .sprout/.ignore) and returns a gitignore object. Results are cached per root and revalidated against file mtimes, so the hot paths (/api/browse, /api/search, /api/file-index) don't re-read and recompile the rule set on every request.

Types

type DiscoveryOptions

type DiscoveryOptions struct {
	MaxFiles      int
	UseSymbols    bool
	UseShell      bool
	IncludeHidden bool
	ExcludeDirs   []string
	IncludeExts   []string
	ExcludeExts   []string
	RootPath      string
}

DiscoveryOptions configures file discovery behavior

type FileDiscovery

type FileDiscovery struct {
	// contains filtered or unexported fields
}

FileDiscovery provides common file discovery and analysis functionality

func NewFileDiscovery

func NewFileDiscovery(cfg *configuration.Config, logger *utils.Logger) *FileDiscovery

NewFileDiscovery creates a new file discovery instance

func (*FileDiscovery) BuildWorkspaceStructure

func (fd *FileDiscovery) BuildWorkspaceStructure() *WorkspaceInfo

BuildWorkspaceStructure builds workspace structure information. It applies a hard timeout (BuildWorkspaceTimeout), respects directory depth limits, emits progress events for large workspaces, and uses an in-memory cache.

func (*FileDiscovery) DiscoverFilesRobust

func (fd *FileDiscovery) DiscoverFilesRobust(userIntent string, options *DiscoveryOptions) *FileResult

DiscoverFilesRobust uses multiple strategies to find relevant files

func (*FileDiscovery) FilterFiles

func (fd *FileDiscovery) FilterFiles(files []string, criteria *FileFilterCriteria) []string

FilterFiles filters files based on criteria

func (*FileDiscovery) GetFileStats

func (fd *FileDiscovery) GetFileStats(files []string) map[string]interface{}

GetFileStats returns statistics about files

type FileFilterCriteria

type FileFilterCriteria struct {
	IncludeExtensions []string
	ExcludeExtensions []string
	IncludePaths      []string
	ExcludePaths      []string
	MinSize           int64
	MaxSize           int64
	ModifiedAfter     time.Time
	ModifiedBefore    time.Time
}

FileFilterCriteria defines filtering criteria for files

type FileResult

type FileResult struct {
	Files        []string
	Error        error
	Duration     time.Duration
	Method       string
	TotalFiles   int
	MatchedFiles int
}

FileResult represents the result of a file discovery operation

type IndexEntry added in v0.24.2

type IndexEntry struct {
	Name string `json:"name"`
	Path string `json:"path"`
	Type string `json:"type"`
}

IndexEntry is one row of the bulk file index consumed by the command palette's quick-open.

type IndexLimits added in v0.24.2

type IndexLimits struct {
	MaxFiles     int
	MaxDirs      int
	MaxDepth     int
	SkipDirNames map[string]bool
}

IndexLimits bounds a workspace walk so a pathological tree cannot pin the server. Defaults match the frontend's previous crawl caps.

func DefaultIndexLimits added in v0.24.2

func DefaultIndexLimits() IndexLimits

DefaultIndexLimits mirrors the palette's historical crawl bounds.

type IndexResult added in v0.24.2

type IndexResult struct {
	Files       []IndexEntry `json:"files"`
	Truncated   bool         `json:"truncated"`
	FileCount   int          `json:"file_count"`
	DirCount    int          `json:"dir_count"`
	SkippedDirs []string     `json:"skipped_dirs,omitempty"`
}

IndexResult reports the walked index plus whether caps truncated it.

func BuildFileIndex added in v0.24.2

func BuildFileIndex(root string, limits IndexLimits) IndexResult

BuildFileIndex walks root once and returns every non-ignored file (workspace-relative slash paths) up to the limits. Directories matched by the workspace's ignore rules are pruned wholesale; directories in SkipDirNames are counted as skipped so the UI can explain a truncated index. Index is relative-path based: files carry no absolute paths, so an index built for one workspace can never leak rows into another. `.git` is always pruned.

type QueryTerms

type QueryTerms struct {
	FilePatterns []string
	SearchTerms  []string
}

QueryTerms represents parsed query terms

type WorkspaceInfo

type WorkspaceInfo struct {
	ProjectType string
	AllFiles    []string
	FilesByDir  map[string][]string
	Error       error
	RootDir     string
}

WorkspaceInfo represents workspace information

Jump to

Keyboard shortcuts

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