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
@@ -97,6 +97,17 @@ function makeSpec(
97
97
  }
98
98
  }
99
99
 
100
+ /** A non-terminal output stream that remembers what the engine printed. */
101
+ function captureOutput(): { stream: { write(s: string): boolean; isTTY: boolean }; text(): string } {
102
+ const chunks: string[] = []
103
+ return {
104
+ stream: { isTTY: false, write: (s: string) => { chunks.push(s); return true } },
105
+ // Colour codes stripped, so assertions read like the terminal.
106
+ // eslint-disable-next-line no-control-regex
107
+ text: () => chunks.join('').replace(/\x1b\[[0-9;]*m/g, ''),
108
+ }
109
+ }
110
+
100
111
  /** Wraps createConvoyEngine with a default no-op _ensureBranch mock so tests never
101
112
  * run real git branch operations. Callers can override _ensureBranch if needed. */
102
113
  function makeEngine(opts: ConvoyEngineOptions): ReturnType<typeof createConvoyEngine> {
@@ -105,6 +116,8 @@ function makeEngine(opts: ConvoyEngineOptions): ReturnType<typeof createConvoyEn
105
116
  basePath: tmpDir, // ditto for the .opencastle/ ledgers
106
117
  _ensureBranch: vi.fn().mockResolvedValue(undefined),
107
118
  _convoyWorktreeDir: null,
119
+ handleSignals: false,
120
+ output: captureOutput().stream,
108
121
  ...opts,
109
122
  })
110
123
  }
@@ -194,7 +207,9 @@ describe('single task failure', () => {
194
207
  expect(result.summary.done).toBe(0)
195
208
  })
196
209
 
197
- it('calls adapter.kill when the task fails', async () => {
210
+ it('leaves a session that already exited alone', async () => {
211
+ // kill() is for a session still running — a timeout or Ctrl+C. The old
212
+ // engine also called it after every failure, on a process already gone.
198
213
  const adapter = makeAdapter()
199
214
  adapter.execute.mockResolvedValue({ success: false, output: 'boom', exitCode: 1 })
200
215
 
@@ -209,7 +224,27 @@ describe('single task failure', () => {
209
224
 
210
225
  await engine.run()
211
226
 
212
- expect(adapter.kill).toHaveBeenCalledOnce()
227
+ expect(adapter.kill).not.toHaveBeenCalled()
228
+ })
229
+
230
+ it('prints the first line of the reason on the ✗ line', async () => {
231
+ const adapter = makeAdapter()
232
+ adapter.execute.mockResolvedValue({ success: false, output: 'TypeError: x is undefined\n at foo (a.ts:1)', exitCode: 1 })
233
+ const out = captureOutput()
234
+ const engine = makeEngine({
235
+ spec: makeSpec({}, [{ id: 'task-1', max_retries: 0 }]),
236
+ specYaml: 'name: test',
237
+ adapter,
238
+ dbPath,
239
+ output: out.stream,
240
+ _worktreeManager: makeWorktreeManager(),
241
+ _mergeQueue: makeMergeQueue(),
242
+ })
243
+ await engine.run()
244
+ const line = out.text().split('\n').find(l => l.includes('✗') && l.includes('[task-1]'))!
245
+ expect(line).toContain('failed')
246
+ expect(line).toContain('TypeError: x is undefined')
247
+ expect(line).not.toContain('at foo')
213
248
  })
214
249
  })
215
250
 
@@ -389,7 +424,9 @@ describe('on_failure:stop', () => {
389
424
  expect(byId['task-c']).toBe('skipped')
390
425
  })
391
426
 
392
- it('does not retry when on_failure is stop even if max_retries > 0', async () => {
427
+ it('still retries a task up to max_retries — stop is about what happens after it fails for good', async () => {
428
+ // The spec builder's default was `stop`, and it used to turn off every
429
+ // retry in every generated plan.
393
430
  const adapter = makeAdapter()
394
431
  adapter.execute.mockResolvedValue({ success: false, output: 'fail', exitCode: 1 })
395
432
 
@@ -405,8 +442,37 @@ describe('on_failure:stop', () => {
405
442
 
406
443
  await engine.run()
407
444
 
408
- // No retries — stop mode skips them
409
- expect(adapter.execute).toHaveBeenCalledOnce()
445
+ expect(adapter.execute).toHaveBeenCalledTimes(4)
446
+ })
447
+
448
+ it('lets running tasks finish and starts nothing new once a task has failed for good', async () => {
449
+ const started: string[] = []
450
+ const adapter = makeAdapter()
451
+ adapter.execute.mockImplementation(async (task: Task) => {
452
+ started.push(task.id)
453
+ if (task.id === 'a-fails') return { success: false, output: 'nope', exitCode: 1 }
454
+ await new Promise(r => setTimeout(r, 60))
455
+ return { success: true, output: 'ok', exitCode: 0 }
456
+ })
457
+ // Two slots: `fails` and `slow` start together; `later` is queued behind them.
458
+ const spec = makeSpec({ on_failure: 'stop', concurrency: 2 }, [
459
+ { id: 'a-fails' },
460
+ { id: 'b-slow' },
461
+ { id: 'c-later' },
462
+ ])
463
+ const engine = makeEngine({
464
+ spec, specYaml: 'name: test', adapter, dbPath,
465
+ _worktreeManager: makeWorktreeManager(), _mergeQueue: makeMergeQueue(),
466
+ })
467
+
468
+ const result = await engine.run()
469
+
470
+ expect(started.sort()).toEqual(['a-fails', 'b-slow'])
471
+ const store = createConvoyStore(dbPath)
472
+ const byId = Object.fromEntries(store.getTasksByConvoy(result.convoyId).map(t => [t.id, t.status]))
473
+ store.close()
474
+ expect(byId).toEqual({ 'a-fails': 'failed', 'b-slow': 'done', 'c-later': 'skipped' })
475
+ expect(result.status).toBe('failed')
410
476
  })
411
477
  })
412
478
 
@@ -799,7 +865,8 @@ describe('worktree lifecycle (non-copilot)', () => {
799
865
  expect(wtManager.remove).toHaveBeenCalledOnce()
800
866
  })
801
867
 
802
- it('continues task execution when worktree creation throws', async () => {
868
+ it('fails the task, never running it in the user checkout, when worktree creation throws', async () => {
869
+ // It used to fall back to running the agent in basePath — the user's own tree.
803
870
  const adapter = makeAdapter('developer')
804
871
  const wtManager = makeWorktreeManager()
805
872
  wtManager.create.mockRejectedValue(new Error('git worktree unavailable'))
@@ -814,38 +881,54 @@ describe('worktree lifecycle (non-copilot)', () => {
814
881
  _mergeQueue: mergeQueue,
815
882
  })
816
883
 
817
- // Task should still succeed even without a worktree
818
884
  const result = await engine.run()
819
- expect(result.status).toBe('done')
820
- expect(adapter.execute).toHaveBeenCalledOnce()
885
+ expect(result.status).toBe('failed')
886
+ expect(adapter.execute).not.toHaveBeenCalled()
821
887
  })
822
888
 
823
- it('task still succeeds when merge throws', async () => {
889
+ it('fails the task and keeps its branch when the merge throws', async () => {
890
+ // A merge error used to be logged under --verbose, set `merged = true`, and
891
+ // delete the branch: the task read "done" and its work was gone.
824
892
  const adapter = makeAdapter('developer')
825
893
  const wtManager = makeWorktreeManager()
826
894
  const mergeQueue = makeMergeQueue()
827
- mergeQueue.merge.mockRejectedValue(new Error('merge conflict'))
895
+ mergeQueue.merge.mockRejectedValue(new Error('cannot lock ref HEAD'))
896
+ const out = captureOutput()
828
897
 
829
898
  const engine = makeEngine({
830
899
  spec: makeSpec(),
831
900
  specYaml: 'name: test',
832
901
  adapter,
833
902
  dbPath,
903
+ output: out.stream,
834
904
  _worktreeManager: wtManager,
835
905
  _mergeQueue: mergeQueue,
836
906
  })
837
907
 
838
908
  const result = await engine.run()
839
- // task is still marked done despite the merge warning
840
- expect(result.status).toBe('done')
841
- expect(wtManager.remove).toHaveBeenCalledOnce()
909
+ expect(result.status).toBe('failed')
910
+ expect(wtManager.remove).toHaveBeenCalledWith('/tmp/worktree-mock', { keepBranch: true })
911
+
912
+ const store = createConvoyStore(dbPath)
913
+ const task = store.getTask('task-1', result.convoyId)!
914
+ const events = store.getEvents(result.convoyId)
915
+ store.close()
916
+ expect(task.status).toBe('failed')
917
+ expect(task.branch).toMatch(/^convoy-/)
918
+ expect(result.keptBranches).toEqual([{ taskId: 'task-1', branch: task.branch }])
919
+ const mergeFailed = events.find(e => e.type === 'merge_failed')!
920
+ expect(JSON.parse(mergeFailed.data!)).toMatchObject({ branch: task.branch, error: 'cannot lock ref HEAD' })
921
+ // Said where the person will see it, not only under --verbose.
922
+ expect(out.text()).toContain('cannot lock ref HEAD')
923
+ expect(out.text()).toContain(task.branch!)
842
924
  })
843
925
  })
844
926
 
845
- // ── 10. Copilot adapter skips worktree ────────────────────────────────────────
927
+ // ── 10. Copilot gets a worktree like every runtime ────────────────────────────
846
928
 
847
929
  describe('copilot adapter', () => {
848
- it('skips worktree create, merge, and remove for copilot adapter', async () => {
930
+ it('runs in a worktree and is merged like any other runtime', async () => {
931
+ // Copilot used to skip worktrees and work in the shared directory, never merged.
849
932
  const adapter = makeAdapter('copilot')
850
933
  const wtManager = makeWorktreeManager()
851
934
  const mergeQueue = makeMergeQueue()
@@ -862,9 +945,9 @@ describe('copilot adapter', () => {
862
945
  const result = await engine.run()
863
946
 
864
947
  expect(result.status).toBe('done')
865
- expect(wtManager.create).not.toHaveBeenCalled()
866
- expect(mergeQueue.merge).not.toHaveBeenCalled()
867
- expect(wtManager.remove).not.toHaveBeenCalled()
948
+ expect(wtManager.create).toHaveBeenCalledOnce()
949
+ expect(mergeQueue.merge).toHaveBeenCalledOnce()
950
+ expect(adapter.execute.mock.calls[0][1]).toMatchObject({ cwd: '/tmp/worktree-mock' })
868
951
  })
869
952
  })
870
953
 
@@ -894,7 +977,6 @@ describe('timeout handling', () => {
894
977
 
895
978
  expect(result.status).toBe('failed')
896
979
  expect(result.summary.timedOut).toBe(1)
897
- expect(adapter.kill).toHaveBeenCalledOnce()
898
980
  })
899
981
 
900
982
  it('retries a timed-out task when retries remain', async () => {
@@ -924,7 +1006,7 @@ describe('timeout handling', () => {
924
1006
  expect(adapter.execute).toHaveBeenCalledTimes(2)
925
1007
  })
926
1008
 
927
- it('does not retry a timed-out task when on_failure is stop', async () => {
1009
+ it('retries a timed-out task under on_failure: stop too', async () => {
928
1010
  const adapter = makeAdapter()
929
1011
  adapter.execute.mockResolvedValue({
930
1012
  _timedOut: true,
@@ -945,7 +1027,7 @@ describe('timeout handling', () => {
945
1027
  const result = await engine.run()
946
1028
 
947
1029
  expect(result.summary.timedOut).toBe(1)
948
- expect(adapter.execute).toHaveBeenCalledOnce()
1030
+ expect(adapter.execute).toHaveBeenCalledTimes(3)
949
1031
  })
950
1032
  })
951
1033
 
@@ -1177,44 +1259,6 @@ describe('verbose mode', () => {
1177
1259
  const result = await engine.run()
1178
1260
  expect(result.status).toBe('done')
1179
1261
  })
1180
-
1181
- it('logs verbose warning when worktree creation fails', async () => {
1182
- const adapter = makeAdapter('developer')
1183
- const wtManager = makeWorktreeManager()
1184
- wtManager.create.mockRejectedValue(new Error('no worktrees'))
1185
-
1186
- const engine = makeEngine({
1187
- spec: makeSpec({}, [{ id: 'task-1' }]),
1188
- specYaml: 'name: test',
1189
- adapter,
1190
- verbose: true,
1191
- dbPath,
1192
- _worktreeManager: wtManager,
1193
- _mergeQueue: makeMergeQueue(),
1194
- })
1195
-
1196
- const result = await engine.run()
1197
- expect(result.status).toBe('done')
1198
- })
1199
-
1200
- it('logs verbose warning when merge fails', async () => {
1201
- const adapter = makeAdapter('developer')
1202
- const mergeQueue = makeMergeQueue()
1203
- mergeQueue.merge.mockRejectedValue(new Error('merge conflict'))
1204
-
1205
- const engine = makeEngine({
1206
- spec: makeSpec({}, [{ id: 'task-1' }]),
1207
- specYaml: 'name: test',
1208
- adapter,
1209
- verbose: true,
1210
- dbPath,
1211
- _worktreeManager: makeWorktreeManager(),
1212
- _mergeQueue: mergeQueue,
1213
- })
1214
-
1215
- const result = await engine.run()
1216
- expect(result.status).toBe('done')
1217
- })
1218
1262
  })
1219
1263
 
1220
1264
  // ── 16. msToTimeout branch coverage ──────────────────────────────────────────
@@ -1317,11 +1361,10 @@ describe('per-task adapter resolution', () => {
1317
1361
  expect(getAdapter).not.toHaveBeenCalled()
1318
1362
  })
1319
1363
 
1320
- it('resolves adapter: auto to detected adapter', async () => {
1364
+ it('treats adapter: auto as the run’s own runtime, without detecting again', async () => {
1365
+ // `auto` used to re-run detection for every task and could land on a
1366
+ // runtime the user never chose.
1321
1367
  const mainAdapter = makeAdapter('test')
1322
- const autoAdapter = makeAdapter('claude-code')
1323
- vi.mocked(detectAdapter).mockResolvedValue('claude-code')
1324
- vi.mocked(getAdapter).mockResolvedValue(autoAdapter)
1325
1368
 
1326
1369
  const spec = makeSpec({}, [{ adapter: 'auto' }])
1327
1370
  const engine = makeEngine({
@@ -1335,10 +1378,28 @@ describe('per-task adapter resolution', () => {
1335
1378
 
1336
1379
  await engine.run()
1337
1380
 
1338
- expect(detectAdapter).toHaveBeenCalled()
1339
- expect(getAdapter).toHaveBeenCalledWith('claude-code')
1340
- expect(autoAdapter.execute).toHaveBeenCalledOnce()
1341
- expect(mainAdapter.execute).not.toHaveBeenCalled()
1381
+ expect(detectAdapter).not.toHaveBeenCalled()
1382
+ expect(getAdapter).not.toHaveBeenCalled()
1383
+ expect(mainAdapter.execute).toHaveBeenCalledOnce()
1384
+ })
1385
+
1386
+ it('refuses an unknown per-task runtime before anything runs or is recorded', async () => {
1387
+ vi.mocked(getAdapter).mockRejectedValue(new Error('Unknown adapter "claud"'))
1388
+ const adapter = makeAdapter('test')
1389
+ const engine = makeEngine({
1390
+ spec: makeSpec({}, [{ id: 'a' }, { id: 'b', adapter: 'claud' }]),
1391
+ specYaml: 'name: test',
1392
+ adapter,
1393
+ dbPath,
1394
+ _worktreeManager: makeWorktreeManager(),
1395
+ _mergeQueue: makeMergeQueue(),
1396
+ })
1397
+
1398
+ await expect(engine.run()).rejects.toThrow('Unknown adapter "claud"')
1399
+ expect(adapter.execute).not.toHaveBeenCalled()
1400
+ const store = createConvoyStore(dbPath)
1401
+ expect(store.getLatestConvoy()).toBeUndefined()
1402
+ store.close()
1342
1403
  })
1343
1404
 
1344
1405
  it('stores per-task adapter name in worker record', async () => {
@@ -1595,7 +1656,135 @@ describe('cost tracking', () => {
1595
1656
 
1596
1657
  const result = await engine.run()
1597
1658
 
1598
- expect(result.cost).toEqual({ total_tokens: 75 })
1659
+ // No cost reported and no model named: the tokens are real, the cost is
1660
+ // unknown, and the total says it is incomplete.
1661
+ expect(result.cost).toEqual({ total_tokens: 75, estimated: true })
1662
+ })
1663
+
1664
+ it('records what the runtime reported: cost, model and cache tokens', async () => {
1665
+ const adapter = makeAdapter('claude')
1666
+ adapter.execute.mockResolvedValue({
1667
+ success: true,
1668
+ output: 'ok',
1669
+ exitCode: 0,
1670
+ usage: { prompt_tokens: 45_000, completion_tokens: 812, total_tokens: 45_812, cache_read_tokens: 40_000, cache_write_tokens: 4_000 },
1671
+ costUsd: 0.1234,
1672
+ model: 'claude-sonnet-4-6',
1673
+ } satisfies ExecuteResult)
1674
+
1675
+ const engine = makeEngine({
1676
+ spec: makeSpec(), specYaml: 'name: test', adapter, dbPath,
1677
+ _worktreeManager: makeWorktreeManager(), _mergeQueue: makeMergeQueue(),
1678
+ })
1679
+ const result = await engine.run()
1680
+
1681
+ const store = createConvoyStore(dbPath)
1682
+ const task = store.getTasksByConvoy(result.convoyId)[0]
1683
+ const convoy = store.getConvoy(result.convoyId)!
1684
+ store.close()
1685
+ expect(task).toMatchObject({
1686
+ total_tokens: 45_812,
1687
+ cache_read_tokens: 40_000,
1688
+ cache_write_tokens: 4_000,
1689
+ cost_usd: 0.1234,
1690
+ cost_estimated: 0,
1691
+ model: 'claude-sonnet-4-6',
1692
+ })
1693
+ expect(convoy.total_cost_usd).toBeCloseTo(0.1234)
1694
+ expect(convoy.cost_estimated).toBe(0)
1695
+ expect(convoy.adapter).toBe('claude')
1696
+ expect(result.cost).toEqual({ total_tokens: 45_812, total_cost_usd: 0.1234, estimated: false })
1697
+ })
1698
+
1699
+ it('never prices by the adapter’s name, and flags an estimate as one', async () => {
1700
+ // "claude" is a runtime, not a model; pricing it as Sonnet produced figures
1701
+ // that looked measured and were not.
1702
+ const adapter = makeAdapter('claude')
1703
+ const engine = makeEngine({
1704
+ spec: makeSpec(), specYaml: 'name: test', adapter, dbPath,
1705
+ _worktreeManager: makeWorktreeManager(), _mergeQueue: makeMergeQueue(),
1706
+ })
1707
+ const result = await engine.run()
1708
+
1709
+ const store = createConvoyStore(dbPath)
1710
+ const task = store.getTasksByConvoy(result.convoyId)[0]
1711
+ const convoy = store.getConvoy(result.convoyId)!
1712
+ store.close()
1713
+ expect(task.model).toBeNull()
1714
+ expect(task.cost_usd).toBeNull()
1715
+ expect(task.cost_estimated).toBe(1)
1716
+ expect(task.total_tokens).toBeGreaterThan(0)
1717
+ expect(convoy.cost_estimated).toBe(1)
1718
+ })
1719
+
1720
+ it('prices the model it was asked for when the runtime reports tokens but no cost — marked estimated', async () => {
1721
+ const adapter = makeAdapter('codex')
1722
+ adapter.execute.mockResolvedValue({
1723
+ success: true, output: 'ok', exitCode: 0,
1724
+ usage: { prompt_tokens: 1_000_000, completion_tokens: 0, total_tokens: 1_000_000 },
1725
+ } satisfies ExecuteResult)
1726
+ const engine = makeEngine({
1727
+ spec: makeSpec({}, [{ id: 'task-1', model: 'gpt-4o' }]), specYaml: 'name: test', adapter, dbPath,
1728
+ _worktreeManager: makeWorktreeManager(), _mergeQueue: makeMergeQueue(),
1729
+ })
1730
+ const result = await engine.run()
1731
+ const store = createConvoyStore(dbPath)
1732
+ const task = store.getTasksByConvoy(result.convoyId)[0]
1733
+ store.close()
1734
+ expect(task.cost_usd).toBeCloseTo(2.5)
1735
+ expect(task.cost_estimated).toBe(1)
1736
+ // The model is handed to the runtime as well.
1737
+ expect(adapter.execute.mock.calls[0][1]).toMatchObject({ model: 'gpt-4o' })
1738
+ })
1739
+
1740
+ it('runs each agent on the runtime\'s model for its tier when the spec names none', async () => {
1741
+ const adapter = makeAdapter('claude')
1742
+ ;(adapter as unknown as { tierModels: Record<string, string> }).tierModels = { premium: 'opus', standard: 'sonnet', economy: 'haiku' }
1743
+ const engine = makeEngine({
1744
+ spec: makeSpec({}, [
1745
+ { id: 'build', agent: 'developer' },
1746
+ { id: 'design', agent: 'architect' },
1747
+ { id: 'docs', agent: 'writer' },
1748
+ { id: 'pinned', agent: 'developer', model: 'opus' },
1749
+ ]),
1750
+ specYaml: 'name: test', adapter, dbPath,
1751
+ _worktreeManager: makeWorktreeManager(), _mergeQueue: makeMergeQueue(),
1752
+ })
1753
+ await engine.run()
1754
+ const modelFor = (id: string) =>
1755
+ adapter.execute.mock.calls.find((c: unknown[]) => (c[0] as { id: string }).id === id)?.[1]?.model
1756
+ expect(modelFor('build')).toBe('sonnet')
1757
+ expect(modelFor('design')).toBe('opus')
1758
+ expect(modelFor('docs')).toBe('haiku')
1759
+ // A model the spec names always wins.
1760
+ expect(modelFor('pinned')).toBe('opus')
1761
+ })
1762
+
1763
+ it('passes no model at all when the runtime declares no tier models', async () => {
1764
+ const adapter = makeAdapter('codex')
1765
+ const engine = makeEngine({
1766
+ spec: makeSpec({}, [{ id: 'build', agent: 'developer' }]), specYaml: 'name: test', adapter, dbPath,
1767
+ _worktreeManager: makeWorktreeManager(), _mergeQueue: makeMergeQueue(),
1768
+ })
1769
+ await engine.run()
1770
+ expect(adapter.execute.mock.calls[0][1]).not.toHaveProperty('model')
1771
+ })
1772
+
1773
+ it('adds up every attempt, not only the last', async () => {
1774
+ const adapter = makeAdapter()
1775
+ adapter.execute
1776
+ .mockResolvedValueOnce({ success: false, output: 'no', exitCode: 1, usage: { total_tokens: 100 }, costUsd: 0.01 })
1777
+ .mockResolvedValueOnce({ success: true, output: 'ok', exitCode: 0, usage: { total_tokens: 50 }, costUsd: 0.02 })
1778
+ const engine = makeEngine({
1779
+ spec: makeSpec({}, [{ id: 'task-1', max_retries: 1 }]), specYaml: 'name: test', adapter, dbPath,
1780
+ _worktreeManager: makeWorktreeManager(), _mergeQueue: makeMergeQueue(),
1781
+ })
1782
+ const result = await engine.run()
1783
+ const store = createConvoyStore(dbPath)
1784
+ const task = store.getTasksByConvoy(result.convoyId)[0]
1785
+ store.close()
1786
+ expect(task.total_tokens).toBe(150)
1787
+ expect(task.cost_usd).toBeCloseTo(0.03)
1599
1788
  })
1600
1789
 
1601
1790
  it('includes estimated cost in ConvoyResult when adapter returns no usage data', async () => {
@@ -1675,145 +1864,113 @@ describe('cost tracking', () => {
1675
1864
  // ── 22. Progress reporting (always-on output) ─────────────────────────────────
1676
1865
 
1677
1866
  describe('progress reporting', () => {
1678
- let stdoutSpy: ReturnType<typeof vi.spyOn>
1679
- let writtenChunks: string[]
1680
-
1681
- beforeEach(() => {
1682
- writtenChunks = []
1683
- stdoutSpy = vi.spyOn(process.stdout, 'write').mockImplementation((data) => {
1684
- writtenChunks.push(String(data))
1685
- return true
1686
- })
1687
- })
1688
-
1689
- afterEach(() => {
1690
- stdoutSpy.mockRestore()
1691
- })
1692
-
1693
- it('prints task start message without verbose flag', async () => {
1694
- const adapter = makeAdapter()
1695
- const engine = makeEngine({
1696
- spec: makeSpec(),
1867
+ function engineWith(out: ReturnType<typeof captureOutput>, spec: TaskSpec, adapter: MockAdapter) {
1868
+ return makeEngine({
1869
+ spec,
1697
1870
  specYaml: 'name: test',
1698
1871
  adapter,
1699
1872
  dbPath,
1873
+ output: out.stream,
1700
1874
  _worktreeManager: makeWorktreeManager(),
1701
1875
  _mergeQueue: makeMergeQueue(),
1702
1876
  })
1877
+ }
1703
1878
 
1704
- await engine.run()
1705
-
1706
- const written = writtenChunks.join('')
1707
- expect(written).toContain('[task-1]')
1708
- expect(written).toMatch(/▶/)
1879
+ it('prints a start line and a finish line for each task', async () => {
1880
+ const out = captureOutput()
1881
+ await engineWith(out, makeSpec(), makeAdapter()).run()
1882
+ const text = out.text()
1883
+ expect(text).toMatch(/▶ \[task-1\] developer/)
1884
+ expect(text).toMatch(/✓ \[task-1\] \(\d+ms\)/)
1709
1885
  })
1710
1886
 
1711
- it('prints task completion with counter', async () => {
1712
- const adapter = makeAdapter()
1713
- const engine = makeEngine({
1714
- spec: makeSpec(),
1715
- specYaml: 'name: test',
1716
- adapter,
1717
- dbPath,
1718
- _worktreeManager: makeWorktreeManager(),
1719
- _mergeQueue: makeMergeQueue(),
1720
- })
1721
-
1722
- await engine.run()
1887
+ it('does not print phases as barriers', async () => {
1888
+ const out = captureOutput()
1889
+ const spec = makeSpec({}, [{ id: 'task-a' }, { id: 'task-b', depends_on: ['task-a'] }])
1890
+ await engineWith(out, spec, makeAdapter()).run()
1891
+ expect(out.text()).not.toContain('Phase 1:')
1892
+ })
1723
1893
 
1724
- const written = writtenChunks.join('')
1725
- expect(written).toContain('[1/1]')
1726
- expect(written).toMatch(/✓/)
1894
+ it('prints no internal noise about missing output contracts', async () => {
1895
+ const out = captureOutput()
1896
+ await engineWith(out, makeSpec(), makeAdapter()).run()
1897
+ expect(out.text()).not.toContain('__contract_block')
1898
+ expect(out.text()).not.toContain('contract violation')
1727
1899
  })
1728
1900
 
1729
- it('prints task failure with counter', async () => {
1901
+ it('ends with the convoy id, the branch, the totals and the log path', async () => {
1902
+ const out = captureOutput()
1730
1903
  const adapter = makeAdapter()
1731
- adapter.execute.mockResolvedValue({ success: false, output: 'boom', exitCode: 1 })
1732
-
1733
- const engine = makeEngine({
1734
- spec: makeSpec({}, [{ id: 'task-1', max_retries: 0 }]),
1735
- specYaml: 'name: test',
1736
- adapter,
1737
- dbPath,
1738
- _worktreeManager: makeWorktreeManager(),
1739
- _mergeQueue: makeMergeQueue(),
1740
- })
1741
-
1742
- await engine.run()
1743
-
1744
- const written = writtenChunks.join('')
1745
- expect(written).toContain('[1/1]')
1746
- expect(written).toMatch(/✗/)
1904
+ adapter.execute.mockResolvedValue({ success: true, output: 'ok', exitCode: 0, usage: { total_tokens: 1500 } })
1905
+ const result = await engineWith(out, makeSpec({ branch: 'feat/x' }), adapter).run()
1906
+ const text = out.text()
1907
+ expect(text).toContain(`Convoy: ${result.convoyId}`)
1908
+ expect(text).toContain('Branch: feat/x')
1909
+ expect(text).toContain('Merge: git merge feat/x')
1910
+ expect(text).toMatch(/Spent: 1\.5K tokens \(est\.\)/)
1911
+ expect(text).toContain(`${result.convoyId}.ndjson`)
1912
+ expect(result.logPath).toBe(join(tmpDir, 'logs', 'convoys', `${result.convoyId}.ndjson`))
1747
1913
  })
1748
1914
 
1749
- it('prints phase headers when tasks span multiple phases', async () => {
1915
+ it('names every task that is not done, with its reason, and how to resume', async () => {
1916
+ const out = captureOutput()
1750
1917
  const adapter = makeAdapter()
1751
- const spec = makeSpec({}, [
1752
- { id: 'task-a', depends_on: [] },
1753
- { id: 'task-b', depends_on: ['task-a'] },
1754
- ])
1755
- const engine = makeEngine({
1756
- spec,
1757
- specYaml: 'name: test',
1758
- adapter,
1759
- dbPath,
1760
- _worktreeManager: makeWorktreeManager(),
1761
- _mergeQueue: makeMergeQueue(),
1762
- })
1763
-
1764
- await engine.run()
1765
-
1766
- const written = writtenChunks.join('')
1767
- expect(written).toContain('Phase 1:')
1768
- expect(written).toContain('Phase 2:')
1918
+ adapter.execute.mockImplementation(async (task: Task) =>
1919
+ task.id === 'task-a' ? { success: false, output: 'compile error in a.ts', exitCode: 2 } : { success: true, output: 'ok', exitCode: 0 })
1920
+ const spec = makeSpec({}, [{ id: 'task-a' }, { id: 'task-b', depends_on: ['task-a'] }])
1921
+ await engineWith(out, spec, adapter).run()
1922
+ const text = out.text()
1923
+ expect(text).toContain('• task-a (failed): compile error in a.ts')
1924
+ expect(text).toContain('• task-b (skipped): dependency "task-a" failed')
1925
+ expect(text).toContain('Resume with: opencastle convoy resume')
1769
1926
  })
1770
1927
 
1771
1928
  it('prints gate results with pass/fail indicators', async () => {
1772
- const adapter = makeAdapter()
1929
+ const out = captureOutput()
1773
1930
  const spec = makeSpec({ gates: ['echo gate-ok', 'false'] }, [{ id: 'task-1' }])
1774
- const engine = makeEngine({
1775
- spec,
1776
- specYaml: 'name: test',
1777
- adapter,
1778
- dbPath,
1779
- _worktreeManager: makeWorktreeManager(),
1780
- _mergeQueue: makeMergeQueue(),
1781
- })
1782
-
1783
- await engine.run()
1784
-
1785
- const written = writtenChunks.join('')
1786
- expect(written).toContain('Gates:')
1787
- expect(written).toContain('echo gate-ok')
1788
- expect(written).toContain('false')
1931
+ await engineWith(out, spec, makeAdapter()).run()
1932
+ const text = out.text()
1933
+ expect(text).toContain('Gates:')
1934
+ expect(text).toContain('✓ echo gate-ok')
1935
+ expect(text).toContain('✗ false')
1936
+ // The summary names the gate that failed.
1937
+ expect(text).toContain('Gates: 1/2 passed')
1938
+ expect(text).toMatch(/• false \(exit 1\)/)
1789
1939
  })
1790
1940
 
1791
- it('prints retry messages when a task fails and is retried', async () => {
1941
+ it('prints retries with their reason', async () => {
1942
+ const out = captureOutput()
1792
1943
  const adapter = makeAdapter()
1793
1944
  adapter.execute
1794
- .mockImplementationOnce(async () => {
1795
- await new Promise(r => setTimeout(r, 5))
1796
- return { success: false, output: 'fail', exitCode: 1 }
1797
- })
1798
- .mockImplementationOnce(async () => {
1799
- await new Promise(r => setTimeout(r, 5))
1800
- return { success: true, output: 'ok', exitCode: 0 }
1801
- })
1945
+ .mockResolvedValueOnce({ success: false, output: 'flaky network', exitCode: 1 })
1946
+ .mockResolvedValueOnce({ success: true, output: 'ok', exitCode: 0 })
1947
+ await engineWith(out, makeSpec({}, [{ id: 'task-1', max_retries: 1 }]), adapter).run()
1948
+ expect(out.text()).toContain('⟳ [task-1] failed, retry 1/1: flaky network')
1949
+ })
1802
1950
 
1803
- const engine = makeEngine({
1804
- spec: makeSpec({}, [{ id: 'task-1', max_retries: 1 }]),
1951
+ it('keeps one status line, redrawn in place, on a terminal', async () => {
1952
+ const chunks: string[] = []
1953
+ const tty = { isTTY: true, columns: 120, write: (s: string) => { chunks.push(s); return true } }
1954
+ const adapter = makeAdapter()
1955
+ adapter.execute.mockImplementation(async () => {
1956
+ await new Promise(r => setTimeout(r, 20))
1957
+ return { success: true, output: 'ok', exitCode: 0 }
1958
+ })
1959
+ await makeEngine({
1960
+ spec: makeSpec({ concurrency: 2 }, [{ id: 'build-api' }, { id: 'write-tests' }, { id: 'docs' }]),
1805
1961
  specYaml: 'name: test',
1806
1962
  adapter,
1807
1963
  dbPath,
1964
+ output: tty,
1808
1965
  _worktreeManager: makeWorktreeManager(),
1809
1966
  _mergeQueue: makeMergeQueue(),
1810
- })
1811
-
1812
- await engine.run()
1813
-
1814
- const written = writtenChunks.join('')
1815
- expect(written).toMatch(/⟳/)
1816
- expect(written).toContain('retry 1/1')
1967
+ }).run()
1968
+ // eslint-disable-next-line no-control-regex
1969
+ const statuses = chunks.filter(ch => ch.startsWith('\r\x1b[2K') && ch.includes('▸')).map(ch => ch.replace(/\x1b\[[0-9;]*m/g, ''))
1970
+ expect(statuses.length).toBeGreaterThan(0)
1971
+ expect(statuses.some(s => /▸ build-api, write-tests · 1 queued · 0\/3 done/.test(s))).toBe(true)
1972
+ // Nothing of the status line is left once the run has ended.
1973
+ expect(chunks.join('')).not.toMatch(/▸[^\n]*$/)
1817
1974
  })
1818
1975
  })
1819
1976
 
@@ -1887,7 +2044,8 @@ describe('gate retry mechanism', () => {
1887
2044
  // The second call should be the fix task
1888
2045
  const fixCall = adapter.execute.mock.calls[1] as [Task]
1889
2046
  expect(fixCall[0].id).toBe('gate-fix-1')
1890
- expect(fixCall[0].prompt).toContain('validation gates failed')
2047
+ expect(fixCall[0].prompt).toContain('These checks failed after every task was merged')
2048
+ expect(fixCall[0].prompt).toContain('Command: false')
1891
2049
  // Gates still fail after fix, so final status is gate-failed
1892
2050
  expect(result.status).toBe('gate-failed')
1893
2051
  })
@@ -1968,89 +2126,53 @@ function makeDiffStats(overrides: Partial<DiffStats> = {}): DiffStats {
1968
2126
  }
1969
2127
 
1970
2128
  describe('evaluateReviewLevel', () => {
1971
- it('routes to panel when a changed file is under auth/', () => {
2129
+ it('never picks a panel on its own — sensitive paths get a fast review, even when small', () => {
2130
+ // A panel is three reviewer sessions; only a spec that asks for one gets one.
2131
+ for (const filePaths of [['auth/session.ts'], ['src/auth/session.ts'], ['security/policy.ts']]) {
2132
+ expect(evaluateReviewLevel(makeTaskRecord(), makeDiffStats({ filePaths, linesChanged: 3, filesChanged: 1 }), undefined, true)).toBe('fast')
2133
+ }
2134
+ })
2135
+
2136
+ it('gives sensitive agents a fast review rather than waving them through', () => {
2137
+ expect(evaluateReviewLevel(makeTaskRecord({ agent: 'security-expert' }), makeDiffStats())).toBe('fast')
2138
+ expect(evaluateReviewLevel(makeTaskRecord({ agent: 'data-engineer' }), makeDiffStats())).toBe('fast')
2139
+ })
2140
+
2141
+ it('routes to auto-pass for writer agent', () => {
1972
2142
  const level = evaluateReviewLevel(
1973
- makeTaskRecord(),
1974
- makeDiffStats({ filePaths: ['auth/session.ts'] }),
2143
+ makeTaskRecord({ agent: 'writer' }),
2144
+ makeDiffStats(),
1975
2145
  )
1976
- expect(level).toBe('panel')
2146
+ expect(level).toBe('auto-pass')
1977
2147
  })
1978
2148
 
1979
- it('routes to panel when a changed file path contains /auth/', () => {
2149
+ it('routes to auto-pass for small diff (<=10 lines, <=2 files) with gates passing', () => {
1980
2150
  const level = evaluateReviewLevel(
1981
2151
  makeTaskRecord(),
1982
- makeDiffStats({ filePaths: ['src/auth/session.ts'] }),
2152
+ makeDiffStats({ linesChanged: 8, filesChanged: 2, filePaths: ['src/Button.tsx', 'src/Button.test.tsx'] }),
2153
+ undefined,
2154
+ true,
1983
2155
  )
1984
- expect(level).toBe('panel')
2156
+ expect(level).toBe('auto-pass')
1985
2157
  })
1986
2158
 
1987
- it('routes to panel for security/ path', () => {
2159
+ it('routes to fast for large diff (>200 lines)', () => {
1988
2160
  const level = evaluateReviewLevel(
1989
2161
  makeTaskRecord(),
1990
- makeDiffStats({ filePaths: ['security/policy.ts'] }),
2162
+ makeDiffStats({ linesChanged: 250, filesChanged: 3, filePaths: ['src/Big.tsx', 'src/Big.test.tsx', 'src/types.ts'] }),
1991
2163
  )
1992
- expect(level).toBe('panel')
2164
+ expect(level).toBe('fast')
1993
2165
  })
1994
2166
 
1995
- it('routes to panel for security-expert agent', () => {
2167
+ it('routes to fast for many files (>5)', () => {
1996
2168
  const level = evaluateReviewLevel(
1997
- makeTaskRecord({ agent: 'security-expert' }),
1998
- makeDiffStats(),
2169
+ makeTaskRecord(),
2170
+ makeDiffStats({ linesChanged: 50, filesChanged: 6, filePaths: ['a.ts', 'b.ts', 'c.ts', 'd.ts', 'e.ts', 'f.ts'] }),
1999
2171
  )
2000
- expect(level).toBe('panel')
2172
+ expect(level).toBe('fast')
2001
2173
  })
2002
2174
 
2003
- it('routes to panel for data-engineer agent', () => {
2004
- const level = evaluateReviewLevel(
2005
- makeTaskRecord({ agent: 'data-engineer' }),
2006
- makeDiffStats(),
2007
- )
2008
- expect(level).toBe('panel')
2009
- })
2010
-
2011
- it('routes to auto-pass for writer agent', () => {
2012
- const level = evaluateReviewLevel(
2013
- makeTaskRecord({ agent: 'writer' }),
2014
- makeDiffStats(),
2015
- )
2016
- expect(level).toBe('auto-pass')
2017
- })
2018
-
2019
- it('routes to auto-pass for writer agent', () => {
2020
- const level = evaluateReviewLevel(
2021
- makeTaskRecord({ agent: 'writer' }),
2022
- makeDiffStats(),
2023
- )
2024
- expect(level).toBe('auto-pass')
2025
- })
2026
-
2027
- it('routes to auto-pass for small diff (<=10 lines, <=2 files) with gates passing', () => {
2028
- const level = evaluateReviewLevel(
2029
- makeTaskRecord(),
2030
- makeDiffStats({ linesChanged: 8, filesChanged: 2, filePaths: ['src/Button.tsx', 'src/Button.test.tsx'] }),
2031
- undefined,
2032
- true,
2033
- )
2034
- expect(level).toBe('auto-pass')
2035
- })
2036
-
2037
- it('routes to fast for large diff (>200 lines)', () => {
2038
- const level = evaluateReviewLevel(
2039
- makeTaskRecord(),
2040
- makeDiffStats({ linesChanged: 250, filesChanged: 3, filePaths: ['src/Big.tsx', 'src/Big.test.tsx', 'src/types.ts'] }),
2041
- )
2042
- expect(level).toBe('fast')
2043
- })
2044
-
2045
- it('routes to fast for many files (>5)', () => {
2046
- const level = evaluateReviewLevel(
2047
- makeTaskRecord(),
2048
- makeDiffStats({ linesChanged: 50, filesChanged: 6, filePaths: ['a.ts', 'b.ts', 'c.ts', 'd.ts', 'e.ts', 'f.ts'] }),
2049
- )
2050
- expect(level).toBe('fast')
2051
- })
2052
-
2053
- it('defaults to fast for medium diff with developer agent', () => {
2175
+ it('defaults to fast for medium diff with developer agent', () => {
2054
2176
  const level = evaluateReviewLevel(
2055
2177
  makeTaskRecord({ agent: 'developer' }),
2056
2178
  makeDiffStats({ linesChanged: 50, filesChanged: 3, filePaths: ['src/Feature.tsx', 'src/Feature.test.tsx', 'src/types.ts'] }),
@@ -2058,583 +2180,241 @@ describe('evaluateReviewLevel', () => {
2058
2180
  expect(level).toBe('fast')
2059
2181
  })
2060
2182
 
2061
- it('custom heuristics: overrides panel_paths', () => {
2183
+ it('custom heuristics: panel_paths mark a path sensitive', () => {
2062
2184
  const level = evaluateReviewLevel(
2063
2185
  makeTaskRecord(),
2064
- makeDiffStats({ filePaths: ['billing/invoice.ts'] }),
2186
+ makeDiffStats({ filePaths: ['billing/invoice.ts'], linesChanged: 2, filesChanged: 1 }),
2065
2187
  { panel_paths: ['billing/'] },
2066
- )
2067
- expect(level).toBe('panel')
2068
- })
2069
-
2070
- it('custom heuristics: overrides auto_pass_agents', () => {
2071
- const level = evaluateReviewLevel(
2072
- makeTaskRecord({ agent: 'designer' }),
2073
- makeDiffStats(),
2074
- { auto_pass_agents: ['designer'] },
2075
- )
2076
- expect(level).toBe('auto-pass')
2077
- })
2078
-
2079
- it('custom heuristics: smaller auto_pass_max_lines threshold', () => {
2080
- const level = evaluateReviewLevel(
2081
- makeTaskRecord(),
2082
- makeDiffStats({ linesChanged: 5, filesChanged: 1, filePaths: ['src/x.ts'] }),
2083
- { auto_pass_max_lines: 3 },
2084
2188
  true,
2085
2189
  )
2086
- expect(level).toBe('fast') // 5 > 3 → not auto-pass
2087
- })
2088
- })
2089
-
2090
- // ── Review pipeline integration ───────────────────────────────────────────────
2091
-
2092
- describe('review pipeline', () => {
2093
- let adapter: ReturnType<typeof makeAdapter>
2094
- let wtManager: ReturnType<typeof makeWorktreeManager>
2095
- let mergeQueue: ReturnType<typeof makeMergeQueue>
2096
-
2097
- beforeEach(() => {
2098
- adapter = makeAdapter()
2099
- wtManager = makeWorktreeManager()
2100
- mergeQueue = makeMergeQueue()
2101
- })
2102
-
2103
- it('task with review: none — reviewer not called, task succeeds', async () => {
2104
- const mockReviewRunner = vi.fn().mockResolvedValue({ verdict: 'pass', feedback: '', tokens: 100, model: 'test' })
2105
- const engine = makeEngine({
2106
- spec: makeSpec({ defaults: { review: 'none' } }, [{ review: 'none' }]),
2107
- specYaml: 'name: test',
2108
- adapter,
2109
- dbPath,
2110
- _worktreeManager: wtManager,
2111
- _mergeQueue: mergeQueue,
2112
- _reviewRunner: mockReviewRunner,
2113
- })
2114
- const result = await engine.run()
2115
- expect(result.status).toBe('done')
2116
- expect(mockReviewRunner).not.toHaveBeenCalled()
2117
- })
2118
-
2119
- it('fast review PASS — task proceeds to merge (status done)', async () => {
2120
- const mockReviewRunner = vi.fn().mockResolvedValue({ verdict: 'pass', feedback: '', tokens: 50, model: 'reviewer' })
2121
- const engine = makeEngine({
2122
- spec: makeSpec({ defaults: { review: 'fast' } }),
2123
- specYaml: 'name: test',
2124
- adapter,
2125
- dbPath,
2126
- _worktreeManager: wtManager,
2127
- _mergeQueue: mergeQueue,
2128
- _reviewRunner: mockReviewRunner,
2129
- })
2130
- const result = await engine.run()
2131
- expect(result.status).toBe('done')
2132
- // Two-stage review: stage 1 (spec compliance) + stage 2 (code quality) = 2 calls
2133
- expect(mockReviewRunner).toHaveBeenCalledTimes(2)
2134
- expect(mockReviewRunner).toHaveBeenCalledWith(expect.objectContaining({ agent: 'developer' }), 'fast', 'default')
2135
- })
2136
-
2137
- it('fast review BLOCK + retries remaining — task retried with feedback prepended', async () => {
2138
- let callCount = 0
2139
- adapter.execute.mockImplementation(() => {
2140
- callCount++
2141
- return Promise.resolve({ success: true, output: 'ok', exitCode: 0 })
2142
- })
2143
- const mockReviewRunner = vi.fn()
2144
- .mockResolvedValueOnce({ verdict: 'block', feedback: 'Missing tests', tokens: 50, model: 'reviewer' }) // round 1 stage 1 → block (short-circuits)
2145
- .mockResolvedValueOnce({ verdict: 'pass', feedback: '', tokens: 50, model: 'reviewer' }) // round 2 stage 1 → pass
2146
- .mockResolvedValueOnce({ verdict: 'pass', feedback: '', tokens: 50, model: 'reviewer' }) // round 2 stage 2 → pass
2147
-
2148
- const engine = makeEngine({
2149
- spec: makeSpec({ defaults: { review: 'fast' } }, [{ max_retries: 1 }]),
2150
- specYaml: 'name: test',
2151
- adapter,
2152
- dbPath,
2153
- _worktreeManager: wtManager,
2154
- _mergeQueue: mergeQueue,
2155
- _reviewRunner: mockReviewRunner,
2156
- })
2157
- const result = await engine.run()
2158
- expect(result.status).toBe('done')
2159
- expect(adapter.execute).toHaveBeenCalledTimes(2)
2160
- // Round 1: stage 1 blocks (1 call). Round 2: stage 1 pass + stage 2 pass (2 calls). Total: 3
2161
- expect(mockReviewRunner).toHaveBeenCalledTimes(3)
2162
- // Prompt on second attempt should contain feedback
2163
- const secondPrompt = (adapter.execute.mock.calls[1] as [Task])[0].prompt
2164
- expect(secondPrompt).toContain('Missing tests')
2165
- })
2166
-
2167
- it('fast review BLOCK + retries exhausted — status review-blocked', async () => {
2168
- const mockReviewRunner = vi.fn().mockResolvedValue({ verdict: 'block', feedback: 'Insecure code', tokens: 50, model: 'reviewer' })
2169
-
2170
- const engine = makeEngine({
2171
- spec: makeSpec({ defaults: { review: 'fast' } }, [{ max_retries: 0 }]),
2172
- specYaml: 'name: test',
2173
- adapter,
2174
- dbPath,
2175
- _worktreeManager: wtManager,
2176
- _mergeQueue: mergeQueue,
2177
- _reviewRunner: mockReviewRunner,
2178
- })
2179
- const result = await engine.run()
2180
- expect(result.status).toBe('failed')
2181
- expect(result.summary.failed).toBe(1)
2182
- // Verify the task itself is review-blocked
2183
- const store = createConvoyStore(dbPath)
2184
- const tasks = store.getTasksByConvoy(result.convoyId)
2185
- store.close()
2186
- expect(tasks[0].status).toBe('review-blocked')
2187
- })
2188
-
2189
- it('panel review 2/3 PASS — task proceeds (status done)', async () => {
2190
- let callCount = 0
2191
- const mockReviewRunner = vi.fn().mockImplementation(() => {
2192
- callCount++
2193
- // Reviewer C blocks at stage 1 (call 3); reviewers A and B pass both stages (calls 1,2,4,5)
2194
- return Promise.resolve(callCount === 3
2195
- ? { verdict: 'block', feedback: 'Minor issue', tokens: 30, model: 'reviewer' }
2196
- : { verdict: 'pass', feedback: '', tokens: 30, model: 'reviewer' })
2197
- })
2198
-
2199
- const engine = makeEngine({
2200
- spec: makeSpec({ defaults: { review: 'panel' } }),
2201
- specYaml: 'name: test',
2202
- adapter,
2203
- dbPath,
2204
- _worktreeManager: wtManager,
2205
- _mergeQueue: mergeQueue,
2206
- _reviewRunner: mockReviewRunner,
2207
- })
2208
- const result = await engine.run()
2209
- expect(result.status).toBe('done')
2210
- // Two-stage panel: 2 pass reviewers × 2 stages + 1 block reviewer × 1 stage = 5 calls
2211
- expect(mockReviewRunner).toHaveBeenCalledTimes(5)
2212
- })
2213
-
2214
- it('panel review 2/3 BLOCK — task retried with MUST-FIX', async () => {
2215
- let reviewCallCount = 0
2216
- const mockReviewRunner = vi.fn().mockImplementation(() => {
2217
- reviewCallCount++
2218
- // First round: 2 block; second round: 3 pass
2219
- if (reviewCallCount <= 3) {
2220
- return Promise.resolve(reviewCallCount <= 2
2221
- ? { verdict: 'block', feedback: 'Critical bug', tokens: 30, model: 'reviewer' }
2222
- : { verdict: 'pass', feedback: '', tokens: 30, model: 'reviewer' })
2223
- }
2224
- return Promise.resolve({ verdict: 'pass', feedback: '', tokens: 30, model: 'reviewer' })
2225
- })
2226
-
2227
- const engine = makeEngine({
2228
- spec: makeSpec({ defaults: { review: 'panel' } }, [{ max_retries: 1 }]),
2229
- specYaml: 'name: test',
2230
- adapter,
2231
- dbPath,
2232
- _worktreeManager: wtManager,
2233
- _mergeQueue: mergeQueue,
2234
- _reviewRunner: mockReviewRunner,
2235
- })
2236
- const result = await engine.run()
2237
- expect(result.status).toBe('done')
2238
- expect(adapter.execute).toHaveBeenCalledTimes(2)
2239
- // Prompt on second attempt contains MUST-FIX
2240
- const secondPrompt = (adapter.execute.mock.calls[1] as [Task])[0].prompt
2241
- expect(secondPrompt).toContain('MUST-FIX')
2242
- expect(secondPrompt).toContain('Critical bug')
2243
- })
2244
-
2245
- it('review budget exceeded with skip — review skipped, task done', async () => {
2246
- const mockReviewRunner = vi.fn().mockResolvedValue({ verdict: 'pass', feedback: '', tokens: 200, model: 'reviewer' })
2247
-
2248
- const engine = makeEngine({
2249
- spec: makeSpec({
2250
- defaults: { review: 'fast', review_budget: 100, on_review_budget_exceeded: 'skip', reviewer_model: 'r1' },
2251
- tasks: [
2252
- { id: 'task-1', prompt: 'Prompt 1', agent: 'developer', timeout: '30s', depends_on: [], files: [], description: '', max_retries: 0 },
2253
- { id: 'task-2', prompt: 'Prompt 2', agent: 'developer', timeout: '30s', depends_on: ['task-1'], files: [], description: '', max_retries: 0 },
2254
- ],
2255
- }),
2256
- specYaml: 'name: test',
2257
- adapter,
2258
- dbPath,
2259
- _worktreeManager: wtManager,
2260
- _mergeQueue: mergeQueue,
2261
- _reviewRunner: mockReviewRunner,
2262
- })
2263
- const result = await engine.run()
2264
- expect(result.status).toBe('done')
2265
- // first task: budget not exceeded (0 < 100), two-stage review runs (2 calls, total 400 tokens)
2266
- // second task: budget exceeded (400 >= 100), review skipped
2267
- expect(mockReviewRunner).toHaveBeenCalledTimes(2)
2268
- })
2269
-
2270
- it('auto route: developer agent with empty diff → auto-pass (no reviewer call)', async () => {
2271
- // Given: 'auto' review setting, developer agent, empty diff (git will fail on mock path)
2272
- const mockReviewRunner = vi.fn()
2273
- const engine = makeEngine({
2274
- spec: makeSpec({ defaults: { review: 'auto' } }),
2275
- specYaml: 'name: test',
2276
- adapter,
2277
- dbPath,
2278
- _worktreeManager: wtManager,
2279
- _mergeQueue: mergeQueue,
2280
- _reviewRunner: mockReviewRunner,
2281
- })
2282
- const result = await engine.run()
2283
- expect(result.status).toBe('done')
2284
- expect(mockReviewRunner).not.toHaveBeenCalled()
2285
- })
2286
-
2287
- it('review tokens tracked on task record', async () => {
2288
- const mockReviewRunner = vi.fn().mockResolvedValue({ verdict: 'pass', feedback: '', tokens: 77, model: 'reviewer' })
2289
- const engine = makeEngine({
2290
- spec: makeSpec({ defaults: { review: 'fast' } }),
2291
- specYaml: 'name: test',
2292
- adapter,
2293
- dbPath,
2294
- _worktreeManager: wtManager,
2295
- _mergeQueue: mergeQueue,
2296
- _reviewRunner: mockReviewRunner,
2297
- })
2298
- const result = await engine.run()
2299
- const store = createConvoyStore(dbPath)
2300
- const tasks = store.getTasksByConvoy(result.convoyId)
2301
- store.close()
2302
- expect(tasks[0].review_tokens).toBe(154) // two-stage: 77 (stage 1) + 77 (stage 2)
2303
- expect(tasks[0].review_level).toBe('fast')
2304
- expect(tasks[0].review_verdict).toBe('pass')
2305
- })
2306
-
2307
- it('review_started and review_verdict events emitted', async () => {
2308
- const mockReviewRunner = vi.fn().mockResolvedValue({ verdict: 'pass', feedback: '', tokens: 10, model: 'reviewer' })
2309
- const engine = makeEngine({
2310
- spec: makeSpec({ defaults: { review: 'fast' } }),
2311
- specYaml: 'name: test',
2312
- adapter,
2313
- dbPath,
2314
- _worktreeManager: wtManager,
2315
- _mergeQueue: mergeQueue,
2316
- _reviewRunner: mockReviewRunner,
2317
- })
2318
- const result = await engine.run()
2319
- const store = createConvoyStore(dbPath)
2320
- const events = store.getEvents(result.convoyId)
2321
- store.close()
2322
- const startedEvent = events.find(e => e.type === 'review_started')
2323
- const verdictEvent = events.find(e => e.type === 'review_verdict')
2324
- expect(startedEvent).toBeDefined()
2325
- expect(verdictEvent).toBeDefined()
2326
- })
2327
-
2328
- it('review sessions do NOT count against concurrency limit', async () => {
2329
- // Concurrency=1, 2 tasks in parallel. Both should complete with review.
2330
- const mockReviewRunner = vi.fn().mockResolvedValue({ verdict: 'pass', feedback: '', tokens: 10, model: 'reviewer' })
2331
- const engine = makeEngine({
2332
- spec: makeSpec(
2333
- { concurrency: 1, defaults: { review: 'fast' } },
2334
- [{ id: 'task-1' }, { id: 'task-2' }],
2335
- ),
2336
- specYaml: 'name: test',
2337
- adapter,
2338
- dbPath,
2339
- _worktreeManager: wtManager,
2340
- _mergeQueue: mergeQueue,
2341
- _reviewRunner: mockReviewRunner,
2342
- })
2343
- const result = await engine.run()
2344
- expect(result.status).toBe('done')
2345
- expect(result.summary.done).toBe(2)
2346
- })
2347
-
2348
- it('full fast-review flow: BLOCK on first attempt → retry → PASS → done with complete events', async () => {
2349
- const mockReviewRunner = vi.fn()
2350
- .mockResolvedValueOnce({ verdict: 'block', feedback: 'Add more tests', tokens: 40, model: 'reviewer' }) // round 1 stage 1 → block
2351
- .mockResolvedValueOnce({ verdict: 'pass', feedback: '', tokens: 35, model: 'reviewer' }) // round 2 stage 1 → pass
2352
- .mockResolvedValueOnce({ verdict: 'pass', feedback: '', tokens: 35, model: 'reviewer' }) // round 2 stage 2 → pass
2353
-
2354
- const engine = makeEngine({
2355
- spec: makeSpec({ defaults: { review: 'fast' } }, [{ id: 'task-1', max_retries: 1 }]),
2356
- specYaml: 'name: test',
2357
- adapter,
2358
- dbPath,
2359
- _worktreeManager: wtManager,
2360
- _mergeQueue: mergeQueue,
2361
- _reviewRunner: mockReviewRunner,
2362
- })
2363
- const result = await engine.run()
2364
-
2365
- expect(result.status).toBe('done')
2366
- expect(adapter.execute).toHaveBeenCalledTimes(2)
2367
- // Round 1: 1 call (block short-circuits). Round 2: 2 calls (stage 1 + stage 2). Total: 3
2368
- expect(mockReviewRunner).toHaveBeenCalledTimes(3)
2369
-
2370
- const store = createConvoyStore(dbPath)
2371
- const tasks = store.getTasksByConvoy(result.convoyId)
2372
- const events = store.getEvents(result.convoyId)
2373
- store.close()
2374
-
2375
- const task = tasks[0]
2376
- expect(task.review_level).toBe('fast')
2377
- expect(task.review_verdict).toBe('pass')
2378
- expect(task.retries).toBe(1)
2379
-
2380
- const reviewStartedEvents = events.filter(e => e.type === 'review_started')
2381
- const reviewVerdictEvents = events.filter(e => e.type === 'review_verdict')
2382
- expect(reviewStartedEvents.length).toBe(2)
2383
- expect(reviewVerdictEvents.length).toBe(2)
2384
-
2385
- const firstVerdict = JSON.parse(reviewVerdictEvents[0].data!) as Record<string, unknown>
2386
- const secondVerdict = JSON.parse(reviewVerdictEvents[1].data!) as Record<string, unknown>
2387
- expect(firstVerdict['verdict']).toBe('block')
2388
- expect(secondVerdict['verdict']).toBe('pass')
2389
- })
2390
-
2391
- it('panel flow: 2/3 BLOCK first round → retry → 3/3 PASS second round → done', async () => {
2392
- let reviewCallCount = 0
2393
- const mockReviewRunner = vi.fn().mockImplementation(() => {
2394
- reviewCallCount++
2395
- // Round 1 (calls 1-3): BLOCK, BLOCK, PASS → majority block → retry
2396
- if (reviewCallCount <= 3) {
2397
- return Promise.resolve(reviewCallCount <= 2
2398
- ? { verdict: 'block', feedback: 'Critical issue', tokens: 20, model: 'reviewer' }
2399
- : { verdict: 'pass', feedback: '', tokens: 20, model: 'reviewer' })
2400
- }
2401
- // Round 2 (calls 4-6): all PASS
2402
- return Promise.resolve({ verdict: 'pass', feedback: '', tokens: 20, model: 'reviewer' })
2403
- })
2404
-
2405
- const engine = makeEngine({
2406
- spec: makeSpec({ defaults: { review: 'panel' } }, [{ id: 'task-1', max_retries: 1 }]),
2407
- specYaml: 'name: test',
2408
- adapter,
2409
- dbPath,
2410
- _worktreeManager: wtManager,
2411
- _mergeQueue: mergeQueue,
2412
- _reviewRunner: mockReviewRunner,
2413
- })
2414
- const result = await engine.run()
2415
-
2416
- expect(result.status).toBe('done')
2417
- expect(adapter.execute).toHaveBeenCalledTimes(2)
2418
- // Two-stage panel round 1: 2 blocks ×1 call + 1 pass ×2 calls = 4 calls
2419
- // Two-stage panel round 2: 3 pass ×2 calls = 6 calls. Total: 10
2420
- expect(mockReviewRunner).toHaveBeenCalledTimes(10)
2421
-
2422
- const store = createConvoyStore(dbPath)
2423
- const tasks = store.getTasksByConvoy(result.convoyId)
2424
- store.close()
2425
-
2426
- expect(tasks[0].review_verdict).toBe('pass')
2427
- expect(tasks[0].panel_attempts).toBeGreaterThanOrEqual(1)
2428
- })
2429
-
2430
- it('dispute: task dispute_id matches the dispute_opened event and panel_attempts is 3', async () => {
2431
- const mockReviewRunner = vi.fn().mockResolvedValue({ verdict: 'block', feedback: 'broken', tokens: 5, model: 'r' })
2432
-
2433
- const engine = makeEngine({
2434
- spec: makeSpec({ defaults: { review: 'panel' } }, [{ id: 'task-1', max_retries: 3 }]),
2435
- specYaml: 'name: test',
2436
- adapter,
2437
- dbPath,
2438
- _worktreeManager: wtManager,
2439
- _mergeQueue: mergeQueue,
2440
- _reviewRunner: mockReviewRunner,
2441
- })
2442
- const result = await engine.run()
2443
-
2444
- const store = createConvoyStore(dbPath)
2445
- const tasks = store.getTasksByConvoy(result.convoyId)
2446
- const events = store.getEvents(result.convoyId)
2447
- store.close()
2448
-
2449
- const task = tasks[0]
2450
- expect(task.status).toBe('disputed')
2451
- expect(task.dispute_id).not.toBeNull()
2452
- expect(task.panel_attempts).toBe(3)
2453
-
2454
- const disputeEvent = events.find(e => e.type === 'dispute_opened')
2455
- expect(disputeEvent).toBeDefined()
2456
- const eventData = JSON.parse(disputeEvent!.data!) as Record<string, unknown>
2457
- // Verify the dispute_id on the task record matches the one in the event
2458
- expect(eventData['dispute_id']).toBe(task.dispute_id)
2459
- expect(eventData['panel_attempts']).toBe(3)
2460
- })
2461
-
2462
- it('review budget exceeded: stop marks task review-blocked and skips all pending tasks', async () => {
2463
- const mockReviewRunner = vi.fn()
2464
-
2465
- const engine = makeEngine({
2466
- spec: makeSpec(
2467
- { defaults: { review: 'fast', review_budget: 0, on_review_budget_exceeded: 'stop' } },
2468
- [
2469
- { id: 'task-1', depends_on: [] },
2470
- { id: 'task-2', depends_on: ['task-1'] },
2471
- ],
2472
- ),
2473
- specYaml: 'name: test',
2474
- adapter,
2475
- dbPath,
2476
- _worktreeManager: wtManager,
2477
- _mergeQueue: mergeQueue,
2478
- _reviewRunner: mockReviewRunner,
2479
- })
2480
- const result = await engine.run()
2481
-
2482
- const store = createConvoyStore(dbPath)
2483
- const tasks = store.getTasksByConvoy(result.convoyId)
2484
- store.close()
2485
-
2486
- const byId = Object.fromEntries(tasks.map(t => [t.id, t.status]))
2487
- expect(byId['task-1']).toBe('review-blocked')
2488
- expect(byId['task-2']).toBe('skipped')
2489
- expect(mockReviewRunner).not.toHaveBeenCalled()
2190
+ expect(level).toBe('fast')
2490
2191
  })
2491
2192
 
2492
- it('review budget exceeded: downgrade auto-passes task without calling reviewer', async () => {
2493
- const mockReviewRunner = vi.fn()
2494
-
2495
- const engine = makeEngine({
2496
- spec: makeSpec(
2497
- { defaults: { review: 'fast', review_budget: 0, on_review_budget_exceeded: 'downgrade' } },
2498
- ),
2499
- specYaml: 'name: test',
2500
- adapter,
2501
- dbPath,
2502
- _worktreeManager: wtManager,
2503
- _mergeQueue: mergeQueue,
2504
- _reviewRunner: mockReviewRunner,
2505
- })
2506
- const result = await engine.run()
2507
-
2508
- expect(result.status).toBe('done')
2509
- expect(mockReviewRunner).not.toHaveBeenCalled()
2510
-
2511
- const store = createConvoyStore(dbPath)
2512
- const tasks = store.getTasksByConvoy(result.convoyId)
2513
- store.close()
2514
-
2515
- expect(tasks[0].review_verdict).toBe('pass')
2516
- expect(tasks[0].review_level).toBe('fast')
2193
+ it('custom heuristics: overrides auto_pass_agents', () => {
2194
+ const level = evaluateReviewLevel(
2195
+ makeTaskRecord({ agent: 'designer' }),
2196
+ makeDiffStats(),
2197
+ { auto_pass_agents: ['designer'] },
2198
+ )
2199
+ expect(level).toBe('auto-pass')
2200
+ })
2201
+
2202
+ it('custom heuristics: smaller auto_pass_max_lines threshold', () => {
2203
+ const level = evaluateReviewLevel(
2204
+ makeTaskRecord(),
2205
+ makeDiffStats({ linesChanged: 5, filesChanged: 1, filePaths: ['src/x.ts'] }),
2206
+ { auto_pass_max_lines: 3 },
2207
+ true,
2208
+ )
2209
+ expect(level).toBe('fast') // 5 > 3 → not auto-pass
2517
2210
  })
2518
2211
  })
2519
2212
 
2520
- // ── Drift detection ───────────────────────────────────────────────────────────
2213
+ // ── Review pipeline integration ───────────────────────────────────────────────
2521
2214
 
2522
- describe('drift detection', () => {
2215
+ describe('review pipeline', () => {
2523
2216
  let adapter: ReturnType<typeof makeAdapter>
2524
2217
  let wtManager: ReturnType<typeof makeWorktreeManager>
2525
2218
  let mergeQueue: ReturnType<typeof makeMergeQueue>
2526
2219
 
2527
2220
  beforeEach(() => {
2528
- adapter = makeAdapter('copilot')
2221
+ adapter = makeAdapter()
2529
2222
  wtManager = makeWorktreeManager()
2530
2223
  mergeQueue = makeMergeQueue()
2531
2224
  })
2532
2225
 
2533
- it('detect_drift=true triggers drift check and retries on low confidence', async () => {
2534
- // Call sequence: main task → drift check (low score) → main task retry
2535
- const driftRetryOutput = [
2536
- 'done retry',
2537
- '<!-- OUTPUT_CONTRACT',
2538
- '{ "files_changed": ["src/foo.ts"], "tests_added": ["src/foo.test.ts"], "summary": "done" }',
2539
- '-->',
2540
- ].join('\n')
2541
- adapter.execute
2542
- .mockResolvedValueOnce({ success: true, output: 'done', exitCode: 0 })
2543
- .mockResolvedValueOnce({ success: true, output: '{"score": 0.3, "explanation": "uncertain"}', exitCode: 0 })
2544
- .mockResolvedValueOnce({ success: true, output: driftRetryOutput, exitCode: 0 })
2545
-
2546
- const engine = makeEngine({
2547
- spec: makeSpec({ defaults: { detect_drift: true } }, [{ id: 'task-1', max_retries: 1 }]),
2226
+ function reviewEngine(spec: TaskSpec, runner?: ConvoyEngineOptions['_reviewRunner']) {
2227
+ return makeEngine({
2228
+ spec,
2548
2229
  specYaml: 'name: test',
2549
2230
  adapter,
2550
2231
  dbPath,
2551
2232
  _worktreeManager: wtManager,
2552
2233
  _mergeQueue: mergeQueue,
2234
+ ...(runner ? { _reviewRunner: runner } : {}),
2553
2235
  })
2554
- const result = await engine.run()
2555
-
2556
- expect(result.status).toBe('done')
2557
- expect(result.summary.done).toBe(1)
2558
- expect(adapter.execute).toHaveBeenCalledTimes(3)
2236
+ }
2559
2237
 
2560
- // Verify drift_score and drift_retried stored
2238
+ function readTasks(convoyId: string) {
2561
2239
  const store = createConvoyStore(dbPath)
2562
- const tasks = store.getTasksByConvoy(result.convoyId)
2240
+ const tasks = store.getTasksByConvoy(convoyId)
2241
+ const events = store.getEvents(convoyId)
2563
2242
  store.close()
2564
- expect(tasks[0].drift_score).toBe(0.3)
2565
- expect(tasks[0].drift_retried).toBe(1)
2243
+ return { tasks, events }
2244
+ }
2245
+
2246
+ it('task with review: none — reviewer not called, task succeeds', async () => {
2247
+ const runner = vi.fn().mockResolvedValue({ verdict: 'pass', feedback: '', tokens: 100, model: 'test' })
2248
+ const result = await reviewEngine(makeSpec({ defaults: { review: 'none' } }, [{ review: 'none' }]), runner).run()
2249
+ expect(result.status).toBe('done')
2250
+ expect(runner).not.toHaveBeenCalled()
2566
2251
  })
2567
2252
 
2568
- it('detect_drift=true does NOT re-check on drift retry (drift_retried=1)', async () => {
2569
- // On second execution drift_retried=1 so no third call for drift check
2570
- adapter.execute
2571
- .mockResolvedValueOnce({ success: true, output: 'done', exitCode: 0 })
2572
- .mockResolvedValueOnce({ success: true, output: '{"score": 0.9, "explanation": "confident"}', exitCode: 0 })
2253
+ it('fast review is one reviewer session, and a pass lets the task merge', async () => {
2254
+ const runner = vi.fn().mockResolvedValue({ verdict: 'pass', feedback: '', tokens: 50, model: 'reviewer' })
2255
+ const result = await reviewEngine(makeSpec({ defaults: { review: 'fast' } }), runner).run()
2256
+ expect(result.status).toBe('done')
2257
+ expect(runner).toHaveBeenCalledTimes(1)
2258
+ expect(runner).toHaveBeenCalledWith(
2259
+ expect.objectContaining({ agent: 'developer' }),
2260
+ 'fast',
2261
+ 'default',
2262
+ expect.objectContaining({ cwd: '/tmp/worktree-mock', prompt: 'Prompt for task 1', canRunReadOnly: true }),
2263
+ )
2264
+ expect(mergeQueue.merge).toHaveBeenCalledOnce()
2265
+ })
2573
2266
 
2574
- const engine = makeEngine({
2575
- spec: makeSpec({ defaults: { detect_drift: true } }),
2576
- specYaml: 'name: test',
2577
- adapter,
2578
- dbPath,
2579
- _worktreeManager: wtManager,
2580
- _mergeQueue: mergeQueue,
2267
+ it('a block with retries left re-runs the task with the feedback and its original prompt', async () => {
2268
+ const runner = vi.fn()
2269
+ .mockResolvedValueOnce({ verdict: 'block', feedback: 'Missing tests', tokens: 50, model: 'reviewer' })
2270
+ .mockResolvedValueOnce({ verdict: 'pass', feedback: '', tokens: 50, model: 'reviewer' })
2271
+ const result = await reviewEngine(makeSpec({ defaults: { review: 'fast' } }, [{ max_retries: 1 }]), runner).run()
2272
+ expect(result.status).toBe('done')
2273
+ expect(adapter.execute).toHaveBeenCalledTimes(2)
2274
+ expect(runner).toHaveBeenCalledTimes(2)
2275
+ const secondPrompt = (adapter.execute.mock.calls[1] as [Task])[0].prompt
2276
+ expect(secondPrompt).toContain('Missing tests')
2277
+ expect(secondPrompt).toContain('Prompt for task 1')
2278
+ })
2279
+
2280
+ it('a block with no retries left ends review-blocked', async () => {
2281
+ const runner = vi.fn().mockResolvedValue({ verdict: 'block', feedback: 'Insecure code', tokens: 50, model: 'reviewer' })
2282
+ const result = await reviewEngine(makeSpec({ defaults: { review: 'fast' } }, [{ max_retries: 0 }]), runner).run()
2283
+ expect(result.status).toBe('failed')
2284
+ expect(readTasks(result.convoyId).tasks[0].status).toBe('review-blocked')
2285
+ expect(mergeQueue.merge).not.toHaveBeenCalled()
2286
+ })
2287
+
2288
+ it('records a review that reached no verdict as skipped — never as a pass', async () => {
2289
+ const runner = vi.fn().mockResolvedValue({ verdict: 'skipped', feedback: 'the reviewer gave no verdict', tokens: 30, model: null })
2290
+ const result = await reviewEngine(makeSpec({ defaults: { review: 'fast' } }), runner).run()
2291
+ expect(result.status).toBe('done')
2292
+ const { tasks, events } = readTasks(result.convoyId)
2293
+ expect(tasks[0].review_verdict).toBe('skipped')
2294
+ expect(events.some(e => e.type === 'review_verdict')).toBe(false)
2295
+ const skipped = events.find(e => e.type === 'review_skipped')!
2296
+ expect(JSON.parse(skipped.data!)).toEqual({ level: 'fast', reason: 'the reviewer gave no verdict' })
2297
+ })
2298
+
2299
+ it('uses the default reviewer when none is injected: the task’s runtime, read-only, in its worktree', async () => {
2300
+ adapter.execute.mockImplementation(async (task: Task) =>
2301
+ task.id.endsWith('-review')
2302
+ ? { success: true, output: 'Looks fine.\n<!-- REVIEW_VERDICT { "verdict": "pass", "issues": [] } -->', exitCode: 0, usage: { total_tokens: 900 } }
2303
+ : { success: true, output: 'ok', exitCode: 0 })
2304
+ const result = await reviewEngine(makeSpec({ defaults: { review: 'fast' } })).run()
2305
+ expect(result.status).toBe('done')
2306
+ const reviewCall = adapter.execute.mock.calls.find(([t]) => (t as Task).id === 'task-1-review')!
2307
+ expect(reviewCall[1]).toMatchObject({ cwd: '/tmp/worktree-mock', permissionMode: 'plan' })
2308
+ expect((reviewCall[0] as Task).prompt).toContain('Prompt for task 1')
2309
+ const task = readTasks(result.convoyId).tasks[0]
2310
+ expect(task).toMatchObject({ review_level: 'fast', review_verdict: 'pass', review_tokens: 900 })
2311
+ })
2312
+
2313
+ it('panel: three reviewers, majority wins', async () => {
2314
+ let n = 0
2315
+ const runner = vi.fn().mockImplementation(() => {
2316
+ n++
2317
+ return Promise.resolve(n === 3
2318
+ ? { verdict: 'block', feedback: 'Minor issue', tokens: 30, model: 'reviewer' }
2319
+ : { verdict: 'pass', feedback: '', tokens: 30, model: 'reviewer' })
2581
2320
  })
2582
- const result = await engine.run()
2321
+ const result = await reviewEngine(makeSpec({ defaults: { review: 'panel' } }), runner).run()
2322
+ expect(result.status).toBe('done')
2323
+ expect(runner).toHaveBeenCalledTimes(3)
2324
+ const task = readTasks(result.convoyId).tasks[0]
2325
+ expect(task).toMatchObject({ review_level: 'panel', review_verdict: 'pass', review_tokens: 90, panel_attempts: 1 })
2326
+ })
2583
2327
 
2328
+ it('panel: 2/3 block → retried with the blocking feedback', async () => {
2329
+ let n = 0
2330
+ const runner = vi.fn().mockImplementation(() => {
2331
+ n++
2332
+ return Promise.resolve(n <= 2
2333
+ ? { verdict: 'block', feedback: 'Critical bug', tokens: 30, model: 'reviewer' }
2334
+ : { verdict: 'pass', feedback: '', tokens: 30, model: 'reviewer' })
2335
+ })
2336
+ const result = await reviewEngine(makeSpec({ defaults: { review: 'panel' } }, [{ max_retries: 1 }]), runner).run()
2584
2337
  expect(result.status).toBe('done')
2585
2338
  expect(adapter.execute).toHaveBeenCalledTimes(2)
2339
+ expect(runner).toHaveBeenCalledTimes(6)
2340
+ const secondPrompt = (adapter.execute.mock.calls[1] as [Task])[0].prompt
2341
+ expect(secondPrompt).toContain('Critical bug')
2586
2342
  })
2587
2343
 
2588
- it('drift_check_result and drift_detected events emitted when drifted', async () => {
2589
- adapter.execute
2590
- .mockResolvedValueOnce({ success: true, output: 'done', exitCode: 0 })
2591
- .mockResolvedValueOnce({ success: true, output: '{"score": 0.2, "explanation": "very unsure"}', exitCode: 0 })
2592
- .mockResolvedValueOnce({ success: true, output: 'done', exitCode: 0 })
2344
+ it('auto route: developer agent with an empty diff → auto-pass, no reviewer', async () => {
2345
+ const runner = vi.fn()
2346
+ const result = await reviewEngine(makeSpec({ defaults: { review: 'auto' } }), runner).run()
2347
+ expect(result.status).toBe('done')
2348
+ expect(runner).not.toHaveBeenCalled()
2349
+ expect(readTasks(result.convoyId).tasks[0]).toMatchObject({ review_level: 'auto-pass', review_verdict: 'pass', review_model: null })
2350
+ })
2593
2351
 
2594
- const engine = makeEngine({
2595
- spec: makeSpec({ defaults: { detect_drift: true } }, [{ id: 'task-1', max_retries: 1 }]),
2596
- specYaml: 'name: test',
2597
- adapter,
2598
- dbPath,
2599
- _worktreeManager: wtManager,
2600
- _mergeQueue: mergeQueue,
2601
- })
2602
- const result = await engine.run()
2352
+ it('review tokens are tracked on the task and the reviewer cost is added to it', async () => {
2353
+ const runner = vi.fn().mockResolvedValue({ verdict: 'pass', feedback: '', tokens: 77, model: 'reviewer', costUsd: 0.05 })
2354
+ adapter.execute.mockResolvedValue({ success: true, output: 'ok', exitCode: 0, usage: { total_tokens: 10 }, costUsd: 0.1 })
2355
+ const result = await reviewEngine(makeSpec({ defaults: { review: 'fast' } }), runner).run()
2356
+ const task = readTasks(result.convoyId).tasks[0]
2357
+ expect(task.review_tokens).toBe(77)
2358
+ expect(task.cost_usd).toBeCloseTo(0.15)
2359
+ expect(result.cost?.total_tokens).toBe(87)
2360
+ })
2603
2361
 
2604
- const store = createConvoyStore(dbPath)
2605
- const events = store.getEvents(result.convoyId)
2606
- store.close()
2362
+ it('review_started and review_verdict events emitted', async () => {
2363
+ const runner = vi.fn().mockResolvedValue({ verdict: 'pass', feedback: '', tokens: 10, model: 'reviewer' })
2364
+ const result = await reviewEngine(makeSpec({ defaults: { review: 'fast' } }), runner).run()
2365
+ const { events } = readTasks(result.convoyId)
2366
+ expect(events.find(e => e.type === 'review_started')).toBeDefined()
2367
+ expect(events.find(e => e.type === 'review_verdict')).toBeDefined()
2368
+ })
2607
2369
 
2608
- expect(events.some(e => e.type === 'drift_check_result')).toBe(true)
2609
- expect(events.some(e => e.type === 'drift_detected')).toBe(true)
2370
+ it('review sessions do NOT count against concurrency limit', async () => {
2371
+ const runner = vi.fn().mockResolvedValue({ verdict: 'pass', feedback: '', tokens: 10, model: 'reviewer' })
2372
+ const result = await reviewEngine(makeSpec({ concurrency: 1, defaults: { review: 'fast' } }, [{ id: 'task-1' }, { id: 'task-2' }]), runner).run()
2373
+ expect(result.status).toBe('done')
2374
+ expect(result.summary.done).toBe(2)
2610
2375
  })
2611
2376
 
2612
- it('non-copilot adapter skips drift detection (returns done without extra call)', async () => {
2613
- // adapter name is 'test-adapter' — not a streaming adapter; drift check should be skipped
2614
- const nonStreamingAdapter = makeAdapter('test-adapter')
2615
- nonStreamingAdapter.execute.mockResolvedValue({ success: true, output: 'ok', exitCode: 0 })
2377
+ it('dispute: three blocked panels open a dispute whose id matches the task', async () => {
2378
+ const runner = vi.fn().mockResolvedValue({ verdict: 'block', feedback: 'broken', tokens: 5, model: 'r' })
2379
+ const result = await reviewEngine(makeSpec({ defaults: { review: 'panel' } }, [{ id: 'task-1', max_retries: 3 }]), runner).run()
2380
+ const { tasks, events } = readTasks(result.convoyId)
2381
+ const task = tasks[0]
2382
+ expect(task.status).toBe('disputed')
2383
+ expect(task.dispute_id).not.toBeNull()
2384
+ expect(task.panel_attempts).toBe(3)
2385
+ const eventData = JSON.parse(events.find(e => e.type === 'dispute_opened')!.data!) as Record<string, unknown>
2386
+ expect(eventData['dispute_id']).toBe(task.dispute_id)
2387
+ expect(eventData['panel_attempts']).toBe(3)
2388
+ })
2616
2389
 
2617
- // Suppress the stderr warning
2618
- const stderrSpy = vi.spyOn(process.stderr, 'write').mockImplementation(() => true)
2619
- try {
2620
- const engine = makeEngine({
2621
- spec: makeSpec({ defaults: { detect_drift: true } }),
2622
- specYaml: 'name: test',
2623
- adapter: nonStreamingAdapter,
2624
- dbPath,
2625
- _worktreeManager: wtManager,
2626
- _mergeQueue: mergeQueue,
2627
- })
2628
- const result = await engine.run()
2629
- expect(result.status).toBe('done')
2630
- // Only 1 call: main task (no drift check call) because non-streaming adapter
2631
- expect(nonStreamingAdapter.execute).toHaveBeenCalledTimes(1)
2632
- } finally {
2633
- stderrSpy.mockRestore()
2634
- }
2390
+ it('review budget spent with skip — later reviews are recorded as skipped, not passed', async () => {
2391
+ const runner = vi.fn().mockResolvedValue({ verdict: 'pass', feedback: '', tokens: 200, model: 'reviewer' })
2392
+ const spec = makeSpec(
2393
+ { defaults: { review: 'fast', review_budget: 100, on_review_budget_exceeded: 'skip' } },
2394
+ [{ id: 'task-1' }, { id: 'task-2', depends_on: ['task-1'] }],
2395
+ )
2396
+ const result = await reviewEngine(spec, runner).run()
2397
+ expect(result.status).toBe('done')
2398
+ expect(runner).toHaveBeenCalledTimes(1)
2399
+ const byId = Object.fromEntries(readTasks(result.convoyId).tasks.map(t => [t.id, t.review_verdict]))
2400
+ expect(byId).toEqual({ 'task-1': 'pass', 'task-2': 'skipped' })
2401
+ })
2402
+
2403
+ it('review budget spent with stop: the task is review-blocked and nothing new starts', async () => {
2404
+ const runner = vi.fn()
2405
+ const spec = makeSpec(
2406
+ { defaults: { review: 'fast', review_budget: 0, on_review_budget_exceeded: 'stop' } },
2407
+ [{ id: 'task-1' }, { id: 'task-2', depends_on: ['task-1'] }],
2408
+ )
2409
+ const result = await reviewEngine(spec, runner).run()
2410
+ const byId = Object.fromEntries(readTasks(result.convoyId).tasks.map(t => [t.id, t.status]))
2411
+ expect(byId['task-1']).toBe('review-blocked')
2412
+ expect(byId['task-2']).toBe('skipped')
2413
+ expect(runner).not.toHaveBeenCalled()
2635
2414
  })
2636
2415
  })
2637
2416
 
2417
+
2638
2418
  // ── Dispute protocol ──────────────────────────────────────────────────────────
2639
2419
 
2640
2420
  describe('dispute protocol', () => {
@@ -2766,49 +2546,6 @@ describe('dispute protocol', () => {
2766
2546
  })
2767
2547
  })
2768
2548
 
2769
- // ── File-based injection ───────────────────────────────────────────────────
2770
-
2771
- describe('file-based injection', () => {
2772
- it('picks up tasks from inject file and ingests them', async () => {
2773
- const adapter = makeAdapter()
2774
- adapter.execute.mockResolvedValue({ success: true, output: 'ok', exitCode: 0 })
2775
-
2776
- const spec = makeSpec({ concurrency: 1 }, [
2777
- { id: 'task-1', prompt: 'Original task', timeout: '5s' },
2778
- ])
2779
-
2780
- const engine = makeEngine({
2781
- spec,
2782
- specYaml: 'name: test',
2783
- adapter,
2784
- dbPath,
2785
- basePath: tmpDir,
2786
- _worktreeManager: makeWorktreeManager(),
2787
- _mergeQueue: makeMergeQueue(),
2788
- })
2789
-
2790
- const result = await engine.run()
2791
- expect(result.summary.done).toBeGreaterThanOrEqual(1)
2792
- })
2793
-
2794
- it('respects convoy_id path traversal guard', async () => {
2795
- const adapter = makeAdapter()
2796
- const spec = makeSpec()
2797
-
2798
- const engine = makeEngine({
2799
- spec,
2800
- specYaml: 'name: test',
2801
- adapter,
2802
- dbPath,
2803
- basePath: tmpDir,
2804
- _worktreeManager: makeWorktreeManager(),
2805
- _mergeQueue: makeMergeQueue(),
2806
- })
2807
-
2808
- const result = await engine.run()
2809
- expect(result.status).toBe('done')
2810
- })
2811
- })
2812
2549
 
2813
2550
  describe('NDJSON recovery', () => {
2814
2551
  it('truncates partial trailing line in NDJSON file', () => {
@@ -3169,8 +2906,17 @@ describe('swarm mode (concurrency: auto)', () => {
3169
2906
  expect(maxConcurrent).toBeLessThanOrEqual(2)
3170
2907
  })
3171
2908
 
3172
- it('defaults max_swarm_concurrency to 8', async () => {
2909
+ it('runs at most four at once when the spec gives no number', async () => {
3173
2910
  const adapter = makeAdapter()
2911
+ let maxConcurrent = 0
2912
+ let current = 0
2913
+ adapter.execute.mockImplementation(async () => {
2914
+ current++
2915
+ maxConcurrent = Math.max(maxConcurrent, current)
2916
+ await new Promise(r => setTimeout(r, 20))
2917
+ current--
2918
+ return { success: true, output: 'ok', exitCode: 0 }
2919
+ })
3174
2920
 
3175
2921
  const spec = makeSpec(
3176
2922
  { concurrency: 'auto' as unknown as number },
@@ -3192,6 +2938,7 @@ describe('swarm mode (concurrency: auto)', () => {
3192
2938
  const result = await engine.run()
3193
2939
  expect(result.status).toBe('done')
3194
2940
  expect(result.summary.done).toBe(10)
2941
+ expect(maxConcurrent).toBe(4)
3195
2942
  })
3196
2943
  })
3197
2944
 
@@ -3230,9 +2977,12 @@ describe('step retry context prepending', () => {
3230
2977
 
3231
2978
  await engine.run()
3232
2979
 
3233
- // First call uses the original step prompt
3234
- expect(capturedPrompts[0]).toBe('step prompt text')
3235
- // Second call (retry) prepends failure context
2980
+ // First call: the step, inside the shared context and the task's role
2981
+ expect(capturedPrompts[0]).toContain('### Instructions\nstep prompt text')
2982
+ expect(capturedPrompts[0]).toContain('# Convoy: Test Convoy')
2983
+ expect(capturedPrompts[0]).toContain('You are the developer agent for this task.')
2984
+ expect(capturedPrompts[0]).not.toContain('Previous attempt failed.')
2985
+ // Second call (retry) adds the failure context
3236
2986
  expect(capturedPrompts[1]).toContain('Previous attempt failed.')
3237
2987
  expect(capturedPrompts[1]).toContain('Exit code: 2')
3238
2988
  expect(capturedPrompts[1]).toContain('step error detail')
@@ -3573,11 +3323,11 @@ describe('circuit breaker', () => {
3573
3323
  .mockResolvedValueOnce({ success: false, output: 'err', exitCode: 1 })
3574
3324
  .mockResolvedValue({ success: true, output: 'ok', exitCode: 0 })
3575
3325
 
3576
- // threshold=2: task-1 failure is recorded twice (failure path + handleExhaustion),
3577
- // reaching threshold=2 → circuit opens before task-2 and task-3 execute
3326
+ // threshold=1: one failure opens the circuit before task-2 and task-3 start.
3327
+ // (Each failure used to be counted twice, and this test was written around that.)
3578
3328
  const spec = makeSpec({
3579
3329
  on_failure: 'continue',
3580
- defaults: { circuit_breaker: { threshold: 2, cooldown_ms: 999_999_999 } },
3330
+ defaults: { circuit_breaker: { threshold: 1, cooldown_ms: 999_999_999 } },
3581
3331
  }, [
3582
3332
  { id: 'task-1', agent: 'developer', max_retries: 0 },
3583
3333
  { id: 'task-2', agent: 'developer', max_retries: 0 },
@@ -3598,6 +3348,31 @@ describe('circuit breaker', () => {
3598
3348
  expect(result.summary.skipped).toBeGreaterThanOrEqual(2)
3599
3349
  })
3600
3350
 
3351
+ it('hands the task to the fallback agent instead of skipping it', async () => {
3352
+ const adapter = makeAdapter()
3353
+ adapter.execute
3354
+ .mockResolvedValueOnce({ success: false, output: 'err', exitCode: 1 })
3355
+ .mockResolvedValue({ success: true, output: 'ok', exitCode: 0 })
3356
+ const spec = makeSpec({
3357
+ on_failure: 'continue',
3358
+ concurrency: 1,
3359
+ defaults: { circuit_breaker: { threshold: 1, cooldown_ms: 999_999_999, fallback_agent: 'architect' } },
3360
+ }, [
3361
+ { id: 'task-1', agent: 'developer', max_retries: 0 },
3362
+ { id: 'task-2', agent: 'developer', max_retries: 0 },
3363
+ ])
3364
+ const engine = makeEngine({
3365
+ spec, specYaml: 'name: test', adapter, dbPath,
3366
+ _worktreeManager: makeWorktreeManager(), _mergeQueue: makeMergeQueue(),
3367
+ })
3368
+ const result = await engine.run()
3369
+ // task-2 ran, as the fallback agent, and was not skipped.
3370
+ expect(adapter.execute).toHaveBeenCalledTimes(2)
3371
+ const second = adapter.execute.mock.calls[1][0] as { id: string; agent: string }
3372
+ expect(second).toMatchObject({ id: 'task-2', agent: 'architect' })
3373
+ expect(result.summary.skipped ?? 0).toBe(0)
3374
+ })
3375
+
3601
3376
  it('records success and persists closed circuit state to store', async () => {
3602
3377
  const adapter = makeAdapter()
3603
3378
  const spec = makeSpec({
@@ -3627,12 +3402,13 @@ describe('circuit breaker', () => {
3627
3402
  const adapter = makeAdapter()
3628
3403
  adapter.execute.mockResolvedValue({ success: false, output: 'err', exitCode: 1 })
3629
3404
 
3630
- // threshold=2: first failure double-records → count reaches 2 → circuit opens
3405
+ // threshold=2, two failures: counted once each, the second opens it
3631
3406
  const spec = makeSpec({
3632
3407
  on_failure: 'continue',
3633
3408
  defaults: { circuit_breaker: { threshold: 2, cooldown_ms: 999_999_999 } },
3634
3409
  }, [
3635
3410
  { id: 'task-f1', agent: 'developer', max_retries: 0 },
3411
+ { id: 'task-f2', agent: 'developer', max_retries: 0 },
3636
3412
  ])
3637
3413
  const engine = makeEngine({
3638
3414
  spec,
@@ -3775,19 +3551,13 @@ describe('createEventEmitter callsite safety', () => {
3775
3551
 
3776
3552
  // ── Contract retry ────────────────────────────────────────────────────────────
3777
3553
 
3778
- describe('contract retry', () => {
3779
- it('retries when output is missing OUTPUT_CONTRACT and retries remain', async () => {
3780
- const validContractOutput = [
3781
- 'Work done.',
3782
- '<!-- OUTPUT_CONTRACT',
3783
- '{ "files_changed": ["src/foo.ts"], "tests_added": ["src/foo.test.ts"], "summary": "implemented" }',
3784
- '-->',
3785
- ].join('\n')
3786
-
3554
+ describe('output contract', () => {
3555
+ it('only warns about a missing contract — the task is never run again', async () => {
3556
+ // The re-run used to happen after the first attempt had already merged:
3557
+ // two tasks produced four agent sessions and four commits.
3787
3558
  const adapter = makeAdapter()
3788
- adapter.execute
3789
- .mockResolvedValueOnce({ success: true, output: 'no contract here', exitCode: 0 })
3790
- .mockResolvedValueOnce({ success: true, output: validContractOutput, exitCode: 0 })
3559
+ adapter.execute.mockResolvedValue({ success: true, output: 'no contract here', exitCode: 0 })
3560
+ const mergeQueue = makeMergeQueue()
3791
3561
 
3792
3562
  const engine = makeEngine({
3793
3563
  spec: makeSpec({}, [{ agent: 'developer', max_retries: 1 }]),
@@ -3795,24 +3565,15 @@ describe('contract retry', () => {
3795
3565
  adapter,
3796
3566
  dbPath,
3797
3567
  _worktreeManager: makeWorktreeManager(),
3798
- _mergeQueue: makeMergeQueue(),
3568
+ _mergeQueue: mergeQueue,
3799
3569
  })
3800
3570
  const result = await engine.run()
3801
3571
  expect(result.status).toBe('done')
3802
- expect(adapter.execute).toHaveBeenCalledTimes(2)
3803
-
3804
- // Second prompt should contain the contract retry message
3805
- const secondPrompt = (adapter.execute.mock.calls[1] as [Task])[0].prompt
3806
- expect(secondPrompt).toContain('OUTPUT_CONTRACT')
3807
- expect(secondPrompt).toContain('Missing fields')
3808
-
3809
- const store = createConvoyStore(dbPath)
3810
- const tasks = store.getTasksByConvoy(result.convoyId)
3811
- store.close()
3812
- expect(tasks[0].status).toBe('done')
3572
+ expect(adapter.execute).toHaveBeenCalledTimes(1)
3573
+ expect(mergeQueue.merge).toHaveBeenCalledTimes(1)
3813
3574
  })
3814
3575
 
3815
- it('emits contract_violation and marks done when retries exhausted', async () => {
3576
+ it('emits contract_violation and marks done', async () => {
3816
3577
  const adapter = makeAdapter()
3817
3578
  adapter.execute.mockResolvedValue({ success: true, output: 'no contract here', exitCode: 0 })
3818
3579
 
@@ -4031,3 +3792,209 @@ describe('permission mode', () => {
4031
3792
 
4032
3793
  // ── Compaction continuation ───────────────────────────────────────────────────
4033
3794
 
3795
+
3796
+ // ── Scheduler: a ready queue, not phase barriers ──────────────────────────────
3797
+
3798
+ describe('ready-queue scheduler', () => {
3799
+ it('runs the audit’s demo in about 6s, not 8.6s', async () => {
3800
+ // slow 6s, fast1 1s, fast2 (after fast1) 1s, indep 1s, two slots. With
3801
+ // phase barriers fast2 waited for slow: 6 + 1 + 1 ≈ 8.6s measured. With a
3802
+ // ready queue it starts the moment fast1 is done, and the run takes as
3803
+ // long as its slowest task.
3804
+ vi.useFakeTimers()
3805
+ try {
3806
+ const durations: Record<string, number> = { slow: 6000, fast1: 1000, fast2: 1000, indep: 1000 }
3807
+ const timeline: Record<string, { start: number; end: number }> = {}
3808
+ const adapter = makeAdapter()
3809
+ adapter.execute.mockImplementation(async (task: Task) => {
3810
+ const start = Date.now()
3811
+ await new Promise(r => setTimeout(r, durations[task.id]))
3812
+ timeline[task.id] = { start, end: Date.now() }
3813
+ return { success: true, output: 'ok', exitCode: 0 }
3814
+ })
3815
+ const spec = makeSpec({ concurrency: 2 }, [
3816
+ { id: 'slow' },
3817
+ { id: 'fast1' },
3818
+ { id: 'fast2', depends_on: ['fast1'] },
3819
+ { id: 'indep' },
3820
+ ])
3821
+ const t0 = Date.now()
3822
+ let finished = false
3823
+ const run = makeEngine({
3824
+ spec, specYaml: 'name: test', adapter, dbPath,
3825
+ _worktreeManager: makeWorktreeManager(), _mergeQueue: makeMergeQueue(),
3826
+ }).run().finally(() => { finished = true })
3827
+ while (!finished) await vi.advanceTimersByTimeAsync(50)
3828
+ const result = await run
3829
+ const total = Date.now() - t0
3830
+
3831
+ expect(result.status).toBe('done')
3832
+ expect(total).toBeGreaterThanOrEqual(6000)
3833
+ expect(total).toBeLessThan(6500)
3834
+ // fast2 ran while slow was still running.
3835
+ expect(timeline.fast2.start).toBeLessThan(timeline.slow.end)
3836
+ expect(timeline.fast2.start - t0).toBeLessThan(1500)
3837
+ } finally {
3838
+ vi.useRealTimers()
3839
+ }
3840
+ })
3841
+
3842
+ it('never runs a task next to a running task whose files overlap, though both are ready', async () => {
3843
+ // `writer` becomes ready while `owner` still holds src/ — the dynamic form
3844
+ // of the per-phase partition check, which only compared tasks in one phase.
3845
+ const timeline: Record<string, { start: number; end: number }> = {}
3846
+ const adapter = makeAdapter()
3847
+ adapter.execute.mockImplementation(async (task: Task) => {
3848
+ const start = Date.now()
3849
+ await new Promise(r => setTimeout(r, task.id === 'owner' ? 120 : 10))
3850
+ timeline[task.id] = { start, end: Date.now() }
3851
+ return { success: true, output: 'ok', exitCode: 0 }
3852
+ })
3853
+ const spec = makeSpec({ concurrency: 3 }, [
3854
+ { id: 'owner', files: ['src/'] },
3855
+ { id: 'gate', files: [] },
3856
+ { id: 'writer', files: ['src/api.ts'], depends_on: ['gate'] },
3857
+ ])
3858
+ // Real (empty) directories: tasks with files are symlink-scanned in their worktree.
3859
+ const wt = makeWorktreeManager()
3860
+ wt.create.mockImplementation(async (id: string) => {
3861
+ const dir = join(tmpDir, 'wt', id)
3862
+ mkdirSync(dir, { recursive: true })
3863
+ return dir
3864
+ })
3865
+ const result = await makeEngine({
3866
+ spec, specYaml: 'name: test', adapter, dbPath,
3867
+ _worktreeManager: wt, _mergeQueue: makeMergeQueue(),
3868
+ }).run()
3869
+ expect(result.status).toBe('done')
3870
+ expect(timeline.writer.start).toBeGreaterThanOrEqual(timeline.owner.end)
3871
+ })
3872
+
3873
+ it('refuses a plan whose same-phase tasks overlap, before recording anything', async () => {
3874
+ const adapter = makeAdapter()
3875
+ const engine = makeEngine({
3876
+ spec: makeSpec({}, [{ id: 'a', files: ['src/'] }, { id: 'b', files: ['src/x.ts'] }]),
3877
+ specYaml: 'name: test', adapter, dbPath,
3878
+ _worktreeManager: makeWorktreeManager(), _mergeQueue: makeMergeQueue(),
3879
+ })
3880
+ await expect(engine.run()).rejects.toThrow('File partition conflicts detected')
3881
+ const store = createConvoyStore(dbPath)
3882
+ expect(store.getLatestConvoy()).toBeUndefined()
3883
+ store.close()
3884
+ expect(adapter.execute).not.toHaveBeenCalled()
3885
+ })
3886
+ })
3887
+
3888
+ // ── Resume resets everything retry did ────────────────────────────────────────
3889
+
3890
+ describe('resume resets every unfinished task', () => {
3891
+ it('reopens failed, timed-out, gate-failed, review-blocked, disputed, interrupted and skipped tasks', async () => {
3892
+ const convoyId = 'convoy-mixed'
3893
+ const statuses = ['done', 'failed', 'timed-out', 'gate-failed', 'review-blocked', 'disputed', 'running', 'assigned', 'skipped'] as const
3894
+ const seeder = createConvoyStore(dbPath)
3895
+ seeder.insertConvoy({ id: convoyId, name: 'Mixed', spec_hash: 'x', status: 'failed', branch: 'feat/mixed', created_at: new Date().toISOString(), spec_yaml: 'name: m' })
3896
+ for (const status of statuses) {
3897
+ seeder.insertTask({
3898
+ id: `t-${status}`, convoy_id: convoyId, phase: 0, prompt: `p ${status}`, agent: 'developer', adapter: null, model: null,
3899
+ timeout_ms: 30_000, status, retries: 1, max_retries: 1, files: null, depends_on: null, gates: null,
3900
+ })
3901
+ }
3902
+ seeder.close()
3903
+
3904
+ const adapter = makeAdapter()
3905
+ const result = await makeEngine({
3906
+ spec: makeSpec({ concurrency: 4 }, statuses.map(s => ({ id: `t-${s}` }))),
3907
+ specYaml: 'name: test', adapter, dbPath,
3908
+ _worktreeManager: makeWorktreeManager(), _mergeQueue: makeMergeQueue(),
3909
+ }).resume(convoyId)
3910
+
3911
+ expect(result.status).toBe('done')
3912
+ const ran = adapter.execute.mock.calls.map(([t]) => (t as Task).id).sort()
3913
+ expect(ran).toEqual(statuses.filter(s => s !== 'done').map(s => `t-${s}`).sort())
3914
+ const store = createConvoyStore(dbPath)
3915
+ const events = store.getEvents(convoyId).filter(e => e.type === 'task_retried')
3916
+ store.close()
3917
+ expect(events).toHaveLength(8)
3918
+ })
3919
+
3920
+ it('retryFailed with task ids brings the dependents a failure skipped along', async () => {
3921
+ const convoyId = 'convoy-chain'
3922
+ const seeder = createConvoyStore(dbPath)
3923
+ seeder.insertConvoy({ id: convoyId, name: 'Chain', spec_hash: 'x', status: 'done', branch: 'feat/chain', created_at: new Date().toISOString(), spec_yaml: 'name: c' })
3924
+ const task = (id: string, status: 'failed' | 'skipped' | 'done', deps: string[] = []) => seeder.insertTask({
3925
+ id, convoy_id: convoyId, phase: deps.length, prompt: id, agent: 'developer', adapter: null, model: null,
3926
+ timeout_ms: 30_000, status, retries: 0, max_retries: 0, files: null, depends_on: deps.length ? JSON.stringify(deps) : null, gates: null,
3927
+ })
3928
+ task('a', 'failed')
3929
+ task('b', 'skipped', ['a'])
3930
+ task('c', 'skipped', ['b'])
3931
+ task('other', 'failed')
3932
+ seeder.close()
3933
+
3934
+ const engine = makeEngine({
3935
+ spec: makeSpec({}, [{ id: 'a' }]), specYaml: 'name: test', adapter: makeAdapter(), dbPath,
3936
+ _worktreeManager: makeWorktreeManager(), _mergeQueue: makeMergeQueue(),
3937
+ })
3938
+ await engine.retryFailed(convoyId, ['a'])
3939
+
3940
+ const store = createConvoyStore(dbPath)
3941
+ const byId = Object.fromEntries(store.getTasksByConvoy(convoyId).map(t => [t.id, t.status]))
3942
+ store.close()
3943
+ expect(byId).toEqual({ a: 'pending', b: 'pending', c: 'pending', other: 'failed' })
3944
+ })
3945
+ })
3946
+
3947
+ // ── Telemetry ─────────────────────────────────────────────────────────────────
3948
+
3949
+ describe('telemetry', () => {
3950
+ it('records the agent’s real tier, not a hard-coded "standard"', async () => {
3951
+ const result = await makeEngine({
3952
+ spec: makeSpec({}, [{ id: 'sec', agent: 'security-expert' }, { id: 'doc', agent: 'writer' }]),
3953
+ specYaml: 'name: test', adapter: makeAdapter(), dbPath,
3954
+ _worktreeManager: makeWorktreeManager(), _mergeQueue: makeMergeQueue(),
3955
+ }).run()
3956
+ const store = createConvoyStore(dbPath)
3957
+ const tiers = Object.fromEntries(store.getEvents(result.convoyId)
3958
+ .filter(e => e.type === 'delegation')
3959
+ .map(e => [e.task_id, (JSON.parse(e.data!) as { tier: string }).tier]))
3960
+ store.close()
3961
+ expect(tiers).toEqual({ sec: 'premium', doc: 'economy' })
3962
+ })
3963
+
3964
+ it('counts a failure once toward the circuit breaker', async () => {
3965
+ const adapter = makeAdapter()
3966
+ adapter.execute.mockResolvedValue({ success: false, output: 'err', exitCode: 1 })
3967
+ const result = await makeEngine({
3968
+ spec: makeSpec({ defaults: { circuit_breaker: { threshold: 5 } } }, [{ id: 'only', max_retries: 0 }]),
3969
+ specYaml: 'name: test', adapter, dbPath,
3970
+ _worktreeManager: makeWorktreeManager(), _mergeQueue: makeMergeQueue(),
3971
+ }).run()
3972
+ const store = createConvoyStore(dbPath)
3973
+ const state = JSON.parse(store.getConvoy(result.convoyId)!.circuit_state!) as Record<string, { failures: number }>
3974
+ store.close()
3975
+ expect(state.developer.failures).toBe(1)
3976
+ })
3977
+
3978
+ it('masks a secret in a failure before it reaches the task row, the DLQ and the ledger', async () => {
3979
+ gates._setAllowlistConfigPath('/nonexistent/secret-scan-config.yml')
3980
+ gates._resetAllowlistCache()
3981
+ const token = 'ghp_' + 'abcdefghijklmnopqrstuvwxyz0123456789AB'
3982
+ const adapter = makeAdapter()
3983
+ adapter.execute.mockResolvedValue({ success: false, output: `auth failed with token ${token}`, exitCode: 1 })
3984
+ const result = await makeEngine({
3985
+ spec: makeSpec({}, [{ id: 'leaky', max_retries: 0 }]),
3986
+ specYaml: 'name: test', adapter, dbPath,
3987
+ _worktreeManager: makeWorktreeManager(), _mergeQueue: makeMergeQueue(),
3988
+ }).run()
3989
+ const store = createConvoyStore(dbPath)
3990
+ const task = store.getTask('leaky', result.convoyId)!
3991
+ const dlq = store.listDlqEntries(result.convoyId)
3992
+ const events = store.getEvents(result.convoyId)
3993
+ store.close()
3994
+ expect(task.output).not.toContain(token)
3995
+ expect(dlq).toHaveLength(1)
3996
+ expect(dlq[0].error_output).not.toContain(token)
3997
+ expect(JSON.stringify(events)).not.toContain(token)
3998
+ expect(readFileSync(join(tmpDir, '.opencastle', 'AGENT-FAILURES.md'), 'utf8')).not.toContain(token)
3999
+ })
4000
+ })