orbital-command 0.2.0 → 1.0.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 (431) hide show
  1. package/README.md +67 -42
  2. package/bin/commands/config.js +19 -0
  3. package/bin/commands/events.js +40 -0
  4. package/bin/commands/launch.js +126 -0
  5. package/bin/commands/manifest.js +283 -0
  6. package/bin/commands/registry.js +104 -0
  7. package/bin/commands/update.js +24 -0
  8. package/bin/lib/helpers.js +229 -0
  9. package/bin/orbital.js +147 -319
  10. package/dist/assets/Landing-CfQdHR0N.js +11 -0
  11. package/dist/assets/PrimitivesConfig-DThSipFy.js +32 -0
  12. package/dist/assets/QualityGates-B4kxM5UU.js +26 -0
  13. package/dist/assets/SessionTimeline-Bz1iZnmg.js +1 -0
  14. package/dist/assets/Settings-DLcZwbCT.js +12 -0
  15. package/dist/assets/SourceControl-BMNIz7Lt.js +36 -0
  16. package/dist/assets/WorkflowVisualizer-CxuSBOYu.js +69 -0
  17. package/dist/assets/arrow-down-DVPp6_qp.js +6 -0
  18. package/dist/assets/bot-NFaJBDn_.js +6 -0
  19. package/dist/assets/charts-LGLb8hyU.js +68 -0
  20. package/dist/assets/circle-x-IsFCkBZu.js +6 -0
  21. package/dist/assets/file-text-J1cebZXF.js +6 -0
  22. package/dist/assets/globe-WzeyHsUc.js +6 -0
  23. package/dist/assets/index-BdJ57EhC.css +1 -0
  24. package/dist/assets/index-o4ScMAuR.js +349 -0
  25. package/dist/assets/key-CKR8JJSj.js +6 -0
  26. package/dist/assets/minus-CHBsJyjp.js +6 -0
  27. package/dist/assets/radio-xqZaR-Uk.js +6 -0
  28. package/dist/assets/rocket-D_xvvNG6.js +6 -0
  29. package/dist/assets/shield-TdB1yv_a.js +6 -0
  30. package/dist/assets/ui-BmsSg9jU.js +53 -0
  31. package/dist/assets/useSocketListener-0L5yiN5i.js +1 -0
  32. package/dist/assets/useWorkflowEditor-CqeRWVQX.js +11 -0
  33. package/dist/assets/{vendor-Dzv9lrRc.js → vendor-Bqt8AJn2.js} +1 -1
  34. package/dist/assets/workflow-constants-Rw-GmgHZ.js +6 -0
  35. package/dist/assets/zap-C9wqYMpl.js +6 -0
  36. package/dist/favicon.svg +1 -0
  37. package/dist/index.html +6 -5
  38. package/dist/server/server/__tests__/data-routes.test.js +126 -0
  39. package/dist/server/server/__tests__/helpers/db.js +17 -0
  40. package/dist/server/server/__tests__/helpers/mock-emitter.js +8 -0
  41. package/dist/server/server/__tests__/scope-routes.test.js +138 -0
  42. package/dist/server/server/__tests__/sprint-routes.test.js +102 -0
  43. package/dist/server/server/__tests__/workflow-routes.test.js +107 -0
  44. package/dist/server/server/config-migrator.js +135 -0
  45. package/dist/server/server/config.js +51 -7
  46. package/dist/server/server/database.js +21 -28
  47. package/dist/server/server/global-config.js +143 -0
  48. package/dist/server/server/index.js +118 -276
  49. package/dist/server/server/init.js +243 -225
  50. package/dist/server/server/launch.js +29 -0
  51. package/dist/server/server/manifest-types.js +8 -0
  52. package/dist/server/server/manifest.js +454 -0
  53. package/dist/server/server/migrate-legacy.js +229 -0
  54. package/dist/server/server/parsers/event-parser.js +4 -1
  55. package/dist/server/server/parsers/event-parser.test.js +117 -0
  56. package/dist/server/server/parsers/scope-parser.js +74 -28
  57. package/dist/server/server/parsers/scope-parser.test.js +230 -0
  58. package/dist/server/server/project-context.js +265 -0
  59. package/dist/server/server/project-emitter.js +41 -0
  60. package/dist/server/server/project-manager.js +297 -0
  61. package/dist/server/server/routes/aggregate-routes.js +871 -0
  62. package/dist/server/server/routes/config-routes.js +41 -90
  63. package/dist/server/server/routes/data-routes.js +25 -123
  64. package/dist/server/server/routes/dispatch-routes.js +37 -15
  65. package/dist/server/server/routes/git-routes.js +74 -0
  66. package/dist/server/server/routes/manifest-routes.js +319 -0
  67. package/dist/server/server/routes/scope-routes.js +45 -28
  68. package/dist/server/server/routes/sync-routes.js +134 -0
  69. package/dist/server/server/routes/version-routes.js +1 -15
  70. package/dist/server/server/routes/workflow-routes.js +9 -3
  71. package/dist/server/server/schema.js +3 -0
  72. package/dist/server/server/services/batch-orchestrator.js +41 -17
  73. package/dist/server/server/services/claude-session-service.js +17 -14
  74. package/dist/server/server/services/config-service.js +10 -1
  75. package/dist/server/server/services/deploy-service.test.js +119 -0
  76. package/dist/server/server/services/event-service.js +64 -1
  77. package/dist/server/server/services/event-service.test.js +191 -0
  78. package/dist/server/server/services/gate-service.test.js +105 -0
  79. package/dist/server/server/services/git-service.js +108 -4
  80. package/dist/server/server/services/github-service.js +110 -2
  81. package/dist/server/server/services/readiness-service.test.js +190 -0
  82. package/dist/server/server/services/scope-cache.js +5 -1
  83. package/dist/server/server/services/scope-cache.test.js +142 -0
  84. package/dist/server/server/services/scope-service.js +222 -131
  85. package/dist/server/server/services/scope-service.test.js +137 -0
  86. package/dist/server/server/services/sprint-orchestrator.js +29 -15
  87. package/dist/server/server/services/sprint-service.js +23 -3
  88. package/dist/server/server/services/sprint-service.test.js +238 -0
  89. package/dist/server/server/services/sync-service.js +434 -0
  90. package/dist/server/server/services/sync-types.js +2 -0
  91. package/dist/server/server/services/workflow-service.js +26 -5
  92. package/dist/server/server/services/workflow-service.test.js +159 -0
  93. package/dist/server/server/settings-sync.js +284 -0
  94. package/dist/server/server/uninstall.js +195 -0
  95. package/dist/server/server/update-planner.js +279 -0
  96. package/dist/server/server/update.js +212 -0
  97. package/dist/server/server/utils/cc-hooks-parser.js +3 -0
  98. package/dist/server/server/utils/cc-hooks-parser.test.js +86 -0
  99. package/dist/server/server/utils/dispatch-utils.js +83 -24
  100. package/dist/server/server/utils/dispatch-utils.test.js +182 -0
  101. package/dist/server/server/utils/flag-builder.js +54 -0
  102. package/dist/server/server/utils/json-fields.js +14 -0
  103. package/dist/server/server/utils/json-fields.test.js +73 -0
  104. package/dist/server/server/utils/logger.js +37 -3
  105. package/dist/server/server/utils/package-info.js +30 -0
  106. package/dist/server/server/utils/route-helpers.js +47 -0
  107. package/dist/server/server/utils/route-helpers.test.js +115 -0
  108. package/dist/server/server/utils/terminal-launcher.js +79 -25
  109. package/dist/server/server/utils/worktree-manager.js +13 -4
  110. package/dist/server/server/validator.js +230 -0
  111. package/dist/server/server/watchers/event-watcher.js +28 -13
  112. package/dist/server/server/watchers/global-watcher.js +63 -0
  113. package/dist/server/server/watchers/scope-watcher.js +27 -12
  114. package/dist/server/server/wizard/config-editor.js +237 -0
  115. package/dist/server/server/wizard/detect.js +96 -0
  116. package/dist/server/server/wizard/doctor.js +115 -0
  117. package/dist/server/server/wizard/index.js +340 -0
  118. package/dist/server/server/wizard/phases/confirm.js +39 -0
  119. package/dist/server/server/wizard/phases/project-setup.js +90 -0
  120. package/dist/server/server/wizard/phases/setup-wizard.js +66 -0
  121. package/dist/server/server/wizard/phases/welcome.js +32 -0
  122. package/dist/server/server/wizard/phases/workflow-setup.js +22 -0
  123. package/dist/server/server/wizard/types.js +29 -0
  124. package/dist/server/server/wizard/ui.js +73 -0
  125. package/dist/server/shared/__fixtures__/workflow-configs.js +75 -0
  126. package/dist/server/shared/api-types.js +80 -1
  127. package/dist/server/shared/default-workflow.json +65 -0
  128. package/dist/server/shared/onboarding-tour.test.js +81 -0
  129. package/dist/server/shared/project-colors.js +24 -0
  130. package/dist/server/shared/workflow-config.test.js +84 -0
  131. package/dist/server/shared/workflow-engine.js +1 -1
  132. package/dist/server/shared/workflow-engine.test.js +302 -0
  133. package/dist/server/shared/workflow-normalizer.js +101 -0
  134. package/dist/server/shared/workflow-normalizer.test.js +100 -0
  135. package/dist/server/src/components/onboarding/tour-steps.js +84 -0
  136. package/package.json +34 -29
  137. package/schemas/orbital.config.schema.json +2 -5
  138. package/scripts/postinstall.js +18 -6
  139. package/scripts/release.sh +53 -0
  140. package/server/__tests__/data-routes.test.ts +151 -0
  141. package/server/__tests__/helpers/db.ts +19 -0
  142. package/server/__tests__/helpers/mock-emitter.ts +10 -0
  143. package/server/__tests__/scope-routes.test.ts +158 -0
  144. package/server/__tests__/sprint-routes.test.ts +118 -0
  145. package/server/__tests__/workflow-routes.test.ts +120 -0
  146. package/server/config-migrator.ts +160 -0
  147. package/server/config.ts +64 -12
  148. package/server/database.ts +22 -31
  149. package/server/global-config.ts +204 -0
  150. package/server/index.ts +139 -316
  151. package/server/init.ts +266 -234
  152. package/server/launch.ts +32 -0
  153. package/server/manifest-types.ts +145 -0
  154. package/server/manifest.ts +494 -0
  155. package/server/migrate-legacy.ts +290 -0
  156. package/server/parsers/event-parser.test.ts +135 -0
  157. package/server/parsers/event-parser.ts +4 -1
  158. package/server/parsers/scope-parser.test.ts +270 -0
  159. package/server/parsers/scope-parser.ts +79 -31
  160. package/server/project-context.ts +325 -0
  161. package/server/project-emitter.ts +50 -0
  162. package/server/project-manager.ts +368 -0
  163. package/server/routes/aggregate-routes.ts +968 -0
  164. package/server/routes/config-routes.ts +43 -85
  165. package/server/routes/data-routes.ts +34 -156
  166. package/server/routes/dispatch-routes.ts +46 -17
  167. package/server/routes/git-routes.ts +77 -0
  168. package/server/routes/manifest-routes.ts +388 -0
  169. package/server/routes/scope-routes.ts +39 -30
  170. package/server/routes/sync-routes.ts +175 -0
  171. package/server/routes/version-routes.ts +1 -16
  172. package/server/routes/workflow-routes.ts +9 -3
  173. package/server/schema.ts +3 -0
  174. package/server/services/batch-orchestrator.ts +41 -17
  175. package/server/services/claude-session-service.ts +16 -14
  176. package/server/services/config-service.ts +10 -1
  177. package/server/services/deploy-service.test.ts +145 -0
  178. package/server/services/deploy-service.ts +2 -2
  179. package/server/services/event-service.test.ts +242 -0
  180. package/server/services/event-service.ts +92 -3
  181. package/server/services/gate-service.test.ts +131 -0
  182. package/server/services/gate-service.ts +2 -2
  183. package/server/services/git-service.ts +137 -4
  184. package/server/services/github-service.ts +120 -2
  185. package/server/services/readiness-service.test.ts +217 -0
  186. package/server/services/scope-cache.test.ts +167 -0
  187. package/server/services/scope-cache.ts +4 -1
  188. package/server/services/scope-service.test.ts +169 -0
  189. package/server/services/scope-service.ts +224 -130
  190. package/server/services/sprint-orchestrator.ts +30 -15
  191. package/server/services/sprint-service.test.ts +271 -0
  192. package/server/services/sprint-service.ts +29 -5
  193. package/server/services/sync-service.ts +482 -0
  194. package/server/services/sync-types.ts +77 -0
  195. package/server/services/workflow-service.test.ts +190 -0
  196. package/server/services/workflow-service.ts +29 -9
  197. package/server/settings-sync.ts +359 -0
  198. package/server/uninstall.ts +214 -0
  199. package/server/update-planner.ts +346 -0
  200. package/server/update.ts +263 -0
  201. package/server/utils/cc-hooks-parser.test.ts +96 -0
  202. package/server/utils/cc-hooks-parser.ts +4 -0
  203. package/server/utils/dispatch-utils.test.ts +245 -0
  204. package/server/utils/dispatch-utils.ts +102 -30
  205. package/server/utils/flag-builder.ts +56 -0
  206. package/server/utils/json-fields.test.ts +83 -0
  207. package/server/utils/json-fields.ts +14 -0
  208. package/server/utils/logger.ts +40 -3
  209. package/server/utils/package-info.ts +32 -0
  210. package/server/utils/route-helpers.test.ts +144 -0
  211. package/server/utils/route-helpers.ts +50 -0
  212. package/server/utils/terminal-launcher.ts +85 -25
  213. package/server/utils/worktree-manager.ts +9 -4
  214. package/server/validator.ts +270 -0
  215. package/server/watchers/event-watcher.ts +24 -12
  216. package/server/watchers/global-watcher.ts +77 -0
  217. package/server/watchers/scope-watcher.ts +21 -9
  218. package/server/wizard/config-editor.ts +248 -0
  219. package/server/wizard/detect.ts +104 -0
  220. package/server/wizard/doctor.ts +114 -0
  221. package/server/wizard/index.ts +438 -0
  222. package/server/wizard/phases/confirm.ts +45 -0
  223. package/server/wizard/phases/project-setup.ts +106 -0
  224. package/server/wizard/phases/setup-wizard.ts +78 -0
  225. package/server/wizard/phases/welcome.ts +39 -0
  226. package/server/wizard/phases/workflow-setup.ts +28 -0
  227. package/server/wizard/types.ts +56 -0
  228. package/server/wizard/ui.ts +92 -0
  229. package/shared/__fixtures__/workflow-configs.ts +80 -0
  230. package/shared/api-types.ts +106 -0
  231. package/shared/onboarding-tour.test.ts +94 -0
  232. package/shared/project-colors.ts +24 -0
  233. package/shared/workflow-config.test.ts +111 -0
  234. package/shared/workflow-config.ts +7 -0
  235. package/shared/workflow-engine.test.ts +388 -0
  236. package/shared/workflow-engine.ts +1 -1
  237. package/shared/workflow-normalizer.test.ts +119 -0
  238. package/shared/workflow-normalizer.ts +118 -0
  239. package/templates/agents/QUICK-REFERENCE.md +1 -0
  240. package/templates/agents/README.md +1 -0
  241. package/templates/agents/SKILL-TRIGGERS.md +11 -0
  242. package/templates/agents/green-team/deep-dive.md +361 -0
  243. package/templates/hooks/end-session.sh +4 -1
  244. package/templates/hooks/init-session.sh +1 -0
  245. package/templates/hooks/orbital-emit.sh +2 -2
  246. package/templates/hooks/orbital-report-deploy.sh +4 -4
  247. package/templates/hooks/orbital-report-gates.sh +4 -4
  248. package/templates/hooks/orbital-scope-update.sh +1 -1
  249. package/templates/hooks/scope-commit-logger.sh +2 -2
  250. package/templates/hooks/scope-create-cleanup.sh +2 -2
  251. package/templates/hooks/scope-create-gate.sh +2 -5
  252. package/templates/hooks/scope-gate.sh +4 -6
  253. package/templates/hooks/scope-helpers.sh +28 -1
  254. package/templates/hooks/scope-lifecycle-gate.sh +14 -5
  255. package/templates/hooks/scope-prepare.sh +67 -12
  256. package/templates/hooks/scope-transition.sh +14 -6
  257. package/templates/hooks/time-tracker.sh +2 -5
  258. package/templates/migrations/renames.json +1 -0
  259. package/templates/orbital.config.json +8 -6
  260. package/{shared/default-workflow.json → templates/presets/default.json} +65 -0
  261. package/templates/presets/development.json +4 -4
  262. package/templates/presets/gitflow.json +7 -0
  263. package/templates/prompts/README.md +23 -0
  264. package/templates/prompts/deep-dive-audit.md +94 -0
  265. package/templates/quick/rules.md +56 -5
  266. package/templates/settings-hooks.json +1 -1
  267. package/templates/skills/git-commit/SKILL.md +27 -7
  268. package/templates/skills/git-dev/SKILL.md +13 -4
  269. package/templates/skills/git-main/SKILL.md +13 -3
  270. package/templates/skills/git-production/SKILL.md +9 -2
  271. package/templates/skills/git-staging/SKILL.md +11 -3
  272. package/templates/skills/scope-create/SKILL.md +17 -3
  273. package/templates/skills/scope-fix-review/SKILL.md +14 -7
  274. package/templates/skills/scope-implement/SKILL.md +15 -4
  275. package/templates/skills/scope-post-review/SKILL.md +77 -7
  276. package/templates/skills/scope-pre-review/SKILL.md +11 -4
  277. package/templates/skills/scope-verify/SKILL.md +5 -3
  278. package/templates/skills/test-code-review/SKILL.md +41 -33
  279. package/templates/skills/test-scaffold/SKILL.md +222 -0
  280. package/dist/assets/WorkflowVisualizer-BZ21PIIF.js +0 -84
  281. package/dist/assets/charts-D__PA1zp.js +0 -72
  282. package/dist/assets/index-D1G6i0nS.css +0 -1
  283. package/dist/assets/index-DpItvKpf.js +0 -419
  284. package/dist/assets/ui-BvF022GT.js +0 -53
  285. package/index.html +0 -15
  286. package/postcss.config.js +0 -6
  287. package/src/App.tsx +0 -33
  288. package/src/components/AgentBadge.tsx +0 -40
  289. package/src/components/BatchPreflightModal.tsx +0 -115
  290. package/src/components/CardDisplayToggle.tsx +0 -74
  291. package/src/components/ColumnHeaderActions.tsx +0 -55
  292. package/src/components/ColumnMenu.tsx +0 -99
  293. package/src/components/DeployHistory.tsx +0 -141
  294. package/src/components/DispatchModal.tsx +0 -164
  295. package/src/components/DispatchPopover.tsx +0 -139
  296. package/src/components/DragOverlay.tsx +0 -25
  297. package/src/components/DriftSidebar.tsx +0 -140
  298. package/src/components/EnvironmentStrip.tsx +0 -88
  299. package/src/components/ErrorBoundary.tsx +0 -62
  300. package/src/components/FilterChip.tsx +0 -105
  301. package/src/components/GateIndicator.tsx +0 -33
  302. package/src/components/IdeaDetailModal.tsx +0 -190
  303. package/src/components/IdeaFormDialog.tsx +0 -113
  304. package/src/components/KanbanColumn.tsx +0 -201
  305. package/src/components/MarkdownRenderer.tsx +0 -114
  306. package/src/components/NeonGrid.tsx +0 -128
  307. package/src/components/PromotionQueue.tsx +0 -89
  308. package/src/components/ScopeCard.tsx +0 -234
  309. package/src/components/ScopeDetailModal.tsx +0 -255
  310. package/src/components/ScopeFilterBar.tsx +0 -152
  311. package/src/components/SearchInput.tsx +0 -102
  312. package/src/components/SessionPanel.tsx +0 -335
  313. package/src/components/SprintContainer.tsx +0 -303
  314. package/src/components/SprintDependencyDialog.tsx +0 -78
  315. package/src/components/SprintPreflightModal.tsx +0 -138
  316. package/src/components/StatusBar.tsx +0 -168
  317. package/src/components/SwimCell.tsx +0 -67
  318. package/src/components/SwimLaneRow.tsx +0 -94
  319. package/src/components/SwimlaneBoardView.tsx +0 -108
  320. package/src/components/VersionBadge.tsx +0 -139
  321. package/src/components/ViewModeSelector.tsx +0 -114
  322. package/src/components/config/AgentChip.tsx +0 -53
  323. package/src/components/config/AgentCreateDialog.tsx +0 -321
  324. package/src/components/config/AgentEditor.tsx +0 -175
  325. package/src/components/config/DirectoryTree.tsx +0 -582
  326. package/src/components/config/FileEditor.tsx +0 -550
  327. package/src/components/config/HookChip.tsx +0 -50
  328. package/src/components/config/StageCard.tsx +0 -198
  329. package/src/components/config/TransitionZone.tsx +0 -173
  330. package/src/components/config/UnifiedWorkflowPipeline.tsx +0 -216
  331. package/src/components/config/WorkflowPipeline.tsx +0 -161
  332. package/src/components/source-control/BranchList.tsx +0 -93
  333. package/src/components/source-control/BranchPanel.tsx +0 -105
  334. package/src/components/source-control/CommitLog.tsx +0 -100
  335. package/src/components/source-control/CommitRow.tsx +0 -47
  336. package/src/components/source-control/GitHubPanel.tsx +0 -110
  337. package/src/components/source-control/GitHubSetupGuide.tsx +0 -52
  338. package/src/components/source-control/GitOverviewBar.tsx +0 -101
  339. package/src/components/source-control/PullRequestList.tsx +0 -69
  340. package/src/components/source-control/WorktreeList.tsx +0 -80
  341. package/src/components/ui/badge.tsx +0 -41
  342. package/src/components/ui/button.tsx +0 -55
  343. package/src/components/ui/card.tsx +0 -78
  344. package/src/components/ui/dialog.tsx +0 -94
  345. package/src/components/ui/popover.tsx +0 -33
  346. package/src/components/ui/scroll-area.tsx +0 -54
  347. package/src/components/ui/separator.tsx +0 -28
  348. package/src/components/ui/tabs.tsx +0 -52
  349. package/src/components/ui/toggle-switch.tsx +0 -35
  350. package/src/components/ui/tooltip.tsx +0 -27
  351. package/src/components/workflow/AddEdgeDialog.tsx +0 -217
  352. package/src/components/workflow/AddListDialog.tsx +0 -201
  353. package/src/components/workflow/ChecklistEditor.tsx +0 -239
  354. package/src/components/workflow/CommandPrefixManager.tsx +0 -118
  355. package/src/components/workflow/ConfigSettingsPanel.tsx +0 -189
  356. package/src/components/workflow/DirectionSelector.tsx +0 -133
  357. package/src/components/workflow/DispatchConfigPanel.tsx +0 -180
  358. package/src/components/workflow/EdgeDetailPanel.tsx +0 -236
  359. package/src/components/workflow/EdgePropertyEditor.tsx +0 -251
  360. package/src/components/workflow/EditToolbar.tsx +0 -138
  361. package/src/components/workflow/HookDetailPanel.tsx +0 -250
  362. package/src/components/workflow/HookExecutionLog.tsx +0 -24
  363. package/src/components/workflow/HookSourceModal.tsx +0 -129
  364. package/src/components/workflow/HooksDashboard.tsx +0 -363
  365. package/src/components/workflow/ListPropertyEditor.tsx +0 -251
  366. package/src/components/workflow/MigrationPreviewDialog.tsx +0 -237
  367. package/src/components/workflow/MovementRulesPanel.tsx +0 -188
  368. package/src/components/workflow/NodeDetailPanel.tsx +0 -245
  369. package/src/components/workflow/PresetSelector.tsx +0 -414
  370. package/src/components/workflow/SkillCommandBuilder.tsx +0 -174
  371. package/src/components/workflow/WorkflowEdgeComponent.tsx +0 -145
  372. package/src/components/workflow/WorkflowNode.tsx +0 -147
  373. package/src/components/workflow/graphLayout.ts +0 -186
  374. package/src/components/workflow/mergeHooks.ts +0 -85
  375. package/src/components/workflow/useEditHistory.ts +0 -88
  376. package/src/components/workflow/useWorkflowEditor.ts +0 -262
  377. package/src/components/workflow/validateConfig.ts +0 -70
  378. package/src/hooks/useActiveDispatches.ts +0 -198
  379. package/src/hooks/useBoardSettings.ts +0 -170
  380. package/src/hooks/useCardDisplay.ts +0 -57
  381. package/src/hooks/useCcHooks.ts +0 -24
  382. package/src/hooks/useConfigTree.ts +0 -51
  383. package/src/hooks/useEnforcementRules.ts +0 -46
  384. package/src/hooks/useEvents.ts +0 -59
  385. package/src/hooks/useFileEditor.ts +0 -165
  386. package/src/hooks/useGates.ts +0 -57
  387. package/src/hooks/useIdeaActions.ts +0 -53
  388. package/src/hooks/useKanbanDnd.ts +0 -410
  389. package/src/hooks/useOrbitalConfig.ts +0 -54
  390. package/src/hooks/usePipeline.ts +0 -47
  391. package/src/hooks/usePipelineData.ts +0 -338
  392. package/src/hooks/useReconnect.ts +0 -25
  393. package/src/hooks/useScopeFilters.ts +0 -125
  394. package/src/hooks/useScopeSessions.ts +0 -44
  395. package/src/hooks/useScopes.ts +0 -67
  396. package/src/hooks/useSearch.ts +0 -67
  397. package/src/hooks/useSettings.tsx +0 -187
  398. package/src/hooks/useSocket.ts +0 -25
  399. package/src/hooks/useSourceControl.ts +0 -105
  400. package/src/hooks/useSprintPreflight.ts +0 -55
  401. package/src/hooks/useSprints.ts +0 -154
  402. package/src/hooks/useStatusBarHighlight.ts +0 -18
  403. package/src/hooks/useSwimlaneBoardSettings.ts +0 -104
  404. package/src/hooks/useTheme.ts +0 -9
  405. package/src/hooks/useTransitionReadiness.ts +0 -53
  406. package/src/hooks/useVersion.ts +0 -155
  407. package/src/hooks/useViolations.ts +0 -65
  408. package/src/hooks/useWorkflow.tsx +0 -125
  409. package/src/hooks/useZoomModifier.ts +0 -19
  410. package/src/index.css +0 -797
  411. package/src/layouts/DashboardLayout.tsx +0 -113
  412. package/src/lib/collisionDetection.ts +0 -20
  413. package/src/lib/scope-fields.ts +0 -61
  414. package/src/lib/swimlane.ts +0 -146
  415. package/src/lib/utils.ts +0 -15
  416. package/src/main.tsx +0 -19
  417. package/src/socket.ts +0 -11
  418. package/src/types/index.ts +0 -497
  419. package/src/views/AgentFeed.tsx +0 -339
  420. package/src/views/DeployPipeline.tsx +0 -59
  421. package/src/views/EnforcementView.tsx +0 -378
  422. package/src/views/PrimitivesConfig.tsx +0 -500
  423. package/src/views/QualityGates.tsx +0 -1012
  424. package/src/views/ScopeBoard.tsx +0 -454
  425. package/src/views/SessionTimeline.tsx +0 -516
  426. package/src/views/Settings.tsx +0 -183
  427. package/src/views/SourceControl.tsx +0 -95
  428. package/src/views/WorkflowVisualizer.tsx +0 -382
  429. package/tailwind.config.js +0 -161
  430. package/tsconfig.json +0 -25
  431. package/vite.config.ts +0 -38
@@ -0,0 +1,175 @@
1
+ import { Router } from 'express';
2
+ import type { SyncService } from '../services/sync-service.js';
3
+ import type { ProjectManager } from '../project-manager.js';
4
+ import { isValidRelativePath } from '../utils/route-helpers.js';
5
+
6
+ interface SyncRouteDeps {
7
+ syncService: SyncService;
8
+ projectManager: ProjectManager;
9
+ }
10
+
11
+ export function createSyncRoutes({ syncService, projectManager }: SyncRouteDeps): Router {
12
+ const router = Router();
13
+
14
+ // ─── Sync State ─────────────────────────────────────────
15
+
16
+ /** GET /sync/state/:projectId — sync state for a specific project */
17
+ router.get('/sync/state/:projectId', (req, res) => {
18
+ const ctx = projectManager.getContext(req.params.projectId);
19
+ if (!ctx) return res.status(404).json({ error: 'Project not found' });
20
+
21
+ const report = syncService.computeSyncState(ctx.id, ctx.config.projectRoot);
22
+ res.json(report);
23
+ });
24
+
25
+ /** GET /sync/global-state — matrix view across all projects */
26
+ router.get('/sync/global-state', (_req, res) => {
27
+ const report = syncService.computeGlobalSyncState();
28
+ res.json(report);
29
+ });
30
+
31
+ // ─── Override Operations ────────────────────────────────
32
+
33
+ /** POST /sync/override — create an override for a file in a project */
34
+ router.post('/sync/override', (req, res) => {
35
+ const { projectId, relativePath, reason } = req.body as {
36
+ projectId: string; relativePath: string; reason?: string;
37
+ };
38
+ if (!projectId || !relativePath) {
39
+ return res.status(400).json({ error: 'projectId and relativePath required' });
40
+ }
41
+ if (!isValidRelativePath(relativePath)) {
42
+ return res.status(400).json({ error: 'Invalid relativePath' });
43
+ }
44
+
45
+ const ctx = projectManager.getContext(projectId);
46
+ if (!ctx) return res.status(404).json({ error: 'Project not found' });
47
+
48
+ syncService.createOverride(ctx.config.projectRoot, relativePath, reason);
49
+ res.json({ success: true });
50
+ });
51
+
52
+ /** POST /sync/revert — revert an override back to global */
53
+ router.post('/sync/revert', (req, res) => {
54
+ const { projectId, relativePath } = req.body as {
55
+ projectId: string; relativePath: string;
56
+ };
57
+ if (!projectId || !relativePath) {
58
+ return res.status(400).json({ error: 'projectId and relativePath required' });
59
+ }
60
+ if (!isValidRelativePath(relativePath)) {
61
+ return res.status(400).json({ error: 'Invalid relativePath' });
62
+ }
63
+
64
+ const ctx = projectManager.getContext(projectId);
65
+ if (!ctx) return res.status(404).json({ error: 'Project not found' });
66
+
67
+ syncService.revertOverride(ctx.config.projectRoot, relativePath);
68
+ res.json({ success: true });
69
+ });
70
+
71
+ /** POST /sync/promote — promote a project override to global */
72
+ router.post('/sync/promote', (req, res) => {
73
+ const { projectId, relativePath } = req.body as {
74
+ projectId: string; relativePath: string;
75
+ };
76
+ if (!projectId || !relativePath) {
77
+ return res.status(400).json({ error: 'projectId and relativePath required' });
78
+ }
79
+ if (!isValidRelativePath(relativePath)) {
80
+ return res.status(400).json({ error: 'Invalid relativePath' });
81
+ }
82
+
83
+ const ctx = projectManager.getContext(projectId);
84
+ if (!ctx) return res.status(404).json({ error: 'Project not found' });
85
+
86
+ const result = syncService.promoteOverride(ctx.config.projectRoot, relativePath);
87
+ res.json({ success: true, ...result });
88
+ });
89
+
90
+ /** POST /sync/resolve-drift — resolve a drifted file */
91
+ router.post('/sync/resolve-drift', (req, res) => {
92
+ const { projectId, relativePath, resolution } = req.body as {
93
+ projectId: string; relativePath: string; resolution: 'pin-override' | 'reset-global';
94
+ };
95
+ if (!projectId || !relativePath || !resolution) {
96
+ return res.status(400).json({ error: 'projectId, relativePath, and resolution required' });
97
+ }
98
+ if (!isValidRelativePath(relativePath)) {
99
+ return res.status(400).json({ error: 'Invalid relativePath' });
100
+ }
101
+
102
+ const ctx = projectManager.getContext(projectId);
103
+ if (!ctx) return res.status(404).json({ error: 'Project not found' });
104
+
105
+ syncService.resolveDrift(ctx.config.projectRoot, relativePath, resolution);
106
+ res.json({ success: true });
107
+ });
108
+
109
+ // ─── Impact Preview ─────────────────────────────────────
110
+
111
+ /** GET /sync/impact?path=<relativePath> — preview impact of a global change */
112
+ router.get('/sync/impact', (req, res) => {
113
+ const relativePath = req.query.path as string;
114
+ if (!relativePath) {
115
+ return res.status(400).json({ error: 'path query parameter required' });
116
+ }
117
+ if (!isValidRelativePath(relativePath)) {
118
+ return res.status(400).json({ error: 'Invalid path' });
119
+ }
120
+
121
+ const preview = syncService.getImpactPreview(relativePath);
122
+ res.json(preview);
123
+ });
124
+
125
+ // ─── Project Management ─────────────────────────────────
126
+
127
+ /** GET /projects — list all registered projects */
128
+ router.get('/projects', (req, res) => {
129
+ const include = req.query.include as string | undefined;
130
+ res.json(projectManager.getProjectList({
131
+ includeWorkflow: include?.includes('workflow'),
132
+ }));
133
+ });
134
+
135
+ /** POST /projects — register a new project */
136
+ router.post('/projects', async (req, res) => {
137
+ const { path: projectPath, name, color } = req.body as {
138
+ path: string; name?: string; color?: string;
139
+ };
140
+ if (!projectPath) {
141
+ return res.status(400).json({ error: 'path required' });
142
+ }
143
+
144
+ try {
145
+ const summary = await projectManager.addProject(projectPath, { name, color });
146
+ res.status(201).json(summary);
147
+ } catch (err) {
148
+ res.status(500).json({ error: String(err) });
149
+ }
150
+ });
151
+
152
+ /** DELETE /projects/:id — unregister a project */
153
+ router.delete('/projects/:id', async (req, res) => {
154
+ const removed = await projectManager.removeProject(req.params.id);
155
+ if (!removed) return res.status(404).json({ error: 'Project not found' });
156
+ res.json({ success: true });
157
+ });
158
+
159
+ /** PATCH /projects/:id — update project metadata */
160
+ router.patch('/projects/:id', async (req, res) => {
161
+ const { name, color, enabled } = req.body as {
162
+ name?: string; color?: string; enabled?: boolean;
163
+ };
164
+
165
+ if (name !== undefined && !name.trim()) {
166
+ return res.status(400).json({ error: 'Name cannot be empty' });
167
+ }
168
+
169
+ const updated = await projectManager.updateProject(req.params.id, { name, color, enabled });
170
+ if (!updated) return res.status(404).json({ error: 'Project not found' });
171
+ res.json(updated);
172
+ });
173
+
174
+ return router;
175
+ }
@@ -3,9 +3,9 @@ import { execFile } from 'child_process';
3
3
  import { promisify } from 'util';
4
4
  import path from 'path';
5
5
  import fs from 'fs';
6
- import { fileURLToPath } from 'url';
7
6
  import type { Server } from 'socket.io';
8
7
  import { createLogger } from '../utils/logger.js';
8
+ import { getOrbitalRoot } from '../utils/package-info.js';
9
9
 
10
10
  const log = createLogger('version');
11
11
 
@@ -15,21 +15,6 @@ interface VersionRouteDeps {
15
15
  io: Server;
16
16
  }
17
17
 
18
- /** Resolve the root directory of the orbital-command package itself. */
19
- function getOrbitalRoot(): string {
20
- const __selfDir = path.dirname(fileURLToPath(import.meta.url));
21
- // Walk up until we find package.json (handles both dev and compiled paths)
22
- let dir = __selfDir;
23
- for (let i = 0; i < 6; i++) {
24
- if (fs.existsSync(path.join(dir, 'package.json'))) {
25
- return dir;
26
- }
27
- dir = path.dirname(dir);
28
- }
29
- // Fallback: assume dev layout (server/routes/ → 2 levels up)
30
- return path.resolve(__selfDir, '../..');
31
- }
32
-
33
18
  async function git(args: string[], cwd: string, timeoutMs = 15_000): Promise<string> {
34
19
  const { stdout } = await execFileAsync('git', args, { cwd, timeout: timeoutMs });
35
20
  return stdout.trim();
@@ -4,6 +4,7 @@ import path from 'node:path';
4
4
  import type { WorkflowConfig } from '../../shared/workflow-config.js';
5
5
  import type { WorkflowService } from '../services/workflow-service.js';
6
6
  import { parseCcHooks } from '../utils/cc-hooks-parser.js';
7
+ import { errMsg } from '../utils/route-helpers.js';
7
8
 
8
9
  interface WorkflowRouteDeps {
9
10
  workflowService: WorkflowService;
@@ -130,6 +131,10 @@ export function createWorkflowRoutes({ workflowService, projectRoot }: WorkflowR
130
131
  return;
131
132
  }
132
133
  const filePath = path.resolve(projectRoot, hook.target);
134
+ if (!filePath.startsWith(projectRoot + path.sep) && filePath !== projectRoot) {
135
+ res.status(400).json({ success: false, error: 'Path outside project root' });
136
+ return;
137
+ }
133
138
  const content = await readFile(filePath, 'utf-8');
134
139
  const lineCount = content.split('\n').length;
135
140
  res.json({ success: true, data: { hookId, filePath: hook.target, content, lineCount } });
@@ -164,6 +169,10 @@ export function createWorkflowRoutes({ workflowService, projectRoot }: WorkflowR
164
169
  return;
165
170
  }
166
171
  const filePath = path.resolve(projectRoot, hookPath);
172
+ if (!filePath.startsWith(projectRoot + path.sep) && filePath !== projectRoot) {
173
+ res.status(400).json({ success: false, error: 'Path outside project root' });
174
+ return;
175
+ }
167
176
  const content = await readFile(filePath, 'utf-8');
168
177
  const lineCount = content.split('\n').length;
169
178
  res.json({ success: true, data: { filePath: hookPath, content, lineCount } });
@@ -193,6 +202,3 @@ export function createWorkflowRoutes({ workflowService, projectRoot }: WorkflowR
193
202
  return router;
194
203
  }
195
204
 
196
- function errMsg(err: unknown): string {
197
- return err instanceof Error ? err.message : String(err);
198
- }
package/server/schema.ts CHANGED
@@ -81,10 +81,13 @@ CREATE TABLE IF NOT EXISTS sprint_scopes (
81
81
  CREATE INDEX IF NOT EXISTS idx_events_type ON events(type);
82
82
  CREATE INDEX IF NOT EXISTS idx_events_timestamp ON events(timestamp);
83
83
  CREATE INDEX IF NOT EXISTS idx_events_scope_id ON events(scope_id);
84
+ CREATE INDEX IF NOT EXISTS idx_events_type_timestamp ON events(type, timestamp);
84
85
  CREATE INDEX IF NOT EXISTS idx_gates_scope_id ON quality_gates(scope_id);
85
86
  CREATE INDEX IF NOT EXISTS idx_gates_run_at ON quality_gates(run_at);
86
87
  CREATE INDEX IF NOT EXISTS idx_deployments_env ON deployments(environment);
87
88
  CREATE INDEX IF NOT EXISTS idx_sessions_scope ON sessions(scope_id);
89
+ CREATE INDEX IF NOT EXISTS idx_sessions_claude_id ON sessions(claude_session_id);
88
90
  CREATE INDEX IF NOT EXISTS idx_sprints_status ON sprints(status);
89
91
  CREATE INDEX IF NOT EXISTS idx_sprint_scopes_sprint ON sprint_scopes(sprint_id);
92
+ CREATE INDEX IF NOT EXISTS idx_events_dispatch_unresolved ON events(type, scope_id) WHERE type = 'DISPATCH' AND JSON_EXTRACT(data, '$.resolved') IS NULL;
90
93
  `;
@@ -1,11 +1,12 @@
1
1
  import type Database from 'better-sqlite3';
2
- import type { Server } from 'socket.io';
2
+ import type { Emitter } from '../project-emitter.js';
3
3
  import type { SprintService } from './sprint-service.js';
4
4
  import type { ScopeService } from './scope-service.js';
5
- import { launchInCategorizedTerminal, escapeForAnsiC, snapshotSessionPids, discoverNewSession, isSessionPidAlive } from '../utils/terminal-launcher.js';
5
+ import { launchInCategorizedTerminal, escapeForAnsiC, shellQuote, snapshotSessionPids, discoverNewSession, isSessionPidAlive } from '../utils/terminal-launcher.js';
6
6
  import { linkPidToDispatch, resolveDispatchEvent } from '../utils/dispatch-utils.js';
7
7
  import type { WorkflowEngine } from '../../shared/workflow-engine.js';
8
- import { getConfig } from '../config.js';
8
+ import type { OrbitalConfig } from '../config.js';
9
+ import { buildClaudeFlags, buildEnvVarPrefix } from '../utils/flag-builder.js';
9
10
  import { createLogger } from '../utils/logger.js';
10
11
 
11
12
  const log = createLogger('batch');
@@ -16,10 +17,12 @@ const VALID_MERGE_MODES = ['push', 'pr'] as const;
16
17
  export class BatchOrchestrator {
17
18
  constructor(
18
19
  private db: Database.Database,
19
- private io: Server,
20
+ private io: Emitter,
20
21
  private sprintService: SprintService,
21
22
  private scopeService: ScopeService,
22
23
  private engine: WorkflowEngine,
24
+ private projectRoot: string,
25
+ private config: OrbitalConfig,
23
26
  ) {}
24
27
 
25
28
  /** Dispatch a batch — validates constraints and routes to column-specific handler */
@@ -70,8 +73,10 @@ export class BatchOrchestrator {
70
73
 
71
74
  // Launch single CLI session with BATCH_SCOPE_IDS prepended to command
72
75
  const escaped = escapeForAnsiC(command);
73
- const fullCmd = `cd '${getConfig().projectRoot}' && BATCH_SCOPE_IDS='${scopeIdsStr}' MERGE_MODE='${mergeModeStr}' claude --dangerously-skip-permissions $'${escaped}'`;
74
- const beforePids = snapshotSessionPids(getConfig().projectRoot);
76
+ const flagsStr = buildClaudeFlags(this.config.claude.dispatchFlags);
77
+ const envPrefix = buildEnvVarPrefix(this.config.dispatch.envVars);
78
+ const fullCmd = `cd '${shellQuote(this.projectRoot)}' && ${envPrefix}ORBITAL_DISPATCH_ID='${shellQuote(eventId)}' BATCH_SCOPE_IDS='${scopeIdsStr}' MERGE_MODE='${mergeModeStr}' claude ${flagsStr} $'${escaped}'`;
79
+ const beforePids = snapshotSessionPids(this.projectRoot);
75
80
 
76
81
  try {
77
82
  await launchInCategorizedTerminal(command, fullCmd);
@@ -82,7 +87,7 @@ export class BatchOrchestrator {
82
87
  });
83
88
 
84
89
  // Fire-and-forget: discover session PID and link to dispatch
85
- discoverNewSession(getConfig().projectRoot, beforePids)
90
+ discoverNewSession(this.projectRoot, beforePids)
86
91
  .then((session) => {
87
92
  if (!session) return;
88
93
  linkPidToDispatch(this.db, eventId, session.pid);
@@ -106,7 +111,7 @@ export class BatchOrchestrator {
106
111
  } catch (err) {
107
112
  this.sprintService.updateStatus(batchId, 'failed');
108
113
  resolveDispatchEvent(this.db, this.io, eventId, 'failed', String(err));
109
- return { ok: false, error: `Failed to launch terminal: ${err}` };
114
+ return { ok: false, error: `Failed to launch terminal: ${err instanceof Error ? err.message : String(err)}` };
110
115
  }
111
116
  }
112
117
 
@@ -148,6 +153,17 @@ export class BatchOrchestrator {
148
153
  if (batch.status !== 'dispatched' && batch.status !== 'in_progress') return;
149
154
 
150
155
  const scopes = this.sprintService.getSprintScopes(batchId);
156
+
157
+ // If batch never reached 'in_progress', the session never started —
158
+ // don't credit any scope regardless of their current workflow status
159
+ if (batch.status === 'dispatched') {
160
+ this.sprintService.updateStatus(batchId, 'failed');
161
+ for (const ss of scopes) {
162
+ this.sprintService.updateScopeStatus(batchId, ss.scope_id, 'failed', 'Session never started');
163
+ }
164
+ return;
165
+ }
166
+
151
167
  const allTransitioned = scopes.every((ss) => ss.dispatch_status === 'completed');
152
168
 
153
169
  if (allTransitioned) {
@@ -210,16 +226,24 @@ export class BatchOrchestrator {
210
226
  let pidDead = false;
211
227
 
212
228
  if (dispatchEvent) {
213
- const data = JSON.parse(dispatchEvent.data) as Record<string, unknown>;
214
- // If the dispatch event is already resolved, the session is definitely done
215
- if (data.resolved != null) {
229
+ let data: Record<string, unknown>;
230
+ try {
231
+ data = JSON.parse(dispatchEvent.data) as Record<string, unknown>;
232
+ } catch {
216
233
  pidDead = true;
217
- } else if (typeof data.pid === 'number') {
218
- pidDead = !isSessionPidAlive(data.pid);
219
- } else {
220
- // No PID recorded check if batch is old enough to consider stale
221
- const dispatchedAt = batch.dispatched_at ? new Date(batch.dispatched_at).getTime() : 0;
222
- pidDead = Date.now() - dispatchedAt > STALE_THRESHOLD_MS;
234
+ // Fall through to resolution below
235
+ }
236
+ if (!pidDead) {
237
+ // If the dispatch event is already resolved, the session is definitely done
238
+ if (data!.resolved != null) {
239
+ pidDead = true;
240
+ } else if (typeof data!.pid === 'number') {
241
+ pidDead = !isSessionPidAlive(data!.pid);
242
+ } else {
243
+ // No PID recorded — check if batch is old enough to consider stale
244
+ const dispatchedAt = batch.dispatched_at ? new Date(batch.dispatched_at).getTime() : 0;
245
+ pidDead = Date.now() - dispatchedAt > STALE_THRESHOLD_MS;
246
+ }
223
247
  }
224
248
  } else {
225
249
  // No dispatch event at all — check age
@@ -3,7 +3,7 @@ import path from 'path';
3
3
  import readline from 'readline';
4
4
  import type Database from 'better-sqlite3';
5
5
  import type { ScopeService } from './scope-service.js';
6
- import { getConfig, getClaudeSessionsDir } from '../config.js';
6
+ import { getClaudeSessionsDir } from '../config.js';
7
7
 
8
8
  export interface ClaudeSession {
9
9
  id: string;
@@ -59,11 +59,12 @@ export interface SessionStats {
59
59
  };
60
60
  }
61
61
 
62
- function getSessionsDir(): string {
63
- return getClaudeSessionsDir(getConfig().projectRoot);
62
+ function getSessionsDir(projectRoot?: string): string {
63
+ if (!projectRoot) throw new Error('projectRoot is required for getSessionsDir');
64
+ return getClaudeSessionsDir(projectRoot);
64
65
  }
65
66
 
66
- let cache: { sessions: ClaudeSession[]; expiry: number } | null = null;
67
+ const cacheByDir = new Map<string, { sessions: ClaudeSession[]; expiry: number }>();
67
68
  const CACHE_TTL_MS = 60_000;
68
69
 
69
70
  /**
@@ -146,12 +147,13 @@ async function parseSessionFile(filePath: string): Promise<ClaudeSession | null>
146
147
  };
147
148
  }
148
149
 
149
- export async function getClaudeSessions(since?: string): Promise<ClaudeSession[]> {
150
- if (cache && Date.now() < cache.expiry) {
151
- return filterSince(cache.sessions, since);
150
+ export async function getClaudeSessions(since?: string, projectRoot?: string): Promise<ClaudeSession[]> {
151
+ const sessionsDir = getSessionsDir(projectRoot);
152
+ const cached = cacheByDir.get(sessionsDir);
153
+ if (cached && Date.now() < cached.expiry) {
154
+ return filterSince(cached.sessions, since);
152
155
  }
153
156
 
154
- const sessionsDir = getSessionsDir();
155
157
  if (!fs.existsSync(sessionsDir)) return [];
156
158
 
157
159
  const files = fs
@@ -171,7 +173,7 @@ export async function getClaudeSessions(since?: string): Promise<ClaudeSession[]
171
173
  (a, b) => new Date(b.lastActiveAt).getTime() - new Date(a.lastActiveAt).getTime(),
172
174
  );
173
175
 
174
- cache = { sessions, expiry: Date.now() + CACHE_TTL_MS };
176
+ cacheByDir.set(sessionsDir, { sessions, expiry: Date.now() + CACHE_TTL_MS });
175
177
  return filterSince(sessions, since);
176
178
  }
177
179
 
@@ -248,8 +250,8 @@ function extractFirstUserMessage(lines: string[], max: number): string | null {
248
250
  * Parse a full JSONL file and return detailed stats grouped by line type.
249
251
  * This is heavier than parseSessionFile — only called for the detail view.
250
252
  */
251
- export function getSessionStats(claudeSessionId: string): SessionStats | null {
252
- const filePath = path.join(getSessionsDir(), `${claudeSessionId}.jsonl`);
253
+ export function getSessionStats(claudeSessionId: string, projectRoot?: string): SessionStats | null {
254
+ const filePath = path.join(getSessionsDir(projectRoot), `${claudeSessionId}.jsonl`);
253
255
  if (!fs.existsSync(filePath)) return null;
254
256
 
255
257
  const stats: SessionStats = {
@@ -360,8 +362,8 @@ export function getSessionStats(claudeSessionId: string): SessionStats | null {
360
362
  * 2. For each scope, parse the sessions JSON: Record<phase, uuid[]>
361
363
  * 3. For each (phase, uuid), UPSERT into sessions table with JSONL metadata if available
362
364
  */
363
- export async function syncClaudeSessionsToDB(db: Database.Database, scopeService: ScopeService): Promise<number> {
364
- cache = null; // Force fresh read from filesystem
365
+ export async function syncClaudeSessionsToDB(db: Database.Database, scopeService: ScopeService, projectRoot?: string): Promise<number> {
366
+ cacheByDir.clear(); // Force fresh read from filesystem
365
367
 
366
368
  const scopeRows = scopeService.getAll()
367
369
  .filter(s => Object.keys(s.sessions).length > 0)
@@ -389,7 +391,7 @@ export async function syncClaudeSessionsToDB(db: Database.Database, scopeService
389
391
  if (typeof uuid !== 'string' || !uuid) continue;
390
392
 
391
393
  // Check if JSONL file exists for metadata enrichment
392
- const jsonlPath = path.join(getSessionsDir(), `${uuid}.jsonl`);
394
+ const jsonlPath = path.join(getSessionsDir(projectRoot), `${uuid}.jsonl`);
393
395
  let startedAt: string | null = null;
394
396
  let endedAt: string | null = null;
395
397
  let summary: string | null = null;
@@ -120,7 +120,16 @@ export class ConfigService {
120
120
  const fullPath = path.join(currentPath, entry.name);
121
121
  const relPath = path.relative(basePath, fullPath);
122
122
 
123
- if (entry.isDirectory()) {
123
+ // Resolve symlinks: Dirent.isDirectory() returns false for symlinks-to-dirs.
124
+ // Self-hosted projects symlink .claude/agents/*, .claude/hooks/*, etc. into templates/.
125
+ let stat: fs.Stats;
126
+ try {
127
+ stat = fs.statSync(fullPath);
128
+ } catch {
129
+ continue; // broken symlink — skip silently
130
+ }
131
+
132
+ if (stat.isDirectory()) {
124
133
  const children = this.walkDir(fullPath, basePath, parseFrontmatter);
125
134
  nodes.push({ name: entry.name, path: relPath, type: 'folder', children });
126
135
  } else {
@@ -0,0 +1,145 @@
1
+ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
2
+ import { DeployService } from './deploy-service.js';
3
+ import { createTestDb } from '../__tests__/helpers/db.js';
4
+ import { createMockEmitter } from '../__tests__/helpers/mock-emitter.js';
5
+ import type Database from 'better-sqlite3';
6
+ import type { Emitter } from '../project-emitter.js';
7
+
8
+ describe('DeployService', () => {
9
+ let db: Database.Database;
10
+ let cleanup: () => void;
11
+ let emitter: Emitter & { emit: ReturnType<typeof vi.fn> };
12
+ let service: DeployService;
13
+
14
+ beforeEach(() => {
15
+ ({ db, cleanup } = createTestDb());
16
+ emitter = createMockEmitter();
17
+ service = new DeployService(db, emitter);
18
+ });
19
+
20
+ afterEach(() => {
21
+ cleanup?.();
22
+ });
23
+
24
+ // ─── record() ─────────────────────────────────────────────
25
+
26
+ describe('record()', () => {
27
+ it('inserts deployment and returns ID', () => {
28
+ const id = service.record({
29
+ environment: 'staging',
30
+ status: 'deploying',
31
+ commit_sha: 'abc1234',
32
+ branch: 'main',
33
+ pr_number: null,
34
+ health_check_url: null,
35
+ details: null,
36
+ });
37
+
38
+ expect(id).toBe(1);
39
+ const row = db.prepare('SELECT * FROM deployments WHERE id = ?').get(id) as Record<string, unknown>;
40
+ expect(row.environment).toBe('staging');
41
+ expect(row.status).toBe('deploying');
42
+ });
43
+
44
+ it('emits deploy:updated with inserted row', () => {
45
+ service.record({
46
+ environment: 'production',
47
+ status: 'deploying',
48
+ commit_sha: 'def5678',
49
+ branch: 'main',
50
+ pr_number: 42,
51
+ health_check_url: 'https://example.com/health',
52
+ details: { version: '1.0.0' },
53
+ });
54
+
55
+ expect(emitter.emit).toHaveBeenCalledWith('deploy:updated', expect.objectContaining({
56
+ environment: 'production',
57
+ branch: 'main',
58
+ pr_number: 42,
59
+ }));
60
+ });
61
+ });
62
+
63
+ // ─── updateStatus() ──────────────────────────────────────
64
+
65
+ describe('updateStatus()', () => {
66
+ let deployId: number;
67
+
68
+ beforeEach(() => {
69
+ deployId = service.record({
70
+ environment: 'staging',
71
+ status: 'deploying',
72
+ commit_sha: 'abc',
73
+ branch: 'main',
74
+ pr_number: null,
75
+ health_check_url: null,
76
+ details: null,
77
+ });
78
+ });
79
+
80
+ it('updates status and emits deploy:updated', () => {
81
+ service.updateStatus(deployId, 'healthy');
82
+
83
+ const row = db.prepare('SELECT * FROM deployments WHERE id = ?').get(deployId) as Record<string, unknown>;
84
+ expect(row.status).toBe('healthy');
85
+ // 1 from record + 1 from updateStatus
86
+ expect(emitter.emit).toHaveBeenCalledTimes(2);
87
+ });
88
+
89
+ it('sets completed_at for terminal status: healthy', () => {
90
+ service.updateStatus(deployId, 'healthy');
91
+ const row = db.prepare('SELECT completed_at FROM deployments WHERE id = ?').get(deployId) as { completed_at: string | null };
92
+ expect(row.completed_at).not.toBeNull();
93
+ expect(row.completed_at).toMatch(/^\d{4}-\d{2}-\d{2}T/);
94
+ });
95
+
96
+ it('sets completed_at for terminal status: failed', () => {
97
+ service.updateStatus(deployId, 'failed');
98
+ const row = db.prepare('SELECT completed_at FROM deployments WHERE id = ?').get(deployId) as { completed_at: string | null };
99
+ expect(row.completed_at).not.toBeNull();
100
+ });
101
+
102
+ it('sets completed_at for terminal status: rolled-back', () => {
103
+ service.updateStatus(deployId, 'rolled-back');
104
+ const row = db.prepare('SELECT completed_at FROM deployments WHERE id = ?').get(deployId) as { completed_at: string | null };
105
+ expect(row.completed_at).not.toBeNull();
106
+ });
107
+
108
+ it('does not set completed_at for non-terminal status', () => {
109
+ service.updateStatus(deployId, 'deploying');
110
+ const row = db.prepare('SELECT completed_at FROM deployments WHERE id = ?').get(deployId) as { completed_at: string | null };
111
+ expect(row.completed_at).toBeNull();
112
+ });
113
+ });
114
+
115
+ // ─── getRecent() ──────────────────────────────────────────
116
+
117
+ describe('getRecent()', () => {
118
+ it('returns deployments ordered by started_at DESC with limit', () => {
119
+ service.record({ environment: 'staging', status: 'healthy', commit_sha: 'a', branch: 'main', pr_number: null, health_check_url: null, details: null });
120
+ service.record({ environment: 'production', status: 'deploying', commit_sha: 'b', branch: 'main', pr_number: null, health_check_url: null, details: null });
121
+
122
+ const recent = service.getRecent(1);
123
+ expect(recent).toHaveLength(1);
124
+ });
125
+ });
126
+
127
+ // ─── getLatestPerEnv() ────────────────────────────────────
128
+
129
+ describe('getLatestPerEnv()', () => {
130
+ it('returns one deployment per environment', () => {
131
+ service.record({ environment: 'staging', status: 'healthy', commit_sha: 'a', branch: 'main', pr_number: null, health_check_url: null, details: null });
132
+ service.record({ environment: 'staging', status: 'deploying', commit_sha: 'b', branch: 'main', pr_number: null, health_check_url: null, details: null });
133
+ service.record({ environment: 'production', status: 'healthy', commit_sha: 'c', branch: 'main', pr_number: null, health_check_url: null, details: null });
134
+
135
+ const latest = service.getLatestPerEnv();
136
+ expect(latest).toHaveLength(2);
137
+ const envs = latest.map(d => d.environment).sort();
138
+ expect(envs).toEqual(['production', 'staging']);
139
+ });
140
+
141
+ it('returns empty when no deployments exist', () => {
142
+ expect(service.getLatestPerEnv()).toEqual([]);
143
+ });
144
+ });
145
+ });
@@ -1,5 +1,5 @@
1
1
  import type Database from 'better-sqlite3';
2
- import type { Server } from 'socket.io';
2
+ import type { Emitter } from '../project-emitter.js';
3
3
  import type { DeployStatus, DeployEnvironment } from '../../shared/api-types.js';
4
4
  import { createLogger } from '../utils/logger.js';
5
5
 
@@ -31,7 +31,7 @@ export interface DeployRow {
31
31
  export class DeployService {
32
32
  constructor(
33
33
  private db: Database.Database,
34
- private io: Server
34
+ private io: Emitter
35
35
  ) {}
36
36
 
37
37
  /** Record a deployment event */