Impl

2. Analyze Codebase & Dependencies - Explore relevant code to understand existing patterns - Check app directory structure…

mojisejr updated 4mo ago
Claude CodeGeneric
View source ↗
# Implementation Workflow Command

## Usage

/impl [task description] [issue-number] /impl [issue-number]


## Implementation Workflow (TDD Red-Green-Refactor)

### 🔍 Phase 0: Analysis & Planning
1. **Analyze Requirement Carefully**
   - Break down the requirement into smaller, testable components
   - Identify what needs to be implemented vs what already exists
   - Determine success criteria and acceptance tests
   - Check if Prisma migrations or LINE Login changes are needed

2. **Analyze Codebase & Dependencies**
   - Explore relevant code to understand existing patterns
   - Check app directory structure (Next.js App Router)
   - Verify if new dependencies need to be added to package.json
   - **STOP IMPLEMENTATION** if additional config/setup is required
   - Inform user about any missing prerequisites

3. **TDD Planning with Success Criteria**
   - Create comprehensive todo list with Red-Green-Refactor phases
   - Define what "success" looks like for each component
   - Plan test cases covering: happy path, edge cases, error handling
   - Consider testing framework: Vitest + React Testing Library

### 🔴 Phase 1: RED - Write Failing Tests
1. **Write Tests BEFORE Implementation**
   - Create test files in `tests/` directory
   - For domain logic: `tests/domain.test.ts`
   - For API routes: `tests/integration.test.ts`
   - For components: `tests/components/` or using `.test.tsx`
   - Tests must clearly define expected behavior

2. **Verify Tests FAIL**
   - Run test suite to ensure all new tests FAIL (Red phase)
   - Verify error messages clearly indicate missing implementation
   - Confirm tests actually test the intended functionality

### 🟢 Phase 2: GREEN - Make Tests Pass
1. **Minimal Implementation**
   - Write the SIMPLEST code that makes tests pass
   - Focus on functionality over optimization
   - Do NOT refactor or optimize in this phase
   - Add just enough code to satisfy test requirements

2. **Continuous Test Execution**
   - Run tests after every small change
   - Fix failing tests immediately
   - **NEVER proceed to next test until current tests pass 100%**

### 🔵 Phase 3: REFACTOR - Improve Code Quality
1. **Code Improvement**
   - Refactor implementation for clarity and maintainability
   - Apply Next.js best practices and TypeScript strict typing
   - Use proper React patterns (hooks, Server/Client components)
   - Remove code duplication and improve structure

2. **Continuous Validation**
   - Run tests after EVERY refactor change
   - Ensure 100% test pass rate is maintained
   - Check TypeScript compilation: `npx tsc --noEmit`
   - Run `npx prisma generate` if schema changes
   - Repeat Refactor phase until code quality meets standards

### 🔄 Phase 4: Final Quality Assurance
1. **Comprehensive Testing**
   - Run ENTIRE test suite (existing + new tests)
   - **MUST achieve 100% pass rate - NO failing tests allowed**
   - Verify test coverage is complete and meaningful

2. **Build & Lint Validation**
   - **Build MUST pass 100%**: `npm run build` - No build errors allowed
   - **Linter MUST pass 100%**: `npm run lint` - No warnings/errors allowed
   - **TypeScript MUST pass**: `npx tsc --noEmit` - No type errors allowed
   - **Prisma MUST be generated**: `npx prisma generate` if schema changed
   - Fix any issues before proceeding

### 📋 Branch Management (STAGING-ONLY POLICY)
- **MANDATORY**: Check current branch immediately upon command execution
- **FORBIDDEN**: NEVER code, implement, or modify files on main branch
- **REQUIRED**: ALWAYS work on staging branch ONLY
- **FEATURE BRANCHES**: Create from staging ONLY when needed
- **SAFETY CHECK**: If on main branch, IMMEDIATELY switch to staging
- **HARD STOP**: Command execution HALTS if cannot switch to staging

### 🤖 Multi-Agent Task Management
- Use Task tool with subagent_type='general-purpose' for complex tasks
- Use Task tool with subagent_type='Explore' for codebase exploration
- Use Task tool with subagent_type='Plan' for architecture planning
- Run agents in parallel when possible for efficiency

### 📊 Continuous Progress Tracking
- Use TodoWrite tool to track Red-Green-Refactor phases
- Mark tasks as in_progress and completed systematically
- Keep working until ALL phases are complete
- Never skip any test case or phase

### ✅ Git Commit Standards
- Run `git add .` after all phases complete successfully
- Create comprehensive commit messages that are:
  - Follow conventional commits: feat:, fix:, docs:, refactor:, etc.
  - Include scope: e.g., feat(orchard): add tree health monitoring
  - Include issue reference: closes #123
  - Descriptive and readable for future reference
- Include context about what was changed and why

### 🚫 PR Policy
- NEVER create PRs automatically
- Only create PR when explicitly requested by user
- PRs should go to staging branch for review

## Implementation Commands

### When executing /impl command:

#### Step 1: Environment Setup (STAGING-ONLY ENFORCEMENT)
```bash
# MANDATORY: Check current branch FIRST
Bash git branch --show-current

# CRITICAL: If on main branch, IMMEDIATELY switch:
Bash git checkout staging

# FORBIDDEN: NEVER work on main branch
# - If branch is 'main', STOP ALL IMPLEMENTATION
# - Switch to staging BEFORE any coding
# - ONLY proceed if on staging or feature branch

# OPTIONAL: Create feature branch FROM staging:
Bash git checkout -b feature/task-123-description

# MANDATORY: Ensure .tmp folder exists for temporary files
Bash mkdir -p .tmp

# MANDATORY: Ensure .tmp/ is in .gitignore
Bash grep -q "^\.tmp/$" .gitignore || echo ".tmp/" >> .gitignore

Step 2: TDD Execution Flow

  1. Phase 0: Analysis

    • Analyze requirement carefully
    • Check codebase and dependencies
    • Create comprehensive todo list with Red-Green-Refactor phases
  2. Phase 1: RED

    • Write failing tests for ALL components
    • Use Vitest + React Testing Library
    • Run tests: npm test
    • Verify tests actually FAIL (100% red phase)
  3. **Phase 2: GREEN


Maintain Impl?

Let people know it's listed here — add the badge (live metrics, light/dark aware) or a plain link to your README or docs.

[Impl on getagentictools](https://getagentictools.com/loops/mojisejr-implementation-workflow-command?ref=badge)
npx agentictools info loops/mojisejr-implementation-workflow-command

The second line is the CLI lookup for this page — handy in READMEs and docs.