@tradejs/cli 3.1.27-beta.249 → 3.1.27

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 CHANGED
@@ -2185,9 +2185,9 @@ var init_features = __esm({
2185
2185
  "targetsymbol",
2186
2186
  "universe"
2187
2187
  ]);
2188
- normalizeFeaturePath = (path41) => (Array.isArray(path41) ? path41 : path41.split(".")).filter(Boolean).map((segment) => segment.toLowerCase());
2189
- classifyAiPocketCoverageFeaturePath = (path41) => {
2190
- const segments = normalizeFeaturePath(path41);
2188
+ normalizeFeaturePath = (path42) => (Array.isArray(path42) ? path42 : path42.split(".")).filter(Boolean).map((segment) => segment.toLowerCase());
2189
+ classifyAiPocketCoverageFeaturePath = (path42) => {
2190
+ const segments = normalizeFeaturePath(path42);
2191
2191
  const normalizedPath = segments.join(".");
2192
2192
  if (segments.some(
2193
2193
  (segment) => segment.includes("cmc") || segment.includes("coinmarketcap")
@@ -2361,8 +2361,8 @@ var init_features = __esm({
2361
2361
  "volumeusd",
2362
2362
  "vwap"
2363
2363
  ]);
2364
- classifyAiPocketFeaturePath = (path41) => {
2365
- const segments = (Array.isArray(path41) ? path41 : path41.split(".")).filter(
2364
+ classifyAiPocketFeaturePath = (path42) => {
2365
+ const segments = (Array.isArray(path42) ? path42 : path42.split(".")).filter(
2366
2366
  Boolean
2367
2367
  );
2368
2368
  const normalized = segments.map((segment) => segment.toLowerCase());
@@ -10693,27 +10693,27 @@ var init_coinMarketCapContextBackfill = __esm({
10693
10693
  totalCredits: 0,
10694
10694
  byPath: /* @__PURE__ */ new Map()
10695
10695
  });
10696
- getCoinMarketCapPathLabel = (path41) => {
10697
- if (path41.includes("global-metrics")) return "global";
10698
- if (path41.includes("cryptocurrency/quotes")) return "reference";
10699
- if (path41.includes("exchange/quotes")) return "exchangeLiquidity";
10700
- if (path41.includes("fear-and-greed")) return "fearGreed";
10701
- if (path41.includes("cmc100")) return "cmc100";
10702
- if (path41.includes("cmc20")) return "cmc20";
10703
- return path41;
10704
- };
10705
- recordCoinMarketCapFetchStats = (stats, path41, creditCount) => {
10696
+ getCoinMarketCapPathLabel = (path42) => {
10697
+ if (path42.includes("global-metrics")) return "global";
10698
+ if (path42.includes("cryptocurrency/quotes")) return "reference";
10699
+ if (path42.includes("exchange/quotes")) return "exchangeLiquidity";
10700
+ if (path42.includes("fear-and-greed")) return "fearGreed";
10701
+ if (path42.includes("cmc100")) return "cmc100";
10702
+ if (path42.includes("cmc20")) return "cmc20";
10703
+ return path42;
10704
+ };
10705
+ recordCoinMarketCapFetchStats = (stats, path42, creditCount) => {
10706
10706
  if (!stats) return;
10707
- const existing = stats.byPath.get(path41) ?? { requests: 0, credits: 0 };
10707
+ const existing = stats.byPath.get(path42) ?? { requests: 0, credits: 0 };
10708
10708
  existing.requests += 1;
10709
10709
  existing.credits += creditCount ?? 0;
10710
10710
  stats.requests += 1;
10711
10711
  stats.totalCredits += creditCount ?? 0;
10712
- stats.byPath.set(path41, existing);
10712
+ stats.byPath.set(path42, existing);
10713
10713
  };
10714
10714
  formatCoinMarketCapFetchStats = (stats) => {
10715
10715
  const byPath = [...stats.byPath.entries()].map(
10716
- ([path41, item]) => `${getCoinMarketCapPathLabel(path41)}=${item.requests}req/${item.credits}cr`
10716
+ ([path42, item]) => `${getCoinMarketCapPathLabel(path42)}=${item.requests}req/${item.credits}cr`
10717
10717
  ).join(" ");
10718
10718
  return `apiRequests=${stats.requests} apiCredits=${stats.totalCredits}${byPath ? ` ${byPath}` : ""}`;
10719
10719
  };
@@ -26625,12 +26625,228 @@ var init_runtimeFeedbackSync2 = __esm({
26625
26625
  }
26626
26626
  });
26627
26627
 
26628
+ // src/lib/runtimeEvidenceCompositionSnapshots.ts
26629
+ var import_node_crypto13, import_promises28, import_node_path24, SNAPSHOT_FILE, MANIFEST_FILE, COMPLETE_FILE, createRuntimeEvidenceCompositionSnapshotRecorder, isRecord4, sha2564, safeSegment6, isExistingDestinationError4, parseManifest3, verifyRuntimeEvidenceCompositionSnapshot, sameSnapshot, publishRuntimeEvidenceCompositionSnapshot, captureRuntimeEvidenceCompositionSnapshot, discoverRuntimeEvidenceCompositionSnapshots;
26630
+ var init_runtimeEvidenceCompositionSnapshots = __esm({
26631
+ "src/lib/runtimeEvidenceCompositionSnapshots.ts"() {
26632
+ "use strict";
26633
+ import_node_crypto13 = require("crypto");
26634
+ import_promises28 = __toESM(require("fs/promises"));
26635
+ import_node_path24 = __toESM(require("path"));
26636
+ init_runtimeEvidenceDeployment();
26637
+ init_runtimeEvidenceProducer();
26638
+ SNAPSHOT_FILE = "snapshot.json";
26639
+ MANIFEST_FILE = "manifest.json";
26640
+ COMPLETE_FILE = ".complete";
26641
+ createRuntimeEvidenceCompositionSnapshotRecorder = ({
26642
+ persist,
26643
+ onError
26644
+ }) => {
26645
+ const completed = /* @__PURE__ */ new Set();
26646
+ const inFlight = /* @__PURE__ */ new Set();
26647
+ return {
26648
+ observe(compositionId) {
26649
+ if (completed.has(compositionId) || inFlight.has(compositionId)) return;
26650
+ inFlight.add(compositionId);
26651
+ void Promise.resolve().then(() => persist(compositionId)).then(() => completed.add(compositionId)).catch((error) => onError(compositionId, error)).finally(() => inFlight.delete(compositionId));
26652
+ }
26653
+ };
26654
+ };
26655
+ isRecord4 = (value) => value != null && typeof value === "object" && !Array.isArray(value);
26656
+ sha2564 = (value) => (0, import_node_crypto13.createHash)("sha256").update(value).digest("hex");
26657
+ safeSegment6 = (value, label) => {
26658
+ const normalized = value.trim();
26659
+ if (!normalized || !/^[a-zA-Z0-9._:-]+$/.test(normalized)) {
26660
+ throw new Error(`Invalid runtime evidence snapshot ${label}`);
26661
+ }
26662
+ return normalized;
26663
+ };
26664
+ isExistingDestinationError4 = (error) => {
26665
+ const code = error.code;
26666
+ return code === "EEXIST" || code === "ENOTEMPTY";
26667
+ };
26668
+ parseManifest3 = (value) => {
26669
+ const manifest = isRecord4(value) ? value : null;
26670
+ const payload = isRecord4(manifest?.payload) ? manifest.payload : null;
26671
+ 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") {
26672
+ throw new Error("Invalid runtime evidence composition snapshot manifest");
26673
+ }
26674
+ return manifest;
26675
+ };
26676
+ verifyRuntimeEvidenceCompositionSnapshot = async (bundleDir) => {
26677
+ const [manifestText, payload, completeText] = await Promise.all([
26678
+ import_promises28.default.readFile(import_node_path24.default.join(bundleDir, MANIFEST_FILE), "utf8"),
26679
+ import_promises28.default.readFile(import_node_path24.default.join(bundleDir, SNAPSHOT_FILE)),
26680
+ import_promises28.default.readFile(import_node_path24.default.join(bundleDir, COMPLETE_FILE), "utf8")
26681
+ ]);
26682
+ const manifest = parseManifest3(JSON.parse(manifestText));
26683
+ if (completeText.trim() !== manifest.deploymentCompositionId) {
26684
+ throw new Error(`Invalid completion marker in ${bundleDir}`);
26685
+ }
26686
+ if (payload.byteLength !== manifest.payload.bytes || sha2564(payload) !== manifest.payload.sha256) {
26687
+ throw new Error(
26688
+ `Runtime evidence snapshot checksum mismatch in ${bundleDir}`
26689
+ );
26690
+ }
26691
+ const value = JSON.parse(payload.toString("utf8"));
26692
+ const record = isRecord4(value) ? value : null;
26693
+ if (record?.schemaVersion !== 1 || record.reportType !== "runtime-evidence-composition-snapshot" || record.userName !== manifest.userName) {
26694
+ throw new Error(
26695
+ `Invalid runtime evidence snapshot payload in ${bundleDir}`
26696
+ );
26697
+ }
26698
+ const deployment = parseRuntimeEvidenceDeploymentSnapshot(record.deployment);
26699
+ const producer = parseRuntimeEvidenceProducer(record.producer);
26700
+ if (deployment.id !== manifest.deploymentId || deployment.deploymentCompositionId !== manifest.deploymentCompositionId) {
26701
+ throw new Error(
26702
+ `Runtime evidence snapshot identity mismatch in ${bundleDir}`
26703
+ );
26704
+ }
26705
+ return { bundleDir, deployment, producer };
26706
+ };
26707
+ sameSnapshot = (snapshot, deployment, producer) => JSON.stringify(snapshot.deployment) === JSON.stringify(deployment) && JSON.stringify(snapshot.producer) === JSON.stringify(producer);
26708
+ publishRuntimeEvidenceCompositionSnapshot = async ({
26709
+ evidenceRoot,
26710
+ userName: userName3,
26711
+ deployment,
26712
+ producer
26713
+ }) => {
26714
+ const deploymentId = safeSegment6(deployment.id, "deployment id");
26715
+ const compositionId = safeSegment6(
26716
+ deployment.deploymentCompositionId,
26717
+ "composition id"
26718
+ );
26719
+ const createdAt = Date.now();
26720
+ const snapshot = {
26721
+ schemaVersion: 1,
26722
+ reportType: "runtime-evidence-composition-snapshot",
26723
+ createdAt,
26724
+ userName: userName3,
26725
+ deployment,
26726
+ producer
26727
+ };
26728
+ const payload = `${JSON.stringify(snapshot, null, 2)}
26729
+ `;
26730
+ const manifest = {
26731
+ schemaVersion: 1,
26732
+ reportType: "runtime-evidence-composition-snapshot",
26733
+ createdAt,
26734
+ userName: userName3,
26735
+ deploymentId,
26736
+ deploymentCompositionId: compositionId,
26737
+ payload: {
26738
+ file: SNAPSHOT_FILE,
26739
+ sha256: sha2564(payload),
26740
+ bytes: Buffer.byteLength(payload)
26741
+ }
26742
+ };
26743
+ const snapshotsRoot = import_node_path24.default.join(evidenceRoot, "snapshots", deploymentId);
26744
+ const bundleDir = import_node_path24.default.join(snapshotsRoot, compositionId);
26745
+ const temporaryDir = import_node_path24.default.join(
26746
+ evidenceRoot,
26747
+ "incoming",
26748
+ `snapshot-${compositionId}.tmp-${(0, import_node_crypto13.randomUUID)()}`
26749
+ );
26750
+ await import_promises28.default.mkdir(temporaryDir, { recursive: true });
26751
+ try {
26752
+ await Promise.all([
26753
+ import_promises28.default.writeFile(import_node_path24.default.join(temporaryDir, SNAPSHOT_FILE), payload, "utf8"),
26754
+ import_promises28.default.writeFile(
26755
+ import_node_path24.default.join(temporaryDir, MANIFEST_FILE),
26756
+ `${JSON.stringify(manifest, null, 2)}
26757
+ `,
26758
+ "utf8"
26759
+ )
26760
+ ]);
26761
+ await import_promises28.default.writeFile(
26762
+ import_node_path24.default.join(temporaryDir, COMPLETE_FILE),
26763
+ `${compositionId}
26764
+ `,
26765
+ "utf8"
26766
+ );
26767
+ await import_promises28.default.mkdir(snapshotsRoot, { recursive: true });
26768
+ try {
26769
+ await import_promises28.default.rename(temporaryDir, bundleDir);
26770
+ } catch (error) {
26771
+ if (!isExistingDestinationError4(error)) throw error;
26772
+ await import_promises28.default.rm(temporaryDir, { recursive: true, force: true });
26773
+ }
26774
+ } catch (error) {
26775
+ await import_promises28.default.rm(temporaryDir, { recursive: true, force: true });
26776
+ throw error;
26777
+ }
26778
+ const verified = await verifyRuntimeEvidenceCompositionSnapshot(bundleDir);
26779
+ if (!sameSnapshot(verified, deployment, producer)) {
26780
+ throw new Error(
26781
+ `Conflicting runtime evidence snapshot for composition ${compositionId}`
26782
+ );
26783
+ }
26784
+ return verified;
26785
+ };
26786
+ captureRuntimeEvidenceCompositionSnapshot = async ({
26787
+ projectRoot: projectRoot17,
26788
+ userName: userName3,
26789
+ deploymentId,
26790
+ expectedCompositionId
26791
+ }) => {
26792
+ const [deployment, producer] = await Promise.all([
26793
+ resolveRuntimeEvidenceDeploymentSnapshot({
26794
+ userName: userName3,
26795
+ projectRoot: projectRoot17,
26796
+ deploymentId
26797
+ }),
26798
+ resolveRuntimeEvidenceProducer({ projectRoot: projectRoot17, required: true })
26799
+ ]);
26800
+ if (!producer) {
26801
+ throw new Error("Runtime evidence producer identity is required");
26802
+ }
26803
+ if (deployment.deploymentCompositionId !== expectedCompositionId) {
26804
+ throw new Error(
26805
+ `Runtime deployment composition changed while capturing snapshot: expected ${expectedCompositionId}, received ${deployment.deploymentCompositionId}`
26806
+ );
26807
+ }
26808
+ await publishRuntimeEvidenceCompositionSnapshot({
26809
+ evidenceRoot: import_node_path24.default.join(projectRoot17, "data", "runtime-evidence"),
26810
+ userName: userName3,
26811
+ deployment,
26812
+ producer
26813
+ });
26814
+ };
26815
+ discoverRuntimeEvidenceCompositionSnapshots = async (evidenceRoot) => {
26816
+ const rootDir = import_node_path24.default.join(evidenceRoot, "snapshots");
26817
+ const bundleDirs = [];
26818
+ let deployments;
26819
+ try {
26820
+ deployments = await import_promises28.default.readdir(rootDir, { withFileTypes: true });
26821
+ } catch (error) {
26822
+ if (error.code === "ENOENT") return [];
26823
+ throw error;
26824
+ }
26825
+ for (const deployment of deployments.filter((entry) => entry.isDirectory())) {
26826
+ const deploymentDir = import_node_path24.default.join(rootDir, deployment.name);
26827
+ const compositions = await import_promises28.default.readdir(deploymentDir, {
26828
+ withFileTypes: true
26829
+ });
26830
+ bundleDirs.push(
26831
+ ...compositions.filter(
26832
+ (entry) => entry.isDirectory() && !entry.name.startsWith(".") && !entry.name.includes(".tmp-")
26833
+ ).map((entry) => import_node_path24.default.join(deploymentDir, entry.name))
26834
+ );
26835
+ }
26836
+ return Promise.all(
26837
+ bundleDirs.sort().map(verifyRuntimeEvidenceCompositionSnapshot)
26838
+ );
26839
+ };
26840
+ }
26841
+ });
26842
+
26628
26843
  // src/lib/runtimeEvidenceCompositions.ts
26629
26844
  var stableSnapshotIdentity, producerIdentity, loadRuntimeEvidenceCompositionSnapshots, rowCompositionId, rowTimestamp, belongsToSnapshot, splitRuntimeEvidenceByComposition;
26630
26845
  var init_runtimeEvidenceCompositions = __esm({
26631
26846
  "src/lib/runtimeEvidenceCompositions.ts"() {
26632
26847
  "use strict";
26633
26848
  init_runtimeEvidenceArtifacts();
26849
+ init_runtimeEvidenceCompositionSnapshots();
26634
26850
  init_runtimeEvidenceDeployment();
26635
26851
  init_runtimeEvidenceProducer();
26636
26852
  stableSnapshotIdentity = (deployment) => JSON.stringify({ ...deployment, tickers: void 0 });
@@ -26651,6 +26867,14 @@ var init_runtimeEvidenceCompositions = __esm({
26651
26867
  }
26652
26868
  snapshots.set(compositionId, snapshot);
26653
26869
  };
26870
+ const compositionSnapshots = await discoverRuntimeEvidenceCompositionSnapshots(publishRoot);
26871
+ for (const snapshot of compositionSnapshots) {
26872
+ if (snapshot.deployment.id !== currentDeployment.id) continue;
26873
+ register({
26874
+ deployment: { ...snapshot.deployment, tickers: void 0 },
26875
+ producer: snapshot.producer
26876
+ });
26877
+ }
26654
26878
  const bundleDirs = await discoverRuntimeEvidenceBundles(publishRoot);
26655
26879
  for (const bundleDir of bundleDirs) {
26656
26880
  const bundle = await verifyRuntimeEvidenceBundle(bundleDir);
@@ -26768,11 +26992,11 @@ var init_runtimeEvidenceCompositions = __esm({
26768
26992
  });
26769
26993
 
26770
26994
  // src/lib/runtimeLineage.ts
26771
- var import_node_crypto13, normalizeForStableJson2, resolveRuntimeMaxLossValue, fingerprintRuntimeValue, buildRuntimeLineage, runtimeLineageKey, runtimeLineagesMatch, runtimeLineagesComparable;
26995
+ var import_node_crypto14, normalizeForStableJson2, resolveRuntimeMaxLossValue, fingerprintRuntimeValue, buildRuntimeLineage, runtimeLineageKey, runtimeLineagesMatch, runtimeLineagesComparable;
26772
26996
  var init_runtimeLineage = __esm({
26773
26997
  "src/lib/runtimeLineage.ts"() {
26774
26998
  "use strict";
26775
- import_node_crypto13 = require("crypto");
26999
+ import_node_crypto14 = require("crypto");
26776
27000
  normalizeForStableJson2 = (value) => {
26777
27001
  if (Array.isArray(value)) {
26778
27002
  return value.map(normalizeForStableJson2);
@@ -26797,7 +27021,7 @@ var init_runtimeLineage = __esm({
26797
27021
  );
26798
27022
  return Number.isFinite(maxLossValue) ? maxLossValue : null;
26799
27023
  };
26800
- fingerprintRuntimeValue = (value) => (0, import_node_crypto13.createHash)("sha256").update(JSON.stringify(normalizeForStableJson2(value))).digest("hex").slice(0, 16);
27024
+ fingerprintRuntimeValue = (value) => (0, import_node_crypto14.createHash)("sha256").update(JSON.stringify(normalizeForStableJson2(value))).digest("hex").slice(0, 16);
26801
27025
  buildRuntimeLineage = async ({
26802
27026
  strategyRevision,
26803
27027
  deploymentCompositionId,
@@ -26851,12 +27075,12 @@ __export(runtimeEvidence_exports, {
26851
27075
  main: () => main36,
26852
27076
  runtimeEvidence: () => runtimeEvidence
26853
27077
  });
26854
- var import_promises28, import_node_path24, import_args28, import_chalk41, flags27, projectRoot11, toEpochMs3, resolveWindow2, parseStrategyFilter2, runtimeEvidence, main36;
27078
+ var import_promises29, import_node_path25, import_args28, import_chalk41, flags27, projectRoot11, toEpochMs3, resolveWindow2, parseStrategyFilter2, runtimeEvidence, main36;
26855
27079
  var init_runtimeEvidence = __esm({
26856
27080
  "src/scripts/runtimeEvidence.ts"() {
26857
27081
  "use strict";
26858
- import_promises28 = __toESM(require("fs/promises"));
26859
- import_node_path24 = __toESM(require("path"));
27082
+ import_promises29 = __toESM(require("fs/promises"));
27083
+ import_node_path25 = __toESM(require("path"));
26860
27084
  import_args28 = __toESM(require("args"));
26861
27085
  import_chalk41 = __toESM(require("chalk"));
26862
27086
  init_runtimeDebugEvidence();
@@ -26963,7 +27187,7 @@ var init_runtimeEvidence = __esm({
26963
27187
  deploymentId
26964
27188
  });
26965
27189
  const snapshots = publishDir && producer ? await loadRuntimeEvidenceCompositionSnapshots({
26966
- publishRoot: import_node_path24.default.resolve(projectRoot11, publishDir),
27190
+ publishRoot: import_node_path25.default.resolve(projectRoot11, publishDir),
26967
27191
  currentDeployment: deploymentSnapshot,
26968
27192
  currentProducer: producer
26969
27193
  }) : /* @__PURE__ */ new Map([
@@ -27036,14 +27260,14 @@ var init_runtimeEvidence = __esm({
27036
27260
  throw new Error("Runtime evidence window has no versioned runtime rows");
27037
27261
  }
27038
27262
  const artifact = current.artifact;
27039
- const outPath = import_node_path24.default.resolve(projectRoot11, String(flags27.out));
27040
- await import_promises28.default.mkdir(import_node_path24.default.dirname(outPath), { recursive: true });
27041
- await import_promises28.default.writeFile(outPath, `${JSON.stringify(artifact, null, 2)}
27263
+ const outPath = import_node_path25.default.resolve(projectRoot11, String(flags27.out));
27264
+ await import_promises29.default.mkdir(import_node_path25.default.dirname(outPath), { recursive: true });
27265
+ await import_promises29.default.writeFile(outPath, `${JSON.stringify(artifact, null, 2)}
27042
27266
  `, "utf8");
27043
27267
  const published = publishDir ? await Promise.all(
27044
27268
  artifacts.map(
27045
27269
  ({ artifact: artifact2, composition }) => publishRuntimeEvidenceBundle({
27046
- publishRoot: import_node_path24.default.resolve(projectRoot11, publishDir),
27270
+ publishRoot: import_node_path25.default.resolve(projectRoot11, publishDir),
27047
27271
  deploymentId,
27048
27272
  userName: String(flags27.user),
27049
27273
  startTime,
@@ -27089,11 +27313,11 @@ __export(runtimeEvidenceSync_exports, {
27089
27313
  main: () => main37,
27090
27314
  runtimeEvidenceSync: () => runtimeEvidenceSync
27091
27315
  });
27092
- var import_node_path25, import_args29, import_chalk42, flags28, projectRoot12, runtimeEvidenceSync, main37;
27316
+ var import_node_path26, import_args29, import_chalk42, flags28, projectRoot12, runtimeEvidenceSync, main37;
27093
27317
  var init_runtimeEvidenceSync2 = __esm({
27094
27318
  "src/scripts/runtimeEvidenceSync.ts"() {
27095
27319
  "use strict";
27096
- import_node_path25 = __toESM(require("path"));
27320
+ import_node_path26 = __toESM(require("path"));
27097
27321
  import_args29 = __toESM(require("args"));
27098
27322
  import_chalk42 = __toESM(require("chalk"));
27099
27323
  init_runtimeEvidenceSync();
@@ -27121,7 +27345,7 @@ var init_runtimeEvidenceSync2 = __esm({
27121
27345
  "Provide --source or RUNTIME_EVIDENCE_RSYNC_SOURCE for runtime evidence sync."
27122
27346
  );
27123
27347
  }
27124
- const evidenceRoot = import_node_path25.default.resolve(projectRoot12, String(flags28.dir));
27348
+ const evidenceRoot = import_node_path26.default.resolve(projectRoot12, String(flags28.dir));
27125
27349
  const result = await syncRuntimeEvidenceBundles({
27126
27350
  source,
27127
27351
  evidenceRoot,
@@ -28208,7 +28432,7 @@ async function collectReleaseEvidenceReferences(references) {
28208
28432
  let artifact;
28209
28433
  try {
28210
28434
  const parsed = JSON.parse(
28211
- await import_promises29.default.readFile(reference.path, "utf8")
28435
+ await import_promises30.default.readFile(reference.path, "utf8")
28212
28436
  );
28213
28437
  assert3(
28214
28438
  parsed != null && typeof parsed === "object" && !Array.isArray(parsed),
@@ -28355,13 +28579,13 @@ async function collectReleaseEvidenceReferences(references) {
28355
28579
  })
28356
28580
  );
28357
28581
  }
28358
- var import_node_crypto14, import_promises29, import_node_path26, import_types9, import_strategyReleaseEvidence2, SHA256_RE2, LINEAGE_FINGERPRINT_RE, STRATEGY_REVISION_RE, DEPLOYMENT_COMPOSITION_ID_RE, REQUIRED_LONG_WINDOWS, REQUIRED_DIAGNOSTIC_TERMINAL_WINDOWS, MIN_RECENT_DIRECTION_REPAIR_EVENTS, safeSegment6, compactTimestamp2, verifyFullPeriodChartArtifact, readVerifiedJsonArtifact, verifyResearchDecisionLineage, hasExactRuntimeTarget, deriveStrategyReleaseResearchDecision, canonicalStrategyReleaseJson, strategyReleaseSha256, assertFingerprint, assertLineageFingerprint, releaseReasons, deriveReleaseGates, verifyEvidenceComposition, createStrategyReleaseManifest, createStrategyReleaseEnvelope, verifyStrategyReleaseEnvelope, verifyStrategyEvidenceMarkerEnvelope, releaseMarkers, writeJsonAtomic2, publishStrategyRelease, publishStrategyLiveDiagnosis, finiteString3, finiteNumber6, finiteDirectionPolicy, uniqueStrings, incompleteEvidenceLineage, extractEvidenceLineage, verifyCompletedCoreResearchBundle;
28582
+ var import_node_crypto15, import_promises30, import_node_path27, import_types9, import_strategyReleaseEvidence2, SHA256_RE2, LINEAGE_FINGERPRINT_RE, STRATEGY_REVISION_RE, DEPLOYMENT_COMPOSITION_ID_RE, REQUIRED_LONG_WINDOWS, REQUIRED_DIAGNOSTIC_TERMINAL_WINDOWS, MIN_RECENT_DIRECTION_REPAIR_EVENTS, safeSegment7, compactTimestamp2, verifyFullPeriodChartArtifact, readVerifiedJsonArtifact, verifyResearchDecisionLineage, hasExactRuntimeTarget, deriveStrategyReleaseResearchDecision, canonicalStrategyReleaseJson, strategyReleaseSha256, assertFingerprint, assertLineageFingerprint, releaseReasons, deriveReleaseGates, verifyEvidenceComposition, createStrategyReleaseManifest, createStrategyReleaseEnvelope, verifyStrategyReleaseEnvelope, verifyStrategyEvidenceMarkerEnvelope, releaseMarkers, writeJsonAtomic2, publishStrategyRelease, publishStrategyLiveDiagnosis, finiteString3, finiteNumber6, finiteDirectionPolicy, uniqueStrings, incompleteEvidenceLineage, extractEvidenceLineage, verifyCompletedCoreResearchBundle;
28359
28583
  var init_strategyRelease = __esm({
28360
28584
  "src/lib/strategyRelease.ts"() {
28361
28585
  "use strict";
28362
- import_node_crypto14 = require("crypto");
28363
- import_promises29 = __toESM(require("fs/promises"));
28364
- import_node_path26 = __toESM(require("path"));
28586
+ import_node_crypto15 = require("crypto");
28587
+ import_promises30 = __toESM(require("fs/promises"));
28588
+ import_node_path27 = __toESM(require("path"));
28365
28589
  import_types9 = require("@tradejs/types");
28366
28590
  import_strategyReleaseEvidence2 = require("@tradejs/infra/strategyReleaseEvidence");
28367
28591
  init_liveDiagnosis();
@@ -28374,17 +28598,17 @@ var init_strategyRelease = __esm({
28374
28598
  REQUIRED_LONG_WINDOWS = [1095, 1460, 1825];
28375
28599
  REQUIRED_DIAGNOSTIC_TERMINAL_WINDOWS = [365, 180, 90];
28376
28600
  MIN_RECENT_DIRECTION_REPAIR_EVENTS = 20;
28377
- safeSegment6 = import_strategyReleaseEvidence2.safeStrategyEvidenceSegment;
28601
+ safeSegment7 = import_strategyReleaseEvidence2.safeStrategyEvidenceSegment;
28378
28602
  compactTimestamp2 = import_strategyReleaseEvidence2.compactStrategyEvidenceTimestamp;
28379
28603
  verifyFullPeriodChartArtifact = async (input) => {
28380
28604
  const artifact = input.chartArtifact;
28381
28605
  if (!artifact?.path || !SHA256_RE2.test(artifact.sha256)) return false;
28382
28606
  try {
28383
- const artifactPath = import_node_path26.default.resolve(artifact.path);
28607
+ const artifactPath = import_node_path27.default.resolve(artifact.path);
28384
28608
  if (await (0, import_strategyReleaseEvidence2.strategyEvidenceFileSha256)(artifactPath) !== artifact.sha256) {
28385
28609
  return false;
28386
28610
  }
28387
- const report = JSON.parse(await import_promises29.default.readFile(artifactPath, "utf8"));
28611
+ const report = JSON.parse(await import_promises30.default.readFile(artifactPath, "utf8"));
28388
28612
  return Boolean(
28389
28613
  report.chart?.persisted === true && report.chart.cardIds?.length && report.errors?.failed === 0 && report.run?.strategy === input.strategy && report.run.mode === "local-deterministic" && report.run.recent === 0 && report.run.since == null && report.run.until == null && Number(report.run.sourceRows) > 0
28390
28614
  );
@@ -28395,11 +28619,11 @@ var init_strategyRelease = __esm({
28395
28619
  readVerifiedJsonArtifact = async (artifact) => {
28396
28620
  if (!artifact?.path || !SHA256_RE2.test(artifact.sha256)) return null;
28397
28621
  try {
28398
- const artifactPath = import_node_path26.default.resolve(artifact.path);
28622
+ const artifactPath = import_node_path27.default.resolve(artifact.path);
28399
28623
  if (await (0, import_strategyReleaseEvidence2.strategyEvidenceFileSha256)(artifactPath) !== artifact.sha256) {
28400
28624
  return null;
28401
28625
  }
28402
- return JSON.parse(await import_promises29.default.readFile(artifactPath, "utf8"));
28626
+ return JSON.parse(await import_promises30.default.readFile(artifactPath, "utf8"));
28403
28627
  } catch {
28404
28628
  return null;
28405
28629
  }
@@ -28890,7 +29114,7 @@ var init_strategyRelease = __esm({
28890
29114
  maxLossValue: input.composition.maxLossValue,
28891
29115
  ...input.composition.directionPolicy == null ? {} : { directionPolicy: input.composition.directionPolicy }
28892
29116
  };
28893
- const compositionId = `${safeSegment6(input.strategy, "strategy")}_${strategyReleaseSha256(compositionIdentity).slice(0, 16)}`;
29117
+ const compositionId = `${safeSegment7(input.strategy, "strategy")}_${strategyReleaseSha256(compositionIdentity).slice(0, 16)}`;
28894
29118
  const reasons = releaseReasons({ ...input, gates: evidenceGates });
28895
29119
  const economicFailure = reasons.some(
28896
29120
  (reason) => [
@@ -28912,16 +29136,16 @@ var init_strategyRelease = __esm({
28912
29136
  strategy: input.strategy,
28913
29137
  createdAt: input.createdAt,
28914
29138
  compositionId,
28915
- evidence: input.evidence.map(({ kind, artifactId, sha256: sha2564 }) => ({
29139
+ evidence: input.evidence.map(({ kind, artifactId, sha256: sha2565 }) => ({
28916
29140
  kind,
28917
29141
  artifactId,
28918
- sha256: sha2564
29142
+ sha256: sha2565
28919
29143
  })),
28920
29144
  verdict
28921
29145
  };
28922
29146
  return {
28923
29147
  schema: import_types9.STRATEGY_RELEASE_SCHEMA,
28924
- releaseId: `${safeSegment6(input.strategy, "strategy")}_${compactTimestamp2(input.createdAt)}_${strategyReleaseSha256(releaseIdentity).slice(0, 16)}`,
29148
+ releaseId: `${safeSegment7(input.strategy, "strategy")}_${compactTimestamp2(input.createdAt)}_${strategyReleaseSha256(releaseIdentity).slice(0, 16)}`,
28925
29149
  strategy: input.strategy,
28926
29150
  createdAt: input.createdAt,
28927
29151
  composition: { ...input.composition, compositionId },
@@ -28945,7 +29169,7 @@ var init_strategyRelease = __esm({
28945
29169
  manifest
28946
29170
  });
28947
29171
  verifyStrategyReleaseEnvelope = async (valueOrPath) => {
28948
- const value = typeof valueOrPath === "string" ? JSON.parse(await import_promises29.default.readFile(valueOrPath, "utf8")) : valueOrPath;
29172
+ const value = typeof valueOrPath === "string" ? JSON.parse(await import_promises30.default.readFile(valueOrPath, "utf8")) : valueOrPath;
28949
29173
  const envelope = value;
28950
29174
  assert3(
28951
29175
  envelope?.schema === "tradejs-strategy-release-envelope/v1",
@@ -28996,7 +29220,7 @@ var init_strategyRelease = __esm({
28996
29220
  return envelope;
28997
29221
  };
28998
29222
  verifyStrategyEvidenceMarkerEnvelope = async (valueOrPath) => {
28999
- const value = typeof valueOrPath === "string" ? JSON.parse(await import_promises29.default.readFile(valueOrPath, "utf8")) : valueOrPath;
29223
+ const value = typeof valueOrPath === "string" ? JSON.parse(await import_promises30.default.readFile(valueOrPath, "utf8")) : valueOrPath;
29000
29224
  return (0, import_strategyReleaseEvidence2.verifyStrategyEvidenceMarkerEnvelope)(value);
29001
29225
  };
29002
29226
  releaseMarkers = (manifest) => {
@@ -29058,14 +29282,14 @@ var init_strategyRelease = __esm({
29058
29282
  };
29059
29283
  writeJsonAtomic2 = async (filePath, value) => {
29060
29284
  const temporaryPath = `${filePath}.${process.pid}.${Date.now()}.tmp`;
29061
- await import_promises29.default.mkdir(import_node_path26.default.dirname(filePath), { recursive: true });
29062
- await import_promises29.default.writeFile(
29285
+ await import_promises30.default.mkdir(import_node_path27.default.dirname(filePath), { recursive: true });
29286
+ await import_promises30.default.writeFile(
29063
29287
  temporaryPath,
29064
29288
  `${canonicalStrategyReleaseJson(value)}
29065
29289
  `,
29066
29290
  "utf8"
29067
29291
  );
29068
- await import_promises29.default.rename(temporaryPath, filePath);
29292
+ await import_promises30.default.rename(temporaryPath, filePath);
29069
29293
  };
29070
29294
  publishStrategyRelease = async ({
29071
29295
  rootDir,
@@ -29082,16 +29306,16 @@ var init_strategyRelease = __esm({
29082
29306
  path: entry.path
29083
29307
  }))
29084
29308
  });
29085
- const releasePath = import_node_path26.default.join(
29309
+ const releasePath = import_node_path27.default.join(
29086
29310
  rootDir,
29087
29311
  "releases",
29088
- safeSegment6(manifest.strategy, "strategy"),
29312
+ safeSegment7(manifest.strategy, "strategy"),
29089
29313
  `${manifest.releaseId}.json`
29090
29314
  );
29091
- const markerPath = import_node_path26.default.join(
29315
+ const markerPath = import_node_path27.default.join(
29092
29316
  rootDir,
29093
29317
  "markers",
29094
- safeSegment6(manifest.strategy, "strategy"),
29318
+ safeSegment7(manifest.strategy, "strategy"),
29095
29319
  `${markerEnvelope.artifactId}.json`
29096
29320
  );
29097
29321
  await Promise.all([
@@ -29111,7 +29335,7 @@ var init_strategyRelease = __esm({
29111
29335
  composition
29112
29336
  }) => {
29113
29337
  const diagnosisSha256 = strategyReleaseSha256(diagnosis);
29114
- const diagnosisId = `${safeSegment6(diagnosis.strategy, "strategy")}_${compactTimestamp2(diagnosis.createdAt)}_${diagnosisSha256.slice(0, 16)}`;
29338
+ const diagnosisId = `${safeSegment7(diagnosis.strategy, "strategy")}_${compactTimestamp2(diagnosis.createdAt)}_${diagnosisSha256.slice(0, 16)}`;
29115
29339
  const envelope = {
29116
29340
  schema: "tradejs-strategy-live-diagnosis-envelope/v1",
29117
29341
  diagnosisId,
@@ -29168,16 +29392,16 @@ var init_strategyRelease = __esm({
29168
29392
  markers,
29169
29393
  sourceArtifacts
29170
29394
  });
29171
- const diagnosisPath = import_node_path26.default.join(
29395
+ const diagnosisPath = import_node_path27.default.join(
29172
29396
  rootDir,
29173
29397
  "diagnoses",
29174
- safeSegment6(diagnosis.strategy, "strategy"),
29398
+ safeSegment7(diagnosis.strategy, "strategy"),
29175
29399
  `${diagnosisId}.json`
29176
29400
  );
29177
- const markerPath = import_node_path26.default.join(
29401
+ const markerPath = import_node_path27.default.join(
29178
29402
  rootDir,
29179
29403
  "markers",
29180
- safeSegment6(diagnosis.strategy, "strategy"),
29404
+ safeSegment7(diagnosis.strategy, "strategy"),
29181
29405
  `${markerEnvelope.artifactId}.json`
29182
29406
  );
29183
29407
  await Promise.all([
@@ -29364,11 +29588,11 @@ var init_strategyRelease = __esm({
29364
29588
  const specSha256 = finiteString3(artifact.specSha256);
29365
29589
  assert3(researchId != null, "core result researchId is required");
29366
29590
  assert3(specSha256 != null, "core result specSha256 is required");
29367
- const researchDir = import_node_path26.default.dirname(resultPath);
29368
- const manifestPath = import_node_path26.default.join(researchDir, "manifest.json");
29369
- const specPath = import_node_path26.default.join(researchDir, "spec.json");
29370
- const manifestBytes = await import_promises29.default.readFile(manifestPath).catch(() => null);
29371
- const specBytes = await import_promises29.default.readFile(specPath).catch(() => null);
29591
+ const researchDir = import_node_path27.default.dirname(resultPath);
29592
+ const manifestPath = import_node_path27.default.join(researchDir, "manifest.json");
29593
+ const specPath = import_node_path27.default.join(researchDir, "spec.json");
29594
+ const manifestBytes = await import_promises30.default.readFile(manifestPath).catch(() => null);
29595
+ const specBytes = await import_promises30.default.readFile(specPath).catch(() => null);
29372
29596
  assert3(
29373
29597
  manifestBytes != null && specBytes != null,
29374
29598
  "core result must belong to a completed core research bundle"
@@ -29377,14 +29601,14 @@ var init_strategyRelease = __esm({
29377
29601
  const artifactHashes = manifest.artifactHashes != null && typeof manifest.artifactHashes === "object" && !Array.isArray(manifest.artifactHashes) ? manifest.artifactHashes : null;
29378
29602
  const parsedSpec = JSON.parse(specBytes.toString("utf8"));
29379
29603
  assert3(
29380
- manifest.schema === "tradejs-core-research-manifest/v1" && manifest.status === "completed" && manifest.researchId === researchId && manifest.specSha256 === specSha256 && artifactHashes?.["result.json"] === resultSha256 && (0, import_node_crypto14.createHash)("sha256").update(canonicalStrategyReleaseJson(parsedSpec)).digest("hex") === specSha256,
29604
+ manifest.schema === "tradejs-core-research-manifest/v1" && manifest.status === "completed" && manifest.researchId === researchId && manifest.specSha256 === specSha256 && artifactHashes?.["result.json"] === resultSha256 && (0, import_node_crypto15.createHash)("sha256").update(canonicalStrategyReleaseJson(parsedSpec)).digest("hex") === specSha256,
29381
29605
  "core result is not bound by its completed core research manifest"
29382
29606
  );
29383
29607
  for (const [relativePath, expectedSha256] of Object.entries(
29384
29608
  artifactHashes ?? {}
29385
29609
  )) {
29386
29610
  assert3(
29387
- !import_node_path26.default.isAbsolute(relativePath) && !relativePath.split(/[\\/]/).includes(".."),
29611
+ !import_node_path27.default.isAbsolute(relativePath) && !relativePath.split(/[\\/]/).includes(".."),
29388
29612
  `core bundle artifact ${relativePath} escapes its research directory`
29389
29613
  );
29390
29614
  assert3(
@@ -29392,7 +29616,7 @@ var init_strategyRelease = __esm({
29392
29616
  `core bundle artifact ${relativePath} has an invalid checksum`
29393
29617
  );
29394
29618
  const actualSha256 = await (0, import_strategyReleaseEvidence2.strategyEvidenceFileSha256)(
29395
- import_node_path26.default.join(researchDir, relativePath)
29619
+ import_node_path27.default.join(researchDir, relativePath)
29396
29620
  );
29397
29621
  assert3(
29398
29622
  actualSha256 === expectedSha256,
@@ -29409,13 +29633,13 @@ __export(runtimeScorecard_exports, {
29409
29633
  main: () => main38,
29410
29634
  runtimeScorecard: () => runtimeScorecard
29411
29635
  });
29412
- var import_promises30, import_node_crypto15, import_node_path27, import_args30, import_chalk43, flags29, projectRoot13, resolveOptionalPath, readJson, assertReportType, sha256File2, loadHistoryArtifacts, runtimeScorecard, main38;
29636
+ var import_promises31, import_node_crypto16, import_node_path28, import_args30, import_chalk43, flags29, projectRoot13, resolveOptionalPath, readJson, assertReportType, sha256File2, loadHistoryArtifacts, runtimeScorecard, main38;
29413
29637
  var init_runtimeScorecard2 = __esm({
29414
29638
  "src/scripts/runtimeScorecard.ts"() {
29415
29639
  "use strict";
29416
- import_promises30 = __toESM(require("fs/promises"));
29417
- import_node_crypto15 = require("crypto");
29418
- import_node_path27 = __toESM(require("path"));
29640
+ import_promises31 = __toESM(require("fs/promises"));
29641
+ import_node_crypto16 = require("crypto");
29642
+ import_node_path28 = __toESM(require("path"));
29419
29643
  import_args30 = __toESM(require("args"));
29420
29644
  import_chalk43 = __toESM(require("chalk"));
29421
29645
  init_runtimeEvidenceArtifacts();
@@ -29485,15 +29709,15 @@ var init_runtimeScorecard2 = __esm({
29485
29709
  projectRoot13 = String(process.env.PROJECT_CWD || process.cwd()).trim() || process.cwd();
29486
29710
  resolveOptionalPath = (value) => {
29487
29711
  const raw = String(value ?? "").trim();
29488
- return raw ? import_node_path27.default.resolve(projectRoot13, raw) : null;
29712
+ return raw ? import_node_path28.default.resolve(projectRoot13, raw) : null;
29489
29713
  };
29490
- readJson = async (filePath) => filePath ? JSON.parse(await import_promises30.default.readFile(filePath, "utf8")) : void 0;
29714
+ readJson = async (filePath) => filePath ? JSON.parse(await import_promises31.default.readFile(filePath, "utf8")) : void 0;
29491
29715
  assertReportType = (artifact, expected, label) => {
29492
29716
  if (artifact != null && (!artifact || typeof artifact !== "object" || Array.isArray(artifact) || artifact.reportType !== expected)) {
29493
29717
  throw new Error(`${label} must be a ${expected} artifact`);
29494
29718
  }
29495
29719
  };
29496
- sha256File2 = async (filePath) => (0, import_node_crypto15.createHash)("sha256").update(await import_promises30.default.readFile(filePath)).digest("hex");
29720
+ sha256File2 = async (filePath) => (0, import_node_crypto16.createHash)("sha256").update(await import_promises31.default.readFile(filePath)).digest("hex");
29497
29721
  loadHistoryArtifacts = async (historyDir) => {
29498
29722
  if (!historyDir) return [];
29499
29723
  const bundleDirs = await discoverRuntimeEvidenceBundles(historyDir);
@@ -29564,13 +29788,13 @@ var init_runtimeScorecard2 = __esm({
29564
29788
  strategy: scorecardStrategy,
29565
29789
  llmComparatorPolicy: verifiedRelease?.manifest.prospective.llmComparatorPolicy ?? "ai_approved_only"
29566
29790
  });
29567
- const outPath = import_node_path27.default.resolve(projectRoot13, String(flags29.out));
29791
+ const outPath = import_node_path28.default.resolve(projectRoot13, String(flags29.out));
29568
29792
  const markdownPath = outPath.replace(/\.json$/i, "") + ".md";
29569
- await import_promises30.default.mkdir(import_node_path27.default.dirname(outPath), { recursive: true });
29793
+ await import_promises31.default.mkdir(import_node_path28.default.dirname(outPath), { recursive: true });
29570
29794
  await Promise.all([
29571
- import_promises30.default.writeFile(outPath, `${JSON.stringify(scorecard, null, 2)}
29795
+ import_promises31.default.writeFile(outPath, `${JSON.stringify(scorecard, null, 2)}
29572
29796
  `, "utf8"),
29573
- import_promises30.default.writeFile(
29797
+ import_promises31.default.writeFile(
29574
29798
  markdownPath,
29575
29799
  formatRuntimeScorecardMarkdown(scorecard),
29576
29800
  "utf8"
@@ -29584,7 +29808,7 @@ var init_runtimeScorecard2 = __esm({
29584
29808
  const diagnosisPath = diagnosis ? outPath.replace(/\.json$/i, "") + ".diagnosis.json" : null;
29585
29809
  const strategyReleaseRoot = resolveOptionalPath(flags29.strategyReleaseRoot);
29586
29810
  if (diagnosis && diagnosisPath) {
29587
- await import_promises30.default.writeFile(
29811
+ await import_promises31.default.writeFile(
29588
29812
  diagnosisPath,
29589
29813
  `${JSON.stringify(diagnosis, null, 2)}
29590
29814
  `,
@@ -29605,7 +29829,7 @@ var init_runtimeScorecard2 = __esm({
29605
29829
  composition: verifiedRelease?.manifest.composition,
29606
29830
  sourceArtifacts: await Promise.all(
29607
29831
  sourcePaths.map(async (sourcePath) => ({
29608
- artifactId: import_node_path27.default.basename(sourcePath),
29832
+ artifactId: import_node_path28.default.basename(sourcePath),
29609
29833
  path: sourcePath,
29610
29834
  sha256: await sha256File2(sourcePath)
29611
29835
  }))
@@ -29616,11 +29840,11 @@ var init_runtimeScorecard2 = __esm({
29616
29840
  let receiptPath2 = null;
29617
29841
  if (flags29.markProcessed) {
29618
29842
  const runtimeEvidenceBundle = await verifyRuntimeEvidenceBundle(
29619
- import_node_path27.default.dirname(runtimeEvidencePath)
29843
+ import_node_path28.default.dirname(runtimeEvidencePath)
29620
29844
  );
29621
29845
  const feedbackSource = replayEvidencePath ? await verifyRuntimeFeedbackReplaySource({
29622
- bundleDir: import_node_path27.default.dirname(replayEvidencePath),
29623
- runtimeEvidenceBundleDir: import_node_path27.default.dirname(runtimeEvidencePath)
29846
+ bundleDir: import_node_path28.default.dirname(replayEvidencePath),
29847
+ runtimeEvidenceBundleDir: import_node_path28.default.dirname(runtimeEvidencePath)
29624
29848
  }).catch((error) => {
29625
29849
  if (runtimeEvidenceBundle.artifact.producer) throw error;
29626
29850
  return null;
@@ -29631,9 +29855,9 @@ var init_runtimeScorecard2 = __esm({
29631
29855
  );
29632
29856
  }
29633
29857
  receiptPath2 = await markRuntimeEvidenceBundleProcessed({
29634
- evidenceRoot: import_node_path27.default.resolve(projectRoot13, String(flags29.evidenceDir)),
29858
+ evidenceRoot: import_node_path28.default.resolve(projectRoot13, String(flags29.evidenceDir)),
29635
29859
  deploymentId: String(flags29.deployment),
29636
- bundleDir: import_node_path27.default.dirname(runtimeEvidencePath),
29860
+ bundleDir: import_node_path28.default.dirname(runtimeEvidencePath),
29637
29861
  scorecardPath: outPath,
29638
29862
  runtimeFeedback: feedbackSource ? {
29639
29863
  artifactId: feedbackSource.feedback.manifest.artifactId,
@@ -29830,14 +30054,14 @@ __export(strategyRelease_exports, {
29830
30054
  main: () => main40,
29831
30055
  runStrategyReleaseCommand: () => runStrategyReleaseCommand
29832
30056
  });
29833
- var import_promises31, import_node_fs5, import_node_readline2, import_node_path28, import_chalk44, valueAfter2, required3, writeJsonAtomic3, runStrategyReleaseCommand, printUsage2, main40;
30057
+ var import_promises32, import_node_fs5, import_node_readline2, import_node_path29, import_chalk44, valueAfter2, required3, writeJsonAtomic3, runStrategyReleaseCommand, printUsage2, main40;
29834
30058
  var init_strategyRelease2 = __esm({
29835
30059
  "src/scripts/strategyRelease.ts"() {
29836
30060
  "use strict";
29837
- import_promises31 = __toESM(require("fs/promises"));
30061
+ import_promises32 = __toESM(require("fs/promises"));
29838
30062
  import_node_fs5 = require("fs");
29839
30063
  import_node_readline2 = require("readline");
29840
- import_node_path28 = __toESM(require("path"));
30064
+ import_node_path29 = __toESM(require("path"));
29841
30065
  import_chalk44 = __toESM(require("chalk"));
29842
30066
  init_strategyRelease();
29843
30067
  valueAfter2 = (argv2, name) => {
@@ -29850,17 +30074,17 @@ var init_strategyRelease2 = __esm({
29850
30074
  };
29851
30075
  writeJsonAtomic3 = async (filePath, value) => {
29852
30076
  const temporaryPath = `${filePath}.${process.pid}.${Date.now()}.tmp`;
29853
- await import_promises31.default.mkdir(import_node_path28.default.dirname(filePath), { recursive: true });
29854
- await import_promises31.default.writeFile(
30077
+ await import_promises32.default.mkdir(import_node_path29.default.dirname(filePath), { recursive: true });
30078
+ await import_promises32.default.writeFile(
29855
30079
  temporaryPath,
29856
30080
  `${JSON.stringify(value, null, 2)}
29857
30081
  `,
29858
30082
  "utf8"
29859
30083
  );
29860
- await import_promises31.default.rename(temporaryPath, filePath);
30084
+ await import_promises32.default.rename(temporaryPath, filePath);
29861
30085
  };
29862
30086
  runStrategyReleaseCommand = async (options) => {
29863
- const inputPath = import_node_path28.default.resolve(options.inputPath);
30087
+ const inputPath = import_node_path29.default.resolve(options.inputPath);
29864
30088
  if (options.command === "verify") {
29865
30089
  const envelope = await verifyStrategyReleaseEnvelope(inputPath);
29866
30090
  return {
@@ -29898,7 +30122,7 @@ var init_strategyRelease2 = __esm({
29898
30122
  endTime,
29899
30123
  days: options.days?.length ? options.days : [7, 30, 90]
29900
30124
  });
29901
- const outputPath = import_node_path28.default.resolve(
30125
+ const outputPath = import_node_path29.default.resolve(
29902
30126
  options.outputPath ?? "output/strategy-monitoring-profile.json"
29903
30127
  );
29904
30128
  await writeJsonAtomic3(outputPath, profile);
@@ -29909,22 +30133,22 @@ var init_strategyRelease2 = __esm({
29909
30133
  profile
29910
30134
  };
29911
30135
  }
29912
- const input = JSON.parse(await import_promises31.default.readFile(inputPath, "utf8"));
30136
+ const input = JSON.parse(await import_promises32.default.readFile(inputPath, "utf8"));
29913
30137
  if (options.command === "decide") {
29914
30138
  const decision = await deriveStrategyReleaseResearchDecision(input);
29915
30139
  if (options.outputPath) {
29916
- await writeJsonAtomic3(import_node_path28.default.resolve(options.outputPath), decision);
30140
+ await writeJsonAtomic3(import_node_path29.default.resolve(options.outputPath), decision);
29917
30141
  }
29918
30142
  return {
29919
30143
  kind: "decided",
29920
30144
  ...decision,
29921
- outputPath: options.outputPath ? import_node_path28.default.resolve(options.outputPath) : null
30145
+ outputPath: options.outputPath ? import_node_path29.default.resolve(options.outputPath) : null
29922
30146
  };
29923
30147
  }
29924
30148
  if (options.command === "retention") {
29925
30149
  const plan = planStrategyEvidenceRetention(input);
29926
30150
  if (options.apply) {
29927
- await Promise.all(plan.delete.map((entry) => import_promises31.default.rm(entry.path)));
30151
+ await Promise.all(plan.delete.map((entry) => import_promises32.default.rm(entry.path)));
29928
30152
  }
29929
30153
  return {
29930
30154
  kind: "retention",
@@ -29937,12 +30161,12 @@ var init_strategyRelease2 = __esm({
29937
30161
  }
29938
30162
  if (options.command === "diagnose") {
29939
30163
  const diagnosis = buildStrategyLiveDiagnosis(input);
29940
- const outputPath = import_node_path28.default.resolve(
30164
+ const outputPath = import_node_path29.default.resolve(
29941
30165
  options.outputPath ?? "output/strategy-live-diagnosis.json"
29942
30166
  );
29943
30167
  await writeJsonAtomic3(outputPath, diagnosis);
29944
30168
  const published2 = options.rootDir ? await publishStrategyLiveDiagnosis({
29945
- rootDir: import_node_path28.default.resolve(options.rootDir),
30169
+ rootDir: import_node_path29.default.resolve(options.rootDir),
29946
30170
  diagnosis,
29947
30171
  sourceArtifacts: input.sourceArtifacts ?? []
29948
30172
  }) : null;
@@ -29959,7 +30183,7 @@ var init_strategyRelease2 = __esm({
29959
30183
  evidence: await collectReleaseEvidenceReferences(input.evidence ?? [])
29960
30184
  });
29961
30185
  const published = await publishStrategyRelease({
29962
- rootDir: import_node_path28.default.resolve(options.rootDir ?? "data/strategy-release"),
30186
+ rootDir: import_node_path29.default.resolve(options.rootDir ?? "data/strategy-release"),
29963
30187
  manifest
29964
30188
  });
29965
30189
  return {
@@ -30061,21 +30285,21 @@ var init_serverHealth = __esm({
30061
30285
  }
30062
30286
  return `${minutes}m`;
30063
30287
  };
30064
- readDiskUsage = (path41) => {
30288
+ readDiskUsage = (path42) => {
30065
30289
  try {
30066
- const stats = (0, import_node_fs6.statfsSync)(path41);
30290
+ const stats = (0, import_node_fs6.statfsSync)(path42);
30067
30291
  const totalBlocks = Number(stats.blocks ?? 0);
30068
30292
  const availableBlocks = Number(stats.bavail ?? 0);
30069
30293
  if (totalBlocks <= 0) {
30070
- return { path: path41, usedPct: null };
30294
+ return { path: path42, usedPct: null };
30071
30295
  }
30072
30296
  const usedPct = (totalBlocks - Math.max(0, availableBlocks)) / totalBlocks * 100;
30073
30297
  return {
30074
- path: path41,
30298
+ path: path42,
30075
30299
  usedPct: Number.isFinite(usedPct) ? usedPct : null
30076
30300
  };
30077
30301
  } catch {
30078
- return { path: path41, usedPct: null };
30302
+ return { path: path42, usedPct: null };
30079
30303
  }
30080
30304
  };
30081
30305
  parseMeminfoBytes = (value) => {
@@ -32183,12 +32407,12 @@ __export(runtimeParity_exports, {
32183
32407
  main: () => main42,
32184
32408
  runtimeParity: () => runtimeParity
32185
32409
  });
32186
- var import_config11, import_node_crypto16, import_args32, import_chalk46, import_constants15, import_time9, import_logger6, import_redis17, import_cli11, import_backtest3, import_connectors14, flags30, interval3, projectRoot15, DEFAULT_LOOKBACK_DAYS, DETAIL_LIMIT2, DEFAULT_REPLAY_ENV, resolveParityConnectorName, createConnector, buildReplayAiAnalyses, formatReplayEnvSummary, buildReplayConfig, warmReplayHistory, runtimeParity, main42;
32410
+ var import_config11, import_node_crypto17, import_args32, import_chalk46, import_constants15, import_time9, import_logger6, import_redis17, import_cli11, import_backtest3, import_connectors14, flags30, interval3, projectRoot15, DEFAULT_LOOKBACK_DAYS, DETAIL_LIMIT2, DEFAULT_REPLAY_ENV, resolveParityConnectorName, createConnector, buildReplayAiAnalyses, formatReplayEnvSummary, buildReplayConfig, warmReplayHistory, runtimeParity, main42;
32187
32411
  var init_runtimeParity2 = __esm({
32188
32412
  "src/scripts/runtimeParity.ts"() {
32189
32413
  "use strict";
32190
32414
  import_config11 = require("dotenv/config");
32191
- import_node_crypto16 = require("crypto");
32415
+ import_node_crypto17 = require("crypto");
32192
32416
  import_args32 = __toESM(require("args"));
32193
32417
  import_chalk46 = __toESM(require("chalk"));
32194
32418
  import_constants15 = require("@tradejs/core/constants");
@@ -32571,9 +32795,9 @@ var init_runtimeParity2 = __esm({
32571
32795
  start: window.start,
32572
32796
  end: window.end
32573
32797
  },
32574
- name: `${target.symbol}_${target.strategy}_${(0, import_node_crypto16.randomUUID)().slice(0, 8)}`,
32575
- testId: (0, import_node_crypto16.randomUUID)().slice(0, 8),
32576
- testSuiteId: (0, import_node_crypto16.randomUUID)().slice(0, 8),
32798
+ name: `${target.symbol}_${target.strategy}_${(0, import_node_crypto17.randomUUID)().slice(0, 8)}`,
32799
+ testId: (0, import_node_crypto17.randomUUID)().slice(0, 8),
32800
+ testSuiteId: (0, import_node_crypto17.randomUUID)().slice(0, 8),
32577
32801
  strategyName: target.strategy,
32578
32802
  strategyConfig: replayConfig,
32579
32803
  connectorName,
@@ -33812,6 +34036,7 @@ var init_runner = __esm({
33812
34036
  init_klineFeed();
33813
34037
  init_tickerEvaluator();
33814
34038
  init_configuredScopes();
34039
+ init_runtimeEvidenceCompositionSnapshots();
33815
34040
  SLOW_SIGNALS_WARNING_MS = 10 * 6e4;
33816
34041
  formatDuration3 = (durationMs) => `${(durationMs / 1e3).toFixed(1)}s`;
33817
34042
  resolvePositiveInteger2 = (value, fallback) => {
@@ -33832,6 +34057,19 @@ var init_runner = __esm({
33832
34057
  createSignalsRunner = (config2) => {
33833
34058
  const interval4 = config2.interval;
33834
34059
  const projectRoot17 = config2.projectRoot?.trim() || String(process.env.PROJECT_CWD || process.cwd()).trim() || process.cwd();
34060
+ const compositionSnapshotRecorder = process.env.TRADEJS_PROJECT_SHA && process.env.TRADEJS_PROJECT_IMAGE_DIGEST && config2.deploymentId ? createRuntimeEvidenceCompositionSnapshotRecorder({
34061
+ persist: (compositionId) => captureRuntimeEvidenceCompositionSnapshot({
34062
+ projectRoot: projectRoot17,
34063
+ userName: config2.userName,
34064
+ deploymentId: config2.deploymentId,
34065
+ expectedCompositionId: compositionId
34066
+ }),
34067
+ onError: (compositionId, error) => import_logger10.logger.warn(
34068
+ "runtime evidence snapshot unavailable; trading continues and the next cycle will retry (composition=%s): %s",
34069
+ compositionId,
34070
+ error instanceof Error ? error.message : String(error)
34071
+ )
34072
+ }) : null;
33835
34073
  const resolveSignalsDaemonMaxLiveBars = (runtimeInterval = interval4) => {
33836
34074
  const intervalMinutes = Number(runtimeInterval);
33837
34075
  const preloadBars = Math.ceil(
@@ -34441,6 +34679,9 @@ var init_runner = __esm({
34441
34679
  if (!currentDeployment) {
34442
34680
  throw new Error(`Runtime deployment not found: ${deploymentId}`);
34443
34681
  }
34682
+ compositionSnapshotRecorder?.observe(
34683
+ currentDeployment.deploymentCompositionId
34684
+ );
34444
34685
  const scopes = await loadConfiguredSignalsScopes(currentDeployment);
34445
34686
  for (const [key, staleSession] of sessions) {
34446
34687
  if (scopes.has(key)) continue;
@@ -34730,12 +34971,12 @@ var init_cliConfig2 = __esm({
34730
34971
  });
34731
34972
 
34732
34973
  // src/lib/replay/runtimeEvidenceSource.ts
34733
- var import_promises32, import_node_path29, asRecord7, asFiniteNumber, unwrapRows2, assertRuntimeRowsMatchDeployment, readRuntimeEvidenceArtifact, loadReplayRuntimeEvidenceMetadata, buildRuntimeEvidenceLineageScopes, loadReplayRuntimeEvidenceSource;
34974
+ var import_promises33, import_node_path30, asRecord7, asFiniteNumber, unwrapRows2, assertRuntimeRowsMatchDeployment, readRuntimeEvidenceArtifact, loadReplayRuntimeEvidenceMetadata, buildRuntimeEvidenceLineageScopes, loadReplayRuntimeEvidenceSource;
34734
34975
  var init_runtimeEvidenceSource = __esm({
34735
34976
  "src/lib/replay/runtimeEvidenceSource.ts"() {
34736
34977
  "use strict";
34737
- import_promises32 = __toESM(require("fs/promises"));
34738
- import_node_path29 = __toESM(require("path"));
34978
+ import_promises33 = __toESM(require("fs/promises"));
34979
+ import_node_path30 = __toESM(require("path"));
34739
34980
  init_runtimeLineage();
34740
34981
  init_runtimeEvidenceDeployment();
34741
34982
  asRecord7 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : null;
@@ -34766,9 +35007,9 @@ var init_runtimeEvidenceSource = __esm({
34766
35007
  filePath,
34767
35008
  projectRoot: projectRoot17
34768
35009
  }) => {
34769
- const resolvedPath = import_node_path29.default.resolve(projectRoot17, filePath);
35010
+ const resolvedPath = import_node_path30.default.resolve(projectRoot17, filePath);
34770
35011
  const root = asRecord7(
34771
- JSON.parse(await import_promises32.default.readFile(resolvedPath, "utf8"))
35012
+ JSON.parse(await import_promises33.default.readFile(resolvedPath, "utf8"))
34772
35013
  );
34773
35014
  const runtime = asRecord7(root?.runtime) ?? root;
34774
35015
  if (!root || !runtime) {
@@ -38440,12 +38681,12 @@ var init_runtimeComparison = __esm({
38440
38681
  });
38441
38682
 
38442
38683
  // src/lib/replay/outputReport.ts
38443
- var import_promises33, import_node_path30, import_data6, formatMsk, formatNumber5, formatMoney2, formatPct, tableCell, createMarkdownTable2, entryStrategy, entryKey, buildDrilldownMap, buildPerTradeAnalysis, renderMatchedRows, renderRuntimeOnlyRows, renderOrderFailedRows, renderBacktestOnlyRows, renderStrategyRows, renderLineageRows, writeReplayOutputReport;
38684
+ var import_promises34, import_node_path31, import_data6, formatMsk, formatNumber5, formatMoney2, formatPct, tableCell, createMarkdownTable2, entryStrategy, entryKey, buildDrilldownMap, buildPerTradeAnalysis, renderMatchedRows, renderRuntimeOnlyRows, renderOrderFailedRows, renderBacktestOnlyRows, renderStrategyRows, renderLineageRows, writeReplayOutputReport;
38444
38685
  var init_outputReport = __esm({
38445
38686
  "src/lib/replay/outputReport.ts"() {
38446
38687
  "use strict";
38447
- import_promises33 = __toESM(require("fs/promises"));
38448
- import_node_path30 = __toESM(require("path"));
38688
+ import_promises34 = __toESM(require("fs/promises"));
38689
+ import_node_path31 = __toESM(require("path"));
38449
38690
  import_data6 = require("@tradejs/core/data");
38450
38691
  init_support();
38451
38692
  formatMsk = (timestamp) => typeof timestamp === "number" && Number.isFinite(timestamp) ? new Intl.DateTimeFormat("ru-RU", {
@@ -38750,8 +38991,8 @@ var init_outputReport = __esm({
38750
38991
  strategySnapshot,
38751
38992
  runtimeComparison
38752
38993
  }) => {
38753
- const outputDir = import_node_path30.default.resolve(projectRoot17, "data/replay/output");
38754
- await import_promises33.default.mkdir(outputDir, { recursive: true });
38994
+ const outputDir = import_node_path31.default.resolve(projectRoot17, "data/replay/output");
38995
+ await import_promises34.default.mkdir(outputDir, { recursive: true });
38755
38996
  const perTradeAnalysis = buildPerTradeAnalysis(runtimeComparison);
38756
38997
  const report = {
38757
38998
  reportType: "replay-output",
@@ -38786,8 +39027,8 @@ var init_outputReport = __esm({
38786
39027
  runtimeComparison,
38787
39028
  perTradeAnalysis
38788
39029
  };
38789
- const markdownPath = import_node_path30.default.join(outputDir, `${timestamp}-replay-report.md`);
38790
- const jsonPath = import_node_path30.default.join(outputDir, `${timestamp}-replay-report.json`);
39030
+ const markdownPath = import_node_path31.default.join(outputDir, `${timestamp}-replay-report.md`);
39031
+ const jsonPath = import_node_path31.default.join(outputDir, `${timestamp}-replay-report.json`);
38791
39032
  const lines = [
38792
39033
  "# Replay Report",
38793
39034
  "",
@@ -38853,8 +39094,8 @@ var init_outputReport = __esm({
38853
39094
  ""
38854
39095
  ];
38855
39096
  await Promise.all([
38856
- import_promises33.default.writeFile(markdownPath, lines.join("\n"), "utf8"),
38857
- import_promises33.default.writeFile(jsonPath, `${(0, import_data6.toJson)(report, true)}
39097
+ import_promises34.default.writeFile(markdownPath, lines.join("\n"), "utf8"),
39098
+ import_promises34.default.writeFile(jsonPath, `${(0, import_data6.toJson)(report, true)}
38858
39099
  `, "utf8")
38859
39100
  ]);
38860
39101
  return {