refs

package
v0.0.26 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package refs implements context reference expansion for the TUI. It parses @ref syntax and expands file, folder, git, and web references into inline content that can be shown in chat messages.

Index

Constants

View Source
const (
	// MaxLinesPerRef is the maximum number of lines for a single reference.
	MaxLinesPerRef = 500

	// MaxFolderEntries is the maximum number of entries in a folder listing.
	MaxFolderEntries = 200
)

Constants for truncation limits.

Variables

This section is empty.

Functions

func Truncate

func Truncate(content string, maxLines int) (string, bool)

Truncate truncates content to maxLines lines.

Types

type DirEntry

type DirEntry struct {
	Name  string
	IsDir bool
	Size  int64
	Mode  string
}

DirEntry represents a directory entry with metadata.

type Expander

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

Expander processes context references in user input.

func NewExpander

func NewExpander(workDir string) *Expander

NewExpander creates a new Expander with the given work directory.

func (*Expander) Expand

func (e *Expander) Expand(input string) (*ExpansionResult, error)

Expand parses references in input and expands them to their content. Returns the expanded message and any warnings.

type ExpansionResult

type ExpansionResult struct {
	// Original is the original input message.
	Original string

	// Expanded is the message with reference content appended.
	Expanded string

	// RefsFound is the list of references found.
	RefsFound []ParsedRef

	// RefsExpanded maps reference raw values to their expanded content.
	RefsExpanded map[string]string

	// Warnings contains warning messages for invalid refs.
	Warnings []string

	// Truncated indicates which refs were truncated.
	Truncated []string
}

ExpansionResult contains the result of expanding references.

type LineRange

type LineRange struct {
	Start int
	End   int
}

LineRange represents a line range for file references.

type ParsedRef

type ParsedRef struct {
	Type      RefType
	RawValue  string     // Original @ref string including the type prefix
	Value     string     // Parsed value (path, URL, etc.)
	LineRange *LineRange // For @file:path:start-end
}

ParsedRef represents a parsed @ref reference.

type RefType

type RefType string

RefType represents the type of context reference.

const (
	RefFile   RefType = "file"
	RefFolder RefType = "folder"
	RefDiff   RefType = "diff"
	RefStaged RefType = "staged"
	RefGit    RefType = "git"
	RefURL    RefType = "url"
)

type Validator

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

Validator enforces security policies on references.

func NewValidator

func NewValidator(workDir string) *Validator

NewValidator creates a new Validator with default security policies.

func (*Validator) IsBinaryFile

func (v *Validator) IsBinaryFile(data []byte) bool

IsBinaryFile checks if a file is binary by examining its content.

func (*Validator) IsBinaryPath

func (v *Validator) IsBinaryPath(path string) bool

IsBinaryPath checks if a file path points to a known binary file type.

func (*Validator) ValidateFile

func (v *Validator) ValidateFile(path string) error

ValidateFile validates a file reference for security and accessibility.

func (*Validator) ValidateFolder

func (v *Validator) ValidateFolder(path string) error

ValidateFolder validates a folder reference for security and accessibility.

func (*Validator) ValidatePath

func (v *Validator) ValidatePath(path string) error

ValidatePath checks if a path is safe to access. Returns an error with a warning message if the path is blocked.

Jump to

Keyboard shortcuts

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