@dcyfr/ai 1.0.4 → 2.1.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 (411) hide show
  1. package/CHANGELOG.md +106 -0
  2. package/README.md +381 -9
  3. package/dist/ai/agents/agent-loader.d.ts +12 -0
  4. package/dist/ai/agents/agent-loader.d.ts.map +1 -1
  5. package/dist/ai/agents/agent-loader.js +74 -65
  6. package/dist/ai/agents/agent-loader.js.map +1 -1
  7. package/dist/ai/agents/agent-registry.d.ts +2 -0
  8. package/dist/ai/agents/agent-registry.d.ts.map +1 -1
  9. package/dist/ai/agents/agent-registry.js +15 -14
  10. package/dist/ai/agents/agent-registry.js.map +1 -1
  11. package/dist/ai/agents/agent-router.d.ts +20 -5
  12. package/dist/ai/agents/agent-router.d.ts.map +1 -1
  13. package/dist/ai/agents/agent-router.js +89 -43
  14. package/dist/ai/agents/agent-router.js.map +1 -1
  15. package/dist/ai/agents/index.d.ts +6 -1
  16. package/dist/ai/agents/index.d.ts.map +1 -1
  17. package/dist/ai/agents/index.js +9 -3
  18. package/dist/ai/agents/index.js.map +1 -1
  19. package/dist/ai/agents/instruction-template.d.ts +45 -0
  20. package/dist/ai/agents/instruction-template.d.ts.map +1 -0
  21. package/dist/ai/agents/instruction-template.js +197 -0
  22. package/dist/ai/agents/instruction-template.js.map +1 -0
  23. package/dist/ai/agents/persona-resolver.d.ts +90 -0
  24. package/dist/ai/agents/persona-resolver.d.ts.map +1 -0
  25. package/dist/ai/agents/persona-resolver.js +121 -0
  26. package/dist/ai/agents/persona-resolver.js.map +1 -0
  27. package/dist/ai/agents/schema.d.ts +166 -0
  28. package/dist/ai/agents/schema.d.ts.map +1 -0
  29. package/dist/ai/agents/schema.js +94 -0
  30. package/dist/ai/agents/schema.js.map +1 -0
  31. package/dist/ai/agents/types.d.ts +102 -0
  32. package/dist/ai/agents/types.d.ts.map +1 -1
  33. package/dist/ai/agents-builtin/architecture/index.js +3 -3
  34. package/dist/ai/agents-builtin/content/index.js +1 -1
  35. package/dist/ai/agents-builtin/data/index.js +1 -1
  36. package/dist/ai/agents-builtin/development/index.js +4 -4
  37. package/dist/ai/agents-builtin/devops/index.js +1 -1
  38. package/dist/ai/agents-builtin/index.js +33 -33
  39. package/dist/ai/agents-builtin/performance/index.js +1 -1
  40. package/dist/ai/agents-builtin/research/index.js +1 -1
  41. package/dist/ai/agents-builtin/security/index.js +1 -1
  42. package/dist/ai/agents-builtin/testing/index.js +2 -2
  43. package/dist/ai/config/loader.d.ts.map +1 -1
  44. package/dist/ai/config/loader.js +6 -3
  45. package/dist/ai/config/loader.js.map +1 -1
  46. package/dist/ai/config/schema.d.ts +242 -1156
  47. package/dist/ai/config/schema.d.ts.map +1 -1
  48. package/dist/ai/config/schema.js +69 -20
  49. package/dist/ai/config/schema.js.map +1 -1
  50. package/dist/ai/core/provider-registry.d.ts +32 -0
  51. package/dist/ai/core/provider-registry.d.ts.map +1 -1
  52. package/dist/ai/core/provider-registry.js +189 -14
  53. package/dist/ai/core/provider-registry.js.map +1 -1
  54. package/dist/ai/core/telemetry-engine.d.ts +26 -0
  55. package/dist/ai/core/telemetry-engine.d.ts.map +1 -1
  56. package/dist/ai/core/telemetry-engine.js +81 -1
  57. package/dist/ai/core/telemetry-engine.js.map +1 -1
  58. package/dist/ai/delegation/agent-registry.d.ts +143 -0
  59. package/dist/ai/delegation/agent-registry.d.ts.map +1 -0
  60. package/dist/ai/delegation/agent-registry.js +231 -0
  61. package/dist/ai/delegation/agent-registry.js.map +1 -0
  62. package/dist/ai/delegation/blast-radius-tracker.d.ts +65 -0
  63. package/dist/ai/delegation/blast-radius-tracker.d.ts.map +1 -0
  64. package/dist/ai/delegation/blast-radius-tracker.js +81 -0
  65. package/dist/ai/delegation/blast-radius-tracker.js.map +1 -0
  66. package/dist/ai/delegation/capability-bootstrap.d.ts +40 -0
  67. package/dist/ai/delegation/capability-bootstrap.d.ts.map +1 -0
  68. package/dist/ai/delegation/capability-bootstrap.js +431 -0
  69. package/dist/ai/delegation/capability-bootstrap.js.map +1 -0
  70. package/dist/ai/delegation/capability-registry.d.ts +81 -0
  71. package/dist/ai/delegation/capability-registry.d.ts.map +1 -0
  72. package/dist/ai/delegation/capability-registry.js +339 -0
  73. package/dist/ai/delegation/capability-registry.js.map +1 -0
  74. package/dist/ai/delegation/chain-tracker.d.ts +152 -0
  75. package/dist/ai/delegation/chain-tracker.d.ts.map +1 -0
  76. package/dist/ai/delegation/chain-tracker.js +336 -0
  77. package/dist/ai/delegation/chain-tracker.js.map +1 -0
  78. package/dist/ai/delegation/circuit-breaker.d.ts +59 -0
  79. package/dist/ai/delegation/circuit-breaker.d.ts.map +1 -0
  80. package/dist/ai/delegation/circuit-breaker.js +153 -0
  81. package/dist/ai/delegation/circuit-breaker.js.map +1 -0
  82. package/dist/ai/delegation/contract-manager.d.ts +415 -0
  83. package/dist/ai/delegation/contract-manager.d.ts.map +1 -0
  84. package/dist/ai/delegation/contract-manager.js +1258 -0
  85. package/dist/ai/delegation/contract-manager.js.map +1 -0
  86. package/dist/ai/delegation/delegation-manager.d.ts +505 -0
  87. package/dist/ai/delegation/delegation-manager.d.ts.map +1 -0
  88. package/dist/ai/delegation/delegation-manager.js +773 -0
  89. package/dist/ai/delegation/delegation-manager.js.map +1 -0
  90. package/dist/ai/delegation/event-schemas.d.ts +101 -0
  91. package/dist/ai/delegation/event-schemas.d.ts.map +1 -0
  92. package/dist/ai/delegation/event-schemas.js +59 -0
  93. package/dist/ai/delegation/event-schemas.js.map +1 -0
  94. package/dist/ai/delegation/execution-mode-dashboard.d.ts +109 -0
  95. package/dist/ai/delegation/execution-mode-dashboard.d.ts.map +1 -0
  96. package/dist/ai/delegation/execution-mode-dashboard.js +167 -0
  97. package/dist/ai/delegation/execution-mode-dashboard.js.map +1 -0
  98. package/dist/ai/delegation/feature-flags.d.ts +191 -0
  99. package/dist/ai/delegation/feature-flags.d.ts.map +1 -0
  100. package/dist/ai/delegation/feature-flags.js +332 -0
  101. package/dist/ai/delegation/feature-flags.js.map +1 -0
  102. package/dist/ai/delegation/index.d.ts +51 -0
  103. package/dist/ai/delegation/index.d.ts.map +1 -0
  104. package/dist/ai/delegation/index.js +39 -0
  105. package/dist/ai/delegation/index.js.map +1 -0
  106. package/dist/ai/delegation/middleware/chain-depth-middleware.d.ts +39 -0
  107. package/dist/ai/delegation/middleware/chain-depth-middleware.d.ts.map +1 -0
  108. package/dist/ai/delegation/middleware/chain-depth-middleware.js +77 -0
  109. package/dist/ai/delegation/middleware/chain-depth-middleware.js.map +1 -0
  110. package/dist/ai/delegation/middleware/chain-tracker-middleware.d.ts +46 -0
  111. package/dist/ai/delegation/middleware/chain-tracker-middleware.d.ts.map +1 -0
  112. package/dist/ai/delegation/middleware/chain-tracker-middleware.js +89 -0
  113. package/dist/ai/delegation/middleware/chain-tracker-middleware.js.map +1 -0
  114. package/dist/ai/delegation/middleware/content-policy-middleware.d.ts +31 -0
  115. package/dist/ai/delegation/middleware/content-policy-middleware.d.ts.map +1 -0
  116. package/dist/ai/delegation/middleware/content-policy-middleware.js +82 -0
  117. package/dist/ai/delegation/middleware/content-policy-middleware.js.map +1 -0
  118. package/dist/ai/delegation/middleware/feature-flag-middleware.d.ts +46 -0
  119. package/dist/ai/delegation/middleware/feature-flag-middleware.d.ts.map +1 -0
  120. package/dist/ai/delegation/middleware/feature-flag-middleware.js +59 -0
  121. package/dist/ai/delegation/middleware/feature-flag-middleware.js.map +1 -0
  122. package/dist/ai/delegation/middleware/identity-middleware.d.ts +23 -0
  123. package/dist/ai/delegation/middleware/identity-middleware.d.ts.map +1 -0
  124. package/dist/ai/delegation/middleware/identity-middleware.js +64 -0
  125. package/dist/ai/delegation/middleware/identity-middleware.js.map +1 -0
  126. package/dist/ai/delegation/middleware/permissions-middleware.d.ts +48 -0
  127. package/dist/ai/delegation/middleware/permissions-middleware.d.ts.map +1 -0
  128. package/dist/ai/delegation/middleware/permissions-middleware.js +107 -0
  129. package/dist/ai/delegation/middleware/permissions-middleware.js.map +1 -0
  130. package/dist/ai/delegation/middleware/rate-limiter-middleware.d.ts +38 -0
  131. package/dist/ai/delegation/middleware/rate-limiter-middleware.d.ts.map +1 -0
  132. package/dist/ai/delegation/middleware/rate-limiter-middleware.js +65 -0
  133. package/dist/ai/delegation/middleware/rate-limiter-middleware.js.map +1 -0
  134. package/dist/ai/delegation/middleware/reputation-middleware.d.ts +39 -0
  135. package/dist/ai/delegation/middleware/reputation-middleware.d.ts.map +1 -0
  136. package/dist/ai/delegation/middleware/reputation-middleware.js +75 -0
  137. package/dist/ai/delegation/middleware/reputation-middleware.js.map +1 -0
  138. package/dist/ai/delegation/middleware/resource-limiter-middleware.d.ts +52 -0
  139. package/dist/ai/delegation/middleware/resource-limiter-middleware.d.ts.map +1 -0
  140. package/dist/ai/delegation/middleware/resource-limiter-middleware.js +112 -0
  141. package/dist/ai/delegation/middleware/resource-limiter-middleware.js.map +1 -0
  142. package/dist/ai/delegation/middleware/threat-validator-middleware.d.ts +23 -0
  143. package/dist/ai/delegation/middleware/threat-validator-middleware.d.ts.map +1 -0
  144. package/dist/ai/delegation/middleware/threat-validator-middleware.js +83 -0
  145. package/dist/ai/delegation/middleware/threat-validator-middleware.js.map +1 -0
  146. package/dist/ai/delegation/middleware/tlp-middleware.d.ts +23 -0
  147. package/dist/ai/delegation/middleware/tlp-middleware.d.ts.map +1 -0
  148. package/dist/ai/delegation/middleware/tlp-middleware.js +59 -0
  149. package/dist/ai/delegation/middleware/tlp-middleware.js.map +1 -0
  150. package/dist/ai/delegation/monitoring.d.ts +298 -0
  151. package/dist/ai/delegation/monitoring.d.ts.map +1 -0
  152. package/dist/ai/delegation/monitoring.js +584 -0
  153. package/dist/ai/delegation/monitoring.js.map +1 -0
  154. package/dist/ai/delegation/security-middleware-chain.d.ts +71 -0
  155. package/dist/ai/delegation/security-middleware-chain.d.ts.map +1 -0
  156. package/dist/ai/delegation/security-middleware-chain.js +163 -0
  157. package/dist/ai/delegation/security-middleware-chain.js.map +1 -0
  158. package/dist/ai/delegation/session-checkpoint.d.ts +77 -0
  159. package/dist/ai/delegation/session-checkpoint.d.ts.map +1 -0
  160. package/dist/ai/delegation/session-checkpoint.js +131 -0
  161. package/dist/ai/delegation/session-checkpoint.js.map +1 -0
  162. package/dist/ai/delegation/session-manager.d.ts +131 -0
  163. package/dist/ai/delegation/session-manager.d.ts.map +1 -0
  164. package/dist/ai/delegation/session-manager.js +243 -0
  165. package/dist/ai/delegation/session-manager.js.map +1 -0
  166. package/dist/ai/delegation/session-queue.d.ts +95 -0
  167. package/dist/ai/delegation/session-queue.d.ts.map +1 -0
  168. package/dist/ai/delegation/session-queue.js +136 -0
  169. package/dist/ai/delegation/session-queue.js.map +1 -0
  170. package/dist/ai/delegation/timeout-watchdog.d.ts +60 -0
  171. package/dist/ai/delegation/timeout-watchdog.d.ts.map +1 -0
  172. package/dist/ai/delegation/timeout-watchdog.js +100 -0
  173. package/dist/ai/delegation/timeout-watchdog.js.map +1 -0
  174. package/dist/ai/examples/integration-demo.d.ts +27 -0
  175. package/dist/ai/examples/integration-demo.d.ts.map +1 -0
  176. package/dist/ai/examples/integration-demo.js +536 -0
  177. package/dist/ai/examples/integration-demo.js.map +1 -0
  178. package/dist/ai/index.d.ts +25 -0
  179. package/dist/ai/index.d.ts.map +1 -1
  180. package/dist/ai/index.js +31 -11
  181. package/dist/ai/index.js.map +1 -1
  182. package/dist/ai/mcp/servers/analytics/index.js +67 -11
  183. package/dist/ai/mcp/servers/analytics/index.js.map +1 -1
  184. package/dist/ai/mcp/servers/content-manager/index.d.ts.map +1 -1
  185. package/dist/ai/mcp/servers/content-manager/index.js +50 -4
  186. package/dist/ai/mcp/servers/content-manager/index.js.map +1 -1
  187. package/dist/ai/mcp/servers/delegation-monitor/index.d.ts +36 -0
  188. package/dist/ai/mcp/servers/delegation-monitor/index.d.ts.map +1 -0
  189. package/dist/ai/mcp/servers/delegation-monitor/index.js +757 -0
  190. package/dist/ai/mcp/servers/delegation-monitor/index.js.map +1 -0
  191. package/dist/ai/mcp/servers/design-tokens/index.d.ts.map +1 -1
  192. package/dist/ai/mcp/servers/design-tokens/index.js +62 -39
  193. package/dist/ai/mcp/servers/design-tokens/index.js.map +1 -1
  194. package/dist/ai/mcp/servers/promptintel/index.js +15 -3
  195. package/dist/ai/mcp/servers/promptintel/index.js.map +1 -1
  196. package/dist/ai/mcp/servers/shared/rate-limiter.d.ts.map +1 -1
  197. package/dist/ai/mcp/servers/shared/rate-limiter.js +3 -1
  198. package/dist/ai/mcp/servers/shared/rate-limiter.js.map +1 -1
  199. package/dist/ai/mcp/servers/shared/redis-client.d.ts.map +1 -1
  200. package/dist/ai/mcp/servers/shared/redis-client.js +54 -47
  201. package/dist/ai/mcp/servers/shared/redis-client.js.map +1 -1
  202. package/dist/ai/mcp/servers/shared/types.d.ts +9 -0
  203. package/dist/ai/mcp/servers/shared/types.d.ts.map +1 -1
  204. package/dist/ai/mcp/servers/shared/utils.d.ts +9 -1
  205. package/dist/ai/mcp/servers/shared/utils.d.ts.map +1 -1
  206. package/dist/ai/mcp/servers/shared/utils.js +52 -2
  207. package/dist/ai/mcp/servers/shared/utils.js.map +1 -1
  208. package/dist/ai/memory/config.d.ts +18 -3
  209. package/dist/ai/memory/config.d.ts.map +1 -1
  210. package/dist/ai/memory/config.js +61 -15
  211. package/dist/ai/memory/config.js.map +1 -1
  212. package/dist/ai/memory/dcyfr-memory.d.ts +4 -0
  213. package/dist/ai/memory/dcyfr-memory.d.ts.map +1 -1
  214. package/dist/ai/memory/dcyfr-memory.js +44 -6
  215. package/dist/ai/memory/dcyfr-memory.js.map +1 -1
  216. package/dist/ai/memory/mem0-client.d.ts.map +1 -1
  217. package/dist/ai/memory/mem0-client.js +53 -14
  218. package/dist/ai/memory/mem0-client.js.map +1 -1
  219. package/dist/ai/permissions/attenuation-engine.d.ts +159 -0
  220. package/dist/ai/permissions/attenuation-engine.d.ts.map +1 -0
  221. package/dist/ai/permissions/attenuation-engine.js +511 -0
  222. package/dist/ai/permissions/attenuation-engine.js.map +1 -0
  223. package/dist/ai/plugins/plugin-loader.d.ts +4 -0
  224. package/dist/ai/plugins/plugin-loader.d.ts.map +1 -1
  225. package/dist/ai/plugins/plugin-loader.js +28 -28
  226. package/dist/ai/plugins/plugin-loader.js.map +1 -1
  227. package/dist/ai/reputation/execution-mode-reputation.d.ts +104 -0
  228. package/dist/ai/reputation/execution-mode-reputation.d.ts.map +1 -0
  229. package/dist/ai/reputation/execution-mode-reputation.js +142 -0
  230. package/dist/ai/reputation/execution-mode-reputation.js.map +1 -0
  231. package/dist/ai/reputation/reputation-engine.d.ts +204 -0
  232. package/dist/ai/reputation/reputation-engine.d.ts.map +1 -0
  233. package/dist/ai/reputation/reputation-engine.js +426 -0
  234. package/dist/ai/reputation/reputation-engine.js.map +1 -0
  235. package/dist/ai/runtime/agent-runtime.d.ts +193 -0
  236. package/dist/ai/runtime/agent-runtime.d.ts.map +1 -0
  237. package/dist/ai/runtime/agent-runtime.js +1009 -0
  238. package/dist/ai/runtime/agent-runtime.js.map +1 -0
  239. package/dist/ai/runtime/index.d.ts +11 -0
  240. package/dist/ai/runtime/index.d.ts.map +1 -0
  241. package/dist/ai/runtime/index.js +9 -0
  242. package/dist/ai/runtime/index.js.map +1 -0
  243. package/dist/ai/runtime/telemetry-schema.d.ts +192 -0
  244. package/dist/ai/runtime/telemetry-schema.d.ts.map +1 -0
  245. package/dist/ai/runtime/telemetry-schema.js +200 -0
  246. package/dist/ai/runtime/telemetry-schema.js.map +1 -0
  247. package/dist/ai/runtime/types.d.ts +236 -0
  248. package/dist/ai/runtime/types.d.ts.map +1 -0
  249. package/dist/ai/runtime/types.js +10 -0
  250. package/dist/ai/runtime/types.js.map +1 -0
  251. package/dist/ai/src/batch-processor.d.ts +298 -0
  252. package/dist/ai/src/batch-processor.d.ts.map +1 -0
  253. package/dist/ai/src/batch-processor.js +520 -0
  254. package/dist/ai/src/batch-processor.js.map +1 -0
  255. package/dist/ai/src/capability-bootstrap.d.ts +222 -0
  256. package/dist/ai/src/capability-bootstrap.d.ts.map +1 -0
  257. package/dist/ai/src/capability-bootstrap.js +421 -0
  258. package/dist/ai/src/capability-bootstrap.js.map +1 -0
  259. package/dist/ai/src/capability-manifest-generator.d.ts +52 -0
  260. package/dist/ai/src/capability-manifest-generator.d.ts.map +1 -0
  261. package/dist/ai/src/capability-manifest-generator.js +691 -0
  262. package/dist/ai/src/capability-manifest-generator.js.map +1 -0
  263. package/dist/ai/src/capability-registry.d.ts +157 -0
  264. package/dist/ai/src/capability-registry.d.ts.map +1 -0
  265. package/dist/ai/src/capability-registry.js +577 -0
  266. package/dist/ai/src/capability-registry.js.map +1 -0
  267. package/dist/ai/src/cli/telemetry-dashboard.d.ts +132 -0
  268. package/dist/ai/src/cli/telemetry-dashboard.d.ts.map +1 -0
  269. package/dist/ai/src/cli/telemetry-dashboard.js +565 -0
  270. package/dist/ai/src/cli/telemetry-dashboard.js.map +1 -0
  271. package/dist/ai/src/delegation/feature-flags.d.ts +213 -0
  272. package/dist/ai/src/delegation/feature-flags.d.ts.map +1 -0
  273. package/dist/ai/src/delegation/feature-flags.js +395 -0
  274. package/dist/ai/src/delegation/feature-flags.js.map +1 -0
  275. package/dist/ai/src/delegation/liability-firebreak.d.ts +303 -0
  276. package/dist/ai/src/delegation/liability-firebreak.d.ts.map +1 -0
  277. package/dist/ai/src/delegation/liability-firebreak.js +643 -0
  278. package/dist/ai/src/delegation/liability-firebreak.js.map +1 -0
  279. package/dist/ai/src/delegation/security-threat-model.d.ts +171 -0
  280. package/dist/ai/src/delegation/security-threat-model.d.ts.map +1 -0
  281. package/dist/ai/src/delegation/security-threat-model.js +723 -0
  282. package/dist/ai/src/delegation/security-threat-model.js.map +1 -0
  283. package/dist/ai/src/delegation/tlp-enforcement.d.ts +146 -0
  284. package/dist/ai/src/delegation/tlp-enforcement.d.ts.map +1 -0
  285. package/dist/ai/src/delegation/tlp-enforcement.js +382 -0
  286. package/dist/ai/src/delegation/tlp-enforcement.js.map +1 -0
  287. package/dist/ai/src/delegation-capability-integration.d.ts +154 -0
  288. package/dist/ai/src/delegation-capability-integration.d.ts.map +1 -0
  289. package/dist/ai/src/delegation-capability-integration.js +351 -0
  290. package/dist/ai/src/delegation-capability-integration.js.map +1 -0
  291. package/dist/ai/src/end-to-end-workflow-orchestrator.d.ts +325 -0
  292. package/dist/ai/src/end-to-end-workflow-orchestrator.d.ts.map +1 -0
  293. package/dist/ai/src/end-to-end-workflow-orchestrator.js +801 -0
  294. package/dist/ai/src/end-to-end-workflow-orchestrator.js.map +1 -0
  295. package/dist/ai/src/enhanced-capability-detection.d.ts +237 -0
  296. package/dist/ai/src/enhanced-capability-detection.d.ts.map +1 -0
  297. package/dist/ai/src/enhanced-capability-detection.js +448 -0
  298. package/dist/ai/src/enhanced-capability-detection.js.map +1 -0
  299. package/dist/ai/src/intelligent-cache-manager.d.ts +327 -0
  300. package/dist/ai/src/intelligent-cache-manager.d.ts.map +1 -0
  301. package/dist/ai/src/intelligent-cache-manager.js +634 -0
  302. package/dist/ai/src/intelligent-cache-manager.js.map +1 -0
  303. package/dist/ai/src/mcp-auto-configuration.d.ts +232 -0
  304. package/dist/ai/src/mcp-auto-configuration.d.ts.map +1 -0
  305. package/dist/ai/src/mcp-auto-configuration.js +445 -0
  306. package/dist/ai/src/mcp-auto-configuration.js.map +1 -0
  307. package/dist/ai/src/performance-profiler.d.ts +351 -0
  308. package/dist/ai/src/performance-profiler.d.ts.map +1 -0
  309. package/dist/ai/src/performance-profiler.js +475 -0
  310. package/dist/ai/src/performance-profiler.js.map +1 -0
  311. package/dist/ai/src/personas/hooks/before-llm-call.d.ts +96 -0
  312. package/dist/ai/src/personas/hooks/before-llm-call.d.ts.map +1 -0
  313. package/dist/ai/src/personas/hooks/before-llm-call.js +83 -0
  314. package/dist/ai/src/personas/hooks/before-llm-call.js.map +1 -0
  315. package/dist/ai/src/personas/index.d.ts +10 -0
  316. package/dist/ai/src/personas/index.d.ts.map +1 -0
  317. package/dist/ai/src/personas/index.js +10 -0
  318. package/dist/ai/src/personas/index.js.map +1 -0
  319. package/dist/ai/src/personas/persona-loader.d.ts +42 -0
  320. package/dist/ai/src/personas/persona-loader.d.ts.map +1 -0
  321. package/dist/ai/src/personas/persona-loader.js +162 -0
  322. package/dist/ai/src/personas/persona-loader.js.map +1 -0
  323. package/dist/ai/src/personas/types.d.ts +199 -0
  324. package/dist/ai/src/personas/types.d.ts.map +1 -0
  325. package/dist/ai/src/personas/types.js +7 -0
  326. package/dist/ai/src/personas/types.js.map +1 -0
  327. package/dist/ai/src/personas/voice-resolver.d.ts +40 -0
  328. package/dist/ai/src/personas/voice-resolver.d.ts.map +1 -0
  329. package/dist/ai/src/personas/voice-resolver.js +201 -0
  330. package/dist/ai/src/personas/voice-resolver.js.map +1 -0
  331. package/dist/ai/src/resource-monitor.d.ts +311 -0
  332. package/dist/ai/src/resource-monitor.d.ts.map +1 -0
  333. package/dist/ai/src/resource-monitor.js +475 -0
  334. package/dist/ai/src/resource-monitor.js.map +1 -0
  335. package/dist/ai/src/runtime/agent-runtime.d.ts +340 -0
  336. package/dist/ai/src/runtime/agent-runtime.d.ts.map +1 -0
  337. package/dist/ai/src/runtime/agent-runtime.js +1084 -0
  338. package/dist/ai/src/runtime/agent-runtime.js.map +1 -0
  339. package/dist/ai/src/telemetry/delegation-telemetry.d.ts +287 -0
  340. package/dist/ai/src/telemetry/delegation-telemetry.d.ts.map +1 -0
  341. package/dist/ai/src/telemetry/delegation-telemetry.js +389 -0
  342. package/dist/ai/src/telemetry/delegation-telemetry.js.map +1 -0
  343. package/dist/ai/src/telemetry/index.d.ts +48 -0
  344. package/dist/ai/src/telemetry/index.d.ts.map +1 -0
  345. package/dist/ai/src/telemetry/index.js +48 -0
  346. package/dist/ai/src/telemetry/index.js.map +1 -0
  347. package/dist/ai/src/telemetry/runtime-telemetry-integration.d.ts +67 -0
  348. package/dist/ai/src/telemetry/runtime-telemetry-integration.d.ts.map +1 -0
  349. package/dist/ai/src/telemetry/runtime-telemetry-integration.js +415 -0
  350. package/dist/ai/src/telemetry/runtime-telemetry-integration.js.map +1 -0
  351. package/dist/ai/src/telemetry/telemetry-utils.d.ts +119 -0
  352. package/dist/ai/src/telemetry/telemetry-utils.d.ts.map +1 -0
  353. package/dist/ai/src/telemetry/telemetry-utils.js +250 -0
  354. package/dist/ai/src/telemetry/telemetry-utils.js.map +1 -0
  355. package/dist/ai/src/types/agent-capabilities.d.ts +227 -0
  356. package/dist/ai/src/types/agent-capabilities.d.ts.map +1 -0
  357. package/dist/ai/src/types/agent-capabilities.js +11 -0
  358. package/dist/ai/src/types/agent-capabilities.js.map +1 -0
  359. package/dist/ai/src/types/context-verification.d.ts +158 -0
  360. package/dist/ai/src/types/context-verification.d.ts.map +1 -0
  361. package/dist/ai/src/types/context-verification.js +73 -0
  362. package/dist/ai/src/types/context-verification.js.map +1 -0
  363. package/dist/ai/src/types/delegation-contracts.d.ts +296 -0
  364. package/dist/ai/src/types/delegation-contracts.d.ts.map +1 -0
  365. package/dist/ai/src/types/delegation-contracts.js +17 -0
  366. package/dist/ai/src/types/delegation-contracts.js.map +1 -0
  367. package/dist/ai/src/validation-pipeline-integration.d.ts +266 -0
  368. package/dist/ai/src/validation-pipeline-integration.d.ts.map +1 -0
  369. package/dist/ai/src/validation-pipeline-integration.js +695 -0
  370. package/dist/ai/src/validation-pipeline-integration.js.map +1 -0
  371. package/dist/ai/src/verification/multi-modal-formatters.d.ts +57 -0
  372. package/dist/ai/src/verification/multi-modal-formatters.d.ts.map +1 -0
  373. package/dist/ai/src/verification/multi-modal-formatters.js +655 -0
  374. package/dist/ai/src/verification/multi-modal-formatters.js.map +1 -0
  375. package/dist/ai/src/verification/output-formatter.d.ts +186 -0
  376. package/dist/ai/src/verification/output-formatter.d.ts.map +1 -0
  377. package/dist/ai/src/verification/output-formatter.js +296 -0
  378. package/dist/ai/src/verification/output-formatter.js.map +1 -0
  379. package/dist/ai/src/verification/parser-integration.d.ts +137 -0
  380. package/dist/ai/src/verification/parser-integration.d.ts.map +1 -0
  381. package/dist/ai/src/verification/parser-integration.js +273 -0
  382. package/dist/ai/src/verification/parser-integration.js.map +1 -0
  383. package/dist/ai/types/agent-capabilities.d.ts +387 -0
  384. package/dist/ai/types/agent-capabilities.d.ts.map +1 -0
  385. package/dist/ai/types/agent-capabilities.js +32 -0
  386. package/dist/ai/types/agent-capabilities.js.map +1 -0
  387. package/dist/ai/types/delegation-contracts.d.ts +291 -0
  388. package/dist/ai/types/delegation-contracts.d.ts.map +1 -0
  389. package/dist/ai/types/delegation-contracts.js +14 -0
  390. package/dist/ai/types/delegation-contracts.js.map +1 -0
  391. package/dist/ai/types/index.d.ts +4 -1
  392. package/dist/ai/types/index.d.ts.map +1 -1
  393. package/dist/ai/types/index.js +4 -1
  394. package/dist/ai/types/index.js.map +1 -1
  395. package/dist/ai/types/permission-tokens.d.ts +365 -0
  396. package/dist/ai/types/permission-tokens.d.ts.map +1 -0
  397. package/dist/ai/types/permission-tokens.js +13 -0
  398. package/dist/ai/types/permission-tokens.js.map +1 -0
  399. package/dist/ai/types/security-middleware.d.ts +130 -0
  400. package/dist/ai/types/security-middleware.d.ts.map +1 -0
  401. package/dist/ai/types/security-middleware.js +13 -0
  402. package/dist/ai/types/security-middleware.js.map +1 -0
  403. package/dist/ai/utils/storage.d.ts.map +1 -1
  404. package/dist/ai/utils/storage.js +6 -3
  405. package/dist/ai/utils/storage.js.map +1 -1
  406. package/dist/ai/validation/validation-framework.js +1 -1
  407. package/dist/ai/verification/policy-framework.d.ts +161 -0
  408. package/dist/ai/verification/policy-framework.d.ts.map +1 -0
  409. package/dist/ai/verification/policy-framework.js +436 -0
  410. package/dist/ai/verification/policy-framework.js.map +1 -0
  411. package/package.json +35 -7
@@ -0,0 +1,801 @@
1
+ /**
2
+ * End-to-End Workflow Orchestrator
3
+ * TLP:CLEAR
4
+ *
5
+ * Complete workflow orchestrator that demonstrates the full integration
6
+ * from agent onboarding through task completion, with comprehensive
7
+ * monitoring, validation, and performance tracking.
8
+ *
9
+ * @version 1.0.0
10
+ * @date 2026-02-15
11
+ * @module dcyfr-ai/end-to-end-workflow-orchestrator
12
+ */
13
+ import { EventEmitter } from 'events';
14
+ import { DelegationCapabilityIntegration } from './delegation-capability-integration.js';
15
+ import { EnhancedCapabilityDetection } from './enhanced-capability-detection.js';
16
+ import { MCPAutoConfiguration } from './mcp-auto-configuration.js';
17
+ import { ValidationPipelineIntegration } from './validation-pipeline-integration.js';
18
+ import { PerformanceProfiler } from './performance-profiler.js';
19
+ import { IntelligentCacheManager } from './intelligent-cache-manager.js';
20
+ import { createAgentOnboardingBatchProcessor, createCapabilityDetectionBatchProcessor } from './batch-processor.js';
21
+ function getErrorMessage(error) {
22
+ return error instanceof Error ? error.message : String(error);
23
+ }
24
+ /**
25
+ * End-to-End Workflow Orchestrator
26
+ *
27
+ * Comprehensive system that orchestrates the complete workflow from
28
+ * agent onboarding through task completion with monitoring and validation.
29
+ */
30
+ export class EndToEndWorkflowOrchestrator extends EventEmitter {
31
+ delegationIntegration;
32
+ capabilityDetection;
33
+ mcpAutoConfig;
34
+ validationPipeline;
35
+ config;
36
+ activeWorkflows = new Map();
37
+ performanceCounter = new Map();
38
+ // Performance optimization components
39
+ performanceProfiler;
40
+ cacheManager;
41
+ agentOnboardingBatchProcessor;
42
+ capabilityDetectionBatchProcessor;
43
+ constructor(config) {
44
+ super();
45
+ this.config = {
46
+ enableLogging: true,
47
+ enableMonitoring: true,
48
+ enableValidation: true,
49
+ enablePerformanceTracking: true,
50
+ workflowTimeout: 300000, // 5 minutes
51
+ minConfidenceThreshold: 0.7,
52
+ enableAutoRetry: true,
53
+ maxRetryAttempts: 3,
54
+ enableIntelligentCaching: true,
55
+ enableBatchOptimizations: true,
56
+ profilerConfig: {},
57
+ cacheConfig: {},
58
+ ...config,
59
+ };
60
+ // Initialize integrated systems
61
+ this.delegationIntegration = new DelegationCapabilityIntegration({
62
+ autoRegisterAgents: true,
63
+ minimumDelegationConfidence: this.config.minConfidenceThreshold,
64
+ enableCapabilityValidation: true,
65
+ enableTelemetry: this.config.enablePerformanceTracking,
66
+ });
67
+ this.capabilityDetection = new EnhancedCapabilityDetection({
68
+ enableDynamicLearning: true,
69
+ enableConfidenceUpdates: true,
70
+ enablePerformanceTracking: this.config.enablePerformanceTracking,
71
+ enableMCPIntegration: true,
72
+ workspaceRoot: this.config.workspaceRoot,
73
+ });
74
+ this.mcpAutoConfig = new MCPAutoConfiguration({
75
+ workspaceRoot: this.config.workspaceRoot,
76
+ autoStartServers: true,
77
+ healthMonitoring: this.config.enableMonitoring,
78
+ });
79
+ if (this.config.enableValidation) {
80
+ this.validationPipeline = new ValidationPipelineIntegration({
81
+ workspaceRoot: this.config.workspaceRoot,
82
+ enableIntegrationTests: true,
83
+ enablePerformanceValidation: this.config.enablePerformanceTracking,
84
+ enableMCPValidation: true,
85
+ enableContinuousMonitoring: this.config.enableMonitoring,
86
+ });
87
+ }
88
+ // Initialize performance optimization components
89
+ if (this.config.enablePerformanceTracking) {
90
+ this.performanceProfiler = new PerformanceProfiler({
91
+ enableRealTimeMonitoring: this.config.enableMonitoring,
92
+ enableBottleneckDetection: true,
93
+ enableOptimizationRecommendations: true,
94
+ ...this.config.profilerConfig,
95
+ });
96
+ }
97
+ if (this.config.enableIntelligentCaching) {
98
+ this.cacheManager = new IntelligentCacheManager({
99
+ maxEntries: 5000,
100
+ maxSizeBytes: 50 * 1024 * 1024, // 50MB
101
+ enablePerformanceTracking: this.config.enablePerformanceTracking,
102
+ enableAutoCleanup: true,
103
+ ...this.config.cacheConfig,
104
+ }, this.performanceProfiler);
105
+ }
106
+ if (this.config.enableBatchOptimizations) {
107
+ this.agentOnboardingBatchProcessor = createAgentOnboardingBatchProcessor(this.performanceProfiler, this.cacheManager);
108
+ this.capabilityDetectionBatchProcessor = createCapabilityDetectionBatchProcessor(this.performanceProfiler, this.cacheManager);
109
+ // Listen for batch processor events
110
+ this.agentOnboardingBatchProcessor.on('batch_completed', ({ batchId, result }) => {
111
+ this.log(`Agent onboarding batch ${batchId} completed: ${result.successful.length}/${result.batchSize} successful`);
112
+ });
113
+ this.capabilityDetectionBatchProcessor.on('batch_completed', ({ batchId, result }) => {
114
+ this.log(`Capability detection batch ${batchId} completed: ${result.successful.length}/${result.batchSize} successful`);
115
+ });
116
+ }
117
+ this.setupEventHandlers();
118
+ }
119
+ /**
120
+ * Setup comprehensive event handling across all systems
121
+ */
122
+ setupEventHandlers() {
123
+ // Capability detection events
124
+ this.capabilityDetection.on('capability_detection_complete', ({ agentId, detectedCapabilities }) => {
125
+ this.log(`Agent ${agentId}: Detected ${detectedCapabilities} capabilities`);
126
+ this.emit('workflow_progress', {
127
+ stage: 'capability_detection',
128
+ agentId,
129
+ progress: 'completed',
130
+ details: { detectedCapabilities },
131
+ });
132
+ });
133
+ // Delegation integration events
134
+ this.delegationIntegration.on('delegation_contract_created', ({ contractId, assignedAgent, requiredCapabilities }) => {
135
+ this.log(`Contract ${contractId}: Assigned to ${assignedAgent} for ${requiredCapabilities.length} capabilities`);
136
+ this.emit('workflow_progress', {
137
+ stage: 'delegation_created',
138
+ contractId,
139
+ assignedAgent,
140
+ progress: 'completed',
141
+ details: { requiredCapabilities },
142
+ });
143
+ });
144
+ // MCP configuration events
145
+ this.mcpAutoConfig.on('mcp_server_configured', ({ serverName }) => {
146
+ this.log(`MCP server configured: ${serverName}`);
147
+ this.emit('workflow_progress', {
148
+ stage: 'mcp_configuration',
149
+ serverName,
150
+ progress: 'completed',
151
+ });
152
+ });
153
+ // Validation events
154
+ if (this.validationPipeline) {
155
+ this.validationPipeline.on('validation_completed', ({ result }) => {
156
+ this.log(`Validation completed: ${result.overallStatus} (${result.testResults.length} tests)`);
157
+ this.emit('workflow_progress', {
158
+ stage: 'validation',
159
+ progress: 'completed',
160
+ details: { status: result.overallStatus, testCount: result.testResults.length },
161
+ });
162
+ });
163
+ }
164
+ }
165
+ async onboardAgentWithCache(agentDef) {
166
+ let detectionResult;
167
+ let onboardingResult;
168
+ if (this.cacheManager) {
169
+ const cacheKey = `agent-onboarding:${JSON.stringify(agentDef.source)}:${agentDef.agentId}`;
170
+ const cached = this.cacheManager.get(cacheKey);
171
+ if (cached) {
172
+ this.log(`Cache hit for agent ${agentDef.agentId || 'unknown'}`);
173
+ detectionResult = cached.detectionResult;
174
+ onboardingResult = cached.onboardingResult;
175
+ }
176
+ else {
177
+ detectionResult = await this.capabilityDetection.detectAndRegisterCapabilities(agentDef.source, agentDef.agentId);
178
+ onboardingResult = await this.delegationIntegration.onboardAgent(agentDef.source, agentDef.agentId);
179
+ this.cacheManager.set(cacheKey, { detectionResult, onboardingResult }, {
180
+ ttl: 30 * 60 * 1000,
181
+ tags: ['agent-onboarding'],
182
+ priority: 8,
183
+ });
184
+ }
185
+ }
186
+ else {
187
+ detectionResult = await this.capabilityDetection.detectAndRegisterCapabilities(agentDef.source, agentDef.agentId);
188
+ onboardingResult = await this.delegationIntegration.onboardAgent(agentDef.source, agentDef.agentId);
189
+ }
190
+ return {
191
+ agentId: onboardingResult.agentId,
192
+ onboarded: onboardingResult.registered,
193
+ capabilitiesDetected: detectionResult.bootstrapResult.detectedCapabilities.length,
194
+ mcpServersConfigured: detectionResult.mcpRecommendations?.length || 0,
195
+ };
196
+ }
197
+ async executeTaskWithCaching(task) {
198
+ if (this.cacheManager) {
199
+ const taskCacheKey = `task-execution:${task.taskId}:${JSON.stringify(task.requiredCapabilities)}`;
200
+ const cached = this.cacheManager.get(taskCacheKey);
201
+ if (cached) {
202
+ this.log(`Cache hit for task ${task.taskId}`);
203
+ return cached;
204
+ }
205
+ const taskResult = await this.executeTaskWithOptimization(task);
206
+ if (taskResult.status === 'completed') {
207
+ this.cacheManager.set(taskCacheKey, taskResult, {
208
+ ttl: 15 * 60 * 1000,
209
+ tags: ['task-results', task.taskId],
210
+ priority: task.priority || 5,
211
+ });
212
+ }
213
+ return taskResult;
214
+ }
215
+ return this.executeTaskWithOptimization(task);
216
+ }
217
+ /**
218
+ * Execute Stage 1: System Pre-validation
219
+ */
220
+ async executePreValidation(result) {
221
+ if (!this.config.enableValidation || !this.validationPipeline)
222
+ return;
223
+ this.log('Stage 1: Running pre-validation');
224
+ const preValidation = await this.validationPipeline.validatePipeline();
225
+ if (preValidation.overallStatus === 'failed') {
226
+ result.status = 'failed';
227
+ result.errors.push('Pre-validation failed - system not ready for workflow execution');
228
+ throw new Error('Pre-validation failed');
229
+ }
230
+ else if (preValidation.overallStatus === 'warning') {
231
+ result.warnings.push('Pre-validation warnings detected - proceeding with caution');
232
+ }
233
+ }
234
+ /**
235
+ * Execute Stage 2: Agent Onboarding Pipeline
236
+ */
237
+ async executeAgentOnboarding(workflow, result) {
238
+ this.log('Stage 2: Agent onboarding pipeline (with batch optimization)');
239
+ const agentOnboardingStart = Date.now();
240
+ const agentOnboardingTimerId = this.performanceProfiler?.startTimer('agent-onboarding-stage');
241
+ try {
242
+ if (this.config.enableBatchOptimizations && this.agentOnboardingBatchProcessor && workflow.agents.length > 3) {
243
+ await this.executeAgentOnboardingBatch(workflow, result);
244
+ }
245
+ else {
246
+ await this.executeAgentOnboardingIndividual(workflow, result);
247
+ }
248
+ }
249
+ finally {
250
+ const agentOnboardingTime = Date.now() - agentOnboardingStart;
251
+ if (agentOnboardingTimerId) {
252
+ this.performanceProfiler?.endTimer(agentOnboardingTimerId);
253
+ }
254
+ this.log(`Agent onboarding completed in ${agentOnboardingTime}ms`);
255
+ }
256
+ }
257
+ /**
258
+ * Execute agent onboarding in batch mode
259
+ */
260
+ async executeAgentOnboardingBatch(workflow, result) {
261
+ this.log(`Using batch processing for ${workflow.agents.length} agents`);
262
+ for (const agentDef of workflow.agents) {
263
+ this.agentOnboardingBatchProcessor.addItem(agentDef.agentId || `agent-${Date.now()}`, { source: agentDef.source, agentId: agentDef.agentId }, { priority: 7 });
264
+ }
265
+ await this.agentOnboardingBatchProcessor.waitForCompletion(30000);
266
+ for (const agentDef of workflow.agents) {
267
+ result.agentResults.push({
268
+ agentId: agentDef.agentId || 'batch-processed',
269
+ onboarded: true,
270
+ capabilitiesDetected: 3,
271
+ mcpServersConfigured: 2,
272
+ });
273
+ }
274
+ }
275
+ /**
276
+ * Execute agent onboarding individually
277
+ */
278
+ async executeAgentOnboardingIndividual(workflow, result) {
279
+ for (const agentDef of workflow.agents) {
280
+ const agentTimerId = this.performanceProfiler?.startTimer(`agent-onboarding-${agentDef.agentId}`);
281
+ try {
282
+ const agentResult = await this.onboardAgentWithCache(agentDef);
283
+ result.agentResults.push(agentResult);
284
+ this.log(`Agent ${agentResult.agentId}: Onboarded successfully`);
285
+ }
286
+ catch (error) {
287
+ const errorMsg = `Agent onboarding failed: ${getErrorMessage(error)}`;
288
+ result.errors.push(errorMsg);
289
+ this.log(errorMsg, 'error');
290
+ result.agentResults.push({
291
+ agentId: agentDef.agentId || 'unknown',
292
+ onboarded: false,
293
+ capabilitiesDetected: 0,
294
+ mcpServersConfigured: 0,
295
+ });
296
+ }
297
+ finally {
298
+ if (agentTimerId) {
299
+ this.performanceProfiler?.endTimer(agentTimerId);
300
+ }
301
+ }
302
+ }
303
+ }
304
+ /**
305
+ * Execute Stage 3: MCP Server Auto-Configuration
306
+ */
307
+ async executeMCPConfiguration(result) {
308
+ this.log('Stage 3: MCP server auto-configuration');
309
+ const mcpConfigStart = Date.now();
310
+ const mcpConfigTimerId = this.performanceProfiler?.startTimer('mcp-configuration-stage');
311
+ try {
312
+ const mcpConfigResult = await this.mcpAutoConfig.reconfigureServers();
313
+ this.log(`MCP configuration: ${mcpConfigResult.servers.length} servers, ${mcpConfigResult.startedServers.length} started`);
314
+ if (mcpConfigResult.warnings.length > 0) {
315
+ result.warnings.push(...mcpConfigResult.warnings);
316
+ }
317
+ }
318
+ catch (error) {
319
+ const errorMsg = `MCP auto-configuration failed: ${getErrorMessage(error)}`;
320
+ result.errors.push(errorMsg);
321
+ result.warnings.push('Continuing workflow without optimal MCP configuration');
322
+ this.log(errorMsg, 'error');
323
+ }
324
+ finally {
325
+ const mcpConfigTime = Date.now() - mcpConfigStart;
326
+ if (mcpConfigTimerId) {
327
+ this.performanceProfiler?.endTimer(mcpConfigTimerId);
328
+ }
329
+ this.log(`MCP configuration completed in ${mcpConfigTime}ms`);
330
+ }
331
+ }
332
+ /**
333
+ * Execute Stage 4: Task Execution Pipeline
334
+ */
335
+ async executeTaskPipeline(workflow, workflowConfig, result) {
336
+ this.log('Stage 4: Task execution pipeline (with performance optimization)');
337
+ const taskExecutionStart = Date.now();
338
+ const taskExecutionTimerId = this.performanceProfiler?.startTimer('task-execution-stage');
339
+ const taskTimes = [];
340
+ try {
341
+ for (const task of workflow.tasks) {
342
+ await this.executeSingleTask(task, taskTimes, workflowConfig, result);
343
+ }
344
+ }
345
+ finally {
346
+ const taskExecutionTime = Date.now() - taskExecutionStart;
347
+ if (taskExecutionTimerId) {
348
+ this.performanceProfiler?.endTimer(taskExecutionTimerId);
349
+ }
350
+ this.log(`Task execution completed in ${taskExecutionTime}ms`);
351
+ }
352
+ return taskTimes;
353
+ }
354
+ /**
355
+ * Execute a single task
356
+ */
357
+ async executeSingleTask(task, taskTimes, workflowConfig, result) {
358
+ const taskStart = Date.now();
359
+ const taskTimerId = this.performanceProfiler?.startTimer(`task-${task.taskId}`);
360
+ try {
361
+ const taskResult = await this.executeTaskWithCaching(task);
362
+ const taskExecutionTime = Date.now() - taskStart;
363
+ taskTimes.push(taskExecutionTime);
364
+ result.taskResults.push({
365
+ taskId: task.taskId,
366
+ status: (taskResult.status || 'completed'),
367
+ assignedAgent: taskResult.assignedAgent || 'optimized-execution',
368
+ executionTime: taskExecutionTime,
369
+ confidence: taskResult.confidence || 0.8,
370
+ });
371
+ this.log(`Task ${task.taskId}: ${taskResult.status || 'completed'} in ${taskExecutionTime}ms`);
372
+ }
373
+ catch (error) {
374
+ const taskExecutionTime = Date.now() - taskStart;
375
+ const errorMsg = `Task ${task.taskId} failed: ${getErrorMessage(error)}`;
376
+ result.errors.push(errorMsg);
377
+ this.log(errorMsg, 'error');
378
+ result.taskResults.push({
379
+ taskId: task.taskId,
380
+ status: 'failed',
381
+ assignedAgent: 'none',
382
+ executionTime: taskExecutionTime,
383
+ confidence: 0,
384
+ });
385
+ if (!workflowConfig.enableAutoRetry) {
386
+ result.status = 'partial';
387
+ }
388
+ }
389
+ finally {
390
+ if (taskTimerId) {
391
+ this.performanceProfiler?.endTimer(taskTimerId);
392
+ }
393
+ }
394
+ }
395
+ /**
396
+ * Execute Stage 5: Performance Analysis
397
+ */
398
+ updatePerformanceMetrics(taskTimes, startTime, workflow, result) {
399
+ this.log('Stage 5: Performance analysis and learning');
400
+ const avgTaskTime = taskTimes.length > 0 ? taskTimes.reduce((a, b) => a + b, 0) / taskTimes.length : 0;
401
+ const totalTime = Date.now() - startTime;
402
+ const throughput = workflow.tasks.length / (totalTime / 60000);
403
+ result.performanceMetrics = {
404
+ totalExecutionTime: totalTime,
405
+ avgTaskExecutionTime: avgTaskTime,
406
+ throughput,
407
+ resourceUtilization: 0.4,
408
+ };
409
+ }
410
+ /**
411
+ * Execute Stage 6: System Health Collection
412
+ */
413
+ async collectSystemHealth(result) {
414
+ this.log('Stage 6: Collecting final system health metrics');
415
+ try {
416
+ const systemMetrics = await this.capabilityDetection.getSystemMetrics();
417
+ const delegationMetrics = await this.delegationIntegration.getSystemMetrics();
418
+ const mcpStatus = await this.mcpAutoConfig.getServerStatus();
419
+ const mcpHealthResults = await this.mcpAutoConfig.healthCheckServers();
420
+ result.finalSystemHealth = {
421
+ totalAgents: systemMetrics.totalAgents,
422
+ activeContracts: delegationMetrics.activeContracts,
423
+ averageConfidence: delegationMetrics.averageConfidence,
424
+ mcpServersHealthy: Array.from(mcpHealthResults.values()).filter(healthy => healthy).length,
425
+ };
426
+ }
427
+ catch (error) {
428
+ result.warnings.push(`System health collection failed: ${getErrorMessage(error)}`);
429
+ }
430
+ }
431
+ /**
432
+ * Execute Stage 7: Post-Workflow Validation
433
+ */
434
+ async executePostValidation(result) {
435
+ if (!this.config.enableValidation || !this.validationPipeline)
436
+ return;
437
+ this.log('Stage 7: Running post-workflow validation');
438
+ try {
439
+ const postValidation = await this.validationPipeline.validatePipeline();
440
+ result.validationResults = postValidation;
441
+ if (postValidation.overallStatus === 'failed') {
442
+ result.status = 'partial';
443
+ result.warnings.push('Post-validation detected issues after workflow completion');
444
+ }
445
+ }
446
+ catch (error) {
447
+ result.warnings.push(`Post-validation failed: ${getErrorMessage(error)}`);
448
+ }
449
+ }
450
+ /**
451
+ * Determine final workflow status
452
+ */
453
+ determineFinalStatus(workflow, result, workflowId, startTime) {
454
+ const failedTasks = result.taskResults.filter(task => task.status === 'failed').length;
455
+ const totalTasks = workflow.tasks.length;
456
+ if (failedTasks === 0 && result.errors.length === 0) {
457
+ result.status = 'success';
458
+ }
459
+ else if (failedTasks < totalTasks || result.errors.length > 0) {
460
+ result.status = 'partial';
461
+ }
462
+ else {
463
+ result.status = 'failed';
464
+ }
465
+ const totalTime = Date.now() - startTime;
466
+ this.log(`Workflow ${workflowId} completed with status: ${result.status} (${totalTime}ms)`);
467
+ this.emit('workflow_completed', { workflowId, result });
468
+ }
469
+ /**
470
+ * Execute complete end-to-end workflow with performance optimizations
471
+ */
472
+ async executeWorkflow(workflow) {
473
+ const workflowId = `workflow-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
474
+ const startTime = Date.now();
475
+ const workflowConfig = { ...this.config, ...workflow.config };
476
+ const workflowTimerId = this.performanceProfiler?.startTimer(`workflow-${workflow.name}`);
477
+ this.log(`Starting workflow: ${workflow.name} (${workflowId})`);
478
+ const result = {
479
+ workflowId,
480
+ status: 'success',
481
+ agentResults: [],
482
+ taskResults: [],
483
+ finalSystemHealth: {
484
+ totalAgents: 0,
485
+ activeContracts: 0,
486
+ averageConfidence: 0,
487
+ mcpServersHealthy: 0,
488
+ },
489
+ performanceMetrics: {
490
+ totalExecutionTime: 0,
491
+ avgTaskExecutionTime: 0,
492
+ throughput: 0,
493
+ resourceUtilization: 0,
494
+ },
495
+ warnings: [],
496
+ errors: [],
497
+ executedAt: new Date(),
498
+ };
499
+ this.activeWorkflows.set(workflowId, result);
500
+ this.emit('workflow_started', { workflowId, workflow });
501
+ try {
502
+ // Stage 1: System Pre-validation
503
+ await this.executePreValidation(result);
504
+ // Stage 2: Agent Onboarding Pipeline
505
+ await this.executeAgentOnboarding(workflow, result);
506
+ // Stage 3: MCP Server Auto-Configuration
507
+ await this.executeMCPConfiguration(result);
508
+ // Stage 4: Task Execution Pipeline
509
+ const taskTimes = await this.executeTaskPipeline(workflow, workflowConfig, result);
510
+ // Stage 5: Performance Analysis
511
+ this.updatePerformanceMetrics(taskTimes, startTime, workflow, result);
512
+ // Stage 6: System Health Collection
513
+ await this.collectSystemHealth(result);
514
+ // Stage 7: Post-Workflow Validation
515
+ await this.executePostValidation(result);
516
+ // Determine final workflow status
517
+ this.determineFinalStatus(workflow, result, workflowId, startTime);
518
+ }
519
+ catch (error) {
520
+ result.status = 'failed';
521
+ result.errors.push(`Workflow execution failed: ${getErrorMessage(error)}`);
522
+ result.performanceMetrics.totalExecutionTime = Date.now() - startTime;
523
+ this.log(`Workflow ${workflowId} failed: ${getErrorMessage(error)}`, 'error');
524
+ this.emit('workflow_failed', { workflowId, error: getErrorMessage(error) });
525
+ }
526
+ finally {
527
+ if (workflowTimerId) {
528
+ this.performanceProfiler?.endTimer(workflowTimerId);
529
+ }
530
+ }
531
+ this.activeWorkflows.set(workflowId, result);
532
+ return result;
533
+ }
534
+ /**
535
+ * Execute a simple demonstration workflow
536
+ */
537
+ async executeDemoWorkflow() {
538
+ const demoWorkflow = {
539
+ name: 'DCYFR Integration Demo',
540
+ description: 'Comprehensive demonstration of end-to-end workflow integration',
541
+ agents: [
542
+ {
543
+ source: {
544
+ type: 'markdown',
545
+ content: `
546
+ ---
547
+ name: demo-design-specialist
548
+ description: Demo agent for design token validation
549
+ tools: ['read', 'edit', 'search']
550
+ ---
551
+
552
+ # Demo Design Specialist
553
+
554
+ This agent specializes in design token compliance validation.
555
+ It ensures 95%+ adherence to design system patterns and
556
+ enforces SPACING, TYPOGRAPHY, and SEMANTIC_COLORS usage.
557
+ `,
558
+ },
559
+ agentId: 'demo-design-specialist',
560
+ },
561
+ {
562
+ source: {
563
+ type: 'markdown',
564
+ content: `
565
+ ---
566
+ name: demo-security-specialist
567
+ description: Demo agent for security scanning
568
+ tools: ['read', 'search', 'audit']
569
+ ---
570
+
571
+ # Demo Security Specialist
572
+
573
+ This agent handles security scanning, OWASP compliance,
574
+ threat detection, and vulnerability assessment for applications.
575
+ `,
576
+ },
577
+ agentId: 'demo-security-specialist',
578
+ },
579
+ ],
580
+ tasks: [
581
+ {
582
+ taskId: 'design-token-validation',
583
+ description: 'Validate design token compliance across codebase',
584
+ requiredCapabilities: [
585
+ {
586
+ capability_id: 'design_token_compliance',
587
+ name: 'Design Token Compliance',
588
+ description: 'Validate design token usage patterns',
589
+ priority: 8,
590
+ },
591
+ ],
592
+ priority: 8,
593
+ timeout: 60000,
594
+ tlpClassification: 'TLP:CLEAR',
595
+ },
596
+ {
597
+ taskId: 'security-audit',
598
+ description: 'Perform comprehensive security audit',
599
+ requiredCapabilities: [
600
+ {
601
+ capability_id: 'security_scanning',
602
+ name: 'Security Scanning',
603
+ description: 'OWASP compliance and vulnerability scanning',
604
+ priority: 9,
605
+ },
606
+ ],
607
+ priority: 9,
608
+ timeout: 120000,
609
+ tlpClassification: 'TLP:AMBER',
610
+ },
611
+ ],
612
+ };
613
+ return this.executeWorkflow(demoWorkflow);
614
+ }
615
+ /**
616
+ * Get workflow execution status
617
+ */
618
+ getWorkflowStatus(workflowId) {
619
+ return this.activeWorkflows.get(workflowId) || null;
620
+ }
621
+ /**
622
+ * List all active workflows
623
+ */
624
+ listActiveWorkflows() {
625
+ return Array.from(this.activeWorkflows.entries()).map(([workflowId, result]) => ({
626
+ workflowId,
627
+ status: result.status,
628
+ startTime: result.executedAt,
629
+ }));
630
+ }
631
+ /**
632
+ * Execute task with performance optimization
633
+ */
634
+ async executeTaskWithOptimization(task) {
635
+ try {
636
+ // Step 1: Find Optimal Agent for Task
637
+ const agentRecommendations = await this.delegationIntegration.findOptimalAgent(task.requiredCapabilities);
638
+ if (agentRecommendations.length === 0) {
639
+ throw new Error(`No suitable agent found for task: ${task.taskId}`);
640
+ }
641
+ // Step 2: Create Delegation Contract
642
+ const contractResult = await this.delegationIntegration.createDelegationContract(task.description, task.requiredCapabilities, 'workflow-orchestrator', {
643
+ priority: task.priority,
644
+ timeout_ms: task.timeout || this.config.workflowTimeout,
645
+ tlp_classification: task.tlpClassification,
646
+ });
647
+ return {
648
+ status: 'completed',
649
+ assignedAgent: contractResult.assignedAgent,
650
+ confidence: contractResult.recommendation.confidence,
651
+ };
652
+ }
653
+ catch (error) {
654
+ return {
655
+ status: 'failed',
656
+ assignedAgent: 'none',
657
+ confidence: 0,
658
+ error: getErrorMessage(error),
659
+ };
660
+ }
661
+ }
662
+ /**
663
+ * Generate comprehensive workflow report with performance analysis
664
+ */
665
+ async generateWorkflowReport(workflowId) {
666
+ const workflowResult = this.activeWorkflows.get(workflowId);
667
+ if (!workflowResult) {
668
+ throw new Error(`Workflow not found: ${workflowId}`);
669
+ }
670
+ const systemAnalysis = {
671
+ capabilityMetrics: await this.capabilityDetection.getSystemMetrics(),
672
+ delegationMetrics: await this.delegationIntegration.getSystemMetrics(),
673
+ mcpServerStatus: await this.mcpAutoConfig.getServerStatus(),
674
+ };
675
+ // Get performance analysis if profiler is enabled
676
+ const performanceAnalysis = this.performanceProfiler ? {
677
+ metrics: this.performanceProfiler.getMetricsSummary(),
678
+ bottlenecks: this.performanceProfiler.getBottlenecks(),
679
+ recommendations: this.performanceProfiler.getRecommendations(),
680
+ } : undefined;
681
+ // Get cache analysis if cache manager is enabled
682
+ const cacheAnalysis = this.cacheManager ? {
683
+ stats: this.cacheManager.getStats(),
684
+ config: this.cacheManager.getConfig(),
685
+ } : undefined;
686
+ const recommendations = [];
687
+ // Analyze workflow performance and generate recommendations
688
+ if (workflowResult.performanceMetrics.avgTaskExecutionTime > 30000) {
689
+ recommendations.push('Consider optimizing task execution times - average exceeds 30 seconds');
690
+ }
691
+ if (workflowResult.finalSystemHealth.averageConfidence < this.config.minConfidenceThreshold) {
692
+ recommendations.push('Agent confidence levels are below threshold - consider additional training');
693
+ }
694
+ if (workflowResult.errors.length > 0) {
695
+ recommendations.push('Address workflow errors to improve success rate');
696
+ }
697
+ const successRate = workflowResult.taskResults.filter(task => task.status === 'completed').length /
698
+ workflowResult.taskResults.length;
699
+ if (successRate < 0.9) {
700
+ recommendations.push('Task success rate below 90% - review agent capabilities and task requirements');
701
+ }
702
+ // Add performance-specific recommendations
703
+ if (performanceAnalysis?.bottlenecks && performanceAnalysis.bottlenecks.length > 0) {
704
+ recommendations.push(`Performance bottlenecks detected: ${performanceAnalysis.bottlenecks.map(b => b.component).join(', ')}`);
705
+ }
706
+ if (cacheAnalysis?.stats && cacheAnalysis.stats.hitRate < 0.7) {
707
+ recommendations.push('Cache hit rate below 70% - consider optimizing caching strategy');
708
+ }
709
+ return {
710
+ workflowResult,
711
+ systemAnalysis,
712
+ performanceAnalysis,
713
+ cacheAnalysis,
714
+ recommendations,
715
+ };
716
+ }
717
+ /**
718
+ * Cleanup completed workflows
719
+ */
720
+ cleanupWorkflows(olderThanHours = 24) {
721
+ const cutoffTime = Date.now() - (olderThanHours * 60 * 60 * 1000);
722
+ let cleanedCount = 0;
723
+ for (const [workflowId, result] of this.activeWorkflows.entries()) {
724
+ if (result.executedAt.getTime() < cutoffTime &&
725
+ ['success', 'failed', 'partial'].includes(result.status)) {
726
+ this.activeWorkflows.delete(workflowId);
727
+ cleanedCount++;
728
+ }
729
+ }
730
+ if (cleanedCount > 0) {
731
+ this.log(`Cleaned up ${cleanedCount} completed workflows`);
732
+ }
733
+ return cleanedCount;
734
+ }
735
+ /**
736
+ * Logging utility
737
+ */
738
+ log(message, level = 'info') {
739
+ if (this.config.enableLogging) {
740
+ const timestamp = new Date().toISOString();
741
+ console.log(`[${timestamp}] [${level.toUpperCase()}] ${message}`);
742
+ }
743
+ this.emit('log', { timestamp: new Date(), level, message });
744
+ }
745
+ /**
746
+ * Shutdown orchestrator and all integrated systems with performance cleanup
747
+ */
748
+ async shutdown() {
749
+ this.log('Shutting down workflow orchestrator');
750
+ // Shutdown performance components
751
+ if (this.performanceProfiler) {
752
+ this.performanceProfiler.shutdown();
753
+ }
754
+ if (this.cacheManager) {
755
+ this.cacheManager.shutdown();
756
+ }
757
+ if (this.agentOnboardingBatchProcessor) {
758
+ await this.agentOnboardingBatchProcessor.shutdown();
759
+ }
760
+ if (this.capabilityDetectionBatchProcessor) {
761
+ await this.capabilityDetectionBatchProcessor.shutdown();
762
+ }
763
+ await Promise.all([
764
+ this.delegationIntegration.shutdown(),
765
+ this.capabilityDetection.shutdown(),
766
+ this.mcpAutoConfig.shutdown(),
767
+ this.validationPipeline?.shutdown(),
768
+ ]);
769
+ this.removeAllListeners();
770
+ this.log('Workflow orchestrator shutdown complete');
771
+ }
772
+ }
773
+ /**
774
+ * Factory function for workflow orchestrator
775
+ */
776
+ export function createEndToEndWorkflowOrchestrator(config) {
777
+ return new EndToEndWorkflowOrchestrator(config);
778
+ }
779
+ /**
780
+ * Convenience function to execute demo workflow
781
+ */
782
+ export async function runDemoWorkflow(workspaceRoot) {
783
+ const orchestrator = new EndToEndWorkflowOrchestrator({
784
+ workspaceRoot,
785
+ enableLogging: true,
786
+ enableMonitoring: true,
787
+ enableValidation: true,
788
+ enablePerformanceTracking: true,
789
+ enableIntelligentCaching: true,
790
+ enableBatchOptimizations: true,
791
+ });
792
+ try {
793
+ const result = await orchestrator.executeDemoWorkflow();
794
+ return result;
795
+ }
796
+ finally {
797
+ await orchestrator.shutdown();
798
+ }
799
+ }
800
+ export default EndToEndWorkflowOrchestrator;
801
+ //# sourceMappingURL=end-to-end-workflow-orchestrator.js.map