Raw view: Refactor Within Explicit Constraints
No invisible, zero-width, or bidi-control characters detected.
Refactor the {{LANGUAGE}} code below toward a single goal, under hard constraints. Constraints win over goal: a refactor that improves the goal but breaks a constraint is a failed refactor.
<code>
{{CODE}}
</code>
<goal>
{{GOAL}}
</goal>
<must_not_change>
{{MUST_NOT_CHANGE}}
</must_not_change>
<may_change>
{{MAY_CHANGE}}
</may_change>
Tests run with `{{TEST_COMMAND}}`. Assume they exist and pass today; your refactor must leave them passing without edits unless <may_change> says tests may change.
Approach:
1. Before editing, list every externally observable thing about <code>: exported names and signatures, return types, thrown errors, side-effect order, log lines, and performance characteristics a caller could depend on. Anything in that list not covered by <may_change> is frozen.
2. Pick the smallest sequence of transformations that reaches <goal>. Prefer rename, extract, inline, and move over rewrite. Each step should be independently correct, so a reviewer could stop at any step and still have working code.
3. Keep scope tight. Only change what <goal> requires or what is clearly necessary to keep the code consistent after the change. A refactor is not a license to add type annotations, comments, defensive checks, or abstractions to code you did not otherwise touch.
4. After the refactor, walk the frozen list from step 1 again and confirm each item is unchanged. Where you cannot confirm from the code alone (for example, timing), say so.
5. If <goal> cannot be reached without violating <must_not_change>, stop and explain the conflict instead of partially complying.
## Output format
**Frozen surface** - bullet list from step 1, each item marked `[kept]`, `[changed: allowed by may_change]`, or `[cannot verify]`.
**Refactored code** - one fenced code block with the complete result. Do not use `...` or "rest unchanged"; a reviewer must be able to paste it over the original.
**Steps taken** - numbered list, one transformation per line, in the order applied: `Extracted parse_header() from handle_request() lines 14-31`.
**Behavior risk** - 1-3 bullets on where behavior could have shifted and how you ruled it out, or "None identified" with a sentence on why.
**Conflicts** - only if step 5 triggered: what in <goal> collides with <must_not_change> and the two or three options for resolving it.