docs/ez-agent-ruby/internal/launcher.md
Ruby runtime launcher
This directory owns the Go launcher behind the self-extracting ez-agent-ruby
wrapper: it selects, installs, verifies, and executes a private Ruby runtime.
Wrong page?
- To use the wrapper, see ez-agent-ruby.
- To build the payload, see package-runtime.
- For the shared payload contract, see runtimepayload.
- To extend EzAgent from Ruby, see the Ruby add-on.
What does the launcher own, and where?
| Role | Location |
|---|---|
| Process boundary | cmd/ez-agent-ruby/main.go calls launcher.Run(payload, os.Args[1:]). |
| CLI, install, execution, cleanup | launcher.go |
| State document and safe paths | state.go |
| Shared manifest authority | internal/runtimepayload/manifest.go |
| Payload producer | cmd/package-runtime/main.go |
Run handles launcher management requests or replaces itself with the installed
runtime's bin/ruby. It does not own Ruby library APIs, JSONL frames, daemon
behavior, the CRuby build, or the payload schema.
How does a launch obtain a runtime?
The launcher uses a strict state document at
${XDG_DATA_HOME:-$HOME/.local/share}/ez-agent/ez-agent-ruby.json; it records
the selected runtime and related settings. CLI parsing deliberately treats
--ez-runtime-home as a leading option and --save as applying only before a
management operation. Ordinary Ruby arguments pass through unchanged.
Installation derives an ID from the payload, serializes access with a lock, and reuses only an already valid runtime. Valid reuse needs no writer lock or state rewrite when the selected runtime is unchanged. A new runtime is extracted into a private temporary directory, validated, then atomically renamed into place. Extraction respects the process umask. Installed files need owner read access and owner execute access where the payload requires it, not exact archive modes. Read-only files and tighter group/other permissions remain valid. The launcher never widens existing permissions. Existing invalid trees remain untouched, and installation errors include the failed validation check.
Automatic selection may fall back only after an EACCES probe failure to a
secure $HOME/.local/bin base, creating it if missing. Existing directories are
not chmodded; an explicit runtime home never falls back. Safe sticky ancestors
are permitted for both group-write and other-write access, not only the directory
named by TMPDIR. Removing world access from a trusted sticky ancestor does not
make it unsafe.
What do the management operations do?
launcher.go:Run routes help, runtime path/info, installation, verification,
notices, and pruning before Ruby execution. --ez-runtime-verify checks rather
than installs or repairs. Notices are read from
share/ez-agent-ruby/NOTICES.txt. Pruning is intentionally conservative: it
considers only runtime-ID-shaped siblings and requires full installed-tree
validation before deletion. Historical schema-1 Ruby versions and revisions can
be pruned, but cannot satisfy current-payload reuse. Verification checks the
recorded selected runtime, including a noexec fallback, unless the caller
explicitly supplies a different runtime home.
Which safety boundaries must edits preserve?
- Keep payload identity and target-platform checks exact; identity rules belong
to
runtimepayload, not a launcher-specific copy. - Require ZIP entries to match the strict manifest exactly, and validate the installed tree's ownership, usable permissions, paths, and checksums before reuse. Reject group/other write access and privilege-changing executable bits, not harmless read access or removed owner-write access.
- Treat existing incomplete or corrupt destinations as failures: installation never repairs them in place.
- Keep state parsing strict: user-owned, regular, non-symlink file without
group/other write access; no unknown or duplicate JSON sections, trailing data,
or unsafe paths. State and completion manifests contain no credentials, so
harmless read permissions are allowed. Newly written state remains
0600. Explicit--saveoperations still report persistence failures. - Sanitize Ruby and Bundler injection environment variables for both the runtime
probe and the final
syscall.Exec. - Keep
--ez-runtime-verifynon-mutating. Pruning may delete only a fully valid, non-selected sibling after safe quarantine; malformed or raced candidates stay.
Where is the authoritative detail?
- Command parsing and lifecycle:
launcher.go(parseCLI,Run,Install,parsePayload,extract,validateInstalled,prune). - State format and filesystem policy:
state.go. - Manifest semantics:
internal/runtimepayload/manifest.go. - Behavior and security coverage:
launcher_test.go,state_test.go,internal/runtimepayload/manifest_test.go, andcmd/package-runtime/main_test.go. - Wrapper-facing behavior: ez-agent-ruby; Ruby extension APIs start at the Ruby add-on.