contextread

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyMode

func ApplyMode(filePath, content string, opts Options) (string, error)

ApplyMode applies the selected read mode before line or token budgeting.

func Build

func Build(filePath, content string, opts Options) (string, int, int, error)

Build renders content according to the requested read behavior.

func CacheStats

func CacheStats() cache.LRUStats

CacheStats returns smart-read render cache statistics.

func DefaultStorePath

func DefaultStorePath() string

DefaultStorePath returns the persisted smart-read snapshot file path.

func DetectAutoMode

func DetectAutoMode(filePath, content string, startLine, endLine int) filter.ReadMode

DetectAutoMode picks a reasonable default context mode for the file contents.

func ResolveMode

func ResolveMode(mode, filePath, content string, startLine, endLine int) (filter.ReadMode, error)

ResolveMode translates user input into a read mode.

func TrackedCommandKinds

func TrackedCommandKinds() []string

TrackedCommandKinds returns the supported smart-read categories.

func TrackedCommandPatterns

func TrackedCommandPatterns() []string

TrackedCommandPatterns returns the command patterns used to summarize smart context-read activity in tracking views.

func TrackedCommandPatternsForKind

func TrackedCommandPatternsForKind(kind string) []string

TrackedCommandPatternsForKind returns command patterns for one smart-read kind.

Types

type Bundle

type Bundle struct {
	TargetFile     string
	RelatedFiles   []string
	Content        string
	OriginalTokens int
	FinalTokens    int
}

Bundle captures a graph-aware context bundle.

func BuildBundle

func BuildBundle(filePath, content string, opts Options) (Bundle, error)

BuildBundle returns a graph-aware bundle for the target file.

type Metadata

type Metadata struct {
	Kind          string
	RequestedMode string
	ResolvedMode  string
	Target        string
	RelatedFiles  int
	Bundle        bool
}

Metadata describes how smart-read content was produced.

func Describe

func Describe(kind, filePath, content string, opts Options) Metadata

Describe returns normalized smart-read metadata for tracking and analytics.

type Options

type Options struct {
	Level        string
	Mode         string
	MaxLines     int
	MaxTokens    int
	LineNumbers  bool
	StartLine    int
	EndLine      int
	SaveSnapshot bool
	RelatedFiles int
}

Options control smart read rendering for files and MCP clients.

type RenderEntry

type RenderEntry struct {
	Key            string    `json:"key"`
	Output         string    `json:"output"`
	OriginalTokens int       `json:"original_tokens"`
	FinalTokens    int       `json:"final_tokens"`
	UpdatedAt      time.Time `json:"updated_at"`
}

RenderEntry stores a persisted smart-read render result for reuse across process restarts.

type Snapshot

type Snapshot struct {
	Path        string    `json:"path"`
	Fingerprint string    `json:"fingerprint"`
	Content     string    `json:"content"`
	UpdatedAt   time.Time `json:"updated_at"`
}

Snapshot stores the last seen contents for a path so future reads can emit deltas.

type Store

type Store struct {
	Snapshots   map[string]Snapshot    `json:"snapshots"`
	RenderCache map[string]RenderEntry `json:"render_cache,omitempty"`
}

Store is a small persisted state file used by smart read flows.

func Load

func Load(path string) (*Store, error)

Load reads the store from disk. Missing files are treated as empty state.

func (*Store) Get

func (s *Store) Get(path string) (Snapshot, bool)

Get looks up a normalized path in the store.

func (*Store) GetRender

func (s *Store) GetRender(key string) (RenderEntry, bool)

GetRender looks up a persisted render cache entry.

func (*Store) Put

func (s *Store) Put(path, content string)

Put updates the last-seen snapshot for a path.

func (*Store) PutRender

func (s *Store) PutRender(key string, output string, originalTokens, finalTokens int)

PutRender updates the persisted render cache.

func (*Store) Save

func (s *Store) Save(path string) error

Save writes the store back to disk atomically.

Jump to

Keyboard shortcuts

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