parser

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractCwdFromSession

func ExtractCwdFromSession(path string) string

ExtractCwdFromSession reads the first cwd field from a Claude Code JSONL session file.

func ExtractProjectFromCwd

func ExtractProjectFromCwd(cwd string) string

ExtractProjectFromCwd extracts a project name from a working directory path. Returns the last path component, normalized.

func GeminiSessionID

func GeminiSessionID(data []byte) string

GeminiSessionID extracts the sessionId field from raw Gemini session JSON data without fully parsing.

func GetProjectName

func GetProjectName(dirName string) string

GetProjectName converts an encoded Claude project directory name to a clean project name. Claude encodes paths like /Users/alice/code/my-app as -Users-alice-code-my-app.

func NeedsProjectReparse

func NeedsProjectReparse(project string) bool

NeedsProjectReparse checks if a stored project name looks like an un-decoded encoded path that should be re-extracted.

func NormalizeToolCategory

func NormalizeToolCategory(rawName string) string

NormalizeToolCategory maps a raw tool name to a normalized category. Categories: Read, Edit, Write, Bash, Grep, Glob, Task, Other.

func ParseClaudeSession

func ParseClaudeSession(
	path, project, machine string,
) (ParsedSession, []ParsedMessage, error)

ParseClaudeSession parses a Claude Code JSONL session file.

func ParseCodexSession

func ParseCodexSession(
	path, machine string, includeExec bool,
) (*ParsedSession, []ParsedMessage, error)

ParseCodexSession parses a Codex JSONL session file. Returns nil session if the session is non-interactive and includeExec is false.

func ParseGeminiSession

func ParseGeminiSession(
	path, project, machine string,
) (*ParsedSession, []ParsedMessage, error)

ParseGeminiSession parses a Gemini CLI session JSON file. Unlike Claude/Codex JSONL, each Gemini file is a single JSON document containing all messages.

Types

type AgentType

type AgentType string

AgentType identifies the AI agent that produced a session.

const (
	AgentClaude AgentType = "claude"
	AgentCodex  AgentType = "codex"
	AgentGemini AgentType = "gemini"
)

type FileInfo

type FileInfo struct {
	Path  string
	Size  int64
	Mtime int64
	Hash  string
}

FileInfo holds file system metadata for a session source file.

type ParsedMessage

type ParsedMessage struct {
	Ordinal       int
	Role          RoleType
	Content       string
	Timestamp     time.Time
	HasThinking   bool
	HasToolUse    bool
	ContentLength int
	ToolCalls     []ParsedToolCall
}

ParsedMessage holds a single extracted message.

type ParsedSession

type ParsedSession struct {
	ID           string
	Project      string
	Machine      string
	Agent        AgentType
	FirstMessage string
	StartedAt    time.Time
	EndedAt      time.Time
	MessageCount int
	File         FileInfo
}

ParsedSession holds session metadata extracted from a JSONL file.

type ParsedToolCall

type ParsedToolCall struct {
	ToolName string // raw name from session data
	Category string // normalized: Read, Edit, Write, Bash, etc.
}

ParsedToolCall holds a single tool invocation extracted from a message.

func ExtractTextContent

func ExtractTextContent(
	content gjson.Result,
) (string, bool, bool, []ParsedToolCall)

ExtractTextContent extracts readable text from message content. content can be a string or a JSON array of blocks. Returns the text, hasThinking, hasToolUse, and tool calls.

type RoleType

type RoleType string

RoleType identifies the role of a message sender.

const (
	RoleUser      RoleType = "user"
	RoleAssistant RoleType = "assistant"
)

Jump to

Keyboard shortcuts

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