sessions

package
v0.0.80 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatInfoText

func FormatInfoText(info *SessionInfo, home string, now time.Time) string

func FormatListTable

func FormatListTable(sessions []Session, home string, now time.Time) string

func FormatListTableWithHits added in v0.0.59

func FormatListTableWithHits(matches []SessionMatch, home string, now time.Time, colorMode string) string

FormatListTableWithHits formats matching sessions like FormatListTable, with indented hit lines under each row. colorMode is "never" | "always" | "auto". Output has no trailing newline (same TrimRight style as FormatListTable).

func FormatStatsText added in v0.0.80

func FormatStatsText(stats *SessionStats, home string, now time.Time) string

FormatStatsText is a thin wrapper for callers that do not pass color/top options. Uses ColorMode "never" and TopN 5.

func FormatStatsTextOpts added in v0.0.80

func FormatStatsTextOpts(stats *SessionStats, opts FormatStatsOptions) string

FormatStatsTextOpts renders SessionStats as sectioned human-readable text. Optional tool / background / subagent sections are omitted when empty. Pretty durations on all duration fields; tool table sorted by N desc then name; Top-N sections when TopN > 0; ANSI when shouldColor(ColorMode). Trailing newline is trimmed (CLI may re-add via fmt.Println).

Types

type BackgroundTaskItem added in v0.0.80

type BackgroundTaskItem struct {
	DurationMs  float64
	Command     string // full, never store-truncate
	Description string
	ExitCode    *int
	Kind, CWD   string
}

BackgroundTaskItem is one background task sample for Top-N tables.

type FormatStatsOptions added in v0.0.80

type FormatStatsOptions struct {
	Home      string
	Now       time.Time
	ColorMode string // "auto" | "always" | "never"; empty → treat as "never" in tests
	TopN      int    // default 5 at CLI; 0 hides Top tools/background/subagent sections
}

FormatStatsOptions configures human stats text (pretty durations, color, tops).

type MatchHit added in v0.0.59

type MatchHit struct {
	File       string // "summary.json", "chat_history.jsonl"
	Line       int    // 1-based
	Part       string // title, session_summary, cwd, user, assistant, ...
	Snippet    string // one-line excerpt
	MatchStart int    // byte offset into Snippet
	MatchLen   int    // length of match in Snippet
}

MatchHit is one content match inside a session file.

type RelocateCWDOptions added in v0.0.62

type RelocateCWDOptions struct {
	// GrokHome is the Grok home directory. Empty → $GROK_HOME or ~/.grok.
	GrokHome string
}

RelocateCWDOptions configures RelocateCWD.

type RelocateCWDResult added in v0.0.62

type RelocateCWDResult struct {
	OldCWD, NewCWD, OldSessionDir, NewSessionDir string
	FilesTouched                                 []string // optional
}

RelocateCWDResult reports paths after a successful relocate.

func RelocateCWD added in v0.0.62

func RelocateCWD(sessionID, targetDir string, opts *RelocateCWDOptions) (*RelocateCWDResult, error)

RelocateCWD relocates a Grok session's workspace cwd by updating explicit JSON fields and moving the session directory under the URL-encoded new cwd key.

Call shape: sessionID first (required), targetDir second (required), opts last (nil OK).

type Session

type Session struct {
	ID              string
	LastActiveAt    time.Time
	CWD             string
	Title           string
	Path            string
	NumChatMessages int
}

func Find

func Find(grokHome, sessionID string) (Session, error)

func List

func List(grokHome string, limit int) ([]Session, error)

type SessionInfo

type SessionInfo struct {
	Session
	CreatedAt, UpdatedAt        time.Time
	NumMessages                 int
	CurrentModelID              string
	AgentName                   string
	SandboxProfile              string
	GitRootDir                  string
	HeadBranch                  string
	HeadCommit                  string
	SessionDir                  string
	SummaryPath                 string
	UpdatesPath                 string
	SignalsPath                 string
	PromptContextPath           string
	UpdatesExists               bool
	SignalsExists               bool
	PromptContextExists         bool
	ContextTokensUsed           int
	ContextWindowTokens         int
	ContextWindowUsage          int
	TotalTokensBeforeCompaction int
}

func Info

func Info(grokHome, sessionID string) (*SessionInfo, error)

type SessionMatch added in v0.0.59

type SessionMatch struct {
	Session
	Hits []MatchHit // full hit list; formatter caps display at 5
}

SessionMatch is a session that matched a grep pattern, with all hits.

func ListWithGrep added in v0.0.59

func ListWithGrep(grokHome string, limit int, pattern string) ([]SessionMatch, error)

ListWithGrep discovers sessions, keeps those with ≥1 case-insensitive literal hit in summary.json or chat_history.jsonl, sorts by last_active_at desc, then applies limit.

type SessionStats added in v0.0.80

type SessionStats struct {
	ID, Title, CWD, Model, Agent string
	CreatedAt, LastActiveAt      time.Time

	Turns, UserMessages, AssistantMessages int
	ThinkingBlocks                         int
	ToolCalls, ToolCompleted, ToolFailed   int
	Compactions, Cancellations, Errors     int

	SessionDurationSec int
	AvgResponseMs      int
	AvgTTFTMs          int

	Tools           []ToolStat
	BackgroundTasks *TaskAgg
	Subagents       *TaskAgg

	// Per-item samples for Top background / Top subagent sections.
	// Command is stored full; display truncation is applied in FormatStatsTextOpts.
	BackgroundTaskItems []BackgroundTaskItem
	SubagentItems       []SubagentItem

	Sources StatsSources
}

SessionStats aggregates identity, counts, latency, tool times, and task aggregates for one Grok session from summary/signals/events/updates.

func Stats added in v0.0.80

func Stats(grokHome, sessionID string) (*SessionStats, error)

Stats locates a session by exact UUID and aggregates stats from summary, signals.json, events.jsonl, and updates.jsonl. Missing optional files do not fail; they set Sources flags and append human-readable warnings.

type StatsSources added in v0.0.80

type StatsSources struct {
	Summary, Signals, Events, Updates bool
	Warnings                          []string
}

StatsSources records which sidecar files contributed to SessionStats.

type SubagentItem added in v0.0.80

type SubagentItem struct {
	DurationMs                   float64
	ID, Description, Type        string
	Status, Model                string
	ToolCalls, Turns, TokensUsed int
}

SubagentItem is one subagent sample for Top-N tables (spawn join + finish).

type TaskAgg added in v0.0.80

type TaskAgg struct {
	Count        int
	AvgMs, MaxMs float64
}

TaskAgg holds count and duration aggregates for background tasks or subagents.

type ToolStat added in v0.0.80

type ToolStat struct {
	Name           string
	Count          int
	Success, Error int
	AvgMs, MedMs   float64
	MinMs, MaxMs   float64
}

ToolStat holds per-tool handler duration aggregates from events.jsonl.

Jump to

Keyboard shortcuts

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