launcher

package
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 31 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package launcher runs one routed Codex session: it makes the runtime dir, starts and probes the proxy, starts the private app-server with -c overrides only, connects the router client, wires the engine to the app-server and control socket, then runs `codex --remote`. If any startup step fails it runs plain codex and says why.

Index

Constants

View Source
const (
	RuntimeDirName = "codex-router"
	AppSocketName  = "app.sock"
	PortFileName   = "proxy.port"
	// EnvToken holds the proxy's per-session token in the app-server's env.
	// Codex sends it as proxy.HeaderToken through env_http_headers, so the
	// value never appears in argv, which other uids can read.
	EnvToken = "CODEX_ROUTER_TOKEN"
)

Names inside the runtime dir and the app-server's env.

Variables

This section is empty.

Functions

func Fallback

func Fallback(o Options, reason error) error

Fallback prints one line with the reason and replaces the process with plain `codex <args>`. It returns only when that fails, or when a test's Options.Exec returns.

func ProviderOverrides

func ProviderOverrides(port int) []string

ProviderOverrides returns the -c values that point Codex at the proxy on port. requires_openai_auth makes Codex send its own ChatGPT auth, which the proxy forwards upstream only. env_http_headers sends $CODEX_ROUTER_TOKEN as the proxy token; Codex leaves the header out when the variable is unset.

func RouterDeps added in v0.3.0

func RouterDeps(o Options, log *slog.Logger) (route.Deps, *catalog.Store)

RouterDeps returns the engine's config, classifier, logger and the Codex home of o's env, with a catalog seeded read-only from $CODEX_HOME/models_cache.json; the caller sets Sink and Cwd. An unresolvable home is the zero Home.

func Run

func Run(ctx context.Context, o Options) (int, error)

Run runs one routed Codex session and returns codex's exit code (128+N when a signal N ended it). If a startup step fails it prints one line why and replaces the process with plain `codex <args>` through Options.Exec; the returned error is then Exec's. A signal during startup aborts it without the fallback.

func RuntimeBase

func RuntimeBase(getenv func(string) string) string

RuntimeBase returns the parent of the per-session runtime dirs (plan D7): $XDG_RUNTIME_DIR/codex-router, else $TMPDIR/codex-router, else /tmp/codex-router. Relative values are ignored.

func Serve

func Serve(ctx context.Context, o Options, ready func(port int)) error

Serve runs the proxy and engine alone, without app-server or Codex, until ctx ends: for debugging and `codex exec` runs pointed at it with ProviderOverrides. ready gets the port once the health probe passes. The port is Config.Proxy.Port (0 = ephemeral). It has no token, so any local uid can use it: a debugging tool, not for shared hosts.

Types

type Options

type Options struct {
	Config config.Config
	// RuntimeDir is the parent of the per-session dirs; empty means
	// RuntimeBase of Env.
	RuntimeDir string
	// CodexBin is the codex executable; empty means Config.CodexBin, else
	// "codex" on PATH.
	CodexBin  string
	CodexArgs []string
	// Env is the environment for codex and for the router's own lookups
	// (classifier key, CODEX_HOME, XDG dirs); nil means os.Environ().
	Env    []string
	Stderr io.Writer // nil means os.Stderr
	// Logger replaces the default log: a JSON file under the XDG state dir
	// for Run, JSON on Stderr for Serve.
	Logger *slog.Logger
	// Upstream overrides the proxy backend; tests only.
	Upstream string
	// Probe checks the proxy on port; nil means GET /healthz within 2 s.
	Probe func(ctx context.Context, port int) error
	// Exec replaces the process with plain codex on fallback; nil means
	// syscall.Exec.
	Exec func(path string, argv, env []string) error
}

Options configure Run and Serve.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL