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
- Variables
- type ApprovalService
- type AuthMode
- type Config
- type Driver
- func (d *Driver) Account(ctx context.Context, botID, botAgentID string) (external.Account, error)
- func (d *Driver) CancelDeviceLogin(ctx context.Context, botID, botAgentID, loginID string) error
- func (*Driver) Caps() external.Caps
- func (*Driver) Commands(_ context.Context, _ external.PromptInput) ([]external.Command, error)
- func (d *Driver) Compact(ctx context.Context, input external.PromptInput) (external.CompactionResult, error)
- func (d *Driver) ControlGoal(ctx context.Context, input external.PromptInput, action string) error
- func (d *Driver) ForkThread(ctx context.Context, botID, botAgentID string, runtimeMetadata map[string]any, ...) (map[string]any, error)
- func (d *Driver) Goal(ctx context.Context, input external.PromptInput) (*external.Goal, error)
- func (d *Driver) ModelCatalog(ctx context.Context, request external.ModelCatalogRequest) (external.ModelCatalog, error)
- func (d *Driver) Modes(ctx context.Context, input external.PromptInput) (external.ModeState, error)
- func (*Driver) PlanMode(_ context.Context, input external.PromptInput) (external.ModeState, error)
- func (d *Driver) PollDeviceLogin(_ context.Context, _, botID, botAgentID, loginID string) (external.DeviceLoginStatus, error)
- func (d *Driver) Prompt(ctx context.Context, input external.PromptInput) (external.PromptResult, error)
- func (d *Driver) PurgeBotAgentAuth(ctx context.Context, botID, botAgentID string) error
- func (d *Driver) Quota(ctx context.Context, botID, botAgentID string) (external.Quota, error)
- func (d *Driver) ReadCommand(ctx context.Context, input external.PromptInput) (external.CommandResult, error)
- func (*Driver) RuntimeType() string
- func (*Driver) SetMode(_ context.Context, _ external.PromptInput, mode string) (external.ModeState, error)
- func (*Driver) SetPlanMode(_ context.Context, _ external.PromptInput, mode string) (external.ModeState, error)
- func (d *Driver) StartDeviceLogin(ctx context.Context, botID, botAgentID string) (external.DeviceLoginStart, error)
- type UserInputService
Constants ¶
const ( AuthAPIKey = codexcfg.AuthAPIKey AuthChatGPT = codexcfg.AuthChatGPT )
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.
const ( // RuntimeType is the thread runtime type this driver serves. RuntimeType = string(runtimekind.Codex) )
Variables ¶
var ( ErrNotConfigured = codexcfg.ErrNotConfigured ParseAgentConfig = codexcfg.ParseAgentConfig )
var Capabilities = external.Caps{ Dependency: dependencyID, Command: "codex", ForkNeedsRuntime: true, }
Capabilities is what Codex declares (external.Caps).
var ErrAuthRequired = external.Fail(external.FailureAuthRequired, nil)
ErrAuthRequired identifies a configured Codex runtime that still needs the user to complete account authorization in the Bot's workspace.
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 ¶
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 ¶
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) CancelDeviceLogin ¶
CancelDeviceLogin aborts a pending device-code login.
func (*Driver) Compact ¶
func (d *Driver) Compact(ctx context.Context, input external.PromptInput) (external.CompactionResult, error)
func (*Driver) ControlGoal ¶
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) 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) 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 ¶
func (d *Driver) Prompt(ctx context.Context, input external.PromptInput) (external.PromptResult, error)
Prompt implements external.Driver: it runs one turn on the bot's app-server, streaming events through the sink.
func (*Driver) PurgeBotAgentAuth ¶
PurgeBotAgentAuth signs the Agent's Codex out by deleting its login file.
func (*Driver) ReadCommand ¶
func (d *Driver) ReadCommand(ctx context.Context, input external.PromptInput) (external.CommandResult, error)
func (*Driver) RuntimeType ¶
RuntimeType implements external.Driver.
func (*Driver) SetMode ¶
func (*Driver) SetMode(_ context.Context, _ external.PromptInput, mode string) (external.ModeState, error)
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) 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.
Source Files
¶
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 vendored JSON Schema snapshot under schema/.
|
Package protocolgen generates the Go types for the codex app-server v2 protocol from the vendored JSON Schema snapshot under schema/. |