Documentation
¶
Overview ¶
Package fence renders UNTRUSTED TEXT as a fenced block an agent is handed as a turn: a preface line written by muster, then an opening marker at column 0 carrying a fresh nonce, the content lines, and a closing marker — with EVERY line between the markers behind ContentPrefix.
🔴 THE PREFIX IS WHAT MAKES THE FENCE STRUCTURAL. No content text can reach column 0, where the markers live, so no text can close the block early or open a forged one; the marker word and the block's own nonce are additionally replaced inside the fence (MarkerPlaceholder, NoncePlaceholder), so a line cannot even QUOTE the real closing marker.
🔴 Sanitize IS THE CALLER'S JOB, PER FIELD, BEFORE A LINE IS BUILT. A field holding a line break would start a line with no content prefix; Sanitize folds every line break into " ⏎ " and replaces every control, format, separator and unassigned code point, so no output of it can. The block itself does not sanitise lines a second time: a caller-composed line (a standing sentence, a stanza header) is muster's own text.
This package was extracted from internal/memorelay. A byte golden of the memo relay's rendered turn checked the move changed no byte; it was deleted once the extraction landed, so internal/memorelay's own tests are what pin its shape now. internal/plugins renders inbound plugin messages through it as well.
Index ¶
Constants ¶
const ( // ContentPrefix begins every line between the markers. ContentPrefix = "| " // MarkerPlaceholder replaces the block's marker word wherever a content line // carries it (any case). MarkerPlaceholder = "[fence-marker]" // NoncePlaceholder replaces the block's nonce wherever a content line carries // it (any case). NoncePlaceholder = "[nonce]" )
const MaxURLBytes = 2048
MaxURLBytes bounds a URL WebURL keeps.
Variables ¶
This section is empty.
Functions ¶
func NewNonce ¶
func NewNonce() string
NewNonce is a fresh 16-hex-character nonce, drawn per render, so text that guesses an earlier block's nonce still sits behind the content prefix of this one.
func Sanitize ¶
Sanitize is the replacement every untrusted field passes through before it is written into a turn: each Unsafe code point becomes U+FFFD, except a line break (" ⏎ ", CRLF folded first) and a tab (one space). Invalid UTF-8 decodes to U+FFFD per invalid byte. Sanitising already-sanitised text is a no-op.
🔴 IT IS ALSO WHAT KEEPS A FIELD ON ONE LINE AND OUT OF A RUNTIME'S REFUSAL. A line break inside a field would start a line with no content prefix, and the claude-code runtime refuses a prompt holding any control character other than newline and tab (a 400, nothing pasted). No output of this function holds either.
func Unsafe ¶
Unsafe reports whether Sanitize must replace r: every code point in General Category C* (Cc, Cf, Co, Cs, Cn), plus Zl, Zp, the variation selectors and the other default-ignorable code points (invisible letters and marks). "In none of L, M, N, P, S, Z" is exactly C*, unassigned code points included.
func WebURL ¶ added in v0.224.0
WebURL is u when it is a URL an outside source may hand muster to SHOW AS TEXT: an absolute http or https URL with a host and no userinfo, at most MaxURLBytes bytes of UTF-8 with no space and no Unsafe code point; "" otherwise. It says nothing about where the URL leads: nothing muster draws from it is a link.
Types ¶
type Block ¶
type Block struct {
// Preface is the one line OUTSIDE the fence, muster's own words: what the
// turn is and that it asks for nothing. It is written verbatim.
Preface string
Marker string
// Count is the number of items the block carries, stated in the opening
// marker.
Count int
// Lines are the content lines, each written behind ContentPrefix. An empty
// string is a blank content line (the prefix alone).
Lines []string
}
Block is one fenced turn. Marker is the word the opening and closing markers carry (e.g. "cairn-memo"); it should be a plain lower-case word, since it is matched case-insensitively inside the content.