Refactor worker management and cleanup hooks

- Removed ensureWorkerRunning calls from multiple hooks (cleanup, context, new, save, summary) to streamline code and avoid unnecessary checks.
- Introduced fixed port usage for worker communication across hooks.
- Enhanced error handling in newHook, saveHook, and summaryHook to provide clearer messages for worker connection issues.
- Updated worker service to start without health checks, relying on PM2 for management.
- Cached Claude executable path to optimize repeated calls.
- Improved logging for better traceability of worker actions and errors.
This commit is contained in:
Alex Newman
2025-11-04 14:21:19 -05:00
parent 37f836b719
commit a46a028ddb
25 changed files with 317 additions and 2914 deletions
+2 -35
View File
@@ -9,44 +9,11 @@
* pm2 status
*/
const os = require('os');
const path = require('path');
// Determine log directory
const logDir = path.join(os.homedir(), '.claude-mem', 'logs');
module.exports = {
apps: [{
name: 'claude-mem-worker',
script: './plugin/scripts/worker-service.cjs',
interpreter: 'node',
instances: 1,
exec_mode: 'fork',
autorestart: true,
watch: false,
env: {
NODE_ENV: 'production',
CLAUDE_MEM_WORKER_PORT: 37777, // Fixed port for reliability
FORCE_COLOR: '1'
},
// Logging
error_file: path.join(logDir, 'worker-error.log'),
out_file: path.join(logDir, 'worker-out.log'),
log_date_format: 'YYYY-MM-DD HH:mm:ss.SSS Z',
merge_logs: true,
// Keep logs from last 7 days
log_type: 'json',
// Process management
kill_timeout: 1000,
listen_timeout: 3000,
shutdown_with_message: true,
// PM2 Plus (optional monitoring)
// instance_var: 'INSTANCE_ID',
// pmx: true
error_file: '/dev/null',
out_file: '/dev/null'
}]
};