jsonl

package
v1.45.7 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: GPL-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CountToolsAfterPosition

func CountToolsAfterPosition(tools []ToolUse, position int) int

CountToolsAfterPosition counts how many tools were used after a given position

func CountToolsByNames

func CountToolsByNames(tools []ToolUse, names []string) int

CountToolsByNames counts tools matching any of the given names

func ExtractRecentText

func ExtractRecentText(messages []Message, count int) string

ExtractRecentText extracts concatenated text from last N assistant messages

func ExtractTextFromMessages

func ExtractTextFromMessages(messages []Message) []string

ExtractTextFromMessages extracts all text content from messages

func ExtractToolInput

func ExtractToolInput(messages []Message, toolName string) map[string]interface{}

ExtractToolInput extracts the input parameters from a specific tool use Returns empty map if tool not found

func FindToolPosition

func FindToolPosition(tools []ToolUse, name string) int

FindToolPosition finds the position of a tool by name (last occurrence) Returns -1 if not found

func GetLastAssistantTimestamp

func GetLastAssistantTimestamp(messages []Message) string

GetLastAssistantTimestamp returns the timestamp of the last assistant message

func GetLastTool

func GetLastTool(tools []ToolUse) string

GetLastTool returns the last tool used, or empty string if none

func GetLastUserTimestamp

func GetLastUserTimestamp(messages []Message) string

GetLastUserTimestamp returns the timestamp of the last user message with text content Includes both string content (normal user messages) and array content with type="text" (interrupted tool use) Excludes tool_result messages

func HasAnyActiveTool

func HasAnyActiveTool(tools []ToolUse, activeTools []string) bool

HasAnyActiveTool checks if any active tool was used

func HasRecentApiError

func HasRecentApiError(messages []Message) bool

HasRecentApiError checks if there are API error messages after the last user message

Types

type Content

type Content struct {
	Type  string                 `json:"type"`
	Name  string                 `json:"name,omitempty"`
	Text  string                 `json:"text,omitempty"`
	Input map[string]interface{} `json:"input,omitempty"`
}

Content represents a content block in a message

func FindLastToolUse

func FindLastToolUse(messages []Message, toolName string) *Content

FindLastToolUse finds the last occurrence of a specific tool use in messages Returns nil if not found

type Message

type Message struct {
	ParentUUID        string         `json:"parentUuid"`
	Type              string         `json:"type"`
	Message           MessageContent `json:"message"`
	Timestamp         string         `json:"timestamp"`
	IsApiErrorMessage bool           `json:"isApiErrorMessage,omitempty"`
	Error             string         `json:"error,omitempty"`
}

Message represents a Claude Code transcript message

func FilterMessagesAfterTimestamp

func FilterMessagesAfterTimestamp(messages []Message, afterTimestamp string) []Message

FilterMessagesAfterTimestamp filters messages that occurred after given timestamp Returns only assistant messages after the timestamp This is used to filter messages to only those in the current response (after last user message)

func GetLastApiErrorMessages

func GetLastApiErrorMessages(messages []Message, count int) []Message

GetLastApiErrorMessages returns the last N messages with isApiErrorMessage=true

func GetLastAssistantMessages

func GetLastAssistantMessages(messages []Message, count int) []Message

GetLastAssistantMessages returns the last N assistant messages

func Parse

func Parse(r io.Reader) ([]Message, error)

Parse parses JSONL from a reader and returns all messages. Uses bufio.Reader instead of bufio.Scanner to handle arbitrarily long lines (e.g. base64-encoded images, large code diffs in Claude Code transcripts).

func ParseFile

func ParseFile(path string) ([]Message, error)

ParseFile parses a JSONL file and returns all messages

type MessageContent

type MessageContent struct {
	Role          string    `json:"role"`
	Content       []Content `json:"-"` // Array content (tool_result, assistant messages)
	ContentString string    `json:"-"` // String content (user text messages)
}

MessageContent represents the content of a message Content can be either a string (user text messages) or an array (tool results, assistant messages)

func (MessageContent) MarshalJSON

func (m MessageContent) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for MessageContent Outputs content as string if ContentString is set, otherwise as array

func (*MessageContent) UnmarshalJSON

func (m *MessageContent) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for MessageContent Handles both string content (user text messages) and array content (tool results, assistant messages)

type ToolUse

type ToolUse struct {
	Position int
	Name     string
}

ToolUse represents a tool use with its position

func ExtractTools

func ExtractTools(messages []Message) []ToolUse

ExtractTools extracts all tools from messages with their positions

Jump to

Keyboard shortcuts

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