truncate

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: MIT Imports: 6 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
	FailClosedOnError bool
}

Config holds token-budget truncation settings.

func ConfigFromEnv

func ConfigFromEnv(hosted ...bool) Config

ConfigFromEnv reads CLOCKIFY_TOKEN_BUDGET from the environment. Default is 8000. Setting it to 0 disables truncation. Hosted profiles force fail-closed truncation errors; non-hosted profiles can opt into the same behavior with CLOCKIFY_TRUNCATION_FAIL_CLOSED=1.

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