Add batch helpers and domain utilities across modules missing Batch APIs.

Third enrichment pass: *Batch methods for agents, economy, consensus, core, messaging, network, observability, pear-platform, scheduling, storage, supercomputer, and time-ordering modules.

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
Raven Scott
2026-05-21 04:12:52 -04:00
co-authored by Cursor
parent 557c7e83b6
commit 2a7812ddbb
43 changed files with 259 additions and 0 deletions
@@ -450,6 +450,20 @@ class HyperP2PAgentMemory extends EventEmitter {
return { memories: this.memories.size, tags: this.tagIndex.size } return { memories: this.memories.size, tags: this.tagIndex.size }
} }
async storeMemoryBatch (entries) {
if (!Array.isArray(entries)) throw new Error('entries array required')
const out = []
for (const e of entries) {
out.push(await this.storeMemory(e.content, e.options || {}))
}
return out
}
async forgetBatch (ids) {
if (!Array.isArray(ids)) throw new Error('ids array required')
return ids.map((id) => this.forget(id))
}
getStats () { getStats () {
return { return {
...this._metrics, ...this._metrics,
@@ -137,6 +137,16 @@ class HyperP2PAuctionGossip extends EventEmitter {
return { auctions: this._auctions.size, open: this.listOpen().length } return { auctions: this._auctions.size, open: this.listOpen().length }
} }
openAuctionBatch (entries) {
if (!Array.isArray(entries)) throw new Error('entries array required')
return entries.map((e) => this.openAuction(e.auctionId, e.meta || {}))
}
placeBidBatch (entries) {
if (!Array.isArray(entries)) throw new Error('entries array required')
return entries.map((e) => this.placeBid(e.auctionId, e.amount, e.meta || {}))
}
_gossip (payload) { _gossip (payload) {
if (!this._peerMsgs) return if (!this._peerMsgs) return
gossipSend(this, payload) gossipSend(this, payload)
@@ -117,6 +117,11 @@ class HyperP2PMarketplaceListing extends EventEmitter {
return { listings: this._listings.size, active: this.listActive().length } return { listings: this._listings.size, active: this.listActive().length }
} }
createListingBatch (entries) {
if (!Array.isArray(entries)) throw new Error('entries array required')
return entries.map((e) => this.createListing(e.listingId, e.listing))
}
removeAllActive () { removeAllActive () {
const ids = this.listActive().map((l) => l.id) const ids = this.listActive().map((l) => l.id)
for (const id of ids) this.removeListing(id) for (const id of ids) this.removeListing(id)
@@ -433,6 +433,15 @@ class HyperP2PCausalConsensus extends EventEmitter {
} }
} }
async proposeBatch (entries) {
if (!Array.isArray(entries)) throw new Error('entries array required')
const out = []
for (const e of entries) {
out.push(await this.propose(e.data, e.causalDeps || {}))
}
return out
}
getMetrics () { getMetrics () {
return { ...this._metrics, peers: this.peers.size, pendingProposals: this.proposals.size - this.decidedOrders.size } return { ...this._metrics, peers: this.peers.size, pendingProposals: this.proposals.size - this.decidedOrders.size }
} }
@@ -374,6 +374,15 @@ class HyperP2PDistributedLock extends EventEmitter {
} }
} }
async acquireBatch (entries) {
if (!Array.isArray(entries)) throw new Error('entries array required')
const out = []
for (const e of entries) {
out.push(await this.acquire(e.resourceId, e.opts || {}))
}
return out
}
/** /**
* List all currently active locks (local + remote). * List all currently active locks (local + remote).
* Supports optional filter by owner or resource prefix. * Supports optional filter by owner or resource prefix.
@@ -352,6 +352,10 @@ class HyperP2PPresence extends EventEmitter {
return { peers: this.peers.size, online: this.onlineCount(), ids: this.peerIds() } return { peers: this.peers.size, online: this.onlineCount(), ids: this.peerIds() }
} }
toJSON () {
return this.snapshot()
}
announceNow () { announceNow () {
this._broadcastPresence() this._broadcastPresence()
return this.getSelf() return this.getSelf()
@@ -32,6 +32,12 @@ class RPCServer extends EventEmitter {
this.services.set(name, { handler, schema }) this.services.set(name, { handler, schema })
} }
registerBatch (entries) {
if (!Array.isArray(entries)) throw new Error('entries array required')
for (const e of entries) this.register(e.name, e.handler, e.schema || null)
return entries.length
}
unregister (name) { unregister (name) {
return this.services.delete(name) return this.services.delete(name)
} }
@@ -85,6 +85,13 @@ class HyperP2PSessionBridge extends EventEmitter {
return { pairs: this.listPairs().length } return { pairs: this.listPairs().length }
} }
async createPairBatch (count = 1) {
const n = Math.max(1, count | 0)
const out = []
for (let i = 0; i < n; i++) out.push(await this.createPair())
return out
}
async removePair (token) { async removePair (token) {
const entry = this._tokens.get(token) const entry = this._tokens.get(token)
if (!entry) return false if (!entry) return false
@@ -93,6 +93,11 @@ class HyperP2PParadoxMerge extends EventEmitter {
return { open: this.listOpen().length, resolved: this._resolved.size } return { open: this.listOpen().length, resolved: this._resolved.size }
} }
branchBatch (entries) {
if (!Array.isArray(entries)) throw new Error('entries array required')
return entries.map((e) => this.branch(e.id, e.value))
}
_gossip (data) { _gossip (data) {
if (!this._peerMsgs) return if (!this._peerMsgs) return
gossipSend(this, data) gossipSend(this, data)
@@ -104,6 +104,11 @@ class HyperP2PPhaseShiftClock extends EventEmitter {
return { phaseMs: this._phaseMs, peers: this.peerPhases() } return { phaseMs: this._phaseMs, peers: this.peerPhases() }
} }
shiftBatch (entries) {
if (!Array.isArray(entries)) throw new Error('entries array required')
return entries.map((e) => this.shift(e.phaseMs))
}
_gossip (data) { _gossip (data) {
if (!this._peerMsgs) return if (!this._peerMsgs) return
gossipSend(this, data) gossipSend(this, data)
@@ -117,6 +117,11 @@ class HyperP2PHelperSwarmCoordinator extends EventEmitter {
return { helpers: this._helpers.size, assignments: this.assignmentCount() } return { helpers: this._helpers.size, assignments: this.assignmentCount() }
} }
registerHelperBatch (entries) {
if (!Array.isArray(entries)) throw new Error('entries array required')
return entries.map((e) => this.registerHelper(e.peerId, e.capacityBps))
}
_gossip (payload) { _gossip (payload) {
if (this._peerMsgs) gossipSend(this, payload) if (this._peerMsgs) gossipSend(this, payload)
} }
@@ -145,6 +145,11 @@ class HyperP2PSubscriptionLease extends EventEmitter {
return { leases: this._leases.size, channels: this.listChannels() } return { leases: this._leases.size, channels: this.listChannels() }
} }
acquireBatch (channels) {
if (!Array.isArray(channels)) throw new Error('channels array required')
return channels.map((ch) => this.acquire(ch))
}
getStats () { getStats () {
return { ...this._stats, active: this._leases.size, protocol: PROTOCOL } return { ...this._stats, active: this._leases.size, protocol: PROTOCOL }
} }
@@ -127,6 +127,11 @@ class HyperP2PStreamMultiplex extends EventEmitter {
return { open: this._streams.size, frames: this._stats.frames, bytes: this._stats.bytes } return { open: this._streams.size, frames: this._stats.frames, bytes: this._stats.bytes }
} }
openStreamBatch (ids) {
if (!Array.isArray(ids)) throw new Error('ids array required')
return ids.map((id) => this.openStream(id))
}
getStats () { getStats () {
return { return {
...this._stats, ...this._stats,
@@ -95,6 +95,11 @@ class HyperP2PStreamTee extends EventEmitter {
return { branches: this._branches.size } return { branches: this._branches.size }
} }
addBranchBatch (names) {
if (!Array.isArray(names)) throw new Error('names array required')
return names.map((name) => this.addBranch(name))
}
getStats () { getStats () {
return { ...this._stats, branchCount: this._branches.size, protocol: PROTOCOL } return { ...this._stats, branchCount: this._branches.size, protocol: PROTOCOL }
} }
@@ -89,6 +89,11 @@ class HyperP2PConnectionPool extends EventEmitter {
return this.getPoolStats() return this.getPoolStats()
} }
acquireBatch (peerIds) {
if (!Array.isArray(peerIds)) throw new Error('peerIds array required')
return peerIds.map((peerId) => this.acquire(peerId))
}
_sweepIdle () { _sweepIdle () {
const now = Date.now() const now = Date.now()
for (const [id, lane] of this._lanes) { for (const [id, lane] of this._lanes) {
@@ -91,6 +91,11 @@ class HyperP2PProtocolHandshake extends EventEmitter {
return { pending: this._offers.size, agreed: this._agreed.size } return { pending: this._offers.size, agreed: this._agreed.size }
} }
offerBatch (entries) {
if (!Array.isArray(entries)) throw new Error('entries array required')
return entries.map((e) => this.offer(e.features || {}))
}
getStats () { getStats () {
return { ...this._stats, pending: this._offers.size, agreed: this._agreed.size, protocol: PROTOCOL } return { ...this._stats, pending: this._offers.size, agreed: this._agreed.size, protocol: PROTOCOL }
} }
@@ -92,6 +92,13 @@ class HyperP2PSecretStreamPair {
return { active: this.hasActivePair(), publicKey: this.publicKeyHex() } return { active: this.hasActivePair(), publicKey: this.publicKeyHex() }
} }
createBatch (count = 1) {
const n = Math.max(1, count | 0)
const out = []
for (let i = 0; i < n; i++) out.push(this.create())
return out
}
publicKeyHex () { publicKeyHex () {
return require('b4a').toString(this.keyPair.publicKey, 'hex') return require('b4a').toString(this.keyPair.publicKey, 'hex')
} }
@@ -68,6 +68,12 @@ class HyperP2PMetricsAggregator extends EventEmitter {
return { series: this._metrics.size, names: this.metricNames() } return { series: this._metrics.size, names: this.metricNames() }
} }
recordBatch (entries) {
if (!Array.isArray(entries)) throw new Error('entries array required')
for (const e of entries) this.record(e.name, e.value, e.labels || {})
return entries.length
}
metricNames () { metricNames () {
const names = new Set() const names = new Set()
for (const s of this._metrics.values()) names.add(s.name) for (const s of this._metrics.values()) names.add(s.name)
@@ -106,6 +106,11 @@ class HyperP2PTraceSpan extends EventEmitter {
return { active: this.activeSpans().length, total: this.spanCount() } return { active: this.activeSpans().length, total: this.spanCount() }
} }
startSpanBatch (entries) {
if (!Array.isArray(entries)) throw new Error('entries array required')
return entries.map((e) => this.startSpan(e.name, e.parentId ?? null))
}
activeCount () { activeCount () {
return this.activeSpans().length return this.activeSpans().length
} }
@@ -110,6 +110,12 @@ class HyperBareArgvBridge extends EventEmitter {
return { flags: this._flags.size, rest: this._rest.length, targets: this.launchTargets().length } return { flags: this._flags.size, rest: this._rest.length, targets: this.launchTargets().length }
} }
appendArgvBatch (chunks) {
if (!Array.isArray(chunks)) throw new Error('chunks array required')
for (const extra of chunks) this.appendArgv(extra)
return chunks.length
}
getStats () { getStats () {
return platformStats(this._stats, PROTOCOL, { return platformStats(this._stats, PROTOCOL, {
flags: this._flags.size, flags: this._flags.size,
@@ -112,6 +112,11 @@ class HyperBareHeadlessUi extends EventEmitter {
} }
} }
sendToUiBatch (messages) {
if (!Array.isArray(messages)) throw new Error('messages array required')
return messages.map((m) => this.sendToUi(m.channel, m.payload))
}
getStats () { getStats () {
return platformStats(this._stats, PROTOCOL, this.snapshot()) return platformStats(this._stats, PROTOCOL, this.snapshot())
} }
@@ -106,6 +106,12 @@ class HyperBareImportMap extends EventEmitter {
return { entries: Object.keys(this._imports).length } return { entries: Object.keys(this._imports).length }
} }
setBatch (entries) {
if (!Array.isArray(entries)) throw new Error('entries array required')
for (const e of entries) this.set(e.specifier, e.target)
return entries.length
}
getStats () { getStats () {
return platformStats(this._stats, PROTOCOL, { entries: Object.keys(this._imports).length }) return platformStats(this._stats, PROTOCOL, { entries: Object.keys(this._imports).length })
} }
@@ -106,6 +106,11 @@ class HyperBareTargetMatrix extends EventEmitter {
return { host: this.host, targets: this.targetCount() } return { host: this.host, targets: this.targetCount() }
} }
addTargetBatch (entries) {
if (!Array.isArray(entries)) throw new Error('entries array required')
return entries.map((e) => this.addTarget(e.os, e.arch, e.extra || {}))
}
targetCount () { targetCount () {
return this._targets.length return this._targets.length
} }
@@ -74,6 +74,12 @@ class HyperPearApplinkConfig extends EventEmitter {
return this._config ? JSON.parse(JSON.stringify(this._config)) : null return this._config ? JSON.parse(JSON.stringify(this._config)) : null
} }
setFlagBatch (entries) {
if (!Array.isArray(entries)) throw new Error('entries array required')
for (const e of entries) this.setFlag(e.name, e.value)
return entries.length
}
applinkHref () { applinkHref () {
return this._config ? this._config.applink : null return this._config ? this._config.applink : null
} }
@@ -90,6 +90,12 @@ class HyperPearDevProfile extends EventEmitter {
} }
} }
setFlagBatch (entries) {
if (!Array.isArray(entries)) throw new Error('entries array required')
for (const e of entries) this.setFlag(e.name, e.value)
return entries.length
}
isProduction () { isProduction () {
return !this.dev return !this.dev
} }
@@ -44,6 +44,12 @@ class HyperPearElectronBridge extends EventEmitter {
return { handlers: this.handlerCount(), renderer: this.renderer } return { handlers: this.handlerCount(), renderer: this.renderer }
} }
registerIpcBatch (entries) {
if (!Array.isArray(entries)) throw new Error('entries array required')
for (const e of entries) this.registerIpc(e.name, e.handler)
return entries.length
}
handlerCount () { handlerCount () {
return this._channels.size return this._channels.size
} }
@@ -47,6 +47,12 @@ class HyperPearOtaState extends EventEmitter {
snapshot () { return { ...this._state } } snapshot () { return { ...this._state } }
transitionBatch (entries) {
if (!Array.isArray(entries)) throw new Error('entries array required')
for (const e of entries) this.transition(e.phase, e.patch || {})
return entries.length
}
history (limit = 32) { history (limit = 32) {
return this._log.slice(-limit) return this._log.slice(-limit)
} }
@@ -147,6 +147,11 @@ class HyperPearPreflightSync extends EventEmitter {
return { jobs: this._jobs.size, pending: this.listPending().length } return { jobs: this._jobs.size, pending: this.listPending().length }
} }
startBatch (entries) {
if (!Array.isArray(entries)) throw new Error('entries array required')
return entries.map((e) => this.start(e.target, e.meta || {}))
}
getStats () { getStats () {
return platformStats(this._stats, PROTOCOL, { return platformStats(this._stats, PROTOCOL, {
jobs: this._jobs.size, jobs: this._jobs.size,
@@ -87,6 +87,11 @@ class HyperPearRuntimeEmbed extends EventEmitter {
} }
} }
planRunBatch (entries) {
if (!Array.isArray(entries)) throw new Error('entries array required')
return entries.map((e) => this.planRun(e.entrypoint, e.args || [], e.opts || {}))
}
async close () { async close () {
if (!this._opened) return if (!this._opened) return
this._opened = false this._opened = false
@@ -98,6 +98,11 @@ class HyperPearRuntimeSession extends EventEmitter {
return { total: this._sessions.size, active: this.activeSessions().length } return { total: this._sessions.size, active: this.activeSessions().length }
} }
startSessionBatch (entries) {
if (!Array.isArray(entries)) throw new Error('entries array required')
return entries.map((e) => this.startSession(e.meta || {}))
}
getStats () { getStats () {
return { return {
...this._stats, ...this._stats,
@@ -78,6 +78,11 @@ class HyperPearStorageLayout extends EventEmitter {
return Object.fromEntries(this._apps) return Object.fromEntries(this._apps)
} }
registerAppBatch (entries) {
if (!Array.isArray(entries)) throw new Error('entries array required')
return entries.map((e) => this.registerApp(e.appKey, e.layout || {}))
}
setDefaultApp (appKey) { setDefaultApp (appKey) {
this.defaultApp = assertId(appKey, 'appKey') this.defaultApp = assertId(appKey, 'appKey')
return this.defaultApp return this.defaultApp
@@ -95,6 +95,12 @@ class HyperP2PLoadSpread extends EventEmitter {
return { peers: this._peers.size, totalLoad: this.totalLoad() } return { peers: this._peers.size, totalLoad: this.totalLoad() }
} }
registerPeerBatch (entries) {
if (!Array.isArray(entries)) throw new Error('entries array required')
for (const e of entries) this.registerPeer(e.peerId, e.load)
return entries.length
}
getStats () { getStats () {
return { return {
...this._stats, ...this._stats,
@@ -112,6 +112,11 @@ class HyperP2PCronGossip extends EventEmitter {
return { jobs: this._jobs.size, paused: this.pausedCount() } return { jobs: this._jobs.size, paused: this.pausedCount() }
} }
scheduleBatch (entries) {
if (!Array.isArray(entries)) throw new Error('entries array required')
return entries.map((e) => this.schedule(e.expr, e.jobId))
}
pausedCount () { pausedCount () {
return [...this._jobs.values()].filter((j) => j.paused).length return [...this._jobs.values()].filter((j) => j.paused).length
} }
@@ -103,6 +103,12 @@ class HyperP2PDeadlineQueue extends EventEmitter {
return { pending: this._queue.length } return { pending: this._queue.length }
} }
enqueueBatch (entries) {
if (!Array.isArray(entries)) throw new Error('entries array required')
for (const e of entries) this.enqueue(e.id, e.task, e.deadline)
return entries.length
}
cancelAll () { cancelAll () {
const ids = [...this._byId.keys()] const ids = [...this._byId.keys()]
for (const id of ids) this.cancel(id) for (const id of ids) this.cancel(id)
@@ -91,6 +91,11 @@ class HyperP2PTopicLease extends EventEmitter {
return { leases: this.leaseCount(), shards: [...this._leases.keys()] } return { leases: this.leaseCount(), shards: [...this._leases.keys()] }
} }
acquireBatch (topicShards) {
if (!Array.isArray(topicShards)) throw new Error('topicShards array required')
return topicShards.map((topicShard) => this.acquire(topicShard))
}
leaseCount () { leaseCount () {
const now = Date.now() const now = Date.now()
return [...this._leases.values()].filter((l) => l.expiresAt > now).length return [...this._leases.values()].filter((l) => l.expiresAt > now).length
@@ -86,6 +86,18 @@ class HyperP2PCrdtLwwRegister extends EventEmitter {
return out return out
} }
setBatch (entries) {
if (!Array.isArray(entries)) throw new Error('entries array required')
for (const e of entries) this.set(e.key, e.value, e.ts)
return entries.length
}
deleteBatch (keys) {
if (!Array.isArray(keys)) throw new Error('keys array required')
for (const key of keys) this.delete(key)
return keys.length
}
compare (key, ts) { compare (key, ts) {
const e = this._values.get(key) const e = this._values.get(key)
if (!e) return ts if (!e) return ts
@@ -81,6 +81,11 @@ class HyperP2PAutobaseWriterLease extends EventEmitter {
return { leases: this.listActiveLeases(), localWriterId: this.localWriterId } return { leases: this.listActiveLeases(), localWriterId: this.localWriterId }
} }
acquireLeaseBatch (entries) {
if (!Array.isArray(entries)) throw new Error('entries array required')
return entries.map((e) => this.acquireLease(e.writerId, e.ttlMs))
}
listActiveLeases () { listActiveLeases () {
const now = Date.now() const now = Date.now()
const out = [] const out = []
@@ -115,6 +115,10 @@ class HyperP2PCoreBitfieldScheduler extends EventEmitter {
return { pending: this._queue.length, served: this._served.size } return { pending: this._queue.length, served: this._served.size }
} }
scheduleRangeBatch (ranges) {
return this.scheduleMany(ranges)
}
getStats () { getStats () {
return coreStats(this._stats, PROTOCOL, { return coreStats(this._stats, PROTOCOL, {
pending: this._queue.length, pending: this._queue.length,
@@ -106,6 +106,11 @@ class HyperP2PCoreForkPicker extends EventEmitter {
return { forks: this._forks.size, chosen: this._chosen } return { forks: this._forks.size, chosen: this._chosen }
} }
registerForkBatch (entries) {
if (!Array.isArray(entries)) throw new Error('entries array required')
return entries.map((e) => this.registerFork(e.head, e.length, e.meta || {}))
}
getStats () { getStats () {
return coreStats(this._stats, PROTOCOL, { return coreStats(this._stats, PROTOCOL, {
forkCount: this._forks.size, forkCount: this._forks.size,
@@ -118,6 +118,10 @@ class HyperP2PCorePriorityFetch extends EventEmitter {
return { pending: this._heap.length, inflight: this._inflight.size } return { pending: this._heap.length, inflight: this._inflight.size }
} }
enqueueBlockBatch (indices, priority = 0) {
return this.enqueueMany(indices, priority)
}
getStats () { getStats () {
return coreStats(this._stats, PROTOCOL, { return coreStats(this._stats, PROTOCOL, {
pending: this._heap.length, pending: this._heap.length,
@@ -111,6 +111,11 @@ class HyperP2PDriveVersionSnapshot extends EventEmitter {
return this.stateSnapshot() return this.stateSnapshot()
} }
snapshotVersionBatch (entries) {
if (!Array.isArray(entries)) throw new Error('entries array required')
return entries.map((e) => this.snapshotVersion(e.label, e.meta || {}))
}
getStats () { getStats () {
return driveStats(this._stats, PROTOCOL, { snapshots: this._snapshots.size }) return driveStats(this._stats, PROTOCOL, { snapshots: this._snapshots.size })
} }
@@ -107,6 +107,11 @@ class HyperP2PClusterAffinity extends EventEmitter {
return { tags: this._tags.size, peers: this.listTagged().length } return { tags: this._tags.size, peers: this.listTagged().length }
} }
tagPeerBatch (entries) {
if (!Array.isArray(entries)) throw new Error('entries array required')
return entries.map((e) => this.tagPeer(e.peerId, e.tags || [], e.latencyMs ?? null))
}
async ready () { async ready () {
if (this.swarm || !this.topic) return this if (this.swarm || !this.topic) return this
await initModuleSwarm(this, { await initModuleSwarm(this, {
@@ -409,6 +409,15 @@ class HyperP2PTemporalIndex extends EventEmitter {
return { events: this.events.size, buckets: this.timeIndex.size } return { events: this.events.size, buckets: this.timeIndex.size }
} }
async insertEventBatch (entries) {
if (!Array.isArray(entries)) throw new Error('entries array required')
const out = []
for (const e of entries) {
out.push(await this.insertEvent(e.data, e.options || {}))
}
return out
}
getStats () { getStats () {
return { return {
events: this.events.size, events: this.events.size,