[PR #1833] [MERGED] Mod API 0.3 (experimental): server mods' contract, runtime and SDK #3799

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

📋 Pull Request Information

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

Base: main ← Head: feat/server-mods-0.3


📝 Commits (2)

  • c9f554d Mod API 0.3 (experimental): server mods' contract, runtime and SDK
  • b90ab85 Merge remote-tracking branch 'origin/main' into feat/server-mods-0.3

📊 Changes

16 files changed (+984 additions, -128 deletions)

View changed files

📝 Cargo.lock (+7 -0)
📝 Cargo.toml (+1 -1)
📝 crates/cargo-horizon-mod/src/check.rs (+53 -26)
📝 crates/horizon-client/src/game/mods.rs (+7 -2)
➕ crates/horizon-mod-sdk/examples/welcome/Cargo.toml (+16 -0)
➕ crates/horizon-mod-sdk/examples/welcome/horizon-mod.toml (+8 -0)
➕ crates/horizon-mod-sdk/examples/welcome/src/lib.rs (+84 -0)
📝 crates/horizon-mod-sdk/src/lib.rs (+151 -1)
📝 crates/horizon-mod-sdk/wit/horizon.wit (+88 -0)
📝 crates/horizon-mods/src/manifest.rs (+52 -5)
📝 crates/horizon-mods/src/runtime.rs (+307 -78)
📝 crates/horizon-mods/tests/sandbox.rs (+76 -1)
📝 docs/api/mods-reference.md (+84 -1)
📝 docs/api/mods.md (+16 -11)
📝 docs/api/stability.md (+1 -1)
📝 docs/mods.md (+33 -1)

📄 Description

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

Stacked on #1816 (the test runner): review and merge that first; this PR's diff is against its branch.

What

Workstream 3, part 1: the server mods' contract, runtime and SDK (manifest api = "0.3", experimental). The next PR makes the game call it on the server thread, LAN host and dedicated server; this one changes nothing in game (the game starts only client mods, and shows a server mod that is on as run elsewhere).

Designed from what a server owner asks of a mod (greet players, keep per-player counts, answer commands, react to chat and building), and from Horizon's shape: one sandbox, the same component model, calls batched per tick.

interface players {            // capability `players`
    online: func() -> list<player>;                      // id, name, x y z, dimension, game-mode, health
    tell: func(player: string, text: string) -> bool;    // false when not online
    broadcast: func(text: string);                       // 8 lines per call, shared with chat
}
interface server-events {      // exported by the mod
    init, tick, player-joined, player-left, chat(player, text),
    command(player, name, args) -> result<option<string>, string>,
    block-broken(player, pos, state), block-placed(player, pos, state)
}
world horizon-server-mod { import log; import storage; import players; export server-events; }
  • Manifest: side = "server" ⇔ api = "0.3"; game-read, chat, hud are refused on a server mod and players on a client mod, with a message naming the capability.
  • Runtime (horizon-mods): a second bindgen world sharing log and storage; a running mod holds client or server hooks; Mods::load_for(Runs::{Client, Server, Both}, …) starts what a game runs and marks the rest Status::Elsewhere; new calls server_tick, player_joined/left, player_chat, server_command (feedback is an Output::Reply to that player), block_broken/placed; outputs Tell, Broadcast, Reply. Client and server commands are owned separately. Same fuel, memory and line limits.
  • SDK: horizon_mod_sdk::server::{ServerMod, Registration} and export_server_mod!; example examples/welcome (greets, announces a newcomer once, kept in storage; /online; /mined counts blocks broken).
  • cargo horizon-mod check: the trial run plays a server mod with a player who joins, chats, types each of its commands and leaves.
  • Docs: generated mods-reference.md (+85, the new world and interfaces), docs/mods.md "Server mods (API 0.3, experimental)", the portal's Mod API page and the stability table.

Mods::load keeps its meaning (starts everything) for tools; the game uses load_for(Runs::Client). The cdylib example builds on the macOS host too (no new --exclude).

How tested

  • cargo test -p horizon-mods --features runtime,pack --test sandbox: 16 passed; new a_server_mod_runs_only_where_the_world_does (the window's load marks it Elsewhere and runs nothing; the server's load owns /online and /mined, not the window's chat; a join gives the greeting Tell and the newcomer Broadcast; a broken block then /mined → Reply "You broke 1 block(s)", /online → "Alex (the_nether)"; an unknown command is refused), run twice (storage starts empty).
  • cargo test -p horizon-mods --features runtime,pack,index --lib: 26 passed; new server_mods_are_api_0_3_with_server_capabilities.
  • api_reference (3 tests) with the regenerated reference; cargo test -p cargo-horizon-mod.
  • pr_ready --quick (against main, so it counts #1816 too): fmt, clippy (workspace), doc tests, launcher checks ✅; workspace tests 1465 passed, 1 failed: this PR's own new test on a re-run with storage left from the first run, fixed in this commit (now run twice, both pass).

Size

+983 −111 against #1816: generated reference 85, docs 63, example 108, tests 85, SDK 152, WIT 88, runtime 361 (the hook calls are refactored to serve both worlds), manifest 57. It is one contract: the runtime test needs the example, the example the SDK.

Needs Ludovic

Nothing to decide. Contributor PR #1677 (capability command) also edits horizon.wit, manifest.rs, runtime.rs and the reference; whichever lands second takes a mechanical merge.

🤖 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/1833 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/25/2026 **Status:** ✅ Merged **Merged:** 10/26/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat/server-mods-0.3` --- ### 📝 Commits (2) - [`c9f554d`](https://github.com/horizon-rust/horizon/commit/c9f554d1c4842ce6b408f5db95479879df545cd5) Mod API 0.3 (experimental): server mods' contract, runtime and SDK - [`b90ab85`](https://github.com/horizon-rust/horizon/commit/b90ab85f448d9c32b89dfaf40a8fef683b113bf7) Merge remote-tracking branch 'origin/main' into feat/server-mods-0.3 ### 📊 Changes **16 files changed** (+984 additions, -128 deletions) <details> <summary>View changed files</summary> 📝 `Cargo.lock` (+7 -0) 📝 `Cargo.toml` (+1 -1) 📝 `crates/cargo-horizon-mod/src/check.rs` (+53 -26) 📝 `crates/horizon-client/src/game/mods.rs` (+7 -2) ➕ `crates/horizon-mod-sdk/examples/welcome/Cargo.toml` (+16 -0) ➕ `crates/horizon-mod-sdk/examples/welcome/horizon-mod.toml` (+8 -0) ➕ `crates/horizon-mod-sdk/examples/welcome/src/lib.rs` (+84 -0) 📝 `crates/horizon-mod-sdk/src/lib.rs` (+151 -1) 📝 `crates/horizon-mod-sdk/wit/horizon.wit` (+88 -0) 📝 `crates/horizon-mods/src/manifest.rs` (+52 -5) 📝 `crates/horizon-mods/src/runtime.rs` (+307 -78) 📝 `crates/horizon-mods/tests/sandbox.rs` (+76 -1) 📝 `docs/api/mods-reference.md` (+84 -1) 📝 `docs/api/mods.md` (+16 -11) 📝 `docs/api/stability.md` (+1 -1) 📝 `docs/mods.md` (+33 -1) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Stacked on #1816 (the test runner): review and merge that first; this PR's diff is against its branch. ## What Workstream 3, part 1: the **server mods' contract, runtime and SDK** (manifest `api = "0.3"`, experimental). The next PR makes the game call it on the server thread, LAN host and dedicated server; this one changes nothing in game (the game starts only client mods, and shows a server mod that is on as run elsewhere). Designed from what a server owner asks of a mod (greet players, keep per-player counts, answer commands, react to chat and building), and from Horizon's shape: one sandbox, the same component model, calls batched per tick. ```wit interface players { // capability `players` online: func() -> list<player>; // id, name, x y z, dimension, game-mode, health tell: func(player: string, text: string) -> bool; // false when not online broadcast: func(text: string); // 8 lines per call, shared with chat } interface server-events { // exported by the mod init, tick, player-joined, player-left, chat(player, text), command(player, name, args) -> result<option<string>, string>, block-broken(player, pos, state), block-placed(player, pos, state) } world horizon-server-mod { import log; import storage; import players; export server-events; } ``` - **Manifest**: `side = "server"` ⇔ `api = "0.3"`; `game-read`, `chat`, `hud` are refused on a server mod and `players` on a client mod, with a message naming the capability. - **Runtime** (`horizon-mods`): a second bindgen world sharing `log` and `storage`; a running mod holds client or server hooks; `Mods::load_for(Runs::{Client, Server, Both}, …)` starts what a game runs and marks the rest `Status::Elsewhere`; new calls `server_tick`, `player_joined/left`, `player_chat`, `server_command` (feedback is an `Output::Reply` to that player), `block_broken/placed`; outputs `Tell`, `Broadcast`, `Reply`. Client and server commands are owned separately. Same fuel, memory and line limits. - **SDK**: `horizon_mod_sdk::server::{ServerMod, Registration}` and `export_server_mod!`; example `examples/welcome` (greets, announces a newcomer once, kept in `storage`; `/online`; `/mined` counts blocks broken). - **`cargo horizon-mod check`**: the trial run plays a server mod with a player who joins, chats, types each of its commands and leaves. - **Docs**: generated `mods-reference.md` (+85, the new world and interfaces), `docs/mods.md` "Server mods (API 0.3, experimental)", the portal's Mod API page and the stability table. `Mods::load` keeps its meaning (starts everything) for tools; the game uses `load_for(Runs::Client)`. The `cdylib` example builds on the macOS host too (no new `--exclude`). ## How tested - `cargo test -p horizon-mods --features runtime,pack --test sandbox`: 16 passed; new `a_server_mod_runs_only_where_the_world_does` (the window's load marks it Elsewhere and runs nothing; the server's load owns `/online` and `/mined`, not the window's chat; a join gives the greeting `Tell` and the newcomer `Broadcast`; a broken block then `/mined` → `Reply "You broke 1 block(s)"`, `/online` → `"Alex (the_nether)"`; an unknown command is refused), run twice (storage starts empty). - `cargo test -p horizon-mods --features runtime,pack,index --lib`: 26 passed; new `server_mods_are_api_0_3_with_server_capabilities`. - `api_reference` (3 tests) with the regenerated reference; `cargo test -p cargo-horizon-mod`. - `pr_ready --quick` (against main, so it counts #1816 too): fmt, clippy (workspace), doc tests, launcher checks ✅; workspace tests 1465 passed, 1 failed: this PR's own new test on a re-run with storage left from the first run, fixed in this commit (now run twice, both pass). ## Size +983 −111 against #1816: generated reference 85, docs 63, example 108, tests 85, SDK 152, WIT 88, runtime 361 (the hook calls are refactored to serve both worlds), manifest 57. It is one contract: the runtime test needs the example, the example the SDK. ## Needs Ludovic Nothing to decide. Contributor PR #1677 (capability `command`) also edits `horizon.wit`, `manifest.rs`, `runtime.rs` and the reference; whichever lands second takes a mechanical merge. 🤖 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:12:23 +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#3799
No description provided.