Skip to content

Refactor: extract commands/install.py helpers into apm_cli/install/ package #839

@sergio-sisternes-epam

Description

@sergio-sisternes-epam

Context

src/apm_cli/commands/install.py is at ~1700 LOC and is guarded by an architecture-invariant test (tests/unit/install/test_architecture_invariants.py::test_install_py_under_legacy_budget) with a legacy budget of 1680 LOC.

PR #803 (Codex project-scoped MCP, fixes #502) needs to thread scope context (project_root, user_scope, explicit_target) through install orchestration, which pushes the file to 1701 LOC and trips the invariant. Rather than block the Codex PR on a large refactor, we're raising the budget in-line there and tracking the extraction here.

Why this matters

The invariant test message says it explicitly:

Do NOT trim cosmetically -- engage the python-architecture skill (.github/skills/python-architecture/SKILL.md) and propose an extraction into apm_cli/install/.

install.py is a well-known God-module candidate. Every cross-cutting change (scope, targets, MCP, hooks, lockfile) adds pressure on it, and silent budget bumps would defeat the guard.

Proposed direction

Extract cohesive helpers into a new apm_cli/install/ package, keeping commands/install.py as the thin CLI entrypoint. Likely candidates:

  • Scope/target resolution helpers (project_root, user_scope, explicit_target plumbing).
  • MCP integration orchestration (dep collection, conflict detection, stale cleanup glue).
  • Dependency/runtime detection and filtering.
  • Post-install reporting / diagnostics assembly.

Engage the python-architecture skill before cutting module boundaries -- the goal is cohesion by responsibility, not file-size juggling.

Acceptance

  • commands/install.py back under a tight budget (target: 1200 LOC or lower).
  • New apm_cli/install/ package with clear module boundaries and its own tests.
  • Architecture invariant updated to guard the new structure (not just the legacy LOC ceiling).
  • No behaviour change for end users -- public CLI surface and flags unchanged.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions