scanner

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SafeResolvePath

func SafeResolvePath(baseDir, userPath string, maxSize int64) (string, error)

SafeResolvePath resolves a user-provided path relative to baseDir with security checks. It prevents path traversal, validates file existence and size, and adds .md extension if missing.

Types

type CachedScanner

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

CachedScanner wraps Scanner with caching and file watching capabilities

func NewCachedScanner

func NewCachedScanner(scanner *Scanner, ttl time.Duration) (*CachedScanner, error)

NewCachedScanner creates a new cached scanner with file watching

func (*CachedScanner) Close

func (cs *CachedScanner) Close() error

Close stops the file watcher and cleans up resources

func (*CachedScanner) CommandsDir

func (cs *CachedScanner) CommandsDir() string

CommandsDir returns the commands directory path

func (*CachedScanner) ProjectDocsDir

func (cs *CachedScanner) ProjectDocsDir() string

ProjectDocsDir returns the project docs directory path

func (*CachedScanner) ProjectRootDir

func (cs *CachedScanner) ProjectRootDir() string

ProjectRootDir returns the project root directory path

func (*CachedScanner) Scan

func (cs *CachedScanner) Scan(ctx context.Context) ([]FileInfo, error)

Scan returns cached file list or scans filesystem if cache miss

type FileInfo

type FileInfo struct {
	Name        string   // original filename
	Filename    string   // filename with source prefix (e.g., "commands:action/commit.md")
	Normalized  string   // lowercase for matching
	Source      Source   // source type
	Path        string   // absolute path
	Size        int64    // file size in bytes
	Description string   // description from frontmatter (if present)
	Tags        []string // tags from frontmatter (if present)
}

FileInfo contains metadata about a documentation file

type Frontmatter added in v0.2.0

type Frontmatter struct {
	Description string   `yaml:"description"`
	Tags        []string `yaml:"tags"`
}

Frontmatter contains metadata extracted from YAML frontmatter

func ParseFrontmatter added in v0.2.0

func ParseFrontmatter(content []byte) (frontmatter Frontmatter, strippedContent []byte)

ParseFrontmatter extracts YAML frontmatter from markdown content. Returns frontmatter metadata and content without the frontmatter block. If no frontmatter exists or parsing fails, returns empty metadata and original content.

type Params

type Params struct {
	CommandsDir    string
	ProjectDocsDir string
	ProjectRootDir string
	MaxFileSize    int64
	ExcludeDirs    []string
}

Params contains parameters for creating a scanner

type Scanner

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

Scanner discovers and indexes documentation files from multiple sources

func NewScanner

func NewScanner(params Params) *Scanner

NewScanner creates a new scanner instance

func (*Scanner) Close

func (s *Scanner) Close() error

Close is a no-op for Scanner but required to implement Interface

func (*Scanner) CommandsDir

func (s *Scanner) CommandsDir() string

CommandsDir returns the commands directory path

func (*Scanner) ProjectDocsDir

func (s *Scanner) ProjectDocsDir() string

ProjectDocsDir returns the project docs directory path

func (*Scanner) ProjectRootDir

func (s *Scanner) ProjectRootDir() string

ProjectRootDir returns the project root directory path

func (*Scanner) Scan

func (s *Scanner) Scan(ctx context.Context) ([]FileInfo, error)

Scan discovers all markdown files from all configured sources

type Source

type Source string

Source represents documentation source type

const (
	// SourceCommands represents ~/.claude/commands documentation
	SourceCommands Source = "commands"
	// SourceProjectDocs represents project docs (with configurable exclusions)
	SourceProjectDocs Source = "project-docs"
	// SourceProjectRoot represents root-level markdown files
	SourceProjectRoot Source = "project-root"
)

Jump to

Keyboard shortcuts

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