debuglog

package
v0.0.82 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DirSize

func DirSize(dir string) (int64, error)

DirSize returns the total size of all JSONL files in the directory

func Export

func Export(w io.Writer, session *Session, opts ExportOptions) error

Export exports a session in the specified format

func ExportRawByID

func ExportRawByID(dir, identifier string, w io.Writer) error

ExportRawByID exports raw JSONL by session ID or number

func ExportSessionByID

func ExportSessionByID(dir, identifier string, w io.Writer, opts ExportOptions) error

ExportSessionByID exports a session by ID or number

func FormatSession

func FormatSession(w io.Writer, session *Session, opts FormatOptions)

FormatSession formats a full session for display

func FormatSessionList

func FormatSessionList(w io.Writer, sessions []SessionSummary, days int)

FormatSessionList formats a list of sessions as a table

func FormatTailEntry

func FormatTailEntry(w io.Writer, line []byte)

FormatTailEntry formats a single entry for tail mode (compact)

func GetSessionFilePath

func GetSessionFilePath(dir, identifier string) (string, error)

GetSessionFilePath returns the file path for a session

func IsNoSessionsError

func IsNoSessionsError(err error) bool

IsNoSessionsError checks if an error is a NoSessionsError

func ParseRawLines

func ParseRawLines(filePath string) ([]json.RawMessage, error)

ParseRawLines parses a session file and returns raw JSON lines

func Tail

func Tail(ctx context.Context, filePath string, w io.Writer, opts TailOptions) error

Tail outputs entries from a session file, optionally following for new entries

func TailLatest

func TailLatest(ctx context.Context, dir string, w io.Writer, opts TailOptions) error

TailLatest tails the most recent session file

func WatchDir

func WatchDir(ctx context.Context, dir string) (string, error)

WatchDir watches the debug log directory for new sessions and returns when a new session file is created

Types

type Entry

type Entry struct {
	Timestamp time.Time
	SessionID string
	Type      string // "request" or "event"
	Raw       json.RawMessage
}

Entry is the base type for all log entries

type EventEntry

type EventEntry struct {
	Timestamp time.Time
	SessionID string
	EventType string
	Data      map[string]any
}

EventEntry represents a logged LLM event

type ExportFormat

type ExportFormat string

ExportFormat specifies the export format

const (
	FormatJSON     ExportFormat = "json"
	FormatMarkdown ExportFormat = "markdown"
	FormatRaw      ExportFormat = "raw"
)

type ExportOptions

type ExportOptions struct {
	Format ExportFormat
	Redact bool // Redact sensitive content (API keys, file contents, paths)
}

ExportOptions controls export behavior

type FormatOptions

type FormatOptions struct {
	ShowTools     bool // Highlight tool calls/results
	RequestsOnly  bool // Only show requests, not streaming events
	NoColor       bool // Disable colors
	ShowTimestamp bool // Show timestamp for each entry
}

FormatOptions controls how session output is formatted

type Message

type Message struct {
	Role    string `json:"role"`
	Content any    `json:"content"` // string or []Part
}

Message is a simplified message for logging

type NoSessionsError

type NoSessionsError struct{}

NoSessionsError indicates no sessions were found

func (*NoSessionsError) Error

func (e *NoSessionsError) Error() string

type Part

type Part struct {
	Type                          string      `json:"type"`
	Text                          string      `json:"text,omitempty"`
	ReasoningContent              string      `json:"reasoning_content,omitempty"`
	ReasoningItemID               string      `json:"reasoning_item_id,omitempty"`
	ReasoningEncryptedContentLen  int         `json:"reasoning_encrypted_content_len,omitempty"`
	ReasoningEncryptedContentHash string      `json:"reasoning_encrypted_content_hash,omitempty"`
	ToolCall                      *ToolCall   `json:"tool_call,omitempty"`
	ToolResult                    *ToolResult `json:"tool_result,omitempty"`
}

Part represents a message part

type RequestData

type RequestData struct {
	SessionID               string      `json:"session_id,omitempty"`
	Messages                []Message   `json:"messages"`
	Tools                   []Tool      `json:"tools,omitempty"`
	ToolChoice              *ToolChoice `json:"tool_choice,omitempty"`
	Search                  bool        `json:"search,omitempty"`
	ForceExternalSearch     bool        `json:"force_external_search,omitempty"`
	ParallelToolCalls       bool        `json:"parallel_tool_calls,omitempty"`
	MaxOutputTokens         int         `json:"max_output_tokens,omitempty"`
	Temperature             float32     `json:"temperature,omitempty"`
	TopP                    float32     `json:"top_p,omitempty"`
	ReasoningEffort         string      `json:"reasoning_effort,omitempty"`
	ReasoningReplayParts    int         `json:"reasoning_replay_parts,omitempty"`
	ReasoningEncryptedParts int         `json:"reasoning_encrypted_parts,omitempty"`
	MaxTurns                int         `json:"max_turns,omitempty"`
}

RequestData contains the request details

type RequestEntry

type RequestEntry struct {
	Timestamp time.Time
	SessionID string
	Provider  string
	Model     string
	Request   RequestData
}

RequestEntry represents a logged LLM request

type SearchOptions

type SearchOptions struct {
	Query      string // Text query to search for
	ToolName   string // Filter by tool name
	Provider   string // Filter by provider
	ErrorsOnly bool   // Only show sessions/entries with errors
	Days       int    // Only search sessions from last N days
}

SearchOptions controls search behavior

type SearchResult

type SearchResult struct {
	SessionID string
	FilePath  string
	LineNum   int
	Timestamp time.Time
	EntryType string // "request" or "event"
	EventType string // For events: "text_delta", "tool_call", etc.
	Match     string // The matching content
	Context   string // Additional context
}

SearchResult represents a search match

func Search(dir string, opts SearchOptions) ([]SearchResult, error)

Search searches across all sessions for matching entries

type Session

type Session struct {
	ID          string
	FilePath    string
	StartTime   time.Time
	EndTime     time.Time
	Provider    string
	Model       string
	Turns       int // Number of request/response cycles
	TotalTokens TokenUsage
	HasErrors   bool
	Command     string   // CLI command that started the session
	Args        []string // CLI arguments
	Cwd         string   // Working directory
	Entries     []any    // RequestEntry or EventEntry
}

Session represents a debug session with metadata

func ParseSession

func ParseSession(filePath string) (*Session, error)

ParseSession parses a full session file into a Session struct

type SessionSummary

type SessionSummary struct {
	ID        string
	FilePath  string
	StartTime time.Time
	Provider  string
	Model     string
	Calls     int // Number of LLM API calls
	Input     int // Input tokens
	Output    int // Output tokens
	Cached    int // Cached input tokens
	HasErrors bool
	FileSize  int64
}

SessionSummary is a lightweight session info for listing

func FilterSessions

func FilterSessions(sessions []SessionSummary, opts SearchOptions) []SessionSummary

FilterSessions filters sessions by various criteria

func GetMostRecentSession

func GetMostRecentSession(dir string) (*SessionSummary, error)

GetMostRecentSession returns the most recent session

func GetSessionByID

func GetSessionByID(dir, id string) (*SessionSummary, error)

GetSessionByID returns the session with the given ID

func GetSessionByNumber

func GetSessionByNumber(dir string, num int) (*SessionSummary, error)

GetSessionByNumber returns the session at the given 1-based index (1 = most recent)

func ListSessions

func ListSessions(dir string) ([]SessionSummary, error)

ListSessions returns summaries of all sessions in the debug log directory, sorted by start time (most recent first).

func ResolveSession

func ResolveSession(dir, identifier string) (*SessionSummary, error)

ResolveSession resolves a session identifier (number or ID) to a session summary

type TailOptions

type TailOptions struct {
	Follow bool // Keep watching for new entries
}

TailOptions controls tail behavior

type TokenUsage

type TokenUsage struct {
	Input  int
	Output int
	Cached int
}

TokenUsage tracks token consumption

type Tool

type Tool struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
}

Tool is a simplified tool spec for logging

type ToolCall

type ToolCall struct {
	ID        string          `json:"id"`
	Name      string          `json:"name"`
	Arguments json.RawMessage `json:"arguments"`
}

ToolCall is a simplified tool call for logging

type ToolChoice

type ToolChoice struct {
	Mode string `json:"mode"`
	Name string `json:"name,omitempty"`
}

ToolChoice represents tool choice settings

type ToolResult

type ToolResult struct {
	ID      string `json:"id"`
	Name    string `json:"name"`
	Content string `json:"content"`
	IsError bool   `json:"is_error,omitempty"`
}

ToolResult is a simplified tool result for logging

Jump to

Keyboard shortcuts

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