---
phase: 03-workflow-management
type: execute
---

<objective>
Implement advanced workflow commands: diff, delete, move, and open.

Purpose: Complete the workflow command suite with utility commands for comparing local/cloud versions, deleting workflows, moving between projects, and opening in browser.
Output: Four advanced CLI commands that round out the workflow management functionality.
</objective>

<execution_context>
~/.claude/get-shit-done/workflows/execute-phase.md
./summary.md
</execution_context>

<context>
@.planning/PROJECT.md
@.planning/ROADMAP.md
@.planning/STATE.md
@.planning/phases/03-workflow-management/03-01-SUMMARY.md
@.planning/phases/03-workflow-management/03-02-SUMMARY.md
@.planning/phases/03-workflow-management/03-03-SUMMARY.md
@src/n8n_cli/commands/workflow.py
@src/n8n_cli/utils.py
@src/n8n_cli/client/resources/workflows.py
@src/n8n_cli/config.py
@REQUIREMENTS.md
</context>

<tasks>

<task type="auto">
  <name>Task 1: Implement workflow diff command with progressive verbosity</name>
  <files>src/n8n_cli/commands/workflow.py, tests/commands/test_workflow.py</files>
  <action>
Implement `workflow diff` command in workflow.py:
- Argument: file (Path) - local JSON file to compare
- Options: -v/-vv/-vvv/-vvvv (count flag for verbosity levels)
- Logic:
  1. Load local workflow from file: local_wf = json.loads(file.read_text())
  2. Check if "id" field exists, error if not: "No workflow ID in file"
  3. Fetch cloud workflow: cloud_wf = client.workflows.get(local_wf["id"])
  4. Compare and show differences based on verbosity:
     - Level 0 (no -v): Show which top-level fields changed (name, active), list nodes added/removed/modified
     - Level 1 (-v): Add field changes with values (truncate to 30 chars)
     - Level 2 (-vv): Field changes with 300 char truncation
     - Level 3 (-vvv): Field-level diffs (show before → after)
     - Level 4 (-vvvv): Complete node-by-node diffs

  5. Output format from REQUIREMENTS.md:
     ```
     Workflow: {name}

       Name: {local} → {cloud}  (if different)
       Active: {local} → {cloud}  (if different)

     Nodes:
       + New Node (added)
       - Old Node (removed)
       ~ Modified Node
           field: (changed) [show details based on verbosity]
     ```

  6. Node comparison: Compare by node name, detect added/removed/modified
  7. Sort nodes by position (x, y) for display (left-to-right, top-to-bottom)
  8. Use typer.style() for colors: green for additions, red for removals, yellow for modifications

Implementation tip: Create helper function _compare_nodes(local_nodes, cloud_nodes, verbosity) to handle node comparison logic. Keep the command function focused on I/O and formatting.
  </action>
  <verify>pytest tests/commands/test_workflow.py::test_diff -v passes, manual test shows formatted diffs</verify>
  <done>workflow diff command works, shows progressive detail with verbosity levels, formats output clearly with colors</done>
</task>

<task type="auto">
  <name>Task 2: Implement workflow delete and move commands</name>
  <files>src/n8n_cli/commands/workflow.py, tests/commands/test_workflow.py</files>
  <action>
Implement two commands in workflow.py:

1. `workflow delete`:
   - Argument: name (str) - workflow name or ID
   - Options: -f/--force (flag to skip confirmation), -v/--verbose (flag)
   - Logic:
     a. Resolve workflow (ID or find_by_name)
     b. If not --force: Prompt for confirmation with typer.confirm(f"Delete workflow '{workflow.name}'?", abort=True)
     c. Call client.workflows.delete(workflow.id)
     d. Success message: "Deleted workflow: {workflow.name} ({workflow.id})"
   - Error handling: Catch NotFoundError, show user-friendly message

2. `workflow move`:
   - Arguments: name (str) - workflow name/ID, destination (str) - project name
   - Options: -v/--verbose (flag)
   - Logic:
     a. Resolve workflow (ID or find_by_name)
     b. Show message: "Moving workflows between projects requires project ID resolution, which will be implemented in Phase 5 (Project & User Management)"
     c. Show placeholder: "Workflow '{workflow.name}' would be moved to project '{destination}'"
     d. Note in code comment: "TODO: Implement in Phase 5 using projects API to resolve destination name to ID, then update workflow"

The move command is a placeholder for now since we don't have project API methods yet (Phase 5). Include it for completeness but make it clear it's not functional yet.
  </action>
  <verify>pytest tests/commands/test_workflow.py::test_delete passes, manual test: delete with confirmation works</verify>
  <done>workflow delete works with confirmation prompt, workflow move is placeholder for Phase 5</done>
</task>

<task type="auto">
  <name>Task 3: Implement workflow open command</name>
  <files>src/n8n_cli/commands/workflow.py, tests/commands/test_workflow.py</files>
  <action>
Implement `workflow open` command in workflow.py:
- Argument: name (str) - workflow name or ID
- Options: -v/--verbose (flag)
- Logic:
  1. Resolve workflow (ID or find_by_name)
  2. Construct URL: {config.instance_url}/workflow/{workflow.id}
     (Note: instance_url from N8nConfig, not base API URL)
  3. Open in browser using typer.launch(url)
  4. Success message: "Opening workflow in browser: {workflow.name}"
  5. If typer.launch() fails (returns False), show message: "Failed to open browser. URL: {url}"

The instance_url should come from config (e.g., "https://your-instance.app.n8n.cloud"). The workflow URL pattern is /workflow/{id} on the instance, not on the API endpoint.
  </action>
  <verify>pytest tests/commands/test_workflow.py::test_open passes, manual test opens browser</verify>
  <done>workflow open command launches browser to workflow edit page, handles launch failures gracefully</done>
</task>

</tasks>

<verification>
Before declaring plan complete:
- [ ] pytest tests/commands/test_workflow.py passes all tests
- [ ] mypy src/n8n_cli/commands/workflow.py passes
- [ ] ruff check passes
- [ ] Manual test: n8n workflow diff shows progressive verbosity
- [ ] Manual test: n8n workflow delete prompts for confirmation
- [ ] Manual test: n8n workflow open launches browser
- [ ] Phase 3 complete: All workflow commands implemented except retry (deferred to Phase 4)
</verification>

<success_criteria>

- All tasks completed
- All verification checks pass
- workflow diff shows clear comparisons with progressive verbosity
- workflow delete works with confirmation prompt
- workflow move is placeholder for Phase 5
- workflow open launches browser successfully
- Phase 3 (Workflow Management) complete - ready for Phase 4
  </success_criteria>

<output>
After completion, create `.planning/phases/03-workflow-management/03-04-SUMMARY.md`:

# Phase 3 Plan 4: Advanced Workflow Commands Summary

**[Substantive one-liner - what shipped]**

## Accomplishments

- [Key outcomes]

## Files Created/Modified

- `src/n8n_cli/commands/workflow.py` - Added diff/delete/move/open commands
- `tests/commands/test_workflow.py` - Tests for advanced commands

## Decisions Made

[Key decisions and rationale, or "None"]

## Issues Encountered

[Problems and resolutions, or "None"]

## Next Phase Readiness

Phase 3 (Workflow Management) complete. Ready for Phase 4 (Execution Management).

**Workflow commands implemented:**
- ✅ list (with filtering)
- ✅ view (name/ID resolution)
- ✅ pull (to local files)
- ✅ push (from local files)
- ✅ create (with ID update)
- ✅ delete (with confirmation)
- ✅ activate / deactivate
- ✅ diff (progressive verbosity)
- ✅ open (browser launch)
- ⏸️ move (placeholder for Phase 5)
- ⏸️ retry (deferred to Phase 4 - requires execution API)

**Next up:**
Phase 4 will implement execution management commands (list, view, download, retry) which will also enable the workflow retry command.
</output>
