@generacy-ai/workflow-engine 0.0.0-preview-20260304013206

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 (347) hide show
  1. package/LICENSE +191 -0
  2. package/README.md +265 -0
  3. package/dist/actions/base-action.d.ts +63 -0
  4. package/dist/actions/base-action.d.ts.map +1 -0
  5. package/dist/actions/base-action.js +130 -0
  6. package/dist/actions/base-action.js.map +1 -0
  7. package/dist/actions/builtin/agent-invoke.d.ts +16 -0
  8. package/dist/actions/builtin/agent-invoke.d.ts.map +1 -0
  9. package/dist/actions/builtin/agent-invoke.js +108 -0
  10. package/dist/actions/builtin/agent-invoke.js.map +1 -0
  11. package/dist/actions/builtin/humancy-api-handler.d.ts +191 -0
  12. package/dist/actions/builtin/humancy-api-handler.d.ts.map +1 -0
  13. package/dist/actions/builtin/humancy-api-handler.js +521 -0
  14. package/dist/actions/builtin/humancy-api-handler.js.map +1 -0
  15. package/dist/actions/builtin/humancy-review.d.ts +83 -0
  16. package/dist/actions/builtin/humancy-review.d.ts.map +1 -0
  17. package/dist/actions/builtin/humancy-review.js +250 -0
  18. package/dist/actions/builtin/humancy-review.js.map +1 -0
  19. package/dist/actions/builtin/pr-create.d.ts +16 -0
  20. package/dist/actions/builtin/pr-create.d.ts.map +1 -0
  21. package/dist/actions/builtin/pr-create.js +110 -0
  22. package/dist/actions/builtin/pr-create.js.map +1 -0
  23. package/dist/actions/builtin/shell.d.ts +16 -0
  24. package/dist/actions/builtin/shell.d.ts.map +1 -0
  25. package/dist/actions/builtin/shell.js +80 -0
  26. package/dist/actions/builtin/shell.js.map +1 -0
  27. package/dist/actions/builtin/speckit/index.d.ts +47 -0
  28. package/dist/actions/builtin/speckit/index.d.ts.map +1 -0
  29. package/dist/actions/builtin/speckit/index.js +347 -0
  30. package/dist/actions/builtin/speckit/index.js.map +1 -0
  31. package/dist/actions/builtin/speckit/lib/feature.d.ts +17 -0
  32. package/dist/actions/builtin/speckit/lib/feature.d.ts.map +1 -0
  33. package/dist/actions/builtin/speckit/lib/feature.js +430 -0
  34. package/dist/actions/builtin/speckit/lib/feature.js.map +1 -0
  35. package/dist/actions/builtin/speckit/lib/fs.d.ts +62 -0
  36. package/dist/actions/builtin/speckit/lib/fs.d.ts.map +1 -0
  37. package/dist/actions/builtin/speckit/lib/fs.js +181 -0
  38. package/dist/actions/builtin/speckit/lib/fs.js.map +1 -0
  39. package/dist/actions/builtin/speckit/lib/paths.d.ts +7 -0
  40. package/dist/actions/builtin/speckit/lib/paths.d.ts.map +1 -0
  41. package/dist/actions/builtin/speckit/lib/paths.js +161 -0
  42. package/dist/actions/builtin/speckit/lib/paths.js.map +1 -0
  43. package/dist/actions/builtin/speckit/lib/prereqs.d.ts +8 -0
  44. package/dist/actions/builtin/speckit/lib/prereqs.d.ts.map +1 -0
  45. package/dist/actions/builtin/speckit/lib/prereqs.js +194 -0
  46. package/dist/actions/builtin/speckit/lib/prereqs.js.map +1 -0
  47. package/dist/actions/builtin/speckit/lib/stream-batcher.d.ts +14 -0
  48. package/dist/actions/builtin/speckit/lib/stream-batcher.d.ts.map +1 -0
  49. package/dist/actions/builtin/speckit/lib/stream-batcher.js +31 -0
  50. package/dist/actions/builtin/speckit/lib/stream-batcher.js.map +1 -0
  51. package/dist/actions/builtin/speckit/lib/templates.d.ts +15 -0
  52. package/dist/actions/builtin/speckit/lib/templates.d.ts.map +1 -0
  53. package/dist/actions/builtin/speckit/lib/templates.js +176 -0
  54. package/dist/actions/builtin/speckit/lib/templates.js.map +1 -0
  55. package/dist/actions/builtin/speckit/operations/check-prereqs.d.ts +11 -0
  56. package/dist/actions/builtin/speckit/operations/check-prereqs.d.ts.map +1 -0
  57. package/dist/actions/builtin/speckit/operations/check-prereqs.js +22 -0
  58. package/dist/actions/builtin/speckit/operations/check-prereqs.js.map +1 -0
  59. package/dist/actions/builtin/speckit/operations/clarify.d.ts +7 -0
  60. package/dist/actions/builtin/speckit/operations/clarify.d.ts.map +1 -0
  61. package/dist/actions/builtin/speckit/operations/clarify.js +302 -0
  62. package/dist/actions/builtin/speckit/operations/clarify.js.map +1 -0
  63. package/dist/actions/builtin/speckit/operations/copy-template.d.ts +11 -0
  64. package/dist/actions/builtin/speckit/operations/copy-template.d.ts.map +1 -0
  65. package/dist/actions/builtin/speckit/operations/copy-template.js +23 -0
  66. package/dist/actions/builtin/speckit/operations/copy-template.js.map +1 -0
  67. package/dist/actions/builtin/speckit/operations/create-feature.d.ts +11 -0
  68. package/dist/actions/builtin/speckit/operations/create-feature.d.ts.map +1 -0
  69. package/dist/actions/builtin/speckit/operations/create-feature.js +25 -0
  70. package/dist/actions/builtin/speckit/operations/create-feature.js.map +1 -0
  71. package/dist/actions/builtin/speckit/operations/get-paths.d.ts +11 -0
  72. package/dist/actions/builtin/speckit/operations/get-paths.d.ts.map +1 -0
  73. package/dist/actions/builtin/speckit/operations/get-paths.js +17 -0
  74. package/dist/actions/builtin/speckit/operations/get-paths.js.map +1 -0
  75. package/dist/actions/builtin/speckit/operations/implement.d.ts +7 -0
  76. package/dist/actions/builtin/speckit/operations/implement.d.ts.map +1 -0
  77. package/dist/actions/builtin/speckit/operations/implement.js +246 -0
  78. package/dist/actions/builtin/speckit/operations/implement.js.map +1 -0
  79. package/dist/actions/builtin/speckit/operations/plan.d.ts +7 -0
  80. package/dist/actions/builtin/speckit/operations/plan.d.ts.map +1 -0
  81. package/dist/actions/builtin/speckit/operations/plan.js +253 -0
  82. package/dist/actions/builtin/speckit/operations/plan.js.map +1 -0
  83. package/dist/actions/builtin/speckit/operations/specify.d.ts +7 -0
  84. package/dist/actions/builtin/speckit/operations/specify.d.ts.map +1 -0
  85. package/dist/actions/builtin/speckit/operations/specify.js +178 -0
  86. package/dist/actions/builtin/speckit/operations/specify.js.map +1 -0
  87. package/dist/actions/builtin/speckit/operations/tasks-to-issues.d.ts +42 -0
  88. package/dist/actions/builtin/speckit/operations/tasks-to-issues.d.ts.map +1 -0
  89. package/dist/actions/builtin/speckit/operations/tasks-to-issues.js +386 -0
  90. package/dist/actions/builtin/speckit/operations/tasks-to-issues.js.map +1 -0
  91. package/dist/actions/builtin/speckit/operations/tasks.d.ts +7 -0
  92. package/dist/actions/builtin/speckit/operations/tasks.d.ts.map +1 -0
  93. package/dist/actions/builtin/speckit/operations/tasks.js +234 -0
  94. package/dist/actions/builtin/speckit/operations/tasks.js.map +1 -0
  95. package/dist/actions/builtin/speckit/types.d.ts +268 -0
  96. package/dist/actions/builtin/speckit/types.d.ts.map +1 -0
  97. package/dist/actions/builtin/speckit/types.js +11 -0
  98. package/dist/actions/builtin/speckit/types.js.map +1 -0
  99. package/dist/actions/builtin/verification-check.d.ts +16 -0
  100. package/dist/actions/builtin/verification-check.d.ts.map +1 -0
  101. package/dist/actions/builtin/verification-check.js +99 -0
  102. package/dist/actions/builtin/verification-check.js.map +1 -0
  103. package/dist/actions/builtin/workspace-prepare.d.ts +16 -0
  104. package/dist/actions/builtin/workspace-prepare.d.ts.map +1 -0
  105. package/dist/actions/builtin/workspace-prepare.js +108 -0
  106. package/dist/actions/builtin/workspace-prepare.js.map +1 -0
  107. package/dist/actions/cli-utils.d.ts +76 -0
  108. package/dist/actions/cli-utils.d.ts.map +1 -0
  109. package/dist/actions/cli-utils.js +278 -0
  110. package/dist/actions/cli-utils.js.map +1 -0
  111. package/dist/actions/epic/check-completion.d.ts +14 -0
  112. package/dist/actions/epic/check-completion.d.ts.map +1 -0
  113. package/dist/actions/epic/check-completion.js +57 -0
  114. package/dist/actions/epic/check-completion.js.map +1 -0
  115. package/dist/actions/epic/close.d.ts +18 -0
  116. package/dist/actions/epic/close.d.ts.map +1 -0
  117. package/dist/actions/epic/close.js +76 -0
  118. package/dist/actions/epic/close.js.map +1 -0
  119. package/dist/actions/epic/create-pr.d.ts +22 -0
  120. package/dist/actions/epic/create-pr.d.ts.map +1 -0
  121. package/dist/actions/epic/create-pr.js +140 -0
  122. package/dist/actions/epic/create-pr.js.map +1 -0
  123. package/dist/actions/epic/dispatch-children.d.ts +16 -0
  124. package/dist/actions/epic/dispatch-children.d.ts.map +1 -0
  125. package/dist/actions/epic/dispatch-children.js +95 -0
  126. package/dist/actions/epic/dispatch-children.js.map +1 -0
  127. package/dist/actions/epic/find-children.d.ts +16 -0
  128. package/dist/actions/epic/find-children.d.ts.map +1 -0
  129. package/dist/actions/epic/find-children.js +92 -0
  130. package/dist/actions/epic/find-children.js.map +1 -0
  131. package/dist/actions/epic/index.d.ts +20 -0
  132. package/dist/actions/epic/index.d.ts.map +1 -0
  133. package/dist/actions/epic/index.js +35 -0
  134. package/dist/actions/epic/index.js.map +1 -0
  135. package/dist/actions/epic/post-tasks-summary.d.ts +18 -0
  136. package/dist/actions/epic/post-tasks-summary.d.ts.map +1 -0
  137. package/dist/actions/epic/post-tasks-summary.js +123 -0
  138. package/dist/actions/epic/post-tasks-summary.js.map +1 -0
  139. package/dist/actions/epic/update-status.d.ts +22 -0
  140. package/dist/actions/epic/update-status.d.ts.map +1 -0
  141. package/dist/actions/epic/update-status.js +105 -0
  142. package/dist/actions/epic/update-status.js.map +1 -0
  143. package/dist/actions/github/add-comment.d.ts +14 -0
  144. package/dist/actions/github/add-comment.d.ts.map +1 -0
  145. package/dist/actions/github/add-comment.js +44 -0
  146. package/dist/actions/github/add-comment.js.map +1 -0
  147. package/dist/actions/github/client/gh-cli.d.ts +68 -0
  148. package/dist/actions/github/client/gh-cli.d.ts.map +1 -0
  149. package/dist/actions/github/client/gh-cli.js +781 -0
  150. package/dist/actions/github/client/gh-cli.js.map +1 -0
  151. package/dist/actions/github/client/index.d.ts +12 -0
  152. package/dist/actions/github/client/index.d.ts.map +1 -0
  153. package/dist/actions/github/client/index.js +10 -0
  154. package/dist/actions/github/client/index.js.map +1 -0
  155. package/dist/actions/github/client/interface.d.ts +270 -0
  156. package/dist/actions/github/client/interface.d.ts.map +1 -0
  157. package/dist/actions/github/client/interface.js +2 -0
  158. package/dist/actions/github/client/interface.js.map +1 -0
  159. package/dist/actions/github/commit-and-push.d.ts +19 -0
  160. package/dist/actions/github/commit-and-push.d.ts.map +1 -0
  161. package/dist/actions/github/commit-and-push.js +86 -0
  162. package/dist/actions/github/commit-and-push.js.map +1 -0
  163. package/dist/actions/github/create-draft-pr.d.ts +18 -0
  164. package/dist/actions/github/create-draft-pr.d.ts.map +1 -0
  165. package/dist/actions/github/create-draft-pr.js +76 -0
  166. package/dist/actions/github/create-draft-pr.js.map +1 -0
  167. package/dist/actions/github/get-context.d.ts +23 -0
  168. package/dist/actions/github/get-context.d.ts.map +1 -0
  169. package/dist/actions/github/get-context.js +109 -0
  170. package/dist/actions/github/get-context.js.map +1 -0
  171. package/dist/actions/github/index.d.ts +32 -0
  172. package/dist/actions/github/index.d.ts.map +1 -0
  173. package/dist/actions/github/index.js +67 -0
  174. package/dist/actions/github/index.js.map +1 -0
  175. package/dist/actions/github/label-definitions.d.ts +19 -0
  176. package/dist/actions/github/label-definitions.d.ts.map +1 -0
  177. package/dist/actions/github/label-definitions.js +71 -0
  178. package/dist/actions/github/label-definitions.js.map +1 -0
  179. package/dist/actions/github/mark-pr-ready.d.ts +14 -0
  180. package/dist/actions/github/mark-pr-ready.d.ts.map +1 -0
  181. package/dist/actions/github/mark-pr-ready.js +43 -0
  182. package/dist/actions/github/mark-pr-ready.js.map +1 -0
  183. package/dist/actions/github/merge-from-base.d.ts +15 -0
  184. package/dist/actions/github/merge-from-base.d.ts.map +1 -0
  185. package/dist/actions/github/merge-from-base.js +120 -0
  186. package/dist/actions/github/merge-from-base.js.map +1 -0
  187. package/dist/actions/github/preflight.d.ts +36 -0
  188. package/dist/actions/github/preflight.d.ts.map +1 -0
  189. package/dist/actions/github/preflight.js +292 -0
  190. package/dist/actions/github/preflight.js.map +1 -0
  191. package/dist/actions/github/read-pr-feedback.d.ts +14 -0
  192. package/dist/actions/github/read-pr-feedback.d.ts.map +1 -0
  193. package/dist/actions/github/read-pr-feedback.js +53 -0
  194. package/dist/actions/github/read-pr-feedback.js.map +1 -0
  195. package/dist/actions/github/respond-pr-feedback.d.ts +14 -0
  196. package/dist/actions/github/respond-pr-feedback.d.ts.map +1 -0
  197. package/dist/actions/github/respond-pr-feedback.js +58 -0
  198. package/dist/actions/github/respond-pr-feedback.js.map +1 -0
  199. package/dist/actions/github/review-changes.d.ts +19 -0
  200. package/dist/actions/github/review-changes.d.ts.map +1 -0
  201. package/dist/actions/github/review-changes.js +95 -0
  202. package/dist/actions/github/review-changes.js.map +1 -0
  203. package/dist/actions/github/sync-labels.d.ts +14 -0
  204. package/dist/actions/github/sync-labels.d.ts.map +1 -0
  205. package/dist/actions/github/sync-labels.js +81 -0
  206. package/dist/actions/github/sync-labels.js.map +1 -0
  207. package/dist/actions/github/update-pr.d.ts +14 -0
  208. package/dist/actions/github/update-pr.d.ts.map +1 -0
  209. package/dist/actions/github/update-pr.js +63 -0
  210. package/dist/actions/github/update-pr.js.map +1 -0
  211. package/dist/actions/index.d.ts +109 -0
  212. package/dist/actions/index.d.ts.map +1 -0
  213. package/dist/actions/index.js +233 -0
  214. package/dist/actions/index.js.map +1 -0
  215. package/dist/actions/workflow/check-gate.d.ts +15 -0
  216. package/dist/actions/workflow/check-gate.d.ts.map +1 -0
  217. package/dist/actions/workflow/check-gate.js +75 -0
  218. package/dist/actions/workflow/check-gate.js.map +1 -0
  219. package/dist/actions/workflow/index.d.ts +21 -0
  220. package/dist/actions/workflow/index.d.ts.map +1 -0
  221. package/dist/actions/workflow/index.js +31 -0
  222. package/dist/actions/workflow/index.js.map +1 -0
  223. package/dist/actions/workflow/update-phase.d.ts +15 -0
  224. package/dist/actions/workflow/update-phase.d.ts.map +1 -0
  225. package/dist/actions/workflow/update-phase.js +143 -0
  226. package/dist/actions/workflow/update-phase.js.map +1 -0
  227. package/dist/actions/workflow/update-stage.d.ts +19 -0
  228. package/dist/actions/workflow/update-stage.d.ts.map +1 -0
  229. package/dist/actions/workflow/update-stage.js +137 -0
  230. package/dist/actions/workflow/update-stage.js.map +1 -0
  231. package/dist/errors/base-workflow-not-found.d.ts +10 -0
  232. package/dist/errors/base-workflow-not-found.d.ts.map +1 -0
  233. package/dist/errors/base-workflow-not-found.js +18 -0
  234. package/dist/errors/base-workflow-not-found.js.map +1 -0
  235. package/dist/errors/circular-extends.d.ts +9 -0
  236. package/dist/errors/circular-extends.d.ts.map +1 -0
  237. package/dist/errors/circular-extends.js +13 -0
  238. package/dist/errors/circular-extends.js.map +1 -0
  239. package/dist/errors/correlation-timeout.d.ts +9 -0
  240. package/dist/errors/correlation-timeout.d.ts.map +1 -0
  241. package/dist/errors/correlation-timeout.js +13 -0
  242. package/dist/errors/correlation-timeout.js.map +1 -0
  243. package/dist/errors/workflow-override.d.ts +9 -0
  244. package/dist/errors/workflow-override.d.ts.map +1 -0
  245. package/dist/errors/workflow-override.js +12 -0
  246. package/dist/errors/workflow-override.js.map +1 -0
  247. package/dist/executor/events.d.ts +55 -0
  248. package/dist/executor/events.d.ts.map +1 -0
  249. package/dist/executor/events.js +72 -0
  250. package/dist/executor/events.js.map +1 -0
  251. package/dist/executor/gate-handler.d.ts +55 -0
  252. package/dist/executor/gate-handler.d.ts.map +1 -0
  253. package/dist/executor/gate-handler.js +139 -0
  254. package/dist/executor/gate-handler.js.map +1 -0
  255. package/dist/executor/index.d.ts +140 -0
  256. package/dist/executor/index.d.ts.map +1 -0
  257. package/dist/executor/index.js +681 -0
  258. package/dist/executor/index.js.map +1 -0
  259. package/dist/index.d.ts +24 -0
  260. package/dist/index.d.ts.map +1 -0
  261. package/dist/index.js +34 -0
  262. package/dist/index.js.map +1 -0
  263. package/dist/interpolation/context.d.ts +117 -0
  264. package/dist/interpolation/context.d.ts.map +1 -0
  265. package/dist/interpolation/context.js +256 -0
  266. package/dist/interpolation/context.js.map +1 -0
  267. package/dist/interpolation/index.d.ts +76 -0
  268. package/dist/interpolation/index.d.ts.map +1 -0
  269. package/dist/interpolation/index.js +264 -0
  270. package/dist/interpolation/index.js.map +1 -0
  271. package/dist/loader/extends.d.ts +48 -0
  272. package/dist/loader/extends.d.ts.map +1 -0
  273. package/dist/loader/extends.js +140 -0
  274. package/dist/loader/extends.js.map +1 -0
  275. package/dist/loader/index.d.ts +50 -0
  276. package/dist/loader/index.d.ts.map +1 -0
  277. package/dist/loader/index.js +190 -0
  278. package/dist/loader/index.js.map +1 -0
  279. package/dist/loader/schema.d.ts +506 -0
  280. package/dist/loader/schema.d.ts.map +1 -0
  281. package/dist/loader/schema.js +63 -0
  282. package/dist/loader/schema.js.map +1 -0
  283. package/dist/loader/validator.d.ts +33 -0
  284. package/dist/loader/validator.d.ts.map +1 -0
  285. package/dist/loader/validator.js +135 -0
  286. package/dist/loader/validator.js.map +1 -0
  287. package/dist/registry/index.d.ts +42 -0
  288. package/dist/registry/index.d.ts.map +1 -0
  289. package/dist/registry/index.js +77 -0
  290. package/dist/registry/index.js.map +1 -0
  291. package/dist/retry/index.d.ts +37 -0
  292. package/dist/retry/index.d.ts.map +1 -0
  293. package/dist/retry/index.js +225 -0
  294. package/dist/retry/index.js.map +1 -0
  295. package/dist/retry/strategies.d.ts +74 -0
  296. package/dist/retry/strategies.d.ts.map +1 -0
  297. package/dist/retry/strategies.js +136 -0
  298. package/dist/retry/strategies.js.map +1 -0
  299. package/dist/store/filesystem-store.d.ts +52 -0
  300. package/dist/store/filesystem-store.d.ts.map +1 -0
  301. package/dist/store/filesystem-store.js +230 -0
  302. package/dist/store/filesystem-store.js.map +1 -0
  303. package/dist/store/index.d.ts +7 -0
  304. package/dist/store/index.d.ts.map +1 -0
  305. package/dist/store/index.js +6 -0
  306. package/dist/store/index.js.map +1 -0
  307. package/dist/types/action.d.ts +358 -0
  308. package/dist/types/action.d.ts.map +1 -0
  309. package/dist/types/action.js +96 -0
  310. package/dist/types/action.js.map +1 -0
  311. package/dist/types/events.d.ts +25 -0
  312. package/dist/types/events.d.ts.map +1 -0
  313. package/dist/types/events.js +6 -0
  314. package/dist/types/events.js.map +1 -0
  315. package/dist/types/execution.d.ts +145 -0
  316. package/dist/types/execution.d.ts.map +1 -0
  317. package/dist/types/execution.js +2 -0
  318. package/dist/types/execution.js.map +1 -0
  319. package/dist/types/gate.d.ts +98 -0
  320. package/dist/types/gate.d.ts.map +1 -0
  321. package/dist/types/gate.js +41 -0
  322. package/dist/types/gate.js.map +1 -0
  323. package/dist/types/github.d.ts +706 -0
  324. package/dist/types/github.d.ts.map +1 -0
  325. package/dist/types/github.js +6 -0
  326. package/dist/types/github.js.map +1 -0
  327. package/dist/types/index.d.ts +17 -0
  328. package/dist/types/index.d.ts.map +1 -0
  329. package/dist/types/index.js +8 -0
  330. package/dist/types/index.js.map +1 -0
  331. package/dist/types/logger.d.ts +60 -0
  332. package/dist/types/logger.d.ts.map +1 -0
  333. package/dist/types/logger.js +66 -0
  334. package/dist/types/logger.js.map +1 -0
  335. package/dist/types/retry.d.ts +36 -0
  336. package/dist/types/retry.d.ts.map +1 -0
  337. package/dist/types/retry.js +6 -0
  338. package/dist/types/retry.js.map +1 -0
  339. package/dist/types/store.d.ts +88 -0
  340. package/dist/types/store.d.ts.map +1 -0
  341. package/dist/types/store.js +6 -0
  342. package/dist/types/store.js.map +1 -0
  343. package/dist/types/workflow.d.ts +105 -0
  344. package/dist/types/workflow.d.ts.map +1 -0
  345. package/dist/types/workflow.js +6 -0
  346. package/dist/types/workflow.js.map +1 -0
  347. package/package.json +69 -0
@@ -0,0 +1,135 @@
1
+ /**
2
+ * Workflow validator using Zod schemas.
3
+ */
4
+ import { ZodError } from 'zod';
5
+ import { WorkflowDefinitionSchema } from './schema.js';
6
+ /**
7
+ * Validation error with detailed information
8
+ */
9
+ export class WorkflowValidationError extends Error {
10
+ issues;
11
+ constructor(message, issues) {
12
+ super(message);
13
+ this.name = 'WorkflowValidationError';
14
+ this.issues = issues;
15
+ }
16
+ }
17
+ /**
18
+ * Validate a workflow definition object
19
+ * @param data Raw workflow data (parsed from YAML)
20
+ * @returns Validated WorkflowDefinition
21
+ * @throws WorkflowValidationError if validation fails
22
+ */
23
+ export function validateWorkflow(data) {
24
+ try {
25
+ const result = WorkflowDefinitionSchema.parse(data);
26
+ // Transform to our internal type format
27
+ return {
28
+ name: result.name,
29
+ description: result.description,
30
+ version: result.version,
31
+ inputs: result.inputs?.map(input => ({
32
+ name: input.name,
33
+ description: input.description,
34
+ default: input.default,
35
+ required: input.required,
36
+ type: input.type,
37
+ })),
38
+ phases: result.phases.map(phase => ({
39
+ name: phase.name,
40
+ condition: phase.condition,
41
+ steps: phase.steps.map(step => ({
42
+ name: step.name,
43
+ action: step.action ?? 'shell',
44
+ uses: step.uses,
45
+ with: step.with,
46
+ command: step.command,
47
+ script: step.script,
48
+ timeout: step.timeout,
49
+ continueOnError: step.continueOnError,
50
+ condition: step.condition,
51
+ env: step.env,
52
+ retry: step.retry ? {
53
+ maxAttempts: step.retry.maxAttempts,
54
+ delay: typeof step.retry.delay === 'number' ? step.retry.delay : parseDuration(step.retry.delay),
55
+ backoff: step.retry.backoff,
56
+ maxDelay: step.retry.maxDelay
57
+ ? (typeof step.retry.maxDelay === 'number' ? step.retry.maxDelay : parseDuration(step.retry.maxDelay))
58
+ : undefined,
59
+ jitter: step.retry.jitter,
60
+ } : undefined,
61
+ })),
62
+ })),
63
+ env: result.env,
64
+ timeout: result.timeout,
65
+ retry: result.retry ? {
66
+ maxAttempts: result.retry.maxAttempts,
67
+ delay: typeof result.retry.delay === 'number' ? result.retry.delay : parseDuration(result.retry.delay),
68
+ backoff: result.retry.backoff,
69
+ maxDelay: result.retry.maxDelay
70
+ ? (typeof result.retry.maxDelay === 'number' ? result.retry.maxDelay : parseDuration(result.retry.maxDelay))
71
+ : undefined,
72
+ jitter: result.retry.jitter,
73
+ } : undefined,
74
+ };
75
+ }
76
+ catch (error) {
77
+ if (error instanceof ZodError) {
78
+ const issues = error.issues.map(issue => ({
79
+ path: issue.path.join('.'),
80
+ message: issue.message,
81
+ code: issue.code,
82
+ }));
83
+ const message = `Workflow validation failed:\n${issues.map(i => ` - ${i.path}: ${i.message}`).join('\n')}`;
84
+ throw new WorkflowValidationError(message, issues);
85
+ }
86
+ throw error;
87
+ }
88
+ }
89
+ /**
90
+ * Parse a duration string to milliseconds
91
+ * @param duration Duration string (e.g., '10s', '5m', '1h', '1000ms')
92
+ * @returns Duration in milliseconds
93
+ */
94
+ function parseDuration(duration) {
95
+ const match = duration.match(/^(\d+(?:\.\d+)?)\s*(ms|s|m|h)?$/i);
96
+ if (!match) {
97
+ throw new Error(`Invalid duration format: ${duration}`);
98
+ }
99
+ const [, value, unit] = match;
100
+ const numValue = parseFloat(value);
101
+ switch (unit?.toLowerCase()) {
102
+ case 'h':
103
+ return numValue * 60 * 60 * 1000;
104
+ case 'm':
105
+ return numValue * 60 * 1000;
106
+ case 's':
107
+ return numValue * 1000;
108
+ case 'ms':
109
+ case undefined:
110
+ return numValue;
111
+ default:
112
+ return numValue;
113
+ }
114
+ }
115
+ /**
116
+ * Check if a workflow definition is valid without throwing
117
+ * @param data Raw workflow data
118
+ * @returns Object with valid flag and optional error
119
+ */
120
+ export function isValidWorkflow(data) {
121
+ try {
122
+ validateWorkflow(data);
123
+ return { valid: true };
124
+ }
125
+ catch (error) {
126
+ if (error instanceof WorkflowValidationError) {
127
+ return { valid: false, error };
128
+ }
129
+ return {
130
+ valid: false,
131
+ error: new WorkflowValidationError(error instanceof Error ? error.message : 'Unknown validation error', []),
132
+ };
133
+ }
134
+ }
135
+ //# sourceMappingURL=validator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validator.js","sourceRoot":"","sources":["../../src/loader/validator.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;AAC/B,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAGvD;;GAEG;AACH,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IAChC,MAAM,CAInB;IAEH,YAAY,OAAe,EAAE,MAA8D;QACzF,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,yBAAy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AAK,CAAC;IAC9B,MAAM,QAAQ,GAAG,UAAU,CAAC,KAAM,CAAC,CAAC;IAEpC,QAAQ,IAAI,EAAE,WAAW,EAAE,EAAE,CAAC;QAC5B,KAAK,GAAG;YACN,OAAO,QAAQ,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;QACnC,KAAK,GAAG;YACN,OAAO,QAAQ,GAAG,EAAE,GAAG,IAAI,CAAC;QAC9B,KAAK,GAAG;YACN,OAAO,QAAQ,GAAG,IAAI,CAAC;QACzB,KAAK,IAAI,CAAC;QACV,KAAK,SAAS;YACZ,OAAO,QAAQ,CAAC;QAClB;YACE,OAAO,QAAQ,CAAC;IACpB,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,IAAa;IAC3C,IAAI,CAAC;QACH,gBAAgB,CAAC,IAAI,CAAC,CAAC;QACvB,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IACzB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,uBAAuB,EAAE,CAAC;YAC7C,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;QACjC,CAAC;QACD,OAAO;YACL,KAAK,EAAE,KAAK;YACZ,KAAK,EAAE,IAAI,uBAAuB,CAChC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,0BAA0B,EACnE,EAAE,CACH;SACF,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Register a workflow by name.
3
+ * Validates that the file exists at registration time.
4
+ * Logs a warning if overwriting an existing registration.
5
+ *
6
+ * @param name The workflow name (e.g., 'speckit-feature')
7
+ * @param filePath The absolute path to the workflow YAML file
8
+ * @throws Error if filePath does not exist on disk
9
+ */
10
+ export declare function registerWorkflow(name: string, filePath: string): void;
11
+ /**
12
+ * Register multiple workflows at once.
13
+ * Each entry is validated and registered individually.
14
+ *
15
+ * @param workflows A Map or Record of workflow name → file path
16
+ */
17
+ export declare function registerWorkflows(workflows: Map<string, string> | Record<string, string>): void;
18
+ /**
19
+ * Resolve a workflow name to a file path from the registry.
20
+ *
21
+ * @param name The workflow name to look up
22
+ * @returns The absolute file path, or undefined if not registered
23
+ */
24
+ export declare function resolveRegisteredWorkflow(name: string): string | undefined;
25
+ /**
26
+ * Check if a workflow is registered.
27
+ *
28
+ * @param name The workflow name to check
29
+ * @returns true if a workflow is registered under this name
30
+ */
31
+ export declare function hasRegisteredWorkflow(name: string): boolean;
32
+ /**
33
+ * Get all registered workflow names.
34
+ *
35
+ * @returns Array of registered workflow names
36
+ */
37
+ export declare function getRegisteredWorkflowNames(): string[];
38
+ /**
39
+ * Clear the workflow registry. Useful for testing.
40
+ */
41
+ export declare function clearWorkflowRegistry(): void;
42
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/registry/index.ts"],"names":[],"mappings":"AAaA;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAcrE;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAQ/F;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAE1E;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE3D;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,IAAI,MAAM,EAAE,CAErD;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,IAAI,CAE5C"}
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Workflow registry — global singleton for plugin-provided workflow discovery.
3
+ * Provides centralized registration and lookup of workflow file paths by name.
4
+ * Follows the same pattern as the actionRegistry in actions/index.ts.
5
+ */
6
+ import { existsSync } from 'node:fs';
7
+ import { resolve } from 'node:path';
8
+ /**
9
+ * Registry of workflow names to absolute file paths.
10
+ */
11
+ const workflowRegistry = new Map();
12
+ /**
13
+ * Register a workflow by name.
14
+ * Validates that the file exists at registration time.
15
+ * Logs a warning if overwriting an existing registration.
16
+ *
17
+ * @param name The workflow name (e.g., 'speckit-feature')
18
+ * @param filePath The absolute path to the workflow YAML file
19
+ * @throws Error if filePath does not exist on disk
20
+ */
21
+ export function registerWorkflow(name, filePath) {
22
+ const absolutePath = resolve(filePath);
23
+ if (!existsSync(absolutePath)) {
24
+ throw new Error(`Cannot register workflow "${name}": file not found at ${absolutePath}`);
25
+ }
26
+ if (workflowRegistry.has(name)) {
27
+ console.warn(`Overwriting existing workflow registration: ${name}`);
28
+ }
29
+ workflowRegistry.set(name, absolutePath);
30
+ }
31
+ /**
32
+ * Register multiple workflows at once.
33
+ * Each entry is validated and registered individually.
34
+ *
35
+ * @param workflows A Map or Record of workflow name → file path
36
+ */
37
+ export function registerWorkflows(workflows) {
38
+ const entries = workflows instanceof Map
39
+ ? workflows.entries()
40
+ : Object.entries(workflows);
41
+ for (const [name, filePath] of entries) {
42
+ registerWorkflow(name, filePath);
43
+ }
44
+ }
45
+ /**
46
+ * Resolve a workflow name to a file path from the registry.
47
+ *
48
+ * @param name The workflow name to look up
49
+ * @returns The absolute file path, or undefined if not registered
50
+ */
51
+ export function resolveRegisteredWorkflow(name) {
52
+ return workflowRegistry.get(name);
53
+ }
54
+ /**
55
+ * Check if a workflow is registered.
56
+ *
57
+ * @param name The workflow name to check
58
+ * @returns true if a workflow is registered under this name
59
+ */
60
+ export function hasRegisteredWorkflow(name) {
61
+ return workflowRegistry.has(name);
62
+ }
63
+ /**
64
+ * Get all registered workflow names.
65
+ *
66
+ * @returns Array of registered workflow names
67
+ */
68
+ export function getRegisteredWorkflowNames() {
69
+ return Array.from(workflowRegistry.keys());
70
+ }
71
+ /**
72
+ * Clear the workflow registry. Useful for testing.
73
+ */
74
+ export function clearWorkflowRegistry() {
75
+ workflowRegistry.clear();
76
+ }
77
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/registry/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC;;GAEG;AACH,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAkB,CAAC;AAEnD;;;;;;;;GAQG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY,EAAE,QAAgB;IAC7D,MAAM,YAAY,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IAEvC,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CACb,6BAA6B,IAAI,wBAAwB,YAAY,EAAE,CACxE,CAAC;IACJ,CAAC;IAED,IAAI,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;QAC/B,OAAO,CAAC,IAAI,CAAC,+CAA+C,IAAI,EAAE,CAAC,CAAC;IACtE,CAAC;IAED,gBAAgB,CAAC,GAAG,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;AAC3C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,SAAuD;IACvF,MAAM,OAAO,GAAG,SAAS,YAAY,GAAG;QACtC,CAAC,CAAC,SAAS,CAAC,OAAO,EAAE;QACrB,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAE9B,KAAK,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,OAAO,EAAE,CAAC;QACvC,gBAAgB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IACnC,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,yBAAyB,CAAC,IAAY;IACpD,OAAO,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AACpC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAY;IAChD,OAAO,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AACpC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,0BAA0B;IACxC,OAAO,KAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,EAAE,CAAC,CAAC;AAC7C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB;IACnC,gBAAgB,CAAC,KAAK,EAAE,CAAC;AAC3B,CAAC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Retry manager for workflow step execution.
3
+ * Wraps action execution with configurable retry and timeout behavior.
4
+ */
5
+ import type { RetryConfig, StepDefinition } from '../types/workflow.js';
6
+ import type { ActionHandler, ActionContext, ActionResult } from '../types/action.js';
7
+ import type { RetryState, RetryResult } from '../types/retry.js';
8
+ /**
9
+ * Parse retry configuration from step or workflow defaults
10
+ */
11
+ export declare function parseRetryConfig(step: StepDefinition): RetryConfig;
12
+ /**
13
+ * Retry manager class
14
+ * Wraps action execution with configurable retry behavior
15
+ */
16
+ export declare class RetryManager {
17
+ private config;
18
+ private onRetry?;
19
+ constructor(config?: Partial<RetryConfig>, onRetry?: (state: RetryState, error: Error) => void);
20
+ /**
21
+ * Execute an action with retry logic
22
+ */
23
+ executeWithRetry(handler: ActionHandler, step: StepDefinition, context: ActionContext): Promise<RetryResult<ActionResult>>;
24
+ /**
25
+ * Create a retry manager from step configuration
26
+ */
27
+ static fromStep(step: StepDefinition, onRetry?: (state: RetryState, error: Error) => void): RetryManager;
28
+ }
29
+ /**
30
+ * Create a timeout wrapper for an async operation.
31
+ * When the timeout fires, the optional onTimeout callback is invoked so the
32
+ * caller can abort the underlying operation (e.g. signal an AbortController).
33
+ */
34
+ export declare function withTimeout<T>(operation: Promise<T>, timeoutMs: number, signal?: AbortSignal, onTimeout?: () => void): Promise<T>;
35
+ export type { RetryState, RetryResult } from '../types/retry.js';
36
+ export { calculateBackoffDelay, constantDelay, linearDelay, exponentialDelay, addJitter, parseDuration, formatDuration, type BackoffStrategy, } from './strategies.js';
37
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/retry/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACrF,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAmBjE;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,cAAc,GAAG,WAAW,CAoBlE;AAwBD;;;GAGG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,OAAO,CAAC,CAA4C;gBAG1D,MAAM,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,EAC7B,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,KAAK,IAAI;IAMrD;;OAEG;IACG,gBAAgB,CACpB,OAAO,EAAE,aAAa,EACtB,IAAI,EAAE,cAAc,EACpB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;IAyHrC;;OAEG;IACH,MAAM,CAAC,QAAQ,CACb,IAAI,EAAE,cAAc,EACpB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,KAAK,IAAI,GAClD,YAAY;CAGhB;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAC3B,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,EACrB,SAAS,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,WAAW,EACpB,SAAS,CAAC,EAAE,MAAM,IAAI,GACrB,OAAO,CAAC,CAAC,CAAC,CAoDZ;AAGD,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGjE,OAAO,EACL,qBAAqB,EACrB,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,SAAS,EACT,aAAa,EACb,cAAc,EACd,KAAK,eAAe,GACrB,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,225 @@
1
+ import { calculateBackoffDelay, parseDuration, formatDuration, } from './strategies.js';
2
+ /**
3
+ * Default retry configuration
4
+ */
5
+ const DEFAULT_RETRY_CONFIG = {
6
+ maxAttempts: 1,
7
+ delay: 1000,
8
+ backoff: 'exponential',
9
+ maxDelay: 60000,
10
+ jitter: 0.1,
11
+ };
12
+ /**
13
+ * Parse retry configuration from step or workflow defaults
14
+ */
15
+ export function parseRetryConfig(step) {
16
+ if (!step.retry) {
17
+ return DEFAULT_RETRY_CONFIG;
18
+ }
19
+ const config = step.retry;
20
+ return {
21
+ maxAttempts: config.maxAttempts ?? DEFAULT_RETRY_CONFIG.maxAttempts,
22
+ delay: typeof config.delay === 'number'
23
+ ? config.delay
24
+ : parseDuration(String(config.delay)),
25
+ backoff: config.backoff ?? DEFAULT_RETRY_CONFIG.backoff,
26
+ maxDelay: config.maxDelay !== undefined
27
+ ? (typeof config.maxDelay === 'number'
28
+ ? config.maxDelay
29
+ : parseDuration(String(config.maxDelay)))
30
+ : DEFAULT_RETRY_CONFIG.maxDelay,
31
+ jitter: config.jitter ?? DEFAULT_RETRY_CONFIG.jitter,
32
+ };
33
+ }
34
+ /**
35
+ * Sleep for a specified duration
36
+ */
37
+ function sleep(ms, signal) {
38
+ return new Promise((resolve, reject) => {
39
+ if (signal?.aborted) {
40
+ reject(new Error('Sleep aborted'));
41
+ return;
42
+ }
43
+ const timeoutId = setTimeout(resolve, ms);
44
+ if (signal) {
45
+ const abortHandler = () => {
46
+ clearTimeout(timeoutId);
47
+ reject(new Error('Sleep aborted'));
48
+ };
49
+ signal.addEventListener('abort', abortHandler, { once: true });
50
+ }
51
+ });
52
+ }
53
+ /**
54
+ * Retry manager class
55
+ * Wraps action execution with configurable retry behavior
56
+ */
57
+ export class RetryManager {
58
+ config;
59
+ onRetry;
60
+ constructor(config, onRetry) {
61
+ this.config = { ...DEFAULT_RETRY_CONFIG, ...config };
62
+ this.onRetry = onRetry;
63
+ }
64
+ /**
65
+ * Execute an action with retry logic
66
+ */
67
+ async executeWithRetry(handler, step, context) {
68
+ const stepConfig = parseRetryConfig(step);
69
+ const config = { ...this.config, ...stepConfig };
70
+ const errors = [];
71
+ const startTime = Date.now();
72
+ let attempt = 1;
73
+ let lastResult;
74
+ while (attempt <= config.maxAttempts) {
75
+ const state = {
76
+ attempt,
77
+ previousErrors: [...errors],
78
+ canRetry: attempt < config.maxAttempts,
79
+ nextDelay: attempt < config.maxAttempts
80
+ ? calculateBackoffDelay(config.backoff, attempt, config.delay, config.maxDelay, config.jitter)
81
+ : undefined,
82
+ };
83
+ try {
84
+ // Check for cancellation before each attempt
85
+ if (context.signal.aborted) {
86
+ throw new Error('Execution cancelled');
87
+ }
88
+ // Log attempt
89
+ if (attempt > 1) {
90
+ context.logger.info(`Retry attempt ${attempt}/${config.maxAttempts} for step "${step.name}"`);
91
+ }
92
+ // Execute the action
93
+ lastResult = await handler.execute(step, context);
94
+ // Check if successful
95
+ if (lastResult.success) {
96
+ return {
97
+ result: lastResult,
98
+ attempts: attempt,
99
+ totalDuration: Date.now() - startTime,
100
+ errors,
101
+ };
102
+ }
103
+ // Action failed but didn't throw
104
+ const error = new Error(lastResult.error ?? 'Action failed');
105
+ errors.push(error);
106
+ // Check if we can retry
107
+ if (state.canRetry) {
108
+ // Call retry callback
109
+ if (this.onRetry) {
110
+ this.onRetry(state, error);
111
+ }
112
+ // Wait before retrying
113
+ context.logger.info(`Waiting ${formatDuration(state.nextDelay)} before retry...`);
114
+ await sleep(state.nextDelay, context.signal);
115
+ }
116
+ }
117
+ catch (error) {
118
+ const err = error instanceof Error ? error : new Error(String(error));
119
+ errors.push(err);
120
+ // Check for cancellation
121
+ if (err.message.includes('cancelled') || err.message.includes('aborted')) {
122
+ // Don't retry on cancellation
123
+ return {
124
+ result: lastResult ?? {
125
+ success: false,
126
+ output: null,
127
+ error: err.message,
128
+ duration: Date.now() - startTime,
129
+ },
130
+ attempts: attempt,
131
+ totalDuration: Date.now() - startTime,
132
+ errors,
133
+ };
134
+ }
135
+ // Check if we can retry
136
+ if (state.canRetry) {
137
+ // Call retry callback
138
+ if (this.onRetry) {
139
+ this.onRetry(state, err);
140
+ }
141
+ // Wait before retrying
142
+ context.logger.info(`Waiting ${formatDuration(state.nextDelay)} before retry...`);
143
+ await sleep(state.nextDelay, context.signal);
144
+ }
145
+ }
146
+ attempt++;
147
+ }
148
+ // All retries exhausted
149
+ const finalError = errors[errors.length - 1];
150
+ return {
151
+ result: lastResult ?? {
152
+ success: false,
153
+ output: null,
154
+ error: finalError?.message ?? 'Max retries exceeded',
155
+ duration: Date.now() - startTime,
156
+ },
157
+ attempts: attempt - 1,
158
+ totalDuration: Date.now() - startTime,
159
+ errors,
160
+ };
161
+ }
162
+ /**
163
+ * Create a retry manager from step configuration
164
+ */
165
+ static fromStep(step, onRetry) {
166
+ return new RetryManager(parseRetryConfig(step), onRetry);
167
+ }
168
+ }
169
+ /**
170
+ * Create a timeout wrapper for an async operation.
171
+ * When the timeout fires, the optional onTimeout callback is invoked so the
172
+ * caller can abort the underlying operation (e.g. signal an AbortController).
173
+ */
174
+ export function withTimeout(operation, timeoutMs, signal, onTimeout) {
175
+ return new Promise((resolve, reject) => {
176
+ // Check if already aborted
177
+ if (signal?.aborted) {
178
+ reject(new Error('Operation aborted'));
179
+ return;
180
+ }
181
+ let settled = false;
182
+ const timeoutId = setTimeout(() => {
183
+ if (!settled) {
184
+ settled = true;
185
+ onTimeout?.(); // let caller abort the underlying operation
186
+ reject(new Error(`Operation timed out after ${formatDuration(timeoutMs)}`));
187
+ }
188
+ }, timeoutMs);
189
+ // Handle abort signal
190
+ const abortHandler = () => {
191
+ if (!settled) {
192
+ settled = true;
193
+ clearTimeout(timeoutId);
194
+ reject(new Error('Operation aborted'));
195
+ }
196
+ };
197
+ if (signal) {
198
+ signal.addEventListener('abort', abortHandler, { once: true });
199
+ }
200
+ operation
201
+ .then((result) => {
202
+ if (!settled) {
203
+ settled = true;
204
+ clearTimeout(timeoutId);
205
+ if (signal) {
206
+ signal.removeEventListener('abort', abortHandler);
207
+ }
208
+ resolve(result);
209
+ }
210
+ })
211
+ .catch((error) => {
212
+ if (!settled) {
213
+ settled = true;
214
+ clearTimeout(timeoutId);
215
+ if (signal) {
216
+ signal.removeEventListener('abort', abortHandler);
217
+ }
218
+ reject(error);
219
+ }
220
+ });
221
+ });
222
+ }
223
+ // Re-export strategies
224
+ export { calculateBackoffDelay, constantDelay, linearDelay, exponentialDelay, addJitter, parseDuration, formatDuration, } from './strategies.js';
225
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/retry/index.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,qBAAqB,EACrB,aAAa,EACb,cAAc,GAEf,MAAM,iBAAiB,CAAC;AAEzB;;GAEG;AACH,MAAM,oBAAoB,GAAgB;IACxC,WAAW,EAAE,CAAC;IACd,KAAK,EAAE,IAAI;IACX,OAAO,EAAE,aAAa;IACtB,QAAQ,EAAE,KAAK;IACf,MAAM,EAAE,GAAG;CACZ,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAoB;IACnD,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;QAChB,OAAO,oBAAoB,CAAC;IAC9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AAC,mBAAmB,CAAC,CAAC,CAAC;YACzC,CAAC;QACH,CAAC,CAAC;QAEF,IAAI,MAAM,EAAE,CAAC;YACX,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QACjE,CAAC;QAED,SAAS;aACN,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;YACf,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,OAAO,GAAG,IAAI,CAAC;gBACf,YAAY,CAAC,SAAS,CAAC,CAAC;gBACxB,IAAI,MAAM,EAAE,CAAC;oBACX,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;gBACpD,CAAC;gBACD,OAAO,CAAC,MAAM,CAAC,CAAC;YAClB,CAAC;QACH,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YACf,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,OAAO,GAAG,IAAI,CAAC;gBACf,YAAY,CAAC,SAAS,CAAC,CAAC;gBACxB,IAAI,MAAM,EAAE,CAAC;oBACX,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;gBACpD,CAAC;gBACD,MAAM,CAAC,KAAK,CAAC,CAAC;YAChB,CAAC;QACH,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACL,CAAC;AAKD,uBAAuB;AACvB,OAAO,EACL,qBAAqB,EACrB,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,SAAS,EACT,aAAa,EACb,cAAc,GAEf,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Retry backoff strategy calculation functions.
3
+ * Provides constant, linear, and exponential backoff algorithms.
4
+ */
5
+ /**
6
+ * Backoff strategy type
7
+ */
8
+ export type BackoffStrategy = 'constant' | 'linear' | 'exponential';
9
+ /**
10
+ * Calculate constant backoff delay
11
+ * Returns the same delay for every attempt.
12
+ *
13
+ * @param _attempt Current attempt number (1-indexed)
14
+ * @param baseDelay Base delay in milliseconds
15
+ * @param maxDelay Maximum delay cap in milliseconds
16
+ * @returns Delay in milliseconds
17
+ */
18
+ export declare function constantDelay(_attempt: number, baseDelay: number, maxDelay?: number): number;
19
+ /**
20
+ * Calculate linear backoff delay
21
+ * Delay increases linearly with each attempt: delay = baseDelay * attempt
22
+ *
23
+ * @param attempt Current attempt number (1-indexed)
24
+ * @param baseDelay Base delay in milliseconds
25
+ * @param maxDelay Maximum delay cap in milliseconds
26
+ * @returns Delay in milliseconds
27
+ */
28
+ export declare function linearDelay(attempt: number, baseDelay: number, maxDelay?: number): number;
29
+ /**
30
+ * Calculate exponential backoff delay
31
+ * Delay doubles with each attempt: delay = baseDelay * 2^(attempt-1)
32
+ *
33
+ * @param attempt Current attempt number (1-indexed)
34
+ * @param baseDelay Base delay in milliseconds
35
+ * @param maxDelay Maximum delay cap in milliseconds
36
+ * @returns Delay in milliseconds
37
+ */
38
+ export declare function exponentialDelay(attempt: number, baseDelay: number, maxDelay?: number): number;
39
+ /**
40
+ * Add jitter to a delay value
41
+ * Jitter helps prevent thundering herd problems.
42
+ *
43
+ * @param delay Base delay in milliseconds
44
+ * @param jitterFactor Jitter factor (0-1), default 0.1 (10%)
45
+ * @returns Delay with jitter applied
46
+ */
47
+ export declare function addJitter(delay: number, jitterFactor?: number): number;
48
+ /**
49
+ * Calculate backoff delay based on strategy
50
+ *
51
+ * @param strategy Backoff strategy
52
+ * @param attempt Current attempt number (1-indexed)
53
+ * @param baseDelay Base delay in milliseconds
54
+ * @param maxDelay Maximum delay cap in milliseconds
55
+ * @param jitterFactor Optional jitter factor (0-1)
56
+ * @returns Delay in milliseconds
57
+ */
58
+ export declare function calculateBackoffDelay(strategy: BackoffStrategy, attempt: number, baseDelay: number, maxDelay?: number, jitterFactor?: number): number;
59
+ /**
60
+ * Parse a duration string to milliseconds
61
+ * Supports: '10s', '5m', '1h', '1000ms', '1000'
62
+ *
63
+ * @param duration Duration string or number
64
+ * @returns Duration in milliseconds
65
+ */
66
+ export declare function parseDuration(duration: string | number): number;
67
+ /**
68
+ * Format milliseconds as a human-readable duration
69
+ *
70
+ * @param ms Duration in milliseconds
71
+ * @returns Formatted duration string
72
+ */
73
+ export declare function formatDuration(ms: number): string;
74
+ //# sourceMappingURL=strategies.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strategies.d.ts","sourceRoot":"","sources":["../../src/retry/strategies.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,UAAU,GAAG,QAAQ,GAAG,aAAa,CAAC;AAEpE;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,QAAQ,CAAC,EAAE,MAAM,GAChB,MAAM,CAGR;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CACzB,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,QAAQ,CAAC,EAAE,MAAM,GAChB,MAAM,CAGR;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,QAAQ,CAAC,EAAE,MAAM,GAChB,MAAM,CAGR;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,SAAM,GAAG,MAAM,CAInE;AAED;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,eAAe,EACzB,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,QAAQ,CAAC,EAAE,MAAM,EACjB,YAAY,CAAC,EAAE,MAAM,GACpB,MAAM,CAsBR;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CA0B/D;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAWjD"}