granttap-mcp 0.8.122 → 0.8.124

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
+ }
@@ -20,3 +20,8 @@ nested conversations through the public catalog and activity readers.
20
20
 
21
21
  Tests live in [`tests/`](tests/). The selected-Page regression covers the public
22
22
  catalog, cached rescans, live activity, and paginated transcript history.
23
+
24
+ Missing rollout lookups use the bounded [rollout identity index](rollout-identity/README.md).
25
+ They do not read unrelated large activity tails. Unchanged file identities are
26
+ reused; file changes invalidate them, and the selected chat keeps its existing
27
+ activity window. `tests/rollout-lookup-cost.test.ts` measures the actual read budget.
@@ -0,0 +1,16 @@
1
+ # Codex rollout identity lookup
2
+
3
+ Public entry: `index.ts`. Missing native-path lookups inspect the existing bounded
4
+ summary window, not every candidate's 16 MiB activity tail. Only the matching
5
+ rollout is opened with the activity budget. Fork ownership keeps the existing
6
+ `ownCodexLines` boundary. The cache retains at most 256 path/identity signatures,
7
+ never conversation text. Device, inode, size, modification and change times
8
+ invalidate it; a file changed during the metadata read is retried on the next
9
+ lookup. Read failures and deleted paths do not retain an identity.
10
+
11
+ Local tests cover unchanged observations, replacement with preserved timestamps,
12
+ concurrent changes, retry and bounded retention. The Codex public-reader cost
13
+ regression measures bytes actually read from a large foreign rollout, followed
14
+ by a successful full read of that rollout when it is explicitly requested.
15
+
16
+ Licensed under the GrantTap Commercial Source License. See LICENSE and NOTICE.
@@ -0,0 +1,36 @@
1
+ import { statSync } from 'node:fs';
2
+ import { safeParse } from '../../../support/common';
3
+
4
+ type Identity = { signature: string; sessionId: string };
5
+
6
+ function signature(file: string): string {
7
+ const stat = statSync(file, { bigint: true });
8
+ if (!stat.isFile()) throw Error('A rollout must be a regular file');
9
+ return [stat.dev, stat.ino, stat.size, stat.mtimeNs, stat.ctimeNs].join(':');
10
+ }
11
+
12
+ /** Index bounded metadata, never another conversation's large activity window. */
13
+ export function createCodexRolloutIdentityLookup(readMetadata: (file: string) => string[]) {
14
+ const cache = new Map<string, Identity>();
15
+ return (sessionId: string, files: string[]): string | undefined => {
16
+ for (const file of files) {
17
+ try {
18
+ const before = signature(file);
19
+ let identity = cache.get(file);
20
+ if (!identity || identity.signature !== before) {
21
+ const line = readMetadata(file).find(row => safeParse(row)?.type === 'session_meta');
22
+ const meta = line ? safeParse(line) : undefined;
23
+ if (signature(file) !== before) { cache.delete(file); continue; }
24
+ identity = { signature: before, sessionId: String(meta?.payload?.id ?? meta?.id ?? '') };
25
+ cache.delete(file);
26
+ if (cache.size >= 256) cache.delete(cache.keys().next().value!);
27
+ cache.set(file, identity);
28
+ }
29
+ if (identity.sessionId && identity.sessionId === sessionId) return file;
30
+ } catch {
31
+ cache.delete(file);
32
+ }
33
+ }
34
+ return undefined;
35
+ };
36
+ }
@@ -3,6 +3,7 @@ import { diffPreviewFromInput, sensitivePath, statsFromInput } from "../../suppo
3
3
  import { redactSecrets } from "../../telemetry/command-preview";
4
4
  import { recordObservedWrite, writtenPaths } from "../../../mesh/observed/writes";
5
5
  import { ownCodexLines } from './lineage';
6
+ import { createCodexRolloutIdentityLookup } from './rollout-identity';
6
7
  /**
7
8
  * Codex session logs:
8
9
  * ~/.codex/sessions/YYYY/MM/DD/rollout-*.jsonl
@@ -198,22 +199,15 @@ export function codexLogLines(sessionId: string): string[] | undefined {
198
199
  codexLogPathBySession.delete(sessionId);
199
200
  }
200
201
  }
201
- for (const file of recentLogs(codexSessionsRoot(), 5)) {
202
+ const file = findCodexRolloutIdentity(sessionId, recentLogs(codexSessionsRoot(), 5));
203
+ if (file) {
202
204
  try {
203
- const candidate = readCodexLogWindow(
204
- file, CODEX_ACTIVITY_HEAD_BYTES, CODEX_ACTIVITY_TAIL_BYTES,
205
- );
206
- if (candidate.some((line) => {
207
- const row = safeParse(line);
208
- return row?.type === "session_meta" &&
209
- String(row.payload?.id ?? row.id ?? "") === sessionId;
210
- })) {
211
- codexLogPathBySession.set(sessionId, file);
212
- return candidate;
213
- }
214
- } catch {
215
- // Keep looking through the bounded recent-file set.
216
- }
205
+ const lines = readCodexLogWindow(file, CODEX_ACTIVITY_HEAD_BYTES, CODEX_ACTIVITY_TAIL_BYTES);
206
+ codexLogPathBySession.set(sessionId, file);
207
+ return lines;
208
+ } catch { /* The matching rollout may have disappeared. */ }
217
209
  }
218
210
  return undefined;
219
211
  }
212
+
213
+ const findCodexRolloutIdentity = createCodexRolloutIdentityLookup(file => readCodexLogWindow(file));
@@ -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.124
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.124\";\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.124";
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.124",
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": {