Skip to main content

Module text

Module text 

Source
Expand description

UTF-8-safe string truncation.

Rust’s &s[..n] panics when n lands inside a multi-byte character. Every truncation in this codebase is expressed as a byte budget (token estimates, tool-result caps, prompt budgets), and the content being truncated is routinely non-ASCII — skill descriptions, prompts, and conversation text in this repo are frequently Chinese, where one character is 3 bytes and a cut at an arbitrary byte offset lands mid-character with probability ~2/3.

Modules§

frontmatter
The frontmatter of a markdown file: the --- block at its head and the YAML scalars and lists a file’s reader pulls out of it.

Functions§

scrub_secrets
text with the credentials a log line could carry masked: sk-… style keys, the word after Bearer / Basic, and the value of any name=value whose name says token, key, secret, password or auth (URL query strings and --flag=value arguments included).
scrub_url
scrub_secrets, and the password of each URL’s userinfo (https://user:***@host).
truncate_at_char_boundary
Truncate s to at most max_bytes bytes, cutting at a character boundary.
truncate_chars
Truncate a string at max chars, appending marker when truncated.