chainlesschain 0.145.0 → 0.156.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 (184) hide show
  1. package/README.md +52 -3
  2. package/package.json +1 -1
  3. package/src/commands/a2a.js +201 -0
  4. package/src/commands/activitypub.js +207 -0
  5. package/src/commands/agent-network.js +217 -0
  6. package/src/commands/agent.js +1250 -0
  7. package/src/commands/automation.js +201 -0
  8. package/src/commands/bi.js +203 -0
  9. package/src/commands/browse.js +213 -0
  10. package/src/commands/chat.js +605 -0
  11. package/src/commands/cli-anything.js +426 -0
  12. package/src/commands/codegen.js +207 -0
  13. package/src/commands/collab.js +211 -0
  14. package/src/commands/compliance.js +822 -0
  15. package/src/commands/config.js +213 -0
  16. package/src/commands/cowork.js +1666 -0
  17. package/src/commands/crosschain.js +203 -0
  18. package/src/commands/dao.js +203 -0
  19. package/src/commands/dbevo.js +227 -0
  20. package/src/commands/dev.js +207 -0
  21. package/src/commands/did-v2.js +217 -0
  22. package/src/commands/did.js +221 -0
  23. package/src/commands/dlp.js +213 -0
  24. package/src/commands/economy.js +199 -0
  25. package/src/commands/encrypt.js +201 -0
  26. package/src/commands/evolution.js +199 -0
  27. package/src/commands/evomap.js +830 -0
  28. package/src/commands/export.js +213 -0
  29. package/src/commands/federation.js +209 -0
  30. package/src/commands/fusion.js +205 -0
  31. package/src/commands/governance.js +209 -0
  32. package/src/commands/hmemory.js +203 -0
  33. package/src/commands/hook.js +209 -0
  34. package/src/commands/import.js +209 -0
  35. package/src/commands/inference.js +207 -0
  36. package/src/commands/infra.js +203 -0
  37. package/src/commands/instinct.js +209 -0
  38. package/src/commands/ipfs.js +207 -0
  39. package/src/commands/kg.js +195 -0
  40. package/src/commands/llm.js +426 -0
  41. package/src/commands/matrix.js +207 -0
  42. package/src/commands/mcp.js +217 -0
  43. package/src/commands/memory.js +412 -0
  44. package/src/commands/multimodal.js +203 -0
  45. package/src/commands/nlprog.js +225 -0
  46. package/src/commands/nostr.js +209 -0
  47. package/src/commands/note.js +205 -0
  48. package/src/commands/ops.js +219 -0
  49. package/src/commands/orchestrate.js +406 -0
  50. package/src/commands/org.js +209 -0
  51. package/src/commands/p2p.js +209 -0
  52. package/src/commands/perception.js +209 -0
  53. package/src/commands/permmem.js +203 -0
  54. package/src/commands/pipeline.js +199 -0
  55. package/src/commands/planmode.js +426 -0
  56. package/src/commands/plugin-ecosystem.js +209 -0
  57. package/src/commands/plugin.js +209 -0
  58. package/src/commands/pqc.js +213 -0
  59. package/src/commands/quantization.js +207 -0
  60. package/src/commands/rcache.js +205 -0
  61. package/src/commands/recommend.js +233 -0
  62. package/src/commands/runtime.js +205 -0
  63. package/src/commands/scim.js +209 -0
  64. package/src/commands/services.js +207 -0
  65. package/src/commands/session.js +209 -0
  66. package/src/commands/setup.js +205 -0
  67. package/src/commands/skill.js +414 -0
  68. package/src/commands/social.js +201 -0
  69. package/src/commands/sso.js +209 -0
  70. package/src/commands/start.js +209 -0
  71. package/src/commands/stream.js +213 -0
  72. package/src/commands/sync.js +209 -0
  73. package/src/commands/tech.js +209 -0
  74. package/src/commands/tenant.js +217 -0
  75. package/src/commands/tokens.js +209 -0
  76. package/src/commands/trust.js +217 -0
  77. package/src/commands/ui.js +225 -0
  78. package/src/commands/wallet.js +209 -0
  79. package/src/commands/workflow.js +412 -0
  80. package/src/index.js +252 -0
  81. package/src/lib/a2a-protocol.js +332 -0
  82. package/src/lib/activitypub-bridge.js +334 -0
  83. package/src/lib/agent-coordinator.js +334 -0
  84. package/src/lib/agent-economy.js +334 -0
  85. package/src/lib/agent-network.js +341 -0
  86. package/src/lib/agent-router.js +333 -0
  87. package/src/lib/aiops.js +346 -0
  88. package/src/lib/automation-engine.js +335 -0
  89. package/src/lib/autonomous-agent.js +332 -0
  90. package/src/lib/autonomous-developer.js +332 -0
  91. package/src/lib/bi-engine.js +333 -0
  92. package/src/lib/browser-automation.js +334 -0
  93. package/src/lib/chat-core.js +335 -0
  94. package/src/lib/cli-anything-bridge.js +341 -0
  95. package/src/lib/cli-context-engineering.js +351 -0
  96. package/src/lib/code-agent.js +339 -0
  97. package/src/lib/collaboration-governance.js +334 -0
  98. package/src/lib/community-governance.js +346 -0
  99. package/src/lib/compliance-manager.js +334 -0
  100. package/src/lib/content-recommendation.js +351 -0
  101. package/src/lib/cowork-adapter.js +336 -0
  102. package/src/lib/cowork-evomap-adapter.js +341 -0
  103. package/src/lib/cowork-mcp-tools.js +341 -0
  104. package/src/lib/cowork-observe-html.js +341 -0
  105. package/src/lib/cowork-observe.js +341 -0
  106. package/src/lib/cowork-share.js +338 -0
  107. package/src/lib/cowork-task-templates.js +342 -1
  108. package/src/lib/cowork-template-marketplace.js +340 -0
  109. package/src/lib/cross-chain.js +339 -0
  110. package/src/lib/crypto-manager.js +334 -0
  111. package/src/lib/dao-governance.js +339 -0
  112. package/src/lib/dbevo.js +351 -0
  113. package/src/lib/decentral-infra.js +330 -0
  114. package/src/lib/did-manager.js +341 -0
  115. package/src/lib/did-v2-manager.js +341 -0
  116. package/src/lib/dlp-engine.js +339 -0
  117. package/src/lib/downloader.js +334 -0
  118. package/src/lib/evolution-system.js +334 -0
  119. package/src/lib/evomap-client.js +342 -0
  120. package/src/lib/evomap-federation.js +338 -0
  121. package/src/lib/evomap-governance.js +334 -0
  122. package/src/lib/evomap-manager.js +330 -0
  123. package/src/lib/execution-backend.js +330 -0
  124. package/src/lib/federation-hardening.js +340 -0
  125. package/src/lib/hashline.js +338 -0
  126. package/src/lib/hierarchical-memory.js +334 -0
  127. package/src/lib/hook-manager.js +341 -0
  128. package/src/lib/inference-network.js +341 -0
  129. package/src/lib/instinct-manager.js +346 -0
  130. package/src/lib/interaction-adapter.js +330 -0
  131. package/src/lib/interactive-planner.js +354 -0
  132. package/src/lib/ipfs-storage.js +334 -0
  133. package/src/lib/knowledge-exporter.js +341 -0
  134. package/src/lib/knowledge-graph.js +331 -0
  135. package/src/lib/knowledge-importer.js +341 -0
  136. package/src/lib/llm-providers.js +346 -0
  137. package/src/lib/matrix-bridge.js +339 -0
  138. package/src/lib/mcp-registry.js +346 -0
  139. package/src/lib/memory-manager.js +336 -0
  140. package/src/lib/multimodal.js +330 -0
  141. package/src/lib/nl-programming.js +341 -0
  142. package/src/lib/nostr-bridge.js +336 -0
  143. package/src/lib/note-versioning.js +339 -0
  144. package/src/lib/org-manager.js +336 -0
  145. package/src/lib/p2p-manager.js +341 -0
  146. package/src/lib/perception.js +346 -0
  147. package/src/lib/permanent-memory.js +327 -0
  148. package/src/lib/pipeline-orchestrator.js +332 -0
  149. package/src/lib/plan-mode.js +336 -0
  150. package/src/lib/plugin-autodiscovery.js +334 -0
  151. package/src/lib/plugin-ecosystem.js +346 -0
  152. package/src/lib/pqc-manager.js +346 -0
  153. package/src/lib/process-manager.js +336 -0
  154. package/src/lib/protocol-fusion.js +338 -0
  155. package/src/lib/provider-options.js +346 -0
  156. package/src/lib/provider-stream.js +348 -0
  157. package/src/lib/quantization.js +337 -0
  158. package/src/lib/response-cache.js +333 -0
  159. package/src/lib/scim-manager.js +346 -0
  160. package/src/lib/service-manager.js +337 -0
  161. package/src/lib/session-core-singletons.js +341 -0
  162. package/src/lib/session-manager.js +334 -0
  163. package/src/lib/skill-loader.js +334 -0
  164. package/src/lib/skill-mcp.js +336 -0
  165. package/src/lib/social-manager.js +330 -0
  166. package/src/lib/sso-manager.js +340 -0
  167. package/src/lib/stix-parser.js +346 -0
  168. package/src/lib/sub-agent-context.js +343 -0
  169. package/src/lib/sub-agent-profiles.js +335 -0
  170. package/src/lib/sub-agent-registry.js +336 -0
  171. package/src/lib/sync-manager.js +336 -0
  172. package/src/lib/tech-learning-engine.js +341 -0
  173. package/src/lib/tenant-saas.js +341 -0
  174. package/src/lib/threat-intel.js +330 -0
  175. package/src/lib/todo-manager.js +336 -0
  176. package/src/lib/token-tracker.js +336 -0
  177. package/src/lib/trust-security.js +343 -0
  178. package/src/lib/ueba.js +340 -0
  179. package/src/lib/universal-runtime.js +330 -0
  180. package/src/lib/wallet-manager.js +336 -0
  181. package/src/lib/web-ui-server.js +348 -0
  182. package/src/lib/workflow-engine.js +330 -0
  183. package/src/lib/workflow-expr.js +346 -0
  184. package/src/lib/ws-chat-handler.js +337 -0
@@ -415,3 +415,341 @@ export function getFederationStatsV2() {
415
415
  byMutationType,
416
416
  };
417
417
  }
418
+
419
+ // =====================================================================
420
+ // evomap-federation V2 governance overlay (iter25)
421
+ // =====================================================================
422
+ export const EVFEDGOV_PROFILE_MATURITY_V2 = Object.freeze({
423
+ PENDING: "pending",
424
+ ACTIVE: "active",
425
+ STALE: "stale",
426
+ ARCHIVED: "archived",
427
+ });
428
+ export const EVFEDGOV_SYNC_LIFECYCLE_V2 = Object.freeze({
429
+ QUEUED: "queued",
430
+ SYNCING: "syncing",
431
+ SYNCED: "synced",
432
+ FAILED: "failed",
433
+ CANCELLED: "cancelled",
434
+ });
435
+ const _evfedgovPTrans = new Map([
436
+ [
437
+ EVFEDGOV_PROFILE_MATURITY_V2.PENDING,
438
+ new Set([
439
+ EVFEDGOV_PROFILE_MATURITY_V2.ACTIVE,
440
+ EVFEDGOV_PROFILE_MATURITY_V2.ARCHIVED,
441
+ ]),
442
+ ],
443
+ [
444
+ EVFEDGOV_PROFILE_MATURITY_V2.ACTIVE,
445
+ new Set([
446
+ EVFEDGOV_PROFILE_MATURITY_V2.STALE,
447
+ EVFEDGOV_PROFILE_MATURITY_V2.ARCHIVED,
448
+ ]),
449
+ ],
450
+ [
451
+ EVFEDGOV_PROFILE_MATURITY_V2.STALE,
452
+ new Set([
453
+ EVFEDGOV_PROFILE_MATURITY_V2.ACTIVE,
454
+ EVFEDGOV_PROFILE_MATURITY_V2.ARCHIVED,
455
+ ]),
456
+ ],
457
+ [EVFEDGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
458
+ ]);
459
+ const _evfedgovPTerminal = new Set([EVFEDGOV_PROFILE_MATURITY_V2.ARCHIVED]);
460
+ const _evfedgovJTrans = new Map([
461
+ [
462
+ EVFEDGOV_SYNC_LIFECYCLE_V2.QUEUED,
463
+ new Set([
464
+ EVFEDGOV_SYNC_LIFECYCLE_V2.SYNCING,
465
+ EVFEDGOV_SYNC_LIFECYCLE_V2.CANCELLED,
466
+ ]),
467
+ ],
468
+ [
469
+ EVFEDGOV_SYNC_LIFECYCLE_V2.SYNCING,
470
+ new Set([
471
+ EVFEDGOV_SYNC_LIFECYCLE_V2.SYNCED,
472
+ EVFEDGOV_SYNC_LIFECYCLE_V2.FAILED,
473
+ EVFEDGOV_SYNC_LIFECYCLE_V2.CANCELLED,
474
+ ]),
475
+ ],
476
+ [EVFEDGOV_SYNC_LIFECYCLE_V2.SYNCED, new Set()],
477
+ [EVFEDGOV_SYNC_LIFECYCLE_V2.FAILED, new Set()],
478
+ [EVFEDGOV_SYNC_LIFECYCLE_V2.CANCELLED, new Set()],
479
+ ]);
480
+ const _evfedgovPsV2 = new Map();
481
+ const _evfedgovJsV2 = new Map();
482
+ let _evfedgovMaxActive = 6,
483
+ _evfedgovMaxPending = 15,
484
+ _evfedgovIdleMs = 30 * 24 * 60 * 60 * 1000,
485
+ _evfedgovStuckMs = 60 * 1000;
486
+ function _evfedgovPos(n, label) {
487
+ const v = Math.floor(Number(n));
488
+ if (!Number.isFinite(v) || v <= 0)
489
+ throw new Error(`${label} must be positive integer`);
490
+ return v;
491
+ }
492
+ function _evfedgovCheckP(from, to) {
493
+ const a = _evfedgovPTrans.get(from);
494
+ if (!a || !a.has(to))
495
+ throw new Error(`invalid evfedgov profile transition ${from} → ${to}`);
496
+ }
497
+ function _evfedgovCheckJ(from, to) {
498
+ const a = _evfedgovJTrans.get(from);
499
+ if (!a || !a.has(to))
500
+ throw new Error(`invalid evfedgov sync transition ${from} → ${to}`);
501
+ }
502
+ function _evfedgovCountActive(owner) {
503
+ let c = 0;
504
+ for (const p of _evfedgovPsV2.values())
505
+ if (p.owner === owner && p.status === EVFEDGOV_PROFILE_MATURITY_V2.ACTIVE)
506
+ c++;
507
+ return c;
508
+ }
509
+ function _evfedgovCountPending(profileId) {
510
+ let c = 0;
511
+ for (const j of _evfedgovJsV2.values())
512
+ if (
513
+ j.profileId === profileId &&
514
+ (j.status === EVFEDGOV_SYNC_LIFECYCLE_V2.QUEUED ||
515
+ j.status === EVFEDGOV_SYNC_LIFECYCLE_V2.SYNCING)
516
+ )
517
+ c++;
518
+ return c;
519
+ }
520
+ export function setMaxActiveEvfedgovProfilesPerOwnerV2(n) {
521
+ _evfedgovMaxActive = _evfedgovPos(n, "maxActiveEvfedgovProfilesPerOwner");
522
+ }
523
+ export function getMaxActiveEvfedgovProfilesPerOwnerV2() {
524
+ return _evfedgovMaxActive;
525
+ }
526
+ export function setMaxPendingEvfedgovSyncsPerProfileV2(n) {
527
+ _evfedgovMaxPending = _evfedgovPos(n, "maxPendingEvfedgovSyncsPerProfile");
528
+ }
529
+ export function getMaxPendingEvfedgovSyncsPerProfileV2() {
530
+ return _evfedgovMaxPending;
531
+ }
532
+ export function setEvfedgovProfileIdleMsV2(n) {
533
+ _evfedgovIdleMs = _evfedgovPos(n, "evfedgovProfileIdleMs");
534
+ }
535
+ export function getEvfedgovProfileIdleMsV2() {
536
+ return _evfedgovIdleMs;
537
+ }
538
+ export function setEvfedgovSyncStuckMsV2(n) {
539
+ _evfedgovStuckMs = _evfedgovPos(n, "evfedgovSyncStuckMs");
540
+ }
541
+ export function getEvfedgovSyncStuckMsV2() {
542
+ return _evfedgovStuckMs;
543
+ }
544
+ export function _resetStateEvomapFederationGovV2() {
545
+ _evfedgovPsV2.clear();
546
+ _evfedgovJsV2.clear();
547
+ _evfedgovMaxActive = 6;
548
+ _evfedgovMaxPending = 15;
549
+ _evfedgovIdleMs = 30 * 24 * 60 * 60 * 1000;
550
+ _evfedgovStuckMs = 60 * 1000;
551
+ }
552
+ export function registerEvfedgovProfileV2({ id, owner, hub, metadata } = {}) {
553
+ if (!id || !owner) throw new Error("id and owner required");
554
+ if (_evfedgovPsV2.has(id))
555
+ throw new Error(`evfedgov profile ${id} already exists`);
556
+ const now = Date.now();
557
+ const p = {
558
+ id,
559
+ owner,
560
+ hub: hub || "primary",
561
+ status: EVFEDGOV_PROFILE_MATURITY_V2.PENDING,
562
+ createdAt: now,
563
+ updatedAt: now,
564
+ lastTouchedAt: now,
565
+ activatedAt: null,
566
+ archivedAt: null,
567
+ metadata: { ...(metadata || {}) },
568
+ };
569
+ _evfedgovPsV2.set(id, p);
570
+ return { ...p, metadata: { ...p.metadata } };
571
+ }
572
+ export function activateEvfedgovProfileV2(id) {
573
+ const p = _evfedgovPsV2.get(id);
574
+ if (!p) throw new Error(`evfedgov profile ${id} not found`);
575
+ const isInitial = p.status === EVFEDGOV_PROFILE_MATURITY_V2.PENDING;
576
+ _evfedgovCheckP(p.status, EVFEDGOV_PROFILE_MATURITY_V2.ACTIVE);
577
+ if (isInitial && _evfedgovCountActive(p.owner) >= _evfedgovMaxActive)
578
+ throw new Error(
579
+ `max active evfedgov profiles for owner ${p.owner} reached`,
580
+ );
581
+ const now = Date.now();
582
+ p.status = EVFEDGOV_PROFILE_MATURITY_V2.ACTIVE;
583
+ p.updatedAt = now;
584
+ p.lastTouchedAt = now;
585
+ if (!p.activatedAt) p.activatedAt = now;
586
+ return { ...p, metadata: { ...p.metadata } };
587
+ }
588
+ export function staleEvfedgovProfileV2(id) {
589
+ const p = _evfedgovPsV2.get(id);
590
+ if (!p) throw new Error(`evfedgov profile ${id} not found`);
591
+ _evfedgovCheckP(p.status, EVFEDGOV_PROFILE_MATURITY_V2.STALE);
592
+ p.status = EVFEDGOV_PROFILE_MATURITY_V2.STALE;
593
+ p.updatedAt = Date.now();
594
+ return { ...p, metadata: { ...p.metadata } };
595
+ }
596
+ export function archiveEvfedgovProfileV2(id) {
597
+ const p = _evfedgovPsV2.get(id);
598
+ if (!p) throw new Error(`evfedgov profile ${id} not found`);
599
+ _evfedgovCheckP(p.status, EVFEDGOV_PROFILE_MATURITY_V2.ARCHIVED);
600
+ const now = Date.now();
601
+ p.status = EVFEDGOV_PROFILE_MATURITY_V2.ARCHIVED;
602
+ p.updatedAt = now;
603
+ if (!p.archivedAt) p.archivedAt = now;
604
+ return { ...p, metadata: { ...p.metadata } };
605
+ }
606
+ export function touchEvfedgovProfileV2(id) {
607
+ const p = _evfedgovPsV2.get(id);
608
+ if (!p) throw new Error(`evfedgov profile ${id} not found`);
609
+ if (_evfedgovPTerminal.has(p.status))
610
+ throw new Error(`cannot touch terminal evfedgov profile ${id}`);
611
+ const now = Date.now();
612
+ p.lastTouchedAt = now;
613
+ p.updatedAt = now;
614
+ return { ...p, metadata: { ...p.metadata } };
615
+ }
616
+ export function getEvfedgovProfileV2(id) {
617
+ const p = _evfedgovPsV2.get(id);
618
+ if (!p) return null;
619
+ return { ...p, metadata: { ...p.metadata } };
620
+ }
621
+ export function listEvfedgovProfilesV2() {
622
+ return [..._evfedgovPsV2.values()].map((p) => ({
623
+ ...p,
624
+ metadata: { ...p.metadata },
625
+ }));
626
+ }
627
+ export function createEvfedgovSyncV2({ id, profileId, geneId, metadata } = {}) {
628
+ if (!id || !profileId) throw new Error("id and profileId required");
629
+ if (_evfedgovJsV2.has(id))
630
+ throw new Error(`evfedgov sync ${id} already exists`);
631
+ if (!_evfedgovPsV2.has(profileId))
632
+ throw new Error(`evfedgov profile ${profileId} not found`);
633
+ if (_evfedgovCountPending(profileId) >= _evfedgovMaxPending)
634
+ throw new Error(
635
+ `max pending evfedgov syncs for profile ${profileId} reached`,
636
+ );
637
+ const now = Date.now();
638
+ const j = {
639
+ id,
640
+ profileId,
641
+ geneId: geneId || "",
642
+ status: EVFEDGOV_SYNC_LIFECYCLE_V2.QUEUED,
643
+ createdAt: now,
644
+ updatedAt: now,
645
+ startedAt: null,
646
+ settledAt: null,
647
+ metadata: { ...(metadata || {}) },
648
+ };
649
+ _evfedgovJsV2.set(id, j);
650
+ return { ...j, metadata: { ...j.metadata } };
651
+ }
652
+ export function syncingEvfedgovSyncV2(id) {
653
+ const j = _evfedgovJsV2.get(id);
654
+ if (!j) throw new Error(`evfedgov sync ${id} not found`);
655
+ _evfedgovCheckJ(j.status, EVFEDGOV_SYNC_LIFECYCLE_V2.SYNCING);
656
+ const now = Date.now();
657
+ j.status = EVFEDGOV_SYNC_LIFECYCLE_V2.SYNCING;
658
+ j.updatedAt = now;
659
+ if (!j.startedAt) j.startedAt = now;
660
+ return { ...j, metadata: { ...j.metadata } };
661
+ }
662
+ export function completeSyncEvfedgovV2(id) {
663
+ const j = _evfedgovJsV2.get(id);
664
+ if (!j) throw new Error(`evfedgov sync ${id} not found`);
665
+ _evfedgovCheckJ(j.status, EVFEDGOV_SYNC_LIFECYCLE_V2.SYNCED);
666
+ const now = Date.now();
667
+ j.status = EVFEDGOV_SYNC_LIFECYCLE_V2.SYNCED;
668
+ j.updatedAt = now;
669
+ if (!j.settledAt) j.settledAt = now;
670
+ return { ...j, metadata: { ...j.metadata } };
671
+ }
672
+ export function failEvfedgovSyncV2(id, reason) {
673
+ const j = _evfedgovJsV2.get(id);
674
+ if (!j) throw new Error(`evfedgov sync ${id} not found`);
675
+ _evfedgovCheckJ(j.status, EVFEDGOV_SYNC_LIFECYCLE_V2.FAILED);
676
+ const now = Date.now();
677
+ j.status = EVFEDGOV_SYNC_LIFECYCLE_V2.FAILED;
678
+ j.updatedAt = now;
679
+ if (!j.settledAt) j.settledAt = now;
680
+ if (reason) j.metadata.failReason = String(reason);
681
+ return { ...j, metadata: { ...j.metadata } };
682
+ }
683
+ export function cancelEvfedgovSyncV2(id, reason) {
684
+ const j = _evfedgovJsV2.get(id);
685
+ if (!j) throw new Error(`evfedgov sync ${id} not found`);
686
+ _evfedgovCheckJ(j.status, EVFEDGOV_SYNC_LIFECYCLE_V2.CANCELLED);
687
+ const now = Date.now();
688
+ j.status = EVFEDGOV_SYNC_LIFECYCLE_V2.CANCELLED;
689
+ j.updatedAt = now;
690
+ if (!j.settledAt) j.settledAt = now;
691
+ if (reason) j.metadata.cancelReason = String(reason);
692
+ return { ...j, metadata: { ...j.metadata } };
693
+ }
694
+ export function getEvfedgovSyncV2(id) {
695
+ const j = _evfedgovJsV2.get(id);
696
+ if (!j) return null;
697
+ return { ...j, metadata: { ...j.metadata } };
698
+ }
699
+ export function listEvfedgovSyncsV2() {
700
+ return [..._evfedgovJsV2.values()].map((j) => ({
701
+ ...j,
702
+ metadata: { ...j.metadata },
703
+ }));
704
+ }
705
+ export function autoStaleIdleEvfedgovProfilesV2({ now } = {}) {
706
+ const t = now ?? Date.now();
707
+ const flipped = [];
708
+ for (const p of _evfedgovPsV2.values())
709
+ if (
710
+ p.status === EVFEDGOV_PROFILE_MATURITY_V2.ACTIVE &&
711
+ t - p.lastTouchedAt >= _evfedgovIdleMs
712
+ ) {
713
+ p.status = EVFEDGOV_PROFILE_MATURITY_V2.STALE;
714
+ p.updatedAt = t;
715
+ flipped.push(p.id);
716
+ }
717
+ return { flipped, count: flipped.length };
718
+ }
719
+ export function autoFailStuckEvfedgovSyncsV2({ now } = {}) {
720
+ const t = now ?? Date.now();
721
+ const flipped = [];
722
+ for (const j of _evfedgovJsV2.values())
723
+ if (
724
+ j.status === EVFEDGOV_SYNC_LIFECYCLE_V2.SYNCING &&
725
+ j.startedAt != null &&
726
+ t - j.startedAt >= _evfedgovStuckMs
727
+ ) {
728
+ j.status = EVFEDGOV_SYNC_LIFECYCLE_V2.FAILED;
729
+ j.updatedAt = t;
730
+ if (!j.settledAt) j.settledAt = t;
731
+ j.metadata.failReason = "auto-fail-stuck";
732
+ flipped.push(j.id);
733
+ }
734
+ return { flipped, count: flipped.length };
735
+ }
736
+ export function getEvomapFederationGovStatsV2() {
737
+ const profilesByStatus = {};
738
+ for (const v of Object.values(EVFEDGOV_PROFILE_MATURITY_V2))
739
+ profilesByStatus[v] = 0;
740
+ for (const p of _evfedgovPsV2.values()) profilesByStatus[p.status]++;
741
+ const syncsByStatus = {};
742
+ for (const v of Object.values(EVFEDGOV_SYNC_LIFECYCLE_V2))
743
+ syncsByStatus[v] = 0;
744
+ for (const j of _evfedgovJsV2.values()) syncsByStatus[j.status]++;
745
+ return {
746
+ totalEvfedgovProfilesV2: _evfedgovPsV2.size,
747
+ totalEvfedgovSyncsV2: _evfedgovJsV2.size,
748
+ maxActiveEvfedgovProfilesPerOwner: _evfedgovMaxActive,
749
+ maxPendingEvfedgovSyncsPerProfile: _evfedgovMaxPending,
750
+ evfedgovProfileIdleMs: _evfedgovIdleMs,
751
+ evfedgovSyncStuckMs: _evfedgovStuckMs,
752
+ profilesByStatus,
753
+ syncsByStatus,
754
+ };
755
+ }
@@ -524,3 +524,337 @@ export function getGovernanceStatsV2() {
524
524
  byType,
525
525
  };
526
526
  }
527
+
528
+ // =====================================================================
529
+ // evomap-governance V2 governance overlay (iter20)
530
+ // =====================================================================
531
+ export const EVGOV_PROFILE_MATURITY_V2 = Object.freeze({
532
+ PENDING: "pending",
533
+ ACTIVE: "active",
534
+ PAUSED: "paused",
535
+ ARCHIVED: "archived",
536
+ });
537
+ export const EVGOV_PROPOSAL_LIFECYCLE_V2 = Object.freeze({
538
+ QUEUED: "queued",
539
+ REVIEWING: "reviewing",
540
+ REVIEWED: "reviewed",
541
+ FAILED: "failed",
542
+ CANCELLED: "cancelled",
543
+ });
544
+ const _evgovPTrans = new Map([
545
+ [
546
+ EVGOV_PROFILE_MATURITY_V2.PENDING,
547
+ new Set([
548
+ EVGOV_PROFILE_MATURITY_V2.ACTIVE,
549
+ EVGOV_PROFILE_MATURITY_V2.ARCHIVED,
550
+ ]),
551
+ ],
552
+ [
553
+ EVGOV_PROFILE_MATURITY_V2.ACTIVE,
554
+ new Set([
555
+ EVGOV_PROFILE_MATURITY_V2.PAUSED,
556
+ EVGOV_PROFILE_MATURITY_V2.ARCHIVED,
557
+ ]),
558
+ ],
559
+ [
560
+ EVGOV_PROFILE_MATURITY_V2.PAUSED,
561
+ new Set([
562
+ EVGOV_PROFILE_MATURITY_V2.ACTIVE,
563
+ EVGOV_PROFILE_MATURITY_V2.ARCHIVED,
564
+ ]),
565
+ ],
566
+ [EVGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
567
+ ]);
568
+ const _evgovPTerminal = new Set([EVGOV_PROFILE_MATURITY_V2.ARCHIVED]);
569
+ const _evgovJTrans = new Map([
570
+ [
571
+ EVGOV_PROPOSAL_LIFECYCLE_V2.QUEUED,
572
+ new Set([
573
+ EVGOV_PROPOSAL_LIFECYCLE_V2.REVIEWING,
574
+ EVGOV_PROPOSAL_LIFECYCLE_V2.CANCELLED,
575
+ ]),
576
+ ],
577
+ [
578
+ EVGOV_PROPOSAL_LIFECYCLE_V2.REVIEWING,
579
+ new Set([
580
+ EVGOV_PROPOSAL_LIFECYCLE_V2.REVIEWED,
581
+ EVGOV_PROPOSAL_LIFECYCLE_V2.FAILED,
582
+ EVGOV_PROPOSAL_LIFECYCLE_V2.CANCELLED,
583
+ ]),
584
+ ],
585
+ [EVGOV_PROPOSAL_LIFECYCLE_V2.REVIEWED, new Set()],
586
+ [EVGOV_PROPOSAL_LIFECYCLE_V2.FAILED, new Set()],
587
+ [EVGOV_PROPOSAL_LIFECYCLE_V2.CANCELLED, new Set()],
588
+ ]);
589
+ const _evgovPsV2 = new Map();
590
+ const _evgovJsV2 = new Map();
591
+ let _evgovMaxActive = 6,
592
+ _evgovMaxPending = 15,
593
+ _evgovIdleMs = 30 * 24 * 60 * 60 * 1000,
594
+ _evgovStuckMs = 60 * 1000;
595
+ function _evgovPos(n, label) {
596
+ const v = Math.floor(Number(n));
597
+ if (!Number.isFinite(v) || v <= 0)
598
+ throw new Error(`${label} must be positive integer`);
599
+ return v;
600
+ }
601
+ function _evgovCheckP(from, to) {
602
+ const a = _evgovPTrans.get(from);
603
+ if (!a || !a.has(to))
604
+ throw new Error(`invalid evgov profile transition ${from} → ${to}`);
605
+ }
606
+ function _evgovCheckJ(from, to) {
607
+ const a = _evgovJTrans.get(from);
608
+ if (!a || !a.has(to))
609
+ throw new Error(`invalid evgov proposal transition ${from} → ${to}`);
610
+ }
611
+ function _evgovCountActive(owner) {
612
+ let c = 0;
613
+ for (const p of _evgovPsV2.values())
614
+ if (p.owner === owner && p.status === EVGOV_PROFILE_MATURITY_V2.ACTIVE) c++;
615
+ return c;
616
+ }
617
+ function _evgovCountPending(profileId) {
618
+ let c = 0;
619
+ for (const j of _evgovJsV2.values())
620
+ if (
621
+ j.profileId === profileId &&
622
+ (j.status === EVGOV_PROPOSAL_LIFECYCLE_V2.QUEUED ||
623
+ j.status === EVGOV_PROPOSAL_LIFECYCLE_V2.REVIEWING)
624
+ )
625
+ c++;
626
+ return c;
627
+ }
628
+ export function setMaxActiveEvgovProfilesPerOwnerV2(n) {
629
+ _evgovMaxActive = _evgovPos(n, "maxActiveEvgovProfilesPerOwner");
630
+ }
631
+ export function getMaxActiveEvgovProfilesPerOwnerV2() {
632
+ return _evgovMaxActive;
633
+ }
634
+ export function setMaxPendingEvgovProposalsPerProfileV2(n) {
635
+ _evgovMaxPending = _evgovPos(n, "maxPendingEvgovProposalsPerProfile");
636
+ }
637
+ export function getMaxPendingEvgovProposalsPerProfileV2() {
638
+ return _evgovMaxPending;
639
+ }
640
+ export function setEvgovProfileIdleMsV2(n) {
641
+ _evgovIdleMs = _evgovPos(n, "evgovProfileIdleMs");
642
+ }
643
+ export function getEvgovProfileIdleMsV2() {
644
+ return _evgovIdleMs;
645
+ }
646
+ export function setEvgovProposalStuckMsV2(n) {
647
+ _evgovStuckMs = _evgovPos(n, "evgovProposalStuckMs");
648
+ }
649
+ export function getEvgovProposalStuckMsV2() {
650
+ return _evgovStuckMs;
651
+ }
652
+ export function _resetStateEvomapGovernanceGovV2() {
653
+ _evgovPsV2.clear();
654
+ _evgovJsV2.clear();
655
+ _evgovMaxActive = 6;
656
+ _evgovMaxPending = 15;
657
+ _evgovIdleMs = 30 * 24 * 60 * 60 * 1000;
658
+ _evgovStuckMs = 60 * 1000;
659
+ }
660
+ export function registerEvgovProfileV2({ id, owner, lane, metadata } = {}) {
661
+ if (!id || !owner) throw new Error("id and owner required");
662
+ if (_evgovPsV2.has(id)) throw new Error(`evgov profile ${id} already exists`);
663
+ const now = Date.now();
664
+ const p = {
665
+ id,
666
+ owner,
667
+ lane: lane || "core",
668
+ status: EVGOV_PROFILE_MATURITY_V2.PENDING,
669
+ createdAt: now,
670
+ updatedAt: now,
671
+ lastTouchedAt: now,
672
+ activatedAt: null,
673
+ archivedAt: null,
674
+ metadata: { ...(metadata || {}) },
675
+ };
676
+ _evgovPsV2.set(id, p);
677
+ return { ...p, metadata: { ...p.metadata } };
678
+ }
679
+ export function activateEvgovProfileV2(id) {
680
+ const p = _evgovPsV2.get(id);
681
+ if (!p) throw new Error(`evgov profile ${id} not found`);
682
+ const isInitial = p.status === EVGOV_PROFILE_MATURITY_V2.PENDING;
683
+ _evgovCheckP(p.status, EVGOV_PROFILE_MATURITY_V2.ACTIVE);
684
+ if (isInitial && _evgovCountActive(p.owner) >= _evgovMaxActive)
685
+ throw new Error(`max active evgov profiles for owner ${p.owner} reached`);
686
+ const now = Date.now();
687
+ p.status = EVGOV_PROFILE_MATURITY_V2.ACTIVE;
688
+ p.updatedAt = now;
689
+ p.lastTouchedAt = now;
690
+ if (!p.activatedAt) p.activatedAt = now;
691
+ return { ...p, metadata: { ...p.metadata } };
692
+ }
693
+ export function pauseEvgovProfileV2(id) {
694
+ const p = _evgovPsV2.get(id);
695
+ if (!p) throw new Error(`evgov profile ${id} not found`);
696
+ _evgovCheckP(p.status, EVGOV_PROFILE_MATURITY_V2.PAUSED);
697
+ p.status = EVGOV_PROFILE_MATURITY_V2.PAUSED;
698
+ p.updatedAt = Date.now();
699
+ return { ...p, metadata: { ...p.metadata } };
700
+ }
701
+ export function archiveEvgovProfileV2(id) {
702
+ const p = _evgovPsV2.get(id);
703
+ if (!p) throw new Error(`evgov profile ${id} not found`);
704
+ _evgovCheckP(p.status, EVGOV_PROFILE_MATURITY_V2.ARCHIVED);
705
+ const now = Date.now();
706
+ p.status = EVGOV_PROFILE_MATURITY_V2.ARCHIVED;
707
+ p.updatedAt = now;
708
+ if (!p.archivedAt) p.archivedAt = now;
709
+ return { ...p, metadata: { ...p.metadata } };
710
+ }
711
+ export function touchEvgovProfileV2(id) {
712
+ const p = _evgovPsV2.get(id);
713
+ if (!p) throw new Error(`evgov profile ${id} not found`);
714
+ if (_evgovPTerminal.has(p.status))
715
+ throw new Error(`cannot touch terminal evgov profile ${id}`);
716
+ const now = Date.now();
717
+ p.lastTouchedAt = now;
718
+ p.updatedAt = now;
719
+ return { ...p, metadata: { ...p.metadata } };
720
+ }
721
+ export function getEvgovProfileV2(id) {
722
+ const p = _evgovPsV2.get(id);
723
+ if (!p) return null;
724
+ return { ...p, metadata: { ...p.metadata } };
725
+ }
726
+ export function listEvgovProfilesV2() {
727
+ return [..._evgovPsV2.values()].map((p) => ({
728
+ ...p,
729
+ metadata: { ...p.metadata },
730
+ }));
731
+ }
732
+ export function createEvgovProposalV2({ id, profileId, topic, metadata } = {}) {
733
+ if (!id || !profileId) throw new Error("id and profileId required");
734
+ if (_evgovJsV2.has(id))
735
+ throw new Error(`evgov proposal ${id} already exists`);
736
+ if (!_evgovPsV2.has(profileId))
737
+ throw new Error(`evgov profile ${profileId} not found`);
738
+ if (_evgovCountPending(profileId) >= _evgovMaxPending)
739
+ throw new Error(
740
+ `max pending evgov proposals for profile ${profileId} reached`,
741
+ );
742
+ const now = Date.now();
743
+ const j = {
744
+ id,
745
+ profileId,
746
+ topic: topic || "",
747
+ status: EVGOV_PROPOSAL_LIFECYCLE_V2.QUEUED,
748
+ createdAt: now,
749
+ updatedAt: now,
750
+ startedAt: null,
751
+ settledAt: null,
752
+ metadata: { ...(metadata || {}) },
753
+ };
754
+ _evgovJsV2.set(id, j);
755
+ return { ...j, metadata: { ...j.metadata } };
756
+ }
757
+ export function reviewingEvgovProposalV2(id) {
758
+ const j = _evgovJsV2.get(id);
759
+ if (!j) throw new Error(`evgov proposal ${id} not found`);
760
+ _evgovCheckJ(j.status, EVGOV_PROPOSAL_LIFECYCLE_V2.REVIEWING);
761
+ const now = Date.now();
762
+ j.status = EVGOV_PROPOSAL_LIFECYCLE_V2.REVIEWING;
763
+ j.updatedAt = now;
764
+ if (!j.startedAt) j.startedAt = now;
765
+ return { ...j, metadata: { ...j.metadata } };
766
+ }
767
+ export function completeProposalEvgovV2(id) {
768
+ const j = _evgovJsV2.get(id);
769
+ if (!j) throw new Error(`evgov proposal ${id} not found`);
770
+ _evgovCheckJ(j.status, EVGOV_PROPOSAL_LIFECYCLE_V2.REVIEWED);
771
+ const now = Date.now();
772
+ j.status = EVGOV_PROPOSAL_LIFECYCLE_V2.REVIEWED;
773
+ j.updatedAt = now;
774
+ if (!j.settledAt) j.settledAt = now;
775
+ return { ...j, metadata: { ...j.metadata } };
776
+ }
777
+ export function failEvgovProposalV2(id, reason) {
778
+ const j = _evgovJsV2.get(id);
779
+ if (!j) throw new Error(`evgov proposal ${id} not found`);
780
+ _evgovCheckJ(j.status, EVGOV_PROPOSAL_LIFECYCLE_V2.FAILED);
781
+ const now = Date.now();
782
+ j.status = EVGOV_PROPOSAL_LIFECYCLE_V2.FAILED;
783
+ j.updatedAt = now;
784
+ if (!j.settledAt) j.settledAt = now;
785
+ if (reason) j.metadata.failReason = String(reason);
786
+ return { ...j, metadata: { ...j.metadata } };
787
+ }
788
+ export function cancelEvgovProposalV2(id, reason) {
789
+ const j = _evgovJsV2.get(id);
790
+ if (!j) throw new Error(`evgov proposal ${id} not found`);
791
+ _evgovCheckJ(j.status, EVGOV_PROPOSAL_LIFECYCLE_V2.CANCELLED);
792
+ const now = Date.now();
793
+ j.status = EVGOV_PROPOSAL_LIFECYCLE_V2.CANCELLED;
794
+ j.updatedAt = now;
795
+ if (!j.settledAt) j.settledAt = now;
796
+ if (reason) j.metadata.cancelReason = String(reason);
797
+ return { ...j, metadata: { ...j.metadata } };
798
+ }
799
+ export function getEvgovProposalV2(id) {
800
+ const j = _evgovJsV2.get(id);
801
+ if (!j) return null;
802
+ return { ...j, metadata: { ...j.metadata } };
803
+ }
804
+ export function listEvgovProposalsV2() {
805
+ return [..._evgovJsV2.values()].map((j) => ({
806
+ ...j,
807
+ metadata: { ...j.metadata },
808
+ }));
809
+ }
810
+ export function autoPauseIdleEvgovProfilesV2({ now } = {}) {
811
+ const t = now ?? Date.now();
812
+ const flipped = [];
813
+ for (const p of _evgovPsV2.values())
814
+ if (
815
+ p.status === EVGOV_PROFILE_MATURITY_V2.ACTIVE &&
816
+ t - p.lastTouchedAt >= _evgovIdleMs
817
+ ) {
818
+ p.status = EVGOV_PROFILE_MATURITY_V2.PAUSED;
819
+ p.updatedAt = t;
820
+ flipped.push(p.id);
821
+ }
822
+ return { flipped, count: flipped.length };
823
+ }
824
+ export function autoFailStuckEvgovProposalsV2({ now } = {}) {
825
+ const t = now ?? Date.now();
826
+ const flipped = [];
827
+ for (const j of _evgovJsV2.values())
828
+ if (
829
+ j.status === EVGOV_PROPOSAL_LIFECYCLE_V2.REVIEWING &&
830
+ j.startedAt != null &&
831
+ t - j.startedAt >= _evgovStuckMs
832
+ ) {
833
+ j.status = EVGOV_PROPOSAL_LIFECYCLE_V2.FAILED;
834
+ j.updatedAt = t;
835
+ if (!j.settledAt) j.settledAt = t;
836
+ j.metadata.failReason = "auto-fail-stuck";
837
+ flipped.push(j.id);
838
+ }
839
+ return { flipped, count: flipped.length };
840
+ }
841
+ export function getEvomapGovernanceGovStatsV2() {
842
+ const profilesByStatus = {};
843
+ for (const v of Object.values(EVGOV_PROFILE_MATURITY_V2))
844
+ profilesByStatus[v] = 0;
845
+ for (const p of _evgovPsV2.values()) profilesByStatus[p.status]++;
846
+ const proposalsByStatus = {};
847
+ for (const v of Object.values(EVGOV_PROPOSAL_LIFECYCLE_V2))
848
+ proposalsByStatus[v] = 0;
849
+ for (const j of _evgovJsV2.values()) proposalsByStatus[j.status]++;
850
+ return {
851
+ totalEvgovProfilesV2: _evgovPsV2.size,
852
+ totalEvgovProposalsV2: _evgovJsV2.size,
853
+ maxActiveEvgovProfilesPerOwner: _evgovMaxActive,
854
+ maxPendingEvgovProposalsPerProfile: _evgovMaxPending,
855
+ evgovProfileIdleMs: _evgovIdleMs,
856
+ evgovProposalStuckMs: _evgovStuckMs,
857
+ profilesByStatus,
858
+ proposalsByStatus,
859
+ };
860
+ }