Documentation
¶
Index ¶
- func CleanCarriageReturns(s string) string
- func ComputeFastHash(s string) uint64
- func ComputeRef(s string) string
- func DeduplicateHistoricalReads(blocks []BlockRecord) ([]string, bool)
- func DistillDiff(s string) (string, bool)
- func DistillJSON(s string) (string, bool)
- func FoldRepeatedLines(s string) string
- func IsLockfileOrGenerated(path string) bool
- func IsUnifiedDiff(s string) bool
- func SanitizeTerminal(s string) (string, bool)
- func StripANSI(s string) string
- type BlockRecord
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CleanCarriageReturns ¶
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 ¶
ComputeFastHash calculates a 64-bit FNV-1a hash of a string.
func ComputeRef ¶
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 ¶
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 ¶
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 ¶
FoldRepeatedLines folds consecutive identical lines repeated >3 times into a single line with count.
func IsLockfileOrGenerated ¶
IsLockfileOrGenerated reports whether a path matches generated files, dependency lockfiles, or minified assets that pollute agent context.
func IsUnifiedDiff ¶
IsUnifiedDiff reports whether text appears to be a unified git diff.
func SanitizeTerminal ¶
SanitizeTerminal runs the full terminal hygiene pipeline: ANSI stripping, progress overwrite resolution, and line folding.