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
@@ -1083,3 +1083,349 @@ export function _resetStateV2() {
1083
1083
  _proposerIdleMsV2 = GOV_DEFAULT_PROPOSER_IDLE_MS;
1084
1084
  _pendingDelegationMsV2 = GOV_DEFAULT_PENDING_DELEGATION_MS;
1085
1085
  }
1086
+
1087
+ // =====================================================================
1088
+ // community-governance V2 governance overlay (iter19)
1089
+ // =====================================================================
1090
+ export const COMMGOV_PROFILE_MATURITY_V2 = Object.freeze({
1091
+ PENDING: "pending",
1092
+ ACTIVE: "active",
1093
+ PAUSED: "paused",
1094
+ ARCHIVED: "archived",
1095
+ });
1096
+ export const COMMGOV_MOTION_LIFECYCLE_V2 = Object.freeze({
1097
+ QUEUED: "queued",
1098
+ VOTING: "voting",
1099
+ VOTED: "voted",
1100
+ FAILED: "failed",
1101
+ CANCELLED: "cancelled",
1102
+ });
1103
+ const _commgovPTrans = new Map([
1104
+ [
1105
+ COMMGOV_PROFILE_MATURITY_V2.PENDING,
1106
+ new Set([
1107
+ COMMGOV_PROFILE_MATURITY_V2.ACTIVE,
1108
+ COMMGOV_PROFILE_MATURITY_V2.ARCHIVED,
1109
+ ]),
1110
+ ],
1111
+ [
1112
+ COMMGOV_PROFILE_MATURITY_V2.ACTIVE,
1113
+ new Set([
1114
+ COMMGOV_PROFILE_MATURITY_V2.PAUSED,
1115
+ COMMGOV_PROFILE_MATURITY_V2.ARCHIVED,
1116
+ ]),
1117
+ ],
1118
+ [
1119
+ COMMGOV_PROFILE_MATURITY_V2.PAUSED,
1120
+ new Set([
1121
+ COMMGOV_PROFILE_MATURITY_V2.ACTIVE,
1122
+ COMMGOV_PROFILE_MATURITY_V2.ARCHIVED,
1123
+ ]),
1124
+ ],
1125
+ [COMMGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
1126
+ ]);
1127
+ const _commgovPTerminal = new Set([COMMGOV_PROFILE_MATURITY_V2.ARCHIVED]);
1128
+ const _commgovJTrans = new Map([
1129
+ [
1130
+ COMMGOV_MOTION_LIFECYCLE_V2.QUEUED,
1131
+ new Set([
1132
+ COMMGOV_MOTION_LIFECYCLE_V2.VOTING,
1133
+ COMMGOV_MOTION_LIFECYCLE_V2.CANCELLED,
1134
+ ]),
1135
+ ],
1136
+ [
1137
+ COMMGOV_MOTION_LIFECYCLE_V2.VOTING,
1138
+ new Set([
1139
+ COMMGOV_MOTION_LIFECYCLE_V2.VOTED,
1140
+ COMMGOV_MOTION_LIFECYCLE_V2.FAILED,
1141
+ COMMGOV_MOTION_LIFECYCLE_V2.CANCELLED,
1142
+ ]),
1143
+ ],
1144
+ [COMMGOV_MOTION_LIFECYCLE_V2.VOTED, new Set()],
1145
+ [COMMGOV_MOTION_LIFECYCLE_V2.FAILED, new Set()],
1146
+ [COMMGOV_MOTION_LIFECYCLE_V2.CANCELLED, new Set()],
1147
+ ]);
1148
+ const _commgovPsV2 = new Map();
1149
+ const _commgovJsV2 = new Map();
1150
+ let _commgovMaxActive = 8,
1151
+ _commgovMaxPending = 25,
1152
+ _commgovIdleMs = 30 * 24 * 60 * 60 * 1000,
1153
+ _commgovStuckMs = 60 * 1000;
1154
+ function _commgovPos(n, label) {
1155
+ const v = Math.floor(Number(n));
1156
+ if (!Number.isFinite(v) || v <= 0)
1157
+ throw new Error(`${label} must be positive integer`);
1158
+ return v;
1159
+ }
1160
+ function _commgovCheckP(from, to) {
1161
+ const a = _commgovPTrans.get(from);
1162
+ if (!a || !a.has(to))
1163
+ throw new Error(`invalid commgov profile transition ${from} → ${to}`);
1164
+ }
1165
+ function _commgovCheckJ(from, to) {
1166
+ const a = _commgovJTrans.get(from);
1167
+ if (!a || !a.has(to))
1168
+ throw new Error(`invalid commgov motion transition ${from} → ${to}`);
1169
+ }
1170
+ function _commgovCountActive(owner) {
1171
+ let c = 0;
1172
+ for (const p of _commgovPsV2.values())
1173
+ if (p.owner === owner && p.status === COMMGOV_PROFILE_MATURITY_V2.ACTIVE)
1174
+ c++;
1175
+ return c;
1176
+ }
1177
+ function _commgovCountPending(profileId) {
1178
+ let c = 0;
1179
+ for (const j of _commgovJsV2.values())
1180
+ if (
1181
+ j.profileId === profileId &&
1182
+ (j.status === COMMGOV_MOTION_LIFECYCLE_V2.QUEUED ||
1183
+ j.status === COMMGOV_MOTION_LIFECYCLE_V2.VOTING)
1184
+ )
1185
+ c++;
1186
+ return c;
1187
+ }
1188
+ export function setMaxActiveCommgovProfilesPerOwnerV2(n) {
1189
+ _commgovMaxActive = _commgovPos(n, "maxActiveCommgovProfilesPerOwner");
1190
+ }
1191
+ export function getMaxActiveCommgovProfilesPerOwnerV2() {
1192
+ return _commgovMaxActive;
1193
+ }
1194
+ export function setMaxPendingCommgovMotionsPerProfileV2(n) {
1195
+ _commgovMaxPending = _commgovPos(n, "maxPendingCommgovMotionsPerProfile");
1196
+ }
1197
+ export function getMaxPendingCommgovMotionsPerProfileV2() {
1198
+ return _commgovMaxPending;
1199
+ }
1200
+ export function setCommgovProfileIdleMsV2(n) {
1201
+ _commgovIdleMs = _commgovPos(n, "commgovProfileIdleMs");
1202
+ }
1203
+ export function getCommgovProfileIdleMsV2() {
1204
+ return _commgovIdleMs;
1205
+ }
1206
+ export function setCommgovMotionStuckMsV2(n) {
1207
+ _commgovStuckMs = _commgovPos(n, "commgovMotionStuckMs");
1208
+ }
1209
+ export function getCommgovMotionStuckMsV2() {
1210
+ return _commgovStuckMs;
1211
+ }
1212
+ export function _resetStateCommunityGovernanceGovV2() {
1213
+ _commgovPsV2.clear();
1214
+ _commgovJsV2.clear();
1215
+ _commgovMaxActive = 8;
1216
+ _commgovMaxPending = 25;
1217
+ _commgovIdleMs = 30 * 24 * 60 * 60 * 1000;
1218
+ _commgovStuckMs = 60 * 1000;
1219
+ }
1220
+ export function registerCommgovProfileV2({
1221
+ id,
1222
+ owner,
1223
+ chamber,
1224
+ metadata,
1225
+ } = {}) {
1226
+ if (!id || !owner) throw new Error("id and owner required");
1227
+ if (_commgovPsV2.has(id))
1228
+ throw new Error(`commgov profile ${id} already exists`);
1229
+ const now = Date.now();
1230
+ const p = {
1231
+ id,
1232
+ owner,
1233
+ chamber: chamber || "general",
1234
+ status: COMMGOV_PROFILE_MATURITY_V2.PENDING,
1235
+ createdAt: now,
1236
+ updatedAt: now,
1237
+ lastTouchedAt: now,
1238
+ activatedAt: null,
1239
+ archivedAt: null,
1240
+ metadata: { ...(metadata || {}) },
1241
+ };
1242
+ _commgovPsV2.set(id, p);
1243
+ return { ...p, metadata: { ...p.metadata } };
1244
+ }
1245
+ export function activateCommgovProfileV2(id) {
1246
+ const p = _commgovPsV2.get(id);
1247
+ if (!p) throw new Error(`commgov profile ${id} not found`);
1248
+ const isInitial = p.status === COMMGOV_PROFILE_MATURITY_V2.PENDING;
1249
+ _commgovCheckP(p.status, COMMGOV_PROFILE_MATURITY_V2.ACTIVE);
1250
+ if (isInitial && _commgovCountActive(p.owner) >= _commgovMaxActive)
1251
+ throw new Error(`max active commgov profiles for owner ${p.owner} reached`);
1252
+ const now = Date.now();
1253
+ p.status = COMMGOV_PROFILE_MATURITY_V2.ACTIVE;
1254
+ p.updatedAt = now;
1255
+ p.lastTouchedAt = now;
1256
+ if (!p.activatedAt) p.activatedAt = now;
1257
+ return { ...p, metadata: { ...p.metadata } };
1258
+ }
1259
+ export function pauseCommgovProfileV2(id) {
1260
+ const p = _commgovPsV2.get(id);
1261
+ if (!p) throw new Error(`commgov profile ${id} not found`);
1262
+ _commgovCheckP(p.status, COMMGOV_PROFILE_MATURITY_V2.PAUSED);
1263
+ p.status = COMMGOV_PROFILE_MATURITY_V2.PAUSED;
1264
+ p.updatedAt = Date.now();
1265
+ return { ...p, metadata: { ...p.metadata } };
1266
+ }
1267
+ export function archiveCommgovProfileV2(id) {
1268
+ const p = _commgovPsV2.get(id);
1269
+ if (!p) throw new Error(`commgov profile ${id} not found`);
1270
+ _commgovCheckP(p.status, COMMGOV_PROFILE_MATURITY_V2.ARCHIVED);
1271
+ const now = Date.now();
1272
+ p.status = COMMGOV_PROFILE_MATURITY_V2.ARCHIVED;
1273
+ p.updatedAt = now;
1274
+ if (!p.archivedAt) p.archivedAt = now;
1275
+ return { ...p, metadata: { ...p.metadata } };
1276
+ }
1277
+ export function touchCommgovProfileV2(id) {
1278
+ const p = _commgovPsV2.get(id);
1279
+ if (!p) throw new Error(`commgov profile ${id} not found`);
1280
+ if (_commgovPTerminal.has(p.status))
1281
+ throw new Error(`cannot touch terminal commgov profile ${id}`);
1282
+ const now = Date.now();
1283
+ p.lastTouchedAt = now;
1284
+ p.updatedAt = now;
1285
+ return { ...p, metadata: { ...p.metadata } };
1286
+ }
1287
+ export function getCommgovProfileV2(id) {
1288
+ const p = _commgovPsV2.get(id);
1289
+ if (!p) return null;
1290
+ return { ...p, metadata: { ...p.metadata } };
1291
+ }
1292
+ export function listCommgovProfilesV2() {
1293
+ return [..._commgovPsV2.values()].map((p) => ({
1294
+ ...p,
1295
+ metadata: { ...p.metadata },
1296
+ }));
1297
+ }
1298
+ export function createCommgovMotionV2({
1299
+ id,
1300
+ profileId,
1301
+ subject,
1302
+ metadata,
1303
+ } = {}) {
1304
+ if (!id || !profileId) throw new Error("id and profileId required");
1305
+ if (_commgovJsV2.has(id))
1306
+ throw new Error(`commgov motion ${id} already exists`);
1307
+ if (!_commgovPsV2.has(profileId))
1308
+ throw new Error(`commgov profile ${profileId} not found`);
1309
+ if (_commgovCountPending(profileId) >= _commgovMaxPending)
1310
+ throw new Error(
1311
+ `max pending commgov motions for profile ${profileId} reached`,
1312
+ );
1313
+ const now = Date.now();
1314
+ const j = {
1315
+ id,
1316
+ profileId,
1317
+ subject: subject || "",
1318
+ status: COMMGOV_MOTION_LIFECYCLE_V2.QUEUED,
1319
+ createdAt: now,
1320
+ updatedAt: now,
1321
+ startedAt: null,
1322
+ settledAt: null,
1323
+ metadata: { ...(metadata || {}) },
1324
+ };
1325
+ _commgovJsV2.set(id, j);
1326
+ return { ...j, metadata: { ...j.metadata } };
1327
+ }
1328
+ export function votingCommgovMotionV2(id) {
1329
+ const j = _commgovJsV2.get(id);
1330
+ if (!j) throw new Error(`commgov motion ${id} not found`);
1331
+ _commgovCheckJ(j.status, COMMGOV_MOTION_LIFECYCLE_V2.VOTING);
1332
+ const now = Date.now();
1333
+ j.status = COMMGOV_MOTION_LIFECYCLE_V2.VOTING;
1334
+ j.updatedAt = now;
1335
+ if (!j.startedAt) j.startedAt = now;
1336
+ return { ...j, metadata: { ...j.metadata } };
1337
+ }
1338
+ export function completeMotionCommgovV2(id) {
1339
+ const j = _commgovJsV2.get(id);
1340
+ if (!j) throw new Error(`commgov motion ${id} not found`);
1341
+ _commgovCheckJ(j.status, COMMGOV_MOTION_LIFECYCLE_V2.VOTED);
1342
+ const now = Date.now();
1343
+ j.status = COMMGOV_MOTION_LIFECYCLE_V2.VOTED;
1344
+ j.updatedAt = now;
1345
+ if (!j.settledAt) j.settledAt = now;
1346
+ return { ...j, metadata: { ...j.metadata } };
1347
+ }
1348
+ export function failCommgovMotionV2(id, reason) {
1349
+ const j = _commgovJsV2.get(id);
1350
+ if (!j) throw new Error(`commgov motion ${id} not found`);
1351
+ _commgovCheckJ(j.status, COMMGOV_MOTION_LIFECYCLE_V2.FAILED);
1352
+ const now = Date.now();
1353
+ j.status = COMMGOV_MOTION_LIFECYCLE_V2.FAILED;
1354
+ j.updatedAt = now;
1355
+ if (!j.settledAt) j.settledAt = now;
1356
+ if (reason) j.metadata.failReason = String(reason);
1357
+ return { ...j, metadata: { ...j.metadata } };
1358
+ }
1359
+ export function cancelCommgovMotionV2(id, reason) {
1360
+ const j = _commgovJsV2.get(id);
1361
+ if (!j) throw new Error(`commgov motion ${id} not found`);
1362
+ _commgovCheckJ(j.status, COMMGOV_MOTION_LIFECYCLE_V2.CANCELLED);
1363
+ const now = Date.now();
1364
+ j.status = COMMGOV_MOTION_LIFECYCLE_V2.CANCELLED;
1365
+ j.updatedAt = now;
1366
+ if (!j.settledAt) j.settledAt = now;
1367
+ if (reason) j.metadata.cancelReason = String(reason);
1368
+ return { ...j, metadata: { ...j.metadata } };
1369
+ }
1370
+ export function getCommgovMotionV2(id) {
1371
+ const j = _commgovJsV2.get(id);
1372
+ if (!j) return null;
1373
+ return { ...j, metadata: { ...j.metadata } };
1374
+ }
1375
+ export function listCommgovMotionsV2() {
1376
+ return [..._commgovJsV2.values()].map((j) => ({
1377
+ ...j,
1378
+ metadata: { ...j.metadata },
1379
+ }));
1380
+ }
1381
+ export function autoPauseIdleCommgovProfilesV2({ now } = {}) {
1382
+ const t = now ?? Date.now();
1383
+ const flipped = [];
1384
+ for (const p of _commgovPsV2.values())
1385
+ if (
1386
+ p.status === COMMGOV_PROFILE_MATURITY_V2.ACTIVE &&
1387
+ t - p.lastTouchedAt >= _commgovIdleMs
1388
+ ) {
1389
+ p.status = COMMGOV_PROFILE_MATURITY_V2.PAUSED;
1390
+ p.updatedAt = t;
1391
+ flipped.push(p.id);
1392
+ }
1393
+ return { flipped, count: flipped.length };
1394
+ }
1395
+ export function autoFailStuckCommgovMotionsV2({ now } = {}) {
1396
+ const t = now ?? Date.now();
1397
+ const flipped = [];
1398
+ for (const j of _commgovJsV2.values())
1399
+ if (
1400
+ j.status === COMMGOV_MOTION_LIFECYCLE_V2.VOTING &&
1401
+ j.startedAt != null &&
1402
+ t - j.startedAt >= _commgovStuckMs
1403
+ ) {
1404
+ j.status = COMMGOV_MOTION_LIFECYCLE_V2.FAILED;
1405
+ j.updatedAt = t;
1406
+ if (!j.settledAt) j.settledAt = t;
1407
+ j.metadata.failReason = "auto-fail-stuck";
1408
+ flipped.push(j.id);
1409
+ }
1410
+ return { flipped, count: flipped.length };
1411
+ }
1412
+ export function getCommunityGovernanceGovStatsV2() {
1413
+ const profilesByStatus = {};
1414
+ for (const v of Object.values(COMMGOV_PROFILE_MATURITY_V2))
1415
+ profilesByStatus[v] = 0;
1416
+ for (const p of _commgovPsV2.values()) profilesByStatus[p.status]++;
1417
+ const motionsByStatus = {};
1418
+ for (const v of Object.values(COMMGOV_MOTION_LIFECYCLE_V2))
1419
+ motionsByStatus[v] = 0;
1420
+ for (const j of _commgovJsV2.values()) motionsByStatus[j.status]++;
1421
+ return {
1422
+ totalCommgovProfilesV2: _commgovPsV2.size,
1423
+ totalCommgovMotionsV2: _commgovJsV2.size,
1424
+ maxActiveCommgovProfilesPerOwner: _commgovMaxActive,
1425
+ maxPendingCommgovMotionsPerProfile: _commgovMaxPending,
1426
+ commgovProfileIdleMs: _commgovIdleMs,
1427
+ commgovMotionStuckMs: _commgovStuckMs,
1428
+ profilesByStatus,
1429
+ motionsByStatus,
1430
+ };
1431
+ }
@@ -1052,3 +1052,337 @@ export function getComplianceManagerGovStatsV2() {
1052
1052
  auditsByStatus,
1053
1053
  };
1054
1054
  }
1055
+
1056
+ // === Iter28 V2 governance overlay: Cmpmgov ===
1057
+ export const CMPMGOV_PROFILE_MATURITY_V2 = Object.freeze({
1058
+ PENDING: "pending",
1059
+ ACTIVE: "active",
1060
+ STALE: "stale",
1061
+ ARCHIVED: "archived",
1062
+ });
1063
+ export const CMPMGOV_REPORT_LIFECYCLE_V2 = Object.freeze({
1064
+ QUEUED: "queued",
1065
+ REPORTING: "reporting",
1066
+ REPORTED: "reported",
1067
+ FAILED: "failed",
1068
+ CANCELLED: "cancelled",
1069
+ });
1070
+ const _cmpmgovPTrans = new Map([
1071
+ [
1072
+ CMPMGOV_PROFILE_MATURITY_V2.PENDING,
1073
+ new Set([
1074
+ CMPMGOV_PROFILE_MATURITY_V2.ACTIVE,
1075
+ CMPMGOV_PROFILE_MATURITY_V2.ARCHIVED,
1076
+ ]),
1077
+ ],
1078
+ [
1079
+ CMPMGOV_PROFILE_MATURITY_V2.ACTIVE,
1080
+ new Set([
1081
+ CMPMGOV_PROFILE_MATURITY_V2.STALE,
1082
+ CMPMGOV_PROFILE_MATURITY_V2.ARCHIVED,
1083
+ ]),
1084
+ ],
1085
+ [
1086
+ CMPMGOV_PROFILE_MATURITY_V2.STALE,
1087
+ new Set([
1088
+ CMPMGOV_PROFILE_MATURITY_V2.ACTIVE,
1089
+ CMPMGOV_PROFILE_MATURITY_V2.ARCHIVED,
1090
+ ]),
1091
+ ],
1092
+ [CMPMGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
1093
+ ]);
1094
+ const _cmpmgovPTerminal = new Set([CMPMGOV_PROFILE_MATURITY_V2.ARCHIVED]);
1095
+ const _cmpmgovJTrans = new Map([
1096
+ [
1097
+ CMPMGOV_REPORT_LIFECYCLE_V2.QUEUED,
1098
+ new Set([
1099
+ CMPMGOV_REPORT_LIFECYCLE_V2.REPORTING,
1100
+ CMPMGOV_REPORT_LIFECYCLE_V2.CANCELLED,
1101
+ ]),
1102
+ ],
1103
+ [
1104
+ CMPMGOV_REPORT_LIFECYCLE_V2.REPORTING,
1105
+ new Set([
1106
+ CMPMGOV_REPORT_LIFECYCLE_V2.REPORTED,
1107
+ CMPMGOV_REPORT_LIFECYCLE_V2.FAILED,
1108
+ CMPMGOV_REPORT_LIFECYCLE_V2.CANCELLED,
1109
+ ]),
1110
+ ],
1111
+ [CMPMGOV_REPORT_LIFECYCLE_V2.REPORTED, new Set()],
1112
+ [CMPMGOV_REPORT_LIFECYCLE_V2.FAILED, new Set()],
1113
+ [CMPMGOV_REPORT_LIFECYCLE_V2.CANCELLED, new Set()],
1114
+ ]);
1115
+ const _cmpmgovPsV2 = new Map();
1116
+ const _cmpmgovJsV2 = new Map();
1117
+ let _cmpmgovMaxActive = 6,
1118
+ _cmpmgovMaxPending = 15,
1119
+ _cmpmgovIdleMs = 2592000000,
1120
+ _cmpmgovStuckMs = 60 * 1000;
1121
+ function _cmpmgovPos(n, label) {
1122
+ const v = Math.floor(Number(n));
1123
+ if (!Number.isFinite(v) || v <= 0)
1124
+ throw new Error(`${label} must be positive integer`);
1125
+ return v;
1126
+ }
1127
+ function _cmpmgovCheckP(from, to) {
1128
+ const a = _cmpmgovPTrans.get(from);
1129
+ if (!a || !a.has(to))
1130
+ throw new Error(`invalid cmpmgov profile transition ${from} → ${to}`);
1131
+ }
1132
+ function _cmpmgovCheckJ(from, to) {
1133
+ const a = _cmpmgovJTrans.get(from);
1134
+ if (!a || !a.has(to))
1135
+ throw new Error(`invalid cmpmgov report transition ${from} → ${to}`);
1136
+ }
1137
+ function _cmpmgovCountActive(owner) {
1138
+ let c = 0;
1139
+ for (const p of _cmpmgovPsV2.values())
1140
+ if (p.owner === owner && p.status === CMPMGOV_PROFILE_MATURITY_V2.ACTIVE)
1141
+ c++;
1142
+ return c;
1143
+ }
1144
+ function _cmpmgovCountPending(profileId) {
1145
+ let c = 0;
1146
+ for (const j of _cmpmgovJsV2.values())
1147
+ if (
1148
+ j.profileId === profileId &&
1149
+ (j.status === CMPMGOV_REPORT_LIFECYCLE_V2.QUEUED ||
1150
+ j.status === CMPMGOV_REPORT_LIFECYCLE_V2.REPORTING)
1151
+ )
1152
+ c++;
1153
+ return c;
1154
+ }
1155
+ export function setMaxActiveCmpmProfilesPerOwnerV2(n) {
1156
+ _cmpmgovMaxActive = _cmpmgovPos(n, "maxActiveCmpmProfilesPerOwner");
1157
+ }
1158
+ export function getMaxActiveCmpmProfilesPerOwnerV2() {
1159
+ return _cmpmgovMaxActive;
1160
+ }
1161
+ export function setMaxPendingCmpmReportsPerProfileV2(n) {
1162
+ _cmpmgovMaxPending = _cmpmgovPos(n, "maxPendingCmpmReportsPerProfile");
1163
+ }
1164
+ export function getMaxPendingCmpmReportsPerProfileV2() {
1165
+ return _cmpmgovMaxPending;
1166
+ }
1167
+ export function setCmpmProfileIdleMsV2(n) {
1168
+ _cmpmgovIdleMs = _cmpmgovPos(n, "cmpmgovProfileIdleMs");
1169
+ }
1170
+ export function getCmpmProfileIdleMsV2() {
1171
+ return _cmpmgovIdleMs;
1172
+ }
1173
+ export function setCmpmReportStuckMsV2(n) {
1174
+ _cmpmgovStuckMs = _cmpmgovPos(n, "cmpmgovReportStuckMs");
1175
+ }
1176
+ export function getCmpmReportStuckMsV2() {
1177
+ return _cmpmgovStuckMs;
1178
+ }
1179
+ export function _resetStateCmpmgovV2() {
1180
+ _cmpmgovPsV2.clear();
1181
+ _cmpmgovJsV2.clear();
1182
+ _cmpmgovMaxActive = 6;
1183
+ _cmpmgovMaxPending = 15;
1184
+ _cmpmgovIdleMs = 2592000000;
1185
+ _cmpmgovStuckMs = 60 * 1000;
1186
+ }
1187
+ export function registerCmpmProfileV2({ id, owner, framework, metadata } = {}) {
1188
+ if (!id || !owner) throw new Error("id and owner required");
1189
+ if (_cmpmgovPsV2.has(id))
1190
+ throw new Error(`cmpmgov profile ${id} already exists`);
1191
+ const now = Date.now();
1192
+ const p = {
1193
+ id,
1194
+ owner,
1195
+ framework: framework || "soc2",
1196
+ status: CMPMGOV_PROFILE_MATURITY_V2.PENDING,
1197
+ createdAt: now,
1198
+ updatedAt: now,
1199
+ lastTouchedAt: now,
1200
+ activatedAt: null,
1201
+ archivedAt: null,
1202
+ metadata: { ...(metadata || {}) },
1203
+ };
1204
+ _cmpmgovPsV2.set(id, p);
1205
+ return { ...p, metadata: { ...p.metadata } };
1206
+ }
1207
+ export function activateCmpmProfileV2(id) {
1208
+ const p = _cmpmgovPsV2.get(id);
1209
+ if (!p) throw new Error(`cmpmgov profile ${id} not found`);
1210
+ const isInitial = p.status === CMPMGOV_PROFILE_MATURITY_V2.PENDING;
1211
+ _cmpmgovCheckP(p.status, CMPMGOV_PROFILE_MATURITY_V2.ACTIVE);
1212
+ if (isInitial && _cmpmgovCountActive(p.owner) >= _cmpmgovMaxActive)
1213
+ throw new Error(`max active cmpmgov profiles for owner ${p.owner} reached`);
1214
+ const now = Date.now();
1215
+ p.status = CMPMGOV_PROFILE_MATURITY_V2.ACTIVE;
1216
+ p.updatedAt = now;
1217
+ p.lastTouchedAt = now;
1218
+ if (!p.activatedAt) p.activatedAt = now;
1219
+ return { ...p, metadata: { ...p.metadata } };
1220
+ }
1221
+ export function staleCmpmProfileV2(id) {
1222
+ const p = _cmpmgovPsV2.get(id);
1223
+ if (!p) throw new Error(`cmpmgov profile ${id} not found`);
1224
+ _cmpmgovCheckP(p.status, CMPMGOV_PROFILE_MATURITY_V2.STALE);
1225
+ p.status = CMPMGOV_PROFILE_MATURITY_V2.STALE;
1226
+ p.updatedAt = Date.now();
1227
+ return { ...p, metadata: { ...p.metadata } };
1228
+ }
1229
+ export function archiveCmpmProfileV2(id) {
1230
+ const p = _cmpmgovPsV2.get(id);
1231
+ if (!p) throw new Error(`cmpmgov profile ${id} not found`);
1232
+ _cmpmgovCheckP(p.status, CMPMGOV_PROFILE_MATURITY_V2.ARCHIVED);
1233
+ const now = Date.now();
1234
+ p.status = CMPMGOV_PROFILE_MATURITY_V2.ARCHIVED;
1235
+ p.updatedAt = now;
1236
+ if (!p.archivedAt) p.archivedAt = now;
1237
+ return { ...p, metadata: { ...p.metadata } };
1238
+ }
1239
+ export function touchCmpmProfileV2(id) {
1240
+ const p = _cmpmgovPsV2.get(id);
1241
+ if (!p) throw new Error(`cmpmgov profile ${id} not found`);
1242
+ if (_cmpmgovPTerminal.has(p.status))
1243
+ throw new Error(`cannot touch terminal cmpmgov profile ${id}`);
1244
+ const now = Date.now();
1245
+ p.lastTouchedAt = now;
1246
+ p.updatedAt = now;
1247
+ return { ...p, metadata: { ...p.metadata } };
1248
+ }
1249
+ export function getCmpmProfileV2(id) {
1250
+ const p = _cmpmgovPsV2.get(id);
1251
+ if (!p) return null;
1252
+ return { ...p, metadata: { ...p.metadata } };
1253
+ }
1254
+ export function listCmpmProfilesV2() {
1255
+ return [..._cmpmgovPsV2.values()].map((p) => ({
1256
+ ...p,
1257
+ metadata: { ...p.metadata },
1258
+ }));
1259
+ }
1260
+ export function createCmpmReportV2({ id, profileId, reportId, metadata } = {}) {
1261
+ if (!id || !profileId) throw new Error("id and profileId required");
1262
+ if (_cmpmgovJsV2.has(id))
1263
+ throw new Error(`cmpmgov report ${id} already exists`);
1264
+ if (!_cmpmgovPsV2.has(profileId))
1265
+ throw new Error(`cmpmgov profile ${profileId} not found`);
1266
+ if (_cmpmgovCountPending(profileId) >= _cmpmgovMaxPending)
1267
+ throw new Error(
1268
+ `max pending cmpmgov reports for profile ${profileId} reached`,
1269
+ );
1270
+ const now = Date.now();
1271
+ const j = {
1272
+ id,
1273
+ profileId,
1274
+ reportId: reportId || "",
1275
+ status: CMPMGOV_REPORT_LIFECYCLE_V2.QUEUED,
1276
+ createdAt: now,
1277
+ updatedAt: now,
1278
+ startedAt: null,
1279
+ settledAt: null,
1280
+ metadata: { ...(metadata || {}) },
1281
+ };
1282
+ _cmpmgovJsV2.set(id, j);
1283
+ return { ...j, metadata: { ...j.metadata } };
1284
+ }
1285
+ export function reportingCmpmReportV2(id) {
1286
+ const j = _cmpmgovJsV2.get(id);
1287
+ if (!j) throw new Error(`cmpmgov report ${id} not found`);
1288
+ _cmpmgovCheckJ(j.status, CMPMGOV_REPORT_LIFECYCLE_V2.REPORTING);
1289
+ const now = Date.now();
1290
+ j.status = CMPMGOV_REPORT_LIFECYCLE_V2.REPORTING;
1291
+ j.updatedAt = now;
1292
+ if (!j.startedAt) j.startedAt = now;
1293
+ return { ...j, metadata: { ...j.metadata } };
1294
+ }
1295
+ export function completeReportCmpmV2(id) {
1296
+ const j = _cmpmgovJsV2.get(id);
1297
+ if (!j) throw new Error(`cmpmgov report ${id} not found`);
1298
+ _cmpmgovCheckJ(j.status, CMPMGOV_REPORT_LIFECYCLE_V2.REPORTED);
1299
+ const now = Date.now();
1300
+ j.status = CMPMGOV_REPORT_LIFECYCLE_V2.REPORTED;
1301
+ j.updatedAt = now;
1302
+ if (!j.settledAt) j.settledAt = now;
1303
+ return { ...j, metadata: { ...j.metadata } };
1304
+ }
1305
+ export function failCmpmReportV2(id, reason) {
1306
+ const j = _cmpmgovJsV2.get(id);
1307
+ if (!j) throw new Error(`cmpmgov report ${id} not found`);
1308
+ _cmpmgovCheckJ(j.status, CMPMGOV_REPORT_LIFECYCLE_V2.FAILED);
1309
+ const now = Date.now();
1310
+ j.status = CMPMGOV_REPORT_LIFECYCLE_V2.FAILED;
1311
+ j.updatedAt = now;
1312
+ if (!j.settledAt) j.settledAt = now;
1313
+ if (reason) j.metadata.failReason = String(reason);
1314
+ return { ...j, metadata: { ...j.metadata } };
1315
+ }
1316
+ export function cancelCmpmReportV2(id, reason) {
1317
+ const j = _cmpmgovJsV2.get(id);
1318
+ if (!j) throw new Error(`cmpmgov report ${id} not found`);
1319
+ _cmpmgovCheckJ(j.status, CMPMGOV_REPORT_LIFECYCLE_V2.CANCELLED);
1320
+ const now = Date.now();
1321
+ j.status = CMPMGOV_REPORT_LIFECYCLE_V2.CANCELLED;
1322
+ j.updatedAt = now;
1323
+ if (!j.settledAt) j.settledAt = now;
1324
+ if (reason) j.metadata.cancelReason = String(reason);
1325
+ return { ...j, metadata: { ...j.metadata } };
1326
+ }
1327
+ export function getCmpmReportV2(id) {
1328
+ const j = _cmpmgovJsV2.get(id);
1329
+ if (!j) return null;
1330
+ return { ...j, metadata: { ...j.metadata } };
1331
+ }
1332
+ export function listCmpmReportsV2() {
1333
+ return [..._cmpmgovJsV2.values()].map((j) => ({
1334
+ ...j,
1335
+ metadata: { ...j.metadata },
1336
+ }));
1337
+ }
1338
+ export function autoStaleIdleCmpmProfilesV2({ now } = {}) {
1339
+ const t = now ?? Date.now();
1340
+ const flipped = [];
1341
+ for (const p of _cmpmgovPsV2.values())
1342
+ if (
1343
+ p.status === CMPMGOV_PROFILE_MATURITY_V2.ACTIVE &&
1344
+ t - p.lastTouchedAt >= _cmpmgovIdleMs
1345
+ ) {
1346
+ p.status = CMPMGOV_PROFILE_MATURITY_V2.STALE;
1347
+ p.updatedAt = t;
1348
+ flipped.push(p.id);
1349
+ }
1350
+ return { flipped, count: flipped.length };
1351
+ }
1352
+ export function autoFailStuckCmpmReportsV2({ now } = {}) {
1353
+ const t = now ?? Date.now();
1354
+ const flipped = [];
1355
+ for (const j of _cmpmgovJsV2.values())
1356
+ if (
1357
+ j.status === CMPMGOV_REPORT_LIFECYCLE_V2.REPORTING &&
1358
+ j.startedAt != null &&
1359
+ t - j.startedAt >= _cmpmgovStuckMs
1360
+ ) {
1361
+ j.status = CMPMGOV_REPORT_LIFECYCLE_V2.FAILED;
1362
+ j.updatedAt = t;
1363
+ if (!j.settledAt) j.settledAt = t;
1364
+ j.metadata.failReason = "auto-fail-stuck";
1365
+ flipped.push(j.id);
1366
+ }
1367
+ return { flipped, count: flipped.length };
1368
+ }
1369
+ export function getCmpmgovStatsV2() {
1370
+ const profilesByStatus = {};
1371
+ for (const v of Object.values(CMPMGOV_PROFILE_MATURITY_V2))
1372
+ profilesByStatus[v] = 0;
1373
+ for (const p of _cmpmgovPsV2.values()) profilesByStatus[p.status]++;
1374
+ const reportsByStatus = {};
1375
+ for (const v of Object.values(CMPMGOV_REPORT_LIFECYCLE_V2))
1376
+ reportsByStatus[v] = 0;
1377
+ for (const j of _cmpmgovJsV2.values()) reportsByStatus[j.status]++;
1378
+ return {
1379
+ totalCmpmProfilesV2: _cmpmgovPsV2.size,
1380
+ totalCmpmReportsV2: _cmpmgovJsV2.size,
1381
+ maxActiveCmpmProfilesPerOwner: _cmpmgovMaxActive,
1382
+ maxPendingCmpmReportsPerProfile: _cmpmgovMaxPending,
1383
+ cmpmgovProfileIdleMs: _cmpmgovIdleMs,
1384
+ cmpmgovReportStuckMs: _cmpmgovStuckMs,
1385
+ profilesByStatus,
1386
+ reportsByStatus,
1387
+ };
1388
+ }