binary-collections 2.0.9 → 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.
- package/.puppeterrc.cjs +25 -0
- package/binaries/binary-executor.cjs +178 -0
- package/{bin → binaries}/clean-nodemodule +0 -0
- package/binaries/clean-nodemodule.cjs +178 -0
- package/binaries/clean-nodemodule.cmd +4 -0
- package/{bin → binaries}/clean-nodemodules +0 -0
- package/binaries/clean-nodemodules.cjs +178 -0
- package/binaries/clean-nodemodules.cmd +5 -0
- package/{bin → binaries}/dev +0 -0
- package/binaries/dev.cjs +178 -0
- package/{bin → binaries}/empty +0 -0
- package/binaries/empty.cjs +178 -0
- package/{bin → binaries}/git-reduce-size +0 -0
- package/binaries/git-reduce-size.cjs +178 -0
- package/binaries/javakill.cjs +178 -0
- package/{bin → binaries}/javakill.cmd +0 -0
- package/binaries/kill-night-crows.bat +7 -0
- package/binaries/kill-night-crows.ps1 +172 -0
- package/{bin → binaries}/kill-process +0 -0
- package/binaries/kill-process.cjs +178 -0
- package/binaries/nodekill.cjs +178 -0
- package/{bin → binaries}/nodekill.ps1 +0 -0
- package/{bin → binaries}/prod +0 -0
- package/binaries/prod.cjs +178 -0
- package/binaries/py +111 -0
- package/binaries/py.cjs +178 -0
- package/binaries/py.cmd +49 -0
- package/{bin → binaries}/rmfind +0 -0
- package/binaries/rmfind.cjs +178 -0
- package/{bin → binaries}/rmx +0 -0
- package/binaries/rmx.cjs +178 -0
- package/{bin → binaries}/submodule-token +0 -0
- package/binaries/submodule-token.cjs +178 -0
- package/binaries/test-cjs +10 -0
- package/binaries/test-cjs.cjs +178 -0
- package/binaries/test-cjs.cmd +11 -0
- package/binaries/yarn-clean +32 -0
- package/binaries/yarn-clean.cjs +178 -0
- package/binaries/yarn-clean.cmd +30 -0
- package/binaries/yarn-clean.py +148 -0
- package/docs-src/clean-github-actions-caches.md +26 -0
- package/docs-src/free-chatgpt.md +26 -0
- package/lib/binary-collections-config.cjs +3 -2
- package/lib/binary-collections-config.mjs +2 -2
- package/lib/binary-collections.cjs +513 -105
- package/lib/binary-collections.mjs +178 -117
- package/lib/changelog.cjs +64 -16
- package/lib/changelog.mjs +177 -171
- package/lib/{chunk-VVEZVNIV.mjs → chunk-2CBJCW7E.mjs} +3 -3
- package/lib/chunk-34IQDTLZ.mjs +27 -0
- package/lib/chunk-3HFFECCI.mjs +27 -0
- package/lib/chunk-4UHL4WVN.mjs +136 -0
- package/lib/{chunk-4BYBVEYC.mjs → chunk-66PAU5PS.mjs} +5 -4
- package/lib/chunk-6HHJRKFB.mjs +59 -0
- package/lib/chunk-6S4NXESK.mjs +26 -0
- package/lib/chunk-7XTEJHOE.mjs +193 -0
- package/lib/{chunk-ZYAQRPUL.mjs → chunk-7YD7IPFF.mjs} +2 -2
- package/lib/{chunk-SH3L6HHV.mjs → chunk-A2JQXI5Z.mjs} +2 -2
- package/lib/{chunk-EGSSKVDH.mjs → chunk-A3VUZEJK.mjs} +1 -1
- package/lib/chunk-AJDD5DZM.mjs +109 -0
- package/lib/chunk-BZWVHODJ.mjs +62 -0
- package/lib/chunk-FCDQGYBF.mjs +136 -0
- package/lib/chunk-FKI7IEB5.mjs +172 -0
- package/lib/chunk-GEYA2USY.mjs +207 -0
- package/lib/chunk-GJTGHXRA.mjs +356 -0
- package/lib/{chunk-YV7DO3YV.mjs → chunk-HLGOWBEO.mjs} +1 -1
- package/lib/chunk-ID2WBTE2.mjs +80 -0
- package/lib/chunk-JXFOHKDM.mjs +239 -0
- package/lib/{chunk-YX5U7XDR.mjs → chunk-M3YIYRHT.mjs} +6 -5
- package/lib/chunk-N436BNBK.mjs +514 -0
- package/lib/chunk-NCXAP7AA.mjs +31 -0
- package/lib/chunk-PDN26I7O.mjs +188 -0
- package/lib/{chunk-JGR2NW6D.mjs → chunk-PDSXF5HY.mjs} +3 -3
- package/lib/{chunk-AASHBCRW.mjs → chunk-QQ4A6DLD.mjs} +8 -0
- package/lib/{chunk-ONIBBBQ3.mjs → chunk-RWLXRTYP.mjs} +4 -3
- package/lib/chunk-TOIVAQF7.mjs +136 -0
- package/lib/chunk-V5SKYJUB.mjs +136 -0
- package/lib/chunk-WSRETQCA.mjs +59 -0
- package/lib/chunk-XA3SNBPA.mjs +184 -0
- package/lib/chunk-XVBFFVCJ.mjs +209 -0
- package/lib/chunk-YYLIQQKF.mjs +31 -0
- package/lib/{chunk-APBWENF6.mjs → chunk-Z6JLYU2J.mjs} +63 -16
- package/lib/chunk-ZDMWBSYF.mjs +81 -0
- package/lib/clean-github-actions-caches.cjs +291 -148
- package/lib/clean-github-actions-caches.mjs +4 -3
- package/lib/del-gradle.cjs +63 -15
- package/lib/del-gradle.js +2 -1
- package/lib/del-gradle.mjs +2 -2
- package/lib/del-node-modules.cjs +143 -148
- package/lib/del-node-modules.js +210 -14
- package/lib/del-node-modules.mjs +149 -18
- package/lib/del-ps.cjs +90 -21
- package/lib/del-ps.js +3 -2
- package/lib/del-ps.mjs +7 -5
- package/lib/del-yarn-caches.cjs +87 -18
- package/lib/del-yarn-caches.js +38 -3
- package/lib/del-yarn-caches.mjs +6 -6
- package/lib/find-node-modules-cli.cjs +5 -4
- package/lib/find-node-modules-cli.js +2 -1
- package/lib/find-node-modules-cli.mjs +2 -2
- package/lib/find-node-modules.cjs +4 -3
- package/lib/{find-node-modules.d.ts → find-node-modules.d.cts} +1 -1
- package/lib/find-node-modules.mjs +2 -2
- package/lib/free-chatgpt.cjs +754 -0
- package/lib/free-chatgpt.js +51 -0
- package/lib/free-chatgpt.mjs +50 -0
- package/lib/git/gitattributes.cjs +2 -1
- package/lib/git/{gitattributes.d.ts → gitattributes.d.cts} +7 -2
- package/lib/git/gitattributes.mjs +2 -2
- package/lib/git/line-endings.cjs +298 -64
- package/lib/git/line-endings.mjs +4 -4
- package/lib/git/normalize.cjs +26 -36
- package/lib/git/normalize.mjs +2 -2
- package/lib/git/permissions.cjs +77 -11
- package/lib/git/permissions.mjs +3 -3
- package/lib/git/pull-strategy.cjs +76 -9
- package/lib/git/pull-strategy.mjs +3 -3
- package/lib/git/undo-commit-cli.cjs +110 -0
- package/lib/git/undo-commit-cli.d.ts +1 -0
- package/lib/git/undo-commit-cli.js +4 -0
- package/lib/git/undo-commit-cli.mjs +14 -0
- package/lib/git/undo-commit.cjs +81 -0
- package/lib/git/undo-commit.d.cts +1 -0
- package/lib/git/undo-commit.mjs +7 -0
- package/lib/git/undo-staged-cli.cjs +110 -0
- package/lib/git/undo-staged-cli.d.ts +1 -0
- package/lib/git/undo-staged-cli.js +4 -0
- package/lib/git/undo-staged-cli.mjs +14 -0
- package/lib/git/undo-staged.cjs +81 -0
- package/lib/git/undo-staged.d.cts +1 -0
- package/lib/git/undo-staged.mjs +7 -0
- package/lib/git/user-config.cjs +313 -83
- package/lib/git/user-config.mjs +4 -4
- package/lib/git/utils.cjs +40 -60
- package/lib/git/utils.mjs +2 -2
- package/lib/git-diff-cli.cjs +857 -0
- package/lib/git-diff-cli.js +16 -0
- package/lib/git-diff-cli.mjs +17 -0
- package/lib/git-diff.cjs +862 -58
- package/lib/git-diff.d.ts +38 -83
- package/lib/git-diff.js +152 -0
- package/lib/git-diff.mjs +23 -85
- package/lib/git-fix.cjs +733 -97
- package/lib/git-fix.mjs +10 -9
- package/lib/git-purge.cjs +64 -16
- package/lib/git-purge.d.cts +1 -0
- package/lib/git-purge.mjs +43 -37
- package/lib/index.cjs +7 -6
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -5
- package/lib/index.mjs +4 -4
- package/lib/kill-night-crows.cjs +87 -0
- package/lib/kill-night-crows.d.mts +1 -0
- package/lib/kill-night-crows.mjs +65 -0
- package/lib/npm-run-series.cjs +63 -16
- package/lib/npm-run-series.mjs +42 -36
- package/lib/package-resolutions-updater-cli.cjs +560 -0
- package/lib/package-resolutions-updater-cli.d.mts +1 -0
- package/lib/package-resolutions-updater-cli.mjs +124 -0
- package/lib/package-resolutions-updater.cjs +178 -158
- package/lib/package-resolutions-updater.d.mts +32 -1
- package/lib/package-resolutions-updater.mjs +17 -338
- package/lib/php-cs-fixer-staged.cjs +105 -0
- package/lib/php-cs-fixer-staged.d.cts +2 -0
- package/lib/php-cs-fixer-staged.mjs +117 -0
- package/lib/print-directory-tree.cjs +320 -207
- package/lib/print-directory-tree.mjs +3 -3
- package/lib/ps/connected-domain.cjs +25 -2
- package/lib/ps/connected-domain.d.ts +10 -2
- package/lib/ps/connected-domain.js +5 -2
- package/lib/ps/connected-domain.mjs +8 -4
- package/lib/ps/index.cjs +345 -322
- package/lib/ps/index.d.mjs +1 -1
- package/lib/ps/index.js +2 -1
- package/lib/ps/index.mjs +179 -182
- package/lib/ps/isWin.cjs +24 -1
- package/lib/ps/isWin.d.ts +1 -1
- package/lib/ps/isWin.js +3 -1
- package/lib/ps/isWin.mjs +8 -4
- package/lib/ps/table-parser.cjs +167 -159
- package/lib/ps/table-parser.d.ts +5 -0
- package/lib/ps/table-parser.js +10 -4
- package/lib/ps/table-parser.mjs +9 -5
- package/lib/remove-module.cjs +310 -0
- package/lib/remove-module.d.mts +1 -0
- package/lib/remove-module.mjs +111 -0
- package/lib/rmpath.cjs +322 -0
- package/lib/rmpath.d.mts +3 -0
- package/lib/rmpath.mjs +108 -0
- package/lib/submodule-install.cjs +311 -86
- package/lib/submodule-install.mjs +53 -5
- package/lib/submodule-remove-cli.cjs +107 -0
- package/lib/submodule-remove-cli.d.ts +1 -0
- package/lib/submodule-remove-cli.js +31 -0
- package/lib/submodule-remove-cli.mjs +28 -0
- package/lib/submodule-remove.cjs +46 -0
- package/lib/submodule-remove.d.cts +2 -0
- package/lib/submodule-remove.mjs +6 -0
- package/lib/utils/chatgpt.cjs +541 -0
- package/lib/utils/chatgpt.d.ts +31 -0
- package/lib/utils/chatgpt.js +708 -0
- package/lib/utils/chatgpt.mjs +8 -0
- package/lib/utils/findEnvFiles.cjs +107 -0
- package/lib/utils/findEnvFiles.d.ts +8 -0
- package/lib/utils/findEnvFiles.js +121 -0
- package/lib/utils/findEnvFiles.mjs +8 -0
- package/lib/utils/findWorkspaceRoot.cjs +70 -0
- package/lib/utils/findWorkspaceRoot.d.ts +9 -0
- package/lib/utils/findWorkspaceRoot.js +57 -0
- package/lib/utils/findWorkspaceRoot.mjs +40 -0
- package/lib/{utils.cjs → utils/index.cjs} +61 -14
- package/lib/{utils.mjs → utils/index.mjs} +2 -2
- package/lib/utils/isGithubTokenValid.cjs +64 -0
- package/lib/utils/isGithubTokenValid.d.ts +7 -0
- package/lib/utils/isGithubTokenValid.js +48 -0
- package/lib/utils/isGithubTokenValid.mjs +36 -0
- package/lib/yarn-reinstall.cjs +220 -38
- package/lib/yarn-reinstall.mjs +2 -2
- package/package.json +138 -104
- package/readme.md +48 -75
- package/releases/readme.md +36 -0
- package/requirements.txt +1 -0
- package/test/README.md +101 -0
- package/test/package.json +2 -1
- package/test-project/readme.md +26 -0
- package/tmp/test-repo/README.md +35 -0
- package/tmp/test-repo/package.json +1 -1
- package/tmp/typedoc/readme.md +320 -0
- package/bin/bash-dummy +0 -56
- package/bin/bash-dummy.cmd +0 -25
- package/bin/dir-tree.cmd +0 -7
- package/bin/git-diff +0 -4
- package/bin/git-diff.cmd +0 -7
- package/bin/git-fix +0 -36
- package/bin/git-fix.cmd +0 -7
- package/bin/rmpath +0 -70
- package/bin/submodule-install.txt +0 -118
- package/bin/submodule-remove +0 -46
- package/bin/submodule.txt +0 -172
- package/lib/binary-collections-config.d.mts +0 -18
- package/lib/binary-collections-config.js +0 -39
- package/lib/binary-collections.d.mts +0 -137
- package/lib/binary-collections.d.ts +0 -137
- package/lib/changelog.d.mts +0 -2
- package/lib/changelog.js +0 -226
- package/lib/chunk-DPKAJKFO.mjs +0 -171
- package/lib/chunk-G3THLIDT.mjs +0 -200
- package/lib/chunk-W3ENOM53.mjs +0 -18
- package/lib/clean-github-actions-caches.d.mts +0 -169
- package/lib/clean-github-actions-caches.d.ts +0 -169
- package/lib/del-gradle.d.mts +0 -2
- package/lib/del-node-modules.d.mts +0 -2
- package/lib/del-ps.d.mts +0 -2
- package/lib/del-yarn-caches.d.mts +0 -2
- package/lib/find-node-modules-cli.d.mts +0 -1
- package/lib/find-node-modules.d.mts +0 -13
- package/lib/find-node-modules.js +0 -53
- package/lib/git/gitattributes.d.mts +0 -35
- package/lib/git/gitattributes.js +0 -223
- package/lib/git/line-endings.d.mts +0 -83
- package/lib/git/line-endings.d.ts +0 -83
- package/lib/git/normalize.d.mts +0 -43
- package/lib/git/normalize.d.ts +0 -43
- package/lib/git/permissions.d.mts +0 -17
- package/lib/git/permissions.d.ts +0 -17
- package/lib/git/pull-strategy.d.mts +0 -15
- package/lib/git/pull-strategy.d.ts +0 -15
- package/lib/git/user-config.d.mts +0 -105
- package/lib/git/user-config.d.ts +0 -105
- package/lib/git/utils.d.mts +0 -69
- package/lib/git/utils.d.ts +0 -69
- package/lib/git-diff.d.mts +0 -84
- package/lib/git-fix.d.mts +0 -141
- package/lib/git-fix.d.ts +0 -141
- package/lib/git-purge.d.mts +0 -2
- package/lib/git-purge.js +0 -59
- package/lib/index.d.mts +0 -1
- package/lib/npm-run-series.d.mts +0 -1
- package/lib/npm-run-series.js +0 -86
- package/lib/package-resolutions-updater.d.ts +0 -352
- package/lib/print-directory-tree.d.mts +0 -234
- package/lib/print-directory-tree.d.ts +0 -234
- package/lib/ps/connected-domain.d.mts +0 -3
- package/lib/ps/index.d.d.mts +0 -26
- package/lib/ps/index.d.d.ts +0 -26
- package/lib/ps/index.d.mts +0 -26
- package/lib/ps/isWin.d.mts +0 -3
- package/lib/ps/table-parser.d.mts +0 -3
- package/lib/submodule-install.d.mts +0 -121
- package/lib/submodule-install.d.ts +0 -121
- package/lib/utils.d.mts +0 -40
- package/lib/utils.js +0 -181
- package/lib/yarn-reinstall.d.mts +0 -49
- package/lib/yarn-reinstall.d.ts +0 -49
- package/src/package-resolutions-updater.mjs +0 -350
- package/src/print-directory-tree.cjs +0 -234
- package/src/ps/index.js +0 -286
- package/src/yarn-reinstall.cjs +0 -49
- /package/{bin → binaries}/nodekill +0 -0
- /package/{bin → binaries}/nodekill.cmd +0 -0
- /package/lib/{binary-collections-config.d.ts → binary-collections-config.d.cts} +0 -0
- /package/lib/{changelog.d.ts → changelog.d.cts} +0 -0
- /package/lib/{git-purge.d.ts → free-chatgpt.d.ts} +0 -0
- /package/lib/{git-diff.d.cts → git-diff-cli.d.ts} +0 -0
- /package/lib/{npm-run-series.d.ts → npm-run-series.d.cts} +0 -0
- /package/lib/{utils.d.ts → utils/index.d.cts} +0 -0
package/lib/git-diff.cjs
CHANGED
|
@@ -1,73 +1,877 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __esm = (fn, res) => function __init() {
|
|
9
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
|
+
};
|
|
11
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
12
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
13
|
+
};
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
27
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
28
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
29
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
30
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
31
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
32
|
+
mod
|
|
33
|
+
));
|
|
34
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
35
|
+
|
|
36
|
+
// node_modules/tsup/assets/cjs_shims.js
|
|
37
|
+
var getImportMetaUrl, importMetaUrl;
|
|
38
|
+
var init_cjs_shims = __esm({
|
|
39
|
+
"node_modules/tsup/assets/cjs_shims.js"() {
|
|
40
|
+
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;
|
|
41
|
+
importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// src/binary-collections-config.cjs
|
|
46
|
+
var require_binary_collections_config = __commonJS({
|
|
47
|
+
"src/binary-collections-config.cjs"(exports2, module2) {
|
|
48
|
+
init_cjs_shims();
|
|
49
|
+
var path3 = require("path");
|
|
50
|
+
require("dotenv").config({ path: path3.join(process.cwd(), ".env"), quiet: true, override: true });
|
|
51
|
+
function getTempDir() {
|
|
52
|
+
return process.env.TEMP_DIR || path3.join(process.cwd(), "tmp");
|
|
53
|
+
}
|
|
54
|
+
function getTempPath2(...segments) {
|
|
55
|
+
return path3.join(getTempDir(), ...segments);
|
|
56
|
+
}
|
|
57
|
+
var TEMP_BASE_DIR = getTempDir();
|
|
58
|
+
module2.exports = {
|
|
59
|
+
getTempDir,
|
|
60
|
+
getTempPath: getTempPath2,
|
|
61
|
+
TEMP_BASE_DIR
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// src/utils/index.cjs
|
|
67
|
+
var require_utils = __commonJS({
|
|
68
|
+
"src/utils/index.cjs"(exports2, module2) {
|
|
69
|
+
init_cjs_shims();
|
|
70
|
+
var fs3 = require("fs");
|
|
71
|
+
var path3 = require("upath");
|
|
72
|
+
var argv = require("minimist")(process.argv.slice(2));
|
|
73
|
+
var { exec } = require("child_process");
|
|
74
|
+
var { URL: URL2 } = require("url");
|
|
75
|
+
var { promisify } = require("util");
|
|
76
|
+
var execAsync = promisify(exec);
|
|
77
|
+
async function parseGitRemotes() {
|
|
78
|
+
try {
|
|
79
|
+
const { stdout } = await execAsync("git remote -v");
|
|
80
|
+
const lines = stdout.split("\n");
|
|
81
|
+
const remotes = {};
|
|
82
|
+
lines.forEach((line) => {
|
|
83
|
+
const [name, url] = line.split(" ");
|
|
84
|
+
if (name && url) {
|
|
85
|
+
const [repoUrl] = url.split(" ");
|
|
86
|
+
try {
|
|
87
|
+
const parsedUrl = new URL2(repoUrl);
|
|
88
|
+
const pathParts = parsedUrl.pathname.split("/").filter(Boolean);
|
|
89
|
+
if (parsedUrl.hostname === "github.com" && pathParts.length === 2) {
|
|
90
|
+
let repoPath = pathParts.join("/");
|
|
91
|
+
if (repoPath.endsWith(".git")) {
|
|
92
|
+
repoPath = repoPath.slice(0, -4);
|
|
93
|
+
}
|
|
94
|
+
remotes[name] = repoPath;
|
|
95
|
+
}
|
|
96
|
+
} catch (e) {
|
|
97
|
+
console.error("URL Parsing Error:", e.message);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
return remotes;
|
|
102
|
+
} catch (error) {
|
|
103
|
+
console.error("Error:", error.message);
|
|
104
|
+
return {};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
module2.exports.parseGitRemotes = parseGitRemotes;
|
|
108
|
+
function joinPathPreserveDriveLetter(...segments) {
|
|
109
|
+
let fullPath = require("path").join(...segments);
|
|
110
|
+
if (/^[a-z]:\\/.test(fullPath)) {
|
|
111
|
+
fullPath = fullPath.charAt(0).toUpperCase() + fullPath.slice(1);
|
|
112
|
+
}
|
|
113
|
+
return fullPath;
|
|
114
|
+
}
|
|
115
|
+
module2.exports.joinPathPreserveDriveLetter = joinPathPreserveDriveLetter;
|
|
116
|
+
function getArgs2() {
|
|
117
|
+
return argv;
|
|
118
|
+
}
|
|
119
|
+
module2.exports.getArgs = getArgs2;
|
|
120
|
+
function del(fullPath) {
|
|
121
|
+
try {
|
|
122
|
+
if (!fs3.existsSync(fullPath)) return;
|
|
123
|
+
const stat = fs3.lstatSync(fullPath);
|
|
124
|
+
if (stat.isSymbolicLink()) {
|
|
125
|
+
try {
|
|
126
|
+
fs3.unlinkSync(fullPath);
|
|
127
|
+
console.log("deleted symlink", fullPath);
|
|
128
|
+
} catch (e) {
|
|
129
|
+
console.log("failed delete symlink", fullPath, e && e.message);
|
|
130
|
+
}
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (stat.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]);
|
|
137
|
+
}
|
|
138
|
+
try {
|
|
139
|
+
fs3.rmdirSync(fullPath);
|
|
140
|
+
console.log("deleted", fullPath);
|
|
141
|
+
} catch (e) {
|
|
142
|
+
try {
|
|
143
|
+
fs3.rmSync(fullPath, { recursive: true, force: true, retryDelay: 7e3 });
|
|
144
|
+
console.log("deleted", fullPath);
|
|
145
|
+
} catch (ee) {
|
|
146
|
+
console.log("failed delete", fullPath, ee && ee.message);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
try {
|
|
152
|
+
fs3.unlinkSync(fullPath);
|
|
153
|
+
console.log("deleted", fullPath);
|
|
154
|
+
} catch (e) {
|
|
155
|
+
try {
|
|
156
|
+
fs3.rmSync(fullPath, { recursive: true, force: true, retryDelay: 7e3 });
|
|
157
|
+
console.log("deleted", fullPath);
|
|
158
|
+
} catch (ee) {
|
|
159
|
+
console.log("failed delete", fullPath, ee && ee.message);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
} catch (err) {
|
|
163
|
+
console.log("failed delete", fullPath, err && err.message);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
module2.exports.del = del;
|
|
167
|
+
function delStream(globStream) {
|
|
168
|
+
globStream.stream().on("data", (result) => {
|
|
169
|
+
const fullPath = path3.resolve(process.cwd(), result);
|
|
170
|
+
try {
|
|
171
|
+
if (fs3.existsSync(fullPath)) {
|
|
172
|
+
const stat = fs3.lstatSync(fullPath);
|
|
173
|
+
if (stat.isSymbolicLink()) {
|
|
174
|
+
try {
|
|
175
|
+
fs3.unlinkSync(fullPath);
|
|
176
|
+
console.log("deleted symlink", fullPath);
|
|
177
|
+
} catch (e) {
|
|
178
|
+
console.log("failed delete symlink", fullPath, e && e.message);
|
|
179
|
+
}
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
if (stat.isDirectory()) {
|
|
183
|
+
const subdir = fs3.readdirSync(fullPath).map((dirPath) => path3.resolve(fullPath, dirPath));
|
|
184
|
+
for (let i = 0; i < subdir.length; i++) {
|
|
185
|
+
del(subdir[i]);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
del(fullPath);
|
|
190
|
+
} catch (err) {
|
|
191
|
+
console.log("failed processing", fullPath, err && err.message);
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
module2.exports.delStream = delStream;
|
|
196
|
+
function getFileTreeString(hashArray) {
|
|
197
|
+
const tree = {};
|
|
198
|
+
const hashMap = {};
|
|
199
|
+
for (const entry of hashArray) {
|
|
200
|
+
const [filePath, hash] = entry.split(" ");
|
|
201
|
+
hashMap[filePath] = hash;
|
|
202
|
+
const parts = filePath.split("/");
|
|
203
|
+
let current = tree;
|
|
204
|
+
for (let i = 0; i < parts.length; i++) {
|
|
205
|
+
const part = parts[i];
|
|
206
|
+
if (i === parts.length - 1) {
|
|
207
|
+
current[part] = null;
|
|
208
|
+
} else {
|
|
209
|
+
current[part] = current[part] || {};
|
|
210
|
+
current = current[part];
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
function printNode(node, prefix = "", parentPath = "") {
|
|
215
|
+
const keys = Object.keys(node).sort();
|
|
216
|
+
let lines = [];
|
|
217
|
+
keys.forEach((key, idx) => {
|
|
218
|
+
const isLast = idx === keys.length - 1;
|
|
219
|
+
const branch = isLast ? "\u2514\u2500\u2500 " : "\u251C\u2500\u2500 ";
|
|
220
|
+
const currentPath = parentPath ? parentPath + "/" + key : key;
|
|
221
|
+
if (node[key] === null) {
|
|
222
|
+
lines.push(prefix + branch + key + " [" + (hashMap[currentPath] || "") + "]");
|
|
223
|
+
} else {
|
|
224
|
+
lines.push(prefix + branch + key + "/");
|
|
225
|
+
lines = lines.concat(printNode(node[key], prefix + (isLast ? " " : "\u2502 "), currentPath));
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
return lines;
|
|
229
|
+
}
|
|
230
|
+
return printNode(tree, "", "").join("\n");
|
|
231
|
+
}
|
|
232
|
+
module2.exports.getFileTreeString = getFileTreeString;
|
|
233
|
+
var delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
234
|
+
module2.exports.delay = delay;
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
// src/git-diff.js
|
|
239
|
+
var git_diff_exports = {};
|
|
240
|
+
__export(git_diff_exports, {
|
|
241
|
+
CACHE_DIR: () => CACHE_DIR,
|
|
242
|
+
DIFF_OUTPUT: () => DIFF_OUTPUT,
|
|
243
|
+
DIFF_OUTPUT_RELATIVE: () => DIFF_OUTPUT_RELATIVE,
|
|
244
|
+
GPT_DIFF_OUTPUT: () => GPT_DIFF_OUTPUT,
|
|
245
|
+
GPT_DIFF_OUTPUT_RELATIVE: () => GPT_DIFF_OUTPUT_RELATIVE,
|
|
246
|
+
default: () => git_diff_default,
|
|
247
|
+
gitDiff: () => runGitDiff,
|
|
248
|
+
mainGitDiff: () => mainGitDiff
|
|
249
|
+
});
|
|
250
|
+
module.exports = __toCommonJS(git_diff_exports);
|
|
251
|
+
init_cjs_shims();
|
|
252
|
+
var import_child_process = require("child_process");
|
|
253
|
+
var import_fs_extra2 = __toESM(require("fs-extra"), 1);
|
|
254
|
+
var import_upath2 = __toESM(require("upath"), 1);
|
|
255
|
+
var import_url = require("url");
|
|
256
|
+
var import_binary_collections_config = __toESM(require_binary_collections_config(), 1);
|
|
257
|
+
|
|
258
|
+
// src/utils/chatgpt.js
|
|
259
|
+
init_cjs_shims();
|
|
260
|
+
var import_fs_extra = __toESM(require("fs-extra"), 1);
|
|
261
|
+
var import_puppeteer_extra = __toESM(require("puppeteer-extra"), 1);
|
|
262
|
+
var import_puppeteer_extra_plugin_stealth = __toESM(require("puppeteer-extra-plugin-stealth"), 1);
|
|
263
|
+
var import_upath = __toESM(require("upath"), 1);
|
|
264
|
+
var COOKIE_DIR = import_upath.default.join(process.cwd(), "tmp", "cookies");
|
|
265
|
+
var DEFAULT_COOKIE_PATH = import_upath.default.join(COOKIE_DIR, "cookies.json");
|
|
266
|
+
var NAVIGATION_TIMEOUT_MS = 9e4;
|
|
267
|
+
var NETWORK_IDLE_TIMEOUT_MS = 15e3;
|
|
268
|
+
var MAX_INLINE_QUESTION_FILE_BYTES = 2 * 1024;
|
|
269
|
+
import_fs_extra.default.ensureDirSync(COOKIE_DIR);
|
|
270
|
+
async function gotoWithFallback(page, url) {
|
|
271
|
+
await page.goto(url, { waitUntil: "domcontentloaded", timeout: NAVIGATION_TIMEOUT_MS });
|
|
272
|
+
try {
|
|
273
|
+
await page.waitForNetworkIdle({ idleTime: 1e3, timeout: NETWORK_IDLE_TIMEOUT_MS });
|
|
274
|
+
} catch {
|
|
275
|
+
}
|
|
13
276
|
}
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
console.log("Usage:");
|
|
18
|
-
console.log(" git-diff FILE Show staged diff of specified file");
|
|
19
|
-
console.log(" git-diff --staged-only Show staged diff of all files");
|
|
20
|
-
console.log(" git-diff -s | -S Same as --staged-only");
|
|
21
|
-
console.log(" git-diff --help | -h Show this help message");
|
|
22
|
-
console.log("");
|
|
23
|
-
console.log(`Output is saved to: ${OUTPUT}`);
|
|
24
|
-
process.exit(0);
|
|
277
|
+
async function saveCookies(page, path3 = DEFAULT_COOKIE_PATH) {
|
|
278
|
+
const cookies = await page.cookies();
|
|
279
|
+
import_fs_extra.default.writeFileSync(path3, JSON.stringify(cookies, null, 2));
|
|
25
280
|
}
|
|
26
|
-
function
|
|
281
|
+
function getCookiePathForUrl(url) {
|
|
282
|
+
try {
|
|
283
|
+
const { hostname } = new URL(url);
|
|
284
|
+
return import_upath.default.join(COOKIE_DIR, `cookies_${hostname}.json`);
|
|
285
|
+
} catch {
|
|
286
|
+
return DEFAULT_COOKIE_PATH;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
async function navigatePage(page, url) {
|
|
290
|
+
const cookiePath = getCookiePathForUrl(url);
|
|
291
|
+
const cookies = loadCookies(cookiePath);
|
|
292
|
+
if (cookies) {
|
|
293
|
+
await page.setCookie(...cookies);
|
|
294
|
+
}
|
|
295
|
+
await gotoWithFallback(page, url);
|
|
296
|
+
await page.evaluate(() => {
|
|
297
|
+
window.__domStillUpdating = true;
|
|
298
|
+
if (window.__domObserver) {
|
|
299
|
+
window.__domObserver.disconnect();
|
|
300
|
+
}
|
|
301
|
+
window.__domObserver = new MutationObserver(() => {
|
|
302
|
+
window.__lastDomMutation = Date.now();
|
|
303
|
+
});
|
|
304
|
+
window.__lastDomMutation = Date.now();
|
|
305
|
+
window.__domObserver.observe(document.body, {
|
|
306
|
+
childList: true,
|
|
307
|
+
subtree: true,
|
|
308
|
+
attributes: true,
|
|
309
|
+
characterData: true
|
|
310
|
+
});
|
|
311
|
+
setTimeout(() => {
|
|
312
|
+
window.__domStillUpdating = false;
|
|
313
|
+
window.__domObserver.disconnect();
|
|
314
|
+
}, 3e4);
|
|
315
|
+
});
|
|
316
|
+
const waitForDomIdle = async (idleMs = 1e3, timeout = 1e4) => {
|
|
317
|
+
const start = Date.now();
|
|
318
|
+
while (Date.now() - start < timeout) {
|
|
319
|
+
const lastMutation = await page.evaluate(() => window.__lastDomMutation);
|
|
320
|
+
const idle = Date.now() - lastMutation;
|
|
321
|
+
if (idle >= idleMs) {
|
|
322
|
+
return true;
|
|
323
|
+
}
|
|
324
|
+
await new Promise((r) => setTimeout(r, 200));
|
|
325
|
+
}
|
|
326
|
+
throw new Error("DOM did not stabilize within timeout");
|
|
327
|
+
};
|
|
328
|
+
return { waitForDomIdle };
|
|
329
|
+
}
|
|
330
|
+
function loadCookies(cookieFilePath = DEFAULT_COOKIE_PATH) {
|
|
331
|
+
if (!import_fs_extra.default.existsSync(cookieFilePath)) return null;
|
|
332
|
+
return JSON.parse(import_fs_extra.default.readFileSync(cookieFilePath));
|
|
333
|
+
}
|
|
334
|
+
async function writeQuestion(page, question) {
|
|
335
|
+
const promptTextarea = await page.waitForSelector("#prompt-textarea", { timeout: 3e4 });
|
|
336
|
+
if (!promptTextarea) {
|
|
337
|
+
console.log(
|
|
338
|
+
"Cannot find the prompt input on the webpage. Please check whether you have access to chat.openai.com without logging in via your browser."
|
|
339
|
+
);
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
await page.evaluate((text) => {
|
|
343
|
+
const promptEl = document.querySelector("#prompt-textarea");
|
|
344
|
+
if (!promptEl) {
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
promptEl.focus();
|
|
348
|
+
promptEl.innerHTML = "";
|
|
349
|
+
const lines = String(text).split("\n");
|
|
350
|
+
for (const line of lines) {
|
|
351
|
+
const p = document.createElement("p");
|
|
352
|
+
p.textContent = line;
|
|
353
|
+
promptEl.appendChild(p);
|
|
354
|
+
}
|
|
355
|
+
promptEl.dispatchEvent(new InputEvent("beforeinput", { bubbles: true, inputType: "insertFromPaste", data: text }));
|
|
356
|
+
promptEl.dispatchEvent(new InputEvent("input", { bubbles: true, inputType: "insertFromPaste", data: text }));
|
|
357
|
+
promptEl.dispatchEvent(new Event("change", { bubbles: true }));
|
|
358
|
+
}, question);
|
|
359
|
+
const hasPromptText = await page.evaluate(() => {
|
|
360
|
+
const promptEl = document.querySelector("#prompt-textarea");
|
|
361
|
+
return Boolean(promptEl && promptEl.textContent && promptEl.textContent.trim().length > 0);
|
|
362
|
+
});
|
|
363
|
+
if (!hasPromptText) {
|
|
364
|
+
console.log("Prompt state not updated by DOM injection. Falling back to keyboard insertText.");
|
|
365
|
+
await promptTextarea.click({ clickCount: 1 });
|
|
366
|
+
await page.keyboard.down("Control");
|
|
367
|
+
await page.keyboard.press("KeyA");
|
|
368
|
+
await page.keyboard.up("Control");
|
|
369
|
+
await page.keyboard.insertText(question);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
async function clickSubmitButton(page) {
|
|
373
|
+
console.log("Attempting to click the submit button...");
|
|
374
|
+
try {
|
|
375
|
+
const userMessageCountBefore = await page.$$eval('[data-message-author-role="user"]', (elements) => elements.length);
|
|
376
|
+
const waitForSubmit = async (timeout = 5e3) => {
|
|
377
|
+
try {
|
|
378
|
+
await page.waitForFunction(
|
|
379
|
+
(previousCount) => {
|
|
380
|
+
const currentCount = document.querySelectorAll('[data-message-author-role="user"]').length;
|
|
381
|
+
return currentCount > previousCount;
|
|
382
|
+
},
|
|
383
|
+
{ timeout },
|
|
384
|
+
userMessageCountBefore
|
|
385
|
+
);
|
|
386
|
+
return true;
|
|
387
|
+
} catch {
|
|
388
|
+
return false;
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
await page.waitForFunction(() => {
|
|
392
|
+
const candidates = [
|
|
393
|
+
document.querySelector('[data-testid="fruitjuice-send-button"]'),
|
|
394
|
+
document.querySelector("#composer-submit-button"),
|
|
395
|
+
document.querySelector('[data-testid="send-button"]')
|
|
396
|
+
].filter(Boolean);
|
|
397
|
+
return candidates.some((button) => {
|
|
398
|
+
const isDisabled = button.disabled || button.getAttribute("aria-disabled") === "true";
|
|
399
|
+
const isVisible = button.offsetParent !== null;
|
|
400
|
+
return !isDisabled && isVisible;
|
|
401
|
+
});
|
|
402
|
+
}, { timeout: 5e3 }).catch(() => {
|
|
403
|
+
});
|
|
404
|
+
const buttonDetails = await page.evaluate(() => {
|
|
405
|
+
const selectors = [
|
|
406
|
+
'[data-testid="fruitjuice-send-button"]',
|
|
407
|
+
"#composer-submit-button",
|
|
408
|
+
'[data-testid="send-button"]'
|
|
409
|
+
];
|
|
410
|
+
const details = selectors.map((selector) => {
|
|
411
|
+
const el = document.querySelector(selector);
|
|
412
|
+
const exists = Boolean(el);
|
|
413
|
+
const disabled = exists ? Boolean(el.disabled || el.getAttribute("aria-disabled") === "true") : null;
|
|
414
|
+
const visible = exists ? el.offsetParent !== null : null;
|
|
415
|
+
return { selector, exists, disabled, visible };
|
|
416
|
+
});
|
|
417
|
+
return details;
|
|
418
|
+
});
|
|
419
|
+
console.log(`Submit button details: ${JSON.stringify(buttonDetails)}`);
|
|
420
|
+
const clickable = buttonDetails.find((item) => item.exists && item.visible && item.disabled === false);
|
|
421
|
+
const selectedSelector = clickable ? clickable.selector : null;
|
|
422
|
+
if (selectedSelector) {
|
|
423
|
+
await page.click(selectedSelector);
|
|
424
|
+
console.log(`Clicked submit button selector: ${selectedSelector}`);
|
|
425
|
+
if (await waitForSubmit(5e3)) {
|
|
426
|
+
console.log("Submission detected after selector click.");
|
|
427
|
+
return true;
|
|
428
|
+
}
|
|
429
|
+
const forcedClickWorked = await page.evaluate((selector) => {
|
|
430
|
+
const el = document.querySelector(selector);
|
|
431
|
+
if (!el) {
|
|
432
|
+
return false;
|
|
433
|
+
}
|
|
434
|
+
el.click();
|
|
435
|
+
return true;
|
|
436
|
+
}, selectedSelector);
|
|
437
|
+
if (forcedClickWorked) {
|
|
438
|
+
console.log(`Forced DOM click on selector: ${selectedSelector}`);
|
|
439
|
+
if (await waitForSubmit(5e3)) {
|
|
440
|
+
console.log("Submission detected after forced DOM click.");
|
|
441
|
+
return true;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
console.log("Submit button path did not submit. Trying Enter key fallback on prompt.");
|
|
446
|
+
await page.focus("#prompt-textarea");
|
|
447
|
+
await page.keyboard.press("Enter");
|
|
448
|
+
if (await waitForSubmit(5e3)) {
|
|
449
|
+
console.log("Submission detected after Enter key fallback.");
|
|
450
|
+
return true;
|
|
451
|
+
}
|
|
452
|
+
const didRequestSubmit = await page.evaluate(() => {
|
|
453
|
+
const prompt = document.querySelector("#prompt-textarea");
|
|
454
|
+
if (!prompt) {
|
|
455
|
+
return false;
|
|
456
|
+
}
|
|
457
|
+
const form = prompt.closest("form");
|
|
458
|
+
if (!form) {
|
|
459
|
+
return false;
|
|
460
|
+
}
|
|
461
|
+
if (typeof form.requestSubmit === "function") {
|
|
462
|
+
form.requestSubmit();
|
|
463
|
+
} else {
|
|
464
|
+
form.submit();
|
|
465
|
+
}
|
|
466
|
+
return true;
|
|
467
|
+
});
|
|
468
|
+
if (didRequestSubmit) {
|
|
469
|
+
console.log("Triggered form submit fallback.");
|
|
470
|
+
if (await waitForSubmit(5e3)) {
|
|
471
|
+
console.log("Submission detected after form submit fallback.");
|
|
472
|
+
return true;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
console.log("Failed to submit prompt after all strategies.");
|
|
476
|
+
return false;
|
|
477
|
+
} catch (e) {
|
|
478
|
+
console.log(`Failed to click the send button: ${e}`);
|
|
479
|
+
return false;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
var lastMessageId = null;
|
|
483
|
+
var messageCount = 0;
|
|
484
|
+
var is_streaming = false;
|
|
485
|
+
function sleep(ms) {
|
|
486
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
487
|
+
}
|
|
488
|
+
async function waitForInitialResponse(page, timeout = 3e4) {
|
|
489
|
+
const startTime = Date.now();
|
|
490
|
+
while (Date.now() - startTime < timeout) {
|
|
491
|
+
const assistantMessages = await page.$$('[data-message-author-role="assistant"]');
|
|
492
|
+
const currentMessageCount = assistantMessages.length;
|
|
493
|
+
if (currentMessageCount > messageCount) {
|
|
494
|
+
const lastMessage = assistantMessages[assistantMessages.length - 1];
|
|
495
|
+
const isThinking = await lastMessage.$(".result-thinking");
|
|
496
|
+
if (!isThinking) {
|
|
497
|
+
lastMessageId = await page.evaluate((element) => element.getAttribute("data-message-id"), lastMessage);
|
|
498
|
+
messageCount = currentMessageCount;
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
await sleep(100);
|
|
503
|
+
}
|
|
504
|
+
console.log("Timed out waiting for the initial response.");
|
|
505
|
+
}
|
|
506
|
+
async function handleStreamingResponse(page, outputFile = import_upath.default.join(process.cwd(), "tmp/response.txt")) {
|
|
507
|
+
let previousText = "";
|
|
508
|
+
let completeResponse = "";
|
|
509
|
+
let newContentDetected = false;
|
|
510
|
+
while (!newContentDetected) {
|
|
511
|
+
const assistantMessages = await page.$$('[data-message-author-role="assistant"]');
|
|
512
|
+
if (assistantMessages.length > 0) {
|
|
513
|
+
const lastMessage = assistantMessages[assistantMessages.length - 1];
|
|
514
|
+
const currentMessageId = await page.evaluate((element) => element.getAttribute("data-message-id"), lastMessage);
|
|
515
|
+
if (currentMessageId === lastMessageId) {
|
|
516
|
+
const currentText = await page.evaluate((element) => element.textContent, lastMessage);
|
|
517
|
+
console.log(`Current text: ${currentText}`);
|
|
518
|
+
if (currentText !== previousText) {
|
|
519
|
+
if (is_streaming) {
|
|
520
|
+
process.stdout.write(currentText.slice(previousText.length));
|
|
521
|
+
} else {
|
|
522
|
+
completeResponse += currentText.slice(previousText.length);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
previousText = currentText;
|
|
526
|
+
const isStreaming = await lastMessage.$(".result-streaming");
|
|
527
|
+
if (!isStreaming) {
|
|
528
|
+
newContentDetected = true;
|
|
529
|
+
}
|
|
530
|
+
} else {
|
|
531
|
+
lastMessageId = currentMessageId;
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
await sleep(100);
|
|
535
|
+
}
|
|
536
|
+
if (!is_streaming) {
|
|
537
|
+
console.log(completeResponse.trim());
|
|
538
|
+
console.log("\n\n");
|
|
539
|
+
import_fs_extra.default.ensureDirSync(import_upath.default.dirname(outputFile));
|
|
540
|
+
import_fs_extra.default.writeFileSync(outputFile, completeResponse.trim());
|
|
541
|
+
console.log(`Response saved to ${outputFile}`);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
async function isLoggedIn(page) {
|
|
545
|
+
const result = await page.evaluate(() => {
|
|
546
|
+
const loginButton = document.querySelector('[data-testid="login-button"]');
|
|
547
|
+
return !(loginButton && loginButton.offsetParent !== null);
|
|
548
|
+
});
|
|
549
|
+
return result === true;
|
|
550
|
+
}
|
|
551
|
+
async function createBrowser(browserOptions = {}) {
|
|
552
|
+
const windowsChromeExecutable = "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe";
|
|
553
|
+
const hasWindowsChrome = process.platform === "win32" && import_fs_extra.default.existsSync(windowsChromeExecutable);
|
|
554
|
+
const defaultOptions = {
|
|
555
|
+
headless: false,
|
|
556
|
+
defaultViewport: null,
|
|
557
|
+
userDataDir: import_upath.default.join(process.cwd(), "tmp/puppeteer-profile"),
|
|
558
|
+
// Windows-specific options to handle browser launch issues
|
|
559
|
+
args: [
|
|
560
|
+
"--start-maximized",
|
|
561
|
+
"--no-sandbox",
|
|
562
|
+
"--disable-setuid-sandbox",
|
|
563
|
+
"--disable-dev-shm-usage",
|
|
564
|
+
"--disable-accelerated-2d-canvas",
|
|
565
|
+
"--no-first-run",
|
|
566
|
+
"--no-zygote",
|
|
567
|
+
"--disable-gpu",
|
|
568
|
+
"--disable-background-timer-throttling",
|
|
569
|
+
"--disable-backgrounding-occluded-windows",
|
|
570
|
+
"--disable-renderer-backgrounding"
|
|
571
|
+
],
|
|
572
|
+
ignoreDefaultArgs: ["--disable-extensions"],
|
|
573
|
+
...hasWindowsChrome && {
|
|
574
|
+
// Prefer local Chrome installation when present on Windows.
|
|
575
|
+
executablePath: windowsChromeExecutable
|
|
576
|
+
}
|
|
577
|
+
};
|
|
578
|
+
try {
|
|
579
|
+
return await import_puppeteer_extra.default.use((0, import_puppeteer_extra_plugin_stealth.default)()).launch({ ...defaultOptions, ...browserOptions });
|
|
580
|
+
} catch (_error) {
|
|
581
|
+
console.error("Failed to launch browser with default options. Trying fallback options...");
|
|
27
582
|
try {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
583
|
+
return await import_puppeteer_extra.default.use((0, import_puppeteer_extra_plugin_stealth.default)()).launch({
|
|
584
|
+
headless: browserOptions.headless || false,
|
|
585
|
+
defaultViewport: null,
|
|
586
|
+
args: ["--start-maximized", "--no-sandbox", "--disable-setuid-sandbox"],
|
|
587
|
+
ignoreDefaultArgs: false,
|
|
588
|
+
...hasWindowsChrome && {
|
|
589
|
+
executablePath: windowsChromeExecutable
|
|
590
|
+
},
|
|
591
|
+
...browserOptions
|
|
592
|
+
});
|
|
593
|
+
} catch (fallbackError) {
|
|
594
|
+
console.error("Browser launch failed completely. Common solutions:");
|
|
595
|
+
console.error("1. Install Google Chrome if not installed");
|
|
596
|
+
console.error("2. Update Node.js to the latest version");
|
|
597
|
+
console.error("3. Try running: npm install puppeteer --force");
|
|
598
|
+
console.error("4. Check if antivirus is blocking browser launch");
|
|
599
|
+
throw new Error(`Browser launch failed: ${fallbackError.message}`);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
async function loginToChatGpt() {
|
|
604
|
+
const browser = await createBrowser({ headless: false });
|
|
605
|
+
const page = (await browser.pages()).length > 0 ? (await browser.pages())[0] : await browser.newPage();
|
|
606
|
+
const url = "https://chat.openai.com";
|
|
607
|
+
const navigate = await navigatePage(page, url);
|
|
608
|
+
await navigate.waitForDomIdle(2e3, 1e4);
|
|
609
|
+
const loginButtonExists = await page.evaluate(() => {
|
|
610
|
+
return document.querySelector('[data-testid="login-button"]') !== null;
|
|
611
|
+
});
|
|
612
|
+
if (loginButtonExists) {
|
|
613
|
+
console.log("Login button found, clicking to log in...");
|
|
614
|
+
await page.click('[data-testid="login-button"]');
|
|
615
|
+
await page.waitForNavigation({ waitUntil: "domcontentloaded", timeout: NAVIGATION_TIMEOUT_MS });
|
|
616
|
+
try {
|
|
617
|
+
await page.waitForNetworkIdle({ idleTime: 1e3, timeout: NETWORK_IDLE_TIMEOUT_MS });
|
|
618
|
+
} catch {
|
|
619
|
+
}
|
|
620
|
+
console.log("Login process completed.");
|
|
621
|
+
} else {
|
|
622
|
+
console.log("No login required - user appears to be already logged in.");
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
async function runChatGpt(chatgptOptions = {}) {
|
|
626
|
+
const headless = chatgptOptions.headless !== void 0 ? chatgptOptions.headless : true;
|
|
627
|
+
const questionFile = chatgptOptions.questionFile;
|
|
628
|
+
let question = chatgptOptions.question;
|
|
629
|
+
let shouldUploadQuestionFile = Boolean(questionFile);
|
|
630
|
+
const responseFile = chatgptOptions.responseFile || import_upath.default.join(process.cwd(), "tmp", "response.txt");
|
|
631
|
+
const noInputProvided = !question && !questionFile;
|
|
632
|
+
const questionIsEmpty = question && question.trim().length === 0;
|
|
633
|
+
const questionFileIsEmpty = questionFile && questionFile.trim().length === 0;
|
|
634
|
+
if (noInputProvided || questionIsEmpty || questionFileIsEmpty) {
|
|
635
|
+
throw new Error("You must provide a question or a question file.");
|
|
636
|
+
}
|
|
637
|
+
if (!question && questionFile) {
|
|
638
|
+
if (!import_fs_extra.default.existsSync(questionFile)) {
|
|
639
|
+
throw new Error(`Question file does not exist: ${questionFile}`);
|
|
640
|
+
}
|
|
641
|
+
const questionFileStats = import_fs_extra.default.statSync(questionFile);
|
|
642
|
+
if (questionFileStats.size <= MAX_INLINE_QUESTION_FILE_BYTES) {
|
|
643
|
+
question = import_fs_extra.default.readFileSync(questionFile, "utf8").trim();
|
|
644
|
+
if (!question) {
|
|
645
|
+
throw new Error("Question file is empty.");
|
|
646
|
+
}
|
|
647
|
+
shouldUploadQuestionFile = false;
|
|
648
|
+
console.log(
|
|
649
|
+
`Question file is ${questionFileStats.size} bytes (<= ${MAX_INLINE_QUESTION_FILE_BYTES}). Sending as text prompt.`
|
|
650
|
+
);
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
let browser;
|
|
654
|
+
try {
|
|
655
|
+
browser = await createBrowser({ headless });
|
|
656
|
+
} catch (error) {
|
|
657
|
+
console.error("Error running ChatGPT:", error);
|
|
658
|
+
console.error("\nTroubleshooting steps:");
|
|
659
|
+
console.error("1. Make sure Google Chrome is installed");
|
|
660
|
+
console.error("2. Try running: yarn add puppeteer --force");
|
|
661
|
+
console.error("3. Check if your antivirus is blocking the browser");
|
|
662
|
+
console.error("4. Close any running Chrome instances and try again");
|
|
663
|
+
throw error;
|
|
664
|
+
}
|
|
665
|
+
const allPages = await browser.pages();
|
|
666
|
+
const page = allPages.length > 0 ? allPages[0] : await browser.newPage();
|
|
667
|
+
await page.bringToFront();
|
|
668
|
+
if (allPages.length > 1) {
|
|
669
|
+
for (const p of allPages) {
|
|
670
|
+
if (p !== page) {
|
|
671
|
+
await p.close();
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
try {
|
|
676
|
+
const url = "https://chat.openai.com";
|
|
677
|
+
const navigate = await navigatePage(page, url);
|
|
678
|
+
await navigate.waitForDomIdle(2e3, 15e3);
|
|
679
|
+
try {
|
|
680
|
+
const tempChatButton = await page.$('button[aria-label="Turn on temporary chat"]');
|
|
681
|
+
if (tempChatButton) {
|
|
682
|
+
await page.evaluate((el) => el.click(), tempChatButton);
|
|
683
|
+
console.log("Successfully clicked temporary chat button");
|
|
684
|
+
await navigate.waitForDomIdle(1e3, 1e4);
|
|
685
|
+
} else {
|
|
686
|
+
console.log("Temporary chat button not found, proceeding without it.");
|
|
687
|
+
}
|
|
688
|
+
} catch (error) {
|
|
689
|
+
console.log(`Failed to click temporary chat button: ${error.message}`);
|
|
690
|
+
}
|
|
691
|
+
if (question) {
|
|
692
|
+
await writeQuestion(page, question);
|
|
693
|
+
const didSubmit = await clickSubmitButton(page);
|
|
694
|
+
if (!didSubmit) {
|
|
695
|
+
throw new Error("Prompt was not submitted. The composer button may be disabled or blocked.");
|
|
696
|
+
}
|
|
697
|
+
await navigate.waitForDomIdle(1e3, 3e4);
|
|
698
|
+
await waitForInitialResponse(page);
|
|
699
|
+
await handleStreamingResponse(page, responseFile);
|
|
700
|
+
await saveCookies(page, getCookiePathForUrl(url));
|
|
701
|
+
} else if (shouldUploadQuestionFile && questionFile) {
|
|
702
|
+
await navigate.waitForDomIdle(2e3, 1e4);
|
|
703
|
+
const isUserLoggedIn = await isLoggedIn(page);
|
|
704
|
+
console.log(`Login status: ${isUserLoggedIn ? "Logged in" : "Not logged in"}`);
|
|
705
|
+
if (!isUserLoggedIn) {
|
|
706
|
+
console.log(
|
|
707
|
+
"Not logged in. Please log in to ChatGPT in the browser window, then close it and run the command again."
|
|
708
|
+
);
|
|
709
|
+
return loginToChatGpt();
|
|
710
|
+
}
|
|
711
|
+
const plusButtonExists = await page.evaluate(() => {
|
|
712
|
+
const button = document.querySelector('[data-testid="composer-plus-btn"]');
|
|
713
|
+
return button !== null;
|
|
714
|
+
});
|
|
715
|
+
if (plusButtonExists) {
|
|
716
|
+
await page.click('[data-testid="composer-plus-btn"]');
|
|
717
|
+
await sleep(500);
|
|
718
|
+
const menuItems = await page.$$('[role="menuitem"]');
|
|
719
|
+
let clicked = false;
|
|
720
|
+
for (const item of menuItems) {
|
|
721
|
+
const text = await page.evaluate((el) => el.innerText, item);
|
|
722
|
+
if (text && text.includes("Add photos") && text.includes("files")) {
|
|
723
|
+
await item.hover();
|
|
724
|
+
clicked = true;
|
|
725
|
+
break;
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
if (!clicked) {
|
|
729
|
+
console.log('Could not find the "Add photos & files" menu item.');
|
|
730
|
+
return;
|
|
39
731
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
732
|
+
try {
|
|
733
|
+
await sleep(1e3);
|
|
734
|
+
const fileInput = await page.waitForSelector('input[type="file"]', { timeout: 1e4 });
|
|
735
|
+
if (fileInput) {
|
|
736
|
+
console.log(`Uploading file: ${questionFile}`);
|
|
737
|
+
await fileInput.uploadFile(questionFile);
|
|
738
|
+
await navigate.waitForDomIdle(2e3, 15e3);
|
|
739
|
+
console.log("File uploaded successfully");
|
|
740
|
+
const didSubmit = await clickSubmitButton(page);
|
|
741
|
+
if (!didSubmit) {
|
|
742
|
+
throw new Error("Prompt was not submitted after file upload.");
|
|
743
|
+
}
|
|
744
|
+
await navigate.waitForDomIdle(1e3, 3e4);
|
|
745
|
+
await waitForInitialResponse(page);
|
|
746
|
+
await handleStreamingResponse(page, responseFile);
|
|
747
|
+
} else {
|
|
748
|
+
console.log("Could not find file input element");
|
|
749
|
+
}
|
|
750
|
+
} catch (error) {
|
|
751
|
+
console.log(`Error uploading file: ${error.message}`);
|
|
50
752
|
}
|
|
51
|
-
|
|
753
|
+
} else {
|
|
754
|
+
console.log('Could not find the [data-testid="composer-plus-btn"] button.');
|
|
755
|
+
}
|
|
52
756
|
}
|
|
757
|
+
} finally {
|
|
758
|
+
if (browser) {
|
|
759
|
+
await browser.close();
|
|
760
|
+
}
|
|
761
|
+
}
|
|
53
762
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
763
|
+
|
|
764
|
+
// src/git-diff.js
|
|
765
|
+
var import_utils = __toESM(require_utils(), 1);
|
|
766
|
+
var __filename2 = (0, import_url.fileURLToPath)(importMetaUrl);
|
|
767
|
+
var __dirname = import_upath2.default.dirname(__filename2);
|
|
768
|
+
var DIFF_OUTPUT = (0, import_binary_collections_config.getTempPath)("git-diff.txt");
|
|
769
|
+
var GPT_DIFF_OUTPUT = (0, import_binary_collections_config.getTempPath)("gpt-question.txt");
|
|
770
|
+
var CACHE_DIR = import_upath2.default.dirname(DIFF_OUTPUT);
|
|
771
|
+
var DIFF_OUTPUT_RELATIVE = import_upath2.default.relative(process.cwd(), DIFF_OUTPUT);
|
|
772
|
+
var GPT_DIFF_OUTPUT_RELATIVE = import_upath2.default.relative(process.cwd(), GPT_DIFF_OUTPUT);
|
|
773
|
+
if (!import_fs_extra2.default.existsSync(CACHE_DIR)) {
|
|
774
|
+
import_fs_extra2.default.mkdirSync(CACHE_DIR, { recursive: true });
|
|
60
775
|
}
|
|
61
|
-
|
|
62
|
-
|
|
776
|
+
function showHelp() {
|
|
777
|
+
console.log("\u{1F4DD} Git Diff Helper");
|
|
778
|
+
console.log("\u{1F4C4} Usage:");
|
|
779
|
+
console.log(" \u{1F4C2} git-diff FILE Show staged diff of specified file");
|
|
780
|
+
console.log(" \u{1F4C2} git-diff --staged-only Show staged diff of all files");
|
|
781
|
+
console.log(" \u{1F4C2} git-diff -s | -S Same as --staged-only");
|
|
782
|
+
console.log(" \u{1F4C2} git-diff --ai Run ChatGPT automation for commit message");
|
|
783
|
+
console.log(" \u{1F4C2} git-diff --help | -h Show this help message");
|
|
784
|
+
console.log("");
|
|
785
|
+
console.log(`\u{1F4BE} Output is saved to: ${DIFF_OUTPUT_RELATIVE}`);
|
|
786
|
+
console.log(`\u{1F916} GPT prompt is saved to: ${GPT_DIFF_OUTPUT_RELATIVE}`);
|
|
787
|
+
process.exit(0);
|
|
63
788
|
}
|
|
64
|
-
|
|
65
|
-
|
|
789
|
+
function runGitDiff(command, successMessage, errorMessage) {
|
|
790
|
+
try {
|
|
791
|
+
console.log(`\u{1F50D} [i] Running command: ${command}`);
|
|
792
|
+
const result = (0, import_child_process.execSync)(command, {
|
|
793
|
+
encoding: "utf8",
|
|
794
|
+
maxBuffer: 1024 * 1024 * 10
|
|
795
|
+
// 10MB buffer to handle large diffs
|
|
796
|
+
});
|
|
797
|
+
if (!result || result.trim() === "") {
|
|
798
|
+
console.log(`\u2139\uFE0F [i] No changes found for the specified criteria`);
|
|
799
|
+
import_fs_extra2.default.writeFileSync(DIFF_OUTPUT, "# No changes found\n");
|
|
800
|
+
console.log(`\u2705 Empty diff saved to "${DIFF_OUTPUT_RELATIVE}"`);
|
|
801
|
+
return;
|
|
802
|
+
}
|
|
803
|
+
import_fs_extra2.default.writeFileSync(DIFF_OUTPUT, result);
|
|
804
|
+
import_fs_extra2.default.writeFileSync(
|
|
805
|
+
GPT_DIFF_OUTPUT,
|
|
806
|
+
`Hello, ChatGPT!
|
|
807
|
+
Can you create a conventional commit message by diff content below:
|
|
808
|
+
|
|
809
|
+
\`\`\`${result}
|
|
810
|
+
\`\`\`
|
|
811
|
+
|
|
812
|
+
Give me result as codeblock with language "text" only.
|
|
813
|
+
|
|
814
|
+
Thank you!`
|
|
815
|
+
);
|
|
816
|
+
console.log(`\u2705 ${successMessage}`);
|
|
817
|
+
console.log(`\u{1F4BE} GPT diff prompt saved to "${GPT_DIFF_OUTPUT_RELATIVE}"`);
|
|
818
|
+
} catch (error) {
|
|
819
|
+
console.error(`\u274C ${errorMessage}`);
|
|
820
|
+
console.error(`\u{1F4DD} Command: ${command}`);
|
|
821
|
+
console.error(`\u26A0\uFE0F Error: ${error.message}`);
|
|
822
|
+
if (error.message.includes("not a git repository")) {
|
|
823
|
+
console.error("\u{1F6A7} Make sure you are in a git repository");
|
|
824
|
+
}
|
|
825
|
+
process.exit(1);
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
async function mainGitDiff() {
|
|
829
|
+
const args = (0, import_utils.getArgs)();
|
|
830
|
+
const positional = args._ || [];
|
|
831
|
+
if (args.help || args.h) {
|
|
832
|
+
showHelp();
|
|
833
|
+
}
|
|
834
|
+
if (args["staged-only"] || args.s || args.S) {
|
|
835
|
+
runGitDiff(
|
|
836
|
+
"git --no-pager diff --staged",
|
|
837
|
+
`Full staged diff saved to "${DIFF_OUTPUT_RELATIVE}"`,
|
|
838
|
+
"Failed to save staged diff"
|
|
839
|
+
);
|
|
840
|
+
} else {
|
|
66
841
|
const file = positional[0];
|
|
67
842
|
if (!file) {
|
|
68
|
-
|
|
843
|
+
runGitDiff(
|
|
844
|
+
"git --no-pager diff",
|
|
845
|
+
`Full staged diff saved to "${DIFF_OUTPUT_RELATIVE}"`,
|
|
846
|
+
"Failed to save all diff's"
|
|
847
|
+
);
|
|
848
|
+
} else {
|
|
849
|
+
runGitDiff(
|
|
850
|
+
`git --no-pager diff --cached -- "${file}"`,
|
|
851
|
+
`Staged diff of "${file}" saved to "${DIFF_OUTPUT_RELATIVE}"`,
|
|
852
|
+
`Failed to generate diff for "${file}"`
|
|
853
|
+
);
|
|
69
854
|
}
|
|
70
|
-
|
|
71
|
-
|
|
855
|
+
}
|
|
856
|
+
if (args.ai) {
|
|
857
|
+
try {
|
|
858
|
+
await runChatGpt({ headless: true, questionFile: GPT_DIFF_OUTPUT });
|
|
859
|
+
} catch (error) {
|
|
860
|
+
console.error("\u274C Error running ChatGPT:", error.message);
|
|
861
|
+
console.error("\u{1F4A1} Try running with visible browser mode or check if Chrome is installed");
|
|
72
862
|
}
|
|
863
|
+
} else {
|
|
864
|
+
console.log("\u{1F4A1} Tip: Use --ai flag to generate commit message with ChatGPT");
|
|
865
|
+
}
|
|
73
866
|
}
|
|
867
|
+
var git_diff_default = runGitDiff;
|
|
868
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
869
|
+
0 && (module.exports = {
|
|
870
|
+
CACHE_DIR,
|
|
871
|
+
DIFF_OUTPUT,
|
|
872
|
+
DIFF_OUTPUT_RELATIVE,
|
|
873
|
+
GPT_DIFF_OUTPUT,
|
|
874
|
+
GPT_DIFF_OUTPUT_RELATIVE,
|
|
875
|
+
gitDiff,
|
|
876
|
+
mainGitDiff
|
|
877
|
+
});
|