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:
2026-03-19 04:33:00 -07:00
parent cd5034ce78
commit ff08b1d6f5
5 changed files with 483 additions and 1 deletions

View File

@@ -362,6 +362,43 @@ The rendering pipeline is documented in `docs/PIPELINE.md` using Mermaid diagram
2. If adding new SVG diagrams, render them manually using an external tool (e.g., Mermaid Live Editor)
3. Commit both the markdown and any new diagram files
### Pipeline Mutation API
The Pipeline class supports dynamic mutation during runtime via the mutation API:
**Core Methods:**
- `add_stage(name, stage, initialize=True)` - Add a stage to the pipeline
- `remove_stage(name, cleanup=True)` - Remove a stage and rebuild execution order
- `replace_stage(name, new_stage, preserve_state=True)` - Replace a stage with another
- `swap_stages(name1, name2)` - Swap two stages
- `move_stage(name, after=None, before=None)` - Move a stage in execution order
- `enable_stage(name)` - Enable a stage
- `disable_stage(name)` - Disable a stage
**New Methods (Issue #35):**
- `cleanup_stage(name)` - Clean up specific stage without removing it
- `remove_stage_safe(name, cleanup=True)` - Alias for remove_stage that explicitly rebuilds
- `can_hot_swap(name)` - Check if a stage can be safely hot-swapped
- Returns False for stages that provide minimum capabilities as sole provider
- Returns True for swappable stages
**WebSocket Commands:**
Commands can be sent via WebSocket to mutate the pipeline at runtime:
```json
{"action": "remove_stage", "stage": "stage_name"}
{"action": "swap_stages", "stage1": "name1", "stage2": "name2"}
{"action": "enable_stage", "stage": "stage_name"}
{"action": "disable_stage", "stage": "stage_name"}
{"action": "cleanup_stage", "stage": "stage_name"}
{"action": "can_hot_swap", "stage": "stage_name"}
```
**Implementation Files:**
- `engine/pipeline/controller.py` - Pipeline class with mutation methods
- `engine/app/pipeline_runner.py` - `_handle_pipeline_mutation()` function
- `engine/pipeline/ui.py` - execute_command() with docstrings
- `tests/test_pipeline_mutation_commands.py` - Integration tests
## Skills Library
A skills library MCP server (`skills`) is available for capturing and tracking learned knowledge. Skills are stored in `~/.skills/`.