safari-mcp 2.1.2 → 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 (3) hide show
  1. package/README.md +2 -0
  2. package/index.js +30 -0
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -17,6 +17,8 @@
17
17
 
18
18
  [Quick Start](#quick-start) · [All 80 Tools](#tools-80) · [Why Safari MCP?](#safari-mcp-vs-alternatives) · [Architecture](#architecture)
19
19
 
20
+ ![Safari MCP Demo](https://github.com/achiya-automation/safari-mcp/releases/download/v2.1.2/safari-mcp-showcase.gif)
21
+
20
22
  </div>
21
23
 
22
24
  ---
package/index.js CHANGED
@@ -12,6 +12,36 @@ import * as safari from "./safari.js";
12
12
  import { WebSocketServer } from "ws";
13
13
  import { createServer } from "node:http";
14
14
  import { randomUUID } from "node:crypto";
15
+ import { execFileSync } from "node:child_process";
16
+
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.
20
+ try {
21
+ const myPid = process.pid;
22
+ const lines = execFileSync("pgrep", ["-af", "node.*/safari-mcp/index\\.js"], { encoding: "utf8" }).trim().split("\n");
23
+ for (const line of lines) {
24
+ const pid = parseInt(line.split(/\s+/)[0], 10);
25
+ if (pid && pid !== myPid) {
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
+ }
42
+ }
43
+ }
44
+ } catch {}
15
45
 
16
46
  // ========== SESSION ID (unique per MCP process — enables per-session tab tracking) ==========
17
47
  const SESSION_ID = randomUUID().slice(0, 8);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "safari-mcp",
3
- "version": "2.1.2",
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",