refactor: remove planning module and repair system#122
Conversation
Move actively-used code out of planning/ module to their natural homes: - parse_structured_response → core/llm_utils.py - smart_filter.py → registry/smart_filter.py - build_planning_context + build_nodes_context → registry/context_builder.py - build_workflows_context → core/workflow/context.py - prompt loader → core/prompt_utils.py Replace PocketFlow discovery nodes with plain functions: - WorkflowDiscoveryNode → core/workflow/discovery.py:discover_workflow() - ComponentBrowsingNode → registry/discovery.py:discover_components() Remove install_anthropic_model monkey-patch and drop direct anthropic>=0.75 dependency (llm-anthropic provides it transitively). Deprecation notices added to planning/ source files pending Phase 2 deletion.
Phase 2 of planning removal — deletes src/pflow/planning/ (~7,300 lines), repair system (~1,050 lines), and all associated tests (~23,000 lines). Code cleanup: - Simplified workflow_execution.py from 642 to 83 lines (validate→execute→return) - Removed 654 lines from cli/main.py (13 planner functions, 7 CLI flags) - Removed planner metrics fields, is_planner threading, __modified_nodes__ tracking - Removed _is_fixable_error(), repaired_workflow_ir, PlannerError, update_ir() - Renamed CriticalPlanningError→CriticalDiscoveryError, build_planning_context→build_component_context Bug fixes (pre-existing, exposed by refactor): - API warnings (__warnings__) now surfaced as actionable error messages instead of generic "Workflow failed with action: error" - MCP "error": null no longer produces "None" string in error output - Nested MCP data.error (Slack/Discord style) now correctly unwrapped Documentation: Updated all CLAUDE.md files, architecture docs, agent definitions, user-facing docs, scripts. Removed natural language mode from CLI docs. Tests: 4,070 pass, 0 skipped from planning/repair. Added 3 regression tests for the error formatting bug fixes.
…iew] - Tightened CLI test assertions to verify post-planner direct execution - Added explicit validation short-circuit assertion in workflow_execution test - Added degraded-success formatter coverage (2 tests) - Updated 5 CLAUDE.md files: build_planning_context → build_component_context - Removed stale DEP003 anthropic exclusion (no longer imported) - Updated progress log
Code Review — PR #122: Remove Planning Module and Repair SystemOverall Assessment: This is an excellent cleanup PR. Removing ~42,000 lines of dead code, simplifying Critical — must fix before mergeNone. Warnings — should be addressed1.
2. In except Exception as e:
# If validation fails, log and return raw result
logger.warning(f"Failed to validate result through {expected_type.__name__}: {e}")
return resultThis silently returns unvalidated data when Pydantic validation fails. The callers ( Consider either:
3.
Suggestions — optional improvements1. In if isinstance(component_context, dict) and "error" in component_context:
logger.warning(...)
component_context_str = ""Returning an empty string when 2. Bug fix tests are high quality The three regression tests in 3. The reduction from 478 lines with repair loops to 18 lines of validate-execute-return is a model cleanup. The 4. Consider:
SummaryStrong PR. The approach of relocating active code to natural homes, converting PocketFlow nodes to plain functions, and removing the entire planning/repair subsystem is well-executed. The bug fixes are well-motivated with clear regression tests. The MCP server discovery service simplification from PocketFlow ceremony to direct function calls is particularly clean. The only actionable item I'd recommend addressing before merge is the silent fallback in |
Summary
Remove the gated planning module (~7,300 production lines, ~23,000 test lines) and repair system (~1,050 production lines). Replace PocketFlow-based discovery nodes with plain functions. Drop direct
anthropicSDK dependency. Fix two pre-existing runtime bugs in error reporting exposed during the refactor.Net impact: ~42,000 lines removed. 4,070 tests pass, 0 skipped from planning/repair.
Task
Task 92: Remove Planning Module and Repair System
Changes
Phase 1: Relocate active dependencies
parse_structured_response→core/llm_utils.pysmart_filter.py→registry/smart_filter.pybuild_planning_context+build_nodes_context→registry/context_builder.pybuild_workflows_context→core/workflow/context.pycore/prompt_utils.pyWorkflowDiscoveryNode→core/workflow/discovery.py:discover_workflow()(plain function +WorkflowMatchdataclass)ComponentBrowsingNode→registry/discovery.py:discover_components()(plain function +ComponentSelectiondataclass)install_anthropic_modelmonkey-patch, droppedanthropic>=0.75direct depPhase 2: Delete and clean
src/pflow/planning/(32 files), repair files, 68+ test filesworkflow_execution.pyfrom 642 → 83 lines (validate→execute→return)cli/main.py(13 planner functions, 7 CLI flags)is_plannerthreading,__modified_nodes__trackingCriticalPlanningError→CriticalDiscoveryError,build_planning_context→build_component_contextBug fixes (pre-existing, exposed by refactor)
__warnings__) now surfaced as actionable error messages instead of generic "Workflow failed with action: error""error": nullno longer produces"None"string in error outputdata.error(Slack/Discord style) now correctly unwrappedExplanation
The planning module was gated since Task 107 (markdown format migration) with 516 skipped tests and unreachable code paths. Rather than maintaining dormant code, we removed it cleanly. The few active features that depended on planning code (discovery commands, context builder, structured response parser) were relocated to their natural homes.
Discovery features (
pflow workflow discover,pflow registry discover) were preserved as plain functions with typed dataclass returns — simpler, more testable, and with explicit contracts vs the PocketFlow node ceremony.The
anthropicSDK was only used by planning's custom Anthropic wrapper for prompt caching and thinking tokens. Thellm-anthropicplugin natively supportsschema=for structured output, which is all discovery needs.Created Docs
.taskmaster/tasks/task_92/task-92.md— updated task spec reflecting what was actually implemented.taskmaster/tasks/task_92/task-review.md— post-implementation review with integration points, patterns, and AI agent guidance.taskmaster/tasks/task_92/implementation/progress-log.md— detailed implementation journal with decisions, corrections, and learningsTesting
make test: 4,070 passed, 0 skipped, 0 failedmake check: all green (ruff, mypy, deptry)pflow.planningreferences remain insrc/ortests/