Skip to content

Refactor: extract common base for purple-agent adapters (CAR + entropic) #40

Description

@bordeauxred

Why

Two purple-agent server implementations duplicate substantial scaffolding:

  • `clawloop/environments/_car_purple.py` (344 lines)
  • `clawloop/environments/_entropic_purple.py` (378 lines)

Both files implement near-identical versions of:

  • `_convert_tools_to_openai()`
  • `_normalize_assistant_msg()`
  • session-state management
  • harness-update protocol

A skilled engineer reading both files will spot the copy-paste immediately. It's also a maintenance liability: a fix in one is unlikely to be ported to the other.

What

  • Create `clawloop/environments/_purple_base.py` containing `_PurpleAgentBase` with the shared methods.
  • Refactor `_car_purple.py` to inherit from `_PurpleAgentBase` and override only the CAR-specific scenario handling.
  • Refactor `_entropic_purple.py` to inherit and override only the CRM prompt parsing.
  • All existing tests pass with no behavioral change.

Acceptance

  • Total LOC across the three files reduced by ≥30%
  • `grep "_convert_tools_to_openai" clawloop/environments/` returns one definition
  • `pytest tests/environments/` green

Effort

~45 min. Bounded, low-risk, well-scoped — solid first-contribution issue.

Source

Code audit, 2026-04-18 (S1 finding).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGood for newcomersrefactorInternal restructuring, no behavior change

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions