UNPKG

@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
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