@exaudeus/workrail 0.8.6 → 0.10.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 (428) hide show
  1. package/README.md +157 -403
  2. package/dist/application/services/enhanced-loop-validator.d.ts +2 -2
  3. package/dist/application/services/enhanced-loop-validator.js +12 -2
  4. package/dist/application/services/validation-engine.d.ts +8 -29
  5. package/dist/application/services/validation-engine.js +38 -21
  6. package/dist/application/services/workflow-compiler.d.ts +18 -0
  7. package/dist/application/services/workflow-compiler.js +79 -0
  8. package/dist/application/services/workflow-interpreter.d.ts +31 -0
  9. package/dist/application/services/workflow-interpreter.js +280 -0
  10. package/dist/application/services/workflow-service.d.ts +34 -32
  11. package/dist/application/services/workflow-service.js +93 -425
  12. package/dist/application/use-cases/get-next-step.d.ts +6 -10
  13. package/dist/application/use-cases/get-next-step.js +2 -6
  14. package/dist/application/use-cases/get-workflow.d.ts +8 -6
  15. package/dist/application/use-cases/get-workflow.js +42 -33
  16. package/dist/application/use-cases/list-workflows.d.ts +3 -3
  17. package/dist/application/use-cases/validate-step-output.d.ts +4 -4
  18. package/dist/application/use-cases/validate-workflow-file.d.ts +46 -0
  19. package/dist/application/use-cases/validate-workflow-file.js +57 -0
  20. package/dist/cli/commands/cleanup.d.ts +8 -0
  21. package/dist/cli/commands/cleanup.js +20 -0
  22. package/dist/cli/commands/index.d.ts +7 -0
  23. package/dist/cli/commands/index.js +21 -0
  24. package/dist/cli/commands/init.d.ts +11 -0
  25. package/dist/cli/commands/init.js +49 -0
  26. package/dist/cli/commands/list.d.ts +9 -0
  27. package/dist/cli/commands/list.js +34 -0
  28. package/dist/cli/commands/migrate.d.ts +78 -0
  29. package/dist/cli/commands/migrate.js +248 -0
  30. package/dist/cli/commands/sources.d.ts +21 -0
  31. package/dist/cli/commands/sources.js +87 -0
  32. package/dist/cli/commands/start.d.ts +8 -0
  33. package/dist/cli/commands/start.js +16 -0
  34. package/dist/cli/commands/validate.d.ts +6 -0
  35. package/dist/cli/commands/validate.js +55 -0
  36. package/dist/cli/interpret-result.d.ts +4 -0
  37. package/dist/cli/interpret-result.js +24 -0
  38. package/dist/cli/output-formatter.d.ts +10 -0
  39. package/dist/cli/output-formatter.js +97 -0
  40. package/dist/cli/types/cli-result.d.ts +23 -0
  41. package/dist/cli/types/cli-result.js +30 -0
  42. package/dist/cli/types/exit-code.d.ts +13 -0
  43. package/dist/cli/types/exit-code.js +23 -0
  44. package/dist/cli/types/index.d.ts +4 -0
  45. package/dist/cli/types/index.js +11 -0
  46. package/dist/cli.js +84 -278
  47. package/dist/config/app-config.d.ts +40 -0
  48. package/dist/config/app-config.js +58 -0
  49. package/dist/config/feature-flags.d.ts +10 -2
  50. package/dist/config/feature-flags.js +74 -12
  51. package/dist/core/error-handler.d.ts +18 -27
  52. package/dist/core/error-handler.js +24 -218
  53. package/dist/di/container.d.ts +12 -0
  54. package/dist/di/container.js +244 -0
  55. package/dist/di/tokens.d.ts +40 -0
  56. package/dist/di/tokens.js +42 -0
  57. package/dist/domain/execution/error.d.ts +32 -0
  58. package/dist/domain/execution/error.js +24 -0
  59. package/dist/domain/execution/event.d.ts +7 -0
  60. package/dist/domain/execution/event.js +11 -0
  61. package/dist/domain/execution/ids.d.ts +9 -0
  62. package/dist/domain/execution/ids.js +9 -0
  63. package/dist/domain/execution/result.d.ts +3 -0
  64. package/dist/domain/execution/result.js +10 -0
  65. package/dist/domain/execution/state.d.ts +57 -0
  66. package/dist/domain/execution/state.js +28 -0
  67. package/dist/errors/app-error.d.ts +23 -0
  68. package/dist/errors/factories.d.ts +6 -0
  69. package/dist/errors/factories.js +21 -0
  70. package/dist/errors/formatter.d.ts +2 -0
  71. package/dist/errors/formatter.js +32 -0
  72. package/dist/errors/index.d.ts +3 -0
  73. package/dist/errors/index.js +7 -0
  74. package/dist/index.d.ts +6 -1
  75. package/dist/index.js +10 -25
  76. package/dist/infrastructure/index.d.ts +0 -1
  77. package/dist/infrastructure/index.js +0 -1
  78. package/dist/infrastructure/session/DashboardHeartbeat.d.ts +8 -0
  79. package/dist/infrastructure/session/DashboardHeartbeat.js +39 -0
  80. package/dist/infrastructure/session/DashboardLockRelease.d.ts +2 -0
  81. package/dist/infrastructure/session/DashboardLockRelease.js +29 -0
  82. package/dist/infrastructure/session/HttpServer.d.ts +25 -6
  83. package/dist/infrastructure/session/HttpServer.js +245 -90
  84. package/dist/infrastructure/session/SessionDataNormalizer.js +12 -2
  85. package/dist/infrastructure/session/SessionDataValidator.js +12 -2
  86. package/dist/infrastructure/session/SessionManager.d.ts +5 -3
  87. package/dist/infrastructure/session/SessionManager.js +52 -6
  88. package/dist/infrastructure/storage/caching-workflow-storage.d.ts +30 -6
  89. package/dist/infrastructure/storage/caching-workflow-storage.js +105 -23
  90. package/dist/infrastructure/storage/enhanced-multi-source-workflow-storage.d.ts +13 -9
  91. package/dist/infrastructure/storage/enhanced-multi-source-workflow-storage.js +45 -39
  92. package/dist/infrastructure/storage/file-workflow-storage.d.ts +10 -8
  93. package/dist/infrastructure/storage/file-workflow-storage.js +48 -56
  94. package/dist/infrastructure/storage/git-workflow-storage.d.ts +7 -22
  95. package/dist/infrastructure/storage/git-workflow-storage.js +48 -103
  96. package/dist/infrastructure/storage/in-memory-storage.d.ts +10 -6
  97. package/dist/infrastructure/storage/in-memory-storage.js +18 -13
  98. package/dist/infrastructure/storage/plugin-workflow-storage.d.ts +6 -18
  99. package/dist/infrastructure/storage/plugin-workflow-storage.js +29 -51
  100. package/dist/infrastructure/storage/remote-workflow-storage.d.ts +8 -17
  101. package/dist/infrastructure/storage/remote-workflow-storage.js +33 -156
  102. package/dist/infrastructure/storage/schema-validating-workflow-storage.d.ts +21 -13
  103. package/dist/infrastructure/storage/schema-validating-workflow-storage.js +86 -24
  104. package/dist/infrastructure/storage/storage.d.ts +7 -5
  105. package/dist/infrastructure/storage/storage.js +7 -6
  106. package/dist/manifest.json +1117 -0
  107. package/dist/mcp/error-mapper.d.ts +9 -0
  108. package/dist/mcp/error-mapper.js +66 -0
  109. package/dist/mcp/handlers/session.d.ts +34 -0
  110. package/dist/mcp/handlers/session.js +135 -0
  111. package/dist/mcp/handlers/v2-workflow.d.ts +4 -0
  112. package/dist/mcp/handlers/v2-workflow.js +112 -0
  113. package/dist/mcp/handlers/workflow.d.ts +45 -0
  114. package/dist/mcp/handlers/workflow.js +167 -0
  115. package/dist/mcp/index.d.ts +16 -0
  116. package/dist/mcp/index.js +51 -0
  117. package/dist/mcp/output-schemas.d.ts +317 -0
  118. package/dist/mcp/output-schemas.js +91 -0
  119. package/dist/mcp/server.d.ts +3 -0
  120. package/dist/mcp/server.js +258 -0
  121. package/dist/mcp/tool-description-provider.d.ts +16 -0
  122. package/dist/mcp/tool-description-provider.js +43 -0
  123. package/dist/mcp/tool-descriptions.d.ts +2 -0
  124. package/dist/mcp/tool-descriptions.js +109 -0
  125. package/dist/mcp/tool-factory.d.ts +23 -0
  126. package/dist/mcp/tool-factory.js +14 -0
  127. package/dist/mcp/tools.d.ts +156 -0
  128. package/dist/mcp/tools.js +196 -0
  129. package/dist/mcp/types/tool-description-types.d.ts +8 -0
  130. package/dist/mcp/types/tool-description-types.js +24 -0
  131. package/dist/mcp/types.d.ts +25 -0
  132. package/dist/mcp/types.js +15 -0
  133. package/dist/mcp/v2/tool-registry.d.ts +11 -0
  134. package/dist/mcp/v2/tool-registry.js +26 -0
  135. package/dist/mcp/v2/tools.d.ts +20 -0
  136. package/dist/mcp/v2/tools.js +17 -0
  137. package/dist/mcp/validation/bounded-json.d.ts +3 -0
  138. package/dist/mcp/validation/bounded-json.js +22 -0
  139. package/dist/mcp/validation/workflow-next-prevalidate.d.ts +9 -0
  140. package/dist/mcp/validation/workflow-next-prevalidate.js +83 -0
  141. package/dist/mcp/zod-to-json-schema.d.ts +17 -0
  142. package/dist/mcp/zod-to-json-schema.js +134 -0
  143. package/dist/mcp-server.d.ts +1 -1
  144. package/dist/mcp-server.js +6 -424
  145. package/dist/runtime/adapters/in-memory-shutdown-events.d.ts +6 -0
  146. package/dist/runtime/adapters/in-memory-shutdown-events.js +20 -0
  147. package/dist/runtime/adapters/node-process-signals.d.ts +4 -0
  148. package/dist/runtime/adapters/node-process-signals.js +11 -0
  149. package/dist/runtime/adapters/node-process-terminator.d.ts +4 -0
  150. package/dist/runtime/adapters/node-process-terminator.js +17 -0
  151. package/dist/runtime/adapters/noop-process-signals.d.ts +4 -0
  152. package/dist/runtime/adapters/noop-process-signals.js +8 -0
  153. package/dist/runtime/adapters/throwing-process-terminator.d.ts +4 -0
  154. package/dist/runtime/adapters/throwing-process-terminator.js +9 -0
  155. package/dist/runtime/assert-never.d.ts +1 -0
  156. package/dist/runtime/assert-never.js +6 -0
  157. package/dist/runtime/brand.d.ts +5 -0
  158. package/dist/runtime/ports/process-signals.d.ts +4 -0
  159. package/dist/runtime/ports/process-signals.js +2 -0
  160. package/dist/runtime/ports/process-terminator.d.ts +8 -0
  161. package/dist/runtime/ports/process-terminator.js +2 -0
  162. package/dist/runtime/ports/shutdown-events.d.ts +11 -0
  163. package/dist/runtime/ports/shutdown-events.js +2 -0
  164. package/dist/runtime/process-lifecycle-policy.d.ts +5 -0
  165. package/dist/runtime/process-lifecycle-policy.js +2 -0
  166. package/dist/runtime/result.d.ts +17 -0
  167. package/dist/runtime/result.js +31 -0
  168. package/dist/runtime/runtime-mode.d.ts +9 -0
  169. package/dist/runtime/runtime-mode.js +2 -0
  170. package/dist/types/storage.d.ts +16 -5
  171. package/dist/types/storage.js +8 -0
  172. package/dist/types/validation.d.ts +27 -0
  173. package/dist/types/validation.js +10 -0
  174. package/dist/types/workflow-definition.d.ts +63 -0
  175. package/dist/types/workflow-definition.js +33 -0
  176. package/dist/types/workflow-source.d.ts +51 -0
  177. package/dist/types/workflow-source.js +128 -0
  178. package/dist/types/workflow.d.ts +28 -0
  179. package/dist/types/workflow.js +96 -0
  180. package/dist/utils/workflow-init.d.ts +1 -0
  181. package/dist/utils/workflow-init.js +38 -0
  182. package/dist/v2/durable-core/canonical/hashing.d.ts +11 -0
  183. package/dist/v2/durable-core/canonical/hashing.js +13 -0
  184. package/dist/v2/durable-core/canonical/jcs.d.ts +11 -0
  185. package/dist/v2/durable-core/canonical/jcs.js +65 -0
  186. package/dist/v2/durable-core/canonical/json-types.d.ts +6 -0
  187. package/dist/v2/durable-core/canonical/json-types.js +2 -0
  188. package/dist/v2/durable-core/canonical/json-zod.d.ts +2 -0
  189. package/dist/v2/durable-core/canonical/json-zod.js +7 -0
  190. package/dist/v2/durable-core/canonical/jsonl.d.ts +4 -0
  191. package/dist/v2/durable-core/canonical/jsonl.js +13 -0
  192. package/dist/v2/durable-core/ids/index.d.ts +23 -0
  193. package/dist/v2/durable-core/ids/index.js +46 -0
  194. package/dist/v2/durable-core/ids/with-healthy-session-lock.d.ts +7 -0
  195. package/dist/v2/durable-core/ids/with-healthy-session-lock.js +2 -0
  196. package/dist/v2/durable-core/schemas/compiled-workflow/index.d.ts +47 -0
  197. package/dist/v2/durable-core/schemas/compiled-workflow/index.js +17 -0
  198. package/dist/v2/durable-core/schemas/session/events.d.ts +1812 -0
  199. package/dist/v2/durable-core/schemas/session/events.js +332 -0
  200. package/dist/v2/durable-core/schemas/session/index.d.ts +3 -0
  201. package/dist/v2/durable-core/schemas/session/index.js +8 -0
  202. package/dist/v2/durable-core/schemas/session/manifest.d.ts +57 -0
  203. package/dist/v2/durable-core/schemas/session/manifest.js +30 -0
  204. package/dist/v2/durable-core/schemas/session/session-health.d.ts +25 -0
  205. package/dist/v2/durable-core/schemas/session/session-health.js +2 -0
  206. package/dist/v2/infra/local/crypto/index.d.ts +5 -0
  207. package/dist/v2/infra/local/crypto/index.js +12 -0
  208. package/dist/v2/infra/local/data-dir/index.d.ts +13 -0
  209. package/dist/v2/infra/local/data-dir/index.js +69 -0
  210. package/dist/v2/infra/local/fs/index.d.ts +26 -0
  211. package/dist/v2/infra/local/fs/index.js +156 -0
  212. package/dist/v2/infra/local/pinned-workflow-store/index.d.ts +11 -0
  213. package/dist/v2/infra/local/pinned-workflow-store/index.js +85 -0
  214. package/dist/v2/infra/local/session-lock/index.d.ts +12 -0
  215. package/dist/v2/infra/local/session-lock/index.js +44 -0
  216. package/dist/v2/infra/local/session-store/index.d.ts +23 -0
  217. package/dist/v2/infra/local/session-store/index.js +473 -0
  218. package/dist/v2/infra/local/sha256/index.d.ts +5 -0
  219. package/dist/v2/infra/local/sha256/index.js +12 -0
  220. package/dist/v2/ports/data-dir.port.d.ts +9 -0
  221. package/dist/v2/ports/data-dir.port.js +2 -0
  222. package/dist/v2/ports/fs.port.d.ts +41 -0
  223. package/dist/v2/ports/fs.port.js +2 -0
  224. package/dist/v2/ports/pinned-workflow-store.port.d.ts +11 -0
  225. package/dist/v2/ports/pinned-workflow-store.port.js +2 -0
  226. package/dist/v2/ports/session-event-log-store.port.d.ts +49 -0
  227. package/dist/v2/ports/session-event-log-store.port.js +2 -0
  228. package/dist/v2/ports/session-lock.port.d.ts +23 -0
  229. package/dist/v2/ports/session-lock.port.js +2 -0
  230. package/dist/v2/ports/sha256.port.d.ts +4 -0
  231. package/dist/v2/ports/sha256.port.js +2 -0
  232. package/dist/v2/projections/advance-outcomes.d.ts +23 -0
  233. package/dist/v2/projections/advance-outcomes.js +23 -0
  234. package/dist/v2/projections/capabilities.d.ts +27 -0
  235. package/dist/v2/projections/capabilities.js +33 -0
  236. package/dist/v2/projections/gaps.d.ts +29 -0
  237. package/dist/v2/projections/gaps.js +49 -0
  238. package/dist/v2/projections/node-outputs.d.ts +34 -0
  239. package/dist/v2/projections/node-outputs.js +73 -0
  240. package/dist/v2/projections/preferences.d.ts +28 -0
  241. package/dist/v2/projections/preferences.js +50 -0
  242. package/dist/v2/projections/run-dag.d.ts +42 -0
  243. package/dist/v2/projections/run-dag.js +186 -0
  244. package/dist/v2/projections/run-status-signals.d.ts +26 -0
  245. package/dist/v2/projections/run-status-signals.js +49 -0
  246. package/dist/v2/projections/session-health.d.ts +4 -0
  247. package/dist/v2/projections/session-health.js +12 -0
  248. package/dist/v2/read-only/v1-to-v2-shim.d.ts +3 -0
  249. package/dist/v2/read-only/v1-to-v2-shim.js +38 -0
  250. package/dist/v2/usecases/execution-session-gate.d.ts +53 -0
  251. package/dist/v2/usecases/execution-session-gate.js +167 -0
  252. package/package.json +35 -10
  253. package/spec/mcp-api-v1.0.md +5 -5
  254. package/web/assets/services/data-normalizer.js +17 -2
  255. package/web/assets/services/pattern-recognizer.js +3 -1
  256. package/web/assets/services/session-data.js +13 -8
  257. package/web/assets/utils/formatters.js +34 -23
  258. package/workflows/CHANGELOG-bug-investigation.md +4 -4
  259. package/workflows/coding-task-workflow-agentic.json +262 -0
  260. package/workflows/design-thinking-workflow-autonomous.agentic.json +215 -0
  261. package/workflows/design-thinking-workflow.json +198 -0
  262. package/workflows/mr-review-workflow.agentic.json +538 -0
  263. package/workflows/routines/context-gathering.json +0 -4
  264. package/dist/application/app.d.ts +0 -29
  265. package/dist/application/app.d.ts.map +0 -1
  266. package/dist/application/app.js +0 -114
  267. package/dist/application/app.js.map +0 -1
  268. package/dist/application/decorators/simple-output-decorator.d.ts +0 -8
  269. package/dist/application/decorators/simple-output-decorator.js +0 -89
  270. package/dist/application/services/classification-engine.d.ts +0 -33
  271. package/dist/application/services/classification-engine.js +0 -258
  272. package/dist/application/services/compression-service.d.ts +0 -20
  273. package/dist/application/services/compression-service.js +0 -312
  274. package/dist/application/services/context-management-service.d.ts +0 -38
  275. package/dist/application/services/context-management-service.js +0 -301
  276. package/dist/application/services/context-optimizer.d.ts +0 -11
  277. package/dist/application/services/context-optimizer.js +0 -62
  278. package/dist/application/services/context-persistence-service.d.ts +0 -45
  279. package/dist/application/services/context-persistence-service.js +0 -273
  280. package/dist/application/services/documentation-service.d.ts +0 -20
  281. package/dist/application/services/documentation-service.js +0 -155
  282. package/dist/application/services/enhanced-error-service.d.ts.map +0 -1
  283. package/dist/application/services/enhanced-error-service.js.map +0 -1
  284. package/dist/application/services/loop-context-optimizer.d.ts +0 -8
  285. package/dist/application/services/loop-context-optimizer.js +0 -114
  286. package/dist/application/services/loop-execution-context.d.ts +0 -23
  287. package/dist/application/services/loop-execution-context.js +0 -188
  288. package/dist/application/services/loop-step-resolver.d.ts +0 -11
  289. package/dist/application/services/loop-step-resolver.js +0 -70
  290. package/dist/application/services/validation-engine.d.ts.map +0 -1
  291. package/dist/application/services/validation-engine.js.map +0 -1
  292. package/dist/application/services/workflow-service.d.ts.map +0 -1
  293. package/dist/application/services/workflow-service.js.map +0 -1
  294. package/dist/application/use-cases/get-next-step.d.ts.map +0 -1
  295. package/dist/application/use-cases/get-next-step.js.map +0 -1
  296. package/dist/application/use-cases/get-workflow-docs.d.ts +0 -4
  297. package/dist/application/use-cases/get-workflow-docs.js +0 -12
  298. package/dist/application/use-cases/get-workflow.d.ts.map +0 -1
  299. package/dist/application/use-cases/get-workflow.js.map +0 -1
  300. package/dist/application/use-cases/get-workrail-help.d.ts +0 -4
  301. package/dist/application/use-cases/get-workrail-help.js +0 -12
  302. package/dist/application/use-cases/list-workflows.d.ts.map +0 -1
  303. package/dist/application/use-cases/list-workflows.js.map +0 -1
  304. package/dist/application/use-cases/validate-step-output.d.ts.map +0 -1
  305. package/dist/application/use-cases/validate-step-output.js.map +0 -1
  306. package/dist/application/use-cases/validate-workflow-json.d.ts.map +0 -1
  307. package/dist/application/use-cases/validate-workflow-json.js.map +0 -1
  308. package/dist/application/validation.d.ts.map +0 -1
  309. package/dist/application/validation.js.map +0 -1
  310. package/dist/cli/migrate-workflow.d.ts +0 -22
  311. package/dist/cli/migrate-workflow.js +0 -196
  312. package/dist/cli.d.ts.map +0 -1
  313. package/dist/cli.js.map +0 -1
  314. package/dist/container.d.ts +0 -15
  315. package/dist/container.d.ts.map +0 -1
  316. package/dist/container.js +0 -25
  317. package/dist/container.js.map +0 -1
  318. package/dist/core/error-handler.d.ts.map +0 -1
  319. package/dist/core/error-handler.js.map +0 -1
  320. package/dist/domain/index.d.ts +0 -2
  321. package/dist/domain/index.d.ts.map +0 -1
  322. package/dist/domain/index.js +0 -18
  323. package/dist/domain/index.js.map +0 -1
  324. package/dist/index.d.ts.map +0 -1
  325. package/dist/index.js.map +0 -1
  326. package/dist/infrastructure/index.d.ts.map +0 -1
  327. package/dist/infrastructure/index.js.map +0 -1
  328. package/dist/infrastructure/rpc/handler.d.ts +0 -17
  329. package/dist/infrastructure/rpc/handler.d.ts.map +0 -1
  330. package/dist/infrastructure/rpc/handler.js +0 -78
  331. package/dist/infrastructure/rpc/handler.js.map +0 -1
  332. package/dist/infrastructure/rpc/index.d.ts +0 -1
  333. package/dist/infrastructure/rpc/index.d.ts.map +0 -1
  334. package/dist/infrastructure/rpc/index.js +0 -17
  335. package/dist/infrastructure/rpc/index.js.map +0 -1
  336. package/dist/infrastructure/rpc/server.d.ts +0 -3
  337. package/dist/infrastructure/rpc/server.d.ts.map +0 -1
  338. package/dist/infrastructure/rpc/server.js +0 -37
  339. package/dist/infrastructure/rpc/server.js.map +0 -1
  340. package/dist/infrastructure/storage/caching-workflow-storage.d.ts.map +0 -1
  341. package/dist/infrastructure/storage/caching-workflow-storage.js.map +0 -1
  342. package/dist/infrastructure/storage/context-storage.d.ts +0 -150
  343. package/dist/infrastructure/storage/context-storage.js +0 -40
  344. package/dist/infrastructure/storage/file-workflow-storage.d.ts.map +0 -1
  345. package/dist/infrastructure/storage/file-workflow-storage.js.map +0 -1
  346. package/dist/infrastructure/storage/filesystem-blob-storage.d.ts +0 -27
  347. package/dist/infrastructure/storage/filesystem-blob-storage.js +0 -363
  348. package/dist/infrastructure/storage/git-workflow-storage.d.ts.map +0 -1
  349. package/dist/infrastructure/storage/git-workflow-storage.js.map +0 -1
  350. package/dist/infrastructure/storage/hybrid-context-storage.d.ts +0 -29
  351. package/dist/infrastructure/storage/hybrid-context-storage.js +0 -400
  352. package/dist/infrastructure/storage/in-memory-storage.d.ts.map +0 -1
  353. package/dist/infrastructure/storage/in-memory-storage.js.map +0 -1
  354. package/dist/infrastructure/storage/index.d.ts.map +0 -1
  355. package/dist/infrastructure/storage/index.js.map +0 -1
  356. package/dist/infrastructure/storage/migrations/001_initial_schema.sql +0 -38
  357. package/dist/infrastructure/storage/migrations/002_context_concurrency_enhancements.sql +0 -234
  358. package/dist/infrastructure/storage/migrations/003_classification_overrides.sql +0 -20
  359. package/dist/infrastructure/storage/multi-directory-workflow-storage.d.ts +0 -32
  360. package/dist/infrastructure/storage/multi-directory-workflow-storage.d.ts.map +0 -1
  361. package/dist/infrastructure/storage/multi-directory-workflow-storage.js +0 -184
  362. package/dist/infrastructure/storage/multi-directory-workflow-storage.js.map +0 -1
  363. package/dist/infrastructure/storage/plugin-workflow-storage.d.ts.map +0 -1
  364. package/dist/infrastructure/storage/plugin-workflow-storage.js.map +0 -1
  365. package/dist/infrastructure/storage/remote-workflow-storage.d.ts.map +0 -1
  366. package/dist/infrastructure/storage/remote-workflow-storage.js.map +0 -1
  367. package/dist/infrastructure/storage/schema-validating-workflow-storage.d.ts.map +0 -1
  368. package/dist/infrastructure/storage/schema-validating-workflow-storage.js.map +0 -1
  369. package/dist/infrastructure/storage/sqlite-metadata-storage.d.ts +0 -35
  370. package/dist/infrastructure/storage/sqlite-metadata-storage.js +0 -410
  371. package/dist/infrastructure/storage/sqlite-migrator.d.ts +0 -46
  372. package/dist/infrastructure/storage/sqlite-migrator.js +0 -293
  373. package/dist/infrastructure/storage/storage.d.ts.map +0 -1
  374. package/dist/infrastructure/storage/storage.js.map +0 -1
  375. package/dist/mcp-server.d.ts.map +0 -1
  376. package/dist/mcp-server.js.map +0 -1
  377. package/dist/tools/mcp_initialize.d.ts +0 -2
  378. package/dist/tools/mcp_initialize.d.ts.map +0 -1
  379. package/dist/tools/mcp_initialize.js +0 -45
  380. package/dist/tools/mcp_initialize.js.map +0 -1
  381. package/dist/tools/mcp_shutdown.d.ts +0 -2
  382. package/dist/tools/mcp_shutdown.d.ts.map +0 -1
  383. package/dist/tools/mcp_shutdown.js +0 -10
  384. package/dist/tools/mcp_shutdown.js.map +0 -1
  385. package/dist/tools/mcp_tools_list.d.ts +0 -2
  386. package/dist/tools/mcp_tools_list.d.ts.map +0 -1
  387. package/dist/tools/mcp_tools_list.js +0 -60
  388. package/dist/tools/mcp_tools_list.js.map +0 -1
  389. package/dist/tools/session-tools.d.ts +0 -5
  390. package/dist/tools/session-tools.js +0 -270
  391. package/dist/types/context-types.d.ts +0 -236
  392. package/dist/types/context-types.js +0 -10
  393. package/dist/types/documentation-types.d.ts +0 -37
  394. package/dist/types/loop-context-optimizer.d.ts +0 -7
  395. package/dist/types/mcp-types.d.ts +0 -273
  396. package/dist/types/mcp-types.d.ts.map +0 -1
  397. package/dist/types/mcp-types.js +0 -19
  398. package/dist/types/mcp-types.js.map +0 -1
  399. package/dist/types/server.d.ts.map +0 -1
  400. package/dist/types/server.js.map +0 -1
  401. package/dist/types/storage.d.ts.map +0 -1
  402. package/dist/types/storage.js.map +0 -1
  403. package/dist/types/workflow-types.d.ts +0 -336
  404. package/dist/types/workflow-types.d.ts.map +0 -1
  405. package/dist/types/workflow-types.js +0 -20
  406. package/dist/types/workflow-types.js.map +0 -1
  407. package/dist/utils/condition-evaluator.d.ts.map +0 -1
  408. package/dist/utils/condition-evaluator.js.map +0 -1
  409. package/dist/utils/config.d.ts +0 -149
  410. package/dist/utils/config.d.ts.map +0 -1
  411. package/dist/utils/config.js +0 -251
  412. package/dist/utils/config.js.map +0 -1
  413. package/dist/utils/storage-security.d.ts.map +0 -1
  414. package/dist/utils/storage-security.js.map +0 -1
  415. package/dist/validation/request-validator.d.ts +0 -8
  416. package/dist/validation/request-validator.d.ts.map +0 -1
  417. package/dist/validation/request-validator.js +0 -32
  418. package/dist/validation/request-validator.js.map +0 -1
  419. package/dist/validation/response-validator.d.ts +0 -8
  420. package/dist/validation/response-validator.d.ts.map +0 -1
  421. package/dist/validation/response-validator.js +0 -110
  422. package/dist/validation/response-validator.js.map +0 -1
  423. package/dist/validation/schemas.d.ts +0 -1
  424. package/dist/validation/schemas.d.ts.map +0 -1
  425. package/dist/validation/schemas.js +0 -53
  426. package/dist/validation/schemas.js.map +0 -1
  427. /package/dist/{types/documentation-types.js → errors/app-error.js} +0 -0
  428. /package/dist/{types/loop-context-optimizer.js → runtime/brand.js} +0 -0
@@ -1,47 +1,49 @@
1
+ import type { ConditionContext } from '../../utils/condition-evaluator';
2
+ import type { Workflow, WorkflowSummary } from '../../types/workflow';
3
+ import { ValidationEngine } from './validation-engine';
4
+ import { WorkflowCompiler } from './workflow-compiler';
5
+ import { WorkflowInterpreter, NextStep } from './workflow-interpreter';
6
+ import type { ExecutionState } from '../../domain/execution/state';
7
+ import type { WorkflowEvent } from '../../domain/execution/event';
8
+ import type { DomainError } from '../../domain/execution/error';
9
+ import type { Result } from 'neverthrow';
1
10
  export interface WorkflowService {
2
- listWorkflowSummaries(): Promise<import('../../types/mcp-types').WorkflowSummary[]>;
3
- getWorkflowById(id: string): Promise<import('../../types/mcp-types').Workflow | null>;
4
- getNextStep(workflowId: string, completedSteps: string[], context?: ConditionContext): Promise<{
5
- step: import('../../types/mcp-types').WorkflowStep | null;
6
- guidance: import('../../types/mcp-types').WorkflowGuidance;
11
+ listWorkflowSummaries(): Promise<readonly WorkflowSummary[]>;
12
+ getWorkflowById(id: string): Promise<Workflow | null>;
13
+ getNextStep(workflowId: string, state: ExecutionState, event?: WorkflowEvent, context?: ConditionContext): Promise<Result<{
14
+ state: ExecutionState;
15
+ next: NextStep | null;
7
16
  isComplete: boolean;
8
- context?: ConditionContext;
9
- }>;
17
+ }, DomainError>>;
10
18
  validateStepOutput(workflowId: string, stepId: string, output: string): Promise<{
11
19
  valid: boolean;
12
- issues: string[];
13
- suggestions: string[];
20
+ issues: readonly string[];
21
+ suggestions: readonly string[];
14
22
  }>;
15
23
  }
16
- import { Workflow, WorkflowSummary, WorkflowStep, WorkflowGuidance } from '../../types/mcp-types';
17
- import { IWorkflowStorage } from '../../types/storage';
18
- import { ConditionContext } from '../../utils/condition-evaluator';
19
- import { ValidationEngine } from './validation-engine';
20
- import { EnhancedContext } from '../../types/workflow-types';
21
- import { ILoopContextOptimizer } from '../../types/loop-context-optimizer';
22
24
  export declare class DefaultWorkflowService implements WorkflowService {
23
25
  private readonly storage;
24
26
  private readonly validationEngine;
25
- private readonly loopContextOptimizer?;
26
- private loopStepResolver;
27
- constructor(storage?: IWorkflowStorage, validationEngine?: ValidationEngine, loopContextOptimizer?: ILoopContextOptimizer | undefined);
28
- listWorkflowSummaries(): Promise<WorkflowSummary[]>;
27
+ private readonly compiler;
28
+ private readonly interpreter;
29
+ private readonly logger;
30
+ private readonly compiledCache;
31
+ private readonly COMPILED_CACHE_MAX;
32
+ constructor(storage: import('../../types/storage').IWorkflowReader, validationEngine: ValidationEngine, compiler: WorkflowCompiler, interpreter: WorkflowInterpreter);
33
+ listWorkflowSummaries(): Promise<readonly WorkflowSummary[]>;
29
34
  getWorkflowById(id: string): Promise<Workflow | null>;
30
- getNextStep(workflowId: string, completedSteps: string[], context?: ConditionContext): Promise<{
31
- step: WorkflowStep | null;
32
- guidance: WorkflowGuidance;
35
+ getNextStep(workflowId: string, state: ExecutionState, event?: WorkflowEvent, context?: ConditionContext): Promise<Result<{
36
+ state: ExecutionState;
37
+ next: NextStep | null;
33
38
  isComplete: boolean;
34
- context?: ConditionContext;
35
- }>;
36
- private buildStepPrompt;
37
- private collectConditionVars;
38
- private collectEqualsValues;
39
- private findLoopStepById;
39
+ }, DomainError>>;
40
40
  validateStepOutput(workflowId: string, stepId: string, output: string): Promise<{
41
41
  valid: boolean;
42
- issues: string[];
43
- suggestions: string[];
42
+ issues: readonly string[];
43
+ suggestions: readonly string[];
44
44
  }>;
45
- updateContextForStepCompletion(workflowId: string, stepId: string, context: ConditionContext): Promise<EnhancedContext>;
45
+ private getOrCompile;
46
+ __debugCompiledCacheSize(): number;
47
+ __debugPrimeCompiledWorkflow(id: string): void;
48
+ private evictCompiledCacheIfNeeded;
46
49
  }
47
- export declare const defaultWorkflowService: WorkflowService;
@@ -1,21 +1,35 @@
1
1
  "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
2
14
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defaultWorkflowService = exports.DefaultWorkflowService = void 0;
4
- const storage_1 = require("../../infrastructure/storage");
5
- const error_handler_1 = require("../../core/error-handler");
6
- const condition_evaluator_1 = require("../../utils/condition-evaluator");
15
+ exports.DefaultWorkflowService = void 0;
16
+ const tsyringe_1 = require("tsyringe");
17
+ const tokens_js_1 = require("../../di/tokens.js");
7
18
  const validation_engine_1 = require("./validation-engine");
8
- const workflow_types_1 = require("../../types/workflow-types");
9
- const loop_execution_context_1 = require("./loop-execution-context");
10
- const loop_step_resolver_1 = require("./loop-step-resolver");
11
- const context_size_1 = require("../../utils/context-size");
12
- const context_optimizer_1 = require("./context-optimizer");
13
- class DefaultWorkflowService {
14
- constructor(storage = (0, storage_1.createDefaultWorkflowStorage)(), validationEngine = new validation_engine_1.ValidationEngine(), loopContextOptimizer) {
19
+ const workflow_compiler_1 = require("./workflow-compiler");
20
+ const workflow_interpreter_1 = require("./workflow-interpreter");
21
+ const error_1 = require("../../domain/execution/error");
22
+ const neverthrow_1 = require("neverthrow");
23
+ const logger_1 = require("../../utils/logger");
24
+ let DefaultWorkflowService = class DefaultWorkflowService {
25
+ constructor(storage, validationEngine, compiler, interpreter) {
15
26
  this.storage = storage;
16
27
  this.validationEngine = validationEngine;
17
- this.loopContextOptimizer = loopContextOptimizer;
18
- this.loopStepResolver = new loop_step_resolver_1.LoopStepResolver();
28
+ this.compiler = compiler;
29
+ this.interpreter = interpreter;
30
+ this.logger = (0, logger_1.createLogger)('WorkflowService');
31
+ this.compiledCache = new Map();
32
+ this.COMPILED_CACHE_MAX = 1000;
19
33
  }
20
34
  async listWorkflowSummaries() {
21
35
  return this.storage.listWorkflowSummaries();
@@ -23,428 +37,82 @@ class DefaultWorkflowService {
23
37
  async getWorkflowById(id) {
24
38
  return this.storage.getWorkflowById(id);
25
39
  }
26
- async getNextStep(workflowId, completedSteps, context = {}) {
27
- const sizeCheck = (0, context_size_1.checkContextSize)(context);
28
- if (sizeCheck.isError) {
29
- throw new Error(`Context size (${Math.round(sizeCheck.sizeBytes / 1024)}KB) exceeds maximum allowed size (256KB)`);
30
- }
31
- const checkedContext = sizeCheck.context;
40
+ async getNextStep(workflowId, state, event, context = {}) {
32
41
  const workflow = await this.storage.getWorkflowById(workflowId);
33
- if (!workflow) {
34
- throw new error_handler_1.WorkflowNotFoundError(workflowId);
35
- }
36
- const validationResult = this.validationEngine.validateWorkflow(workflow);
37
- if (!validationResult.valid) {
38
- throw new Error(`Invalid workflow structure: ${validationResult.issues.join('; ')}`);
39
- }
40
- const completed = [...(completedSteps || [])];
41
- const enhancedContext = checkedContext;
42
- const loopBodySteps = new Set();
43
- const bodyStepToLoop = new Map();
44
- for (const step of workflow.steps) {
45
- if ((0, workflow_types_1.isLoopStep)(step)) {
46
- const loopStep = step;
47
- if (typeof loopStep.body === 'string') {
48
- loopBodySteps.add(loopStep.body);
49
- bodyStepToLoop.set(loopStep.body, loopStep);
50
- }
51
- else if (Array.isArray(loopStep.body)) {
52
- loopStep.body.forEach(bodyStep => {
53
- loopBodySteps.add(bodyStep.id);
54
- bodyStepToLoop.set(bodyStep.id, loopStep);
55
- });
56
- }
57
- }
58
- }
59
- if (!enhancedContext._currentLoop) {
60
- const completedLoopBodySteps = completed.filter(stepId => loopBodySteps.has(stepId));
61
- if (completedLoopBodySteps.length > 0) {
62
- const loopStep = bodyStepToLoop.get(completedLoopBodySteps[0]);
63
- if (loopStep && !completed.includes(loopStep.id)) {
64
- enhancedContext._currentLoop = {
65
- loopId: loopStep.id,
66
- loopStep: loopStep
67
- };
68
- if (!enhancedContext._loopState || !enhancedContext._loopState[loopStep.id]) {
69
- const resolvedBody = this.loopStepResolver.resolveLoopBody(workflow, loopStep.body, loopStep.id);
70
- let completedIterations = 0;
71
- if (Array.isArray(resolvedBody)) {
72
- const hasConditionalSteps = resolvedBody.some(step => step.runCondition);
73
- if (hasConditionalSteps) {
74
- completedIterations = completedLoopBodySteps.length;
75
- }
76
- else {
77
- completedIterations = 0;
78
- }
79
- }
80
- else {
81
- completedIterations = completedLoopBodySteps.length;
82
- }
83
- if (!enhancedContext._loopState) {
84
- enhancedContext._loopState = {};
85
- }
86
- enhancedContext._loopState[loopStep.id] = {
87
- iteration: completedIterations,
88
- started: Date.now(),
89
- warnings: []
90
- };
91
- }
92
- }
93
- }
94
- }
95
- if (enhancedContext._currentLoop) {
96
- const { loopId, loopStep } = enhancedContext._currentLoop;
97
- const loopContext = new loop_execution_context_1.LoopExecutionContext(loopId, loopStep.loop, enhancedContext._loopState?.[loopId]);
98
- const bodyStep = this.loopStepResolver.resolveLoopBody(workflow, loopStep.body, loopStep.id);
99
- let bodyIsCompleted;
100
- if (Array.isArray(bodyStep)) {
101
- const loopEnhancedContext = loopContext.injectVariables(enhancedContext, false);
102
- const eligibleSteps = bodyStep.filter(step => {
103
- if (!step.runCondition) {
104
- return true;
105
- }
106
- return (0, condition_evaluator_1.evaluateCondition)(step.runCondition, loopEnhancedContext);
107
- });
108
- bodyIsCompleted = eligibleSteps.length === 0 || eligibleSteps.every(step => completed.includes(step.id));
109
- }
110
- else {
111
- bodyIsCompleted = completed.includes(bodyStep.id);
112
- }
113
- if (bodyIsCompleted) {
114
- loopContext.incrementIteration();
115
- if (!enhancedContext._loopState) {
116
- enhancedContext._loopState = {};
117
- }
118
- enhancedContext._loopState[loopId] = loopContext.getCurrentState();
119
- if (Array.isArray(bodyStep)) {
120
- bodyStep.forEach(step => {
121
- const index = completed.indexOf(step.id);
122
- if (index > -1) {
123
- completed.splice(index, 1);
124
- }
125
- });
126
- }
127
- else {
128
- const index = completed.indexOf(bodyStep.id);
129
- if (index > -1) {
130
- completed.splice(index, 1);
131
- }
132
- }
133
- if (!loopContext.shouldContinue(context)) {
134
- completed.push(loopId);
135
- delete enhancedContext._currentLoop;
136
- const nextStep = await this.getNextStep(workflow.id, completed, enhancedContext);
137
- return nextStep;
138
- }
139
- }
140
- if (loopContext.shouldContinue(context)) {
141
- if (!Array.isArray(bodyStep)) {
142
- const isFirst = loopContext.isFirstIteration();
143
- if (isFirst && loopContext.isEmpty(context)) {
144
- const skipContext = context_optimizer_1.ContextOptimizer.createEnhancedContext(context, completed);
145
- delete skipContext._currentLoop;
146
- const nextStep = await this.getNextStep(workflow.id, completed, skipContext);
147
- return nextStep;
148
- }
149
- const useMinimal = !isFirst && !!this.loopContextOptimizer;
150
- const loopEnhancedContext = loopContext.injectVariables(context, useMinimal);
151
- const optimizedContext = useMinimal && this.loopContextOptimizer
152
- ? this.loopContextOptimizer.stripLoopMetadata(loopEnhancedContext)
153
- : loopEnhancedContext;
154
- const loopSizeCheck = (0, context_size_1.checkContextSize)(optimizedContext);
155
- if (loopSizeCheck.isError) {
156
- throw new Error(`Context size (${Math.round(loopSizeCheck.sizeBytes / 1024)}KB) exceeds maximum allowed size (256KB) during loop execution`);
157
- }
158
- return {
159
- step: bodyStep,
160
- guidance: {
161
- prompt: this.buildStepPrompt(bodyStep, loopContext, useMinimal)
162
- },
163
- isComplete: false,
164
- context: loopSizeCheck.context
165
- };
166
- }
167
- else {
168
- const isFirst = loopContext.isFirstIteration();
169
- if (isFirst && loopContext.isEmpty(context)) {
170
- const skipContext = context_optimizer_1.ContextOptimizer.createEnhancedContext(context, completed);
171
- delete skipContext._currentLoop;
172
- const nextStep = await this.getNextStep(workflow.id, completed, skipContext);
173
- return nextStep;
174
- }
175
- const useMinimal = !isFirst && !!this.loopContextOptimizer;
176
- const loopEnhancedContext = loopContext.injectVariables(context, useMinimal);
177
- const uncompletedBodyStep = bodyStep.find(step => {
178
- if (completed.includes(step.id)) {
179
- return false;
180
- }
181
- if (step.runCondition) {
182
- return (0, condition_evaluator_1.evaluateCondition)(step.runCondition, loopEnhancedContext);
183
- }
184
- return true;
185
- });
186
- if (uncompletedBodyStep) {
187
- const optimizedContext = useMinimal && this.loopContextOptimizer
188
- ? this.loopContextOptimizer.stripLoopMetadata(loopEnhancedContext)
189
- : loopEnhancedContext;
190
- const loopSizeCheck = (0, context_size_1.checkContextSize)(optimizedContext);
191
- if (loopSizeCheck.isError) {
192
- throw new Error(`Context size (${Math.round(loopSizeCheck.sizeBytes / 1024)}KB) exceeds maximum allowed size (256KB) during loop execution`);
193
- }
194
- return {
195
- step: uncompletedBodyStep,
196
- guidance: {
197
- prompt: this.buildStepPrompt(uncompletedBodyStep, loopContext, useMinimal)
198
- },
199
- isComplete: false,
200
- context: loopSizeCheck.context
201
- };
202
- }
203
- else {
204
- loopContext.incrementIteration();
205
- if (!enhancedContext._loopState) {
206
- enhancedContext._loopState = {};
207
- }
208
- enhancedContext._loopState[loopId] = loopContext.getCurrentState();
209
- bodyStep.forEach(step => {
210
- const index = completed.indexOf(step.id);
211
- if (index > -1) {
212
- completed.splice(index, 1);
213
- }
214
- });
215
- return this.getNextStep(workflowId, completed, enhancedContext);
216
- }
217
- }
218
- }
219
- else {
220
- completed.push(loopId);
221
- delete enhancedContext._currentLoop;
222
- }
223
- }
224
- const nextStep = workflow.steps.find((step) => {
225
- if (completed.includes(step.id)) {
226
- return false;
227
- }
228
- if (loopBodySteps.has(step.id)) {
229
- if (!enhancedContext._currentLoop) {
230
- return false;
231
- }
232
- const currentLoopBody = enhancedContext._currentLoop.loopStep.body;
233
- if (typeof currentLoopBody === 'string') {
234
- return currentLoopBody === step.id;
235
- }
236
- else if (Array.isArray(currentLoopBody)) {
237
- return currentLoopBody.some(bodyStep => bodyStep.id === step.id);
238
- }
239
- return false;
240
- }
241
- if (step.runCondition) {
242
- return (0, condition_evaluator_1.evaluateCondition)(step.runCondition, context);
243
- }
244
- return true;
245
- }) || null;
246
- if (nextStep && (0, workflow_types_1.isLoopStep)(nextStep)) {
247
- const loopStep = nextStep;
248
- const loopContext = new loop_execution_context_1.LoopExecutionContext(nextStep.id, loopStep.loop, enhancedContext._loopState?.[nextStep.id]);
249
- if (loopStep.loop.type === 'forEach') {
250
- loopContext.initializeForEach(context);
251
- }
252
- if (!loopContext.shouldContinue(context)) {
253
- completed.push(nextStep.id);
254
- const loopStateData = loopContext.getCurrentState();
255
- let skipContext = context_optimizer_1.ContextOptimizer.mergeLoopState(context, nextStep.id, loopStateData);
256
- if (loopStateData.warnings && loopStateData.warnings.length > 0) {
257
- skipContext = context_optimizer_1.ContextOptimizer.addWarnings(skipContext, 'loops', nextStep.id, loopStateData.warnings);
258
- }
259
- return this.getNextStep(workflowId, completed, skipContext);
260
- }
261
- let newContext = context_optimizer_1.ContextOptimizer.createEnhancedContext(context, {
262
- _currentLoop: {
263
- loopId: nextStep.id,
264
- loopStep: loopStep
265
- }
266
- });
267
- newContext = context_optimizer_1.ContextOptimizer.mergeLoopState(newContext, nextStep.id, loopContext.getCurrentState());
268
- const loopStartSizeCheck = (0, context_size_1.checkContextSize)(newContext);
269
- if (loopStartSizeCheck.isError) {
270
- throw new Error(`Context size (${Math.round(loopStartSizeCheck.sizeBytes / 1024)}KB) exceeds maximum allowed size (256KB) when starting loop`);
271
- }
272
- return this.getNextStep(workflowId, completedSteps, loopStartSizeCheck.context);
273
- }
274
- if (!nextStep) {
275
- const remainingConditionalSteps = workflow.steps.filter((step) => {
276
- if (completed.includes(step.id))
277
- return false;
278
- if (loopBodySteps.has(step.id))
279
- return false;
280
- return !!step.runCondition;
281
- });
282
- if (remainingConditionalSteps.length > 0) {
283
- const requiredVars = new Set();
284
- const allowedValues = {};
285
- for (const step of remainingConditionalSteps) {
286
- const condition = step.runCondition;
287
- this.collectConditionVars(condition, requiredVars);
288
- this.collectEqualsValues(condition, allowedValues);
289
- }
290
- const issues = [];
291
- for (const variableName of requiredVars) {
292
- const currentValue = enhancedContext[variableName];
293
- const allowed = allowedValues[variableName]
294
- ? Array.from(allowedValues[variableName])
295
- : [];
296
- if (currentValue === undefined || currentValue === null || currentValue === '') {
297
- if (allowed.length > 0) {
298
- issues.push(`Set '${variableName}' to one of: ${allowed.map(v => `'${v}'`).join(', ')}`);
299
- }
300
- else {
301
- issues.push(`Provide a value for '${variableName}'`);
302
- }
303
- }
304
- else if (allowed.length > 0) {
305
- const matchesExactly = allowed.some(v => v === String(currentValue));
306
- const matchesCaseInsensitive = allowed.some(v => v.toLowerCase() === String(currentValue).toLowerCase());
307
- if (!matchesExactly) {
308
- if (matchesCaseInsensitive) {
309
- issues.push(`Normalize casing for '${variableName}': use one of ${allowed.map(v => `'${v}'`).join(', ')} (current '${currentValue}')`);
310
- }
311
- else {
312
- issues.push(`Adjust '${variableName}' to one of: ${allowed.map(v => `'${v}'`).join(', ')} (current '${currentValue}')`);
313
- }
314
- }
315
- }
316
- }
317
- if (issues.length > 0) {
318
- return {
319
- step: null,
320
- guidance: {
321
- prompt: `No eligible step due to unmet conditions. Please update context:\n- ${issues.join('\n- ')}`
322
- },
323
- isComplete: false,
324
- context: enhancedContext
325
- };
326
- }
327
- }
328
- }
329
- const isComplete = !nextStep;
330
- let finalPrompt = 'Workflow complete.';
331
- if (nextStep) {
332
- finalPrompt = this.buildStepPrompt(nextStep);
333
- }
334
- return {
335
- step: nextStep,
336
- guidance: {
337
- prompt: finalPrompt
338
- },
339
- isComplete,
340
- context: enhancedContext
341
- };
342
- }
343
- buildStepPrompt(step, loopContext, useMinimal = false) {
344
- let stepGuidance = '';
345
- if (step.guidance && step.guidance.length > 0) {
346
- const guidanceHeader = '## Step Guidance';
347
- const guidanceList = step.guidance.map((g) => `- ${g}`).join('\n');
348
- stepGuidance = `${guidanceHeader}\n${guidanceList}\n\n`;
349
- }
350
- let finalPrompt = `${stepGuidance}${step.prompt}`;
351
- if (step.agentRole) {
352
- finalPrompt = `## Agent Role Instructions\n${step.agentRole}\n\n${finalPrompt}`;
353
- }
354
- if (loopContext) {
355
- const state = loopContext.getCurrentState();
356
- if (useMinimal && this.loopContextOptimizer) {
357
- finalPrompt += `\n\n## Loop Context\n- Iteration: ${state.iteration + 1}`;
358
- if (!loopContext.isFirstIteration()) {
359
- finalPrompt += '\n\n_Note: Refer to the phase overview provided in the first iteration for overall context._';
360
- }
361
- }
362
- else {
363
- finalPrompt += `\n\n## Loop Context\n- Iteration: ${state.iteration + 1}`;
364
- if (state.items) {
365
- finalPrompt += `\n- Total Items: ${state.items.length}`;
366
- finalPrompt += `\n- Current Index: ${state.index}`;
367
- }
368
- }
369
- }
370
- return finalPrompt;
371
- }
372
- collectConditionVars(condition, sink) {
373
- if (!condition || typeof condition !== 'object')
374
- return;
375
- if (typeof condition.var === 'string' && condition.var.length > 0) {
376
- sink.add(condition.var);
377
- }
378
- if (Array.isArray(condition.and)) {
379
- for (const sub of condition.and)
380
- this.collectConditionVars(sub, sink);
381
- }
382
- if (Array.isArray(condition.or)) {
383
- for (const sub of condition.or)
384
- this.collectConditionVars(sub, sink);
385
- }
386
- if (condition.not)
387
- this.collectConditionVars(condition.not, sink);
388
- }
389
- collectEqualsValues(condition, sink) {
390
- if (!condition || typeof condition !== 'object')
391
- return;
392
- if (typeof condition.var === 'string' && Object.prototype.hasOwnProperty.call(condition, 'equals')) {
393
- const variableName = condition.var;
394
- const value = condition.equals;
395
- if (value !== undefined && value !== null) {
396
- if (!sink[variableName])
397
- sink[variableName] = new Set();
398
- sink[variableName].add(String(value));
399
- }
400
- }
401
- if (Array.isArray(condition.and)) {
402
- for (const sub of condition.and)
403
- this.collectEqualsValues(sub, sink);
404
- }
405
- if (Array.isArray(condition.or)) {
406
- for (const sub of condition.or)
407
- this.collectEqualsValues(sub, sink);
408
- }
409
- if (condition.not)
410
- this.collectEqualsValues(condition.not, sink);
411
- }
412
- findLoopStepById(workflow, stepId) {
413
- const step = workflow.steps.find(s => s.id === stepId);
414
- return step && (0, workflow_types_1.isLoopStep)(step) ? step : null;
42
+ if (!workflow)
43
+ return (0, neverthrow_1.err)(error_1.Err.workflowNotFound(workflowId));
44
+ const compiled = this.getOrCompile(workflowId, workflow);
45
+ if (compiled.isErr())
46
+ return (0, neverthrow_1.err)(compiled.error);
47
+ const advancedState = event ? this.interpreter.applyEvent(state, event) : (0, neverthrow_1.ok)(state);
48
+ if (advancedState.isErr())
49
+ return (0, neverthrow_1.err)(advancedState.error);
50
+ const next = this.interpreter.next(compiled.value, advancedState.value, context);
51
+ if (next.isErr())
52
+ return (0, neverthrow_1.err)(next.error);
53
+ return (0, neverthrow_1.ok)({
54
+ state: next.value.state,
55
+ next: next.value.next,
56
+ isComplete: next.value.isComplete,
57
+ });
415
58
  }
416
59
  async validateStepOutput(workflowId, stepId, output) {
417
60
  const workflow = await this.storage.getWorkflowById(workflowId);
418
61
  if (!workflow) {
419
- throw new error_handler_1.WorkflowNotFoundError(workflowId);
62
+ return { valid: false, issues: [`Workflow '${workflowId}' not found`], suggestions: [] };
420
63
  }
421
- const step = workflow.steps.find((s) => s.id === stepId);
64
+ const step = workflow.definition.steps.find((s) => s.id === stepId);
422
65
  if (!step) {
423
- throw new error_handler_1.StepNotFoundError(stepId, workflowId);
66
+ return { valid: false, issues: [`Step '${stepId}' not found in workflow '${workflowId}'`], suggestions: [] };
424
67
  }
425
- const criteria = step.validationCriteria || [];
68
+ const criteria = step.validationCriteria;
69
+ if (!criteria)
70
+ return { valid: true, issues: [], suggestions: [] };
426
71
  return this.validationEngine.validate(output, criteria);
427
72
  }
428
- async updateContextForStepCompletion(workflowId, stepId, context) {
429
- let enhancedContext = context;
430
- if (enhancedContext._currentLoop) {
431
- const { loopId, loopStep } = enhancedContext._currentLoop;
432
- const workflow = await this.storage.getWorkflowById(workflowId);
433
- if (workflow) {
434
- const bodyStep = this.loopStepResolver.resolveLoopBody(workflow, loopStep.body, loopStep.id);
435
- if (!Array.isArray(bodyStep) && bodyStep.id === stepId) {
436
- const loopContext = new loop_execution_context_1.LoopExecutionContext(loopId, loopStep.loop, enhancedContext._loopState?.[loopId]);
437
- loopContext.incrementIteration();
438
- enhancedContext = context_optimizer_1.ContextOptimizer.mergeLoopState(enhancedContext, loopId, loopContext.getCurrentState());
439
- }
440
- }
441
- }
442
- const sizeCheck = (0, context_size_1.checkContextSize)(enhancedContext);
443
- if (sizeCheck.isError) {
444
- throw new Error(`Context size (${Math.round(sizeCheck.sizeBytes / 1024)}KB) exceeds maximum allowed size (256KB) after step completion`);
73
+ getOrCompile(workflowId, workflow) {
74
+ const cached = this.compiledCache.get(workflowId);
75
+ if (cached)
76
+ return (0, neverthrow_1.ok)(cached);
77
+ const validation = this.validationEngine.validateWorkflow(workflow);
78
+ if (!validation.valid) {
79
+ return (0, neverthrow_1.err)(error_1.Err.invalidState(`Invalid workflow structure: ${validation.issues.join('; ')}`));
80
+ }
81
+ const compiled = this.compiler.compile(workflow);
82
+ if (compiled.isErr())
83
+ return (0, neverthrow_1.err)(compiled.error);
84
+ this.compiledCache.set(workflowId, compiled.value);
85
+ this.evictCompiledCacheIfNeeded();
86
+ return (0, neverthrow_1.ok)(compiled.value);
87
+ }
88
+ __debugCompiledCacheSize() {
89
+ return this.compiledCache.size;
90
+ }
91
+ __debugPrimeCompiledWorkflow(id) {
92
+ if (this.compiledCache.has(id))
93
+ return;
94
+ this.compiledCache.set(id, {});
95
+ this.evictCompiledCacheIfNeeded();
96
+ }
97
+ evictCompiledCacheIfNeeded() {
98
+ if (this.compiledCache.size <= this.COMPILED_CACHE_MAX)
99
+ return;
100
+ while (this.compiledCache.size > this.COMPILED_CACHE_MAX) {
101
+ const oldestKey = this.compiledCache.keys().next().value;
102
+ if (!oldestKey)
103
+ return;
104
+ this.compiledCache.delete(oldestKey);
445
105
  }
446
- return sizeCheck.context;
447
106
  }
448
- }
107
+ };
449
108
  exports.DefaultWorkflowService = DefaultWorkflowService;
450
- exports.defaultWorkflowService = new DefaultWorkflowService();
109
+ exports.DefaultWorkflowService = DefaultWorkflowService = __decorate([
110
+ (0, tsyringe_1.singleton)(),
111
+ __param(0, (0, tsyringe_1.inject)(tokens_js_1.DI.Storage.Primary)),
112
+ __param(1, (0, tsyringe_1.inject)(validation_engine_1.ValidationEngine)),
113
+ __param(2, (0, tsyringe_1.inject)(workflow_compiler_1.WorkflowCompiler)),
114
+ __param(3, (0, tsyringe_1.inject)(workflow_interpreter_1.WorkflowInterpreter)),
115
+ __metadata("design:paramtypes", [Object, validation_engine_1.ValidationEngine,
116
+ workflow_compiler_1.WorkflowCompiler,
117
+ workflow_interpreter_1.WorkflowInterpreter])
118
+ ], DefaultWorkflowService);
@@ -1,13 +1,9 @@
1
1
  import { WorkflowService } from '../services/workflow-service';
2
- import { WorkflowStep, WorkflowGuidance } from '../../types/mcp-types';
3
2
  import { ConditionContext } from '../../utils/condition-evaluator';
4
- export declare function createGetNextStep(service: WorkflowService): (workflowId: string, completedSteps: string[], context?: ConditionContext) => Promise<{
5
- step: WorkflowStep | null;
6
- guidance: WorkflowGuidance;
3
+ import type { ExecutionState } from '../../domain/execution/state';
4
+ import type { WorkflowEvent } from '../../domain/execution/event';
5
+ export declare function createGetNextStep(service: WorkflowService): (workflowId: string, state: ExecutionState, event?: WorkflowEvent, context?: ConditionContext) => Promise<import("neverthrow").Result<{
6
+ state: ExecutionState;
7
+ next: import("../services/workflow-interpreter").NextStep | null;
7
8
  isComplete: boolean;
8
- }>;
9
- export declare function getNextStep(service: WorkflowService, workflowId: string, completedSteps: string[], context?: ConditionContext): Promise<{
10
- step: WorkflowStep | null;
11
- guidance: WorkflowGuidance;
12
- isComplete: boolean;
13
- }>;
9
+ }, import("../../domain/execution/error").DomainError>>;