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 textwith the credentials a log line could carry masked:sk-…style keys, the word afterBearer/Basic, and the value of anyname=valuewhose name says token, key, secret, password or auth (URL query strings and--flag=valuearguments included).- scrub_
url scrub_secrets, and the password of each URL’s userinfo (https://user:***@host).- truncate_
at_ char_ boundary - Truncate
sto at mostmax_bytesbytes, cutting at a character boundary. - truncate_
chars - Truncate a string at
maxchars, appendingmarkerwhen truncated.