@bazilio-san/glm-cc 1.0.19 → 1.0.22

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/package.json CHANGED
@@ -1,11 +1,18 @@
1
1
  {
2
2
  "name": "@bazilio-san/glm-cc",
3
- "version": "1.0.19",
3
+ "version": "1.0.22",
4
4
  "description": "CLI tool for running claude with custom GLM configuration",
5
- "main": "bin/glm.js",
6
5
  "bin": {
7
- "glm": "bin/glm.js"
6
+ "glm": "bin/glm.cmd"
8
7
  },
8
+ "files": [
9
+ "bin/glm.cmd",
10
+ "bin/glm.sh",
11
+ "bin/glm-config.js",
12
+ "bin/lib/",
13
+ "LICENSE",
14
+ "README.md"
15
+ ],
9
16
  "type": "module",
10
17
  "scripts": {
11
18
  "test": "echo \"Error: no test specified\" && exit 1"
package/bin/glm.js DELETED
@@ -1,211 +0,0 @@
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 showConfig(config) {
82
- const lines = [
83
- '',
84
- `Config file: ${CONFIG_FILE}`,
85
- '',
86
- 'Current settings:',
87
- ];
88
- for (const field of CONFIG_FIELDS) {
89
- const val = config[field.key] !== undefined && config[field.key] !== ''
90
- ? config[field.key]
91
- : '(not set)';
92
- lines.push(` ${field.key} = ${val}`);
93
- }
94
- lines.push('');
95
- console.log(lines.join('\n'));
96
- }
97
-
98
- // Resolve `claude` into { cmd, args, useShell } without an extra cmd.exe
99
- // layer on Windows. A nested cmd.exe breaks ConPty stdin for Ink-based TUIs
100
- // (e.g. when glm is spawned via node-pty from a test harness).
101
- function resolveClaude() {
102
- if (process.platform !== 'win32') {
103
- return { cmd: 'claude', prefix: [], useShell: false };
104
- }
105
-
106
- const pathExts = (process.env.PATHEXT || '.COM;.EXE;.BAT;.CMD')
107
- .split(';').map(e => e.toLowerCase()).filter(Boolean);
108
- const pathDirs = (process.env.PATH || '').split(path.delimiter).filter(Boolean);
109
-
110
- let exePath = null;
111
- let cmdPath = null;
112
- for (const dir of pathDirs) {
113
- for (const ext of pathExts) {
114
- const full = path.join(dir, 'claude' + ext);
115
- if (!fs.existsSync(full)) continue;
116
- if (ext === '.exe' && !exePath) exePath = full;
117
- else if ((ext === '.cmd' || ext === '.bat') && !cmdPath) cmdPath = full;
118
- }
119
- if (exePath) break;
120
- }
121
-
122
- // Prefer native .exe — spawn directly, no shell layer.
123
- if (exePath) {
124
- return { cmd: exePath, prefix: [], useShell: false };
125
- }
126
-
127
- // npm shim on Windows looks like:
128
- // @"C:\Program Files\nodejs\node.exe" "...\cli.js" %*
129
- // Parse it and spawn node directly so we skip the shim's cmd.exe.
130
- if (cmdPath) {
131
- try {
132
- const shim = fs.readFileSync(cmdPath, 'utf8');
133
- const m = shim.match(/"([^"]+\\node\.exe)"\s+"([^"]+\.(?:js|mjs|cjs))"/i);
134
- if (m) {
135
- return { cmd: m[1], prefix: [m[2]], useShell: false };
136
- }
137
- } catch { /* fall through */ }
138
- // Can't parse — must go through shell for .cmd execution.
139
- return { cmd: cmdPath, prefix: [], useShell: true };
140
- }
141
-
142
- // Nothing found — let cmd.exe resolve at runtime (legacy behavior).
143
- return { cmd: 'claude', prefix: [], useShell: true };
144
- }
145
-
146
- function launchClaude(config, args) {
147
- const env = { ...process.env };
148
- for (const field of CONFIG_FIELDS) {
149
- if (config[field.key]) {
150
- env[field.key] = config[field.key];
151
- }
152
- }
153
-
154
- const { cmd, prefix, useShell } = resolveClaude();
155
- const proc = spawn(cmd, [...prefix, ...args], {
156
- env,
157
- stdio: 'inherit',
158
- shell: useShell,
159
- });
160
-
161
- const signals = ['SIGINT', 'SIGTERM', 'SIGHUP', 'SIGBREAK'];
162
- for (const sig of signals) {
163
- process.on(sig, () => {
164
- try { proc.kill(sig); } catch { /* */ }
165
- });
166
- }
167
-
168
- proc.on('exit', code => process.exit(code ?? 0));
169
- proc.on('error', err => {
170
- console.error(`Failed to launch claude: ${err.message}`);
171
- process.exit(1);
172
- });
173
- }
174
-
175
- async function main() {
176
- const args = process.argv.slice(2);
177
-
178
- // Only glm-specific flags: --config, --show-config, --glm-version
179
- if (args.includes('--glm-config') || args.includes('-c')) {
180
- await runConfig(CONFIG_FIELDS);
181
- return;
182
- }
183
-
184
- if (args.includes('--glm-show')) {
185
- showConfig(loadConfig());
186
- return;
187
- }
188
-
189
- if (args.includes('--glm-version')) {
190
- console.log(`glm v${pkg.version}`);
191
- return;
192
- }
193
-
194
- let config = loadConfig();
195
-
196
- const missingFields = CONFIG_FIELDS.filter(f => !config[f.key]);
197
-
198
- if (missingFields.length > 0) {
199
- console.log('Some settings are missing. Please fill them in:\n');
200
- config = await runConfig(missingFields);
201
- config = loadConfig();
202
- }
203
-
204
- // All arguments are passed through to claude
205
- launchClaude(config, args);
206
- }
207
-
208
- main().catch(err => {
209
- console.error(err.message);
210
- process.exit(1);
211
- });