From 5d4e71d2ff4053733b33bdca33a5c248429e6584 Mon Sep 17 00:00:00 2001 From: Alex Newman Date: Fri, 12 Dec 2025 20:16:39 -0500 Subject: [PATCH] fix: run PM2 cleanup on all platforms for quality migration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously skipped Windows PM2 cleanup based on assumption that PM2 wasn't used on Windows. However, this left potential orphaned processes. Changes: - Remove platform check (process.platform !== 'win32') - Run PM2 cleanup on Mac/Linux/Windows consistently - Create .pm2-migrated marker on all platforms - Update documentation to reflect cross-platform behavior Rationale: - Quality migration should clean up ALL orphaned processes - Error handling (try/catch) already makes this safe - Even if PM2 had Windows issues, cleanup won't hurt - Consistent behavior across platforms is better UX Impact: - Windows users will get PM2 cleanup on first hook trigger - Marker file now created on Windows (prevents repeated attempts) - No breaking changes (errors caught and ignored) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- docs/PM2-TO-BUN-MIGRATION.md | 1552 +++++++++++++++++++++++++++ plugin/scripts/cleanup-hook.js | 2 +- plugin/scripts/context-hook.js | 4 +- plugin/scripts/new-hook.js | 4 +- plugin/scripts/save-hook.js | 8 +- plugin/scripts/summary-hook.js | 2 +- plugin/scripts/user-message-hook.js | 2 +- src/shared/worker-utils.ts | 2 +- 8 files changed, 1564 insertions(+), 12 deletions(-) create mode 100644 docs/PM2-TO-BUN-MIGRATION.md diff --git a/docs/PM2-TO-BUN-MIGRATION.md b/docs/PM2-TO-BUN-MIGRATION.md new file mode 100644 index 00000000..fa38a049 --- /dev/null +++ b/docs/PM2-TO-BUN-MIGRATION.md @@ -0,0 +1,1552 @@ +# PM2 to Bun Migration: Complete Technical Documentation + +**Version**: 7.0.10+ +**Date**: December 2025 +**Migration Type**: Process Management (PM2 → Bun) + Database Driver (better-sqlite3 → bun:sqlite) + +--- + +## Table of Contents + +1. [Executive Summary](#executive-summary) +2. [Architecture Comparison](#architecture-comparison) +3. [Migration Mechanics](#migration-mechanics) +4. [User Experience Timeline](#user-experience-timeline) +5. [Platform-Specific Behavior](#platform-specific-behavior) +6. [Observable Changes](#observable-changes) +7. [File System State](#file-system-state) +8. [Edge Cases and Troubleshooting](#edge-cases-and-troubleshooting) +9. [Developer Notes](#developer-notes) + +--- + +## Executive Summary + +Claude-mem version 7.0.10 introduces two major architectural migrations: + +1. **Process Management**: PM2 → Custom Bun-based ProcessManager +2. **Database Driver**: better-sqlite3 npm package → bun:sqlite runtime module + +Both migrations are **automatic** and **transparent** to end users. The first time a hook fires after updating to 7.0.10+, the system performs a one-time cleanup of legacy PM2 processes and transitions to the new architecture. + +### Key Benefits + +- **Simplified Dependencies**: Removes PM2 and better-sqlite3 npm packages +- **Improved Cross-Platform Support**: Better Windows compatibility +- **Faster Installation**: No native module compilation required +- **Built-in Runtime**: Leverages Bun's built-in process management and SQLite +- **Reduced Complexity**: Custom ProcessManager is simpler than PM2 integration + +### Migration Impact + +- **Data Preservation**: User data, settings, and database remain unchanged +- **Automatic Cleanup**: Old PM2 processes automatically terminated (all platforms) +- **No User Action Required**: Migration happens automatically on first hook trigger +- **Backward Compatible**: SQLite database format unchanged (only driver changed) + +--- + +## Architecture Comparison + +### Old System (PM2-based) + +#### Process Management (PM2) + +**Component**: PM2 (Process Manager 2) +- **Package**: `pm2` npm dependency +- **Process Name**: `claude-mem-worker` +- **Management**: External PM2 daemon manages lifecycle +- **Discovery**: `pm2 list`, `pm2 describe` commands +- **Auto-restart**: PM2 automatically restarts on crash +- **Logs**: `~/.pm2/logs/claude-mem-worker-*.log` +- **PID File**: `~/.pm2/pids/claude-mem-worker.pid` + +**Lifecycle Commands**: +```bash +pm2 start