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
@@ -1276,3 +1276,333 @@ export function getWorkflowEngineStatsV2() {
1276
1276
  runsByStatus,
1277
1277
  };
1278
1278
  }
1279
+
1280
+ // =====================================================================
1281
+ // workflow-engine V2 governance overlay (iter21)
1282
+ // =====================================================================
1283
+ export const WFGOV_PROFILE_MATURITY_V2 = Object.freeze({
1284
+ PENDING: "pending",
1285
+ ACTIVE: "active",
1286
+ PAUSED: "paused",
1287
+ ARCHIVED: "archived",
1288
+ });
1289
+ export const WFGOV_STEP_LIFECYCLE_V2 = Object.freeze({
1290
+ QUEUED: "queued",
1291
+ EXECUTING: "executing",
1292
+ EXECUTED: "executed",
1293
+ FAILED: "failed",
1294
+ CANCELLED: "cancelled",
1295
+ });
1296
+ const _wfgovPTrans = new Map([
1297
+ [
1298
+ WFGOV_PROFILE_MATURITY_V2.PENDING,
1299
+ new Set([
1300
+ WFGOV_PROFILE_MATURITY_V2.ACTIVE,
1301
+ WFGOV_PROFILE_MATURITY_V2.ARCHIVED,
1302
+ ]),
1303
+ ],
1304
+ [
1305
+ WFGOV_PROFILE_MATURITY_V2.ACTIVE,
1306
+ new Set([
1307
+ WFGOV_PROFILE_MATURITY_V2.PAUSED,
1308
+ WFGOV_PROFILE_MATURITY_V2.ARCHIVED,
1309
+ ]),
1310
+ ],
1311
+ [
1312
+ WFGOV_PROFILE_MATURITY_V2.PAUSED,
1313
+ new Set([
1314
+ WFGOV_PROFILE_MATURITY_V2.ACTIVE,
1315
+ WFGOV_PROFILE_MATURITY_V2.ARCHIVED,
1316
+ ]),
1317
+ ],
1318
+ [WFGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
1319
+ ]);
1320
+ const _wfgovPTerminal = new Set([WFGOV_PROFILE_MATURITY_V2.ARCHIVED]);
1321
+ const _wfgovJTrans = new Map([
1322
+ [
1323
+ WFGOV_STEP_LIFECYCLE_V2.QUEUED,
1324
+ new Set([
1325
+ WFGOV_STEP_LIFECYCLE_V2.EXECUTING,
1326
+ WFGOV_STEP_LIFECYCLE_V2.CANCELLED,
1327
+ ]),
1328
+ ],
1329
+ [
1330
+ WFGOV_STEP_LIFECYCLE_V2.EXECUTING,
1331
+ new Set([
1332
+ WFGOV_STEP_LIFECYCLE_V2.EXECUTED,
1333
+ WFGOV_STEP_LIFECYCLE_V2.FAILED,
1334
+ WFGOV_STEP_LIFECYCLE_V2.CANCELLED,
1335
+ ]),
1336
+ ],
1337
+ [WFGOV_STEP_LIFECYCLE_V2.EXECUTED, new Set()],
1338
+ [WFGOV_STEP_LIFECYCLE_V2.FAILED, new Set()],
1339
+ [WFGOV_STEP_LIFECYCLE_V2.CANCELLED, new Set()],
1340
+ ]);
1341
+ const _wfgovPsV2 = new Map();
1342
+ const _wfgovJsV2 = new Map();
1343
+ let _wfgovMaxActive = 8,
1344
+ _wfgovMaxPending = 20,
1345
+ _wfgovIdleMs = 30 * 24 * 60 * 60 * 1000,
1346
+ _wfgovStuckMs = 60 * 1000;
1347
+ function _wfgovPos(n, label) {
1348
+ const v = Math.floor(Number(n));
1349
+ if (!Number.isFinite(v) || v <= 0)
1350
+ throw new Error(`${label} must be positive integer`);
1351
+ return v;
1352
+ }
1353
+ function _wfgovCheckP(from, to) {
1354
+ const a = _wfgovPTrans.get(from);
1355
+ if (!a || !a.has(to))
1356
+ throw new Error(`invalid wfgov profile transition ${from} → ${to}`);
1357
+ }
1358
+ function _wfgovCheckJ(from, to) {
1359
+ const a = _wfgovJTrans.get(from);
1360
+ if (!a || !a.has(to))
1361
+ throw new Error(`invalid wfgov step transition ${from} → ${to}`);
1362
+ }
1363
+ function _wfgovCountActive(owner) {
1364
+ let c = 0;
1365
+ for (const p of _wfgovPsV2.values())
1366
+ if (p.owner === owner && p.status === WFGOV_PROFILE_MATURITY_V2.ACTIVE) c++;
1367
+ return c;
1368
+ }
1369
+ function _wfgovCountPending(profileId) {
1370
+ let c = 0;
1371
+ for (const j of _wfgovJsV2.values())
1372
+ if (
1373
+ j.profileId === profileId &&
1374
+ (j.status === WFGOV_STEP_LIFECYCLE_V2.QUEUED ||
1375
+ j.status === WFGOV_STEP_LIFECYCLE_V2.EXECUTING)
1376
+ )
1377
+ c++;
1378
+ return c;
1379
+ }
1380
+ export function setMaxActiveWfgovProfilesPerOwnerV2(n) {
1381
+ _wfgovMaxActive = _wfgovPos(n, "maxActiveWfgovProfilesPerOwner");
1382
+ }
1383
+ export function getMaxActiveWfgovProfilesPerOwnerV2() {
1384
+ return _wfgovMaxActive;
1385
+ }
1386
+ export function setMaxPendingWfgovStepsPerProfileV2(n) {
1387
+ _wfgovMaxPending = _wfgovPos(n, "maxPendingWfgovStepsPerProfile");
1388
+ }
1389
+ export function getMaxPendingWfgovStepsPerProfileV2() {
1390
+ return _wfgovMaxPending;
1391
+ }
1392
+ export function setWfgovProfileIdleMsV2(n) {
1393
+ _wfgovIdleMs = _wfgovPos(n, "wfgovProfileIdleMs");
1394
+ }
1395
+ export function getWfgovProfileIdleMsV2() {
1396
+ return _wfgovIdleMs;
1397
+ }
1398
+ export function setWfgovStepStuckMsV2(n) {
1399
+ _wfgovStuckMs = _wfgovPos(n, "wfgovStepStuckMs");
1400
+ }
1401
+ export function getWfgovStepStuckMsV2() {
1402
+ return _wfgovStuckMs;
1403
+ }
1404
+ export function _resetStateWorkflowEngineGovV2() {
1405
+ _wfgovPsV2.clear();
1406
+ _wfgovJsV2.clear();
1407
+ _wfgovMaxActive = 8;
1408
+ _wfgovMaxPending = 20;
1409
+ _wfgovIdleMs = 30 * 24 * 60 * 60 * 1000;
1410
+ _wfgovStuckMs = 60 * 1000;
1411
+ }
1412
+ export function registerWfgovProfileV2({ id, owner, kind, metadata } = {}) {
1413
+ if (!id || !owner) throw new Error("id and owner required");
1414
+ if (_wfgovPsV2.has(id)) throw new Error(`wfgov profile ${id} already exists`);
1415
+ const now = Date.now();
1416
+ const p = {
1417
+ id,
1418
+ owner,
1419
+ kind: kind || "sequential",
1420
+ status: WFGOV_PROFILE_MATURITY_V2.PENDING,
1421
+ createdAt: now,
1422
+ updatedAt: now,
1423
+ lastTouchedAt: now,
1424
+ activatedAt: null,
1425
+ archivedAt: null,
1426
+ metadata: { ...(metadata || {}) },
1427
+ };
1428
+ _wfgovPsV2.set(id, p);
1429
+ return { ...p, metadata: { ...p.metadata } };
1430
+ }
1431
+ export function activateWfgovProfileV2(id) {
1432
+ const p = _wfgovPsV2.get(id);
1433
+ if (!p) throw new Error(`wfgov profile ${id} not found`);
1434
+ const isInitial = p.status === WFGOV_PROFILE_MATURITY_V2.PENDING;
1435
+ _wfgovCheckP(p.status, WFGOV_PROFILE_MATURITY_V2.ACTIVE);
1436
+ if (isInitial && _wfgovCountActive(p.owner) >= _wfgovMaxActive)
1437
+ throw new Error(`max active wfgov profiles for owner ${p.owner} reached`);
1438
+ const now = Date.now();
1439
+ p.status = WFGOV_PROFILE_MATURITY_V2.ACTIVE;
1440
+ p.updatedAt = now;
1441
+ p.lastTouchedAt = now;
1442
+ if (!p.activatedAt) p.activatedAt = now;
1443
+ return { ...p, metadata: { ...p.metadata } };
1444
+ }
1445
+ export function pauseWfgovProfileV2(id) {
1446
+ const p = _wfgovPsV2.get(id);
1447
+ if (!p) throw new Error(`wfgov profile ${id} not found`);
1448
+ _wfgovCheckP(p.status, WFGOV_PROFILE_MATURITY_V2.PAUSED);
1449
+ p.status = WFGOV_PROFILE_MATURITY_V2.PAUSED;
1450
+ p.updatedAt = Date.now();
1451
+ return { ...p, metadata: { ...p.metadata } };
1452
+ }
1453
+ export function archiveWfgovProfileV2(id) {
1454
+ const p = _wfgovPsV2.get(id);
1455
+ if (!p) throw new Error(`wfgov profile ${id} not found`);
1456
+ _wfgovCheckP(p.status, WFGOV_PROFILE_MATURITY_V2.ARCHIVED);
1457
+ const now = Date.now();
1458
+ p.status = WFGOV_PROFILE_MATURITY_V2.ARCHIVED;
1459
+ p.updatedAt = now;
1460
+ if (!p.archivedAt) p.archivedAt = now;
1461
+ return { ...p, metadata: { ...p.metadata } };
1462
+ }
1463
+ export function touchWfgovProfileV2(id) {
1464
+ const p = _wfgovPsV2.get(id);
1465
+ if (!p) throw new Error(`wfgov profile ${id} not found`);
1466
+ if (_wfgovPTerminal.has(p.status))
1467
+ throw new Error(`cannot touch terminal wfgov profile ${id}`);
1468
+ const now = Date.now();
1469
+ p.lastTouchedAt = now;
1470
+ p.updatedAt = now;
1471
+ return { ...p, metadata: { ...p.metadata } };
1472
+ }
1473
+ export function getWfgovProfileV2(id) {
1474
+ const p = _wfgovPsV2.get(id);
1475
+ if (!p) return null;
1476
+ return { ...p, metadata: { ...p.metadata } };
1477
+ }
1478
+ export function listWfgovProfilesV2() {
1479
+ return [..._wfgovPsV2.values()].map((p) => ({
1480
+ ...p,
1481
+ metadata: { ...p.metadata },
1482
+ }));
1483
+ }
1484
+ export function createWfgovStepV2({ id, profileId, stepName, metadata } = {}) {
1485
+ if (!id || !profileId) throw new Error("id and profileId required");
1486
+ if (_wfgovJsV2.has(id)) throw new Error(`wfgov step ${id} already exists`);
1487
+ if (!_wfgovPsV2.has(profileId))
1488
+ throw new Error(`wfgov profile ${profileId} not found`);
1489
+ if (_wfgovCountPending(profileId) >= _wfgovMaxPending)
1490
+ throw new Error(`max pending wfgov steps for profile ${profileId} reached`);
1491
+ const now = Date.now();
1492
+ const j = {
1493
+ id,
1494
+ profileId,
1495
+ stepName: stepName || "",
1496
+ status: WFGOV_STEP_LIFECYCLE_V2.QUEUED,
1497
+ createdAt: now,
1498
+ updatedAt: now,
1499
+ startedAt: null,
1500
+ settledAt: null,
1501
+ metadata: { ...(metadata || {}) },
1502
+ };
1503
+ _wfgovJsV2.set(id, j);
1504
+ return { ...j, metadata: { ...j.metadata } };
1505
+ }
1506
+ export function executingWfgovStepV2(id) {
1507
+ const j = _wfgovJsV2.get(id);
1508
+ if (!j) throw new Error(`wfgov step ${id} not found`);
1509
+ _wfgovCheckJ(j.status, WFGOV_STEP_LIFECYCLE_V2.EXECUTING);
1510
+ const now = Date.now();
1511
+ j.status = WFGOV_STEP_LIFECYCLE_V2.EXECUTING;
1512
+ j.updatedAt = now;
1513
+ if (!j.startedAt) j.startedAt = now;
1514
+ return { ...j, metadata: { ...j.metadata } };
1515
+ }
1516
+ export function completeStepWfgovV2(id) {
1517
+ const j = _wfgovJsV2.get(id);
1518
+ if (!j) throw new Error(`wfgov step ${id} not found`);
1519
+ _wfgovCheckJ(j.status, WFGOV_STEP_LIFECYCLE_V2.EXECUTED);
1520
+ const now = Date.now();
1521
+ j.status = WFGOV_STEP_LIFECYCLE_V2.EXECUTED;
1522
+ j.updatedAt = now;
1523
+ if (!j.settledAt) j.settledAt = now;
1524
+ return { ...j, metadata: { ...j.metadata } };
1525
+ }
1526
+ export function failWfgovStepV2(id, reason) {
1527
+ const j = _wfgovJsV2.get(id);
1528
+ if (!j) throw new Error(`wfgov step ${id} not found`);
1529
+ _wfgovCheckJ(j.status, WFGOV_STEP_LIFECYCLE_V2.FAILED);
1530
+ const now = Date.now();
1531
+ j.status = WFGOV_STEP_LIFECYCLE_V2.FAILED;
1532
+ j.updatedAt = now;
1533
+ if (!j.settledAt) j.settledAt = now;
1534
+ if (reason) j.metadata.failReason = String(reason);
1535
+ return { ...j, metadata: { ...j.metadata } };
1536
+ }
1537
+ export function cancelWfgovStepV2(id, reason) {
1538
+ const j = _wfgovJsV2.get(id);
1539
+ if (!j) throw new Error(`wfgov step ${id} not found`);
1540
+ _wfgovCheckJ(j.status, WFGOV_STEP_LIFECYCLE_V2.CANCELLED);
1541
+ const now = Date.now();
1542
+ j.status = WFGOV_STEP_LIFECYCLE_V2.CANCELLED;
1543
+ j.updatedAt = now;
1544
+ if (!j.settledAt) j.settledAt = now;
1545
+ if (reason) j.metadata.cancelReason = String(reason);
1546
+ return { ...j, metadata: { ...j.metadata } };
1547
+ }
1548
+ export function getWfgovStepV2(id) {
1549
+ const j = _wfgovJsV2.get(id);
1550
+ if (!j) return null;
1551
+ return { ...j, metadata: { ...j.metadata } };
1552
+ }
1553
+ export function listWfgovStepsV2() {
1554
+ return [..._wfgovJsV2.values()].map((j) => ({
1555
+ ...j,
1556
+ metadata: { ...j.metadata },
1557
+ }));
1558
+ }
1559
+ export function autoPauseIdleWfgovProfilesV2({ now } = {}) {
1560
+ const t = now ?? Date.now();
1561
+ const flipped = [];
1562
+ for (const p of _wfgovPsV2.values())
1563
+ if (
1564
+ p.status === WFGOV_PROFILE_MATURITY_V2.ACTIVE &&
1565
+ t - p.lastTouchedAt >= _wfgovIdleMs
1566
+ ) {
1567
+ p.status = WFGOV_PROFILE_MATURITY_V2.PAUSED;
1568
+ p.updatedAt = t;
1569
+ flipped.push(p.id);
1570
+ }
1571
+ return { flipped, count: flipped.length };
1572
+ }
1573
+ export function autoFailStuckWfgovStepsV2({ now } = {}) {
1574
+ const t = now ?? Date.now();
1575
+ const flipped = [];
1576
+ for (const j of _wfgovJsV2.values())
1577
+ if (
1578
+ j.status === WFGOV_STEP_LIFECYCLE_V2.EXECUTING &&
1579
+ j.startedAt != null &&
1580
+ t - j.startedAt >= _wfgovStuckMs
1581
+ ) {
1582
+ j.status = WFGOV_STEP_LIFECYCLE_V2.FAILED;
1583
+ j.updatedAt = t;
1584
+ if (!j.settledAt) j.settledAt = t;
1585
+ j.metadata.failReason = "auto-fail-stuck";
1586
+ flipped.push(j.id);
1587
+ }
1588
+ return { flipped, count: flipped.length };
1589
+ }
1590
+ export function getWorkflowEngineGovStatsV2() {
1591
+ const profilesByStatus = {};
1592
+ for (const v of Object.values(WFGOV_PROFILE_MATURITY_V2))
1593
+ profilesByStatus[v] = 0;
1594
+ for (const p of _wfgovPsV2.values()) profilesByStatus[p.status]++;
1595
+ const stepsByStatus = {};
1596
+ for (const v of Object.values(WFGOV_STEP_LIFECYCLE_V2)) stepsByStatus[v] = 0;
1597
+ for (const j of _wfgovJsV2.values()) stepsByStatus[j.status]++;
1598
+ return {
1599
+ totalWfgovProfilesV2: _wfgovPsV2.size,
1600
+ totalWfgovStepsV2: _wfgovJsV2.size,
1601
+ maxActiveWfgovProfilesPerOwner: _wfgovMaxActive,
1602
+ maxPendingWfgovStepsPerProfile: _wfgovMaxPending,
1603
+ wfgovProfileIdleMs: _wfgovIdleMs,
1604
+ wfgovStepStuckMs: _wfgovStuckMs,
1605
+ profilesByStatus,
1606
+ stepsByStatus,
1607
+ };
1608
+ }
@@ -316,3 +316,349 @@ export function evaluateRaw(src, ctx) {
316
316
  if (ast.kind === "truthy") ast = ast.expr;
317
317
  return evalAst(ast, ctx);
318
318
  }
319
+
320
+ // =====================================================================
321
+ // workflow-expr V2 governance overlay (iter26)
322
+ // =====================================================================
323
+ export const WFEXGOV_PROFILE_MATURITY_V2 = Object.freeze({
324
+ PENDING: "pending",
325
+ ACTIVE: "active",
326
+ PAUSED: "paused",
327
+ ARCHIVED: "archived",
328
+ });
329
+ export const WFEXGOV_EVAL_LIFECYCLE_V2 = Object.freeze({
330
+ QUEUED: "queued",
331
+ EVALUATING: "evaluating",
332
+ EVALUATED: "evaluated",
333
+ FAILED: "failed",
334
+ CANCELLED: "cancelled",
335
+ });
336
+ const _wfexgovPTrans = new Map([
337
+ [
338
+ WFEXGOV_PROFILE_MATURITY_V2.PENDING,
339
+ new Set([
340
+ WFEXGOV_PROFILE_MATURITY_V2.ACTIVE,
341
+ WFEXGOV_PROFILE_MATURITY_V2.ARCHIVED,
342
+ ]),
343
+ ],
344
+ [
345
+ WFEXGOV_PROFILE_MATURITY_V2.ACTIVE,
346
+ new Set([
347
+ WFEXGOV_PROFILE_MATURITY_V2.PAUSED,
348
+ WFEXGOV_PROFILE_MATURITY_V2.ARCHIVED,
349
+ ]),
350
+ ],
351
+ [
352
+ WFEXGOV_PROFILE_MATURITY_V2.PAUSED,
353
+ new Set([
354
+ WFEXGOV_PROFILE_MATURITY_V2.ACTIVE,
355
+ WFEXGOV_PROFILE_MATURITY_V2.ARCHIVED,
356
+ ]),
357
+ ],
358
+ [WFEXGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
359
+ ]);
360
+ const _wfexgovPTerminal = new Set([WFEXGOV_PROFILE_MATURITY_V2.ARCHIVED]);
361
+ const _wfexgovJTrans = new Map([
362
+ [
363
+ WFEXGOV_EVAL_LIFECYCLE_V2.QUEUED,
364
+ new Set([
365
+ WFEXGOV_EVAL_LIFECYCLE_V2.EVALUATING,
366
+ WFEXGOV_EVAL_LIFECYCLE_V2.CANCELLED,
367
+ ]),
368
+ ],
369
+ [
370
+ WFEXGOV_EVAL_LIFECYCLE_V2.EVALUATING,
371
+ new Set([
372
+ WFEXGOV_EVAL_LIFECYCLE_V2.EVALUATED,
373
+ WFEXGOV_EVAL_LIFECYCLE_V2.FAILED,
374
+ WFEXGOV_EVAL_LIFECYCLE_V2.CANCELLED,
375
+ ]),
376
+ ],
377
+ [WFEXGOV_EVAL_LIFECYCLE_V2.EVALUATED, new Set()],
378
+ [WFEXGOV_EVAL_LIFECYCLE_V2.FAILED, new Set()],
379
+ [WFEXGOV_EVAL_LIFECYCLE_V2.CANCELLED, new Set()],
380
+ ]);
381
+ const _wfexgovPsV2 = new Map();
382
+ const _wfexgovJsV2 = new Map();
383
+ let _wfexgovMaxActive = 8,
384
+ _wfexgovMaxPending = 20,
385
+ _wfexgovIdleMs = 30 * 24 * 60 * 60 * 1000,
386
+ _wfexgovStuckMs = 60 * 1000;
387
+ function _wfexgovPos(n, label) {
388
+ const v = Math.floor(Number(n));
389
+ if (!Number.isFinite(v) || v <= 0)
390
+ throw new Error(`${label} must be positive integer`);
391
+ return v;
392
+ }
393
+ function _wfexgovCheckP(from, to) {
394
+ const a = _wfexgovPTrans.get(from);
395
+ if (!a || !a.has(to))
396
+ throw new Error(`invalid wfexgov profile transition ${from} → ${to}`);
397
+ }
398
+ function _wfexgovCheckJ(from, to) {
399
+ const a = _wfexgovJTrans.get(from);
400
+ if (!a || !a.has(to))
401
+ throw new Error(`invalid wfexgov eval transition ${from} → ${to}`);
402
+ }
403
+ function _wfexgovCountActive(owner) {
404
+ let c = 0;
405
+ for (const p of _wfexgovPsV2.values())
406
+ if (p.owner === owner && p.status === WFEXGOV_PROFILE_MATURITY_V2.ACTIVE)
407
+ c++;
408
+ return c;
409
+ }
410
+ function _wfexgovCountPending(profileId) {
411
+ let c = 0;
412
+ for (const j of _wfexgovJsV2.values())
413
+ if (
414
+ j.profileId === profileId &&
415
+ (j.status === WFEXGOV_EVAL_LIFECYCLE_V2.QUEUED ||
416
+ j.status === WFEXGOV_EVAL_LIFECYCLE_V2.EVALUATING)
417
+ )
418
+ c++;
419
+ return c;
420
+ }
421
+ export function setMaxActiveWfexgovProfilesPerOwnerV2(n) {
422
+ _wfexgovMaxActive = _wfexgovPos(n, "maxActiveWfexgovProfilesPerOwner");
423
+ }
424
+ export function getMaxActiveWfexgovProfilesPerOwnerV2() {
425
+ return _wfexgovMaxActive;
426
+ }
427
+ export function setMaxPendingWfexgovEvalsPerProfileV2(n) {
428
+ _wfexgovMaxPending = _wfexgovPos(n, "maxPendingWfexgovEvalsPerProfile");
429
+ }
430
+ export function getMaxPendingWfexgovEvalsPerProfileV2() {
431
+ return _wfexgovMaxPending;
432
+ }
433
+ export function setWfexgovProfileIdleMsV2(n) {
434
+ _wfexgovIdleMs = _wfexgovPos(n, "wfexgovProfileIdleMs");
435
+ }
436
+ export function getWfexgovProfileIdleMsV2() {
437
+ return _wfexgovIdleMs;
438
+ }
439
+ export function setWfexgovEvalStuckMsV2(n) {
440
+ _wfexgovStuckMs = _wfexgovPos(n, "wfexgovEvalStuckMs");
441
+ }
442
+ export function getWfexgovEvalStuckMsV2() {
443
+ return _wfexgovStuckMs;
444
+ }
445
+ export function _resetStateWorkflowExprGovV2() {
446
+ _wfexgovPsV2.clear();
447
+ _wfexgovJsV2.clear();
448
+ _wfexgovMaxActive = 8;
449
+ _wfexgovMaxPending = 20;
450
+ _wfexgovIdleMs = 30 * 24 * 60 * 60 * 1000;
451
+ _wfexgovStuckMs = 60 * 1000;
452
+ }
453
+ export function registerWfexgovProfileV2({
454
+ id,
455
+ owner,
456
+ language,
457
+ metadata,
458
+ } = {}) {
459
+ if (!id || !owner) throw new Error("id and owner required");
460
+ if (_wfexgovPsV2.has(id))
461
+ throw new Error(`wfexgov profile ${id} already exists`);
462
+ const now = Date.now();
463
+ const p = {
464
+ id,
465
+ owner,
466
+ language: language || "cel",
467
+ status: WFEXGOV_PROFILE_MATURITY_V2.PENDING,
468
+ createdAt: now,
469
+ updatedAt: now,
470
+ lastTouchedAt: now,
471
+ activatedAt: null,
472
+ archivedAt: null,
473
+ metadata: { ...(metadata || {}) },
474
+ };
475
+ _wfexgovPsV2.set(id, p);
476
+ return { ...p, metadata: { ...p.metadata } };
477
+ }
478
+ export function activateWfexgovProfileV2(id) {
479
+ const p = _wfexgovPsV2.get(id);
480
+ if (!p) throw new Error(`wfexgov profile ${id} not found`);
481
+ const isInitial = p.status === WFEXGOV_PROFILE_MATURITY_V2.PENDING;
482
+ _wfexgovCheckP(p.status, WFEXGOV_PROFILE_MATURITY_V2.ACTIVE);
483
+ if (isInitial && _wfexgovCountActive(p.owner) >= _wfexgovMaxActive)
484
+ throw new Error(`max active wfexgov profiles for owner ${p.owner} reached`);
485
+ const now = Date.now();
486
+ p.status = WFEXGOV_PROFILE_MATURITY_V2.ACTIVE;
487
+ p.updatedAt = now;
488
+ p.lastTouchedAt = now;
489
+ if (!p.activatedAt) p.activatedAt = now;
490
+ return { ...p, metadata: { ...p.metadata } };
491
+ }
492
+ export function pauseWfexgovProfileV2(id) {
493
+ const p = _wfexgovPsV2.get(id);
494
+ if (!p) throw new Error(`wfexgov profile ${id} not found`);
495
+ _wfexgovCheckP(p.status, WFEXGOV_PROFILE_MATURITY_V2.PAUSED);
496
+ p.status = WFEXGOV_PROFILE_MATURITY_V2.PAUSED;
497
+ p.updatedAt = Date.now();
498
+ return { ...p, metadata: { ...p.metadata } };
499
+ }
500
+ export function archiveWfexgovProfileV2(id) {
501
+ const p = _wfexgovPsV2.get(id);
502
+ if (!p) throw new Error(`wfexgov profile ${id} not found`);
503
+ _wfexgovCheckP(p.status, WFEXGOV_PROFILE_MATURITY_V2.ARCHIVED);
504
+ const now = Date.now();
505
+ p.status = WFEXGOV_PROFILE_MATURITY_V2.ARCHIVED;
506
+ p.updatedAt = now;
507
+ if (!p.archivedAt) p.archivedAt = now;
508
+ return { ...p, metadata: { ...p.metadata } };
509
+ }
510
+ export function touchWfexgovProfileV2(id) {
511
+ const p = _wfexgovPsV2.get(id);
512
+ if (!p) throw new Error(`wfexgov profile ${id} not found`);
513
+ if (_wfexgovPTerminal.has(p.status))
514
+ throw new Error(`cannot touch terminal wfexgov profile ${id}`);
515
+ const now = Date.now();
516
+ p.lastTouchedAt = now;
517
+ p.updatedAt = now;
518
+ return { ...p, metadata: { ...p.metadata } };
519
+ }
520
+ export function getWfexgovProfileV2(id) {
521
+ const p = _wfexgovPsV2.get(id);
522
+ if (!p) return null;
523
+ return { ...p, metadata: { ...p.metadata } };
524
+ }
525
+ export function listWfexgovProfilesV2() {
526
+ return [..._wfexgovPsV2.values()].map((p) => ({
527
+ ...p,
528
+ metadata: { ...p.metadata },
529
+ }));
530
+ }
531
+ export function createWfexgovEvalV2({
532
+ id,
533
+ profileId,
534
+ expression,
535
+ metadata,
536
+ } = {}) {
537
+ if (!id || !profileId) throw new Error("id and profileId required");
538
+ if (_wfexgovJsV2.has(id))
539
+ throw new Error(`wfexgov eval ${id} already exists`);
540
+ if (!_wfexgovPsV2.has(profileId))
541
+ throw new Error(`wfexgov profile ${profileId} not found`);
542
+ if (_wfexgovCountPending(profileId) >= _wfexgovMaxPending)
543
+ throw new Error(
544
+ `max pending wfexgov evals for profile ${profileId} reached`,
545
+ );
546
+ const now = Date.now();
547
+ const j = {
548
+ id,
549
+ profileId,
550
+ expression: expression || "",
551
+ status: WFEXGOV_EVAL_LIFECYCLE_V2.QUEUED,
552
+ createdAt: now,
553
+ updatedAt: now,
554
+ startedAt: null,
555
+ settledAt: null,
556
+ metadata: { ...(metadata || {}) },
557
+ };
558
+ _wfexgovJsV2.set(id, j);
559
+ return { ...j, metadata: { ...j.metadata } };
560
+ }
561
+ export function evaluatingWfexgovEvalV2(id) {
562
+ const j = _wfexgovJsV2.get(id);
563
+ if (!j) throw new Error(`wfexgov eval ${id} not found`);
564
+ _wfexgovCheckJ(j.status, WFEXGOV_EVAL_LIFECYCLE_V2.EVALUATING);
565
+ const now = Date.now();
566
+ j.status = WFEXGOV_EVAL_LIFECYCLE_V2.EVALUATING;
567
+ j.updatedAt = now;
568
+ if (!j.startedAt) j.startedAt = now;
569
+ return { ...j, metadata: { ...j.metadata } };
570
+ }
571
+ export function completeEvalWfexgovV2(id) {
572
+ const j = _wfexgovJsV2.get(id);
573
+ if (!j) throw new Error(`wfexgov eval ${id} not found`);
574
+ _wfexgovCheckJ(j.status, WFEXGOV_EVAL_LIFECYCLE_V2.EVALUATED);
575
+ const now = Date.now();
576
+ j.status = WFEXGOV_EVAL_LIFECYCLE_V2.EVALUATED;
577
+ j.updatedAt = now;
578
+ if (!j.settledAt) j.settledAt = now;
579
+ return { ...j, metadata: { ...j.metadata } };
580
+ }
581
+ export function failWfexgovEvalV2(id, reason) {
582
+ const j = _wfexgovJsV2.get(id);
583
+ if (!j) throw new Error(`wfexgov eval ${id} not found`);
584
+ _wfexgovCheckJ(j.status, WFEXGOV_EVAL_LIFECYCLE_V2.FAILED);
585
+ const now = Date.now();
586
+ j.status = WFEXGOV_EVAL_LIFECYCLE_V2.FAILED;
587
+ j.updatedAt = now;
588
+ if (!j.settledAt) j.settledAt = now;
589
+ if (reason) j.metadata.failReason = String(reason);
590
+ return { ...j, metadata: { ...j.metadata } };
591
+ }
592
+ export function cancelWfexgovEvalV2(id, reason) {
593
+ const j = _wfexgovJsV2.get(id);
594
+ if (!j) throw new Error(`wfexgov eval ${id} not found`);
595
+ _wfexgovCheckJ(j.status, WFEXGOV_EVAL_LIFECYCLE_V2.CANCELLED);
596
+ const now = Date.now();
597
+ j.status = WFEXGOV_EVAL_LIFECYCLE_V2.CANCELLED;
598
+ j.updatedAt = now;
599
+ if (!j.settledAt) j.settledAt = now;
600
+ if (reason) j.metadata.cancelReason = String(reason);
601
+ return { ...j, metadata: { ...j.metadata } };
602
+ }
603
+ export function getWfexgovEvalV2(id) {
604
+ const j = _wfexgovJsV2.get(id);
605
+ if (!j) return null;
606
+ return { ...j, metadata: { ...j.metadata } };
607
+ }
608
+ export function listWfexgovEvalsV2() {
609
+ return [..._wfexgovJsV2.values()].map((j) => ({
610
+ ...j,
611
+ metadata: { ...j.metadata },
612
+ }));
613
+ }
614
+ export function autoPauseIdleWfexgovProfilesV2({ now } = {}) {
615
+ const t = now ?? Date.now();
616
+ const flipped = [];
617
+ for (const p of _wfexgovPsV2.values())
618
+ if (
619
+ p.status === WFEXGOV_PROFILE_MATURITY_V2.ACTIVE &&
620
+ t - p.lastTouchedAt >= _wfexgovIdleMs
621
+ ) {
622
+ p.status = WFEXGOV_PROFILE_MATURITY_V2.PAUSED;
623
+ p.updatedAt = t;
624
+ flipped.push(p.id);
625
+ }
626
+ return { flipped, count: flipped.length };
627
+ }
628
+ export function autoFailStuckWfexgovEvalsV2({ now } = {}) {
629
+ const t = now ?? Date.now();
630
+ const flipped = [];
631
+ for (const j of _wfexgovJsV2.values())
632
+ if (
633
+ j.status === WFEXGOV_EVAL_LIFECYCLE_V2.EVALUATING &&
634
+ j.startedAt != null &&
635
+ t - j.startedAt >= _wfexgovStuckMs
636
+ ) {
637
+ j.status = WFEXGOV_EVAL_LIFECYCLE_V2.FAILED;
638
+ j.updatedAt = t;
639
+ if (!j.settledAt) j.settledAt = t;
640
+ j.metadata.failReason = "auto-fail-stuck";
641
+ flipped.push(j.id);
642
+ }
643
+ return { flipped, count: flipped.length };
644
+ }
645
+ export function getWorkflowExprGovStatsV2() {
646
+ const profilesByStatus = {};
647
+ for (const v of Object.values(WFEXGOV_PROFILE_MATURITY_V2))
648
+ profilesByStatus[v] = 0;
649
+ for (const p of _wfexgovPsV2.values()) profilesByStatus[p.status]++;
650
+ const evalsByStatus = {};
651
+ for (const v of Object.values(WFEXGOV_EVAL_LIFECYCLE_V2))
652
+ evalsByStatus[v] = 0;
653
+ for (const j of _wfexgovJsV2.values()) evalsByStatus[j.status]++;
654
+ return {
655
+ totalWfexgovProfilesV2: _wfexgovPsV2.size,
656
+ totalWfexgovEvalsV2: _wfexgovJsV2.size,
657
+ maxActiveWfexgovProfilesPerOwner: _wfexgovMaxActive,
658
+ maxPendingWfexgovEvalsPerProfile: _wfexgovMaxPending,
659
+ wfexgovProfileIdleMs: _wfexgovIdleMs,
660
+ wfexgovEvalStuckMs: _wfexgovStuckMs,
661
+ profilesByStatus,
662
+ evalsByStatus,
663
+ };
664
+ }