codexapp

package
v0.16.397 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: AGPL-3.0 Imports: 13 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 codexapp talks to a chat's `codex app-server`: the structured channel a message goes to Codex through instead of being typed in its terminal. The server speaks JSON-RPC, one message per line; a message is a record with the client's id, and its delivery, the end of the turn and the approvals Codex asks for come as messages of the protocol, not as text on a screen. Codex marks the protocol experimental, so every failure here is one the caller can answer by typing in the terminal as before.

Index

Constants

View Source
const (
	TurnCompleted   = "completed"
	TurnInterrupted = "interrupted"
	TurnFailed      = "failed"
)

Turn statuses of the protocol.

Variables

View Source
var (
	// ErrNotReady: the app-server answers but has no thread of the chat to send into yet.
	ErrNotReady = errors.New("codex app-server has no thread for the chat yet")
	// ErrUncertain: the message was written and no answer came, and the thread does not show it. It may still be
	// with Codex, so it is neither sent again nor typed: whoever sent it waits for the transcript to say.
	ErrUncertain = errors.New("codex app-server did not say whether it took the message")
)
View Source
var ErrClosed = errors.New("codex app-server connection ended")

ErrClosed: the connection to the app-server has ended.

View Source
var ErrNoChannel = errors.New("the chat has no codex app-server")

ErrNoChannel: the chat has no app-server to talk to (it was started without one, or the server is gone).

Functions

func ProxyDial

func ProxyDial(bin string) func(ctx context.Context, socket string) (io.ReadWriteCloser, error)

ProxyDial connects through `codex app-server proxy`, Codex's own bridge from standard streams to the server's socket: the lines of the protocol go over the process's pipes, whatever the socket itself speaks.

func Supported

func Supported(version string) bool

Supported says whether a Codex of this version (`codex --version`: "codex-cli 0.147.0") has the app-server this package talks to. A version that cannot be read is not supported.

Types

type Approval

type Approval struct {
	// Command is the shell command, "" for a change of files; Paths are the files a change touches.
	Command string
	Paths   []string
	Cwd     string
	Reason  string
}

Approval is what Codex asks the person to approve.

type Decision

type Decision string

Decision is the answer to an Approval, in the protocol's words.

const (
	Accept  Decision = "accept"
	Decline Decision = "decline" // refused, the turn goes on
	Cancel  Decision = "cancel"  // refused, and the turn is interrupted
)

type Dialer

type Dialer func(ctx context.Context) (io.ReadWriteCloser, error)

Dialer opens a connection to the chat's app-server.

type Events

type Events interface {
	TurnStarted(turnID string)
	TurnEnded(turnID, status, detail string)
	Approval(ctx context.Context, a Approval) (Decision, bool)
	// Lost: the connection ended; nothing more comes until the next Send connects again.
	Lost()
}

Events is what the server says of the chat's thread. The calls come in the server's order, one at a time, and must not wait long — except Approval, which runs beside them and may wait for the person: false leaves the request to Codex's own dialog, and ctx ends when someone else answered it.

type Manager

type Manager struct {
	// Dir holds the chats' sockets, one per conversation.
	Dir string
	// Dial connects to a socket.
	Dial func(ctx context.Context, socket string) (io.ReadWriteCloser, error)
	Sink Sink
	// contains filtered or unexported fields
}

Manager keeps the sessions of the chats that run beside an app-server. A chat has one when the socket its launch was given exists: the launch decides, the manager only finds it.

func (*Manager) Forget

func (m *Manager) Forget(conv string)

Forget ends the session of a conversation that is over or has lost its server.

func (*Manager) Send

func (m *Manager) Send(ctx context.Context, conv string, msg Message) error

Send hands the message to the conversation's Codex (Session.Send); ErrNoChannel when the chat has no app-server.

func (*Manager) Socket

func (m *Manager) Socket(conv string) string

Socket is where the app-server of a conversation listens; "" when the id or the folder gives no usable path.

type Message

type Message struct {
	ID     string
	Text   string
	Images []string
	// Steer puts the message into the turn that runs, when one does.
	Steer bool
}

Message is one message of the person. ID is the client's id of it: Codex keeps it with the user message, so a message sent before is known by it and never starts a second turn.

type RPCError

type RPCError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

RPCError is the server's refusal of a request: it read the request and said no.

func (*RPCError) Error

func (e *RPCError) Error() string

type Session

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

Session is one chat's channel to its app-server. It connects when a message is sent and again after a break, and each time reads the thread first, so it knows which of its messages Codex already has.

func NewSession

func NewSession(dial Dialer, ev Events) *Session

NewSession makes a session that is not connected yet. ev may be nil.

func (*Session) Close

func (s *Session) Close()

Close ends the session's connection; it connects again at the next Send.

func (*Session) Send

func (s *Session) Send(ctx context.Context, m Message) error

Send hands the message to Codex and returns nil once Codex has it: the server answered the request, or the thread already holds a message with this id. ErrUncertain is the one error after which the message may be with Codex; after any other it is not, and the caller is free to deliver it another way.

type Sink

type Sink interface {
	TurnStarted(conv, turnID string)
	TurnEnded(conv, turnID, status, detail string)
	Approval(ctx context.Context, conv string, a Approval) (Decision, bool)
	Lost(conv string)
}

Sink is Events for many chats: every call names its conversation.

Jump to

Keyboard shortcuts

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