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 ¶
const ( TypeUser = "user" TypeAssistant = "assistant" )
Message type constants for transcript lines.
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 ¶
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 ¶
ParseFromBytes parses transcript content from a byte slice. Uses bufio.Reader to handle arbitrarily long lines.
func ParseFromFileAtLine ¶ added in v0.4.5
ParseFromFileAtLine reads and parses a transcript file starting from a specific line. Uses bufio.Reader to handle arbitrarily long lines (no size limit). 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.