granttap-mcp 0.8.197 → 0.8.198
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 +1 -1
- package/apps/bridge/src/provider-model-catalog/README.md +36 -18
- package/apps/bridge/src/provider-model-catalog/claude/claude-model-cache.ts +133 -0
- package/apps/bridge/src/provider-model-catalog/claude/claude-model-memory.ts +74 -0
- package/apps/bridge/src/provider-model-catalog/{claude-models.ts → claude/claude-models.ts} +7 -64
- package/apps/bridge/src/provider-model-catalog/index.ts +1 -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
- /package/apps/bridge/src/provider-model-catalog/{claude-account-scope.ts → claude/claude-account-scope.ts} +0 -0
package/README.md
CHANGED
|
@@ -73,7 +73,7 @@ service need a durable path, not npm's temporary `npx` cache.
|
|
|
73
73
|
|
|
74
74
|
## What's new
|
|
75
75
|
|
|
76
|
-
Available now, with GrantTap MCP 0.8.
|
|
76
|
+
Available now, with GrantTap MCP 0.8.198 on npm and GrantTap 1.0.2 on the App Store:
|
|
77
77
|
|
|
78
78
|
- **Phones on the connection card.** In Claude (including the Claude desktop app),
|
|
79
79
|
Codex, Cursor and Grok Build, the GrantTap card lists every phone paired with
|
|
@@ -51,31 +51,49 @@ without Grok's installer directory no longer hides it.
|
|
|
51
51
|
|
|
52
52
|
Claude Code exposes its picker metadata in the `initialize` control response
|
|
53
53
|
([official API reference](https://code.claude.com/docs/en/agent-sdk/typescript#sdkcontrolinitializeresponse)).
|
|
54
|
-
`claude-models.ts` requests that metadata without a user message, tools, hooks,
|
|
54
|
+
`claude/claude-models.ts` requests that metadata without a user message, tools, hooks,
|
|
55
55
|
MCP servers or saved conversation. It preserves exact CLI values, versioned labels,
|
|
56
56
|
order and supported effort levels. The Default row is represented by Automatic in
|
|
57
|
-
the client. Account identity is discarded.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
57
|
+
the client. Account identity is discarded. The query may take 60 s: by hand it
|
|
58
|
+
answered in 0.2–7 s, and on 2–3 November the monitor's own query ran out of 30 s
|
|
59
|
+
twice beside 89–140 Codex processes. A deadline reached while the monitor's event
|
|
60
|
+
loop was held reads an answer already waiting in the pipe before it gives up.
|
|
61
|
+
|
|
62
|
+
`claude/claude-model-cache.ts` shares one bounded query at a time among all catalog
|
|
63
|
+
readers and never blocks catalog polling. Live rows win. A good answer is asked
|
|
64
|
+
again after ten minutes and stays offered for an hour, so a failed refresh never
|
|
65
|
+
empties the list; a failed query is retried after 15 s, then every two minutes.
|
|
66
|
+
Changed settings keep the answer until the new one arrives; another Claude Code,
|
|
67
|
+
config directory or account (an opaque digest, see below) starts with none.
|
|
68
|
+
`claude/claude-model-memory.ts` keeps the last answer of each Claude Code and account in
|
|
69
|
+
`~/.granttap/claude-models.json` (projected rows and opaque digests only, at most
|
|
70
|
+
four answers and 256 KB), so a restarted monitor publishes it at once instead of
|
|
71
|
+
four unnamed aliases; the phone shows the newest report it holds, and on
|
|
72
|
+
18 November it listed "Opus" two minutes after a monitor restart. While Claude
|
|
73
|
+
Code is installed (`GRANTTAP_CLAUDE_BIN`, `PATH`, the native installer or the
|
|
74
|
+
Claude app's copy) but no answer is current, the catalog advertises the CLI's
|
|
75
|
+
documented aliases (`opus`, `sonnet`, `haiku`, `fable`, in that order), which the
|
|
76
|
+
installed CLI resolves itself, so the phone always has a list. Each alias carries
|
|
77
|
+
the name, description and effort levels that the same Claude Code and account
|
|
78
|
+
gave it in their last answer (`Opus 5.5`); without one it stays `Opus` with the
|
|
79
|
+
phone's localization key as its description, and no version is invented. A Mac
|
|
80
|
+
without Claude Code advertises no Claude rows and starts nothing. Every failed
|
|
81
|
+
query, and every catalog read that offers the aliases, writes one line to the
|
|
82
|
+
process's stderr (the monitor log): `[granttap] Claude Code model list query
|
|
83
|
+
failed (…)` and `[granttap] Claude Code model list unavailable, offering its
|
|
84
|
+
aliases as …: why`.
|
|
85
|
+
Tests: [`claude/tests/claude-models.test.ts`](claude/tests/claude-models.test.ts),
|
|
86
|
+
[`claude/tests/claude-aliases.test.ts`](claude/tests/claude-aliases.test.ts),
|
|
87
|
+
[`claude/tests/claude-model-cache.test.ts`](claude/tests/claude-model-cache.test.ts).
|
|
72
88
|
|
|
73
89
|
Claude account invalidation uses an opaque digest of account, organization and
|
|
74
90
|
model-entitlement fields, rather than the modification time of `.claude.json`.
|
|
75
91
|
CLI initialization updates startup counters and profile refresh dates in that
|
|
76
92
|
file; those writes must not discard its own reply or repeatedly launch the CLI.
|
|
77
|
-
Credential and settings-file changes still
|
|
78
|
-
account
|
|
93
|
+
Credential and settings-file changes still start a new query for their own scope
|
|
94
|
+
(`claude/claude-account-scope.ts`), while the same account's answer stays offered
|
|
95
|
+
until it arrives. A read that catches `.claude.json` half-written keeps the last
|
|
96
|
+
readable account digest instead of counting as another account. The account reader is bounded to 4 MiB and 16 cached file signatures, retaining only
|
|
79
97
|
digests. Raw account fields and API keys never enter the model report or cache key.
|
|
80
98
|
Tests cover self-updating initialization, one metadata subprocess per unchanged
|
|
81
99
|
account, actual account changes, private fields, malformed data and retention.
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { statSync } from 'node:fs';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import type { AdvertisedModel } from '../../../../../packages/protocol/schema';
|
|
6
|
+
import { installedClaudeBinary } from '../../providers/claude-bin';
|
|
7
|
+
import { claudeAccountScope } from './claude-account-scope';
|
|
8
|
+
import { claudeModelMemoryPath, recallClaudeModels, rememberClaudeModels } from './claude-model-memory';
|
|
9
|
+
import { readClaudeModels } from './claude-models';
|
|
10
|
+
|
|
11
|
+
/** A good answer is asked again after ten minutes and stays offered for an hour, so one failed query never empties the list. */
|
|
12
|
+
export const CLAUDE_MODEL_REFRESH_MS = 10 * 60_000;
|
|
13
|
+
export const CLAUDE_MODEL_KEEP_MS = 60 * 60_000;
|
|
14
|
+
/** A failed query is retried after 15 s, then every two minutes. */
|
|
15
|
+
export const CLAUDE_MODEL_RETRY_MS: readonly number[] = [15_000, 2 * 60_000];
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* `--model` documents these aliases, and the installed CLI resolves each to a
|
|
19
|
+
* concrete version. Their names come from that CLI's own last answer when this
|
|
20
|
+
* Claude Code and account gave one; otherwise no version is invented. The
|
|
21
|
+
* descriptions are the phone's own localization keys.
|
|
22
|
+
*/
|
|
23
|
+
const ALIASES: ReadonlyArray<{ modelId: string; label: string; description: string }> = [
|
|
24
|
+
{ modelId: 'opus', label: 'Opus', description: 'Latest Opus alias · complex reasoning tasks.' },
|
|
25
|
+
{ modelId: 'sonnet', label: 'Sonnet', description: 'Latest Sonnet alias · everyday coding tasks.' },
|
|
26
|
+
{ modelId: 'haiku', label: 'Haiku', description: 'Latest Haiku alias · fast, efficient simple tasks.' },
|
|
27
|
+
{ modelId: 'fable', label: 'Fable',
|
|
28
|
+
description: 'Fable alias · hardest and longest-running tasks. May require usage credits.' },
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
export type ClaudeModelCacheOptions = { now?: () => number; memory?: string; timeoutMs?: number };
|
|
32
|
+
type Log = (line: string) => void;
|
|
33
|
+
|
|
34
|
+
const state = { scope: '', identity: '', checkedAt: 0, failures: 0, reason: '' };
|
|
35
|
+
/** The answer offered for this scope: this one's, or the same Claude Code and account's before its settings changed. */
|
|
36
|
+
let report: AdvertisedModel[] = [];
|
|
37
|
+
/** The latest answer this Claude Code and account gave, whatever its age: the aliases' names. */
|
|
38
|
+
let named: AdvertisedModel[] = [];
|
|
39
|
+
let pending: Promise<void> | undefined;
|
|
40
|
+
|
|
41
|
+
const stderrLog: Log = line => { process.stderr.write(`[granttap] ${line}\n`); };
|
|
42
|
+
const digest = (parts: unknown[]) => createHash('sha256').update(JSON.stringify(parts)).digest('hex');
|
|
43
|
+
|
|
44
|
+
function modified(path: string): string {
|
|
45
|
+
try { const info = statSync(path); return `${info.mtimeMs}:${info.ctimeMs}`; } catch { return ''; }
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const readable = new Map<string, string>();
|
|
49
|
+
|
|
50
|
+
/** Claude Code rewrites `.claude.json` all the time; a read that catches it half-written is not another account. */
|
|
51
|
+
function account(file: string): string {
|
|
52
|
+
const scope = claudeAccountScope(file);
|
|
53
|
+
if (scope !== 'unavailable') readable.set(file, scope);
|
|
54
|
+
return readable.get(file) ?? scope;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function nextCheck(): number {
|
|
58
|
+
if (state.failures > 0) return CLAUDE_MODEL_RETRY_MS[Math.min(state.failures, CLAUDE_MODEL_RETRY_MS.length) - 1]!;
|
|
59
|
+
return report.length ? CLAUDE_MODEL_REFRESH_MS : 0;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Another account never inherits rows; changed settings keep the old answer until the new one arrives. */
|
|
63
|
+
function adopt(scope: string, identity: string, endpointId: string, memory: string): void {
|
|
64
|
+
if (identity !== state.identity) { report = []; named = []; }
|
|
65
|
+
Object.assign(state, { scope, identity, checkedAt: 0, failures: 0, reason: '' });
|
|
66
|
+
const saved = recallClaudeModels(memory, identity, endpointId);
|
|
67
|
+
if (!saved) return;
|
|
68
|
+
if (!named.length) named = saved.rows;
|
|
69
|
+
if (!report.length && saved.scope === scope) report = saved.rows;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
type Query = { memory: string; now: () => number; log: Log; timeoutMs?: number };
|
|
73
|
+
|
|
74
|
+
function query(binary: string, endpointId: string, env: NodeJS.ProcessEnv, { memory, now, log, timeoutMs }: Query): void {
|
|
75
|
+
state.checkedAt = now();
|
|
76
|
+
const { scope, identity } = state;
|
|
77
|
+
let failure = 'listed no usable models';
|
|
78
|
+
pending = readClaudeModels(binary, endpointId, { env, timeoutMs, onFailure: reason => { failure = reason; } })
|
|
79
|
+
.then(rows => {
|
|
80
|
+
if (state.scope !== scope) return;
|
|
81
|
+
if (rows.length) {
|
|
82
|
+
const at = now();
|
|
83
|
+
report = named = rows.map(row => ({ ...row, observedAt: at }));
|
|
84
|
+
Object.assign(state, { failures: 0, reason: '' });
|
|
85
|
+
rememberClaudeModels(memory, { identity, scope, rows: report });
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
state.failures += 1;
|
|
89
|
+
state.reason = failure;
|
|
90
|
+
log(`Claude Code model list query failed (${state.failures} in a row, next in ${nextCheck() / 1000} s`
|
|
91
|
+
+ `${report.length ? '; its last answer stays offered' : ''}): ${failure}`);
|
|
92
|
+
}).finally(() => { pending = undefined; });
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function aliasRows(endpointId: string, observedAt: number): AdvertisedModel[] {
|
|
96
|
+
return ALIASES.map((alias, priority) => {
|
|
97
|
+
const answer = named.find(row => row.modelId === alias.modelId && row.label);
|
|
98
|
+
return { ...alias, provider: 'claude' as const, endpointId, observedAt, source: 'advertised' as const, priority,
|
|
99
|
+
...(answer ? { label: answer.label, description: answer.description ?? alias.description,
|
|
100
|
+
...(answer.supportedEfforts ? { supportedEfforts: answer.supportedEfforts } : {}) } : {}) };
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Nonblocking, one bounded metadata process at a time, shared by all catalog readers.
|
|
106
|
+
* Live picker rows win; an installed Claude Code without them still offers its aliases,
|
|
107
|
+
* and every catalog read that does so says why in one stderr line (the monitor log).
|
|
108
|
+
*/
|
|
109
|
+
export function cachedClaudeModels(endpointId: string, env = process.env, home = homedir(),
|
|
110
|
+
log: Log = stderrLog, options: ClaudeModelCacheOptions = {}): AdvertisedModel[] {
|
|
111
|
+
const binary = installedClaudeBinary(home, env);
|
|
112
|
+
if (!binary) return [];
|
|
113
|
+
const now = options.now ?? Date.now, memory = options.memory ?? claudeModelMemoryPath();
|
|
114
|
+
const config = env.GRANTTAP_CLAUDE_DIR ?? env.NODVOX_CLAUDE_DIR ?? env.CLAUDE_CONFIG_DIR;
|
|
115
|
+
const root = config ?? join(home, '.claude');
|
|
116
|
+
const identity = digest([endpointId, binary.path, binary.version, root,
|
|
117
|
+
account(config ? join(root, '.claude.json') : join(home, '.claude.json'))]);
|
|
118
|
+
const scope = digest([identity, modified(join(root, '.credentials.json')),
|
|
119
|
+
modified(join(root, 'settings.json')), modified(join(root, 'settings.local.json'))]);
|
|
120
|
+
if (scope !== state.scope) adopt(scope, identity, endpointId, memory);
|
|
121
|
+
if (!pending && now() - state.checkedAt >= nextCheck()) {
|
|
122
|
+
query(binary.path, endpointId, config ? { ...env, CLAUDE_CONFIG_DIR: config } : env,
|
|
123
|
+
{ memory, now, log, timeoutMs: options.timeoutMs });
|
|
124
|
+
}
|
|
125
|
+
const at = now();
|
|
126
|
+
const live = report.filter(row => at - row.observedAt <= CLAUDE_MODEL_KEEP_MS);
|
|
127
|
+
if (live.length) return live;
|
|
128
|
+
const rows = aliasRows(endpointId, at);
|
|
129
|
+
const why = [report.length ? `its last answer is more than ${CLAUDE_MODEL_KEEP_MS / 60_000} min old` : '',
|
|
130
|
+
state.reason || (report.length ? '' : 'its first answer has not arrived')].filter(Boolean).join('; ');
|
|
131
|
+
log(`Claude Code model list unavailable, offering its aliases as ${rows.map(row => row.label).join(', ')}: ${why}`);
|
|
132
|
+
return rows;
|
|
133
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { closeSync, fstatSync, openSync, readSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import type { AdvertisedModel } from '../../../../../packages/protocol/schema';
|
|
4
|
+
import { configDir } from '../../config/runtime/paths';
|
|
5
|
+
import { writePrivateFile } from '../../config/access/write-private';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Claude Code's last picker answer, kept across monitor restarts.
|
|
9
|
+
*
|
|
10
|
+
* Every monitor start used to publish the four unnamed aliases to every
|
|
11
|
+
* Project until its first query answered, and the phone shows the newest
|
|
12
|
+
* report it holds: on 18 November the monitor restarted at 23:16:19 and the
|
|
13
|
+
* owner's phone listed "Opus" without its version at 23:18. Only projected
|
|
14
|
+
* picker rows are kept, under opaque digests of which Claude Code, account
|
|
15
|
+
* and settings gave them; never the account payload.
|
|
16
|
+
*/
|
|
17
|
+
export type ClaudeModelAnswer = { identity: string; scope: string; rows: AdvertisedModel[] };
|
|
18
|
+
|
|
19
|
+
const MAX_BYTES = 256 * 1024;
|
|
20
|
+
const MAX_ANSWERS = 4;
|
|
21
|
+
const DIGEST = /^[0-9a-f]{64}$/;
|
|
22
|
+
const ID = /^[a-zA-Z0-9][a-zA-Z0-9._:/-]{0,159}$/;
|
|
23
|
+
const EFFORTS = new Set(['low', 'medium', 'high', 'xhigh', 'max']);
|
|
24
|
+
|
|
25
|
+
export function claudeModelMemoryPath(): string {
|
|
26
|
+
return join(configDir(), 'claude-models.json');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const bounded = (value: unknown, max: number) => typeof value === 'string' && value.length <= max ? value : undefined;
|
|
30
|
+
|
|
31
|
+
function row(value: unknown, endpointId: string): AdvertisedModel | undefined {
|
|
32
|
+
const item = value as Record<string, unknown> | null;
|
|
33
|
+
if (!item || typeof item !== 'object' || typeof item.modelId !== 'string' || !ID.test(item.modelId)
|
|
34
|
+
|| typeof item.observedAt !== 'number' || !Number.isFinite(item.observedAt)) return undefined;
|
|
35
|
+
const efforts = Array.isArray(item.supportedEfforts)
|
|
36
|
+
? item.supportedEfforts.filter((level): level is NonNullable<AdvertisedModel['supportedEfforts']>[number] =>
|
|
37
|
+
typeof level === 'string' && EFFORTS.has(level)) : undefined;
|
|
38
|
+
return { modelId: item.modelId, provider: 'claude', endpointId, source: 'advertised', observedAt: item.observedAt,
|
|
39
|
+
label: bounded(item.label, 160), description: bounded(item.description, 240),
|
|
40
|
+
...(Number.isInteger(item.priority) ? { priority: item.priority as number } : {}),
|
|
41
|
+
...(efforts ? { supportedEfforts: efforts } : {}) };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function readAnswers(path: string): unknown[] {
|
|
45
|
+
let fd: number | undefined;
|
|
46
|
+
try {
|
|
47
|
+
fd = openSync(path, 'r');
|
|
48
|
+
const size = fstatSync(fd).size;
|
|
49
|
+
if (size > MAX_BYTES) return [];
|
|
50
|
+
const bytes = Buffer.alloc(size);
|
|
51
|
+
const answers = JSON.parse(bytes.subarray(0, readSync(fd, bytes, 0, size, 0)).toString('utf8'))?.answers;
|
|
52
|
+
return Array.isArray(answers) ? answers.slice(0, MAX_ANSWERS) : [];
|
|
53
|
+
} catch { return []; } finally { if (fd !== undefined) closeSync(fd); }
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** The last answer this Claude Code gave for this account, if one was kept. */
|
|
57
|
+
export function recallClaudeModels(path: string, identity: string, endpointId: string): ClaudeModelAnswer | undefined {
|
|
58
|
+
const saved = readAnswers(path).find(item => (item as ClaudeModelAnswer | null)?.identity === identity) as
|
|
59
|
+
{ scope?: unknown; rows?: unknown } | undefined;
|
|
60
|
+
if (!saved || typeof saved.scope !== 'string' || !DIGEST.test(saved.scope) || !Array.isArray(saved.rows)) return undefined;
|
|
61
|
+
const rows = saved.rows.slice(0, 64).flatMap(item => row(item, endpointId) ?? []);
|
|
62
|
+
return rows.length ? { identity, scope: saved.scope, rows } : undefined;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Keep the newest answer of each Claude Code and account; a failed write only costs the next restart its names. */
|
|
66
|
+
export function rememberClaudeModels(path: string, answer: ClaudeModelAnswer): void {
|
|
67
|
+
const rows = answer.rows.slice(0, 64).map(({ modelId, label, description, priority, supportedEfforts, observedAt }) =>
|
|
68
|
+
({ modelId, label, description, priority, supportedEfforts, observedAt }));
|
|
69
|
+
const others = readAnswers(path).filter(item => (item as ClaudeModelAnswer | null)?.identity !== answer.identity);
|
|
70
|
+
try {
|
|
71
|
+
writePrivateFile(path, JSON.stringify({ answers: [{ identity: answer.identity, scope: answer.scope, rows },
|
|
72
|
+
...others].slice(0, MAX_ANSWERS) }));
|
|
73
|
+
} catch { /* The live answer is still served from memory. */ }
|
|
74
|
+
}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import { createInterface } from 'node:readline';
|
|
3
3
|
import { homedir } from 'node:os';
|
|
4
|
-
import {
|
|
5
|
-
import { join } from 'node:path';
|
|
6
|
-
import type { AdvertisedModel } from '../../../../packages/protocol/schema';
|
|
7
|
-
import { installedClaudeBinary } from '../providers/claude-bin';
|
|
8
|
-
import { claudeAccountScope } from './claude-account-scope';
|
|
4
|
+
import type { AdvertisedModel } from '../../../../../packages/protocol/schema';
|
|
9
5
|
|
|
10
6
|
const ID = /^[a-zA-Z0-9][a-zA-Z0-9._:/-]{0,159}$/;
|
|
11
7
|
const EFFORTS = new Set(['low', 'medium', 'high', 'xhigh', 'max']);
|
|
@@ -29,35 +25,19 @@ export function projectClaudeModels(value: unknown, endpointId: string, now: num
|
|
|
29
25
|
});
|
|
30
26
|
}
|
|
31
27
|
|
|
32
|
-
/**
|
|
33
|
-
* `--model` documents these aliases, and the installed CLI resolves each to a
|
|
34
|
-
* concrete version, so none is invented here. The descriptions are the phone's
|
|
35
|
-
* own localization keys.
|
|
36
|
-
*/
|
|
37
|
-
const ALIASES: ReadonlyArray<{ modelId: string; label: string; description: string }> = [
|
|
38
|
-
{ modelId: 'opus', label: 'Opus', description: 'Latest Opus alias · complex reasoning tasks.' },
|
|
39
|
-
{ modelId: 'sonnet', label: 'Sonnet', description: 'Latest Sonnet alias · everyday coding tasks.' },
|
|
40
|
-
{ modelId: 'haiku', label: 'Haiku', description: 'Latest Haiku alias · fast, efficient simple tasks.' },
|
|
41
|
-
{ modelId: 'fable', label: 'Fable',
|
|
42
|
-
description: 'Fable alias · hardest and longest-running tasks. May require usage credits.' },
|
|
43
|
-
];
|
|
44
|
-
|
|
45
|
-
function claudeAliasRows(endpointId: string, now: number): AdvertisedModel[] {
|
|
46
|
-
return ALIASES.map((alias, priority) => ({ ...alias, provider: 'claude' as const, endpointId,
|
|
47
|
-
observedAt: now, source: 'advertised' as const, priority }));
|
|
48
|
-
}
|
|
49
|
-
|
|
50
28
|
export type ClaudeModelQuery = { timeoutMs?: number; cwd?: string; env?: NodeJS.ProcessEnv;
|
|
51
29
|
onFailure?: (reason: string) => void };
|
|
52
30
|
|
|
31
|
+
/** By hand it answered in 0.2–7 s; on 2–3 November the monitor's own query ran out of 30 s twice beside 89–140 Codex processes. */
|
|
32
|
+
export const CLAUDE_MODEL_QUERY_TIMEOUT_MS = 60_000;
|
|
33
|
+
|
|
53
34
|
/**
|
|
54
35
|
* No prompt, saved session, hooks, MCP children or tools. Never persists the account payload.
|
|
55
|
-
* Startup took 2–7 s by hand on an idle Mac; a busy monitor runs several CLIs beside it.
|
|
56
36
|
*/
|
|
57
37
|
export async function readClaudeModels(binary: string, endpointId: string,
|
|
58
38
|
options: ClaudeModelQuery = {}): Promise<AdvertisedModel[]> {
|
|
59
39
|
return new Promise(resolve => {
|
|
60
|
-
const timeoutMs = options.timeoutMs ??
|
|
40
|
+
const timeoutMs = options.timeoutMs ?? CLAUDE_MODEL_QUERY_TIMEOUT_MS;
|
|
61
41
|
const child = spawn(binary, ['--print', '--input-format', 'stream-json', '--output-format', 'stream-json',
|
|
62
42
|
'--verbose', '--no-session-persistence', '--strict-mcp-config', '--mcp-config', '{"mcpServers":{}}',
|
|
63
43
|
'--settings', '{"disableAllHooks":true}', '--tools', ''],
|
|
@@ -74,7 +54,8 @@ export async function readClaudeModels(binary: string, endpointId: string,
|
|
|
74
54
|
if (!rows.length) options.onFailure?.(said ? `${failure}: ${said}` : failure);
|
|
75
55
|
resolve(rows);
|
|
76
56
|
};
|
|
77
|
-
|
|
57
|
+
// A monitor whose event loop was held past the deadline reads the answer already waiting in the pipe first.
|
|
58
|
+
const timeout = setTimeout(() => setImmediate(() => stop([], `timed out after ${timeoutMs / 1000} s`)), timeoutMs);
|
|
78
59
|
child.on('error', error => stop([], `could not start (${(error as NodeJS.ErrnoException).code ?? error.name})`));
|
|
79
60
|
// `close` follows the last stderr bytes, so the reason a CLI gave on its way out is kept.
|
|
80
61
|
child.on('close', (code, signal) => stop([], `exited with ${signal ?? `code ${code}`} before answering`));
|
|
@@ -96,41 +77,3 @@ export async function readClaudeModels(binary: string, endpointId: string,
|
|
|
96
77
|
request: { subtype: 'initialize' } }) + '\n');
|
|
97
78
|
});
|
|
98
79
|
}
|
|
99
|
-
|
|
100
|
-
let scope = '', report: AdvertisedModel[] = [], checkedAt = 0, recorded = '';
|
|
101
|
-
let pending: Promise<void> | undefined;
|
|
102
|
-
const stderrLog = (line: string) => { process.stderr.write(`[granttap] ${line}\n`); };
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Nonblocking, one bounded metadata process at a time, shared by all catalog readers.
|
|
106
|
-
* Live picker rows win; an installed Claude Code without them still offers its aliases.
|
|
107
|
-
*/
|
|
108
|
-
export function cachedClaudeModels(endpointId: string, env = process.env, home = homedir(),
|
|
109
|
-
log: (line: string) => void = stderrLog): AdvertisedModel[] {
|
|
110
|
-
const binary = installedClaudeBinary(home, env);
|
|
111
|
-
if (!binary) return [];
|
|
112
|
-
const config = env.GRANTTAP_CLAUDE_DIR ?? env.NODVOX_CLAUDE_DIR ?? env.CLAUDE_CONFIG_DIR;
|
|
113
|
-
const root = config ?? join(home, '.claude');
|
|
114
|
-
const key = [endpointId, binary.path, binary.version, root,
|
|
115
|
-
modified(join(root, '.credentials.json')), claudeAccountScope(config ? join(root, '.claude.json') : join(home, '.claude.json')),
|
|
116
|
-
modified(join(root, 'settings.json')), modified(join(root, 'settings.local.json'))].join('\u001f');
|
|
117
|
-
if (key !== scope) { scope = key; report = []; checkedAt = 0; }
|
|
118
|
-
if (!pending && Date.now() - checkedAt > (report.length ? 10 : 2) * 60_000) {
|
|
119
|
-
checkedAt = Date.now();
|
|
120
|
-
const onFailure = (reason: string) => {
|
|
121
|
-
if (reason !== recorded) log(`Claude Code model list unavailable, offering its aliases: ${reason}`);
|
|
122
|
-
recorded = reason;
|
|
123
|
-
};
|
|
124
|
-
pending = readClaudeModels(binary.path, endpointId, { env: config ? { ...env, CLAUDE_CONFIG_DIR: config } : env, onFailure })
|
|
125
|
-
.then(rows => {
|
|
126
|
-
if (rows.length) recorded = '';
|
|
127
|
-
if (scope === key) report = rows;
|
|
128
|
-
}).finally(() => { pending = undefined; });
|
|
129
|
-
}
|
|
130
|
-
const live = report.filter(row => Date.now() - row.observedAt <= 15 * 60_000);
|
|
131
|
-
return live.length ? live : claudeAliasRows(endpointId, Date.now());
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function modified(path: string): string {
|
|
135
|
-
try { const info = statSync(path); return `${info.mtimeMs}:${info.ctimeMs}`; } catch { return ''; }
|
|
136
|
-
}
|
|
@@ -3,7 +3,7 @@ import { homedir } from "node:os";
|
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import type { AdvertisedModel, EndpointModelCatalog } from "../../../../packages/protocol/schema";
|
|
5
5
|
|
|
6
|
-
import { cachedClaudeModels } from "./claude-
|
|
6
|
+
import { cachedClaudeModels } from "./claude/claude-model-cache";
|
|
7
7
|
import { cachedCLIModels } from "./cli-models";
|
|
8
8
|
import { cachedNativeAccountUsage, cachedProviderAccount } from "../provider-account-status";
|
|
9
9
|
|
package/cursor-plugin/README.md
CHANGED
|
@@ -18,7 +18,7 @@ keeps each phone response tied to the exact originating chat and prompt.
|
|
|
18
18
|
Install the supported CLI on this computer, then run:
|
|
19
19
|
|
|
20
20
|
```bash
|
|
21
|
-
npm install -g granttap-mcp@0.8.
|
|
21
|
+
npm install -g granttap-mcp@0.8.198
|
|
22
22
|
granttap setup
|
|
23
23
|
granttap status
|
|
24
24
|
```
|
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.198\";\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.198";
|
|
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.
|
|
3
|
+
"version": "0.8.198",
|
|
4
4
|
"description": "Approve, answer and steer Claude Code, Codex, Cursor and Grok Build from iPhone, iPad and Apple Watch: the local runtime, CLI and MCP server for GrantTap, a free App Store download.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
File without changes
|