distill

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: Apache-2.0 Imports: 10 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanCarriageReturns

func CleanCarriageReturns(s string) string

CleanCarriageReturns resolves in-place line overwrites caused by terminal progress bars (\r). Standard CRLF (\r\n) is normalized to \n. Standalone \r keeps only the last segment before \n.

func ComputeFastHash

func ComputeFastHash(s string) uint64

ComputeFastHash calculates a 64-bit FNV-1a hash of a string.

func ComputeRef

func ComputeRef(s string) string

ComputeRef creates a 12-char SHA-256 ref for a string.

func DeduplicateHistoricalReads

func DeduplicateHistoricalReads(blocks []BlockRecord) ([]string, bool)

DeduplicateHistoricalReads collapses identical large blocks (>=512 bytes) repeated across turns. The FIRST occurrence is kept 100% intact; every LATER repeat becomes a backwards reference to it.

The direction is the whole point, and it is the opposite of what looks natural. Keeping the newest copy intact and rewriting the older ones reads like "the active working set stays sharp", but a conversation reaches the provider as a growing prefix: turn N's body is turn N-1's body plus new messages. Anything at a position the provider has already seen must stay byte-identical forever, or the cached prefix is invalidated from that position onward — on a re-read that is nearly the entire conversation. So the only copy that may be rewritten is one the provider has not seen yet: the newest.

Referencing the first occurrence also makes the marker itself stable. A marker that names the LATEST turn changes every turn (turn 3, then 4, then 5...), so the rewritten history never settles; the first occurrence never moves, so the marker is written once and stays.

Nothing is lost: the full bytes remain in context at the earlier position, which the model can attend to, and the marker says where.

func DistillDiff

func DistillDiff(s string) (string, bool)

DistillDiff processes git unified diffs: 1. Collapses massive lockfile and minified asset diffs into 1-line semantic summaries. 2. Compacts excessive unchanged context lines (>8 lines) in application code diffs down to 3 lines. 3. Real code modifications are preserved 100% verbatim.

func DistillJSON

func DistillJSON(s string) (string, bool)

DistillJSON applies structural pruning and tabular schema-lifting to JSON strings: 1. Drops null fields, empty arrays/objects, and envelope telemetry. 2. Lifts homogeneous arrays of objects into compact, token-efficient Markdown tables. 3. Emits dense, unindented JSON for non-tabular structures.

Determinism: identical input bytes always produce identical output bytes. Column order comes from the document, never from Go map iteration.

func FoldRepeatedLines

func FoldRepeatedLines(s string) string

FoldRepeatedLines folds consecutive identical lines repeated >3 times into a single line with count.

func IsLockfileOrGenerated

func IsLockfileOrGenerated(path string) bool

IsLockfileOrGenerated reports whether a path matches generated files, dependency lockfiles, or minified assets that pollute agent context.

func IsUnifiedDiff

func IsUnifiedDiff(s string) bool

IsUnifiedDiff reports whether text appears to be a unified git diff.

func SanitizeTerminal

func SanitizeTerminal(s string) (string, bool)

SanitizeTerminal runs the full terminal hygiene pipeline: ANSI stripping, progress overwrite resolution, and line folding.

func StripANSI

func StripANSI(s string) string

StripANSI removes ANSI escape codes (CSI, OSC) from a string. Fast path: if no ESC byte (0x1b) is found, returns the input untouched without allocations.

Types

type BlockRecord

type BlockRecord struct {
	TurnIndex int
	Content   string
	Hash      uint64
	Ref       string
}

BlockRecord tracks a large tool content block across conversation turns.

Jump to

Keyboard shortcuts

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