grok

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package grok provides an adapter for Grok Build TUI sessions.

Sessions live under $GROK_HOME/sessions (default ~/.grok/sessions), organized by URL-encoded working directory:

~/.grok/sessions/<encoded-cwd>/<session-id>/
  summary.json         // metadata index (title, timestamps, model, parent)
  chat_history.jsonl   // structured conversation for display
  events.jsonl         // runtime telemetry
  updates.jsonl        // ACP restore log

Encoding matches Python urllib.parse.quote(path, safe=”): every non-unreserved byte is percent-encoded, so "/" becomes "%2F".

Resume CLI: grok --resume <session-id>

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

type Adapter struct {
	// contains filtered or unexported fields
}

Adapter implements adapter.Adapter for Grok Build sessions.

func New

func New() *Adapter

New creates a Grok adapter using GROK_HOME or ~/.grok.

func NewWithSessionsDir

func NewWithSessionsDir(sessionsDir string) *Adapter

NewWithSessionsDir creates an adapter rooted at sessionsDir (for tests).

func (*Adapter) Capabilities

func (a *Adapter) Capabilities() adapter.CapabilitySet

Capabilities returns supported features.

func (*Adapter) Detect

func (a *Adapter) Detect(projectRoot string) (bool, error)

Detect reports whether any Grok sessions exist for projectRoot.

func (*Adapter) DiscoverRelatedProjectDirs

func (a *Adapter) DiscoverRelatedProjectDirs(mainWorktreePath string) ([]string, error)

DiscoverRelatedProjectDirs finds other Grok-encoded project dirs under the same sessions root that look like worktrees of mainWorktreePath.

func (*Adapter) ID

func (a *Adapter) ID() string

ID returns the adapter identifier.

func (*Adapter) Icon

func (a *Adapter) Icon() string

Icon returns the adapter icon for badge display.

func (*Adapter) Messages

func (a *Adapter) Messages(sessionID string) ([]adapter.Message, error)

Messages returns conversation messages for sessionID.

func (*Adapter) Name

func (a *Adapter) Name() string

Name returns the human-readable adapter name.

func (*Adapter) SearchMessages

func (a *Adapter) SearchMessages(sessionID, query string, opts adapter.SearchOptions) ([]adapter.MessageMatch, error)

SearchMessages searches message content within a session. Implements adapter.MessageSearcher.

func (*Adapter) SessionByID

func (a *Adapter) SessionByID(sessionID string) (*adapter.Session, error)

SessionByID implements TargetedRefresher.

func (*Adapter) SessionIDFromPath

func (a *Adapter) SessionIDFromPath(path string) (string, error)

SessionIDFromPath resolves a chat_history path to its session ID.

func (*Adapter) Sessions

func (a *Adapter) Sessions(projectRoot string) ([]adapter.Session, error)

Sessions returns project-scoped sessions sorted by UpdatedAt desc.

func (*Adapter) Usage

func (a *Adapter) Usage(sessionID string) (*adapter.UsageStats, error)

Usage is not available from Grok chat history; returns empty stats.

func (*Adapter) Watch

func (a *Adapter) Watch(projectRoot string) (<-chan adapter.Event, io.Closer, error)

Watch watches the sessions root for changes, filtering to projectRoot.

func (*Adapter) WatchForProjectDiscovery

func (a *Adapter) WatchForProjectDiscovery() bool

WatchForProjectDiscovery keeps the watcher alive when the project has no sessions yet so the first session can appear without a restart.

func (*Adapter) WatchScope

func (a *Adapter) WatchScope() adapter.WatchScope

WatchScope is global: all projects live under a single sessions root.

type ChatLine

type ChatLine struct {
	Type            string          `json:"type"`
	ID              string          `json:"id"`
	Content         json.RawMessage `json:"content"`
	ToolCallID      string          `json:"tool_call_id"`
	ToolCalls       []ToolCall      `json:"tool_calls"`
	ModelID         string          `json:"model_id"`
	Summary         []SummaryText   `json:"summary"` // reasoning summaries
	Status          string          `json:"status"`
	SyntheticReason string          `json:"synthetic_reason"`
}

ChatLine is one JSONL record from chat_history.jsonl. Content is heterogeneous (string or array of blocks) so it stays raw JSON.

type ContentBlock

type ContentBlock struct {
	Type string `json:"type"`
	Text string `json:"text"`
}

ContentBlock is a user content part (text or image).

type Summary

type Summary struct {
	Info struct {
		ID  string `json:"id"`
		CWD string `json:"cwd"`
	} `json:"info"`
	SessionSummary  string    `json:"session_summary"`
	GeneratedTitle  string    `json:"generated_title"`
	CreatedAt       time.Time `json:"created_at"`
	UpdatedAt       time.Time `json:"updated_at"`
	LastActiveAt    time.Time `json:"last_active_at"`
	NumMessages     int       `json:"num_messages"`
	NumChatMessages int       `json:"num_chat_messages"`
	CurrentModelID  string    `json:"current_model_id"`
	GitRootDir      string    `json:"git_root_dir"`
	AgentName       string    `json:"agent_name"`
	SessionKind     string    `json:"session_kind"`
	ParentSessionID string    `json:"parent_session_id"`
}

Summary is the on-disk summary.json index for a Grok session.

type SummaryText

type SummaryText struct {
	Type string `json:"type"`
	Text string `json:"text"`
}

SummaryText is a reasoning summary fragment.

type ToolCall

type ToolCall struct {
	ID        string `json:"id"`
	Name      string `json:"name"`
	Arguments string `json:"arguments"` // JSON string in Grok format
}

ToolCall is an assistant tool invocation on a chat line.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL