codemax-pro 1.0.0

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/README.md +42 -0
  2. package/index.js +314 -0
  3. package/package.json +29 -0
package/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # ⚡ codemax-pro
2
+
3
+ The Official 1-Command Setup Tool for **CodeMax** (`api.codemax.pro`).
4
+
5
+ Automatically configures **Claude Code CLI**, **VS Code Extension**, and **Claude Desktop App** with high-speed Anthropic-compatible endpoints in under 5 seconds.
6
+
7
+ ## 🚀 Quick Start
8
+
9
+ Run this single command in your terminal:
10
+
11
+ ```bash
12
+ npx codemax-pro
13
+ ```
14
+
15
+ Or pass your API key directly:
16
+
17
+ ```bash
18
+ npx codemax-pro sk-cp-your-key-here
19
+ ```
20
+
21
+ ---
22
+
23
+ ## 🛠️ What it Configures:
24
+
25
+ 1. **Validates your CodeMax API key** against `api.codemax.pro`
26
+ 2. **Configures Claude Code CLI & VS Code** (`~/.claude/settings.json`)
27
+ 3. **Configures Claude Desktop App** (`claude_desktop_config.json`)
28
+ 4. **Installs Claude Code CLI globally** if missing (`@anthropic-ai/claude-code`)
29
+ 5. **Auto-bypasses onboarding** (`~/.claude.json`)
30
+
31
+ ---
32
+
33
+ ## 🌐 Supported Models:
34
+ - `claude-sonnet-5` (Fastest flagship general intelligence)
35
+ - `claude-opus-5` (Extreme architectural & complex coding)
36
+ - `claude-haiku-4.5` (Ultra-fast turnaround)
37
+ - `claude-fable-5` (Extended reasoning & deep problem solving)
38
+
39
+ ---
40
+
41
+ ## 📖 License
42
+ MIT © [CodeMax](https://codemax.pro)
package/index.js ADDED
@@ -0,0 +1,314 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+ const { execSync } = require("child_process");
6
+ const readline = require("readline");
7
+
8
+ const API_ENDPOINT = "https://api.codemax.pro";
9
+
10
+ // ── Colors ──
11
+ const c = {
12
+ reset: "\x1b[0m",
13
+ bold: "\x1b[1m",
14
+ dim: "\x1b[2m",
15
+ cyan: "\x1b[36m",
16
+ green: "\x1b[32m",
17
+ yellow: "\x1b[33m",
18
+ red: "\x1b[31m",
19
+ gray: "\x1b[90m",
20
+ white: "\x1b[97m",
21
+ };
22
+
23
+ const log = (msg) => console.log(msg);
24
+ const ok = (msg) => log(` ${c.green}✓ ${msg}${c.reset}`);
25
+ const warn = (msg) => log(` ${c.yellow}⚠ ${msg}${c.reset}`);
26
+ const fail = (msg) => log(` ${c.red}✗ ${msg}${c.reset}`);
27
+ const info = (msg) => log(` ${c.cyan}${msg}${c.reset}`);
28
+ const gray = (msg) => log(` ${c.gray}${msg}${c.reset}`);
29
+
30
+ function ask(question) {
31
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
32
+ return new Promise((resolve) => {
33
+ rl.question(question, (answer) => {
34
+ rl.close();
35
+ resolve(answer.trim());
36
+ });
37
+ });
38
+ }
39
+
40
+ function readJson(filePath) {
41
+ try {
42
+ if (fs.existsSync(filePath)) {
43
+ const raw = fs.readFileSync(filePath, "utf8").trim();
44
+ if (!raw) return {};
45
+ return JSON.parse(raw);
46
+ }
47
+ } catch { }
48
+ return {};
49
+ }
50
+
51
+ function writeJson(filePath, data) {
52
+ const dir = path.dirname(filePath);
53
+ if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
54
+ fs.writeFileSync(filePath, JSON.stringify(data, null, 2), "utf8");
55
+ }
56
+
57
+ function run(cmd) {
58
+ try {
59
+ return execSync(cmd, { encoding: "utf8", stdio: "pipe" }).trim();
60
+ } catch {
61
+ return null;
62
+ }
63
+ }
64
+
65
+ function which(cmd) {
66
+ try {
67
+ const r = execSync(process.platform === "win32" ? `where ${cmd}` : `which ${cmd}`, {
68
+ encoding: "utf8",
69
+ stdio: "pipe",
70
+ }).trim();
71
+ return r ? true : false;
72
+ } catch {
73
+ return false;
74
+ }
75
+ }
76
+
77
+ async function validateKey(apiKey) {
78
+ const body = JSON.stringify({
79
+ model: "claude-haiku-4.5",
80
+ max_tokens: 10,
81
+ messages: [{ role: "user", content: "Hi" }],
82
+ });
83
+
84
+ try {
85
+ const res = await fetch(`${API_ENDPOINT}/v1/messages`, {
86
+ method: "POST",
87
+ headers: {
88
+ "Content-Type": "application/json",
89
+ "x-api-key": apiKey,
90
+ "anthropic-version": "2023-06-01",
91
+ },
92
+ body,
93
+ signal: AbortSignal.timeout(30000),
94
+ });
95
+
96
+ if (res.ok) return { valid: true };
97
+ if (res.status === 429) return { valid: true, rateLimit: true };
98
+ if (res.status === 401 || res.status === 403) return { valid: false, reason: "Invalid API key" };
99
+ if (res.status === 402) return { valid: false, reason: "No remaining balance" };
100
+ return { valid: false, reason: `Server returned ${res.status}` };
101
+ } catch (e) {
102
+ return { valid: false, reason: e.message, network: true };
103
+ }
104
+ }
105
+
106
+ async function main() {
107
+ log("");
108
+ log(` ${c.cyan}╔══════════════════════════════════════════╗${c.reset}`);
109
+ log(` ${c.cyan}║ ${c.bold}CodeMax Setup${c.reset}${c.cyan} ║${c.reset}`);
110
+ log(` ${c.cyan}╚══════════════════════════════════════════╝${c.reset}`);
111
+ log("");
112
+
113
+ const home = process.env.HOME || process.env.USERPROFILE;
114
+ if (!home) {
115
+ fail("Cannot determine home directory");
116
+ process.exit(1);
117
+ }
118
+
119
+ // ── Get API Key ──
120
+ let apiKey = process.argv[2] || "";
121
+ if (!apiKey) {
122
+ log(` ${c.white}Enter your CodeMax API key${c.reset}`);
123
+ gray("Get it from your admin or codemax.pro");
124
+ log("");
125
+ apiKey = await ask(` ${c.white}API Key: ${c.reset}`);
126
+ log("");
127
+ }
128
+
129
+ if (!apiKey || apiKey.length < 5) {
130
+ fail("No valid API key provided. Exiting.");
131
+ process.exit(1);
132
+ }
133
+
134
+ // ── [1/5] Validate API Key ──
135
+ info("[1/5] Validating API key...");
136
+ const result = await validateKey(apiKey);
137
+
138
+ if (result.valid) {
139
+ if (result.rateLimit) {
140
+ warn("API key valid but rate-limited. Continuing setup...");
141
+ } else {
142
+ ok("API key is valid!");
143
+ ok("Connected to CodeMax");
144
+ }
145
+ } else if (result.network) {
146
+ warn(`Could not reach server: ${result.reason}`);
147
+ const cont = await ask(` ${c.yellow}Continue anyway? (y/n): ${c.reset}`);
148
+ if (cont.toLowerCase() !== "y") process.exit(1);
149
+ } else {
150
+ fail(result.reason);
151
+ gray("Make sure you're using a valid CodeMax API key (sk-cp-...)");
152
+ process.exit(1);
153
+ }
154
+ log("");
155
+
156
+ // ── [2/5] Check Node.js ──
157
+ info("[2/5] Checking Node.js...");
158
+ const nodeVer = run("node --version");
159
+ if (nodeVer) {
160
+ ok(`Node.js ${nodeVer} found`);
161
+ } else {
162
+ fail("Node.js not found. Install from https://nodejs.org");
163
+ process.exit(1);
164
+ }
165
+ log("");
166
+
167
+ // ── [3/5] Configure Claude Code CLI & VS Code settings ──
168
+ info("[3/5] Configuring Claude Code & VS Code settings...");
169
+ const settingsPath = path.join(home, ".claude", "settings.json");
170
+ try {
171
+ const settings = readJson(settingsPath);
172
+ if (!settings.env) settings.env = {};
173
+
174
+ Object.assign(settings.env, {
175
+ ANTHROPIC_AUTH_TOKEN: apiKey,
176
+ ANTHROPIC_BASE_URL: API_ENDPOINT,
177
+ CLAUDE_CODE_OAUTH_TOKEN: apiKey,
178
+ CLAUDE_CODE_SUBSCRIPTION_TYPE: "max",
179
+ CLAUDE_CODE_REMOTE: "1",
180
+ });
181
+
182
+ // Remove stale vars from previous installs
183
+ const removeVars = [
184
+ "ANTHROPIC_MODEL", "CLAUDE_CODE_SUBAGENT_MODEL", "ANTHROPIC_DEFAULT_MODEL",
185
+ "ANTHROPIC_REASONING_MODEL",
186
+ "ANTHROPIC_DEFAULT_SONNET_MODEL", "ANTHROPIC_DEFAULT_OPUS_MODEL",
187
+ "ANTHROPIC_DEFAULT_HAIKU_MODEL",
188
+ ];
189
+ for (const v of removeVars) delete settings.env[v];
190
+ delete settings.model;
191
+
192
+ writeJson(settingsPath, settings);
193
+ ok(settingsPath);
194
+ } catch (e) {
195
+ fail(`Failed: ${e.message}`);
196
+ }
197
+ log("");
198
+
199
+ // ── [4/5] Configure Claude Desktop App ──
200
+ info("[4/5] Configuring Claude Desktop App...");
201
+ const isWin = process.platform === "win32";
202
+ const isMac = process.platform === "darwin";
203
+ const desktopConfigPath = isWin
204
+ ? path.join(process.env.APPDATA || path.join(home, "AppData", "Roaming"), "Claude", "claude_desktop_config.json")
205
+ : isMac
206
+ ? path.join(home, "Library", "Application Support", "Claude", "claude_desktop_config.json")
207
+ : path.join(home, ".config", "Claude", "claude_desktop_config.json");
208
+
209
+ try {
210
+ const desktopConfig = readJson(desktopConfigPath);
211
+ if (!desktopConfig.env) desktopConfig.env = {};
212
+ Object.assign(desktopConfig.env, {
213
+ ANTHROPIC_BASE_URL: API_ENDPOINT,
214
+ ANTHROPIC_AUTH_TOKEN: apiKey,
215
+ ANTHROPIC_API_KEY: apiKey,
216
+ });
217
+ writeJson(desktopConfigPath, desktopConfig);
218
+ ok(`Claude Desktop configured (${desktopConfigPath})`);
219
+ } catch (e) {
220
+ warn(`Claude Desktop config note: ${e.message}`);
221
+ }
222
+ log("");
223
+
224
+ // ── Clean up any stale MCP config from prior installs ──
225
+ const claudeJsonPath = path.join(home, ".claude.json");
226
+ try {
227
+ const claudeJson = readJson(claudeJsonPath);
228
+ let mutated = false;
229
+ if (claudeJson.mcpServers && claudeJson.mcpServers.CodeMax) {
230
+ delete claudeJson.mcpServers.CodeMax;
231
+ mutated = true;
232
+ }
233
+ if (mutated) {
234
+ if (claudeJson.mcpServers && Object.keys(claudeJson.mcpServers).length === 0) {
235
+ delete claudeJson.mcpServers;
236
+ }
237
+ claudeJson.hasCompletedOnboarding = true;
238
+ writeJson(claudeJsonPath, claudeJson);
239
+ } else if (!fs.existsSync(claudeJsonPath)) {
240
+ writeJson(claudeJsonPath, { hasCompletedOnboarding: true });
241
+ }
242
+ } catch { /* non-critical */ }
243
+
244
+ // ── Clear stale env vars (Windows only) ──
245
+ if (process.platform === "win32") {
246
+ const staleVars = [
247
+ "ANTHROPIC_API_KEY", "ANTHROPIC_AUTH_TOKEN", "ANTHROPIC_BASE_URL",
248
+ "ANTHROPIC_MODEL", "ANTHROPIC_SMALL_FAST_MODEL",
249
+ "ANTHROPIC_DEFAULT_SONNET_MODEL", "ANTHROPIC_DEFAULT_OPUS_MODEL",
250
+ "ANTHROPIC_DEFAULT_HAIKU_MODEL", "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC",
251
+ ];
252
+ for (const v of staleVars) {
253
+ run(`REG delete "HKCU\\Environment" /v ${v} /f`);
254
+ }
255
+ }
256
+
257
+ // ── [5/5] Install Claude Code CLI ──
258
+ info("[5/5] Checking Claude Code CLI...");
259
+ if (which("claude")) {
260
+ ok("Claude Code CLI already installed");
261
+ } else {
262
+ info("Installing Claude Code CLI...");
263
+ const cliResult = run("npm install -g @anthropic-ai/claude-code");
264
+ if (cliResult !== null) {
265
+ ok("Claude Code CLI installed!");
266
+ } else {
267
+ warn("Auto-install failed. Run: npm install -g @anthropic-ai/claude-code");
268
+ }
269
+ }
270
+
271
+ // ── Done ──
272
+ log("");
273
+ log(` ${c.green}╔══════════════════════════════════════════╗${c.reset}`);
274
+ log(` ${c.green}║ ${c.bold}✓ Setup complete!${c.reset}${c.green} ║${c.reset}`);
275
+ log(` ${c.green}╚══════════════════════════════════════════╝${c.reset}`);
276
+ log("");
277
+ log(` ${c.white}What was configured:${c.reset}`);
278
+ gray(` • API key validated ✓`);
279
+ gray(` • Claude Code CLI & VS Code (~/.claude/settings.json)`);
280
+ gray(` • Claude Desktop App`);
281
+ gray(` • Claude Code CLI environment`);
282
+ log("");
283
+ log(` ${c.gray}╭───────────────────────────────────────╮${c.reset}`);
284
+ log(` ${c.gray}│ Base URL: api.codemax.pro │${c.reset}`);
285
+ log(` ${c.gray}│ Key: ${apiKey.substring(0, 8)}... │${c.reset}`);
286
+ log(` ${c.gray}╰───────────────────────────────────────╯${c.reset}`);
287
+ log("");
288
+ gray("Restart Claude Code / VS Code / Claude Desktop to apply.");
289
+ gray("Re-run anytime to update your key.");
290
+ log("");
291
+
292
+ // Ask to launch
293
+ if (which("claude")) {
294
+ const launch = await ask(` ${c.white}Launch Claude Code now? (y/n): ${c.reset}`);
295
+ if (launch.toLowerCase() === "y" || launch === "") {
296
+ log("");
297
+ info("🚀 Launching Claude Code...");
298
+ log(` ${c.gray}════════════════════════════════════${c.reset}`);
299
+ log("");
300
+ try {
301
+ execSync("claude", { stdio: "inherit" });
302
+ } catch { }
303
+ } else {
304
+ log("");
305
+ log(` ${c.white}To start later, open any terminal and type: claude${c.reset}`);
306
+ log("");
307
+ }
308
+ }
309
+ }
310
+
311
+ main().catch((e) => {
312
+ fail(`Unexpected error: ${e.message}`);
313
+ process.exit(1);
314
+ });
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "codemax-pro",
3
+ "version": "1.0.0",
4
+ "description": "One-command setup for CodeMax — configures Claude Code CLI, VS Code extension, and Claude Desktop automatically",
5
+ "main": "index.js",
6
+ "bin": {
7
+ "codemax-pro": "index.js"
8
+ },
9
+ "keywords": [
10
+ "codemax",
11
+ "codemax-pro",
12
+ "claude",
13
+ "claude-code",
14
+ "claude-desktop",
15
+ "setup",
16
+ "anthropic",
17
+ "ai",
18
+ "coding-assistant"
19
+ ],
20
+ "author": "CodeMax <support@codemax.pro>",
21
+ "license": "MIT",
22
+ "engines": {
23
+ "node": ">=18"
24
+ },
25
+ "files": [
26
+ "index.js",
27
+ "README.md"
28
+ ]
29
+ }