Documentation
¶
Overview ¶
Package codex implements the direct codex app-server runtime driver: it speaks the v2 protocol (internal/agent/runtime/codex/protocol) to a pinned codex CLI running inside the bot workspace, with no ACP adapter in between.
Session state is owned by codex itself under CODEX_HOME on the bot's persistent data volume; Memoh keeps only the thread id in session runtime metadata and projects the turn transcript into its own history.
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 BridgeSource
- type Config
- type DeviceLoginStart
- type DeviceLoginStatus
- type Driver
- func (d *Driver) CancelDeviceLogin(ctx context.Context, botID, botAgentID, loginID string) error
- func (d *Driver) CloseAll()
- func (d *Driver) CloseBot(botID string)
- 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) CompleteChatGPTDeviceLogin(ctx context.Context, ownerUserID, botID, botAgentID, loginID string) 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(botID, botAgentID, loginID string) DeviceLoginStatus
- 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) ReadCommand(ctx context.Context, input external.PromptInput) (external.CommandResult, error)
- func (*Driver) RequiredDependency() string
- func (d *Driver) ResetBot(botID string)
- func (d *Driver) ResetBotAgent(botID, botAgentID string)
- func (*Driver) RuntimeType() string
- func (d *Driver) SetLauncherResolver(r external.LauncherResolver)
- 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) StartChatGPTDeviceLogin(ctx context.Context, botID, botAgentID string) (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 ErrAuthRequired = external.ErrAuthRequired
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 BridgeSource ¶
type BridgeSource interface {
MCPClient(ctx context.Context, botID string) (*bridge.Client, error)
WorkspaceInfo(ctx context.Context, botID string) (bridge.WorkspaceInfo, error)
}
BridgeSource resolves the workspace bridge client for a bot; the workspace manager implements it.
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 DeviceLoginStart ¶
DeviceLoginStart describes a pending ChatGPT device-code login.
type DeviceLoginStatus ¶
type DeviceLoginStatus struct {
// Status is pending, success, error, or unknown (login not tracked, e.g.
// the app-server restarted).
Status string
Error string
}
DeviceLoginStatus is the poll answer for a pending device-code login.
type Driver ¶
type Driver struct {
// contains filtered or unexported fields
}
Driver runs codex turns over the app-server protocol.
func NewDriver ¶
func NewDriver( bridges BridgeSource, agents *botagents.Service, credentials *agentcredential.Service, approvalSvc ApprovalService, userInput UserInputService, toolGateway toolmount.Gateway, logger *slog.Logger, ) *Driver
NewDriver constructs the codex runtime driver.
func (*Driver) CancelDeviceLogin ¶
CancelDeviceLogin aborts a pending device-code login.
func (*Driver) CloseAll ¶
func (d *Driver) CloseAll()
CloseAll tears down every app-server (server shutdown).
func (*Driver) CloseBot ¶
CloseBot recycles the bot's app-server: new work builds a fresh server on current configuration, while in-flight turns finish on the displaced one, which dies at their last release.
func (*Driver) Compact ¶
func (d *Driver) Compact(ctx context.Context, input external.PromptInput) (external.CompactionResult, error)
func (*Driver) CompleteChatGPTDeviceLogin ¶
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(botID, botAgentID, loginID string) DeviceLoginStatus
PollDeviceLogin reports a tracked login's state.
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 ¶
func (*Driver) ReadCommand ¶
func (d *Driver) ReadCommand(ctx context.Context, input external.PromptInput) (external.CommandResult, error)
func (*Driver) RequiredDependency ¶
RequiredDependency implements external.DependencyRequirer: the codex CLI is a managed workspace dependency. No version is declared; the handshake in startAppServerSession warns when the running CLI drifts from the protocol snapshot.
func (*Driver) ResetBotAgent ¶
func (*Driver) RuntimeType ¶
RuntimeType implements external.Driver.
func (*Driver) SetLauncherResolver ¶
func (d *Driver) SetLauncherResolver(r external.LauncherResolver)
SetLauncherResolver installs the workspace dependency resolver. Setter injection keeps the driver constructible without one (tests, the toolkit fallback); assembly wires it right after NewDriver.
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) StartChatGPTDeviceLogin ¶
func (d *Driver) StartChatGPTDeviceLogin(ctx context.Context, botID, botAgentID string) (DeviceLoginStart, error)
StartChatGPTDeviceLogin begins a 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/. |