# Simulator

> Run a miniapp on your computer with no phone and no glasses, and drive it from the terminal.

Source: https://docs.glasslyos.com/app-devs/getting-started/simulator/

`glassly sim` runs your miniapp on macOS, Linux, or Windows. The background
script runs in a worker, the glasses display is drawn in a browser window, and
the phone page loads in a phone frame beside it. Every input the glasses and
phone would produce can be sent from that window or from the command line, so a
script or a coding agent can change code, act, and check the result without a
person in the loop.

```bash
glassly sim
```

It validates `miniapp.json`, builds both layers, opens the simulator window, and
rebuilds and reloads when you save a source file. Console output from both
layers prints in the terminal and in the window's log.

## The window

- **Glasses**: the display, drawn by the same scene pipeline the Glassly App
  runs (clamping, element budgets, text wrapping, transitions). It simulates
  the app's Simulated Glasses, a 576×288 canvas with 16 gray levels that
  previews what Glassly CFW glasses can show. Pass `--device` to simulate a
  specific model instead (see [Glasses models](#glasses-models)).
- **Controls**: the touch bar (tap A and tap B, double tap, hold, swipes), look up and
  down (gestures the simulated model does not send are greyed out), speech the glasses hear (typed, delivered as a transcription), phone
  notifications, battery, location, and connecting or disconnecting the
  glasses. Tap A and tap B are single taps with `index` 0 and 1, the two
  fingers a Neural Band tells apart (`glassly sim tap` / `glassly sim tap --b`).
  Button presses come from `glassly sim button`.
- **Phone**: your UI page with the same `glassly` bridge, safe-area insets and
  capsule menu it gets inside the Glassly App. Switch it to a folded iPhone Duo
  (or run `glassly sim phone duo`) to check the page against the 84 pt status
  rail on the right, with the capsule and any `useRailBackButton` back button
  drawn in the rail. The same page is at `/ui/` on the simulator's address if
  you want it in its own tab.
- **Log, Scene, State**: console output, the elements on the display, and what
  the miniapp is subscribed to.

## Drive it from the terminal

While a simulator is running, `glassly sim <command>` from the project folder
talks to it:

```bash
glassly sim --detach            # start in the background and return when ready
glassly sim screen              # what is on the glasses, one element per line
glassly sim screenshot out.png  # the display as a PNG
glassly sim screenshot --phone --tap Skip phone.png  # the phone page, past its setup guide (needs Chrome)
glassly sim tap                 # also: double-tap, hold, swipe-up, swipe-down, look-up, look-down
glassly sim button long
glassly sim phone duo           # folded iPhone Duo phone page; back with: glassly sim phone iphone
glassly sim say "what's the weather"
glassly sim notify --title "Mom" --content "Call me back"
glassly sim location 48.8566 2.3522
glassly sim ui request places:autocomplete '{"query": "cafe"}'
glassly sim logs --since 0      # console output from both layers, plus build errors
glassly sim status --json
glassly sim stop
```

`screen` prints the processed frame, which is usually the quickest check:

```
Simulated Glasses 576x288, view main
text     title            @ 286,14 150x27  "TETRIS" {"color":15}
rect     frame            @ 138,12 134x264 {"border":1,"color":7}
```

`ui send` and `ui request` act as the phone page, so background logic that
answers the page can be exercised without a browser. To drive the real page, open
`http://localhost:<port>/ui/` in any browser or browser automation tool.

The full list is in the [CLI reference](https://docs.glasslyos.com/app-devs/reference/cli.md#sim).

## Glasses models

`glassly sim --device <id>` simulates one model and firmware. Each device
reports the capabilities the Glassly App reports for it, including
`display.textProfile`, so `textProfileFor(capabilities)` from
`@glassly/miniapp/display` picks the profile it would on the glasses. Text is
wrapped with that profile, frames are cut to the model's element budget and
shapes, and gesture commands accept only the gestures its driver sends: `glassly
sim tap` on a Mentra Display, which only sends head up, fails and lists the
gestures it does send.

| `--device` | Model and firmware | Canvas | Draws |
| --- | --- | --- | --- |
| `simulated` (default) | Simulated Glasses, the Glassly App's phone mode | 576×288 | everything |
| `g1` | Even Realities G1, stock | 640×200 | one wrapped block of text, no shapes |
| `g1-cfw` | G1, Glassly custom firmware | 640×200 | positioned elements, every shape |
| `g2` | Even Realities G2, stock | 576×288 | 6 text or rect elements, 4 images |
| `g2-cfw` | G2, Glassly custom firmware | 576×288 | positioned elements, every shape, animation |
| `rayneo-io` | RayNeo iO, stock | 540×180 | the frame's text joined on one subtitle page (an approximation) |
| `rayneo-io-cfw` | RayNeo iO, Glassly custom firmware | 540×180 | positioned elements, every shape |
| `nimo` | NIMO, stock layout page | 500×220 | text, rects, circles and lines |
| `nimo-cfw` | NIMO, Glassly custom firmware | 540×280 | positioned elements, every shape |
| `memomind-one` | MemoMind One (custom firmware only) | 600×350 | positioned elements, every shape |
| `mentra-display` | Mentra Display | 500×220 | 6 text or rect elements, 4 images |
| `mentra-live` | Mentra Live (camera, no display) | none | nothing: `render()` answers `{status: "blocked"}` |

Custom firmware values are those current Glassly CFW reports.

To see a miniapp on every model at once:

```bash
glassly sim shots                            # one PNG per device in ./glassly-sim-shots, plus index.html
glassly sim shots out --say "Hello there"    # deliver speech first, for apps that draw what they hear
glassly sim shots --devices g1,g2,g2-cfw
```

It builds once, runs the miniapp headless on each device in turn, waits for the
display to stop changing, and saves a screenshot. It exits non-zero and names
the device when the miniapp fails to start on one.

## What is simulated

The simulator handles every request a miniapp can send. Five are one-way and
get no reply, as on the phone: `open_url`, `apps_stop_self`, `action_result`,
`widget_update` and `widget_result`. A clipboard copy without text or a
download without a file gets no reply either. **Real** means the simulator
does what the Glassly App does, with the app's permission checks, argument
checks, error codes and messages. **Stand-in** means the app would need the
cloud, the phone's OS or a camera, so the simulator answers in the app's reply
shape and marks it (see [Stand-ins and forced errors](#stand-ins-and-forced-errors)).

| Area | In the simulator |
| --- | --- |
| `session.display` | Real: rendered and reported as the host processes it, including `degraded` and `dropped`. `preload()` lands at once on `g1-cfw`, `g2-cfw` and `memomind-one` and answers `unsupported` elsewhere (`simulated glasses` on the default device). `showView("dashboard")` is granted to a `dashboard` miniapp on glasses with Glassly custom firmware (`g1-cfw`, `g2-cfw`, `rayneo-io-cfw`, `nimo-cfw`, `memomind-one`) and answers `{status: "unsupported"}` elsewhere. Display diagnostics report `enabled: false`, as with the app's debug settings off. |
| `session.display.requestSurface` | Real: a miniapp's own display surfaces show beside its own main frame. Other miniapps' surfaces in the same session are not composed. |
| `session.input`, `session.imu.onHeadPosition` | Real: touch gestures, head up and down, button presses, each only on glasses that send it. |
| `session.transcription`, `session.translation` | Real event shape: text you send with `say`, `translate` or `play`, with the app's field names (`utteranceId`, `transcribeLanguage`, `translateLanguage`, `speakerId`, start and end times). |
| `session.wakeWord` | Fires when you run `glassly sim wake`, or `say` a line that opens with "Hey Glassly". No keyword model runs: audio you feed with `glassly sim audio` never triggers it. |
| `session.health` | Stand-in: Apple Health holding an Apple Watch and WHOOP, and a connected Even R1, with every metric over the 35 days before today and one night of sleep per source. The same query always gets the same answer. `sync()` answers `synced` at once on every call. `glassly sim health` fires `onChange` from the ring, `--store` from the store. The `HEALTH` declaration and argument checks are real; with no wearer to ask, a miniapp that declares `HEALTH` counts as allowed. |
| `session.mic` | Real: `onAudioChunk` gets audio you feed with `glassly sim audio <file.wav>`; voice activity detection and the loudness gate apply per model. |
| `session.speaker` | `speak()` and `play()` are logged and resolve after a simulated duration; the window can read speech aloud. Speaker streams are real: validation, buffering, drain on close and state events. No audio plays. |
| `session.storage`, `session.memory`, `session.settings`, `session.blob` | Real, kept on disk per project in `~/.glassly/sim/<packageName>/<project>/`, so they survive a restart and two copies of one miniapp do not share them; `glassly sim reset` clears that project's state. Settings belong to the phone, so the miniapps run with `--with` share the first miniapp's settings. Memory, blob limits and the settings allowlist, defaults and checks follow the app. Stand-ins for the phone's share sheet and file picker: `memory.exportFile()` writes a backup into that folder, `memory.importFile()` reads the newest one there, blob share answers as if shared, and blob import answers as if cancelled. |
| `session.phone.notifications` | `listApps()` returns a fixed list of sample phone apps, plus your miniapp when it declares `POST_NOTIFICATIONS`. Notifications are values you send. |
| `session.location`, `session.glasses`, battery | Values you set. |
| Sensors (`session.lightSensor`, `session.compass`, IMU) | Real answers per model (light on `g2-cfw`, `memomind-one` and `nimo-cfw`, compass on `g2-cfw`); no readings are sent. |
| `session.camera` | Real checks per model: a photo on glasses without a camera fails with the app's `request_timeout` (at once instead of after 30 seconds). Stand-in: a JPEG test card on `mentra-live`; video and streams are recorded in the log. |
| `session.ai` | Stand-in: text starting "[glassly sim]" that echoes the prompt, and a call to the offered tool the prompt names. |
| `session.keys` | Real allowlist; keys come from `GLASSLY_SIM_KEY_<PROVIDER>` environment variables, otherwise no key. |
| `session.navigation` | Real trip state, stop and native navigation answers. Stand-ins: routes as straight lines, a placeholder address, two made-up places per search. |
| `session.auth` | Stand-in: a placeholder token for user `sim-user` that no server accepts. |
| `session.link` | Real: `open()` dials the computer over iroh as the Glassly App does, so Terminal in the simulator pairs with a running `glassly link`. |
| Calendar, speaker names, QR scan, web sign-in, Wi-Fi setup | Real checks; stand-in answers (three sample events around now, `spk_<name>` resolves to the name, `GLASSLY_SIM_QR_DATA`, placeholder cookies). |
| `session.system` (open URL, clipboard, share, download), `session.led` | Logged, not performed. |
| Your actions and widgets | `glassly sim action <id> [json]` calls a declared action and prints its result; `glassly sim widget <id>` places a declared widget and prints the card it draws, or with a JSON event, its answer. `--app <packageName>` calls a miniapp installed with `--with`. |
| `session.ui` and the `glassly` page bridge | Real, including RPC and cancellation. |
| Manifest permissions | Real: an undeclared permission fails with `PERMISSION_NOT_DECLARED` and the app's message. |

One request answers `NOT_IMPLEMENTED` on both: dashboard content updates, which
the Glassly App has not built yet.

## Several miniapps

`glassly sim --with ../news,../notes` installs other miniapps beside the one
you are working on, as installed apps on a phone: not running until something
starts them. Then `session.widgets` places and shows their widgets,
`session.actions` lists and invokes their actions (waking them), and
`session.miniapps` lists, starts and stops them, with the Glassly App's
permission checks and errors. A miniapp whose `hardwareRequirements` the
simulated glasses lack is listed as incompatible and refused with
`APP_NOT_COMPATIBLE`, as on the phone. Gesture claims are shared: a claimed
gesture reaches only the miniapp that claimed it last, and an unclaimed one
reaches every miniapp listening. A miniapp started only to show a widget stops
when its last widget is removed. Their console output is in the log, tagged with
their name. The glasses display and the phone page stay your miniapp's.
`glassly sim action` and `glassly sim widget` take `--app <packageName>` to
call one of those miniapps instead of yours.

## Play a conversation

`glassly sim play talk.txt` plays a transcript as speech. Each line is one
utterance:

```text
# Two people at a station
[0:00] A (en): Excuse me, where is the train station?
[0:04] B (es): Está a dos cuadras. | en: It's two blocks away.
A (en): Thank you.
```

Every part but the text is optional: the time from the start, the speaker,
the spoken language (the line before's when absent), and translations after
`|`. Each line's words arrive as growing interims under one `utteranceId` at
the speaking rate (`--rate`, default 160 words per minute), then one final
half a second later, as the speech service sends them. Speakers become
`speakerId` `"1"`, `"2"`, … in order of appearance. A miniapp that subscribes
to translations into a language gets each line in it: the text after `| <code>:`,
a marked stand-in such as `[es→en] Está a dos cuadras.` when the line has
none, or the line itself when it is already in that language.

`--frames <dir>` saves a screenshot of every frame once it settles, to check
how a display builds up over a conversation. If a frame cannot be saved, the
command fails and says why.

## Stand-ins and forced errors

A stand-in reply has the Glassly App's shape and is marked with
`simulated: true` or "(glassly sim)" text where the shape allows.
`glassly sim status` lists each stand-in your miniapp has used, so you know
which answers to check on a phone.

To test an error path, `glassly sim fail <type> <code>` makes the next request
of that type fail, with the app's message for that code when the simulator
knows it:

```bash
glassly sim fail ai_complete QUOTA_EXCEEDED
```

## What the simulator cannot stand in for

Check these on a phone and glasses before you ship.

- **Bluetooth**: latency, dropped or reordered packets, reconnects, throughput
  limits on large frames.
- **Firmware**: the glasses' own fonts and glyph shapes, RayNeo's character
  folding and line cutting, G2 custom firmware drawing at a 27 px pitch while
  the host wraps at 40, emoji and unsupported scripts rasterized on the phone,
  stock RayNeo and NIMO flattening frames into a subtitle page (approximated),
  gestures a model lists but its firmware never sends.
- **Audio**: microphone quality, voice activity detection, recognition errors,
  the real pace of interim results, speaker and phone audio routing.
- **The lens**: brightness, contrast, focus distance, field of view, how text
  reads in daylight. Screenshots use a generic font; the glasses use their own.
- **The phone**: OS share sheets, file pickers, QR scanning, in-app sign-in,
  permission prompts, background limits, battery.
- **The camera**: real photos, video, live streams and their upload.
- **Cloud answers**: AI, maps, sign-in tokens and speech synthesis.

## Next steps

- [Quickstart](https://docs.glasslyos.com/app-devs/getting-started/quickstart.md)
Run the same project on a phone and glasses.
- [AI IDE integration](https://docs.glasslyos.com/app-devs/getting-started/ai-ide-integration.md)
Tell your coding agent how to use the simulator.
