codex

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package codex is the brainjar Platform adapter for OpenAI Codex CLI. Imported for side effects from internal/cli to register itself in the parent platform registry.

Runtime verified against openai/codex main @ 0127cef / rust-v0.122.0 (Apr 2026). Sync targets AGENTS.md at the project root; hooks use Codex's Claude-Code-compatible JSON schema in .codex/hooks.json and require [features] codex_hooks = true in the matching config.toml; MCP registration merges into ~/.codex/config.toml as a [mcp_servers.brainjar] table.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Platform

type Platform struct{}

Platform adapts brainjar to the OpenAI Codex CLI.

func (*Platform) Capabilities

func (c *Platform) Capabilities() platform.Capabilities

Capabilities implements Platform. Codex supports sync, hooks (behind a feature flag), MCP registration, and CLI-arg prompt injection. Local scope is Claude-specific — Codex has no gitignored-override file tier.

func (*Platform) Catalog added in v0.6.0

func (c *Platform) Catalog() platform.ModelCatalog

Catalog satisfies platform.Platform.

func (*Platform) EmitSkills added in v0.6.0

EmitSkills returns ErrUnsupportedByPlatform — Codex has no skills loader yet. The CLI catches the sentinel and downgrades it to a one-line warning so sync still writes AGENTS.md.

func (*Platform) HooksStatus

func (c *Platform) HooksStatus(_ context.Context, scope platform.HookScope, projectRoot string) (platform.HookStatus, error)

HooksStatus reports whether brainjar's hook is present and whether the installed command matches what InstallHooks would write now. Up to date means both entry and flag agree with a fresh install.

func (*Platform) InstallHooks

func (c *Platform) InstallHooks(_ context.Context, scope platform.HookScope, projectRoot string) error

InstallHooks registers brainjar's UserPromptSubmit hook in <scope>/.codex/hooks.json and sets [features] codex_hooks = true in the matching config.toml. Both files are atomic-rewritten; sibling hooks and config keys are preserved.

func (*Platform) InstallMCP

func (c *Platform) InstallMCP(_ context.Context, scope platform.HookScope, projectRoot, home string) error

InstallMCP registers brainjar as a stdio MCP server in $CODEX_HOME/config.toml under [mcp_servers.brainjar]. User scope only — Codex's own `codex mcp add` also writes user-global config, and project-scope MCP under an untrusted .codex is awkward.

func (*Platform) MCPStatus

func (c *Platform) MCPStatus(_ context.Context, scope platform.HookScope, projectRoot, home string) (platform.MCPStatus, error)

MCPStatus reports registration presence and whether stored command + args match what InstallMCP would write now for the given home.

func (*Platform) MapModelPrefs

func (c *Platform) MapModelPrefs(prefs *models.ModelPrefs) map[string]any

MapModelPrefs delegates to the catalog-backed canonical helper. Codex accepts arbitrary model identifiers server-side; unknown names pass through verbatim — a user who writes a specific ID meant exactly that.

func (*Platform) ModelArgs added in v0.6.0

func (c *Platform) ModelArgs(prefs *models.ModelPrefs) []string

ModelArgs renders prefs as argv for `codex` — `--model <id>`. The caller prepends the result so user-supplied `-- --model X` still wins.

func (*Platform) Name

func (c *Platform) Name() string

Name implements Platform.

func (*Platform) RemoveHooks

func (c *Platform) RemoveHooks(_ context.Context, scope platform.HookScope, projectRoot string) error

RemoveHooks strips brainjar's hook entry from hooks.json. The codex_hooks feature flag is left alone — turning it off could disable other user-authored hooks, so that's a deliberate no-touch.

func (*Platform) RemoveMCP

func (c *Platform) RemoveMCP(_ context.Context, scope platform.HookScope, projectRoot string) error

RemoveMCP strips brainjar's [mcp_servers.brainjar] table while preserving every sibling server entry.

func (*Platform) SkillsStatus added in v0.6.0

func (c *Platform) SkillsStatus(_ context.Context, _ string) (platform.SkillsStatus, error)

SkillsStatus returns ErrUnsupportedByPlatform for the same reason EmitSkills does — there is no on-disk skill surface for Codex.

func (*Platform) Spawn

func (c *Platform) Spawn(ctx context.Context, prompt string, extraArgs []string) (*exec.Cmd, error)

Spawn implements Platform. Builds an *exec.Cmd that runs `codex --system-prompt <prompt> [extraArgs...]`. Stdio is left nil so the caller wires the streams; PATH lookup happens at Start() time.

func (*Platform) Sync

func (c *Platform) Sync(_ context.Context, prompt string, projectRoot string) error

Sync writes the composed prompt into the managed section of <projectRoot>/AGENTS.md. Content outside the markers survives byte-for-byte. Idempotent: a second Sync with the same prompt is a no-op. Emits a warning to stderr when the final file would exceed Codex's 32 KiB AGENTS.md budget.

func (*Platform) SyncRemove added in v0.7.0

func (c *Platform) SyncRemove(_ context.Context, projectRoot string) error

SyncRemove strips brainjar's managed section from the project's AGENTS.md. Empty file → removed. Missing file → no-op.

func (*Platform) SyncUser added in v0.7.0

func (c *Platform) SyncUser(_ context.Context, prompt string) error

SyncUser writes the composed prompt into $CODEX_HOME/AGENTS.md (default ~/.codex/AGENTS.md). Same managed-section semantics as Sync.

Jump to

Keyboard shortcuts

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