granttap-mcp 0.8.122 → 0.8.123

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.
@@ -11,3 +11,13 @@ history cache's lifetime begins when that read completes.
11
11
 
12
12
  Behavior tests live in `tests/`.
13
13
  Licensed under the GrantTap Commercial Source License in the repository root.
14
+
15
+ Identical full session snapshots share one in-flight capability scan across relay
16
+ clients. A completed observation is reused for one second, retaining its original
17
+ `generatedAt`; changed session metadata gets an independent read immediately.
18
+ Inputs are snapshotted before asynchronous work, rejected reads are retryable,
19
+ and the cache holds at most 16 scopes. Room attribution is still applied per
20
+ recipient after reading. Foreground usage requests retain their existing direct
21
+ reader. This removes repeated parsing without changing totals or unknown-use
22
+ semantics. `tests/shared-reader.test.ts` covers sharing, scope separation,
23
+ concurrent input changes, expiration, retry and bounded retention.
@@ -3,6 +3,10 @@ import type { RelayClient } from "../../../../../packages/core/relay-client";
3
3
  import type { SessionInfo, SessionsStatus } from "../../../../../packages/protocol/schema";
4
4
  import { scanRecordedCapabilityUsage, scopeCapabilityUsageToRoom } from "../../sessions";
5
5
 
6
+ import { createSharedCapabilityReader } from './shared-reader';
7
+
8
+ const readUsage = createSharedCapabilityReader(scanRecordedCapabilityUsage);
9
+
6
10
  type Publication = { running: boolean; closed: boolean; lastPublishedAt: number };
7
11
  const publications = new WeakMap<RelayClient, Publication>();
8
12
 
@@ -17,7 +21,7 @@ export function publishMonitorCapabilities(client: RelayClient, status: Sessions
17
21
  await setImmediate();
18
22
  if (state.closed || !client.isConnected) return;
19
23
  const publish = async (sessions: SessionInfo[]) => {
20
- const usage = await scanRecordedCapabilityUsage(sessions);
24
+ const usage = await readUsage(sessions);
21
25
  if (state.closed || !client.isConnected) return;
22
26
  await client.send(scopeCapabilityUsageToRoom(usage, client.room), "phone",
23
27
  { ttlMs: 90_000, reliable: false });
@@ -36,3 +40,5 @@ export function stopMonitorCapabilities(client: RelayClient): void {
36
40
  if (state) state.closed = true;
37
41
  publications.delete(client);
38
42
  }
43
+
44
+ export { createSharedCapabilityReader } from './shared-reader';
@@ -0,0 +1,30 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { performance } from 'node:perf_hooks';
3
+ import type { CapabilityUsageStatus, SessionInfo } from '../../../../../packages/protocol/schema';
4
+
5
+ type Observation = { until: number; value: Promise<CapabilityUsageStatus> };
6
+
7
+ /** Coalesce identical machine-side reads; room scoping still happens for each recipient. */
8
+ export function createSharedCapabilityReader(scan: (sessions: SessionInfo[]) => Promise<CapabilityUsageStatus>,
9
+ now: () => number = () => performance.now()) {
10
+ const cache = new Map<string, Observation>();
11
+ return (sessions: SessionInfo[]): Promise<CapabilityUsageStatus> => {
12
+ const snapshot = JSON.stringify(sessions);
13
+ const key = createHash('sha256').update(snapshot).digest('hex');
14
+ const previous = cache.get(key);
15
+ if (previous && now() < previous.until) return previous.value;
16
+ cache.delete(key);
17
+ if (cache.size >= 16) cache.delete(cache.keys().next().value!);
18
+ const entry: Observation = { until: Infinity,
19
+ value: Promise.resolve().then(() => scan(JSON.parse(snapshot) as SessionInfo[])) };
20
+ entry.value = entry.value.then(value => {
21
+ entry.until = now() + 1_000;
22
+ return value;
23
+ }, error => {
24
+ if (cache.get(key) === entry) cache.delete(key);
25
+ throw error;
26
+ });
27
+ cache.set(key, entry);
28
+ return entry.value;
29
+ };
30
+ }
@@ -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.122
13
+ npm install -g granttap-mcp@0.8.123
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.122\";\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.123\";\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.122";
10
+ const PACKAGE = "granttap-mcp@0.8.123";
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.122",
3
+ "version": "0.8.123",
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": {