Help us shape the future of Go! Take the 2026 Go Developer Survey

transcript

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package transcript provides shared types and utilities for parsing JSONL transcripts. Used by agents that share the same JSONL format (Claude Code, Cursor).

Index

Constants

View Source
const (
	TypeUser      = "user"
	TypeAssistant = "assistant"
)

Message type constants for transcript lines.

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

Content type constants for content blocks within messages.

Variables

This section is empty.

Functions

func ExtractUserContent

func ExtractUserContent(message json.RawMessage) string

ExtractUserContent extracts user content from a raw message. Handles both string and array content formats. IDE-injected context tags (like <ide_opened_file>) are stripped from the result. Returns empty string if the message cannot be parsed or contains no text.

func SliceFromLine

func SliceFromLine(content []byte, startLine int) []byte

SliceFromLine returns the content starting from line number `startLine` (0-indexed). This is used to extract only the checkpoint-specific portion of a cumulative transcript. For example, if startLine is 2, lines 0 and 1 are skipped and the result starts at line 2. Returns empty slice if startLine exceeds the number of lines.

Types

type AssistantMessage

type AssistantMessage struct {
	Content []ContentBlock `json:"content"`
}

AssistantMessage represents an assistant message in the transcript.

type ContentBlock

type ContentBlock struct {
	Type  string          `json:"type"`
	Text  string          `json:"text,omitempty"`
	Name  string          `json:"name,omitempty"`
	Input json.RawMessage `json:"input,omitempty"`
}

ContentBlock represents a block within an assistant message.

type Line

type Line struct {
	Type    string          `json:"type"`
	Role    string          `json:"role,omitempty"`
	UUID    string          `json:"uuid"`
	Message json.RawMessage `json:"message"`
}

Line represents a single line in a Claude Code or Cursor JSONL transcript. Claude Code uses "type" to distinguish user/assistant messages. Cursor uses "role" for the same purpose.

func ParseFromBytes

func ParseFromBytes(content []byte) ([]Line, error)

ParseFromBytes parses transcript content from a byte slice. Uses bufio.Reader to handle arbitrarily long lines.

func ParseFromFileAtLine

func ParseFromFileAtLine(path string, startLine int) ([]Line, error)

ParseFromFileAtLine reads and parses a transcript file starting from a specific line. Uses bufio.Reader to handle arbitrarily long lines (no size limit). Transparently handles gzip-compressed transcripts (tries path.gz if path doesn't exist). Returns:

  • lines: parsed transcript lines from startLine onwards (malformed lines skipped)
  • error: any error encountered during reading

The startLine parameter is 0-indexed (startLine=0 reads from the beginning). This is useful for incremental parsing when you've already processed some lines.

type ToolInput

type ToolInput struct {
	FilePath     string `json:"file_path,omitempty"`
	NotebookPath string `json:"notebook_path,omitempty"`
	Description  string `json:"description,omitempty"`
	Command      string `json:"command,omitempty"`
	Pattern      string `json:"pattern,omitempty"`
	// Skill tool fields
	Skill string `json:"skill,omitempty"`
	// WebFetch tool fields
	URL    string `json:"url,omitempty"`
	Prompt string `json:"prompt,omitempty"`
}

ToolInput represents the input to various tools. Used to extract file paths and descriptions from tool calls.

type UserMessage

type UserMessage struct {
	Content interface{} `json:"content"`
}

UserMessage represents a user message in the transcript.

Directories

Path Synopsis
Package compact converts full.jsonl transcripts into a normalized, compact transcript.jsonl format.
Package compact converts full.jsonl transcripts into a normalized, compact transcript.jsonl format.

Jump to

Keyboard shortcuts

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