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 MaxTokensTransform
- type NativeWebSearchStripTransform
- 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 enabled server-side MCP 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 MaxTokensTransform ¶
MaxTokensTransform ensures max_tokens is set and properly bounded for Anthropic requests.
It applies three rules:
- Fill defaultMaxTokens when the client sends 0.
- Cap max_tokens at maxAllowed.
- If the thinking budget exceeds maxAllowed, shrink it to max(maxAllowed/10, 1024).
func NewMaxTokensTransform ¶
func NewMaxTokensTransform(defaultMaxTokens, maxAllowed int) *MaxTokensTransform
NewMaxTokensTransform creates a MaxTokensTransform.
func (*MaxTokensTransform) Apply ¶
func (t *MaxTokensTransform) Apply(ctx *protocoltransform.TransformContext) error
func (*MaxTokensTransform) Name ¶
func (t *MaxTokensTransform) 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 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).