feat: Complete Pipeline Mutation API implementation
- Add can_hot_swap() function to Pipeline class - Add cleanup_stage() method to Pipeline class - Fix remove_stage() to rebuild execution order after removal - Extend ui_panel.execute_command() with docstrings for mutation commands - Update WebSocket handler to support pipeline mutation commands - Add _handle_pipeline_mutation() function for command routing - Add comprehensive integration tests in test_pipeline_mutation_commands.py - Update AGENTS.md with mutation API documentation Issue: #35 (Pipeline Mutation API) Acceptance criteria met: - ✅ can_hot_swap() checker for stage compatibility - ✅ cleanup_stage() cleans up specific stages - ✅ remove_stage_safe() rebuilds execution order (via remove_stage) - ✅ Unit tests for all operations - ✅ Integration with WebSocket commands - ✅ Documentation in AGENTS.md
This commit is contained in:
@@ -111,8 +111,82 @@ class Pipeline:
|
||||
stage.cleanup()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Rebuild execution order and capability map if stage was removed
|
||||
if stage and self._initialized:
|
||||
self._rebuild()
|
||||
|
||||
return stage
|
||||
|
||||
def remove_stage_safe(self, name: str, cleanup: bool = True) -> Stage | None:
|
||||
"""Remove a stage and rebuild execution order safely.
|
||||
|
||||
This is an alias for remove_stage() that explicitly rebuilds
|
||||
the execution order after removal.
|
||||
|
||||
Args:
|
||||
name: Name of the stage to remove
|
||||
cleanup: If True, call cleanup() on the removed stage
|
||||
|
||||
Returns:
|
||||
The removed stage, or None if not found
|
||||
"""
|
||||
return self.remove_stage(name, cleanup)
|
||||
|
||||
def cleanup_stage(self, name: str) -> None:
|
||||
"""Clean up a specific stage without removing it.
|
||||
|
||||
This is useful for stages that need to release resources
|
||||
(like display connections) without being removed from the pipeline.
|
||||
|
||||
Args:
|
||||
name: Name of the stage to clean up
|
||||
"""
|
||||
stage = self._stages.get(name)
|
||||
if stage:
|
||||
try:
|
||||
stage.cleanup()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def can_hot_swap(self, name: str) -> bool:
|
||||
"""Check if a stage can be safely hot-swapped.
|
||||
|
||||
A stage can be hot-swapped if:
|
||||
1. It exists in the pipeline
|
||||
2. It's not required for basic pipeline function
|
||||
3. It doesn't have strict dependencies that can't be re-resolved
|
||||
|
||||
Args:
|
||||
name: Name of the stage to check
|
||||
|
||||
Returns:
|
||||
True if the stage can be hot-swapped, False otherwise
|
||||
"""
|
||||
# Check if stage exists
|
||||
if name not in self._stages:
|
||||
return False
|
||||
|
||||
# Check if stage is a minimum capability provider
|
||||
stage = self._stages[name]
|
||||
stage_caps = stage.capabilities if hasattr(stage, "capabilities") else set()
|
||||
minimum_caps = self._minimum_capabilities
|
||||
|
||||
# If stage provides a minimum capability, it's more critical
|
||||
# but still potentially swappable if another stage provides the same capability
|
||||
for cap in stage_caps:
|
||||
if cap in minimum_caps:
|
||||
# Check if another stage provides this capability
|
||||
providers = self._capability_map.get(cap, [])
|
||||
# This stage is the sole provider - might be critical
|
||||
# but still allow hot-swap if pipeline is not initialized
|
||||
if len(providers) <= 1 and self._initialized:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
return True
|
||||
|
||||
def replace_stage(
|
||||
self, name: str, new_stage: Stage, preserve_state: bool = True
|
||||
) -> Stage | None:
|
||||
|
||||
Reference in New Issue
Block a user