Skip to main content

Module compaction

Module compaction 

Source
Expand description

When to shorten something, and what to keep.

The mechanism half of this — moving a big result out of the window and leaving a reference — is offload’s and was frozen first. This is the policy half: given a piece of text, what kind of thing is it, and which end of it carries the information.

Three rules hold the whole module up.

The result is never longer than the input. Shortening that lengthens is not a corner case, it is the failure that makes a context budget meaningless, so it is an invariant with a test rather than a property people remember.

No regular expressions on this path. Detection is a handful of prefix and count checks over the first few lines; a pattern engine here would put backtracking between a model and its next turn.

Cuts land on character boundaries. A budget in bytes and a cut in the middle of a character is how a compactor produces text nothing downstream can read. The boundary rule and the marker that announces the loss both belong to elision, which every shortening path here shares.

Enums§

Content
What a piece of text is, as far as shortening is concerned. Eight, and Unknown is one of them: a compactor that had to guess would guess wrong on exactly the material nobody anticipated.
Shrink
What has to happen to one piece of text: decided here, carried out by the caller.
Strategy
Which end of a text survives a shortening.

Functions§

detect
Detection, in priority order, over the first lines only.
plan
What happens to that kind of content, at that size.
shorten
Carries out a shortening the caller has already decided on.