@tradejs/cli 1.0.9 → 1.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/README.md +13 -4
  2. package/dist/cli.js +29531 -13520
  3. package/dist/lib/aiPocketSearch.js +1316 -0
  4. package/dist/lib/aiTrainCharts.js +711 -0
  5. package/dist/lib/aiTrainDataset.js +40 -0
  6. package/dist/lib/aiTrainEvaluationDump.js +76 -0
  7. package/dist/lib/aiTrainMetrics.js +148 -8
  8. package/dist/lib/aiTrainOptions.js +130 -0
  9. package/dist/lib/aiTrainQuarantine.js +199 -0
  10. package/dist/lib/aiTrainResearch.js +467 -0
  11. package/dist/lib/binanceMarketContextBackfill.js +841 -0
  12. package/dist/lib/binanceMarketData.js +392 -0
  13. package/dist/lib/coinMarketCapContextBackfill.js +1126 -0
  14. package/dist/lib/continuity.js +60 -0
  15. package/dist/lib/derivativesContextBackfill.js +490 -77
  16. package/dist/lib/executionCalibration.js +705 -0
  17. package/dist/lib/marketContextPrepare.js +4441 -0
  18. package/dist/lib/paritySummary.js +101 -0
  19. package/dist/lib/runBot.js +1 -0
  20. package/dist/lib/runEnvironment.js +2259 -0
  21. package/dist/lib/runFormatting.js +1657 -0
  22. package/dist/lib/runtimeDebugEvidence.js +526 -0
  23. package/dist/lib/runtimeModeConfig.js +53 -0
  24. package/dist/lib/runtimeParity.js +88 -11
  25. package/dist/lib/runtimeParityDetails.js +751 -0
  26. package/dist/lib/runtimeRedis.js +157 -0
  27. package/dist/lib/runtimeSignalsLoader.js +40 -6
  28. package/dist/lib/runtimeSignalsStorage.js +45 -22
  29. package/dist/lib/runtimeStrategyBacktest.js +134 -0
  30. package/dist/lib/runtimeTradeSync.js +263 -0
  31. package/dist/lib/telegramReports.js +9 -0
  32. package/dist/lib/tickerUniverseCache.js +116 -0
  33. package/dist/lib/timeWindow.js +3 -3
  34. package/dist/scripts/agentRun.js +14 -8
  35. package/dist/scripts/aiExport.js +1721 -7
  36. package/dist/scripts/aiExportSelect.js +16 -4
  37. package/dist/scripts/aiPocketSearch.js +4190 -0
  38. package/dist/scripts/aiTrain.js +1866 -87
  39. package/dist/scripts/backtest.js +4534 -803
  40. package/dist/scripts/binanceMarketIngest.js +565 -0
  41. package/dist/scripts/bot.js +16 -2
  42. package/dist/scripts/candlesMigrateProvider.js +32 -22
  43. package/dist/scripts/cleanDir.js +15 -2
  44. package/dist/scripts/cleanRedis.js +15 -2
  45. package/dist/scripts/cleanTests.js +38 -2
  46. package/dist/scripts/cleanupMarketContext.js +69 -0
  47. package/dist/scripts/continuity.js +148 -67
  48. package/dist/scripts/derivativesIngest.js +14 -4
  49. package/dist/scripts/derivativesIngestCoinalyzeAll.js +14 -4
  50. package/dist/scripts/doctor.js +14 -4
  51. package/dist/scripts/executionCalibration.js +792 -0
  52. package/dist/scripts/infraCommon.js +18 -5
  53. package/dist/scripts/infraDown.js +14 -4
  54. package/dist/scripts/infraInit.js +32 -9
  55. package/dist/scripts/infraUp.js +24 -6
  56. package/dist/scripts/marketWs.js +222 -0
  57. package/dist/scripts/migration.js +15 -2
  58. package/dist/scripts/mlExport.js +1698 -10
  59. package/dist/scripts/mlExportSelect.js +16 -4
  60. package/dist/scripts/mlInspect.js +13 -3
  61. package/dist/scripts/mlTrainLatestSelect.js +14 -4
  62. package/dist/scripts/replay.js +8867 -0
  63. package/dist/scripts/replayRunner.js +8870 -0
  64. package/dist/scripts/replayRuntimeEvidence.js +868 -0
  65. package/dist/scripts/researchAuto.js +286 -59
  66. package/dist/scripts/results.js +3 -3
  67. package/dist/scripts/runtimeEvidence.js +605 -0
  68. package/dist/scripts/runtimeParity.js +6400 -1043
  69. package/dist/scripts/serverHealth.js +588 -0
  70. package/dist/scripts/signals.js +5628 -511
  71. package/dist/scripts/signalsDaemon.js +6205 -0
  72. package/dist/scripts/signalsSummary.js +833 -248
  73. package/dist/scripts/test-ml.js +25 -3
  74. package/dist/scripts/test.js +26 -1
  75. package/dist/scripts/user-add.js +15 -2
  76. package/dist/workers/testerWorker.js +130 -21
  77. package/package.json +18 -12
@@ -5,6 +5,13 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __commonJS = (cb, mod) => function __require() {
9
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
+ };
11
+ var __export = (target, all) => {
12
+ for (var name in all)
13
+ __defProp(target, name, { get: all[name], enumerable: true });
14
+ };
8
15
  var __copyProps = (to, from, except, desc) => {
9
16
  if (from && typeof from === "object" || typeof from === "function") {
10
17
  for (let key of __getOwnPropNames(from))
@@ -21,14 +28,1655 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
21
28
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
29
  mod
23
30
  ));
31
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
+
33
+ // ../../node_modules/debug/node_modules/ms/index.js
34
+ var require_ms = __commonJS({
35
+ "../../node_modules/debug/node_modules/ms/index.js"(exports2, module2) {
36
+ "use strict";
37
+ var s = 1e3;
38
+ var m = s * 60;
39
+ var h = m * 60;
40
+ var d = h * 24;
41
+ var w = d * 7;
42
+ var y = d * 365.25;
43
+ module2.exports = function(val, options) {
44
+ options = options || {};
45
+ var type = typeof val;
46
+ if (type === "string" && val.length > 0) {
47
+ return parse(val);
48
+ } else if (type === "number" && isFinite(val)) {
49
+ return options.long ? fmtLong(val) : fmtShort(val);
50
+ }
51
+ throw new Error(
52
+ "val is not a non-empty string or a valid number. val=" + JSON.stringify(val)
53
+ );
54
+ };
55
+ function parse(str) {
56
+ str = String(str);
57
+ if (str.length > 100) {
58
+ return;
59
+ }
60
+ var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
61
+ str
62
+ );
63
+ if (!match) {
64
+ return;
65
+ }
66
+ var n = parseFloat(match[1]);
67
+ var type = (match[2] || "ms").toLowerCase();
68
+ switch (type) {
69
+ case "years":
70
+ case "year":
71
+ case "yrs":
72
+ case "yr":
73
+ case "y":
74
+ return n * y;
75
+ case "weeks":
76
+ case "week":
77
+ case "w":
78
+ return n * w;
79
+ case "days":
80
+ case "day":
81
+ case "d":
82
+ return n * d;
83
+ case "hours":
84
+ case "hour":
85
+ case "hrs":
86
+ case "hr":
87
+ case "h":
88
+ return n * h;
89
+ case "minutes":
90
+ case "minute":
91
+ case "mins":
92
+ case "min":
93
+ case "m":
94
+ return n * m;
95
+ case "seconds":
96
+ case "second":
97
+ case "secs":
98
+ case "sec":
99
+ case "s":
100
+ return n * s;
101
+ case "milliseconds":
102
+ case "millisecond":
103
+ case "msecs":
104
+ case "msec":
105
+ case "ms":
106
+ return n;
107
+ default:
108
+ return void 0;
109
+ }
110
+ }
111
+ function fmtShort(ms) {
112
+ var msAbs = Math.abs(ms);
113
+ if (msAbs >= d) {
114
+ return Math.round(ms / d) + "d";
115
+ }
116
+ if (msAbs >= h) {
117
+ return Math.round(ms / h) + "h";
118
+ }
119
+ if (msAbs >= m) {
120
+ return Math.round(ms / m) + "m";
121
+ }
122
+ if (msAbs >= s) {
123
+ return Math.round(ms / s) + "s";
124
+ }
125
+ return ms + "ms";
126
+ }
127
+ function fmtLong(ms) {
128
+ var msAbs = Math.abs(ms);
129
+ if (msAbs >= d) {
130
+ return plural(ms, msAbs, d, "day");
131
+ }
132
+ if (msAbs >= h) {
133
+ return plural(ms, msAbs, h, "hour");
134
+ }
135
+ if (msAbs >= m) {
136
+ return plural(ms, msAbs, m, "minute");
137
+ }
138
+ if (msAbs >= s) {
139
+ return plural(ms, msAbs, s, "second");
140
+ }
141
+ return ms + " ms";
142
+ }
143
+ function plural(ms, msAbs, n, name) {
144
+ var isPlural = msAbs >= n * 1.5;
145
+ return Math.round(ms / n) + " " + name + (isPlural ? "s" : "");
146
+ }
147
+ }
148
+ });
149
+
150
+ // ../../node_modules/debug/src/common.js
151
+ var require_common = __commonJS({
152
+ "../../node_modules/debug/src/common.js"(exports2, module2) {
153
+ "use strict";
154
+ function setup(env) {
155
+ createDebug.debug = createDebug;
156
+ createDebug.default = createDebug;
157
+ createDebug.coerce = coerce;
158
+ createDebug.disable = disable;
159
+ createDebug.enable = enable;
160
+ createDebug.enabled = enabled;
161
+ createDebug.humanize = require_ms();
162
+ createDebug.destroy = destroy;
163
+ Object.keys(env).forEach((key) => {
164
+ createDebug[key] = env[key];
165
+ });
166
+ createDebug.names = [];
167
+ createDebug.skips = [];
168
+ createDebug.formatters = {};
169
+ function selectColor(namespace) {
170
+ let hash = 0;
171
+ for (let i = 0; i < namespace.length; i++) {
172
+ hash = (hash << 5) - hash + namespace.charCodeAt(i);
173
+ hash |= 0;
174
+ }
175
+ return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
176
+ }
177
+ createDebug.selectColor = selectColor;
178
+ function createDebug(namespace) {
179
+ let prevTime;
180
+ let enableOverride = null;
181
+ let namespacesCache;
182
+ let enabledCache;
183
+ function debug(...args2) {
184
+ if (!debug.enabled) {
185
+ return;
186
+ }
187
+ const self = debug;
188
+ const curr = Number(/* @__PURE__ */ new Date());
189
+ const ms = curr - (prevTime || curr);
190
+ self.diff = ms;
191
+ self.prev = prevTime;
192
+ self.curr = curr;
193
+ prevTime = curr;
194
+ args2[0] = createDebug.coerce(args2[0]);
195
+ if (typeof args2[0] !== "string") {
196
+ args2.unshift("%O");
197
+ }
198
+ let index = 0;
199
+ args2[0] = args2[0].replace(/%([a-zA-Z%])/g, (match, format2) => {
200
+ if (match === "%%") {
201
+ return "%";
202
+ }
203
+ index++;
204
+ const formatter = createDebug.formatters[format2];
205
+ if (typeof formatter === "function") {
206
+ const val = args2[index];
207
+ match = formatter.call(self, val);
208
+ args2.splice(index, 1);
209
+ index--;
210
+ }
211
+ return match;
212
+ });
213
+ createDebug.formatArgs.call(self, args2);
214
+ const logFn = self.log || createDebug.log;
215
+ logFn.apply(self, args2);
216
+ }
217
+ debug.namespace = namespace;
218
+ debug.useColors = createDebug.useColors();
219
+ debug.color = createDebug.selectColor(namespace);
220
+ debug.extend = extend;
221
+ debug.destroy = createDebug.destroy;
222
+ Object.defineProperty(debug, "enabled", {
223
+ enumerable: true,
224
+ configurable: false,
225
+ get: () => {
226
+ if (enableOverride !== null) {
227
+ return enableOverride;
228
+ }
229
+ if (namespacesCache !== createDebug.namespaces) {
230
+ namespacesCache = createDebug.namespaces;
231
+ enabledCache = createDebug.enabled(namespace);
232
+ }
233
+ return enabledCache;
234
+ },
235
+ set: (v) => {
236
+ enableOverride = v;
237
+ }
238
+ });
239
+ if (typeof createDebug.init === "function") {
240
+ createDebug.init(debug);
241
+ }
242
+ return debug;
243
+ }
244
+ function extend(namespace, delimiter) {
245
+ const newDebug = createDebug(this.namespace + (typeof delimiter === "undefined" ? ":" : delimiter) + namespace);
246
+ newDebug.log = this.log;
247
+ return newDebug;
248
+ }
249
+ function enable(namespaces) {
250
+ createDebug.save(namespaces);
251
+ createDebug.namespaces = namespaces;
252
+ createDebug.names = [];
253
+ createDebug.skips = [];
254
+ let i;
255
+ const split = (typeof namespaces === "string" ? namespaces : "").split(/[\s,]+/);
256
+ const len = split.length;
257
+ for (i = 0; i < len; i++) {
258
+ if (!split[i]) {
259
+ continue;
260
+ }
261
+ namespaces = split[i].replace(/\*/g, ".*?");
262
+ if (namespaces[0] === "-") {
263
+ createDebug.skips.push(new RegExp("^" + namespaces.slice(1) + "$"));
264
+ } else {
265
+ createDebug.names.push(new RegExp("^" + namespaces + "$"));
266
+ }
267
+ }
268
+ }
269
+ function disable() {
270
+ const namespaces = [
271
+ ...createDebug.names.map(toNamespace),
272
+ ...createDebug.skips.map(toNamespace).map((namespace) => "-" + namespace)
273
+ ].join(",");
274
+ createDebug.enable("");
275
+ return namespaces;
276
+ }
277
+ function enabled(name) {
278
+ if (name[name.length - 1] === "*") {
279
+ return true;
280
+ }
281
+ let i;
282
+ let len;
283
+ for (i = 0, len = createDebug.skips.length; i < len; i++) {
284
+ if (createDebug.skips[i].test(name)) {
285
+ return false;
286
+ }
287
+ }
288
+ for (i = 0, len = createDebug.names.length; i < len; i++) {
289
+ if (createDebug.names[i].test(name)) {
290
+ return true;
291
+ }
292
+ }
293
+ return false;
294
+ }
295
+ function toNamespace(regexp) {
296
+ return regexp.toString().substring(2, regexp.toString().length - 2).replace(/\.\*\?$/, "*");
297
+ }
298
+ function coerce(val) {
299
+ if (val instanceof Error) {
300
+ return val.stack || val.message;
301
+ }
302
+ return val;
303
+ }
304
+ function destroy() {
305
+ console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
306
+ }
307
+ createDebug.enable(createDebug.load());
308
+ return createDebug;
309
+ }
310
+ module2.exports = setup;
311
+ }
312
+ });
313
+
314
+ // ../../node_modules/debug/src/browser.js
315
+ var require_browser = __commonJS({
316
+ "../../node_modules/debug/src/browser.js"(exports2, module2) {
317
+ "use strict";
318
+ exports2.formatArgs = formatArgs;
319
+ exports2.save = save;
320
+ exports2.load = load;
321
+ exports2.useColors = useColors;
322
+ exports2.storage = localstorage();
323
+ exports2.destroy = /* @__PURE__ */ (() => {
324
+ let warned = false;
325
+ return () => {
326
+ if (!warned) {
327
+ warned = true;
328
+ console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
329
+ }
330
+ };
331
+ })();
332
+ exports2.colors = [
333
+ "#0000CC",
334
+ "#0000FF",
335
+ "#0033CC",
336
+ "#0033FF",
337
+ "#0066CC",
338
+ "#0066FF",
339
+ "#0099CC",
340
+ "#0099FF",
341
+ "#00CC00",
342
+ "#00CC33",
343
+ "#00CC66",
344
+ "#00CC99",
345
+ "#00CCCC",
346
+ "#00CCFF",
347
+ "#3300CC",
348
+ "#3300FF",
349
+ "#3333CC",
350
+ "#3333FF",
351
+ "#3366CC",
352
+ "#3366FF",
353
+ "#3399CC",
354
+ "#3399FF",
355
+ "#33CC00",
356
+ "#33CC33",
357
+ "#33CC66",
358
+ "#33CC99",
359
+ "#33CCCC",
360
+ "#33CCFF",
361
+ "#6600CC",
362
+ "#6600FF",
363
+ "#6633CC",
364
+ "#6633FF",
365
+ "#66CC00",
366
+ "#66CC33",
367
+ "#9900CC",
368
+ "#9900FF",
369
+ "#9933CC",
370
+ "#9933FF",
371
+ "#99CC00",
372
+ "#99CC33",
373
+ "#CC0000",
374
+ "#CC0033",
375
+ "#CC0066",
376
+ "#CC0099",
377
+ "#CC00CC",
378
+ "#CC00FF",
379
+ "#CC3300",
380
+ "#CC3333",
381
+ "#CC3366",
382
+ "#CC3399",
383
+ "#CC33CC",
384
+ "#CC33FF",
385
+ "#CC6600",
386
+ "#CC6633",
387
+ "#CC9900",
388
+ "#CC9933",
389
+ "#CCCC00",
390
+ "#CCCC33",
391
+ "#FF0000",
392
+ "#FF0033",
393
+ "#FF0066",
394
+ "#FF0099",
395
+ "#FF00CC",
396
+ "#FF00FF",
397
+ "#FF3300",
398
+ "#FF3333",
399
+ "#FF3366",
400
+ "#FF3399",
401
+ "#FF33CC",
402
+ "#FF33FF",
403
+ "#FF6600",
404
+ "#FF6633",
405
+ "#FF9900",
406
+ "#FF9933",
407
+ "#FFCC00",
408
+ "#FFCC33"
409
+ ];
410
+ function useColors() {
411
+ if (typeof window !== "undefined" && window.process && (window.process.type === "renderer" || window.process.__nwjs)) {
412
+ return true;
413
+ }
414
+ if (typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
415
+ return false;
416
+ }
417
+ return typeof document !== "undefined" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || // Is firebug? http://stackoverflow.com/a/398120/376773
418
+ typeof window !== "undefined" && window.console && (window.console.firebug || window.console.exception && window.console.table) || // Is firefox >= v31?
419
+ // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
420
+ typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31 || // Double check webkit in userAgent just in case we are in a worker
421
+ typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
422
+ }
423
+ function formatArgs(args2) {
424
+ args2[0] = (this.useColors ? "%c" : "") + this.namespace + (this.useColors ? " %c" : " ") + args2[0] + (this.useColors ? "%c " : " ") + "+" + module2.exports.humanize(this.diff);
425
+ if (!this.useColors) {
426
+ return;
427
+ }
428
+ const c = "color: " + this.color;
429
+ args2.splice(1, 0, c, "color: inherit");
430
+ let index = 0;
431
+ let lastC = 0;
432
+ args2[0].replace(/%[a-zA-Z%]/g, (match) => {
433
+ if (match === "%%") {
434
+ return;
435
+ }
436
+ index++;
437
+ if (match === "%c") {
438
+ lastC = index;
439
+ }
440
+ });
441
+ args2.splice(lastC, 0, c);
442
+ }
443
+ exports2.log = console.debug || console.log || (() => {
444
+ });
445
+ function save(namespaces) {
446
+ try {
447
+ if (namespaces) {
448
+ exports2.storage.setItem("debug", namespaces);
449
+ } else {
450
+ exports2.storage.removeItem("debug");
451
+ }
452
+ } catch (error) {
453
+ }
454
+ }
455
+ function load() {
456
+ let r;
457
+ try {
458
+ r = exports2.storage.getItem("debug");
459
+ } catch (error) {
460
+ }
461
+ if (!r && typeof process !== "undefined" && "env" in process) {
462
+ r = process.env.DEBUG;
463
+ }
464
+ return r;
465
+ }
466
+ function localstorage() {
467
+ try {
468
+ return localStorage;
469
+ } catch (error) {
470
+ }
471
+ }
472
+ module2.exports = require_common()(exports2);
473
+ var { formatters } = module2.exports;
474
+ formatters.j = function(v) {
475
+ try {
476
+ return JSON.stringify(v);
477
+ } catch (error) {
478
+ return "[UnexpectedJSONParseError]: " + error.message;
479
+ }
480
+ };
481
+ }
482
+ });
483
+
484
+ // ../../node_modules/has-flag/index.js
485
+ var require_has_flag = __commonJS({
486
+ "../../node_modules/has-flag/index.js"(exports2, module2) {
487
+ "use strict";
488
+ module2.exports = (flag, argv = process.argv) => {
489
+ const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
490
+ const position = argv.indexOf(prefix + flag);
491
+ const terminatorPosition = argv.indexOf("--");
492
+ return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
493
+ };
494
+ }
495
+ });
496
+
497
+ // ../../node_modules/supports-color/index.js
498
+ var require_supports_color = __commonJS({
499
+ "../../node_modules/supports-color/index.js"(exports2, module2) {
500
+ "use strict";
501
+ var os = require("os");
502
+ var tty = require("tty");
503
+ var hasFlag = require_has_flag();
504
+ var { env } = process;
505
+ var flagForceColor;
506
+ if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
507
+ flagForceColor = 0;
508
+ } else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
509
+ flagForceColor = 1;
510
+ }
511
+ function envForceColor() {
512
+ if ("FORCE_COLOR" in env) {
513
+ if (env.FORCE_COLOR === "true") {
514
+ return 1;
515
+ }
516
+ if (env.FORCE_COLOR === "false") {
517
+ return 0;
518
+ }
519
+ return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
520
+ }
521
+ }
522
+ function translateLevel(level) {
523
+ if (level === 0) {
524
+ return false;
525
+ }
526
+ return {
527
+ level,
528
+ hasBasic: true,
529
+ has256: level >= 2,
530
+ has16m: level >= 3
531
+ };
532
+ }
533
+ function supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
534
+ const noFlagForceColor = envForceColor();
535
+ if (noFlagForceColor !== void 0) {
536
+ flagForceColor = noFlagForceColor;
537
+ }
538
+ const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
539
+ if (forceColor === 0) {
540
+ return 0;
541
+ }
542
+ if (sniffFlags) {
543
+ if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
544
+ return 3;
545
+ }
546
+ if (hasFlag("color=256")) {
547
+ return 2;
548
+ }
549
+ }
550
+ if (haveStream && !streamIsTTY && forceColor === void 0) {
551
+ return 0;
552
+ }
553
+ const min = forceColor || 0;
554
+ if (env.TERM === "dumb") {
555
+ return min;
556
+ }
557
+ if (process.platform === "win32") {
558
+ const osRelease = os.release().split(".");
559
+ if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
560
+ return Number(osRelease[2]) >= 14931 ? 3 : 2;
561
+ }
562
+ return 1;
563
+ }
564
+ if ("CI" in env) {
565
+ if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "GITHUB_ACTIONS", "BUILDKITE", "DRONE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
566
+ return 1;
567
+ }
568
+ return min;
569
+ }
570
+ if ("TEAMCITY_VERSION" in env) {
571
+ return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
572
+ }
573
+ if (env.COLORTERM === "truecolor") {
574
+ return 3;
575
+ }
576
+ if ("TERM_PROGRAM" in env) {
577
+ const version = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
578
+ switch (env.TERM_PROGRAM) {
579
+ case "iTerm.app":
580
+ return version >= 3 ? 3 : 2;
581
+ case "Apple_Terminal":
582
+ return 2;
583
+ }
584
+ }
585
+ if (/-256(color)?$/i.test(env.TERM)) {
586
+ return 2;
587
+ }
588
+ if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
589
+ return 1;
590
+ }
591
+ if ("COLORTERM" in env) {
592
+ return 1;
593
+ }
594
+ return min;
595
+ }
596
+ function getSupportLevel(stream, options = {}) {
597
+ const level = supportsColor(stream, {
598
+ streamIsTTY: stream && stream.isTTY,
599
+ ...options
600
+ });
601
+ return translateLevel(level);
602
+ }
603
+ module2.exports = {
604
+ supportsColor: getSupportLevel,
605
+ stdout: getSupportLevel({ isTTY: tty.isatty(1) }),
606
+ stderr: getSupportLevel({ isTTY: tty.isatty(2) })
607
+ };
608
+ }
609
+ });
610
+
611
+ // ../../node_modules/debug/src/node.js
612
+ var require_node = __commonJS({
613
+ "../../node_modules/debug/src/node.js"(exports2, module2) {
614
+ "use strict";
615
+ var tty = require("tty");
616
+ var util = require("util");
617
+ exports2.init = init;
618
+ exports2.log = log;
619
+ exports2.formatArgs = formatArgs;
620
+ exports2.save = save;
621
+ exports2.load = load;
622
+ exports2.useColors = useColors;
623
+ exports2.destroy = util.deprecate(
624
+ () => {
625
+ },
626
+ "Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."
627
+ );
628
+ exports2.colors = [6, 2, 3, 4, 5, 1];
629
+ try {
630
+ const supportsColor = require_supports_color();
631
+ if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) {
632
+ exports2.colors = [
633
+ 20,
634
+ 21,
635
+ 26,
636
+ 27,
637
+ 32,
638
+ 33,
639
+ 38,
640
+ 39,
641
+ 40,
642
+ 41,
643
+ 42,
644
+ 43,
645
+ 44,
646
+ 45,
647
+ 56,
648
+ 57,
649
+ 62,
650
+ 63,
651
+ 68,
652
+ 69,
653
+ 74,
654
+ 75,
655
+ 76,
656
+ 77,
657
+ 78,
658
+ 79,
659
+ 80,
660
+ 81,
661
+ 92,
662
+ 93,
663
+ 98,
664
+ 99,
665
+ 112,
666
+ 113,
667
+ 128,
668
+ 129,
669
+ 134,
670
+ 135,
671
+ 148,
672
+ 149,
673
+ 160,
674
+ 161,
675
+ 162,
676
+ 163,
677
+ 164,
678
+ 165,
679
+ 166,
680
+ 167,
681
+ 168,
682
+ 169,
683
+ 170,
684
+ 171,
685
+ 172,
686
+ 173,
687
+ 178,
688
+ 179,
689
+ 184,
690
+ 185,
691
+ 196,
692
+ 197,
693
+ 198,
694
+ 199,
695
+ 200,
696
+ 201,
697
+ 202,
698
+ 203,
699
+ 204,
700
+ 205,
701
+ 206,
702
+ 207,
703
+ 208,
704
+ 209,
705
+ 214,
706
+ 215,
707
+ 220,
708
+ 221
709
+ ];
710
+ }
711
+ } catch (error) {
712
+ }
713
+ exports2.inspectOpts = Object.keys(process.env).filter((key) => {
714
+ return /^debug_/i.test(key);
715
+ }).reduce((obj, key) => {
716
+ const prop = key.substring(6).toLowerCase().replace(/_([a-z])/g, (_, k) => {
717
+ return k.toUpperCase();
718
+ });
719
+ let val = process.env[key];
720
+ if (/^(yes|on|true|enabled)$/i.test(val)) {
721
+ val = true;
722
+ } else if (/^(no|off|false|disabled)$/i.test(val)) {
723
+ val = false;
724
+ } else if (val === "null") {
725
+ val = null;
726
+ } else {
727
+ val = Number(val);
728
+ }
729
+ obj[prop] = val;
730
+ return obj;
731
+ }, {});
732
+ function useColors() {
733
+ return "colors" in exports2.inspectOpts ? Boolean(exports2.inspectOpts.colors) : tty.isatty(process.stderr.fd);
734
+ }
735
+ function formatArgs(args2) {
736
+ const { namespace: name, useColors: useColors2 } = this;
737
+ if (useColors2) {
738
+ const c = this.color;
739
+ const colorCode = "\x1B[3" + (c < 8 ? c : "8;5;" + c);
740
+ const prefix = ` ${colorCode};1m${name} \x1B[0m`;
741
+ args2[0] = prefix + args2[0].split("\n").join("\n" + prefix);
742
+ args2.push(colorCode + "m+" + module2.exports.humanize(this.diff) + "\x1B[0m");
743
+ } else {
744
+ args2[0] = getDate() + name + " " + args2[0];
745
+ }
746
+ }
747
+ function getDate() {
748
+ if (exports2.inspectOpts.hideDate) {
749
+ return "";
750
+ }
751
+ return (/* @__PURE__ */ new Date()).toISOString() + " ";
752
+ }
753
+ function log(...args2) {
754
+ return process.stderr.write(util.format(...args2) + "\n");
755
+ }
756
+ function save(namespaces) {
757
+ if (namespaces) {
758
+ process.env.DEBUG = namespaces;
759
+ } else {
760
+ delete process.env.DEBUG;
761
+ }
762
+ }
763
+ function load() {
764
+ return process.env.DEBUG;
765
+ }
766
+ function init(debug) {
767
+ debug.inspectOpts = {};
768
+ const keys = Object.keys(exports2.inspectOpts);
769
+ for (let i = 0; i < keys.length; i++) {
770
+ debug.inspectOpts[keys[i]] = exports2.inspectOpts[keys[i]];
771
+ }
772
+ }
773
+ module2.exports = require_common()(exports2);
774
+ var { formatters } = module2.exports;
775
+ formatters.o = function(v) {
776
+ this.inspectOpts.colors = this.useColors;
777
+ return util.inspect(v, this.inspectOpts).split("\n").map((str) => str.trim()).join(" ");
778
+ };
779
+ formatters.O = function(v) {
780
+ this.inspectOpts.colors = this.useColors;
781
+ return util.inspect(v, this.inspectOpts);
782
+ };
783
+ }
784
+ });
785
+
786
+ // ../../node_modules/debug/src/index.js
787
+ var require_src = __commonJS({
788
+ "../../node_modules/debug/src/index.js"(exports2, module2) {
789
+ "use strict";
790
+ if (typeof process === "undefined" || process.type === "renderer" || process.browser === true || process.__nwjs) {
791
+ module2.exports = require_browser();
792
+ } else {
793
+ module2.exports = require_node();
794
+ }
795
+ }
796
+ });
797
+
798
+ // ../../node_modules/eastasianwidth/eastasianwidth.js
799
+ var require_eastasianwidth = __commonJS({
800
+ "../../node_modules/eastasianwidth/eastasianwidth.js"(exports2, module2) {
801
+ "use strict";
802
+ var eaw = {};
803
+ if ("undefined" == typeof module2) {
804
+ window.eastasianwidth = eaw;
805
+ } else {
806
+ module2.exports = eaw;
807
+ }
808
+ eaw.eastAsianWidth = function(character) {
809
+ var x = character.charCodeAt(0);
810
+ var y = character.length == 2 ? character.charCodeAt(1) : 0;
811
+ var codePoint = x;
812
+ if (55296 <= x && x <= 56319 && (56320 <= y && y <= 57343)) {
813
+ x &= 1023;
814
+ y &= 1023;
815
+ codePoint = x << 10 | y;
816
+ codePoint += 65536;
817
+ }
818
+ if (12288 == codePoint || 65281 <= codePoint && codePoint <= 65376 || 65504 <= codePoint && codePoint <= 65510) {
819
+ return "F";
820
+ }
821
+ if (8361 == codePoint || 65377 <= codePoint && codePoint <= 65470 || 65474 <= codePoint && codePoint <= 65479 || 65482 <= codePoint && codePoint <= 65487 || 65490 <= codePoint && codePoint <= 65495 || 65498 <= codePoint && codePoint <= 65500 || 65512 <= codePoint && codePoint <= 65518) {
822
+ return "H";
823
+ }
824
+ if (4352 <= codePoint && codePoint <= 4447 || 4515 <= codePoint && codePoint <= 4519 || 4602 <= codePoint && codePoint <= 4607 || 9001 <= codePoint && codePoint <= 9002 || 11904 <= codePoint && codePoint <= 11929 || 11931 <= codePoint && codePoint <= 12019 || 12032 <= codePoint && codePoint <= 12245 || 12272 <= codePoint && codePoint <= 12283 || 12289 <= codePoint && codePoint <= 12350 || 12353 <= codePoint && codePoint <= 12438 || 12441 <= codePoint && codePoint <= 12543 || 12549 <= codePoint && codePoint <= 12589 || 12593 <= codePoint && codePoint <= 12686 || 12688 <= codePoint && codePoint <= 12730 || 12736 <= codePoint && codePoint <= 12771 || 12784 <= codePoint && codePoint <= 12830 || 12832 <= codePoint && codePoint <= 12871 || 12880 <= codePoint && codePoint <= 13054 || 13056 <= codePoint && codePoint <= 19903 || 19968 <= codePoint && codePoint <= 42124 || 42128 <= codePoint && codePoint <= 42182 || 43360 <= codePoint && codePoint <= 43388 || 44032 <= codePoint && codePoint <= 55203 || 55216 <= codePoint && codePoint <= 55238 || 55243 <= codePoint && codePoint <= 55291 || 63744 <= codePoint && codePoint <= 64255 || 65040 <= codePoint && codePoint <= 65049 || 65072 <= codePoint && codePoint <= 65106 || 65108 <= codePoint && codePoint <= 65126 || 65128 <= codePoint && codePoint <= 65131 || 110592 <= codePoint && codePoint <= 110593 || 127488 <= codePoint && codePoint <= 127490 || 127504 <= codePoint && codePoint <= 127546 || 127552 <= codePoint && codePoint <= 127560 || 127568 <= codePoint && codePoint <= 127569 || 131072 <= codePoint && codePoint <= 194367 || 177984 <= codePoint && codePoint <= 196605 || 196608 <= codePoint && codePoint <= 262141) {
825
+ return "W";
826
+ }
827
+ if (32 <= codePoint && codePoint <= 126 || 162 <= codePoint && codePoint <= 163 || 165 <= codePoint && codePoint <= 166 || 172 == codePoint || 175 == codePoint || 10214 <= codePoint && codePoint <= 10221 || 10629 <= codePoint && codePoint <= 10630) {
828
+ return "Na";
829
+ }
830
+ if (161 == codePoint || 164 == codePoint || 167 <= codePoint && codePoint <= 168 || 170 == codePoint || 173 <= codePoint && codePoint <= 174 || 176 <= codePoint && codePoint <= 180 || 182 <= codePoint && codePoint <= 186 || 188 <= codePoint && codePoint <= 191 || 198 == codePoint || 208 == codePoint || 215 <= codePoint && codePoint <= 216 || 222 <= codePoint && codePoint <= 225 || 230 == codePoint || 232 <= codePoint && codePoint <= 234 || 236 <= codePoint && codePoint <= 237 || 240 == codePoint || 242 <= codePoint && codePoint <= 243 || 247 <= codePoint && codePoint <= 250 || 252 == codePoint || 254 == codePoint || 257 == codePoint || 273 == codePoint || 275 == codePoint || 283 == codePoint || 294 <= codePoint && codePoint <= 295 || 299 == codePoint || 305 <= codePoint && codePoint <= 307 || 312 == codePoint || 319 <= codePoint && codePoint <= 322 || 324 == codePoint || 328 <= codePoint && codePoint <= 331 || 333 == codePoint || 338 <= codePoint && codePoint <= 339 || 358 <= codePoint && codePoint <= 359 || 363 == codePoint || 462 == codePoint || 464 == codePoint || 466 == codePoint || 468 == codePoint || 470 == codePoint || 472 == codePoint || 474 == codePoint || 476 == codePoint || 593 == codePoint || 609 == codePoint || 708 == codePoint || 711 == codePoint || 713 <= codePoint && codePoint <= 715 || 717 == codePoint || 720 == codePoint || 728 <= codePoint && codePoint <= 731 || 733 == codePoint || 735 == codePoint || 768 <= codePoint && codePoint <= 879 || 913 <= codePoint && codePoint <= 929 || 931 <= codePoint && codePoint <= 937 || 945 <= codePoint && codePoint <= 961 || 963 <= codePoint && codePoint <= 969 || 1025 == codePoint || 1040 <= codePoint && codePoint <= 1103 || 1105 == codePoint || 8208 == codePoint || 8211 <= codePoint && codePoint <= 8214 || 8216 <= codePoint && codePoint <= 8217 || 8220 <= codePoint && codePoint <= 8221 || 8224 <= codePoint && codePoint <= 8226 || 8228 <= codePoint && codePoint <= 8231 || 8240 == codePoint || 8242 <= codePoint && codePoint <= 8243 || 8245 == codePoint || 8251 == codePoint || 8254 == codePoint || 8308 == codePoint || 8319 == codePoint || 8321 <= codePoint && codePoint <= 8324 || 8364 == codePoint || 8451 == codePoint || 8453 == codePoint || 8457 == codePoint || 8467 == codePoint || 8470 == codePoint || 8481 <= codePoint && codePoint <= 8482 || 8486 == codePoint || 8491 == codePoint || 8531 <= codePoint && codePoint <= 8532 || 8539 <= codePoint && codePoint <= 8542 || 8544 <= codePoint && codePoint <= 8555 || 8560 <= codePoint && codePoint <= 8569 || 8585 == codePoint || 8592 <= codePoint && codePoint <= 8601 || 8632 <= codePoint && codePoint <= 8633 || 8658 == codePoint || 8660 == codePoint || 8679 == codePoint || 8704 == codePoint || 8706 <= codePoint && codePoint <= 8707 || 8711 <= codePoint && codePoint <= 8712 || 8715 == codePoint || 8719 == codePoint || 8721 == codePoint || 8725 == codePoint || 8730 == codePoint || 8733 <= codePoint && codePoint <= 8736 || 8739 == codePoint || 8741 == codePoint || 8743 <= codePoint && codePoint <= 8748 || 8750 == codePoint || 8756 <= codePoint && codePoint <= 8759 || 8764 <= codePoint && codePoint <= 8765 || 8776 == codePoint || 8780 == codePoint || 8786 == codePoint || 8800 <= codePoint && codePoint <= 8801 || 8804 <= codePoint && codePoint <= 8807 || 8810 <= codePoint && codePoint <= 8811 || 8814 <= codePoint && codePoint <= 8815 || 8834 <= codePoint && codePoint <= 8835 || 8838 <= codePoint && codePoint <= 8839 || 8853 == codePoint || 8857 == codePoint || 8869 == codePoint || 8895 == codePoint || 8978 == codePoint || 9312 <= codePoint && codePoint <= 9449 || 9451 <= codePoint && codePoint <= 9547 || 9552 <= codePoint && codePoint <= 9587 || 9600 <= codePoint && codePoint <= 9615 || 9618 <= codePoint && codePoint <= 9621 || 9632 <= codePoint && codePoint <= 9633 || 9635 <= codePoint && codePoint <= 9641 || 9650 <= codePoint && codePoint <= 9651 || 9654 <= codePoint && codePoint <= 9655 || 9660 <= codePoint && codePoint <= 9661 || 9664 <= codePoint && codePoint <= 9665 || 9670 <= codePoint && codePoint <= 9672 || 9675 == codePoint || 9678 <= codePoint && codePoint <= 9681 || 9698 <= codePoint && codePoint <= 9701 || 9711 == codePoint || 9733 <= codePoint && codePoint <= 9734 || 9737 == codePoint || 9742 <= codePoint && codePoint <= 9743 || 9748 <= codePoint && codePoint <= 9749 || 9756 == codePoint || 9758 == codePoint || 9792 == codePoint || 9794 == codePoint || 9824 <= codePoint && codePoint <= 9825 || 9827 <= codePoint && codePoint <= 9829 || 9831 <= codePoint && codePoint <= 9834 || 9836 <= codePoint && codePoint <= 9837 || 9839 == codePoint || 9886 <= codePoint && codePoint <= 9887 || 9918 <= codePoint && codePoint <= 9919 || 9924 <= codePoint && codePoint <= 9933 || 9935 <= codePoint && codePoint <= 9953 || 9955 == codePoint || 9960 <= codePoint && codePoint <= 9983 || 10045 == codePoint || 10071 == codePoint || 10102 <= codePoint && codePoint <= 10111 || 11093 <= codePoint && codePoint <= 11097 || 12872 <= codePoint && codePoint <= 12879 || 57344 <= codePoint && codePoint <= 63743 || 65024 <= codePoint && codePoint <= 65039 || 65533 == codePoint || 127232 <= codePoint && codePoint <= 127242 || 127248 <= codePoint && codePoint <= 127277 || 127280 <= codePoint && codePoint <= 127337 || 127344 <= codePoint && codePoint <= 127386 || 917760 <= codePoint && codePoint <= 917999 || 983040 <= codePoint && codePoint <= 1048573 || 1048576 <= codePoint && codePoint <= 1114109) {
831
+ return "A";
832
+ }
833
+ return "N";
834
+ };
835
+ eaw.characterLength = function(character) {
836
+ var code = this.eastAsianWidth(character);
837
+ if (code == "F" || code == "W" || code == "A") {
838
+ return 2;
839
+ } else {
840
+ return 1;
841
+ }
842
+ };
843
+ function stringToArray(string) {
844
+ return string.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]|[^\uD800-\uDFFF]/g) || [];
845
+ }
846
+ eaw.length = function(string) {
847
+ var characters = stringToArray(string);
848
+ var len = 0;
849
+ for (var i = 0; i < characters.length; i++) {
850
+ len = len + this.characterLength(characters[i]);
851
+ }
852
+ return len;
853
+ };
854
+ eaw.slice = function(text, start, end) {
855
+ textLen = eaw.length(text);
856
+ start = start ? start : 0;
857
+ end = end ? end : 1;
858
+ if (start < 0) {
859
+ start = textLen + start;
860
+ }
861
+ if (end < 0) {
862
+ end = textLen + end;
863
+ }
864
+ var result = "";
865
+ var eawLen = 0;
866
+ var chars = stringToArray(text);
867
+ for (var i = 0; i < chars.length; i++) {
868
+ var char = chars[i];
869
+ var charLen = eaw.length(char);
870
+ if (eawLen >= start - (charLen == 2 ? 1 : 0)) {
871
+ if (eawLen + charLen <= end) {
872
+ result += char;
873
+ } else {
874
+ break;
875
+ }
876
+ }
877
+ eawLen += charLen;
878
+ }
879
+ return result;
880
+ };
881
+ }
882
+ });
883
+
884
+ // ../../node_modules/list-it/lib/data-cell.js
885
+ var require_data_cell = __commonJS({
886
+ "../../node_modules/list-it/lib/data-cell.js"(exports2, module2) {
887
+ "use strict";
888
+ var eaw = require_eastasianwidth();
889
+ function DataCell() {
890
+ this.data = "";
891
+ }
892
+ module2.exports = DataCell;
893
+ DataCell.prototype.getData = function() {
894
+ return this.data;
895
+ };
896
+ DataCell.prototype.setData = function(data) {
897
+ this.data = data;
898
+ };
899
+ DataCell.prototype.visibleLength = function() {
900
+ if (typeof this.data != "string") {
901
+ return ("" + this.data).length;
902
+ }
903
+ return DataCell.visibleLength(this.data);
904
+ };
905
+ DataCell.visibleLength = function(data) {
906
+ const s = data.replace(/\x1b[^m]*m/g, "");
907
+ return eaw.length(s);
908
+ };
909
+ }
910
+ });
911
+
912
+ // ../../node_modules/list-it/lib/row.js
913
+ var require_row = __commonJS({
914
+ "../../node_modules/list-it/lib/row.js"(exports2, module2) {
915
+ "use strict";
916
+ function Row() {
917
+ this.cells = [];
918
+ this.empty = true;
919
+ this.fixed = false;
920
+ }
921
+ module2.exports = Row;
922
+ Row.prototype.getCellLength = function() {
923
+ return this.cells.length;
924
+ };
925
+ Row.prototype.getCell = function(idx) {
926
+ return this.cells[idx];
927
+ };
928
+ Row.prototype.pushCell = function(cell) {
929
+ if (this.isFixed()) {
930
+ throw "pushCell Fail, The row was already fixed.";
931
+ }
932
+ this.empty = false;
933
+ return this.cells.push(cell);
934
+ };
935
+ Row.prototype.fix = function() {
936
+ this.fixed = true;
937
+ };
938
+ Row.prototype.isEmpty = function() {
939
+ return this.empty;
940
+ };
941
+ Row.prototype.isFixed = function() {
942
+ return this.fixed;
943
+ };
944
+ }
945
+ });
946
+
947
+ // ../../node_modules/list-it/lib/column.js
948
+ var require_column = __commonJS({
949
+ "../../node_modules/list-it/lib/column.js"(exports2, module2) {
950
+ "use strict";
951
+ var DataCell = require_data_cell();
952
+ function Column() {
953
+ this.opt = {
954
+ "autoAlign": false
955
+ };
956
+ this.width = 0;
957
+ this.textWidth = null;
958
+ this.intLen = 0;
959
+ this.fracLen = 0;
960
+ this.expLen = 0;
961
+ this.cellAtRow = {};
962
+ this.header = null;
963
+ }
964
+ module2.exports = Column;
965
+ Column.prototype.getWidth = function() {
966
+ return this.width;
967
+ };
968
+ Column.prototype.setTextWidth = function(textWidth) {
969
+ this.textWidth = textWidth;
970
+ };
971
+ Column.prototype.setCellAt = function(row, cell) {
972
+ this.cellAtRow[row] = cell;
973
+ };
974
+ Column.prototype.setHeader = function(header) {
975
+ this.header = header;
976
+ };
977
+ Column.prototype.hasHeader = function() {
978
+ return this.header != null;
979
+ };
980
+ Column.prototype.updateWidth = function() {
981
+ const headerWidth = !this.hasHeader() ? 0 : DataCell.visibleLength("" + this.header);
982
+ this.width = headerWidth;
983
+ Object.keys(this.cellAtRow).forEach((key) => {
984
+ const cell = this.cellAtRow[key];
985
+ const data = cell.getData();
986
+ let width = cell.visibleLength();
987
+ if (typeof data == "number") {
988
+ if (this.opt.autoAlign) {
989
+ this.updateNumWidth(data);
990
+ width = this.getNumMaxWidth();
991
+ }
992
+ }
993
+ if (width > this.width) {
994
+ this.width = width;
995
+ }
996
+ if (typeof data == "string") {
997
+ if (this.textWidth && this.textWidth > headerWidth) {
998
+ if (this.width > this.textWidth) {
999
+ this.width = this.textWidth;
1000
+ }
1001
+ }
1002
+ }
1003
+ });
1004
+ };
1005
+ Column.prototype.formatColumnHeader = function() {
1006
+ if (!this.hasHeader()) {
1007
+ return null;
1008
+ }
1009
+ const width = this.getWidth();
1010
+ const header = this.header;
1011
+ const headerWidth = DataCell.visibleLength("" + header);
1012
+ if (header.length == headerWidth && width - headerWidth <= 0) {
1013
+ return ("" + header).substring(0, width);
1014
+ }
1015
+ return "" + header + " ".repeat(width - headerWidth);
1016
+ };
1017
+ Column.prototype.formatCell = function(data) {
1018
+ const width = this.getWidth();
1019
+ if (this.opt.autoAlign) {
1020
+ if (typeof data == "number") {
1021
+ return this.makeAutoAlignNum(data).padStart(width, " ");
1022
+ }
1023
+ }
1024
+ const dataWidth = DataCell.visibleLength("" + data);
1025
+ if (data.length == dataWidth && width - dataWidth <= 0) {
1026
+ return ("" + data).substring(0, width);
1027
+ }
1028
+ return "" + data + " ".repeat(width - dataWidth);
1029
+ };
1030
+ Column.prototype.setAutoAlign = function(autoAlign) {
1031
+ this.opt.autoAlign = autoAlign;
1032
+ };
1033
+ Column.prototype.updateNumWidth = function(num) {
1034
+ const numInfo = this.analyzeNumber(num);
1035
+ const intLen = numInfo.intStr.length;
1036
+ const fracLen = numInfo.fracStr.length;
1037
+ const expLen = numInfo.expStr.length;
1038
+ if (intLen > this.intLen) {
1039
+ this.intLen = intLen;
1040
+ }
1041
+ if (fracLen > this.fracLen) {
1042
+ this.fracLen = fracLen;
1043
+ }
1044
+ if (expLen > this.expLen) {
1045
+ this.expLen = expLen;
1046
+ }
1047
+ };
1048
+ Column.prototype.getNumMaxWidth = function() {
1049
+ return this.intLen + this.fracLen + (this.fracLen > 0 ? 1 : 0) + this.expLen + (this.expLen > 0 ? 1 : 0);
1050
+ };
1051
+ Column.prototype.makeAutoAlignNum = function(num) {
1052
+ const numInfo = this.analyzeNumber(num);
1053
+ const intStr = numInfo.intStr.padStart(this.intLen, " ");
1054
+ const fracStr = numInfo.expStr != "" ? numInfo.fracStr.padEnd(this.fracLen, "0") : numInfo.fracStr.padEnd(this.fracLen, " ");
1055
+ const expStr = numInfo.expStr.padEnd(this.expLen, " ");
1056
+ if (numInfo.expStr != "") {
1057
+ return [intStr, ".", fracStr, "e", expStr].join("");
1058
+ }
1059
+ if (numInfo.pointPos >= 0) {
1060
+ if (this.expLen > 0) {
1061
+ return [intStr, ".", fracStr, " ", expStr].join("");
1062
+ }
1063
+ return [intStr, ".", fracStr].join("");
1064
+ } else if (this.fracLen == 0) {
1065
+ return intStr;
1066
+ }
1067
+ if (this.expLen > 0) {
1068
+ return [intStr, ".0", fracStr.substr(1), " ", expStr].join("");
1069
+ }
1070
+ return [intStr, ".0", fracStr.substr(1)].join("");
1071
+ };
1072
+ Column.prototype.analyzeNumber = function(num) {
1073
+ const s = "" + num;
1074
+ let intStr = "";
1075
+ let fracStr = "";
1076
+ const pointPos = s.indexOf(".");
1077
+ const expIndex = s.indexOf("e");
1078
+ if (expIndex >= 0) {
1079
+ if (pointPos < 0) {
1080
+ return {
1081
+ pointPos: expIndex,
1082
+ intStr: s.substr(0, expIndex),
1083
+ fracStr: "0",
1084
+ expStr: s.substr(expIndex + 1)
1085
+ };
1086
+ }
1087
+ return {
1088
+ pointPos,
1089
+ intStr: s.substr(0, pointPos),
1090
+ fracStr: s.substring(pointPos + 1, expIndex),
1091
+ expStr: s.substr(expIndex + 1)
1092
+ };
1093
+ }
1094
+ if (pointPos < 0) {
1095
+ intStr = s;
1096
+ } else {
1097
+ intStr = s.substr(0, pointPos);
1098
+ fracStr = s.substr(pointPos + 1);
1099
+ }
1100
+ return {
1101
+ "pointPos": pointPos,
1102
+ "intStr": intStr,
1103
+ "fracStr": fracStr,
1104
+ "expStr": ""
1105
+ };
1106
+ };
1107
+ }
1108
+ });
1109
+
1110
+ // ../../node_modules/ansi-escape-sequences/dist/index.cjs
1111
+ var require_dist = __commonJS({
1112
+ "../../node_modules/ansi-escape-sequences/dist/index.cjs"(exports2, module2) {
1113
+ "use strict";
1114
+ function isObject(input) {
1115
+ return typeof input === "object" && input !== null;
1116
+ }
1117
+ function isArrayLike(input) {
1118
+ return isObject(input) && typeof input.length === "number";
1119
+ }
1120
+ function arrayify(input) {
1121
+ if (Array.isArray(input)) {
1122
+ return input;
1123
+ } else if (input === void 0) {
1124
+ return [];
1125
+ } else if (isArrayLike(input) || input instanceof Set) {
1126
+ return Array.from(input);
1127
+ } else {
1128
+ return [input];
1129
+ }
1130
+ }
1131
+ var csi = "\x1B[";
1132
+ var ansi = {};
1133
+ ansi.style = {
1134
+ reset: "\x1B[0m",
1135
+ bold: "\x1B[1m",
1136
+ italic: "\x1B[3m",
1137
+ underline: "\x1B[4m",
1138
+ fontDefault: "\x1B[10m",
1139
+ font2: "\x1B[11m",
1140
+ font3: "\x1B[12m",
1141
+ font4: "\x1B[13m",
1142
+ font5: "\x1B[14m",
1143
+ font6: "\x1B[15m",
1144
+ imageNegative: "\x1B[7m",
1145
+ imagePositive: "\x1B[27m",
1146
+ black: "\x1B[30m",
1147
+ red: "\x1B[31m",
1148
+ green: "\x1B[32m",
1149
+ yellow: "\x1B[33m",
1150
+ blue: "\x1B[34m",
1151
+ magenta: "\x1B[35m",
1152
+ cyan: "\x1B[36m",
1153
+ white: "\x1B[37m",
1154
+ grey: "\x1B[90m",
1155
+ gray: "\x1B[90m",
1156
+ brightRed: "\x1B[91m",
1157
+ brightGreen: "\x1B[92m",
1158
+ brightYellow: "\x1B[93m",
1159
+ brightBlue: "\x1B[94m",
1160
+ brightMagenta: "\x1B[95m",
1161
+ brightCyan: "\x1B[96m",
1162
+ brightWhite: "\x1B[97m",
1163
+ "bg-black": "\x1B[40m",
1164
+ "bg-red": "\x1B[41m",
1165
+ "bg-green": "\x1B[42m",
1166
+ "bg-yellow": "\x1B[43m",
1167
+ "bg-blue": "\x1B[44m",
1168
+ "bg-magenta": "\x1B[45m",
1169
+ "bg-cyan": "\x1B[46m",
1170
+ "bg-white": "\x1B[47m",
1171
+ "bg-grey": "\x1B[100m",
1172
+ "bg-gray": "\x1B[100m",
1173
+ "bg-brightRed": "\x1B[101m",
1174
+ "bg-brightGreen": "\x1B[102m",
1175
+ "bg-brightYellow": "\x1B[103m",
1176
+ "bg-brightBlue": "\x1B[104m",
1177
+ "bg-brightMagenta": "\x1B[105m",
1178
+ "bg-brightCyan": "\x1B[106m",
1179
+ "bg-brightWhite": "\x1B[107m"
1180
+ };
1181
+ ansi.rgb = function(r, g, b) {
1182
+ return `\x1B[38;2;${r};${g};${b}m`;
1183
+ };
1184
+ ansi.bgRgb = function(r, g, b) {
1185
+ return `\x1B[48;2;${r};${g};${b}m`;
1186
+ };
1187
+ ansi.styles = function(styles) {
1188
+ styles = arrayify(styles);
1189
+ return styles.map(function(effect) {
1190
+ const rgbMatches = effect.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/);
1191
+ const bgRgbMatches = effect.match(/bg-rgb\((\d+),\s*(\d+),\s*(\d+)\)/);
1192
+ if (bgRgbMatches) {
1193
+ const [full, r, g, b] = bgRgbMatches;
1194
+ return ansi.bgRgb(r, g, b);
1195
+ } else if (rgbMatches) {
1196
+ const [full, r, g, b] = rgbMatches;
1197
+ return ansi.rgb(r, g, b);
1198
+ } else {
1199
+ return ansi.style[effect];
1200
+ }
1201
+ }).join("");
1202
+ };
1203
+ ansi.format = function(str, styleArray) {
1204
+ const re = /\[([\w\s-\(\),]+)\]{([^]*?)}/;
1205
+ let matches;
1206
+ str = String(str);
1207
+ if (!str) return "";
1208
+ while (matches = str.match(re)) {
1209
+ const inlineStyles = matches[1].split(/\s+/);
1210
+ const inlineString = matches[2];
1211
+ str = str.replace(matches[0], ansi.format(inlineString, inlineStyles));
1212
+ }
1213
+ return styleArray && styleArray.length ? ansi.styles(styleArray) + str + ansi.style.reset : str;
1214
+ };
1215
+ ansi.cursor = {
1216
+ /**
1217
+ * Moves the cursor `lines` cells up. If the cursor is already at the edge of the screen, this has no effect
1218
+ * @param [lines=1] {number}
1219
+ * @return {string}
1220
+ */
1221
+ up: function(lines) {
1222
+ return csi + (lines || 1) + "A";
1223
+ },
1224
+ /**
1225
+ * Moves the cursor `lines` cells down. If the cursor is already at the edge of the screen, this has no effect
1226
+ * @param [lines=1] {number}
1227
+ * @return {string}
1228
+ */
1229
+ down: function(lines) {
1230
+ return csi + (lines || 1) + "B";
1231
+ },
1232
+ /**
1233
+ * Moves the cursor `lines` cells forward. If the cursor is already at the edge of the screen, this has no effect
1234
+ * @param [lines=1] {number}
1235
+ * @return {string}
1236
+ */
1237
+ forward: function(lines) {
1238
+ return csi + (lines || 1) + "C";
1239
+ },
1240
+ /**
1241
+ * Moves the cursor `lines` cells back. If the cursor is already at the edge of the screen, this has no effect
1242
+ * @param [lines=1] {number}
1243
+ * @return {string}
1244
+ */
1245
+ back: function(lines) {
1246
+ return csi + (lines || 1) + "D";
1247
+ },
1248
+ /**
1249
+ * Moves cursor to beginning of the line n lines down.
1250
+ * @param [lines=1] {number}
1251
+ * @return {string}
1252
+ */
1253
+ nextLine: function(lines) {
1254
+ return csi + (lines || 1) + "E";
1255
+ },
1256
+ /**
1257
+ * Moves cursor to beginning of the line n lines up.
1258
+ * @param [lines=1] {number}
1259
+ * @return {string}
1260
+ */
1261
+ previousLine: function(lines) {
1262
+ return csi + (lines || 1) + "F";
1263
+ },
1264
+ /**
1265
+ * Moves the cursor to column n.
1266
+ * @param n {number} - column number
1267
+ * @return {string}
1268
+ */
1269
+ horizontalAbsolute: function(n) {
1270
+ return csi + n + "G";
1271
+ },
1272
+ /**
1273
+ * Moves the cursor to row n, column m. The values are 1-based, and default to 1 (top left corner) if omitted.
1274
+ * @param n {number} - row number
1275
+ * @param m {number} - column number
1276
+ * @return {string}
1277
+ */
1278
+ position: function(n, m) {
1279
+ return csi + (n || 1) + ";" + (m || 1) + "H";
1280
+ },
1281
+ /**
1282
+ * Hides the cursor
1283
+ */
1284
+ hide: csi + "?25l",
1285
+ /**
1286
+ * Shows the cursor
1287
+ */
1288
+ show: csi + "?25h"
1289
+ };
1290
+ ansi.erase = {
1291
+ /**
1292
+ * Clears part of the screen. If n is 0 (or missing), clear from cursor to end of screen. If n is 1, clear from cursor to beginning of the screen. If n is 2, clear entire screen.
1293
+ * @param n {number}
1294
+ * @return {string}
1295
+ */
1296
+ display: function(n) {
1297
+ return csi + (n || 0) + "J";
1298
+ },
1299
+ /**
1300
+ * Erases part of the line. If n is zero (or missing), clear from cursor to the end of the line. If n is one, clear from cursor to beginning of the line. If n is two, clear entire line. Cursor position does not change.
1301
+ * @param n {number}
1302
+ * @return {string}
1303
+ */
1304
+ inLine: function(n) {
1305
+ return csi + (n || 0) + "K";
1306
+ }
1307
+ };
1308
+ module2.exports = ansi;
1309
+ }
1310
+ });
1311
+
1312
+ // ../../node_modules/list-it/lib/list-it-buffer.js
1313
+ var require_list_it_buffer = __commonJS({
1314
+ "../../node_modules/list-it/lib/list-it-buffer.js"(exports2, module2) {
1315
+ "use strict";
1316
+ var debug = require_src()("list-it-buffer");
1317
+ var DataCell = require_data_cell();
1318
+ var Row = require_row();
1319
+ var Column = require_column();
1320
+ var ansi = require_dist();
1321
+ function ListItBuffer(opt) {
1322
+ opt = opt || {};
1323
+ this.opt = {
1324
+ "autoAlign": true,
1325
+ "columnWidth": null,
1326
+ "header": null,
1327
+ "headerBold": false,
1328
+ "headerColor": "",
1329
+ "headerUnderline": false
1330
+ };
1331
+ if (opt.header != null && !Array.isArray(opt.header)) {
1332
+ throw new Error([
1333
+ `Invalid header was specified. It must be an array, but (${JSON.stringify(opt.header)}):${typeof opt.header} was specified.`
1334
+ ].join(" "));
1335
+ }
1336
+ if (opt.headerColor && !(opt.headerColor in COLORS)) {
1337
+ throw new Error([
1338
+ `Invalid color ${JSON.stringify(opt.headerColor)} was specified.`,
1339
+ "Available color names:",
1340
+ ...AVAILABLE_COLORS.map((color) => `* ${JSON.stringify(color)}`)
1341
+ ].join("\n"));
1342
+ }
1343
+ Object.keys(this.opt).forEach((key) => {
1344
+ if (key in opt) {
1345
+ this.opt[key] = opt[key];
1346
+ }
1347
+ });
1348
+ this.lines = [];
1349
+ this.columns = [];
1350
+ this.columnWidth = this.opt.columnWidth;
1351
+ if (this.opt.header) {
1352
+ this.setHeaderRow(this.opt.header);
1353
+ }
1354
+ }
1355
+ module2.exports = ListItBuffer;
1356
+ ListItBuffer.prototype.nl = function() {
1357
+ const lastRowIndex = this.lines.length - 1;
1358
+ if (lastRowIndex >= 0 && !this.lines[lastRowIndex].isFixed()) {
1359
+ this.lines[lastRowIndex].fix();
1360
+ }
1361
+ this.pushNewRow();
1362
+ return this;
1363
+ };
1364
+ ListItBuffer.prototype.d = function(data) {
1365
+ if (arguments.length > 1) {
1366
+ const array = Array.apply(null, arguments);
1367
+ if (ListItBuffer.isMultiDimensionalArray(array)) {
1368
+ array.forEach((row) => this.addRow(row));
1369
+ } else {
1370
+ array.forEach((data2) => this.d(data2));
1371
+ }
1372
+ return this;
1373
+ }
1374
+ if (Array.isArray(data)) {
1375
+ if (ListItBuffer.isMultiDimensionalArray(data)) {
1376
+ data.forEach((row) => this.addRow(row));
1377
+ } else if (ListItBuffer.isObjectArray(data)) {
1378
+ data = objectArrayToTable(data);
1379
+ if (!this.header && (this.opt.headerBold || this.opt.headerColor || this.opt.headerUnderline)) {
1380
+ this.setHeaderRow(data.shift());
1381
+ }
1382
+ data.forEach((row) => this.addRow(row));
1383
+ } else {
1384
+ this.addRow(data);
1385
+ }
1386
+ return this;
1387
+ }
1388
+ const rowidx = this.lines.length - 1;
1389
+ if (rowidx < 0 || this.lines[rowidx].isFixed()) {
1390
+ this.pushNewRow();
1391
+ }
1392
+ const cell = new DataCell();
1393
+ cell.setData(data);
1394
+ const iRow = this.lines.length - 1;
1395
+ let iCol = this.lines[iRow].getCellLength();
1396
+ if (iCol >= this.columns.length) {
1397
+ this.addColumn();
1398
+ }
1399
+ this.columns[iCol].setCellAt(iRow, cell);
1400
+ this.lines[iRow].pushCell(cell);
1401
+ return this;
1402
+ };
1403
+ ListItBuffer.isMultiDimensionalArray = function(arr) {
1404
+ if (!Array.isArray(arr)) {
1405
+ throw Error("The parameter arr must be array");
1406
+ }
1407
+ for (let element of arr) {
1408
+ if (!Array.isArray(element)) {
1409
+ return false;
1410
+ }
1411
+ }
1412
+ return true;
1413
+ };
1414
+ ListItBuffer.isObjectArray = function(arr) {
1415
+ if (!Array.isArray(arr)) {
1416
+ throw Error("The parameter arr must be array");
1417
+ }
1418
+ const ctor = arr[0].constructor;
1419
+ for (let element of arr) {
1420
+ if (typeof element != "object") {
1421
+ return false;
1422
+ } else {
1423
+ if (element.constructor.name != ctor.name) {
1424
+ return false;
1425
+ }
1426
+ }
1427
+ }
1428
+ return true;
1429
+ };
1430
+ ListItBuffer.prototype.addRow = function(row) {
1431
+ row.forEach((col) => {
1432
+ switch (typeof col) {
1433
+ case "string":
1434
+ case "number":
1435
+ this.d(col);
1436
+ break;
1437
+ default:
1438
+ this.d(col != null ? col.toString() : "(null)");
1439
+ break;
1440
+ }
1441
+ });
1442
+ this.nl();
1443
+ };
1444
+ ListItBuffer.prototype.pushNewRow = function() {
1445
+ this.lines.push(new Row());
1446
+ };
1447
+ ListItBuffer.prototype.toString = function() {
1448
+ const rows = [];
1449
+ this.columns.forEach((column, iCol) => {
1450
+ if (this.header != null) {
1451
+ column.setHeader(this.header[iCol] || "");
1452
+ }
1453
+ column.setTextWidth(this.getColumnWidth(iCol));
1454
+ column.updateWidth();
1455
+ });
1456
+ if (this.header != null) {
1457
+ const headerLine = this.applyHeaderStyleOption(
1458
+ this.columns.map((column) => column.formatColumnHeader()).join(" ")
1459
+ );
1460
+ rows.push(headerLine);
1461
+ const headerUnderline = this.generateHeaderUnderline();
1462
+ if (headerUnderline) {
1463
+ rows.push(headerUnderline);
1464
+ }
1465
+ }
1466
+ this.lines.forEach((line) => {
1467
+ if (line.isFixed() || !line.isEmpty()) {
1468
+ if (line.isEmpty()) {
1469
+ rows.push("\n");
1470
+ } else {
1471
+ rows.push(this.columns.map((column, iCol) => {
1472
+ const cell = line.getCell(iCol);
1473
+ const data = cell.getData();
1474
+ return column.formatCell(data);
1475
+ }).join(" "));
1476
+ }
1477
+ }
1478
+ });
1479
+ return rows.join("\n");
1480
+ };
1481
+ var COLORS = {};
1482
+ var BGCOLORS = {};
1483
+ Object.keys(ansi.style).forEach((key) => {
1484
+ const value = ansi.style[key];
1485
+ if (/^bg-/.test(key)) {
1486
+ BGCOLORS[key.substr(3)] = value;
1487
+ } else {
1488
+ COLORS[key] = value;
1489
+ debug(`COLOR-KEY: ${key}`);
1490
+ }
1491
+ });
1492
+ Object.keys(COLORS).forEach((key) => {
1493
+ if (!(key in BGCOLORS)) {
1494
+ delete COLORS[key];
1495
+ debug(`remove COLOR-KEY: ${key}`);
1496
+ }
1497
+ });
1498
+ var AVAILABLE_COLORS = Object.keys(COLORS);
1499
+ debug(`AVAILABLE_COLORS:${JSON.stringify(AVAILABLE_COLORS)}`);
1500
+ ListItBuffer.prototype.applyHeaderStyleOption = function(line) {
1501
+ if (!this.opt.headerBold && !this.opt.headerColor) {
1502
+ return line;
1503
+ }
1504
+ const textBuffer = [];
1505
+ if (this.opt.headerBold) {
1506
+ textBuffer.push(ansi.style.bold);
1507
+ }
1508
+ if (this.opt.headerColor) {
1509
+ textBuffer.push(COLORS[this.opt.headerColor]);
1510
+ }
1511
+ textBuffer.push(line);
1512
+ textBuffer.push(ansi.style.reset);
1513
+ return textBuffer.join("");
1514
+ };
1515
+ ListItBuffer.prototype.generateHeaderUnderline = function() {
1516
+ if (!this.opt.headerUnderline) {
1517
+ return null;
1518
+ }
1519
+ if (this.header == null) {
1520
+ return null;
1521
+ }
1522
+ return this.columns.map(
1523
+ (column) => "-".repeat(column.getWidth())
1524
+ ).join(" ");
1525
+ };
1526
+ function objectArrayToTable(objects) {
1527
+ const keys = Object.keys(objects[0]);
1528
+ const body = objects.map((item) => keys.map((key) => {
1529
+ if (item[key] != null && typeof item[key] == "object" && item[key].constructor.name == "Date") {
1530
+ return item[key].toISOString();
1531
+ }
1532
+ return item[key];
1533
+ }));
1534
+ return [keys, ...body];
1535
+ }
1536
+ ListItBuffer.prototype.setColumnWidth = function(indexOfColumns, width) {
1537
+ this.columnWidth = this.columnWidth || [];
1538
+ if (typeof indexOfColumns !== "number") {
1539
+ throw new Error("indexOfColumns must be a number");
1540
+ }
1541
+ if (!width) {
1542
+ delete this.columnWidth[indexOfColumns];
1543
+ } else {
1544
+ if (typeof width !== "number") {
1545
+ throw new Error("width must be a number");
1546
+ }
1547
+ this.columnWidth[indexOfColumns] = width;
1548
+ }
1549
+ return this;
1550
+ };
1551
+ ListItBuffer.prototype.setColumnWidthAll = function(widthForAll) {
1552
+ if (widthForAll != null && !Array.isArray(widthForAll) && typeof widthForAll !== "number") {
1553
+ throw new Error(
1554
+ "widthForAll must be one of a null, an Array or a number"
1555
+ );
1556
+ }
1557
+ if (Array.isArray(widthForAll)) {
1558
+ for (let i = 0; i < widthForAll.length; i++) {
1559
+ const width = widthForAll[i];
1560
+ if (width != void 0 && typeof width !== "number") {
1561
+ throw new Error(
1562
+ `widthForAll[${i}] must be an undefined or a number`
1563
+ );
1564
+ }
1565
+ }
1566
+ }
1567
+ this.columnWidth = widthForAll;
1568
+ return this;
1569
+ };
1570
+ ListItBuffer.prototype.getColumnWidth = function(indexOfColumns) {
1571
+ if (Array.isArray(this.columnWidth)) {
1572
+ return this.columnWidth[indexOfColumns];
1573
+ }
1574
+ return this.columnWidth;
1575
+ };
1576
+ ListItBuffer.prototype.setHeaderRow = function(header) {
1577
+ if (header && !Array.isArray(header)) {
1578
+ throw new Error([
1579
+ "The header must be an array,",
1580
+ `but ${typeof header} was specified.`,
1581
+ `header: ${JSON.stringify(header)}`
1582
+ ].join(" "));
1583
+ }
1584
+ this.header = header;
1585
+ if (this.header == null) {
1586
+ this.columns.forEach((column) => column.setHeader(null));
1587
+ } else {
1588
+ this.header.forEach((headerText, iCol) => {
1589
+ if (iCol >= this.columns.length) {
1590
+ this.addColumn(headerText);
1591
+ }
1592
+ });
1593
+ }
1594
+ return this;
1595
+ };
1596
+ ListItBuffer.prototype.addColumn = function(headerText) {
1597
+ const column = new Column();
1598
+ if (headerText) {
1599
+ column.setHeader(headerText);
1600
+ }
1601
+ if (this.opt.autoAlign) {
1602
+ column.setAutoAlign(true);
1603
+ }
1604
+ this.columns.push(column);
1605
+ };
1606
+ }
1607
+ });
1608
+
1609
+ // ../../node_modules/list-it/index.js
1610
+ var require_list_it = __commonJS({
1611
+ "../../node_modules/list-it/index.js"(exports2, module2) {
1612
+ "use strict";
1613
+ var ListItBuffer = require_list_it_buffer();
1614
+ function ListIt2(opt) {
1615
+ ListItBuffer.call(this, opt);
1616
+ }
1617
+ ListIt2.prototype = new ListItBuffer();
1618
+ ListIt2.buffer = function(opt) {
1619
+ opt = opt || {};
1620
+ if (!("autoAlign" in opt)) {
1621
+ opt.autoAlign = false;
1622
+ }
1623
+ return new ListIt2(opt);
1624
+ };
1625
+ module2.exports = ListIt2;
1626
+ }
1627
+ });
24
1628
 
25
1629
  // src/scripts/mlExport.ts
1630
+ var mlExport_exports = {};
1631
+ __export(mlExport_exports, {
1632
+ main: () => main
1633
+ });
1634
+ module.exports = __toCommonJS(mlExport_exports);
26
1635
  var import_args = __toESM(require("args"));
27
1636
  var import_chalk2 = __toESM(require("chalk"));
28
1637
  var import_promises = __toESM(require("fs/promises"));
29
1638
  var import_path = __toESM(require("path"));
30
1639
  var import_ml = require("@tradejs/infra/ml");
31
1640
 
1641
+ // src/lib/backtest/checkpoint.ts
1642
+ var import_node_crypto = require("crypto");
1643
+ var import_constants = require("@tradejs/core/constants");
1644
+ var import_redis = require("@tradejs/infra/redis");
1645
+
1646
+ // src/lib/runFormatting.ts
1647
+ var import_date_fns = require("date-fns");
1648
+ var ListIt = require_list_it();
1649
+
1650
+ // src/lib/backtest/checkpoint.ts
1651
+ var buildBacktestDatasetAttemptKey = ({
1652
+ chunkId,
1653
+ testKey
1654
+ }) => {
1655
+ const resolvedTestKey = typeof testKey === "string" ? testKey.trim() : "";
1656
+ const resolvedChunkId = typeof chunkId === "string" ? chunkId.trim() : "";
1657
+ return resolvedTestKey && resolvedChunkId ? `${resolvedTestKey}:${resolvedChunkId}` : "";
1658
+ };
1659
+ var buildCompletedBacktestDatasetAttemptKeys = (completed) => new Set(
1660
+ completed.map(
1661
+ (item) => buildBacktestDatasetAttemptKey({
1662
+ testKey: item.testKey,
1663
+ chunkId: item.result?.test?.chunkId
1664
+ })
1665
+ ).filter(Boolean)
1666
+ );
1667
+ var isBacktestDatasetRowForCompletedAttempt = (row, completedAttemptKeys) => completedAttemptKeys.has(
1668
+ buildBacktestDatasetAttemptKey({
1669
+ testKey: row.backtestTestKey,
1670
+ chunkId: row.backtestChunkId
1671
+ })
1672
+ );
1673
+ var loadBacktestCheckpointResults = async ({
1674
+ runId,
1675
+ userName
1676
+ }) => (0, import_redis.getHashJsonValues)(
1677
+ import_redis.redisKeys.backtestRunResults(userName, runId)
1678
+ );
1679
+
32
1680
  // src/scripts/selectStrategy.ts
33
1681
  var import_readline = __toESM(require("readline"));
34
1682
  var import_chalk = __toESM(require("chalk"));
@@ -135,11 +1783,38 @@ import_args.default.option(
135
1783
  "Keep source chunk files after successful merge",
136
1784
  false
137
1785
  );
1786
+ import_args.default.option(["R", "runId"], "Backtest run id to export");
1787
+ import_args.default.option(
1788
+ ["u", "user"],
1789
+ "Backtest user for checkpoint-filtered export",
1790
+ "root"
1791
+ );
138
1792
  var flags = import_args.default.parse(process.argv);
139
- var listChunkFiles = async (outDir, strategyName) => {
140
- const prefix = `ml-dataset-${(0, import_ml.toFileToken)(strategyName)}-chunk-`;
141
- const entries = await import_promises.default.readdir(outDir, { withFileTypes: true });
142
- return entries.filter((entry) => entry.isFile()).map((entry) => entry.name).filter((name) => name.startsWith(prefix) && name.endsWith(".jsonl")).map((name) => import_path.default.join(outDir, name)).sort();
1793
+ var resolveRunScopedMlChunks = async ({
1794
+ outDir,
1795
+ strategyName
1796
+ }) => {
1797
+ const requestedRunId = typeof flags.runId === "string" && flags.runId.trim() ? flags.runId.trim() : "";
1798
+ const runIds = requestedRunId ? [requestedRunId] : await (0, import_ml.listMlChunkRunIds)({ strategyName, outDir });
1799
+ const runId = runIds.at(-1) ?? "";
1800
+ if (!runId) {
1801
+ return null;
1802
+ }
1803
+ const chunkFiles = await (0, import_ml.listMlChunkFiles)({ strategyName, outDir, runId });
1804
+ if (!chunkFiles.length) {
1805
+ return {
1806
+ runId,
1807
+ chunkFiles,
1808
+ completedAttemptKeys: /* @__PURE__ */ new Set()
1809
+ };
1810
+ }
1811
+ const userName = String(flags.user || "root");
1812
+ const completed = await loadBacktestCheckpointResults({ runId, userName });
1813
+ return {
1814
+ runId,
1815
+ chunkFiles,
1816
+ completedAttemptKeys: buildCompletedBacktestDatasetAttemptKeys(completed)
1817
+ };
143
1818
  };
144
1819
  var main = async () => {
145
1820
  const outDir = String(flags.outDir || "data/ml/export");
@@ -155,7 +1830,11 @@ var main = async () => {
155
1830
  console.log(import_chalk2.default.yellow(`No ML chunk files found in ${outDir}`));
156
1831
  process.exit(0);
157
1832
  }
158
- const chunkFiles = await listChunkFiles(outDir, strategyName);
1833
+ const runScopedChunks = await resolveRunScopedMlChunks({
1834
+ strategyName,
1835
+ outDir
1836
+ });
1837
+ const chunkFiles = runScopedChunks ? runScopedChunks.chunkFiles : await (0, import_ml.listMlChunkFiles)({ outDir, strategyName });
159
1838
  if (!chunkFiles.length) {
160
1839
  console.log(
161
1840
  import_chalk2.default.yellow(
@@ -164,13 +1843,22 @@ var main = async () => {
164
1843
  );
165
1844
  process.exit(0);
166
1845
  }
1846
+ if (runScopedChunks && runScopedChunks.completedAttemptKeys.size === 0) {
1847
+ throw new Error(
1848
+ `No completed checkpoint attempts found for ML export run "${runScopedChunks.runId}"`
1849
+ );
1850
+ }
167
1851
  const mergedPath = import_path.default.join(
168
1852
  outDir,
169
1853
  `ml-dataset-${(0, import_ml.toFileToken)(strategyName)}-merged-${Date.now()}.jsonl`
170
1854
  );
171
1855
  await (0, import_ml.mergeJsonlFiles)({
172
1856
  filePaths: chunkFiles,
173
- outPath: mergedPath
1857
+ outPath: mergedPath,
1858
+ shouldIncludeRow: runScopedChunks ? (row) => isBacktestDatasetRowForCompletedAttempt(
1859
+ row,
1860
+ runScopedChunks.completedAttemptKeys
1861
+ ) : void 0
174
1862
  });
175
1863
  const shouldDeleteChunks = !Boolean(flags.keepChunks);
176
1864
  if (shouldDeleteChunks) {
@@ -183,12 +1871,12 @@ var main = async () => {
183
1871
  import_chalk2.default.gray(
184
1872
  `strategy=${strategyName}, source_chunks=${chunkFiles.length}, deleteChunks=${Boolean(
185
1873
  shouldDeleteChunks
186
- )}`
1874
+ )}${runScopedChunks ? `, runId=${runScopedChunks.runId}, completedAttempts=${runScopedChunks.completedAttemptKeys.size}` : ""}`
187
1875
  )
188
1876
  );
189
1877
  process.exit(0);
190
1878
  };
191
- main().catch((error) => {
192
- console.error(import_chalk2.default.red(error?.message || String(error)));
193
- process.exit(1);
1879
+ // Annotate the CommonJS export names for ESM import in node:
1880
+ 0 && (module.exports = {
1881
+ main
194
1882
  });