codegpt-ai 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.
package/bin/ai.js ADDED
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env node
2
+ const { spawn } = require("child_process");
3
+ const path = require("path");
4
+ const fs = require("fs");
5
+
6
+ // Find Python
7
+ const pythonCmds = process.platform === "win32"
8
+ ? ["python", "python3", "py"]
9
+ : ["python3", "python"];
10
+
11
+ function findPython() {
12
+ for (const cmd of pythonCmds) {
13
+ try {
14
+ require("child_process").execSync(`${cmd} --version`, { stdio: "pipe" });
15
+ return cmd;
16
+ } catch {}
17
+ }
18
+ return null;
19
+ }
20
+
21
+ const python = findPython();
22
+ if (!python) {
23
+ console.error("Python not found. Install from https://python.org");
24
+ process.exit(1);
25
+ }
26
+
27
+ // Find chat.py — check npm package dir first, then common locations
28
+ const locations = [
29
+ path.join(__dirname, "..", "chat.py"),
30
+ path.join(process.env.HOME || process.env.USERPROFILE, "codegpt", "chat.py"),
31
+ path.join(process.env.HOME || process.env.USERPROFILE, ".codegpt", "src", "chat.py"),
32
+ ];
33
+
34
+ let chatPy = null;
35
+ for (const loc of locations) {
36
+ if (fs.existsSync(loc)) {
37
+ chatPy = loc;
38
+ break;
39
+ }
40
+ }
41
+
42
+ if (!chatPy) {
43
+ console.error("CodeGPT not found. Run: codegpt-setup");
44
+ process.exit(1);
45
+ }
46
+
47
+ // Pass all args through to Python
48
+ const args = [chatPy, ...process.argv.slice(2)];
49
+ const child = spawn(python, args, {
50
+ stdio: "inherit",
51
+ cwd: path.dirname(chatPy),
52
+ env: { ...process.env, PYTHONUTF8: "1" },
53
+ });
54
+
55
+ child.on("exit", (code) => process.exit(code || 0));
package/bin/setup.js ADDED
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env node
2
+ // Post-install: ensure Python deps are installed
3
+ const { execSync } = require("child_process");
4
+
5
+ const pythonCmds = process.platform === "win32"
6
+ ? ["python", "python3", "py"]
7
+ : ["python3", "python"];
8
+
9
+ function findPython() {
10
+ for (const cmd of pythonCmds) {
11
+ try {
12
+ execSync(`${cmd} --version`, { stdio: "pipe" });
13
+ return cmd;
14
+ } catch {}
15
+ }
16
+ return null;
17
+ }
18
+
19
+ const python = findPython();
20
+
21
+ if (!python) {
22
+ console.log("\n CodeGPT installed but Python not found.");
23
+ console.log(" Install Python from https://python.org");
24
+ console.log(" Then run: pip install requests rich prompt-toolkit\n");
25
+ process.exit(0);
26
+ }
27
+
28
+ // Install Python deps
29
+ console.log(" Installing Python dependencies...");
30
+ try {
31
+ execSync(`${python} -m pip install requests rich prompt-toolkit --quiet`, {
32
+ stdio: "inherit",
33
+ });
34
+ console.log(" Python dependencies installed.");
35
+ } catch {
36
+ console.log(" Warning: Could not install Python deps.");
37
+ console.log(" Run manually: pip install requests rich prompt-toolkit");
38
+ }
39
+
40
+ console.log("\n CodeGPT ready! Type: ai\n");