@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,327 @@
1
+ /**
2
+ * Weaver Design Quality Checker
3
+ *
4
+ * Heuristic, context-dependent design checks that the bot evaluates during
5
+ * its exec-validate-retry loop and genesis proposal validation. These are
6
+ * opinionated recommendations, not core validator rules.
7
+ *
8
+ * Checks structural quality, complexity limits, and completeness.
9
+ */
10
+
11
+ import type { TWorkflowAST, TNodeInstanceAST, TNodeTypeAST } from '@synergenius/flow-weaver';
12
+
13
+ export interface DesignCheck {
14
+ code: string;
15
+ severity: 'info' | 'warning' | 'error';
16
+ message: string;
17
+ nodeId?: string;
18
+ }
19
+
20
+ export interface DesignReport {
21
+ score: number; // 0-100
22
+ checks: DesignCheck[];
23
+ passed: number;
24
+ failed: number;
25
+ }
26
+
27
+ // ---------------------------------------------------------------------------
28
+ // Helpers
29
+ // ---------------------------------------------------------------------------
30
+
31
+ function resolveNodeType(ast: TWorkflowAST, instance: TNodeInstanceAST): TNodeTypeAST | undefined {
32
+ return ast.nodeTypes.find(
33
+ (nt) => nt.name === instance.nodeType || nt.functionName === instance.nodeType,
34
+ );
35
+ }
36
+
37
+ function getOutgoing(ast: TWorkflowAST, nodeId: string, portName?: string) {
38
+ return ast.connections.filter((c) => {
39
+ if (c.from.node !== nodeId) return false;
40
+ if (portName && c.from.port !== portName) return false;
41
+ return true;
42
+ });
43
+ }
44
+
45
+ function getIncoming(ast: TWorkflowAST, nodeId: string) {
46
+ return ast.connections.filter((c) => c.to.node === nodeId);
47
+ }
48
+
49
+ const GENERIC_ID_PATTERN = /^(node|n|tmp|x|test|foo|bar)\d*$/i;
50
+
51
+ // ---------------------------------------------------------------------------
52
+ // Structural Quality Checks
53
+ // ---------------------------------------------------------------------------
54
+
55
+ function checkVisualAnnotations(ast: TWorkflowAST): DesignCheck[] {
56
+ const checks: DesignCheck[] = [];
57
+ for (const inst of ast.instances) {
58
+ const hasColor = inst.config?.color;
59
+ const hasIcon = inst.config?.icon;
60
+ if (!hasColor && !hasIcon) {
61
+ checks.push({
62
+ code: 'WEAVER_MISSING_VISUALS',
63
+ severity: 'info',
64
+ message: `Node '${inst.id}' has no @color or @icon set. Visual annotations help readability.`,
65
+ nodeId: inst.id,
66
+ });
67
+ }
68
+ }
69
+ return checks;
70
+ }
71
+
72
+ function checkDescriptiveIds(ast: TWorkflowAST): DesignCheck[] {
73
+ const checks: DesignCheck[] = [];
74
+ for (const inst of ast.instances) {
75
+ if (GENERIC_ID_PATTERN.test(inst.id)) {
76
+ checks.push({
77
+ code: 'WEAVER_GENERIC_NODE_ID',
78
+ severity: 'warning',
79
+ message: `Node instance ID '${inst.id}' is generic. Use a descriptive ID that reflects the node's purpose.`,
80
+ nodeId: inst.id,
81
+ });
82
+ }
83
+ }
84
+ return checks;
85
+ }
86
+
87
+ function checkFlowDirection(ast: TWorkflowAST): DesignCheck[] {
88
+ const checks: DesignCheck[] = [];
89
+ if (!ast.ui?.instances || ast.ui.instances.length < 2) return checks;
90
+
91
+ // Check if x-positions generally increase along step connections
92
+ const posMap = new Map<string, number>();
93
+ for (const uiNode of ast.ui.instances) {
94
+ posMap.set(uiNode.name, uiNode.x);
95
+ }
96
+
97
+ let violations = 0;
98
+ let total = 0;
99
+ for (const conn of ast.connections) {
100
+ const fromX = posMap.get(conn.from.node);
101
+ const toX = posMap.get(conn.to.node);
102
+ if (fromX !== undefined && toX !== undefined) {
103
+ total++;
104
+ if (toX < fromX - 50) violations++; // Allow small tolerance
105
+ }
106
+ }
107
+
108
+ if (total > 0 && violations / total > 0.3) {
109
+ checks.push({
110
+ code: 'WEAVER_LAYOUT_DIRECTION',
111
+ severity: 'info',
112
+ message: `${violations} of ${total} connections flow right-to-left. Consider a left-to-right or top-to-bottom layout for readability.`,
113
+ });
114
+ }
115
+
116
+ return checks;
117
+ }
118
+
119
+ function checkDescription(ast: TWorkflowAST): DesignCheck[] {
120
+ if (!ast.description) {
121
+ return [{
122
+ code: 'WEAVER_NO_DESCRIPTION',
123
+ severity: 'info',
124
+ message: 'Workflow has no JSDoc description. A short summary helps collaborators understand its purpose.',
125
+ }];
126
+ }
127
+ return [];
128
+ }
129
+
130
+ // ---------------------------------------------------------------------------
131
+ // Complexity Checks
132
+ // ---------------------------------------------------------------------------
133
+
134
+ function checkNodeCount(ast: TWorkflowAST): DesignCheck[] {
135
+ const checks: DesignCheck[] = [];
136
+ const count = ast.instances.length;
137
+
138
+ if (count > 50) {
139
+ checks.push({
140
+ code: 'WEAVER_TOO_MANY_NODES',
141
+ severity: 'error',
142
+ message: `Workflow has ${count} nodes (limit: 50). Extract sub-workflows to reduce complexity.`,
143
+ });
144
+ } else if (count > 30) {
145
+ checks.push({
146
+ code: 'WEAVER_TOO_MANY_NODES',
147
+ severity: 'warning',
148
+ message: `Workflow has ${count} nodes (recommended limit: 30). Consider extracting sub-workflows.`,
149
+ });
150
+ }
151
+
152
+ return checks;
153
+ }
154
+
155
+ function checkScopeNesting(ast: TWorkflowAST): DesignCheck[] {
156
+ const checks: DesignCheck[] = [];
157
+ if (!ast.scopes) return checks;
158
+
159
+ // Build parent chain: instance -> scope -> parent instance
160
+ const instanceScopeDepth = new Map<string, number>();
161
+
162
+ function getDepth(instanceId: string, visited: Set<string>): number {
163
+ if (visited.has(instanceId)) return 0;
164
+ visited.add(instanceId);
165
+
166
+ const cached = instanceScopeDepth.get(instanceId);
167
+ if (cached !== undefined) return cached;
168
+
169
+ const inst = ast.instances.find((i) => i.id === instanceId);
170
+ if (!inst?.parent) {
171
+ instanceScopeDepth.set(instanceId, 0);
172
+ return 0;
173
+ }
174
+
175
+ const parentDepth = getDepth(inst.parent.id, visited);
176
+ const depth = parentDepth + 1;
177
+ instanceScopeDepth.set(instanceId, depth);
178
+ return depth;
179
+ }
180
+
181
+ for (const inst of ast.instances) {
182
+ const depth = getDepth(inst.id, new Set());
183
+ if (depth > 3) {
184
+ checks.push({
185
+ code: 'WEAVER_DEEP_NESTING',
186
+ severity: 'warning',
187
+ message: `Node '${inst.id}' is nested ${depth} scopes deep (limit: 3). Deep nesting makes workflows hard to follow.`,
188
+ nodeId: inst.id,
189
+ });
190
+ }
191
+ }
192
+
193
+ return checks;
194
+ }
195
+
196
+ function checkFanInComplexity(ast: TWorkflowAST): DesignCheck[] {
197
+ const checks: DesignCheck[] = [];
198
+
199
+ for (const inst of ast.instances) {
200
+ const dataIn = getIncoming(ast, inst.id).filter(
201
+ (c) => c.to.port !== 'execute' && c.to.port !== 'start',
202
+ );
203
+ if (dataIn.length > 5) {
204
+ checks.push({
205
+ code: 'WEAVER_HIGH_FANIN',
206
+ severity: 'warning',
207
+ message: `Node '${inst.id}' receives ${dataIn.length} data connections (limit: 5). This may be a bottleneck.`,
208
+ nodeId: inst.id,
209
+ });
210
+ }
211
+ }
212
+
213
+ return checks;
214
+ }
215
+
216
+ function checkFanOutComplexity(ast: TWorkflowAST): DesignCheck[] {
217
+ const checks: DesignCheck[] = [];
218
+ const stepPorts = new Set(['onSuccess', 'onFailure', 'execute', 'start', 'success', 'failure']);
219
+
220
+ for (const inst of ast.instances) {
221
+ const stepOut = getOutgoing(ast, inst.id).filter((c) => stepPorts.has(c.from.port));
222
+ const uniqueTargets = new Set(stepOut.map((c) => c.to.node));
223
+ if (uniqueTargets.size > 4) {
224
+ checks.push({
225
+ code: 'WEAVER_HIGH_FANOUT',
226
+ severity: 'warning',
227
+ message: `Node '${inst.id}' fans out to ${uniqueTargets.size} step targets (limit: 4). High branching increases complexity.`,
228
+ nodeId: inst.id,
229
+ });
230
+ }
231
+ }
232
+
233
+ return checks;
234
+ }
235
+
236
+ // ---------------------------------------------------------------------------
237
+ // Completeness Checks
238
+ // ---------------------------------------------------------------------------
239
+
240
+ function checkNotificationPresence(ast: TWorkflowAST): DesignCheck[] {
241
+ const checks: DesignCheck[] = [];
242
+
243
+ // Check if workflow has side-effect nodes (heuristic: async nodes with write/send/push-like names)
244
+ const sideEffectPattern = /write|send|push|post|create|delete|update|deploy|publish|upload|notify/i;
245
+ const hasSideEffects = ast.instances.some((inst) => {
246
+ const nt = resolveNodeType(ast, inst);
247
+ const nameHint = `${inst.id} ${nt?.name ?? ''} ${nt?.functionName ?? ''} ${nt?.label ?? ''}`;
248
+ return sideEffectPattern.test(nameHint);
249
+ });
250
+
251
+ if (!hasSideEffects) return checks;
252
+
253
+ // Check if there's a notification-like node
254
+ const notifyPattern = /notify|notification|alert|report|summary|slack|email|webhook|message/i;
255
+ const hasNotification = ast.instances.some((inst) => {
256
+ const nt = resolveNodeType(ast, inst);
257
+ const nameHint = `${inst.id} ${nt?.name ?? ''} ${nt?.functionName ?? ''} ${nt?.label ?? ''}`;
258
+ return notifyPattern.test(nameHint);
259
+ });
260
+
261
+ if (!hasNotification) {
262
+ checks.push({
263
+ code: 'WEAVER_NO_NOTIFICATION',
264
+ severity: 'info',
265
+ message: 'Workflow has side-effect nodes but no notification or reporting node. Consider adding one for observability.',
266
+ });
267
+ }
268
+
269
+ return checks;
270
+ }
271
+
272
+ // ---------------------------------------------------------------------------
273
+ // Score calculation
274
+ // ---------------------------------------------------------------------------
275
+
276
+ const SEVERITY_WEIGHTS: Record<string, number> = {
277
+ error: 10,
278
+ warning: 3,
279
+ info: 1,
280
+ };
281
+
282
+ function calculateScore(checks: DesignCheck[]): number {
283
+ if (checks.length === 0) return 100;
284
+
285
+ let penalty = 0;
286
+ for (const check of checks) {
287
+ penalty += SEVERITY_WEIGHTS[check.severity] ?? 1;
288
+ }
289
+
290
+ // Cap at 0
291
+ return Math.max(0, 100 - penalty);
292
+ }
293
+
294
+ // ---------------------------------------------------------------------------
295
+ // Public API
296
+ // ---------------------------------------------------------------------------
297
+
298
+ export function checkDesignQuality(ast: TWorkflowAST): DesignReport {
299
+ const allCheckers = [
300
+ checkVisualAnnotations,
301
+ checkDescriptiveIds,
302
+ checkFlowDirection,
303
+ checkDescription,
304
+ checkNodeCount,
305
+ checkScopeNesting,
306
+ checkFanInComplexity,
307
+ checkFanOutComplexity,
308
+ checkNotificationPresence,
309
+ ];
310
+
311
+ const checks: DesignCheck[] = [];
312
+ for (const checker of allCheckers) {
313
+ checks.push(...checker(ast));
314
+ }
315
+
316
+ const failed = checks.length;
317
+ // Total possible checks is roughly: instances * 2 (visuals, id) + 4 (globals)
318
+ const totalPossible = ast.instances.length * 2 + 4;
319
+ const passed = Math.max(0, totalPossible - failed);
320
+
321
+ return {
322
+ score: calculateScore(checks),
323
+ checks,
324
+ passed,
325
+ failed,
326
+ };
327
+ }
@@ -0,0 +1,73 @@
1
+ import * as fs from 'node:fs';
2
+ import * as path from 'node:path';
3
+
4
+ export interface FileLockOptions {
5
+ retries?: number;
6
+ retryWait?: number;
7
+ staleMs?: number;
8
+ }
9
+
10
+ interface LockInfo {
11
+ pid: number;
12
+ timestamp: number;
13
+ }
14
+
15
+ function isPidAlive(pid: number): boolean {
16
+ try {
17
+ process.kill(pid, 0);
18
+ return true;
19
+ } catch {
20
+ return false;
21
+ }
22
+ }
23
+
24
+ export async function withFileLock<T>(
25
+ lockPath: string,
26
+ fn: () => T | Promise<T>,
27
+ options?: FileLockOptions,
28
+ ): Promise<T> {
29
+ const retries = options?.retries ?? 50;
30
+ const retryWait = options?.retryWait ?? 50;
31
+ const staleMs = options?.staleMs ?? 10_000;
32
+ const lockDir = lockPath + '.lock';
33
+ const infoFile = path.join(lockDir, 'info.json');
34
+
35
+ for (let attempt = 0; attempt <= retries; attempt++) {
36
+ try {
37
+ fs.mkdirSync(lockDir, { recursive: false });
38
+
39
+ fs.writeFileSync(infoFile, JSON.stringify({ pid: process.pid, timestamp: Date.now() }), 'utf-8');
40
+
41
+ try {
42
+ return await fn();
43
+ } finally {
44
+ try { fs.rmSync(lockDir, { recursive: true }); } catch { /* ignore */ }
45
+ }
46
+ } catch (err: unknown) {
47
+ if ((err as NodeJS.ErrnoException).code !== 'EEXIST') throw err;
48
+
49
+ // Lock exists, check if stale
50
+ try {
51
+ const raw = fs.readFileSync(infoFile, 'utf-8');
52
+ const info = JSON.parse(raw) as LockInfo;
53
+ const isStale = Date.now() - info.timestamp > staleMs;
54
+ const isDead = !isPidAlive(info.pid);
55
+
56
+ if (isStale || isDead) {
57
+ try { fs.rmSync(lockDir, { recursive: true }); } catch { /* ignore */ }
58
+ continue;
59
+ }
60
+ } catch {
61
+ // Can't read lock info, try to clean up
62
+ try { fs.rmSync(lockDir, { recursive: true }); } catch { /* ignore */ }
63
+ continue;
64
+ }
65
+
66
+ if (attempt < retries) {
67
+ await new Promise(r => setTimeout(r, retryWait));
68
+ }
69
+ }
70
+ }
71
+
72
+ throw new Error(`Failed to acquire file lock after ${retries} retries: ${lockPath}`);
73
+ }
@@ -0,0 +1,41 @@
1
+ import { checkDesignQuality, type DesignReport } from './design-checker.js';
2
+ import { fwValidate } from './fw-api.js';
3
+
4
+ export interface FileValidationResult {
5
+ file: string;
6
+ valid: boolean;
7
+ errors: string[];
8
+ warnings: string[];
9
+ designReport?: DesignReport;
10
+ }
11
+
12
+ export async function validateFiles(
13
+ files: string[],
14
+ projectDir: string,
15
+ ): Promise<FileValidationResult[]> {
16
+ const results: FileValidationResult[] = [];
17
+
18
+ for (const file of files) {
19
+ if (!file.endsWith('.ts')) continue;
20
+ try {
21
+ const { valid, errors, warnings, ast } = await fwValidate(file);
22
+
23
+ if (!valid) {
24
+ results.push({ file, valid: false, errors, warnings });
25
+ continue;
26
+ }
27
+
28
+ const designReport = checkDesignQuality(ast);
29
+ const designWarnings = designReport.checks
30
+ .filter((c) => c.severity === 'warning' || c.severity === 'error')
31
+ .map((c) => `[${c.code}] ${c.message}`);
32
+
33
+ results.push({ file, valid: true, errors: [], warnings: [...warnings, ...designWarnings], designReport });
34
+ } catch (err: unknown) {
35
+ const msg = err instanceof Error ? err.message : String(err);
36
+ results.push({ file, valid: false, errors: [msg], warnings: [] });
37
+ }
38
+ }
39
+
40
+ return results;
41
+ }
@@ -0,0 +1,103 @@
1
+ import * as fs from 'node:fs';
2
+ import { EventEmitter } from 'node:events';
3
+
4
+ export interface FileWatcherOptions {
5
+ filePath: string;
6
+ debounceMs?: number;
7
+ pollingIntervalMs?: number;
8
+ }
9
+
10
+ export class FileWatcher extends EventEmitter {
11
+ private filePath: string;
12
+ private debounceMs: number;
13
+ private pollingIntervalMs: number;
14
+ private watcher: fs.FSWatcher | null = null;
15
+ private pollTimer: ReturnType<typeof setInterval> | null = null;
16
+ private debounceTimer: ReturnType<typeof setTimeout> | null = null;
17
+ private lastMtime: number = 0;
18
+ private stopped = false;
19
+
20
+ constructor(options: FileWatcherOptions) {
21
+ super();
22
+ this.filePath = options.filePath;
23
+ this.debounceMs = options.debounceMs ?? 500;
24
+ this.pollingIntervalMs = options.pollingIntervalMs ?? 2000;
25
+ }
26
+
27
+ start(): void {
28
+ this.stopped = false;
29
+ this.lastMtime = this.getMtime();
30
+ this.attachFsWatch();
31
+ }
32
+
33
+ stop(): void {
34
+ this.stopped = true;
35
+ if (this.debounceTimer) clearTimeout(this.debounceTimer);
36
+ if (this.pollTimer) clearInterval(this.pollTimer);
37
+ if (this.watcher) {
38
+ this.watcher.close();
39
+ this.watcher = null;
40
+ }
41
+ }
42
+
43
+ private attachFsWatch(): void {
44
+ try {
45
+ this.watcher = fs.watch(this.filePath, () => this.onFsEvent());
46
+ this.watcher.on('error', () => this.switchToPolling());
47
+ } catch {
48
+ this.switchToPolling();
49
+ }
50
+ }
51
+
52
+ private switchToPolling(): void {
53
+ if (this.stopped) return;
54
+ if (this.watcher) {
55
+ this.watcher.close();
56
+ this.watcher = null;
57
+ }
58
+ if (this.pollTimer) return;
59
+
60
+ this.pollTimer = setInterval(() => {
61
+ if (this.stopped) return;
62
+ const mtime = this.getMtime();
63
+ if (mtime > this.lastMtime) {
64
+ this.lastMtime = mtime;
65
+ this.emit('change');
66
+ }
67
+
68
+ // Try to re-attach fs.watch
69
+ if (!this.watcher && fs.existsSync(this.filePath)) {
70
+ try {
71
+ this.watcher = fs.watch(this.filePath, () => this.onFsEvent());
72
+ this.watcher.on('error', () => this.switchToPolling());
73
+ if (this.pollTimer) {
74
+ clearInterval(this.pollTimer);
75
+ this.pollTimer = null;
76
+ }
77
+ } catch {
78
+ // Stay in polling mode
79
+ }
80
+ }
81
+ }, this.pollingIntervalMs);
82
+ }
83
+
84
+ private onFsEvent(): void {
85
+ if (this.stopped) return;
86
+ if (this.debounceTimer) clearTimeout(this.debounceTimer);
87
+ this.debounceTimer = setTimeout(() => {
88
+ const mtime = this.getMtime();
89
+ if (mtime > this.lastMtime) {
90
+ this.lastMtime = mtime;
91
+ this.emit('change');
92
+ }
93
+ }, this.debounceMs);
94
+ }
95
+
96
+ private getMtime(): number {
97
+ try {
98
+ return fs.statSync(this.filePath).mtimeMs;
99
+ } catch {
100
+ return 0;
101
+ }
102
+ }
103
+ }
@@ -0,0 +1,18 @@
1
+ import { parseWorkflow, validateWorkflow } from '@synergenius/flow-weaver';
2
+ import type { TWorkflowAST } from '@synergenius/flow-weaver';
3
+
4
+ export async function fwValidate(filePath: string): Promise<{
5
+ valid: boolean;
6
+ errors: string[];
7
+ warnings: string[];
8
+ ast: TWorkflowAST;
9
+ }> {
10
+ const parseResult = await parseWorkflow(filePath);
11
+ if (parseResult.errors.length > 0) {
12
+ return { valid: false, errors: parseResult.errors, warnings: parseResult.warnings, ast: parseResult.ast };
13
+ }
14
+ const validation = validateWorkflow(parseResult.ast);
15
+ const errors = validation.errors.map((e) => typeof e === 'string' ? e : e.message);
16
+ const warnings = validation.warnings.map((w) => typeof w === 'string' ? w : w.message);
17
+ return { valid: errors.length === 0, errors, warnings, ast: parseResult.ast };
18
+ }
@@ -0,0 +1,135 @@
1
+ /**
2
+ * Shared prompt helpers for genesis propose and revise steps.
3
+ * Centralises context building so the AI always gets the CLI grammar,
4
+ * operation syntax, and workflow structure it needs to produce valid proposals.
5
+ */
6
+
7
+ import { buildSystemPrompt } from './system-prompt.js';
8
+ import type { GenesisConfig } from './types.js';
9
+
10
+ let cachedOpsContext: string | null = null;
11
+
12
+ /**
13
+ * Full system prompt with annotation grammar, CLI commands, validation codes,
14
+ * and genesis protocol. Cached after first call.
15
+ */
16
+ export async function getGenesisSystemPrompt(
17
+ config: GenesisConfig,
18
+ stabilized: boolean,
19
+ options?: { selfEvolveLocked?: boolean; graceRemaining?: number },
20
+ ): Promise<string> {
21
+ const base = await buildSystemPrompt();
22
+
23
+ const stabilizeClause = stabilized
24
+ ? '\n\nSTABILIZE MODE: Only removeNode, removeConnection, and implementNode operations are allowed. Do NOT propose addNode or addConnection.'
25
+ : '';
26
+
27
+ const selfEvolveClause = config.selfEvolve
28
+ ? [
29
+ '',
30
+ '## Self-Evolution',
31
+ `Self-evolution is ENABLED with a budget of ${config.selfEvolveBudget ?? 2} cost units.`,
32
+ 'Cost map: selfModifyWorkflow=3, selfModifyNodeType=2, selfModifyModule=2.',
33
+ 'Self-modify operations use { file: "relative/path.ts", content: "full file content" } in args.',
34
+ 'The file path is relative to the pack root (e.g. "src/workflows/genesis-task.ts").',
35
+ 'Content must be the complete replacement file, not a diff.',
36
+ ].join('\n')
37
+ : '';
38
+
39
+ const lockClause = options?.selfEvolveLocked
40
+ ? `\n\nSELF-EVOLUTION LOCKED: A migration is in grace period (${options.graceRemaining} cycles remaining). Do not propose selfModify operations.`
41
+ : '';
42
+
43
+ return [
44
+ base,
45
+ '',
46
+ '## Genesis Cycle Config',
47
+ `Intent: ${config.intent}`,
48
+ config.focus.length > 0 ? `Focus areas: ${config.focus.join(', ')}` : '',
49
+ config.constraints.length > 0 ? `Constraints: ${config.constraints.join(', ')}` : '',
50
+ `Budget: ${config.budgetPerCycle} cost units per cycle.`,
51
+ 'Cost map: addNode=1, removeNode=1, addConnection=1, removeConnection=1, implementNode=2.',
52
+ stabilizeClause,
53
+ selfEvolveClause,
54
+ lockClause,
55
+ ].filter(Boolean).join('\n');
56
+ }
57
+
58
+ /**
59
+ * Operation format reference with concrete examples.
60
+ * Appended to both propose and revise prompts so the AI knows
61
+ * the exact CLI arg format.
62
+ */
63
+ export function getOperationExamples(targetPath: string): string {
64
+ return `## Operation Format
65
+
66
+ Each operation is { type, args, costUnits, rationale }.
67
+
68
+ ### addNode
69
+ args: { "nodeId": "myNode", "nodeType": "someFunction", "file": "${targetPath}" }
70
+
71
+ ### removeNode
72
+ args: { "nodeId": "myNode", "file": "${targetPath}" }
73
+
74
+ ### addConnection
75
+ args: { "from": "sourceNode.portName", "to": "targetNode.portName", "file": "${targetPath}" }
76
+ IMPORTANT: Connection format is "node.port" using a DOT separator. NOT "node:port", NOT "node:portName".
77
+
78
+ ### removeConnection
79
+ args: { "from": "sourceNode.portName", "to": "targetNode.portName", "file": "${targetPath}" }
80
+
81
+ ### implementNode
82
+ args: { "nodeId": "existingStubNodeId", "file": "${targetPath}" }
83
+ Only works on nodes declared with \`declare function\` (stubs). The nodeId must match an existing stub in the workflow.
84
+
85
+ ### selfModifyWorkflow (cost: 3)
86
+ args: { "file": "src/workflows/genesis-task.ts", "content": "// full file content..." }
87
+ Replaces the genesis workflow file. File path is relative to pack root.
88
+
89
+ ### selfModifyNodeType (cost: 2)
90
+ args: { "file": "src/node-types/genesis-propose.ts", "content": "// full file content..." }
91
+ Replaces a genesis node type implementation.
92
+
93
+ ### selfModifyModule (cost: 2)
94
+ args: { "file": "src/bot/genesis-prompt-context.ts", "content": "// full file content..." }
95
+ Replaces a bot module file.
96
+
97
+ ## Response Format
98
+ Return ONLY valid JSON with: { operations: [...], totalCost: number, impactLevel: "COSMETIC"|"MINOR"|"BREAKING"|"CRITICAL", summary: string, rationale: string }
99
+ No markdown, no code fences, no explanation outside the JSON.`;
100
+ }
101
+
102
+ /**
103
+ * Ops context from flow-weaver docs (CLI reference, error codes, etc.).
104
+ * Falls back gracefully if the context module is unavailable.
105
+ */
106
+ export async function getOpsContext(): Promise<string> {
107
+ if (cachedOpsContext) return cachedOpsContext;
108
+
109
+ try {
110
+ const { buildContext } = await import('@synergenius/flow-weaver/context');
111
+ const result = buildContext({ preset: 'ops', includeGrammar: false });
112
+ cachedOpsContext = result.content;
113
+ } catch {
114
+ cachedOpsContext = '(ops context unavailable)';
115
+ }
116
+
117
+ return cachedOpsContext!;
118
+ }
119
+
120
+ /**
121
+ * Gets a text description of the workflow using the describe module.
122
+ * Falls back to reading the raw file if describe isn't available.
123
+ */
124
+ export async function getWorkflowDescription(filePath: string): Promise<string> {
125
+ try {
126
+ const { parseWorkflow } = await import('@synergenius/flow-weaver/api');
127
+ const { describeWorkflow, formatTextOutput } = await import('@synergenius/flow-weaver/describe');
128
+
129
+ const result = await parseWorkflow(filePath);
130
+ const output = describeWorkflow(result.ast);
131
+ return formatTextOutput(result.ast, output);
132
+ } catch {
133
+ return '(workflow description unavailable)';
134
+ }
135
+ }