@synergenius/flow-weaver-pack-weaver 0.8.1

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 (459) hide show
  1. package/LICENSE +204 -0
  2. package/README.md +167 -0
  3. package/dist/bot/agent-provider.d.ts +34 -0
  4. package/dist/bot/agent-provider.d.ts.map +1 -0
  5. package/dist/bot/agent-provider.js +218 -0
  6. package/dist/bot/agent-provider.js.map +1 -0
  7. package/dist/bot/ai-client.d.ts +15 -0
  8. package/dist/bot/ai-client.d.ts.map +1 -0
  9. package/dist/bot/ai-client.js +128 -0
  10. package/dist/bot/ai-client.js.map +1 -0
  11. package/dist/bot/approvals.d.ts +22 -0
  12. package/dist/bot/approvals.d.ts.map +1 -0
  13. package/dist/bot/approvals.js +187 -0
  14. package/dist/bot/approvals.js.map +1 -0
  15. package/dist/bot/audit-logger.d.ts +5 -0
  16. package/dist/bot/audit-logger.d.ts.map +1 -0
  17. package/dist/bot/audit-logger.js +42 -0
  18. package/dist/bot/audit-logger.js.map +1 -0
  19. package/dist/bot/audit-store.d.ts +13 -0
  20. package/dist/bot/audit-store.d.ts.map +1 -0
  21. package/dist/bot/audit-store.js +59 -0
  22. package/dist/bot/audit-store.js.map +1 -0
  23. package/dist/bot/bot-agent-channel.d.ts +46 -0
  24. package/dist/bot/bot-agent-channel.d.ts.map +1 -0
  25. package/dist/bot/bot-agent-channel.js +58 -0
  26. package/dist/bot/bot-agent-channel.js.map +1 -0
  27. package/dist/bot/cli-provider.d.ts +29 -0
  28. package/dist/bot/cli-provider.d.ts.map +1 -0
  29. package/dist/bot/cli-provider.js +132 -0
  30. package/dist/bot/cli-provider.js.map +1 -0
  31. package/dist/bot/cli-stream-parser.d.ts +11 -0
  32. package/dist/bot/cli-stream-parser.d.ts.map +1 -0
  33. package/dist/bot/cli-stream-parser.js +53 -0
  34. package/dist/bot/cli-stream-parser.js.map +1 -0
  35. package/dist/bot/cost-store.d.ts +18 -0
  36. package/dist/bot/cost-store.d.ts.map +1 -0
  37. package/dist/bot/cost-store.js +81 -0
  38. package/dist/bot/cost-store.js.map +1 -0
  39. package/dist/bot/cost-tracker.d.ts +18 -0
  40. package/dist/bot/cost-tracker.d.ts.map +1 -0
  41. package/dist/bot/cost-tracker.js +60 -0
  42. package/dist/bot/cost-tracker.js.map +1 -0
  43. package/dist/bot/cron-parser.d.ts +5 -0
  44. package/dist/bot/cron-parser.d.ts.map +1 -0
  45. package/dist/bot/cron-parser.js +141 -0
  46. package/dist/bot/cron-parser.js.map +1 -0
  47. package/dist/bot/cron-scheduler.d.ts +12 -0
  48. package/dist/bot/cron-scheduler.d.ts.map +1 -0
  49. package/dist/bot/cron-scheduler.js +43 -0
  50. package/dist/bot/cron-scheduler.js.map +1 -0
  51. package/dist/bot/dashboard.d.ts +34 -0
  52. package/dist/bot/dashboard.d.ts.map +1 -0
  53. package/dist/bot/dashboard.js +602 -0
  54. package/dist/bot/dashboard.js.map +1 -0
  55. package/dist/bot/design-checker.d.ts +24 -0
  56. package/dist/bot/design-checker.d.ts.map +1 -0
  57. package/dist/bot/design-checker.js +269 -0
  58. package/dist/bot/design-checker.js.map +1 -0
  59. package/dist/bot/file-lock.d.ts +7 -0
  60. package/dist/bot/file-lock.d.ts.map +1 -0
  61. package/dist/bot/file-lock.js +64 -0
  62. package/dist/bot/file-lock.js.map +1 -0
  63. package/dist/bot/file-validator.d.ts +10 -0
  64. package/dist/bot/file-validator.d.ts.map +1 -0
  65. package/dist/bot/file-validator.js +27 -0
  66. package/dist/bot/file-validator.js.map +1 -0
  67. package/dist/bot/file-watcher.d.ts +24 -0
  68. package/dist/bot/file-watcher.d.ts.map +1 -0
  69. package/dist/bot/file-watcher.js +98 -0
  70. package/dist/bot/file-watcher.js.map +1 -0
  71. package/dist/bot/fw-api.d.ts +8 -0
  72. package/dist/bot/fw-api.d.ts.map +1 -0
  73. package/dist/bot/fw-api.js +12 -0
  74. package/dist/bot/fw-api.js.map +1 -0
  75. package/dist/bot/genesis-prompt-context.d.ts +31 -0
  76. package/dist/bot/genesis-prompt-context.d.ts.map +1 -0
  77. package/dist/bot/genesis-prompt-context.js +121 -0
  78. package/dist/bot/genesis-prompt-context.js.map +1 -0
  79. package/dist/bot/genesis-store.d.ts +28 -0
  80. package/dist/bot/genesis-store.d.ts.map +1 -0
  81. package/dist/bot/genesis-store.js +154 -0
  82. package/dist/bot/genesis-store.js.map +1 -0
  83. package/dist/bot/index.d.ts +38 -0
  84. package/dist/bot/index.d.ts.map +1 -0
  85. package/dist/bot/index.js +37 -0
  86. package/dist/bot/index.js.map +1 -0
  87. package/dist/bot/notifications.d.ts +20 -0
  88. package/dist/bot/notifications.d.ts.map +1 -0
  89. package/dist/bot/notifications.js +215 -0
  90. package/dist/bot/notifications.js.map +1 -0
  91. package/dist/bot/pipeline-runner.d.ts +22 -0
  92. package/dist/bot/pipeline-runner.d.ts.map +1 -0
  93. package/dist/bot/pipeline-runner.js +263 -0
  94. package/dist/bot/pipeline-runner.js.map +1 -0
  95. package/dist/bot/provider-registry.d.ts +26 -0
  96. package/dist/bot/provider-registry.d.ts.map +1 -0
  97. package/dist/bot/provider-registry.js +175 -0
  98. package/dist/bot/provider-registry.js.map +1 -0
  99. package/dist/bot/run-store.d.ts +25 -0
  100. package/dist/bot/run-store.d.ts.map +1 -0
  101. package/dist/bot/run-store.js +156 -0
  102. package/dist/bot/run-store.js.map +1 -0
  103. package/dist/bot/runner.d.ts +13 -0
  104. package/dist/bot/runner.d.ts.map +1 -0
  105. package/dist/bot/runner.js +244 -0
  106. package/dist/bot/runner.js.map +1 -0
  107. package/dist/bot/session-state.d.ts +19 -0
  108. package/dist/bot/session-state.d.ts.map +1 -0
  109. package/dist/bot/session-state.js +65 -0
  110. package/dist/bot/session-state.js.map +1 -0
  111. package/dist/bot/steering.d.ts +13 -0
  112. package/dist/bot/steering.d.ts.map +1 -0
  113. package/dist/bot/steering.js +40 -0
  114. package/dist/bot/steering.js.map +1 -0
  115. package/dist/bot/step-executor.d.ts +10 -0
  116. package/dist/bot/step-executor.d.ts.map +1 -0
  117. package/dist/bot/step-executor.js +30 -0
  118. package/dist/bot/step-executor.js.map +1 -0
  119. package/dist/bot/system-prompt.d.ts +19 -0
  120. package/dist/bot/system-prompt.d.ts.map +1 -0
  121. package/dist/bot/system-prompt.js +222 -0
  122. package/dist/bot/system-prompt.js.map +1 -0
  123. package/dist/bot/task-queue.d.ts +26 -0
  124. package/dist/bot/task-queue.d.ts.map +1 -0
  125. package/dist/bot/task-queue.js +98 -0
  126. package/dist/bot/task-queue.js.map +1 -0
  127. package/dist/bot/types.d.ts +478 -0
  128. package/dist/bot/types.d.ts.map +1 -0
  129. package/dist/bot/types.js +2 -0
  130. package/dist/bot/types.js.map +1 -0
  131. package/dist/bot/utils.d.ts +2 -0
  132. package/dist/bot/utils.d.ts.map +1 -0
  133. package/dist/bot/utils.js +20 -0
  134. package/dist/bot/utils.js.map +1 -0
  135. package/dist/bot/watch-daemon.d.ts +19 -0
  136. package/dist/bot/watch-daemon.d.ts.map +1 -0
  137. package/dist/bot/watch-daemon.js +178 -0
  138. package/dist/bot/watch-daemon.js.map +1 -0
  139. package/dist/bot/web-approval.d.ts +19 -0
  140. package/dist/bot/web-approval.d.ts.map +1 -0
  141. package/dist/bot/web-approval.js +207 -0
  142. package/dist/bot/web-approval.js.map +1 -0
  143. package/dist/cli-bridge.d.ts +2 -0
  144. package/dist/cli-bridge.d.ts.map +1 -0
  145. package/dist/cli-bridge.js +30 -0
  146. package/dist/cli-bridge.js.map +1 -0
  147. package/dist/cli-handlers.d.ts +79 -0
  148. package/dist/cli-handlers.d.ts.map +1 -0
  149. package/dist/cli-handlers.js +1335 -0
  150. package/dist/cli-handlers.js.map +1 -0
  151. package/dist/cli.d.ts +3 -0
  152. package/dist/cli.d.ts.map +1 -0
  153. package/dist/cli.js +749 -0
  154. package/dist/cli.js.map +1 -0
  155. package/dist/docs/docs/weaver-config.md +135 -0
  156. package/dist/docs/weaver-config.md +141 -0
  157. package/dist/index.d.ts +30 -0
  158. package/dist/index.d.ts.map +1 -0
  159. package/dist/index.js +37 -0
  160. package/dist/index.js.map +1 -0
  161. package/dist/mcp-tools.d.ts +13 -0
  162. package/dist/mcp-tools.d.ts.map +1 -0
  163. package/dist/mcp-tools.js +197 -0
  164. package/dist/mcp-tools.js.map +1 -0
  165. package/dist/node-types/abort-task.d.ts +15 -0
  166. package/dist/node-types/abort-task.d.ts.map +1 -0
  167. package/dist/node-types/abort-task.js +28 -0
  168. package/dist/node-types/abort-task.js.map +1 -0
  169. package/dist/node-types/approval-gate.d.ts +18 -0
  170. package/dist/node-types/approval-gate.d.ts.map +1 -0
  171. package/dist/node-types/approval-gate.js +80 -0
  172. package/dist/node-types/approval-gate.js.map +1 -0
  173. package/dist/node-types/bot-report.d.ts +20 -0
  174. package/dist/node-types/bot-report.d.ts.map +1 -0
  175. package/dist/node-types/bot-report.js +67 -0
  176. package/dist/node-types/bot-report.js.map +1 -0
  177. package/dist/node-types/build-context.d.ts +16 -0
  178. package/dist/node-types/build-context.d.ts.map +1 -0
  179. package/dist/node-types/build-context.js +64 -0
  180. package/dist/node-types/build-context.js.map +1 -0
  181. package/dist/node-types/detect-provider.d.ts +17 -0
  182. package/dist/node-types/detect-provider.d.ts.map +1 -0
  183. package/dist/node-types/detect-provider.js +71 -0
  184. package/dist/node-types/detect-provider.js.map +1 -0
  185. package/dist/node-types/exec-validate-retry.d.ts +17 -0
  186. package/dist/node-types/exec-validate-retry.d.ts.map +1 -0
  187. package/dist/node-types/exec-validate-retry.js +147 -0
  188. package/dist/node-types/exec-validate-retry.js.map +1 -0
  189. package/dist/node-types/execute-plan.d.ts +26 -0
  190. package/dist/node-types/execute-plan.d.ts.map +1 -0
  191. package/dist/node-types/execute-plan.js +120 -0
  192. package/dist/node-types/execute-plan.js.map +1 -0
  193. package/dist/node-types/execute-target.d.ts +16 -0
  194. package/dist/node-types/execute-target.d.ts.map +1 -0
  195. package/dist/node-types/execute-target.js +238 -0
  196. package/dist/node-types/execute-target.js.map +1 -0
  197. package/dist/node-types/fix-errors.d.ts +24 -0
  198. package/dist/node-types/fix-errors.d.ts.map +1 -0
  199. package/dist/node-types/fix-errors.js +49 -0
  200. package/dist/node-types/fix-errors.js.map +1 -0
  201. package/dist/node-types/genesis-apply-retry.d.ts +27 -0
  202. package/dist/node-types/genesis-apply-retry.d.ts.map +1 -0
  203. package/dist/node-types/genesis-apply-retry.js +97 -0
  204. package/dist/node-types/genesis-apply-retry.js.map +1 -0
  205. package/dist/node-types/genesis-apply.d.ts +29 -0
  206. package/dist/node-types/genesis-apply.d.ts.map +1 -0
  207. package/dist/node-types/genesis-apply.js +76 -0
  208. package/dist/node-types/genesis-apply.js.map +1 -0
  209. package/dist/node-types/genesis-approve.d.ts +19 -0
  210. package/dist/node-types/genesis-approve.d.ts.map +1 -0
  211. package/dist/node-types/genesis-approve.js +59 -0
  212. package/dist/node-types/genesis-approve.js.map +1 -0
  213. package/dist/node-types/genesis-check-stabilize.d.ts +16 -0
  214. package/dist/node-types/genesis-check-stabilize.d.ts.map +1 -0
  215. package/dist/node-types/genesis-check-stabilize.js +32 -0
  216. package/dist/node-types/genesis-check-stabilize.js.map +1 -0
  217. package/dist/node-types/genesis-check-threshold.d.ts +15 -0
  218. package/dist/node-types/genesis-check-threshold.d.ts.map +1 -0
  219. package/dist/node-types/genesis-check-threshold.js +29 -0
  220. package/dist/node-types/genesis-check-threshold.js.map +1 -0
  221. package/dist/node-types/genesis-commit.d.ts +17 -0
  222. package/dist/node-types/genesis-commit.d.ts.map +1 -0
  223. package/dist/node-types/genesis-commit.js +59 -0
  224. package/dist/node-types/genesis-commit.js.map +1 -0
  225. package/dist/node-types/genesis-compile-validate.d.ts +26 -0
  226. package/dist/node-types/genesis-compile-validate.d.ts.map +1 -0
  227. package/dist/node-types/genesis-compile-validate.js +60 -0
  228. package/dist/node-types/genesis-compile-validate.js.map +1 -0
  229. package/dist/node-types/genesis-diff-fingerprint.d.ts +15 -0
  230. package/dist/node-types/genesis-diff-fingerprint.d.ts.map +1 -0
  231. package/dist/node-types/genesis-diff-fingerprint.js +59 -0
  232. package/dist/node-types/genesis-diff-fingerprint.js.map +1 -0
  233. package/dist/node-types/genesis-diff-workflow.d.ts +15 -0
  234. package/dist/node-types/genesis-diff-workflow.d.ts.map +1 -0
  235. package/dist/node-types/genesis-diff-workflow.js +67 -0
  236. package/dist/node-types/genesis-diff-workflow.js.map +1 -0
  237. package/dist/node-types/genesis-escrow-grace.d.ts +15 -0
  238. package/dist/node-types/genesis-escrow-grace.d.ts.map +1 -0
  239. package/dist/node-types/genesis-escrow-grace.js +52 -0
  240. package/dist/node-types/genesis-escrow-grace.js.map +1 -0
  241. package/dist/node-types/genesis-escrow-migrate.d.ts +21 -0
  242. package/dist/node-types/genesis-escrow-migrate.d.ts.map +1 -0
  243. package/dist/node-types/genesis-escrow-migrate.js +116 -0
  244. package/dist/node-types/genesis-escrow-migrate.js.map +1 -0
  245. package/dist/node-types/genesis-escrow-recover.d.ts +15 -0
  246. package/dist/node-types/genesis-escrow-recover.d.ts.map +1 -0
  247. package/dist/node-types/genesis-escrow-recover.js +90 -0
  248. package/dist/node-types/genesis-escrow-recover.js.map +1 -0
  249. package/dist/node-types/genesis-escrow-stage.d.ts +17 -0
  250. package/dist/node-types/genesis-escrow-stage.d.ts.map +1 -0
  251. package/dist/node-types/genesis-escrow-stage.js +86 -0
  252. package/dist/node-types/genesis-escrow-stage.js.map +1 -0
  253. package/dist/node-types/genesis-escrow-validate.d.ts +17 -0
  254. package/dist/node-types/genesis-escrow-validate.d.ts.map +1 -0
  255. package/dist/node-types/genesis-escrow-validate.js +110 -0
  256. package/dist/node-types/genesis-escrow-validate.js.map +1 -0
  257. package/dist/node-types/genesis-load-config.d.ts +17 -0
  258. package/dist/node-types/genesis-load-config.d.ts.map +1 -0
  259. package/dist/node-types/genesis-load-config.js +36 -0
  260. package/dist/node-types/genesis-load-config.js.map +1 -0
  261. package/dist/node-types/genesis-observe.d.ts +18 -0
  262. package/dist/node-types/genesis-observe.d.ts.map +1 -0
  263. package/dist/node-types/genesis-observe.js +103 -0
  264. package/dist/node-types/genesis-observe.js.map +1 -0
  265. package/dist/node-types/genesis-propose.d.ts +17 -0
  266. package/dist/node-types/genesis-propose.d.ts.map +1 -0
  267. package/dist/node-types/genesis-propose.js +69 -0
  268. package/dist/node-types/genesis-propose.js.map +1 -0
  269. package/dist/node-types/genesis-report.d.ts +20 -0
  270. package/dist/node-types/genesis-report.d.ts.map +1 -0
  271. package/dist/node-types/genesis-report.js +87 -0
  272. package/dist/node-types/genesis-report.js.map +1 -0
  273. package/dist/node-types/genesis-snapshot.d.ts +15 -0
  274. package/dist/node-types/genesis-snapshot.d.ts.map +1 -0
  275. package/dist/node-types/genesis-snapshot.js +26 -0
  276. package/dist/node-types/genesis-snapshot.js.map +1 -0
  277. package/dist/node-types/genesis-try-apply.d.ts +18 -0
  278. package/dist/node-types/genesis-try-apply.d.ts.map +1 -0
  279. package/dist/node-types/genesis-try-apply.js +142 -0
  280. package/dist/node-types/genesis-try-apply.js.map +1 -0
  281. package/dist/node-types/genesis-update-history.d.ts +15 -0
  282. package/dist/node-types/genesis-update-history.d.ts.map +1 -0
  283. package/dist/node-types/genesis-update-history.js +70 -0
  284. package/dist/node-types/genesis-update-history.js.map +1 -0
  285. package/dist/node-types/genesis-validate-proposal.d.ts +16 -0
  286. package/dist/node-types/genesis-validate-proposal.d.ts.map +1 -0
  287. package/dist/node-types/genesis-validate-proposal.js +109 -0
  288. package/dist/node-types/genesis-validate-proposal.js.map +1 -0
  289. package/dist/node-types/git-ops.d.ts +15 -0
  290. package/dist/node-types/git-ops.d.ts.map +1 -0
  291. package/dist/node-types/git-ops.js +69 -0
  292. package/dist/node-types/git-ops.js.map +1 -0
  293. package/dist/node-types/index.d.ts +37 -0
  294. package/dist/node-types/index.d.ts.map +1 -0
  295. package/dist/node-types/index.js +37 -0
  296. package/dist/node-types/index.js.map +1 -0
  297. package/dist/node-types/load-config.d.ts +17 -0
  298. package/dist/node-types/load-config.d.ts.map +1 -0
  299. package/dist/node-types/load-config.js +27 -0
  300. package/dist/node-types/load-config.js.map +1 -0
  301. package/dist/node-types/plan-task.d.ts +17 -0
  302. package/dist/node-types/plan-task.d.ts.map +1 -0
  303. package/dist/node-types/plan-task.js +55 -0
  304. package/dist/node-types/plan-task.js.map +1 -0
  305. package/dist/node-types/read-workflow.d.ts +15 -0
  306. package/dist/node-types/read-workflow.d.ts.map +1 -0
  307. package/dist/node-types/read-workflow.js +60 -0
  308. package/dist/node-types/read-workflow.js.map +1 -0
  309. package/dist/node-types/receive-task.d.ts +20 -0
  310. package/dist/node-types/receive-task.d.ts.map +1 -0
  311. package/dist/node-types/receive-task.js +69 -0
  312. package/dist/node-types/receive-task.js.map +1 -0
  313. package/dist/node-types/report.d.ts +14 -0
  314. package/dist/node-types/report.d.ts.map +1 -0
  315. package/dist/node-types/report.js +25 -0
  316. package/dist/node-types/report.js.map +1 -0
  317. package/dist/node-types/resolve-target.d.ts +16 -0
  318. package/dist/node-types/resolve-target.d.ts.map +1 -0
  319. package/dist/node-types/resolve-target.js +67 -0
  320. package/dist/node-types/resolve-target.js.map +1 -0
  321. package/dist/node-types/route-task.d.ts +14 -0
  322. package/dist/node-types/route-task.d.ts.map +1 -0
  323. package/dist/node-types/route-task.js +22 -0
  324. package/dist/node-types/route-task.js.map +1 -0
  325. package/dist/node-types/send-notify.d.ts +14 -0
  326. package/dist/node-types/send-notify.d.ts.map +1 -0
  327. package/dist/node-types/send-notify.js +71 -0
  328. package/dist/node-types/send-notify.js.map +1 -0
  329. package/dist/node-types/validate-result.d.ts +24 -0
  330. package/dist/node-types/validate-result.d.ts.map +1 -0
  331. package/dist/node-types/validate-result.js +38 -0
  332. package/dist/node-types/validate-result.js.map +1 -0
  333. package/dist/templates/index.d.ts +5 -0
  334. package/dist/templates/index.d.ts.map +1 -0
  335. package/dist/templates/index.js +4 -0
  336. package/dist/templates/index.js.map +1 -0
  337. package/dist/templates/weaver-bot-template.d.ts +11 -0
  338. package/dist/templates/weaver-bot-template.d.ts.map +1 -0
  339. package/dist/templates/weaver-bot-template.js +99 -0
  340. package/dist/templates/weaver-bot-template.js.map +1 -0
  341. package/dist/templates/weaver-template.d.ts +11 -0
  342. package/dist/templates/weaver-template.d.ts.map +1 -0
  343. package/dist/templates/weaver-template.js +53 -0
  344. package/dist/templates/weaver-template.js.map +1 -0
  345. package/dist/workflows/genesis-task.d.ts +62 -0
  346. package/dist/workflows/genesis-task.d.ts.map +1 -0
  347. package/dist/workflows/genesis-task.js +64 -0
  348. package/dist/workflows/genesis-task.js.map +1 -0
  349. package/dist/workflows/index.d.ts +4 -0
  350. package/dist/workflows/index.d.ts.map +1 -0
  351. package/dist/workflows/index.js +4 -0
  352. package/dist/workflows/index.js.map +1 -0
  353. package/dist/workflows/weaver-bot-batch.d.ts +49 -0
  354. package/dist/workflows/weaver-bot-batch.d.ts.map +1 -0
  355. package/dist/workflows/weaver-bot-batch.js +49 -0
  356. package/dist/workflows/weaver-bot-batch.js.map +1 -0
  357. package/dist/workflows/weaver-bot-session.d.ts +65 -0
  358. package/dist/workflows/weaver-bot-session.d.ts.map +1 -0
  359. package/dist/workflows/weaver-bot-session.js +68 -0
  360. package/dist/workflows/weaver-bot-session.js.map +1 -0
  361. package/dist/workflows/weaver-bot.d.ts +61 -0
  362. package/dist/workflows/weaver-bot.d.ts.map +1 -0
  363. package/dist/workflows/weaver-bot.js +61 -0
  364. package/dist/workflows/weaver-bot.js.map +1 -0
  365. package/dist/workflows/weaver.d.ts +24 -0
  366. package/dist/workflows/weaver.d.ts.map +1 -0
  367. package/dist/workflows/weaver.js +28 -0
  368. package/dist/workflows/weaver.js.map +1 -0
  369. package/flowweaver.manifest.json +1001 -0
  370. package/package.json +78 -0
  371. package/src/bot/agent-provider.ts +273 -0
  372. package/src/bot/ai-client.ts +153 -0
  373. package/src/bot/approvals.ts +273 -0
  374. package/src/bot/audit-logger.ts +45 -0
  375. package/src/bot/audit-store.ts +69 -0
  376. package/src/bot/bot-agent-channel.ts +99 -0
  377. package/src/bot/cli-provider.ts +169 -0
  378. package/src/bot/cli-stream-parser.ts +59 -0
  379. package/src/bot/cost-store.ts +92 -0
  380. package/src/bot/cost-tracker.ts +72 -0
  381. package/src/bot/cron-parser.ts +153 -0
  382. package/src/bot/cron-scheduler.ts +48 -0
  383. package/src/bot/dashboard.ts +658 -0
  384. package/src/bot/design-checker.ts +327 -0
  385. package/src/bot/file-lock.ts +73 -0
  386. package/src/bot/file-validator.ts +41 -0
  387. package/src/bot/file-watcher.ts +103 -0
  388. package/src/bot/fw-api.ts +18 -0
  389. package/src/bot/genesis-prompt-context.ts +135 -0
  390. package/src/bot/genesis-store.ts +180 -0
  391. package/src/bot/index.ts +127 -0
  392. package/src/bot/notifications.ts +263 -0
  393. package/src/bot/pipeline-runner.ts +324 -0
  394. package/src/bot/provider-registry.ts +236 -0
  395. package/src/bot/run-store.ts +169 -0
  396. package/src/bot/runner.ts +311 -0
  397. package/src/bot/session-state.ts +73 -0
  398. package/src/bot/steering.ts +44 -0
  399. package/src/bot/step-executor.ts +34 -0
  400. package/src/bot/system-prompt.ts +280 -0
  401. package/src/bot/task-queue.ts +111 -0
  402. package/src/bot/types.ts +571 -0
  403. package/src/bot/utils.ts +17 -0
  404. package/src/bot/watch-daemon.ts +203 -0
  405. package/src/bot/web-approval.ts +240 -0
  406. package/src/cli-bridge.ts +41 -0
  407. package/src/cli-handlers.ts +1445 -0
  408. package/src/docs/weaver-config.md +135 -0
  409. package/src/index.ts +177 -0
  410. package/src/mcp-tools.ts +274 -0
  411. package/src/node-types/abort-task.ts +31 -0
  412. package/src/node-types/approval-gate.ts +95 -0
  413. package/src/node-types/bot-report.ts +82 -0
  414. package/src/node-types/build-context.ts +65 -0
  415. package/src/node-types/detect-provider.ts +77 -0
  416. package/src/node-types/exec-validate-retry.ts +170 -0
  417. package/src/node-types/execute-plan.ts +130 -0
  418. package/src/node-types/execute-target.ts +256 -0
  419. package/src/node-types/fix-errors.ts +63 -0
  420. package/src/node-types/genesis-apply-retry.ts +133 -0
  421. package/src/node-types/genesis-apply.ts +96 -0
  422. package/src/node-types/genesis-approve.ts +73 -0
  423. package/src/node-types/genesis-check-stabilize.ts +37 -0
  424. package/src/node-types/genesis-check-threshold.ts +34 -0
  425. package/src/node-types/genesis-commit.ts +71 -0
  426. package/src/node-types/genesis-compile-validate.ts +77 -0
  427. package/src/node-types/genesis-diff-fingerprint.ts +67 -0
  428. package/src/node-types/genesis-diff-workflow.ts +71 -0
  429. package/src/node-types/genesis-escrow-grace.ts +62 -0
  430. package/src/node-types/genesis-escrow-migrate.ts +138 -0
  431. package/src/node-types/genesis-escrow-recover.ts +99 -0
  432. package/src/node-types/genesis-escrow-stage.ts +104 -0
  433. package/src/node-types/genesis-escrow-validate.ts +120 -0
  434. package/src/node-types/genesis-load-config.ts +44 -0
  435. package/src/node-types/genesis-observe.ts +119 -0
  436. package/src/node-types/genesis-propose.ts +86 -0
  437. package/src/node-types/genesis-report.ts +95 -0
  438. package/src/node-types/genesis-snapshot.ts +30 -0
  439. package/src/node-types/genesis-try-apply.ts +165 -0
  440. package/src/node-types/genesis-update-history.ts +72 -0
  441. package/src/node-types/genesis-validate-proposal.ts +124 -0
  442. package/src/node-types/git-ops.ts +72 -0
  443. package/src/node-types/index.ts +36 -0
  444. package/src/node-types/load-config.ts +27 -0
  445. package/src/node-types/plan-task.ts +66 -0
  446. package/src/node-types/read-workflow.ts +68 -0
  447. package/src/node-types/receive-task.ts +92 -0
  448. package/src/node-types/report.ts +25 -0
  449. package/src/node-types/resolve-target.ts +64 -0
  450. package/src/node-types/route-task.ts +25 -0
  451. package/src/node-types/send-notify.ts +75 -0
  452. package/src/node-types/validate-result.ts +49 -0
  453. package/src/templates/index.ts +5 -0
  454. package/src/templates/weaver-bot-template.ts +106 -0
  455. package/src/workflows/genesis-task.ts +91 -0
  456. package/src/workflows/index.ts +3 -0
  457. package/src/workflows/weaver-bot-batch.ts +65 -0
  458. package/src/workflows/weaver-bot.ts +79 -0
  459. package/templates.js +1 -0
@@ -0,0 +1,256 @@
1
+ import type { WeaverEnv, ProviderInfo, WeaverContext } from '../bot/types.js';
2
+ import { callAI, parseJsonResponse } from '../bot/ai-client.js';
3
+
4
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
+ async function buildWeaverPrompt(): Promise<string> {
6
+ const FALLBACK = 'You are Weaver, an expert AI companion for Flow Weaver workflows. Respond ONLY with valid JSON. No markdown, no code fences, no explanation outside the JSON structure.';
7
+ try {
8
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
+ const docMeta: any = await import('@synergenius/flow-weaver/doc-metadata');
10
+
11
+ const annotations: Array<{ name: string; syntax: string; description: string; category: string }> = docMeta.ALL_ANNOTATIONS ?? [];
12
+ const portMods: Array<{ syntax: string; description: string }> = docMeta.PORT_MODIFIERS ?? [];
13
+ const nodeMods: Array<{ syntax: string; description: string }> = docMeta.NODE_MODIFIERS ?? [];
14
+ const codes: Array<{ code: string; severity: string; title: string; description: string }> = docMeta.VALIDATION_CODES ?? [];
15
+ const commands: Array<{ name: string; description: string; group?: string }> = docMeta.CLI_COMMANDS ?? [];
16
+
17
+ const groups = new Map<string, typeof annotations>();
18
+ for (const a of annotations) {
19
+ const list = groups.get(a.category) ?? [];
20
+ list.push(a);
21
+ groups.set(a.category, list);
22
+ }
23
+ const annotationLines: string[] = [];
24
+ for (const [category, items] of groups) {
25
+ annotationLines.push('[' + category + ']');
26
+ for (const item of items) annotationLines.push(' ' + item.syntax + ' -- ' + item.description);
27
+ }
28
+
29
+ const modLines: string[] = [];
30
+ if (portMods.length > 0) {
31
+ modLines.push('Port modifiers (after port name):');
32
+ for (const m of portMods) modLines.push(' ' + m.syntax + ' -- ' + m.description);
33
+ }
34
+ if (nodeMods.length > 0) {
35
+ modLines.push('Node instance modifiers (in @node declaration):');
36
+ for (const m of nodeMods) modLines.push(' ' + m.syntax + ' -- ' + m.description);
37
+ }
38
+
39
+ const errors = codes.filter(c => c.severity === 'error').slice(0, 15);
40
+ const errorLines = errors.map(c => ' ' + c.code + ': ' + c.title + ' -- ' + c.description);
41
+
42
+ const topCmds = commands.filter(c => !c.group);
43
+ const cmdLines = topCmds.map(c => ' flow-weaver ' + c.name + ' -- ' + c.description);
44
+
45
+ return `You are Weaver, an expert AI companion for Flow Weaver workflows. You have deep knowledge of the entire Flow Weaver ecosystem: annotation grammar, compilation, CLI tools, node patterns, error diagnosis, and the Genesis self-evolution protocol.
46
+
47
+ ## Core Mental Model
48
+
49
+ The code IS the workflow. Flow Weaver workflows are plain TypeScript files with JSDoc annotations above functions. The compiler reads annotations and generates deterministic execution code between @flow-weaver-body-start/end markers. Compiled code is standalone with no runtime dependency on flow-weaver.
50
+
51
+ Three block types:
52
+ - @flowWeaver nodeType: A reusable function (node) with typed inputs/outputs
53
+ - @flowWeaver workflow: A DAG orchestration that wires node instances together
54
+ - @flowWeaver pattern: A reusable fragment with boundary ports (IN/OUT instead of Start/Exit)
55
+
56
+ ## Annotation Grammar
57
+
58
+ ${annotationLines.join('\n')}
59
+
60
+ ${modLines.join('\n')}
61
+
62
+ ## Node Execution Model
63
+
64
+ Expression nodes (@expression):
65
+ - No execute/onSuccess/onFailure params. Just inputs and return value.
66
+ - throw = failure path, return = success path
67
+ - Synchronous. Use execSync for shell commands.
68
+ - Preferred for deterministic operations.
69
+
70
+ Standard nodes:
71
+ - execute: boolean param gates execution
72
+ - Return { onSuccess: boolean, onFailure: boolean, ...outputs }
73
+ - Can be async for I/O operations
74
+
75
+ Async agent nodes:
76
+ - Use (globalThis as any).__fw_agent_channel__ to pause workflow
77
+ - Call channel.request({ agentId, context, prompt }) which returns a Promise
78
+ - Workflow suspends until agent responds
79
+ - NOT @expression (must be async)
80
+
81
+ Pass-through pattern:
82
+ - FW auto-connects ports by matching names on adjacent nodes
83
+ - To forward data through intermediate nodes, declare it as both @input and @output with the same name
84
+ - For non-adjacent wiring, use @connect sourceNode.port -> targetNode.port
85
+
86
+ Data flow:
87
+ - @path A -> B -> C: Linear execution path (sugar for multiple @connect)
88
+ - @autoConnect: Auto-wire all nodes in declaration order
89
+ - @connect: Explicit port-to-port wiring
90
+ - Merge strategies for fan-in: FIRST, LAST, COLLECT, MERGE, CONCAT
91
+
92
+ ## CLI Commands
93
+
94
+ ${cmdLines.join('\n')}
95
+
96
+ Key workflows:
97
+ flow-weaver compile <file> -- Generate executable code (in-place)
98
+ flow-weaver validate <file> -- Check for errors without compiling
99
+ flow-weaver modify <op> --file <f> -- Structural changes (addNode, removeNode, addConnection, removeConnection)
100
+ flow-weaver implement <file> -- Replace declare stubs with implementations
101
+ flow-weaver diff <a> <b> -- Semantic diff between two workflow versions
102
+ flow-weaver diagram <file> -f ascii-compact -- Generate ASCII diagram
103
+
104
+ ## Validation Errors
105
+
106
+ ${errorLines.join('\n')}
107
+
108
+ When you encounter validation errors, suggest the specific fix. Common resolutions:
109
+ - UNKNOWN_NODE_TYPE: Ensure the referenced function has @flowWeaver nodeType annotation
110
+ - MISSING_REQUIRED_INPUT: Add a @connect from a source port or make the input optional with [brackets]
111
+ - UNKNOWN_SOURCE_PORT / UNKNOWN_TARGET_PORT: Check port name spelling in @connect
112
+ - CYCLE_DETECTED: Break the cycle; use scoped iteration (@scope, @map) instead of circular dependencies
113
+
114
+ ## Genesis Protocol
115
+
116
+ Genesis is a 17-step self-evolving workflow engine:
117
+ 1. Load config (.genesis/config.json with intent, focus, constraints, approval thresholds)
118
+ 2. Observe project (fingerprint: files, package.json, git, CI, tests, existing FW workflows)
119
+ 3. Load task workflow (genesis-task.ts)
120
+ 4. Diff fingerprint against last cycle
121
+ 5. Check stabilize mode (3+ rollbacks/rejections = read-only, or explicit flag)
122
+ 6. Wait for agent (YOU decide what evolutions to propose)
123
+ 7. Propose evolution (map your decisions to FwModifyOperation[])
124
+ 8. Validate proposal (budget: max 3 cost units per cycle. addNode=1, removeNode=1, addConnection=1, removeConnection=1, implementNode=2)
125
+ 9. Snapshot current task workflow for rollback
126
+ 10. Apply changes via flow-weaver CLI
127
+ 11. Compile and validate (auto-rollback on failure)
128
+ 12. Diff workflow (semantic diff)
129
+ 13. Check approval threshold (CRITICAL > BREAKING > MINOR > COSMETIC)
130
+ 14. Wait for approval (if impact >= threshold)
131
+ 15. Commit or rollback based on approval
132
+ 16. Update history (.genesis/history.json)
133
+ 17. Report summary
134
+
135
+ When stabilize mode is active, only fix-up operations are allowed: removeNode, removeConnection, implementNode. No new nodes or connections.
136
+
137
+ ## Response Format
138
+
139
+ Return ONLY valid JSON. No markdown, no code fences, no explanation outside the JSON structure.`;
140
+ } catch {
141
+ return FALLBACK;
142
+ }
143
+ }
144
+
145
+ /**
146
+ * Run the target workflow via the flow-weaver executor with an AI agent channel.
147
+ *
148
+ * @flowWeaver nodeType
149
+ * @label Execute Target
150
+ * @input ctx [order:0] - Weaver context (JSON)
151
+ * @output ctx [order:0] - Weaver context with resultJson (JSON)
152
+ * @output onSuccess [order:-2] - On Success
153
+ * @output onFailure [order:-1] [hidden] - On Failure
154
+ */
155
+ export async function weaverExecuteTarget(
156
+ execute: boolean,
157
+ ctx: string,
158
+ ): Promise<{
159
+ onSuccess: boolean; onFailure: boolean;
160
+ ctx: string;
161
+ }> {
162
+ const context = JSON.parse(ctx) as WeaverContext;
163
+ const { env } = context;
164
+ const targetPath = context.targetPath!;
165
+
166
+ if (!execute) {
167
+ context.resultJson = JSON.stringify({ success: true, summary: 'Dry run', outcome: 'skipped' });
168
+ return { onSuccess: true, onFailure: false, ctx: JSON.stringify(context) };
169
+ }
170
+
171
+ const { config, providerInfo: pInfo } = env;
172
+ const systemPrompt = await buildWeaverPrompt();
173
+
174
+ const approvalSetting = config.approval ?? 'auto';
175
+ const approvalMode = typeof approvalSetting === 'string' ? approvalSetting : approvalSetting.mode;
176
+
177
+ const agentChannel = {
178
+ request: async (req: { agentId: string; context: Record<string, unknown>; prompt: string }) => {
179
+ if (req.agentId.includes('approval')) {
180
+ if (approvalMode === 'auto') {
181
+ console.log('\x1b[36m→ Auto-approving\x1b[0m');
182
+ return { approved: true, reason: 'auto-approved' };
183
+ }
184
+ if (approvalMode === 'timeout-auto') {
185
+ const timeout = typeof approvalSetting === 'object' ? (approvalSetting.timeoutSeconds ?? 300) : 300;
186
+ console.log(`\x1b[36m→ Waiting ${timeout}s before auto-approving...\x1b[0m`);
187
+ await new Promise(resolve => setTimeout(resolve, timeout * 1000));
188
+ return { approved: true, reason: 'timeout-auto-approved' };
189
+ }
190
+ return { approved: true, reason: 'default-approved' };
191
+ }
192
+
193
+ const contextStr = typeof req.context === 'string'
194
+ ? req.context
195
+ : JSON.stringify(req.context, null, 2);
196
+ const userPrompt = `Context:\n${contextStr}\n\nInstructions:\n${req.prompt}`;
197
+
198
+ const text = await callAI(pInfo, systemPrompt, userPrompt);
199
+
200
+ return parseJsonResponse(text);
201
+ },
202
+ onPause: () => new Promise<never>(() => {}),
203
+ resume: () => {},
204
+ fail: () => {},
205
+ };
206
+
207
+ try {
208
+ console.log(`\x1b[36m→ Executing: ${targetPath}\x1b[0m`);
209
+ const startTime = Date.now();
210
+
211
+ const mod = '@synergenius/flow-weaver/executor';
212
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
213
+ const { executeWorkflowFromFile } = await (import(mod) as Promise<any>);
214
+ const execResult = await executeWorkflowFromFile(targetPath, {}, {
215
+ agentChannel,
216
+ includeTrace: false,
217
+ production: true,
218
+ });
219
+
220
+ const elapsed = ((Date.now() - startTime) / 1000).toFixed(1);
221
+ const result = execResult.result as Record<string, unknown> | null;
222
+ const ok = (result?.onSuccess as boolean) ?? false;
223
+
224
+ let summary: string;
225
+ if (typeof result?.summary === 'string') {
226
+ summary = result.summary;
227
+ } else if (result) {
228
+ const parts: string[] = [];
229
+ for (const [k, v] of Object.entries(result)) {
230
+ if (k === 'onSuccess' || k === 'onFailure' || v == null) continue;
231
+ const s = typeof v === 'string' ? v : JSON.stringify(v);
232
+ parts.push(k + ': ' + (s.length > 80 ? s.slice(0, 80) + '...' : s));
233
+ }
234
+ summary = parts.length > 0 ? parts.join(', ') : 'completed';
235
+ } else {
236
+ summary = 'completed';
237
+ }
238
+
239
+ if (ok) console.log(`\x1b[32m✓ Completed in ${elapsed}s: ${summary}\x1b[0m`);
240
+ else console.log(`\x1b[33m! Failed after ${elapsed}s: ${summary}\x1b[0m`);
241
+
242
+ const resultObj = {
243
+ success: ok, summary, outcome: ok ? 'completed' : 'failed',
244
+ functionName: execResult.functionName,
245
+ executionTime: Number(elapsed),
246
+ };
247
+
248
+ context.resultJson = JSON.stringify(resultObj);
249
+ return { onSuccess: ok, onFailure: !ok, ctx: JSON.stringify(context) };
250
+ } catch (err: unknown) {
251
+ const msg = err instanceof Error ? err.message : String(err);
252
+ console.log(`\x1b[33m! Error: ${msg}\x1b[0m`);
253
+ context.resultJson = JSON.stringify({ success: false, summary: msg, outcome: 'error' });
254
+ return { onSuccess: false, onFailure: true, ctx: JSON.stringify(context) };
255
+ }
256
+ }
@@ -0,0 +1,63 @@
1
+ import type { WeaverEnv } from '../bot/types.js';
2
+ import { callAI, parseJsonResponse } from '../bot/ai-client.js';
3
+
4
+ /**
5
+ * When validation fails, sends errors + context to the AI and
6
+ * asks it to produce a repair plan.
7
+ *
8
+ * @flowWeaver nodeType
9
+ * @label Fix Errors
10
+ * @input env [order:0] - Weaver environment bundle
11
+ * @input validationResultJson [order:1] - Validation results (JSON)
12
+ * @input taskJson [order:2] - Task (JSON, pass-through)
13
+ * @output env [order:0] - Weaver environment bundle (pass-through)
14
+ * @output fixPlanJson [order:1] - Fix plan (JSON, same schema as planJson)
15
+ * @output taskJson [order:2] - Task (pass-through)
16
+ * @output onSuccess [order:-2] - On Success
17
+ * @output onFailure [order:-1] - On Failure
18
+ */
19
+ export async function weaverFixErrors(
20
+ execute: boolean,
21
+ env: WeaverEnv,
22
+ validationResultJson: string,
23
+ taskJson: string,
24
+ ): Promise<{
25
+ onSuccess: boolean; onFailure: boolean;
26
+ env: WeaverEnv;
27
+ fixPlanJson: string; taskJson: string;
28
+ }> {
29
+ if (!execute) {
30
+ return { onSuccess: true, onFailure: false, env, taskJson, fixPlanJson: '{"steps":[],"summary":"dry run"}' };
31
+ }
32
+
33
+ const { providerInfo: pInfo } = env;
34
+ const validation = JSON.parse(validationResultJson) as Array<{ file: string; valid: boolean; errors: string[] }>;
35
+ const errors = validation.filter(v => !v.valid);
36
+
37
+ if (errors.length === 0) {
38
+ return { onSuccess: true, onFailure: false, env, taskJson, fixPlanJson: '{"steps":[],"summary":"no errors to fix"}' };
39
+ }
40
+
41
+ let systemPrompt: string;
42
+ try {
43
+ const mod = await import('../bot/system-prompt.js');
44
+ systemPrompt = await mod.buildSystemPrompt();
45
+ } catch {
46
+ systemPrompt = 'You are Weaver. Return ONLY valid JSON.';
47
+ }
48
+
49
+ const errorSummary = errors.map(e => `${e.file}: ${e.errors.join(', ')}`).join('\n');
50
+ const userPrompt = `The following validation errors occurred:\n${errorSummary}\n\nProvide a fix plan as JSON with "steps" and "summary". Each step needs "id", "operation", "description", and "args".`;
51
+
52
+ try {
53
+ const text = await callAI(pInfo, systemPrompt, userPrompt, 8192);
54
+
55
+ const plan = parseJsonResponse(text);
56
+ console.log(`\x1b[36m→ Fix plan: ${(plan as { summary?: string }).summary ?? 'generated'}\x1b[0m`);
57
+ return { onSuccess: true, onFailure: false, env, taskJson, fixPlanJson: JSON.stringify(plan) };
58
+ } catch (err: unknown) {
59
+ const msg = err instanceof Error ? err.message : String(err);
60
+ console.error(`\x1b[31m→ Fix planning failed: ${msg}\x1b[0m`);
61
+ return { onSuccess: false, onFailure: true, env, taskJson, fixPlanJson: JSON.stringify({ steps: [], summary: `Fix failed: ${msg}` }) };
62
+ }
63
+ }
@@ -0,0 +1,133 @@
1
+ import * as fs from 'node:fs';
2
+ import * as path from 'node:path';
3
+ import type { GenesisConfig, GenesisContext } from '../bot/types.js';
4
+ import { callAI, parseJsonResponse } from '../bot/ai-client.js';
5
+ import { GenesisStore } from '../bot/genesis-store.js';
6
+ import { getGenesisSystemPrompt, getOperationExamples } from '../bot/genesis-prompt-context.js';
7
+
8
+ /**
9
+ * Scoped retry loop for apply + compile. Delegates the actual work to
10
+ * a child node via the attempt callback, and between failures restores
11
+ * the snapshot and asks the AI to revise the proposal.
12
+ *
13
+ * @flowWeaver nodeType
14
+ * @label Genesis Apply Retry
15
+ * @input ctx [order:0] - Genesis context (JSON)
16
+ * @output start scope:attempt [order:10] [hidden] - Trigger scope execution (boolean)
17
+ * @output attemptCtx scope:attempt [order:11] - Context for child (JSON)
18
+ * @input success scope:attempt [order:12] [hidden] - Success signal from child (boolean)
19
+ * @input failure scope:attempt [order:13] [hidden] - Failure signal from child (boolean)
20
+ * @input attemptCtx scope:attempt [order:14] - Result context from child (JSON)
21
+ * @output ctx [order:0] - Genesis context with applyResultJson (JSON)
22
+ * @output onSuccess [order:-2] - On Success
23
+ * @output onFailure [order:-1] - On Failure
24
+ */
25
+ export async function genesisApplyRetry(
26
+ execute: boolean,
27
+ ctx: string,
28
+ attempt: (
29
+ start: boolean,
30
+ attemptCtx: string,
31
+ ) => Promise<{ success: boolean; failure: boolean; attemptCtx: string }>,
32
+ ): Promise<{
33
+ onSuccess: boolean; onFailure: boolean;
34
+ ctx: string;
35
+ }> {
36
+ const context = JSON.parse(ctx) as GenesisContext;
37
+
38
+ if (!execute) {
39
+ const result = { applied: 0, failed: 0, errors: [] as string[] };
40
+ context.applyResultJson = JSON.stringify(result);
41
+ context.error = '';
42
+ return { onSuccess: true, onFailure: false, ctx: JSON.stringify(context) };
43
+ }
44
+
45
+ const { env } = context;
46
+ const maxAttempts = 3;
47
+ let lastResult = '';
48
+ let lastErrors = '';
49
+
50
+ for (let i = 1; i <= maxAttempts; i++) {
51
+ console.log(`\x1b[36m→ Apply attempt ${i}/${maxAttempts}\x1b[0m`);
52
+
53
+ const outcome = await attempt(true, JSON.stringify(context));
54
+ const childCtx = JSON.parse(outcome.attemptCtx) as GenesisContext;
55
+ lastResult = childCtx.applyResultJson ?? '';
56
+ lastErrors = childCtx.error ?? '';
57
+
58
+ if (outcome.success) {
59
+ context.applyResultJson = childCtx.applyResultJson;
60
+ context.error = '';
61
+ return { onSuccess: true, onFailure: false, ctx: JSON.stringify(context) };
62
+ }
63
+
64
+ if (i < maxAttempts) {
65
+ console.log('\x1b[33m→ Requesting revised proposal from AI...\x1b[0m');
66
+
67
+ const config = JSON.parse(context.genesisConfigJson) as GenesisConfig;
68
+ const targetPath = path.resolve(env.projectDir, config.targetWorkflow);
69
+ const store = new GenesisStore(env.projectDir);
70
+ const snapshot = store.loadSnapshot(context.snapshotPath!);
71
+ if (snapshot) {
72
+ fs.writeFileSync(targetPath, snapshot, 'utf-8');
73
+ }
74
+
75
+ try {
76
+ const revisedProposal = await reviseProposal(
77
+ env, config, context.proposalJson!, lastErrors,
78
+ targetPath, context.workflowDescription, !!context.stabilized,
79
+ );
80
+ context.proposalJson = revisedProposal;
81
+ console.log('\x1b[36m→ Revised proposal received\x1b[0m');
82
+ } catch (err: unknown) {
83
+ const msg = err instanceof Error ? err.message : String(err);
84
+ console.error(`\x1b[31m→ AI revision failed: ${msg}\x1b[0m`);
85
+ break;
86
+ }
87
+ }
88
+ }
89
+
90
+ const errorDesc = lastErrors
91
+ ? `Apply/compile failed after ${maxAttempts} attempts. Last errors: ${lastErrors}`
92
+ : `Apply failed after ${maxAttempts} attempts (all operations failed)`;
93
+
94
+ context.applyResultJson = lastResult;
95
+ context.error = errorDesc;
96
+ return { onSuccess: false, onFailure: true, ctx: JSON.stringify(context) };
97
+ }
98
+
99
+ async function reviseProposal(
100
+ env: GenesisContext['env'],
101
+ config: GenesisConfig,
102
+ currentProposal: string,
103
+ compileErrors: string,
104
+ targetPath: string,
105
+ workflowDescription?: string,
106
+ stabilized?: boolean,
107
+ ): Promise<string> {
108
+ const { providerInfo: pInfo } = env;
109
+
110
+ const systemPrompt = await getGenesisSystemPrompt(config, !!stabilized);
111
+
112
+ const userPrompt = [
113
+ 'The following proposal caused errors when applied. Revise it to fix these errors.',
114
+ '',
115
+ '## Current Workflow Structure',
116
+ workflowDescription || '(no description available)',
117
+ '',
118
+ '## Failed Proposal',
119
+ currentProposal,
120
+ '',
121
+ '## Errors',
122
+ compileErrors,
123
+ '',
124
+ getOperationExamples(targetPath),
125
+ '',
126
+ 'Return the full revised proposal as JSON. Use node IDs and port names that exist in the workflow structure above.',
127
+ ].join('\n');
128
+
129
+ const text = await callAI(pInfo, systemPrompt, userPrompt, 8192);
130
+
131
+ const parsed = parseJsonResponse(text);
132
+ return JSON.stringify(parsed);
133
+ }
@@ -0,0 +1,96 @@
1
+ import * as path from 'node:path';
2
+ import { execFileSync } from 'node:child_process';
3
+ import type { WeaverEnv, GenesisConfig, GenesisProposal, GenesisOperation } from '../bot/types.js';
4
+
5
+ /**
6
+ * Applies proposal operations to the target workflow by invoking the
7
+ * flow-weaver CLI modify command for each operation.
8
+ *
9
+ * @flowWeaver nodeType
10
+ * @label Genesis Apply
11
+ * @input env [order:0] - Weaver environment bundle
12
+ * @input genesisConfigJson [order:1] - Genesis configuration (JSON)
13
+ * @input proposalJson [order:2] - Genesis proposal (JSON)
14
+ * @input snapshotPath [order:3] - Path to the pre-apply snapshot
15
+ * @output env [order:0] - Weaver environment bundle (pass-through)
16
+ * @output genesisConfigJson [order:1] - Genesis configuration (pass-through)
17
+ * @output proposalJson [order:2] - Genesis proposal (pass-through)
18
+ * @output snapshotPath [order:3] - Path to the pre-apply snapshot (pass-through)
19
+ * @output applyResultJson [order:4] - Apply result (JSON)
20
+ * @output onSuccess [order:-2] - On Success
21
+ * @output onFailure [order:-1] - On Failure
22
+ */
23
+ export async function genesisApply(
24
+ execute: boolean,
25
+ env: WeaverEnv,
26
+ genesisConfigJson: string,
27
+ proposalJson: string,
28
+ snapshotPath: string,
29
+ ): Promise<{
30
+ onSuccess: boolean; onFailure: boolean;
31
+ env: WeaverEnv;
32
+ genesisConfigJson: string;
33
+ proposalJson: string;
34
+ snapshotPath: string;
35
+ applyResultJson: string;
36
+ }> {
37
+ if (!execute) {
38
+ const result = { applied: 0, failed: 0, errors: [] as string[] };
39
+ return { onSuccess: true, onFailure: false, env, genesisConfigJson, proposalJson, snapshotPath, applyResultJson: JSON.stringify(result) };
40
+ }
41
+
42
+ const config = JSON.parse(genesisConfigJson) as GenesisConfig;
43
+ const proposal = JSON.parse(proposalJson) as GenesisProposal;
44
+ const targetPath = path.resolve(env.projectDir, config.targetWorkflow);
45
+
46
+ let applied = 0;
47
+ let failed = 0;
48
+ const errors: string[] = [];
49
+
50
+ for (const op of proposal.operations) {
51
+ try {
52
+ const cliArgs = buildModifyArgs(op, targetPath);
53
+ execFileSync('flow-weaver', cliArgs, {
54
+ cwd: env.projectDir,
55
+ encoding: 'utf-8',
56
+ stdio: ['pipe', 'pipe', 'pipe'],
57
+ timeout: 30_000,
58
+ });
59
+ applied++;
60
+ console.log(`\x1b[32m + ${op.type}: ${op.rationale}\x1b[0m`);
61
+ } catch (err: unknown) {
62
+ failed++;
63
+ const msg = err instanceof Error ? err.message : String(err);
64
+ errors.push(`${op.type}: ${msg}`);
65
+ console.error(`\x1b[31m x ${op.type}: ${msg}\x1b[0m`);
66
+ }
67
+ }
68
+
69
+ const result = { applied, failed, errors };
70
+ const success = failed === 0 && applied > 0;
71
+
72
+ console.log(`\x1b[36m→ Apply: ${applied} succeeded, ${failed} failed\x1b[0m`);
73
+
74
+ return {
75
+ onSuccess: success, onFailure: !success,
76
+ env, genesisConfigJson, proposalJson, snapshotPath,
77
+ applyResultJson: JSON.stringify(result),
78
+ };
79
+ }
80
+
81
+ function buildModifyArgs(op: GenesisOperation, targetPath: string): string[] {
82
+ switch (op.type) {
83
+ case 'addNode':
84
+ return ['modify', 'addNode', '--file', targetPath, '--nodeId', String(op.args.nodeId), '--nodeType', String(op.args.nodeType)];
85
+ case 'removeNode':
86
+ return ['modify', 'removeNode', '--file', targetPath, '--nodeId', String(op.args.nodeId)];
87
+ case 'addConnection':
88
+ return ['modify', 'addConnection', '--file', targetPath, '--from', String(op.args.from), '--to', String(op.args.to)];
89
+ case 'removeConnection':
90
+ return ['modify', 'removeConnection', '--file', targetPath, '--from', String(op.args.from), '--to', String(op.args.to)];
91
+ case 'implementNode':
92
+ return ['implement', targetPath, '--nodeId', String(op.args.nodeId)];
93
+ default:
94
+ throw new Error(`Unknown genesis operation type: ${op.type}`);
95
+ }
96
+ }
@@ -0,0 +1,73 @@
1
+ import type { GenesisProposal, GenesisContext } from '../bot/types.js';
2
+
3
+ /**
4
+ * Handles approval for genesis proposals. Auto-approves when approval
5
+ * is not required or when config approval mode is 'auto'. Otherwise
6
+ * displays the proposal summary and diff, then rejects (non-interactive
7
+ * environments cannot prompt).
8
+ *
9
+ * @flowWeaver nodeType
10
+ * @label Genesis Approve
11
+ * @input ctx [order:0] - Genesis context (JSON)
12
+ * @output ctx [order:0] - Genesis context with approved (JSON)
13
+ * @output onSuccess [order:-2] - On Success
14
+ * @output onFailure [order:-1] [hidden] - On Failure
15
+ */
16
+ export async function genesisApprove(
17
+ execute: boolean,
18
+ ctx: string,
19
+ ): Promise<{
20
+ onSuccess: boolean; onFailure: boolean;
21
+ ctx: string;
22
+ }> {
23
+ const context = JSON.parse(ctx) as GenesisContext;
24
+
25
+ if (!execute) {
26
+ context.approved = true;
27
+ return { onSuccess: true, onFailure: false, ctx: JSON.stringify(context) };
28
+ }
29
+
30
+ // Auto-approve when approval is not required
31
+ if (!context.approvalRequired) {
32
+ console.log('\x1b[32m→ Auto-approved (below threshold)\x1b[0m');
33
+ context.approved = true;
34
+ return { onSuccess: true, onFailure: false, ctx: JSON.stringify(context) };
35
+ }
36
+
37
+ const { config } = context.env;
38
+ // Match the same default as runner.ts resolveApproval: no approval field = 'auto'
39
+ const approvalMode = !config.approval || config.approval === 'auto'
40
+ ? 'auto'
41
+ : typeof config.approval === 'string'
42
+ ? config.approval
43
+ : config.approval.mode;
44
+
45
+ // Display proposal summary
46
+ const proposal = JSON.parse(context.proposalJson!) as GenesisProposal;
47
+ const diffData = JSON.parse(context.workflowDiffJson!) as { diff: string };
48
+
49
+ console.log('\n\x1b[1m┌─ Genesis Proposal ─────────────────────┐\x1b[0m');
50
+ console.log(`\x1b[1m│\x1b[0m Impact: ${proposal.impactLevel}`);
51
+ console.log(`\x1b[1m│\x1b[0m Summary: ${proposal.summary}`);
52
+ console.log(`\x1b[1m│\x1b[0m Operations: ${proposal.operations.length} (cost: ${proposal.totalCost})`);
53
+ for (const op of proposal.operations) {
54
+ console.log(`\x1b[1m│\x1b[0m ${op.type}: ${op.rationale}`);
55
+ }
56
+ console.log('\x1b[1m├─ Diff ─────────────────────────────────┤\x1b[0m');
57
+ for (const line of diffData.diff.split('\n').slice(0, 20)) {
58
+ console.log(`\x1b[1m│\x1b[0m ${line}`);
59
+ }
60
+ console.log('\x1b[1m└────────────────────────────────────────┘\x1b[0m\n');
61
+
62
+ // Auto mode approves automatically
63
+ if (approvalMode === 'auto') {
64
+ console.log('\x1b[32m→ Auto-approved (approval mode: auto)\x1b[0m');
65
+ context.approved = true;
66
+ return { onSuccess: true, onFailure: false, ctx: JSON.stringify(context) };
67
+ }
68
+
69
+ // Non-auto modes reject in non-interactive context
70
+ console.log('\x1b[33m→ Rejected (approval required, non-auto mode)\x1b[0m');
71
+ context.approved = false;
72
+ return { onSuccess: true, onFailure: false, ctx: JSON.stringify(context) };
73
+ }
@@ -0,0 +1,37 @@
1
+ import type { GenesisConfig, GenesisContext } from '../bot/types.js';
2
+ import { GenesisStore } from '../bot/genesis-store.js';
3
+
4
+ /**
5
+ * Determines whether genesis should enter stabilize mode. This happens
6
+ * when the config flag is set or when the last 3 cycles were all
7
+ * rollbacks or rejections.
8
+ *
9
+ * @flowWeaver nodeType
10
+ * @expression
11
+ * @label Genesis Check Stabilize
12
+ * @input ctx [order:0] - Genesis context (JSON)
13
+ * @output ctx [order:0] - Genesis context with stabilized (JSON)
14
+ * @output onFailure [hidden]
15
+ */
16
+ export function genesisCheckStabilize(ctx: string): { ctx: string } {
17
+ const context = JSON.parse(ctx) as GenesisContext;
18
+ const config = JSON.parse(context.genesisConfigJson) as GenesisConfig;
19
+
20
+ if (config.stabilize) {
21
+ console.log('\x1b[33m→ Stabilize mode: enabled by config\x1b[0m');
22
+ context.stabilized = true;
23
+ return { ctx: JSON.stringify(context) };
24
+ }
25
+
26
+ const store = new GenesisStore(context.env.projectDir);
27
+ const recent = store.getRecentOutcomes(3);
28
+
29
+ if (recent.length >= 3 && recent.every(o => o === 'rolled-back' || o === 'rejected')) {
30
+ console.log('\x1b[33m→ Stabilize mode: 3+ consecutive rollbacks/rejections\x1b[0m');
31
+ context.stabilized = true;
32
+ return { ctx: JSON.stringify(context) };
33
+ }
34
+
35
+ context.stabilized = false;
36
+ return { ctx: JSON.stringify(context) };
37
+ }