truncate

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArrayReduction

type ArrayReduction struct {
	Path        string `json:"path"`
	OriginalLen int    `json:"original_len"`
	NewLen      int    `json:"new_len"`
	Removed     int    `json:"removed"`
}

ArrayReduction records a single array halving: its path, original length, new (kept) length, and the number of removed elements.

type Config

type Config struct {
	TokenBudget int
	Enabled     bool
}

Config holds token-budget truncation settings.

func ConfigFromEnv

func ConfigFromEnv() Config

ConfigFromEnv reads CLOCKIFY_TOKEN_BUDGET from the environment. Default is 8000. Setting it to 0 disables truncation.

func (Config) Truncate

func (c Config) Truncate(v any) (any, bool)

Truncate applies progressive truncation stages to keep the token estimate within the configured budget. It returns the (possibly modified) value and a boolean indicating whether any truncation occurred.

type TruncationReport

type TruncationReport struct {
	ArrayReductions []ArrayReduction `json:"array_reductions,omitempty"`
}

TruncationReport captures side-channel metadata about reductions applied during truncation. It is populated by reduceArrays and surfaced via the _truncation field in the resulting map, keeping arrays homogeneous.

Jump to

Keyboard shortcuts

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