@tradejs/cli 2.0.19 → 2.0.21
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 +8783 -3214
- package/dist/lib/aiExport.js +14 -1
- package/dist/lib/aiPocketSearch.js +499 -67
- package/dist/lib/aiPocketSearchCli.js +113 -0
- package/dist/lib/aiTrainCharts.js +14 -1
- package/dist/lib/aiTrainMetrics.js +4 -1
- package/dist/lib/aiTrainResearch.js +88 -54
- package/dist/lib/coreResearch.js +2738 -0
- package/dist/lib/executionCalibration.js +6 -3
- package/dist/lib/runtimeLineage.js +69 -48
- package/dist/lib/runtimeScorecard.js +153 -10
- package/dist/lib/strategyGateFingerprint.js +80 -0
- package/dist/lib/strategyRelease.js +1373 -0
- package/dist/scripts/aiExport.js +16 -3
- package/dist/scripts/aiPocketSearch.js +1069 -163
- package/dist/scripts/aiTrain.js +91 -65
- package/dist/scripts/backtest.js +10 -1
- package/dist/scripts/coreResearch.js +2830 -0
- package/dist/scripts/executionCalibration.js +6 -3
- package/dist/scripts/replay.js +94 -73
- package/dist/scripts/replayRunner.js +94 -73
- package/dist/scripts/replayRuntimeEvidence.js +27 -14
- package/dist/scripts/runtimeEvidence.js +17 -8
- package/dist/scripts/runtimeScorecard.js +883 -29
- package/dist/scripts/signals.js +121 -89
- package/dist/scripts/signalsDaemon.js +121 -89
- package/dist/scripts/strategyRelease.js +1477 -0
- package/package.json +11 -9
|
@@ -152,7 +152,8 @@ var extractRuntimeTradeRows = (runtimePayload) => {
|
|
|
152
152
|
const signal = asRecord(redisValues?.signal) ?? (signalId ? signalsById.get(signalId) ?? null : null) ?? (shapeKey ? signalsByShape.get(shapeKey) ?? null : null);
|
|
153
153
|
return {
|
|
154
154
|
trade,
|
|
155
|
-
signal
|
|
155
|
+
signal,
|
|
156
|
+
runtimeLineage: asRecord(trade.runtimeLineage) ?? null
|
|
156
157
|
};
|
|
157
158
|
}).filter((row) => row != null);
|
|
158
159
|
};
|
|
@@ -454,7 +455,8 @@ var buildSample = ({
|
|
|
454
455
|
direction: direction ?? match?.direction ?? null,
|
|
455
456
|
expectedPrice: match?.backtestPrice ?? null,
|
|
456
457
|
actualPrice: match?.runtimePrice ?? null
|
|
457
|
-
})
|
|
458
|
+
}),
|
|
459
|
+
runtimeLineage: row.runtimeLineage
|
|
458
460
|
};
|
|
459
461
|
};
|
|
460
462
|
var buildReplayOnlySample = (match) => ({
|
|
@@ -501,7 +503,8 @@ var buildReplayOnlySample = (match) => ({
|
|
|
501
503
|
direction: match.direction,
|
|
502
504
|
expectedPrice: match.backtestPrice,
|
|
503
505
|
actualPrice: match.runtimePrice
|
|
504
|
-
})
|
|
506
|
+
}),
|
|
507
|
+
runtimeLineage: null
|
|
505
508
|
});
|
|
506
509
|
var hasTelemetry = (sample) => sample.signalClosePrice != null || sample.arrivalMid != null || sample.orderSubmitTime != null || sample.fillAvgPrice != null || sample.fillTime != null || sample.fee != null;
|
|
507
510
|
var hasFullTelemetry = (sample) => sample.signalClosePrice != null && sample.arrivalMid != null && sample.orderSubmitTime != null && sample.orderAckTime != null && sample.fillAvgPrice != null && sample.fillTime != null;
|
|
@@ -38,11 +38,57 @@ __export(runtimeLineage_exports, {
|
|
|
38
38
|
});
|
|
39
39
|
module.exports = __toCommonJS(runtimeLineage_exports);
|
|
40
40
|
var import_node_child_process = require("child_process");
|
|
41
|
+
var import_node_crypto2 = require("crypto");
|
|
42
|
+
var import_promises2 = __toESM(require("fs/promises"));
|
|
43
|
+
var import_node_path2 = __toESM(require("path"));
|
|
44
|
+
var import_types = require("@tradejs/types");
|
|
45
|
+
var import_strategies = require("@tradejs/node/strategies");
|
|
46
|
+
var import_strategyReleaseEvidence = require("@tradejs/infra/strategyReleaseEvidence");
|
|
47
|
+
|
|
48
|
+
// src/lib/strategyGateFingerprint.ts
|
|
41
49
|
var import_node_crypto = require("crypto");
|
|
42
50
|
var import_promises = __toESM(require("fs/promises"));
|
|
43
51
|
var import_node_path = __toESM(require("path"));
|
|
44
|
-
var
|
|
45
|
-
|
|
52
|
+
var gateFingerprintRelativePaths = (strategyName) => [
|
|
53
|
+
`packages/strategies/src/${strategyName}/adapters/ai.ts`,
|
|
54
|
+
`packages/strategies/src/${strategyName}/guardrails.ts`,
|
|
55
|
+
`packages/strategies/src/${strategyName}/pockets.ts`,
|
|
56
|
+
`packages/strategies/src/${strategyName}/config.ts`,
|
|
57
|
+
"packages/strategies/src/shared/localAiGate.ts",
|
|
58
|
+
"packages/node/src/ai.ts",
|
|
59
|
+
"packages/core/src/utils/strategyHelpers/signalBuilders.ts"
|
|
60
|
+
];
|
|
61
|
+
var resolveStrategyGateFingerprint = async ({
|
|
62
|
+
projectRoot,
|
|
63
|
+
strategyName,
|
|
64
|
+
gitSha
|
|
65
|
+
}) => {
|
|
66
|
+
const candidates = await Promise.all(
|
|
67
|
+
gateFingerprintRelativePaths(strategyName).map(async (relativePath) => {
|
|
68
|
+
const content = await import_promises.default.readFile(import_node_path.default.join(projectRoot, relativePath)).catch(() => null);
|
|
69
|
+
return content == null ? null : { relativePath, content };
|
|
70
|
+
})
|
|
71
|
+
);
|
|
72
|
+
const sourceEntries = candidates.filter(
|
|
73
|
+
(entry) => entry != null
|
|
74
|
+
);
|
|
75
|
+
const hash = (0, import_node_crypto.createHash)("sha256");
|
|
76
|
+
hash.update(strategyName);
|
|
77
|
+
if (sourceEntries.length) {
|
|
78
|
+
for (const entry of sourceEntries) {
|
|
79
|
+
hash.update(entry.relativePath);
|
|
80
|
+
hash.update(entry.content);
|
|
81
|
+
}
|
|
82
|
+
} else {
|
|
83
|
+
hash.update(gitSha ?? "unknown-git-sha");
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
gateFingerprint: hash.digest("hex").slice(0, 16),
|
|
87
|
+
gateFingerprintFiles: sourceEntries.map((entry) => entry.relativePath)
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// src/lib/runtimeLineage.ts
|
|
46
92
|
var RUNTIME_CONTEXT_ENV_KEYS = [
|
|
47
93
|
"AI_MODE",
|
|
48
94
|
"MIN_AI_QUALITY",
|
|
@@ -105,7 +151,7 @@ var resolveRuntimeMaxLossValue = (config) => {
|
|
|
105
151
|
);
|
|
106
152
|
return Number.isFinite(maxLossValue) ? maxLossValue : null;
|
|
107
153
|
};
|
|
108
|
-
var fingerprintRuntimeValue = (value) => (0,
|
|
154
|
+
var fingerprintRuntimeValue = (value) => (0, import_node_crypto2.createHash)("sha256").update(JSON.stringify(normalizeForStableJson(value))).digest("hex").slice(0, 16);
|
|
109
155
|
var gitLineageCache = /* @__PURE__ */ new Map();
|
|
110
156
|
var gateFingerprintCache = /* @__PURE__ */ new Map();
|
|
111
157
|
var binanceBreadthFingerprintCache = /* @__PURE__ */ new Map();
|
|
@@ -156,7 +202,7 @@ var resolveGitLineage = (projectRoot) => {
|
|
|
156
202
|
};
|
|
157
203
|
var readOptionalFile = async (filePath) => {
|
|
158
204
|
try {
|
|
159
|
-
return await
|
|
205
|
+
return await import_promises2.default.readFile(filePath);
|
|
160
206
|
} catch {
|
|
161
207
|
return null;
|
|
162
208
|
}
|
|
@@ -166,7 +212,7 @@ var resolveBinanceBreadthFingerprint = async (projectRoot) => {
|
|
|
166
212
|
return binanceBreadthFingerprintCache.get(projectRoot) ?? null;
|
|
167
213
|
}
|
|
168
214
|
const content = await readOptionalFile(
|
|
169
|
-
|
|
215
|
+
import_node_path2.default.join(
|
|
170
216
|
projectRoot,
|
|
171
217
|
"packages/node/src/config/binanceBreadthUniverses.json"
|
|
172
218
|
)
|
|
@@ -188,7 +234,7 @@ var resolveSnapshotFingerprint = async (projectRoot, relativePath) => {
|
|
|
188
234
|
if (snapshotFingerprintCache.has(cacheKey)) {
|
|
189
235
|
return snapshotFingerprintCache.get(cacheKey) ?? null;
|
|
190
236
|
}
|
|
191
|
-
const content = await readOptionalFile(
|
|
237
|
+
const content = await readOptionalFile(import_node_path2.default.join(projectRoot, relativePath));
|
|
192
238
|
let result = null;
|
|
193
239
|
if (content) {
|
|
194
240
|
try {
|
|
@@ -201,55 +247,26 @@ var resolveSnapshotFingerprint = async (projectRoot, relativePath) => {
|
|
|
201
247
|
snapshotFingerprintCache.set(cacheKey, result);
|
|
202
248
|
return result;
|
|
203
249
|
};
|
|
204
|
-
var
|
|
250
|
+
var resolveRuntimeGateFingerprint = async ({
|
|
205
251
|
projectRoot,
|
|
206
252
|
strategyName,
|
|
207
253
|
gitSha
|
|
208
254
|
}) => {
|
|
209
255
|
const cacheKey = `${projectRoot}:${strategyName}:${gitSha ?? "unknown"}`;
|
|
210
256
|
const cached = gateFingerprintCache.get(cacheKey);
|
|
211
|
-
if (cached)
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
"packages/node/src/ai.ts",
|
|
220
|
-
"packages/core/src/utils/strategyHelpers/signalBuilders.ts"
|
|
221
|
-
];
|
|
222
|
-
const optionalEntries = await Promise.all(
|
|
223
|
-
relativeCandidates.map(async (relativePath) => {
|
|
224
|
-
const content = await readOptionalFile(
|
|
225
|
-
import_node_path.default.join(projectRoot, relativePath)
|
|
226
|
-
);
|
|
227
|
-
return content == null ? null : { relativePath, content };
|
|
228
|
-
})
|
|
229
|
-
);
|
|
230
|
-
const sourceEntries = [];
|
|
231
|
-
for (const entry of optionalEntries) {
|
|
232
|
-
if (entry != null) {
|
|
233
|
-
sourceEntries.push(entry);
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
const hash = (0, import_node_crypto.createHash)("sha256");
|
|
237
|
-
hash.update(strategyName);
|
|
238
|
-
if (sourceEntries.length) {
|
|
239
|
-
for (const entry of sourceEntries) {
|
|
240
|
-
hash.update(entry.relativePath);
|
|
241
|
-
hash.update(entry.content);
|
|
242
|
-
}
|
|
243
|
-
} else {
|
|
244
|
-
hash.update(gitSha ?? "unknown-git-sha");
|
|
245
|
-
}
|
|
246
|
-
const fingerprint = hash.digest("hex").slice(0, 16);
|
|
247
|
-
gateFingerprintCache.set(cacheKey, fingerprint);
|
|
248
|
-
return fingerprint;
|
|
257
|
+
if (cached) return cached;
|
|
258
|
+
const result = await resolveStrategyGateFingerprint({
|
|
259
|
+
projectRoot,
|
|
260
|
+
strategyName,
|
|
261
|
+
gitSha
|
|
262
|
+
});
|
|
263
|
+
gateFingerprintCache.set(cacheKey, result);
|
|
264
|
+
return result;
|
|
249
265
|
};
|
|
250
266
|
var buildRuntimeLineage = async ({
|
|
251
267
|
projectRoot,
|
|
252
268
|
strategyName,
|
|
269
|
+
compositionId,
|
|
253
270
|
config,
|
|
254
271
|
runContext,
|
|
255
272
|
env = process.env
|
|
@@ -275,19 +292,23 @@ var buildRuntimeLineage = async ({
|
|
|
275
292
|
};
|
|
276
293
|
return {
|
|
277
294
|
schemaVersion: 1,
|
|
295
|
+
compositionId: compositionId?.trim() || null,
|
|
278
296
|
...git,
|
|
279
|
-
gateFingerprint: await
|
|
297
|
+
gateFingerprint: (await resolveRuntimeGateFingerprint({
|
|
280
298
|
projectRoot,
|
|
281
299
|
strategyName,
|
|
282
300
|
gitSha: git.gitSha
|
|
283
|
-
}),
|
|
284
|
-
|
|
301
|
+
})).gateFingerprint,
|
|
302
|
+
// Position risk is tracked separately so changing trade size does not
|
|
303
|
+
// masquerade as a change to the core + gate decision logic.
|
|
304
|
+
configFingerprint: (0, import_strategyReleaseEvidence.strategyLogicConfigFingerprint)(config),
|
|
285
305
|
contextFingerprint: fingerprintRuntimeValue(context),
|
|
286
306
|
maxLossValue: resolveRuntimeMaxLossValue(config)
|
|
287
307
|
};
|
|
288
308
|
};
|
|
289
309
|
var runtimeLineageKey = (lineage) => [
|
|
290
310
|
lineage.schemaVersion,
|
|
311
|
+
lineage.compositionId ?? "unbound-composition",
|
|
291
312
|
lineage.gitSha ?? "unknown",
|
|
292
313
|
lineage.gitDirty == null ? "unknown" : lineage.gitDirty ? "dirty" : "clean",
|
|
293
314
|
lineage.gateFingerprint,
|
|
@@ -47,6 +47,71 @@ var extractRuntimeRows = (artifact) => {
|
|
|
47
47
|
statsBuckets: asArray(runtime.evaluationStatsBuckets).map(asRecord).filter((item) => item != null)
|
|
48
48
|
};
|
|
49
49
|
};
|
|
50
|
+
var buildRuntimeLineageSummary = (rows) => {
|
|
51
|
+
const lineageRows = [...rows.evaluations, ...rows.signals, ...rows.trades];
|
|
52
|
+
const lineages = lineageRows.map((row) => asRecord(row.runtimeLineage)).filter((lineage) => lineage != null);
|
|
53
|
+
const identities = /* @__PURE__ */ new Map();
|
|
54
|
+
for (const lineage of lineages) {
|
|
55
|
+
const identity2 = {
|
|
56
|
+
compositionId: finiteString(lineage.compositionId),
|
|
57
|
+
gitSha: finiteString(lineage.gitSha),
|
|
58
|
+
gitDirty: typeof lineage.gitDirty === "boolean" ? lineage.gitDirty : null,
|
|
59
|
+
gateFingerprint: finiteString(lineage.gateFingerprint),
|
|
60
|
+
configFingerprint: finiteString(lineage.configFingerprint),
|
|
61
|
+
contextFingerprint: finiteString(lineage.contextFingerprint),
|
|
62
|
+
maxLossValue: finiteNumber(lineage.maxLossValue)
|
|
63
|
+
};
|
|
64
|
+
identities.set(JSON.stringify(identity2), identity2);
|
|
65
|
+
}
|
|
66
|
+
const identity = identities.size === 1 ? [...identities.values()][0] : null;
|
|
67
|
+
const complete = lineageRows.length > 0 && lineages.length === lineageRows.length && identity != null && identity.compositionId != null && identity.gitSha != null && identity.gitDirty === false && identity.gateFingerprint != null && identity.configFingerprint != null && identity.contextFingerprint != null && identity.maxLossValue != null;
|
|
68
|
+
return {
|
|
69
|
+
complete,
|
|
70
|
+
conflicts: identities.size > 1,
|
|
71
|
+
rows: lineageRows.length,
|
|
72
|
+
rowsWithLineage: lineages.length,
|
|
73
|
+
compositionId: finiteString(identity?.compositionId),
|
|
74
|
+
gitSha: finiteString(identity?.gitSha),
|
|
75
|
+
gitDirty: typeof identity?.gitDirty === "boolean" ? identity.gitDirty : null,
|
|
76
|
+
gateFingerprint: finiteString(identity?.gateFingerprint),
|
|
77
|
+
configFingerprint: finiteString(identity?.configFingerprint),
|
|
78
|
+
contextFingerprint: finiteString(identity?.contextFingerprint),
|
|
79
|
+
maxLossValue: finiteNumber(identity?.maxLossValue)
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
var belongsToStrategy = (row, strategy) => strategy == null || finiteString(row.strategy) === strategy;
|
|
83
|
+
var filterArtifactByStrategy = (artifact, strategy) => {
|
|
84
|
+
if (!strategy) return artifact;
|
|
85
|
+
const root = asRecord(artifact) ?? {};
|
|
86
|
+
const runtime = runtimePayload(artifact);
|
|
87
|
+
return {
|
|
88
|
+
...root,
|
|
89
|
+
runtime: {
|
|
90
|
+
...runtime,
|
|
91
|
+
evaluations: asArray(runtime.evaluations).filter(
|
|
92
|
+
(item) => belongsToStrategy(
|
|
93
|
+
asRecord(asRecord(item)?.evaluation) ?? asRecord(item) ?? {},
|
|
94
|
+
strategy
|
|
95
|
+
)
|
|
96
|
+
),
|
|
97
|
+
signals: asArray(runtime.signals).filter(
|
|
98
|
+
(item) => belongsToStrategy(
|
|
99
|
+
asRecord(asRecord(item)?.signal) ?? asRecord(item) ?? {},
|
|
100
|
+
strategy
|
|
101
|
+
)
|
|
102
|
+
),
|
|
103
|
+
trades: asArray(runtime.trades).filter(
|
|
104
|
+
(item) => belongsToStrategy(
|
|
105
|
+
asRecord(asRecord(item)?.trade) ?? asRecord(item) ?? {},
|
|
106
|
+
strategy
|
|
107
|
+
)
|
|
108
|
+
),
|
|
109
|
+
evaluationStatsBuckets: asArray(runtime.evaluationStatsBuckets).filter(
|
|
110
|
+
(item) => belongsToStrategy(asRecord(item) ?? {}, strategy)
|
|
111
|
+
)
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
};
|
|
50
115
|
var countBy = (items, getter) => {
|
|
51
116
|
const counts = {};
|
|
52
117
|
for (const item of items) {
|
|
@@ -165,14 +230,43 @@ var getReplayComparison = (artifact) => {
|
|
|
165
230
|
const root = asRecord(artifact) ?? {};
|
|
166
231
|
return asRecord(asRecord(root.replay)?.runtimeComparison) ?? null;
|
|
167
232
|
};
|
|
233
|
+
var replayCountsForStrategy = (replayComparison, strategy) => {
|
|
234
|
+
if (strategy) {
|
|
235
|
+
const byStrategy = asRecord(replayComparison?.byStrategy);
|
|
236
|
+
const strategyCounts = asRecord(byStrategy?.[strategy]);
|
|
237
|
+
if (strategyCounts) {
|
|
238
|
+
return {
|
|
239
|
+
matched: finiteNumber(strategyCounts.matched) ?? 0,
|
|
240
|
+
backtestOnly: finiteNumber(strategyCounts.backtestOnly) ?? 0,
|
|
241
|
+
runtimeOnly: finiteNumber(strategyCounts.runtimeOnly) ?? 0
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
const counts = asRecord(replayComparison?.counts);
|
|
246
|
+
return {
|
|
247
|
+
matched: finiteNumber(counts?.matched) ?? 0,
|
|
248
|
+
backtestOnly: finiteNumber(counts?.backtestOnly) ?? 0,
|
|
249
|
+
runtimeOnly: finiteNumber(counts?.runtimeOnly) ?? 0
|
|
250
|
+
};
|
|
251
|
+
};
|
|
168
252
|
var getCalibrationSummary = (artifact) => {
|
|
169
253
|
const root = asRecord(artifact) ?? {};
|
|
170
254
|
return asRecord(asRecord(root.summary)?.all) ?? null;
|
|
171
255
|
};
|
|
256
|
+
var getProspectiveSummary = (artifact) => {
|
|
257
|
+
const root = asRecord(artifact);
|
|
258
|
+
if (!root || root.reportType !== "strategy-prospective-evidence") return null;
|
|
259
|
+
return {
|
|
260
|
+
rawCoreExpectancy: finiteNumber(root.rawCoreExpectancy),
|
|
261
|
+
aiGateExpectancy: finiteNumber(root.aiGateExpectancy),
|
|
262
|
+
regimeCoverage: finiteNumber(root.regimeCoverage)
|
|
263
|
+
};
|
|
264
|
+
};
|
|
172
265
|
var buildRuntimeScorecard = ({
|
|
173
266
|
runtimeArtifact,
|
|
174
267
|
replayEvidenceArtifact,
|
|
175
268
|
calibrationArtifact,
|
|
269
|
+
prospectiveEvidenceArtifact,
|
|
176
270
|
historyRuntimeArtifacts = [],
|
|
177
271
|
thresholds = {
|
|
178
272
|
minimumParityRatio: 0.95,
|
|
@@ -180,9 +274,19 @@ var buildRuntimeScorecard = ({
|
|
|
180
274
|
minimumClosedTrades: 20,
|
|
181
275
|
minimumExpectancy: 0
|
|
182
276
|
},
|
|
183
|
-
generatedAt = Date.now()
|
|
277
|
+
generatedAt = Date.now(),
|
|
278
|
+
strategy = null,
|
|
279
|
+
llmComparatorPolicy = "ai_approved_only"
|
|
184
280
|
}) => {
|
|
185
|
-
const
|
|
281
|
+
const scopedRuntimeArtifact = filterArtifactByStrategy(
|
|
282
|
+
runtimeArtifact,
|
|
283
|
+
strategy
|
|
284
|
+
);
|
|
285
|
+
const scopedHistoryArtifacts = historyRuntimeArtifacts.map(
|
|
286
|
+
(artifact) => filterArtifactByStrategy(artifact, strategy)
|
|
287
|
+
);
|
|
288
|
+
const rows = extractRuntimeRows(scopedRuntimeArtifact);
|
|
289
|
+
const runtimeLineage = buildRuntimeLineageSummary(rows);
|
|
186
290
|
const window = runtimeWindow(runtimeArtifact);
|
|
187
291
|
const startTime = finiteNumber(window.startTime) ?? generatedAt - 864e5;
|
|
188
292
|
const endTime = finiteNumber(window.endTime) ?? generatedAt;
|
|
@@ -197,6 +301,20 @@ var buildRuntimeScorecard = ({
|
|
|
197
301
|
})).filter(
|
|
198
302
|
({ decision }) => decision === "approved" || decision === "rejected"
|
|
199
303
|
);
|
|
304
|
+
const llmEligibleEvaluations = llmComparatorPolicy === "disabled" ? [] : llmComparatorPolicy === "ai_approved_only" ? signalEvaluations.filter(
|
|
305
|
+
(evaluation) => finiteString(asRecord(evaluation.aiAnalysis)?.gateDecision) === "approved"
|
|
306
|
+
) : signalEvaluations;
|
|
307
|
+
const gateComparisons = llmEligibleEvaluations.map((evaluation) => {
|
|
308
|
+
const analysis = asRecord(evaluation.aiAnalysis);
|
|
309
|
+
const gateDecision = finiteString(analysis?.gateDecision);
|
|
310
|
+
const llmDecision = finiteString(analysis?.llmDecision);
|
|
311
|
+
if (gateDecision !== "approved" && gateDecision !== "rejected" || llmDecision !== "approved" && llmDecision !== "rejected") {
|
|
312
|
+
return null;
|
|
313
|
+
}
|
|
314
|
+
return { gateDecision, llmDecision };
|
|
315
|
+
}).filter(
|
|
316
|
+
(comparison) => Boolean(comparison)
|
|
317
|
+
);
|
|
200
318
|
const allocatorDecisions = signalEvaluations.map((evaluation) => asRecord(evaluation.allocatorDecision)).filter((item) => item != null);
|
|
201
319
|
const riskDecisions = signalEvaluations.map((evaluation) => asRecord(evaluation.riskDecision)).filter((item) => item != null);
|
|
202
320
|
const orderAttempts = rows.signals.filter(
|
|
@@ -207,27 +325,30 @@ var buildRuntimeScorecard = ({
|
|
|
207
325
|
return trade.status === "closed" && exitTimestamp != null && exitTimestamp >= startTime && exitTimestamp < endTime;
|
|
208
326
|
});
|
|
209
327
|
const replayComparison = getReplayComparison(replayEvidenceArtifact);
|
|
210
|
-
const replayCounts =
|
|
211
|
-
const matched =
|
|
212
|
-
const backtestOnly =
|
|
213
|
-
const runtimeOnly =
|
|
328
|
+
const replayCounts = replayCountsForStrategy(replayComparison, strategy);
|
|
329
|
+
const matched = replayCounts.matched;
|
|
330
|
+
const backtestOnly = replayCounts.backtestOnly;
|
|
331
|
+
const runtimeOnly = replayCounts.runtimeOnly;
|
|
214
332
|
const comparisonTotal = matched + backtestOnly + runtimeOnly;
|
|
215
333
|
const parityRatio = comparisonTotal > 0 ? matched / comparisonTotal : null;
|
|
216
334
|
const lineage = asRecord(replayComparison?.lineage);
|
|
217
335
|
const lineageReason = finiteString(lineage?.reason);
|
|
218
|
-
const
|
|
336
|
+
const calibrationRoot = asRecord(calibrationArtifact) ?? {};
|
|
337
|
+
const calibrationSummary = asRecord(calibrationRoot.summary);
|
|
338
|
+
const calibration = strategy ? asRecord(asRecord(calibrationSummary?.byStrategy)?.[strategy]) : getCalibrationSummary(calibrationArtifact);
|
|
219
339
|
const actualSlippageBps = finiteNumber(
|
|
220
340
|
asRecord(calibration?.signalToFillAdverseBps)?.avg
|
|
221
341
|
);
|
|
222
342
|
const residualVsModelBps = finiteNumber(
|
|
223
343
|
asRecord(calibration?.residualVsCurrentModelBps)?.avg
|
|
224
344
|
);
|
|
345
|
+
const prospective = getProspectiveSummary(prospectiveEvidenceArtifact);
|
|
225
346
|
const historyTrades = dedupeTrades([
|
|
226
|
-
...
|
|
227
|
-
|
|
347
|
+
...scopedHistoryArtifacts,
|
|
348
|
+
scopedRuntimeArtifact
|
|
228
349
|
]);
|
|
229
350
|
const currentDistributions = buildDistributions(rows);
|
|
230
|
-
const previousArtifact =
|
|
351
|
+
const previousArtifact = scopedHistoryArtifacts.map((artifact) => ({ artifact, window: runtimeWindow(artifact) })).filter(({ window: candidateWindow }) => {
|
|
231
352
|
const candidateEndTime = finiteNumber(candidateWindow.endTime);
|
|
232
353
|
return candidateEndTime != null && candidateEndTime <= startTime;
|
|
233
354
|
}).sort(
|
|
@@ -286,6 +407,8 @@ var buildRuntimeScorecard = ({
|
|
|
286
407
|
schemaVersion: 1,
|
|
287
408
|
generatedAt,
|
|
288
409
|
window: { startTime, endTime },
|
|
410
|
+
strategy,
|
|
411
|
+
lineage: runtimeLineage,
|
|
289
412
|
promotionStatus,
|
|
290
413
|
thresholds,
|
|
291
414
|
funnel: {
|
|
@@ -342,6 +465,24 @@ var buildRuntimeScorecard = ({
|
|
|
342
465
|
currentClosedTrades.map((trade) => finiteNumber(trade.fundingFee))
|
|
343
466
|
)
|
|
344
467
|
},
|
|
468
|
+
gateComparison: {
|
|
469
|
+
policy: llmComparatorPolicy,
|
|
470
|
+
eligible: llmEligibleEvaluations.length,
|
|
471
|
+
compared: gateComparisons.length,
|
|
472
|
+
coverage: llmEligibleEvaluations.length ? round(gateComparisons.length / llmEligibleEvaluations.length) : null,
|
|
473
|
+
agreements: gateComparisons.filter(
|
|
474
|
+
(comparison) => comparison.gateDecision === comparison.llmDecision
|
|
475
|
+
).length,
|
|
476
|
+
disagreements: gateComparisons.filter(
|
|
477
|
+
(comparison) => comparison.gateDecision !== comparison.llmDecision
|
|
478
|
+
).length,
|
|
479
|
+
gateApprovedLlmRejected: gateComparisons.filter(
|
|
480
|
+
(comparison) => comparison.gateDecision === "approved" && comparison.llmDecision === "rejected"
|
|
481
|
+
).length,
|
|
482
|
+
gateRejectedLlmApproved: gateComparisons.filter(
|
|
483
|
+
(comparison) => comparison.gateDecision === "rejected" && comparison.llmDecision === "approved"
|
|
484
|
+
).length
|
|
485
|
+
},
|
|
345
486
|
parity: {
|
|
346
487
|
available: comparisonTotal > 0,
|
|
347
488
|
matched,
|
|
@@ -355,6 +496,7 @@ var buildRuntimeScorecard = ({
|
|
|
355
496
|
actualSignalToFillSlippageBps: actualSlippageBps,
|
|
356
497
|
residualVsCurrentModelBps: residualVsModelBps
|
|
357
498
|
},
|
|
499
|
+
prospective,
|
|
358
500
|
rolling,
|
|
359
501
|
distributions: currentDistributions,
|
|
360
502
|
distributionChanges: {
|
|
@@ -407,6 +549,7 @@ Window: ${new Date(scorecard.window.startTime).toISOString()} \u2014 ${new Date(
|
|
|
407
549
|
- Evaluations: ${scorecard.funnel.evaluations}
|
|
408
550
|
- Core candidates: ${scorecard.funnel.coreCandidates}
|
|
409
551
|
- Gate approvals/rejects: ${scorecard.funnel.gate.approved}/${scorecard.funnel.gate.rejected}
|
|
552
|
+
- AI / LLM disagreement: ${scorecard.gateComparison.disagreements}/${scorecard.gateComparison.compared}
|
|
410
553
|
- Allocator approvals/rejects: ${scorecard.funnel.allocator.available ? `${scorecard.funnel.allocator.approved}/${scorecard.funnel.allocator.rejected}` : "unavailable"}
|
|
411
554
|
- Risk approvals/rejects: ${scorecard.funnel.risk.available ? `${scorecard.funnel.risk.approved}/${scorecard.funnel.risk.rejected}` : "unavailable"}
|
|
412
555
|
- Order attempts/failures: ${scorecard.funnel.orderAttempts}/${scorecard.funnel.orderFailures}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/lib/strategyGateFingerprint.ts
|
|
31
|
+
var strategyGateFingerprint_exports = {};
|
|
32
|
+
__export(strategyGateFingerprint_exports, {
|
|
33
|
+
resolveStrategyGateFingerprint: () => resolveStrategyGateFingerprint
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(strategyGateFingerprint_exports);
|
|
36
|
+
var import_node_crypto = require("crypto");
|
|
37
|
+
var import_promises = __toESM(require("fs/promises"));
|
|
38
|
+
var import_node_path = __toESM(require("path"));
|
|
39
|
+
var gateFingerprintRelativePaths = (strategyName) => [
|
|
40
|
+
`packages/strategies/src/${strategyName}/adapters/ai.ts`,
|
|
41
|
+
`packages/strategies/src/${strategyName}/guardrails.ts`,
|
|
42
|
+
`packages/strategies/src/${strategyName}/pockets.ts`,
|
|
43
|
+
`packages/strategies/src/${strategyName}/config.ts`,
|
|
44
|
+
"packages/strategies/src/shared/localAiGate.ts",
|
|
45
|
+
"packages/node/src/ai.ts",
|
|
46
|
+
"packages/core/src/utils/strategyHelpers/signalBuilders.ts"
|
|
47
|
+
];
|
|
48
|
+
var resolveStrategyGateFingerprint = async ({
|
|
49
|
+
projectRoot,
|
|
50
|
+
strategyName,
|
|
51
|
+
gitSha
|
|
52
|
+
}) => {
|
|
53
|
+
const candidates = await Promise.all(
|
|
54
|
+
gateFingerprintRelativePaths(strategyName).map(async (relativePath) => {
|
|
55
|
+
const content = await import_promises.default.readFile(import_node_path.default.join(projectRoot, relativePath)).catch(() => null);
|
|
56
|
+
return content == null ? null : { relativePath, content };
|
|
57
|
+
})
|
|
58
|
+
);
|
|
59
|
+
const sourceEntries = candidates.filter(
|
|
60
|
+
(entry) => entry != null
|
|
61
|
+
);
|
|
62
|
+
const hash = (0, import_node_crypto.createHash)("sha256");
|
|
63
|
+
hash.update(strategyName);
|
|
64
|
+
if (sourceEntries.length) {
|
|
65
|
+
for (const entry of sourceEntries) {
|
|
66
|
+
hash.update(entry.relativePath);
|
|
67
|
+
hash.update(entry.content);
|
|
68
|
+
}
|
|
69
|
+
} else {
|
|
70
|
+
hash.update(gitSha ?? "unknown-git-sha");
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
gateFingerprint: hash.digest("hex").slice(0, 16),
|
|
74
|
+
gateFingerprintFiles: sourceEntries.map((entry) => entry.relativePath)
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
78
|
+
0 && (module.exports = {
|
|
79
|
+
resolveStrategyGateFingerprint
|
|
80
|
+
});
|