codex

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyCodexConfigDir added in v0.1.8

func ApplyCodexConfigDir(sessionDir, configDir string) error

ApplyCodexConfigDir overlays configDir into sessionDir when configDir != "".

func BuildArgs

func BuildArgs(prompt string, configOverrides []string, ignoreUserConfig bool, resumeSessionID string) []string

BuildArgs constructs codex CLI arguments for non-interactive execution. Uses "codex exec --json" with config overrides via -c flags. When ignoreUserConfig is true, appends --ignore-user-config (legacy default). When false (config_dir active), omits it so overlayed $CODEX_HOME/config.toml and skills under CODEX_HOME can load; -c overrides still win for Tern keys. When resumeSessionID != "", uses "codex exec resume <id>" to continue a thread. When prompt is non-empty, "-" is appended to instruct codex to read from stdin.

func BuildConfigOverrides

func BuildConfigOverrides(model, gatewayURL, wireAPI string) []string

BuildConfigOverrides constructs "-c key=value" CLI arguments to override Codex configuration inline. This is the most reliable way to configure Codex, avoiding any config.toml file discovery issues.

func BuildEnv

BuildEnv constructs environment variables from AdapterConfig and SessionConfig.

func DetectStdinWaitFromStderr added in v0.1.2

func DetectStdinWaitFromStderr(line string) (bool, string)

DetectStdinWaitFromStderr reports whether a stderr line indicates stdin wait.

func DetectUserInputFromExecEvent added in v0.1.2

func DetectUserInputFromExecEvent(line string) *codingagent.StreamEvent

DetectUserInputFromExecEvent parses a JSONL line for explicit user-input events. Returns nil unless the event has a structured choices field (R12: no heuristics).

func GenerateConfigTOML

func GenerateConfigTOML(model, gatewayURL, wireAPI string) string

GenerateConfigTOML generates a Codex config.toml string. wireAPI should be "chat" or "responses". Defaults to "chat" if empty.

func ParseExecEvent

func ParseExecEvent(line string) *codingagent.StreamEvent

ParseExecEvent converts a JSONL line from "codex exec --json" to a StreamEvent. Handles both nested format (Codex CLI 0.139.0+) and flat format (backward compat). Returns nil for events that don't map to StreamEvent types.

func WriteConfigTOML

func WriteConfigTOML(model, gatewayURL, wireAPI string) (string, error)

WriteConfigTOML writes a config.toml to a CODEX_HOME directory and returns the directory path. Codex CLI reads config from $CODEX_HOME/config.toml automatically. Note: Codex CLI refuses CODEX_HOME under OS temp dirs, so we use the user's home directory with a unique subdirectory. The caller is responsible for cleaning up the directory after use.

Types

type CodexAdapter

type CodexAdapter struct {
	// contains filtered or unexported fields
}

CodexAdapter is a CodingAgent implementation using the Codex CLI.

func New

New creates a CodexAdapter.

func (*CodexAdapter) Close

func (a *CodexAdapter) Close() error

Close stops all active processes and releases resources.

func (*CodexAdapter) CreateSession

func (a *CodexAdapter) CreateSession(
	ctx context.Context, opts ...codingagent.SessionOption,
) (codingagent.Session, error)

CreateSession starts a new Codex session by launching the CLI subprocess.

func (*CodexAdapter) Name

func (a *CodexAdapter) Name() string

Name returns "codex".

func (*CodexAdapter) SetGatewayToken

func (a *CodexAdapter) SetGatewayToken(token string)

SetGatewayToken sets the gateway token in the adapter config.

func (*CodexAdapter) SupportsMultimodal added in v0.1.1

func (a *CodexAdapter) SupportsMultimodal() bool

SupportsMultimodal returns true: Codex CLI supports image inputs.

type ExecEvent

type ExecEvent struct {
	Type     string          `json:"type"`
	Message  string          `json:"message,omitempty"`
	ThreadID string          `json:"thread_id,omitempty"`
	Error    json.RawMessage `json:"error,omitempty"`
	Payload  json.RawMessage `json:"payload,omitempty"`
	Item     json.RawMessage `json:"item,omitempty"`
}

ExecEvent represents a JSONL event from "codex exec --json" output. Codex CLI 0.139.0+ wraps events in response_item/event_msg envelopes with the actual event type in payload.type. Older flat-format events (e.g. {"type":"function_call",...}) are also supported for backward compatibility.

type ExecEventMessage

type ExecEventMessage struct {
	Type    string `json:"type"`
	Text    string `json:"text,omitempty"`
	Name    string `json:"name,omitempty"`
	Content string `json:"content,omitempty"`
}

ExecEventMessage is the data payload for message-type events.

type ProcessManager

type ProcessManager struct {
	// contains filtered or unexported fields
}

ProcessManager manages a Codex CLI subprocess.

func StartProcess

func StartProcess(
	ctx context.Context,
	ac *codingagent.AdapterConfig,
	cfg *codingagent.SessionConfig,
	configOverrides []string,
	codexHome string,
) (<-chan codingagent.StreamEvent, *ProcessManager, error)

StartProcess launches codex CLI as a subprocess using "codex exec --json". It reads JSONL events from stdout and converts them to StreamEvents.

func (*ProcessManager) Stop

func (pm *ProcessManager) Stop() error

Stop gracefully terminates the subprocess and cleans up the codex home. 1. Send SIGTERM (Unix) or Kill (Windows) 2. Wait up to 5 seconds for exit 3. Force kill if timeout 4. Clean up temporary CODEX_HOME directory

func (*ProcessManager) WriteStdin added in v0.1.2

func (pm *ProcessManager) WriteStdin(text string) error

WriteStdin writes additional input to the running CLI process.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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