Documentation
¶
Overview ¶
Package subprocess provides subprocess-based transport for the Codex CLI.
This package implements the Transport interface by spawning the Codex CLI as a child process and communicating via stdin/stdout. It handles process lifecycle management, message buffering, and error handling.
Index ¶
- type AppServerAdapter
- func (a *AppServerAdapter) Close() error
- func (a *AppServerAdapter) EndInput() error
- func (a *AppServerAdapter) IsReady() bool
- func (a *AppServerAdapter) ReadMessages(_ context.Context) (<-chan map[string]any, <-chan error)
- func (a *AppServerAdapter) SendMessage(ctx context.Context, data []byte) error
- func (a *AppServerAdapter) Start(ctx context.Context) error
- type AppServerTransport
- func (t *AppServerTransport) Close() error
- func (t *AppServerTransport) IsReady() bool
- func (t *AppServerTransport) Notifications() <-chan *RPCNotification
- func (t *AppServerTransport) Requests() <-chan *RPCIncomingRequest
- func (t *AppServerTransport) SendRequest(ctx context.Context, method string, params any) (*RPCResponse, error)
- func (t *AppServerTransport) SendResponse(id int64, result json.RawMessage, rpcErr *RPCError) error
- func (t *AppServerTransport) Start(ctx context.Context) error
- type CLITransport
- func (t *CLITransport) Close() error
- func (t *CLITransport) CloseStdin() error
- func (t *CLITransport) EndInput() error
- func (t *CLITransport) IsReady() bool
- func (t *CLITransport) ReadMessages(ctx context.Context) (<-chan map[string]any, <-chan error)
- func (t *CLITransport) SendMessage(ctx context.Context, data []byte) error
- func (t *CLITransport) Start(ctx context.Context) error
- type RPCError
- type RPCIncomingRequest
- type RPCNotification
- type RPCRequest
- type RPCResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AppServerAdapter ¶
type AppServerAdapter struct {
// contains filtered or unexported fields
}
AppServerAdapter bridges the control_request/control_response protocol used by Controller/Session to the JSON-RPC 2.0 protocol spoken by codex app-server. It implements config.Transport.
func NewAppServerAdapter ¶
func NewAppServerAdapter( log *slog.Logger, opts *config.Options, ) *AppServerAdapter
NewAppServerAdapter creates a new adapter that wraps an AppServerTransport.
func (*AppServerAdapter) Close ¶
func (a *AppServerAdapter) Close() error
Close shuts down the adapter and inner transport.
func (*AppServerAdapter) EndInput ¶
func (a *AppServerAdapter) EndInput() error
EndInput is a no-op for app-server sessions which stay alive for multi-turn interaction.
func (*AppServerAdapter) IsReady ¶
func (a *AppServerAdapter) IsReady() bool
IsReady delegates to the inner transport.
func (*AppServerAdapter) ReadMessages ¶
ReadMessages returns channels populated by the adapter read loop with messages in exec-event format that message.Parse() understands.
func (*AppServerAdapter) SendMessage ¶
func (a *AppServerAdapter) SendMessage(ctx context.Context, data []byte) error
SendMessage intercepts outgoing control protocol messages and translates them into JSON-RPC calls on the inner transport.
type AppServerTransport ¶
type AppServerTransport struct {
// contains filtered or unexported fields
}
AppServerTransport manages a codex app-server subprocess communicating via JSON-RPC 2.0 over stdin/stdout.
func NewAppServerTransport ¶
func NewAppServerTransport(log *slog.Logger, opts *config.Options) *AppServerTransport
NewAppServerTransport creates a new app server transport.
func (*AppServerTransport) Close ¶
func (t *AppServerTransport) Close() error
Close terminates the app server subprocess.
func (*AppServerTransport) IsReady ¶
func (t *AppServerTransport) IsReady() bool
IsReady reports whether the transport has completed the initialize handshake.
func (*AppServerTransport) Notifications ¶
func (t *AppServerTransport) Notifications() <-chan *RPCNotification
Notifications returns the channel of incoming notifications.
func (*AppServerTransport) Requests ¶
func (t *AppServerTransport) Requests() <-chan *RPCIncomingRequest
Requests returns the channel of incoming server-to-client requests.
func (*AppServerTransport) SendRequest ¶
func (t *AppServerTransport) SendRequest( ctx context.Context, method string, params any, ) (*RPCResponse, error)
SendRequest sends a JSON-RPC request and waits for the matching response.
func (*AppServerTransport) SendResponse ¶
func (t *AppServerTransport) SendResponse( id int64, result json.RawMessage, rpcErr *RPCError, ) error
SendResponse sends a JSON-RPC response back to the server for a given request ID.
type CLITransport ¶
type CLITransport struct {
// contains filtered or unexported fields
}
CLITransport implements Transport by spawning a Codex CLI subprocess.
func NewCLITransport ¶
NewCLITransport creates a new CLI transport for one-shot exec mode.
func NewCLITransportWithMode ¶
func NewCLITransportWithMode( log *slog.Logger, prompt string, options *config.Options, isStreaming bool, ) *CLITransport
NewCLITransportWithMode creates a new CLI transport with explicit mode control.
When isStreaming is true, the transport spawns `codex app-server` and keeps stdin open for bidirectional JSON-RPC. When false, it spawns `codex exec` for one-shot queries.
func (*CLITransport) CloseStdin ¶
func (t *CLITransport) CloseStdin() error
CloseStdin closes the stdin pipe to signal end of input in streaming mode.
This is used in streaming mode to indicate that no more messages will be sent. The CLI process will continue processing any pending input and then exit normally.
func (*CLITransport) EndInput ¶
func (t *CLITransport) EndInput() error
EndInput ends the input stream (closes stdin for process transports).
This signals to the CLI that no more input will be sent. The CLI process will continue processing any pending input and then exit normally.
func (*CLITransport) IsReady ¶
func (t *CLITransport) IsReady() bool
IsReady checks if the transport is ready for communication.
func (*CLITransport) ReadMessages ¶
ReadMessages reads JSON messages from the CLI stdout.
func (*CLITransport) SendMessage ¶
func (t *CLITransport) SendMessage(ctx context.Context, data []byte) error
SendMessage sends a JSON message to the CLI stdin.
type RPCIncomingRequest ¶
type RPCIncomingRequest struct {
JSONRPC string `json:"jsonrpc"`
Method string `json:"method"`
ID int64 `json:"id"`
Params json.RawMessage `json:"params,omitempty"`
}
RPCIncomingRequest is a JSON-RPC 2.0 request received from the server.
type RPCNotification ¶
type RPCNotification struct {
JSONRPC string `json:"jsonrpc"`
Method string `json:"method"`
Params json.RawMessage `json:"params,omitempty"`
}
RPCNotification is a JSON-RPC 2.0 notification (no id field).
type RPCRequest ¶
type RPCRequest struct {
JSONRPC string `json:"jsonrpc"`
Method string `json:"method"`
ID int64 `json:"id"`
Params any `json:"params,omitempty"`
}
RPCRequest is a JSON-RPC 2.0 request message.
type RPCResponse ¶
type RPCResponse struct {
JSONRPC string `json:"jsonrpc"`
ID int64 `json:"id"`
Result json.RawMessage `json:"result,omitempty"`
Error *RPCError `json:"error,omitempty"`
}
RPCResponse is a JSON-RPC 2.0 response message.