chainlesschain 0.132.0 → 0.145.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 (135) hide show
  1. package/package.json +1 -1
  2. package/src/commands/a2a.js +230 -0
  3. package/src/commands/activitypub.js +191 -0
  4. package/src/commands/agent.js +601 -0
  5. package/src/commands/audit.js +206 -0
  6. package/src/commands/bi.js +186 -0
  7. package/src/commands/bm25.js +162 -0
  8. package/src/commands/browse.js +225 -0
  9. package/src/commands/ccron.js +178 -0
  10. package/src/commands/chat.js +207 -0
  11. package/src/commands/compliance.js +420 -0
  12. package/src/commands/compt.js +176 -0
  13. package/src/commands/consol.js +237 -0
  14. package/src/commands/cowork.js +588 -0
  15. package/src/commands/crosschain.js +216 -0
  16. package/src/commands/dao.js +216 -0
  17. package/src/commands/dlp.js +206 -0
  18. package/src/commands/economy.js +211 -0
  19. package/src/commands/evolution.js +209 -0
  20. package/src/commands/evomap.js +216 -0
  21. package/src/commands/fflag.js +230 -0
  22. package/src/commands/git.js +185 -0
  23. package/src/commands/hardening.js +209 -0
  24. package/src/commands/hmemory.js +210 -0
  25. package/src/commands/incentive.js +209 -0
  26. package/src/commands/inference.js +178 -0
  27. package/src/commands/itbudget.js +161 -0
  28. package/src/commands/kg.js +206 -0
  29. package/src/commands/lowcode.js +201 -0
  30. package/src/commands/marketplace.js +206 -0
  31. package/src/commands/matrix.js +214 -0
  32. package/src/commands/mcpscaf.js +153 -0
  33. package/src/commands/meminj.js +153 -0
  34. package/src/commands/nostr.js +213 -0
  35. package/src/commands/orchestrate.js +217 -0
  36. package/src/commands/orchgov.js +156 -0
  37. package/src/commands/pdfp.js +160 -0
  38. package/src/commands/perf.js +176 -0
  39. package/src/commands/perm.js +156 -0
  40. package/src/commands/pipeline.js +211 -0
  41. package/src/commands/planmode.js +154 -0
  42. package/src/commands/privacy.js +203 -0
  43. package/src/commands/promcomp.js +166 -0
  44. package/src/commands/recommend.js +185 -0
  45. package/src/commands/reputation.js +208 -0
  46. package/src/commands/sandbox.js +206 -0
  47. package/src/commands/seshhook.js +153 -0
  48. package/src/commands/seshsearch.js +149 -0
  49. package/src/commands/seshtail.js +152 -0
  50. package/src/commands/seshu.js +160 -0
  51. package/src/commands/sganal.js +172 -0
  52. package/src/commands/siem.js +207 -0
  53. package/src/commands/sla.js +212 -0
  54. package/src/commands/slotfill.js +154 -0
  55. package/src/commands/social.js +159 -0
  56. package/src/commands/stress.js +206 -0
  57. package/src/commands/svccont.js +157 -0
  58. package/src/commands/terraform.js +206 -0
  59. package/src/commands/tms.js +183 -0
  60. package/src/commands/topiccls.js +158 -0
  61. package/src/commands/uprof.js +154 -0
  62. package/src/commands/vcheck.js +172 -0
  63. package/src/commands/webfetch.js +150 -0
  64. package/src/commands/zkp.js +218 -0
  65. package/src/harness/prompt-compressor.js +331 -0
  66. package/src/index.js +101 -1
  67. package/src/lib/a2a-protocol.js +373 -0
  68. package/src/lib/activitypub-bridge.js +343 -0
  69. package/src/lib/agent-economy.js +358 -0
  70. package/src/lib/app-builder.js +338 -0
  71. package/src/lib/audit-logger.js +321 -0
  72. package/src/lib/autonomous-agent.js +341 -0
  73. package/src/lib/bi-engine.js +339 -0
  74. package/src/lib/bm25-search.js +333 -0
  75. package/src/lib/browser-automation.js +352 -0
  76. package/src/lib/chat-core.js +336 -0
  77. package/src/lib/claude-code-bridge.js +341 -0
  78. package/src/lib/compliance-framework-reporter.js +359 -0
  79. package/src/lib/compliance-manager.js +330 -0
  80. package/src/lib/compression-telemetry.js +333 -0
  81. package/src/lib/content-recommender.js +370 -0
  82. package/src/lib/cowork-cron.js +330 -0
  83. package/src/lib/cowork-learning.js +333 -0
  84. package/src/lib/cowork-task-runner.js +362 -0
  85. package/src/lib/cowork-workflow.js +327 -0
  86. package/src/lib/cross-chain.js +365 -0
  87. package/src/lib/dao-governance.js +339 -0
  88. package/src/lib/dlp-engine.js +343 -0
  89. package/src/lib/evolution-system.js +336 -0
  90. package/src/lib/evomap-manager.js +339 -0
  91. package/src/lib/execution-backend.js +351 -0
  92. package/src/lib/feature-flags.js +330 -0
  93. package/src/lib/git-integration.js +343 -0
  94. package/src/lib/hardening-manager.js +341 -0
  95. package/src/lib/hierarchical-memory.js +341 -0
  96. package/src/lib/inference-network.js +362 -0
  97. package/src/lib/iteration-budget.js +357 -0
  98. package/src/lib/knowledge-graph.js +333 -0
  99. package/src/lib/matrix-bridge.js +339 -0
  100. package/src/lib/mcp-scaffold.js +345 -0
  101. package/src/lib/memory-injection.js +320 -0
  102. package/src/lib/nostr-bridge.js +342 -0
  103. package/src/lib/orchestrator.js +350 -0
  104. package/src/lib/pdf-parser.js +330 -0
  105. package/src/lib/perf-tuning.js +364 -0
  106. package/src/lib/permission-engine.js +319 -0
  107. package/src/lib/pipeline-orchestrator.js +345 -0
  108. package/src/lib/plan-mode.js +328 -0
  109. package/src/lib/privacy-computing.js +335 -0
  110. package/src/lib/prompt-compressor.js +1 -10
  111. package/src/lib/reputation-optimizer.js +340 -0
  112. package/src/lib/sandbox-v2.js +327 -0
  113. package/src/lib/service-container.js +342 -0
  114. package/src/lib/session-consolidator.js +352 -0
  115. package/src/lib/session-hooks.js +340 -0
  116. package/src/lib/session-search.js +334 -0
  117. package/src/lib/session-tail.js +320 -0
  118. package/src/lib/session-usage.js +329 -0
  119. package/src/lib/siem-exporter.js +352 -0
  120. package/src/lib/skill-marketplace.js +345 -0
  121. package/src/lib/sla-manager.js +341 -0
  122. package/src/lib/slot-filler.js +333 -0
  123. package/src/lib/social-graph-analytics.js +327 -0
  124. package/src/lib/social-graph.js +304 -0
  125. package/src/lib/stress-tester.js +342 -0
  126. package/src/lib/sub-agent-registry.js +359 -0
  127. package/src/lib/task-model-selector.js +333 -0
  128. package/src/lib/terraform-manager.js +333 -0
  129. package/src/lib/todo-manager.js +339 -0
  130. package/src/lib/token-incentive.js +341 -0
  131. package/src/lib/topic-classifier.js +353 -0
  132. package/src/lib/user-profile.js +325 -0
  133. package/src/lib/version-checker.js +335 -0
  134. package/src/lib/web-fetch.js +322 -0
  135. package/src/lib/zkp-engine.js +342 -0
@@ -1012,3 +1012,368 @@ export function getCrossChainStatsV2() {
1012
1012
  configuredChains: _chainConfigs.size,
1013
1013
  };
1014
1014
  }
1015
+
1016
+ // ===== V2 Surface: Cross-Chain governance overlay (CLI v0.136.0) =====
1017
+ export const XCHAIN_CHANNEL_MATURITY_V2 = Object.freeze({
1018
+ PENDING: "pending",
1019
+ ACTIVE: "active",
1020
+ PAUSED: "paused",
1021
+ DECOMMISSIONED: "decommissioned",
1022
+ });
1023
+ export const XCHAIN_TRANSFER_LIFECYCLE_V2 = Object.freeze({
1024
+ QUEUED: "queued",
1025
+ RELAYING: "relaying",
1026
+ CONFIRMED: "confirmed",
1027
+ FAILED: "failed",
1028
+ CANCELLED: "cancelled",
1029
+ });
1030
+
1031
+ const _xcChanTrans = new Map([
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
+ ],
1053
+ [XCHAIN_CHANNEL_MATURITY_V2.DECOMMISSIONED, new Set()],
1054
+ ]);
1055
+ const _xcChanTerminal = new Set([XCHAIN_CHANNEL_MATURITY_V2.DECOMMISSIONED]);
1056
+ const _xcTxTrans = new Map([
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
+ ],
1072
+ [XCHAIN_TRANSFER_LIFECYCLE_V2.CONFIRMED, new Set()],
1073
+ [XCHAIN_TRANSFER_LIFECYCLE_V2.FAILED, new Set()],
1074
+ [XCHAIN_TRANSFER_LIFECYCLE_V2.CANCELLED, new Set()],
1075
+ ]);
1076
+
1077
+ const _xcChans = new Map();
1078
+ const _xcTxs = new Map();
1079
+ let _xcMaxActivePerOwner = 10;
1080
+ let _xcMaxPendingPerChan = 20;
1081
+ let _xcChanIdleMs = 24 * 60 * 60 * 1000;
1082
+ let _xcTxStuckMs = 15 * 60 * 1000;
1083
+
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
+ }
1090
+
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
+ }
1115
+
1116
+ export function _resetStateCrossChainV2() {
1117
+ _xcChans.clear();
1118
+ _xcTxs.clear();
1119
+ _xcMaxActivePerOwner = 10;
1120
+ _xcMaxPendingPerChan = 20;
1121
+ _xcChanIdleMs = 24 * 60 * 60 * 1000;
1122
+ _xcTxStuckMs = 15 * 60 * 1000;
1123
+ }
1124
+
1125
+ export function registerXchainChannelV2({
1126
+ id,
1127
+ owner,
1128
+ fromChain,
1129
+ toChain,
1130
+ metadata,
1131
+ } = {}) {
1132
+ if (!id || typeof id !== "string") throw new Error("id is required");
1133
+ if (!owner || typeof owner !== "string") throw new Error("owner is required");
1134
+ if (_xcChans.has(id))
1135
+ throw new Error(`xchain channel ${id} already registered`);
1136
+ const now = Date.now();
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
+ };
1150
+ _xcChans.set(id, c);
1151
+ return { ...c, metadata: { ...c.metadata } };
1152
+ }
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
+ }
1165
+
1166
+ export function activateXchainChannelV2(id) {
1167
+ const c = _xcChans.get(id);
1168
+ if (!c) throw new Error(`xchain channel ${id} not found`);
1169
+ _xcCheckC(c.status, XCHAIN_CHANNEL_MATURITY_V2.ACTIVE);
1170
+ const recovery = c.status === XCHAIN_CHANNEL_MATURITY_V2.PAUSED;
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;
1216
+ return { ...c, metadata: { ...c.metadata } };
1217
+ }
1218
+ export function listXchainChannelsV2() {
1219
+ return [..._xcChans.values()].map((c) => ({
1220
+ ...c,
1221
+ metadata: { ...c.metadata },
1222
+ }));
1223
+ }
1224
+
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
+ }
1236
+
1237
+ export function createXchainTransferV2({
1238
+ id,
1239
+ channelId,
1240
+ amount,
1241
+ metadata,
1242
+ } = {}) {
1243
+ if (!id || typeof id !== "string") throw new Error("id is required");
1244
+ if (!channelId || typeof channelId !== "string")
1245
+ throw new Error("channelId is required");
1246
+ if (_xcTxs.has(id)) throw new Error(`xchain transfer ${id} already exists`);
1247
+ if (!_xcChans.has(channelId))
1248
+ throw new Error(`xchain channel ${channelId} not found`);
1249
+ const pending = _xcCountPending(channelId);
1250
+ if (pending >= _xcMaxPendingPerChan)
1251
+ throw new Error(
1252
+ `max pending xchain transfers per channel (${_xcMaxPendingPerChan}) reached for ${channelId}`,
1253
+ );
1254
+ const now = Date.now();
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
+ };
1266
+ _xcTxs.set(id, t);
1267
+ return { ...t, metadata: { ...t.metadata } };
1268
+ }
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
+ }
1327
+
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
+ }
1359
+
1360
+ export function getCrossChainGovStatsV2() {
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
+ };
1379
+ }
@@ -863,3 +863,342 @@ export function _resetState() {
863
863
  maxSingleAllocation: 100000,
864
864
  };
865
865
  }
866
+
867
+ // ===== V2 Surface: DAO Governance overlay (CLI v0.136.0) =====
868
+ export const DAO_ORG_MATURITY_V2 = Object.freeze({
869
+ PENDING: "pending",
870
+ ACTIVE: "active",
871
+ PAUSED: "paused",
872
+ DISSOLVED: "dissolved",
873
+ });
874
+ export const DAO_PROPOSAL_LIFECYCLE_V2 = Object.freeze({
875
+ QUEUED: "queued",
876
+ VOTING: "voting",
877
+ PASSED: "passed",
878
+ FAILED: "failed",
879
+ CANCELLED: "cancelled",
880
+ });
881
+
882
+ const _daoOrgTrans = new Map([
883
+ [
884
+ DAO_ORG_MATURITY_V2.PENDING,
885
+ new Set([DAO_ORG_MATURITY_V2.ACTIVE, DAO_ORG_MATURITY_V2.DISSOLVED]),
886
+ ],
887
+ [
888
+ DAO_ORG_MATURITY_V2.ACTIVE,
889
+ new Set([DAO_ORG_MATURITY_V2.PAUSED, DAO_ORG_MATURITY_V2.DISSOLVED]),
890
+ ],
891
+ [
892
+ DAO_ORG_MATURITY_V2.PAUSED,
893
+ new Set([DAO_ORG_MATURITY_V2.ACTIVE, DAO_ORG_MATURITY_V2.DISSOLVED]),
894
+ ],
895
+ [DAO_ORG_MATURITY_V2.DISSOLVED, new Set()],
896
+ ]);
897
+ const _daoOrgTerminal = new Set([DAO_ORG_MATURITY_V2.DISSOLVED]);
898
+ const _daoPropTrans = new Map([
899
+ [
900
+ DAO_PROPOSAL_LIFECYCLE_V2.QUEUED,
901
+ new Set([
902
+ DAO_PROPOSAL_LIFECYCLE_V2.VOTING,
903
+ DAO_PROPOSAL_LIFECYCLE_V2.CANCELLED,
904
+ ]),
905
+ ],
906
+ [
907
+ DAO_PROPOSAL_LIFECYCLE_V2.VOTING,
908
+ new Set([
909
+ DAO_PROPOSAL_LIFECYCLE_V2.PASSED,
910
+ DAO_PROPOSAL_LIFECYCLE_V2.FAILED,
911
+ DAO_PROPOSAL_LIFECYCLE_V2.CANCELLED,
912
+ ]),
913
+ ],
914
+ [DAO_PROPOSAL_LIFECYCLE_V2.PASSED, new Set()],
915
+ [DAO_PROPOSAL_LIFECYCLE_V2.FAILED, new Set()],
916
+ [DAO_PROPOSAL_LIFECYCLE_V2.CANCELLED, new Set()],
917
+ ]);
918
+
919
+ const _daoOrgs = new Map();
920
+ const _daoProps = new Map();
921
+ let _daoMaxActivePerOwner = 8;
922
+ let _daoMaxPendingPerOrg = 50;
923
+ let _daoOrgIdleMs = 7 * 24 * 60 * 60 * 1000;
924
+ let _daoPropStuckMs = 2 * 60 * 1000;
925
+
926
+ function _daoPos(n, lbl) {
927
+ const v = Math.floor(Number(n));
928
+ if (!Number.isFinite(v) || v <= 0)
929
+ throw new Error(`${lbl} must be positive integer`);
930
+ return v;
931
+ }
932
+
933
+ export function setMaxActiveDaoOrgsPerOwnerV2(n) {
934
+ _daoMaxActivePerOwner = _daoPos(n, "maxActiveDaoOrgsPerOwner");
935
+ }
936
+ export function getMaxActiveDaoOrgsPerOwnerV2() {
937
+ return _daoMaxActivePerOwner;
938
+ }
939
+ export function setMaxPendingDaoProposalsPerOrgV2(n) {
940
+ _daoMaxPendingPerOrg = _daoPos(n, "maxPendingDaoProposalsPerOrg");
941
+ }
942
+ export function getMaxPendingDaoProposalsPerOrgV2() {
943
+ return _daoMaxPendingPerOrg;
944
+ }
945
+ export function setDaoOrgIdleMsV2(n) {
946
+ _daoOrgIdleMs = _daoPos(n, "daoOrgIdleMs");
947
+ }
948
+ export function getDaoOrgIdleMsV2() {
949
+ return _daoOrgIdleMs;
950
+ }
951
+ export function setDaoProposalStuckMsV2(n) {
952
+ _daoPropStuckMs = _daoPos(n, "daoProposalStuckMs");
953
+ }
954
+ export function getDaoProposalStuckMsV2() {
955
+ return _daoPropStuckMs;
956
+ }
957
+
958
+ export function _resetStateDaoGovernanceV2() {
959
+ _daoOrgs.clear();
960
+ _daoProps.clear();
961
+ _daoMaxActivePerOwner = 8;
962
+ _daoMaxPendingPerOrg = 50;
963
+ _daoOrgIdleMs = 7 * 24 * 60 * 60 * 1000;
964
+ _daoPropStuckMs = 2 * 60 * 1000;
965
+ }
966
+
967
+ export function registerDaoOrgV2({ id, owner, name, metadata } = {}) {
968
+ if (!id || typeof id !== "string") throw new Error("id is required");
969
+ if (!owner || typeof owner !== "string") throw new Error("owner is required");
970
+ if (_daoOrgs.has(id)) throw new Error(`dao org ${id} already registered`);
971
+ const now = Date.now();
972
+ const o = {
973
+ id,
974
+ owner,
975
+ name: name || id,
976
+ status: DAO_ORG_MATURITY_V2.PENDING,
977
+ createdAt: now,
978
+ updatedAt: now,
979
+ activatedAt: null,
980
+ dissolvedAt: null,
981
+ lastTouchedAt: now,
982
+ metadata: { ...(metadata || {}) },
983
+ };
984
+ _daoOrgs.set(id, o);
985
+ return { ...o, metadata: { ...o.metadata } };
986
+ }
987
+ function _daoCheckO(from, to) {
988
+ const a = _daoOrgTrans.get(from);
989
+ if (!a || !a.has(to))
990
+ throw new Error(`invalid dao org transition ${from} → ${to}`);
991
+ }
992
+ function _daoCountActive(owner) {
993
+ let n = 0;
994
+ for (const o of _daoOrgs.values())
995
+ if (o.owner === owner && o.status === DAO_ORG_MATURITY_V2.ACTIVE) n++;
996
+ return n;
997
+ }
998
+
999
+ export function activateDaoOrgV2(id) {
1000
+ const o = _daoOrgs.get(id);
1001
+ if (!o) throw new Error(`dao org ${id} not found`);
1002
+ _daoCheckO(o.status, DAO_ORG_MATURITY_V2.ACTIVE);
1003
+ const recovery = o.status === DAO_ORG_MATURITY_V2.PAUSED;
1004
+ if (!recovery) {
1005
+ const a = _daoCountActive(o.owner);
1006
+ if (a >= _daoMaxActivePerOwner)
1007
+ throw new Error(
1008
+ `max active dao orgs per owner (${_daoMaxActivePerOwner}) reached for ${o.owner}`,
1009
+ );
1010
+ }
1011
+ const now = Date.now();
1012
+ o.status = DAO_ORG_MATURITY_V2.ACTIVE;
1013
+ o.updatedAt = now;
1014
+ o.lastTouchedAt = now;
1015
+ if (!o.activatedAt) o.activatedAt = now;
1016
+ return { ...o, metadata: { ...o.metadata } };
1017
+ }
1018
+ export function pauseDaoOrgV2(id) {
1019
+ const o = _daoOrgs.get(id);
1020
+ if (!o) throw new Error(`dao org ${id} not found`);
1021
+ _daoCheckO(o.status, DAO_ORG_MATURITY_V2.PAUSED);
1022
+ o.status = DAO_ORG_MATURITY_V2.PAUSED;
1023
+ o.updatedAt = Date.now();
1024
+ return { ...o, metadata: { ...o.metadata } };
1025
+ }
1026
+ export function dissolveDaoOrgV2(id) {
1027
+ const o = _daoOrgs.get(id);
1028
+ if (!o) throw new Error(`dao org ${id} not found`);
1029
+ _daoCheckO(o.status, DAO_ORG_MATURITY_V2.DISSOLVED);
1030
+ const now = Date.now();
1031
+ o.status = DAO_ORG_MATURITY_V2.DISSOLVED;
1032
+ o.updatedAt = now;
1033
+ if (!o.dissolvedAt) o.dissolvedAt = now;
1034
+ return { ...o, metadata: { ...o.metadata } };
1035
+ }
1036
+ export function touchDaoOrgV2(id) {
1037
+ const o = _daoOrgs.get(id);
1038
+ if (!o) throw new Error(`dao org ${id} not found`);
1039
+ if (_daoOrgTerminal.has(o.status))
1040
+ throw new Error(`cannot touch terminal dao org ${id}`);
1041
+ const now = Date.now();
1042
+ o.lastTouchedAt = now;
1043
+ o.updatedAt = now;
1044
+ return { ...o, metadata: { ...o.metadata } };
1045
+ }
1046
+ export function getDaoOrgV2(id) {
1047
+ const o = _daoOrgs.get(id);
1048
+ if (!o) return null;
1049
+ return { ...o, metadata: { ...o.metadata } };
1050
+ }
1051
+ export function listDaoOrgsV2() {
1052
+ return [..._daoOrgs.values()].map((o) => ({
1053
+ ...o,
1054
+ metadata: { ...o.metadata },
1055
+ }));
1056
+ }
1057
+
1058
+ function _daoCountPending(oid) {
1059
+ let n = 0;
1060
+ for (const p of _daoProps.values())
1061
+ if (
1062
+ p.orgId === oid &&
1063
+ (p.status === DAO_PROPOSAL_LIFECYCLE_V2.QUEUED ||
1064
+ p.status === DAO_PROPOSAL_LIFECYCLE_V2.VOTING)
1065
+ )
1066
+ n++;
1067
+ return n;
1068
+ }
1069
+
1070
+ export function createDaoProposalV2({ id, orgId, title, metadata } = {}) {
1071
+ if (!id || typeof id !== "string") throw new Error("id is required");
1072
+ if (!orgId || typeof orgId !== "string") throw new Error("orgId is required");
1073
+ if (_daoProps.has(id)) throw new Error(`dao proposal ${id} already exists`);
1074
+ if (!_daoOrgs.has(orgId)) throw new Error(`dao org ${orgId} not found`);
1075
+ const pending = _daoCountPending(orgId);
1076
+ if (pending >= _daoMaxPendingPerOrg)
1077
+ throw new Error(
1078
+ `max pending dao proposals per org (${_daoMaxPendingPerOrg}) reached for ${orgId}`,
1079
+ );
1080
+ const now = Date.now();
1081
+ const p = {
1082
+ id,
1083
+ orgId,
1084
+ title: title || id,
1085
+ status: DAO_PROPOSAL_LIFECYCLE_V2.QUEUED,
1086
+ createdAt: now,
1087
+ updatedAt: now,
1088
+ startedAt: null,
1089
+ settledAt: null,
1090
+ metadata: { ...(metadata || {}) },
1091
+ };
1092
+ _daoProps.set(id, p);
1093
+ return { ...p, metadata: { ...p.metadata } };
1094
+ }
1095
+ function _daoCheckP(from, to) {
1096
+ const a = _daoPropTrans.get(from);
1097
+ if (!a || !a.has(to))
1098
+ throw new Error(`invalid dao proposal transition ${from} → ${to}`);
1099
+ }
1100
+ export function startDaoProposalV2(id) {
1101
+ const p = _daoProps.get(id);
1102
+ if (!p) throw new Error(`dao proposal ${id} not found`);
1103
+ _daoCheckP(p.status, DAO_PROPOSAL_LIFECYCLE_V2.VOTING);
1104
+ const now = Date.now();
1105
+ p.status = DAO_PROPOSAL_LIFECYCLE_V2.VOTING;
1106
+ p.updatedAt = now;
1107
+ if (!p.startedAt) p.startedAt = now;
1108
+ return { ...p, metadata: { ...p.metadata } };
1109
+ }
1110
+ export function passDaoProposalV2(id) {
1111
+ const p = _daoProps.get(id);
1112
+ if (!p) throw new Error(`dao proposal ${id} not found`);
1113
+ _daoCheckP(p.status, DAO_PROPOSAL_LIFECYCLE_V2.PASSED);
1114
+ const now = Date.now();
1115
+ p.status = DAO_PROPOSAL_LIFECYCLE_V2.PASSED;
1116
+ p.updatedAt = now;
1117
+ if (!p.settledAt) p.settledAt = now;
1118
+ return { ...p, metadata: { ...p.metadata } };
1119
+ }
1120
+ export function failDaoProposalV2(id, reason) {
1121
+ const p = _daoProps.get(id);
1122
+ if (!p) throw new Error(`dao proposal ${id} not found`);
1123
+ _daoCheckP(p.status, DAO_PROPOSAL_LIFECYCLE_V2.FAILED);
1124
+ const now = Date.now();
1125
+ p.status = DAO_PROPOSAL_LIFECYCLE_V2.FAILED;
1126
+ p.updatedAt = now;
1127
+ if (!p.settledAt) p.settledAt = now;
1128
+ if (reason) p.metadata.failReason = String(reason);
1129
+ return { ...p, metadata: { ...p.metadata } };
1130
+ }
1131
+ export function cancelDaoProposalV2(id, reason) {
1132
+ const p = _daoProps.get(id);
1133
+ if (!p) throw new Error(`dao proposal ${id} not found`);
1134
+ _daoCheckP(p.status, DAO_PROPOSAL_LIFECYCLE_V2.CANCELLED);
1135
+ const now = Date.now();
1136
+ p.status = DAO_PROPOSAL_LIFECYCLE_V2.CANCELLED;
1137
+ p.updatedAt = now;
1138
+ if (!p.settledAt) p.settledAt = now;
1139
+ if (reason) p.metadata.cancelReason = String(reason);
1140
+ return { ...p, metadata: { ...p.metadata } };
1141
+ }
1142
+ export function getDaoProposalV2(id) {
1143
+ const p = _daoProps.get(id);
1144
+ if (!p) return null;
1145
+ return { ...p, metadata: { ...p.metadata } };
1146
+ }
1147
+ export function listDaoProposalsV2() {
1148
+ return [..._daoProps.values()].map((p) => ({
1149
+ ...p,
1150
+ metadata: { ...p.metadata },
1151
+ }));
1152
+ }
1153
+
1154
+ export function autoPauseIdleDaoOrgsV2({ now } = {}) {
1155
+ const t = now ?? Date.now();
1156
+ const flipped = [];
1157
+ for (const o of _daoOrgs.values())
1158
+ if (
1159
+ o.status === DAO_ORG_MATURITY_V2.ACTIVE &&
1160
+ t - o.lastTouchedAt >= _daoOrgIdleMs
1161
+ ) {
1162
+ o.status = DAO_ORG_MATURITY_V2.PAUSED;
1163
+ o.updatedAt = t;
1164
+ flipped.push(o.id);
1165
+ }
1166
+ return { flipped, count: flipped.length };
1167
+ }
1168
+ export function autoFailStuckDaoProposalsV2({ now } = {}) {
1169
+ const t = now ?? Date.now();
1170
+ const flipped = [];
1171
+ for (const p of _daoProps.values())
1172
+ if (
1173
+ p.status === DAO_PROPOSAL_LIFECYCLE_V2.VOTING &&
1174
+ p.startedAt != null &&
1175
+ t - p.startedAt >= _daoPropStuckMs
1176
+ ) {
1177
+ p.status = DAO_PROPOSAL_LIFECYCLE_V2.FAILED;
1178
+ p.updatedAt = t;
1179
+ if (!p.settledAt) p.settledAt = t;
1180
+ p.metadata.failReason = "auto-fail-stuck";
1181
+ flipped.push(p.id);
1182
+ }
1183
+ return { flipped, count: flipped.length };
1184
+ }
1185
+
1186
+ export function getDaoGovernanceGovStatsV2() {
1187
+ const orgsByStatus = {};
1188
+ for (const s of Object.values(DAO_ORG_MATURITY_V2)) orgsByStatus[s] = 0;
1189
+ for (const o of _daoOrgs.values()) orgsByStatus[o.status]++;
1190
+ const proposalsByStatus = {};
1191
+ for (const s of Object.values(DAO_PROPOSAL_LIFECYCLE_V2))
1192
+ proposalsByStatus[s] = 0;
1193
+ for (const p of _daoProps.values()) proposalsByStatus[p.status]++;
1194
+ return {
1195
+ totalOrgsV2: _daoOrgs.size,
1196
+ totalProposalsV2: _daoProps.size,
1197
+ maxActiveDaoOrgsPerOwner: _daoMaxActivePerOwner,
1198
+ maxPendingDaoProposalsPerOrg: _daoMaxPendingPerOrg,
1199
+ daoOrgIdleMs: _daoOrgIdleMs,
1200
+ daoProposalStuckMs: _daoPropStuckMs,
1201
+ orgsByStatus,
1202
+ proposalsByStatus,
1203
+ };
1204
+ }