@bazilio-san/glm-cc 1.0.9 → 1.0.13

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 (2) hide show
  1. package/bin/glm.js +159 -150
  2. package/package.json +1 -1
package/bin/glm.js CHANGED
@@ -1,150 +1,159 @@
1
- #!/usr/bin/env node
2
-
3
- import path from 'node:path';
4
- import os from 'node:os';
5
- import fs from 'node:fs';
6
- import readline from 'node:readline';
7
- import { spawn } from 'node:child_process';
8
-
9
- const CONFIG_FILE = path.join(os.homedir(), '.glm-claude-code.json');
10
-
11
- const CONFIG_FIELDS = [
12
- {
13
- key: 'ANTHROPIC_BASE_URL',
14
- label: 'Anthropic Base URL',
15
- defaultValue: 'https://api.z.ai/api/anthropic',
16
- },
17
- {
18
- key: 'ANTHROPIC_AUTH_TOKEN',
19
- label: 'Anthropic Auth Token',
20
- defaultValue: '',
21
- },
22
- {
23
- key: 'ANTHROPIC_DEFAULT_HAIKU_MODEL',
24
- label: 'Default Haiku model',
25
- defaultValue: 'glm-4.5-air',
26
- },
27
- {
28
- key: 'ANTHROPIC_DEFAULT_SONNET_MODEL',
29
- label: 'Default Sonnet model',
30
- defaultValue: 'glm-5.1',
31
- },
32
- {
33
- key: 'ANTHROPIC_DEFAULT_OPUS_MODEL',
34
- label: 'Default Opus model',
35
- defaultValue: 'glm-5.1',
36
- },
37
- ];
38
-
39
- function loadConfig() {
40
- if (!fs.existsSync(CONFIG_FILE)) return {};
41
- try {
42
- return JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8'));
43
- } catch {
44
- return {};
45
- }
46
- }
47
-
48
- function saveConfig(config) {
49
- fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2), 'utf8');
50
- }
51
-
52
- function ask(rl, question) {
53
- return new Promise(resolve => rl.question(question, resolve));
54
- }
55
-
56
- async function runConfig(fields) {
57
- const config = loadConfig();
58
- const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
59
-
60
- console.log('\nConfiguration (press Enter to keep current value):\n');
61
-
62
- for (const field of fields) {
63
- const current = config[field.key] !== undefined && config[field.key] !== ''
64
- ? config[field.key]
65
- : field.defaultValue;
66
- const hint = current ? ` [\x1b[32m${current}\x1b[0m]` : '';
67
- const answer = await ask(rl, `${field.label}${hint}: `);
68
- config[field.key] = answer.trim() !== '' ? answer.trim() : current;
69
- }
70
-
71
- rl.close();
72
- saveConfig(config);
73
- console.log(`\nConfig saved: ${CONFIG_FILE}\n`);
74
- return config;
75
- }
76
-
77
- function showHelp(config) {
78
- const lines = [
79
- '',
80
- 'Usage: glm [options]',
81
- '',
82
- 'Options:',
83
- ' -c, --config Interactive configuration',
84
- ' -h, --help Show this help',
85
- '',
86
- 'Without options: applies config to environment and launches claude.',
87
- '',
88
- `Config file: ${CONFIG_FILE}`,
89
- '',
90
- 'Current settings:',
91
- ];
92
- for (const field of CONFIG_FIELDS) {
93
- const val = config[field.key] !== undefined && config[field.key] !== ''
94
- ? config[field.key]
95
- : '(not set)';
96
- lines.push(` ${field.key} = ${val}`);
97
- }
98
- lines.push('');
99
- console.log(lines.join('\n'));
100
- }
101
-
102
- function launchClaude(config) {
103
- const env = { ...process.env };
104
- for (const field of CONFIG_FIELDS) {
105
- if (config[field.key]) {
106
- env[field.key] = config[field.key];
107
- }
108
- }
109
- const proc = spawn('claude', [], {
110
- env,
111
- stdio: 'inherit',
112
- shell: process.platform === 'win32',
113
- });
114
- proc.on('exit', code => process.exit(code ?? 0));
115
- proc.on('error', err => {
116
- console.error(`Failed to launch claude: ${err.message}`);
117
- process.exit(1);
118
- });
119
- }
120
-
121
- async function main() {
122
- const args = process.argv.slice(2);
123
-
124
- if (args.includes('-h') || args.includes('--help')) {
125
- showHelp(loadConfig());
126
- return;
127
- }
128
-
129
- if (args.includes('-c') || args.includes('--config')) {
130
- await runConfig(CONFIG_FIELDS);
131
- return;
132
- }
133
-
134
- let config = loadConfig();
135
-
136
- const missingFields = CONFIG_FIELDS.filter(f => !config[f.key]);
137
-
138
- if (missingFields.length > 0) {
139
- console.log('Some settings are missing. Please fill them in:\n');
140
- config = await runConfig(missingFields);
141
- config = loadConfig();
142
- }
143
-
144
- launchClaude(config);
145
- }
146
-
147
- main().catch(err => {
148
- console.error(err.message);
149
- process.exit(1);
150
- });
1
+ #!/usr/bin/env node
2
+
3
+ import path from 'node:path';
4
+ import os from 'node:os';
5
+ import fs from 'node:fs';
6
+ import { createRequire } from 'node:module';
7
+
8
+ const require = createRequire(import.meta.url);
9
+ const pkg = require('../package.json');
10
+ import readline from 'node:readline';
11
+ import { spawn } from 'node:child_process';
12
+
13
+ const CONFIG_FILE = path.join(os.homedir(), '.glm-claude-code.json');
14
+
15
+ const CONFIG_FIELDS = [
16
+ {
17
+ key: 'ANTHROPIC_BASE_URL',
18
+ label: 'Anthropic Base URL',
19
+ defaultValue: 'https://api.z.ai/api/anthropic',
20
+ },
21
+ {
22
+ key: 'ANTHROPIC_AUTH_TOKEN',
23
+ label: 'Anthropic Auth Token',
24
+ defaultValue: '',
25
+ },
26
+ {
27
+ key: 'ANTHROPIC_DEFAULT_HAIKU_MODEL',
28
+ label: 'Default Haiku model',
29
+ defaultValue: 'glm-4.5-air',
30
+ },
31
+ {
32
+ key: 'ANTHROPIC_DEFAULT_SONNET_MODEL',
33
+ label: 'Default Sonnet model',
34
+ defaultValue: 'glm-5.1',
35
+ },
36
+ {
37
+ key: 'ANTHROPIC_DEFAULT_OPUS_MODEL',
38
+ label: 'Default Opus model',
39
+ defaultValue: 'glm-5.1',
40
+ },
41
+ ];
42
+
43
+ function loadConfig() {
44
+ if (!fs.existsSync(CONFIG_FILE)) return {};
45
+ try {
46
+ return JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8'));
47
+ } catch {
48
+ return {};
49
+ }
50
+ }
51
+
52
+ function saveConfig(config) {
53
+ fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2), 'utf8');
54
+ }
55
+
56
+ function ask(rl, question) {
57
+ return new Promise(resolve => rl.question(question, resolve));
58
+ }
59
+
60
+ async function runConfig(fields) {
61
+ const config = loadConfig();
62
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
63
+
64
+ console.log('\nConfiguration (press Enter to keep current value):\n');
65
+
66
+ for (const field of fields) {
67
+ const current = config[field.key] !== undefined && config[field.key] !== ''
68
+ ? config[field.key]
69
+ : field.defaultValue;
70
+ const hint = current ? ` [\x1b[32m${current}\x1b[0m]` : '';
71
+ const answer = await ask(rl, `${field.label}${hint}: `);
72
+ config[field.key] = answer.trim() !== '' ? answer.trim() : current;
73
+ }
74
+
75
+ rl.close();
76
+ saveConfig(config);
77
+ console.log(`\nConfig saved: ${CONFIG_FILE}\n`);
78
+ return config;
79
+ }
80
+
81
+ function showHelp(config) {
82
+ const lines = [
83
+ '',
84
+ 'Usage: glm [options]',
85
+ '',
86
+ 'Options:',
87
+ ' -c, --config Interactive configuration',
88
+ ' -h, --help Show this help',
89
+ '',
90
+ 'Without options: applies config to environment and launches claude.',
91
+ '',
92
+ `Config file: ${CONFIG_FILE}`,
93
+ '',
94
+ 'Current settings:',
95
+ ];
96
+ for (const field of CONFIG_FIELDS) {
97
+ const val = config[field.key] !== undefined && config[field.key] !== ''
98
+ ? config[field.key]
99
+ : '(not set)';
100
+ lines.push(` ${field.key} = ${val}`);
101
+ }
102
+ lines.push('');
103
+ console.log(lines.join('\n'));
104
+ }
105
+
106
+ function launchClaude(config) {
107
+ const env = { ...process.env };
108
+ for (const field of CONFIG_FIELDS) {
109
+ if (config[field.key]) {
110
+ env[field.key] = config[field.key];
111
+ }
112
+ }
113
+ const proc = spawn('claude', [], {
114
+ env,
115
+ stdio: 'inherit',
116
+ shell: process.platform === 'win32',
117
+ });
118
+ proc.on('exit', code => process.exit(code ?? 0));
119
+ proc.on('error', err => {
120
+ console.error(`Failed to launch claude: ${err.message}`);
121
+ process.exit(1);
122
+ });
123
+ }
124
+
125
+ async function main() {
126
+ const args = process.argv.slice(2);
127
+
128
+ if (args.includes('-v') || args.includes('-V') || args.includes('--version') || args.includes('-version')) {
129
+ console.log(pkg.version);
130
+ return;
131
+ }
132
+
133
+ if (args.includes('-h') || args.includes('--help')) {
134
+ showHelp(loadConfig());
135
+ return;
136
+ }
137
+
138
+ if (args.includes('-c') || args.includes('--config')) {
139
+ await runConfig(CONFIG_FIELDS);
140
+ return;
141
+ }
142
+
143
+ let config = loadConfig();
144
+
145
+ const missingFields = CONFIG_FIELDS.filter(f => !config[f.key]);
146
+
147
+ if (missingFields.length > 0) {
148
+ console.log('Some settings are missing. Please fill them in:\n');
149
+ config = await runConfig(missingFields);
150
+ config = loadConfig();
151
+ }
152
+
153
+ launchClaude(config);
154
+ }
155
+
156
+ main().catch(err => {
157
+ console.error(err.message);
158
+ process.exit(1);
159
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bazilio-san/glm-cc",
3
- "version": "1.0.9",
3
+ "version": "1.0.13",
4
4
  "description": "CLI tool for running claude with custom GLM configuration",
5
5
  "main": "bin/glm.js",
6
6
  "bin": {