chainlesschain 0.81.0 → 0.143.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 (209) hide show
  1. package/bin/chainlesschain.js +0 -0
  2. package/package.json +1 -1
  3. package/src/commands/a2a.js +62 -0
  4. package/src/commands/activitypub.js +61 -0
  5. package/src/commands/agent-network.js +254 -1
  6. package/src/commands/agent.js +117 -0
  7. package/src/commands/audit.js +302 -0
  8. package/src/commands/automation.js +271 -1
  9. package/src/commands/bi.js +61 -0
  10. package/src/commands/bm25.js +78 -0
  11. package/src/commands/browse.js +64 -0
  12. package/src/commands/ccron.js +78 -0
  13. package/src/commands/codegen.js +224 -0
  14. package/src/commands/collab.js +341 -0
  15. package/src/commands/compliance.js +1075 -0
  16. package/src/commands/compt.js +78 -0
  17. package/src/commands/consol.js +231 -0
  18. package/src/commands/cowork.js +263 -0
  19. package/src/commands/crosschain.js +62 -0
  20. package/src/commands/dao.js +62 -0
  21. package/src/commands/dbevo.js +284 -0
  22. package/src/commands/dev.js +252 -0
  23. package/src/commands/did.js +358 -0
  24. package/src/commands/dlp.js +61 -0
  25. package/src/commands/economy.js +56 -0
  26. package/src/commands/encrypt.js +341 -0
  27. package/src/commands/evolution.js +56 -0
  28. package/src/commands/evomap.js +61 -0
  29. package/src/commands/export.js +256 -1
  30. package/src/commands/fflag.js +178 -0
  31. package/src/commands/fusion.js +258 -0
  32. package/src/commands/git.js +45 -0
  33. package/src/commands/governance.js +325 -0
  34. package/src/commands/hardening.js +411 -0
  35. package/src/commands/hmemory.js +56 -0
  36. package/src/commands/hook.js +148 -0
  37. package/src/commands/import.js +252 -0
  38. package/src/commands/incentive.js +322 -0
  39. package/src/commands/inference.js +42 -0
  40. package/src/commands/infra.js +244 -0
  41. package/src/commands/instinct.js +260 -0
  42. package/src/commands/ipfs.js +318 -0
  43. package/src/commands/itbudget.js +45 -0
  44. package/src/commands/kg.js +387 -0
  45. package/src/commands/llm.js +263 -0
  46. package/src/commands/lowcode.js +44 -0
  47. package/src/commands/matrix.js +62 -0
  48. package/src/commands/mcp.js +221 -0
  49. package/src/commands/mcpscaf.js +41 -0
  50. package/src/commands/meminj.js +41 -0
  51. package/src/commands/memory.js +248 -0
  52. package/src/commands/multimodal.js +296 -0
  53. package/src/commands/nlprog.js +356 -0
  54. package/src/commands/nostr.js +62 -0
  55. package/src/commands/note.js +244 -0
  56. package/src/commands/ops.js +354 -0
  57. package/src/commands/orchestrate.js +166 -0
  58. package/src/commands/orchgov.js +45 -0
  59. package/src/commands/org.js +277 -0
  60. package/src/commands/p2p.js +390 -0
  61. package/src/commands/pdfp.js +78 -0
  62. package/src/commands/perception.js +290 -0
  63. package/src/commands/perf.js +39 -0
  64. package/src/commands/perm.js +45 -0
  65. package/src/commands/permmem.js +251 -0
  66. package/src/commands/pipeline.js +57 -1
  67. package/src/commands/planmode.js +45 -0
  68. package/src/commands/plugin-ecosystem.js +273 -0
  69. package/src/commands/pqc.js +393 -0
  70. package/src/commands/promcomp.js +82 -0
  71. package/src/commands/quantization.js +351 -0
  72. package/src/commands/rcache.js +271 -0
  73. package/src/commands/recommend.js +382 -0
  74. package/src/commands/runtime.js +307 -0
  75. package/src/commands/scim.js +262 -0
  76. package/src/commands/seshhook.js +41 -0
  77. package/src/commands/seshsearch.js +41 -0
  78. package/src/commands/seshtail.js +41 -0
  79. package/src/commands/seshu.js +41 -0
  80. package/src/commands/session.js +258 -0
  81. package/src/commands/sganal.js +78 -0
  82. package/src/commands/siem.js +40 -0
  83. package/src/commands/skill.js +267 -1
  84. package/src/commands/slotfill.js +41 -0
  85. package/src/commands/social.js +290 -0
  86. package/src/commands/sso.js +186 -1
  87. package/src/commands/svccont.js +45 -0
  88. package/src/commands/sync.js +256 -0
  89. package/src/commands/tech.js +338 -0
  90. package/src/commands/tenant.js +351 -0
  91. package/src/commands/tms.js +45 -0
  92. package/src/commands/tokens.js +269 -0
  93. package/src/commands/topiccls.js +45 -0
  94. package/src/commands/trust.js +249 -0
  95. package/src/commands/uprof.js +45 -0
  96. package/src/commands/vcheck.js +78 -0
  97. package/src/commands/wallet.js +277 -0
  98. package/src/commands/webfetch.js +41 -0
  99. package/src/commands/workflow.js +171 -0
  100. package/src/commands/zkp.js +62 -0
  101. package/src/harness/prompt-compressor.js +331 -0
  102. package/src/index.js +65 -1
  103. package/src/lib/a2a-protocol.js +105 -0
  104. package/src/lib/activitypub-bridge.js +105 -0
  105. package/src/lib/agent-coordinator.js +325 -0
  106. package/src/lib/agent-economy.js +105 -0
  107. package/src/lib/agent-network.js +387 -0
  108. package/src/lib/agent-router.js +395 -0
  109. package/src/lib/aiops.js +478 -0
  110. package/src/lib/app-builder.js +105 -0
  111. package/src/lib/audit-logger.js +379 -0
  112. package/src/lib/automation-engine.js +330 -0
  113. package/src/lib/autonomous-agent.js +105 -0
  114. package/src/lib/autonomous-developer.js +350 -0
  115. package/src/lib/bi-engine.js +105 -0
  116. package/src/lib/bm25-search.js +81 -0
  117. package/src/lib/browser-automation.js +105 -0
  118. package/src/lib/code-agent.js +323 -0
  119. package/src/lib/collaboration-governance.js +364 -0
  120. package/src/lib/community-governance.js +436 -0
  121. package/src/lib/compliance-framework-reporter.js +105 -0
  122. package/src/lib/compliance-manager.js +434 -0
  123. package/src/lib/compression-telemetry.js +81 -0
  124. package/src/lib/content-recommendation.js +469 -0
  125. package/src/lib/content-recommender.js +105 -0
  126. package/src/lib/cowork-cron.js +81 -0
  127. package/src/lib/cowork-task-runner.js +105 -0
  128. package/src/lib/cross-chain.js +105 -0
  129. package/src/lib/crypto-manager.js +350 -0
  130. package/src/lib/dao-governance.js +105 -0
  131. package/src/lib/dbevo.js +338 -0
  132. package/src/lib/decentral-infra.js +340 -0
  133. package/src/lib/did-manager.js +367 -0
  134. package/src/lib/dlp-engine.js +105 -0
  135. package/src/lib/evolution-system.js +105 -0
  136. package/src/lib/evomap-manager.js +105 -0
  137. package/src/lib/execution-backend.js +105 -0
  138. package/src/lib/feature-flags.js +85 -0
  139. package/src/lib/git-integration.js +105 -0
  140. package/src/lib/hardening-manager.js +348 -0
  141. package/src/lib/hierarchical-memory.js +105 -0
  142. package/src/lib/hook-manager.js +380 -0
  143. package/src/lib/inference-network.js +105 -0
  144. package/src/lib/instinct-manager.js +332 -0
  145. package/src/lib/ipfs-storage.js +334 -0
  146. package/src/lib/iteration-budget.js +105 -0
  147. package/src/lib/knowledge-exporter.js +381 -0
  148. package/src/lib/knowledge-graph.js +432 -0
  149. package/src/lib/knowledge-importer.js +379 -0
  150. package/src/lib/llm-providers.js +391 -0
  151. package/src/lib/matrix-bridge.js +105 -0
  152. package/src/lib/mcp-registry.js +333 -0
  153. package/src/lib/mcp-scaffold.js +81 -0
  154. package/src/lib/memory-injection.js +81 -0
  155. package/src/lib/memory-manager.js +330 -0
  156. package/src/lib/multimodal.js +346 -0
  157. package/src/lib/nl-programming.js +343 -0
  158. package/src/lib/nostr-bridge.js +105 -0
  159. package/src/lib/note-versioning.js +327 -0
  160. package/src/lib/orchestrator.js +105 -0
  161. package/src/lib/org-manager.js +323 -0
  162. package/src/lib/p2p-manager.js +387 -0
  163. package/src/lib/pdf-parser.js +81 -0
  164. package/src/lib/perception.js +346 -0
  165. package/src/lib/perf-tuning.js +109 -1
  166. package/src/lib/permanent-memory.js +320 -0
  167. package/src/lib/permission-engine.js +81 -0
  168. package/src/lib/pipeline-orchestrator.js +105 -0
  169. package/src/lib/plan-mode.js +81 -0
  170. package/src/lib/plugin-ecosystem.js +377 -0
  171. package/src/lib/pqc-manager.js +368 -0
  172. package/src/lib/prompt-compressor.js +1 -10
  173. package/src/lib/protocol-fusion.js +417 -0
  174. package/src/lib/quantization.js +325 -0
  175. package/src/lib/response-cache.js +327 -0
  176. package/src/lib/scim-manager.js +329 -0
  177. package/src/lib/service-container.js +81 -0
  178. package/src/lib/session-consolidator.js +105 -0
  179. package/src/lib/session-hooks.js +81 -0
  180. package/src/lib/session-manager.js +329 -0
  181. package/src/lib/session-search.js +81 -0
  182. package/src/lib/session-tail.js +81 -0
  183. package/src/lib/session-usage.js +83 -0
  184. package/src/lib/siem-exporter.js +105 -0
  185. package/src/lib/skill-loader.js +377 -0
  186. package/src/lib/slot-filler.js +81 -0
  187. package/src/lib/social-graph-analytics.js +81 -0
  188. package/src/lib/social-graph.js +81 -0
  189. package/src/lib/social-manager.js +326 -0
  190. package/src/lib/sso-manager.js +332 -0
  191. package/src/lib/sub-agent-registry.js +110 -0
  192. package/src/lib/sync-manager.js +326 -0
  193. package/src/lib/task-model-selector.js +81 -0
  194. package/src/lib/tech-learning-engine.js +369 -0
  195. package/src/lib/tenant-saas.js +460 -0
  196. package/src/lib/threat-intel.js +335 -0
  197. package/src/lib/todo-manager.js +105 -0
  198. package/src/lib/token-incentive.js +293 -0
  199. package/src/lib/token-tracker.js +329 -0
  200. package/src/lib/topic-classifier.js +105 -0
  201. package/src/lib/trust-security.js +390 -0
  202. package/src/lib/ueba.js +389 -0
  203. package/src/lib/universal-runtime.js +325 -0
  204. package/src/lib/user-profile.js +81 -0
  205. package/src/lib/version-checker.js +81 -0
  206. package/src/lib/wallet-manager.js +326 -0
  207. package/src/lib/web-fetch.js +81 -0
  208. package/src/lib/workflow-engine.js +322 -0
  209. package/src/lib/zkp-engine.js +105 -0
@@ -954,3 +954,325 @@ export function importWorkflow(db, definition) {
954
954
  stages: definition.stages,
955
955
  });
956
956
  }
957
+
958
+ // ===== V2 Surface (cli 0.130.0) — in-memory governance =====
959
+ export const WORKFLOW_MATURITY_V2 = Object.freeze({
960
+ DRAFT: "draft",
961
+ ACTIVE: "active",
962
+ PAUSED: "paused",
963
+ RETIRED: "retired",
964
+ });
965
+ export const RUN_LIFECYCLE_V2 = Object.freeze({
966
+ QUEUED: "queued",
967
+ RUNNING: "running",
968
+ COMPLETED: "completed",
969
+ FAILED: "failed",
970
+ CANCELLED: "cancelled",
971
+ });
972
+
973
+ const _WM_V2 = WORKFLOW_MATURITY_V2;
974
+ const _RL_V2 = RUN_LIFECYCLE_V2;
975
+ const _WM_TRANS_V2 = new Map([
976
+ [_WM_V2.DRAFT, new Set([_WM_V2.ACTIVE, _WM_V2.RETIRED])],
977
+ [_WM_V2.ACTIVE, new Set([_WM_V2.PAUSED, _WM_V2.RETIRED])],
978
+ [_WM_V2.PAUSED, new Set([_WM_V2.ACTIVE, _WM_V2.RETIRED])],
979
+ [_WM_V2.RETIRED, new Set()],
980
+ ]);
981
+ const _RL_TRANS_V2 = new Map([
982
+ [_RL_V2.QUEUED, new Set([_RL_V2.RUNNING, _RL_V2.CANCELLED])],
983
+ [
984
+ _RL_V2.RUNNING,
985
+ new Set([_RL_V2.COMPLETED, _RL_V2.FAILED, _RL_V2.CANCELLED]),
986
+ ],
987
+ [_RL_V2.COMPLETED, new Set()],
988
+ [_RL_V2.FAILED, new Set()],
989
+ [_RL_V2.CANCELLED, new Set()],
990
+ ]);
991
+ const _RL_TERM_V2 = new Set([
992
+ _RL_V2.COMPLETED,
993
+ _RL_V2.FAILED,
994
+ _RL_V2.CANCELLED,
995
+ ]);
996
+
997
+ const WF_DEFAULT_MAX_ACTIVE_WORKFLOWS_PER_OWNER = 12;
998
+ const WF_DEFAULT_MAX_PENDING_RUNS_PER_WORKFLOW = 8;
999
+ const WF_DEFAULT_WORKFLOW_IDLE_MS = 60 * 24 * 60 * 60 * 1000;
1000
+ const WF_DEFAULT_RUN_STUCK_MS = 10 * 60 * 1000;
1001
+
1002
+ const _wfWorkflowsV2 = new Map();
1003
+ const _wfRunsV2 = new Map();
1004
+ let _wfConfigV2 = {
1005
+ maxActiveWorkflowsPerOwner: WF_DEFAULT_MAX_ACTIVE_WORKFLOWS_PER_OWNER,
1006
+ maxPendingRunsPerWorkflow: WF_DEFAULT_MAX_PENDING_RUNS_PER_WORKFLOW,
1007
+ workflowIdleMs: WF_DEFAULT_WORKFLOW_IDLE_MS,
1008
+ runStuckMs: WF_DEFAULT_RUN_STUCK_MS,
1009
+ };
1010
+
1011
+ function _wfPosIntV2(n, label) {
1012
+ if (typeof n !== "number" || !isFinite(n) || isNaN(n))
1013
+ throw new Error(`${label} must be positive integer`);
1014
+ const v = Math.floor(n);
1015
+ if (v <= 0) throw new Error(`${label} must be positive integer`);
1016
+ return v;
1017
+ }
1018
+
1019
+ export function _resetStateWorkflowEngineV2() {
1020
+ _wfWorkflowsV2.clear();
1021
+ _wfRunsV2.clear();
1022
+ _wfConfigV2 = {
1023
+ maxActiveWorkflowsPerOwner: WF_DEFAULT_MAX_ACTIVE_WORKFLOWS_PER_OWNER,
1024
+ maxPendingRunsPerWorkflow: WF_DEFAULT_MAX_PENDING_RUNS_PER_WORKFLOW,
1025
+ workflowIdleMs: WF_DEFAULT_WORKFLOW_IDLE_MS,
1026
+ runStuckMs: WF_DEFAULT_RUN_STUCK_MS,
1027
+ };
1028
+ }
1029
+
1030
+ export function setMaxActiveWorkflowsPerOwnerV2(n) {
1031
+ _wfConfigV2.maxActiveWorkflowsPerOwner = _wfPosIntV2(
1032
+ n,
1033
+ "maxActiveWorkflowsPerOwner",
1034
+ );
1035
+ }
1036
+ export function setMaxPendingRunsPerWorkflowV2(n) {
1037
+ _wfConfigV2.maxPendingRunsPerWorkflow = _wfPosIntV2(
1038
+ n,
1039
+ "maxPendingRunsPerWorkflow",
1040
+ );
1041
+ }
1042
+ export function setWorkflowIdleMsV2(n) {
1043
+ _wfConfigV2.workflowIdleMs = _wfPosIntV2(n, "workflowIdleMs");
1044
+ }
1045
+ export function setRunStuckMsV2(n) {
1046
+ _wfConfigV2.runStuckMs = _wfPosIntV2(n, "runStuckMs");
1047
+ }
1048
+ export function getMaxActiveWorkflowsPerOwnerV2() {
1049
+ return _wfConfigV2.maxActiveWorkflowsPerOwner;
1050
+ }
1051
+ export function getMaxPendingRunsPerWorkflowV2() {
1052
+ return _wfConfigV2.maxPendingRunsPerWorkflow;
1053
+ }
1054
+ export function getWorkflowIdleMsV2() {
1055
+ return _wfConfigV2.workflowIdleMs;
1056
+ }
1057
+ export function getRunStuckMsV2() {
1058
+ return _wfConfigV2.runStuckMs;
1059
+ }
1060
+
1061
+ function _copyWorkflowV2(w) {
1062
+ return { ...w, metadata: { ...(w.metadata || {}) } };
1063
+ }
1064
+ function _copyRunV2(r) {
1065
+ return { ...r, metadata: { ...(r.metadata || {}) } };
1066
+ }
1067
+
1068
+ export function registerWorkflowV2({ id, owner, name, metadata } = {}) {
1069
+ if (!id || typeof id !== "string") throw new Error("id required");
1070
+ if (!owner || typeof owner !== "string") throw new Error("owner required");
1071
+ if (_wfWorkflowsV2.has(id))
1072
+ throw new Error(`workflow ${id} already registered`);
1073
+ const now = Date.now();
1074
+ const w = {
1075
+ id,
1076
+ owner,
1077
+ name: name || id,
1078
+ status: _WM_V2.DRAFT,
1079
+ activatedAt: null,
1080
+ retiredAt: null,
1081
+ lastSeenAt: now,
1082
+ createdAt: now,
1083
+ metadata: metadata && typeof metadata === "object" ? { ...metadata } : {},
1084
+ };
1085
+ _wfWorkflowsV2.set(id, w);
1086
+ return _copyWorkflowV2(w);
1087
+ }
1088
+
1089
+ function _activeWorkflowCountForOwnerV2(owner) {
1090
+ let c = 0;
1091
+ for (const w of _wfWorkflowsV2.values())
1092
+ if (w.owner === owner && w.status === _WM_V2.ACTIVE) c++;
1093
+ return c;
1094
+ }
1095
+
1096
+ function _transitionWorkflowV2(id, next) {
1097
+ const w = _wfWorkflowsV2.get(id);
1098
+ if (!w) throw new Error(`workflow ${id} not found`);
1099
+ const allowed = _WM_TRANS_V2.get(w.status);
1100
+ if (!allowed || !allowed.has(next))
1101
+ throw new Error(`invalid transition ${w.status} -> ${next}`);
1102
+ if (next === _WM_V2.ACTIVE && w.status === _WM_V2.DRAFT) {
1103
+ if (
1104
+ _activeWorkflowCountForOwnerV2(w.owner) >=
1105
+ _wfConfigV2.maxActiveWorkflowsPerOwner
1106
+ ) {
1107
+ throw new Error(
1108
+ `owner ${w.owner} active-workflow cap reached (${_wfConfigV2.maxActiveWorkflowsPerOwner})`,
1109
+ );
1110
+ }
1111
+ }
1112
+ const now = Date.now();
1113
+ w.status = next;
1114
+ if (next === _WM_V2.ACTIVE && !w.activatedAt) w.activatedAt = now;
1115
+ if (next === _WM_V2.RETIRED && !w.retiredAt) w.retiredAt = now;
1116
+ w.lastSeenAt = now;
1117
+ return _copyWorkflowV2(w);
1118
+ }
1119
+
1120
+ export function activateWorkflowV2(id) {
1121
+ return _transitionWorkflowV2(id, _WM_V2.ACTIVE);
1122
+ }
1123
+ export function pauseWorkflowV2(id) {
1124
+ return _transitionWorkflowV2(id, _WM_V2.PAUSED);
1125
+ }
1126
+ export function retireWorkflowV2(id) {
1127
+ return _transitionWorkflowV2(id, _WM_V2.RETIRED);
1128
+ }
1129
+ export function touchWorkflowV2(id) {
1130
+ const w = _wfWorkflowsV2.get(id);
1131
+ if (!w) throw new Error(`workflow ${id} not found`);
1132
+ w.lastSeenAt = Date.now();
1133
+ return _copyWorkflowV2(w);
1134
+ }
1135
+ export function getWorkflowV2(id) {
1136
+ const w = _wfWorkflowsV2.get(id);
1137
+ return w ? _copyWorkflowV2(w) : null;
1138
+ }
1139
+ export function listWorkflowsV2({ owner, status } = {}) {
1140
+ const out = [];
1141
+ for (const w of _wfWorkflowsV2.values()) {
1142
+ if (owner && w.owner !== owner) continue;
1143
+ if (status && w.status !== status) continue;
1144
+ out.push(_copyWorkflowV2(w));
1145
+ }
1146
+ return out;
1147
+ }
1148
+
1149
+ function _pendingRunCountForWorkflowV2(workflowId) {
1150
+ let c = 0;
1151
+ for (const r of _wfRunsV2.values()) {
1152
+ if (r.workflowId !== workflowId) continue;
1153
+ if (r.status === _RL_V2.QUEUED || r.status === _RL_V2.RUNNING) c++;
1154
+ }
1155
+ return c;
1156
+ }
1157
+
1158
+ export function createRunV2({ id, workflowId, trigger, metadata } = {}) {
1159
+ if (!id || typeof id !== "string") throw new Error("id required");
1160
+ if (!workflowId || typeof workflowId !== "string")
1161
+ throw new Error("workflowId required");
1162
+ if (_wfRunsV2.has(id)) throw new Error(`run ${id} already exists`);
1163
+ const wf = _wfWorkflowsV2.get(workflowId);
1164
+ if (!wf) throw new Error(`workflow ${workflowId} not found`);
1165
+ if (wf.status === _WM_V2.RETIRED)
1166
+ throw new Error(`workflow ${workflowId} retired`);
1167
+ if (
1168
+ _pendingRunCountForWorkflowV2(workflowId) >=
1169
+ _wfConfigV2.maxPendingRunsPerWorkflow
1170
+ ) {
1171
+ throw new Error(
1172
+ `workflow ${workflowId} pending-run cap reached (${_wfConfigV2.maxPendingRunsPerWorkflow})`,
1173
+ );
1174
+ }
1175
+ const now = Date.now();
1176
+ const r = {
1177
+ id,
1178
+ workflowId,
1179
+ trigger: trigger || "manual",
1180
+ status: _RL_V2.QUEUED,
1181
+ startedAt: null,
1182
+ settledAt: null,
1183
+ createdAt: now,
1184
+ metadata: metadata && typeof metadata === "object" ? { ...metadata } : {},
1185
+ };
1186
+ _wfRunsV2.set(id, r);
1187
+ return _copyRunV2(r);
1188
+ }
1189
+
1190
+ function _transitionRunV2(id, next, extra = {}) {
1191
+ const r = _wfRunsV2.get(id);
1192
+ if (!r) throw new Error(`run ${id} not found`);
1193
+ const allowed = _RL_TRANS_V2.get(r.status);
1194
+ if (!allowed || !allowed.has(next))
1195
+ throw new Error(`invalid transition ${r.status} -> ${next}`);
1196
+ const now = Date.now();
1197
+ r.status = next;
1198
+ if (next === _RL_V2.RUNNING && !r.startedAt) r.startedAt = now;
1199
+ if (_RL_TERM_V2.has(next) && !r.settledAt) r.settledAt = now;
1200
+ if (extra.error) r.metadata.error = extra.error;
1201
+ return _copyRunV2(r);
1202
+ }
1203
+
1204
+ export function startRunV2(id) {
1205
+ return _transitionRunV2(id, _RL_V2.RUNNING);
1206
+ }
1207
+ export function completeRunV2(id) {
1208
+ return _transitionRunV2(id, _RL_V2.COMPLETED);
1209
+ }
1210
+ export function failRunV2(id, error) {
1211
+ return _transitionRunV2(id, _RL_V2.FAILED, { error });
1212
+ }
1213
+ export function cancelRunV2(id) {
1214
+ return _transitionRunV2(id, _RL_V2.CANCELLED);
1215
+ }
1216
+
1217
+ export function getRunV2(id) {
1218
+ const r = _wfRunsV2.get(id);
1219
+ return r ? _copyRunV2(r) : null;
1220
+ }
1221
+ export function listRunsV2({ workflowId, status, trigger } = {}) {
1222
+ const out = [];
1223
+ for (const r of _wfRunsV2.values()) {
1224
+ if (workflowId && r.workflowId !== workflowId) continue;
1225
+ if (status && r.status !== status) continue;
1226
+ if (trigger && r.trigger !== trigger) continue;
1227
+ out.push(_copyRunV2(r));
1228
+ }
1229
+ return out;
1230
+ }
1231
+
1232
+ export function autoPauseIdleWorkflowsV2({ now } = {}) {
1233
+ const t = typeof now === "number" ? now : Date.now();
1234
+ const flipped = [];
1235
+ for (const w of _wfWorkflowsV2.values()) {
1236
+ if (w.status !== _WM_V2.ACTIVE) continue;
1237
+ if (t - w.lastSeenAt > _wfConfigV2.workflowIdleMs) {
1238
+ w.status = _WM_V2.PAUSED;
1239
+ w.lastSeenAt = t;
1240
+ flipped.push(_copyWorkflowV2(w));
1241
+ }
1242
+ }
1243
+ return flipped;
1244
+ }
1245
+
1246
+ export function autoFailStuckRunsV2({ now } = {}) {
1247
+ const t = typeof now === "number" ? now : Date.now();
1248
+ const flipped = [];
1249
+ for (const r of _wfRunsV2.values()) {
1250
+ if (r.status !== _RL_V2.RUNNING) continue;
1251
+ if (r.startedAt && t - r.startedAt > _wfConfigV2.runStuckMs) {
1252
+ r.status = _RL_V2.FAILED;
1253
+ r.settledAt = t;
1254
+ r.metadata.error = "stuck-timeout";
1255
+ flipped.push(_copyRunV2(r));
1256
+ }
1257
+ }
1258
+ return flipped;
1259
+ }
1260
+
1261
+ export function getWorkflowEngineStatsV2() {
1262
+ const workflowsByStatus = {};
1263
+ for (const s of Object.values(_WM_V2)) workflowsByStatus[s] = 0;
1264
+ for (const w of _wfWorkflowsV2.values()) workflowsByStatus[w.status]++;
1265
+ const runsByStatus = {};
1266
+ for (const s of Object.values(_RL_V2)) runsByStatus[s] = 0;
1267
+ for (const r of _wfRunsV2.values()) runsByStatus[r.status]++;
1268
+ return {
1269
+ totalWorkflowsV2: _wfWorkflowsV2.size,
1270
+ totalRunsV2: _wfRunsV2.size,
1271
+ maxActiveWorkflowsPerOwner: _wfConfigV2.maxActiveWorkflowsPerOwner,
1272
+ maxPendingRunsPerWorkflow: _wfConfigV2.maxPendingRunsPerWorkflow,
1273
+ workflowIdleMs: _wfConfigV2.workflowIdleMs,
1274
+ runStuckMs: _wfConfigV2.runStuckMs,
1275
+ workflowsByStatus,
1276
+ runsByStatus,
1277
+ };
1278
+ }
@@ -742,3 +742,108 @@ export function getZKPStatsV2() {
742
742
  credentialsByDid,
743
743
  };
744
744
  }
745
+
746
+
747
+ // ===== V2 Surface: ZKP Engine governance overlay (CLI v0.136.0) =====
748
+ export const ZKP_CIRCUIT_MATURITY_V2 = Object.freeze({
749
+ PENDING: "pending", ACTIVE: "active", DEPRECATED: "deprecated", ARCHIVED: "archived",
750
+ });
751
+ export const ZKP_PROOF_LIFECYCLE_V2 = Object.freeze({
752
+ QUEUED: "queued", PROVING: "proving", VERIFIED: "verified", FAILED: "failed", CANCELLED: "cancelled",
753
+ });
754
+
755
+ const _zkpCircTrans = new Map([
756
+ [ZKP_CIRCUIT_MATURITY_V2.PENDING, new Set([ZKP_CIRCUIT_MATURITY_V2.ACTIVE, ZKP_CIRCUIT_MATURITY_V2.ARCHIVED])],
757
+ [ZKP_CIRCUIT_MATURITY_V2.ACTIVE, new Set([ZKP_CIRCUIT_MATURITY_V2.DEPRECATED, ZKP_CIRCUIT_MATURITY_V2.ARCHIVED])],
758
+ [ZKP_CIRCUIT_MATURITY_V2.DEPRECATED, new Set([ZKP_CIRCUIT_MATURITY_V2.ACTIVE, ZKP_CIRCUIT_MATURITY_V2.ARCHIVED])],
759
+ [ZKP_CIRCUIT_MATURITY_V2.ARCHIVED, new Set()],
760
+ ]);
761
+ const _zkpCircTerminal = new Set([ZKP_CIRCUIT_MATURITY_V2.ARCHIVED]);
762
+ const _zkpProofTrans = new Map([
763
+ [ZKP_PROOF_LIFECYCLE_V2.QUEUED, new Set([ZKP_PROOF_LIFECYCLE_V2.PROVING, ZKP_PROOF_LIFECYCLE_V2.CANCELLED])],
764
+ [ZKP_PROOF_LIFECYCLE_V2.PROVING, new Set([ZKP_PROOF_LIFECYCLE_V2.VERIFIED, ZKP_PROOF_LIFECYCLE_V2.FAILED, ZKP_PROOF_LIFECYCLE_V2.CANCELLED])],
765
+ [ZKP_PROOF_LIFECYCLE_V2.VERIFIED, new Set()],
766
+ [ZKP_PROOF_LIFECYCLE_V2.FAILED, new Set()],
767
+ [ZKP_PROOF_LIFECYCLE_V2.CANCELLED, new Set()],
768
+ ]);
769
+
770
+ const _zkpCircs = new Map();
771
+ const _zkpProofs = new Map();
772
+ let _zkpMaxActivePerOwner = 10;
773
+ let _zkpMaxPendingPerCircuit = 15;
774
+ let _zkpCircuitIdleMs = 30 * 24 * 60 * 60 * 1000;
775
+ let _zkpProofStuckMs = 10 * 60 * 1000;
776
+
777
+ function _zkpPos(n, lbl) { const v = Math.floor(Number(n)); if (!Number.isFinite(v) || v <= 0) throw new Error(`${lbl} must be positive integer`); return v; }
778
+
779
+ export function setMaxActiveZkpCircuitsPerOwnerV2(n) { _zkpMaxActivePerOwner = _zkpPos(n, "maxActiveZkpCircuitsPerOwner"); }
780
+ export function getMaxActiveZkpCircuitsPerOwnerV2() { return _zkpMaxActivePerOwner; }
781
+ export function setMaxPendingZkpProofsPerCircuitV2(n) { _zkpMaxPendingPerCircuit = _zkpPos(n, "maxPendingZkpProofsPerCircuit"); }
782
+ export function getMaxPendingZkpProofsPerCircuitV2() { return _zkpMaxPendingPerCircuit; }
783
+ export function setZkpCircuitIdleMsV2(n) { _zkpCircuitIdleMs = _zkpPos(n, "zkpCircuitIdleMs"); }
784
+ export function getZkpCircuitIdleMsV2() { return _zkpCircuitIdleMs; }
785
+ export function setZkpProofStuckMsV2(n) { _zkpProofStuckMs = _zkpPos(n, "zkpProofStuckMs"); }
786
+ export function getZkpProofStuckMsV2() { return _zkpProofStuckMs; }
787
+
788
+ export function _resetStateZkpEngineV2() {
789
+ _zkpCircs.clear(); _zkpProofs.clear();
790
+ _zkpMaxActivePerOwner = 10; _zkpMaxPendingPerCircuit = 15;
791
+ _zkpCircuitIdleMs = 30 * 24 * 60 * 60 * 1000; _zkpProofStuckMs = 10 * 60 * 1000;
792
+ }
793
+
794
+ export function registerZkpCircuitV2({ id, owner, scheme, metadata } = {}) {
795
+ if (!id || typeof id !== "string") throw new Error("id is required");
796
+ if (!owner || typeof owner !== "string") throw new Error("owner is required");
797
+ if (_zkpCircs.has(id)) throw new Error(`zkp circuit ${id} already registered`);
798
+ const now = Date.now();
799
+ const c = { id, owner, scheme: scheme || "groth16", status: ZKP_CIRCUIT_MATURITY_V2.PENDING, createdAt: now, updatedAt: now, activatedAt: null, archivedAt: null, lastTouchedAt: now, metadata: { ...(metadata || {}) } };
800
+ _zkpCircs.set(id, c);
801
+ return { ...c, metadata: { ...c.metadata } };
802
+ }
803
+ function _zkpCheckC(from, to) { const a = _zkpCircTrans.get(from); if (!a || !a.has(to)) throw new Error(`invalid zkp circuit transition ${from} → ${to}`); }
804
+ function _zkpCountActive(owner) { let n = 0; for (const c of _zkpCircs.values()) if (c.owner === owner && c.status === ZKP_CIRCUIT_MATURITY_V2.ACTIVE) n++; return n; }
805
+
806
+ export function activateZkpCircuitV2(id) {
807
+ const c = _zkpCircs.get(id); if (!c) throw new Error(`zkp circuit ${id} not found`);
808
+ _zkpCheckC(c.status, ZKP_CIRCUIT_MATURITY_V2.ACTIVE);
809
+ const recovery = c.status === ZKP_CIRCUIT_MATURITY_V2.DEPRECATED;
810
+ if (!recovery) { const a = _zkpCountActive(c.owner); if (a >= _zkpMaxActivePerOwner) throw new Error(`max active zkp circuits per owner (${_zkpMaxActivePerOwner}) reached for ${c.owner}`); }
811
+ const now = Date.now(); c.status = ZKP_CIRCUIT_MATURITY_V2.ACTIVE; c.updatedAt = now; c.lastTouchedAt = now; if (!c.activatedAt) c.activatedAt = now;
812
+ return { ...c, metadata: { ...c.metadata } };
813
+ }
814
+ export function deprecateZkpCircuitV2(id) { const c = _zkpCircs.get(id); if (!c) throw new Error(`zkp circuit ${id} not found`); _zkpCheckC(c.status, ZKP_CIRCUIT_MATURITY_V2.DEPRECATED); c.status = ZKP_CIRCUIT_MATURITY_V2.DEPRECATED; c.updatedAt = Date.now(); return { ...c, metadata: { ...c.metadata } }; }
815
+ export function archiveZkpCircuitV2(id) { const c = _zkpCircs.get(id); if (!c) throw new Error(`zkp circuit ${id} not found`); _zkpCheckC(c.status, ZKP_CIRCUIT_MATURITY_V2.ARCHIVED); const now = Date.now(); c.status = ZKP_CIRCUIT_MATURITY_V2.ARCHIVED; c.updatedAt = now; if (!c.archivedAt) c.archivedAt = now; return { ...c, metadata: { ...c.metadata } }; }
816
+ export function touchZkpCircuitV2(id) { const c = _zkpCircs.get(id); if (!c) throw new Error(`zkp circuit ${id} not found`); if (_zkpCircTerminal.has(c.status)) throw new Error(`cannot touch terminal zkp circuit ${id}`); const now = Date.now(); c.lastTouchedAt = now; c.updatedAt = now; return { ...c, metadata: { ...c.metadata } }; }
817
+ export function getZkpCircuitV2(id) { const c = _zkpCircs.get(id); if (!c) return null; return { ...c, metadata: { ...c.metadata } }; }
818
+ export function listZkpCircuitsV2() { return [..._zkpCircs.values()].map((c) => ({ ...c, metadata: { ...c.metadata } })); }
819
+
820
+ function _zkpCountPending(cid) { let n = 0; for (const p of _zkpProofs.values()) if (p.circuitId === cid && (p.status === ZKP_PROOF_LIFECYCLE_V2.QUEUED || p.status === ZKP_PROOF_LIFECYCLE_V2.PROVING)) n++; return n; }
821
+
822
+ export function createZkpProofV2({ id, circuitId, inputs, metadata } = {}) {
823
+ if (!id || typeof id !== "string") throw new Error("id is required");
824
+ if (!circuitId || typeof circuitId !== "string") throw new Error("circuitId is required");
825
+ if (_zkpProofs.has(id)) throw new Error(`zkp proof ${id} already exists`);
826
+ if (!_zkpCircs.has(circuitId)) throw new Error(`zkp circuit ${circuitId} not found`);
827
+ const pending = _zkpCountPending(circuitId);
828
+ if (pending >= _zkpMaxPendingPerCircuit) throw new Error(`max pending zkp proofs per circuit (${_zkpMaxPendingPerCircuit}) reached for ${circuitId}`);
829
+ const now = Date.now();
830
+ const p = { id, circuitId, inputs: inputs || "", status: ZKP_PROOF_LIFECYCLE_V2.QUEUED, createdAt: now, updatedAt: now, startedAt: null, settledAt: null, metadata: { ...(metadata || {}) } };
831
+ _zkpProofs.set(id, p);
832
+ return { ...p, metadata: { ...p.metadata } };
833
+ }
834
+ function _zkpCheckP(from, to) { const a = _zkpProofTrans.get(from); if (!a || !a.has(to)) throw new Error(`invalid zkp proof transition ${from} → ${to}`); }
835
+ export function startZkpProofV2(id) { const p = _zkpProofs.get(id); if (!p) throw new Error(`zkp proof ${id} not found`); _zkpCheckP(p.status, ZKP_PROOF_LIFECYCLE_V2.PROVING); const now = Date.now(); p.status = ZKP_PROOF_LIFECYCLE_V2.PROVING; p.updatedAt = now; if (!p.startedAt) p.startedAt = now; return { ...p, metadata: { ...p.metadata } }; }
836
+ export function verifyZkpProofV2(id) { const p = _zkpProofs.get(id); if (!p) throw new Error(`zkp proof ${id} not found`); _zkpCheckP(p.status, ZKP_PROOF_LIFECYCLE_V2.VERIFIED); const now = Date.now(); p.status = ZKP_PROOF_LIFECYCLE_V2.VERIFIED; p.updatedAt = now; if (!p.settledAt) p.settledAt = now; return { ...p, metadata: { ...p.metadata } }; }
837
+ export function failZkpProofV2(id, reason) { const p = _zkpProofs.get(id); if (!p) throw new Error(`zkp proof ${id} not found`); _zkpCheckP(p.status, ZKP_PROOF_LIFECYCLE_V2.FAILED); const now = Date.now(); p.status = ZKP_PROOF_LIFECYCLE_V2.FAILED; p.updatedAt = now; if (!p.settledAt) p.settledAt = now; if (reason) p.metadata.failReason = String(reason); return { ...p, metadata: { ...p.metadata } }; }
838
+ export function cancelZkpProofV2(id, reason) { const p = _zkpProofs.get(id); if (!p) throw new Error(`zkp proof ${id} not found`); _zkpCheckP(p.status, ZKP_PROOF_LIFECYCLE_V2.CANCELLED); const now = Date.now(); p.status = ZKP_PROOF_LIFECYCLE_V2.CANCELLED; p.updatedAt = now; if (!p.settledAt) p.settledAt = now; if (reason) p.metadata.cancelReason = String(reason); return { ...p, metadata: { ...p.metadata } }; }
839
+ export function getZkpProofV2(id) { const p = _zkpProofs.get(id); if (!p) return null; return { ...p, metadata: { ...p.metadata } }; }
840
+ export function listZkpProofsV2() { return [..._zkpProofs.values()].map((p) => ({ ...p, metadata: { ...p.metadata } })); }
841
+
842
+ export function autoDeprecateIdleZkpCircuitsV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const c of _zkpCircs.values()) if (c.status === ZKP_CIRCUIT_MATURITY_V2.ACTIVE && (t - c.lastTouchedAt) >= _zkpCircuitIdleMs) { c.status = ZKP_CIRCUIT_MATURITY_V2.DEPRECATED; c.updatedAt = t; flipped.push(c.id); } return { flipped, count: flipped.length }; }
843
+ export function autoFailStuckZkpProofsV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const p of _zkpProofs.values()) if (p.status === ZKP_PROOF_LIFECYCLE_V2.PROVING && p.startedAt != null && (t - p.startedAt) >= _zkpProofStuckMs) { p.status = ZKP_PROOF_LIFECYCLE_V2.FAILED; p.updatedAt = t; if (!p.settledAt) p.settledAt = t; p.metadata.failReason = "auto-fail-stuck"; flipped.push(p.id); } return { flipped, count: flipped.length }; }
844
+
845
+ export function getZkpEngineGovStatsV2() {
846
+ const circuitsByStatus = {}; for (const s of Object.values(ZKP_CIRCUIT_MATURITY_V2)) circuitsByStatus[s] = 0; for (const c of _zkpCircs.values()) circuitsByStatus[c.status]++;
847
+ const proofsByStatus = {}; for (const s of Object.values(ZKP_PROOF_LIFECYCLE_V2)) proofsByStatus[s] = 0; for (const p of _zkpProofs.values()) proofsByStatus[p.status]++;
848
+ return { totalCircuitsV2: _zkpCircs.size, totalProofsV2: _zkpProofs.size, maxActiveZkpCircuitsPerOwner: _zkpMaxActivePerOwner, maxPendingZkpProofsPerCircuit: _zkpMaxPendingPerCircuit, zkpCircuitIdleMs: _zkpCircuitIdleMs, zkpProofStuckMs: _zkpProofStuckMs, circuitsByStatus, proofsByStatus };
849
+ }