compact

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 26, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package compact provides compaction strategies, types, and helpers for context-window management. See ../REFACTOR_PLAN.md.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func APICompactMessages

func APICompactMessages(msgs []types.EyrieMessage, cfg APICompactConfig) []types.EyrieMessage

func AdjustIndexToPreserveAPIInvariants

func AdjustIndexToPreserveAPIInvariants(msgs []types.EyrieMessage, startIdx int) int

func BuildCompactPrompt

func BuildCompactPrompt(variant CompactVariant) string

func BuildPrompt

func BuildPrompt(variant Variant) string

BuildPrompt renders the compaction prompt template for the given variant.

func CalculateMessagesToKeepIndex

func CalculateMessagesToKeepIndex(msgs []types.EyrieMessage, cfg SessionMemoryConfig) int

func CountClearableToolResults

func CountClearableToolResults(msgs []types.EyrieMessage) int

func FilterCompactBoundaries

func FilterCompactBoundaries(msgs []types.EyrieMessage) []types.EyrieMessage

func FormatCompactSummary

func FormatCompactSummary(raw string) string

func FormatSummary

func FormatSummary(raw string) string

FormatSummary normalises a raw LLM summary for display.

func HasTextContent

func HasTextContent(m types.EyrieMessage) bool

func HasTimeGap

func HasTimeGap(msgs []types.EyrieMessage, threshold time.Duration) bool

func IsCompactBoundary

func IsCompactBoundary(m types.EyrieMessage) bool

func IsCompactableTool

func IsCompactableTool(name string) bool

func MicrocompactMessages

func MicrocompactMessages(msgs []types.EyrieMessage, cfg MicroCompactConfig) []types.EyrieMessage

func ReadSessionMemory

func ReadSessionMemory(sessionID string) (string, error)

func SessionMemoryPath

func SessionMemoryPath(sessionID string) string

func ToolNameForResult

func ToolNameForResult(m types.EyrieMessage, msgs []types.EyrieMessage) string

Types

type APICompactConfig

type APICompactConfig struct {
	TriggerTokens    int
	KeepTargetTokens int
	ClearToolInputs  bool
	ClearThinking    bool
	PreserveMutating bool
}

func DefaultAPICompactConfig

func DefaultAPICompactConfig() APICompactConfig

func DefaultAPIConfig

func DefaultAPIConfig() APICompactConfig

DefaultAPIConfig returns the default API-boundary compactor config.

type CompactConfig

type CompactConfig struct {
	AutoEnabled       bool
	ContextWindowSize int
	AutoCompactBuffer int
	MaxOutputTokens   int
	MaxFailures       int
}

func DefaultCompactConfig

func DefaultCompactConfig() CompactConfig

type CompactResult

type CompactResult struct {
	Messages     []types.EyrieMessage
	Summary      string
	TokensBefore int
	TokensAfter  int
	Strategy     string
}

type CompactVariant

type CompactVariant int
const (
	CompactBase CompactVariant = iota
	CompactPartial
	CompactUpTo
)

type CompactionTrigger

type CompactionTrigger struct {
	Threshold   float64
	WindowSize  int
	LastCompact time.Time
	MinInterval time.Duration
}

func NewCompactionTrigger

func NewCompactionTrigger(windowSize int) *CompactionTrigger

func (*CompactionTrigger) MarkCompacted

func (ct *CompactionTrigger) MarkCompacted()

func (*CompactionTrigger) ShouldCompact

func (ct *CompactionTrigger) ShouldCompact(currentTokens int) bool

type Config

type Config = CompactConfig

Config tunes compaction behaviour.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default top-level compaction config.

type FileTracker

type FileTracker struct {
	ReadFiles     map[string]int
	ModifiedFiles map[string]int
}

func NewFileTracker

func NewFileTracker() *FileTracker

func (*FileTracker) ExtractFromMessages

func (ft *FileTracker) ExtractFromMessages(messages []types.EyrieMessage)

func (*FileTracker) FormatForSummary

func (ft *FileTracker) FormatForSummary() string

func (*FileTracker) Merge

func (ft *FileTracker) Merge(other *FileTracker)

func (*FileTracker) ParseFromSummary

func (ft *FileTracker) ParseFromSummary(summary string)

func (*FileTracker) RecordModified

func (ft *FileTracker) RecordModified(path string)

func (*FileTracker) RecordRead

func (ft *FileTracker) RecordRead(path string)

type MicroCompactConfig

type MicroCompactConfig struct {
	CompactableTools map[string]bool
	TimeGapMins      float64
	KeepRecent       int
}

func DefaultMicroCompactConfig

func DefaultMicroCompactConfig() MicroCompactConfig

func DefaultMicroConfig

func DefaultMicroConfig() MicroCompactConfig

DefaultMicroConfig returns the default micro-compactor config.

type Result

type Result = CompactResult

Result is the outcome of a compaction pass.

type SessionMemoryConfig

type SessionMemoryConfig struct {
	MinTokens            int
	MinTextBlockMessages int
	MaxTokens            int
}

func DefaultSessionMemoryConfig

func DefaultSessionMemoryConfig() SessionMemoryConfig

type Variant

type Variant = CompactVariant

Variant identifies which compaction prompt variant to render.

Jump to

Keyboard shortcuts

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