safari-mcp 2.1.3 → 2.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +18 -2
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -15,14 +15,30 @@ import { randomUUID } from "node:crypto";
15
15
  import { execFileSync } from "node:child_process";
16
16
 
17
17
  // ========== SINGLETON: kill stale instances from previous sessions ==========
18
+ // NOTE: Claude Code VSCode may start 2 instances simultaneously (~40ms apart).
19
+ // Only kill instances running >10 seconds (truly stale), not fresh siblings.
18
20
  try {
19
21
  const myPid = process.pid;
20
22
  const lines = execFileSync("pgrep", ["-af", "node.*/safari-mcp/index\\.js"], { encoding: "utf8" }).trim().split("\n");
21
23
  for (const line of lines) {
22
24
  const pid = parseInt(line.split(/\s+/)[0], 10);
23
25
  if (pid && pid !== myPid) {
24
- try { process.kill(pid, "SIGTERM"); } catch {}
25
- console.error(`[Safari MCP] Killed stale instance PID ${pid}`);
26
+ // Check how long the process has been running (elapsed time in seconds)
27
+ let elapsedSec = 0;
28
+ try {
29
+ const etime = execFileSync("ps", ["-o", "etime=", "-p", String(pid)], { encoding: "utf8" }).trim();
30
+ // etime format: [[DD-]HH:]MM:SS — parse to seconds
31
+ const parts = etime.replace(/-/g, ":").split(":").map(Number);
32
+ if (parts.length === 2) elapsedSec = parts[0] * 60 + parts[1];
33
+ else if (parts.length === 3) elapsedSec = parts[0] * 3600 + parts[1] * 60 + parts[2];
34
+ else if (parts.length === 4) elapsedSec = parts[0] * 86400 + parts[1] * 3600 + parts[2] * 60 + parts[3];
35
+ } catch {}
36
+ if (elapsedSec > 10) {
37
+ try { process.kill(pid, "SIGTERM"); } catch {}
38
+ console.error(`[Safari MCP] Killed stale instance PID ${pid} (running ${elapsedSec}s)`);
39
+ } else {
40
+ console.error(`[Safari MCP] Skipping fresh instance PID ${pid} (running ${elapsedSec}s)`);
41
+ }
26
42
  }
27
43
  }
28
44
  } catch {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "safari-mcp",
3
- "version": "2.1.3",
3
+ "version": "2.1.4",
4
4
  "mcpName": "io.github.achiya-automation/safari-mcp",
5
5
  "description": "Safari browser automation for AI agents — native macOS, zero Chrome overhead. 80 tools via AppleScript + JavaScript.",
6
6
  "type": "module",