opencastle 1.3.1 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (486) hide show
  1. package/README.md +16 -10
  2. package/bin/cli.mjs +8 -9
  3. package/dist/cli/agent-roster.test.js +0 -48
  4. package/dist/cli/agent-roster.test.js.map +1 -1
  5. package/dist/cli/boundary.test.js +9 -7
  6. package/dist/cli/boundary.test.js.map +1 -1
  7. package/dist/cli/convoy/artifacts.d.ts +9 -2
  8. package/dist/cli/convoy/artifacts.d.ts.map +1 -1
  9. package/dist/cli/convoy/artifacts.js +13 -10
  10. package/dist/cli/convoy/artifacts.js.map +1 -1
  11. package/dist/cli/convoy/artifacts.test.js +4 -2
  12. package/dist/cli/convoy/artifacts.test.js.map +1 -1
  13. package/dist/cli/convoy/engine.d.ts +53 -23
  14. package/dist/cli/convoy/engine.d.ts.map +1 -1
  15. package/dist/cli/convoy/engine.git.test.d.ts +2 -0
  16. package/dist/cli/convoy/engine.git.test.d.ts.map +1 -0
  17. package/dist/cli/convoy/engine.git.test.js +435 -0
  18. package/dist/cli/convoy/engine.git.test.js.map +1 -0
  19. package/dist/cli/convoy/engine.js +1746 -2305
  20. package/dist/cli/convoy/engine.js.map +1 -1
  21. package/dist/cli/convoy/engine.test.js +698 -678
  22. package/dist/cli/convoy/engine.test.js.map +1 -1
  23. package/dist/cli/convoy/event-schemas.d.ts +2 -0
  24. package/dist/cli/convoy/event-schemas.d.ts.map +1 -1
  25. package/dist/cli/convoy/event-schemas.js +59 -57
  26. package/dist/cli/convoy/event-schemas.js.map +1 -1
  27. package/dist/cli/convoy/events.d.ts +4 -1
  28. package/dist/cli/convoy/events.d.ts.map +1 -1
  29. package/dist/cli/convoy/events.js +69 -84
  30. package/dist/cli/convoy/events.js.map +1 -1
  31. package/dist/cli/convoy/events.test.js +50 -9
  32. package/dist/cli/convoy/events.test.js.map +1 -1
  33. package/dist/cli/convoy/gates.d.ts +9 -4
  34. package/dist/cli/convoy/gates.d.ts.map +1 -1
  35. package/dist/cli/convoy/gates.js +29 -14
  36. package/dist/cli/convoy/gates.js.map +1 -1
  37. package/dist/cli/convoy/isolation.d.ts +32 -6
  38. package/dist/cli/convoy/isolation.d.ts.map +1 -1
  39. package/dist/cli/convoy/isolation.js +72 -34
  40. package/dist/cli/convoy/isolation.js.map +1 -1
  41. package/dist/cli/convoy/isolation.test.js +66 -42
  42. package/dist/cli/convoy/isolation.test.js.map +1 -1
  43. package/dist/cli/convoy/lock.d.ts.map +1 -1
  44. package/dist/cli/convoy/lock.js +25 -10
  45. package/dist/cli/convoy/lock.js.map +1 -1
  46. package/dist/cli/convoy/lock.test.js +12 -0
  47. package/dist/cli/convoy/lock.test.js.map +1 -1
  48. package/dist/cli/convoy/merge.d.ts +21 -4
  49. package/dist/cli/convoy/merge.d.ts.map +1 -1
  50. package/dist/cli/convoy/merge.js +69 -53
  51. package/dist/cli/convoy/merge.js.map +1 -1
  52. package/dist/cli/convoy/merge.test.js +23 -1
  53. package/dist/cli/convoy/merge.test.js.map +1 -1
  54. package/dist/cli/convoy/progress.d.ts +35 -0
  55. package/dist/cli/convoy/progress.d.ts.map +1 -0
  56. package/dist/cli/convoy/progress.js +103 -0
  57. package/dist/cli/convoy/progress.js.map +1 -0
  58. package/dist/cli/convoy/progress.test.d.ts +2 -0
  59. package/dist/cli/convoy/progress.test.d.ts.map +1 -0
  60. package/dist/cli/convoy/progress.test.js +53 -0
  61. package/dist/cli/convoy/progress.test.js.map +1 -0
  62. package/dist/cli/convoy/read-model.d.ts +468 -0
  63. package/dist/cli/convoy/read-model.d.ts.map +1 -0
  64. package/dist/cli/convoy/read-model.js +1132 -0
  65. package/dist/cli/convoy/read-model.js.map +1 -0
  66. package/dist/cli/convoy/read-model.test.d.ts +2 -0
  67. package/dist/cli/convoy/read-model.test.d.ts.map +1 -0
  68. package/dist/cli/convoy/read-model.test.js +609 -0
  69. package/dist/cli/convoy/read-model.test.js.map +1 -0
  70. package/dist/cli/convoy/redact.d.ts +34 -0
  71. package/dist/cli/convoy/redact.d.ts.map +1 -0
  72. package/dist/cli/convoy/redact.js +66 -0
  73. package/dist/cli/convoy/redact.js.map +1 -0
  74. package/dist/cli/convoy/redact.test.d.ts +2 -0
  75. package/dist/cli/convoy/redact.test.d.ts.map +1 -0
  76. package/dist/cli/convoy/redact.test.js +43 -0
  77. package/dist/cli/convoy/redact.test.js.map +1 -0
  78. package/dist/cli/convoy/reviewer.d.ts +65 -0
  79. package/dist/cli/convoy/reviewer.d.ts.map +1 -0
  80. package/dist/cli/convoy/reviewer.js +141 -0
  81. package/dist/cli/convoy/reviewer.js.map +1 -0
  82. package/dist/cli/convoy/reviewer.test.d.ts +2 -0
  83. package/dist/cli/convoy/reviewer.test.d.ts.map +1 -0
  84. package/dist/cli/convoy/reviewer.test.js +96 -0
  85. package/dist/cli/convoy/reviewer.test.js.map +1 -0
  86. package/dist/cli/convoy/schedule.d.ts +30 -0
  87. package/dist/cli/convoy/schedule.d.ts.map +1 -0
  88. package/dist/cli/convoy/schedule.js +111 -0
  89. package/dist/cli/convoy/schedule.js.map +1 -0
  90. package/dist/cli/convoy/schedule.test.d.ts +2 -0
  91. package/dist/cli/convoy/schedule.test.d.ts.map +1 -0
  92. package/dist/cli/convoy/schedule.test.js +45 -0
  93. package/dist/cli/convoy/schedule.test.js.map +1 -0
  94. package/dist/cli/convoy/spec-builder.d.ts +120 -30
  95. package/dist/cli/convoy/spec-builder.d.ts.map +1 -1
  96. package/dist/cli/convoy/spec-builder.js +438 -114
  97. package/dist/cli/convoy/spec-builder.js.map +1 -1
  98. package/dist/cli/convoy/spec-builder.test.js +419 -435
  99. package/dist/cli/convoy/spec-builder.test.js.map +1 -1
  100. package/dist/cli/convoy/spec-types.d.ts +46 -92
  101. package/dist/cli/convoy/spec-types.d.ts.map +1 -1
  102. package/dist/cli/convoy/store.d.ts +6 -1
  103. package/dist/cli/convoy/store.d.ts.map +1 -1
  104. package/dist/cli/convoy/store.js +111 -15
  105. package/dist/cli/convoy/store.js.map +1 -1
  106. package/dist/cli/convoy/store.test.js +59 -13
  107. package/dist/cli/convoy/store.test.js.map +1 -1
  108. package/dist/cli/convoy/types.d.ts +76 -113
  109. package/dist/cli/convoy/types.d.ts.map +1 -1
  110. package/dist/cli/convoy/types.js +6 -13
  111. package/dist/cli/convoy/types.js.map +1 -1
  112. package/dist/cli/convoy/worktree.d.ts +88 -3
  113. package/dist/cli/convoy/worktree.d.ts.map +1 -1
  114. package/dist/cli/convoy/worktree.js +282 -56
  115. package/dist/cli/convoy/worktree.js.map +1 -1
  116. package/dist/cli/convoy/worktree.test.js +132 -1
  117. package/dist/cli/convoy/worktree.test.js.map +1 -1
  118. package/dist/cli/convoy-args.test.js +9 -27
  119. package/dist/cli/convoy-args.test.js.map +1 -1
  120. package/dist/cli/convoy-cmd.d.ts +31 -6
  121. package/dist/cli/convoy-cmd.d.ts.map +1 -1
  122. package/dist/cli/convoy-cmd.js +150 -201
  123. package/dist/cli/convoy-cmd.js.map +1 -1
  124. package/dist/cli/convoy-cmd.test.d.ts +2 -0
  125. package/dist/cli/convoy-cmd.test.d.ts.map +1 -0
  126. package/dist/cli/convoy-cmd.test.js +144 -0
  127. package/dist/cli/convoy-cmd.test.js.map +1 -0
  128. package/dist/cli/dashboard.d.ts +24 -11
  129. package/dist/cli/dashboard.d.ts.map +1 -1
  130. package/dist/cli/dashboard.js +241 -303
  131. package/dist/cli/dashboard.js.map +1 -1
  132. package/dist/cli/dashboard.test.d.ts +2 -0
  133. package/dist/cli/dashboard.test.d.ts.map +1 -0
  134. package/dist/cli/dashboard.test.js +340 -0
  135. package/dist/cli/dashboard.test.js.map +1 -0
  136. package/dist/cli/dispatcher.test.js +35 -2
  137. package/dist/cli/dispatcher.test.js.map +1 -1
  138. package/dist/cli/docs-accuracy.test.js +3 -3
  139. package/dist/cli/docs-accuracy.test.js.map +1 -1
  140. package/dist/cli/log.d.ts +39 -0
  141. package/dist/cli/log.d.ts.map +1 -1
  142. package/dist/cli/log.js +267 -93
  143. package/dist/cli/log.js.map +1 -1
  144. package/dist/cli/log.test.d.ts +2 -0
  145. package/dist/cli/log.test.d.ts.map +1 -0
  146. package/dist/cli/log.test.js +208 -0
  147. package/dist/cli/log.test.js.map +1 -0
  148. package/dist/cli/nearest.d.ts +18 -0
  149. package/dist/cli/nearest.d.ts.map +1 -0
  150. package/dist/cli/nearest.js +38 -0
  151. package/dist/cli/nearest.js.map +1 -0
  152. package/dist/cli/nearest.test.d.ts +2 -0
  153. package/dist/cli/nearest.test.d.ts.map +1 -0
  154. package/dist/cli/nearest.test.js +24 -0
  155. package/dist/cli/nearest.test.js.map +1 -0
  156. package/dist/cli/pipeline.d.ts +61 -0
  157. package/dist/cli/pipeline.d.ts.map +1 -1
  158. package/dist/cli/pipeline.flow.test.d.ts +2 -0
  159. package/dist/cli/pipeline.flow.test.d.ts.map +1 -0
  160. package/dist/cli/pipeline.flow.test.js +524 -0
  161. package/dist/cli/pipeline.flow.test.js.map +1 -0
  162. package/dist/cli/pipeline.js +471 -690
  163. package/dist/cli/pipeline.js.map +1 -1
  164. package/dist/cli/plan.d.ts +82 -31
  165. package/dist/cli/plan.d.ts.map +1 -1
  166. package/dist/cli/plan.js +167 -507
  167. package/dist/cli/plan.js.map +1 -1
  168. package/dist/cli/plan.test.d.ts +2 -0
  169. package/dist/cli/plan.test.d.ts.map +1 -0
  170. package/dist/cli/plan.test.js +158 -0
  171. package/dist/cli/plan.test.js.map +1 -0
  172. package/dist/cli/run/adapters/agent-process.d.ts +82 -0
  173. package/dist/cli/run/adapters/agent-process.d.ts.map +1 -0
  174. package/dist/cli/run/adapters/agent-process.js +224 -0
  175. package/dist/cli/run/adapters/agent-process.js.map +1 -0
  176. package/dist/cli/run/adapters/agent-process.test.d.ts +2 -0
  177. package/dist/cli/run/adapters/agent-process.test.d.ts.map +1 -0
  178. package/dist/cli/run/adapters/agent-process.test.js +159 -0
  179. package/dist/cli/run/adapters/agent-process.test.js.map +1 -0
  180. package/dist/cli/run/adapters/claude.d.ts +53 -2
  181. package/dist/cli/run/adapters/claude.d.ts.map +1 -1
  182. package/dist/cli/run/adapters/claude.js +147 -171
  183. package/dist/cli/run/adapters/claude.js.map +1 -1
  184. package/dist/cli/run/adapters/claude.test.js +197 -254
  185. package/dist/cli/run/adapters/claude.test.js.map +1 -1
  186. package/dist/cli/run/adapters/codex.d.ts +25 -2
  187. package/dist/cli/run/adapters/codex.d.ts.map +1 -1
  188. package/dist/cli/run/adapters/codex.js +113 -81
  189. package/dist/cli/run/adapters/codex.js.map +1 -1
  190. package/dist/cli/run/adapters/codex.test.js +116 -95
  191. package/dist/cli/run/adapters/codex.test.js.map +1 -1
  192. package/dist/cli/run/adapters/copilot.d.ts +35 -1
  193. package/dist/cli/run/adapters/copilot.d.ts.map +1 -1
  194. package/dist/cli/run/adapters/copilot.js +104 -287
  195. package/dist/cli/run/adapters/copilot.js.map +1 -1
  196. package/dist/cli/run/adapters/copilot.test.js +122 -282
  197. package/dist/cli/run/adapters/copilot.test.js.map +1 -1
  198. package/dist/cli/run/adapters/cursor.d.ts +25 -7
  199. package/dist/cli/run/adapters/cursor.d.ts.map +1 -1
  200. package/dist/cli/run/adapters/cursor.js +103 -156
  201. package/dist/cli/run/adapters/cursor.js.map +1 -1
  202. package/dist/cli/run/adapters/cursor.test.js +106 -218
  203. package/dist/cli/run/adapters/cursor.test.js.map +1 -1
  204. package/dist/cli/run/adapters/index.d.ts +34 -5
  205. package/dist/cli/run/adapters/index.d.ts.map +1 -1
  206. package/dist/cli/run/adapters/index.js +147 -21
  207. package/dist/cli/run/adapters/index.js.map +1 -1
  208. package/dist/cli/run/adapters/index.test.d.ts +2 -0
  209. package/dist/cli/run/adapters/index.test.d.ts.map +1 -0
  210. package/dist/cli/run/adapters/index.test.js +129 -0
  211. package/dist/cli/run/adapters/index.test.js.map +1 -0
  212. package/dist/cli/run/adapters/opencode.d.ts +25 -9
  213. package/dist/cli/run/adapters/opencode.d.ts.map +1 -1
  214. package/dist/cli/run/adapters/opencode.js +136 -152
  215. package/dist/cli/run/adapters/opencode.js.map +1 -1
  216. package/dist/cli/run/adapters/opencode.test.js +99 -218
  217. package/dist/cli/run/adapters/opencode.test.js.map +1 -1
  218. package/dist/cli/run/adapters/permission-modes.d.ts +47 -4
  219. package/dist/cli/run/adapters/permission-modes.d.ts.map +1 -1
  220. package/dist/cli/run/adapters/permission-modes.js +113 -37
  221. package/dist/cli/run/adapters/permission-modes.js.map +1 -1
  222. package/dist/cli/run/adapters/permission-modes.test.js +55 -40
  223. package/dist/cli/run/adapters/permission-modes.test.js.map +1 -1
  224. package/dist/cli/run/adapters/stub-cli.test-helper.d.ts +22 -0
  225. package/dist/cli/run/adapters/stub-cli.test-helper.d.ts.map +1 -0
  226. package/dist/cli/run/adapters/stub-cli.test-helper.js +73 -0
  227. package/dist/cli/run/adapters/stub-cli.test-helper.js.map +1 -0
  228. package/dist/cli/run/platform.d.ts +52 -0
  229. package/dist/cli/run/platform.d.ts.map +1 -0
  230. package/dist/cli/run/platform.js +207 -0
  231. package/dist/cli/run/platform.js.map +1 -0
  232. package/dist/cli/run/platform.test.d.ts +2 -0
  233. package/dist/cli/run/platform.test.d.ts.map +1 -0
  234. package/dist/cli/run/platform.test.js +119 -0
  235. package/dist/cli/run/platform.test.js.map +1 -0
  236. package/dist/cli/run/schema.d.ts +6 -8
  237. package/dist/cli/run/schema.d.ts.map +1 -1
  238. package/dist/cli/run/schema.js +44 -68
  239. package/dist/cli/run/schema.js.map +1 -1
  240. package/dist/cli/run/schema.test.js +59 -279
  241. package/dist/cli/run/schema.test.js.map +1 -1
  242. package/dist/cli/run.d.ts +34 -56
  243. package/dist/cli/run.d.ts.map +1 -1
  244. package/dist/cli/run.js +379 -1132
  245. package/dist/cli/run.js.map +1 -1
  246. package/dist/cli/run.test.d.ts +2 -0
  247. package/dist/cli/run.test.d.ts.map +1 -0
  248. package/dist/cli/run.test.js +318 -0
  249. package/dist/cli/run.test.js.map +1 -0
  250. package/dist/cli/team-config.d.ts.map +1 -1
  251. package/dist/cli/team-config.js +2 -21
  252. package/dist/cli/team-config.js.map +1 -1
  253. package/dist/cli/tiers.test.js +4 -13
  254. package/dist/cli/tiers.test.js.map +1 -1
  255. package/package.json +3 -10
  256. package/src/cli/agent-roster.test.ts +0 -55
  257. package/src/cli/boundary.test.ts +9 -7
  258. package/src/cli/convoy/TELEMETRY.md +131 -125
  259. package/src/cli/convoy/artifacts.test.ts +4 -2
  260. package/src/cli/convoy/artifacts.ts +13 -12
  261. package/src/cli/convoy/engine.git.test.ts +462 -0
  262. package/src/cli/convoy/engine.test.ts +817 -850
  263. package/src/cli/convoy/engine.ts +1864 -2596
  264. package/src/cli/convoy/event-schemas.ts +63 -59
  265. package/src/cli/convoy/events.test.ts +58 -9
  266. package/src/cli/convoy/events.ts +69 -91
  267. package/src/cli/convoy/gates.ts +31 -12
  268. package/src/cli/convoy/isolation.test.ts +76 -43
  269. package/src/cli/convoy/isolation.ts +100 -38
  270. package/src/cli/convoy/lock.test.ts +16 -0
  271. package/src/cli/convoy/lock.ts +25 -8
  272. package/src/cli/convoy/merge.test.ts +25 -1
  273. package/src/cli/convoy/merge.ts +74 -61
  274. package/src/cli/convoy/progress.test.ts +59 -0
  275. package/src/cli/convoy/progress.ts +121 -0
  276. package/src/cli/convoy/read-model.test.ts +685 -0
  277. package/src/cli/convoy/read-model.ts +1469 -0
  278. package/src/cli/convoy/redact.test.ts +49 -0
  279. package/src/cli/convoy/redact.ts +73 -0
  280. package/src/cli/convoy/reviewer.test.ts +112 -0
  281. package/src/cli/convoy/reviewer.ts +196 -0
  282. package/src/cli/convoy/schedule.test.ts +56 -0
  283. package/src/cli/convoy/schedule.ts +109 -0
  284. package/src/cli/convoy/spec-builder.test.ts +460 -464
  285. package/src/cli/convoy/spec-builder.ts +460 -129
  286. package/src/cli/convoy/spec-types.ts +46 -108
  287. package/src/cli/convoy/store.test.ts +64 -13
  288. package/src/cli/convoy/store.ts +143 -33
  289. package/src/cli/convoy/types.ts +59 -71
  290. package/src/cli/convoy/worktree.test.ts +140 -1
  291. package/src/cli/convoy/worktree.ts +311 -61
  292. package/src/cli/convoy-args.test.ts +10 -30
  293. package/src/cli/convoy-cmd.test.ts +163 -0
  294. package/src/cli/convoy-cmd.ts +173 -216
  295. package/src/cli/dashboard/dashboard.css +2086 -0
  296. package/src/cli/dashboard/dashboard.js +1687 -0
  297. package/src/cli/dashboard/index.html +307 -0
  298. package/src/cli/dashboard.test.ts +382 -0
  299. package/src/cli/dashboard.ts +243 -339
  300. package/src/cli/dispatcher.test.ts +36 -2
  301. package/src/cli/docs-accuracy.test.ts +3 -3
  302. package/src/cli/log.test.ts +228 -0
  303. package/src/cli/log.ts +302 -83
  304. package/src/cli/nearest.test.ts +27 -0
  305. package/src/cli/nearest.ts +38 -0
  306. package/src/cli/pipeline.flow.test.ts +607 -0
  307. package/src/cli/pipeline.ts +544 -759
  308. package/src/cli/plan.test.ts +193 -0
  309. package/src/cli/plan.ts +209 -545
  310. package/src/cli/run/adapters/agent-process.test.ts +175 -0
  311. package/src/cli/run/adapters/agent-process.ts +252 -0
  312. package/src/cli/run/adapters/claude.test.ts +205 -260
  313. package/src/cli/run/adapters/claude.ts +151 -162
  314. package/src/cli/run/adapters/codex.test.ts +120 -100
  315. package/src/cli/run/adapters/codex.ts +115 -91
  316. package/src/cli/run/adapters/copilot.test.ts +135 -306
  317. package/src/cli/run/adapters/copilot.ts +105 -274
  318. package/src/cli/run/adapters/cursor.test.ts +111 -220
  319. package/src/cli/run/adapters/cursor.ts +105 -156
  320. package/src/cli/run/adapters/index.test.ts +148 -0
  321. package/src/cli/run/adapters/index.ts +168 -20
  322. package/src/cli/run/adapters/opencode.test.ts +106 -227
  323. package/src/cli/run/adapters/opencode.ts +139 -151
  324. package/src/cli/run/adapters/permission-modes.test.ts +63 -41
  325. package/src/cli/run/adapters/permission-modes.ts +118 -37
  326. package/src/cli/run/adapters/stub-cli.test-helper.ts +88 -0
  327. package/src/cli/run/platform.test.ts +128 -0
  328. package/src/cli/run/platform.ts +213 -0
  329. package/src/cli/run/schema.test.ts +62 -344
  330. package/src/cli/run/schema.ts +48 -78
  331. package/src/cli/run.test.ts +351 -0
  332. package/src/cli/run.ts +366 -1151
  333. package/src/cli/team-config.ts +2 -21
  334. package/src/cli/tiers.test.ts +4 -17
  335. package/src/orchestrator/agents/team-lead.agent.md +1 -1
  336. package/src/orchestrator/prompts/assess-complexity.prompt.md +43 -26
  337. package/src/orchestrator/prompts/brainstorm.prompt.md +1 -1
  338. package/src/orchestrator/prompts/bug-fix.prompt.md +2 -2
  339. package/src/orchestrator/prompts/fix-convoy.prompt.md +43 -29
  340. package/src/orchestrator/prompts/fix-prd.prompt.md +26 -22
  341. package/src/orchestrator/prompts/generate-convoy.prompt.md +139 -147
  342. package/src/orchestrator/prompts/generate-prd.prompt.md +75 -68
  343. package/src/orchestrator/prompts/implement-feature.prompt.md +2 -2
  344. package/src/orchestrator/prompts/validate-convoy.prompt.md +29 -28
  345. package/src/orchestrator/prompts/validate-prd.prompt.md +28 -21
  346. package/src/orchestrator/skills/agent-hooks/HOOKS-REFERENCE.md +3 -3
  347. package/src/orchestrator/skills/agent-hooks/SKILL.md +1 -1
  348. package/src/orchestrator/skills/fast-review/SKILL.md +3 -1
  349. package/src/orchestrator/skills/orchestration-protocols/SKILL.md +7 -8
  350. package/dist/cli/convoy/dag-analysis.d.ts +0 -39
  351. package/dist/cli/convoy/dag-analysis.d.ts.map +0 -1
  352. package/dist/cli/convoy/dag-analysis.js +0 -279
  353. package/dist/cli/convoy/dag-analysis.js.map +0 -1
  354. package/dist/cli/convoy/dag-analysis.test.d.ts +0 -2
  355. package/dist/cli/convoy/dag-analysis.test.d.ts.map +0 -1
  356. package/dist/cli/convoy/dag-analysis.test.js +0 -289
  357. package/dist/cli/convoy/dag-analysis.test.js.map +0 -1
  358. package/dist/cli/convoy/formula.d.ts +0 -19
  359. package/dist/cli/convoy/formula.d.ts.map +0 -1
  360. package/dist/cli/convoy/formula.js +0 -142
  361. package/dist/cli/convoy/formula.js.map +0 -1
  362. package/dist/cli/convoy/formula.test.d.ts +0 -2
  363. package/dist/cli/convoy/formula.test.d.ts.map +0 -1
  364. package/dist/cli/convoy/formula.test.js +0 -342
  365. package/dist/cli/convoy/formula.test.js.map +0 -1
  366. package/dist/cli/convoy/health.d.ts +0 -34
  367. package/dist/cli/convoy/health.d.ts.map +0 -1
  368. package/dist/cli/convoy/health.js +0 -123
  369. package/dist/cli/convoy/health.js.map +0 -1
  370. package/dist/cli/convoy/health.test.d.ts +0 -2
  371. package/dist/cli/convoy/health.test.d.ts.map +0 -1
  372. package/dist/cli/convoy/health.test.js +0 -448
  373. package/dist/cli/convoy/health.test.js.map +0 -1
  374. package/dist/cli/convoy/last-run.d.ts +0 -53
  375. package/dist/cli/convoy/last-run.d.ts.map +0 -1
  376. package/dist/cli/convoy/last-run.js +0 -54
  377. package/dist/cli/convoy/last-run.js.map +0 -1
  378. package/dist/cli/convoy/last-run.test.d.ts +0 -2
  379. package/dist/cli/convoy/last-run.test.d.ts.map +0 -1
  380. package/dist/cli/convoy/last-run.test.js +0 -110
  381. package/dist/cli/convoy/last-run.test.js.map +0 -1
  382. package/dist/cli/convoy/pipeline.d.ts +0 -41
  383. package/dist/cli/convoy/pipeline.d.ts.map +0 -1
  384. package/dist/cli/convoy/pipeline.js +0 -414
  385. package/dist/cli/convoy/pipeline.js.map +0 -1
  386. package/dist/cli/convoy/pipeline.test.d.ts +0 -2
  387. package/dist/cli/convoy/pipeline.test.d.ts.map +0 -1
  388. package/dist/cli/convoy/pipeline.test.js +0 -837
  389. package/dist/cli/convoy/pipeline.test.js.map +0 -1
  390. package/dist/cli/convoy/review-stages.d.ts +0 -9
  391. package/dist/cli/convoy/review-stages.d.ts.map +0 -1
  392. package/dist/cli/convoy/review-stages.js +0 -134
  393. package/dist/cli/convoy/review-stages.js.map +0 -1
  394. package/dist/cli/convoy/review-stages.test.d.ts +0 -2
  395. package/dist/cli/convoy/review-stages.test.d.ts.map +0 -1
  396. package/dist/cli/convoy/review-stages.test.js +0 -197
  397. package/dist/cli/convoy/review-stages.test.js.map +0 -1
  398. package/dist/cli/run/executor.d.ts +0 -15
  399. package/dist/cli/run/executor.d.ts.map +0 -1
  400. package/dist/cli/run/executor.js +0 -249
  401. package/dist/cli/run/executor.js.map +0 -1
  402. package/dist/cli/run/executor.test.d.ts +0 -2
  403. package/dist/cli/run/executor.test.d.ts.map +0 -1
  404. package/dist/cli/run/executor.test.js +0 -297
  405. package/dist/cli/run/executor.test.js.map +0 -1
  406. package/dist/cli/run/reporter.d.ts +0 -10
  407. package/dist/cli/run/reporter.d.ts.map +0 -1
  408. package/dist/cli/run/reporter.js +0 -142
  409. package/dist/cli/run/reporter.js.map +0 -1
  410. package/dist/cli/run-dry-run.test.d.ts +0 -2
  411. package/dist/cli/run-dry-run.test.d.ts.map +0 -1
  412. package/dist/cli/run-dry-run.test.js +0 -83
  413. package/dist/cli/run-dry-run.test.js.map +0 -1
  414. package/dist/cli/run-executor-flags.test.d.ts +0 -2
  415. package/dist/cli/run-executor-flags.test.d.ts.map +0 -1
  416. package/dist/cli/run-executor-flags.test.js +0 -31
  417. package/dist/cli/run-executor-flags.test.js.map +0 -1
  418. package/dist/cli/run-finish.test.d.ts +0 -2
  419. package/dist/cli/run-finish.test.d.ts.map +0 -1
  420. package/dist/cli/run-finish.test.js +0 -77
  421. package/dist/cli/run-finish.test.js.map +0 -1
  422. package/dist/cli/watch.d.ts +0 -15
  423. package/dist/cli/watch.d.ts.map +0 -1
  424. package/dist/cli/watch.js +0 -277
  425. package/dist/cli/watch.js.map +0 -1
  426. package/dist/dashboard/scripts/etl.d.ts +0 -10
  427. package/dist/dashboard/scripts/etl.d.ts.map +0 -1
  428. package/dist/dashboard/scripts/etl.js +0 -141
  429. package/dist/dashboard/scripts/etl.js.map +0 -1
  430. package/src/cli/convoy/dag-analysis.test.ts +0 -349
  431. package/src/cli/convoy/dag-analysis.ts +0 -367
  432. package/src/cli/convoy/formula.test.ts +0 -404
  433. package/src/cli/convoy/formula.ts +0 -174
  434. package/src/cli/convoy/health.test.ts +0 -519
  435. package/src/cli/convoy/health.ts +0 -189
  436. package/src/cli/convoy/last-run.test.ts +0 -130
  437. package/src/cli/convoy/last-run.ts +0 -87
  438. package/src/cli/convoy/pipeline.test.ts +0 -999
  439. package/src/cli/convoy/pipeline.ts +0 -492
  440. package/src/cli/convoy/review-stages.test.ts +0 -235
  441. package/src/cli/convoy/review-stages.ts +0 -166
  442. package/src/cli/run/executor.test.ts +0 -338
  443. package/src/cli/run/executor.ts +0 -292
  444. package/src/cli/run/reporter.ts +0 -160
  445. package/src/cli/run-dry-run.test.ts +0 -97
  446. package/src/cli/run-executor-flags.test.ts +0 -38
  447. package/src/cli/run-finish.test.ts +0 -91
  448. package/src/cli/watch.ts +0 -295
  449. package/src/dashboard/astro.config.mjs +0 -6
  450. package/src/dashboard/dist/_astro/index.CADNhRPS.css +0 -1
  451. package/src/dashboard/dist/data/.gitkeep +0 -0
  452. package/src/dashboard/dist/data/convoy-list.json +0 -1
  453. package/src/dashboard/dist/data/overall-stats.json +0 -29
  454. package/src/dashboard/dist/index.html +0 -1963
  455. package/src/dashboard/node_modules/.vite/deps/_metadata.json +0 -31
  456. package/src/dashboard/node_modules/.vite/deps/astro___aria-query.js +0 -6776
  457. package/src/dashboard/node_modules/.vite/deps/astro___aria-query.js.map +0 -7
  458. package/src/dashboard/node_modules/.vite/deps/astro___axobject-query.js +0 -3754
  459. package/src/dashboard/node_modules/.vite/deps/astro___axobject-query.js.map +0 -7
  460. package/src/dashboard/node_modules/.vite/deps/astro___cssesc.js +0 -99
  461. package/src/dashboard/node_modules/.vite/deps/astro___cssesc.js.map +0 -7
  462. package/src/dashboard/node_modules/.vite/deps/chunk-BUSYA2B4.js +0 -8
  463. package/src/dashboard/node_modules/.vite/deps/chunk-BUSYA2B4.js.map +0 -7
  464. package/src/dashboard/node_modules/.vite/deps/package.json +0 -3
  465. package/src/dashboard/package-lock.json +0 -6
  466. package/src/dashboard/public/data/.gitkeep +0 -0
  467. package/src/dashboard/public/data/convoy-list.json +0 -1
  468. package/src/dashboard/public/data/overall-stats.json +0 -29
  469. package/src/dashboard/public/icon-192.png +0 -0
  470. package/src/dashboard/scripts/etl.test.ts +0 -166
  471. package/src/dashboard/scripts/etl.ts +0 -170
  472. package/src/dashboard/scripts/generate-demo-db.test.ts +0 -30
  473. package/src/dashboard/scripts/generate-demo-db.ts +0 -529
  474. package/src/dashboard/scripts/integration-test.ts +0 -504
  475. package/src/dashboard/scripts/verify-demo-data.sh +0 -51
  476. package/src/dashboard/seed-data/delegations.ndjson +0 -35
  477. package/src/dashboard/seed-data/events.ndjson +0 -104
  478. package/src/dashboard/seed-data/panels.ndjson +0 -13
  479. package/src/dashboard/seed-data/reviews.ndjson +0 -6
  480. package/src/dashboard/seed-data/sessions.ndjson +0 -50
  481. package/src/dashboard/src/env.d.ts +0 -1
  482. package/src/dashboard/src/layouts/Layout.astro +0 -25
  483. package/src/dashboard/src/pages/index.astro +0 -2313
  484. package/src/dashboard/src/styles/dashboard.css +0 -2943
  485. package/src/dashboard/tsconfig.json +0 -6
  486. /package/src/{dashboard/dist → cli/dashboard}/icon-192.png +0 -0
@@ -1,391 +1,295 @@
1
+ /**
2
+ * `opencastle convoy dashboard` — the Observability dashboard: a read-only,
3
+ * live view of a project's convoy runs.
4
+ *
5
+ * The page is four files in the package (src/cli/dashboard/: the HTML, its
6
+ * stylesheet, its script and an icon), with no build step, and a JSON API over
7
+ * the read model. Every request opens the database read-only, queries and
8
+ * closes it, so what the page shows is what the store holds now. The dashboard
9
+ * this replaced ran an ETL once at startup into a temp directory and served that
10
+ * snapshot for as long as it stayed up.
11
+ *
12
+ * GET /api/runs runs, newest first, the event categories, and the overview of every run
13
+ * GET /api/runs/:id one run with its tasks, and what its events and side tables add
14
+ * GET /api/runs/:id/events?since=<n> that run's events after cursor n (&limit, at most 2000)
15
+ * GET /api/sessions agent sessions: `opencastle log` records and the engine's own
16
+ */
1
17
  import { createServer } from 'node:http'
2
- import type { IncomingMessage, ServerResponse, Server } from 'node:http'
3
- import { readFile, access } from 'node:fs/promises'
4
- import { mkdtempSync } from 'node:fs'
5
- import { tmpdir } from 'node:os'
6
- import { resolve, join, extname } from 'node:path'
7
- import { execFile } from 'node:child_process'
18
+ import type { IncomingMessage, Server, ServerResponse } from 'node:http'
19
+ import type { AddressInfo } from 'node:net'
20
+ import { existsSync, readFileSync } from 'node:fs'
21
+ import { basename, dirname, join } from 'node:path'
22
+ import { fileURLToPath } from 'node:url'
23
+ import {
24
+ convoyDbPath,
25
+ eventCategories,
26
+ findProjectRoot,
27
+ readAllSessions,
28
+ readEventsSince,
29
+ readOverview,
30
+ readRun,
31
+ readRunInsights,
32
+ readRuns,
33
+ } from './convoy/read-model.js'
34
+ import { openUrl } from './run/platform.js'
35
+ import { nearest } from './nearest.js'
8
36
  import type { CliContext } from './types.js'
9
37
 
10
- const MIME_TYPES: Record<string, string> = {
11
- '.html': 'text/html',
12
- '.css': 'text/css',
13
- '.js': 'application/javascript',
14
- '.json': 'application/json',
15
- '.ndjson': 'application/x-ndjson',
16
- '.png': 'image/png',
17
- '.svg': 'image/svg+xml',
18
- '.ico': 'image/x-icon',
19
- '.woff': 'font/woff',
20
- '.woff2': 'font/woff2',
21
- }
22
-
23
- const DATA_FILES = [
24
- 'events.ndjson',
25
- 'pipelines.ndjson',
26
- // Legacy individual files — kept for backwards compatibility
27
- 'sessions.ndjson',
28
- 'delegations.ndjson',
29
- 'panels.ndjson',
30
- 'reviews.ndjson',
31
- 'disputes.ndjson',
32
- ]
33
-
34
- interface DashboardArgs {
35
- port: number
36
- openBrowser: boolean
37
- seed: boolean
38
- convoyId?: string
39
- help: boolean
40
- }
41
-
42
- export interface DashboardServerOptions {
38
+ const DEFAULT_PORT = 4300
39
+ /** Ports tried after a busy one: 4300 through 4319. */
40
+ const PORT_ATTEMPTS = 20
41
+ const EVENTS_PAGE = 500
42
+ const EVENTS_MAX = 2000
43
+ /** The runs the list carries; the overview counts every run regardless. */
44
+ const RUNS_LISTED = 500
45
+
46
+ export interface DashboardOptions {
47
+ projectRoot: string
48
+ /** 0 asks the OS for a free port. Defaults to 4300, moving up while busy. */
43
49
  port?: number
44
- openBrowser?: boolean
45
- seed?: boolean
46
- pkgRoot: string
47
- convoyId?: string
50
+ open?: boolean
48
51
  }
49
52
 
50
- export interface DashboardServerResult {
51
- server: Server
52
- port: number
53
+ export interface DashboardHandle {
53
54
  url: string
55
+ close(): Promise<void>
54
56
  }
55
57
 
56
- const DASHBOARD_HELP = `
57
- opencastle convoy dashboard [options]
58
-
59
- Start the observability dashboard server.
60
-
61
- Options:
62
- --port <number> Port to listen on (default: 4300, auto-increments if busy)
63
- --no-open Don't auto-open the browser
64
- --seed Show demo data instead of project logs
65
- --convoy <id> Filter dashboard to a specific convoy
66
- --help, -h Show this help
67
- `
68
-
69
- function parseArgs(args: string[]): DashboardArgs {
70
- let port = 4300
71
- let openBrowser = true
72
- let seed = false
73
- let convoyId: string | undefined
74
- let help = false
58
+ /** The page's files, and the only paths served besides the API. */
59
+ export const PAGE_FILES: Readonly<Record<string, string>> = {
60
+ 'index.html': 'text/html; charset=utf-8',
61
+ 'dashboard.css': 'text/css; charset=utf-8',
62
+ 'dashboard.js': 'text/javascript; charset=utf-8',
63
+ 'icon-192.png': 'image/png',
64
+ }
75
65
 
76
- for (let i = 0; i < args.length; i++) {
77
- if (args[i] === '--help' || args[i] === '-h') {
78
- help = true
79
- } else if (args[i] === '--port' && args[i + 1]) {
80
- port = parseInt(args[i + 1], 10)
81
- if (isNaN(port)) { console.error(' ✗ --port requires a valid number'); process.exit(1) }
82
- i++
83
- } else if (args[i] === '--no-open') {
84
- openBrowser = false
85
- } else if (args[i] === '--seed') {
86
- seed = true
87
- } else if (args[i] === '--convoy' && args[i + 1]) {
88
- convoyId = args[i + 1]
89
- if (!convoyId.trim()) { console.error(' ✗ --convoy cannot be empty'); process.exit(1) }
90
- i++
91
- }
66
+ /**
67
+ * The page ships as files in the package. From the TypeScript source they sit
68
+ * beside this module; from the compiled `dist/cli/dashboard.js` they are back
69
+ * in `src/`, which `files` in package.json publishes.
70
+ */
71
+ export function pageDir(): string {
72
+ const here = dirname(fileURLToPath(import.meta.url))
73
+ for (const candidate of [join(here, 'dashboard'), join(here, '..', '..', 'src', 'cli', 'dashboard')]) {
74
+ if (existsSync(join(candidate, 'index.html'))) return candidate
92
75
  }
93
-
94
- return { port, openBrowser, seed, convoyId, help }
76
+ throw new Error('The dashboard page is missing from this installation (src/cli/dashboard/index.html).')
95
77
  }
96
78
 
97
- function openUrl(url: string): void {
98
- const plat = process.platform
99
- const cmd =
100
- plat === 'darwin'
101
- ? 'open'
102
- : plat === 'win32'
103
- ? 'start'
104
- : 'xdg-open'
105
- execFile(cmd, [url])
79
+ /**
80
+ * Same-origin only: the page loads its own script and stylesheet and calls its
81
+ * own API. Inline style attributes carry the chart widths, so styles allow them;
82
+ * scripts do not.
83
+ */
84
+ const CSP = "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; connect-src 'self'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'"
85
+
86
+ function send(res: ServerResponse, status: number, body: unknown, type = 'application/json; charset=utf-8'): void {
87
+ res.writeHead(status, {
88
+ 'Content-Type': type,
89
+ 'Cache-Control': 'no-store',
90
+ 'X-Content-Type-Options': 'nosniff',
91
+ ...(type.startsWith('text/html') ? { 'Content-Security-Policy': CSP } : {}),
92
+ })
93
+ res.end(typeof body === 'string' || Buffer.isBuffer(body) ? body : JSON.stringify(body))
106
94
  }
107
95
 
108
- async function fileExists(filePath: string): Promise<boolean> {
109
- try {
110
- await access(filePath)
111
- return true
112
- } catch {
113
- return false
114
- }
96
+ /**
97
+ * Bound to 127.0.0.1, but a web page elsewhere can still reach it through DNS
98
+ * rebinding: a name it controls re-pointed at 127.0.0.1. The Host header gives
99
+ * that away, so only requests addressed to this machine by name or number are
100
+ * answered.
101
+ */
102
+ function localHost(req: IncomingMessage): boolean {
103
+ const host = (req.headers.host ?? '').replace(/:\d+$/, '').toLowerCase()
104
+ return host === '127.0.0.1' || host === 'localhost' || host === '[::1]'
115
105
  }
116
106
 
117
- function tryListen(
118
- server: Server,
119
- port: number,
120
- maxAttempts = 10
121
- ): Promise<number> {
122
- return new Promise((res, rej) => {
123
- let attempt = 0
124
-
125
- function attemptListen(): void {
126
- const currentPort = port + attempt
107
+ function intParam(url: URL, name: string, fallback: number): number | null {
108
+ const raw = url.searchParams.get(name)
109
+ if (raw === null) return fallback
110
+ return /^\d+$/.test(raw) ? Number(raw) : null
111
+ }
127
112
 
128
- const onError = (err: Error & { code?: string }): void => {
129
- if (err.code === 'EADDRINUSE' && attempt < maxAttempts) {
130
- attempt++
131
- attemptListen()
132
- } else {
133
- rej(err)
113
+ function handler(projectRoot: string, dir: string) {
114
+ return (req: IncomingMessage, res: ServerResponse): void => {
115
+ try {
116
+ if (!localHost(req)) return send(res, 403, { error: 'Forbidden host' })
117
+ if (req.method !== 'GET' && req.method !== 'HEAD') return send(res, 405, { error: 'Read-only' })
118
+ const url = new URL(req.url ?? '/', 'http://127.0.0.1')
119
+ const path = url.pathname
120
+
121
+ // Read on every request, so an edit to the page shows on the next reload.
122
+ const file = path === '/' ? 'index.html' : path.slice(1)
123
+ if (Object.hasOwn(PAGE_FILES, file)) return send(res, 200, readFileSync(join(dir, file)), PAGE_FILES[file])
124
+
125
+ if (path === '/api/runs') {
126
+ return send(res, 200, {
127
+ project: basename(projectRoot),
128
+ runs: readRuns(projectRoot, RUNS_LISTED),
129
+ categories: eventCategories(),
130
+ overview: readOverview(projectRoot),
131
+ })
132
+ }
133
+ if (path === '/api/sessions') return send(res, 200, { sessions: readAllSessions(projectRoot, 50) })
134
+
135
+ const m = /^\/api\/runs\/([^/]+)(\/events)?$/.exec(path)
136
+ if (m) {
137
+ const id = decodeURIComponent(m[1])
138
+ if (m[2]) {
139
+ const since = intParam(url, 'since', 0)
140
+ if (since === null) return send(res, 400, { error: 'since must be a non-negative integer' })
141
+ const limit = intParam(url, 'limit', EVENTS_PAGE)
142
+ if (limit === null || limit < 1 || limit > EVENTS_MAX) return send(res, 400, { error: `limit must be a whole number from 1 to ${EVENTS_MAX}` })
143
+ // One more than asked says whether there is more, without a second query.
144
+ const read = readEventsSince(projectRoot, id, since, limit + 1)
145
+ return send(res, 200, { events: read.slice(0, limit), more: read.length > limit })
134
146
  }
147
+ const run = readRun(projectRoot, id)
148
+ if (!run) return send(res, 404, { error: `No run "${id}" in this project` })
149
+ return send(res, 200, { run, insights: readRunInsights(projectRoot, id) })
135
150
  }
136
-
137
- server.once('error', onError)
138
- server.listen(currentPort, '127.0.0.1', () => {
139
- server.removeListener('error', onError)
140
- res(currentPort)
141
- })
151
+ send(res, 404, { error: 'Not found' })
152
+ } catch (err) {
153
+ send(res, 500, { error: (err as Error).message })
142
154
  }
155
+ }
156
+ }
143
157
 
144
- attemptListen()
158
+ /**
159
+ * Listen on exactly one port and report the one actually bound.
160
+ *
161
+ * Both listeners are removed whichever fires. The old loop left each failed
162
+ * attempt's `listening` callback registered, so after a busy port the first
163
+ * stale callback resolved with the busy port's number, and the URL printed —
164
+ * and opened — pointed at whatever else was listening there.
165
+ */
166
+ function listenOnce(server: Server, port: number): Promise<number> {
167
+ return new Promise((resolvePort, reject) => {
168
+ const onError = (err: Error): void => {
169
+ server.off('listening', onListening)
170
+ reject(err)
171
+ }
172
+ const onListening = (): void => {
173
+ server.off('error', onError)
174
+ resolvePort((server.address() as AddressInfo).port)
175
+ }
176
+ server.once('error', onError)
177
+ server.once('listening', onListening)
178
+ server.listen(port, '127.0.0.1')
145
179
  })
146
180
  }
147
181
 
148
- export async function startDashboardServer(
149
- options: DashboardServerOptions,
150
- ): Promise<DashboardServerResult> {
151
- const port = options.port ?? 4300
152
- const seed = options.seed ?? false
153
- const { pkgRoot } = options
154
-
155
- const distDir = resolve(pkgRoot, 'src', 'dashboard', 'dist')
156
- const seedDir = resolve(pkgRoot, 'src', 'dashboard', 'seed-data')
157
- const projectRoot = process.cwd()
158
- const convoyLogsDir = resolve(projectRoot, '.opencastle', 'logs')
159
-
160
- const runtimeDataDir = seed ? null : mkdtempSync(join(tmpdir(), 'opencastle-dashboard-'))
161
- if (runtimeDataDir) {
182
+ async function listen(server: Server, port: number): Promise<number> {
183
+ const last = port === 0 ? 0 : Math.min(65535, port + PORT_ATTEMPTS - 1)
184
+ for (let p = port; ; p++) {
162
185
  try {
163
- const { runEtl } = await import('../dashboard/scripts/etl.js')
164
- const dbPath = resolve(projectRoot, '.opencastle', 'convoy.db')
165
- await runEtl({ dbPath, outputDir: runtimeDataDir })
166
- } catch {
167
- // ETL failure should not block dashboard — it will serve empty data
186
+ return await listenOnce(server, p)
187
+ } catch (err) {
188
+ if ((err as NodeJS.ErrnoException).code !== 'EADDRINUSE' || p >= last) throw err
168
189
  }
169
190
  }
191
+ }
170
192
 
171
- // Check if dist exists
172
- if (!(await fileExists(distDir))) {
173
- throw new Error(
174
- 'Dashboard not built. Run "npm run dashboard:build" in the opencastle package first.'
175
- )
176
- }
177
-
178
- const server = createServer(
179
- async (req: IncomingMessage, res: ServerResponse) => {
180
- try {
181
- const url = new URL(req.url ?? '/', `http://${req.headers.host}`)
182
- let pathname = decodeURIComponent(url.pathname)
183
-
184
- // Serve index.html for root
185
- if (pathname === '/') {
186
- pathname = '/index.html'
187
- }
188
-
189
- // Handle refresh requests — re-run ETL on demand
190
- if (pathname === '/data/refresh' && runtimeDataDir) {
191
- try {
192
- const { runEtl } = await import('../dashboard/scripts/etl.js')
193
- const dbPath = resolve(projectRoot, '.opencastle', 'convoy.db')
194
- const result = await runEtl({ dbPath, outputDir: runtimeDataDir })
195
- res.writeHead(200, { 'Content-Type': 'application/json' })
196
- res.end(JSON.stringify({ ok: true, convoyCount: result.convoyCount }))
197
- } catch (err) {
198
- res.writeHead(200, { 'Content-Type': 'application/json' })
199
- res.end(JSON.stringify({ ok: true, convoyCount: 0 }))
200
- }
201
- return
202
- }
203
-
204
- // Handle active convoy resolution — queries DB directly (no ETL needed)
205
- if (pathname === '/data/active-convoy.json' && !seed) {
206
- try {
207
- const { createConvoyStore } = await import('./convoy/store.js')
208
- const dbPath = resolve(projectRoot, '.opencastle', 'convoy.db')
209
- const { existsSync } = await import('node:fs')
210
- if (!existsSync(dbPath)) {
211
- res.writeHead(200, { 'Content-Type': 'application/json' })
212
- res.end(JSON.stringify({ convoy: null, pipeline: null }))
213
- return
214
- }
215
- const store = createConvoyStore(dbPath)
216
- try {
217
- // Find the running convoy, or fall back to the latest
218
- const allConvoys = store.getConvoyList(10, 0)
219
- const running = allConvoys.find(c => c.status === 'running')
220
- const pending = allConvoys.find(c => c.status === 'pending')
221
- const target = running ?? pending ?? (allConvoys.length > 0 ? allConvoys[0] : null)
222
-
223
- let pipelineConvoys: Array<{ id: string; name: string; status: string }> | null = null
224
- if (target?.pipeline_id) {
225
- const pipeConvoys = store.getConvoysByPipeline(target.pipeline_id)
226
- pipelineConvoys = pipeConvoys.map(c => ({ id: c.id, name: c.name, status: c.status }))
227
- }
228
-
229
- res.writeHead(200, { 'Content-Type': 'application/json' })
230
- res.end(JSON.stringify({
231
- convoy: target ? { id: target.id, name: target.name, status: target.status, pipeline_id: target.pipeline_id ?? null } : null,
232
- pipeline: pipelineConvoys,
233
- }))
234
- } finally {
235
- store.close()
236
- }
237
- } catch {
238
- res.writeHead(200, { 'Content-Type': 'application/json' })
239
- res.end(JSON.stringify({ convoy: null, pipeline: null }))
240
- }
241
- return
242
- }
243
-
244
- // Handle data file requests — proxy to project logs or dist
245
- const dataMatch = pathname.match(/^\/data\/(.+\.ndjson)$/)
246
- if (dataMatch && DATA_FILES.includes(dataMatch[1])) {
247
- const filename = dataMatch[1]
193
+ function closer(server: Server): () => Promise<void> {
194
+ return () =>
195
+ new Promise((done) => {
196
+ // The page polls with keep-alive; without this, close() waits for those sockets to time out.
197
+ server.closeAllConnections()
198
+ server.close(() => done())
199
+ })
200
+ }
248
201
 
249
- if (seed) {
250
- const filePath = join(seedDir, filename)
251
- if (await fileExists(filePath)) {
252
- const content = await readFile(filePath)
253
- res.writeHead(200, { 'Content-Type': 'application/x-ndjson' })
254
- res.end(content)
255
- } else {
256
- res.writeHead(200, { 'Content-Type': 'application/x-ndjson' })
257
- res.end('')
258
- }
259
- } else {
260
- const convoyPath = join(convoyLogsDir, filename)
261
- res.writeHead(200, { 'Content-Type': 'application/x-ndjson' })
262
- res.end(await fileExists(convoyPath) ? await readFile(convoyPath) : '')
263
- }
264
- return
265
- }
202
+ /** Start the dashboard for one project. Resolves once it is listening. */
203
+ export async function startDashboard(opts: DashboardOptions): Promise<DashboardHandle> {
204
+ const server = createServer(handler(opts.projectRoot, pageDir()))
205
+ const port = await listen(server, opts.port ?? DEFAULT_PORT)
206
+ const url = `http://127.0.0.1:${port}`
207
+ if (opts.open) openUrl(url)
208
+ return { url, close: closer(server) }
209
+ }
266
210
 
267
- // Handle JSON data requests — serve from runtime ETL output or dist
268
- const jsonDataMatch = pathname.match(/^\/data\/(.+\.json)$/)
269
- if (jsonDataMatch) {
270
- const jsonFilename = jsonDataMatch[1]
271
- const dataSource = runtimeDataDir ?? resolve(distDir, 'data')
272
- const jsonPath = resolve(dataSource, jsonFilename)
211
+ // ── command ───────────────────────────────────────────────────────────────────
273
212
 
274
- // Security: prevent path traversal
275
- if (!jsonPath.startsWith(dataSource)) {
276
- res.writeHead(403)
277
- res.end('Forbidden')
278
- return
279
- }
213
+ const HELP = `
214
+ opencastle convoy dashboard [options]
280
215
 
281
- if (await fileExists(jsonPath)) {
282
- const content = await readFile(jsonPath)
283
- res.writeHead(200, { 'Content-Type': 'application/json' })
284
- res.end(content)
285
- } else {
286
- res.writeHead(404)
287
- res.end('Not Found')
288
- }
289
- return
290
- }
216
+ Open the Observability dashboard: a live, read-only view of this project's
217
+ convoy runs. Totals across every run; and for each run its tasks and what
218
+ they wait for, tokens and cost, reviews, checks, retries, failure reasons
219
+ and the event timeline. Every figure is read from .opencastle/convoy.db.
291
220
 
292
- // Serve static files from dist/
293
- const filePath = resolve(distDir, pathname.slice(1))
221
+ Options:
222
+ --port <n> Port to listen on (default ${DEFAULT_PORT}, moving up while busy; 0 picks a free one)
223
+ --no-open Print the URL without opening a browser
224
+ --help, -h Show this help
225
+ `
294
226
 
295
- // Security: prevent path traversal
296
- if (!filePath.startsWith(distDir)) {
297
- res.writeHead(403)
298
- res.end('Forbidden')
299
- return
300
- }
227
+ const FLAGS = ['--port', '--no-open', '--help', '-h']
301
228
 
302
- if (await fileExists(filePath)) {
303
- const ext = extname(filePath)
304
- const contentType = MIME_TYPES[ext] ?? 'application/octet-stream'
305
- const content = await readFile(filePath)
306
- res.writeHead(200, { 'Content-Type': contentType })
307
- res.end(content)
308
- } else {
309
- res.writeHead(404)
310
- res.end('Not Found')
311
- }
312
- } catch {
313
- res.writeHead(500)
314
- res.end('Internal Server Error')
315
- }
229
+ export function parseDashboardArgs(args: string[]): { port: number; open: boolean; help: boolean } | { error: string } {
230
+ let port = DEFAULT_PORT
231
+ let open = true
232
+ let help = false
233
+ for (let i = 0; i < args.length; i++) {
234
+ const arg = args[i]
235
+ if (arg === '--help' || arg === '-h') help = true
236
+ else if (arg === '--no-open') open = false
237
+ else if (arg === '--port') {
238
+ const raw = args[++i]
239
+ if (raw === undefined || raw.startsWith('-')) return { error: '--port needs a number, e.g. --port 4300' }
240
+ port = Number(raw)
241
+ if (!/^\d+$/.test(raw) || port > 65535) return { error: `--port must be a whole number from 0 to 65535, not "${raw}"` }
242
+ } else if (arg.startsWith('-')) {
243
+ const near = nearest(arg, FLAGS)
244
+ return { error: `Unknown option ${arg}. ${near ? `Did you mean ${near}?` : `It accepts ${FLAGS.join(', ')}.`}` }
245
+ } else {
246
+ return { error: `Unexpected argument "${arg}". The dashboard shows every run; pick one on the page.` }
316
247
  }
317
- )
318
-
319
- const actualPort = await tryListen(server, port)
320
- const resolvedUrl = `http://localhost:${actualPort}`
321
-
322
- if (options.openBrowser) {
323
- const fullUrl = options.convoyId ? `${resolvedUrl}/?convoy=${options.convoyId}` : resolvedUrl
324
- openUrl(fullUrl)
325
248
  }
326
-
327
- return { server, port: actualPort, url: resolvedUrl }
249
+ return { port, open, help }
328
250
  }
329
251
 
330
- export default async function dashboard({
331
- pkgRoot,
332
- args,
333
- }: CliContext): Promise<void> {
334
- const { port, openBrowser, seed, convoyId, help } = parseArgs(args)
335
-
336
- if (help) {
337
- console.log(DASHBOARD_HELP)
252
+ export default async function dashboard({ args }: CliContext): Promise<void> {
253
+ const parsed = parseDashboardArgs(args)
254
+ if ('error' in parsed) {
255
+ console.error(` ✗ ${parsed.error}`)
256
+ console.error(' Run "opencastle convoy dashboard --help" for usage.')
257
+ process.exit(1)
258
+ }
259
+ if (parsed.help) {
260
+ console.log(HELP)
338
261
  return
339
262
  }
340
263
 
341
- // Check if any log files exist (for messaging)
342
- let hasLogs = false
343
- if (!seed) {
344
- const projectRoot = process.cwd()
345
- const convoyLogsDir2 = resolve(projectRoot, '.opencastle', 'logs')
346
- for (const f of ['events.ndjson', ...DATA_FILES]) {
347
- if (await fileExists(join(convoyLogsDir2, f))) {
348
- hasLogs = true
349
- break
350
- }
351
- }
264
+ const found = findProjectRoot(process.cwd())
265
+ const projectRoot = found ?? process.cwd()
266
+ let dash: DashboardHandle
267
+ try {
268
+ dash = await startDashboard({ projectRoot, port: parsed.port, open: parsed.open })
269
+ } catch (err) {
270
+ const e = err as NodeJS.ErrnoException
271
+ const why = e.code === 'EADDRINUSE' ? `ports ${parsed.port}–${parsed.port + PORT_ATTEMPTS - 1} are all in use; try --port 0` : e.message
272
+ console.error(` ✗ Could not start the dashboard: ${why}`)
273
+ process.exit(1)
352
274
  }
353
275
 
354
- const dashResult = await startDashboardServer({ port, seed, pkgRoot, convoyId, openBrowser })
355
-
356
276
  console.log('')
357
- console.log(' \u{1F3F0} OpenCastle Dashboard')
358
- console.log('')
359
-
360
- if (convoyId) {
361
- console.log(` \u2192 ${dashResult.url}/?convoy=${convoyId}`)
362
- console.log(` \u{1F4C2} Watching convoy: ${convoyId}`)
363
- } else {
364
- console.log(` \u2192 ${dashResult.url}`)
365
- if (seed) {
366
- console.log(
367
- ' \u{1F4C2} Showing demo data (use without --seed to read project logs)'
368
- )
369
- } else if (hasLogs) {
370
- console.log(' \u{1F4C2} Reading logs from .opencastle/logs/')
371
- } else {
372
- console.log(
373
- ' \u{1F4A1} No agent logs found. Run agents with OpenCastle to generate data, or use --seed for demo data.'
374
- )
375
- }
376
- }
377
-
277
+ console.log(` Dashboard: ${dash.url}`)
278
+ console.log(` Project: ${projectRoot}`)
279
+ if (!found) console.log(' No .opencastle/ here or above; showing this directory, which has no runs.')
280
+ else if (!existsSync(convoyDbPath(projectRoot))) console.log(' No convoy runs yet. They appear on the page as they start.')
378
281
  console.log('')
379
282
  console.log(' Press Ctrl+C to stop')
380
283
  console.log('')
381
284
 
382
- // Graceful shutdown
383
- process.on('SIGINT', () => {
384
- console.log('\n Dashboard stopped.\n')
385
- dashResult.server.close()
386
- process.exit(0)
285
+ await new Promise<void>((done) => {
286
+ const stop = (): void => {
287
+ process.off('SIGINT', stop)
288
+ process.off('SIGTERM', stop)
289
+ void dash.close().then(done)
290
+ }
291
+ process.on('SIGINT', stop)
292
+ process.on('SIGTERM', stop)
387
293
  })
388
-
389
- // Keep the process alive
390
- await new Promise<never>(() => {})
294
+ console.log(' Dashboard stopped.')
391
295
  }