CodexWrapper.JsonLineEvent (CodexWrapper v0.4.0)

Copy Markdown View Source

A single event from codex's --json NDJSON output.

When using --json, the codex CLI emits one JSON object per line. Each event has an event type and associated data.

Event types

Common event types include:

  • "thread.started" -- thread initialization
  • "turn.started" -- turn began
  • "item.completed" -- item completed
  • "turn.completed" -- turn finished

Summary

Functions

Return the full data map.

Return the event type string.

Get a value from the data map by key.

Parse a single NDJSON line into a %JsonLineEvent{}.

Parse multiple NDJSON lines from stdout into a list of events.

Parse a lazy stream of NDJSON lines into a lazy stream of events.

Whether this event matches the given type.

Types

t()

@type t() :: %CodexWrapper.JsonLineEvent{
  data: map(),
  event_type: String.t() | nil,
  raw: String.t()
}

Functions

data(json_line_event)

@spec data(t()) :: map()

Return the full data map.

event_type(json_line_event)

@spec event_type(t()) :: String.t() | nil

Return the event type string.

get(json_line_event, key, default \\ nil)

@spec get(t(), String.t(), term()) :: term()

Get a value from the data map by key.

parse(line)

@spec parse(String.t()) :: {:ok, t()} | {:error, term()}

Parse a single NDJSON line into a %JsonLineEvent{}.

parse_lines(stdout)

@spec parse_lines(String.t()) :: [t()]

Parse multiple NDJSON lines from stdout into a list of events.

Filters for lines that look like JSON objects and silently drops lines that fail to parse.

parse_stream(lines)

@spec parse_stream(Enumerable.t()) :: Enumerable.t()

Parse a lazy stream of NDJSON lines into a lazy stream of events.

The streaming counterpart of parse_lines/1: same silent drop of lines that do not parse, no buffering of the whole run. Used by Exec.stream/2, ExecResume.stream/2, and Review.stream/2 over the lines their CodexWrapper.Runner produces.

type?(json_line_event, expected)

@spec type?(t(), String.t()) :: boolean()

Whether this event matches the given type.