# Methodology Workflow Enforcement - MANDATORY PHASE PROGRESSION

## 🔒 CRITICAL ENFORCEMENT RULES

**NO EXCEPTIONS**: These rules CANNOT be bypassed. Any violation INVALIDATES the entire optimization session.

---

## Phase Progression Rules

### Rule 1: Sequential Phase Execution
**MANDATORY ORDER**: Analysis → Performance → Verification
- ❌ **FORBIDDEN**: Skipping any phase
- ❌ **FORBIDDEN**: Reverse phase order  
- ❌ **FORBIDDEN**: Parallel phase execution

### Rule 2: Phase Completion Gates
**BLOCKING CONDITIONS**: Each phase has mandatory gates that MUST pass before progression.

#### Analysis Phase Gates
- [ ] **Gate A1**: Complete file inventory generated using automated tools
- [ ] **Gate A2**: User scope selection documented (if large codebase)
- [ ] **Gate A3**: File + Pattern checklists created
- **ENFORCEMENT**: Cannot proceed to Performance phase until ALL Analysis gates pass

#### Performance Phase Gates  
- [ ] **Gate P1**: Every file in scope addressed in optimization log
- [ ] **Gate P2**: Infrastructure changes implemented where required
- [ ] **Gate P3**: No phantom optimizations claimed
- **ENFORCEMENT**: Cannot proceed to Verification phase until ALL Performance gates pass

#### Verification Phase Gates
- [ ] **Gate V1**: File coverage validation completed
- [ ] **Gate V2**: All gaps identified and resolved  
- [ ] **Gate V3**: Final accuracy validation passed
- **ENFORCEMENT**: Cannot mark session complete until ALL Verification gates pass

---

## Validation Commands - MANDATORY USAGE

### File Inventory Validation
```bash
# REQUIRED: Generate actual file list
find /project/path -name "*.al" -type f | sort
# OR
glob **/*.al
```

### Coverage Cross-Reference
```bash  
# REQUIRED: Validate optimization claims
grep -r "filename.al" optimization-log.md
# Cross-reference against actual files
```

### Gap Detection
```bash
# REQUIRED: Identify missing files
diff planned-files.txt actual-files.txt
# Any differences = BLOCKING CONDITION
```

---

## Agent Behavior Enforcement

### FORBIDDEN Agent Actions
- ❌ **Claiming "100% complete"** without verification phase
- ❌ **Skipping file inventory generation**
- ❌ **Making optimization claims for non-existent files**
- ❌ **Proceeding without gate validation**
- ❌ **Marking any phase complete with known gaps**

### REQUIRED Agent Actions  
- ✅ **Generate file lists using automated tools**
- ✅ **Cross-reference ALL claims against actual files**
- ✅ **Document EVERY gate passage explicitly**
- ✅ **Stop and request gap resolution when validation fails**
- ✅ **Execute verification phase for EVERY session**

---

## Session Validation Checklist

### Before Marking ANY Session Complete:
- [ ] **Analysis phase**: All gates documented as passed
- [ ] **Performance phase**: All gates documented as passed  
- [ ] **Verification phase**: Executed and all gates passed
- [ ] **File inventory**: Generated using automated tools and validated
- [ ] **Coverage gaps**: Zero unresolved gaps remaining
- [ ] **Accuracy validation**: All optimization claims verified against actual files

### Session INVALID If:
- Any phase skipped
- Any gate bypassed without documentation
- Any phantom optimizations claimed
- Any files in scope left unaddressed
- Verification phase not executed

---

## Quality Assurance Requirements

### Documentation Standards
- **File references**: Must include exact file paths that exist
- **Line references**: Must reference actual line numbers in files
- **Optimization claims**: Must be verifiable by examining actual code
- **Coverage claims**: Must be backed by file inventory validation

### Validation Evidence Required
- **Actual file lists**: Generated by automated tools, not manual entry  
- **Cross-reference results**: Showing planned vs actual analysis coverage
- **Gap resolution**: Documentation of how ALL identified gaps were resolved
- **Accuracy verification**: Evidence that claimed optimizations actually exist

---

## Enforcement Violations - Session Restart Required

### Major Violations (Restart Entire Session):
- Phantom file optimizations claimed
- Verification phase completely skipped
- Major coverage gaps discovered in verification

### Minor Violations (Restart Current Phase):
- Gate bypassed without documentation
- File inventory not generated using automated tools  
- Optimization claims not cross-referenced

---

## Success Criteria - ALL MUST BE MET

✅ **Phase Sequence**: Analysis → Performance → Verification completed in order  
✅ **Gate Compliance**: ALL gates passed and documented  
✅ **File Accuracy**: Zero phantom files, zero missing files in scope  
✅ **Validation Evidence**: Automated tools used for all inventory and validation  
✅ **Gap Resolution**: ALL coverage gaps identified and resolved  
✅ **Quality Assurance**: All optimization claims verified against actual code

**Only sessions meeting ALL criteria are considered valid and complete.**