---
phase: 05-project-user-management
plan: 02
type: execute
---

<objective>
Implement project and user CLI commands (list, view, invite, remove) using the ProjectsResource and UsersResource API methods from Plan 1.

Purpose: Enable terminal-based project and user management following established CLI patterns from Phases 3-4.
Output: Complete `n8n project` and `n8n user` command groups with list, view, invite, and remove operations.
</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/05-project-user-management/05-01-SUMMARY.md
@REQUIREMENTS.md
@src/n8n_cli/cli.py
@src/n8n_cli/commands/workflow.py
@src/n8n_cli/commands/execution.py
@src/n8n_cli/client/resources/projects.py
@src/n8n_cli/client/resources/users.py
@src/n8n_cli/config.py
@tests/commands/test_workflow.py
@tests/commands/test_execution.py
</context>

<tasks>

<task type="auto">
  <name>Implement project list and project view commands</name>
  <files>src/n8n_cli/commands/project.py, tests/commands/test_project.py, src/n8n_cli/cli.py</files>
  <action>
    Create src/n8n_cli/commands/project.py following workflow.py pattern from Phase 3:

    **project list command:**
    - `n8n project list [-v]`
    - Call client.projects.list()
    - Output: Name and type in columns (default), add ID with -v
    - Color coding: No special colors (projects don't have active/inactive)
    - Format: "ProjectName    team" or "ProjectName    team    abc123def" (with -v)

    **project view command:**
    - `n8n project view <name> [-v]`
    - Resolve name to ID using client.projects.find_by_name(name)
    - Call client.projects.get(project_id)
    - Output: Name, ID, Type, and Members list
    - Members extracted from project.relations if present (project API returns relations with member info)
    - Format:
      ```
      Name: My Project
      ID: abc123def
      Type: team
      Members:
        user@example.com (admin)
        other@example.com (editor)
      ```
    - With -v: Show member IDs

    **Error handling:**
    - Use `from None` to suppress exception chaining for clean CLI errors
    - typer.Exit(1) on errors
    - Validate config (api_key, instance_url) with clear setup messages

    **CLI registration:**
    - Update src/n8n_cli/cli.py to add project_group command group
    - Follow pattern from workflow_group and execution_group

    Write tests following test_workflow.py pattern:
    - test_project_list (default and verbose)
    - test_project_view (default and verbose)
    - test_project_view_not_found
    - Use pytest-httpx for mocking API responses
  </action>
  <verify>pytest tests/commands/test_project.py -v passes, `n8n project list` and `n8n project view` work locally</verify>
  <done>project list and project view commands working with proper output formatting and error handling</done>
</task>

<task type="auto">
  <name>Implement user list, user invite, and user remove commands</name>
  <files>src/n8n_cli/commands/user.py, tests/commands/test_user.py, src/n8n_cli/cli.py</files>
  <action>
    Create src/n8n_cli/commands/user.py following project.py pattern:

    **user list command:**
    - `n8n user list [-v]`
    - Call client.users.list()
    - Output: Email, name (firstName lastName), status (if available), role in columns
    - Format: "user@example.com    John Doe    admin"
    - With -v: Add user ID column
    - Handle missing firstName/lastName gracefully (use email if names not set)

    **user invite command:**
    - `n8n user invite <email> [-v]`
    - Call client.users.invite(email)
    - Output: "Invited user@example.com" (default) or full user details with -v
    - Handle ValidationError if email already exists (friendly message)

    **user remove command:**
    - `n8n user remove <email> [-f] [-v]`
    - Resolve email to user ID using client.users.find_by_email(email)
    - If not found: "User not found: {email}", exit 1
    - Without --force: Prompt for confirmation with typer.confirm()
    - Call client.users.delete(user_id)
    - Output: "Removed user@example.com"

    **Error handling:**
    - Use `from None` for clean CLI errors
    - Handle NotFoundError gracefully with user-friendly messages
    - Validate config before making API calls

    **CLI registration:**
    - Update src/n8n_cli/cli.py to add user_group command group

    Write comprehensive tests:
    - test_user_list (default and verbose)
    - test_user_invite_success
    - test_user_invite_duplicate (ValidationError handling)
    - test_user_remove_with_force
    - test_user_remove_cancelled (typer.confirm returns False)
    - test_user_remove_not_found
  </action>
  <verify>pytest tests/commands/test_user.py -v passes, all user commands work locally, ruff check passes</verify>
  <done>user list, user invite, and user remove commands working with confirmation prompts and proper error handling</done>
</task>

</tasks>

<verification>
Before declaring plan complete:
- [ ] pytest tests/commands/test_project.py tests/commands/test_user.py passes
- [ ] mypy src/n8n_cli/commands/ passes
- [ ] ruff check passes
- [ ] Manual verification: Run `n8n project list`, `n8n project view`, `n8n user list`, `n8n user invite`, `n8n user remove` locally
- [ ] All commands registered in src/n8n_cli/cli.py
- [ ] Confirmation prompts work correctly for user remove
</verification>

<success_criteria>

- All tasks completed
- All verification checks pass
- No errors or warnings introduced
- project list shows projects with type
- project view shows project details with members
- user list shows users with email, name, role
- user invite creates new user invitation
- user remove deletes user with confirmation (or --force)
- All commands follow established CLI patterns (error handling, verbosity, formatting)
- Ready for Plan 3 (member management commands)
</success_criteria>

<output>
After completion, create `.planning/phases/05-project-user-management/05-02-SUMMARY.md`:

# Phase 5 Plan 2: Project and User CLI Commands Summary

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

## Performance

- **Duration:** [time]
- **Started:** [timestamp]
- **Completed:** [timestamp]
- **Tasks:** 2
- **Files modified:** [count]

## Accomplishments

- project list command with type display
- project view command with member list
- user list command with email, name, role
- user invite command with duplicate handling
- user remove command with confirmation prompt
- All commands integrated into n8n CLI
- Comprehensive test suite with [X] test methods
- Following established CLI patterns from Phases 3-4

## Files Created/Modified

- `src/n8n_cli/commands/project.py` - project list and view commands
- `src/n8n_cli/commands/user.py` - user list, invite, remove commands
- `tests/commands/test_project.py` - Comprehensive project command tests
- `tests/commands/test_user.py` - Comprehensive user command tests
- `src/n8n_cli/cli.py` - Register project_group and user_group

## Decisions Made

[Key decisions and rationale, or "None - followed plan exactly"]

## Deviations from Plan

[Any auto-fixes or deferred issues, or "None"]

## Issues Encountered

[Problems and resolutions, or "None"]

## Next Phase Readiness

Phase 5 Plan 2 complete. Ready for **05-03-PLAN.md (Member Management)**.

**CLI foundation established:**
- ✅ project list and project view commands
- ✅ user list, user invite, user remove commands
- ✅ All commands follow established patterns
- ✅ Proper error handling and user confirmations
- ✅ Comprehensive test coverage
- ✅ All quality gates passing

**Next up:**
Phase 5 Plan 3 will implement member management (list, add, remove members from projects) to complete the project/user/member management suite.

---
*Phase: 05-project-user-management*
*Completed: [date]*
</output>
