codex

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: Apache-2.0 Imports: 23 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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.

View Source
const AgentBinary = "codex"

AgentBinary is the name `executor.LookPath` searches for during detection. Adapter-private.

View Source
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

func New(home, binaryPath string) *Adapter

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

func (a *Adapter) DecideResponse(ev *event.Event, d adapter.Decision) adapter.HookResponse

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

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

func (a *Adapter) Install(ctx context.Context) (adapter.InstallResult, error)

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) Name

func (a *Adapter) Name() string

Name returns the adapter agent name.

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

func (a *Adapter) ShellCommand(ev *event.Event) (cmd string, cwd string, ok bool)

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

func (a *Adapter) SupportedHooks() []event.HookEvent

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

func (a *Adapter) Uninstall(ctx context.Context) (adapter.UninstallResult, error)

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.

Jump to

Keyboard shortcuts

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