Documentation
¶
Overview ¶
Package codexsup drives `codex app-server` (target: Codex 0.156.1) over its stdio JSON-RPC connection: it starts the process, performs the handshake, and starts, resumes and interrupts turns on one Codex thread. Server notifications reach the caller raw; server requests (approval prompts and the rest) reach a caller handler, or are declined by default — no default path ever accepts.
The wire contract is codex_app_server_protocol.schemas.json (see SCHEMA.md). Framing is internal/acp's Transport, reused unchanged.
Params are never logged: they carry prompt text, commands and file contents.
Index ¶
- Variables
- type Client
- func (c *Client) Done() <-chan struct{}
- func (c *Client) Err() error
- func (c *Client) Interrupt(ctx context.Context, turnID string) error
- func (c *Client) ResumeThread(ctx context.Context, threadID string) error
- func (c *Client) StartThread(ctx context.Context) (string, error)
- func (c *Client) StartTurn(ctx context.Context, in TurnInput) (string, error)
- func (c *Client) Stop(ctx context.Context) error
- func (c *Client) ThreadID() string
- func (c *Client) UserAgent() string
- func (c *Client) Version() string
- type Config
- type ServerRequest
- type TurnInput
Constants ¶
This section is empty.
Variables ¶
var ErrExited = errors.New("codexsup: app-server exited")
ErrExited is wrapped by every call that fails because the app-server process is gone, whether the caller stopped it or it died on its own.
var ErrNoThread = errors.New("codexsup: no thread")
ErrNoThread is returned by StartTurn and Interrupt before a thread was started or resumed.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a connection to one running app-server process.
func Start ¶
Start launches `<Binary> app-server` and performs the handshake: initialize, then the initialized notification. ctx bounds the handshake only; the process runs until Stop or its own exit.
func (*Client) Done ¶
func (c *Client) Done() <-chan struct{}
Done is closed once the process has exited and its output has been read.
func (*Client) Err ¶
Err is the process's exit error once Done is closed (nil on a clean exit), and nil before.
func (*Client) Interrupt ¶
Interrupt asks Codex to stop the running turn turnID on the client's thread. The turn ends with a turn/completed notification.
func (*Client) ResumeThread ¶
ResumeThread resumes the thread with id, without its turn history, and makes it the client's thread.
func (*Client) StartThread ¶
StartThread starts a thread in the configured directory and returns the id Codex minted, which becomes the client's thread.
func (*Client) StartTurn ¶
StartTurn starts a turn on the client's thread and returns its id. The turn's progress arrives through OnNotification.
func (*Client) Stop ¶
Stop closes the process's stdin, on which app-server exits, and waits for the exit. If ctx ends first the process is sent SIGTERM, then SIGKILL after killGrace. It returns Err.
func (*Client) ThreadID ¶
ThreadID is the client's current thread, empty before one was started or resumed.
type Config ¶
type Config struct {
// Binary is the codex executable; Dir its working directory; CodexHome
// its CODEX_HOME. All three are required.
Binary string
Dir string
CodexHome string
// ClientVersion is sent as clientInfo.version; empty sends "dev".
ClientVersion string
// OnNotification receives every server notification, raw and in arrival
// order. It runs on the connection's read loop: it must not block, and
// must not call Client methods (their responses are read by that loop).
// params is untrusted input.
OnNotification func(method string, params json.RawMessage)
// OnServerRequest receives every server request under the same read-loop
// rules. It must answer each request exactly once, now or later from any
// goroutine. Nil declines every request (see ServerRequest.Decline).
OnServerRequest func(req *ServerRequest)
// Stderr receives the process's stderr; nil discards it.
Stderr io.Writer
// Log receives diagnostics; nil uses slog.Default().
Log *slog.Logger
}
Config configures one app-server process.
type ServerRequest ¶
type ServerRequest struct {
Method string
// Params is the request's params as the app-server sent them. It is
// untrusted input and may carry commands, paths and file contents.
Params json.RawMessage
// contains filtered or unexported fields
}
ServerRequest is one request the app-server sent to the client (a frame carrying both id and method), such as an approval prompt. It must be answered exactly once, by Respond or Decline, from any goroutine; until it is, the Codex turn that raised it waits.
func (*ServerRequest) Decline ¶
func (r *ServerRequest) Decline() error
Decline answers the request with the package's default: a decline for the approval methods, a JSON-RPC error for everything else. It never accepts.
func (*ServerRequest) Respond ¶
func (r *ServerRequest) Respond(result any) error
Respond answers the request with result. A second answer writes nothing and returns acp.ErrAlreadyResolved.