transcript

package
v0.11.4 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: MIT Imports: 8 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"`
	ID    string          `json:"id,omitempty"`
	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 added in v0.4.5

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). 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.

func ParseFromFileAtLineWithTotal added in v0.10.3

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

ParseFromFileAtLineWithTotal is ParseFromFileAtLine plus the file's total line count, gathered in the same pass.

Callers implementing agent.TranscriptAnalyzer.ExtractModifiedFilesFromOffset need both halves at once: the slice from startLine, and the new position to record for the next call. Reading the file twice (parse, then count) is the thing to avoid — these run on hook paths where transcripts reach tens of megabytes.

The total counts every non-empty line in the file, including lines before startLine and lines too malformed to unmarshal, so it stays a faithful position marker for a subsequent startLine.

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"`
	// Task/Agent tool fields: the dispatched subagent's name.
	SubagentType string `json:"subagent_type,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.
Package geminilegacy reads Gemini CLI transcripts stored in checkpoints written before Gemini CLI support was removed.
Package geminilegacy reads Gemini CLI transcripts stored in checkpoints written before Gemini CLI support was removed.
Package imageextract externalizes inline base64 images from an agent's session transcript into a checkpoint asset store, replacing each with a compact, path-bearing placeholder, and re-injects them byte-exactly on restore.
Package imageextract externalizes inline base64 images from an agent's session transcript into a checkpoint asset store, replacing each with a compact, path-bearing placeholder, and re-injects them byte-exactly on restore.

Jump to

Keyboard shortcuts

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