transform

package
v1.261105.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MPL-2.0 Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func (*MCPToolInjectionTransform) WithConnectedTools added in v1.261026.0

func (t *MCPToolInjectionTransform) WithConnectedTools(on func() bool) *MCPToolInjectionTransform

WithConnectedTools makes injection of connected MCP tools conditional.

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 MaxTokensDefaultTransform added in v1.261001.1

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 added in v1.261001.1

func NewMaxTokensDefaultTransform(defaultMaxTokens int) *MaxTokensDefaultTransform

NewMaxTokensDefaultTransform creates a MaxTokensDefaultTransform.

func (*MaxTokensDefaultTransform) Apply added in v1.261001.1

func (*MaxTokensDefaultTransform) Name added in v1.261001.1

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 OutputLimitTransform added in v1.261001.1

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 added in v1.261001.1

func NewOutputLimitTransform(maxAllowed int) *OutputLimitTransform

NewOutputLimitTransform creates an OutputLimitTransform.

func (*OutputLimitTransform) Apply added in v1.261001.1

func (*OutputLimitTransform) Name added in v1.261001.1

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

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