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
@@ -927,25 +927,53 @@ export function getStats(db) {
927
927
  };
928
928
  }
929
929
 
930
-
931
930
  // ===== V2 Surface: Pipeline Orchestrator governance overlay (CLI v0.137.0) =====
932
931
  export const PIPELINE_MATURITY_V2 = Object.freeze({
933
- PENDING: "pending", ACTIVE: "active", PAUSED: "paused", ARCHIVED: "archived",
932
+ PENDING: "pending",
933
+ ACTIVE: "active",
934
+ PAUSED: "paused",
935
+ ARCHIVED: "archived",
934
936
  });
935
937
  export const PIPELINE_RUN_LIFECYCLE_V2 = Object.freeze({
936
- QUEUED: "queued", RUNNING: "running", COMPLETED: "completed", FAILED: "failed", CANCELLED: "cancelled",
938
+ QUEUED: "queued",
939
+ RUNNING: "running",
940
+ COMPLETED: "completed",
941
+ FAILED: "failed",
942
+ CANCELLED: "cancelled",
937
943
  });
938
944
 
939
945
  const _pipTrans = new Map([
940
- [PIPELINE_MATURITY_V2.PENDING, new Set([PIPELINE_MATURITY_V2.ACTIVE, PIPELINE_MATURITY_V2.ARCHIVED])],
941
- [PIPELINE_MATURITY_V2.ACTIVE, new Set([PIPELINE_MATURITY_V2.PAUSED, PIPELINE_MATURITY_V2.ARCHIVED])],
942
- [PIPELINE_MATURITY_V2.PAUSED, new Set([PIPELINE_MATURITY_V2.ACTIVE, PIPELINE_MATURITY_V2.ARCHIVED])],
946
+ [
947
+ PIPELINE_MATURITY_V2.PENDING,
948
+ new Set([PIPELINE_MATURITY_V2.ACTIVE, PIPELINE_MATURITY_V2.ARCHIVED]),
949
+ ],
950
+ [
951
+ PIPELINE_MATURITY_V2.ACTIVE,
952
+ new Set([PIPELINE_MATURITY_V2.PAUSED, PIPELINE_MATURITY_V2.ARCHIVED]),
953
+ ],
954
+ [
955
+ PIPELINE_MATURITY_V2.PAUSED,
956
+ new Set([PIPELINE_MATURITY_V2.ACTIVE, PIPELINE_MATURITY_V2.ARCHIVED]),
957
+ ],
943
958
  [PIPELINE_MATURITY_V2.ARCHIVED, new Set()],
944
959
  ]);
945
960
  const _pipTerminal = new Set([PIPELINE_MATURITY_V2.ARCHIVED]);
946
961
  const _pipRunTrans = new Map([
947
- [PIPELINE_RUN_LIFECYCLE_V2.QUEUED, new Set([PIPELINE_RUN_LIFECYCLE_V2.RUNNING, PIPELINE_RUN_LIFECYCLE_V2.CANCELLED])],
948
- [PIPELINE_RUN_LIFECYCLE_V2.RUNNING, new Set([PIPELINE_RUN_LIFECYCLE_V2.COMPLETED, PIPELINE_RUN_LIFECYCLE_V2.FAILED, PIPELINE_RUN_LIFECYCLE_V2.CANCELLED])],
962
+ [
963
+ PIPELINE_RUN_LIFECYCLE_V2.QUEUED,
964
+ new Set([
965
+ PIPELINE_RUN_LIFECYCLE_V2.RUNNING,
966
+ PIPELINE_RUN_LIFECYCLE_V2.CANCELLED,
967
+ ]),
968
+ ],
969
+ [
970
+ PIPELINE_RUN_LIFECYCLE_V2.RUNNING,
971
+ new Set([
972
+ PIPELINE_RUN_LIFECYCLE_V2.COMPLETED,
973
+ PIPELINE_RUN_LIFECYCLE_V2.FAILED,
974
+ PIPELINE_RUN_LIFECYCLE_V2.CANCELLED,
975
+ ]),
976
+ ],
949
977
  [PIPELINE_RUN_LIFECYCLE_V2.COMPLETED, new Set()],
950
978
  [PIPELINE_RUN_LIFECYCLE_V2.FAILED, new Set()],
951
979
  [PIPELINE_RUN_LIFECYCLE_V2.CANCELLED, new Set()],
@@ -958,21 +986,45 @@ let _pipMaxPendingPerPip = 20;
958
986
  let _pipIdleMs = 3 * 24 * 60 * 60 * 1000;
959
987
  let _pipRunStuckMs = 10 * 60 * 1000;
960
988
 
961
- function _pipPos(n, lbl) { const v = Math.floor(Number(n)); if (!Number.isFinite(v) || v <= 0) throw new Error(`${lbl} must be positive integer`); return v; }
989
+ function _pipPos(n, lbl) {
990
+ const v = Math.floor(Number(n));
991
+ if (!Number.isFinite(v) || v <= 0)
992
+ throw new Error(`${lbl} must be positive integer`);
993
+ return v;
994
+ }
962
995
 
963
- export function setMaxActivePipelinesPerOwnerV2(n) { _pipMaxActivePerOwner = _pipPos(n, "maxActivePipelinesPerOwner"); }
964
- export function getMaxActivePipelinesPerOwnerV2() { return _pipMaxActivePerOwner; }
965
- export function setMaxPendingPipelineRunsPerPipelineV2(n) { _pipMaxPendingPerPip = _pipPos(n, "maxPendingPipelineRunsPerPipeline"); }
966
- export function getMaxPendingPipelineRunsPerPipelineV2() { return _pipMaxPendingPerPip; }
967
- export function setPipelineIdleMsV2(n) { _pipIdleMs = _pipPos(n, "pipelineIdleMs"); }
968
- export function getPipelineIdleMsV2() { return _pipIdleMs; }
969
- export function setPipelineRunStuckMsV2(n) { _pipRunStuckMs = _pipPos(n, "pipelineRunStuckMs"); }
970
- export function getPipelineRunStuckMsV2() { return _pipRunStuckMs; }
996
+ export function setMaxActivePipelinesPerOwnerV2(n) {
997
+ _pipMaxActivePerOwner = _pipPos(n, "maxActivePipelinesPerOwner");
998
+ }
999
+ export function getMaxActivePipelinesPerOwnerV2() {
1000
+ return _pipMaxActivePerOwner;
1001
+ }
1002
+ export function setMaxPendingPipelineRunsPerPipelineV2(n) {
1003
+ _pipMaxPendingPerPip = _pipPos(n, "maxPendingPipelineRunsPerPipeline");
1004
+ }
1005
+ export function getMaxPendingPipelineRunsPerPipelineV2() {
1006
+ return _pipMaxPendingPerPip;
1007
+ }
1008
+ export function setPipelineIdleMsV2(n) {
1009
+ _pipIdleMs = _pipPos(n, "pipelineIdleMs");
1010
+ }
1011
+ export function getPipelineIdleMsV2() {
1012
+ return _pipIdleMs;
1013
+ }
1014
+ export function setPipelineRunStuckMsV2(n) {
1015
+ _pipRunStuckMs = _pipPos(n, "pipelineRunStuckMs");
1016
+ }
1017
+ export function getPipelineRunStuckMsV2() {
1018
+ return _pipRunStuckMs;
1019
+ }
971
1020
 
972
1021
  export function _resetStatePipelineOrchestratorV2() {
973
- _pips.clear(); _pipRuns.clear();
974
- _pipMaxActivePerOwner = 10; _pipMaxPendingPerPip = 20;
975
- _pipIdleMs = 3 * 24 * 60 * 60 * 1000; _pipRunStuckMs = 10 * 60 * 1000;
1022
+ _pips.clear();
1023
+ _pipRuns.clear();
1024
+ _pipMaxActivePerOwner = 10;
1025
+ _pipMaxPendingPerPip = 20;
1026
+ _pipIdleMs = 3 * 24 * 60 * 60 * 1000;
1027
+ _pipRunStuckMs = 10 * 60 * 1000;
976
1028
  }
977
1029
 
978
1030
  export function registerPipelineV2({ id, owner, name, metadata } = {}) {
@@ -980,54 +1032,242 @@ export function registerPipelineV2({ id, owner, name, metadata } = {}) {
980
1032
  if (!owner || typeof owner !== "string") throw new Error("owner is required");
981
1033
  if (_pips.has(id)) throw new Error(`pipeline ${id} already registered`);
982
1034
  const now = Date.now();
983
- const p = { id, owner, name: name || id, status: PIPELINE_MATURITY_V2.PENDING, createdAt: now, updatedAt: now, activatedAt: null, archivedAt: null, lastTouchedAt: now, metadata: { ...(metadata || {}) } };
1035
+ const p = {
1036
+ id,
1037
+ owner,
1038
+ name: name || id,
1039
+ status: PIPELINE_MATURITY_V2.PENDING,
1040
+ createdAt: now,
1041
+ updatedAt: now,
1042
+ activatedAt: null,
1043
+ archivedAt: null,
1044
+ lastTouchedAt: now,
1045
+ metadata: { ...(metadata || {}) },
1046
+ };
984
1047
  _pips.set(id, p);
985
1048
  return { ...p, metadata: { ...p.metadata } };
986
1049
  }
987
- function _pipCheckP(from, to) { const a = _pipTrans.get(from); if (!a || !a.has(to)) throw new Error(`invalid pipeline transition ${from} → ${to}`); }
988
- function _pipCountActive(owner) { let n = 0; for (const p of _pips.values()) if (p.owner === owner && p.status === PIPELINE_MATURITY_V2.ACTIVE) n++; return n; }
1050
+ function _pipCheckP(from, to) {
1051
+ const a = _pipTrans.get(from);
1052
+ if (!a || !a.has(to))
1053
+ throw new Error(`invalid pipeline transition ${from} → ${to}`);
1054
+ }
1055
+ function _pipCountActive(owner) {
1056
+ let n = 0;
1057
+ for (const p of _pips.values())
1058
+ if (p.owner === owner && p.status === PIPELINE_MATURITY_V2.ACTIVE) n++;
1059
+ return n;
1060
+ }
989
1061
 
990
1062
  export function activatePipelineV2(id) {
991
- const p = _pips.get(id); if (!p) throw new Error(`pipeline ${id} not found`);
1063
+ const p = _pips.get(id);
1064
+ if (!p) throw new Error(`pipeline ${id} not found`);
992
1065
  _pipCheckP(p.status, PIPELINE_MATURITY_V2.ACTIVE);
993
1066
  const recovery = p.status === PIPELINE_MATURITY_V2.PAUSED;
994
- if (!recovery) { const c = _pipCountActive(p.owner); if (c >= _pipMaxActivePerOwner) throw new Error(`max active pipelines per owner (${_pipMaxActivePerOwner}) reached for ${p.owner}`); }
995
- const now = Date.now(); p.status = PIPELINE_MATURITY_V2.ACTIVE; p.updatedAt = now; p.lastTouchedAt = now; if (!p.activatedAt) p.activatedAt = now;
1067
+ if (!recovery) {
1068
+ const c = _pipCountActive(p.owner);
1069
+ if (c >= _pipMaxActivePerOwner)
1070
+ throw new Error(
1071
+ `max active pipelines per owner (${_pipMaxActivePerOwner}) reached for ${p.owner}`,
1072
+ );
1073
+ }
1074
+ const now = Date.now();
1075
+ p.status = PIPELINE_MATURITY_V2.ACTIVE;
1076
+ p.updatedAt = now;
1077
+ p.lastTouchedAt = now;
1078
+ if (!p.activatedAt) p.activatedAt = now;
1079
+ return { ...p, metadata: { ...p.metadata } };
1080
+ }
1081
+ export function pausePipelineV2(id) {
1082
+ const p = _pips.get(id);
1083
+ if (!p) throw new Error(`pipeline ${id} not found`);
1084
+ _pipCheckP(p.status, PIPELINE_MATURITY_V2.PAUSED);
1085
+ p.status = PIPELINE_MATURITY_V2.PAUSED;
1086
+ p.updatedAt = Date.now();
1087
+ return { ...p, metadata: { ...p.metadata } };
1088
+ }
1089
+ export function archivePipelineV2(id) {
1090
+ const p = _pips.get(id);
1091
+ if (!p) throw new Error(`pipeline ${id} not found`);
1092
+ _pipCheckP(p.status, PIPELINE_MATURITY_V2.ARCHIVED);
1093
+ const now = Date.now();
1094
+ p.status = PIPELINE_MATURITY_V2.ARCHIVED;
1095
+ p.updatedAt = now;
1096
+ if (!p.archivedAt) p.archivedAt = now;
1097
+ return { ...p, metadata: { ...p.metadata } };
1098
+ }
1099
+ export function touchPipelineV2(id) {
1100
+ const p = _pips.get(id);
1101
+ if (!p) throw new Error(`pipeline ${id} not found`);
1102
+ if (_pipTerminal.has(p.status))
1103
+ throw new Error(`cannot touch terminal pipeline ${id}`);
1104
+ const now = Date.now();
1105
+ p.lastTouchedAt = now;
1106
+ p.updatedAt = now;
1107
+ return { ...p, metadata: { ...p.metadata } };
1108
+ }
1109
+ export function getPipelineV2(id) {
1110
+ const p = _pips.get(id);
1111
+ if (!p) return null;
996
1112
  return { ...p, metadata: { ...p.metadata } };
997
1113
  }
998
- export function pausePipelineV2(id) { const p = _pips.get(id); if (!p) throw new Error(`pipeline ${id} not found`); _pipCheckP(p.status, PIPELINE_MATURITY_V2.PAUSED); p.status = PIPELINE_MATURITY_V2.PAUSED; p.updatedAt = Date.now(); return { ...p, metadata: { ...p.metadata } }; }
999
- export function archivePipelineV2(id) { const p = _pips.get(id); if (!p) throw new Error(`pipeline ${id} not found`); _pipCheckP(p.status, PIPELINE_MATURITY_V2.ARCHIVED); const now = Date.now(); p.status = PIPELINE_MATURITY_V2.ARCHIVED; p.updatedAt = now; if (!p.archivedAt) p.archivedAt = now; return { ...p, metadata: { ...p.metadata } }; }
1000
- export function touchPipelineV2(id) { const p = _pips.get(id); if (!p) throw new Error(`pipeline ${id} not found`); if (_pipTerminal.has(p.status)) throw new Error(`cannot touch terminal pipeline ${id}`); const now = Date.now(); p.lastTouchedAt = now; p.updatedAt = now; return { ...p, metadata: { ...p.metadata } }; }
1001
- export function getPipelineV2(id) { const p = _pips.get(id); if (!p) return null; return { ...p, metadata: { ...p.metadata } }; }
1002
- export function listPipelinesV2() { return [..._pips.values()].map((p) => ({ ...p, metadata: { ...p.metadata } })); }
1114
+ export function listPipelinesV2() {
1115
+ return [..._pips.values()].map((p) => ({
1116
+ ...p,
1117
+ metadata: { ...p.metadata },
1118
+ }));
1119
+ }
1003
1120
 
1004
- function _pipCountPendingRuns(pid) { let n = 0; for (const r of _pipRuns.values()) if (r.pipelineId === pid && (r.status === PIPELINE_RUN_LIFECYCLE_V2.QUEUED || r.status === PIPELINE_RUN_LIFECYCLE_V2.RUNNING)) n++; return n; }
1121
+ function _pipCountPendingRuns(pid) {
1122
+ let n = 0;
1123
+ for (const r of _pipRuns.values())
1124
+ if (
1125
+ r.pipelineId === pid &&
1126
+ (r.status === PIPELINE_RUN_LIFECYCLE_V2.QUEUED ||
1127
+ r.status === PIPELINE_RUN_LIFECYCLE_V2.RUNNING)
1128
+ )
1129
+ n++;
1130
+ return n;
1131
+ }
1005
1132
 
1006
- export function createPipelineRunV2({ id, pipelineId, trigger, metadata } = {}) {
1133
+ export function createPipelineRunV2({
1134
+ id,
1135
+ pipelineId,
1136
+ trigger,
1137
+ metadata,
1138
+ } = {}) {
1007
1139
  if (!id || typeof id !== "string") throw new Error("id is required");
1008
- if (!pipelineId || typeof pipelineId !== "string") throw new Error("pipelineId is required");
1140
+ if (!pipelineId || typeof pipelineId !== "string")
1141
+ throw new Error("pipelineId is required");
1009
1142
  if (_pipRuns.has(id)) throw new Error(`pipeline run ${id} already exists`);
1010
- if (!_pips.has(pipelineId)) throw new Error(`pipeline ${pipelineId} not found`);
1143
+ if (!_pips.has(pipelineId))
1144
+ throw new Error(`pipeline ${pipelineId} not found`);
1011
1145
  const pending = _pipCountPendingRuns(pipelineId);
1012
- if (pending >= _pipMaxPendingPerPip) throw new Error(`max pending pipeline runs per pipeline (${_pipMaxPendingPerPip}) reached for ${pipelineId}`);
1146
+ if (pending >= _pipMaxPendingPerPip)
1147
+ throw new Error(
1148
+ `max pending pipeline runs per pipeline (${_pipMaxPendingPerPip}) reached for ${pipelineId}`,
1149
+ );
1013
1150
  const now = Date.now();
1014
- const r = { id, pipelineId, trigger: trigger || "manual", status: PIPELINE_RUN_LIFECYCLE_V2.QUEUED, createdAt: now, updatedAt: now, startedAt: null, settledAt: null, metadata: { ...(metadata || {}) } };
1151
+ const r = {
1152
+ id,
1153
+ pipelineId,
1154
+ trigger: trigger || "manual",
1155
+ status: PIPELINE_RUN_LIFECYCLE_V2.QUEUED,
1156
+ createdAt: now,
1157
+ updatedAt: now,
1158
+ startedAt: null,
1159
+ settledAt: null,
1160
+ metadata: { ...(metadata || {}) },
1161
+ };
1015
1162
  _pipRuns.set(id, r);
1016
1163
  return { ...r, metadata: { ...r.metadata } };
1017
1164
  }
1018
- function _pipCheckR(from, to) { const a = _pipRunTrans.get(from); if (!a || !a.has(to)) throw new Error(`invalid pipeline run transition ${from} → ${to}`); }
1019
- export function startPipelineRunV2(id) { const r = _pipRuns.get(id); if (!r) throw new Error(`pipeline run ${id} not found`); _pipCheckR(r.status, PIPELINE_RUN_LIFECYCLE_V2.RUNNING); const now = Date.now(); r.status = PIPELINE_RUN_LIFECYCLE_V2.RUNNING; r.updatedAt = now; if (!r.startedAt) r.startedAt = now; return { ...r, metadata: { ...r.metadata } }; }
1020
- export function completePipelineRunV2(id) { const r = _pipRuns.get(id); if (!r) throw new Error(`pipeline run ${id} not found`); _pipCheckR(r.status, PIPELINE_RUN_LIFECYCLE_V2.COMPLETED); const now = Date.now(); r.status = PIPELINE_RUN_LIFECYCLE_V2.COMPLETED; r.updatedAt = now; if (!r.settledAt) r.settledAt = now; return { ...r, metadata: { ...r.metadata } }; }
1021
- export function failPipelineRunV2(id, reason) { const r = _pipRuns.get(id); if (!r) throw new Error(`pipeline run ${id} not found`); _pipCheckR(r.status, PIPELINE_RUN_LIFECYCLE_V2.FAILED); const now = Date.now(); r.status = PIPELINE_RUN_LIFECYCLE_V2.FAILED; r.updatedAt = now; if (!r.settledAt) r.settledAt = now; if (reason) r.metadata.failReason = String(reason); return { ...r, metadata: { ...r.metadata } }; }
1022
- export function cancelPipelineRunV2(id, reason) { const r = _pipRuns.get(id); if (!r) throw new Error(`pipeline run ${id} not found`); _pipCheckR(r.status, PIPELINE_RUN_LIFECYCLE_V2.CANCELLED); const now = Date.now(); r.status = PIPELINE_RUN_LIFECYCLE_V2.CANCELLED; r.updatedAt = now; if (!r.settledAt) r.settledAt = now; if (reason) r.metadata.cancelReason = String(reason); return { ...r, metadata: { ...r.metadata } }; }
1023
- export function getPipelineRunV2(id) { const r = _pipRuns.get(id); if (!r) return null; return { ...r, metadata: { ...r.metadata } }; }
1024
- export function listPipelineRunsV2() { return [..._pipRuns.values()].map((r) => ({ ...r, metadata: { ...r.metadata } })); }
1165
+ function _pipCheckR(from, to) {
1166
+ const a = _pipRunTrans.get(from);
1167
+ if (!a || !a.has(to))
1168
+ throw new Error(`invalid pipeline run transition ${from} ${to}`);
1169
+ }
1170
+ export function startPipelineRunV2(id) {
1171
+ const r = _pipRuns.get(id);
1172
+ if (!r) throw new Error(`pipeline run ${id} not found`);
1173
+ _pipCheckR(r.status, PIPELINE_RUN_LIFECYCLE_V2.RUNNING);
1174
+ const now = Date.now();
1175
+ r.status = PIPELINE_RUN_LIFECYCLE_V2.RUNNING;
1176
+ r.updatedAt = now;
1177
+ if (!r.startedAt) r.startedAt = now;
1178
+ return { ...r, metadata: { ...r.metadata } };
1179
+ }
1180
+ export function completePipelineRunV2(id) {
1181
+ const r = _pipRuns.get(id);
1182
+ if (!r) throw new Error(`pipeline run ${id} not found`);
1183
+ _pipCheckR(r.status, PIPELINE_RUN_LIFECYCLE_V2.COMPLETED);
1184
+ const now = Date.now();
1185
+ r.status = PIPELINE_RUN_LIFECYCLE_V2.COMPLETED;
1186
+ r.updatedAt = now;
1187
+ if (!r.settledAt) r.settledAt = now;
1188
+ return { ...r, metadata: { ...r.metadata } };
1189
+ }
1190
+ export function failPipelineRunV2(id, reason) {
1191
+ const r = _pipRuns.get(id);
1192
+ if (!r) throw new Error(`pipeline run ${id} not found`);
1193
+ _pipCheckR(r.status, PIPELINE_RUN_LIFECYCLE_V2.FAILED);
1194
+ const now = Date.now();
1195
+ r.status = PIPELINE_RUN_LIFECYCLE_V2.FAILED;
1196
+ r.updatedAt = now;
1197
+ if (!r.settledAt) r.settledAt = now;
1198
+ if (reason) r.metadata.failReason = String(reason);
1199
+ return { ...r, metadata: { ...r.metadata } };
1200
+ }
1201
+ export function cancelPipelineRunV2(id, reason) {
1202
+ const r = _pipRuns.get(id);
1203
+ if (!r) throw new Error(`pipeline run ${id} not found`);
1204
+ _pipCheckR(r.status, PIPELINE_RUN_LIFECYCLE_V2.CANCELLED);
1205
+ const now = Date.now();
1206
+ r.status = PIPELINE_RUN_LIFECYCLE_V2.CANCELLED;
1207
+ r.updatedAt = now;
1208
+ if (!r.settledAt) r.settledAt = now;
1209
+ if (reason) r.metadata.cancelReason = String(reason);
1210
+ return { ...r, metadata: { ...r.metadata } };
1211
+ }
1212
+ export function getPipelineRunV2(id) {
1213
+ const r = _pipRuns.get(id);
1214
+ if (!r) return null;
1215
+ return { ...r, metadata: { ...r.metadata } };
1216
+ }
1217
+ export function listPipelineRunsV2() {
1218
+ return [..._pipRuns.values()].map((r) => ({
1219
+ ...r,
1220
+ metadata: { ...r.metadata },
1221
+ }));
1222
+ }
1025
1223
 
1026
- export function autoPauseIdlePipelinesV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const p of _pips.values()) if (p.status === PIPELINE_MATURITY_V2.ACTIVE && (t - p.lastTouchedAt) >= _pipIdleMs) { p.status = PIPELINE_MATURITY_V2.PAUSED; p.updatedAt = t; flipped.push(p.id); } return { flipped, count: flipped.length }; }
1027
- export function autoFailStuckPipelineRunsV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const r of _pipRuns.values()) if (r.status === PIPELINE_RUN_LIFECYCLE_V2.RUNNING && r.startedAt != null && (t - r.startedAt) >= _pipRunStuckMs) { r.status = PIPELINE_RUN_LIFECYCLE_V2.FAILED; r.updatedAt = t; if (!r.settledAt) r.settledAt = t; r.metadata.failReason = "auto-fail-stuck"; flipped.push(r.id); } return { flipped, count: flipped.length }; }
1224
+ export function autoPauseIdlePipelinesV2({ now } = {}) {
1225
+ const t = now ?? Date.now();
1226
+ const flipped = [];
1227
+ for (const p of _pips.values())
1228
+ if (
1229
+ p.status === PIPELINE_MATURITY_V2.ACTIVE &&
1230
+ t - p.lastTouchedAt >= _pipIdleMs
1231
+ ) {
1232
+ p.status = PIPELINE_MATURITY_V2.PAUSED;
1233
+ p.updatedAt = t;
1234
+ flipped.push(p.id);
1235
+ }
1236
+ return { flipped, count: flipped.length };
1237
+ }
1238
+ export function autoFailStuckPipelineRunsV2({ now } = {}) {
1239
+ const t = now ?? Date.now();
1240
+ const flipped = [];
1241
+ for (const r of _pipRuns.values())
1242
+ if (
1243
+ r.status === PIPELINE_RUN_LIFECYCLE_V2.RUNNING &&
1244
+ r.startedAt != null &&
1245
+ t - r.startedAt >= _pipRunStuckMs
1246
+ ) {
1247
+ r.status = PIPELINE_RUN_LIFECYCLE_V2.FAILED;
1248
+ r.updatedAt = t;
1249
+ if (!r.settledAt) r.settledAt = t;
1250
+ r.metadata.failReason = "auto-fail-stuck";
1251
+ flipped.push(r.id);
1252
+ }
1253
+ return { flipped, count: flipped.length };
1254
+ }
1028
1255
 
1029
1256
  export function getPipelineOrchestratorGovStatsV2() {
1030
- const pipelinesByStatus = {}; for (const s of Object.values(PIPELINE_MATURITY_V2)) pipelinesByStatus[s] = 0; for (const p of _pips.values()) pipelinesByStatus[p.status]++;
1031
- const runsByStatus = {}; for (const s of Object.values(PIPELINE_RUN_LIFECYCLE_V2)) runsByStatus[s] = 0; for (const r of _pipRuns.values()) runsByStatus[r.status]++;
1032
- return { totalPipelinesV2: _pips.size, totalRunsV2: _pipRuns.size, maxActivePipelinesPerOwner: _pipMaxActivePerOwner, maxPendingPipelineRunsPerPipeline: _pipMaxPendingPerPip, pipelineIdleMs: _pipIdleMs, pipelineRunStuckMs: _pipRunStuckMs, pipelinesByStatus, runsByStatus };
1257
+ const pipelinesByStatus = {};
1258
+ for (const s of Object.values(PIPELINE_MATURITY_V2)) pipelinesByStatus[s] = 0;
1259
+ for (const p of _pips.values()) pipelinesByStatus[p.status]++;
1260
+ const runsByStatus = {};
1261
+ for (const s of Object.values(PIPELINE_RUN_LIFECYCLE_V2)) runsByStatus[s] = 0;
1262
+ for (const r of _pipRuns.values()) runsByStatus[r.status]++;
1263
+ return {
1264
+ totalPipelinesV2: _pips.size,
1265
+ totalRunsV2: _pipRuns.size,
1266
+ maxActivePipelinesPerOwner: _pipMaxActivePerOwner,
1267
+ maxPendingPipelineRunsPerPipeline: _pipMaxPendingPerPip,
1268
+ pipelineIdleMs: _pipIdleMs,
1269
+ pipelineRunStuckMs: _pipRunStuckMs,
1270
+ pipelinesByStatus,
1271
+ runsByStatus,
1272
+ };
1033
1273
  }