V Vant Docs

Entropy Patching Protocol

Lossless entropy scan + verbatim-segment patching for Vant v0.8.6 (the pipeline lives in lib/entropy-patch.js; this page describes what IS shipped - see Path policy before running it)

What is Entropy Patching?

Entropy Patching is a compression protocol that separates high-entropy data (unique, random-looking content) from low-entropy data (repeated, predictable patterns). It gives Vant a lossless, tamper-evident patch format (.vpatch).

Why Does It Exist?

LLMs are token-limited. Loading 60+ brain files on startup is expensive. Entropy Patching enables:

  1. Tamper-evident lossless restore - decompress() refuses any envelope whose seed no longer hashes its restored bytes
  2. Git-native diffs - Segments are stored verbatim, so the diff story stays whole
  3. Selective inspection - Read the scan stats without hydrating

Path policy (read this first)

Input and output paths go through the VAF path gate (lib/vaf.js checkPathTraversal): operate inside the repository tree. Paths typed as system locations (/tmp/, /home/, /etc/, /var/, /bin/, /opt/, /boot/, /dev/, /sys/, /proc/, /snap/, /lib*), Windows drive letters, ~/$HOME expansions, encoded traversal (%2e%2e, double-encoding), or anything containing .. are blocked with SECURITY_PATH_TRAVERSAL.

In practice this means the file 19-mind-fusion compression examples below run on files under models/, docs/, or the repo root - not on /tmp scratch files. Use a project-local working directory if you need scratch space.

This gate is deliberate and shared with every other CLI input path; do not file it as a bug.

How It Works

1. Windowed Entropy Scan

The algorithm scans data with a sliding window (default 8 bytes), calculating Shannon entropy for each position:

Input: "aaaaaaaaXYaabcdefg..."
         ↓ entropy scan
Output: [stable][spike][stable][spike]...

Shannon Entropy Formula:

H = -Σ P(x) log₂ P(x)  (normalized 0-1)

2. Stable vs Spike

Type Description Example
stable Low entropy, repetitive aaaaaaaa, 00000000
spike High entropy, unique binary data, encrypted content

3. Latent Seed

The seed is a STATUS ANCHOR: we sha256 the original source file to create:

"latentSeed": "93f2e8bbb696dddb..."  // = lib/hash.sha256(original bytes)

This enables lightweight “what changed” queries without full hydration.

Use Cases

Use Case 1: Brain Compression

Compress a brain file (or a directory of them) for storage as .vpatch envelopes; restore exactly with --decompress:

# Compress one file into models/latent/
vant compress models/private/vant/goals.md -o models/latent

# Compress a directory of files
vant compress models/private/ -o models/latent

Use Case 2: Generational Evolution

When updating a chapter in your novel, only the spike that changed gets a new commit:

# Update chapter 4 (creates new spike commit, not full file)
vant compress novel/chapter4.md --output novel/latent
git commit -m "Updated chapter 4"

Use Case 3: Delta Queries

Ask lightweight questions without full hydration:

# Get stats on any file
vant compress models/private/vant/goals.md --stats

CLI Commands

Statistics

vant compress <file> --stats

# Output:
# File: goals.md
# Size: 2,547 bytes
# Overall Entropy: 0.6234
# Compression Potential: LOW

Compress

vant compress <file>              # Single file
vant compress <dir>/               # Directory
vant compress <file> -o <output>  # Custom output
vant compress <file> -w 16         # Custom window size
vant compress <file> -t 0.9       # Custom threshold

Decompress

vant compress <file.vpatch> -d     # -d / --decompress

(The older --output long spelling is accepted too; -o and --output are the same flag, as are -d and --decompress.)

API Reference

The implementation is lib/entropy-patch.js (require it directly):

const entropy = require('./lib/entropy-patch');

scan()

Windowed entropy scan (the classifier behind everything else):

const scanned = entropy.scan(buffer, { windowSize: 8, threshold: 0.85 });
// scanned.chunks: [{ offset, length, entropy: H(n), kind: 'stable'|'spike' }...]
// scanned.stats: { min, max, mean, overall, stableCount, spikeCount,
//                  totalPatches, byteCount, windowSize, threshold }

getEntropyStats()

const stats = entropy.getEntropyStats(buffer, opts);
// { byteCount, overall, min, max, mean, stableCount, spikeCount,
//   totalPatches, windowSize, threshold }

compress() and decompress()

Lossless: segments store the ORIGINAL bytes verbatim (base64 in the envelope); decompress() concatenates them back and verifies the seed.

const result = entropy.compress(bufferOrPath, outputDir, { windowSize, threshold });
// { path: '<out>/<name>.vpatch', latentSeed: <sha256 of ORIGINAL>, metadata }

const back = entropy.decompress(vpatchPath, outputPath);
// { path, byteCount } - original byte length restored exactly

Tamper-EVIDENCE: the latent seed is lib/hash.sha256 of the original content. decompress() recomputes it over the restored bytes and REFUSES on mismatch - a mutated .vpatch fails loudly, never restores silently.

shannonEntropy()

entropy.shannonEntropy(buffer); // H(bytes), normalized 0-1

Configuration

Defaults

Parameter Default Range Description
windowSize 8 1-1024 Bytes per sliding window
threshold 0.85 0-1 Entropy cutoff (H below = stable)

Adaptive Mode

Self-calibrating threshold from the data itself:

const patch = entropy.createAdaptivePatch(buffer, { sensitivity: 1.5, windowSize: 8 });
// pass 1: mean/stddev of chunk entropies; threshold = mu + k*sigma
// patch.stats: { threshold, mu, sd, windowSize, sensitivity }
// patch.metadata: spike/stable counts at the calibrated threshold

Algorithm: threshold = μ + k × σ (rolling mean + k × standard deviation)

Option Default Range Description
sensitivity 1.5 0.1-10 k-factor for threshold (lower = more spikes)
windowSize 64 1-1024 Bytes per sliding window
historyLimit 1000 10-10000 Max entropy history to track

CLI Usage:

vant compress file.md --adaptive         # auto threshold
vant compress file.md -a -k 2.0         # custom sensitivity
vant compress file.md --stats           # view entropy stats first

Tuning

File Format

.vpatch Structure (real envelope, lib/entropy-patch.js)

{
  "version": 1,
  "format": "vpatch",
  "source": "identity.md",
  "createdAt": "2026-10-12T00:00:00.000Z",
  "params": { "windowSize": 8, "threshold": 0.85 },
  "latentSeed": "<sha256 of the ORIGINAL bytes>",
  "metadata": {
    "byteCount": 1714, "windowSize": 8, "threshold": 0.85,
    "min": 0.125, "max": 0.375, "mean": 0.3367, "overall": 0.3367,
    "stableCount": 215, "spikeCount": 0, "totalPatches": 215
  },
  "segments": [
    { "kind": "stable", "offset": 0, "length": 8, "entropyMax": 0.125 }
  ],
  "segmentsData": ["<base64 of the EXACT original bytes, per segment>"]
}

Lossless by construction: the concatenation of segmentsData (in segments offset order) IS the original file. decompress() restores it exactly and verifies the latent seed.

Security


Generational Optimization Guide

Tips for tuning Entropy Patching in production autonomous sessions.

1. The Sensitivity Sweet Spot

The k factor (sensitivity) controls threshold = μ + k×σ:

k Value Behavior Use Case
0.5-1.0 Lower threshold, more spikes Token-limited agents
1.5 Default (balanced) General use
2.0+ Higher threshold, less pruning Agents feel “forgetful”

Tuning tips:

Run a quick calibration on first autonomous session:

const patch = entropy.createAdaptivePatch(sample, { sensitivity: 1.5 });
console.log('Auto-calibrated threshold:', patch.stats.threshold);

Recommended: Add to vant start sequence for auto k-detection.

3. Semantic Seed (Anchoring)

The latent seed is a CONTENT anchor (sha256 of the original bytes), used for tamper evidence on restore. If you want a LLM-facing semantic anchor (“where to place” restored high-entropy data), store a summary in your brain alongside the .vpatch - the envelope is byte-discipline, not prose.

4. Generational Evolution

Track entropy drift across sessions by comparing the overall stat of two .vpatch files for the same source:

const a = entropy.getEntropyStats(oldContent);
const b = entropy.getEntropyStats(newContent);
// |b.overall - a.overall| small = stable evolution; large = review