# MoonBit OS Boundary

## Positioning

- Kernel and hardware control stay in host Linux (or hypervisor stack).
- MoonBit is used for pure compute modules compiled to WASM.
- I/O, network, file, and process management stay in host services.

## Why This Split

- Keeps the OS delivery path stable for VMware and bare-metal workflows.
- Avoids cross-platform native binary sprawl for compute-heavy modules.
- Preserves strict rollback path: switch compute engine by env/config only.

## Current Khy OS Mapping

- Host layer:
  - `khy_quant/cli.py`
  - `backend/bin/khyquant.js`
  - `backend/src/services/*` (I/O, network, orchestration)
- MoonBit/WASM layer:
  - `backend/wasm-indicators/` (pure indicator algorithms)
  - `backend/src/services/wasmAppService.js` (WASM app export execution)
  - `scripts/moonbit/run-wasm-indicators-tests-offline.sh` (offline validation)

## Build and Delivery

- Unified component build entry:
  - `scripts/build-khy-os.sh`
- VMware image planning/build:
  - `scripts/khytogo/make-khytogo.sh --mode vmware-plan|vmware-create`
- Portable package:
  - `scripts/portable/build-usb-portable.sh`

## WASM ABI

- `numeric-v1`: positional numeric args to exported function.
- `string-v2`: host encodes UTF-8 payload and passes `(ptr,len)`, module returns packed `(ptr,len)` as `i64`.
- `json-v2`: host sends JSON string over `string-v2` transport and enforces JSON output parsing.

## Design Rule

`Kernel untouched, sandbox accelerated.`
