codexsup

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: MIT 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 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

Constants

This section is empty.

Variables

View Source
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.

View Source
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

func Start(ctx context.Context, cfg Config) (*Client, error)

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

func (c *Client) Err() error

Err is the process's exit error once Done is closed (nil on a clean exit), and nil before.

func (*Client) Interrupt

func (c *Client) Interrupt(ctx context.Context, turnID string) error

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

func (c *Client) ResumeThread(ctx context.Context, threadID string) error

ResumeThread resumes the thread with id, without its turn history, and makes it the client's thread.

func (*Client) StartThread

func (c *Client) StartThread(ctx context.Context) (string, error)

StartThread starts a thread in the configured directory and returns the id Codex minted, which becomes the client's thread.

func (*Client) StartTurn

func (c *Client) StartTurn(ctx context.Context, in TurnInput) (string, error)

StartTurn starts a turn on the client's thread and returns its id. The turn's progress arrives through OnNotification.

func (*Client) Stop

func (c *Client) Stop(ctx context.Context) error

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

func (c *Client) ThreadID() string

ThreadID is the client's current thread, empty before one was started or resumed.

func (*Client) UserAgent

func (c *Client) UserAgent() string

UserAgent is the initialize response's userAgent, unparsed.

func (*Client) Version

func (c *Client) Version() string

Version is the Codex version from the initialize response's userAgent.

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.

type TurnInput

type TurnInput struct {
	Text   string
	Model  string
	Effort string
}

TurnInput is one turn's text input and its per-turn overrides. Empty Model or Effort leaves the thread's setting unchanged.

Jump to

Keyboard shortcuts

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