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?

What does the launcher own, and where?

RoleLocation
Process boundarycmd/ez-agent-ruby/main.go calls launcher.Run(payload, os.Args[1:]).
CLI, install, execution, cleanuplauncher.go
State document and safe pathsstate.go
Shared manifest authorityinternal/runtimepayload/manifest.go
Payload producercmd/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 private 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. A new runtime is extracted into a private temporary directory, validated, then atomically renamed into place. Automatic selection may fall back only after an EACCES probe failure, and only to an existing, secure $HOME/.local/bin base; an explicit runtime home never takes that path.

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.

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, modes, paths, and checksums before reuse.
  • Treat existing incomplete or corrupt destinations as failures: installation never repairs them in place.
  • Keep state parsing strict: user-owned, regular, non-symlink, restrictive file; no unknown or duplicate JSON sections, trailing data, or unsafe paths.
  • Sanitize Ruby and Bundler injection environment variables for both the runtime probe and the final syscall.Exec.
  • Keep --ez-runtime-verify non-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, and cmd/package-runtime/main_test.go.
  • Wrapper-facing behavior: ez-agent-ruby; Ruby extension APIs start at the Ruby add-on.