From 8ed2967f6f42fa1563c26ca89cb87d4942417b7f Mon Sep 17 00:00:00 2001 From: Docker Config Backup Date: Tue, 29 Jul 2025 14:27:28 +0200 Subject: [PATCH] Save before creating restore point: Session start MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Auto-saved at 2025-07-29 14:27:28 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- ecosystem.config.js | 44 ++++++++++++++++ logs/auto-commit.error.log | 2 + logs/auto-commit.log | 22 ++++++++ logs/auto-commit.out.log | 20 +++++++ package.json | 12 ++++- start-services.sh | 103 +++++++++++++++++++++++++++++++++++++ watch-and-commit.js | 10 +++- 7 files changed, 211 insertions(+), 2 deletions(-) create mode 100644 ecosystem.config.js create mode 100644 logs/auto-commit.error.log create mode 100644 logs/auto-commit.log create mode 100644 logs/auto-commit.out.log create mode 100755 start-services.sh diff --git a/ecosystem.config.js b/ecosystem.config.js new file mode 100644 index 0000000..66ad93f --- /dev/null +++ b/ecosystem.config.js @@ -0,0 +1,44 @@ +module.exports = { + apps: [ + { + name: 'timeshift-auto-commit', + script: './watch-and-commit.js', + cwd: '/home/klas/timeshift', + watch: false, // We don't want PM2 to restart on file changes since we're watching files ourselves + autorestart: true, + max_restarts: 10, + min_uptime: '10s', + restart_delay: 5000, + env: { + NODE_ENV: 'development', + PWD: '/home/klas/timeshift' + }, + log_file: '/home/klas/timeshift/logs/auto-commit.log', + out_file: '/home/klas/timeshift/logs/auto-commit.out.log', + error_file: '/home/klas/timeshift/logs/auto-commit.error.log', + log_date_format: 'YYYY-MM-DD HH:mm:ss Z', + merge_logs: true, + max_memory_restart: '200M' + }, + { + name: 'timeshift-dev', + script: 'npm', + args: 'run dev', + cwd: '/home/klas/timeshift', + watch: false, + autorestart: true, + max_restarts: 5, + min_uptime: '30s', + restart_delay: 10000, + env: { + NODE_ENV: 'development', + PORT: 3000 + }, + log_file: '/home/klas/timeshift/logs/dev-server.log', + out_file: '/home/klas/timeshift/logs/dev-server.out.log', + error_file: '/home/klas/timeshift/logs/dev-server.error.log', + log_date_format: 'YYYY-MM-DD HH:mm:ss Z', + merge_logs: true + } + ] +}; \ No newline at end of file diff --git a/logs/auto-commit.error.log b/logs/auto-commit.error.log new file mode 100644 index 0000000..1fa1b20 --- /dev/null +++ b/logs/auto-commit.error.log @@ -0,0 +1,2 @@ +2025-07-29 14:27:23 +02:00: (node:489145) [DEP0060] DeprecationWarning: The `util._extend` API is deprecated. Please use Object.assign() instead. +2025-07-29 14:27:23 +02:00: (Use `node --trace-deprecation ...` to show where the warning was created) diff --git a/logs/auto-commit.log b/logs/auto-commit.log new file mode 100644 index 0000000..14be2a6 --- /dev/null +++ b/logs/auto-commit.log @@ -0,0 +1,22 @@ +2025-07-29 14:27:23 +02:00: 🚀 Timeshift Auto-Commit Watcher Started +2025-07-29 14:27:23 +02:00: ========================================== +2025-07-29 14:27:23 +02:00: 📅 Start time: 2025-07-29T12:27:23.269Z +2025-07-29 14:27:23 +02:00: 📁 Watching directories: components, app, lib, styles +2025-07-29 14:27:23 +02:00: 📄 File extensions: .tsx, .ts, .js, .jsx, .css, .scss, .json +2025-07-29 14:27:23 +02:00: ⏱️ Commit delay: 30s +2025-07-29 14:27:23 +02:00: 🚦 Max commits per hour: 10 +2025-07-29 14:27:23 +02:00: 🔧 Process ID: 489145 +2025-07-29 14:27:23 +02:00: ========================================== +2025-07-29 14:27:23 +02:00: 👀 Watching: /home/klas/timeshift/components +2025-07-29 14:27:23 +02:00: 👀 Watching: /home/klas/timeshift/app +2025-07-29 14:27:23 +02:00: 👀 Watching: /home/klas/timeshift/lib +2025-07-29 14:27:23 +02:00: ⚠️ Directory not found: /home/klas/timeshift/styles +2025-07-29 14:27:23 +02:00: 🚀 Auto-commit system ready! Press Ctrl+C to stop. +2025-07-29 14:27:23 +02:00: 📋 Commands available: +2025-07-29 14:27:23 +02:00: ./auto-commit.sh commit [message] +2025-07-29 14:27:23 +02:00: ./auto-commit.sh restore-point [description] +2025-07-29 14:27:23 +02:00: ./auto-commit.sh list +2025-07-29 14:27:23 +02:00: ./auto-commit.sh cleanup +2025-07-29 14:27:23 +02:00: (node:489145) [DEP0060] DeprecationWarning: The `util._extend` API is deprecated. Please use Object.assign() instead. +2025-07-29 14:27:23 +02:00: (Use `node --trace-deprecation ...` to show where the warning was created) +2025-07-29 14:27:28 +02:00: 🔖 Creating restore point... diff --git a/logs/auto-commit.out.log b/logs/auto-commit.out.log new file mode 100644 index 0000000..27bd7d6 --- /dev/null +++ b/logs/auto-commit.out.log @@ -0,0 +1,20 @@ +2025-07-29 14:27:23 +02:00: 🚀 Timeshift Auto-Commit Watcher Started +2025-07-29 14:27:23 +02:00: ========================================== +2025-07-29 14:27:23 +02:00: 📅 Start time: 2025-07-29T12:27:23.269Z +2025-07-29 14:27:23 +02:00: 📁 Watching directories: components, app, lib, styles +2025-07-29 14:27:23 +02:00: 📄 File extensions: .tsx, .ts, .js, .jsx, .css, .scss, .json +2025-07-29 14:27:23 +02:00: ⏱️ Commit delay: 30s +2025-07-29 14:27:23 +02:00: 🚦 Max commits per hour: 10 +2025-07-29 14:27:23 +02:00: 🔧 Process ID: 489145 +2025-07-29 14:27:23 +02:00: ========================================== +2025-07-29 14:27:23 +02:00: 👀 Watching: /home/klas/timeshift/components +2025-07-29 14:27:23 +02:00: 👀 Watching: /home/klas/timeshift/app +2025-07-29 14:27:23 +02:00: 👀 Watching: /home/klas/timeshift/lib +2025-07-29 14:27:23 +02:00: ⚠️ Directory not found: /home/klas/timeshift/styles +2025-07-29 14:27:23 +02:00: 🚀 Auto-commit system ready! Press Ctrl+C to stop. +2025-07-29 14:27:23 +02:00: 📋 Commands available: +2025-07-29 14:27:23 +02:00: ./auto-commit.sh commit [message] +2025-07-29 14:27:23 +02:00: ./auto-commit.sh restore-point [description] +2025-07-29 14:27:23 +02:00: ./auto-commit.sh list +2025-07-29 14:27:23 +02:00: ./auto-commit.sh cleanup +2025-07-29 14:27:28 +02:00: 🔖 Creating restore point... diff --git a/package.json b/package.json index 01e194f..c7e284a 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,17 @@ "auto-commit": "./auto-commit.sh", "watch-commit": "node watch-and-commit.js", "save": "./auto-commit.sh commit", - "restore-point": "./auto-commit.sh restore-point" + "restore-point": "./auto-commit.sh restore-point", + "pm2:start": "pm2 start ecosystem.config.js", + "pm2:stop": "pm2 stop ecosystem.config.js", + "pm2:restart": "pm2 restart ecosystem.config.js", + "pm2:delete": "pm2 delete ecosystem.config.js", + "pm2:logs": "pm2 logs timeshift-auto-commit", + "pm2:status": "pm2 status", + "pm2:monit": "pm2 monit", + "services:start": "pm2 start ecosystem.config.js --only timeshift-auto-commit", + "services:stop": "pm2 stop timeshift-auto-commit", + "services:logs": "pm2 logs timeshift-auto-commit --lines 50" }, "dependencies": { "@radix-ui/react-dialog": "^1.1.14", diff --git a/start-services.sh b/start-services.sh new file mode 100755 index 0000000..664fcd7 --- /dev/null +++ b/start-services.sh @@ -0,0 +1,103 @@ +#!/bin/bash + +# Timeshift Project Services Startup Script +# This script starts the auto-commit watcher and development server using PM2 + +set -e + +echo "🚀 Starting Timeshift Project Services" +echo "========================================" + +# Function to check if PM2 is installed +check_pm2() { + if ! command -v pm2 &> /dev/null; then + echo "❌ PM2 is not installed. Please install it first:" + echo " npm install -g pm2" + exit 1 + fi + echo "✅ PM2 is available" +} + +# Function to start services +start_services() { + echo "" + echo "🔧 Starting services..." + + # Stop any existing services first + pm2 delete timeshift-auto-commit 2>/dev/null || true + pm2 delete timeshift-dev 2>/dev/null || true + + # Start the auto-commit watcher + echo "📁 Starting auto-commit watcher..." + pm2 start ecosystem.config.js --only timeshift-auto-commit + + # Wait a moment for the service to start + sleep 2 + + echo "" + echo "✅ Services started successfully!" + echo "" + + # Show status + pm2 status + + echo "" + echo "📋 Service Management Commands:" + echo " npm run services:logs - View auto-commit logs" + echo " npm run services:stop - Stop auto-commit service" + echo " npm run pm2:status - Check all PM2 services" + echo " npm run pm2:monit - Open PM2 monitoring" + echo "" + echo "🌐 Development Server:" + echo " npm run dev - Start Next.js dev server manually" + echo " npm run pm2:start - Start both services with PM2" + echo "" + echo "💾 Manual Save Commands:" + echo " npm run save - Save changes immediately" + echo " npm run restore-point - Create a restore point" + echo "" +} + +# Function to show logs +show_logs() { + echo "📋 Auto-commit service logs (last 20 lines):" + echo "============================================" + pm2 logs timeshift-auto-commit --lines 20 --nostream +} + +# Main execution +case "$1" in + "logs") + show_logs + ;; + "stop") + echo "🛑 Stopping auto-commit service..." + pm2 stop timeshift-auto-commit + echo "✅ Service stopped" + ;; + "restart") + echo "🔄 Restarting auto-commit service..." + pm2 restart timeshift-auto-commit + echo "✅ Service restarted" + ;; + "status") + pm2 status + ;; + *) + check_pm2 + start_services + + # Option to show logs + echo "👀 Would you like to see the logs? (y/n)" + read -t 10 -n 1 -r + echo + if [[ $REPLY =~ ^[Yy]$ ]]; then + show_logs + fi + ;; +esac + +echo "" +echo "🎯 Auto-commit watcher is now running in the background!" +echo "🔄 Your changes will be automatically saved every 30 seconds." +echo "🛡️ No more lost work when Claude restarts!" \ No newline at end of file diff --git a/watch-and-commit.js b/watch-and-commit.js index ca4daa2..7dc93bb 100755 --- a/watch-and-commit.js +++ b/watch-and-commit.js @@ -19,16 +19,24 @@ class AutoCommitWatcher { this.commitTimeout = null; this.commitsThisHour = 0; this.lastCommitTime = 0; + this.startTime = new Date(); // Reset commit counter every hour setInterval(() => { this.commitsThisHour = 0; + console.log('🔄 Hourly reset: Commit counter reset to 0'); }, 3600000); - console.log('🔍 Auto-commit watcher started'); + // Log startup info + console.log('🚀 Timeshift Auto-Commit Watcher Started'); + console.log('=========================================='); + console.log(`📅 Start time: ${this.startTime.toISOString()}`); console.log(`📁 Watching directories: ${WATCH_DIRS.join(', ')}`); + console.log(`📄 File extensions: ${WATCH_EXTENSIONS.join(', ')}`); console.log(`⏱️ Commit delay: ${COMMIT_DELAY/1000}s`); console.log(`🚦 Max commits per hour: ${MAX_COMMITS_PER_HOUR}`); + console.log(`🔧 Process ID: ${process.pid}`); + console.log('=========================================='); } start() {