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
@@ -1271,3 +1271,335 @@ export function getPipelineOrchestratorGovStatsV2() {
1271
1271
  runsByStatus,
1272
1272
  };
1273
1273
  }
1274
+
1275
+ // === Iter28 V2 governance overlay: Pipogov ===
1276
+ export const PIPOGOV_PROFILE_MATURITY_V2 = Object.freeze({
1277
+ PENDING: "pending",
1278
+ ACTIVE: "active",
1279
+ PAUSED: "paused",
1280
+ ARCHIVED: "archived",
1281
+ });
1282
+ export const PIPOGOV_RUN_LIFECYCLE_V2 = Object.freeze({
1283
+ QUEUED: "queued",
1284
+ RUNNING: "running",
1285
+ FINISHED: "finished",
1286
+ FAILED: "failed",
1287
+ CANCELLED: "cancelled",
1288
+ });
1289
+ const _pipogovPTrans = new Map([
1290
+ [
1291
+ PIPOGOV_PROFILE_MATURITY_V2.PENDING,
1292
+ new Set([
1293
+ PIPOGOV_PROFILE_MATURITY_V2.ACTIVE,
1294
+ PIPOGOV_PROFILE_MATURITY_V2.ARCHIVED,
1295
+ ]),
1296
+ ],
1297
+ [
1298
+ PIPOGOV_PROFILE_MATURITY_V2.ACTIVE,
1299
+ new Set([
1300
+ PIPOGOV_PROFILE_MATURITY_V2.PAUSED,
1301
+ PIPOGOV_PROFILE_MATURITY_V2.ARCHIVED,
1302
+ ]),
1303
+ ],
1304
+ [
1305
+ PIPOGOV_PROFILE_MATURITY_V2.PAUSED,
1306
+ new Set([
1307
+ PIPOGOV_PROFILE_MATURITY_V2.ACTIVE,
1308
+ PIPOGOV_PROFILE_MATURITY_V2.ARCHIVED,
1309
+ ]),
1310
+ ],
1311
+ [PIPOGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
1312
+ ]);
1313
+ const _pipogovPTerminal = new Set([PIPOGOV_PROFILE_MATURITY_V2.ARCHIVED]);
1314
+ const _pipogovJTrans = new Map([
1315
+ [
1316
+ PIPOGOV_RUN_LIFECYCLE_V2.QUEUED,
1317
+ new Set([
1318
+ PIPOGOV_RUN_LIFECYCLE_V2.RUNNING,
1319
+ PIPOGOV_RUN_LIFECYCLE_V2.CANCELLED,
1320
+ ]),
1321
+ ],
1322
+ [
1323
+ PIPOGOV_RUN_LIFECYCLE_V2.RUNNING,
1324
+ new Set([
1325
+ PIPOGOV_RUN_LIFECYCLE_V2.FINISHED,
1326
+ PIPOGOV_RUN_LIFECYCLE_V2.FAILED,
1327
+ PIPOGOV_RUN_LIFECYCLE_V2.CANCELLED,
1328
+ ]),
1329
+ ],
1330
+ [PIPOGOV_RUN_LIFECYCLE_V2.FINISHED, new Set()],
1331
+ [PIPOGOV_RUN_LIFECYCLE_V2.FAILED, new Set()],
1332
+ [PIPOGOV_RUN_LIFECYCLE_V2.CANCELLED, new Set()],
1333
+ ]);
1334
+ const _pipogovPsV2 = new Map();
1335
+ const _pipogovJsV2 = new Map();
1336
+ let _pipogovMaxActive = 8,
1337
+ _pipogovMaxPending = 20,
1338
+ _pipogovIdleMs = 2592000000,
1339
+ _pipogovStuckMs = 60 * 1000;
1340
+ function _pipogovPos(n, label) {
1341
+ const v = Math.floor(Number(n));
1342
+ if (!Number.isFinite(v) || v <= 0)
1343
+ throw new Error(`${label} must be positive integer`);
1344
+ return v;
1345
+ }
1346
+ function _pipogovCheckP(from, to) {
1347
+ const a = _pipogovPTrans.get(from);
1348
+ if (!a || !a.has(to))
1349
+ throw new Error(`invalid pipogov profile transition ${from} → ${to}`);
1350
+ }
1351
+ function _pipogovCheckJ(from, to) {
1352
+ const a = _pipogovJTrans.get(from);
1353
+ if (!a || !a.has(to))
1354
+ throw new Error(`invalid pipogov run transition ${from} → ${to}`);
1355
+ }
1356
+ function _pipogovCountActive(owner) {
1357
+ let c = 0;
1358
+ for (const p of _pipogovPsV2.values())
1359
+ if (p.owner === owner && p.status === PIPOGOV_PROFILE_MATURITY_V2.ACTIVE)
1360
+ c++;
1361
+ return c;
1362
+ }
1363
+ function _pipogovCountPending(profileId) {
1364
+ let c = 0;
1365
+ for (const j of _pipogovJsV2.values())
1366
+ if (
1367
+ j.profileId === profileId &&
1368
+ (j.status === PIPOGOV_RUN_LIFECYCLE_V2.QUEUED ||
1369
+ j.status === PIPOGOV_RUN_LIFECYCLE_V2.RUNNING)
1370
+ )
1371
+ c++;
1372
+ return c;
1373
+ }
1374
+ export function setMaxActivePipoProfilesPerOwnerV2(n) {
1375
+ _pipogovMaxActive = _pipogovPos(n, "maxActivePipoProfilesPerOwner");
1376
+ }
1377
+ export function getMaxActivePipoProfilesPerOwnerV2() {
1378
+ return _pipogovMaxActive;
1379
+ }
1380
+ export function setMaxPendingPipoRunsPerProfileV2(n) {
1381
+ _pipogovMaxPending = _pipogovPos(n, "maxPendingPipoRunsPerProfile");
1382
+ }
1383
+ export function getMaxPendingPipoRunsPerProfileV2() {
1384
+ return _pipogovMaxPending;
1385
+ }
1386
+ export function setPipoProfileIdleMsV2(n) {
1387
+ _pipogovIdleMs = _pipogovPos(n, "pipogovProfileIdleMs");
1388
+ }
1389
+ export function getPipoProfileIdleMsV2() {
1390
+ return _pipogovIdleMs;
1391
+ }
1392
+ export function setPipoRunStuckMsV2(n) {
1393
+ _pipogovStuckMs = _pipogovPos(n, "pipogovRunStuckMs");
1394
+ }
1395
+ export function getPipoRunStuckMsV2() {
1396
+ return _pipogovStuckMs;
1397
+ }
1398
+ export function _resetStatePipogovV2() {
1399
+ _pipogovPsV2.clear();
1400
+ _pipogovJsV2.clear();
1401
+ _pipogovMaxActive = 8;
1402
+ _pipogovMaxPending = 20;
1403
+ _pipogovIdleMs = 2592000000;
1404
+ _pipogovStuckMs = 60 * 1000;
1405
+ }
1406
+ export function registerPipoProfileV2({ id, owner, pipeline, metadata } = {}) {
1407
+ if (!id || !owner) throw new Error("id and owner required");
1408
+ if (_pipogovPsV2.has(id))
1409
+ throw new Error(`pipogov profile ${id} already exists`);
1410
+ const now = Date.now();
1411
+ const p = {
1412
+ id,
1413
+ owner,
1414
+ pipeline: pipeline || "default",
1415
+ status: PIPOGOV_PROFILE_MATURITY_V2.PENDING,
1416
+ createdAt: now,
1417
+ updatedAt: now,
1418
+ lastTouchedAt: now,
1419
+ activatedAt: null,
1420
+ archivedAt: null,
1421
+ metadata: { ...(metadata || {}) },
1422
+ };
1423
+ _pipogovPsV2.set(id, p);
1424
+ return { ...p, metadata: { ...p.metadata } };
1425
+ }
1426
+ export function activatePipoProfileV2(id) {
1427
+ const p = _pipogovPsV2.get(id);
1428
+ if (!p) throw new Error(`pipogov profile ${id} not found`);
1429
+ const isInitial = p.status === PIPOGOV_PROFILE_MATURITY_V2.PENDING;
1430
+ _pipogovCheckP(p.status, PIPOGOV_PROFILE_MATURITY_V2.ACTIVE);
1431
+ if (isInitial && _pipogovCountActive(p.owner) >= _pipogovMaxActive)
1432
+ throw new Error(`max active pipogov profiles for owner ${p.owner} reached`);
1433
+ const now = Date.now();
1434
+ p.status = PIPOGOV_PROFILE_MATURITY_V2.ACTIVE;
1435
+ p.updatedAt = now;
1436
+ p.lastTouchedAt = now;
1437
+ if (!p.activatedAt) p.activatedAt = now;
1438
+ return { ...p, metadata: { ...p.metadata } };
1439
+ }
1440
+ export function pausedPipoProfileV2(id) {
1441
+ const p = _pipogovPsV2.get(id);
1442
+ if (!p) throw new Error(`pipogov profile ${id} not found`);
1443
+ _pipogovCheckP(p.status, PIPOGOV_PROFILE_MATURITY_V2.PAUSED);
1444
+ p.status = PIPOGOV_PROFILE_MATURITY_V2.PAUSED;
1445
+ p.updatedAt = Date.now();
1446
+ return { ...p, metadata: { ...p.metadata } };
1447
+ }
1448
+ export function archivePipoProfileV2(id) {
1449
+ const p = _pipogovPsV2.get(id);
1450
+ if (!p) throw new Error(`pipogov profile ${id} not found`);
1451
+ _pipogovCheckP(p.status, PIPOGOV_PROFILE_MATURITY_V2.ARCHIVED);
1452
+ const now = Date.now();
1453
+ p.status = PIPOGOV_PROFILE_MATURITY_V2.ARCHIVED;
1454
+ p.updatedAt = now;
1455
+ if (!p.archivedAt) p.archivedAt = now;
1456
+ return { ...p, metadata: { ...p.metadata } };
1457
+ }
1458
+ export function touchPipoProfileV2(id) {
1459
+ const p = _pipogovPsV2.get(id);
1460
+ if (!p) throw new Error(`pipogov profile ${id} not found`);
1461
+ if (_pipogovPTerminal.has(p.status))
1462
+ throw new Error(`cannot touch terminal pipogov profile ${id}`);
1463
+ const now = Date.now();
1464
+ p.lastTouchedAt = now;
1465
+ p.updatedAt = now;
1466
+ return { ...p, metadata: { ...p.metadata } };
1467
+ }
1468
+ export function getPipoProfileV2(id) {
1469
+ const p = _pipogovPsV2.get(id);
1470
+ if (!p) return null;
1471
+ return { ...p, metadata: { ...p.metadata } };
1472
+ }
1473
+ export function listPipoProfilesV2() {
1474
+ return [..._pipogovPsV2.values()].map((p) => ({
1475
+ ...p,
1476
+ metadata: { ...p.metadata },
1477
+ }));
1478
+ }
1479
+ export function createPipoRunV2({ id, profileId, runId, metadata } = {}) {
1480
+ if (!id || !profileId) throw new Error("id and profileId required");
1481
+ if (_pipogovJsV2.has(id)) throw new Error(`pipogov run ${id} already exists`);
1482
+ if (!_pipogovPsV2.has(profileId))
1483
+ throw new Error(`pipogov profile ${profileId} not found`);
1484
+ if (_pipogovCountPending(profileId) >= _pipogovMaxPending)
1485
+ throw new Error(
1486
+ `max pending pipogov runs for profile ${profileId} reached`,
1487
+ );
1488
+ const now = Date.now();
1489
+ const j = {
1490
+ id,
1491
+ profileId,
1492
+ runId: runId || "",
1493
+ status: PIPOGOV_RUN_LIFECYCLE_V2.QUEUED,
1494
+ createdAt: now,
1495
+ updatedAt: now,
1496
+ startedAt: null,
1497
+ settledAt: null,
1498
+ metadata: { ...(metadata || {}) },
1499
+ };
1500
+ _pipogovJsV2.set(id, j);
1501
+ return { ...j, metadata: { ...j.metadata } };
1502
+ }
1503
+ export function runningPipoRunV2(id) {
1504
+ const j = _pipogovJsV2.get(id);
1505
+ if (!j) throw new Error(`pipogov run ${id} not found`);
1506
+ _pipogovCheckJ(j.status, PIPOGOV_RUN_LIFECYCLE_V2.RUNNING);
1507
+ const now = Date.now();
1508
+ j.status = PIPOGOV_RUN_LIFECYCLE_V2.RUNNING;
1509
+ j.updatedAt = now;
1510
+ if (!j.startedAt) j.startedAt = now;
1511
+ return { ...j, metadata: { ...j.metadata } };
1512
+ }
1513
+ export function completeRunPipoV2(id) {
1514
+ const j = _pipogovJsV2.get(id);
1515
+ if (!j) throw new Error(`pipogov run ${id} not found`);
1516
+ _pipogovCheckJ(j.status, PIPOGOV_RUN_LIFECYCLE_V2.FINISHED);
1517
+ const now = Date.now();
1518
+ j.status = PIPOGOV_RUN_LIFECYCLE_V2.FINISHED;
1519
+ j.updatedAt = now;
1520
+ if (!j.settledAt) j.settledAt = now;
1521
+ return { ...j, metadata: { ...j.metadata } };
1522
+ }
1523
+ export function failPipoRunV2(id, reason) {
1524
+ const j = _pipogovJsV2.get(id);
1525
+ if (!j) throw new Error(`pipogov run ${id} not found`);
1526
+ _pipogovCheckJ(j.status, PIPOGOV_RUN_LIFECYCLE_V2.FAILED);
1527
+ const now = Date.now();
1528
+ j.status = PIPOGOV_RUN_LIFECYCLE_V2.FAILED;
1529
+ j.updatedAt = now;
1530
+ if (!j.settledAt) j.settledAt = now;
1531
+ if (reason) j.metadata.failReason = String(reason);
1532
+ return { ...j, metadata: { ...j.metadata } };
1533
+ }
1534
+ export function cancelPipoRunV2(id, reason) {
1535
+ const j = _pipogovJsV2.get(id);
1536
+ if (!j) throw new Error(`pipogov run ${id} not found`);
1537
+ _pipogovCheckJ(j.status, PIPOGOV_RUN_LIFECYCLE_V2.CANCELLED);
1538
+ const now = Date.now();
1539
+ j.status = PIPOGOV_RUN_LIFECYCLE_V2.CANCELLED;
1540
+ j.updatedAt = now;
1541
+ if (!j.settledAt) j.settledAt = now;
1542
+ if (reason) j.metadata.cancelReason = String(reason);
1543
+ return { ...j, metadata: { ...j.metadata } };
1544
+ }
1545
+ export function getPipoRunV2(id) {
1546
+ const j = _pipogovJsV2.get(id);
1547
+ if (!j) return null;
1548
+ return { ...j, metadata: { ...j.metadata } };
1549
+ }
1550
+ export function listPipoRunsV2() {
1551
+ return [..._pipogovJsV2.values()].map((j) => ({
1552
+ ...j,
1553
+ metadata: { ...j.metadata },
1554
+ }));
1555
+ }
1556
+ export function autoPausedIdlePipoProfilesV2({ now } = {}) {
1557
+ const t = now ?? Date.now();
1558
+ const flipped = [];
1559
+ for (const p of _pipogovPsV2.values())
1560
+ if (
1561
+ p.status === PIPOGOV_PROFILE_MATURITY_V2.ACTIVE &&
1562
+ t - p.lastTouchedAt >= _pipogovIdleMs
1563
+ ) {
1564
+ p.status = PIPOGOV_PROFILE_MATURITY_V2.PAUSED;
1565
+ p.updatedAt = t;
1566
+ flipped.push(p.id);
1567
+ }
1568
+ return { flipped, count: flipped.length };
1569
+ }
1570
+ export function autoFailStuckPipoRunsV2({ now } = {}) {
1571
+ const t = now ?? Date.now();
1572
+ const flipped = [];
1573
+ for (const j of _pipogovJsV2.values())
1574
+ if (
1575
+ j.status === PIPOGOV_RUN_LIFECYCLE_V2.RUNNING &&
1576
+ j.startedAt != null &&
1577
+ t - j.startedAt >= _pipogovStuckMs
1578
+ ) {
1579
+ j.status = PIPOGOV_RUN_LIFECYCLE_V2.FAILED;
1580
+ j.updatedAt = t;
1581
+ if (!j.settledAt) j.settledAt = t;
1582
+ j.metadata.failReason = "auto-fail-stuck";
1583
+ flipped.push(j.id);
1584
+ }
1585
+ return { flipped, count: flipped.length };
1586
+ }
1587
+ export function getPipogovStatsV2() {
1588
+ const profilesByStatus = {};
1589
+ for (const v of Object.values(PIPOGOV_PROFILE_MATURITY_V2))
1590
+ profilesByStatus[v] = 0;
1591
+ for (const p of _pipogovPsV2.values()) profilesByStatus[p.status]++;
1592
+ const runsByStatus = {};
1593
+ for (const v of Object.values(PIPOGOV_RUN_LIFECYCLE_V2)) runsByStatus[v] = 0;
1594
+ for (const j of _pipogovJsV2.values()) runsByStatus[j.status]++;
1595
+ return {
1596
+ totalPipoProfilesV2: _pipogovPsV2.size,
1597
+ totalPipoRunsV2: _pipogovJsV2.size,
1598
+ maxActivePipoProfilesPerOwner: _pipogovMaxActive,
1599
+ maxPendingPipoRunsPerProfile: _pipogovMaxPending,
1600
+ pipogovProfileIdleMs: _pipogovIdleMs,
1601
+ pipogovRunStuckMs: _pipogovStuckMs,
1602
+ profilesByStatus,
1603
+ runsByStatus,
1604
+ };
1605
+ }
@@ -872,3 +872,339 @@ export function getPlanModeGovStatsV2() {
872
872
  stepsByStatus,
873
873
  };
874
874
  }
875
+
876
+ // === Iter28 V2 governance overlay: Pmodegov ===
877
+ export const PMODEGOV_PROFILE_MATURITY_V2 = Object.freeze({
878
+ PENDING: "pending",
879
+ ACTIVE: "active",
880
+ PAUSED: "paused",
881
+ ARCHIVED: "archived",
882
+ });
883
+ export const PMODEGOV_PLAN_LIFECYCLE_V2 = Object.freeze({
884
+ QUEUED: "queued",
885
+ PLANNING: "planning",
886
+ FINALIZED: "finalized",
887
+ FAILED: "failed",
888
+ CANCELLED: "cancelled",
889
+ });
890
+ const _pmodegovPTrans = new Map([
891
+ [
892
+ PMODEGOV_PROFILE_MATURITY_V2.PENDING,
893
+ new Set([
894
+ PMODEGOV_PROFILE_MATURITY_V2.ACTIVE,
895
+ PMODEGOV_PROFILE_MATURITY_V2.ARCHIVED,
896
+ ]),
897
+ ],
898
+ [
899
+ PMODEGOV_PROFILE_MATURITY_V2.ACTIVE,
900
+ new Set([
901
+ PMODEGOV_PROFILE_MATURITY_V2.PAUSED,
902
+ PMODEGOV_PROFILE_MATURITY_V2.ARCHIVED,
903
+ ]),
904
+ ],
905
+ [
906
+ PMODEGOV_PROFILE_MATURITY_V2.PAUSED,
907
+ new Set([
908
+ PMODEGOV_PROFILE_MATURITY_V2.ACTIVE,
909
+ PMODEGOV_PROFILE_MATURITY_V2.ARCHIVED,
910
+ ]),
911
+ ],
912
+ [PMODEGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
913
+ ]);
914
+ const _pmodegovPTerminal = new Set([PMODEGOV_PROFILE_MATURITY_V2.ARCHIVED]);
915
+ const _pmodegovJTrans = new Map([
916
+ [
917
+ PMODEGOV_PLAN_LIFECYCLE_V2.QUEUED,
918
+ new Set([
919
+ PMODEGOV_PLAN_LIFECYCLE_V2.PLANNING,
920
+ PMODEGOV_PLAN_LIFECYCLE_V2.CANCELLED,
921
+ ]),
922
+ ],
923
+ [
924
+ PMODEGOV_PLAN_LIFECYCLE_V2.PLANNING,
925
+ new Set([
926
+ PMODEGOV_PLAN_LIFECYCLE_V2.FINALIZED,
927
+ PMODEGOV_PLAN_LIFECYCLE_V2.FAILED,
928
+ PMODEGOV_PLAN_LIFECYCLE_V2.CANCELLED,
929
+ ]),
930
+ ],
931
+ [PMODEGOV_PLAN_LIFECYCLE_V2.FINALIZED, new Set()],
932
+ [PMODEGOV_PLAN_LIFECYCLE_V2.FAILED, new Set()],
933
+ [PMODEGOV_PLAN_LIFECYCLE_V2.CANCELLED, new Set()],
934
+ ]);
935
+ const _pmodegovPsV2 = new Map();
936
+ const _pmodegovJsV2 = new Map();
937
+ let _pmodegovMaxActive = 6,
938
+ _pmodegovMaxPending = 15,
939
+ _pmodegovIdleMs = 2592000000,
940
+ _pmodegovStuckMs = 60 * 1000;
941
+ function _pmodegovPos(n, label) {
942
+ const v = Math.floor(Number(n));
943
+ if (!Number.isFinite(v) || v <= 0)
944
+ throw new Error(`${label} must be positive integer`);
945
+ return v;
946
+ }
947
+ function _pmodegovCheckP(from, to) {
948
+ const a = _pmodegovPTrans.get(from);
949
+ if (!a || !a.has(to))
950
+ throw new Error(`invalid pmodegov profile transition ${from} → ${to}`);
951
+ }
952
+ function _pmodegovCheckJ(from, to) {
953
+ const a = _pmodegovJTrans.get(from);
954
+ if (!a || !a.has(to))
955
+ throw new Error(`invalid pmodegov plan transition ${from} → ${to}`);
956
+ }
957
+ function _pmodegovCountActive(owner) {
958
+ let c = 0;
959
+ for (const p of _pmodegovPsV2.values())
960
+ if (p.owner === owner && p.status === PMODEGOV_PROFILE_MATURITY_V2.ACTIVE)
961
+ c++;
962
+ return c;
963
+ }
964
+ function _pmodegovCountPending(profileId) {
965
+ let c = 0;
966
+ for (const j of _pmodegovJsV2.values())
967
+ if (
968
+ j.profileId === profileId &&
969
+ (j.status === PMODEGOV_PLAN_LIFECYCLE_V2.QUEUED ||
970
+ j.status === PMODEGOV_PLAN_LIFECYCLE_V2.PLANNING)
971
+ )
972
+ c++;
973
+ return c;
974
+ }
975
+ export function setMaxActivePmodeProfilesPerOwnerV2(n) {
976
+ _pmodegovMaxActive = _pmodegovPos(n, "maxActivePmodeProfilesPerOwner");
977
+ }
978
+ export function getMaxActivePmodeProfilesPerOwnerV2() {
979
+ return _pmodegovMaxActive;
980
+ }
981
+ export function setMaxPendingPmodePlansPerProfileV2(n) {
982
+ _pmodegovMaxPending = _pmodegovPos(n, "maxPendingPmodePlansPerProfile");
983
+ }
984
+ export function getMaxPendingPmodePlansPerProfileV2() {
985
+ return _pmodegovMaxPending;
986
+ }
987
+ export function setPmodeProfileIdleMsV2(n) {
988
+ _pmodegovIdleMs = _pmodegovPos(n, "pmodegovProfileIdleMs");
989
+ }
990
+ export function getPmodeProfileIdleMsV2() {
991
+ return _pmodegovIdleMs;
992
+ }
993
+ export function setPmodePlanStuckMsV2(n) {
994
+ _pmodegovStuckMs = _pmodegovPos(n, "pmodegovPlanStuckMs");
995
+ }
996
+ export function getPmodePlanStuckMsV2() {
997
+ return _pmodegovStuckMs;
998
+ }
999
+ export function _resetStatePmodegovV2() {
1000
+ _pmodegovPsV2.clear();
1001
+ _pmodegovJsV2.clear();
1002
+ _pmodegovMaxActive = 6;
1003
+ _pmodegovMaxPending = 15;
1004
+ _pmodegovIdleMs = 2592000000;
1005
+ _pmodegovStuckMs = 60 * 1000;
1006
+ }
1007
+ export function registerPmodeProfileV2({ id, owner, template, metadata } = {}) {
1008
+ if (!id || !owner) throw new Error("id and owner required");
1009
+ if (_pmodegovPsV2.has(id))
1010
+ throw new Error(`pmodegov profile ${id} already exists`);
1011
+ const now = Date.now();
1012
+ const p = {
1013
+ id,
1014
+ owner,
1015
+ template: template || "default",
1016
+ status: PMODEGOV_PROFILE_MATURITY_V2.PENDING,
1017
+ createdAt: now,
1018
+ updatedAt: now,
1019
+ lastTouchedAt: now,
1020
+ activatedAt: null,
1021
+ archivedAt: null,
1022
+ metadata: { ...(metadata || {}) },
1023
+ };
1024
+ _pmodegovPsV2.set(id, p);
1025
+ return { ...p, metadata: { ...p.metadata } };
1026
+ }
1027
+ export function activatePmodeProfileV2(id) {
1028
+ const p = _pmodegovPsV2.get(id);
1029
+ if (!p) throw new Error(`pmodegov profile ${id} not found`);
1030
+ const isInitial = p.status === PMODEGOV_PROFILE_MATURITY_V2.PENDING;
1031
+ _pmodegovCheckP(p.status, PMODEGOV_PROFILE_MATURITY_V2.ACTIVE);
1032
+ if (isInitial && _pmodegovCountActive(p.owner) >= _pmodegovMaxActive)
1033
+ throw new Error(
1034
+ `max active pmodegov profiles for owner ${p.owner} reached`,
1035
+ );
1036
+ const now = Date.now();
1037
+ p.status = PMODEGOV_PROFILE_MATURITY_V2.ACTIVE;
1038
+ p.updatedAt = now;
1039
+ p.lastTouchedAt = now;
1040
+ if (!p.activatedAt) p.activatedAt = now;
1041
+ return { ...p, metadata: { ...p.metadata } };
1042
+ }
1043
+ export function pausedPmodeProfileV2(id) {
1044
+ const p = _pmodegovPsV2.get(id);
1045
+ if (!p) throw new Error(`pmodegov profile ${id} not found`);
1046
+ _pmodegovCheckP(p.status, PMODEGOV_PROFILE_MATURITY_V2.PAUSED);
1047
+ p.status = PMODEGOV_PROFILE_MATURITY_V2.PAUSED;
1048
+ p.updatedAt = Date.now();
1049
+ return { ...p, metadata: { ...p.metadata } };
1050
+ }
1051
+ export function archivePmodeProfileV2(id) {
1052
+ const p = _pmodegovPsV2.get(id);
1053
+ if (!p) throw new Error(`pmodegov profile ${id} not found`);
1054
+ _pmodegovCheckP(p.status, PMODEGOV_PROFILE_MATURITY_V2.ARCHIVED);
1055
+ const now = Date.now();
1056
+ p.status = PMODEGOV_PROFILE_MATURITY_V2.ARCHIVED;
1057
+ p.updatedAt = now;
1058
+ if (!p.archivedAt) p.archivedAt = now;
1059
+ return { ...p, metadata: { ...p.metadata } };
1060
+ }
1061
+ export function touchPmodeProfileV2(id) {
1062
+ const p = _pmodegovPsV2.get(id);
1063
+ if (!p) throw new Error(`pmodegov profile ${id} not found`);
1064
+ if (_pmodegovPTerminal.has(p.status))
1065
+ throw new Error(`cannot touch terminal pmodegov profile ${id}`);
1066
+ const now = Date.now();
1067
+ p.lastTouchedAt = now;
1068
+ p.updatedAt = now;
1069
+ return { ...p, metadata: { ...p.metadata } };
1070
+ }
1071
+ export function getPmodeProfileV2(id) {
1072
+ const p = _pmodegovPsV2.get(id);
1073
+ if (!p) return null;
1074
+ return { ...p, metadata: { ...p.metadata } };
1075
+ }
1076
+ export function listPmodeProfilesV2() {
1077
+ return [..._pmodegovPsV2.values()].map((p) => ({
1078
+ ...p,
1079
+ metadata: { ...p.metadata },
1080
+ }));
1081
+ }
1082
+ export function createPmodePlanV2({ id, profileId, planId, metadata } = {}) {
1083
+ if (!id || !profileId) throw new Error("id and profileId required");
1084
+ if (_pmodegovJsV2.has(id))
1085
+ throw new Error(`pmodegov plan ${id} already exists`);
1086
+ if (!_pmodegovPsV2.has(profileId))
1087
+ throw new Error(`pmodegov profile ${profileId} not found`);
1088
+ if (_pmodegovCountPending(profileId) >= _pmodegovMaxPending)
1089
+ throw new Error(
1090
+ `max pending pmodegov plans for profile ${profileId} reached`,
1091
+ );
1092
+ const now = Date.now();
1093
+ const j = {
1094
+ id,
1095
+ profileId,
1096
+ planId: planId || "",
1097
+ status: PMODEGOV_PLAN_LIFECYCLE_V2.QUEUED,
1098
+ createdAt: now,
1099
+ updatedAt: now,
1100
+ startedAt: null,
1101
+ settledAt: null,
1102
+ metadata: { ...(metadata || {}) },
1103
+ };
1104
+ _pmodegovJsV2.set(id, j);
1105
+ return { ...j, metadata: { ...j.metadata } };
1106
+ }
1107
+ export function planningPmodePlanV2(id) {
1108
+ const j = _pmodegovJsV2.get(id);
1109
+ if (!j) throw new Error(`pmodegov plan ${id} not found`);
1110
+ _pmodegovCheckJ(j.status, PMODEGOV_PLAN_LIFECYCLE_V2.PLANNING);
1111
+ const now = Date.now();
1112
+ j.status = PMODEGOV_PLAN_LIFECYCLE_V2.PLANNING;
1113
+ j.updatedAt = now;
1114
+ if (!j.startedAt) j.startedAt = now;
1115
+ return { ...j, metadata: { ...j.metadata } };
1116
+ }
1117
+ export function completePlanPmodeV2(id) {
1118
+ const j = _pmodegovJsV2.get(id);
1119
+ if (!j) throw new Error(`pmodegov plan ${id} not found`);
1120
+ _pmodegovCheckJ(j.status, PMODEGOV_PLAN_LIFECYCLE_V2.FINALIZED);
1121
+ const now = Date.now();
1122
+ j.status = PMODEGOV_PLAN_LIFECYCLE_V2.FINALIZED;
1123
+ j.updatedAt = now;
1124
+ if (!j.settledAt) j.settledAt = now;
1125
+ return { ...j, metadata: { ...j.metadata } };
1126
+ }
1127
+ export function failPmodePlanV2(id, reason) {
1128
+ const j = _pmodegovJsV2.get(id);
1129
+ if (!j) throw new Error(`pmodegov plan ${id} not found`);
1130
+ _pmodegovCheckJ(j.status, PMODEGOV_PLAN_LIFECYCLE_V2.FAILED);
1131
+ const now = Date.now();
1132
+ j.status = PMODEGOV_PLAN_LIFECYCLE_V2.FAILED;
1133
+ j.updatedAt = now;
1134
+ if (!j.settledAt) j.settledAt = now;
1135
+ if (reason) j.metadata.failReason = String(reason);
1136
+ return { ...j, metadata: { ...j.metadata } };
1137
+ }
1138
+ export function cancelPmodePlanV2(id, reason) {
1139
+ const j = _pmodegovJsV2.get(id);
1140
+ if (!j) throw new Error(`pmodegov plan ${id} not found`);
1141
+ _pmodegovCheckJ(j.status, PMODEGOV_PLAN_LIFECYCLE_V2.CANCELLED);
1142
+ const now = Date.now();
1143
+ j.status = PMODEGOV_PLAN_LIFECYCLE_V2.CANCELLED;
1144
+ j.updatedAt = now;
1145
+ if (!j.settledAt) j.settledAt = now;
1146
+ if (reason) j.metadata.cancelReason = String(reason);
1147
+ return { ...j, metadata: { ...j.metadata } };
1148
+ }
1149
+ export function getPmodePlanV2(id) {
1150
+ const j = _pmodegovJsV2.get(id);
1151
+ if (!j) return null;
1152
+ return { ...j, metadata: { ...j.metadata } };
1153
+ }
1154
+ export function listPmodePlansV2() {
1155
+ return [..._pmodegovJsV2.values()].map((j) => ({
1156
+ ...j,
1157
+ metadata: { ...j.metadata },
1158
+ }));
1159
+ }
1160
+ export function autoPausedIdlePmodeProfilesV2({ now } = {}) {
1161
+ const t = now ?? Date.now();
1162
+ const flipped = [];
1163
+ for (const p of _pmodegovPsV2.values())
1164
+ if (
1165
+ p.status === PMODEGOV_PROFILE_MATURITY_V2.ACTIVE &&
1166
+ t - p.lastTouchedAt >= _pmodegovIdleMs
1167
+ ) {
1168
+ p.status = PMODEGOV_PROFILE_MATURITY_V2.PAUSED;
1169
+ p.updatedAt = t;
1170
+ flipped.push(p.id);
1171
+ }
1172
+ return { flipped, count: flipped.length };
1173
+ }
1174
+ export function autoFailStuckPmodePlansV2({ now } = {}) {
1175
+ const t = now ?? Date.now();
1176
+ const flipped = [];
1177
+ for (const j of _pmodegovJsV2.values())
1178
+ if (
1179
+ j.status === PMODEGOV_PLAN_LIFECYCLE_V2.PLANNING &&
1180
+ j.startedAt != null &&
1181
+ t - j.startedAt >= _pmodegovStuckMs
1182
+ ) {
1183
+ j.status = PMODEGOV_PLAN_LIFECYCLE_V2.FAILED;
1184
+ j.updatedAt = t;
1185
+ if (!j.settledAt) j.settledAt = t;
1186
+ j.metadata.failReason = "auto-fail-stuck";
1187
+ flipped.push(j.id);
1188
+ }
1189
+ return { flipped, count: flipped.length };
1190
+ }
1191
+ export function getPmodegovStatsV2() {
1192
+ const profilesByStatus = {};
1193
+ for (const v of Object.values(PMODEGOV_PROFILE_MATURITY_V2))
1194
+ profilesByStatus[v] = 0;
1195
+ for (const p of _pmodegovPsV2.values()) profilesByStatus[p.status]++;
1196
+ const plansByStatus = {};
1197
+ for (const v of Object.values(PMODEGOV_PLAN_LIFECYCLE_V2))
1198
+ plansByStatus[v] = 0;
1199
+ for (const j of _pmodegovJsV2.values()) plansByStatus[j.status]++;
1200
+ return {
1201
+ totalPmodeProfilesV2: _pmodegovPsV2.size,
1202
+ totalPmodePlansV2: _pmodegovJsV2.size,
1203
+ maxActivePmodeProfilesPerOwner: _pmodegovMaxActive,
1204
+ maxPendingPmodePlansPerProfile: _pmodegovMaxPending,
1205
+ pmodegovProfileIdleMs: _pmodegovIdleMs,
1206
+ pmodegovPlanStuckMs: _pmodegovStuckMs,
1207
+ profilesByStatus,
1208
+ plansByStatus,
1209
+ };
1210
+ }