---
description:
globs:
alwaysApply: true
---
# Task Completion Workflow with Zen MCP

<critical_requirement>
**MANDATORY:** Before marking any task as complete, you MUST follow this exact workflow to ensure code quality:
</critical_requirement>

<workflow_overview>
**Enhanced Quality Assurance Steps:**
1. **Task Definition Validation** - Verify alignment with task, PRD, and tech spec
2. **Rules Analysis & Code Review** - Analyze applicable rules and perform comprehensive review
3. **Issue Resolution** - Address all identified problems
4. **Pre-Commit Validation** - Final validation before commit
5. **Task Completion** - Mark task as complete only after successful validation
</workflow_overview>

## 1. Task Definition Validation

<mandatory_step>
**FIRST:** Verify the implementation aligns with requirements:
</mandatory_step>

- **Task Definition:** Review the specific task file (e.g., `tasks/prd-[feature-slug]/[task_number]_task.md`)
- **PRD Alignment:** Check against the Product Requirements Document (`tasks/prd-[feature-slug]/_prd.md`)
- **Tech Spec Compliance:** Ensure implementation follows the Technical Specification (`tasks/prd-[feature-slug]/_techspec.md`)

```
Verify that task [task_number] implementation fully satisfies:
1. The specific requirements defined in the task file
2. The business objectives from the PRD
3. The technical specifications and architecture requirements
4. All acceptance criteria and success metrics
```

## 2. Rules Analysis & Code Review with Zen MCP

<mandatory_step>
**Analyze applicable rules first, then perform comprehensive code review:**
</mandatory_step>

### 2.1 Rules Analysis
```
Analyze all Cursor rules that apply to the changed files for task [task_number]:
- Identify which .cursor/rules/*.mdc files are relevant to the implementation
- List the specific coding standards, patterns, and requirements that apply
- Check for any rule violations or areas needing attention
```

### 2.2 Multi-Model Code Review

<mandatory_step>
Use the criteria from [`review-checklist.mdc`](mdc:.cursor/rules/review-checklist.mdc) as the basis for all code reviews:
</mandatory_step>

<critical>
**MANDATORY REQUIREMENTS:**
- **ALWAYS** check dependent files APIs before write tests to avoid write wrong code
- **ALWAYS** verify against PRD and tech specs - NEVER make assumptions
- **NEVER** use workarounds, especially in tests - implement proper solutions
- **MUST** follow all established project standards:
    - Architecture patterns: `.cursor/rules/architecture.mdc`
    - Go coding standards: `.cursor/rules/go-coding-standards.mdc`
    - Testing requirements: `.cursor/rules/testing-standards.mdc`
    - API standards: `.cursor/rules/api-standards.mdc`
    - Security & quality: `.cursor/rules/quality-security.mdc`
- **MUST** run `make lint` and `make test` before completing ANY subtask
- **MUST** follow `.cursor/rules/task-review.mdc` workflow for parent tasks
**Enforcement:** Violating these standards results in immediate task rejection.
</critical>

```
Use zen for codereview with gemini-2.5-pro-preview-05-06 to analyze the implementation for task [task_number]: [task_title].
Focus on the review checklist criteria: code quality, security, adherence to project standards, error handling, testing patterns, and maintainability.
Apply the specific rules identified in step 2.1 during the review.
```

```
Use zen with o3 to perform a logical review of the implementation for task [task_number]: [task_title].
Analyze the logic, edge cases, and potential issues while considering the applicable coding standards and rules.
```

### 2.3 Rules-Specific Review
```
Use zen with gemini-2.5-pro-preview-05-06 to review task [task_number] implementation specifically against the identified Cursor rules:
- Verify compliance with project-specific coding standards
- Check adherence to architectural patterns and design principles
- Validate implementation follows the established conventions
- Ensure all rule-based requirements are met
```

## 3. Fix Review Issues

<mandatory_fixes>
Address ALL issues identified:
- Fix critical and high-severity issues immediately
- Address medium-severity issues unless explicitly justified
- Document any decisions to skip low-severity issues
</mandatory_fixes>

## 4. Pre-Commit Validation

<mandatory_step>
**Execute codereview validation with proper parameters:**
</mandatory_step>

**Required Parameters:**
- `path`: Current workspace directory (absolute path)
- `model`: Use `gemini-2.5-pro-preview-05-06` for comprehensive analysis
- `prompt`: Original task requirements and context

**Example Implementation:**
```
Execute codereview validation for task [task_number]:
- Path: /path/to/workspace
- Model: gemini-2.5-pro-preview-05-06
- Context: Implementation of [task_title] as defined in task requirements
- Review: Comprehensive validation of all staged and unstaged changes
```

**Validation Focus:**
- Verify implementation matches task requirements
- Check for bugs, security issues, and incomplete implementations
- Ensure changes follow project coding standards
- Validate test coverage and error handling
- Confirm no code duplication or logic redundancy

## 5. Mark Task Complete

**ONLY AFTER** successful validation, update the Markdown task file:

```markdown
- [x] 1.0 [task_title] ✅ COMPLETED
  - [x] 1.1 Implementation completed
  - [x] 1.2 Task definition, PRD, and tech spec validated
  - [x] 1.3 Rules analysis and compliance verified
  - [x] 1.4 Code review completed with Zen MCP
  - [x] 1.5 Ready for deployment
```

## Important Notes

- **Tool Usage:** Most Zen MCP tools use natural language requests, but **codereview requires structured parameters** (path, model, prompt)
- **File Paths:** Use absolute paths when referencing files with Zen MCP
- **Available Models:** `gemini-2.5-pro-preview-05-06` (deep analysis), `o3` (logical reasoning), `flash` (fast responses)
- **Codereview Parameters:** Always provide absolute workspace path, model selection, and task context for codereview validation
- **Exceptions:** Only allowed for hotfixes, documentation-only, or config-only changes (must be documented)

<enforcement_policy>
**MANDATORY:** This workflow must be followed for every task completion. No exceptions without explicit justification.
</enforcement_policy>
