Documentation
¶
Overview ¶
Package codex implements the Adapter interface for OpenAI Codex.
Detection is by `executor.LookPath("codex")`. Codex stores hook configuration across two files:
- ~/.codex/hooks.json — hook definitions (JSON)
- ~/.codex/config.toml — global config; install also sets `[features].codex_hooks = true` here so Codex actually invokes hooks at runtime
Uninstall removes DMG-owned hook entries from hooks.json but does NOT revert the codex_hooks feature flag — the user may have wired up other tools' hooks that depend on it.
Restore + Status are intentionally absent (see adapter.Adapter for the trimmed-interface rationale). There is no Force install option: the upsert path always refreshes managed entries in place, which covers the binary-move self-heal case the same way claudecode does.
Index ¶
- Constants
- type Adapter
- func (a *Adapter) DecideResponse(ev *event.Event, d adapter.Decision) adapter.HookResponse
- func (a *Adapter) Detect(ctx context.Context, exec executor.Executor) (adapter.DetectionResult, error)
- func (a *Adapter) Install(ctx context.Context) (adapter.InstallResult, error)
- func (a *Adapter) ManagedFiles() []adapter.ManagedFile
- func (a *Adapter) Name() string
- func (a *Adapter) ParseEvent(ctx context.Context, hookType event.HookEvent, raw []byte) (*event.Event, error)
- func (a *Adapter) ShellCommand(ev *event.Event) (cmd string, cwd string, ok bool)
- func (a *Adapter) SupportedHooks() []event.HookEvent
- func (a *Adapter) Uninstall(ctx context.Context) (adapter.UninstallResult, error)
Constants ¶
const ( HookSessionStart event.HookEvent = "SessionStart" HookPreToolUse event.HookEvent = "PreToolUse" HookPermissionRequest event.HookEvent = "PermissionRequest" HookPostToolUse event.HookEvent = "PostToolUse" HookUserPromptSubmit event.HookEvent = "UserPromptSubmit" HookStop event.HookEvent = "Stop" )
Codex-native hook event names. These are kept in this package and NOT promoted to internal/aiagents/event so cross-agent code (policy, runtime) cannot branch on them — branching MUST go through event.HookPhase instead.
const AgentBinary = "codex"
AgentBinary is the name `executor.LookPath` searches for during detection. Adapter-private.
const AgentName = "codex"
AgentName is the identifier DMG uses for Codex on the wire and in the `_hook <agent>` invocation. Adapter-private; the runtime never compares against it.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Adapter ¶
type Adapter struct {
// contains filtered or unexported fields
}
Adapter implements adapter.Adapter for OpenAI Codex.
State is set once at construction and never mutated. hooksPath and configPath are derived from home; binaryPath is the absolute DMG binary path the install handler resolved via internal/aiagents/cli.Resolve.
func New ¶
New constructs an Adapter for the given user home and resolved DMG binary path. Both arguments must be absolute; behavior with relative paths is undefined.
func (*Adapter) DecideResponse ¶
DecideResponse renders a generic Decision into Codex's wire format. Default is the empty object {}; only PreToolUse + Allow=false produces the hook-specific deny shape.
The runtime NEVER returns Allow=false to the agent today: the policy evaluator is forced to audit mode. The Allow=false path is exercised only by adapter unit tests until block mode ships.
func (*Adapter) Detect ¶
func (a *Adapter) Detect(ctx context.Context, exec executor.Executor) (adapter.DetectionResult, error)
Detect reports whether the Codex CLI is on $PATH. Settings file presence is NOT a gate — install creates the files from scratch when absent.
func (*Adapter) Install ¶
Install adds DMG-owned hooks to hooks.json and ensures the `[features].codex_hooks=true` flag in config.toml.
Multi-file safety: every output buffer (hooks.json + config.toml) is loaded, validated, and encoded BEFORE the first write happens — a malformed config.toml aborts the operation with hooks.json still intact. Partial-write states are forbidden (covered by TestInstallMalformedTOMLDoesNotMutateHooks).
Idempotent: when both files are already in desired state, returns empty WrittenFiles and BackupFiles and performs no writes.
func (*Adapter) ManagedFiles ¶
func (a *Adapter) ManagedFiles() []adapter.ManagedFile
ManagedFiles enumerates the two files Codex install/uninstall mutates. Used by the install handler for the chown sweep under root.
func (*Adapter) ParseEvent ¶
func (a *Adapter) ParseEvent(ctx context.Context, hookType event.HookEvent, raw []byte) (*event.Event, error)
ParseEvent normalizes a Codex hook stdin payload into a DMG event. The raw payload is REDACTED before being attached to the result; the original bytes never appear in the returned event.
func (*Adapter) ShellCommand ¶
ShellCommand extracts the redacted shell command from a parsed Codex event. Returns ok=false for everything except `Bash`. apply_patch's tool_input.command is a patch payload, not shell input.
func (*Adapter) SupportedHooks ¶
SupportedHooks returns a fresh copy of the Codex-supported hook list. Callers may freely mutate the returned slice without affecting adapter internals.
func (*Adapter) Uninstall ¶
Uninstall removes DMG-owned hook entries from hooks.json. The `[features].codex_hooks` flag in config.toml is intentionally NOT reverted — the user may have other tools' hooks that depend on it being enabled.
The settings file is preserved even when uninstall removes the last hook — leaving an empty {} (or whatever non-hook keys remain) keeps any user customization intact.