feat: add Codex CLI support#49
Open
manuel-alvarez-alvarez wants to merge 5 commits into
Open
Conversation
Add OpenAI Codex CLI as a supported coding agent alongside Claude Code, giving it the same AI Guard protection. - src/aiguard/codex/: CodexHandler (hook dispatch + lifecycle/PreToolUse/ PostToolUse/UserPromptSubmit), translate.py (Codex rollout JSONL in the OpenAI Responses-API item shape -> AI Guard messages), and CodexInstaller (idempotent merge into ~/.codex/hooks.json, version gate >= 0.117.0). - src/aiguard/hooks/common.py: extract the agent-neutral blocked-tool payload, investigate-link builder, and common span tags shared by both handlers; ClaudeHandler refactored to use them (payloads unchanged). - UserPromptSubmit resolves explicit $skill / /prompts: references and injects the definition for evaluation (Codex's analog of Claude's UserPromptExpansion). - Wiring: _build_handler, SUPPORTED_AGENTS, ai-guard.spec hidden imports, paths (codex_config_dir/codex_hooks_path honoring $CODEX_HOME), constants. - docker/codex/ reference container + compose service (Rust-client proxy/CA env). - Tests mirror the Claude suite (unit + integration); full suite green.
|
Codex's bubblewrap sandbox can't create user namespaces inside Docker (bwrap: No permissions to create a new namespace). The container is the isolation boundary, so set sandbox_mode=danger-full-access and approval_policy=never in the reference config.toml.
Real Codex rollouts record apply_patch (and other freeform tools) as custom_tool_call / custom_tool_call_output items, not function_call. The translator only handled function_call*, so apply_patch — the file-edit tool — was silently dropped from the trajectory sent to AI Guard. - translate: map custom_tool_call -> assistant tool_call (payload is in `input`, a raw string, passed through as arguments) and custom_tool_call_output -> tool. - tests: add CodexRolloutWriter builders + a real-transcript fixture (rollout_wasm.jsonl, a trimmed codex-tui 0.140.0 session) and an end-to-end test asserting apply_patch and an empty function_call_output are captured.
Codex splits the system prompt and the first user turn across separate rollout items. Fold them back so AI Guard sees coherent turns: - session_meta.base_instructions.text (the base system prompt) is prepended into the developer-derived system message. - the injected <environment_context> user turn is merged with the user's first real prompt into one user message with multiple content parts. These are the only two merges — no general same-role coalescing.
3b42cb1 to
accf1b5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds OpenAI Codex CLI as a supported coding agent alongside Claude Code, giving it the same Datadog AI Guard protection. Codex's hook contract is nearly identical to Claude Code's (same
permissionDecision:"deny"/decision:"block"/reasonpayloads), so the decision-shaping layer is shared; the genuinely new pieces are the transcript translator (Codex uses OpenAI Responses-API rollout JSONL, not Anthropic blocks) and the installer (wires into~/.codex/hooks.json).What's included
src/aiguard/codex/—CodexHandler(dispatch +SessionStart/SubagentStart/SubagentStop/Stopspans,PreToolUsedeny,PostToolUseblock,UserPromptSubmit),translate.py(rolloutresponse_items → AI Guard messages),installer.py(idempotent merge into~/.codex/hooks.json, version gate>= 0.117.0).src/aiguard/hooks/common.py— extracted the agent-neutral blocked-tool payload, investigate-link builder, and common span tags;ClaudeHandlerrefactored to use them (payloads byte-unchanged, all Claude tests still pass).UserPromptSubmit— Codex's analog of Claude'sUserPromptExpansion: evaluates the prompt and resolves/injects explicit$skilland/prompts:definitions._build_handler,SUPPORTED_AGENTS,ai-guard.spechidden imports,paths.codex_config_dir/codex_hooks_path(honor$CODEX_HOME), constants.docker/codex/— reference container + compose service, configured for Codex's Rust HTTP client (proxy +CODEX_CA_CERTIFICATE).Notable design points / caveats
SKILL.mdwith no tool call and no hook event, so — unlike Claude'sSkill-tool gate atPreToolUse— only explicitly-invoked ($name) skills are screened today. ASessionStartskill audit is a possible follow-up.CODEX_MIN_VERSION = 0.117.0is the release that introducedPreToolUse/PostToolUse; pinned but not verified against the exact introducing build.🤖 Generated with Claude Code