@tradejs/cli 2.0.5 → 2.0.7
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/cli.js +3145 -1827
- package/dist/lib/aiExport.js +1822 -0
- package/dist/lib/binanceMarketContextBackfill.js +97 -88
- package/dist/lib/binanceMarketData.js +6 -3
- package/dist/lib/marketContextPrepare.js +149 -125
- package/dist/lib/runEnvironment.js +100 -55
- package/dist/lib/runFormatting.js +52 -37
- package/dist/lib/runtimeLineage.js +255 -0
- package/dist/lib/runtimeParityDetails.js +24 -1
- package/dist/lib/runtimeSignalsLoader.js +19 -0
- package/dist/lib/runtimeSignalsStorage.js +3 -0
- package/dist/lib/runtimeTradeSync.js +40 -11
- package/dist/lib/timeWindow.js +44 -16
- package/dist/scripts/aiExport.js +252 -125
- package/dist/scripts/aiPocketSearch.js +52 -37
- package/dist/scripts/aiTrain.js +52 -37
- package/dist/scripts/backtest.js +222 -144
- package/dist/scripts/binanceBreadthUniversesUpdate.js +120 -0
- package/dist/scripts/binanceMarketIngest.js +32 -33
- package/dist/scripts/candlesMigrateProvider.js +648 -419
- package/dist/scripts/doctor.js +648 -419
- package/dist/scripts/mlExport.js +57 -39
- package/dist/scripts/replay.js +1040 -255
- package/dist/scripts/replayRunner.js +1040 -255
- package/dist/scripts/replayRuntimeEvidence.js +3 -1
- package/dist/scripts/resolveExportStrategy.js +7 -2
- package/dist/scripts/results.js +52 -37
- package/dist/scripts/runtimeParity.js +193 -141
- package/dist/scripts/signals.js +433 -144
- package/dist/scripts/signalsDaemon.js +433 -144
- package/dist/scripts/signalsSummary.js +40 -11
- package/package.json +15 -14
package/dist/scripts/aiExport.js
CHANGED
|
@@ -34,9 +34,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
34
34
|
));
|
|
35
35
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
36
36
|
|
|
37
|
-
// ../../node_modules/
|
|
37
|
+
// ../../node_modules/ms/index.js
|
|
38
38
|
var require_ms = __commonJS({
|
|
39
|
-
"../../node_modules/
|
|
39
|
+
"../../node_modules/ms/index.js"(exports2, module2) {
|
|
40
40
|
"use strict";
|
|
41
41
|
var s = 1e3;
|
|
42
42
|
var m = s * 60;
|
|
@@ -151,9 +151,9 @@ var require_ms = __commonJS({
|
|
|
151
151
|
}
|
|
152
152
|
});
|
|
153
153
|
|
|
154
|
-
// ../../node_modules/debug/src/common.js
|
|
154
|
+
// ../../node_modules/list-it/node_modules/debug/src/common.js
|
|
155
155
|
var require_common = __commonJS({
|
|
156
|
-
"../../node_modules/debug/src/common.js"(exports2, module2) {
|
|
156
|
+
"../../node_modules/list-it/node_modules/debug/src/common.js"(exports2, module2) {
|
|
157
157
|
"use strict";
|
|
158
158
|
function setup(env) {
|
|
159
159
|
createDebug.debug = createDebug;
|
|
@@ -255,50 +255,64 @@ var require_common = __commonJS({
|
|
|
255
255
|
createDebug.namespaces = namespaces;
|
|
256
256
|
createDebug.names = [];
|
|
257
257
|
createDebug.skips = [];
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
258
|
+
const split = (typeof namespaces === "string" ? namespaces : "").trim().replace(/\s+/g, ",").split(",").filter(Boolean);
|
|
259
|
+
for (const ns of split) {
|
|
260
|
+
if (ns[0] === "-") {
|
|
261
|
+
createDebug.skips.push(ns.slice(1));
|
|
262
|
+
} else {
|
|
263
|
+
createDebug.names.push(ns);
|
|
264
264
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
function matchesTemplate(search, template) {
|
|
268
|
+
let searchIndex = 0;
|
|
269
|
+
let templateIndex = 0;
|
|
270
|
+
let starIndex = -1;
|
|
271
|
+
let matchIndex = 0;
|
|
272
|
+
while (searchIndex < search.length) {
|
|
273
|
+
if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === "*")) {
|
|
274
|
+
if (template[templateIndex] === "*") {
|
|
275
|
+
starIndex = templateIndex;
|
|
276
|
+
matchIndex = searchIndex;
|
|
277
|
+
templateIndex++;
|
|
278
|
+
} else {
|
|
279
|
+
searchIndex++;
|
|
280
|
+
templateIndex++;
|
|
281
|
+
}
|
|
282
|
+
} else if (starIndex !== -1) {
|
|
283
|
+
templateIndex = starIndex + 1;
|
|
284
|
+
matchIndex++;
|
|
285
|
+
searchIndex = matchIndex;
|
|
268
286
|
} else {
|
|
269
|
-
|
|
287
|
+
return false;
|
|
270
288
|
}
|
|
271
289
|
}
|
|
290
|
+
while (templateIndex < template.length && template[templateIndex] === "*") {
|
|
291
|
+
templateIndex++;
|
|
292
|
+
}
|
|
293
|
+
return templateIndex === template.length;
|
|
272
294
|
}
|
|
273
295
|
function disable() {
|
|
274
296
|
const namespaces = [
|
|
275
|
-
...createDebug.names
|
|
276
|
-
...createDebug.skips.map(
|
|
297
|
+
...createDebug.names,
|
|
298
|
+
...createDebug.skips.map((namespace) => "-" + namespace)
|
|
277
299
|
].join(",");
|
|
278
300
|
createDebug.enable("");
|
|
279
301
|
return namespaces;
|
|
280
302
|
}
|
|
281
303
|
function enabled(name) {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
}
|
|
285
|
-
let i;
|
|
286
|
-
let len;
|
|
287
|
-
for (i = 0, len = createDebug.skips.length; i < len; i++) {
|
|
288
|
-
if (createDebug.skips[i].test(name)) {
|
|
304
|
+
for (const skip of createDebug.skips) {
|
|
305
|
+
if (matchesTemplate(name, skip)) {
|
|
289
306
|
return false;
|
|
290
307
|
}
|
|
291
308
|
}
|
|
292
|
-
for (
|
|
293
|
-
if (
|
|
309
|
+
for (const ns of createDebug.names) {
|
|
310
|
+
if (matchesTemplate(name, ns)) {
|
|
294
311
|
return true;
|
|
295
312
|
}
|
|
296
313
|
}
|
|
297
314
|
return false;
|
|
298
315
|
}
|
|
299
|
-
function toNamespace(regexp) {
|
|
300
|
-
return regexp.toString().substring(2, regexp.toString().length - 2).replace(/\.\*\?$/, "*");
|
|
301
|
-
}
|
|
302
316
|
function coerce(val) {
|
|
303
317
|
if (val instanceof Error) {
|
|
304
318
|
return val.stack || val.message;
|
|
@@ -315,9 +329,9 @@ var require_common = __commonJS({
|
|
|
315
329
|
}
|
|
316
330
|
});
|
|
317
331
|
|
|
318
|
-
// ../../node_modules/debug/src/browser.js
|
|
332
|
+
// ../../node_modules/list-it/node_modules/debug/src/browser.js
|
|
319
333
|
var require_browser = __commonJS({
|
|
320
|
-
"../../node_modules/debug/src/browser.js"(exports2, module2) {
|
|
334
|
+
"../../node_modules/list-it/node_modules/debug/src/browser.js"(exports2, module2) {
|
|
321
335
|
"use strict";
|
|
322
336
|
exports2.formatArgs = formatArgs;
|
|
323
337
|
exports2.save = save;
|
|
@@ -418,10 +432,11 @@ var require_browser = __commonJS({
|
|
|
418
432
|
if (typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
|
|
419
433
|
return false;
|
|
420
434
|
}
|
|
435
|
+
let m;
|
|
421
436
|
return typeof document !== "undefined" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || // Is firebug? http://stackoverflow.com/a/398120/376773
|
|
422
437
|
typeof window !== "undefined" && window.console && (window.console.firebug || window.console.exception && window.console.table) || // Is firefox >= v31?
|
|
423
438
|
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
|
|
424
|
-
typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(
|
|
439
|
+
typeof navigator !== "undefined" && navigator.userAgent && (m = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(m[1], 10) >= 31 || // Double check webkit in userAgent just in case we are in a worker
|
|
425
440
|
typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
|
|
426
441
|
}
|
|
427
442
|
function formatArgs(args2) {
|
|
@@ -459,7 +474,7 @@ var require_browser = __commonJS({
|
|
|
459
474
|
function load() {
|
|
460
475
|
let r;
|
|
461
476
|
try {
|
|
462
|
-
r = exports2.storage.getItem("debug");
|
|
477
|
+
r = exports2.storage.getItem("debug") || exports2.storage.getItem("DEBUG");
|
|
463
478
|
} catch (error) {
|
|
464
479
|
}
|
|
465
480
|
if (!r && typeof process !== "undefined" && "env" in process) {
|
|
@@ -600,9 +615,9 @@ var require_supports_color = __commonJS({
|
|
|
600
615
|
}
|
|
601
616
|
});
|
|
602
617
|
|
|
603
|
-
// ../../node_modules/debug/src/node.js
|
|
618
|
+
// ../../node_modules/list-it/node_modules/debug/src/node.js
|
|
604
619
|
var require_node = __commonJS({
|
|
605
|
-
"../../node_modules/debug/src/node.js"(exports2, module2) {
|
|
620
|
+
"../../node_modules/list-it/node_modules/debug/src/node.js"(exports2, module2) {
|
|
606
621
|
"use strict";
|
|
607
622
|
var tty = require("tty");
|
|
608
623
|
var util = require("util");
|
|
@@ -743,7 +758,7 @@ var require_node = __commonJS({
|
|
|
743
758
|
return (/* @__PURE__ */ new Date()).toISOString() + " ";
|
|
744
759
|
}
|
|
745
760
|
function log(...args2) {
|
|
746
|
-
return process.stderr.write(util.
|
|
761
|
+
return process.stderr.write(util.formatWithOptions(exports2.inspectOpts, ...args2) + "\n");
|
|
747
762
|
}
|
|
748
763
|
function save(namespaces) {
|
|
749
764
|
if (namespaces) {
|
|
@@ -775,9 +790,9 @@ var require_node = __commonJS({
|
|
|
775
790
|
}
|
|
776
791
|
});
|
|
777
792
|
|
|
778
|
-
// ../../node_modules/debug/src/index.js
|
|
793
|
+
// ../../node_modules/list-it/node_modules/debug/src/index.js
|
|
779
794
|
var require_src = __commonJS({
|
|
780
|
-
"../../node_modules/debug/src/index.js"(exports2, module2) {
|
|
795
|
+
"../../node_modules/list-it/node_modules/debug/src/index.js"(exports2, module2) {
|
|
781
796
|
"use strict";
|
|
782
797
|
if (typeof process === "undefined" || process.type === "renderer" || process.browser === true || process.__nwjs) {
|
|
783
798
|
module2.exports = require_browser();
|
|
@@ -1626,6 +1641,11 @@ __export(aiExport_exports, {
|
|
|
1626
1641
|
module.exports = __toCommonJS(aiExport_exports);
|
|
1627
1642
|
var import_args = __toESM(require("args"));
|
|
1628
1643
|
var import_chalk2 = __toESM(require("chalk"));
|
|
1644
|
+
var import_promises2 = __toESM(require("fs/promises"));
|
|
1645
|
+
var import_progress = __toESM(require("progress"));
|
|
1646
|
+
var import_ai2 = require("@tradejs/infra/ai");
|
|
1647
|
+
|
|
1648
|
+
// src/lib/aiExport.ts
|
|
1629
1649
|
var import_promises = __toESM(require("fs/promises"));
|
|
1630
1650
|
var import_path = __toESM(require("path"));
|
|
1631
1651
|
var import_ai = require("@tradejs/infra/ai");
|
|
@@ -1669,6 +1689,139 @@ var loadBacktestCheckpointResults = async ({
|
|
|
1669
1689
|
import_redis.redisKeys.backtestRunResults(userName, runId)
|
|
1670
1690
|
);
|
|
1671
1691
|
|
|
1692
|
+
// src/lib/aiExport.ts
|
|
1693
|
+
var resolveRunScopedAiChunks = async ({
|
|
1694
|
+
outDir,
|
|
1695
|
+
requestedRunId,
|
|
1696
|
+
strategyName,
|
|
1697
|
+
userName
|
|
1698
|
+
}) => {
|
|
1699
|
+
const resolvedRunId = String(requestedRunId || "").trim();
|
|
1700
|
+
const runIds = resolvedRunId ? [resolvedRunId] : await (0, import_ai.listAiChunkRunIds)({ strategyName, outDir });
|
|
1701
|
+
const runId = runIds.at(-1) ?? "";
|
|
1702
|
+
if (!runId) {
|
|
1703
|
+
return null;
|
|
1704
|
+
}
|
|
1705
|
+
const chunkFiles = await (0, import_ai.listAiChunkFiles)({ strategyName, outDir, runId });
|
|
1706
|
+
if (!chunkFiles.length) {
|
|
1707
|
+
return {
|
|
1708
|
+
runId,
|
|
1709
|
+
chunkFiles,
|
|
1710
|
+
completedAttemptKeys: /* @__PURE__ */ new Set()
|
|
1711
|
+
};
|
|
1712
|
+
}
|
|
1713
|
+
const completed = await loadBacktestCheckpointResults({ runId, userName });
|
|
1714
|
+
return {
|
|
1715
|
+
runId,
|
|
1716
|
+
chunkFiles,
|
|
1717
|
+
completedAttemptKeys: buildCompletedBacktestDatasetAttemptKeys(completed)
|
|
1718
|
+
};
|
|
1719
|
+
};
|
|
1720
|
+
var exportAiStrategy = async (params) => {
|
|
1721
|
+
const {
|
|
1722
|
+
outDir,
|
|
1723
|
+
strategyName,
|
|
1724
|
+
keepChunks,
|
|
1725
|
+
requestedRunId,
|
|
1726
|
+
userName,
|
|
1727
|
+
now = Date.now
|
|
1728
|
+
} = params;
|
|
1729
|
+
const partMonths = Math.max(0, Math.trunc(Number(params.partMonths) || 0));
|
|
1730
|
+
const runScopedChunks = await resolveRunScopedAiChunks({
|
|
1731
|
+
outDir,
|
|
1732
|
+
requestedRunId,
|
|
1733
|
+
strategyName,
|
|
1734
|
+
userName
|
|
1735
|
+
});
|
|
1736
|
+
const chunkFiles = runScopedChunks ? runScopedChunks.chunkFiles : await (0, import_ai.listAiChunkFiles)({ strategyName, outDir });
|
|
1737
|
+
if (!chunkFiles.length) {
|
|
1738
|
+
return null;
|
|
1739
|
+
}
|
|
1740
|
+
if (runScopedChunks && runScopedChunks.completedAttemptKeys.size === 0) {
|
|
1741
|
+
throw new Error(
|
|
1742
|
+
`No completed checkpoint attempts found for AI export run "${runScopedChunks.runId}"`
|
|
1743
|
+
);
|
|
1744
|
+
}
|
|
1745
|
+
const completedAttemptCount = runScopedChunks?.completedAttemptKeys.size ?? void 0;
|
|
1746
|
+
const mergedPath = import_path.default.join(
|
|
1747
|
+
outDir,
|
|
1748
|
+
`ai-dataset-${(0, import_ai.toFileToken)(strategyName)}-merged-${now()}.jsonl`
|
|
1749
|
+
);
|
|
1750
|
+
await (0, import_ai.mergeAiJsonlFiles)({
|
|
1751
|
+
filePaths: chunkFiles,
|
|
1752
|
+
outPath: mergedPath,
|
|
1753
|
+
shouldIncludeRow: runScopedChunks ? (row) => isBacktestDatasetRowForCompletedAttempt(
|
|
1754
|
+
row,
|
|
1755
|
+
runScopedChunks.completedAttemptKeys
|
|
1756
|
+
) : void 0
|
|
1757
|
+
});
|
|
1758
|
+
runScopedChunks?.completedAttemptKeys.clear();
|
|
1759
|
+
const splitResult = partMonths > 0 ? await (0, import_ai.splitAiMergedDatasetFile)({
|
|
1760
|
+
filePath: mergedPath,
|
|
1761
|
+
monthsPerPart: partMonths
|
|
1762
|
+
}) : {
|
|
1763
|
+
partPaths: [mergedPath],
|
|
1764
|
+
partCount: 1,
|
|
1765
|
+
splitApplied: false
|
|
1766
|
+
};
|
|
1767
|
+
const shouldDeleteChunks = !keepChunks;
|
|
1768
|
+
if (shouldDeleteChunks) {
|
|
1769
|
+
for (const filePath of chunkFiles) {
|
|
1770
|
+
await import_promises.default.rm(filePath, { force: true });
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
return {
|
|
1774
|
+
strategyName,
|
|
1775
|
+
sourceChunkCount: chunkFiles.length,
|
|
1776
|
+
deleteChunks: shouldDeleteChunks,
|
|
1777
|
+
partMonths,
|
|
1778
|
+
partPaths: splitResult.partPaths,
|
|
1779
|
+
partCount: splitResult.partCount,
|
|
1780
|
+
splitApplied: splitResult.splitApplied,
|
|
1781
|
+
runId: runScopedChunks?.runId,
|
|
1782
|
+
completedAttemptCount
|
|
1783
|
+
};
|
|
1784
|
+
};
|
|
1785
|
+
var exportAiStrategiesSequentially = async (params, dependencies = {}) => {
|
|
1786
|
+
const { strategyNames, onProgress, ...strategyParams } = params;
|
|
1787
|
+
const runExport = dependencies.exportStrategy ?? exportAiStrategy;
|
|
1788
|
+
const results = [];
|
|
1789
|
+
const total = strategyNames.length;
|
|
1790
|
+
for (let index = 0; index < strategyNames.length; index += 1) {
|
|
1791
|
+
const strategyName = strategyNames[index];
|
|
1792
|
+
onProgress?.({
|
|
1793
|
+
strategyName,
|
|
1794
|
+
current: index,
|
|
1795
|
+
total,
|
|
1796
|
+
status: "started"
|
|
1797
|
+
});
|
|
1798
|
+
try {
|
|
1799
|
+
const result = await runExport({
|
|
1800
|
+
...strategyParams,
|
|
1801
|
+
strategyName
|
|
1802
|
+
});
|
|
1803
|
+
if (result) {
|
|
1804
|
+
results.push(result);
|
|
1805
|
+
}
|
|
1806
|
+
onProgress?.({
|
|
1807
|
+
strategyName,
|
|
1808
|
+
current: index + 1,
|
|
1809
|
+
total,
|
|
1810
|
+
status: result ? "completed" : "skipped"
|
|
1811
|
+
});
|
|
1812
|
+
} catch (error) {
|
|
1813
|
+
onProgress?.({
|
|
1814
|
+
strategyName,
|
|
1815
|
+
current: index,
|
|
1816
|
+
total,
|
|
1817
|
+
status: "failed"
|
|
1818
|
+
});
|
|
1819
|
+
throw error;
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
return results;
|
|
1823
|
+
};
|
|
1824
|
+
|
|
1672
1825
|
// src/scripts/selectStrategy.ts
|
|
1673
1826
|
var import_readline = __toESM(require("readline"));
|
|
1674
1827
|
var import_chalk = __toESM(require("chalk"));
|
|
@@ -1735,12 +1888,14 @@ var selectStrategy = async (promptLabel = "Select strategy", options) => {
|
|
|
1735
1888
|
};
|
|
1736
1889
|
|
|
1737
1890
|
// src/scripts/resolveExportStrategy.ts
|
|
1891
|
+
var ALL_EXPORT_STRATEGIES = "all";
|
|
1738
1892
|
var resolveExportStrategy = async ({
|
|
1739
1893
|
explicitStrategy,
|
|
1740
1894
|
outDir,
|
|
1741
1895
|
datasetLabel,
|
|
1742
1896
|
promptLabel,
|
|
1743
|
-
listStrategies
|
|
1897
|
+
listStrategies,
|
|
1898
|
+
includeAllOption = false
|
|
1744
1899
|
}) => {
|
|
1745
1900
|
const raw = String(explicitStrategy || "").trim();
|
|
1746
1901
|
if (raw) {
|
|
@@ -1758,8 +1913,9 @@ var resolveExportStrategy = async ({
|
|
|
1758
1913
|
`Multiple ${datasetLabel} chunk strategies found in ${outDir}: ${availableStrategies.join(", ")}. Pass --strategy.`
|
|
1759
1914
|
);
|
|
1760
1915
|
}
|
|
1916
|
+
const promptStrategies = includeAllOption ? [...availableStrategies, ALL_EXPORT_STRATEGIES] : availableStrategies;
|
|
1761
1917
|
return selectStrategy(promptLabel, {
|
|
1762
|
-
strategies:
|
|
1918
|
+
strategies: promptStrategies,
|
|
1763
1919
|
defaultStrategy: availableStrategies[0]
|
|
1764
1920
|
});
|
|
1765
1921
|
};
|
|
@@ -1788,110 +1944,81 @@ import_args.default.option(
|
|
|
1788
1944
|
"root"
|
|
1789
1945
|
);
|
|
1790
1946
|
var flags = import_args.default.parse(process.argv);
|
|
1791
|
-
var
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
}
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
runId,
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
};
|
|
1808
|
-
}
|
|
1809
|
-
const userName = String(flags.user || "root");
|
|
1810
|
-
const completed = await loadBacktestCheckpointResults({ runId, userName });
|
|
1811
|
-
return {
|
|
1812
|
-
runId,
|
|
1813
|
-
chunkFiles,
|
|
1814
|
-
completedAttemptKeys: buildCompletedBacktestDatasetAttemptKeys(completed)
|
|
1815
|
-
};
|
|
1947
|
+
var printExportResult = (result) => {
|
|
1948
|
+
console.log(
|
|
1949
|
+
import_chalk2.default.green(
|
|
1950
|
+
result.splitApplied ? `Merged AI dataset for ${result.strategyName} saved as ${result.partCount} part files` : `Merged AI dataset saved: ${result.partPaths[0]}`
|
|
1951
|
+
)
|
|
1952
|
+
);
|
|
1953
|
+
result.partPaths.forEach((filePath, index) => {
|
|
1954
|
+
console.log(import_chalk2.default.gray(`part${index + 1}: ${filePath}`));
|
|
1955
|
+
});
|
|
1956
|
+
console.log(
|
|
1957
|
+
import_chalk2.default.gray(
|
|
1958
|
+
`strategy=${result.strategyName}, source_chunks=${result.sourceChunkCount}, deleteChunks=${Boolean(
|
|
1959
|
+
result.deleteChunks
|
|
1960
|
+
)}, partMonths=${result.partMonths}, partCount=${result.partCount}${result.runId ? `, runId=${result.runId}, completedAttempts=${result.completedAttemptCount}` : ""}`
|
|
1961
|
+
)
|
|
1962
|
+
);
|
|
1816
1963
|
};
|
|
1817
1964
|
var main = async () => {
|
|
1818
1965
|
const outDir = String(flags.outDir || "data/ai/export");
|
|
1819
|
-
await
|
|
1966
|
+
await import_promises2.default.mkdir(outDir, { recursive: true });
|
|
1820
1967
|
const strategyName = await resolveExportStrategy({
|
|
1821
1968
|
explicitStrategy: String(flags.strategy || ""),
|
|
1822
1969
|
outDir,
|
|
1823
1970
|
datasetLabel: "AI",
|
|
1824
1971
|
promptLabel: "Select AI export strategy",
|
|
1825
|
-
listStrategies:
|
|
1972
|
+
listStrategies: import_ai2.listAiChunkStrategies,
|
|
1973
|
+
includeAllOption: true
|
|
1826
1974
|
});
|
|
1827
1975
|
if (!strategyName) {
|
|
1828
1976
|
console.log(import_chalk2.default.yellow(`No AI chunk files found in ${outDir}`));
|
|
1829
|
-
|
|
1977
|
+
return;
|
|
1830
1978
|
}
|
|
1831
|
-
const
|
|
1832
|
-
|
|
1833
|
-
outDir
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1979
|
+
const strategyNames = strategyName === ALL_EXPORT_STRATEGIES ? await (0, import_ai2.listAiChunkStrategies)({ outDir }) : [strategyName];
|
|
1980
|
+
if (!strategyNames.length) {
|
|
1981
|
+
console.log(import_chalk2.default.yellow(`No AI chunk files found in ${outDir}`));
|
|
1982
|
+
return;
|
|
1983
|
+
}
|
|
1984
|
+
const progressBar = strategyNames.length > 1 ? new import_progress.default(":current/:total [:bar] :percent :strategy :status", {
|
|
1985
|
+
total: strategyNames.length,
|
|
1986
|
+
width: 30
|
|
1987
|
+
}) : null;
|
|
1988
|
+
const results = await exportAiStrategiesSequentially({
|
|
1989
|
+
outDir,
|
|
1990
|
+
strategyNames,
|
|
1991
|
+
keepChunks: Boolean(flags.keepChunks),
|
|
1992
|
+
partMonths: Number(flags.partMonths),
|
|
1993
|
+
requestedRunId: typeof flags.runId === "string" ? flags.runId.trim() : void 0,
|
|
1994
|
+
userName: String(flags.user || "root"),
|
|
1995
|
+
onProgress: progressBar ? ({ strategyName: currentStrategy, status }) => {
|
|
1996
|
+
const progressStatus = status === "started" ? "exporting" : status;
|
|
1997
|
+
if (status === "started" || status === "failed") {
|
|
1998
|
+
progressBar.tick(0, {
|
|
1999
|
+
strategy: currentStrategy,
|
|
2000
|
+
status: progressStatus
|
|
2001
|
+
});
|
|
2002
|
+
if (status === "failed") {
|
|
2003
|
+
progressBar.terminate();
|
|
2004
|
+
}
|
|
2005
|
+
return;
|
|
2006
|
+
}
|
|
2007
|
+
progressBar.tick(1, {
|
|
2008
|
+
strategy: currentStrategy,
|
|
2009
|
+
status: progressStatus
|
|
2010
|
+
});
|
|
2011
|
+
} : void 0
|
|
1838
2012
|
});
|
|
1839
|
-
if (!
|
|
2013
|
+
if (!results.length) {
|
|
1840
2014
|
console.log(
|
|
1841
2015
|
import_chalk2.default.yellow(
|
|
1842
|
-
`No chunk files found for strategy "${
|
|
2016
|
+
strategyNames.length === 1 ? `No chunk files found for strategy "${strategyNames[0]}" in ${outDir}` : `No AI chunk files were exported from ${outDir}`
|
|
1843
2017
|
)
|
|
1844
2018
|
);
|
|
1845
|
-
|
|
2019
|
+
return;
|
|
1846
2020
|
}
|
|
1847
|
-
|
|
1848
|
-
throw new Error(
|
|
1849
|
-
`No completed checkpoint attempts found for AI export run "${runScopedChunks.runId}"`
|
|
1850
|
-
);
|
|
1851
|
-
}
|
|
1852
|
-
const mergedPath = import_path.default.join(
|
|
1853
|
-
outDir,
|
|
1854
|
-
`ai-dataset-${(0, import_ai.toFileToken)(strategyName)}-merged-${Date.now()}.jsonl`
|
|
1855
|
-
);
|
|
1856
|
-
await (0, import_ai.mergeAiJsonlFiles)({
|
|
1857
|
-
filePaths: chunkFiles,
|
|
1858
|
-
outPath: mergedPath,
|
|
1859
|
-
shouldIncludeRow: runScopedChunks ? (row) => isBacktestDatasetRowForCompletedAttempt(
|
|
1860
|
-
row,
|
|
1861
|
-
runScopedChunks.completedAttemptKeys
|
|
1862
|
-
) : void 0
|
|
1863
|
-
});
|
|
1864
|
-
const partMonths = Math.max(0, Math.trunc(Number(flags.partMonths) || 0));
|
|
1865
|
-
const splitResult = partMonths > 0 ? await (0, import_ai.splitAiMergedDatasetFile)({
|
|
1866
|
-
filePath: mergedPath,
|
|
1867
|
-
monthsPerPart: partMonths
|
|
1868
|
-
}) : {
|
|
1869
|
-
partPaths: [mergedPath],
|
|
1870
|
-
partCount: 1,
|
|
1871
|
-
splitApplied: false
|
|
1872
|
-
};
|
|
1873
|
-
const shouldDeleteChunks = !Boolean(flags.keepChunks);
|
|
1874
|
-
if (shouldDeleteChunks) {
|
|
1875
|
-
for (const filePath of chunkFiles) {
|
|
1876
|
-
await import_promises.default.rm(filePath, { force: true });
|
|
1877
|
-
}
|
|
1878
|
-
}
|
|
1879
|
-
console.log(
|
|
1880
|
-
import_chalk2.default.green(
|
|
1881
|
-
splitResult.splitApplied ? `Merged AI dataset saved as ${splitResult.partCount} part files` : `Merged AI dataset saved: ${splitResult.partPaths[0]}`
|
|
1882
|
-
)
|
|
1883
|
-
);
|
|
1884
|
-
splitResult.partPaths.forEach((filePath, index) => {
|
|
1885
|
-
console.log(import_chalk2.default.gray(`part${index + 1}: ${filePath}`));
|
|
1886
|
-
});
|
|
1887
|
-
console.log(
|
|
1888
|
-
import_chalk2.default.gray(
|
|
1889
|
-
`strategy=${strategyName}, source_chunks=${chunkFiles.length}, deleteChunks=${Boolean(
|
|
1890
|
-
shouldDeleteChunks
|
|
1891
|
-
)}, partMonths=${partMonths}, partCount=${splitResult.partCount}${runScopedChunks ? `, runId=${runScopedChunks.runId}, completedAttempts=${runScopedChunks.completedAttemptKeys.size}` : ""}`
|
|
1892
|
-
)
|
|
1893
|
-
);
|
|
1894
|
-
process.exit(0);
|
|
2021
|
+
results.forEach(printExportResult);
|
|
1895
2022
|
};
|
|
1896
2023
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1897
2024
|
0 && (module.exports = {
|