cmp-mesh
v2.0.0
Published
Distribute computation across nearby devices. No cloud. No server. No internet required.
Maintainers
Readme
Your laptop is processing a large file. There are 3 other devices on the same WiFi doing nothing. What if they could help?
import { CMP } from 'cmp-mesh';
const mesh = new CMP();
await mesh.start();
await mesh.waitForPeers(1);
const result = await mesh.distribute(imageBytes, processorWasm);
// ⚡ Processed across 3 devices in 200ms instead of 800msCMP discovers nearby devices automatically, negotiates who helps, splits the work, executes in WASM sandboxes, encrypts everything, and assembles the result. Your code just calls distribute().
Quick Start
git clone https://github.com/agentviscro/cmp.git
cd cmp
npm installRun your first distributed computation (60 seconds):
npx tsx examples/04-two-node-compute.ts [1] Creating two CMPNodes...
Node A: 5d01151a
Node B: 692bba5a
[2] Waiting for peer discovery...
Node A sees 1 peer(s)
[4] Node A submitting WASM computation to mesh...
WASM module: 56 bytes
Input data: 64 bytes
[5] RESULT:
Distributed: true
Time: 239ms
Devices: 1
║ DISTRIBUTED COMPUTATION SUCCESSFUL! ║
║ Node A submitted → Node B executed → Result ║
║ All over real LAN with Ed25519 auth. ║Two real nodes. Real WASM execution. Real encrypted transport. No cloud.
Examples
Process real data:
npx tsx examples/02-distribute-work.ts ── Task 1: Sort 1000 random numbers ──
Output: [32,39,43,49,61,69,78,86,86,87] Time: 7ms
── Task 2: Word frequency analysis ──
"devices" → 2 times, "compute" → 2 times Time: 4ms
── Task 3: Transform sensor data ──
Avg Temperature: 27.2°C, Alert: HIGH_TEMP_WARNING Time: 55msWatch the mesh think:
npx tsx examples/03-consciousness.ts Task 1 succeeded → success pheromone: ████████ 1.50
Task 2 succeeded → success pheromone: █████████████ 2.50
Threat detected → danger pheromone: ███████████████████ 6.30
Mesh behavior: DEFENSIVE
→ No voting happened. No leader decided. Emergent behavior.Interactive CLI:
npx tsx packages/cli/src/cli.ts startcmp> status
Peers 3
Credits 100 CCU
Behavior HIGH_DEMAND
Pheromones 12 (dominant: compute_success)
DAG 45 nodes, 2 branches
Wormholes 1 active, 2 remote meshes
cmp> consciousness pheromones
compute_success ████████████ 1.20 (8 deposits)
danger ██ 0.23 (2 deposits)
cmp> spacetime fork experiment-1
Forked: branch-a1b2c3d4 ("experiment-1")
cmp> wormhole declare mesh-beta Beta 100
Declared wormhole → mesh-beta ("Beta", 100ms)When to Use CMP
| Use CMP when | Don't use CMP when | |---|---| | Heavy computation (image processing, AI inference, data analysis) | Task takes < 1 second on one device | | Multiple devices nearby on same network | Only one device available | | No cloud / can't use cloud / privacy-critical data | Reliable cloud infrastructure exists | | Need offline capability | Internet is always available | | Edge processing (IoT, sensors, warehouses) | Need massive GPU (training large models) |
Real use cases:
- Disaster relief — 10 phones with no cell tower pool compute for offline AI translation
- Hospital — 50 tablets process medical images without data leaving the building
- Classroom — 30 students pool devices to train an ML model together
- Warehouse — IoT sensors form a mesh and process anomaly detection at the edge
- Field research — Drones and phones in a remote area share compute for data analysis
Architecture
CMP implements a 13-layer protocol stack — the deepest of any peer-to-peer system:
┌─────────────────────────────────────────────────────────┐
│ Layer 13: Cross-Mesh Wormholes (Federation) v2.0│
│ Layer 12: Computation Spacetime (Temporal Fork) v2.0│
│ Layer 11: Collective Consciousness (Stigmergy) v2.0│
├─────────────────────────────────────────────────────────┤
│ Layer 10: Lifeforms (Autonomous entities) v1.4│
│ Layer 9: Precognition (Predictive scheduling) v1.3│
│ Layer 8: Mesh Cognition (Learning from history) v1.2│
│ Layer 7: Certification (Computation provenance) v1.1│
├─────────────────────────────────────────────────────────┤
│ Layer 6: Assembly (Result collection) v1.0│
│ Layer 5: Execution (WASM sandbox) v1.0│
│ Layer 4: Distribution (Chunk splitting) v1.0│
│ Layer 3: Negotiation (Bid/assign) v1.0│
│ Layer 2: Capability (Resource profiling) v1.0│
│ Layer 1: Discovery (BLE/LAN/WiFi/WebRTC) v1.0│
└─────────────────────────────────────────────────────────┘91 wire protocol message types. Full spec: CMP Protocol Specification v2.0
What makes CMP different
| Feature | CMP | BOINC | Spark | libp2p | |---------|-----|-------|-------|--------| | Zero infrastructure | ✓ | ✗ | ✗ | Partial | | Works offline | ✓ | ✗ | ✗ | ✗ | | Privacy preserving | ✓ | ✗ | Partial | Partial | | Autonomous entities (Lifeforms) | ✓ | ✗ | ✗ | ✗ | | Pheromone coordination | ✓ | ✗ | ✗ | ✗ | | Temporal forking | ✓ | ✗ | ✗ | ✗ | | Process teleportation | ✓ | ✗ | ✗ | ✗ | | Self-evolving code | ✓ | ✗ | ✗ | ✗ |
Novel concepts (no prior art)
- Stigmergy — Nodes leave pheromone trails that influence other nodes' behavior. Coordination without communication.
- Computation Spacetime — Fork a running process into parallel timelines, race them, merge the winner back. Git for live computation.
- Lifeform Teleportation — Serialize an autonomous entity (identity + state + genome + economic balance + synapses + causal history) and transmit it to a completely different mesh.
- Genome Mutation — WASM binaries evolve through natural selection. Mutant generations compete; the fittest survive.
- Emergent Behavior — The mesh automatically shifts between NORMAL, HIGH_DEMAND, DEFENSIVE, CONSERVATION, and DREAMING based on collective pheromone concentrations.
SDK
import { CMP } from 'cmp-mesh';
const mesh = new CMP();
await mesh.start();
// 5 methods. That's it.
mesh.peers // Number of nearby devices
mesh.behavior // Mesh consciousness state
mesh.distribute(data, wasm) // Distribute computation
mesh.run(lang, code, input) // Run code on mesh
mesh.status() // Full statusSee SDK documentation for full API reference with examples.
Project Structure
cmp/
├── packages/
│ ├── core/ Protocol layers, types, crypto, consciousness, spacetime, wormholes
│ ├── transport/ BLE, LAN (UDP/TCP), WiFi Direct, WebRTC transports
│ ├── runtime/ WASM sandbox, multi-runtime execution engine
│ ├── cli/ Interactive REPL (2,400 lines)
│ └── mobile/ React Native entry point
├── examples/ 4 runnable examples
├── docs/ Protocol specifications
├── sdk.ts Simple 5-method API wrapper
└── SDK-README.md Developer documentation68,059 lines of TypeScript. 212 source files. 827 tests. 0 failures.
Tests
npm run test:all # Run all test suites
# Individual suites
npm run test # Core protocol (49 tests)
npm run test:auth # Ed25519 authentication + flow control (45 tests)
npm run test:distributed # Two-node WASM distribution (2 tests)
npm run test:consciousness # Layer 11: Pheromones, quorum, swarm (43 tests)
npm run test:spacetime # Layer 12: DAG, forking, racing (39 tests)
npm run test:wormhole # Layer 13: Discovery, teleport, synapses (30 tests)
npm run test:bridge # V2 integration (15 tests)Protocol Spec
The complete v2.0 specification (709 lines, 26 sections) covering all 13 layers, 91 message types, security model, and incentive mechanism:
CMP Protocol Specification v2.0
Roadmap
- [x] v1.0 — Core protocol (6 layers, distributed WASM execution)
- [x] v1.2 — Mesh Cognition (learning from past executions)
- [x] v1.3 — Mesh Intelligence (immune system, metabolism, futures, morphogenesis)
- [x] v1.4 — Lifeforms (autonomous entities, CRDT state, fusion/fission, mutation)
- [x] v1.5 — Ground Truth (Ed25519 auth, flow control, native crypto, distributed compute proven)
- [x] v2.0 — Consciousness (stigmergy, spacetime, wormholes)
- [ ] v2.5 — ZK proofs, neuromorphic routing, homomorphic computation
- [ ] v3.0 — Production hardening, monitoring, observability
Contributing
CMP is an open protocol. Contributions welcome.
git clone https://github.com/agentviscro/cmp.git
cd cmp
npm install
npm run test:all # Make sure everything passesAreas where help is needed:
- React Native testing — Run the real protocol on phones via BLE
- WebGPU integration — GPU compute from WASM sandboxes
- ZK-SNARK verification — Replace redundant execution with zero-knowledge proofs
- Production hardening — Rate limiting, monitoring, graceful upgrades
- Real applications — Build something on CMP and tell us about it
License
MIT — LICENSE
