Files
bare-operating-system/packages/bare-os-booter/lib/corestore-host-lifecycle.js
T
Raven Scott a485ce98d3 feat(boot,vfs,security): expand kernel boot contract, VFS snapshots, and ctx surfaces
- Kernel: strict capability contract merge, junit selftest, startup class, cold boot
  budget warning, boot txn schema v1, rc/kernel.ext resolution traces, richer
  bareOsPublishBootReady (steps/bootSteps, FSM sketch)
- Booter: warm reboot extra cycles, boot provenance on boot.json, step mirroring,
  corestore/swarm suspend-resume hooks, swarm connection manager sketch, event bus
  + optional NDJSON, security_posture proc schema v2, key handle TTL/scopes
- VFS: snapshot path class + BARE_OS_VFS_SNAPSHOTS checkout views, policy metrics,
  batch put + diff helpers, watch consistency hint, quotas vfsQuota fields
- Protocol: BARE_OS_PROTOMUX_CORK_HINT_VERSION via channel exports
- Initd: BARE_INITD_UNIT_STATES; shell: tokenizer module split
- Extensions: capability conflict detector in kernel-extension-resolver
- Docs/scripts: reference index map, observability event bus, dry-run vs rollback
  table, benchmark trend + integration-lab smoke, scripts README
- Tests: /proc listing + pseudo path caps for snapshots and security_posture
2026-04-04 17:24:48 -04:00

47 lines
1.5 KiB
JavaScript

/**
* Host lifecycle: when Corestore / Hyperswarm expose `suspend`/`resume`, wire them into
* `ctx.bareOsInvokeSuspendHooks` / `ctx.bareOsInvokeResumeHooks` (mobile sleep, etc.).
*/
/** @type {{ store: unknown, swarm: unknown } | null} */
let pendingPair = null
/**
* Called once from main() with live instances; hooks install on first guest ctx.
* @param {unknown} store
* @param {unknown} swarm
*/
export function bareOsRegisterCorestoreSuspendResumeHooks(store, swarm) {
pendingPair = { store, swarm }
}
/**
* @param {unknown} target
* @param {string} label
*/
async function callSuspendResume(target, label) {
if (!target || typeof target !== 'object') return
const o = /** @type {{ suspend?: () => unknown, resume?: () => unknown }} */ (
target
)
const fn = label === 'suspend' ? o.suspend : o.resume
if (typeof fn !== 'function') return
await Promise.resolve(fn.call(target))
}
/**
* @param {{ bareOsRegisterSuspendHook: (fn: () => void | Promise<void>) => unknown, bareOsRegisterResumeHook: (fn: () => void | Promise<void>) => unknown }} ctx
*/
export function bareOsInstallCorestoreSuspendResumeHooks(ctx) {
if (!pendingPair) return
const { store, swarm } = pendingPair
ctx.bareOsRegisterSuspendHook(async () => {
await callSuspendResume(store, 'suspend')
await callSuspendResume(swarm, 'suspend')
})
ctx.bareOsRegisterResumeHook(async () => {
await callSuspendResume(swarm, 'resume')
await callSuspendResume(store, 'resume')
})
}