context

package
v0.3.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: May 16, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package context provides context window management for AI agents

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EstimateTokens

func EstimateTokens(content string) int

EstimateTokens estimates the number of tokens in content Rough estimate: ~4 characters per token for English text

func GetRelativePath

func GetRelativePath(base, target string) string

GetRelativePath returns a relative path from base to target

Types

type ContentInfo

type ContentInfo struct {
	Type      ContentType
	Path      string // File path or description
	Content   string
	Size      int64 // Size in bytes
	Threshold int64 // Size threshold in bytes
}

ContentInfo holds information about content that may be too large

func (*ContentInfo) ShouldUseReference

func (c *ContentInfo) ShouldUseReference() bool

ShouldUseReference returns true if content exceeds its threshold

type ContentThresholds

type ContentThresholds struct {
	MaxDescriptionSize project.ByteSize // Default: 250MB
	MaxDiffSize        project.ByteSize // Default: 250MB
	MaxFileSize        project.ByteSize // Default: 1MB
}

ContentThresholds defines size limits for different content types

func DefaultThresholds

func DefaultThresholds() *ContentThresholds

DefaultThresholds returns the default content size thresholds

func ThresholdsFromConfig

func ThresholdsFromConfig(cfg *project.Config) *ContentThresholds

ThresholdsFromConfig creates thresholds from project configuration

type ContentType

type ContentType string

ContentType represents the type of content being managed

const (
	ContentTypeDescription ContentType = "description"
	ContentTypeDiff        ContentType = "diff"
	ContentTypeFile        ContentType = "file"
)

type Manager

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

Manager handles context window management

func NewManager

func NewManager() *Manager

NewManager creates a new context manager with default thresholds

func NewManagerWithConfig

func NewManagerWithConfig(cfg *project.Config) *Manager

NewManagerWithConfig creates a new context manager with configuration thresholds

func NewManagerWithThresholds

func NewManagerWithThresholds(thresholds *ContentThresholds) *Manager

NewManagerWithThresholds creates a new context manager with custom thresholds

func (*Manager) CombineContext

func (m *Manager) CombineContext(pieces []string, maxTotalBytes int64) string

CombineContext intelligently combines multiple content pieces with size awareness

func (*Manager) ContentTooLarge

func (m *Manager) ContentTooLarge(contentType ContentType, content string) bool

ContentTooLarge returns true if content exceeds its threshold

func (*Manager) GetThresholds

func (m *Manager) GetThresholds() *ContentThresholds

GetThresholds returns the current thresholds

func (*Manager) ManageContent

func (m *Manager) ManageContent(contentType ContentType, path, content string) string

ManageContent checks if content exceeds thresholds and returns either the content or a reference to it

func (*Manager) ManageDescription

func (m *Manager) ManageDescription(description string) string

ManageDescription manages task description content

func (*Manager) ManageDiff

func (m *Manager) ManageDiff(diff string) string

ManageDiff manages git diff content

func (*Manager) ManageFile

func (m *Manager) ManageFile(filePath, content string) string

ManageFile manages file content

func (*Manager) TruncateContent

func (m *Manager) TruncateContent(content string, maxBytes int) string

TruncateContent truncates content to fit within a size limit This is used as a fallback when references aren't appropriate

Jump to

Keyboard shortcuts

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