Documentation
¶
Overview ¶
Package textutil holds small string helpers shared across packages.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Clip ¶
Clip truncates s to at most max bytes without splitting a multibyte UTF-8 rune, returning the (possibly shorter) string and whether it was truncated. Backing off to a rune boundary avoids feeding the model — and the JSONL trace — a broken trailing rune (the byte-cap-halves-Cyrillic bug class).
func OneLine ¶ added in v0.17.0
OneLine collapses all runs of whitespace (incl. newlines) to single spaces and rune-safely clips the result to at most max bytes — the shared "flatten to one tidy line, capped" helper used across the packages for log/error rendering.
func Tail ¶ added in v0.23.0
Tail keeps the last max bytes of s, backing off to a rune boundary so a multibyte character is never split; a clipped result is prefixed with "…". The counterpart of Clip for when the END of the text is the valuable part (e.g. a CLI agent's final answer after pages of progress noise).
Types ¶
type BoundedTailWriter ¶ added in v0.41.7
type BoundedTailWriter struct {
Truncated bool
// contains filtered or unexported fields
}
BoundedTailWriter is an io.Writer that keeps only the most recent max bytes written to it — the tail counterpart of BoundedWriter — without ever holding more than a small bounded multiple of max bytes at once, so tailing a runaway command's output doesn't require buffering all of it first. Truncated reports whether any bytes were ever dropped.
func NewBoundedTailWriter ¶ added in v0.41.7
func NewBoundedTailWriter(max int) *BoundedTailWriter
NewBoundedTailWriter returns a BoundedTailWriter that retains at most the last max bytes written.
func (*BoundedTailWriter) String ¶ added in v0.41.7
func (w *BoundedTailWriter) String() string
String returns the retained tail, backed off to a UTF-8 rune boundary at the start since a dropped prefix can land mid-rune.
type BoundedWriter ¶ added in v0.41.7
type BoundedWriter struct {
Truncated bool
// contains filtered or unexported fields
}
BoundedWriter is an io.Writer that keeps only the first max bytes ever written to it, discarding the rest instead of buffering it — so wiring a subprocess's stdout/stderr to one caps this process's memory use at max regardless of how much output a runaway command produces. Truncated reports whether any bytes were dropped. Write always reports success (returns len(p), nil) since dropping the tail is by design, not an error.
func NewBoundedWriter ¶ added in v0.41.7
func NewBoundedWriter(max int) *BoundedWriter
NewBoundedWriter returns a BoundedWriter that retains at most max bytes.
func (*BoundedWriter) String ¶ added in v0.41.7
func (w *BoundedWriter) String() string
String returns the retained bytes.