msgfmt

package
v0.0.100 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package msgfmt formats an ordered chat transcript (oldest → newest) into a plain-text block suitable for injecting into an agent prompt.

Pure and SeaTalk-unaware: no I/O, env, cwd, or process globals.

Index

Constants

View Source
const DefaultMaxPerMessageRunes = 1000

DefaultMaxPerMessageRunes is the default per-message body rune cap when Options.MaxPerMessageRunes is 0 or negative.

Variables

This section is empty.

Functions

func Format

func Format(msgs []Message, opts Options) string

Format returns the formatted chat-history block (same as FormatDetailed.Text).

Types

type Message

type Message struct {
	ID     string
	Sender string
	Text   string
}

Message is one chat message in oldest → newest order.

type Options

type Options struct {
	// MaxPerMessageRunes caps each message body. 0 or negative → DefaultMaxPerMessageRunes.
	MaxPerMessageRunes int
	// MaxMessages, when >0, keeps the latest N messages. 0 means no count cap.
	MaxMessages int
	// TotalBudgetRunes, when >0, is a rune budget on the full formatted block.
	// 0 means no total budget. Oldest messages are dropped first; the last
	// message is always kept even if the block still exceeds the budget.
	TotalBudgetRunes int
}

Options controls selection and size caps. Zero fields select package defaults: body cap DefaultMaxPerMessageRunes, no MaxMessages count cap, no total budget.

type Result

type Result struct {
	Text            string
	Shown           int
	SourceCount     int
	OldestDropped   int    // SourceCount - Shown
	BodiesTruncated int    // messages whose body was shortened (among shown)
	LastMessageID   string // newest input message ID ("" if none / empty id)
}

Result is a structured view of what FormatDetailed produced.

func FormatDetailed

func FormatDetailed(msgs []Message, opts Options) Result

FormatDetailed formats msgs under opts and returns text plus selection metadata.

Pipeline: (1) MaxMessages keeps latest N → (2) per-body rune cap → (3) TotalBudgetRunes drops oldest from the full formatted block.

Jump to

Keyboard shortcuts

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