@gramatr/client 0.6.0 → 0.6.1
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/bin/add-api-key.ts +4 -4
- package/bin/clean-legacy-install.ts +1 -1
- package/bin/clear-creds.ts +8 -8
- package/bin/gmtr-login.ts +8 -8
- package/bin/gramatr.ts +4 -4
- package/bin/install.ts +9 -9
- package/bin/lib/config.ts +4 -4
- package/bin/logout.ts +5 -5
- package/bin/uninstall.ts +14 -14
- package/codex/install.ts +1 -1
- package/core/auth.ts +6 -6
- package/core/version.ts +2 -2
- package/gemini/install.ts +8 -8
- package/gemini/lib/gemini-install-utils.ts +2 -2
- package/hooks/StopOrchestrator.hook.ts +1 -1
- package/hooks/lib/gmtr-hook-utils.ts +9 -9
- package/hooks/lib/identity.ts +2 -2
- package/hooks/lib/paths.ts +1 -1
- package/hooks/session-start.hook.ts +1 -1
- package/package.json +1 -1
package/bin/add-api-key.ts
CHANGED
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
* 3. Env-sourced: gramatr add-api-key --from-env GRAMATR_API_KEY
|
|
9
9
|
*
|
|
10
10
|
* The key is validated against the gramatr server before being written
|
|
11
|
-
* to ~/.
|
|
11
|
+
* to ~/.gramatr.json. Use --force to skip server validation when offline.
|
|
12
12
|
*
|
|
13
|
-
* This command is the ONLY way to put an API key into ~/.
|
|
13
|
+
* This command is the ONLY way to put an API key into ~/.gramatr.json.
|
|
14
14
|
* Installers never prompt for API keys — see packages/client/core/auth.ts.
|
|
15
15
|
*/
|
|
16
16
|
|
|
@@ -20,7 +20,7 @@ import { join } from "path";
|
|
|
20
20
|
import { createInterface } from "readline";
|
|
21
21
|
|
|
22
22
|
function gmtrJsonPath(): string {
|
|
23
|
-
return join(process.env.HOME || process.env.USERPROFILE || homedir(), ".
|
|
23
|
+
return join(process.env.HOME || process.env.USERPROFILE || homedir(), ".gramatr.json");
|
|
24
24
|
}
|
|
25
25
|
const SERVER_BASE = (process.env.GRAMATR_URL || "https://api.gramatr.com").replace(/\/mcp\/?$/, "");
|
|
26
26
|
|
|
@@ -59,7 +59,7 @@ function parseArgs(argv: string[]): {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
function showHelp(): void {
|
|
62
|
-
log(`gramatr add-api-key — Add a gramatr API key to ~/.
|
|
62
|
+
log(`gramatr add-api-key — Add a gramatr API key to ~/.gramatr.json
|
|
63
63
|
|
|
64
64
|
Usage:
|
|
65
65
|
gramatr add-api-key Interactive prompt for the key
|
|
@@ -15,7 +15,7 @@ function main(): void {
|
|
|
15
15
|
|
|
16
16
|
const apply = process.argv.includes('--apply');
|
|
17
17
|
const includeOptionalUx = process.env.GRAMATR_ENABLE_OPTIONAL_CLAUDE_UX === '1';
|
|
18
|
-
const clientDir = process.env.GRAMATR_DIR || join(home, '
|
|
18
|
+
const clientDir = process.env.GRAMATR_DIR || join(home, '.gramatr');
|
|
19
19
|
runLegacyMigration({
|
|
20
20
|
homeDir: home,
|
|
21
21
|
clientDir,
|
package/bin/clear-creds.ts
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* gramatr clear-creds — Nuke ALL stored gramatr credentials.
|
|
4
4
|
*
|
|
5
|
-
* Stronger than `gramatr logout` (which only removes ~/.
|
|
5
|
+
* Stronger than `gramatr logout` (which only removes ~/.gramatr.json).
|
|
6
6
|
* This sweeps every credential location in the resolveAuthToken chain
|
|
7
7
|
* (core/auth.ts), so the next install/login is forced through OAuth.
|
|
8
8
|
*
|
|
9
9
|
* Locations cleared:
|
|
10
|
-
* 1. ~/.
|
|
11
|
-
* 2.
|
|
10
|
+
* 1. ~/.gramatr.json — deleted entirely
|
|
11
|
+
* 2. ~/.gramatr/settings.json `auth.api_key` — stripped, file preserved
|
|
12
12
|
*
|
|
13
13
|
* Env vars (GRAMATR_API_KEY, GRAMATR_TOKEN) cannot be cleared from a child
|
|
14
14
|
* process — they live in the parent shell. We detect them and warn.
|
|
@@ -24,11 +24,11 @@ function getHome(): string {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
function gmtrJsonPath(): string {
|
|
27
|
-
return join(getHome(), ".
|
|
27
|
+
return join(getHome(), ".gramatr.json");
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
function legacySettingsPath(): string {
|
|
31
|
-
const gmtrDir = process.env.GRAMATR_DIR || join(getHome(), "
|
|
31
|
+
const gmtrDir = process.env.GRAMATR_DIR || join(getHome(), ".gramatr");
|
|
32
32
|
return join(gmtrDir, "settings.json");
|
|
33
33
|
}
|
|
34
34
|
|
|
@@ -40,7 +40,7 @@ function showHelp(): void {
|
|
|
40
40
|
log(`gramatr clear-creds — Remove every stored gramatr credential
|
|
41
41
|
|
|
42
42
|
Usage:
|
|
43
|
-
gramatr clear-creds Sweep ~/.
|
|
43
|
+
gramatr clear-creds Sweep ~/.gramatr.json + auth.api_key from gmtr-client/settings.json
|
|
44
44
|
|
|
45
45
|
After running, the next install or login will be forced through OAuth.
|
|
46
46
|
|
|
@@ -61,14 +61,14 @@ export function clearAll(): ClearResult {
|
|
|
61
61
|
envVarsSet: [],
|
|
62
62
|
};
|
|
63
63
|
|
|
64
|
-
// 1. ~/.
|
|
64
|
+
// 1. ~/.gramatr.json — delete entirely
|
|
65
65
|
const gj = gmtrJsonPath();
|
|
66
66
|
if (existsSync(gj)) {
|
|
67
67
|
unlinkSync(gj);
|
|
68
68
|
result.removedGmtrJson = true;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
// 2.
|
|
71
|
+
// 2. ~/.gramatr/settings.json — strip auth.api_key, preserve rest
|
|
72
72
|
const ls = legacySettingsPath();
|
|
73
73
|
if (existsSync(ls)) {
|
|
74
74
|
try {
|
package/bin/gmtr-login.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* gmtr-login — Authenticate with the gramatr server
|
|
4
4
|
*
|
|
5
5
|
* Opens the grāmatr dashboard login flow, captures a Firebase ID token
|
|
6
|
-
* on localhost, and stores it in ~/.
|
|
6
|
+
* on localhost, and stores it in ~/.gramatr.json.
|
|
7
7
|
*
|
|
8
8
|
* Usage:
|
|
9
9
|
* bun gmtr-login.ts # Interactive browser login via Firebase dashboard
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* bun gmtr-login.ts --status # Check current auth status
|
|
12
12
|
* bun gmtr-login.ts --logout # Remove stored credentials
|
|
13
13
|
*
|
|
14
|
-
* Token is stored in ~/.
|
|
14
|
+
* Token is stored in ~/.gramatr.json under the "token" key.
|
|
15
15
|
* The GMTRPromptEnricher hook reads this on every prompt.
|
|
16
16
|
*/
|
|
17
17
|
|
|
@@ -23,7 +23,7 @@ import { createServer, type IncomingMessage, type ServerResponse } from 'http';
|
|
|
23
23
|
// ── Config ──
|
|
24
24
|
|
|
25
25
|
const HOME = process.env.HOME || process.env.USERPROFILE || '';
|
|
26
|
-
const CONFIG_PATH = join(HOME, '.
|
|
26
|
+
const CONFIG_PATH = join(HOME, '.gramatr.json');
|
|
27
27
|
const DEFAULT_SERVER = process.env.GRAMATR_URL || 'https://api.gramatr.com/mcp';
|
|
28
28
|
// Strip /mcp suffix to get base URL
|
|
29
29
|
const SERVER_BASE = DEFAULT_SERVER.replace(/\/mcp\/?$/, '');
|
|
@@ -317,7 +317,7 @@ async function logout(): Promise<void> {
|
|
|
317
317
|
delete config.token_expires;
|
|
318
318
|
delete config.authenticated_at;
|
|
319
319
|
writeConfig(config);
|
|
320
|
-
console.log('\n ✓ Logged out. Token removed from ~/.
|
|
320
|
+
console.log('\n ✓ Logged out. Token removed from ~/.gramatr.json\n');
|
|
321
321
|
}
|
|
322
322
|
|
|
323
323
|
async function loginWithToken(token: string): Promise<void> {
|
|
@@ -330,7 +330,7 @@ async function loginWithToken(token: string): Promise<void> {
|
|
|
330
330
|
config.token_type = token.startsWith('aios_sk_') || token.startsWith('gramatr_sk_') ? 'api_key' : 'oauth';
|
|
331
331
|
config.authenticated_at = new Date().toISOString();
|
|
332
332
|
writeConfig(config);
|
|
333
|
-
console.log(' ✓ Token valid. Saved to ~/.
|
|
333
|
+
console.log(' ✓ Token valid. Saved to ~/.gramatr.json');
|
|
334
334
|
console.log(' gramatr intelligence is now active.\n');
|
|
335
335
|
} else {
|
|
336
336
|
console.log(` ✗ Token rejected: ${result.error}`);
|
|
@@ -396,7 +396,7 @@ async function loginBrowser(): Promise<void> {
|
|
|
396
396
|
|
|
397
397
|
console.log('');
|
|
398
398
|
console.log(' ✓ Authenticated successfully');
|
|
399
|
-
console.log(' Token saved to ~/.
|
|
399
|
+
console.log(' Token saved to ~/.gramatr.json');
|
|
400
400
|
console.log(' gramatr intelligence is now active.\n');
|
|
401
401
|
return;
|
|
402
402
|
} catch (e: any) {
|
|
@@ -503,7 +503,7 @@ async function loginBrowser(): Promise<void> {
|
|
|
503
503
|
|
|
504
504
|
console.log('');
|
|
505
505
|
console.log(' ✓ Authenticated successfully');
|
|
506
|
-
console.log(' Token saved to ~/.
|
|
506
|
+
console.log(' Token saved to ~/.gramatr.json');
|
|
507
507
|
console.log(' gramatr intelligence is now active.\n');
|
|
508
508
|
} catch (e: any) {
|
|
509
509
|
console.log(`\n ✗ Authentication failed: ${e.message}\n`);
|
|
@@ -570,7 +570,7 @@ export async function main(): Promise<void> {
|
|
|
570
570
|
gmtr-login --logout Remove stored credentials
|
|
571
571
|
gmtr-login --help Show this help
|
|
572
572
|
|
|
573
|
-
Token storage: ~/.
|
|
573
|
+
Token storage: ~/.gramatr.json
|
|
574
574
|
Server: ${SERVER_BASE}
|
|
575
575
|
Dashboard: ${DASHBOARD_BASE}
|
|
576
576
|
`);
|
package/bin/gramatr.ts
CHANGED
|
@@ -205,7 +205,7 @@ function installTarget(targetId: IntegrationTargetId): void {
|
|
|
205
205
|
|
|
206
206
|
function migrate(apply: boolean, deep: boolean = false): void {
|
|
207
207
|
const homeDir = homedir();
|
|
208
|
-
const clientDir = process.env.GRAMATR_DIR || join(homeDir, '
|
|
208
|
+
const clientDir = process.env.GRAMATR_DIR || join(homeDir, '.gramatr');
|
|
209
209
|
runLegacyMigration({
|
|
210
210
|
homeDir,
|
|
211
211
|
clientDir,
|
|
@@ -220,7 +220,7 @@ function migrate(apply: boolean, deep: boolean = false): void {
|
|
|
220
220
|
}
|
|
221
221
|
|
|
222
222
|
function doctor(): void {
|
|
223
|
-
const gmtrDir = process.env.GRAMATR_DIR || join(homedir(), '
|
|
223
|
+
const gmtrDir = process.env.GRAMATR_DIR || join(homedir(), '.gramatr');
|
|
224
224
|
const stale = findStaleArtifacts(homedir(), gmtrDir, existsSync);
|
|
225
225
|
for (const line of formatDoctorLines(detectTargets(), gmtrDir, existsSync(gmtrDir), stale)) log(line);
|
|
226
226
|
renderRemoteGuidance();
|
|
@@ -228,7 +228,7 @@ function doctor(): void {
|
|
|
228
228
|
|
|
229
229
|
function upgrade(): void {
|
|
230
230
|
const homeDir = homedir();
|
|
231
|
-
const clientDir = process.env.GRAMATR_DIR || join(homeDir, '
|
|
231
|
+
const clientDir = process.env.GRAMATR_DIR || join(homeDir, '.gramatr');
|
|
232
232
|
const stale = findStaleArtifacts(homeDir, clientDir, existsSync);
|
|
233
233
|
if (stale.length > 0) {
|
|
234
234
|
log('Cleaning stale legacy artifacts before upgrade...');
|
|
@@ -344,7 +344,7 @@ function main(): void {
|
|
|
344
344
|
log(' install [target] Install gramatr (claude-code, codex, gemini-cli, all)');
|
|
345
345
|
log(' login Authenticate with the gramatr server (OAuth)');
|
|
346
346
|
log(' add-api-key Add an API key explicitly (interactive / piped / --from-env)');
|
|
347
|
-
log(' logout Clear session token (~/.
|
|
347
|
+
log(' logout Clear session token (~/.gramatr.json)');
|
|
348
348
|
log(' clear-creds Nuke ALL stored credentials, force OAuth on next login');
|
|
349
349
|
log(' detect Show detected CLI platforms');
|
|
350
350
|
log(' doctor Check installation health');
|
package/bin/install.ts
CHANGED
|
@@ -27,8 +27,8 @@ const HOME = process.env.HOME || process.env.USERPROFILE || '';
|
|
|
27
27
|
const CLAUDE_DIR = join(HOME, '.claude');
|
|
28
28
|
const CLAUDE_SETTINGS = join(CLAUDE_DIR, 'settings.json');
|
|
29
29
|
const CLAUDE_JSON = join(HOME, '.claude.json');
|
|
30
|
-
const CLIENT_DIR = join(HOME, '
|
|
31
|
-
const GMTR_JSON = join(HOME, '.
|
|
30
|
+
const CLIENT_DIR = join(HOME, '.gramatr');
|
|
31
|
+
const GMTR_JSON = join(HOME, '.gramatr.json');
|
|
32
32
|
const SCRIPT_DIR = dirname(dirname(resolve(import.meta.filename || __filename)));
|
|
33
33
|
const DEFAULT_URL = 'https://api.gramatr.com/mcp';
|
|
34
34
|
|
|
@@ -398,13 +398,13 @@ async function handleAuth(legacyToken: string): Promise<{ url: string; token: st
|
|
|
398
398
|
const url = await prompt('gramatr server URL', DEFAULT_URL) || DEFAULT_URL;
|
|
399
399
|
|
|
400
400
|
// Legacy aios token migration: if we cherry-picked a token from a prior
|
|
401
|
-
// aios install and there is no current ~/.
|
|
401
|
+
// aios install and there is no current ~/.gramatr.json token, seed it so the
|
|
402
402
|
// shared resolver picks it up.
|
|
403
403
|
if (legacyToken && !existsSync(GMTR_JSON)) {
|
|
404
404
|
try {
|
|
405
405
|
writeFileSync(GMTR_JSON, `${JSON.stringify({ token: legacyToken }, null, 2)}\n`, 'utf8');
|
|
406
406
|
try { chmodSync(GMTR_JSON, 0o600); } catch { /* ok */ }
|
|
407
|
-
log('OK Seeded ~/.
|
|
407
|
+
log('OK Seeded ~/.gramatr.json from legacy aios installation token');
|
|
408
408
|
} catch { /* ignore */ }
|
|
409
409
|
}
|
|
410
410
|
|
|
@@ -517,7 +517,7 @@ function updateClaudeSettings(url: string, token: string): void {
|
|
|
517
517
|
settings.env = settings.env || {};
|
|
518
518
|
settings.env.GRAMATR_DIR = CLIENT_DIR;
|
|
519
519
|
settings.env.GRAMATR_URL = url;
|
|
520
|
-
settings.env.PATH = `${HOME}/.
|
|
520
|
+
settings.env.PATH = `${HOME}/.gramatr/bin:/usr/local/bin:/usr/bin:/bin`;
|
|
521
521
|
if (token) settings.env.AIOS_MCP_TOKEN = token;
|
|
522
522
|
|
|
523
523
|
// Identity defaults (don't overwrite)
|
|
@@ -564,7 +564,7 @@ function registerMcpServer(url: string, token: string): void {
|
|
|
564
564
|
const backup = `${CLAUDE_JSON}.backup-${timestamp()}`;
|
|
565
565
|
cpSync(CLAUDE_JSON, backup);
|
|
566
566
|
|
|
567
|
-
// Store token in ~/.
|
|
567
|
+
// Store token in ~/.gramatr.json
|
|
568
568
|
if (token) {
|
|
569
569
|
mergeJson(GMTR_JSON, (data) => ({
|
|
570
570
|
...data,
|
|
@@ -572,10 +572,10 @@ function registerMcpServer(url: string, token: string): void {
|
|
|
572
572
|
token_updated_at: new Date().toISOString(),
|
|
573
573
|
}));
|
|
574
574
|
try { chmodSync(GMTR_JSON, 0o600); } catch { /* ok */ }
|
|
575
|
-
log('OK Token stored in ~/.
|
|
575
|
+
log('OK Token stored in ~/.gramatr.json (canonical source)');
|
|
576
576
|
}
|
|
577
577
|
|
|
578
|
-
// Write tool paths to ~/.
|
|
578
|
+
// Write tool paths to ~/.gramatr.json
|
|
579
579
|
mergeJson(GMTR_JSON, (data) => ({
|
|
580
580
|
...data,
|
|
581
581
|
jq_binary: which('jq') || '',
|
|
@@ -734,7 +734,7 @@ async function main(): Promise<void> {
|
|
|
734
734
|
if (!token) {
|
|
735
735
|
log(' 2. Run /gmtr-login in Claude Code to authenticate');
|
|
736
736
|
} else {
|
|
737
|
-
log(' 2. Already authenticated (token found in ~/.
|
|
737
|
+
log(' 2. Already authenticated (token found in ~/.gramatr.json)');
|
|
738
738
|
}
|
|
739
739
|
log('');
|
|
740
740
|
} else {
|
package/bin/lib/config.ts
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
* gramatr client config resolver (statusline refactor, #495).
|
|
3
3
|
*
|
|
4
4
|
* Single-purpose helper that returns the server URL + auth token with
|
|
5
|
-
* NO reads of ~/.claude* or
|
|
5
|
+
* NO reads of ~/.claude* or ~/.gramatr/settings.json. This is the
|
|
6
6
|
* statusline-specific config path; the richer installer auth lives in
|
|
7
7
|
* core/auth.ts for a reason — this file must stay small and side-effect-free
|
|
8
8
|
* so it can be loaded in a 2s shim without touching disk more than once.
|
|
9
9
|
*
|
|
10
10
|
* Resolution:
|
|
11
|
-
* URL — GRAMATR_URL → ~/.
|
|
12
|
-
* Token —
|
|
11
|
+
* URL — GRAMATR_URL → ~/.gramatr.json.url → https://api.gramatr.com
|
|
12
|
+
* Token — GRAMATR_API_KEY → ~/.gramatr.json.token → null
|
|
13
13
|
*/
|
|
14
14
|
import { existsSync, readFileSync } from 'fs';
|
|
15
15
|
import { homedir } from 'os';
|
|
@@ -27,7 +27,7 @@ function getHome(): string {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
function readGmtrJson(): Record<string, any> | null {
|
|
30
|
-
const path = join(getHome(), '.
|
|
30
|
+
const path = join(getHome(), '.gramatr.json');
|
|
31
31
|
if (!existsSync(path)) return null;
|
|
32
32
|
try {
|
|
33
33
|
return JSON.parse(readFileSync(path, 'utf8'));
|
package/bin/logout.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* gramatr logout — Clear stored gramatr credentials (issue #484).
|
|
4
4
|
*
|
|
5
|
-
* Removes ~/.
|
|
6
|
-
* ~/.
|
|
5
|
+
* Removes ~/.gramatr.json. With --keep-backup, renames it to
|
|
6
|
+
* ~/.gramatr.json.bak.<timestamp> instead of deleting.
|
|
7
7
|
*
|
|
8
8
|
* Not-logged-in is not an error: exits 0 with a clean message.
|
|
9
9
|
*/
|
|
@@ -13,7 +13,7 @@ import { homedir } from "os";
|
|
|
13
13
|
import { join } from "path";
|
|
14
14
|
|
|
15
15
|
function gmtrJsonPath(): string {
|
|
16
|
-
return join(process.env.HOME || process.env.USERPROFILE || homedir(), ".
|
|
16
|
+
return join(process.env.HOME || process.env.USERPROFILE || homedir(), ".gramatr.json");
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
function log(msg: string = ""): void {
|
|
@@ -34,8 +34,8 @@ function showHelp(): void {
|
|
|
34
34
|
log(`gramatr logout — Clear stored gramatr credentials
|
|
35
35
|
|
|
36
36
|
Usage:
|
|
37
|
-
gramatr logout Delete ~/.
|
|
38
|
-
gramatr logout --keep-backup Rename to ~/.
|
|
37
|
+
gramatr logout Delete ~/.gramatr.json
|
|
38
|
+
gramatr logout --keep-backup Rename to ~/.gramatr.json.bak.<timestamp> instead`);
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
export function main(argv: string[] = process.argv.slice(2)): number {
|
package/bin/uninstall.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Usage:
|
|
6
6
|
* bun uninstall.ts # Interactive — confirms each step
|
|
7
7
|
* bun uninstall.ts --yes # Non-interactive — uninstall everything
|
|
8
|
-
* bun uninstall.ts --keep-auth # Keep ~/.
|
|
8
|
+
* bun uninstall.ts --keep-auth # Keep ~/.gramatr.json (preserve login)
|
|
9
9
|
* npx tsx uninstall.ts # Without bun
|
|
10
10
|
*/
|
|
11
11
|
|
|
@@ -97,8 +97,8 @@ async function main(): Promise<void> {
|
|
|
97
97
|
log(' ===================');
|
|
98
98
|
log('');
|
|
99
99
|
|
|
100
|
-
const gmtrClient = join(HOME, '
|
|
101
|
-
const gmtrJson = join(HOME, '.
|
|
100
|
+
const gmtrClient = join(HOME, '.gramatr');
|
|
101
|
+
const gmtrJson = join(HOME, '.gramatr.json');
|
|
102
102
|
const gmtrDotDir = join(HOME, '.gmtr');
|
|
103
103
|
const claudeSettings = join(HOME, '.claude', 'settings.json');
|
|
104
104
|
const claudeJson = join(HOME, '.claude.json');
|
|
@@ -111,9 +111,9 @@ async function main(): Promise<void> {
|
|
|
111
111
|
|
|
112
112
|
// Detect what's installed
|
|
113
113
|
const installed: string[] = [];
|
|
114
|
-
if (existsSync(gmtrClient)) installed.push(
|
|
114
|
+
if (existsSync(gmtrClient)) installed.push(`~/.gramatr (${dirSize(gmtrClient)})`);
|
|
115
115
|
if (existsSync(gmtrDotDir)) installed.push(`~/.gmtr/ (${dirSize(gmtrDotDir)})`);
|
|
116
|
-
if (existsSync(gmtrJson)) installed.push('~/.
|
|
116
|
+
if (existsSync(gmtrJson)) installed.push('~/.gramatr.json');
|
|
117
117
|
if (existsSync(claudeSettings)) installed.push('~/.claude/settings.json (hooks)');
|
|
118
118
|
if (existsSync(claudeJson)) installed.push('~/.claude.json (MCP server)');
|
|
119
119
|
if (existsSync(codexHooks)) installed.push('~/.codex/hooks.json');
|
|
@@ -136,10 +136,10 @@ async function main(): Promise<void> {
|
|
|
136
136
|
|
|
137
137
|
log('');
|
|
138
138
|
|
|
139
|
-
// 1. Remove
|
|
139
|
+
// 1. Remove ~/.gramatr (hooks, bin, skills, agents, tools)
|
|
140
140
|
if (existsSync(gmtrClient)) {
|
|
141
141
|
rmSync(gmtrClient, { recursive: true, force: true });
|
|
142
|
-
log(' OK Removed
|
|
142
|
+
log(' OK Removed ~/.gramatr');
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
// 2. Remove ~/.gmtr/ (bun binary, PATH additions)
|
|
@@ -148,13 +148,13 @@ async function main(): Promise<void> {
|
|
|
148
148
|
log(' OK Removed ~/.gmtr/');
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
-
// 3. Remove ~/.
|
|
151
|
+
// 3. Remove ~/.gramatr.json (auth token) — unless --keep-auth
|
|
152
152
|
if (existsSync(gmtrJson)) {
|
|
153
153
|
if (KEEP_AUTH) {
|
|
154
|
-
log(' -- Kept ~/.
|
|
154
|
+
log(' -- Kept ~/.gramatr.json (--keep-auth)');
|
|
155
155
|
} else {
|
|
156
156
|
rmSync(gmtrJson);
|
|
157
|
-
log(' OK Removed ~/.
|
|
157
|
+
log(' OK Removed ~/.gramatr.json');
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
160
|
|
|
@@ -174,14 +174,14 @@ async function main(): Promise<void> {
|
|
|
174
174
|
for (const [event, hooks] of Object.entries(settings.hooks)) {
|
|
175
175
|
if (Array.isArray(hooks)) {
|
|
176
176
|
settings.hooks[event] = (hooks as any[]).filter(
|
|
177
|
-
(h: any) => !h.command?.includes('
|
|
177
|
+
(h: any) => !h.command?.includes('.gramatr') && !h.command?.includes('gramatr')
|
|
178
178
|
);
|
|
179
179
|
if (settings.hooks[event].length === 0) delete settings.hooks[event];
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
182
|
if (Object.keys(settings.hooks).length === 0) delete settings.hooks;
|
|
183
183
|
}
|
|
184
|
-
if (settings.statusLine?.command?.includes('
|
|
184
|
+
if (settings.statusLine?.command?.includes('.gramatr')) {
|
|
185
185
|
delete settings.statusLine;
|
|
186
186
|
}
|
|
187
187
|
writeFileSync(claudeSettings, JSON.stringify(settings, null, 2) + '\n');
|
|
@@ -242,7 +242,7 @@ async function main(): Promise<void> {
|
|
|
242
242
|
for (const [event, eventHooks] of Object.entries(hooks.hooks)) {
|
|
243
243
|
if (Array.isArray(eventHooks)) {
|
|
244
244
|
hooks.hooks[event] = (eventHooks as any[]).filter(
|
|
245
|
-
(h: any) => !h.command?.includes('
|
|
245
|
+
(h: any) => !h.command?.includes('.gramatr') && !h.command?.includes('gramatr')
|
|
246
246
|
);
|
|
247
247
|
if (hooks.hooks[event].length === 0) delete hooks.hooks[event];
|
|
248
248
|
}
|
|
@@ -278,7 +278,7 @@ async function main(): Promise<void> {
|
|
|
278
278
|
log(' Uninstall complete.');
|
|
279
279
|
log(' Restart Claude Code / Codex / Gemini CLI to apply changes.');
|
|
280
280
|
if (KEEP_AUTH) {
|
|
281
|
-
log(' Auth token preserved in ~/.
|
|
281
|
+
log(' Auth token preserved in ~/.gramatr.json (use --token with next install).');
|
|
282
282
|
}
|
|
283
283
|
log('');
|
|
284
284
|
}
|
package/codex/install.ts
CHANGED
|
@@ -47,7 +47,7 @@ export function main(): void {
|
|
|
47
47
|
throw new Error('HOME is not set');
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
const gmtrDir = process.env.GRAMATR_DIR || join(home, '
|
|
50
|
+
const gmtrDir = process.env.GRAMATR_DIR || join(home, '.gramatr');
|
|
51
51
|
const codexHome = join(home, '.codex');
|
|
52
52
|
const hooksPath = join(codexHome, 'hooks.json');
|
|
53
53
|
const configPath = join(codexHome, 'config.toml');
|
package/core/auth.ts
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
* Resolution chain (first non-empty wins):
|
|
9
9
|
* 1. GRAMATR_API_KEY env var
|
|
10
10
|
* 2. GRAMATR_TOKEN env var (legacy)
|
|
11
|
-
* 3. ~/.
|
|
12
|
-
* 4.
|
|
11
|
+
* 3. ~/.gramatr.json `token` field
|
|
12
|
+
* 4. ~/.gramatr/settings.json `auth.api_key` (legacy, skips placeholder)
|
|
13
13
|
* 5. If interactive + TTY: spawn gmtr-login.ts (OAuth)
|
|
14
14
|
* 6. Otherwise: throw clean actionable error
|
|
15
15
|
*
|
|
@@ -44,11 +44,11 @@ function getHome(): string {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
function gmtrJsonPath(): string {
|
|
47
|
-
return join(getHome(), ".
|
|
47
|
+
return join(getHome(), ".gramatr.json");
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
function legacySettingsPath(): string {
|
|
51
|
-
const gmtrDir = process.env.GRAMATR_DIR || join(getHome(), "
|
|
51
|
+
const gmtrDir = process.env.GRAMATR_DIR || join(getHome(), ".gramatr");
|
|
52
52
|
return join(gmtrDir, "settings.json");
|
|
53
53
|
}
|
|
54
54
|
|
|
@@ -90,7 +90,7 @@ function findGmtrLoginScript(): string | null {
|
|
|
90
90
|
}
|
|
91
91
|
// Fallback to installed client dir
|
|
92
92
|
const installedCandidate = join(
|
|
93
|
-
process.env.GRAMATR_DIR || join(getHome(), "
|
|
93
|
+
process.env.GRAMATR_DIR || join(getHome(), ".gramatr"),
|
|
94
94
|
"bin",
|
|
95
95
|
"gmtr-login.ts",
|
|
96
96
|
);
|
|
@@ -144,7 +144,7 @@ export async function resolveAuthToken(opts: ResolveAuthTokenOptions): Promise<s
|
|
|
144
144
|
const envToken = tokenFromEnv();
|
|
145
145
|
if (envToken) return envToken;
|
|
146
146
|
|
|
147
|
-
// 3: ~/.
|
|
147
|
+
// 3: ~/.gramatr.json
|
|
148
148
|
const stored = tokenFromGmtrJson();
|
|
149
149
|
if (stored) return stored;
|
|
150
150
|
|
package/core/version.ts
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
* Works in two environments:
|
|
9
9
|
* 1. Source checkout: packages/client/core/version.ts →
|
|
10
10
|
* packages/client/package.json (found one directory up).
|
|
11
|
-
* 2. Installed client:
|
|
12
|
-
*
|
|
11
|
+
* 2. Installed client: ~/.gramatr/core/version.ts →
|
|
12
|
+
* ~/.gramatr/package.json (copied by installClientFiles()).
|
|
13
13
|
*
|
|
14
14
|
* If the file cannot be resolved (unexpected layout), falls back to '0.0.0'
|
|
15
15
|
* rather than throwing — the version check is opportunistic and must never
|
package/gemini/install.ts
CHANGED
|
@@ -104,10 +104,10 @@ async function testApiKey(key: string): Promise<boolean> {
|
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
async function resolveApiKey(home: string): Promise<string | null> {
|
|
107
|
-
// 1. Check if already stored in ~/.
|
|
107
|
+
// 1. Check if already stored in ~/.gramatr.json (shared with other platforms)
|
|
108
108
|
const stored = readStoredApiKey(home);
|
|
109
109
|
if (stored) {
|
|
110
|
-
log(` Found existing token in ~/.
|
|
110
|
+
log(` Found existing token in ~/.gramatr.json`);
|
|
111
111
|
log(' Testing token...');
|
|
112
112
|
const valid = await testApiKey(stored);
|
|
113
113
|
if (valid) {
|
|
@@ -142,8 +142,8 @@ async function resolveApiKey(home: string): Promise<string | null> {
|
|
|
142
142
|
const valid = await testApiKey(prompted);
|
|
143
143
|
if (valid) {
|
|
144
144
|
log(' OK Token is valid');
|
|
145
|
-
// Save to ~/.
|
|
146
|
-
const configPath = join(home, '.
|
|
145
|
+
// Save to ~/.gramatr.json for cross-platform reuse
|
|
146
|
+
const configPath = join(home, '.gramatr.json');
|
|
147
147
|
let config: Record<string, unknown> = {};
|
|
148
148
|
if (existsSync(configPath)) {
|
|
149
149
|
try {
|
|
@@ -159,7 +159,7 @@ async function resolveApiKey(home: string): Promise<string | null> {
|
|
|
159
159
|
: 'oauth';
|
|
160
160
|
config.authenticated_at = new Date().toISOString();
|
|
161
161
|
writeFileSync(configPath, JSON.stringify(config, null, 2) + '\n');
|
|
162
|
-
log(' OK Saved to ~/.
|
|
162
|
+
log(' OK Saved to ~/.gramatr.json');
|
|
163
163
|
return prompted;
|
|
164
164
|
}
|
|
165
165
|
log(' Token rejected by server.');
|
|
@@ -244,9 +244,9 @@ export async function main(): Promise<void> {
|
|
|
244
244
|
);
|
|
245
245
|
log(' OK Wrote hooks/hooks.json');
|
|
246
246
|
|
|
247
|
-
// ── Store token in ~/.
|
|
247
|
+
// ── Store token in ~/.gramatr.json (canonical source, not in extension dir) ──
|
|
248
248
|
if (apiKey) {
|
|
249
|
-
const gmtrJsonPath = join(home, '.
|
|
249
|
+
const gmtrJsonPath = join(home, '.gramatr.json');
|
|
250
250
|
let gmtrConfig: Record<string, unknown> = {};
|
|
251
251
|
if (existsSync(gmtrJsonPath)) {
|
|
252
252
|
try { gmtrConfig = JSON.parse(readFileSync(gmtrJsonPath, 'utf8')); } catch {}
|
|
@@ -254,7 +254,7 @@ export async function main(): Promise<void> {
|
|
|
254
254
|
gmtrConfig.token = apiKey;
|
|
255
255
|
gmtrConfig.token_updated_at = new Date().toISOString();
|
|
256
256
|
writeFileSync(gmtrJsonPath, JSON.stringify(gmtrConfig, null, 2) + '\n');
|
|
257
|
-
log(' OK Token stored in ~/.
|
|
257
|
+
log(' OK Token stored in ~/.gramatr.json (hooks read from here at runtime)');
|
|
258
258
|
}
|
|
259
259
|
|
|
260
260
|
// ── Summary ──
|
|
@@ -155,10 +155,10 @@ export function getGramatrExtensionDir(home: string): string {
|
|
|
155
155
|
}
|
|
156
156
|
|
|
157
157
|
/**
|
|
158
|
-
* Read the stored API key from ~/.
|
|
158
|
+
* Read the stored API key from ~/.gramatr.json (shared with other platforms).
|
|
159
159
|
*/
|
|
160
160
|
export function readStoredApiKey(home: string): string | null {
|
|
161
|
-
const configPath = join(home, '.
|
|
161
|
+
const configPath = join(home, '.gramatr.json');
|
|
162
162
|
if (!existsSync(configPath)) return null;
|
|
163
163
|
try {
|
|
164
164
|
const config = JSON.parse(readFileSync(configPath, 'utf8'));
|
|
@@ -40,7 +40,7 @@ async function main() {
|
|
|
40
40
|
let token = '';
|
|
41
41
|
|
|
42
42
|
try {
|
|
43
|
-
const gmtrJson = JSON.parse(readFileSync(`${process.env.HOME}/.
|
|
43
|
+
const gmtrJson = JSON.parse(readFileSync(`${process.env.HOME}/.gramatr.json`, 'utf8'));
|
|
44
44
|
token = gmtrJson.token || '';
|
|
45
45
|
} catch { /* no token */ }
|
|
46
46
|
|
|
@@ -341,16 +341,16 @@ export function createDefaultConfig(options: {
|
|
|
341
341
|
* Resolve auth token. gramatr credentials NEVER live in CLI-specific config files.
|
|
342
342
|
*
|
|
343
343
|
* Priority:
|
|
344
|
-
* 1. ~/.
|
|
344
|
+
* 1. ~/.gramatr.json (canonical, gramatr-owned, vendor-agnostic)
|
|
345
345
|
* 2. GRAMATR_TOKEN env var (CI, headless override)
|
|
346
|
-
* 3.
|
|
346
|
+
* 3. ~/.gramatr/settings.json auth.api_key (legacy, will be migrated)
|
|
347
347
|
*
|
|
348
348
|
* Token is NEVER stored in ~/.claude.json, ~/.codex/, or ~/.gemini/.
|
|
349
349
|
*/
|
|
350
350
|
export function resolveAuthToken(): string | null {
|
|
351
|
-
// 1. ~/.
|
|
351
|
+
// 1. ~/.gramatr.json (canonical source — written by installer, read by all platforms)
|
|
352
352
|
try {
|
|
353
|
-
const configPath = join(HOME, '.
|
|
353
|
+
const configPath = join(HOME, '.gramatr.json');
|
|
354
354
|
const config = JSON.parse(readFileSync(configPath, 'utf8'));
|
|
355
355
|
if (config.token) return config.token;
|
|
356
356
|
} catch {
|
|
@@ -363,9 +363,9 @@ export function resolveAuthToken(): string | null {
|
|
|
363
363
|
// 3. Legacy: AIOS_MCP_TOKEN env var (deprecated)
|
|
364
364
|
if (process.env.AIOS_MCP_TOKEN) return process.env.AIOS_MCP_TOKEN;
|
|
365
365
|
|
|
366
|
-
// 4. Legacy:
|
|
366
|
+
// 4. Legacy: ~/.gramatr/settings.json (will be migrated to ~/.gramatr.json)
|
|
367
367
|
try {
|
|
368
|
-
const gmtrDir = process.env.GRAMATR_DIR || join(HOME, '
|
|
368
|
+
const gmtrDir = process.env.GRAMATR_DIR || join(HOME, '.gramatr');
|
|
369
369
|
const settingsPath = join(gmtrDir, 'settings.json');
|
|
370
370
|
const settings = JSON.parse(readFileSync(settingsPath, 'utf8'));
|
|
371
371
|
if (settings.auth?.api_key && settings.auth.api_key !== 'REPLACE_WITH_YOUR_API_KEY') {
|
|
@@ -382,12 +382,12 @@ export function resolveAuthToken(): string | null {
|
|
|
382
382
|
|
|
383
383
|
/**
|
|
384
384
|
* Resolve MCP server URL from config files.
|
|
385
|
-
* Priority:
|
|
385
|
+
* Priority: ~/.gramatr/settings.json > GRAMATR_URL env > ~/.claude.json > default
|
|
386
386
|
*/
|
|
387
387
|
export function resolveMcpUrl(): string {
|
|
388
|
-
// 1.
|
|
388
|
+
// 1. ~/.gramatr/settings.json (canonical, vendor-agnostic)
|
|
389
389
|
try {
|
|
390
|
-
const gmtrDir = process.env.GRAMATR_DIR || join(HOME, '
|
|
390
|
+
const gmtrDir = process.env.GRAMATR_DIR || join(HOME, '.gramatr');
|
|
391
391
|
const settingsPath = join(gmtrDir, 'settings.json');
|
|
392
392
|
const settings = JSON.parse(readFileSync(settingsPath, 'utf8'));
|
|
393
393
|
if (settings.auth?.server_url) return settings.auth.server_url;
|
package/hooks/lib/identity.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { readFileSync, existsSync } from 'fs';
|
|
|
10
10
|
import { join } from 'path';
|
|
11
11
|
|
|
12
12
|
const HOME = process.env.HOME!;
|
|
13
|
-
const GRAMATR_DIR = process.env.GRAMATR_DIR || join(HOME, '
|
|
13
|
+
const GRAMATR_DIR = process.env.GRAMATR_DIR || join(HOME, '.gramatr');
|
|
14
14
|
const GMTR_SETTINGS_PATH = join(GRAMATR_DIR, 'settings.json'); // gramatr-owned, vendor-agnostic
|
|
15
15
|
const CLAUDE_SETTINGS_PATH = join(HOME, '.claude/settings.json'); // legacy fallback only
|
|
16
16
|
|
|
@@ -82,7 +82,7 @@ let cachedSettings: Settings | null = null;
|
|
|
82
82
|
* Load settings — gramatr-owned config first, Claude vendor file as legacy fallback.
|
|
83
83
|
*
|
|
84
84
|
* Priority:
|
|
85
|
-
* 1.
|
|
85
|
+
* 1. ~/.gramatr/settings.json (gramatr-owned, vendor-agnostic)
|
|
86
86
|
* 2. ~/.claude/settings.json (Claude vendor file — legacy fallback only)
|
|
87
87
|
*
|
|
88
88
|
* Merges both: gramatr settings take precedence for identity fields,
|
package/hooks/lib/paths.ts
CHANGED
|
@@ -50,7 +50,7 @@ export function getGmtrDir(): string {
|
|
|
50
50
|
/**
|
|
51
51
|
* Get the settings.json path
|
|
52
52
|
* Always ~/.claude/settings.json — NOT relative to GRAMATR_DIR.
|
|
53
|
-
* GRAMATR_DIR is the client payload directory (
|
|
53
|
+
* GRAMATR_DIR is the client payload directory (~/.gramatr), not ~/.claude.
|
|
54
54
|
*/
|
|
55
55
|
export function getSettingsPath(): string {
|
|
56
56
|
return join(homedir(), '.claude', 'settings.json');
|
|
@@ -171,7 +171,7 @@ function displayBanner(): void {
|
|
|
171
171
|
// ── Sync Ratings (background, non-blocking) ──
|
|
172
172
|
|
|
173
173
|
function syncRatingsInBackground(): void {
|
|
174
|
-
const syncScript = join(process.env.GRAMATR_DIR || join(process.env.HOME || '', '
|
|
174
|
+
const syncScript = join(process.env.GRAMATR_DIR || join(process.env.HOME || '', '.gramatr'), 'hooks', 'sync-ratings.hook.ts');
|
|
175
175
|
if (existsSync(syncScript)) {
|
|
176
176
|
try {
|
|
177
177
|
const npxBin = process.platform === 'win32' ? 'npx.cmd' : 'npx';
|