codex

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: AGPL-3.0 Imports: 39 Imported by: 0

Documentation

Overview

Package codex implements the direct codex app-server runtime driver: it speaks the v2 protocol (internal/agent/runtime/external/codex/protocol) to a pinned codex CLI running inside the bot workspace, with no ACP adapter in between.

Codex writes native rollouts under CODEX_HOME on the bot's data volume; they are the only copy of its conversation. Memoh keeps the thread id and rollout path in session metadata and resumes from them; a thread codex can no longer resume starts over and says so.

Bridges codex MCP server elicitation to Memoh's ask_user decision flow. Form-mode schemas reuse the shared elicitation core (the same mapping the ACP runtime uses); url mode renders as a single confirm card. The protocol carries no thread id, so the app-server routes an elicitation to the bot's sole active turn and declines when ownership is ambiguous.

Memoh tool-gateway injection for codex threads. Each thread gets its own reverse-HTTP route into the workspace tools proxy, configured through the thread's `mcp_servers` config override at start/resume/fork. The route outlives individual turns (thread config is start-time), so the tool session identity resolves live from the thread's active turn.

Bridges codex `tool/requestUserInput` to Memoh's ask_user decision flow: codex questions render as ask_user cards, the answers map back to the question ids codex asked with, and a canceled or timed-out card degrades to the empty answer set codex treats as "proceed with defaults".

Index

Constants

View Source
const (
	AuthAPIKey  = codexcfg.AuthAPIKey
	AuthChatGPT = codexcfg.AuthChatGPT
)
View Source
const MemohToolTimeoutSec = 900

MemohToolTimeoutSec caps one Memoh gateway tool call on the codex side. Memoh tools can legitimately block on a human decision (approval cards, ask_user) for up to their wait windows; the toolmount timeout-ladder guard test pins this above them.

View Source
const (
	// RuntimeType is the thread runtime type this driver serves.
	RuntimeType = string(runtimekind.Codex)
)

Variables

View Source
var (
	ErrNotConfigured = codexcfg.ErrNotConfigured
	ParseAgentConfig = codexcfg.ParseAgentConfig
)
View Source
var Capabilities = external.Caps{
	Dependency:       dependencyID,
	Command:          "codex",
	ForkNeedsRuntime: true,
}

Capabilities is what Codex declares (external.Caps).

ErrAuthRequired identifies a configured Codex runtime that still needs the user to complete account authorization in the Bot's workspace.

View Source
var ErrConnClosed = errors.New("codex app-server connection closed")

ErrConnClosed reports that the app-server connection is gone.

Functions

This section is empty.

Types

type ApprovalService

type ApprovalService interface {
	approval.FlowService
	RegisterWaiter(approvalID string) func()
}

ApprovalService is the decision flow the driver routes approvals through.

type AuthMode

type AuthMode = codexcfg.AuthMode

Configuration lives in the codexcfg leaf package so validators can import it without the driver's dependency tree; these aliases keep driver-side call sites short.

type Config

type Config = codexcfg.Config

Configuration lives in the codexcfg leaf package so validators can import it without the driver's dependency tree; these aliases keep driver-side call sites short.

type Driver

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

Driver runs codex turns over the app-server protocol.

func NewDriver

func NewDriver(
	workspaces external.Workspaces,
	agents *botagents.Service,
	credentials *agentcredential.Service,
	approvalSvc ApprovalService,
	userInput UserInputService,
	toolGateway toolmount.Gateway,
	launchers external.LauncherResolver,
	procs *agentproc.Supervisor,
	logger *slog.Logger,
) *Driver

NewDriver constructs the codex runtime driver.

func (*Driver) Account

func (d *Driver) Account(ctx context.Context, botID, botAgentID string) (external.Account, error)

Account asks the Agent's Codex which ChatGPT account it is signed in to.

func (*Driver) CancelDeviceLogin

func (d *Driver) CancelDeviceLogin(ctx context.Context, botID, botAgentID, loginID string) error

CancelDeviceLogin aborts a pending device-code login.

func (*Driver) Caps

func (*Driver) Caps() external.Caps

Caps implements external.Driver.

func (*Driver) Commands

func (*Driver) Compact

func (*Driver) ControlGoal

func (d *Driver) ControlGoal(ctx context.Context, input external.PromptInput, action string) error

func (*Driver) ForkThread

func (d *Driver) ForkThread(ctx context.Context, botID, botAgentID string, runtimeMetadata map[string]any, lastTurnID string) (map[string]any, error)

ForkThread implements external.ThreadForker: it derives a new codex thread sharing history up to lastTurnID (inclusive; empty forks at the head) and returns the runtime-metadata delta naming the forked thread. The session's runtime metadata supplies the source thread id and working directory.

func (*Driver) Goal

func (d *Driver) Goal(ctx context.Context, input external.PromptInput) (*external.Goal, error)

func (*Driver) ModelCatalog

func (d *Driver) ModelCatalog(ctx context.Context, request external.ModelCatalogRequest) (external.ModelCatalog, error)

ModelCatalog returns the models available to this Agent. API-key Agents with an explicit Base URL use that provider's OpenAI-compatible /models endpoint; ChatGPT and default-OpenAI Agents retain Codex's richer native catalog.

func (*Driver) Modes

func (*Driver) PlanMode

func (*Driver) PollDeviceLogin

func (d *Driver) PollDeviceLogin(_ context.Context, _, botID, botAgentID, loginID string) (external.DeviceLoginStatus, error)

PollDeviceLogin reports a tracked login's state. A login that succeeded is already in CODEX_HOME, written there by Codex itself.

func (*Driver) Prompt

Prompt implements external.Driver: it runs one turn on the bot's app-server, streaming events through the sink.

func (*Driver) PurgeBotAgentAuth

func (d *Driver) PurgeBotAgentAuth(ctx context.Context, botID, botAgentID string) error

PurgeBotAgentAuth signs the Agent's Codex out by deleting its login file.

func (*Driver) Quota

func (d *Driver) Quota(ctx context.Context, botID, botAgentID string) (external.Quota, error)

Quota asks the Agent's Codex for its ChatGPT account's usage limits.

func (*Driver) ReadCommand

func (d *Driver) ReadCommand(ctx context.Context, input external.PromptInput) (external.CommandResult, error)

func (*Driver) RuntimeType

func (*Driver) RuntimeType() string

RuntimeType implements external.Driver.

func (*Driver) SetMode

The application persists the choice under the thread admission guard. Each new turn supplies it explicitly, including when the Codex thread is warm.

func (*Driver) SetPlanMode

func (*Driver) SetPlanMode(_ context.Context, _ external.PromptInput, mode string) (external.ModeState, error)

func (*Driver) StartDeviceLogin

func (d *Driver) StartDeviceLogin(ctx context.Context, botID, botAgentID string) (external.DeviceLoginStart, error)

StartDeviceLogin begins a ChatGPT device-code login on the bot's codex, returning the code the user must enter. Completion lands in CODEX_HOME and is observable via PollDeviceLogin.

type UserInputService

type UserInputService interface {
	userinput.FlowService
}

UserInputService is the ask_user decision flow the driver routes tool/requestUserInput through.

Directories

Path Synopsis
Package codexcfg holds the Bot Agent configuration contract for the direct codex runtime.
Package codexcfg holds the Bot Agent configuration contract for the direct codex runtime.
Package protocol implements the wire contract Memoh speaks with the codex app-server: JSON-RPC 2.0 semantics over newline-delimited JSON on stdio, with the `jsonrpc` version field omitted, as the app-server does.
Package protocol implements the wire contract Memoh speaks with the codex app-server: JSON-RPC 2.0 semantics over newline-delimited JSON on stdio, with the `jsonrpc` version field omitted, as the app-server does.
Package protocolgen generates the Go types for the codex app-server v2 protocol from the JSON Schema a codex CLI exports (`codex app-server generate-json-schema --experimental`).
Package protocolgen generates the Go types for the codex app-server v2 protocol from the JSON Schema a codex CLI exports (`codex app-server generate-json-schema --experimental`).

Jump to

Keyboard shortcuts

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