bisync-cli 0.0.12 → 0.0.14
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/dist/bisync.js +1551 -27
- package/package.json +6 -2
package/dist/bisync.js
CHANGED
|
@@ -1,15 +1,159 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
9
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
10
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
11
|
+
for (let key of __getOwnPropNames(mod))
|
|
12
|
+
if (!__hasOwnProp.call(to, key))
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: () => mod[key],
|
|
15
|
+
enumerable: true
|
|
16
|
+
});
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
20
|
+
|
|
21
|
+
// ../node_modules/.bun/picocolors@1.1.1/node_modules/picocolors/picocolors.js
|
|
22
|
+
var require_picocolors = __commonJS((exports, module) => {
|
|
23
|
+
var p = process || {};
|
|
24
|
+
var argv = p.argv || [];
|
|
25
|
+
var env = p.env || {};
|
|
26
|
+
var isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || (p.stdout || {}).isTTY && env.TERM !== "dumb" || !!env.CI);
|
|
27
|
+
var formatter = (open, close, replace = open) => (input) => {
|
|
28
|
+
let string = "" + input, index = string.indexOf(close, open.length);
|
|
29
|
+
return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
|
|
30
|
+
};
|
|
31
|
+
var replaceClose = (string, close, replace, index) => {
|
|
32
|
+
let result = "", cursor = 0;
|
|
33
|
+
do {
|
|
34
|
+
result += string.substring(cursor, index) + replace;
|
|
35
|
+
cursor = index + close.length;
|
|
36
|
+
index = string.indexOf(close, cursor);
|
|
37
|
+
} while (~index);
|
|
38
|
+
return result + string.substring(cursor);
|
|
39
|
+
};
|
|
40
|
+
var createColors = (enabled = isColorSupported) => {
|
|
41
|
+
let f = enabled ? formatter : () => String;
|
|
42
|
+
return {
|
|
43
|
+
isColorSupported: enabled,
|
|
44
|
+
reset: f("\x1B[0m", "\x1B[0m"),
|
|
45
|
+
bold: f("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
|
|
46
|
+
dim: f("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
|
|
47
|
+
italic: f("\x1B[3m", "\x1B[23m"),
|
|
48
|
+
underline: f("\x1B[4m", "\x1B[24m"),
|
|
49
|
+
inverse: f("\x1B[7m", "\x1B[27m"),
|
|
50
|
+
hidden: f("\x1B[8m", "\x1B[28m"),
|
|
51
|
+
strikethrough: f("\x1B[9m", "\x1B[29m"),
|
|
52
|
+
black: f("\x1B[30m", "\x1B[39m"),
|
|
53
|
+
red: f("\x1B[31m", "\x1B[39m"),
|
|
54
|
+
green: f("\x1B[32m", "\x1B[39m"),
|
|
55
|
+
yellow: f("\x1B[33m", "\x1B[39m"),
|
|
56
|
+
blue: f("\x1B[34m", "\x1B[39m"),
|
|
57
|
+
magenta: f("\x1B[35m", "\x1B[39m"),
|
|
58
|
+
cyan: f("\x1B[36m", "\x1B[39m"),
|
|
59
|
+
white: f("\x1B[37m", "\x1B[39m"),
|
|
60
|
+
gray: f("\x1B[90m", "\x1B[39m"),
|
|
61
|
+
bgBlack: f("\x1B[40m", "\x1B[49m"),
|
|
62
|
+
bgRed: f("\x1B[41m", "\x1B[49m"),
|
|
63
|
+
bgGreen: f("\x1B[42m", "\x1B[49m"),
|
|
64
|
+
bgYellow: f("\x1B[43m", "\x1B[49m"),
|
|
65
|
+
bgBlue: f("\x1B[44m", "\x1B[49m"),
|
|
66
|
+
bgMagenta: f("\x1B[45m", "\x1B[49m"),
|
|
67
|
+
bgCyan: f("\x1B[46m", "\x1B[49m"),
|
|
68
|
+
bgWhite: f("\x1B[47m", "\x1B[49m"),
|
|
69
|
+
blackBright: f("\x1B[90m", "\x1B[39m"),
|
|
70
|
+
redBright: f("\x1B[91m", "\x1B[39m"),
|
|
71
|
+
greenBright: f("\x1B[92m", "\x1B[39m"),
|
|
72
|
+
yellowBright: f("\x1B[93m", "\x1B[39m"),
|
|
73
|
+
blueBright: f("\x1B[94m", "\x1B[39m"),
|
|
74
|
+
magentaBright: f("\x1B[95m", "\x1B[39m"),
|
|
75
|
+
cyanBright: f("\x1B[96m", "\x1B[39m"),
|
|
76
|
+
whiteBright: f("\x1B[97m", "\x1B[39m"),
|
|
77
|
+
bgBlackBright: f("\x1B[100m", "\x1B[49m"),
|
|
78
|
+
bgRedBright: f("\x1B[101m", "\x1B[49m"),
|
|
79
|
+
bgGreenBright: f("\x1B[102m", "\x1B[49m"),
|
|
80
|
+
bgYellowBright: f("\x1B[103m", "\x1B[49m"),
|
|
81
|
+
bgBlueBright: f("\x1B[104m", "\x1B[49m"),
|
|
82
|
+
bgMagentaBright: f("\x1B[105m", "\x1B[49m"),
|
|
83
|
+
bgCyanBright: f("\x1B[106m", "\x1B[49m"),
|
|
84
|
+
bgWhiteBright: f("\x1B[107m", "\x1B[49m")
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
module.exports = createColors();
|
|
88
|
+
module.exports.createColors = createColors;
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
// ../node_modules/.bun/sisteransi@1.0.5/node_modules/sisteransi/src/index.js
|
|
92
|
+
var require_src = __commonJS((exports, module) => {
|
|
93
|
+
var ESC = "\x1B";
|
|
94
|
+
var CSI = `${ESC}[`;
|
|
95
|
+
var beep = "\x07";
|
|
96
|
+
var cursor = {
|
|
97
|
+
to(x, y) {
|
|
98
|
+
if (!y)
|
|
99
|
+
return `${CSI}${x + 1}G`;
|
|
100
|
+
return `${CSI}${y + 1};${x + 1}H`;
|
|
101
|
+
},
|
|
102
|
+
move(x, y) {
|
|
103
|
+
let ret = "";
|
|
104
|
+
if (x < 0)
|
|
105
|
+
ret += `${CSI}${-x}D`;
|
|
106
|
+
else if (x > 0)
|
|
107
|
+
ret += `${CSI}${x}C`;
|
|
108
|
+
if (y < 0)
|
|
109
|
+
ret += `${CSI}${-y}A`;
|
|
110
|
+
else if (y > 0)
|
|
111
|
+
ret += `${CSI}${y}B`;
|
|
112
|
+
return ret;
|
|
113
|
+
},
|
|
114
|
+
up: (count = 1) => `${CSI}${count}A`,
|
|
115
|
+
down: (count = 1) => `${CSI}${count}B`,
|
|
116
|
+
forward: (count = 1) => `${CSI}${count}C`,
|
|
117
|
+
backward: (count = 1) => `${CSI}${count}D`,
|
|
118
|
+
nextLine: (count = 1) => `${CSI}E`.repeat(count),
|
|
119
|
+
prevLine: (count = 1) => `${CSI}F`.repeat(count),
|
|
120
|
+
left: `${CSI}G`,
|
|
121
|
+
hide: `${CSI}?25l`,
|
|
122
|
+
show: `${CSI}?25h`,
|
|
123
|
+
save: `${ESC}7`,
|
|
124
|
+
restore: `${ESC}8`
|
|
125
|
+
};
|
|
126
|
+
var scroll = {
|
|
127
|
+
up: (count = 1) => `${CSI}S`.repeat(count),
|
|
128
|
+
down: (count = 1) => `${CSI}T`.repeat(count)
|
|
129
|
+
};
|
|
130
|
+
var erase = {
|
|
131
|
+
screen: `${CSI}2J`,
|
|
132
|
+
up: (count = 1) => `${CSI}1J`.repeat(count),
|
|
133
|
+
down: (count = 1) => `${CSI}J`.repeat(count),
|
|
134
|
+
line: `${CSI}2K`,
|
|
135
|
+
lineEnd: `${CSI}K`,
|
|
136
|
+
lineStart: `${CSI}1K`,
|
|
137
|
+
lines(count) {
|
|
138
|
+
let clear = "";
|
|
139
|
+
for (let i = 0;i < count; i++)
|
|
140
|
+
clear += this.line + (i < count - 1 ? cursor.up() : "");
|
|
141
|
+
if (count)
|
|
142
|
+
clear += cursor.left;
|
|
143
|
+
return clear;
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
module.exports = { cursor, scroll, erase, beep };
|
|
147
|
+
});
|
|
3
148
|
|
|
4
149
|
// src/bin.ts
|
|
5
150
|
import { appendFileSync, mkdirSync } from "fs";
|
|
6
|
-
import { homedir as
|
|
7
|
-
import { join as
|
|
8
|
-
import { createInterface } from "readline";
|
|
151
|
+
import { homedir as homedir4 } from "os";
|
|
152
|
+
import { join as join4, resolve as resolve3 } from "path";
|
|
9
153
|
import { setTimeout } from "timers/promises";
|
|
10
154
|
import { parseArgs as parseArgsUtil } from "util";
|
|
11
155
|
// package.json
|
|
12
|
-
var version = "0.0.
|
|
156
|
+
var version = "0.0.14";
|
|
13
157
|
|
|
14
158
|
// src/claude.ts
|
|
15
159
|
import { readdir, stat } from "fs/promises";
|
|
@@ -369,10 +513,1349 @@ var buildCodexStateFiles = async (siteUrl, token, helpers) => {
|
|
|
369
513
|
return buildStateFilesFromCollection(files, "codex-state", siteUrl, token, helpers);
|
|
370
514
|
};
|
|
371
515
|
|
|
372
|
-
// src/
|
|
516
|
+
// src/resume.ts
|
|
517
|
+
import { appendFile, mkdir, stat as stat3 } from "fs/promises";
|
|
518
|
+
import { homedir as homedir3 } from "os";
|
|
519
|
+
import { basename, dirname, join as join3, resolve as resolve2 } from "path";
|
|
520
|
+
|
|
521
|
+
// ../node_modules/.bun/@clack+core@1.0.0/node_modules/@clack/core/dist/index.mjs
|
|
522
|
+
var import_picocolors = __toESM(require_picocolors(), 1);
|
|
523
|
+
var import_sisteransi = __toESM(require_src(), 1);
|
|
524
|
+
import { stdout as R, stdin as q } from "process";
|
|
525
|
+
import * as k from "readline";
|
|
526
|
+
import ot from "readline";
|
|
527
|
+
import { ReadStream as J } from "tty";
|
|
528
|
+
var at = (t) => t === 161 || t === 164 || t === 167 || t === 168 || t === 170 || t === 173 || t === 174 || t >= 176 && t <= 180 || t >= 182 && t <= 186 || t >= 188 && t <= 191 || t === 198 || t === 208 || t === 215 || t === 216 || t >= 222 && t <= 225 || t === 230 || t >= 232 && t <= 234 || t === 236 || t === 237 || t === 240 || t === 242 || t === 243 || t >= 247 && t <= 250 || t === 252 || t === 254 || t === 257 || t === 273 || t === 275 || t === 283 || t === 294 || t === 295 || t === 299 || t >= 305 && t <= 307 || t === 312 || t >= 319 && t <= 322 || t === 324 || t >= 328 && t <= 331 || t === 333 || t === 338 || t === 339 || t === 358 || t === 359 || t === 363 || t === 462 || t === 464 || t === 466 || t === 468 || t === 470 || t === 472 || t === 474 || t === 476 || t === 593 || t === 609 || t === 708 || t === 711 || t >= 713 && t <= 715 || t === 717 || t === 720 || t >= 728 && t <= 731 || t === 733 || t === 735 || t >= 768 && t <= 879 || t >= 913 && t <= 929 || t >= 931 && t <= 937 || t >= 945 && t <= 961 || t >= 963 && t <= 969 || t === 1025 || t >= 1040 && t <= 1103 || t === 1105 || t === 8208 || t >= 8211 && t <= 8214 || t === 8216 || t === 8217 || t === 8220 || t === 8221 || t >= 8224 && t <= 8226 || t >= 8228 && t <= 8231 || t === 8240 || t === 8242 || t === 8243 || t === 8245 || t === 8251 || t === 8254 || t === 8308 || t === 8319 || t >= 8321 && t <= 8324 || t === 8364 || t === 8451 || t === 8453 || t === 8457 || t === 8467 || t === 8470 || t === 8481 || t === 8482 || t === 8486 || t === 8491 || t === 8531 || t === 8532 || t >= 8539 && t <= 8542 || t >= 8544 && t <= 8555 || t >= 8560 && t <= 8569 || t === 8585 || t >= 8592 && t <= 8601 || t === 8632 || t === 8633 || t === 8658 || t === 8660 || t === 8679 || t === 8704 || t === 8706 || t === 8707 || t === 8711 || t === 8712 || t === 8715 || t === 8719 || t === 8721 || t === 8725 || t === 8730 || t >= 8733 && t <= 8736 || t === 8739 || t === 8741 || t >= 8743 && t <= 8748 || t === 8750 || t >= 8756 && t <= 8759 || t === 8764 || t === 8765 || t === 8776 || t === 8780 || t === 8786 || t === 8800 || t === 8801 || t >= 8804 && t <= 8807 || t === 8810 || t === 8811 || t === 8814 || t === 8815 || t === 8834 || t === 8835 || t === 8838 || t === 8839 || t === 8853 || t === 8857 || t === 8869 || t === 8895 || t === 8978 || t >= 9312 && t <= 9449 || t >= 9451 && t <= 9547 || t >= 9552 && t <= 9587 || t >= 9600 && t <= 9615 || t >= 9618 && t <= 9621 || t === 9632 || t === 9633 || t >= 9635 && t <= 9641 || t === 9650 || t === 9651 || t === 9654 || t === 9655 || t === 9660 || t === 9661 || t === 9664 || t === 9665 || t >= 9670 && t <= 9672 || t === 9675 || t >= 9678 && t <= 9681 || t >= 9698 && t <= 9701 || t === 9711 || t === 9733 || t === 9734 || t === 9737 || t === 9742 || t === 9743 || t === 9756 || t === 9758 || t === 9792 || t === 9794 || t === 9824 || t === 9825 || t >= 9827 && t <= 9829 || t >= 9831 && t <= 9834 || t === 9836 || t === 9837 || t === 9839 || t === 9886 || t === 9887 || t === 9919 || t >= 9926 && t <= 9933 || t >= 9935 && t <= 9939 || t >= 9941 && t <= 9953 || t === 9955 || t === 9960 || t === 9961 || t >= 9963 && t <= 9969 || t === 9972 || t >= 9974 && t <= 9977 || t === 9979 || t === 9980 || t === 9982 || t === 9983 || t === 10045 || t >= 10102 && t <= 10111 || t >= 11094 && t <= 11097 || t >= 12872 && t <= 12879 || t >= 57344 && t <= 63743 || t >= 65024 && t <= 65039 || t === 65533 || t >= 127232 && t <= 127242 || t >= 127248 && t <= 127277 || t >= 127280 && t <= 127337 || t >= 127344 && t <= 127373 || t === 127375 || t === 127376 || t >= 127387 && t <= 127404 || t >= 917760 && t <= 917999 || t >= 983040 && t <= 1048573 || t >= 1048576 && t <= 1114109;
|
|
529
|
+
var lt = (t) => t === 12288 || t >= 65281 && t <= 65376 || t >= 65504 && t <= 65510;
|
|
530
|
+
var ht = (t) => t >= 4352 && t <= 4447 || t === 8986 || t === 8987 || t === 9001 || t === 9002 || t >= 9193 && t <= 9196 || t === 9200 || t === 9203 || t === 9725 || t === 9726 || t === 9748 || t === 9749 || t >= 9800 && t <= 9811 || t === 9855 || t === 9875 || t === 9889 || t === 9898 || t === 9899 || t === 9917 || t === 9918 || t === 9924 || t === 9925 || t === 9934 || t === 9940 || t === 9962 || t === 9970 || t === 9971 || t === 9973 || t === 9978 || t === 9981 || t === 9989 || t === 9994 || t === 9995 || t === 10024 || t === 10060 || t === 10062 || t >= 10067 && t <= 10069 || t === 10071 || t >= 10133 && t <= 10135 || t === 10160 || t === 10175 || t === 11035 || t === 11036 || t === 11088 || t === 11093 || t >= 11904 && t <= 11929 || t >= 11931 && t <= 12019 || t >= 12032 && t <= 12245 || t >= 12272 && t <= 12287 || t >= 12289 && t <= 12350 || t >= 12353 && t <= 12438 || t >= 12441 && t <= 12543 || t >= 12549 && t <= 12591 || t >= 12593 && t <= 12686 || t >= 12688 && t <= 12771 || t >= 12783 && t <= 12830 || t >= 12832 && t <= 12871 || t >= 12880 && t <= 19903 || t >= 19968 && t <= 42124 || t >= 42128 && t <= 42182 || t >= 43360 && t <= 43388 || t >= 44032 && t <= 55203 || t >= 63744 && t <= 64255 || t >= 65040 && t <= 65049 || t >= 65072 && t <= 65106 || t >= 65108 && t <= 65126 || t >= 65128 && t <= 65131 || t >= 94176 && t <= 94180 || t === 94192 || t === 94193 || t >= 94208 && t <= 100343 || t >= 100352 && t <= 101589 || t >= 101632 && t <= 101640 || t >= 110576 && t <= 110579 || t >= 110581 && t <= 110587 || t === 110589 || t === 110590 || t >= 110592 && t <= 110882 || t === 110898 || t >= 110928 && t <= 110930 || t === 110933 || t >= 110948 && t <= 110951 || t >= 110960 && t <= 111355 || t === 126980 || t === 127183 || t === 127374 || t >= 127377 && t <= 127386 || t >= 127488 && t <= 127490 || t >= 127504 && t <= 127547 || t >= 127552 && t <= 127560 || t === 127568 || t === 127569 || t >= 127584 && t <= 127589 || t >= 127744 && t <= 127776 || t >= 127789 && t <= 127797 || t >= 127799 && t <= 127868 || t >= 127870 && t <= 127891 || t >= 127904 && t <= 127946 || t >= 127951 && t <= 127955 || t >= 127968 && t <= 127984 || t === 127988 || t >= 127992 && t <= 128062 || t === 128064 || t >= 128066 && t <= 128252 || t >= 128255 && t <= 128317 || t >= 128331 && t <= 128334 || t >= 128336 && t <= 128359 || t === 128378 || t === 128405 || t === 128406 || t === 128420 || t >= 128507 && t <= 128591 || t >= 128640 && t <= 128709 || t === 128716 || t >= 128720 && t <= 128722 || t >= 128725 && t <= 128727 || t >= 128732 && t <= 128735 || t === 128747 || t === 128748 || t >= 128756 && t <= 128764 || t >= 128992 && t <= 129003 || t === 129008 || t >= 129292 && t <= 129338 || t >= 129340 && t <= 129349 || t >= 129351 && t <= 129535 || t >= 129648 && t <= 129660 || t >= 129664 && t <= 129672 || t >= 129680 && t <= 129725 || t >= 129727 && t <= 129733 || t >= 129742 && t <= 129755 || t >= 129760 && t <= 129768 || t >= 129776 && t <= 129784 || t >= 131072 && t <= 196605 || t >= 196608 && t <= 262141;
|
|
531
|
+
var O = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/y;
|
|
532
|
+
var y = /[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y;
|
|
533
|
+
var M = /\t{1,1000}/y;
|
|
534
|
+
var P = /[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/yu;
|
|
535
|
+
var L = /(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y;
|
|
536
|
+
var ct = /\p{M}+/gu;
|
|
537
|
+
var pt = { limit: 1 / 0, ellipsis: "" };
|
|
538
|
+
var X = (t, e = {}, s = {}) => {
|
|
539
|
+
const i = e.limit ?? 1 / 0, r = e.ellipsis ?? "", n = e?.ellipsisWidth ?? (r ? X(r, pt, s).width : 0), u = s.ansiWidth ?? 0, a = s.controlWidth ?? 0, l = s.tabWidth ?? 8, E = s.ambiguousWidth ?? 1, g = s.emojiWidth ?? 2, m = s.fullWidthWidth ?? 2, A = s.regularWidth ?? 1, V = s.wideWidth ?? 2;
|
|
540
|
+
let h = 0, o = 0, f = t.length, v = 0, F = false, d = f, b = Math.max(0, i - n), C = 0, B = 0, c = 0, p = 0;
|
|
541
|
+
t:
|
|
542
|
+
for (;; ) {
|
|
543
|
+
if (B > C || o >= f && o > h) {
|
|
544
|
+
const ut = t.slice(C, B) || t.slice(h, o);
|
|
545
|
+
v = 0;
|
|
546
|
+
for (const Y of ut.replaceAll(ct, "")) {
|
|
547
|
+
const $ = Y.codePointAt(0) || 0;
|
|
548
|
+
if (lt($) ? p = m : ht($) ? p = V : E !== A && at($) ? p = E : p = A, c + p > b && (d = Math.min(d, Math.max(C, h) + v)), c + p > i) {
|
|
549
|
+
F = true;
|
|
550
|
+
break t;
|
|
551
|
+
}
|
|
552
|
+
v += Y.length, c += p;
|
|
553
|
+
}
|
|
554
|
+
C = B = 0;
|
|
555
|
+
}
|
|
556
|
+
if (o >= f)
|
|
557
|
+
break;
|
|
558
|
+
if (L.lastIndex = o, L.test(t)) {
|
|
559
|
+
if (v = L.lastIndex - o, p = v * A, c + p > b && (d = Math.min(d, o + Math.floor((b - c) / A))), c + p > i) {
|
|
560
|
+
F = true;
|
|
561
|
+
break;
|
|
562
|
+
}
|
|
563
|
+
c += p, C = h, B = o, o = h = L.lastIndex;
|
|
564
|
+
continue;
|
|
565
|
+
}
|
|
566
|
+
if (O.lastIndex = o, O.test(t)) {
|
|
567
|
+
if (c + u > b && (d = Math.min(d, o)), c + u > i) {
|
|
568
|
+
F = true;
|
|
569
|
+
break;
|
|
570
|
+
}
|
|
571
|
+
c += u, C = h, B = o, o = h = O.lastIndex;
|
|
572
|
+
continue;
|
|
573
|
+
}
|
|
574
|
+
if (y.lastIndex = o, y.test(t)) {
|
|
575
|
+
if (v = y.lastIndex - o, p = v * a, c + p > b && (d = Math.min(d, o + Math.floor((b - c) / a))), c + p > i) {
|
|
576
|
+
F = true;
|
|
577
|
+
break;
|
|
578
|
+
}
|
|
579
|
+
c += p, C = h, B = o, o = h = y.lastIndex;
|
|
580
|
+
continue;
|
|
581
|
+
}
|
|
582
|
+
if (M.lastIndex = o, M.test(t)) {
|
|
583
|
+
if (v = M.lastIndex - o, p = v * l, c + p > b && (d = Math.min(d, o + Math.floor((b - c) / l))), c + p > i) {
|
|
584
|
+
F = true;
|
|
585
|
+
break;
|
|
586
|
+
}
|
|
587
|
+
c += p, C = h, B = o, o = h = M.lastIndex;
|
|
588
|
+
continue;
|
|
589
|
+
}
|
|
590
|
+
if (P.lastIndex = o, P.test(t)) {
|
|
591
|
+
if (c + g > b && (d = Math.min(d, o)), c + g > i) {
|
|
592
|
+
F = true;
|
|
593
|
+
break;
|
|
594
|
+
}
|
|
595
|
+
c += g, C = h, B = o, o = h = P.lastIndex;
|
|
596
|
+
continue;
|
|
597
|
+
}
|
|
598
|
+
o += 1;
|
|
599
|
+
}
|
|
600
|
+
return { width: F ? b : c, index: F ? d : f, truncated: F, ellipsed: F && i >= n };
|
|
601
|
+
};
|
|
602
|
+
var ft = { limit: 1 / 0, ellipsis: "", ellipsisWidth: 0 };
|
|
603
|
+
var S = (t, e = {}) => X(t, ft, e).width;
|
|
604
|
+
var W = "\x1B";
|
|
605
|
+
var Z = "\x9B";
|
|
606
|
+
var Ft = 39;
|
|
607
|
+
var j = "\x07";
|
|
608
|
+
var Q = "[";
|
|
609
|
+
var dt = "]";
|
|
610
|
+
var tt = "m";
|
|
611
|
+
var U = `${dt}8;;`;
|
|
612
|
+
var et = new RegExp(`(?:\\${Q}(?<code>\\d+)m|\\${U}(?<uri>.*)${j})`, "y");
|
|
613
|
+
var mt = (t) => {
|
|
614
|
+
if (t >= 30 && t <= 37 || t >= 90 && t <= 97)
|
|
615
|
+
return 39;
|
|
616
|
+
if (t >= 40 && t <= 47 || t >= 100 && t <= 107)
|
|
617
|
+
return 49;
|
|
618
|
+
if (t === 1 || t === 2)
|
|
619
|
+
return 22;
|
|
620
|
+
if (t === 3)
|
|
621
|
+
return 23;
|
|
622
|
+
if (t === 4)
|
|
623
|
+
return 24;
|
|
624
|
+
if (t === 7)
|
|
625
|
+
return 27;
|
|
626
|
+
if (t === 8)
|
|
627
|
+
return 28;
|
|
628
|
+
if (t === 9)
|
|
629
|
+
return 29;
|
|
630
|
+
if (t === 0)
|
|
631
|
+
return 0;
|
|
632
|
+
};
|
|
633
|
+
var st = (t) => `${W}${Q}${t}${tt}`;
|
|
634
|
+
var it = (t) => `${W}${U}${t}${j}`;
|
|
635
|
+
var gt = (t) => t.map((e) => S(e));
|
|
636
|
+
var G = (t, e, s) => {
|
|
637
|
+
const i = e[Symbol.iterator]();
|
|
638
|
+
let r = false, n = false, u = t.at(-1), a = u === undefined ? 0 : S(u), l = i.next(), E = i.next(), g = 0;
|
|
639
|
+
for (;!l.done; ) {
|
|
640
|
+
const m = l.value, A = S(m);
|
|
641
|
+
a + A <= s ? t[t.length - 1] += m : (t.push(m), a = 0), (m === W || m === Z) && (r = true, n = e.startsWith(U, g + 1)), r ? n ? m === j && (r = false, n = false) : m === tt && (r = false) : (a += A, a === s && !E.done && (t.push(""), a = 0)), l = E, E = i.next(), g += m.length;
|
|
642
|
+
}
|
|
643
|
+
u = t.at(-1), !a && u !== undefined && u.length > 0 && t.length > 1 && (t[t.length - 2] += t.pop());
|
|
644
|
+
};
|
|
645
|
+
var vt = (t) => {
|
|
646
|
+
const e = t.split(" ");
|
|
647
|
+
let s = e.length;
|
|
648
|
+
for (;s > 0 && !(S(e[s - 1]) > 0); )
|
|
649
|
+
s--;
|
|
650
|
+
return s === e.length ? t : e.slice(0, s).join(" ") + e.slice(s).join("");
|
|
651
|
+
};
|
|
652
|
+
var Et = (t, e, s = {}) => {
|
|
653
|
+
if (s.trim !== false && t.trim() === "")
|
|
654
|
+
return "";
|
|
655
|
+
let i = "", r, n;
|
|
656
|
+
const u = t.split(" "), a = gt(u);
|
|
657
|
+
let l = [""];
|
|
658
|
+
for (const [h, o] of u.entries()) {
|
|
659
|
+
s.trim !== false && (l[l.length - 1] = (l.at(-1) ?? "").trimStart());
|
|
660
|
+
let f = S(l.at(-1) ?? "");
|
|
661
|
+
if (h !== 0 && (f >= e && (s.wordWrap === false || s.trim === false) && (l.push(""), f = 0), (f > 0 || s.trim === false) && (l[l.length - 1] += " ", f++)), s.hard && a[h] > e) {
|
|
662
|
+
const v = e - f, F = 1 + Math.floor((a[h] - v - 1) / e);
|
|
663
|
+
Math.floor((a[h] - 1) / e) < F && l.push(""), G(l, o, e);
|
|
664
|
+
continue;
|
|
665
|
+
}
|
|
666
|
+
if (f + a[h] > e && f > 0 && a[h] > 0) {
|
|
667
|
+
if (s.wordWrap === false && f < e) {
|
|
668
|
+
G(l, o, e);
|
|
669
|
+
continue;
|
|
670
|
+
}
|
|
671
|
+
l.push("");
|
|
672
|
+
}
|
|
673
|
+
if (f + a[h] > e && s.wordWrap === false) {
|
|
674
|
+
G(l, o, e);
|
|
675
|
+
continue;
|
|
676
|
+
}
|
|
677
|
+
l[l.length - 1] += o;
|
|
678
|
+
}
|
|
679
|
+
s.trim !== false && (l = l.map((h) => vt(h)));
|
|
680
|
+
const E = l.join(`
|
|
681
|
+
`), g = E[Symbol.iterator]();
|
|
682
|
+
let m = g.next(), A = g.next(), V = 0;
|
|
683
|
+
for (;!m.done; ) {
|
|
684
|
+
const h = m.value, o = A.value;
|
|
685
|
+
if (i += h, h === W || h === Z) {
|
|
686
|
+
et.lastIndex = V + 1;
|
|
687
|
+
const F = et.exec(E)?.groups;
|
|
688
|
+
if (F?.code !== undefined) {
|
|
689
|
+
const d = Number.parseFloat(F.code);
|
|
690
|
+
r = d === Ft ? undefined : d;
|
|
691
|
+
} else
|
|
692
|
+
F?.uri !== undefined && (n = F.uri.length === 0 ? undefined : F.uri);
|
|
693
|
+
}
|
|
694
|
+
const f = r ? mt(r) : undefined;
|
|
695
|
+
o === `
|
|
696
|
+
` ? (n && (i += it("")), r && f && (i += st(f))) : h === `
|
|
697
|
+
` && (r && f && (i += st(r)), n && (i += it(n))), V += h.length, m = A, A = g.next();
|
|
698
|
+
}
|
|
699
|
+
return i;
|
|
700
|
+
};
|
|
701
|
+
function K(t, e, s) {
|
|
702
|
+
return String(t).normalize().replaceAll(`\r
|
|
703
|
+
`, `
|
|
704
|
+
`).split(`
|
|
705
|
+
`).map((i) => Et(i, e, s)).join(`
|
|
706
|
+
`);
|
|
707
|
+
}
|
|
708
|
+
var At = ["up", "down", "left", "right", "space", "enter", "cancel"];
|
|
709
|
+
var _ = { actions: new Set(At), aliases: new Map([["k", "up"], ["j", "down"], ["h", "left"], ["l", "right"], ["\x03", "cancel"], ["escape", "cancel"]]), messages: { cancel: "Canceled", error: "Something went wrong" }, withGuide: true };
|
|
710
|
+
function H(t, e) {
|
|
711
|
+
if (typeof t == "string")
|
|
712
|
+
return _.aliases.get(t) === e;
|
|
713
|
+
for (const s of t)
|
|
714
|
+
if (s !== undefined && H(s, e))
|
|
715
|
+
return true;
|
|
716
|
+
return false;
|
|
717
|
+
}
|
|
718
|
+
function _t(t, e) {
|
|
719
|
+
if (t === e)
|
|
720
|
+
return;
|
|
721
|
+
const s = t.split(`
|
|
722
|
+
`), i = e.split(`
|
|
723
|
+
`), r = Math.max(s.length, i.length), n = [];
|
|
724
|
+
for (let u = 0;u < r; u++)
|
|
725
|
+
s[u] !== i[u] && n.push(u);
|
|
726
|
+
return { lines: n, numLinesBefore: s.length, numLinesAfter: i.length, numLines: r };
|
|
727
|
+
}
|
|
728
|
+
var bt = globalThis.process.platform.startsWith("win");
|
|
729
|
+
var z = Symbol("clack:cancel");
|
|
730
|
+
function Ct(t) {
|
|
731
|
+
return t === z;
|
|
732
|
+
}
|
|
733
|
+
function T(t, e) {
|
|
734
|
+
const s = t;
|
|
735
|
+
s.isTTY && s.setRawMode(e);
|
|
736
|
+
}
|
|
737
|
+
function xt({ input: t = q, output: e = R, overwrite: s = true, hideCursor: i = true } = {}) {
|
|
738
|
+
const r = k.createInterface({ input: t, output: e, prompt: "", tabSize: 1 });
|
|
739
|
+
k.emitKeypressEvents(t, r), t instanceof J && t.isTTY && t.setRawMode(true);
|
|
740
|
+
const n = (u, { name: a, sequence: l }) => {
|
|
741
|
+
const E = String(u);
|
|
742
|
+
if (H([E, a, l], "cancel")) {
|
|
743
|
+
i && e.write(import_sisteransi.cursor.show), process.exit(0);
|
|
744
|
+
return;
|
|
745
|
+
}
|
|
746
|
+
if (!s)
|
|
747
|
+
return;
|
|
748
|
+
const g = a === "return" ? 0 : -1, m = a === "return" ? -1 : 0;
|
|
749
|
+
k.moveCursor(e, g, m, () => {
|
|
750
|
+
k.clearLine(e, 1, () => {
|
|
751
|
+
t.once("keypress", n);
|
|
752
|
+
});
|
|
753
|
+
});
|
|
754
|
+
};
|
|
755
|
+
return i && e.write(import_sisteransi.cursor.hide), t.once("keypress", n), () => {
|
|
756
|
+
t.off("keypress", n), i && e.write(import_sisteransi.cursor.show), t instanceof J && t.isTTY && !bt && t.setRawMode(false), r.terminal = false, r.close();
|
|
757
|
+
};
|
|
758
|
+
}
|
|
759
|
+
var rt = (t) => ("columns" in t) && typeof t.columns == "number" ? t.columns : 80;
|
|
760
|
+
var nt = (t) => ("rows" in t) && typeof t.rows == "number" ? t.rows : 20;
|
|
761
|
+
function Bt(t, e, s, i = s) {
|
|
762
|
+
const r = rt(t ?? R);
|
|
763
|
+
return K(e, r - s.length, { hard: true, trim: false }).split(`
|
|
764
|
+
`).map((n, u) => `${u === 0 ? i : s}${n}`).join(`
|
|
765
|
+
`);
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
class x {
|
|
769
|
+
input;
|
|
770
|
+
output;
|
|
771
|
+
_abortSignal;
|
|
772
|
+
rl;
|
|
773
|
+
opts;
|
|
774
|
+
_render;
|
|
775
|
+
_track = false;
|
|
776
|
+
_prevFrame = "";
|
|
777
|
+
_subscribers = new Map;
|
|
778
|
+
_cursor = 0;
|
|
779
|
+
state = "initial";
|
|
780
|
+
error = "";
|
|
781
|
+
value;
|
|
782
|
+
userInput = "";
|
|
783
|
+
constructor(e, s = true) {
|
|
784
|
+
const { input: i = q, output: r = R, render: n, signal: u, ...a } = e;
|
|
785
|
+
this.opts = a, this.onKeypress = this.onKeypress.bind(this), this.close = this.close.bind(this), this.render = this.render.bind(this), this._render = n.bind(this), this._track = s, this._abortSignal = u, this.input = i, this.output = r;
|
|
786
|
+
}
|
|
787
|
+
unsubscribe() {
|
|
788
|
+
this._subscribers.clear();
|
|
789
|
+
}
|
|
790
|
+
setSubscriber(e, s) {
|
|
791
|
+
const i = this._subscribers.get(e) ?? [];
|
|
792
|
+
i.push(s), this._subscribers.set(e, i);
|
|
793
|
+
}
|
|
794
|
+
on(e, s) {
|
|
795
|
+
this.setSubscriber(e, { cb: s });
|
|
796
|
+
}
|
|
797
|
+
once(e, s) {
|
|
798
|
+
this.setSubscriber(e, { cb: s, once: true });
|
|
799
|
+
}
|
|
800
|
+
emit(e, ...s) {
|
|
801
|
+
const i = this._subscribers.get(e) ?? [], r = [];
|
|
802
|
+
for (const n of i)
|
|
803
|
+
n.cb(...s), n.once && r.push(() => i.splice(i.indexOf(n), 1));
|
|
804
|
+
for (const n of r)
|
|
805
|
+
n();
|
|
806
|
+
}
|
|
807
|
+
prompt() {
|
|
808
|
+
return new Promise((e) => {
|
|
809
|
+
if (this._abortSignal) {
|
|
810
|
+
if (this._abortSignal.aborted)
|
|
811
|
+
return this.state = "cancel", this.close(), e(z);
|
|
812
|
+
this._abortSignal.addEventListener("abort", () => {
|
|
813
|
+
this.state = "cancel", this.close();
|
|
814
|
+
}, { once: true });
|
|
815
|
+
}
|
|
816
|
+
this.rl = ot.createInterface({ input: this.input, tabSize: 2, prompt: "", escapeCodeTimeout: 50, terminal: true }), this.rl.prompt(), this.opts.initialUserInput !== undefined && this._setUserInput(this.opts.initialUserInput, true), this.input.on("keypress", this.onKeypress), T(this.input, true), this.output.on("resize", this.render), this.render(), this.once("submit", () => {
|
|
817
|
+
this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), T(this.input, false), e(this.value);
|
|
818
|
+
}), this.once("cancel", () => {
|
|
819
|
+
this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), T(this.input, false), e(z);
|
|
820
|
+
});
|
|
821
|
+
});
|
|
822
|
+
}
|
|
823
|
+
_isActionKey(e, s) {
|
|
824
|
+
return e === "\t";
|
|
825
|
+
}
|
|
826
|
+
_setValue(e) {
|
|
827
|
+
this.value = e, this.emit("value", this.value);
|
|
828
|
+
}
|
|
829
|
+
_setUserInput(e, s) {
|
|
830
|
+
this.userInput = e ?? "", this.emit("userInput", this.userInput), s && this._track && this.rl && (this.rl.write(this.userInput), this._cursor = this.rl.cursor);
|
|
831
|
+
}
|
|
832
|
+
_clearUserInput() {
|
|
833
|
+
this.rl?.write(null, { ctrl: true, name: "u" }), this._setUserInput("");
|
|
834
|
+
}
|
|
835
|
+
onKeypress(e, s) {
|
|
836
|
+
if (this._track && s.name !== "return" && (s.name && this._isActionKey(e, s) && this.rl?.write(null, { ctrl: true, name: "h" }), this._cursor = this.rl?.cursor ?? 0, this._setUserInput(this.rl?.line)), this.state === "error" && (this.state = "active"), s?.name && (!this._track && _.aliases.has(s.name) && this.emit("cursor", _.aliases.get(s.name)), _.actions.has(s.name) && this.emit("cursor", s.name)), e && (e.toLowerCase() === "y" || e.toLowerCase() === "n") && this.emit("confirm", e.toLowerCase() === "y"), this.emit("key", e?.toLowerCase(), s), s?.name === "return") {
|
|
837
|
+
if (this.opts.validate) {
|
|
838
|
+
const i = this.opts.validate(this.value);
|
|
839
|
+
i && (this.error = i instanceof Error ? i.message : i, this.state = "error", this.rl?.write(this.userInput));
|
|
840
|
+
}
|
|
841
|
+
this.state !== "error" && (this.state = "submit");
|
|
842
|
+
}
|
|
843
|
+
H([e, s?.name, s?.sequence], "cancel") && (this.state = "cancel"), (this.state === "submit" || this.state === "cancel") && this.emit("finalize"), this.render(), (this.state === "submit" || this.state === "cancel") && this.close();
|
|
844
|
+
}
|
|
845
|
+
close() {
|
|
846
|
+
this.input.unpipe(), this.input.removeListener("keypress", this.onKeypress), this.output.write(`
|
|
847
|
+
`), T(this.input, false), this.rl?.close(), this.rl = undefined, this.emit(`${this.state}`, this.value), this.unsubscribe();
|
|
848
|
+
}
|
|
849
|
+
restoreCursor() {
|
|
850
|
+
const e = K(this._prevFrame, process.stdout.columns, { hard: true, trim: false }).split(`
|
|
851
|
+
`).length - 1;
|
|
852
|
+
this.output.write(import_sisteransi.cursor.move(-999, e * -1));
|
|
853
|
+
}
|
|
854
|
+
render() {
|
|
855
|
+
const e = K(this._render(this) ?? "", process.stdout.columns, { hard: true, trim: false });
|
|
856
|
+
if (e !== this._prevFrame) {
|
|
857
|
+
if (this.state === "initial")
|
|
858
|
+
this.output.write(import_sisteransi.cursor.hide);
|
|
859
|
+
else {
|
|
860
|
+
const s = _t(this._prevFrame, e), i = nt(this.output);
|
|
861
|
+
if (this.restoreCursor(), s) {
|
|
862
|
+
const r = Math.max(0, s.numLinesAfter - i), n = Math.max(0, s.numLinesBefore - i);
|
|
863
|
+
let u = s.lines.find((a) => a >= r);
|
|
864
|
+
if (u === undefined) {
|
|
865
|
+
this._prevFrame = e;
|
|
866
|
+
return;
|
|
867
|
+
}
|
|
868
|
+
if (s.lines.length === 1) {
|
|
869
|
+
this.output.write(import_sisteransi.cursor.move(0, u - n)), this.output.write(import_sisteransi.erase.lines(1));
|
|
870
|
+
const a = e.split(`
|
|
871
|
+
`);
|
|
872
|
+
this.output.write(a[u]), this._prevFrame = e, this.output.write(import_sisteransi.cursor.move(0, a.length - u - 1));
|
|
873
|
+
return;
|
|
874
|
+
} else if (s.lines.length > 1) {
|
|
875
|
+
if (r < n)
|
|
876
|
+
u = r;
|
|
877
|
+
else {
|
|
878
|
+
const l = u - n;
|
|
879
|
+
l > 0 && this.output.write(import_sisteransi.cursor.move(0, l));
|
|
880
|
+
}
|
|
881
|
+
this.output.write(import_sisteransi.erase.down());
|
|
882
|
+
const a = e.split(`
|
|
883
|
+
`).slice(u);
|
|
884
|
+
this.output.write(a.join(`
|
|
885
|
+
`)), this._prevFrame = e;
|
|
886
|
+
return;
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
this.output.write(import_sisteransi.erase.down());
|
|
890
|
+
}
|
|
891
|
+
this.output.write(e), this.state === "initial" && (this.state = "active"), this._prevFrame = e;
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
function wt(t, e) {
|
|
896
|
+
if (t === undefined || e.length === 0)
|
|
897
|
+
return 0;
|
|
898
|
+
const s = e.findIndex((i) => i.value === t);
|
|
899
|
+
return s !== -1 ? s : 0;
|
|
900
|
+
}
|
|
901
|
+
function Dt(t, e) {
|
|
902
|
+
return (e.label ?? String(e.value)).toLowerCase().includes(t.toLowerCase());
|
|
903
|
+
}
|
|
904
|
+
function St(t, e) {
|
|
905
|
+
if (e)
|
|
906
|
+
return t ? e : e[0];
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
class Vt extends x {
|
|
910
|
+
filteredOptions;
|
|
911
|
+
multiple;
|
|
912
|
+
isNavigating = false;
|
|
913
|
+
selectedValues = [];
|
|
914
|
+
focusedValue;
|
|
915
|
+
#t = 0;
|
|
916
|
+
#s = "";
|
|
917
|
+
#i;
|
|
918
|
+
#e;
|
|
919
|
+
get cursor() {
|
|
920
|
+
return this.#t;
|
|
921
|
+
}
|
|
922
|
+
get userInputWithCursor() {
|
|
923
|
+
if (!this.userInput)
|
|
924
|
+
return import_picocolors.default.inverse(import_picocolors.default.hidden("_"));
|
|
925
|
+
if (this._cursor >= this.userInput.length)
|
|
926
|
+
return `${this.userInput}\u2588`;
|
|
927
|
+
const e = this.userInput.slice(0, this._cursor), [s, ...i] = this.userInput.slice(this._cursor);
|
|
928
|
+
return `${e}${import_picocolors.default.inverse(s)}${i.join("")}`;
|
|
929
|
+
}
|
|
930
|
+
get options() {
|
|
931
|
+
return typeof this.#e == "function" ? this.#e() : this.#e;
|
|
932
|
+
}
|
|
933
|
+
constructor(e) {
|
|
934
|
+
super(e), this.#e = e.options;
|
|
935
|
+
const s = this.options;
|
|
936
|
+
this.filteredOptions = [...s], this.multiple = e.multiple === true, this.#i = e.filter ?? Dt;
|
|
937
|
+
let i;
|
|
938
|
+
if (e.initialValue && Array.isArray(e.initialValue) ? this.multiple ? i = e.initialValue : i = e.initialValue.slice(0, 1) : !this.multiple && this.options.length > 0 && (i = [this.options[0].value]), i)
|
|
939
|
+
for (const r of i) {
|
|
940
|
+
const n = s.findIndex((u) => u.value === r);
|
|
941
|
+
n !== -1 && (this.toggleSelected(r), this.#t = n);
|
|
942
|
+
}
|
|
943
|
+
this.focusedValue = this.options[this.#t]?.value, this.on("key", (r, n) => this.#r(r, n)), this.on("userInput", (r) => this.#n(r));
|
|
944
|
+
}
|
|
945
|
+
_isActionKey(e, s) {
|
|
946
|
+
return e === "\t" || this.multiple && this.isNavigating && s.name === "space" && e !== undefined && e !== "";
|
|
947
|
+
}
|
|
948
|
+
#r(e, s) {
|
|
949
|
+
const i = s.name === "up", r = s.name === "down", n = s.name === "return";
|
|
950
|
+
i || r ? (this.#t = Math.max(0, Math.min(this.#t + (i ? -1 : 1), this.filteredOptions.length - 1)), this.focusedValue = this.filteredOptions[this.#t]?.value, this.multiple || (this.selectedValues = [this.focusedValue]), this.isNavigating = true) : n ? this.value = St(this.multiple, this.selectedValues) : this.multiple ? this.focusedValue !== undefined && (s.name === "tab" || this.isNavigating && s.name === "space") ? this.toggleSelected(this.focusedValue) : this.isNavigating = false : (this.focusedValue && (this.selectedValues = [this.focusedValue]), this.isNavigating = false);
|
|
951
|
+
}
|
|
952
|
+
deselectAll() {
|
|
953
|
+
this.selectedValues = [];
|
|
954
|
+
}
|
|
955
|
+
toggleSelected(e) {
|
|
956
|
+
this.filteredOptions.length !== 0 && (this.multiple ? this.selectedValues.includes(e) ? this.selectedValues = this.selectedValues.filter((s) => s !== e) : this.selectedValues = [...this.selectedValues, e] : this.selectedValues = [e]);
|
|
957
|
+
}
|
|
958
|
+
#n(e) {
|
|
959
|
+
if (e !== this.#s) {
|
|
960
|
+
this.#s = e;
|
|
961
|
+
const s = this.options;
|
|
962
|
+
e ? this.filteredOptions = s.filter((i) => this.#i(e, i)) : this.filteredOptions = [...s], this.#t = wt(this.focusedValue, this.filteredOptions), this.focusedValue = this.filteredOptions[this.#t]?.value, this.multiple || (this.focusedValue !== undefined ? this.toggleSelected(this.focusedValue) : this.deselectAll());
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
class kt extends x {
|
|
968
|
+
get cursor() {
|
|
969
|
+
return this.value ? 0 : 1;
|
|
970
|
+
}
|
|
971
|
+
get _value() {
|
|
972
|
+
return this.cursor === 0;
|
|
973
|
+
}
|
|
974
|
+
constructor(e) {
|
|
975
|
+
super(e, false), this.value = !!e.initialValue, this.on("userInput", () => {
|
|
976
|
+
this.value = this._value;
|
|
977
|
+
}), this.on("confirm", (s) => {
|
|
978
|
+
this.output.write(import_sisteransi.cursor.move(0, -1)), this.value = s, this.state = "submit", this.close();
|
|
979
|
+
}), this.on("cursor", () => {
|
|
980
|
+
this.value = !this.value;
|
|
981
|
+
});
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
class yt extends x {
|
|
986
|
+
options;
|
|
987
|
+
cursor = 0;
|
|
988
|
+
#t;
|
|
989
|
+
getGroupItems(e) {
|
|
990
|
+
return this.options.filter((s) => s.group === e);
|
|
991
|
+
}
|
|
992
|
+
isGroupSelected(e) {
|
|
993
|
+
const s = this.getGroupItems(e), i = this.value;
|
|
994
|
+
return i === undefined ? false : s.every((r) => i.includes(r.value));
|
|
995
|
+
}
|
|
996
|
+
toggleValue() {
|
|
997
|
+
const e = this.options[this.cursor];
|
|
998
|
+
if (this.value === undefined && (this.value = []), e.group === true) {
|
|
999
|
+
const s = e.value, i = this.getGroupItems(s);
|
|
1000
|
+
this.isGroupSelected(s) ? this.value = this.value.filter((r) => i.findIndex((n) => n.value === r) === -1) : this.value = [...this.value, ...i.map((r) => r.value)], this.value = Array.from(new Set(this.value));
|
|
1001
|
+
} else {
|
|
1002
|
+
const s = this.value.includes(e.value);
|
|
1003
|
+
this.value = s ? this.value.filter((i) => i !== e.value) : [...this.value, e.value];
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
constructor(e) {
|
|
1007
|
+
super(e, false);
|
|
1008
|
+
const { options: s } = e;
|
|
1009
|
+
this.#t = e.selectableGroups !== false, this.options = Object.entries(s).flatMap(([i, r]) => [{ value: i, group: true, label: i }, ...r.map((n) => ({ ...n, group: i }))]), this.value = [...e.initialValues ?? []], this.cursor = Math.max(this.options.findIndex(({ value: i }) => i === e.cursorAt), this.#t ? 0 : 1), this.on("cursor", (i) => {
|
|
1010
|
+
switch (i) {
|
|
1011
|
+
case "left":
|
|
1012
|
+
case "up": {
|
|
1013
|
+
this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1;
|
|
1014
|
+
const r = this.options[this.cursor]?.group === true;
|
|
1015
|
+
!this.#t && r && (this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1);
|
|
1016
|
+
break;
|
|
1017
|
+
}
|
|
1018
|
+
case "down":
|
|
1019
|
+
case "right": {
|
|
1020
|
+
this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1;
|
|
1021
|
+
const r = this.options[this.cursor]?.group === true;
|
|
1022
|
+
!this.#t && r && (this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1);
|
|
1023
|
+
break;
|
|
1024
|
+
}
|
|
1025
|
+
case "space":
|
|
1026
|
+
this.toggleValue();
|
|
1027
|
+
break;
|
|
1028
|
+
}
|
|
1029
|
+
});
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
function D(t, e, s) {
|
|
1033
|
+
const i = t + e, r = Math.max(s.length - 1, 0), n = i < 0 ? r : i > r ? 0 : i;
|
|
1034
|
+
return s[n].disabled ? D(n, e < 0 ? -1 : 1, s) : n;
|
|
1035
|
+
}
|
|
1036
|
+
class Wt extends x {
|
|
1037
|
+
options;
|
|
1038
|
+
cursor = 0;
|
|
1039
|
+
get _selectedValue() {
|
|
1040
|
+
return this.options[this.cursor];
|
|
1041
|
+
}
|
|
1042
|
+
changeValue() {
|
|
1043
|
+
this.value = this._selectedValue.value;
|
|
1044
|
+
}
|
|
1045
|
+
constructor(e) {
|
|
1046
|
+
super(e, false), this.options = e.options;
|
|
1047
|
+
const s = this.options.findIndex(({ value: r }) => r === e.initialValue), i = s === -1 ? 0 : s;
|
|
1048
|
+
this.cursor = this.options[i].disabled ? D(i, 1, this.options) : i, this.changeValue(), this.on("cursor", (r) => {
|
|
1049
|
+
switch (r) {
|
|
1050
|
+
case "left":
|
|
1051
|
+
case "up":
|
|
1052
|
+
this.cursor = D(this.cursor, -1, this.options);
|
|
1053
|
+
break;
|
|
1054
|
+
case "down":
|
|
1055
|
+
case "right":
|
|
1056
|
+
this.cursor = D(this.cursor, 1, this.options);
|
|
1057
|
+
break;
|
|
1058
|
+
}
|
|
1059
|
+
this.changeValue();
|
|
1060
|
+
});
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
// ../node_modules/.bun/@clack+prompts@1.0.0/node_modules/@clack/prompts/dist/index.mjs
|
|
1065
|
+
var import_picocolors2 = __toESM(require_picocolors(), 1);
|
|
1066
|
+
import P2 from "process";
|
|
1067
|
+
var import_sisteransi2 = __toESM(require_src(), 1);
|
|
1068
|
+
function ht2() {
|
|
1069
|
+
return P2.platform !== "win32" ? P2.env.TERM !== "linux" : !!P2.env.CI || !!P2.env.WT_SESSION || !!P2.env.TERMINUS_SUBLIME || P2.env.ConEmuTask === "{cmd::Cmder}" || P2.env.TERM_PROGRAM === "Terminus-Sublime" || P2.env.TERM_PROGRAM === "vscode" || P2.env.TERM === "xterm-256color" || P2.env.TERM === "alacritty" || P2.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
|
|
1070
|
+
}
|
|
1071
|
+
var ee = ht2();
|
|
1072
|
+
var ue = () => process.env.CI === "true";
|
|
1073
|
+
var w2 = (e, r) => ee ? e : r;
|
|
1074
|
+
var Me = w2("\u25C6", "*");
|
|
1075
|
+
var ce = w2("\u25A0", "x");
|
|
1076
|
+
var de = w2("\u25B2", "x");
|
|
1077
|
+
var k2 = w2("\u25C7", "o");
|
|
1078
|
+
var $e = w2("\u250C", "T");
|
|
1079
|
+
var h = w2("\u2502", "|");
|
|
1080
|
+
var x2 = w2("\u2514", "\u2014");
|
|
1081
|
+
var Re = w2("\u2510", "T");
|
|
1082
|
+
var Oe = w2("\u2518", "\u2014");
|
|
1083
|
+
var Y = w2("\u25CF", ">");
|
|
1084
|
+
var K2 = w2("\u25CB", " ");
|
|
1085
|
+
var te = w2("\u25FB", "[\u2022]");
|
|
1086
|
+
var G2 = w2("\u25FC", "[+]");
|
|
1087
|
+
var z2 = w2("\u25FB", "[ ]");
|
|
1088
|
+
var Pe = w2("\u25AA", "\u2022");
|
|
1089
|
+
var se = w2("\u2500", "-");
|
|
1090
|
+
var he = w2("\u256E", "+");
|
|
1091
|
+
var Ne = w2("\u251C", "+");
|
|
1092
|
+
var me = w2("\u256F", "+");
|
|
1093
|
+
var pe = w2("\u2570", "+");
|
|
1094
|
+
var We = w2("\u256D", "+");
|
|
1095
|
+
var ge = w2("\u25CF", "\u2022");
|
|
1096
|
+
var fe = w2("\u25C6", "*");
|
|
1097
|
+
var Fe = w2("\u25B2", "!");
|
|
1098
|
+
var ye = w2("\u25A0", "x");
|
|
1099
|
+
var N2 = (e) => {
|
|
1100
|
+
switch (e) {
|
|
1101
|
+
case "initial":
|
|
1102
|
+
case "active":
|
|
1103
|
+
return import_picocolors2.default.cyan(Me);
|
|
1104
|
+
case "cancel":
|
|
1105
|
+
return import_picocolors2.default.red(ce);
|
|
1106
|
+
case "error":
|
|
1107
|
+
return import_picocolors2.default.yellow(de);
|
|
1108
|
+
case "submit":
|
|
1109
|
+
return import_picocolors2.default.green(k2);
|
|
1110
|
+
}
|
|
1111
|
+
};
|
|
1112
|
+
var Ee = (e) => {
|
|
1113
|
+
switch (e) {
|
|
1114
|
+
case "initial":
|
|
1115
|
+
case "active":
|
|
1116
|
+
return import_picocolors2.default.cyan(h);
|
|
1117
|
+
case "cancel":
|
|
1118
|
+
return import_picocolors2.default.red(h);
|
|
1119
|
+
case "error":
|
|
1120
|
+
return import_picocolors2.default.yellow(h);
|
|
1121
|
+
case "submit":
|
|
1122
|
+
return import_picocolors2.default.green(h);
|
|
1123
|
+
}
|
|
1124
|
+
};
|
|
1125
|
+
var mt2 = (e) => e === 161 || e === 164 || e === 167 || e === 168 || e === 170 || e === 173 || e === 174 || e >= 176 && e <= 180 || e >= 182 && e <= 186 || e >= 188 && e <= 191 || e === 198 || e === 208 || e === 215 || e === 216 || e >= 222 && e <= 225 || e === 230 || e >= 232 && e <= 234 || e === 236 || e === 237 || e === 240 || e === 242 || e === 243 || e >= 247 && e <= 250 || e === 252 || e === 254 || e === 257 || e === 273 || e === 275 || e === 283 || e === 294 || e === 295 || e === 299 || e >= 305 && e <= 307 || e === 312 || e >= 319 && e <= 322 || e === 324 || e >= 328 && e <= 331 || e === 333 || e === 338 || e === 339 || e === 358 || e === 359 || e === 363 || e === 462 || e === 464 || e === 466 || e === 468 || e === 470 || e === 472 || e === 474 || e === 476 || e === 593 || e === 609 || e === 708 || e === 711 || e >= 713 && e <= 715 || e === 717 || e === 720 || e >= 728 && e <= 731 || e === 733 || e === 735 || e >= 768 && e <= 879 || e >= 913 && e <= 929 || e >= 931 && e <= 937 || e >= 945 && e <= 961 || e >= 963 && e <= 969 || e === 1025 || e >= 1040 && e <= 1103 || e === 1105 || e === 8208 || e >= 8211 && e <= 8214 || e === 8216 || e === 8217 || e === 8220 || e === 8221 || e >= 8224 && e <= 8226 || e >= 8228 && e <= 8231 || e === 8240 || e === 8242 || e === 8243 || e === 8245 || e === 8251 || e === 8254 || e === 8308 || e === 8319 || e >= 8321 && e <= 8324 || e === 8364 || e === 8451 || e === 8453 || e === 8457 || e === 8467 || e === 8470 || e === 8481 || e === 8482 || e === 8486 || e === 8491 || e === 8531 || e === 8532 || e >= 8539 && e <= 8542 || e >= 8544 && e <= 8555 || e >= 8560 && e <= 8569 || e === 8585 || e >= 8592 && e <= 8601 || e === 8632 || e === 8633 || e === 8658 || e === 8660 || e === 8679 || e === 8704 || e === 8706 || e === 8707 || e === 8711 || e === 8712 || e === 8715 || e === 8719 || e === 8721 || e === 8725 || e === 8730 || e >= 8733 && e <= 8736 || e === 8739 || e === 8741 || e >= 8743 && e <= 8748 || e === 8750 || e >= 8756 && e <= 8759 || e === 8764 || e === 8765 || e === 8776 || e === 8780 || e === 8786 || e === 8800 || e === 8801 || e >= 8804 && e <= 8807 || e === 8810 || e === 8811 || e === 8814 || e === 8815 || e === 8834 || e === 8835 || e === 8838 || e === 8839 || e === 8853 || e === 8857 || e === 8869 || e === 8895 || e === 8978 || e >= 9312 && e <= 9449 || e >= 9451 && e <= 9547 || e >= 9552 && e <= 9587 || e >= 9600 && e <= 9615 || e >= 9618 && e <= 9621 || e === 9632 || e === 9633 || e >= 9635 && e <= 9641 || e === 9650 || e === 9651 || e === 9654 || e === 9655 || e === 9660 || e === 9661 || e === 9664 || e === 9665 || e >= 9670 && e <= 9672 || e === 9675 || e >= 9678 && e <= 9681 || e >= 9698 && e <= 9701 || e === 9711 || e === 9733 || e === 9734 || e === 9737 || e === 9742 || e === 9743 || e === 9756 || e === 9758 || e === 9792 || e === 9794 || e === 9824 || e === 9825 || e >= 9827 && e <= 9829 || e >= 9831 && e <= 9834 || e === 9836 || e === 9837 || e === 9839 || e === 9886 || e === 9887 || e === 9919 || e >= 9926 && e <= 9933 || e >= 9935 && e <= 9939 || e >= 9941 && e <= 9953 || e === 9955 || e === 9960 || e === 9961 || e >= 9963 && e <= 9969 || e === 9972 || e >= 9974 && e <= 9977 || e === 9979 || e === 9980 || e === 9982 || e === 9983 || e === 10045 || e >= 10102 && e <= 10111 || e >= 11094 && e <= 11097 || e >= 12872 && e <= 12879 || e >= 57344 && e <= 63743 || e >= 65024 && e <= 65039 || e === 65533 || e >= 127232 && e <= 127242 || e >= 127248 && e <= 127277 || e >= 127280 && e <= 127337 || e >= 127344 && e <= 127373 || e === 127375 || e === 127376 || e >= 127387 && e <= 127404 || e >= 917760 && e <= 917999 || e >= 983040 && e <= 1048573 || e >= 1048576 && e <= 1114109;
|
|
1126
|
+
var pt2 = (e) => e === 12288 || e >= 65281 && e <= 65376 || e >= 65504 && e <= 65510;
|
|
1127
|
+
var gt2 = (e) => e >= 4352 && e <= 4447 || e === 8986 || e === 8987 || e === 9001 || e === 9002 || e >= 9193 && e <= 9196 || e === 9200 || e === 9203 || e === 9725 || e === 9726 || e === 9748 || e === 9749 || e >= 9800 && e <= 9811 || e === 9855 || e === 9875 || e === 9889 || e === 9898 || e === 9899 || e === 9917 || e === 9918 || e === 9924 || e === 9925 || e === 9934 || e === 9940 || e === 9962 || e === 9970 || e === 9971 || e === 9973 || e === 9978 || e === 9981 || e === 9989 || e === 9994 || e === 9995 || e === 10024 || e === 10060 || e === 10062 || e >= 10067 && e <= 10069 || e === 10071 || e >= 10133 && e <= 10135 || e === 10160 || e === 10175 || e === 11035 || e === 11036 || e === 11088 || e === 11093 || e >= 11904 && e <= 11929 || e >= 11931 && e <= 12019 || e >= 12032 && e <= 12245 || e >= 12272 && e <= 12287 || e >= 12289 && e <= 12350 || e >= 12353 && e <= 12438 || e >= 12441 && e <= 12543 || e >= 12549 && e <= 12591 || e >= 12593 && e <= 12686 || e >= 12688 && e <= 12771 || e >= 12783 && e <= 12830 || e >= 12832 && e <= 12871 || e >= 12880 && e <= 19903 || e >= 19968 && e <= 42124 || e >= 42128 && e <= 42182 || e >= 43360 && e <= 43388 || e >= 44032 && e <= 55203 || e >= 63744 && e <= 64255 || e >= 65040 && e <= 65049 || e >= 65072 && e <= 65106 || e >= 65108 && e <= 65126 || e >= 65128 && e <= 65131 || e >= 94176 && e <= 94180 || e === 94192 || e === 94193 || e >= 94208 && e <= 100343 || e >= 100352 && e <= 101589 || e >= 101632 && e <= 101640 || e >= 110576 && e <= 110579 || e >= 110581 && e <= 110587 || e === 110589 || e === 110590 || e >= 110592 && e <= 110882 || e === 110898 || e >= 110928 && e <= 110930 || e === 110933 || e >= 110948 && e <= 110951 || e >= 110960 && e <= 111355 || e === 126980 || e === 127183 || e === 127374 || e >= 127377 && e <= 127386 || e >= 127488 && e <= 127490 || e >= 127504 && e <= 127547 || e >= 127552 && e <= 127560 || e === 127568 || e === 127569 || e >= 127584 && e <= 127589 || e >= 127744 && e <= 127776 || e >= 127789 && e <= 127797 || e >= 127799 && e <= 127868 || e >= 127870 && e <= 127891 || e >= 127904 && e <= 127946 || e >= 127951 && e <= 127955 || e >= 127968 && e <= 127984 || e === 127988 || e >= 127992 && e <= 128062 || e === 128064 || e >= 128066 && e <= 128252 || e >= 128255 && e <= 128317 || e >= 128331 && e <= 128334 || e >= 128336 && e <= 128359 || e === 128378 || e === 128405 || e === 128406 || e === 128420 || e >= 128507 && e <= 128591 || e >= 128640 && e <= 128709 || e === 128716 || e >= 128720 && e <= 128722 || e >= 128725 && e <= 128727 || e >= 128732 && e <= 128735 || e === 128747 || e === 128748 || e >= 128756 && e <= 128764 || e >= 128992 && e <= 129003 || e === 129008 || e >= 129292 && e <= 129338 || e >= 129340 && e <= 129349 || e >= 129351 && e <= 129535 || e >= 129648 && e <= 129660 || e >= 129664 && e <= 129672 || e >= 129680 && e <= 129725 || e >= 129727 && e <= 129733 || e >= 129742 && e <= 129755 || e >= 129760 && e <= 129768 || e >= 129776 && e <= 129784 || e >= 131072 && e <= 196605 || e >= 196608 && e <= 262141;
|
|
1128
|
+
var ve = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/y;
|
|
1129
|
+
var re = /[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y;
|
|
1130
|
+
var ie = /\t{1,1000}/y;
|
|
1131
|
+
var Ae = /[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/yu;
|
|
1132
|
+
var ne = /(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y;
|
|
1133
|
+
var ft2 = /\p{M}+/gu;
|
|
1134
|
+
var Ft2 = { limit: 1 / 0, ellipsis: "" };
|
|
1135
|
+
var Le = (e, r = {}, s = {}) => {
|
|
1136
|
+
const i = r.limit ?? 1 / 0, n = r.ellipsis ?? "", o = r?.ellipsisWidth ?? (n ? Le(n, Ft2, s).width : 0), u = s.ansiWidth ?? 0, l = s.controlWidth ?? 0, a = s.tabWidth ?? 8, d = s.ambiguousWidth ?? 1, g = s.emojiWidth ?? 2, E = s.fullWidthWidth ?? 2, p = s.regularWidth ?? 1, y2 = s.wideWidth ?? 2;
|
|
1137
|
+
let $ = 0, c = 0, m = e.length, f = 0, F = false, v = m, S2 = Math.max(0, i - o), B = 0, b = 0, A = 0, C = 0;
|
|
1138
|
+
e:
|
|
1139
|
+
for (;; ) {
|
|
1140
|
+
if (b > B || c >= m && c > $) {
|
|
1141
|
+
const _2 = e.slice(B, b) || e.slice($, c);
|
|
1142
|
+
f = 0;
|
|
1143
|
+
for (const D2 of _2.replaceAll(ft2, "")) {
|
|
1144
|
+
const T2 = D2.codePointAt(0) || 0;
|
|
1145
|
+
if (pt2(T2) ? C = E : gt2(T2) ? C = y2 : d !== p && mt2(T2) ? C = d : C = p, A + C > S2 && (v = Math.min(v, Math.max(B, $) + f)), A + C > i) {
|
|
1146
|
+
F = true;
|
|
1147
|
+
break e;
|
|
1148
|
+
}
|
|
1149
|
+
f += D2.length, A += C;
|
|
1150
|
+
}
|
|
1151
|
+
B = b = 0;
|
|
1152
|
+
}
|
|
1153
|
+
if (c >= m)
|
|
1154
|
+
break;
|
|
1155
|
+
if (ne.lastIndex = c, ne.test(e)) {
|
|
1156
|
+
if (f = ne.lastIndex - c, C = f * p, A + C > S2 && (v = Math.min(v, c + Math.floor((S2 - A) / p))), A + C > i) {
|
|
1157
|
+
F = true;
|
|
1158
|
+
break;
|
|
1159
|
+
}
|
|
1160
|
+
A += C, B = $, b = c, c = $ = ne.lastIndex;
|
|
1161
|
+
continue;
|
|
1162
|
+
}
|
|
1163
|
+
if (ve.lastIndex = c, ve.test(e)) {
|
|
1164
|
+
if (A + u > S2 && (v = Math.min(v, c)), A + u > i) {
|
|
1165
|
+
F = true;
|
|
1166
|
+
break;
|
|
1167
|
+
}
|
|
1168
|
+
A += u, B = $, b = c, c = $ = ve.lastIndex;
|
|
1169
|
+
continue;
|
|
1170
|
+
}
|
|
1171
|
+
if (re.lastIndex = c, re.test(e)) {
|
|
1172
|
+
if (f = re.lastIndex - c, C = f * l, A + C > S2 && (v = Math.min(v, c + Math.floor((S2 - A) / l))), A + C > i) {
|
|
1173
|
+
F = true;
|
|
1174
|
+
break;
|
|
1175
|
+
}
|
|
1176
|
+
A += C, B = $, b = c, c = $ = re.lastIndex;
|
|
1177
|
+
continue;
|
|
1178
|
+
}
|
|
1179
|
+
if (ie.lastIndex = c, ie.test(e)) {
|
|
1180
|
+
if (f = ie.lastIndex - c, C = f * a, A + C > S2 && (v = Math.min(v, c + Math.floor((S2 - A) / a))), A + C > i) {
|
|
1181
|
+
F = true;
|
|
1182
|
+
break;
|
|
1183
|
+
}
|
|
1184
|
+
A += C, B = $, b = c, c = $ = ie.lastIndex;
|
|
1185
|
+
continue;
|
|
1186
|
+
}
|
|
1187
|
+
if (Ae.lastIndex = c, Ae.test(e)) {
|
|
1188
|
+
if (A + g > S2 && (v = Math.min(v, c)), A + g > i) {
|
|
1189
|
+
F = true;
|
|
1190
|
+
break;
|
|
1191
|
+
}
|
|
1192
|
+
A += g, B = $, b = c, c = $ = Ae.lastIndex;
|
|
1193
|
+
continue;
|
|
1194
|
+
}
|
|
1195
|
+
c += 1;
|
|
1196
|
+
}
|
|
1197
|
+
return { width: F ? S2 : A, index: F ? v : m, truncated: F, ellipsed: F && i >= o };
|
|
1198
|
+
};
|
|
1199
|
+
var yt2 = { limit: 1 / 0, ellipsis: "", ellipsisWidth: 0 };
|
|
1200
|
+
var M2 = (e, r = {}) => Le(e, yt2, r).width;
|
|
1201
|
+
var ae = "\x1B";
|
|
1202
|
+
var je = "\x9B";
|
|
1203
|
+
var Et2 = 39;
|
|
1204
|
+
var Ce = "\x07";
|
|
1205
|
+
var Ve = "[";
|
|
1206
|
+
var vt2 = "]";
|
|
1207
|
+
var ke = "m";
|
|
1208
|
+
var we = `${vt2}8;;`;
|
|
1209
|
+
var Ge = new RegExp(`(?:\\${Ve}(?<code>\\d+)m|\\${we}(?<uri>.*)${Ce})`, "y");
|
|
1210
|
+
var At2 = (e) => {
|
|
1211
|
+
if (e >= 30 && e <= 37 || e >= 90 && e <= 97)
|
|
1212
|
+
return 39;
|
|
1213
|
+
if (e >= 40 && e <= 47 || e >= 100 && e <= 107)
|
|
1214
|
+
return 49;
|
|
1215
|
+
if (e === 1 || e === 2)
|
|
1216
|
+
return 22;
|
|
1217
|
+
if (e === 3)
|
|
1218
|
+
return 23;
|
|
1219
|
+
if (e === 4)
|
|
1220
|
+
return 24;
|
|
1221
|
+
if (e === 7)
|
|
1222
|
+
return 27;
|
|
1223
|
+
if (e === 8)
|
|
1224
|
+
return 28;
|
|
1225
|
+
if (e === 9)
|
|
1226
|
+
return 29;
|
|
1227
|
+
if (e === 0)
|
|
1228
|
+
return 0;
|
|
1229
|
+
};
|
|
1230
|
+
var He = (e) => `${ae}${Ve}${e}${ke}`;
|
|
1231
|
+
var Ue = (e) => `${ae}${we}${e}${Ce}`;
|
|
1232
|
+
var Ct2 = (e) => e.map((r) => M2(r));
|
|
1233
|
+
var Se = (e, r, s) => {
|
|
1234
|
+
const i = r[Symbol.iterator]();
|
|
1235
|
+
let n = false, o = false, u = e.at(-1), l = u === undefined ? 0 : M2(u), a = i.next(), d = i.next(), g = 0;
|
|
1236
|
+
for (;!a.done; ) {
|
|
1237
|
+
const E = a.value, p = M2(E);
|
|
1238
|
+
l + p <= s ? e[e.length - 1] += E : (e.push(E), l = 0), (E === ae || E === je) && (n = true, o = r.startsWith(we, g + 1)), n ? o ? E === Ce && (n = false, o = false) : E === ke && (n = false) : (l += p, l === s && !d.done && (e.push(""), l = 0)), a = d, d = i.next(), g += E.length;
|
|
1239
|
+
}
|
|
1240
|
+
u = e.at(-1), !l && u !== undefined && u.length > 0 && e.length > 1 && (e[e.length - 2] += e.pop());
|
|
1241
|
+
};
|
|
1242
|
+
var wt2 = (e) => {
|
|
1243
|
+
const r = e.split(" ");
|
|
1244
|
+
let s = r.length;
|
|
1245
|
+
for (;s > 0 && !(M2(r[s - 1]) > 0); )
|
|
1246
|
+
s--;
|
|
1247
|
+
return s === r.length ? e : r.slice(0, s).join(" ") + r.slice(s).join("");
|
|
1248
|
+
};
|
|
1249
|
+
var St2 = (e, r, s = {}) => {
|
|
1250
|
+
if (s.trim !== false && e.trim() === "")
|
|
1251
|
+
return "";
|
|
1252
|
+
let i = "", n, o;
|
|
1253
|
+
const u = e.split(" "), l = Ct2(u);
|
|
1254
|
+
let a = [""];
|
|
1255
|
+
for (const [$, c] of u.entries()) {
|
|
1256
|
+
s.trim !== false && (a[a.length - 1] = (a.at(-1) ?? "").trimStart());
|
|
1257
|
+
let m = M2(a.at(-1) ?? "");
|
|
1258
|
+
if ($ !== 0 && (m >= r && (s.wordWrap === false || s.trim === false) && (a.push(""), m = 0), (m > 0 || s.trim === false) && (a[a.length - 1] += " ", m++)), s.hard && l[$] > r) {
|
|
1259
|
+
const f = r - m, F = 1 + Math.floor((l[$] - f - 1) / r);
|
|
1260
|
+
Math.floor((l[$] - 1) / r) < F && a.push(""), Se(a, c, r);
|
|
1261
|
+
continue;
|
|
1262
|
+
}
|
|
1263
|
+
if (m + l[$] > r && m > 0 && l[$] > 0) {
|
|
1264
|
+
if (s.wordWrap === false && m < r) {
|
|
1265
|
+
Se(a, c, r);
|
|
1266
|
+
continue;
|
|
1267
|
+
}
|
|
1268
|
+
a.push("");
|
|
1269
|
+
}
|
|
1270
|
+
if (m + l[$] > r && s.wordWrap === false) {
|
|
1271
|
+
Se(a, c, r);
|
|
1272
|
+
continue;
|
|
1273
|
+
}
|
|
1274
|
+
a[a.length - 1] += c;
|
|
1275
|
+
}
|
|
1276
|
+
s.trim !== false && (a = a.map(($) => wt2($)));
|
|
1277
|
+
const d = a.join(`
|
|
1278
|
+
`), g = d[Symbol.iterator]();
|
|
1279
|
+
let E = g.next(), p = g.next(), y2 = 0;
|
|
1280
|
+
for (;!E.done; ) {
|
|
1281
|
+
const $ = E.value, c = p.value;
|
|
1282
|
+
if (i += $, $ === ae || $ === je) {
|
|
1283
|
+
Ge.lastIndex = y2 + 1;
|
|
1284
|
+
const F = Ge.exec(d)?.groups;
|
|
1285
|
+
if (F?.code !== undefined) {
|
|
1286
|
+
const v = Number.parseFloat(F.code);
|
|
1287
|
+
n = v === Et2 ? undefined : v;
|
|
1288
|
+
} else
|
|
1289
|
+
F?.uri !== undefined && (o = F.uri.length === 0 ? undefined : F.uri);
|
|
1290
|
+
}
|
|
1291
|
+
const m = n ? At2(n) : undefined;
|
|
1292
|
+
c === `
|
|
1293
|
+
` ? (o && (i += Ue("")), n && m && (i += He(m))) : $ === `
|
|
1294
|
+
` && (n && m && (i += He(n)), o && (i += Ue(o))), y2 += $.length, E = p, p = g.next();
|
|
1295
|
+
}
|
|
1296
|
+
return i;
|
|
1297
|
+
};
|
|
1298
|
+
function q2(e, r, s) {
|
|
1299
|
+
return String(e).normalize().replaceAll(`\r
|
|
1300
|
+
`, `
|
|
1301
|
+
`).split(`
|
|
1302
|
+
`).map((i) => St2(i, r, s)).join(`
|
|
1303
|
+
`);
|
|
1304
|
+
}
|
|
1305
|
+
var It2 = (e, r, s, i, n) => {
|
|
1306
|
+
let o = r, u = 0;
|
|
1307
|
+
for (let l = s;l < i; l++) {
|
|
1308
|
+
const a = e[l];
|
|
1309
|
+
if (o = o - a.length, u++, o <= n)
|
|
1310
|
+
break;
|
|
1311
|
+
}
|
|
1312
|
+
return { lineCount: o, removals: u };
|
|
1313
|
+
};
|
|
1314
|
+
var J2 = (e) => {
|
|
1315
|
+
const { cursor: r, options: s, style: i } = e, n = e.output ?? process.stdout, o = rt(n), u = e.columnPadding ?? 0, l = e.rowPadding ?? 4, a = o - u, d = nt(n), g = import_picocolors2.default.dim("..."), E = e.maxItems ?? Number.POSITIVE_INFINITY, p = Math.max(d - l, 0), y2 = Math.max(Math.min(E, p), 5);
|
|
1316
|
+
let $ = 0;
|
|
1317
|
+
r >= y2 - 3 && ($ = Math.max(Math.min(r - y2 + 3, s.length - y2), 0));
|
|
1318
|
+
let c = y2 < s.length && $ > 0, m = y2 < s.length && $ + y2 < s.length;
|
|
1319
|
+
const f = Math.min($ + y2, s.length), F = [];
|
|
1320
|
+
let v = 0;
|
|
1321
|
+
c && v++, m && v++;
|
|
1322
|
+
const S2 = $ + (c ? 1 : 0), B = f - (m ? 1 : 0);
|
|
1323
|
+
for (let A = S2;A < B; A++) {
|
|
1324
|
+
const C = q2(i(s[A], A === r), a, { hard: true, trim: false }).split(`
|
|
1325
|
+
`);
|
|
1326
|
+
F.push(C), v += C.length;
|
|
1327
|
+
}
|
|
1328
|
+
if (v > p) {
|
|
1329
|
+
let A = 0, C = 0, _2 = v;
|
|
1330
|
+
const D2 = r - S2, T2 = (W2, I2) => It2(F, _2, W2, I2, p);
|
|
1331
|
+
c ? ({ lineCount: _2, removals: A } = T2(0, D2), _2 > p && ({ lineCount: _2, removals: C } = T2(D2 + 1, F.length))) : ({ lineCount: _2, removals: C } = T2(D2 + 1, F.length), _2 > p && ({ lineCount: _2, removals: A } = T2(0, D2))), A > 0 && (c = true, F.splice(0, A)), C > 0 && (m = true, F.splice(F.length - C, C));
|
|
1332
|
+
}
|
|
1333
|
+
const b = [];
|
|
1334
|
+
c && b.push(g);
|
|
1335
|
+
for (const A of F)
|
|
1336
|
+
for (const C of A)
|
|
1337
|
+
b.push(C);
|
|
1338
|
+
return m && b.push(g), b;
|
|
1339
|
+
};
|
|
1340
|
+
var Mt2 = (e) => {
|
|
1341
|
+
const r = e.active ?? "Yes", s = e.inactive ?? "No";
|
|
1342
|
+
return new kt({ active: r, inactive: s, signal: e.signal, input: e.input, output: e.output, initialValue: e.initialValue ?? true, render() {
|
|
1343
|
+
const i = `${import_picocolors2.default.gray(h)}
|
|
1344
|
+
${N2(this.state)} ${e.message}
|
|
1345
|
+
`, n = this.value ? r : s;
|
|
1346
|
+
switch (this.state) {
|
|
1347
|
+
case "submit":
|
|
1348
|
+
return `${i}${import_picocolors2.default.gray(h)} ${import_picocolors2.default.dim(n)}`;
|
|
1349
|
+
case "cancel":
|
|
1350
|
+
return `${i}${import_picocolors2.default.gray(h)} ${import_picocolors2.default.strikethrough(import_picocolors2.default.dim(n))}
|
|
1351
|
+
${import_picocolors2.default.gray(h)}`;
|
|
1352
|
+
default:
|
|
1353
|
+
return `${i}${import_picocolors2.default.cyan(h)} ${this.value ? `${import_picocolors2.default.green(Y)} ${r}` : `${import_picocolors2.default.dim(K2)} ${import_picocolors2.default.dim(r)}`} ${import_picocolors2.default.dim("/")} ${this.value ? `${import_picocolors2.default.dim(K2)} ${import_picocolors2.default.dim(s)}` : `${import_picocolors2.default.green(Y)} ${s}`}
|
|
1354
|
+
${import_picocolors2.default.cyan(x2)}
|
|
1355
|
+
`;
|
|
1356
|
+
}
|
|
1357
|
+
} }).prompt();
|
|
1358
|
+
};
|
|
1359
|
+
var Ut = import_picocolors2.default.magenta;
|
|
1360
|
+
var Ie = ({ indicator: e = "dots", onCancel: r, output: s = process.stdout, cancelMessage: i, errorMessage: n, frames: o = ee ? ["\u25D2", "\u25D0", "\u25D3", "\u25D1"] : ["\u2022", "o", "O", "0"], delay: u = ee ? 80 : 120, signal: l, ...a } = {}) => {
|
|
1361
|
+
const d = ue();
|
|
1362
|
+
let g, E, p = false, y2 = false, $ = "", c, m = performance.now();
|
|
1363
|
+
const f = rt(s), F = a?.styleFrame ?? Ut, v = (I2) => {
|
|
1364
|
+
const O2 = I2 > 1 ? n ?? _.messages.error : i ?? _.messages.cancel;
|
|
1365
|
+
y2 = I2 === 1, p && (W2(O2, I2), y2 && typeof r == "function" && r());
|
|
1366
|
+
}, S2 = () => v(2), B = () => v(1), b = () => {
|
|
1367
|
+
process.on("uncaughtExceptionMonitor", S2), process.on("unhandledRejection", S2), process.on("SIGINT", B), process.on("SIGTERM", B), process.on("exit", v), l && l.addEventListener("abort", B);
|
|
1368
|
+
}, A = () => {
|
|
1369
|
+
process.removeListener("uncaughtExceptionMonitor", S2), process.removeListener("unhandledRejection", S2), process.removeListener("SIGINT", B), process.removeListener("SIGTERM", B), process.removeListener("exit", v), l && l.removeEventListener("abort", B);
|
|
1370
|
+
}, C = () => {
|
|
1371
|
+
if (c === undefined)
|
|
1372
|
+
return;
|
|
1373
|
+
d && s.write(`
|
|
1374
|
+
`);
|
|
1375
|
+
const I2 = q2(c, f, { hard: true, trim: false }).split(`
|
|
1376
|
+
`);
|
|
1377
|
+
I2.length > 1 && s.write(import_sisteransi2.cursor.up(I2.length - 1)), s.write(import_sisteransi2.cursor.to(0)), s.write(import_sisteransi2.erase.down());
|
|
1378
|
+
}, _2 = (I2) => I2.replace(/\.+$/, ""), D2 = (I2) => {
|
|
1379
|
+
const O2 = (performance.now() - I2) / 1000, L2 = Math.floor(O2 / 60), j2 = Math.floor(O2 % 60);
|
|
1380
|
+
return L2 > 0 ? `[${L2}m ${j2}s]` : `[${j2}s]`;
|
|
1381
|
+
}, T2 = (I2 = "") => {
|
|
1382
|
+
p = true, g = xt({ output: s }), $ = _2(I2), m = performance.now(), s.write(`${import_picocolors2.default.gray(h)}
|
|
1383
|
+
`);
|
|
1384
|
+
let O2 = 0, L2 = 0;
|
|
1385
|
+
b(), E = setInterval(() => {
|
|
1386
|
+
if (d && $ === c)
|
|
1387
|
+
return;
|
|
1388
|
+
C(), c = $;
|
|
1389
|
+
const j2 = F(o[O2]);
|
|
1390
|
+
let Z2;
|
|
1391
|
+
if (d)
|
|
1392
|
+
Z2 = `${j2} ${$}...`;
|
|
1393
|
+
else if (e === "timer")
|
|
1394
|
+
Z2 = `${j2} ${$} ${D2(m)}`;
|
|
1395
|
+
else {
|
|
1396
|
+
const Ze = ".".repeat(Math.floor(L2)).slice(0, 3);
|
|
1397
|
+
Z2 = `${j2} ${$}${Ze}`;
|
|
1398
|
+
}
|
|
1399
|
+
const Qe = q2(Z2, f, { hard: true, trim: false });
|
|
1400
|
+
s.write(Qe), O2 = O2 + 1 < o.length ? O2 + 1 : 0, L2 = L2 < 4 ? L2 + 0.125 : 0;
|
|
1401
|
+
}, u);
|
|
1402
|
+
}, W2 = (I2 = "", O2 = 0, L2 = false) => {
|
|
1403
|
+
if (!p)
|
|
1404
|
+
return;
|
|
1405
|
+
p = false, clearInterval(E), C();
|
|
1406
|
+
const j2 = O2 === 0 ? import_picocolors2.default.green(k2) : O2 === 1 ? import_picocolors2.default.red(ce) : import_picocolors2.default.red(de);
|
|
1407
|
+
$ = I2 ?? $, L2 || (e === "timer" ? s.write(`${j2} ${$} ${D2(m)}
|
|
1408
|
+
`) : s.write(`${j2} ${$}
|
|
1409
|
+
`)), A(), g();
|
|
1410
|
+
};
|
|
1411
|
+
return { start: T2, stop: (I2 = "") => W2(I2, 0), message: (I2 = "") => {
|
|
1412
|
+
$ = _2(I2 ?? $);
|
|
1413
|
+
}, cancel: (I2 = "") => W2(I2, 1), error: (I2 = "") => W2(I2, 2), clear: () => W2("", 0, true), get isCancelled() {
|
|
1414
|
+
return y2;
|
|
1415
|
+
} };
|
|
1416
|
+
};
|
|
1417
|
+
var Ye = { light: w2("\u2500", "-"), heavy: w2("\u2501", "="), block: w2("\u2588", "#") };
|
|
1418
|
+
var oe = (e, r) => e.includes(`
|
|
1419
|
+
`) ? e.split(`
|
|
1420
|
+
`).map((s) => r(s)).join(`
|
|
1421
|
+
`) : r(e);
|
|
1422
|
+
var qt = (e) => {
|
|
1423
|
+
const r = (s, i) => {
|
|
1424
|
+
const n = s.label ?? String(s.value);
|
|
1425
|
+
switch (i) {
|
|
1426
|
+
case "disabled":
|
|
1427
|
+
return `${import_picocolors2.default.gray(K2)} ${oe(n, import_picocolors2.default.gray)}${s.hint ? ` ${import_picocolors2.default.dim(`(${s.hint ?? "disabled"})`)}` : ""}`;
|
|
1428
|
+
case "selected":
|
|
1429
|
+
return `${oe(n, import_picocolors2.default.dim)}`;
|
|
1430
|
+
case "active":
|
|
1431
|
+
return `${import_picocolors2.default.green(Y)} ${n}${s.hint ? ` ${import_picocolors2.default.dim(`(${s.hint})`)}` : ""}`;
|
|
1432
|
+
case "cancelled":
|
|
1433
|
+
return `${oe(n, (o) => import_picocolors2.default.strikethrough(import_picocolors2.default.dim(o)))}`;
|
|
1434
|
+
default:
|
|
1435
|
+
return `${import_picocolors2.default.dim(K2)} ${oe(n, import_picocolors2.default.dim)}`;
|
|
1436
|
+
}
|
|
1437
|
+
};
|
|
1438
|
+
return new Wt({ options: e.options, signal: e.signal, input: e.input, output: e.output, initialValue: e.initialValue, render() {
|
|
1439
|
+
const s = `${N2(this.state)} `, i = `${Ee(this.state)} `, n = Bt(e.output, e.message, i, s), o = `${import_picocolors2.default.gray(h)}
|
|
1440
|
+
${n}
|
|
1441
|
+
`;
|
|
1442
|
+
switch (this.state) {
|
|
1443
|
+
case "submit": {
|
|
1444
|
+
const u = `${import_picocolors2.default.gray(h)} `, l = Bt(e.output, r(this.options[this.cursor], "selected"), u);
|
|
1445
|
+
return `${o}${l}`;
|
|
1446
|
+
}
|
|
1447
|
+
case "cancel": {
|
|
1448
|
+
const u = `${import_picocolors2.default.gray(h)} `, l = Bt(e.output, r(this.options[this.cursor], "cancelled"), u);
|
|
1449
|
+
return `${o}${l}
|
|
1450
|
+
${import_picocolors2.default.gray(h)}`;
|
|
1451
|
+
}
|
|
1452
|
+
default: {
|
|
1453
|
+
const u = `${import_picocolors2.default.cyan(h)} `, l = o.split(`
|
|
1454
|
+
`).length;
|
|
1455
|
+
return `${o}${u}${J2({ output: e.output, cursor: this.cursor, options: this.options, maxItems: e.maxItems, columnPadding: u.length, rowPadding: l + 2, style: (a, d) => r(a, a.disabled ? "disabled" : d ? "active" : "inactive") }).join(`
|
|
1456
|
+
${u}`)}
|
|
1457
|
+
${import_picocolors2.default.cyan(x2)}
|
|
1458
|
+
`;
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
} }).prompt();
|
|
1462
|
+
};
|
|
1463
|
+
var ze = `${import_picocolors2.default.gray(h)} `;
|
|
1464
|
+
|
|
1465
|
+
// src/ui.ts
|
|
1466
|
+
var logAtLevel = (log, level, message) => {
|
|
1467
|
+
log(level, message);
|
|
1468
|
+
};
|
|
1469
|
+
var confirmYesNo = async (question, defaultValue, log) => {
|
|
1470
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
1471
|
+
logAtLevel(log, "warn", `${question} Using default ${defaultValue ? "yes" : "no"} (stdin not interactive).`);
|
|
1472
|
+
return defaultValue;
|
|
1473
|
+
}
|
|
1474
|
+
const result = await Mt2({
|
|
1475
|
+
message: question,
|
|
1476
|
+
initialValue: defaultValue,
|
|
1477
|
+
active: "yes",
|
|
1478
|
+
inactive: "no"
|
|
1479
|
+
});
|
|
1480
|
+
if (Ct(result)) {
|
|
1481
|
+
logAtLevel(log, "warn", "Prompt cancelled. Using default answer.");
|
|
1482
|
+
return defaultValue;
|
|
1483
|
+
}
|
|
1484
|
+
return Boolean(result);
|
|
1485
|
+
};
|
|
1486
|
+
var selectOne = async (message, options, defaultValue, log) => {
|
|
1487
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
1488
|
+
logAtLevel(log, "warn", `${message} Using default option '${defaultValue}'.`);
|
|
1489
|
+
return defaultValue;
|
|
1490
|
+
}
|
|
1491
|
+
const result = await qt({
|
|
1492
|
+
message,
|
|
1493
|
+
initialValue: defaultValue,
|
|
1494
|
+
options
|
|
1495
|
+
});
|
|
1496
|
+
if (Ct(result)) {
|
|
1497
|
+
logAtLevel(log, "warn", "Prompt cancelled. Using default option.");
|
|
1498
|
+
return defaultValue;
|
|
1499
|
+
}
|
|
1500
|
+
return result;
|
|
1501
|
+
};
|
|
1502
|
+
var runWithSpinner = async (label, run, log, options) => {
|
|
1503
|
+
if (!process.stderr.isTTY) {
|
|
1504
|
+
logAtLevel(log, "info", `${label}...`);
|
|
1505
|
+
try {
|
|
1506
|
+
const result = await run();
|
|
1507
|
+
logAtLevel(log, "info", options?.successMessage ?? `${label} complete.`);
|
|
1508
|
+
return result;
|
|
1509
|
+
} catch (error) {
|
|
1510
|
+
logAtLevel(log, "error", options?.errorMessage ?? `${label} failed.`);
|
|
1511
|
+
throw error;
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
const step = Ie();
|
|
1515
|
+
step.start(label);
|
|
1516
|
+
try {
|
|
1517
|
+
const result = await run();
|
|
1518
|
+
step.stop(options?.successMessage ?? `${label} complete.`);
|
|
1519
|
+
return result;
|
|
1520
|
+
} catch (error) {
|
|
1521
|
+
step.error(options?.errorMessage ?? `${label} failed.`);
|
|
1522
|
+
throw error;
|
|
1523
|
+
}
|
|
1524
|
+
};
|
|
1525
|
+
|
|
1526
|
+
// src/resume.ts
|
|
373
1527
|
var CONFIG_DIR = join3(homedir3(), ".agent-bisync");
|
|
374
|
-
var
|
|
375
|
-
var
|
|
1528
|
+
var CODEX_HOME2 = process.env.CODEX_HOME ? resolve2(process.env.CODEX_HOME) : join3(homedir3(), ".codex");
|
|
1529
|
+
var runCommand = async (cmd, cwd) => {
|
|
1530
|
+
const proc = Bun.spawn(cmd, { cwd, stdout: "pipe", stderr: "pipe" });
|
|
1531
|
+
const stdout = await new Response(proc.stdout).text();
|
|
1532
|
+
const stderr = await new Response(proc.stderr).text();
|
|
1533
|
+
const exitCode = await proc.exited;
|
|
1534
|
+
return { exitCode, stdout, stderr };
|
|
1535
|
+
};
|
|
1536
|
+
var requireCommand = async (cmd, cwd, errorMessage) => {
|
|
1537
|
+
const result = await runCommand(cmd, cwd);
|
|
1538
|
+
if (result.exitCode !== 0) {
|
|
1539
|
+
throw new Error(`${errorMessage}
|
|
1540
|
+
${result.stderr.trim() || result.stdout.trim()}`);
|
|
1541
|
+
}
|
|
1542
|
+
return result.stdout.trim();
|
|
1543
|
+
};
|
|
1544
|
+
var parseGithubProjectPath = (projectPath) => {
|
|
1545
|
+
if (!projectPath)
|
|
1546
|
+
return null;
|
|
1547
|
+
if (!projectPath.startsWith("github:"))
|
|
1548
|
+
return null;
|
|
1549
|
+
const fullName = projectPath.slice("github:".length).trim();
|
|
1550
|
+
return fullName.length > 0 ? fullName : null;
|
|
1551
|
+
};
|
|
1552
|
+
var normalizeGithubRemote = (remoteUrl) => {
|
|
1553
|
+
const trimmed = remoteUrl.trim();
|
|
1554
|
+
const match = trimmed.match(/github\.com[:/](.+?)(?:\.git)?$/i);
|
|
1555
|
+
return match?.[1] ?? null;
|
|
1556
|
+
};
|
|
1557
|
+
var ensureDir = async (path) => {
|
|
1558
|
+
await mkdir(path, { recursive: true });
|
|
1559
|
+
};
|
|
1560
|
+
var fileExists = async (path) => {
|
|
1561
|
+
try {
|
|
1562
|
+
await stat3(path);
|
|
1563
|
+
return true;
|
|
1564
|
+
} catch {
|
|
1565
|
+
return false;
|
|
1566
|
+
}
|
|
1567
|
+
};
|
|
1568
|
+
var downloadToFile = async (url, destination) => {
|
|
1569
|
+
const response = await fetch(url);
|
|
1570
|
+
if (!response.ok) {
|
|
1571
|
+
throw new Error(`Failed to download ${url}: ${response.status}`);
|
|
1572
|
+
}
|
|
1573
|
+
const buffer = await response.arrayBuffer();
|
|
1574
|
+
await ensureDir(dirname(destination));
|
|
1575
|
+
await Bun.write(destination, buffer);
|
|
1576
|
+
};
|
|
1577
|
+
var deriveRolloutDir = (filename) => {
|
|
1578
|
+
const match = filename.match(/^rollout-(\d{4})-(\d{2})-(\d{2})T/);
|
|
1579
|
+
if (match) {
|
|
1580
|
+
return join3(CODEX_HOME2, "sessions", match[1], match[2], match[3]);
|
|
1581
|
+
}
|
|
1582
|
+
const now = new Date;
|
|
1583
|
+
const pad = (value) => value.toString().padStart(2, "0");
|
|
1584
|
+
const year = now.getFullYear().toString();
|
|
1585
|
+
const month = pad(now.getMonth() + 1);
|
|
1586
|
+
const day = pad(now.getDate());
|
|
1587
|
+
return join3(CODEX_HOME2, "sessions", year, month, day);
|
|
1588
|
+
};
|
|
1589
|
+
var parseSessionIndex = (content) => {
|
|
1590
|
+
const lines = content.split(`
|
|
1591
|
+
`);
|
|
1592
|
+
const latestById = new Map;
|
|
1593
|
+
for (const line of lines) {
|
|
1594
|
+
const trimmed = line.trim();
|
|
1595
|
+
if (!trimmed)
|
|
1596
|
+
continue;
|
|
1597
|
+
try {
|
|
1598
|
+
const parsed = JSON.parse(trimmed);
|
|
1599
|
+
if (!parsed.id)
|
|
1600
|
+
continue;
|
|
1601
|
+
const parsedAt = parsed.updated_at ? Date.parse(parsed.updated_at) : 0;
|
|
1602
|
+
const updatedAt = Number.isNaN(parsedAt) ? 0 : parsedAt;
|
|
1603
|
+
const current = latestById.get(parsed.id) ?? 0;
|
|
1604
|
+
if (updatedAt > current) {
|
|
1605
|
+
latestById.set(parsed.id, updatedAt);
|
|
1606
|
+
}
|
|
1607
|
+
} catch {}
|
|
1608
|
+
}
|
|
1609
|
+
return latestById;
|
|
1610
|
+
};
|
|
1611
|
+
var mergeSessionIndex = async (localPath, remotePath) => {
|
|
1612
|
+
const remoteFile = Bun.file(remotePath);
|
|
1613
|
+
if (!await remoteFile.exists())
|
|
1614
|
+
return;
|
|
1615
|
+
const remoteText = await remoteFile.text();
|
|
1616
|
+
if (!remoteText.trim())
|
|
1617
|
+
return;
|
|
1618
|
+
const localFile = Bun.file(localPath);
|
|
1619
|
+
const localText = await localFile.exists() ? await localFile.text() : "";
|
|
1620
|
+
const localLatest = parseSessionIndex(localText);
|
|
1621
|
+
const remoteLines = remoteText.split(`
|
|
1622
|
+
`).filter((line) => line.trim().length > 0);
|
|
1623
|
+
const linesToAppend = [];
|
|
1624
|
+
for (const line of remoteLines) {
|
|
1625
|
+
try {
|
|
1626
|
+
const parsed = JSON.parse(line);
|
|
1627
|
+
if (!parsed.id)
|
|
1628
|
+
continue;
|
|
1629
|
+
const parsedAt = parsed.updated_at ? Date.parse(parsed.updated_at) : 0;
|
|
1630
|
+
const updatedAt = Number.isNaN(parsedAt) ? 0 : parsedAt;
|
|
1631
|
+
const current = localLatest.get(parsed.id) ?? 0;
|
|
1632
|
+
if (updatedAt > current) {
|
|
1633
|
+
linesToAppend.push(line);
|
|
1634
|
+
localLatest.set(parsed.id, updatedAt);
|
|
1635
|
+
}
|
|
1636
|
+
} catch {}
|
|
1637
|
+
}
|
|
1638
|
+
if (linesToAppend.length === 0) {
|
|
1639
|
+
return;
|
|
1640
|
+
}
|
|
1641
|
+
await ensureDir(dirname(localPath));
|
|
1642
|
+
const needsLeadingNewline = localText.length > 0 && !localText.endsWith(`
|
|
1643
|
+
`);
|
|
1644
|
+
const prefix = needsLeadingNewline ? `
|
|
1645
|
+
` : "";
|
|
1646
|
+
const payload = `${prefix}${linesToAppend.join(`
|
|
1647
|
+
`)}
|
|
1648
|
+
`;
|
|
1649
|
+
await appendFile(localPath, payload);
|
|
1650
|
+
};
|
|
1651
|
+
var ensureBaseCommit = async (repoRoot, baseSha, log) => {
|
|
1652
|
+
const check = await runCommand(["git", "cat-file", "-e", `${baseSha}^{commit}`], repoRoot);
|
|
1653
|
+
if (check.exitCode === 0) {
|
|
1654
|
+
return;
|
|
1655
|
+
}
|
|
1656
|
+
log("info", "Base commit not found locally; fetching from origin.");
|
|
1657
|
+
const fetchResult = await runCommand(["git", "fetch", "origin"], repoRoot);
|
|
1658
|
+
if (fetchResult.exitCode !== 0) {
|
|
1659
|
+
throw new Error(fetchResult.stderr.trim() || "Failed to fetch from origin.");
|
|
1660
|
+
}
|
|
1661
|
+
};
|
|
1662
|
+
var isWorktreeDirty = async (repoRoot) => {
|
|
1663
|
+
const result = await runCommand(["git", "status", "--porcelain"], repoRoot);
|
|
1664
|
+
if (result.exitCode !== 0) {
|
|
1665
|
+
throw new Error(result.stderr.trim() || "Failed to inspect worktree status.");
|
|
1666
|
+
}
|
|
1667
|
+
return result.stdout.trim().length > 0;
|
|
1668
|
+
};
|
|
1669
|
+
var stashWorktree = async (repoRoot, sessionId) => {
|
|
1670
|
+
await requireCommand(["git", "stash", "push", "-u", "-m", `bisync resume ${sessionId}`], repoRoot, "Failed to stash local changes.");
|
|
1671
|
+
};
|
|
1672
|
+
var applyPatch = async (repoRoot, patchPath) => {
|
|
1673
|
+
const apply = await runCommand(["git", "apply", "--binary", patchPath], repoRoot);
|
|
1674
|
+
if (apply.exitCode === 0) {
|
|
1675
|
+
return;
|
|
1676
|
+
}
|
|
1677
|
+
const retry = await runCommand(["git", "apply", "--binary", "--3way", patchPath], repoRoot);
|
|
1678
|
+
if (retry.exitCode !== 0) {
|
|
1679
|
+
throw new Error(retry.stderr.trim() || "Failed to apply patch.");
|
|
1680
|
+
}
|
|
1681
|
+
};
|
|
1682
|
+
var getCurrentBranch = async (repoRoot) => {
|
|
1683
|
+
const result = await runCommand(["git", "rev-parse", "--abbrev-ref", "HEAD"], repoRoot);
|
|
1684
|
+
if (result.exitCode !== 0) {
|
|
1685
|
+
return "HEAD";
|
|
1686
|
+
}
|
|
1687
|
+
return result.stdout.trim() || "HEAD";
|
|
1688
|
+
};
|
|
1689
|
+
var checkoutOrCreateBranch = async (repoRoot, branchName, baseSha, log) => {
|
|
1690
|
+
const branchCheck = await runCommand(["git", "show-ref", "--verify", `refs/heads/${branchName}`], repoRoot);
|
|
1691
|
+
if (branchCheck.exitCode === 0) {
|
|
1692
|
+
await requireCommand(["git", "checkout", branchName], repoRoot, `Failed to checkout branch '${branchName}'.`);
|
|
1693
|
+
return;
|
|
1694
|
+
}
|
|
1695
|
+
await ensureBaseCommit(repoRoot, baseSha, log);
|
|
1696
|
+
await requireCommand(["git", "checkout", "-b", branchName, baseSha], repoRoot, `Failed to create branch '${branchName}'.`);
|
|
1697
|
+
};
|
|
1698
|
+
var startCodex = async (repoRoot, externalId) => {
|
|
1699
|
+
const proc = Bun.spawn(["codex", "resume", externalId, "--cd", repoRoot], {
|
|
1700
|
+
cwd: repoRoot,
|
|
1701
|
+
stdin: "inherit",
|
|
1702
|
+
stdout: "inherit",
|
|
1703
|
+
stderr: "inherit"
|
|
1704
|
+
});
|
|
1705
|
+
const exitCode = await proc.exited;
|
|
1706
|
+
if (exitCode !== 0) {
|
|
1707
|
+
throw new Error(`Codex exited with status ${exitCode}`);
|
|
1708
|
+
}
|
|
1709
|
+
};
|
|
1710
|
+
var createResumeWorktree = async (repoRoot, data, log) => {
|
|
1711
|
+
const shortId = data.sessionId.slice(0, 8);
|
|
1712
|
+
const repoName = basename(repoRoot);
|
|
1713
|
+
const worktreePath = resolve2(repoRoot, "..", `${repoName}-bisync-${shortId}`);
|
|
1714
|
+
if (await fileExists(worktreePath)) {
|
|
1715
|
+
throw new Error(`Worktree path already exists: ${worktreePath}`);
|
|
1716
|
+
}
|
|
1717
|
+
const branchName = data.patch.headBranch && data.patch.headBranch !== "HEAD" ? data.patch.headBranch : `bisync/resume/${shortId}`;
|
|
1718
|
+
const branchCheck = await runCommand(["git", "show-ref", "--verify", `refs/heads/${branchName}`], repoRoot);
|
|
1719
|
+
if (branchCheck.exitCode === 0) {
|
|
1720
|
+
await requireCommand(["git", "worktree", "add", worktreePath, branchName], repoRoot, "Failed to create worktree.");
|
|
1721
|
+
} else {
|
|
1722
|
+
await ensureBaseCommit(repoRoot, data.patch.baseSha, log);
|
|
1723
|
+
await requireCommand(["git", "worktree", "add", "-b", branchName, worktreePath, data.patch.baseSha], repoRoot, "Failed to create worktree.");
|
|
1724
|
+
}
|
|
1725
|
+
return worktreePath;
|
|
1726
|
+
};
|
|
1727
|
+
var runResume = async (sessionId, args, deps) => {
|
|
1728
|
+
const response = await runWithSpinner("Preparing resume bundle", async () => await fetch(`${deps.siteUrl}/api/resume`, {
|
|
1729
|
+
method: "POST",
|
|
1730
|
+
headers: {
|
|
1731
|
+
Authorization: `Bearer ${deps.token}`,
|
|
1732
|
+
"Content-Type": "application/json"
|
|
1733
|
+
},
|
|
1734
|
+
body: JSON.stringify({ session_id: sessionId })
|
|
1735
|
+
}), deps.log, {
|
|
1736
|
+
successMessage: "Resume bundle ready.",
|
|
1737
|
+
errorMessage: "Failed while preparing resume bundle."
|
|
1738
|
+
});
|
|
1739
|
+
if (!response.ok) {
|
|
1740
|
+
let errorMessage = `${response.status}`;
|
|
1741
|
+
try {
|
|
1742
|
+
const errorJson = await response.json();
|
|
1743
|
+
errorMessage = errorJson.message ?? errorJson.error ?? errorMessage;
|
|
1744
|
+
} catch {
|
|
1745
|
+
errorMessage = await response.text();
|
|
1746
|
+
}
|
|
1747
|
+
throw new Error(`Resume request failed: ${errorMessage}`);
|
|
1748
|
+
}
|
|
1749
|
+
const data = await response.json();
|
|
1750
|
+
const repoRoot = await requireCommand(["git", "rev-parse", "--show-toplevel"], process.cwd(), "Not inside a Git repository.");
|
|
1751
|
+
const expectedRepo = parseGithubProjectPath(data.projectPath);
|
|
1752
|
+
if (!expectedRepo) {
|
|
1753
|
+
throw new Error("Session is not linked to a GitHub repository.");
|
|
1754
|
+
}
|
|
1755
|
+
const originUrl = await requireCommand(["git", "remote", "get-url", "origin"], repoRoot, "Missing git remote 'origin'.");
|
|
1756
|
+
const actualRepo = normalizeGithubRemote(originUrl);
|
|
1757
|
+
if (actualRepo && actualRepo !== expectedRepo && !args.force) {
|
|
1758
|
+
throw new Error(`Repository mismatch. Expected ${expectedRepo}, found ${actualRepo}. Re-run with --force to continue.`);
|
|
1759
|
+
}
|
|
1760
|
+
let targetRepo = repoRoot;
|
|
1761
|
+
let targetSelection = "current";
|
|
1762
|
+
if (process.stdin.isTTY) {
|
|
1763
|
+
targetSelection = await selectOne("Where should we continue this session?", [
|
|
1764
|
+
{ label: "Current repository", value: "current", hint: repoRoot },
|
|
1765
|
+
{ label: "New worktree", value: "worktree", hint: "Create isolated checkout" }
|
|
1766
|
+
], "current", deps.log);
|
|
1767
|
+
}
|
|
1768
|
+
if (targetSelection === "current") {
|
|
1769
|
+
const dirty = await isWorktreeDirty(repoRoot);
|
|
1770
|
+
if (dirty) {
|
|
1771
|
+
deps.log("warn", "Current repository has uncommitted changes.");
|
|
1772
|
+
if (!process.stdin.isTTY) {
|
|
1773
|
+
throw new Error("Current repository is not clean. Re-run in an interactive terminal to choose stash or worktree.");
|
|
1774
|
+
}
|
|
1775
|
+
const dirtyAction = await selectOne("Current repository is not clean. How should we continue?", [
|
|
1776
|
+
{ label: "Use a new worktree", value: "worktree", hint: "Recommended" },
|
|
1777
|
+
{ label: "Stash current changes and continue here", value: "stash" },
|
|
1778
|
+
{ label: "Cancel resume", value: "cancel" }
|
|
1779
|
+
], "worktree", deps.log);
|
|
1780
|
+
if (dirtyAction === "cancel") {
|
|
1781
|
+
throw new Error("Resume cancelled by user.");
|
|
1782
|
+
}
|
|
1783
|
+
if (dirtyAction === "stash") {
|
|
1784
|
+
await runWithSpinner("Stashing local changes", async () => await stashWorktree(repoRoot, sessionId), deps.log, {
|
|
1785
|
+
successMessage: "Local changes stashed.",
|
|
1786
|
+
errorMessage: "Failed to stash local changes."
|
|
1787
|
+
});
|
|
1788
|
+
} else {
|
|
1789
|
+
targetSelection = "worktree";
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
1792
|
+
}
|
|
1793
|
+
if (targetSelection === "worktree") {
|
|
1794
|
+
targetRepo = await createResumeWorktree(repoRoot, data, deps.log);
|
|
1795
|
+
}
|
|
1796
|
+
if (targetRepo === repoRoot && data.patch.headBranch && data.patch.headBranch !== "HEAD") {
|
|
1797
|
+
const currentBranch = await getCurrentBranch(repoRoot);
|
|
1798
|
+
if (currentBranch !== data.patch.headBranch) {
|
|
1799
|
+
const shouldSwitch = process.stdin.isTTY ? await confirmYesNo(`Switch to session branch '${data.patch.headBranch}' before applying patch?`, true, deps.log) : true;
|
|
1800
|
+
if (shouldSwitch) {
|
|
1801
|
+
await checkoutOrCreateBranch(repoRoot, data.patch.headBranch, data.patch.baseSha, deps.log);
|
|
1802
|
+
}
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
await ensureBaseCommit(repoRoot, data.patch.baseSha, deps.log);
|
|
1806
|
+
const cacheDir = join3(CONFIG_DIR, "resume", sessionId);
|
|
1807
|
+
await ensureDir(cacheDir);
|
|
1808
|
+
const patchPath = join3(cacheDir, "patch.diff");
|
|
1809
|
+
await runWithSpinner("Downloading patch", async () => await downloadToFile(data.patch.url, patchPath), deps.log, {
|
|
1810
|
+
successMessage: "Patch downloaded.",
|
|
1811
|
+
errorMessage: "Failed to download patch."
|
|
1812
|
+
});
|
|
1813
|
+
if ((await Bun.file(patchPath).text()).trim().length > 0) {
|
|
1814
|
+
await runWithSpinner("Applying patch", async () => await applyPatch(targetRepo, patchPath), deps.log, {
|
|
1815
|
+
successMessage: "Patch applied.",
|
|
1816
|
+
errorMessage: "Failed to apply patch."
|
|
1817
|
+
});
|
|
1818
|
+
} else {
|
|
1819
|
+
deps.log("info", "No code changes to apply.");
|
|
1820
|
+
}
|
|
1821
|
+
const codexCacheDir = join3(cacheDir, "codex");
|
|
1822
|
+
await ensureDir(codexCacheDir);
|
|
1823
|
+
if (data.stateFiles.length > 0) {
|
|
1824
|
+
deps.log("info", `Downloading ${data.stateFiles.length} Codex state file(s)...`);
|
|
1825
|
+
} else {
|
|
1826
|
+
deps.log("info", "No Codex state files available to download.");
|
|
1827
|
+
}
|
|
1828
|
+
const stateFileMap = new Map;
|
|
1829
|
+
for (const [index, file] of data.stateFiles.entries()) {
|
|
1830
|
+
const stepLabel = `Downloading state file ${index + 1}/${data.stateFiles.length}: ${file.path}`;
|
|
1831
|
+
const destination = join3(codexCacheDir, file.path);
|
|
1832
|
+
await runWithSpinner(stepLabel, async () => await downloadToFile(file.url, destination), deps.log, {
|
|
1833
|
+
successMessage: `Downloaded ${file.path}.`,
|
|
1834
|
+
errorMessage: `Failed to download ${file.path}.`
|
|
1835
|
+
});
|
|
1836
|
+
stateFileMap.set(file.path, destination);
|
|
1837
|
+
}
|
|
1838
|
+
const rolloutDir = deriveRolloutDir(data.rollout.suggestedFilename);
|
|
1839
|
+
const rolloutPath = join3(rolloutDir, data.rollout.suggestedFilename);
|
|
1840
|
+
await runWithSpinner("Downloading rollout log", async () => await downloadToFile(data.rollout.url, rolloutPath), deps.log, {
|
|
1841
|
+
successMessage: "Rollout downloaded.",
|
|
1842
|
+
errorMessage: "Failed to download rollout log."
|
|
1843
|
+
});
|
|
1844
|
+
deps.log("info", `Rollout stored at ${rolloutPath}`);
|
|
1845
|
+
const sessionIndexRemote = stateFileMap.get("session_index.jsonl");
|
|
1846
|
+
if (sessionIndexRemote) {
|
|
1847
|
+
deps.log("info", "Reconciling session index...");
|
|
1848
|
+
await mergeSessionIndex(join3(CODEX_HOME2, "session_index.jsonl"), sessionIndexRemote);
|
|
1849
|
+
deps.log("info", "Session index merge complete.");
|
|
1850
|
+
}
|
|
1851
|
+
deps.log("info", "Resume state downloaded. Launching Codex...");
|
|
1852
|
+
await startCodex(targetRepo, data.externalId);
|
|
1853
|
+
};
|
|
1854
|
+
|
|
1855
|
+
// src/bin.ts
|
|
1856
|
+
var CONFIG_DIR2 = join4(homedir4(), ".agent-bisync");
|
|
1857
|
+
var CONFIG_PATH = join4(CONFIG_DIR2, "config.json");
|
|
1858
|
+
var DEBUG_LOG_PATH = join4(CONFIG_DIR2, "debug.log");
|
|
376
1859
|
var CLIENT_ID = "bisync-cli";
|
|
377
1860
|
var MAX_LINES_PER_BATCH = 200;
|
|
378
1861
|
var parseArgs = () => {
|
|
@@ -399,6 +1882,8 @@ var printUsage = () => {
|
|
|
399
1882
|
Commands:
|
|
400
1883
|
auth login --site-url <url> Authenticate via device flow
|
|
401
1884
|
auth logout Sign out of the CLI
|
|
1885
|
+
github credential [get|store|erase] Print dynamic git credentials
|
|
1886
|
+
resume <SESSION_ID> Resume a cloud session locally
|
|
402
1887
|
session list List session ids
|
|
403
1888
|
setup [claude|codex] --site-url <url> Configure hooks and authenticate
|
|
404
1889
|
hook <HOOK> Handle Claude/Codex hook input (stdin JSON)
|
|
@@ -414,7 +1899,7 @@ Version: ${version} (Bun ${Bun.version})
|
|
|
414
1899
|
var LOG_LEVEL = "info";
|
|
415
1900
|
var appendDebugLog = (line) => {
|
|
416
1901
|
try {
|
|
417
|
-
mkdirSync(
|
|
1902
|
+
mkdirSync(CONFIG_DIR2, { recursive: true });
|
|
418
1903
|
appendFileSync(DEBUG_LOG_PATH, line);
|
|
419
1904
|
} catch {}
|
|
420
1905
|
};
|
|
@@ -451,21 +1936,6 @@ var readConfigIfExists = async () => {
|
|
|
451
1936
|
return null;
|
|
452
1937
|
}
|
|
453
1938
|
};
|
|
454
|
-
var promptYesNo = async (question, defaultValue) => {
|
|
455
|
-
if (!process.stdin.isTTY) {
|
|
456
|
-
log("warn", `${question} Using default ${defaultValue ? "yes" : "no"} (stdin not interactive).`);
|
|
457
|
-
return defaultValue;
|
|
458
|
-
}
|
|
459
|
-
const suffix = defaultValue ? " [Y/n] " : " [y/N] ";
|
|
460
|
-
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
461
|
-
const answer = await new Promise((resolve3) => rl.question(`${question}${suffix}`, resolve3));
|
|
462
|
-
rl.close();
|
|
463
|
-
const normalized = answer.trim().toLowerCase();
|
|
464
|
-
if (!normalized) {
|
|
465
|
-
return defaultValue;
|
|
466
|
-
}
|
|
467
|
-
return normalized === "y" || normalized === "yes";
|
|
468
|
-
};
|
|
469
1939
|
var resolveSiteUrl = (args) => {
|
|
470
1940
|
const argValue = args["site-url"] ?? args.siteUrl;
|
|
471
1941
|
const envValue = process.env.BISYNC_SITE_URL;
|
|
@@ -769,7 +2239,7 @@ var runAuthLogin = async (args) => {
|
|
|
769
2239
|
throw new Error("Missing site URL. Provide --site-url or BISYNC_SITE_URL.");
|
|
770
2240
|
}
|
|
771
2241
|
if (config?.token) {
|
|
772
|
-
const shouldReauth = force || await
|
|
2242
|
+
const shouldReauth = force || await confirmYesNo("Already signed in. Sign out and re-authenticate?", false, log);
|
|
773
2243
|
if (!shouldReauth) {
|
|
774
2244
|
log("info", "Keeping existing credentials.");
|
|
775
2245
|
return;
|
|
@@ -835,15 +2305,42 @@ var runSessionList = async () => {
|
|
|
835
2305
|
console.log(session.externalId);
|
|
836
2306
|
}
|
|
837
2307
|
};
|
|
2308
|
+
var fetchGithubLaunchToken = async (siteUrl, token) => {
|
|
2309
|
+
const response = await fetch(`${siteUrl}/api/github/launch-token`, {
|
|
2310
|
+
method: "GET",
|
|
2311
|
+
headers: {
|
|
2312
|
+
Authorization: `Bearer ${token}`
|
|
2313
|
+
}
|
|
2314
|
+
});
|
|
2315
|
+
if (!response.ok) {
|
|
2316
|
+
const errorText = await response.text();
|
|
2317
|
+
throw new Error(`GitHub token request failed: ${response.status} ${errorText}`);
|
|
2318
|
+
}
|
|
2319
|
+
const data = await response.json();
|
|
2320
|
+
if (!data.token) {
|
|
2321
|
+
throw new Error("GitHub token response missing token");
|
|
2322
|
+
}
|
|
2323
|
+
return data.token;
|
|
2324
|
+
};
|
|
2325
|
+
var runGithubCredential = async (operation) => {
|
|
2326
|
+
const op = operation ?? "get";
|
|
2327
|
+
if (op !== "get")
|
|
2328
|
+
return;
|
|
2329
|
+
const config = await readConfig();
|
|
2330
|
+
const siteUrl = process.env.BISYNC_SITE_URL ?? config.siteUrl;
|
|
2331
|
+
const githubToken = await fetchGithubLaunchToken(siteUrl, config.token);
|
|
2332
|
+
console.log("username=x-access-token");
|
|
2333
|
+
console.log(`password=${githubToken}`);
|
|
2334
|
+
};
|
|
838
2335
|
var runHook = async (hookName, payloadArg) => {
|
|
839
2336
|
log("debug", `runHook start`, { hook: hookName });
|
|
840
|
-
const stdinRaw = payloadArg && payloadArg.trim().length > 0 ? "" : await new Promise((
|
|
2337
|
+
const stdinRaw = payloadArg && payloadArg.trim().length > 0 ? "" : await new Promise((resolve4, reject) => {
|
|
841
2338
|
let data = "";
|
|
842
2339
|
process.stdin.setEncoding("utf8");
|
|
843
2340
|
process.stdin.on("data", (chunk) => {
|
|
844
2341
|
data += chunk;
|
|
845
2342
|
});
|
|
846
|
-
process.stdin.on("end", () =>
|
|
2343
|
+
process.stdin.on("end", () => resolve4(data));
|
|
847
2344
|
process.stdin.on("error", (error) => reject(error));
|
|
848
2345
|
});
|
|
849
2346
|
const rawPayload = stdinRaw.trim() || payloadArg?.trim() || "";
|
|
@@ -931,7 +2428,7 @@ var runHook = async (hookName, payloadArg) => {
|
|
|
931
2428
|
let sessionFile = null;
|
|
932
2429
|
const transcriptPath = typeof payload.transcript_path === "string" ? payload.transcript_path : undefined;
|
|
933
2430
|
if (transcriptPath) {
|
|
934
|
-
const resolvedPath =
|
|
2431
|
+
const resolvedPath = resolve3(transcriptPath);
|
|
935
2432
|
if (await Bun.file(resolvedPath).exists()) {
|
|
936
2433
|
sessionFile = resolvedPath;
|
|
937
2434
|
}
|
|
@@ -1039,6 +2536,33 @@ var main = async () => {
|
|
|
1039
2536
|
printUsage();
|
|
1040
2537
|
process.exit(1);
|
|
1041
2538
|
}
|
|
2539
|
+
if (command === "github") {
|
|
2540
|
+
if (subcommand === "credential") {
|
|
2541
|
+
await runGithubCredential(rest[0]);
|
|
2542
|
+
process.exit(0);
|
|
2543
|
+
}
|
|
2544
|
+
printUsage();
|
|
2545
|
+
process.exit(1);
|
|
2546
|
+
}
|
|
2547
|
+
if (command === "resume") {
|
|
2548
|
+
const sessionId = subcommand ?? "";
|
|
2549
|
+
if (!sessionId) {
|
|
2550
|
+
printUsage();
|
|
2551
|
+
process.exit(1);
|
|
2552
|
+
}
|
|
2553
|
+
const config = await readConfig();
|
|
2554
|
+
const resolution = resolveSiteUrl(values);
|
|
2555
|
+
const siteUrl = resolution.siteUrl ?? config.siteUrl;
|
|
2556
|
+
if (!siteUrl) {
|
|
2557
|
+
throw new Error("Missing site URL. Provide --site-url or BISYNC_SITE_URL.");
|
|
2558
|
+
}
|
|
2559
|
+
await runResume(sessionId, values, {
|
|
2560
|
+
log,
|
|
2561
|
+
siteUrl,
|
|
2562
|
+
token: config.token
|
|
2563
|
+
});
|
|
2564
|
+
process.exit(0);
|
|
2565
|
+
}
|
|
1042
2566
|
if (command === "hook") {
|
|
1043
2567
|
const payloadArg = rest.length > 0 ? rest.join(" ") : null;
|
|
1044
2568
|
await runHook(subcommand ?? "unknown", payloadArg);
|