Skip to content

refactor: extract core/workflow/ subdirectory#121

Merged
spinje merged 1 commit into
mainfrom
refactor/core-workflow-subdir
Mar 16, 2026
Merged

refactor: extract core/workflow/ subdirectory#121
spinje merged 1 commit into
mainfrom
refactor/core-workflow-subdir

Conversation

@spinje
Copy link
Copy Markdown
Owner

@spinje spinje commented Mar 16, 2026

Summary

Extract 6 workflow-related files from src/pflow/core/ into a new src/pflow/core/workflow/ subdirectory. Preparatory refactor for the planning module removal (Phase 1 places new files into core/workflow/).

Changes

File moves (via git mv, history preserved):

  • workflow_manager.pyworkflow/manager.py
  • workflow_validator.pyworkflow/validator.py
  • workflow_save_service.pyworkflow/save_service.py
  • workflow_data_flow.pyworkflow/data_flow.py
  • workflow_status.pyworkflow/status.py
  • skill_service.pyworkflow/skill_service.py

New files:

  • core/workflow/__init__.py — re-exports all public symbols (22 symbols from 6 modules)
  • core/workflow/CLAUDE.md — per-file details, internal dependencies, known issues, key lessons

Import updates:

  • 36 src/ files — import paths updated
  • 30 test files — import paths + 52 mock.patch() string targets updated
  • 8 CLAUDE.md files — stale references updated

Cleanup:

  • Removed dead re-exports from core/__init__.py (zero consumers for WorkflowValidator, CycleError, build_execution_order, validate_data_flow via that path)
  • Reorganized core/CLAUDE.md — workflow-specific content moved to workflow/CLAUDE.md, parent keeps cross-cutting concerns

Also included:

  • template_validation/CLAUDE.md — added Design Decisions section (two regex patterns, coalesce pre-splitting, type matrix, validation boundaries)
  • .claude/commands/refactor.md — lessons learned: sed for bulk replacements, relative import auditing, intermediate checkpoints, __init__.py transitive loading, CLAUDE.md content placement

Explanation

core/ had 20+ files and was becoming cluttered. The 6 workflow files form a cohesive group (they cross-reference each other, share the same domain). Extracting them into a subdirectory reduces noise for agents working on unrelated core files (settings, metrics, shell integration) and gives the workflow domain its own CLAUDE.md for detailed documentation.

This is the pre-task for the planning module removal — Phase 1 of that work places new discovery functions into core/workflow/, so the subdirectory needs to exist first.

Testing

make test   → 4128 passed, 485 skipped (exact baseline match)
make check  → ruff, mypy, deptry all clean

Zero regressions. Stale reference sweep confirms zero old-path references in any .py or .md file.

Move 6 workflow-related files from core/ into core/workflow/:
- workflow_manager.py → workflow/manager.py
- workflow_validator.py → workflow/validator.py
- workflow_save_service.py → workflow/save_service.py
- workflow_data_flow.py → workflow/data_flow.py
- workflow_status.py → workflow/status.py
- skill_service.py → workflow/skill_service.py

Create workflow/__init__.py with re-exports and workflow/CLAUDE.md.
Update all imports (36 src files, 30 test files), 52 mock.patch strings,
and 8 CLAUDE.md files. Remove dead re-exports from core/__init__.py.

Also: improve refactor command with lessons learned (sed over subagents
for bulk replacements, relative import auditing, intermediate checkpoints,
__init__.py transitive loading warning, CLAUDE.md content placement).

Also: add Design Decisions section to template_validation/CLAUDE.md.

4128 passed, 485 skipped — zero regressions.
@spinje
Copy link
Copy Markdown
Owner Author

spinje commented Mar 16, 2026

Context: Why this refactor is needed

This PR is the pre-task for a larger effort: removing the gated planning/ module and repair system from pflow.

The bigger picture

The planning module (~7,300 production lines, ~23,000 test lines) and repair system (~1,050 production lines) were gated by Task 107 (markdown format migration). All code is preserved but unreachable — 516 skipped tests, entry-point guards everywhere. The architecture docs call the planner "legacy" and "being phased out."

Rather than maintaining this dormant code, we're removing it cleanly in 3 phases:

Phase Scope
Pre-task (this PR) Extract core/workflow/ subdirectory
Phase 1 Relocate active dependencies out of planning/ — move build_workflows_context to core/workflow/context.py, replace WorkflowDiscoveryNode with core/workflow/discovery.py, move context builders to registry/
Phase 2 Delete planning/, repair, gated code paths, ~516 skipped tests

Why extract core/workflow/ first?

Phase 1 places new files into core/workflow/ (workflow context builder, workflow discovery function). The subdirectory needs to exist before that work begins.

Doing the extraction separately (Decision #8 in the master plan) keeps the blast radius contained — 74 files touched, 52 mock.patch strings updated — and independently testable. Mixing this mechanical refactor with the planning removal logic changes would make both harder to review and debug.

Full planning docs: scratchpads/planning-removal/00-master-plan.md

@spinje spinje merged commit 2a2409c into main Mar 16, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant