parse

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 4 Imported by: 0

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

View Source
const (
	BlockCap   = 8000 // per-block char ceiling (recall > leanness for a rare dig)
	ToolInCap  = 500
	ToolResCap = 1000
)

Per-block / per-tool character ceilings.

View Source
const NoHumanMarker = "[tool-only match — use --include-tools to see it]"

NoHumanMarker is the placeholder shown for a tool-only match.

View Source
const TitleCap = 80

TitleCap is the rune ceiling for a derived session title.

Variables

View Source
var IndexableTypes = []string{"user", "assistant", "summary", "system"}

IndexableTypes is the set of transcript record types that get indexed.

Functions

func DeriveTitle

func DeriveTitle(records []map[string]any) (string, bool)

DeriveTitle derives a single-line session title from a session's records, in preference order:

  1. A record's own native title field (ai_title / summary / custom_title / title) — the first record (in iteration order) that carries one wins.
  2. 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

func Disp(content string, includeTools bool, cap int) string

Disp normalizes content for display: generated material optionally removed, whitespace collapsed, capped to `cap` runes.

func DispWith added in v0.9.0

func DispWith(content string, includeTools, includeThinking bool, cap int) string

DispWith normalizes content for display with granular inclusion of tools and thinking.

func ExtractText

func ExtractText(obj map[string]any) string

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

func ISOToEpoch(s string) float64

ISOToEpoch parses an ISO-8601 string to epoch seconds, treating tz-naive as UTC; returns 0.0 on empty/invalid.

func IsLowSignal

func IsLowSignal(text string) bool

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

func IsSubstantive(text string) bool

IsSubstantive is the negation of IsLowSignal: true when text is a real human turn worth using for a title or preview.

func MsgRole

func MsgRole(obj map[string]any) string

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

func MsgUUID(obj map[string]any) string

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

func RemoveThinkingRuns(text string) string

RemoveThinkingRuns deletes every [THINKING...] run up to the next marker boundary or end of string.

func StripEnvelopes added in v0.9.0

func StripEnvelopes(text string) string

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

func StripGenerated(text string) string

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

func StripThinking(text string) string

StripThinking removes [THINKING...] runs and collapses whitespace.

func StripTools

func StripTools(text string) string

StripTools removes [TOOL...]/[TOOL_RESULT...] runs and collapses whitespace.

Types

This section is empty.

Jump to

Keyboard shortcuts

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