Files
bare-operating-system/packages/bare-os-protocol/lib/channel.js
T
Raven Scott d286ce19b5 chore(plan): cancel end-to-end seeder-to-booter smoke harness task
test(protocol): add deterministic MBR failover-key coverage
docs(protocol): align package-bare-os-protocol version to 0.9.1
test(booter): add MBR corruption and wrong-topic smoke fixtures
test(peer-seed): add strict pre-MBR bare_os.capabilities negotiation check
feat(seeder): validate BARE_OS_SEED_REQUIRE_MBR_LABELS
feat(seeder): validate BARE_OS_SEED_CAPABILITY_ATTESTATION_JSON schema
docs(boot-policy): add requireProtocolPackageMin 0.9.1 example
test(kernel): cover boot.policy denySeedRpcMethods behavior
test(protocol): add app/cap/chat/meshdrop channel compatibility fixture
test(swarm-disk): cover duplicate Protomux channel null-return path
test(protocol): add 11-word kernelCapabilityWords round-trip fixture
docs(schema): add mbr-layout schema and validate seeder examples
test(protocol): add topicKey() golden hash fixture
docs(trust): document block-0 trust assumptions in boot docs
feat(seeder): add discovery.flushed readiness logging
feat(booter): record peer discovery timings in boot-perf.json
feat(integration): add local testnet mode to integration lab smoke
test(booter): add Hyperswarm connection-budget env regression coverage
test(booter): add swarm plus Corestore suspend/resume integration coverage
feat(booter): mirror swarm ban events into host audit logs
feat(booter): add direct-peer boot via BARE_OS_BOOT_JOIN_PEER_HEX
feat(seeder): pass BARE_OS_SEED_MAX_PEERS to Hyperswarm
feat(seeder): log drive.version and discoveryKey at startup
test(booter): add Hyperdrive.checkout read-only boot probe coverage
feat(booter): prefetch /boot/init.js before kernel handoff
feat(booter): add optional /bin warm replication via downloadDiff
feat(seeder): add manifestPaths SHA-256 generation in stage-kernel-tree
test(peer-seed): cover helper-served block-0 after seeder exit
feat(protocol): add Protomux cork batching for initial channel sends
test(boot-graph): compare kernel/init labels with booter graph proc
docs(boot-policy): add v9-v11 schema examples
feat(release): add requireInitJsSha256 fixture generation step
test(vfs): add BARE_OS_VFS_SYSTEM_RO_ALIAS coverage
test(vfs): strengthen system-drive write-deny path coverage
feat(identity): add personal-drive namespace export/import docs and tests
test(booter): add guest-to-login warm cache invalidation regression
test(vfs): add guest deny coverage for /.bare sensitive paths
test(coreutils): add cross-drive mv failure injection coverage
test(vfs): add .bareos_empty round-trip coverage across mkdir/rmdir/cp/git-fs
test(vfs): add /dev/shm quota enforcement coverage
test(proc): add /proc/bare_os/index.json sortedness and schema checks
test(vfs): add warm read cache invalidation on replication growth
docs(ctx): document bareOsInvalidateWarmReadCaches(reason)
test(kernel): add BARE_OS_BOOT_DRY_RUN behavior coverage
docs(posix): add dashboard rows for all COREUTILS_COMMANDS
feat(curl): expand -w variables beyond http_code/url_effective/size_download
feat(wget): mark -N timestamping as explicit unsupported error
feat(curl): plumb mutual TLS cert/key intent to ctx.httpFetch metadata
feat(shuf): add deterministic seed mode via BARE_OS_SHUF_SEED
docs(sort): document -M month-sort as unsupported
feat(grep): add explicit -E and -G mode handling
test(sed): add Open Group Issue 7 golden fixtures
test(awk): add getline VFS regressions for missing/repeat/boundary cases
test(shell): add non-interactive here-doc coverage
test(shell): add trap delivery coverage for synthetic PIDs/job IDs
test(shell): add set -e compound-body behavior coverage
docs(shell): strengthen read builtin opt-in guidance
test(env): add Bare-runtime coverage for -S and --env-file
docs(man): add examples for pathcap-verify pkg-swarm-index corestorectl
test(identity): add account/vault backup-restore smoke coverage
feat(audit): add tamper detection verification for audit chain rows
test(peer-admission): cover strict empty allowlist deny behavior
test(peer-admission): add denylist precedence over allowlist coverage
test(peer-admission): add BARE_OS_PEER_REQUIRE_CAPS_JSON metadata checks
docs(identity): add trusted-key rotation example for path capabilities
feat(schema): tighten extensionSignerPinsV2-V4 hash validation
test(delegate): add allowlist negative cases for curl/wget/git/hrpc/systemctl
test(proc): extend /proc/self/environ redaction key coverage
docs(security): add peer-assisted block-0 mirroring threat-model notes
feat(bench): add boot budget trend output from real booter phases
test(baretop): align fixture coverage with /proc snapshot key set
test(metrics): validate /proc/bare_os/metrics.prom OpenMetrics shape
docs(ops): add structured seeder NDJSON examples
test(replication): add live stall-hint coverage for no_peers/length_unavailable/ok
docs(release): add corestore-snapshot workflow to checklist
docs(ops): add mirror-drive experiment utility to maintainer workflow
test(booter): add monitor progress coverage for replication live sketch
feat(seeder): validate DHT bootstrap address class JSON inputs
docs(network): add HYPERSWARM_BOOTSTRAP testnet operator guidance
chore(root): add deterministic test:integration script
docs(ci): add local CI runbook for no-.github environments
docs(release): add npm run test:bare after npm test
feat(verify): add protocol docs/package version parity checker
feat(verify): enforce feature-roadmap canonical path consistency
feat(lockfile-drift): add tier-1 strict fail option for mismatches
docs(lockfile-drift): add udx-native and blind-peering upgrade workflow notes
docs(cli-parity): add bare-fetch upstream issue tracking row
feat(bundle-health): generate per-tier bundle size regression thresholds
feat(doc-contracts): verify handbook references to current proc schema versions
feat(pretest): add validate-mermaid-syntax gate
feat(probe): add bare-runtime top-25 critical command lane
docs(protocol): update capability-word prose from bits..bits5 to current words
docs(two-drive): document /tmp /var/log and account-prefix routing
docs(security): add concise boot trust model page and links
docs(dev-guide): add P2P lab cookbook section
docs(dev-guide): add how-to for adding seed RPCs
docs(dev-guide): add how-to for adding /proc/bare_os nodes
docs(dev-guide): add /bin utility checklist for man/posix/build/parity/tests
docs(user-manual): add short What BareOS is not section
2026-04-26 22:28:21 -04:00

1811 lines
61 KiB
JavaScript

import b4a from 'b4a'
import c from 'compact-encoding'
import {
PROTOCOL_NAME,
PROTOCOL_APP_CHANNEL_NAME,
PROTOCOL_CHAT_CHANNEL_NAME
} from '../constants.js'
import {
BARE_OS_KERNEL_FEATURE_BITS_DOC,
BARE_OS_KERNEL_FEATURES_STOCK_WORD_PRIMARY,
BARE_OS_KERNEL_FEATURES_STOCK_WORD_EXTENDED_SEEDING_PLATFORM,
BARE_OS_KERNEL_FEATURES_STOCK_WORD_RLIMITS_DELEGATES_SHELL,
BARE_OS_KERNEL_FEATURES_STOCK_WORD_OFFLINE_NET_EXTENSIONS,
BARE_OS_KERNEL_FEATURES_STOCK_WORD_HOST_TRANSPORT_DELEGATES,
BARE_OS_KERNEL_FEATURES_STOCK_WORD_REPLICATION_OPERATOR_SURFACE,
BARE_OS_KERNEL_FEATURES_STOCK_WORD_PEAR_CORESTORE_HRPC,
BARE_OS_KERNEL_FEATURES_STOCK_WORD_BARE_RUNTIME_PROTO_MUX,
BARE_OS_KERNEL_FEATURES_STOCK_WORD_BARE_MODULE_CRYPTO_STAGING,
BARE_OS_KERNEL_FEATURES_STOCK_WORD_PEAR_INSPECT_LOGGER_TLS,
BARE_OS_KERNEL_FEATURES_STOCK_WORD_HYPERCORE_PACK_HRPC_LIFECYCLE
} from './kernel-feature-bits.js'
import {
BARE_OS_SEED_RPC_METHODS,
BARE_OS_SEED_RPC_METHOD_SHORT_NAME_SET
} from './seed-rpc-methods.js'
import { BARE_OS_PROTOCOL_PACKAGE_VERSION } from './protocol-meta.js'
import {
BARE_OS_KERNEL_CAPABILITY_WORDS_JSON_KEY,
BARE_OS_KERNEL_CAPABILITY_WIRE_VERSION,
buildKernelCapabilityWordsObject
} from './kernel-capability-wire.js'
import {
msgDataEncoding,
msgSearchReqEncoding,
msgSearchResEncoding,
msgRpcReqEncoding,
msgRpcResEncoding
} from './messages.js'
import { BARE_OS_CHAT_WIRE_SCHEMA_VERSION } from './chat-messages.js'
import { setupBareOsChatChannel } from './chat-channel.js'
import { bareOsProtMuxChatChannelEnabled } from './chat-env.js'
import {
BARE_OS_PROTOMUX_CHANNEL_SCHEMA_VERSION,
BARE_OS_PROTOMUX_CORK_HINT_VERSION
} from './protomux-channel-schema.js'
export {
BARE_OS_PROTOMUX_CHANNEL_SCHEMA_VERSION,
BARE_OS_PROTOMUX_CORK_HINT_VERSION
}
/**
* Seeder-side Protomux channel: MBR block service + manifest search + RPC + drive replication.
* @param {import('protomux')} mux
* @param {Map<number, Uint8Array>} localRAM
* @param {(stream: any) => void} replicateDrive - e.g. (s) => drive.replicate(s)
* @param {{
* manifestPaths?: string[],
* enableBareOsChatChannel?: boolean,
* searchMaxMatches?: number,
* stagingActiveSlot?: string,
* stagingPendingSlot?: string,
* mbrKeysHex?: string[],
* attestationJson?: string,
* snapshotHintsJson?: string,
* peerFirewallStatsJson?: string,
* replicationQueueDepthHint?: number,
* replicationSnapshotNoteJson?: string,
* stagingPreviousSlot?: string,
* stagingCanarySlot?: string,
* drive?: { core?: { length?: number }, id?: Uint8Array },
* replicationPlanId?: string,
* replicationPlanNote?: string,
* imageTipId?: string,
* dhtBootstrapAddrs?: string[],
* snapshotChainJson?: string,
* mirrorCompactionHint?: string,
* updaterStateJson?: string,
* blindPeerTopologyV2Json?: string,
* handshakeTokenBucketJson?: string,
* replicationPriorityClass?: string,
* replicationIpv6ScopeCountsJson?: string,
* corestoreSnapshotTag?: string,
* queuedPeerCount?: number,
* mbrKeyLabels?: string[],
* relayVsDirectNote?: string,
* seederHostBundleId?: string,
* seederPearRuntimeFingerprint?: string,
* booterPackageVersionHint?: string,
* corestoreStatsJson?: string,
* snapshotManifestSliceJson?: string,
* mirrorDriveHintV2Json?: string,
* hrpcRegistrySummaryJson?: string,
* protomuxCapabilityAdHex?: string,
* dhtAddressBookJson?: string,
* replicationThrottleHintJson?: string,
* bundlebeeStageJson?: string,
* httpDhtProxyHintJson?: string,
* protomuxRpcPoolHintJson?: string,
* hyperblobStoreHintJson?: string,
* signingRequestQueueHintJson?: string,
* coreStorageLayoutHintJson?: string,
* mirrorDriveCompactionV3Json?: string,
* bundlebeeCliStageJson?: string,
* readyGuardV2Json?: string,
* blindRelayCircuitHintJson?: string,
* httpDhtProxyRoutesJson?: string,
* udxLossEstimateBps?: number,
* tcpFallbackReason?: string,
* hyperdbIndexLagHintJson?: string,
* stagingDrainDeadlineMs?: number,
* peerFirewallSaturationJson?: string,
* notReadyReason?: string,
* udxRttMsEstimate?: number,
* relayCircuitId?: string,
* hyperbee2ReadOnlyHintJson?: string,
* stagingQuarantineJson?: string,
* peerFirewallTransportJson?: string,
* pearRuntimeChannel?: string,
* pearUpdaterDelegateClass?: string,
* seederPearApplingId?: string,
* handshakeTokenBucketV3Json?: string,
* peerFirewallStatsV4Json?: string,
* stagingSlotWave9Json?: string,
* compactPingEncodingHint?: string,
* pearStageHintJson?: string,
* updaterChannelMatrixJson?: string,
* applingBundlePointerJson?: string,
* driveResolvePolicyJson?: string,
* bundleIdFingerprintJson?: string,
* hyperdbMigrationHintJson?: string,
* sidecarBundleIndexV2Json?: string,
* pearMessageQueueSketchJson?: string,
* runtimeBootstrapEtagJson?: string,
* forceUpdateGuardJson?: string,
* gracedownWindowJson?: string,
* trybootSlotJson?: string,
* hotmodsAllowlistJson?: string,
* prefetcherBudgetJson?: string,
* opstreamBackpressureJson?: string,
* multisigLinkPointerJson?: string,
* mdRenderCapsJson?: string,
* bundlebeeCliStageV2Json?: string,
* seedManifestDiffV2Json?: string,
* peerHandshakeLatencyBudgetJson?: string,
* mirrorDriveCompactionV4Json?: string,
* readyGuardV3Json?: string,
* blindRelayCircuitV2Json?: string,
* httpDhtProxyRoutesV2Json?: string,
* pearBundleTier?: string,
* autobaseDiscoveryHintJson?: string,
* handshakeTokenBucketV4Json?: string,
* peerFirewallStatsV5Json?: string,
* stagingSlotWave10Json?: string,
* compactPingV4Json?: string,
* seederPearRuntimeBareFingerprint?: string,
* pearDoctorHintJson?: string,
* pearInfoSketchJson?: string,
* pearInspectCapsJson?: string,
* pearDumpBudgetJson?: string,
* pearResetGuardJson?: string,
* pearRestartWindowJson?: string,
* pearRunFlagsJson?: string,
* pearBundleManifestSliceJson?: string,
* pearPackLayoutHintJson?: string,
* pearSeedTopologyJson?: string,
* pearStateSnapshotJson?: string,
* pearStampPointerJson?: string,
* pearShakeLatencyJson?: string,
* pearCrasherClassJson?: string,
* pearErrorsRateHintJson?: string,
* pearBridgeHealthJson?: string,
* pearLinkMatrixJson?: string,
* pearPipeBackpressureJson?: string,
* pearOpwaitBudgetJson?: string,
* pearTerminalCapsJson?: string,
* readyGuardV4Json?: string,
* mirrorDriveCompactionV5Json?: string,
* blindRelayCircuitV3Json?: string,
* hypercoreReplicateBudgetV2Json?: string,
* driveVersionGraphJson?: string,
* protomuxBackpressureV3Json?: string,
* pearRuntimeMatrixJson?: string,
* bundlePreloadHintJson?: string,
* autopassRotationHintJson?: string,
* hrpcMethodAllowlistJson?: string,
* sidecarResourceCapJson?: string,
* gitLfsBudgetJson?: string,
* netQosClassJson?: string,
* storageTierHintJson?: string,
* indexerCatchupJson?: string,
* multisigQuorumHintJson?: string,
* relayGeoHintJson?: string,
* compactPingV5Json?: string,
* stagingSlotV8Json?: string,
* peerFirewallStatsV6Json?: string,
* httpDhtProxyRoutesV3Json?: string,
* readyGuardV5Json?: string,
* mirrorDriveCompactionV6Json?: string
* }} [opts]
*/
export function setupSeedChannel(mux, localRAM, replicateDrive, opts = {}) {
const bareOsChatMuxOn =
opts.enableBareOsChatChannel !== undefined &&
opts.enableBareOsChatChannel !== null
? Boolean(opts.enableBareOsChatChannel)
: bareOsProtMuxChatChannelEnabled(
typeof globalThis.process !== 'undefined' &&
globalThis.process &&
globalThis.process.env
? /** @type {Record<string, string | undefined>} */ (globalThis.process.env)
: undefined
)
const manifestPaths = Array.isArray(opts.manifestPaths) ? opts.manifestPaths : []
const mbrKeysHex = Array.isArray(opts.mbrKeysHex)
? opts.mbrKeysHex.map((h) => String(h).trim().toLowerCase()).filter(Boolean)
: []
const attestationRaw = String(opts.attestationJson ?? '').trim()
const snapshotHintsRaw = String(opts.snapshotHintsJson ?? '').trim()
const peerFirewallStatsRaw = String(opts.peerFirewallStatsJson ?? '').trim()
const stagingActiveSlot = String(
opts.stagingActiveSlot ?? opts.stagingSlot ?? 'a'
)
.trim()
.toLowerCase() || 'a'
const stagingPendingSlot = String(
opts.stagingPendingSlot ?? opts.stagingPending ?? ''
).trim()
const stagingPreviousSlot = String(opts.stagingPreviousSlot ?? '')
.trim()
.toLowerCase()
const stagingCanarySlot = String(opts.stagingCanarySlot ?? '')
.trim()
.toLowerCase()
const replicationPlanId = String(opts.replicationPlanId ?? '')
.trim()
.slice(0, 128)
const replicationPlanNote = String(opts.replicationPlanNote ?? '')
.trim()
.slice(0, 512)
const imageTipId = String(opts.imageTipId ?? '')
.trim()
.slice(0, 256)
const dhtBootstrapAddrs = Array.isArray(opts.dhtBootstrapAddrs)
? opts.dhtBootstrapAddrs
.map((a) => String(a).trim())
.filter(Boolean)
.slice(0, 32)
: []
const mirrorCompactionHint = String(opts.mirrorCompactionHint ?? '')
.trim()
.slice(0, 512)
const replicationPriorityClass = String(opts.replicationPriorityClass ?? '')
.trim()
.slice(0, 64)
const corestoreSnapshotTag = String(opts.corestoreSnapshotTag ?? '')
.trim()
.slice(0, 128)
const queuedPeerCount =
typeof opts.queuedPeerCount === 'number' && opts.queuedPeerCount >= 0
? Math.min(1e9, Math.floor(opts.queuedPeerCount))
: null
const mbrKeyLabels = Array.isArray(opts.mbrKeyLabels)
? opts.mbrKeyLabels.map((s) => String(s).trim().slice(0, 64)).slice(0, 32)
: []
const relayVsDirectNote = String(opts.relayVsDirectNote ?? '')
.trim()
.slice(0, 256)
const seederHostBundleId = String(opts.seederHostBundleId ?? '')
.trim()
.slice(0, 256)
const seederPearRuntimeFingerprint = String(
opts.seederPearRuntimeFingerprint ?? ''
)
.trim()
.slice(0, 256)
const booterPackageVersionHint = String(opts.booterPackageVersionHint ?? '')
.trim()
.slice(0, 64)
const notReadyReason = String(opts.notReadyReason ?? '')
.trim()
.slice(0, 128)
const udxRttMsEstimate =
typeof opts.udxRttMsEstimate === 'number' && opts.udxRttMsEstimate >= 0
? Math.min(1e9, Math.floor(opts.udxRttMsEstimate))
: null
const relayCircuitId = String(opts.relayCircuitId ?? '')
.trim()
.slice(0, 128)
const protomuxCapabilityAdHex = String(opts.protomuxCapabilityAdHex ?? '')
.trim()
.slice(0, 2048)
const udxLossEstimateBps =
typeof opts.udxLossEstimateBps === 'number' && opts.udxLossEstimateBps >= 0
? Math.min(1e9, Math.floor(opts.udxLossEstimateBps))
: null
const tcpFallbackReason = String(opts.tcpFallbackReason ?? '')
.trim()
.slice(0, 128)
const stagingDrainDeadlineMs =
typeof opts.stagingDrainDeadlineMs === 'number' &&
opts.stagingDrainDeadlineMs >= 0
? Math.min(1e12, Math.floor(opts.stagingDrainDeadlineMs))
: null
const pearRuntimeChannel = String(opts.pearRuntimeChannel ?? '')
.trim()
.slice(0, 128)
const pearUpdaterDelegateClass = String(opts.pearUpdaterDelegateClass ?? '')
.trim()
.slice(0, 128)
const seederPearApplingId = String(opts.seederPearApplingId ?? '')
.trim()
.slice(0, 256)
const seederPearRuntimeBareFingerprint = String(
opts.seederPearRuntimeBareFingerprint ?? ''
)
.trim()
.slice(0, 256)
const pearBundleTier = String(opts.pearBundleTier ?? '')
.trim()
.slice(0, 64)
const compactPingEncodingHint = String(opts.compactPingEncodingHint ?? '')
.trim()
.slice(0, 64)
function parseOptJson(raw) {
const s = String(raw ?? '').trim()
if (!s) return null
try {
const o = JSON.parse(s)
return o && typeof o === 'object' ? o : null
} catch {
return { error: 'invalid_json' }
}
}
const searchMax =
typeof opts.searchMaxMatches === 'number' && opts.searchMaxMatches > 0
? Math.min(opts.searchMaxMatches, 2000)
: 500
const chan = mux.createChannel({ protocol: PROTOCOL_NAME })
chan.addMessage({
encoding: c.uint32,
onmessage(index) {
const data = localRAM.get(index)
if (data) chan.messages[1].send({ index, data })
}
})
chan.addMessage({
encoding: msgDataEncoding
})
chan.addMessage({ encoding: c.buffer })
chan.addMessage({
encoding: msgSearchReqEncoding,
onmessage(m) {
const q = (m.query || '').trim().toLowerCase()
/** @type {string[]} */
let matches = []
if (!q) {
matches = manifestPaths.slice(0, searchMax)
} else {
matches = manifestPaths
.filter((p) => p.toLowerCase().includes(q))
.slice(0, searchMax)
}
chan.messages[4].send({ id: m.id, matches })
}
})
chan.addMessage({
encoding: msgSearchResEncoding
})
chan.addMessage({
encoding: msgRpcReqEncoding,
onmessage(m) {
if (m.module !== 'bare_os') {
chan.messages[6].send({
id: m.id,
success: false,
result: '',
error:
m.module == null || m.module === ''
? 'bare_os.rpc_missing_module'
: 'bare_os.rpc_wrong_module'
})
return
}
{
const meth = String(m.method ?? '').trim()
if (!BARE_OS_SEED_RPC_METHOD_SHORT_NAME_SET.has(meth)) {
chan.messages[6].send({
id: m.id,
success: false,
result: '',
error: 'bare_os.rpc_unknown_method'
})
return
}
}
if (m.module === 'bare_os' && m.method === 'version') {
chan.messages[6].send({
id: m.id,
success: true,
result: JSON.stringify({
protocol: PROTOCOL_NAME,
seederRpc: 'bare_os.version'
}),
error: ''
})
return
}
if (m.module === 'bare_os' && m.method === 'health') {
chan.messages[6].send({
id: m.id,
success: true,
result: JSON.stringify({
ok: true,
protocol: PROTOCOL_NAME,
role: 'seeder'
}),
error: ''
})
return
}
if (m.module === 'bare_os' && m.method === 'kernel_info') {
chan.messages[6].send({
id: m.id,
success: true,
result: JSON.stringify({
protocol: PROTOCOL_NAME,
rpc: BARE_OS_SEED_RPC_METHODS,
note: 'Kernel and image semver are resolved at boot on the booter; this channel is seeder-local.',
channelFingerprintNote:
'pear-runtime channel vs bare-runtime fingerprint coupling is operator-defined; non-secret hints only.',
hostBundleId: seederHostBundleId || undefined,
pearRuntimeFingerprint:
seederPearRuntimeFingerprint || undefined,
booterPackageVersion: booterPackageVersionHint || undefined,
pearApplingId: seederPearApplingId || undefined,
pearRuntimeBareFingerprint:
seederPearRuntimeBareFingerprint || undefined
}),
error: ''
})
return
}
if (m.module === 'bare_os' && m.method === 'capabilities') {
/** @type {Record<string, unknown>} */
const capBody = {
doc: BARE_OS_KERNEL_FEATURE_BITS_DOC,
featureBitsDoc: BARE_OS_KERNEL_FEATURE_BITS_DOC,
kernelCapabilityWireVersion: BARE_OS_KERNEL_CAPABILITY_WIRE_VERSION,
[BARE_OS_KERNEL_CAPABILITY_WORDS_JSON_KEY]: buildKernelCapabilityWordsObject(
BARE_OS_KERNEL_FEATURES_STOCK_WORD_PRIMARY >>> 0,
BARE_OS_KERNEL_FEATURES_STOCK_WORD_EXTENDED_SEEDING_PLATFORM >>> 0,
BARE_OS_KERNEL_FEATURES_STOCK_WORD_RLIMITS_DELEGATES_SHELL >>> 0,
BARE_OS_KERNEL_FEATURES_STOCK_WORD_OFFLINE_NET_EXTENSIONS >>> 0,
BARE_OS_KERNEL_FEATURES_STOCK_WORD_HOST_TRANSPORT_DELEGATES >>> 0,
BARE_OS_KERNEL_FEATURES_STOCK_WORD_REPLICATION_OPERATOR_SURFACE >>> 0,
BARE_OS_KERNEL_FEATURES_STOCK_WORD_PEAR_CORESTORE_HRPC >>> 0,
BARE_OS_KERNEL_FEATURES_STOCK_WORD_BARE_RUNTIME_PROTO_MUX >>> 0,
BARE_OS_KERNEL_FEATURES_STOCK_WORD_BARE_MODULE_CRYPTO_STAGING >>> 0,
BARE_OS_KERNEL_FEATURES_STOCK_WORD_PEAR_INSPECT_LOGGER_TLS >>> 0,
BARE_OS_KERNEL_FEATURES_STOCK_WORD_HYPERCORE_PACK_HRPC_LIFECYCLE >>> 0
),
protocolPackageVersion: BARE_OS_PROTOCOL_PACKAGE_VERSION,
booterPackageVersion: booterPackageVersionHint || undefined,
role: 'seeder',
protocol: PROTOCOL_NAME
}
if (bareOsChatMuxOn) {
capBody.chatChannel = {
name: PROTOCOL_CHAT_CHANNEL_NAME,
schemaVersion: BARE_OS_CHAT_WIRE_SCHEMA_VERSION,
note: 'Informational; Protomux bare-os-chat-v1 paired when enabled.'
}
}
if (imageTipId) capBody.imageTipId = imageTipId
chan.messages[6].send({
id: m.id,
success: true,
result: JSON.stringify(capBody),
error: ''
})
return
}
if (m.module === 'bare_os' && m.method === 'replication_status') {
/** @type {Record<string, unknown>} */
const rs = {
role: 'seeder',
protocol: PROTOCOL_NAME,
manifestPathCount: manifestPaths.length,
localRamBlockCount: localRAM.size,
atMs: Date.now()
}
const tb = parseOptJson(opts.handshakeTokenBucketJson)
if (tb) rs.handshakeTokenBucket = tb
if (replicationPriorityClass) rs.priorityClass = replicationPriorityClass
const ipv6c = parseOptJson(opts.replicationIpv6ScopeCountsJson)
if (ipv6c) rs.ipv6ScopeCounts = ipv6c
if (corestoreSnapshotTag) rs.corestoreSnapshotTag = corestoreSnapshotTag
if (queuedPeerCount != null) rs.queuedPeerCount = queuedPeerCount
if (relayVsDirectNote) rs.relayVsDirectNote = relayVsDirectNote
if (notReadyReason) rs.notReadyReason = notReadyReason
if (udxRttMsEstimate != null) rs.udxRttMsEstimate = udxRttMsEstimate
if (relayCircuitId) rs.relayCircuitId = relayCircuitId
if (udxLossEstimateBps != null) rs.udxLossEstimateBps = udxLossEstimateBps
if (tcpFallbackReason) rs.tcpFallbackReason = tcpFallbackReason
const lag = parseOptJson(opts.hyperdbIndexLagHintJson)
if (lag) rs.hyperdbIndexLagHint = lag
const hb2 = parseOptJson(opts.hyperbee2ReadOnlyHintJson)
if (hb2) rs.hyperbee2ReadOnlyHint = hb2
if (pearRuntimeChannel) rs.pearRuntimeChannel = pearRuntimeChannel
if (pearUpdaterDelegateClass)
rs.pearUpdaterDelegate = pearUpdaterDelegateClass
const tb3 = parseOptJson(opts.handshakeTokenBucketV3Json)
if (tb3) rs.handshakeTokenBucketV3 = tb3
if (pearBundleTier) rs.pearBundleTier = pearBundleTier
const abdisc = parseOptJson(opts.autobaseDiscoveryHintJson)
if (abdisc) rs.autobaseDiscoveryHint = abdisc
const tb4 = parseOptJson(opts.handshakeTokenBucketV4Json)
if (tb4) rs.handshakeTokenBucketV4 = tb4
chan.messages[6].send({
id: m.id,
success: true,
result: JSON.stringify(rs),
error: ''
})
return
}
if (m.module === 'bare_os' && m.method === 'gossip') {
chan.messages[6].send({
id: m.id,
success: true,
result: JSON.stringify({
role: 'seeder',
protocol: PROTOCOL_NAME,
manifestPathCount: manifestPaths.length,
atMs: Date.now()
}),
error: ''
})
return
}
if (m.module === 'bare_os' && m.method === 'manifest_hints') {
const maxSample = 48
const samplePaths = manifestPaths.slice(0, maxSample)
chan.messages[6].send({
id: m.id,
success: true,
result: JSON.stringify({
role: 'seeder',
protocol: PROTOCOL_NAME,
totalPaths: manifestPaths.length,
samplePaths,
truncated: manifestPaths.length > samplePaths.length,
atMs: Date.now()
}),
error: ''
})
return
}
if (m.module === 'bare_os' && m.method === 'peer_health') {
chan.messages[6].send({
id: m.id,
success: true,
result: JSON.stringify({
ok: true,
role: 'seeder',
protocol: PROTOCOL_NAME,
manifestPathCount: manifestPaths.length,
localRamBlockCount: localRAM.size,
atMs: Date.now()
}),
error: ''
})
return
}
if (m.module === 'bare_os' && m.method === 'staging_slot') {
chan.messages[6].send({
id: m.id,
success: true,
result: JSON.stringify({
role: 'seeder',
protocol: PROTOCOL_NAME,
schema: 7,
activeSlot: stagingActiveSlot,
pendingSlot: stagingPendingSlot || null,
previousSlot: stagingPreviousSlot || null,
canarySlot: stagingCanarySlot || null,
drainDeadlineMs: stagingDrainDeadlineMs,
quarantine: parseOptJson(opts.stagingQuarantineJson),
wave9: parseOptJson(opts.stagingSlotWave9Json),
wave10: parseOptJson(opts.stagingSlotWave10Json),
rollbackHint:
'pending slot is rollback candidate when switching A/B; verify image before activate',
tripleSlotNote:
'canarySlot is optional third slot metadata for staged rollouts (operator-defined).',
schema6Note:
'schema 6 adds optional wave9 operator blob; schema 5 fields remain stable.',
schema7Note:
'schema 7 adds optional wave10 operator blob; prior fields remain stable.',
atMs: Date.now()
}),
error: ''
})
return
}
if (m.module === 'bare_os' && m.method === 'replication_queue') {
let coreLength = 0
try {
const d = opts.drive
if (d && d.core && typeof d.core.length === 'number')
coreLength = d.core.length
} catch {
/* ignore */
}
const depthHint =
typeof opts.replicationQueueDepthHint === 'number' &&
opts.replicationQueueDepthHint >= 0
? Math.floor(opts.replicationQueueDepthHint)
: manifestPaths.length
let snapshotNote = ''
const snapRaw = String(opts.replicationSnapshotNoteJson ?? '').trim()
if (snapRaw) {
try {
const o = JSON.parse(snapRaw)
snapshotNote =
o && typeof o === 'object' && typeof o.note === 'string'
? o.note.slice(0, 256)
: 'snapshot-hint-json'
} catch {
snapshotNote = 'invalid replicationSnapshotNoteJson'
}
}
chan.messages[6].send({
id: m.id,
success: true,
result: JSON.stringify({
role: 'seeder',
protocol: PROTOCOL_NAME,
manifestPathCount: manifestPaths.length,
localRamBlockCount: localRAM.size,
hypercoreLengthHint: coreLength,
queueDepthEstimate: depthHint,
snapshotWorkflowNote:
snapshotNote ||
'Align long replication with corestore-snapshot-style cutover; guest does not verify crypto.',
note: 'hypercoreLengthHint and queueDepthEstimate are seeder-local hints only.',
atMs: Date.now()
}),
error: ''
})
return
}
if (m.module === 'bare_os' && m.method === 'capability_attestation') {
/** @type {Record<string, unknown>} */
let payload = { format: 'bare-os-seeder-none' }
if (attestationRaw) {
try {
payload = {
format: 'bare-os-seeder-json-v1',
data: JSON.parse(attestationRaw)
}
} catch {
payload = {
format: 'bare-os-seeder-json-v1',
error: 'invalid JSON in seeder attestation'
}
}
}
chan.messages[6].send({
id: m.id,
success: true,
result: JSON.stringify({
role: 'seeder',
protocol: PROTOCOL_NAME,
attestation: payload,
atMs: Date.now()
}),
error: ''
})
return
}
if (m.module === 'bare_os' && m.method === 'mbr_layout') {
const labels = mbrKeyLabels.length
? mbrKeyLabels.slice(0, mbrKeysHex.length)
: []
chan.messages[6].send({
id: m.id,
success: true,
result: JSON.stringify({
role: 'seeder',
protocol: PROTOCOL_NAME,
primaryHex: mbrKeysHex[0] || null,
failoverHexes: mbrKeysHex.slice(1),
keyCount: mbrKeysHex.length,
keyLabels: labels.length ? labels : undefined,
regionLabels: labels.length ? labels : undefined,
activeIndex: 0,
atMs: Date.now()
}),
error: ''
})
return
}
if (m.module === 'bare_os' && m.method === 'snapshot_hints') {
/** @type {Record<string, unknown>} */
let payload = { slots: [], note: 'corestore-snapshot-style hints (seeder-local)' }
if (snapshotHintsRaw) {
try {
const o = JSON.parse(snapshotHintsRaw)
if (o && typeof o === 'object') payload = /** @type {Record<string, unknown>} */ (o)
} catch {
payload = { error: 'invalid snapshotHintsJson on seeder' }
}
}
chan.messages[6].send({
id: m.id,
success: true,
result: JSON.stringify({
role: 'seeder',
protocol: PROTOCOL_NAME,
hints: payload,
atMs: Date.now()
}),
error: ''
})
return
}
if (m.module === 'bare_os' && m.method === 'peer_firewall_stats') {
/** Default counter fields mirrored in `/proc/bare_os/net_summary.json` scalar totals + `peerFirewallStats` object for baretop. */
/** @type {Record<string, unknown>} */
let stats = {
acceptedSessionCount: 0,
rejectedSessionCount: 0,
inboundSessionCount: 0,
outboundSessionCount: 0,
note: 'bounded operator counts only; no raw keys'
}
if (peerFirewallStatsRaw) {
try {
const o = JSON.parse(peerFirewallStatsRaw)
if (o && typeof o === 'object')
stats = { ...stats, .../** @type {Record<string, unknown>} */ (o) }
} catch {
stats = { ...stats, error: 'invalid peerFirewallStatsJson' }
}
}
const tj = parseOptJson(opts.peerFirewallTransportJson)
if (tj) stats.transportBreakdown = tj
const sat = parseOptJson(opts.peerFirewallSaturationJson)
if (sat) stats.saturationClass = sat
const fw4 = parseOptJson(opts.peerFirewallStatsV4Json)
if (fw4) stats.wave9 = fw4
const fw5 = parseOptJson(opts.peerFirewallStatsV5Json)
if (fw5) stats.wave10 = fw5
chan.messages[6].send({
id: m.id,
success: true,
result: JSON.stringify({
role: 'seeder',
protocol: PROTOCOL_NAME,
firewall: stats,
firewallSchema: 5,
atMs: Date.now()
}),
error: ''
})
return
}
if (m.module === 'bare_os' && m.method === 'replication_plan') {
chan.messages[6].send({
id: m.id,
success: true,
result: JSON.stringify({
role: 'seeder',
protocol: PROTOCOL_NAME,
planId: replicationPlanId || null,
planNote:
replicationPlanNote ||
'Advisory replication plan label; guest does not enforce crypto.',
atMs: Date.now()
}),
error: ''
})
return
}
if (m.module === 'bare_os' && m.method === 'dht_bootstrap_hint') {
chan.messages[6].send({
id: m.id,
success: true,
result: JSON.stringify({
role: 'seeder',
protocol: PROTOCOL_NAME,
bootstrapAddrs: dhtBootstrapAddrs,
atMs: Date.now()
}),
error: ''
})
return
}
if (m.module === 'bare_os' && m.method === 'snapshot_chain') {
const chain = parseOptJson(opts.snapshotChainJson)
chan.messages[6].send({
id: m.id,
success: true,
result: JSON.stringify({
role: 'seeder',
protocol: PROTOCOL_NAME,
chain: chain || { note: 'no snapshotChainJson on seeder' },
atMs: Date.now()
}),
error: ''
})
return
}
if (m.module === 'bare_os' && m.method === 'mirror_compaction_hint') {
chan.messages[6].send({
id: m.id,
success: true,
result: JSON.stringify({
role: 'seeder',
protocol: PROTOCOL_NAME,
hint:
mirrorCompactionHint ||
'Operator may compact mirror-drive after snapshot cutover; guest does not verify.',
atMs: Date.now()
}),
error: ''
})
return
}
if (m.module === 'bare_os' && m.method === 'updater_state') {
const st = parseOptJson(opts.updaterStateJson)
chan.messages[6].send({
id: m.id,
success: true,
result: JSON.stringify({
role: 'seeder',
protocol: PROTOCOL_NAME,
updater:
st || {
note: 'pear-runtime-updater-shaped JSON optional on seeder'
},
atMs: Date.now()
}),
error: ''
})
return
}
if (m.module === 'bare_os' && m.method === 'blind_peer_topology_v2') {
const topo = parseOptJson(opts.blindPeerTopologyV2Json)
chan.messages[6].send({
id: m.id,
success: true,
result: JSON.stringify({
role: 'seeder',
protocol: PROTOCOL_NAME,
topology:
topo || {
note: 'blind-peer / blind-peering topology sketch (bounded)'
},
atMs: Date.now()
}),
error: ''
})
return
}
if (m.module === 'bare_os' && m.method === 'compact_ping') {
const perf = globalThis.performance
const tUs =
perf && typeof perf.now === 'function'
? Math.floor(perf.now() * 1000)
: Date.now() * 1000
const v4 = parseOptJson(opts.compactPingV4Json)
chan.messages[6].send({
id: m.id,
success: true,
result: JSON.stringify({
role: 'seeder',
pong: true,
tUs,
protocol: PROTOCOL_NAME,
schema: 4,
encodingHint: compactPingEncodingHint || undefined,
wave10: v4 || undefined
}),
error: ''
})
return
}
if (m.module === 'bare_os' && m.method === 'corestore_stats') {
const st = parseOptJson(opts.corestoreStatsJson)
chan.messages[6].send({
id: m.id,
success: true,
result: JSON.stringify({
role: 'seeder',
protocol: PROTOCOL_NAME,
stats:
st || {
note: 'bounded vault/corestore hint JSON; guest does not verify'
},
atMs: Date.now()
}),
error: ''
})
return
}
if (m.module === 'bare_os' && m.method === 'snapshot_manifest_slice') {
const sl = parseOptJson(opts.snapshotManifestSliceJson)
chan.messages[6].send({
id: m.id,
success: true,
result: JSON.stringify({
role: 'seeder',
protocol: PROTOCOL_NAME,
slice:
sl || {
paths: [],
tags: [],
note: 'capped snapshot paths/tags only; no secret hashes'
},
atMs: Date.now()
}),
error: ''
})
return
}
if (m.module === 'bare_os' && m.method === 'mirror_drive_hint_v2') {
const h = parseOptJson(opts.mirrorDriveHintV2Json)
chan.messages[6].send({
id: m.id,
success: true,
result: JSON.stringify({
role: 'seeder',
protocol: PROTOCOL_NAME,
hint:
h || {
role: 'unknown',
keyLabels: [],
note: 'mirror-drive structured hint (operator)'
},
atMs: Date.now()
}),
error: ''
})
return
}
if (m.module === 'bare_os' && m.method === 'hrpc_registry_summary') {
const h = parseOptJson(opts.hrpcRegistrySummaryJson)
chan.messages[6].send({
id: m.id,
success: true,
result: JSON.stringify({
role: 'seeder',
protocol: PROTOCOL_NAME,
services:
h || {
logicalNames: [],
note: 'audit-only hrpc service name list; host may expose subset'
},
atMs: Date.now()
}),
error: ''
})
return
}
if (m.module === 'bare_os' && m.method === 'protomux_capability_ad') {
chan.messages[6].send({
id: m.id,
success: true,
result: JSON.stringify({
role: 'seeder',
protocol: PROTOCOL_NAME,
adHex: protomuxCapabilityAdHex || null,
note: 'optional hex-capped mux ad; see FEATURE7_COMPACT_MUX_ADVERT',
atMs: Date.now()
}),
error: ''
})
return
}
if (m.module === 'bare_os' && m.method === 'dht_address_book') {
const b = parseOptJson(opts.dhtAddressBookJson)
chan.messages[6].send({
id: m.id,
success: true,
result: JSON.stringify({
role: 'seeder',
protocol: PROTOCOL_NAME,
entries:
b || {
multiAddrs: [],
note: 'hyperdht-address-style bounded entries'
},
atMs: Date.now()
}),
error: ''
})
return
}
if (m.module === 'bare_os' && m.method === 'replication_throttle_hint') {
const th = parseOptJson(opts.replicationThrottleHintJson)
chan.messages[6].send({
id: m.id,
success: true,
result: JSON.stringify({
role: 'seeder',
protocol: PROTOCOL_NAME,
throttle:
th || { note: 'operator advisory pacing JSON for guest-side hints' },
atMs: Date.now()
}),
error: ''
})
return
}
if (m.module === 'bare_os' && m.method === 'bundlebee_stage') {
const bb = parseOptJson(opts.bundlebeeStageJson)
chan.messages[6].send({
id: m.id,
success: true,
result: JSON.stringify({
role: 'seeder',
protocol: PROTOCOL_NAME,
stage:
bb || {
note: 'non-secret bundlebee staging channel hint (doc tie-in)'
},
atMs: Date.now()
}),
error: ''
})
return
}
if (m.module === 'bare_os' && m.method === 'http_dht_proxy_hint') {
const px = parseOptJson(opts.httpDhtProxyHintJson)
chan.messages[6].send({
id: m.id,
success: true,
result: JSON.stringify({
role: 'seeder',
protocol: PROTOCOL_NAME,
httpDhtProxy:
px || {
note: 'DHT HTTP proxy hint RPC; non-secret operator JSON only'
},
atMs: Date.now()
}),
error: ''
})
return
}
if (m.module === 'bare_os' && m.method === 'protomux_rpc_pool_hint') {
const h = parseOptJson(opts.protomuxRpcPoolHintJson)
chan.messages[6].send({
id: m.id,
success: true,
result: JSON.stringify({
role: 'seeder',
protocol: PROTOCOL_NAME,
pool:
h || {
note: 'protomux-rpc-client-pool depth/idle hint (bounded JSON)'
},
atMs: Date.now()
}),
error: ''
})
return
}
if (m.module === 'bare_os' && m.method === 'hyperblob_store_hint') {
const h = parseOptJson(opts.hyperblobStoreHintJson)
chan.messages[6].send({
id: m.id,
success: true,
result: JSON.stringify({
role: 'seeder',
protocol: PROTOCOL_NAME,
store:
h || {
note: 'hyperblobs-shaped non-secret store id / role enum'
},
atMs: Date.now()
}),
error: ''
})
return
}
if (m.module === 'bare_os' && m.method === 'signing_request_queue_hint') {
const h = parseOptJson(opts.signingRequestQueueHintJson)
chan.messages[6].send({
id: m.id,
success: true,
result: JSON.stringify({
role: 'seeder',
protocol: PROTOCOL_NAME,
queue:
h || {
note: 'hypercore-signing-request queue depth sketch; no payloads'
},
atMs: Date.now()
}),
error: ''
})
return
}
if (m.module === 'bare_os' && m.method === 'core_storage_layout_hint') {
const h = parseOptJson(opts.coreStorageLayoutHintJson)
chan.messages[6].send({
id: m.id,
success: true,
result: JSON.stringify({
role: 'seeder',
protocol: PROTOCOL_NAME,
layout:
h || {
note: 'hypercore-storage operator layout pointer JSON'
},
atMs: Date.now()
}),
error: ''
})
return
}
if (m.module === 'bare_os' && m.method === 'mirror_drive_compaction_v3') {
const h = parseOptJson(opts.mirrorDriveCompactionV3Json)
chan.messages[6].send({
id: m.id,
success: true,
result: JSON.stringify({
role: 'seeder',
protocol: PROTOCOL_NAME,
compaction:
h || {
phases: [],
note: 'extended mirror-drive compaction phase enum v3'
},
atMs: Date.now()
}),
error: ''
})
return
}
if (m.module === 'bare_os' && m.method === 'bundlebee_cli_stage') {
const h = parseOptJson(opts.bundlebeeCliStageJson)
chan.messages[6].send({
id: m.id,
success: true,
result: JSON.stringify({
role: 'seeder',
protocol: PROTOCOL_NAME,
cliStage:
h || { note: 'bundlebee-cli non-secret stage id pointer' },
atMs: Date.now()
}),
error: ''
})
return
}
if (m.module === 'bare_os' && m.method === 'ready_guard_v2') {
const h = parseOptJson(opts.readyGuardV2Json)
chan.messages[6].send({
id: m.id,
success: true,
result: JSON.stringify({
role: 'seeder',
protocol: PROTOCOL_NAME,
readyGuard:
h || {
matrix: [],
note: 'ready-guard v2 reason + subsystem enum (structured)'
},
atMs: Date.now()
}),
error: ''
})
return
}
if (m.module === 'bare_os' && m.method === 'blind_relay_circuit_hint') {
const h = parseOptJson(opts.blindRelayCircuitHintJson)
chan.messages[6].send({
id: m.id,
success: true,
result: JSON.stringify({
role: 'seeder',
protocol: PROTOCOL_NAME,
circuits:
h || {
note: 'blind-relay-service opaque circuit class counts'
},
atMs: Date.now()
}),
error: ''
})
return
}
if (m.module === 'bare_os' && m.method === 'http_dht_proxy_routes') {
const h = parseOptJson(opts.httpDhtProxyRoutesJson)
chan.messages[6].send({
id: m.id,
success: true,
result: JSON.stringify({
role: 'seeder',
protocol: PROTOCOL_NAME,
routes:
h || {
revision: 0,
note: 'http-dht-proxy route table revision (capped)'
},
atMs: Date.now()
}),
error: ''
})
return
}
/** @param {Record<string, unknown>} body */
function sendWave9Rpc(body) {
chan.messages[6].send({
id: m.id,
success: true,
result: JSON.stringify({
role: 'seeder',
protocol: PROTOCOL_NAME,
atMs: Date.now(),
...body
}),
error: ''
})
}
if (m.module === 'bare_os' && m.method === 'pear_stage_hint') {
const h = parseOptJson(opts.pearStageHintJson)
sendWave9Rpc({
pearStage: h || { note: 'pear-stage slot sketch (non-secret)' }
})
return
}
if (m.module === 'bare_os' && m.method === 'updater_channel_matrix') {
const h = parseOptJson(opts.updaterChannelMatrixJson)
sendWave9Rpc({
channels:
h || { note: 'pear-updater / pear-runtime-updater channel matrix' }
})
return
}
if (m.module === 'bare_os' && m.method === 'appling_bundle_pointer') {
const h = parseOptJson(opts.applingBundlePointerJson)
sendWave9Rpc({
appling: h || { note: 'pear-appling bundle pointer (capped)' }
})
return
}
if (m.module === 'bare_os' && m.method === 'drive_resolve_policy') {
const h = parseOptJson(opts.driveResolvePolicyJson)
sendWave9Rpc({
policy: h || { note: 'drive-resolve / bare-pack-drive policy blob' }
})
return
}
if (m.module === 'bare_os' && m.method === 'bundle_id_fingerprint') {
const h = parseOptJson(opts.bundleIdFingerprintJson)
sendWave9Rpc({
fingerprint: h || { note: 'bare-bundle-id fingerprint sketch' }
})
return
}
if (m.module === 'bare_os' && m.method === 'hyperdb_migration_hint') {
const h = parseOptJson(opts.hyperdbMigrationHintJson)
sendWave9Rpc({
migration: h || { note: 'pear-hyperdb migration hint (read-only)' }
})
return
}
if (m.module === 'bare_os' && m.method === 'sidecar_bundle_index_v2') {
const h = parseOptJson(opts.sidecarBundleIndexV2Json)
sendWave9Rpc({
sidecarIndexV2: h || { note: 'bare-sidecar-bundle index v2' }
})
return
}
if (m.module === 'bare_os' && m.method === 'pear_message_queue_sketch') {
const h = parseOptJson(opts.pearMessageQueueSketchJson)
sendWave9Rpc({
messageQueue: h || { note: 'pear-message queue depth sketch' }
})
return
}
if (m.module === 'bare_os' && m.method === 'runtime_bootstrap_etag') {
const h = parseOptJson(opts.runtimeBootstrapEtagJson)
sendWave9Rpc({
bootstrapEtag: h || { note: 'pear-runtime-bootstrap cache etag' }
})
return
}
if (m.module === 'bare_os' && m.method === 'force_update_guard') {
const h = parseOptJson(opts.forceUpdateGuardJson)
sendWave9Rpc({
guard: h || { note: 'pear-force-update guard class' }
})
return
}
if (m.module === 'bare_os' && m.method === 'gracedown_window') {
const h = parseOptJson(opts.gracedownWindowJson)
sendWave9Rpc({
gracedown: h || { note: 'pear-gracedown draining window' }
})
return
}
if (m.module === 'bare_os' && m.method === 'tryboot_slot') {
const h = parseOptJson(opts.trybootSlotJson)
sendWave9Rpc({
tryboot: h || { note: 'pear-tryboot canary slot sketch' }
})
return
}
if (m.module === 'bare_os' && m.method === 'hotmods_allowlist') {
const h = parseOptJson(opts.hotmodsAllowlistJson)
sendWave9Rpc({
hotmods: h || { note: 'pear-hotmods allowlist sketch' }
})
return
}
if (m.module === 'bare_os' && m.method === 'prefetcher_budget') {
const h = parseOptJson(opts.prefetcherBudgetJson)
sendWave9Rpc({
prefetcher: h || { note: 'pear-prefetcher budget hint' }
})
return
}
if (m.module === 'bare_os' && m.method === 'opstream_backpressure') {
const h = parseOptJson(opts.opstreamBackpressureJson)
sendWave9Rpc({
opstream: h || { note: 'pear-opstream backpressure class' }
})
return
}
if (m.module === 'bare_os' && m.method === 'multisig_link_pointer') {
const h = parseOptJson(opts.multisigLinkPointerJson)
sendWave9Rpc({
multisig: h || { note: 'pear-multisig-link pointer only' }
})
return
}
if (m.module === 'bare_os' && m.method === 'md_render_caps') {
const h = parseOptJson(opts.mdRenderCapsJson)
sendWave9Rpc({
md: h || { note: 'pear-md render capability flags' }
})
return
}
if (m.module === 'bare_os' && m.method === 'bundlebee_cli_stage_v2') {
const h = parseOptJson(opts.bundlebeeCliStageV2Json)
sendWave9Rpc({
cliStageV2: h || { note: 'bundlebee-cli stage v2 pointer' }
})
return
}
if (m.module === 'bare_os' && m.method === 'seed_manifest_diff_v2') {
const h = parseOptJson(opts.seedManifestDiffV2Json)
sendWave9Rpc({
manifestDiff: h || { note: 'structured manifest generation diff v2' }
})
return
}
if (m.module === 'bare_os' && m.method === 'peer_handshake_latency_budget') {
const h = parseOptJson(opts.peerHandshakeLatencyBudgetJson)
sendWave9Rpc({
latencyBudget: h || { note: 'seed handshake SLO budget (ms)' }
})
return
}
if (m.module === 'bare_os' && m.method === 'mirror_drive_compaction_v4') {
const h = parseOptJson(opts.mirrorDriveCompactionV4Json)
sendWave9Rpc({
compactionV4:
h || { phases: [], note: 'mirror-drive compaction enum v4' }
})
return
}
if (m.module === 'bare_os' && m.method === 'ready_guard_v3') {
const h = parseOptJson(opts.readyGuardV3Json)
sendWave9Rpc({
readyGuardV3:
h || { matrix: [], note: 'ready-guard v3 enum expansion' }
})
return
}
if (m.module === 'bare_os' && m.method === 'blind_relay_circuit_v2') {
const h = parseOptJson(opts.blindRelayCircuitV2Json)
sendWave9Rpc({
circuitsV2:
h || { note: 'blind-relay circuit v2 with reason codes' }
})
return
}
if (m.module === 'bare_os' && m.method === 'http_dht_proxy_routes_v2') {
const h = parseOptJson(opts.httpDhtProxyRoutesV2Json)
sendWave9Rpc({
routesV2:
h || { revision: 0, note: 'http-dht-proxy routes revision v2' }
})
return
}
if (m.module === 'bare_os' && m.method === 'pear_doctor_hint') {
const h = parseOptJson(opts.pearDoctorHintJson)
sendWave9Rpc({
doctor: h || { note: 'pear-doctor health class (non-secret)' }
})
return
}
if (m.module === 'bare_os' && m.method === 'pear_info_sketch') {
const h = parseOptJson(opts.pearInfoSketchJson)
sendWave9Rpc({
info: h || { note: 'pear-info build/runtime pointer' }
})
return
}
if (m.module === 'bare_os' && m.method === 'pear_inspect_caps') {
const h = parseOptJson(opts.pearInspectCapsJson)
sendWave9Rpc({
inspect: h || { note: 'pear-inspect capability flags' }
})
return
}
if (m.module === 'bare_os' && m.method === 'pear_dump_budget') {
const h = parseOptJson(opts.pearDumpBudgetJson)
sendWave9Rpc({
dumpBudget: h || { note: 'pear-dump export budget class' }
})
return
}
if (m.module === 'bare_os' && m.method === 'pear_reset_guard') {
const h = parseOptJson(opts.pearResetGuardJson)
sendWave9Rpc({
resetGuard: h || { note: 'pear-reset policy hint' }
})
return
}
if (m.module === 'bare_os' && m.method === 'pear_restart_window') {
const h = parseOptJson(opts.pearRestartWindowJson)
sendWave9Rpc({
restartWindow: h || { note: 'pear-restart backoff window' }
})
return
}
if (m.module === 'bare_os' && m.method === 'pear_run_flags') {
const h = parseOptJson(opts.pearRunFlagsJson)
sendWave9Rpc({
runFlags: h || { note: 'pear-run mode flags' }
})
return
}
if (m.module === 'bare_os' && m.method === 'pear_bundle_manifest_slice') {
const h = parseOptJson(opts.pearBundleManifestSliceJson)
sendWave9Rpc({
bundleSlice: h || { note: 'pear-bundle manifest sample' }
})
return
}
if (m.module === 'bare_os' && m.method === 'pear_pack_layout_hint') {
const h = parseOptJson(opts.pearPackLayoutHintJson)
sendWave9Rpc({
packLayout: h || { note: 'pear-pack layout operator hint' }
})
return
}
if (m.module === 'bare_os' && m.method === 'pear_seed_topology') {
const h = parseOptJson(opts.pearSeedTopologyJson)
sendWave9Rpc({
seedTopology: h || { note: 'pear-seed graph sketch' }
})
return
}
if (m.module === 'bare_os' && m.method === 'pear_state_snapshot') {
const h = parseOptJson(opts.pearStateSnapshotJson)
sendWave9Rpc({
stateSnapshot: h || { note: 'pear-state volatile class' }
})
return
}
if (m.module === 'bare_os' && m.method === 'pear_stamp_pointer') {
const h = parseOptJson(opts.pearStampPointerJson)
sendWave9Rpc({
stamp: h || { note: 'pear-stamp provenance pointer' }
})
return
}
if (m.module === 'bare_os' && m.method === 'pear_shake_latency') {
const h = parseOptJson(opts.pearShakeLatencyJson)
sendWave9Rpc({
shakeLatency: h || { note: 'pear-shake handshake latency sketch' }
})
return
}
if (m.module === 'bare_os' && m.method === 'pear_crasher_class') {
const h = parseOptJson(opts.pearCrasherClassJson)
sendWave9Rpc({
crasherClass: h || { note: 'pear-crasher reporting class (non-secret)' }
})
return
}
if (m.module === 'bare_os' && m.method === 'pear_errors_rate_hint') {
const h = parseOptJson(opts.pearErrorsRateHintJson)
sendWave9Rpc({
errorsRate: h || { note: 'pear-errors taxonomy rate bucket' }
})
return
}
if (m.module === 'bare_os' && m.method === 'pear_bridge_health') {
const h = parseOptJson(opts.pearBridgeHealthJson)
sendWave9Rpc({
bridgeHealth: h || { note: 'pear-bridge health sketch' }
})
return
}
if (m.module === 'bare_os' && m.method === 'pear_link_matrix') {
const h = parseOptJson(opts.pearLinkMatrixJson)
sendWave9Rpc({
linkMatrix: h || { note: 'pear-link alias matrix' }
})
return
}
if (m.module === 'bare_os' && m.method === 'pear_pipe_backpressure') {
const h = parseOptJson(opts.pearPipeBackpressureJson)
sendWave9Rpc({
pipeBackpressure: h || { note: 'pear-pipe backlog class' }
})
return
}
if (m.module === 'bare_os' && m.method === 'pear_opwait_budget') {
const h = parseOptJson(opts.pearOpwaitBudgetJson)
sendWave9Rpc({
opwaitBudget: h || { note: 'pear-opwait budget' }
})
return
}
if (m.module === 'bare_os' && m.method === 'pear_terminal_caps') {
const h = parseOptJson(opts.pearTerminalCapsJson)
sendWave9Rpc({
terminalCaps: h || { note: 'pear-terminal capability flags' }
})
return
}
if (m.module === 'bare_os' && m.method === 'ready_guard_v4') {
const h = parseOptJson(opts.readyGuardV4Json)
sendWave9Rpc({
readyGuardV4:
h || { matrix: [], note: 'ready-guard v4 enum expansion' }
})
return
}
if (m.module === 'bare_os' && m.method === 'mirror_drive_compaction_v5') {
const h = parseOptJson(opts.mirrorDriveCompactionV5Json)
sendWave9Rpc({
compactionV5:
h || { phases: [], note: 'mirror-drive compaction enum v5' }
})
return
}
if (m.module === 'bare_os' && m.method === 'blind_relay_circuit_v3') {
const h = parseOptJson(opts.blindRelayCircuitV3Json)
sendWave9Rpc({
circuitsV3:
h || { note: 'blind-relay circuit v3 reason codes' }
})
return
}
if (m.module === 'bare_os' && m.method === 'compact_ping_v4') {
const perf = globalThis.performance
const tUs =
perf && typeof perf.now === 'function'
? Math.floor(perf.now() * 1000)
: Date.now() * 1000
const v4 = parseOptJson(opts.compactPingV4Json)
chan.messages[6].send({
id: m.id,
success: true,
result: JSON.stringify({
role: 'seeder',
pong: true,
tUs,
protocol: PROTOCOL_NAME,
schema: 4,
variant: 'compact_ping_v4',
wave10: v4 || { note: 'compact ping v4 dedicated RPC' },
atMs: Date.now()
}),
error: ''
})
return
}
if (m.module === 'bare_os' && m.method === 'hypercore_replicate_budget_v2') {
const h = parseOptJson(opts.hypercoreReplicateBudgetV2Json)
sendWave9Rpc({
replicateBudgetV2: h || { note: 'hypercore replicate queue budget v2' }
})
return
}
if (m.module === 'bare_os' && m.method === 'drive_version_graph') {
const h = parseOptJson(opts.driveVersionGraphJson)
sendWave9Rpc({
driveVersionGraph: h || { note: 'multi-drive lineage sketch' }
})
return
}
if (m.module === 'bare_os' && m.method === 'protomux_backpressure_v3') {
const h = parseOptJson(opts.protomuxBackpressureV3Json)
sendWave9Rpc({
protomuxBackpressureV3: h || { note: 'protomux channel depth hints' }
})
return
}
if (m.module === 'bare_os' && m.method === 'pear_runtime_matrix') {
const h = parseOptJson(opts.pearRuntimeMatrixJson)
sendWave9Rpc({
pearRuntimeMatrix: h || { note: 'pear-runtime channel matrix' }
})
return
}
if (m.module === 'bare_os' && m.method === 'bundle_preload_hint') {
const h = parseOptJson(opts.bundlePreloadHintJson)
sendWave9Rpc({
bundlePreload: h || { note: 'cold-start bundle preload list' }
})
return
}
if (m.module === 'bare_os' && m.method === 'autopass_rotation_hint') {
const h = parseOptJson(opts.autopassRotationHintJson)
sendWave9Rpc({
autopassRotation: h || { note: 'autopass rotation schedule class' }
})
return
}
if (m.module === 'bare_os' && m.method === 'hrpc_method_allowlist') {
const h = parseOptJson(opts.hrpcMethodAllowlistJson)
sendWave9Rpc({
hrpcAllowlist: h || { note: 'hrpc method allowlist sketch' }
})
return
}
if (m.module === 'bare_os' && m.method === 'sidecar_resource_cap') {
const h = parseOptJson(opts.sidecarResourceCapJson)
sendWave9Rpc({
sidecarResourceCap: h || { note: 'sidecar CPU/mem class' }
})
return
}
if (m.module === 'bare_os' && m.method === 'git_lfs_budget') {
const h = parseOptJson(opts.gitLfsBudgetJson)
sendWave9Rpc({
gitLfsBudget: h || { note: 'git LFS bandwidth window' }
})
return
}
if (m.module === 'bare_os' && m.method === 'net_qos_class') {
const h = parseOptJson(opts.netQosClassJson)
sendWave9Rpc({
netQosClass: h || { note: 'egress QoS class hint' }
})
return
}
if (m.module === 'bare_os' && m.method === 'storage_tier_hint') {
const h = parseOptJson(opts.storageTierHintJson)
sendWave9Rpc({
storageTier: h || { note: 'hot/warm/cold storage pointer' }
})
return
}
if (m.module === 'bare_os' && m.method === 'indexer_catchup') {
const h = parseOptJson(opts.indexerCatchupJson)
sendWave9Rpc({
indexerCatchup: h || { note: 'Hyperbee/HyperDB lag budget' }
})
return
}
if (m.module === 'bare_os' && m.method === 'multisig_quorum_hint') {
const h = parseOptJson(opts.multisigQuorumHintJson)
sendWave9Rpc({
multisigQuorum: h || { note: 'multisig quorum policy pointer' }
})
return
}
if (m.module === 'bare_os' && m.method === 'relay_geo_hint') {
const h = parseOptJson(opts.relayGeoHintJson)
sendWave9Rpc({
relayGeo: h || { note: 'coarse relay region tags' }
})
return
}
if (m.module === 'bare_os' && m.method === 'compact_ping_v5') {
const perf = globalThis.performance
const tUs =
perf && typeof perf.now === 'function'
? Math.floor(perf.now() * 1000)
: Date.now() * 1000
const v5 = parseOptJson(opts.compactPingV5Json)
chan.messages[6].send({
id: m.id,
success: true,
result: JSON.stringify({
role: 'seeder',
pong: true,
tUs,
protocol: PROTOCOL_NAME,
schema: 5,
variant: 'compact_ping_v5',
wave11: v5 || { note: 'compact ping v5' },
atMs: Date.now()
}),
error: ''
})
return
}
if (m.module === 'bare_os' && m.method === 'staging_slot_v8') {
const h = parseOptJson(opts.stagingSlotV8Json)
sendWave9Rpc({
stagingSlotV8:
h || { schema: 8, note: 'staging slot word 11 triple' }
})
return
}
if (m.module === 'bare_os' && m.method === 'peer_firewall_stats_v6') {
const h = parseOptJson(opts.peerFirewallStatsV6Json)
sendWave9Rpc({
peerFirewallV6: h || { note: 'peer firewall stats v6' }
})
return
}
if (m.module === 'bare_os' && m.method === 'http_dht_proxy_routes_v3') {
const h = parseOptJson(opts.httpDhtProxyRoutesV3Json)
sendWave9Rpc({
routesV3: h || { revision: 0, note: 'http-dht-proxy routes v3' }
})
return
}
if (m.module === 'bare_os' && m.method === 'ready_guard_v5') {
const h = parseOptJson(opts.readyGuardV5Json)
sendWave9Rpc({
readyGuardV5:
h || { matrix: [], note: 'ready-guard v5 enum expansion' }
})
return
}
if (m.module === 'bare_os' && m.method === 'mirror_drive_compaction_v6') {
const h = parseOptJson(opts.mirrorDriveCompactionV6Json)
sendWave9Rpc({
compactionV6:
h || { phases: [], note: 'mirror-drive compaction enum v6' }
})
return
}
chan.messages[6].send({
id: m.id,
success: false,
result: '',
error: 'bare_os.rpc_internal_unreachable'
})
}
})
chan.addMessage({
encoding: msgRpcResEncoding
})
const appChOn =
opts.enableBareOsAppChannel === true ||
(typeof globalThis.process !== 'undefined' &&
globalThis.process &&
globalThis.process.env &&
(globalThis.process.env.BARE_OS_PROTOMUX_APP_CHANNEL === '1' ||
globalThis.process.env.BARE_OS_PROTOMUX_APP_CHANNEL === 'true'))
const stream = mux && typeof mux === 'object' ? mux.stream : null
const canCork =
stream &&
typeof stream.cork === 'function' &&
typeof stream.uncork === 'function'
if (canCork) stream.cork()
try {
chan.open()
const bitfield = b4a.alloc(250)
bitfield[0] |= 1
chan.messages[2].send(bitfield)
replicateDrive(mux.stream)
if (appChOn) {
mux.pair({ protocol: PROTOCOL_APP_CHANNEL_NAME }, (achan) => {
achan.addMessage({
encoding: c.buffer,
onmessage: () => {}
})
achan.open()
})
}
} finally {
if (canCork) stream.uncork()
}
if (bareOsChatMuxOn) {
setupBareOsChatChannel(mux, {})
}
}