feat: add --plan for guided refactoring workflow#53
Conversation
Groups 56 rules into 9 ordered phases with dependency chains, auto-selects strategy (local_first vs architecture_first) based on findings distribution, and outputs ready-to-use --select commands for each phase. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
❌ PR Template Validation FailedNo template marker found in the PR body.Please use one of the available templates when creating your PR:
Tip: Add |
There was a problem hiding this comment.
Pull request overview
This PR adds a --plan CLI flag that generates a customized, phased refactoring plan based on actual code findings. The feature groups smellcheck's 56 rules into 9 ordered phases (correctness, dead code, clarity, idioms, control flow, functions, state/class design, architecture, and OO metrics) with dependency chains and execution metadata. The plan auto-selects between local_first (default, phases 0-8) and architecture_first (reordered to [0,1,7,8,2,3,4,5,6]) strategies based on the ratio of cross-file/metric findings (>30% threshold). The implementation is fully composable with existing flags like --baseline, --select, --diff, and --format json.
Changes:
- Added refactoring phase metadata structure (_REFACTORING_PHASES) organizing 56 rules into 9 phases with execution mode, internal ordering chains, gates, rescan flags, and feedback loops
- Implemented plan computation logic (_compute_plan, _group_findings_by_phase) with automatic strategy selection based on findings distribution
- Added text and JSON formatters for plan output
- Integrated --plan flag into CLI with proper help text and examples
- Provided 12 comprehensive tests covering phase coverage, mapping, strategy selection, formatting, and CLI integration
- Updated SKILL.md with detailed guided refactoring workflow documentation including 3-pass phase execution, manual pattern assignments, conditional branching, and feedback loops
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/smellcheck/detector.py | Core implementation: phase definitions, plan computation, formatters, CLI integration |
| plugins/python-refactoring/skills/python-refactoring/scripts/smellcheck/detector.py | Vendored copy synced with src/ changes |
| tests/test_detector.py | 12 new tests for phase coverage, strategy selection, formatting, and CLI E2E |
| plugins/python-refactoring/skills/python-refactoring/SKILL.md | Comprehensive guided workflow documentation replacing old workflow section |
| README.md | Added --plan usage examples |
Comments suppressed due to low confidence (4)
src/smellcheck/detector.py:499
- Extra blank line inconsistent with other phase definitions. All other phases have no blank line before "feedback_to". Remove this line to maintain consistent formatting.
src/smellcheck/detector.py:527 - Extra blank line inconsistent with other phase definitions. All other phases have no blank line before "feedback_to". Remove this line to maintain consistent formatting.
plugins/python-refactoring/skills/python-refactoring/scripts/smellcheck/detector.py:499 - Extra blank line inconsistent with other phase definitions. All other phases have no blank line before "feedback_to". Remove this line to maintain consistent formatting.
plugins/python-refactoring/skills/python-refactoring/scripts/smellcheck/detector.py:527 - Extra blank line inconsistent with other phase definitions. All other phases have no blank line before "feedback_to". Remove this line to maintain consistent formatting.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Add bundled script examples alongside CLI commands in the workflow initialization section, and add reference file loading guidance before the manual pattern table. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Rewrite to use CLI with --plan --baseline, verifying that baselined findings are excluded from the plan output. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Fix singular/plural grammar in plan header ("1 finding" vs "2 findings")
- Remove stray blank lines in phase 6/8 dicts left by skip_if removal
- Document unknown rule code handling in _group_findings_by_phase
- Add --plan + --generate-baseline mutual exclusion check
- Add tests for feedback label text under both strategies
- Add test for --plan + --generate-baseline mutual exclusion
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
What does this PR do?
Adds
--planCLI flag that generates a phased refactoring plan. Groups 56 rules into 9 ordered phases with dependency chains, auto-selects strategy (local_firstvsarchitecture_firstbased on findings distribution), and outputs ready-to-use--selectcommands for each phase. Updates SKILL.md with comprehensive guided refactoring workflow.Type of change
Checklist
pytest tests/ -vpassestests/test_detector.pysmellcheck src/smellcheck/self-check runs clean (or new findings are intentional)For new smell checks
N/A — this is a CLI feature, not a new smell check.
Test plan
smellcheck src/smellcheck/ --min-severity warning)--plantext output verified with sample code--plan --format jsonoutput validated withjson.toolAdditional context
--baseline,--select/--ignore,--diff,--scope,--format jsonarchitecture_firststrategy, the phase 8→6 feedback relationship correctly renders as "Feeds into" (forward flow) rather than "Feedback to" (loop)skip_ifwas intentionally omitted from phase defs — phases skip naturally when they have 0 findings🤖 Generated with Claude Code