codemax-pro 1.4.1 → 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 -298
- package/lib.js +96 -67
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,85 +1,93 @@
|
|
|
1
|
-
# ⚡ codemax-pro
|
|
2
|
-
|
|
3
|
-
Setup for **CodeMax** (`api.codemax.pro`) — configures **Claude Code CLI**, the **VS Code
|
|
4
|
-
extension**, and the **Claude Desktop app**.
|
|
5
|
-
|
|
6
|
-
```bash
|
|
7
|
-
npx codemax-pro
|
|
8
|
-
```
|
|
9
|
-
|
|
10
|
-
Or pass the key directly:
|
|
11
|
-
|
|
12
|
-
```bash
|
|
13
|
-
npx codemax-pro sk-cp-your-key-here
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
---
|
|
17
|
-
|
|
18
|
-
## Commands
|
|
19
|
-
|
|
20
|
-
| | |
|
|
21
|
-
| --- | --- |
|
|
22
|
-
| `codemax-pro [key]` | Configure everything |
|
|
23
|
-
| `codemax-pro doctor` | Report what is actually configured, and what is fighting it |
|
|
24
|
-
| `codemax-pro reset` | Remove what this tool set, and nothing else |
|
|
25
|
-
|
|
26
|
-
| Flag | |
|
|
27
|
-
| --- | --- |
|
|
28
|
-
| `--yes` | Never prompt |
|
|
29
|
-
| `--only cli` / `--only desktop` | Configure one surface only |
|
|
30
|
-
|
|
31
|
-
The key can also come from `CODEMAX_API_KEY`.
|
|
32
|
-
|
|
33
|
-
---
|
|
34
|
-
|
|
35
|
-
## `doctor`
|
|
36
|
-
|
|
37
|
-
Run this first when something isn't working. It only reads — it changes nothing.
|
|
38
|
-
|
|
39
|
-
```
|
|
40
|
-
Claude Code CLI
|
|
41
|
-
✓ endpoint https://api.codemax.pro
|
|
42
|
-
✓ key sk-cp-a1b2…9f3c
|
|
43
|
-
✓ default model settings present
|
|
44
|
-
✓ claude CLI installed 2.1.81
|
|
45
|
-
|
|
46
|
-
Claude Desktop
|
|
47
|
-
✓
|
|
48
|
-
✓ auth x-api-key
|
|
49
|
-
✓ models 4 configured
|
|
50
|
-
|
|
51
|
-
Conflicts
|
|
52
|
-
✓ no environment variables competing with the settings file
|
|
53
|
-
|
|
54
|
-
Connection
|
|
55
|
-
✓ endpoint reachable, key accepted 412ms
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
It exists because the failures here are quiet ones. Each of these looks identical to "the setup
|
|
59
|
-
didn't work", and none of them produces an error:
|
|
60
|
-
|
|
61
|
-
- an environment variable that outranks the settings file
|
|
62
|
-
- a
|
|
63
|
-
- an app still running with the configuration it read at launch
|
|
64
|
-
- a key that was rotated
|
|
65
|
-
|
|
66
|
-
---
|
|
67
|
-
|
|
68
|
-
> ###
|
|
69
|
-
>
|
|
70
|
-
>
|
|
71
|
-
>
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
---
|
|
82
|
-
|
|
83
|
-
##
|
|
84
|
-
|
|
85
|
-
|
|
1
|
+
# ⚡ codemax-pro
|
|
2
|
+
|
|
3
|
+
Setup for **CodeMax** (`api.codemax.pro`) — configures **Claude Code CLI**, the **VS Code
|
|
4
|
+
extension**, and the **Claude Desktop app**.
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
npx codemax-pro
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
Or pass the key directly:
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npx codemax-pro sk-cp-your-key-here
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Commands
|
|
19
|
+
|
|
20
|
+
| | |
|
|
21
|
+
| --- | --- |
|
|
22
|
+
| `codemax-pro [key]` | Configure everything |
|
|
23
|
+
| `codemax-pro doctor` | Report what is actually configured, and what is fighting it |
|
|
24
|
+
| `codemax-pro reset` | Remove what this tool set, and nothing else |
|
|
25
|
+
|
|
26
|
+
| Flag | |
|
|
27
|
+
| --- | --- |
|
|
28
|
+
| `--yes` | Never prompt |
|
|
29
|
+
| `--only cli` / `--only desktop` | Configure one surface only |
|
|
30
|
+
|
|
31
|
+
The key can also come from `CODEMAX_API_KEY`.
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## `doctor`
|
|
36
|
+
|
|
37
|
+
Run this first when something isn't working. It only reads — it changes nothing.
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
Claude Code CLI
|
|
41
|
+
✓ endpoint https://api.codemax.pro
|
|
42
|
+
✓ key sk-cp-a1b2…9f3c
|
|
43
|
+
✓ default model settings present
|
|
44
|
+
✓ claude CLI installed 2.1.81
|
|
45
|
+
|
|
46
|
+
Claude Desktop
|
|
47
|
+
✓ provider gateway → https://api.codemax.pro
|
|
48
|
+
✓ auth x-api-key
|
|
49
|
+
✓ models 4 configured, 3 at 1M
|
|
50
|
+
|
|
51
|
+
Conflicts
|
|
52
|
+
✓ no environment variables competing with the settings file
|
|
53
|
+
|
|
54
|
+
Connection
|
|
55
|
+
✓ endpoint reachable, key accepted 412ms
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
It exists because the failures here are quiet ones. Each of these looks identical to "the setup
|
|
59
|
+
didn't work", and none of them produces an error:
|
|
60
|
+
|
|
61
|
+
- an environment variable that outranks the settings file
|
|
62
|
+
- a Windows policy that locks Claude Desktop ("Organization-managed") and overrides this setup
|
|
63
|
+
- an app still running with the configuration it read at launch
|
|
64
|
+
- a key that was rotated
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
> ### 🔒 Claude Desktop says "Organization-managed"
|
|
69
|
+
> A Windows policy (`SOFTWARE\Policies\Claude`) is overriding this setup, so every field is locked
|
|
70
|
+
> and new models never appear. If an earlier CodeMax setup left it, open **PowerShell as
|
|
71
|
+
> Administrator**, run `npx codemax-pro@latest` once — it removes that policy — then quit Claude
|
|
72
|
+
> Desktop from the system tray and reopen it. `doctor` tells you which case you are in.
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
> ### ⚠️ Quit Claude Desktop fully, then reopen it
|
|
77
|
+
> It reads its configuration **once, at launch**. Closing the window leaves the process running, so
|
|
78
|
+
> a reopened window keeps the old settings — and it looks exactly like setup failed. Quit from the
|
|
79
|
+
> system tray (Windows) or menu bar (macOS).
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## Safety
|
|
84
|
+
|
|
85
|
+
- Existing settings are backed up beside the original as `*.codemax-backup` before being changed.
|
|
86
|
+
- Files are written atomically — an interrupted run cannot leave a half-written settings file.
|
|
87
|
+
- `reset` removes only the keys this tool set; anything else in those files is left alone.
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## 📖 License
|
|
92
|
+
|
|
93
|
+
MIT © [CodeMax](https://codemax.pro)
|
package/index.js
CHANGED
|
@@ -1,298 +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
|
-
|
|
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
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
p(
|
|
172
|
-
p(` ${c.
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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; });
|
package/lib.js
CHANGED
|
@@ -28,16 +28,23 @@ const HOME = process.env.HOME || process.env.USERPROFILE || os.homedir();
|
|
|
28
28
|
* against what each one actually advertises, not switched on across the board.
|
|
29
29
|
*
|
|
30
30
|
* Haiku is deliberately absent from that list: it serves a 200K window (operator, 2026-10-25: there is no
|
|
31
|
-
* official 1M Haiku), and giving it a 1M entry would offer the customer something that cannot work.
|
|
31
|
+
* official 1M Haiku), and giving it a 1M entry would offer the customer something that cannot work.
|
|
32
|
+
*
|
|
33
|
+
* `prefer1m` ("Only show the 1M option") collapses that pair back to ONE entry, which the app then
|
|
34
|
+
* requests as the 1M variant. Without it every 1M model appeared twice — once at 200K and once at 1M —
|
|
35
|
+
* so the picker showed seven entries for four tiers (operator, 2026-11-04: exactly four, the three 1M
|
|
36
|
+
* and Haiku at 200K). Listing only the `[1m]` spelling does not achieve this: the app folds that back
|
|
37
|
+
* into `supports1m` on the plain id and offers both again. Desktop releases older than the field
|
|
38
|
+
* ignore it and simply keep showing both, so it degrades to the old behaviour rather than breaking. */
|
|
32
39
|
/* 🔴 These must be the ids `GET /v1/models` advertises TODAY, not the ones that merely still work.
|
|
33
40
|
* Every legacy id folds in at the router, so shipping `claude-opus-5` here broke nothing and was
|
|
34
41
|
* therefore invisible — the picker simply showed names the product had stopped using, contradicting
|
|
35
42
|
* the site and the tier. Checked against production before each release:
|
|
36
43
|
* curl -s https://api.codemax.pro/v1/models | jq -r '.data[].id' */
|
|
37
44
|
const MODELS = [
|
|
38
|
-
{ name: 'claude-opus-5-5', supports1m: true },
|
|
39
|
-
{ name: 'claude-fable-5-
|
|
40
|
-
{ name: 'claude-sonnet-5-5', supports1m: true },
|
|
45
|
+
{ name: 'claude-opus-5-5', supports1m: true, prefer1m: true },
|
|
46
|
+
{ name: 'claude-fable-5-2', supports1m: true, prefer1m: true },
|
|
47
|
+
{ name: 'claude-sonnet-5-5', supports1m: true, prefer1m: true },
|
|
41
48
|
{ name: 'claude-haiku-5-5' },
|
|
42
49
|
];
|
|
43
50
|
|
|
@@ -205,29 +212,7 @@ function readCliState() {
|
|
|
205
212
|
}
|
|
206
213
|
|
|
207
214
|
function readDesktopState() {
|
|
208
|
-
const out = {
|
|
209
|
-
|
|
210
|
-
if (IS_WIN) {
|
|
211
|
-
const q = sh(`reg query "${paths.winPolicy}"`);
|
|
212
|
-
if (q) {
|
|
213
|
-
const grab = (name) => {
|
|
214
|
-
const m = q.match(new RegExp(`${name}\\s+REG_SZ\\s+([^\\r\\n]*)`));
|
|
215
|
-
return m ? m[1].trim() : null;
|
|
216
|
-
};
|
|
217
|
-
out.policy = {
|
|
218
|
-
provider: grab('inferenceProvider'),
|
|
219
|
-
baseUrl: grab('inferenceGatewayBaseUrl'),
|
|
220
|
-
key: grab('inferenceGatewayApiKey'),
|
|
221
|
-
authScheme: grab('inferenceGatewayAuthScheme'),
|
|
222
|
-
models: grab('inferenceModels'),
|
|
223
|
-
egress: grab('coworkEgressAllowedHosts'),
|
|
224
|
-
skipPreflight: grab('skipWebFetchPreflight'),
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
// A machine policy makes the app ignore the per-user one ENTIRELY, so a correct HKCU write
|
|
228
|
-
// changes nothing and looks like it worked. Worth naming rather than debugging later.
|
|
229
|
-
out.machinePolicy = sh(`reg query "${paths.winMachinePolicy}" /v inferenceProvider`) !== null;
|
|
230
|
-
}
|
|
215
|
+
const out = { policies: readPolicies(), profile: null };
|
|
231
216
|
|
|
232
217
|
const meta = readJson(path.join(paths.configLibrary(), '_meta.json'));
|
|
233
218
|
if (meta && meta.appliedId) {
|
|
@@ -301,49 +286,86 @@ function configureCli(apiKey) {
|
|
|
301
286
|
return { file, backup: bak };
|
|
302
287
|
}
|
|
303
288
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
/*
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
289
|
+
// ── The Windows policy branch ────────────────────────────────────────────────
|
|
290
|
+
|
|
291
|
+
/* Claude Desktop reads SOFTWARE\Policies\Claude from BOTH hives as its managed tier. Any value there
|
|
292
|
+
* makes the whole configuration "Organization-managed": every field is locked, and the per-user
|
|
293
|
+
* profile this tool writes is ignored.
|
|
294
|
+
*
|
|
295
|
+
* Earlier versions of this tool wrote that branch as well. An ordinary account cannot write there,
|
|
296
|
+
* so for most people the attempt failed harmlessly. Run once from an Administrator terminal, it
|
|
297
|
+
* succeeded, and from then on the app was locked to that run's values: every later run, being an
|
|
298
|
+
* ordinary one, could no longer change them, so a new model list never reached the picker.
|
|
299
|
+
*
|
|
300
|
+
* So this tool no longer writes there. It removes what an earlier run left in the user's branch,
|
|
301
|
+
* and only when the endpoint in it is ours. The machine-wide branch is never touched: this tool never
|
|
302
|
+
* wrote it, so whatever is in it was put there deliberately by someone who manages the computer. */
|
|
303
|
+
|
|
304
|
+
// Every value name any version of this tool has written under that branch.
|
|
305
|
+
const POLICY_VALUES = Object.keys(desktopValues(''));
|
|
306
|
+
|
|
307
|
+
function isOurEndpoint(url) {
|
|
308
|
+
try { return new URL(String(url)).host.toLowerCase() === new URL(API_ENDPOINT).host; } catch { return false; }
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/* `reg query` output: one line per value, " name REG_TYPE data", then each subkey as a full
|
|
312
|
+
* path. The key's own name is printed only when it holds values, so subkeys are recognised by their
|
|
313
|
+
* prefix rather than by position. */
|
|
314
|
+
function parseRegQuery(text, fullKey) {
|
|
315
|
+
const values = {};
|
|
316
|
+
let subkeys = 0;
|
|
317
|
+
const prefix = `${fullKey}\\`.toLowerCase();
|
|
318
|
+
for (const line of String(text || '').split(/\r?\n/)) {
|
|
319
|
+
const m = /^ {4}(.+?) {4}(REG_[A-Z_]+)(?: {4}(.*))?$/.exec(line);
|
|
320
|
+
if (m) values[m[1]] = (m[3] || '').trim();
|
|
321
|
+
else if (line.trim().toLowerCase().startsWith(prefix)) subkeys++;
|
|
327
322
|
}
|
|
328
|
-
|
|
323
|
+
return { values, subkeys };
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
const fullHive = (key) => key.replace(/^HKCU\\/i, 'HKEY_CURRENT_USER\\').replace(/^HKLM\\/i, 'HKEY_LOCAL_MACHINE\\');
|
|
327
|
+
|
|
328
|
+
function readPolicy(key) {
|
|
329
|
+
const q = sh(`reg query "${key}"`);
|
|
330
|
+
if (q === null) return null;
|
|
331
|
+
const { values, subkeys } = parseRegQuery(q, fullHive(key));
|
|
332
|
+
return { key, values, subkeys, ours: isOurEndpoint(values.inferenceGatewayBaseUrl) };
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/* Each branch that would lock the app, with what it points at. An existing but empty key is not
|
|
336
|
+
* listed: with no values in it there is nothing for the app to enforce. */
|
|
337
|
+
function readPolicies() {
|
|
338
|
+
if (!IS_WIN) return [];
|
|
339
|
+
const found = [];
|
|
340
|
+
for (const [scope, key] of [['user', paths.winPolicy], ['machine', paths.winMachinePolicy]]) {
|
|
341
|
+
const pol = readPolicy(key);
|
|
342
|
+
if (pol && Object.keys(pol.values).length) found.push({ scope, ...pol });
|
|
343
|
+
}
|
|
344
|
+
return found;
|
|
345
|
+
}
|
|
329
346
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
347
|
+
/* Only for a branch whose endpoint is ours. Deletes the values this tool writes, then the key if
|
|
348
|
+
* that left it empty. It needs an administrator, exactly like the write it undoes. Success is judged
|
|
349
|
+
* by reading the branch back: what matters is whether the app will still find anything to enforce. */
|
|
350
|
+
function removeOwnPolicy(pol) {
|
|
351
|
+
for (const name of POLICY_VALUES) {
|
|
352
|
+
if (name in pol.values) sh(`reg delete "${pol.key}" /v ${name} /f`);
|
|
353
|
+
}
|
|
354
|
+
let after = readPolicy(pol.key);
|
|
355
|
+
if (after && !Object.keys(after.values).length && !after.subkeys) {
|
|
356
|
+
sh(`reg delete "${pol.key}" /f`);
|
|
357
|
+
after = readPolicy(pol.key);
|
|
358
|
+
}
|
|
359
|
+
const left = after ? Object.keys(after.values) : [];
|
|
360
|
+
return { ...pol, attempted: true, removed: left.length === 0, left };
|
|
333
361
|
}
|
|
334
362
|
|
|
335
363
|
function configureDesktop(apiKey) {
|
|
336
364
|
const values = desktopValues(apiKey);
|
|
337
365
|
const written = [];
|
|
338
|
-
let machinePolicy = false;
|
|
339
|
-
let policyError = null;
|
|
340
366
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
const r = writeWinPolicy(values);
|
|
344
|
-
if (r.ok) written.push(paths.winPolicy);
|
|
345
|
-
else policyError = r.error;
|
|
346
|
-
}
|
|
367
|
+
// A branch left by an earlier Administrator run would override everything written below.
|
|
368
|
+
const policies = readPolicies().map((pol) => (pol.scope === 'user' && pol.ours ? removeOwnPolicy(pol) : pol));
|
|
347
369
|
|
|
348
370
|
const dir = paths.configLibrary();
|
|
349
371
|
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
@@ -373,7 +395,7 @@ function configureDesktop(apiKey) {
|
|
|
373
395
|
devJson.allowDevTools = true;
|
|
374
396
|
writeJson(dev, devJson);
|
|
375
397
|
|
|
376
|
-
return { written,
|
|
398
|
+
return { written, policies };
|
|
377
399
|
}
|
|
378
400
|
|
|
379
401
|
/* Older versions put an `env` block in claude_desktop_config.json and an MCP server entry in
|
|
@@ -450,9 +472,14 @@ function resetAll() {
|
|
|
450
472
|
}
|
|
451
473
|
}
|
|
452
474
|
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
475
|
+
// Only the user's branch, and only when it points here; the same rule setup follows.
|
|
476
|
+
const policies = [];
|
|
477
|
+
for (const pol of readPolicies()) {
|
|
478
|
+
if (pol.scope === 'user' && pol.ours) {
|
|
479
|
+
const r = removeOwnPolicy(pol);
|
|
480
|
+
if (r.removed) removed.push(`${pol.key} (the policy that locked Claude Desktop)`);
|
|
481
|
+
else policies.push(r);
|
|
482
|
+
} else policies.push(pol);
|
|
456
483
|
}
|
|
457
484
|
|
|
458
485
|
const metaPath = path.join(paths.configLibrary(), '_meta.json');
|
|
@@ -468,7 +495,8 @@ function resetAll() {
|
|
|
468
495
|
writeJson(metaPath, meta);
|
|
469
496
|
}
|
|
470
497
|
}
|
|
471
|
-
|
|
498
|
+
// `policies`: what is still enforced afterwards, so reset can say why the app may stay locked.
|
|
499
|
+
return { removed, policies };
|
|
472
500
|
}
|
|
473
501
|
|
|
474
502
|
module.exports = {
|
|
@@ -476,5 +504,6 @@ module.exports = {
|
|
|
476
504
|
paths, sh, readJson, writeJson, backup, redact,
|
|
477
505
|
checkKey, readCliState, readDesktopState, readEnvConflicts, claudeCliInfo,
|
|
478
506
|
configureCli, configureDesktop, cleanLegacy, resetAll,
|
|
507
|
+
readPolicies, removeOwnPolicy, parseRegQuery, isOurEndpoint, POLICY_VALUES,
|
|
479
508
|
cliEnvVars, desktopValues, STALE_CLI_VARS,
|
|
480
509
|
};
|