Expose /proc/bare_os/metrics.prom (kernel counter OpenMetrics) and /proc/bare_os/protomux.json (alias registry snapshot). Extend VFS routing, readdir, pseudo watch, and bare_os_proc_index to schema 8; restore flat /proc entries for syscalls and process_table with sort order matching tests. Add ctx.bareOsAuditLogAppendBatch and bump BARE_OS_CTX_API_VERSION to 1.30.0 with d.ts and compatibility-matrix updates. Harden swarm peer ban backoff with jitter on the exponential window. Refresh conformance matrix, environment appendix, booter package doc, and handbook chapters for proc paths, param expansion V3, vault at rest, and baretop snapshot keys. Align baretop-snapshot with bareOsReadBareTopSnapshot.
99 lines
2.7 KiB
JavaScript
99 lines
2.7 KiB
JavaScript
/**
|
|
* Build `/proc/bare_os/host_os.json` text (Holepunch `bare-os`-shaped snapshot).
|
|
*
|
|
* Always uses the **`bare-os`** package (ESM on Node and Bare). On Bare, **`bare-module`**
|
|
* `createRequire` is used when needed; there is no `node:os` / `node:module` path.
|
|
*/
|
|
|
|
/**
|
|
* @param {Record<string, string>} env
|
|
* @returns {Promise<string>}
|
|
*/
|
|
export async function buildBareOsHostProcJsonText(env) {
|
|
const rawInject = String(env.BARE_OS_HOST_OS_JSON || '').trim()
|
|
if (rawInject) {
|
|
try {
|
|
const parsed = JSON.parse(rawInject)
|
|
return `${JSON.stringify({
|
|
schema: 1,
|
|
source: 'BARE_OS_HOST_OS_JSON',
|
|
host: parsed,
|
|
atMs: Date.now()
|
|
})}\n`
|
|
} catch {
|
|
return `${JSON.stringify({
|
|
schema: 1,
|
|
error: 'invalid BARE_OS_HOST_OS_JSON',
|
|
atMs: Date.now()
|
|
})}\n`
|
|
}
|
|
}
|
|
const probe =
|
|
env.BARE_OS_HOST_BARE_OS_PROC === '1' ||
|
|
env.BARE_OS_HOST_BARE_OS_PROC === 'true'
|
|
if (!probe) {
|
|
return `${JSON.stringify({
|
|
schema: 1,
|
|
note: 'Set BARE_OS_HOST_BARE_OS_PROC=1 or inject BARE_OS_HOST_OS_JSON.',
|
|
atMs: Date.now()
|
|
})}\n`
|
|
}
|
|
try {
|
|
let os
|
|
if (typeof Bare !== 'undefined') {
|
|
const bm = await import('bare-module')
|
|
const createRequire = bm.createRequire || bm.default?.createRequire
|
|
if (typeof createRequire !== 'function') {
|
|
throw new Error('bare-module createRequire unavailable')
|
|
}
|
|
const _require = createRequire(import.meta.url)
|
|
os = _require('bare-os')
|
|
} else {
|
|
const m = await import('bare-os')
|
|
os = m.default ?? m
|
|
}
|
|
return `${JSON.stringify(hostPayloadFromBareOsLike(os, 'bare-os'))}\n`
|
|
} catch {
|
|
return `${JSON.stringify({
|
|
schema: 1,
|
|
note: 'Host OS probe failed; use BARE_OS_HOST_OS_JSON on this runtime.',
|
|
atMs: Date.now()
|
|
})}\n`
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param {Record<string, unknown>} os
|
|
* @param {string} source
|
|
*/
|
|
function hostPayloadFromBareOsLike(os, source) {
|
|
const snap = {
|
|
platform: typeof os.platform === 'function' ? os.platform() : null,
|
|
arch: typeof os.arch === 'function' ? os.arch() : null,
|
|
hostname: typeof os.hostname === 'function' ? os.hostname() : null,
|
|
release: typeof os.release === 'function' ? os.release() : null
|
|
}
|
|
let ifaces = null
|
|
try {
|
|
if (typeof os.networkInterfaces === 'function') {
|
|
const n = os.networkInterfaces()
|
|
if (n && typeof n === 'object') {
|
|
ifaces = Object.keys(n)
|
|
.slice(0, 32)
|
|
.map((name) => ({
|
|
name,
|
|
count: Array.isArray(n[name]) ? n[name].length : 0
|
|
}))
|
|
}
|
|
}
|
|
} catch {
|
|
ifaces = null
|
|
}
|
|
return {
|
|
schema: 1,
|
|
source,
|
|
host: { ...snap, networkInterfaceNames: ifaces },
|
|
atMs: Date.now()
|
|
}
|
|
}
|