LemonCliRunners. CodexSchema
(lemon_cli_runners v0.1.0)
View Source
Codex CLI JSONL event schema definitions.
This module defines all the event types emitted by codex exec --json.
Events are decoded from newline-delimited JSON (JSONL) format.
Event Categories
Session Lifecycle
ThreadStarted- Session has started with a thread_idTurnStarted- New conversation turn has begunTurnCompleted- Conversation turn has finished (includes usage)TurnFailed- Turn failed with error
Stream Events
StreamError- Stream-level error or reconnection notice
Item Events
Items represent discrete work units within a turn:
ItemStarted- Item has begunItemUpdated- Item has progress updateItemCompleted- Item has finished
Item Types
AgentMessageItem- Final text response from agentReasoningItem- Extended thinking/reasoning textCommandExecutionItem- Shell command executionFileChangeItem- File modificationsMcpToolCallItem- MCP tool invocationWebSearchItem- Web search queryTodoListItem- Task listErrorItem- Error message
Decoding
case CodexSchema.decode_event(json_line) do
{:ok, %ThreadStarted{thread_id: id}} -> ...
{:ok, %ItemCompleted{item: item}} -> ...
{:error, reason} -> ...
end
Summary
Functions
Decode a JSON line into a thread event struct.
Decode a map (already parsed JSON) into a thread event struct.
Types
@type thread_event() :: LemonCliRunners.CodexSchema.ThreadStarted.t() | LemonCliRunners.CodexSchema.TurnStarted.t() | LemonCliRunners.CodexSchema.TurnCompleted.t() | LemonCliRunners.CodexSchema.TurnFailed.t() | LemonCliRunners.CodexSchema.StreamError.t() | LemonCliRunners.CodexSchema.ItemStarted.t() | LemonCliRunners.CodexSchema.ItemUpdated.t() | LemonCliRunners.CodexSchema.ItemCompleted.t()
Union of all thread event types
@type thread_item() :: LemonCliRunners.CodexSchema.AgentMessageItem.t() | LemonCliRunners.CodexSchema.ReasoningItem.t() | LemonCliRunners.CodexSchema.CommandExecutionItem.t() | LemonCliRunners.CodexSchema.FileChangeItem.t() | LemonCliRunners.CodexSchema.McpToolCallItem.t() | LemonCliRunners.CodexSchema.WebSearchItem.t() | LemonCliRunners.CodexSchema.TodoListItem.t() | LemonCliRunners.CodexSchema.ErrorItem.t()
Union of all thread item types
Functions
@spec decode_event(String.t() | binary()) :: {:ok, thread_event()} | {:error, term()}
Decode a JSON line into a thread event struct.
Returns {:ok, event} on success or {:error, reason} on failure.
Examples
iex> CodexSchema.decode_event(~s|{"type":"thread.started","thread_id":"abc123"}|)
{:ok, %ThreadStarted{thread_id: "abc123"}}
iex> CodexSchema.decode_event(~s|{"type":"item.completed","item":{"type":"agent_message","id":"1","text":"Hello"}}|)
{:ok, %ItemCompleted{item: %AgentMessageItem{id: "1", text: "Hello"}}}
@spec decode_event_map(map()) :: {:ok, thread_event()} | {:error, term()}
Decode a map (already parsed JSON) into a thread event struct.