@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.
- 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-
|
|
@@ -36,309 +37,31 @@ __export(runtimeEvidenceCompositions_exports, {
|
|
|
36
37
|
module.exports = __toCommonJS(runtimeEvidenceCompositions_exports);
|
|
37
38
|
|
|
38
39
|
// src/lib/runtimeEvidenceArtifacts.ts
|
|
40
|
+
var runtimeEvidenceArtifacts_exports = {};
|
|
41
|
+
__reExport(runtimeEvidenceArtifacts_exports, require("@tradejs/node/diagnostics"));
|
|
42
|
+
|
|
43
|
+
// src/lib/runtimeEvidenceCompositionSnapshots.ts
|
|
39
44
|
var import_node_crypto = require("crypto");
|
|
40
45
|
var import_promises = __toESM(require("fs/promises"));
|
|
41
46
|
var import_node_path = __toESM(require("path"));
|
|
42
47
|
|
|
43
48
|
// src/lib/runtimeEvidenceDeployment.ts
|
|
44
|
-
var
|
|
45
|
-
|
|
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 samePackageVersions = (left, right) => {
|
|
68
|
-
if (!left || !right) return false;
|
|
69
|
-
const leftEntries = Object.entries(left).sort(
|
|
70
|
-
([a], [b]) => a.localeCompare(b)
|
|
71
|
-
);
|
|
72
|
-
const rightEntries = Object.entries(right).sort(
|
|
73
|
-
([a], [b]) => a.localeCompare(b)
|
|
74
|
-
);
|
|
75
|
-
return JSON.stringify(leftEntries) === JSON.stringify(rightEntries);
|
|
76
|
-
};
|
|
77
|
-
var runtimeLineageMatchesStrategySnapshot = ({
|
|
78
|
-
lineage,
|
|
79
|
-
deployment,
|
|
80
|
-
strategy
|
|
81
|
-
}) => lineage?.schemaVersion === 3 && lineage.strategyRevision === strategy.strategyRevision && lineage.deploymentCompositionId === deployment.deploymentCompositionId && lineage.strategyPackageVersion === strategy.strategyPackageVersion && lineage.runtimePackageVersion === strategy.runtimePackageVersion && samePackageVersions(
|
|
82
|
-
lineage.strategyDependencyVersions,
|
|
83
|
-
strategy.strategyDependencyVersions
|
|
84
|
-
);
|
|
85
|
-
var parseRuntimeEvidenceDeploymentSnapshot = (value) => {
|
|
86
|
-
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)) {
|
|
87
|
-
throw new Error(
|
|
88
|
-
"Runtime evidence deployment snapshot is missing or invalid"
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
const strategies = value.strategies.map((candidate) => {
|
|
92
|
-
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)) {
|
|
93
|
-
throw new Error(
|
|
94
|
-
"Runtime evidence deployment strategy snapshot is invalid"
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
if (String(candidate.strategyConfig.INTERVAL) !== String(candidate.interval) || String(candidate.strategyConfig.UNIVERSE) !== String(candidate.universe)) {
|
|
98
|
-
throw new Error(
|
|
99
|
-
`Runtime evidence strategy config does not match its scope: ${candidate.strategyName}`
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
if (candidate.accountId != null && (!isNonEmptyString(candidate.accountId) || candidate.accountId !== value.accountId)) {
|
|
103
|
-
throw new Error(
|
|
104
|
-
`Runtime evidence strategy account does not match deployment: ${candidate.strategyName}`
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
return candidate;
|
|
108
|
-
});
|
|
109
|
-
const identities = /* @__PURE__ */ new Set();
|
|
110
|
-
for (const strategy of strategies) {
|
|
111
|
-
if (identities.has(strategy.strategyName)) {
|
|
112
|
-
throw new Error(
|
|
113
|
-
`Duplicate runtime evidence strategy: ${strategy.strategyName}`
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
identities.add(strategy.strategyName);
|
|
117
|
-
}
|
|
118
|
-
return {
|
|
119
|
-
...value,
|
|
120
|
-
strategies
|
|
121
|
-
};
|
|
122
|
-
};
|
|
123
|
-
var activeRuntimeEvidenceStrategies = (deployment) => deployment.enabled ? deployment.strategies.filter((strategy) => strategy.enabled) : [];
|
|
124
|
-
var unwrapRuntimeEvidenceRows = (value, field) => (Array.isArray(value) ? value : []).map((candidate) => {
|
|
125
|
-
const record = isRecord(candidate) ? candidate : null;
|
|
126
|
-
const nested = record && isRecord(record[field]) ? record[field] : null;
|
|
127
|
-
return nested ?? record;
|
|
128
|
-
}).filter((record) => record != null);
|
|
129
|
-
var assertCurrentRuntimeEvidenceArtifact = (artifact) => {
|
|
130
|
-
if (!isRecord(artifact) || artifact.reportType !== "runtime-evidence") {
|
|
131
|
-
throw new Error("Invalid runtime evidence artifact");
|
|
132
|
-
}
|
|
133
|
-
const deployment = parseRuntimeEvidenceDeploymentSnapshot(
|
|
134
|
-
artifact.deployment
|
|
135
|
-
);
|
|
136
|
-
const activeStrategies = activeRuntimeEvidenceStrategies(deployment);
|
|
137
|
-
if (activeStrategies.length === 0) {
|
|
138
|
-
throw new Error("Runtime evidence deployment has no enabled strategies");
|
|
139
|
-
}
|
|
140
|
-
const runtime = isRecord(artifact.runtime) ? artifact.runtime : null;
|
|
141
|
-
if (!runtime) {
|
|
142
|
-
throw new Error("Runtime evidence payload is missing");
|
|
143
|
-
}
|
|
144
|
-
if ("strategyConfigs" in runtime) {
|
|
145
|
-
throw new Error(
|
|
146
|
-
"Runtime evidence payload contains removed strategyConfigs data"
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
if ("evaluationStatsBuckets" in runtime) {
|
|
150
|
-
throw new Error(
|
|
151
|
-
"Runtime evidence payload contains removed lineage-less evaluationStatsBuckets data"
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
|
-
const rowFields = [
|
|
155
|
-
"trades",
|
|
156
|
-
"signals",
|
|
157
|
-
"evaluations",
|
|
158
|
-
"lineageScopes"
|
|
159
|
-
];
|
|
160
|
-
for (const field of rowFields) {
|
|
161
|
-
if (!Array.isArray(runtime[field])) {
|
|
162
|
-
throw new Error(`Runtime evidence payload ${field} must be an array`);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
const snapshots = new Map(
|
|
166
|
-
activeStrategies.map((strategy) => [strategy.strategyName, strategy])
|
|
167
|
-
);
|
|
168
|
-
const assertRows = (label, rows, lineageField) => {
|
|
169
|
-
for (const row of rows) {
|
|
170
|
-
const strategyName = String(row.strategy ?? "").trim();
|
|
171
|
-
const strategy = snapshots.get(strategyName);
|
|
172
|
-
if (!strategy || row.deploymentId !== deployment.id || row.accountId !== deployment.accountId || !runtimeLineageMatchesStrategySnapshot({
|
|
173
|
-
lineage: isRecord(row[lineageField]) ? row[lineageField] : void 0,
|
|
174
|
-
deployment,
|
|
175
|
-
strategy
|
|
176
|
-
})) {
|
|
177
|
-
throw new Error(
|
|
178
|
-
`Runtime evidence ${label} row is outside the current embedded deployment lineage`
|
|
179
|
-
);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
assertRows(
|
|
184
|
-
"trade",
|
|
185
|
-
unwrapRuntimeEvidenceRows(runtime.trades, "trade"),
|
|
186
|
-
"runtimeLineage"
|
|
187
|
-
);
|
|
188
|
-
assertRows(
|
|
189
|
-
"signal",
|
|
190
|
-
unwrapRuntimeEvidenceRows(runtime.signals, "signal"),
|
|
191
|
-
"runtimeLineage"
|
|
192
|
-
);
|
|
193
|
-
assertRows(
|
|
194
|
-
"evaluation",
|
|
195
|
-
unwrapRuntimeEvidenceRows(runtime.evaluations, "evaluation"),
|
|
196
|
-
"runtimeLineage"
|
|
197
|
-
);
|
|
198
|
-
assertRows(
|
|
199
|
-
"lineage scope",
|
|
200
|
-
unwrapRuntimeEvidenceRows(runtime.lineageScopes, "lineageScope"),
|
|
201
|
-
"lineage"
|
|
202
|
-
);
|
|
203
|
-
return deployment;
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
// src/lib/runtimeEvidenceArtifacts.ts
|
|
207
|
-
var RUNTIME_EVIDENCE_MANIFEST_FILE = "manifest.json";
|
|
208
|
-
var RUNTIME_EVIDENCE_PAYLOAD_FILE = "runtime-evidence.json";
|
|
209
|
-
var RUNTIME_EVIDENCE_COMPLETE_FILE = ".complete";
|
|
210
|
-
var asRecord = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
211
|
-
var sha256 = (value) => (0, import_node_crypto.createHash)("sha256").update(value).digest("hex");
|
|
212
|
-
var assertFiniteTimestamp = (value, label) => {
|
|
213
|
-
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
214
|
-
throw new Error(`Invalid runtime evidence ${label}`);
|
|
215
|
-
}
|
|
216
|
-
return value;
|
|
217
|
-
};
|
|
218
|
-
var parseManifest = (value) => {
|
|
219
|
-
const manifest = asRecord(value);
|
|
220
|
-
const window = asRecord(manifest?.window);
|
|
221
|
-
const payload = asRecord(manifest?.payload);
|
|
222
|
-
const counts = asRecord(manifest?.counts);
|
|
223
|
-
if (manifest?.schemaVersion !== 1 || manifest.reportType !== "runtime-evidence" || typeof manifest.artifactId !== "string" || typeof manifest.deploymentId !== "string" || typeof manifest.userName !== "string" || typeof manifest.createdAt !== "number" || payload?.file !== RUNTIME_EVIDENCE_PAYLOAD_FILE || typeof payload.sha256 !== "string" || !/^[a-f0-9]{64}$/.test(payload.sha256) || typeof payload.bytes !== "number" || !Array.isArray(manifest.lineageKeys)) {
|
|
224
|
-
throw new Error("Invalid runtime evidence manifest");
|
|
225
|
-
}
|
|
226
|
-
return {
|
|
227
|
-
schemaVersion: 1,
|
|
228
|
-
artifactId: manifest.artifactId,
|
|
229
|
-
reportType: "runtime-evidence",
|
|
230
|
-
deploymentId: manifest.deploymentId,
|
|
231
|
-
userName: manifest.userName,
|
|
232
|
-
createdAt: manifest.createdAt,
|
|
233
|
-
window: {
|
|
234
|
-
startTime: assertFiniteTimestamp(window?.startTime, "window.startTime"),
|
|
235
|
-
endTime: assertFiniteTimestamp(window?.endTime, "window.endTime")
|
|
236
|
-
},
|
|
237
|
-
payload: {
|
|
238
|
-
file: RUNTIME_EVIDENCE_PAYLOAD_FILE,
|
|
239
|
-
sha256: payload.sha256,
|
|
240
|
-
bytes: payload.bytes
|
|
241
|
-
},
|
|
242
|
-
counts: Object.fromEntries(
|
|
243
|
-
Object.entries(counts ?? {}).filter(
|
|
244
|
-
(entry) => typeof entry[1] === "number" && Number.isFinite(entry[1])
|
|
245
|
-
)
|
|
246
|
-
),
|
|
247
|
-
lineageKeys: manifest.lineageKeys.filter(
|
|
248
|
-
(value2) => typeof value2 === "string" && value2.length > 0
|
|
249
|
-
)
|
|
250
|
-
};
|
|
251
|
-
};
|
|
252
|
-
var verifyRuntimeEvidenceBundle = async (bundleDir) => {
|
|
253
|
-
const manifestPath = import_node_path.default.join(bundleDir, RUNTIME_EVIDENCE_MANIFEST_FILE);
|
|
254
|
-
const payloadPath = import_node_path.default.join(bundleDir, RUNTIME_EVIDENCE_PAYLOAD_FILE);
|
|
255
|
-
const completePath = import_node_path.default.join(bundleDir, RUNTIME_EVIDENCE_COMPLETE_FILE);
|
|
256
|
-
const [manifestText, payload, completeText] = await Promise.all([
|
|
257
|
-
import_promises.default.readFile(manifestPath, "utf8"),
|
|
258
|
-
import_promises.default.readFile(payloadPath),
|
|
259
|
-
import_promises.default.readFile(completePath, "utf8")
|
|
260
|
-
]);
|
|
261
|
-
const manifest = parseManifest(JSON.parse(manifestText));
|
|
262
|
-
if (completeText.trim() !== manifest.artifactId) {
|
|
263
|
-
throw new Error(`Invalid completion marker in ${bundleDir}`);
|
|
264
|
-
}
|
|
265
|
-
if (payload.byteLength !== manifest.payload.bytes) {
|
|
266
|
-
throw new Error(`Runtime evidence size mismatch in ${bundleDir}`);
|
|
267
|
-
}
|
|
268
|
-
if (sha256(payload) !== manifest.payload.sha256) {
|
|
269
|
-
throw new Error(`Runtime evidence checksum mismatch in ${bundleDir}`);
|
|
270
|
-
}
|
|
271
|
-
const artifact = asRecord(JSON.parse(payload.toString("utf8")));
|
|
272
|
-
const artifactWindow = asRecord(artifact?.window);
|
|
273
|
-
if (artifact?.reportType !== "runtime-evidence" || artifactWindow?.startTime !== manifest.window.startTime || artifactWindow.endTime !== manifest.window.endTime) {
|
|
274
|
-
throw new Error(`Runtime evidence payload mismatch in ${bundleDir}`);
|
|
275
|
-
}
|
|
276
|
-
const deployment = assertCurrentRuntimeEvidenceArtifact(artifact);
|
|
277
|
-
if (deployment.id !== manifest.deploymentId) {
|
|
278
|
-
throw new Error(`Runtime evidence deployment mismatch in ${bundleDir}`);
|
|
279
|
-
}
|
|
280
|
-
return {
|
|
281
|
-
bundleDir,
|
|
282
|
-
manifestPath,
|
|
283
|
-
payloadPath,
|
|
284
|
-
manifest,
|
|
285
|
-
artifact
|
|
286
|
-
};
|
|
287
|
-
};
|
|
288
|
-
var discoverRuntimeEvidenceBundles = async (rootDir) => {
|
|
289
|
-
const bundles = [];
|
|
290
|
-
const visit = async (directory, depth) => {
|
|
291
|
-
if (depth > 8) return;
|
|
292
|
-
let entries;
|
|
293
|
-
try {
|
|
294
|
-
entries = await import_promises.default.readdir(directory, { withFileTypes: true });
|
|
295
|
-
} catch (error) {
|
|
296
|
-
if (error.code === "ENOENT") return;
|
|
297
|
-
throw error;
|
|
298
|
-
}
|
|
299
|
-
const names = new Set(entries.map((entry) => entry.name));
|
|
300
|
-
if (names.has(RUNTIME_EVIDENCE_MANIFEST_FILE) && names.has(RUNTIME_EVIDENCE_PAYLOAD_FILE) && names.has(RUNTIME_EVIDENCE_COMPLETE_FILE)) {
|
|
301
|
-
bundles.push(directory);
|
|
302
|
-
return;
|
|
303
|
-
}
|
|
304
|
-
await Promise.all(
|
|
305
|
-
entries.filter(
|
|
306
|
-
(entry) => entry.isDirectory() && !entry.name.startsWith(".") && !entry.name.includes(".tmp-")
|
|
307
|
-
).map((entry) => visit(import_node_path.default.join(directory, entry.name), depth + 1))
|
|
308
|
-
);
|
|
309
|
-
};
|
|
310
|
-
await visit(rootDir, 0);
|
|
311
|
-
return bundles.sort();
|
|
312
|
-
};
|
|
313
|
-
|
|
314
|
-
// src/lib/runtimeEvidenceCompositionSnapshots.ts
|
|
315
|
-
var import_node_crypto3 = require("crypto");
|
|
316
|
-
var import_promises3 = __toESM(require("fs/promises"));
|
|
317
|
-
var import_node_path3 = __toESM(require("path"));
|
|
49
|
+
var runtimeEvidenceDeployment_exports = {};
|
|
50
|
+
__reExport(runtimeEvidenceDeployment_exports, require("@tradejs/node/diagnostics"));
|
|
318
51
|
|
|
319
52
|
// src/lib/runtimeEvidenceProducer.ts
|
|
320
|
-
var
|
|
321
|
-
|
|
322
|
-
var import_node_path2 = __toESM(require("path"));
|
|
323
|
-
var isRecord2 = (value) => value != null && typeof value === "object" && !Array.isArray(value);
|
|
324
|
-
var parseRuntimeEvidenceProducer = (value) => {
|
|
325
|
-
const producer = isRecord2(value) ? value : null;
|
|
326
|
-
const runtimePackageManifest = isRecord2(producer?.runtimePackageManifest) ? producer.runtimePackageManifest : null;
|
|
327
|
-
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)) {
|
|
328
|
-
throw new Error("Runtime evidence producer image identity is invalid");
|
|
329
|
-
}
|
|
330
|
-
return producer;
|
|
331
|
-
};
|
|
53
|
+
var runtimeEvidenceProducer_exports = {};
|
|
54
|
+
__reExport(runtimeEvidenceProducer_exports, require("@tradejs/node/diagnostics"));
|
|
332
55
|
|
|
333
56
|
// src/lib/runtimeEvidenceCompositionSnapshots.ts
|
|
334
57
|
var SNAPSHOT_FILE = "snapshot.json";
|
|
335
58
|
var MANIFEST_FILE = "manifest.json";
|
|
336
59
|
var COMPLETE_FILE = ".complete";
|
|
337
|
-
var
|
|
338
|
-
var
|
|
339
|
-
var
|
|
340
|
-
const manifest =
|
|
341
|
-
const payload =
|
|
60
|
+
var isRecord = (value) => value != null && typeof value === "object" && !Array.isArray(value);
|
|
61
|
+
var sha256 = (value) => (0, import_node_crypto.createHash)("sha256").update(value).digest("hex");
|
|
62
|
+
var parseManifest = (value) => {
|
|
63
|
+
const manifest = isRecord(value) ? value : null;
|
|
64
|
+
const payload = isRecord(manifest?.payload) ? manifest.payload : null;
|
|
342
65
|
if (manifest?.schemaVersion !== 1 || manifest.reportType !== "runtime-evidence-composition-snapshot" || typeof manifest.createdAt !== "number" || typeof manifest.userName !== "string" || typeof manifest.deploymentId !== "string" || typeof manifest.deploymentCompositionId !== "string" || payload?.file !== SNAPSHOT_FILE || typeof payload.sha256 !== "string" || !/^[a-f0-9]{64}$/.test(payload.sha256) || typeof payload.bytes !== "number") {
|
|
343
66
|
throw new Error("Invalid runtime evidence composition snapshot manifest");
|
|
344
67
|
}
|
|
@@ -346,28 +69,28 @@ var parseManifest2 = (value) => {
|
|
|
346
69
|
};
|
|
347
70
|
var verifyRuntimeEvidenceCompositionSnapshot = async (bundleDir) => {
|
|
348
71
|
const [manifestText, payload, completeText] = await Promise.all([
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
72
|
+
import_promises.default.readFile(import_node_path.default.join(bundleDir, MANIFEST_FILE), "utf8"),
|
|
73
|
+
import_promises.default.readFile(import_node_path.default.join(bundleDir, SNAPSHOT_FILE)),
|
|
74
|
+
import_promises.default.readFile(import_node_path.default.join(bundleDir, COMPLETE_FILE), "utf8")
|
|
352
75
|
]);
|
|
353
|
-
const manifest =
|
|
76
|
+
const manifest = parseManifest(JSON.parse(manifestText));
|
|
354
77
|
if (completeText.trim() !== manifest.deploymentCompositionId) {
|
|
355
78
|
throw new Error(`Invalid completion marker in ${bundleDir}`);
|
|
356
79
|
}
|
|
357
|
-
if (payload.byteLength !== manifest.payload.bytes ||
|
|
80
|
+
if (payload.byteLength !== manifest.payload.bytes || sha256(payload) !== manifest.payload.sha256) {
|
|
358
81
|
throw new Error(
|
|
359
82
|
`Runtime evidence snapshot checksum mismatch in ${bundleDir}`
|
|
360
83
|
);
|
|
361
84
|
}
|
|
362
85
|
const value = JSON.parse(payload.toString("utf8"));
|
|
363
|
-
const record =
|
|
86
|
+
const record = isRecord(value) ? value : null;
|
|
364
87
|
if (record?.schemaVersion !== 1 || record.reportType !== "runtime-evidence-composition-snapshot" || record.userName !== manifest.userName) {
|
|
365
88
|
throw new Error(
|
|
366
89
|
`Invalid runtime evidence snapshot payload in ${bundleDir}`
|
|
367
90
|
);
|
|
368
91
|
}
|
|
369
|
-
const deployment = parseRuntimeEvidenceDeploymentSnapshot(record.deployment);
|
|
370
|
-
const producer = parseRuntimeEvidenceProducer(record.producer);
|
|
92
|
+
const deployment = (0, runtimeEvidenceDeployment_exports.parseRuntimeEvidenceDeploymentSnapshot)(record.deployment);
|
|
93
|
+
const producer = (0, runtimeEvidenceProducer_exports.parseRuntimeEvidenceProducer)(record.producer);
|
|
371
94
|
if (deployment.id !== manifest.deploymentId || deployment.deploymentCompositionId !== manifest.deploymentCompositionId) {
|
|
372
95
|
throw new Error(
|
|
373
96
|
`Runtime evidence snapshot identity mismatch in ${bundleDir}`
|
|
@@ -376,24 +99,24 @@ var verifyRuntimeEvidenceCompositionSnapshot = async (bundleDir) => {
|
|
|
376
99
|
return { bundleDir, deployment, producer };
|
|
377
100
|
};
|
|
378
101
|
var discoverRuntimeEvidenceCompositionSnapshots = async (evidenceRoot) => {
|
|
379
|
-
const rootDir =
|
|
102
|
+
const rootDir = import_node_path.default.join(evidenceRoot, "snapshots");
|
|
380
103
|
const bundleDirs = [];
|
|
381
104
|
let deployments;
|
|
382
105
|
try {
|
|
383
|
-
deployments = await
|
|
106
|
+
deployments = await import_promises.default.readdir(rootDir, { withFileTypes: true });
|
|
384
107
|
} catch (error) {
|
|
385
108
|
if (error.code === "ENOENT") return [];
|
|
386
109
|
throw error;
|
|
387
110
|
}
|
|
388
111
|
for (const deployment of deployments.filter((entry) => entry.isDirectory())) {
|
|
389
|
-
const deploymentDir =
|
|
390
|
-
const compositions = await
|
|
112
|
+
const deploymentDir = import_node_path.default.join(rootDir, deployment.name);
|
|
113
|
+
const compositions = await import_promises.default.readdir(deploymentDir, {
|
|
391
114
|
withFileTypes: true
|
|
392
115
|
});
|
|
393
116
|
bundleDirs.push(
|
|
394
117
|
...compositions.filter(
|
|
395
118
|
(entry) => entry.isDirectory() && !entry.name.startsWith(".") && !entry.name.includes(".tmp-")
|
|
396
|
-
).map((entry) =>
|
|
119
|
+
).map((entry) => import_node_path.default.join(deploymentDir, entry.name))
|
|
397
120
|
);
|
|
398
121
|
}
|
|
399
122
|
return Promise.all(
|
|
@@ -435,17 +158,17 @@ var loadRuntimeEvidenceCompositionSnapshots = async ({
|
|
|
435
158
|
producer: snapshot.producer
|
|
436
159
|
});
|
|
437
160
|
}
|
|
438
|
-
const bundleDirs = await discoverRuntimeEvidenceBundles(publishRoot);
|
|
161
|
+
const bundleDirs = await (0, runtimeEvidenceArtifacts_exports.discoverRuntimeEvidenceBundles)(publishRoot);
|
|
439
162
|
for (const bundleDir of bundleDirs) {
|
|
440
|
-
const bundle = await verifyRuntimeEvidenceBundle(bundleDir);
|
|
441
|
-
const deployment = parseRuntimeEvidenceDeploymentSnapshot(
|
|
163
|
+
const bundle = await (0, runtimeEvidenceArtifacts_exports.verifyRuntimeEvidenceBundle)(bundleDir);
|
|
164
|
+
const deployment = (0, runtimeEvidenceDeployment_exports.parseRuntimeEvidenceDeploymentSnapshot)(
|
|
442
165
|
bundle.artifact.deployment
|
|
443
166
|
);
|
|
444
167
|
if (deployment.id !== currentDeployment.id) continue;
|
|
445
168
|
if (bundle.artifact.producer == null) continue;
|
|
446
169
|
register({
|
|
447
170
|
deployment: { ...deployment, tickers: void 0 },
|
|
448
|
-
producer: parseRuntimeEvidenceProducer(bundle.artifact.producer),
|
|
171
|
+
producer: (0, runtimeEvidenceProducer_exports.parseRuntimeEvidenceProducer)(bundle.artifact.producer),
|
|
449
172
|
// A historical composition may reappear through a position that closes
|
|
450
173
|
// in this window even without current-window lineage scopes. Its latest
|
|
451
174
|
// checksum-verified universe is only a fallback; fresh scopes win.
|
|
@@ -480,11 +203,11 @@ var rowTimestamp = (row) => {
|
|
|
480
203
|
return Number.POSITIVE_INFINITY;
|
|
481
204
|
};
|
|
482
205
|
var belongsToSnapshot = (row, deployment) => {
|
|
483
|
-
const strategy = activeRuntimeEvidenceStrategies(deployment).find(
|
|
206
|
+
const strategy = (0, runtimeEvidenceDeployment_exports.activeRuntimeEvidenceStrategies)(deployment).find(
|
|
484
207
|
(candidate) => candidate.strategyName === row.strategy
|
|
485
208
|
);
|
|
486
209
|
return Boolean(
|
|
487
|
-
strategy && row.deploymentId === deployment.id && row.accountId === deployment.accountId && runtimeLineageMatchesStrategySnapshot({
|
|
210
|
+
strategy && row.deploymentId === deployment.id && row.accountId === deployment.accountId && (0, runtimeEvidenceDeployment_exports.runtimeLineageMatchesStrategySnapshot)({
|
|
488
211
|
lineage: row.runtimeLineage ?? row.lineage,
|
|
489
212
|
deployment,
|
|
490
213
|
strategy
|