Documentation
¶
Index ¶
- func CanDistillJSON(trimmed string) bool
- 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 FindLiftableArray(raw 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 CanDistillJSON ¶ added in v0.4.0
CanDistillJSON reports whether DistillJSON could change s at all. It answers with raw-byte scans only, so a caller can decide before paying for json.Unmarshal. Cheap test first: the array search is a structural skip-scan, while the prunable-feature scan reads every byte.
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 FindLiftableArray ¶ added in v0.4.0
FindLiftableArray locates the array a Markdown table could be lifted from, without unmarshalling anything: gjson walks raw bytes and skips over values it was not asked about, so the cost tracks the document's shape rather than its field count.
It returns the key path to the array, deepest key last; an empty path with ok means the document root is itself the array. Depth stops at 2 because the path becomes a label in the table headline, and a deeper one stops being a useful label.
Two conditions have to hold. The array must look like a table — three or more elements, the first an object; verifying that every element really is a homogeneous object stays tryTabularLifting's job, so this test is deliberately the looser superset. And the lift must be lossless: see liftIsLossless.
v0.3.0 searched four hard-coded wrapper names (items, data, results, records) and gave up on anything else, so a provider that named its list rows or files paid the full parse and got nothing back. The search is structural now; the old names still lift, and TestWrapperNamesStillLift holds that line.
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.