# `@supermachine/core` examples

Runnable scripts demonstrating each integrator-facing surface.
Every example is self-contained — `node examples/NN-name.mjs`
with the package installed.

| File | Surfaces |
|---|---|
| `01-hello.mjs` | `Image.build` + `pool.acquire` + `vm.exec` — the minimum program |
| `02-pool.mjs`  | Pool sizing (`min`/`max`), `pool.stats()`, concurrent acquire |
| `03-snapshot-then-restore.mjs` | `vm.writeFile` / `readFile`, mid-flight `vm.snapshot()`, `Image.fromSnapshot` |
| `04-expose-tcp.mjs` | `listenerRequired: true` bakes, `vm.exposeTcp()`, `TcpForwarder` |
| `05-spawn-streaming.mjs` | `vm.spawn()` → `ExecChild` (writeStdin / readStdout / wait) |
| `06-mount-workspace.mjs` | `mounts` + `symlinks` policy: live host dir into guest, npm-workspace symlink pattern |
| `07-npm-workspace-fast.mjs` | The recommended npm/pnpm/cargo pattern: virtio-fs mount for source + virtio-blk volume for node_modules + warmup-bake for one-time install |

## Requirements

- macOS on Apple Silicon (no Linux/Windows backends yet)
- Docker available for the OCI image pull on first run
- Node ≥ 18.17

## Running locally from a source checkout

The examples import `"@supermachine/core"` as if installed from
npm. From this repo, run them with a path-rewrite:

```sh
cd npm/supermachine-core
npm install
npm run build
# then either: `npm link` once, then `node examples/01-hello.mjs`
# or: rewrite the import inline
node --input-type=module -e \
  "$(sed 's|@supermachine/core|./index.js|' examples/01-hello.mjs)"
```

For a quick smoke test that all examples work end-to-end:

```sh
for f in examples/*.mjs; do
  echo "=== $f ===";
  node --input-type=module -e "$(sed 's|@supermachine/core|./index.js|' $f)";
done
```
