glm-switch 2.0.0

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 ADDED
@@ -0,0 +1,456 @@
1
+ # GLM Switch Profile for claude-code
2
+
3
+ > **Public tool for Supermeo & Inwave DR Team**
4
+
5
+ A CLI tool for managing multiple GLM API profiles in Claude Code/VS Code. Quickly switch between different GLM configurations without manual editing.
6
+
7
+ [![npm version](https://badge.fury.io/js/glm-switch.svg)](https://www.npmjs.com/package/glm-switch)
8
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
9
+
10
+ ---
11
+
12
+ ## Features
13
+
14
+ - **Multiple Profiles** - Manage multiple profiles with different tokens and models
15
+ - **Quick Switch** - Switch between profiles with a single command
16
+ - **Bulk Update** - Update config across all profiles at once
17
+ - **Safe Operations** - Automatic backup, JSON validation, and rollback on errors
18
+ - **Cross-Platform** - Support for Windows & macOS
19
+ - **JSONC Support** - Reads settings.json with comments
20
+ - **Auto-Create** - Automatically creates files if they don't exist
21
+
22
+ ---
23
+
24
+ ## Installation
25
+
26
+ ### Method 1: Install from npm (Recommended)
27
+
28
+ ```bash
29
+ npm install -g glm-switch
30
+ ```
31
+
32
+ ### Method 2: Install from GitHub
33
+
34
+ ```bash
35
+ # Clone repository
36
+ git clone https://github.com/your-org/glm-switch.git
37
+ cd glm-switch
38
+
39
+ # Setup
40
+ npm run setup
41
+ ```
42
+
43
+ The `npm run setup` command will:
44
+ 1. Install dependencies
45
+ 2. Build TypeScript to JavaScript
46
+ 3. Create a global symlink via `npm link`
47
+
48
+ ---
49
+
50
+ ## Profile Concept
51
+
52
+ Each **profile** is a separate GLM API configuration containing:
53
+
54
+ | Config Key | Description |
55
+ |------------|-------------|
56
+ | `ANTHROPIC_BASE_URL` | API endpoint for GLM |
57
+ | `ANTHROPIC_AUTH_TOKEN` | Authentication token |
58
+ | `ANTHROPIC_DEFAULT_HAIKU_MODEL` | Haiku model (lightweight) |
59
+ | `ANTHROPIC_DEFAULT_SONNET_MODEL` | Sonnet model (balanced) |
60
+ | `ANTHROPIC_DEFAULT_OPUS_MODEL` | Opus model (powerful) |
61
+
62
+ **Storage:** Profiles are stored in `~/.claude/glm-switch/`
63
+
64
+ ---
65
+
66
+ ## Usage Guide
67
+
68
+ ### 1. Create Your First Profile
69
+
70
+ ```bash
71
+ # Create profile 0 with default values
72
+ glm-switch init 0
73
+ ```
74
+
75
+ Output:
76
+ ```
77
+ ✓ Profile 0 created
78
+ Config: {
79
+ "ANTHROPIC_BASE_URL": "https://api.z.ai/api/anthropic",
80
+ "ANTHROPIC_AUTH_TOKEN": "",
81
+ "ANTHROPIC_DEFAULT_HAIKU_MODEL": "glm-4.5-air",
82
+ "ANTHROPIC_DEFAULT_SONNET_MODEL": "glm-4.7",
83
+ "ANTHROPIC_DEFAULT_OPUS_MODEL": "glm-4.7"
84
+ }
85
+ Don't forget to set your auth token:
86
+ glm-switch set 0 token <your-token>
87
+ ```
88
+
89
+ ### 2. Set Token for Profile
90
+
91
+ ```bash
92
+ # Set token for profile 0
93
+ glm-switch set 0 token b8eb5131e993419fa5f39181c7c6a1db.emTv6QgzVxbSo3a7
94
+ ```
95
+
96
+ ### 3. Apply Profile
97
+
98
+ ```bash
99
+ # Apply default profile (0)
100
+ glm-switch on
101
+
102
+ # Apply specific profile
103
+ glm-switch on 1
104
+ ```
105
+
106
+ **Important:** After applying, **restart Claude Code/VS Code** for changes to take effect.
107
+
108
+ ### 4. Create Additional Profiles
109
+
110
+ ```bash
111
+ # Create profile 1
112
+ glm-switch init 1
113
+
114
+ # Set different token for profile 1
115
+ glm-switch set 1 token another_token_here
116
+
117
+ # Apply profile 1
118
+ glm-switch on 1
119
+ ```
120
+
121
+ ### 5. Bulk Update - Update All Profiles
122
+
123
+ ```bash
124
+ # Update Sonnet model for all profiles
125
+ glm-switch setall sonnet glm-4.7
126
+
127
+ # Update Opus model for all profiles
128
+ glm-switch setall opus glm-4.7
129
+
130
+ # Update Haiku model for all profiles
131
+ glm-switch setall haiku glm-4.5-air
132
+
133
+ # Update API endpoint for all profiles
134
+ glm-switch setall ANTHROPIC_BASE_URL https://api.z.ai/api/anthropic
135
+ ```
136
+
137
+ ### 6. List All Profiles
138
+
139
+ ```bash
140
+ glm-switch list
141
+ ```
142
+
143
+ Output:
144
+ ```
145
+ Profiles:
146
+
147
+ [active] [default] 0
148
+ Base URL: https://api.z.ai/api/anthropic
149
+ Token: b8eb5131e...
150
+ Haiku: glm-4.5-air
151
+ Sonnet: glm-4.7
152
+ Opus: glm-4.7
153
+
154
+ 1
155
+ Base URL: https://api.z.ai/api/anthropic
156
+ Token: (not set)
157
+ Haiku: glm-4.5-air
158
+ Sonnet: glm-4.7
159
+ Opus: glm-4.7
160
+ ```
161
+
162
+ ### 7. Check Current Status
163
+
164
+ ```bash
165
+ glm-switch status
166
+ ```
167
+
168
+ ### 8. Delete Profile
169
+
170
+ ```bash
171
+ glm-switch delete 1
172
+ ```
173
+
174
+ ### 9. Disable GLM Mode (Restore Claude API)
175
+
176
+ ```bash
177
+ glm-switch off
178
+ ```
179
+
180
+ ---
181
+
182
+ ## All Commands
183
+
184
+ | Command | Description | Example |
185
+ |---------|-------------|---------|
186
+ | `init [id]` | Create a new profile | `glm-switch init 0` |
187
+ | `set <id> <key> <value>` | Set value for a specific profile | `glm-switch set 0 token xxxx` |
188
+ | `setall <key> <value>` | Set value for all profiles | `glm-switch setall sonnet glm-4.7` |
189
+ | `on [id]` | Apply profile (default: 0) | `glm-switch on 1` |
190
+ | `off` | Remove GLM config | `glm-switch off` |
191
+ | `status` | Show current status | `glm-switch status` |
192
+ | `list` | List all profiles | `glm-switch list` |
193
+ | `delete <id>` | Delete a profile | `glm-switch delete 1` |
194
+ | `--help` | Show help | `glm-switch --help` |
195
+ | `--version` | Show version | `glm-switch --version` |
196
+
197
+ ---
198
+
199
+ ## Valid Config Keys
200
+
201
+ When using `set` or `setall` commands, valid keys are:
202
+
203
+ ```
204
+ ANTHROPIC_BASE_URL
205
+ ANTHROPIC_AUTH_TOKEN
206
+ ANTHROPIC_DEFAULT_HAIKU_MODEL
207
+ ANTHROPIC_DEFAULT_SONNET_MODEL
208
+ ANTHROPIC_DEFAULT_OPUS_MODEL
209
+ ```
210
+
211
+ ---
212
+
213
+ ## How It Works
214
+
215
+ ### File Storage Structure
216
+
217
+ ```
218
+ ~/.claude/
219
+ ├── settings.json # Claude Code settings
220
+ └── glm-switch/ # GLM Switch profiles directory
221
+ ├── profile-0.json # Profile 0 config
222
+ ├── profile-1.json # Profile 1 config
223
+ ├── active-profile.json # Currently active profile
224
+ └── default-profile.json # Default profile (0)
225
+ ```
226
+
227
+ ### Profile File Format
228
+
229
+ ```json
230
+ {
231
+ "id": "0",
232
+ "config": {
233
+ "ANTHROPIC_BASE_URL": "https://api.z.ai/api/anthropic",
234
+ "ANTHROPIC_AUTH_TOKEN": "your-token-here",
235
+ "ANTHROPIC_DEFAULT_HAIKU_MODEL": "glm-4.5-air",
236
+ "ANTHROPIC_DEFAULT_SONNET_MODEL": "glm-4.7",
237
+ "ANTHROPIC_DEFAULT_OPUS_MODEL": "glm-4.7"
238
+ },
239
+ "createdAt": "2025-01-14T10:00:00.000Z",
240
+ "updatedAt": "2025-01-14T10:00:00.000Z"
241
+ }
242
+ ```
243
+
244
+ ### Settings.json Modification
245
+
246
+ When running `glm-switch on [id]`, the tool injects config from the profile into `~/.claude/settings.json`:
247
+
248
+ ```json
249
+ {
250
+ "env": {
251
+ "ANTHROPIC_BASE_URL": "https://api.z.ai/api/anthropic",
252
+ "ANTHROPIC_AUTH_TOKEN": "your-token-here",
253
+ "ANTHROPIC_DEFAULT_HAIKU_MODEL": "glm-4.5-air",
254
+ "ANTHROPIC_DEFAULT_SONNET_MODEL": "glm-4.7",
255
+ "ANTHROPIC_DEFAULT_OPUS_MODEL": "glm-4.7"
256
+ }
257
+ }
258
+ ```
259
+
260
+ ---
261
+
262
+ ## Recommended Workflows
263
+
264
+ ### First-Time Setup
265
+
266
+ ```bash
267
+ # 1. Create profile 0
268
+ glm-switch init 0
269
+
270
+ # 2. Set your token
271
+ glm-switch set 0 token your_token_here
272
+
273
+ # 3. Apply
274
+ glm-switch on
275
+
276
+ # 4. Restart Claude Code
277
+ ```
278
+
279
+ ### Add New Profile
280
+
281
+ ```bash
282
+ # 1. Create new profile
283
+ glm-switch init 1
284
+
285
+ # 2. Set token
286
+ glm-switch set 1 token another_token
287
+
288
+ # 3. Apply when needed
289
+ glm-switch on 1
290
+ ```
291
+
292
+ ### Update Models for All
293
+
294
+ ```bash
295
+ glm-switch setall sonnet glm-4.7
296
+ glm-switch setall opus glm-4.7
297
+ glm-switch setall haiku glm-4.5-air
298
+ ```
299
+
300
+ ---
301
+
302
+ ## Safety Features
303
+
304
+ - **Automatic Backup** - Creates `.backup` file before modifying
305
+ - **Atomic Writes** - Uses temp files to prevent corruption
306
+ - **JSON Validation** - Validates structure before writing
307
+ - **Rollback on Error** - Restores from backup if modification fails
308
+ - **Non-destructive** - Preserves other settings
309
+
310
+ ---
311
+
312
+ ## Troubleshooting
313
+
314
+ ### Command not found after installation
315
+
316
+ ```bash
317
+ # Close and reopen terminal
318
+ # Or check npm bin path
319
+ npm bin -g
320
+
321
+ # Ensure npm bin is in your PATH
322
+ ```
323
+
324
+ ### Changes not taking effect
325
+
326
+ ```bash
327
+ # 1. Check status
328
+ glm-switch status
329
+
330
+ # 2. Restart Claude Code/VS Code COMPLETELY
331
+ # 3. Check status again
332
+ ```
333
+
334
+ ### Profile does not exist
335
+
336
+ ```bash
337
+ # List all profiles
338
+ glm-switch list
339
+
340
+ # Create profile if needed
341
+ glm-switch init 0
342
+ ```
343
+
344
+ ### Invalid config key
345
+
346
+ ```bash
347
+ ✗ Invalid config key: invalid_key
348
+ Valid keys: ANTHROPIC_BASE_URL, ANTHROPIC_AUTH_TOKEN, ANTHROPIC_DEFAULT_HAIKU_MODEL, ANTHROPIC_DEFAULT_SONNET_MODEL, ANTHROPIC_DEFAULT_OPUS_MODEL
349
+ ```
350
+
351
+ ### Permission errors
352
+
353
+ **Windows:** Run terminal as Administrator
354
+
355
+ **macOS:**
356
+ ```bash
357
+ # Check permissions
358
+ ls -la ~/.claude/
359
+
360
+ # Fix permissions
361
+ chmod 644 ~/.claude/settings.json
362
+ ```
363
+
364
+ ---
365
+
366
+ ## Development
367
+
368
+ ### Clone & Setup
369
+
370
+ ```bash
371
+ git clone https://github.com/your-org/glm-switch.git
372
+ cd glm-switch
373
+ npm run setup
374
+ ```
375
+
376
+ ### Build
377
+
378
+ ```bash
379
+ npm run build
380
+ ```
381
+
382
+ ### Watch Mode
383
+
384
+ ```bash
385
+ npm run dev
386
+ ```
387
+
388
+ ### Clean
389
+
390
+ ```bash
391
+ npm run clean
392
+ ```
393
+
394
+ ---
395
+
396
+ ## Uninstallation
397
+
398
+ ### Global npm package
399
+
400
+ ```bash
401
+ npm uninstall -g glm-switch
402
+ ```
403
+
404
+ ### Manual cleanup (optional)
405
+
406
+ ```bash
407
+ # Remove profiles directory
408
+ rm -rf ~/.claude/glm-switch
409
+ ```
410
+
411
+ ---
412
+
413
+ ## Platform Support
414
+
415
+ | Platform | Status | Settings Location |
416
+ |----------|--------|-------------------|
417
+ | Windows 10/11 | ✅ Supported | `C:\Users\{username}\.claude\settings.json` |
418
+ | macOS | ✅ Supported | `~/.claude/settings.json` |
419
+ | Linux | ⚠️ Untested | `~/.claude/settings.json` |
420
+
421
+ ---
422
+
423
+ ## Version History
424
+
425
+ ### v2.0.0 (Current)
426
+ - ✨ Multi-profile support
427
+ - ✨ New commands: `init`, `set`, `setall`, `list`, `delete`
428
+ - ✨ Profile storage in `~/.claude/glm-switch/`
429
+ - ✨ Default profile concept
430
+
431
+ ### v1.1.0
432
+ - ✅ JSONC support (comments in settings.json)
433
+ - ✅ Auto-create settings.json
434
+
435
+ ### v1.0.0
436
+ - 🎉 Initial release
437
+ - ✅ Basic on/off switching
438
+
439
+ ---
440
+
441
+ ## License
442
+
443
+ MIT © Supermeo & Inwave DR Team
444
+
445
+ ---
446
+
447
+ ## Links
448
+
449
+ - **npm:** https://www.npmjs.com/package/glm-switch
450
+ - **GitHub:** https://github.com/your-org/glm-switch
451
+
452
+ ---
453
+
454
+ ## Contributing
455
+
456
+ Contributions are welcome! Please feel free to submit a Pull Request.
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/dist/cli.js ADDED
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const commander_1 = require("commander");
5
+ const commands_1 = require("./commands");
6
+ const program = new commander_1.Command();
7
+ program
8
+ .name('glm-switch')
9
+ .description('CLI utility to manage GLM API profiles for Claude Code')
10
+ .version('1.2.0');
11
+ // Apply profile command
12
+ program
13
+ .command('on [id]')
14
+ .description('Apply a profile (default: 0)')
15
+ .action((id) => {
16
+ (0, commands_1.applyProfile)(id);
17
+ });
18
+ // Disable GLM mode command
19
+ program
20
+ .command('off')
21
+ .description('Remove all GLM configuration (restore Claude API mode)')
22
+ .action(() => {
23
+ (0, commands_1.disableGLM)();
24
+ });
25
+ // Show status command
26
+ program
27
+ .command('status')
28
+ .description('Show current API mode and active profile')
29
+ .action(() => {
30
+ (0, commands_1.showStatus)();
31
+ });
32
+ // Initialize profile command
33
+ program
34
+ .command('init [id]')
35
+ .description('Create a new profile (default: 0)')
36
+ .action((id = '0') => {
37
+ (0, commands_1.initProfile)(id);
38
+ });
39
+ // Set value for specific profile command
40
+ program
41
+ .command('set <id> <key> <value>')
42
+ .description('Set a config value for a specific profile')
43
+ .action((id, key, value) => {
44
+ (0, commands_1.setProfileValue)(id, key, value);
45
+ });
46
+ // Set value for all profiles command
47
+ program
48
+ .command('setall <key> <value>')
49
+ .description('Set a config value for all profiles')
50
+ .action((key, value) => {
51
+ (0, commands_1.setAllProfilesValue)(key, value);
52
+ });
53
+ // List profiles command
54
+ program
55
+ .command('list')
56
+ .description('List all profiles')
57
+ .action(() => {
58
+ (0, commands_1.listAllProfiles)();
59
+ });
60
+ // Delete profile command
61
+ program
62
+ .command('delete <id>')
63
+ .description('Delete a profile')
64
+ .action((id) => {
65
+ (0, commands_1.deleteProfile)(id);
66
+ });
67
+ program.parse();
68
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;AACA,yCAAoC;AACpC,yCASoB;AAEpB,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,IAAI,CAAC,YAAY,CAAC;KAClB,WAAW,CAAC,wDAAwD,CAAC;KACrE,OAAO,CAAC,OAAO,CAAC,CAAC;AAEpB,wBAAwB;AACxB,OAAO;KACJ,OAAO,CAAC,SAAS,CAAC;KAClB,WAAW,CAAC,8BAA8B,CAAC;KAC3C,MAAM,CAAC,CAAC,EAAW,EAAE,EAAE;IACtB,IAAA,uBAAY,EAAC,EAAE,CAAC,CAAC;AACnB,CAAC,CAAC,CAAC;AAEL,2BAA2B;AAC3B,OAAO;KACJ,OAAO,CAAC,KAAK,CAAC;KACd,WAAW,CAAC,wDAAwD,CAAC;KACrE,MAAM,CAAC,GAAG,EAAE;IACX,IAAA,qBAAU,GAAE,CAAC;AACf,CAAC,CAAC,CAAC;AAEL,sBAAsB;AACtB,OAAO;KACJ,OAAO,CAAC,QAAQ,CAAC;KACjB,WAAW,CAAC,0CAA0C,CAAC;KACvD,MAAM,CAAC,GAAG,EAAE;IACX,IAAA,qBAAU,GAAE,CAAC;AACf,CAAC,CAAC,CAAC;AAEL,6BAA6B;AAC7B,OAAO;KACJ,OAAO,CAAC,WAAW,CAAC;KACpB,WAAW,CAAC,mCAAmC,CAAC;KAChD,MAAM,CAAC,CAAC,KAAa,GAAG,EAAE,EAAE;IAC3B,IAAA,sBAAW,EAAC,EAAE,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC;AAEL,yCAAyC;AACzC,OAAO;KACJ,OAAO,CAAC,wBAAwB,CAAC;KACjC,WAAW,CAAC,2CAA2C,CAAC;KACxD,MAAM,CAAC,CAAC,EAAU,EAAE,GAAW,EAAE,KAAa,EAAE,EAAE;IACjD,IAAA,0BAAe,EAAC,EAAE,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;AAClC,CAAC,CAAC,CAAC;AAEL,qCAAqC;AACrC,OAAO;KACJ,OAAO,CAAC,sBAAsB,CAAC;KAC/B,WAAW,CAAC,qCAAqC,CAAC;KAClD,MAAM,CAAC,CAAC,GAAW,EAAE,KAAa,EAAE,EAAE;IACrC,IAAA,8BAAmB,EAAC,GAAG,EAAE,KAAK,CAAC,CAAC;AAClC,CAAC,CAAC,CAAC;AAEL,wBAAwB;AACxB,OAAO;KACJ,OAAO,CAAC,MAAM,CAAC;KACf,WAAW,CAAC,mBAAmB,CAAC;KAChC,MAAM,CAAC,GAAG,EAAE;IACX,IAAA,0BAAe,GAAE,CAAC;AACpB,CAAC,CAAC,CAAC;AAEL,yBAAyB;AACzB,OAAO;KACJ,OAAO,CAAC,aAAa,CAAC;KACtB,WAAW,CAAC,kBAAkB,CAAC;KAC/B,MAAM,CAAC,CAAC,EAAU,EAAE,EAAE;IACrB,IAAA,wBAAa,EAAC,EAAE,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC;AAEL,OAAO,CAAC,KAAK,EAAE,CAAC"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Apply a profile by ID (or default profile if no ID provided)
3
+ */
4
+ export declare function applyProfile(profileId?: string): void;
5
+ /**
6
+ * Legacy function - applies profile 0 by default
7
+ * @deprecated Use applyProfile() instead
8
+ */
9
+ export declare function enableGLM(): void;
10
+ /**
11
+ * Disable GLM mode (remove all GLM config from settings)
12
+ */
13
+ export declare function disableGLM(): void;
14
+ /**
15
+ * Show current status
16
+ */
17
+ export declare function showStatus(): void;
18
+ /**
19
+ * Initialize a new profile
20
+ */
21
+ export declare function initProfile(id: string): void;
22
+ /**
23
+ * Set a value for a specific profile
24
+ */
25
+ export declare function setProfileValue(id: string, key: string, value: string): void;
26
+ /**
27
+ * Set a value for all profiles
28
+ */
29
+ export declare function setAllProfilesValue(key: string, value: string): void;
30
+ /**
31
+ * List all profiles
32
+ */
33
+ export declare function listAllProfiles(): void;
34
+ /**
35
+ * Delete a profile
36
+ */
37
+ export declare function deleteProfile(id: string): void;
38
+ //# sourceMappingURL=commands.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../src/commands.ts"],"names":[],"mappings":"AAwBA;;GAEG;AACH,wBAAgB,YAAY,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAmDrD;AAED;;;GAGG;AACH,wBAAgB,SAAS,IAAI,IAAI,CAEhC;AAED;;GAEG;AACH,wBAAgB,UAAU,IAAI,IAAI,CAqBjC;AAED;;GAEG;AACH,wBAAgB,UAAU,IAAI,IAAI,CAoCjC;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAmB5C;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CA+B5E;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAmBpE;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,IAAI,CA0CtC;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAe9C"}