codex

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 24 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 codex adapts the native Codex CLI app-server protocol to the common agent contract.

Index

Constants

View Source
const (
	Name   = "codex"
	Binary = "codex"
)
View Source
const (
	LoginChatGPTDeviceCode = "chatgpt_device_code"
	LoginChatGPT           = "chatgpt"
)

Native login methods. Device code works from any machine; chatgpt needs the browser on the gateway host because the native callback listens on localhost.

Variables

View Source
var (
	ReasoningSummaries = agent.EnumOf[RequestOptions]("ReasoningSummary")
	ApprovalsReviewers = agent.EnumOf[RequestOptions]("ApprovalsReviewer")
)

Functions

func Environment

func Environment(opts Options) []string

func RunInteractive

func RunInteractive(ctx context.Context, opts Options, stdio agent.IO, command agent.InteractiveCommand) error

func Sections

func Sections() map[agent.Section]reflect.Type

Sections describes Codex's provider sections.

Types

type Agent

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

func New

func New(opts Options) (*Agent, error)

func (*Agent) AuthStatus

func (a *Agent) AuthStatus(ctx context.Context) (agent.AuthStatus, error)

AuthStatus implements agent.Agent with app-server account/read.

func (*Agent) Diagnostics

func (a *Agent) Diagnostics(ctx context.Context) (agent.Diagnostics, error)

func (*Agent) Info

func (*Agent) Info() agent.Info

func (*Agent) Interactive

func (a *Agent) Interactive(ctx context.Context, stdio agent.IO, command agent.InteractiveCommand) error

func (*Agent) Logout

func (a *Agent) Logout(ctx context.Context) error

Logout implements agent.Authenticator with the native `codex logout` command.

func (*Agent) Models

func (a *Agent) Models(ctx context.Context) ([]agent.Model, error)

Models implements agent.ModelReporter using Codex's native model catalog.

func (*Agent) Name

func (*Agent) Name() string

func (*Agent) ProfileDir

func (a *Agent) ProfileDir() string

ProfileDir implements agent.ProfileReporter.

func (*Agent) ProviderSections

func (*Agent) ProviderSections() map[agent.Section]reflect.Type

ProviderSections implements agent.SectionDescriber.

func (*Agent) Start

func (a *Agent) Start(parent context.Context, req agent.Request, onEvent agent.EventFunc) (agent.Conversation, error)

func (*Agent) StartLogin

func (a *Agent) StartLogin(ctx context.Context, req agent.LoginRequest) (agent.Login, error)

StartLogin runs account/login/start on a dedicated app-server process that stays alive until account/login/completed arrives.

func (*Agent) Usage

func (a *Agent) Usage(ctx context.Context) (agent.Usage, error)

Usage implements agent.UsageReporter. Account allowance and token activity remain separate native documents because Codex assigns them different scopes.

func (*Agent) Validate

func (*Agent) Validate(req *agent.Request) error

func (*Agent) Version

func (a *Agent) Version(ctx context.Context) (string, error)

type AuthFields

type AuthFields struct {
	Method string `json:"method,omitempty" doc:"Native account type, e.g. chatgpt or apiKey."`
}

AuthFields are Codex's fields of the auth status provider section.

type Options

type Options struct {
	Binary string
	// ProfileDir is agent.ProfileNative (Codex's own ~/.codex) or a custom absolute directory
	// exported as CODEX_HOME.
	ProfileDir     string
	HomeDir        string
	User           string
	WorkDir        string
	TempDir        string
	ProxyEnv       []string // Standard proxy variables (NAME=value), passed on unchanged.
	Path           string
	SandboxMode    agent.SandboxMode
	MaxOutputBytes int64
	CommandTimeout time.Duration
	Logger         *slog.Logger
}

type RequestFields

type RequestFields struct {
	Method string `json:"method" doc:"Native app-server request method, e.g. item/commandExecution/requestApproval."`
}

RequestFields are Codex's fields of a permission or control request's provider section.

type RequestOptions

type RequestOptions struct {
	// Config holds native config overrides (mcp_servers, features, tools, web_search, ...).
	Config                map[string]any `` /* 140-byte string literal not displayed */
	DeveloperInstructions string         `json:"developer_instructions,omitempty" doc:"Thread developerInstructions."`
	ApprovalsReviewer     string         `json:"approvals_reviewer,omitempty" enum:"user,auto_review" doc:"Thread approvalsReviewer; needs tools.permissions ask."`
	ServiceTier           string         `json:"service_tier,omitempty" doc:"Thread serviceTier."`
	ReasoningSummary      string         `json:"reasoning_summary,omitempty" enum:"auto,concise,detailed,none" doc:"Turn summary."`
	// DisabledPluginIDs replaces the thread's disabled plugins; an empty list clears it.
	DisabledPluginIDs *[]string `json:"disabled_plugin_ids,omitempty" doc:"Turn disabledPluginIds; an empty list clears it."`
	// SkillRoots add skill directories inside an allowed root or the workspace. They live in
	// the run's own app-server process and are never written to the Codex config.
	SkillRoots []string `json:"skill_roots,omitempty" doc:"Extra skill directories inside an allowed root or the workspace."`
}

RequestOptions are Codex app-server's native per-run options (the request "options" object). See docs/agents/codex-cli.md.

func ParseOptions

func ParseOptions(req *agent.Request) (RequestOptions, error)

ParseOptions decodes and validates raw options for req.

type ResultFields

type ResultFields struct {
	Reason string `json:"reason" doc:"Native turn status, e.g. completed, interrupted or failed."`
	// Thread is the native cumulative usage of the thread, when Codex reported it.
	Thread *ThreadUsage `json:"thread,omitempty"`
}

ResultFields are Codex's fields of a turn result's provider section.

type SubscriptionFields

type SubscriptionFields struct {
	WindowMinutes map[string]int64 `json:"window_minutes,omitempty" doc:"Window length in minutes, by window id."`
}

SubscriptionFields are Codex's fields of the subscription usage provider section.

type ThreadUsage

type ThreadUsage struct {
	Tokens agent.Tokens `json:"tokens"`
}

ThreadUsage is the native cumulative token usage of a thread. It is kept across resumes and a fork starts from its parent's.

Jump to

Keyboard shortcuts

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