opencastle 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (577) hide show
  1. package/README.md +102 -131
  2. package/bin/cli.mjs +20 -10
  3. package/dist/cli/adapters/claude-code.d.ts +5 -3
  4. package/dist/cli/adapters/claude-code.d.ts.map +1 -1
  5. package/dist/cli/adapters/claude-code.js +7 -3
  6. package/dist/cli/adapters/claude-code.js.map +1 -1
  7. package/dist/cli/adapters/single-file-base.d.ts +18 -0
  8. package/dist/cli/adapters/single-file-base.d.ts.map +1 -1
  9. package/dist/cli/adapters/single-file-base.js +29 -4
  10. package/dist/cli/adapters/single-file-base.js.map +1 -1
  11. package/dist/cli/agent-plugin.test.js +12 -0
  12. package/dist/cli/agent-plugin.test.js.map +1 -1
  13. package/dist/cli/agent-roster.test.js +0 -48
  14. package/dist/cli/agent-roster.test.js.map +1 -1
  15. package/dist/cli/bootstrap.d.ts.map +1 -1
  16. package/dist/cli/bootstrap.js +20 -0
  17. package/dist/cli/bootstrap.js.map +1 -1
  18. package/dist/cli/boundary.test.js +9 -7
  19. package/dist/cli/boundary.test.js.map +1 -1
  20. package/dist/cli/ci.d.ts.map +1 -1
  21. package/dist/cli/ci.js +6 -4
  22. package/dist/cli/ci.js.map +1 -1
  23. package/dist/cli/command-namespace.test.js +33 -0
  24. package/dist/cli/command-namespace.test.js.map +1 -1
  25. package/dist/cli/convoy/artifacts.d.ts +9 -2
  26. package/dist/cli/convoy/artifacts.d.ts.map +1 -1
  27. package/dist/cli/convoy/artifacts.js +13 -10
  28. package/dist/cli/convoy/artifacts.js.map +1 -1
  29. package/dist/cli/convoy/artifacts.test.js +4 -2
  30. package/dist/cli/convoy/artifacts.test.js.map +1 -1
  31. package/dist/cli/convoy/engine.d.ts +53 -23
  32. package/dist/cli/convoy/engine.d.ts.map +1 -1
  33. package/dist/cli/convoy/engine.git.test.d.ts +2 -0
  34. package/dist/cli/convoy/engine.git.test.d.ts.map +1 -0
  35. package/dist/cli/convoy/engine.git.test.js +435 -0
  36. package/dist/cli/convoy/engine.git.test.js.map +1 -0
  37. package/dist/cli/convoy/engine.js +1746 -2305
  38. package/dist/cli/convoy/engine.js.map +1 -1
  39. package/dist/cli/convoy/engine.test.js +698 -678
  40. package/dist/cli/convoy/engine.test.js.map +1 -1
  41. package/dist/cli/convoy/event-schemas.d.ts +2 -0
  42. package/dist/cli/convoy/event-schemas.d.ts.map +1 -1
  43. package/dist/cli/convoy/event-schemas.js +59 -57
  44. package/dist/cli/convoy/event-schemas.js.map +1 -1
  45. package/dist/cli/convoy/events.d.ts +4 -1
  46. package/dist/cli/convoy/events.d.ts.map +1 -1
  47. package/dist/cli/convoy/events.js +69 -84
  48. package/dist/cli/convoy/events.js.map +1 -1
  49. package/dist/cli/convoy/events.test.js +50 -9
  50. package/dist/cli/convoy/events.test.js.map +1 -1
  51. package/dist/cli/convoy/gates.d.ts +9 -4
  52. package/dist/cli/convoy/gates.d.ts.map +1 -1
  53. package/dist/cli/convoy/gates.js +29 -14
  54. package/dist/cli/convoy/gates.js.map +1 -1
  55. package/dist/cli/convoy/isolation.d.ts +32 -6
  56. package/dist/cli/convoy/isolation.d.ts.map +1 -1
  57. package/dist/cli/convoy/isolation.js +72 -34
  58. package/dist/cli/convoy/isolation.js.map +1 -1
  59. package/dist/cli/convoy/isolation.test.js +66 -42
  60. package/dist/cli/convoy/isolation.test.js.map +1 -1
  61. package/dist/cli/convoy/lock.d.ts.map +1 -1
  62. package/dist/cli/convoy/lock.js +25 -10
  63. package/dist/cli/convoy/lock.js.map +1 -1
  64. package/dist/cli/convoy/lock.test.js +12 -0
  65. package/dist/cli/convoy/lock.test.js.map +1 -1
  66. package/dist/cli/convoy/merge.d.ts +21 -4
  67. package/dist/cli/convoy/merge.d.ts.map +1 -1
  68. package/dist/cli/convoy/merge.js +69 -53
  69. package/dist/cli/convoy/merge.js.map +1 -1
  70. package/dist/cli/convoy/merge.test.js +23 -1
  71. package/dist/cli/convoy/merge.test.js.map +1 -1
  72. package/dist/cli/convoy/progress.d.ts +35 -0
  73. package/dist/cli/convoy/progress.d.ts.map +1 -0
  74. package/dist/cli/convoy/progress.js +103 -0
  75. package/dist/cli/convoy/progress.js.map +1 -0
  76. package/dist/cli/convoy/progress.test.d.ts +2 -0
  77. package/dist/cli/convoy/progress.test.d.ts.map +1 -0
  78. package/dist/cli/convoy/progress.test.js +53 -0
  79. package/dist/cli/convoy/progress.test.js.map +1 -0
  80. package/dist/cli/convoy/read-model.d.ts +468 -0
  81. package/dist/cli/convoy/read-model.d.ts.map +1 -0
  82. package/dist/cli/convoy/read-model.js +1132 -0
  83. package/dist/cli/convoy/read-model.js.map +1 -0
  84. package/dist/cli/convoy/read-model.test.d.ts +2 -0
  85. package/dist/cli/convoy/read-model.test.d.ts.map +1 -0
  86. package/dist/cli/convoy/read-model.test.js +609 -0
  87. package/dist/cli/convoy/read-model.test.js.map +1 -0
  88. package/dist/cli/convoy/redact.d.ts +34 -0
  89. package/dist/cli/convoy/redact.d.ts.map +1 -0
  90. package/dist/cli/convoy/redact.js +66 -0
  91. package/dist/cli/convoy/redact.js.map +1 -0
  92. package/dist/cli/convoy/redact.test.d.ts +2 -0
  93. package/dist/cli/convoy/redact.test.d.ts.map +1 -0
  94. package/dist/cli/convoy/redact.test.js +43 -0
  95. package/dist/cli/convoy/redact.test.js.map +1 -0
  96. package/dist/cli/convoy/reviewer.d.ts +65 -0
  97. package/dist/cli/convoy/reviewer.d.ts.map +1 -0
  98. package/dist/cli/convoy/reviewer.js +141 -0
  99. package/dist/cli/convoy/reviewer.js.map +1 -0
  100. package/dist/cli/convoy/reviewer.test.d.ts +2 -0
  101. package/dist/cli/convoy/reviewer.test.d.ts.map +1 -0
  102. package/dist/cli/convoy/reviewer.test.js +96 -0
  103. package/dist/cli/convoy/reviewer.test.js.map +1 -0
  104. package/dist/cli/convoy/schedule.d.ts +30 -0
  105. package/dist/cli/convoy/schedule.d.ts.map +1 -0
  106. package/dist/cli/convoy/schedule.js +111 -0
  107. package/dist/cli/convoy/schedule.js.map +1 -0
  108. package/dist/cli/convoy/schedule.test.d.ts +2 -0
  109. package/dist/cli/convoy/schedule.test.d.ts.map +1 -0
  110. package/dist/cli/convoy/schedule.test.js +45 -0
  111. package/dist/cli/convoy/schedule.test.js.map +1 -0
  112. package/dist/cli/convoy/spec-builder.d.ts +120 -30
  113. package/dist/cli/convoy/spec-builder.d.ts.map +1 -1
  114. package/dist/cli/convoy/spec-builder.js +438 -114
  115. package/dist/cli/convoy/spec-builder.js.map +1 -1
  116. package/dist/cli/convoy/spec-builder.test.js +419 -435
  117. package/dist/cli/convoy/spec-builder.test.js.map +1 -1
  118. package/dist/cli/convoy/spec-types.d.ts +46 -92
  119. package/dist/cli/convoy/spec-types.d.ts.map +1 -1
  120. package/dist/cli/convoy/store.d.ts +6 -1
  121. package/dist/cli/convoy/store.d.ts.map +1 -1
  122. package/dist/cli/convoy/store.js +111 -15
  123. package/dist/cli/convoy/store.js.map +1 -1
  124. package/dist/cli/convoy/store.test.js +59 -13
  125. package/dist/cli/convoy/store.test.js.map +1 -1
  126. package/dist/cli/convoy/types.d.ts +76 -113
  127. package/dist/cli/convoy/types.d.ts.map +1 -1
  128. package/dist/cli/convoy/types.js +6 -13
  129. package/dist/cli/convoy/types.js.map +1 -1
  130. package/dist/cli/convoy/worktree.d.ts +88 -3
  131. package/dist/cli/convoy/worktree.d.ts.map +1 -1
  132. package/dist/cli/convoy/worktree.js +282 -56
  133. package/dist/cli/convoy/worktree.js.map +1 -1
  134. package/dist/cli/convoy/worktree.test.js +132 -1
  135. package/dist/cli/convoy/worktree.test.js.map +1 -1
  136. package/dist/cli/convoy-args.test.js +9 -27
  137. package/dist/cli/convoy-args.test.js.map +1 -1
  138. package/dist/cli/convoy-cmd.d.ts +31 -6
  139. package/dist/cli/convoy-cmd.d.ts.map +1 -1
  140. package/dist/cli/convoy-cmd.js +150 -200
  141. package/dist/cli/convoy-cmd.js.map +1 -1
  142. package/dist/cli/convoy-cmd.test.d.ts +2 -0
  143. package/dist/cli/convoy-cmd.test.d.ts.map +1 -0
  144. package/dist/cli/convoy-cmd.test.js +144 -0
  145. package/dist/cli/convoy-cmd.test.js.map +1 -0
  146. package/dist/cli/dashboard.d.ts +24 -11
  147. package/dist/cli/dashboard.d.ts.map +1 -1
  148. package/dist/cli/dashboard.js +241 -303
  149. package/dist/cli/dashboard.js.map +1 -1
  150. package/dist/cli/dashboard.test.d.ts +2 -0
  151. package/dist/cli/dashboard.test.d.ts.map +1 -0
  152. package/dist/cli/dashboard.test.js +340 -0
  153. package/dist/cli/dashboard.test.js.map +1 -0
  154. package/dist/cli/dispatcher.test.js +41 -2
  155. package/dist/cli/dispatcher.test.js.map +1 -1
  156. package/dist/cli/docs-accuracy.test.js +36 -11
  157. package/dist/cli/docs-accuracy.test.js.map +1 -1
  158. package/dist/cli/doctor.d.ts.map +1 -1
  159. package/dist/cli/doctor.js +9 -6
  160. package/dist/cli/doctor.js.map +1 -1
  161. package/dist/cli/init-own-files.test.d.ts +2 -0
  162. package/dist/cli/init-own-files.test.d.ts.map +1 -0
  163. package/dist/cli/init-own-files.test.js +133 -0
  164. package/dist/cli/init-own-files.test.js.map +1 -0
  165. package/dist/cli/init.d.ts.map +1 -1
  166. package/dist/cli/init.js +106 -7
  167. package/dist/cli/init.js.map +1 -1
  168. package/dist/cli/init.test.js +5 -4
  169. package/dist/cli/init.test.js.map +1 -1
  170. package/dist/cli/layers.d.ts.map +1 -1
  171. package/dist/cli/layers.js +13 -4
  172. package/dist/cli/layers.js.map +1 -1
  173. package/dist/cli/lesson.d.ts.map +1 -1
  174. package/dist/cli/lesson.js +6 -5
  175. package/dist/cli/lesson.js.map +1 -1
  176. package/dist/cli/log.d.ts +39 -0
  177. package/dist/cli/log.d.ts.map +1 -1
  178. package/dist/cli/log.js +267 -93
  179. package/dist/cli/log.js.map +1 -1
  180. package/dist/cli/log.test.d.ts +2 -0
  181. package/dist/cli/log.test.d.ts.map +1 -0
  182. package/dist/cli/log.test.js +208 -0
  183. package/dist/cli/log.test.js.map +1 -0
  184. package/dist/cli/nearest.d.ts +18 -0
  185. package/dist/cli/nearest.d.ts.map +1 -0
  186. package/dist/cli/nearest.js +38 -0
  187. package/dist/cli/nearest.js.map +1 -0
  188. package/dist/cli/nearest.test.d.ts +2 -0
  189. package/dist/cli/nearest.test.d.ts.map +1 -0
  190. package/dist/cli/nearest.test.js +24 -0
  191. package/dist/cli/nearest.test.js.map +1 -0
  192. package/dist/cli/pipeline.d.ts +61 -0
  193. package/dist/cli/pipeline.d.ts.map +1 -1
  194. package/dist/cli/pipeline.flow.test.d.ts +2 -0
  195. package/dist/cli/pipeline.flow.test.d.ts.map +1 -0
  196. package/dist/cli/pipeline.flow.test.js +524 -0
  197. package/dist/cli/pipeline.flow.test.js.map +1 -0
  198. package/dist/cli/pipeline.js +471 -690
  199. package/dist/cli/pipeline.js.map +1 -1
  200. package/dist/cli/plan.d.ts +82 -31
  201. package/dist/cli/plan.d.ts.map +1 -1
  202. package/dist/cli/plan.js +167 -507
  203. package/dist/cli/plan.js.map +1 -1
  204. package/dist/cli/plan.test.d.ts +2 -0
  205. package/dist/cli/plan.test.d.ts.map +1 -0
  206. package/dist/cli/plan.test.js +158 -0
  207. package/dist/cli/plan.test.js.map +1 -0
  208. package/dist/cli/prompt.d.ts.map +1 -1
  209. package/dist/cli/prompt.js +9 -7
  210. package/dist/cli/prompt.js.map +1 -1
  211. package/dist/cli/prompt.test.js +20 -2
  212. package/dist/cli/prompt.test.js.map +1 -1
  213. package/dist/cli/remove.d.ts.map +1 -1
  214. package/dist/cli/remove.js +3 -1
  215. package/dist/cli/remove.js.map +1 -1
  216. package/dist/cli/review.d.ts.map +1 -1
  217. package/dist/cli/review.js +7 -1
  218. package/dist/cli/review.js.map +1 -1
  219. package/dist/cli/run/adapters/agent-process.d.ts +82 -0
  220. package/dist/cli/run/adapters/agent-process.d.ts.map +1 -0
  221. package/dist/cli/run/adapters/agent-process.js +224 -0
  222. package/dist/cli/run/adapters/agent-process.js.map +1 -0
  223. package/dist/cli/run/adapters/agent-process.test.d.ts +2 -0
  224. package/dist/cli/run/adapters/agent-process.test.d.ts.map +1 -0
  225. package/dist/cli/run/adapters/agent-process.test.js +159 -0
  226. package/dist/cli/run/adapters/agent-process.test.js.map +1 -0
  227. package/dist/cli/run/adapters/claude.d.ts +53 -2
  228. package/dist/cli/run/adapters/claude.d.ts.map +1 -1
  229. package/dist/cli/run/adapters/claude.js +147 -171
  230. package/dist/cli/run/adapters/claude.js.map +1 -1
  231. package/dist/cli/run/adapters/claude.test.js +197 -254
  232. package/dist/cli/run/adapters/claude.test.js.map +1 -1
  233. package/dist/cli/run/adapters/codex.d.ts +25 -2
  234. package/dist/cli/run/adapters/codex.d.ts.map +1 -1
  235. package/dist/cli/run/adapters/codex.js +113 -81
  236. package/dist/cli/run/adapters/codex.js.map +1 -1
  237. package/dist/cli/run/adapters/codex.test.js +116 -95
  238. package/dist/cli/run/adapters/codex.test.js.map +1 -1
  239. package/dist/cli/run/adapters/copilot.d.ts +35 -1
  240. package/dist/cli/run/adapters/copilot.d.ts.map +1 -1
  241. package/dist/cli/run/adapters/copilot.js +104 -287
  242. package/dist/cli/run/adapters/copilot.js.map +1 -1
  243. package/dist/cli/run/adapters/copilot.test.js +122 -282
  244. package/dist/cli/run/adapters/copilot.test.js.map +1 -1
  245. package/dist/cli/run/adapters/cursor.d.ts +25 -7
  246. package/dist/cli/run/adapters/cursor.d.ts.map +1 -1
  247. package/dist/cli/run/adapters/cursor.js +103 -156
  248. package/dist/cli/run/adapters/cursor.js.map +1 -1
  249. package/dist/cli/run/adapters/cursor.test.js +106 -218
  250. package/dist/cli/run/adapters/cursor.test.js.map +1 -1
  251. package/dist/cli/run/adapters/index.d.ts +34 -5
  252. package/dist/cli/run/adapters/index.d.ts.map +1 -1
  253. package/dist/cli/run/adapters/index.js +147 -21
  254. package/dist/cli/run/adapters/index.js.map +1 -1
  255. package/dist/cli/run/adapters/index.test.d.ts +2 -0
  256. package/dist/cli/run/adapters/index.test.d.ts.map +1 -0
  257. package/dist/cli/run/adapters/index.test.js +129 -0
  258. package/dist/cli/run/adapters/index.test.js.map +1 -0
  259. package/dist/cli/run/adapters/opencode.d.ts +25 -9
  260. package/dist/cli/run/adapters/opencode.d.ts.map +1 -1
  261. package/dist/cli/run/adapters/opencode.js +136 -152
  262. package/dist/cli/run/adapters/opencode.js.map +1 -1
  263. package/dist/cli/run/adapters/opencode.test.js +99 -218
  264. package/dist/cli/run/adapters/opencode.test.js.map +1 -1
  265. package/dist/cli/run/adapters/permission-modes.d.ts +47 -4
  266. package/dist/cli/run/adapters/permission-modes.d.ts.map +1 -1
  267. package/dist/cli/run/adapters/permission-modes.js +113 -37
  268. package/dist/cli/run/adapters/permission-modes.js.map +1 -1
  269. package/dist/cli/run/adapters/permission-modes.test.js +55 -40
  270. package/dist/cli/run/adapters/permission-modes.test.js.map +1 -1
  271. package/dist/cli/run/adapters/stub-cli.test-helper.d.ts +22 -0
  272. package/dist/cli/run/adapters/stub-cli.test-helper.d.ts.map +1 -0
  273. package/dist/cli/run/adapters/stub-cli.test-helper.js +73 -0
  274. package/dist/cli/run/adapters/stub-cli.test-helper.js.map +1 -0
  275. package/dist/cli/run/platform.d.ts +52 -0
  276. package/dist/cli/run/platform.d.ts.map +1 -0
  277. package/dist/cli/run/platform.js +207 -0
  278. package/dist/cli/run/platform.js.map +1 -0
  279. package/dist/cli/run/platform.test.d.ts +2 -0
  280. package/dist/cli/run/platform.test.d.ts.map +1 -0
  281. package/dist/cli/run/platform.test.js +119 -0
  282. package/dist/cli/run/platform.test.js.map +1 -0
  283. package/dist/cli/run/schema.d.ts +6 -8
  284. package/dist/cli/run/schema.d.ts.map +1 -1
  285. package/dist/cli/run/schema.js +44 -68
  286. package/dist/cli/run/schema.js.map +1 -1
  287. package/dist/cli/run/schema.test.js +59 -279
  288. package/dist/cli/run/schema.test.js.map +1 -1
  289. package/dist/cli/run.d.ts +34 -56
  290. package/dist/cli/run.d.ts.map +1 -1
  291. package/dist/cli/run.js +379 -1132
  292. package/dist/cli/run.js.map +1 -1
  293. package/dist/cli/run.test.d.ts +2 -0
  294. package/dist/cli/run.test.d.ts.map +1 -0
  295. package/dist/cli/run.test.js +318 -0
  296. package/dist/cli/run.test.js.map +1 -0
  297. package/dist/cli/sync-check.d.ts.map +1 -1
  298. package/dist/cli/sync-check.js +12 -3
  299. package/dist/cli/sync-check.js.map +1 -1
  300. package/dist/cli/sync.d.ts.map +1 -1
  301. package/dist/cli/sync.js +3 -2
  302. package/dist/cli/sync.js.map +1 -1
  303. package/dist/cli/team-config.d.ts.map +1 -1
  304. package/dist/cli/team-config.js +2 -21
  305. package/dist/cli/team-config.js.map +1 -1
  306. package/dist/cli/tiers.test.js +4 -13
  307. package/dist/cli/tiers.test.js.map +1 -1
  308. package/dist/cli/update.d.ts.map +1 -1
  309. package/dist/cli/update.js +4 -3
  310. package/dist/cli/update.js.map +1 -1
  311. package/dist/cli/website-plugins.test.js +51 -2
  312. package/dist/cli/website-plugins.test.js.map +1 -1
  313. package/dist/orchestrator/plugins/coolify/config.d.ts.map +1 -1
  314. package/dist/orchestrator/plugins/coolify/config.js +13 -0
  315. package/dist/orchestrator/plugins/coolify/config.js.map +1 -1
  316. package/dist/orchestrator/plugins/sentry/config.d.ts.map +1 -1
  317. package/dist/orchestrator/plugins/sentry/config.js +13 -0
  318. package/dist/orchestrator/plugins/sentry/config.js.map +1 -1
  319. package/package.json +3 -10
  320. package/src/cli/adapters/claude-code.ts +7 -3
  321. package/src/cli/adapters/single-file-base.ts +47 -4
  322. package/src/cli/agent-plugin.test.ts +14 -0
  323. package/src/cli/agent-roster.test.ts +0 -55
  324. package/src/cli/bootstrap.ts +23 -0
  325. package/src/cli/boundary.test.ts +9 -7
  326. package/src/cli/ci.ts +6 -4
  327. package/src/cli/command-namespace.test.ts +35 -0
  328. package/src/cli/convoy/TELEMETRY.md +138 -130
  329. package/src/cli/convoy/artifacts.test.ts +4 -2
  330. package/src/cli/convoy/artifacts.ts +13 -12
  331. package/src/cli/convoy/engine.git.test.ts +462 -0
  332. package/src/cli/convoy/engine.test.ts +817 -850
  333. package/src/cli/convoy/engine.ts +1864 -2596
  334. package/src/cli/convoy/event-schemas.ts +63 -59
  335. package/src/cli/convoy/events.test.ts +58 -9
  336. package/src/cli/convoy/events.ts +69 -91
  337. package/src/cli/convoy/gates.ts +31 -12
  338. package/src/cli/convoy/isolation.test.ts +76 -43
  339. package/src/cli/convoy/isolation.ts +100 -38
  340. package/src/cli/convoy/lock.test.ts +16 -0
  341. package/src/cli/convoy/lock.ts +25 -8
  342. package/src/cli/convoy/merge.test.ts +25 -1
  343. package/src/cli/convoy/merge.ts +74 -61
  344. package/src/cli/convoy/progress.test.ts +59 -0
  345. package/src/cli/convoy/progress.ts +121 -0
  346. package/src/cli/convoy/read-model.test.ts +685 -0
  347. package/src/cli/convoy/read-model.ts +1469 -0
  348. package/src/cli/convoy/redact.test.ts +49 -0
  349. package/src/cli/convoy/redact.ts +73 -0
  350. package/src/cli/convoy/reviewer.test.ts +112 -0
  351. package/src/cli/convoy/reviewer.ts +196 -0
  352. package/src/cli/convoy/schedule.test.ts +56 -0
  353. package/src/cli/convoy/schedule.ts +109 -0
  354. package/src/cli/convoy/spec-builder.test.ts +460 -464
  355. package/src/cli/convoy/spec-builder.ts +460 -129
  356. package/src/cli/convoy/spec-types.ts +46 -108
  357. package/src/cli/convoy/store.test.ts +64 -13
  358. package/src/cli/convoy/store.ts +143 -33
  359. package/src/cli/convoy/types.ts +59 -71
  360. package/src/cli/convoy/worktree.test.ts +140 -1
  361. package/src/cli/convoy/worktree.ts +311 -61
  362. package/src/cli/convoy-args.test.ts +10 -30
  363. package/src/cli/convoy-cmd.test.ts +163 -0
  364. package/src/cli/convoy-cmd.ts +173 -215
  365. package/src/cli/dashboard/dashboard.css +2086 -0
  366. package/src/cli/dashboard/dashboard.js +1687 -0
  367. package/src/cli/dashboard/index.html +307 -0
  368. package/src/cli/dashboard.test.ts +382 -0
  369. package/src/cli/dashboard.ts +243 -339
  370. package/src/cli/dispatcher.test.ts +43 -2
  371. package/src/cli/docs-accuracy.test.ts +37 -10
  372. package/src/cli/doctor.ts +9 -6
  373. package/src/cli/init-own-files.test.ts +156 -0
  374. package/src/cli/init.test.ts +5 -4
  375. package/src/cli/init.ts +104 -7
  376. package/src/cli/layers.ts +13 -4
  377. package/src/cli/lesson.ts +6 -5
  378. package/src/cli/log.test.ts +228 -0
  379. package/src/cli/log.ts +302 -83
  380. package/src/cli/nearest.test.ts +27 -0
  381. package/src/cli/nearest.ts +38 -0
  382. package/src/cli/pipeline.flow.test.ts +607 -0
  383. package/src/cli/pipeline.ts +544 -759
  384. package/src/cli/plan.test.ts +193 -0
  385. package/src/cli/plan.ts +209 -545
  386. package/src/cli/prompt.test.ts +21 -2
  387. package/src/cli/prompt.ts +11 -7
  388. package/src/cli/remove.ts +3 -0
  389. package/src/cli/review.ts +7 -1
  390. package/src/cli/run/adapters/agent-process.test.ts +175 -0
  391. package/src/cli/run/adapters/agent-process.ts +252 -0
  392. package/src/cli/run/adapters/claude.test.ts +205 -260
  393. package/src/cli/run/adapters/claude.ts +151 -162
  394. package/src/cli/run/adapters/codex.test.ts +120 -100
  395. package/src/cli/run/adapters/codex.ts +115 -91
  396. package/src/cli/run/adapters/copilot.test.ts +135 -306
  397. package/src/cli/run/adapters/copilot.ts +105 -274
  398. package/src/cli/run/adapters/cursor.test.ts +111 -220
  399. package/src/cli/run/adapters/cursor.ts +105 -156
  400. package/src/cli/run/adapters/index.test.ts +148 -0
  401. package/src/cli/run/adapters/index.ts +168 -20
  402. package/src/cli/run/adapters/opencode.test.ts +106 -227
  403. package/src/cli/run/adapters/opencode.ts +139 -151
  404. package/src/cli/run/adapters/permission-modes.test.ts +63 -41
  405. package/src/cli/run/adapters/permission-modes.ts +118 -37
  406. package/src/cli/run/adapters/stub-cli.test-helper.ts +88 -0
  407. package/src/cli/run/platform.test.ts +128 -0
  408. package/src/cli/run/platform.ts +213 -0
  409. package/src/cli/run/schema.test.ts +62 -344
  410. package/src/cli/run/schema.ts +48 -78
  411. package/src/cli/run.test.ts +351 -0
  412. package/src/cli/run.ts +366 -1151
  413. package/src/cli/sync-check.ts +12 -3
  414. package/src/cli/sync.ts +3 -2
  415. package/src/cli/team-config.ts +2 -21
  416. package/src/cli/tiers.test.ts +4 -17
  417. package/src/cli/update.ts +4 -3
  418. package/src/cli/website-plugins.test.ts +55 -5
  419. package/src/orchestrator/agents/team-lead.agent.md +2 -2
  420. package/src/orchestrator/customizations/README.md +58 -13
  421. package/src/orchestrator/customizations/logs/README.md +23 -18
  422. package/src/orchestrator/instructions/general.instructions.md +1 -1
  423. package/src/orchestrator/plugins/coolify/config.ts +13 -0
  424. package/src/orchestrator/plugins/sentry/config.ts +13 -0
  425. package/src/orchestrator/prompts/assess-complexity.prompt.md +43 -26
  426. package/src/orchestrator/prompts/bootstrap-customizations.prompt.md +44 -49
  427. package/src/orchestrator/prompts/brainstorm.prompt.md +2 -2
  428. package/src/orchestrator/prompts/bug-fix.prompt.md +5 -4
  429. package/src/orchestrator/prompts/create-skill.prompt.md +29 -39
  430. package/src/orchestrator/prompts/fix-convoy.prompt.md +43 -29
  431. package/src/orchestrator/prompts/fix-prd.prompt.md +26 -22
  432. package/src/orchestrator/prompts/generate-convoy.prompt.md +139 -147
  433. package/src/orchestrator/prompts/generate-prd.prompt.md +75 -68
  434. package/src/orchestrator/prompts/implement-feature.prompt.md +7 -6
  435. package/src/orchestrator/prompts/validate-convoy.prompt.md +29 -28
  436. package/src/orchestrator/prompts/validate-prd.prompt.md +28 -21
  437. package/src/orchestrator/skills/agent-hooks/HOOKS-REFERENCE.md +3 -3
  438. package/src/orchestrator/skills/agent-hooks/SKILL.md +1 -1
  439. package/src/orchestrator/skills/fast-review/SKILL.md +3 -1
  440. package/src/orchestrator/skills/orchestration-protocols/SKILL.md +7 -8
  441. package/dist/cli/convoy/dag-analysis.d.ts +0 -39
  442. package/dist/cli/convoy/dag-analysis.d.ts.map +0 -1
  443. package/dist/cli/convoy/dag-analysis.js +0 -279
  444. package/dist/cli/convoy/dag-analysis.js.map +0 -1
  445. package/dist/cli/convoy/dag-analysis.test.d.ts +0 -2
  446. package/dist/cli/convoy/dag-analysis.test.d.ts.map +0 -1
  447. package/dist/cli/convoy/dag-analysis.test.js +0 -289
  448. package/dist/cli/convoy/dag-analysis.test.js.map +0 -1
  449. package/dist/cli/convoy/formula.d.ts +0 -19
  450. package/dist/cli/convoy/formula.d.ts.map +0 -1
  451. package/dist/cli/convoy/formula.js +0 -142
  452. package/dist/cli/convoy/formula.js.map +0 -1
  453. package/dist/cli/convoy/formula.test.d.ts +0 -2
  454. package/dist/cli/convoy/formula.test.d.ts.map +0 -1
  455. package/dist/cli/convoy/formula.test.js +0 -342
  456. package/dist/cli/convoy/formula.test.js.map +0 -1
  457. package/dist/cli/convoy/health.d.ts +0 -34
  458. package/dist/cli/convoy/health.d.ts.map +0 -1
  459. package/dist/cli/convoy/health.js +0 -123
  460. package/dist/cli/convoy/health.js.map +0 -1
  461. package/dist/cli/convoy/health.test.d.ts +0 -2
  462. package/dist/cli/convoy/health.test.d.ts.map +0 -1
  463. package/dist/cli/convoy/health.test.js +0 -448
  464. package/dist/cli/convoy/health.test.js.map +0 -1
  465. package/dist/cli/convoy/last-run.d.ts +0 -53
  466. package/dist/cli/convoy/last-run.d.ts.map +0 -1
  467. package/dist/cli/convoy/last-run.js +0 -54
  468. package/dist/cli/convoy/last-run.js.map +0 -1
  469. package/dist/cli/convoy/last-run.test.d.ts +0 -2
  470. package/dist/cli/convoy/last-run.test.d.ts.map +0 -1
  471. package/dist/cli/convoy/last-run.test.js +0 -110
  472. package/dist/cli/convoy/last-run.test.js.map +0 -1
  473. package/dist/cli/convoy/pipeline.d.ts +0 -41
  474. package/dist/cli/convoy/pipeline.d.ts.map +0 -1
  475. package/dist/cli/convoy/pipeline.js +0 -414
  476. package/dist/cli/convoy/pipeline.js.map +0 -1
  477. package/dist/cli/convoy/pipeline.test.d.ts +0 -2
  478. package/dist/cli/convoy/pipeline.test.d.ts.map +0 -1
  479. package/dist/cli/convoy/pipeline.test.js +0 -837
  480. package/dist/cli/convoy/pipeline.test.js.map +0 -1
  481. package/dist/cli/convoy/review-stages.d.ts +0 -9
  482. package/dist/cli/convoy/review-stages.d.ts.map +0 -1
  483. package/dist/cli/convoy/review-stages.js +0 -134
  484. package/dist/cli/convoy/review-stages.js.map +0 -1
  485. package/dist/cli/convoy/review-stages.test.d.ts +0 -2
  486. package/dist/cli/convoy/review-stages.test.d.ts.map +0 -1
  487. package/dist/cli/convoy/review-stages.test.js +0 -197
  488. package/dist/cli/convoy/review-stages.test.js.map +0 -1
  489. package/dist/cli/run/executor.d.ts +0 -15
  490. package/dist/cli/run/executor.d.ts.map +0 -1
  491. package/dist/cli/run/executor.js +0 -249
  492. package/dist/cli/run/executor.js.map +0 -1
  493. package/dist/cli/run/executor.test.d.ts +0 -2
  494. package/dist/cli/run/executor.test.d.ts.map +0 -1
  495. package/dist/cli/run/executor.test.js +0 -297
  496. package/dist/cli/run/executor.test.js.map +0 -1
  497. package/dist/cli/run/reporter.d.ts +0 -10
  498. package/dist/cli/run/reporter.d.ts.map +0 -1
  499. package/dist/cli/run/reporter.js +0 -142
  500. package/dist/cli/run/reporter.js.map +0 -1
  501. package/dist/cli/run-dry-run.test.d.ts +0 -2
  502. package/dist/cli/run-dry-run.test.d.ts.map +0 -1
  503. package/dist/cli/run-dry-run.test.js +0 -83
  504. package/dist/cli/run-dry-run.test.js.map +0 -1
  505. package/dist/cli/run-executor-flags.test.d.ts +0 -2
  506. package/dist/cli/run-executor-flags.test.d.ts.map +0 -1
  507. package/dist/cli/run-executor-flags.test.js +0 -31
  508. package/dist/cli/run-executor-flags.test.js.map +0 -1
  509. package/dist/cli/run-finish.test.d.ts +0 -2
  510. package/dist/cli/run-finish.test.d.ts.map +0 -1
  511. package/dist/cli/run-finish.test.js +0 -77
  512. package/dist/cli/run-finish.test.js.map +0 -1
  513. package/dist/cli/watch.d.ts +0 -15
  514. package/dist/cli/watch.d.ts.map +0 -1
  515. package/dist/cli/watch.js +0 -277
  516. package/dist/cli/watch.js.map +0 -1
  517. package/dist/dashboard/scripts/etl.d.ts +0 -10
  518. package/dist/dashboard/scripts/etl.d.ts.map +0 -1
  519. package/dist/dashboard/scripts/etl.js +0 -141
  520. package/dist/dashboard/scripts/etl.js.map +0 -1
  521. package/src/cli/convoy/dag-analysis.test.ts +0 -349
  522. package/src/cli/convoy/dag-analysis.ts +0 -367
  523. package/src/cli/convoy/formula.test.ts +0 -404
  524. package/src/cli/convoy/formula.ts +0 -174
  525. package/src/cli/convoy/health.test.ts +0 -519
  526. package/src/cli/convoy/health.ts +0 -189
  527. package/src/cli/convoy/last-run.test.ts +0 -130
  528. package/src/cli/convoy/last-run.ts +0 -87
  529. package/src/cli/convoy/pipeline.test.ts +0 -999
  530. package/src/cli/convoy/pipeline.ts +0 -492
  531. package/src/cli/convoy/review-stages.test.ts +0 -235
  532. package/src/cli/convoy/review-stages.ts +0 -166
  533. package/src/cli/run/executor.test.ts +0 -338
  534. package/src/cli/run/executor.ts +0 -292
  535. package/src/cli/run/reporter.ts +0 -160
  536. package/src/cli/run-dry-run.test.ts +0 -97
  537. package/src/cli/run-executor-flags.test.ts +0 -38
  538. package/src/cli/run-finish.test.ts +0 -91
  539. package/src/cli/watch.ts +0 -295
  540. package/src/dashboard/astro.config.mjs +0 -6
  541. package/src/dashboard/dist/_astro/index.CADNhRPS.css +0 -1
  542. package/src/dashboard/dist/data/.gitkeep +0 -0
  543. package/src/dashboard/dist/data/convoy-list.json +0 -1
  544. package/src/dashboard/dist/data/overall-stats.json +0 -29
  545. package/src/dashboard/dist/index.html +0 -1963
  546. package/src/dashboard/node_modules/.vite/deps/_metadata.json +0 -31
  547. package/src/dashboard/node_modules/.vite/deps/astro___aria-query.js +0 -6776
  548. package/src/dashboard/node_modules/.vite/deps/astro___aria-query.js.map +0 -7
  549. package/src/dashboard/node_modules/.vite/deps/astro___axobject-query.js +0 -3754
  550. package/src/dashboard/node_modules/.vite/deps/astro___axobject-query.js.map +0 -7
  551. package/src/dashboard/node_modules/.vite/deps/astro___cssesc.js +0 -99
  552. package/src/dashboard/node_modules/.vite/deps/astro___cssesc.js.map +0 -7
  553. package/src/dashboard/node_modules/.vite/deps/chunk-BUSYA2B4.js +0 -8
  554. package/src/dashboard/node_modules/.vite/deps/chunk-BUSYA2B4.js.map +0 -7
  555. package/src/dashboard/node_modules/.vite/deps/package.json +0 -3
  556. package/src/dashboard/package-lock.json +0 -6
  557. package/src/dashboard/public/data/.gitkeep +0 -0
  558. package/src/dashboard/public/data/convoy-list.json +0 -1
  559. package/src/dashboard/public/data/overall-stats.json +0 -29
  560. package/src/dashboard/public/icon-192.png +0 -0
  561. package/src/dashboard/scripts/etl.test.ts +0 -166
  562. package/src/dashboard/scripts/etl.ts +0 -170
  563. package/src/dashboard/scripts/generate-demo-db.test.ts +0 -30
  564. package/src/dashboard/scripts/generate-demo-db.ts +0 -529
  565. package/src/dashboard/scripts/integration-test.ts +0 -504
  566. package/src/dashboard/scripts/verify-demo-data.sh +0 -51
  567. package/src/dashboard/seed-data/delegations.ndjson +0 -35
  568. package/src/dashboard/seed-data/events.ndjson +0 -104
  569. package/src/dashboard/seed-data/panels.ndjson +0 -13
  570. package/src/dashboard/seed-data/reviews.ndjson +0 -6
  571. package/src/dashboard/seed-data/sessions.ndjson +0 -50
  572. package/src/dashboard/src/env.d.ts +0 -1
  573. package/src/dashboard/src/layouts/Layout.astro +0 -25
  574. package/src/dashboard/src/pages/index.astro +0 -2313
  575. package/src/dashboard/src/styles/dashboard.css +0 -2943
  576. package/src/dashboard/tsconfig.json +0 -6
  577. /package/src/{dashboard/dist → cli/dashboard}/icon-192.png +0 -0
@@ -1,8 +1,12 @@
1
- import { describe, it, expect, vi } from 'vitest';
1
+ import { describe, it, expect, vi, afterEach } from 'vitest';
2
+ import { mkdtempSync, writeFileSync, rmSync } from 'node:fs';
3
+ import { tmpdir } from 'node:os';
4
+ import { join } from 'node:path';
2
5
  import { parse as yamlParse } from 'yaml';
3
6
  import { parseYaml, validateSpec } from '../run/schema.js';
4
- import { buildConvoyYaml, applyPatches, parseTaskPlan, parsePatches, deriveSpecEnrichment, } from './spec-builder.js';
7
+ import { foldTestOnlyTasks, buildConvoyYaml, applyPatches, parseTaskPlan, parseTaskPlanWithReason, parsePatches, detectPackageManager, detectGates, planConcurrency, normalizePlanFiles, checkPlan, sequenceConflicts, mergeGroupPlans, slugify, MAX_PLANNED_CONCURRENCY, } from './spec-builder.js';
5
8
  // ── helpers ────────────────────────────────────────────────────────────────────
9
+ const SETTINGS = { adapter: 'claude', branch: 'convoy/my-feature', gates: [] };
6
10
  function minimalPlan() {
7
11
  return {
8
12
  name: 'My Feature',
@@ -12,88 +16,87 @@ function minimalPlan() {
12
16
  function fullTask() {
13
17
  return {
14
18
  id: 'full-task',
15
- agent: 'ui-expert',
19
+ agent: 'ui-ux-expert',
16
20
  description: 'A fully-specified task',
17
21
  files: ['src/foo.ts', 'src/bar.ts'],
18
22
  depends_on: ['other-task'],
19
23
  timeout: '15m',
20
24
  max_retries: 3,
21
25
  review: 'panel',
22
- gates: ['custom-gate'],
23
- built_in_gates: { secret_scan: true },
24
26
  prompt: 'Implement the feature\n\nWith multiple paragraphs.',
25
27
  };
26
28
  }
29
+ function build(plan, settings = SETTINGS) {
30
+ return yamlParse(buildConvoyYaml(plan, settings));
31
+ }
32
+ const tmpDirs = [];
33
+ function project(files) {
34
+ const dir = mkdtempSync(join(tmpdir(), 'oc-spec-builder-'));
35
+ tmpDirs.push(dir);
36
+ for (const [name, text] of Object.entries(files))
37
+ writeFileSync(join(dir, name), text);
38
+ return dir;
39
+ }
40
+ afterEach(() => {
41
+ while (tmpDirs.length)
42
+ rmSync(tmpDirs.pop(), { recursive: true, force: true });
43
+ });
27
44
  // ── buildConvoyYaml ────────────────────────────────────────────────────────────
28
45
  describe('buildConvoyYaml', () => {
29
- it('builds valid YAML from a minimal plan', () => {
30
- const yaml = buildConvoyYaml(minimalPlan());
31
- expect(typeof yaml).toBe('string');
32
- expect(yaml.length).toBeGreaterThan(0);
33
- const parsed = yamlParse(yaml);
34
- expect(parsed.name).toBe('My Feature');
35
- expect(Array.isArray(parsed.tasks)).toBe(true);
36
- });
37
- it('sets correct defaults when not specified', () => {
38
- const yaml = buildConvoyYaml(minimalPlan());
39
- const parsed = yamlParse(yaml);
40
- expect(parsed.concurrency).toBe(2);
41
- expect(parsed.on_failure).toBe('stop');
46
+ it('builds a spec the runner accepts from a minimal plan', () => {
47
+ const yaml = buildConvoyYaml(minimalPlan(), SETTINGS);
48
+ const result = validateSpec(parseYaml(yaml));
49
+ expect(result.errors).toEqual([]);
50
+ expect(result.valid).toBe(true);
51
+ });
52
+ it('is safe by default: own branch, continue on failure, the runtime recorded', () => {
53
+ const parsed = build(minimalPlan());
42
54
  expect(parsed.version).toBe(1);
43
- expect(parsed.defaults.timeout).toBe('30m');
44
- expect(parsed.defaults.max_retries).toBe(1);
45
- expect(parsed.defaults.review).toBe('fast');
46
- });
47
- it('uses plan concurrency and on_failure when provided', () => {
48
- const plan = { ...minimalPlan(), concurrency: 4, on_failure: 'continue' };
49
- const parsed = yamlParse(buildConvoyYaml(plan));
50
- expect(parsed.concurrency).toBe(4);
55
+ expect(parsed.branch).toBe('convoy/my-feature');
51
56
  expect(parsed.on_failure).toBe('continue');
57
+ expect(parsed.adapter).toBe('claude');
52
58
  });
53
- it('includes branch when defined', () => {
54
- const plan = { ...minimalPlan(), branch: 'feat/my-branch' };
55
- const parsed = yamlParse(buildConvoyYaml(plan));
56
- expect(parsed.branch).toBe('feat/my-branch');
57
- });
58
- it('omits branch when undefined', () => {
59
- const parsed = yamlParse(buildConvoyYaml(minimalPlan()));
60
- expect(parsed.branch).toBeUndefined();
59
+ it('switches on nothing that re-runs work per task', () => {
60
+ const parsed = build({ ...minimalPlan(), tasks: [{ id: 't', complexity: 13, prompt: 'Epic' }] });
61
+ expect(parsed.defaults.detect_drift).toBeUndefined();
62
+ expect(parsed.defaults.built_in_gates).toBeUndefined();
63
+ expect(parsed.guard).toBeUndefined();
64
+ expect(parsed.tasks[0].gates).toBeUndefined();
65
+ expect(parsed.tasks[0].built_in_gates).toBeUndefined();
61
66
  });
62
- it('includes gates and gate_retries when defined', () => {
63
- const plan = { ...minimalPlan(), gates: ['lint', 'tests'], gate_retries: 2 };
64
- const parsed = yamlParse(buildConvoyYaml(plan));
65
- expect(parsed.gates).toEqual(['lint', 'tests']);
66
- expect(parsed.gate_retries).toBe(2);
67
+ it('runs the project checks once at the end, with one fix attempt', () => {
68
+ const parsed = build(minimalPlan(), { ...SETTINGS, gates: ['pnpm run lint', 'pnpm run test'] });
69
+ expect(parsed.gates).toEqual(['pnpm run lint', 'pnpm run test']);
70
+ expect(parsed.gate_retries).toBe(1);
67
71
  });
68
- it('omits gates and gate_retries when undefined', () => {
69
- const parsed = yamlParse(buildConvoyYaml(minimalPlan()));
72
+ it('omits gates and gate_retries when the project has no checks', () => {
73
+ const parsed = build(minimalPlan());
70
74
  expect(parsed.gates).toBeUndefined();
71
75
  expect(parsed.gate_retries).toBeUndefined();
72
76
  });
77
+ it('sizes concurrency to the plan', () => {
78
+ const wide = { name: 'w', tasks: ['a', 'b', 'c'].map((id) => ({ id, prompt: id })) };
79
+ expect(build(wide).concurrency).toBe(3);
80
+ expect(build(minimalPlan()).concurrency).toBe(1);
81
+ });
82
+ it('keeps the default timeout, retries and review', () => {
83
+ const parsed = build(minimalPlan());
84
+ expect(parsed.defaults).toEqual({ timeout: '30m', max_retries: 1, review: 'fast' });
85
+ });
73
86
  it('handles tasks with all optional fields set', () => {
74
- const plan = {
75
- name: 'My Feature',
76
- tasks: [
77
- { id: 'other-task', prompt: 'Other task' },
78
- fullTask(),
79
- ],
80
- };
81
- const parsed = yamlParse(buildConvoyYaml(plan));
82
- const task = parsed.tasks[1];
83
- expect(task.agent).toBe('ui-expert');
87
+ const plan = { name: 'My Feature', tasks: [{ id: 'other-task', prompt: 'Other task' }, fullTask()] };
88
+ const task = build(plan).tasks[1];
89
+ expect(task.agent).toBe('ui-ux-expert');
84
90
  expect(task.description).toBe('A fully-specified task');
85
91
  expect(task.files).toEqual(['src/foo.ts', 'src/bar.ts']);
86
92
  expect(task.depends_on).toEqual(['other-task']);
87
93
  expect(task.timeout).toBe('15m');
88
94
  expect(task.max_retries).toBe(3);
89
95
  expect(task.review).toBe('panel');
90
- expect(task.gates).toEqual(['custom-gate']);
91
- expect(task.built_in_gates).toEqual({ secret_scan: true });
92
96
  expect(task.prompt).toBe('Implement the feature\n\nWith multiple paragraphs.');
93
97
  });
94
98
  it('handles tasks with only required fields (id + prompt)', () => {
95
- const parsed = yamlParse(buildConvoyYaml(minimalPlan()));
96
- const task = parsed.tasks[0];
99
+ const task = build(minimalPlan()).tasks[0];
97
100
  expect(task.id).toBe('task-1');
98
101
  expect(task.prompt).toBe('Do something useful');
99
102
  expect(task.agent).toBe('developer');
@@ -103,249 +106,325 @@ describe('buildConvoyYaml', () => {
103
106
  expect(task.timeout).toBeUndefined();
104
107
  expect(task.max_retries).toBeUndefined();
105
108
  });
106
- it('prepends the comment header with kebab-case file path', () => {
107
- const yaml = buildConvoyYaml(minimalPlan());
108
- expect(yaml.startsWith('# .opencastle/convoys/my-feature.convoy.yml\n')).toBe(true);
109
- });
110
- it('comment header converts spaces and special chars to kebab-case', () => {
111
- const plan = { ...minimalPlan(), name: 'My Big Feature 2' };
112
- const yaml = buildConvoyYaml(plan);
113
- expect(yaml.startsWith('# .opencastle/convoys/my-big-feature-2.convoy.yml\n')).toBe(true);
109
+ it('starts with a comment saying how to run it', () => {
110
+ const yaml = buildConvoyYaml(minimalPlan(), SETTINGS);
111
+ expect(yaml.startsWith('# Written by `opencastle convoy`.')).toBe(true);
112
+ expect(yaml).toContain('opencastle convoy run <this file>');
114
113
  });
115
114
  it('ensures prompt appears last in each task YAML block', () => {
115
+ const plan = { name: 'My Feature', tasks: [{ id: 'other-task', prompt: 'Other task' }, fullTask()] };
116
+ const yaml = buildConvoyYaml(plan, SETTINGS);
117
+ const promptIdx = yaml.lastIndexOf(' prompt:');
118
+ expect(promptIdx).toBeGreaterThan(yaml.lastIndexOf(' agent:'));
119
+ expect(promptIdx).toBeGreaterThan(yaml.lastIndexOf(' files:'));
120
+ expect(promptIdx).toBeGreaterThan(yaml.lastIndexOf(' description:'));
121
+ });
122
+ // ── complexity effort-scaling integration ────────────────────────────────────
123
+ it('auto-populates timeout, max_retries, review from effort table when complexity is set', () => {
124
+ const task = build({ name: 'E', tasks: [{ id: 'task-1', complexity: 3, prompt: 'Do something' }] }).tasks[0];
125
+ expect(task.timeout).toBe('15m');
126
+ expect(task.max_retries).toBe(2);
127
+ expect(task.review).toBe('fast');
128
+ });
129
+ it('does not override explicitly set fields when complexity is also set', () => {
130
+ const tasks = [
131
+ { id: 't1', complexity: 3, timeout: '1h', prompt: 'x' },
132
+ { id: 't2', complexity: 5, max_retries: 5, prompt: 'x' },
133
+ { id: 't3', complexity: 8, review: 'panel', prompt: 'x' },
134
+ ];
135
+ const parsed = build({ name: 'E', tasks });
136
+ expect(parsed.tasks[0].timeout).toBe('1h');
137
+ expect(parsed.tasks[1].max_retries).toBe(5);
138
+ expect(parsed.tasks[2].review).toBe('panel');
139
+ });
140
+ it('uses complexity-13 profile for epic tasks', () => {
141
+ const task = build({ name: 'E', tasks: [{ id: 'task-1', complexity: 13, prompt: 'Epic task' }] }).tasks[0];
142
+ expect(task.timeout).toBe('45m');
143
+ expect(task.max_retries).toBe(3);
144
+ expect(task.review).toBe('panel');
145
+ });
146
+ });
147
+ // ── Project checks ─────────────────────────────────────────────────────────────
148
+ describe('detectPackageManager', () => {
149
+ it('reads the packageManager field first', () => {
150
+ const dir = project({ 'package.json': JSON.stringify({ packageManager: 'yarn@4.1.0' }), 'pnpm-lock.yaml': '' });
151
+ expect(detectPackageManager(dir)).toBe('yarn');
152
+ });
153
+ it.each([
154
+ ['pnpm-lock.yaml', 'pnpm'],
155
+ ['yarn.lock', 'yarn'],
156
+ ['bun.lockb', 'bun'],
157
+ ['bun.lock', 'bun'],
158
+ ['package-lock.json', 'npm'],
159
+ ])('falls back to the lockfile: %s → %s', (lockfile, pm) => {
160
+ expect(detectPackageManager(project({ 'package.json': '{}', [lockfile]: '' }))).toBe(pm);
161
+ });
162
+ it('defaults to npm', () => {
163
+ expect(detectPackageManager(project({}))).toBe('npm');
164
+ });
165
+ });
166
+ describe('detectGates', () => {
167
+ it('runs typecheck, lint, test and build with the project package manager, cheapest first', () => {
168
+ const dir = project({
169
+ 'package.json': JSON.stringify({
170
+ scripts: { build: 'tsc -b', test: 'vitest run', lint: 'eslint .', typecheck: 'tsc --noEmit', dev: 'vite' },
171
+ }),
172
+ 'pnpm-lock.yaml': '',
173
+ });
174
+ expect(detectGates(dir)).toEqual(['pnpm run typecheck', 'pnpm run lint', 'pnpm run test', 'pnpm run build']);
175
+ });
176
+ it('accepts type-check as the typecheck script', () => {
177
+ const dir = project({ 'package.json': JSON.stringify({ scripts: { 'type-check': 'tsc' } }) });
178
+ expect(detectGates(dir)).toEqual(['npm run type-check']);
179
+ });
180
+ it('skips the npm init placeholder and watchers', () => {
181
+ const dir = project({
182
+ 'package.json': JSON.stringify({
183
+ scripts: { test: 'echo "Error: no test specified" && exit 1', lint: 'eslint . --watch' },
184
+ }),
185
+ });
186
+ expect(detectGates(dir)).toEqual([]);
187
+ });
188
+ it('returns nothing without a package.json, or with an unreadable one', () => {
189
+ expect(detectGates(project({}))).toEqual([]);
190
+ expect(detectGates(project({ 'package.json': '{ nope' }))).toEqual([]);
191
+ });
192
+ });
193
+ // ── planConcurrency ────────────────────────────────────────────────────────────
194
+ describe('planConcurrency', () => {
195
+ it('is 1 for a straight chain', () => {
116
196
  const plan = {
117
- name: 'My Feature',
197
+ name: 'c',
118
198
  tasks: [
119
- { id: 'other-task', prompt: 'Other task' },
120
- fullTask(),
199
+ { id: 'a', prompt: 'a' },
200
+ { id: 'b', prompt: 'b', depends_on: ['a'] },
201
+ { id: 'c', prompt: 'c', depends_on: ['b'] },
121
202
  ],
122
203
  };
123
- const yaml = buildConvoyYaml(plan);
124
- // find last occurrence of prompt: which belongs to the full-task
125
- const agentIdx = yaml.lastIndexOf(' agent:');
126
- const filesIdx = yaml.lastIndexOf(' files:');
127
- const descIdx = yaml.lastIndexOf(' description:');
128
- const promptIdx = yaml.lastIndexOf(' prompt:');
129
- expect(promptIdx).toBeGreaterThan(agentIdx);
130
- expect(promptIdx).toBeGreaterThan(filesIdx);
131
- expect(promptIdx).toBeGreaterThan(descIdx);
204
+ expect(planConcurrency(plan)).toBe(1);
132
205
  });
133
- it('output can be parsed back and produces a valid spec (round-trip)', () => {
206
+ it('is the widest level of a diamond', () => {
134
207
  const plan = {
135
- name: 'Round Trip Test',
136
- concurrency: 3,
137
- on_failure: 'continue',
138
- branch: 'feat/round-trip',
139
- gates: ['custom'],
140
- gate_retries: 1,
208
+ name: 'd',
141
209
  tasks: [
142
- { id: 'task-a', prompt: 'First task' },
143
- { id: 'task-b', depends_on: ['task-a'], prompt: 'Second task', agent: 'ui-expert' },
210
+ { id: 'a', prompt: 'a' },
211
+ { id: 'b', prompt: 'b', depends_on: ['a'] },
212
+ { id: 'c', prompt: 'c', depends_on: ['a'] },
213
+ { id: 'd', prompt: 'd', depends_on: ['b', 'c'] },
144
214
  ],
145
215
  };
146
- const yaml = buildConvoyYaml(plan);
147
- const spec = parseYaml(yaml);
148
- const result = validateSpec(spec);
149
- expect(result.valid).toBe(true);
150
- expect(result.errors).toEqual([]);
216
+ expect(planConcurrency(plan)).toBe(2);
151
217
  });
152
- it('round-trip with minimal plan passes validateSpec', () => {
153
- const yaml = buildConvoyYaml(minimalPlan());
154
- const result = validateSpec(parseYaml(yaml));
155
- expect(result.valid).toBe(true);
156
- expect(result.errors).toEqual([]);
218
+ it('is capped', () => {
219
+ const plan = { name: 'w', tasks: Array.from({ length: 9 }, (_, i) => ({ id: `t${i}`, prompt: 'x' })) };
220
+ expect(planConcurrency(plan)).toBe(MAX_PLANNED_CONCURRENCY);
157
221
  });
158
- it('merges enrichment into defaults and spec', () => {
159
- const enrichment = {
160
- guard: { enabled: true },
161
- circuit_breaker: { threshold: 2, cooldown_ms: 300_000 },
162
- detect_drift: true,
163
- built_in_gates: { secret_scan: true, blast_radius: true, browser_test: 'auto' },
164
- max_concurrent_reviews: 3,
222
+ });
223
+ // ── Files ──────────────────────────────────────────────────────────────────────
224
+ describe('normalizePlanFiles', () => {
225
+ it('cuts a glob back to the directory before its first wildcard', () => {
226
+ const plan = {
227
+ name: 'g',
228
+ tasks: [{ id: 't', prompt: 'x', files: ['src/**/*.ts', 'components/*.tsx', 'docs/guide?.md'] }],
165
229
  };
166
- const yaml = buildConvoyYaml(minimalPlan(), enrichment);
167
- const parsed = yamlParse(yaml);
168
- expect(parsed.guard).toEqual({ enabled: true });
169
- expect(parsed.defaults.circuit_breaker).toEqual({ threshold: 2, cooldown_ms: 300000 });
170
- expect(parsed.defaults.detect_drift).toBe(true);
171
- expect(parsed.defaults.built_in_gates.secret_scan).toBe(true);
172
- expect(parsed.defaults.built_in_gates.browser_test).toBe('auto');
173
- expect(parsed.defaults.max_concurrent_reviews).toBe(3);
174
- });
175
- it('omits enrichment fields when enrichment is not provided', () => {
176
- const yaml = buildConvoyYaml(minimalPlan());
177
- const parsed = yamlParse(yaml);
178
- expect(parsed.guard).toBeUndefined();
179
- expect(parsed.defaults.circuit_breaker).toBeUndefined();
180
- expect(parsed.defaults.detect_drift).toBeUndefined();
181
- expect(parsed.defaults.built_in_gates).toBeUndefined();
182
- expect(parsed.defaults.max_concurrent_reviews).toBeUndefined();
230
+ const { plan: out, notes } = normalizePlanFiles(plan);
231
+ expect(out.tasks[0].files).toEqual(['src/', 'components/', 'docs/']);
232
+ expect(notes).toHaveLength(3);
233
+ });
234
+ it('drops a pattern at the project root instead of claiming everything', () => {
235
+ const { plan, notes } = normalizePlanFiles({ name: 'g', tasks: [{ id: 't', prompt: 'x', files: ['*.md', 'README.md'] }] });
236
+ expect(plan.tasks[0].files).toEqual(['README.md']);
237
+ expect(notes[0]).toContain('dropped');
183
238
  });
184
- it('enriched plan still passes round-trip validation', () => {
185
- const enrichment = deriveSpecEnrichment({ complexity: 'high', total_tasks: 10, domains: ['frontend', 'api'] });
239
+ it('leaves real paths alone, including bracketed route segments, and removes duplicates', () => {
240
+ const files = ['app/[slug]/page.tsx', 'src/a.ts', 'src/a.ts'];
241
+ const { plan, notes } = normalizePlanFiles({ name: 'g', tasks: [{ id: 't', prompt: 'x', files }] });
242
+ expect(plan.tasks[0].files).toEqual(['app/[slug]/page.tsx', 'src/a.ts']);
243
+ expect(notes).toEqual([]);
244
+ });
245
+ });
246
+ // ── checkPlan ──────────────────────────────────────────────────────────────────
247
+ describe('checkPlan', () => {
248
+ it('passes a sound plan', () => {
186
249
  const plan = {
187
- name: 'Enriched Round Trip',
188
- branch: 'feat/enriched',
250
+ name: 'ok',
189
251
  tasks: [
190
- { id: 'task-a', prompt: 'First task' },
191
- { id: 'task-b', depends_on: ['task-a'], prompt: 'Second task' },
252
+ { id: 'a', prompt: 'a', files: ['src/a.ts'] },
253
+ { id: 'b', prompt: 'b', files: ['src/b.ts'] },
254
+ { id: 'c', prompt: 'c', files: ['src/a.ts'], depends_on: ['a'] },
192
255
  ],
193
256
  };
194
- const yaml = buildConvoyYaml(plan, enrichment);
195
- const spec = parseYaml(yaml);
196
- const result = validateSpec(spec);
197
- expect(result.valid).toBe(true);
198
- expect(result.errors).toEqual([]);
257
+ expect(checkPlan(plan, SETTINGS)).toEqual([]);
199
258
  });
200
- // ── complexity effort-scaling integration ────────────────────────────────────
201
- it('auto-populates timeout, max_retries, review from effort table when complexity is set', () => {
259
+ it('reports two tasks that can run together and claim the same file', () => {
202
260
  const plan = {
203
- name: 'Effort Test',
204
- tasks: [{ id: 'task-1', complexity: 3, prompt: 'Do something' }],
261
+ name: 'x',
262
+ tasks: [
263
+ { id: 'a', prompt: 'a', files: ['src/components/'] },
264
+ { id: 'b', prompt: 'b', files: ['src/components/Hero.tsx'] },
265
+ ],
205
266
  };
206
- const parsed = yamlParse(buildConvoyYaml(plan));
207
- const task = parsed.tasks[0];
208
- expect(task.timeout).toBe('15m');
209
- expect(task.max_retries).toBe(2);
210
- expect(task.review).toBe('fast');
267
+ const problems = checkPlan(plan, SETTINGS);
268
+ expect(problems).toHaveLength(1);
269
+ expect(problems[0]).toContain('"a" and "b"');
211
270
  });
212
- it('does not override explicitly set timeout when complexity is also set', () => {
271
+ it('counts a conflict across phases when nothing orders the two tasks', () => {
272
+ // The engine compares phase by phase: b (phase 1) and c (phase 0) passed.
273
+ // A scheduler that starts work as soon as it is ready can run them together.
213
274
  const plan = {
214
- name: 'Effort Override Test',
215
- tasks: [{ id: 'task-1', complexity: 3, timeout: '1h', prompt: 'Do something' }],
275
+ name: 'x',
276
+ tasks: [
277
+ { id: 'a', prompt: 'a' },
278
+ { id: 'b', prompt: 'b', depends_on: ['a'], files: ['src/shared.ts'] },
279
+ { id: 'c', prompt: 'c', files: ['src/shared.ts'] },
280
+ ],
216
281
  };
217
- const parsed = yamlParse(buildConvoyYaml(plan));
218
- expect(parsed.tasks[0].timeout).toBe('1h');
282
+ expect(checkPlan(plan, SETTINGS)).toHaveLength(1);
219
283
  });
220
- it('does not override explicitly set max_retries when complexity is also set', () => {
284
+ it('accepts shared files when one task waits for the other through a third', () => {
221
285
  const plan = {
222
- name: 'Effort Override Test',
223
- tasks: [{ id: 'task-1', complexity: 5, max_retries: 5, prompt: 'Do something' }],
286
+ name: 'x',
287
+ tasks: [
288
+ { id: 'a', prompt: 'a', files: ['src/shared.ts'] },
289
+ { id: 'b', prompt: 'b', depends_on: ['a'] },
290
+ { id: 'c', prompt: 'c', depends_on: ['b'], files: ['src/shared.ts'] },
291
+ ],
224
292
  };
225
- const parsed = yamlParse(buildConvoyYaml(plan));
226
- expect(parsed.tasks[0].max_retries).toBe(5);
293
+ expect(checkPlan(plan, SETTINGS)).toEqual([]);
227
294
  });
228
- it('does not override explicitly set review when complexity is also set', () => {
295
+ it('compares paths without regard to case', () => {
229
296
  const plan = {
230
- name: 'Effort Override Test',
231
- tasks: [{ id: 'task-1', complexity: 8, review: 'panel', prompt: 'Do something' }],
297
+ name: 'x',
298
+ tasks: [
299
+ { id: 'a', prompt: 'a', files: ['README.md'] },
300
+ { id: 'b', prompt: 'b', files: ['readme.md'] },
301
+ ],
232
302
  };
233
- const parsed = yamlParse(buildConvoyYaml(plan));
234
- expect(parsed.tasks[0].review).toBe('panel');
303
+ expect(checkPlan(plan, SETTINGS)).toHaveLength(1);
235
304
  });
236
- it('works unchanged (backward compatible) when complexity is not set', () => {
237
- const parsed = yamlParse(buildConvoyYaml(minimalPlan()));
238
- const task = parsed.tasks[0];
239
- expect(task.timeout).toBeUndefined();
240
- expect(task.max_retries).toBeUndefined();
241
- expect(task.review).toBeUndefined();
305
+ it('reports globs, absolute paths and paths that leave the project', () => {
306
+ const plan = {
307
+ name: 'x',
308
+ tasks: [{ id: 'a', prompt: 'a', files: ['src/*.ts', '/etc/hosts', 'C:\\x', '../outside.ts'] }],
309
+ };
310
+ const problems = checkPlan(plan, SETTINGS).join('\n');
311
+ expect(problems).toContain('"src/*.ts" is a pattern');
312
+ expect(problems).toContain('"/etc/hosts" must be relative');
313
+ expect(problems).toContain('"C:\\x" must be relative');
314
+ expect(problems).toContain('..');
315
+ });
316
+ it('reports what the runner would reject, such as a bad timeout', () => {
317
+ const problems = checkPlan({ name: 'x', tasks: [{ id: 'a', prompt: 'a', timeout: 'soon' }] }, SETTINGS);
318
+ expect(problems.join('\n')).toContain('Schema:');
319
+ });
320
+ it('reports unknown dependencies and cycles', () => {
321
+ expect(checkPlan({ name: 'x', tasks: [{ id: 'a', prompt: 'a', depends_on: ['ghost'] }] }, SETTINGS)[0]).toContain('ghost');
322
+ const cycle = {
323
+ name: 'x',
324
+ tasks: [
325
+ { id: 'a', prompt: 'a', depends_on: ['b'] },
326
+ { id: 'b', prompt: 'b', depends_on: ['a'] },
327
+ ],
328
+ };
329
+ expect(checkPlan(cycle, SETTINGS)[0]).toContain('cycle');
242
330
  });
243
- it('uses complexity-13 profile for epic tasks', () => {
331
+ });
332
+ describe('sequenceConflicts', () => {
333
+ it('makes the later task wait for the earlier, leaving a plan that passes', () => {
244
334
  const plan = {
245
- name: 'Epic Test',
246
- tasks: [{ id: 'task-1', complexity: 13, prompt: 'Epic task' }],
335
+ name: 'x',
336
+ tasks: [
337
+ { id: 'a', prompt: 'a', files: ['src/components/'] },
338
+ { id: 'b', prompt: 'b', files: ['src/components/Hero.tsx'] },
339
+ { id: 'c', prompt: 'c', files: ['src/components/Card.tsx'] },
340
+ { id: 'd', prompt: 'd', files: ['src/other.ts'] },
341
+ ],
247
342
  };
248
- const parsed = yamlParse(buildConvoyYaml(plan));
249
- const task = parsed.tasks[0];
250
- expect(task.timeout).toBe('45m');
251
- expect(task.max_retries).toBe(3);
252
- expect(task.review).toBe('panel');
343
+ const { plan: out, added } = sequenceConflicts(plan);
344
+ expect(checkPlan(out, SETTINGS)).toEqual([]);
345
+ expect(added.length).toBeGreaterThan(0);
346
+ expect(out.tasks.find((t) => t.id === 'd').depends_on ?? []).toEqual([]);
347
+ expect(parseTaskPlan(JSON.stringify(out))).not.toBeNull(); // still acyclic
348
+ expect(plan.tasks[1].depends_on).toBeUndefined(); // input untouched
349
+ });
350
+ it('changes nothing when there is no conflict', () => {
351
+ expect(sequenceConflicts(minimalPlan()).added).toEqual([]);
352
+ });
353
+ });
354
+ // ── mergeGroupPlans ────────────────────────────────────────────────────────────
355
+ describe('mergeGroupPlans', () => {
356
+ const group = (name, prefix) => ({
357
+ name,
358
+ tasks: [
359
+ { id: 'setup', prompt: `set up ${name}`, files: [`${prefix}/setup.ts`] },
360
+ { id: `work-${name}`, prompt: `work ${name}`, files: [`${prefix}/work.ts`], depends_on: ['setup'] },
361
+ ],
362
+ });
363
+ const merged = mergeGroupPlans('Feature', [
364
+ { name: 'theme', depends_on: [], plan: group('theme', 'src/theme') },
365
+ { name: 'docs', depends_on: [], plan: group('docs', 'docs') },
366
+ { name: 'ui', depends_on: ['theme', 'docs'], plan: group('ui', 'src/ui') },
367
+ ]);
368
+ const byId = new Map(merged.tasks.map((t) => [t.id, t]));
369
+ it('renames a clashing id within its own group', () => {
370
+ expect([...byId.keys()]).toEqual(['setup', 'work-theme', 'docs-setup', 'work-docs', 'ui-setup', 'work-ui']);
371
+ expect(byId.get('work-docs').depends_on).toEqual(['docs-setup']);
372
+ });
373
+ it('makes a group start after the last tasks of the groups it depends on', () => {
374
+ expect(byId.get('ui-setup').depends_on).toEqual(['work-theme', 'work-docs']);
375
+ expect(byId.get('work-ui').depends_on).toEqual(['ui-setup']);
376
+ });
377
+ it('adds nothing between independent groups, so they run side by side', () => {
378
+ expect(byId.get('setup').depends_on).toEqual([]);
379
+ expect(byId.get('docs-setup').depends_on).toEqual([]);
380
+ expect(planConcurrency(merged)).toBe(2);
381
+ });
382
+ it('is one plan that passes the checks and writes plain YAML', () => {
383
+ expect(merged.name).toBe('Feature');
384
+ expect(checkPlan(merged, SETTINGS)).toEqual([]);
385
+ expect(buildConvoyYaml(merged, SETTINGS)).not.toMatch(/[&*]a\d/);
386
+ });
387
+ });
388
+ describe('slugify', () => {
389
+ it('kebab-cases a name', () => {
390
+ expect(slugify('My Big Feature 2!')).toBe('my-big-feature-2');
253
391
  });
254
392
  });
255
393
  // ── applyPatches ──────────────────────────────────────────────────────────────
256
394
  describe('applyPatches', () => {
257
395
  it('patches a task-level field (prompt)', () => {
258
- const plan = minimalPlan();
259
- const patched = applyPatches(plan, [
260
- { task_id: 'task-1', field: 'prompt', value: 'Updated prompt' },
261
- ]);
396
+ const patched = applyPatches(minimalPlan(), [{ task_id: 'task-1', field: 'prompt', value: 'Updated prompt' }]);
262
397
  expect(patched.tasks[0].prompt).toBe('Updated prompt');
263
398
  });
264
399
  it('patches task depends_on', () => {
265
- const plan = {
266
- name: 'Test',
267
- tasks: [
268
- { id: 'task-1', prompt: 'First' },
269
- { id: 'task-2', prompt: 'Second' },
270
- ],
271
- };
272
- const patched = applyPatches(plan, [
273
- { task_id: 'task-2', field: 'depends_on', value: ['task-1'] },
274
- ]);
400
+ const plan = { name: 'Test', tasks: [{ id: 'task-1', prompt: 'First' }, { id: 'task-2', prompt: 'Second' }] };
401
+ const patched = applyPatches(plan, [{ task_id: 'task-2', field: 'depends_on', value: ['task-1'] }]);
275
402
  expect(patched.tasks[1].depends_on).toEqual(['task-1']);
276
403
  });
277
- it('patches a top-level field using _plan task_id', () => {
278
- const plan = minimalPlan();
279
- const patched = applyPatches(plan, [
280
- { task_id: '_plan', field: 'concurrency', value: 5 },
281
- ]);
282
- expect(patched.concurrency).toBe(5);
283
- });
284
- it('patches a top-level string field (_plan)', () => {
285
- const plan = minimalPlan();
286
- const patched = applyPatches(plan, [
287
- { task_id: '_plan', field: 'branch', value: 'feat/patched-branch' },
288
- ]);
289
- expect(patched.branch).toBe('feat/patched-branch');
290
- });
291
- it('leaves task unchanged when task id does not exist', () => {
292
- const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => { });
293
- const plan = minimalPlan();
294
- const patched = applyPatches(plan, [
295
- { task_id: 'nonexistent', field: 'prompt', value: 'x' },
296
- ]);
297
- expect(patched.tasks[0].prompt).toBe('Do something useful');
298
- warnSpy.mockRestore();
404
+ it('renames the plan through _plan', () => {
405
+ const patched = applyPatches(minimalPlan(), [{ task_id: '_plan', field: 'name', value: 'Renamed' }]);
406
+ expect(patched.name).toBe('Renamed');
299
407
  });
300
408
  it('returns a new object (original plan unchanged)', () => {
301
409
  const plan = minimalPlan();
302
- const patched = applyPatches(plan, [
303
- { task_id: 'task-1', field: 'prompt', value: 'New prompt' },
304
- ]);
410
+ const patched = applyPatches(plan, [{ task_id: 'task-1', field: 'prompt', value: 'New prompt' }]);
305
411
  expect(patched).not.toBe(plan);
306
412
  expect(plan.tasks[0].prompt).toBe('Do something useful');
307
413
  });
308
414
  it('applies multiple patches in order', () => {
309
- const plan = {
310
- name: 'Test',
311
- tasks: [
312
- { id: 'task-1', prompt: 'First' },
313
- { id: 'task-2', prompt: 'Second' },
314
- ],
315
- };
415
+ const plan = { name: 'Test', tasks: [{ id: 'task-1', prompt: 'First' }, { id: 'task-2', prompt: 'Second' }] };
316
416
  const patches = [
317
417
  { task_id: 'task-1', field: 'prompt', value: 'Patched first' },
318
- { task_id: 'task-2', field: 'agent', value: 'ui-expert' },
319
- { task_id: '_plan', field: 'on_failure', value: 'continue' },
418
+ { task_id: 'task-2', field: 'agent', value: 'ui-ux-expert' },
419
+ { task_id: 'task-2', field: 'agent', value: 'writer' },
320
420
  ];
321
421
  const patched = applyPatches(plan, patches);
322
422
  expect(patched.tasks[0].prompt).toBe('Patched first');
323
- expect(patched.tasks[1].agent).toBe('ui-expert');
324
- expect(patched.on_failure).toBe('continue');
423
+ expect(patched.tasks[1].agent).toBe('writer');
325
424
  });
326
- it('warns when patch targets unknown task_id', () => {
327
- const plan = {
328
- name: 'test',
329
- tasks: [{ id: 'task-1', prompt: 'do something' }],
330
- };
331
- const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => { });
332
- const result = applyPatches(plan, [
333
- { task_id: 'nonexistent', field: 'prompt', value: 'new prompt' },
334
- ]);
335
- expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('nonexistent'));
336
- // Original task unchanged
337
- expect(result.tasks[0].prompt).toBe('do something');
338
- warnSpy.mockRestore();
339
- });
340
- it('applies valid patches and warns for invalid ones', () => {
341
- const plan = {
342
- name: 'test',
343
- tasks: [
344
- { id: 'task-1', prompt: 'original' },
345
- { id: 'task-2', prompt: 'original2' },
346
- ],
347
- };
425
+ it('warns about, and skips, a patch for an unknown task', () => {
348
426
  const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => { });
427
+ const plan = { name: 'test', tasks: [{ id: 'task-1', prompt: 'original' }] };
349
428
  const result = applyPatches(plan, [
350
429
  { task_id: 'task-1', field: 'prompt', value: 'updated' },
351
430
  { task_id: 'ghost', field: 'prompt', value: 'nope' },
@@ -355,14 +434,8 @@ describe('applyPatches', () => {
355
434
  warnSpy.mockRestore();
356
435
  });
357
436
  it('does not warn when all patches target valid tasks', () => {
358
- const plan = {
359
- name: 'test',
360
- tasks: [{ id: 'task-1', prompt: 'original' }],
361
- };
362
437
  const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => { });
363
- applyPatches(plan, [
364
- { task_id: 'task-1', field: 'prompt', value: 'updated' },
365
- ]);
438
+ applyPatches(minimalPlan(), [{ task_id: 'task-1', field: 'prompt', value: 'updated' }]);
366
439
  expect(warnSpy).not.toHaveBeenCalled();
367
440
  warnSpy.mockRestore();
368
441
  });
@@ -370,111 +443,44 @@ describe('applyPatches', () => {
370
443
  // ── parseTaskPlan ──────────────────────────────────────────────────────────────
371
444
  describe('parseTaskPlan', () => {
372
445
  it('parses a valid plan successfully', () => {
373
- const json = JSON.stringify({
374
- name: 'My Plan',
375
- tasks: [{ id: 'task-1', prompt: 'Do the thing' }],
376
- });
377
- const result = parseTaskPlan(json);
378
- expect(result).not.toBeNull();
446
+ const result = parseTaskPlan(JSON.stringify({ name: 'My Plan', tasks: [{ id: 'task-1', prompt: 'Do the thing' }] }));
379
447
  expect(result.name).toBe('My Plan');
380
448
  expect(result.tasks).toHaveLength(1);
381
449
  });
382
- it('parses a plan with all optional fields', () => {
383
- const json = JSON.stringify({
384
- name: 'Full Plan',
385
- branch: 'feat/full',
386
- concurrency: 3,
387
- on_failure: 'continue',
388
- gates: ['lint'],
389
- gate_retries: 2,
390
- tasks: [{ id: 't1', prompt: 'prompt', agent: 'developer', files: ['a.ts'] }],
391
- });
392
- const result = parseTaskPlan(json);
393
- expect(result).not.toBeNull();
394
- expect(result.branch).toBe('feat/full');
395
- expect(result.concurrency).toBe(3);
396
- });
397
- it('returns null for empty string', () => {
398
- expect(parseTaskPlan('')).toBeNull();
399
- });
400
- it('returns null for invalid JSON', () => {
401
- expect(parseTaskPlan('{not valid json')).toBeNull();
402
- });
403
- it('returns null when name is missing', () => {
404
- const json = JSON.stringify({ tasks: [{ id: 't1', prompt: 'p' }] });
405
- expect(parseTaskPlan(json)).toBeNull();
406
- });
407
- it('returns null when name is not a string', () => {
408
- const json = JSON.stringify({ name: 42, tasks: [{ id: 't1', prompt: 'p' }] });
409
- expect(parseTaskPlan(json)).toBeNull();
410
- });
411
- it('returns null for empty tasks array', () => {
412
- const json = JSON.stringify({ name: 'Test', tasks: [] });
413
- expect(parseTaskPlan(json)).toBeNull();
414
- });
415
- it('returns null when tasks is missing', () => {
416
- const json = JSON.stringify({ name: 'Test' });
417
- expect(parseTaskPlan(json)).toBeNull();
418
- });
419
- it('returns null for task missing id', () => {
420
- const json = JSON.stringify({ name: 'Test', tasks: [{ prompt: 'p' }] });
421
- expect(parseTaskPlan(json)).toBeNull();
422
- });
423
- it('returns null for task missing prompt', () => {
424
- const json = JSON.stringify({ name: 'Test', tasks: [{ id: 't1' }] });
425
- expect(parseTaskPlan(json)).toBeNull();
426
- });
427
- it('returns null for task with non-string id', () => {
428
- const json = JSON.stringify({ name: 'Test', tasks: [{ id: 1, prompt: 'p' }] });
429
- expect(parseTaskPlan(json)).toBeNull();
430
- });
431
- it('returns null when JSON is surrounded by text', () => {
432
- const json = JSON.stringify({ name: 'Test', tasks: [{ id: 't1', prompt: 'p' }] });
433
- const wrapped = `Here is the plan:\n${json}\nHope this helps!`;
434
- expect(parseTaskPlan(wrapped)).toBeNull();
435
- });
436
- it('returns null when trailing garbage present', () => {
437
- const json = JSON.stringify({ name: 'Test', tasks: [{ id: 't1', prompt: 'p' }] });
438
- const withTrailing = json + '\n```\nSome extra text';
439
- expect(parseTaskPlan(withTrailing)).toBeNull();
450
+ it('ignores run settings a planner adds, which the code decides', () => {
451
+ const json = JSON.stringify({ name: 'P', branch: 'main', on_failure: 'stop', tasks: [{ id: 't1', prompt: 'p' }] });
452
+ const plan = parseTaskPlan(json);
453
+ const parsed = build(plan);
454
+ expect(parsed.branch).toBe(SETTINGS.branch);
455
+ expect(parsed.on_failure).toBe('continue');
440
456
  });
441
- it('returns null for duplicate task IDs', () => {
457
+ it.each([
458
+ ['empty string', ''],
459
+ ['invalid JSON', '{not valid json'],
460
+ ['missing name', JSON.stringify({ tasks: [{ id: 't1', prompt: 'p' }] })],
461
+ ['non-string name', JSON.stringify({ name: 42, tasks: [{ id: 't1', prompt: 'p' }] })],
462
+ ['empty tasks', JSON.stringify({ name: 'Test', tasks: [] })],
463
+ ['missing tasks', JSON.stringify({ name: 'Test' })],
464
+ ['task missing id', JSON.stringify({ name: 'Test', tasks: [{ prompt: 'p' }] })],
465
+ ['task missing prompt', JSON.stringify({ name: 'Test', tasks: [{ id: 't1' }] })],
466
+ ['non-string id', JSON.stringify({ name: 'Test', tasks: [{ id: 1, prompt: 'p' }] })],
467
+ ['surrounding text', `Here is the plan:\n${JSON.stringify({ name: 'T', tasks: [{ id: 't', prompt: 'p' }] })}\nHope this helps!`],
468
+ ])('returns null for %s', (_label, text) => {
442
469
  const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => { });
443
- const plan = JSON.stringify({
444
- name: 'test',
445
- tasks: [
446
- { id: 'setup', prompt: 'Do setup' },
447
- { id: 'setup', prompt: 'Do setup again' },
448
- ],
449
- });
450
- expect(parseTaskPlan(plan)).toBeNull();
451
- expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('setup'));
470
+ expect(parseTaskPlan(text)).toBeNull();
452
471
  warnSpy.mockRestore();
453
472
  });
454
- it('returns null for invalid depends_on reference', () => {
455
- const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => { });
456
- const plan = JSON.stringify({
457
- name: 'test',
458
- tasks: [
459
- { id: 'a', prompt: 'Do A' },
460
- { id: 'b', prompt: 'Do B', depends_on: ['nonexistent'] },
461
- ],
462
- });
463
- expect(parseTaskPlan(plan)).toBeNull();
464
- expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('nonexistent'));
465
- warnSpy.mockRestore();
473
+ it('names duplicate ids, unknown dependencies and cycles in the reason', () => {
474
+ const dup = parseTaskPlanWithReason(JSON.stringify({ name: 't', tasks: [{ id: 'setup', prompt: 'a' }, { id: 'setup', prompt: 'b' }] }));
475
+ expect(dup.reason).toContain('setup');
476
+ const unknown = parseTaskPlanWithReason(JSON.stringify({ name: 't', tasks: [{ id: 'b', prompt: 'b', depends_on: ['nonexistent'] }] }));
477
+ expect(unknown.reason).toContain('nonexistent');
478
+ const cycle = parseTaskPlanWithReason(JSON.stringify({ name: 't', tasks: [{ id: 'a', prompt: 'a', depends_on: ['b'] }, { id: 'b', prompt: 'b', depends_on: ['a'] }] }));
479
+ expect(cycle.reason).toContain('cycle');
466
480
  });
467
- it('returns null for dependency cycle', () => {
481
+ it('reports a truncated answer as truncated', () => {
468
482
  const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => { });
469
- const plan = JSON.stringify({
470
- name: 'test',
471
- tasks: [
472
- { id: 'a', prompt: 'Do A', depends_on: ['b'] },
473
- { id: 'b', prompt: 'Do B', depends_on: ['a'] },
474
- ],
475
- });
476
- expect(parseTaskPlan(plan)).toBeNull();
477
- expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('cycle'));
483
+ expect(parseTaskPlanWithReason('{ "name": "x", "tasks": [').reason).toContain('truncated');
478
484
  warnSpy.mockRestore();
479
485
  });
480
486
  it('accepts valid plan with correct dependencies', () => {
@@ -486,9 +492,7 @@ describe('parseTaskPlan', () => {
486
492
  { id: 'c', prompt: 'Do C', depends_on: ['a', 'b'] },
487
493
  ],
488
494
  });
489
- const result = parseTaskPlan(plan);
490
- expect(result).not.toBeNull();
491
- expect(result.tasks).toHaveLength(3);
495
+ expect(parseTaskPlan(plan).tasks).toHaveLength(3);
492
496
  });
493
497
  });
494
498
  // ── parsePatches ──────────────────────────────────────────────────────────────
@@ -496,106 +500,86 @@ describe('parsePatches', () => {
496
500
  it('parses a valid patches array successfully', () => {
497
501
  const json = JSON.stringify([
498
502
  { task_id: 'task-1', field: 'prompt', value: 'New prompt' },
499
- { task_id: '_plan', field: 'concurrency', value: 3 },
503
+ { task_id: '_plan', field: 'name', value: 'Renamed' },
500
504
  ]);
501
505
  const result = parsePatches(json);
502
- expect(result).not.toBeNull();
503
506
  expect(result).toHaveLength(2);
504
507
  expect(result[0].task_id).toBe('task-1');
505
- expect(result[1].value).toBe(3);
508
+ expect(result[1].value).toBe('Renamed');
506
509
  });
507
510
  it('parses empty array', () => {
508
- const result = parsePatches('[]');
509
- expect(result).not.toBeNull();
510
- expect(result).toHaveLength(0);
511
- });
512
- it('returns null for non-array JSON', () => {
513
- expect(parsePatches(JSON.stringify({ task_id: 't1', field: 'f', value: 'v' }))).toBeNull();
511
+ expect(parsePatches('[]')).toEqual([]);
512
+ });
513
+ it.each([
514
+ ['non-array JSON', JSON.stringify({ task_id: 't1', field: 'f', value: 'v' })],
515
+ ['invalid JSON', '{bad'],
516
+ ['empty string', ''],
517
+ ['missing task_id', JSON.stringify([{ field: 'prompt', value: 'x' }])],
518
+ ['missing field', JSON.stringify([{ task_id: 'task-1', value: 'x' }])],
519
+ ['missing value', JSON.stringify([{ task_id: 'task-1', field: 'prompt' }])],
520
+ ['one bad patch among good', JSON.stringify([{ task_id: 'a', field: 'prompt', value: 'ok' }, { task_id: 'b', field: 'prompt' }])],
521
+ ])('returns null for %s', (_label, text) => {
522
+ expect(parsePatches(text)).toBeNull();
514
523
  });
515
- it('returns null for invalid JSON', () => {
516
- expect(parsePatches('{bad')).toBeNull();
517
- });
518
- it('returns null for empty string', () => {
519
- expect(parsePatches('')).toBeNull();
520
- });
521
- it('returns null for patch missing task_id', () => {
522
- const json = JSON.stringify([{ field: 'prompt', value: 'x' }]);
523
- expect(parsePatches(json)).toBeNull();
524
- });
525
- it('returns null for patch missing field', () => {
526
- const json = JSON.stringify([{ task_id: 'task-1', value: 'x' }]);
527
- expect(parsePatches(json)).toBeNull();
524
+ });
525
+ describe('foldTestOnlyTasks', () => {
526
+ const t = (id, files, depends_on = [], agent = 'developer') => ({ id, agent, files, depends_on, prompt: `do ${id}` });
527
+ it('folds a test-only task into the task it tests, as three real plans split them', () => {
528
+ // The plan a real run produced for pagination and DELETE /notes.
529
+ const { plan, folded } = foldTestOnlyTasks({
530
+ name: 'x',
531
+ tasks: [
532
+ t('store', ['src/notes.js']),
533
+ t('routes', ['src/server.js'], ['store']),
534
+ t('unit-tests', ['test/notes.test.js'], ['store'], 'testing-expert'),
535
+ t('http-tests', ['test/server.test.js'], ['routes'], 'testing-expert'),
536
+ ],
537
+ });
538
+ expect(folded).toEqual([['unit-tests', 'store'], ['http-tests', 'routes']]);
539
+ expect(plan.tasks.map((x) => x.id)).toEqual(['store', 'routes']);
540
+ expect(plan.tasks[0]).toMatchObject({ files: ['src/notes.js', 'test/notes.test.js'], agent: 'developer' });
541
+ expect(plan.tasks[0].prompt).toContain('do store');
542
+ expect(plan.tasks[0].prompt).toContain('do unit-tests');
543
+ });
544
+ it('points tasks that waited on the tests at the merged task', () => {
545
+ const { plan } = foldTestOnlyTasks({
546
+ name: 'x',
547
+ tasks: [t('api', ['src/api.ts']), t('api-tests', ['src/api.test.ts'], ['api']), t('docs', ['README.md'], ['api-tests'])],
548
+ });
549
+ expect(plan.tasks.find((x) => x.id === 'docs')?.depends_on).toEqual(['api']);
528
550
  });
529
- it('returns null for patch missing value', () => {
530
- const json = JSON.stringify([{ task_id: 'task-1', field: 'prompt' }]);
531
- expect(parsePatches(json)).toBeNull();
551
+ it('folds tests that list a task and something that task already waits on', () => {
552
+ // The plan a later real run produced: the integration tests named both the
553
+ // store change and the routes built on it, so they test the routes.
554
+ const { plan, folded } = foldTestOnlyTasks({
555
+ name: 'x',
556
+ tasks: [
557
+ t('store', ['src/notes.js']),
558
+ t('routes', ['src/server.js'], ['store']),
559
+ t('http-tests', ['test/server.test.js'], ['store', 'routes'], 'testing-expert'),
560
+ ],
561
+ });
562
+ expect(folded).toEqual([['http-tests', 'routes']]);
563
+ expect(plan.tasks.map((x) => x.id)).toEqual(['store', 'routes']);
532
564
  });
533
- it('returns null when any patch in the array is invalid', () => {
534
- const json = JSON.stringify([
535
- { task_id: 'task-1', field: 'prompt', value: 'ok' },
536
- { task_id: 'task-2', field: 'prompt' }, // missing value
537
- ]);
538
- expect(parsePatches(json)).toBeNull();
565
+ it('leaves alone tests that cover several tasks, or files another task claims', () => {
566
+ const several = foldTestOnlyTasks({
567
+ name: 'x',
568
+ tasks: [t('a', ['src/a.ts']), t('b', ['src/b.ts']), t('e2e', ['tests/e2e.test.ts'], ['a', 'b'])],
569
+ });
570
+ expect(several.folded).toEqual([]);
571
+ const shared = foldTestOnlyTasks({
572
+ name: 'x',
573
+ tasks: [t('a', ['src/a.ts']), t('a-tests', ['test/shared.test.ts'], ['a']), t('b', ['test/shared.test.ts'])],
574
+ });
575
+ expect(shared.folded).toEqual([]);
539
576
  });
540
- });
541
- // ── deriveSpecEnrichment ───────────────────────────────────────────────────────
542
- describe('deriveSpecEnrichment', () => {
543
- it('returns no circuit_breaker for low complexity', () => {
544
- const result = deriveSpecEnrichment({ complexity: 'low', total_tasks: 3, domains: ['frontend'] });
545
- expect(result.circuit_breaker).toBeUndefined();
546
- });
547
- it('returns circuit_breaker threshold=3 for medium complexity', () => {
548
- const result = deriveSpecEnrichment({ complexity: 'medium', total_tasks: 6, domains: ['frontend'] });
549
- expect(result.circuit_breaker).toEqual({ threshold: 3, cooldown_ms: 300_000 });
550
- });
551
- it('returns circuit_breaker threshold=2 for high complexity', () => {
552
- const result = deriveSpecEnrichment({ complexity: 'high', total_tasks: 12, domains: ['frontend'] });
553
- expect(result.circuit_breaker).toEqual({ threshold: 2, cooldown_ms: 300_000 });
554
- });
555
- it('enables detect_drift for medium/high, not low', () => {
556
- expect(deriveSpecEnrichment({ complexity: 'low', total_tasks: 3, domains: [] }).detect_drift).toBeUndefined();
557
- expect(deriveSpecEnrichment({ complexity: 'medium', total_tasks: 6, domains: [] }).detect_drift).toBe(true);
558
- expect(deriveSpecEnrichment({ complexity: 'high', total_tasks: 12, domains: [] }).detect_drift).toBe(true);
559
- });
560
- it('enables guard for medium/high, not low', () => {
561
- expect(deriveSpecEnrichment({ complexity: 'low', total_tasks: 3, domains: [] }).guard).toBeUndefined();
562
- expect(deriveSpecEnrichment({ complexity: 'medium', total_tasks: 6, domains: [] }).guard).toEqual({ enabled: true });
563
- expect(deriveSpecEnrichment({ complexity: 'high', total_tasks: 12, domains: [] }).guard).toEqual({ enabled: true });
564
- });
565
- it('always includes secret_scan and blast_radius gates', () => {
566
- const result = deriveSpecEnrichment({ complexity: 'low', total_tasks: 2, domains: [] });
567
- expect(result.built_in_gates?.secret_scan).toBe(true);
568
- expect(result.built_in_gates?.blast_radius).toBe(true);
569
- });
570
- it('adds browser_test gate for frontend/ui domains', () => {
571
- const frontend = deriveSpecEnrichment({ complexity: 'low', total_tasks: 3, domains: ['frontend'] });
572
- expect(frontend.built_in_gates?.browser_test).toBe('auto');
573
- const ui = deriveSpecEnrichment({ complexity: 'low', total_tasks: 3, domains: ['UI'] });
574
- expect(ui.built_in_gates?.browser_test).toBe('auto');
575
- const backend = deriveSpecEnrichment({ complexity: 'low', total_tasks: 3, domains: ['backend'] });
576
- expect(backend.built_in_gates?.browser_test).toBeUndefined();
577
- });
578
- it('adds regression_test gate for testing domain or >5 tasks', () => {
579
- const testing = deriveSpecEnrichment({ complexity: 'low', total_tasks: 3, domains: ['testing'] });
580
- expect(testing.built_in_gates?.regression_test).toBe('auto');
581
- const manyTasks = deriveSpecEnrichment({ complexity: 'medium', total_tasks: 7, domains: [] });
582
- expect(manyTasks.built_in_gates?.regression_test).toBe('auto');
583
- const fewTasks = deriveSpecEnrichment({ complexity: 'low', total_tasks: 4, domains: [] });
584
- expect(fewTasks.built_in_gates?.regression_test).toBeUndefined();
585
- });
586
- it('adds dependency_audit for database/api/backend domains', () => {
587
- const db = deriveSpecEnrichment({ complexity: 'low', total_tasks: 3, domains: ['database'] });
588
- expect(db.built_in_gates?.dependency_audit).toBe('auto');
589
- const api = deriveSpecEnrichment({ complexity: 'low', total_tasks: 3, domains: ['api'] });
590
- expect(api.built_in_gates?.dependency_audit).toBe('auto');
591
- const backend = deriveSpecEnrichment({ complexity: 'low', total_tasks: 3, domains: ['Backend'] });
592
- expect(backend.built_in_gates?.dependency_audit).toBe('auto');
593
- });
594
- it('scales max_concurrent_reviews with task count', () => {
595
- const few = deriveSpecEnrichment({ complexity: 'low', total_tasks: 4, domains: [] });
596
- expect(few.max_concurrent_reviews).toBe(2);
597
- const many = deriveSpecEnrichment({ complexity: 'high', total_tasks: 10, domains: [] });
598
- expect(many.max_concurrent_reviews).toBe(3);
577
+ it('leaves a task with any non-test file alone', () => {
578
+ const { folded } = foldTestOnlyTasks({
579
+ name: 'x',
580
+ tasks: [t('a', ['src/a.ts']), t('fixtures', ['test/a.test.ts', 'src/fixtures.ts'], ['a'])],
581
+ });
582
+ expect(folded).toEqual([]);
599
583
  });
600
584
  });
601
585
  //# sourceMappingURL=spec-builder.test.js.map