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

<objective>
Implement basic workflow CLI commands: list, view, activate, and deactivate.

Purpose: Provide core workflow read and state-change operations through the CLI, building on the API methods from Plan 1.
Output: Four working CLI commands with proper output formatting, error handling, and integration with APIClient.
</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
@src/n8n_cli/cli.py
@src/n8n_cli/config.py
@src/n8n_cli/client/core.py
@src/n8n_cli/client/resources/workflows.py
@src/n8n_cli/client/models/workflow.py
@REQUIREMENTS.md
</context>

<tasks>

<task type="auto">
  <name>Task 1: Create workflow command group and implement list command</name>
  <files>src/n8n_cli/commands/workflow.py, src/n8n_cli/cli.py, tests/commands/test_workflow.py</files>
  <action>
Create new file src/n8n_cli/commands/workflow.py with Typer app for workflow commands:
1. Create workflow_app = typer.Typer(name="workflow", help="Manage n8n workflows")
2. Register in src/n8n_cli/cli.py: app.add_typer(workflow_app, name="workflow")
3. Implement `workflow list` command:
   - Options: -p/--project (str), --active (flag), --inactive (flag), -v/--verbose (flag)
   - Load config with N8nConfig.load()
   - Create APIClient context manager
   - Call client.workflows.list(active=True/False/None based on flags)
   - Format output: Green for active workflows, yellow for inactive, show ID with -v flag
   - Use typer.style() for colors (typer.colors.GREEN, typer.colors.YELLOW)
   - If --project specified, filter results by project_id (will need to resolve project name to ID in later phase, for now just show message "Project filtering not yet implemented")

Error handling: Catch N8NAPIError and display user-friendly message with typer.echo(). Don't let exceptions leak to user.
  </action>
  <verify>pytest tests/commands/test_workflow.py::test_list -v passes, manual test: n8n workflow list shows workflows</verify>
  <done>workflow list command works, shows color-coded output, handles active/inactive filtering, -v shows IDs</done>
</task>

<task type="auto">
  <name>Task 2: Implement workflow view command</name>
  <files>src/n8n_cli/commands/workflow.py, tests/commands/test_workflow.py</files>
  <action>
Implement `workflow view` command in workflow.py:
- Argument: name (str) - accepts workflow name, ID, or file path
- Options: -v/--verbose (flag for more details)
- Logic:
  1. If name looks like a workflow ID (alphanumeric, ~12-16 chars), call client.workflows.get(name)
  2. Otherwise, try client.workflows.find_by_name(name)
  3. If not found, display error: "Workflow not found: {name}"
  4. Display workflow info: name, ID, active status, created/updated timestamps
  5. With -v: also show project_id, tags, node count, connection count
  6. Format output with typer.echo() in readable format

Don't implement file path resolution yet (that's in Plan 3 with utility functions). For now, just support name and ID.
  </action>
  <verify>pytest tests/commands/test_workflow.py::test_view -v passes, manual test: n8n workflow view "name" shows details</verify>
  <done>workflow view command works with workflow names and IDs, shows formatted output, verbose flag adds details</done>
</task>

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

1. `workflow activate`:
   - Argument: name (str) - workflow name or ID
   - Options: -v/--verbose (flag)
   - Logic: Resolve workflow (ID or find_by_name), call client.workflows.activate(workflow_id), display success message
   - Success output: "Activated workflow: {workflow.name} ({workflow.id})"

2. `workflow deactivate`:
   - Argument: name (str)
   - Options: -v/--verbose (flag)
   - Logic: Same as activate but call deactivate()
   - Success output: "Deactivated workflow: {workflow.name} ({workflow.id})"

Both commands should handle errors gracefully and show user-friendly messages. Use the same resolution logic as view command (ID or name).
  </action>
  <verify>pytest tests/commands/test_workflow.py::test_activate -v and test_deactivate pass, manual tests work</verify>
  <done>workflow activate and deactivate commands work, resolve workflows by name/ID, show clear success messages</done>
</task>

</tasks>

<verification>
Before declaring plan complete:
- [ ] pytest tests/commands/test_workflow.py passes
- [ ] mypy src/n8n_cli/commands/workflow.py passes
- [ ] ruff check src/n8n_cli/commands/workflow.py passes
- [ ] Manual test: n8n workflow list shows color-coded workflows
- [ ] Manual test: n8n workflow view "name" shows workflow details
- [ ] Manual test: n8n workflow activate/deactivate work
</verification>

<success_criteria>

- All tasks completed
- All verification checks pass
- Four workflow commands implemented and working: list, view, activate, deactivate
- Commands integrate with APIClient and WorkflowsResource
- Error handling prevents stack traces from reaching users
- Output is formatted and user-friendly
  </success_criteria>

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

# Phase 3 Plan 2: Basic Workflow CLI Commands Summary

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

## Accomplishments

- [Key outcomes]

## Files Created/Modified

- `src/n8n_cli/commands/__init__.py` - Package init
- `src/n8n_cli/commands/workflow.py` - Workflow command group with list/view/activate/deactivate
- `src/n8n_cli/cli.py` - Registered workflow command group
- `tests/commands/__init__.py` - Test package init
- `tests/commands/test_workflow.py` - Tests for workflow commands

## Decisions Made

[Key decisions and rationale, or "None"]

## Issues Encountered

[Problems and resolutions, or "None"]

## Next Step

Ready for 03-03-PLAN.md (File Operation Commands)
</output>
