Codex.Sessions (Codex SDK v0.7.2)

Copy Markdown View Source

Helpers for inspecting Codex CLI session files and replaying recorded changes.

Summary

Functions

Applies a unified diff or file_change items to the local working tree.

Lists known sessions by scanning the sessions directory.

Restores the working tree using a ghost snapshot item.

Types

apply_result()

@type apply_result() :: %{
  stdout: String.t(),
  stderr: String.t(),
  exit_code: integer(),
  success: boolean()
}

session_entry()

@type session_entry() :: %{
  id: String.t(),
  path: String.t(),
  started_at: String.t() | nil,
  updated_at: String.t() | nil,
  cwd: String.t() | nil,
  originator: String.t() | nil,
  cli_version: String.t() | nil,
  metadata: map()
}

Functions

apply(input, opts \\ [])

@spec apply(
  String.t() | list(),
  keyword()
) :: {:ok, apply_result()} | {:error, term()}

Applies a unified diff or file_change items to the local working tree.

Accepts either a diff string or a list of %Codex.Items.FileChange{} structs (or raw change maps with path, kind, and diff fields).

list_sessions(opts \\ [])

@spec list_sessions(keyword()) :: {:ok, [session_entry()]} | {:error, term()}

Lists known sessions by scanning the sessions directory.

Options

  • :sessions_dir - Override the default session directory.

undo(snapshot, opts \\ [])

@spec undo(
  term(),
  keyword()
) :: {:ok, map()} | {:error, term()}

Restores the working tree using a ghost snapshot item.

Accepts a %Codex.Items.GhostSnapshot{} struct, a raw response item map, or a ghost commit map with id and preexisting untracked fields.