parse

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package parse turns raw transcript lines and snapshots into typed events, leniently and without I/O.

Index

Constants

View Source
const MaxText = 64 << 10

MaxText caps Event.Text in bytes.

Variables

View Source
var ErrBadLine = errors.New("parse: line is not valid JSON")

ErrBadLine is returned for input that is not valid JSON.

Functions

func Summarize

func Summarize(tool string, input map[string]any) (summary, idents string)

Summarize returns the <=200-rune input summary and the idents string of a tool call. Only the whitelisted fields are ever read, never content/old_string/new_string/text/prompt.

Types

type AgentMeta

type AgentMeta struct {
	AgentType, Description, ToolUseID, ParentAgentID string
	SpawnDepth                                       int
	Finished                                         *bool
}

AgentMeta is the content of an agent-*.meta.json snapshot.

type Event

type Event struct {
	Kind                                    Kind
	TS                                      time.Time // zero if the line has none
	CWD, Branch                             string
	Sidechain                               bool
	Text                                    string // capped at MaxText, cut on a rune boundary
	AI                                      bool
	Model                                   string
	Usage                                   *Usage
	ToolUseID, Tool, Summary, Skill, Idents string
	IsError                                 bool
	Background                              bool // KindToolUse: run_in_background; KindToolResult: status async_launched. Either way the result is only a launch ack
	DurationMs, AgentTotalMs                *int64
	Failure                                 *Failure
	Meta                                    *AgentMeta
	// Agent time (spec 02 section 4), set on KindTouch events only.
	TurnStart  bool   // a user line that is neither a tool_result nor isMeta
	Work       bool   // an assistant line or a user line carrying a tool_result
	WorkAsst   bool   // Work, and an assistant line
	ReportedMs *int64 // Work: the duration the tool result reports (durationMs, else totalDurationMs)
}

Event is one typed fact extracted from a line or snapshot; which fields are set depends on Kind.

func ParseLine

func ParseLine(raw []byte) ([]Event, error)

ParseLine returns the events of one raw line, in document order (Touch first).

func ParseSnapshot

func ParseSnapshot(fi FileInfo, content []byte) ([]Event, error)

ParseSnapshot handles FileAgentMeta and FileCustomTitle snapshots; other kinds yield nil.

type Failure

type Failure struct {
	Category, Detail, LimitType string
	ResetsAt                    time.Time // zero if none
}

Failure is a classified API, refusal or tool failure.

type FileInfo

type FileInfo struct {
	Kind               FileKind
	SessionID, AgentID string
}

FileInfo is the result of ClassifyPath.

func ClassifyPath

func ClassifyPath(rel string) FileInfo

ClassifyPath classifies a path relative to the projects root.

type FileKind

type FileKind uint8

FileKind is the kind of a transcript-tree file.

const (
	FileOther FileKind = iota
	FileMain
	FileSubagent
	FileAgentMeta
	FileCustomTitle
)

File kinds understood by ClassifyPath.

type Kind

type Kind uint8

Kind is the type of a parsed Event.

const (
	KindTouch Kind = iota + 1
	KindPrompt
	KindAssistant
	KindToolUse
	KindToolResult
	KindTurn
	KindTitle
	KindTaskNote
	KindFailure
	KindAgentMeta
	KindCustomTitle
)

Event kinds.

type Usage

type Usage struct {
	ID, Model, Speed                                               string
	Input, Output, CacheRead, CacheWrite5m, CacheWrite1h, Thinking int64
	WebSearch, WebFetch                                            int64
}

Usage is the token usage of one assistant message.

Jump to

Keyboard shortcuts

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