Skip to content

[Refactoring] Split containers/api-proxy/anthropic-transforms.js into focused transform modules #3467

@github-actions

Description

@github-actions

Refactoring Opportunity

Summary

  • File: containers/api-proxy/anthropic-transforms.js
  • Current size: 474 lines
  • Responsibilities identified: 4 distinct concerns in a single module

Evidence

The file bundles four unrelated transform features under one module:

Concern Functions Lines
ANSI stripping stripAnsi, applyAnsiStrip 40–135 (~95 lines)
Cache breakpoint injection withCacheControl, injectCacheBreakpoints 53–264 (~75 lines)
Ephemeral TTL upgrading upgradeEphemeralTtl 265–343 (~78 lines)
Tool scrubbing buildToolScrubPattern, applyToolDrop 68–190 (~122 lines)
Transform composition loadCustomTransform, makeAnthropicTransform 344–459 (~115 lines)

The ANSI stripping concern is entirely orthogonal to cache management and tool dropping — these are three independent data-transformation pipelines that happen to be assembled by makeAnthropicTransform. The 78-line upgradeEphemeralTtl function alone has an outer: label and nested loop with 5+ levels of indentation, making it hard to review in context.

Proposed Split

containers/api-proxy/anthropic-transforms.js → 3 focused modules:

  • containers/api-proxy/transforms/ansi-strip.jsstripAnsi, applyAnsiStrip (~50 lines; reusable across providers)
  • containers/api-proxy/transforms/cache-control.jswithCacheControl, injectCacheBreakpoints, upgradeEphemeralTtl (~160 lines; cache-specific logic)
  • containers/api-proxy/transforms/tool-drop.jsbuildToolScrubPattern, applyToolDrop (~80 lines)
  • containers/api-proxy/anthropic-transforms.jsloadCustomTransform, makeAnthropicTransform composition only (~80 lines; imports from sub-modules)

Affected Callers

containers/api-proxy/providers/anthropic.js:23:
  ({ makeAnthropicTransform, loadCustomTransform, EXTENDED_CACHE_BETA } =
    require('../anthropic-transforms'));
containers/api-proxy/anthropic-transforms.test.js:26:
  } = require('./anthropic-transforms');

No public API change required — makeAnthropicTransform, loadCustomTransform, and EXTENDED_CACHE_BETA continue to be exported from anthropic-transforms.js. Sub-module internals are not re-exported.

Effort Estimate

Low

Benefits

  • ANSI stripping is a generic utility that could be reused by other providers (e.g., OpenAI); extracting it enables reuse
  • Cache control logic is independently testable without constructing a full transform pipeline
  • upgradeEphemeralTtl's complex nested loop is easier to review in isolation
  • Reduces cognitive load when reviewing Anthropic-specific proxy behavior

Detected by Refactoring Scanner workflow. Run date: 2026-05-20

Note

🔒 Integrity filter blocked 2 items

The following items were blocked because they don't meet the GitHub integrity level.

  • #135 search_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".
  • #1376 search_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".

To allow these resources, lower min-integrity in your GitHub frontmatter:

tools:
  github:
    min-integrity: approved  # merged | approved | unapproved | none

Generated by Refactoring Opportunity Scanner · ● 13.1M ·

  • expires on Jul 19, 2026, 4:12 PM UTC

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions