sessiontitle

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Title normalization matches session-title/normalize: remove escapes, control and directional characters, normalize whitespace, and truncate to a UTF-8 byte budget without splitting characters.

Package sessiontitle generates session titles (S08), matching storage/session-title. Session events and FoldSessionTitle already provide latest-wins title projection. This package generates titles from the first user message: Fallback takes a 30-rune prefix by default, while an optional LLMAdapter generates a concise title. Missing or failed LLM generation falls back to the prefix. Rune-based truncation preserves UTF-8 characters. Generate returns both Title and Source (llm/fallback).

Index

Constants

This section is empty.

Variables

View Source
var FallbackSystemPrompt = "" /* 166-byte string literal not displayed */

FallbackSystemPrompt asks the model for a concise single-sentence title.

Functions

func CleanTitle

func CleanTitle(input string) string

CleanTitle removes escape/control characters and collapses whitespace to one line.

func Fallback

func Fallback(firstUserMessage string) string

Fallback uses the first user-message prefix, up to 30 runes by default. Empty input returns empty; callers decide whether to emit session/title.

func FallbackMax

func FallbackMax(firstUserMessage string, maxRunes int) string

FallbackMax generates a prefix title with the supplied rune limit.

func Normalize

func Normalize(input string, maxBytes int) string

Normalize cleans a title and truncates it to a byte budget.

func TrimTitle

func TrimTitle(s string) string

TrimTitle removes surrounding quotes, periods, and similar LLM output decoration.

func TruncateUTF8

func TruncateUTF8(input string, maxBytes int) string

TruncateUTF8 returns the longest complete-rune prefix within a UTF-8 byte budget.

Types

type Generator

type Generator struct {
	// LLM optionally summarizes the first user message; nil always uses fallback.
	LLM llm.LLMAdapter
	// Model selects the title model; empty uses the adapter default.
	Model string
	// MaxRunes limits fallback titles; nonpositive values use 30.
	MaxRunes int
	// System optionally overrides the built-in title-generation prompt.
	System string
	// MaxTokens limits tokens for one LLM title request.
	MaxTokens int
}

Generator creates session titles using an optional LLM helper.

func (*Generator) Generate

func (g *Generator) Generate(ctx context.Context, firstUserMessage string) Result

Generate prefers the LLM helper, falling back to a prefix when unavailable or failed.

type Result

type Result struct {
	Title  string `json:"title"`
	Source Source `json:"source"`
}

Result contains a generated title and its source.

type Source

type Source string

Source identifies how a title was generated.

const (
	SourceLLM      Source = "llm"      // Generated by the LLM helper.
	SourceFallback Source = "fallback" // Generated by truncating a prefix.
)

Title sources.

Jump to

Keyboard shortcuts

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