Documentation
¶
Index ¶
- func CleanBetaMessages(messages []anthropic.BetaMessageParam) []anthropic.BetaMessageParam
- func CleanBetaSystemMessages(blocks []anthropic.BetaTextBlockParam) []anthropic.BetaTextBlockParam
- func CleanMessages(messages []anthropic.MessageParam) []anthropic.MessageParam
- func CleanSystemMessages(blocks []anthropic.TextBlockParam) []anthropic.TextBlockParam
- func NormalizeSteganographyText(text string) string
- func StripClaudeCodeSystemPreamble(text string) string
- type CleanHeaderTransform
- type MCPToolInjectionTransform
- type MCPToolStripGuardTransform
- type MaxTokensDefaultTransform
- type NativeWebSearchStripTransform
- type OutputLimitTransform
- type ThinkingCompactTransform
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CleanBetaMessages ¶
func CleanBetaMessages(messages []anthropic.BetaMessageParam) []anthropic.BetaMessageParam
CleanBetaMessages normalizes steganographic markers in text content blocks within <system-reminder> tags in user messages (beta API).
func CleanBetaSystemMessages ¶
func CleanBetaSystemMessages(blocks []anthropic.BetaTextBlockParam) []anthropic.BetaTextBlockParam
CleanBetaSystemMessages removes billing header messages from beta system blocks and normalizes steganographic markers in surviving blocks.
func CleanMessages ¶
func CleanMessages(messages []anthropic.MessageParam) []anthropic.MessageParam
CleanMessages normalizes steganographic markers in text content blocks within <system-reminder> tags in user messages. Anthropic's steganographic date string lives inside a <system-reminder> block in the first user message's content; we scope to user role and system-reminder tag to avoid modifying user-authored or assistant message text.
func CleanSystemMessages ¶
func CleanSystemMessages(blocks []anthropic.TextBlockParam) []anthropic.TextBlockParam
CleanSystemMessages removes billing header messages from system blocks and normalizes steganographic markers in surviving blocks. This is used for Claude Code scenario to filter out injected billing headers.
func NormalizeSteganographyText ¶
NormalizeSteganographyText removes Anthropic's steganographic markers embedded in system prompt text that silently encode user geolocation.
Background: Claude Code's bundled binary contains a function that, when it detects the user is in China (via timezone Asia/Shanghai or Asia/Urumqi), modifies the system prompt date string in two ways before sending the request:
- Apostrophe substitution — the apostrophe in "Today's" (U+0027) is replaced with a homoglyphic Unicode character (U+2019 RIGHT SINGLE QUOTATION MARK, U+02BC MODIFIER LETTER APOSTROPHE, or U+2018 LEFT SINGLE QUOTATION MARK). The three variants encode 1-2 bits.
- Date separator substitution — "2026-06-30" becomes "2026/06/30" by replacing hyphens with slashes when the local timezone is Asia/Shanghai or Asia/Urumqi. This encodes 1 bit.
Together these form a 2-3 bit steganographic tag that Anthropic's server reads from the prompt itself — no network headers needed.
This function neutralizes both markers at the text level so that:
- "Today's" (with any look-alike apostrophe) is normalized to "Today's".
- Any date in YYYY/MM/DD format is normalized back to YYYY-MM-DD.
Types ¶
type CleanHeaderTransform ¶
type CleanHeaderTransform struct{}
CleanHeaderTransform cleans system messages and message content by:
- Stripping injected billing header blocks (x-anthropic-billing-header).
- Normalizing steganographic markers embedded by Claude Code to encode user geolocation (look-alike Unicode apostrophes and date separators), both in the system field and inside <system-reminder> blocks in the first message of the messages array.
- For Anthropic-to-Codex Responses conversion only, stripping Claude Code identity/capability preambles that otherwise pollute Codex instructions.
Used by Claude Code scenarios to ensure system text is clean before forwarding to third-party providers. Only added to the chain when CleanHeader flag is true.
func NewCleanHeaderTransform ¶
func NewCleanHeaderTransform() *CleanHeaderTransform
NewCleanHeaderTransform creates a CleanHeaderTransform.
func (*CleanHeaderTransform) Apply ¶
func (t *CleanHeaderTransform) Apply(ctx *protocoltransform.TransformContext) error
func (*CleanHeaderTransform) Name ¶
func (t *CleanHeaderTransform) Name() string
type MCPToolInjectionTransform ¶
type MCPToolInjectionTransform struct {
// contains filtered or unexported fields
}
MCPToolInjectionTransform injects Tingly Box's enabled Server Tools into requests.
func NewMCPToolInjectionTransform ¶
func NewMCPToolInjectionTransform(rt *runtime.Runtime) *MCPToolInjectionTransform
func (*MCPToolInjectionTransform) Apply ¶
func (t *MCPToolInjectionTransform) Apply(ctx *protocoltransform.TransformContext) error
func (*MCPToolInjectionTransform) Name ¶
func (t *MCPToolInjectionTransform) Name() string
type MCPToolStripGuardTransform ¶
type MCPToolStripGuardTransform struct {
// contains filtered or unexported fields
}
MCPToolStripGuardTransform strips disabled MCP tool declarations/tool calls when enabled.
func NewMCPToolStripGuardTransform ¶
func NewMCPToolStripGuardTransform(rt *runtime.Runtime, stripEnabled bool) *MCPToolStripGuardTransform
func (*MCPToolStripGuardTransform) Apply ¶
func (t *MCPToolStripGuardTransform) Apply(ctx *protocoltransform.TransformContext) error
func (*MCPToolStripGuardTransform) Name ¶
func (t *MCPToolStripGuardTransform) Name() string
type MaxTokensDefaultTransform ¶
type MaxTokensDefaultTransform struct {
DefaultMaxTokens int
}
MaxTokensDefaultTransform fills max_tokens on an Anthropic request that arrived without one. max_tokens is required by the Anthropic protocol, so this normalizes the client's own request: it runs in the source half of the chain and leaves every other shape alone (see .design/protocol-stage-pipeline.md).
func NewMaxTokensDefaultTransform ¶
func NewMaxTokensDefaultTransform(defaultMaxTokens int) *MaxTokensDefaultTransform
NewMaxTokensDefaultTransform creates a MaxTokensDefaultTransform.
func (*MaxTokensDefaultTransform) Apply ¶
func (t *MaxTokensDefaultTransform) Apply(ctx *protocoltransform.TransformContext) error
func (*MaxTokensDefaultTransform) Name ¶
func (t *MaxTokensDefaultTransform) Name() string
type NativeWebSearchStripTransform ¶
type NativeWebSearchStripTransform struct {
// contains filtered or unexported fields
}
NativeWebSearchStripTransform removes native web_search / web_fetch tool definitions from upstream requests when tingly-box's own MCP equivalents are enabled and ready.
This prevents the LLM from selecting Anthropic's built-in web tools (which require a Claude Code subscription) when our MCP-backed versions are available via Serper/Jina.
func NewNativeWebSearchStripTransform ¶
func NewNativeWebSearchStripTransform(rt *runtime.Runtime) *NativeWebSearchStripTransform
func (*NativeWebSearchStripTransform) Apply ¶
func (t *NativeWebSearchStripTransform) Apply(ctx *protocoltransform.TransformContext) error
func (*NativeWebSearchStripTransform) Name ¶
func (t *NativeWebSearchStripTransform) Name() string
type OutputLimitTransform ¶
type OutputLimitTransform struct {
MaxAllowed int
}
OutputLimitTransform bounds the upstream-bound request by the model's output-token limit on the provider. It runs in the target half of the chain, so it sees the provider's own shape and each rule applies only where that shape has the field:
- Every shape: cap the output-token field(s) at MaxAllowed.
- Anthropic: a thinking budget over MaxAllowed shrinks to max(MaxAllowed/10, 1024), and a budget that reaches max_tokens is capped to max_tokens-1 (Anthropic requires 1024 <= budget_tokens < max_tokens; max_tokens is the hard operator limit, so the budget yields, and thinking is turned off when max_tokens leaves no room for it).
OpenAI Chat / Responses have no budget: an Anthropic client's budget was already tiered onto reasoning_effort by the conversion, so it is never shrunk to fit a limit it does not travel under (#1897).
MaxAllowed <= 0 disables the transform.
func NewOutputLimitTransform ¶
func NewOutputLimitTransform(maxAllowed int) *OutputLimitTransform
NewOutputLimitTransform creates an OutputLimitTransform.
func (*OutputLimitTransform) Apply ¶
func (t *OutputLimitTransform) Apply(ctx *protocoltransform.TransformContext) error
func (*OutputLimitTransform) Name ¶
func (t *OutputLimitTransform) Name() string
type ThinkingCompactTransform ¶
type ThinkingCompactTransform struct {
// contains filtered or unexported fields
}
ThinkingCompactTransform removes thinking blocks from assistant messages in historical conversation rounds, preserving the last keepLastNRounds rounds. This is what the SmartCompact scenario flag actually does: a thinking trim, not a general conversation compression.
It is a server-domain transform: the flag path in internal/server prepends it to the transform chain when a scenario enables SmartCompact. The vmodel-oriented compression strategies (round-only, round-files, replay, dedup, ...) live in internal/smart_compact — this transform intentionally does not.
func NewThinkingCompactTransform ¶
func NewThinkingCompactTransform(keepLastNRounds int) *ThinkingCompactTransform
NewThinkingCompactTransform creates a ThinkingCompactTransform.
keepLastNRounds controls how many recent conversation rounds keep their thinking blocks. Higher values retain more reasoning context but save fewer tokens:
- 1: preserves only the current request's thinking (safe baseline)
- 2-3: suitable for multi-step reasoning, debugging, or document analysis
Values below 1 are clamped to 1 — the current round's thinking is always preserved.
func (*ThinkingCompactTransform) Apply ¶
func (t *ThinkingCompactTransform) Apply(ctx *protocoltransform.TransformContext) error
Apply applies the compaction to the request.
func (*ThinkingCompactTransform) Name ¶
func (t *ThinkingCompactTransform) Name() string
Name returns the transform identifier (kept as "compact_thinking" for continuity with recorded TransformSteps and probe output).