chainlesschain 0.81.0 → 0.132.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 (110) hide show
  1. package/bin/chainlesschain.js +0 -0
  2. package/package.json +1 -1
  3. package/src/commands/agent-network.js +254 -1
  4. package/src/commands/audit.js +302 -0
  5. package/src/commands/automation.js +271 -1
  6. package/src/commands/codegen.js +224 -0
  7. package/src/commands/collab.js +341 -0
  8. package/src/commands/compliance.js +1035 -0
  9. package/src/commands/cowork.js +221 -0
  10. package/src/commands/dbevo.js +284 -0
  11. package/src/commands/dev.js +252 -0
  12. package/src/commands/did.js +358 -0
  13. package/src/commands/encrypt.js +341 -0
  14. package/src/commands/export.js +256 -1
  15. package/src/commands/fusion.js +258 -0
  16. package/src/commands/governance.js +325 -0
  17. package/src/commands/hardening.js +411 -0
  18. package/src/commands/hook.js +148 -0
  19. package/src/commands/import.js +252 -0
  20. package/src/commands/incentive.js +322 -0
  21. package/src/commands/infra.js +244 -0
  22. package/src/commands/instinct.js +260 -0
  23. package/src/commands/ipfs.js +318 -0
  24. package/src/commands/kg.js +387 -0
  25. package/src/commands/llm.js +263 -0
  26. package/src/commands/mcp.js +221 -0
  27. package/src/commands/memory.js +248 -0
  28. package/src/commands/multimodal.js +296 -0
  29. package/src/commands/nlprog.js +356 -0
  30. package/src/commands/note.js +244 -0
  31. package/src/commands/ops.js +354 -0
  32. package/src/commands/orchestrate.js +166 -0
  33. package/src/commands/org.js +277 -0
  34. package/src/commands/p2p.js +390 -0
  35. package/src/commands/perception.js +290 -0
  36. package/src/commands/permmem.js +251 -0
  37. package/src/commands/plugin-ecosystem.js +273 -0
  38. package/src/commands/pqc.js +393 -0
  39. package/src/commands/quantization.js +351 -0
  40. package/src/commands/rcache.js +271 -0
  41. package/src/commands/recommend.js +340 -0
  42. package/src/commands/runtime.js +307 -0
  43. package/src/commands/scim.js +262 -0
  44. package/src/commands/session.js +258 -0
  45. package/src/commands/skill.js +267 -1
  46. package/src/commands/social.js +256 -0
  47. package/src/commands/sso.js +186 -1
  48. package/src/commands/sync.js +256 -0
  49. package/src/commands/tech.js +338 -0
  50. package/src/commands/tenant.js +351 -0
  51. package/src/commands/tokens.js +269 -0
  52. package/src/commands/trust.js +249 -0
  53. package/src/commands/wallet.js +277 -0
  54. package/src/commands/workflow.js +171 -0
  55. package/src/index.js +4 -0
  56. package/src/lib/agent-coordinator.js +325 -0
  57. package/src/lib/agent-network.js +387 -0
  58. package/src/lib/agent-router.js +395 -0
  59. package/src/lib/aiops.js +478 -0
  60. package/src/lib/audit-logger.js +379 -0
  61. package/src/lib/automation-engine.js +330 -0
  62. package/src/lib/autonomous-developer.js +350 -0
  63. package/src/lib/code-agent.js +323 -0
  64. package/src/lib/collaboration-governance.js +364 -0
  65. package/src/lib/community-governance.js +436 -0
  66. package/src/lib/compliance-manager.js +434 -0
  67. package/src/lib/content-recommendation.js +469 -0
  68. package/src/lib/crypto-manager.js +350 -0
  69. package/src/lib/dbevo.js +338 -0
  70. package/src/lib/decentral-infra.js +340 -0
  71. package/src/lib/did-manager.js +367 -0
  72. package/src/lib/hardening-manager.js +348 -0
  73. package/src/lib/hook-manager.js +380 -0
  74. package/src/lib/instinct-manager.js +332 -0
  75. package/src/lib/ipfs-storage.js +334 -0
  76. package/src/lib/knowledge-exporter.js +381 -0
  77. package/src/lib/knowledge-graph.js +432 -0
  78. package/src/lib/knowledge-importer.js +379 -0
  79. package/src/lib/llm-providers.js +391 -0
  80. package/src/lib/mcp-registry.js +333 -0
  81. package/src/lib/memory-manager.js +330 -0
  82. package/src/lib/multimodal.js +346 -0
  83. package/src/lib/nl-programming.js +343 -0
  84. package/src/lib/note-versioning.js +327 -0
  85. package/src/lib/org-manager.js +323 -0
  86. package/src/lib/p2p-manager.js +387 -0
  87. package/src/lib/perception.js +346 -0
  88. package/src/lib/perf-tuning.js +4 -1
  89. package/src/lib/permanent-memory.js +320 -0
  90. package/src/lib/plugin-ecosystem.js +377 -0
  91. package/src/lib/pqc-manager.js +368 -0
  92. package/src/lib/protocol-fusion.js +417 -0
  93. package/src/lib/quantization.js +325 -0
  94. package/src/lib/response-cache.js +327 -0
  95. package/src/lib/scim-manager.js +329 -0
  96. package/src/lib/session-manager.js +329 -0
  97. package/src/lib/skill-loader.js +377 -0
  98. package/src/lib/social-manager.js +326 -0
  99. package/src/lib/sso-manager.js +332 -0
  100. package/src/lib/sync-manager.js +326 -0
  101. package/src/lib/tech-learning-engine.js +369 -0
  102. package/src/lib/tenant-saas.js +460 -0
  103. package/src/lib/threat-intel.js +335 -0
  104. package/src/lib/token-incentive.js +293 -0
  105. package/src/lib/token-tracker.js +329 -0
  106. package/src/lib/trust-security.js +390 -0
  107. package/src/lib/ueba.js +389 -0
  108. package/src/lib/universal-runtime.js +325 -0
  109. package/src/lib/wallet-manager.js +326 -0
  110. package/src/lib/workflow-engine.js +322 -0
@@ -573,3 +573,337 @@ export function _resetState() {
573
573
  };
574
574
  _quotaBytes = DEFAULT_QUOTA_BYTES;
575
575
  }
576
+
577
+ /* ═════════════════════════════════════════════════════════ *
578
+ * Phase 17 V2 — Gateway Maturity + Pin Lifecycle
579
+ * ═════════════════════════════════════════════════════════ */
580
+
581
+ export const GATEWAY_MATURITY_V2 = Object.freeze({
582
+ ONBOARDING: "onboarding",
583
+ ACTIVE: "active",
584
+ DEGRADED: "degraded",
585
+ OFFLINE: "offline",
586
+ RETIRED: "retired",
587
+ });
588
+
589
+ export const PIN_LIFECYCLE_V2 = Object.freeze({
590
+ PENDING: "pending",
591
+ PINNED: "pinned",
592
+ UNPINNED: "unpinned",
593
+ FAILED: "failed",
594
+ });
595
+
596
+ const GATEWAY_TRANSITIONS_V2 = new Map([
597
+ ["onboarding", new Set(["active", "retired"])],
598
+ ["active", new Set(["degraded", "offline", "retired"])],
599
+ ["degraded", new Set(["active", "offline", "retired"])],
600
+ ["offline", new Set(["active", "retired"])],
601
+ ]);
602
+ const GATEWAY_TERMINALS_V2 = new Set(["retired"]);
603
+
604
+ const PIN_TRANSITIONS_V2 = new Map([
605
+ ["pending", new Set(["pinned", "failed", "unpinned"])],
606
+ ["pinned", new Set(["unpinned"])],
607
+ ["failed", new Set(["pending", "unpinned"])],
608
+ ]);
609
+ const PIN_TERMINALS_V2 = new Set(["unpinned"]);
610
+
611
+ export const IPFS_DEFAULT_MAX_ACTIVE_GATEWAYS_PER_OPERATOR = 20;
612
+ export const IPFS_DEFAULT_MAX_PENDING_PINS_PER_OWNER = 100;
613
+ export const IPFS_DEFAULT_GATEWAY_IDLE_MS = 60 * 86400000; // 60d
614
+ export const IPFS_DEFAULT_PIN_PENDING_MS = 24 * 3600000; // 24h
615
+
616
+ let _maxActiveGatewaysPerOperatorV2 =
617
+ IPFS_DEFAULT_MAX_ACTIVE_GATEWAYS_PER_OPERATOR;
618
+ let _maxPendingPinsPerOwnerV2 = IPFS_DEFAULT_MAX_PENDING_PINS_PER_OWNER;
619
+ let _gatewayIdleMsV2 = IPFS_DEFAULT_GATEWAY_IDLE_MS;
620
+ let _pinPendingMsV2 = IPFS_DEFAULT_PIN_PENDING_MS;
621
+
622
+ function _positiveIntV2(n, label) {
623
+ const v = Math.floor(Number(n));
624
+ if (!Number.isFinite(v) || v <= 0)
625
+ throw new Error(`${label} must be a positive integer`);
626
+ return v;
627
+ }
628
+
629
+ export function getDefaultMaxActiveGatewaysPerOperatorV2() {
630
+ return IPFS_DEFAULT_MAX_ACTIVE_GATEWAYS_PER_OPERATOR;
631
+ }
632
+ export function getMaxActiveGatewaysPerOperatorV2() {
633
+ return _maxActiveGatewaysPerOperatorV2;
634
+ }
635
+ export function setMaxActiveGatewaysPerOperatorV2(n) {
636
+ return (_maxActiveGatewaysPerOperatorV2 = _positiveIntV2(
637
+ n,
638
+ "maxActiveGatewaysPerOperator",
639
+ ));
640
+ }
641
+ export function getDefaultMaxPendingPinsPerOwnerV2() {
642
+ return IPFS_DEFAULT_MAX_PENDING_PINS_PER_OWNER;
643
+ }
644
+ export function getMaxPendingPinsPerOwnerV2() {
645
+ return _maxPendingPinsPerOwnerV2;
646
+ }
647
+ export function setMaxPendingPinsPerOwnerV2(n) {
648
+ return (_maxPendingPinsPerOwnerV2 = _positiveIntV2(
649
+ n,
650
+ "maxPendingPinsPerOwner",
651
+ ));
652
+ }
653
+ export function getDefaultGatewayIdleMsV2() {
654
+ return IPFS_DEFAULT_GATEWAY_IDLE_MS;
655
+ }
656
+ export function getGatewayIdleMsV2() {
657
+ return _gatewayIdleMsV2;
658
+ }
659
+ export function setGatewayIdleMsV2(ms) {
660
+ return (_gatewayIdleMsV2 = _positiveIntV2(ms, "gatewayIdleMs"));
661
+ }
662
+ export function getDefaultPinPendingMsV2() {
663
+ return IPFS_DEFAULT_PIN_PENDING_MS;
664
+ }
665
+ export function getPinPendingMsV2() {
666
+ return _pinPendingMsV2;
667
+ }
668
+ export function setPinPendingMsV2(ms) {
669
+ return (_pinPendingMsV2 = _positiveIntV2(ms, "pinPendingMs"));
670
+ }
671
+
672
+ const _gatewaysV2 = new Map();
673
+ const _pinsV2 = new Map();
674
+
675
+ export function registerGatewayV2(
676
+ _db,
677
+ { gatewayId, operatorId, endpoint, initialStatus, metadata } = {},
678
+ ) {
679
+ if (!gatewayId) throw new Error("gatewayId is required");
680
+ if (!operatorId) throw new Error("operatorId is required");
681
+ if (!endpoint) throw new Error("endpoint is required");
682
+ if (_gatewaysV2.has(gatewayId))
683
+ throw new Error(`Gateway ${gatewayId} already exists`);
684
+ const status = initialStatus || GATEWAY_MATURITY_V2.ONBOARDING;
685
+ if (!Object.values(GATEWAY_MATURITY_V2).includes(status))
686
+ throw new Error(`Invalid initial status: ${status}`);
687
+ if (GATEWAY_TERMINALS_V2.has(status))
688
+ throw new Error(`Cannot register in terminal status: ${status}`);
689
+ if (status === GATEWAY_MATURITY_V2.ACTIVE) {
690
+ if (getActiveGatewayCount(operatorId) >= _maxActiveGatewaysPerOperatorV2)
691
+ throw new Error(
692
+ `Operator ${operatorId} reached active-gateway cap (${_maxActiveGatewaysPerOperatorV2})`,
693
+ );
694
+ }
695
+ const now = Date.now();
696
+ const record = {
697
+ gatewayId,
698
+ operatorId,
699
+ endpoint,
700
+ status,
701
+ metadata: metadata || {},
702
+ createdAt: now,
703
+ updatedAt: now,
704
+ lastHeartbeatAt: now,
705
+ };
706
+ _gatewaysV2.set(gatewayId, record);
707
+ return { ...record, metadata: { ...record.metadata } };
708
+ }
709
+
710
+ export function getGatewayV2(gatewayId) {
711
+ const r = _gatewaysV2.get(gatewayId);
712
+ return r ? { ...r, metadata: { ...r.metadata } } : null;
713
+ }
714
+
715
+ export function setGatewayMaturityV2(_db, gatewayId, newStatus, patch = {}) {
716
+ const record = _gatewaysV2.get(gatewayId);
717
+ if (!record) throw new Error(`Unknown gateway: ${gatewayId}`);
718
+ if (!Object.values(GATEWAY_MATURITY_V2).includes(newStatus))
719
+ throw new Error(`Invalid status: ${newStatus}`);
720
+ const allowed = GATEWAY_TRANSITIONS_V2.get(record.status) || new Set();
721
+ if (!allowed.has(newStatus))
722
+ throw new Error(`Invalid transition: ${record.status} -> ${newStatus}`);
723
+ if (newStatus === GATEWAY_MATURITY_V2.ACTIVE) {
724
+ if (
725
+ getActiveGatewayCount(record.operatorId) >=
726
+ _maxActiveGatewaysPerOperatorV2
727
+ )
728
+ throw new Error(
729
+ `Operator ${record.operatorId} reached active-gateway cap (${_maxActiveGatewaysPerOperatorV2})`,
730
+ );
731
+ }
732
+ record.status = newStatus;
733
+ record.updatedAt = Date.now();
734
+ if (patch.reason !== undefined) record.lastReason = patch.reason;
735
+ if (patch.metadata)
736
+ record.metadata = { ...record.metadata, ...patch.metadata };
737
+ return { ...record, metadata: { ...record.metadata } };
738
+ }
739
+
740
+ export function activateGateway(db, id, reason) {
741
+ return setGatewayMaturityV2(db, id, GATEWAY_MATURITY_V2.ACTIVE, { reason });
742
+ }
743
+ export function degradeGateway(db, id, reason) {
744
+ return setGatewayMaturityV2(db, id, GATEWAY_MATURITY_V2.DEGRADED, { reason });
745
+ }
746
+ export function offlineGateway(db, id, reason) {
747
+ return setGatewayMaturityV2(db, id, GATEWAY_MATURITY_V2.OFFLINE, { reason });
748
+ }
749
+ export function retireGateway(db, id, reason) {
750
+ return setGatewayMaturityV2(db, id, GATEWAY_MATURITY_V2.RETIRED, { reason });
751
+ }
752
+
753
+ export function touchGatewayHeartbeat(gatewayId) {
754
+ const record = _gatewaysV2.get(gatewayId);
755
+ if (!record) throw new Error(`Unknown gateway: ${gatewayId}`);
756
+ record.lastHeartbeatAt = Date.now();
757
+ record.updatedAt = record.lastHeartbeatAt;
758
+ return { ...record, metadata: { ...record.metadata } };
759
+ }
760
+
761
+ export function registerPinV2(
762
+ _db,
763
+ { pinId, ownerId, cid, initialStatus, metadata } = {},
764
+ ) {
765
+ if (!pinId) throw new Error("pinId is required");
766
+ if (!ownerId) throw new Error("ownerId is required");
767
+ if (!cid) throw new Error("cid is required");
768
+ if (_pinsV2.has(pinId)) throw new Error(`Pin ${pinId} already exists`);
769
+ const status = initialStatus || PIN_LIFECYCLE_V2.PENDING;
770
+ if (!Object.values(PIN_LIFECYCLE_V2).includes(status))
771
+ throw new Error(`Invalid initial status: ${status}`);
772
+ if (PIN_TERMINALS_V2.has(status))
773
+ throw new Error(`Cannot register in terminal status: ${status}`);
774
+ if (status === PIN_LIFECYCLE_V2.PENDING) {
775
+ if (getPendingPinCount(ownerId) >= _maxPendingPinsPerOwnerV2)
776
+ throw new Error(
777
+ `Owner ${ownerId} reached pending-pin cap (${_maxPendingPinsPerOwnerV2})`,
778
+ );
779
+ }
780
+ const now = Date.now();
781
+ const record = {
782
+ pinId,
783
+ ownerId,
784
+ cid,
785
+ status,
786
+ metadata: metadata || {},
787
+ createdAt: now,
788
+ updatedAt: now,
789
+ };
790
+ _pinsV2.set(pinId, record);
791
+ return { ...record, metadata: { ...record.metadata } };
792
+ }
793
+
794
+ export function getPinV2(pinId) {
795
+ const r = _pinsV2.get(pinId);
796
+ return r ? { ...r, metadata: { ...r.metadata } } : null;
797
+ }
798
+
799
+ export function setPinStatusV2(_db, pinId, newStatus, patch = {}) {
800
+ const record = _pinsV2.get(pinId);
801
+ if (!record) throw new Error(`Unknown pin: ${pinId}`);
802
+ if (!Object.values(PIN_LIFECYCLE_V2).includes(newStatus))
803
+ throw new Error(`Invalid status: ${newStatus}`);
804
+ const allowed = PIN_TRANSITIONS_V2.get(record.status) || new Set();
805
+ if (!allowed.has(newStatus))
806
+ throw new Error(`Invalid transition: ${record.status} -> ${newStatus}`);
807
+ record.status = newStatus;
808
+ record.updatedAt = Date.now();
809
+ if (newStatus === PIN_LIFECYCLE_V2.PINNED && !record.pinnedAt)
810
+ record.pinnedAt = record.updatedAt;
811
+ if (patch.reason !== undefined) record.lastReason = patch.reason;
812
+ if (patch.metadata)
813
+ record.metadata = { ...record.metadata, ...patch.metadata };
814
+ return { ...record, metadata: { ...record.metadata } };
815
+ }
816
+
817
+ export function confirmPin(db, pinId, reason) {
818
+ return setPinStatusV2(db, pinId, PIN_LIFECYCLE_V2.PINNED, { reason });
819
+ }
820
+ export function failPin(db, pinId, reason) {
821
+ return setPinStatusV2(db, pinId, PIN_LIFECYCLE_V2.FAILED, { reason });
822
+ }
823
+ export function unpinV2(db, pinId, reason) {
824
+ return setPinStatusV2(db, pinId, PIN_LIFECYCLE_V2.UNPINNED, { reason });
825
+ }
826
+
827
+ export function getActiveGatewayCount(operatorId) {
828
+ let n = 0;
829
+ for (const r of _gatewaysV2.values()) {
830
+ if (r.status !== GATEWAY_MATURITY_V2.ACTIVE) continue;
831
+ if (operatorId && r.operatorId !== operatorId) continue;
832
+ n++;
833
+ }
834
+ return n;
835
+ }
836
+
837
+ export function getPendingPinCount(ownerId) {
838
+ let n = 0;
839
+ for (const r of _pinsV2.values()) {
840
+ if (r.status !== PIN_LIFECYCLE_V2.PENDING) continue;
841
+ if (ownerId && r.ownerId !== ownerId) continue;
842
+ n++;
843
+ }
844
+ return n;
845
+ }
846
+
847
+ export function autoOfflineStaleGateways(_db, nowMs) {
848
+ const now = nowMs ?? Date.now();
849
+ const flipped = [];
850
+ for (const r of _gatewaysV2.values()) {
851
+ if (
852
+ r.status === GATEWAY_MATURITY_V2.ACTIVE ||
853
+ r.status === GATEWAY_MATURITY_V2.DEGRADED
854
+ ) {
855
+ if (now - r.lastHeartbeatAt > _gatewayIdleMsV2) {
856
+ r.status = GATEWAY_MATURITY_V2.OFFLINE;
857
+ r.updatedAt = now;
858
+ r.lastReason = "heartbeat_timeout";
859
+ flipped.push(r.gatewayId);
860
+ }
861
+ }
862
+ }
863
+ return { flipped, count: flipped.length };
864
+ }
865
+
866
+ export function autoFailStalePendingPins(_db, nowMs) {
867
+ const now = nowMs ?? Date.now();
868
+ const flipped = [];
869
+ for (const r of _pinsV2.values()) {
870
+ if (r.status === PIN_LIFECYCLE_V2.PENDING) {
871
+ if (now - r.createdAt > _pinPendingMsV2) {
872
+ r.status = PIN_LIFECYCLE_V2.FAILED;
873
+ r.updatedAt = now;
874
+ r.lastReason = "pending_timeout";
875
+ flipped.push(r.pinId);
876
+ }
877
+ }
878
+ }
879
+ return { flipped, count: flipped.length };
880
+ }
881
+
882
+ export function getIpfsStatsV2() {
883
+ const gatewaysByStatus = {};
884
+ for (const s of Object.values(GATEWAY_MATURITY_V2)) gatewaysByStatus[s] = 0;
885
+ const pinsByStatus = {};
886
+ for (const s of Object.values(PIN_LIFECYCLE_V2)) pinsByStatus[s] = 0;
887
+ for (const r of _gatewaysV2.values()) gatewaysByStatus[r.status]++;
888
+ for (const r of _pinsV2.values()) pinsByStatus[r.status]++;
889
+ return {
890
+ totalGatewaysV2: _gatewaysV2.size,
891
+ totalPinsV2: _pinsV2.size,
892
+ maxActiveGatewaysPerOperator: _maxActiveGatewaysPerOperatorV2,
893
+ maxPendingPinsPerOwner: _maxPendingPinsPerOwnerV2,
894
+ gatewayIdleMs: _gatewayIdleMsV2,
895
+ pinPendingMs: _pinPendingMsV2,
896
+ gatewaysByStatus,
897
+ pinsByStatus,
898
+ };
899
+ }
900
+
901
+ export function _resetStateV2() {
902
+ _maxActiveGatewaysPerOperatorV2 =
903
+ IPFS_DEFAULT_MAX_ACTIVE_GATEWAYS_PER_OPERATOR;
904
+ _maxPendingPinsPerOwnerV2 = IPFS_DEFAULT_MAX_PENDING_PINS_PER_OWNER;
905
+ _gatewayIdleMsV2 = IPFS_DEFAULT_GATEWAY_IDLE_MS;
906
+ _pinPendingMsV2 = IPFS_DEFAULT_PIN_PENDING_MS;
907
+ _gatewaysV2.clear();
908
+ _pinsV2.clear();
909
+ }