opencastle 1.3.1 → 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 (486) hide show
  1. package/README.md +16 -10
  2. package/bin/cli.mjs +8 -9
  3. package/dist/cli/agent-roster.test.js +0 -48
  4. package/dist/cli/agent-roster.test.js.map +1 -1
  5. package/dist/cli/boundary.test.js +9 -7
  6. package/dist/cli/boundary.test.js.map +1 -1
  7. package/dist/cli/convoy/artifacts.d.ts +9 -2
  8. package/dist/cli/convoy/artifacts.d.ts.map +1 -1
  9. package/dist/cli/convoy/artifacts.js +13 -10
  10. package/dist/cli/convoy/artifacts.js.map +1 -1
  11. package/dist/cli/convoy/artifacts.test.js +4 -2
  12. package/dist/cli/convoy/artifacts.test.js.map +1 -1
  13. package/dist/cli/convoy/engine.d.ts +53 -23
  14. package/dist/cli/convoy/engine.d.ts.map +1 -1
  15. package/dist/cli/convoy/engine.git.test.d.ts +2 -0
  16. package/dist/cli/convoy/engine.git.test.d.ts.map +1 -0
  17. package/dist/cli/convoy/engine.git.test.js +435 -0
  18. package/dist/cli/convoy/engine.git.test.js.map +1 -0
  19. package/dist/cli/convoy/engine.js +1746 -2305
  20. package/dist/cli/convoy/engine.js.map +1 -1
  21. package/dist/cli/convoy/engine.test.js +698 -678
  22. package/dist/cli/convoy/engine.test.js.map +1 -1
  23. package/dist/cli/convoy/event-schemas.d.ts +2 -0
  24. package/dist/cli/convoy/event-schemas.d.ts.map +1 -1
  25. package/dist/cli/convoy/event-schemas.js +59 -57
  26. package/dist/cli/convoy/event-schemas.js.map +1 -1
  27. package/dist/cli/convoy/events.d.ts +4 -1
  28. package/dist/cli/convoy/events.d.ts.map +1 -1
  29. package/dist/cli/convoy/events.js +69 -84
  30. package/dist/cli/convoy/events.js.map +1 -1
  31. package/dist/cli/convoy/events.test.js +50 -9
  32. package/dist/cli/convoy/events.test.js.map +1 -1
  33. package/dist/cli/convoy/gates.d.ts +9 -4
  34. package/dist/cli/convoy/gates.d.ts.map +1 -1
  35. package/dist/cli/convoy/gates.js +29 -14
  36. package/dist/cli/convoy/gates.js.map +1 -1
  37. package/dist/cli/convoy/isolation.d.ts +32 -6
  38. package/dist/cli/convoy/isolation.d.ts.map +1 -1
  39. package/dist/cli/convoy/isolation.js +72 -34
  40. package/dist/cli/convoy/isolation.js.map +1 -1
  41. package/dist/cli/convoy/isolation.test.js +66 -42
  42. package/dist/cli/convoy/isolation.test.js.map +1 -1
  43. package/dist/cli/convoy/lock.d.ts.map +1 -1
  44. package/dist/cli/convoy/lock.js +25 -10
  45. package/dist/cli/convoy/lock.js.map +1 -1
  46. package/dist/cli/convoy/lock.test.js +12 -0
  47. package/dist/cli/convoy/lock.test.js.map +1 -1
  48. package/dist/cli/convoy/merge.d.ts +21 -4
  49. package/dist/cli/convoy/merge.d.ts.map +1 -1
  50. package/dist/cli/convoy/merge.js +69 -53
  51. package/dist/cli/convoy/merge.js.map +1 -1
  52. package/dist/cli/convoy/merge.test.js +23 -1
  53. package/dist/cli/convoy/merge.test.js.map +1 -1
  54. package/dist/cli/convoy/progress.d.ts +35 -0
  55. package/dist/cli/convoy/progress.d.ts.map +1 -0
  56. package/dist/cli/convoy/progress.js +103 -0
  57. package/dist/cli/convoy/progress.js.map +1 -0
  58. package/dist/cli/convoy/progress.test.d.ts +2 -0
  59. package/dist/cli/convoy/progress.test.d.ts.map +1 -0
  60. package/dist/cli/convoy/progress.test.js +53 -0
  61. package/dist/cli/convoy/progress.test.js.map +1 -0
  62. package/dist/cli/convoy/read-model.d.ts +468 -0
  63. package/dist/cli/convoy/read-model.d.ts.map +1 -0
  64. package/dist/cli/convoy/read-model.js +1132 -0
  65. package/dist/cli/convoy/read-model.js.map +1 -0
  66. package/dist/cli/convoy/read-model.test.d.ts +2 -0
  67. package/dist/cli/convoy/read-model.test.d.ts.map +1 -0
  68. package/dist/cli/convoy/read-model.test.js +609 -0
  69. package/dist/cli/convoy/read-model.test.js.map +1 -0
  70. package/dist/cli/convoy/redact.d.ts +34 -0
  71. package/dist/cli/convoy/redact.d.ts.map +1 -0
  72. package/dist/cli/convoy/redact.js +66 -0
  73. package/dist/cli/convoy/redact.js.map +1 -0
  74. package/dist/cli/convoy/redact.test.d.ts +2 -0
  75. package/dist/cli/convoy/redact.test.d.ts.map +1 -0
  76. package/dist/cli/convoy/redact.test.js +43 -0
  77. package/dist/cli/convoy/redact.test.js.map +1 -0
  78. package/dist/cli/convoy/reviewer.d.ts +65 -0
  79. package/dist/cli/convoy/reviewer.d.ts.map +1 -0
  80. package/dist/cli/convoy/reviewer.js +141 -0
  81. package/dist/cli/convoy/reviewer.js.map +1 -0
  82. package/dist/cli/convoy/reviewer.test.d.ts +2 -0
  83. package/dist/cli/convoy/reviewer.test.d.ts.map +1 -0
  84. package/dist/cli/convoy/reviewer.test.js +96 -0
  85. package/dist/cli/convoy/reviewer.test.js.map +1 -0
  86. package/dist/cli/convoy/schedule.d.ts +30 -0
  87. package/dist/cli/convoy/schedule.d.ts.map +1 -0
  88. package/dist/cli/convoy/schedule.js +111 -0
  89. package/dist/cli/convoy/schedule.js.map +1 -0
  90. package/dist/cli/convoy/schedule.test.d.ts +2 -0
  91. package/dist/cli/convoy/schedule.test.d.ts.map +1 -0
  92. package/dist/cli/convoy/schedule.test.js +45 -0
  93. package/dist/cli/convoy/schedule.test.js.map +1 -0
  94. package/dist/cli/convoy/spec-builder.d.ts +120 -30
  95. package/dist/cli/convoy/spec-builder.d.ts.map +1 -1
  96. package/dist/cli/convoy/spec-builder.js +438 -114
  97. package/dist/cli/convoy/spec-builder.js.map +1 -1
  98. package/dist/cli/convoy/spec-builder.test.js +419 -435
  99. package/dist/cli/convoy/spec-builder.test.js.map +1 -1
  100. package/dist/cli/convoy/spec-types.d.ts +46 -92
  101. package/dist/cli/convoy/spec-types.d.ts.map +1 -1
  102. package/dist/cli/convoy/store.d.ts +6 -1
  103. package/dist/cli/convoy/store.d.ts.map +1 -1
  104. package/dist/cli/convoy/store.js +111 -15
  105. package/dist/cli/convoy/store.js.map +1 -1
  106. package/dist/cli/convoy/store.test.js +59 -13
  107. package/dist/cli/convoy/store.test.js.map +1 -1
  108. package/dist/cli/convoy/types.d.ts +76 -113
  109. package/dist/cli/convoy/types.d.ts.map +1 -1
  110. package/dist/cli/convoy/types.js +6 -13
  111. package/dist/cli/convoy/types.js.map +1 -1
  112. package/dist/cli/convoy/worktree.d.ts +88 -3
  113. package/dist/cli/convoy/worktree.d.ts.map +1 -1
  114. package/dist/cli/convoy/worktree.js +282 -56
  115. package/dist/cli/convoy/worktree.js.map +1 -1
  116. package/dist/cli/convoy/worktree.test.js +132 -1
  117. package/dist/cli/convoy/worktree.test.js.map +1 -1
  118. package/dist/cli/convoy-args.test.js +9 -27
  119. package/dist/cli/convoy-args.test.js.map +1 -1
  120. package/dist/cli/convoy-cmd.d.ts +31 -6
  121. package/dist/cli/convoy-cmd.d.ts.map +1 -1
  122. package/dist/cli/convoy-cmd.js +150 -201
  123. package/dist/cli/convoy-cmd.js.map +1 -1
  124. package/dist/cli/convoy-cmd.test.d.ts +2 -0
  125. package/dist/cli/convoy-cmd.test.d.ts.map +1 -0
  126. package/dist/cli/convoy-cmd.test.js +144 -0
  127. package/dist/cli/convoy-cmd.test.js.map +1 -0
  128. package/dist/cli/dashboard.d.ts +24 -11
  129. package/dist/cli/dashboard.d.ts.map +1 -1
  130. package/dist/cli/dashboard.js +241 -303
  131. package/dist/cli/dashboard.js.map +1 -1
  132. package/dist/cli/dashboard.test.d.ts +2 -0
  133. package/dist/cli/dashboard.test.d.ts.map +1 -0
  134. package/dist/cli/dashboard.test.js +340 -0
  135. package/dist/cli/dashboard.test.js.map +1 -0
  136. package/dist/cli/dispatcher.test.js +35 -2
  137. package/dist/cli/dispatcher.test.js.map +1 -1
  138. package/dist/cli/docs-accuracy.test.js +3 -3
  139. package/dist/cli/docs-accuracy.test.js.map +1 -1
  140. package/dist/cli/log.d.ts +39 -0
  141. package/dist/cli/log.d.ts.map +1 -1
  142. package/dist/cli/log.js +267 -93
  143. package/dist/cli/log.js.map +1 -1
  144. package/dist/cli/log.test.d.ts +2 -0
  145. package/dist/cli/log.test.d.ts.map +1 -0
  146. package/dist/cli/log.test.js +208 -0
  147. package/dist/cli/log.test.js.map +1 -0
  148. package/dist/cli/nearest.d.ts +18 -0
  149. package/dist/cli/nearest.d.ts.map +1 -0
  150. package/dist/cli/nearest.js +38 -0
  151. package/dist/cli/nearest.js.map +1 -0
  152. package/dist/cli/nearest.test.d.ts +2 -0
  153. package/dist/cli/nearest.test.d.ts.map +1 -0
  154. package/dist/cli/nearest.test.js +24 -0
  155. package/dist/cli/nearest.test.js.map +1 -0
  156. package/dist/cli/pipeline.d.ts +61 -0
  157. package/dist/cli/pipeline.d.ts.map +1 -1
  158. package/dist/cli/pipeline.flow.test.d.ts +2 -0
  159. package/dist/cli/pipeline.flow.test.d.ts.map +1 -0
  160. package/dist/cli/pipeline.flow.test.js +524 -0
  161. package/dist/cli/pipeline.flow.test.js.map +1 -0
  162. package/dist/cli/pipeline.js +471 -690
  163. package/dist/cli/pipeline.js.map +1 -1
  164. package/dist/cli/plan.d.ts +82 -31
  165. package/dist/cli/plan.d.ts.map +1 -1
  166. package/dist/cli/plan.js +167 -507
  167. package/dist/cli/plan.js.map +1 -1
  168. package/dist/cli/plan.test.d.ts +2 -0
  169. package/dist/cli/plan.test.d.ts.map +1 -0
  170. package/dist/cli/plan.test.js +158 -0
  171. package/dist/cli/plan.test.js.map +1 -0
  172. package/dist/cli/run/adapters/agent-process.d.ts +82 -0
  173. package/dist/cli/run/adapters/agent-process.d.ts.map +1 -0
  174. package/dist/cli/run/adapters/agent-process.js +224 -0
  175. package/dist/cli/run/adapters/agent-process.js.map +1 -0
  176. package/dist/cli/run/adapters/agent-process.test.d.ts +2 -0
  177. package/dist/cli/run/adapters/agent-process.test.d.ts.map +1 -0
  178. package/dist/cli/run/adapters/agent-process.test.js +159 -0
  179. package/dist/cli/run/adapters/agent-process.test.js.map +1 -0
  180. package/dist/cli/run/adapters/claude.d.ts +53 -2
  181. package/dist/cli/run/adapters/claude.d.ts.map +1 -1
  182. package/dist/cli/run/adapters/claude.js +147 -171
  183. package/dist/cli/run/adapters/claude.js.map +1 -1
  184. package/dist/cli/run/adapters/claude.test.js +197 -254
  185. package/dist/cli/run/adapters/claude.test.js.map +1 -1
  186. package/dist/cli/run/adapters/codex.d.ts +25 -2
  187. package/dist/cli/run/adapters/codex.d.ts.map +1 -1
  188. package/dist/cli/run/adapters/codex.js +113 -81
  189. package/dist/cli/run/adapters/codex.js.map +1 -1
  190. package/dist/cli/run/adapters/codex.test.js +116 -95
  191. package/dist/cli/run/adapters/codex.test.js.map +1 -1
  192. package/dist/cli/run/adapters/copilot.d.ts +35 -1
  193. package/dist/cli/run/adapters/copilot.d.ts.map +1 -1
  194. package/dist/cli/run/adapters/copilot.js +104 -287
  195. package/dist/cli/run/adapters/copilot.js.map +1 -1
  196. package/dist/cli/run/adapters/copilot.test.js +122 -282
  197. package/dist/cli/run/adapters/copilot.test.js.map +1 -1
  198. package/dist/cli/run/adapters/cursor.d.ts +25 -7
  199. package/dist/cli/run/adapters/cursor.d.ts.map +1 -1
  200. package/dist/cli/run/adapters/cursor.js +103 -156
  201. package/dist/cli/run/adapters/cursor.js.map +1 -1
  202. package/dist/cli/run/adapters/cursor.test.js +106 -218
  203. package/dist/cli/run/adapters/cursor.test.js.map +1 -1
  204. package/dist/cli/run/adapters/index.d.ts +34 -5
  205. package/dist/cli/run/adapters/index.d.ts.map +1 -1
  206. package/dist/cli/run/adapters/index.js +147 -21
  207. package/dist/cli/run/adapters/index.js.map +1 -1
  208. package/dist/cli/run/adapters/index.test.d.ts +2 -0
  209. package/dist/cli/run/adapters/index.test.d.ts.map +1 -0
  210. package/dist/cli/run/adapters/index.test.js +129 -0
  211. package/dist/cli/run/adapters/index.test.js.map +1 -0
  212. package/dist/cli/run/adapters/opencode.d.ts +25 -9
  213. package/dist/cli/run/adapters/opencode.d.ts.map +1 -1
  214. package/dist/cli/run/adapters/opencode.js +136 -152
  215. package/dist/cli/run/adapters/opencode.js.map +1 -1
  216. package/dist/cli/run/adapters/opencode.test.js +99 -218
  217. package/dist/cli/run/adapters/opencode.test.js.map +1 -1
  218. package/dist/cli/run/adapters/permission-modes.d.ts +47 -4
  219. package/dist/cli/run/adapters/permission-modes.d.ts.map +1 -1
  220. package/dist/cli/run/adapters/permission-modes.js +113 -37
  221. package/dist/cli/run/adapters/permission-modes.js.map +1 -1
  222. package/dist/cli/run/adapters/permission-modes.test.js +55 -40
  223. package/dist/cli/run/adapters/permission-modes.test.js.map +1 -1
  224. package/dist/cli/run/adapters/stub-cli.test-helper.d.ts +22 -0
  225. package/dist/cli/run/adapters/stub-cli.test-helper.d.ts.map +1 -0
  226. package/dist/cli/run/adapters/stub-cli.test-helper.js +73 -0
  227. package/dist/cli/run/adapters/stub-cli.test-helper.js.map +1 -0
  228. package/dist/cli/run/platform.d.ts +52 -0
  229. package/dist/cli/run/platform.d.ts.map +1 -0
  230. package/dist/cli/run/platform.js +207 -0
  231. package/dist/cli/run/platform.js.map +1 -0
  232. package/dist/cli/run/platform.test.d.ts +2 -0
  233. package/dist/cli/run/platform.test.d.ts.map +1 -0
  234. package/dist/cli/run/platform.test.js +119 -0
  235. package/dist/cli/run/platform.test.js.map +1 -0
  236. package/dist/cli/run/schema.d.ts +6 -8
  237. package/dist/cli/run/schema.d.ts.map +1 -1
  238. package/dist/cli/run/schema.js +44 -68
  239. package/dist/cli/run/schema.js.map +1 -1
  240. package/dist/cli/run/schema.test.js +59 -279
  241. package/dist/cli/run/schema.test.js.map +1 -1
  242. package/dist/cli/run.d.ts +34 -56
  243. package/dist/cli/run.d.ts.map +1 -1
  244. package/dist/cli/run.js +379 -1132
  245. package/dist/cli/run.js.map +1 -1
  246. package/dist/cli/run.test.d.ts +2 -0
  247. package/dist/cli/run.test.d.ts.map +1 -0
  248. package/dist/cli/run.test.js +318 -0
  249. package/dist/cli/run.test.js.map +1 -0
  250. package/dist/cli/team-config.d.ts.map +1 -1
  251. package/dist/cli/team-config.js +2 -21
  252. package/dist/cli/team-config.js.map +1 -1
  253. package/dist/cli/tiers.test.js +4 -13
  254. package/dist/cli/tiers.test.js.map +1 -1
  255. package/package.json +3 -10
  256. package/src/cli/agent-roster.test.ts +0 -55
  257. package/src/cli/boundary.test.ts +9 -7
  258. package/src/cli/convoy/TELEMETRY.md +131 -125
  259. package/src/cli/convoy/artifacts.test.ts +4 -2
  260. package/src/cli/convoy/artifacts.ts +13 -12
  261. package/src/cli/convoy/engine.git.test.ts +462 -0
  262. package/src/cli/convoy/engine.test.ts +817 -850
  263. package/src/cli/convoy/engine.ts +1864 -2596
  264. package/src/cli/convoy/event-schemas.ts +63 -59
  265. package/src/cli/convoy/events.test.ts +58 -9
  266. package/src/cli/convoy/events.ts +69 -91
  267. package/src/cli/convoy/gates.ts +31 -12
  268. package/src/cli/convoy/isolation.test.ts +76 -43
  269. package/src/cli/convoy/isolation.ts +100 -38
  270. package/src/cli/convoy/lock.test.ts +16 -0
  271. package/src/cli/convoy/lock.ts +25 -8
  272. package/src/cli/convoy/merge.test.ts +25 -1
  273. package/src/cli/convoy/merge.ts +74 -61
  274. package/src/cli/convoy/progress.test.ts +59 -0
  275. package/src/cli/convoy/progress.ts +121 -0
  276. package/src/cli/convoy/read-model.test.ts +685 -0
  277. package/src/cli/convoy/read-model.ts +1469 -0
  278. package/src/cli/convoy/redact.test.ts +49 -0
  279. package/src/cli/convoy/redact.ts +73 -0
  280. package/src/cli/convoy/reviewer.test.ts +112 -0
  281. package/src/cli/convoy/reviewer.ts +196 -0
  282. package/src/cli/convoy/schedule.test.ts +56 -0
  283. package/src/cli/convoy/schedule.ts +109 -0
  284. package/src/cli/convoy/spec-builder.test.ts +460 -464
  285. package/src/cli/convoy/spec-builder.ts +460 -129
  286. package/src/cli/convoy/spec-types.ts +46 -108
  287. package/src/cli/convoy/store.test.ts +64 -13
  288. package/src/cli/convoy/store.ts +143 -33
  289. package/src/cli/convoy/types.ts +59 -71
  290. package/src/cli/convoy/worktree.test.ts +140 -1
  291. package/src/cli/convoy/worktree.ts +311 -61
  292. package/src/cli/convoy-args.test.ts +10 -30
  293. package/src/cli/convoy-cmd.test.ts +163 -0
  294. package/src/cli/convoy-cmd.ts +173 -216
  295. package/src/cli/dashboard/dashboard.css +2086 -0
  296. package/src/cli/dashboard/dashboard.js +1687 -0
  297. package/src/cli/dashboard/index.html +307 -0
  298. package/src/cli/dashboard.test.ts +382 -0
  299. package/src/cli/dashboard.ts +243 -339
  300. package/src/cli/dispatcher.test.ts +36 -2
  301. package/src/cli/docs-accuracy.test.ts +3 -3
  302. package/src/cli/log.test.ts +228 -0
  303. package/src/cli/log.ts +302 -83
  304. package/src/cli/nearest.test.ts +27 -0
  305. package/src/cli/nearest.ts +38 -0
  306. package/src/cli/pipeline.flow.test.ts +607 -0
  307. package/src/cli/pipeline.ts +544 -759
  308. package/src/cli/plan.test.ts +193 -0
  309. package/src/cli/plan.ts +209 -545
  310. package/src/cli/run/adapters/agent-process.test.ts +175 -0
  311. package/src/cli/run/adapters/agent-process.ts +252 -0
  312. package/src/cli/run/adapters/claude.test.ts +205 -260
  313. package/src/cli/run/adapters/claude.ts +151 -162
  314. package/src/cli/run/adapters/codex.test.ts +120 -100
  315. package/src/cli/run/adapters/codex.ts +115 -91
  316. package/src/cli/run/adapters/copilot.test.ts +135 -306
  317. package/src/cli/run/adapters/copilot.ts +105 -274
  318. package/src/cli/run/adapters/cursor.test.ts +111 -220
  319. package/src/cli/run/adapters/cursor.ts +105 -156
  320. package/src/cli/run/adapters/index.test.ts +148 -0
  321. package/src/cli/run/adapters/index.ts +168 -20
  322. package/src/cli/run/adapters/opencode.test.ts +106 -227
  323. package/src/cli/run/adapters/opencode.ts +139 -151
  324. package/src/cli/run/adapters/permission-modes.test.ts +63 -41
  325. package/src/cli/run/adapters/permission-modes.ts +118 -37
  326. package/src/cli/run/adapters/stub-cli.test-helper.ts +88 -0
  327. package/src/cli/run/platform.test.ts +128 -0
  328. package/src/cli/run/platform.ts +213 -0
  329. package/src/cli/run/schema.test.ts +62 -344
  330. package/src/cli/run/schema.ts +48 -78
  331. package/src/cli/run.test.ts +351 -0
  332. package/src/cli/run.ts +366 -1151
  333. package/src/cli/team-config.ts +2 -21
  334. package/src/cli/tiers.test.ts +4 -17
  335. package/src/orchestrator/agents/team-lead.agent.md +1 -1
  336. package/src/orchestrator/prompts/assess-complexity.prompt.md +43 -26
  337. package/src/orchestrator/prompts/brainstorm.prompt.md +1 -1
  338. package/src/orchestrator/prompts/bug-fix.prompt.md +2 -2
  339. package/src/orchestrator/prompts/fix-convoy.prompt.md +43 -29
  340. package/src/orchestrator/prompts/fix-prd.prompt.md +26 -22
  341. package/src/orchestrator/prompts/generate-convoy.prompt.md +139 -147
  342. package/src/orchestrator/prompts/generate-prd.prompt.md +75 -68
  343. package/src/orchestrator/prompts/implement-feature.prompt.md +2 -2
  344. package/src/orchestrator/prompts/validate-convoy.prompt.md +29 -28
  345. package/src/orchestrator/prompts/validate-prd.prompt.md +28 -21
  346. package/src/orchestrator/skills/agent-hooks/HOOKS-REFERENCE.md +3 -3
  347. package/src/orchestrator/skills/agent-hooks/SKILL.md +1 -1
  348. package/src/orchestrator/skills/fast-review/SKILL.md +3 -1
  349. package/src/orchestrator/skills/orchestration-protocols/SKILL.md +7 -8
  350. package/dist/cli/convoy/dag-analysis.d.ts +0 -39
  351. package/dist/cli/convoy/dag-analysis.d.ts.map +0 -1
  352. package/dist/cli/convoy/dag-analysis.js +0 -279
  353. package/dist/cli/convoy/dag-analysis.js.map +0 -1
  354. package/dist/cli/convoy/dag-analysis.test.d.ts +0 -2
  355. package/dist/cli/convoy/dag-analysis.test.d.ts.map +0 -1
  356. package/dist/cli/convoy/dag-analysis.test.js +0 -289
  357. package/dist/cli/convoy/dag-analysis.test.js.map +0 -1
  358. package/dist/cli/convoy/formula.d.ts +0 -19
  359. package/dist/cli/convoy/formula.d.ts.map +0 -1
  360. package/dist/cli/convoy/formula.js +0 -142
  361. package/dist/cli/convoy/formula.js.map +0 -1
  362. package/dist/cli/convoy/formula.test.d.ts +0 -2
  363. package/dist/cli/convoy/formula.test.d.ts.map +0 -1
  364. package/dist/cli/convoy/formula.test.js +0 -342
  365. package/dist/cli/convoy/formula.test.js.map +0 -1
  366. package/dist/cli/convoy/health.d.ts +0 -34
  367. package/dist/cli/convoy/health.d.ts.map +0 -1
  368. package/dist/cli/convoy/health.js +0 -123
  369. package/dist/cli/convoy/health.js.map +0 -1
  370. package/dist/cli/convoy/health.test.d.ts +0 -2
  371. package/dist/cli/convoy/health.test.d.ts.map +0 -1
  372. package/dist/cli/convoy/health.test.js +0 -448
  373. package/dist/cli/convoy/health.test.js.map +0 -1
  374. package/dist/cli/convoy/last-run.d.ts +0 -53
  375. package/dist/cli/convoy/last-run.d.ts.map +0 -1
  376. package/dist/cli/convoy/last-run.js +0 -54
  377. package/dist/cli/convoy/last-run.js.map +0 -1
  378. package/dist/cli/convoy/last-run.test.d.ts +0 -2
  379. package/dist/cli/convoy/last-run.test.d.ts.map +0 -1
  380. package/dist/cli/convoy/last-run.test.js +0 -110
  381. package/dist/cli/convoy/last-run.test.js.map +0 -1
  382. package/dist/cli/convoy/pipeline.d.ts +0 -41
  383. package/dist/cli/convoy/pipeline.d.ts.map +0 -1
  384. package/dist/cli/convoy/pipeline.js +0 -414
  385. package/dist/cli/convoy/pipeline.js.map +0 -1
  386. package/dist/cli/convoy/pipeline.test.d.ts +0 -2
  387. package/dist/cli/convoy/pipeline.test.d.ts.map +0 -1
  388. package/dist/cli/convoy/pipeline.test.js +0 -837
  389. package/dist/cli/convoy/pipeline.test.js.map +0 -1
  390. package/dist/cli/convoy/review-stages.d.ts +0 -9
  391. package/dist/cli/convoy/review-stages.d.ts.map +0 -1
  392. package/dist/cli/convoy/review-stages.js +0 -134
  393. package/dist/cli/convoy/review-stages.js.map +0 -1
  394. package/dist/cli/convoy/review-stages.test.d.ts +0 -2
  395. package/dist/cli/convoy/review-stages.test.d.ts.map +0 -1
  396. package/dist/cli/convoy/review-stages.test.js +0 -197
  397. package/dist/cli/convoy/review-stages.test.js.map +0 -1
  398. package/dist/cli/run/executor.d.ts +0 -15
  399. package/dist/cli/run/executor.d.ts.map +0 -1
  400. package/dist/cli/run/executor.js +0 -249
  401. package/dist/cli/run/executor.js.map +0 -1
  402. package/dist/cli/run/executor.test.d.ts +0 -2
  403. package/dist/cli/run/executor.test.d.ts.map +0 -1
  404. package/dist/cli/run/executor.test.js +0 -297
  405. package/dist/cli/run/executor.test.js.map +0 -1
  406. package/dist/cli/run/reporter.d.ts +0 -10
  407. package/dist/cli/run/reporter.d.ts.map +0 -1
  408. package/dist/cli/run/reporter.js +0 -142
  409. package/dist/cli/run/reporter.js.map +0 -1
  410. package/dist/cli/run-dry-run.test.d.ts +0 -2
  411. package/dist/cli/run-dry-run.test.d.ts.map +0 -1
  412. package/dist/cli/run-dry-run.test.js +0 -83
  413. package/dist/cli/run-dry-run.test.js.map +0 -1
  414. package/dist/cli/run-executor-flags.test.d.ts +0 -2
  415. package/dist/cli/run-executor-flags.test.d.ts.map +0 -1
  416. package/dist/cli/run-executor-flags.test.js +0 -31
  417. package/dist/cli/run-executor-flags.test.js.map +0 -1
  418. package/dist/cli/run-finish.test.d.ts +0 -2
  419. package/dist/cli/run-finish.test.d.ts.map +0 -1
  420. package/dist/cli/run-finish.test.js +0 -77
  421. package/dist/cli/run-finish.test.js.map +0 -1
  422. package/dist/cli/watch.d.ts +0 -15
  423. package/dist/cli/watch.d.ts.map +0 -1
  424. package/dist/cli/watch.js +0 -277
  425. package/dist/cli/watch.js.map +0 -1
  426. package/dist/dashboard/scripts/etl.d.ts +0 -10
  427. package/dist/dashboard/scripts/etl.d.ts.map +0 -1
  428. package/dist/dashboard/scripts/etl.js +0 -141
  429. package/dist/dashboard/scripts/etl.js.map +0 -1
  430. package/src/cli/convoy/dag-analysis.test.ts +0 -349
  431. package/src/cli/convoy/dag-analysis.ts +0 -367
  432. package/src/cli/convoy/formula.test.ts +0 -404
  433. package/src/cli/convoy/formula.ts +0 -174
  434. package/src/cli/convoy/health.test.ts +0 -519
  435. package/src/cli/convoy/health.ts +0 -189
  436. package/src/cli/convoy/last-run.test.ts +0 -130
  437. package/src/cli/convoy/last-run.ts +0 -87
  438. package/src/cli/convoy/pipeline.test.ts +0 -999
  439. package/src/cli/convoy/pipeline.ts +0 -492
  440. package/src/cli/convoy/review-stages.test.ts +0 -235
  441. package/src/cli/convoy/review-stages.ts +0 -166
  442. package/src/cli/run/executor.test.ts +0 -338
  443. package/src/cli/run/executor.ts +0 -292
  444. package/src/cli/run/reporter.ts +0 -160
  445. package/src/cli/run-dry-run.test.ts +0 -97
  446. package/src/cli/run-executor-flags.test.ts +0 -38
  447. package/src/cli/run-finish.test.ts +0 -91
  448. package/src/cli/watch.ts +0 -295
  449. package/src/dashboard/astro.config.mjs +0 -6
  450. package/src/dashboard/dist/_astro/index.CADNhRPS.css +0 -1
  451. package/src/dashboard/dist/data/.gitkeep +0 -0
  452. package/src/dashboard/dist/data/convoy-list.json +0 -1
  453. package/src/dashboard/dist/data/overall-stats.json +0 -29
  454. package/src/dashboard/dist/index.html +0 -1963
  455. package/src/dashboard/node_modules/.vite/deps/_metadata.json +0 -31
  456. package/src/dashboard/node_modules/.vite/deps/astro___aria-query.js +0 -6776
  457. package/src/dashboard/node_modules/.vite/deps/astro___aria-query.js.map +0 -7
  458. package/src/dashboard/node_modules/.vite/deps/astro___axobject-query.js +0 -3754
  459. package/src/dashboard/node_modules/.vite/deps/astro___axobject-query.js.map +0 -7
  460. package/src/dashboard/node_modules/.vite/deps/astro___cssesc.js +0 -99
  461. package/src/dashboard/node_modules/.vite/deps/astro___cssesc.js.map +0 -7
  462. package/src/dashboard/node_modules/.vite/deps/chunk-BUSYA2B4.js +0 -8
  463. package/src/dashboard/node_modules/.vite/deps/chunk-BUSYA2B4.js.map +0 -7
  464. package/src/dashboard/node_modules/.vite/deps/package.json +0 -3
  465. package/src/dashboard/package-lock.json +0 -6
  466. package/src/dashboard/public/data/.gitkeep +0 -0
  467. package/src/dashboard/public/data/convoy-list.json +0 -1
  468. package/src/dashboard/public/data/overall-stats.json +0 -29
  469. package/src/dashboard/public/icon-192.png +0 -0
  470. package/src/dashboard/scripts/etl.test.ts +0 -166
  471. package/src/dashboard/scripts/etl.ts +0 -170
  472. package/src/dashboard/scripts/generate-demo-db.test.ts +0 -30
  473. package/src/dashboard/scripts/generate-demo-db.ts +0 -529
  474. package/src/dashboard/scripts/integration-test.ts +0 -504
  475. package/src/dashboard/scripts/verify-demo-data.sh +0 -51
  476. package/src/dashboard/seed-data/delegations.ndjson +0 -35
  477. package/src/dashboard/seed-data/events.ndjson +0 -104
  478. package/src/dashboard/seed-data/panels.ndjson +0 -13
  479. package/src/dashboard/seed-data/reviews.ndjson +0 -6
  480. package/src/dashboard/seed-data/sessions.ndjson +0 -50
  481. package/src/dashboard/src/env.d.ts +0 -1
  482. package/src/dashboard/src/layouts/Layout.astro +0 -25
  483. package/src/dashboard/src/pages/index.astro +0 -2313
  484. package/src/dashboard/src/styles/dashboard.css +0 -2943
  485. package/src/dashboard/tsconfig.json +0 -6
  486. /package/src/{dashboard/dist → cli/dashboard}/icon-192.png +0 -0
@@ -1,27 +1,197 @@
1
1
  import { execFile as execFileCb } from 'node:child_process'
2
- import { mkdir } from 'node:fs/promises'
3
- import { realpathSync } from 'node:fs'
4
- import { join, basename, resolve, sep } from 'node:path'
2
+ import { existsSync, mkdirSync, realpathSync } from 'node:fs'
3
+ import { join, basename, dirname, resolve, sep } from 'node:path'
5
4
  import { promisify } from 'node:util'
6
5
 
7
6
  const execFile = promisify(execFileCb)
8
7
 
8
+ /**
9
+ * Git worktrees for a convoy.
10
+ *
11
+ * Every worktree — the convoy's own integration checkout and each task's —
12
+ * lives directly under `<repo>/.opencastle/worktrees/`, created from the main
13
+ * repository with a short name. They used to nest (a task's worktree inside the
14
+ * convoy's, each named with a 13-digit timestamp), which put ~100 characters in
15
+ * front of every path in the repo and broke Windows' 260-character limit.
16
+ * Staying inside the repository keeps npm's walk up to the project's
17
+ * node_modules working for gates run in a worktree.
18
+ */
19
+
9
20
  export interface WorktreeInfo {
10
21
  path: string
11
22
  branch: string
12
23
  head: string
24
+ /** git marks a worktree whose directory has gone as prunable. */
25
+ prunable?: boolean
26
+ }
27
+
28
+ /** What a task changed since its worktree was created. */
29
+ export interface WorktreeChanges {
30
+ files: string[]
31
+ diff: string
13
32
  }
14
33
 
15
34
  export interface WorktreeManager {
35
+ /** Create a worktree on a new branch `convoy-<workerId>` starting at `featureBranch`. */
16
36
  create(workerId: string, featureBranch: string): Promise<string>
17
- remove(worktreePath: string): Promise<void>
37
+ /** Remove a worktree; its branch goes too unless `keepBranch` — kept when its work could not be merged. */
38
+ remove(worktreePath: string, opts?: { keepBranch?: boolean }): Promise<void>
18
39
  list(): Promise<WorktreeInfo[]>
19
- removeAll(): Promise<void>
40
+ /** Remove every managed worktree except the paths in `except`. */
41
+ removeAll(opts?: { except?: string[] }): Promise<void>
42
+ /**
43
+ * Commit everything in a worktree. Returns true when a commit was made.
44
+ * Optional so a test double can leave git out entirely.
45
+ */
46
+ commitAll?(worktreePath: string, message: string): Promise<boolean>
47
+ /** The commit a worktree's HEAD points at. */
48
+ head?(worktreePath: string): Promise<string | null>
49
+ /** Files and diff between `sinceRef` and the worktree's HEAD. */
50
+ changes?(worktreePath: string, sinceRef: string): Promise<WorktreeChanges | null>
51
+ }
52
+
53
+ /** The branch name a worker's worktree is created on. */
54
+ export function workerBranchName(workerId: string): string {
55
+ return `convoy-${workerId}`
56
+ }
57
+
58
+ /** Absolute path of the directory every managed worktree lives in. */
59
+ export function worktreesDirFor(repoRoot: string): string {
60
+ return join(resolve(repoRoot), '.opencastle', 'worktrees')
61
+ }
62
+
63
+ function realOrResolved(p: string): string {
64
+ try {
65
+ return realpathSync(p)
66
+ } catch {
67
+ return resolve(p)
68
+ }
69
+ }
70
+
71
+ /** True when `child` is inside `parent`, on either path separator. */
72
+ export function isInside(parent: string, child: string): boolean {
73
+ const p = realOrResolved(parent)
74
+ const c = realOrResolved(child)
75
+ return c.startsWith(p + sep) || c.startsWith(p + '/')
76
+ }
77
+
78
+ // ── git, with an identity when the user has none ────────────────────────────
79
+
80
+ let identityKnown: boolean | null = null
81
+
82
+ /**
83
+ * Run git. A commit or merge on a machine with no `user.email` (a CI box, a
84
+ * fresh container) used to fail the task outright; the convoy signs as itself
85
+ * there, and only there.
86
+ */
87
+ /**
88
+ * git refuses a command, before doing anything, when another git process holds
89
+ * a lock it needs — the index, a ref, packed-refs. Tasks create and remove
90
+ * worktrees and branches in one repository at the same moment, so a refusal is
91
+ * contention, not a fault, and a moment later the command goes through.
92
+ */
93
+ const LOCK_CONTENTION = /\.lock'?: File exists|Unable to create '[^']*\.lock'|cannot lock ref|could not lock config file|failed to read \S*worktrees\/\S*\/(commondir|gitdir)/i
94
+
95
+ /**
96
+ * One worktree command at a time per repository.
97
+ *
98
+ * `git worktree add` reads every other worktree's entry under .git/worktrees/,
99
+ * and one being written by a concurrent add is half there: with eight tasks
100
+ * starting together, two failed "Could not create a worktree: fatal: failed to
101
+ * read .git/worktrees/<other>/commondir". Adding, removing and listing
102
+ * worktrees, and deleting branches, now queue per repository. Each takes
103
+ * milliseconds; the agents still run side by side.
104
+ */
105
+ const repoQueues = new Map<string, Promise<unknown>>()
106
+
107
+ function changesWorktrees(args: string[]): boolean {
108
+ return args[0] === 'worktree' || (args[0] === 'branch' && (args.includes('-D') || args.includes('-d')))
109
+ }
110
+
111
+ export async function git(args: string[], cwd: string): Promise<string> {
112
+ if (!changesWorktrees(args)) return runGit(args, cwd)
113
+ const key = realOrResolved(cwd)
114
+ const prev = repoQueues.get(key) ?? Promise.resolve()
115
+ const next = prev.then(() => runGit(args, cwd), () => runGit(args, cwd))
116
+ repoQueues.set(key, next.catch(() => undefined))
117
+ return next
118
+ }
119
+
120
+ async function runGit(args: string[], cwd: string): Promise<string> {
121
+ for (let attempt = 0; ; attempt++) {
122
+ try {
123
+ const { stdout } = await execFile('git', args, { cwd, maxBuffer: 64 * 1024 * 1024 })
124
+ return stdout
125
+ } catch (err) {
126
+ const text = `${(err as { stderr?: string }).stderr ?? ''}\n${(err as Error).message}`
127
+ if (attempt >= 6 || !LOCK_CONTENTION.test(text)) throw err
128
+ await new Promise((r) => setTimeout(r, 40 * 2 ** attempt + Math.random() * 40))
129
+ }
130
+ }
131
+ }
132
+
133
+ async function gitWithIdentity(args: string[], cwd: string): Promise<string> {
134
+ if (identityKnown === null) {
135
+ try {
136
+ await execFile('git', ['var', 'GIT_AUTHOR_IDENT'], { cwd })
137
+ identityKnown = true
138
+ } catch {
139
+ identityKnown = false
140
+ }
141
+ }
142
+ const prefix = identityKnown ? [] : ['-c', 'user.name=OpenCastle convoy', '-c', 'user.email=convoy@opencastle.invalid']
143
+ return git([...prefix, ...args], cwd)
144
+ }
145
+
146
+ /**
147
+ * Stage and commit everything in `cwd`. Returns true when there was something
148
+ * to commit.
149
+ *
150
+ * `--no-verify`: this is the convoy's bookkeeping commit inside its own
151
+ * worktree, and the checks it cares about run as gates, with their output fed
152
+ * back to the agent. A project's pre-commit hook (lint-staged and the like) is
153
+ * for the commit a person makes when they merge the convoy branch.
154
+ */
155
+ export async function commitAllIn(cwd: string, message: string): Promise<boolean> {
156
+ await git(['add', '-A'], cwd)
157
+ const staged = await git(['diff', '--cached', '--name-only'], cwd)
158
+ if (!staged.trim()) return false
159
+ await gitWithIdentity(['commit', '-q', '--no-verify', '-m', message], cwd)
160
+ return true
161
+ }
162
+
163
+ /** `git merge` with the convoy's fallback identity. */
164
+ export async function mergeIn(cwd: string, args: string[]): Promise<string> {
165
+ return gitWithIdentity(['merge', ...args], cwd)
166
+ }
167
+
168
+ export function parseWorktreeList(output: string): WorktreeInfo[] {
169
+ const results: WorktreeInfo[] = []
170
+ const blocks = output.trim().split(/\n\n+/).filter(Boolean)
171
+ for (const block of blocks) {
172
+ let path = ''
173
+ let head = ''
174
+ let branch = ''
175
+ let prunable = false
176
+ for (const line of block.split('\n')) {
177
+ if (line.startsWith('worktree ')) path = line.slice('worktree '.length)
178
+ else if (line.startsWith('HEAD ')) head = line.slice('HEAD '.length)
179
+ else if (line.startsWith('branch ')) branch = line.slice('branch '.length)
180
+ else if (line.startsWith('prunable')) prunable = true
181
+ }
182
+ if (path) results.push({ path, branch, head, prunable })
183
+ }
184
+ return results
185
+ }
186
+
187
+ /** Every worktree of the repository, the main checkout first. */
188
+ export async function listAllWorktrees(repoRoot: string): Promise<WorktreeInfo[]> {
189
+ return parseWorktreeList(await git(['worktree', 'list', '--porcelain'], repoRoot))
20
190
  }
21
191
 
22
- export function createWorktreeManager(basePath: string): WorktreeManager {
23
- const resolvedBase = realpathSync(resolve(basePath))
24
- const worktreesDir = join(resolvedBase, '.opencastle', 'worktrees')
192
+ export function createWorktreeManager(repoRoot: string): WorktreeManager {
193
+ const resolvedBase = realpathSync(resolve(repoRoot))
194
+ const worktreesDir = worktreesDirFor(resolvedBase)
25
195
 
26
196
  async function create(workerId: string, featureBranch: string): Promise<string> {
27
197
  if (!/^[a-zA-Z0-9_-]+$/.test(workerId)) {
@@ -30,87 +200,167 @@ export function createWorktreeManager(basePath: string): WorktreeManager {
30
200
  )
31
201
  }
32
202
  const worktreePath = join(worktreesDir, workerId)
33
- await mkdir(worktreesDir, { recursive: true })
34
- await execFile(
35
- 'git',
36
- ['worktree', 'add', worktreePath, '-b', `convoy-${workerId}`, featureBranch],
37
- { cwd: resolvedBase },
38
- )
203
+ mkdirSync(worktreesDir, { recursive: true })
204
+ await git(['worktree', 'add', '-q', worktreePath, '-b', workerBranchName(workerId), featureBranch], resolvedBase)
39
205
  return worktreePath
40
206
  }
41
207
 
42
- async function remove(worktreePath: string): Promise<void> {
43
- let resolved: string
44
- try {
45
- resolved = realpathSync(worktreePath)
46
- } catch {
47
- resolved = resolve(worktreePath)
48
- }
49
- if (!resolved.startsWith(worktreesDir + sep)) {
208
+ async function remove(worktreePath: string, opts: { keepBranch?: boolean } = {}): Promise<void> {
209
+ const resolved = realOrResolved(worktreePath)
210
+ if (!resolved.startsWith(realOrResolved(worktreesDir) + sep)) {
50
211
  throw new Error(`Path "${worktreePath}" is outside the managed worktrees directory`)
51
212
  }
52
213
  const workerId = basename(resolved)
53
214
  try {
54
- await execFile('git', ['worktree', 'remove', resolved, '--force'], {
55
- cwd: resolvedBase,
56
- })
215
+ await git(['worktree', 'remove', resolved, '--force'], resolvedBase)
57
216
  } catch (err) {
58
217
  const stderr = (err as { stderr?: string }).stderr ?? ''
59
- if (stderr.includes('is not a working tree')) {
60
- return
61
- }
62
- throw err
218
+ if (!stderr.includes('is not a working tree')) throw err
63
219
  }
220
+ if (opts.keepBranch) return
64
221
  try {
65
- await execFile('git', ['branch', '-D', `convoy-${workerId}`], { cwd: resolvedBase })
222
+ await git(['branch', '-D', workerBranchName(workerId)], resolvedBase)
66
223
  } catch {
67
224
  // Branch may already be deleted — ignore
68
225
  }
69
226
  }
70
227
 
71
-
72
228
  async function list(): Promise<WorktreeInfo[]> {
73
- const { stdout } = await execFile('git', ['worktree', 'list', '--porcelain'], {
74
- cwd: resolvedBase,
75
- })
76
- return parseWorktreeList(stdout, worktreesDir)
229
+ const all = await listAllWorktrees(resolvedBase)
230
+ const dir = realOrResolved(worktreesDir)
231
+ return all.filter((w) => realOrResolved(w.path).startsWith(dir + sep))
77
232
  }
78
233
 
79
- async function removeAll(): Promise<void> {
80
- const worktrees = await list()
81
- for (const wt of worktrees) {
234
+ async function removeAll(opts: { except?: string[] } = {}): Promise<void> {
235
+ const keep = new Set((opts.except ?? []).map(realOrResolved))
236
+ for (const wt of await list()) {
237
+ if (keep.has(realOrResolved(wt.path))) continue
82
238
  await remove(wt.path)
83
239
  }
240
+ // A directory deleted by hand leaves its registration behind, and git then
241
+ // refuses to check its branch out anywhere else.
242
+ try { await git(['worktree', 'prune'], resolvedBase) } catch { /* nothing to prune */ }
243
+ }
244
+
245
+ async function commitAll(worktreePath: string, message: string): Promise<boolean> {
246
+ return commitAllIn(worktreePath, message)
84
247
  }
85
248
 
86
- return { create, remove, list, removeAll }
249
+ async function head(worktreePath: string): Promise<string | null> {
250
+ try {
251
+ return (await git(['rev-parse', 'HEAD'], worktreePath)).trim() || null
252
+ } catch {
253
+ return null
254
+ }
255
+ }
256
+
257
+ async function changes(worktreePath: string, sinceRef: string): Promise<WorktreeChanges | null> {
258
+ try {
259
+ const files = (await git(['diff', '--name-only', `${sinceRef}..HEAD`], worktreePath))
260
+ .split('\n').map((s) => s.trim()).filter(Boolean)
261
+ const diff = await git(['diff', `${sinceRef}..HEAD`], worktreePath)
262
+ return { files, diff }
263
+ } catch {
264
+ return null
265
+ }
266
+ }
267
+
268
+ return { create, remove, list, removeAll, commitAll, head, changes }
87
269
  }
88
270
 
89
- function parseWorktreeList(output: string, worktreesDir: string): WorktreeInfo[] {
90
- const results: WorktreeInfo[] = []
91
- const blocks = output.trim().split(/\n\n+/).filter(Boolean)
271
+ // ── The convoy's integration checkout ───────────────────────────────────────
92
272
 
93
- for (const block of blocks) {
94
- const lines = block.split('\n')
95
- let path = ''
96
- let head = ''
97
- let branch = ''
273
+ export class BranchInUseError extends Error {
274
+ constructor(public readonly branch: string, public readonly path: string) {
275
+ super(
276
+ `Branch "${branch}" is checked out at ${path}.\n` +
277
+ ` A convoy merges into its branch in a checkout of its own. Switch that ` +
278
+ `checkout to another branch, then run again.`,
279
+ )
280
+ this.name = 'BranchInUseError'
281
+ }
282
+ }
98
283
 
99
- for (const line of lines) {
100
- if (line.startsWith('worktree ')) {
101
- path = line.slice('worktree '.length)
102
- } else if (line.startsWith('HEAD ')) {
103
- head = line.slice('HEAD '.length)
104
- } else if (line.startsWith('branch ')) {
105
- branch = line.slice('branch '.length)
106
- }
107
- }
284
+ /**
285
+ * Check `branch` out in the convoy's integration worktree, creating the branch
286
+ * from `base` when it does not exist yet.
287
+ *
288
+ * A worktree left behind by a killed run is reused: its unfinished merge is
289
+ * aborted and it is reset to the branch tip, which holds every merge that
290
+ * completed. One whose directory has gone is pruned first. Either used to make
291
+ * `resume` fail with "'<branch>' is already used by worktree".
292
+ */
293
+ export async function ensureRootWorktree(opts: {
294
+ repoRoot: string
295
+ branch: string
296
+ base: string
297
+ dirName: string
298
+ }): Promise<string> {
299
+ const repoRoot = realOrResolved(opts.repoRoot)
300
+ const worktreesDir = worktreesDirFor(repoRoot)
301
+ const target = join(worktreesDir, opts.dirName)
302
+ const ref = `refs/heads/${opts.branch}`
108
303
 
109
- // Only include worktrees that live under .opencastle/worktrees/
110
- if (path.startsWith(worktreesDir + sep)) {
111
- results.push({ path, branch, head })
112
- }
304
+ let worktrees = await listAllWorktrees(repoRoot)
305
+ if (worktrees.some((w) => w.branch === ref && (w.prunable || !existsSync(w.path)))) {
306
+ await git(['worktree', 'prune'], repoRoot)
307
+ worktrees = await listAllWorktrees(repoRoot)
113
308
  }
114
309
 
115
- return results
310
+ const holder = worktrees.find((w) => w.branch === ref)
311
+ if (holder) {
312
+ if (!isInside(worktreesDir, holder.path)) throw new BranchInUseError(opts.branch, holder.path)
313
+ try { await git(['merge', '--abort'], holder.path) } catch { /* no merge in progress */ }
314
+ await git(['reset', '-q', '--hard', 'HEAD'], holder.path)
315
+ await git(['clean', '-q', '-fd'], holder.path)
316
+ return holder.path
317
+ }
318
+
319
+ mkdirSync(dirname(target), { recursive: true })
320
+ let exists = true
321
+ try {
322
+ await git(['rev-parse', '--verify', '--quiet', ref], repoRoot)
323
+ } catch {
324
+ exists = false
325
+ }
326
+ if (exists) {
327
+ await git(['worktree', 'add', '-q', target, opts.branch], repoRoot)
328
+ } else {
329
+ await git(['worktree', 'add', '-q', '-b', opts.branch, target, opts.base], repoRoot)
330
+ }
331
+ return target
332
+ }
333
+
334
+ /** Remove the integration worktree. The branch stays: it is the result. */
335
+ export async function removeRootWorktree(repoRoot: string, path: string): Promise<void> {
336
+ try {
337
+ await git(['worktree', 'remove', '--force', path], realOrResolved(repoRoot))
338
+ } catch {
339
+ try { await git(['worktree', 'prune'], realOrResolved(repoRoot)) } catch { /* ignore */ }
340
+ }
341
+ }
342
+
343
+ /**
344
+ * The repository's main checkout — where `.opencastle/` belongs — even when
345
+ * `cwd` is a worktree. Logs written inside a worktree vanished with it.
346
+ */
347
+ export async function mainRepoRoot(cwd: string): Promise<string | null> {
348
+ try {
349
+ const top = (await git(['rev-parse', '--show-toplevel'], cwd)).trim()
350
+ const list = await listAllWorktrees(top)
351
+ return list[0]?.path ?? top
352
+ } catch {
353
+ return null
354
+ }
355
+ }
356
+
357
+ /** The branch checked out at `cwd`, or its commit when HEAD is detached. */
358
+ export async function currentRef(cwd: string): Promise<string | null> {
359
+ try {
360
+ const name = (await git(['rev-parse', '--abbrev-ref', 'HEAD'], cwd)).trim()
361
+ if (name && name !== 'HEAD') return name
362
+ return (await git(['rev-parse', 'HEAD'], cwd)).trim() || null
363
+ } catch {
364
+ return null
365
+ }
116
366
  }
@@ -60,12 +60,12 @@ describe('positionalWords', () => {
60
60
  })
61
61
 
62
62
  it('treats a value that looks like a word as a value, not a task word', () => {
63
- expect(positionalWords(['--permission-mode', 'plan', 'do', 'work'])).toEqual(['do', 'work'])
63
+ expect(positionalWords(['--concurrency', '3', 'do', 'work'])).toEqual(['do', 'work'])
64
64
  })
65
65
  })
66
66
 
67
67
  describe('the task the planner is given', () => {
68
- /** What the dispatcher passes to `pipeline` as `--text`. */
68
+ /** What the dispatcher hands the planner as the task. */
69
69
  const taskText = (args: string[]): string => positionalWords(args).join(' ')
70
70
 
71
71
  it('reassembles an unquoted request in order', () => {
@@ -86,30 +86,6 @@ describe('the task the planner is given', () => {
86
86
  })
87
87
  })
88
88
 
89
- describe('status words stay a status query', () => {
90
- /** The dispatcher's rule: a status word alone, with no other words after it. */
91
- const STATUS_WORDS = ['status', 'state', 'info', 'ls', 'list']
92
- const isStatusQuery = (args: string[]): boolean => {
93
- const words = positionalWords(args)
94
- return words.length === 1 && STATUS_WORDS.includes(words[0])
95
- }
96
-
97
- it('treats a bare status word as a status query', () => {
98
- for (const w of STATUS_WORDS) expect(isStatusQuery([w])).toBe(true)
99
- })
100
-
101
- it('still does so when flags accompany it', () => {
102
- expect(isStatusQuery(['status', '--json'])).toBe(true)
103
- })
104
-
105
- it('treats a status word that opens a sentence as a task', () => {
106
- // "status" alone means "where do things stand"; "status page for the admin"
107
- // is a feature, and planning it must not be hijacked.
108
- expect(isStatusQuery(['status', 'page', 'for', 'the', 'admin'])).toBe(false)
109
- expect(isStatusQuery(['list', 'all', 'users', 'in', 'the', 'dashboard'])).toBe(false)
110
- })
111
- })
112
-
113
89
  describe('splitTaskFlags', () => {
114
90
  it('forwards a flag the planner reads, with its value', () => {
115
91
  // The defect: --adapter was dropped, and the run used the auto-detected
@@ -138,15 +114,19 @@ describe('splitTaskFlags', () => {
138
114
  expect(splitTaskFlags(['add', 'caching', '--adaptr', 'codex']).unknown).toEqual(['--adaptr'])
139
115
  })
140
116
 
141
- it('does not mistake an unknown flag value for another unknown flag', () => {
142
- expect(splitTaskFlags(['x', '--report-dir', 'out']).unknown).toEqual(['--report-dir'])
117
+ it('reports a removed flag rather than forwarding it', () => {
118
+ expect(splitTaskFlags(['x', '--skip-validation']).unknown).toEqual(['--skip-validation'])
119
+ })
120
+
121
+ it('does not mistake a flag value for another unknown flag', () => {
122
+ expect(splitTaskFlags(['x', '--prd', 'out', '--nope']).unknown).toEqual(['--prd', '--nope'])
143
123
  })
144
124
 
145
125
  it('forwards several flags at once, keeping order', () => {
146
126
  const { forward, unknown } = splitTaskFlags([
147
- 'build', 'it', '--verbose', '--adapter', 'codex', '--skip-validation',
127
+ 'build', 'it', '--verbose', '--adapter', 'codex', '--yes', '-c', '2',
148
128
  ])
149
- expect(forward).toEqual(['--verbose', '--adapter', 'codex', '--skip-validation'])
129
+ expect(forward).toEqual(['--verbose', '--adapter', 'codex', '--yes', '-c', '2'])
150
130
  expect(unknown).toEqual([])
151
131
  })
152
132
 
@@ -0,0 +1,163 @@
1
+ /**
2
+ * `opencastle convoy` with no task: where the last run stands, and the one
3
+ * thing to do next — read through the read model, never a store that migrates.
4
+ */
5
+ import { mkdirSync, mkdtempSync, realpathSync, rmSync, statSync } from 'node:fs'
6
+ import { hostname, tmpdir } from 'node:os'
7
+ import { join } from 'node:path'
8
+ import { DatabaseSync } from 'node:sqlite'
9
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
10
+ import convoy, { readLastRun } from './convoy-cmd.js'
11
+ import { createConvoyStore } from './convoy/store.js'
12
+
13
+ let root: string
14
+ let out: string[]
15
+ let savedNoColor: string | undefined
16
+
17
+ beforeEach(() => {
18
+ root = realpathSync(mkdtempSync(join(tmpdir(), 'oc-convoy-')))
19
+ mkdirSync(join(root, '.opencastle'))
20
+ vi.spyOn(process, 'cwd').mockReturnValue(root)
21
+ out = []
22
+ const capture = (...a: unknown[]): void => void out.push(a.join(' '))
23
+ vi.spyOn(console, 'log').mockImplementation(capture)
24
+ vi.spyOn(console, 'error').mockImplementation(capture)
25
+ vi.spyOn(process, 'exit').mockImplementation(((code?: number) => {
26
+ throw new Error(`exit ${code}`)
27
+ }) as typeof process.exit)
28
+ savedNoColor = process.env.NO_COLOR
29
+ process.env.NO_COLOR = '1'
30
+ })
31
+
32
+ afterEach(() => {
33
+ vi.restoreAllMocks()
34
+ if (savedNoColor === undefined) delete process.env.NO_COLOR
35
+ else process.env.NO_COLOR = savedNoColor
36
+ rmSync(root, { recursive: true, force: true })
37
+ })
38
+
39
+ const text = (): string => out.join('\n')
40
+ const dbPath = (): string => join(root, '.opencastle', 'convoy.db')
41
+
42
+ function seed(runs: Array<{ id: string; status: string; tasks: string[]; created: string }>): void {
43
+ const store = createConvoyStore(dbPath())
44
+ for (const run of runs) {
45
+ store.insertConvoy({ id: run.id, name: `Run ${run.id}`, spec_hash: 'h', status: 'pending', branch: `convoy/${run.id}`, created_at: run.created, spec_yaml: 'x' })
46
+ run.tasks.forEach((status, i) => {
47
+ const id = `t${i}`
48
+ store.insertTask({
49
+ id, convoy_id: run.id, phase: 0, prompt: 'p', agent: 'developer', adapter: null, model: null, timeout_ms: 1000,
50
+ status: 'pending', retries: 0, max_retries: 0, files: null, depends_on: null, gates: null,
51
+ })
52
+ if (status !== 'pending') store.updateTaskStatus(id, run.id, status as 'done')
53
+ })
54
+ store.updateConvoyStatus(run.id, run.status as 'done', {})
55
+ }
56
+ store.close()
57
+ }
58
+
59
+ function holdLock(): void {
60
+ const db = new DatabaseSync(dbPath())
61
+ db.prepare('INSERT OR REPLACE INTO engine_lock (id, pid, hostname, started_at, last_heartbeat) VALUES (1, ?, ?, ?, ?)')
62
+ .run(process.pid, hostname(), '2026-01-01T00:00:00Z', new Date().toISOString())
63
+ db.close()
64
+ }
65
+
66
+ describe('readLastRun', () => {
67
+ it('is null for a project that has never run a convoy', () => {
68
+ expect(readLastRun(root)).toBeNull()
69
+ })
70
+
71
+ it('counts every failed status as failed', () => {
72
+ seed([{ id: 'a', status: 'failed', created: '2026-10-01T00:00:00Z', tasks: ['done', 'failed', 'gate-failed', 'timed-out', 'review-blocked', 'disputed', 'hook-failed'] }])
73
+ expect(readLastRun(root)).toMatchObject({ total: 7, done: 1, failed: 6, next: 'opencastle convoy resume' })
74
+ })
75
+
76
+ it('does not call a run finished while a task was skipped, even when it says "done"', () => {
77
+ seed([{ id: 'a', status: 'done', created: '2026-10-01T00:00:00Z', tasks: ['done', 'skipped'] }])
78
+ expect(readLastRun(root)).toMatchObject({ done: 1, skipped: 1, failed: 0, next: 'opencastle convoy resume' })
79
+ })
80
+
81
+ it('treats a running task in a dead run as not done', () => {
82
+ seed([{ id: 'a', status: 'running', created: '2026-10-01T00:00:00Z', tasks: ['done', 'running'] }])
83
+ expect(readLastRun(root)).toMatchObject({ running: 1, alive: false, next: 'opencastle convoy resume' })
84
+ })
85
+
86
+ it('points at the live view while a process is working on the run', () => {
87
+ seed([{ id: 'a', status: 'running', created: new Date().toISOString(), tasks: ['running', 'pending'] }])
88
+ holdLock()
89
+ expect(readLastRun(root)).toMatchObject({ alive: true, next: 'opencastle convoy dashboard' })
90
+ })
91
+
92
+ it('offers a new run when every task is done, and names an older run with work left', () => {
93
+ seed([
94
+ { id: 'old', status: 'interrupted', created: '2026-10-01T00:00:00Z', tasks: ['pending'] },
95
+ { id: 'new', status: 'done', created: '2026-10-02T00:00:00Z', tasks: ['done', 'done'] },
96
+ ])
97
+ expect(readLastRun(root)).toMatchObject({
98
+ id: 'new', done: 2, total: 2, next: 'opencastle convoy "<task>"', older_unfinished: { id: 'old', name: 'Run old' },
99
+ })
100
+ })
101
+
102
+ it('reads without writing to the database', () => {
103
+ seed([{ id: 'a', status: 'failed', created: '2026-10-01T00:00:00Z', tasks: ['failed'] }])
104
+ const before = statSync(dbPath()).mtimeMs
105
+ readLastRun(root)
106
+ expect(statSync(dbPath()).mtimeMs).toBe(before)
107
+ })
108
+ })
109
+
110
+ describe('opencastle convoy (status)', () => {
111
+ it('never reports a run as finished while a task is not done', async () => {
112
+ seed([{ id: 'a', status: 'done', created: '2026-10-01T00:00:00Z', tasks: ['done', 'skipped'] }])
113
+ await convoy({ args: [], pkgRoot: root })
114
+ expect(text()).toMatch(/1\/2 done, 1 skipped/)
115
+ expect(text()).toContain('Next: opencastle convoy resume')
116
+ expect(text()).not.toMatch(/every task is done|Nothing outstanding/)
117
+ })
118
+
119
+ it('prints JSON with --json', async () => {
120
+ seed([{ id: 'a', status: 'done', created: '2026-10-01T00:00:00Z', tasks: ['done'] }])
121
+ await convoy({ args: ['--json'], pkgRoot: root })
122
+ expect(JSON.parse(text())).toMatchObject({ id: 'a', done: 1, total: 1, next: 'opencastle convoy "<task>"' })
123
+ })
124
+
125
+ it('says how to start when there are no runs', async () => {
126
+ await convoy({ args: [], pkgRoot: root })
127
+ expect(text()).toContain('No runs yet.')
128
+ })
129
+ })
130
+
131
+ describe('opencastle convoy (what it refuses before planning anything)', () => {
132
+ const refused = async (args: string[]): Promise<string> => {
133
+ await expect(convoy({ args, pkgRoot: root })).rejects.toThrow('exit 1')
134
+ return text()
135
+ }
136
+
137
+ it('reads a mistyped subcommand as a typo, not a task', async () => {
138
+ expect(await refused(['resum'])).toContain('Did you mean opencastle convoy resume?')
139
+ })
140
+
141
+ it('does not plan a one-word task such as "status"', async () => {
142
+ const said = await refused(['status'])
143
+ expect(said).toContain('"status" is one word')
144
+ expect(said).toContain('For the last run: opencastle convoy')
145
+ })
146
+
147
+ it('names what replaced a removed flag', async () => {
148
+ expect(await refused(['--retry-failed'])).toContain('--retry-failed was removed. Use: opencastle convoy resume')
149
+ expect(await refused(['add', 'rate', 'limiting', '--status'])).toContain('--status was removed')
150
+ })
151
+
152
+ it('suggests the nearest flag a task takes', async () => {
153
+ expect(await refused(['add', 'rate', 'limiting', '--yse'])).toContain('Did you mean --yes?')
154
+ })
155
+
156
+ it('says a task flag needs a task', async () => {
157
+ expect(await refused(['--yes'])).toContain('--yes goes with a task')
158
+ })
159
+
160
+ it('sends a subcommand flag to its subcommand', async () => {
161
+ expect(await refused(['-f', 'spec.yml'])).toContain('-f belongs to `opencastle convoy run`')
162
+ })
163
+ })