Skip to main content

Module grok

Module grok 

Source
Expand description

Grok CLI (Grok Build): ~/.grok/sessions/<urlencoded-cwd>/<session-uuid>/.

A Grok session is a directory of files, three of which matter here:

  • chat_history.jsonl — the model-protocol log, one record per line typed by type: system, user, assistant (text + tool_calls), reasoning (summary + encrypted_content), tool_result. This is what the model sees on continuation.
  • updates.jsonl — the ACP display log (session/update notifications: user_message_chunk, agent_message_chunk, agent_thought_chunk, tool_call, tool_call_update, turn_completed, …). This is what grok --resume and grok export actually replay; a session without it is invisible to Grok.
  • summary.json — session metadata (id, cwd, title, model, git info).

The remaining sidecars (events.jsonl telemetry, signals.json, prompt_context.json, resources_state.json, rewind_points.jsonl, system_prompt.txt) are carried verbatim in the GrokSession body so a native load → save round-trips them; from_common leaves them empty and Grok regenerates what it needs.

to_common reads the conversation from chat_history.jsonl and backfills what that log lacks from updates.jsonl: per-message timestamps, tool-result error status, and per-turn stop reasons. from_common regenerates chat_history.jsonl, updates.jsonl, and summary.json.

User images follow Grok’s own split: the display log carries the bytes (an ACP {"type": "image", data, mimeType} chunk of the prompt), while the model log holds only text — natively a Grok-generated description; from_common writes an [image] placeholder there.

from_common cannot preserve per-turn usage, non-turn stop reasons, reasoning signatures, structured tool-result JSON, reasoning record ids, or system prompt records.

Structs§

AssistantLine
An assistant line: response text plus any tool_calls (whose arguments are JSON-in-a-string).
Grok
The Grok CLI harness marker.
GrokSession
Faithful in-memory representation of one Grok session directory.
GrokStore
Reads and writes Grok session directories under a sessions root (default ~/.grok/sessions, or $GROK_HOME/sessions).
ReasoningLine
A reasoning line: summary text plus the opaque provider reasoning token.
SystemLine
A system line: the injected system prompt.
ToolResultLine
A tool_result line.
UserLine
A user line: content blocks, plus prior_turn_interrupt when the previous turn was aborted mid-flight.

Enums§

ChatRecord
One chat_history.jsonl line. Known kinds are typed; anything else (or a malformed known kind) is kept whole in ChatRecord::Other.