summarize

package
v2.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 18 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package summarize provides pure eligible-evidence rendering, deterministic summary chunk planning and ordered validation. It does not load or store content.

Index

Constants

View Source
const MaxSummaryChunks = 8

MaxSummaryChunks bounds sequential summariser calls per compaction.

Variables

This section is empty.

Functions

func AnnotateReceipts

func AnnotateReceipts(lines []index.ReceiptLine, plan Plan) ([]index.ReceiptLine, error)

AnnotateReceipts copies K12's lines and attaches exact inclusive byte ranges and non-text annotations. It never mutates previous immutable receipts.

func RenderChunk

func RenderChunk(prompt, previous string, chunk Chunk) *model.Request

RenderChunk frames every evidence line as quoted data. The rendered running summary is bounded at the table rate to OutputTokens, including quote prefixes. Prompt must be the same rendered prompt supplied to PlanChunks.

Types

type ByteRange

type ByteRange struct {
	MessageID  index.MessageID
	Part       int
	ToolUseID  string
	Start, End int
	// IsResult binds ranges to original result bytes rather than call arguments.
	IsResult bool
}

ByteRange is a half-open byte interval in a Unit's full eligible Text. ToolUseID binds result ranges to the call's receipt; Part identifies other text.

type Chunk

type Chunk struct {
	Pieces       []Piece
	OutputTokens int
}

Chunk holds the new evidence and output cap for one sequential folding call.

type ChunkOptions

type ChunkOptions struct {
	// MaxSummaryChunks and MaxSummarisedResultTokens override the default rules.
	MaxSummaryChunks          int
	MaxSummarisedResultTokens int
	Limits                    model.ContextLimits
	MaxSummaryTokens          int
	Prompt                    string
	// PromptFor measures a resolved custom template using the same quoted data as the actual call.
	PromptFor func(previous string, chunk Chunk) (string, error)
}

ChunkOptions uses recorded summariser limits and the agent's summary cap.

type Evidence

type Evidence struct {
	Previous    string
	Units       []Unit
	Annotations []PartAnnotation
}

Evidence keeps full eligible input, independent of planner caps or view omissions.

func RenderInput

func RenderInput(in Input) (Evidence, error)

RenderInput projects full eligible canonical evidence without view omissions. Contents must come from the authorized access layer: Record, Output and injected call fields are never selected. Hidden declarations are scanned beyond the cut.

type Input

type Input struct {
	Entries                         []index.MessageEntry
	Contents                        map[runstore.Hash][]byte
	From, To                        index.MessageID
	CurrentPos, SummaryPos          int
	Previous                        string
	AcceptsImages, AcceptsDocuments bool
	RecallNames                     []string
}

Input supplies authorized canonical contents and entries. Entries include bookkeeping declarations after the cut; only [From, To) is summarized.

type PartAnnotation

type PartAnnotation struct {
	MessageID               index.MessageID
	Part                    int
	ToolUseID, Kind, Format string
	Bytes                   int
}

PartAnnotation identifies a non-text part excluded from summary requests.

func (PartAnnotation) String

func (p PartAnnotation) String() string

String is the receipt annotation required for an unsupported part.

type Piece

type Piece struct {
	Unit       Unit
	Start, End int
}

Piece selects one rune-aligned interval or an indivisible attachment.

type Plan

type Plan struct {
	Budget, OutputTokens int
	Chunks               []Chunk
	Unsummarised         []ByteRange
	Annotations          []PartAnnotation
}

Plan carries call inputs and annotations for integration into K12 receipts.

func PlanChunks

func PlanChunks(evidence Evidence, options ChunkOptions) (Plan, error)

PlanChunks uses only recorded limits, the uncalibrated 1/3 table rate, and integer arithmetic. Every request reserves a full running summary plus 10% of the input budget. Result caps apply to raw eligible bytes, not quoted framing. Out <= (window-Out)/4 uses floor(window/5); when window mod 5 is 4 this is conservatively one token below floor(Bs/4), which has no exact integer solution.

type Rejection

type Rejection struct{ Kind string }

Rejection names the first contract failure; infrastructure errors stay errors.

func (*Rejection) Error

func (r *Rejection) Error() string

Error implements error.

type Unit

type Unit struct {
	MessageID              index.MessageID
	Part                   int
	ToolUseID, Label, Text string
	Attachment             model.Part
	IsResult               bool
}

Unit is one labelled eligible part. Result Text is exact stored JSON, so byte ranges address the original result without a decoding/re-encoding step.

type Validation

type Validation struct {
	CitedUsers []checkpoint.UserLine
	LooseRefs  int
}

Validation returns canonical record-authored cited lines in citation order.

func Validate

func Validate(in ValidationInput) (Validation, error)

Validate checks first-failure order before a checkpoint can be stored. Size estimation and citation-resolution infrastructure errors are returned intact. Earlier-run citations delegate to the recorded continuation resolver.

type ValidationInput

type ValidationInput struct {
	Text, StopReason             string
	Unfinished, DefaultPrompt    bool
	SummaryBytes, ReplacedTokens int
	RenderedCheckpoint           func(string) (int, error)
	CurrentPos                   int
	To                           index.MessageID
	Resolver                     checkpoint.CitationResolver
	RecallNames                  []string
}

ValidationInput supplies the current exact summary-section byte allowance, the old checkpoint plus evicted VIEW estimate, and the new rendered checkpoint estimate (including reselected pins). Estimates use the same K12 units.

Jump to

Keyboard shortcuts

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