granttap-mcp 0.8.164 → 0.8.166

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.
package/README.md CHANGED
@@ -519,27 +519,54 @@ hooks, installs the background helper, removes a leftover user GrantTap MCP
519
519
  entry when Cursor is present, and starts phone pairing when run in an
520
520
  interactive terminal. It ends with one exact next action.
521
521
 
522
- Setup also declares the separately distributed GrantTap Engine, which Project
523
- Governance needs before it can report anything. The standard locations are
524
- searched, and `--engine <path>` points at one that lives elsewhere; the binary
525
- is checksummed here, because that checksum is the only thing verified before it
526
- is launched. Without an engine the rollout stays off and setup says so, rather
527
- than leaving "Governance not reported" on the phone as the only symptom.
528
- A paired monitor can prepare the pinned managed Engine in the background.
529
- Inspect current readiness and coverage rather than assuming every missing
530
- Engine requires a manual binary path; initial catalog delivery does not wait
531
- for background preparation.
522
+ Setup also prepares the separately distributed GrantTap Engine, which Graph,
523
+ Health and Project Governance need. It installs the release pinned for this
524
+ computer, verified by size and SHA-256, or uses the absolute executable given
525
+ with `--engine <path>`; that binary is checksummed here, because the checksum
526
+ is the only thing verified before it is launched. Pinned releases do not exist
527
+ for every computer: today only Apple silicon Macs (Engine 0.1.7) have one; Intel
528
+ Macs, Linux and Windows need an Engine supplied with `--engine` or in a standard
529
+ location. When no release exists for this one, or its download is
530
+ unavailable, setup keeps an Engine it declared earlier whose bytes still match
531
+ the saved checksum. Otherwise it searches the standard locations:
532
+ `engine/granttap-engine` in the GrantTap config directory,
533
+ `~/.local/bin/granttap-engine`, `/usr/local/bin/granttap-engine` and
534
+ `/opt/homebrew/bin/granttap-engine` (on Windows, `granttap-engine.exe` in the
535
+ config directory's `engine` folder and in the profile's
536
+ `AppData\Local\GrantTap\bin`).
537
+
538
+ Without any Engine, setup prints `Graph Engine unavailable on this computer:`
539
+ with the reason, reports `Project Governance No engine found`, and still
540
+ installs the hooks, the background helper and, for an installed agent, the
541
+ local MCP service, checks Codex hook trust, offers pairing in an interactive
542
+ terminal, prints the summary and its next action, and exits 0. Graph and
543
+ Health then report the Engine as unavailable; chats, questions and approvals
544
+ keep working. An `--engine` value that is missing or is not an absolute path to
545
+ an executable file stops setup before it changes anything.
546
+
547
+ A paired monitor prepares the pinned managed Engine in the background and
548
+ retries a failed download. If an update cannot be downloaded, it keeps the
549
+ verified Engine already declared and retries when the helper next starts; a
550
+ computer with no pinned release is not retried. Initial catalog delivery does
551
+ not wait for background preparation.
532
552
 
533
553
  The normal CLI surface is intentionally small:
534
554
 
535
555
  ```text
536
556
  granttap setup [--engine <path>]
557
+ granttap setup --help
537
558
  granttap status [--json]
538
559
  granttap connect [--relay <wss-url>]
539
560
  granttap reset [--yes]
540
561
  granttap mesh connect <one-time-invite>
562
+ granttap --version
541
563
  ```
542
564
 
565
+ `granttap --version` (also `-v` or `version`) prints the version of the
566
+ runtime the other commands run, including an automatically updated one, and
567
+ exits. `granttap setup --help` (or `-h`) prints setup usage without
568
+ running setup or writing any configuration.
569
+
543
570
  `connect` reuses a valid pairing. If none exists, it creates a one-time QR.
544
571
  Custom relays are CLI-only and explicit. `reset` moves active pairing files to
545
572
  recoverable local backups before a new pairing can be created.
@@ -556,16 +583,19 @@ trust.
556
583
 
557
584
  ## MCP contract
558
585
 
559
- `tools/list` returns exactly six public tools:
586
+ `tools/list` returns exactly nine public tools:
560
587
 
561
588
  | Tool | Contract |
562
589
  | --- | --- |
590
+ | `set_runtime_auto_update` | When the user asks, turn automatic GrantTap runtime updates on this computer on or off; saves the preference without restarting services or changing pairing, tasks, or provider policy |
563
591
  | `connection_status` | Open the connection card and inspect saved pairing, QR expiry, relay observations, and provider readiness without changing pairing |
592
+ | `connect_with_passkey` | Open a short-lived GrantTap account passkey request for this computer; the passkey is entered only on granttap.com and existing QR pairings stay unchanged |
564
593
  | `connect` | Reuse the existing production pairing or return a one-time QR |
565
594
  | `reconnect` | After explicit confirmation, show a one-time QR to reconnect or add an independent controller device while retaining the current room |
566
595
  | `notify` | Send a non-blocking status update of at most 2,000 characters |
567
596
  | `ask_yes_no` | Ask a yes/no question and wait for the explicit answer |
568
597
  | `ask` | Ask an open question and wait for typed or spoken text |
598
+ | `offload_task` | Request moving the calling Task to a compatible computer in its Mesh, keeping provider, model, effort and visible conversation; requires Automatic computer transfers, and `action=status` or `action=cancel` acts only on the caller's own request |
569
599
 
570
600
  MCP `connect` accepts no custom routing, replacement, or key-rotation input.
571
601
  `reconnect` is declared destructive and requires `confirmed: true`; the
@@ -574,7 +604,7 @@ Setup is CLI-only because it changes provider configuration and must not be
574
604
  available to a model through prompt injection.
575
605
 
576
606
  `notify` may alternatively carry one bounded task-scoped Mesh event. This does
577
- not add a fifth MCP tool or grant any global setup capability, and it publishes
607
+ not add another MCP tool or grant any global setup capability, and it publishes
578
608
  only for the execution whose provider hook attributed the call.
579
609
 
580
610
  `notify`, `ask_yes_no`, and `ask` accept an `operationId`. A named call is
@@ -11,11 +11,42 @@ import {
11
11
  type InstallResult,
12
12
  } from "../../install";
13
13
  import { createOneTimePairing, DEFAULT_RELAY, PAIRING_CODE_TTL_MINUTES } from "../../pairing";
14
- import { prepareEngine } from "../../engine/distribution";
14
+ import { prepareSetupEngine, type SetupEngine } from "../../engine/distribution";
15
+ import { usableEngineBinary } from "../../engine/protocol/engine-declaration";
15
16
  import { isMachineConfigured } from "../../../../mcp/src/status/pairing-status";
16
17
  import { removeCursorUserGrantTap } from "../../../../mcp/src/cursor-config";
17
18
  import { installHttpMcpService, waitForHttpMcpHealth } from "../../../../mcp/src/http-service";
18
19
 
20
+ const SETUP_USAGE = [
21
+ "Usage: granttap setup [--engine <path>]",
22
+ "",
23
+ "Detects local coding agents, installs or repairs their GrantTap hooks, the background",
24
+ "helper and the local MCP service, prepares the Graph Engine, and starts phone pairing",
25
+ "when run in an interactive terminal. Without an Engine, everything else is still set up.",
26
+ "",
27
+ "Options:",
28
+ " --engine <path> Use this absolute path to an executable as the Engine",
29
+ " -h, --help Show this help without changing anything",
30
+ "",
31
+ ].join("\n");
32
+
33
+ /** Argument mistakes stop setup before it changes any provider configuration. */
34
+ function engineArgument(args: string[]): string | undefined {
35
+ const flag = args.indexOf("--engine");
36
+ if (flag < 0) return undefined;
37
+ const path = args[flag + 1];
38
+ if (!path) throw new Error("Choose an executable after --engine");
39
+ if (!usableEngineBinary(path)) throw new Error("The selected Engine must be an absolute path to an executable regular file");
40
+ return path;
41
+ }
42
+
43
+ function engineNote(engine: SetupEngine): string[] {
44
+ if (!engine.reason) return [];
45
+ return [engine.declaration
46
+ ? `Engine not prepared: ${engine.reason}. Using the verified Engine already installed on this computer.`
47
+ : `Graph Engine unavailable on this computer: ${engine.reason}. Graph and Project Governance stay off.`];
48
+ }
49
+
19
50
  function state(result: InstallResult): string {
20
51
  return result.status === "manual" ? "Needs attention" : "Ready";
21
52
  }
@@ -49,6 +80,7 @@ async function pairIfNeeded(): Promise<string | null> {
49
80
  }
50
81
 
51
82
  async function main(): Promise<void> {
83
+ const explicitEngine = engineArgument(process.argv.slice(2));
52
84
  const before = {
53
85
  cursor: inspectCursorIntegration(),
54
86
  agents: inspectAgentIntegrations(),
@@ -57,10 +89,9 @@ async function main(): Promise<void> {
57
89
  const claudeHook = installClaudeHook();
58
90
  const codexHook = installCodexHook();
59
91
  // Declared before the helper is written, so the LaunchAgent picks the engine
60
- // up in the same run rather than needing a second one.
61
- const engineFlag = process.argv.indexOf("--engine");
62
- if (engineFlag >= 0 && !process.argv[engineFlag + 1]) throw new Error("Choose an executable after --engine");
63
- const engine = await prepareEngine(engineFlag >= 0 ? process.argv[engineFlag + 1] : undefined);
92
+ // up in the same run rather than needing a second one. A missing Engine never
93
+ // stops the helper, HTTP service, Codex trust or pairing below.
94
+ const engine = await prepareSetupEngine(explicitEngine);
64
95
  const helper = installMonitorHelper();
65
96
  let httpService: InstallResult | null = null;
66
97
  let cursorConfig: InstallResult | null = null;
@@ -102,8 +133,9 @@ async function main(): Promise<void> {
102
133
  : "Not installed"}`,
103
134
  // Governance is edited on the phone but cannot report until an engine is
104
135
  // declared here, so say plainly which of the two is missing.
105
- `Project Governance ${engine ? "Ready" : "No engine found"}`,
136
+ `Project Governance ${engine.declaration ? "Ready" : "No engine found"}`,
106
137
  "",
138
+ ...engineNote(engine),
107
139
  paired && installed.has("codex")
108
140
  ? codexHooksReady(codexTrust.hooks) ? "Codex confirmed both GrantTap hooks are trusted and enabled."
109
141
  : `Next: review GrantTap hooks in GrantTap Settings → This Mac → Codex hooks, or ${CODEX_TRUST_INSTRUCTION}`
@@ -116,9 +148,14 @@ async function main(): Promise<void> {
116
148
  ].join("\n"));
117
149
  }
118
150
 
119
- void main().catch((error: unknown) => {
120
- process.stderr.write(
121
- `[granttap-mcp] setup failed: ${error instanceof Error ? error.message : String(error)}\n`,
122
- );
123
- process.exitCode = 1;
124
- });
151
+ const args = process.argv.slice(2);
152
+ if (args.includes("--help") || args.includes("-h")) {
153
+ process.stdout.write(SETUP_USAGE);
154
+ } else {
155
+ void main().catch((error: unknown) => {
156
+ process.stderr.write(
157
+ `[granttap-mcp] setup failed: ${error instanceof Error ? error.message : String(error)}\n`,
158
+ );
159
+ process.exitCode = 1;
160
+ });
161
+ }
@@ -11,10 +11,21 @@ Failed downloads leave the previous declared Engine untouched. Setup and the
11
11
  paired monitor save a new declaration only after verification.
12
12
  Custom executable declarations remain available through `setup --engine`.
13
13
 
14
+ Setup never aborts because an Engine cannot be prepared. `prepareSetupEngine`
15
+ reports why: no pinned release for this platform, an unavailable or
16
+ unreachable download, or a configured executable that disappeared. It then
17
+ keeps a previously declared Engine only while its bytes match the saved
18
+ checksum, otherwise declares the first usable standard location. With neither,
19
+ setup reports Graph as unavailable and completes its remaining steps. An
20
+ explicit `--engine` executable is never replaced by another one.
21
+
14
22
  Provider hooks never download an executable. The catalog can connect and replay
15
23
  questions independently of Engine installation and repository analysis.
16
24
  The monitor prepares a missing or outdated managed Engine in the background,
17
25
  retries failed downloads and recovers verified bindings once it becomes healthy.
26
+ When an update cannot be downloaded, a declared Engine that still verifies stays
27
+ in use until the helper next starts. A platform with no pinned release and no
28
+ declared Engine leaves Graph unavailable without a retry loop.
18
29
  Explicit disablement and custom executable declarations remain in force.
19
30
 
20
31
  License: GrantTap Commercial Source License, in the repository-root `LICENSE`.
@@ -10,10 +10,9 @@ export type EngineArtifact = {
10
10
  export const ENGINE_ARTIFACTS: readonly EngineArtifact[] = [
11
11
  { version: "0.1.7", platform: "darwin", arch: "arm64",
12
12
  sha256: "bf7fcf3d08d78a437da21fcb88057d77840be4b22a0f7388f383059e685a76ef", bytes: 12201856 },
13
- { version: "0.1.2", platform: "darwin", arch: "x64",
14
- sha256: "b3235a15936a77ec323d5ecbc54a0bc19994fe6e5a36044da964b68524b4c1dd", bytes: 13944984 },
15
- { version: "0.1.2", platform: "linux", arch: "x64",
16
- sha256: "1a6b227289b69459a64cd13078044960cf83bb858e6be1b70b1b38c950b00cc0", bytes: 14753312 },
13
+ // The 0.1.2 Intel Mac and Linux x64 builds are no longer published. Without a
14
+ // pin, setup reports Graph as unavailable and the helper does not retry a 404;
15
+ // an Engine already installed and verified on such a computer keeps working.
17
16
  ];
18
17
 
19
18
  export function selectEngineArtifact(platform: string = process.platform, arch: string = process.arch): EngineArtifact | undefined {
@@ -5,7 +5,8 @@ import { engineArtifactName, type EngineArtifact } from "./artifacts";
5
5
  export async function downloadEngine(artifact: EngineArtifact, fetcher: typeof fetch): Promise<Buffer> {
6
6
  const url = `https://granttap.com/downloads/engine/${artifact.version}/${engineArtifactName(artifact)}`;
7
7
  const response = await fetcher(url, { redirect: "error", credentials: "omit",
8
- headers: { "Accept-Encoding": "identity" }, signal: AbortSignal.timeout(120_000) });
8
+ headers: { "Accept-Encoding": "identity" }, signal: AbortSignal.timeout(120_000) })
9
+ .catch(() => { throw new Error("Engine download could not reach granttap.com"); });
9
10
  if (!response.ok || response.redirected) throw new Error("Verified Engine download is unavailable");
10
11
  const length = response.headers.get("content-length");
11
12
  if (length !== null && Number(length) !== artifact.bytes) throw new Error("Engine download size is invalid");
@@ -1,3 +1,3 @@
1
- export { installEngineArtifact, prepareEngine } from "./installation";
1
+ export { installEngineArtifact, prepareEngine, prepareSetupEngine, type SetupEngine } from "./installation";
2
2
  export { selectEngineArtifact, type EngineArtifact } from "./artifacts";
3
3
  export { prepareMonitorEngine } from "./monitor";
@@ -1,6 +1,6 @@
1
1
  import { join } from "node:path";
2
- import { configDir, loadRuntimeConfig, saveRuntimeConfig } from "../../config";
3
- import { declarationFor, type EngineDeclaration } from "../protocol/engine-declaration";
2
+ import { configDir, loadRuntimeConfig, saveRuntimeConfig, verifiableEngine } from "../../config";
3
+ import { declarationFor, declareEngine, defaultEngineLocations, type EngineDeclaration } from "../protocol/engine-declaration";
4
4
  import { verifyEngineBinary } from "../runtime/engine-supervisor";
5
5
  import { activateConfiguredEngine } from "../startup";
6
6
  import { selectEngineArtifact, validateEngineArtifact, type EngineArtifact } from "./artifacts";
@@ -9,6 +9,12 @@ import { privateEngineDirectory, writeEngineExecutable } from "./storage";
9
9
 
10
10
  export { selectEngineArtifact, type EngineArtifact } from "./artifacts";
11
11
 
12
+ /** Host selection and network are injectable so tests never depend on this computer's release. */
13
+ export type EnginePreparationOptions = { platform?: string; arch?: string; fetcher?: typeof fetch };
14
+
15
+ /** Setup's outcome: the declared Engine, if any, and why the pinned release could not be prepared. */
16
+ export type SetupEngine = { declaration: EngineDeclaration | null; reason?: string };
17
+
12
18
  export async function installEngineArtifact(artifact: EngineArtifact, options: {
13
19
  directory?: string; fetcher?: typeof fetch;
14
20
  } = {}): Promise<EngineDeclaration> {
@@ -25,20 +31,61 @@ export async function installEngineArtifact(artifact: EngineArtifact, options: {
25
31
  }
26
32
 
27
33
  /** Setup only: downloads never run in a provider hook or delay the first catalog. */
28
- export async function prepareEngine(explicitPath?: string): Promise<EngineDeclaration> {
34
+ export async function prepareEngine(explicitPath?: string, options: EnginePreparationOptions = {}): Promise<EngineDeclaration> {
29
35
  const configured = loadRuntimeConfig();
30
36
  const managedRoot = join(configDir(), "engine");
31
37
  const customPath = explicitPath ?? (configured.enginePath && !configured.enginePath.startsWith(managedRoot + "/")
32
38
  && !configured.enginePath.startsWith(managedRoot + "\\") ? configured.enginePath : undefined);
33
39
  const declaration = customPath ? declarationFor(customPath)
34
- : await installEngineArtifact(selectEngineArtifact() ?? missingArtifact());
35
- if (!declaration) throw new Error("The selected Engine must be an executable regular file");
40
+ : await installEngineArtifact(selectEngineArtifact(options.platform, options.arch) ?? missingArtifact(),
41
+ { fetcher: options.fetcher });
42
+ if (!declaration) {
43
+ throw new Error(explicitPath ? "The selected Engine must be an executable regular file"
44
+ : "The configured Engine is no longer an executable regular file");
45
+ }
36
46
  saveRuntimeConfig({ enginePath: declaration.path, engineSha256: declaration.sha256 });
47
+ activate(declaration);
48
+ return declaration;
49
+ }
50
+
51
+ /**
52
+ * Setup never aborts for a missing Engine. When the pinned release cannot be
53
+ * prepared, a verified Engine already declared here is kept; otherwise the
54
+ * standard locations are searched. With neither, Graph stays unavailable.
55
+ * An explicitly selected executable is never replaced by another one.
56
+ */
57
+ export async function prepareSetupEngine(explicitPath?: string, options: EnginePreparationOptions & {
58
+ locations?: string[];
59
+ } = {}): Promise<SetupEngine> {
60
+ try {
61
+ return { declaration: await prepareEngine(explicitPath, options) };
62
+ } catch (error) {
63
+ const reason = (error instanceof Error ? error.message : String(error)).replace(/\.+$/, "");
64
+ const kept = explicitPath ? null
65
+ : await installedEngine(options.locations ?? defaultEngineLocations()).catch(() => null);
66
+ if (kept) activate(kept);
67
+ return { declaration: kept, reason };
68
+ }
69
+ }
70
+
71
+ async function installedEngine(locations: string[]): Promise<EngineDeclaration | null> {
72
+ const previous = verifiableEngine(loadRuntimeConfig());
73
+ // The saved checksum is the trust anchor for the previous Engine; it is never re-derived from changed bytes.
74
+ if (previous) {
75
+ try { return await verifyEngineBinary(previous.path, previous.sha256); } catch { /* Search the standard locations. */ }
76
+ }
77
+ for (const location of locations) {
78
+ const declaration = declareEngine(location);
79
+ if (declaration) return declaration;
80
+ }
81
+ return null;
82
+ }
83
+
84
+ function activate(declaration: EngineDeclaration): void {
37
85
  // Setup's preload may still contain the previous managed declaration.
38
86
  process.env.GRANTTAP_ENGINE_BINARY = declaration.path;
39
87
  process.env.GRANTTAP_ENGINE_SHA256 = declaration.sha256;
40
88
  activateConfiguredEngine();
41
- return declaration;
42
89
  }
43
90
 
44
91
  function missingArtifact(): never { throw new Error("No verified Engine release is available for this computer yet"); }
@@ -1,10 +1,13 @@
1
1
  import { isAbsolute, join, relative, sep } from "node:path";
2
2
  import { configDir, loadRuntimeConfig, saveRuntimeConfig, verifiableEngine } from "../../../config";
3
+ import type { EngineDeclaration } from "../../protocol/engine-declaration";
4
+ import { verifyEngineBinary } from "../../runtime/engine-supervisor";
3
5
  import { activateConfiguredEngine } from "../../startup";
4
6
  import { selectEngineArtifact, type EngineArtifact } from "../artifacts";
5
7
  import { installEngineArtifact } from "../installation";
6
8
 
7
- type MonitorPreparation = { env?: NodeJS.ProcessEnv; artifact?: EngineArtifact; fetcher?: typeof fetch };
9
+ /** `artifact: null` stands for a platform with no pinned release. */
10
+ type MonitorPreparation = { env?: NodeJS.ProcessEnv; artifact?: EngineArtifact | null; fetcher?: typeof fetch };
8
11
 
9
12
  /** Monitor only: repair the managed installation without touching custom declarations or policy. */
10
13
  export async function prepareMonitorEngine(options: MonitorPreparation = {}): Promise<boolean> {
@@ -18,9 +21,21 @@ export async function prepareMonitorEngine(options: MonitorPreparation = {}): Pr
18
21
  activateConfiguredEngine(env);
19
22
  return true;
20
23
  }
21
- const artifact = options.artifact ?? selectEngineArtifact();
22
- if (!artifact) throw new Error("No verified Engine release is available for this computer yet");
23
- const declaration = await installEngineArtifact(artifact, { fetcher: options.fetcher });
24
+ const artifact = options.artifact === null ? undefined : options.artifact ?? selectEngineArtifact();
25
+ let declaration: EngineDeclaration;
26
+ try {
27
+ if (!artifact) throw new Error("No verified Engine release is available for this computer yet");
28
+ declaration = await installEngineArtifact(artifact, { fetcher: options.fetcher });
29
+ } catch (error) {
30
+ // A failed update keeps the verified Engine already declared here; the next helper start retries.
31
+ if (configured && await verified(configured)) {
32
+ activateConfiguredEngine(env);
33
+ return true;
34
+ }
35
+ // No release for this platform cannot change while this helper runs: Graph stays unavailable, not retried.
36
+ if (!artifact) return false;
37
+ throw error;
38
+ }
24
39
  const current = loadRuntimeConfig();
25
40
  // A settings change made during an offline or slow download wins over this preparation.
26
41
  if (disabledOrPartial(env)) return false;
@@ -34,6 +49,10 @@ export async function prepareMonitorEngine(options: MonitorPreparation = {}): Pr
34
49
  return true;
35
50
  }
36
51
 
52
+ async function verified(engine: { path: string; sha256: string }): Promise<boolean> {
53
+ try { await verifyEngineBinary(engine.path, engine.sha256); return true; } catch { return false; }
54
+ }
55
+
37
56
  function disabledOrPartial(env: NodeJS.ProcessEnv): boolean {
38
57
  const flag = env.GRANTTAP_ENGINE_ENABLED?.trim().toLowerCase();
39
58
  if (flag !== undefined && flag !== "1" && flag !== "true") return true;
@@ -32,6 +32,33 @@ function token(value: unknown): string | undefined {
32
32
  && !/[\r\n]/.test(value) ? value : undefined;
33
33
  }
34
34
 
35
+ /** Claude Code's saved login record, from its file or the macOS Keychain; never refreshed or written. */
36
+ async function claudeCredentialRecord(options: Options = {}): Promise<any> {
37
+ const home = options.home ?? homedir();
38
+ const env = options.env ?? process.env;
39
+ const platform = options.platform ?? process.platform;
40
+ const keychain = options.keychain ?? readNativeKeychain;
41
+ const keychainAllowed = options.keychain !== undefined || home === userInfo().homedir;
42
+ const override = env.GRANTTAP_CLAUDE_DIR ?? env.NODVOX_CLAUDE_DIR ?? env.CLAUDE_CONFIG_DIR;
43
+ const saved = await jsonFile(join(override ?? join(home, ".claude"), ".credentials.json"));
44
+ if (claudeToken(saved, options.now ?? Date.now()) || platform !== "darwin" || override || !keychainAllowed) return saved;
45
+ if (!await jsonFile(join(home, ".claude", "settings.json"))) return saved;
46
+ try {
47
+ const raw = await keychain("Claude Code-credentials");
48
+ return raw ? JSON.parse(raw) : saved;
49
+ } catch { return saved; }
50
+ }
51
+
52
+ /**
53
+ * Whether Claude Code's own login can be used. An expired one used to read as
54
+ * "no limits reported", which blamed the computer for a login that had lapsed.
55
+ */
56
+ export async function claudeCredentialState(options: Options = {}): Promise<"valid" | "expired" | "absent"> {
57
+ const record = await claudeCredentialRecord(options);
58
+ if (!record?.claudeAiOauth) return "absent";
59
+ return claudeToken(record, options.now ?? Date.now()) ? "valid" : "expired";
60
+ }
61
+
35
62
  function claudeToken(value: any, now: number): string | undefined {
36
63
  const row = value?.claudeAiOauth;
37
64
  return typeof row?.expiresAt === "number" && row.expiresAt <= now ? undefined : token(row?.accessToken);
@@ -51,14 +78,7 @@ export async function readNativeCredential(provider: NativeUsageProvider, option
51
78
  .find(Boolean);
52
79
  }
53
80
  if (provider === "claude") {
54
- const override = env.GRANTTAP_CLAUDE_DIR ?? env.NODVOX_CLAUDE_DIR ?? env.CLAUDE_CONFIG_DIR;
55
- const saved = claudeToken(await jsonFile(join(override ?? join(home, ".claude"), ".credentials.json")), options.now ?? Date.now());
56
- if (saved || platform !== "darwin" || override || !keychainAllowed) return saved;
57
- if (!await jsonFile(join(home, ".claude", "settings.json"))) return undefined;
58
- try {
59
- const raw = await keychain("Claude Code-credentials");
60
- return raw ? claudeToken(JSON.parse(raw), options.now ?? Date.now()) : undefined;
61
- } catch { return undefined; }
81
+ return claudeToken(await claudeCredentialRecord(options), options.now ?? Date.now());
62
82
  }
63
83
  const root = platform === "win32" ? join(env.APPDATA ?? join(home, "AppData", "Roaming"), "Cursor")
64
84
  : platform === "darwin" ? join(home, ".cursor") : join(env.XDG_CONFIG_HOME ?? join(home, ".config"), "cursor");
@@ -1,11 +1,12 @@
1
1
  import { homedir } from "node:os";
2
2
  import type { ProviderAccountUsage } from "../../../../../packages/protocol/schema";
3
3
  import { readClaudeUsage } from "../claude-statusline";
4
- import { readNativeCredential } from "./credentials";
5
- import { createNativeAccountUsageReader } from "./reader";
4
+ import { claudeCredentialState, readNativeCredential } from "./credentials";
5
+ import { createNativeAccountUsageReader, isSignedOutUsage } from "./reader";
6
6
 
7
7
  let scope = "";
8
8
  const create = () => createNativeAccountUsageReader({ credential: readNativeCredential,
9
+ expired: async provider => provider === "claude" && await claudeCredentialState() === "expired",
9
10
  report: (provider, reason) => process.stderr.write(reason
10
11
  ? `[granttap-mcp] ${provider} account limits unavailable: ${reason}\n`
11
12
  : `[granttap-mcp] ${provider} account limits readable again\n`) });
@@ -17,7 +18,8 @@ export function mergeNativeUsage(direct: ProviderAccountUsage[], statusLine: Pro
17
18
  for (const report of [...direct, ...statusLine]) {
18
19
  const key = `${report.provider}\u001f${report.limitId}`;
19
20
  const windows = report.windows.filter(window => window.resetsAt > now);
20
- if (!windows.length || now - report.observedAt > 300_000 || report.observedAt > now + 60_000) continue;
21
+ if ((!windows.length && !isSignedOutUsage(report)) || now - report.observedAt > 300_000
22
+ || report.observedAt > now + 60_000) continue;
21
23
  if ((newest.get(key)?.observedAt ?? -Infinity) <= report.observedAt) newest.set(key, { ...report, windows });
22
24
  }
23
25
  return [...newest.values()];
@@ -3,6 +3,8 @@ import { projectCursorPeriodUsage, projectNativeAccountUsage, type NativeUsagePr
3
3
 
4
4
  type Options = {
5
5
  credential: (provider: NativeUsageProvider) => Promise<string | undefined>;
6
+ /** Tells an expired login from none, so a lapsed login is reported rather than silent. */
7
+ expired?: (provider: NativeUsageProvider) => Promise<boolean>;
6
8
  fetcher?: (url: string, init: RequestInit) => Promise<Response>;
7
9
  clock?: () => number;
8
10
  /** Told when a signed-in account's limits become unreadable or readable again; never given a credential. */
@@ -15,6 +17,19 @@ const requests = {
15
17
  grok: { url: "https://cli-chat-proxy.grok.com/v1/billing?format=credits", method: "GET" },
16
18
  } as const;
17
19
 
20
+ /**
21
+ * A limit report with no windows whose id ends in ":signed-out": the provider is
22
+ * installed but its own login has lapsed. The wire format is unchanged, so older
23
+ * phones show no numbers and newer ones say why.
24
+ */
25
+ export const SIGNED_OUT_SUFFIX = ":signed-out";
26
+ export function signedOutUsage(provider: NativeUsageProvider, now: number): ProviderAccountUsage {
27
+ return { provider, limitId: `${provider}${SIGNED_OUT_SUFFIX}`, observedAt: now, windows: [] };
28
+ }
29
+ export function isSignedOutUsage(report: ProviderAccountUsage): boolean {
30
+ return report.windows.length === 0 && report.limitId.endsWith(SIGNED_OUT_SUFFIX);
31
+ }
32
+
18
33
  async function boundedResponse(response: Response): Promise<unknown> {
19
34
  if (!response.ok || !response.body) return undefined;
20
35
  const reader = response.body.getReader();
@@ -50,7 +65,13 @@ export function createNativeAccountUsageReader(options: Options) {
50
65
  async function update(provider: NativeUsageProvider): Promise<void> {
51
66
  try {
52
67
  const token = await options.credential(provider);
53
- if (!token) { reports.delete(provider); reasons.delete(provider); return; }
68
+ if (!token) {
69
+ if (await options.expired?.(provider)) {
70
+ reports.set(provider, signedOutUsage(provider, clock()));
71
+ note(provider, "the provider's console login has expired");
72
+ } else { reports.delete(provider); reasons.delete(provider); }
73
+ return;
74
+ }
54
75
  const request = requests[provider];
55
76
  const response = await fetcher(request.url, {
56
77
  method: request.method, redirect: "error", signal: AbortSignal.timeout(8_000),
@@ -83,7 +104,8 @@ export function createNativeAccountUsageReader(options: Options) {
83
104
  const now = clock();
84
105
  return [...reports.values()].flatMap(report => {
85
106
  const windows = report.windows.filter(window => window.resetsAt > now);
86
- return now - report.observedAt <= 300_000 && windows.length ? [{ ...report, windows }] : [];
107
+ return now - report.observedAt <= 300_000 && (windows.length || isSignedOutUsage(report))
108
+ ? [{ ...report, windows }] : [];
87
109
  });
88
110
  },
89
111
  refresh(): Promise<void> {
@@ -28,7 +28,7 @@ const usage = [
28
28
  "GrantTap — personal control center for local coding agents",
29
29
  "",
30
30
  "Usage:",
31
- " granttap setup Detect agents and install or repair GrantTap",
31
+ " granttap setup [--help] Detect agents and install or repair GrantTap",
32
32
  " granttap status [--json] Show pairing, helper, and provider readiness",
33
33
  " granttap connect [--relay <url>] Pair this computer with iPhone/Apple Watch",
34
34
  " granttap phone add Show a QR for another controller phone",
@@ -36,6 +36,7 @@ const usage = [
36
36
  " granttap reset [--yes] Reset this computer's phone pairing",
37
37
  " granttap mesh connect <invite> Redeem a one-time Grok Bot Mesh invite",
38
38
  " granttap restrictions check [dir] Check files against Mesh / .granttap restrictions",
39
+ " granttap --version Print the installed GrantTap version",
39
40
  "",
40
41
  "The legacy granttap-mcp command is an alias for granttap.",
41
42
  "",
@@ -45,6 +46,11 @@ if (command === "help" || command === "--help" || command === "-h") {
45
46
  process.stdout.write(usage);
46
47
  process.exit(0);
47
48
  }
49
+ if (command === "version" || command === "--version" || command === "-v") {
50
+ // The selected runtime is what every other command runs, so its version is the one reported.
51
+ process.stdout.write(`${runtimeVersion(root)}\n`);
52
+ process.exit(0);
53
+ }
48
54
 
49
55
  let entry;
50
56
  if (command === "mcp") {
@@ -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.164
13
+ npm install -g granttap-mcp@0.8.166
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.164\";\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.166\";\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.164";
10
+ const PACKAGE = "granttap-mcp@0.8.166";
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.164",
3
+ "version": "0.8.166",
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": {