granttap-mcp 0.8.167 → 0.8.169
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 +6 -0
- package/apps/bridge/src/provider-account-status/native-usage/index.ts +7 -3
- package/apps/bridge/src/provider-account-status/native-usage/memory.ts +84 -0
- package/apps/bridge/src/provider-account-status/native-usage/reader.ts +29 -21
- package/apps/bridge/src/provider-account-status/native-usage/saved.ts +33 -0
- package/apps/bridge/src/reply/process/auth-failure.ts +22 -3
- package/apps/bridge/src/task-transfer/index.ts +18 -1
- 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
|
@@ -67,6 +67,12 @@ export async function claudeCredentialState(options: Options = {}): Promise<"val
|
|
|
67
67
|
return claudeToken(record, options.now ?? Date.now()) ? "valid" : "expired";
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
/** A live login whose access token has run out: only Claude Code's next run renews it, and nothing is read until then. */
|
|
71
|
+
export async function claudeAccessRenewable(options: Options = {}): Promise<boolean> {
|
|
72
|
+
const record = await claudeCredentialRecord(options);
|
|
73
|
+
return !!token(record?.claudeAiOauth?.refreshToken) && !claudeToken(record, options.now ?? Date.now());
|
|
74
|
+
}
|
|
75
|
+
|
|
70
76
|
function claudeToken(value: any, now: number): string | undefined {
|
|
71
77
|
const row = value?.claudeAiOauth;
|
|
72
78
|
return typeof row?.expiresAt === "number" && row.expiresAt <= now ? undefined : token(row?.accessToken);
|
|
@@ -1,8 +1,9 @@
|
|
|
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 { claudeCredentialState, readNativeCredential } from "./credentials";
|
|
5
|
-
import { createNativeAccountUsageReader, isSignedOutUsage } from "./reader";
|
|
4
|
+
import { claudeAccessRenewable, claudeCredentialState, readNativeCredential } from "./credentials";
|
|
5
|
+
import { createNativeAccountUsageReader, HELD_USAGE_MS, isSignedOutUsage } from "./reader";
|
|
6
|
+
import { savedNativeUsage } from "./saved";
|
|
6
7
|
import { providerAuthentication } from "../../device-management/provider-command";
|
|
7
8
|
|
|
8
9
|
/**
|
|
@@ -17,6 +18,8 @@ export async function claudeLoginLapsed(read = () => claudeCredentialState(),
|
|
|
17
18
|
let scope = "";
|
|
18
19
|
const create = () => createNativeAccountUsageReader({ credential: readNativeCredential,
|
|
19
20
|
expired: async provider => provider === "claude" && await claudeLoginLapsed(),
|
|
21
|
+
renewable: async provider => provider === "claude" && await claudeAccessRenewable(),
|
|
22
|
+
saved: savedNativeUsage(),
|
|
20
23
|
report: (provider, reason) => process.stderr.write(reason
|
|
21
24
|
? `[granttap-mcp] ${provider} account limits unavailable: ${reason}\n`
|
|
22
25
|
: `[granttap-mcp] ${provider} account limits readable again\n`) });
|
|
@@ -28,7 +31,8 @@ export function mergeNativeUsage(direct: ProviderAccountUsage[], statusLine: Pro
|
|
|
28
31
|
for (const report of [...direct, ...statusLine]) {
|
|
29
32
|
const key = `${report.provider}\u001f${report.limitId}`;
|
|
30
33
|
const windows = report.windows.filter(window => window.resetsAt > now);
|
|
31
|
-
|
|
34
|
+
const held = isSignedOutUsage(report) ? 300_000 : HELD_USAGE_MS;
|
|
35
|
+
if ((!windows.length && !isSignedOutUsage(report)) || now - report.observedAt > held
|
|
32
36
|
|| report.observedAt > now + 60_000) continue;
|
|
33
37
|
if ((newest.get(key)?.observedAt ?? -Infinity) <= report.observedAt) newest.set(key, { ...report, windows });
|
|
34
38
|
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { ProviderAccountUsage } from "../../../../../packages/protocol/schema";
|
|
2
|
+
import type { NativeUsageProvider } from "./projection";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* What every GrantTap process on this computer shares: the last good readings, kept across restarts,
|
|
6
|
+
* and the time before which a provider must not be asked again. Numbers only, never a credential.
|
|
7
|
+
*/
|
|
8
|
+
export type SharedUsage = { read: () => ProviderAccountUsage[]; write: (reports: ProviderAccountUsage[]) => void;
|
|
9
|
+
notBefore?: () => Record<string, number>; defer?: (provider: string, until: number) => void };
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A provider limits how often its account may be read: Claude answers the fifth quick request with
|
|
13
|
+
* 429 and five minutes of refusals. Dozens of GrantTap processes run on one computer, so they share
|
|
14
|
+
* one read per provider every three minutes, wait as long as a refusal names, and otherwise back off.
|
|
15
|
+
*/
|
|
16
|
+
const READ_EVERY_MS = 180_000;
|
|
17
|
+
/** How often one process looks at the shared state; the network is asked far less often. */
|
|
18
|
+
export const CHECK_EVERY_MS = 60_000;
|
|
19
|
+
const BACKOFF_MS = 60_000, BACKOFF_MAX_MS = 600_000, RETRY_AFTER_MAX_MS = 900_000;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A limit report with no windows whose id ends in ":signed-out": the provider is
|
|
23
|
+
* installed but its own login has lapsed. The wire format is unchanged, so older
|
|
24
|
+
* phones show no numbers and newer ones say why.
|
|
25
|
+
*/
|
|
26
|
+
export const SIGNED_OUT_SUFFIX = ":signed-out";
|
|
27
|
+
export function signedOutUsage(provider: NativeUsageProvider, now: number): ProviderAccountUsage {
|
|
28
|
+
return { provider, limitId: `${provider}${SIGNED_OUT_SUFFIX}`, observedAt: now, windows: [] };
|
|
29
|
+
}
|
|
30
|
+
export function isSignedOutUsage(report: ProviderAccountUsage): boolean {
|
|
31
|
+
return report.windows.length === 0 && report.limitId.endsWith(SIGNED_OUT_SUFFIX);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The readings one process holds, kept in step with the other processes on the computer. */
|
|
35
|
+
export function createUsageMemory(saved: SharedUsage | undefined, clock: () => number, known: (provider: string) => boolean) {
|
|
36
|
+
const reports = new Map<NativeUsageProvider, ProviderAccountUsage>();
|
|
37
|
+
const pauses = new Map<NativeUsageProvider, number>(), failures = new Map<NativeUsageProvider, number>();
|
|
38
|
+
const notBefore = (provider: NativeUsageProvider) => {
|
|
39
|
+
let shared = -Infinity;
|
|
40
|
+
try { shared = Number(saved?.notBefore?.()[provider] ?? -Infinity); } catch { /* Only this process's pause is known. */ }
|
|
41
|
+
return Math.max(pauses.get(provider) ?? -Infinity, Number.isFinite(shared) ? shared : -Infinity);
|
|
42
|
+
};
|
|
43
|
+
const defer = (provider: NativeUsageProvider, until: number) => {
|
|
44
|
+
pauses.set(provider, until);
|
|
45
|
+
try { saved?.defer?.(provider, until); } catch { /* Best effort. */ }
|
|
46
|
+
};
|
|
47
|
+
const restore = () => {
|
|
48
|
+
try {
|
|
49
|
+
for (const report of saved?.read() ?? []) {
|
|
50
|
+
const held = reports.get(report.provider as NativeUsageProvider);
|
|
51
|
+
if (known(report.provider) && !isSignedOutUsage(report) && (held?.observedAt ?? -Infinity) < report.observedAt
|
|
52
|
+
&& (!held || !isSignedOutUsage(held))) reports.set(report.provider as NativeUsageProvider, report);
|
|
53
|
+
}
|
|
54
|
+
} catch { /* A missing or damaged file only means nothing is remembered. */ }
|
|
55
|
+
};
|
|
56
|
+
restore();
|
|
57
|
+
return {
|
|
58
|
+
reports, restore,
|
|
59
|
+
remember(): void {
|
|
60
|
+
restore();
|
|
61
|
+
try { saved?.write([...reports.values()].filter(report => !isSignedOutUsage(report))); } catch { /* Best effort. */ }
|
|
62
|
+
},
|
|
63
|
+
/** Not while another process has just read it, or while the provider asked everyone to wait. */
|
|
64
|
+
due(provider: NativeUsageProvider, now: number): boolean {
|
|
65
|
+
const held = reports.get(provider);
|
|
66
|
+
return now >= notBefore(provider) && !(held && !isSignedOutUsage(held) && now - held.observedAt < READ_EVERY_MS);
|
|
67
|
+
},
|
|
68
|
+
claim(provider: NativeUsageProvider, now: number): void { defer(provider, now + READ_EVERY_MS); },
|
|
69
|
+
succeeded(provider: NativeUsageProvider): void { failures.delete(provider); },
|
|
70
|
+
/**
|
|
71
|
+
* A refused or failed request says nothing about the account: the last good reading stays. Every
|
|
72
|
+
* process waits as long as the provider asked, or twice as long after each failure in a row.
|
|
73
|
+
*/
|
|
74
|
+
refused(provider: NativeUsageProvider, response?: Response): void {
|
|
75
|
+
const count = (failures.get(provider) ?? 0) + 1;
|
|
76
|
+
failures.set(provider, count);
|
|
77
|
+
const asked = Number(response?.headers.get("retry-after"));
|
|
78
|
+
defer(provider, clock() + (Number.isFinite(asked) && asked > 0 ? Math.min(asked * 1_000, RETRY_AFTER_MAX_MS)
|
|
79
|
+
: Math.min(BACKOFF_MS * 2 ** (count - 1), BACKOFF_MAX_MS)));
|
|
80
|
+
if (isSignedOutUsage(reports.get(provider) ?? signedOutUsage(provider, 0))) reports.delete(provider);
|
|
81
|
+
restore();
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
|
@@ -1,35 +1,31 @@
|
|
|
1
1
|
import type { ProviderAccountUsage } from "../../../../../packages/protocol/schema";
|
|
2
2
|
import { projectCursorPeriodUsage, projectNativeAccountUsage, type NativeUsageProvider } from "./projection";
|
|
3
|
+
import { CHECK_EVERY_MS, createUsageMemory, isSignedOutUsage, signedOutUsage, type SharedUsage } from "./memory";
|
|
4
|
+
export { isSignedOutUsage, SIGNED_OUT_SUFFIX, signedOutUsage } from "./memory";
|
|
3
5
|
|
|
4
6
|
type Options = {
|
|
5
7
|
credential: (provider: NativeUsageProvider) => Promise<string | undefined>;
|
|
6
8
|
/** Tells an expired login from none, so a lapsed login is reported rather than silent. */
|
|
7
9
|
expired?: (provider: NativeUsageProvider) => Promise<boolean>;
|
|
10
|
+
/** The login is live, but its access token waits for the provider's own CLI to renew it. */
|
|
11
|
+
renewable?: (provider: NativeUsageProvider) => Promise<boolean>;
|
|
12
|
+
saved?: SharedUsage;
|
|
8
13
|
fetcher?: (url: string, init: RequestInit) => Promise<Response>;
|
|
9
14
|
clock?: () => number;
|
|
10
15
|
/** Told when a signed-in account's limits become unreadable or readable again; never given a credential. */
|
|
11
16
|
report?: (provider: NativeUsageProvider, reason: string | undefined) => void;
|
|
12
17
|
};
|
|
13
18
|
|
|
19
|
+
/** How long the last good reading is still offered, with the time it was really read, while reads fail. */
|
|
20
|
+
export const HELD_USAGE_MS = 24 * 3_600_000;
|
|
21
|
+
const MARKER_MS = 300_000;
|
|
22
|
+
|
|
14
23
|
const requests = {
|
|
15
24
|
claude: { url: "https://api.anthropic.com/api/oauth/usage", method: "GET" },
|
|
16
25
|
cursor: { url: "https://api2.cursor.sh/aiserver.v1.DashboardService/GetSandUsageStatus", method: "POST" },
|
|
17
26
|
grok: { url: "https://cli-chat-proxy.grok.com/v1/billing?format=credits", method: "GET" },
|
|
18
27
|
} as const;
|
|
19
28
|
|
|
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
|
-
|
|
33
29
|
async function boundedResponse(response: Response): Promise<unknown> {
|
|
34
30
|
if (!response.ok || !response.body) return undefined;
|
|
35
31
|
const reader = response.body.getReader();
|
|
@@ -51,7 +47,8 @@ async function boundedResponse(response: Response): Promise<unknown> {
|
|
|
51
47
|
export function createNativeAccountUsageReader(options: Options) {
|
|
52
48
|
const clock = options.clock ?? Date.now;
|
|
53
49
|
const fetcher = options.fetcher ?? fetch;
|
|
54
|
-
const
|
|
50
|
+
const memory = createUsageMemory(options.saved, clock, provider => provider in requests);
|
|
51
|
+
const { reports, restore, remember } = memory;
|
|
55
52
|
let pending: Promise<void> | undefined;
|
|
56
53
|
let attemptedAt = -Infinity;
|
|
57
54
|
// Missing limits used to leave no trace; one line per change of reason keeps the log readable.
|
|
@@ -69,9 +66,19 @@ export function createNativeAccountUsageReader(options: Options) {
|
|
|
69
66
|
if (await options.expired?.(provider)) {
|
|
70
67
|
reports.set(provider, signedOutUsage(provider, clock()));
|
|
71
68
|
note(provider, "the provider's console login has expired");
|
|
72
|
-
} else
|
|
69
|
+
} else if (await options.renewable?.(provider)) {
|
|
70
|
+
// Nothing can be read until the provider's CLI runs again; what was read last still stands.
|
|
71
|
+
if (isSignedOutUsage(reports.get(provider) ?? signedOutUsage(provider, 0))) reports.delete(provider);
|
|
72
|
+
restore();
|
|
73
|
+
note(provider, "its saved access token has expired; the provider renews it on its next run");
|
|
74
|
+
} else { reports.delete(provider); reasons.delete(provider); remember(); }
|
|
73
75
|
return;
|
|
74
76
|
}
|
|
77
|
+
restore();
|
|
78
|
+
const now = clock();
|
|
79
|
+
// Another process on this computer has just read it, or the provider asked everyone to wait.
|
|
80
|
+
if (!memory.due(provider, now)) return;
|
|
81
|
+
memory.claim(provider, now);
|
|
75
82
|
const request = requests[provider];
|
|
76
83
|
const response = await fetcher(request.url, {
|
|
77
84
|
method: request.method, redirect: "error", signal: AbortSignal.timeout(8_000),
|
|
@@ -90,11 +97,12 @@ export function createNativeAccountUsageReader(options: Options) {
|
|
|
90
97
|
});
|
|
91
98
|
report = projectCursorPeriodUsage(await boundedResponse(legacy), clock());
|
|
92
99
|
}
|
|
93
|
-
if (report) reports.set(provider, report);
|
|
94
|
-
else reports.delete(provider);
|
|
100
|
+
if (report) { memory.succeeded(provider); reports.set(provider, report); remember(); }
|
|
101
|
+
else if (response.ok) reports.delete(provider);
|
|
102
|
+
else memory.refused(provider, response);
|
|
95
103
|
note(provider, report ? undefined : response.ok ? "unrecognized response" : `HTTP ${response.status}`);
|
|
96
104
|
} catch (error) {
|
|
97
|
-
|
|
105
|
+
memory.refused(provider);
|
|
98
106
|
note(provider, error instanceof Error ? error.name : "request failed");
|
|
99
107
|
}
|
|
100
108
|
}
|
|
@@ -104,13 +112,13 @@ export function createNativeAccountUsageReader(options: Options) {
|
|
|
104
112
|
const now = clock();
|
|
105
113
|
return [...reports.values()].flatMap(report => {
|
|
106
114
|
const windows = report.windows.filter(window => window.resetsAt > now);
|
|
107
|
-
return now - report.observedAt <=
|
|
108
|
-
? [{ ...report, windows }] : [];
|
|
115
|
+
return isSignedOutUsage(report) ? (now - report.observedAt <= MARKER_MS ? [report] : [])
|
|
116
|
+
: windows.length && now - report.observedAt <= HELD_USAGE_MS ? [{ ...report, windows }] : [];
|
|
109
117
|
});
|
|
110
118
|
},
|
|
111
119
|
refresh(): Promise<void> {
|
|
112
120
|
if (pending) return pending;
|
|
113
|
-
if (clock() - attemptedAt <
|
|
121
|
+
if (clock() - attemptedAt < CHECK_EVERY_MS) return Promise.resolve();
|
|
114
122
|
attemptedAt = clock();
|
|
115
123
|
pending = Promise.allSettled((Object.keys(requests) as NativeUsageProvider[]).map(update))
|
|
116
124
|
.then(() => undefined).finally(() => { pending = undefined; });
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { ProviderAccountUsage } from "../../../../../packages/protocol/schema";
|
|
5
|
+
import { configDir, writePrivateFile } from "../../config";
|
|
6
|
+
|
|
7
|
+
const Saved = z.array(ProviderAccountUsage).max(8);
|
|
8
|
+
const Pauses = z.record(z.string().max(40), z.number().finite());
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The last good account readings, shared by every GrantTap process on this computer and kept across
|
|
12
|
+
* restarts. A monitor that has just started, or whose next read fails, still knows what was read last.
|
|
13
|
+
* The file holds percentages and reset times only.
|
|
14
|
+
*/
|
|
15
|
+
export function savedNativeUsage(path = () => join(configDir(), "native-usage.json")) {
|
|
16
|
+
// Beside the readings: the time before which no process here may ask a provider again.
|
|
17
|
+
const schedule = () => path().replace(/\.json$/, "") + "-schedule.json";
|
|
18
|
+
const pauses = (): Record<string, number> => {
|
|
19
|
+
try { return Pauses.parse(JSON.parse(readFileSync(schedule(), "utf8"))); } catch { return {}; }
|
|
20
|
+
};
|
|
21
|
+
return {
|
|
22
|
+
notBefore: pauses,
|
|
23
|
+
defer(provider: string, until: number): void {
|
|
24
|
+
try { writePrivateFile(schedule(), JSON.stringify(Pauses.parse({ ...pauses(), [provider]: until }))); } catch { /* Best effort. */ }
|
|
25
|
+
},
|
|
26
|
+
read(): ProviderAccountUsage[] {
|
|
27
|
+
try { return Saved.parse(JSON.parse(readFileSync(path(), "utf8"))); } catch { return []; }
|
|
28
|
+
},
|
|
29
|
+
write(reports: ProviderAccountUsage[]): void {
|
|
30
|
+
try { writePrivateFile(path(), JSON.stringify(Saved.parse(reports))); } catch { /* Best effort. */ }
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -14,6 +14,22 @@ const SIGN_IN_REQUIRED = new RegExp([
|
|
|
14
14
|
String.raw`"type"\s*:\s*"authentication_error"`,
|
|
15
15
|
].join('|'), 'i');
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* A block page from the network protection in front of the provider, not an answer from the
|
|
19
|
+
* provider about the login. Claude Code words it "Failed to authenticate. API Error: 403
|
|
20
|
+
* Attention Required! | Cloudflare", which sent people to sign in again when the VPN was the cause.
|
|
21
|
+
*/
|
|
22
|
+
const NETWORK_BLOCK = /\b403\b[\s\S]{0,400}(?:attention required!?|just a moment\.\.\.|sorry, you have been blocked|\bcf-ray\b|\bcloudflare\b)/i;
|
|
23
|
+
|
|
24
|
+
/** The request never reached the provider's own service, so signing in again changes nothing. */
|
|
25
|
+
export function providerNetworkBlock(command: string, ...outputs: string[]): string | undefined {
|
|
26
|
+
const text = outputs.join('\n').replace(/\u001b\[[0-9;?]*[ -/]*[@-~]/g, '');
|
|
27
|
+
if (!NETWORK_BLOCK.test(text)) return;
|
|
28
|
+
const agent = providerAgent(command);
|
|
29
|
+
const provider = agent ? PROVIDER_NAMES[agent] : 'The coding agent';
|
|
30
|
+
return `${provider} could not reach its service: the request was blocked on the network (HTTP 403). This is not a sign-in problem. Check the VPN, proxy or network on the computer, then send the message again. This message has not been submitted to the agent.`;
|
|
31
|
+
}
|
|
32
|
+
|
|
17
33
|
export function providerAgent(command: string): CodingAgent | undefined {
|
|
18
34
|
const executable = basename(command).toLowerCase();
|
|
19
35
|
return executable.includes('grok') ? 'grok' : executable.includes('claude') ? 'claude'
|
|
@@ -25,10 +41,10 @@ const PROVIDER_NAMES: Record<CodingAgent, string> = { claude: 'Claude Code', cod
|
|
|
25
41
|
/** A native sign-in prompt before admission is actionable, not a minute-long delivery timeout. */
|
|
26
42
|
export function providerSignInFailure(command: string, ...outputs: string[]): string | undefined {
|
|
27
43
|
const text = outputs.join('\n').replace(/\u001b\[[0-9;?]*[ -/]*[@-~]/g, '');
|
|
28
|
-
if (!SIGN_IN_REQUIRED.test(text)) return;
|
|
44
|
+
if (!SIGN_IN_REQUIRED.test(text) || NETWORK_BLOCK.test(text)) return;
|
|
29
45
|
const agent = providerAgent(command);
|
|
30
46
|
const provider = agent ? PROVIDER_NAMES[agent] : 'the coding agent';
|
|
31
|
-
return `Sign-in required for ${provider}.
|
|
47
|
+
return `Sign-in required for ${provider}. Tap Sign in in this chat, or open Devices, choose this computer, then Sign in for ${provider}. This message has not been submitted to the agent.`;
|
|
32
48
|
}
|
|
33
49
|
|
|
34
50
|
export function isSignInFailure(error: string): boolean { return error.startsWith('Sign-in required for '); }
|
|
@@ -74,7 +90,10 @@ export function providerResultFailure(stdout: string): string | undefined {
|
|
|
74
90
|
}
|
|
75
91
|
|
|
76
92
|
export function providerExitFailure(command: string, stderr: string, stdout: string, code: number | null): string {
|
|
77
|
-
const
|
|
93
|
+
const said = providerResultFailure(stdout) ?? '';
|
|
94
|
+
const blocked = providerNetworkBlock(command, stderr, said);
|
|
95
|
+
if (blocked) return blocked;
|
|
96
|
+
const signIn = providerSignInFailure(command, stderr, said);
|
|
78
97
|
if (signIn) return signIn;
|
|
79
98
|
const reported = stderr.trim() ? undefined : providerResultFailure(stdout);
|
|
80
99
|
return providerUsageFailure(stderr)
|
|
@@ -12,6 +12,10 @@ type TransferProvider = {
|
|
|
12
12
|
};
|
|
13
13
|
const interrupted = (): ReplyResult => ({ ok: false,
|
|
14
14
|
error: 'The first transfer turn was interrupted. Inspect the destination provider before starting another execution.' });
|
|
15
|
+
/** A transport retry arrives within minutes; a message sent after this long is the person deliberately trying again. */
|
|
16
|
+
const RESTART_AFTER_MS = 10 * 60_000;
|
|
17
|
+
const interruptedUnopened = (): ReplyResult => ({ ok: false,
|
|
18
|
+
error: 'The first transfer turn was interrupted before the agent opened a chat. Send the message again after ten minutes to start it again.' });
|
|
15
19
|
|
|
16
20
|
/** Prepared executions are visible immediately and start only with a person's first message. */
|
|
17
21
|
export class PreparedTaskTransfers extends TransferPersistence {
|
|
@@ -49,7 +53,7 @@ export class PreparedTaskTransfers extends TransferPersistence {
|
|
|
49
53
|
}
|
|
50
54
|
|
|
51
55
|
async deliver(id: string, text: string, attachments: UserAttachment[], options: DeliveryOptions,
|
|
52
|
-
provider: TransferProvider): Promise<ReplyResult | undefined> {
|
|
56
|
+
provider: TransferProvider, now = Date.now()): Promise<ReplyResult | undefined> {
|
|
53
57
|
if (!/^transfer-[a-f0-9]{48}$/.test(id)) return undefined;
|
|
54
58
|
let row = this.load(id);
|
|
55
59
|
if (!row) return { ok: false, error: 'The prepared transfer is unavailable.' };
|
|
@@ -57,6 +61,19 @@ export class PreparedTaskTransfers extends TransferPersistence {
|
|
|
57
61
|
const result = await provider.resume({ ...this.session(row), sessionId: row.nativeSessionId }, text, attachments, options);
|
|
58
62
|
return result.ok ? { ...result, sessionId: id } : result;
|
|
59
63
|
}
|
|
64
|
+
if (row.phase === 'uncertain') {
|
|
65
|
+
// The launch that owned this transfer is over, whoever ran it. It used to refuse every later message for good.
|
|
66
|
+
if (row.nativeSessionId) {
|
|
67
|
+
// The agent did open its chat: the person's next message continues it, and nothing is started twice.
|
|
68
|
+
const result = await provider.resume({ ...this.session(row), sessionId: row.nativeSessionId }, text, attachments, options);
|
|
69
|
+
if (!result.ok) return result;
|
|
70
|
+
this.update(id, current => current.phase === 'uncertain' ? { ...current, phase: 'active', updatedAt: Date.now() } : current);
|
|
71
|
+
return { ...result, sessionId: id };
|
|
72
|
+
}
|
|
73
|
+
if (now - row.updatedAt < RESTART_AFTER_MS) return interruptedUnopened();
|
|
74
|
+
row = this.update(id, current => current.phase === 'uncertain' && !current.nativeSessionId
|
|
75
|
+
? { ...current, phase: 'prepared', ownerPid: undefined, updatedAt: Date.now() } : current);
|
|
76
|
+
}
|
|
60
77
|
if (row.phase !== 'prepared') return interrupted();
|
|
61
78
|
let ownsLaunch = false;
|
|
62
79
|
try {
|
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.169
|
|
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.169\";\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.169";
|
|
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;
|