codexsup

package
v0.41.1 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 18 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

View Source
const (
	ApprovalGranular  = "granular"
	ApprovalOnRequest = "on-request"
	ApprovalNever     = "never"
)

TurnInput.ApprovalPolicy values. Granular is sent as the object that turns every sandbox block, rule prompt and MCP elicitation into an approval request; the others as their string.

View Source
const (
	SandboxReadOnly         = "readOnly"
	SandboxWorkspaceWrite   = "workspaceWrite"
	SandboxDangerFullAccess = "dangerFullAccess"
)

TurnInput.Sandbox values: the type tag of turn/start's sandboxPolicy.

View Source
const (
	ReviewerUser       = "user"
	ReviewerAutoReview = "auto_review"
)

TurnInput.ApprovalsReviewer values.

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) CloseInput added in v0.29.0

func (c *Client) CloseInput()

CloseInput closes the process's stdin without waiting for exit. A caller that must coordinate the final close with server-request replies can call this first, then Stop after releasing its own lock.

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) LatestModels added in v0.27.0

func (c *Client) LatestModels(ctx context.Context) ([]turnevent.ModelOption, error)

LatestModels reads every page of model/list and returns the newest version of each model family, in order of the family's first appearance: Value is the family, ResolvedModel the newest version's id and EffortLevels that version's advertised levels in order. An entry whose id is not shaped gpt-<version>-<family> is left out. Hidden models are not asked for.

Each page is folded into a table of at most maxModelFamilies before the next is read. A read that fails part-way returns an error and no list, so a family seen only on a later page is never dropped silently.

func (*Client) PID added in v0.28.0

func (c *Client) PID() int

PID is the app-server's process id, or 0 for a connection with no process. It stays set after the process exits; Done says whether it still runs.

func (*Client) ResumeThread

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

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

func (*Client) SignedIn added in v0.27.0

func (c *Client) SignedIn(ctx context.Context) (bool, error)

SignedIn reports whether the Codex home can run a turn, from account/read. It is false only when Codex answers no account and requiresOpenaiAuth true; a provider needing no OpenAI sign-in is signed in without an account. The account's fields (an email address among them) are never decoded.

func (*Client) StartThread

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

StartThread starts a thread in the configured directory, with the configured developer instructions, 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
	// DeveloperInstructions, when non-empty, is sent as developerInstructions
	// on every thread/start and thread/resume; empty omits the key (#2662).
	DeveloperInstructions 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
	// ID is the request's JSON-RPC id, which serverRequest/resolved names as
	// requestId when the app-server stops waiting for the answer.
	ID json.RawMessage
	// 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 Translator added in v0.27.0

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

Translator maps Codex server notifications onto turn events: the Codex twin of streamsup's parser. It holds per-turn state (usage, reroute target, retry) and remembers the first untrusted-project warning for its entire lifetime. It is not safe for concurrent use; call it from OnNotification, which runs on one goroutine.

Params are untrusted. Text is carried, never interpreted; every string the translator builds from them other than text deltas is bounded here. A tool call's input, output, paths and diffs are carried as streamsup carries tool input and tool_result text, bounded by acp's line cap and capped by turnbridge on the way to the wire.

func NewTranslator added in v0.27.0

func NewTranslator(model string) *Translator

NewTranslator returns a translator for turns running on model, the model the caller sets on each turn (TurnInput.Model).

func (*Translator) SetModel added in v0.27.0

func (t *Translator) SetModel(model string)

SetModel changes the model later turns run on.

func (*Translator) Translate added in v0.27.0

func (t *Translator) Translate(method string, params json.RawMessage) []turnevent.Event

Translate maps one server notification to the events it means, in order. An ignored method yields none; a method or item type with no mapping yields one Unrecognized.

type TurnInput

type TurnInput struct {
	Text              string
	Model             string
	Effort            string
	ApprovalPolicy    string
	Sandbox           string
	ApprovalsReviewer string
}

TurnInput is one turn's text input and its per-turn overrides. Codex keeps each override for the thread's later turns, so an empty field leaves the thread's setting unchanged rather than resetting it.

Jump to

Keyboard shortcuts

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