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,190 @@
1
+ import { describe, it, expect, beforeEach, afterEach } from 'vitest';
2
+ import { WorkflowService } from './workflow-service.js';
3
+ import { WorkflowEngine } from '../../shared/workflow-engine.js';
4
+ import { DEFAULT_CONFIG, MINIMAL_CONFIG } from '../../shared/__fixtures__/workflow-configs.js';
5
+ import { createMockEmitter } from '../__tests__/helpers/mock-emitter.js';
6
+ import fs from 'fs';
7
+ import os from 'os';
8
+ import path from 'path';
9
+
10
+ describe('WorkflowService', () => {
11
+ let tmpDir: string;
12
+ let configDir: string;
13
+ let scopesDir: string;
14
+ let defaultConfigPath: string;
15
+ let engine: WorkflowEngine;
16
+ let service: WorkflowService;
17
+
18
+ beforeEach(() => {
19
+ tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'workflow-svc-test-'));
20
+ configDir = path.join(tmpDir, 'config');
21
+ scopesDir = path.join(tmpDir, 'scopes');
22
+ defaultConfigPath = path.join(tmpDir, 'default-workflow.json');
23
+
24
+ fs.mkdirSync(configDir, { recursive: true });
25
+ fs.mkdirSync(scopesDir, { recursive: true });
26
+
27
+ // Write the default workflow config that the constructor reads
28
+ fs.writeFileSync(defaultConfigPath, JSON.stringify(DEFAULT_CONFIG));
29
+
30
+ // Create scope directories for the default workflow
31
+ for (const list of DEFAULT_CONFIG.lists) {
32
+ if (list.hasDirectory) {
33
+ fs.mkdirSync(path.join(scopesDir, list.id), { recursive: true });
34
+ }
35
+ }
36
+
37
+ engine = new WorkflowEngine(DEFAULT_CONFIG);
38
+ service = new WorkflowService(configDir, engine, scopesDir, defaultConfigPath);
39
+ service.setSocketServer(createMockEmitter() as any);
40
+ });
41
+
42
+ afterEach(() => {
43
+ fs.rmSync(tmpDir, { recursive: true, force: true });
44
+ });
45
+
46
+ // ─── validate() ──────────────────────────────────────────
47
+
48
+ describe('validate()', () => {
49
+ it('passes for valid config', () => {
50
+ const result = service.validate(DEFAULT_CONFIG);
51
+ expect(result.valid).toBe(true);
52
+ expect(result.errors).toHaveLength(0);
53
+ });
54
+
55
+ it('fails for invalid config shape', () => {
56
+ const result = service.validate({ version: 2 } as any);
57
+ expect(result.valid).toBe(false);
58
+ expect(result.errors.length).toBeGreaterThan(0);
59
+ });
60
+
61
+ it('fails for duplicate list IDs', () => {
62
+ const config = {
63
+ ...MINIMAL_CONFIG,
64
+ lists: [
65
+ ...MINIMAL_CONFIG.lists,
66
+ { ...MINIMAL_CONFIG.lists[0] }, // duplicate 'todo'
67
+ ],
68
+ };
69
+ const result = service.validate(config);
70
+ expect(result.valid).toBe(false);
71
+ expect(result.errors.some(e => e.toLowerCase().includes('duplicate'))).toBe(true);
72
+ });
73
+
74
+ it('fails for edges referencing non-existent lists', () => {
75
+ const config = {
76
+ ...MINIMAL_CONFIG,
77
+ edges: [
78
+ { from: 'todo', to: 'nonexistent', direction: 'forward' as const, command: null, confirmLevel: 'quick' as const, label: 'X', description: 'X' },
79
+ ],
80
+ };
81
+ const result = service.validate(config);
82
+ expect(result.valid).toBe(false);
83
+ });
84
+
85
+ it('fails for zero entry points', () => {
86
+ const config = {
87
+ ...MINIMAL_CONFIG,
88
+ lists: MINIMAL_CONFIG.lists.map(l => ({ ...l, isEntryPoint: false })),
89
+ };
90
+ const result = service.validate(config);
91
+ expect(result.valid).toBe(false);
92
+ });
93
+ });
94
+
95
+ // ─── getActive() / updateActive() ────────────────────────
96
+
97
+ describe('getActive()', () => {
98
+ it('returns active workflow config', () => {
99
+ const config = service.getActive();
100
+ expect(config.name).toBe(DEFAULT_CONFIG.name);
101
+ expect(config.version).toBe(1);
102
+ });
103
+
104
+ it('strips _defaultDigest from returned config', () => {
105
+ const config = service.getActive() as any;
106
+ expect(config._defaultDigest).toBeUndefined();
107
+ });
108
+ });
109
+
110
+ describe('updateActive()', () => {
111
+ it('updates config and returns valid result', () => {
112
+ const result = service.updateActive(DEFAULT_CONFIG);
113
+ expect(result.valid).toBe(true);
114
+ });
115
+
116
+ it('rejects invalid config', () => {
117
+ const result = service.updateActive({ version: 1, name: 'Bad', lists: [], edges: [] } as any);
118
+ expect(result.valid).toBe(false);
119
+ });
120
+ });
121
+
122
+ // ─── Presets ──────────────────────────────────────────────
123
+
124
+ describe('presets', () => {
125
+ it('savePreset() creates a preset file', () => {
126
+ service.savePreset('test-preset');
127
+ const presets = service.listPresets();
128
+ expect(presets.some(p => p.name === 'test-preset')).toBe(true);
129
+ });
130
+
131
+ it('listPresets() returns all saved presets', () => {
132
+ service.savePreset('preset-a');
133
+ service.savePreset('preset-b');
134
+ const presets = service.listPresets();
135
+ expect(presets.length).toBeGreaterThanOrEqual(2);
136
+ });
137
+
138
+ it('getPreset() loads preset by name', () => {
139
+ service.savePreset('loadable');
140
+ const config = service.getPreset('loadable');
141
+ expect(config.version).toBe(1);
142
+ });
143
+
144
+ it('getPreset() throws for non-existent preset', () => {
145
+ expect(() => service.getPreset('nonexistent')).toThrow();
146
+ });
147
+
148
+ it('deletePreset() removes preset file', () => {
149
+ service.savePreset('to-delete');
150
+ service.deletePreset('to-delete');
151
+ expect(() => service.getPreset('to-delete')).toThrow();
152
+ });
153
+
154
+ it('deletePreset() blocks deletion of "default"', () => {
155
+ expect(() => service.deletePreset('default')).toThrow();
156
+ });
157
+ });
158
+
159
+ // ─── previewMigration() ──────────────────────────────────
160
+
161
+ describe('previewMigration()', () => {
162
+ it('detects removed lists', () => {
163
+ // Preview migrating from DEFAULT_CONFIG (7 lists) to MINIMAL_CONFIG (2 lists)
164
+ const plan = service.previewMigration(MINIMAL_CONFIG);
165
+ expect(plan.removedLists.length).toBeGreaterThan(0);
166
+ });
167
+
168
+ it('returns no-op plan when configs have same lists', () => {
169
+ const plan = service.previewMigration(DEFAULT_CONFIG);
170
+ expect(plan.valid).toBe(true);
171
+ expect(plan.removedLists).toHaveLength(0);
172
+ expect(plan.orphanedScopes).toHaveLength(0);
173
+ });
174
+
175
+ it('returns valid: false for invalid config', () => {
176
+ const plan = service.previewMigration({ version: 1, name: 'Bad', lists: [], edges: [] } as any);
177
+ expect(plan.valid).toBe(false);
178
+ });
179
+ });
180
+
181
+ // ─── getEngine() ─────────────────────────────────────────
182
+
183
+ describe('getEngine()', () => {
184
+ it('returns the active workflow engine', () => {
185
+ const e = service.getEngine();
186
+ expect(e).toBeDefined();
187
+ expect(e.getLists().length).toBeGreaterThan(0);
188
+ });
189
+ });
190
+ });
@@ -1,7 +1,7 @@
1
1
  import crypto from 'crypto';
2
2
  import fs from 'fs';
3
3
  import path from 'path';
4
- import type { Server } from 'socket.io';
4
+ import type { Emitter } from '../project-emitter.js';
5
5
  import type { WorkflowConfig } from '../../shared/workflow-config.js';
6
6
  import { createLogger } from '../utils/logger.js';
7
7
 
@@ -53,7 +53,7 @@ export class WorkflowService {
53
53
  private engine: WorkflowEngine;
54
54
  private defaultConfigPath: string;
55
55
  private manifestPath: string;
56
- private io: Server | null = null;
56
+ private io: Emitter | null = null;
57
57
 
58
58
  constructor(configDir: string, engine: WorkflowEngine, scopesDir: string, defaultConfigPath: string) {
59
59
  this.presetsDir = path.join(configDir, 'workflows');
@@ -81,13 +81,19 @@ export class WorkflowService {
81
81
  this.engine.reload(defaultConfig);
82
82
  fs.writeFileSync(this.manifestPath, this.engine.generateShellManifest(), 'utf-8');
83
83
  } else {
84
- const active = JSON.parse(fs.readFileSync(this.activeConfigPath, 'utf-8')) as WorkflowConfig & { _defaultDigest?: string };
84
+ const active = JSON.parse(fs.readFileSync(this.activeConfigPath, 'utf-8')) as WorkflowConfig & { _defaultDigest?: string; _customized?: boolean };
85
85
  if (!active._defaultDigest) {
86
- // Legacy file without digest marker. If content matches current default, stamp it.
87
- // If different, it's user-customized — leave it alone.
88
86
  if (configDigest(active) === currentDigest) {
87
+ // Exact content match — just stamp it with the digest
89
88
  this.writeWithDigest(this.activeConfigPath, defaultConfig, currentDigest);
89
+ } else if (this.isLikelyOldDefault(active, defaultConfig)) {
90
+ // Same list structure but different edges — old default that needs updating
91
+ log.info('Upgrading legacy workflow config to current default');
92
+ this.writeWithDigest(this.activeConfigPath, defaultConfig, currentDigest);
93
+ this.engine.reload(defaultConfig);
94
+ fs.writeFileSync(this.manifestPath, this.engine.generateShellManifest(), 'utf-8');
90
95
  }
96
+ // else: genuinely user-customized (different list structure), leave alone
91
97
  } else if (active._defaultDigest !== currentDigest) {
92
98
  // Bundled default changed since last sync — refresh + regenerate manifest
93
99
  this.writeWithDigest(this.activeConfigPath, defaultConfig, currentDigest);
@@ -96,13 +102,17 @@ export class WorkflowService {
96
102
  }
97
103
  }
98
104
 
99
- // Always keep the "default" preset in sync with the bundled default
105
+ // Always keep the "default" preset in sync with the bundled default.
106
+ // Copy the raw template bytes to preserve formatting (avoid hash drift from re-serialization).
100
107
  const defaultPresetPath = path.join(this.presetsDir, 'default.json');
101
- const preset = { _preset: { name: 'default', savedAt: new Date().toISOString(), savedFrom: 'bundled' }, ...defaultConfig };
102
- fs.writeFileSync(defaultPresetPath, JSON.stringify(preset, null, 2));
108
+ const templateBytes = fs.readFileSync(this.defaultConfigPath, 'utf-8');
109
+ const existing = fs.existsSync(defaultPresetPath) ? fs.readFileSync(defaultPresetPath, 'utf-8') : '';
110
+ if (existing !== templateBytes) {
111
+ fs.writeFileSync(defaultPresetPath, templateBytes);
112
+ }
103
113
  }
104
114
 
105
- setSocketServer(io: Server): void {
115
+ setSocketServer(io: Emitter): void {
106
116
  this.io = io;
107
117
  }
108
118
 
@@ -110,6 +120,16 @@ export class WorkflowService {
110
120
  return this.engine;
111
121
  }
112
122
 
123
+ /** Check if a legacy config (no digest) is structurally an old default rather than
124
+ * a user customization. If it has the same list IDs in the same order, it was
125
+ * almost certainly seeded from an older version of the bundled default. */
126
+ private isLikelyOldDefault(active: WorkflowConfig, currentDefault: WorkflowConfig): boolean {
127
+ if (active.name !== currentDefault.name) return false;
128
+ const activeListIds = active.lists.map(l => l.id).join(',');
129
+ const defaultListIds = currentDefault.lists.map(l => l.id).join(',');
130
+ return activeListIds === defaultListIds;
131
+ }
132
+
113
133
  // ─── Validation ──────────────────────────────────────
114
134
 
115
135
  validate(config: WorkflowConfig): ValidationResult {
@@ -0,0 +1,359 @@
1
+ /**
2
+ * Bidirectional settings hook sync.
3
+ *
4
+ * Replaces the old additive-only mergeSettingsHooks(). The key improvement:
5
+ * when a hook is removed from the template between versions, it's also
6
+ * removed from settings.local.json — preventing stale registrations
7
+ * pointing to deleted scripts.
8
+ */
9
+
10
+ import fs from 'fs';
11
+ import path from 'path';
12
+ import { hashFile } from './manifest.js';
13
+ import { createLogger } from './utils/logger.js';
14
+ import type { SettingsHooks } from './manifest-types.js';
15
+
16
+ const log = createLogger('sync');
17
+
18
+ // ─── Types ──────────────────────────────────────────────────
19
+
20
+ interface SettingsFile {
21
+ hooks?: SettingsHooks;
22
+ [key: string]: unknown;
23
+ }
24
+
25
+ export interface SettingsSyncResult {
26
+ added: number;
27
+ removed: number;
28
+ updated: number;
29
+ skipped: boolean;
30
+ }
31
+
32
+ // ─── Public API ─────────────────────────────────────────────
33
+
34
+ /**
35
+ * Sync settings.local.json hooks with the current settings-hooks.json template.
36
+ *
37
+ * - Adds new _orbital hooks from the template
38
+ * - Removes _orbital hooks that are no longer in the template
39
+ * - Updates _orbital hooks that have changed (e.g., renamed command paths)
40
+ * - Never touches user hooks (those without _orbital: true)
41
+ *
42
+ * @param settingsPath - Path to .claude/settings.local.json
43
+ * @param templatePath - Path to templates/settings-hooks.json
44
+ * @param previousChecksum - Hash of the template last time sync was run (from manifest)
45
+ * @param renameMap - Optional map of old command paths to new ones
46
+ * @returns Sync result with counts of changes made
47
+ */
48
+ export function syncSettingsHooks(
49
+ settingsPath: string,
50
+ templatePath: string,
51
+ previousChecksum: string,
52
+ renameMap?: Map<string, string>,
53
+ ): SettingsSyncResult {
54
+ if (!fs.existsSync(templatePath)) {
55
+ return { added: 0, removed: 0, updated: 0, skipped: true };
56
+ }
57
+
58
+ // Check if template has changed since last sync
59
+ const currentChecksum = hashFile(templatePath);
60
+ if (currentChecksum === previousChecksum) {
61
+ return { added: 0, removed: 0, updated: 0, skipped: true };
62
+ }
63
+
64
+ // Load current settings
65
+ let settings: SettingsFile = {};
66
+ if (fs.existsSync(settingsPath)) {
67
+ try {
68
+ settings = JSON.parse(fs.readFileSync(settingsPath, 'utf-8'));
69
+ } catch {
70
+ log.warn('Malformed settings file, starting fresh', { path: settingsPath });
71
+ settings = {};
72
+ }
73
+ }
74
+
75
+ // Load template
76
+ const template: SettingsFile = JSON.parse(fs.readFileSync(templatePath, 'utf-8'));
77
+ const templateHooks = template.hooks || {};
78
+
79
+ // Collect all _orbital commands currently in settings
80
+ const currentOrbitalCommands = collectOrbitalCommands(settings.hooks || {});
81
+
82
+ // Collect all commands from the template
83
+ const templateCommands = collectAllCommands(templateHooks);
84
+
85
+ // Build rename map for command paths (from file rename map)
86
+ const commandRenameMap = buildCommandRenameMap(renameMap);
87
+
88
+ let added = 0;
89
+ let removed = 0;
90
+ let updated = 0;
91
+
92
+ // Phase 1: Handle renames in existing _orbital hooks
93
+ if (settings.hooks && commandRenameMap.size > 0) {
94
+ updated += applyCommandRenames(settings.hooks, commandRenameMap);
95
+ }
96
+
97
+ // Phase 2: Remove _orbital hooks that are no longer in the template
98
+ if (settings.hooks) {
99
+ removed += removeStaleHooks(settings.hooks, templateCommands);
100
+ }
101
+
102
+ // Phase 3: Add new hooks from the template
103
+ if (!settings.hooks) settings.hooks = {};
104
+ added += addNewHooks(settings.hooks, templateHooks, currentOrbitalCommands);
105
+
106
+ // Phase 4: Clean up empty groups and events
107
+ cleanupEmptyEntries(settings.hooks);
108
+ if (Object.keys(settings.hooks).length === 0) {
109
+ delete settings.hooks;
110
+ }
111
+
112
+ // Write back
113
+ fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2) + '\n', 'utf-8');
114
+
115
+ return { added, removed, updated, skipped: false };
116
+ }
117
+
118
+ /**
119
+ * Remove all _orbital hooks from settings.local.json.
120
+ * Used during uninstall.
121
+ */
122
+ export function removeAllOrbitalHooks(settingsPath: string): number {
123
+ if (!fs.existsSync(settingsPath)) return 0;
124
+
125
+ let settings: SettingsFile;
126
+ try {
127
+ settings = JSON.parse(fs.readFileSync(settingsPath, 'utf-8'));
128
+ } catch {
129
+ log.debug('Settings unreadable during cleanup', { path: settingsPath });
130
+ return 0;
131
+ }
132
+
133
+ if (!settings.hooks) return 0;
134
+
135
+ let removed = 0;
136
+
137
+ for (const groups of Object.values(settings.hooks)) {
138
+ for (const group of groups) {
139
+ if (!group.hooks) continue;
140
+ const before = group.hooks.length;
141
+ group.hooks = group.hooks.filter(h => !h._orbital);
142
+ removed += before - group.hooks.length;
143
+ }
144
+ }
145
+
146
+ cleanupEmptyEntries(settings.hooks);
147
+ if (Object.keys(settings.hooks).length === 0) {
148
+ delete settings.hooks;
149
+ }
150
+
151
+ fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2) + '\n', 'utf-8');
152
+ return removed;
153
+ }
154
+
155
+ /**
156
+ * Get the current checksum of the settings-hooks.json template.
157
+ */
158
+ export function getTemplateChecksum(templatePath: string): string {
159
+ if (!fs.existsSync(templatePath)) return '';
160
+ return hashFile(templatePath);
161
+ }
162
+
163
+ /**
164
+ * Validate that every _orbital hook in settings.local.json points to a file
165
+ * that exists on disk. Returns list of broken command paths.
166
+ */
167
+ export function validateHookPaths(
168
+ settingsPath: string,
169
+ projectRoot: string,
170
+ ): string[] {
171
+ if (!fs.existsSync(settingsPath)) return [];
172
+
173
+ let settings: SettingsFile;
174
+ try {
175
+ settings = JSON.parse(fs.readFileSync(settingsPath, 'utf-8'));
176
+ } catch {
177
+ return [];
178
+ }
179
+
180
+ if (!settings.hooks) return [];
181
+
182
+ const broken: string[] = [];
183
+
184
+ for (const groups of Object.values(settings.hooks)) {
185
+ for (const group of groups) {
186
+ for (const hook of group.hooks || []) {
187
+ if (!hook._orbital) continue;
188
+
189
+ // Resolve command path — handle $CLAUDE_PROJECT_DIR variable
190
+ const commandPath = hook.command
191
+ .replace(/^"?\$CLAUDE_PROJECT_DIR"?\//, '')
192
+ .replace(/^"/, '')
193
+ .replace(/"$/, '');
194
+
195
+ const absPath = path.join(projectRoot, commandPath);
196
+ if (!fs.existsSync(absPath)) {
197
+ broken.push(hook.command);
198
+ }
199
+ }
200
+ }
201
+ }
202
+
203
+ return broken;
204
+ }
205
+
206
+ // ─── Internal Helpers ───────────────────────────────────────
207
+
208
+ /** Collect all command strings from _orbital hooks in settings. */
209
+ function collectOrbitalCommands(hooks: SettingsHooks): Set<string> {
210
+ const commands = new Set<string>();
211
+ for (const groups of Object.values(hooks)) {
212
+ for (const group of groups) {
213
+ for (const hook of group.hooks || []) {
214
+ if (hook._orbital) commands.add(hook.command);
215
+ }
216
+ }
217
+ }
218
+ return commands;
219
+ }
220
+
221
+ /** Collect all command strings from a hooks template. */
222
+ function collectAllCommands(hooks: SettingsHooks): Set<string> {
223
+ const commands = new Set<string>();
224
+ for (const groups of Object.values(hooks)) {
225
+ for (const group of groups) {
226
+ for (const hook of group.hooks || []) {
227
+ if (hook.command) commands.add(hook.command);
228
+ }
229
+ }
230
+ }
231
+ return commands;
232
+ }
233
+
234
+ /** Build a command-level rename map from a file-level rename map. */
235
+ function buildCommandRenameMap(
236
+ fileRenameMap?: Map<string, string>,
237
+ ): Map<string, string> {
238
+ const commandMap = new Map<string, string>();
239
+ if (!fileRenameMap) return commandMap;
240
+
241
+ for (const [oldFile, newFile] of fileRenameMap) {
242
+ // Hook commands use paths like: "$CLAUDE_PROJECT_DIR"/.claude/hooks/foo.sh
243
+ // We need to detect when oldFile appears in a command and replace with newFile
244
+ if (oldFile.startsWith('hooks/') || oldFile.startsWith('skills/')) {
245
+ const oldSuffix = `.claude/${oldFile}`;
246
+ const newSuffix = `.claude/${newFile}`;
247
+ commandMap.set(oldSuffix, newSuffix);
248
+ }
249
+ }
250
+
251
+ return commandMap;
252
+ }
253
+
254
+ /** Apply command path renames to existing _orbital hooks. Returns count of updates. */
255
+ function applyCommandRenames(
256
+ hooks: SettingsHooks,
257
+ commandRenameMap: Map<string, string>,
258
+ ): number {
259
+ let updated = 0;
260
+
261
+ for (const groups of Object.values(hooks)) {
262
+ for (const group of groups) {
263
+ for (const hook of group.hooks || []) {
264
+ if (!hook._orbital) continue;
265
+
266
+ for (const [oldSuffix, newSuffix] of commandRenameMap) {
267
+ if (hook.command.includes(oldSuffix)) {
268
+ hook.command = hook.command.replace(oldSuffix, newSuffix);
269
+ updated++;
270
+ break;
271
+ }
272
+ }
273
+ }
274
+ }
275
+ }
276
+
277
+ return updated;
278
+ }
279
+
280
+ /** Remove _orbital hooks whose commands are not in the template. Returns count removed. */
281
+ function removeStaleHooks(
282
+ hooks: SettingsHooks,
283
+ templateCommands: Set<string>,
284
+ ): number {
285
+ let removed = 0;
286
+
287
+ for (const groups of Object.values(hooks)) {
288
+ for (const group of groups) {
289
+ if (!group.hooks) continue;
290
+
291
+ const before = group.hooks.length;
292
+ group.hooks = group.hooks.filter(hook => {
293
+ if (!hook._orbital) return true; // Keep user hooks
294
+ return templateCommands.has(hook.command); // Keep if still in template
295
+ });
296
+ removed += before - group.hooks.length;
297
+ }
298
+ }
299
+
300
+ return removed;
301
+ }
302
+
303
+ /** Add hooks from template that aren't already in settings. Returns count added. */
304
+ function addNewHooks(
305
+ settingsHooks: SettingsHooks,
306
+ templateHooks: SettingsHooks,
307
+ existingOrbitalCommands: Set<string>,
308
+ ): number {
309
+ let added = 0;
310
+
311
+ for (const [event, templateGroups] of Object.entries(templateHooks)) {
312
+ if (!settingsHooks[event]) {
313
+ settingsHooks[event] = [];
314
+ }
315
+
316
+ for (const templateGroup of templateGroups) {
317
+ const matcher = templateGroup.matcher || '__none__';
318
+
319
+ // Find matching group in settings
320
+ let targetGroup = settingsHooks[event].find(
321
+ g => (g.matcher || '__none__') === matcher,
322
+ );
323
+
324
+ if (!targetGroup) {
325
+ // Create the group with all hooks tagged
326
+ targetGroup = {
327
+ ...(templateGroup.matcher ? { matcher: templateGroup.matcher } : {}),
328
+ hooks: [],
329
+ };
330
+ settingsHooks[event].push(targetGroup);
331
+ }
332
+
333
+ if (!targetGroup.hooks) targetGroup.hooks = [];
334
+
335
+ for (const hook of templateGroup.hooks || []) {
336
+ if (existingOrbitalCommands.has(hook.command)) continue;
337
+
338
+ // Also check if command already exists (de-dup)
339
+ const alreadyPresent = targetGroup.hooks.some(h => h.command === hook.command);
340
+ if (alreadyPresent) continue;
341
+
342
+ targetGroup.hooks.push({ ...hook, _orbital: true });
343
+ added++;
344
+ }
345
+ }
346
+ }
347
+
348
+ return added;
349
+ }
350
+
351
+ /** Remove empty hook groups and empty event entries. */
352
+ function cleanupEmptyEntries(hooks: SettingsHooks): void {
353
+ for (const [event, groups] of Object.entries(hooks)) {
354
+ hooks[event] = groups.filter(g => g.hooks && g.hooks.length > 0);
355
+ if (hooks[event].length === 0) {
356
+ delete hooks[event];
357
+ }
358
+ }
359
+ }