Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/test-suite-registry.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
"pkgs/id/examples/roc-chat/**",
"pkgs/id/examples/roc-counter/**",
"pkgs/id/examples/roc-grid/**",
"pkgs/id/examples/roc-mind-map/**",
"pkgs/id/examples/roc-screen/**",
"pkgs/id/examples/roc-text-counter/**",
"pkgs/id/examples/territory/**",
Expand Down
7 changes: 4 additions & 3 deletions pkgs/id/book/design/first-apps.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ The did-it data model has its own investigation: `2026-10-29T13-04-50Z_investiga
- Early surfaces. `2026-03-20T05-30-00Z_feature_collaborative_cursor_enhancements` (2026-03-20) and `2026-03-23T00:00:00Z_feature_file_list_ui` (2026-03-23) are the earliest records in this theme — collaborative cursors and the file list UI of the pre-worlds editor generation. `2026-04-01T00-00-00Z_feature_multi_instance` covers multi-instance support for `id`. `2026-10-17T09-00-00Z_feature_world_fixtures` designs session recording to replayable fixtures, the testing base the app designs rely on.
- Games and assets. `2026-11-08T09-14-46Z_research_id5988_prior_art_bot_games_programmable_worlds` is the prior-art research on scripted-bot battle games and user-programmable worlds. `2026-11-06T00-50-21Z_design_dynamic_world_tick_cost` designs the dynamic-world per-tick cost model and the bot-battle benchmark. `2026-11-08T00-57-08Z_design_shader_asset_format` designs the shader asset format v1. `2026-10-16T15-00-00Z_feature_roc_grid` is the RocGrid record — a bounds-checked grid library for world programs, the library the grid guest app demonstrates.

## The shipped first apps: the 9 Roc guest apps
## The shipped first apps: the 10 Roc guest apps

The platform's working first apps are the 9 deployable Roc guest apps in `pkgs/id/examples/`, plus the one packaged app. They run on the shared Plaza platform (`examples/roc-world/`), whose guest shape is fixed: every app provides `init`, `update`, `view`, `layout`, `records`, `wants`, `snapshot` and `restore`; guests are compiled to import-free Wasm modules with no WASI, no filesystem, network, clock or randomness imports; all effects go through the capability protocol, with requests answered as participant-0 events and refusals returned as events with stable error codes (`cap_denied`, `unknown_cap`, `bad_args`, `failed`, `actor_denied`, `outside_ceiling`, `result_too_large`). The full platform treatment is in [Design: worlds and the guest runtime](worlds-runtime.md).
The platform's working first apps are the 10 deployable Roc guest apps in `pkgs/id/examples/`, plus the one packaged app. They run on the shared Plaza platform (`examples/roc-world/`), whose guest shape is fixed: every app provides `init`, `update`, `view`, `layout`, `records`, `wants`, `snapshot` and `restore`; guests are compiled to import-free Wasm modules with no WASI, no filesystem, network, clock or randomness imports; all effects go through the capability protocol, with requests answered as participant-0 events and refusals returned as events with stable error codes (`cap_denied`, `unknown_cap`, `bad_args`, `failed`, `actor_denied`, `outside_ceiling`, `result_too_large`). The full platform treatment is in [Design: worlds and the guest runtime](worlds-runtime.md).

| App | Location | What it is |
|---|---|---|
Expand All @@ -30,6 +30,7 @@ The platform's working first apps are the 9 deployable Roc guest apps in `pkgs/i
| roc-text-counter | `examples/roc-text-counter/` | The no-Screen legacy-text twin of roc-counter; keeps the plain-text presentation path covered (#3181). |
| roc-chat | `examples/roc-chat/` | Minimal chat client on `RocCap` with `chat.say` and `chat.history`; typing `hist` shows the newest 8 lines. |
| roc-grid | `examples/roc-grid/` | RocGrid demo: a 4×3 byte grid, `set` claims the centre cell, bounds-checked reads with fallback. |
| roc-mind-map | `examples/roc-mind-map/` | Mind map for `mind-map/same-label-distinct-nodes` (#13609): stable node IDs, a typed `related` cross-link that survives reparent and rename, refused single-history cycles, preserved positions. |
| roc-screen | `examples/roc-screen/` | Screen and Key demo: a bordered-box counter screen document; presenters render the structured grid. |
| territory | `examples/territory/` | Multiplayer territory game: at most 8 seated players on a 16×8 grid, adjacency-only claiming, seats persist across leave, rejoin and restart. |
| roc-cap-demo | `examples/roc-cap-demo/` | Library-import worked example (#5957): a capability-dependent Roc library over `records.read`, with two compile-must-fail negative tests. |
Expand Down Expand Up @@ -62,7 +63,7 @@ An example with invented data, following the v1 design: a creator exports the pr

Grounding, from the library survey for this book (checkout `1ccb4a19457`, 2026-11-23):

- Shipped: the 9 Roc guest apps and the packaged tic-tac-toe app listed in the table above, with checked-in Wasm artifacts beside most apps so host conformance suites run without a Roc toolchain. These are the first apps in the literal sense: working guest programs on the shipped Plaza platform.
- Shipped: the 10 Roc guest apps and the packaged tic-tac-toe app listed in the table above, with checked-in Wasm artifacts beside most apps so host conformance suites run without a Roc toolchain. These are the first apps in the literal sense: working guest programs on the shipped Plaza platform.
- Shipped: the program-side machinery the ecosystem designs build on — the program registry and gallery surface named in the CLI (`gallery`, `publish`, `unpublish`, `publications` command families exist in the shipped CLI table), and the bundle record path the #10662 listing design distinguishes itself from: author-signed bundle records with author, name, version and payload hash, fetched by content hash and verified on the bundle path.
- Shipped as a proof of concept only: the first app of #2031 — sticky notes plus did-it — exists as the integration test `tests/first_app_poc.rs` and a README in `examples/first-app-poc/`. It is not a packaged application.
- Still design: the ecosystem ladder as designed — signed bundle export/import/fork as the v1 user flow (#6291 is a design record; the record states no implementation code is in it), the gallery as a registry with update channels (#6293, design only), the hosted public gallery as an operated instance (#6294, design only), and creator tooling (#6308, design only). The chat v1, boards and match-attestation designs are likewise design records; the shipped chat and boards functionality in the `id` program is the earlier application surface documented in the reference chapters, not an implementation of these v1 designs — the records themselves make no completion claim, and this chapter makes none for them.
1 change: 1 addition & 0 deletions pkgs/id/book/development/add-a-guest.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Worked examples live in `pkgs/id/examples/`. Each app is a directory holding its
| `examples/roc-text-counter/` | The same counter on the legacy plain-text presentation, importing no platform modules. |
| `examples/roc-chat/` | Chat over the capability protocol: `chat.say` and `chat.history` through `RocCap`. |
| `examples/roc-grid/` | The `RocGrid` library: a 4×3 byte grid with bounds-checked reads. |
| `examples/roc-mind-map/` | Stable IDs with duplicate labels, a typed cross-link, refused cycles, preserved positions. |
| `examples/roc-screen/` | The `Screen` and `Key` libraries: a structured screen document instead of text. |
| `examples/lounge/` | The capability system end to end: subscriptions, arrival greetings through `chat.say`, and refusal counting. |
| `examples/territory/` | A complete multiplayer game: at most 8 seated players on a 16×8 grid, adjacency-only claiming, seats that persist across leave, rejoin and restart. |
Expand Down
5 changes: 3 additions & 2 deletions pkgs/id/book/library/guests-and-shells.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ The runtime provider set named in `ABI.md` is `time.now`, `time.tick` (subscribe

The Roc client library is `RocCap`: a session issuing request ids `r0`, `r1`, and so on, with `issue`, `attach`, `requests`, and `route`, and builders `chat_request`, `now_request`, `players_request`, `world_request`, `history_request`, `records_request`, `schedule_at_request`, and `schedule_cancel_request`.

## The nine Roc guest apps
## The ten Roc guest apps

Checked-in `.wasm` artefacts sit beside most apps, so the host conformance suites run without a Roc toolchain. `pkgs/id/apps/tic-tac-toe/` is the sole packaged app; the other eight live in `pkgs/id/examples/`.
Checked-in `.wasm` artefacts sit beside most apps, so the host conformance suites run without a Roc toolchain. `pkgs/id/apps/tic-tac-toe/` is the sole packaged app; the other nine live in `pkgs/id/examples/`.

| App | Location | What it does |
|---|---|---|
Expand All @@ -49,6 +49,7 @@ Checked-in `.wasm` artefacts sit beside most apps, so the host conformance suite
| roc-text-counter | `examples/roc-text-counter/` | The no-`Screen` legacy-text twin of roc-counter: imports no platform modules and keeps the plain-text presentation path covered (#3181). |
| roc-chat | `examples/roc-chat/` | Minimal chat client on `RocCap` with `chat.say` and `chat.history`; typing `hist` shows the newest 8 lines. |
| roc-grid | `examples/roc-grid/` | `RocGrid` demo: a 4×3 byte grid where `set` claims the centre cell; bounds-checked reads with a fallback. |
| roc-mind-map | `examples/roc-mind-map/` | Mind map for `mind-map/same-label-distinct-nodes` (#13609): nodes distinguished by stable ID with duplicate `Archive` labels, a typed `related` cross-link through reparent and rename, refused single-history cycles, preserved positions; `records` and `snapshot` publish the same domain document. |
| roc-screen | `examples/roc-screen/` | `Screen` and `Key` demo: a bordered-box counter screen document, `+` increments; presenters (SSH ANSI, browser DOM) render the structured grid. |
| territory | `examples/territory/` | Multiplayer territory game: at most 8 seated players on a 16×8 grid, adjacency-only claiming, seats persist across leave, rejoin, and restart. |
| roc-cap-demo | `examples/roc-cap-demo/` | Library-import worked example (#5957): a capability-dependent Roc library (`lib/Greeter.roc` over `records.read`) plus its app, with two compile-must-fail negative tests — a missing capability on `platform-no-caps.roc`, and a wrong `RocCap` signature. |
Expand Down
74 changes: 74 additions & 0 deletions pkgs/id/crates/id-worlds/src/sandbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2106,6 +2106,80 @@ mod tests {
assert!(text.contains("cells=11 at11=65 out=63"), "{text}");
}

#[test]
fn checked_in_mind_map_replays_same_label_distinct_nodes() {
// Oracle: mind-map/same-label-distinct-nodes in app-vectors.json
// (revision b9d8177). Inputs carry the event tag stripped; the after
// states below are literal copies of the vector projections.
let wasm = include_bytes!("../../../examples/roc-mind-map/mind-map.wasm");
let runner = Sandbox::compile(wasm, SandboxLimits::default()).unwrap();
let mut live = runner.instantiate(7).unwrap();
let records = |world: &mut WorldInstance| -> serde_json::Value {
serde_json::from_slice(&world.records().unwrap().unwrap()).unwrap()
};
let nodes = |u_name: &str, u_parent: &str| -> serde_json::Value {
serde_json::json!([
{"id": "P", "name": "North", "parent": "R", "position": [0, 1]},
{"id": "Q", "name": "South", "parent": "R", "position": [2, 1]},
{"id": "R", "name": "World", "parent": null, "position": [1, 0]},
{"id": "U", "name": u_name, "parent": u_parent, "position": [0, 2]},
{"id": "V", "name": "Archive", "parent": "Q", "position": [2, 2]}
])
};
// (input, expected outcome, expected after-state)
let steps = [
(
r#"{"kind":"AddCrossLink","source":"U","target":"V"}"#,
"linked",
serde_json::json!({
"root": "R",
"nodes": nodes("Archive", "P"),
"cross_links": [{"from": "U", "to": "V"}]
}),
),
(
r#"{"kind":"Reparent","id":"U","new_parent":"Q"}"#,
"moved",
serde_json::json!({
"root": "R",
"nodes": nodes("Archive", "Q"),
"cross_links": [{"from": "U", "to": "V"}]
}),
),
(
r#"{"kind":"Rename","id":"U","name":"Inbox"}"#,
"renamed",
serde_json::json!({
"root": "R",
"nodes": nodes("Inbox", "Q"),
"cross_links": [{"from": "U", "to": "V"}]
}),
),
(
r#"{"kind":"Reparent","id":"Q","new_parent":"U"}"#,
"refused-cycle",
serde_json::json!({
"root": "R",
"nodes": nodes("Inbox", "Q"),
"cross_links": [{"from": "U", "to": "V"}]
}),
),
];
assert_eq!(records(&mut live)["nodes"], nodes("Archive", "P"));
for (input, outcome, after) in steps {
live.update(1, input.as_bytes()).unwrap();
let doc = records(&mut live);
assert_eq!(doc["outcome"], outcome, "{input}");
assert_eq!(doc["root"], after["root"], "{input}");
assert_eq!(doc["nodes"], after["nodes"], "{input}");
assert_eq!(doc["cross_links"], after["cross_links"], "{input}");
}
let snapshot = live.snapshot().unwrap().unwrap();
let mut restored = runner.instantiate(7).unwrap();
restored.restore(&snapshot).unwrap();
assert_eq!(records(&mut restored), records(&mut live));
}

#[test]
fn checked_in_chat_example_sends_and_reads_history() {
use crate::world::{WorldEvent, WorldEventKind};
Expand Down
40 changes: 40 additions & 0 deletions pkgs/id/examples/roc-mind-map/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Roc Mind Map Example

A playable mind-map world for `mind-map/same-label-distinct-nodes` (#13609).
Nodes are distinguished by stable ID, so two nodes can share the label
"Archive". A typed cross-link (`related`) keeps pointing at its node through
reparent and rename. A reparent that would put a node under its own descendant
is refused and leaves the tree unchanged. Positions never change.

Inputs are JSON commands:

- `{"kind":"AddCrossLink","source":"U","target":"V"}` links U to V (`linked`).
- `{"kind":"Reparent","id":"U","new_parent":"Q"}` moves U under Q (`moved`).
- `{"kind":"Rename","id":"U","name":"Inbox"}` relabels U (`renamed`).
- `{"kind":"Reparent","id":"Q","new_parent":"U"}` is refused (`refused-cycle`):
Q would land under its own descendant U, so the tree is unchanged.

`records` publishes the domain state (`root`, `nodes` with `id`/`name`/`parent`/`position`,
`cross_links`, and the last `outcome`); `snapshot` is the same document, so a
snapshot restored into a fresh instance compares byte-identical through the
regular host. The view draws the nodes on a portable screen with the last
outcome and the link list.

## Build

```bash
./build.sh
```

Produces `mind-map.wasm`, validated as an import-free Wasm module.

## Run

```bash
id serve --data-dir ./data --world --world-admin-token "$ADMIN" \
--world-module "$PWD/examples/roc-mind-map/mind-map.wasm" \
--world-ssh-port 2223 --web --port 8787
```

Join with SSH or the web page and send an input such as
`{"kind":"Rename","id":"U","name":"Inbox"}` to relabel U.
43 changes: 43 additions & 0 deletions pkgs/id/examples/roc-mind-map/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")"
export ROC="${ROC:-roc}"
source ../roc-toolchain.sh

if [ -z "${WASM_TOOLS:-}" ]; then
if command -v wasm-tools >/dev/null 2>&1; then
WASM_TOOLS="wasm-tools"
else
STORE_TOOL=$(ls -d /nix/store/*-wasm-tools-*/bin/wasm-tools 2>/dev/null | head -n1 || true)
if [ -n "$STORE_TOOL" ] && [ -x "$STORE_TOOL" ]; then
WASM_TOOLS="$STORE_TOOL"
else
WASM_TOOLS="nix run nixpkgs#wasm-tools --"
fi
fi
fi

if [ -z "${WASM_OPT:-}" ]; then
if command -v wasm-opt >/dev/null 2>&1; then
WASM_OPT="wasm-opt"
else
STORE_OPT=$(ls -d /nix/store/*-binaryen-*/bin/wasm-opt 2>/dev/null | head -n1 || true)
if [ -n "$STORE_OPT" ] && [ -x "$STORE_OPT" ]; then
WASM_OPT="$STORE_OPT"
else
WASM_OPT="nix shell nixpkgs#binaryen --command wasm-opt"
fi
fi
fi

(cd ../roc-world && ./build-host.sh >/dev/null)
"$ROC" build main.roc --target=wasm32 --wasm-memory=8454144 --output=mind-map.wasm

# Same size discipline as roc-grid: optimize, strip DWARF, keep the name section
# so Wasmtime traps still resolve, then validate the import-free module.
$WASM_OPT -Os --all-features mind-map.wasm -o mind-map.wasm.opt
mv mind-map.wasm.opt mind-map.wasm
$WASM_TOOLS strip mind-map.wasm -o mind-map.wasm.stripped
mv mind-map.wasm.stripped mind-map.wasm
$WASM_TOOLS validate mind-map.wasm
echo "Built mind-map.wasm (import-free Roc world module)"
Loading