UNPKG

claude-code-automation

Version:

๐Ÿš€ Generic project automation system with anti-compaction protection and recovery capabilities. Automatically detects project type (React, Node.js, Python, Rust, Go, Java) and provides intelligent analysis. Claude Code optimized - run 'welcome' after inst

403 lines (315 loc) โ€ข 11.6 kB
# Code Automation ๐Ÿš€ **Universal anti-compaction system with perfect recovery capabilities for Claude Code projects** > โš ๏ธ **Note**: This package is specifically designed for Claude Code AI assistant sessions and will not work with other AI tools (ChatGPT, Copilot, Cursor, etc.). [![npm version](https://badge.fury.io/js/claude-code-automation.svg)](https://badge.fury.io/js/claude-code-automation) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) ## ๐ŸŒŸ Latest Features (v3.0.6) ### ๐Ÿ› **FIXED: Critical Installation Bug (v3.0.6)** - **โœ… Complete File Installation** - Fixed missing anti-truncation-guard.js file during installation - **๐Ÿ› ๏ธ All NPM Scripts Work** - Users can now run all automation commands without module errors - **๐ŸŽฏ Immediate Fix** - Resolves "Cannot find module" error for automation:guard command ### ๐Ÿ› **FIXED: Installation Issues (v3.0.2)** - **โœ… Reliable Installation** - Fixed critical bug where automation files weren't copied - **๐Ÿ” Enhanced Error Reporting** - Clear feedback when installation fails - **๐Ÿ“Š Detailed Logging** - See exactly what's happening during installation - **โšก Fail-Fast Behavior** - Installation stops immediately with helpful error messages ### ๐Ÿ”’ **Enterprise Security (v3.0.0)** - **๐Ÿ›ก๏ธ SecureProcessManager** - Enterprise-grade process security system - **โš”๏ธ Command Injection Prevention** - Blocks dangerous shell patterns (`;`, `&&`, `||`, `|`, etc.) - **๐Ÿ“Š Resource Limits** - Process count (5 max), memory (512MB), timeout (2min) enforcement - **๐Ÿ” Process Isolation** - Secure project-level process management - **๐ŸŽฏ Command Whitelisting** - Only allow safe npm, git, node operations - **๐Ÿ“ฑ Verbose Mode** - `--verbose` flag for detailed operation feedback ### ๐Ÿง  **Core Features** - **๐Ÿ›ก๏ธ Anti-Truncation Guard** - Prevents context truncation in real-time - **๐Ÿ” Compaction Risk Analyzer** - Predicts and prevents compaction events - **โšก Live Preservation Engine** - Continuous context monitoring - **๐ŸŽฏ Advanced Recovery System** - Comprehensive project reconstruction - **๐Ÿ“Š Development Session Tracker** - Maintains session continuity - **๐Ÿง  Enhanced Context Analysis** - Deep project understanding ## ๐ŸŽฏ The Problem This Solves **Context Loss** is the #1 problem when working with Claude Code: - โŒ Long sessions lose context due to token limits - โŒ Complex projects get "compacted" and lose detail - โŒ Recovery is manual and error-prone - โŒ Progress gets lost between sessions ## โœ… The Solution **Code Automation** provides: - โœ… **Fixed critical installation bug** - All automation files now install correctly (v3.0.6) - โœ… **Fixed installation issues** - Reliable file copying and clear error messages (v3.0.2) - โœ… **Enterprise-grade security** - Process isolation, command validation, resource limits - โœ… **Automatic context preservation** every 30 minutes - โœ… **Advanced project recovery** from any state - โœ… **Real-time compaction protection** - โœ… **Professional user experience** with verbose feedback - โœ… **Zero-configuration setup** - โœ… **Reliable automation** ## ๐Ÿš€ Quick Start ### Installation ```bash # Global installation (recommended) npm install -g claude-code-automation # โš ๏ธ IMPORTANT: NPM doesn't show post-install messages for global packages # Run this command immediately after install: welcome # Or get detailed help code-automation help # Or local installation npm install claude-code-automation --save-dev ``` ### Setup Your Project ```bash # Navigate to your project cd your-project # Install automation system claude-code-automation install # Start protection immediately (with verbose feedback) code-automation --verbose preserve # Or use npm scripts npm run automation:preserve ``` ## ๐Ÿ“‹ Available Commands ### CLI Commands (Global) ```bash claude-code-automation install # Setup in current project code-automation --verbose preserve # Preserve current context (with detailed feedback) code-automation --verbose recover # Recover from backup (with detailed feedback) code-automation --verbose analyze # Analyze project state (with detailed feedback) preserve # Quick preserve (silent) recover # Quick recover (silent) analyze # Quick analyze (silent) inject # Inject into existing project ``` ### ๐Ÿ”’ Security Options ```bash code-automation --verbose [command] # Enable detailed security feedback code-automation --quiet [command] # Suppress non-essential output ``` ### NPM Scripts (Project) ```bash npm run automation:preserve # Preserve current state npm run automation:recover # Recover from latest backup npm run automation:analyze # Analyze project health npm run automation:daily # Run full automation cycle npm run automation:guard # Start anti-truncation guard ``` ## ๐Ÿ”ง Core Features ### ๐Ÿ›ก๏ธ Anti-Truncation Guard Prevents context loss before it happens: ```bash npm run automation:guard ``` - Monitors token usage in real-time - Triggers preservation before limits - Maintains conversation continuity ### ๐Ÿ” Compaction Risk Analyzer Predicts when compaction will occur: - Analyzes conversation patterns - Calculates risk scores - Proactive preservation triggers ### โšก Live Preservation Engine Continuous background protection: - Auto-saves every 30 minutes - Incremental state updates - Zero performance impact ### ๐ŸŽฏ Advanced Recovery System Comprehensive project restoration: ```bash recover # Attempts to restore project state ``` - Reconstructs complete project state - Restores all decisions and context - Maintains development history ## ๐Ÿ”’ Enterprise Security (v3.0.0) ### ๐Ÿ›ก๏ธ SecureProcessManager - **Process Isolation**: Each project runs in isolated context - **Resource Limits**: Max 5 processes, 512MB memory, 2-minute timeouts - **Command Whitelisting**: Only npm, yarn, pnpm, node, git allowed - **Input Sanitization**: Blocks dangerous patterns: `;`, `&&`, `||`, `|`, `\``, `$`, `>`, `<`, `&` ### โš”๏ธ Security Features ```bash # Secure command execution with validation code-automation --verbose preserve # Shows security decisions # Process resource monitoring code-automation analyze # Displays security status # Safe automation without global process hijacking npm run automation:daily # Uses secure process management ``` ### ๐Ÿ” What's Protected - โœ… **Command Injection Prevention** - All user input validated - โœ… **Process Resource Limits** - Prevents system overload - โœ… **Path Traversal Protection** - Secure file operations only - โœ… **Process Cleanup** - Automatic resource cleanup on exit - โœ… **Timeout Enforcement** - No runaway processes ### ๐Ÿšจ Breaking Changes in v3.0.0 - All process execution now goes through SecureProcessManager - Stricter command validation may block some edge cases - Process limits enforced (upgrade from unlimited processes) - More restrictive input validation for enhanced security ## ๐Ÿ“Š Usage Examples ### Basic Project Setup ```bash # Install globally npm install -g claude-code-automation # Setup new project mkdir my-claude-project cd my-claude-project claude-code-automation install # Start development with protection npm run automation:preserve ``` ### Recovering Lost Context ```bash # If you lose context during development recover # Or use NPM script npm run automation:recover # Verify recovery npm run automation:analyze ``` ### Continuous Protection ```bash # Start anti-truncation guard npm run automation:guard # Run daily maintenance npm run automation:daily # Check project health npm run automation:analyze ``` ## ๐Ÿ—๏ธ Architecture ### Core Components - **Context Preservation Engine** - State capture and storage - **Auto Recovery System** - Intelligent project reconstruction - **Live Preservation Engine** - Real-time monitoring - **Anti-Truncation Guard** - Proactive protection - **Compaction Risk Analyzer** - Predictive analysis - **Development Session Tracker** - Session continuity ### File Structure ``` your-project/ โ”œโ”€โ”€ scripts/automation/ # Automation scripts โ”œโ”€โ”€ docs/automation/ # Generated documentation โ”œโ”€โ”€ docs/state/ # Project state snapshots โ”œโ”€โ”€ docs/recovery/ # Recovery instructions โ””โ”€โ”€ package.json # Updated with scripts ``` ## โš™๏ธ Configuration Configuration is automatic, but can be customized: ```json { "version": "1.0.0", "enabled": true, "features": { "contextPreservation": true, "antiTruncation": true, "livePreservation": true, "perfectRecovery": true, "riskAnalysis": true, "sessionTracking": true }, "settings": { "preservationInterval": 1800000, "maxBackups": 50, "compressionEnabled": true, "verboseLogging": false } } ``` ## ๐Ÿงช Testing ```bash # Test installation npm test # Verify integrity npm run verify # Test recovery system code-automation recover --verify ``` ## ๐Ÿ“ˆ Benefits ### For Developers - โœ… **Never lose progress** again - โœ… **Seamless session continuity** - โœ… **Instant project recovery** - โœ… **Zero maintenance required** ### For Teams - โœ… **Consistent project state** - โœ… **Reliable handoffs** - โœ… **Automated documentation** - โœ… **Reduced onboarding time** ## ๐Ÿ”„ Upgrading ```bash # Upgrade globally npm install -g claude-code-automation@latest # Update existing projects cd your-project claude-code-automation install ``` **Latest features are automatically enabled!** ## ๐Ÿ› Troubleshooting ### Common Issues **Installation fails (Fixed in v3.0.6):** ```bash # v3.0.6+ ensures all automation files are copied during installation # v3.0.2+ provides clear error messages if installation fails claude-code-automation install # If you see "Failed to copy automation files": # 1. Check npm permissions # 2. Try reinstalling the package npm uninstall -g claude-code-automation npm install -g claude-code-automation # Alternative: Use npx npx claude-claude-code-automation install ``` **Files not copied to .automation/ directory:** ```bash # v3.0.2+ shows detailed logging during installation # Look for these messages: # โœ… Copied: context-preservation.js # โœ… All 4 automation files copied successfully # If files are missing, check: ls -la .automation/ # Should contain: context-preservation.js, auto-recovery.js, etc. ``` **Recovery doesn't work:** ```bash # Verify backup exists ls docs/state/ # Force recovery recover --force # Check integrity npm run verify ``` **Context still lost:** ```bash # Enable verbose logging npm run automation:preserve -- --verbose # Check risk analysis npm run automation:analyze ``` ## ๐Ÿ“š Advanced Usage ### Custom Preservation Intervals ```javascript // In your project const preservation = require('claude-code-automation'); preservation.setInterval(15 * 60 * 1000); // 15 minutes ``` ### Integration with CI/CD ```yaml # .github/workflows/preserve.yml name: Context Preservation on: [push, pull_request] jobs: preserve: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - run: npm install -g claude-code-automation - run: preserve ``` ## ๐Ÿค Contributing 1. Fork the repository 2. Create a feature branch 3. Add tests for new functionality 4. Submit a pull request ## ๐Ÿ“„ License MIT License - see [LICENSE](LICENSE)