chainlesschain 0.143.0 → 0.152.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 (227) hide show
  1. package/package.json +1 -1
  2. package/src/commands/a2a.js +196 -28
  3. package/src/commands/activitypub.js +364 -27
  4. package/src/commands/agent-network.js +217 -0
  5. package/src/commands/agent.js +587 -103
  6. package/src/commands/audit.js +206 -0
  7. package/src/commands/automation.js +201 -0
  8. package/src/commands/bi.js +355 -27
  9. package/src/commands/bm25.js +111 -27
  10. package/src/commands/browse.js +403 -29
  11. package/src/commands/ccron.js +128 -28
  12. package/src/commands/chat.js +207 -0
  13. package/src/commands/codegen.js +207 -0
  14. package/src/commands/collab.js +211 -0
  15. package/src/commands/compliance.js +824 -34
  16. package/src/commands/compt.js +127 -29
  17. package/src/commands/consol.js +8 -2
  18. package/src/commands/cowork.js +783 -34
  19. package/src/commands/crosschain.js +182 -28
  20. package/src/commands/dao.js +182 -28
  21. package/src/commands/dbevo.js +227 -0
  22. package/src/commands/dev.js +207 -0
  23. package/src/commands/did-v2.js +217 -0
  24. package/src/commands/did.js +221 -0
  25. package/src/commands/dlp.js +385 -27
  26. package/src/commands/economy.js +205 -50
  27. package/src/commands/evolution.js +203 -50
  28. package/src/commands/evomap.js +387 -27
  29. package/src/commands/export.js +213 -0
  30. package/src/commands/federation.js +209 -0
  31. package/src/commands/fflag.js +74 -22
  32. package/src/commands/fusion.js +205 -0
  33. package/src/commands/git.js +177 -37
  34. package/src/commands/governance.js +209 -0
  35. package/src/commands/hardening.js +209 -0
  36. package/src/commands/hmemory.js +204 -50
  37. package/src/commands/hook.js +209 -0
  38. package/src/commands/import.js +209 -0
  39. package/src/commands/incentive.js +209 -0
  40. package/src/commands/inference.js +170 -34
  41. package/src/commands/infra.js +203 -0
  42. package/src/commands/instinct.js +209 -0
  43. package/src/commands/ipfs.js +207 -0
  44. package/src/commands/itbudget.js +149 -33
  45. package/src/commands/kg.js +206 -0
  46. package/src/commands/llm.js +217 -0
  47. package/src/commands/lowcode.js +195 -38
  48. package/src/commands/marketplace.js +206 -0
  49. package/src/commands/matrix.js +386 -27
  50. package/src/commands/mcp.js +217 -0
  51. package/src/commands/mcpscaf.js +145 -33
  52. package/src/commands/meminj.js +145 -33
  53. package/src/commands/memory.js +209 -0
  54. package/src/commands/multimodal.js +203 -0
  55. package/src/commands/nlprog.js +225 -0
  56. package/src/commands/nostr.js +387 -27
  57. package/src/commands/note.js +205 -0
  58. package/src/commands/ops.js +219 -0
  59. package/src/commands/orchestrate.js +217 -0
  60. package/src/commands/orchgov.js +144 -33
  61. package/src/commands/org.js +209 -0
  62. package/src/commands/p2p.js +209 -0
  63. package/src/commands/pdfp.js +109 -27
  64. package/src/commands/perception.js +209 -0
  65. package/src/commands/perf.js +169 -32
  66. package/src/commands/perm.js +144 -33
  67. package/src/commands/permmem.js +203 -0
  68. package/src/commands/pipeline.js +207 -52
  69. package/src/commands/planmode.js +141 -32
  70. package/src/commands/plugin-ecosystem.js +209 -0
  71. package/src/commands/pqc.js +213 -0
  72. package/src/commands/privacy.js +203 -0
  73. package/src/commands/promcomp.js +111 -27
  74. package/src/commands/quantization.js +207 -0
  75. package/src/commands/rcache.js +205 -0
  76. package/src/commands/recommend.js +410 -34
  77. package/src/commands/reputation.js +208 -0
  78. package/src/commands/runtime.js +205 -0
  79. package/src/commands/sandbox.js +206 -0
  80. package/src/commands/scim.js +209 -0
  81. package/src/commands/seshhook.js +145 -33
  82. package/src/commands/seshsearch.js +141 -33
  83. package/src/commands/seshtail.js +144 -33
  84. package/src/commands/seshu.js +152 -33
  85. package/src/commands/session.js +209 -0
  86. package/src/commands/sganal.js +123 -29
  87. package/src/commands/siem.js +201 -34
  88. package/src/commands/skill.js +207 -0
  89. package/src/commands/sla.js +212 -0
  90. package/src/commands/slotfill.js +146 -33
  91. package/src/commands/social.js +358 -32
  92. package/src/commands/sso.js +209 -0
  93. package/src/commands/stress.js +206 -0
  94. package/src/commands/svccont.js +145 -33
  95. package/src/commands/sync.js +209 -0
  96. package/src/commands/tech.js +209 -0
  97. package/src/commands/tenant.js +217 -0
  98. package/src/commands/terraform.js +206 -0
  99. package/src/commands/tms.js +171 -33
  100. package/src/commands/tokens.js +209 -0
  101. package/src/commands/topiccls.js +146 -33
  102. package/src/commands/trust.js +217 -0
  103. package/src/commands/uprof.js +141 -32
  104. package/src/commands/vcheck.js +122 -28
  105. package/src/commands/wallet.js +209 -0
  106. package/src/commands/webfetch.js +141 -32
  107. package/src/commands/workflow.js +203 -0
  108. package/src/commands/zkp.js +184 -28
  109. package/src/index.js +180 -0
  110. package/src/lib/a2a-protocol.js +319 -51
  111. package/src/lib/activitypub-bridge.js +622 -50
  112. package/src/lib/agent-economy.js +304 -51
  113. package/src/lib/agent-network.js +341 -0
  114. package/src/lib/aiops.js +346 -0
  115. package/src/lib/app-builder.js +279 -46
  116. package/src/lib/audit-logger.js +321 -0
  117. package/src/lib/automation-engine.js +335 -0
  118. package/src/lib/autonomous-agent.js +284 -48
  119. package/src/lib/autonomous-developer.js +332 -0
  120. package/src/lib/bi-engine.js +616 -49
  121. package/src/lib/bm25-search.js +301 -49
  122. package/src/lib/browser-automation.js +630 -49
  123. package/src/lib/chat-core.js +336 -0
  124. package/src/lib/claude-code-bridge.js +341 -0
  125. package/src/lib/code-agent.js +339 -0
  126. package/src/lib/collaboration-governance.js +334 -0
  127. package/src/lib/community-governance.js +346 -0
  128. package/src/lib/compliance-framework-reporter.js +305 -51
  129. package/src/lib/compliance-manager.js +330 -0
  130. package/src/lib/compression-telemetry.js +301 -49
  131. package/src/lib/content-recommendation.js +351 -0
  132. package/src/lib/content-recommender.js +317 -52
  133. package/src/lib/cowork-cron.js +298 -49
  134. package/src/lib/cowork-learning.js +333 -0
  135. package/src/lib/cowork-share.js +338 -0
  136. package/src/lib/cowork-task-runner.js +308 -51
  137. package/src/lib/cowork-workflow.js +327 -0
  138. package/src/lib/cross-chain.js +311 -51
  139. package/src/lib/dao-governance.js +280 -46
  140. package/src/lib/dbevo.js +351 -0
  141. package/src/lib/decentral-infra.js +330 -0
  142. package/src/lib/did-manager.js +341 -0
  143. package/src/lib/did-v2-manager.js +341 -0
  144. package/src/lib/dlp-engine.js +626 -49
  145. package/src/lib/evolution-system.js +278 -47
  146. package/src/lib/evomap-governance.js +334 -0
  147. package/src/lib/evomap-manager.js +280 -46
  148. package/src/lib/execution-backend.js +294 -48
  149. package/src/lib/feature-flags.js +294 -49
  150. package/src/lib/federation-hardening.js +340 -0
  151. package/src/lib/git-integration.js +285 -47
  152. package/src/lib/hardening-manager.js +341 -0
  153. package/src/lib/hierarchical-memory.js +284 -48
  154. package/src/lib/hook-manager.js +341 -0
  155. package/src/lib/inference-network.js +308 -51
  156. package/src/lib/instinct-manager.js +346 -0
  157. package/src/lib/ipfs-storage.js +334 -0
  158. package/src/lib/iteration-budget.js +302 -50
  159. package/src/lib/knowledge-exporter.js +341 -0
  160. package/src/lib/knowledge-graph.js +333 -0
  161. package/src/lib/knowledge-importer.js +341 -0
  162. package/src/lib/llm-providers.js +346 -0
  163. package/src/lib/matrix-bridge.js +620 -47
  164. package/src/lib/mcp-registry.js +346 -0
  165. package/src/lib/mcp-scaffold.js +318 -54
  166. package/src/lib/memory-injection.js +288 -49
  167. package/src/lib/memory-manager.js +336 -0
  168. package/src/lib/multimodal.js +330 -0
  169. package/src/lib/nl-programming.js +341 -0
  170. package/src/lib/nostr-bridge.js +622 -49
  171. package/src/lib/note-versioning.js +339 -0
  172. package/src/lib/orchestrator.js +293 -48
  173. package/src/lib/org-manager.js +336 -0
  174. package/src/lib/p2p-manager.js +341 -0
  175. package/src/lib/pdf-parser.js +298 -49
  176. package/src/lib/perception.js +346 -0
  177. package/src/lib/perf-tuning.js +309 -50
  178. package/src/lib/permanent-memory.js +327 -0
  179. package/src/lib/permission-engine.js +287 -49
  180. package/src/lib/pipeline-orchestrator.js +289 -49
  181. package/src/lib/plan-mode.js +298 -51
  182. package/src/lib/plugin-ecosystem.js +346 -0
  183. package/src/lib/pqc-manager.js +346 -0
  184. package/src/lib/privacy-computing.js +335 -0
  185. package/src/lib/protocol-fusion.js +338 -0
  186. package/src/lib/quantization.js +337 -0
  187. package/src/lib/reputation-optimizer.js +340 -0
  188. package/src/lib/response-cache.js +333 -0
  189. package/src/lib/sandbox-v2.js +327 -0
  190. package/src/lib/scim-manager.js +346 -0
  191. package/src/lib/service-container.js +313 -52
  192. package/src/lib/session-consolidator.js +296 -49
  193. package/src/lib/session-hooks.js +312 -53
  194. package/src/lib/session-manager.js +334 -0
  195. package/src/lib/session-search.js +304 -51
  196. package/src/lib/session-tail.js +288 -49
  197. package/src/lib/session-usage.js +298 -52
  198. package/src/lib/siem-exporter.js +298 -51
  199. package/src/lib/skill-loader.js +334 -0
  200. package/src/lib/skill-marketplace.js +345 -0
  201. package/src/lib/sla-manager.js +341 -0
  202. package/src/lib/slot-filler.js +303 -51
  203. package/src/lib/social-graph-analytics.js +295 -49
  204. package/src/lib/social-graph.js +272 -49
  205. package/src/lib/social-manager.js +330 -0
  206. package/src/lib/sso-manager.js +340 -0
  207. package/src/lib/stress-tester.js +342 -0
  208. package/src/lib/sub-agent-registry.js +302 -53
  209. package/src/lib/sync-manager.js +336 -0
  210. package/src/lib/task-model-selector.js +302 -50
  211. package/src/lib/tech-learning-engine.js +341 -0
  212. package/src/lib/tenant-saas.js +341 -0
  213. package/src/lib/terraform-manager.js +333 -0
  214. package/src/lib/threat-intel.js +330 -0
  215. package/src/lib/todo-manager.js +281 -47
  216. package/src/lib/token-incentive.js +341 -0
  217. package/src/lib/token-tracker.js +336 -0
  218. package/src/lib/topic-classifier.js +297 -49
  219. package/src/lib/trust-security.js +343 -0
  220. package/src/lib/ueba.js +340 -0
  221. package/src/lib/universal-runtime.js +330 -0
  222. package/src/lib/user-profile.js +294 -50
  223. package/src/lib/version-checker.js +304 -50
  224. package/src/lib/wallet-manager.js +336 -0
  225. package/src/lib/web-fetch.js +292 -51
  226. package/src/lib/workflow-engine.js +330 -0
  227. package/src/lib/zkp-engine.js +286 -49
@@ -1484,3 +1484,349 @@ export function _resetStateV2() {
1484
1484
  _autoDeprecateAfterMs = PLUGIN_DEFAULT_AUTO_DEPRECATE_AFTER_MS;
1485
1485
  _autoArchiveAfterMs = PLUGIN_DEFAULT_AUTO_ARCHIVE_AFTER_MS;
1486
1486
  }
1487
+
1488
+ // =====================================================================
1489
+ // plugin-ecosystem V2 governance overlay (iter24)
1490
+ // =====================================================================
1491
+ export const ECOGOV_PROFILE_MATURITY_V2 = Object.freeze({
1492
+ PENDING: "pending",
1493
+ ACTIVE: "active",
1494
+ DISABLED: "disabled",
1495
+ ARCHIVED: "archived",
1496
+ });
1497
+ export const ECOGOV_INSTALL_LIFECYCLE_V2 = Object.freeze({
1498
+ QUEUED: "queued",
1499
+ INSTALLING: "installing",
1500
+ INSTALLED: "installed",
1501
+ FAILED: "failed",
1502
+ CANCELLED: "cancelled",
1503
+ });
1504
+ const _ecogovPTrans = new Map([
1505
+ [
1506
+ ECOGOV_PROFILE_MATURITY_V2.PENDING,
1507
+ new Set([
1508
+ ECOGOV_PROFILE_MATURITY_V2.ACTIVE,
1509
+ ECOGOV_PROFILE_MATURITY_V2.ARCHIVED,
1510
+ ]),
1511
+ ],
1512
+ [
1513
+ ECOGOV_PROFILE_MATURITY_V2.ACTIVE,
1514
+ new Set([
1515
+ ECOGOV_PROFILE_MATURITY_V2.DISABLED,
1516
+ ECOGOV_PROFILE_MATURITY_V2.ARCHIVED,
1517
+ ]),
1518
+ ],
1519
+ [
1520
+ ECOGOV_PROFILE_MATURITY_V2.DISABLED,
1521
+ new Set([
1522
+ ECOGOV_PROFILE_MATURITY_V2.ACTIVE,
1523
+ ECOGOV_PROFILE_MATURITY_V2.ARCHIVED,
1524
+ ]),
1525
+ ],
1526
+ [ECOGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
1527
+ ]);
1528
+ const _ecogovPTerminal = new Set([ECOGOV_PROFILE_MATURITY_V2.ARCHIVED]);
1529
+ const _ecogovJTrans = new Map([
1530
+ [
1531
+ ECOGOV_INSTALL_LIFECYCLE_V2.QUEUED,
1532
+ new Set([
1533
+ ECOGOV_INSTALL_LIFECYCLE_V2.INSTALLING,
1534
+ ECOGOV_INSTALL_LIFECYCLE_V2.CANCELLED,
1535
+ ]),
1536
+ ],
1537
+ [
1538
+ ECOGOV_INSTALL_LIFECYCLE_V2.INSTALLING,
1539
+ new Set([
1540
+ ECOGOV_INSTALL_LIFECYCLE_V2.INSTALLED,
1541
+ ECOGOV_INSTALL_LIFECYCLE_V2.FAILED,
1542
+ ECOGOV_INSTALL_LIFECYCLE_V2.CANCELLED,
1543
+ ]),
1544
+ ],
1545
+ [ECOGOV_INSTALL_LIFECYCLE_V2.INSTALLED, new Set()],
1546
+ [ECOGOV_INSTALL_LIFECYCLE_V2.FAILED, new Set()],
1547
+ [ECOGOV_INSTALL_LIFECYCLE_V2.CANCELLED, new Set()],
1548
+ ]);
1549
+ const _ecogovPsV2 = new Map();
1550
+ const _ecogovJsV2 = new Map();
1551
+ let _ecogovMaxActive = 12,
1552
+ _ecogovMaxPending = 30,
1553
+ _ecogovIdleMs = 30 * 24 * 60 * 60 * 1000,
1554
+ _ecogovStuckMs = 60 * 1000;
1555
+ function _ecogovPos(n, label) {
1556
+ const v = Math.floor(Number(n));
1557
+ if (!Number.isFinite(v) || v <= 0)
1558
+ throw new Error(`${label} must be positive integer`);
1559
+ return v;
1560
+ }
1561
+ function _ecogovCheckP(from, to) {
1562
+ const a = _ecogovPTrans.get(from);
1563
+ if (!a || !a.has(to))
1564
+ throw new Error(`invalid ecogov profile transition ${from} → ${to}`);
1565
+ }
1566
+ function _ecogovCheckJ(from, to) {
1567
+ const a = _ecogovJTrans.get(from);
1568
+ if (!a || !a.has(to))
1569
+ throw new Error(`invalid ecogov install transition ${from} → ${to}`);
1570
+ }
1571
+ function _ecogovCountActive(owner) {
1572
+ let c = 0;
1573
+ for (const p of _ecogovPsV2.values())
1574
+ if (p.owner === owner && p.status === ECOGOV_PROFILE_MATURITY_V2.ACTIVE)
1575
+ c++;
1576
+ return c;
1577
+ }
1578
+ function _ecogovCountPending(profileId) {
1579
+ let c = 0;
1580
+ for (const j of _ecogovJsV2.values())
1581
+ if (
1582
+ j.profileId === profileId &&
1583
+ (j.status === ECOGOV_INSTALL_LIFECYCLE_V2.QUEUED ||
1584
+ j.status === ECOGOV_INSTALL_LIFECYCLE_V2.INSTALLING)
1585
+ )
1586
+ c++;
1587
+ return c;
1588
+ }
1589
+ export function setMaxActiveEcogovProfilesPerOwnerV2(n) {
1590
+ _ecogovMaxActive = _ecogovPos(n, "maxActiveEcogovProfilesPerOwner");
1591
+ }
1592
+ export function getMaxActiveEcogovProfilesPerOwnerV2() {
1593
+ return _ecogovMaxActive;
1594
+ }
1595
+ export function setMaxPendingEcogovInstallsPerProfileV2(n) {
1596
+ _ecogovMaxPending = _ecogovPos(n, "maxPendingEcogovInstallsPerProfile");
1597
+ }
1598
+ export function getMaxPendingEcogovInstallsPerProfileV2() {
1599
+ return _ecogovMaxPending;
1600
+ }
1601
+ export function setEcogovProfileIdleMsV2(n) {
1602
+ _ecogovIdleMs = _ecogovPos(n, "ecogovProfileIdleMs");
1603
+ }
1604
+ export function getEcogovProfileIdleMsV2() {
1605
+ return _ecogovIdleMs;
1606
+ }
1607
+ export function setEcogovInstallStuckMsV2(n) {
1608
+ _ecogovStuckMs = _ecogovPos(n, "ecogovInstallStuckMs");
1609
+ }
1610
+ export function getEcogovInstallStuckMsV2() {
1611
+ return _ecogovStuckMs;
1612
+ }
1613
+ export function _resetStatePluginEcosystemGovV2() {
1614
+ _ecogovPsV2.clear();
1615
+ _ecogovJsV2.clear();
1616
+ _ecogovMaxActive = 12;
1617
+ _ecogovMaxPending = 30;
1618
+ _ecogovIdleMs = 30 * 24 * 60 * 60 * 1000;
1619
+ _ecogovStuckMs = 60 * 1000;
1620
+ }
1621
+ export function registerEcogovProfileV2({
1622
+ id,
1623
+ owner,
1624
+ category,
1625
+ metadata,
1626
+ } = {}) {
1627
+ if (!id || !owner) throw new Error("id and owner required");
1628
+ if (_ecogovPsV2.has(id))
1629
+ throw new Error(`ecogov profile ${id} already exists`);
1630
+ const now = Date.now();
1631
+ const p = {
1632
+ id,
1633
+ owner,
1634
+ category: category || "general",
1635
+ status: ECOGOV_PROFILE_MATURITY_V2.PENDING,
1636
+ createdAt: now,
1637
+ updatedAt: now,
1638
+ lastTouchedAt: now,
1639
+ activatedAt: null,
1640
+ archivedAt: null,
1641
+ metadata: { ...(metadata || {}) },
1642
+ };
1643
+ _ecogovPsV2.set(id, p);
1644
+ return { ...p, metadata: { ...p.metadata } };
1645
+ }
1646
+ export function activateEcogovProfileV2(id) {
1647
+ const p = _ecogovPsV2.get(id);
1648
+ if (!p) throw new Error(`ecogov profile ${id} not found`);
1649
+ const isInitial = p.status === ECOGOV_PROFILE_MATURITY_V2.PENDING;
1650
+ _ecogovCheckP(p.status, ECOGOV_PROFILE_MATURITY_V2.ACTIVE);
1651
+ if (isInitial && _ecogovCountActive(p.owner) >= _ecogovMaxActive)
1652
+ throw new Error(`max active ecogov profiles for owner ${p.owner} reached`);
1653
+ const now = Date.now();
1654
+ p.status = ECOGOV_PROFILE_MATURITY_V2.ACTIVE;
1655
+ p.updatedAt = now;
1656
+ p.lastTouchedAt = now;
1657
+ if (!p.activatedAt) p.activatedAt = now;
1658
+ return { ...p, metadata: { ...p.metadata } };
1659
+ }
1660
+ export function disableEcogovProfileV2(id) {
1661
+ const p = _ecogovPsV2.get(id);
1662
+ if (!p) throw new Error(`ecogov profile ${id} not found`);
1663
+ _ecogovCheckP(p.status, ECOGOV_PROFILE_MATURITY_V2.DISABLED);
1664
+ p.status = ECOGOV_PROFILE_MATURITY_V2.DISABLED;
1665
+ p.updatedAt = Date.now();
1666
+ return { ...p, metadata: { ...p.metadata } };
1667
+ }
1668
+ export function archiveEcogovProfileV2(id) {
1669
+ const p = _ecogovPsV2.get(id);
1670
+ if (!p) throw new Error(`ecogov profile ${id} not found`);
1671
+ _ecogovCheckP(p.status, ECOGOV_PROFILE_MATURITY_V2.ARCHIVED);
1672
+ const now = Date.now();
1673
+ p.status = ECOGOV_PROFILE_MATURITY_V2.ARCHIVED;
1674
+ p.updatedAt = now;
1675
+ if (!p.archivedAt) p.archivedAt = now;
1676
+ return { ...p, metadata: { ...p.metadata } };
1677
+ }
1678
+ export function touchEcogovProfileV2(id) {
1679
+ const p = _ecogovPsV2.get(id);
1680
+ if (!p) throw new Error(`ecogov profile ${id} not found`);
1681
+ if (_ecogovPTerminal.has(p.status))
1682
+ throw new Error(`cannot touch terminal ecogov profile ${id}`);
1683
+ const now = Date.now();
1684
+ p.lastTouchedAt = now;
1685
+ p.updatedAt = now;
1686
+ return { ...p, metadata: { ...p.metadata } };
1687
+ }
1688
+ export function getEcogovProfileV2(id) {
1689
+ const p = _ecogovPsV2.get(id);
1690
+ if (!p) return null;
1691
+ return { ...p, metadata: { ...p.metadata } };
1692
+ }
1693
+ export function listEcogovProfilesV2() {
1694
+ return [..._ecogovPsV2.values()].map((p) => ({
1695
+ ...p,
1696
+ metadata: { ...p.metadata },
1697
+ }));
1698
+ }
1699
+ export function createEcogovInstallV2({
1700
+ id,
1701
+ profileId,
1702
+ version,
1703
+ metadata,
1704
+ } = {}) {
1705
+ if (!id || !profileId) throw new Error("id and profileId required");
1706
+ if (_ecogovJsV2.has(id))
1707
+ throw new Error(`ecogov install ${id} already exists`);
1708
+ if (!_ecogovPsV2.has(profileId))
1709
+ throw new Error(`ecogov profile ${profileId} not found`);
1710
+ if (_ecogovCountPending(profileId) >= _ecogovMaxPending)
1711
+ throw new Error(
1712
+ `max pending ecogov installs for profile ${profileId} reached`,
1713
+ );
1714
+ const now = Date.now();
1715
+ const j = {
1716
+ id,
1717
+ profileId,
1718
+ version: version || "",
1719
+ status: ECOGOV_INSTALL_LIFECYCLE_V2.QUEUED,
1720
+ createdAt: now,
1721
+ updatedAt: now,
1722
+ startedAt: null,
1723
+ settledAt: null,
1724
+ metadata: { ...(metadata || {}) },
1725
+ };
1726
+ _ecogovJsV2.set(id, j);
1727
+ return { ...j, metadata: { ...j.metadata } };
1728
+ }
1729
+ export function installingEcogovInstallV2(id) {
1730
+ const j = _ecogovJsV2.get(id);
1731
+ if (!j) throw new Error(`ecogov install ${id} not found`);
1732
+ _ecogovCheckJ(j.status, ECOGOV_INSTALL_LIFECYCLE_V2.INSTALLING);
1733
+ const now = Date.now();
1734
+ j.status = ECOGOV_INSTALL_LIFECYCLE_V2.INSTALLING;
1735
+ j.updatedAt = now;
1736
+ if (!j.startedAt) j.startedAt = now;
1737
+ return { ...j, metadata: { ...j.metadata } };
1738
+ }
1739
+ export function completeInstallEcogovV2(id) {
1740
+ const j = _ecogovJsV2.get(id);
1741
+ if (!j) throw new Error(`ecogov install ${id} not found`);
1742
+ _ecogovCheckJ(j.status, ECOGOV_INSTALL_LIFECYCLE_V2.INSTALLED);
1743
+ const now = Date.now();
1744
+ j.status = ECOGOV_INSTALL_LIFECYCLE_V2.INSTALLED;
1745
+ j.updatedAt = now;
1746
+ if (!j.settledAt) j.settledAt = now;
1747
+ return { ...j, metadata: { ...j.metadata } };
1748
+ }
1749
+ export function failEcogovInstallV2(id, reason) {
1750
+ const j = _ecogovJsV2.get(id);
1751
+ if (!j) throw new Error(`ecogov install ${id} not found`);
1752
+ _ecogovCheckJ(j.status, ECOGOV_INSTALL_LIFECYCLE_V2.FAILED);
1753
+ const now = Date.now();
1754
+ j.status = ECOGOV_INSTALL_LIFECYCLE_V2.FAILED;
1755
+ j.updatedAt = now;
1756
+ if (!j.settledAt) j.settledAt = now;
1757
+ if (reason) j.metadata.failReason = String(reason);
1758
+ return { ...j, metadata: { ...j.metadata } };
1759
+ }
1760
+ export function cancelEcogovInstallV2(id, reason) {
1761
+ const j = _ecogovJsV2.get(id);
1762
+ if (!j) throw new Error(`ecogov install ${id} not found`);
1763
+ _ecogovCheckJ(j.status, ECOGOV_INSTALL_LIFECYCLE_V2.CANCELLED);
1764
+ const now = Date.now();
1765
+ j.status = ECOGOV_INSTALL_LIFECYCLE_V2.CANCELLED;
1766
+ j.updatedAt = now;
1767
+ if (!j.settledAt) j.settledAt = now;
1768
+ if (reason) j.metadata.cancelReason = String(reason);
1769
+ return { ...j, metadata: { ...j.metadata } };
1770
+ }
1771
+ export function getEcogovInstallV2(id) {
1772
+ const j = _ecogovJsV2.get(id);
1773
+ if (!j) return null;
1774
+ return { ...j, metadata: { ...j.metadata } };
1775
+ }
1776
+ export function listEcogovInstallsV2() {
1777
+ return [..._ecogovJsV2.values()].map((j) => ({
1778
+ ...j,
1779
+ metadata: { ...j.metadata },
1780
+ }));
1781
+ }
1782
+ export function autoDisableIdleEcogovProfilesV2({ now } = {}) {
1783
+ const t = now ?? Date.now();
1784
+ const flipped = [];
1785
+ for (const p of _ecogovPsV2.values())
1786
+ if (
1787
+ p.status === ECOGOV_PROFILE_MATURITY_V2.ACTIVE &&
1788
+ t - p.lastTouchedAt >= _ecogovIdleMs
1789
+ ) {
1790
+ p.status = ECOGOV_PROFILE_MATURITY_V2.DISABLED;
1791
+ p.updatedAt = t;
1792
+ flipped.push(p.id);
1793
+ }
1794
+ return { flipped, count: flipped.length };
1795
+ }
1796
+ export function autoFailStuckEcogovInstallsV2({ now } = {}) {
1797
+ const t = now ?? Date.now();
1798
+ const flipped = [];
1799
+ for (const j of _ecogovJsV2.values())
1800
+ if (
1801
+ j.status === ECOGOV_INSTALL_LIFECYCLE_V2.INSTALLING &&
1802
+ j.startedAt != null &&
1803
+ t - j.startedAt >= _ecogovStuckMs
1804
+ ) {
1805
+ j.status = ECOGOV_INSTALL_LIFECYCLE_V2.FAILED;
1806
+ j.updatedAt = t;
1807
+ if (!j.settledAt) j.settledAt = t;
1808
+ j.metadata.failReason = "auto-fail-stuck";
1809
+ flipped.push(j.id);
1810
+ }
1811
+ return { flipped, count: flipped.length };
1812
+ }
1813
+ export function getPluginEcosystemGovStatsV2() {
1814
+ const profilesByStatus = {};
1815
+ for (const v of Object.values(ECOGOV_PROFILE_MATURITY_V2))
1816
+ profilesByStatus[v] = 0;
1817
+ for (const p of _ecogovPsV2.values()) profilesByStatus[p.status]++;
1818
+ const installsByStatus = {};
1819
+ for (const v of Object.values(ECOGOV_INSTALL_LIFECYCLE_V2))
1820
+ installsByStatus[v] = 0;
1821
+ for (const j of _ecogovJsV2.values()) installsByStatus[j.status]++;
1822
+ return {
1823
+ totalEcogovProfilesV2: _ecogovPsV2.size,
1824
+ totalEcogovInstallsV2: _ecogovJsV2.size,
1825
+ maxActiveEcogovProfilesPerOwner: _ecogovMaxActive,
1826
+ maxPendingEcogovInstallsPerProfile: _ecogovMaxPending,
1827
+ ecogovProfileIdleMs: _ecogovIdleMs,
1828
+ ecogovInstallStuckMs: _ecogovStuckMs,
1829
+ profilesByStatus,
1830
+ installsByStatus,
1831
+ };
1832
+ }
@@ -694,3 +694,349 @@ export function _resetStatePqcManagerV2() {
694
694
  _keyIdleMsV2 = PQC_DEFAULT_KEY_IDLE_MS;
695
695
  _migrationStuckMsV2 = PQC_DEFAULT_MIGRATION_STUCK_MS;
696
696
  }
697
+
698
+ // =====================================================================
699
+ // pqc-manager V2 governance overlay (iter22)
700
+ // =====================================================================
701
+ export const PQCGOV_PROFILE_MATURITY_V2 = Object.freeze({
702
+ PENDING: "pending",
703
+ ACTIVE: "active",
704
+ DEPRECATED: "deprecated",
705
+ ARCHIVED: "archived",
706
+ });
707
+ export const PQCGOV_KEYGEN_LIFECYCLE_V2 = Object.freeze({
708
+ QUEUED: "queued",
709
+ GENERATING: "generating",
710
+ GENERATED: "generated",
711
+ FAILED: "failed",
712
+ CANCELLED: "cancelled",
713
+ });
714
+ const _pqcgovPTrans = new Map([
715
+ [
716
+ PQCGOV_PROFILE_MATURITY_V2.PENDING,
717
+ new Set([
718
+ PQCGOV_PROFILE_MATURITY_V2.ACTIVE,
719
+ PQCGOV_PROFILE_MATURITY_V2.ARCHIVED,
720
+ ]),
721
+ ],
722
+ [
723
+ PQCGOV_PROFILE_MATURITY_V2.ACTIVE,
724
+ new Set([
725
+ PQCGOV_PROFILE_MATURITY_V2.DEPRECATED,
726
+ PQCGOV_PROFILE_MATURITY_V2.ARCHIVED,
727
+ ]),
728
+ ],
729
+ [
730
+ PQCGOV_PROFILE_MATURITY_V2.DEPRECATED,
731
+ new Set([
732
+ PQCGOV_PROFILE_MATURITY_V2.ACTIVE,
733
+ PQCGOV_PROFILE_MATURITY_V2.ARCHIVED,
734
+ ]),
735
+ ],
736
+ [PQCGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
737
+ ]);
738
+ const _pqcgovPTerminal = new Set([PQCGOV_PROFILE_MATURITY_V2.ARCHIVED]);
739
+ const _pqcgovJTrans = new Map([
740
+ [
741
+ PQCGOV_KEYGEN_LIFECYCLE_V2.QUEUED,
742
+ new Set([
743
+ PQCGOV_KEYGEN_LIFECYCLE_V2.GENERATING,
744
+ PQCGOV_KEYGEN_LIFECYCLE_V2.CANCELLED,
745
+ ]),
746
+ ],
747
+ [
748
+ PQCGOV_KEYGEN_LIFECYCLE_V2.GENERATING,
749
+ new Set([
750
+ PQCGOV_KEYGEN_LIFECYCLE_V2.GENERATED,
751
+ PQCGOV_KEYGEN_LIFECYCLE_V2.FAILED,
752
+ PQCGOV_KEYGEN_LIFECYCLE_V2.CANCELLED,
753
+ ]),
754
+ ],
755
+ [PQCGOV_KEYGEN_LIFECYCLE_V2.GENERATED, new Set()],
756
+ [PQCGOV_KEYGEN_LIFECYCLE_V2.FAILED, new Set()],
757
+ [PQCGOV_KEYGEN_LIFECYCLE_V2.CANCELLED, new Set()],
758
+ ]);
759
+ const _pqcgovPsV2 = new Map();
760
+ const _pqcgovJsV2 = new Map();
761
+ let _pqcgovMaxActive = 6,
762
+ _pqcgovMaxPending = 12,
763
+ _pqcgovIdleMs = 30 * 24 * 60 * 60 * 1000,
764
+ _pqcgovStuckMs = 60 * 1000;
765
+ function _pqcgovPos(n, label) {
766
+ const v = Math.floor(Number(n));
767
+ if (!Number.isFinite(v) || v <= 0)
768
+ throw new Error(`${label} must be positive integer`);
769
+ return v;
770
+ }
771
+ function _pqcgovCheckP(from, to) {
772
+ const a = _pqcgovPTrans.get(from);
773
+ if (!a || !a.has(to))
774
+ throw new Error(`invalid pqcgov profile transition ${from} → ${to}`);
775
+ }
776
+ function _pqcgovCheckJ(from, to) {
777
+ const a = _pqcgovJTrans.get(from);
778
+ if (!a || !a.has(to))
779
+ throw new Error(`invalid pqcgov keygen transition ${from} → ${to}`);
780
+ }
781
+ function _pqcgovCountActive(owner) {
782
+ let c = 0;
783
+ for (const p of _pqcgovPsV2.values())
784
+ if (p.owner === owner && p.status === PQCGOV_PROFILE_MATURITY_V2.ACTIVE)
785
+ c++;
786
+ return c;
787
+ }
788
+ function _pqcgovCountPending(profileId) {
789
+ let c = 0;
790
+ for (const j of _pqcgovJsV2.values())
791
+ if (
792
+ j.profileId === profileId &&
793
+ (j.status === PQCGOV_KEYGEN_LIFECYCLE_V2.QUEUED ||
794
+ j.status === PQCGOV_KEYGEN_LIFECYCLE_V2.GENERATING)
795
+ )
796
+ c++;
797
+ return c;
798
+ }
799
+ export function setMaxActivePqcgovProfilesPerOwnerV2(n) {
800
+ _pqcgovMaxActive = _pqcgovPos(n, "maxActivePqcgovProfilesPerOwner");
801
+ }
802
+ export function getMaxActivePqcgovProfilesPerOwnerV2() {
803
+ return _pqcgovMaxActive;
804
+ }
805
+ export function setMaxPendingPqcgovKeygensPerProfileV2(n) {
806
+ _pqcgovMaxPending = _pqcgovPos(n, "maxPendingPqcgovKeygensPerProfile");
807
+ }
808
+ export function getMaxPendingPqcgovKeygensPerProfileV2() {
809
+ return _pqcgovMaxPending;
810
+ }
811
+ export function setPqcgovProfileIdleMsV2(n) {
812
+ _pqcgovIdleMs = _pqcgovPos(n, "pqcgovProfileIdleMs");
813
+ }
814
+ export function getPqcgovProfileIdleMsV2() {
815
+ return _pqcgovIdleMs;
816
+ }
817
+ export function setPqcgovKeygenStuckMsV2(n) {
818
+ _pqcgovStuckMs = _pqcgovPos(n, "pqcgovKeygenStuckMs");
819
+ }
820
+ export function getPqcgovKeygenStuckMsV2() {
821
+ return _pqcgovStuckMs;
822
+ }
823
+ export function _resetStatePqcManagerGovV2() {
824
+ _pqcgovPsV2.clear();
825
+ _pqcgovJsV2.clear();
826
+ _pqcgovMaxActive = 6;
827
+ _pqcgovMaxPending = 12;
828
+ _pqcgovIdleMs = 30 * 24 * 60 * 60 * 1000;
829
+ _pqcgovStuckMs = 60 * 1000;
830
+ }
831
+ export function registerPqcgovProfileV2({
832
+ id,
833
+ owner,
834
+ algorithm,
835
+ metadata,
836
+ } = {}) {
837
+ if (!id || !owner) throw new Error("id and owner required");
838
+ if (_pqcgovPsV2.has(id))
839
+ throw new Error(`pqcgov profile ${id} already exists`);
840
+ const now = Date.now();
841
+ const p = {
842
+ id,
843
+ owner,
844
+ algorithm: algorithm || "kyber",
845
+ status: PQCGOV_PROFILE_MATURITY_V2.PENDING,
846
+ createdAt: now,
847
+ updatedAt: now,
848
+ lastTouchedAt: now,
849
+ activatedAt: null,
850
+ archivedAt: null,
851
+ metadata: { ...(metadata || {}) },
852
+ };
853
+ _pqcgovPsV2.set(id, p);
854
+ return { ...p, metadata: { ...p.metadata } };
855
+ }
856
+ export function activatePqcgovProfileV2(id) {
857
+ const p = _pqcgovPsV2.get(id);
858
+ if (!p) throw new Error(`pqcgov profile ${id} not found`);
859
+ const isInitial = p.status === PQCGOV_PROFILE_MATURITY_V2.PENDING;
860
+ _pqcgovCheckP(p.status, PQCGOV_PROFILE_MATURITY_V2.ACTIVE);
861
+ if (isInitial && _pqcgovCountActive(p.owner) >= _pqcgovMaxActive)
862
+ throw new Error(`max active pqcgov profiles for owner ${p.owner} reached`);
863
+ const now = Date.now();
864
+ p.status = PQCGOV_PROFILE_MATURITY_V2.ACTIVE;
865
+ p.updatedAt = now;
866
+ p.lastTouchedAt = now;
867
+ if (!p.activatedAt) p.activatedAt = now;
868
+ return { ...p, metadata: { ...p.metadata } };
869
+ }
870
+ export function deprecatePqcgovProfileV2(id) {
871
+ const p = _pqcgovPsV2.get(id);
872
+ if (!p) throw new Error(`pqcgov profile ${id} not found`);
873
+ _pqcgovCheckP(p.status, PQCGOV_PROFILE_MATURITY_V2.DEPRECATED);
874
+ p.status = PQCGOV_PROFILE_MATURITY_V2.DEPRECATED;
875
+ p.updatedAt = Date.now();
876
+ return { ...p, metadata: { ...p.metadata } };
877
+ }
878
+ export function archivePqcgovProfileV2(id) {
879
+ const p = _pqcgovPsV2.get(id);
880
+ if (!p) throw new Error(`pqcgov profile ${id} not found`);
881
+ _pqcgovCheckP(p.status, PQCGOV_PROFILE_MATURITY_V2.ARCHIVED);
882
+ const now = Date.now();
883
+ p.status = PQCGOV_PROFILE_MATURITY_V2.ARCHIVED;
884
+ p.updatedAt = now;
885
+ if (!p.archivedAt) p.archivedAt = now;
886
+ return { ...p, metadata: { ...p.metadata } };
887
+ }
888
+ export function touchPqcgovProfileV2(id) {
889
+ const p = _pqcgovPsV2.get(id);
890
+ if (!p) throw new Error(`pqcgov profile ${id} not found`);
891
+ if (_pqcgovPTerminal.has(p.status))
892
+ throw new Error(`cannot touch terminal pqcgov profile ${id}`);
893
+ const now = Date.now();
894
+ p.lastTouchedAt = now;
895
+ p.updatedAt = now;
896
+ return { ...p, metadata: { ...p.metadata } };
897
+ }
898
+ export function getPqcgovProfileV2(id) {
899
+ const p = _pqcgovPsV2.get(id);
900
+ if (!p) return null;
901
+ return { ...p, metadata: { ...p.metadata } };
902
+ }
903
+ export function listPqcgovProfilesV2() {
904
+ return [..._pqcgovPsV2.values()].map((p) => ({
905
+ ...p,
906
+ metadata: { ...p.metadata },
907
+ }));
908
+ }
909
+ export function createPqcgovKeygenV2({
910
+ id,
911
+ profileId,
912
+ purpose,
913
+ metadata,
914
+ } = {}) {
915
+ if (!id || !profileId) throw new Error("id and profileId required");
916
+ if (_pqcgovJsV2.has(id))
917
+ throw new Error(`pqcgov keygen ${id} already exists`);
918
+ if (!_pqcgovPsV2.has(profileId))
919
+ throw new Error(`pqcgov profile ${profileId} not found`);
920
+ if (_pqcgovCountPending(profileId) >= _pqcgovMaxPending)
921
+ throw new Error(
922
+ `max pending pqcgov keygens for profile ${profileId} reached`,
923
+ );
924
+ const now = Date.now();
925
+ const j = {
926
+ id,
927
+ profileId,
928
+ purpose: purpose || "",
929
+ status: PQCGOV_KEYGEN_LIFECYCLE_V2.QUEUED,
930
+ createdAt: now,
931
+ updatedAt: now,
932
+ startedAt: null,
933
+ settledAt: null,
934
+ metadata: { ...(metadata || {}) },
935
+ };
936
+ _pqcgovJsV2.set(id, j);
937
+ return { ...j, metadata: { ...j.metadata } };
938
+ }
939
+ export function generatingPqcgovKeygenV2(id) {
940
+ const j = _pqcgovJsV2.get(id);
941
+ if (!j) throw new Error(`pqcgov keygen ${id} not found`);
942
+ _pqcgovCheckJ(j.status, PQCGOV_KEYGEN_LIFECYCLE_V2.GENERATING);
943
+ const now = Date.now();
944
+ j.status = PQCGOV_KEYGEN_LIFECYCLE_V2.GENERATING;
945
+ j.updatedAt = now;
946
+ if (!j.startedAt) j.startedAt = now;
947
+ return { ...j, metadata: { ...j.metadata } };
948
+ }
949
+ export function completeKeygenPqcgovV2(id) {
950
+ const j = _pqcgovJsV2.get(id);
951
+ if (!j) throw new Error(`pqcgov keygen ${id} not found`);
952
+ _pqcgovCheckJ(j.status, PQCGOV_KEYGEN_LIFECYCLE_V2.GENERATED);
953
+ const now = Date.now();
954
+ j.status = PQCGOV_KEYGEN_LIFECYCLE_V2.GENERATED;
955
+ j.updatedAt = now;
956
+ if (!j.settledAt) j.settledAt = now;
957
+ return { ...j, metadata: { ...j.metadata } };
958
+ }
959
+ export function failPqcgovKeygenV2(id, reason) {
960
+ const j = _pqcgovJsV2.get(id);
961
+ if (!j) throw new Error(`pqcgov keygen ${id} not found`);
962
+ _pqcgovCheckJ(j.status, PQCGOV_KEYGEN_LIFECYCLE_V2.FAILED);
963
+ const now = Date.now();
964
+ j.status = PQCGOV_KEYGEN_LIFECYCLE_V2.FAILED;
965
+ j.updatedAt = now;
966
+ if (!j.settledAt) j.settledAt = now;
967
+ if (reason) j.metadata.failReason = String(reason);
968
+ return { ...j, metadata: { ...j.metadata } };
969
+ }
970
+ export function cancelPqcgovKeygenV2(id, reason) {
971
+ const j = _pqcgovJsV2.get(id);
972
+ if (!j) throw new Error(`pqcgov keygen ${id} not found`);
973
+ _pqcgovCheckJ(j.status, PQCGOV_KEYGEN_LIFECYCLE_V2.CANCELLED);
974
+ const now = Date.now();
975
+ j.status = PQCGOV_KEYGEN_LIFECYCLE_V2.CANCELLED;
976
+ j.updatedAt = now;
977
+ if (!j.settledAt) j.settledAt = now;
978
+ if (reason) j.metadata.cancelReason = String(reason);
979
+ return { ...j, metadata: { ...j.metadata } };
980
+ }
981
+ export function getPqcgovKeygenV2(id) {
982
+ const j = _pqcgovJsV2.get(id);
983
+ if (!j) return null;
984
+ return { ...j, metadata: { ...j.metadata } };
985
+ }
986
+ export function listPqcgovKeygensV2() {
987
+ return [..._pqcgovJsV2.values()].map((j) => ({
988
+ ...j,
989
+ metadata: { ...j.metadata },
990
+ }));
991
+ }
992
+ export function autoDeprecateIdlePqcgovProfilesV2({ now } = {}) {
993
+ const t = now ?? Date.now();
994
+ const flipped = [];
995
+ for (const p of _pqcgovPsV2.values())
996
+ if (
997
+ p.status === PQCGOV_PROFILE_MATURITY_V2.ACTIVE &&
998
+ t - p.lastTouchedAt >= _pqcgovIdleMs
999
+ ) {
1000
+ p.status = PQCGOV_PROFILE_MATURITY_V2.DEPRECATED;
1001
+ p.updatedAt = t;
1002
+ flipped.push(p.id);
1003
+ }
1004
+ return { flipped, count: flipped.length };
1005
+ }
1006
+ export function autoFailStuckPqcgovKeygensV2({ now } = {}) {
1007
+ const t = now ?? Date.now();
1008
+ const flipped = [];
1009
+ for (const j of _pqcgovJsV2.values())
1010
+ if (
1011
+ j.status === PQCGOV_KEYGEN_LIFECYCLE_V2.GENERATING &&
1012
+ j.startedAt != null &&
1013
+ t - j.startedAt >= _pqcgovStuckMs
1014
+ ) {
1015
+ j.status = PQCGOV_KEYGEN_LIFECYCLE_V2.FAILED;
1016
+ j.updatedAt = t;
1017
+ if (!j.settledAt) j.settledAt = t;
1018
+ j.metadata.failReason = "auto-fail-stuck";
1019
+ flipped.push(j.id);
1020
+ }
1021
+ return { flipped, count: flipped.length };
1022
+ }
1023
+ export function getPqcManagerGovStatsV2() {
1024
+ const profilesByStatus = {};
1025
+ for (const v of Object.values(PQCGOV_PROFILE_MATURITY_V2))
1026
+ profilesByStatus[v] = 0;
1027
+ for (const p of _pqcgovPsV2.values()) profilesByStatus[p.status]++;
1028
+ const keygensByStatus = {};
1029
+ for (const v of Object.values(PQCGOV_KEYGEN_LIFECYCLE_V2))
1030
+ keygensByStatus[v] = 0;
1031
+ for (const j of _pqcgovJsV2.values()) keygensByStatus[j.status]++;
1032
+ return {
1033
+ totalPqcgovProfilesV2: _pqcgovPsV2.size,
1034
+ totalPqcgovKeygensV2: _pqcgovJsV2.size,
1035
+ maxActivePqcgovProfilesPerOwner: _pqcgovMaxActive,
1036
+ maxPendingPqcgovKeygensPerProfile: _pqcgovMaxPending,
1037
+ pqcgovProfileIdleMs: _pqcgovIdleMs,
1038
+ pqcgovKeygenStuckMs: _pqcgovStuckMs,
1039
+ profilesByStatus,
1040
+ keygensByStatus,
1041
+ };
1042
+ }