chainlesschain 0.143.0 → 0.152.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 (227) hide show
  1. package/package.json +1 -1
  2. package/src/commands/a2a.js +196 -28
  3. package/src/commands/activitypub.js +364 -27
  4. package/src/commands/agent-network.js +217 -0
  5. package/src/commands/agent.js +587 -103
  6. package/src/commands/audit.js +206 -0
  7. package/src/commands/automation.js +201 -0
  8. package/src/commands/bi.js +355 -27
  9. package/src/commands/bm25.js +111 -27
  10. package/src/commands/browse.js +403 -29
  11. package/src/commands/ccron.js +128 -28
  12. package/src/commands/chat.js +207 -0
  13. package/src/commands/codegen.js +207 -0
  14. package/src/commands/collab.js +211 -0
  15. package/src/commands/compliance.js +824 -34
  16. package/src/commands/compt.js +127 -29
  17. package/src/commands/consol.js +8 -2
  18. package/src/commands/cowork.js +783 -34
  19. package/src/commands/crosschain.js +182 -28
  20. package/src/commands/dao.js +182 -28
  21. package/src/commands/dbevo.js +227 -0
  22. package/src/commands/dev.js +207 -0
  23. package/src/commands/did-v2.js +217 -0
  24. package/src/commands/did.js +221 -0
  25. package/src/commands/dlp.js +385 -27
  26. package/src/commands/economy.js +205 -50
  27. package/src/commands/evolution.js +203 -50
  28. package/src/commands/evomap.js +387 -27
  29. package/src/commands/export.js +213 -0
  30. package/src/commands/federation.js +209 -0
  31. package/src/commands/fflag.js +74 -22
  32. package/src/commands/fusion.js +205 -0
  33. package/src/commands/git.js +177 -37
  34. package/src/commands/governance.js +209 -0
  35. package/src/commands/hardening.js +209 -0
  36. package/src/commands/hmemory.js +204 -50
  37. package/src/commands/hook.js +209 -0
  38. package/src/commands/import.js +209 -0
  39. package/src/commands/incentive.js +209 -0
  40. package/src/commands/inference.js +170 -34
  41. package/src/commands/infra.js +203 -0
  42. package/src/commands/instinct.js +209 -0
  43. package/src/commands/ipfs.js +207 -0
  44. package/src/commands/itbudget.js +149 -33
  45. package/src/commands/kg.js +206 -0
  46. package/src/commands/llm.js +217 -0
  47. package/src/commands/lowcode.js +195 -38
  48. package/src/commands/marketplace.js +206 -0
  49. package/src/commands/matrix.js +386 -27
  50. package/src/commands/mcp.js +217 -0
  51. package/src/commands/mcpscaf.js +145 -33
  52. package/src/commands/meminj.js +145 -33
  53. package/src/commands/memory.js +209 -0
  54. package/src/commands/multimodal.js +203 -0
  55. package/src/commands/nlprog.js +225 -0
  56. package/src/commands/nostr.js +387 -27
  57. package/src/commands/note.js +205 -0
  58. package/src/commands/ops.js +219 -0
  59. package/src/commands/orchestrate.js +217 -0
  60. package/src/commands/orchgov.js +144 -33
  61. package/src/commands/org.js +209 -0
  62. package/src/commands/p2p.js +209 -0
  63. package/src/commands/pdfp.js +109 -27
  64. package/src/commands/perception.js +209 -0
  65. package/src/commands/perf.js +169 -32
  66. package/src/commands/perm.js +144 -33
  67. package/src/commands/permmem.js +203 -0
  68. package/src/commands/pipeline.js +207 -52
  69. package/src/commands/planmode.js +141 -32
  70. package/src/commands/plugin-ecosystem.js +209 -0
  71. package/src/commands/pqc.js +213 -0
  72. package/src/commands/privacy.js +203 -0
  73. package/src/commands/promcomp.js +111 -27
  74. package/src/commands/quantization.js +207 -0
  75. package/src/commands/rcache.js +205 -0
  76. package/src/commands/recommend.js +410 -34
  77. package/src/commands/reputation.js +208 -0
  78. package/src/commands/runtime.js +205 -0
  79. package/src/commands/sandbox.js +206 -0
  80. package/src/commands/scim.js +209 -0
  81. package/src/commands/seshhook.js +145 -33
  82. package/src/commands/seshsearch.js +141 -33
  83. package/src/commands/seshtail.js +144 -33
  84. package/src/commands/seshu.js +152 -33
  85. package/src/commands/session.js +209 -0
  86. package/src/commands/sganal.js +123 -29
  87. package/src/commands/siem.js +201 -34
  88. package/src/commands/skill.js +207 -0
  89. package/src/commands/sla.js +212 -0
  90. package/src/commands/slotfill.js +146 -33
  91. package/src/commands/social.js +358 -32
  92. package/src/commands/sso.js +209 -0
  93. package/src/commands/stress.js +206 -0
  94. package/src/commands/svccont.js +145 -33
  95. package/src/commands/sync.js +209 -0
  96. package/src/commands/tech.js +209 -0
  97. package/src/commands/tenant.js +217 -0
  98. package/src/commands/terraform.js +206 -0
  99. package/src/commands/tms.js +171 -33
  100. package/src/commands/tokens.js +209 -0
  101. package/src/commands/topiccls.js +146 -33
  102. package/src/commands/trust.js +217 -0
  103. package/src/commands/uprof.js +141 -32
  104. package/src/commands/vcheck.js +122 -28
  105. package/src/commands/wallet.js +209 -0
  106. package/src/commands/webfetch.js +141 -32
  107. package/src/commands/workflow.js +203 -0
  108. package/src/commands/zkp.js +184 -28
  109. package/src/index.js +180 -0
  110. package/src/lib/a2a-protocol.js +319 -51
  111. package/src/lib/activitypub-bridge.js +622 -50
  112. package/src/lib/agent-economy.js +304 -51
  113. package/src/lib/agent-network.js +341 -0
  114. package/src/lib/aiops.js +346 -0
  115. package/src/lib/app-builder.js +279 -46
  116. package/src/lib/audit-logger.js +321 -0
  117. package/src/lib/automation-engine.js +335 -0
  118. package/src/lib/autonomous-agent.js +284 -48
  119. package/src/lib/autonomous-developer.js +332 -0
  120. package/src/lib/bi-engine.js +616 -49
  121. package/src/lib/bm25-search.js +301 -49
  122. package/src/lib/browser-automation.js +630 -49
  123. package/src/lib/chat-core.js +336 -0
  124. package/src/lib/claude-code-bridge.js +341 -0
  125. package/src/lib/code-agent.js +339 -0
  126. package/src/lib/collaboration-governance.js +334 -0
  127. package/src/lib/community-governance.js +346 -0
  128. package/src/lib/compliance-framework-reporter.js +305 -51
  129. package/src/lib/compliance-manager.js +330 -0
  130. package/src/lib/compression-telemetry.js +301 -49
  131. package/src/lib/content-recommendation.js +351 -0
  132. package/src/lib/content-recommender.js +317 -52
  133. package/src/lib/cowork-cron.js +298 -49
  134. package/src/lib/cowork-learning.js +333 -0
  135. package/src/lib/cowork-share.js +338 -0
  136. package/src/lib/cowork-task-runner.js +308 -51
  137. package/src/lib/cowork-workflow.js +327 -0
  138. package/src/lib/cross-chain.js +311 -51
  139. package/src/lib/dao-governance.js +280 -46
  140. package/src/lib/dbevo.js +351 -0
  141. package/src/lib/decentral-infra.js +330 -0
  142. package/src/lib/did-manager.js +341 -0
  143. package/src/lib/did-v2-manager.js +341 -0
  144. package/src/lib/dlp-engine.js +626 -49
  145. package/src/lib/evolution-system.js +278 -47
  146. package/src/lib/evomap-governance.js +334 -0
  147. package/src/lib/evomap-manager.js +280 -46
  148. package/src/lib/execution-backend.js +294 -48
  149. package/src/lib/feature-flags.js +294 -49
  150. package/src/lib/federation-hardening.js +340 -0
  151. package/src/lib/git-integration.js +285 -47
  152. package/src/lib/hardening-manager.js +341 -0
  153. package/src/lib/hierarchical-memory.js +284 -48
  154. package/src/lib/hook-manager.js +341 -0
  155. package/src/lib/inference-network.js +308 -51
  156. package/src/lib/instinct-manager.js +346 -0
  157. package/src/lib/ipfs-storage.js +334 -0
  158. package/src/lib/iteration-budget.js +302 -50
  159. package/src/lib/knowledge-exporter.js +341 -0
  160. package/src/lib/knowledge-graph.js +333 -0
  161. package/src/lib/knowledge-importer.js +341 -0
  162. package/src/lib/llm-providers.js +346 -0
  163. package/src/lib/matrix-bridge.js +620 -47
  164. package/src/lib/mcp-registry.js +346 -0
  165. package/src/lib/mcp-scaffold.js +318 -54
  166. package/src/lib/memory-injection.js +288 -49
  167. package/src/lib/memory-manager.js +336 -0
  168. package/src/lib/multimodal.js +330 -0
  169. package/src/lib/nl-programming.js +341 -0
  170. package/src/lib/nostr-bridge.js +622 -49
  171. package/src/lib/note-versioning.js +339 -0
  172. package/src/lib/orchestrator.js +293 -48
  173. package/src/lib/org-manager.js +336 -0
  174. package/src/lib/p2p-manager.js +341 -0
  175. package/src/lib/pdf-parser.js +298 -49
  176. package/src/lib/perception.js +346 -0
  177. package/src/lib/perf-tuning.js +309 -50
  178. package/src/lib/permanent-memory.js +327 -0
  179. package/src/lib/permission-engine.js +287 -49
  180. package/src/lib/pipeline-orchestrator.js +289 -49
  181. package/src/lib/plan-mode.js +298 -51
  182. package/src/lib/plugin-ecosystem.js +346 -0
  183. package/src/lib/pqc-manager.js +346 -0
  184. package/src/lib/privacy-computing.js +335 -0
  185. package/src/lib/protocol-fusion.js +338 -0
  186. package/src/lib/quantization.js +337 -0
  187. package/src/lib/reputation-optimizer.js +340 -0
  188. package/src/lib/response-cache.js +333 -0
  189. package/src/lib/sandbox-v2.js +327 -0
  190. package/src/lib/scim-manager.js +346 -0
  191. package/src/lib/service-container.js +313 -52
  192. package/src/lib/session-consolidator.js +296 -49
  193. package/src/lib/session-hooks.js +312 -53
  194. package/src/lib/session-manager.js +334 -0
  195. package/src/lib/session-search.js +304 -51
  196. package/src/lib/session-tail.js +288 -49
  197. package/src/lib/session-usage.js +298 -52
  198. package/src/lib/siem-exporter.js +298 -51
  199. package/src/lib/skill-loader.js +334 -0
  200. package/src/lib/skill-marketplace.js +345 -0
  201. package/src/lib/sla-manager.js +341 -0
  202. package/src/lib/slot-filler.js +303 -51
  203. package/src/lib/social-graph-analytics.js +295 -49
  204. package/src/lib/social-graph.js +272 -49
  205. package/src/lib/social-manager.js +330 -0
  206. package/src/lib/sso-manager.js +340 -0
  207. package/src/lib/stress-tester.js +342 -0
  208. package/src/lib/sub-agent-registry.js +302 -53
  209. package/src/lib/sync-manager.js +336 -0
  210. package/src/lib/task-model-selector.js +302 -50
  211. package/src/lib/tech-learning-engine.js +341 -0
  212. package/src/lib/tenant-saas.js +341 -0
  213. package/src/lib/terraform-manager.js +333 -0
  214. package/src/lib/threat-intel.js +330 -0
  215. package/src/lib/todo-manager.js +281 -47
  216. package/src/lib/token-incentive.js +341 -0
  217. package/src/lib/token-tracker.js +336 -0
  218. package/src/lib/topic-classifier.js +297 -49
  219. package/src/lib/trust-security.js +343 -0
  220. package/src/lib/ueba.js +340 -0
  221. package/src/lib/universal-runtime.js +330 -0
  222. package/src/lib/user-profile.js +294 -50
  223. package/src/lib/version-checker.js +304 -50
  224. package/src/lib/wallet-manager.js +336 -0
  225. package/src/lib/web-fetch.js +292 -51
  226. package/src/lib/workflow-engine.js +330 -0
  227. package/src/lib/zkp-engine.js +286 -49
package/src/lib/dbevo.js CHANGED
@@ -1005,3 +1005,354 @@ export function _resetStateV2() {
1005
1005
  _baselinesV2.clear();
1006
1006
  _runsV2.clear();
1007
1007
  }
1008
+
1009
+ // =====================================================================
1010
+ // dbevo V2 governance overlay (iter23)
1011
+ // =====================================================================
1012
+ export const DBEVOGOV_PROFILE_MATURITY_V2 = Object.freeze({
1013
+ PENDING: "pending",
1014
+ ACTIVE: "active",
1015
+ PAUSED: "paused",
1016
+ ARCHIVED: "archived",
1017
+ });
1018
+ export const DBEVOGOV_MIGRATION_LIFECYCLE_V2 = Object.freeze({
1019
+ QUEUED: "queued",
1020
+ APPLYING: "applying",
1021
+ APPLIED: "applied",
1022
+ FAILED: "failed",
1023
+ CANCELLED: "cancelled",
1024
+ });
1025
+ const _dbevogovPTrans = new Map([
1026
+ [
1027
+ DBEVOGOV_PROFILE_MATURITY_V2.PENDING,
1028
+ new Set([
1029
+ DBEVOGOV_PROFILE_MATURITY_V2.ACTIVE,
1030
+ DBEVOGOV_PROFILE_MATURITY_V2.ARCHIVED,
1031
+ ]),
1032
+ ],
1033
+ [
1034
+ DBEVOGOV_PROFILE_MATURITY_V2.ACTIVE,
1035
+ new Set([
1036
+ DBEVOGOV_PROFILE_MATURITY_V2.PAUSED,
1037
+ DBEVOGOV_PROFILE_MATURITY_V2.ARCHIVED,
1038
+ ]),
1039
+ ],
1040
+ [
1041
+ DBEVOGOV_PROFILE_MATURITY_V2.PAUSED,
1042
+ new Set([
1043
+ DBEVOGOV_PROFILE_MATURITY_V2.ACTIVE,
1044
+ DBEVOGOV_PROFILE_MATURITY_V2.ARCHIVED,
1045
+ ]),
1046
+ ],
1047
+ [DBEVOGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
1048
+ ]);
1049
+ const _dbevogovPTerminal = new Set([DBEVOGOV_PROFILE_MATURITY_V2.ARCHIVED]);
1050
+ const _dbevogovJTrans = new Map([
1051
+ [
1052
+ DBEVOGOV_MIGRATION_LIFECYCLE_V2.QUEUED,
1053
+ new Set([
1054
+ DBEVOGOV_MIGRATION_LIFECYCLE_V2.APPLYING,
1055
+ DBEVOGOV_MIGRATION_LIFECYCLE_V2.CANCELLED,
1056
+ ]),
1057
+ ],
1058
+ [
1059
+ DBEVOGOV_MIGRATION_LIFECYCLE_V2.APPLYING,
1060
+ new Set([
1061
+ DBEVOGOV_MIGRATION_LIFECYCLE_V2.APPLIED,
1062
+ DBEVOGOV_MIGRATION_LIFECYCLE_V2.FAILED,
1063
+ DBEVOGOV_MIGRATION_LIFECYCLE_V2.CANCELLED,
1064
+ ]),
1065
+ ],
1066
+ [DBEVOGOV_MIGRATION_LIFECYCLE_V2.APPLIED, new Set()],
1067
+ [DBEVOGOV_MIGRATION_LIFECYCLE_V2.FAILED, new Set()],
1068
+ [DBEVOGOV_MIGRATION_LIFECYCLE_V2.CANCELLED, new Set()],
1069
+ ]);
1070
+ const _dbevogovPsV2 = new Map();
1071
+ const _dbevogovJsV2 = new Map();
1072
+ let _dbevogovMaxActive = 8,
1073
+ _dbevogovMaxPending = 20,
1074
+ _dbevogovIdleMs = 30 * 24 * 60 * 60 * 1000,
1075
+ _dbevogovStuckMs = 60 * 1000;
1076
+ function _dbevogovPos(n, label) {
1077
+ const v = Math.floor(Number(n));
1078
+ if (!Number.isFinite(v) || v <= 0)
1079
+ throw new Error(`${label} must be positive integer`);
1080
+ return v;
1081
+ }
1082
+ function _dbevogovCheckP(from, to) {
1083
+ const a = _dbevogovPTrans.get(from);
1084
+ if (!a || !a.has(to))
1085
+ throw new Error(`invalid dbevogov profile transition ${from} → ${to}`);
1086
+ }
1087
+ function _dbevogovCheckJ(from, to) {
1088
+ const a = _dbevogovJTrans.get(from);
1089
+ if (!a || !a.has(to))
1090
+ throw new Error(`invalid dbevogov migration transition ${from} → ${to}`);
1091
+ }
1092
+ function _dbevogovCountActive(owner) {
1093
+ let c = 0;
1094
+ for (const p of _dbevogovPsV2.values())
1095
+ if (p.owner === owner && p.status === DBEVOGOV_PROFILE_MATURITY_V2.ACTIVE)
1096
+ c++;
1097
+ return c;
1098
+ }
1099
+ function _dbevogovCountPending(profileId) {
1100
+ let c = 0;
1101
+ for (const j of _dbevogovJsV2.values())
1102
+ if (
1103
+ j.profileId === profileId &&
1104
+ (j.status === DBEVOGOV_MIGRATION_LIFECYCLE_V2.QUEUED ||
1105
+ j.status === DBEVOGOV_MIGRATION_LIFECYCLE_V2.APPLYING)
1106
+ )
1107
+ c++;
1108
+ return c;
1109
+ }
1110
+ export function setMaxActiveDbevogovProfilesPerOwnerV2(n) {
1111
+ _dbevogovMaxActive = _dbevogovPos(n, "maxActiveDbevogovProfilesPerOwner");
1112
+ }
1113
+ export function getMaxActiveDbevogovProfilesPerOwnerV2() {
1114
+ return _dbevogovMaxActive;
1115
+ }
1116
+ export function setMaxPendingDbevogovMigrationsPerProfileV2(n) {
1117
+ _dbevogovMaxPending = _dbevogovPos(
1118
+ n,
1119
+ "maxPendingDbevogovMigrationsPerProfile",
1120
+ );
1121
+ }
1122
+ export function getMaxPendingDbevogovMigrationsPerProfileV2() {
1123
+ return _dbevogovMaxPending;
1124
+ }
1125
+ export function setDbevogovProfileIdleMsV2(n) {
1126
+ _dbevogovIdleMs = _dbevogovPos(n, "dbevogovProfileIdleMs");
1127
+ }
1128
+ export function getDbevogovProfileIdleMsV2() {
1129
+ return _dbevogovIdleMs;
1130
+ }
1131
+ export function setDbevogovMigrationStuckMsV2(n) {
1132
+ _dbevogovStuckMs = _dbevogovPos(n, "dbevogovMigrationStuckMs");
1133
+ }
1134
+ export function getDbevogovMigrationStuckMsV2() {
1135
+ return _dbevogovStuckMs;
1136
+ }
1137
+ export function _resetStateDbevoGovV2() {
1138
+ _dbevogovPsV2.clear();
1139
+ _dbevogovJsV2.clear();
1140
+ _dbevogovMaxActive = 8;
1141
+ _dbevogovMaxPending = 20;
1142
+ _dbevogovIdleMs = 30 * 24 * 60 * 60 * 1000;
1143
+ _dbevogovStuckMs = 60 * 1000;
1144
+ }
1145
+ export function registerDbevogovProfileV2({
1146
+ id,
1147
+ owner,
1148
+ schema,
1149
+ metadata,
1150
+ } = {}) {
1151
+ if (!id || !owner) throw new Error("id and owner required");
1152
+ if (_dbevogovPsV2.has(id))
1153
+ throw new Error(`dbevogov profile ${id} already exists`);
1154
+ const now = Date.now();
1155
+ const p = {
1156
+ id,
1157
+ owner,
1158
+ schema: schema || "default",
1159
+ status: DBEVOGOV_PROFILE_MATURITY_V2.PENDING,
1160
+ createdAt: now,
1161
+ updatedAt: now,
1162
+ lastTouchedAt: now,
1163
+ activatedAt: null,
1164
+ archivedAt: null,
1165
+ metadata: { ...(metadata || {}) },
1166
+ };
1167
+ _dbevogovPsV2.set(id, p);
1168
+ return { ...p, metadata: { ...p.metadata } };
1169
+ }
1170
+ export function activateDbevogovProfileV2(id) {
1171
+ const p = _dbevogovPsV2.get(id);
1172
+ if (!p) throw new Error(`dbevogov profile ${id} not found`);
1173
+ const isInitial = p.status === DBEVOGOV_PROFILE_MATURITY_V2.PENDING;
1174
+ _dbevogovCheckP(p.status, DBEVOGOV_PROFILE_MATURITY_V2.ACTIVE);
1175
+ if (isInitial && _dbevogovCountActive(p.owner) >= _dbevogovMaxActive)
1176
+ throw new Error(
1177
+ `max active dbevogov profiles for owner ${p.owner} reached`,
1178
+ );
1179
+ const now = Date.now();
1180
+ p.status = DBEVOGOV_PROFILE_MATURITY_V2.ACTIVE;
1181
+ p.updatedAt = now;
1182
+ p.lastTouchedAt = now;
1183
+ if (!p.activatedAt) p.activatedAt = now;
1184
+ return { ...p, metadata: { ...p.metadata } };
1185
+ }
1186
+ export function pauseDbevogovProfileV2(id) {
1187
+ const p = _dbevogovPsV2.get(id);
1188
+ if (!p) throw new Error(`dbevogov profile ${id} not found`);
1189
+ _dbevogovCheckP(p.status, DBEVOGOV_PROFILE_MATURITY_V2.PAUSED);
1190
+ p.status = DBEVOGOV_PROFILE_MATURITY_V2.PAUSED;
1191
+ p.updatedAt = Date.now();
1192
+ return { ...p, metadata: { ...p.metadata } };
1193
+ }
1194
+ export function archiveDbevogovProfileV2(id) {
1195
+ const p = _dbevogovPsV2.get(id);
1196
+ if (!p) throw new Error(`dbevogov profile ${id} not found`);
1197
+ _dbevogovCheckP(p.status, DBEVOGOV_PROFILE_MATURITY_V2.ARCHIVED);
1198
+ const now = Date.now();
1199
+ p.status = DBEVOGOV_PROFILE_MATURITY_V2.ARCHIVED;
1200
+ p.updatedAt = now;
1201
+ if (!p.archivedAt) p.archivedAt = now;
1202
+ return { ...p, metadata: { ...p.metadata } };
1203
+ }
1204
+ export function touchDbevogovProfileV2(id) {
1205
+ const p = _dbevogovPsV2.get(id);
1206
+ if (!p) throw new Error(`dbevogov profile ${id} not found`);
1207
+ if (_dbevogovPTerminal.has(p.status))
1208
+ throw new Error(`cannot touch terminal dbevogov profile ${id}`);
1209
+ const now = Date.now();
1210
+ p.lastTouchedAt = now;
1211
+ p.updatedAt = now;
1212
+ return { ...p, metadata: { ...p.metadata } };
1213
+ }
1214
+ export function getDbevogovProfileV2(id) {
1215
+ const p = _dbevogovPsV2.get(id);
1216
+ if (!p) return null;
1217
+ return { ...p, metadata: { ...p.metadata } };
1218
+ }
1219
+ export function listDbevogovProfilesV2() {
1220
+ return [..._dbevogovPsV2.values()].map((p) => ({
1221
+ ...p,
1222
+ metadata: { ...p.metadata },
1223
+ }));
1224
+ }
1225
+ export function createDbevogovMigrationV2({
1226
+ id,
1227
+ profileId,
1228
+ version,
1229
+ metadata,
1230
+ } = {}) {
1231
+ if (!id || !profileId) throw new Error("id and profileId required");
1232
+ if (_dbevogovJsV2.has(id))
1233
+ throw new Error(`dbevogov migration ${id} already exists`);
1234
+ if (!_dbevogovPsV2.has(profileId))
1235
+ throw new Error(`dbevogov profile ${profileId} not found`);
1236
+ if (_dbevogovCountPending(profileId) >= _dbevogovMaxPending)
1237
+ throw new Error(
1238
+ `max pending dbevogov migrations for profile ${profileId} reached`,
1239
+ );
1240
+ const now = Date.now();
1241
+ const j = {
1242
+ id,
1243
+ profileId,
1244
+ version: version || "",
1245
+ status: DBEVOGOV_MIGRATION_LIFECYCLE_V2.QUEUED,
1246
+ createdAt: now,
1247
+ updatedAt: now,
1248
+ startedAt: null,
1249
+ settledAt: null,
1250
+ metadata: { ...(metadata || {}) },
1251
+ };
1252
+ _dbevogovJsV2.set(id, j);
1253
+ return { ...j, metadata: { ...j.metadata } };
1254
+ }
1255
+ export function applyingDbevogovMigrationV2(id) {
1256
+ const j = _dbevogovJsV2.get(id);
1257
+ if (!j) throw new Error(`dbevogov migration ${id} not found`);
1258
+ _dbevogovCheckJ(j.status, DBEVOGOV_MIGRATION_LIFECYCLE_V2.APPLYING);
1259
+ const now = Date.now();
1260
+ j.status = DBEVOGOV_MIGRATION_LIFECYCLE_V2.APPLYING;
1261
+ j.updatedAt = now;
1262
+ if (!j.startedAt) j.startedAt = now;
1263
+ return { ...j, metadata: { ...j.metadata } };
1264
+ }
1265
+ export function completeMigrationDbevogovV2(id) {
1266
+ const j = _dbevogovJsV2.get(id);
1267
+ if (!j) throw new Error(`dbevogov migration ${id} not found`);
1268
+ _dbevogovCheckJ(j.status, DBEVOGOV_MIGRATION_LIFECYCLE_V2.APPLIED);
1269
+ const now = Date.now();
1270
+ j.status = DBEVOGOV_MIGRATION_LIFECYCLE_V2.APPLIED;
1271
+ j.updatedAt = now;
1272
+ if (!j.settledAt) j.settledAt = now;
1273
+ return { ...j, metadata: { ...j.metadata } };
1274
+ }
1275
+ export function failDbevogovMigrationV2(id, reason) {
1276
+ const j = _dbevogovJsV2.get(id);
1277
+ if (!j) throw new Error(`dbevogov migration ${id} not found`);
1278
+ _dbevogovCheckJ(j.status, DBEVOGOV_MIGRATION_LIFECYCLE_V2.FAILED);
1279
+ const now = Date.now();
1280
+ j.status = DBEVOGOV_MIGRATION_LIFECYCLE_V2.FAILED;
1281
+ j.updatedAt = now;
1282
+ if (!j.settledAt) j.settledAt = now;
1283
+ if (reason) j.metadata.failReason = String(reason);
1284
+ return { ...j, metadata: { ...j.metadata } };
1285
+ }
1286
+ export function cancelDbevogovMigrationV2(id, reason) {
1287
+ const j = _dbevogovJsV2.get(id);
1288
+ if (!j) throw new Error(`dbevogov migration ${id} not found`);
1289
+ _dbevogovCheckJ(j.status, DBEVOGOV_MIGRATION_LIFECYCLE_V2.CANCELLED);
1290
+ const now = Date.now();
1291
+ j.status = DBEVOGOV_MIGRATION_LIFECYCLE_V2.CANCELLED;
1292
+ j.updatedAt = now;
1293
+ if (!j.settledAt) j.settledAt = now;
1294
+ if (reason) j.metadata.cancelReason = String(reason);
1295
+ return { ...j, metadata: { ...j.metadata } };
1296
+ }
1297
+ export function getDbevogovMigrationV2(id) {
1298
+ const j = _dbevogovJsV2.get(id);
1299
+ if (!j) return null;
1300
+ return { ...j, metadata: { ...j.metadata } };
1301
+ }
1302
+ export function listDbevogovMigrationsV2() {
1303
+ return [..._dbevogovJsV2.values()].map((j) => ({
1304
+ ...j,
1305
+ metadata: { ...j.metadata },
1306
+ }));
1307
+ }
1308
+ export function autoPauseIdleDbevogovProfilesV2({ now } = {}) {
1309
+ const t = now ?? Date.now();
1310
+ const flipped = [];
1311
+ for (const p of _dbevogovPsV2.values())
1312
+ if (
1313
+ p.status === DBEVOGOV_PROFILE_MATURITY_V2.ACTIVE &&
1314
+ t - p.lastTouchedAt >= _dbevogovIdleMs
1315
+ ) {
1316
+ p.status = DBEVOGOV_PROFILE_MATURITY_V2.PAUSED;
1317
+ p.updatedAt = t;
1318
+ flipped.push(p.id);
1319
+ }
1320
+ return { flipped, count: flipped.length };
1321
+ }
1322
+ export function autoFailStuckDbevogovMigrationsV2({ now } = {}) {
1323
+ const t = now ?? Date.now();
1324
+ const flipped = [];
1325
+ for (const j of _dbevogovJsV2.values())
1326
+ if (
1327
+ j.status === DBEVOGOV_MIGRATION_LIFECYCLE_V2.APPLYING &&
1328
+ j.startedAt != null &&
1329
+ t - j.startedAt >= _dbevogovStuckMs
1330
+ ) {
1331
+ j.status = DBEVOGOV_MIGRATION_LIFECYCLE_V2.FAILED;
1332
+ j.updatedAt = t;
1333
+ if (!j.settledAt) j.settledAt = t;
1334
+ j.metadata.failReason = "auto-fail-stuck";
1335
+ flipped.push(j.id);
1336
+ }
1337
+ return { flipped, count: flipped.length };
1338
+ }
1339
+ export function getDbevoGovStatsV2() {
1340
+ const profilesByStatus = {};
1341
+ for (const v of Object.values(DBEVOGOV_PROFILE_MATURITY_V2))
1342
+ profilesByStatus[v] = 0;
1343
+ for (const p of _dbevogovPsV2.values()) profilesByStatus[p.status]++;
1344
+ const migrationsByStatus = {};
1345
+ for (const v of Object.values(DBEVOGOV_MIGRATION_LIFECYCLE_V2))
1346
+ migrationsByStatus[v] = 0;
1347
+ for (const j of _dbevogovJsV2.values()) migrationsByStatus[j.status]++;
1348
+ return {
1349
+ totalDbevogovProfilesV2: _dbevogovPsV2.size,
1350
+ totalDbevogovMigrationsV2: _dbevogovJsV2.size,
1351
+ maxActiveDbevogovProfilesPerOwner: _dbevogovMaxActive,
1352
+ maxPendingDbevogovMigrationsPerProfile: _dbevogovMaxPending,
1353
+ dbevogovProfileIdleMs: _dbevogovIdleMs,
1354
+ dbevogovMigrationStuckMs: _dbevogovStuckMs,
1355
+ profilesByStatus,
1356
+ migrationsByStatus,
1357
+ };
1358
+ }
@@ -783,3 +783,333 @@ export function _resetStateV2() {
783
783
  _providersV2.clear();
784
784
  _dealsV2.clear();
785
785
  }
786
+
787
+ // =====================================================================
788
+ // decentral-infra V2 governance overlay (iter23)
789
+ // =====================================================================
790
+ export const DIGOV_PROFILE_MATURITY_V2 = Object.freeze({
791
+ PENDING: "pending",
792
+ ACTIVE: "active",
793
+ STALE: "stale",
794
+ ARCHIVED: "archived",
795
+ });
796
+ export const DIGOV_DEAL_LIFECYCLE_V2 = Object.freeze({
797
+ QUEUED: "queued",
798
+ NEGOTIATING: "negotiating",
799
+ SETTLED: "settled",
800
+ FAILED: "failed",
801
+ CANCELLED: "cancelled",
802
+ });
803
+ const _digovPTrans = new Map([
804
+ [
805
+ DIGOV_PROFILE_MATURITY_V2.PENDING,
806
+ new Set([
807
+ DIGOV_PROFILE_MATURITY_V2.ACTIVE,
808
+ DIGOV_PROFILE_MATURITY_V2.ARCHIVED,
809
+ ]),
810
+ ],
811
+ [
812
+ DIGOV_PROFILE_MATURITY_V2.ACTIVE,
813
+ new Set([
814
+ DIGOV_PROFILE_MATURITY_V2.STALE,
815
+ DIGOV_PROFILE_MATURITY_V2.ARCHIVED,
816
+ ]),
817
+ ],
818
+ [
819
+ DIGOV_PROFILE_MATURITY_V2.STALE,
820
+ new Set([
821
+ DIGOV_PROFILE_MATURITY_V2.ACTIVE,
822
+ DIGOV_PROFILE_MATURITY_V2.ARCHIVED,
823
+ ]),
824
+ ],
825
+ [DIGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
826
+ ]);
827
+ const _digovPTerminal = new Set([DIGOV_PROFILE_MATURITY_V2.ARCHIVED]);
828
+ const _digovJTrans = new Map([
829
+ [
830
+ DIGOV_DEAL_LIFECYCLE_V2.QUEUED,
831
+ new Set([
832
+ DIGOV_DEAL_LIFECYCLE_V2.NEGOTIATING,
833
+ DIGOV_DEAL_LIFECYCLE_V2.CANCELLED,
834
+ ]),
835
+ ],
836
+ [
837
+ DIGOV_DEAL_LIFECYCLE_V2.NEGOTIATING,
838
+ new Set([
839
+ DIGOV_DEAL_LIFECYCLE_V2.SETTLED,
840
+ DIGOV_DEAL_LIFECYCLE_V2.FAILED,
841
+ DIGOV_DEAL_LIFECYCLE_V2.CANCELLED,
842
+ ]),
843
+ ],
844
+ [DIGOV_DEAL_LIFECYCLE_V2.SETTLED, new Set()],
845
+ [DIGOV_DEAL_LIFECYCLE_V2.FAILED, new Set()],
846
+ [DIGOV_DEAL_LIFECYCLE_V2.CANCELLED, new Set()],
847
+ ]);
848
+ const _digovPsV2 = new Map();
849
+ const _digovJsV2 = new Map();
850
+ let _digovMaxActive = 6,
851
+ _digovMaxPending = 15,
852
+ _digovIdleMs = 30 * 24 * 60 * 60 * 1000,
853
+ _digovStuckMs = 60 * 1000;
854
+ function _digovPos(n, label) {
855
+ const v = Math.floor(Number(n));
856
+ if (!Number.isFinite(v) || v <= 0)
857
+ throw new Error(`${label} must be positive integer`);
858
+ return v;
859
+ }
860
+ function _digovCheckP(from, to) {
861
+ const a = _digovPTrans.get(from);
862
+ if (!a || !a.has(to))
863
+ throw new Error(`invalid digov profile transition ${from} → ${to}`);
864
+ }
865
+ function _digovCheckJ(from, to) {
866
+ const a = _digovJTrans.get(from);
867
+ if (!a || !a.has(to))
868
+ throw new Error(`invalid digov deal transition ${from} → ${to}`);
869
+ }
870
+ function _digovCountActive(owner) {
871
+ let c = 0;
872
+ for (const p of _digovPsV2.values())
873
+ if (p.owner === owner && p.status === DIGOV_PROFILE_MATURITY_V2.ACTIVE) c++;
874
+ return c;
875
+ }
876
+ function _digovCountPending(profileId) {
877
+ let c = 0;
878
+ for (const j of _digovJsV2.values())
879
+ if (
880
+ j.profileId === profileId &&
881
+ (j.status === DIGOV_DEAL_LIFECYCLE_V2.QUEUED ||
882
+ j.status === DIGOV_DEAL_LIFECYCLE_V2.NEGOTIATING)
883
+ )
884
+ c++;
885
+ return c;
886
+ }
887
+ export function setMaxActiveDigovProfilesPerOwnerV2(n) {
888
+ _digovMaxActive = _digovPos(n, "maxActiveDigovProfilesPerOwner");
889
+ }
890
+ export function getMaxActiveDigovProfilesPerOwnerV2() {
891
+ return _digovMaxActive;
892
+ }
893
+ export function setMaxPendingDigovDealsPerProfileV2(n) {
894
+ _digovMaxPending = _digovPos(n, "maxPendingDigovDealsPerProfile");
895
+ }
896
+ export function getMaxPendingDigovDealsPerProfileV2() {
897
+ return _digovMaxPending;
898
+ }
899
+ export function setDigovProfileIdleMsV2(n) {
900
+ _digovIdleMs = _digovPos(n, "digovProfileIdleMs");
901
+ }
902
+ export function getDigovProfileIdleMsV2() {
903
+ return _digovIdleMs;
904
+ }
905
+ export function setDigovDealStuckMsV2(n) {
906
+ _digovStuckMs = _digovPos(n, "digovDealStuckMs");
907
+ }
908
+ export function getDigovDealStuckMsV2() {
909
+ return _digovStuckMs;
910
+ }
911
+ export function _resetStateDecentralInfraGovV2() {
912
+ _digovPsV2.clear();
913
+ _digovJsV2.clear();
914
+ _digovMaxActive = 6;
915
+ _digovMaxPending = 15;
916
+ _digovIdleMs = 30 * 24 * 60 * 60 * 1000;
917
+ _digovStuckMs = 60 * 1000;
918
+ }
919
+ export function registerDigovProfileV2({ id, owner, region, metadata } = {}) {
920
+ if (!id || !owner) throw new Error("id and owner required");
921
+ if (_digovPsV2.has(id)) throw new Error(`digov profile ${id} already exists`);
922
+ const now = Date.now();
923
+ const p = {
924
+ id,
925
+ owner,
926
+ region: region || "us-east",
927
+ status: DIGOV_PROFILE_MATURITY_V2.PENDING,
928
+ createdAt: now,
929
+ updatedAt: now,
930
+ lastTouchedAt: now,
931
+ activatedAt: null,
932
+ archivedAt: null,
933
+ metadata: { ...(metadata || {}) },
934
+ };
935
+ _digovPsV2.set(id, p);
936
+ return { ...p, metadata: { ...p.metadata } };
937
+ }
938
+ export function activateDigovProfileV2(id) {
939
+ const p = _digovPsV2.get(id);
940
+ if (!p) throw new Error(`digov profile ${id} not found`);
941
+ const isInitial = p.status === DIGOV_PROFILE_MATURITY_V2.PENDING;
942
+ _digovCheckP(p.status, DIGOV_PROFILE_MATURITY_V2.ACTIVE);
943
+ if (isInitial && _digovCountActive(p.owner) >= _digovMaxActive)
944
+ throw new Error(`max active digov profiles for owner ${p.owner} reached`);
945
+ const now = Date.now();
946
+ p.status = DIGOV_PROFILE_MATURITY_V2.ACTIVE;
947
+ p.updatedAt = now;
948
+ p.lastTouchedAt = now;
949
+ if (!p.activatedAt) p.activatedAt = now;
950
+ return { ...p, metadata: { ...p.metadata } };
951
+ }
952
+ export function staleDigovProfileV2(id) {
953
+ const p = _digovPsV2.get(id);
954
+ if (!p) throw new Error(`digov profile ${id} not found`);
955
+ _digovCheckP(p.status, DIGOV_PROFILE_MATURITY_V2.STALE);
956
+ p.status = DIGOV_PROFILE_MATURITY_V2.STALE;
957
+ p.updatedAt = Date.now();
958
+ return { ...p, metadata: { ...p.metadata } };
959
+ }
960
+ export function archiveDigovProfileV2(id) {
961
+ const p = _digovPsV2.get(id);
962
+ if (!p) throw new Error(`digov profile ${id} not found`);
963
+ _digovCheckP(p.status, DIGOV_PROFILE_MATURITY_V2.ARCHIVED);
964
+ const now = Date.now();
965
+ p.status = DIGOV_PROFILE_MATURITY_V2.ARCHIVED;
966
+ p.updatedAt = now;
967
+ if (!p.archivedAt) p.archivedAt = now;
968
+ return { ...p, metadata: { ...p.metadata } };
969
+ }
970
+ export function touchDigovProfileV2(id) {
971
+ const p = _digovPsV2.get(id);
972
+ if (!p) throw new Error(`digov profile ${id} not found`);
973
+ if (_digovPTerminal.has(p.status))
974
+ throw new Error(`cannot touch terminal digov profile ${id}`);
975
+ const now = Date.now();
976
+ p.lastTouchedAt = now;
977
+ p.updatedAt = now;
978
+ return { ...p, metadata: { ...p.metadata } };
979
+ }
980
+ export function getDigovProfileV2(id) {
981
+ const p = _digovPsV2.get(id);
982
+ if (!p) return null;
983
+ return { ...p, metadata: { ...p.metadata } };
984
+ }
985
+ export function listDigovProfilesV2() {
986
+ return [..._digovPsV2.values()].map((p) => ({
987
+ ...p,
988
+ metadata: { ...p.metadata },
989
+ }));
990
+ }
991
+ export function createDigovDealV2({ id, profileId, provider, metadata } = {}) {
992
+ if (!id || !profileId) throw new Error("id and profileId required");
993
+ if (_digovJsV2.has(id)) throw new Error(`digov deal ${id} already exists`);
994
+ if (!_digovPsV2.has(profileId))
995
+ throw new Error(`digov profile ${profileId} not found`);
996
+ if (_digovCountPending(profileId) >= _digovMaxPending)
997
+ throw new Error(`max pending digov deals for profile ${profileId} reached`);
998
+ const now = Date.now();
999
+ const j = {
1000
+ id,
1001
+ profileId,
1002
+ provider: provider || "",
1003
+ status: DIGOV_DEAL_LIFECYCLE_V2.QUEUED,
1004
+ createdAt: now,
1005
+ updatedAt: now,
1006
+ startedAt: null,
1007
+ settledAt: null,
1008
+ metadata: { ...(metadata || {}) },
1009
+ };
1010
+ _digovJsV2.set(id, j);
1011
+ return { ...j, metadata: { ...j.metadata } };
1012
+ }
1013
+ export function negotiatingDigovDealV2(id) {
1014
+ const j = _digovJsV2.get(id);
1015
+ if (!j) throw new Error(`digov deal ${id} not found`);
1016
+ _digovCheckJ(j.status, DIGOV_DEAL_LIFECYCLE_V2.NEGOTIATING);
1017
+ const now = Date.now();
1018
+ j.status = DIGOV_DEAL_LIFECYCLE_V2.NEGOTIATING;
1019
+ j.updatedAt = now;
1020
+ if (!j.startedAt) j.startedAt = now;
1021
+ return { ...j, metadata: { ...j.metadata } };
1022
+ }
1023
+ export function completeDealDigovV2(id) {
1024
+ const j = _digovJsV2.get(id);
1025
+ if (!j) throw new Error(`digov deal ${id} not found`);
1026
+ _digovCheckJ(j.status, DIGOV_DEAL_LIFECYCLE_V2.SETTLED);
1027
+ const now = Date.now();
1028
+ j.status = DIGOV_DEAL_LIFECYCLE_V2.SETTLED;
1029
+ j.updatedAt = now;
1030
+ if (!j.settledAt) j.settledAt = now;
1031
+ return { ...j, metadata: { ...j.metadata } };
1032
+ }
1033
+ export function failDigovDealV2(id, reason) {
1034
+ const j = _digovJsV2.get(id);
1035
+ if (!j) throw new Error(`digov deal ${id} not found`);
1036
+ _digovCheckJ(j.status, DIGOV_DEAL_LIFECYCLE_V2.FAILED);
1037
+ const now = Date.now();
1038
+ j.status = DIGOV_DEAL_LIFECYCLE_V2.FAILED;
1039
+ j.updatedAt = now;
1040
+ if (!j.settledAt) j.settledAt = now;
1041
+ if (reason) j.metadata.failReason = String(reason);
1042
+ return { ...j, metadata: { ...j.metadata } };
1043
+ }
1044
+ export function cancelDigovDealV2(id, reason) {
1045
+ const j = _digovJsV2.get(id);
1046
+ if (!j) throw new Error(`digov deal ${id} not found`);
1047
+ _digovCheckJ(j.status, DIGOV_DEAL_LIFECYCLE_V2.CANCELLED);
1048
+ const now = Date.now();
1049
+ j.status = DIGOV_DEAL_LIFECYCLE_V2.CANCELLED;
1050
+ j.updatedAt = now;
1051
+ if (!j.settledAt) j.settledAt = now;
1052
+ if (reason) j.metadata.cancelReason = String(reason);
1053
+ return { ...j, metadata: { ...j.metadata } };
1054
+ }
1055
+ export function getDigovDealV2(id) {
1056
+ const j = _digovJsV2.get(id);
1057
+ if (!j) return null;
1058
+ return { ...j, metadata: { ...j.metadata } };
1059
+ }
1060
+ export function listDigovDealsV2() {
1061
+ return [..._digovJsV2.values()].map((j) => ({
1062
+ ...j,
1063
+ metadata: { ...j.metadata },
1064
+ }));
1065
+ }
1066
+ export function autoStaleIdleDigovProfilesV2({ now } = {}) {
1067
+ const t = now ?? Date.now();
1068
+ const flipped = [];
1069
+ for (const p of _digovPsV2.values())
1070
+ if (
1071
+ p.status === DIGOV_PROFILE_MATURITY_V2.ACTIVE &&
1072
+ t - p.lastTouchedAt >= _digovIdleMs
1073
+ ) {
1074
+ p.status = DIGOV_PROFILE_MATURITY_V2.STALE;
1075
+ p.updatedAt = t;
1076
+ flipped.push(p.id);
1077
+ }
1078
+ return { flipped, count: flipped.length };
1079
+ }
1080
+ export function autoFailStuckDigovDealsV2({ now } = {}) {
1081
+ const t = now ?? Date.now();
1082
+ const flipped = [];
1083
+ for (const j of _digovJsV2.values())
1084
+ if (
1085
+ j.status === DIGOV_DEAL_LIFECYCLE_V2.NEGOTIATING &&
1086
+ j.startedAt != null &&
1087
+ t - j.startedAt >= _digovStuckMs
1088
+ ) {
1089
+ j.status = DIGOV_DEAL_LIFECYCLE_V2.FAILED;
1090
+ j.updatedAt = t;
1091
+ if (!j.settledAt) j.settledAt = t;
1092
+ j.metadata.failReason = "auto-fail-stuck";
1093
+ flipped.push(j.id);
1094
+ }
1095
+ return { flipped, count: flipped.length };
1096
+ }
1097
+ export function getDecentralInfraGovStatsV2() {
1098
+ const profilesByStatus = {};
1099
+ for (const v of Object.values(DIGOV_PROFILE_MATURITY_V2))
1100
+ profilesByStatus[v] = 0;
1101
+ for (const p of _digovPsV2.values()) profilesByStatus[p.status]++;
1102
+ const dealsByStatus = {};
1103
+ for (const v of Object.values(DIGOV_DEAL_LIFECYCLE_V2)) dealsByStatus[v] = 0;
1104
+ for (const j of _digovJsV2.values()) dealsByStatus[j.status]++;
1105
+ return {
1106
+ totalDigovProfilesV2: _digovPsV2.size,
1107
+ totalDigovDealsV2: _digovJsV2.size,
1108
+ maxActiveDigovProfilesPerOwner: _digovMaxActive,
1109
+ maxPendingDigovDealsPerProfile: _digovMaxPending,
1110
+ digovProfileIdleMs: _digovIdleMs,
1111
+ digovDealStuckMs: _digovStuckMs,
1112
+ profilesByStatus,
1113
+ dealsByStatus,
1114
+ };
1115
+ }