@gramatr/client 0.5.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.
Files changed (65) hide show
  1. package/AGENTS.md +17 -0
  2. package/CLAUDE.md +18 -0
  3. package/README.md +108 -0
  4. package/bin/add-api-key.ts +264 -0
  5. package/bin/clean-legacy-install.ts +28 -0
  6. package/bin/clear-creds.ts +141 -0
  7. package/bin/get-token.py +3 -0
  8. package/bin/gmtr-login.ts +599 -0
  9. package/bin/gramatr.js +36 -0
  10. package/bin/gramatr.ts +374 -0
  11. package/bin/install.ts +716 -0
  12. package/bin/lib/config.ts +57 -0
  13. package/bin/lib/git.ts +111 -0
  14. package/bin/lib/stdin.ts +53 -0
  15. package/bin/logout.ts +76 -0
  16. package/bin/render-claude-hooks.ts +16 -0
  17. package/bin/statusline.ts +81 -0
  18. package/bin/uninstall.ts +289 -0
  19. package/chatgpt/README.md +95 -0
  20. package/chatgpt/install.ts +140 -0
  21. package/chatgpt/lib/chatgpt-install-utils.ts +89 -0
  22. package/codex/README.md +28 -0
  23. package/codex/hooks/session-start.ts +73 -0
  24. package/codex/hooks/stop.ts +34 -0
  25. package/codex/hooks/user-prompt-submit.ts +79 -0
  26. package/codex/install.ts +116 -0
  27. package/codex/lib/codex-hook-utils.ts +48 -0
  28. package/codex/lib/codex-install-utils.ts +123 -0
  29. package/core/auth.ts +170 -0
  30. package/core/feedback.ts +55 -0
  31. package/core/formatting.ts +179 -0
  32. package/core/install.ts +107 -0
  33. package/core/installer-cli.ts +122 -0
  34. package/core/migration.ts +479 -0
  35. package/core/routing.ts +108 -0
  36. package/core/session.ts +202 -0
  37. package/core/targets.ts +292 -0
  38. package/core/types.ts +179 -0
  39. package/core/version-check.ts +219 -0
  40. package/core/version.ts +47 -0
  41. package/desktop/README.md +72 -0
  42. package/desktop/build-mcpb.ts +166 -0
  43. package/desktop/install.ts +136 -0
  44. package/desktop/lib/desktop-install-utils.ts +70 -0
  45. package/gemini/README.md +95 -0
  46. package/gemini/hooks/session-start.ts +72 -0
  47. package/gemini/hooks/stop.ts +30 -0
  48. package/gemini/hooks/user-prompt-submit.ts +77 -0
  49. package/gemini/install.ts +281 -0
  50. package/gemini/lib/gemini-hook-utils.ts +63 -0
  51. package/gemini/lib/gemini-install-utils.ts +169 -0
  52. package/hooks/GMTRPromptEnricher.hook.ts +651 -0
  53. package/hooks/GMTRRatingCapture.hook.ts +198 -0
  54. package/hooks/GMTRSecurityValidator.hook.ts +399 -0
  55. package/hooks/GMTRToolTracker.hook.ts +181 -0
  56. package/hooks/StopOrchestrator.hook.ts +78 -0
  57. package/hooks/gmtr-tool-tracker-utils.ts +105 -0
  58. package/hooks/lib/gmtr-hook-utils.ts +770 -0
  59. package/hooks/lib/identity.ts +227 -0
  60. package/hooks/lib/notify.ts +46 -0
  61. package/hooks/lib/paths.ts +104 -0
  62. package/hooks/lib/transcript-parser.ts +452 -0
  63. package/hooks/session-end.hook.ts +168 -0
  64. package/hooks/session-start.hook.ts +501 -0
  65. package/package.json +63 -0
@@ -0,0 +1,169 @@
1
+ import { existsSync, readFileSync } from 'fs';
2
+ import { join } from 'path';
3
+
4
+ export interface GeminiExtensionManifest {
5
+ name: string;
6
+ version: string;
7
+ description: string;
8
+ mcpServers?: Record<string, GeminiMcpServerConfig>;
9
+ settings?: GeminiSettingDef[];
10
+ contextFileName?: string;
11
+ }
12
+
13
+ export interface GeminiMcpServerConfig {
14
+ httpUrl?: string;
15
+ headers?: Record<string, string>;
16
+ timeout?: number;
17
+ }
18
+
19
+ export interface GeminiSettingDef {
20
+ name: string;
21
+ envVar: string;
22
+ sensitive?: boolean;
23
+ description?: string;
24
+ }
25
+
26
+ export interface GeminiHooksFileHook {
27
+ type: 'command';
28
+ command: string;
29
+ name?: string;
30
+ timeout?: number;
31
+ description?: string;
32
+ }
33
+
34
+ export interface GeminiHooksFileEntry {
35
+ matcher?: string;
36
+ sequential?: boolean;
37
+ hooks: GeminiHooksFileHook[];
38
+ }
39
+
40
+ export interface GeminiHooksFile {
41
+ hooks: Record<string, GeminiHooksFileEntry[]>;
42
+ }
43
+
44
+ /**
45
+ * Build the gemini-extension.json manifest for gramatr.
46
+ *
47
+ * The mcpServers block points to the production MCP endpoint.
48
+ * Auth is handled via the GRAMATR_API_KEY setting which Gemini stores
49
+ * in its extension .env / system keychain.
50
+ */
51
+ export function buildExtensionManifest(): GeminiExtensionManifest {
52
+ return {
53
+ name: 'gramatr',
54
+ version: '1.0.0',
55
+ description: 'gramatr intelligence layer — decision routing, vector memory, and pattern learning for Gemini CLI',
56
+ mcpServers: {
57
+ gramatr: {
58
+ httpUrl: 'https://api.gramatr.com/mcp',
59
+ headers: {
60
+ Authorization: 'Bearer ${GRAMATR_API_KEY}',
61
+ },
62
+ timeout: 30000,
63
+ },
64
+ },
65
+ settings: [
66
+ {
67
+ name: 'API Key',
68
+ envVar: 'GRAMATR_API_KEY',
69
+ sensitive: true,
70
+ description: 'gramatr API key (starts with gmtr_sk_). Get one at gramatr.com or via gmtr-login.',
71
+ },
72
+ ],
73
+ };
74
+ }
75
+
76
+ /**
77
+ * Build the hooks/hooks.json for the gramatr Gemini extension.
78
+ *
79
+ * Maps Gemini CLI lifecycle events to gramatr hook scripts.
80
+ * Uses ${extensionPath} for portability — Gemini CLI expands this
81
+ * to the installed extension directory at runtime.
82
+ */
83
+ export function buildGeminiHooksFile(): GeminiHooksFile {
84
+ return {
85
+ hooks: {
86
+ SessionStart: [
87
+ {
88
+ hooks: [
89
+ {
90
+ type: 'command',
91
+ command: 'npx tsx "${extensionPath}/hooks/session-start.ts"',
92
+ name: 'gramatr-session-start',
93
+ timeout: 15,
94
+ description: 'Load gramatr session context and handoff',
95
+ },
96
+ ],
97
+ },
98
+ ],
99
+ BeforeAgent: [
100
+ {
101
+ hooks: [
102
+ {
103
+ type: 'command',
104
+ command: 'npx tsx "${extensionPath}/hooks/user-prompt-submit.ts"',
105
+ name: 'gramatr-prompt-routing',
106
+ timeout: 15,
107
+ description: 'Route prompt through gramatr intelligence',
108
+ },
109
+ ],
110
+ },
111
+ ],
112
+ SessionEnd: [
113
+ {
114
+ hooks: [
115
+ {
116
+ type: 'command',
117
+ command: 'npx tsx "${extensionPath}/hooks/stop.ts"',
118
+ name: 'gramatr-session-end',
119
+ timeout: 10,
120
+ description: 'Submit classification feedback to gramatr',
121
+ },
122
+ ],
123
+ },
124
+ ],
125
+ },
126
+ };
127
+ }
128
+
129
+ /**
130
+ * Read existing Gemini settings.json and extract the mcpServers block.
131
+ * Returns null if file doesn't exist or can't be parsed.
132
+ */
133
+ export function readGeminiSettings(geminiHome: string): Record<string, unknown> | null {
134
+ const settingsPath = join(geminiHome, 'settings.json');
135
+ if (!existsSync(settingsPath)) return null;
136
+ try {
137
+ return JSON.parse(readFileSync(settingsPath, 'utf8'));
138
+ } catch {
139
+ return null;
140
+ }
141
+ }
142
+
143
+ /**
144
+ * Resolve the Gemini extensions directory.
145
+ */
146
+ export function getGeminiExtensionsDir(home: string): string {
147
+ return join(home, '.gemini', 'extensions');
148
+ }
149
+
150
+ /**
151
+ * Resolve the gramatr extension install path.
152
+ */
153
+ export function getGramatrExtensionDir(home: string): string {
154
+ return join(getGeminiExtensionsDir(home), 'gramatr');
155
+ }
156
+
157
+ /**
158
+ * Read the stored API key from ~/.gmtr.json (shared with other platforms).
159
+ */
160
+ export function readStoredApiKey(home: string): string | null {
161
+ const configPath = join(home, '.gmtr.json');
162
+ if (!existsSync(configPath)) return null;
163
+ try {
164
+ const config = JSON.parse(readFileSync(configPath, 'utf8'));
165
+ return config.token || null;
166
+ } catch {
167
+ return null;
168
+ }
169
+ }