@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,95 @@
1
+ import * as readline from 'node:readline';
2
+ import type { WeaverContext } from '../bot/types.js';
3
+ import { auditEmit } from '../bot/audit-logger.js';
4
+
5
+ /**
6
+ * Presents the plan to the user for approval. Branching:
7
+ * onSuccess = approved, onFailure = rejected.
8
+ * Supports autoApprove mode from config.
9
+ *
10
+ * @flowWeaver nodeType
11
+ * @label Approval Gate
12
+ * @input ctx [order:0] - Weaver context (JSON)
13
+ * @output ctx [order:0] - Weaver context with rejectionReason (JSON)
14
+ * @output onSuccess [order:-2] - On Success
15
+ * @output onFailure [order:-1] - On Failure
16
+ */
17
+ export async function weaverApprovalGate(
18
+ execute: boolean,
19
+ ctx: string,
20
+ ): Promise<{
21
+ onSuccess: boolean; onFailure: boolean;
22
+ ctx: string;
23
+ }> {
24
+ const context = JSON.parse(ctx) as WeaverContext;
25
+ const { env } = context;
26
+
27
+ // Studio sandbox: use agent channel instead of readline
28
+ const channel = (globalThis as any).__fw_agent_channel__;
29
+ if (channel) {
30
+ const plan = JSON.parse(context.planJson!) as { steps: Array<{ id: string; operation: string; description: string }>; summary: string };
31
+ const result = await channel.request({
32
+ agentId: 'weaver-approval',
33
+ context: { plan: { steps: plan.steps || [] }, summary: plan.summary || '' },
34
+ prompt: `Review and approve/reject this plan with ${(plan.steps || []).length} steps.`,
35
+ });
36
+ const approved = (result as Record<string, unknown>).approved !== false;
37
+ if (approved) {
38
+ context.rejectionReason = '';
39
+ return { onSuccess: true, onFailure: false, ctx: JSON.stringify(context) };
40
+ } else {
41
+ const reason = ((result as Record<string, unknown>).reason as string) || 'rejected by agent';
42
+ context.rejectionReason = reason;
43
+ return { onSuccess: false, onFailure: true, ctx: JSON.stringify(context) };
44
+ }
45
+ }
46
+
47
+ if (!execute) {
48
+ context.rejectionReason = '';
49
+ return { onSuccess: true, onFailure: false, ctx: JSON.stringify(context) };
50
+ }
51
+
52
+ const { config } = env;
53
+ const approvalMode = typeof config.approval === 'string' ? config.approval : config.approval?.mode ?? 'prompt';
54
+
55
+ // Check for autoApprove in task options
56
+ const task = JSON.parse(context.taskJson!) as { options?: { autoApprove?: boolean } };
57
+ if (task.options?.autoApprove || approvalMode === 'auto') {
58
+ console.log('\x1b[36m→ Auto-approved\x1b[0m');
59
+ auditEmit('approval-decision', { approved: true, mode: 'auto' });
60
+ context.rejectionReason = '';
61
+ return { onSuccess: true, onFailure: false, ctx: JSON.stringify(context) };
62
+ }
63
+
64
+ // Display the plan
65
+ const plan = JSON.parse(context.planJson!) as { steps: Array<{ id: string; operation: string; description: string }>; summary: string };
66
+ console.log('\n\x1b[1m┌─ Bot Plan ─────────────────────────────┐\x1b[0m');
67
+ console.log(`\x1b[1m│\x1b[0m Summary: ${plan.summary}`);
68
+ console.log(`\x1b[1m│\x1b[0m Steps: ${plan.steps.length}`);
69
+ for (const step of plan.steps) {
70
+ console.log(`\x1b[1m│\x1b[0m ${step.id}: [${step.operation}] ${step.description}`);
71
+ }
72
+ console.log('\x1b[1m└────────────────────────────────────────┘\x1b[0m\n');
73
+
74
+ // Prompt for approval
75
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
76
+ const answer = await new Promise<string>(resolve => {
77
+ rl.question('Approve this plan? [Y/n] ', resolve);
78
+ });
79
+ rl.close();
80
+
81
+ const approved = !answer || answer.toLowerCase().startsWith('y');
82
+
83
+ if (approved) {
84
+ console.log('\x1b[32m→ Plan approved\x1b[0m');
85
+ auditEmit('approval-decision', { approved: true, mode: 'prompt' });
86
+ context.rejectionReason = '';
87
+ return { onSuccess: true, onFailure: false, ctx: JSON.stringify(context) };
88
+ }
89
+
90
+ const reason = answer || 'rejected by user';
91
+ console.log(`\x1b[33m→ Plan rejected: ${reason}\x1b[0m`);
92
+ auditEmit('approval-decision', { approved: false, reason });
93
+ context.rejectionReason = reason;
94
+ return { onSuccess: false, onFailure: true, ctx: JSON.stringify(context) };
95
+ }
@@ -0,0 +1,82 @@
1
+ import type { WeaverContext } from '../bot/types.js';
2
+
3
+ /**
4
+ * Generates the final bot session report. Receives context from any
5
+ * of the three paths: read-only, main execution, or abort.
6
+ *
7
+ * @flowWeaver nodeType
8
+ * @expression
9
+ * @label Bot Report
10
+ * @executeWhen DISJUNCTION
11
+ * @input [mainCtx] [order:0] - Context from main path (JSON, optional)
12
+ * @input [readCtx] [order:1] - Context from read-only path (JSON, optional)
13
+ * @input [abortCtx] [order:2] - Context from abort path (JSON, optional)
14
+ * @output summary [order:0] - Summary text
15
+ * @output reportJson [order:1] [hidden] - Full report (JSON)
16
+ * @output onFailure [hidden]
17
+ */
18
+ export function weaverBotReport(
19
+ mainCtx?: string,
20
+ readCtx?: string,
21
+ abortCtx?: string,
22
+ ): { summary: string; reportJson: string } {
23
+ const ctxStr = mainCtx ?? readCtx ?? abortCtx;
24
+
25
+ if (!ctxStr) {
26
+ const report = { task: {}, path: 'unknown', result: null, filesModified: [], gitResult: null, timestamp: Date.now() };
27
+ return { summary: '', reportJson: JSON.stringify(report) };
28
+ }
29
+
30
+ const context = JSON.parse(ctxStr) as WeaverContext;
31
+ const task = context.taskJson ? JSON.parse(context.taskJson) as { instruction?: string; mode?: string } : {};
32
+ const files: string[] = context.filesModified ? JSON.parse(context.filesModified) : [];
33
+ const gitResult = context.gitResultJson ? JSON.parse(context.gitResultJson) : null;
34
+
35
+ let result: { success?: boolean; summary?: string; outcome?: string; results?: unknown[] } | null = null;
36
+ let pathName = 'unknown';
37
+
38
+ if (readCtx) {
39
+ result = context.resultJson ? JSON.parse(context.resultJson) : null;
40
+ pathName = 'read';
41
+ } else if (mainCtx) {
42
+ result = context.resultJson ? JSON.parse(context.resultJson) : null;
43
+ pathName = 'main';
44
+ } else if (abortCtx) {
45
+ result = context.resultJson ? JSON.parse(context.resultJson) : null;
46
+ pathName = 'abort';
47
+ }
48
+
49
+ const parts: string[] = [];
50
+
51
+ if (task.instruction) {
52
+ parts.push(`Task: ${task.instruction}`);
53
+ }
54
+
55
+ if (result) {
56
+ parts.push(`Outcome: ${result.outcome ?? (result.success ? 'completed' : 'failed')}`);
57
+ if (result.summary) parts.push(`Summary: ${result.summary}`);
58
+ }
59
+
60
+ if (files.length > 0) {
61
+ parts.push(`Files: ${files.length} modified`);
62
+ }
63
+
64
+ if (gitResult && !gitResult.skipped) {
65
+ parts.push('Git: committed');
66
+ }
67
+
68
+ const summary = parts.join(' | ');
69
+
70
+ const report = {
71
+ task,
72
+ path: pathName,
73
+ result,
74
+ filesModified: files,
75
+ gitResult,
76
+ timestamp: Date.now(),
77
+ };
78
+
79
+ console.log(`\n\x1b[1m${result?.success !== false ? '\x1b[32m' : '\x1b[31m'}Bot Report: ${summary}\x1b[0m\n`);
80
+
81
+ return { summary, reportJson: JSON.stringify(report) };
82
+ }
@@ -0,0 +1,65 @@
1
+ import { execFileSync } from 'node:child_process';
2
+ import * as fs from 'node:fs';
3
+ import * as path from 'node:path';
4
+ import type { WeaverContext } from '../bot/types.js';
5
+
6
+ /**
7
+ * Builds the knowledge bundle the AI needs for planning. Calls
8
+ * flow-weaver context authoring for the base knowledge, and
9
+ * appends target file sources for modify tasks.
10
+ *
11
+ * @flowWeaver nodeType
12
+ * @expression
13
+ * @label Build Context
14
+ * @input ctx [order:0] - Weaver context (JSON)
15
+ * @output ctx [order:0] - Weaver context with contextBundle (JSON)
16
+ * @output onFailure [hidden]
17
+ */
18
+ export function weaverBuildContext(ctx: string): { ctx: string } {
19
+ const context = JSON.parse(ctx) as WeaverContext;
20
+ const { projectDir } = context.env;
21
+ const task = JSON.parse(context.taskJson!) as { mode?: string; targets?: string[] };
22
+ const sections: string[] = [];
23
+
24
+ try {
25
+ const ctxOutput = execFileSync('flow-weaver', ['context', 'authoring', '--profile', 'assistant'], {
26
+ encoding: 'utf-8',
27
+ stdio: ['pipe', 'pipe', 'pipe'],
28
+ timeout: 30_000,
29
+ cwd: projectDir,
30
+ }).trim();
31
+ if (ctxOutput) sections.push(ctxOutput);
32
+ } catch {
33
+ sections.push('(flow-weaver context not available)');
34
+ }
35
+
36
+ if (task.mode === 'modify' && task.targets) {
37
+ for (const target of task.targets) {
38
+ const filePath = path.isAbsolute(target) ? target : path.resolve(projectDir, target);
39
+ try {
40
+ if (fs.existsSync(filePath)) {
41
+ const source = fs.readFileSync(filePath, 'utf-8');
42
+ sections.push(`## Current Source: ${target}\n\n\`\`\`typescript\n${source}\n\`\`\``);
43
+ }
44
+ } catch { /* skip unreadable files */ }
45
+ }
46
+ }
47
+
48
+ if (task.mode === 'create') {
49
+ try {
50
+ const templates = execFileSync('flow-weaver', ['list', 'templates'], {
51
+ encoding: 'utf-8',
52
+ stdio: ['pipe', 'pipe', 'pipe'],
53
+ timeout: 10_000,
54
+ cwd: projectDir,
55
+ }).trim();
56
+ if (templates) sections.push(`## Available Templates\n\n${templates}`);
57
+ } catch { /* templates not available */ }
58
+ }
59
+
60
+ const bundle = sections.join('\n\n---\n\n');
61
+ console.log(`\x1b[36m→ Context bundle: ${bundle.length} chars\x1b[0m`);
62
+
63
+ context.contextBundle = bundle;
64
+ return { ctx: JSON.stringify(context) };
65
+ }
@@ -0,0 +1,77 @@
1
+ import { execFileSync } from 'node:child_process';
2
+ import type { WeaverConfig, WeaverEnv, ProviderInfo } from '../bot/types.js';
3
+
4
+ const WHICH_CMD = process.platform === 'win32' ? 'where' : 'which';
5
+
6
+ function whichSafe(cmd: string, cwd: string): string {
7
+ try {
8
+ return execFileSync(WHICH_CMD, [cmd], { cwd, encoding: 'utf-8', stdio: 'pipe' }).trim();
9
+ } catch {
10
+ return '';
11
+ }
12
+ }
13
+
14
+ /**
15
+ * Auto-detect or resolve the configured AI provider.
16
+ * Assembles the WeaverEnv bundle from projectDir, config, and detected provider.
17
+ *
18
+ * @flowWeaver nodeType
19
+ * @expression
20
+ * @label Detect Provider
21
+ * @input projectDir [order:0] - Project root directory
22
+ * @input config [order:1] - Weaver configuration
23
+ * @output env [order:0] - Weaver environment bundle
24
+ * @output onFailure [hidden]
25
+ */
26
+ export function weaverDetectProvider(projectDir: string, config: WeaverConfig): {
27
+ env: WeaverEnv;
28
+ } {
29
+ const providerSetting = config.provider ?? 'auto';
30
+
31
+ let type: string;
32
+ let model: string | undefined;
33
+ let maxTokens: number | undefined;
34
+
35
+ if (typeof providerSetting === 'object') {
36
+ type = providerSetting.name;
37
+ model = providerSetting.model;
38
+ maxTokens = providerSetting.maxTokens;
39
+ } else if (providerSetting !== 'auto') {
40
+ type = providerSetting;
41
+ } else {
42
+ if ((globalThis as any).__fw_llm_provider__) {
43
+ type = 'platform';
44
+ } else if (process.env.ANTHROPIC_API_KEY) {
45
+ type = 'anthropic';
46
+ } else if (whichSafe('claude', projectDir)) {
47
+ type = 'claude-cli';
48
+ } else if (whichSafe('copilot', projectDir)) {
49
+ type = 'copilot-cli';
50
+ } else {
51
+ throw new Error(
52
+ 'No AI provider found. Options:\n' +
53
+ ' 1. Set ANTHROPIC_API_KEY environment variable\n' +
54
+ ' 2. Install Claude CLI: https://docs.anthropic.com/claude-code\n' +
55
+ ' 3. Install GitHub Copilot CLI: https://github.com/features/copilot',
56
+ );
57
+ }
58
+ }
59
+
60
+ const providerInfo: ProviderInfo = {
61
+ type: type as ProviderInfo['type'],
62
+ model: model ?? (type === 'anthropic' ? 'claude-sonnet-4-6' : undefined),
63
+ maxTokens: maxTokens ?? (type === 'anthropic' ? 4096 : undefined),
64
+ apiKey: type === 'anthropic' ? process.env.ANTHROPIC_API_KEY : undefined,
65
+ };
66
+
67
+ if (type === 'anthropic' && !providerInfo.apiKey) {
68
+ throw new Error('Provider is "anthropic" but ANTHROPIC_API_KEY is not set');
69
+ }
70
+
71
+ const label = providerInfo.model ? `${type} (${providerInfo.model})` : type;
72
+ console.log(`\x1b[36m→ Provider: ${label}\x1b[0m`);
73
+
74
+ return {
75
+ env: { projectDir, config, providerType: type, providerInfo },
76
+ };
77
+ }
@@ -0,0 +1,170 @@
1
+ import * as fs from 'node:fs';
2
+ import * as path from 'node:path';
3
+ import * as os from 'node:os';
4
+ import type { WeaverContext } from '../bot/types.js';
5
+ import { callAI, parseJsonResponse } from '../bot/ai-client.js';
6
+ import { executeStep } from '../bot/step-executor.js';
7
+ import { validateFiles } from '../bot/file-validator.js';
8
+ import { auditEmit } from '../bot/audit-logger.js';
9
+
10
+ /**
11
+ * Execute-validate-fix retry loop. Runs the plan, validates results,
12
+ * and if validation fails, asks the AI for fixes. Up to 3 attempts.
13
+ *
14
+ * @flowWeaver nodeType
15
+ * @label Execute & Validate
16
+ * @input ctx [order:0] - Weaver context (JSON)
17
+ * @output ctx [order:0] - Weaver context with results (JSON)
18
+ * @output onSuccess [order:-2] - On Success
19
+ * @output onFailure [order:-1] [hidden] - On Failure
20
+ */
21
+ export async function weaverExecValidateRetry(
22
+ execute: boolean,
23
+ ctx: string,
24
+ ): Promise<{
25
+ onSuccess: boolean; onFailure: boolean;
26
+ ctx: string;
27
+ }> {
28
+ const context = JSON.parse(ctx) as WeaverContext;
29
+ const { env } = context;
30
+
31
+ if (!execute) {
32
+ context.resultJson = JSON.stringify({ success: true, stepsCompleted: 0, stepsTotal: 0 });
33
+ context.validationResultJson = '[]';
34
+ context.filesModified = '[]';
35
+ context.allValid = true;
36
+ return { onSuccess: true, onFailure: false, ctx: JSON.stringify(context) };
37
+ }
38
+
39
+ const { providerInfo: pInfo, projectDir } = env;
40
+ const maxAttempts = 3;
41
+ let currentPlan = JSON.parse(context.planJson!);
42
+ let allFilesModified: string[] = [];
43
+ let lastExecResult: Record<string, unknown> = {};
44
+ let lastValidation: Array<{ file: string; valid: boolean; errors: string[] }> = [];
45
+ let allValid = false;
46
+
47
+ for (let attempt = 1; attempt <= maxAttempts; attempt++) {
48
+ console.log(`\x1b[36m→ Attempt ${attempt}/${maxAttempts}\x1b[0m`);
49
+ auditEmit('step-start', { attempt, stepCount: currentPlan.steps?.length });
50
+
51
+ const execResult = await executePlanSteps(currentPlan, projectDir);
52
+ lastExecResult = execResult;
53
+ allFilesModified = [...new Set([...allFilesModified, ...execResult.filesModified])];
54
+ auditEmit('step-complete', { attempt, filesModified: execResult.filesModified, errors: execResult.errors });
55
+
56
+ const validation = await validateFiles(execResult.filesModified, projectDir);
57
+ lastValidation = validation;
58
+ allValid = validation.every(v => v.valid);
59
+ const errorCount = validation.filter(v => !v.valid).length;
60
+ auditEmit('validation-run', { attempt, allValid, errorCount });
61
+
62
+ // Collect design warnings from valid files
63
+ const designWarnings = validation
64
+ .filter(v => v.valid && v.warnings.length > 0)
65
+ .map(v => `${v.file}:\n${v.warnings.map(w => ` - ${w}`).join('\n')}`)
66
+ .join('\n');
67
+
68
+ if (allValid && !designWarnings) {
69
+ console.log('\x1b[32m→ All files valid, no design issues\x1b[0m');
70
+ break;
71
+ }
72
+
73
+ if (allValid && designWarnings) {
74
+ console.log('\x1b[32m→ All files valid\x1b[0m');
75
+ console.log(`\x1b[33m→ Design warnings:\n${designWarnings}\x1b[0m`);
76
+ // Design warnings don't block, but include them for the AI on the next attempt
77
+ if (attempt < maxAttempts) {
78
+ // Only retry for design issues if there are warning/error severity checks
79
+ const hasActionable = validation.some(v =>
80
+ v.designReport?.checks.some(c => c.severity === 'warning' || c.severity === 'error'),
81
+ );
82
+ if (!hasActionable) break;
83
+ } else {
84
+ break;
85
+ }
86
+ }
87
+
88
+ if (attempt < maxAttempts) {
89
+ console.log(`\x1b[33m→ Validation errors found, requesting fix plan...\x1b[0m`);
90
+ const validationErrors = validation.filter(v => !v.valid).map(v => `${v.file}: ${v.errors.join(', ')}`).join('\n');
91
+ const errors = [validationErrors, designWarnings].filter(Boolean).join('\n\nDesign issues:\n');
92
+
93
+ try {
94
+ auditEmit('fix-attempt', { attempt });
95
+
96
+ let systemPrompt: string;
97
+ try {
98
+ const mod = await import('../bot/system-prompt.js');
99
+ systemPrompt = await mod.buildSystemPrompt();
100
+ } catch {
101
+ systemPrompt = 'You are Weaver. Return ONLY valid JSON.';
102
+ }
103
+
104
+ const fixPrompt = `The following validation errors occurred:\n${errors}\n\nProvide a fix plan as JSON with steps and summary.`;
105
+
106
+ const text = await callAI(pInfo, systemPrompt, fixPrompt, 8192);
107
+
108
+ currentPlan = parseJsonResponse(text);
109
+ console.log(`\x1b[36m→ Fix plan: ${(currentPlan as { summary?: string }).summary ?? 'generated'}\x1b[0m`);
110
+ } catch (err: unknown) {
111
+ const msg = err instanceof Error ? err.message : String(err);
112
+ console.error(`\x1b[31m→ Fix planning failed: ${msg}\x1b[0m`);
113
+ break;
114
+ }
115
+ }
116
+ }
117
+
118
+ context.resultJson = JSON.stringify(lastExecResult);
119
+ context.validationResultJson = JSON.stringify(lastValidation);
120
+ context.filesModified = JSON.stringify(allFilesModified);
121
+ context.allValid = allValid;
122
+
123
+ return { onSuccess: allValid, onFailure: !allValid, ctx: JSON.stringify(context) };
124
+ }
125
+
126
+ async function executePlanSteps(
127
+ plan: { steps: Array<{ id: string; operation: string; description: string; args: Record<string, unknown> }> },
128
+ projectDir: string,
129
+ ): Promise<{ success: boolean; filesModified: string[]; errors: string[]; stepsCompleted: number; stepsTotal: number }> {
130
+ const filesModified: string[] = [];
131
+ const errors: string[] = [];
132
+ let completed = 0;
133
+ const steps = plan.steps ?? [];
134
+
135
+ for (const step of steps) {
136
+ const steering = checkSteeringSignal();
137
+ if (steering === 'cancel') {
138
+ errors.push(`Cancelled at step ${step.id}`);
139
+ break;
140
+ }
141
+
142
+ try {
143
+ const result = await executeStep(step, projectDir);
144
+ if (result.file) filesModified.push(result.file);
145
+ if (result.files) filesModified.push(...result.files);
146
+ completed++;
147
+ console.log(`\x1b[32m + ${step.id}: ${step.description}\x1b[0m`);
148
+ } catch (err: unknown) {
149
+ const msg = err instanceof Error ? err.message : String(err);
150
+ errors.push(`${step.id}: ${msg}`);
151
+ console.error(`\x1b[31m x ${step.id}: ${msg}\x1b[0m`);
152
+ }
153
+ }
154
+
155
+ return { success: errors.length === 0, filesModified: [...new Set(filesModified)], errors, stepsCompleted: completed, stepsTotal: steps.length };
156
+ }
157
+
158
+ function checkSteeringSignal(): 'cancel' | null {
159
+ try {
160
+ const controlPath = path.join(os.homedir(), '.weaver', 'control.json');
161
+ if (!fs.existsSync(controlPath)) return null;
162
+ const raw = fs.readFileSync(controlPath, 'utf-8');
163
+ fs.unlinkSync(controlPath);
164
+ const cmd = JSON.parse(raw) as { command: string };
165
+ if (cmd.command === 'cancel') return 'cancel';
166
+ return null;
167
+ } catch {
168
+ return null;
169
+ }
170
+ }
@@ -0,0 +1,130 @@
1
+ import * as fs from 'node:fs';
2
+ import * as path from 'node:path';
3
+ import * as os from 'node:os';
4
+ import type { WeaverEnv } from '../bot/types.js';
5
+ import { executeStep } from '../bot/step-executor.js';
6
+
7
+ /**
8
+ * Executes plan steps via the flow-weaver CLI. Checks steering
9
+ * between steps.
10
+ *
11
+ * @flowWeaver nodeType
12
+ * @label Execute Plan
13
+ * @input env [order:0] - Weaver environment bundle
14
+ * @input planJson [order:1] - Plan (JSON)
15
+ * @input taskJson [order:2] - Task (JSON)
16
+ * @output env [order:0] - Weaver environment bundle (pass-through)
17
+ * @output executionResultJson [order:1] - Execution result (JSON)
18
+ * @output taskJson [order:2] - Task (pass-through)
19
+ * @output filesModified [order:3] - Files modified (JSON array)
20
+ * @output onSuccess [order:-2] - On Success
21
+ * @output onFailure [order:-1] - On Failure
22
+ */
23
+ export async function weaverExecutePlan(
24
+ execute: boolean,
25
+ env: WeaverEnv,
26
+ planJson: string,
27
+ taskJson: string,
28
+ ): Promise<{
29
+ onSuccess: boolean; onFailure: boolean;
30
+ env: WeaverEnv;
31
+ executionResultJson: string; taskJson: string; filesModified: string;
32
+ }> {
33
+ if (!execute) {
34
+ return {
35
+ onSuccess: true, onFailure: false, env, taskJson,
36
+ executionResultJson: JSON.stringify({ success: true, stepsCompleted: 0, stepsTotal: 0, filesModified: [], filesCreated: [], errors: [], output: 'dry run' }),
37
+ filesModified: '[]',
38
+ };
39
+ }
40
+
41
+ const { projectDir } = env;
42
+ const plan = JSON.parse(planJson) as { steps: Array<{ id: string; operation: string; description: string; args: Record<string, unknown> }> };
43
+ const filesModified: string[] = [];
44
+ const filesCreated: string[] = [];
45
+ const errors: string[] = [];
46
+ const output: string[] = [];
47
+ let completed = 0;
48
+
49
+ const steeringCheck = checkSteering();
50
+ if (steeringCheck === 'cancel') {
51
+ return {
52
+ onSuccess: false, onFailure: true, env, taskJson,
53
+ executionResultJson: JSON.stringify({ success: false, stepsCompleted: 0, stepsTotal: plan.steps.length, filesModified: [], filesCreated: [], errors: ['Cancelled via steering'], output: '' }),
54
+ filesModified: '[]',
55
+ };
56
+ }
57
+
58
+ for (const step of plan.steps) {
59
+ const steering = checkSteering();
60
+ if (steering === 'cancel') {
61
+ output.push(`Cancelled at step ${step.id}`);
62
+ break;
63
+ }
64
+ if (steering === 'pause') {
65
+ console.log('\x1b[33m→ Paused. Waiting for resume...\x1b[0m');
66
+ await waitForResume();
67
+ }
68
+
69
+ try {
70
+ const result = await executeStep(step, projectDir);
71
+ if (result.file) {
72
+ if (result.created) filesCreated.push(result.file);
73
+ else filesModified.push(result.file);
74
+ }
75
+ completed++;
76
+ output.push(`${step.id}: ${step.description} - done`);
77
+ console.log(`\x1b[32m + ${step.id}: ${step.description}\x1b[0m`);
78
+ } catch (err: unknown) {
79
+ const msg = err instanceof Error ? err.message : String(err);
80
+ errors.push(`${step.id}: ${msg}`);
81
+ output.push(`${step.id}: FAILED - ${msg}`);
82
+ console.error(`\x1b[31m x ${step.id}: ${msg}\x1b[0m`);
83
+ }
84
+ }
85
+
86
+ const allFiles = [...new Set([...filesModified, ...filesCreated])];
87
+ const success = errors.length === 0;
88
+
89
+ return {
90
+ onSuccess: success, onFailure: !success, env, taskJson,
91
+ executionResultJson: JSON.stringify({
92
+ success, stepsCompleted: completed, stepsTotal: plan.steps.length,
93
+ filesModified, filesCreated, errors, output: output.join('\n'),
94
+ }),
95
+ filesModified: JSON.stringify(allFiles),
96
+ };
97
+ }
98
+
99
+ function checkSteering(): 'cancel' | 'pause' | null {
100
+ try {
101
+ const controlPath = path.join(os.homedir(), '.weaver', 'control.json');
102
+ if (!fs.existsSync(controlPath)) return null;
103
+ const raw = fs.readFileSync(controlPath, 'utf-8');
104
+ fs.unlinkSync(controlPath);
105
+ const cmd = JSON.parse(raw) as { command: string };
106
+ if (cmd.command === 'cancel') return 'cancel';
107
+ if (cmd.command === 'pause') return 'pause';
108
+ return null;
109
+ } catch {
110
+ return null;
111
+ }
112
+ }
113
+
114
+ async function waitForResume(): Promise<void> {
115
+ const controlPath = path.join(os.homedir(), '.weaver', 'control.json');
116
+ while (true) {
117
+ await new Promise(r => setTimeout(r, 1000));
118
+ try {
119
+ if (fs.existsSync(controlPath)) {
120
+ const raw = fs.readFileSync(controlPath, 'utf-8');
121
+ fs.unlinkSync(controlPath);
122
+ const cmd = JSON.parse(raw) as { command: string };
123
+ if (cmd.command === 'resume' || cmd.command === 'cancel') {
124
+ console.log(`\x1b[36m→ ${cmd.command === 'resume' ? 'Resumed' : 'Cancelled'}\x1b[0m`);
125
+ return;
126
+ }
127
+ }
128
+ } catch { /* retry */ }
129
+ }
130
+ }