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 ¶
Decode decodes one transcript line; ok is false for a line that is empty, undecodable or a sidechain entry.
func IsUserTurn ¶
IsUserTurn reports whether a user entry is a genuine turn: not meta, not a tool result, with some text in it.
func ResultText ¶
ResultText returns the text of a tool_result block's content.
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"`
// Attachment is the payload of an "attachment" entry: a task notification
// that arrived DURING a turn is recorded there (type queued_command).
Attachment json.RawMessage `json:"attachment"`
}
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.