chainlesschain 0.143.0 → 0.145.0

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.
Files changed (133) hide show
  1. package/package.json +1 -1
  2. package/src/commands/a2a.js +196 -28
  3. package/src/commands/activitypub.js +157 -27
  4. package/src/commands/agent.js +587 -103
  5. package/src/commands/audit.js +206 -0
  6. package/src/commands/bi.js +152 -27
  7. package/src/commands/bm25.js +111 -27
  8. package/src/commands/browse.js +190 -29
  9. package/src/commands/ccron.js +128 -28
  10. package/src/commands/chat.js +207 -0
  11. package/src/commands/compliance.js +414 -34
  12. package/src/commands/compt.js +127 -29
  13. package/src/commands/consol.js +8 -2
  14. package/src/commands/cowork.js +580 -34
  15. package/src/commands/crosschain.js +182 -28
  16. package/src/commands/dao.js +182 -28
  17. package/src/commands/dlp.js +172 -27
  18. package/src/commands/economy.js +205 -50
  19. package/src/commands/evolution.js +203 -50
  20. package/src/commands/evomap.js +182 -27
  21. package/src/commands/fflag.js +74 -22
  22. package/src/commands/git.js +177 -37
  23. package/src/commands/hardening.js +209 -0
  24. package/src/commands/hmemory.js +204 -50
  25. package/src/commands/incentive.js +209 -0
  26. package/src/commands/inference.js +170 -34
  27. package/src/commands/itbudget.js +149 -33
  28. package/src/commands/kg.js +206 -0
  29. package/src/commands/lowcode.js +195 -38
  30. package/src/commands/marketplace.js +206 -0
  31. package/src/commands/matrix.js +179 -27
  32. package/src/commands/mcpscaf.js +145 -33
  33. package/src/commands/meminj.js +145 -33
  34. package/src/commands/nostr.js +178 -27
  35. package/src/commands/orchestrate.js +217 -0
  36. package/src/commands/orchgov.js +144 -33
  37. package/src/commands/pdfp.js +109 -27
  38. package/src/commands/perf.js +169 -32
  39. package/src/commands/perm.js +144 -33
  40. package/src/commands/pipeline.js +207 -52
  41. package/src/commands/planmode.js +141 -32
  42. package/src/commands/privacy.js +203 -0
  43. package/src/commands/promcomp.js +111 -27
  44. package/src/commands/recommend.js +177 -34
  45. package/src/commands/reputation.js +208 -0
  46. package/src/commands/sandbox.js +206 -0
  47. package/src/commands/seshhook.js +145 -33
  48. package/src/commands/seshsearch.js +141 -33
  49. package/src/commands/seshtail.js +144 -33
  50. package/src/commands/seshu.js +152 -33
  51. package/src/commands/sganal.js +123 -29
  52. package/src/commands/siem.js +201 -34
  53. package/src/commands/sla.js +212 -0
  54. package/src/commands/slotfill.js +146 -33
  55. package/src/commands/social.js +157 -32
  56. package/src/commands/stress.js +206 -0
  57. package/src/commands/svccont.js +145 -33
  58. package/src/commands/terraform.js +206 -0
  59. package/src/commands/tms.js +171 -33
  60. package/src/commands/topiccls.js +146 -33
  61. package/src/commands/uprof.js +141 -32
  62. package/src/commands/vcheck.js +122 -28
  63. package/src/commands/webfetch.js +141 -32
  64. package/src/commands/zkp.js +184 -28
  65. package/src/index.js +40 -0
  66. package/src/lib/a2a-protocol.js +319 -51
  67. package/src/lib/activitypub-bridge.js +288 -50
  68. package/src/lib/agent-economy.js +304 -51
  69. package/src/lib/app-builder.js +279 -46
  70. package/src/lib/audit-logger.js +321 -0
  71. package/src/lib/autonomous-agent.js +284 -48
  72. package/src/lib/bi-engine.js +283 -49
  73. package/src/lib/bm25-search.js +301 -49
  74. package/src/lib/browser-automation.js +296 -49
  75. package/src/lib/chat-core.js +336 -0
  76. package/src/lib/claude-code-bridge.js +341 -0
  77. package/src/lib/compliance-framework-reporter.js +305 -51
  78. package/src/lib/compliance-manager.js +330 -0
  79. package/src/lib/compression-telemetry.js +301 -49
  80. package/src/lib/content-recommender.js +317 -52
  81. package/src/lib/cowork-cron.js +298 -49
  82. package/src/lib/cowork-learning.js +333 -0
  83. package/src/lib/cowork-task-runner.js +308 -51
  84. package/src/lib/cowork-workflow.js +327 -0
  85. package/src/lib/cross-chain.js +311 -51
  86. package/src/lib/dao-governance.js +280 -46
  87. package/src/lib/dlp-engine.js +287 -49
  88. package/src/lib/evolution-system.js +278 -47
  89. package/src/lib/evomap-manager.js +280 -46
  90. package/src/lib/execution-backend.js +294 -48
  91. package/src/lib/feature-flags.js +294 -49
  92. package/src/lib/git-integration.js +285 -47
  93. package/src/lib/hardening-manager.js +341 -0
  94. package/src/lib/hierarchical-memory.js +284 -48
  95. package/src/lib/inference-network.js +308 -51
  96. package/src/lib/iteration-budget.js +302 -50
  97. package/src/lib/knowledge-graph.js +333 -0
  98. package/src/lib/matrix-bridge.js +281 -47
  99. package/src/lib/mcp-scaffold.js +318 -54
  100. package/src/lib/memory-injection.js +288 -49
  101. package/src/lib/nostr-bridge.js +286 -49
  102. package/src/lib/orchestrator.js +293 -48
  103. package/src/lib/pdf-parser.js +298 -49
  104. package/src/lib/perf-tuning.js +309 -50
  105. package/src/lib/permission-engine.js +287 -49
  106. package/src/lib/pipeline-orchestrator.js +289 -49
  107. package/src/lib/plan-mode.js +298 -51
  108. package/src/lib/privacy-computing.js +335 -0
  109. package/src/lib/reputation-optimizer.js +340 -0
  110. package/src/lib/sandbox-v2.js +327 -0
  111. package/src/lib/service-container.js +313 -52
  112. package/src/lib/session-consolidator.js +296 -49
  113. package/src/lib/session-hooks.js +312 -53
  114. package/src/lib/session-search.js +304 -51
  115. package/src/lib/session-tail.js +288 -49
  116. package/src/lib/session-usage.js +298 -52
  117. package/src/lib/siem-exporter.js +298 -51
  118. package/src/lib/skill-marketplace.js +345 -0
  119. package/src/lib/sla-manager.js +341 -0
  120. package/src/lib/slot-filler.js +303 -51
  121. package/src/lib/social-graph-analytics.js +295 -49
  122. package/src/lib/social-graph.js +272 -49
  123. package/src/lib/stress-tester.js +342 -0
  124. package/src/lib/sub-agent-registry.js +302 -53
  125. package/src/lib/task-model-selector.js +302 -50
  126. package/src/lib/terraform-manager.js +333 -0
  127. package/src/lib/todo-manager.js +281 -47
  128. package/src/lib/token-incentive.js +341 -0
  129. package/src/lib/topic-classifier.js +297 -49
  130. package/src/lib/user-profile.js +294 -50
  131. package/src/lib/version-checker.js +304 -50
  132. package/src/lib/web-fetch.js +292 -51
  133. package/src/lib/zkp-engine.js +286 -49
@@ -636,25 +636,50 @@ export function _resetV2State() {
636
636
  _statusHistoryV2.clear();
637
637
  }
638
638
 
639
-
640
639
  // ===== V2 Surface: BI Engine governance overlay (CLI v0.135.0) =====
641
640
  export const BI_DATASET_MATURITY_V2 = Object.freeze({
642
- PENDING: "pending", ACTIVE: "active", STALE: "stale", ARCHIVED: "archived",
641
+ PENDING: "pending",
642
+ ACTIVE: "active",
643
+ STALE: "stale",
644
+ ARCHIVED: "archived",
643
645
  });
644
646
  export const BI_QUERY_LIFECYCLE_V2 = Object.freeze({
645
- QUEUED: "queued", RUNNING: "running", COMPLETED: "completed", FAILED: "failed", CANCELLED: "cancelled",
647
+ QUEUED: "queued",
648
+ RUNNING: "running",
649
+ COMPLETED: "completed",
650
+ FAILED: "failed",
651
+ CANCELLED: "cancelled",
646
652
  });
647
653
 
648
654
  const _biDsTrans = new Map([
649
- [BI_DATASET_MATURITY_V2.PENDING, new Set([BI_DATASET_MATURITY_V2.ACTIVE, BI_DATASET_MATURITY_V2.ARCHIVED])],
650
- [BI_DATASET_MATURITY_V2.ACTIVE, new Set([BI_DATASET_MATURITY_V2.STALE, BI_DATASET_MATURITY_V2.ARCHIVED])],
651
- [BI_DATASET_MATURITY_V2.STALE, new Set([BI_DATASET_MATURITY_V2.ACTIVE, BI_DATASET_MATURITY_V2.ARCHIVED])],
655
+ [
656
+ BI_DATASET_MATURITY_V2.PENDING,
657
+ new Set([BI_DATASET_MATURITY_V2.ACTIVE, BI_DATASET_MATURITY_V2.ARCHIVED]),
658
+ ],
659
+ [
660
+ BI_DATASET_MATURITY_V2.ACTIVE,
661
+ new Set([BI_DATASET_MATURITY_V2.STALE, BI_DATASET_MATURITY_V2.ARCHIVED]),
662
+ ],
663
+ [
664
+ BI_DATASET_MATURITY_V2.STALE,
665
+ new Set([BI_DATASET_MATURITY_V2.ACTIVE, BI_DATASET_MATURITY_V2.ARCHIVED]),
666
+ ],
652
667
  [BI_DATASET_MATURITY_V2.ARCHIVED, new Set()],
653
668
  ]);
654
669
  const _biDsTerminal = new Set([BI_DATASET_MATURITY_V2.ARCHIVED]);
655
670
  const _biQTrans = new Map([
656
- [BI_QUERY_LIFECYCLE_V2.QUEUED, new Set([BI_QUERY_LIFECYCLE_V2.RUNNING, BI_QUERY_LIFECYCLE_V2.CANCELLED])],
657
- [BI_QUERY_LIFECYCLE_V2.RUNNING, new Set([BI_QUERY_LIFECYCLE_V2.COMPLETED, BI_QUERY_LIFECYCLE_V2.FAILED, BI_QUERY_LIFECYCLE_V2.CANCELLED])],
671
+ [
672
+ BI_QUERY_LIFECYCLE_V2.QUEUED,
673
+ new Set([BI_QUERY_LIFECYCLE_V2.RUNNING, BI_QUERY_LIFECYCLE_V2.CANCELLED]),
674
+ ],
675
+ [
676
+ BI_QUERY_LIFECYCLE_V2.RUNNING,
677
+ new Set([
678
+ BI_QUERY_LIFECYCLE_V2.COMPLETED,
679
+ BI_QUERY_LIFECYCLE_V2.FAILED,
680
+ BI_QUERY_LIFECYCLE_V2.CANCELLED,
681
+ ]),
682
+ ],
658
683
  [BI_QUERY_LIFECYCLE_V2.COMPLETED, new Set()],
659
684
  [BI_QUERY_LIFECYCLE_V2.FAILED, new Set()],
660
685
  [BI_QUERY_LIFECYCLE_V2.CANCELLED, new Set()],
@@ -667,76 +692,285 @@ let _biMaxPendingPerDs = 10;
667
692
  let _biDsIdleMs = 7 * 24 * 60 * 60 * 1000;
668
693
  let _biQStuckMs = 5 * 60 * 1000;
669
694
 
670
- function _biPos(n, lbl) { const v = Math.floor(Number(n)); if (!Number.isFinite(v) || v <= 0) throw new Error(`${lbl} must be positive integer`); return v; }
695
+ function _biPos(n, lbl) {
696
+ const v = Math.floor(Number(n));
697
+ if (!Number.isFinite(v) || v <= 0)
698
+ throw new Error(`${lbl} must be positive integer`);
699
+ return v;
700
+ }
671
701
 
672
- export function setMaxActiveBiDatasetsPerOwnerV2(n) { _biMaxActivePerOwner = _biPos(n, "maxActiveBiDatasetsPerOwner"); }
673
- export function getMaxActiveBiDatasetsPerOwnerV2() { return _biMaxActivePerOwner; }
674
- export function setMaxPendingBiQueriesPerDatasetV2(n) { _biMaxPendingPerDs = _biPos(n, "maxPendingBiQueriesPerDataset"); }
675
- export function getMaxPendingBiQueriesPerDatasetV2() { return _biMaxPendingPerDs; }
676
- export function setBiDatasetIdleMsV2(n) { _biDsIdleMs = _biPos(n, "biDatasetIdleMs"); }
677
- export function getBiDatasetIdleMsV2() { return _biDsIdleMs; }
678
- export function setBiQueryStuckMsV2(n) { _biQStuckMs = _biPos(n, "biQueryStuckMs"); }
679
- export function getBiQueryStuckMsV2() { return _biQStuckMs; }
702
+ export function setMaxActiveBiDatasetsPerOwnerV2(n) {
703
+ _biMaxActivePerOwner = _biPos(n, "maxActiveBiDatasetsPerOwner");
704
+ }
705
+ export function getMaxActiveBiDatasetsPerOwnerV2() {
706
+ return _biMaxActivePerOwner;
707
+ }
708
+ export function setMaxPendingBiQueriesPerDatasetV2(n) {
709
+ _biMaxPendingPerDs = _biPos(n, "maxPendingBiQueriesPerDataset");
710
+ }
711
+ export function getMaxPendingBiQueriesPerDatasetV2() {
712
+ return _biMaxPendingPerDs;
713
+ }
714
+ export function setBiDatasetIdleMsV2(n) {
715
+ _biDsIdleMs = _biPos(n, "biDatasetIdleMs");
716
+ }
717
+ export function getBiDatasetIdleMsV2() {
718
+ return _biDsIdleMs;
719
+ }
720
+ export function setBiQueryStuckMsV2(n) {
721
+ _biQStuckMs = _biPos(n, "biQueryStuckMs");
722
+ }
723
+ export function getBiQueryStuckMsV2() {
724
+ return _biQStuckMs;
725
+ }
680
726
 
681
727
  export function _resetStateBiEngineV2() {
682
- _biDatasets.clear(); _biQueries.clear();
683
- _biMaxActivePerOwner = 8; _biMaxPendingPerDs = 10;
684
- _biDsIdleMs = 7 * 24 * 60 * 60 * 1000; _biQStuckMs = 5 * 60 * 1000;
728
+ _biDatasets.clear();
729
+ _biQueries.clear();
730
+ _biMaxActivePerOwner = 8;
731
+ _biMaxPendingPerDs = 10;
732
+ _biDsIdleMs = 7 * 24 * 60 * 60 * 1000;
733
+ _biQStuckMs = 5 * 60 * 1000;
685
734
  }
686
735
 
687
736
  export function registerBiDatasetV2({ id, owner, source, metadata } = {}) {
688
737
  if (!id || typeof id !== "string") throw new Error("id is required");
689
738
  if (!owner || typeof owner !== "string") throw new Error("owner is required");
690
- if (_biDatasets.has(id)) throw new Error(`bi dataset ${id} already registered`);
739
+ if (_biDatasets.has(id))
740
+ throw new Error(`bi dataset ${id} already registered`);
691
741
  const now = Date.now();
692
- const d = { id, owner, source: source || "", status: BI_DATASET_MATURITY_V2.PENDING, createdAt: now, updatedAt: now, activatedAt: null, archivedAt: null, lastTouchedAt: now, metadata: { ...(metadata || {}) } };
742
+ const d = {
743
+ id,
744
+ owner,
745
+ source: source || "",
746
+ status: BI_DATASET_MATURITY_V2.PENDING,
747
+ createdAt: now,
748
+ updatedAt: now,
749
+ activatedAt: null,
750
+ archivedAt: null,
751
+ lastTouchedAt: now,
752
+ metadata: { ...(metadata || {}) },
753
+ };
693
754
  _biDatasets.set(id, d);
694
755
  return { ...d, metadata: { ...d.metadata } };
695
756
  }
696
- function _biCheckD(from, to) { const a = _biDsTrans.get(from); if (!a || !a.has(to)) throw new Error(`invalid bi dataset transition ${from} → ${to}`); }
697
- function _biCountActive(owner) { let n = 0; for (const d of _biDatasets.values()) if (d.owner === owner && d.status === BI_DATASET_MATURITY_V2.ACTIVE) n++; return n; }
757
+ function _biCheckD(from, to) {
758
+ const a = _biDsTrans.get(from);
759
+ if (!a || !a.has(to))
760
+ throw new Error(`invalid bi dataset transition ${from} → ${to}`);
761
+ }
762
+ function _biCountActive(owner) {
763
+ let n = 0;
764
+ for (const d of _biDatasets.values())
765
+ if (d.owner === owner && d.status === BI_DATASET_MATURITY_V2.ACTIVE) n++;
766
+ return n;
767
+ }
698
768
 
699
769
  export function activateBiDatasetV2(id) {
700
- const d = _biDatasets.get(id); if (!d) throw new Error(`bi dataset ${id} not found`);
770
+ const d = _biDatasets.get(id);
771
+ if (!d) throw new Error(`bi dataset ${id} not found`);
701
772
  _biCheckD(d.status, BI_DATASET_MATURITY_V2.ACTIVE);
702
773
  const recovery = d.status === BI_DATASET_MATURITY_V2.STALE;
703
- if (!recovery) { const a = _biCountActive(d.owner); if (a >= _biMaxActivePerOwner) throw new Error(`max active bi datasets per owner (${_biMaxActivePerOwner}) reached for ${d.owner}`); }
704
- const now = Date.now(); d.status = BI_DATASET_MATURITY_V2.ACTIVE; d.updatedAt = now; d.lastTouchedAt = now; if (!d.activatedAt) d.activatedAt = now;
774
+ if (!recovery) {
775
+ const a = _biCountActive(d.owner);
776
+ if (a >= _biMaxActivePerOwner)
777
+ throw new Error(
778
+ `max active bi datasets per owner (${_biMaxActivePerOwner}) reached for ${d.owner}`,
779
+ );
780
+ }
781
+ const now = Date.now();
782
+ d.status = BI_DATASET_MATURITY_V2.ACTIVE;
783
+ d.updatedAt = now;
784
+ d.lastTouchedAt = now;
785
+ if (!d.activatedAt) d.activatedAt = now;
705
786
  return { ...d, metadata: { ...d.metadata } };
706
787
  }
707
- export function staleBiDatasetV2(id) { const d = _biDatasets.get(id); if (!d) throw new Error(`bi dataset ${id} not found`); _biCheckD(d.status, BI_DATASET_MATURITY_V2.STALE); d.status = BI_DATASET_MATURITY_V2.STALE; d.updatedAt = Date.now(); return { ...d, metadata: { ...d.metadata } }; }
708
- export function archiveBiDatasetV2(id) { const d = _biDatasets.get(id); if (!d) throw new Error(`bi dataset ${id} not found`); _biCheckD(d.status, BI_DATASET_MATURITY_V2.ARCHIVED); const now = Date.now(); d.status = BI_DATASET_MATURITY_V2.ARCHIVED; d.updatedAt = now; if (!d.archivedAt) d.archivedAt = now; return { ...d, metadata: { ...d.metadata } }; }
709
- export function touchBiDatasetV2(id) { const d = _biDatasets.get(id); if (!d) throw new Error(`bi dataset ${id} not found`); if (_biDsTerminal.has(d.status)) throw new Error(`cannot touch terminal bi dataset ${id}`); const now = Date.now(); d.lastTouchedAt = now; d.updatedAt = now; return { ...d, metadata: { ...d.metadata } }; }
710
- export function getBiDatasetV2(id) { const d = _biDatasets.get(id); if (!d) return null; return { ...d, metadata: { ...d.metadata } }; }
711
- export function listBiDatasetsV2() { return [..._biDatasets.values()].map((d) => ({ ...d, metadata: { ...d.metadata } })); }
788
+ export function staleBiDatasetV2(id) {
789
+ const d = _biDatasets.get(id);
790
+ if (!d) throw new Error(`bi dataset ${id} not found`);
791
+ _biCheckD(d.status, BI_DATASET_MATURITY_V2.STALE);
792
+ d.status = BI_DATASET_MATURITY_V2.STALE;
793
+ d.updatedAt = Date.now();
794
+ return { ...d, metadata: { ...d.metadata } };
795
+ }
796
+ export function archiveBiDatasetV2(id) {
797
+ const d = _biDatasets.get(id);
798
+ if (!d) throw new Error(`bi dataset ${id} not found`);
799
+ _biCheckD(d.status, BI_DATASET_MATURITY_V2.ARCHIVED);
800
+ const now = Date.now();
801
+ d.status = BI_DATASET_MATURITY_V2.ARCHIVED;
802
+ d.updatedAt = now;
803
+ if (!d.archivedAt) d.archivedAt = now;
804
+ return { ...d, metadata: { ...d.metadata } };
805
+ }
806
+ export function touchBiDatasetV2(id) {
807
+ const d = _biDatasets.get(id);
808
+ if (!d) throw new Error(`bi dataset ${id} not found`);
809
+ if (_biDsTerminal.has(d.status))
810
+ throw new Error(`cannot touch terminal bi dataset ${id}`);
811
+ const now = Date.now();
812
+ d.lastTouchedAt = now;
813
+ d.updatedAt = now;
814
+ return { ...d, metadata: { ...d.metadata } };
815
+ }
816
+ export function getBiDatasetV2(id) {
817
+ const d = _biDatasets.get(id);
818
+ if (!d) return null;
819
+ return { ...d, metadata: { ...d.metadata } };
820
+ }
821
+ export function listBiDatasetsV2() {
822
+ return [..._biDatasets.values()].map((d) => ({
823
+ ...d,
824
+ metadata: { ...d.metadata },
825
+ }));
826
+ }
712
827
 
713
- function _biCountPending(did) { let n = 0; for (const q of _biQueries.values()) if (q.datasetId === did && (q.status === BI_QUERY_LIFECYCLE_V2.QUEUED || q.status === BI_QUERY_LIFECYCLE_V2.RUNNING)) n++; return n; }
828
+ function _biCountPending(did) {
829
+ let n = 0;
830
+ for (const q of _biQueries.values())
831
+ if (
832
+ q.datasetId === did &&
833
+ (q.status === BI_QUERY_LIFECYCLE_V2.QUEUED ||
834
+ q.status === BI_QUERY_LIFECYCLE_V2.RUNNING)
835
+ )
836
+ n++;
837
+ return n;
838
+ }
714
839
 
715
840
  export function createBiQueryV2({ id, datasetId, sql, metadata } = {}) {
716
841
  if (!id || typeof id !== "string") throw new Error("id is required");
717
- if (!datasetId || typeof datasetId !== "string") throw new Error("datasetId is required");
842
+ if (!datasetId || typeof datasetId !== "string")
843
+ throw new Error("datasetId is required");
718
844
  if (_biQueries.has(id)) throw new Error(`bi query ${id} already exists`);
719
- if (!_biDatasets.has(datasetId)) throw new Error(`bi dataset ${datasetId} not found`);
845
+ if (!_biDatasets.has(datasetId))
846
+ throw new Error(`bi dataset ${datasetId} not found`);
720
847
  const pending = _biCountPending(datasetId);
721
- if (pending >= _biMaxPendingPerDs) throw new Error(`max pending bi queries per dataset (${_biMaxPendingPerDs}) reached for ${datasetId}`);
848
+ if (pending >= _biMaxPendingPerDs)
849
+ throw new Error(
850
+ `max pending bi queries per dataset (${_biMaxPendingPerDs}) reached for ${datasetId}`,
851
+ );
722
852
  const now = Date.now();
723
- const q = { id, datasetId, sql: sql || "", status: BI_QUERY_LIFECYCLE_V2.QUEUED, createdAt: now, updatedAt: now, startedAt: null, settledAt: null, metadata: { ...(metadata || {}) } };
853
+ const q = {
854
+ id,
855
+ datasetId,
856
+ sql: sql || "",
857
+ status: BI_QUERY_LIFECYCLE_V2.QUEUED,
858
+ createdAt: now,
859
+ updatedAt: now,
860
+ startedAt: null,
861
+ settledAt: null,
862
+ metadata: { ...(metadata || {}) },
863
+ };
724
864
  _biQueries.set(id, q);
725
865
  return { ...q, metadata: { ...q.metadata } };
726
866
  }
727
- function _biCheckQ(from, to) { const a = _biQTrans.get(from); if (!a || !a.has(to)) throw new Error(`invalid bi query transition ${from} → ${to}`); }
728
- export function startBiQueryV2(id) { const q = _biQueries.get(id); if (!q) throw new Error(`bi query ${id} not found`); _biCheckQ(q.status, BI_QUERY_LIFECYCLE_V2.RUNNING); const now = Date.now(); q.status = BI_QUERY_LIFECYCLE_V2.RUNNING; q.updatedAt = now; if (!q.startedAt) q.startedAt = now; return { ...q, metadata: { ...q.metadata } }; }
729
- export function completeBiQueryV2(id) { const q = _biQueries.get(id); if (!q) throw new Error(`bi query ${id} not found`); _biCheckQ(q.status, BI_QUERY_LIFECYCLE_V2.COMPLETED); const now = Date.now(); q.status = BI_QUERY_LIFECYCLE_V2.COMPLETED; q.updatedAt = now; if (!q.settledAt) q.settledAt = now; return { ...q, metadata: { ...q.metadata } }; }
730
- export function failBiQueryV2(id, reason) { const q = _biQueries.get(id); if (!q) throw new Error(`bi query ${id} not found`); _biCheckQ(q.status, BI_QUERY_LIFECYCLE_V2.FAILED); const now = Date.now(); q.status = BI_QUERY_LIFECYCLE_V2.FAILED; q.updatedAt = now; if (!q.settledAt) q.settledAt = now; if (reason) q.metadata.failReason = String(reason); return { ...q, metadata: { ...q.metadata } }; }
731
- export function cancelBiQueryV2(id, reason) { const q = _biQueries.get(id); if (!q) throw new Error(`bi query ${id} not found`); _biCheckQ(q.status, BI_QUERY_LIFECYCLE_V2.CANCELLED); const now = Date.now(); q.status = BI_QUERY_LIFECYCLE_V2.CANCELLED; q.updatedAt = now; if (!q.settledAt) q.settledAt = now; if (reason) q.metadata.cancelReason = String(reason); return { ...q, metadata: { ...q.metadata } }; }
732
- export function getBiQueryV2(id) { const q = _biQueries.get(id); if (!q) return null; return { ...q, metadata: { ...q.metadata } }; }
733
- export function listBiQueriesV2() { return [..._biQueries.values()].map((q) => ({ ...q, metadata: { ...q.metadata } })); }
867
+ function _biCheckQ(from, to) {
868
+ const a = _biQTrans.get(from);
869
+ if (!a || !a.has(to))
870
+ throw new Error(`invalid bi query transition ${from} ${to}`);
871
+ }
872
+ export function startBiQueryV2(id) {
873
+ const q = _biQueries.get(id);
874
+ if (!q) throw new Error(`bi query ${id} not found`);
875
+ _biCheckQ(q.status, BI_QUERY_LIFECYCLE_V2.RUNNING);
876
+ const now = Date.now();
877
+ q.status = BI_QUERY_LIFECYCLE_V2.RUNNING;
878
+ q.updatedAt = now;
879
+ if (!q.startedAt) q.startedAt = now;
880
+ return { ...q, metadata: { ...q.metadata } };
881
+ }
882
+ export function completeBiQueryV2(id) {
883
+ const q = _biQueries.get(id);
884
+ if (!q) throw new Error(`bi query ${id} not found`);
885
+ _biCheckQ(q.status, BI_QUERY_LIFECYCLE_V2.COMPLETED);
886
+ const now = Date.now();
887
+ q.status = BI_QUERY_LIFECYCLE_V2.COMPLETED;
888
+ q.updatedAt = now;
889
+ if (!q.settledAt) q.settledAt = now;
890
+ return { ...q, metadata: { ...q.metadata } };
891
+ }
892
+ export function failBiQueryV2(id, reason) {
893
+ const q = _biQueries.get(id);
894
+ if (!q) throw new Error(`bi query ${id} not found`);
895
+ _biCheckQ(q.status, BI_QUERY_LIFECYCLE_V2.FAILED);
896
+ const now = Date.now();
897
+ q.status = BI_QUERY_LIFECYCLE_V2.FAILED;
898
+ q.updatedAt = now;
899
+ if (!q.settledAt) q.settledAt = now;
900
+ if (reason) q.metadata.failReason = String(reason);
901
+ return { ...q, metadata: { ...q.metadata } };
902
+ }
903
+ export function cancelBiQueryV2(id, reason) {
904
+ const q = _biQueries.get(id);
905
+ if (!q) throw new Error(`bi query ${id} not found`);
906
+ _biCheckQ(q.status, BI_QUERY_LIFECYCLE_V2.CANCELLED);
907
+ const now = Date.now();
908
+ q.status = BI_QUERY_LIFECYCLE_V2.CANCELLED;
909
+ q.updatedAt = now;
910
+ if (!q.settledAt) q.settledAt = now;
911
+ if (reason) q.metadata.cancelReason = String(reason);
912
+ return { ...q, metadata: { ...q.metadata } };
913
+ }
914
+ export function getBiQueryV2(id) {
915
+ const q = _biQueries.get(id);
916
+ if (!q) return null;
917
+ return { ...q, metadata: { ...q.metadata } };
918
+ }
919
+ export function listBiQueriesV2() {
920
+ return [..._biQueries.values()].map((q) => ({
921
+ ...q,
922
+ metadata: { ...q.metadata },
923
+ }));
924
+ }
734
925
 
735
- export function autoStaleIdleBiDatasetsV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const d of _biDatasets.values()) if (d.status === BI_DATASET_MATURITY_V2.ACTIVE && (t - d.lastTouchedAt) >= _biDsIdleMs) { d.status = BI_DATASET_MATURITY_V2.STALE; d.updatedAt = t; flipped.push(d.id); } return { flipped, count: flipped.length }; }
736
- export function autoFailStuckBiQueriesV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const q of _biQueries.values()) if (q.status === BI_QUERY_LIFECYCLE_V2.RUNNING && q.startedAt != null && (t - q.startedAt) >= _biQStuckMs) { q.status = BI_QUERY_LIFECYCLE_V2.FAILED; q.updatedAt = t; if (!q.settledAt) q.settledAt = t; q.metadata.failReason = "auto-fail-stuck"; flipped.push(q.id); } return { flipped, count: flipped.length }; }
926
+ export function autoStaleIdleBiDatasetsV2({ now } = {}) {
927
+ const t = now ?? Date.now();
928
+ const flipped = [];
929
+ for (const d of _biDatasets.values())
930
+ if (
931
+ d.status === BI_DATASET_MATURITY_V2.ACTIVE &&
932
+ t - d.lastTouchedAt >= _biDsIdleMs
933
+ ) {
934
+ d.status = BI_DATASET_MATURITY_V2.STALE;
935
+ d.updatedAt = t;
936
+ flipped.push(d.id);
937
+ }
938
+ return { flipped, count: flipped.length };
939
+ }
940
+ export function autoFailStuckBiQueriesV2({ now } = {}) {
941
+ const t = now ?? Date.now();
942
+ const flipped = [];
943
+ for (const q of _biQueries.values())
944
+ if (
945
+ q.status === BI_QUERY_LIFECYCLE_V2.RUNNING &&
946
+ q.startedAt != null &&
947
+ t - q.startedAt >= _biQStuckMs
948
+ ) {
949
+ q.status = BI_QUERY_LIFECYCLE_V2.FAILED;
950
+ q.updatedAt = t;
951
+ if (!q.settledAt) q.settledAt = t;
952
+ q.metadata.failReason = "auto-fail-stuck";
953
+ flipped.push(q.id);
954
+ }
955
+ return { flipped, count: flipped.length };
956
+ }
737
957
 
738
958
  export function getBiEngineStatsV2() {
739
- const datasetsByStatus = {}; for (const s of Object.values(BI_DATASET_MATURITY_V2)) datasetsByStatus[s] = 0; for (const d of _biDatasets.values()) datasetsByStatus[d.status]++;
740
- const queriesByStatus = {}; for (const s of Object.values(BI_QUERY_LIFECYCLE_V2)) queriesByStatus[s] = 0; for (const q of _biQueries.values()) queriesByStatus[q.status]++;
741
- return { totalDatasetsV2: _biDatasets.size, totalQueriesV2: _biQueries.size, maxActiveBiDatasetsPerOwner: _biMaxActivePerOwner, maxPendingBiQueriesPerDataset: _biMaxPendingPerDs, biDatasetIdleMs: _biDsIdleMs, biQueryStuckMs: _biQStuckMs, datasetsByStatus, queriesByStatus };
959
+ const datasetsByStatus = {};
960
+ for (const s of Object.values(BI_DATASET_MATURITY_V2))
961
+ datasetsByStatus[s] = 0;
962
+ for (const d of _biDatasets.values()) datasetsByStatus[d.status]++;
963
+ const queriesByStatus = {};
964
+ for (const s of Object.values(BI_QUERY_LIFECYCLE_V2)) queriesByStatus[s] = 0;
965
+ for (const q of _biQueries.values()) queriesByStatus[q.status]++;
966
+ return {
967
+ totalDatasetsV2: _biDatasets.size,
968
+ totalQueriesV2: _biQueries.size,
969
+ maxActiveBiDatasetsPerOwner: _biMaxActivePerOwner,
970
+ maxPendingBiQueriesPerDataset: _biMaxPendingPerDs,
971
+ biDatasetIdleMs: _biDsIdleMs,
972
+ biQueryStuckMs: _biQStuckMs,
973
+ datasetsByStatus,
974
+ queriesByStatus,
975
+ };
742
976
  }