codemax-pro 1.4.2 → 1.4.3
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 +93 -85
- package/index.js +339 -301
- package/lib.js +509 -487
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,301 +1,339 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/* CodeMax setup for Claude Code and Claude Desktop.
|
|
4
|
-
*
|
|
5
|
-
* codemax-pro [key] configure everything
|
|
6
|
-
* codemax-pro doctor report what is actually configured, and what is fighting it
|
|
7
|
-
* codemax-pro reset remove what this tool set, and nothing else
|
|
8
|
-
*
|
|
9
|
-
* The three commands share one description of every location (lib.js) on purpose: when setup,
|
|
10
|
-
* doctor and reset each carry their own idea of where things live, reset starts leaving behind
|
|
11
|
-
* things doctor never learned to look for. */
|
|
12
|
-
|
|
13
|
-
'use strict';
|
|
14
|
-
|
|
15
|
-
const readline = require('readline');
|
|
16
|
-
const L = require('./lib');
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
problems++;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
step('
|
|
151
|
-
|
|
152
|
-
if (!
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
p(` ${c.
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
if (
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
if (
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/* CodeMax setup for Claude Code and Claude Desktop.
|
|
4
|
+
*
|
|
5
|
+
* codemax-pro [key] configure everything
|
|
6
|
+
* codemax-pro doctor report what is actually configured, and what is fighting it
|
|
7
|
+
* codemax-pro reset remove what this tool set, and nothing else
|
|
8
|
+
*
|
|
9
|
+
* The three commands share one description of every location (lib.js) on purpose: when setup,
|
|
10
|
+
* doctor and reset each carry their own idea of where things live, reset starts leaving behind
|
|
11
|
+
* things doctor never learned to look for. */
|
|
12
|
+
|
|
13
|
+
'use strict';
|
|
14
|
+
|
|
15
|
+
const readline = require('readline');
|
|
16
|
+
const L = require('./lib');
|
|
17
|
+
|
|
18
|
+
// PowerShell's default execution policy blocks npx.ps1; npx.cmd runs in PowerShell and cmd alike.
|
|
19
|
+
const NPX = L.IS_WIN ? 'npx.cmd' : 'npx';
|
|
20
|
+
|
|
21
|
+
const c = {
|
|
22
|
+
reset: '\x1b[0m', bold: '\x1b[1m', dim: '\x1b[2m',
|
|
23
|
+
cyan: '\x1b[36m', green: '\x1b[32m', yellow: '\x1b[33m', red: '\x1b[31m',
|
|
24
|
+
gray: '\x1b[90m', white: '\x1b[97m',
|
|
25
|
+
};
|
|
26
|
+
const NO_COLOR = !!process.env.NO_COLOR || !process.stdout.isTTY;
|
|
27
|
+
const p = (s = '') => console.log(NO_COLOR ? String(s).replace(/\x1b\[[0-9;]*m/g, '') : s);
|
|
28
|
+
const ok = (m) => p(` ${c.green}✓${c.reset} ${m}`);
|
|
29
|
+
const bad = (m) => p(` ${c.red}✗${c.reset} ${m}`);
|
|
30
|
+
const warn = (m) => p(` ${c.yellow}!${c.reset} ${m}`);
|
|
31
|
+
const step = (m) => p(`\n${c.cyan}${m}${c.reset}`);
|
|
32
|
+
const dim = (m) => p(` ${c.gray}${m}${c.reset}`);
|
|
33
|
+
|
|
34
|
+
function ask(q) {
|
|
35
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
36
|
+
return new Promise((res) => rl.question(q, (a) => { rl.close(); res(a.trim()); }));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function header() {
|
|
40
|
+
p('');
|
|
41
|
+
p(` ${c.bold}CodeMax${c.reset} ${c.gray}·${c.reset} ${L.API_ENDPOINT}`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/* A value under SOFTWARE\Policies\Claude outranks everything this tool writes, and the app shows it
|
|
45
|
+
* as "Organization-managed" with every field locked. Shared by setup, doctor and reset so all three
|
|
46
|
+
* describe the same finding the same way. Returns how many findings still lock the app. */
|
|
47
|
+
function reportPolicies(policies) {
|
|
48
|
+
let locked = 0;
|
|
49
|
+
for (const pol of policies) {
|
|
50
|
+
if (pol.removed) {
|
|
51
|
+
ok('removed an old CodeMax policy that had locked Claude Desktop ("Organization-managed")');
|
|
52
|
+
dim(pol.key);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
locked++;
|
|
56
|
+
if (pol.ours && pol.scope === 'user') {
|
|
57
|
+
// Our own values still there means the delete was refused: it needs an administrator.
|
|
58
|
+
const ownLeft = !pol.attempted || pol.left.some((n) => L.POLICY_VALUES.includes(n));
|
|
59
|
+
bad('Claude Desktop is locked ("Organization-managed") by an old CodeMax policy, which overrides this setup');
|
|
60
|
+
if (ownLeft) {
|
|
61
|
+
dim('To unlock it, open PowerShell as Administrator and run:');
|
|
62
|
+
dim(`${NPX} codemax-pro@latest`);
|
|
63
|
+
} else {
|
|
64
|
+
dim(`${pol.key} still holds other values: ${pol.left.join(', ')}`);
|
|
65
|
+
dim(`To unlock it, in PowerShell as Administrator: reg delete "${pol.key}" /f`);
|
|
66
|
+
}
|
|
67
|
+
} else if (pol.ours) {
|
|
68
|
+
bad('Claude Desktop is locked ("Organization-managed") by a CodeMax policy set for the whole computer');
|
|
69
|
+
dim('This tool leaves a machine-wide policy alone. To unlock it, in PowerShell as Administrator:');
|
|
70
|
+
dim(`reg delete "${pol.key}" /f`);
|
|
71
|
+
} else {
|
|
72
|
+
bad('Claude Desktop is managed by a policy on this computer that points elsewhere, and it overrides this setup');
|
|
73
|
+
dim(`${pol.key} → ${pol.values.inferenceGatewayBaseUrl || '(no endpoint)'} — whoever manages this computer has to change it`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return locked;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// ─── doctor ──────────────────────────────────────────────────────────────────
|
|
80
|
+
|
|
81
|
+
/* Reads only. Its value is naming the failures that produce no error anywhere: a machine-wide
|
|
82
|
+
* policy that silently outranks the per-user one, an environment variable that outranks the
|
|
83
|
+
* settings file, and an app still running with the configuration it read at launch. Each of those
|
|
84
|
+
* looks exactly like "the installer did not work" from the outside. */
|
|
85
|
+
async function doctor() {
|
|
86
|
+
header();
|
|
87
|
+
let problems = 0;
|
|
88
|
+
|
|
89
|
+
step('Claude Code CLI');
|
|
90
|
+
const cli = L.readCliState();
|
|
91
|
+
if (!cli.exists) {
|
|
92
|
+
warn('not configured — no settings file');
|
|
93
|
+
dim(cli.file);
|
|
94
|
+
problems++;
|
|
95
|
+
} else {
|
|
96
|
+
const pointed = cli.baseUrl === L.API_ENDPOINT;
|
|
97
|
+
(pointed ? ok : bad)(`endpoint ${cli.baseUrl || '(not set)'}`);
|
|
98
|
+
if (!pointed) problems++;
|
|
99
|
+
(cli.key ? ok : bad)(`key ${L.redact(cli.key)}`);
|
|
100
|
+
if (!cli.key) problems++;
|
|
101
|
+
if (cli.defaultModelVars.length === 3) ok('default model settings present');
|
|
102
|
+
else warn(`default model settings incomplete (${cli.defaultModelVars.length}/3) — the default may not be Opus 5`);
|
|
103
|
+
if (cli.stalePresent.length) { warn(`stale variables present: ${cli.stalePresent.join(', ')}`); problems++; }
|
|
104
|
+
if (cli.pinnedModel) { warn(`a model is pinned in settings ("${cli.pinnedModel}") — this adds a duplicate picker entry`); problems++; }
|
|
105
|
+
dim(cli.file);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const info = L.claudeCliInfo();
|
|
109
|
+
if (info.installed) {
|
|
110
|
+
ok(`claude CLI installed${info.version ? ` ${info.version}` : ''}`);
|
|
111
|
+
if (!info.version && info.at) dim(info.at);
|
|
112
|
+
} else warn('claude CLI not found — run: npm install -g @anthropic-ai/claude-code');
|
|
113
|
+
|
|
114
|
+
/* Two places, for two different situations. The local profile is the ordinary user's, and the
|
|
115
|
+
* only one this tool writes. The registry branch under SOFTWARE\Policies is the managed one: when
|
|
116
|
+
* it holds anything, it wins, the app locks every field as "Organization-managed", and the profile
|
|
117
|
+
* is ignored. So an absent policy is the healthy state and says nothing; a present one is the
|
|
118
|
+
* first thing to name, because it makes a correct profile look like a setup that did not work. */
|
|
119
|
+
step('Claude Desktop');
|
|
120
|
+
const d = L.readDesktopState();
|
|
121
|
+
const prof = d.profile;
|
|
122
|
+
if (prof && prof.inferenceProvider === 'gateway' && prof.inferenceGatewayBaseUrl === L.API_ENDPOINT) {
|
|
123
|
+
ok(`provider gateway → ${prof.inferenceGatewayBaseUrl}`);
|
|
124
|
+
const scheme = prof.inferenceGatewayAuthScheme;
|
|
125
|
+
(scheme === 'x-api-key' ? ok : bad)(`auth ${scheme || '(default — expect 401)'}`);
|
|
126
|
+
if (scheme !== 'x-api-key') problems++;
|
|
127
|
+
const n = Array.isArray(prof.inferenceModels) ? prof.inferenceModels.length : 0;
|
|
128
|
+
const oneM = Array.isArray(prof.inferenceModels) ? prof.inferenceModels.filter((m) => m && m.supports1m).length : 0;
|
|
129
|
+
// A 1M model without `prefer1m` shows twice in the picker (200K and 1M) — say so rather than
|
|
130
|
+
// report a count that does not match what the customer sees.
|
|
131
|
+
const twice = Array.isArray(prof.inferenceModels) ? prof.inferenceModels.filter((m) => m && m.supports1m && !m.prefer1m).length : 0;
|
|
132
|
+
(n ? ok : bad)(`models ${n} configured${oneM ? `, ${oneM} at 1M` : ''}${twice ? ` (${twice} also listed at 200K — re-run setup)` : ''}`);
|
|
133
|
+
if (!n) problems++;
|
|
134
|
+
// Old ids still answer, so an outdated list never errors: the picker just shows old names.
|
|
135
|
+
const have = Array.isArray(prof.inferenceModels) ? prof.inferenceModels.map((m) => m && m.name) : [];
|
|
136
|
+
const missing = L.MODELS.map((m) => m.name).filter((id) => !have.includes(id));
|
|
137
|
+
if (n && missing.length) {
|
|
138
|
+
warn(`model list is out of date (no ${missing.join(', ')}) — run: ${NPX} codemax-pro@latest`);
|
|
139
|
+
problems++;
|
|
140
|
+
}
|
|
141
|
+
ok(`fetch egress ${JSON.stringify(prof.coworkEgressAllowedHosts || [])}, preflight ${prof.skipWebFetchPreflight ? 'off' : 'ON'}`);
|
|
142
|
+
dim(prof.file);
|
|
143
|
+
} else {
|
|
144
|
+
bad('not configured — run `codemax-pro` to set it up');
|
|
145
|
+
problems++;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
problems += reportPolicies(d.policies);
|
|
149
|
+
|
|
150
|
+
step('Conflicts');
|
|
151
|
+
const conflicts = L.readEnvConflicts();
|
|
152
|
+
if (!conflicts.length) ok('no environment variables competing with the settings file');
|
|
153
|
+
else {
|
|
154
|
+
for (const v of conflicts) bad(`${v.name} = ${v.value} (${v.scope}) — this OUTRANKS the settings file`);
|
|
155
|
+
dim('run `codemax-pro` again to clear the persisted ones');
|
|
156
|
+
problems += conflicts.length;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
step('Connection');
|
|
160
|
+
const ownPolicy = d.policies.find((pol) => pol.ours);
|
|
161
|
+
const key = cli.key || (ownPolicy && ownPolicy.values.inferenceGatewayApiKey) || (d.profile && d.profile.inferenceGatewayApiKey);
|
|
162
|
+
if (!key) { bad('no key found to test'); problems++; }
|
|
163
|
+
else {
|
|
164
|
+
const r = await L.checkKey(key);
|
|
165
|
+
if (r.ok) ok(`endpoint reachable, key accepted ${r.ms}ms${r.note ? ` (${r.note})` : ''}`);
|
|
166
|
+
else { bad(`${r.reason} ${r.ms}ms`); problems++; }
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
p('');
|
|
170
|
+
if (problems === 0) {
|
|
171
|
+
p(` ${c.green}Everything checks out.${c.reset}`);
|
|
172
|
+
p(` ${c.gray}If the desktop app still behaves as before, it is still running with the${c.reset}`);
|
|
173
|
+
p(` ${c.gray}configuration it read at launch — quit it from the tray, then reopen.${c.reset}`);
|
|
174
|
+
} else {
|
|
175
|
+
p(` ${c.yellow}${problems} thing${problems > 1 ? 's' : ''} to look at, listed above.${c.reset}`);
|
|
176
|
+
}
|
|
177
|
+
p('');
|
|
178
|
+
return problems === 0 ? 0 : 1;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// ─── reset ───────────────────────────────────────────────────────────────────
|
|
182
|
+
|
|
183
|
+
async function reset(opts) {
|
|
184
|
+
header();
|
|
185
|
+
step('Reset');
|
|
186
|
+
p(` ${c.gray}Removes only what this tool set. Anything else in those files stays.${c.reset}`);
|
|
187
|
+
if (!opts.yes) {
|
|
188
|
+
const a = await ask(`\n Continue? ${c.gray}(y/N)${c.reset} `);
|
|
189
|
+
if (a.toLowerCase() !== 'y') { p('\n Cancelled.\n'); return 0; }
|
|
190
|
+
}
|
|
191
|
+
const { removed, policies } = L.resetAll();
|
|
192
|
+
p('');
|
|
193
|
+
if (!removed.length) ok('nothing to remove — no CodeMax settings found');
|
|
194
|
+
else for (const r of removed) ok(`removed ${r}`);
|
|
195
|
+
reportPolicies(policies);
|
|
196
|
+
p('');
|
|
197
|
+
p(` ${c.gray}Restart Claude Code and quit Claude Desktop from the tray to apply.${c.reset}`);
|
|
198
|
+
p('');
|
|
199
|
+
// Our own policy still in place means reset did not finish its job.
|
|
200
|
+
return policies.some((pol) => pol.ours && pol.scope === 'user') ? 1 : 0;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// ─── setup ───────────────────────────────────────────────────────────────────
|
|
204
|
+
|
|
205
|
+
async function setup(opts) {
|
|
206
|
+
header();
|
|
207
|
+
|
|
208
|
+
let key = opts.key || process.env.CODEMAX_API_KEY || '';
|
|
209
|
+
if (!key) {
|
|
210
|
+
if (opts.yes) { bad('no key given, and --yes means nothing can be asked'); return 1; }
|
|
211
|
+
p('');
|
|
212
|
+
p(` ${c.white}Paste your CodeMax API key${c.reset} ${c.gray}(from codemax.pro)${c.reset}`);
|
|
213
|
+
key = await ask(' › ');
|
|
214
|
+
}
|
|
215
|
+
if (!key || key.length < 8) { p(''); bad('that does not look like a key'); p(''); return 1; }
|
|
216
|
+
|
|
217
|
+
step('Checking the key');
|
|
218
|
+
const check = await L.checkKey(key);
|
|
219
|
+
if (check.ok) ok(`accepted ${check.ms}ms${check.note ? ` (${check.note})` : ''}`);
|
|
220
|
+
else if (check.network) {
|
|
221
|
+
warn(`could not reach the endpoint: ${check.reason}`);
|
|
222
|
+
if (!opts.yes) {
|
|
223
|
+
const a = await ask(` Configure anyway? ${c.gray}(y/N)${c.reset} `);
|
|
224
|
+
if (a.toLowerCase() !== 'y') { p(''); return 1; }
|
|
225
|
+
}
|
|
226
|
+
} else { bad(check.reason); p(''); return 1; }
|
|
227
|
+
|
|
228
|
+
const want = (t) => !opts.only || opts.only === t;
|
|
229
|
+
let desktopLocked = 0;
|
|
230
|
+
|
|
231
|
+
if (want('cli')) {
|
|
232
|
+
step('Claude Code CLI and VS Code');
|
|
233
|
+
const r = L.configureCli(key);
|
|
234
|
+
ok(r.file);
|
|
235
|
+
if (r.backup) dim(`previous settings kept at ${r.backup}`);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (want('desktop')) {
|
|
239
|
+
step('Claude Desktop');
|
|
240
|
+
const r = L.configureDesktop(key);
|
|
241
|
+
for (const w of r.written) ok(w);
|
|
242
|
+
if (!r.written.length) warn('nothing could be written — is the app installed?');
|
|
243
|
+
desktopLocked = reportPolicies(r.policies);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const cleaned = L.cleanLegacy();
|
|
247
|
+
if (cleaned.length) {
|
|
248
|
+
step('Cleaned up');
|
|
249
|
+
for (const r of cleaned) dim(r);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (want('cli') && !L.claudeCliInfo().installed) {
|
|
253
|
+
step('Installing Claude Code CLI');
|
|
254
|
+
if (L.sh('npm install -g @anthropic-ai/claude-code') !== null) ok('installed');
|
|
255
|
+
else warn('could not install — run: npm install -g @anthropic-ai/claude-code');
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/* Verifying after writing, not before. The check above proved the key works; this proves the
|
|
259
|
+
* configuration that was just written is the configuration a client will read. */
|
|
260
|
+
step('Verifying');
|
|
261
|
+
const after = L.readCliState();
|
|
262
|
+
if (!want('cli')) dim('skipped — CLI was not configured this run');
|
|
263
|
+
else if (after.baseUrl === L.API_ENDPOINT && after.key) ok('settings file reads back correctly');
|
|
264
|
+
else bad('settings file did not read back as expected — run `codemax-pro doctor`');
|
|
265
|
+
|
|
266
|
+
const conflicts = L.readEnvConflicts();
|
|
267
|
+
if (conflicts.length) {
|
|
268
|
+
for (const v of conflicts) warn(`${v.name} is set (${v.scope}) and outranks the settings file`);
|
|
269
|
+
} else ok('nothing competing with the settings file');
|
|
270
|
+
|
|
271
|
+
p('');
|
|
272
|
+
/* "Done" over a locked app hides the problem: the run looks successful and the picker never
|
|
273
|
+
* changes. Say plainly which half is finished. */
|
|
274
|
+
if (desktopLocked) {
|
|
275
|
+
p(` ${c.yellow}Claude Code is set up. Claude Desktop is still locked: see "Claude Desktop" above.${c.reset}`);
|
|
276
|
+
p('');
|
|
277
|
+
return 1;
|
|
278
|
+
}
|
|
279
|
+
p(` ${c.green}Done.${c.reset}`);
|
|
280
|
+
p('');
|
|
281
|
+
p(` ${c.white}Claude Desktop must be quit from the tray, not just closed.${c.reset}`);
|
|
282
|
+
p(` ${c.gray}It reads its configuration once at launch, so a window reopened from a${c.reset}`);
|
|
283
|
+
p(` ${c.gray}running process keeps the old settings and looks like this did not work.${c.reset}`);
|
|
284
|
+
p('');
|
|
285
|
+
p(` ${c.gray}Check anything at any time: ${c.reset}codemax-pro doctor`);
|
|
286
|
+
p('');
|
|
287
|
+
return 0;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// ─── entry ───────────────────────────────────────────────────────────────────
|
|
291
|
+
|
|
292
|
+
function help() {
|
|
293
|
+
p(`
|
|
294
|
+
${c.bold}codemax-pro${c.reset} ${c.gray}· setup for Claude Code and Claude Desktop${c.reset}
|
|
295
|
+
|
|
296
|
+
${c.white}codemax-pro${c.reset} [key] configure everything
|
|
297
|
+
${c.white}codemax-pro doctor${c.reset} report what is configured, and what is fighting it
|
|
298
|
+
${c.white}codemax-pro reset${c.reset} remove what this tool set
|
|
299
|
+
|
|
300
|
+
${c.gray}--yes${c.reset} never prompt
|
|
301
|
+
${c.gray}--only cli|desktop${c.reset} configure one surface only
|
|
302
|
+
|
|
303
|
+
${c.gray}The key can also come from CODEMAX_API_KEY.${c.reset}
|
|
304
|
+
`);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
async function main() {
|
|
308
|
+
const argv = process.argv.slice(2);
|
|
309
|
+
const opts = { yes: false, only: null, key: '' };
|
|
310
|
+
const rest = [];
|
|
311
|
+
for (let i = 0; i < argv.length; i++) {
|
|
312
|
+
const a = argv[i];
|
|
313
|
+
if (a === '--yes' || a === '-y') opts.yes = true;
|
|
314
|
+
else if (a === '--only') opts.only = (argv[++i] || '').toLowerCase();
|
|
315
|
+
else if (a.startsWith('--only=')) opts.only = a.slice(7).toLowerCase();
|
|
316
|
+
else if (a === '--help' || a === '-h') { help(); return 0; }
|
|
317
|
+
else rest.push(a);
|
|
318
|
+
}
|
|
319
|
+
if (opts.only && !['cli', 'desktop'].includes(opts.only)) {
|
|
320
|
+
bad(`--only takes "cli" or "desktop", not "${opts.only}"`);
|
|
321
|
+
return 1;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const cmd = (rest[0] || '').toLowerCase();
|
|
325
|
+
if (cmd === 'doctor') return doctor();
|
|
326
|
+
if (cmd === 'reset') return reset(opts);
|
|
327
|
+
if (cmd === 'help') { help(); return 0; }
|
|
328
|
+
// Anything else is treated as the key, so `codemax-pro sk-cp-…` keeps working.
|
|
329
|
+
opts.key = rest[0] || '';
|
|
330
|
+
return setup(opts);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/* Set the exit code and let Node wind down on its own, rather than calling process.exit().
|
|
334
|
+
* Forcing an exit while a socket from the connection check is still tearing down is what produced
|
|
335
|
+
* the libuv assertion above; setting the code lets the loop drain first and reports the same
|
|
336
|
+
* result to the shell. */
|
|
337
|
+
main()
|
|
338
|
+
.then((code) => { process.exitCode = code || 0; })
|
|
339
|
+
.catch((e) => { p(''); bad(e.message); p(''); process.exitCode = 1; });
|