Skip to content

Flow

The flow axis

The trend of a per-token signal: its windowed slope, its direction, how long it has held that direction, and where it reverses. The signal is the magnitude by default, the stress depth or the token length on request, or any per-token value a caller computes.

Source: src/flow.rs.

The readings

ReadingMeaning
slopethe average per-step change over the trailing window
direction+1 rising, 0 steady, -1 falling, with a steady band around zero
momentumconsecutive tokens holding the same non-steady direction
EventMeaning
reversalthe trend flips between rising and falling; steady does not count
Signal--overSource
Magnitudemagnitudethe magnitude of each token
StressDepthstressthe stress depth of each token
Lengthlengtheach token’s byte length

analyze_signal(tokens, signal, cfg) takes any precomputed per-token f32.

Reading the axis

$ trex flow --text '1 10 100 1000 50 5'
trex flow (over magnitude): 18 bytes, 6 tokens, 1 reversal(s)
  peak momentum: 4 (rising)

--over magnitude|stress|length picks the signal, --field prints the per-token slope, direction and momentum, and --reversals the turning points. In PowerShell -Signal picks the signal and -Detail adds a frame at every token.

Data model

FlowFrame, one token’s reading:

FieldTypeMeaning
slopef32windowed rate of change
directioni8-1, 0 or +1
momentumu16consecutive same-direction tokens

FlowField, keyed by byte offset:

FieldTypeMeaning
n_tokensusizetoken count
spansVec<(usize, usize)>byte span per token
framesVec<FlowFrame>one per token
reversalsVec<usize>turning-point byte offsets

Query API: slope_at(byte), direction_at(byte).

Algorithm

Per token: slope = (signal[i] - signal[i - window]) / window, the average trend over the trailing window; direction thresholds the slope against a steady band; momentum is the run length of the same non-steady direction; a reversal is recorded where the direction flips between +1 and -1. One pass, O(1) per token; the signal costs one pass of the axis it comes from.