@hemacharanpyla/infinitycli 1.0.1 → 1.0.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/bin/infinity.js CHANGED
@@ -1,7 +1,51 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- // The CLI only needs built-in modules (process, readline, os, fetch).
4
- // Puppeteer/Express are only needed for the server (server.js).
5
3
  process.env.PUPPETEER_SKIP_DOWNLOAD = "true";
6
4
 
7
- import "../chat.js";
5
+ import { spawn } from "child_process";
6
+ import { fileURLToPath } from "url";
7
+ import { dirname, resolve } from "path";
8
+
9
+ const __dirname = dirname(fileURLToPath(import.meta.url));
10
+ const PKG_DIR = resolve(__dirname, "..");
11
+ const serverPath = resolve(PKG_DIR, "server.js");
12
+
13
+ let serverProc = null;
14
+
15
+ async function ensureServer() {
16
+ try {
17
+ const res = await fetch("http://localhost:3000/health");
18
+ if (res.ok) return;
19
+ } catch {}
20
+
21
+ serverProc = spawn(process.execPath, [serverPath], {
22
+ cwd: PKG_DIR,
23
+ stdio: "ignore",
24
+ detached: true,
25
+ });
26
+ serverProc.unref();
27
+
28
+ for (let i = 0; i < 30; i++) {
29
+ await new Promise(r => setTimeout(r, 1000));
30
+ try {
31
+ const res = await fetch("http://localhost:3000/health");
32
+ if (res.ok) return;
33
+ } catch {}
34
+ }
35
+ throw new Error("Server failed to start — check port 3000");
36
+ }
37
+
38
+ async function main() {
39
+ await ensureServer();
40
+
41
+ process.on("exit", () => {
42
+ if (serverProc) try { serverProc.kill(); } catch {}
43
+ });
44
+
45
+ await import("../chat.js");
46
+ }
47
+
48
+ main().catch(err => {
49
+ console.error(`\n \x1b[31m✕\x1b[0m ${err.message}`);
50
+ process.exit(1);
51
+ });
package/chat.js CHANGED
@@ -497,7 +497,7 @@ async function init() {
497
497
  updateStatus();
498
498
  } catch {
499
499
  state.connected = false;
500
- state.status = "start the server: node server.js";
500
+ state.status = "Server unreachable try again in a moment";
501
501
  updateStatus();
502
502
  }
503
503
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hemacharanpyla/infinitycli",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "∞ Infinity CLI — terminal AI chat with real-time response timing",
5
5
  "type": "module",
6
6
  "bin": {
@@ -11,17 +11,9 @@
11
11
  "chat": "node chat.js",
12
12
  "start": "node server.js",
13
13
  "infinity": "node bin/infinity.js",
14
- "prepublishOnly": "node --check bin/infinity.js && node --check chat.js"
14
+ "prepublishOnly": "node --check bin/infinity.js && node --check chat.js && node --check server.js"
15
15
  },
16
- "keywords": [
17
- "cli",
18
- "ai",
19
- "chat",
20
- "terminal",
21
- "assistant",
22
- "chatgpt",
23
- "puppeteer"
24
- ],
16
+ "keywords": ["cli", "ai", "chat", "terminal", "assistant"],
25
17
  "author": "Charan <hemacharanpyla@gmail.com>",
26
18
  "license": "MIT",
27
19
  "repository": {
@@ -38,14 +30,11 @@
38
30
  "files": [
39
31
  "bin/",
40
32
  "chat.js",
41
- "server.js",
42
- "cookies/",
43
- "README.md"
33
+ "server.js"
44
34
  ],
45
- "dependencies": {},
46
- "optionalDependencies": {
47
- "express": "^4.22.2",
48
- "puppeteer": "^23.11.1"
35
+ "dependencies": {
36
+ "express": "^4.21.0",
37
+ "puppeteer": "^23.0.0"
49
38
  },
50
39
  "puppeteer": {
51
40
  "skipDownload": true
package/server.js CHANGED
@@ -4,9 +4,13 @@ import { spawn } from "child_process";
4
4
  import { randomUUID } from "crypto";
5
5
  import { existsSync, readFileSync } from "fs";
6
6
  import path from "path";
7
+ import { fileURLToPath } from "url";
8
+ import os from "os";
9
+
10
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
7
11
 
8
12
  const app = express();
9
- const publicPath = path.resolve("public");
13
+ const publicPath = path.resolve(__dirname, "../public");
10
14
 
11
15
  app.use(express.static(publicPath));
12
16
 
@@ -20,7 +24,8 @@ const CHROME_PATH =
20
24
  const CHROME_DEBUG_PORT = process.env.CHROME_DEBUG_PORT || "9222";
21
25
  const CHROME_USER_DATA_DIR =
22
26
  process.env.CHROME_USER_DATA_DIR || "C:\\chrome-debug";
23
- const COOKIES_PATH = process.env.COOKIES_PATH || "./cookies/chatgpt.json";
27
+ const COOKIES_PATH = process.env.COOKIES_PATH || path.resolve(__dirname, "../cookies/chatgpt.json");
28
+ const HOME_COOKIES = path.resolve(os.homedir(), ".infinitycli", "cookies", "chatgpt.json");
24
29
 
25
30
  function positiveInt(value, fallback) {
26
31
  const number = Number.parseInt(value, 10);
@@ -88,11 +93,25 @@ class Semaphore {
88
93
  const pageCreateLimiter = new Semaphore(MAX_CONCURRENT_PAGE_CREATES);
89
94
  const messageLimiter = new Semaphore(MAX_CONCURRENT_MESSAGES);
90
95
 
96
+ function resolveCookies() {
97
+ if (process.env.COOKIES_PATH) return process.env.COOKIES_PATH;
98
+ if (existsSync(COOKIES_PATH)) return COOKIES_PATH;
99
+ if (existsSync(HOME_COOKIES)) return HOME_COOKIES;
100
+ return COOKIES_PATH;
101
+ }
102
+
91
103
  function loadCookies() {
92
- if (!existsSync(COOKIES_PATH)) {
93
- throw new Error(`Cookies file not found at ${COOKIES_PATH}`);
104
+ const cookiesFile = resolveCookies();
105
+ if (!existsSync(cookiesFile)) {
106
+ throw new Error(
107
+ `ChatGPT cookies not found.\n\n` +
108
+ `Place your cookies file at one of:\n` +
109
+ ` - ${COOKIES_PATH}\n` +
110
+ ` - ${HOME_COOKIES}\n\n` +
111
+ `Or set COOKIES_PATH env var to point to your cookies file.`
112
+ );
94
113
  }
95
- return JSON.parse(readFileSync(COOKIES_PATH, "utf-8"));
114
+ return JSON.parse(readFileSync(cookiesFile, "utf-8"));
96
115
  }
97
116
 
98
117
  function startChrome() {
@@ -1,11 +0,0 @@
1
- [
2
- {
3
- "name": "__Secure-next-auth.session-token",
4
- "value": "your-session-token-here",
5
- "domain": ".chatgpt.com",
6
- "path": "/",
7
- "httpOnly": true,
8
- "secure": true,
9
- "sameSite": "Lax"
10
- }
11
- ]