codemax-pro 1.2.1 → 1.3.1
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 +50 -56
- package/index.js +277 -484
- package/lib.js +455 -0
- package/package.json +3 -2
package/lib.js
ADDED
|
@@ -0,0 +1,455 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/* Everything the CLI does, minus the talking. index.js owns argument parsing and output; this file
|
|
4
|
+
* owns the facts — where configuration lives, what is currently in it, and how to change it.
|
|
5
|
+
*
|
|
6
|
+
* Split out because the three commands need the same answers: setup writes what doctor reads and
|
|
7
|
+
* reset removes. Sharing one description of each location is what keeps them from drifting, which
|
|
8
|
+
* is how a `reset` ends up leaving something behind that `doctor` never looks for. */
|
|
9
|
+
|
|
10
|
+
const fs = require('fs');
|
|
11
|
+
const os = require('os');
|
|
12
|
+
const path = require('path');
|
|
13
|
+
const crypto = require('crypto');
|
|
14
|
+
const { execSync } = require('child_process');
|
|
15
|
+
|
|
16
|
+
const API_ENDPOINT = 'https://api.codemax.pro';
|
|
17
|
+
|
|
18
|
+
const IS_WIN = process.platform === 'win32';
|
|
19
|
+
const IS_MAC = process.platform === 'darwin';
|
|
20
|
+
const HOME = process.env.HOME || process.env.USERPROFILE || os.homedir();
|
|
21
|
+
|
|
22
|
+
/* The tiers this endpoint serves. Written out rather than discovered so the desktop model picker
|
|
23
|
+
* is populated even before the app has talked to the endpoint once.
|
|
24
|
+
*
|
|
25
|
+
* `supports1m` adds a second picker entry for that model, labelled as the 1M context window. It is
|
|
26
|
+
* an assertion the app cannot check: claim it on a model the endpoint will not take a 1M request
|
|
27
|
+
* for, and every request made from that entry fails at inference time — so it is set per model
|
|
28
|
+
* against what each one actually advertises, not switched on across the board.
|
|
29
|
+
*
|
|
30
|
+
* Haiku is deliberately absent from that list: it serves a 200K window, and giving it a 1M entry
|
|
31
|
+
* would offer the customer something that cannot work. */
|
|
32
|
+
const MODELS = [
|
|
33
|
+
{ name: 'claude-opus-5', supports1m: true },
|
|
34
|
+
{ name: 'claude-fable-5', supports1m: true },
|
|
35
|
+
{ name: 'claude-sonnet-5', supports1m: true },
|
|
36
|
+
{ name: 'claude-haiku-4-5-20251001' },
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
/* What the agent's own tools may reach from inside the sandbox — a stricter boundary than the
|
|
40
|
+
* machine's firewall, whose default is nothing at all beyond the API endpoint.
|
|
41
|
+
*
|
|
42
|
+
* "*" deliberately. A curated list of the usual developer hosts reads as the careful choice and
|
|
43
|
+
* behaves as the wrong one: the moment somebody pastes a link to a blog post, a vendor's docs or
|
|
44
|
+
* their own staging site, the fetch fails with nothing to explain why. A tool cannot know in
|
|
45
|
+
* advance which host the next question is about. An organisation that wants the sandbox locked
|
|
46
|
+
* down should set its own list — that is a deployment policy decision, not an installer default. */
|
|
47
|
+
const EGRESS_HOSTS = ['*'];
|
|
48
|
+
|
|
49
|
+
/* Variables set on ~/.claude/settings.json. The last three belong together and were established by
|
|
50
|
+
* testing: remove any one and behaviour changes quietly, with nothing erroring — it simply settles
|
|
51
|
+
* on different defaults. Treat them as a set. */
|
|
52
|
+
function cliEnvVars(apiKey) {
|
|
53
|
+
return {
|
|
54
|
+
ANTHROPIC_AUTH_TOKEN: apiKey,
|
|
55
|
+
ANTHROPIC_BASE_URL: API_ENDPOINT,
|
|
56
|
+
CLAUDE_CODE_OAUTH_TOKEN: apiKey,
|
|
57
|
+
CLAUDE_CODE_SUBSCRIPTION_TYPE: 'max',
|
|
58
|
+
CLAUDE_CODE_REMOTE: '1',
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/* Left over from other setups, and actively harmful here: each one pins a model and produces a
|
|
63
|
+
* duplicate entry in the picker. Removed on every run, not just the first. */
|
|
64
|
+
const STALE_CLI_VARS = [
|
|
65
|
+
'ANTHROPIC_MODEL', 'ANTHROPIC_DEFAULT_MODEL', 'ANTHROPIC_REASONING_MODEL',
|
|
66
|
+
'CLAUDE_CODE_SUBAGENT_MODEL', 'ANTHROPIC_SMALL_FAST_MODEL',
|
|
67
|
+
'ANTHROPIC_DEFAULT_SONNET_MODEL', 'ANTHROPIC_DEFAULT_OPUS_MODEL', 'ANTHROPIC_DEFAULT_HAIKU_MODEL',
|
|
68
|
+
];
|
|
69
|
+
|
|
70
|
+
function desktopValues(apiKey) {
|
|
71
|
+
return {
|
|
72
|
+
inferenceProvider: 'gateway',
|
|
73
|
+
inferenceGatewayBaseUrl: API_ENDPOINT,
|
|
74
|
+
inferenceGatewayApiKey: apiKey,
|
|
75
|
+
inferenceCredentialKind: 'static',
|
|
76
|
+
// This endpoint reads the x-api-key header. The key defaults to "bearer", so omitting it
|
|
77
|
+
// sends the credential in a header nothing reads and every request returns 401.
|
|
78
|
+
inferenceGatewayAuthScheme: 'x-api-key',
|
|
79
|
+
// Given explicitly rather than discovered: the picker keeps only model IDs it recognises,
|
|
80
|
+
// so anything unexpected produces an empty picker with no error to explain it. Full IDs
|
|
81
|
+
// also let the app skip a round trip at launch.
|
|
82
|
+
inferenceModels: JSON.stringify(MODELS),
|
|
83
|
+
// Without this the fetch tool asks a third-party host whether each domain is permitted
|
|
84
|
+
// before fetching it — a dependency this setup otherwise never has, which fails closed on
|
|
85
|
+
// a restricted network.
|
|
86
|
+
skipWebFetchPreflight: 'true',
|
|
87
|
+
coworkEgressAllowedHosts: JSON.stringify(EGRESS_HOSTS),
|
|
88
|
+
// Product analytics. Off because leaving it on also widens the sandbox allowlist to carry
|
|
89
|
+
// it. Crash reporting is deliberately NOT touched — disabling that trades away anyone's
|
|
90
|
+
// ability to see failures on this machine.
|
|
91
|
+
disableNonessentialTelemetry: 'true',
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// ── Paths ────────────────────────────────────────────────────────────────────
|
|
96
|
+
|
|
97
|
+
const paths = {
|
|
98
|
+
cliSettings: () => path.join(HOME, '.claude', 'settings.json'),
|
|
99
|
+
claudeJson: () => path.join(HOME, '.claude.json'),
|
|
100
|
+
desktopBase: () => (IS_WIN
|
|
101
|
+
? path.join(process.env.LOCALAPPDATA || path.join(HOME, 'AppData', 'Local'), 'Claude-3p')
|
|
102
|
+
: IS_MAC
|
|
103
|
+
? path.join(HOME, 'Library', 'Application Support', 'Claude-3p')
|
|
104
|
+
: path.join(HOME, '.config', 'Claude-3p')),
|
|
105
|
+
configLibrary: () => path.join(paths.desktopBase(), 'configLibrary'),
|
|
106
|
+
winPolicy: 'HKCU\\SOFTWARE\\Policies\\Claude',
|
|
107
|
+
winMachinePolicy: 'HKLM\\SOFTWARE\\Policies\\Claude',
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
// ── Small helpers ────────────────────────────────────────────────────────────
|
|
111
|
+
|
|
112
|
+
function sh(cmd) {
|
|
113
|
+
try { return execSync(cmd, { encoding: 'utf8', stdio: 'pipe' }).trim(); } catch { return null; }
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function readJson(file) {
|
|
117
|
+
try {
|
|
118
|
+
if (!fs.existsSync(file)) return null;
|
|
119
|
+
const raw = fs.readFileSync(file, 'utf8').trim();
|
|
120
|
+
return raw ? JSON.parse(raw) : {};
|
|
121
|
+
} catch { return null; }
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/* Writes through a temp file in the same directory, then renames. A half-written settings.json is
|
|
125
|
+
* worse than an unchanged one: the app cannot parse it, and the user is left with a broken client
|
|
126
|
+
* and no obvious cause. Rename is atomic on both platforms when source and target share a volume. */
|
|
127
|
+
function writeJson(file, data) {
|
|
128
|
+
const dir = path.dirname(file);
|
|
129
|
+
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
130
|
+
const tmp = path.join(dir, `.${path.basename(file)}.tmp-${process.pid}`);
|
|
131
|
+
fs.writeFileSync(tmp, JSON.stringify(data, null, 2), 'utf8');
|
|
132
|
+
fs.renameSync(tmp, file);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/* Kept next to the original with a fixed name, so a re-run overwrites its own backup rather than
|
|
136
|
+
* littering, and the user can always find the one file to restore. */
|
|
137
|
+
function backup(file) {
|
|
138
|
+
try {
|
|
139
|
+
if (!fs.existsSync(file)) return null;
|
|
140
|
+
const dest = `${file}.codemax-backup`;
|
|
141
|
+
fs.copyFileSync(file, dest);
|
|
142
|
+
return dest;
|
|
143
|
+
} catch { return null; }
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const redact = (s) => (typeof s === 'string' && s.length > 12 ? `${s.slice(0, 10)}…${s.slice(-4)}` : s ? '••••' : '(none)');
|
|
147
|
+
|
|
148
|
+
// ── The endpoint ─────────────────────────────────────────────────────────────
|
|
149
|
+
|
|
150
|
+
/* A real request, not a HEAD or a ping. Whether the key can complete a message is the only
|
|
151
|
+
* question that matters, and the cheap checks all pass in situations where that one fails. */
|
|
152
|
+
async function checkKey(apiKey, timeoutMs = 30000) {
|
|
153
|
+
const body = JSON.stringify({
|
|
154
|
+
model: 'claude-haiku-4-5-20251001',
|
|
155
|
+
max_tokens: 8,
|
|
156
|
+
messages: [{ role: 'user', content: 'hi' }],
|
|
157
|
+
});
|
|
158
|
+
const started = Date.now();
|
|
159
|
+
try {
|
|
160
|
+
const res = await fetch(`${API_ENDPOINT}/v1/messages`, {
|
|
161
|
+
method: 'POST',
|
|
162
|
+
headers: { 'content-type': 'application/json', 'x-api-key': apiKey, 'anthropic-version': '2023-06-01' },
|
|
163
|
+
body,
|
|
164
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
165
|
+
});
|
|
166
|
+
const ms = Date.now() - started;
|
|
167
|
+
if (res.ok) return { ok: true, ms };
|
|
168
|
+
// Rate limiting proves the key is real and accepted; it is not a setup failure.
|
|
169
|
+
if (res.status === 429) return { ok: true, ms, note: 'rate limited right now' };
|
|
170
|
+
if (res.status === 401 || res.status === 403) return { ok: false, ms, reason: 'key rejected' };
|
|
171
|
+
if (res.status === 402) return { ok: false, ms, reason: 'no remaining balance' };
|
|
172
|
+
return { ok: false, ms, reason: `endpoint returned ${res.status}` };
|
|
173
|
+
} catch (e) {
|
|
174
|
+
return { ok: false, ms: Date.now() - started, reason: e.message, network: true };
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// ── Reading current state (doctor) ───────────────────────────────────────────
|
|
179
|
+
|
|
180
|
+
function readCliState() {
|
|
181
|
+
const file = paths.cliSettings();
|
|
182
|
+
const json = readJson(file);
|
|
183
|
+
const env = (json && json.env) || {};
|
|
184
|
+
return {
|
|
185
|
+
file,
|
|
186
|
+
exists: !!json,
|
|
187
|
+
baseUrl: env.ANTHROPIC_BASE_URL || null,
|
|
188
|
+
key: env.ANTHROPIC_AUTH_TOKEN || null,
|
|
189
|
+
defaultModelVars: ['CLAUDE_CODE_OAUTH_TOKEN', 'CLAUDE_CODE_SUBSCRIPTION_TYPE', 'CLAUDE_CODE_REMOTE']
|
|
190
|
+
.filter((k) => env[k]),
|
|
191
|
+
stalePresent: STALE_CLI_VARS.filter((k) => env[k]),
|
|
192
|
+
pinnedModel: json && json.model ? json.model : null,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function readDesktopState() {
|
|
197
|
+
const out = { policy: null, profile: null, machinePolicy: false };
|
|
198
|
+
|
|
199
|
+
if (IS_WIN) {
|
|
200
|
+
const q = sh(`reg query "${paths.winPolicy}"`);
|
|
201
|
+
if (q) {
|
|
202
|
+
const grab = (name) => {
|
|
203
|
+
const m = q.match(new RegExp(`${name}\\s+REG_SZ\\s+([^\\r\\n]*)`));
|
|
204
|
+
return m ? m[1].trim() : null;
|
|
205
|
+
};
|
|
206
|
+
out.policy = {
|
|
207
|
+
provider: grab('inferenceProvider'),
|
|
208
|
+
baseUrl: grab('inferenceGatewayBaseUrl'),
|
|
209
|
+
key: grab('inferenceGatewayApiKey'),
|
|
210
|
+
authScheme: grab('inferenceGatewayAuthScheme'),
|
|
211
|
+
models: grab('inferenceModels'),
|
|
212
|
+
egress: grab('coworkEgressAllowedHosts'),
|
|
213
|
+
skipPreflight: grab('skipWebFetchPreflight'),
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
// A machine policy makes the app ignore the per-user one ENTIRELY, so a correct HKCU write
|
|
217
|
+
// changes nothing and looks like it worked. Worth naming rather than debugging later.
|
|
218
|
+
out.machinePolicy = sh(`reg query "${paths.winMachinePolicy}" /v inferenceProvider`) !== null;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const meta = readJson(path.join(paths.configLibrary(), '_meta.json'));
|
|
222
|
+
if (meta && meta.appliedId) {
|
|
223
|
+
const p = path.join(paths.configLibrary(), `${meta.appliedId}.json`);
|
|
224
|
+
const prof = readJson(p);
|
|
225
|
+
if (prof) out.profile = { file: p, ...prof };
|
|
226
|
+
}
|
|
227
|
+
return out;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/* An environment variable beats the settings file, so a stale one silently sends the CLI somewhere
|
|
231
|
+
* else while the file on disk looks perfect. This is the single most confusing failure in this
|
|
232
|
+
* setup, and it is invisible unless something goes looking for it. */
|
|
233
|
+
function readEnvConflicts() {
|
|
234
|
+
const names = ['ANTHROPIC_BASE_URL', 'ANTHROPIC_API_KEY', 'ANTHROPIC_AUTH_TOKEN', 'ANTHROPIC_MODEL'];
|
|
235
|
+
const found = [];
|
|
236
|
+
for (const n of names) {
|
|
237
|
+
if (process.env[n]) found.push({ name: n, value: n.includes('URL') || n.includes('MODEL') ? process.env[n] : redact(process.env[n]), scope: 'this shell' });
|
|
238
|
+
}
|
|
239
|
+
if (IS_WIN) {
|
|
240
|
+
for (const n of names) {
|
|
241
|
+
const q = sh(`reg query "HKCU\\Environment" /v ${n}`);
|
|
242
|
+
if (q) {
|
|
243
|
+
const m = q.match(new RegExp(`${n}\\s+REG_[A-Z_]+\\s+([^\\r\\n]*)`));
|
|
244
|
+
found.push({ name: n, value: n.includes('URL') || n.includes('MODEL') ? (m ? m[1].trim() : '?') : '••••', scope: 'persisted (Windows)' });
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return found;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/* Three ways to look, because running it is not a reliable test.
|
|
252
|
+
*
|
|
253
|
+
* `claude --version` succeeds in a normal terminal and FAILS through execSync on Windows: Node
|
|
254
|
+
* shells out to cmd.exe, whose PATH does not necessarily include npm's global bin directory. The
|
|
255
|
+
* first version of this reported "not installed" on a machine where the CLI was installed and
|
|
256
|
+
* working — a diagnostic that invents problems is worse than no diagnostic, because the person
|
|
257
|
+
* reading it goes and fixes something that was never broken.
|
|
258
|
+
*
|
|
259
|
+
* So: try running it, then ask the shell where it is, then look where npm puts it. Finding the
|
|
260
|
+
* binary without a version is still "installed". */
|
|
261
|
+
function claudeCliInfo() {
|
|
262
|
+
const v = sh('claude --version');
|
|
263
|
+
if (v) return { installed: true, version: v };
|
|
264
|
+
|
|
265
|
+
const located = sh(IS_WIN ? 'where claude' : 'which claude');
|
|
266
|
+
if (located) return { installed: true, version: null, at: located.split(/\r?\n/)[0].trim() };
|
|
267
|
+
|
|
268
|
+
const root = sh('npm prefix -g');
|
|
269
|
+
if (root) {
|
|
270
|
+
for (const rel of IS_WIN ? ['claude.cmd', 'claude.ps1', 'claude'] : ['bin/claude']) {
|
|
271
|
+
const candidate = path.join(root, rel);
|
|
272
|
+
if (fs.existsSync(candidate)) return { installed: true, version: null, at: candidate };
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return { installed: false, version: null };
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// ── Writing (setup) ──────────────────────────────────────────────────────────
|
|
279
|
+
|
|
280
|
+
function configureCli(apiKey) {
|
|
281
|
+
const file = paths.cliSettings();
|
|
282
|
+
const bak = backup(file);
|
|
283
|
+
const json = readJson(file) || {};
|
|
284
|
+
if (!json.env) json.env = {};
|
|
285
|
+
Object.assign(json.env, cliEnvVars(apiKey));
|
|
286
|
+
for (const k of STALE_CLI_VARS) delete json.env[k];
|
|
287
|
+
// Not the same thing as the env vars: this creates a separate kind of pinned entry.
|
|
288
|
+
delete json.model;
|
|
289
|
+
writeJson(file, json);
|
|
290
|
+
return { file, backup: bak };
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const escReg = (s) => String(s).replace(/\\/g, '\\\\').replace(/"/g, '\\"');
|
|
294
|
+
|
|
295
|
+
/* Built as a .reg file and imported rather than passed to `reg add`. The command-line form loses
|
|
296
|
+
* quotes inside JSON values to cmd's own parsing and stores a truncated value that imports
|
|
297
|
+
* cleanly — which surfaces much later as an empty model picker with nothing to explain it. */
|
|
298
|
+
function writeWinPolicy(values) {
|
|
299
|
+
const lines = [
|
|
300
|
+
'Windows Registry Editor Version 5.00', '',
|
|
301
|
+
`[HKEY_CURRENT_USER\\SOFTWARE\\Policies\\Claude]`,
|
|
302
|
+
...Object.entries(values).map(([k, v]) => `"${k}"="${escReg(v)}"`),
|
|
303
|
+
'',
|
|
304
|
+
];
|
|
305
|
+
const tmp = path.join(os.tmpdir(), `codemax-3p-${process.pid}.reg`);
|
|
306
|
+
// UTF-16LE with a BOM is what reg.exe expects for a v5 file; UTF-8 imports as mojibake.
|
|
307
|
+
fs.writeFileSync(tmp, '' + lines.join('\r\n'), 'utf16le');
|
|
308
|
+
const ok = sh(`reg import "${tmp}"`) !== null;
|
|
309
|
+
try { fs.unlinkSync(tmp); } catch { /* temp */ }
|
|
310
|
+
return ok;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function configureDesktop(apiKey) {
|
|
314
|
+
const values = desktopValues(apiKey);
|
|
315
|
+
const written = [];
|
|
316
|
+
let machinePolicy = false;
|
|
317
|
+
|
|
318
|
+
if (IS_WIN) {
|
|
319
|
+
machinePolicy = sh(`reg query "${paths.winMachinePolicy}" /v inferenceProvider`) !== null;
|
|
320
|
+
if (writeWinPolicy(values)) written.push(paths.winPolicy);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const dir = paths.configLibrary();
|
|
324
|
+
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
325
|
+
const metaPath = path.join(dir, '_meta.json');
|
|
326
|
+
const meta = readJson(metaPath) || {};
|
|
327
|
+
if (!Array.isArray(meta.entries)) meta.entries = [];
|
|
328
|
+
let id = meta.appliedId;
|
|
329
|
+
if (!id || !fs.existsSync(path.join(dir, `${id}.json`))) {
|
|
330
|
+
id = crypto.randomUUID ? crypto.randomUUID() : `codemax-${Date.now()}`;
|
|
331
|
+
meta.appliedId = id;
|
|
332
|
+
if (!meta.entries.some((e) => e && e.id === id)) meta.entries.push({ id, name: 'CodeMax Gateway' });
|
|
333
|
+
}
|
|
334
|
+
const profile = path.join(dir, `${id}.json`);
|
|
335
|
+
// The local profile takes real types; only the OS policy store requires everything as strings.
|
|
336
|
+
writeJson(profile, {
|
|
337
|
+
...values,
|
|
338
|
+
inferenceModels: MODELS,
|
|
339
|
+
coworkEgressAllowedHosts: EGRESS_HOSTS,
|
|
340
|
+
skipWebFetchPreflight: true,
|
|
341
|
+
disableNonessentialTelemetry: true,
|
|
342
|
+
});
|
|
343
|
+
writeJson(metaPath, meta);
|
|
344
|
+
written.push(profile);
|
|
345
|
+
|
|
346
|
+
const dev = path.join(paths.desktopBase(), 'developer_settings.json');
|
|
347
|
+
const devJson = readJson(dev) || {};
|
|
348
|
+
devJson.allowDevTools = true;
|
|
349
|
+
writeJson(dev, devJson);
|
|
350
|
+
|
|
351
|
+
return { written, machinePolicy };
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/* Older versions put an `env` block in claude_desktop_config.json and an MCP server entry in
|
|
355
|
+
* .claude.json. Neither ever selected an inference endpoint — the first configures MCP servers,
|
|
356
|
+
* the second is unrelated — so they sat there doing nothing while looking like the thing that made
|
|
357
|
+
* this work. Cleaned on every run, because the key should not be left lying in a file the app
|
|
358
|
+
* hands to MCP server processes. */
|
|
359
|
+
function cleanLegacy() {
|
|
360
|
+
const removed = [];
|
|
361
|
+
|
|
362
|
+
const dcPath = IS_WIN
|
|
363
|
+
? path.join(process.env.APPDATA || path.join(HOME, 'AppData', 'Roaming'), 'Claude', 'claude_desktop_config.json')
|
|
364
|
+
: IS_MAC
|
|
365
|
+
? path.join(HOME, 'Library', 'Application Support', 'Claude', 'claude_desktop_config.json')
|
|
366
|
+
: path.join(HOME, '.config', 'Claude', 'claude_desktop_config.json');
|
|
367
|
+
const dc = readJson(dcPath);
|
|
368
|
+
if (dc && dc.env) {
|
|
369
|
+
let touched = false;
|
|
370
|
+
for (const k of ['ANTHROPIC_BASE_URL', 'ANTHROPIC_AUTH_TOKEN', 'ANTHROPIC_API_KEY']) {
|
|
371
|
+
if (k in dc.env) { delete dc.env[k]; touched = true; }
|
|
372
|
+
}
|
|
373
|
+
if (touched) {
|
|
374
|
+
if (Object.keys(dc.env).length === 0) delete dc.env;
|
|
375
|
+
writeJson(dcPath, dc);
|
|
376
|
+
removed.push(`${dcPath} (stale env block)`);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
const cj = readJson(paths.claudeJson());
|
|
381
|
+
if (cj && cj.mcpServers && cj.mcpServers.CodeMax) {
|
|
382
|
+
delete cj.mcpServers.CodeMax;
|
|
383
|
+
if (Object.keys(cj.mcpServers).length === 0) delete cj.mcpServers;
|
|
384
|
+
cj.hasCompletedOnboarding = true;
|
|
385
|
+
writeJson(paths.claudeJson(), cj);
|
|
386
|
+
removed.push(`${paths.claudeJson()} (old MCP entry)`);
|
|
387
|
+
} else if (!cj) {
|
|
388
|
+
writeJson(paths.claudeJson(), { hasCompletedOnboarding: true });
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// A persisted variable outranks the settings file, so leaving one behind quietly overrides
|
|
392
|
+
// everything written above.
|
|
393
|
+
if (IS_WIN) {
|
|
394
|
+
for (const v of ['ANTHROPIC_API_KEY', 'ANTHROPIC_AUTH_TOKEN', 'ANTHROPIC_BASE_URL', 'ANTHROPIC_MODEL',
|
|
395
|
+
'ANTHROPIC_SMALL_FAST_MODEL', 'ANTHROPIC_DEFAULT_SONNET_MODEL', 'ANTHROPIC_DEFAULT_OPUS_MODEL',
|
|
396
|
+
'ANTHROPIC_DEFAULT_HAIKU_MODEL', 'CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC']) {
|
|
397
|
+
if (sh(`reg query "HKCU\\Environment" /v ${v}`)) {
|
|
398
|
+
sh(`REG delete "HKCU\\Environment" /v ${v} /f`);
|
|
399
|
+
removed.push(`Windows environment variable ${v}`);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
return removed;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// ── Removing (reset) ─────────────────────────────────────────────────────────
|
|
407
|
+
|
|
408
|
+
/* Removes only what this tool set. Other people's settings in the same files are left exactly as
|
|
409
|
+
* they are — a reset that takes the whole file with it is not a reset, it is data loss. */
|
|
410
|
+
function resetAll() {
|
|
411
|
+
const removed = [];
|
|
412
|
+
|
|
413
|
+
const file = paths.cliSettings();
|
|
414
|
+
const json = readJson(file);
|
|
415
|
+
if (json && json.env) {
|
|
416
|
+
let touched = false;
|
|
417
|
+
for (const k of Object.keys(cliEnvVars('x'))) {
|
|
418
|
+
if (k in json.env) { delete json.env[k]; touched = true; }
|
|
419
|
+
}
|
|
420
|
+
if (touched) {
|
|
421
|
+
if (Object.keys(json.env).length === 0) delete json.env;
|
|
422
|
+
backup(file);
|
|
423
|
+
writeJson(file, json);
|
|
424
|
+
removed.push(`${file} (CodeMax variables only)`);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
if (IS_WIN && sh(`reg query "${paths.winPolicy}"`)) {
|
|
429
|
+
sh(`reg delete "${paths.winPolicy}" /f`);
|
|
430
|
+
removed.push(paths.winPolicy);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
const metaPath = path.join(paths.configLibrary(), '_meta.json');
|
|
434
|
+
const meta = readJson(metaPath);
|
|
435
|
+
if (meta && meta.appliedId) {
|
|
436
|
+
const p = path.join(paths.configLibrary(), `${meta.appliedId}.json`);
|
|
437
|
+
const prof = readJson(p);
|
|
438
|
+
// Only ours. Another profile in the same library belongs to whoever put it there.
|
|
439
|
+
if (prof && prof.inferenceGatewayBaseUrl === API_ENDPOINT) {
|
|
440
|
+
try { fs.unlinkSync(p); removed.push(p); } catch { /* */ }
|
|
441
|
+
delete meta.appliedId;
|
|
442
|
+
meta.entries = (meta.entries || []).filter((e) => !e || e.name !== 'CodeMax Gateway');
|
|
443
|
+
writeJson(metaPath, meta);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
return removed;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
module.exports = {
|
|
450
|
+
API_ENDPOINT, MODELS, EGRESS_HOSTS, IS_WIN, IS_MAC, HOME,
|
|
451
|
+
paths, sh, readJson, writeJson, backup, redact,
|
|
452
|
+
checkKey, readCliState, readDesktopState, readEnvConflicts, claudeCliInfo,
|
|
453
|
+
configureCli, configureDesktop, cleanLegacy, resetAll,
|
|
454
|
+
cliEnvVars, desktopValues, STALE_CLI_VARS,
|
|
455
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codemax-pro",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.3.1",
|
|
4
|
+
"description": "Setup for CodeMax — configures Claude Code CLI, VS Code, and Claude Desktop, with a doctor and reset",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
7
7
|
"codemax-pro": "index.js"
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"files": [
|
|
26
26
|
"index.js",
|
|
27
|
+
"lib.js",
|
|
27
28
|
"README.md"
|
|
28
29
|
]
|
|
29
30
|
}
|