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
@@ -1295,3 +1295,337 @@ export function getEvolutionSystemGovStatsV2() {
1295
1295
  cyclesByStatus,
1296
1296
  };
1297
1297
  }
1298
+
1299
+ // === Iter28 V2 governance overlay: Esysgov ===
1300
+ export const ESYSGOV_PROFILE_MATURITY_V2 = Object.freeze({
1301
+ PENDING: "pending",
1302
+ ACTIVE: "active",
1303
+ PAUSED: "paused",
1304
+ ARCHIVED: "archived",
1305
+ });
1306
+ export const ESYSGOV_CYCLE_LIFECYCLE_V2 = Object.freeze({
1307
+ QUEUED: "queued",
1308
+ EVOLVING: "evolving",
1309
+ EVOLVED: "evolved",
1310
+ FAILED: "failed",
1311
+ CANCELLED: "cancelled",
1312
+ });
1313
+ const _esysgovPTrans = new Map([
1314
+ [
1315
+ ESYSGOV_PROFILE_MATURITY_V2.PENDING,
1316
+ new Set([
1317
+ ESYSGOV_PROFILE_MATURITY_V2.ACTIVE,
1318
+ ESYSGOV_PROFILE_MATURITY_V2.ARCHIVED,
1319
+ ]),
1320
+ ],
1321
+ [
1322
+ ESYSGOV_PROFILE_MATURITY_V2.ACTIVE,
1323
+ new Set([
1324
+ ESYSGOV_PROFILE_MATURITY_V2.PAUSED,
1325
+ ESYSGOV_PROFILE_MATURITY_V2.ARCHIVED,
1326
+ ]),
1327
+ ],
1328
+ [
1329
+ ESYSGOV_PROFILE_MATURITY_V2.PAUSED,
1330
+ new Set([
1331
+ ESYSGOV_PROFILE_MATURITY_V2.ACTIVE,
1332
+ ESYSGOV_PROFILE_MATURITY_V2.ARCHIVED,
1333
+ ]),
1334
+ ],
1335
+ [ESYSGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
1336
+ ]);
1337
+ const _esysgovPTerminal = new Set([ESYSGOV_PROFILE_MATURITY_V2.ARCHIVED]);
1338
+ const _esysgovJTrans = new Map([
1339
+ [
1340
+ ESYSGOV_CYCLE_LIFECYCLE_V2.QUEUED,
1341
+ new Set([
1342
+ ESYSGOV_CYCLE_LIFECYCLE_V2.EVOLVING,
1343
+ ESYSGOV_CYCLE_LIFECYCLE_V2.CANCELLED,
1344
+ ]),
1345
+ ],
1346
+ [
1347
+ ESYSGOV_CYCLE_LIFECYCLE_V2.EVOLVING,
1348
+ new Set([
1349
+ ESYSGOV_CYCLE_LIFECYCLE_V2.EVOLVED,
1350
+ ESYSGOV_CYCLE_LIFECYCLE_V2.FAILED,
1351
+ ESYSGOV_CYCLE_LIFECYCLE_V2.CANCELLED,
1352
+ ]),
1353
+ ],
1354
+ [ESYSGOV_CYCLE_LIFECYCLE_V2.EVOLVED, new Set()],
1355
+ [ESYSGOV_CYCLE_LIFECYCLE_V2.FAILED, new Set()],
1356
+ [ESYSGOV_CYCLE_LIFECYCLE_V2.CANCELLED, new Set()],
1357
+ ]);
1358
+ const _esysgovPsV2 = new Map();
1359
+ const _esysgovJsV2 = new Map();
1360
+ let _esysgovMaxActive = 6,
1361
+ _esysgovMaxPending = 15,
1362
+ _esysgovIdleMs = 2592000000,
1363
+ _esysgovStuckMs = 60 * 1000;
1364
+ function _esysgovPos(n, label) {
1365
+ const v = Math.floor(Number(n));
1366
+ if (!Number.isFinite(v) || v <= 0)
1367
+ throw new Error(`${label} must be positive integer`);
1368
+ return v;
1369
+ }
1370
+ function _esysgovCheckP(from, to) {
1371
+ const a = _esysgovPTrans.get(from);
1372
+ if (!a || !a.has(to))
1373
+ throw new Error(`invalid esysgov profile transition ${from} → ${to}`);
1374
+ }
1375
+ function _esysgovCheckJ(from, to) {
1376
+ const a = _esysgovJTrans.get(from);
1377
+ if (!a || !a.has(to))
1378
+ throw new Error(`invalid esysgov cycle transition ${from} → ${to}`);
1379
+ }
1380
+ function _esysgovCountActive(owner) {
1381
+ let c = 0;
1382
+ for (const p of _esysgovPsV2.values())
1383
+ if (p.owner === owner && p.status === ESYSGOV_PROFILE_MATURITY_V2.ACTIVE)
1384
+ c++;
1385
+ return c;
1386
+ }
1387
+ function _esysgovCountPending(profileId) {
1388
+ let c = 0;
1389
+ for (const j of _esysgovJsV2.values())
1390
+ if (
1391
+ j.profileId === profileId &&
1392
+ (j.status === ESYSGOV_CYCLE_LIFECYCLE_V2.QUEUED ||
1393
+ j.status === ESYSGOV_CYCLE_LIFECYCLE_V2.EVOLVING)
1394
+ )
1395
+ c++;
1396
+ return c;
1397
+ }
1398
+ export function setMaxActiveEsysProfilesPerOwnerV2(n) {
1399
+ _esysgovMaxActive = _esysgovPos(n, "maxActiveEsysProfilesPerOwner");
1400
+ }
1401
+ export function getMaxActiveEsysProfilesPerOwnerV2() {
1402
+ return _esysgovMaxActive;
1403
+ }
1404
+ export function setMaxPendingEsysCyclesPerProfileV2(n) {
1405
+ _esysgovMaxPending = _esysgovPos(n, "maxPendingEsysCyclesPerProfile");
1406
+ }
1407
+ export function getMaxPendingEsysCyclesPerProfileV2() {
1408
+ return _esysgovMaxPending;
1409
+ }
1410
+ export function setEsysProfileIdleMsV2(n) {
1411
+ _esysgovIdleMs = _esysgovPos(n, "esysgovProfileIdleMs");
1412
+ }
1413
+ export function getEsysProfileIdleMsV2() {
1414
+ return _esysgovIdleMs;
1415
+ }
1416
+ export function setEsysCycleStuckMsV2(n) {
1417
+ _esysgovStuckMs = _esysgovPos(n, "esysgovCycleStuckMs");
1418
+ }
1419
+ export function getEsysCycleStuckMsV2() {
1420
+ return _esysgovStuckMs;
1421
+ }
1422
+ export function _resetStateEsysgovV2() {
1423
+ _esysgovPsV2.clear();
1424
+ _esysgovJsV2.clear();
1425
+ _esysgovMaxActive = 6;
1426
+ _esysgovMaxPending = 15;
1427
+ _esysgovIdleMs = 2592000000;
1428
+ _esysgovStuckMs = 60 * 1000;
1429
+ }
1430
+ export function registerEsysProfileV2({ id, owner, lane, metadata } = {}) {
1431
+ if (!id || !owner) throw new Error("id and owner required");
1432
+ if (_esysgovPsV2.has(id))
1433
+ throw new Error(`esysgov profile ${id} already exists`);
1434
+ const now = Date.now();
1435
+ const p = {
1436
+ id,
1437
+ owner,
1438
+ lane: lane || "default",
1439
+ status: ESYSGOV_PROFILE_MATURITY_V2.PENDING,
1440
+ createdAt: now,
1441
+ updatedAt: now,
1442
+ lastTouchedAt: now,
1443
+ activatedAt: null,
1444
+ archivedAt: null,
1445
+ metadata: { ...(metadata || {}) },
1446
+ };
1447
+ _esysgovPsV2.set(id, p);
1448
+ return { ...p, metadata: { ...p.metadata } };
1449
+ }
1450
+ export function activateEsysProfileV2(id) {
1451
+ const p = _esysgovPsV2.get(id);
1452
+ if (!p) throw new Error(`esysgov profile ${id} not found`);
1453
+ const isInitial = p.status === ESYSGOV_PROFILE_MATURITY_V2.PENDING;
1454
+ _esysgovCheckP(p.status, ESYSGOV_PROFILE_MATURITY_V2.ACTIVE);
1455
+ if (isInitial && _esysgovCountActive(p.owner) >= _esysgovMaxActive)
1456
+ throw new Error(`max active esysgov profiles for owner ${p.owner} reached`);
1457
+ const now = Date.now();
1458
+ p.status = ESYSGOV_PROFILE_MATURITY_V2.ACTIVE;
1459
+ p.updatedAt = now;
1460
+ p.lastTouchedAt = now;
1461
+ if (!p.activatedAt) p.activatedAt = now;
1462
+ return { ...p, metadata: { ...p.metadata } };
1463
+ }
1464
+ export function pausedEsysProfileV2(id) {
1465
+ const p = _esysgovPsV2.get(id);
1466
+ if (!p) throw new Error(`esysgov profile ${id} not found`);
1467
+ _esysgovCheckP(p.status, ESYSGOV_PROFILE_MATURITY_V2.PAUSED);
1468
+ p.status = ESYSGOV_PROFILE_MATURITY_V2.PAUSED;
1469
+ p.updatedAt = Date.now();
1470
+ return { ...p, metadata: { ...p.metadata } };
1471
+ }
1472
+ export function archiveEsysProfileV2(id) {
1473
+ const p = _esysgovPsV2.get(id);
1474
+ if (!p) throw new Error(`esysgov profile ${id} not found`);
1475
+ _esysgovCheckP(p.status, ESYSGOV_PROFILE_MATURITY_V2.ARCHIVED);
1476
+ const now = Date.now();
1477
+ p.status = ESYSGOV_PROFILE_MATURITY_V2.ARCHIVED;
1478
+ p.updatedAt = now;
1479
+ if (!p.archivedAt) p.archivedAt = now;
1480
+ return { ...p, metadata: { ...p.metadata } };
1481
+ }
1482
+ export function touchEsysProfileV2(id) {
1483
+ const p = _esysgovPsV2.get(id);
1484
+ if (!p) throw new Error(`esysgov profile ${id} not found`);
1485
+ if (_esysgovPTerminal.has(p.status))
1486
+ throw new Error(`cannot touch terminal esysgov profile ${id}`);
1487
+ const now = Date.now();
1488
+ p.lastTouchedAt = now;
1489
+ p.updatedAt = now;
1490
+ return { ...p, metadata: { ...p.metadata } };
1491
+ }
1492
+ export function getEsysProfileV2(id) {
1493
+ const p = _esysgovPsV2.get(id);
1494
+ if (!p) return null;
1495
+ return { ...p, metadata: { ...p.metadata } };
1496
+ }
1497
+ export function listEsysProfilesV2() {
1498
+ return [..._esysgovPsV2.values()].map((p) => ({
1499
+ ...p,
1500
+ metadata: { ...p.metadata },
1501
+ }));
1502
+ }
1503
+ export function createEsysCycleV2({ id, profileId, cycleId, metadata } = {}) {
1504
+ if (!id || !profileId) throw new Error("id and profileId required");
1505
+ if (_esysgovJsV2.has(id))
1506
+ throw new Error(`esysgov cycle ${id} already exists`);
1507
+ if (!_esysgovPsV2.has(profileId))
1508
+ throw new Error(`esysgov profile ${profileId} not found`);
1509
+ if (_esysgovCountPending(profileId) >= _esysgovMaxPending)
1510
+ throw new Error(
1511
+ `max pending esysgov cycles for profile ${profileId} reached`,
1512
+ );
1513
+ const now = Date.now();
1514
+ const j = {
1515
+ id,
1516
+ profileId,
1517
+ cycleId: cycleId || "",
1518
+ status: ESYSGOV_CYCLE_LIFECYCLE_V2.QUEUED,
1519
+ createdAt: now,
1520
+ updatedAt: now,
1521
+ startedAt: null,
1522
+ settledAt: null,
1523
+ metadata: { ...(metadata || {}) },
1524
+ };
1525
+ _esysgovJsV2.set(id, j);
1526
+ return { ...j, metadata: { ...j.metadata } };
1527
+ }
1528
+ export function evolvingEsysCycleV2(id) {
1529
+ const j = _esysgovJsV2.get(id);
1530
+ if (!j) throw new Error(`esysgov cycle ${id} not found`);
1531
+ _esysgovCheckJ(j.status, ESYSGOV_CYCLE_LIFECYCLE_V2.EVOLVING);
1532
+ const now = Date.now();
1533
+ j.status = ESYSGOV_CYCLE_LIFECYCLE_V2.EVOLVING;
1534
+ j.updatedAt = now;
1535
+ if (!j.startedAt) j.startedAt = now;
1536
+ return { ...j, metadata: { ...j.metadata } };
1537
+ }
1538
+ export function completeCycleEsysV2(id) {
1539
+ const j = _esysgovJsV2.get(id);
1540
+ if (!j) throw new Error(`esysgov cycle ${id} not found`);
1541
+ _esysgovCheckJ(j.status, ESYSGOV_CYCLE_LIFECYCLE_V2.EVOLVED);
1542
+ const now = Date.now();
1543
+ j.status = ESYSGOV_CYCLE_LIFECYCLE_V2.EVOLVED;
1544
+ j.updatedAt = now;
1545
+ if (!j.settledAt) j.settledAt = now;
1546
+ return { ...j, metadata: { ...j.metadata } };
1547
+ }
1548
+ export function failEsysCycleV2(id, reason) {
1549
+ const j = _esysgovJsV2.get(id);
1550
+ if (!j) throw new Error(`esysgov cycle ${id} not found`);
1551
+ _esysgovCheckJ(j.status, ESYSGOV_CYCLE_LIFECYCLE_V2.FAILED);
1552
+ const now = Date.now();
1553
+ j.status = ESYSGOV_CYCLE_LIFECYCLE_V2.FAILED;
1554
+ j.updatedAt = now;
1555
+ if (!j.settledAt) j.settledAt = now;
1556
+ if (reason) j.metadata.failReason = String(reason);
1557
+ return { ...j, metadata: { ...j.metadata } };
1558
+ }
1559
+ export function cancelEsysCycleV2(id, reason) {
1560
+ const j = _esysgovJsV2.get(id);
1561
+ if (!j) throw new Error(`esysgov cycle ${id} not found`);
1562
+ _esysgovCheckJ(j.status, ESYSGOV_CYCLE_LIFECYCLE_V2.CANCELLED);
1563
+ const now = Date.now();
1564
+ j.status = ESYSGOV_CYCLE_LIFECYCLE_V2.CANCELLED;
1565
+ j.updatedAt = now;
1566
+ if (!j.settledAt) j.settledAt = now;
1567
+ if (reason) j.metadata.cancelReason = String(reason);
1568
+ return { ...j, metadata: { ...j.metadata } };
1569
+ }
1570
+ export function getEsysCycleV2(id) {
1571
+ const j = _esysgovJsV2.get(id);
1572
+ if (!j) return null;
1573
+ return { ...j, metadata: { ...j.metadata } };
1574
+ }
1575
+ export function listEsysCyclesV2() {
1576
+ return [..._esysgovJsV2.values()].map((j) => ({
1577
+ ...j,
1578
+ metadata: { ...j.metadata },
1579
+ }));
1580
+ }
1581
+ export function autoPausedIdleEsysProfilesV2({ now } = {}) {
1582
+ const t = now ?? Date.now();
1583
+ const flipped = [];
1584
+ for (const p of _esysgovPsV2.values())
1585
+ if (
1586
+ p.status === ESYSGOV_PROFILE_MATURITY_V2.ACTIVE &&
1587
+ t - p.lastTouchedAt >= _esysgovIdleMs
1588
+ ) {
1589
+ p.status = ESYSGOV_PROFILE_MATURITY_V2.PAUSED;
1590
+ p.updatedAt = t;
1591
+ flipped.push(p.id);
1592
+ }
1593
+ return { flipped, count: flipped.length };
1594
+ }
1595
+ export function autoFailStuckEsysCyclesV2({ now } = {}) {
1596
+ const t = now ?? Date.now();
1597
+ const flipped = [];
1598
+ for (const j of _esysgovJsV2.values())
1599
+ if (
1600
+ j.status === ESYSGOV_CYCLE_LIFECYCLE_V2.EVOLVING &&
1601
+ j.startedAt != null &&
1602
+ t - j.startedAt >= _esysgovStuckMs
1603
+ ) {
1604
+ j.status = ESYSGOV_CYCLE_LIFECYCLE_V2.FAILED;
1605
+ j.updatedAt = t;
1606
+ if (!j.settledAt) j.settledAt = t;
1607
+ j.metadata.failReason = "auto-fail-stuck";
1608
+ flipped.push(j.id);
1609
+ }
1610
+ return { flipped, count: flipped.length };
1611
+ }
1612
+ export function getEsysgovStatsV2() {
1613
+ const profilesByStatus = {};
1614
+ for (const v of Object.values(ESYSGOV_PROFILE_MATURITY_V2))
1615
+ profilesByStatus[v] = 0;
1616
+ for (const p of _esysgovPsV2.values()) profilesByStatus[p.status]++;
1617
+ const cyclesByStatus = {};
1618
+ for (const v of Object.values(ESYSGOV_CYCLE_LIFECYCLE_V2))
1619
+ cyclesByStatus[v] = 0;
1620
+ for (const j of _esysgovJsV2.values()) cyclesByStatus[j.status]++;
1621
+ return {
1622
+ totalEsysProfilesV2: _esysgovPsV2.size,
1623
+ totalEsysCyclesV2: _esysgovJsV2.size,
1624
+ maxActiveEsysProfilesPerOwner: _esysgovMaxActive,
1625
+ maxPendingEsysCyclesPerProfile: _esysgovMaxPending,
1626
+ esysgovProfileIdleMs: _esysgovIdleMs,
1627
+ esysgovCycleStuckMs: _esysgovStuckMs,
1628
+ profilesByStatus,
1629
+ cyclesByStatus,
1630
+ };
1631
+ }
@@ -133,3 +133,345 @@ export class EvoMapClient {
133
133
  }
134
134
  }
135
135
  }
136
+
137
+ // =====================================================================
138
+ // evomap-client V2 governance overlay (iter27)
139
+ // =====================================================================
140
+ export const EVCLIGOV_PROFILE_MATURITY_V2 = Object.freeze({
141
+ PENDING: "pending",
142
+ ACTIVE: "active",
143
+ STALE: "stale",
144
+ ARCHIVED: "archived",
145
+ });
146
+ export const EVCLIGOV_RPC_LIFECYCLE_V2 = Object.freeze({
147
+ QUEUED: "queued",
148
+ CALLING: "calling",
149
+ RETURNED: "returned",
150
+ FAILED: "failed",
151
+ CANCELLED: "cancelled",
152
+ });
153
+ const _evcligovPTrans = new Map([
154
+ [
155
+ EVCLIGOV_PROFILE_MATURITY_V2.PENDING,
156
+ new Set([
157
+ EVCLIGOV_PROFILE_MATURITY_V2.ACTIVE,
158
+ EVCLIGOV_PROFILE_MATURITY_V2.ARCHIVED,
159
+ ]),
160
+ ],
161
+ [
162
+ EVCLIGOV_PROFILE_MATURITY_V2.ACTIVE,
163
+ new Set([
164
+ EVCLIGOV_PROFILE_MATURITY_V2.STALE,
165
+ EVCLIGOV_PROFILE_MATURITY_V2.ARCHIVED,
166
+ ]),
167
+ ],
168
+ [
169
+ EVCLIGOV_PROFILE_MATURITY_V2.STALE,
170
+ new Set([
171
+ EVCLIGOV_PROFILE_MATURITY_V2.ACTIVE,
172
+ EVCLIGOV_PROFILE_MATURITY_V2.ARCHIVED,
173
+ ]),
174
+ ],
175
+ [EVCLIGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
176
+ ]);
177
+ const _evcligovPTerminal = new Set([EVCLIGOV_PROFILE_MATURITY_V2.ARCHIVED]);
178
+ const _evcligovJTrans = new Map([
179
+ [
180
+ EVCLIGOV_RPC_LIFECYCLE_V2.QUEUED,
181
+ new Set([
182
+ EVCLIGOV_RPC_LIFECYCLE_V2.CALLING,
183
+ EVCLIGOV_RPC_LIFECYCLE_V2.CANCELLED,
184
+ ]),
185
+ ],
186
+ [
187
+ EVCLIGOV_RPC_LIFECYCLE_V2.CALLING,
188
+ new Set([
189
+ EVCLIGOV_RPC_LIFECYCLE_V2.RETURNED,
190
+ EVCLIGOV_RPC_LIFECYCLE_V2.FAILED,
191
+ EVCLIGOV_RPC_LIFECYCLE_V2.CANCELLED,
192
+ ]),
193
+ ],
194
+ [EVCLIGOV_RPC_LIFECYCLE_V2.RETURNED, new Set()],
195
+ [EVCLIGOV_RPC_LIFECYCLE_V2.FAILED, new Set()],
196
+ [EVCLIGOV_RPC_LIFECYCLE_V2.CANCELLED, new Set()],
197
+ ]);
198
+ const _evcligovPsV2 = new Map();
199
+ const _evcligovJsV2 = new Map();
200
+ let _evcligovMaxActive = 6,
201
+ _evcligovMaxPending = 15,
202
+ _evcligovIdleMs = 30 * 24 * 60 * 60 * 1000,
203
+ _evcligovStuckMs = 60 * 1000;
204
+ function _evcligovPos(n, label) {
205
+ const v = Math.floor(Number(n));
206
+ if (!Number.isFinite(v) || v <= 0)
207
+ throw new Error(`${label} must be positive integer`);
208
+ return v;
209
+ }
210
+ function _evcligovCheckP(from, to) {
211
+ const a = _evcligovPTrans.get(from);
212
+ if (!a || !a.has(to))
213
+ throw new Error(`invalid evcligov profile transition ${from} → ${to}`);
214
+ }
215
+ function _evcligovCheckJ(from, to) {
216
+ const a = _evcligovJTrans.get(from);
217
+ if (!a || !a.has(to))
218
+ throw new Error(`invalid evcligov rpc transition ${from} → ${to}`);
219
+ }
220
+ function _evcligovCountActive(owner) {
221
+ let c = 0;
222
+ for (const p of _evcligovPsV2.values())
223
+ if (p.owner === owner && p.status === EVCLIGOV_PROFILE_MATURITY_V2.ACTIVE)
224
+ c++;
225
+ return c;
226
+ }
227
+ function _evcligovCountPending(profileId) {
228
+ let c = 0;
229
+ for (const j of _evcligovJsV2.values())
230
+ if (
231
+ j.profileId === profileId &&
232
+ (j.status === EVCLIGOV_RPC_LIFECYCLE_V2.QUEUED ||
233
+ j.status === EVCLIGOV_RPC_LIFECYCLE_V2.CALLING)
234
+ )
235
+ c++;
236
+ return c;
237
+ }
238
+ export function setMaxActiveEvcligovProfilesPerOwnerV2(n) {
239
+ _evcligovMaxActive = _evcligovPos(n, "maxActiveEvcligovProfilesPerOwner");
240
+ }
241
+ export function getMaxActiveEvcligovProfilesPerOwnerV2() {
242
+ return _evcligovMaxActive;
243
+ }
244
+ export function setMaxPendingEvcligovRpcsPerProfileV2(n) {
245
+ _evcligovMaxPending = _evcligovPos(n, "maxPendingEvcligovRpcsPerProfile");
246
+ }
247
+ export function getMaxPendingEvcligovRpcsPerProfileV2() {
248
+ return _evcligovMaxPending;
249
+ }
250
+ export function setEvcligovProfileIdleMsV2(n) {
251
+ _evcligovIdleMs = _evcligovPos(n, "evcligovProfileIdleMs");
252
+ }
253
+ export function getEvcligovProfileIdleMsV2() {
254
+ return _evcligovIdleMs;
255
+ }
256
+ export function setEvcligovRpcStuckMsV2(n) {
257
+ _evcligovStuckMs = _evcligovPos(n, "evcligovRpcStuckMs");
258
+ }
259
+ export function getEvcligovRpcStuckMsV2() {
260
+ return _evcligovStuckMs;
261
+ }
262
+ export function _resetStateEvomapClientGovV2() {
263
+ _evcligovPsV2.clear();
264
+ _evcligovJsV2.clear();
265
+ _evcligovMaxActive = 6;
266
+ _evcligovMaxPending = 15;
267
+ _evcligovIdleMs = 30 * 24 * 60 * 60 * 1000;
268
+ _evcligovStuckMs = 60 * 1000;
269
+ }
270
+ export function registerEvcligovProfileV2({
271
+ id,
272
+ owner,
273
+ endpoint,
274
+ metadata,
275
+ } = {}) {
276
+ if (!id || !owner) throw new Error("id and owner required");
277
+ if (_evcligovPsV2.has(id))
278
+ throw new Error(`evcligov profile ${id} already exists`);
279
+ const now = Date.now();
280
+ const p = {
281
+ id,
282
+ owner,
283
+ endpoint: endpoint || "primary",
284
+ status: EVCLIGOV_PROFILE_MATURITY_V2.PENDING,
285
+ createdAt: now,
286
+ updatedAt: now,
287
+ lastTouchedAt: now,
288
+ activatedAt: null,
289
+ archivedAt: null,
290
+ metadata: { ...(metadata || {}) },
291
+ };
292
+ _evcligovPsV2.set(id, p);
293
+ return { ...p, metadata: { ...p.metadata } };
294
+ }
295
+ export function activateEvcligovProfileV2(id) {
296
+ const p = _evcligovPsV2.get(id);
297
+ if (!p) throw new Error(`evcligov profile ${id} not found`);
298
+ const isInitial = p.status === EVCLIGOV_PROFILE_MATURITY_V2.PENDING;
299
+ _evcligovCheckP(p.status, EVCLIGOV_PROFILE_MATURITY_V2.ACTIVE);
300
+ if (isInitial && _evcligovCountActive(p.owner) >= _evcligovMaxActive)
301
+ throw new Error(
302
+ `max active evcligov profiles for owner ${p.owner} reached`,
303
+ );
304
+ const now = Date.now();
305
+ p.status = EVCLIGOV_PROFILE_MATURITY_V2.ACTIVE;
306
+ p.updatedAt = now;
307
+ p.lastTouchedAt = now;
308
+ if (!p.activatedAt) p.activatedAt = now;
309
+ return { ...p, metadata: { ...p.metadata } };
310
+ }
311
+ export function staleEvcligovProfileV2(id) {
312
+ const p = _evcligovPsV2.get(id);
313
+ if (!p) throw new Error(`evcligov profile ${id} not found`);
314
+ _evcligovCheckP(p.status, EVCLIGOV_PROFILE_MATURITY_V2.STALE);
315
+ p.status = EVCLIGOV_PROFILE_MATURITY_V2.STALE;
316
+ p.updatedAt = Date.now();
317
+ return { ...p, metadata: { ...p.metadata } };
318
+ }
319
+ export function archiveEvcligovProfileV2(id) {
320
+ const p = _evcligovPsV2.get(id);
321
+ if (!p) throw new Error(`evcligov profile ${id} not found`);
322
+ _evcligovCheckP(p.status, EVCLIGOV_PROFILE_MATURITY_V2.ARCHIVED);
323
+ const now = Date.now();
324
+ p.status = EVCLIGOV_PROFILE_MATURITY_V2.ARCHIVED;
325
+ p.updatedAt = now;
326
+ if (!p.archivedAt) p.archivedAt = now;
327
+ return { ...p, metadata: { ...p.metadata } };
328
+ }
329
+ export function touchEvcligovProfileV2(id) {
330
+ const p = _evcligovPsV2.get(id);
331
+ if (!p) throw new Error(`evcligov profile ${id} not found`);
332
+ if (_evcligovPTerminal.has(p.status))
333
+ throw new Error(`cannot touch terminal evcligov profile ${id}`);
334
+ const now = Date.now();
335
+ p.lastTouchedAt = now;
336
+ p.updatedAt = now;
337
+ return { ...p, metadata: { ...p.metadata } };
338
+ }
339
+ export function getEvcligovProfileV2(id) {
340
+ const p = _evcligovPsV2.get(id);
341
+ if (!p) return null;
342
+ return { ...p, metadata: { ...p.metadata } };
343
+ }
344
+ export function listEvcligovProfilesV2() {
345
+ return [..._evcligovPsV2.values()].map((p) => ({
346
+ ...p,
347
+ metadata: { ...p.metadata },
348
+ }));
349
+ }
350
+ export function createEvcligovRpcV2({ id, profileId, method, metadata } = {}) {
351
+ if (!id || !profileId) throw new Error("id and profileId required");
352
+ if (_evcligovJsV2.has(id))
353
+ throw new Error(`evcligov rpc ${id} already exists`);
354
+ if (!_evcligovPsV2.has(profileId))
355
+ throw new Error(`evcligov profile ${profileId} not found`);
356
+ if (_evcligovCountPending(profileId) >= _evcligovMaxPending)
357
+ throw new Error(
358
+ `max pending evcligov rpcs for profile ${profileId} reached`,
359
+ );
360
+ const now = Date.now();
361
+ const j = {
362
+ id,
363
+ profileId,
364
+ method: method || "",
365
+ status: EVCLIGOV_RPC_LIFECYCLE_V2.QUEUED,
366
+ createdAt: now,
367
+ updatedAt: now,
368
+ startedAt: null,
369
+ settledAt: null,
370
+ metadata: { ...(metadata || {}) },
371
+ };
372
+ _evcligovJsV2.set(id, j);
373
+ return { ...j, metadata: { ...j.metadata } };
374
+ }
375
+ export function callingEvcligovRpcV2(id) {
376
+ const j = _evcligovJsV2.get(id);
377
+ if (!j) throw new Error(`evcligov rpc ${id} not found`);
378
+ _evcligovCheckJ(j.status, EVCLIGOV_RPC_LIFECYCLE_V2.CALLING);
379
+ const now = Date.now();
380
+ j.status = EVCLIGOV_RPC_LIFECYCLE_V2.CALLING;
381
+ j.updatedAt = now;
382
+ if (!j.startedAt) j.startedAt = now;
383
+ return { ...j, metadata: { ...j.metadata } };
384
+ }
385
+ export function completeRpcEvcligovV2(id) {
386
+ const j = _evcligovJsV2.get(id);
387
+ if (!j) throw new Error(`evcligov rpc ${id} not found`);
388
+ _evcligovCheckJ(j.status, EVCLIGOV_RPC_LIFECYCLE_V2.RETURNED);
389
+ const now = Date.now();
390
+ j.status = EVCLIGOV_RPC_LIFECYCLE_V2.RETURNED;
391
+ j.updatedAt = now;
392
+ if (!j.settledAt) j.settledAt = now;
393
+ return { ...j, metadata: { ...j.metadata } };
394
+ }
395
+ export function failEvcligovRpcV2(id, reason) {
396
+ const j = _evcligovJsV2.get(id);
397
+ if (!j) throw new Error(`evcligov rpc ${id} not found`);
398
+ _evcligovCheckJ(j.status, EVCLIGOV_RPC_LIFECYCLE_V2.FAILED);
399
+ const now = Date.now();
400
+ j.status = EVCLIGOV_RPC_LIFECYCLE_V2.FAILED;
401
+ j.updatedAt = now;
402
+ if (!j.settledAt) j.settledAt = now;
403
+ if (reason) j.metadata.failReason = String(reason);
404
+ return { ...j, metadata: { ...j.metadata } };
405
+ }
406
+ export function cancelEvcligovRpcV2(id, reason) {
407
+ const j = _evcligovJsV2.get(id);
408
+ if (!j) throw new Error(`evcligov rpc ${id} not found`);
409
+ _evcligovCheckJ(j.status, EVCLIGOV_RPC_LIFECYCLE_V2.CANCELLED);
410
+ const now = Date.now();
411
+ j.status = EVCLIGOV_RPC_LIFECYCLE_V2.CANCELLED;
412
+ j.updatedAt = now;
413
+ if (!j.settledAt) j.settledAt = now;
414
+ if (reason) j.metadata.cancelReason = String(reason);
415
+ return { ...j, metadata: { ...j.metadata } };
416
+ }
417
+ export function getEvcligovRpcV2(id) {
418
+ const j = _evcligovJsV2.get(id);
419
+ if (!j) return null;
420
+ return { ...j, metadata: { ...j.metadata } };
421
+ }
422
+ export function listEvcligovRpcsV2() {
423
+ return [..._evcligovJsV2.values()].map((j) => ({
424
+ ...j,
425
+ metadata: { ...j.metadata },
426
+ }));
427
+ }
428
+ export function autoStaleIdleEvcligovProfilesV2({ now } = {}) {
429
+ const t = now ?? Date.now();
430
+ const flipped = [];
431
+ for (const p of _evcligovPsV2.values())
432
+ if (
433
+ p.status === EVCLIGOV_PROFILE_MATURITY_V2.ACTIVE &&
434
+ t - p.lastTouchedAt >= _evcligovIdleMs
435
+ ) {
436
+ p.status = EVCLIGOV_PROFILE_MATURITY_V2.STALE;
437
+ p.updatedAt = t;
438
+ flipped.push(p.id);
439
+ }
440
+ return { flipped, count: flipped.length };
441
+ }
442
+ export function autoFailStuckEvcligovRpcsV2({ now } = {}) {
443
+ const t = now ?? Date.now();
444
+ const flipped = [];
445
+ for (const j of _evcligovJsV2.values())
446
+ if (
447
+ j.status === EVCLIGOV_RPC_LIFECYCLE_V2.CALLING &&
448
+ j.startedAt != null &&
449
+ t - j.startedAt >= _evcligovStuckMs
450
+ ) {
451
+ j.status = EVCLIGOV_RPC_LIFECYCLE_V2.FAILED;
452
+ j.updatedAt = t;
453
+ if (!j.settledAt) j.settledAt = t;
454
+ j.metadata.failReason = "auto-fail-stuck";
455
+ flipped.push(j.id);
456
+ }
457
+ return { flipped, count: flipped.length };
458
+ }
459
+ export function getEvomapClientGovStatsV2() {
460
+ const profilesByStatus = {};
461
+ for (const v of Object.values(EVCLIGOV_PROFILE_MATURITY_V2))
462
+ profilesByStatus[v] = 0;
463
+ for (const p of _evcligovPsV2.values()) profilesByStatus[p.status]++;
464
+ const rpcsByStatus = {};
465
+ for (const v of Object.values(EVCLIGOV_RPC_LIFECYCLE_V2)) rpcsByStatus[v] = 0;
466
+ for (const j of _evcligovJsV2.values()) rpcsByStatus[j.status]++;
467
+ return {
468
+ totalEvcligovProfilesV2: _evcligovPsV2.size,
469
+ totalEvcligovRpcsV2: _evcligovJsV2.size,
470
+ maxActiveEvcligovProfilesPerOwner: _evcligovMaxActive,
471
+ maxPendingEvcligovRpcsPerProfile: _evcligovMaxPending,
472
+ evcligovProfileIdleMs: _evcligovIdleMs,
473
+ evcligovRpcStuckMs: _evcligovStuckMs,
474
+ profilesByStatus,
475
+ rpcsByStatus,
476
+ };
477
+ }