granttap-mcp 0.8.138 → 0.8.139

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.
@@ -31,6 +31,7 @@ import { configDir } from "../../config";
31
31
  // meant five minutes of a silent phone.
32
32
  export const LEADERSHIP_TTL_MS = 90_000;
33
33
  const REPORT_INTERVAL_MS = 10 * 60_000;
34
+ const INSTALLED = "installed-";
34
35
 
35
36
  export type MonitorLeadership = { acquire: () => boolean; release: () => void };
36
37
 
@@ -101,7 +102,11 @@ export function monitorLeadership(
101
102
  primary = false,
102
103
  ): MonitorLeadership {
103
104
  const path = join(configDir(), "monitor.lock");
104
- const token = `${process.pid}:${randomUUID()}:${primary ? "primary" : "peer"}`;
105
+ // Chats started by an older monitor inherited its primary flag and still run
106
+ // that release, so ":primary" alone no longer proves the installed monitor.
107
+ // The marker sits mid-token: older releases keep reading the suffix and so
108
+ // never take the lease from the installed monitor.
109
+ const token = `${process.pid}:${primary ? INSTALLED : ""}${randomUUID()}:${primary ? "primary" : "peer"}`;
105
110
  let leader = false;
106
111
  let reportedAt = 0;
107
112
 
@@ -139,7 +144,10 @@ export function monitorLeadership(
139
144
  }
140
145
  };
141
146
 
142
- const ownerIsPrimary = (): boolean => read()?.trim().endsWith(":primary") === true;
147
+ const ownerIsPrimary = (): boolean => {
148
+ const owner = read()?.trim() ?? "";
149
+ return owner.endsWith(":primary") && owner.includes(`:${INSTALLED}`);
150
+ };
143
151
 
144
152
  const reportRefusal = (): void => {
145
153
  if (now() - reportedAt < REPORT_INTERVAL_MS) return;
@@ -10,7 +10,7 @@ keeps each phone response tied to the exact originating chat and prompt.
10
10
  Install the supported CLI on this computer, then run:
11
11
 
12
12
  ```bash
13
- npm install -g granttap-mcp@0.8.138
13
+ npm install -g granttap-mcp@0.8.139
14
14
  granttap setup
15
15
  granttap status
16
16
  ```
@@ -4,7 +4,7 @@
4
4
  "command": "node",
5
5
  "args": [
6
6
  "-e",
7
- "\"use strict\";\n\n// Cursor may start this MCP from any cwd. Execute JavaScript entry points with\n// Node itself: Windows batch shims require shell quoting that differs by host.\nconst { spawn } = require(\"node:child_process\");\nconst { existsSync } = require(\"node:fs\");\nconst { delimiter, dirname, join } = require(\"node:path\");\n\nconst PACKAGE = \"granttap-mcp@0.8.138\";\nconst dryRun = process.env.GRANTTAP_BOOTSTRAP_DRY_RUN === \"1\";\nconst platform = dryRun && process.env.GRANTTAP_BOOTSTRAP_PLATFORM\n ? process.env.GRANTTAP_BOOTSTRAP_PLATFORM : process.platform;\nconst nodeRoot = dryRun && process.env.GRANTTAP_BOOTSTRAP_NODE_ROOT\n ? process.env.GRANTTAP_BOOTSTRAP_NODE_ROOT : dirname(process.execPath);\nconst pathRoots = (process.env.PATH || \"\").split(delimiter).filter(Boolean);\nconst appData = process.env.APPDATA;\nconst roots = [nodeRoot, ...pathRoots, ...(appData ? [join(appData, \"npm\")] : [])];\nconst first = (paths) => paths.find((path) => existsSync(path));\n\nfunction launch() {\n if (platform !== \"win32\") {\n const installed = first(roots.map((root) => join(root, \"granttap-mcp\")));\n if (installed) return { command: installed, args: [] };\n const npx = first(roots.map((root) => join(root, \"npx\"))) || \"npx\";\n return { command: npx, args: [\"-y\", PACKAGE] };\n }\n const installed = first(roots.map((root) =>\n join(root, \"node_modules\", \"granttap-mcp\", \"bin\", \"granttap-mcp.mjs\")));\n if (installed) return { command: process.execPath, args: [installed] };\n const npx = first(roots.map((root) =>\n join(root, \"node_modules\", \"npm\", \"bin\", \"npx-cli.js\")));\n if (npx) return { command: process.execPath, args: [npx, \"-y\", PACKAGE] };\n throw new Error(\"Node.js/npm 22.13.0+ is required on this Windows device. Install npm and retry GrantTap.\");\n}\n\nlet target;\ntry { target = launch(); }\ncatch (error) {\n process.stderr.write(`[granttap] ${error.message}\\n`);\n process.exit(1);\n}\n\nif (dryRun) {\n process.stdout.write(JSON.stringify(target));\n process.exit(0);\n}\n\nconst child = spawn(target.command, target.args, { stdio: \"inherit\", windowsHide: true });\nchild.on(\"error\", (error) => {\n process.stderr.write(`[granttap] ${error.message}\\n`);\n process.exit(1);\n});\nchild.on(\"exit\", (code, signal) => {\n if (signal && platform !== \"win32\") {\n try { process.kill(process.pid, signal); } catch { process.exit(code ?? 1); }\n return;\n }\n process.exit(code ?? 1);\n});\n"
7
+ "\"use strict\";\n\n// Cursor may start this MCP from any cwd. Execute JavaScript entry points with\n// Node itself: Windows batch shims require shell quoting that differs by host.\nconst { spawn } = require(\"node:child_process\");\nconst { existsSync } = require(\"node:fs\");\nconst { delimiter, dirname, join } = require(\"node:path\");\n\nconst PACKAGE = \"granttap-mcp@0.8.139\";\nconst dryRun = process.env.GRANTTAP_BOOTSTRAP_DRY_RUN === \"1\";\nconst platform = dryRun && process.env.GRANTTAP_BOOTSTRAP_PLATFORM\n ? process.env.GRANTTAP_BOOTSTRAP_PLATFORM : process.platform;\nconst nodeRoot = dryRun && process.env.GRANTTAP_BOOTSTRAP_NODE_ROOT\n ? process.env.GRANTTAP_BOOTSTRAP_NODE_ROOT : dirname(process.execPath);\nconst pathRoots = (process.env.PATH || \"\").split(delimiter).filter(Boolean);\nconst appData = process.env.APPDATA;\nconst roots = [nodeRoot, ...pathRoots, ...(appData ? [join(appData, \"npm\")] : [])];\nconst first = (paths) => paths.find((path) => existsSync(path));\n\nfunction launch() {\n if (platform !== \"win32\") {\n const installed = first(roots.map((root) => join(root, \"granttap-mcp\")));\n if (installed) return { command: installed, args: [] };\n const npx = first(roots.map((root) => join(root, \"npx\"))) || \"npx\";\n return { command: npx, args: [\"-y\", PACKAGE] };\n }\n const installed = first(roots.map((root) =>\n join(root, \"node_modules\", \"granttap-mcp\", \"bin\", \"granttap-mcp.mjs\")));\n if (installed) return { command: process.execPath, args: [installed] };\n const npx = first(roots.map((root) =>\n join(root, \"node_modules\", \"npm\", \"bin\", \"npx-cli.js\")));\n if (npx) return { command: process.execPath, args: [npx, \"-y\", PACKAGE] };\n throw new Error(\"Node.js/npm 22.13.0+ is required on this Windows device. Install npm and retry GrantTap.\");\n}\n\nlet target;\ntry { target = launch(); }\ncatch (error) {\n process.stderr.write(`[granttap] ${error.message}\\n`);\n process.exit(1);\n}\n\nif (dryRun) {\n process.stdout.write(JSON.stringify(target));\n process.exit(0);\n}\n\nconst child = spawn(target.command, target.args, { stdio: \"inherit\", windowsHide: true });\nchild.on(\"error\", (error) => {\n process.stderr.write(`[granttap] ${error.message}\\n`);\n process.exit(1);\n});\nchild.on(\"exit\", (code, signal) => {\n if (signal && platform !== \"win32\") {\n try { process.kill(process.pid, signal); } catch { process.exit(code ?? 1); }\n return;\n }\n process.exit(code ?? 1);\n});\n"
8
8
  ]
9
9
  }
10
10
  }
@@ -7,7 +7,7 @@ const { spawn } = require("node:child_process");
7
7
  const { existsSync } = require("node:fs");
8
8
  const { delimiter, dirname, join } = require("node:path");
9
9
 
10
- const PACKAGE = "granttap-mcp@0.8.138";
10
+ const PACKAGE = "granttap-mcp@0.8.139";
11
11
  const dryRun = process.env.GRANTTAP_BOOTSTRAP_DRY_RUN === "1";
12
12
  const platform = dryRun && process.env.GRANTTAP_BOOTSTRAP_PLATFORM
13
13
  ? process.env.GRANTTAP_BOOTSTRAP_PLATFORM : process.platform;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "granttap-mcp",
3
- "version": "0.8.138",
3
+ "version": "0.8.139",
4
4
  "description": "Commercial computer runtime connecting local coding agents to GrantTap on Mac, iPhone, iPad and Apple Watch.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -7,3 +7,8 @@ Redirects are rejected. HTTP failure text never includes credentials or content.
7
7
  `TaskJobHttpError.status` supports a bounded product error mapping.
8
8
 
9
9
  Licensed under the GrantTap Commercial Source License. See LICENSE and NOTICE.
10
+
11
+ A request that fails because the relay closed an idle pooled connection
12
+ (`UND_ERR_SOCKET`, `ECONNRESET`, …) is sent once more on a fresh connection.
13
+ Claims and outcomes carry their claim id, so the repeat is idempotent.
14
+ Tests: [`tests/dropped-connection.test.ts`](tests/dropped-connection.test.ts).
@@ -9,6 +9,12 @@ export class TaskJobHttpError extends Error {
9
9
  constructor(readonly status: number) { super('The relay did not confirm the queued task operation.'); }
10
10
  }
11
11
 
12
+ const DROPPED = new Set(['UND_ERR_SOCKET', 'UND_ERR_CLOSED', 'ECONNRESET', 'EPIPE']);
13
+ function droppedConnection(error: unknown): boolean {
14
+ const code = error instanceof Error ? (error.cause as NodeJS.ErrnoException | undefined)?.code : undefined;
15
+ return error instanceof TypeError && code !== undefined && DROPPED.has(code);
16
+ }
17
+
12
18
  /** Only a bounded receipt is returned; prompt and photo ciphertext are never echoed into status polling. */
13
19
  export async function requestTaskJob(config: PeerConfig, input: {
14
20
  id: string; method: 'GET' | 'PUT' | 'POST' | 'DELETE'; action?: 'claim' | 'finish'; body?: unknown;
@@ -17,10 +23,17 @@ export async function requestTaskJob(config: PeerConfig, input: {
17
23
  const url = new URL(`/task-jobs/${input.id}${input.action ? '/' + input.action : ''}`, config.relayUrl);
18
24
  url.protocol = url.protocol === 'wss:' ? 'https:' : url.protocol === 'ws:' ? 'http:' : url.protocol;
19
25
  url.searchParams.set('room', config.room); url.searchParams.set('metadata', '1');
20
- const response = await request(url, { method: input.method, redirect: 'error', signal: AbortSignal.timeout(20_000),
26
+ const send = () => request(url, { method: input.method, redirect: 'error', signal: AbortSignal.timeout(20_000),
21
27
  headers: { authorization: `Bearer ${config.pushAuth ?? ''}`, accept: 'application/json',
22
28
  ...(input.body ? { 'content-type': 'application/json' } : {}) },
23
29
  body: input.body ? JSON.stringify(input.body) : undefined });
30
+ // A long-lived monitor reuses a pooled connection the relay already closed
31
+ // while idle; that request fails before it is sent. Claims and outcomes carry
32
+ // their claim id, so asking once more on a fresh connection is safe.
33
+ const response = await send().catch(error => {
34
+ if (!droppedConnection(error)) throw error;
35
+ return send();
36
+ });
24
37
  if ([404, 409].includes(response.status)) return null;
25
38
  if (!response.ok) throw new TaskJobHttpError(response.status);
26
39
  const raw = await response.text();