Add Supercomputer category: 12 P2P resource-sharing modules (164 total)

Introduce a new production category for distributed system resource pooling
over Hyperswarm — CPU, RAM, GPU, bandwidth, disk, jobs, cache, and egress.

New modules (supercomputer/):
- hyper-p2p-capacity-registry — gossip CPU/RAM/GPU/disk/bandwidth ads
- hyper-p2p-cpu-share — CPU millisecond credit pool
- hyper-p2p-ram-pool — RAM byte lend/claim/release
- hyper-p2p-gpu-slot — GPU slot register/reserve
- hyper-p2p-bandwidth-share — shared up/down Mbps
- hyper-p2p-disk-stripe — striped block shards
- hyper-p2p-job-dispatcher — submit/claim/complete jobs
- hyper-p2p-thermal-guard — load/temperature throttle signals
- hyper-p2p-cache-farm — distributed LRU cache
- hyper-p2p-net-gateway — peer internet egress routing
- hyper-p2p-cluster-affinity — hardware tag placement scoring
- hyper-p2p-work-stealer — shard queues + work stealing

Each package: index.js, tests, README, api/architecture docs, examples/basic.js.
Shared layering guide: _shared/SUPERCOMPUTER_LAYERS.md.
Registry, module-paths, MODULE_CATEGORIES, and workspace README updated to 164.

Parent workspace also adds docs/supercomputer hub and demo-supercomputer-mesh
(outside this repo).

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
Raven Scott
2026-05-21 00:38:53 -04:00
co-authored by Cursor
parent 70119888cd
commit 693385bd7c
114 changed files with 24378 additions and 6 deletions
@@ -0,0 +1,5 @@
# Changelog
## 0.3.0
- Initial Supercomputer category release (thermal-guard/v1).
@@ -0,0 +1,30 @@
# hyper-p2p-thermal-guard
Production **Supercomputer** module: pool P2P system resources over Hyperswarm.
**Category:** Supercomputer · **Protocol:** `thermal-guard/v1` · **Export:** `HyperP2PThermalGuard`
## When to use
CPU, RAM, and temperature load throttle signals.
## Quick start
```js
const { HyperP2PThermalGuard } = require('hyper-p2p-thermal-guard')
const mod = new HyperP2PThermalGuard({ topic: 'my-super-mesh' })
await mod.ready()
// ...
await mod.close()
```
## Docs
- [docs/api.md](docs/api.md)
- [docs/architecture.md](docs/architecture.md)
## Test
```bash
npm install && npm test
```
@@ -0,0 +1,36 @@
# API: hyper-p2p-thermal-guard
**Protocol:** `thermal-guard/v1` · **Export:** `HyperP2PThermalGuard`
## Overview
CPU, RAM, and temperature load throttle signals.
## Constructor
```js
const mod = new HyperP2PThermalGuard(opts)
```
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| `topic` | Buffer \| string \| null | `null` | Hyperswarm topic |
| `keyPair` | KeyPair | random | Discovery identity |
## Methods
See [`index.js`](../index.js) for the full method list. All modules implement `getStats()`, `async ready()`, and `async close()`.
## getStats()
Returns `{ ...stats, protocol: 'thermal-guard/v1' }` plus module-specific counters.
## P2P
When `topic` is set, `ready()` joins Hyperswarm and opens Protomux `thermal-guard/v1`.
## Testing
```bash
npm install && npm test
```
@@ -0,0 +1,14 @@
# Architecture: hyper-p2p-thermal-guard
**Category:** Supercomputer · **Protocol:** `thermal-guard/v1`
```mermaid
flowchart LR
App[Application] --> Mod[HyperP2PThermalGuard]
Mod --> Mux[Protomux thermal-guard/v1]
Mux --> Swarm[Hyperswarm]
```
## Composition
See [`../../_shared/SUPERCOMPUTER_LAYERS.md`](../../_shared/SUPERCOMPUTER_LAYERS.md) and [`../README.md`](../README.md).
@@ -0,0 +1,10 @@
require('bare-process/global')
const { HyperP2PThermalGuard } = require('../index.js')
async function main () {
const mod = new HyperP2PThermalGuard()
console.log('stats', mod.getStats())
await mod.close()
console.log('done')
}
main().catch(console.error)
@@ -0,0 +1,86 @@
require('bare-process/global')
const EventEmitter = require('bare-events')
const b4a = require('b4a')
const { initModuleSwarm, gossipSend } = require('../../_shared/p2p-bare.js')
const PROTOCOL = 'thermal-guard/v1'
class HyperP2PThermalGuard extends EventEmitter {
constructor (opts = {}) {
super()
this._stats = { reports: 0 }
this.topic = opts.topic || null
this.keyPair = opts.keyPair || require('hypercore-crypto').keyPair()
this.cpuThreshold = opts.cpuThreshold ?? 85
this.ramThreshold = opts.ramThreshold ?? 90
this.tempThresholdC = opts.tempThresholdC ?? 80
this._samples = new Map()
this.swarm = null
this._peerMsgs = null
}
_pid (peerId) {
return typeof peerId === 'string' ? peerId : b4a.toString(peerId, 'hex')
}
reportLoad (peerId, cpuPct = 0, ramPct = 0, tempC = 0) {
if (!peerId) throw new Error('peerId required')
const sample = {
peerId: this._pid(peerId),
cpuPct: Math.max(0, Math.min(100, cpuPct)),
ramPct: Math.max(0, Math.min(100, ramPct)),
tempC: Math.max(0, tempC),
at: Date.now()
}
this._samples.set(sample.peerId, sample)
this._stats.reports++
if (this._peerMsgs) gossipSend(this, { type: 'load', sample })
this.emit('report', sample)
return sample
}
shouldThrottle (peerId) {
const s = this._samples.get(this._pid(peerId))
if (!s) return false
return s.cpuPct >= this.cpuThreshold || s.ramPct >= this.ramThreshold || s.tempC >= this.tempThresholdC
}
getHeadroom (peerId) {
const s = this._samples.get(this._pid(peerId))
if (!s) return { cpu: 100, ram: 100, temp: 100 }
return {
cpu: Math.max(0, 100 - s.cpuPct),
ram: Math.max(0, 100 - s.ramPct),
temp: Math.max(0, this.tempThresholdC - s.tempC)
}
}
listSamples () { return [...this._samples.values()] }
async ready () {
if (this.swarm || !this.topic) return this
await initModuleSwarm(this, {
keyPair: this.keyPair, topic: this.topic, protocol: PROTOCOL,
onmessage: (data) => {
if (data?.type === 'load' && data.sample) {
const cur = this._samples.get(data.sample.peerId)
if (!cur || data.sample.at >= cur.at) this._samples.set(data.sample.peerId, data.sample)
}
}
})
return this
}
getStats () {
return { ...this._stats, peers: this._samples.size, protocol: PROTOCOL }
}
async close () {
if (this.swarm) await this.swarm.destroy().catch(() => {})
this.swarm = null
this._samples.clear()
this.emit('closed')
}
}
module.exports = { HyperP2PThermalGuard, PROTOCOL }
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,23 @@
{
"name": "hyper-p2p-thermal-guard",
"version": "0.3.0",
"description": "Load and thermal throttle signals for Bare/Pear P2P supercomputer mesh.",
"main": "index.js",
"type": "commonjs",
"license": "Apache-2.0",
"scripts": { "test": "brittle-bare test/test.js" },
"dependencies": {
"bare-events": "^2.8.0",
"bare-process": "^4.4.0",
"b4a": "^1.6.7",
"hypercore-crypto": "^3.0.0",
"protomux": "^3.0.0",
"compact-encoding": "^2.0.0"
},
"peerDependencies": { "hyperswarm": "^4.0.0", "bare": ">=1.0.0" },
"devDependencies": { "brittle": "^3.0.0" },
"imports": {
"process": { "bare": "bare-process", "default": "process" },
"events": { "bare": "bare-events", "default": "events" }
}
}
@@ -0,0 +1,22 @@
require('bare-process/global')
const test = require('brittle')
const { HyperP2PThermalGuard } = require('../index.js')
test('thermal-guard: throttle', async (t) => {
const g = new HyperP2PThermalGuard({ cpuThreshold: 80 })
g.reportLoad('peer-a', 90, 50, 60)
t.ok(g.shouldThrottle('peer-a'))
t.ok(g.getHeadroom('peer-a').cpu < 20)
await g.close()
})
test('thermal-guard: validation', async (t) => {
const g = new HyperP2PThermalGuard()
try {
g.reportLoad(null, 0, 0, 0)
t.fail('expected throw')
} catch (e) {
t.ok(e instanceof Error)
}
await g.close()
})