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,338 @@ export function _resetStateAutomationEngineV2() {
1276
1276
  _automationIdleMsV2 = AUTOMATION_DEFAULT_AUTOMATION_IDLE_MS;
1277
1277
  _executionStuckMsV2 = AUTOMATION_DEFAULT_EXECUTION_STUCK_MS;
1278
1278
  }
1279
+
1280
+ // =====================================================================
1281
+ // automation-engine V2 governance overlay (iter22)
1282
+ // =====================================================================
1283
+ export const AUGOV_PROFILE_MATURITY_V2 = Object.freeze({
1284
+ PENDING: "pending",
1285
+ ACTIVE: "active",
1286
+ PAUSED: "paused",
1287
+ ARCHIVED: "archived",
1288
+ });
1289
+ export const AUGOV_FLOW_LIFECYCLE_V2 = Object.freeze({
1290
+ QUEUED: "queued",
1291
+ RUNNING: "running",
1292
+ COMPLETED: "completed",
1293
+ FAILED: "failed",
1294
+ CANCELLED: "cancelled",
1295
+ });
1296
+ const _augovPTrans = new Map([
1297
+ [
1298
+ AUGOV_PROFILE_MATURITY_V2.PENDING,
1299
+ new Set([
1300
+ AUGOV_PROFILE_MATURITY_V2.ACTIVE,
1301
+ AUGOV_PROFILE_MATURITY_V2.ARCHIVED,
1302
+ ]),
1303
+ ],
1304
+ [
1305
+ AUGOV_PROFILE_MATURITY_V2.ACTIVE,
1306
+ new Set([
1307
+ AUGOV_PROFILE_MATURITY_V2.PAUSED,
1308
+ AUGOV_PROFILE_MATURITY_V2.ARCHIVED,
1309
+ ]),
1310
+ ],
1311
+ [
1312
+ AUGOV_PROFILE_MATURITY_V2.PAUSED,
1313
+ new Set([
1314
+ AUGOV_PROFILE_MATURITY_V2.ACTIVE,
1315
+ AUGOV_PROFILE_MATURITY_V2.ARCHIVED,
1316
+ ]),
1317
+ ],
1318
+ [AUGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
1319
+ ]);
1320
+ const _augovPTerminal = new Set([AUGOV_PROFILE_MATURITY_V2.ARCHIVED]);
1321
+ const _augovJTrans = new Map([
1322
+ [
1323
+ AUGOV_FLOW_LIFECYCLE_V2.QUEUED,
1324
+ new Set([
1325
+ AUGOV_FLOW_LIFECYCLE_V2.RUNNING,
1326
+ AUGOV_FLOW_LIFECYCLE_V2.CANCELLED,
1327
+ ]),
1328
+ ],
1329
+ [
1330
+ AUGOV_FLOW_LIFECYCLE_V2.RUNNING,
1331
+ new Set([
1332
+ AUGOV_FLOW_LIFECYCLE_V2.COMPLETED,
1333
+ AUGOV_FLOW_LIFECYCLE_V2.FAILED,
1334
+ AUGOV_FLOW_LIFECYCLE_V2.CANCELLED,
1335
+ ]),
1336
+ ],
1337
+ [AUGOV_FLOW_LIFECYCLE_V2.COMPLETED, new Set()],
1338
+ [AUGOV_FLOW_LIFECYCLE_V2.FAILED, new Set()],
1339
+ [AUGOV_FLOW_LIFECYCLE_V2.CANCELLED, new Set()],
1340
+ ]);
1341
+ const _augovPsV2 = new Map();
1342
+ const _augovJsV2 = new Map();
1343
+ let _augovMaxActive = 10,
1344
+ _augovMaxPending = 25,
1345
+ _augovIdleMs = 30 * 24 * 60 * 60 * 1000,
1346
+ _augovStuckMs = 60 * 1000;
1347
+ function _augovPos(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 _augovCheckP(from, to) {
1354
+ const a = _augovPTrans.get(from);
1355
+ if (!a || !a.has(to))
1356
+ throw new Error(`invalid augov profile transition ${from} → ${to}`);
1357
+ }
1358
+ function _augovCheckJ(from, to) {
1359
+ const a = _augovJTrans.get(from);
1360
+ if (!a || !a.has(to))
1361
+ throw new Error(`invalid augov flow transition ${from} → ${to}`);
1362
+ }
1363
+ function _augovCountActive(owner) {
1364
+ let c = 0;
1365
+ for (const p of _augovPsV2.values())
1366
+ if (p.owner === owner && p.status === AUGOV_PROFILE_MATURITY_V2.ACTIVE) c++;
1367
+ return c;
1368
+ }
1369
+ function _augovCountPending(profileId) {
1370
+ let c = 0;
1371
+ for (const j of _augovJsV2.values())
1372
+ if (
1373
+ j.profileId === profileId &&
1374
+ (j.status === AUGOV_FLOW_LIFECYCLE_V2.QUEUED ||
1375
+ j.status === AUGOV_FLOW_LIFECYCLE_V2.RUNNING)
1376
+ )
1377
+ c++;
1378
+ return c;
1379
+ }
1380
+ export function setMaxActiveAugovProfilesPerOwnerV2(n) {
1381
+ _augovMaxActive = _augovPos(n, "maxActiveAugovProfilesPerOwner");
1382
+ }
1383
+ export function getMaxActiveAugovProfilesPerOwnerV2() {
1384
+ return _augovMaxActive;
1385
+ }
1386
+ export function setMaxPendingAugovFlowsPerProfileV2(n) {
1387
+ _augovMaxPending = _augovPos(n, "maxPendingAugovFlowsPerProfile");
1388
+ }
1389
+ export function getMaxPendingAugovFlowsPerProfileV2() {
1390
+ return _augovMaxPending;
1391
+ }
1392
+ export function setAugovProfileIdleMsV2(n) {
1393
+ _augovIdleMs = _augovPos(n, "augovProfileIdleMs");
1394
+ }
1395
+ export function getAugovProfileIdleMsV2() {
1396
+ return _augovIdleMs;
1397
+ }
1398
+ export function setAugovFlowStuckMsV2(n) {
1399
+ _augovStuckMs = _augovPos(n, "augovFlowStuckMs");
1400
+ }
1401
+ export function getAugovFlowStuckMsV2() {
1402
+ return _augovStuckMs;
1403
+ }
1404
+ export function _resetStateAutomationEngineGovV2() {
1405
+ _augovPsV2.clear();
1406
+ _augovJsV2.clear();
1407
+ _augovMaxActive = 10;
1408
+ _augovMaxPending = 25;
1409
+ _augovIdleMs = 30 * 24 * 60 * 60 * 1000;
1410
+ _augovStuckMs = 60 * 1000;
1411
+ }
1412
+ export function registerAugovProfileV2({
1413
+ id,
1414
+ owner,
1415
+ connector,
1416
+ metadata,
1417
+ } = {}) {
1418
+ if (!id || !owner) throw new Error("id and owner required");
1419
+ if (_augovPsV2.has(id)) throw new Error(`augov profile ${id} already exists`);
1420
+ const now = Date.now();
1421
+ const p = {
1422
+ id,
1423
+ owner,
1424
+ connector: connector || "webhook",
1425
+ status: AUGOV_PROFILE_MATURITY_V2.PENDING,
1426
+ createdAt: now,
1427
+ updatedAt: now,
1428
+ lastTouchedAt: now,
1429
+ activatedAt: null,
1430
+ archivedAt: null,
1431
+ metadata: { ...(metadata || {}) },
1432
+ };
1433
+ _augovPsV2.set(id, p);
1434
+ return { ...p, metadata: { ...p.metadata } };
1435
+ }
1436
+ export function activateAugovProfileV2(id) {
1437
+ const p = _augovPsV2.get(id);
1438
+ if (!p) throw new Error(`augov profile ${id} not found`);
1439
+ const isInitial = p.status === AUGOV_PROFILE_MATURITY_V2.PENDING;
1440
+ _augovCheckP(p.status, AUGOV_PROFILE_MATURITY_V2.ACTIVE);
1441
+ if (isInitial && _augovCountActive(p.owner) >= _augovMaxActive)
1442
+ throw new Error(`max active augov profiles for owner ${p.owner} reached`);
1443
+ const now = Date.now();
1444
+ p.status = AUGOV_PROFILE_MATURITY_V2.ACTIVE;
1445
+ p.updatedAt = now;
1446
+ p.lastTouchedAt = now;
1447
+ if (!p.activatedAt) p.activatedAt = now;
1448
+ return { ...p, metadata: { ...p.metadata } };
1449
+ }
1450
+ export function pauseAugovProfileV2(id) {
1451
+ const p = _augovPsV2.get(id);
1452
+ if (!p) throw new Error(`augov profile ${id} not found`);
1453
+ _augovCheckP(p.status, AUGOV_PROFILE_MATURITY_V2.PAUSED);
1454
+ p.status = AUGOV_PROFILE_MATURITY_V2.PAUSED;
1455
+ p.updatedAt = Date.now();
1456
+ return { ...p, metadata: { ...p.metadata } };
1457
+ }
1458
+ export function archiveAugovProfileV2(id) {
1459
+ const p = _augovPsV2.get(id);
1460
+ if (!p) throw new Error(`augov profile ${id} not found`);
1461
+ _augovCheckP(p.status, AUGOV_PROFILE_MATURITY_V2.ARCHIVED);
1462
+ const now = Date.now();
1463
+ p.status = AUGOV_PROFILE_MATURITY_V2.ARCHIVED;
1464
+ p.updatedAt = now;
1465
+ if (!p.archivedAt) p.archivedAt = now;
1466
+ return { ...p, metadata: { ...p.metadata } };
1467
+ }
1468
+ export function touchAugovProfileV2(id) {
1469
+ const p = _augovPsV2.get(id);
1470
+ if (!p) throw new Error(`augov profile ${id} not found`);
1471
+ if (_augovPTerminal.has(p.status))
1472
+ throw new Error(`cannot touch terminal augov profile ${id}`);
1473
+ const now = Date.now();
1474
+ p.lastTouchedAt = now;
1475
+ p.updatedAt = now;
1476
+ return { ...p, metadata: { ...p.metadata } };
1477
+ }
1478
+ export function getAugovProfileV2(id) {
1479
+ const p = _augovPsV2.get(id);
1480
+ if (!p) return null;
1481
+ return { ...p, metadata: { ...p.metadata } };
1482
+ }
1483
+ export function listAugovProfilesV2() {
1484
+ return [..._augovPsV2.values()].map((p) => ({
1485
+ ...p,
1486
+ metadata: { ...p.metadata },
1487
+ }));
1488
+ }
1489
+ export function createAugovFlowV2({ id, profileId, trigger, metadata } = {}) {
1490
+ if (!id || !profileId) throw new Error("id and profileId required");
1491
+ if (_augovJsV2.has(id)) throw new Error(`augov flow ${id} already exists`);
1492
+ if (!_augovPsV2.has(profileId))
1493
+ throw new Error(`augov profile ${profileId} not found`);
1494
+ if (_augovCountPending(profileId) >= _augovMaxPending)
1495
+ throw new Error(`max pending augov flows for profile ${profileId} reached`);
1496
+ const now = Date.now();
1497
+ const j = {
1498
+ id,
1499
+ profileId,
1500
+ trigger: trigger || "",
1501
+ status: AUGOV_FLOW_LIFECYCLE_V2.QUEUED,
1502
+ createdAt: now,
1503
+ updatedAt: now,
1504
+ startedAt: null,
1505
+ settledAt: null,
1506
+ metadata: { ...(metadata || {}) },
1507
+ };
1508
+ _augovJsV2.set(id, j);
1509
+ return { ...j, metadata: { ...j.metadata } };
1510
+ }
1511
+ export function runningAugovFlowV2(id) {
1512
+ const j = _augovJsV2.get(id);
1513
+ if (!j) throw new Error(`augov flow ${id} not found`);
1514
+ _augovCheckJ(j.status, AUGOV_FLOW_LIFECYCLE_V2.RUNNING);
1515
+ const now = Date.now();
1516
+ j.status = AUGOV_FLOW_LIFECYCLE_V2.RUNNING;
1517
+ j.updatedAt = now;
1518
+ if (!j.startedAt) j.startedAt = now;
1519
+ return { ...j, metadata: { ...j.metadata } };
1520
+ }
1521
+ export function completeFlowAugovV2(id) {
1522
+ const j = _augovJsV2.get(id);
1523
+ if (!j) throw new Error(`augov flow ${id} not found`);
1524
+ _augovCheckJ(j.status, AUGOV_FLOW_LIFECYCLE_V2.COMPLETED);
1525
+ const now = Date.now();
1526
+ j.status = AUGOV_FLOW_LIFECYCLE_V2.COMPLETED;
1527
+ j.updatedAt = now;
1528
+ if (!j.settledAt) j.settledAt = now;
1529
+ return { ...j, metadata: { ...j.metadata } };
1530
+ }
1531
+ export function failAugovFlowV2(id, reason) {
1532
+ const j = _augovJsV2.get(id);
1533
+ if (!j) throw new Error(`augov flow ${id} not found`);
1534
+ _augovCheckJ(j.status, AUGOV_FLOW_LIFECYCLE_V2.FAILED);
1535
+ const now = Date.now();
1536
+ j.status = AUGOV_FLOW_LIFECYCLE_V2.FAILED;
1537
+ j.updatedAt = now;
1538
+ if (!j.settledAt) j.settledAt = now;
1539
+ if (reason) j.metadata.failReason = String(reason);
1540
+ return { ...j, metadata: { ...j.metadata } };
1541
+ }
1542
+ export function cancelAugovFlowV2(id, reason) {
1543
+ const j = _augovJsV2.get(id);
1544
+ if (!j) throw new Error(`augov flow ${id} not found`);
1545
+ _augovCheckJ(j.status, AUGOV_FLOW_LIFECYCLE_V2.CANCELLED);
1546
+ const now = Date.now();
1547
+ j.status = AUGOV_FLOW_LIFECYCLE_V2.CANCELLED;
1548
+ j.updatedAt = now;
1549
+ if (!j.settledAt) j.settledAt = now;
1550
+ if (reason) j.metadata.cancelReason = String(reason);
1551
+ return { ...j, metadata: { ...j.metadata } };
1552
+ }
1553
+ export function getAugovFlowV2(id) {
1554
+ const j = _augovJsV2.get(id);
1555
+ if (!j) return null;
1556
+ return { ...j, metadata: { ...j.metadata } };
1557
+ }
1558
+ export function listAugovFlowsV2() {
1559
+ return [..._augovJsV2.values()].map((j) => ({
1560
+ ...j,
1561
+ metadata: { ...j.metadata },
1562
+ }));
1563
+ }
1564
+ export function autoPauseIdleAugovProfilesV2({ now } = {}) {
1565
+ const t = now ?? Date.now();
1566
+ const flipped = [];
1567
+ for (const p of _augovPsV2.values())
1568
+ if (
1569
+ p.status === AUGOV_PROFILE_MATURITY_V2.ACTIVE &&
1570
+ t - p.lastTouchedAt >= _augovIdleMs
1571
+ ) {
1572
+ p.status = AUGOV_PROFILE_MATURITY_V2.PAUSED;
1573
+ p.updatedAt = t;
1574
+ flipped.push(p.id);
1575
+ }
1576
+ return { flipped, count: flipped.length };
1577
+ }
1578
+ export function autoFailStuckAugovFlowsV2({ now } = {}) {
1579
+ const t = now ?? Date.now();
1580
+ const flipped = [];
1581
+ for (const j of _augovJsV2.values())
1582
+ if (
1583
+ j.status === AUGOV_FLOW_LIFECYCLE_V2.RUNNING &&
1584
+ j.startedAt != null &&
1585
+ t - j.startedAt >= _augovStuckMs
1586
+ ) {
1587
+ j.status = AUGOV_FLOW_LIFECYCLE_V2.FAILED;
1588
+ j.updatedAt = t;
1589
+ if (!j.settledAt) j.settledAt = t;
1590
+ j.metadata.failReason = "auto-fail-stuck";
1591
+ flipped.push(j.id);
1592
+ }
1593
+ return { flipped, count: flipped.length };
1594
+ }
1595
+ export function getAutomationEngineGovStatsV2() {
1596
+ const profilesByStatus = {};
1597
+ for (const v of Object.values(AUGOV_PROFILE_MATURITY_V2))
1598
+ profilesByStatus[v] = 0;
1599
+ for (const p of _augovPsV2.values()) profilesByStatus[p.status]++;
1600
+ const flowsByStatus = {};
1601
+ for (const v of Object.values(AUGOV_FLOW_LIFECYCLE_V2)) flowsByStatus[v] = 0;
1602
+ for (const j of _augovJsV2.values()) flowsByStatus[j.status]++;
1603
+ return {
1604
+ totalAugovProfilesV2: _augovPsV2.size,
1605
+ totalAugovFlowsV2: _augovJsV2.size,
1606
+ maxActiveAugovProfilesPerOwner: _augovMaxActive,
1607
+ maxPendingAugovFlowsPerProfile: _augovMaxPending,
1608
+ augovProfileIdleMs: _augovIdleMs,
1609
+ augovFlowStuckMs: _augovStuckMs,
1610
+ profilesByStatus,
1611
+ flowsByStatus,
1612
+ };
1613
+ }
@@ -833,3 +833,335 @@ export function getAutonomousAgentGovStatsV2() {
833
833
  runsByStatus,
834
834
  };
835
835
  }
836
+
837
+ // === Iter28 V2 governance overlay: Autagov ===
838
+ export const AUTAGOV_PROFILE_MATURITY_V2 = Object.freeze({
839
+ PENDING: "pending",
840
+ ACTIVE: "active",
841
+ PAUSED: "paused",
842
+ ARCHIVED: "archived",
843
+ });
844
+ export const AUTAGOV_RUN_LIFECYCLE_V2 = Object.freeze({
845
+ QUEUED: "queued",
846
+ RUNNING: "running",
847
+ FINISHED: "finished",
848
+ FAILED: "failed",
849
+ CANCELLED: "cancelled",
850
+ });
851
+ const _autagovPTrans = new Map([
852
+ [
853
+ AUTAGOV_PROFILE_MATURITY_V2.PENDING,
854
+ new Set([
855
+ AUTAGOV_PROFILE_MATURITY_V2.ACTIVE,
856
+ AUTAGOV_PROFILE_MATURITY_V2.ARCHIVED,
857
+ ]),
858
+ ],
859
+ [
860
+ AUTAGOV_PROFILE_MATURITY_V2.ACTIVE,
861
+ new Set([
862
+ AUTAGOV_PROFILE_MATURITY_V2.PAUSED,
863
+ AUTAGOV_PROFILE_MATURITY_V2.ARCHIVED,
864
+ ]),
865
+ ],
866
+ [
867
+ AUTAGOV_PROFILE_MATURITY_V2.PAUSED,
868
+ new Set([
869
+ AUTAGOV_PROFILE_MATURITY_V2.ACTIVE,
870
+ AUTAGOV_PROFILE_MATURITY_V2.ARCHIVED,
871
+ ]),
872
+ ],
873
+ [AUTAGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
874
+ ]);
875
+ const _autagovPTerminal = new Set([AUTAGOV_PROFILE_MATURITY_V2.ARCHIVED]);
876
+ const _autagovJTrans = new Map([
877
+ [
878
+ AUTAGOV_RUN_LIFECYCLE_V2.QUEUED,
879
+ new Set([
880
+ AUTAGOV_RUN_LIFECYCLE_V2.RUNNING,
881
+ AUTAGOV_RUN_LIFECYCLE_V2.CANCELLED,
882
+ ]),
883
+ ],
884
+ [
885
+ AUTAGOV_RUN_LIFECYCLE_V2.RUNNING,
886
+ new Set([
887
+ AUTAGOV_RUN_LIFECYCLE_V2.FINISHED,
888
+ AUTAGOV_RUN_LIFECYCLE_V2.FAILED,
889
+ AUTAGOV_RUN_LIFECYCLE_V2.CANCELLED,
890
+ ]),
891
+ ],
892
+ [AUTAGOV_RUN_LIFECYCLE_V2.FINISHED, new Set()],
893
+ [AUTAGOV_RUN_LIFECYCLE_V2.FAILED, new Set()],
894
+ [AUTAGOV_RUN_LIFECYCLE_V2.CANCELLED, new Set()],
895
+ ]);
896
+ const _autagovPsV2 = new Map();
897
+ const _autagovJsV2 = new Map();
898
+ let _autagovMaxActive = 6,
899
+ _autagovMaxPending = 15,
900
+ _autagovIdleMs = 2592000000,
901
+ _autagovStuckMs = 60 * 1000;
902
+ function _autagovPos(n, label) {
903
+ const v = Math.floor(Number(n));
904
+ if (!Number.isFinite(v) || v <= 0)
905
+ throw new Error(`${label} must be positive integer`);
906
+ return v;
907
+ }
908
+ function _autagovCheckP(from, to) {
909
+ const a = _autagovPTrans.get(from);
910
+ if (!a || !a.has(to))
911
+ throw new Error(`invalid autagov profile transition ${from} → ${to}`);
912
+ }
913
+ function _autagovCheckJ(from, to) {
914
+ const a = _autagovJTrans.get(from);
915
+ if (!a || !a.has(to))
916
+ throw new Error(`invalid autagov run transition ${from} → ${to}`);
917
+ }
918
+ function _autagovCountActive(owner) {
919
+ let c = 0;
920
+ for (const p of _autagovPsV2.values())
921
+ if (p.owner === owner && p.status === AUTAGOV_PROFILE_MATURITY_V2.ACTIVE)
922
+ c++;
923
+ return c;
924
+ }
925
+ function _autagovCountPending(profileId) {
926
+ let c = 0;
927
+ for (const j of _autagovJsV2.values())
928
+ if (
929
+ j.profileId === profileId &&
930
+ (j.status === AUTAGOV_RUN_LIFECYCLE_V2.QUEUED ||
931
+ j.status === AUTAGOV_RUN_LIFECYCLE_V2.RUNNING)
932
+ )
933
+ c++;
934
+ return c;
935
+ }
936
+ export function setMaxActiveAutagProfilesPerOwnerV2(n) {
937
+ _autagovMaxActive = _autagovPos(n, "maxActiveAutagProfilesPerOwner");
938
+ }
939
+ export function getMaxActiveAutagProfilesPerOwnerV2() {
940
+ return _autagovMaxActive;
941
+ }
942
+ export function setMaxPendingAutagRunsPerProfileV2(n) {
943
+ _autagovMaxPending = _autagovPos(n, "maxPendingAutagRunsPerProfile");
944
+ }
945
+ export function getMaxPendingAutagRunsPerProfileV2() {
946
+ return _autagovMaxPending;
947
+ }
948
+ export function setAutagProfileIdleMsV2(n) {
949
+ _autagovIdleMs = _autagovPos(n, "autagovProfileIdleMs");
950
+ }
951
+ export function getAutagProfileIdleMsV2() {
952
+ return _autagovIdleMs;
953
+ }
954
+ export function setAutagRunStuckMsV2(n) {
955
+ _autagovStuckMs = _autagovPos(n, "autagovRunStuckMs");
956
+ }
957
+ export function getAutagRunStuckMsV2() {
958
+ return _autagovStuckMs;
959
+ }
960
+ export function _resetStateAutagovV2() {
961
+ _autagovPsV2.clear();
962
+ _autagovJsV2.clear();
963
+ _autagovMaxActive = 6;
964
+ _autagovMaxPending = 15;
965
+ _autagovIdleMs = 2592000000;
966
+ _autagovStuckMs = 60 * 1000;
967
+ }
968
+ export function registerAutagProfileV2({ id, owner, tier, metadata } = {}) {
969
+ if (!id || !owner) throw new Error("id and owner required");
970
+ if (_autagovPsV2.has(id))
971
+ throw new Error(`autagov profile ${id} already exists`);
972
+ const now = Date.now();
973
+ const p = {
974
+ id,
975
+ owner,
976
+ tier: tier || "assist",
977
+ status: AUTAGOV_PROFILE_MATURITY_V2.PENDING,
978
+ createdAt: now,
979
+ updatedAt: now,
980
+ lastTouchedAt: now,
981
+ activatedAt: null,
982
+ archivedAt: null,
983
+ metadata: { ...(metadata || {}) },
984
+ };
985
+ _autagovPsV2.set(id, p);
986
+ return { ...p, metadata: { ...p.metadata } };
987
+ }
988
+ export function activateAutagProfileV2(id) {
989
+ const p = _autagovPsV2.get(id);
990
+ if (!p) throw new Error(`autagov profile ${id} not found`);
991
+ const isInitial = p.status === AUTAGOV_PROFILE_MATURITY_V2.PENDING;
992
+ _autagovCheckP(p.status, AUTAGOV_PROFILE_MATURITY_V2.ACTIVE);
993
+ if (isInitial && _autagovCountActive(p.owner) >= _autagovMaxActive)
994
+ throw new Error(`max active autagov profiles for owner ${p.owner} reached`);
995
+ const now = Date.now();
996
+ p.status = AUTAGOV_PROFILE_MATURITY_V2.ACTIVE;
997
+ p.updatedAt = now;
998
+ p.lastTouchedAt = now;
999
+ if (!p.activatedAt) p.activatedAt = now;
1000
+ return { ...p, metadata: { ...p.metadata } };
1001
+ }
1002
+ export function pausedAutagProfileV2(id) {
1003
+ const p = _autagovPsV2.get(id);
1004
+ if (!p) throw new Error(`autagov profile ${id} not found`);
1005
+ _autagovCheckP(p.status, AUTAGOV_PROFILE_MATURITY_V2.PAUSED);
1006
+ p.status = AUTAGOV_PROFILE_MATURITY_V2.PAUSED;
1007
+ p.updatedAt = Date.now();
1008
+ return { ...p, metadata: { ...p.metadata } };
1009
+ }
1010
+ export function archiveAutagProfileV2(id) {
1011
+ const p = _autagovPsV2.get(id);
1012
+ if (!p) throw new Error(`autagov profile ${id} not found`);
1013
+ _autagovCheckP(p.status, AUTAGOV_PROFILE_MATURITY_V2.ARCHIVED);
1014
+ const now = Date.now();
1015
+ p.status = AUTAGOV_PROFILE_MATURITY_V2.ARCHIVED;
1016
+ p.updatedAt = now;
1017
+ if (!p.archivedAt) p.archivedAt = now;
1018
+ return { ...p, metadata: { ...p.metadata } };
1019
+ }
1020
+ export function touchAutagProfileV2(id) {
1021
+ const p = _autagovPsV2.get(id);
1022
+ if (!p) throw new Error(`autagov profile ${id} not found`);
1023
+ if (_autagovPTerminal.has(p.status))
1024
+ throw new Error(`cannot touch terminal autagov profile ${id}`);
1025
+ const now = Date.now();
1026
+ p.lastTouchedAt = now;
1027
+ p.updatedAt = now;
1028
+ return { ...p, metadata: { ...p.metadata } };
1029
+ }
1030
+ export function getAutagProfileV2(id) {
1031
+ const p = _autagovPsV2.get(id);
1032
+ if (!p) return null;
1033
+ return { ...p, metadata: { ...p.metadata } };
1034
+ }
1035
+ export function listAutagProfilesV2() {
1036
+ return [..._autagovPsV2.values()].map((p) => ({
1037
+ ...p,
1038
+ metadata: { ...p.metadata },
1039
+ }));
1040
+ }
1041
+ export function createAutagRunV2({ id, profileId, runId, metadata } = {}) {
1042
+ if (!id || !profileId) throw new Error("id and profileId required");
1043
+ if (_autagovJsV2.has(id)) throw new Error(`autagov run ${id} already exists`);
1044
+ if (!_autagovPsV2.has(profileId))
1045
+ throw new Error(`autagov profile ${profileId} not found`);
1046
+ if (_autagovCountPending(profileId) >= _autagovMaxPending)
1047
+ throw new Error(
1048
+ `max pending autagov runs for profile ${profileId} reached`,
1049
+ );
1050
+ const now = Date.now();
1051
+ const j = {
1052
+ id,
1053
+ profileId,
1054
+ runId: runId || "",
1055
+ status: AUTAGOV_RUN_LIFECYCLE_V2.QUEUED,
1056
+ createdAt: now,
1057
+ updatedAt: now,
1058
+ startedAt: null,
1059
+ settledAt: null,
1060
+ metadata: { ...(metadata || {}) },
1061
+ };
1062
+ _autagovJsV2.set(id, j);
1063
+ return { ...j, metadata: { ...j.metadata } };
1064
+ }
1065
+ export function runningAutagRunV2(id) {
1066
+ const j = _autagovJsV2.get(id);
1067
+ if (!j) throw new Error(`autagov run ${id} not found`);
1068
+ _autagovCheckJ(j.status, AUTAGOV_RUN_LIFECYCLE_V2.RUNNING);
1069
+ const now = Date.now();
1070
+ j.status = AUTAGOV_RUN_LIFECYCLE_V2.RUNNING;
1071
+ j.updatedAt = now;
1072
+ if (!j.startedAt) j.startedAt = now;
1073
+ return { ...j, metadata: { ...j.metadata } };
1074
+ }
1075
+ export function completeRunAutagV2(id) {
1076
+ const j = _autagovJsV2.get(id);
1077
+ if (!j) throw new Error(`autagov run ${id} not found`);
1078
+ _autagovCheckJ(j.status, AUTAGOV_RUN_LIFECYCLE_V2.FINISHED);
1079
+ const now = Date.now();
1080
+ j.status = AUTAGOV_RUN_LIFECYCLE_V2.FINISHED;
1081
+ j.updatedAt = now;
1082
+ if (!j.settledAt) j.settledAt = now;
1083
+ return { ...j, metadata: { ...j.metadata } };
1084
+ }
1085
+ export function failAutagRunV2(id, reason) {
1086
+ const j = _autagovJsV2.get(id);
1087
+ if (!j) throw new Error(`autagov run ${id} not found`);
1088
+ _autagovCheckJ(j.status, AUTAGOV_RUN_LIFECYCLE_V2.FAILED);
1089
+ const now = Date.now();
1090
+ j.status = AUTAGOV_RUN_LIFECYCLE_V2.FAILED;
1091
+ j.updatedAt = now;
1092
+ if (!j.settledAt) j.settledAt = now;
1093
+ if (reason) j.metadata.failReason = String(reason);
1094
+ return { ...j, metadata: { ...j.metadata } };
1095
+ }
1096
+ export function cancelAutagRunV2(id, reason) {
1097
+ const j = _autagovJsV2.get(id);
1098
+ if (!j) throw new Error(`autagov run ${id} not found`);
1099
+ _autagovCheckJ(j.status, AUTAGOV_RUN_LIFECYCLE_V2.CANCELLED);
1100
+ const now = Date.now();
1101
+ j.status = AUTAGOV_RUN_LIFECYCLE_V2.CANCELLED;
1102
+ j.updatedAt = now;
1103
+ if (!j.settledAt) j.settledAt = now;
1104
+ if (reason) j.metadata.cancelReason = String(reason);
1105
+ return { ...j, metadata: { ...j.metadata } };
1106
+ }
1107
+ export function getAutagRunV2(id) {
1108
+ const j = _autagovJsV2.get(id);
1109
+ if (!j) return null;
1110
+ return { ...j, metadata: { ...j.metadata } };
1111
+ }
1112
+ export function listAutagRunsV2() {
1113
+ return [..._autagovJsV2.values()].map((j) => ({
1114
+ ...j,
1115
+ metadata: { ...j.metadata },
1116
+ }));
1117
+ }
1118
+ export function autoPausedIdleAutagProfilesV2({ now } = {}) {
1119
+ const t = now ?? Date.now();
1120
+ const flipped = [];
1121
+ for (const p of _autagovPsV2.values())
1122
+ if (
1123
+ p.status === AUTAGOV_PROFILE_MATURITY_V2.ACTIVE &&
1124
+ t - p.lastTouchedAt >= _autagovIdleMs
1125
+ ) {
1126
+ p.status = AUTAGOV_PROFILE_MATURITY_V2.PAUSED;
1127
+ p.updatedAt = t;
1128
+ flipped.push(p.id);
1129
+ }
1130
+ return { flipped, count: flipped.length };
1131
+ }
1132
+ export function autoFailStuckAutagRunsV2({ now } = {}) {
1133
+ const t = now ?? Date.now();
1134
+ const flipped = [];
1135
+ for (const j of _autagovJsV2.values())
1136
+ if (
1137
+ j.status === AUTAGOV_RUN_LIFECYCLE_V2.RUNNING &&
1138
+ j.startedAt != null &&
1139
+ t - j.startedAt >= _autagovStuckMs
1140
+ ) {
1141
+ j.status = AUTAGOV_RUN_LIFECYCLE_V2.FAILED;
1142
+ j.updatedAt = t;
1143
+ if (!j.settledAt) j.settledAt = t;
1144
+ j.metadata.failReason = "auto-fail-stuck";
1145
+ flipped.push(j.id);
1146
+ }
1147
+ return { flipped, count: flipped.length };
1148
+ }
1149
+ export function getAutagovStatsV2() {
1150
+ const profilesByStatus = {};
1151
+ for (const v of Object.values(AUTAGOV_PROFILE_MATURITY_V2))
1152
+ profilesByStatus[v] = 0;
1153
+ for (const p of _autagovPsV2.values()) profilesByStatus[p.status]++;
1154
+ const runsByStatus = {};
1155
+ for (const v of Object.values(AUTAGOV_RUN_LIFECYCLE_V2)) runsByStatus[v] = 0;
1156
+ for (const j of _autagovJsV2.values()) runsByStatus[j.status]++;
1157
+ return {
1158
+ totalAutagProfilesV2: _autagovPsV2.size,
1159
+ totalAutagRunsV2: _autagovJsV2.size,
1160
+ maxActiveAutagProfilesPerOwner: _autagovMaxActive,
1161
+ maxPendingAutagRunsPerProfile: _autagovMaxPending,
1162
+ autagovProfileIdleMs: _autagovIdleMs,
1163
+ autagovRunStuckMs: _autagovStuckMs,
1164
+ profilesByStatus,
1165
+ runsByStatus,
1166
+ };
1167
+ }