[PR #2626] [MERGED] launcher: pre-launch command, wrapper and environment per instance #4488

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

📋 Pull Request Information

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

Base: main ← Head: feat/launcher-instance-commands


📝 Commits (1)

  • 7115c70 launcher: pre-launch command, wrapper and environment per instance

📊 Changes

14 files changed (+646 additions, -6 deletions)

View changed files

📝 docs/launcher-commands.md (+13 -0)
📝 launcher/README.md (+8 -0)
📝 launcher/src/cli.rs (+52 -1)
📝 launcher/src/cli_tools.rs (+2 -0)
📝 launcher/src/import/tests.rs (+1 -0)
📝 launcher/src/instances.rs (+14 -3)
📝 launcher/src/instances/tests.rs (+12 -0)
📝 launcher/src/instances_page.rs (+22 -1)
➕ launcher/src/launch.rs (+220 -0)
➕ launcher/src/launch/tests.rs (+143 -0)
➕ launcher/src/launch_page.rs (+137 -0)
📝 launcher/src/lib.rs (+1 -0)
📝 launcher/src/main.rs (+12 -0)
📝 launcher/src/servers_page.rs (+9 -1)

📄 Description

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

Clean room: designed from the feature list in briefs/launcher-features-1.md; no other launcher's code, docs or assets were read.

Launcher features, item 15: a pre-launch command, a wrapper command and environment variables per instance. Stacked on #2625 (shortcuts).

  • Launch… on Home's Instance row opens a panel for the selected instance. It has three fields, Save, and a line saying what the next Play will do:
    • Before the game: a shell command, run in the instance's folder. The game starts only if it succeeds.
    • Run the game through: a wrapper and its arguments. Quotes group a word, as in Game arguments.
    • Environment variables: NAME=value OTHER="two words", for the game and both commands.
  • New horizon_launcher::launch. wrap() runs last, after every argument (session file, quick play, game arguments), and turns the game's command into one process, so Console, Stop, exit codes, play time and While playing keep working:
    • Unix: /bin/sh -c '(<pre-launch>) || { message; exit $s; }; exec "$@"' horizon <wrapper…> <game> <args…>.
      • The game's words pass through "$@", so the shell never parses them.
      • exec makes the shell become the wrapper, then the game.
      • The pre-launch command runs in a subshell, so an exit in it still prints the message.
    • Windows: cmd /D /S /C "<pre-launch> && <words…>", each word quoted the way the C runtime reads it back.
    • With only a wrapper and variables, no shell runs at all.
  • Stored as launch in each instance's instances.json entry. Empty means nothing, and nothing is written.
  • The window's Play (also a pack's Play, through its instance) and horizon-launcher play both use it.
  • CLI and MCP: instance launch <instance> [--pre-launch …] [--wrapper …] [--env …]; with no options it shows the current ones, and an empty value clears one.
    • It is in DESTRUCTIVE, so an agent needs confirm: true. It sets shell commands the player's next Play runs, so the player should say yes first.
  • Two fixes found while testing:
    • The Instance row's six actions now sit under the name and wrap. Beside it they overlapped the play time, and at the window's minimum width they couldn't fit.
    • Editing anything about an instance that shares its name with an import (an own "Hardcore" and a ported "Hardcore") failed with "There is already an instance called Hardcore". Only a rename checks the name now. There is a test for it.
  • launcher/README.md: a Launch options bullet.

Proof

  • fmt, clippy -D warnings and the launcher tests: clean and passing (179 + 36). The new tests cover:
    • variables, read and written back;
    • the summary;
    • each system's plan;
    • Windows quoting (spaces, quotes, trailing backslashes);
    • an empty Launch, which leaves the command untouched;
    • a real Unix run. The pre-launch command wrote a file in the folder, then the wrapper (/usr/bin/env) and the "game" ran. The game got a b and a literal $HOME unparsed, plus both the launcher's and the instance's variables. A failing exit 3 exits 3 with the message and never starts the game.
  • CLI, scratch homes: instance launch hardcore --pre-launch 'echo "backed up" > pre.txt' --wrapper '/usr/bin/env HORIZON_WRAPPED=1' --env 'LF1_VAR="hello there"'.
    • Then play --instance hardcore: the fake game printed LF1_VAR=hello there HORIZON_WRAPPED=1 in hardcore, and pre.txt said backed up.
    • With --pre-launch 'exit 3': "The pre-launch command failed (exit 3), so the game did not start.", exit 1.
  • Window: the panel showed the CLI's values. Play ran the pre-launch command (pre.txt written) and the wrapped game, with its log in the Console.
  • Not checked: the failing case in the window. The Mac's screen locked before I could click through it.
  • Not checked: Windows. There is no Windows machine for this work; the cmd line is covered by the unit test.
Instance row Launch panel

🤖 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/2626 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/27/2026 **Status:** ✅ Merged **Merged:** 10/27/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat/launcher-instance-commands` --- ### 📝 Commits (1) - [`7115c70`](https://github.com/horizon-rust/horizon/commit/7115c708e110e7077f8c4ca037295ad52e3db267) launcher: pre-launch command, wrapper and environment per instance ### 📊 Changes **14 files changed** (+646 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `docs/launcher-commands.md` (+13 -0) 📝 `launcher/README.md` (+8 -0) 📝 `launcher/src/cli.rs` (+52 -1) 📝 `launcher/src/cli_tools.rs` (+2 -0) 📝 `launcher/src/import/tests.rs` (+1 -0) 📝 `launcher/src/instances.rs` (+14 -3) 📝 `launcher/src/instances/tests.rs` (+12 -0) 📝 `launcher/src/instances_page.rs` (+22 -1) ➕ `launcher/src/launch.rs` (+220 -0) ➕ `launcher/src/launch/tests.rs` (+143 -0) ➕ `launcher/src/launch_page.rs` (+137 -0) 📝 `launcher/src/lib.rs` (+1 -0) 📝 `launcher/src/main.rs` (+12 -0) 📝 `launcher/src/servers_page.rs` (+9 -1) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Clean room: designed from the feature list in briefs/launcher-features-1.md; no other launcher's code, docs or assets were read. Launcher features, item 15: a pre-launch command, a wrapper command and environment variables per instance. Stacked on #2625 (shortcuts). - **Launch…** on Home's Instance row opens a panel for the selected instance. It has three fields, Save, and a line saying what the next Play will do: - **Before the game**: a shell command, run in the instance's folder. The game starts only if it succeeds. - **Run the game through**: a wrapper and its arguments. Quotes group a word, as in Game arguments. - **Environment variables**: `NAME=value OTHER="two words"`, for the game and both commands. - New `horizon_launcher::launch`. `wrap()` runs last, after every argument (session file, quick play, game arguments), and turns the game's command into **one process**, so Console, Stop, exit codes, play time and While playing keep working: - Unix: `/bin/sh -c '(<pre-launch>) || { message; exit $s; }; exec "$@"' horizon <wrapper…> <game> <args…>`. - The game's words pass through `"$@"`, so the shell never parses them. - `exec` makes the shell become the wrapper, then the game. - The pre-launch command runs in a subshell, so an `exit` in it still prints the message. - Windows: `cmd /D /S /C "<pre-launch> && <words…>"`, each word quoted the way the C runtime reads it back. - With only a wrapper and variables, no shell runs at all. - Stored as `launch` in each instance's `instances.json` entry. Empty means nothing, and nothing is written. - The window's Play (also a pack's Play, through its instance) and `horizon-launcher play` both use it. - CLI and MCP: `instance launch <instance> [--pre-launch …] [--wrapper …] [--env …]`; with no options it shows the current ones, and an empty value clears one. - It is in `DESTRUCTIVE`, so an agent needs `confirm: true`. It sets shell commands the player's next Play runs, so the player should say yes first. - Two fixes found while testing: - The Instance row's six actions now sit under the name and wrap. Beside it they overlapped the play time, and at the window's minimum width they couldn't fit. - Editing anything about an instance that shares its name with an import (an own "Hardcore" and a ported "Hardcore") failed with "There is already an instance called Hardcore". Only a rename checks the name now. There is a test for it. - launcher/README.md: a Launch options bullet. ## Proof - fmt, clippy `-D warnings` and the launcher tests: clean and passing (179 + 36). The new tests cover: - variables, read and written back; - the summary; - each system's plan; - Windows quoting (spaces, quotes, trailing backslashes); - an empty `Launch`, which leaves the command untouched; - a real Unix run. The pre-launch command wrote a file in the folder, then the wrapper (`/usr/bin/env`) and the "game" ran. The game got `a b` and a literal `$HOME` unparsed, plus both the launcher's and the instance's variables. A failing `exit 3` exits 3 with the message and never starts the game. - CLI, scratch homes: `instance launch hardcore --pre-launch 'echo "backed up" > pre.txt' --wrapper '/usr/bin/env HORIZON_WRAPPED=1' --env 'LF1_VAR="hello there"'`. - Then `play --instance hardcore`: the fake game printed `LF1_VAR=hello there HORIZON_WRAPPED=1 in hardcore`, and `pre.txt` said `backed up`. - With `--pre-launch 'exit 3'`: "The pre-launch command failed (exit 3), so the game did not start.", exit 1. - Window: the panel showed the CLI's values. Play ran the pre-launch command (`pre.txt` written) and the wrapped game, with its log in the Console. - Not checked: the failing case in the window. The Mac's screen locked before I could click through it. - Not checked: Windows. There is no Windows machine for this work; the `cmd` line is covered by the unit test. | Instance row | Launch panel | |---|---| | ![](https://raw.githubusercontent.com/ludovic111/horizon/screenshots/launcher-features/launch/row.png) | ![](https://raw.githubusercontent.com/ludovic111/horizon/screenshots/launcher-features/launch/panel.png) | 🤖 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:17:31 +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#4488
No description provided.