Expand description
Strips the formatting a model wraps around its whole reply. Whether what is
left is usable is the reply format’s question (reply), then the purpose’s own
check (validate).
Constants§
- CONVERSATIONAL_
PREAMBLES 🔒 - Conversational-filler openers a model reaches for despite being told to respond with a bare, direct instruction — e.g. “Yeah, let’s fix the bug” instead of “Fix the bug”. Matched case-insensitively against the very start of the string only (a “let’s” appearing mid-sentence is left alone — this strips openers, not arbitrary word choice). Longer/more specific entries first so e.g. “let’s go ahead and “ matches whole rather than the shorter “let’s “ eating only part of it.
Functions§
- case_
insensitive_ 🔒prefix_ byte_ len - Byte length in
sof a prefix that case-insensitively matchesprefix(always plain ASCII lowercase), orNoneifsdoesn’t start with it. Walkss’s own char boundaries rather than slicing by an offset computed against a separately-lowercased copy ofs— a char’s lowercase mapping can change UTF-8 byte length (e.g. the Kelvin sign ‘K’ -> ‘k’) or even character count (e.g. Turkish ‘İ’ -> “i̇”), which would otherwise misalign the offset or land it off a char boundary and panic on slice. - sanitize_
ambient_ text - Removes, repeatedly, then trims: a code fence wrapping the whole text (optionally with a language tag), one matching pair of quotes wrapping it, and a conversational opener (“Yeah, let’s…”). A reply left with nothing but backticks (an empty fence) becomes “”, which callers already treat as no reply.
- strip_
conversational_ 🔒preamble - Strip one leading conversational-filler opener (see
CONVERSATIONAL_PREAMBLES) and re-capitalize the new first letter, so “Yeah, let’s debug the bug” becomes “Debug the bug” — matching the direct-instruction register every ambient-call prompt asks for. ReturnsNoneif no known opener matches (left alone rather than guessed at — this list is deliberately not exhaustive NLP-style filler detection, just the handful of openers a model actually reaches for here). - strip_
wrapping_ 🔒fence - Strip a wrapping code fence (triple-backtick, optionally with a language tag on the opening line, or a single inline backtick) if the entire string is wrapped — a fence-like substring embedded mid-sentence is left alone. Returns the un-fenced inner text, trimmed.
- strip_
wrapping_ 🔒quotes - Strip ONE pair of quotes that wraps the whole string. A quote at only one end,
or a pair that closes before the end (
"a" and "b"), is part of the text.