Documentation
¶
Overview ¶
Package codex drives the codex CLI as a subprocess and parses its JSON-lines output into a plain text reply with optional file-change events.
Index ¶
- func ParseFinalMessage(jsonlOutput string) (string, error)
- type ExecPolicyConfig
- type LoginStatusReport
- type Runner
- func (r Runner) Run(ctx context.Context, userText string) (string, error)
- func (r Runner) RunWithThreadAndProgress(ctx context.Context, threadID string, userText string, policy ExecPolicyConfig, ...) (string, string, error)
- func (r Runner) RunWithThreadAndProgressAndUsage(ctx context.Context, threadID string, userText string, policy ExecPolicyConfig, ...) (string, string, Usage, error)
- type Usage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseFinalMessage ¶
Types ¶
type ExecPolicyConfig ¶
ExecPolicyConfig controls codex sandbox and approval settings.
type LoginStatusReport ¶
LoginStatusReport holds the result of a Codex CLI login status check.
func CheckLogin ¶
func CheckLogin(command, codexHome string, timeout time.Duration) (LoginStatusReport, error)
CheckLogin runs "codex login status" for the given codexHome directory. If codexHome is empty, it falls back to $CODEX_HOME or ~/.codex. If timeout is zero or negative, a 15-second default is used.
type Runner ¶
type Runner struct {
Command string
Timeout time.Duration
IdleTimeout time.Duration
DefaultIdleTimeout time.Duration
HighIdleTimeout time.Duration
XHighIdleTimeout time.Duration
DefaultModel string
DefaultReasoningEffort string
Env map[string]string
WorkspaceDir string
}
Runner executes the codex CLI for a single request.
func (Runner) Run ¶
Run is a convenience wrapper that runs without thread resumption or progress callbacks.
func (Runner) RunWithThreadAndProgress ¶
func (r Runner) RunWithThreadAndProgress( ctx context.Context, threadID string, userText string, policy ExecPolicyConfig, model string, profile string, reasoningEffort string, personality string, env map[string]string, onThinking func(step string), ) (string, string, error)
RunWithThreadAndProgress runs the codex CLI and returns the final reply and next thread ID. It is a convenience wrapper around RunWithThreadAndProgressAndUsage.
func (Runner) RunWithThreadAndProgressAndUsage ¶
func (r Runner) RunWithThreadAndProgressAndUsage( ctx context.Context, threadID string, userText string, policy ExecPolicyConfig, model string, profile string, reasoningEffort string, personality string, env map[string]string, onThinking func(step string), onRawEvent func(kind, line, detail string), ) (string, string, Usage, error)
RunWithThreadAndProgressAndUsage runs the codex CLI and returns the final reply, next thread ID, and token usage.
- threadID: resume an existing session when non-empty.
- userText: the fully assembled prompt.
- policy: sandbox and approval settings.
- model, profile, reasoningEffort, personality: forwarded as CLI flags.
- env: merged over the process environment.
- onThinking: receives intermediate messages and file-change notifications.
- onRawEvent: optional callback for raw stdout events (kind, line, detail); nil disables raw event delivery.