codex

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package codex implements the Codex agent via the Codex App Server.

Index

Constants

View Source
const (
	MethodInitialize       = "initialize"
	MethodShutdown         = "shutdown"
	MethodExecute          = "execute"
	MethodCancel           = "cancel"
	MethodApproveCommand   = "approveCommand"
	MethodApproveFile      = "approveFile"
	MethodGetSessionStatus = "getSessionStatus"
)

Method names for Codex App Server.

View Source
const (
	NotifyCommandRequest = "commandRequest"
	NotifyFileRequest    = "fileRequest"
	NotifyProgress       = "progress"
	NotifyOutput         = "output"
	NotifyError          = "error"
)

Notification methods from Codex.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

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

Agent implements the Agent interface for Codex.

func New

func New(cfg *agent.Config) *Agent

New creates a new Codex agent.

func (*Agent) Execute

func (a *Agent) Execute(ctx context.Context, msgs []*bridge.Message) (*agent.Result, error)

Execute sends messages to Codex and waits for a result.

func (*Agent) IsRunning

func (a *Agent) IsRunning() bool

IsRunning returns true if the agent is running.

func (*Agent) Name

func (a *Agent) Name() string

Name returns the agent name.

func (*Agent) SessionID

func (a *Agent) SessionID() string

SessionID returns the current session ID.

func (*Agent) SetMCPServerAddr

func (a *Agent) SetMCPServerAddr(addr string)

SetMCPServerAddr sets the MCP server address for bridge tools.

func (*Agent) Start

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

Start initializes and starts the Codex agent.

func (*Agent) Status

func (a *Agent) Status() *agent.Status

Status returns the current agent status.

func (*Agent) Stop

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

Stop gracefully stops the Codex agent.

type ApproveCommandParams

type ApproveCommandParams struct {
	RequestID string `json:"requestId"`
	Command   string `json:"command"`
	Approved  bool   `json:"approved"`
}

ApproveCommandParams for command approval.

type ApproveFileParams

type ApproveFileParams struct {
	RequestID string `json:"requestId"`
	FilePath  string `json:"filePath"`
	Approved  bool   `json:"approved"`
}

ApproveFileParams for file change approval.

type CommandRequestParams

type CommandRequestParams struct {
	RequestID   string `json:"requestId"`
	Command     string `json:"command"`
	Description string `json:"description"`
}

CommandRequestParams for command approval requests.

type ErrorParams

type ErrorParams struct {
	Code    string `json:"code"`
	Message string `json:"message"`
	Details string `json:"details,omitempty"`
}

ErrorParams for error notifications.

type ExecuteParams

type ExecuteParams struct {
	Prompt      string            `json:"prompt"`
	MaxTokens   int               `json:"maxTokens,omitempty"`
	Timeout     int               `json:"timeout,omitempty"`
	AutoApprove bool              `json:"autoApprove,omitempty"`
	Context     map[string]string `json:"context,omitempty"`
}

ExecuteParams for the execute method.

type ExecuteResult

type ExecuteResult struct {
	Output     string         `json:"output"`
	Done       bool           `json:"done"`
	ToolCalls  []ToolCall     `json:"toolCalls,omitempty"`
	Statistics *Statistics    `json:"statistics,omitempty"`
	Metadata   map[string]any `json:"metadata,omitempty"`
}

ExecuteResult from the execute method.

type FileRequestParams

type FileRequestParams struct {
	RequestID   string `json:"requestId"`
	FilePath    string `json:"filePath"`
	Operation   string `json:"operation"` // "create", "edit", "delete"
	Description string `json:"description"`
}

FileRequestParams for file change approval requests.

type InitializeParams

type InitializeParams struct {
	WorkDir     string            `json:"workDir"`
	Model       string            `json:"model,omitempty"`
	AutoApprove bool              `json:"autoApprove,omitempty"`
	Environment map[string]string `json:"environment,omitempty"`
}

InitializeParams for the initialize method.

type InitializeResult

type InitializeResult struct {
	SessionID    string   `json:"sessionId"`
	Capabilities []string `json:"capabilities,omitempty"`
}

InitializeResult from the initialize method.

type Notification

type Notification struct {
	JSONRPC string `json:"jsonrpc"`
	Method  string `json:"method"`
	Params  any    `json:"params,omitempty"`
}

Notification represents a JSON-RPC 2.0 notification (no id field).

func NewNotification

func NewNotification(method string, params any) *Notification

NewNotification creates a new JSON-RPC 2.0 notification.

type OutputParams

type OutputParams struct {
	Text   string `json:"text"`
	Stream string `json:"stream"` // "stdout" or "stderr"
}

OutputParams for streaming output.

type ProgressParams

type ProgressParams struct {
	Message    string `json:"message"`
	Percentage int    `json:"percentage,omitempty"`
}

ProgressParams for progress updates.

type RPCError

type RPCError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    any    `json:"data,omitempty"`
}

RPCError represents a JSON-RPC 2.0 error.

func (*RPCError) Error

func (e *RPCError) Error() string

Error implements the error interface.

type Request

type Request struct {
	JSONRPC string `json:"jsonrpc"`
	ID      int64  `json:"id"`
	Method  string `json:"method"`
	Params  any    `json:"params,omitempty"`
}

Request represents a JSON-RPC 2.0 request.

func NewRequest

func NewRequest(method string, params any) *Request

NewRequest creates a new JSON-RPC 2.0 request.

type Response

type Response struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      int64           `json:"id"`
	Result  json.RawMessage `json:"result,omitempty"`
	Error   *RPCError       `json:"error,omitempty"`
}

Response represents a JSON-RPC 2.0 response.

func (*Response) DecodeResult

func (r *Response) DecodeResult(v any) error

DecodeResult decodes a response result into the given type.

type SessionStatusResult

type SessionStatusResult struct {
	SessionID string `json:"sessionId"`
	State     string `json:"state"`
	Running   bool   `json:"running"`
}

SessionStatusResult from getSessionStatus.

type Statistics

type Statistics struct {
	InputTokens  int `json:"inputTokens"`
	OutputTokens int `json:"outputTokens"`
	DurationMs   int `json:"durationMs"`
}

Statistics contains usage statistics.

type ToolCall

type ToolCall struct {
	ID        string `json:"id"`
	Name      string `json:"name"`
	Arguments string `json:"arguments"`
	Result    string `json:"result,omitempty"`
	Error     string `json:"error,omitempty"`
}

ToolCall represents a tool invocation.

Jump to

Keyboard shortcuts

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