codemax-pro 1.3.1 → 1.3.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.
Files changed (3) hide show
  1. package/index.js +38 -17
  2. package/lib.js +26 -6
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -73,29 +73,42 @@ async function doctor() {
73
73
  if (!info.version && info.at) dim(info.at);
74
74
  } else warn('claude CLI not found — run: npm install -g @anthropic-ai/claude-code');
75
75
 
76
+ /* Two supported places, for two different situations, and only one of them is the ordinary
77
+ * user's. The local profile is the per-user path; the registry branch under SOFTWARE\Policies
78
+ * is the managed one and a normal account cannot write there at all — reg import answers
79
+ * "Error accessing the registry" — which is by design, since the point of that branch is that
80
+ * only whoever administers the machine controls it.
81
+ *
82
+ * So the profile is what decides whether this is configured. An absent policy is reported as
83
+ * information, never as a fault: calling it a failure sent someone looking for a problem on a
84
+ * machine that was set up correctly. */
76
85
  step('Claude Desktop');
77
86
  const d = L.readDesktopState();
87
+ const prof = d.profile;
88
+ if (prof && prof.inferenceProvider === 'gateway' && prof.inferenceGatewayBaseUrl === L.API_ENDPOINT) {
89
+ ok(`provider gateway → ${prof.inferenceGatewayBaseUrl}`);
90
+ const scheme = prof.inferenceGatewayAuthScheme;
91
+ (scheme === 'x-api-key' ? ok : bad)(`auth ${scheme || '(default — expect 401)'}`);
92
+ if (scheme !== 'x-api-key') problems++;
93
+ const n = Array.isArray(prof.inferenceModels) ? prof.inferenceModels.length : 0;
94
+ const oneM = Array.isArray(prof.inferenceModels) ? prof.inferenceModels.filter((m) => m && m.supports1m).length : 0;
95
+ (n ? ok : bad)(`models ${n} configured${oneM ? `, ${oneM} with a 1M option` : ''}`);
96
+ if (!n) problems++;
97
+ ok(`fetch egress ${JSON.stringify(prof.coworkEgressAllowedHosts || [])}, preflight ${prof.skipWebFetchPreflight ? 'off' : 'ON'}`);
98
+ dim(prof.file);
99
+ } else {
100
+ bad('not configured — run `codemax-pro` to set it up');
101
+ problems++;
102
+ }
103
+
78
104
  if (L.IS_WIN) {
79
- if (d.policy && d.policy.provider === 'gateway' && d.policy.baseUrl === L.API_ENDPOINT) {
80
- ok(`policy gateway → ${d.policy.baseUrl}`);
81
- ok(`auth ${d.policy.authScheme || '(default — expect 401)'}`);
82
- if (d.policy.authScheme !== 'x-api-key') problems++;
83
- let n = 0; try { n = JSON.parse(d.policy.models || '[]').length; } catch { /* */ }
84
- (n ? ok : bad)(`models ${n} configured`);
85
- if (!n) problems++;
86
- ok(`fetch egress ${d.policy.egress || '(none)'}, preflight ${d.policy.skipPreflight === 'true' ? 'off' : 'ON — needs an external host'}`);
87
- } else {
88
- bad('policy not set');
89
- problems++;
90
- }
105
+ if (d.policy) dim('a managed policy is also set for this user');
91
106
  if (d.machinePolicy) {
92
107
  bad('a machine-wide policy exists and OVERRIDES everything above');
93
108
  dim(`${L.paths.winMachinePolicy} — whoever manages this device must set it there instead`);
94
109
  problems++;
95
110
  }
96
111
  }
97
- if (d.profile) { ok(`local profile written`); dim(d.profile.file); }
98
- else { warn('no local profile — the app may not show these settings in its own UI'); }
99
112
 
100
113
  step('Conflicts');
101
114
  const conflicts = L.readEnvConflicts();
@@ -184,8 +197,12 @@ async function setup(opts) {
184
197
  if (want('desktop')) {
185
198
  step('Claude Desktop');
186
199
  const r = L.configureDesktop(key);
187
- if (!r.written.length) warn('nothing could be written — is the app installed?');
188
200
  for (const w of r.written) ok(w);
201
+ /* The managed policy branch is attempted and expected to fail for an ordinary account —
202
+ * SOFTWARE\Policies belongs to whoever administers the machine. That is not a problem to
203
+ * report; the per-user profile above is the supported path here and is enough on its own. */
204
+ if (r.policyError) dim('managed policy not written (needs an administrator — not required here)');
205
+ if (!r.written.length) warn('nothing could be written — is the app installed?');
189
206
  if (r.machinePolicy) {
190
207
  warn('a machine-wide policy exists and overrides what was just written');
191
208
  dim(`${L.paths.winMachinePolicy} — ask whoever manages this device to set it there`);
@@ -272,6 +289,10 @@ async function main() {
272
289
  return setup(opts);
273
290
  }
274
291
 
292
+ /* Set the exit code and let Node wind down on its own, rather than calling process.exit().
293
+ * Forcing an exit while a socket from the connection check is still tearing down is what produced
294
+ * the libuv assertion above; setting the code lets the loop drain first and reports the same
295
+ * result to the shell. */
275
296
  main()
276
- .then((code) => process.exit(code || 0))
277
- .catch((e) => { p(''); bad(e.message); p(''); process.exit(1); });
297
+ .then((code) => { process.exitCode = code || 0; })
298
+ .catch((e) => { p(''); bad(e.message); p(''); process.exitCode = 1; });
package/lib.js CHANGED
@@ -164,6 +164,12 @@ async function checkKey(apiKey, timeoutMs = 30000) {
164
164
  signal: AbortSignal.timeout(timeoutMs),
165
165
  });
166
166
  const ms = Date.now() - started;
167
+ /* Drain the body even though nothing here reads it. An unread response keeps its
168
+ * connection in fetch's pool, the pool keeps a libuv handle alive, and exiting while that
169
+ * handle is mid-teardown aborts the process with
170
+ * `Assertion failed: !(handle->flags & UV_HANDLE_CLOSING)`. Seen on Windows: the whole
171
+ * report printed correctly and then the process crashed, which reads as a broken tool. */
172
+ try { await res.arrayBuffer(); } catch { /* body already gone; nothing to release */ }
167
173
  if (res.ok) return { ok: true, ms };
168
174
  // Rate limiting proves the key is real and accepted; it is not a setup failure.
169
175
  if (res.status === 429) return { ok: true, ms, note: 'rate limited right now' };
@@ -303,21 +309,35 @@ function writeWinPolicy(values) {
303
309
  '',
304
310
  ];
305
311
  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;
312
+ let error = null;
313
+ try {
314
+ // UTF-16LE with a BOM is what reg.exe expects for a v5 file; UTF-8 imports as mojibake.
315
+ fs.writeFileSync(tmp, '' + lines.join('\r\n'), 'utf16le');
316
+ execSync(`reg import "${tmp}"`, { encoding: 'utf8', stdio: 'pipe' });
317
+ } catch (e) {
318
+ /* Captured rather than swallowed. The first version returned a bare false here, so a failed
319
+ * import was indistinguishable from "not attempted" — and what the user saw afterwards was
320
+ * a report saying "policy not set" with nothing anywhere explaining why. */
321
+ error = String((e && (e.stderr || e.message)) || 'unknown').trim().split(/\r?\n/)[0];
322
+ }
309
323
  try { fs.unlinkSync(tmp); } catch { /* temp */ }
310
- return ok;
324
+
325
+ // Trust the registry, not the exit code: confirm the value is actually readable back.
326
+ const verified = sh(`reg query "${paths.winPolicy}" /v inferenceProvider`) !== null;
327
+ return { ok: verified, error: verified ? null : (error || 'reg import reported success but the value is not readable back') };
311
328
  }
312
329
 
313
330
  function configureDesktop(apiKey) {
314
331
  const values = desktopValues(apiKey);
315
332
  const written = [];
316
333
  let machinePolicy = false;
334
+ let policyError = null;
317
335
 
318
336
  if (IS_WIN) {
319
337
  machinePolicy = sh(`reg query "${paths.winMachinePolicy}" /v inferenceProvider`) !== null;
320
- if (writeWinPolicy(values)) written.push(paths.winPolicy);
338
+ const r = writeWinPolicy(values);
339
+ if (r.ok) written.push(paths.winPolicy);
340
+ else policyError = r.error;
321
341
  }
322
342
 
323
343
  const dir = paths.configLibrary();
@@ -348,7 +368,7 @@ function configureDesktop(apiKey) {
348
368
  devJson.allowDevTools = true;
349
369
  writeJson(dev, devJson);
350
370
 
351
- return { written, machinePolicy };
371
+ return { written, machinePolicy, policyError };
352
372
  }
353
373
 
354
374
  /* Older versions put an `env` block in claude_desktop_config.json and an MCP server entry in
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codemax-pro",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
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": {