@tradejs/cli 2.0.19 → 2.0.20

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.
@@ -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,56 @@ __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
+
47
+ // src/lib/strategyGateFingerprint.ts
41
48
  var import_node_crypto = require("crypto");
42
49
  var import_promises = __toESM(require("fs/promises"));
43
50
  var import_node_path = __toESM(require("path"));
44
- var import_types = require("@tradejs/types");
45
- var import_strategies = require("@tradejs/node/strategies");
51
+ var gateFingerprintRelativePaths = (strategyName) => [
52
+ `packages/strategies/src/${strategyName}/adapters/ai.ts`,
53
+ `packages/strategies/src/${strategyName}/guardrails.ts`,
54
+ `packages/strategies/src/${strategyName}/pockets.ts`,
55
+ `packages/strategies/src/${strategyName}/config.ts`,
56
+ "packages/strategies/src/shared/localAiGate.ts",
57
+ "packages/node/src/ai.ts",
58
+ "packages/core/src/utils/strategyHelpers/signalBuilders.ts"
59
+ ];
60
+ var resolveStrategyGateFingerprint = async ({
61
+ projectRoot,
62
+ strategyName,
63
+ gitSha
64
+ }) => {
65
+ const candidates = await Promise.all(
66
+ gateFingerprintRelativePaths(strategyName).map(async (relativePath) => {
67
+ const content = await import_promises.default.readFile(import_node_path.default.join(projectRoot, relativePath)).catch(() => null);
68
+ return content == null ? null : { relativePath, content };
69
+ })
70
+ );
71
+ const sourceEntries = candidates.filter(
72
+ (entry) => entry != null
73
+ );
74
+ const hash = (0, import_node_crypto.createHash)("sha256");
75
+ hash.update(strategyName);
76
+ if (sourceEntries.length) {
77
+ for (const entry of sourceEntries) {
78
+ hash.update(entry.relativePath);
79
+ hash.update(entry.content);
80
+ }
81
+ } else {
82
+ hash.update(gitSha ?? "unknown-git-sha");
83
+ }
84
+ return {
85
+ gateFingerprint: hash.digest("hex").slice(0, 16),
86
+ gateFingerprintFiles: sourceEntries.map((entry) => entry.relativePath)
87
+ };
88
+ };
89
+
90
+ // src/lib/runtimeLineage.ts
46
91
  var RUNTIME_CONTEXT_ENV_KEYS = [
47
92
  "AI_MODE",
48
93
  "MIN_AI_QUALITY",
@@ -92,6 +137,17 @@ var normalizeForStableJson = (value) => {
92
137
  }
93
138
  return value;
94
139
  };
140
+ var normalizeRuntimeLogicConfig = (value) => {
141
+ if (Array.isArray(value)) {
142
+ return value.map(normalizeRuntimeLogicConfig);
143
+ }
144
+ if (value && typeof value === "object") {
145
+ return Object.fromEntries(
146
+ Object.entries(value).filter(([key]) => key !== "MAX_LOSS_VALUE").sort(([left], [right]) => left.localeCompare(right)).map(([key, entry]) => [key, normalizeRuntimeLogicConfig(entry)])
147
+ );
148
+ }
149
+ return value;
150
+ };
95
151
  var resolveRuntimeMaxLossValue = (config) => {
96
152
  if (!config || typeof config !== "object" || Array.isArray(config)) {
97
153
  return null;
@@ -105,7 +161,7 @@ var resolveRuntimeMaxLossValue = (config) => {
105
161
  );
106
162
  return Number.isFinite(maxLossValue) ? maxLossValue : null;
107
163
  };
108
- var fingerprintRuntimeValue = (value) => (0, import_node_crypto.createHash)("sha256").update(JSON.stringify(normalizeForStableJson(value))).digest("hex").slice(0, 16);
164
+ var fingerprintRuntimeValue = (value) => (0, import_node_crypto2.createHash)("sha256").update(JSON.stringify(normalizeForStableJson(value))).digest("hex").slice(0, 16);
109
165
  var gitLineageCache = /* @__PURE__ */ new Map();
110
166
  var gateFingerprintCache = /* @__PURE__ */ new Map();
111
167
  var binanceBreadthFingerprintCache = /* @__PURE__ */ new Map();
@@ -156,7 +212,7 @@ var resolveGitLineage = (projectRoot) => {
156
212
  };
157
213
  var readOptionalFile = async (filePath) => {
158
214
  try {
159
- return await import_promises.default.readFile(filePath);
215
+ return await import_promises2.default.readFile(filePath);
160
216
  } catch {
161
217
  return null;
162
218
  }
@@ -166,7 +222,7 @@ var resolveBinanceBreadthFingerprint = async (projectRoot) => {
166
222
  return binanceBreadthFingerprintCache.get(projectRoot) ?? null;
167
223
  }
168
224
  const content = await readOptionalFile(
169
- import_node_path.default.join(
225
+ import_node_path2.default.join(
170
226
  projectRoot,
171
227
  "packages/node/src/config/binanceBreadthUniverses.json"
172
228
  )
@@ -188,7 +244,7 @@ var resolveSnapshotFingerprint = async (projectRoot, relativePath) => {
188
244
  if (snapshotFingerprintCache.has(cacheKey)) {
189
245
  return snapshotFingerprintCache.get(cacheKey) ?? null;
190
246
  }
191
- const content = await readOptionalFile(import_node_path.default.join(projectRoot, relativePath));
247
+ const content = await readOptionalFile(import_node_path2.default.join(projectRoot, relativePath));
192
248
  let result = null;
193
249
  if (content) {
194
250
  try {
@@ -201,55 +257,26 @@ var resolveSnapshotFingerprint = async (projectRoot, relativePath) => {
201
257
  snapshotFingerprintCache.set(cacheKey, result);
202
258
  return result;
203
259
  };
204
- var resolveGateFingerprint = async ({
260
+ var resolveRuntimeGateFingerprint = async ({
205
261
  projectRoot,
206
262
  strategyName,
207
263
  gitSha
208
264
  }) => {
209
265
  const cacheKey = `${projectRoot}:${strategyName}:${gitSha ?? "unknown"}`;
210
266
  const cached = gateFingerprintCache.get(cacheKey);
211
- if (cached) {
212
- return cached;
213
- }
214
- const relativeCandidates = [
215
- `packages/strategies/src/${strategyName}/adapters/ai.ts`,
216
- `packages/strategies/src/${strategyName}/guardrails.ts`,
217
- `packages/strategies/src/${strategyName}/pockets.ts`,
218
- `packages/strategies/src/${strategyName}/config.ts`,
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;
267
+ if (cached) return cached;
268
+ const result = await resolveStrategyGateFingerprint({
269
+ projectRoot,
270
+ strategyName,
271
+ gitSha
272
+ });
273
+ gateFingerprintCache.set(cacheKey, result);
274
+ return result;
249
275
  };
250
276
  var buildRuntimeLineage = async ({
251
277
  projectRoot,
252
278
  strategyName,
279
+ compositionId,
253
280
  config,
254
281
  runContext,
255
282
  env = process.env
@@ -275,19 +302,25 @@ var buildRuntimeLineage = async ({
275
302
  };
276
303
  return {
277
304
  schemaVersion: 1,
305
+ compositionId: compositionId?.trim() || null,
278
306
  ...git,
279
- gateFingerprint: await resolveGateFingerprint({
307
+ gateFingerprint: (await resolveRuntimeGateFingerprint({
280
308
  projectRoot,
281
309
  strategyName,
282
310
  gitSha: git.gitSha
283
- }),
284
- configFingerprint: fingerprintRuntimeValue(config),
311
+ })).gateFingerprint,
312
+ // Position risk is tracked separately so changing trade size does not
313
+ // masquerade as a change to the core + gate decision logic.
314
+ configFingerprint: fingerprintRuntimeValue(
315
+ normalizeRuntimeLogicConfig(config)
316
+ ),
285
317
  contextFingerprint: fingerprintRuntimeValue(context),
286
318
  maxLossValue: resolveRuntimeMaxLossValue(config)
287
319
  };
288
320
  };
289
321
  var runtimeLineageKey = (lineage) => [
290
322
  lineage.schemaVersion,
323
+ lineage.compositionId ?? "unbound-composition",
291
324
  lineage.gitSha ?? "unknown",
292
325
  lineage.gitDirty == null ? "unknown" : lineage.gitDirty ? "dirty" : "clean",
293
326
  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 rows = extractRuntimeRows(runtimeArtifact);
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 = asRecord(replayComparison?.counts);
211
- const matched = finiteNumber(replayCounts?.matched) ?? 0;
212
- const backtestOnly = finiteNumber(replayCounts?.backtestOnly) ?? 0;
213
- const runtimeOnly = finiteNumber(replayCounts?.runtimeOnly) ?? 0;
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 calibration = getCalibrationSummary(calibrationArtifact);
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
- ...historyRuntimeArtifacts,
227
- runtimeArtifact
347
+ ...scopedHistoryArtifacts,
348
+ scopedRuntimeArtifact
228
349
  ]);
229
350
  const currentDistributions = buildDistributions(rows);
230
- const previousArtifact = historyRuntimeArtifacts.map((artifact) => ({ artifact, window: runtimeWindow(artifact) })).filter(({ window: candidateWindow }) => {
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
+ });