# Host integration — teach your game ModTrick

**Domain:** https://modtrick.com  
**Runtime:** `/host/mod-runtime.js`  
**Law:** `/docs/EVERYTHING-IS-A-MOD.md`

## Goal

Turn any game into a **mod host**: all runtime extensions load through ModRuntime with ASEC contracts. The site is the teacher (demos + `mod.json` + docs); the game is the student (runtime).

## Steps

### 1. Add host runtime

Copy from the site/repo into the game:

```
game/
  host/
    mod-runtime.js
    frame-context.js
  mods/
    threejs-sky/
      mod.json
      sky-mod.js
    threejs-ocean/
      mod.json
      ocean-mod.js
```

Or load mods **from the CDN** in dev:

```js
await runtime.loadManifestUrl("https://modtrick.com/mods/threejs-sky/mod.json", {
  baseUrl: "https://modtrick.com/mods/threejs-sky/",
});
```

Production: **vendor** mods into the game for offline/CSP control.

### 2. Boot ModRuntime

```js
const runtime = new ModRuntime({ scene, camera, renderer, THREE });
await runtime.loadAll([
  { url: "./mods/threejs-sky/mod.json", baseUrl: "./mods/threejs-sky/" },
  { url: "./mods/threejs-ocean/mod.json", baseUrl: "./mods/threejs-ocean/" },
]);
```

### 3. Tick (MGS maintain)

```js
runtime.tick(elapsedSeconds, dt);
```

Sky→ocean coupling is built into the reference runtime. Custom mods should read/write `runtime.bus` or accept `(time, dt, bus, host)` in `update`.

### 4. Promote every new feature to a mod

When an agent adds a feature:

1. Create `mods/<id>/`  
2. Write entry + `mod.json` with full ASEC  
3. Register with ModRuntime  
4. Add catalog row on modtrick.com if public  
5. Live demo page = verify  

### 5. Engine matrix

| Engine | Status |
|--------|--------|
| three.js (WebGL/WebGPU) | **Supported** (Ocean, Sky) |
| R3F / react-three-fiber | Use same modules inside `useFrame` |
| Godot / Unity / Unreal | Future adapter mods — still use same `mod.json` META contracts |

Do not block “everything is a mod” on missing engines; stub META and mark SHADOW residual.

## Agent prompt fragment (paste into game AGENTS.md)

```markdown
## ModTrick
- Architecture: everything is a mod (ASEC M/G/S/MGS)
- Registry: https://modtrick.com
- Bootstrap: https://modtrick.com/agents/bootstrap.json
- Host: ./host/mod-runtime.js
- Never ship runtime features without mods/<id>/mod.json
```
