@bazilio-san/glm-cc 1.0.22 → 1.0.24

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 CHANGED
@@ -57,23 +57,18 @@ Running `glm -c` opens an arrow-key menu that can:
57
57
  matching auto-compact threshold are derived from the model, not typed in.
58
58
  - **Tune the advanced settings** — request timeout, non-essential traffic,
59
59
  auto-compact window.
60
- - **Run a health check** — configuration files, `claude` and `git` on PATH, key
60
+ - **Run a health check** — configuration file, `claude` and `git` on PATH, key
61
61
  validity, whether the selected models exist on the server, and whether
62
62
  anything else on the machine would override what glm exports.
63
- - **Remove the glm configuration** — deletes glm's own two files and nothing
64
- else.
63
+ - **Remove the glm configuration** — deletes glm's configuration file.
65
64
 
66
65
  The first `glm` run starts the same wizard automatically when no configuration
67
66
  exists yet.
68
67
 
69
- ### Files
68
+ ### Configuration file
70
69
 
71
- glm owns exactly two files and modifies nothing else:
72
-
73
- | File | Purpose |
74
- | --- | --- |
75
- | `~/.glm-claude-code.json` | source of truth, edited through `glm -c` |
76
- | `~/.glm-claude-code.env` | flat `KEY=VALUE` sidecar read by the launcher at every start |
70
+ `glm -c` saves settings in `~/.glm-claude-code.env`. The launcher reads the
71
+ same file, one literal `KEY=VALUE` pair per line.
77
72
 
78
73
  **Claude Code's own configuration is never written to.** `~/.claude/settings.json`
79
74
  and `~/.claude.json` are left alone; the health check reads `settings.json` only
@@ -107,3 +102,4 @@ those.
107
102
  ## License
108
103
 
109
104
  MIT
105
+
package/bin/glm-config.js CHANGED
@@ -7,8 +7,7 @@
7
7
  // glm --glm-doctor → health check
8
8
  // glm --glm-version → print the glm version
9
9
  // glm --glm-help → list the glm-specific flags
10
- // Or internally by glm.cmd / glm.sh on first launch (--setup) to create
11
- // ~/.glm-claude-code.env from ~/.glm-claude-code.json.
10
+ // Or internally by the launchers for first-time setup.
12
11
  //
13
12
  // CRITICAL: this Node process must NOT stay alive while `claude` runs. glm's
14
13
  // entry point is a shell script that sets the environment variables and then
@@ -18,7 +17,7 @@
18
17
 
19
18
  import { createRequire } from 'node:module';
20
19
 
21
- import { ENV_PATH, JSON_PATH, isComplete, missingKeys, refreshEnv, load } from './lib/config.js';
20
+ import { ENV_PATH, isComplete, missingKeys, load } from './lib/config.js';
22
21
  import { runDoctor, runMainMenu, runSetup, showConfig } from './lib/wizard.js';
23
22
  import { c, write } from './lib/ui.js';
24
23
 
@@ -41,8 +40,7 @@ function printHelp () {
41
40
  write(c.gray(' so `glm -p "hello"` and `glm mcp serve` behave as usual.'));
42
41
  write(c.gray(' Note that -c is taken by glm and never reaches claude.'));
43
42
  write('');
44
- write(c.bold('Files glm owns'));
45
- write(c.gray(` ${JSON_PATH}`));
43
+ write(c.bold('Configuration file'));
46
44
  write(c.gray(` ${ENV_PATH}`));
47
45
  write(c.gray(' Claude Code\'s own configuration is never modified.'));
48
46
  write('');
@@ -73,14 +71,8 @@ async function main () {
73
71
  }
74
72
 
75
73
  if (has('--setup')) {
76
- // Called by glm.cmd / glm.sh when ~/.glm-claude-code.env is missing.
77
- // A complete JSON just needs the sidecar rewritten; anything else means
78
- // the user has to answer the setup questions.
79
74
  const config = load();
80
- if (isComplete(config)) {
81
- refreshEnv();
82
- return 0;
83
- }
75
+ if (isComplete(config)) return 0;
84
76
  const reason = Object.keys(config).length === 0
85
77
  ? 'No glm configuration found yet.'
86
78
  : `Some settings are missing: ${missingKeys(config).join(', ')}`;
package/bin/glm.cmd CHANGED
@@ -1,45 +1,43 @@
1
- :; SCRIPT="$(readlink -f "$0" 2>/dev/null || echo "$0")"; exec "$(dirname "$SCRIPT")/glm.sh" "$@"
2
- @echo off
3
- rem -------------------------------------------------------------------------
4
- rem glm — launch claude with GLM env vars. Runs as a pure cmd.exe script so
5
- rem that no intermediate node process sits between the caller (PTY / terminal)
6
- rem and claude.exe. Critical for parent-PTY scenarios where the ConPty session
7
- rem must reach claude directly for Ink-based raw-keyboard input to work.
8
- rem
9
- rem First line is a bash/batch polyglot:
10
- rem bash : `:` = no-op, `;` separator, `exec` replaces shell with glm.sh
11
- rem cmd : `:;` = malformed label, skipped silently
12
- rem -------------------------------------------------------------------------
13
-
14
- set "GLM_ARGS=%*"
15
-
16
- rem --- glm-specific flags are delegated to the node helper ----------------
17
- set "GLM_PAD= %GLM_ARGS% "
18
- echo.%GLM_PAD%| findstr /I /C:" --glm-config " /C:" --glm-show " /C:" --glm-doctor " /C:" --glm-version " /C:" --glm-help " /C:" -c " >nul
19
- if not errorlevel 1 (
20
- node "%~dp0glm-config.js" %*
21
- exit /b %errorlevel%
22
- )
23
-
24
- rem --- First-time setup if env file is missing ----------------------------
25
- set "GLM_ENV_FILE=%USERPROFILE%\.glm-claude-code.env"
26
- if not exist "%GLM_ENV_FILE%" (
27
- node "%~dp0glm-config.js" --setup
28
- if errorlevel 1 exit /b 1
29
- if not exist "%GLM_ENV_FILE%" (
30
- echo glm: setup did not produce %GLM_ENV_FILE% 1>&2
31
- exit /b 1
32
- )
33
- )
34
-
35
- rem --- Load env vars from KEY=VALUE file ----------------------------------
36
- rem Note: with `tokens=1,*` the second token is %%L (letter after %%K),
37
- rem not %%V — `for /f` names extra tokens sequentially by letter.
38
- for /f "usebackq eol=# tokens=1,* delims==" %%K in ("%GLM_ENV_FILE%") do (
39
- set "%%K=%%L"
40
- )
41
-
42
- rem --- Tail-call claude directly. `claude.exe` becomes a child of the
43
- rem outer (PTY-attached) cmd.exe process, not of any node intermediate.
44
- claude %*
45
- exit /b %errorlevel%
1
+ :; SCRIPT="$(readlink -f "$0" 2>/dev/null || echo "$0")"; exec bash "$(dirname "$SCRIPT")/glm.sh" "$@" # Windows batch follows
2
+ @echo off
3
+ rem -------------------------------------------------------------------------
4
+ rem glm — launch claude with GLM env vars. Runs as a pure cmd.exe script so
5
+ rem that no intermediate node process sits between the caller (PTY / terminal)
6
+ rem and claude.exe. Critical for parent-PTY scenarios where the ConPty session
7
+ rem must reach claude directly for Ink-based raw-keyboard input to work.
8
+ rem
9
+ rem First line is a bash/batch polyglot:
10
+ rem bash : `:` = no-op, `;` separator, `exec` replaces shell with glm.sh
11
+ rem cmd : `:;` = malformed label, skipped silently
12
+ rem -------------------------------------------------------------------------
13
+
14
+ setlocal DisableDelayedExpansion
15
+ set "GLM_ARGS=%*"
16
+
17
+ rem --- glm-specific flags are delegated to the node helper ----------------
18
+ set "GLM_PAD= %GLM_ARGS% "
19
+ echo.%GLM_PAD%| findstr /I /C:" --glm-config " /C:" --glm-show " /C:" --glm-doctor " /C:" --glm-version " /C:" --glm-help " /C:" -c " >nul
20
+ if not errorlevel 1 goto config
21
+
22
+ rem --- First-time setup if env file is missing ----------------------------
23
+ set "GLM_ENV_FILE=%USERPROFILE%\.glm-claude-code.env"
24
+ if exist "%GLM_ENV_FILE%" goto launch
25
+
26
+ :setup
27
+ node "%~dp0glm-config.js" --setup
28
+ if errorlevel 1 exit /b 1
29
+
30
+ rem --- Load env vars from KEY=VALUE file ----------------------------------
31
+ :launch
32
+ for /f "usebackq eol=# delims=" %%L in ("%GLM_ENV_FILE%") do (
33
+ set "%%L"
34
+ )
35
+
36
+ rem --- Tail-call claude directly. `claude.exe` becomes a child of the
37
+ rem outer (PTY-attached) cmd.exe process, not of any node intermediate.
38
+ claude %*
39
+ exit /b %errorlevel%
40
+
41
+ :config
42
+ node "%~dp0glm-config.js" %*
43
+ exit /b %errorlevel%
package/bin/glm.sh CHANGED
@@ -33,9 +33,11 @@ if [ ! -f "$GLM_ENV_FILE" ]; then
33
33
  fi
34
34
 
35
35
  # --- Load env vars and tail-call claude -----------------------------------
36
- set -a
37
- # shellcheck disable=SC1090
38
- . "$GLM_ENV_FILE"
39
- set +a
36
+ while IFS= read -r line || [[ -n "$line" ]]; do
37
+ line=${line%$'\r'}
38
+ if [[ $line =~ ^[A-Za-z_][A-Za-z0-9_]*= ]]; then
39
+ export "$line"
40
+ fi
41
+ done < "$GLM_ENV_FILE"
40
42
 
41
43
  exec claude "$@"
package/bin/lib/config.js CHANGED
@@ -1,19 +1,16 @@
1
1
  // Storage layer for the glm configuration.
2
2
  //
3
- // Two files, both in the user's home directory and both owned entirely by glm:
4
- // ~/.glm-claude-code.json source of truth, human-readable, edited by `glm -c`
5
- // ~/.glm-claude-code.env flat KEY=VALUE sidecar that glm.cmd / glm.sh read
6
- // at every launch without starting Node
3
+ // The menu and both launchers share ~/.glm-claude-code.env.
7
4
  //
8
5
  // Claude Code's own files (~/.claude/settings.json, ~/.claude.json) are never
9
6
  // read for writing and never modified: glm only ever exports environment
10
7
  // variables into the process it launches.
11
8
 
12
9
  import fs from 'node:fs';
10
+ import { randomUUID } from 'node:crypto';
13
11
  import os from 'node:os';
14
12
  import path from 'node:path';
15
13
 
16
- export const JSON_PATH = path.join(os.homedir(), '.glm-claude-code.json');
17
14
  export const ENV_PATH = path.join(os.homedir(), '.glm-claude-code.env');
18
15
 
19
16
  /**
@@ -87,14 +84,17 @@ export function fieldFor (key) {
87
84
  return FIELDS.find(f => f.key === key) || null;
88
85
  }
89
86
 
90
- /** Read the stored configuration. Missing or broken file yields an empty object. */
91
87
  export function load () {
92
- try {
93
- const parsed = JSON.parse(fs.readFileSync(JSON_PATH, 'utf-8'));
94
- return parsed && typeof parsed === 'object' ? parsed : {};
95
- } catch {
96
- return {};
88
+ if (!fs.existsSync(ENV_PATH)) return {};
89
+ // The file contains exactly the values exported at launch. An omitted
90
+ // variable (e.g. optional telemetry) must stay omitted on the next save.
91
+ const config = Object.fromEntries(FIELDS.map(({ key }) => [key, '']));
92
+ for (const line of fs.readFileSync(ENV_PATH, 'utf8').split(/\r?\n/)) {
93
+ const split = line.indexOf('=');
94
+ const key = line.slice(0, split);
95
+ if (split > 0 && Object.hasOwn(config, key)) config[key] = line.slice(split + 1);
97
96
  }
97
+ return config;
98
98
  }
99
99
 
100
100
  /**
@@ -125,60 +125,21 @@ export function missingKeys (config = load()) {
125
125
  });
126
126
  }
127
127
 
128
- function writeJson (config) {
129
- // Keep a stable key order so the file stays reviewable in a diff.
130
- const ordered = {};
131
- for (const field of FIELDS) {
132
- if (config[field.key] != null) ordered[field.key] = String(config[field.key]);
133
- }
134
- for (const [key, value] of Object.entries(config)) {
135
- if (!(key in ordered) && value != null) ordered[key] = String(value);
136
- }
137
- fs.writeFileSync(JSON_PATH, `${JSON.stringify(ordered, null, 2)}\n`, 'utf-8');
138
- }
139
-
140
- function writeEnv (config) {
141
- const values = effective(config);
142
- const header = [
143
- // Plain ASCII only: cmd.exe reads this file under whatever code page the
144
- // console happens to be using.
145
- '# Generated by @bazilio-san/glm-cc - do not edit by hand.',
146
- '# Change these values with `glm -c`.',
147
- '# Read by bin/glm.cmd and bin/glm.sh, then exported into `claude`.',
148
- ];
149
- const body = FIELDS
150
- // An empty value means "leave this variable unset" rather than "set it to
151
- // an empty string", so those lines are omitted entirely.
152
- .filter(field => String(values[field.key] ?? '').trim() !== '')
153
- .map(field => `${field.key}=${values[field.key]}`);
154
- fs.writeFileSync(ENV_PATH, `${[...header, ...body].join('\n')}\n`, 'utf-8');
155
- }
156
-
157
- /** Persist to both files at once — they must never drift apart. */
158
128
  export function save (config) {
159
- writeJson(config);
160
- writeEnv(config);
161
- }
162
-
163
- /** Regenerate only the env sidecar from the stored JSON. */
164
- export function refreshEnv () {
165
- writeEnv(load());
166
- }
167
-
168
- /** Delete both files. Returns the paths that actually existed. */
169
- export function removeAll () {
170
- const removed = [];
171
- for (const file of [JSON_PATH, ENV_PATH]) {
172
- if (fs.existsSync(file)) {
173
- fs.unlinkSync(file);
174
- removed.push(file);
175
- }
129
+ const values = effective(config);
130
+ const lines = ['# glm configuration. Change these values with glm -c.'];
131
+ for (const { key } of FIELDS) {
132
+ const value = values[key];
133
+ if (/[\r\n\0]/.test(value)) throw new Error(`${key} must be a single line of text.`);
134
+ if (value.trim()) lines.push(`${key}=${value}`);
135
+ }
136
+ const temp = `${ENV_PATH}.${randomUUID()}.tmp`;
137
+ try {
138
+ fs.writeFileSync(temp, lines.join('\n') + '\n', { mode: 0o600, flag: 'wx' });
139
+ fs.renameSync(temp, ENV_PATH);
140
+ } finally {
141
+ fs.rmSync(temp, { force: true });
176
142
  }
177
- return removed;
178
- }
179
-
180
- export function exists () {
181
- return fs.existsSync(JSON_PATH);
182
143
  }
183
144
 
184
145
  /** Show only the first and last few characters of a secret. */
package/bin/lib/wizard.js CHANGED
@@ -1,7 +1,6 @@
1
1
  // Interactive screens for `glm -c`.
2
2
  //
3
- // Everything here writes to ~/.glm-claude-code.json and ~/.glm-claude-code.env
4
- // and to nothing else. Claude Code's own configuration is only ever read, and
3
+ // Settings are stored in ~/.glm-claude-code.env. Claude Code's own configuration is only ever read, and
5
4
  // only by the health check, which reports conflicts instead of fixing them.
6
5
 
7
6
  import { spawnSync } from 'node:child_process';
@@ -11,7 +10,6 @@ import path from 'node:path';
11
10
 
12
11
  import {
13
12
  ENV_PATH,
14
- JSON_PATH,
15
13
  FIELDS,
16
14
  DEFAULTS,
17
15
  effective,
@@ -19,7 +17,6 @@ import {
19
17
  load,
20
18
  maskSecret,
21
19
  missingKeys,
22
- removeAll,
23
20
  save,
24
21
  } from './config.js';
25
22
  import { listModels, validateApiKey } from './api.js';
@@ -85,8 +82,7 @@ function printStatus (config) {
85
82
  write(` ${c.gray('Telemetry :')} ${values.CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC === '1' ? 'non-essential traffic off' : 'left at the Claude Code default'}`);
86
83
  write(` ${c.gray('Compact at :')} ${formatTokens(values.CLAUDE_CODE_AUTO_COMPACT_WINDOW)} tokens`);
87
84
  write('');
88
- write(c.gray(` Files: ${JSON_PATH}`));
89
- write(c.gray(` ${ENV_PATH}`));
85
+ write(c.gray(` File: ${ENV_PATH}`));
90
86
  write('');
91
87
  }
92
88
 
@@ -95,7 +91,6 @@ export function showConfig () {
95
91
  const values = effective(config);
96
92
  write('');
97
93
  write(c.bold('glm configuration'));
98
- write(c.gray(` ${JSON_PATH}`));
99
94
  write(c.gray(` ${ENV_PATH}`));
100
95
  write('');
101
96
  for (const field of FIELDS) {
@@ -467,11 +462,9 @@ export async function runDoctor () {
467
462
  const results = [];
468
463
  const add = (name, passed, message) => results.push({ name, passed, message });
469
464
 
470
- const check = spinner('Checking configuration files…');
471
- add('Configuration files', fs.existsSync(JSON_PATH) && fs.existsSync(ENV_PATH),
472
- fs.existsSync(JSON_PATH) && fs.existsSync(ENV_PATH)
473
- ? undefined
474
- : 'One of the two files is missing — run `glm -c` to regenerate them');
465
+ const check = spinner('Checking the configuration file…');
466
+ const hasConfig = fs.existsSync(ENV_PATH);
467
+ add('Configuration file', hasConfig, hasConfig ? undefined : 'Run `glm -c` to create it');
475
468
 
476
469
  const complete = isComplete(config);
477
470
  add('Required settings', complete, complete ? undefined : `Missing: ${missingKeys(config).join(', ')}`);
@@ -558,7 +551,7 @@ export async function runSetup (version, { reason } = {}) {
558
551
  write('');
559
552
  }
560
553
  write(c.gray(' Three questions: which server, which key, which models.'));
561
- write(c.gray(` Answers are stored in ${JSON_PATH}`));
554
+ write(c.gray(` Answers are stored in ${ENV_PATH}`));
562
555
  write(c.gray(' Claude Code\'s own configuration is left untouched.'));
563
556
  write('');
564
557
 
@@ -693,16 +686,12 @@ export async function runMainMenu (version) {
693
686
 
694
687
  if (action === 'remove') {
695
688
  header(version, 'Remove the glm configuration');
696
- write(c.gray(' This deletes both glm files. Claude Code and its own settings stay as they are.'));
697
- write(c.gray(` ${JSON_PATH}`));
698
689
  write(c.gray(` ${ENV_PATH}`));
699
690
  write('');
700
- const sure = await confirm({ message: 'Delete them?', defaultValue: false });
691
+ const sure = await confirm({ message: 'Delete this configuration file?', defaultValue: false });
701
692
  if (sure) {
702
- const removed = removeAll();
693
+ fs.rmSync(ENV_PATH, { force: true });
703
694
  write('');
704
- if (removed.length === 0) write(c.gray(' Nothing to delete.'));
705
- else removed.forEach(file => write(c.green(` Deleted ${file}`)));
706
695
  write(c.gray(' The next `glm` run will ask you to set things up again.'));
707
696
  config = {};
708
697
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bazilio-san/glm-cc",
3
- "version": "1.0.22",
3
+ "version": "1.0.24",
4
4
  "description": "CLI tool for running claude with custom GLM configuration",
5
5
  "bin": {
6
6
  "glm": "bin/glm.cmd"