codex

package
v0.68.54 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package codex drives the official OpenAI Codex binary as an agentbridge.Agent. Two transports behind one seam: the stateful `codex app-server` JSON-RPC connection (primary — steer, interrupt, and approval round-trips) and `codex exec --json` one-shot turns (fallback). Wire shapes are pinned against `codex app-server generate-json-schema` from codex-cli 0.147.0; unknown notifications and fields are tolerated.

Auth is detection-only: the user signs the Codex CLI in themselves (ChatGPT subscription or API key), the bridge reads nothing beyond the sign-in method and plan label, and a policy reversal on OpenAI's side degrades to API-key-authed Codex with zero code change here.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bridge

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

Bridge implements agentbridge.Agent against the codex CLI. One turn runs at a time; concurrent StartTurn returns ErrBusy.

func New

func New(cfg Config) *Bridge

New constructs the bridge. Construction never fails — capability is reported honestly through Status so hosts can render/speak the reason.

func (*Bridge) Close

func (b *Bridge) Close() error

Close implements agentbridge.Agent: interrupts running work, denies pending approvals, and closes the event stream.

func (*Bridge) Events

func (b *Bridge) Events() <-chan agentbridge.Event

Events implements agentbridge.Agent.

func (*Bridge) Interrupt

func (b *Bridge) Interrupt(ctx context.Context, ref agentbridge.ThreadRef) error

Interrupt implements agentbridge.Agent.

func (*Bridge) LastThreadRef

func (b *Bridge) LastThreadRef() agentbridge.ThreadRef

LastThreadRef returns the most recently observed thread reference — the default target for "continue working on that" follow-up turns.

func (*Bridge) RespondApproval

func (b *Bridge) RespondApproval(_ context.Context, id string, d agentbridge.Decision) error

RespondApproval implements agentbridge.Agent. Only app-server mode raises approvals; exec mode runs non-interactively.

func (*Bridge) StartTurn

StartTurn implements agentbridge.Agent (fast-ack; the turn continues in the background and progress arrives on Events).

func (*Bridge) Status

func (b *Bridge) Status(ctx context.Context) agentbridge.Status

Status implements agentbridge.Agent.

func (*Bridge) Steer

func (b *Bridge) Steer(ctx context.Context, ref agentbridge.ThreadRef, text string) error

Steer implements agentbridge.Agent. Exec mode cannot steer mid-turn.

type Config

type Config struct {
	// BinaryPath pins the codex binary; empty means PATH lookup.
	BinaryPath string
	// CodexHome overrides the auth-detection directory (tests); empty means
	// $CODEX_HOME or ~/.codex.
	CodexHome string
	// Mode selects the transport: "auto" (default; app-server with exec
	// fallback), "app_server", or "exec".
	Mode string
	// ClientVersion is reported in the app-server initialize handshake.
	ClientVersion string
	// EventBuffer sizes the Events channel; default 64.
	EventBuffer int
	// Logger defaults to slog.Default().
	Logger *slog.Logger
}

Config configures the bridge. All fields are optional.

Jump to

Keyboard shortcuts

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