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 ¶
const ( TurnCompleted = "completed" TurnInterrupted = "interrupted" TurnFailed = "failed" )
Turn statuses of the protocol.
Variables ¶
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") )
var ErrClosed = errors.New("codex app-server connection ended")
ErrClosed: the connection to the app-server has ended.
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 ¶
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.
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 ¶
Forget ends the session of a conversation that is over or has lost its server.
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 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 ¶
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 ¶
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.