---
name: wallrus
description: Build, hot-swap, visually verify, and live-control interactive 3D Three.js desktop wallpapers on Linux (Wayland/X11) and macOS using the `wallrus` CLI or MCP server. Use whenever the user asks to create, edit, animate, debug, or interact with a 3D/shader/Three.js desktop wallpaper.
---

# Wallrus — Agent Guide for 3D Live Wallpapers

`wallrus` is an agent-first Three.js wallpaper runtime written in Rust. A wallpaper is a single zero-asset ES module `.js` file (or `.html` scene) rendered natively on the desktop background (`zwlr_layer_shell_v1` on Linux Wayland, `_NET_WM_WINDOW_TYPE_DESKTOP` on X11, `kCGDesktopWindowLevel` on macOS).

> Install: `curl -fsSL https://wallrus.pages.dev/install.sh | bash`. Converting an existing Three.js page/project/URL/shader? Use the companion skill: `curl -fsSL https://wallrus.pages.dev/skills/wallrusify/SKILL.md`.

## The Autonomous Agent Loop (Always Follow This!)

1. **Check environment & contract** (if first run):
   ```bash
   wallrus doctor
   ```
2. **Write a self-contained ES module** (e.g., `~/.local/share/wallrus/scenes/<name>.js` or `./scenes/<name>.js`) following the **Scene Contract** below.
3. **Deploy & validate WebGL/GLSL compilation**:
   ```bash
   wallrus set ./scenes/<name>.js
   ```
   - Exit code `0`: Scene compiled cleanly and is live on the user's desktop.
   - Exit code `1`: Runtime, GLSL shader, or wallpaper-guardrail error printed to `stderr` (and the user's desktop automatically stayed on the previous working wallpaper without crashing). Fix the reported error and re-run `wallrus set`.
4. **Visually verify your framing & lighting (Privacy-Safe!)**:
   ```bash
   wallrus screenshot /tmp/wallrus-preview.png
   ```
   - `wallrus screenshot` captures **only** the pure Three.js WebGL backbuffer (never the user's open windows!).
   - Inspect `/tmp/wallrus-preview.png` with your vision/file-reading tool to verify camera framing, exposure/bloom balance, horizon placement, and color contrast. Refine and save — `wallrus` auto-hot-reloads edits every 250ms!
5. **Check performance & logs**:
   ```bash
   wallrus status --json
   ```

---

## Standardized Scene Contract

Every scene is a standard ES module. **No npm install or external CDN is needed** — Three.js `r170`, common addons, and procedural noise are embedded inside the `wallrus` binary.

### Available Offline Imports
```js
import * as THREE from 'three';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import { UnrealBloomPass } from 'three/addons/postprocessing/UnrealBloomPass.js';
import { EffectComposer } from 'three/addons/postprocessing/EffectComposer.js';
import { Sky } from 'three/addons/objects/Sky.js';
import { Water } from 'three/addons/objects/Water.js';
import { RoundedBoxGeometry } from 'three/addons/geometries/RoundedBoxGeometry.js';
import * as BufferGeometryUtils from 'three/addons/utils/BufferGeometryUtils.js';
```

### Module Structure (Engine-Managed 3D Depth Parallax + Orbit + WASD!)

`wallrus` **automatically provides**:
- **True 3D Spherical Depth Parallax** around `controls.target` while pinned on the desktop (respecting the user's `[p]` toggle and parallax intensity slider in `~/.config/wallrus/config.toml`),
- **Smooth Damped `OrbitControls` + `WASD` / `Q` / `E` 3D Camera Flight** in Interactive Mode (`Ctrl+Alt+I`),
- **Persistent Camera Pinning (`Esc`) & Reset (`R`)**, and **Automatic Near/Far Frustum Protection** so models never clip!

**Important:** Set your initial `camera.position` and `controls.target` in `setup(ctx)`, and **do NOT manually overwrite `camera.position` in `onTick`** — let the engine's 3D camera rig handle camera orbit, WASD flight, and camera-local 3D parallax cleanly from any pinned angle! Use `ctx.pointer.smoothX` / `smoothY` for subtle world/shader reactions (wind, ripples, particles, lights).

```js
import * as THREE from 'three';

export const meta = {
  title: 'Rainy Cyberpunk Skyline',
  category: 'Cyber & Sci-Fi',
  description: 'Neon-drenched rainy skyline with reflective wet streets and volumetric light.',
  // Shown as clickable chips + keyboard shortcuts in Interactive Mode (avoid reserving W/A/S/D/Q/E/R/P):
  controls: [
    { key: '1', label: 'Neon Dusk' },
    { key: '2', label: 'Acid Rain' },
    { key: 'Space', label: 'Lightning' },
  ],
};

export function setup(ctx) {
  const { scene, camera, renderer, controls, noise } = ctx;

  camera.position.set(0, 8, 26);
  controls.target.set(0, 4, 0);
  controls.update();

  // Optional post-processing bloom (returns UnrealBloomPass):
  const bloom = ctx.enableBloom({ strength: 0.45, radius: 0.5, threshold: 0.72 });

  // Built-in seeded procedural noise (no external noise library needed!):
  // noise.noise2D(x, y)            -> [-1, 1]
  // noise.noise3D(x, y, z)         -> [-1, 1]
  // noise.fbm2D(x, y, octaves)     -> [-1, 1]
  // noise.ridged2D(x, y, octaves)  -> [0, 1] sharp ridges/peaks

  // Raycast clicks on 3D geometry in Interactive Mode:
  ctx.onClick(({ raycaster, ndc }) => {
    // const hits = raycaster.intersectObjects(clickableMeshes);
  });

  // Keyboard shortcuts & HUD button clicks:
  ctx.onKey((key) => {
    if (key === '1') ctx.toast('Preset: Neon Dusk');
  });

  // Live external events from `wallrus send <name> '<json>'`:
  ctx.onEvent((name, payload) => {
    // Mutate uniforms/state live without reloading!
  });

  ctx.onTick(({ dt, elapsed, pointer, system, interactive }) => {
    // Animate geometry, shaders, particles, and subtle pointer world effects (pointer.smoothX / smoothY).
    // Leave `camera.position` to Wallrus's built-in 3D depth parallax, OrbitControls & WASD rig!
  });
}
```

---

## Customizing Config & WM Ricing (`config.toml` + `hud.css`)

Wallrus is built for Linux/macOS desktop ricing. Both `~/.config/wallrus/config.toml` and `~/.config/wallrus/hud.css` **auto-hot-reload within 250ms** whenever edited:

```bash
wallrus config --show                                     # Print config.toml & hud.css paths + live values
wallrus config --parallax true --parallax-strength 1.2    # Adjust 3D depth parallax (0.0..2.5)
wallrus config --wasd-speed 1.5 --fps 60                  # Adjust WASD speed & FPS cap
wallrus hud --position bar --theme catppuccin             # Themes: default, catppuccin, tokyo-night, gruvbox, nord, rose-pine, kanagawa, transparent
wallrus hud --init-css                                    # Scaffolds ~/.config/wallrus/hud.css (--wallrus-* vars, pywal/wallust ready)
```

---

## Wallpaper Complexity & Anti-Game Guardrails

To keep wallpapers crisp, battery-friendly, and non-intrusive:
1. **Lightweight Self-Contained Scenes**: Source files must be `<= 1 MB` locally (`<= 512 KB` for community uploads on `wallrus.pages.dev`).
2. **No Game Hijacking**: `PointerLockControls`, fullscreen requests, popups, gamepads, and audio autoplay (`AudioContext` / `<audio>`) are automatically blocked/muted.
3. **60 FPS GPU Budget**: Stay well within `< 3,500` draw calls and `< 10M` triangles per frame (prefer `THREE.InstancedMesh`, `THREE.Points`, and `THREE.ShaderMaterial`).
4. **Desktop Readability**: Keep `renderer.toneMappingExposure` around `0.95–1.15` and bloom `threshold >= 0.65` so terminal text and translucent windows remain legible.
