snapkit-v2
The Architecture of Harmony — a triadic cognitive architecture for multi-agent systems based on the Free Energy Principle.
What is this?
snapkit-v2 is a constraint-geometry toolkit that implements FEP (Free Energy Principle) cognition for AI agents. Each agent operates on the Eisenstein A₂ lattice, communicates via MIDI-style temporal events, and is monitored by a Harmony Governor that measures "friction" — the degree to which an agent's internal model fails to predict its sensory inputs.
The Triadic Architecture
┌─────────────────────────────────────────┐
│ Layer 3: Executive (Agency) │
│ Wakes on friction alarm, improvises │
│ (rewrites constraints, cross-wires I/O)│
└──────────────────┬──────────────────────┘
│ tuning forks
▼
┌─────────────────────────────────────────┐
│ Layer 2: Harmony Governor │
│ Measures cognitive friction (Φ) │
│ Triggers Executive when Φ > deadband │
└──────┬───────────────────────┬──────────┘
│ MIDI ch 0 │ MIDI ch N
▼ ▼
┌──────────────┐ ┌──────────────┐
│ Layer 1 │ │ Layer 1 │
│ Sandbox │ │ Sandbox │
│ Forward │ │ Forward │
│ simulation │ │ simulation │
└──────────────┘ └──────────────┘
Install
pip install cocapn-snapkit
From source:
git clone https://github.com/SuperInstance/snapkit-v2
cd snapkit-v2
pip install -e .
For MIDI hardware support:
pip install cocapn-snapkit[midi]
Quick Start
Run the integration demo
python3 examples/harmony_demo.py
Simulates a fishing boat in calm → rough seas. Shows the full triadic architecture in action.
View the maritime token lattice
snapkit lattice
Run the harmony monitor
snapkit harmony --period 1.0 --deadband 1.5
Listen to the harmony
from snapkit.audio import harmony_demo_audio
harmony_demo_audio("/tmp/harmony.wav")
Use as a library
from snapkit.governor import HarmonyGovernor
from snapkit.sandbox import HypothesisSandbox
from snapkit.executive import ExecutiveAgent
from snapkit.midi_io import MIDIBridge
from snapkit.clever_tokens import create_maritime_lattice
# Set up the triadic architecture
gov = HarmonyGovernor()
gov.register_channel("helm", channel=0)
sandbox = HypothesisSandbox(sensor_name="heading")
sandbox.set_action_range(-1.0, 1.0, step=0.1)
executive = ExecutiveAgent(gov)
executive.register_agent("helm", channel=0)
bridge = MIDIBridge(governor=gov)
bridge.register_sensor("heading", lo=0, hi=360)
# In your main loop:
gov.tick()
phi = sandbox.evaluate(sensor_current=heading, target_sensor=target)
sandbox.observe(action_taken=best_action, sensor_before=h, sensor_after=h2)
gov.record_observation("helm", prediction=p, actual=h2)
# When something breaks:
results = executive.handle_alarms()
Physical Hardware
ESP32 + MPU6050 IMU
See firmware/esp32_mpu6050_imu/. Flash the Arduino sketch, connect to a serial port, and feed IMU data to the MIDI bridge:
import serial, json
from snapkit.midi_io import MIDIBridge
bridge = MIDIBridge(governor=gov)
ser = serial.Serial('/dev/ttyUSB0', 115200)
while True:
line = ser.readline()
data = json.loads(line)
if 'roll' in data:
bpm = bridge.feed_roll(data['roll'])
print(f"Hull tempo: {bpm:.1f} BPM")
Architecture Layers
| Module | Purpose |
|---|---|
eisenstein.py |
Geometric constraint space (A₂ lattice) |
temporal.py |
BeatGrid, T-minus-0 detection |
spectral.py |
Entropy, Hurst exponent, autocorrelation |
connectome.py |
Coupled/anti-coupled room detection |
midi.py |
FluxTensorMIDI protocol |
midi_io.py |
Bridge to physical sensors |
clever_tokens.py |
Lattice-anchored constraint tokens |
sandbox.py |
Layer 1: Forward simulation + óthismos scoring |
governor.py |
Layer 2: FEP friction monitoring |
executive.py |
Layer 3: Improvisation protocol |
fleet.py |
Multi-vessel coordination |
othismos_bridge.py |
Connects to the othismos library |
audio.py |
Synthesize MIDI bus as audio (listen to harmony) |
cli.py |
Command-line tools |
Web Dashboard
Open examples/harmony_dashboard.html in a browser for a real-time view of:
- Per-channel friction state
- Hull-derived tempo
- MIDI piano roll
- Event log
For a live deployment, serve the dashboard from a Fleet Coordinator:
docker run -p 8000:8000 snapkit-v2
JavaScript / TypeScript
The core primitives are available in TypeScript at js/snapkit.ts for browser-side use:
import { HarmonyGovernor, BeatGrid, TokenLattice } from './snapkit.js';
const gov = new HarmonyGovernor();
gov.registerChannel('helm', 0, 1.5);
gov.tick();
gov.recordObservation('helm', 180.0, 182.0);
console.log(gov.systemState());
Related Repos
- othismos — Constraint pressure theory
- constraint-theory-core — Algebraic primitives
- style-dna — Musical DNA extraction
- snapkit-js — Full JS port
- spline-midi-smooth — MIDI interpolation
- AI-Writings — Reflections and essays
Documentation
- Architecture of Harmony — The full white paper
- ESP32 firmware — Physical sensor layer
- Integration demo — Worked example
License
MIT
The hull sets the beat. The agents sync to the ocean.
Metadata
Release files for cocapn-snapkit 2.8.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cocapn_snapkit-2.8.0.tar.gz | 62.5 kB | Without provenance | Details for cocapn_snapkit-2.8.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cocapn_snapkit-2.8.0-py3-none-any.whl | Python 3 | none | any | Details for cocapn_snapkit-2.8.0-py3-none-any.whl |
Total release size: 121.3 kB
Release files / cocapn_snapkit-2.8.0.tar.gz
| Download URL | cocapn_snapkit-2.8.0.tar.gz |
|---|---|
| Size | 62.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9b9301f2c57004ca0fe2fbaa08ffbf17b4c9b49bac50d1f4392cb076bab1aaa8
|
|
BLAKE2b-256 checksum How to use checksums |
22fcd5ee1e90adf29b57804a5f8cdc5fbae8cdad116554fed359bead0ad74a3b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.5
|
Release files / cocapn_snapkit-2.8.0-py3-none-any.whl
| Download URL | cocapn_snapkit-2.8.0-py3-none-any.whl |
|---|---|
| Size | 58.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c29fa415849ef688757da17fb67f282989e827e1c332cc4c4c0af24330f55f48
|
|
BLAKE2b-256 checksum How to use checksums |
c0cccad4b6a1c69f68c2b1b1dc660666c23e6bc2b433de5c083767441dd45a01
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.5
|
Security for cocapn-snapkit 2.8.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.