diff --git a/ACTION-PLAN.md b/ACTION-PLAN.md deleted file mode 100644 index cbd03e72..00000000 --- a/ACTION-PLAN.md +++ /dev/null @@ -1,167 +0,0 @@ -# Action Plan: Issues & PRs Cleanup -Generated: 2025-12-12 - -## Phase 1: Immediate Cleanup (Today) - -### Close Obsolete PRs - -- [ ] **#255** - Close PR "Fix PM2 worker MODULE_NOT_FOUND" - - Reason: v7.1.0 removed PM2 entirely, this fix is no longer relevant - - Comment: Explain that v7.1.0 migration to Bun eliminated PM2 dependency - -- [ ] **#206** - Close or request update on "Harden worker startup" - - Reason: Contains PM2-specific code that no longer exists - - Comment: Ask author if they want to update for Bun architecture, otherwise close as obsolete - -### Close/Update Fixed Issues - -- [ ] **#213** - Comment and close "Windows endless process spawning" - - Reason: v7.1.0 Bun migration eliminated PM2 process management - - Comment: Ask user to verify fix on v7.1.0, explain PM2 removal resolved issue - -- [ ] **#229** - Close as duplicate - - Reason: Duplicate of #227 (upstream Claude Code bug) - - Comment: Direct to #227 for full details and workaround - -- [ ] **#211** - Answer and close "Cursor IDE support question" - - Reason: Product question, not a bug report - - Comment: Explain focus is Claude Code, but plugin architecture may allow future expansion - -### Critical Bug Follow-Up - -- [ ] **#254** - Follow up on "Worker API fetch failed" - - Current status: Asked about PM2 logs (pre-v7.1.0 comment) - - Action: Update comment asking: - - What version of claude-mem are you running? - - If pre-v7.1.0: Please upgrade to v7.1.0 which fixes PM2 issues - - If v7.1.0+: Run troubleshoot skill and share logs - -## Phase 2: High-Priority Merges (This Week) - -### Security & Critical Fixes - -- [ ] **#236** - Review and merge "Localhost-only binding" πŸ”’ PRIORITY - - Impact: Security improvement (fixes network exposure) - - Status: 156 additions, all tests pass (42/42) - - Action: Final review, merge, update CHANGELOG - -- [ ] **#212** - Review and merge "Windows path quoting fix" - - Impact: Fixes Windows usernames with spaces - - Status: 6 lines changed, minimal risk - - Action: Quick cross-platform test, merge - -### Major Features (Maintainer-Authored) - -- [ ] **#225** - Review and merge "Export/Import scripts" - - Impact: Enables backup/restore, partially addresses #233 - - Status: 927 additions, extensively tested by maintainer - - Action: Final review, merge, update docs - -- [ ] **#250** - Review and merge "README translations" - - Impact: International user onboarding (22 languages) - - Status: 10,209 additions (massive but low-risk) - - Action: Spot-check a few translations, merge - -### User-Requested Features - -- [ ] **#252** - Test and merge "Execution traces" (addresses #194) - - Impact: Shows tools/skills/MCPs in UI bubbles - - Status: 383 additions, comprehensive implementation - - Action: Test database migration, API endpoints, UI display - -- [ ] **#251** - Test and merge "Plan file context" (addresses #180) - - Impact: Injects last plan file into context - - Status: 85 additions, follows existing patterns - - Action: Test with real plan files, verify toggle works - -## Phase 3: Review & Consider (Next Week) - -### Quality Enhancements - -- [ ] **#230** - Review "Multi-language support" (addresses #228) - - Impact: Observations/summaries in user's language - - Status: 157 additions, Korean screenshot provided - - Action: Review prompt changes carefully, test with multiple languages - -- [ ] **#226** - Review "CLAUDE_CONFIG_DIR support" - - Impact: Supports non-standard Claude installations - - Status: 10 additions, minimal change - - Action: Test with custom config directory, merge if working - -### Developer Experience - -- [ ] **#216** - Review "Makefile shortcuts" - - Impact: DX improvement for contributors - - Status: 1,085 additions - - Priority: Low (not urgent) - - Action: Review when time permits - -## Phase 4: Issue Follow-Ups (Ongoing) - -### Awaiting User Verification - -- [ ] **#209** - Follow up if no response on Windows worker startup - - Status: Already commented asking for v7.1.0 verification - - Action: Close if verified fixed, or investigate if still broken - -- [ ] **#231** - Follow up if no response on module resolution - - Status: Already commented asking for v7.1.0 verification - - Action: Close if verified fixed, or investigate if still broken - -### Upstream Bugs (Keep Open) - -- [ ] **#227** - Keep open as documented upstream bug - - Reason: Claude Code CLI uses invalid Windows paths - - Action: No action needed, workaround documented - -### Active Bugs (Investigate) - -- [ ] **#208** - Investigate "Windows console windows appearing" - - Priority: Medium (cosmetic but annoying) - - Action: Reproduce on Windows, identify root cause - -## Phase 5: Future Feature Planning - -### Feature Requests Without PRs - -- [ ] **#240** - Plan "Move MCP scaffolding to separate file" - - Type: Internal refactoring - - Priority: Low - - Action: Design approach when time permits - -- [ ] **#239** - Plan "Track git branch as metadata" - - Type: Context enhancement - - Priority: Medium - - Action: Design schema changes, discuss approach - -- [ ] **#215** - Plan "PreCompact event hook" - - Type: Power user feature - - Priority: Low - - Action: Evaluate use cases, design API - -- [ ] **#233** - Plan "Multi-device sync" (partial solution exists) - - Type: Major feature - - Note: PR #225 provides export/import, full sync is more complex - - Action: Determine if export/import is sufficient, or plan cloud sync - -## Summary - -### Quick Wins (Do Today) -- Close 2 obsolete PRs (#255, #206) -- Close 3 resolved/duplicate issues (#213, #229, #211) -- Follow up on critical bug (#254) - -### High-Impact Merges (This Week) -- Merge security fix (#236) -- Merge 2 simple fixes (#212, #225) -- Merge 2 major features (#250, #252, #251) - -### Expected Impact -- **Security**: Localhost-only by default -- **Functionality**: Export/import, execution traces, plan context -- **UX**: Multi-language support, Windows fixes -- **Clarity**: Clean backlog, remove PM2 confusion - ---- - -**Next Review**: After Phase 2 completion, reassess remaining items diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 15449b08..00000000 --- a/SECURITY.md +++ /dev/null @@ -1,186 +0,0 @@ -# Security Policy - -## Reporting a Vulnerability - -If you discover a security vulnerability in claude-mem, please report it by: - -1. **DO NOT** create a public GitHub issue -2. Email the maintainer directly with details -3. Include steps to reproduce, impact assessment, and suggested fixes if possible - -We take security seriously and will respond to valid reports within 48 hours. - -## Security Measures - -### Command Injection Prevention - -Claude-mem executes system commands for git operations and process management. We have implemented comprehensive protections against command injection: - -#### Safe Command Execution -- **Array-based Arguments:** All commands use array-based arguments to prevent shell interpretation -- **No Shell Execution:** `shell: false` is explicitly set for all spawn operations involving user input -- **Input Validation:** All user-controlled parameters are validated before use - -#### Example Safe Pattern -```typescript -// βœ… SAFE: Array-based arguments with validation -if (!isValidBranchName(userInput)) { - throw new Error('Invalid input'); -} -spawnSync('git', ['checkout', userInput], { shell: false }); - -// ❌ UNSAFE: Never do this -execSync(`git checkout ${userInput}`); -``` - -### Input Validation - -All user-controlled inputs are validated using whitelists and strict patterns: - -- **Branch Names:** Must match `/^[a-zA-Z0-9][a-zA-Z0-9._/-]*$/` and not contain `..` -- **Port Numbers:** Must be numeric and within range 1024-65535 -- **File Paths:** All paths are joined using `path.join()` to prevent traversal - -### Process Management - -- **PID File Protection:** Process IDs are stored in user's data directory (`~/.claude-mem/`) -- **Port Validation:** Worker port is validated before binding -- **Health Checks:** Worker health is verified before processing requests - -### Privacy Controls - -Claude-mem includes dual-tag system for content privacy: - -- `content` - User-level privacy (prevents storage) -- `content` - System-level tag (prevents recursive storage) - -Tags are stripped at the hook layer before data reaches worker/database. - -## Security Audit History - -### 2025-12-16: Command Injection Vulnerability (Issue #354) -- **Severity:** CRITICAL -- **Status:** RESOLVED -- **Details:** See [SECURITY_AUDIT_REPORT.md](./SECURITY_AUDIT_REPORT.md) -- **Affected Versions:** All versions prior to fix -- **Fixed In:** Current version -- **Vulnerabilities Found:** 3 -- **Vulnerabilities Fixed:** 3 - -**Summary of Fixes:** -1. Replaced string interpolation with array-based arguments in `BranchManager.ts` -2. Added `isValidBranchName()` validation function -3. Removed unnecessary shell usage in `bun-path.ts` -4. Created comprehensive security test suite - -## Security Best Practices for Contributors - -### When Adding Command Execution - -1. **NEVER use shell with user input:** - ```typescript - // ❌ NEVER - execSync(`command ${userInput}`); - spawn('command', [...], { shell: true }); - - // βœ… ALWAYS - spawnSync('command', [userInput], { shell: false }); - ``` - -2. **ALWAYS validate user input:** - ```typescript - if (!isValidInput(userInput)) { - throw new Error('Invalid input'); - } - ``` - -3. **Use array-based arguments:** - ```typescript - // ❌ NEVER - execSync(`git ${command} ${arg}`); - - // βœ… ALWAYS - spawnSync('git', [command, arg], { shell: false }); - ``` - -4. **Explicitly set shell: false:** - ```typescript - spawnSync('command', args, { shell: false }); - ``` - -### When Adding User Input - -1. **Whitelist validation** over blacklist -2. **Strict regex patterns** for format validation -3. **Type checking** for expected data types -4. **Range validation** for numeric inputs -5. **Length limits** for string inputs - -### Code Review Checklist - -Before submitting a PR with command execution or user input handling: - -- [ ] No `execSync` with string interpolation or template literals -- [ ] No `shell: true` when user input is involved -- [ ] All spawn/spawnSync calls use array arguments -- [ ] Input validation is present for all user-controlled parameters -- [ ] Security tests are added for new attack vectors -- [ ] Code follows patterns in [SECURITY_AUDIT_REPORT.md](./SECURITY_AUDIT_REPORT.md) - -## Dependencies - -We regularly audit dependencies for vulnerabilities: - -- **npm audit:** Run before each release -- **Dependabot:** Enabled for automatic security updates -- **Manual Review:** Critical dependencies reviewed quarterly - -## Data Storage - -Claude-mem stores data locally in `~/.claude-mem/`: - -- **Database:** SQLite3 at `~/.claude-mem/claude-mem.db` -- **Vector Store:** Chroma at `~/.claude-mem/chroma/` -- **Logs:** `~/.claude-mem/logs/` -- **Settings:** `~/.claude-mem/settings.json` - -All data remains on the user's machine. No telemetry or external data transmission. - -## Permissions - -Claude-mem requires: - -- **File System:** Read/write to `~/.claude-mem/` and `~/.claude/plugins/` -- **Network:** HTTP server on localhost (default port 37777) -- **Process Management:** Spawn worker processes, manage PIDs - -No elevated privileges (root/administrator) are required. - -## Secure Defaults - -- **Worker Host:** Binds to `127.0.0.1` by default (localhost only) -- **Worker Port:** User-configurable, validates range 1024-65535 -- **Log Level:** INFO by default (no sensitive data in logs) -- **Privacy Tags:** Auto-strips private content before storage - -## Updates - -Security patches are released as soon as possible after discovery. Users should: - -1. Keep claude-mem updated to the latest version -2. Monitor GitHub releases for security announcements -3. Review [CHANGELOG.md](./CHANGELOG.md) for security-related changes - -## Questions? - -For security-related questions (non-vulnerabilities), please: - -1. Check [SECURITY_AUDIT_REPORT.md](./SECURITY_AUDIT_REPORT.md) for technical details -2. Review code comments in security-critical files -3. Open a GitHub Discussion (not an Issue) for general security questions - ---- - -**Last Updated:** 2025-12-16 -**Last Audit:** 2025-12-16 (Issue #354) -**Next Scheduled Audit:** 2025-03-16 diff --git a/SECURITY_AUDIT_REPORT.md b/SECURITY_AUDIT_REPORT.md deleted file mode 100644 index 790f259f..00000000 --- a/SECURITY_AUDIT_REPORT.md +++ /dev/null @@ -1,403 +0,0 @@ -# Security Audit Report - Command Injection Prevention - -**Date:** 2025-12-16 -**Issue:** #354 - Command Injection Vulnerability -**Severity:** CRITICAL -**Status:** RESOLVED - -## Executive Summary - -A comprehensive security audit was conducted to identify and fix command injection vulnerabilities in the claude-mem codebase. The primary vulnerability was found in `BranchManager.ts` where user-supplied branch names were directly interpolated into shell commands without validation or sanitization. - -### Vulnerabilities Found: 3 -### Vulnerabilities Fixed: 3 -### Files Modified: 2 -### Tests Added: 1 comprehensive test suite - ---- - -## Critical Vulnerabilities (Fixed) - -### 1. BranchManager.ts - Command Injection via Branch Name - -**File:** `src/services/worker/BranchManager.ts` -**Lines:** 156, 159, 164, 224 (original line numbers) -**Severity:** CRITICAL -**Attack Vector:** User-controlled branch name parameter - -#### Original Vulnerable Code: -```typescript -// VULNERABLE: Direct string interpolation -function execGit(command: string): string { - return execSync(`git ${command}`, { ... }); -} - -// Called with user input: -execGit(`checkout ${targetBranch}`); // Line 156 -execGit(`checkout -b ${targetBranch} origin/${targetBranch}`); // Line 159 -execGit(`pull origin ${targetBranch}`); // Line 164 -execGit(`pull origin ${info.branch}`); // Line 224 -``` - -#### Exploitation Example: -```bash -targetBranch = "main; rm -rf /" -# Results in: git checkout main; rm -rf / -``` - -#### Fix Applied: -1. **Input Validation:** Added `isValidBranchName()` function to validate branch names using regex -2. **Array-based Arguments:** Replaced `execSync` string interpolation with `spawnSync` array arguments -3. **Shell Disabled:** Explicitly set `shell: false` to prevent shell interpretation - -```typescript -// SECURE: Array-based arguments with validation -function isValidBranchName(branchName: string): boolean { - if (!branchName || typeof branchName !== 'string') { - return false; - } - const validBranchRegex = /^[a-zA-Z0-9][a-zA-Z0-9._/-]*$/; - return validBranchRegex.test(branchName) && !branchName.includes('..'); -} - -function execGit(args: string[]): string { - const result = spawnSync('git', args, { - cwd: INSTALLED_PLUGIN_PATH, - encoding: 'utf-8', - timeout: GIT_COMMAND_TIMEOUT_MS, - windowsHide: true, - shell: false // CRITICAL: Never use shell with user input - }); - // ... error handling - return result.stdout.trim(); -} - -// Called with validated input: -if (!isValidBranchName(targetBranch)) { - return { success: false, error: 'Invalid branch name' }; -} -execGit(['checkout', targetBranch]); -``` - ---- - -### 2. BranchManager.ts - NPM Command Injection - -**File:** `src/services/worker/BranchManager.ts` -**Lines:** 173, 231 (original line numbers) -**Severity:** MEDIUM -**Attack Vector:** Indirect (through branch switching workflow) - -#### Original Vulnerable Code: -```typescript -// VULNERABLE: Shell execution -function execShell(command: string): string { - return execSync(command, { ... }); -} - -execShell('npm install', NPM_INSTALL_TIMEOUT_MS); -``` - -#### Fix Applied: -Created dedicated `execNpm()` function using array-based arguments: - -```typescript -function execNpm(args: string[], timeoutMs: number = NPM_INSTALL_TIMEOUT_MS): string { - const isWindows = process.platform === 'win32'; - const npmCmd = isWindows ? 'npm.cmd' : 'npm'; - - const result = spawnSync(npmCmd, args, { - cwd: INSTALLED_PLUGIN_PATH, - encoding: 'utf-8', - timeout: timeoutMs, - windowsHide: true, - shell: false // CRITICAL: Never use shell - }); - // ... error handling - return result.stdout.trim(); -} - -execNpm(['install'], NPM_INSTALL_TIMEOUT_MS); -``` - ---- - -### 3. bun-path.ts - Unnecessary Shell Usage on Windows - -**File:** `src/utils/bun-path.ts` -**Line:** 26 (original) -**Severity:** LOW -**Attack Vector:** None (command is hardcoded), but violates security best practices - -#### Original Code: -```typescript -const result = spawnSync('bun', ['--version'], { - encoding: 'utf-8', - stdio: ['pipe', 'pipe', 'pipe'], - shell: isWindows // Unnecessary shell usage -}); -``` - -#### Fix Applied: -```typescript -const result = spawnSync('bun', ['--version'], { - encoding: 'utf-8', - stdio: ['pipe', 'pipe', 'pipe'], - shell: false // SECURITY: No need for shell -}); -``` - ---- - -## Safe Code Patterns Verified - -The following files were audited and confirmed to be safe from command injection: - -### 1. ProcessManager.ts -```typescript -// SAFE: Array-based arguments, no user input -const child = spawn(bunPath, [script], { - detached: true, - stdio: ['ignore', 'pipe', 'pipe'], - env: { ...process.env, CLAUDE_MEM_WORKER_PORT: String(port) }, - cwd: MARKETPLACE_ROOT, - ...(isWindows && { windowsHide: true }) -}); -``` - -**Why Safe:** -- Uses array-based arguments -- No shell execution -- Port parameter is validated (lines 29-35) before use -- `bunPath` comes from trusted utility function - -### 2. SDKAgent.ts -```typescript -// SAFE: Hardcoded command, no user input -execSync(process.platform === 'win32' ? 'where claude' : 'which claude', { - encoding: 'utf8', - windowsHide: true -}) -``` - -**Why Safe:** -- Command is completely hardcoded (no user input) -- Used only for finding Claude executable in PATH - -### 3. paths.ts -```typescript -// SAFE: Hardcoded command, no user input -const gitRoot = execSync('git rev-parse --show-toplevel', { - cwd: process.cwd(), - encoding: 'utf8', - stdio: ['pipe', 'pipe', 'ignore'], - windowsHide: true -}); -``` - -**Why Safe:** -- Command is completely hardcoded -- No user input in command or arguments -- `cwd` is from `process.cwd()` (trusted source) - -### 4. worker-utils.ts -```typescript -// SAFE: Hardcoded arguments -spawnSync('pm2', ['delete', 'claude-mem-worker'], { stdio: 'ignore' }); -``` - -**Why Safe:** -- Array-based arguments -- All arguments are hardcoded strings -- No user input - ---- - -## Security Test Suite - -Created comprehensive test suite at `tests/security/command-injection.test.ts` with: - -- **50+ test cases** covering various injection attempts -- **Platform-specific tests** for Windows and Unix command separators -- **Edge case testing** (Unicode control chars, URL encoding, long inputs) -- **Regression tests** for Issue #354 -- **Code verification tests** to ensure no shell usage remains - -### Key Test Categories: - -1. **Branch Name Validation** - - Shell metacharacters (`; && || | & $ \` \n \r`) - - Directory traversal (`..`) - - Invalid starting characters (`. - /`) - - Valid branch names (main, beta, feature/*, etc.) - -2. **Command Array Safety** - - Verifies no string interpolation in git commands - - Verifies `shell: false` is set - - Verifies array-based arguments are used - -3. **Cross-platform Attacks** - - Windows-specific injections (`& type C:\...`) - - Unix-specific injections (`; cat /etc/shadow`) - -4. **Edge Cases** - - Null/undefined/empty inputs - - URL encoding attempts - - Unicode control characters - - Very long inputs (1000+ chars) - ---- - -## Security Best Practices Applied - -### 1. Never Use Shell with User Input -```typescript -// ❌ NEVER DO THIS -execSync(`git ${userInput}`); -spawn('git', [...], { shell: true }); - -// βœ… ALWAYS DO THIS -spawnSync('git', [userInput], { shell: false }); -``` - -### 2. Always Validate User Input -```typescript -// ❌ NEVER DO THIS -execGit(['checkout', targetBranch]); - -// βœ… ALWAYS DO THIS -if (!isValidBranchName(targetBranch)) { - return { success: false, error: 'Invalid input' }; -} -execGit(['checkout', targetBranch]); -``` - -### 3. Use Array-based Arguments -```typescript -// ❌ NEVER DO THIS -execSync(`git checkout ${branch}`); - -// βœ… ALWAYS DO THIS -spawnSync('git', ['checkout', branch], { shell: false }); -``` - -### 4. Explicit shell: false -```typescript -// ❌ BAD (shell might be enabled by default in some cases) -spawnSync('git', ['checkout', branch]); - -// βœ… GOOD (explicit is better) -spawnSync('git', ['checkout', branch], { shell: false }); -``` - ---- - -## Verification Steps - -### Manual Testing -```bash -# Run security test suite -bun test tests/security/command-injection.test.ts - -# Expected result: All tests pass -``` - -### Code Review Checklist -- [x] No `execSync` with string interpolation -- [x] No `shell: true` with user input -- [x] All spawn/spawnSync calls use array arguments -- [x] Input validation on all user-controlled parameters -- [x] Security test coverage for all attack vectors - -### Automated Scanning -```bash -# Check for potential vulnerabilities -grep -rn "execSync.*\${" src/ -grep -rn "shell:\s*true" src/ -grep -rn "exec(\`" src/ - -# Expected result: No matches (or only false positives in comments) -``` - ---- - -## Impact Assessment - -### Before Fix: -- **Risk:** Remote code execution via branch name parameter -- **Attack Surface:** Any UI or API endpoint accepting branch names -- **Affected Functions:** `switchBranch()`, `pullUpdates()` -- **Exploitability:** High (trivial to exploit) - -### After Fix: -- **Risk:** None -- **Attack Surface:** Zero (input validation + safe execution) -- **Affected Functions:** All secured -- **Exploitability:** None - ---- - -## Recommendations - -### Immediate Actions -1. βœ… Apply all fixes from this audit -2. βœ… Run security test suite -3. βœ… Deploy to production immediately (critical security fix) - -### Long-term Actions -1. **Code Review Process:** - - Add security checklist to PR template - - Require review of all `exec*` and `spawn*` calls - - Flag any `shell: true` usage for security review - -2. **Automated Scanning:** - - Add pre-commit hooks to detect unsafe patterns - - Integrate SAST (Static Application Security Testing) tools - - Run security tests in CI/CD pipeline - -3. **Developer Training:** - - Document secure coding practices for command execution - - Share this audit report with the team - - Add security section to CONTRIBUTING.md - -4. **Regular Audits:** - - Quarterly security audits of all exec/spawn usage - - Review any new dependencies for vulnerabilities - - Keep security test suite updated with new attack vectors - ---- - -## Files Modified - -### /src/services/worker/BranchManager.ts -- Added `isValidBranchName()` validation function -- Replaced `execGit()` with safe implementation using `spawnSync` -- Replaced `execShell()` with `execNpm()` using safe implementation -- Added validation to `switchBranch()` function -- Added validation to `pullUpdates()` function -- Updated all git command calls to use array arguments - -### /src/utils/bun-path.ts -- Changed `shell: isWindows` to `shell: false` - -### /tests/security/command-injection.test.ts (NEW) -- Comprehensive security test suite with 50+ test cases - ---- - -## Conclusion - -All command injection vulnerabilities have been identified and fixed. The codebase now follows security best practices for command execution: - -1. **No shell execution** with user input -2. **Array-based arguments** for all external commands -3. **Input validation** on all user-controlled parameters -4. **Comprehensive test coverage** for security scenarios - -The risk of command injection is now **ELIMINATED** in the claude-mem codebase. - ---- - -**Audited by:** Agent A (AI Security Audit) -**Date:** 2025-12-16 -**Next Audit:** Recommended within 3 months diff --git a/docs/PM2-TO-BUN-MIGRATION.md b/docs/PM2-TO-BUN-MIGRATION.md deleted file mode 100644 index 1e978cc2..00000000 --- a/docs/PM2-TO-BUN-MIGRATION.md +++ /dev/null @@ -1,1508 +0,0 @@ -# PM2 to Bun Migration: Complete Technical Documentation - -**Version**: 7.1.0 -**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