transcript

package
v0.192.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: BSD-3-Clause Imports: 4 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 transcript reads a Claude Code session transcript (JSONL): the ONE parser the Stop and PreToolUse hooks of this repository share.

It was moved out of cmd/replystamp when a second gate (cmd/mergedcheck) needed the same three decisions, each of which had been a defect once:

  • a line that overruns bufio's default 64 KiB must not be dropped (the anchor would move), so Scan raises the limit;
  • a subagent's entries are written into the same file with isSidechain set, and are not this session's: Decode skips them;
  • most `type: "user"` entries are not turns (tool results, injected meta), and a usage-limit message (isApiErrorMessage) is not a reply: IsUserTurn and the Entry field carry both facts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(line []byte) (Entry, Message, bool)

Decode decodes one transcript line; ok is false for a line that is empty, undecodable or a sidechain entry.

func IsUserTurn

func IsUserTurn(e Entry, m Message) bool

IsUserTurn reports whether a user entry is a genuine turn: not meta, not a tool result, with some text in it.

func ResultText

func ResultText(b Block) string

ResultText returns the text of a tool_result block's content.

func Scan

func Scan(r io.Reader, fn func(e Entry, m Message)) error

Scan calls fn for each decodable, non-sidechain entry of a transcript.

Types

type Block

type Block struct {
	Type string `json:"type"`
	Text string `json:"text"`
	ID   string `json:"id"` // a tool_use block's id
	// A tool_use block names the tool and carries its input.
	Name  string          `json:"name"`
	Input json.RawMessage `json:"input"`
	// A tool_result block names the tool_use it answers; its content is a
	// string or a list of text blocks.
	ToolUseID string          `json:"tool_use_id"`
	Content   json.RawMessage `json:"content"`
	IsError   bool            `json:"is_error"`
}

Block is one element of a message's content: text, tool_use or tool_result.

func Blocks

func Blocks(raw json.RawMessage) []Block

Blocks decodes a message's content as blocks; a plain string content is one text block.

type Entry

type Entry struct {
	Type    string          `json:"type"`
	IsMeta  bool            `json:"isMeta"`
	UUID    string          `json:"uuid"`
	Message json.RawMessage `json:"message"`
	// ⛔⛔ A USAGE-LIMIT MESSAGE IS NOT A REPLY, AND IT IS THE MOST COMMON LAST
	// TEXT IN A TRANSCRIPT. Measured over the 50 transcripts on this machine:
	// 14 of them end on `You've hit your 5-hour limit · resets 8:50pm`, text
	// the model never wrote, recorded as an ordinary assistant text entry.
	//
	// The entry says so itself: isApiErrorMessage, beside apiError
	// ("usage_limit_reached") and apiErrorStatus (429). A FIELD, not a text
	// pattern: matching on the words would break when the message is reworded
	// and would refuse a real reply that quoted it.
	IsAPIErrorMessage bool `json:"isApiErrorMessage"`
	// A subagent's entries are written into the same transcript with this set.
	IsSidechain bool `json:"isSidechain"`
	// Timestamp is when the entry was recorded, RFC 3339.
	Timestamp string `json:"timestamp"`
	// What opened a turn: the resume after a compaction, or a background task
	// finishing.
	IsCompactSummary bool   `json:"isCompactSummary"`
	TurnOrigin       string `json:"turnOrigin"`
	PromptSource     string `json:"promptSource"`
}

Entry is one transcript line.

type Message

type Message struct {
	Role    string          `json:"role"`
	Content json.RawMessage `json:"content"`
}

Message is an entry's message.

Jump to

Keyboard shortcuts

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