- name
- pre-implementation-check
- description
- Verify existing implementations before coding to prevent duplicate work and enable verification-focused workflows. Use before starting any new feature implementation to check if functionality already exists. Saves 20-40% of implementation time by avoiding redundant work.
# Pre-Implementation Check
Verify existing implementations before coding to prevent duplicate work. Saves 20-40% of implementation time by catching existing features early.
## Overview
Before implementing new functionality, always verify:
1. Does this feature already exist?
2. Is it partially implemented?
3. Does it need enhancement rather than creation?
**Pattern observed**: Agents discovered features already implemented after starting work, wasting 20-40% of implementation time.
## Mandatory Skill Loading Validation
**CRITICAL**: Before starting implementation, verify ALL mandatory skills are loaded. Missing mandatory skills lead to incomplete verification and protocol violations.
### Mandatory Skills Checklist
**For Web Applications**:
- [ ] `agent-browser` (MANDATORY - browser automation required)
- [ ] `screenshot-handling` (if visual verification needed)
- [ ] `completion-marker-optimization` (RECOMMENDED - prevents protocol violations)
**For Phaser Games**:
- [ ] `phaser-game-testing` (MANDATORY - Phaser testing patterns)
- [ ] `agent-browser` (MANDATORY - Phaser games are web apps)
- [ ] `screenshot-handling` (MANDATORY for visual tasks)
- [ ] `completion-marker-optimization` (RECOMMENDED - prevents protocol violations)
**For All Tasks**:
- [ ] `completion-marker-optimization` (RECOMMENDED - prevents protocol violations)
- [ ] `pre-implementation-check` (RECOMMENDED - this skill)
### Skill Loading Verification Patterns
**Pattern 1: Check Skill Availability**
```markdown
## Mandatory Skill Check
Before starting implementation:
1. **Web Application**:
- [ ] agent-browser loaded
- [ ] screenshot-handling loaded (if visual verification)
2. **Phaser Game**:
- [ ] phaser-game-testing loaded
- [ ] agent-browser loaded
- [ ] screenshot-handling loaded
3. **All Tasks**:
- [ ] completion-marker-optimization loaded
- [ ] pre-implementation-check loaded
If any mandatory skill is missing, load it BEFORE proceeding.
```
**Pattern 2: Load Missing Skills**
```markdown
## Load Missing Mandatory Skills
If mandatory skills are missing:
1. Load agent-browser (for web apps/games)
2. Load phaser-game-testing (for Phaser games)
3. Load screenshot-handling (for visual tasks)
4. Load completion-marker-optimization (for all tasks)
Then proceed with implementation.
```
### Skill Loading Workflow
**Step 0: Verify Mandatory Skills (Before Step 1)**
Before searching codebase, verify mandatory skills:
1. **Identify task type**: Web app, Phaser game, or other
2. **Check mandatory skills**: Use checklist above
3. **Load missing skills**: If any mandatory skill missing, load it
4. **Verify skills loaded**: Confirm skills are available
5. **Proceed to Step 1**: Only after all mandatory skills loaded
**Example**:
```markdown
## Pre-Implementation: Mandatory Skills
**Task Type**: Phaser Game
**Mandatory Skills Check**:
- [x] phaser-game-testing: ✅ Loaded
- [x] agent-browser: ✅ Loaded
- [x] screenshot-handling: ✅ Loaded
- [x] completion-marker-optimization: ✅ Loaded
**Status**: All mandatory skills loaded. Proceeding to implementation check.
```
## Dev Server Verification
### Add Dev Server Health Check to Pre-Implementation Workflow
**Before starting implementation, verify dev server is running and healthy:**
```bash
# Check if dev server is running
check_dev_server() {
local port=${1:-5173} # Default Vite port
# Check if port is in use
if lsof -i :$port > /dev/null 2>&1; then
echo "Dev server running on port $port"
# Health check
if curl -f http://localhost:$port > /dev/null 2>&1; then
echo "Dev server is healthy"
return 0
else
echo "Dev server not responding"
return 1
fi
else
echo "Dev server not running on port $port"
return 1
fi
}
```
#### Backend / Server (for backend tasks)
**Before the first API test**: Check that the target port is free (e.g. `lsof -i :PORT`) or that a single dev server is listening. Start command: use an **explicit directory** (e.g. `cd /absolute/path/to/backend && npm run dev`). Optional: short-timeout health check (e.g. `curl -f http://localhost:PORT/api/health --max-time 5`). **Auth tasks**: First register/login may be slow (e.g. bcrypt). Use request timeouts (e.g. 10–15 s) for register/login (e.g. `curl --max-time 10`).
#### Path convention (monorepos)
- Backend library code lives under `backend/src/lib/`, not `backend/lib/`. Confirm the backend app root before creating API or lib files.
### Port Verification Patterns
**Pattern 1: Check Configuration Files**
```bash
# Check vite.config.ts for port
PORT=$(grep -o "port: [0-9]*" vite.config.ts | grep -o "[0-9]*" || echo "5173")
# Check package.json for port in dev script
PORT=$(grep -o "vite --port [0-9]*" package.json | grep -o "[0-9]*" || echo "5173")
```
**Pattern 2: Check Common Ports**
```bash
# Check common ports in parallel
for port in 3000 5173 8080 5000; do
if lsof -i :$port > /dev/null 2>&1; then
echo "Dev server found on port $port"
break
fi
done
```
**Pattern 3: Parse Terminal Output**
```bash
# If server is starting, parse output for port
npm run dev 2>&1 | grep -o "Local:.*http://localhost:[0-9]*" | grep -o "[0-9]*"
```
### Server Readiness Checks
**Verify server is actually serving content:**
```bash
# Health check function
verify_server_ready() {
local url=$1
local max_attempts=5
local attempt=0
while [ $attempt -lt $max_attempts ]; do
if curl -f "$url" > /dev/null 2>&1; then
echo "Server is ready"
return 0
fi
attempt=$((attempt + 1))
sleep $((2 ** $attempt)) # Exponential backoff: 2s, 4s, 8s, 16s
done
echo "Server not ready after $max_attempts attempts"
return 1
}
```
## Test Seam Availability
### Check Test Seam Availability Before Implementation
**For Phaser games, check test seam availability before implementation:**
```bash
# Check test seam availability
check_test_seam_availability() {
local url=$1
local max_wait=5 # 5 seconds max
# Open browser
agent-browser open "$url"
# Wait for test seam with timeout
local elapsed=0
while [ $elapsed -lt $max_wait ]; do
if agent-browser eval "window.__TEST__?.sceneKey || false"; then
echo "Test seam available"
return 0
fi
sleep 1
elapsed=$((elapsed + 1))
done
echo "Test seam not available after $max_wait seconds"
return 1
}
```
### Document Expected Setup Times
**Document expected test seam setup times:**
| Scenario | Expected Setup Time |
|----------|-------------------|
| Initial page load | 2-5 seconds |
| Scene transition | 1-3 seconds |
| Test seam initialization | 1-2 seconds |
| Total | 4-10 seconds |
**If test seam takes longer than expected**:
- Check browser console for errors
- Verify test seam setup in source code
- Check if scene is properly initialized
### Fallback Strategies When Test Seams Aren't Ready
**If test seams aren't available after timeout:**
1. **Document limitation**:
```markdown
## Test Seam Limitation
Test seam not available after 5 second timeout.
Proceeding with implementation, will verify via code review.
```
2. **Use alternative verification**:
- Code review
- TypeScript compilation
- DOM inspection (if applicable)
3. **Proceed with caution**:
- Note limitation in progress.txt
- Use alternative verification methods
- Document fallback method used
## Dependency Verification
### Check for Required Dependencies
**Before implementation, verify required dependencies are installed:**
```bash
# Check for required npm packages
check_dependencies() {
local required_packages=("phaser" "typescript" "vite")
for package in "${required_packages[@]}"; do
if ! grep -q "\"$package\"" package.json; then
echo "Missing dependency: $package"
return 1
fi
done
echo "All required dependencies present"
return 0
}
```
### Verify Build Tools Are Available
**Check if build tools are available:**
```bash
# Check for build tools
check_build_tools() {
# Check Node.js
if ! command -v node &> /dev/null; then
echo "Node.js not found"
return 1
fi
# Check npm
if ! command -v npm &> /dev/null; then
echo "npm not found"
return 1
fi
# Check TypeScript compiler
if ! command -v tsc &> /dev/null && ! npx tsc --version &> /dev/null; then
echo "TypeScript compiler not found"
return 1
fi
echo "All build tools available"
return 0
}
```
### Confirm Test Infrastructure Is Ready
**Verify test infrastructure is ready:**
```bash
# Check test infrastructure
check_test_infrastructure() {
# Check for test files
if [ ! -d "tests" ] && [ ! -d "__tests__" ]; then
echo "Test directory not found"
# Not a blocker, but document
fi
# Check for test runner
if ! grep -q "\"test\"" package.json; then
echo "Test script not found in package.json"
# Not a blocker, but document
fi
# Check for agent-browser (for browser testing)
if ! command -v agent-browser &> /dev/null; then
echo "agent-browser not found"
# Document limitation
fi
echo "Test infrastructure check complete"
}
```
## Infrastructure Checks
### Verification Patterns for Common Development Environments
**Pattern 1: Vite Development Environment**
```bash
# Vite environment check
check_vite_environment() {
# Check vite.config.ts exists
if [ ! -f "vite.config.ts" ] && [ ! -f "vite.config.js" ]; then
echo "vite.config not found"
return 1
fi
# Check dev server port
local port=$(grep -o "port: [0-9]*" vite.config.ts 2>/dev/null | grep -o "[0-9]*" || echo "5173")
# Check if dev server is running
if lsof -i :$port > /dev/null 2>&1; then
echo "Vite dev server running on port $port"
return 0
else
echo "Vite dev server not running"
return 1
fi
}
```
**Pattern 2: Phaser Game Environment**
```bash
# Phaser game environment check
check_phaser_environment() {
# Check Phaser is installed
if ! grep -q "\"phaser\"" package.json; then
echo "Phaser not found in package.json"
return 1
fi
# Check for scene files
if [ ! -d "src/scenes" ] && [ ! -d "scenes" ]; then
echo "Scene directory not found"
# Not a blocker, but document
fi
# Check for test seam setup
if ! grep -r "window.__TEST__" src/ 2>/dev/null; then
echo "Test seam not found in source code"
# Document limitation
fi
echo "Phaser environment check complete"
return 0
}
```
**Pattern 3: React Application Environment**
```bash
# React environment check
check_react_environment() {
# Check React is installed
if ! grep -q "\"react\"" package.json; then
echo "React not found in package.json"
return 1
fi
# Check for component files
if [ ! -d "src/components" ] && [ ! -d "components" ]; then
echo "Component directory not found"
# Not a blocker, but document
fi
echo "React environment check complete"
return 0
}
```
## Checklist Template for Pre-Implementation Verification
**Use this checklist for every pre-implementation check:**
```markdown
## Pre-Implementation Verification Checklist
### Mandatory Skills
- [ ] All mandatory skills loaded (see Mandatory Skill Loading section)
### Dev Server
- [ ] Dev server is running
- [ ] Dev server is healthy (responds to HTTP requests)
- [ ] Port verified (from config or detected)
- [ ] Server is serving content correctly
### Test Seam (for Phaser games)
- [ ] Test seam available (if applicable)
- [ ] Test seam setup time documented
- [ ] Fallback strategy defined (if test seam unavailable)
### Dependencies
- [ ] Required dependencies installed
- [ ] Build tools available (Node.js, npm, TypeScript)
- [ ] Test infrastructure ready (if applicable)
### Infrastructure
- [ ] Development environment verified (Vite/React/Phaser)
- [ ] Configuration files present
- [ ] Source code structure verified
### Feature Check
- [ ] Codebase searched for existing implementation
- [ ] Test seam commands checked (if applicable)
- [ ] Success criteria compared to existing code
- [ ] Decision made: verify existing vs. implement new
### Documentation
- [ ] Findings documented in progress.txt
- [ ] Limitations documented (if any)
- [ ] Action plan documented
```
## Workflow
### Step 0: Infrastructure Verification (Before Step 1)
**Before searching codebase, verify infrastructure:**
1. **Verify mandatory skills loaded** (see Mandatory Skill Loading section)
2. **Check dev server**:
- Verify dev server is running
- Check server health
- Verify port configuration
3. **Check test seam availability** (for Phaser games):
- Verify test seam is available
- Document setup time
- Define fallback strategy if unavailable
4. **Verify dependencies**:
- Check required packages are installed
- Verify build tools are available
- Confirm test infrastructure is ready
5. **Verify infrastructure**:
View on GitHub