processor

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ToolNameTask      = "Task"
	ToolNameBash      = "Bash"
	ToolNameEdit      = "Edit"
	ToolNameMultiEdit = "MultiEdit"
	ToolNameWrite     = "Write"
	ToolNameRead      = "Read"
	ToolNameTodoWrite = "TodoWrite"
)

Tool names

View Source
const (
	TypeUser       = "user"
	TypeAssistant  = "assistant"
	TypeMessage    = "message"
	TypeToolUse    = "tool_use"
	TypeToolResult = "tool_result"
)

Entry types

View Source
const (
	RoleUser      = "user"
	RoleAssistant = "assistant"
)

Roles

View Source
const (
	ContentTypeText       = "text"
	ContentTypeToolUse    = "tool_use"
	ContentTypeToolResult = "tool_result"
)

Content types

View Source
const (
	TagCommandName   = "command-name"
	TagCommandArgs   = "command-args"
	TagCommandStdout = "local-command-stdout"
)

XML tags for command parsing

View Source
const (
	BashOutputCollapseThreshold = 20
	ShortUUIDLength             = 8
	MinTextLengthForPrefixMatch = 20
)

UI and formatting constants

View Source
const (
	DefaultBufferSize = 64 * 1024        // 64KB buffer
	MaxLineSize       = 10 * 1024 * 1024 // 10MB max line size
)

Parser constants

View Source
const (
	HTMLBuilderInitialCapacity = 100
)

Builder constants

View Source
const (
	ThousandSeparatorThreshold = 1000
)

Number formatting constants

Variables

This section is empty.

Functions

func EstimateTokens

func EstimateTokens(text string) int

EstimateTokens provides a simple approximation of token count This uses a rough heuristic: ~4 characters per token for English text For more accurate counting, you would need to use the actual tokenizer

func GetBoolValue

func GetBoolValue(m map[string]interface{}, key string) bool

GetBoolValue extracts a bool value from a map

func GetStringValue

func GetStringValue(m map[string]interface{}, key string) string

GetStringValue extracts a string value from a map

func ProcessAssistantMessage

func ProcessAssistantMessage(msg map[string]interface{}, cwd string) (string, []models.ToolCall)

ProcessAssistantMessage processes assistant messages and returns raw content and tool calls

func ProcessEntries

func ProcessEntries(entries []models.LogEntry) []*models.ProcessedEntry

ProcessEntries processes raw log entries into a structured format

func ProcessToolUse

func ProcessToolUse(toolUse map[string]interface{}) models.ToolCall

ProcessToolUse processes a tool use message and returns a ToolCall This function delegates to the global ToolProcessor for consistency

func ProcessUserMessage

func ProcessUserMessage(msg map[string]interface{}) string

ProcessUserMessage processes user messages and returns raw content

Types

type HierarchyBuilder

type HierarchyBuilder struct{}

HierarchyBuilder builds parent-child relationships and calculates depths

func NewHierarchyBuilder

func NewHierarchyBuilder() *HierarchyBuilder

NewHierarchyBuilder creates a new hierarchy builder

func (*HierarchyBuilder) BuildHierarchy

func (h *HierarchyBuilder) BuildHierarchy(entries []*models.ProcessedEntry) error

BuildHierarchy builds the hierarchy and sets depths for all entries

func (*HierarchyBuilder) BuildParentChildMap

func (h *HierarchyBuilder) BuildParentChildMap(entries []*models.ProcessedEntry) map[string][]string

BuildParentChildMap builds a map of parent UUIDs to child UUIDs

type MatchingOptions

type MatchingOptions struct {
	WindowSize time.Duration
}

MatchingOptions controls how tool calls are matched

type MessageHandler

type MessageHandler func(*models.ProcessedEntry, map[string]interface{}, models.LogEntry) error

MessageHandler defines a function for processing specific message types

type ProcessingState

type ProcessingState struct {
	Entries        []*models.ProcessedEntry
	ToolCallMap    map[string]*ToolCallContext
	ParentChildMap map[string][]string
	RootParent     string
	Index          int
}

ProcessingState holds all state during entry processing

type SidechainContext

type SidechainContext struct {
	RootToolCallID string
	StartIndex     int
	EndIndex       int
	Entries        []*models.ProcessedEntry
}

SidechainContext tracks active sidechain conversations

type SidechainProcessor

type SidechainProcessor struct{}

SidechainProcessor handles processing of sidechain conversations

func NewSidechainProcessor

func NewSidechainProcessor() *SidechainProcessor

NewSidechainProcessor creates a new sidechain processor

func (*SidechainProcessor) ProcessSidechains

func (s *SidechainProcessor) ProcessSidechains(entries []*models.ProcessedEntry, originalEntries []models.LogEntry, entryMap map[string]*models.ProcessedEntry) error

ProcessSidechains processes sidechain conversations and matches them with Task tool calls

type TaskMatchContext

type TaskMatchContext struct {
	ToolCall          *models.ToolCall
	Entry             *models.LogEntry
	OriginalEntries   []models.LogEntry
	SidechainRoots    []*models.ProcessedEntry
	EntryMap          map[string]*models.ProcessedEntry
	MatchedSidechains map[string]bool
}

TaskMatchContext holds the context for matching Task tools with sidechains

type TokenProcessor

type TokenProcessor struct{}

TokenProcessor handles token counting logic

func NewTokenProcessor

func NewTokenProcessor() *TokenProcessor

NewTokenProcessor creates a new token processor

func (*TokenProcessor) ProcessTokens

func (tp *TokenProcessor) ProcessTokens(processed *models.ProcessedEntry, msg map[string]interface{})

ProcessTokens extracts and calculates token counts for an entry

type ToolCallContext

type ToolCallContext struct {
	Entry      *models.ProcessedEntry
	ToolCall   *models.ToolCall
	CallTime   time.Time
	ParentID   string
	IsComplete bool
}

ToolCallContext tracks pending tool calls

type ToolCallMatcher

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

ToolCallMatcher handles matching tool calls with their results

func NewToolCallMatcher

func NewToolCallMatcher() *ToolCallMatcher

NewToolCallMatcher creates a new tool call matcher

func (*ToolCallMatcher) FilterRootEntries

func (m *ToolCallMatcher) FilterRootEntries(entries []*models.ProcessedEntry) []*models.ProcessedEntry

FilterRootEntries filters entries to only include root conversation entries

func (*ToolCallMatcher) MatchToolCalls

func (m *ToolCallMatcher) MatchToolCalls(entries []*models.ProcessedEntry) error

MatchToolCalls matches tool calls with their results

type ToolProcessor

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

ToolProcessor handles all tool-related processing

func GetToolProcessor

func GetToolProcessor() *ToolProcessor

GetToolProcessor returns the global tool processor instance

func (*ToolProcessor) ProcessToolCall

func (tp *ToolProcessor) ProcessToolCall(toolCall *models.ToolCall)

ProcessToolCall processes a tool call, applying formatting and extracting metadata

func (*ToolProcessor) ProcessToolUseWithRegistry

func (tp *ToolProcessor) ProcessToolUseWithRegistry(toolUse map[string]interface{}) models.ToolCall

ProcessToolUseWithRegistry processes a tool use message and returns a ToolCall This replaces the standalone ProcessToolUse function

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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