filescan

package
v0.0.202 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package filescan provides shared file scanning and token estimation utilities

Index

Constants

View Source
const (
	TokenThresholdSafe  = 10000 // Files under this are safe to read fully
	TokenThresholdLarge = 25000 // Files under this can be read with care
	TokenThresholdMax   = 25000 // Claude-code's max file read limit
	BytesPerToken       = 4     // Rough estimate for text files
)

Token thresholds (matching claude-code limits)

Variables

View Source
var BinaryExtensions = map[string]bool{
	".exe": true, ".bin": true, ".so": true, ".dylib": true, ".dll": true,
	".png": true, ".jpg": true, ".jpeg": true, ".gif": true, ".ico": true, ".webp": true,
	".zip": true, ".tar": true, ".gz": true, ".rar": true, ".7z": true,
	".pdf": true, ".doc": true, ".docx": true, ".xls": true, ".xlsx": true,
	".mp3": true, ".mp4": true, ".avi": true, ".mov": true, ".mkv": true,
	".woff": true, ".woff2": true, ".ttf": true, ".eot": true, ".otf": true,
	".pyc": true, ".pyo": true, ".class": true, ".o": true, ".a": true,
	".sqlite": true, ".db": true,
}

BinaryExtensions is the set of extensions to skip when IgnoreBinary is true

Functions

This section is empty.

Types

type FileInfo

type FileInfo struct {
	Path            string
	RelPath         string // Relative to scan root
	Size            int64
	EstimatedTokens int
	IsDir           bool
}

FileInfo holds basic file information with token estimation

func (*FileInfo) TokenCategory

func (f *FileInfo) TokenCategory() string

TokenCategory returns the token budget category for a file

type ScanOptions

type ScanOptions struct {
	// IgnoreDirs is a set of directory names to skip
	IgnoreDirs map[string]bool

	// IgnoreHidden skips files and dirs starting with "."
	IgnoreHidden bool

	// IgnoreBinary skips common binary file extensions
	IgnoreBinary bool

	// MaxDepth limits recursion depth (0 = unlimited)
	MaxDepth int
}

ScanOptions configures the scanner behavior

func DefaultOptions

func DefaultOptions() ScanOptions

DefaultOptions returns sensible defaults for code scanning

type ScanResult

type ScanResult struct {
	Root           string
	Files          []FileInfo
	TotalFiles     int
	TotalTokens    int
	SafeCount      int
	LargeCount     int
	OversizedCount int
}

ScanResult holds the results of a directory scan

func Scan

func Scan(root string, opts ScanOptions) (*ScanResult, error)

Scan walks a directory and collects file information with token estimates

func ScanPaths

func ScanPaths(paths []string, opts ScanOptions) (*ScanResult, error)

ScanPaths scans multiple paths and combines results

func (*ScanResult) FilterByCategory

func (r *ScanResult) FilterByCategory(category string) []FileInfo

FilterByCategory returns files matching the given category

func (*ScanResult) HasLargeFiles

func (r *ScanResult) HasLargeFiles() bool

HasLargeFiles returns true if there are any large or oversized files

func (*ScanResult) Manifest

func (r *ScanResult) Manifest() string

Manifest generates a human-readable token budget manifest

func (*ScanResult) MarkdownSection

func (r *ScanResult) MarkdownSection() string

MarkdownSection generates a markdown section for embedding in codebase index

Jump to

Keyboard shortcuts

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