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
- func Fallback(o Options, reason error) error
- func ProviderOverrides(port int) []string
- func RouterDeps(o Options, log *slog.Logger) (route.Deps, *catalog.Store)
- func Run(ctx context.Context, o Options) (int, error)
- func RuntimeBase(getenv func(string) string) string
- func Serve(ctx context.Context, o Options, ready func(port int)) error
- type Options
Constants ¶
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 ¶
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 ¶
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
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 ¶
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 ¶
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 ¶
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.