194 lines
5.8 KiB
JavaScript
194 lines
5.8 KiB
JavaScript
import {
|
|
BARE_OS_HRPC_ROUTE_TABLE_SCHEMA_VERSION,
|
|
BARE_OS_HRPC_STOCK_ROUTES
|
|
} from './bare-os-hrpc-route-table.js'
|
|
import { buildKernelProgramProcJson } from './bare-os-kernel-program-proc.js'
|
|
import {
|
|
bareOsProcBlindPeerRelayHintsExposed,
|
|
bareOsProcBlindPeerRelayHintsMinimal
|
|
} from './bare-os-proc-blind-peer-relay-gate.js'
|
|
|
|
/**
|
|
* Capability word 11 optional `/proc/bare_os/*.json` payloads (env-injected; bounded, non-secret).
|
|
* Aligns with seed RPC word 11 + bits11 — no Node `node:*` built-ins in guest paths.
|
|
* @param {string} id
|
|
* @param {Record<string, string>} env
|
|
* @param {{ swarm?: Record<string, unknown> | null }} [runtimeHints]
|
|
*/
|
|
export function buildBareOsHypercorePackHrpcLifecycleProcJson(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 'hypercore_replicate_budget':
|
|
return {
|
|
schema: 1,
|
|
budget: parseJsonEnv('BARE_OS_HYPERCORE_REPLICATE_BUDGET_JSON'),
|
|
note: 'hypercore replicate queue budget v2 sketch.',
|
|
atMs: now
|
|
}
|
|
case 'drive_version_graph':
|
|
return {
|
|
schema: 1,
|
|
graph: parseJsonEnv('BARE_OS_DRIVE_VERSION_GRAPH_JSON'),
|
|
note: 'multi-drive lineage graph pointer.',
|
|
atMs: now
|
|
}
|
|
case 'protomux_backpressure':
|
|
return {
|
|
schema: 1,
|
|
backpressure: parseJsonEnv('BARE_OS_PROTOMUX_BACKPRESSURE_JSON'),
|
|
note: 'protomux channel depth hints.',
|
|
atMs: now
|
|
}
|
|
case 'pear_runtime_matrix':
|
|
return {
|
|
schema: 1,
|
|
matrix: parseJsonEnv('BARE_OS_PEAR_RUNTIME_MATRIX_JSON'),
|
|
note: 'pear-runtime vs bare-runtime matrix.',
|
|
atMs: now
|
|
}
|
|
case 'bundle_preload_hint':
|
|
return {
|
|
schema: 1,
|
|
preload: parseJsonEnv('BARE_OS_BUNDLE_PRELOAD_HINT_JSON'),
|
|
note: 'cold-start bundle preload list.',
|
|
atMs: now
|
|
}
|
|
case 'autopass_rotation_sketch':
|
|
return {
|
|
schema: 1,
|
|
rotation: parseJsonEnv('BARE_OS_AUTOPASS_ROTATION_SKETCH_JSON'),
|
|
note: 'autopass rotation schedule class.',
|
|
atMs: now
|
|
}
|
|
case 'hrpc_allowlist_sketch':
|
|
return {
|
|
schema: 3,
|
|
allowlist: parseJsonEnv('BARE_OS_HRPC_ALLOWLIST_SKETCH_JSON'),
|
|
routeTableSchemaVersion: BARE_OS_HRPC_ROUTE_TABLE_SCHEMA_VERSION,
|
|
stockRoutes: [...BARE_OS_HRPC_STOCK_ROUTES],
|
|
note:
|
|
'Schema 3: adds routeTableSchemaVersion; stock route list matches ctx.bareOsHrpcRequest + kernel.capabilities payload.',
|
|
atMs: now
|
|
}
|
|
case 'sidecar_resource_cap':
|
|
return {
|
|
schema: 1,
|
|
cap: parseJsonEnv('BARE_OS_SIDECAR_RESOURCE_CAP_JSON'),
|
|
note: 'sidecar CPU/memory class.',
|
|
atMs: now
|
|
}
|
|
case 'git_lfs_budget':
|
|
return {
|
|
schema: 1,
|
|
budget: parseJsonEnv('BARE_OS_GIT_LFS_BUDGET_JSON'),
|
|
note: 'git LFS bandwidth window.',
|
|
atMs: now
|
|
}
|
|
case 'net_qos_class':
|
|
return {
|
|
schema: 1,
|
|
qos: parseJsonEnv('BARE_OS_NET_QOS_CLASS_JSON'),
|
|
note: 'egress QoS class hint.',
|
|
atMs: now
|
|
}
|
|
case 'storage_tier_hint':
|
|
return {
|
|
schema: 1,
|
|
tier: parseJsonEnv('BARE_OS_STORAGE_TIER_HINT_JSON'),
|
|
note: 'storage hot/warm/cold pointer.',
|
|
atMs: now
|
|
}
|
|
case 'indexer_catchup':
|
|
return {
|
|
schema: 1,
|
|
catchup: parseJsonEnv('BARE_OS_INDEXER_CATCHUP_JSON'),
|
|
note: 'Hyperbee/HyperDB indexer lag budget.',
|
|
atMs: now
|
|
}
|
|
case 'multisig_quorum_pointer':
|
|
return {
|
|
schema: 1,
|
|
pointer: parseJsonEnv('BARE_OS_MULTISIG_QUORUM_POINTER_JSON'),
|
|
note: 'multisig quorum policy pointer only.',
|
|
atMs: now
|
|
}
|
|
case 'relay_geo_hint':
|
|
if (!bareOsProcBlindPeerRelayHintsExposed(env)) {
|
|
return bareOsProcBlindPeerRelayHintsMinimal(now)
|
|
}
|
|
return {
|
|
schema: 2,
|
|
exposed: true,
|
|
regions: parseJsonEnv('BARE_OS_RELAY_GEO_HINT_JSON'),
|
|
swarm: runtimeHints?.swarm ?? null,
|
|
note: 'Coarse relay region tags from env plus swarm aggregates (no geo-IP; peer count tier only).',
|
|
atMs: now
|
|
}
|
|
case 'bare_pack_cache':
|
|
return {
|
|
schema: 1,
|
|
cache: parseJsonEnv('BARE_OS_BARE_PACK_CACHE_JSON'),
|
|
note: 'bare-pack / bare-pack-drive cache policy.',
|
|
atMs: now
|
|
}
|
|
case 'bare_addon_policy':
|
|
return {
|
|
schema: 1,
|
|
policy: parseJsonEnv('BARE_OS_BARE_ADDON_POLICY_JSON'),
|
|
note: 'native bare-addon policy sketch.',
|
|
atMs: now
|
|
}
|
|
case 'bare_signals_profile':
|
|
return {
|
|
schema: 1,
|
|
profile: parseJsonEnv('BARE_OS_BARE_SIGNALS_PROFILE_JSON'),
|
|
note: 'bare-signals mask summary.',
|
|
atMs: now
|
|
}
|
|
case 'bare_timers_histogram':
|
|
return {
|
|
schema: 1,
|
|
histogram: parseJsonEnv('BARE_OS_BARE_TIMERS_HISTOGRAM_JSON'),
|
|
note: 'bare-timers histogram (dev).',
|
|
atMs: now
|
|
}
|
|
case 'wave11_peer_qos_sketch':
|
|
return {
|
|
schema: 1,
|
|
sketch: parseJsonEnv('BARE_OS_WAVE11_PEER_QOS_SKETCH_JSON'),
|
|
note: 'wave11 peer QoS operator sketch.',
|
|
atMs: now
|
|
}
|
|
case 'wave11_operator_slo_v2':
|
|
return {
|
|
schema: 1,
|
|
slo: parseJsonEnv('BARE_OS_WAVE11_OPERATOR_SLO_V2_JSON'),
|
|
note: 'wave11 SLO hint adjunct.',
|
|
atMs: now
|
|
}
|
|
case 'kernel_program':
|
|
case 'giant_phase_program':
|
|
return buildKernelProgramProcJson(env)
|
|
default:
|
|
return {
|
|
schema: 1,
|
|
error: 'unknown_wave11_proc',
|
|
id,
|
|
atMs: now
|
|
}
|
|
}
|
|
}
|