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
@@ -1013,25 +1013,62 @@ export function getCrossChainStatsV2() {
1013
1013
  };
1014
1014
  }
1015
1015
 
1016
-
1017
1016
  // ===== V2 Surface: Cross-Chain governance overlay (CLI v0.136.0) =====
1018
1017
  export const XCHAIN_CHANNEL_MATURITY_V2 = Object.freeze({
1019
- PENDING: "pending", ACTIVE: "active", PAUSED: "paused", DECOMMISSIONED: "decommissioned",
1018
+ PENDING: "pending",
1019
+ ACTIVE: "active",
1020
+ PAUSED: "paused",
1021
+ DECOMMISSIONED: "decommissioned",
1020
1022
  });
1021
1023
  export const XCHAIN_TRANSFER_LIFECYCLE_V2 = Object.freeze({
1022
- QUEUED: "queued", RELAYING: "relaying", CONFIRMED: "confirmed", FAILED: "failed", CANCELLED: "cancelled",
1024
+ QUEUED: "queued",
1025
+ RELAYING: "relaying",
1026
+ CONFIRMED: "confirmed",
1027
+ FAILED: "failed",
1028
+ CANCELLED: "cancelled",
1023
1029
  });
1024
1030
 
1025
1031
  const _xcChanTrans = new Map([
1026
- [XCHAIN_CHANNEL_MATURITY_V2.PENDING, new Set([XCHAIN_CHANNEL_MATURITY_V2.ACTIVE, XCHAIN_CHANNEL_MATURITY_V2.DECOMMISSIONED])],
1027
- [XCHAIN_CHANNEL_MATURITY_V2.ACTIVE, new Set([XCHAIN_CHANNEL_MATURITY_V2.PAUSED, XCHAIN_CHANNEL_MATURITY_V2.DECOMMISSIONED])],
1028
- [XCHAIN_CHANNEL_MATURITY_V2.PAUSED, new Set([XCHAIN_CHANNEL_MATURITY_V2.ACTIVE, XCHAIN_CHANNEL_MATURITY_V2.DECOMMISSIONED])],
1032
+ [
1033
+ XCHAIN_CHANNEL_MATURITY_V2.PENDING,
1034
+ new Set([
1035
+ XCHAIN_CHANNEL_MATURITY_V2.ACTIVE,
1036
+ XCHAIN_CHANNEL_MATURITY_V2.DECOMMISSIONED,
1037
+ ]),
1038
+ ],
1039
+ [
1040
+ XCHAIN_CHANNEL_MATURITY_V2.ACTIVE,
1041
+ new Set([
1042
+ XCHAIN_CHANNEL_MATURITY_V2.PAUSED,
1043
+ XCHAIN_CHANNEL_MATURITY_V2.DECOMMISSIONED,
1044
+ ]),
1045
+ ],
1046
+ [
1047
+ XCHAIN_CHANNEL_MATURITY_V2.PAUSED,
1048
+ new Set([
1049
+ XCHAIN_CHANNEL_MATURITY_V2.ACTIVE,
1050
+ XCHAIN_CHANNEL_MATURITY_V2.DECOMMISSIONED,
1051
+ ]),
1052
+ ],
1029
1053
  [XCHAIN_CHANNEL_MATURITY_V2.DECOMMISSIONED, new Set()],
1030
1054
  ]);
1031
1055
  const _xcChanTerminal = new Set([XCHAIN_CHANNEL_MATURITY_V2.DECOMMISSIONED]);
1032
1056
  const _xcTxTrans = new Map([
1033
- [XCHAIN_TRANSFER_LIFECYCLE_V2.QUEUED, new Set([XCHAIN_TRANSFER_LIFECYCLE_V2.RELAYING, XCHAIN_TRANSFER_LIFECYCLE_V2.CANCELLED])],
1034
- [XCHAIN_TRANSFER_LIFECYCLE_V2.RELAYING, new Set([XCHAIN_TRANSFER_LIFECYCLE_V2.CONFIRMED, XCHAIN_TRANSFER_LIFECYCLE_V2.FAILED, XCHAIN_TRANSFER_LIFECYCLE_V2.CANCELLED])],
1057
+ [
1058
+ XCHAIN_TRANSFER_LIFECYCLE_V2.QUEUED,
1059
+ new Set([
1060
+ XCHAIN_TRANSFER_LIFECYCLE_V2.RELAYING,
1061
+ XCHAIN_TRANSFER_LIFECYCLE_V2.CANCELLED,
1062
+ ]),
1063
+ ],
1064
+ [
1065
+ XCHAIN_TRANSFER_LIFECYCLE_V2.RELAYING,
1066
+ new Set([
1067
+ XCHAIN_TRANSFER_LIFECYCLE_V2.CONFIRMED,
1068
+ XCHAIN_TRANSFER_LIFECYCLE_V2.FAILED,
1069
+ XCHAIN_TRANSFER_LIFECYCLE_V2.CANCELLED,
1070
+ ]),
1071
+ ],
1035
1072
  [XCHAIN_TRANSFER_LIFECYCLE_V2.CONFIRMED, new Set()],
1036
1073
  [XCHAIN_TRANSFER_LIFECYCLE_V2.FAILED, new Set()],
1037
1074
  [XCHAIN_TRANSFER_LIFECYCLE_V2.CANCELLED, new Set()],
@@ -1044,76 +1081,299 @@ let _xcMaxPendingPerChan = 20;
1044
1081
  let _xcChanIdleMs = 24 * 60 * 60 * 1000;
1045
1082
  let _xcTxStuckMs = 15 * 60 * 1000;
1046
1083
 
1047
- function _xcPos(n, lbl) { const v = Math.floor(Number(n)); if (!Number.isFinite(v) || v <= 0) throw new Error(`${lbl} must be positive integer`); return v; }
1084
+ function _xcPos(n, lbl) {
1085
+ const v = Math.floor(Number(n));
1086
+ if (!Number.isFinite(v) || v <= 0)
1087
+ throw new Error(`${lbl} must be positive integer`);
1088
+ return v;
1089
+ }
1048
1090
 
1049
- export function setMaxActiveXchainChannelsPerOwnerV2(n) { _xcMaxActivePerOwner = _xcPos(n, "maxActiveXchainChannelsPerOwner"); }
1050
- export function getMaxActiveXchainChannelsPerOwnerV2() { return _xcMaxActivePerOwner; }
1051
- export function setMaxPendingXchainTransfersPerChannelV2(n) { _xcMaxPendingPerChan = _xcPos(n, "maxPendingXchainTransfersPerChannel"); }
1052
- export function getMaxPendingXchainTransfersPerChannelV2() { return _xcMaxPendingPerChan; }
1053
- export function setXchainChannelIdleMsV2(n) { _xcChanIdleMs = _xcPos(n, "xchainChannelIdleMs"); }
1054
- export function getXchainChannelIdleMsV2() { return _xcChanIdleMs; }
1055
- export function setXchainTransferStuckMsV2(n) { _xcTxStuckMs = _xcPos(n, "xchainTransferStuckMs"); }
1056
- export function getXchainTransferStuckMsV2() { return _xcTxStuckMs; }
1091
+ export function setMaxActiveXchainChannelsPerOwnerV2(n) {
1092
+ _xcMaxActivePerOwner = _xcPos(n, "maxActiveXchainChannelsPerOwner");
1093
+ }
1094
+ export function getMaxActiveXchainChannelsPerOwnerV2() {
1095
+ return _xcMaxActivePerOwner;
1096
+ }
1097
+ export function setMaxPendingXchainTransfersPerChannelV2(n) {
1098
+ _xcMaxPendingPerChan = _xcPos(n, "maxPendingXchainTransfersPerChannel");
1099
+ }
1100
+ export function getMaxPendingXchainTransfersPerChannelV2() {
1101
+ return _xcMaxPendingPerChan;
1102
+ }
1103
+ export function setXchainChannelIdleMsV2(n) {
1104
+ _xcChanIdleMs = _xcPos(n, "xchainChannelIdleMs");
1105
+ }
1106
+ export function getXchainChannelIdleMsV2() {
1107
+ return _xcChanIdleMs;
1108
+ }
1109
+ export function setXchainTransferStuckMsV2(n) {
1110
+ _xcTxStuckMs = _xcPos(n, "xchainTransferStuckMs");
1111
+ }
1112
+ export function getXchainTransferStuckMsV2() {
1113
+ return _xcTxStuckMs;
1114
+ }
1057
1115
 
1058
1116
  export function _resetStateCrossChainV2() {
1059
- _xcChans.clear(); _xcTxs.clear();
1060
- _xcMaxActivePerOwner = 10; _xcMaxPendingPerChan = 20;
1061
- _xcChanIdleMs = 24 * 60 * 60 * 1000; _xcTxStuckMs = 15 * 60 * 1000;
1117
+ _xcChans.clear();
1118
+ _xcTxs.clear();
1119
+ _xcMaxActivePerOwner = 10;
1120
+ _xcMaxPendingPerChan = 20;
1121
+ _xcChanIdleMs = 24 * 60 * 60 * 1000;
1122
+ _xcTxStuckMs = 15 * 60 * 1000;
1062
1123
  }
1063
1124
 
1064
- export function registerXchainChannelV2({ id, owner, fromChain, toChain, metadata } = {}) {
1125
+ export function registerXchainChannelV2({
1126
+ id,
1127
+ owner,
1128
+ fromChain,
1129
+ toChain,
1130
+ metadata,
1131
+ } = {}) {
1065
1132
  if (!id || typeof id !== "string") throw new Error("id is required");
1066
1133
  if (!owner || typeof owner !== "string") throw new Error("owner is required");
1067
- if (_xcChans.has(id)) throw new Error(`xchain channel ${id} already registered`);
1134
+ if (_xcChans.has(id))
1135
+ throw new Error(`xchain channel ${id} already registered`);
1068
1136
  const now = Date.now();
1069
- const c = { id, owner, fromChain: fromChain || "", toChain: toChain || "", status: XCHAIN_CHANNEL_MATURITY_V2.PENDING, createdAt: now, updatedAt: now, activatedAt: null, decommissionedAt: null, lastTouchedAt: now, metadata: { ...(metadata || {}) } };
1137
+ const c = {
1138
+ id,
1139
+ owner,
1140
+ fromChain: fromChain || "",
1141
+ toChain: toChain || "",
1142
+ status: XCHAIN_CHANNEL_MATURITY_V2.PENDING,
1143
+ createdAt: now,
1144
+ updatedAt: now,
1145
+ activatedAt: null,
1146
+ decommissionedAt: null,
1147
+ lastTouchedAt: now,
1148
+ metadata: { ...(metadata || {}) },
1149
+ };
1070
1150
  _xcChans.set(id, c);
1071
1151
  return { ...c, metadata: { ...c.metadata } };
1072
1152
  }
1073
- function _xcCheckC(from, to) { const a = _xcChanTrans.get(from); if (!a || !a.has(to)) throw new Error(`invalid xchain channel transition ${from} → ${to}`); }
1074
- function _xcCountActive(owner) { let n = 0; for (const c of _xcChans.values()) if (c.owner === owner && c.status === XCHAIN_CHANNEL_MATURITY_V2.ACTIVE) n++; return n; }
1153
+ function _xcCheckC(from, to) {
1154
+ const a = _xcChanTrans.get(from);
1155
+ if (!a || !a.has(to))
1156
+ throw new Error(`invalid xchain channel transition ${from} → ${to}`);
1157
+ }
1158
+ function _xcCountActive(owner) {
1159
+ let n = 0;
1160
+ for (const c of _xcChans.values())
1161
+ if (c.owner === owner && c.status === XCHAIN_CHANNEL_MATURITY_V2.ACTIVE)
1162
+ n++;
1163
+ return n;
1164
+ }
1075
1165
 
1076
1166
  export function activateXchainChannelV2(id) {
1077
- const c = _xcChans.get(id); if (!c) throw new Error(`xchain channel ${id} not found`);
1167
+ const c = _xcChans.get(id);
1168
+ if (!c) throw new Error(`xchain channel ${id} not found`);
1078
1169
  _xcCheckC(c.status, XCHAIN_CHANNEL_MATURITY_V2.ACTIVE);
1079
1170
  const recovery = c.status === XCHAIN_CHANNEL_MATURITY_V2.PAUSED;
1080
- if (!recovery) { const a = _xcCountActive(c.owner); if (a >= _xcMaxActivePerOwner) throw new Error(`max active xchain channels per owner (${_xcMaxActivePerOwner}) reached for ${c.owner}`); }
1081
- const now = Date.now(); c.status = XCHAIN_CHANNEL_MATURITY_V2.ACTIVE; c.updatedAt = now; c.lastTouchedAt = now; if (!c.activatedAt) c.activatedAt = now;
1171
+ if (!recovery) {
1172
+ const a = _xcCountActive(c.owner);
1173
+ if (a >= _xcMaxActivePerOwner)
1174
+ throw new Error(
1175
+ `max active xchain channels per owner (${_xcMaxActivePerOwner}) reached for ${c.owner}`,
1176
+ );
1177
+ }
1178
+ const now = Date.now();
1179
+ c.status = XCHAIN_CHANNEL_MATURITY_V2.ACTIVE;
1180
+ c.updatedAt = now;
1181
+ c.lastTouchedAt = now;
1182
+ if (!c.activatedAt) c.activatedAt = now;
1183
+ return { ...c, metadata: { ...c.metadata } };
1184
+ }
1185
+ export function pauseXchainChannelV2(id) {
1186
+ const c = _xcChans.get(id);
1187
+ if (!c) throw new Error(`xchain channel ${id} not found`);
1188
+ _xcCheckC(c.status, XCHAIN_CHANNEL_MATURITY_V2.PAUSED);
1189
+ c.status = XCHAIN_CHANNEL_MATURITY_V2.PAUSED;
1190
+ c.updatedAt = Date.now();
1191
+ return { ...c, metadata: { ...c.metadata } };
1192
+ }
1193
+ export function decommissionXchainChannelV2(id) {
1194
+ const c = _xcChans.get(id);
1195
+ if (!c) throw new Error(`xchain channel ${id} not found`);
1196
+ _xcCheckC(c.status, XCHAIN_CHANNEL_MATURITY_V2.DECOMMISSIONED);
1197
+ const now = Date.now();
1198
+ c.status = XCHAIN_CHANNEL_MATURITY_V2.DECOMMISSIONED;
1199
+ c.updatedAt = now;
1200
+ if (!c.decommissionedAt) c.decommissionedAt = now;
1201
+ return { ...c, metadata: { ...c.metadata } };
1202
+ }
1203
+ export function touchXchainChannelV2(id) {
1204
+ const c = _xcChans.get(id);
1205
+ if (!c) throw new Error(`xchain channel ${id} not found`);
1206
+ if (_xcChanTerminal.has(c.status))
1207
+ throw new Error(`cannot touch terminal xchain channel ${id}`);
1208
+ const now = Date.now();
1209
+ c.lastTouchedAt = now;
1210
+ c.updatedAt = now;
1211
+ return { ...c, metadata: { ...c.metadata } };
1212
+ }
1213
+ export function getXchainChannelV2(id) {
1214
+ const c = _xcChans.get(id);
1215
+ if (!c) return null;
1082
1216
  return { ...c, metadata: { ...c.metadata } };
1083
1217
  }
1084
- export function pauseXchainChannelV2(id) { const c = _xcChans.get(id); if (!c) throw new Error(`xchain channel ${id} not found`); _xcCheckC(c.status, XCHAIN_CHANNEL_MATURITY_V2.PAUSED); c.status = XCHAIN_CHANNEL_MATURITY_V2.PAUSED; c.updatedAt = Date.now(); return { ...c, metadata: { ...c.metadata } }; }
1085
- export function decommissionXchainChannelV2(id) { const c = _xcChans.get(id); if (!c) throw new Error(`xchain channel ${id} not found`); _xcCheckC(c.status, XCHAIN_CHANNEL_MATURITY_V2.DECOMMISSIONED); const now = Date.now(); c.status = XCHAIN_CHANNEL_MATURITY_V2.DECOMMISSIONED; c.updatedAt = now; if (!c.decommissionedAt) c.decommissionedAt = now; return { ...c, metadata: { ...c.metadata } }; }
1086
- export function touchXchainChannelV2(id) { const c = _xcChans.get(id); if (!c) throw new Error(`xchain channel ${id} not found`); if (_xcChanTerminal.has(c.status)) throw new Error(`cannot touch terminal xchain channel ${id}`); const now = Date.now(); c.lastTouchedAt = now; c.updatedAt = now; return { ...c, metadata: { ...c.metadata } }; }
1087
- export function getXchainChannelV2(id) { const c = _xcChans.get(id); if (!c) return null; return { ...c, metadata: { ...c.metadata } }; }
1088
- export function listXchainChannelsV2() { return [..._xcChans.values()].map((c) => ({ ...c, metadata: { ...c.metadata } })); }
1218
+ export function listXchainChannelsV2() {
1219
+ return [..._xcChans.values()].map((c) => ({
1220
+ ...c,
1221
+ metadata: { ...c.metadata },
1222
+ }));
1223
+ }
1089
1224
 
1090
- function _xcCountPending(cid) { let n = 0; for (const t of _xcTxs.values()) if (t.channelId === cid && (t.status === XCHAIN_TRANSFER_LIFECYCLE_V2.QUEUED || t.status === XCHAIN_TRANSFER_LIFECYCLE_V2.RELAYING)) n++; return n; }
1225
+ function _xcCountPending(cid) {
1226
+ let n = 0;
1227
+ for (const t of _xcTxs.values())
1228
+ if (
1229
+ t.channelId === cid &&
1230
+ (t.status === XCHAIN_TRANSFER_LIFECYCLE_V2.QUEUED ||
1231
+ t.status === XCHAIN_TRANSFER_LIFECYCLE_V2.RELAYING)
1232
+ )
1233
+ n++;
1234
+ return n;
1235
+ }
1091
1236
 
1092
- export function createXchainTransferV2({ id, channelId, amount, metadata } = {}) {
1237
+ export function createXchainTransferV2({
1238
+ id,
1239
+ channelId,
1240
+ amount,
1241
+ metadata,
1242
+ } = {}) {
1093
1243
  if (!id || typeof id !== "string") throw new Error("id is required");
1094
- if (!channelId || typeof channelId !== "string") throw new Error("channelId is required");
1244
+ if (!channelId || typeof channelId !== "string")
1245
+ throw new Error("channelId is required");
1095
1246
  if (_xcTxs.has(id)) throw new Error(`xchain transfer ${id} already exists`);
1096
- if (!_xcChans.has(channelId)) throw new Error(`xchain channel ${channelId} not found`);
1247
+ if (!_xcChans.has(channelId))
1248
+ throw new Error(`xchain channel ${channelId} not found`);
1097
1249
  const pending = _xcCountPending(channelId);
1098
- if (pending >= _xcMaxPendingPerChan) throw new Error(`max pending xchain transfers per channel (${_xcMaxPendingPerChan}) reached for ${channelId}`);
1250
+ if (pending >= _xcMaxPendingPerChan)
1251
+ throw new Error(
1252
+ `max pending xchain transfers per channel (${_xcMaxPendingPerChan}) reached for ${channelId}`,
1253
+ );
1099
1254
  const now = Date.now();
1100
- const t = { id, channelId, amount: amount || "0", status: XCHAIN_TRANSFER_LIFECYCLE_V2.QUEUED, createdAt: now, updatedAt: now, startedAt: null, settledAt: null, metadata: { ...(metadata || {}) } };
1255
+ const t = {
1256
+ id,
1257
+ channelId,
1258
+ amount: amount || "0",
1259
+ status: XCHAIN_TRANSFER_LIFECYCLE_V2.QUEUED,
1260
+ createdAt: now,
1261
+ updatedAt: now,
1262
+ startedAt: null,
1263
+ settledAt: null,
1264
+ metadata: { ...(metadata || {}) },
1265
+ };
1101
1266
  _xcTxs.set(id, t);
1102
1267
  return { ...t, metadata: { ...t.metadata } };
1103
1268
  }
1104
- function _xcCheckT(from, to) { const a = _xcTxTrans.get(from); if (!a || !a.has(to)) throw new Error(`invalid xchain transfer transition ${from} → ${to}`); }
1105
- export function startXchainTransferV2(id) { const t = _xcTxs.get(id); if (!t) throw new Error(`xchain transfer ${id} not found`); _xcCheckT(t.status, XCHAIN_TRANSFER_LIFECYCLE_V2.RELAYING); const now = Date.now(); t.status = XCHAIN_TRANSFER_LIFECYCLE_V2.RELAYING; t.updatedAt = now; if (!t.startedAt) t.startedAt = now; return { ...t, metadata: { ...t.metadata } }; }
1106
- export function confirmXchainTransferV2(id) { const t = _xcTxs.get(id); if (!t) throw new Error(`xchain transfer ${id} not found`); _xcCheckT(t.status, XCHAIN_TRANSFER_LIFECYCLE_V2.CONFIRMED); const now = Date.now(); t.status = XCHAIN_TRANSFER_LIFECYCLE_V2.CONFIRMED; t.updatedAt = now; if (!t.settledAt) t.settledAt = now; return { ...t, metadata: { ...t.metadata } }; }
1107
- export function failXchainTransferV2(id, reason) { const t = _xcTxs.get(id); if (!t) throw new Error(`xchain transfer ${id} not found`); _xcCheckT(t.status, XCHAIN_TRANSFER_LIFECYCLE_V2.FAILED); const now = Date.now(); t.status = XCHAIN_TRANSFER_LIFECYCLE_V2.FAILED; t.updatedAt = now; if (!t.settledAt) t.settledAt = now; if (reason) t.metadata.failReason = String(reason); return { ...t, metadata: { ...t.metadata } }; }
1108
- export function cancelXchainTransferV2(id, reason) { const t = _xcTxs.get(id); if (!t) throw new Error(`xchain transfer ${id} not found`); _xcCheckT(t.status, XCHAIN_TRANSFER_LIFECYCLE_V2.CANCELLED); const now = Date.now(); t.status = XCHAIN_TRANSFER_LIFECYCLE_V2.CANCELLED; t.updatedAt = now; if (!t.settledAt) t.settledAt = now; if (reason) t.metadata.cancelReason = String(reason); return { ...t, metadata: { ...t.metadata } }; }
1109
- export function getXchainTransferV2(id) { const t = _xcTxs.get(id); if (!t) return null; return { ...t, metadata: { ...t.metadata } }; }
1110
- export function listXchainTransfersV2() { return [..._xcTxs.values()].map((t) => ({ ...t, metadata: { ...t.metadata } })); }
1269
+ function _xcCheckT(from, to) {
1270
+ const a = _xcTxTrans.get(from);
1271
+ if (!a || !a.has(to))
1272
+ throw new Error(`invalid xchain transfer transition ${from} ${to}`);
1273
+ }
1274
+ export function startXchainTransferV2(id) {
1275
+ const t = _xcTxs.get(id);
1276
+ if (!t) throw new Error(`xchain transfer ${id} not found`);
1277
+ _xcCheckT(t.status, XCHAIN_TRANSFER_LIFECYCLE_V2.RELAYING);
1278
+ const now = Date.now();
1279
+ t.status = XCHAIN_TRANSFER_LIFECYCLE_V2.RELAYING;
1280
+ t.updatedAt = now;
1281
+ if (!t.startedAt) t.startedAt = now;
1282
+ return { ...t, metadata: { ...t.metadata } };
1283
+ }
1284
+ export function confirmXchainTransferV2(id) {
1285
+ const t = _xcTxs.get(id);
1286
+ if (!t) throw new Error(`xchain transfer ${id} not found`);
1287
+ _xcCheckT(t.status, XCHAIN_TRANSFER_LIFECYCLE_V2.CONFIRMED);
1288
+ const now = Date.now();
1289
+ t.status = XCHAIN_TRANSFER_LIFECYCLE_V2.CONFIRMED;
1290
+ t.updatedAt = now;
1291
+ if (!t.settledAt) t.settledAt = now;
1292
+ return { ...t, metadata: { ...t.metadata } };
1293
+ }
1294
+ export function failXchainTransferV2(id, reason) {
1295
+ const t = _xcTxs.get(id);
1296
+ if (!t) throw new Error(`xchain transfer ${id} not found`);
1297
+ _xcCheckT(t.status, XCHAIN_TRANSFER_LIFECYCLE_V2.FAILED);
1298
+ const now = Date.now();
1299
+ t.status = XCHAIN_TRANSFER_LIFECYCLE_V2.FAILED;
1300
+ t.updatedAt = now;
1301
+ if (!t.settledAt) t.settledAt = now;
1302
+ if (reason) t.metadata.failReason = String(reason);
1303
+ return { ...t, metadata: { ...t.metadata } };
1304
+ }
1305
+ export function cancelXchainTransferV2(id, reason) {
1306
+ const t = _xcTxs.get(id);
1307
+ if (!t) throw new Error(`xchain transfer ${id} not found`);
1308
+ _xcCheckT(t.status, XCHAIN_TRANSFER_LIFECYCLE_V2.CANCELLED);
1309
+ const now = Date.now();
1310
+ t.status = XCHAIN_TRANSFER_LIFECYCLE_V2.CANCELLED;
1311
+ t.updatedAt = now;
1312
+ if (!t.settledAt) t.settledAt = now;
1313
+ if (reason) t.metadata.cancelReason = String(reason);
1314
+ return { ...t, metadata: { ...t.metadata } };
1315
+ }
1316
+ export function getXchainTransferV2(id) {
1317
+ const t = _xcTxs.get(id);
1318
+ if (!t) return null;
1319
+ return { ...t, metadata: { ...t.metadata } };
1320
+ }
1321
+ export function listXchainTransfersV2() {
1322
+ return [..._xcTxs.values()].map((t) => ({
1323
+ ...t,
1324
+ metadata: { ...t.metadata },
1325
+ }));
1326
+ }
1111
1327
 
1112
- export function autoPauseIdleXchainChannelsV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const c of _xcChans.values()) if (c.status === XCHAIN_CHANNEL_MATURITY_V2.ACTIVE && (t - c.lastTouchedAt) >= _xcChanIdleMs) { c.status = XCHAIN_CHANNEL_MATURITY_V2.PAUSED; c.updatedAt = t; flipped.push(c.id); } return { flipped, count: flipped.length }; }
1113
- export function autoFailStuckXchainTransfersV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const tx of _xcTxs.values()) if (tx.status === XCHAIN_TRANSFER_LIFECYCLE_V2.RELAYING && tx.startedAt != null && (t - tx.startedAt) >= _xcTxStuckMs) { tx.status = XCHAIN_TRANSFER_LIFECYCLE_V2.FAILED; tx.updatedAt = t; if (!tx.settledAt) tx.settledAt = t; tx.metadata.failReason = "auto-fail-stuck"; flipped.push(tx.id); } return { flipped, count: flipped.length }; }
1328
+ export function autoPauseIdleXchainChannelsV2({ now } = {}) {
1329
+ const t = now ?? Date.now();
1330
+ const flipped = [];
1331
+ for (const c of _xcChans.values())
1332
+ if (
1333
+ c.status === XCHAIN_CHANNEL_MATURITY_V2.ACTIVE &&
1334
+ t - c.lastTouchedAt >= _xcChanIdleMs
1335
+ ) {
1336
+ c.status = XCHAIN_CHANNEL_MATURITY_V2.PAUSED;
1337
+ c.updatedAt = t;
1338
+ flipped.push(c.id);
1339
+ }
1340
+ return { flipped, count: flipped.length };
1341
+ }
1342
+ export function autoFailStuckXchainTransfersV2({ now } = {}) {
1343
+ const t = now ?? Date.now();
1344
+ const flipped = [];
1345
+ for (const tx of _xcTxs.values())
1346
+ if (
1347
+ tx.status === XCHAIN_TRANSFER_LIFECYCLE_V2.RELAYING &&
1348
+ tx.startedAt != null &&
1349
+ t - tx.startedAt >= _xcTxStuckMs
1350
+ ) {
1351
+ tx.status = XCHAIN_TRANSFER_LIFECYCLE_V2.FAILED;
1352
+ tx.updatedAt = t;
1353
+ if (!tx.settledAt) tx.settledAt = t;
1354
+ tx.metadata.failReason = "auto-fail-stuck";
1355
+ flipped.push(tx.id);
1356
+ }
1357
+ return { flipped, count: flipped.length };
1358
+ }
1114
1359
 
1115
1360
  export function getCrossChainGovStatsV2() {
1116
- const channelsByStatus = {}; for (const s of Object.values(XCHAIN_CHANNEL_MATURITY_V2)) channelsByStatus[s] = 0; for (const c of _xcChans.values()) channelsByStatus[c.status]++;
1117
- const transfersByStatus = {}; for (const s of Object.values(XCHAIN_TRANSFER_LIFECYCLE_V2)) transfersByStatus[s] = 0; for (const t of _xcTxs.values()) transfersByStatus[t.status]++;
1118
- return { totalChannelsV2: _xcChans.size, totalTransfersV2: _xcTxs.size, maxActiveXchainChannelsPerOwner: _xcMaxActivePerOwner, maxPendingXchainTransfersPerChannel: _xcMaxPendingPerChan, xchainChannelIdleMs: _xcChanIdleMs, xchainTransferStuckMs: _xcTxStuckMs, channelsByStatus, transfersByStatus };
1361
+ const channelsByStatus = {};
1362
+ for (const s of Object.values(XCHAIN_CHANNEL_MATURITY_V2))
1363
+ channelsByStatus[s] = 0;
1364
+ for (const c of _xcChans.values()) channelsByStatus[c.status]++;
1365
+ const transfersByStatus = {};
1366
+ for (const s of Object.values(XCHAIN_TRANSFER_LIFECYCLE_V2))
1367
+ transfersByStatus[s] = 0;
1368
+ for (const t of _xcTxs.values()) transfersByStatus[t.status]++;
1369
+ return {
1370
+ totalChannelsV2: _xcChans.size,
1371
+ totalTransfersV2: _xcTxs.size,
1372
+ maxActiveXchainChannelsPerOwner: _xcMaxActivePerOwner,
1373
+ maxPendingXchainTransfersPerChannel: _xcMaxPendingPerChan,
1374
+ xchainChannelIdleMs: _xcChanIdleMs,
1375
+ xchainTransferStuckMs: _xcTxStuckMs,
1376
+ channelsByStatus,
1377
+ transfersByStatus,
1378
+ };
1119
1379
  }