compaction

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package compaction prepares and summarizes old coding-session context. It is deliberately independent of the coding Session so it can be tested with a fake summarizer and reused by future product adapters.

Index

Constants

This section is empty.

Variables

View Source
var ErrNothingToCompact = errors.New("coding: not enough history to compact")

Functions

func EstimateEntries

func EstimateEntries(entries []transcript.Entry) int64

func EstimateMessage

func EstimateMessage(message agent.AgentMessage) int64

EstimateMessage uses a conservative character heuristic. Provider usage is more accurate for thresholding later, but this is stable enough for choosing a complete-turn cut point.

func EstimateMessages

func EstimateMessages(messages []agent.AgentMessage) int64

Types

type Compactor

type Compactor interface {
	Compact(ctx context.Context, request Request) (Response, error)
}

Compactor performs one tool-free summary request.

type LLM

type LLM struct {
	StreamFn      agent.StreamFn
	StreamOptions llm.StreamOptions
	GetAPIKey     func(provider string) string
}

LLM performs a single model request with no tools and thinking disabled.

func (LLM) Compact

func (c LLM) Compact(ctx context.Context, request Request) (Response, error)

type Prepared

type Prepared struct {
	Messages        []agent.AgentMessage
	PreviousSummary string
	FirstKeptID     string
	TokensBefore    int64
	KeptTokens      int64
}

func Prepare

func Prepare(entries []transcript.Entry, keepRecentTokens int64) (Prepared, error)

Prepare selects complete, oldest user turns for summarization. The retained suffix always begins with a user message, so tool calls and results cannot be separated from the turn that owns them.

type Request

type Request struct {
	Model           llm.Model
	Messages        []agent.AgentMessage
	PreviousSummary string
	Instructions    string
}

type Response

type Response struct {
	Summary       string
	Usage         llm.Usage
	Provider      string
	Model         string
	ResponseModel string
	ResponseID    string
	Timestamp     time.Time
}

Jump to

Keyboard shortcuts

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