diff --git a/src/modules/bmm/workflows/n8n-expert/modify-workflow/checklist.md b/src/modules/bmm/workflows/n8n-expert/modify-workflow/checklist.md new file mode 100644 index 00000000..9534b32b --- /dev/null +++ b/src/modules/bmm/workflows/n8n-expert/modify-workflow/checklist.md @@ -0,0 +1,90 @@ +# Modify n8n Workflow - Validation Checklist + +## Pre-Modification + +- [ ] Original workflow file was successfully loaded +- [ ] Workflow JSON was valid before modifications +- [ ] Backup was created before making changes +- [ ] User requirements were clearly understood + +## Workflow Structure + +- [ ] Workflow maintains valid JSON structure +- [ ] Workflow name is preserved (unless intentionally changed) +- [ ] All nodes still have unique IDs +- [ ] All nodes still have unique names +- [ ] Workflow settings are preserved + +## Node Modifications + +- [ ] Added nodes have unique IDs +- [ ] Added nodes have unique names +- [ ] Added nodes have valid node types +- [ ] Added nodes have required parameters set +- [ ] Modified nodes preserve their IDs +- [ ] Modified nodes have valid parameter values +- [ ] Removed nodes are completely removed from nodes array + +## Connections + +- [ ] All connections reference existing nodes +- [ ] Connections to/from added nodes are properly configured +- [ ] Connections affected by removed nodes are updated +- [ ] No orphaned connections remain +- [ ] Connection indices are correct (0 for default, 0/1 for IF nodes) +- [ ] No circular dependencies (unless intentional) + +## Node Positioning + +- [ ] New nodes have valid positions +- [ ] New nodes don't overlap with existing nodes +- [ ] Node positions follow spacing guidelines (220px horizontal) +- [ ] Branch nodes have appropriate vertical spacing (±100px) + +## Error Handling + +- [ ] Error handling modifications are applied correctly +- [ ] Retry logic is properly configured if added +- [ ] continueOnFail settings are appropriate +- [ ] maxTries and waitBetweenTries are set if retries enabled + +## Data Flow + +- [ ] Data flow is maintained after modifications +- [ ] New transformations are properly configured +- [ ] Expressions use correct n8n syntax (={{ }}) +- [ ] No data flow breaks introduced + +## Integration Changes + +- [ ] New integrations are properly configured +- [ ] Credential requirements are identified +- [ ] API configurations are correct +- [ ] Existing integrations still work + +## Validation + +- [ ] Modified workflow passes JSON validation +- [ ] All modifications match user requirements +- [ ] No unintended changes were made +- [ ] Workflow structure is still logical + +## Backup & Recovery + +- [ ] Backup file was created successfully +- [ ] Backup location was communicated to user +- [ ] Original workflow can be restored if needed + +## Testing Readiness + +- [ ] Modified workflow can be imported into n8n +- [ ] Changes are testable +- [ ] Expected behavior is clear +- [ ] Any new credentials needed are identified + +## Documentation + +- [ ] Changes made are summarized for user +- [ ] User understands what was modified +- [ ] Testing recommendations provided if needed +- [ ] Backup location shared with user diff --git a/src/modules/bmm/workflows/n8n-expert/modify-workflow/instructions.md b/src/modules/bmm/workflows/n8n-expert/modify-workflow/instructions.md new file mode 100644 index 00000000..5f086d95 --- /dev/null +++ b/src/modules/bmm/workflows/n8n-expert/modify-workflow/instructions.md @@ -0,0 +1,327 @@ +# Modify n8n Workflow - Workflow Instructions + +```xml +The workflow execution engine is governed by: {project_root}/{bmad_folder}/core/tasks/workflow.xml +You MUST have already loaded and processed: {installed_path}/workflow.yaml +This workflow modifies an existing n8n workflow based on user requirements. + + + + + Before asking any questions, analyze what the user has already told you + + Review the user's initial request and conversation history + Extract any mentioned: workflow file path, changes needed, specific nodes + + + Summarize your understanding + Skip directly to Step 2 (Load Existing Workflow) + + + + Note what you already know + Only ask about missing information in Step 1 + + + + Proceed with full elicitation in Step 1 + + + + + Ask Question 1: "Which workflow file do you want to modify?" + Present numbered options: + 1. Provide file path - Specify exact path to workflow JSON + 2. Search in workflows folder - List available workflows + 3. Paste workflow JSON - Provide workflow content directly + + WAIT for user selection (1-3) + + + Ask: "Please provide the file path to the workflow JSON" + WAIT for user input + Store in {{workflow_file}} + + + + List all .json files in workflows/ directory + Present as numbered list + WAIT for user selection + Store selected file path in {{workflow_file}} + + + + Ask: "Please paste the workflow JSON content" + WAIT for user input + Create temporary file with content + Store temp file path in {{workflow_file}} + + + Ask Question 2: "What type of modification do you need?" + Present numbered options: + 1. Add new nodes - Add functionality to existing workflow + 2. Modify existing nodes - Change node parameters or configuration + 3. Remove nodes - Delete nodes from workflow + 4. Change connections - Modify how nodes are connected + 5. Update error handling - Add or modify retry/error logic + 6. Optimize workflow - Improve performance or structure + 7. Multiple changes - Combination of above + + WAIT for user selection (1-7) + Store selection in {{modification_type}} + + Ask Question 3: "Please describe the changes you want to make" + WAIT for user input + Store in {{changes_description}} + + + Ask: "What nodes do you want to add? (describe functionality)" + WAIT for user input + Store in {{nodes_to_add}} + + + + Ask: "Which nodes do you want to modify? (provide node names or descriptions)" + WAIT for user input + Store in {{nodes_to_modify}} + + + + Ask: "Which nodes do you want to remove? (provide node names)" + WAIT for user input + Store in {{nodes_to_remove}} + + + + + Only load the workflow file when user provides it - never preload + + Read workflow file from {{workflow_file}} + Parse JSON content + Validate JSON structure + + + Inform user: "The workflow file has invalid JSON syntax" + Show error details + Ask: "Would you like me to fix the JSON syntax first? (yes/no)" + WAIT for user response + + + Fix JSON syntax errors + Save corrected file + Proceed with loading + + + + Exit workflow with error + + + + Extract workflow structure: + - Workflow name + - List of nodes (names, types, IDs) + - Connections map + - Current settings + + Display workflow summary to user: + - Name: [workflow name] + - Nodes: [count] nodes + - Node list: [node names and types] + - Connections: [connection count] + + + + Create backup of original workflow + Save backup to: {{workflow_file}}.backup-{timestamp} + Store true in {{backup_created}} + Inform user: "Backup created at {{workflow_file}}.backup-{timestamp}" + + + + Check if Context7 MCP server is configured + Try to list available MCP tools + + + Store true in {{context7_available}} + Proceed to Step 5 + + + + Store false in {{context7_available}} + Inform user: "Context7 MCP not configured. Proceeding with built-in knowledge." + Proceed to Step 6 + + + + + + Resolve n8n library ID using Context7 + Query Context7 for relevant n8n documentation based on: + - Modification type: {{modification_type}} + - Nodes to add: {{nodes_to_add}} + - Changes description: {{changes_description}} + Store relevant documentation snippets for reference + + + + + Load {{helpers}} for node creation guidelines + Analyze current workflow structure + Plan modifications based on requirements: + + + 1. Identify where new nodes should be inserted + 2. Determine node types needed + 3. Plan connections to/from new nodes + 4. Calculate positions for new nodes + + + + 1. Identify nodes to modify by name or ID + 2. Determine what parameters to change + 3. Validate new parameter values + + + + 1. Identify nodes to remove by name or ID + 2. Identify connections that will be affected + 3. Plan how to reconnect remaining nodes + + + + 1. Identify connections to modify + 2. Validate new connection targets exist + 3. Update connection indices if needed + + + Present modification plan to user: + - Changes to be made: [detailed list] + - Nodes affected: [list] + - New connections: [list] + - Removed connections: [list] + + Ask: "Does this modification plan look correct?" + Present numbered options: + 1. Yes - Proceed with modifications + 2. No - Adjust the plan + 3. Add more changes - Include additional modifications + + WAIT for user selection (1-3) + + + Ask: "What changes or additions are needed?" + WAIT for user input + Adjust plan based on feedback + Repeat this step + + + + + Follow guidelines from {{helpers}} for proper node creation + + Load current workflow JSON into memory + + If Adding Nodes: + 1. Generate unique node IDs (check against existing IDs) + 2. Create node objects with proper structure + 3. Calculate positions (avoid overlaps with existing nodes) + 4. Add nodes to workflow.nodes array + 5. Create connections to/from new nodes + 6. Update connections object + + + If Modifying Nodes: + 1. Find nodes by name or ID + 2. Update parameters as specified + 3. Preserve node ID and other unchanged properties + 4. Validate new parameter values + 5. Update node in workflow.nodes array + + + If Removing Nodes: + 1. Find nodes by name or ID + 2. Remove from workflow.nodes array + 3. Remove all connections to/from removed nodes + 4. Update connections object + 5. Reconnect remaining nodes if needed + + + If Changing Connections: + 1. Update connections object + 2. Validate all referenced nodes exist + 3. Ensure connection indices are correct + 4. Remove orphaned connections + + + If Updating Error Handling: + 1. Find affected nodes + 2. Add or update error handling properties: + - continueOnFail + - retryOnFail + - maxTries + - waitBetweenTries + 3. Validate error handling configuration + + + Validate modified workflow: + - All node IDs are unique + - All node names are unique + - All connections reference existing nodes + - No orphaned nodes (except trigger) + - Node positions don't overlap + + + + Save modified workflow to {{workflow_file}} + Preserve original file location + + + + NEVER delete the file if validation fails - always fix syntax errors + + Run: node -e "JSON.parse(require('fs').readFileSync('{{workflow_file}}', 'utf8')); console.log('✓ Valid JSON')" + + + Read the error message carefully - it shows the syntax error and position + Open the file and navigate to the error location + Fix the syntax error (add missing comma, bracket, or quote as indicated) + Save the file + Re-run validation with the same command + Repeat until validation passes + + + Once validation passes, confirm with user: "Workflow modified successfully at {{workflow_file}}" + + + + Provide summary of changes made: + - Nodes added: [count and names] + - Nodes modified: [count and names] + - Nodes removed: [count and names] + - Connections changed: [count] + - Backup location: {{workflow_file}}.backup-{timestamp} + + Ask: "Would you like to make additional changes?" + Present numbered options: + 1. No - I'm done + 2. Yes - Make more modifications + 3. Revert - Restore from backup + + WAIT for user selection (1-3) + + + Return to Step 1 with current workflow + + + + Restore workflow from backup + Confirm restoration to user + + + + + Validate against checklist at {{validation}} using {{bmad_folder}}/core/tasks/validate-workflow.xml + + + +``` diff --git a/src/modules/bmm/workflows/n8n-expert/modify-workflow/workflow.yaml b/src/modules/bmm/workflows/n8n-expert/modify-workflow/workflow.yaml new file mode 100644 index 00000000..4ec24de8 --- /dev/null +++ b/src/modules/bmm/workflows/n8n-expert/modify-workflow/workflow.yaml @@ -0,0 +1,30 @@ +name: modify-workflow +description: "Edit or update existing n8n workflow" +author: "Saif" + +# Workflow components +installed_path: "{project-root}/{bmad_folder}/bmm/workflows/n8n-expert/modify-workflow" +shared_path: "{project-root}/{bmad_folder}/bmm/workflows/n8n-expert/_shared" +instructions: "{installed_path}/instructions.md" +validation: "{installed_path}/checklist.md" + +# Shared resources +helpers: "{shared_path}/n8n-helpers.md" +templates: "{shared_path}/n8n-templates.yaml" +platform_mappings: "{shared_path}/platform-mappings.yaml" + +# Variables +variables: + workflow_file: "" # Will be elicited + modification_type: "" # Will be elicited + changes_description: "" # Will be elicited + nodes_to_add: [] # Will be elicited + nodes_to_modify: [] # Will be elicited + nodes_to_remove: [] # Will be elicited + backup_created: false # Will be set + context7_available: false # Will be checked + +default_output_file: "" # Will use existing file location + +standalone: true +web_bundle: false