Files
bare-operating-system/packages/bare-os-booter/lib/proc/bare-os-proc-pear-corestore-hrpc.js
T
2026-08-18 18:11:28 -04:00

166 lines
5.4 KiB
JavaScript

import {
bareOsProcBlindPeerRelayHintsExposed,
bareOsProcBlindPeerRelayHintsMinimal
} from './bare-os-proc-blind-peer-relay-gate.js'
/**
* Capability word 7 optional `/proc/bare_os/*.json` payloads (env-injected; bounded, non-secret).
* @param {string} id
* @param {Record<string, string>} env
* @param {{
* swarm?: Record<string, unknown> | null
* protomuxWireShape?: Record<string, unknown> | null
* }} [runtimeHints]
*/
export function buildBareOsPearCorestoreHrpcProcJson(id, env, runtimeHints) {
const now = Date.now()
const esc = (k) => String(env[k] ?? '').trim()
function parseJsonEnv(key) {
const raw = esc(key)
if (!raw) return null
try {
const o = JSON.parse(raw)
return o && typeof o === 'object' ? o : null
} catch {
return { schema: 1, error: 'invalid_json', key, atMs: now }
}
}
switch (id) {
case 'diagnostics_channel':
return {
schema: 1,
subscriptions: parseJsonEnv('BARE_OS_DIAGNOSTICS_CHANNEL_STATS_JSON'),
note: 'bare-diagnostics-channel mirror: subscription counts / names from host.',
atMs: now
}
case 'thread_pool':
return {
schema: 1,
pool: parseJsonEnv('BARE_OS_THREAD_POOL_HINT_JSON'),
note: 'Shallow worker/thread hint snapshot; non-secret.',
atMs: now
}
case 'async_hooks_lag':
return {
schema: 1,
lag: parseJsonEnv('BARE_OS_ASYNC_HOOKS_LAG_JSON'),
note: 'Event-loop lag sketch when host injects bare-async-hooks metrics.',
atMs: now
}
case 'compact_encoding_profile':
return {
schema: 1,
profile: parseJsonEnv('BARE_OS_COMPACT_ENCODING_PROFILE_JSON'),
note: 'Which compact codecs enabled on seed wire (documentation-first).',
atMs: now
}
case 'protomux_channels':
return {
schema: 1,
channels: parseJsonEnv('BARE_OS_PROTOMUX_CHANNELS_JSON'),
wireShapeSummary:
runtimeHints?.protomuxWireShape &&
typeof runtimeHints.protomuxWireShape === 'object'
? runtimeHints.protomuxWireShape
: undefined,
note: 'Bounded protomux channel name inventory; wireShapeSummary mirrors bare-os-v1 wire kinds + live peer mux count when the booter supplies runtimeHints.',
atMs: now
}
case 'hrpc_bridge_health':
return {
schema: 1,
health: parseJsonEnv('BARE_OS_HRPC_BRIDGE_HEALTH_JSON'),
note: 'Parallel to pear_ipc_health for hrpc bridge (operator JSON).',
atMs: now
}
case 'updater_download_state':
return {
schema: 1,
state: parseJsonEnv('BARE_OS_UPDATER_DOWNLOAD_STATE_JSON'),
note: 'pear-runtime-updater-shaped non-secret download progress.',
atMs: now
}
case 'security_context':
return {
schema: 1,
context: parseJsonEnv('BARE_OS_SECURITY_CONTEXT_JSON'),
note: 'Active boot policy / sandbox profile ids; no secrets.',
atMs: now
}
case 'git_lfs_pointer_stats':
return {
schema: 1,
stats: parseJsonEnv('BARE_OS_GIT_LFS_POINTER_STATS_JSON'),
note: 'LFS pointer rate summary for git delegate.',
atMs: now
}
case 'corestore_gc_hint':
return {
schema: 1,
hint: parseJsonEnv('BARE_OS_CORESTORE_GC_HINT_JSON'),
note: 'Operator corestore GC hint JSON.',
atMs: now
}
case 'hyperdb_readonly_index':
return {
schema: 1,
index: parseJsonEnv('BARE_OS_HYPERDB_READONLY_INDEX_JSON'),
note: 'Capped topic → length hints map (read-only).',
atMs: now
}
case 'blind_relay_router':
if (!bareOsProcBlindPeerRelayHintsExposed(env)) {
return bareOsProcBlindPeerRelayHintsMinimal(now)
}
return {
schema: 2,
exposed: true,
router: parseJsonEnv('BARE_OS_BLIND_RELAY_ROUTER_JSON'),
swarm: runtimeHints?.swarm ?? null,
note: 'Env router sketch plus live swarm aggregates (peer count / lifecycle) when runtimeHints supplied from booter.',
atMs: now
}
case 'autopass_session_sketch':
return {
schema: 1,
phase: esc('BARE_OS_AUTOPASS_SESSION_PHASE') || null,
sketch: parseJsonEnv('BARE_OS_AUTOPASS_SESSION_SKETCH_JSON'),
note: 'Session phase enum only; no pairing secrets.',
atMs: now
}
case 'bare_net_interfaces':
return {
schema: 1,
interfaces: parseJsonEnv('BARE_OS_BARE_NET_INTERFACES_JSON'),
note: 'bare-net-shaped summary when host provides.',
atMs: now
}
case 'pear_build_fingerprint':
return {
schema: 1,
fingerprint: parseJsonEnv('BARE_OS_PEAR_BUILD_FINGERPRINT_JSON'),
note: 'pear-build non-secret build id pointer.',
atMs: now
}
case 'pear_runtime_channel':
return {
schema: 1,
channel: esc('BARE_OS_PEAR_RUNTIME_CHANNEL') || null,
stage: esc('BARE_OS_PEAR_RUNTIME_STAGE') || null,
inspectorAttachHint: esc('BARE_OS_PEAR_INSPECTOR_ATTACH_HINT') || null,
snapshot: parseJsonEnv('BARE_OS_PEAR_RUNTIME_SNAPSHOT_JSON'),
note: 'Non-secret Pear runtime / updater channel hints from env; hosts may inject BARE_OS_PEAR_RUNTIME_SNAPSHOT_JSON from local pear-runtime tooling.',
atMs: now
}
default:
return {
schema: 1,
error: 'unknown_wave7_proc_id',
id,
atMs: now
}
}
}