format

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package format transforms session data into formatted journal Markdown with frontmatter and turn headers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Duration

func Duration(d interface{ Minutes() float64 }) string

Duration formats a duration in a human-readable way.

Parameters:

  • d: Duration with Minutes() method

Returns:

  • string: Human-readable duration (e.g., "<1m", "5m", "1h30m")

func ExtractSystemReminders

func ExtractSystemReminders(content string) (string, []string)

ExtractSystemReminders separates system-reminder content from tool output.

Claude Code injects <system-reminder> tags into tool results. This function extracts them so they can be rendered as Markdown outside code fences.

Parameters:

  • content: Tool result content potentially containing system-reminder tags

Returns:

  • string: Content with system-reminder tags removed
  • []string: Extracted reminder texts (may be empty)

func FenceForContent

func FenceForContent(content string) string

FenceForContent returns the appropriate code fence for content.

Uses longer fences when content contains backticks to avoid nested Markdown rendering issues. Starts with ``` and adds more backticks as needed.

Parameters:

  • content: The content to be fenced

Returns:

  • string: A fence string (e.g., "```", "````", "```"")

func JournalEntryPart

func JournalEntryPart(
	s *entity.Session,
	messages []entity.Message,
	startMsgIdx, part, totalParts int,
	baseName, title string,
) string

JournalEntryPart generates Markdown content for a part of a journal entry.

Includes metadata, tool usage summary (on part 1 only), navigation links, and the conversation subset for this part.

Parameters:

  • s: Session to format
  • messages: Subset of messages for this part
  • startMsgIdx: Starting message index (for numbering)
  • part: Current part number (1-indexed)
  • totalParts: Total number of parts
  • baseName: Base filename without extension (for navigation links)
  • title: Human-readable title for frontmatter and H1 heading (may be empty)

Returns:

  • string: Markdown content for this part

func JournalFilename

func JournalFilename(s *entity.Session, slugOverride string) string

JournalFilename generates the filename for a journal entry.

Format: YYYY-MM-DD-slug-shortid.md Uses local time for the date.

When slugOverride is non-empty it replaces s.Slug in the filename, allowing title-derived slugs to be used instead of Claude Code's random slug.

Parameters:

  • s: Session to generate filename for
  • slugOverride: If non-empty, used instead of s.Slug

Returns:

  • string: Filename like "2026-01-15-fix-auth-bug-abc12345.md"

func NormalizeCodeFences

func NormalizeCodeFences(content string) string

NormalizeCodeFences ensures code fences are on their own lines with proper spacing.

Users often type "text: ```code" without proper line breaks. Markdown requires code fences to be on their own lines with blank lines separating them from surrounding content.

Parameters:

  • content: Text that may contain inline code fences

Returns:

  • string: Content with code fences properly separated by blank lines

func PartNavigation

func PartNavigation(part, totalParts int, baseName string) string

PartNavigation generates previous/next navigation links for multipart sessions.

Parameters:

  • part: Current part number (1-indexed)
  • totalParts: Total number of parts
  • baseName: Base filename without extension

Returns:

  • string: Formatted navigation line (e.g., "**Part 2 of 3** | [← Previous](...) | [Next →](...)")

func SessionMatchLines

func SessionMatchLines(matches []*entity.Session) []string

SessionMatchLines formats session matches for ambiguous query output.

Parameters:

  • matches: sessions that matched the query.

Returns:

  • []string: pre-formatted lines, one per match.

func StripLineNumbers

func StripLineNumbers(content string) string

StripLineNumbers removes Claude Code's line number prefixes from content.

Parameters:

  • content: Text potentially containing " 1→" style prefixes

Returns:

  • string: Content with line number prefixes removed

func Tokens

func Tokens(tokens int) string

Tokens formats token counts in a human-readable way.

Parameters:

  • tokens: Token count to format

Returns:

  • string: Human-readable count (e.g., "500", "1.5K", "2.3M")

func ToolUse

func ToolUse(t entity.ToolUse) string

ToolUse formats a tool invocation with its key parameters.

Parameters:

  • t: Tool use to format

Returns:

  • string: Formatted string like "Read: /path/to/file" or just tool name

func Truncate

func Truncate(s string, max int) string

Truncate shortens s to max characters, appending "…" if truncated.

Parameters:

  • s: String to truncate
  • max: Maximum length

Returns:

  • string: Truncated string

Types

This section is empty.

Jump to

Keyboard shortcuts

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