granttap-mcp 0.8.124 → 0.8.125

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.
@@ -43,3 +43,10 @@ Question publication reads the private record collection once per batch, then
43
43
  validates each matching question freshly before sending. Targeted notification
44
44
  replay reads the requested identity directly. This keeps multiple chats from
45
45
  repeatedly parsing the same collection.
46
+
47
+ Question polling reuses at most 512 validated, unchanged private records. Inode,
48
+ size and nanosecond modification/change times invalidate an observation;
49
+ `saveQuestion` invalidates it immediately. Reads return detached copies, and
50
+ invalid, replaced or deleted files cannot return an earlier cached question.
51
+ `tests/record-observation.test.ts` covers durable updates, external replacement,
52
+ caller mutation, malformed data, bounded retention and actual file-read counts.
@@ -11,21 +11,35 @@ const Record = z.object({ requestId: z.string(), sessionId: z.string(), callId:
11
11
  announced: z.boolean().optional(), answered: z.boolean().optional(), resolvedSent: z.boolean().optional() });
12
12
  export type QuestionRecord = z.infer<typeof Record>;
13
13
  const directory = () => join(configDir(), 'codex-question-records');
14
+ const observations = new Map<string, { revision: string; record: QuestionRecord }>();
15
+
16
+ function revision(path: string): string {
17
+ const stat = statSync(path, { bigint: true });
18
+ if (!stat.isFile() || stat.size > 16_384n) throw Error('Invalid native question record');
19
+ return [stat.dev, stat.ino, stat.size, stat.mtimeNs, stat.ctimeNs].join(':');
20
+ }
14
21
 
15
22
  export function readQuestion(requestId: string): QuestionRecord | undefined {
16
23
  if (!/^codex-question-[a-f0-9]{32}$/.test(requestId)) return undefined;
24
+ const path = join(directory(), requestId + '.json');
17
25
  try {
18
- const path = join(directory(), requestId + '.json');
19
- if (statSync(path).size > 16_384) return undefined;
26
+ const before = revision(path), cached = observations.get(path);
27
+ if (cached?.revision === before) return structuredClone(cached.record);
20
28
  const record = Record.parse(JSON.parse(readFileSync(path, 'utf8')));
21
- return record.requestId === requestId && questionId(record.sessionId, record.callId, record.index) === requestId
22
- ? record : undefined;
23
- } catch { return undefined; }
29
+ if (record.requestId !== requestId || questionId(record.sessionId, record.callId, record.index) !== requestId
30
+ || revision(path) !== before) { observations.delete(path); return undefined; }
31
+ observations.delete(path);
32
+ if (observations.size >= 512) observations.delete(observations.keys().next().value!);
33
+ observations.set(path, { revision: before, record });
34
+ return structuredClone(record);
35
+ } catch { observations.delete(path); return undefined; }
24
36
  }
25
37
 
26
38
  export function saveQuestion(record: QuestionRecord): void {
27
39
  if (!/^codex-question-[a-f0-9]{32}$/.test(record.requestId)) throw new Error('Invalid native question identity');
28
- writePrivateFile(join(directory(), record.requestId + '.json'), JSON.stringify(record));
40
+ const path = join(directory(), record.requestId + '.json');
41
+ writePrivateFile(path, JSON.stringify(record));
42
+ observations.delete(path);
29
43
  }
30
44
 
31
45
  export function storedQuestions(): QuestionRecord[] {
@@ -1,61 +1,12 @@
1
1
  import type { SessionInfo } from "../../../../packages/protocol/schema";
2
2
  import { localTaskTransfers, localTransferContinuations } from "../task-transfer";
3
- import { loadRuntimeConfig } from "../config";
4
- import { timedProviderScan, timedProviderScanAsync } from "../machine-load/mcp/scan-cost";
5
- import { scanClaude, scanClaudeCooperatively } from "./scan/claude";
6
- import { scanCodex, scanCodexCooperatively } from "./scan/codex";
7
- import { scanCursor } from "./cursor";
8
- import { scanGrok } from "./scan/grok";
9
3
  import { MAX_FILES, MAX_HISTORY, MAX_LIVE, TOKEN_WINDOW_MS } from "./support/common";
10
- import { setImmediate } from "node:timers/promises";
11
-
12
- type ProviderScan = ReturnType<typeof scanClaude>;
4
+ import { providerScans, cooperativeProviderScans, type ProviderScan } from "./provider-discovery";
13
5
 
14
6
  function sessionKey(session: SessionInfo): string {
15
7
  return `${session.agent}\0${session.sessionId}`;
16
8
  }
17
9
 
18
- function emptyScan(): ProviderScan {
19
- return { sessions: [], tokensRecent: 0 };
20
- }
21
-
22
- /**
23
- * Explicit provider roots isolate fixtures and diagnostics from real user logs.
24
- * In normal operation (no overrides) every installed provider is scanned.
25
- */
26
- function providerReaders(maxFiles: number) {
27
- const enabled = loadRuntimeConfig().providerSettings;
28
- const explicit = {
29
- claude: Boolean(process.env.GRANTTAP_CLAUDE_PROJECTS_DIR || process.env.NODVOX_CLAUDE_PROJECTS_DIR),
30
- codex: Boolean(process.env.GRANTTAP_CODEX_SESSIONS_DIR || process.env.NODVOX_CODEX_SESSIONS_DIR),
31
- cursor: Boolean(process.env.GRANTTAP_CURSOR_TRANSCRIPTS_DIR || process.env.GRANTTAP_CURSOR_STATE_DB),
32
- grok: Boolean(process.env.GRANTTAP_GROK_SESSIONS_DIR || process.env.GROK_HOME),
33
- };
34
- const isolated = Object.values(explicit).some(Boolean);
35
- const cooperative = { claude: scanClaudeCooperatively, codex: scanCodexCooperatively,
36
- cursor: async (limit: number) => scanCursor(limit), grok: async (limit: number) => scanGrok(limit) };
37
- return Object.entries({ claude: scanClaude, codex: scanCodex, cursor: scanCursor, grok: scanGrok })
38
- .map(([agent, read]) => {
39
- const key = agent as keyof typeof explicit;
40
- return { agent, read: () => read(maxFiles), cooperative: () => cooperative[key](maxFiles),
41
- enabled: enabled[key] && (!isolated || explicit[key]) };
42
- });
43
- }
44
-
45
- function providerScans(maxFiles = MAX_FILES): ProviderScan[] {
46
- return providerReaders(maxFiles).map(reader => reader.enabled
47
- ? timedProviderScan(reader.agent, reader.read) : emptyScan());
48
- }
49
-
50
- async function cooperativeProviderScans(maxFiles = MAX_FILES): Promise<ProviderScan[]> {
51
- const scans: ProviderScan[] = [];
52
- for (const reader of providerReaders(maxFiles)) {
53
- await setImmediate();
54
- scans.push(reader.enabled ? await timedProviderScanAsync(reader.agent, reader.cooperative) : emptyScan());
55
- }
56
- return scans;
57
- }
58
-
59
10
  function sortedUniqueSessions(sessions: SessionInfo[]): SessionInfo[] {
60
11
  const merged = new Map<string, SessionInfo>();
61
12
  for (const session of sessions) {
@@ -0,0 +1,13 @@
1
+ # Native provider discovery batch
2
+
3
+ Public entry: `index.ts`. Live catalogs and history share an identical pending
4
+ native provider read on this computer. The read is scoped to provider settings,
5
+ file budget and a digest of the complete process environment. No environment
6
+ values are retained in the key or published. Completion or failure removes the
7
+ pending entry; the next refresh reads current state. Each consumer still applies
8
+ its own current Task-transfer mappings after the native read.
9
+
10
+ `tests/scan-batch.test.ts` witnesses real directory discovery and Git checkout
11
+ verification, both shared concurrent reads and a fresh subsequent scan.
12
+
13
+ Licensed under the GrantTap Commercial Source License. See LICENSE and NOTICE.
@@ -0,0 +1,67 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { setImmediate } from 'node:timers/promises';
3
+ import { loadRuntimeConfig } from '../../config';
4
+ import { timedProviderScan, timedProviderScanAsync } from '../../machine-load/mcp/scan-cost';
5
+ import { scanClaude, scanClaudeCooperatively } from '../scan/claude';
6
+ import { scanCodex, scanCodexCooperatively } from '../scan/codex';
7
+ import { scanCursor } from '../cursor';
8
+ import { scanGrok } from '../scan/grok';
9
+ import { MAX_FILES } from '../support/common';
10
+
11
+ export type ProviderScan = ReturnType<typeof scanClaude>;
12
+
13
+ function emptyScan(): ProviderScan {
14
+ return { sessions: [], tokensRecent: 0 };
15
+ }
16
+
17
+ /**
18
+ * Explicit provider roots isolate fixtures and diagnostics from real user logs.
19
+ * In normal operation (no overrides) every installed provider is scanned.
20
+ */
21
+ function providerReaders(maxFiles: number) {
22
+ const enabled = loadRuntimeConfig().providerSettings;
23
+ const explicit = {
24
+ claude: Boolean(process.env.GRANTTAP_CLAUDE_PROJECTS_DIR || process.env.NODVOX_CLAUDE_PROJECTS_DIR),
25
+ codex: Boolean(process.env.GRANTTAP_CODEX_SESSIONS_DIR || process.env.NODVOX_CODEX_SESSIONS_DIR),
26
+ cursor: Boolean(process.env.GRANTTAP_CURSOR_TRANSCRIPTS_DIR || process.env.GRANTTAP_CURSOR_STATE_DB),
27
+ grok: Boolean(process.env.GRANTTAP_GROK_SESSIONS_DIR || process.env.GROK_HOME),
28
+ };
29
+ const isolated = Object.values(explicit).some(Boolean);
30
+ const cooperative = { claude: scanClaudeCooperatively, codex: scanCodexCooperatively,
31
+ cursor: async (limit: number) => scanCursor(limit), grok: async (limit: number) => scanGrok(limit) };
32
+ return Object.entries({ claude: scanClaude, codex: scanCodex, cursor: scanCursor, grok: scanGrok })
33
+ .map(([agent, read]) => {
34
+ const key = agent as keyof typeof explicit;
35
+ return { agent, read: () => read(maxFiles), cooperative: () => cooperative[key](maxFiles),
36
+ enabled: enabled[key] && (!isolated || explicit[key]) };
37
+ });
38
+ }
39
+
40
+ export function providerScans(maxFiles = MAX_FILES): ProviderScan[] {
41
+ return providerReaders(maxFiles).map(reader => reader.enabled
42
+ ? timedProviderScan(reader.agent, reader.read) : emptyScan());
43
+ }
44
+
45
+ const pending = new Map<string, Promise<ProviderScan[]>>();
46
+
47
+ /** Share one native read only while it is running; subsequent refreshes stay fresh. */
48
+ export function cooperativeProviderScans(maxFiles = MAX_FILES): Promise<ProviderScan[]> {
49
+ const readers = providerReaders(maxFiles);
50
+ // Hash the complete process scope rather than retaining environment values.
51
+ const scope = [maxFiles, readers.map(({ agent, enabled }) => [agent, enabled]),
52
+ Object.entries(process.env).sort(([left], [right]) => left.localeCompare(right))];
53
+ const key = createHash('sha256').update(JSON.stringify(scope)).digest('hex');
54
+ const active = pending.get(key);
55
+ if (active) return active;
56
+ const next = (async () => {
57
+ const scans: ProviderScan[] = [];
58
+ for (const reader of readers) {
59
+ await setImmediate();
60
+ scans.push(reader.enabled ? await timedProviderScanAsync(reader.agent, reader.cooperative) : emptyScan());
61
+ }
62
+ return scans;
63
+ })().finally(() => { if (pending.get(key) === next) pending.delete(key); });
64
+ pending.set(key, next);
65
+ return next;
66
+ }
67
+
@@ -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.124
13
+ npm install -g granttap-mcp@0.8.125
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.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"
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.125\";\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.124";
10
+ const PACKAGE = "granttap-mcp@0.8.125";
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.124",
3
+ "version": "0.8.125",
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": {