@noanswer/context-compose
Version:
Orchestrate complex AI interactions with Context Compose. A powerful CLI and server for building, validating, and managing context for large language models using the Model Context Protocol (MCP).
75 lines (64 loc) โข 2.45 kB
YAML
version: 1
kind: action
name: Refactor
description: Basic code refactoring and improvement
prompt: |
Perform systematic code refactoring to improve code quality and maintainability.
Identify common refactoring opportunities and apply best practices.
Focus on reducing complexity while maintaining functionality.
Use this for improving code structure and readability through targeted refactoring.
enhanced-prompt: |-
# ๐ง Code Refactoring
## Code Analysis
```bash
PROJECT_NAME=$(basename $(pwd))
echo "๐ง Project: $PROJECT_NAME"
# Create backup
echo "๐พ Creating backup..."
if git status >/dev/null 2>&1; then
git stash push -m "Pre-refactoring backup $(date)" 2>/dev/null || echo "No changes to backup"
echo "โ
Backup completed with git stash"
else
echo "โน๏ธ Not a git repository - manual backup recommended"
fi
```
## Issue Identification
```bash
echo "๐ Analyzing code issues..."
# Find large files
echo "๐ Large files (500+ lines):"
find src/ -name "*.js" -o -name "*.ts" -o -name "*.jsx" -o -name "*.tsx" 2>/dev/null | \
xargs wc -l 2>/dev/null | awk '$1 > 500 {print " - " $2 ": " $1 " lines"}' | head -5
# Detect complex patterns
echo "๐งฎ Complex code patterns:"
NESTED_LOOPS=$(grep -r "for.*for\|while.*while" --include="*.js" --include="*.ts" src/ 2>/dev/null | wc -l)
DEEP_NESTING=$(grep -r "if.*if.*if" --include="*.js" --include="*.ts" src/ 2>/dev/null | wc -l)
echo " - Nested loops: $NESTED_LOOPS"
echo " - Deep nesting: $DEEP_NESTING"
# Check for outdated patterns
echo "๐ Improvement opportunities:"
VAR_COUNT=$(grep -r "var " --include="*.js" src/ 2>/dev/null | wc -l)
CONSOLE_COUNT=$(grep -r "console.log" --include="*.js" --include="*.ts" src/ 2>/dev/null | wc -l)
echo " - var usage: $VAR_COUNT (recommend let/const)"
echo " - console.log: $CONSOLE_COUNT (recommend proper logging)"
```
## Validation & Testing
```bash
echo "๐งช Refactoring validation:"
# Run tests
if [ -f "package.json" ]; then
echo "๐งช Running tests..."
if npm test >/dev/null 2>&1; then
echo "โ
All tests passed"
else
echo "โ Tests failed - requires fixes"
fi
# Run linting
if npm run lint >/dev/null 2>&1; then
echo "โ
Linting passed"
else
echo "โ ๏ธ Linting errors found"
fi
fi
```
**๐ฏ Result:** Systematic code improvement with quality validation