binary-collections 2.0.10 → 2.0.11

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 (165) hide show
  1. package/.puppeterrc.cjs +25 -0
  2. package/binaries/binary-executor.cjs +138 -3
  3. package/binaries/clean-nodemodule.cjs +138 -3
  4. package/binaries/clean-nodemodules.cjs +138 -3
  5. package/binaries/dev.cjs +138 -3
  6. package/binaries/empty.cjs +138 -3
  7. package/binaries/git-reduce-size.cjs +138 -3
  8. package/binaries/javakill.cjs +138 -3
  9. package/binaries/kill-night-crows.bat +7 -0
  10. package/binaries/kill-night-crows.ps1 +172 -0
  11. package/binaries/kill-process.cjs +138 -3
  12. package/binaries/nodekill.cjs +138 -3
  13. package/binaries/prod.cjs +138 -3
  14. package/binaries/py +111 -0
  15. package/binaries/py.cjs +178 -0
  16. package/binaries/py.cmd +49 -0
  17. package/binaries/rmfind.cjs +138 -3
  18. package/binaries/rmx.cjs +138 -3
  19. package/binaries/submodule-token.cjs +138 -3
  20. package/binaries/test-cjs +10 -0
  21. package/binaries/test-cjs.cjs +178 -0
  22. package/binaries/test-cjs.cmd +11 -0
  23. package/binaries/yarn-clean +32 -0
  24. package/binaries/yarn-clean.cjs +178 -0
  25. package/binaries/yarn-clean.cmd +30 -0
  26. package/binaries/yarn-clean.py +148 -0
  27. package/lib/binary-collections-config.cjs +1 -1
  28. package/lib/binary-collections-config.mjs +1 -1
  29. package/lib/binary-collections.cjs +167 -106
  30. package/lib/binary-collections.mjs +108 -94
  31. package/lib/changelog.cjs +61 -13
  32. package/lib/changelog.mjs +1 -1
  33. package/lib/{chunk-AI4CVPJ7.mjs → chunk-2CBJCW7E.mjs} +4 -4
  34. package/lib/chunk-34IQDTLZ.mjs +27 -0
  35. package/lib/chunk-3HFFECCI.mjs +27 -0
  36. package/lib/{chunk-SBNDSKG5.mjs → chunk-4UHL4WVN.mjs} +1 -1
  37. package/lib/chunk-7XTEJHOE.mjs +193 -0
  38. package/lib/chunk-AJDD5DZM.mjs +109 -0
  39. package/lib/chunk-BZWVHODJ.mjs +62 -0
  40. package/lib/{chunk-BEZKJ25G.mjs → chunk-FCDQGYBF.mjs} +5 -9
  41. package/lib/chunk-GEYA2USY.mjs +207 -0
  42. package/lib/chunk-ID2WBTE2.mjs +80 -0
  43. package/lib/chunk-JXFOHKDM.mjs +239 -0
  44. package/lib/{chunk-DI5MDPSN.mjs → chunk-N436BNBK.mjs} +192 -64
  45. package/lib/chunk-NCXAP7AA.mjs +31 -0
  46. package/lib/chunk-PDN26I7O.mjs +188 -0
  47. package/lib/{chunk-E6FDDAOO.mjs → chunk-RWLXRTYP.mjs} +1 -1
  48. package/lib/{chunk-BDCHCWHD.mjs → chunk-TOIVAQF7.mjs} +4 -4
  49. package/lib/chunk-V5SKYJUB.mjs +136 -0
  50. package/lib/{chunk-HMRMTYZM.mjs → chunk-WSRETQCA.mjs} +21 -2
  51. package/lib/chunk-XA3SNBPA.mjs +184 -0
  52. package/lib/chunk-YYLIQQKF.mjs +31 -0
  53. package/lib/{chunk-V3N3JEUF.mjs → chunk-Z6JLYU2J.mjs} +60 -13
  54. package/lib/{chunk-O6SWBEOQ.mjs → chunk-ZDMWBSYF.mjs} +2 -2
  55. package/lib/clean-github-actions-caches.cjs +63 -15
  56. package/lib/clean-github-actions-caches.mjs +3 -3
  57. package/lib/del-gradle.cjs +61 -13
  58. package/lib/del-gradle.js +1 -0
  59. package/lib/del-gradle.mjs +1 -1
  60. package/lib/del-node-modules.cjs +143 -148
  61. package/lib/del-node-modules.js +210 -14
  62. package/lib/del-node-modules.mjs +148 -17
  63. package/lib/del-ps.cjs +61 -13
  64. package/lib/del-ps.js +1 -0
  65. package/lib/del-ps.mjs +1 -1
  66. package/lib/del-yarn-caches.cjs +61 -13
  67. package/lib/del-yarn-caches.mjs +1 -1
  68. package/lib/find-node-modules-cli.js +1 -0
  69. package/lib/free-chatgpt.cjs +253 -47
  70. package/lib/free-chatgpt.mjs +2 -2
  71. package/lib/git/gitattributes.cjs +1 -0
  72. package/lib/git/gitattributes.d.cts +7 -2
  73. package/lib/git/gitattributes.mjs +1 -1
  74. package/lib/git/line-endings.cjs +2 -1
  75. package/lib/git/line-endings.mjs +2 -2
  76. package/lib/git/undo-commit-cli.cjs +110 -0
  77. package/lib/git/undo-commit-cli.d.ts +1 -0
  78. package/lib/git/undo-commit-cli.js +4 -0
  79. package/lib/git/undo-commit-cli.mjs +14 -0
  80. package/lib/git/undo-commit.cjs +81 -0
  81. package/lib/git/undo-commit.d.cts +1 -0
  82. package/lib/git/undo-commit.mjs +7 -0
  83. package/lib/git/undo-staged-cli.cjs +110 -0
  84. package/lib/git/undo-staged-cli.d.ts +1 -0
  85. package/lib/git/undo-staged-cli.js +4 -0
  86. package/lib/git/undo-staged-cli.mjs +14 -0
  87. package/lib/git/undo-staged.cjs +81 -0
  88. package/lib/git/undo-staged.d.cts +1 -0
  89. package/lib/git/undo-staged.mjs +7 -0
  90. package/lib/git/user-config.cjs +61 -14
  91. package/lib/git/user-config.mjs +2 -2
  92. package/lib/git-diff-cli.cjs +255 -49
  93. package/lib/git-diff-cli.d.ts +1 -0
  94. package/lib/git-diff-cli.js +1 -0
  95. package/lib/git-diff-cli.mjs +5 -4
  96. package/lib/git-diff.cjs +254 -49
  97. package/lib/git-diff.mjs +4 -4
  98. package/lib/git-fix.cjs +64 -16
  99. package/lib/git-fix.mjs +10 -10
  100. package/lib/git-purge.cjs +61 -13
  101. package/lib/git-purge.mjs +1 -1
  102. package/lib/kill-night-crows.cjs +87 -0
  103. package/lib/kill-night-crows.d.mts +1 -0
  104. package/lib/kill-night-crows.mjs +65 -0
  105. package/lib/npm-run-series.cjs +60 -13
  106. package/lib/npm-run-series.mjs +1 -1
  107. package/lib/package-resolutions-updater-cli.cjs +560 -0
  108. package/lib/package-resolutions-updater-cli.d.mts +1 -0
  109. package/lib/package-resolutions-updater-cli.mjs +124 -0
  110. package/lib/package-resolutions-updater.cjs +174 -154
  111. package/lib/package-resolutions-updater.d.mts +32 -1
  112. package/lib/package-resolutions-updater.mjs +16 -294
  113. package/lib/php-cs-fixer-staged.cjs +105 -0
  114. package/lib/php-cs-fixer-staged.d.cts +2 -0
  115. package/lib/php-cs-fixer-staged.mjs +117 -0
  116. package/lib/print-directory-tree.cjs +62 -14
  117. package/lib/print-directory-tree.mjs +2 -2
  118. package/lib/ps/connected-domain.d.ts +1 -1
  119. package/lib/ps/index.js +1 -0
  120. package/lib/remove-module.cjs +61 -13
  121. package/lib/remove-module.mjs +1 -1
  122. package/lib/rmpath.cjs +63 -15
  123. package/lib/rmpath.mjs +2 -2
  124. package/lib/submodule-install.cjs +62 -15
  125. package/lib/submodule-install.mjs +3 -3
  126. package/lib/submodule-remove-cli.cjs +5 -1
  127. package/lib/submodule-remove-cli.mjs +1 -1
  128. package/lib/submodule-remove.cjs +4 -1
  129. package/lib/submodule-remove.mjs +1 -1
  130. package/lib/utils/chatgpt.cjs +192 -34
  131. package/lib/utils/chatgpt.js +210 -43
  132. package/lib/utils/chatgpt.mjs +1 -1
  133. package/lib/utils/findEnvFiles.cjs +107 -0
  134. package/lib/utils/findEnvFiles.d.ts +8 -0
  135. package/lib/utils/findEnvFiles.js +121 -0
  136. package/lib/utils/findEnvFiles.mjs +8 -0
  137. package/lib/utils/findWorkspaceRoot.cjs +70 -0
  138. package/lib/utils/findWorkspaceRoot.d.ts +9 -0
  139. package/lib/utils/findWorkspaceRoot.js +57 -0
  140. package/lib/utils/findWorkspaceRoot.mjs +40 -0
  141. package/lib/utils/index.cjs +60 -13
  142. package/lib/utils/index.mjs +1 -1
  143. package/lib/utils/isGithubTokenValid.cjs +64 -0
  144. package/lib/utils/isGithubTokenValid.d.ts +7 -0
  145. package/lib/utils/isGithubTokenValid.js +48 -0
  146. package/lib/utils/isGithubTokenValid.mjs +36 -0
  147. package/lib/yarn-reinstall.cjs +61 -13
  148. package/lib/yarn-reinstall.mjs +1 -1
  149. package/package.json +107 -93
  150. package/readme.md +33 -34
  151. package/releases/readme.md +1 -1
  152. package/requirements.txt +1 -0
  153. package/lib/chunk-4EWQC6GZ.mjs +0 -382
  154. package/lib/chunk-4ZI7BQKQ.mjs +0 -381
  155. package/lib/chunk-5J2BEPY5.mjs +0 -83
  156. package/lib/chunk-AGZYRDC2.mjs +0 -323
  157. package/lib/chunk-HN52G2YL.mjs +0 -305
  158. package/lib/chunk-HO6GHCOB.mjs +0 -385
  159. package/lib/chunk-LEM5OMRP.mjs +0 -384
  160. package/lib/chunk-RCP7DHVY.mjs +0 -190
  161. package/lib/chunk-U6SO4QEV.mjs +0 -320
  162. package/lib/chunk-XD6BJK6Q.mjs +0 -351
  163. package/lib/chunk-YXSFGA2D.mjs +0 -383
  164. package/lib/git/gitattributes.d.ts +0 -33
  165. package/lib/git/gitattributes.js +0 -223
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env node
1
2
  var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -31,7 +32,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
31
32
  var getImportMetaUrl, importMetaUrl;
32
33
  var init_cjs_shims = __esm({
33
34
  "node_modules/tsup/assets/cjs_shims.js"() {
34
- getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
35
+ getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
35
36
  importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
36
37
  }
37
38
  });
@@ -41,7 +42,7 @@ var require_binary_collections_config = __commonJS({
41
42
  "src/binary-collections-config.cjs"(exports2, module2) {
42
43
  init_cjs_shims();
43
44
  var path3 = require("path");
44
- require("dotenv").config({ path: path3.join(process.cwd(), ".env") });
45
+ require("dotenv").config({ path: path3.join(process.cwd(), ".env"), quiet: true, override: true });
45
46
  function getTempDir() {
46
47
  return process.env.TEMP_DIR || path3.join(process.cwd(), "tmp");
47
48
  }
@@ -112,31 +113,78 @@ var require_utils = __commonJS({
112
113
  }
113
114
  module2.exports.getArgs = getArgs2;
114
115
  function del(fullPath) {
115
- if (fs3.statSync(fullPath).isDirectory()) {
116
- const subdir = fs3.readdirSync(fullPath).map((dirPath) => path3.resolve(fullPath, dirPath));
117
- for (let i = 0; i < subdir.length; i++) {
118
- del(subdir[i]);
116
+ try {
117
+ if (!fs3.existsSync(fullPath)) return;
118
+ const stat = fs3.lstatSync(fullPath);
119
+ if (stat.isSymbolicLink()) {
120
+ try {
121
+ fs3.unlinkSync(fullPath);
122
+ console.log("deleted symlink", fullPath);
123
+ } catch (e) {
124
+ console.log("failed delete symlink", fullPath, e && e.message);
125
+ }
126
+ return;
127
+ }
128
+ if (stat.isDirectory()) {
129
+ const subdir = fs3.readdirSync(fullPath).map((dirPath) => path3.resolve(fullPath, dirPath));
130
+ for (let i = 0; i < subdir.length; i++) {
131
+ del(subdir[i]);
132
+ }
133
+ try {
134
+ fs3.rmdirSync(fullPath);
135
+ console.log("deleted", fullPath);
136
+ } catch (e) {
137
+ try {
138
+ fs3.rmSync(fullPath, { recursive: true, force: true, retryDelay: 7e3 });
139
+ console.log("deleted", fullPath);
140
+ } catch (ee) {
141
+ console.log("failed delete", fullPath, ee && ee.message);
142
+ }
143
+ }
144
+ return;
119
145
  }
120
- } else {
121
146
  try {
122
- fs3.rmSync(fullPath, { recursive: true, force: true, retryDelay: 7e3 });
147
+ fs3.unlinkSync(fullPath);
123
148
  console.log("deleted", fullPath);
124
- } catch (_) {
125
- console.log("failed delete", fullPath);
149
+ } catch (e) {
150
+ try {
151
+ fs3.rmSync(fullPath, { recursive: true, force: true, retryDelay: 7e3 });
152
+ console.log("deleted", fullPath);
153
+ } catch (ee) {
154
+ console.log("failed delete", fullPath, ee && ee.message);
155
+ }
126
156
  }
157
+ } catch (err) {
158
+ console.log("failed delete", fullPath, err && err.message);
127
159
  }
128
160
  }
129
161
  module2.exports.del = del;
130
162
  function delStream(globStream) {
131
163
  globStream.stream().on("data", (result) => {
132
164
  const fullPath = path3.resolve(process.cwd(), result);
133
- if (fs3.statSync(fullPath).isDirectory()) {
134
- const subdir = fs3.readdirSync(fullPath).map((dirPath) => path3.resolve(fullPath, dirPath));
135
- for (let i = 0; i < subdir.length; i++) {
136
- del(subdir[i]);
165
+ try {
166
+ if (fs3.existsSync(fullPath)) {
167
+ const stat = fs3.lstatSync(fullPath);
168
+ if (stat.isSymbolicLink()) {
169
+ try {
170
+ fs3.unlinkSync(fullPath);
171
+ console.log("deleted symlink", fullPath);
172
+ } catch (e) {
173
+ console.log("failed delete symlink", fullPath, e && e.message);
174
+ }
175
+ return;
176
+ }
177
+ if (stat.isDirectory()) {
178
+ const subdir = fs3.readdirSync(fullPath).map((dirPath) => path3.resolve(fullPath, dirPath));
179
+ for (let i = 0; i < subdir.length; i++) {
180
+ del(subdir[i]);
181
+ }
182
+ }
137
183
  }
184
+ del(fullPath);
185
+ } catch (err) {
186
+ console.log("failed processing", fullPath, err && err.message);
138
187
  }
139
- del(fullPath);
140
188
  });
141
189
  }
142
190
  module2.exports.delStream = delStream;
@@ -201,7 +249,17 @@ var import_puppeteer_extra_plugin_stealth = __toESM(require("puppeteer-extra-plu
201
249
  var import_upath = __toESM(require("upath"), 1);
202
250
  var COOKIE_DIR = import_upath.default.join(process.cwd(), "tmp", "cookies");
203
251
  var DEFAULT_COOKIE_PATH = import_upath.default.join(COOKIE_DIR, "cookies.json");
252
+ var NAVIGATION_TIMEOUT_MS = 9e4;
253
+ var NETWORK_IDLE_TIMEOUT_MS = 15e3;
254
+ var MAX_INLINE_QUESTION_FILE_BYTES = 2 * 1024;
204
255
  import_fs_extra.default.ensureDirSync(COOKIE_DIR);
256
+ async function gotoWithFallback(page, url) {
257
+ await page.goto(url, { waitUntil: "domcontentloaded", timeout: NAVIGATION_TIMEOUT_MS });
258
+ try {
259
+ await page.waitForNetworkIdle({ idleTime: 1e3, timeout: NETWORK_IDLE_TIMEOUT_MS });
260
+ } catch {
261
+ }
262
+ }
205
263
  async function saveCookies(page, path3 = DEFAULT_COOKIE_PATH) {
206
264
  const cookies = await page.cookies();
207
265
  import_fs_extra.default.writeFileSync(path3, JSON.stringify(cookies, null, 2));
@@ -220,7 +278,7 @@ async function navigatePage(page, url) {
220
278
  if (cookies) {
221
279
  await page.setCookie(...cookies);
222
280
  }
223
- await page.goto(url, { waitUntil: "networkidle0" });
281
+ await gotoWithFallback(page, url);
224
282
  await page.evaluate(() => {
225
283
  window.__domStillUpdating = true;
226
284
  if (window.__domObserver) {
@@ -260,46 +318,151 @@ function loadCookies(cookieFilePath = DEFAULT_COOKIE_PATH) {
260
318
  return JSON.parse(import_fs_extra.default.readFileSync(cookieFilePath));
261
319
  }
262
320
  async function writeQuestion(page, question) {
263
- const questions = question.split("\n");
264
321
  const promptTextarea = await page.waitForSelector("#prompt-textarea", { timeout: 3e4 });
265
322
  if (!promptTextarea) {
266
323
  console.log(
267
324
  "Cannot find the prompt input on the webpage. Please check whether you have access to chat.openai.com without logging in via your browser."
268
325
  );
269
- }
270
- await page.evaluate(() => {
271
- document.querySelector("#prompt-textarea").innerHTML = `<p></p>`;
272
- });
273
- if (questions.length === 1) {
274
- await page.type("#prompt-textarea", questions[0], { delay: 100 });
275
326
  return;
276
327
  }
277
- for (const q of questions) {
278
- await page.type("#prompt-textarea", q, { delay: 100 });
279
- if (q !== questions[questions.length - 1]) {
280
- await page.keyboard.down("Shift");
281
- await page.keyboard.press("Enter");
282
- await page.keyboard.up("Shift");
328
+ await page.evaluate((text) => {
329
+ const promptEl = document.querySelector("#prompt-textarea");
330
+ if (!promptEl) {
331
+ return;
283
332
  }
333
+ promptEl.focus();
334
+ promptEl.innerHTML = "";
335
+ const lines = String(text).split("\n");
336
+ for (const line of lines) {
337
+ const p = document.createElement("p");
338
+ p.textContent = line;
339
+ promptEl.appendChild(p);
340
+ }
341
+ promptEl.dispatchEvent(new InputEvent("beforeinput", { bubbles: true, inputType: "insertFromPaste", data: text }));
342
+ promptEl.dispatchEvent(new InputEvent("input", { bubbles: true, inputType: "insertFromPaste", data: text }));
343
+ promptEl.dispatchEvent(new Event("change", { bubbles: true }));
344
+ }, question);
345
+ const hasPromptText = await page.evaluate(() => {
346
+ const promptEl = document.querySelector("#prompt-textarea");
347
+ return Boolean(promptEl && promptEl.textContent && promptEl.textContent.trim().length > 0);
348
+ });
349
+ if (!hasPromptText) {
350
+ console.log("Prompt state not updated by DOM injection. Falling back to keyboard insertText.");
351
+ await promptTextarea.click({ clickCount: 1 });
352
+ await page.keyboard.down("Control");
353
+ await page.keyboard.press("KeyA");
354
+ await page.keyboard.up("Control");
355
+ await page.keyboard.insertText(question);
284
356
  }
285
357
  }
286
358
  async function clickSubmitButton(page) {
359
+ console.log("Attempting to click the submit button...");
287
360
  try {
288
- const fruitjuiceSendButton = await page.evaluate(() => {
289
- return document.querySelector('[data-testid="fruitjuice-send-button"]') !== null;
361
+ const userMessageCountBefore = await page.$$eval('[data-message-author-role="user"]', (elements) => elements.length);
362
+ const waitForSubmit = async (timeout = 5e3) => {
363
+ try {
364
+ await page.waitForFunction(
365
+ (previousCount) => {
366
+ const currentCount = document.querySelectorAll('[data-message-author-role="user"]').length;
367
+ return currentCount > previousCount;
368
+ },
369
+ { timeout },
370
+ userMessageCountBefore
371
+ );
372
+ return true;
373
+ } catch {
374
+ return false;
375
+ }
376
+ };
377
+ await page.waitForFunction(() => {
378
+ const candidates = [
379
+ document.querySelector('[data-testid="fruitjuice-send-button"]'),
380
+ document.querySelector("#composer-submit-button"),
381
+ document.querySelector('[data-testid="send-button"]')
382
+ ].filter(Boolean);
383
+ return candidates.some((button) => {
384
+ const isDisabled = button.disabled || button.getAttribute("aria-disabled") === "true";
385
+ const isVisible = button.offsetParent !== null;
386
+ return !isDisabled && isVisible;
387
+ });
388
+ }, { timeout: 5e3 }).catch(() => {
290
389
  });
291
- const sendButton = await page.evaluate(() => {
292
- return document.querySelector('[data-testid="send-button"]') !== null;
390
+ const buttonDetails = await page.evaluate(() => {
391
+ const selectors = [
392
+ '[data-testid="fruitjuice-send-button"]',
393
+ "#composer-submit-button",
394
+ '[data-testid="send-button"]'
395
+ ];
396
+ const details = selectors.map((selector) => {
397
+ const el = document.querySelector(selector);
398
+ const exists = Boolean(el);
399
+ const disabled = exists ? Boolean(el.disabled || el.getAttribute("aria-disabled") === "true") : null;
400
+ const visible = exists ? el.offsetParent !== null : null;
401
+ return { selector, exists, disabled, visible };
402
+ });
403
+ return details;
293
404
  });
294
- if (fruitjuiceSendButton) {
295
- await page.click('[data-testid="fruitjuice-send-button"]');
296
- } else if (sendButton) {
297
- await page.click('[data-testid="send-button"]');
298
- } else {
299
- console.log("Neither send button is present");
405
+ console.log(`Submit button details: ${JSON.stringify(buttonDetails)}`);
406
+ const clickable = buttonDetails.find((item) => item.exists && item.visible && item.disabled === false);
407
+ const selectedSelector = clickable ? clickable.selector : null;
408
+ if (selectedSelector) {
409
+ await page.click(selectedSelector);
410
+ console.log(`Clicked submit button selector: ${selectedSelector}`);
411
+ if (await waitForSubmit(5e3)) {
412
+ console.log("Submission detected after selector click.");
413
+ return true;
414
+ }
415
+ const forcedClickWorked = await page.evaluate((selector) => {
416
+ const el = document.querySelector(selector);
417
+ if (!el) {
418
+ return false;
419
+ }
420
+ el.click();
421
+ return true;
422
+ }, selectedSelector);
423
+ if (forcedClickWorked) {
424
+ console.log(`Forced DOM click on selector: ${selectedSelector}`);
425
+ if (await waitForSubmit(5e3)) {
426
+ console.log("Submission detected after forced DOM click.");
427
+ return true;
428
+ }
429
+ }
430
+ }
431
+ console.log("Submit button path did not submit. Trying Enter key fallback on prompt.");
432
+ await page.focus("#prompt-textarea");
433
+ await page.keyboard.press("Enter");
434
+ if (await waitForSubmit(5e3)) {
435
+ console.log("Submission detected after Enter key fallback.");
436
+ return true;
437
+ }
438
+ const didRequestSubmit = await page.evaluate(() => {
439
+ const prompt = document.querySelector("#prompt-textarea");
440
+ if (!prompt) {
441
+ return false;
442
+ }
443
+ const form = prompt.closest("form");
444
+ if (!form) {
445
+ return false;
446
+ }
447
+ if (typeof form.requestSubmit === "function") {
448
+ form.requestSubmit();
449
+ } else {
450
+ form.submit();
451
+ }
452
+ return true;
453
+ });
454
+ if (didRequestSubmit) {
455
+ console.log("Triggered form submit fallback.");
456
+ if (await waitForSubmit(5e3)) {
457
+ console.log("Submission detected after form submit fallback.");
458
+ return true;
459
+ }
300
460
  }
461
+ console.log("Failed to submit prompt after all strategies.");
462
+ return false;
301
463
  } catch (e) {
302
464
  console.log(`Failed to click the send button: ${e}`);
465
+ return false;
303
466
  }
304
467
  }
305
468
  var lastMessageId = null;
@@ -372,11 +535,15 @@ async function isLoggedIn(page) {
372
535
  return result === true;
373
536
  }
374
537
  async function createBrowser(browserOptions = {}) {
538
+ const windowsChromeExecutable = "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe";
539
+ const hasWindowsChrome = process.platform === "win32" && import_fs_extra.default.existsSync(windowsChromeExecutable);
375
540
  const defaultOptions = {
376
541
  headless: false,
542
+ defaultViewport: null,
377
543
  userDataDir: import_upath.default.join(process.cwd(), "tmp/puppeteer-profile"),
378
544
  // Windows-specific options to handle browser launch issues
379
545
  args: [
546
+ "--start-maximized",
380
547
  "--no-sandbox",
381
548
  "--disable-setuid-sandbox",
382
549
  "--disable-dev-shm-usage",
@@ -389,10 +556,9 @@ async function createBrowser(browserOptions = {}) {
389
556
  "--disable-renderer-backgrounding"
390
557
  ],
391
558
  ignoreDefaultArgs: ["--disable-extensions"],
392
- ...process.platform === "win32" && {
393
- // Additional Windows-specific options
394
- executablePath: void 0
395
- // Let Puppeteer find Chrome automatically
559
+ ...hasWindowsChrome && {
560
+ // Prefer local Chrome installation when present on Windows.
561
+ executablePath: windowsChromeExecutable
396
562
  }
397
563
  };
398
564
  try {
@@ -402,8 +568,12 @@ async function createBrowser(browserOptions = {}) {
402
568
  try {
403
569
  return await import_puppeteer_extra.default.use((0, import_puppeteer_extra_plugin_stealth.default)()).launch({
404
570
  headless: browserOptions.headless || false,
405
- args: ["--no-sandbox", "--disable-setuid-sandbox"],
571
+ defaultViewport: null,
572
+ args: ["--start-maximized", "--no-sandbox", "--disable-setuid-sandbox"],
406
573
  ignoreDefaultArgs: false,
574
+ ...hasWindowsChrome && {
575
+ executablePath: windowsChromeExecutable
576
+ },
407
577
  ...browserOptions
408
578
  });
409
579
  } catch (fallbackError) {
@@ -428,7 +598,11 @@ async function loginToChatGpt() {
428
598
  if (loginButtonExists) {
429
599
  console.log("Login button found, clicking to log in...");
430
600
  await page.click('[data-testid="login-button"]');
431
- await page.waitForNavigation({ waitUntil: "networkidle0" });
601
+ await page.waitForNavigation({ waitUntil: "domcontentloaded", timeout: NAVIGATION_TIMEOUT_MS });
602
+ try {
603
+ await page.waitForNetworkIdle({ idleTime: 1e3, timeout: NETWORK_IDLE_TIMEOUT_MS });
604
+ } catch {
605
+ }
432
606
  console.log("Login process completed.");
433
607
  } else {
434
608
  console.log("No login required - user appears to be already logged in.");
@@ -438,6 +612,7 @@ async function runChatGpt(chatgptOptions = {}) {
438
612
  const headless = chatgptOptions.headless !== void 0 ? chatgptOptions.headless : true;
439
613
  const questionFile = chatgptOptions.questionFile;
440
614
  let question = chatgptOptions.question;
615
+ let shouldUploadQuestionFile = Boolean(questionFile);
441
616
  const responseFile = chatgptOptions.responseFile || import_upath.default.join(process.cwd(), "tmp", "response.txt");
442
617
  const noInputProvided = !question && !questionFile;
443
618
  const questionIsEmpty = question && question.trim().length === 0;
@@ -445,6 +620,22 @@ async function runChatGpt(chatgptOptions = {}) {
445
620
  if (noInputProvided || questionIsEmpty || questionFileIsEmpty) {
446
621
  throw new Error("You must provide a question or a question file.");
447
622
  }
623
+ if (!question && questionFile) {
624
+ if (!import_fs_extra.default.existsSync(questionFile)) {
625
+ throw new Error(`Question file does not exist: ${questionFile}`);
626
+ }
627
+ const questionFileStats = import_fs_extra.default.statSync(questionFile);
628
+ if (questionFileStats.size <= MAX_INLINE_QUESTION_FILE_BYTES) {
629
+ question = import_fs_extra.default.readFileSync(questionFile, "utf8").trim();
630
+ if (!question) {
631
+ throw new Error("Question file is empty.");
632
+ }
633
+ shouldUploadQuestionFile = false;
634
+ console.log(
635
+ `Question file is ${questionFileStats.size} bytes (<= ${MAX_INLINE_QUESTION_FILE_BYTES}). Sending as text prompt.`
636
+ );
637
+ }
638
+ }
448
639
  let browser;
449
640
  try {
450
641
  browser = await createBrowser({ headless });
@@ -457,7 +648,16 @@ async function runChatGpt(chatgptOptions = {}) {
457
648
  console.error("4. Close any running Chrome instances and try again");
458
649
  throw error;
459
650
  }
460
- const page = (await browser.pages()).length > 0 ? (await browser.pages())[0] : await browser.newPage();
651
+ const allPages = await browser.pages();
652
+ const page = allPages.length > 0 ? allPages[0] : await browser.newPage();
653
+ await page.bringToFront();
654
+ if (allPages.length > 1) {
655
+ for (const p of allPages) {
656
+ if (p !== page) {
657
+ await p.close();
658
+ }
659
+ }
660
+ }
461
661
  try {
462
662
  const url = "https://chat.openai.com";
463
663
  const navigate = await navigatePage(page, url);
@@ -476,12 +676,15 @@ async function runChatGpt(chatgptOptions = {}) {
476
676
  }
477
677
  if (question) {
478
678
  await writeQuestion(page, question);
479
- await clickSubmitButton(page);
679
+ const didSubmit = await clickSubmitButton(page);
680
+ if (!didSubmit) {
681
+ throw new Error("Prompt was not submitted. The composer button may be disabled or blocked.");
682
+ }
480
683
  await navigate.waitForDomIdle(1e3, 3e4);
481
684
  await waitForInitialResponse(page);
482
685
  await handleStreamingResponse(page, responseFile);
483
686
  await saveCookies(page, getCookiePathForUrl(url));
484
- } else if (questionFile) {
687
+ } else if (shouldUploadQuestionFile && questionFile) {
485
688
  await navigate.waitForDomIdle(2e3, 1e4);
486
689
  const isUserLoggedIn = await isLoggedIn(page);
487
690
  console.log(`Login status: ${isUserLoggedIn ? "Logged in" : "Not logged in"}`);
@@ -520,7 +723,10 @@ async function runChatGpt(chatgptOptions = {}) {
520
723
  await fileInput.uploadFile(questionFile);
521
724
  await navigate.waitForDomIdle(2e3, 15e3);
522
725
  console.log("File uploaded successfully");
523
- await clickSubmitButton(page);
726
+ const didSubmit = await clickSubmitButton(page);
727
+ if (!didSubmit) {
728
+ throw new Error("Prompt was not submitted after file upload.");
729
+ }
524
730
  await navigate.waitForDomIdle(1e3, 3e4);
525
731
  await waitForInitialResponse(page);
526
732
  await handleStreamingResponse(page, responseFile);
@@ -1 +1,2 @@
1
+ #!/usr/bin/env node
1
2
  export {};
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env node
1
2
  "use strict";
2
3
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
4
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
@@ -1,10 +1,11 @@
1
+ #!/usr/bin/env node
1
2
  import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
3
  import {
3
4
  mainGitDiff
4
- } from "./chunk-SBNDSKG5.mjs";
5
- import "./chunk-GJTGHXRA.mjs";
6
- import "./chunk-66PAU5PS.mjs";
7
- import "./chunk-V3N3JEUF.mjs";
5
+ } from "./chunk-FCDQGYBF.mjs";
6
+ import "./chunk-N436BNBK.mjs";
7
+ import "./chunk-YYLIQQKF.mjs";
8
+ import "./chunk-Z6JLYU2J.mjs";
8
9
  import {
9
10
  init_esm_shims
10
11
  } from "./chunk-QQ4A6DLD.mjs";