boundctx

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 9 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 boundctx keeps an agent prompt under a model's context window.

A ticket log, a command's output or a diff can be megabytes; one such prompt was rejected as "~1241087 tokens (limit 1000000)". A Set bounds each input: one that fits is passed through untouched, one that does not is written in full to a file and replaced by a head and tail excerpt, the path, and a line saying the agent may read the file.

Index

Constants

View Source
const (
	// DefaultPerInput bounds one log entry or output in the prompt.
	DefaultPerInput = 24 << 10
	// DefaultTotal bounds all log entries together. The diff is bounded
	// separately by its own limit.
	DefaultTotal = 128 << 10
	// DefaultDiffLimit bounds a diff in the prompt unless the caller says more.
	DefaultDiffLimit = 100 << 10
	// MaxRolePrompt is the ceiling on the instruction part of a prompt.
	MaxRolePrompt = 64 << 10
)

Variables

This section is empty.

Functions

func DiffSummary

func DiffSummary(diff string) string

DiffSummary lists the files, line counts and largest files of a unified diff, marking generated and fixture files.

func Excerpt

func Excerpt(text string, max int) string

Excerpt returns text unchanged when it fits max bytes, and otherwise its first and last halves around a marker saying how much was left out. Cuts move to the nearest rune start, so a multi-byte character is dropped whole rather than split; bytes that were never valid UTF-8 are left alone.

Types

type Item

type Item struct{ Name, Text string }

Item is one named input of a sequence.

type Set

type Set struct {
	// Dir is where full inputs go. Files are named by content, so building the
	// same prompt again reuses them. Empty means do not write files.
	Dir      string
	PerInput int
	Total    int
	// Unreadable means the agent has no tools: files are saved for the operator
	// and the prompt does not point the agent at them.
	Unreadable bool
	// contains filtered or unexported fields
}

Set bounds the inputs of one prompt. The zero value uses the defaults and writes no files, so an overflow leaves only the excerpt.

func (*Set) Bound

func (s *Set) Bound(name, text string) string

Bound returns text when it fits the per-input limit and the remaining total. Otherwise it saves text under name and returns an excerpt with a pointer, or only the pointer when little room is left.

func (*Set) BoundDiff

func (s *Set) BoundDiff(name, diff string, limit int) string

BoundDiff returns diff when it is at most limit bytes. A larger diff becomes a per-file summary, an excerpt, a statement of what was not seen, and the path of the full diff.

func (*Set) BoundSeq

func (s *Set) BoundSeq(items []Item) []string

BoundSeq bounds items, oldest first, spending the budget on the newest. When the budget runs out the older items are replaced by a single note at the front, with their full text in one file; the result then has one more element than the kept items. The total stays within the Set's Total plus that one note.

Jump to

Keyboard shortcuts

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