compact

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 8 Imported by: 0 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 compact owns bounded structured handoffs, never canonical history. Adapted from Goose 14741e9a (Apache-2.0); see ../model/LICENSE.goose.

Index

Constants

View Source
const Request = "Please summarize the conversation history provided in the system prompt."

Variables

This section is empty.

Functions

func Cap

func Cap(contextLimit, outputLimit uint64) uint64

Cap bounds the rendered handoff to half the actual summary output budget. Normal windows target 2% of context, between 4,000 and 12,000 tokens; smaller windows and model output limits can reduce that target.

func Output

func Output(contextLimit uint64) uint64

Output is the output limit a summary request asks for in a context window: twice the handoff's cap, since the JSON document is larger than the text rendered from it. Small windows reserve at most a quarter for output so the transcript has room. The model's own output limit also bounds it.

func Pending

func Pending(records []canonical.Record) []canonical.Record

Pending includes empty messages because source token accounting reserves their role wrappers even though summary transcripts discard empty content.

func Prepare

func Prepare(records []canonical.Record, contextLimit, outputLimit uint64, request ...string) (string, error)

func Visible

func Visible(records []canonical.Record) []canonical.Record

Visible projects summary membership and audiences without changing canonical records. The latest summary precedes the history after its captured boundary.

Types

type File

type File struct {
	Path    string  `json:"path"`
	Summary string  `json:"summary"`
	KeyCode *string `json:"key_code"`
}

type Selection

type Selection struct {
	Prefix   []canonical.Record
	Tail     []canonical.Record
	Boundary canonical.Record
}

Selection replaces Prefix through Boundary and leaves Tail in canonical history. Prefix retains the prior compaction record so Prepare can pin it.

func Select

func Select(records []canonical.Record, contextLimit uint64, keepRecent bool) (Selection, bool)

Select keeps recent complete turns within a soft budget of 20% of context, capped at 20,000 tokens. A long turn can split only between complete tool exchanges. The newest exchange stays whole even when it exceeds the budget. keepRecent=false selects all visible history; the caller preserves any unprocessed user input when using that fallback.

type Summary

type Summary struct {
	UserIntent        []string `json:"user_intent"`
	TechnicalConcepts []string `json:"technical_concepts"`
	Files             []File   `json:"files"`
	ErrorsAndFixes    []string `json:"errors_and_fixes"`
	ProblemSolving    []string `json:"problem_solving"`
	UserMessages      []string `json:"user_messages"`
	PendingTasks      []string `json:"pending_tasks"`
	CurrentWork       *string  `json:"current_work"`
	NextStep          *string  `json:"next_step"`
}

func Parse

func Parse(text string, limit uint64) (Summary, error)

Parse reads the handoff of a summary response and bounds its rendered text to limit tokens.

func (*Summary) Bound

func (s *Summary) Bound(limit uint64)

Bound cuts the least essential sections toward limit, retaining the last essential fields. Parse rejects a handoff that still cannot fit.

func (Summary) Render

func (s Summary) Render() string

Jump to

Keyboard shortcuts

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