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
@@ -960,25 +960,50 @@ export function _resetV2State() {
960
960
  _v2Config.growthLogRetentionDays = 365;
961
961
  }
962
962
 
963
-
964
963
  // ===== V2 Surface: Evolution System governance overlay (CLI v0.137.0) =====
965
964
  export const EVO_GOAL_MATURITY_V2 = Object.freeze({
966
- PENDING: "pending", ACTIVE: "active", PAUSED: "paused", ARCHIVED: "archived",
965
+ PENDING: "pending",
966
+ ACTIVE: "active",
967
+ PAUSED: "paused",
968
+ ARCHIVED: "archived",
967
969
  });
968
970
  export const EVO_CYCLE_LIFECYCLE_V2 = Object.freeze({
969
- QUEUED: "queued", RUNNING: "running", COMPLETED: "completed", FAILED: "failed", CANCELLED: "cancelled",
971
+ QUEUED: "queued",
972
+ RUNNING: "running",
973
+ COMPLETED: "completed",
974
+ FAILED: "failed",
975
+ CANCELLED: "cancelled",
970
976
  });
971
977
 
972
978
  const _evoGoalTrans = new Map([
973
- [EVO_GOAL_MATURITY_V2.PENDING, new Set([EVO_GOAL_MATURITY_V2.ACTIVE, EVO_GOAL_MATURITY_V2.ARCHIVED])],
974
- [EVO_GOAL_MATURITY_V2.ACTIVE, new Set([EVO_GOAL_MATURITY_V2.PAUSED, EVO_GOAL_MATURITY_V2.ARCHIVED])],
975
- [EVO_GOAL_MATURITY_V2.PAUSED, new Set([EVO_GOAL_MATURITY_V2.ACTIVE, EVO_GOAL_MATURITY_V2.ARCHIVED])],
979
+ [
980
+ EVO_GOAL_MATURITY_V2.PENDING,
981
+ new Set([EVO_GOAL_MATURITY_V2.ACTIVE, EVO_GOAL_MATURITY_V2.ARCHIVED]),
982
+ ],
983
+ [
984
+ EVO_GOAL_MATURITY_V2.ACTIVE,
985
+ new Set([EVO_GOAL_MATURITY_V2.PAUSED, EVO_GOAL_MATURITY_V2.ARCHIVED]),
986
+ ],
987
+ [
988
+ EVO_GOAL_MATURITY_V2.PAUSED,
989
+ new Set([EVO_GOAL_MATURITY_V2.ACTIVE, EVO_GOAL_MATURITY_V2.ARCHIVED]),
990
+ ],
976
991
  [EVO_GOAL_MATURITY_V2.ARCHIVED, new Set()],
977
992
  ]);
978
993
  const _evoGoalTerminal = new Set([EVO_GOAL_MATURITY_V2.ARCHIVED]);
979
994
  const _evoCycleTrans = new Map([
980
- [EVO_CYCLE_LIFECYCLE_V2.QUEUED, new Set([EVO_CYCLE_LIFECYCLE_V2.RUNNING, EVO_CYCLE_LIFECYCLE_V2.CANCELLED])],
981
- [EVO_CYCLE_LIFECYCLE_V2.RUNNING, new Set([EVO_CYCLE_LIFECYCLE_V2.COMPLETED, EVO_CYCLE_LIFECYCLE_V2.FAILED, EVO_CYCLE_LIFECYCLE_V2.CANCELLED])],
995
+ [
996
+ EVO_CYCLE_LIFECYCLE_V2.QUEUED,
997
+ new Set([EVO_CYCLE_LIFECYCLE_V2.RUNNING, EVO_CYCLE_LIFECYCLE_V2.CANCELLED]),
998
+ ],
999
+ [
1000
+ EVO_CYCLE_LIFECYCLE_V2.RUNNING,
1001
+ new Set([
1002
+ EVO_CYCLE_LIFECYCLE_V2.COMPLETED,
1003
+ EVO_CYCLE_LIFECYCLE_V2.FAILED,
1004
+ EVO_CYCLE_LIFECYCLE_V2.CANCELLED,
1005
+ ]),
1006
+ ],
982
1007
  [EVO_CYCLE_LIFECYCLE_V2.COMPLETED, new Set()],
983
1008
  [EVO_CYCLE_LIFECYCLE_V2.FAILED, new Set()],
984
1009
  [EVO_CYCLE_LIFECYCLE_V2.CANCELLED, new Set()],
@@ -991,21 +1016,45 @@ let _evoMaxPendingPerGoal = 12;
991
1016
  let _evoGoalIdleMs = 14 * 24 * 60 * 60 * 1000;
992
1017
  let _evoCycleStuckMs = 10 * 60 * 1000;
993
1018
 
994
- function _evoPos(n, lbl) { const v = Math.floor(Number(n)); if (!Number.isFinite(v) || v <= 0) throw new Error(`${lbl} must be positive integer`); return v; }
1019
+ function _evoPos(n, lbl) {
1020
+ const v = Math.floor(Number(n));
1021
+ if (!Number.isFinite(v) || v <= 0)
1022
+ throw new Error(`${lbl} must be positive integer`);
1023
+ return v;
1024
+ }
995
1025
 
996
- export function setMaxActiveEvoGoalsPerOwnerV2(n) { _evoMaxActivePerOwner = _evoPos(n, "maxActiveEvoGoalsPerOwner"); }
997
- export function getMaxActiveEvoGoalsPerOwnerV2() { return _evoMaxActivePerOwner; }
998
- export function setMaxPendingEvoCyclesPerGoalV2(n) { _evoMaxPendingPerGoal = _evoPos(n, "maxPendingEvoCyclesPerGoal"); }
999
- export function getMaxPendingEvoCyclesPerGoalV2() { return _evoMaxPendingPerGoal; }
1000
- export function setEvoGoalIdleMsV2(n) { _evoGoalIdleMs = _evoPos(n, "evoGoalIdleMs"); }
1001
- export function getEvoGoalIdleMsV2() { return _evoGoalIdleMs; }
1002
- export function setEvoCycleStuckMsV2(n) { _evoCycleStuckMs = _evoPos(n, "evoCycleStuckMs"); }
1003
- export function getEvoCycleStuckMsV2() { return _evoCycleStuckMs; }
1026
+ export function setMaxActiveEvoGoalsPerOwnerV2(n) {
1027
+ _evoMaxActivePerOwner = _evoPos(n, "maxActiveEvoGoalsPerOwner");
1028
+ }
1029
+ export function getMaxActiveEvoGoalsPerOwnerV2() {
1030
+ return _evoMaxActivePerOwner;
1031
+ }
1032
+ export function setMaxPendingEvoCyclesPerGoalV2(n) {
1033
+ _evoMaxPendingPerGoal = _evoPos(n, "maxPendingEvoCyclesPerGoal");
1034
+ }
1035
+ export function getMaxPendingEvoCyclesPerGoalV2() {
1036
+ return _evoMaxPendingPerGoal;
1037
+ }
1038
+ export function setEvoGoalIdleMsV2(n) {
1039
+ _evoGoalIdleMs = _evoPos(n, "evoGoalIdleMs");
1040
+ }
1041
+ export function getEvoGoalIdleMsV2() {
1042
+ return _evoGoalIdleMs;
1043
+ }
1044
+ export function setEvoCycleStuckMsV2(n) {
1045
+ _evoCycleStuckMs = _evoPos(n, "evoCycleStuckMs");
1046
+ }
1047
+ export function getEvoCycleStuckMsV2() {
1048
+ return _evoCycleStuckMs;
1049
+ }
1004
1050
 
1005
1051
  export function _resetStateEvolutionSystemV2() {
1006
- _evoGoals.clear(); _evoCycles.clear();
1007
- _evoMaxActivePerOwner = 6; _evoMaxPendingPerGoal = 12;
1008
- _evoGoalIdleMs = 14 * 24 * 60 * 60 * 1000; _evoCycleStuckMs = 10 * 60 * 1000;
1052
+ _evoGoals.clear();
1053
+ _evoCycles.clear();
1054
+ _evoMaxActivePerOwner = 6;
1055
+ _evoMaxPendingPerGoal = 12;
1056
+ _evoGoalIdleMs = 14 * 24 * 60 * 60 * 1000;
1057
+ _evoCycleStuckMs = 10 * 60 * 1000;
1009
1058
  }
1010
1059
 
1011
1060
  export function registerEvoGoalV2({ id, owner, objective, metadata } = {}) {
@@ -1013,54 +1062,236 @@ export function registerEvoGoalV2({ id, owner, objective, metadata } = {}) {
1013
1062
  if (!owner || typeof owner !== "string") throw new Error("owner is required");
1014
1063
  if (_evoGoals.has(id)) throw new Error(`evo goal ${id} already registered`);
1015
1064
  const now = Date.now();
1016
- const g = { id, owner, objective: objective || "", status: EVO_GOAL_MATURITY_V2.PENDING, createdAt: now, updatedAt: now, activatedAt: null, archivedAt: null, lastTouchedAt: now, metadata: { ...(metadata || {}) } };
1065
+ const g = {
1066
+ id,
1067
+ owner,
1068
+ objective: objective || "",
1069
+ status: EVO_GOAL_MATURITY_V2.PENDING,
1070
+ createdAt: now,
1071
+ updatedAt: now,
1072
+ activatedAt: null,
1073
+ archivedAt: null,
1074
+ lastTouchedAt: now,
1075
+ metadata: { ...(metadata || {}) },
1076
+ };
1017
1077
  _evoGoals.set(id, g);
1018
1078
  return { ...g, metadata: { ...g.metadata } };
1019
1079
  }
1020
- function _evoCheckG(from, to) { const a = _evoGoalTrans.get(from); if (!a || !a.has(to)) throw new Error(`invalid evo goal transition ${from} → ${to}`); }
1021
- function _evoCountActive(owner) { let n = 0; for (const g of _evoGoals.values()) if (g.owner === owner && g.status === EVO_GOAL_MATURITY_V2.ACTIVE) n++; return n; }
1080
+ function _evoCheckG(from, to) {
1081
+ const a = _evoGoalTrans.get(from);
1082
+ if (!a || !a.has(to))
1083
+ throw new Error(`invalid evo goal transition ${from} → ${to}`);
1084
+ }
1085
+ function _evoCountActive(owner) {
1086
+ let n = 0;
1087
+ for (const g of _evoGoals.values())
1088
+ if (g.owner === owner && g.status === EVO_GOAL_MATURITY_V2.ACTIVE) n++;
1089
+ return n;
1090
+ }
1022
1091
 
1023
1092
  export function activateEvoGoalV2(id) {
1024
- const g = _evoGoals.get(id); if (!g) throw new Error(`evo goal ${id} not found`);
1093
+ const g = _evoGoals.get(id);
1094
+ if (!g) throw new Error(`evo goal ${id} not found`);
1025
1095
  _evoCheckG(g.status, EVO_GOAL_MATURITY_V2.ACTIVE);
1026
1096
  const recovery = g.status === EVO_GOAL_MATURITY_V2.PAUSED;
1027
- if (!recovery) { const a = _evoCountActive(g.owner); if (a >= _evoMaxActivePerOwner) throw new Error(`max active evo goals per owner (${_evoMaxActivePerOwner}) reached for ${g.owner}`); }
1028
- const now = Date.now(); g.status = EVO_GOAL_MATURITY_V2.ACTIVE; g.updatedAt = now; g.lastTouchedAt = now; if (!g.activatedAt) g.activatedAt = now;
1097
+ if (!recovery) {
1098
+ const a = _evoCountActive(g.owner);
1099
+ if (a >= _evoMaxActivePerOwner)
1100
+ throw new Error(
1101
+ `max active evo goals per owner (${_evoMaxActivePerOwner}) reached for ${g.owner}`,
1102
+ );
1103
+ }
1104
+ const now = Date.now();
1105
+ g.status = EVO_GOAL_MATURITY_V2.ACTIVE;
1106
+ g.updatedAt = now;
1107
+ g.lastTouchedAt = now;
1108
+ if (!g.activatedAt) g.activatedAt = now;
1109
+ return { ...g, metadata: { ...g.metadata } };
1110
+ }
1111
+ export function pauseEvoGoalV2(id) {
1112
+ const g = _evoGoals.get(id);
1113
+ if (!g) throw new Error(`evo goal ${id} not found`);
1114
+ _evoCheckG(g.status, EVO_GOAL_MATURITY_V2.PAUSED);
1115
+ g.status = EVO_GOAL_MATURITY_V2.PAUSED;
1116
+ g.updatedAt = Date.now();
1029
1117
  return { ...g, metadata: { ...g.metadata } };
1030
1118
  }
1031
- export function pauseEvoGoalV2(id) { const g = _evoGoals.get(id); if (!g) throw new Error(`evo goal ${id} not found`); _evoCheckG(g.status, EVO_GOAL_MATURITY_V2.PAUSED); g.status = EVO_GOAL_MATURITY_V2.PAUSED; g.updatedAt = Date.now(); return { ...g, metadata: { ...g.metadata } }; }
1032
- export function archiveEvoGoalV2(id) { const g = _evoGoals.get(id); if (!g) throw new Error(`evo goal ${id} not found`); _evoCheckG(g.status, EVO_GOAL_MATURITY_V2.ARCHIVED); const now = Date.now(); g.status = EVO_GOAL_MATURITY_V2.ARCHIVED; g.updatedAt = now; if (!g.archivedAt) g.archivedAt = now; return { ...g, metadata: { ...g.metadata } }; }
1033
- export function touchEvoGoalV2(id) { const g = _evoGoals.get(id); if (!g) throw new Error(`evo goal ${id} not found`); if (_evoGoalTerminal.has(g.status)) throw new Error(`cannot touch terminal evo goal ${id}`); const now = Date.now(); g.lastTouchedAt = now; g.updatedAt = now; return { ...g, metadata: { ...g.metadata } }; }
1034
- export function getEvoGoalV2(id) { const g = _evoGoals.get(id); if (!g) return null; return { ...g, metadata: { ...g.metadata } }; }
1035
- export function listEvoGoalsV2() { return [..._evoGoals.values()].map((g) => ({ ...g, metadata: { ...g.metadata } })); }
1119
+ export function archiveEvoGoalV2(id) {
1120
+ const g = _evoGoals.get(id);
1121
+ if (!g) throw new Error(`evo goal ${id} not found`);
1122
+ _evoCheckG(g.status, EVO_GOAL_MATURITY_V2.ARCHIVED);
1123
+ const now = Date.now();
1124
+ g.status = EVO_GOAL_MATURITY_V2.ARCHIVED;
1125
+ g.updatedAt = now;
1126
+ if (!g.archivedAt) g.archivedAt = now;
1127
+ return { ...g, metadata: { ...g.metadata } };
1128
+ }
1129
+ export function touchEvoGoalV2(id) {
1130
+ const g = _evoGoals.get(id);
1131
+ if (!g) throw new Error(`evo goal ${id} not found`);
1132
+ if (_evoGoalTerminal.has(g.status))
1133
+ throw new Error(`cannot touch terminal evo goal ${id}`);
1134
+ const now = Date.now();
1135
+ g.lastTouchedAt = now;
1136
+ g.updatedAt = now;
1137
+ return { ...g, metadata: { ...g.metadata } };
1138
+ }
1139
+ export function getEvoGoalV2(id) {
1140
+ const g = _evoGoals.get(id);
1141
+ if (!g) return null;
1142
+ return { ...g, metadata: { ...g.metadata } };
1143
+ }
1144
+ export function listEvoGoalsV2() {
1145
+ return [..._evoGoals.values()].map((g) => ({
1146
+ ...g,
1147
+ metadata: { ...g.metadata },
1148
+ }));
1149
+ }
1036
1150
 
1037
- function _evoCountPending(gid) { let n = 0; for (const c of _evoCycles.values()) if (c.goalId === gid && (c.status === EVO_CYCLE_LIFECYCLE_V2.QUEUED || c.status === EVO_CYCLE_LIFECYCLE_V2.RUNNING)) n++; return n; }
1151
+ function _evoCountPending(gid) {
1152
+ let n = 0;
1153
+ for (const c of _evoCycles.values())
1154
+ if (
1155
+ c.goalId === gid &&
1156
+ (c.status === EVO_CYCLE_LIFECYCLE_V2.QUEUED ||
1157
+ c.status === EVO_CYCLE_LIFECYCLE_V2.RUNNING)
1158
+ )
1159
+ n++;
1160
+ return n;
1161
+ }
1038
1162
 
1039
1163
  export function createEvoCycleV2({ id, goalId, generation, metadata } = {}) {
1040
1164
  if (!id || typeof id !== "string") throw new Error("id is required");
1041
- if (!goalId || typeof goalId !== "string") throw new Error("goalId is required");
1165
+ if (!goalId || typeof goalId !== "string")
1166
+ throw new Error("goalId is required");
1042
1167
  if (_evoCycles.has(id)) throw new Error(`evo cycle ${id} already exists`);
1043
1168
  if (!_evoGoals.has(goalId)) throw new Error(`evo goal ${goalId} not found`);
1044
1169
  const pending = _evoCountPending(goalId);
1045
- if (pending >= _evoMaxPendingPerGoal) throw new Error(`max pending evo cycles per goal (${_evoMaxPendingPerGoal}) reached for ${goalId}`);
1170
+ if (pending >= _evoMaxPendingPerGoal)
1171
+ throw new Error(
1172
+ `max pending evo cycles per goal (${_evoMaxPendingPerGoal}) reached for ${goalId}`,
1173
+ );
1046
1174
  const now = Date.now();
1047
- const c = { id, goalId, generation: generation ?? 0, status: EVO_CYCLE_LIFECYCLE_V2.QUEUED, createdAt: now, updatedAt: now, startedAt: null, settledAt: null, metadata: { ...(metadata || {}) } };
1175
+ const c = {
1176
+ id,
1177
+ goalId,
1178
+ generation: generation ?? 0,
1179
+ status: EVO_CYCLE_LIFECYCLE_V2.QUEUED,
1180
+ createdAt: now,
1181
+ updatedAt: now,
1182
+ startedAt: null,
1183
+ settledAt: null,
1184
+ metadata: { ...(metadata || {}) },
1185
+ };
1048
1186
  _evoCycles.set(id, c);
1049
1187
  return { ...c, metadata: { ...c.metadata } };
1050
1188
  }
1051
- function _evoCheckC(from, to) { const a = _evoCycleTrans.get(from); if (!a || !a.has(to)) throw new Error(`invalid evo cycle transition ${from} → ${to}`); }
1052
- export function startEvoCycleV2(id) { const c = _evoCycles.get(id); if (!c) throw new Error(`evo cycle ${id} not found`); _evoCheckC(c.status, EVO_CYCLE_LIFECYCLE_V2.RUNNING); const now = Date.now(); c.status = EVO_CYCLE_LIFECYCLE_V2.RUNNING; c.updatedAt = now; if (!c.startedAt) c.startedAt = now; return { ...c, metadata: { ...c.metadata } }; }
1053
- export function completeEvoCycleV2(id) { const c = _evoCycles.get(id); if (!c) throw new Error(`evo cycle ${id} not found`); _evoCheckC(c.status, EVO_CYCLE_LIFECYCLE_V2.COMPLETED); const now = Date.now(); c.status = EVO_CYCLE_LIFECYCLE_V2.COMPLETED; c.updatedAt = now; if (!c.settledAt) c.settledAt = now; return { ...c, metadata: { ...c.metadata } }; }
1054
- export function failEvoCycleV2(id, reason) { const c = _evoCycles.get(id); if (!c) throw new Error(`evo cycle ${id} not found`); _evoCheckC(c.status, EVO_CYCLE_LIFECYCLE_V2.FAILED); const now = Date.now(); c.status = EVO_CYCLE_LIFECYCLE_V2.FAILED; c.updatedAt = now; if (!c.settledAt) c.settledAt = now; if (reason) c.metadata.failReason = String(reason); return { ...c, metadata: { ...c.metadata } }; }
1055
- export function cancelEvoCycleV2(id, reason) { const c = _evoCycles.get(id); if (!c) throw new Error(`evo cycle ${id} not found`); _evoCheckC(c.status, EVO_CYCLE_LIFECYCLE_V2.CANCELLED); const now = Date.now(); c.status = EVO_CYCLE_LIFECYCLE_V2.CANCELLED; c.updatedAt = now; if (!c.settledAt) c.settledAt = now; if (reason) c.metadata.cancelReason = String(reason); return { ...c, metadata: { ...c.metadata } }; }
1056
- export function getEvoCycleV2(id) { const c = _evoCycles.get(id); if (!c) return null; return { ...c, metadata: { ...c.metadata } }; }
1057
- export function listEvoCyclesV2() { return [..._evoCycles.values()].map((c) => ({ ...c, metadata: { ...c.metadata } })); }
1189
+ function _evoCheckC(from, to) {
1190
+ const a = _evoCycleTrans.get(from);
1191
+ if (!a || !a.has(to))
1192
+ throw new Error(`invalid evo cycle transition ${from} ${to}`);
1193
+ }
1194
+ export function startEvoCycleV2(id) {
1195
+ const c = _evoCycles.get(id);
1196
+ if (!c) throw new Error(`evo cycle ${id} not found`);
1197
+ _evoCheckC(c.status, EVO_CYCLE_LIFECYCLE_V2.RUNNING);
1198
+ const now = Date.now();
1199
+ c.status = EVO_CYCLE_LIFECYCLE_V2.RUNNING;
1200
+ c.updatedAt = now;
1201
+ if (!c.startedAt) c.startedAt = now;
1202
+ return { ...c, metadata: { ...c.metadata } };
1203
+ }
1204
+ export function completeEvoCycleV2(id) {
1205
+ const c = _evoCycles.get(id);
1206
+ if (!c) throw new Error(`evo cycle ${id} not found`);
1207
+ _evoCheckC(c.status, EVO_CYCLE_LIFECYCLE_V2.COMPLETED);
1208
+ const now = Date.now();
1209
+ c.status = EVO_CYCLE_LIFECYCLE_V2.COMPLETED;
1210
+ c.updatedAt = now;
1211
+ if (!c.settledAt) c.settledAt = now;
1212
+ return { ...c, metadata: { ...c.metadata } };
1213
+ }
1214
+ export function failEvoCycleV2(id, reason) {
1215
+ const c = _evoCycles.get(id);
1216
+ if (!c) throw new Error(`evo cycle ${id} not found`);
1217
+ _evoCheckC(c.status, EVO_CYCLE_LIFECYCLE_V2.FAILED);
1218
+ const now = Date.now();
1219
+ c.status = EVO_CYCLE_LIFECYCLE_V2.FAILED;
1220
+ c.updatedAt = now;
1221
+ if (!c.settledAt) c.settledAt = now;
1222
+ if (reason) c.metadata.failReason = String(reason);
1223
+ return { ...c, metadata: { ...c.metadata } };
1224
+ }
1225
+ export function cancelEvoCycleV2(id, reason) {
1226
+ const c = _evoCycles.get(id);
1227
+ if (!c) throw new Error(`evo cycle ${id} not found`);
1228
+ _evoCheckC(c.status, EVO_CYCLE_LIFECYCLE_V2.CANCELLED);
1229
+ const now = Date.now();
1230
+ c.status = EVO_CYCLE_LIFECYCLE_V2.CANCELLED;
1231
+ c.updatedAt = now;
1232
+ if (!c.settledAt) c.settledAt = now;
1233
+ if (reason) c.metadata.cancelReason = String(reason);
1234
+ return { ...c, metadata: { ...c.metadata } };
1235
+ }
1236
+ export function getEvoCycleV2(id) {
1237
+ const c = _evoCycles.get(id);
1238
+ if (!c) return null;
1239
+ return { ...c, metadata: { ...c.metadata } };
1240
+ }
1241
+ export function listEvoCyclesV2() {
1242
+ return [..._evoCycles.values()].map((c) => ({
1243
+ ...c,
1244
+ metadata: { ...c.metadata },
1245
+ }));
1246
+ }
1058
1247
 
1059
- export function autoPauseIdleEvoGoalsV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const g of _evoGoals.values()) if (g.status === EVO_GOAL_MATURITY_V2.ACTIVE && (t - g.lastTouchedAt) >= _evoGoalIdleMs) { g.status = EVO_GOAL_MATURITY_V2.PAUSED; g.updatedAt = t; flipped.push(g.id); } return { flipped, count: flipped.length }; }
1060
- export function autoFailStuckEvoCyclesV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const c of _evoCycles.values()) if (c.status === EVO_CYCLE_LIFECYCLE_V2.RUNNING && c.startedAt != null && (t - c.startedAt) >= _evoCycleStuckMs) { c.status = EVO_CYCLE_LIFECYCLE_V2.FAILED; c.updatedAt = t; if (!c.settledAt) c.settledAt = t; c.metadata.failReason = "auto-fail-stuck"; flipped.push(c.id); } return { flipped, count: flipped.length }; }
1248
+ export function autoPauseIdleEvoGoalsV2({ now } = {}) {
1249
+ const t = now ?? Date.now();
1250
+ const flipped = [];
1251
+ for (const g of _evoGoals.values())
1252
+ if (
1253
+ g.status === EVO_GOAL_MATURITY_V2.ACTIVE &&
1254
+ t - g.lastTouchedAt >= _evoGoalIdleMs
1255
+ ) {
1256
+ g.status = EVO_GOAL_MATURITY_V2.PAUSED;
1257
+ g.updatedAt = t;
1258
+ flipped.push(g.id);
1259
+ }
1260
+ return { flipped, count: flipped.length };
1261
+ }
1262
+ export function autoFailStuckEvoCyclesV2({ now } = {}) {
1263
+ const t = now ?? Date.now();
1264
+ const flipped = [];
1265
+ for (const c of _evoCycles.values())
1266
+ if (
1267
+ c.status === EVO_CYCLE_LIFECYCLE_V2.RUNNING &&
1268
+ c.startedAt != null &&
1269
+ t - c.startedAt >= _evoCycleStuckMs
1270
+ ) {
1271
+ c.status = EVO_CYCLE_LIFECYCLE_V2.FAILED;
1272
+ c.updatedAt = t;
1273
+ if (!c.settledAt) c.settledAt = t;
1274
+ c.metadata.failReason = "auto-fail-stuck";
1275
+ flipped.push(c.id);
1276
+ }
1277
+ return { flipped, count: flipped.length };
1278
+ }
1061
1279
 
1062
1280
  export function getEvolutionSystemGovStatsV2() {
1063
- const goalsByStatus = {}; for (const s of Object.values(EVO_GOAL_MATURITY_V2)) goalsByStatus[s] = 0; for (const g of _evoGoals.values()) goalsByStatus[g.status]++;
1064
- const cyclesByStatus = {}; for (const s of Object.values(EVO_CYCLE_LIFECYCLE_V2)) cyclesByStatus[s] = 0; for (const c of _evoCycles.values()) cyclesByStatus[c.status]++;
1065
- return { totalGoalsV2: _evoGoals.size, totalCyclesV2: _evoCycles.size, maxActiveEvoGoalsPerOwner: _evoMaxActivePerOwner, maxPendingEvoCyclesPerGoal: _evoMaxPendingPerGoal, evoGoalIdleMs: _evoGoalIdleMs, evoCycleStuckMs: _evoCycleStuckMs, goalsByStatus, cyclesByStatus };
1281
+ const goalsByStatus = {};
1282
+ for (const s of Object.values(EVO_GOAL_MATURITY_V2)) goalsByStatus[s] = 0;
1283
+ for (const g of _evoGoals.values()) goalsByStatus[g.status]++;
1284
+ const cyclesByStatus = {};
1285
+ for (const s of Object.values(EVO_CYCLE_LIFECYCLE_V2)) cyclesByStatus[s] = 0;
1286
+ for (const c of _evoCycles.values()) cyclesByStatus[c.status]++;
1287
+ return {
1288
+ totalGoalsV2: _evoGoals.size,
1289
+ totalCyclesV2: _evoCycles.size,
1290
+ maxActiveEvoGoalsPerOwner: _evoMaxActivePerOwner,
1291
+ maxPendingEvoCyclesPerGoal: _evoMaxPendingPerGoal,
1292
+ evoGoalIdleMs: _evoGoalIdleMs,
1293
+ evoCycleStuckMs: _evoCycleStuckMs,
1294
+ goalsByStatus,
1295
+ cyclesByStatus,
1296
+ };
1066
1297
  }