Loading...
Loading...
Finds all REFACTOR markers in codebase, validates associated ADRs exist, identifies stale markers (30+ days old), and detects orphaned markers (no ADR reference). Use during status checks, before feature completion, or for refactor health audits. Triggers on "check refactor status", "marker health", "what's the status", or PROACTIVELY before marking features complete. Works with Python (.py), TypeScript (.ts), and JavaScript (.js) files using grep patterns to locate markers and validate against ADR files in docs/adr/ directories.
npx skill4agent add dawiddutoit/custom-claude quality-detect-refactor-markers# Find all REFACTOR markers (file-level and method-level)
grep -rn "^# REFACTOR:" src/ --include="*.py"
grep -rn "# REFACTOR(" src/ --include="*.py"
# Validate ADR existence
test -f docs/adr/in_progress/027-service-result-migration.md && echo "ADR exists" || echo "ADR missing"
# Calculate marker age (if STARTED date present)
# Current date - STARTED date > 30 days = STALEgrep -rn "^# REFACTOR:" src/ --include="*.py" --include="*.ts" --include="*.js"grep -rn "# REFACTOR(" src/ --include="*.py" --include="*.ts" --include="*.js"# REFACTOR: ADR-027 - ServiceResult Migration
# STATUS: IN_PROGRESS
# STARTED: 2025-10-10
# PERMANENT_RECORD: docs/adr/in_progress/027-service-result-migration.md# REFACTOR(ADR-027): Migrate to ServiceResult pattern
def get_user(user_id: int):
passADR-(\d+)# STATUS:# STARTED:# PERMANENT_RECORD:# Search for ADR file in all ADR directories
find docs/adr -name "*027-*.md" -type fdocs/adr/in_progress/XXX-title.md # Active refactors
docs/adr/implemented/XXX-title.md # Completed refactors
docs/adr/deprecated/XXX-title.md # Deprecated refactors# For markers with STARTED date
STARTED_DATE="2025-09-01"
CURRENT_DATE=$(date +%Y-%m-%d)
AGE_DAYS=$((( $(date -d "$CURRENT_DATE" +%s) - $(date -d "$STARTED_DATE" +%s) ) / 86400))
# Check if stale
if [ $AGE_DAYS -gt 30 ]; then
echo "⚠️ STALE: Marker is $AGE_DAYS days old"
fi# If ADR moved to implemented/ but markers remain
if [ -f docs/adr/implemented/027-*.md ]; then
echo "🔴 Should be removed: ADR complete but markers present"
fihealth: GOOD | ATTENTION_NEEDED | CRITICAL
active_refactors:
- adr: ADR-XXX
title: Title from ADR
files: Count of files with markers
markers: Total marker count
age_days: Age since STARTED date
status: IN_PROGRESS | BLOCKED | REVIEW
adr_valid: true | false
stale_markers: []
orphaned_markers: []
should_be_removed: []
summary: Human-readable summarydocs/adr/implemented/User: "What's my progress on the feature?"
@statuser workflow:
1. Check todo.md status (TodoRead)
2. Check quality metrics (pytest, pyright)
3. Invoke detect-refactor-markers skill
4. Include refactor health in status report
Report includes:
- Task completion percentage
- Quality gate status
- Refactor health status
- Blockers or issuesUser: "Mark feature complete"
@feature-completer workflow:
1. Verify all tasks complete
2. Verify quality gates pass
3. Invoke detect-refactor-markers skill
4. Block completion if markers present
Decision logic:
- If active markers found: ❌ Block completion
- Reason: "Cannot complete feature with active refactor markers"
- Action: "Complete or remove markers first"
- If no markers: ✅ Allow completionUser: "How's the refactor going?" OR "Check refactor status"
Agent workflow:
1. Invoke detect-refactor-markers skill
2. Generate comprehensive health report
3. Recommend actions for each issue
Report sections:
- Active refactors summary
- Stale markers (prioritized by age)
- Orphaned markers (needs immediate cleanup)
- Completion suggestions# Grep returns no results
grep -rn "^# REFACTOR:" src/ --include="*.py"
# (no output)
Report:
✅ No active refactors (healthy state)
All code is clean, no ongoing migrations.# Old marker format (missing STARTED field)
# REFACTOR: ADR-015 - Database Migration
# STATUS: IN_PROGRESS
# (no STARTED date)
Handling:
- Can't calculate age
- Report as "Unknown age (missing STARTED date)"
- Recommend adding STARTED date# Valid: Method markers can exist without file marker
# REFACTOR(ADR-027): Migrate to ServiceResult
def get_user():
pass
# REFACTOR(ADR-027): Migrate to ServiceResult
def update_user():
pass
Report:
✅ Valid markers (method-only is allowed)
File: src/services/user_service.py
Markers: 2 method-level (no file-level)# Valid: Multiple refactors can overlap
# REFACTOR: ADR-027 - ServiceResult Migration
# STATUS: IN_PROGRESS
# STARTED: 2025-10-10
# REFACTOR(ADR-042): Payment Service Refactor
def process_payment():
pass
Report:
✅ Multiple active refactors in file
File: src/services/payment_service.py
- ADR-027: ServiceResult Migration (file-level)
- ADR-042: Payment Refactor (1 method marker)# Marker references old path
# PERMANENT_RECORD: docs/adr/in_progress/027-service-result-migration.md
# But ADR actually at:
docs/adr/implemented/027-service-result-migration.md
Detection:
🔴 Should be removed: ADR moved to implemented/
Action: Remove markers (refactor complete)findtest -ffind docs/adr -name "*XXX-*.md"docs/adr/implemented/# Possible causes:
# 1. Wrong directory (not in project root)
pwd # Check current directory
cd /path/to/project/root
# 2. Wrong pattern (marker format different)
# Try broader search:
grep -rn "REFACTOR" src/
# 3. Markers in different file types
grep -rn "REFACTOR" src/ --include="*.py" --include="*.ts" --include="*.js" --include="*.tsx"# Check ADR directory structure
ls -R docs/adr/
# Expected structure:
# docs/adr/in_progress/
# docs/adr/implemented/
# docs/adr/deprecated/
# If different structure, adjust validation paths# Check date format in marker
# Expected: YYYY-MM-DD (2025-10-16)
# If different format, parsing will fail
# Verify date command works
date +%Y-%m-%d
# For macOS vs Linux compatibility:
# macOS: date -j -f "%Y-%m-%d" "2025-10-16" +%s
# Linux: date -d "2025-10-16" +%s# Handle variation:
# Format 1: # REFACTOR: ADR-027 - Title
# Format 2: # REFACTOR(ADR-027): Description
# Format 3: # REFACTOR [ADR-027] Title
# Use flexible regex:
grep -rn "REFACTOR.*ADR-[0-9]" src/
# Extract ADR number with sed:
sed -n 's/.*ADR-\([0-9]\+\).*/\1/p'health: GOOD
active_refactors:
- adr: ADR-027
title: ServiceResult Migration
files: 2
markers: 10
age_days: 6
status: IN_PROGRESS
adr_valid: true
adr_path: docs/adr/in_progress/027-service-result-migration.md
stale_markers: []
orphaned_markers: []
should_be_removed: []
summary: All refactors healthy. 1 active refactor (ADR-027) with 10 markers across 2 files.health: CRITICAL
active_refactors:
- adr: ADR-027
title: ServiceResult Migration
files: 2
markers: 10
age_days: 6
status: IN_PROGRESS
adr_valid: true
stale_markers:
- adr: ADR-015
title: Database Migration
file: src/infrastructure/database.py
age_days: 45
started: 2025-09-01
status: IN_PROGRESS
issue: Stale (>30 days without completion)
action: Review progress, update ADR status, or complete work
orphaned_markers:
- adr: ADR-042
file: src/services/payment_service.py
markers: 4
issue: ADR file not found in any docs/adr directory
possible_causes:
- ADR deleted without removing markers
- ADR moved to different directory
- Incorrect ADR number in markers
action: |
1. Search for ADR: find docs/adr -name "*payment*"
2. If found: Update marker ADR numbers
3. If not found: Remove markers using manage-refactor-markers
should_be_removed:
- adr: ADR-028
title: Cache Layer Implementation
files: 4
markers: 12
adr_status: COMPLETE
adr_path: docs/adr/implemented/028-cache-layer.md
issue: ADR complete and moved to implemented/ but markers remain
action: Remove all markers using manage-refactor-markers remove
summary: |
3 critical issues requiring attention:
- 1 stale marker (ADR-015, 45 days old)
- 1 orphaned marker set (ADR-042, 4 markers)
- 1 should-be-removed set (ADR-028, 12 markers)
Recommended priority:
1. Remove orphaned ADR-042 markers (critical)
2. Remove completed ADR-028 markers (cleanup)
3. Review stale ADR-015 refactor (assess continuation)grepfindtest -fdate.claude/refactor-marker-guide.mddocs/adr/src/