workspacefiles

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package workspacefiles serves ranked file and folder search under one directory root from a cached, git-backed index with a bounded walk fallback.

Index

Constants

View Source
const (
	// DefaultMaxFiles caps the number of files indexed per root.
	DefaultMaxFiles = 25_000
	// DefaultCacheTTL is how long a built index serves searches for one root.
	DefaultCacheTTL = 15 * time.Second
	// DefaultGitTimeout bounds the git subprocesses of one index build.
	DefaultGitTimeout = 5 * time.Second
	// DefaultBuildTimeout bounds one whole shared index build, git and walk fallback included.
	DefaultBuildTimeout = 10 * time.Second
	// DefaultMaxWalkEntries caps the directory entries (files and folders) one walk visits.
	DefaultMaxWalkEntries = 4 * DefaultMaxFiles
)

Variables

View Source
var ErrInvalidRoot = errors.New("workspacefiles: search root is required")

ErrInvalidRoot reports a blank search root.

Functions

func ClassifySymlink(root string, rel string) (string, bool)

ClassifySymlink classifies a symlink by its target, as mention resolution does: a directory inside root lists as a folder ("rel/"), a regular file inside root as a file, and a broken, escaping, or special target is skipped.

Types

type Entry

type Entry struct {
	Path string // relative to the searched root; folders end in "/"
	Name string
	Kind EntryKind
}

Entry is one indexed file or folder.

type EntryKind

type EntryKind string

EntryKind distinguishes files from folders.

const (
	KindFile   EntryKind = "file"
	KindFolder EntryKind = "folder"
)

type GitRunner

type GitRunner interface {
	Run(ctx context.Context, dir string, args ...string) (stdout []byte, stderr []byte, err error)
}

GitRunner runs git with structured arguments. It is satisfied by worktree.RealGitRunner, which internal/daemon injects; this package never spawns git itself.

type Index

type Index interface {
	Search(ctx context.Context, root string, query string, limit int) (Result, error)
	Paths(ctx context.Context, root string) ([]Entry, bool, error)
}

Index searches files and folders under a directory root.

func New

func New(git GitRunner, opts ...Option) Index

New returns an index that lists git roots through git.

type Option

type Option func(*index)

Option customizes an index. Options exist for tests.

func WithBuildTimeout

func WithBuildTimeout(timeout time.Duration) Option

WithBuildTimeout overrides the deadline of one shared build.

func WithCacheTTL

func WithCacheTTL(ttl time.Duration) Option

WithCacheTTL overrides the per-root cache lifetime.

func WithClock

func WithClock(now func() time.Time) Option

WithClock overrides the cache clock.

func WithGitTimeout

func WithGitTimeout(timeout time.Duration) Option

WithGitTimeout overrides the git deadline of one build.

func WithLogger

func WithLogger(logger *slog.Logger) Option

WithLogger overrides the index logger.

func WithMaxFiles

func WithMaxFiles(limit int) Option

WithMaxFiles overrides the per-root file cap.

func WithMaxWalkEntries

func WithMaxWalkEntries(limit int) Option

WithMaxWalkEntries overrides how many directory entries one walk may visit.

type Result

type Result struct {
	Entries []Entry
	// Truncated reports that the root held more files than the index cap.
	Truncated bool
}

Result is one ranked search page.

type StreamingGitRunner

type StreamingGitRunner interface {
	GitRunner
	RunStreaming(
		ctx context.Context,
		dir string,
		onStdout func(chunk []byte),
		args ...string,
	) (stderr []byte, err error)
}

StreamingGitRunner is an optional GitRunner capability that delivers stdout chunks as git writes them, without an output cap. When the injected runner implements it, listings stream and stop at the index cap; otherwise the buffered Run path is used.

Jump to

Keyboard shortcuts

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