Skip to content

[Architecture] Promote patch-contract strictness/budgets to a surface-neutral owner #44

Description

@orenlab

[Architecture] Promote patch-contract strictness/budgets to a surface-neutral owner

Labels: enhancement, architecture, mcp, cli, change-control
Priority: P2 (architecture triage)
Subject: codeclone/surfaces/mcp/_patch_contract.py
Signal: ownership_drift
Triage run: e28867ed (health 91/A)

Summary

Reusable patch strictness and budget semantics (PatchBudgets, budgets_for_strictness) live in a private MCP module while the CLI surface imports that private owner directly.

Environment

  • Product/Service: CodeClone
  • Version: 2.1.0a1 (run e28867ed)
  • Area: Structural Change Controller / patch verification

Current State

  1. codeclone/surfaces/mcp/_patch_contract.py defines StrictnessProfile, PatchBudgets, PatchContractStatus, budgets_for_strictness, detect_baseline_abuse.
  2. CLI import (cross-surface private dependency):
    # codeclone/surfaces/cli/patch_verify.py
    from ..mcp._patch_contract import (
        VALID_STRICTNESS_PROFILES,
        StrictnessProfile,
        budgets_for_strictness,
    )
  3. MCP consumers: _session_patch_contract_mixin.py, _session_workflow_mixin.py.
  4. AGENTS.md documents shared patch-budget helpers under codeclone/budget/*, but budget/ currently covers token estimation only.
  5. Impact blast: medium (reaches main.py and CLI workflow transitively).
  6. Precedent: tests/test_architecture.py forbids non-MCP surfaces from importing codeclone.surfaces.mcp._blast_radius — no equivalent guard for _patch_contract.

Expected Behavior

CLI and MCP are sibling surfaces; shared controller contracts (strictness profiles, patch budgets, baseline-abuse rules) live in a surface-neutral module (e.g. extend codeclone/budget or add codeclone/controller/patch_contract.py). Both surfaces import the same owner.

Actual Behavior

CLI --patch-verify depends on MCP-private _patch_contract internals. Contract changes risk breaking CLI without a documented public boundary.

Impact

Medium — Functional today, but wrong dependency direction for a public controller contract shared by CLI and MCP. Increases risk of CLI/MCP strictness drift.

Proposed Direction

  • Extract PatchBudgets, strictness profiles, and baseline-abuse helpers to a non-surfaces.mcp module.
  • Update CLI patch_verify.py and MCP mixins to import the shared owner.
  • Add architecture test mirroring the _blast_radius import ban for _patch_contract from non-MCP packages (or eliminate the need by promoting the contract).
  • Keep token payload estimation in codeclone/budget/estimator.py separate from gate/budget semantics.

Additional Context

  • Architecture triage score: B → 25 (P2).
  • Tests: tests/test_cli_patch_verify.py, tests/test_mcp_service.py (test_mcp_patch_contract_profiles_and_baseline_abuse).

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions