cli

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package cli provides CLI discovery, version validation, and command building for the Codex CLI binary.

This package provides three main capabilities:

CLI Discovery

The Discoverer interface locates and validates the Codex CLI binary:

discoverer := cli.NewDiscoverer(&cli.Config{
    CliPath: "",           // Optional explicit path
    Logger:  slog.Default(),
})
cliPath, err := discoverer.Discover(ctx)

Discovery searches in the following order:

  1. Explicit path in Config.CliPath (if provided)
  2. System PATH
  3. Common installation directories (/usr/local/bin, /usr/bin, ~/.local/bin)

Version Validation

During discovery, the CLI version is validated against MinimumVersion (2.0.0). A warning is logged if the version is below minimum. Version checking can be skipped via Config.SkipVersionCheck or the CODEX_AGENT_SDK_SKIP_VERSION_CHECK environment variable.

Command Building

The package provides functions to build CLI command arguments and environment:

args := cli.BuildExecArgs("prompt", options)
env := cli.BuildEnvironment(options)

Index

Constants

View Source
const (
	// BinaryName is the name of the Codex CLI binary.
	BinaryName = "codex"

	// MinimumVersion is the minimum required Codex CLI version.
	MinimumVersion = "0.103.0"

	// VersionCheckTimeout is the timeout for the CLI version check command.
	VersionCheckTimeout = 2 * time.Second
)

Variables

This section is empty.

Functions

func BuildAppServerArgs

func BuildAppServerArgs(options *config.Options) []string

BuildAppServerArgs constructs the CLI argument list for `codex app-server`.

func BuildEnvironment

func BuildEnvironment(options *config.Options) []string

BuildEnvironment constructs the environment variables for the CLI process.

func BuildExecArgs

func BuildExecArgs(prompt string, options *config.Options) []string

BuildExecArgs constructs the CLI argument list for a one-shot `codex exec` invocation.

Types

type Command

type Command struct {
	// Args are the command line arguments.
	Args []string

	// Env are the environment variables.
	Env []string
}

Command represents the CLI command to execute.

type Config

type Config struct {
	// CliPath is an explicit CLI path that skips PATH search.
	CliPath string

	// SkipVersionCheck skips version validation during discovery.
	// Can also be controlled via CODEX_CLI_SKIP_VERSION_CHECK env var.
	SkipVersionCheck bool

	// Logger is an optional logger for discovery operations.
	Logger *slog.Logger
}

Config holds configuration for CLI discovery.

type Discoverer

type Discoverer interface {
	// Discover locates the Codex CLI binary and validates its version.
	Discover(ctx context.Context) (string, error)
}

Discoverer locates and validates the Codex CLI binary.

func NewDiscoverer

func NewDiscoverer(cfg *Config) Discoverer

NewDiscoverer creates a new CLI discoverer with the given configuration.

Jump to

Keyboard shortcuts

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