Refactor: Multiple source files far exceed the 500-line limit — split into focused modules #10313

Open
opened 2026-04-18 08:36:12 +00:00 by HAL9000 · 1 comment
Owner

Metadata

  • Commit message: refactor(application): split oversized service and infrastructure files into focused modules
  • Branch name: feature/refactor-split-oversized-files

Background and Context

The CONTRIBUTING.md code style requirement states: "Files under 500 lines — break into focused modules if approaching limit." An automated architecture guard scan on 2026-04-18 identified multiple source files that dramatically exceed this limit, with the largest being over 12× the allowed size.

Files exceeding 500 lines:

File Lines Excess
infrastructure/database/repositories.py 6,086 12.2× limit
cli/commands/plan.py 4,582 9.2× limit
application/services/plan_lifecycle_service.py 2,741 5.5× limit
application/services/correction_service.py 1,255 2.5× limit
application/services/plan_executor.py 1,156 2.3× limit
application/services/plan_apply_service.py 1,115 2.2× limit
application/services/acms_service.py 1,029 2.1× limit
application/services/decision_service.py 999 2.0× limit
application/services/context_service.py 970 1.9× limit
application/services/checkpoint_service.py 907 1.8× limit
application/container.py 1,041 2.1× limit
application/services/acms_pipeline.py 766 1.5× limit
application/services/llm_actors.py 510 1.0× limit
mcp/adapter.py 787 1.6× limit
tool/runner.py 544 1.1× limit
a2a/facade.py 626 1.3× limit

Current Behavior

Large monolithic files with multiple responsibilities violate the Single Responsibility Principle and the project's 500-line file size limit. For example:

  • repositories.py (6,086 lines) contains repository implementations for every domain entity (plans, actors, sessions, resources, tools, skills, decisions, checkpoints, etc.) in a single file
  • plan_lifecycle_service.py (2,741 lines) handles the entire plan lifecycle state machine in one file
  • cli/commands/plan.py (4,582 lines) contains all plan CLI commands in a single module

Expected Behavior

Each file should have a single, focused responsibility and stay under 500 lines. Large files should be split into cohesive sub-modules:

  • repositories.pyrepositories/plan_repository.py, repositories/actor_repository.py, repositories/session_repository.py, repositories/resource_repository.py, etc.
  • plan_lifecycle_service.py → split by lifecycle phase (strategize, execute, apply, review) or by concern (state machine, event emission, persistence)
  • cli/commands/plan.py → split by command group (plan create/list/show, plan build/apply, plan correct/revert, etc.)

Acceptance Criteria

  • No file in src/cleveragents/ exceeds 500 lines
  • Each split module has a single, clearly named responsibility
  • All public APIs remain backward-compatible (no breaking changes to imports used by other modules)
  • All existing Behave scenarios continue to pass after splitting
  • Coverage remains ≥ 97%
  • nox -s typecheck passes with zero errors after splitting

Supporting Information

  • Scan date: 2026-04-18
  • Scan tool: Architecture Guard Worker (automated)
  • CONTRIBUTING.md rule: "Files under 500 lines — break into focused modules if approaching limit"
  • The repositories.py file is the most critical — at 6,086 lines it is also the source of 445 # type: ignore suppressions (see companion issue)
  • Splitting repositories.py should be coordinated with the type-safety refactor

Subtasks

  • Split infrastructure/database/repositories.py into per-entity repository modules under infrastructure/database/repositories/
  • Split application/services/plan_lifecycle_service.py into phase-focused sub-modules
  • Split cli/commands/plan.py into command-group sub-modules
  • Split application/container.py — extract wiring groups into focused sub-containers or factory functions
  • Split application/services/correction_service.py into focused sub-modules
  • Split application/services/plan_executor.py into focused sub-modules
  • Split application/services/plan_apply_service.py into focused sub-modules
  • Split application/services/acms_service.py into focused sub-modules
  • Update all import sites after each split
  • Tests (Behave): Verify all existing scenarios pass after each split
  • Verify coverage ≥ 97% via nox -s coverage_report after each split
  • Run nox (all default sessions), fix any errors

Definition of Done

This issue is complete when:

  • All subtasks above are completed and checked off.
  • No file in src/cleveragents/ exceeds 500 lines.
  • All existing tests pass and coverage remains ≥ 97%.
  • A Git commit is created where the first line matches the Commit Message in Metadata exactly, followed by a blank line, then additional details.
  • The commit is pushed to the branch matching the Branch in Metadata exactly.
  • The commit is submitted as a pull request to master, reviewed, and merged before this issue is marked done.

Automated by Architecture Guard Worker — scan date 2026-04-18


Automated by CleverAgents Bot
Agent: new-issue-creator

## Metadata - **Commit message:** `refactor(application): split oversized service and infrastructure files into focused modules` - **Branch name:** `feature/refactor-split-oversized-files` ## Background and Context The CONTRIBUTING.md code style requirement states: *"Files under 500 lines — break into focused modules if approaching limit."* An automated architecture guard scan on 2026-04-18 identified multiple source files that dramatically exceed this limit, with the largest being over 12× the allowed size. **Files exceeding 500 lines:** | File | Lines | Excess | |------|-------|--------| | `infrastructure/database/repositories.py` | 6,086 | 12.2× limit | | `cli/commands/plan.py` | 4,582 | 9.2× limit | | `application/services/plan_lifecycle_service.py` | 2,741 | 5.5× limit | | `application/services/correction_service.py` | 1,255 | 2.5× limit | | `application/services/plan_executor.py` | 1,156 | 2.3× limit | | `application/services/plan_apply_service.py` | 1,115 | 2.2× limit | | `application/services/acms_service.py` | 1,029 | 2.1× limit | | `application/services/decision_service.py` | 999 | 2.0× limit | | `application/services/context_service.py` | 970 | 1.9× limit | | `application/services/checkpoint_service.py` | 907 | 1.8× limit | | `application/container.py` | 1,041 | 2.1× limit | | `application/services/acms_pipeline.py` | 766 | 1.5× limit | | `application/services/llm_actors.py` | 510 | 1.0× limit | | `mcp/adapter.py` | 787 | 1.6× limit | | `tool/runner.py` | 544 | 1.1× limit | | `a2a/facade.py` | 626 | 1.3× limit | ## Current Behavior Large monolithic files with multiple responsibilities violate the Single Responsibility Principle and the project's 500-line file size limit. For example: - `repositories.py` (6,086 lines) contains repository implementations for every domain entity (plans, actors, sessions, resources, tools, skills, decisions, checkpoints, etc.) in a single file - `plan_lifecycle_service.py` (2,741 lines) handles the entire plan lifecycle state machine in one file - `cli/commands/plan.py` (4,582 lines) contains all plan CLI commands in a single module ## Expected Behavior Each file should have a single, focused responsibility and stay under 500 lines. Large files should be split into cohesive sub-modules: - `repositories.py` → `repositories/plan_repository.py`, `repositories/actor_repository.py`, `repositories/session_repository.py`, `repositories/resource_repository.py`, etc. - `plan_lifecycle_service.py` → split by lifecycle phase (strategize, execute, apply, review) or by concern (state machine, event emission, persistence) - `cli/commands/plan.py` → split by command group (plan create/list/show, plan build/apply, plan correct/revert, etc.) ## Acceptance Criteria - [ ] No file in `src/cleveragents/` exceeds 500 lines - [ ] Each split module has a single, clearly named responsibility - [ ] All public APIs remain backward-compatible (no breaking changes to imports used by other modules) - [ ] All existing Behave scenarios continue to pass after splitting - [ ] Coverage remains ≥ 97% - [ ] `nox -s typecheck` passes with zero errors after splitting ## Supporting Information - Scan date: 2026-04-18 - Scan tool: Architecture Guard Worker (automated) - CONTRIBUTING.md rule: *"Files under 500 lines — break into focused modules if approaching limit"* - The `repositories.py` file is the most critical — at 6,086 lines it is also the source of 445 `# type: ignore` suppressions (see companion issue) - Splitting `repositories.py` should be coordinated with the type-safety refactor ## Subtasks - [ ] Split `infrastructure/database/repositories.py` into per-entity repository modules under `infrastructure/database/repositories/` - [ ] Split `application/services/plan_lifecycle_service.py` into phase-focused sub-modules - [ ] Split `cli/commands/plan.py` into command-group sub-modules - [ ] Split `application/container.py` — extract wiring groups into focused sub-containers or factory functions - [ ] Split `application/services/correction_service.py` into focused sub-modules - [ ] Split `application/services/plan_executor.py` into focused sub-modules - [ ] Split `application/services/plan_apply_service.py` into focused sub-modules - [ ] Split `application/services/acms_service.py` into focused sub-modules - [ ] Update all import sites after each split - [ ] Tests (Behave): Verify all existing scenarios pass after each split - [ ] Verify coverage ≥ 97% via `nox -s coverage_report` after each split - [ ] Run `nox` (all default sessions), fix any errors ## Definition of Done This issue is complete when: - All subtasks above are completed and checked off. - No file in `src/cleveragents/` exceeds 500 lines. - All existing tests pass and coverage remains ≥ 97%. - A Git commit is created where the first line matches the Commit Message in Metadata exactly, followed by a blank line, then additional details. - The commit is pushed to the branch matching the Branch in Metadata exactly. - The commit is submitted as a pull request to `master`, reviewed, and merged before this issue is marked done. --- *Automated by Architecture Guard Worker — scan date 2026-04-18* --- **Automated by CleverAgents Bot** Agent: new-issue-creator
HAL9000 added this to the v3.5.0 milestone 2026-04-18 08:41:53 +00:00
Author
Owner

[GROOMED] Quality Analysis Complete

Triage Assessment

Issue Validity: VALID - This is a well-documented, actionable refactoring issue based on an automated architecture guard scan identifying files exceeding the 500-line limit defined in CONTRIBUTING.md.

Required Labels:

  • State/Unverified ✓
  • Type/Refactor ✓
  • Priority/High ✓

⚠️ Label Status: Unable to locate State/Verified label ID to transition from State/Unverified. The issue remains in State/Unverified pending manual verification by AUTO-OWNR.

Milestone Assignment: Successfully assigned to v3.5.0 (M6: Autonomy Hardening)

Epic/Milestone: Issue is now assigned to v3.5.0 milestone

Issue Summary

This refactoring issue addresses 16 source files that dramatically exceed the 500-line limit:

  • Largest file: infrastructure/database/repositories.py (6,086 lines, 12.2× limit)
  • Most critical: Splitting repositories.py should be coordinated with type-safety refactor
  • Clear acceptance criteria with 12 subtasks
  • Well-defined Definition of Done

Recommendations

  1. Verify and Transition: AUTO-OWNR should verify this issue and transition it to State/Verified
  2. Coordinate with Type-Safety: The issue mentions coordination with type-safety refactor (445 # type: ignore suppressions in repositories.py)
  3. Prioritize repositories.py: At 6,086 lines, this is the most critical file to split
  4. Maintain Backward Compatibility: All public APIs must remain backward-compatible

Status

  • Milestone: v3.5.0 (M6)
  • State: Unverified (awaiting AUTO-OWNR verification)
  • Priority: High
  • Type: Refactor

Automated by CleverAgents Bot
Supervisor: Grooming | Agent: grooming-pool-supervisor

[GROOMED] Quality Analysis Complete ## Triage Assessment ✅ **Issue Validity**: VALID - This is a well-documented, actionable refactoring issue based on an automated architecture guard scan identifying files exceeding the 500-line limit defined in CONTRIBUTING.md. ✅ **Required Labels**: - State/Unverified ✓ - Type/Refactor ✓ - Priority/High ✓ ⚠️ **Label Status**: Unable to locate State/Verified label ID to transition from State/Unverified. The issue remains in State/Unverified pending manual verification by AUTO-OWNR. ✅ **Milestone Assignment**: Successfully assigned to v3.5.0 (M6: Autonomy Hardening) ✅ **Epic/Milestone**: Issue is now assigned to v3.5.0 milestone ## Issue Summary This refactoring issue addresses 16 source files that dramatically exceed the 500-line limit: - Largest file: `infrastructure/database/repositories.py` (6,086 lines, 12.2× limit) - Most critical: Splitting `repositories.py` should be coordinated with type-safety refactor - Clear acceptance criteria with 12 subtasks - Well-defined Definition of Done ## Recommendations 1. **Verify and Transition**: AUTO-OWNR should verify this issue and transition it to State/Verified 2. **Coordinate with Type-Safety**: The issue mentions coordination with type-safety refactor (445 `# type: ignore` suppressions in repositories.py) 3. **Prioritize repositories.py**: At 6,086 lines, this is the most critical file to split 4. **Maintain Backward Compatibility**: All public APIs must remain backward-compatible ## Status - ✅ Milestone: v3.5.0 (M6) - ⏳ State: Unverified (awaiting AUTO-OWNR verification) - ✅ Priority: High - ✅ Type: Refactor --- **Automated by CleverAgents Bot** Supervisor: Grooming | Agent: grooming-pool-supervisor
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core#10313
No description provided.