opencastle 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (577) hide show
  1. package/README.md +102 -131
  2. package/bin/cli.mjs +20 -10
  3. package/dist/cli/adapters/claude-code.d.ts +5 -3
  4. package/dist/cli/adapters/claude-code.d.ts.map +1 -1
  5. package/dist/cli/adapters/claude-code.js +7 -3
  6. package/dist/cli/adapters/claude-code.js.map +1 -1
  7. package/dist/cli/adapters/single-file-base.d.ts +18 -0
  8. package/dist/cli/adapters/single-file-base.d.ts.map +1 -1
  9. package/dist/cli/adapters/single-file-base.js +29 -4
  10. package/dist/cli/adapters/single-file-base.js.map +1 -1
  11. package/dist/cli/agent-plugin.test.js +12 -0
  12. package/dist/cli/agent-plugin.test.js.map +1 -1
  13. package/dist/cli/agent-roster.test.js +0 -48
  14. package/dist/cli/agent-roster.test.js.map +1 -1
  15. package/dist/cli/bootstrap.d.ts.map +1 -1
  16. package/dist/cli/bootstrap.js +20 -0
  17. package/dist/cli/bootstrap.js.map +1 -1
  18. package/dist/cli/boundary.test.js +9 -7
  19. package/dist/cli/boundary.test.js.map +1 -1
  20. package/dist/cli/ci.d.ts.map +1 -1
  21. package/dist/cli/ci.js +6 -4
  22. package/dist/cli/ci.js.map +1 -1
  23. package/dist/cli/command-namespace.test.js +33 -0
  24. package/dist/cli/command-namespace.test.js.map +1 -1
  25. package/dist/cli/convoy/artifacts.d.ts +9 -2
  26. package/dist/cli/convoy/artifacts.d.ts.map +1 -1
  27. package/dist/cli/convoy/artifacts.js +13 -10
  28. package/dist/cli/convoy/artifacts.js.map +1 -1
  29. package/dist/cli/convoy/artifacts.test.js +4 -2
  30. package/dist/cli/convoy/artifacts.test.js.map +1 -1
  31. package/dist/cli/convoy/engine.d.ts +53 -23
  32. package/dist/cli/convoy/engine.d.ts.map +1 -1
  33. package/dist/cli/convoy/engine.git.test.d.ts +2 -0
  34. package/dist/cli/convoy/engine.git.test.d.ts.map +1 -0
  35. package/dist/cli/convoy/engine.git.test.js +435 -0
  36. package/dist/cli/convoy/engine.git.test.js.map +1 -0
  37. package/dist/cli/convoy/engine.js +1746 -2305
  38. package/dist/cli/convoy/engine.js.map +1 -1
  39. package/dist/cli/convoy/engine.test.js +698 -678
  40. package/dist/cli/convoy/engine.test.js.map +1 -1
  41. package/dist/cli/convoy/event-schemas.d.ts +2 -0
  42. package/dist/cli/convoy/event-schemas.d.ts.map +1 -1
  43. package/dist/cli/convoy/event-schemas.js +59 -57
  44. package/dist/cli/convoy/event-schemas.js.map +1 -1
  45. package/dist/cli/convoy/events.d.ts +4 -1
  46. package/dist/cli/convoy/events.d.ts.map +1 -1
  47. package/dist/cli/convoy/events.js +69 -84
  48. package/dist/cli/convoy/events.js.map +1 -1
  49. package/dist/cli/convoy/events.test.js +50 -9
  50. package/dist/cli/convoy/events.test.js.map +1 -1
  51. package/dist/cli/convoy/gates.d.ts +9 -4
  52. package/dist/cli/convoy/gates.d.ts.map +1 -1
  53. package/dist/cli/convoy/gates.js +29 -14
  54. package/dist/cli/convoy/gates.js.map +1 -1
  55. package/dist/cli/convoy/isolation.d.ts +32 -6
  56. package/dist/cli/convoy/isolation.d.ts.map +1 -1
  57. package/dist/cli/convoy/isolation.js +72 -34
  58. package/dist/cli/convoy/isolation.js.map +1 -1
  59. package/dist/cli/convoy/isolation.test.js +66 -42
  60. package/dist/cli/convoy/isolation.test.js.map +1 -1
  61. package/dist/cli/convoy/lock.d.ts.map +1 -1
  62. package/dist/cli/convoy/lock.js +25 -10
  63. package/dist/cli/convoy/lock.js.map +1 -1
  64. package/dist/cli/convoy/lock.test.js +12 -0
  65. package/dist/cli/convoy/lock.test.js.map +1 -1
  66. package/dist/cli/convoy/merge.d.ts +21 -4
  67. package/dist/cli/convoy/merge.d.ts.map +1 -1
  68. package/dist/cli/convoy/merge.js +69 -53
  69. package/dist/cli/convoy/merge.js.map +1 -1
  70. package/dist/cli/convoy/merge.test.js +23 -1
  71. package/dist/cli/convoy/merge.test.js.map +1 -1
  72. package/dist/cli/convoy/progress.d.ts +35 -0
  73. package/dist/cli/convoy/progress.d.ts.map +1 -0
  74. package/dist/cli/convoy/progress.js +103 -0
  75. package/dist/cli/convoy/progress.js.map +1 -0
  76. package/dist/cli/convoy/progress.test.d.ts +2 -0
  77. package/dist/cli/convoy/progress.test.d.ts.map +1 -0
  78. package/dist/cli/convoy/progress.test.js +53 -0
  79. package/dist/cli/convoy/progress.test.js.map +1 -0
  80. package/dist/cli/convoy/read-model.d.ts +468 -0
  81. package/dist/cli/convoy/read-model.d.ts.map +1 -0
  82. package/dist/cli/convoy/read-model.js +1132 -0
  83. package/dist/cli/convoy/read-model.js.map +1 -0
  84. package/dist/cli/convoy/read-model.test.d.ts +2 -0
  85. package/dist/cli/convoy/read-model.test.d.ts.map +1 -0
  86. package/dist/cli/convoy/read-model.test.js +609 -0
  87. package/dist/cli/convoy/read-model.test.js.map +1 -0
  88. package/dist/cli/convoy/redact.d.ts +34 -0
  89. package/dist/cli/convoy/redact.d.ts.map +1 -0
  90. package/dist/cli/convoy/redact.js +66 -0
  91. package/dist/cli/convoy/redact.js.map +1 -0
  92. package/dist/cli/convoy/redact.test.d.ts +2 -0
  93. package/dist/cli/convoy/redact.test.d.ts.map +1 -0
  94. package/dist/cli/convoy/redact.test.js +43 -0
  95. package/dist/cli/convoy/redact.test.js.map +1 -0
  96. package/dist/cli/convoy/reviewer.d.ts +65 -0
  97. package/dist/cli/convoy/reviewer.d.ts.map +1 -0
  98. package/dist/cli/convoy/reviewer.js +141 -0
  99. package/dist/cli/convoy/reviewer.js.map +1 -0
  100. package/dist/cli/convoy/reviewer.test.d.ts +2 -0
  101. package/dist/cli/convoy/reviewer.test.d.ts.map +1 -0
  102. package/dist/cli/convoy/reviewer.test.js +96 -0
  103. package/dist/cli/convoy/reviewer.test.js.map +1 -0
  104. package/dist/cli/convoy/schedule.d.ts +30 -0
  105. package/dist/cli/convoy/schedule.d.ts.map +1 -0
  106. package/dist/cli/convoy/schedule.js +111 -0
  107. package/dist/cli/convoy/schedule.js.map +1 -0
  108. package/dist/cli/convoy/schedule.test.d.ts +2 -0
  109. package/dist/cli/convoy/schedule.test.d.ts.map +1 -0
  110. package/dist/cli/convoy/schedule.test.js +45 -0
  111. package/dist/cli/convoy/schedule.test.js.map +1 -0
  112. package/dist/cli/convoy/spec-builder.d.ts +120 -30
  113. package/dist/cli/convoy/spec-builder.d.ts.map +1 -1
  114. package/dist/cli/convoy/spec-builder.js +438 -114
  115. package/dist/cli/convoy/spec-builder.js.map +1 -1
  116. package/dist/cli/convoy/spec-builder.test.js +419 -435
  117. package/dist/cli/convoy/spec-builder.test.js.map +1 -1
  118. package/dist/cli/convoy/spec-types.d.ts +46 -92
  119. package/dist/cli/convoy/spec-types.d.ts.map +1 -1
  120. package/dist/cli/convoy/store.d.ts +6 -1
  121. package/dist/cli/convoy/store.d.ts.map +1 -1
  122. package/dist/cli/convoy/store.js +111 -15
  123. package/dist/cli/convoy/store.js.map +1 -1
  124. package/dist/cli/convoy/store.test.js +59 -13
  125. package/dist/cli/convoy/store.test.js.map +1 -1
  126. package/dist/cli/convoy/types.d.ts +76 -113
  127. package/dist/cli/convoy/types.d.ts.map +1 -1
  128. package/dist/cli/convoy/types.js +6 -13
  129. package/dist/cli/convoy/types.js.map +1 -1
  130. package/dist/cli/convoy/worktree.d.ts +88 -3
  131. package/dist/cli/convoy/worktree.d.ts.map +1 -1
  132. package/dist/cli/convoy/worktree.js +282 -56
  133. package/dist/cli/convoy/worktree.js.map +1 -1
  134. package/dist/cli/convoy/worktree.test.js +132 -1
  135. package/dist/cli/convoy/worktree.test.js.map +1 -1
  136. package/dist/cli/convoy-args.test.js +9 -27
  137. package/dist/cli/convoy-args.test.js.map +1 -1
  138. package/dist/cli/convoy-cmd.d.ts +31 -6
  139. package/dist/cli/convoy-cmd.d.ts.map +1 -1
  140. package/dist/cli/convoy-cmd.js +150 -200
  141. package/dist/cli/convoy-cmd.js.map +1 -1
  142. package/dist/cli/convoy-cmd.test.d.ts +2 -0
  143. package/dist/cli/convoy-cmd.test.d.ts.map +1 -0
  144. package/dist/cli/convoy-cmd.test.js +144 -0
  145. package/dist/cli/convoy-cmd.test.js.map +1 -0
  146. package/dist/cli/dashboard.d.ts +24 -11
  147. package/dist/cli/dashboard.d.ts.map +1 -1
  148. package/dist/cli/dashboard.js +241 -303
  149. package/dist/cli/dashboard.js.map +1 -1
  150. package/dist/cli/dashboard.test.d.ts +2 -0
  151. package/dist/cli/dashboard.test.d.ts.map +1 -0
  152. package/dist/cli/dashboard.test.js +340 -0
  153. package/dist/cli/dashboard.test.js.map +1 -0
  154. package/dist/cli/dispatcher.test.js +41 -2
  155. package/dist/cli/dispatcher.test.js.map +1 -1
  156. package/dist/cli/docs-accuracy.test.js +36 -11
  157. package/dist/cli/docs-accuracy.test.js.map +1 -1
  158. package/dist/cli/doctor.d.ts.map +1 -1
  159. package/dist/cli/doctor.js +9 -6
  160. package/dist/cli/doctor.js.map +1 -1
  161. package/dist/cli/init-own-files.test.d.ts +2 -0
  162. package/dist/cli/init-own-files.test.d.ts.map +1 -0
  163. package/dist/cli/init-own-files.test.js +133 -0
  164. package/dist/cli/init-own-files.test.js.map +1 -0
  165. package/dist/cli/init.d.ts.map +1 -1
  166. package/dist/cli/init.js +106 -7
  167. package/dist/cli/init.js.map +1 -1
  168. package/dist/cli/init.test.js +5 -4
  169. package/dist/cli/init.test.js.map +1 -1
  170. package/dist/cli/layers.d.ts.map +1 -1
  171. package/dist/cli/layers.js +13 -4
  172. package/dist/cli/layers.js.map +1 -1
  173. package/dist/cli/lesson.d.ts.map +1 -1
  174. package/dist/cli/lesson.js +6 -5
  175. package/dist/cli/lesson.js.map +1 -1
  176. package/dist/cli/log.d.ts +39 -0
  177. package/dist/cli/log.d.ts.map +1 -1
  178. package/dist/cli/log.js +267 -93
  179. package/dist/cli/log.js.map +1 -1
  180. package/dist/cli/log.test.d.ts +2 -0
  181. package/dist/cli/log.test.d.ts.map +1 -0
  182. package/dist/cli/log.test.js +208 -0
  183. package/dist/cli/log.test.js.map +1 -0
  184. package/dist/cli/nearest.d.ts +18 -0
  185. package/dist/cli/nearest.d.ts.map +1 -0
  186. package/dist/cli/nearest.js +38 -0
  187. package/dist/cli/nearest.js.map +1 -0
  188. package/dist/cli/nearest.test.d.ts +2 -0
  189. package/dist/cli/nearest.test.d.ts.map +1 -0
  190. package/dist/cli/nearest.test.js +24 -0
  191. package/dist/cli/nearest.test.js.map +1 -0
  192. package/dist/cli/pipeline.d.ts +61 -0
  193. package/dist/cli/pipeline.d.ts.map +1 -1
  194. package/dist/cli/pipeline.flow.test.d.ts +2 -0
  195. package/dist/cli/pipeline.flow.test.d.ts.map +1 -0
  196. package/dist/cli/pipeline.flow.test.js +524 -0
  197. package/dist/cli/pipeline.flow.test.js.map +1 -0
  198. package/dist/cli/pipeline.js +471 -690
  199. package/dist/cli/pipeline.js.map +1 -1
  200. package/dist/cli/plan.d.ts +82 -31
  201. package/dist/cli/plan.d.ts.map +1 -1
  202. package/dist/cli/plan.js +167 -507
  203. package/dist/cli/plan.js.map +1 -1
  204. package/dist/cli/plan.test.d.ts +2 -0
  205. package/dist/cli/plan.test.d.ts.map +1 -0
  206. package/dist/cli/plan.test.js +158 -0
  207. package/dist/cli/plan.test.js.map +1 -0
  208. package/dist/cli/prompt.d.ts.map +1 -1
  209. package/dist/cli/prompt.js +9 -7
  210. package/dist/cli/prompt.js.map +1 -1
  211. package/dist/cli/prompt.test.js +20 -2
  212. package/dist/cli/prompt.test.js.map +1 -1
  213. package/dist/cli/remove.d.ts.map +1 -1
  214. package/dist/cli/remove.js +3 -1
  215. package/dist/cli/remove.js.map +1 -1
  216. package/dist/cli/review.d.ts.map +1 -1
  217. package/dist/cli/review.js +7 -1
  218. package/dist/cli/review.js.map +1 -1
  219. package/dist/cli/run/adapters/agent-process.d.ts +82 -0
  220. package/dist/cli/run/adapters/agent-process.d.ts.map +1 -0
  221. package/dist/cli/run/adapters/agent-process.js +224 -0
  222. package/dist/cli/run/adapters/agent-process.js.map +1 -0
  223. package/dist/cli/run/adapters/agent-process.test.d.ts +2 -0
  224. package/dist/cli/run/adapters/agent-process.test.d.ts.map +1 -0
  225. package/dist/cli/run/adapters/agent-process.test.js +159 -0
  226. package/dist/cli/run/adapters/agent-process.test.js.map +1 -0
  227. package/dist/cli/run/adapters/claude.d.ts +53 -2
  228. package/dist/cli/run/adapters/claude.d.ts.map +1 -1
  229. package/dist/cli/run/adapters/claude.js +147 -171
  230. package/dist/cli/run/adapters/claude.js.map +1 -1
  231. package/dist/cli/run/adapters/claude.test.js +197 -254
  232. package/dist/cli/run/adapters/claude.test.js.map +1 -1
  233. package/dist/cli/run/adapters/codex.d.ts +25 -2
  234. package/dist/cli/run/adapters/codex.d.ts.map +1 -1
  235. package/dist/cli/run/adapters/codex.js +113 -81
  236. package/dist/cli/run/adapters/codex.js.map +1 -1
  237. package/dist/cli/run/adapters/codex.test.js +116 -95
  238. package/dist/cli/run/adapters/codex.test.js.map +1 -1
  239. package/dist/cli/run/adapters/copilot.d.ts +35 -1
  240. package/dist/cli/run/adapters/copilot.d.ts.map +1 -1
  241. package/dist/cli/run/adapters/copilot.js +104 -287
  242. package/dist/cli/run/adapters/copilot.js.map +1 -1
  243. package/dist/cli/run/adapters/copilot.test.js +122 -282
  244. package/dist/cli/run/adapters/copilot.test.js.map +1 -1
  245. package/dist/cli/run/adapters/cursor.d.ts +25 -7
  246. package/dist/cli/run/adapters/cursor.d.ts.map +1 -1
  247. package/dist/cli/run/adapters/cursor.js +103 -156
  248. package/dist/cli/run/adapters/cursor.js.map +1 -1
  249. package/dist/cli/run/adapters/cursor.test.js +106 -218
  250. package/dist/cli/run/adapters/cursor.test.js.map +1 -1
  251. package/dist/cli/run/adapters/index.d.ts +34 -5
  252. package/dist/cli/run/adapters/index.d.ts.map +1 -1
  253. package/dist/cli/run/adapters/index.js +147 -21
  254. package/dist/cli/run/adapters/index.js.map +1 -1
  255. package/dist/cli/run/adapters/index.test.d.ts +2 -0
  256. package/dist/cli/run/adapters/index.test.d.ts.map +1 -0
  257. package/dist/cli/run/adapters/index.test.js +129 -0
  258. package/dist/cli/run/adapters/index.test.js.map +1 -0
  259. package/dist/cli/run/adapters/opencode.d.ts +25 -9
  260. package/dist/cli/run/adapters/opencode.d.ts.map +1 -1
  261. package/dist/cli/run/adapters/opencode.js +136 -152
  262. package/dist/cli/run/adapters/opencode.js.map +1 -1
  263. package/dist/cli/run/adapters/opencode.test.js +99 -218
  264. package/dist/cli/run/adapters/opencode.test.js.map +1 -1
  265. package/dist/cli/run/adapters/permission-modes.d.ts +47 -4
  266. package/dist/cli/run/adapters/permission-modes.d.ts.map +1 -1
  267. package/dist/cli/run/adapters/permission-modes.js +113 -37
  268. package/dist/cli/run/adapters/permission-modes.js.map +1 -1
  269. package/dist/cli/run/adapters/permission-modes.test.js +55 -40
  270. package/dist/cli/run/adapters/permission-modes.test.js.map +1 -1
  271. package/dist/cli/run/adapters/stub-cli.test-helper.d.ts +22 -0
  272. package/dist/cli/run/adapters/stub-cli.test-helper.d.ts.map +1 -0
  273. package/dist/cli/run/adapters/stub-cli.test-helper.js +73 -0
  274. package/dist/cli/run/adapters/stub-cli.test-helper.js.map +1 -0
  275. package/dist/cli/run/platform.d.ts +52 -0
  276. package/dist/cli/run/platform.d.ts.map +1 -0
  277. package/dist/cli/run/platform.js +207 -0
  278. package/dist/cli/run/platform.js.map +1 -0
  279. package/dist/cli/run/platform.test.d.ts +2 -0
  280. package/dist/cli/run/platform.test.d.ts.map +1 -0
  281. package/dist/cli/run/platform.test.js +119 -0
  282. package/dist/cli/run/platform.test.js.map +1 -0
  283. package/dist/cli/run/schema.d.ts +6 -8
  284. package/dist/cli/run/schema.d.ts.map +1 -1
  285. package/dist/cli/run/schema.js +44 -68
  286. package/dist/cli/run/schema.js.map +1 -1
  287. package/dist/cli/run/schema.test.js +59 -279
  288. package/dist/cli/run/schema.test.js.map +1 -1
  289. package/dist/cli/run.d.ts +34 -56
  290. package/dist/cli/run.d.ts.map +1 -1
  291. package/dist/cli/run.js +379 -1132
  292. package/dist/cli/run.js.map +1 -1
  293. package/dist/cli/run.test.d.ts +2 -0
  294. package/dist/cli/run.test.d.ts.map +1 -0
  295. package/dist/cli/run.test.js +318 -0
  296. package/dist/cli/run.test.js.map +1 -0
  297. package/dist/cli/sync-check.d.ts.map +1 -1
  298. package/dist/cli/sync-check.js +12 -3
  299. package/dist/cli/sync-check.js.map +1 -1
  300. package/dist/cli/sync.d.ts.map +1 -1
  301. package/dist/cli/sync.js +3 -2
  302. package/dist/cli/sync.js.map +1 -1
  303. package/dist/cli/team-config.d.ts.map +1 -1
  304. package/dist/cli/team-config.js +2 -21
  305. package/dist/cli/team-config.js.map +1 -1
  306. package/dist/cli/tiers.test.js +4 -13
  307. package/dist/cli/tiers.test.js.map +1 -1
  308. package/dist/cli/update.d.ts.map +1 -1
  309. package/dist/cli/update.js +4 -3
  310. package/dist/cli/update.js.map +1 -1
  311. package/dist/cli/website-plugins.test.js +51 -2
  312. package/dist/cli/website-plugins.test.js.map +1 -1
  313. package/dist/orchestrator/plugins/coolify/config.d.ts.map +1 -1
  314. package/dist/orchestrator/plugins/coolify/config.js +13 -0
  315. package/dist/orchestrator/plugins/coolify/config.js.map +1 -1
  316. package/dist/orchestrator/plugins/sentry/config.d.ts.map +1 -1
  317. package/dist/orchestrator/plugins/sentry/config.js +13 -0
  318. package/dist/orchestrator/plugins/sentry/config.js.map +1 -1
  319. package/package.json +3 -10
  320. package/src/cli/adapters/claude-code.ts +7 -3
  321. package/src/cli/adapters/single-file-base.ts +47 -4
  322. package/src/cli/agent-plugin.test.ts +14 -0
  323. package/src/cli/agent-roster.test.ts +0 -55
  324. package/src/cli/bootstrap.ts +23 -0
  325. package/src/cli/boundary.test.ts +9 -7
  326. package/src/cli/ci.ts +6 -4
  327. package/src/cli/command-namespace.test.ts +35 -0
  328. package/src/cli/convoy/TELEMETRY.md +138 -130
  329. package/src/cli/convoy/artifacts.test.ts +4 -2
  330. package/src/cli/convoy/artifacts.ts +13 -12
  331. package/src/cli/convoy/engine.git.test.ts +462 -0
  332. package/src/cli/convoy/engine.test.ts +817 -850
  333. package/src/cli/convoy/engine.ts +1864 -2596
  334. package/src/cli/convoy/event-schemas.ts +63 -59
  335. package/src/cli/convoy/events.test.ts +58 -9
  336. package/src/cli/convoy/events.ts +69 -91
  337. package/src/cli/convoy/gates.ts +31 -12
  338. package/src/cli/convoy/isolation.test.ts +76 -43
  339. package/src/cli/convoy/isolation.ts +100 -38
  340. package/src/cli/convoy/lock.test.ts +16 -0
  341. package/src/cli/convoy/lock.ts +25 -8
  342. package/src/cli/convoy/merge.test.ts +25 -1
  343. package/src/cli/convoy/merge.ts +74 -61
  344. package/src/cli/convoy/progress.test.ts +59 -0
  345. package/src/cli/convoy/progress.ts +121 -0
  346. package/src/cli/convoy/read-model.test.ts +685 -0
  347. package/src/cli/convoy/read-model.ts +1469 -0
  348. package/src/cli/convoy/redact.test.ts +49 -0
  349. package/src/cli/convoy/redact.ts +73 -0
  350. package/src/cli/convoy/reviewer.test.ts +112 -0
  351. package/src/cli/convoy/reviewer.ts +196 -0
  352. package/src/cli/convoy/schedule.test.ts +56 -0
  353. package/src/cli/convoy/schedule.ts +109 -0
  354. package/src/cli/convoy/spec-builder.test.ts +460 -464
  355. package/src/cli/convoy/spec-builder.ts +460 -129
  356. package/src/cli/convoy/spec-types.ts +46 -108
  357. package/src/cli/convoy/store.test.ts +64 -13
  358. package/src/cli/convoy/store.ts +143 -33
  359. package/src/cli/convoy/types.ts +59 -71
  360. package/src/cli/convoy/worktree.test.ts +140 -1
  361. package/src/cli/convoy/worktree.ts +311 -61
  362. package/src/cli/convoy-args.test.ts +10 -30
  363. package/src/cli/convoy-cmd.test.ts +163 -0
  364. package/src/cli/convoy-cmd.ts +173 -215
  365. package/src/cli/dashboard/dashboard.css +2086 -0
  366. package/src/cli/dashboard/dashboard.js +1687 -0
  367. package/src/cli/dashboard/index.html +307 -0
  368. package/src/cli/dashboard.test.ts +382 -0
  369. package/src/cli/dashboard.ts +243 -339
  370. package/src/cli/dispatcher.test.ts +43 -2
  371. package/src/cli/docs-accuracy.test.ts +37 -10
  372. package/src/cli/doctor.ts +9 -6
  373. package/src/cli/init-own-files.test.ts +156 -0
  374. package/src/cli/init.test.ts +5 -4
  375. package/src/cli/init.ts +104 -7
  376. package/src/cli/layers.ts +13 -4
  377. package/src/cli/lesson.ts +6 -5
  378. package/src/cli/log.test.ts +228 -0
  379. package/src/cli/log.ts +302 -83
  380. package/src/cli/nearest.test.ts +27 -0
  381. package/src/cli/nearest.ts +38 -0
  382. package/src/cli/pipeline.flow.test.ts +607 -0
  383. package/src/cli/pipeline.ts +544 -759
  384. package/src/cli/plan.test.ts +193 -0
  385. package/src/cli/plan.ts +209 -545
  386. package/src/cli/prompt.test.ts +21 -2
  387. package/src/cli/prompt.ts +11 -7
  388. package/src/cli/remove.ts +3 -0
  389. package/src/cli/review.ts +7 -1
  390. package/src/cli/run/adapters/agent-process.test.ts +175 -0
  391. package/src/cli/run/adapters/agent-process.ts +252 -0
  392. package/src/cli/run/adapters/claude.test.ts +205 -260
  393. package/src/cli/run/adapters/claude.ts +151 -162
  394. package/src/cli/run/adapters/codex.test.ts +120 -100
  395. package/src/cli/run/adapters/codex.ts +115 -91
  396. package/src/cli/run/adapters/copilot.test.ts +135 -306
  397. package/src/cli/run/adapters/copilot.ts +105 -274
  398. package/src/cli/run/adapters/cursor.test.ts +111 -220
  399. package/src/cli/run/adapters/cursor.ts +105 -156
  400. package/src/cli/run/adapters/index.test.ts +148 -0
  401. package/src/cli/run/adapters/index.ts +168 -20
  402. package/src/cli/run/adapters/opencode.test.ts +106 -227
  403. package/src/cli/run/adapters/opencode.ts +139 -151
  404. package/src/cli/run/adapters/permission-modes.test.ts +63 -41
  405. package/src/cli/run/adapters/permission-modes.ts +118 -37
  406. package/src/cli/run/adapters/stub-cli.test-helper.ts +88 -0
  407. package/src/cli/run/platform.test.ts +128 -0
  408. package/src/cli/run/platform.ts +213 -0
  409. package/src/cli/run/schema.test.ts +62 -344
  410. package/src/cli/run/schema.ts +48 -78
  411. package/src/cli/run.test.ts +351 -0
  412. package/src/cli/run.ts +366 -1151
  413. package/src/cli/sync-check.ts +12 -3
  414. package/src/cli/sync.ts +3 -2
  415. package/src/cli/team-config.ts +2 -21
  416. package/src/cli/tiers.test.ts +4 -17
  417. package/src/cli/update.ts +4 -3
  418. package/src/cli/website-plugins.test.ts +55 -5
  419. package/src/orchestrator/agents/team-lead.agent.md +2 -2
  420. package/src/orchestrator/customizations/README.md +58 -13
  421. package/src/orchestrator/customizations/logs/README.md +23 -18
  422. package/src/orchestrator/instructions/general.instructions.md +1 -1
  423. package/src/orchestrator/plugins/coolify/config.ts +13 -0
  424. package/src/orchestrator/plugins/sentry/config.ts +13 -0
  425. package/src/orchestrator/prompts/assess-complexity.prompt.md +43 -26
  426. package/src/orchestrator/prompts/bootstrap-customizations.prompt.md +44 -49
  427. package/src/orchestrator/prompts/brainstorm.prompt.md +2 -2
  428. package/src/orchestrator/prompts/bug-fix.prompt.md +5 -4
  429. package/src/orchestrator/prompts/create-skill.prompt.md +29 -39
  430. package/src/orchestrator/prompts/fix-convoy.prompt.md +43 -29
  431. package/src/orchestrator/prompts/fix-prd.prompt.md +26 -22
  432. package/src/orchestrator/prompts/generate-convoy.prompt.md +139 -147
  433. package/src/orchestrator/prompts/generate-prd.prompt.md +75 -68
  434. package/src/orchestrator/prompts/implement-feature.prompt.md +7 -6
  435. package/src/orchestrator/prompts/validate-convoy.prompt.md +29 -28
  436. package/src/orchestrator/prompts/validate-prd.prompt.md +28 -21
  437. package/src/orchestrator/skills/agent-hooks/HOOKS-REFERENCE.md +3 -3
  438. package/src/orchestrator/skills/agent-hooks/SKILL.md +1 -1
  439. package/src/orchestrator/skills/fast-review/SKILL.md +3 -1
  440. package/src/orchestrator/skills/orchestration-protocols/SKILL.md +7 -8
  441. package/dist/cli/convoy/dag-analysis.d.ts +0 -39
  442. package/dist/cli/convoy/dag-analysis.d.ts.map +0 -1
  443. package/dist/cli/convoy/dag-analysis.js +0 -279
  444. package/dist/cli/convoy/dag-analysis.js.map +0 -1
  445. package/dist/cli/convoy/dag-analysis.test.d.ts +0 -2
  446. package/dist/cli/convoy/dag-analysis.test.d.ts.map +0 -1
  447. package/dist/cli/convoy/dag-analysis.test.js +0 -289
  448. package/dist/cli/convoy/dag-analysis.test.js.map +0 -1
  449. package/dist/cli/convoy/formula.d.ts +0 -19
  450. package/dist/cli/convoy/formula.d.ts.map +0 -1
  451. package/dist/cli/convoy/formula.js +0 -142
  452. package/dist/cli/convoy/formula.js.map +0 -1
  453. package/dist/cli/convoy/formula.test.d.ts +0 -2
  454. package/dist/cli/convoy/formula.test.d.ts.map +0 -1
  455. package/dist/cli/convoy/formula.test.js +0 -342
  456. package/dist/cli/convoy/formula.test.js.map +0 -1
  457. package/dist/cli/convoy/health.d.ts +0 -34
  458. package/dist/cli/convoy/health.d.ts.map +0 -1
  459. package/dist/cli/convoy/health.js +0 -123
  460. package/dist/cli/convoy/health.js.map +0 -1
  461. package/dist/cli/convoy/health.test.d.ts +0 -2
  462. package/dist/cli/convoy/health.test.d.ts.map +0 -1
  463. package/dist/cli/convoy/health.test.js +0 -448
  464. package/dist/cli/convoy/health.test.js.map +0 -1
  465. package/dist/cli/convoy/last-run.d.ts +0 -53
  466. package/dist/cli/convoy/last-run.d.ts.map +0 -1
  467. package/dist/cli/convoy/last-run.js +0 -54
  468. package/dist/cli/convoy/last-run.js.map +0 -1
  469. package/dist/cli/convoy/last-run.test.d.ts +0 -2
  470. package/dist/cli/convoy/last-run.test.d.ts.map +0 -1
  471. package/dist/cli/convoy/last-run.test.js +0 -110
  472. package/dist/cli/convoy/last-run.test.js.map +0 -1
  473. package/dist/cli/convoy/pipeline.d.ts +0 -41
  474. package/dist/cli/convoy/pipeline.d.ts.map +0 -1
  475. package/dist/cli/convoy/pipeline.js +0 -414
  476. package/dist/cli/convoy/pipeline.js.map +0 -1
  477. package/dist/cli/convoy/pipeline.test.d.ts +0 -2
  478. package/dist/cli/convoy/pipeline.test.d.ts.map +0 -1
  479. package/dist/cli/convoy/pipeline.test.js +0 -837
  480. package/dist/cli/convoy/pipeline.test.js.map +0 -1
  481. package/dist/cli/convoy/review-stages.d.ts +0 -9
  482. package/dist/cli/convoy/review-stages.d.ts.map +0 -1
  483. package/dist/cli/convoy/review-stages.js +0 -134
  484. package/dist/cli/convoy/review-stages.js.map +0 -1
  485. package/dist/cli/convoy/review-stages.test.d.ts +0 -2
  486. package/dist/cli/convoy/review-stages.test.d.ts.map +0 -1
  487. package/dist/cli/convoy/review-stages.test.js +0 -197
  488. package/dist/cli/convoy/review-stages.test.js.map +0 -1
  489. package/dist/cli/run/executor.d.ts +0 -15
  490. package/dist/cli/run/executor.d.ts.map +0 -1
  491. package/dist/cli/run/executor.js +0 -249
  492. package/dist/cli/run/executor.js.map +0 -1
  493. package/dist/cli/run/executor.test.d.ts +0 -2
  494. package/dist/cli/run/executor.test.d.ts.map +0 -1
  495. package/dist/cli/run/executor.test.js +0 -297
  496. package/dist/cli/run/executor.test.js.map +0 -1
  497. package/dist/cli/run/reporter.d.ts +0 -10
  498. package/dist/cli/run/reporter.d.ts.map +0 -1
  499. package/dist/cli/run/reporter.js +0 -142
  500. package/dist/cli/run/reporter.js.map +0 -1
  501. package/dist/cli/run-dry-run.test.d.ts +0 -2
  502. package/dist/cli/run-dry-run.test.d.ts.map +0 -1
  503. package/dist/cli/run-dry-run.test.js +0 -83
  504. package/dist/cli/run-dry-run.test.js.map +0 -1
  505. package/dist/cli/run-executor-flags.test.d.ts +0 -2
  506. package/dist/cli/run-executor-flags.test.d.ts.map +0 -1
  507. package/dist/cli/run-executor-flags.test.js +0 -31
  508. package/dist/cli/run-executor-flags.test.js.map +0 -1
  509. package/dist/cli/run-finish.test.d.ts +0 -2
  510. package/dist/cli/run-finish.test.d.ts.map +0 -1
  511. package/dist/cli/run-finish.test.js +0 -77
  512. package/dist/cli/run-finish.test.js.map +0 -1
  513. package/dist/cli/watch.d.ts +0 -15
  514. package/dist/cli/watch.d.ts.map +0 -1
  515. package/dist/cli/watch.js +0 -277
  516. package/dist/cli/watch.js.map +0 -1
  517. package/dist/dashboard/scripts/etl.d.ts +0 -10
  518. package/dist/dashboard/scripts/etl.d.ts.map +0 -1
  519. package/dist/dashboard/scripts/etl.js +0 -141
  520. package/dist/dashboard/scripts/etl.js.map +0 -1
  521. package/src/cli/convoy/dag-analysis.test.ts +0 -349
  522. package/src/cli/convoy/dag-analysis.ts +0 -367
  523. package/src/cli/convoy/formula.test.ts +0 -404
  524. package/src/cli/convoy/formula.ts +0 -174
  525. package/src/cli/convoy/health.test.ts +0 -519
  526. package/src/cli/convoy/health.ts +0 -189
  527. package/src/cli/convoy/last-run.test.ts +0 -130
  528. package/src/cli/convoy/last-run.ts +0 -87
  529. package/src/cli/convoy/pipeline.test.ts +0 -999
  530. package/src/cli/convoy/pipeline.ts +0 -492
  531. package/src/cli/convoy/review-stages.test.ts +0 -235
  532. package/src/cli/convoy/review-stages.ts +0 -166
  533. package/src/cli/run/executor.test.ts +0 -338
  534. package/src/cli/run/executor.ts +0 -292
  535. package/src/cli/run/reporter.ts +0 -160
  536. package/src/cli/run-dry-run.test.ts +0 -97
  537. package/src/cli/run-executor-flags.test.ts +0 -38
  538. package/src/cli/run-finish.test.ts +0 -91
  539. package/src/cli/watch.ts +0 -295
  540. package/src/dashboard/astro.config.mjs +0 -6
  541. package/src/dashboard/dist/_astro/index.CADNhRPS.css +0 -1
  542. package/src/dashboard/dist/data/.gitkeep +0 -0
  543. package/src/dashboard/dist/data/convoy-list.json +0 -1
  544. package/src/dashboard/dist/data/overall-stats.json +0 -29
  545. package/src/dashboard/dist/index.html +0 -1963
  546. package/src/dashboard/node_modules/.vite/deps/_metadata.json +0 -31
  547. package/src/dashboard/node_modules/.vite/deps/astro___aria-query.js +0 -6776
  548. package/src/dashboard/node_modules/.vite/deps/astro___aria-query.js.map +0 -7
  549. package/src/dashboard/node_modules/.vite/deps/astro___axobject-query.js +0 -3754
  550. package/src/dashboard/node_modules/.vite/deps/astro___axobject-query.js.map +0 -7
  551. package/src/dashboard/node_modules/.vite/deps/astro___cssesc.js +0 -99
  552. package/src/dashboard/node_modules/.vite/deps/astro___cssesc.js.map +0 -7
  553. package/src/dashboard/node_modules/.vite/deps/chunk-BUSYA2B4.js +0 -8
  554. package/src/dashboard/node_modules/.vite/deps/chunk-BUSYA2B4.js.map +0 -7
  555. package/src/dashboard/node_modules/.vite/deps/package.json +0 -3
  556. package/src/dashboard/package-lock.json +0 -6
  557. package/src/dashboard/public/data/.gitkeep +0 -0
  558. package/src/dashboard/public/data/convoy-list.json +0 -1
  559. package/src/dashboard/public/data/overall-stats.json +0 -29
  560. package/src/dashboard/public/icon-192.png +0 -0
  561. package/src/dashboard/scripts/etl.test.ts +0 -166
  562. package/src/dashboard/scripts/etl.ts +0 -170
  563. package/src/dashboard/scripts/generate-demo-db.test.ts +0 -30
  564. package/src/dashboard/scripts/generate-demo-db.ts +0 -529
  565. package/src/dashboard/scripts/integration-test.ts +0 -504
  566. package/src/dashboard/scripts/verify-demo-data.sh +0 -51
  567. package/src/dashboard/seed-data/delegations.ndjson +0 -35
  568. package/src/dashboard/seed-data/events.ndjson +0 -104
  569. package/src/dashboard/seed-data/panels.ndjson +0 -13
  570. package/src/dashboard/seed-data/reviews.ndjson +0 -6
  571. package/src/dashboard/seed-data/sessions.ndjson +0 -50
  572. package/src/dashboard/src/env.d.ts +0 -1
  573. package/src/dashboard/src/layouts/Layout.astro +0 -25
  574. package/src/dashboard/src/pages/index.astro +0 -2313
  575. package/src/dashboard/src/styles/dashboard.css +0 -2943
  576. package/src/dashboard/tsconfig.json +0 -6
  577. /package/src/{dashboard/dist → cli/dashboard}/icon-192.png +0 -0
@@ -1,185 +1,174 @@
1
- import { spawn } from 'node:child_process'
2
- import { writeFileSync, unlinkSync } from 'node:fs'
3
- import { join } from 'node:path'
4
1
  import type { Task, ExecuteOptions, ExecuteResult, TokenUsage } from '../../convoy/spec-types.js'
2
+ import { commandExists } from '../platform.js'
3
+ import { runAgent, stopTask, promptOf, interruptedMessage, OUTPUT_LIMIT } from './agent-process.js'
4
+
5
+ /**
6
+ * Claude Code, run headless: `claude -p --output-format json`.
7
+ *
8
+ * The prompt goes on stdin — `claude -p` reads it from there when no prompt
9
+ * argument is given — so its size is not bounded by the command line.
10
+ * The JSON result carries the runtime's own token counts, its cost in USD and,
11
+ * in `modelUsage`, the model that did the work; all three are recorded as
12
+ * reported, never estimated.
13
+ */
5
14
 
6
- // Adapter name
7
15
  export const name = 'claude'
8
16
 
9
17
  export function supportsSessionContinuity(): boolean { return false }
10
18
 
11
- // CLI check
12
- async function cliAvailable(): Promise<boolean> {
13
- return new Promise((resolve) => {
14
- const proc = spawn('which', ['claude'], { stdio: 'pipe' })
15
- proc.on('close', (code) => resolve(code === 0))
16
- proc.on('error', () => resolve(false))
17
- })
18
- }
19
+ /**
20
+ * Claude Code's model aliases, which always name the current model of each
21
+ * family. A convoy worker is headless, so without one it runs on the account's
22
+ * default — usually the largest model — for a docs edit as much as for a
23
+ * security review.
24
+ */
25
+ export const tierModels = { premium: 'opus', standard: 'sonnet', economy: 'haiku' } as const
19
26
 
20
27
  export async function isAvailable(): Promise<boolean> {
21
- return cliAvailable()
28
+ return commandExists('claude')
22
29
  }
23
30
 
24
- // --- CLI implementation (from claude-code.ts) ---
25
- export async function executeViaCli(task: Task, options: ExecuteOptions = {}): Promise<ExecuteResult> {
26
- let prompt = `You are a ${task.agent}. ${task.prompt}`
27
- if (task.files && task.files.length > 0) {
28
- prompt += `\n\nOnly modify files under: ${task.files.join(', ')}`
31
+ export interface ParsedClaude {
32
+ text?: string
33
+ isError?: boolean
34
+ /** The `errors` of an error result. */
35
+ errors?: string[]
36
+ usage?: TokenUsage
37
+ costUsd?: number
38
+ model?: string
39
+ }
40
+
41
+ const num = (v: unknown): number | undefined => (typeof v === 'number' && Number.isFinite(v) ? v : undefined)
42
+
43
+ /** The final `result` object: the whole of stdout for `json`, the last `result` line for `stream-json`. */
44
+ function resultObject(stdout: string): Record<string, unknown> | null {
45
+ try {
46
+ const whole = JSON.parse(stdout) as unknown
47
+ if (whole && typeof whole === 'object' && !Array.isArray(whole)) return whole as Record<string, unknown>
48
+ } catch { /* not a single object */ }
49
+ const lines = stdout.split('\n')
50
+ for (let i = lines.length - 1; i >= 0; i--) {
51
+ const line = lines[i].trim()
52
+ if (!line.startsWith('{')) continue
53
+ try {
54
+ const obj = JSON.parse(line) as Record<string, unknown>
55
+ if (obj.type === 'result') return obj
56
+ } catch { /* not JSON */ }
29
57
  }
30
- // A convoy worker runs with no terminal attached, so a permission prompt is
31
- // not a question — it is a refusal it cannot answer. Without a mode the
32
- // worker tries Write, is denied, tries a heredoc, is denied, and exits 0
33
- // having written nothing. `acceptEdits` is the least authority that lets it
34
- // do the job it was given, and matches what the sibling adapters already do
35
- // (codex: `-a never -s workspace-write`, cursor: `--force`). Raise it to
36
- // `bypassPermissions` for a worker that needs a free hand, or drop it to
37
- // `default` to restore the prompt-driven behavior.
38
- const permissionMode = options.permissionMode ?? 'acceptEdits'
39
- const args = [
40
- '-p',
41
- prompt,
42
- '--output-format',
43
- 'json',
44
- '--max-turns',
45
- '50',
46
- '--permission-mode',
47
- permissionMode,
48
- ]
49
- const cwd = options?.cwd ?? process.cwd()
50
- const mcpJsonPath = join(cwd, 'mcp.json')
51
- let wroteJson = false
52
- if (options.mcpServers?.length) {
53
- const mcpJson: Record<string, Record<string, unknown>> = {}
54
- for (const server of options.mcpServers) {
55
- const entry: Record<string, unknown> = {}
56
- if (server.command) entry.command = server.command
57
- if (server.args) entry.args = server.args
58
- if (server.url) entry.url = server.url
59
- if (server.config) Object.assign(entry, server.config)
60
- mcpJson[server.name] = entry
61
- }
62
- writeFileSync(mcpJsonPath, JSON.stringify({ mcpServers: mcpJson }, null, 2), 'utf8')
63
- args.push('--mcp-config', mcpJsonPath)
64
- wroteJson = true
58
+ return null
59
+ }
60
+
61
+ function toUsage(input?: number, output?: number, cacheRead?: number, cacheWrite?: number): TokenUsage | undefined {
62
+ if (input === undefined && output === undefined) return undefined
63
+ const prompt = (input ?? 0) + (cacheRead ?? 0) + (cacheWrite ?? 0)
64
+ return {
65
+ prompt_tokens: prompt,
66
+ completion_tokens: output ?? 0,
67
+ total_tokens: prompt + (output ?? 0),
68
+ ...(cacheRead !== undefined ? { cache_read_tokens: cacheRead } : {}),
69
+ ...(cacheWrite !== undefined ? { cache_write_tokens: cacheWrite } : {}),
65
70
  }
66
- if (options.mcp_approve_all) {
67
- args.push('--approve-mcps')
71
+ }
72
+
73
+ /**
74
+ * Read what Claude Code reported.
75
+ *
76
+ * Tokens come from `modelUsage`, summed over its models, when it is there:
77
+ * Claude Code documents the top-level `usage` as the main agent loop only,
78
+ * while `total_cost_usd` also covers subagents, and the two should describe
79
+ * the same work. `usage` is the fallback. Claude Code counts input tokens
80
+ * apart from cache reads and writes; `prompt_tokens` here counts every input
81
+ * token, so the cache figures are added in and also kept apart. The model is
82
+ * the `modelUsage` entry that cost the most — a session can call a small model
83
+ * for housekeeping beside the one doing the work.
84
+ */
85
+ export function parseClaudeOutput(stdout: string): ParsedClaude {
86
+ const obj = resultObject(stdout)
87
+ if (!obj) return {}
88
+ const parsed: ParsedClaude = {}
89
+ if (typeof obj.result === 'string') parsed.text = obj.result
90
+ if (obj.is_error === true) parsed.isError = true
91
+ if (Array.isArray(obj.errors)) {
92
+ const errors = obj.errors.filter((e): e is string => typeof e === 'string' && e.length > 0)
93
+ if (errors.length) parsed.errors = errors
68
94
  }
69
- try {
70
- return await new Promise<ExecuteResult>((resolve) => {
71
- const proc = spawn('claude', args, {
72
- stdio: ['ignore', 'pipe', 'pipe'],
73
- env: { ...process.env },
74
- cwd,
75
- })
76
- let stdout = ''
77
- let stderr = ''
78
- proc.stdout.on('data', (chunk: Buffer) => {
79
- stdout += chunk.toString()
80
- if (options.verbose) {
81
- process.stdout.write(chunk)
82
- }
83
- })
84
- proc.stderr.on('data', (chunk: Buffer) => {
85
- stderr += chunk.toString()
86
- if (options.verbose) {
87
- process.stderr.write(chunk)
88
- }
89
- })
90
- proc.on('close', (code) => {
91
- let textOutput = [stdout, stderr].filter(Boolean).join('\n')
92
- let usage: TokenUsage | undefined
93
- try {
94
- // Try single JSON object first (claude CLI)
95
- const parsedJson = JSON.parse(stdout) as Record<string, unknown>
96
- if (typeof parsedJson.result === 'string') {
97
- textOutput = parsedJson.result
98
- }
99
- const u = parsedJson?.usage as Record<string, number> | undefined
100
- if (u) {
101
- const promptTokens = (u.input_tokens ?? u.prompt_tokens) as number | undefined
102
- const completionTokens = (u.output_tokens ?? u.completion_tokens) as number | undefined
103
- const total = ((promptTokens ?? 0) + (completionTokens ?? 0)) || undefined
104
- usage = { prompt_tokens: promptTokens, completion_tokens: completionTokens, total_tokens: total }
105
- }
106
- } catch {
107
- // Fallback: parse JSONL (one JSON object per line)
108
- // Claude CLI uses {"result": "text"}, Copilot CLI uses
109
- // {"type":"assistant.message","data":{"content":"text"}} for the AI
110
- // response and a separate {"type":"result"} line for session metadata.
111
- const lines = stdout.split('\n')
112
- let lastAssistantContent: string | undefined
113
- for (const rawLine of lines) {
114
- const line = rawLine.trim()
115
- if (!line) continue
116
- try {
117
- const parsed = JSON.parse(line) as Record<string, unknown>
118
- // Claude-style: result text in the result line
119
- if (typeof parsed.result === 'string' && parsed.result) {
120
- textOutput = parsed.result
121
- const u = parsed?.usage as Record<string, number> | undefined
122
- if (u) {
123
- const promptTokens = (u.input_tokens ?? u.prompt_tokens) as number | undefined
124
- const completionTokens = (u.output_tokens ?? u.completion_tokens) as number | undefined
125
- const total = ((promptTokens ?? 0) + (completionTokens ?? 0)) || undefined
126
- usage = { prompt_tokens: promptTokens, completion_tokens: completionTokens, total_tokens: total }
127
- }
128
- lastAssistantContent = undefined // prefer explicit result field
129
- break
130
- }
131
- // Copilot-style: AI response in assistant.message events
132
- if (parsed.type === 'assistant.message') {
133
- const data = parsed.data as Record<string, unknown> | undefined
134
- if (data && typeof data.content === 'string') {
135
- lastAssistantContent = data.content
136
- }
137
- }
138
- } catch { /* skip non-JSON lines */ }
139
- }
140
- if (lastAssistantContent !== undefined) {
141
- textOutput = lastAssistantContent
142
- }
143
- }
144
- resolve({
145
- success: code === 0,
146
- output: textOutput.slice(0, 500_000),
147
- exitCode: code ?? -1,
148
- usage,
149
- })
150
- })
151
- proc.on('error', (err) => {
152
- resolve({
153
- success: false,
154
- output: `Failed to spawn claude: ${err.message}`,
155
- exitCode: -1,
156
- })
157
- })
158
- task._process = proc
159
- })
160
- } finally {
161
- if (wroteJson) {
162
- try { unlinkSync(mcpJsonPath) } catch { /* ignore */ }
95
+
96
+ const models = obj.modelUsage as Record<string, Record<string, unknown>> | undefined
97
+ const entries = models && typeof models === 'object' ? Object.entries(models).filter(([, m]) => m && typeof m === 'object') : []
98
+ if (entries.length) {
99
+ const sum = (key: string): number | undefined => {
100
+ const values = entries.map(([, m]) => num(m[key])).filter((v): v is number => v !== undefined)
101
+ return values.length ? values.reduce((a, b) => a + b, 0) : undefined
163
102
  }
103
+ parsed.usage = toUsage(sum('inputTokens'), sum('outputTokens'), sum('cacheReadInputTokens'), sum('cacheCreationInputTokens'))
104
+ let best: { name: string; cost: number; out: number } | undefined
105
+ for (const [model, m] of entries) {
106
+ const c = num(m.costUSD) ?? 0
107
+ const o = num(m.outputTokens) ?? 0
108
+ if (!best || c > best.cost || (c === best.cost && o > best.out)) best = { name: model, cost: c, out: o }
109
+ }
110
+ if (best) parsed.model = best.name
111
+ }
112
+ const u = obj.usage as Record<string, unknown> | undefined
113
+ if (!parsed.usage && u && typeof u === 'object') {
114
+ parsed.usage = toUsage(num(u.input_tokens), num(u.output_tokens), num(u.cache_read_input_tokens), num(u.cache_creation_input_tokens))
164
115
  }
116
+ if (!parsed.usage) delete parsed.usage
117
+
118
+ const cost = num(obj.total_cost_usd)
119
+ if (cost !== undefined) parsed.costUsd = cost
120
+ return parsed
165
121
  }
166
122
 
167
- function killCli(task: Task): void {
168
- if (task._process && !task._process.killed) {
169
- task._process.kill('SIGTERM')
170
- setTimeout(() => {
171
- if (task._process && !task._process.killed) {
172
- task._process.kill('SIGKILL')
173
- }
174
- }, 5000)
175
- }
123
+ /**
124
+ * How a permission mode is spelled for `claude -p`.
125
+ *
126
+ * Read-only (`plan`) is not passed as Claude Code's plan mode: plan mode
127
+ * replaces a small model with a larger one, so a review asked to run on
128
+ * `haiku` ran on `sonnet` at four times the cost. Default mode with the edit
129
+ * tools taken away is just as read-only — a headless session refuses whatever
130
+ * it would have asked about — and keeps the model it was given.
131
+ */
132
+ export function claudePermissionArgs(mode: ExecuteOptions['permissionMode']): string[] {
133
+ if (mode === 'plan') return ['--permission-mode', 'default', '--disallowedTools', 'Edit,Write,NotebookEdit']
134
+ return ['--permission-mode', mode ?? 'acceptEdits']
176
135
  }
177
136
 
178
- // --- Unified interface ---
179
137
  export async function execute(task: Task, options: ExecuteOptions = {}): Promise<ExecuteResult> {
180
- return executeViaCli(task, options)
138
+ // A worker has no terminal, so a permission prompt is a refusal it cannot
139
+ // answer: without a mode it tries to write, is denied, and exits 0 having
140
+ // written nothing. `acceptEdits` is the least that lets it do the work.
141
+ const args = ['-p', '--output-format', 'json', ...claudePermissionArgs(options.permissionMode)]
142
+ if (options.model) args.push('--model', options.model)
143
+ // No --max-turns: the task's timeout bounds a session, and a turn cap only
144
+ // cut long tasks short with a result that looked like an ordinary failure.
145
+
146
+ const exit = await runAgent(task, {
147
+ command: 'claude',
148
+ args,
149
+ input: promptOf(task),
150
+ cwd: options.cwd ?? process.cwd(),
151
+ verbose: options.verbose,
152
+ })
153
+
154
+ const parsed = parseClaudeOutput(exit.stdout)
155
+ const interrupted = interruptedMessage('claude', task, exit)
156
+ const success = !interrupted && exit.code === 0 && !parsed.isError
157
+ const raw = [exit.stdout, exit.stderr].filter(Boolean).join('\n')
158
+ const output = success
159
+ ? parsed.text ?? raw
160
+ : [interrupted, parsed.text, ...(parsed.errors ?? []), parsed.text || parsed.errors ? exit.stderr : raw].filter(Boolean).join('\n')
161
+ return {
162
+ success,
163
+ output: output.slice(0, OUTPUT_LIMIT),
164
+ exitCode: exit.code,
165
+ ...(exit.timedOut ? { _timedOut: true } : {}),
166
+ ...(parsed.usage ? { usage: parsed.usage } : {}),
167
+ ...(parsed.costUsd !== undefined ? { costUsd: parsed.costUsd } : {}),
168
+ ...(parsed.model ? { model: parsed.model } : {}),
169
+ }
181
170
  }
182
171
 
183
172
  export function kill(task: Task): void {
184
- killCli(task)
185
- }
173
+ stopTask(task)
174
+ }
@@ -1,130 +1,150 @@
1
- import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
2
- import { EventEmitter } from 'node:events'
3
- import { existsSync, rmSync, writeFileSync } from 'node:fs'
1
+ import { describe, it, expect, beforeEach, afterEach } from 'vitest'
2
+ import { existsSync } from 'node:fs'
4
3
  import type { Task } from '../../convoy/spec-types.js'
4
+ import { installStubCli, type StubCli } from './stub-cli.test-helper.js'
5
+ import { execute, isAvailable, parseCodexOutput } from './codex.js'
5
6
 
6
- function makeTask(): Task {
7
- return {
8
- id: 'test-task',
9
- agent: 'developer',
10
- prompt: 'Do something',
11
- files: [],
12
- timeout: '5m',
13
- depends_on: [],
14
- description: 'test task',
15
- max_retries: 0,
16
- } as unknown as Task
17
- }
7
+ const posix = process.platform !== 'win32'
18
8
 
19
- function makeMockProc(exitCode = 0, stdoutData = '', stderrData = '') {
20
- const proc = new EventEmitter() as EventEmitter & {
21
- stdout: EventEmitter
22
- stderr: EventEmitter
23
- killed: boolean
24
- kill: ReturnType<typeof vi.fn>
9
+ function makeTask(overrides: Partial<Task> = {}): Task {
10
+ return {
11
+ id: 'test-task', agent: 'developer', prompt: 'Do something', files: [], timeout: '5m',
12
+ depends_on: [], description: 'test task', max_retries: 0, ...overrides,
25
13
  }
26
- proc.stdout = new EventEmitter()
27
- proc.stderr = new EventEmitter()
28
- proc.killed = false
29
- proc.kill = vi.fn()
30
- process.nextTick(() => {
31
- if (stdoutData) proc.stdout.emit('data', Buffer.from(stdoutData))
32
- if (stderrData) proc.stderr.emit('data', Buffer.from(stderrData))
33
- proc.emit('close', exitCode)
34
- })
35
- return proc
36
14
  }
37
15
 
38
- describe('codex adapter', () => {
39
- let mockSpawn: ReturnType<typeof vi.fn>
40
-
41
- beforeEach(() => {
42
- vi.resetModules()
43
- mockSpawn = vi.fn().mockImplementation((cmd: string) => {
44
- if (cmd === 'which') return makeMockProc(0)
45
- return makeMockProc(0)
16
+ /**
17
+ * `codex exec --json` stdout: the sample from Codex's non-interactive docs,
18
+ * with the fields the current event structs always serialize. `turn.completed`
19
+ * carries the thread's running total; `input_tokens` includes the cached ones.
20
+ */
21
+ const STREAM = [
22
+ '{"type":"thread.started","thread_id":"0199a213-81c0-7800-8aa1-bbab2a035a53"}',
23
+ '{"type":"turn.started"}',
24
+ '{"type":"item.completed","item":{"id":"item_0","type":"reasoning","text":"**Inspecting repo layout**"}}',
25
+ '{"type":"item.started","item":{"id":"item_1","type":"command_execution","command":"bash -lc ls","aggregated_output":"","exit_code":null,"status":"in_progress"}}',
26
+ '{"type":"item.completed","item":{"id":"item_1","type":"command_execution","command":"bash -lc ls","aggregated_output":"docs\\nsdk\\n","exit_code":0,"status":"completed"}}',
27
+ '{"type":"item.completed","item":{"id":"item_3","type":"agent_message","text":"Repo contains docs, sdk, and examples directories."}}',
28
+ '{"type":"turn.completed","usage":{"input_tokens":24763,"cached_input_tokens":24448,"cache_write_input_tokens":0,"output_tokens":122,"reasoning_output_tokens":0}}',
29
+ ].join('\n')
30
+
31
+ describe('parseCodexOutput', () => {
32
+ it('reads the token counts from turn.completed and the final message', () => {
33
+ const parsed = parseCodexOutput(STREAM)
34
+ expect(parsed.usage).toEqual({
35
+ prompt_tokens: 24763,
36
+ completion_tokens: 122,
37
+ total_tokens: 24885,
38
+ cache_read_tokens: 24448,
46
39
  })
47
- vi.doMock('node:child_process', () => ({ spawn: mockSpawn }))
40
+ expect(parsed.text).toBe('Repo contains docs, sdk, and examples directories.')
41
+ expect(parsed.errors).toEqual([])
48
42
  })
49
43
 
50
- afterEach(() => {
51
- vi.restoreAllMocks()
44
+ it('takes the last running total when there are several turns', () => {
45
+ const two = STREAM + '\n' + '{"type":"turn.completed","usage":{"input_tokens":50000,"cached_input_tokens":40000,"output_tokens":300,"reasoning_output_tokens":10}}'
46
+ expect(parseCodexOutput(two).usage?.prompt_tokens).toBe(50000)
52
47
  })
53
48
 
54
- it('loads through the runtime adapter registry', async () => {
55
- const { getAdapter } = await import('./index.js')
56
- const adapter = await getAdapter('codex')
57
- expect(adapter.name).toBe('codex')
49
+ it('reads the token_count events older releases printed', () => {
50
+ const legacy = [
51
+ '{"id":"0","msg":{"type":"task_started"}}',
52
+ '{"id":"0","msg":{"type":"token_count","info":null}}',
53
+ '{"id":"0","msg":{"type":"token_count","info":{"total_token_usage":{"input_tokens":3051,"cached_input_tokens":2944,"output_tokens":87,"reasoning_output_tokens":64,"total_tokens":3138},"last_token_usage":{"input_tokens":3051,"cached_input_tokens":2944,"output_tokens":87,"reasoning_output_tokens":64,"total_tokens":3138},"model_context_window":272000}}}',
54
+ ].join('\n')
55
+ expect(parseCodexOutput(legacy).usage).toEqual({
56
+ prompt_tokens: 3051, completion_tokens: 87, total_tokens: 3138, cache_read_tokens: 2944,
57
+ })
58
58
  })
59
59
 
60
- it('reports availability when codex is on PATH', async () => {
61
- const { isAvailable } = await import('./codex.js')
62
- await expect(isAvailable()).resolves.toBe(true)
60
+ it('collects the failure messages and names no cost or model it was not given', () => {
61
+ const failed = [
62
+ '{"type":"thread.started","thread_id":"t"}',
63
+ '{"type":"turn.started"}',
64
+ '{"type":"error","message":"stream disconnected before completion"}',
65
+ '{"type":"turn.failed","error":{"message":"stream disconnected before completion"}}',
66
+ ].join('\n')
67
+ const parsed = parseCodexOutput(failed)
68
+ expect(parsed.errors).toHaveLength(2)
69
+ expect(parsed.usage).toBeUndefined()
70
+ expect(Object.keys(parsed)).not.toContain('costUsd')
63
71
  })
72
+ })
64
73
 
65
- it('returns the final agent message written via --output-last-message', async () => {
66
- const capturedArgs: string[] = []
67
-
68
- mockSpawn.mockImplementation((cmd: string, args: string[]) => {
69
- if (cmd === 'which') return makeMockProc(0)
70
- capturedArgs.push(...args)
71
- const outputIdx = args.indexOf('-o')
72
- const outputPath = args[outputIdx + 1]
73
- if (outputPath) {
74
- writeFileSync(outputPath, 'I did the task\n', 'utf8')
75
- }
76
- return makeMockProc(0, '', 'progress')
77
- })
74
+ describe.skipIf(!posix)('codex adapter — against a stub `codex`', () => {
75
+ let stub: StubCli
76
+
77
+ beforeEach(() => {
78
+ stub = installStubCli('codex')
79
+ stub.respond(STREAM, 'progress on stderr')
80
+ process.env.STUB_LAST_MESSAGE = 'I did the task\n'
81
+ })
82
+ afterEach(() => stub.restore())
78
83
 
79
- const { execute } = await import('./codex.js')
80
- const result = await execute(makeTask(), { cwd: process.cwd() })
84
+ it('is available only when `codex` is on PATH', async () => {
85
+ expect(await isAvailable()).toBe(true)
86
+ stub.restore()
87
+ stub = installStubCli()
88
+ expect(await isAvailable()).toBe(false)
89
+ })
81
90
 
91
+ it('reads the prompt from stdin, works in the task directory, and reports usage', async () => {
92
+ const task = makeTask()
93
+ const result = await execute(task, { cwd: stub.work })
82
94
  expect(result.success).toBe(true)
83
95
  expect(result.output).toBe('I did the task')
84
- expect(capturedArgs).toContain('exec')
85
- expect(capturedArgs).toContain('-a')
86
- expect(capturedArgs).toContain('never')
87
- expect(capturedArgs).toContain('-s')
88
- expect(capturedArgs).toContain('workspace-write')
89
- expect(capturedArgs).toContain('--ephemeral')
90
- expect(capturedArgs).toContain('-C')
91
- expect(capturedArgs).toContain(process.cwd())
96
+ expect(result.usage?.cache_read_tokens).toBe(24448)
97
+ expect(result.costUsd).toBeUndefined()
98
+ expect(stub.stdin()).toBe(task.prompt)
99
+ expect(stub.cwd()).toBe(stub.work)
100
+ const argv = stub.argv()
101
+ expect(argv[0]).toBe('exec')
102
+ expect(argv.at(-1)).toBe('-')
103
+ expect(argv).toContain('--json')
104
+ expect(argv[argv.indexOf('-C') + 1]).toBe(stub.work)
105
+ expect(argv).not.toContain(task.prompt)
106
+ // `-a` is not an exec option; before `exec` it was parsed and ignored.
107
+ expect(argv).not.toContain('-a')
92
108
  })
93
109
 
94
- it('falls back to combined stdout and stderr when execution fails', async () => {
95
- mockSpawn.mockImplementation((cmd: string) => {
96
- if (cmd === 'which') return makeMockProc(0)
97
- return makeMockProc(1, 'stdout failure', 'stderr failure')
98
- })
110
+ it('maps the permission mode onto the sandbox', async () => {
111
+ const sandbox = () => { const a = stub.argv(); return a[a.indexOf('-s') + 1] }
112
+ await execute(makeTask(), { cwd: stub.work })
113
+ expect(sandbox()).toBe('workspace-write')
114
+ await execute(makeTask(), { cwd: stub.work, permissionMode: 'plan' })
115
+ expect(sandbox()).toBe('read-only')
116
+ await execute(makeTask(), { cwd: stub.work, permissionMode: 'bypassPermissions' })
117
+ expect(sandbox()).toBe('danger-full-access')
118
+ })
99
119
 
100
- const { execute } = await import('./codex.js')
101
- const result = await execute(makeTask(), { cwd: process.cwd() })
120
+ it('passes -m only when a model is set', async () => {
121
+ await execute(makeTask(), { cwd: stub.work })
122
+ expect(stub.argv()).not.toContain('-m')
123
+ await execute(makeTask(), { cwd: stub.work, model: 'gpt-5.1-codex' })
124
+ const argv = stub.argv()
125
+ expect(argv[argv.indexOf('-m') + 1]).toBe('gpt-5.1-codex')
126
+ })
102
127
 
128
+ it('reports the failure messages on a non-zero exit', async () => {
129
+ process.env.STUB_EXIT = '1'
130
+ delete process.env.STUB_LAST_MESSAGE
131
+ stub.respond('{"type":"turn.failed","error":{"message":"unauthorized"}}\n', 'stderr failure')
132
+ const result = await execute(makeTask(), { cwd: stub.work })
103
133
  expect(result.success).toBe(false)
104
- expect(result.output).toContain('stdout failure')
134
+ expect(result.output).toContain('unauthorized')
105
135
  expect(result.output).toContain('stderr failure')
106
136
  })
107
137
 
108
- it('cleans up the temporary output file after execution', async () => {
109
- let outputPath = ''
110
-
111
- mockSpawn.mockImplementation((cmd: string, args: string[]) => {
112
- if (cmd === 'which') return makeMockProc(0)
113
- const outputIdx = args.indexOf('-o')
114
- outputPath = args[outputIdx + 1] ?? ''
115
- if (outputPath) {
116
- writeFileSync(outputPath, 'done\n', 'utf8')
117
- }
118
- return makeMockProc(0)
119
- })
120
-
121
- const { execute } = await import('./codex.js')
122
- await execute(makeTask(), { cwd: process.cwd() })
138
+ it('removes its temporary output file', async () => {
139
+ await execute(makeTask(), { cwd: stub.work })
140
+ const argv = stub.argv()
141
+ expect(existsSync(argv[argv.indexOf('-o') + 1])).toBe(false)
142
+ })
123
143
 
124
- expect(outputPath).not.toBe('')
125
- expect(existsSync(outputPath)).toBe(false)
126
- if (outputPath) {
127
- rmSync(outputPath, { force: true })
128
- }
144
+ it('times out with success false', async () => {
145
+ process.env.STUB_SLEEP = '30'
146
+ const result = await execute(makeTask({ timeout: '300ms' }), { cwd: stub.work })
147
+ expect(result.success).toBe(false)
148
+ expect(result._timedOut).toBe(true)
129
149
  })
130
150
  })