granttap-mcp 0.8.164 → 0.8.165
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/apps/bridge/src/provider-account-status/native-usage/credentials.ts +28 -8
- package/apps/bridge/src/provider-account-status/native-usage/index.ts +5 -3
- package/apps/bridge/src/provider-account-status/native-usage/reader.ts +24 -2
- package/cursor-plugin/README.md +1 -1
- package/cursor-plugin/mcp.json +1 -1
- package/cursor-plugin/stdio-bootstrap.cjs +1 -1
- package/package.json +1 -1
|
@@ -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
|
-
|
|
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
|
|
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) {
|
|
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
|
|
107
|
+
return now - report.observedAt <= 300_000 && (windows.length || isSignedOutUsage(report))
|
|
108
|
+
? [{ ...report, windows }] : [];
|
|
87
109
|
});
|
|
88
110
|
},
|
|
89
111
|
refresh(): Promise<void> {
|
package/cursor-plugin/README.md
CHANGED
|
@@ -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.
|
|
13
|
+
npm install -g granttap-mcp@0.8.165
|
|
14
14
|
granttap setup
|
|
15
15
|
granttap status
|
|
16
16
|
```
|
package/cursor-plugin/mcp.json
CHANGED
|
@@ -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.
|
|
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.165\";\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.
|
|
10
|
+
const PACKAGE = "granttap-mcp@0.8.165";
|
|
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;
|