ai-debug-local-mcp
Version:
🎯 ENHANCED AI GUIDANCE v4.1.2: Dramatically improved tool descriptions help AI users choose the right tools instead of 'close enough' options. Ultra-fast keyboard automation (10x speed), universal recording, multi-ecosystem debugging support, and compreh
72 lines • 2.33 kB
JavaScript
/**
* Connection Lock - Prevents multiple simultaneous AI-Debug startups
* Solves the Claude rapid connection crash issue
*/
import { promises as fs } from 'fs';
import { tmpdir } from 'os';
import { join } from 'path';
export class ConnectionLock {
static LOCK_FILE = join(tmpdir(), 'ai-debug-mcp.lock');
static LOCK_TIMEOUT = 30000; // 30 seconds
/**
* Acquire connection lock
*/
static async acquire() {
try {
// Check if lock file exists and is recent
try {
const stat = await fs.stat(this.LOCK_FILE);
const age = Date.now() - stat.mtime.getTime();
if (age < this.LOCK_TIMEOUT) {
console.log('🔒 AI-Debug already starting, waiting...');
return false;
}
else {
// Stale lock, remove it
await fs.unlink(this.LOCK_FILE).catch(() => { });
}
}
catch (error) {
// Lock file doesn't exist, we can proceed
}
// Create lock file with current PID
await fs.writeFile(this.LOCK_FILE, process.pid.toString());
console.log('🔓 Connection lock acquired');
// Setup cleanup on exit
process.on('exit', () => this.release());
process.on('SIGINT', () => this.release());
process.on('SIGTERM', () => this.release());
return true;
}
catch (error) {
console.error('❌ Failed to acquire connection lock:', error);
return false;
}
}
/**
* Release connection lock
*/
static async release() {
try {
await fs.unlink(this.LOCK_FILE);
console.log('🔓 Connection lock released');
}
catch (error) {
// Lock file might not exist, ignore
}
}
/**
* Check if another instance is running
*/
static async isLocked() {
try {
const stat = await fs.stat(this.LOCK_FILE);
const age = Date.now() - stat.mtime.getTime();
return age < this.LOCK_TIMEOUT;
}
catch (error) {
return false;
}
}
}
//# sourceMappingURL=connection-lock.js.map