codex

package
v0.6.43 Latest Latest
Warning

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

Go to latest
Published: May 30, 2026 License: AGPL-3.0, Apache-2.0, MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(config v1.Config) v1.Tool

func WriteCodexConfig

func WriteCodexConfig(basePath string, cfg *CodexConfig) (string, error)

Types

type AgentInput

type AgentInput struct {
	Name                  string
	Model                 string
	ModelProvider         string
	SandboxMode           string
	ApprovalPolicy        string
	ModelReasoningEffort  string
	AllowedEnvVars        []string
	EnableWebSearch       bool
	EnableShellCache      bool
	ModelInstructionsFile string
	DindEnabled           bool
}

type Codex

type Codex struct {
	v1.DefaultTool
	// contains filtered or unexported fields
}

func (*Codex) AnalysisFollowUpRun added in v0.6.40

func (in *Codex) AnalysisFollowUpRun(ctx context.Context, followUpPrompt string) error

AnalysisFollowUpRun re-runs Codex with the analysis profile and followUpPrompt. Errors are returned to the caller and must not be sent on ErrorChan.

func (*Codex) BabysitRun

func (in *Codex) BabysitRun(ctx context.Context, bCtx *v1.BabysitContext) bool

func (*Codex) Configure

func (in *Codex) Configure(consoleURL, consoleToken string) error

func (*Codex) ConfigureBabysitRun

func (in *Codex) ConfigureBabysitRun() error

func (*Codex) OnMessage

func (in *Codex) OnMessage(f func(message *console.AgentMessageAttributes))

func (*Codex) Run

func (in *Codex) Run(ctx context.Context, options ...exec.Option)

type CodexConfig

type CodexConfig struct {
	Projects       map[string]*Project             `toml:"projects,omitempty"`
	ModelProviders map[string]*ModelProviderConfig `toml:"model_providers,omitempty"`
	Profiles       map[string]*Profile             `toml:"profiles"`
	MCPServers     map[string]*MCPServer           `toml:"mcp_servers"`
}

func BuildCodexConfig

func BuildCodexConfig(repositoryDir string, agents []AgentInput, mcps []MCPInput, providers []ModelProviderInput) (*CodexConfig, error)

type DynamicToolContentItem added in v0.6.41

type DynamicToolContentItem struct {
	Type string `json:"type"`
	Text string `json:"text,omitempty"`
}

DynamicToolContentItem is a single output block for a "dynamic_tool_call" item.

type Features

type Features struct {
	WebSearchRequest bool `toml:"web_search_request,omitempty"`
	ShellSnapshot    bool `toml:"shell_snapshot,omitempty"`
}

type FileChange

type FileChange struct {
	Path string `json:"path,omitempty"`
	Kind string `json:"kind,omitempty"` // e.g. "add", "modify", "delete"
}

FileChange describes a single file modification inside a "file_change" item.

type MCPContentBlock added in v0.6.41

type MCPContentBlock struct {
	Type string `json:"type"`
	Text string `json:"text,omitempty"`
}

MCPContentBlock is a single MCP content block inside MCPToolResult.Content.

type MCPInput

type MCPInput struct {
	Name          string
	Type          string // Transport type: "stdio", "sse" or "http"
	URL           string
	Command       string
	Args          []string
	Env           map[string]string
	Headers       map[string]string // HTTP request headers, used for "http" transport
	EnabledTools  []string
	DisabledTools []string
	TrustPolicy   string // e.g. "always" to auto-approve tool calls in exec mode
}

type MCPServer

type MCPServer struct {
	Type          string            `toml:"type,omitempty"`    // Transport type: "stdio", "sse" or "http"
	URL           string            `toml:"url,omitempty"`     // For remote MCP (sse/http)
	Command       string            `toml:"command,omitempty"` // For local MCP (stdio)
	Args          []string          `toml:"args,omitempty"`
	Env           map[string]string `toml:"env,omitempty"`
	Headers       map[string]string `toml:"headers,omitempty"` // HTTP request headers for "http" transport
	EnabledTools  []string          `toml:"enabled_tools,omitempty"`
	DisabledTools []string          `toml:"disabled_tools,omitempty"`
	TrustPolicy   string            `toml:"trust_policy,omitempty"` // e.g. "always" to auto-approve tool calls in exec mode
}

type MCPToolError

type MCPToolError struct {
	Message string `json:"message,omitempty"`
}

MCPToolError holds the error payload for a failed "mcp_tool_call" item.

type MCPToolResult added in v0.6.41

type MCPToolResult struct {
	Content           []MCPContentBlock `json:"content,omitempty"`
	StructuredContent json.RawMessage   `json:"structured_content,omitempty"`
}

MCPToolResult is the result payload for a completed "mcp_tool_call" item. See https://takopi.dev/reference/runners/codex/exec-json-cheatsheet/

type Model

type Model string
const (
	ModelGPT5 Model = "gpt-5"

	// Primary Codex models
	ModelGPT51Codex     Model = "gpt-5.1-codex"
	ModelGPT51CodexMini Model = "gpt-5.1-codex-mini"
	ModelGPT54          Model = "gpt-5.4"
	ModelCodexMini      Model = "codex-mini-latest"

	// Optional powerful Codex options
	ModelGPT52Codex Model = "gpt-5.2-codex"
)

func EnsureModel

func EnsureModel(model string) Model

EnsureModel returns a sensible default

type ModelProviderConfig

type ModelProviderConfig struct {
	Name    string `toml:"name,omitempty"`
	BaseURL string `toml:"base_url,omitempty"`
	EnvKey  string `toml:"env_key,omitempty"`
}

ModelProviderConfig is serialized into [model_providers.<key>] in config.toml.

type ModelProviderInput

type ModelProviderInput struct {
	// Name is the key used to reference this provider from a Profile's ModelProvider field.
	Name string
	// BaseURL is the OpenAI-compatible API endpoint, e.g. "https://api.example.com/v1".
	BaseURL string
	// EnvKey is the name of the environment variable that holds the API key.
	EnvKey string
}

ModelProviderInput is the user-facing input for registering a custom model provider.

type Profile

type Profile struct {
	Model                  string                 `toml:"model"`
	ModelProvider          string                 `toml:"model_provider,omitempty"`
	SandboxMode            string                 `toml:"sandbox_mode"`
	ApprovalPolicy         string                 `toml:"approval_policy"`
	ModelReasoningEffort   string                 `toml:"model_reasoning_effort"`
	ShellEnvironmentPolicy *ShellEnvPolicy        `toml:"shell_environment_policy,omitempty"`
	Features               *Features              `toml:"features,omitempty"`
	ModelInstructionsFile  string                 `toml:"model_instructions_file,omitempty"`
	SandboxWorkspaceWrite  *SandboxWorkspaceWrite `toml:"sandbox_workspace_write,omitempty"`
}

type Project

type Project struct {
	TrustLevel string `toml:"trust_level,omitempty"`
}

type SandboxWorkspaceWrite added in v0.6.41

type SandboxWorkspaceWrite struct {
	NetworkAccess bool     `toml:"network_access,omitempty"`
	WritableRoots []string `toml:"writable_roots,omitempty"`
}

type ShellEnvPolicy

type ShellEnvPolicy struct {
	IncludeOnly []string          `toml:"include_only,omitempty"`
	Set         map[string]string `toml:"set,omitempty"`
}

type StreamEvent

type StreamEvent struct {
	// Type identifies the event kind, e.g. "thread.started", "turn.started",
	// "item.started", "item.completed", "turn.completed".
	Type string `json:"type"`

	// Message is populated with "error" events.
	Message string `json:"message"`

	// ThreadID is set on "thread.started" events and carries the session
	// identifier that must be forwarded to the API (analogous to session_id in Claude).
	ThreadID string `json:"thread_id,omitempty"`

	// Item is populated on "item.started" and "item.completed" events.
	Item *StreamItem `json:"item,omitempty"`

	// Usage is populated on "turn.completed" events and contains token usage statistics.
	Usage *TurnUsage `json:"usage,omitempty"`

	// Error is populated on "turn.failed" events.
	Error *TurnError `json:"error,omitempty"`
}

StreamEvent is the top-level envelope for every JSON line emitted by `codex exec --json`.

type StreamItem

type StreamItem struct {
	// ID is the stable identifier for this item across started/completed pairs.
	ID string `json:"id"`

	// Type describes what kind of item this is: "reasoning", "agent_message", "todo_list",
	// "command_execution", "dynamic_tool_call", "mcp_tool_call", "file_change", etc.
	Type string `json:"type"`

	// Text is populated for "reasoning" and "agent_message" items.
	Text string `json:"text,omitempty"`

	// Message is populated for Type "error" items.
	Message string `json:"message,omitempty"`

	// Command and output fields are populated for "command_execution" items.
	Command          string `json:"command,omitempty"`
	AggregatedOutput string `json:"aggregated_output,omitempty"`
	ExitCode         *int   `json:"exit_code,omitempty"`
	Status           string `json:"status,omitempty"`

	// Items is populated for "todo_list" items.
	Items []TodoItem `json:"items,omitempty"`

	// Tool fields are populated for "mcp_tool_call" and "dynamic_tool_call" items.
	Server    string          `json:"server,omitempty"`
	Namespace string          `json:"namespace,omitempty"`
	Tool      string          `json:"tool,omitempty"`
	Arguments json.RawMessage `json:"arguments,omitempty"`
	Result    *MCPToolResult  `json:"result,omitempty"`
	Error     *MCPToolError   `json:"error,omitempty"`

	// ContentItems is populated for "dynamic_tool_call" items.
	ContentItems []DynamicToolContentItem `json:"content_items,omitempty"`
	Success      *bool                    `json:"success,omitempty"`

	// Query is populated for "web_search" items.
	Query string `json:"query,omitempty"`

	// Changes is populated for "file_change" items.
	Changes []FileChange `json:"changes,omitempty"`
}

StreamItem is the payload carried inside "item.started" / "item.completed" events.

type TodoItem

type TodoItem struct {
	Text      string `json:"text"`
	Completed bool   `json:"completed"`
}

TodoItem is a single entry inside a "todo_list" StreamItem.

type TurnError added in v0.6.41

type TurnError struct {
	Message string `json:"message,omitempty"`
}

TurnError holds the error payload for a failed turn.

type TurnUsage

type TurnUsage struct {
	InputTokens       int `json:"input_tokens"`
	CachedInputTokens int `json:"cached_input_tokens"`
	OutputTokens      int `json:"output_tokens"`
}

TurnUsage holds token usage statistics emitted in the "turn.completed" event.

Jump to

Keyboard shortcuts

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