opencastle 1.3.1 → 1.4.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 (486) hide show
  1. package/README.md +16 -10
  2. package/bin/cli.mjs +8 -9
  3. package/dist/cli/agent-roster.test.js +0 -48
  4. package/dist/cli/agent-roster.test.js.map +1 -1
  5. package/dist/cli/boundary.test.js +9 -7
  6. package/dist/cli/boundary.test.js.map +1 -1
  7. package/dist/cli/convoy/artifacts.d.ts +9 -2
  8. package/dist/cli/convoy/artifacts.d.ts.map +1 -1
  9. package/dist/cli/convoy/artifacts.js +13 -10
  10. package/dist/cli/convoy/artifacts.js.map +1 -1
  11. package/dist/cli/convoy/artifacts.test.js +4 -2
  12. package/dist/cli/convoy/artifacts.test.js.map +1 -1
  13. package/dist/cli/convoy/engine.d.ts +53 -23
  14. package/dist/cli/convoy/engine.d.ts.map +1 -1
  15. package/dist/cli/convoy/engine.git.test.d.ts +2 -0
  16. package/dist/cli/convoy/engine.git.test.d.ts.map +1 -0
  17. package/dist/cli/convoy/engine.git.test.js +435 -0
  18. package/dist/cli/convoy/engine.git.test.js.map +1 -0
  19. package/dist/cli/convoy/engine.js +1746 -2305
  20. package/dist/cli/convoy/engine.js.map +1 -1
  21. package/dist/cli/convoy/engine.test.js +698 -678
  22. package/dist/cli/convoy/engine.test.js.map +1 -1
  23. package/dist/cli/convoy/event-schemas.d.ts +2 -0
  24. package/dist/cli/convoy/event-schemas.d.ts.map +1 -1
  25. package/dist/cli/convoy/event-schemas.js +59 -57
  26. package/dist/cli/convoy/event-schemas.js.map +1 -1
  27. package/dist/cli/convoy/events.d.ts +4 -1
  28. package/dist/cli/convoy/events.d.ts.map +1 -1
  29. package/dist/cli/convoy/events.js +69 -84
  30. package/dist/cli/convoy/events.js.map +1 -1
  31. package/dist/cli/convoy/events.test.js +50 -9
  32. package/dist/cli/convoy/events.test.js.map +1 -1
  33. package/dist/cli/convoy/gates.d.ts +9 -4
  34. package/dist/cli/convoy/gates.d.ts.map +1 -1
  35. package/dist/cli/convoy/gates.js +29 -14
  36. package/dist/cli/convoy/gates.js.map +1 -1
  37. package/dist/cli/convoy/isolation.d.ts +32 -6
  38. package/dist/cli/convoy/isolation.d.ts.map +1 -1
  39. package/dist/cli/convoy/isolation.js +72 -34
  40. package/dist/cli/convoy/isolation.js.map +1 -1
  41. package/dist/cli/convoy/isolation.test.js +66 -42
  42. package/dist/cli/convoy/isolation.test.js.map +1 -1
  43. package/dist/cli/convoy/lock.d.ts.map +1 -1
  44. package/dist/cli/convoy/lock.js +25 -10
  45. package/dist/cli/convoy/lock.js.map +1 -1
  46. package/dist/cli/convoy/lock.test.js +12 -0
  47. package/dist/cli/convoy/lock.test.js.map +1 -1
  48. package/dist/cli/convoy/merge.d.ts +21 -4
  49. package/dist/cli/convoy/merge.d.ts.map +1 -1
  50. package/dist/cli/convoy/merge.js +69 -53
  51. package/dist/cli/convoy/merge.js.map +1 -1
  52. package/dist/cli/convoy/merge.test.js +23 -1
  53. package/dist/cli/convoy/merge.test.js.map +1 -1
  54. package/dist/cli/convoy/progress.d.ts +35 -0
  55. package/dist/cli/convoy/progress.d.ts.map +1 -0
  56. package/dist/cli/convoy/progress.js +103 -0
  57. package/dist/cli/convoy/progress.js.map +1 -0
  58. package/dist/cli/convoy/progress.test.d.ts +2 -0
  59. package/dist/cli/convoy/progress.test.d.ts.map +1 -0
  60. package/dist/cli/convoy/progress.test.js +53 -0
  61. package/dist/cli/convoy/progress.test.js.map +1 -0
  62. package/dist/cli/convoy/read-model.d.ts +468 -0
  63. package/dist/cli/convoy/read-model.d.ts.map +1 -0
  64. package/dist/cli/convoy/read-model.js +1132 -0
  65. package/dist/cli/convoy/read-model.js.map +1 -0
  66. package/dist/cli/convoy/read-model.test.d.ts +2 -0
  67. package/dist/cli/convoy/read-model.test.d.ts.map +1 -0
  68. package/dist/cli/convoy/read-model.test.js +609 -0
  69. package/dist/cli/convoy/read-model.test.js.map +1 -0
  70. package/dist/cli/convoy/redact.d.ts +34 -0
  71. package/dist/cli/convoy/redact.d.ts.map +1 -0
  72. package/dist/cli/convoy/redact.js +66 -0
  73. package/dist/cli/convoy/redact.js.map +1 -0
  74. package/dist/cli/convoy/redact.test.d.ts +2 -0
  75. package/dist/cli/convoy/redact.test.d.ts.map +1 -0
  76. package/dist/cli/convoy/redact.test.js +43 -0
  77. package/dist/cli/convoy/redact.test.js.map +1 -0
  78. package/dist/cli/convoy/reviewer.d.ts +65 -0
  79. package/dist/cli/convoy/reviewer.d.ts.map +1 -0
  80. package/dist/cli/convoy/reviewer.js +141 -0
  81. package/dist/cli/convoy/reviewer.js.map +1 -0
  82. package/dist/cli/convoy/reviewer.test.d.ts +2 -0
  83. package/dist/cli/convoy/reviewer.test.d.ts.map +1 -0
  84. package/dist/cli/convoy/reviewer.test.js +96 -0
  85. package/dist/cli/convoy/reviewer.test.js.map +1 -0
  86. package/dist/cli/convoy/schedule.d.ts +30 -0
  87. package/dist/cli/convoy/schedule.d.ts.map +1 -0
  88. package/dist/cli/convoy/schedule.js +111 -0
  89. package/dist/cli/convoy/schedule.js.map +1 -0
  90. package/dist/cli/convoy/schedule.test.d.ts +2 -0
  91. package/dist/cli/convoy/schedule.test.d.ts.map +1 -0
  92. package/dist/cli/convoy/schedule.test.js +45 -0
  93. package/dist/cli/convoy/schedule.test.js.map +1 -0
  94. package/dist/cli/convoy/spec-builder.d.ts +120 -30
  95. package/dist/cli/convoy/spec-builder.d.ts.map +1 -1
  96. package/dist/cli/convoy/spec-builder.js +438 -114
  97. package/dist/cli/convoy/spec-builder.js.map +1 -1
  98. package/dist/cli/convoy/spec-builder.test.js +419 -435
  99. package/dist/cli/convoy/spec-builder.test.js.map +1 -1
  100. package/dist/cli/convoy/spec-types.d.ts +46 -92
  101. package/dist/cli/convoy/spec-types.d.ts.map +1 -1
  102. package/dist/cli/convoy/store.d.ts +6 -1
  103. package/dist/cli/convoy/store.d.ts.map +1 -1
  104. package/dist/cli/convoy/store.js +111 -15
  105. package/dist/cli/convoy/store.js.map +1 -1
  106. package/dist/cli/convoy/store.test.js +59 -13
  107. package/dist/cli/convoy/store.test.js.map +1 -1
  108. package/dist/cli/convoy/types.d.ts +76 -113
  109. package/dist/cli/convoy/types.d.ts.map +1 -1
  110. package/dist/cli/convoy/types.js +6 -13
  111. package/dist/cli/convoy/types.js.map +1 -1
  112. package/dist/cli/convoy/worktree.d.ts +88 -3
  113. package/dist/cli/convoy/worktree.d.ts.map +1 -1
  114. package/dist/cli/convoy/worktree.js +282 -56
  115. package/dist/cli/convoy/worktree.js.map +1 -1
  116. package/dist/cli/convoy/worktree.test.js +132 -1
  117. package/dist/cli/convoy/worktree.test.js.map +1 -1
  118. package/dist/cli/convoy-args.test.js +9 -27
  119. package/dist/cli/convoy-args.test.js.map +1 -1
  120. package/dist/cli/convoy-cmd.d.ts +31 -6
  121. package/dist/cli/convoy-cmd.d.ts.map +1 -1
  122. package/dist/cli/convoy-cmd.js +150 -201
  123. package/dist/cli/convoy-cmd.js.map +1 -1
  124. package/dist/cli/convoy-cmd.test.d.ts +2 -0
  125. package/dist/cli/convoy-cmd.test.d.ts.map +1 -0
  126. package/dist/cli/convoy-cmd.test.js +144 -0
  127. package/dist/cli/convoy-cmd.test.js.map +1 -0
  128. package/dist/cli/dashboard.d.ts +24 -11
  129. package/dist/cli/dashboard.d.ts.map +1 -1
  130. package/dist/cli/dashboard.js +241 -303
  131. package/dist/cli/dashboard.js.map +1 -1
  132. package/dist/cli/dashboard.test.d.ts +2 -0
  133. package/dist/cli/dashboard.test.d.ts.map +1 -0
  134. package/dist/cli/dashboard.test.js +340 -0
  135. package/dist/cli/dashboard.test.js.map +1 -0
  136. package/dist/cli/dispatcher.test.js +35 -2
  137. package/dist/cli/dispatcher.test.js.map +1 -1
  138. package/dist/cli/docs-accuracy.test.js +3 -3
  139. package/dist/cli/docs-accuracy.test.js.map +1 -1
  140. package/dist/cli/log.d.ts +39 -0
  141. package/dist/cli/log.d.ts.map +1 -1
  142. package/dist/cli/log.js +267 -93
  143. package/dist/cli/log.js.map +1 -1
  144. package/dist/cli/log.test.d.ts +2 -0
  145. package/dist/cli/log.test.d.ts.map +1 -0
  146. package/dist/cli/log.test.js +208 -0
  147. package/dist/cli/log.test.js.map +1 -0
  148. package/dist/cli/nearest.d.ts +18 -0
  149. package/dist/cli/nearest.d.ts.map +1 -0
  150. package/dist/cli/nearest.js +38 -0
  151. package/dist/cli/nearest.js.map +1 -0
  152. package/dist/cli/nearest.test.d.ts +2 -0
  153. package/dist/cli/nearest.test.d.ts.map +1 -0
  154. package/dist/cli/nearest.test.js +24 -0
  155. package/dist/cli/nearest.test.js.map +1 -0
  156. package/dist/cli/pipeline.d.ts +61 -0
  157. package/dist/cli/pipeline.d.ts.map +1 -1
  158. package/dist/cli/pipeline.flow.test.d.ts +2 -0
  159. package/dist/cli/pipeline.flow.test.d.ts.map +1 -0
  160. package/dist/cli/pipeline.flow.test.js +524 -0
  161. package/dist/cli/pipeline.flow.test.js.map +1 -0
  162. package/dist/cli/pipeline.js +471 -690
  163. package/dist/cli/pipeline.js.map +1 -1
  164. package/dist/cli/plan.d.ts +82 -31
  165. package/dist/cli/plan.d.ts.map +1 -1
  166. package/dist/cli/plan.js +167 -507
  167. package/dist/cli/plan.js.map +1 -1
  168. package/dist/cli/plan.test.d.ts +2 -0
  169. package/dist/cli/plan.test.d.ts.map +1 -0
  170. package/dist/cli/plan.test.js +158 -0
  171. package/dist/cli/plan.test.js.map +1 -0
  172. package/dist/cli/run/adapters/agent-process.d.ts +82 -0
  173. package/dist/cli/run/adapters/agent-process.d.ts.map +1 -0
  174. package/dist/cli/run/adapters/agent-process.js +224 -0
  175. package/dist/cli/run/adapters/agent-process.js.map +1 -0
  176. package/dist/cli/run/adapters/agent-process.test.d.ts +2 -0
  177. package/dist/cli/run/adapters/agent-process.test.d.ts.map +1 -0
  178. package/dist/cli/run/adapters/agent-process.test.js +159 -0
  179. package/dist/cli/run/adapters/agent-process.test.js.map +1 -0
  180. package/dist/cli/run/adapters/claude.d.ts +53 -2
  181. package/dist/cli/run/adapters/claude.d.ts.map +1 -1
  182. package/dist/cli/run/adapters/claude.js +147 -171
  183. package/dist/cli/run/adapters/claude.js.map +1 -1
  184. package/dist/cli/run/adapters/claude.test.js +197 -254
  185. package/dist/cli/run/adapters/claude.test.js.map +1 -1
  186. package/dist/cli/run/adapters/codex.d.ts +25 -2
  187. package/dist/cli/run/adapters/codex.d.ts.map +1 -1
  188. package/dist/cli/run/adapters/codex.js +113 -81
  189. package/dist/cli/run/adapters/codex.js.map +1 -1
  190. package/dist/cli/run/adapters/codex.test.js +116 -95
  191. package/dist/cli/run/adapters/codex.test.js.map +1 -1
  192. package/dist/cli/run/adapters/copilot.d.ts +35 -1
  193. package/dist/cli/run/adapters/copilot.d.ts.map +1 -1
  194. package/dist/cli/run/adapters/copilot.js +104 -287
  195. package/dist/cli/run/adapters/copilot.js.map +1 -1
  196. package/dist/cli/run/adapters/copilot.test.js +122 -282
  197. package/dist/cli/run/adapters/copilot.test.js.map +1 -1
  198. package/dist/cli/run/adapters/cursor.d.ts +25 -7
  199. package/dist/cli/run/adapters/cursor.d.ts.map +1 -1
  200. package/dist/cli/run/adapters/cursor.js +103 -156
  201. package/dist/cli/run/adapters/cursor.js.map +1 -1
  202. package/dist/cli/run/adapters/cursor.test.js +106 -218
  203. package/dist/cli/run/adapters/cursor.test.js.map +1 -1
  204. package/dist/cli/run/adapters/index.d.ts +34 -5
  205. package/dist/cli/run/adapters/index.d.ts.map +1 -1
  206. package/dist/cli/run/adapters/index.js +147 -21
  207. package/dist/cli/run/adapters/index.js.map +1 -1
  208. package/dist/cli/run/adapters/index.test.d.ts +2 -0
  209. package/dist/cli/run/adapters/index.test.d.ts.map +1 -0
  210. package/dist/cli/run/adapters/index.test.js +129 -0
  211. package/dist/cli/run/adapters/index.test.js.map +1 -0
  212. package/dist/cli/run/adapters/opencode.d.ts +25 -9
  213. package/dist/cli/run/adapters/opencode.d.ts.map +1 -1
  214. package/dist/cli/run/adapters/opencode.js +136 -152
  215. package/dist/cli/run/adapters/opencode.js.map +1 -1
  216. package/dist/cli/run/adapters/opencode.test.js +99 -218
  217. package/dist/cli/run/adapters/opencode.test.js.map +1 -1
  218. package/dist/cli/run/adapters/permission-modes.d.ts +47 -4
  219. package/dist/cli/run/adapters/permission-modes.d.ts.map +1 -1
  220. package/dist/cli/run/adapters/permission-modes.js +113 -37
  221. package/dist/cli/run/adapters/permission-modes.js.map +1 -1
  222. package/dist/cli/run/adapters/permission-modes.test.js +55 -40
  223. package/dist/cli/run/adapters/permission-modes.test.js.map +1 -1
  224. package/dist/cli/run/adapters/stub-cli.test-helper.d.ts +22 -0
  225. package/dist/cli/run/adapters/stub-cli.test-helper.d.ts.map +1 -0
  226. package/dist/cli/run/adapters/stub-cli.test-helper.js +73 -0
  227. package/dist/cli/run/adapters/stub-cli.test-helper.js.map +1 -0
  228. package/dist/cli/run/platform.d.ts +52 -0
  229. package/dist/cli/run/platform.d.ts.map +1 -0
  230. package/dist/cli/run/platform.js +207 -0
  231. package/dist/cli/run/platform.js.map +1 -0
  232. package/dist/cli/run/platform.test.d.ts +2 -0
  233. package/dist/cli/run/platform.test.d.ts.map +1 -0
  234. package/dist/cli/run/platform.test.js +119 -0
  235. package/dist/cli/run/platform.test.js.map +1 -0
  236. package/dist/cli/run/schema.d.ts +6 -8
  237. package/dist/cli/run/schema.d.ts.map +1 -1
  238. package/dist/cli/run/schema.js +44 -68
  239. package/dist/cli/run/schema.js.map +1 -1
  240. package/dist/cli/run/schema.test.js +59 -279
  241. package/dist/cli/run/schema.test.js.map +1 -1
  242. package/dist/cli/run.d.ts +34 -56
  243. package/dist/cli/run.d.ts.map +1 -1
  244. package/dist/cli/run.js +379 -1132
  245. package/dist/cli/run.js.map +1 -1
  246. package/dist/cli/run.test.d.ts +2 -0
  247. package/dist/cli/run.test.d.ts.map +1 -0
  248. package/dist/cli/run.test.js +318 -0
  249. package/dist/cli/run.test.js.map +1 -0
  250. package/dist/cli/team-config.d.ts.map +1 -1
  251. package/dist/cli/team-config.js +2 -21
  252. package/dist/cli/team-config.js.map +1 -1
  253. package/dist/cli/tiers.test.js +4 -13
  254. package/dist/cli/tiers.test.js.map +1 -1
  255. package/package.json +3 -10
  256. package/src/cli/agent-roster.test.ts +0 -55
  257. package/src/cli/boundary.test.ts +9 -7
  258. package/src/cli/convoy/TELEMETRY.md +131 -125
  259. package/src/cli/convoy/artifacts.test.ts +4 -2
  260. package/src/cli/convoy/artifacts.ts +13 -12
  261. package/src/cli/convoy/engine.git.test.ts +462 -0
  262. package/src/cli/convoy/engine.test.ts +817 -850
  263. package/src/cli/convoy/engine.ts +1864 -2596
  264. package/src/cli/convoy/event-schemas.ts +63 -59
  265. package/src/cli/convoy/events.test.ts +58 -9
  266. package/src/cli/convoy/events.ts +69 -91
  267. package/src/cli/convoy/gates.ts +31 -12
  268. package/src/cli/convoy/isolation.test.ts +76 -43
  269. package/src/cli/convoy/isolation.ts +100 -38
  270. package/src/cli/convoy/lock.test.ts +16 -0
  271. package/src/cli/convoy/lock.ts +25 -8
  272. package/src/cli/convoy/merge.test.ts +25 -1
  273. package/src/cli/convoy/merge.ts +74 -61
  274. package/src/cli/convoy/progress.test.ts +59 -0
  275. package/src/cli/convoy/progress.ts +121 -0
  276. package/src/cli/convoy/read-model.test.ts +685 -0
  277. package/src/cli/convoy/read-model.ts +1469 -0
  278. package/src/cli/convoy/redact.test.ts +49 -0
  279. package/src/cli/convoy/redact.ts +73 -0
  280. package/src/cli/convoy/reviewer.test.ts +112 -0
  281. package/src/cli/convoy/reviewer.ts +196 -0
  282. package/src/cli/convoy/schedule.test.ts +56 -0
  283. package/src/cli/convoy/schedule.ts +109 -0
  284. package/src/cli/convoy/spec-builder.test.ts +460 -464
  285. package/src/cli/convoy/spec-builder.ts +460 -129
  286. package/src/cli/convoy/spec-types.ts +46 -108
  287. package/src/cli/convoy/store.test.ts +64 -13
  288. package/src/cli/convoy/store.ts +143 -33
  289. package/src/cli/convoy/types.ts +59 -71
  290. package/src/cli/convoy/worktree.test.ts +140 -1
  291. package/src/cli/convoy/worktree.ts +311 -61
  292. package/src/cli/convoy-args.test.ts +10 -30
  293. package/src/cli/convoy-cmd.test.ts +163 -0
  294. package/src/cli/convoy-cmd.ts +173 -216
  295. package/src/cli/dashboard/dashboard.css +2086 -0
  296. package/src/cli/dashboard/dashboard.js +1687 -0
  297. package/src/cli/dashboard/index.html +307 -0
  298. package/src/cli/dashboard.test.ts +382 -0
  299. package/src/cli/dashboard.ts +243 -339
  300. package/src/cli/dispatcher.test.ts +36 -2
  301. package/src/cli/docs-accuracy.test.ts +3 -3
  302. package/src/cli/log.test.ts +228 -0
  303. package/src/cli/log.ts +302 -83
  304. package/src/cli/nearest.test.ts +27 -0
  305. package/src/cli/nearest.ts +38 -0
  306. package/src/cli/pipeline.flow.test.ts +607 -0
  307. package/src/cli/pipeline.ts +544 -759
  308. package/src/cli/plan.test.ts +193 -0
  309. package/src/cli/plan.ts +209 -545
  310. package/src/cli/run/adapters/agent-process.test.ts +175 -0
  311. package/src/cli/run/adapters/agent-process.ts +252 -0
  312. package/src/cli/run/adapters/claude.test.ts +205 -260
  313. package/src/cli/run/adapters/claude.ts +151 -162
  314. package/src/cli/run/adapters/codex.test.ts +120 -100
  315. package/src/cli/run/adapters/codex.ts +115 -91
  316. package/src/cli/run/adapters/copilot.test.ts +135 -306
  317. package/src/cli/run/adapters/copilot.ts +105 -274
  318. package/src/cli/run/adapters/cursor.test.ts +111 -220
  319. package/src/cli/run/adapters/cursor.ts +105 -156
  320. package/src/cli/run/adapters/index.test.ts +148 -0
  321. package/src/cli/run/adapters/index.ts +168 -20
  322. package/src/cli/run/adapters/opencode.test.ts +106 -227
  323. package/src/cli/run/adapters/opencode.ts +139 -151
  324. package/src/cli/run/adapters/permission-modes.test.ts +63 -41
  325. package/src/cli/run/adapters/permission-modes.ts +118 -37
  326. package/src/cli/run/adapters/stub-cli.test-helper.ts +88 -0
  327. package/src/cli/run/platform.test.ts +128 -0
  328. package/src/cli/run/platform.ts +213 -0
  329. package/src/cli/run/schema.test.ts +62 -344
  330. package/src/cli/run/schema.ts +48 -78
  331. package/src/cli/run.test.ts +351 -0
  332. package/src/cli/run.ts +366 -1151
  333. package/src/cli/team-config.ts +2 -21
  334. package/src/cli/tiers.test.ts +4 -17
  335. package/src/orchestrator/agents/team-lead.agent.md +1 -1
  336. package/src/orchestrator/prompts/assess-complexity.prompt.md +43 -26
  337. package/src/orchestrator/prompts/brainstorm.prompt.md +1 -1
  338. package/src/orchestrator/prompts/bug-fix.prompt.md +2 -2
  339. package/src/orchestrator/prompts/fix-convoy.prompt.md +43 -29
  340. package/src/orchestrator/prompts/fix-prd.prompt.md +26 -22
  341. package/src/orchestrator/prompts/generate-convoy.prompt.md +139 -147
  342. package/src/orchestrator/prompts/generate-prd.prompt.md +75 -68
  343. package/src/orchestrator/prompts/implement-feature.prompt.md +2 -2
  344. package/src/orchestrator/prompts/validate-convoy.prompt.md +29 -28
  345. package/src/orchestrator/prompts/validate-prd.prompt.md +28 -21
  346. package/src/orchestrator/skills/agent-hooks/HOOKS-REFERENCE.md +3 -3
  347. package/src/orchestrator/skills/agent-hooks/SKILL.md +1 -1
  348. package/src/orchestrator/skills/fast-review/SKILL.md +3 -1
  349. package/src/orchestrator/skills/orchestration-protocols/SKILL.md +7 -8
  350. package/dist/cli/convoy/dag-analysis.d.ts +0 -39
  351. package/dist/cli/convoy/dag-analysis.d.ts.map +0 -1
  352. package/dist/cli/convoy/dag-analysis.js +0 -279
  353. package/dist/cli/convoy/dag-analysis.js.map +0 -1
  354. package/dist/cli/convoy/dag-analysis.test.d.ts +0 -2
  355. package/dist/cli/convoy/dag-analysis.test.d.ts.map +0 -1
  356. package/dist/cli/convoy/dag-analysis.test.js +0 -289
  357. package/dist/cli/convoy/dag-analysis.test.js.map +0 -1
  358. package/dist/cli/convoy/formula.d.ts +0 -19
  359. package/dist/cli/convoy/formula.d.ts.map +0 -1
  360. package/dist/cli/convoy/formula.js +0 -142
  361. package/dist/cli/convoy/formula.js.map +0 -1
  362. package/dist/cli/convoy/formula.test.d.ts +0 -2
  363. package/dist/cli/convoy/formula.test.d.ts.map +0 -1
  364. package/dist/cli/convoy/formula.test.js +0 -342
  365. package/dist/cli/convoy/formula.test.js.map +0 -1
  366. package/dist/cli/convoy/health.d.ts +0 -34
  367. package/dist/cli/convoy/health.d.ts.map +0 -1
  368. package/dist/cli/convoy/health.js +0 -123
  369. package/dist/cli/convoy/health.js.map +0 -1
  370. package/dist/cli/convoy/health.test.d.ts +0 -2
  371. package/dist/cli/convoy/health.test.d.ts.map +0 -1
  372. package/dist/cli/convoy/health.test.js +0 -448
  373. package/dist/cli/convoy/health.test.js.map +0 -1
  374. package/dist/cli/convoy/last-run.d.ts +0 -53
  375. package/dist/cli/convoy/last-run.d.ts.map +0 -1
  376. package/dist/cli/convoy/last-run.js +0 -54
  377. package/dist/cli/convoy/last-run.js.map +0 -1
  378. package/dist/cli/convoy/last-run.test.d.ts +0 -2
  379. package/dist/cli/convoy/last-run.test.d.ts.map +0 -1
  380. package/dist/cli/convoy/last-run.test.js +0 -110
  381. package/dist/cli/convoy/last-run.test.js.map +0 -1
  382. package/dist/cli/convoy/pipeline.d.ts +0 -41
  383. package/dist/cli/convoy/pipeline.d.ts.map +0 -1
  384. package/dist/cli/convoy/pipeline.js +0 -414
  385. package/dist/cli/convoy/pipeline.js.map +0 -1
  386. package/dist/cli/convoy/pipeline.test.d.ts +0 -2
  387. package/dist/cli/convoy/pipeline.test.d.ts.map +0 -1
  388. package/dist/cli/convoy/pipeline.test.js +0 -837
  389. package/dist/cli/convoy/pipeline.test.js.map +0 -1
  390. package/dist/cli/convoy/review-stages.d.ts +0 -9
  391. package/dist/cli/convoy/review-stages.d.ts.map +0 -1
  392. package/dist/cli/convoy/review-stages.js +0 -134
  393. package/dist/cli/convoy/review-stages.js.map +0 -1
  394. package/dist/cli/convoy/review-stages.test.d.ts +0 -2
  395. package/dist/cli/convoy/review-stages.test.d.ts.map +0 -1
  396. package/dist/cli/convoy/review-stages.test.js +0 -197
  397. package/dist/cli/convoy/review-stages.test.js.map +0 -1
  398. package/dist/cli/run/executor.d.ts +0 -15
  399. package/dist/cli/run/executor.d.ts.map +0 -1
  400. package/dist/cli/run/executor.js +0 -249
  401. package/dist/cli/run/executor.js.map +0 -1
  402. package/dist/cli/run/executor.test.d.ts +0 -2
  403. package/dist/cli/run/executor.test.d.ts.map +0 -1
  404. package/dist/cli/run/executor.test.js +0 -297
  405. package/dist/cli/run/executor.test.js.map +0 -1
  406. package/dist/cli/run/reporter.d.ts +0 -10
  407. package/dist/cli/run/reporter.d.ts.map +0 -1
  408. package/dist/cli/run/reporter.js +0 -142
  409. package/dist/cli/run/reporter.js.map +0 -1
  410. package/dist/cli/run-dry-run.test.d.ts +0 -2
  411. package/dist/cli/run-dry-run.test.d.ts.map +0 -1
  412. package/dist/cli/run-dry-run.test.js +0 -83
  413. package/dist/cli/run-dry-run.test.js.map +0 -1
  414. package/dist/cli/run-executor-flags.test.d.ts +0 -2
  415. package/dist/cli/run-executor-flags.test.d.ts.map +0 -1
  416. package/dist/cli/run-executor-flags.test.js +0 -31
  417. package/dist/cli/run-executor-flags.test.js.map +0 -1
  418. package/dist/cli/run-finish.test.d.ts +0 -2
  419. package/dist/cli/run-finish.test.d.ts.map +0 -1
  420. package/dist/cli/run-finish.test.js +0 -77
  421. package/dist/cli/run-finish.test.js.map +0 -1
  422. package/dist/cli/watch.d.ts +0 -15
  423. package/dist/cli/watch.d.ts.map +0 -1
  424. package/dist/cli/watch.js +0 -277
  425. package/dist/cli/watch.js.map +0 -1
  426. package/dist/dashboard/scripts/etl.d.ts +0 -10
  427. package/dist/dashboard/scripts/etl.d.ts.map +0 -1
  428. package/dist/dashboard/scripts/etl.js +0 -141
  429. package/dist/dashboard/scripts/etl.js.map +0 -1
  430. package/src/cli/convoy/dag-analysis.test.ts +0 -349
  431. package/src/cli/convoy/dag-analysis.ts +0 -367
  432. package/src/cli/convoy/formula.test.ts +0 -404
  433. package/src/cli/convoy/formula.ts +0 -174
  434. package/src/cli/convoy/health.test.ts +0 -519
  435. package/src/cli/convoy/health.ts +0 -189
  436. package/src/cli/convoy/last-run.test.ts +0 -130
  437. package/src/cli/convoy/last-run.ts +0 -87
  438. package/src/cli/convoy/pipeline.test.ts +0 -999
  439. package/src/cli/convoy/pipeline.ts +0 -492
  440. package/src/cli/convoy/review-stages.test.ts +0 -235
  441. package/src/cli/convoy/review-stages.ts +0 -166
  442. package/src/cli/run/executor.test.ts +0 -338
  443. package/src/cli/run/executor.ts +0 -292
  444. package/src/cli/run/reporter.ts +0 -160
  445. package/src/cli/run-dry-run.test.ts +0 -97
  446. package/src/cli/run-executor-flags.test.ts +0 -38
  447. package/src/cli/run-finish.test.ts +0 -91
  448. package/src/cli/watch.ts +0 -295
  449. package/src/dashboard/astro.config.mjs +0 -6
  450. package/src/dashboard/dist/_astro/index.CADNhRPS.css +0 -1
  451. package/src/dashboard/dist/data/.gitkeep +0 -0
  452. package/src/dashboard/dist/data/convoy-list.json +0 -1
  453. package/src/dashboard/dist/data/overall-stats.json +0 -29
  454. package/src/dashboard/dist/index.html +0 -1963
  455. package/src/dashboard/node_modules/.vite/deps/_metadata.json +0 -31
  456. package/src/dashboard/node_modules/.vite/deps/astro___aria-query.js +0 -6776
  457. package/src/dashboard/node_modules/.vite/deps/astro___aria-query.js.map +0 -7
  458. package/src/dashboard/node_modules/.vite/deps/astro___axobject-query.js +0 -3754
  459. package/src/dashboard/node_modules/.vite/deps/astro___axobject-query.js.map +0 -7
  460. package/src/dashboard/node_modules/.vite/deps/astro___cssesc.js +0 -99
  461. package/src/dashboard/node_modules/.vite/deps/astro___cssesc.js.map +0 -7
  462. package/src/dashboard/node_modules/.vite/deps/chunk-BUSYA2B4.js +0 -8
  463. package/src/dashboard/node_modules/.vite/deps/chunk-BUSYA2B4.js.map +0 -7
  464. package/src/dashboard/node_modules/.vite/deps/package.json +0 -3
  465. package/src/dashboard/package-lock.json +0 -6
  466. package/src/dashboard/public/data/.gitkeep +0 -0
  467. package/src/dashboard/public/data/convoy-list.json +0 -1
  468. package/src/dashboard/public/data/overall-stats.json +0 -29
  469. package/src/dashboard/public/icon-192.png +0 -0
  470. package/src/dashboard/scripts/etl.test.ts +0 -166
  471. package/src/dashboard/scripts/etl.ts +0 -170
  472. package/src/dashboard/scripts/generate-demo-db.test.ts +0 -30
  473. package/src/dashboard/scripts/generate-demo-db.ts +0 -529
  474. package/src/dashboard/scripts/integration-test.ts +0 -504
  475. package/src/dashboard/scripts/verify-demo-data.sh +0 -51
  476. package/src/dashboard/seed-data/delegations.ndjson +0 -35
  477. package/src/dashboard/seed-data/events.ndjson +0 -104
  478. package/src/dashboard/seed-data/panels.ndjson +0 -13
  479. package/src/dashboard/seed-data/reviews.ndjson +0 -6
  480. package/src/dashboard/seed-data/sessions.ndjson +0 -50
  481. package/src/dashboard/src/env.d.ts +0 -1
  482. package/src/dashboard/src/layouts/Layout.astro +0 -25
  483. package/src/dashboard/src/pages/index.astro +0 -2313
  484. package/src/dashboard/src/styles/dashboard.css +0 -2943
  485. package/src/dashboard/tsconfig.json +0 -6
  486. /package/src/{dashboard/dist → cli/dashboard}/icon-192.png +0 -0
@@ -1,56 +1,129 @@
1
1
  import { stringify } from 'yaml';
2
+ import { existsSync, readFileSync } from 'node:fs';
3
+ import { join } from 'node:path';
2
4
  import { getEffortProfile } from './effort-scaling.js';
3
- function toKebabCase(name) {
5
+ import { normalizePath, pathsOverlap } from './partition.js';
6
+ import { parseYaml, validateSpec } from '../run/schema.js';
7
+ /** More agents at once than this costs more in rate limits and machine load than it saves. */
8
+ export const MAX_PLANNED_CONCURRENCY = 4;
9
+ export function slugify(name) {
4
10
  return name
5
11
  .toLowerCase()
6
12
  .replace(/[^a-z0-9]+/g, '-')
7
13
  .replace(/^-+|-+$/g, '');
8
14
  }
9
- /**
10
- * Derives advanced convoy spec properties from a complexity assessment.
11
- * These are infrastructure concerns the LLM shouldn't generate — they're computed from signals.
12
- */
13
- export function deriveSpecEnrichment(complexity) {
14
- const enrichment = {};
15
- // Circuit breaker: higher complexity → lower threshold (trip faster)
16
- if (complexity.complexity === 'high') {
17
- enrichment.circuit_breaker = { threshold: 2, cooldown_ms: 300_000 };
15
+ function readPackageJson(projectRoot) {
16
+ const path = join(projectRoot, 'package.json');
17
+ if (!existsSync(path))
18
+ return null;
19
+ try {
20
+ return JSON.parse(readFileSync(path, 'utf8'));
18
21
  }
19
- else if (complexity.complexity === 'medium') {
20
- enrichment.circuit_breaker = { threshold: 3, cooldown_ms: 300_000 };
22
+ catch {
23
+ return null;
21
24
  }
22
- // Drift detection for medium/high
23
- if (complexity.complexity !== 'low') {
24
- enrichment.detect_drift = true;
25
+ }
26
+ /**
27
+ * The package manager a project uses: its `packageManager` field (what
28
+ * corepack honours), else its lockfile, else npm.
29
+ */
30
+ export function detectPackageManager(projectRoot) {
31
+ const declared = readPackageJson(projectRoot)?.packageManager;
32
+ if (typeof declared === 'string') {
33
+ const name = declared.split('@')[0];
34
+ if (name === 'npm' || name === 'pnpm' || name === 'yarn' || name === 'bun')
35
+ return name;
25
36
  }
26
- // Guard: enabled for medium/high
27
- if (complexity.complexity !== 'low') {
28
- enrichment.guard = { enabled: true };
37
+ if (existsSync(join(projectRoot, 'pnpm-lock.yaml')))
38
+ return 'pnpm';
39
+ if (existsSync(join(projectRoot, 'yarn.lock')))
40
+ return 'yarn';
41
+ if (existsSync(join(projectRoot, 'bun.lockb')) || existsSync(join(projectRoot, 'bun.lock')))
42
+ return 'bun';
43
+ return 'npm';
44
+ }
45
+ /** Cheapest first, so a type error fails the run before the test suite starts. */
46
+ const GATE_SCRIPTS = [['typecheck', 'type-check'], ['lint'], ['test'], ['build']];
47
+ /**
48
+ * The project's own checks, from its package.json scripts.
49
+ *
50
+ * They run once, after every task has merged, which is the only point at which
51
+ * they test the combined result. The planner used to choose gates itself and
52
+ * the spec builder added a per-task `npm test` once a plan passed five tasks:
53
+ * the whole suite, once per task, mostly against the same code.
54
+ */
55
+ export function detectGates(projectRoot) {
56
+ const scripts = readPackageJson(projectRoot)?.scripts;
57
+ if (!scripts || typeof scripts !== 'object')
58
+ return [];
59
+ const pm = detectPackageManager(projectRoot);
60
+ const gates = [];
61
+ for (const names of GATE_SCRIPTS) {
62
+ const name = names.find((n) => typeof scripts[n] === 'string');
63
+ if (!name)
64
+ continue;
65
+ const body = scripts[name];
66
+ // `npm init` writes a test script that always fails, and a watcher never
67
+ // exits; either would fail or hang every run.
68
+ if (/no test specified/.test(body) || /--watch\b/.test(body))
69
+ continue;
70
+ gates.push(`${pm} run ${name}`);
29
71
  }
30
- // Built-in gates based on domains
31
- const domains = new Set(complexity.domains.map(d => d.toLowerCase()));
32
- const gates = {
33
- secret_scan: true,
34
- blast_radius: true,
72
+ return gates;
73
+ }
74
+ // ── Building the spec ───────────────────────────────────────────────────────
75
+ /** Topological levels: a task's level is one more than its deepest dependency's. */
76
+ function levels(plan) {
77
+ const byId = new Map(plan.tasks.map((t) => [t.id, t]));
78
+ const memo = new Map();
79
+ const visit = (id, seen) => {
80
+ const known = memo.get(id);
81
+ if (known !== undefined)
82
+ return known;
83
+ if (seen.has(id))
84
+ return 0; // a cycle; checkPlan reports it
85
+ seen.add(id);
86
+ const deps = (byId.get(id)?.depends_on ?? []).filter((d) => byId.has(d));
87
+ const level = deps.length ? 1 + Math.max(...deps.map((d) => visit(d, seen))) : 0;
88
+ memo.set(id, level);
89
+ return level;
35
90
  };
36
- if (domains.has('frontend') || domains.has('ui')) {
37
- gates.browser_test = 'auto';
38
- }
39
- if (domains.has('testing') || complexity.total_tasks > 5) {
40
- gates.regression_test = 'auto';
41
- }
42
- if (domains.has('database') || domains.has('api') || domains.has('backend')) {
43
- gates.dependency_audit = 'auto';
44
- }
45
- enrichment.built_in_gates = gates;
46
- // Review concurrency scales with task count
47
- enrichment.max_concurrent_reviews = complexity.total_tasks > 6 ? 3 : 2;
48
- return enrichment;
91
+ for (const t of plan.tasks)
92
+ visit(t.id, new Set());
93
+ return memo;
94
+ }
95
+ /**
96
+ * How many tasks to run at once: the widest level of the plan, capped.
97
+ *
98
+ * A fixed 2 left wide plans waiting and gave a straight chain a slot it could
99
+ * never use.
100
+ */
101
+ export function planConcurrency(plan) {
102
+ const width = new Map();
103
+ for (const level of levels(plan).values())
104
+ width.set(level, (width.get(level) ?? 0) + 1);
105
+ const widest = Math.max(1, ...width.values());
106
+ return Math.min(widest, MAX_PLANNED_CONCURRENCY);
49
107
  }
50
108
  /**
51
- * Converts a TaskPlan into a valid convoy YAML string with a comment header.
109
+ * Converts a TaskPlan into convoy YAML.
110
+ *
111
+ * Defaults that changed, and why:
112
+ * - `branch: convoy/<slug>`. Without one the engine merged into whatever was
113
+ * checked out, and resume of a branchless run crashed.
114
+ * - `on_failure: continue`. `stop` switched off every per-task retry and still
115
+ * let the rest of the wave run; with `continue` a failure blocks only what
116
+ * depends on it, and resume picks it up.
117
+ * - `adapter`, so a resumed run cannot land on a different runtime.
118
+ * - No `detect_drift`, and no built-in gates: drift asked a fresh session with
119
+ * no memory to grade work it never saw and re-ran tasks on its guess, and the
120
+ * built-in gates either repeated the full suite per task or read a diff that
121
+ * was not committed yet.
122
+ * - `gate_retries: 1` when there are gates: one agent attempt to fix a failing
123
+ * check on the merged result, rather than a finished run reported red over a
124
+ * lint error.
52
125
  */
53
- export function buildConvoyYaml(plan, enrichment) {
126
+ export function buildConvoyYaml(plan, settings) {
54
127
  const tasks = plan.tasks.map((task) => {
55
128
  const t = {};
56
129
  t.id = task.id;
@@ -66,11 +139,7 @@ export function buildConvoyYaml(plan, enrichment) {
66
139
  t.max_retries = task.max_retries;
67
140
  if (task.review !== undefined)
68
141
  t.review = task.review;
69
- if (task.gates !== undefined)
70
- t.gates = task.gates;
71
- if (task.built_in_gates !== undefined)
72
- t.built_in_gates = task.built_in_gates;
73
- // Auto-populate from effort table when complexity is set and fields are missing
142
+ // The effort table fills in what the planner left out, from its complexity score.
74
143
  if (task.complexity !== undefined) {
75
144
  const profile = getEffortProfile(task.complexity);
76
145
  if (t.timeout === undefined)
@@ -87,41 +156,297 @@ export function buildConvoyYaml(plan, enrichment) {
87
156
  const spec = {
88
157
  name: plan.name,
89
158
  version: 1,
90
- concurrency: plan.concurrency ?? 2,
91
- on_failure: plan.on_failure ?? 'stop',
92
- };
93
- if (plan.branch !== undefined)
94
- spec.branch = plan.branch;
95
- const defaults = {
96
- timeout: '30m',
97
- max_retries: 1,
98
- review: 'fast',
159
+ adapter: settings.adapter,
160
+ branch: settings.branch,
161
+ concurrency: planConcurrency(plan),
162
+ on_failure: 'continue',
99
163
  };
100
- if (enrichment?.circuit_breaker)
101
- defaults.circuit_breaker = enrichment.circuit_breaker;
102
- if (enrichment?.detect_drift)
103
- defaults.detect_drift = enrichment.detect_drift;
104
- if (enrichment?.built_in_gates)
105
- defaults.built_in_gates = enrichment.built_in_gates;
106
- if (enrichment?.max_concurrent_reviews)
107
- defaults.max_concurrent_reviews = enrichment.max_concurrent_reviews;
108
- spec.defaults = defaults;
109
- // guard is spec-level (not inside defaults)
110
- if (enrichment?.guard)
111
- spec.guard = enrichment.guard;
164
+ if (settings.gates.length > 0) {
165
+ spec.gates = settings.gates;
166
+ spec.gate_retries = 1;
167
+ }
168
+ spec.defaults = { timeout: '30m', max_retries: 1, review: 'fast' };
112
169
  spec.tasks = tasks;
113
- if (plan.gates !== undefined)
114
- spec.gates = plan.gates;
115
- if (plan.gate_retries !== undefined)
116
- spec.gate_retries = plan.gate_retries;
117
- const header = `# .opencastle/convoys/${toKebabCase(plan.name)}.convoy.yml\n`;
118
- const yaml = stringify(spec, {
119
- lineWidth: 120,
120
- defaultKeyType: 'PLAIN',
121
- defaultStringType: 'PLAIN',
170
+ const header = '# Written by `opencastle convoy`. Edit it if you like, then run it with:\n' +
171
+ '# opencastle convoy run <this file>\n';
172
+ return header + stringify(spec, { lineWidth: 120, defaultKeyType: 'PLAIN', defaultStringType: 'PLAIN' });
173
+ }
174
+ // ── Files ───────────────────────────────────────────────────────────────────
175
+ function isGlob(path) {
176
+ return path.includes('*') || path.includes('?');
177
+ }
178
+ /**
179
+ * Every `files` entry as a concrete path or directory.
180
+ *
181
+ * The engine refuses a glob, and refused it only after the run had been
182
+ * recorded. A glob is reduced to the directory in front of its first wildcard
183
+ * (`src/**\/*.ts` → `src/`), which claims at least what the glob did. One with
184
+ * no directory in front (`*.md`) would claim the whole project, so it is
185
+ * dropped and reported instead.
186
+ */
187
+ export function normalizePlanFiles(plan) {
188
+ const notes = [];
189
+ const tasks = plan.tasks.map((task) => {
190
+ if (!task.files?.length)
191
+ return task;
192
+ const files = [];
193
+ for (const raw of task.files) {
194
+ let path = raw.trim();
195
+ if (isGlob(path)) {
196
+ const segments = path.replace(/\\/g, '/').split('/');
197
+ const fixed = segments.slice(0, segments.findIndex(isGlob));
198
+ if (fixed.length === 0 || fixed.every((s) => s === '' || s === '.')) {
199
+ notes.push(`${task.id}: dropped "${raw}" — a pattern at the project root would claim everything`);
200
+ continue;
201
+ }
202
+ path = fixed.join('/') + '/';
203
+ notes.push(`${task.id}: "${raw}" → "${path}"`);
204
+ }
205
+ if (path && !files.includes(path))
206
+ files.push(path);
207
+ }
208
+ return { ...task, files };
122
209
  });
123
- return header + yaml;
210
+ return { plan: { ...plan, tasks }, notes };
211
+ }
212
+ /** For each task, every task it waits for, directly or not. */
213
+ function ancestors(plan) {
214
+ const byId = new Map(plan.tasks.map((t) => [t.id, t]));
215
+ const memo = new Map();
216
+ const visit = (id, path) => {
217
+ const known = memo.get(id);
218
+ if (known)
219
+ return known;
220
+ const out = new Set();
221
+ if (path.has(id))
222
+ return out; // a cycle; checkPlan reports it
223
+ path.add(id);
224
+ for (const dep of byId.get(id)?.depends_on ?? []) {
225
+ if (!byId.has(dep))
226
+ continue;
227
+ out.add(dep);
228
+ for (const a of visit(dep, path))
229
+ out.add(a);
230
+ }
231
+ path.delete(id);
232
+ memo.set(id, out);
233
+ return out;
234
+ };
235
+ for (const t of plan.tasks)
236
+ visit(t.id, new Set());
237
+ return memo;
238
+ }
239
+ /**
240
+ * Pairs of tasks that may run at the same time and claim the same files.
241
+ *
242
+ * "At the same time" means neither waits for the other, directly or through
243
+ * others. That is stricter than the engine's check, which compares tasks
244
+ * phase by phase, and it is the right one for a scheduler that starts a task
245
+ * the moment its dependencies finish: two tasks in different phases can still
246
+ * overlap in time. Compared case-insensitively too, because the spec may run
247
+ * on macOS or Windows.
248
+ */
249
+ function conflicts(plan) {
250
+ const before = ancestors(plan);
251
+ const normalized = new Map();
252
+ for (const t of plan.tasks) {
253
+ const paths = [];
254
+ for (const f of t.files ?? []) {
255
+ try {
256
+ paths.push(normalizePath(f));
257
+ }
258
+ catch {
259
+ // Reported by checkPlan.
260
+ }
261
+ }
262
+ normalized.set(t.id, paths);
263
+ }
264
+ const found = [];
265
+ for (let i = 0; i < plan.tasks.length; i++) {
266
+ for (let j = i + 1; j < plan.tasks.length; j++) {
267
+ const a = plan.tasks[i];
268
+ const b = plan.tasks[j];
269
+ if (before.get(a.id)?.has(b.id) || before.get(b.id)?.has(a.id))
270
+ continue;
271
+ const paths = [];
272
+ for (const pa of normalized.get(a.id) ?? []) {
273
+ for (const pb of normalized.get(b.id) ?? []) {
274
+ if (pathsOverlap(pa, pb) || pathsOverlap(pa.toLowerCase(), pb.toLowerCase())) {
275
+ if (!paths.includes(pa))
276
+ paths.push(pa);
277
+ }
278
+ }
279
+ }
280
+ if (paths.length)
281
+ found.push({ first: a.id, second: b.id, paths });
282
+ }
283
+ }
284
+ return found;
285
+ }
286
+ /**
287
+ * Everything the code can check about a plan before an agent runs it.
288
+ *
289
+ * The schema the runner applies, plus the two rules the engine enforces only
290
+ * once the run has started: no globs, and no two concurrent tasks on the same
291
+ * files. An empty list means the engine will accept the spec.
292
+ */
293
+ const TEST_PATH = /(^|\/)(tests?|__tests__|spec)\/|\.(test|spec)\.[cm]?[jt]sx?$|_test\.(go|py)$|(^|\/)test_[^/]+\.py$/;
294
+ /**
295
+ * Fold a task that only writes tests for one other task into that task.
296
+ *
297
+ * Planners split work into "write the code" and "test the code" even when told
298
+ * not to: three real runs did it every time. Each split is another session,
299
+ * review and merge, and the agent that wrote the code never runs a test against
300
+ * it. A task folds in when every file it owns is a test file, it depends on
301
+ * exactly one task, nothing else claims its files, and that task is not itself
302
+ * test-only. Tasks that waited on it wait on the merged task instead.
303
+ */
304
+ export function foldTestOnlyTasks(plan) {
305
+ const byId = new Map(plan.tasks.map((t) => [t.id, { ...t, files: [...(t.files ?? [])], depends_on: [...(t.depends_on ?? [])] }]));
306
+ const isTestOnly = (t) => (t.files ?? []).length > 0 && (t.files ?? []).every((f) => TEST_PATH.test(f));
307
+ const folded = [];
308
+ // A dependency another dependency already waits on adds nothing: tests that
309
+ // list both a store change and the routes built on it test the routes.
310
+ const ancestors = (id, seen = new Set()) => {
311
+ for (const d of byId.get(id)?.depends_on ?? []) {
312
+ if (!seen.has(d)) {
313
+ seen.add(d);
314
+ ancestors(d, seen);
315
+ }
316
+ }
317
+ return seen;
318
+ };
319
+ const direct = (deps) => deps.filter((d) => !deps.some((o) => o !== d && ancestors(o).has(d)));
320
+ for (const task of plan.tasks) {
321
+ const t = byId.get(task.id);
322
+ if (!t || !isTestOnly(t))
323
+ continue;
324
+ const deps = direct(t.depends_on);
325
+ if (deps.length !== 1)
326
+ continue;
327
+ const target = byId.get(deps[0]);
328
+ if (!target || isTestOnly(target))
329
+ continue;
330
+ const claimedElsewhere = [...byId.values()].some((o) => o.id !== t.id && o.id !== target.id && (o.files ?? []).some((f) => t.files.includes(f)));
331
+ if (claimedElsewhere)
332
+ continue;
333
+ target.files = [...new Set([...(target.files ?? []), ...t.files])];
334
+ target.prompt = `${target.prompt.trimEnd()}\n\nIn the same session, write the tests for this change:\n${t.prompt.trim()}`;
335
+ byId.delete(t.id);
336
+ for (const other of byId.values()) {
337
+ if (other.depends_on.includes(t.id)) {
338
+ other.depends_on = [...new Set(other.depends_on.map((d) => (d === t.id ? target.id : d)))].filter((d) => d !== other.id);
339
+ }
340
+ }
341
+ folded.push([t.id, target.id]);
342
+ }
343
+ return { plan: { ...plan, tasks: plan.tasks.filter((t) => byId.has(t.id)).map((t) => byId.get(t.id)) }, folded };
344
+ }
345
+ export function checkPlan(plan, settings) {
346
+ const problems = [];
347
+ const shape = planShapeProblem(plan);
348
+ if (shape) {
349
+ problems.push(`Plan: ${shape}`);
350
+ }
351
+ else {
352
+ try {
353
+ const { valid, errors } = validateSpec(parseYaml(buildConvoyYaml(plan, settings)));
354
+ if (!valid)
355
+ problems.push(...errors.map((e) => `Schema: ${e}`));
356
+ }
357
+ catch (err) {
358
+ problems.push(`Schema: ${err instanceof Error ? err.message : String(err)}`);
359
+ }
360
+ }
361
+ for (const task of plan.tasks) {
362
+ for (const f of task.files ?? []) {
363
+ if (isGlob(f)) {
364
+ problems.push(`Task "${task.id}": files entry "${f}" is a pattern — name a file or a directory`);
365
+ continue;
366
+ }
367
+ if (/^([A-Za-z]:)?[\\/]/.test(f)) {
368
+ problems.push(`Task "${task.id}": files entry "${f}" must be relative to the project root`);
369
+ continue;
370
+ }
371
+ try {
372
+ normalizePath(f);
373
+ }
374
+ catch (err) {
375
+ problems.push(`Task "${task.id}": ${err instanceof Error ? err.message : String(err)}`);
376
+ }
377
+ }
378
+ }
379
+ for (const c of conflicts(plan)) {
380
+ problems.push(`Tasks "${c.first}" and "${c.second}" can run at the same time but both claim ${c.paths.join(', ')}` +
381
+ ` — give each its own files, or make one depend on the other`);
382
+ }
383
+ return problems;
384
+ }
385
+ /**
386
+ * Make the later of each conflicting pair wait for the earlier.
387
+ *
388
+ * The last resort, after fix-convoy has had its rounds: it costs parallelism,
389
+ * never correctness, and it cannot create a cycle — an edge is only added
390
+ * between two tasks that do not yet wait for each other in either direction.
391
+ */
392
+ export function sequenceConflicts(plan) {
393
+ let current = structuredClone(plan);
394
+ const added = [];
395
+ for (;;) {
396
+ const [next] = conflicts(current);
397
+ if (!next)
398
+ break;
399
+ current = {
400
+ ...current,
401
+ tasks: current.tasks.map((t) => t.id === next.second ? { ...t, depends_on: [...(t.depends_on ?? []), next.first] } : t),
402
+ };
403
+ added.push([next.second, next.first]);
404
+ }
405
+ return { plan: current, added };
124
406
  }
407
+ /**
408
+ * One plan from the plans written for each group of a large feature.
409
+ *
410
+ * Groups used to become a chain of separate specs run one after another, even
411
+ * when the assessment said two of them were independent. Here a group's first
412
+ * tasks wait for the last tasks of every group it depends on, and nothing else
413
+ * is added: independent groups run side by side under the normal scheduler,
414
+ * and the user gets one spec, one plan to read and one run to resume.
415
+ *
416
+ * Two groups can both name a task `setup`. The later one is renamed
417
+ * `<group>-setup`, with its group's references to it.
418
+ *
419
+ * `groups` must come in dependency order (topologicalSortGroups).
420
+ */
421
+ export function mergeGroupPlans(name, groups) {
422
+ const taken = new Set();
423
+ const sinks = new Map();
424
+ const tasks = [];
425
+ for (const group of groups) {
426
+ const rename = new Map();
427
+ for (const t of group.plan.tasks) {
428
+ let id = t.id;
429
+ if (taken.has(id)) {
430
+ id = `${group.name}-${t.id}`;
431
+ for (let n = 2; taken.has(id); n++)
432
+ id = `${group.name}-${t.id}-${n}`;
433
+ }
434
+ taken.add(id);
435
+ rename.set(t.id, id);
436
+ }
437
+ const upstream = group.depends_on.flatMap((g) => sinks.get(g) ?? []);
438
+ const dependedOn = new Set(group.plan.tasks.flatMap((t) => t.depends_on ?? []));
439
+ for (const t of group.plan.tasks) {
440
+ const own = (t.depends_on ?? []).map((d) => rename.get(d) ?? d);
441
+ // A copy each: a shared array would come out of the YAML writer as an anchor.
442
+ const depends_on = own.length > 0 ? own : [...upstream];
443
+ tasks.push({ ...t, id: rename.get(t.id), depends_on });
444
+ }
445
+ sinks.set(group.name, group.plan.tasks.filter((t) => !dependedOn.has(t.id)).map((t) => rename.get(t.id)));
446
+ }
447
+ return { name, tasks };
448
+ }
449
+ // ── Patches and parsing ─────────────────────────────────────────────────────
125
450
  /**
126
451
  * Applies an array of patches to a task plan. Returns a new TaskPlan (immutable).
127
452
  */
@@ -158,7 +483,6 @@ function detectJsonTruncation(jsonText) {
158
483
  const trimmed = jsonText.trim();
159
484
  if (!trimmed)
160
485
  return 'empty output';
161
- // Count open/close braces and brackets
162
486
  let braces = 0;
163
487
  let brackets = 0;
164
488
  let inString = false;
@@ -191,14 +515,13 @@ export function parseTaskPlan(jsonText) {
191
515
  return parseTaskPlanWithReason(jsonText).plan;
192
516
  }
193
517
  /**
194
- * Like parseTaskPlan but returns a diagnostic reason on failure.
518
+ * Like parseTaskPlan but returns a diagnostic reason on failure, for the caller
519
+ * to report.
195
520
  */
196
521
  export function parseTaskPlanWithReason(jsonText) {
197
522
  const truncation = detectJsonTruncation(jsonText);
198
- if (truncation) {
199
- console.warn(` ⚠ parseTaskPlan: ${truncation}`);
523
+ if (truncation)
200
524
  return { plan: null, reason: truncation };
201
- }
202
525
  let parsed;
203
526
  try {
204
527
  parsed = JSON.parse(jsonText.trim());
@@ -206,26 +529,35 @@ export function parseTaskPlanWithReason(jsonText) {
206
529
  catch (err) {
207
530
  return { plan: null, reason: `JSON.parse failed: ${err instanceof Error ? err.message : String(err)}` };
208
531
  }
532
+ const problem = planShapeProblem(parsed);
533
+ if (problem)
534
+ return { plan: null, reason: problem };
535
+ return { plan: parsed };
536
+ }
537
+ /**
538
+ * What makes an object not a task plan, or null: a name, a non-empty task list,
539
+ * unique ids, a prompt each, dependencies that exist, and no cycle.
540
+ */
541
+ function planShapeProblem(parsed) {
209
542
  if (!parsed || typeof parsed.name !== 'string') {
210
- return { plan: null, reason: `missing or invalid top-level "name" field (got ${typeof parsed?.name})` };
543
+ return `missing or invalid top-level "name" field (got ${typeof parsed?.name})`;
211
544
  }
212
545
  if (!Array.isArray(parsed.tasks) || parsed.tasks.length === 0) {
213
- return { plan: null, reason: `missing or empty "tasks" array` };
546
+ return `missing or empty "tasks" array`;
214
547
  }
215
- for (let i = 0; i < parsed.tasks.length; i++) {
216
- const t = parsed.tasks[i];
217
- if (typeof t.id !== 'string') {
218
- return { plan: null, reason: `task[${i}] missing "id" field` };
219
- }
548
+ const tasks = parsed.tasks;
549
+ for (let i = 0; i < tasks.length; i++) {
550
+ const t = tasks[i];
551
+ if (!t || typeof t !== 'object')
552
+ return `task[${i}] is not an object`;
553
+ if (typeof t.id !== 'string')
554
+ return `task[${i}] missing "id" field`;
220
555
  if (typeof t.prompt !== 'string') {
221
- return { plan: null, reason: `task "${t.id ?? i}" missing "prompt" field (has keys: ${Object.keys(t).join(', ')})` };
222
- }
223
- if (t.prompt.length === 0) {
224
- return { plan: null, reason: `task "${t.id}" has empty "prompt" field` };
556
+ return `task "${t.id}" missing "prompt" field (has keys: ${Object.keys(t).join(', ')})`;
225
557
  }
558
+ if (t.prompt.length === 0)
559
+ return `task "${t.id}" has empty "prompt" field`;
226
560
  }
227
- // Validate unique task IDs
228
- const tasks = parsed.tasks;
229
561
  const ids = new Set();
230
562
  const duplicates = [];
231
563
  for (const task of tasks) {
@@ -234,19 +566,15 @@ export function parseTaskPlanWithReason(jsonText) {
234
566
  duplicates.push(id);
235
567
  ids.add(id);
236
568
  }
237
- if (duplicates.length > 0) {
238
- console.warn(` ⚠ parseTaskPlan: duplicate task IDs: ${duplicates.join(', ')}`);
239
- return { plan: null, reason: `duplicate task IDs: ${duplicates.join(', ')}` };
240
- }
241
- // Validate depends_on references
569
+ if (duplicates.length > 0)
570
+ return `duplicate task IDs: ${duplicates.join(', ')}`;
242
571
  for (const task of tasks) {
243
- if (Array.isArray(task.depends_on)) {
244
- for (const dep of task.depends_on) {
245
- if (!ids.has(dep)) {
246
- console.warn(` ⚠ parseTaskPlan: task "${task.id}" depends on unknown task "${dep}"`);
247
- return { plan: null, reason: `task "${task.id}" depends on unknown task "${dep}"` };
248
- }
249
- }
572
+ if (task.depends_on !== undefined && !Array.isArray(task.depends_on)) {
573
+ return `task "${task.id}" has a depends_on that is not a list`;
574
+ }
575
+ for (const dep of task.depends_on ?? []) {
576
+ if (!ids.has(dep))
577
+ return `task "${task.id}" depends on unknown task "${dep}"`;
250
578
  }
251
579
  }
252
580
  // Cycle detection (Kahn's algorithm)
@@ -257,11 +585,9 @@ export function parseTaskPlanWithReason(jsonText) {
257
585
  adj.set(id, []);
258
586
  }
259
587
  for (const task of tasks) {
260
- if (Array.isArray(task.depends_on)) {
261
- for (const dep of task.depends_on) {
262
- adj.get(dep).push(task.id);
263
- inDegree.set(task.id, (inDegree.get(task.id) ?? 0) + 1);
264
- }
588
+ for (const dep of task.depends_on ?? []) {
589
+ adj.get(dep).push(task.id);
590
+ inDegree.set(task.id, (inDegree.get(task.id) ?? 0) + 1);
265
591
  }
266
592
  }
267
593
  const queue = [...ids].filter(id => inDegree.get(id) === 0);
@@ -276,11 +602,9 @@ export function parseTaskPlanWithReason(jsonText) {
276
602
  queue.push(next);
277
603
  }
278
604
  }
279
- if (visited < ids.size) {
280
- console.warn(` ⚠ parseTaskPlan: dependency cycle detected`);
281
- return { plan: null, reason: 'dependency cycle detected' };
282
- }
283
- return { plan: parsed };
605
+ if (visited < ids.size)
606
+ return 'dependency cycle detected';
607
+ return null;
284
608
  }
285
609
  /**
286
610
  * Parses a JSON string into a TaskPatch[]. Returns null if parsing fails.