Documentation
¶
Overview ¶
Package parse holds text-extraction and parse primitives — flattening one transcript JSON record into a searchable string, tool-stripping, role lookup, ISO-timestamp parsing, and display formatting.
Index ¶
- Constants
- Variables
- func DeriveTitle(records []map[string]any) (string, bool)
- func Disp(content string, includeTools bool, cap int) string
- func DispWith(content string, includeTools, includeThinking bool, cap int) string
- func ExtractText(obj map[string]any) string
- func ISOToEpoch(s string) float64
- func IsLowSignal(text string) bool
- func IsSubstantive(text string) bool
- func MsgRole(obj map[string]any) string
- func MsgUUID(obj map[string]any) string
- func RemoveThinkingRuns(text string) string
- func StripEnvelopes(text string) string
- func StripGenerated(text string) string
- func StripThinking(text string) string
- func StripTools(text string) string
Constants ¶
const ( BlockCap = 8000 // per-block char ceiling (recall > leanness for a rare dig) ToolInCap = 500 ToolResCap = 1000 )
Per-block / per-tool character ceilings.
const NoHumanMarker = "[tool-only match — use --include-tools to see it]"
NoHumanMarker is the placeholder shown for a tool-only match.
const TitleCap = 80
TitleCap is the rune ceiling for a derived session title.
Variables ¶
var IndexableTypes = []string{"user", "assistant", "summary", "system"}
IndexableTypes is the set of transcript record types that get indexed.
Functions ¶
func DeriveTitle ¶
DeriveTitle derives a single-line session title from a session's records, in preference order:
- A record's own native title field (ai_title / summary / custom_title / title) — the first record (in iteration order) that carries one wins.
- The first user message whose flattened text IsSubstantive.
It returns (title, true) when either path yields a non-empty title, else ("", false). The title is collapsed to one line, trimmed, and capped to ~TitleCap runes. records are decoded JSONL maps in transcript order.
func Disp ¶
Disp normalizes content for display: generated material optionally removed, whitespace collapsed, capped to `cap` runes.
func DispWith ¶ added in v0.9.0
DispWith normalizes content for display with granular inclusion of tools and thinking.
func ExtractText ¶
ExtractText flattens one decoded transcript record into a searchable string. Includes text, thinking, system, summary, and marker-tagged tool_use / tool_result so they are matchable. `obj` is a decoded JSON object.
func ISOToEpoch ¶
ISOToEpoch parses an ISO-8601 string to epoch seconds, treating tz-naive as UTC; returns 0.0 on empty/invalid.
func IsLowSignal ¶
IsLowSignal reports whether text is a low-signal message: one that should be skipped for previews and title derivation. Low-signal = empty/whitespace, a bare greeting/warmup token, a bare slash-command, a command-envelope markup line (<command-name>/<command-message>/<local-command-*>), or a pure tool/JSON/XML opener ('{', '[', '<'). The session is NEVER dropped on this predicate — only the individual message is filtered.
func IsSubstantive ¶
IsSubstantive is the negation of IsLowSignal: true when text is a real human turn worth using for a title or preview.
func MsgRole ¶
MsgRole returns the role for a decoded record: message.role when present and non-empty, otherwise the record type. An empty/missing role falls through to type; an empty string is the result when neither yields a non-empty value.
func MsgUUID ¶
MsgUUID returns the stable per-message identifier for a decoded record: the top-level "uuid" string when present and non-empty, else "leafUuid" (which "summary" records carry instead of their own uuid), else "". This id is Claude Code's own per-message handle — it survives reindex and append, so it anchors the external read-ref. A record with no uuid is still indexed and searchable; it is simply not returned as a primary read anchor.
func RemoveThinkingRuns ¶ added in v0.9.0
RemoveThinkingRuns deletes every [THINKING...] run up to the next marker boundary or end of string.
func StripEnvelopes ¶ added in v0.9.0
StripEnvelopes removes every injected-envelope run (see envelopeTags) from text. A run ends at its closing tag; an unclosed run — the shape a truncated or streamed record leaves behind — runs to the end of the text, since these wrappers are whole-message in practice.
Nothing is deleted from the index: this is a DISPLAY-and-RANKING predicate. The record stays stored and stays readable by ref, and --include-tools puts it back in the haystack. Keeping everything and showing what answers the question are separate dials.
func StripGenerated ¶ added in v0.9.0
StripGenerated removes everything a runtime generated into a record — tool runs and injected envelopes both — leaving only what a person or a model actually wrote. This is the haystack the default search matches against, so a record consisting ONLY of generated material has nothing left to match and drops out of results by the same rule that already excluded tool-only hits.
func StripThinking ¶ added in v0.9.0
StripThinking removes [THINKING...] runs and collapses whitespace.
func StripTools ¶
StripTools removes [TOOL...]/[TOOL_RESULT...] runs and collapses whitespace.
Types ¶
This section is empty.