[PR #2080] [MERGED] Mod API levels: refuse a mod made for a newer Horizon, list each version's level #3992

Closed
opened 2026-11-03 04:13:51 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/2080
Author: @ludovic111
Created: 10/26/2026
Status: ✅ Merged
Merged: 10/26/2026
Merged by: @ludovic111

Base: main ← Head: feat/mod-api-level


📝 Commits (4)

  • 8cc8c61 Mod API levels: refuse a mod made for a newer Horizon, list each version's level
  • 6c995bf Merge remote-tracking branch 'origin/main' into feat/mod-api-level
  • 0a9a7c0 Merge remote-tracking branch 'origin/main' into feat/mod-api-level
  • b12c896 Mod API levels: server mods' players functions are level 1; the registry's lockfile

📊 Changes

18 files changed (+436 additions, -16 deletions)

View changed files

📝 Cargo.lock (+24 -0)
📝 crates/cargo-horizon-mod/src/check.rs (+4 -0)
📝 crates/horizon-client/src/moved_extras.rs (+11 -11)
📝 crates/horizon-mod-registry/Cargo.lock (+24 -0)
📝 crates/horizon-mods/Cargo.toml (+9 -2)
➕ crates/horizon-mods/src/api_level.rs (+154 -0)
📝 crates/horizon-mods/src/index.rs (+32 -1)
📝 crates/horizon-mods/src/index/registry.rs (+1 -0)
📝 crates/horizon-mods/src/index/tests.rs (+33 -0)
📝 crates/horizon-mods/src/lib.rs (+1 -0)
📝 crates/horizon-mods/src/runtime.rs (+6 -0)
📝 crates/horizon-mods/tests/api_reference.rs (+35 -0)
📝 crates/horizon-mods/tests/index/index-v1.json (+1 -0)
📝 crates/horizon-mods/tests/sandbox.rs (+59 -0)
📝 docs/api/mod-index.md (+4 -2)
📝 docs/api/stability.md (+16 -0)
📝 docs/mods.md (+6 -0)
📝 launcher/Cargo.lock (+16 -0)

📄 Description

🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself.

A mod made for a newer Horizon fails today with a wasmtime linking error. Minimap 1.0.0 is published and calls render.set-minimap, which v0.2.69 doesn't have, so a v0.2.69 player who installs it sees that error. This PR gives every mod API function a level, reads a mod's level from its file, and uses it in three places: the game says "update Horizon", the registry lists each version's level, and the game's installer takes a version it can run.

What players and modders get

  • API levels (crates/horizon-mods/src/api_level.rs). Every function the game offers mods has the level it arrived at:
    • level 0 is the contract of Horizon 0.2.67 to 0.2.69 (I compared their WIT with main's; the functions added since are render.set-minimap and, from #1833, server mods' players.online, tell and broadcast);
    • level 1 adds those four.
    • A mod needs the level of the newest function it imports. A component imports only the functions it calls: FPS Counter, Keystrokes and Zoom need level 0, Minimap needs level 1. Nobody declares the level: it is read from the component.
  • The game refuses a mod made for a newer Horizon in plain words. It checks before linking. Options > Mods shows "did not start: made for a newer Horizon (it uses render.set-sky): update Horizon to run it" instead of a linking error.
  • The registry index lists each mod version's level as api_level. The registry's CI reads it from the file, as it reads capabilities.
    • check_file compares it when the entry has one. An index built before levels lists none, and its files still pass.
    • Index::installable(project, game, level) picks the newest version that this game version can run and that wasn't taken down. The game's moved-extras installer uses it.
  • cargo horizon-mod check prints "needs mod API level N or newer", and puts api_level in --json.
  • Adding a function: a PR that adds a WIT function lists it in api_level.rs at the next level and raises LEVEL. The api_reference test fails until it does. This is documented in docs/api/stability.md (Mod API levels), docs/mods.md and docs/api/mod-index.md.

Games already released (v0.2.69 and older) can't be changed: they keep the linking error. From the release that ships this, the game says "update Horizon". The launcher's browser is the next PR: it will hide or mark versions above the installed game's level. Once this is on main and HORIZON_REV moves to it, the published index gets api_level on every version, Zoom and Minimap included, with no change to their entries.

How tested

  • Sandbox test a_mod_for_a_newer_horizon_is_refused: a real component built from the WIT plus a function this Horizon doesn't have (render.set-sky) is refused with the message above. coords_hud reads as level 0 and the UI guest, which calls set-minimap, as level 1.
  • api_reference: every function a world imports has a level, and the table lists nothing else.
  • Index tests:
    • a wrong level is refused, and no level passes;
    • installable skips a version above the game's level, follows the Minecraft version, and treats an unlisted level as runnable.
  • The four published official mods read with api_level::imports:
    • FPS Counter: ui.set-settings, render.set-corner, render.text-width, render.frame-stats, storage.get, storage.set (level 0);
    • Zoom: level 0;
    • Keystrokes: level 0;
    • Minimap: render.set-minimap (level 1).
  • The parser is wasmparser 0.254, already in the tree through wasmtime and wit-component. The test-only wat is pinned to the same wasm-tools line, so no second copy is built.

Self-check:

pr_ready (tools/pr_ready.py --quick on ludovics-mac-mini, against origin/main at 45bc45b39, 9 min 35 s)

Check Result
Scope ⚠️ 17 files, +412 −16; mixes game, launcher
Cargo.lock ✅ changes with a Cargo.toml
Public tree ✅
Python tests ➖ no Python change
rustfmt ✅ (7 s)
clippy ✅ (1 min 21 s)
tests: workspace ✅ 2181 passed (5 min 43 s)
doc tests ✅ 1 passed (1 min 7 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ✅ (1 s)
launcher clippy ✅ (9 s)
launcher tests ✅ 129 passed (1 min 6 s)
Parity ➖ 338 affected, to run in CI (--quick): active_effect_tick, active_effects, ambient_sound, anchor, arrow, attribute_health, attribute_map_queries, attribute, attribute_updates, audio_attributes, auto_jump, bamboo and 326 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

The "mixes game, launcher" note is only launcher/Cargo.lock, which picks up wasmparser through horizon-mods' index feature. No label: it fixes how a too-new mod fails.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/2080 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/26/2026 **Status:** ✅ Merged **Merged:** 10/26/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat/mod-api-level` --- ### 📝 Commits (4) - [`8cc8c61`](https://github.com/horizon-rust/horizon/commit/8cc8c6180d729d345d41d4bc0093d8108ca5c730) Mod API levels: refuse a mod made for a newer Horizon, list each version's level - [`6c995bf`](https://github.com/horizon-rust/horizon/commit/6c995bfa154ee931dfdf10dc7f861f2782efa39c) Merge remote-tracking branch 'origin/main' into feat/mod-api-level - [`0a9a7c0`](https://github.com/horizon-rust/horizon/commit/0a9a7c0d0644787658b30ce22b39fbbcf1f2b37a) Merge remote-tracking branch 'origin/main' into feat/mod-api-level - [`b12c896`](https://github.com/horizon-rust/horizon/commit/b12c89650ed0d7d0f02c7e2bf2a475c3b962e9a3) Mod API levels: server mods' players functions are level 1; the registry's lockfile ### 📊 Changes **18 files changed** (+436 additions, -16 deletions) <details> <summary>View changed files</summary> 📝 `Cargo.lock` (+24 -0) 📝 `crates/cargo-horizon-mod/src/check.rs` (+4 -0) 📝 `crates/horizon-client/src/moved_extras.rs` (+11 -11) 📝 `crates/horizon-mod-registry/Cargo.lock` (+24 -0) 📝 `crates/horizon-mods/Cargo.toml` (+9 -2) ➕ `crates/horizon-mods/src/api_level.rs` (+154 -0) 📝 `crates/horizon-mods/src/index.rs` (+32 -1) 📝 `crates/horizon-mods/src/index/registry.rs` (+1 -0) 📝 `crates/horizon-mods/src/index/tests.rs` (+33 -0) 📝 `crates/horizon-mods/src/lib.rs` (+1 -0) 📝 `crates/horizon-mods/src/runtime.rs` (+6 -0) 📝 `crates/horizon-mods/tests/api_reference.rs` (+35 -0) 📝 `crates/horizon-mods/tests/index/index-v1.json` (+1 -0) 📝 `crates/horizon-mods/tests/sandbox.rs` (+59 -0) 📝 `docs/api/mod-index.md` (+4 -2) 📝 `docs/api/stability.md` (+16 -0) 📝 `docs/mods.md` (+6 -0) 📝 `launcher/Cargo.lock` (+16 -0) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. A mod made for a newer Horizon fails today with a wasmtime linking error. Minimap 1.0.0 is published and calls `render.set-minimap`, which v0.2.69 doesn't have, so a v0.2.69 player who installs it sees that error. This PR gives every mod API function a level, reads a mod's level from its file, and uses it in three places: the game says "update Horizon", the registry lists each version's level, and the game's installer takes a version it can run. ## What players and modders get - **API levels** (`crates/horizon-mods/src/api_level.rs`). Every function the game offers mods has the level it arrived at: - level 0 is the contract of Horizon 0.2.67 to 0.2.69 (I compared their WIT with main's; the functions added since are `render.set-minimap` and, from #1833, server mods' `players.online`, `tell` and `broadcast`); - level 1 adds those four. - A mod needs the level of the newest function it imports. A component imports only the functions it calls: FPS Counter, Keystrokes and Zoom need level 0, Minimap needs level 1. Nobody declares the level: it is read from the component. - **The game refuses a mod made for a newer Horizon in plain words.** It checks before linking. Options > Mods shows "did not start: made for a newer Horizon (it uses render.set-sky): update Horizon to run it" instead of a linking error. - **The registry index lists each mod version's level** as `api_level`. The registry's CI reads it from the file, as it reads capabilities. - `check_file` compares it when the entry has one. An index built before levels lists none, and its files still pass. - `Index::installable(project, game, level)` picks the newest version that this game version can run and that wasn't taken down. The game's moved-extras installer uses it. - **`cargo horizon-mod check`** prints "needs mod API level N or newer", and puts `api_level` in `--json`. - **Adding a function:** a PR that adds a WIT function lists it in `api_level.rs` at the next level and raises `LEVEL`. The `api_reference` test fails until it does. This is documented in `docs/api/stability.md` (Mod API levels), `docs/mods.md` and `docs/api/mod-index.md`. Games already released (v0.2.69 and older) can't be changed: they keep the linking error. From the release that ships this, the game says "update Horizon". The launcher's browser is the next PR: it will hide or mark versions above the installed game's level. Once this is on `main` and `HORIZON_REV` moves to it, the published index gets `api_level` on every version, Zoom and Minimap included, with no change to their entries. ## How tested - **Sandbox test `a_mod_for_a_newer_horizon_is_refused`:** a real component built from the WIT plus a function this Horizon doesn't have (`render.set-sky`) is refused with the message above. `coords_hud` reads as level 0 and the UI guest, which calls `set-minimap`, as level 1. - **`api_reference`:** every function a world imports has a level, and the table lists nothing else. - **Index tests:** - a wrong level is refused, and no level passes; - `installable` skips a version above the game's level, follows the Minecraft version, and treats an unlisted level as runnable. - **The four published official mods** read with `api_level::imports`: - FPS Counter: `ui.set-settings`, `render.set-corner`, `render.text-width`, `render.frame-stats`, `storage.get`, `storage.set` (level 0); - Zoom: level 0; - Keystrokes: level 0; - Minimap: `render.set-minimap` (level 1). - The parser is wasmparser 0.254, already in the tree through wasmtime and wit-component. The test-only `wat` is pinned to the same wasm-tools line, so no second copy is built. **Self-check**: **pr_ready** (`tools/pr_ready.py --quick` on ludovics-mac-mini, against origin/main at 45bc45b39, 9 min 35 s) | Check | Result | | --- | --- | | Scope | ⚠️ 17 files, +412 −16; mixes game, launcher | | Cargo.lock | ✅ changes with a Cargo.toml | | Public tree | ✅ | | Python tests | ➖ no Python change | | rustfmt | ✅ (7 s) | | clippy | ✅ (1 min 21 s) | | tests: workspace | ✅ 2181 passed (5 min 43 s) | | doc tests | ✅ 1 passed (1 min 7 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ✅ (1 s) | | launcher clippy | ✅ (9 s) | | launcher tests | ✅ 129 passed (1 min 6 s) | | Parity | ➖ 338 affected, to run in CI (--quick): active_effect_tick, active_effects, ambient_sound, anchor, arrow, attribute_health, attribute_map_queries, attribute, attribute_updates, audio_attributes, auto_jump, bamboo and 326 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | The "mixes game, launcher" note is only `launcher/Cargo.lock`, which picks up wasmparser through horizon-mods' `index` feature. No label: it fixes how a too-new mod fails. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 04:13:51 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#3992
No description provided.