transform

package
v0.260806.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 6, 2026 License: MPL-2.0 Imports: 14 Imported by: 0

Documentation

Index

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

func NormalizeSteganographyText(text string) string

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:

  1. 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.
  2. 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.

func StripClaudeCodeSystemPreamble

func StripClaudeCodeSystemPreamble(text string) string

Types

type CleanHeaderTransform

type CleanHeaderTransform struct{}

CleanHeaderTransform cleans system messages and message content by:

  1. Stripping injected billing header blocks (x-anthropic-billing-header).
  2. 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.
  3. 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 (*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 (*MCPToolInjectionTransform) Name

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 (*MCPToolStripGuardTransform) Name

type MaxTokensTransform

type MaxTokensTransform struct {
	DefaultMaxTokens int
	MaxAllowed       int
}

MaxTokensTransform ensures max_tokens is set and properly bounded for Anthropic requests.

It applies three rules:

  1. Fill defaultMaxTokens when the client sends 0.
  2. Cap max_tokens at maxAllowed.
  3. 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 (*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 (*NativeWebSearchStripTransform) Name

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

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).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL