@tradejs/cli 3.1.29-beta.262 → 3.1.29-beta.263
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 +864 -1424
- package/dist/lib/runtimeEvidenceArtifacts.js +3 -416
- package/dist/lib/runtimeEvidenceCompositionSnapshots.js +42 -211
- package/dist/lib/runtimeEvidenceCompositions.js +33 -310
- package/dist/lib/runtimeEvidenceDeployment.js +3 -315
- package/dist/lib/runtimeEvidenceProducer.js +3 -77
- package/dist/lib/runtimeEvidenceSync.js +32 -299
- package/dist/lib/runtimeFeedbackArtifacts.js +3 -545
- package/dist/lib/runtimeFeedbackNotification.js +7 -195
- package/dist/lib/runtimeFeedbackReplay.js +26 -525
- package/dist/lib/runtimeFeedbackSync.js +26 -219
- package/dist/lib/runtimeScorecard.js +5 -163
- package/dist/scripts/backtest.js +6 -1
- package/dist/scripts/mcpWorker.js +273 -0
- package/dist/scripts/replay.js +14 -250
- package/dist/scripts/replayRunner.js +14 -250
- package/dist/scripts/runtimeEvidence.js +47 -597
- package/dist/scripts/runtimeEvidenceSync.js +29 -296
- package/dist/scripts/runtimeFeedbackNotify.js +10 -188
- package/dist/scripts/runtimeFeedbackReplay.js +29 -528
- package/dist/scripts/runtimeFeedbackSync.js +28 -221
- package/dist/scripts/runtimeScorecard.js +88 -503
- package/dist/scripts/signals.js +55 -224
- package/dist/scripts/signalsDaemon.js +55 -224
- package/package.json +7 -7
|
@@ -17,6 +17,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
}
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
20
21
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
22
|
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
23
|
// file that has been converted to a CommonJS file using a Babel-
|
|
@@ -34,223 +35,29 @@ __export(runtimeFeedbackSync_exports, {
|
|
|
34
35
|
});
|
|
35
36
|
module.exports = __toCommonJS(runtimeFeedbackSync_exports);
|
|
36
37
|
var import_node_child_process2 = require("child_process");
|
|
37
|
-
var
|
|
38
|
-
var
|
|
38
|
+
var import_promises2 = __toESM(require("fs/promises"));
|
|
39
|
+
var import_node_path2 = __toESM(require("path"));
|
|
39
40
|
var import_node_util2 = require("util");
|
|
40
41
|
|
|
41
42
|
// src/lib/runtimeFeedbackArtifacts.ts
|
|
42
|
-
var
|
|
43
|
-
|
|
44
|
-
var import_node_path3 = __toESM(require("path"));
|
|
45
|
-
|
|
46
|
-
// src/lib/runtimeEvidenceDeployment.ts
|
|
47
|
-
var import_runtimeStrategies = require("@tradejs/node/runtimeStrategies");
|
|
48
|
-
var isRecord = (value) => value != null && typeof value === "object" && !Array.isArray(value);
|
|
49
|
-
var isNonEmptyString = (value) => typeof value === "string" && value.trim().length > 0;
|
|
50
|
-
var isPackageVersionMap = (value) => isRecord(value) && Object.keys(value).length > 0 && Object.entries(value).every(
|
|
51
|
-
([name, version]) => name.startsWith("@tradejs/") && isNonEmptyString(version)
|
|
52
|
-
);
|
|
53
|
-
var INTERVALS = /* @__PURE__ */ new Set([
|
|
54
|
-
"1",
|
|
55
|
-
"3",
|
|
56
|
-
"5",
|
|
57
|
-
"15",
|
|
58
|
-
"30",
|
|
59
|
-
"60",
|
|
60
|
-
"120",
|
|
61
|
-
"240",
|
|
62
|
-
"360",
|
|
63
|
-
"720",
|
|
64
|
-
"D",
|
|
65
|
-
"W",
|
|
66
|
-
"M"
|
|
67
|
-
]);
|
|
68
|
-
var UNIVERSES = /* @__PURE__ */ new Set(["crypto", "tradfi"]);
|
|
69
|
-
var isRuntimeStrategySelection = (value) => value === void 0 || isRecord(value) && Object.keys(value).length === 1 && Object.keys(value).every((key) => key === "tickers") && Array.isArray(value.tickers) && value.tickers.length > 0 && value.tickers.every((ticker) => isNonEmptyString(ticker));
|
|
70
|
-
var parseRuntimeEvidenceDeploymentSnapshot = (value) => {
|
|
71
|
-
if (!isRecord(value) || value.schemaVersion !== 2 || !isNonEmptyString(value.id) || !isNonEmptyString(value.deploymentCompositionId) || !/^dc1:[a-f0-9]{16}$/.test(value.deploymentCompositionId) || !isNonEmptyString(value.label) || !isNonEmptyString(value.connectorName) || !isNonEmptyString(value.provider) || !isNonEmptyString(value.accountId) || typeof value.enabled !== "boolean" || !Array.isArray(value.strategies)) {
|
|
72
|
-
throw new Error(
|
|
73
|
-
"Runtime evidence deployment snapshot is missing or invalid"
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
const strategies = value.strategies.map((candidate) => {
|
|
77
|
-
if (!isRecord(candidate) || !isNonEmptyString(candidate.strategyName) || !isNonEmptyString(candidate.strategyRevision) || !/^sr1:[a-f0-9]{16}$/.test(candidate.strategyRevision) || typeof candidate.enabled !== "boolean" || !["active", "entries_paused"].includes(String(candidate.controlState)) || !INTERVALS.has(String(candidate.interval)) || !UNIVERSES.has(String(candidate.universe)) || !isNonEmptyString(candidate.strategyPackage) || !isNonEmptyString(candidate.strategyPackageVersion) || !isPackageVersionMap(candidate.strategyDependencyVersions) || !isNonEmptyString(candidate.runtimePackageVersion) || !isRecord(candidate.strategyConfig) || !isRuntimeStrategySelection(candidate.selection)) {
|
|
78
|
-
throw new Error(
|
|
79
|
-
"Runtime evidence deployment strategy snapshot is invalid"
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
if (String(candidate.strategyConfig.INTERVAL) !== String(candidate.interval) || String(candidate.strategyConfig.UNIVERSE) !== String(candidate.universe)) {
|
|
83
|
-
throw new Error(
|
|
84
|
-
`Runtime evidence strategy config does not match its scope: ${candidate.strategyName}`
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
if (candidate.accountId != null && (!isNonEmptyString(candidate.accountId) || candidate.accountId !== value.accountId)) {
|
|
88
|
-
throw new Error(
|
|
89
|
-
`Runtime evidence strategy account does not match deployment: ${candidate.strategyName}`
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
return candidate;
|
|
93
|
-
});
|
|
94
|
-
const identities = /* @__PURE__ */ new Set();
|
|
95
|
-
for (const strategy of strategies) {
|
|
96
|
-
if (identities.has(strategy.strategyName)) {
|
|
97
|
-
throw new Error(
|
|
98
|
-
`Duplicate runtime evidence strategy: ${strategy.strategyName}`
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
identities.add(strategy.strategyName);
|
|
102
|
-
}
|
|
103
|
-
return {
|
|
104
|
-
...value,
|
|
105
|
-
strategies
|
|
106
|
-
};
|
|
107
|
-
};
|
|
108
|
-
var activeRuntimeEvidenceStrategies = (deployment) => deployment.enabled ? deployment.strategies.filter((strategy) => strategy.enabled) : [];
|
|
43
|
+
var runtimeFeedbackArtifacts_exports = {};
|
|
44
|
+
__reExport(runtimeFeedbackArtifacts_exports, require("@tradejs/node/diagnostics"));
|
|
109
45
|
|
|
110
|
-
// src/lib/
|
|
111
|
-
var
|
|
46
|
+
// src/lib/runtimeEvidenceSync.ts
|
|
47
|
+
var import_node_child_process = require("child_process");
|
|
112
48
|
var import_promises = __toESM(require("fs/promises"));
|
|
113
49
|
var import_node_path = __toESM(require("path"));
|
|
50
|
+
var import_node_util = require("util");
|
|
114
51
|
|
|
115
|
-
// src/lib/
|
|
116
|
-
var
|
|
117
|
-
|
|
118
|
-
var import_node_path2 = __toESM(require("path"));
|
|
119
|
-
var isRecord2 = (value) => value != null && typeof value === "object" && !Array.isArray(value);
|
|
120
|
-
var parseRuntimeEvidenceProducer = (value) => {
|
|
121
|
-
const producer = isRecord2(value) ? value : null;
|
|
122
|
-
const runtimePackageManifest = isRecord2(producer?.runtimePackageManifest) ? producer.runtimePackageManifest : null;
|
|
123
|
-
if (producer?.schemaVersion !== 1 || typeof producer.projectSha !== "string" || !/^[a-f0-9]{40}$/.test(producer.projectSha) || typeof producer.imageDigest !== "string" || !/^sha256:[a-f0-9]{64}$/.test(producer.imageDigest) || runtimePackageManifest?.file !== "runtime-package-manifest.json" || typeof runtimePackageManifest.sha256 !== "string" || !/^[a-f0-9]{64}$/.test(runtimePackageManifest.sha256)) {
|
|
124
|
-
throw new Error("Runtime evidence producer image identity is invalid");
|
|
125
|
-
}
|
|
126
|
-
return producer;
|
|
127
|
-
};
|
|
52
|
+
// src/lib/runtimeEvidenceArtifacts.ts
|
|
53
|
+
var runtimeEvidenceArtifacts_exports = {};
|
|
54
|
+
__reExport(runtimeEvidenceArtifacts_exports, require("@tradejs/node/diagnostics"));
|
|
128
55
|
|
|
129
|
-
// src/lib/
|
|
130
|
-
var
|
|
131
|
-
|
|
132
|
-
var RUNTIME_FEEDBACK_LOG_FILE = "replay.log";
|
|
133
|
-
var RUNTIME_FEEDBACK_COMPLETE_FILE = ".complete";
|
|
134
|
-
var isRecord3 = (value) => value != null && typeof value === "object" && !Array.isArray(value);
|
|
135
|
-
var sha256 = (value) => (0, import_node_crypto3.createHash)("sha256").update(value).digest("hex");
|
|
136
|
-
var parsePayload = (value, expectedFile) => {
|
|
137
|
-
const payload = isRecord3(value) ? value : null;
|
|
138
|
-
if (payload?.file !== expectedFile || typeof payload.sha256 !== "string" || !/^[a-f0-9]{64}$/.test(payload.sha256) || typeof payload.bytes !== "number" || !Number.isFinite(payload.bytes) || payload.bytes < 0) {
|
|
139
|
-
throw new Error(`Invalid runtime feedback payload: ${expectedFile}`);
|
|
140
|
-
}
|
|
141
|
-
return payload;
|
|
142
|
-
};
|
|
143
|
-
var parseManifest = (value) => {
|
|
144
|
-
const manifest = isRecord3(value) ? value : null;
|
|
145
|
-
const window = isRecord3(manifest?.window) ? manifest.window : null;
|
|
146
|
-
const runtimeEvidence = isRecord3(manifest?.runtimeEvidence) ? manifest.runtimeEvidence : null;
|
|
147
|
-
const safety = isRecord3(manifest?.safety) ? manifest.safety : null;
|
|
148
|
-
const payloads = isRecord3(manifest?.payloads) ? manifest.payloads : null;
|
|
149
|
-
if (manifest?.schemaVersion !== 1 || manifest.reportType !== "runtime-feedback-replay" || typeof manifest.artifactId !== "string" || !manifest.artifactId.trim() || typeof manifest.runId !== "string" || !manifest.runId.trim() || typeof manifest.deploymentId !== "string" || !manifest.deploymentId.trim() || typeof manifest.deploymentCompositionId !== "string" || !/^dc1:[a-f0-9]{16}$/.test(manifest.deploymentCompositionId) || typeof manifest.userName !== "string" || !manifest.userName.trim() || typeof manifest.createdAt !== "number" || typeof window?.startTime !== "number" || typeof window.endTime !== "number" || typeof runtimeEvidence?.artifactId !== "string" || typeof runtimeEvidence.payloadSha256 !== "string" || !/^[a-f0-9]{64}$/.test(runtimeEvidence.payloadSha256) || !Array.isArray(manifest.activeStrategies) || manifest.activeStrategies.length === 0 || !manifest.activeStrategies.every(
|
|
150
|
-
(strategy) => typeof strategy === "string" && strategy.trim()
|
|
151
|
-
) || typeof manifest.cycleCount !== "number" || !Number.isFinite(manifest.cycleCount) || manifest.cycleCount <= 0 || safety?.cacheOnly !== true || safety.externalOrderPlacement !== false || safety.redis !== "isolated" || safety.timescale !== "read_only") {
|
|
152
|
-
throw new Error("Invalid runtime feedback replay manifest");
|
|
153
|
-
}
|
|
154
|
-
const replayEvidence = parsePayload(
|
|
155
|
-
payloads?.replayEvidence,
|
|
156
|
-
RUNTIME_FEEDBACK_REPLAY_FILE
|
|
157
|
-
);
|
|
158
|
-
const log = parsePayload(payloads?.log, RUNTIME_FEEDBACK_LOG_FILE);
|
|
159
|
-
return {
|
|
160
|
-
...manifest,
|
|
161
|
-
producer: parseRuntimeEvidenceProducer(manifest.producer),
|
|
162
|
-
payloads: {
|
|
163
|
-
replayEvidence: {
|
|
164
|
-
...replayEvidence,
|
|
165
|
-
file: RUNTIME_FEEDBACK_REPLAY_FILE
|
|
166
|
-
},
|
|
167
|
-
log: { ...log, file: RUNTIME_FEEDBACK_LOG_FILE }
|
|
168
|
-
}
|
|
169
|
-
};
|
|
170
|
-
};
|
|
171
|
-
var verifyRuntimeFeedbackReplayBundle = async (bundleDir) => {
|
|
172
|
-
const manifestPath = import_node_path3.default.join(bundleDir, RUNTIME_FEEDBACK_MANIFEST_FILE);
|
|
173
|
-
const replayEvidencePath = import_node_path3.default.join(bundleDir, RUNTIME_FEEDBACK_REPLAY_FILE);
|
|
174
|
-
const logPath = import_node_path3.default.join(bundleDir, RUNTIME_FEEDBACK_LOG_FILE);
|
|
175
|
-
const completePath = import_node_path3.default.join(bundleDir, RUNTIME_FEEDBACK_COMPLETE_FILE);
|
|
176
|
-
const [manifestText, replayPayload, logPayload, completeText] = await Promise.all([
|
|
177
|
-
import_promises3.default.readFile(manifestPath, "utf8"),
|
|
178
|
-
import_promises3.default.readFile(replayEvidencePath),
|
|
179
|
-
import_promises3.default.readFile(logPath),
|
|
180
|
-
import_promises3.default.readFile(completePath, "utf8")
|
|
181
|
-
]);
|
|
182
|
-
const manifest = parseManifest(JSON.parse(manifestText));
|
|
183
|
-
if (completeText.trim() !== manifest.artifactId) {
|
|
184
|
-
throw new Error(`Invalid runtime feedback completion marker: ${bundleDir}`);
|
|
185
|
-
}
|
|
186
|
-
for (const [payload, descriptor] of [
|
|
187
|
-
[replayPayload, manifest.payloads.replayEvidence],
|
|
188
|
-
[logPayload, manifest.payloads.log]
|
|
189
|
-
]) {
|
|
190
|
-
if (payload.byteLength !== descriptor.bytes) {
|
|
191
|
-
throw new Error(
|
|
192
|
-
`Runtime feedback payload size mismatch: ${descriptor.file}`
|
|
193
|
-
);
|
|
194
|
-
}
|
|
195
|
-
if (sha256(payload) !== descriptor.sha256) {
|
|
196
|
-
throw new Error(
|
|
197
|
-
`Runtime feedback payload checksum mismatch: ${descriptor.file}`
|
|
198
|
-
);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
const replayEvidence = JSON.parse(replayPayload.toString("utf8"));
|
|
202
|
-
if (replayEvidence.reportType !== "replay-runtime-evidence") {
|
|
203
|
-
throw new Error("Invalid runtime feedback replay evidence payload");
|
|
204
|
-
}
|
|
205
|
-
const replayWindow = isRecord3(replayEvidence.window) ? replayEvidence.window : null;
|
|
206
|
-
const replay = isRecord3(replayEvidence.replay) ? replayEvidence.replay : null;
|
|
207
|
-
const replayDeployment = parseRuntimeEvidenceDeploymentSnapshot(
|
|
208
|
-
replayEvidence.deployment
|
|
209
|
-
);
|
|
210
|
-
const replayStrategies = activeRuntimeEvidenceStrategies(replayDeployment).map(({ strategyName }) => strategyName).sort();
|
|
211
|
-
if (replayEvidence.userName !== manifest.userName || replayWindow?.startTime !== manifest.window.startTime || replayWindow.endTime !== manifest.window.endTime || replayDeployment.id !== manifest.deploymentId || replayDeployment.deploymentCompositionId !== manifest.deploymentCompositionId || Number(replay?.cycleCount) !== manifest.cycleCount || JSON.stringify(replayStrategies) !== JSON.stringify([...manifest.activeStrategies].sort())) {
|
|
212
|
-
throw new Error("Runtime feedback replay payload does not match manifest");
|
|
213
|
-
}
|
|
214
|
-
return {
|
|
215
|
-
bundleDir,
|
|
216
|
-
manifestPath,
|
|
217
|
-
replayEvidencePath,
|
|
218
|
-
logPath,
|
|
219
|
-
manifest,
|
|
220
|
-
replayEvidence
|
|
221
|
-
};
|
|
222
|
-
};
|
|
223
|
-
var discoverRuntimeFeedbackReplayBundles = async (rootDir) => {
|
|
224
|
-
const bundles = [];
|
|
225
|
-
const visit = async (directory, depth) => {
|
|
226
|
-
if (depth > 10) return;
|
|
227
|
-
let entries;
|
|
228
|
-
try {
|
|
229
|
-
entries = await import_promises3.default.readdir(directory, { withFileTypes: true });
|
|
230
|
-
} catch (error) {
|
|
231
|
-
if (error.code === "ENOENT") return;
|
|
232
|
-
throw error;
|
|
233
|
-
}
|
|
234
|
-
const names = new Set(entries.map((entry) => entry.name));
|
|
235
|
-
if (names.has(RUNTIME_FEEDBACK_MANIFEST_FILE) && names.has(RUNTIME_FEEDBACK_REPLAY_FILE) && names.has(RUNTIME_FEEDBACK_LOG_FILE) && names.has(RUNTIME_FEEDBACK_COMPLETE_FILE)) {
|
|
236
|
-
bundles.push(directory);
|
|
237
|
-
return;
|
|
238
|
-
}
|
|
239
|
-
await Promise.all(
|
|
240
|
-
entries.filter(
|
|
241
|
-
(entry) => entry.isDirectory() && !entry.name.startsWith(".") && !entry.name.includes(".tmp-")
|
|
242
|
-
).map((entry) => visit(import_node_path3.default.join(directory, entry.name), depth + 1))
|
|
243
|
-
);
|
|
244
|
-
};
|
|
245
|
-
await visit(rootDir, 0);
|
|
246
|
-
return bundles.sort();
|
|
247
|
-
};
|
|
56
|
+
// src/lib/runtimeEvidenceDeployment.ts
|
|
57
|
+
var runtimeEvidenceDeployment_exports = {};
|
|
58
|
+
__reExport(runtimeEvidenceDeployment_exports, require("@tradejs/node/diagnostics"));
|
|
248
59
|
|
|
249
60
|
// src/lib/runtimeEvidenceSync.ts
|
|
250
|
-
var import_node_child_process = require("child_process");
|
|
251
|
-
var import_promises4 = __toESM(require("fs/promises"));
|
|
252
|
-
var import_node_path4 = __toESM(require("path"));
|
|
253
|
-
var import_node_util = require("util");
|
|
254
61
|
var execFileAsync = (0, import_node_util.promisify)(import_node_child_process.execFile);
|
|
255
62
|
var withTrailingSlash = (value) => value.endsWith("/") ? value : `${value}/`;
|
|
256
63
|
var buildRuntimeEvidenceRsyncArgs = ({
|
|
@@ -296,46 +103,46 @@ var syncRuntimeFeedbackReplayBundles = async ({
|
|
|
296
103
|
}
|
|
297
104
|
}) => {
|
|
298
105
|
const safeDeploymentId = safeSegment(deploymentId, "production");
|
|
299
|
-
const inboxRoot =
|
|
300
|
-
const artifactsRoot =
|
|
106
|
+
const inboxRoot = import_node_path2.default.join(feedbackRoot, "inbox", safeDeploymentId);
|
|
107
|
+
const artifactsRoot = import_node_path2.default.join(feedbackRoot, "artifacts", safeDeploymentId);
|
|
301
108
|
await Promise.all([
|
|
302
|
-
|
|
303
|
-
|
|
109
|
+
import_promises2.default.mkdir(inboxRoot, { recursive: true }),
|
|
110
|
+
import_promises2.default.mkdir(artifactsRoot, { recursive: true })
|
|
304
111
|
]);
|
|
305
112
|
const rsyncArgs = buildRuntimeEvidenceRsyncArgs({
|
|
306
113
|
source,
|
|
307
114
|
destination: inboxRoot
|
|
308
115
|
});
|
|
309
116
|
const transfer = await runRsync(rsyncArgs);
|
|
310
|
-
const discovered = await discoverRuntimeFeedbackReplayBundles(inboxRoot);
|
|
117
|
+
const discovered = await (0, runtimeFeedbackArtifacts_exports.discoverRuntimeFeedbackReplayBundles)(inboxRoot);
|
|
311
118
|
const received = [];
|
|
312
119
|
for (const bundleDir of discovered) {
|
|
313
|
-
const verified = await verifyRuntimeFeedbackReplayBundle(bundleDir);
|
|
120
|
+
const verified = await (0, runtimeFeedbackArtifacts_exports.verifyRuntimeFeedbackReplayBundle)(bundleDir);
|
|
314
121
|
if (verified.manifest.deploymentId !== safeDeploymentId) {
|
|
315
122
|
throw new Error(
|
|
316
123
|
`Runtime feedback deployment mismatch: expected ${safeDeploymentId}, received ${verified.manifest.deploymentId}`
|
|
317
124
|
);
|
|
318
125
|
}
|
|
319
|
-
const destinationDir =
|
|
126
|
+
const destinationDir = import_node_path2.default.join(
|
|
320
127
|
artifactsRoot,
|
|
321
128
|
...dateParts(verified.manifest.window.endTime),
|
|
322
129
|
safeSegment(verified.manifest.runtimeEvidence.artifactId, "artifact"),
|
|
323
130
|
safeSegment(verified.manifest.runId, "run")
|
|
324
131
|
);
|
|
325
|
-
await
|
|
132
|
+
await import_promises2.default.mkdir(import_node_path2.default.dirname(destinationDir), { recursive: true });
|
|
326
133
|
try {
|
|
327
|
-
await
|
|
134
|
+
await import_promises2.default.rename(bundleDir, destinationDir);
|
|
328
135
|
} catch (error) {
|
|
329
136
|
if (!isExistingDestinationError(error)) throw error;
|
|
330
|
-
const existing = await verifyRuntimeFeedbackReplayBundle(destinationDir);
|
|
137
|
+
const existing = await (0, runtimeFeedbackArtifacts_exports.verifyRuntimeFeedbackReplayBundle)(destinationDir);
|
|
331
138
|
if (existing.manifest.payloads.replayEvidence.sha256 !== verified.manifest.payloads.replayEvidence.sha256) {
|
|
332
139
|
throw new Error(
|
|
333
140
|
`Conflicting runtime feedback replay ${verified.manifest.artifactId}`
|
|
334
141
|
);
|
|
335
142
|
}
|
|
336
|
-
await
|
|
143
|
+
await import_promises2.default.rm(bundleDir, { recursive: true, force: true });
|
|
337
144
|
}
|
|
338
|
-
received.push(await verifyRuntimeFeedbackReplayBundle(destinationDir));
|
|
145
|
+
received.push(await (0, runtimeFeedbackArtifacts_exports.verifyRuntimeFeedbackReplayBundle)(destinationDir));
|
|
339
146
|
}
|
|
340
147
|
return {
|
|
341
148
|
rsyncArgs,
|
|
@@ -15,6 +15,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
15
|
}
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
20
|
|
|
20
21
|
// src/lib/runtimeScorecard.ts
|
|
@@ -49,167 +50,8 @@ var runtimeLineageKey = (lineage) => [
|
|
|
49
50
|
].join(":");
|
|
50
51
|
|
|
51
52
|
// src/lib/runtimeEvidenceDeployment.ts
|
|
52
|
-
var
|
|
53
|
-
|
|
54
|
-
var isNonEmptyString = (value) => typeof value === "string" && value.trim().length > 0;
|
|
55
|
-
var isPackageVersionMap = (value) => isRecord(value) && Object.keys(value).length > 0 && Object.entries(value).every(
|
|
56
|
-
([name, version]) => name.startsWith("@tradejs/") && isNonEmptyString(version)
|
|
57
|
-
);
|
|
58
|
-
var INTERVALS = /* @__PURE__ */ new Set([
|
|
59
|
-
"1",
|
|
60
|
-
"3",
|
|
61
|
-
"5",
|
|
62
|
-
"15",
|
|
63
|
-
"30",
|
|
64
|
-
"60",
|
|
65
|
-
"120",
|
|
66
|
-
"240",
|
|
67
|
-
"360",
|
|
68
|
-
"720",
|
|
69
|
-
"D",
|
|
70
|
-
"W",
|
|
71
|
-
"M"
|
|
72
|
-
]);
|
|
73
|
-
var UNIVERSES = /* @__PURE__ */ new Set(["crypto", "tradfi"]);
|
|
74
|
-
var isRuntimeStrategySelection = (value) => value === void 0 || isRecord(value) && Object.keys(value).length === 1 && Object.keys(value).every((key) => key === "tickers") && Array.isArray(value.tickers) && value.tickers.length > 0 && value.tickers.every((ticker) => isNonEmptyString(ticker));
|
|
75
|
-
var samePackageVersions = (left, right) => {
|
|
76
|
-
if (!left || !right) return false;
|
|
77
|
-
const leftEntries = Object.entries(left).sort(
|
|
78
|
-
([a], [b]) => a.localeCompare(b)
|
|
79
|
-
);
|
|
80
|
-
const rightEntries = Object.entries(right).sort(
|
|
81
|
-
([a], [b]) => a.localeCompare(b)
|
|
82
|
-
);
|
|
83
|
-
return JSON.stringify(leftEntries) === JSON.stringify(rightEntries);
|
|
84
|
-
};
|
|
85
|
-
var runtimeLineageMatchesStrategySnapshot = ({
|
|
86
|
-
lineage,
|
|
87
|
-
deployment,
|
|
88
|
-
strategy
|
|
89
|
-
}) => lineage?.schemaVersion === 3 && lineage.strategyRevision === strategy.strategyRevision && lineage.deploymentCompositionId === deployment.deploymentCompositionId && lineage.strategyPackageVersion === strategy.strategyPackageVersion && lineage.runtimePackageVersion === strategy.runtimePackageVersion && samePackageVersions(
|
|
90
|
-
lineage.strategyDependencyVersions,
|
|
91
|
-
strategy.strategyDependencyVersions
|
|
92
|
-
);
|
|
93
|
-
var parseRuntimeEvidenceDeploymentSnapshot = (value) => {
|
|
94
|
-
if (!isRecord(value) || value.schemaVersion !== 2 || !isNonEmptyString(value.id) || !isNonEmptyString(value.deploymentCompositionId) || !/^dc1:[a-f0-9]{16}$/.test(value.deploymentCompositionId) || !isNonEmptyString(value.label) || !isNonEmptyString(value.connectorName) || !isNonEmptyString(value.provider) || !isNonEmptyString(value.accountId) || typeof value.enabled !== "boolean" || !Array.isArray(value.strategies)) {
|
|
95
|
-
throw new Error(
|
|
96
|
-
"Runtime evidence deployment snapshot is missing or invalid"
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
const strategies = value.strategies.map((candidate) => {
|
|
100
|
-
if (!isRecord(candidate) || !isNonEmptyString(candidate.strategyName) || !isNonEmptyString(candidate.strategyRevision) || !/^sr1:[a-f0-9]{16}$/.test(candidate.strategyRevision) || typeof candidate.enabled !== "boolean" || !["active", "entries_paused"].includes(String(candidate.controlState)) || !INTERVALS.has(String(candidate.interval)) || !UNIVERSES.has(String(candidate.universe)) || !isNonEmptyString(candidate.strategyPackage) || !isNonEmptyString(candidate.strategyPackageVersion) || !isPackageVersionMap(candidate.strategyDependencyVersions) || !isNonEmptyString(candidate.runtimePackageVersion) || !isRecord(candidate.strategyConfig) || !isRuntimeStrategySelection(candidate.selection)) {
|
|
101
|
-
throw new Error(
|
|
102
|
-
"Runtime evidence deployment strategy snapshot is invalid"
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
if (String(candidate.strategyConfig.INTERVAL) !== String(candidate.interval) || String(candidate.strategyConfig.UNIVERSE) !== String(candidate.universe)) {
|
|
106
|
-
throw new Error(
|
|
107
|
-
`Runtime evidence strategy config does not match its scope: ${candidate.strategyName}`
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
if (candidate.accountId != null && (!isNonEmptyString(candidate.accountId) || candidate.accountId !== value.accountId)) {
|
|
111
|
-
throw new Error(
|
|
112
|
-
`Runtime evidence strategy account does not match deployment: ${candidate.strategyName}`
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
return candidate;
|
|
116
|
-
});
|
|
117
|
-
const identities = /* @__PURE__ */ new Set();
|
|
118
|
-
for (const strategy of strategies) {
|
|
119
|
-
if (identities.has(strategy.strategyName)) {
|
|
120
|
-
throw new Error(
|
|
121
|
-
`Duplicate runtime evidence strategy: ${strategy.strategyName}`
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
identities.add(strategy.strategyName);
|
|
125
|
-
}
|
|
126
|
-
return {
|
|
127
|
-
...value,
|
|
128
|
-
strategies
|
|
129
|
-
};
|
|
130
|
-
};
|
|
131
|
-
var activeRuntimeEvidenceStrategies = (deployment) => deployment.enabled ? deployment.strategies.filter((strategy) => strategy.enabled) : [];
|
|
132
|
-
var unwrapRuntimeEvidenceRows = (value, field) => (Array.isArray(value) ? value : []).map((candidate) => {
|
|
133
|
-
const record = isRecord(candidate) ? candidate : null;
|
|
134
|
-
const nested = record && isRecord(record[field]) ? record[field] : null;
|
|
135
|
-
return nested ?? record;
|
|
136
|
-
}).filter((record) => record != null);
|
|
137
|
-
var assertCurrentRuntimeEvidenceArtifact = (artifact) => {
|
|
138
|
-
if (!isRecord(artifact) || artifact.reportType !== "runtime-evidence") {
|
|
139
|
-
throw new Error("Invalid runtime evidence artifact");
|
|
140
|
-
}
|
|
141
|
-
const deployment = parseRuntimeEvidenceDeploymentSnapshot(
|
|
142
|
-
artifact.deployment
|
|
143
|
-
);
|
|
144
|
-
const activeStrategies = activeRuntimeEvidenceStrategies(deployment);
|
|
145
|
-
if (activeStrategies.length === 0) {
|
|
146
|
-
throw new Error("Runtime evidence deployment has no enabled strategies");
|
|
147
|
-
}
|
|
148
|
-
const runtime = isRecord(artifact.runtime) ? artifact.runtime : null;
|
|
149
|
-
if (!runtime) {
|
|
150
|
-
throw new Error("Runtime evidence payload is missing");
|
|
151
|
-
}
|
|
152
|
-
if ("strategyConfigs" in runtime) {
|
|
153
|
-
throw new Error(
|
|
154
|
-
"Runtime evidence payload contains removed strategyConfigs data"
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
if ("evaluationStatsBuckets" in runtime) {
|
|
158
|
-
throw new Error(
|
|
159
|
-
"Runtime evidence payload contains removed lineage-less evaluationStatsBuckets data"
|
|
160
|
-
);
|
|
161
|
-
}
|
|
162
|
-
const rowFields = [
|
|
163
|
-
"trades",
|
|
164
|
-
"signals",
|
|
165
|
-
"evaluations",
|
|
166
|
-
"lineageScopes"
|
|
167
|
-
];
|
|
168
|
-
for (const field of rowFields) {
|
|
169
|
-
if (!Array.isArray(runtime[field])) {
|
|
170
|
-
throw new Error(`Runtime evidence payload ${field} must be an array`);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
const snapshots = new Map(
|
|
174
|
-
activeStrategies.map((strategy) => [strategy.strategyName, strategy])
|
|
175
|
-
);
|
|
176
|
-
const assertRows = (label, rows, lineageField) => {
|
|
177
|
-
for (const row of rows) {
|
|
178
|
-
const strategyName = String(row.strategy ?? "").trim();
|
|
179
|
-
const strategy = snapshots.get(strategyName);
|
|
180
|
-
if (!strategy || row.deploymentId !== deployment.id || row.accountId !== deployment.accountId || !runtimeLineageMatchesStrategySnapshot({
|
|
181
|
-
lineage: isRecord(row[lineageField]) ? row[lineageField] : void 0,
|
|
182
|
-
deployment,
|
|
183
|
-
strategy
|
|
184
|
-
})) {
|
|
185
|
-
throw new Error(
|
|
186
|
-
`Runtime evidence ${label} row is outside the current embedded deployment lineage`
|
|
187
|
-
);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
};
|
|
191
|
-
assertRows(
|
|
192
|
-
"trade",
|
|
193
|
-
unwrapRuntimeEvidenceRows(runtime.trades, "trade"),
|
|
194
|
-
"runtimeLineage"
|
|
195
|
-
);
|
|
196
|
-
assertRows(
|
|
197
|
-
"signal",
|
|
198
|
-
unwrapRuntimeEvidenceRows(runtime.signals, "signal"),
|
|
199
|
-
"runtimeLineage"
|
|
200
|
-
);
|
|
201
|
-
assertRows(
|
|
202
|
-
"evaluation",
|
|
203
|
-
unwrapRuntimeEvidenceRows(runtime.evaluations, "evaluation"),
|
|
204
|
-
"runtimeLineage"
|
|
205
|
-
);
|
|
206
|
-
assertRows(
|
|
207
|
-
"lineage scope",
|
|
208
|
-
unwrapRuntimeEvidenceRows(runtime.lineageScopes, "lineageScope"),
|
|
209
|
-
"lineage"
|
|
210
|
-
);
|
|
211
|
-
return deployment;
|
|
212
|
-
};
|
|
53
|
+
var runtimeEvidenceDeployment_exports = {};
|
|
54
|
+
__reExport(runtimeEvidenceDeployment_exports, require("@tradejs/node/diagnostics"));
|
|
213
55
|
|
|
214
56
|
// src/lib/runtimeScorecard.ts
|
|
215
57
|
var asRecord = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
@@ -590,9 +432,9 @@ var buildRuntimeScorecard = ({
|
|
|
590
432
|
strategy = null,
|
|
591
433
|
llmComparatorPolicy = "ai_approved_only"
|
|
592
434
|
}) => {
|
|
593
|
-
assertCurrentRuntimeEvidenceArtifact(runtimeArtifact);
|
|
435
|
+
(0, runtimeEvidenceDeployment_exports.assertCurrentRuntimeEvidenceArtifact)(runtimeArtifact);
|
|
594
436
|
for (const artifact of historyRuntimeArtifacts) {
|
|
595
|
-
assertCurrentRuntimeEvidenceArtifact(artifact);
|
|
437
|
+
(0, runtimeEvidenceDeployment_exports.assertCurrentRuntimeEvidenceArtifact)(artifact);
|
|
596
438
|
}
|
|
597
439
|
const scopedRuntimeArtifact = filterArtifactByStrategy(
|
|
598
440
|
runtimeArtifact,
|
package/dist/scripts/backtest.js
CHANGED
|
@@ -4329,6 +4329,11 @@ import_args.default.option(
|
|
|
4329
4329
|
"Skip per-test artifact persistence and keep only in-memory summary/AI-ML dataset output",
|
|
4330
4330
|
false
|
|
4331
4331
|
);
|
|
4332
|
+
import_args.default.option(
|
|
4333
|
+
["Y", "persistResults"],
|
|
4334
|
+
"Persist lightweight result summaries even in fast mode",
|
|
4335
|
+
false
|
|
4336
|
+
);
|
|
4332
4337
|
import_args.default.option(
|
|
4333
4338
|
"researchTrace",
|
|
4334
4339
|
"Write compact setup/entry/exit/skip research trace JSONL",
|
|
@@ -5639,7 +5644,7 @@ var finishBacktest = async (testSuite) => {
|
|
|
5639
5644
|
}
|
|
5640
5645
|
console.log(import_chalk10.default.gray(`full report: ${markdownReportPath}`));
|
|
5641
5646
|
console.log("");
|
|
5642
|
-
if (!isFastMode) {
|
|
5647
|
+
if (!isFastMode || flags.persistResults) {
|
|
5643
5648
|
await (0, import_redis5.setData)(
|
|
5644
5649
|
import_redis5.redisKeys.backtestResults(userName, flags.config, timestamp),
|
|
5645
5650
|
{
|