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
@@ -226,25 +226,53 @@ export class EvoMapManager {
226
226
  }
227
227
  }
228
228
 
229
-
230
229
  // ===== V2 Surface: EvoMap Manager governance overlay (CLI v0.135.0) =====
231
230
  export const EVOMAP_MAP_MATURITY_V2 = Object.freeze({
232
- PENDING: "pending", ACTIVE: "active", STALE: "stale", ARCHIVED: "archived",
231
+ PENDING: "pending",
232
+ ACTIVE: "active",
233
+ STALE: "stale",
234
+ ARCHIVED: "archived",
233
235
  });
234
236
  export const EVOMAP_EVOLUTION_LIFECYCLE_V2 = Object.freeze({
235
- QUEUED: "queued", RUNNING: "running", COMPLETED: "completed", FAILED: "failed", CANCELLED: "cancelled",
237
+ QUEUED: "queued",
238
+ RUNNING: "running",
239
+ COMPLETED: "completed",
240
+ FAILED: "failed",
241
+ CANCELLED: "cancelled",
236
242
  });
237
243
 
238
244
  const _emMapTrans = new Map([
239
- [EVOMAP_MAP_MATURITY_V2.PENDING, new Set([EVOMAP_MAP_MATURITY_V2.ACTIVE, EVOMAP_MAP_MATURITY_V2.ARCHIVED])],
240
- [EVOMAP_MAP_MATURITY_V2.ACTIVE, new Set([EVOMAP_MAP_MATURITY_V2.STALE, EVOMAP_MAP_MATURITY_V2.ARCHIVED])],
241
- [EVOMAP_MAP_MATURITY_V2.STALE, new Set([EVOMAP_MAP_MATURITY_V2.ACTIVE, EVOMAP_MAP_MATURITY_V2.ARCHIVED])],
245
+ [
246
+ EVOMAP_MAP_MATURITY_V2.PENDING,
247
+ new Set([EVOMAP_MAP_MATURITY_V2.ACTIVE, EVOMAP_MAP_MATURITY_V2.ARCHIVED]),
248
+ ],
249
+ [
250
+ EVOMAP_MAP_MATURITY_V2.ACTIVE,
251
+ new Set([EVOMAP_MAP_MATURITY_V2.STALE, EVOMAP_MAP_MATURITY_V2.ARCHIVED]),
252
+ ],
253
+ [
254
+ EVOMAP_MAP_MATURITY_V2.STALE,
255
+ new Set([EVOMAP_MAP_MATURITY_V2.ACTIVE, EVOMAP_MAP_MATURITY_V2.ARCHIVED]),
256
+ ],
242
257
  [EVOMAP_MAP_MATURITY_V2.ARCHIVED, new Set()],
243
258
  ]);
244
259
  const _emMapTerminal = new Set([EVOMAP_MAP_MATURITY_V2.ARCHIVED]);
245
260
  const _emEvoTrans = new Map([
246
- [EVOMAP_EVOLUTION_LIFECYCLE_V2.QUEUED, new Set([EVOMAP_EVOLUTION_LIFECYCLE_V2.RUNNING, EVOMAP_EVOLUTION_LIFECYCLE_V2.CANCELLED])],
247
- [EVOMAP_EVOLUTION_LIFECYCLE_V2.RUNNING, new Set([EVOMAP_EVOLUTION_LIFECYCLE_V2.COMPLETED, EVOMAP_EVOLUTION_LIFECYCLE_V2.FAILED, EVOMAP_EVOLUTION_LIFECYCLE_V2.CANCELLED])],
261
+ [
262
+ EVOMAP_EVOLUTION_LIFECYCLE_V2.QUEUED,
263
+ new Set([
264
+ EVOMAP_EVOLUTION_LIFECYCLE_V2.RUNNING,
265
+ EVOMAP_EVOLUTION_LIFECYCLE_V2.CANCELLED,
266
+ ]),
267
+ ],
268
+ [
269
+ EVOMAP_EVOLUTION_LIFECYCLE_V2.RUNNING,
270
+ new Set([
271
+ EVOMAP_EVOLUTION_LIFECYCLE_V2.COMPLETED,
272
+ EVOMAP_EVOLUTION_LIFECYCLE_V2.FAILED,
273
+ EVOMAP_EVOLUTION_LIFECYCLE_V2.CANCELLED,
274
+ ]),
275
+ ],
248
276
  [EVOMAP_EVOLUTION_LIFECYCLE_V2.COMPLETED, new Set()],
249
277
  [EVOMAP_EVOLUTION_LIFECYCLE_V2.FAILED, new Set()],
250
278
  [EVOMAP_EVOLUTION_LIFECYCLE_V2.CANCELLED, new Set()],
@@ -257,21 +285,45 @@ let _emMaxPendingPerMap = 15;
257
285
  let _emMapIdleMs = 7 * 24 * 60 * 60 * 1000;
258
286
  let _emEvoStuckMs = 5 * 60 * 1000;
259
287
 
260
- function _emPos(n, lbl) { const v = Math.floor(Number(n)); if (!Number.isFinite(v) || v <= 0) throw new Error(`${lbl} must be positive integer`); return v; }
288
+ function _emPos(n, lbl) {
289
+ const v = Math.floor(Number(n));
290
+ if (!Number.isFinite(v) || v <= 0)
291
+ throw new Error(`${lbl} must be positive integer`);
292
+ return v;
293
+ }
261
294
 
262
- export function setMaxActiveEvoMapsPerOwnerV2(n) { _emMaxActivePerOwner = _emPos(n, "maxActiveEvoMapsPerOwner"); }
263
- export function getMaxActiveEvoMapsPerOwnerV2() { return _emMaxActivePerOwner; }
264
- export function setMaxPendingEvoEvolutionsPerMapV2(n) { _emMaxPendingPerMap = _emPos(n, "maxPendingEvoEvolutionsPerMap"); }
265
- export function getMaxPendingEvoEvolutionsPerMapV2() { return _emMaxPendingPerMap; }
266
- export function setEvoMapIdleMsV2(n) { _emMapIdleMs = _emPos(n, "evoMapIdleMs"); }
267
- export function getEvoMapIdleMsV2() { return _emMapIdleMs; }
268
- export function setEvoEvolutionStuckMsV2(n) { _emEvoStuckMs = _emPos(n, "evoEvolutionStuckMs"); }
269
- export function getEvoEvolutionStuckMsV2() { return _emEvoStuckMs; }
295
+ export function setMaxActiveEvoMapsPerOwnerV2(n) {
296
+ _emMaxActivePerOwner = _emPos(n, "maxActiveEvoMapsPerOwner");
297
+ }
298
+ export function getMaxActiveEvoMapsPerOwnerV2() {
299
+ return _emMaxActivePerOwner;
300
+ }
301
+ export function setMaxPendingEvoEvolutionsPerMapV2(n) {
302
+ _emMaxPendingPerMap = _emPos(n, "maxPendingEvoEvolutionsPerMap");
303
+ }
304
+ export function getMaxPendingEvoEvolutionsPerMapV2() {
305
+ return _emMaxPendingPerMap;
306
+ }
307
+ export function setEvoMapIdleMsV2(n) {
308
+ _emMapIdleMs = _emPos(n, "evoMapIdleMs");
309
+ }
310
+ export function getEvoMapIdleMsV2() {
311
+ return _emMapIdleMs;
312
+ }
313
+ export function setEvoEvolutionStuckMsV2(n) {
314
+ _emEvoStuckMs = _emPos(n, "evoEvolutionStuckMs");
315
+ }
316
+ export function getEvoEvolutionStuckMsV2() {
317
+ return _emEvoStuckMs;
318
+ }
270
319
 
271
320
  export function _resetStateEvoMapManagerV2() {
272
- _emMaps.clear(); _emEvos.clear();
273
- _emMaxActivePerOwner = 10; _emMaxPendingPerMap = 15;
274
- _emMapIdleMs = 7 * 24 * 60 * 60 * 1000; _emEvoStuckMs = 5 * 60 * 1000;
321
+ _emMaps.clear();
322
+ _emEvos.clear();
323
+ _emMaxActivePerOwner = 10;
324
+ _emMaxPendingPerMap = 15;
325
+ _emMapIdleMs = 7 * 24 * 60 * 60 * 1000;
326
+ _emEvoStuckMs = 5 * 60 * 1000;
275
327
  }
276
328
 
277
329
  export function registerEvoMapV2({ id, owner, name, metadata } = {}) {
@@ -279,28 +331,103 @@ export function registerEvoMapV2({ id, owner, name, metadata } = {}) {
279
331
  if (!owner || typeof owner !== "string") throw new Error("owner is required");
280
332
  if (_emMaps.has(id)) throw new Error(`evomap ${id} already registered`);
281
333
  const now = Date.now();
282
- const m = { id, owner, name: name || id, status: EVOMAP_MAP_MATURITY_V2.PENDING, createdAt: now, updatedAt: now, activatedAt: null, archivedAt: null, lastTouchedAt: now, metadata: { ...(metadata || {}) } };
334
+ const m = {
335
+ id,
336
+ owner,
337
+ name: name || id,
338
+ status: EVOMAP_MAP_MATURITY_V2.PENDING,
339
+ createdAt: now,
340
+ updatedAt: now,
341
+ activatedAt: null,
342
+ archivedAt: null,
343
+ lastTouchedAt: now,
344
+ metadata: { ...(metadata || {}) },
345
+ };
283
346
  _emMaps.set(id, m);
284
347
  return { ...m, metadata: { ...m.metadata } };
285
348
  }
286
- function _emCheckM(from, to) { const a = _emMapTrans.get(from); if (!a || !a.has(to)) throw new Error(`invalid evomap transition ${from} → ${to}`); }
287
- function _emCountActive(owner) { let n = 0; for (const m of _emMaps.values()) if (m.owner === owner && m.status === EVOMAP_MAP_MATURITY_V2.ACTIVE) n++; return n; }
349
+ function _emCheckM(from, to) {
350
+ const a = _emMapTrans.get(from);
351
+ if (!a || !a.has(to))
352
+ throw new Error(`invalid evomap transition ${from} → ${to}`);
353
+ }
354
+ function _emCountActive(owner) {
355
+ let n = 0;
356
+ for (const m of _emMaps.values())
357
+ if (m.owner === owner && m.status === EVOMAP_MAP_MATURITY_V2.ACTIVE) n++;
358
+ return n;
359
+ }
288
360
 
289
361
  export function activateEvoMapV2(id) {
290
- const m = _emMaps.get(id); if (!m) throw new Error(`evomap ${id} not found`);
362
+ const m = _emMaps.get(id);
363
+ if (!m) throw new Error(`evomap ${id} not found`);
291
364
  _emCheckM(m.status, EVOMAP_MAP_MATURITY_V2.ACTIVE);
292
365
  const recovery = m.status === EVOMAP_MAP_MATURITY_V2.STALE;
293
- if (!recovery) { const a = _emCountActive(m.owner); if (a >= _emMaxActivePerOwner) throw new Error(`max active evomaps per owner (${_emMaxActivePerOwner}) reached for ${m.owner}`); }
294
- const now = Date.now(); m.status = EVOMAP_MAP_MATURITY_V2.ACTIVE; m.updatedAt = now; m.lastTouchedAt = now; if (!m.activatedAt) m.activatedAt = now;
366
+ if (!recovery) {
367
+ const a = _emCountActive(m.owner);
368
+ if (a >= _emMaxActivePerOwner)
369
+ throw new Error(
370
+ `max active evomaps per owner (${_emMaxActivePerOwner}) reached for ${m.owner}`,
371
+ );
372
+ }
373
+ const now = Date.now();
374
+ m.status = EVOMAP_MAP_MATURITY_V2.ACTIVE;
375
+ m.updatedAt = now;
376
+ m.lastTouchedAt = now;
377
+ if (!m.activatedAt) m.activatedAt = now;
378
+ return { ...m, metadata: { ...m.metadata } };
379
+ }
380
+ export function staleEvoMapV2(id) {
381
+ const m = _emMaps.get(id);
382
+ if (!m) throw new Error(`evomap ${id} not found`);
383
+ _emCheckM(m.status, EVOMAP_MAP_MATURITY_V2.STALE);
384
+ m.status = EVOMAP_MAP_MATURITY_V2.STALE;
385
+ m.updatedAt = Date.now();
386
+ return { ...m, metadata: { ...m.metadata } };
387
+ }
388
+ export function archiveEvoMapV2(id) {
389
+ const m = _emMaps.get(id);
390
+ if (!m) throw new Error(`evomap ${id} not found`);
391
+ _emCheckM(m.status, EVOMAP_MAP_MATURITY_V2.ARCHIVED);
392
+ const now = Date.now();
393
+ m.status = EVOMAP_MAP_MATURITY_V2.ARCHIVED;
394
+ m.updatedAt = now;
395
+ if (!m.archivedAt) m.archivedAt = now;
396
+ return { ...m, metadata: { ...m.metadata } };
397
+ }
398
+ export function touchEvoMapV2(id) {
399
+ const m = _emMaps.get(id);
400
+ if (!m) throw new Error(`evomap ${id} not found`);
401
+ if (_emMapTerminal.has(m.status))
402
+ throw new Error(`cannot touch terminal evomap ${id}`);
403
+ const now = Date.now();
404
+ m.lastTouchedAt = now;
405
+ m.updatedAt = now;
406
+ return { ...m, metadata: { ...m.metadata } };
407
+ }
408
+ export function getEvoMapV2(id) {
409
+ const m = _emMaps.get(id);
410
+ if (!m) return null;
295
411
  return { ...m, metadata: { ...m.metadata } };
296
412
  }
297
- export function staleEvoMapV2(id) { const m = _emMaps.get(id); if (!m) throw new Error(`evomap ${id} not found`); _emCheckM(m.status, EVOMAP_MAP_MATURITY_V2.STALE); m.status = EVOMAP_MAP_MATURITY_V2.STALE; m.updatedAt = Date.now(); return { ...m, metadata: { ...m.metadata } }; }
298
- export function archiveEvoMapV2(id) { const m = _emMaps.get(id); if (!m) throw new Error(`evomap ${id} not found`); _emCheckM(m.status, EVOMAP_MAP_MATURITY_V2.ARCHIVED); const now = Date.now(); m.status = EVOMAP_MAP_MATURITY_V2.ARCHIVED; m.updatedAt = now; if (!m.archivedAt) m.archivedAt = now; return { ...m, metadata: { ...m.metadata } }; }
299
- export function touchEvoMapV2(id) { const m = _emMaps.get(id); if (!m) throw new Error(`evomap ${id} not found`); if (_emMapTerminal.has(m.status)) throw new Error(`cannot touch terminal evomap ${id}`); const now = Date.now(); m.lastTouchedAt = now; m.updatedAt = now; return { ...m, metadata: { ...m.metadata } }; }
300
- export function getEvoMapV2(id) { const m = _emMaps.get(id); if (!m) return null; return { ...m, metadata: { ...m.metadata } }; }
301
- export function listEvoMapsV2() { return [..._emMaps.values()].map((m) => ({ ...m, metadata: { ...m.metadata } })); }
413
+ export function listEvoMapsV2() {
414
+ return [..._emMaps.values()].map((m) => ({
415
+ ...m,
416
+ metadata: { ...m.metadata },
417
+ }));
418
+ }
302
419
 
303
- function _emCountPending(mid) { let n = 0; for (const e of _emEvos.values()) if (e.mapId === mid && (e.status === EVOMAP_EVOLUTION_LIFECYCLE_V2.QUEUED || e.status === EVOMAP_EVOLUTION_LIFECYCLE_V2.RUNNING)) n++; return n; }
420
+ function _emCountPending(mid) {
421
+ let n = 0;
422
+ for (const e of _emEvos.values())
423
+ if (
424
+ e.mapId === mid &&
425
+ (e.status === EVOMAP_EVOLUTION_LIFECYCLE_V2.QUEUED ||
426
+ e.status === EVOMAP_EVOLUTION_LIFECYCLE_V2.RUNNING)
427
+ )
428
+ n++;
429
+ return n;
430
+ }
304
431
 
305
432
  export function createEvoEvolutionV2({ id, mapId, strategy, metadata } = {}) {
306
433
  if (!id || typeof id !== "string") throw new Error("id is required");
@@ -308,25 +435,132 @@ export function createEvoEvolutionV2({ id, mapId, strategy, metadata } = {}) {
308
435
  if (_emEvos.has(id)) throw new Error(`evo evolution ${id} already exists`);
309
436
  if (!_emMaps.has(mapId)) throw new Error(`evomap ${mapId} not found`);
310
437
  const pending = _emCountPending(mapId);
311
- if (pending >= _emMaxPendingPerMap) throw new Error(`max pending evo evolutions per map (${_emMaxPendingPerMap}) reached for ${mapId}`);
438
+ if (pending >= _emMaxPendingPerMap)
439
+ throw new Error(
440
+ `max pending evo evolutions per map (${_emMaxPendingPerMap}) reached for ${mapId}`,
441
+ );
312
442
  const now = Date.now();
313
- const e = { id, mapId, strategy: strategy || "default", status: EVOMAP_EVOLUTION_LIFECYCLE_V2.QUEUED, createdAt: now, updatedAt: now, startedAt: null, settledAt: null, metadata: { ...(metadata || {}) } };
443
+ const e = {
444
+ id,
445
+ mapId,
446
+ strategy: strategy || "default",
447
+ status: EVOMAP_EVOLUTION_LIFECYCLE_V2.QUEUED,
448
+ createdAt: now,
449
+ updatedAt: now,
450
+ startedAt: null,
451
+ settledAt: null,
452
+ metadata: { ...(metadata || {}) },
453
+ };
314
454
  _emEvos.set(id, e);
315
455
  return { ...e, metadata: { ...e.metadata } };
316
456
  }
317
- function _emCheckE(from, to) { const a = _emEvoTrans.get(from); if (!a || !a.has(to)) throw new Error(`invalid evo evolution transition ${from} → ${to}`); }
318
- export function startEvoEvolutionV2(id) { const e = _emEvos.get(id); if (!e) throw new Error(`evo evolution ${id} not found`); _emCheckE(e.status, EVOMAP_EVOLUTION_LIFECYCLE_V2.RUNNING); const now = Date.now(); e.status = EVOMAP_EVOLUTION_LIFECYCLE_V2.RUNNING; e.updatedAt = now; if (!e.startedAt) e.startedAt = now; return { ...e, metadata: { ...e.metadata } }; }
319
- export function completeEvoEvolutionV2(id) { const e = _emEvos.get(id); if (!e) throw new Error(`evo evolution ${id} not found`); _emCheckE(e.status, EVOMAP_EVOLUTION_LIFECYCLE_V2.COMPLETED); const now = Date.now(); e.status = EVOMAP_EVOLUTION_LIFECYCLE_V2.COMPLETED; e.updatedAt = now; if (!e.settledAt) e.settledAt = now; return { ...e, metadata: { ...e.metadata } }; }
320
- export function failEvoEvolutionV2(id, reason) { const e = _emEvos.get(id); if (!e) throw new Error(`evo evolution ${id} not found`); _emCheckE(e.status, EVOMAP_EVOLUTION_LIFECYCLE_V2.FAILED); const now = Date.now(); e.status = EVOMAP_EVOLUTION_LIFECYCLE_V2.FAILED; e.updatedAt = now; if (!e.settledAt) e.settledAt = now; if (reason) e.metadata.failReason = String(reason); return { ...e, metadata: { ...e.metadata } }; }
321
- export function cancelEvoEvolutionV2(id, reason) { const e = _emEvos.get(id); if (!e) throw new Error(`evo evolution ${id} not found`); _emCheckE(e.status, EVOMAP_EVOLUTION_LIFECYCLE_V2.CANCELLED); const now = Date.now(); e.status = EVOMAP_EVOLUTION_LIFECYCLE_V2.CANCELLED; e.updatedAt = now; if (!e.settledAt) e.settledAt = now; if (reason) e.metadata.cancelReason = String(reason); return { ...e, metadata: { ...e.metadata } }; }
322
- export function getEvoEvolutionV2(id) { const e = _emEvos.get(id); if (!e) return null; return { ...e, metadata: { ...e.metadata } }; }
323
- export function listEvoEvolutionsV2() { return [..._emEvos.values()].map((e) => ({ ...e, metadata: { ...e.metadata } })); }
457
+ function _emCheckE(from, to) {
458
+ const a = _emEvoTrans.get(from);
459
+ if (!a || !a.has(to))
460
+ throw new Error(`invalid evo evolution transition ${from} ${to}`);
461
+ }
462
+ export function startEvoEvolutionV2(id) {
463
+ const e = _emEvos.get(id);
464
+ if (!e) throw new Error(`evo evolution ${id} not found`);
465
+ _emCheckE(e.status, EVOMAP_EVOLUTION_LIFECYCLE_V2.RUNNING);
466
+ const now = Date.now();
467
+ e.status = EVOMAP_EVOLUTION_LIFECYCLE_V2.RUNNING;
468
+ e.updatedAt = now;
469
+ if (!e.startedAt) e.startedAt = now;
470
+ return { ...e, metadata: { ...e.metadata } };
471
+ }
472
+ export function completeEvoEvolutionV2(id) {
473
+ const e = _emEvos.get(id);
474
+ if (!e) throw new Error(`evo evolution ${id} not found`);
475
+ _emCheckE(e.status, EVOMAP_EVOLUTION_LIFECYCLE_V2.COMPLETED);
476
+ const now = Date.now();
477
+ e.status = EVOMAP_EVOLUTION_LIFECYCLE_V2.COMPLETED;
478
+ e.updatedAt = now;
479
+ if (!e.settledAt) e.settledAt = now;
480
+ return { ...e, metadata: { ...e.metadata } };
481
+ }
482
+ export function failEvoEvolutionV2(id, reason) {
483
+ const e = _emEvos.get(id);
484
+ if (!e) throw new Error(`evo evolution ${id} not found`);
485
+ _emCheckE(e.status, EVOMAP_EVOLUTION_LIFECYCLE_V2.FAILED);
486
+ const now = Date.now();
487
+ e.status = EVOMAP_EVOLUTION_LIFECYCLE_V2.FAILED;
488
+ e.updatedAt = now;
489
+ if (!e.settledAt) e.settledAt = now;
490
+ if (reason) e.metadata.failReason = String(reason);
491
+ return { ...e, metadata: { ...e.metadata } };
492
+ }
493
+ export function cancelEvoEvolutionV2(id, reason) {
494
+ const e = _emEvos.get(id);
495
+ if (!e) throw new Error(`evo evolution ${id} not found`);
496
+ _emCheckE(e.status, EVOMAP_EVOLUTION_LIFECYCLE_V2.CANCELLED);
497
+ const now = Date.now();
498
+ e.status = EVOMAP_EVOLUTION_LIFECYCLE_V2.CANCELLED;
499
+ e.updatedAt = now;
500
+ if (!e.settledAt) e.settledAt = now;
501
+ if (reason) e.metadata.cancelReason = String(reason);
502
+ return { ...e, metadata: { ...e.metadata } };
503
+ }
504
+ export function getEvoEvolutionV2(id) {
505
+ const e = _emEvos.get(id);
506
+ if (!e) return null;
507
+ return { ...e, metadata: { ...e.metadata } };
508
+ }
509
+ export function listEvoEvolutionsV2() {
510
+ return [..._emEvos.values()].map((e) => ({
511
+ ...e,
512
+ metadata: { ...e.metadata },
513
+ }));
514
+ }
324
515
 
325
- export function autoStaleIdleEvoMapsV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const m of _emMaps.values()) if (m.status === EVOMAP_MAP_MATURITY_V2.ACTIVE && (t - m.lastTouchedAt) >= _emMapIdleMs) { m.status = EVOMAP_MAP_MATURITY_V2.STALE; m.updatedAt = t; flipped.push(m.id); } return { flipped, count: flipped.length }; }
326
- export function autoFailStuckEvoEvolutionsV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const e of _emEvos.values()) if (e.status === EVOMAP_EVOLUTION_LIFECYCLE_V2.RUNNING && e.startedAt != null && (t - e.startedAt) >= _emEvoStuckMs) { e.status = EVOMAP_EVOLUTION_LIFECYCLE_V2.FAILED; e.updatedAt = t; if (!e.settledAt) e.settledAt = t; e.metadata.failReason = "auto-fail-stuck"; flipped.push(e.id); } return { flipped, count: flipped.length }; }
516
+ export function autoStaleIdleEvoMapsV2({ now } = {}) {
517
+ const t = now ?? Date.now();
518
+ const flipped = [];
519
+ for (const m of _emMaps.values())
520
+ if (
521
+ m.status === EVOMAP_MAP_MATURITY_V2.ACTIVE &&
522
+ t - m.lastTouchedAt >= _emMapIdleMs
523
+ ) {
524
+ m.status = EVOMAP_MAP_MATURITY_V2.STALE;
525
+ m.updatedAt = t;
526
+ flipped.push(m.id);
527
+ }
528
+ return { flipped, count: flipped.length };
529
+ }
530
+ export function autoFailStuckEvoEvolutionsV2({ now } = {}) {
531
+ const t = now ?? Date.now();
532
+ const flipped = [];
533
+ for (const e of _emEvos.values())
534
+ if (
535
+ e.status === EVOMAP_EVOLUTION_LIFECYCLE_V2.RUNNING &&
536
+ e.startedAt != null &&
537
+ t - e.startedAt >= _emEvoStuckMs
538
+ ) {
539
+ e.status = EVOMAP_EVOLUTION_LIFECYCLE_V2.FAILED;
540
+ e.updatedAt = t;
541
+ if (!e.settledAt) e.settledAt = t;
542
+ e.metadata.failReason = "auto-fail-stuck";
543
+ flipped.push(e.id);
544
+ }
545
+ return { flipped, count: flipped.length };
546
+ }
327
547
 
328
548
  export function getEvoMapManagerStatsV2() {
329
- const mapsByStatus = {}; for (const s of Object.values(EVOMAP_MAP_MATURITY_V2)) mapsByStatus[s] = 0; for (const m of _emMaps.values()) mapsByStatus[m.status]++;
330
- const evosByStatus = {}; for (const s of Object.values(EVOMAP_EVOLUTION_LIFECYCLE_V2)) evosByStatus[s] = 0; for (const e of _emEvos.values()) evosByStatus[e.status]++;
331
- return { totalMapsV2: _emMaps.size, totalEvolutionsV2: _emEvos.size, maxActiveEvoMapsPerOwner: _emMaxActivePerOwner, maxPendingEvoEvolutionsPerMap: _emMaxPendingPerMap, evoMapIdleMs: _emMapIdleMs, evoEvolutionStuckMs: _emEvoStuckMs, mapsByStatus, evosByStatus };
549
+ const mapsByStatus = {};
550
+ for (const s of Object.values(EVOMAP_MAP_MATURITY_V2)) mapsByStatus[s] = 0;
551
+ for (const m of _emMaps.values()) mapsByStatus[m.status]++;
552
+ const evosByStatus = {};
553
+ for (const s of Object.values(EVOMAP_EVOLUTION_LIFECYCLE_V2))
554
+ evosByStatus[s] = 0;
555
+ for (const e of _emEvos.values()) evosByStatus[e.status]++;
556
+ return {
557
+ totalMapsV2: _emMaps.size,
558
+ totalEvolutionsV2: _emEvos.size,
559
+ maxActiveEvoMapsPerOwner: _emMaxActivePerOwner,
560
+ maxPendingEvoEvolutionsPerMap: _emMaxPendingPerMap,
561
+ evoMapIdleMs: _emMapIdleMs,
562
+ evoEvolutionStuckMs: _emEvoStuckMs,
563
+ mapsByStatus,
564
+ evosByStatus,
565
+ };
332
566
  }