@tradejs/cli 3.1.29-beta.262 → 3.1.29-beta.264

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.
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,7 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
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
- ));
18
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
28
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
20
 
30
21
  // src/lib/runtimeFeedbackNotification.ts
@@ -36,187 +27,8 @@ __export(runtimeFeedbackNotification_exports, {
36
27
  module.exports = __toCommonJS(runtimeFeedbackNotification_exports);
37
28
 
38
29
  // src/lib/runtimeFeedbackArtifacts.ts
39
- var import_node_crypto3 = require("crypto");
40
- var import_promises3 = __toESM(require("fs/promises"));
41
- var import_node_path3 = __toESM(require("path"));
42
-
43
- // src/lib/runtimeEvidenceDeployment.ts
44
- var import_runtimeStrategies = require("@tradejs/node/runtimeStrategies");
45
- var isRecord = (value) => value != null && typeof value === "object" && !Array.isArray(value);
46
- var isNonEmptyString = (value) => typeof value === "string" && value.trim().length > 0;
47
- var isPackageVersionMap = (value) => isRecord(value) && Object.keys(value).length > 0 && Object.entries(value).every(
48
- ([name, version]) => name.startsWith("@tradejs/") && isNonEmptyString(version)
49
- );
50
- var INTERVALS = /* @__PURE__ */ new Set([
51
- "1",
52
- "3",
53
- "5",
54
- "15",
55
- "30",
56
- "60",
57
- "120",
58
- "240",
59
- "360",
60
- "720",
61
- "D",
62
- "W",
63
- "M"
64
- ]);
65
- var UNIVERSES = /* @__PURE__ */ new Set(["crypto", "tradfi"]);
66
- 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));
67
- var parseRuntimeEvidenceDeploymentSnapshot = (value) => {
68
- 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)) {
69
- throw new Error(
70
- "Runtime evidence deployment snapshot is missing or invalid"
71
- );
72
- }
73
- const strategies = value.strategies.map((candidate) => {
74
- 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)) {
75
- throw new Error(
76
- "Runtime evidence deployment strategy snapshot is invalid"
77
- );
78
- }
79
- if (String(candidate.strategyConfig.INTERVAL) !== String(candidate.interval) || String(candidate.strategyConfig.UNIVERSE) !== String(candidate.universe)) {
80
- throw new Error(
81
- `Runtime evidence strategy config does not match its scope: ${candidate.strategyName}`
82
- );
83
- }
84
- if (candidate.accountId != null && (!isNonEmptyString(candidate.accountId) || candidate.accountId !== value.accountId)) {
85
- throw new Error(
86
- `Runtime evidence strategy account does not match deployment: ${candidate.strategyName}`
87
- );
88
- }
89
- return candidate;
90
- });
91
- const identities = /* @__PURE__ */ new Set();
92
- for (const strategy of strategies) {
93
- if (identities.has(strategy.strategyName)) {
94
- throw new Error(
95
- `Duplicate runtime evidence strategy: ${strategy.strategyName}`
96
- );
97
- }
98
- identities.add(strategy.strategyName);
99
- }
100
- return {
101
- ...value,
102
- strategies
103
- };
104
- };
105
- var activeRuntimeEvidenceStrategies = (deployment) => deployment.enabled ? deployment.strategies.filter((strategy) => strategy.enabled) : [];
106
-
107
- // src/lib/runtimeEvidenceArtifacts.ts
108
- var import_node_crypto = require("crypto");
109
- var import_promises = __toESM(require("fs/promises"));
110
- var import_node_path = __toESM(require("path"));
111
-
112
- // src/lib/runtimeEvidenceProducer.ts
113
- var import_node_crypto2 = require("crypto");
114
- var import_promises2 = __toESM(require("fs/promises"));
115
- var import_node_path2 = __toESM(require("path"));
116
- var isRecord2 = (value) => value != null && typeof value === "object" && !Array.isArray(value);
117
- var parseRuntimeEvidenceProducer = (value) => {
118
- const producer = isRecord2(value) ? value : null;
119
- const runtimePackageManifest = isRecord2(producer?.runtimePackageManifest) ? producer.runtimePackageManifest : null;
120
- 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)) {
121
- throw new Error("Runtime evidence producer image identity is invalid");
122
- }
123
- return producer;
124
- };
125
-
126
- // src/lib/runtimeFeedbackArtifacts.ts
127
- var RUNTIME_FEEDBACK_MANIFEST_FILE = "manifest.json";
128
- var RUNTIME_FEEDBACK_REPLAY_FILE = "replay-runtime-evidence.json";
129
- var RUNTIME_FEEDBACK_LOG_FILE = "replay.log";
130
- var RUNTIME_FEEDBACK_COMPLETE_FILE = ".complete";
131
- var isRecord3 = (value) => value != null && typeof value === "object" && !Array.isArray(value);
132
- var sha256 = (value) => (0, import_node_crypto3.createHash)("sha256").update(value).digest("hex");
133
- var parsePayload = (value, expectedFile) => {
134
- const payload = isRecord3(value) ? value : null;
135
- 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) {
136
- throw new Error(`Invalid runtime feedback payload: ${expectedFile}`);
137
- }
138
- return payload;
139
- };
140
- var parseManifest = (value) => {
141
- const manifest = isRecord3(value) ? value : null;
142
- const window = isRecord3(manifest?.window) ? manifest.window : null;
143
- const runtimeEvidence = isRecord3(manifest?.runtimeEvidence) ? manifest.runtimeEvidence : null;
144
- const safety = isRecord3(manifest?.safety) ? manifest.safety : null;
145
- const payloads = isRecord3(manifest?.payloads) ? manifest.payloads : null;
146
- 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(
147
- (strategy) => typeof strategy === "string" && strategy.trim()
148
- ) || typeof manifest.cycleCount !== "number" || !Number.isFinite(manifest.cycleCount) || manifest.cycleCount <= 0 || safety?.cacheOnly !== true || safety.externalOrderPlacement !== false || safety.redis !== "isolated" || safety.timescale !== "read_only") {
149
- throw new Error("Invalid runtime feedback replay manifest");
150
- }
151
- const replayEvidence = parsePayload(
152
- payloads?.replayEvidence,
153
- RUNTIME_FEEDBACK_REPLAY_FILE
154
- );
155
- const log = parsePayload(payloads?.log, RUNTIME_FEEDBACK_LOG_FILE);
156
- return {
157
- ...manifest,
158
- producer: parseRuntimeEvidenceProducer(manifest.producer),
159
- payloads: {
160
- replayEvidence: {
161
- ...replayEvidence,
162
- file: RUNTIME_FEEDBACK_REPLAY_FILE
163
- },
164
- log: { ...log, file: RUNTIME_FEEDBACK_LOG_FILE }
165
- }
166
- };
167
- };
168
- var verifyRuntimeFeedbackReplayBundle = async (bundleDir) => {
169
- const manifestPath = import_node_path3.default.join(bundleDir, RUNTIME_FEEDBACK_MANIFEST_FILE);
170
- const replayEvidencePath = import_node_path3.default.join(bundleDir, RUNTIME_FEEDBACK_REPLAY_FILE);
171
- const logPath = import_node_path3.default.join(bundleDir, RUNTIME_FEEDBACK_LOG_FILE);
172
- const completePath = import_node_path3.default.join(bundleDir, RUNTIME_FEEDBACK_COMPLETE_FILE);
173
- const [manifestText, replayPayload, logPayload, completeText] = await Promise.all([
174
- import_promises3.default.readFile(manifestPath, "utf8"),
175
- import_promises3.default.readFile(replayEvidencePath),
176
- import_promises3.default.readFile(logPath),
177
- import_promises3.default.readFile(completePath, "utf8")
178
- ]);
179
- const manifest = parseManifest(JSON.parse(manifestText));
180
- if (completeText.trim() !== manifest.artifactId) {
181
- throw new Error(`Invalid runtime feedback completion marker: ${bundleDir}`);
182
- }
183
- for (const [payload, descriptor] of [
184
- [replayPayload, manifest.payloads.replayEvidence],
185
- [logPayload, manifest.payloads.log]
186
- ]) {
187
- if (payload.byteLength !== descriptor.bytes) {
188
- throw new Error(
189
- `Runtime feedback payload size mismatch: ${descriptor.file}`
190
- );
191
- }
192
- if (sha256(payload) !== descriptor.sha256) {
193
- throw new Error(
194
- `Runtime feedback payload checksum mismatch: ${descriptor.file}`
195
- );
196
- }
197
- }
198
- const replayEvidence = JSON.parse(replayPayload.toString("utf8"));
199
- if (replayEvidence.reportType !== "replay-runtime-evidence") {
200
- throw new Error("Invalid runtime feedback replay evidence payload");
201
- }
202
- const replayWindow = isRecord3(replayEvidence.window) ? replayEvidence.window : null;
203
- const replay = isRecord3(replayEvidence.replay) ? replayEvidence.replay : null;
204
- const replayDeployment = parseRuntimeEvidenceDeploymentSnapshot(
205
- replayEvidence.deployment
206
- );
207
- const replayStrategies = activeRuntimeEvidenceStrategies(replayDeployment).map(({ strategyName }) => strategyName).sort();
208
- 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())) {
209
- throw new Error("Runtime feedback replay payload does not match manifest");
210
- }
211
- return {
212
- bundleDir,
213
- manifestPath,
214
- replayEvidencePath,
215
- logPath,
216
- manifest,
217
- replayEvidence
218
- };
219
- };
30
+ var runtimeFeedbackArtifacts_exports = {};
31
+ __reExport(runtimeFeedbackArtifacts_exports, require("@tradejs/node/diagnostics"));
220
32
 
221
33
  // src/lib/telegramReports.ts
222
34
  var import_cli = require("@tradejs/node/cli");
@@ -288,8 +100,8 @@ ${chunk}`, {
288
100
  };
289
101
 
290
102
  // src/lib/runtimeFeedbackNotification.ts
291
- var isRecord4 = (value) => value != null && typeof value === "object" && !Array.isArray(value);
292
- var asRecord = (value) => isRecord4(value) ? value : {};
103
+ var isRecord = (value) => value != null && typeof value === "object" && !Array.isArray(value);
104
+ var asRecord = (value) => isRecord(value) ? value : {};
293
105
  var asArray = (value) => Array.isArray(value) ? value.map(asRecord) : [];
294
106
  var finiteNumber = (value, fallback = 0) => {
295
107
  const number = Number(value);
@@ -326,7 +138,7 @@ var buildRuntimeFeedbackTelegramMessage = (replayEvidence) => {
326
138
  const endTime = requiredTimestamp(window.endTime, "window.endTime");
327
139
  const deployment = asRecord(replayEvidence.deployment);
328
140
  const replay = asRecord(replayEvidence.replay);
329
- if (!isRecord4(replay.runtimeComparison) || !isRecord4(replay.runtimeComparison.counts) || !Array.isArray(replay.runtimeComparison.rows) || !isRecord4(replay.runtimeComparison.lineage)) {
141
+ if (!isRecord(replay.runtimeComparison) || !isRecord(replay.runtimeComparison.counts) || !Array.isArray(replay.runtimeComparison.rows) || !isRecord(replay.runtimeComparison.lineage)) {
330
142
  throw new Error("Runtime feedback replay comparison is missing");
331
143
  }
332
144
  const comparison = asRecord(replay.runtimeComparison);
@@ -396,7 +208,7 @@ var notifyRuntimeFeedbackBundle = async ({
396
208
  bundleDir,
397
209
  send = sendTelegramReport
398
210
  }) => {
399
- const verified = await verifyRuntimeFeedbackReplayBundle(bundleDir);
211
+ const verified = await (0, runtimeFeedbackArtifacts_exports.verifyRuntimeFeedbackReplayBundle)(bundleDir);
400
212
  const message = buildRuntimeFeedbackTelegramMessage(verified.replayEvidence);
401
213
  await send(message, { userName: verified.manifest.userName });
402
214
  return {