# LodaLiteWeb browser TTY demo

A one-page browser demo with two runtimes:

```text
Browser tab
└── JS hypervisor
    └── Rust no_std Wasm guest
          scenario loop
          event replay
          golden comparison
          configurable logical clock
          character-cell screen layout
          scroll and navigation
          browser favorites and page mode
          Markdown report
```

There is no Python, Pyodide, Node runtime, Playwright, Chromium, or backend at
runtime. The local Python server only serves static files.

## Published demo

<https://llw.livive.net/>

GitHub Pages deploys `.github/workflows/pages.yml` on every push to `main`.
The workflow builds the Wasm guest, captures the three favorite pages into
static text, and publishes `browser-demo` plus `_site/pages/*.txt`.

## Run locally

```bash
cd browser-demo
./build.sh
```

Then open:

```text
http://127.0.0.1:8000/
```

`build.sh` builds `lodalite-web-wasm` for `wasm32-unknown-unknown`, copies the
`.wasm` into the demo, and starts the static server.

Use a different port:

```bash
PORT=8080 ./build.sh
```

## What the page does

- Instantiates the Rust Wasm guest
- Reads the Rust-emitted UI manifest
- Builds the icon navigation bar and resolution selector from the manifest
- Asks Rust to render the startup browser screen
- Starts at 100×36 by default; screen size is configurable at runtime
- Sends semantic actions to Rust
- Paints the returned screen text into one `<pre>`
- Loads favorite URLs through the local `/page` text proxy
- Writes fetched page text into Rust page memory

The appliance now uses a full-viewport shell. The browser pane fills the
available space; the screen font is fitted to the pane with `ResizeObserver`
and recalculated on resolution changes and inspector docking.

JS does not compose cards, metrics, or view layout. It loads Wasm, reads the
manifest, forwards actions, and paints the screen.

## Browser modes

```text
Startup  default browser shell
Viewer   six text snapshots and timing
Help     generated keyboard help
Page     fetched text page
Quit     closed screen; Enter restarts
```

The startup screen is the default path. The address is editable state.

## Actions

Startup:

```text
Enter  Open address
e      Edit address
?      Show keyboard help
Esc    Return to startup
q      Quit
```

Viewer:

```text
R  run scenario
X  reset
A  previous view
D  next view
W  scroll up
S  scroll down
1  1000 Hz
2  60 Hz
3  10 Hz
4  1 Hz
```

The navigation bar contains icon buttons:

```text
←  Back
→  Forward
↻  Refresh
✕  Cancel / return to startup
⌖  Address / edit address
★  Favorites menu
▦  Resolution menu
```

## Display profiles

The Rust contract emits display profiles and the browser builds a resolution
selector from them:

```text
phone-portrait     40 x 66   portrait
phone-landscape    72 x 30   landscape
tablet-portrait    64 x 48   portrait
tablet-landscape   96 x 32   landscape
desktop            100 x 36  landscape
desktop-wide       140 x 44  landscape
```

The `▦` Resolution menu lists the display profiles and applies the selected
profile to the current mode and content.

## Favorites

The Rust contract emits:

```text
favorite|cp.livive.net/login|https://cp.livive.net/login
favorite|lexd.livive.net|https://lexd.livive.net/
favorite|mo-lab.livive.net|https://mo-lab.livive.net/
```

Clicking `Favorites` opens the manifest-generated menu. Selecting a favorite:

1. writes the URL into Rust address memory
2. shows a loading page
3. fetches text through `serve.py` at `/page?url=...`
4. writes the page text into Rust page memory
5. switches the machine to `Page` mode

## Rust Wasm exports

```text
lod_manifest_render
lod_manifest_ptr / lod_manifest_len
lod_manual_render
lod_manual_ptr / lod_manual_len
lod_help_render
lod_help_ptr / lod_help_len

lod_action
lod_action2
lod_set_screen_size
lod_text_input / lod_text_backspace / lod_editing
lod_address_input_ptr / lod_address_input_capacity / lod_set_address
lod_page_input_ptr / lod_page_input_capacity / lod_set_page

lod_meta_render / lod_meta_ptr / lod_meta_len
lod_event_render / lod_event_ptr / lod_event_len / lod_event_dropped
lod_console_render / lod_console_ptr / lod_console_len / lod_console_dropped
lod_console_input_ptr / lod_console_input_capacity / lod_console_add
lod_network_render / lod_network_ptr / lod_network_len / lod_network_dropped
lod_network_begin / lod_network_end
lod_storage_render / lod_storage_ptr / lod_storage_len
lod_storage_input_ptr / lod_storage_input_capacity / lod_storage_set
lod_storage_get / lod_storage_delete / lod_storage_clear_session
lod_heap_render / lod_heap_ptr / lod_heap_len
lod_heap_capacity / lod_heap_used / lod_heap_oom_count
lod_gc_render / lod_gc_ptr / lod_gc_len / lod_gc_begin / lod_gc_step
lod_engine_render / lod_engine_ptr / lod_engine_len / lod_engine_event

lod_screen_render
lod_screen_ptr / lod_screen_len
lod_screen_rows / lod_screen_cols
lod_selected_view / lod_scroll

lod_run_all
lod_render_view
lod_output_ptr / lod_output_len
lod_view_match
lod_matched_count
lod_report_ptr / lod_report_len

lod_set_timebase / lod_timebase_hz
lod_view_scheduled_ms
lod_view_tick
lod_view_elapsed_ms
lod_clock_tick / lod_elapsed_ms / lod_elapsed_us

lod_view_count / lod_view_name_ptr / lod_view_name_len
lod_phase / lod_transitions / lod_user_id / lod_job_id / lod_detail_job_id
lod_abi_version
```

## Telemetry buffers

The machine now exposes:

```text
metadata
event log
console log
network log
storage
heap
GC
engine lifecycle
```

They are fixed-capacity, allocation-free, and separate from the display. The
manifest announces their capacities with `buffer|...` lines.

Inspect all buffers from the browser console:

```js
window.lodaTelemetry()
```

It returns:

```text
meta, events, console, network, storage, heap, gc, engine
```

## DevTools inspector

The `▤` toolbar icon opens a docked DevTools drawer under the appliance.
The browser pane and inspector share the viewport; the splitter is draggable.
Panels are generated from the manifest:

```text
Metadata, Events, Console, Network, Storage, Heap, GC, Engine
```

The drawer refreshes live from the Rust buffers. `F12` toggles it; `Esc` closes
it while open.

Manifest entries:

```text
nav|▤|devtools|0|DevTools|
devtools|toggle|F12
devtools|panel|meta|Metadata
devtools|panel|events|Events
devtools|panel|console|Console
devtools|panel|network|Network
devtools|panel|storage|Storage
devtools|panel|heap|Heap
devtools|panel|gc|GC
devtools|panel|engine|Engine
```

## UI manifest

Rust emits the manifest from `lodalite-web-rs/src/contract.rs`. The JS
hypervisor builds the controls from it. JS contains no action IDs, rate values,
labels, key bindings, or download filenames.

Example:

```text
schema|contract|1
abi|16
title|LodaLiteWeb — browser TTY
subtitle|JS hypervisor + Rust no_std text screen
screen|100|36
screen_bounds|40|240|12|80
display_action|17
open_action|7
display|phone-portrait|Phone portrait|40|66|portrait
display|phone-landscape|Phone landscape|72|30|landscape
display|tablet-portrait|Tablet portrait|64|48|portrait
display|tablet-landscape|Tablet landscape|96|32|landscape
display|desktop|Desktop|100|36|landscape
display|desktop-wide|Desktop wide|140|44|landscape
browser|startup|about:start
nav|←|button|13|Back|
nav|→|button|14|Forward|
nav|↻|button|15|Refresh|
nav|✕|button|16|Cancel|
nav|⌖|button|9|Address|
nav|★|menu|0|Favorites|favorites
nav|▦|menu|0|Resolution|display
nav|▤|devtools|0|DevTools|
devtools|toggle|F12
devtools|panel|meta|Metadata
devtools|panel|events|Events
devtools|panel|console|Console
devtools|panel|network|Network
devtools|panel|storage|Storage
devtools|panel|heap|Heap
devtools|panel|gc|GC
devtools|panel|engine|Engine
favorite|cp.livive.net/login|https://cp.livive.net/login
favorite|lexd.livive.net|https://lexd.livive.net/
favorite|mo-lab.livive.net|https://mo-lab.livive.net/
rate_action|2
rate|1000|1000 Hz|1
rate|60|60 Hz|2
rate|10|10 Hz|3
rate|1|1 Hz|4
mode|as_fast_as_possible
pacing|none|500
clock|logical
rate_limit|token_bucket|10|1000|10|client|logical|queue|true
timing|reply_timeout_ms|2000|propagation_ms|500|queued_counts|true|reply_before_timeout|true
consistency|eventual
wait|await_reply
event_order|tick,phase,sequence
action|0|Run|R|button|primary
action|1|Reset|X|button|secondary
action|3|Prev|A|button|secondary
action|4|Next|D|button|secondary
action|5|PgUp|W|button|secondary
action|6|PgDn|S|button|secondary
action|2|Clock||select|secondary
action|7|Open address|Enter|button|primary
action|8|Show keyboard help|?|button|secondary
action|9|Edit address|e|button|secondary
action|10|Quit|q|button|secondary
action|11|Startup|Esc|button|secondary
action|12|Screen size||hidden|secondary
action|13|Back||hidden|secondary
action|14|Forward||hidden|secondary
action|15|Refresh||hidden|secondary
action|16|Cancel||hidden|secondary
action|17|Display profile||hidden|secondary
arg|2|hz|rate|required|rates
arg|12|cols|u32|required|40..240
arg|12|rows|u32|required|12..80
download|screen|screen.txt|screen|
download|report|report.md|report|
download|manual|manual.txt|manual|
download|help|help.txt|help|
state|0|idle
state|1|login
state|2|dashboard
state|3|job_detail
buffer|meta|4096
buffer|event|256|32768
buffer|console|128|32768
buffer|network|128|65536
buffer|storage|128|32768
buffer|heap|5|1966080
buffer|gc|512
buffer|engine|512
schema|manifest|1
schema|provenance|1
provenance|crate|lodalite-web-wasm
provenance|version|0.0.1
provenance|source_commit|<git commit>
provenance|source_dirty|false
provenance|rustc_version|1.99.1
provenance|rustc_commit|<rustc commit>
provenance|rustc_host|aarch64-apple-darwin
provenance|cargo_version|1.99.1
provenance|target|wasm32-unknown-unknown
provenance|profile|release
provenance|opt_level|s
provenance|build_id|<build id>
fingerprint|contract|0x<contract fingerprint>
```

## Help and manual

Rust emits `help.txt` as the short usage guide and `manual.txt` as the full
instruction manual. Both are generated from the same contract.

`help.txt` contains:

- machine title and subtitle
- version and source commit
- ABI and contract fingerprint
- action ids and names
- rates
- outputs

`manual.txt` contains:

- ABI and screen geometry
- runtime rules
- action ids, names, labels, keys, controls, and arguments
- rates
- outputs
- states
- execution mode and pacing
- rate limiting
- reply timeout and propagation window
- consistency and wait policy
- event ordering
- replay rules
- toolchain and build provenance

The machine exposes both through the ABI. The current browser UI does not
expose download buttons; a host can read `lod_help_*` and `lod_manual_*` and
provide its own download controls.

## GitHub Pages fallback

GitHub Pages is static, so `/page?url=...` is unavailable there. The Pages
build captures the three favorites into `pages/*.txt` and writes `pages.json`.
The browser tries the local proxy first, then falls back to the captured text.

Typed addresses outside the captured favorites show a static-deployment message.

## Provenance

`lodalite-web-wasm/build.rs` captures:

- crate name, version, license, repository
- git commit, tree, dirty state
- rustc version, commit, host
- cargo version
- target triple
- profile and optimization level
- enabled features
- build timestamp
- build id

The manifest carries these fields and a stable contract fingerprint. The
contract fingerprint excludes volatile build data.

## Clock rates

```text
1000 Hz
  60 Hz
  10 Hz
   1 Hz
```

View times are scheduled canonically in milliseconds, then converted to logical
ticks with ceiling quantization. At 1 Hz, a 500 ms event becomes tick 1 and
displays 1000 ms elapsed. The rendered text stays identical across rates; only
timing metadata changes.

## Layout

```text
browser-demo/
├── index.html         controls + one text screen
├── hypervisor.js      Wasm load, action forwarding, screen paint, DevTools
├── serve.py           static server + favorite-page text proxy
├── build_site.py      GitHub Pages static builder + page capture
├── CNAME              llw.livive.net
├── build.sh           build + serve
├── lodalite.wasm      generated Wasm guest (ignored by git)
└── styles.css
```

## Notes

- The startup screen is the default view at 100×36.
- The browser chrome is a manifest-generated icon nav bar with Back, Forward, Refresh, Cancel, Address, Favorites, and a Resolution menu.
- Screen size is configurable via display profiles or the hidden `set_screen_size` action / `lod_set_screen_size`.
- The six generated views match the committed goldens exactly.
- Goldens are embedded into the Wasm guest at build time.
- The screen is composed in `no_std` Rust into a fixed character grid.
- Wrapping, scrolling, selection, timing, comparison, report generation, policy
  metadata, and the machine manual are all inside Rust.
- Pacing, timeout, propagation, consistency, and token-bucket rate-limit
  primitives live in `lodalite-web-rs/src/policy.rs`.
- No allocation is used in the Rust guest.
- Build provenance is static data injected by `build.rs`.
