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.
- package/README.md +67 -42
- package/bin/commands/config.js +19 -0
- package/bin/commands/events.js +40 -0
- package/bin/commands/launch.js +126 -0
- package/bin/commands/manifest.js +283 -0
- package/bin/commands/registry.js +104 -0
- package/bin/commands/update.js +24 -0
- package/bin/lib/helpers.js +229 -0
- package/bin/orbital.js +147 -319
- package/dist/assets/Landing-CfQdHR0N.js +11 -0
- package/dist/assets/PrimitivesConfig-DThSipFy.js +32 -0
- package/dist/assets/QualityGates-B4kxM5UU.js +26 -0
- package/dist/assets/SessionTimeline-Bz1iZnmg.js +1 -0
- package/dist/assets/Settings-DLcZwbCT.js +12 -0
- package/dist/assets/SourceControl-BMNIz7Lt.js +36 -0
- package/dist/assets/WorkflowVisualizer-CxuSBOYu.js +69 -0
- package/dist/assets/arrow-down-DVPp6_qp.js +6 -0
- package/dist/assets/bot-NFaJBDn_.js +6 -0
- package/dist/assets/charts-LGLb8hyU.js +68 -0
- package/dist/assets/circle-x-IsFCkBZu.js +6 -0
- package/dist/assets/file-text-J1cebZXF.js +6 -0
- package/dist/assets/globe-WzeyHsUc.js +6 -0
- package/dist/assets/index-BdJ57EhC.css +1 -0
- package/dist/assets/index-o4ScMAuR.js +349 -0
- package/dist/assets/key-CKR8JJSj.js +6 -0
- package/dist/assets/minus-CHBsJyjp.js +6 -0
- package/dist/assets/radio-xqZaR-Uk.js +6 -0
- package/dist/assets/rocket-D_xvvNG6.js +6 -0
- package/dist/assets/shield-TdB1yv_a.js +6 -0
- package/dist/assets/ui-BmsSg9jU.js +53 -0
- package/dist/assets/useSocketListener-0L5yiN5i.js +1 -0
- package/dist/assets/useWorkflowEditor-CqeRWVQX.js +11 -0
- package/dist/assets/{vendor-Dzv9lrRc.js → vendor-Bqt8AJn2.js} +1 -1
- package/dist/assets/workflow-constants-Rw-GmgHZ.js +6 -0
- package/dist/assets/zap-C9wqYMpl.js +6 -0
- package/dist/favicon.svg +1 -0
- package/dist/index.html +6 -5
- package/dist/server/server/__tests__/data-routes.test.js +126 -0
- package/dist/server/server/__tests__/helpers/db.js +17 -0
- package/dist/server/server/__tests__/helpers/mock-emitter.js +8 -0
- package/dist/server/server/__tests__/scope-routes.test.js +138 -0
- package/dist/server/server/__tests__/sprint-routes.test.js +102 -0
- package/dist/server/server/__tests__/workflow-routes.test.js +107 -0
- package/dist/server/server/config-migrator.js +135 -0
- package/dist/server/server/config.js +51 -7
- package/dist/server/server/database.js +21 -28
- package/dist/server/server/global-config.js +143 -0
- package/dist/server/server/index.js +118 -276
- package/dist/server/server/init.js +243 -225
- package/dist/server/server/launch.js +29 -0
- package/dist/server/server/manifest-types.js +8 -0
- package/dist/server/server/manifest.js +454 -0
- package/dist/server/server/migrate-legacy.js +229 -0
- package/dist/server/server/parsers/event-parser.js +4 -1
- package/dist/server/server/parsers/event-parser.test.js +117 -0
- package/dist/server/server/parsers/scope-parser.js +74 -28
- package/dist/server/server/parsers/scope-parser.test.js +230 -0
- package/dist/server/server/project-context.js +265 -0
- package/dist/server/server/project-emitter.js +41 -0
- package/dist/server/server/project-manager.js +297 -0
- package/dist/server/server/routes/aggregate-routes.js +871 -0
- package/dist/server/server/routes/config-routes.js +41 -90
- package/dist/server/server/routes/data-routes.js +25 -123
- package/dist/server/server/routes/dispatch-routes.js +37 -15
- package/dist/server/server/routes/git-routes.js +74 -0
- package/dist/server/server/routes/manifest-routes.js +319 -0
- package/dist/server/server/routes/scope-routes.js +45 -28
- package/dist/server/server/routes/sync-routes.js +134 -0
- package/dist/server/server/routes/version-routes.js +1 -15
- package/dist/server/server/routes/workflow-routes.js +9 -3
- package/dist/server/server/schema.js +3 -0
- package/dist/server/server/services/batch-orchestrator.js +41 -17
- package/dist/server/server/services/claude-session-service.js +17 -14
- package/dist/server/server/services/config-service.js +10 -1
- package/dist/server/server/services/deploy-service.test.js +119 -0
- package/dist/server/server/services/event-service.js +64 -1
- package/dist/server/server/services/event-service.test.js +191 -0
- package/dist/server/server/services/gate-service.test.js +105 -0
- package/dist/server/server/services/git-service.js +108 -4
- package/dist/server/server/services/github-service.js +110 -2
- package/dist/server/server/services/readiness-service.test.js +190 -0
- package/dist/server/server/services/scope-cache.js +5 -1
- package/dist/server/server/services/scope-cache.test.js +142 -0
- package/dist/server/server/services/scope-service.js +222 -131
- package/dist/server/server/services/scope-service.test.js +137 -0
- package/dist/server/server/services/sprint-orchestrator.js +29 -15
- package/dist/server/server/services/sprint-service.js +23 -3
- package/dist/server/server/services/sprint-service.test.js +238 -0
- package/dist/server/server/services/sync-service.js +434 -0
- package/dist/server/server/services/sync-types.js +2 -0
- package/dist/server/server/services/workflow-service.js +26 -5
- package/dist/server/server/services/workflow-service.test.js +159 -0
- package/dist/server/server/settings-sync.js +284 -0
- package/dist/server/server/uninstall.js +195 -0
- package/dist/server/server/update-planner.js +279 -0
- package/dist/server/server/update.js +212 -0
- package/dist/server/server/utils/cc-hooks-parser.js +3 -0
- package/dist/server/server/utils/cc-hooks-parser.test.js +86 -0
- package/dist/server/server/utils/dispatch-utils.js +83 -24
- package/dist/server/server/utils/dispatch-utils.test.js +182 -0
- package/dist/server/server/utils/flag-builder.js +54 -0
- package/dist/server/server/utils/json-fields.js +14 -0
- package/dist/server/server/utils/json-fields.test.js +73 -0
- package/dist/server/server/utils/logger.js +37 -3
- package/dist/server/server/utils/package-info.js +30 -0
- package/dist/server/server/utils/route-helpers.js +47 -0
- package/dist/server/server/utils/route-helpers.test.js +115 -0
- package/dist/server/server/utils/terminal-launcher.js +79 -25
- package/dist/server/server/utils/worktree-manager.js +13 -4
- package/dist/server/server/validator.js +230 -0
- package/dist/server/server/watchers/event-watcher.js +28 -13
- package/dist/server/server/watchers/global-watcher.js +63 -0
- package/dist/server/server/watchers/scope-watcher.js +27 -12
- package/dist/server/server/wizard/config-editor.js +237 -0
- package/dist/server/server/wizard/detect.js +96 -0
- package/dist/server/server/wizard/doctor.js +115 -0
- package/dist/server/server/wizard/index.js +340 -0
- package/dist/server/server/wizard/phases/confirm.js +39 -0
- package/dist/server/server/wizard/phases/project-setup.js +90 -0
- package/dist/server/server/wizard/phases/setup-wizard.js +66 -0
- package/dist/server/server/wizard/phases/welcome.js +32 -0
- package/dist/server/server/wizard/phases/workflow-setup.js +22 -0
- package/dist/server/server/wizard/types.js +29 -0
- package/dist/server/server/wizard/ui.js +73 -0
- package/dist/server/shared/__fixtures__/workflow-configs.js +75 -0
- package/dist/server/shared/api-types.js +80 -1
- package/dist/server/shared/default-workflow.json +65 -0
- package/dist/server/shared/onboarding-tour.test.js +81 -0
- package/dist/server/shared/project-colors.js +24 -0
- package/dist/server/shared/workflow-config.test.js +84 -0
- package/dist/server/shared/workflow-engine.js +1 -1
- package/dist/server/shared/workflow-engine.test.js +302 -0
- package/dist/server/shared/workflow-normalizer.js +101 -0
- package/dist/server/shared/workflow-normalizer.test.js +100 -0
- package/dist/server/src/components/onboarding/tour-steps.js +84 -0
- package/package.json +34 -29
- package/schemas/orbital.config.schema.json +2 -5
- package/scripts/postinstall.js +18 -6
- package/scripts/release.sh +53 -0
- package/server/__tests__/data-routes.test.ts +151 -0
- package/server/__tests__/helpers/db.ts +19 -0
- package/server/__tests__/helpers/mock-emitter.ts +10 -0
- package/server/__tests__/scope-routes.test.ts +158 -0
- package/server/__tests__/sprint-routes.test.ts +118 -0
- package/server/__tests__/workflow-routes.test.ts +120 -0
- package/server/config-migrator.ts +160 -0
- package/server/config.ts +64 -12
- package/server/database.ts +22 -31
- package/server/global-config.ts +204 -0
- package/server/index.ts +139 -316
- package/server/init.ts +266 -234
- package/server/launch.ts +32 -0
- package/server/manifest-types.ts +145 -0
- package/server/manifest.ts +494 -0
- package/server/migrate-legacy.ts +290 -0
- package/server/parsers/event-parser.test.ts +135 -0
- package/server/parsers/event-parser.ts +4 -1
- package/server/parsers/scope-parser.test.ts +270 -0
- package/server/parsers/scope-parser.ts +79 -31
- package/server/project-context.ts +325 -0
- package/server/project-emitter.ts +50 -0
- package/server/project-manager.ts +368 -0
- package/server/routes/aggregate-routes.ts +968 -0
- package/server/routes/config-routes.ts +43 -85
- package/server/routes/data-routes.ts +34 -156
- package/server/routes/dispatch-routes.ts +46 -17
- package/server/routes/git-routes.ts +77 -0
- package/server/routes/manifest-routes.ts +388 -0
- package/server/routes/scope-routes.ts +39 -30
- package/server/routes/sync-routes.ts +175 -0
- package/server/routes/version-routes.ts +1 -16
- package/server/routes/workflow-routes.ts +9 -3
- package/server/schema.ts +3 -0
- package/server/services/batch-orchestrator.ts +41 -17
- package/server/services/claude-session-service.ts +16 -14
- package/server/services/config-service.ts +10 -1
- package/server/services/deploy-service.test.ts +145 -0
- package/server/services/deploy-service.ts +2 -2
- package/server/services/event-service.test.ts +242 -0
- package/server/services/event-service.ts +92 -3
- package/server/services/gate-service.test.ts +131 -0
- package/server/services/gate-service.ts +2 -2
- package/server/services/git-service.ts +137 -4
- package/server/services/github-service.ts +120 -2
- package/server/services/readiness-service.test.ts +217 -0
- package/server/services/scope-cache.test.ts +167 -0
- package/server/services/scope-cache.ts +4 -1
- package/server/services/scope-service.test.ts +169 -0
- package/server/services/scope-service.ts +224 -130
- package/server/services/sprint-orchestrator.ts +30 -15
- package/server/services/sprint-service.test.ts +271 -0
- package/server/services/sprint-service.ts +29 -5
- package/server/services/sync-service.ts +482 -0
- package/server/services/sync-types.ts +77 -0
- package/server/services/workflow-service.test.ts +190 -0
- package/server/services/workflow-service.ts +29 -9
- package/server/settings-sync.ts +359 -0
- package/server/uninstall.ts +214 -0
- package/server/update-planner.ts +346 -0
- package/server/update.ts +263 -0
- package/server/utils/cc-hooks-parser.test.ts +96 -0
- package/server/utils/cc-hooks-parser.ts +4 -0
- package/server/utils/dispatch-utils.test.ts +245 -0
- package/server/utils/dispatch-utils.ts +102 -30
- package/server/utils/flag-builder.ts +56 -0
- package/server/utils/json-fields.test.ts +83 -0
- package/server/utils/json-fields.ts +14 -0
- package/server/utils/logger.ts +40 -3
- package/server/utils/package-info.ts +32 -0
- package/server/utils/route-helpers.test.ts +144 -0
- package/server/utils/route-helpers.ts +50 -0
- package/server/utils/terminal-launcher.ts +85 -25
- package/server/utils/worktree-manager.ts +9 -4
- package/server/validator.ts +270 -0
- package/server/watchers/event-watcher.ts +24 -12
- package/server/watchers/global-watcher.ts +77 -0
- package/server/watchers/scope-watcher.ts +21 -9
- package/server/wizard/config-editor.ts +248 -0
- package/server/wizard/detect.ts +104 -0
- package/server/wizard/doctor.ts +114 -0
- package/server/wizard/index.ts +438 -0
- package/server/wizard/phases/confirm.ts +45 -0
- package/server/wizard/phases/project-setup.ts +106 -0
- package/server/wizard/phases/setup-wizard.ts +78 -0
- package/server/wizard/phases/welcome.ts +39 -0
- package/server/wizard/phases/workflow-setup.ts +28 -0
- package/server/wizard/types.ts +56 -0
- package/server/wizard/ui.ts +92 -0
- package/shared/__fixtures__/workflow-configs.ts +80 -0
- package/shared/api-types.ts +106 -0
- package/shared/onboarding-tour.test.ts +94 -0
- package/shared/project-colors.ts +24 -0
- package/shared/workflow-config.test.ts +111 -0
- package/shared/workflow-config.ts +7 -0
- package/shared/workflow-engine.test.ts +388 -0
- package/shared/workflow-engine.ts +1 -1
- package/shared/workflow-normalizer.test.ts +119 -0
- package/shared/workflow-normalizer.ts +118 -0
- package/templates/agents/QUICK-REFERENCE.md +1 -0
- package/templates/agents/README.md +1 -0
- package/templates/agents/SKILL-TRIGGERS.md +11 -0
- package/templates/agents/green-team/deep-dive.md +361 -0
- package/templates/hooks/end-session.sh +4 -1
- package/templates/hooks/init-session.sh +1 -0
- package/templates/hooks/orbital-emit.sh +2 -2
- package/templates/hooks/orbital-report-deploy.sh +4 -4
- package/templates/hooks/orbital-report-gates.sh +4 -4
- package/templates/hooks/orbital-scope-update.sh +1 -1
- package/templates/hooks/scope-commit-logger.sh +2 -2
- package/templates/hooks/scope-create-cleanup.sh +2 -2
- package/templates/hooks/scope-create-gate.sh +2 -5
- package/templates/hooks/scope-gate.sh +4 -6
- package/templates/hooks/scope-helpers.sh +28 -1
- package/templates/hooks/scope-lifecycle-gate.sh +14 -5
- package/templates/hooks/scope-prepare.sh +67 -12
- package/templates/hooks/scope-transition.sh +14 -6
- package/templates/hooks/time-tracker.sh +2 -5
- package/templates/migrations/renames.json +1 -0
- package/templates/orbital.config.json +8 -6
- package/{shared/default-workflow.json → templates/presets/default.json} +65 -0
- package/templates/presets/development.json +4 -4
- package/templates/presets/gitflow.json +7 -0
- package/templates/prompts/README.md +23 -0
- package/templates/prompts/deep-dive-audit.md +94 -0
- package/templates/quick/rules.md +56 -5
- package/templates/settings-hooks.json +1 -1
- package/templates/skills/git-commit/SKILL.md +27 -7
- package/templates/skills/git-dev/SKILL.md +13 -4
- package/templates/skills/git-main/SKILL.md +13 -3
- package/templates/skills/git-production/SKILL.md +9 -2
- package/templates/skills/git-staging/SKILL.md +11 -3
- package/templates/skills/scope-create/SKILL.md +17 -3
- package/templates/skills/scope-fix-review/SKILL.md +14 -7
- package/templates/skills/scope-implement/SKILL.md +15 -4
- package/templates/skills/scope-post-review/SKILL.md +77 -7
- package/templates/skills/scope-pre-review/SKILL.md +11 -4
- package/templates/skills/scope-verify/SKILL.md +5 -3
- package/templates/skills/test-code-review/SKILL.md +41 -33
- package/templates/skills/test-scaffold/SKILL.md +222 -0
- package/dist/assets/WorkflowVisualizer-BZ21PIIF.js +0 -84
- package/dist/assets/charts-D__PA1zp.js +0 -72
- package/dist/assets/index-D1G6i0nS.css +0 -1
- package/dist/assets/index-DpItvKpf.js +0 -419
- package/dist/assets/ui-BvF022GT.js +0 -53
- package/index.html +0 -15
- package/postcss.config.js +0 -6
- package/src/App.tsx +0 -33
- package/src/components/AgentBadge.tsx +0 -40
- package/src/components/BatchPreflightModal.tsx +0 -115
- package/src/components/CardDisplayToggle.tsx +0 -74
- package/src/components/ColumnHeaderActions.tsx +0 -55
- package/src/components/ColumnMenu.tsx +0 -99
- package/src/components/DeployHistory.tsx +0 -141
- package/src/components/DispatchModal.tsx +0 -164
- package/src/components/DispatchPopover.tsx +0 -139
- package/src/components/DragOverlay.tsx +0 -25
- package/src/components/DriftSidebar.tsx +0 -140
- package/src/components/EnvironmentStrip.tsx +0 -88
- package/src/components/ErrorBoundary.tsx +0 -62
- package/src/components/FilterChip.tsx +0 -105
- package/src/components/GateIndicator.tsx +0 -33
- package/src/components/IdeaDetailModal.tsx +0 -190
- package/src/components/IdeaFormDialog.tsx +0 -113
- package/src/components/KanbanColumn.tsx +0 -201
- package/src/components/MarkdownRenderer.tsx +0 -114
- package/src/components/NeonGrid.tsx +0 -128
- package/src/components/PromotionQueue.tsx +0 -89
- package/src/components/ScopeCard.tsx +0 -234
- package/src/components/ScopeDetailModal.tsx +0 -255
- package/src/components/ScopeFilterBar.tsx +0 -152
- package/src/components/SearchInput.tsx +0 -102
- package/src/components/SessionPanel.tsx +0 -335
- package/src/components/SprintContainer.tsx +0 -303
- package/src/components/SprintDependencyDialog.tsx +0 -78
- package/src/components/SprintPreflightModal.tsx +0 -138
- package/src/components/StatusBar.tsx +0 -168
- package/src/components/SwimCell.tsx +0 -67
- package/src/components/SwimLaneRow.tsx +0 -94
- package/src/components/SwimlaneBoardView.tsx +0 -108
- package/src/components/VersionBadge.tsx +0 -139
- package/src/components/ViewModeSelector.tsx +0 -114
- package/src/components/config/AgentChip.tsx +0 -53
- package/src/components/config/AgentCreateDialog.tsx +0 -321
- package/src/components/config/AgentEditor.tsx +0 -175
- package/src/components/config/DirectoryTree.tsx +0 -582
- package/src/components/config/FileEditor.tsx +0 -550
- package/src/components/config/HookChip.tsx +0 -50
- package/src/components/config/StageCard.tsx +0 -198
- package/src/components/config/TransitionZone.tsx +0 -173
- package/src/components/config/UnifiedWorkflowPipeline.tsx +0 -216
- package/src/components/config/WorkflowPipeline.tsx +0 -161
- package/src/components/source-control/BranchList.tsx +0 -93
- package/src/components/source-control/BranchPanel.tsx +0 -105
- package/src/components/source-control/CommitLog.tsx +0 -100
- package/src/components/source-control/CommitRow.tsx +0 -47
- package/src/components/source-control/GitHubPanel.tsx +0 -110
- package/src/components/source-control/GitHubSetupGuide.tsx +0 -52
- package/src/components/source-control/GitOverviewBar.tsx +0 -101
- package/src/components/source-control/PullRequestList.tsx +0 -69
- package/src/components/source-control/WorktreeList.tsx +0 -80
- package/src/components/ui/badge.tsx +0 -41
- package/src/components/ui/button.tsx +0 -55
- package/src/components/ui/card.tsx +0 -78
- package/src/components/ui/dialog.tsx +0 -94
- package/src/components/ui/popover.tsx +0 -33
- package/src/components/ui/scroll-area.tsx +0 -54
- package/src/components/ui/separator.tsx +0 -28
- package/src/components/ui/tabs.tsx +0 -52
- package/src/components/ui/toggle-switch.tsx +0 -35
- package/src/components/ui/tooltip.tsx +0 -27
- package/src/components/workflow/AddEdgeDialog.tsx +0 -217
- package/src/components/workflow/AddListDialog.tsx +0 -201
- package/src/components/workflow/ChecklistEditor.tsx +0 -239
- package/src/components/workflow/CommandPrefixManager.tsx +0 -118
- package/src/components/workflow/ConfigSettingsPanel.tsx +0 -189
- package/src/components/workflow/DirectionSelector.tsx +0 -133
- package/src/components/workflow/DispatchConfigPanel.tsx +0 -180
- package/src/components/workflow/EdgeDetailPanel.tsx +0 -236
- package/src/components/workflow/EdgePropertyEditor.tsx +0 -251
- package/src/components/workflow/EditToolbar.tsx +0 -138
- package/src/components/workflow/HookDetailPanel.tsx +0 -250
- package/src/components/workflow/HookExecutionLog.tsx +0 -24
- package/src/components/workflow/HookSourceModal.tsx +0 -129
- package/src/components/workflow/HooksDashboard.tsx +0 -363
- package/src/components/workflow/ListPropertyEditor.tsx +0 -251
- package/src/components/workflow/MigrationPreviewDialog.tsx +0 -237
- package/src/components/workflow/MovementRulesPanel.tsx +0 -188
- package/src/components/workflow/NodeDetailPanel.tsx +0 -245
- package/src/components/workflow/PresetSelector.tsx +0 -414
- package/src/components/workflow/SkillCommandBuilder.tsx +0 -174
- package/src/components/workflow/WorkflowEdgeComponent.tsx +0 -145
- package/src/components/workflow/WorkflowNode.tsx +0 -147
- package/src/components/workflow/graphLayout.ts +0 -186
- package/src/components/workflow/mergeHooks.ts +0 -85
- package/src/components/workflow/useEditHistory.ts +0 -88
- package/src/components/workflow/useWorkflowEditor.ts +0 -262
- package/src/components/workflow/validateConfig.ts +0 -70
- package/src/hooks/useActiveDispatches.ts +0 -198
- package/src/hooks/useBoardSettings.ts +0 -170
- package/src/hooks/useCardDisplay.ts +0 -57
- package/src/hooks/useCcHooks.ts +0 -24
- package/src/hooks/useConfigTree.ts +0 -51
- package/src/hooks/useEnforcementRules.ts +0 -46
- package/src/hooks/useEvents.ts +0 -59
- package/src/hooks/useFileEditor.ts +0 -165
- package/src/hooks/useGates.ts +0 -57
- package/src/hooks/useIdeaActions.ts +0 -53
- package/src/hooks/useKanbanDnd.ts +0 -410
- package/src/hooks/useOrbitalConfig.ts +0 -54
- package/src/hooks/usePipeline.ts +0 -47
- package/src/hooks/usePipelineData.ts +0 -338
- package/src/hooks/useReconnect.ts +0 -25
- package/src/hooks/useScopeFilters.ts +0 -125
- package/src/hooks/useScopeSessions.ts +0 -44
- package/src/hooks/useScopes.ts +0 -67
- package/src/hooks/useSearch.ts +0 -67
- package/src/hooks/useSettings.tsx +0 -187
- package/src/hooks/useSocket.ts +0 -25
- package/src/hooks/useSourceControl.ts +0 -105
- package/src/hooks/useSprintPreflight.ts +0 -55
- package/src/hooks/useSprints.ts +0 -154
- package/src/hooks/useStatusBarHighlight.ts +0 -18
- package/src/hooks/useSwimlaneBoardSettings.ts +0 -104
- package/src/hooks/useTheme.ts +0 -9
- package/src/hooks/useTransitionReadiness.ts +0 -53
- package/src/hooks/useVersion.ts +0 -155
- package/src/hooks/useViolations.ts +0 -65
- package/src/hooks/useWorkflow.tsx +0 -125
- package/src/hooks/useZoomModifier.ts +0 -19
- package/src/index.css +0 -797
- package/src/layouts/DashboardLayout.tsx +0 -113
- package/src/lib/collisionDetection.ts +0 -20
- package/src/lib/scope-fields.ts +0 -61
- package/src/lib/swimlane.ts +0 -146
- package/src/lib/utils.ts +0 -15
- package/src/main.tsx +0 -19
- package/src/socket.ts +0 -11
- package/src/types/index.ts +0 -497
- package/src/views/AgentFeed.tsx +0 -339
- package/src/views/DeployPipeline.tsx +0 -59
- package/src/views/EnforcementView.tsx +0 -378
- package/src/views/PrimitivesConfig.tsx +0 -500
- package/src/views/QualityGates.tsx +0 -1012
- package/src/views/ScopeBoard.tsx +0 -454
- package/src/views/SessionTimeline.tsx +0 -516
- package/src/views/Settings.tsx +0 -183
- package/src/views/SourceControl.tsx +0 -95
- package/src/views/WorkflowVisualizer.tsx +0 -382
- package/tailwind.config.js +0 -161
- package/tsconfig.json +0 -25
- package/vite.config.ts +0 -38
|
@@ -0,0 +1,968 @@
|
|
|
1
|
+
import { Router } from 'express';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import type { Server } from 'socket.io';
|
|
4
|
+
import type { GateRow } from '../services/gate-service.js';
|
|
5
|
+
import { launchInTerminal } from '../utils/terminal-launcher.js';
|
|
6
|
+
import { buildClaudeFlags } from '../utils/flag-builder.js';
|
|
7
|
+
import { DEFAULT_DISPATCH_FLAGS, DEFAULT_DISPATCH_CONFIG, validateDispatchFlags, validateDispatchConfig } from '../../shared/api-types.js';
|
|
8
|
+
import type { DispatchFlags, DispatchConfig } from '../../shared/api-types.js';
|
|
9
|
+
import { getClaudeSessions, getSessionStats } from '../services/claude-session-service.js';
|
|
10
|
+
import { getActiveScopeIds, getAbandonedScopeIds } from '../utils/dispatch-utils.js';
|
|
11
|
+
import { ConfigService, isValidPrimitiveType } from '../services/config-service.js';
|
|
12
|
+
import { GLOBAL_PRIMITIVES_DIR } from '../global-config.js';
|
|
13
|
+
import { WorkflowEngine } from '../../shared/workflow-engine.js';
|
|
14
|
+
import { getHookEnforcement } from '../../shared/workflow-config.js';
|
|
15
|
+
import type { CcHookParsed } from '../../shared/workflow-config.js';
|
|
16
|
+
import { parseCcHooks } from '../utils/cc-hooks-parser.js';
|
|
17
|
+
import { createLogger } from '../utils/logger.js';
|
|
18
|
+
import { parseJsonFields } from '../utils/json-fields.js';
|
|
19
|
+
import type { ProjectManager } from '../project-manager.js';
|
|
20
|
+
import type { SyncService } from '../services/sync-service.js';
|
|
21
|
+
import { loadManifest, refreshFileStatuses, summarizeManifest } from '../manifest.js';
|
|
22
|
+
import { getPackageVersion } from '../utils/package-info.js';
|
|
23
|
+
import { runUpdate } from '../init.js';
|
|
24
|
+
import {
|
|
25
|
+
loadGlobalConfig,
|
|
26
|
+
saveGlobalConfig,
|
|
27
|
+
} from '../global-config.js';
|
|
28
|
+
|
|
29
|
+
const log = createLogger('aggregate');
|
|
30
|
+
|
|
31
|
+
interface AggregateRouteDeps {
|
|
32
|
+
projectManager: ProjectManager;
|
|
33
|
+
io: Server;
|
|
34
|
+
syncService: SyncService;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function createAggregateRoutes({ projectManager, io, syncService }: AggregateRouteDeps): Router {
|
|
38
|
+
const router = Router();
|
|
39
|
+
|
|
40
|
+
// ─── Aggregate: Scopes & Events ──────────────────────────
|
|
41
|
+
|
|
42
|
+
router.get('/aggregate/scopes', (_req, res) => {
|
|
43
|
+
const allScopes: Array<Record<string, unknown>> = [];
|
|
44
|
+
for (const [projectId, ctx] of projectManager.getAllContexts()) {
|
|
45
|
+
for (const scope of ctx.scopeService.getAll()) {
|
|
46
|
+
allScopes.push({ ...scope, project_id: projectId });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
res.json(allScopes);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
router.get('/aggregate/sprints', (_req, res) => {
|
|
53
|
+
const allSprints: Array<Record<string, unknown>> = [];
|
|
54
|
+
for (const [projectId, ctx] of projectManager.getAllContexts()) {
|
|
55
|
+
for (const sprint of ctx.sprintService.getAll()) {
|
|
56
|
+
allSprints.push({ ...sprint, project_id: projectId });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
res.json(allSprints);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
router.get('/aggregate/events', (req, res) => {
|
|
63
|
+
const limit = Number(req.query.limit) || 50;
|
|
64
|
+
const allEvents: Array<Record<string, unknown>> = [];
|
|
65
|
+
for (const [projectId, ctx] of projectManager.getAllContexts()) {
|
|
66
|
+
const events = ctx.db.prepare(
|
|
67
|
+
`SELECT * FROM events ORDER BY timestamp DESC LIMIT ?`
|
|
68
|
+
).all(limit) as Array<Record<string, unknown>>;
|
|
69
|
+
for (const event of events) {
|
|
70
|
+
allEvents.push({ ...event, project_id: projectId });
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// Sort by timestamp descending across all projects
|
|
74
|
+
allEvents.sort((a, b) => String(b.timestamp).localeCompare(String(a.timestamp)));
|
|
75
|
+
res.json(allEvents.slice(0, limit));
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// Aggregate sessions across all projects
|
|
79
|
+
router.get('/aggregate/sessions', (_req, res) => {
|
|
80
|
+
const allRows: Array<Record<string, unknown>> = [];
|
|
81
|
+
for (const [projectId, ctx] of projectManager.getAllContexts()) {
|
|
82
|
+
const rows = ctx.db.prepare(
|
|
83
|
+
'SELECT * FROM sessions ORDER BY started_at DESC'
|
|
84
|
+
).all() as Array<Record<string, unknown>>;
|
|
85
|
+
for (const row of rows) {
|
|
86
|
+
allRows.push({ ...parseJsonFields(row), project_id: projectId });
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Deduplicate by claude_session_id, aggregate scope_ids and actions
|
|
91
|
+
const seen = new Map<string, Record<string, unknown>>();
|
|
92
|
+
const scopeMap = new Map<string, number[]>();
|
|
93
|
+
const actionMap = new Map<string, string[]>();
|
|
94
|
+
|
|
95
|
+
for (const row of allRows) {
|
|
96
|
+
const key = (row.claude_session_id as string | null) ?? (row.id as string);
|
|
97
|
+
if (!seen.has(key)) {
|
|
98
|
+
seen.set(key, row);
|
|
99
|
+
scopeMap.set(key, []);
|
|
100
|
+
actionMap.set(key, []);
|
|
101
|
+
}
|
|
102
|
+
const sid = row.scope_id as number | null;
|
|
103
|
+
if (sid != null) {
|
|
104
|
+
const arr = scopeMap.get(key)!;
|
|
105
|
+
if (!arr.includes(sid)) arr.push(sid);
|
|
106
|
+
}
|
|
107
|
+
const action = row.action as string | null;
|
|
108
|
+
if (action) {
|
|
109
|
+
const actions = actionMap.get(key)!;
|
|
110
|
+
if (!actions.includes(action)) actions.push(action);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const results = [...seen.values()].map((row) => {
|
|
115
|
+
const key = (row.claude_session_id as string | null) ?? (row.id as string);
|
|
116
|
+
return { ...row, scope_ids: scopeMap.get(key) ?? [], actions: actionMap.get(key) ?? [] };
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
// Sort by started_at descending across all projects
|
|
120
|
+
results.sort((a, b) =>
|
|
121
|
+
String((b as Record<string, unknown>).started_at ?? '').localeCompare(
|
|
122
|
+
String((a as Record<string, unknown>).started_at ?? ''),
|
|
123
|
+
),
|
|
124
|
+
);
|
|
125
|
+
res.json(results.slice(0, 50));
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
router.get('/aggregate/sessions/:id/content', async (req, res) => {
|
|
129
|
+
const sessionId = req.params.id;
|
|
130
|
+
|
|
131
|
+
// Find the session across all project databases
|
|
132
|
+
let session: Record<string, unknown> | undefined;
|
|
133
|
+
let matchedProjectRoot: string | undefined;
|
|
134
|
+
for (const [, ctx] of projectManager.getAllContexts()) {
|
|
135
|
+
const row = ctx.db.prepare('SELECT * FROM sessions WHERE id = ?').get(sessionId) as Record<string, unknown> | undefined;
|
|
136
|
+
if (row) {
|
|
137
|
+
session = parseJsonFields(row);
|
|
138
|
+
matchedProjectRoot = ctx.config.projectRoot;
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (!session || !matchedProjectRoot) {
|
|
144
|
+
res.status(404).json({ error: 'Session not found' });
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
let content = '';
|
|
149
|
+
let meta: Record<string, unknown> | null = null;
|
|
150
|
+
let stats: Record<string, unknown> | null = null;
|
|
151
|
+
|
|
152
|
+
if (session.claude_session_id && typeof session.claude_session_id === 'string') {
|
|
153
|
+
const claudeSessions = await getClaudeSessions(undefined, matchedProjectRoot);
|
|
154
|
+
const match = claudeSessions.find(s => s.id === session!.claude_session_id);
|
|
155
|
+
if (match) {
|
|
156
|
+
meta = {
|
|
157
|
+
slug: match.slug,
|
|
158
|
+
branch: match.branch,
|
|
159
|
+
fileSize: match.fileSize,
|
|
160
|
+
summary: match.summary,
|
|
161
|
+
startedAt: match.startedAt,
|
|
162
|
+
lastActiveAt: match.lastActiveAt,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
stats = getSessionStats(session.claude_session_id, matchedProjectRoot) as Record<string, unknown> | null;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (!content) {
|
|
169
|
+
const parts: string[] = [];
|
|
170
|
+
if (session.summary) parts.push(`# ${session.summary}\n`);
|
|
171
|
+
const discoveries = Array.isArray(session.discoveries) ? session.discoveries : [];
|
|
172
|
+
if (discoveries.length > 0) {
|
|
173
|
+
parts.push('## Completed\n');
|
|
174
|
+
for (const d of discoveries) parts.push(`- ${d}`);
|
|
175
|
+
parts.push('');
|
|
176
|
+
}
|
|
177
|
+
const nextSteps = Array.isArray(session.next_steps) ? session.next_steps : [];
|
|
178
|
+
if (nextSteps.length > 0) {
|
|
179
|
+
parts.push('## Next Steps\n');
|
|
180
|
+
for (const n of nextSteps) parts.push(`- ${n}`);
|
|
181
|
+
}
|
|
182
|
+
content = parts.join('\n');
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
res.json({
|
|
186
|
+
id: session.id,
|
|
187
|
+
content,
|
|
188
|
+
claude_session_id: session.claude_session_id ?? null,
|
|
189
|
+
meta,
|
|
190
|
+
stats,
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
router.post('/aggregate/sessions/:id/resume', async (req, res) => {
|
|
195
|
+
const sessionId = req.params.id;
|
|
196
|
+
const { claude_session_id } = req.body as { claude_session_id?: string };
|
|
197
|
+
|
|
198
|
+
if (!claude_session_id || !/^[0-9a-f-]{36}$/i.test(claude_session_id)) {
|
|
199
|
+
res.status(400).json({ error: 'Valid claude_session_id (UUID) required' });
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Find the session's project root and config
|
|
204
|
+
let matchedProjectRoot: string | undefined;
|
|
205
|
+
let matchedConfig: import('../config.js').OrbitalConfig | undefined;
|
|
206
|
+
for (const [, ctx] of projectManager.getAllContexts()) {
|
|
207
|
+
const row = ctx.db.prepare('SELECT * FROM sessions WHERE id = ?').get(sessionId);
|
|
208
|
+
if (row) {
|
|
209
|
+
matchedProjectRoot = ctx.config.projectRoot;
|
|
210
|
+
matchedConfig = ctx.config;
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (!matchedProjectRoot || !matchedConfig) {
|
|
216
|
+
res.status(404).json({ error: 'Session not found' });
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const flagsStr = buildClaudeFlags(matchedConfig.claude.dispatchFlags);
|
|
221
|
+
const resumeCmd = `cd '${matchedProjectRoot}' && claude ${flagsStr} --resume '${claude_session_id}'`;
|
|
222
|
+
try {
|
|
223
|
+
await launchInTerminal(resumeCmd);
|
|
224
|
+
res.json({ ok: true, session_id: claude_session_id });
|
|
225
|
+
} catch (err) {
|
|
226
|
+
log.error('Terminal launch failed', { error: String(err) });
|
|
227
|
+
res.status(500).json({ error: 'Failed to launch terminal', details: String(err) });
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
// ─── Aggregate: Enforcement & Gates ──────────────────────
|
|
232
|
+
|
|
233
|
+
router.get('/aggregate/events/violations/summary', (_req, res) => {
|
|
234
|
+
try {
|
|
235
|
+
const mergedByRule = new Map<string, { rule: string; count: number; last_seen: string }>();
|
|
236
|
+
const mergedByFile = new Map<string, { file: string; count: number }>();
|
|
237
|
+
let allOverrides: Array<{ rule: string; reason: string; date: string }> = [];
|
|
238
|
+
let totalViolations = 0;
|
|
239
|
+
let totalOverrides = 0;
|
|
240
|
+
|
|
241
|
+
for (const [, ctx] of projectManager.getAllContexts()) {
|
|
242
|
+
const byRule = ctx.db.prepare(
|
|
243
|
+
`SELECT JSON_EXTRACT(data, '$.rule') as rule, COUNT(*) as count, MAX(timestamp) as last_seen
|
|
244
|
+
FROM events WHERE type = 'VIOLATION' GROUP BY rule ORDER BY count DESC`
|
|
245
|
+
).all() as Array<{ rule: string; count: number; last_seen: string }>;
|
|
246
|
+
for (const r of byRule) {
|
|
247
|
+
const existing = mergedByRule.get(r.rule);
|
|
248
|
+
if (existing) {
|
|
249
|
+
existing.count += r.count;
|
|
250
|
+
if (r.last_seen > existing.last_seen) existing.last_seen = r.last_seen;
|
|
251
|
+
} else {
|
|
252
|
+
mergedByRule.set(r.rule, { ...r });
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const byFile = ctx.db.prepare(
|
|
257
|
+
`SELECT JSON_EXTRACT(data, '$.file') as file, COUNT(*) as count FROM events
|
|
258
|
+
WHERE type = 'VIOLATION' AND JSON_EXTRACT(data, '$.file') IS NOT NULL AND JSON_EXTRACT(data, '$.file') != ''
|
|
259
|
+
GROUP BY file ORDER BY count DESC LIMIT 20`
|
|
260
|
+
).all() as Array<{ file: string; count: number }>;
|
|
261
|
+
for (const f of byFile) {
|
|
262
|
+
const existing = mergedByFile.get(f.file);
|
|
263
|
+
if (existing) {
|
|
264
|
+
existing.count += f.count;
|
|
265
|
+
} else {
|
|
266
|
+
mergedByFile.set(f.file, { ...f });
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const overrides = ctx.db.prepare(
|
|
271
|
+
`SELECT JSON_EXTRACT(data, '$.rule') as rule, JSON_EXTRACT(data, '$.reason') as reason, timestamp as date
|
|
272
|
+
FROM events WHERE type = 'OVERRIDE' ORDER BY timestamp DESC LIMIT 50`
|
|
273
|
+
).all() as Array<{ rule: string; reason: string; date: string }>;
|
|
274
|
+
allOverrides = allOverrides.concat(overrides);
|
|
275
|
+
|
|
276
|
+
const tv = ctx.db.prepare(`SELECT COUNT(*) as count FROM events WHERE type = 'VIOLATION'`).get() as { count: number };
|
|
277
|
+
const to = ctx.db.prepare(`SELECT COUNT(*) as count FROM events WHERE type = 'OVERRIDE'`).get() as { count: number };
|
|
278
|
+
totalViolations += tv.count;
|
|
279
|
+
totalOverrides += to.count;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const byRule = [...mergedByRule.values()].sort((a, b) => b.count - a.count);
|
|
283
|
+
const byFile = [...mergedByFile.values()].sort((a, b) => b.count - a.count).slice(0, 20);
|
|
284
|
+
allOverrides.sort((a, b) => b.date.localeCompare(a.date));
|
|
285
|
+
|
|
286
|
+
res.json({ byRule, byFile, overrides: allOverrides.slice(0, 50), totalViolations, totalOverrides });
|
|
287
|
+
} catch (err) {
|
|
288
|
+
log.error('Violations summary failed', { error: String(err) });
|
|
289
|
+
res.status(500).json({ error: 'Failed to aggregate violations summary' });
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
router.get('/aggregate/enforcement/rules', (_req, res) => {
|
|
294
|
+
try {
|
|
295
|
+
const hookMap = new Map<string, {
|
|
296
|
+
hook: ReturnType<WorkflowEngine['getAllHooks']>[number];
|
|
297
|
+
enforcement: string;
|
|
298
|
+
edges: Array<{ from: string; to: string; label: string }>;
|
|
299
|
+
stats: { violations: number; overrides: number; last_triggered: string | null };
|
|
300
|
+
}>();
|
|
301
|
+
const summary = { guards: 0, gates: 0, lifecycle: 0, observers: 0 };
|
|
302
|
+
const edgeIdSet = new Set<string>();
|
|
303
|
+
let totalEdges = 0;
|
|
304
|
+
|
|
305
|
+
for (const [, ctx] of projectManager.getAllContexts()) {
|
|
306
|
+
const allHooks = ctx.workflowEngine.getAllHooks();
|
|
307
|
+
const allEdges = ctx.workflowEngine.getAllEdges();
|
|
308
|
+
|
|
309
|
+
// Build edge map for this project
|
|
310
|
+
const hookEdgeMap = new Map<string, Array<{ from: string; to: string; label: string }>>();
|
|
311
|
+
for (const edge of allEdges) {
|
|
312
|
+
const edgeKey = `${edge.from}->${edge.to}`;
|
|
313
|
+
if (!edgeIdSet.has(edgeKey)) {
|
|
314
|
+
edgeIdSet.add(edgeKey);
|
|
315
|
+
totalEdges++;
|
|
316
|
+
}
|
|
317
|
+
for (const hookId of edge.hooks ?? []) {
|
|
318
|
+
if (!hookEdgeMap.has(hookId)) hookEdgeMap.set(hookId, []);
|
|
319
|
+
hookEdgeMap.get(hookId)!.push({ from: edge.from, to: edge.to, label: edge.label });
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// Query stats from this project's DB
|
|
324
|
+
const violationStats = ctx.db.prepare(
|
|
325
|
+
`SELECT JSON_EXTRACT(data, '$.rule') as rule, COUNT(*) as count, MAX(timestamp) as last_seen
|
|
326
|
+
FROM events WHERE type = 'VIOLATION' GROUP BY rule`
|
|
327
|
+
).all() as Array<{ rule: string; count: number; last_seen: string }>;
|
|
328
|
+
const overrideStats = ctx.db.prepare(
|
|
329
|
+
`SELECT JSON_EXTRACT(data, '$.rule') as rule, COUNT(*) as count
|
|
330
|
+
FROM events WHERE type = 'OVERRIDE' GROUP BY rule`
|
|
331
|
+
).all() as Array<{ rule: string; count: number }>;
|
|
332
|
+
const violationMap = new Map(violationStats.map((v) => [v.rule, v]));
|
|
333
|
+
const overrideMap = new Map(overrideStats.map((o) => [o.rule, o]));
|
|
334
|
+
|
|
335
|
+
for (const hook of allHooks) {
|
|
336
|
+
const existing = hookMap.get(hook.id);
|
|
337
|
+
const projViolations = violationMap.get(hook.id)?.count ?? 0;
|
|
338
|
+
const projOverrides = overrideMap.get(hook.id)?.count ?? 0;
|
|
339
|
+
const projLastTriggered = violationMap.get(hook.id)?.last_seen ?? null;
|
|
340
|
+
|
|
341
|
+
if (existing) {
|
|
342
|
+
// Sum stats across projects
|
|
343
|
+
existing.stats.violations += projViolations;
|
|
344
|
+
existing.stats.overrides += projOverrides;
|
|
345
|
+
if (projLastTriggered && (!existing.stats.last_triggered || projLastTriggered > existing.stats.last_triggered)) {
|
|
346
|
+
existing.stats.last_triggered = projLastTriggered;
|
|
347
|
+
}
|
|
348
|
+
// Union edges
|
|
349
|
+
const existingEdgeKeys = new Set(existing.edges.map((e) => `${e.from}->${e.to}`));
|
|
350
|
+
for (const edge of hookEdgeMap.get(hook.id) ?? []) {
|
|
351
|
+
if (!existingEdgeKeys.has(`${edge.from}->${edge.to}`)) {
|
|
352
|
+
existing.edges.push(edge);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
} else {
|
|
356
|
+
// First time seeing this hook — count it in summary
|
|
357
|
+
if (hook.category === 'guard') summary.guards++;
|
|
358
|
+
else if (hook.category === 'gate') summary.gates++;
|
|
359
|
+
else if (hook.category === 'lifecycle') summary.lifecycle++;
|
|
360
|
+
else if (hook.category === 'observer') summary.observers++;
|
|
361
|
+
|
|
362
|
+
hookMap.set(hook.id, {
|
|
363
|
+
hook,
|
|
364
|
+
enforcement: getHookEnforcement(hook),
|
|
365
|
+
edges: hookEdgeMap.get(hook.id) ?? [],
|
|
366
|
+
stats: {
|
|
367
|
+
violations: projViolations,
|
|
368
|
+
overrides: projOverrides,
|
|
369
|
+
last_triggered: projLastTriggered,
|
|
370
|
+
},
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
res.json({ summary, rules: [...hookMap.values()], totalEdges });
|
|
377
|
+
} catch (err) {
|
|
378
|
+
log.error('Enforcement rules failed', { error: String(err) });
|
|
379
|
+
res.status(500).json({ error: 'Failed to aggregate enforcement rules' });
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
// GET /aggregate/workflow/claude-hooks — union of CC hooks across all projects
|
|
384
|
+
router.get('/aggregate/workflow/claude-hooks', (_req, res) => {
|
|
385
|
+
try {
|
|
386
|
+
const allHooks: CcHookParsed[] = [];
|
|
387
|
+
for (const [, ctx] of projectManager.getAllContexts()) {
|
|
388
|
+
const settingsPath = path.join(ctx.config.projectRoot, '.claude/settings.local.json');
|
|
389
|
+
allHooks.push(...parseCcHooks(settingsPath));
|
|
390
|
+
}
|
|
391
|
+
res.json({ success: true, data: allHooks });
|
|
392
|
+
} catch (err) {
|
|
393
|
+
log.error('Aggregate claude-hooks failed', { error: String(err) });
|
|
394
|
+
res.status(500).json({ success: false, error: String(err) });
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
router.get('/aggregate/events/violations/trend', (req, res) => {
|
|
399
|
+
try {
|
|
400
|
+
const days = Number(req.query.days) || 30;
|
|
401
|
+
const merged = new Map<string, { day: string; rule: string; count: number }>();
|
|
402
|
+
|
|
403
|
+
for (const [, ctx] of projectManager.getAllContexts()) {
|
|
404
|
+
const trend = ctx.db.prepare(
|
|
405
|
+
`SELECT date(timestamp) as day, JSON_EXTRACT(data, '$.rule') as rule, COUNT(*) as count
|
|
406
|
+
FROM events WHERE type = 'VIOLATION' AND timestamp >= datetime('now', ? || ' days')
|
|
407
|
+
GROUP BY day, rule ORDER BY day ASC`
|
|
408
|
+
).all(`-${days}`) as Array<{ day: string; rule: string; count: number }>;
|
|
409
|
+
for (const t of trend) {
|
|
410
|
+
const key = `${t.day}:${t.rule}`;
|
|
411
|
+
const existing = merged.get(key);
|
|
412
|
+
if (existing) {
|
|
413
|
+
existing.count += t.count;
|
|
414
|
+
} else {
|
|
415
|
+
merged.set(key, { ...t });
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
const result = [...merged.values()].sort((a, b) => a.day.localeCompare(b.day));
|
|
421
|
+
res.json(result);
|
|
422
|
+
} catch (err) {
|
|
423
|
+
log.error('Violation trends failed', { error: String(err) });
|
|
424
|
+
res.status(500).json({ error: 'Failed to aggregate violation trends' });
|
|
425
|
+
}
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
router.get('/aggregate/gates', (req, res) => {
|
|
429
|
+
try {
|
|
430
|
+
const scopeId = req.query.scope_id;
|
|
431
|
+
const filterProjectId = req.query.project_id as string | undefined;
|
|
432
|
+
const mergedGates = new Map<string, GateRow & { project_id: string }>();
|
|
433
|
+
|
|
434
|
+
for (const [projectId, ctx] of projectManager.getAllContexts()) {
|
|
435
|
+
if (filterProjectId && projectId !== filterProjectId) continue;
|
|
436
|
+
const gates = scopeId
|
|
437
|
+
? ctx.gateService.getLatestForScope(Number(scopeId))
|
|
438
|
+
: ctx.gateService.getLatestRun();
|
|
439
|
+
for (const gate of gates) {
|
|
440
|
+
const existing = mergedGates.get(gate.gate_name);
|
|
441
|
+
if (!existing || gate.run_at > existing.run_at) {
|
|
442
|
+
mergedGates.set(gate.gate_name, { ...gate, project_id: projectId });
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
res.json([...mergedGates.values()]);
|
|
448
|
+
} catch (err) {
|
|
449
|
+
log.error('Gates aggregation failed', { error: String(err) });
|
|
450
|
+
res.status(500).json({ error: 'Failed to aggregate gates' });
|
|
451
|
+
}
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
router.get('/aggregate/gates/stats', (_req, res) => {
|
|
455
|
+
try {
|
|
456
|
+
const merged = new Map<string, { gate_name: string; total: number; passed: number; failed: number }>();
|
|
457
|
+
|
|
458
|
+
for (const [, ctx] of projectManager.getAllContexts()) {
|
|
459
|
+
const stats = ctx.gateService.getStats();
|
|
460
|
+
for (const s of stats) {
|
|
461
|
+
const existing = merged.get(s.gate_name);
|
|
462
|
+
if (existing) {
|
|
463
|
+
existing.total += s.total;
|
|
464
|
+
existing.passed += s.passed;
|
|
465
|
+
existing.failed += s.failed;
|
|
466
|
+
} else {
|
|
467
|
+
merged.set(s.gate_name, { ...s });
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
res.json([...merged.values()]);
|
|
473
|
+
} catch (err) {
|
|
474
|
+
log.error('Gate stats failed', { error: String(err) });
|
|
475
|
+
res.status(500).json({ error: 'Failed to aggregate gate stats' });
|
|
476
|
+
}
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
// ─── Aggregate: Git & GitHub ───────────────────────────────
|
|
480
|
+
|
|
481
|
+
router.get('/aggregate/git/overview', async (_req, res) => {
|
|
482
|
+
try {
|
|
483
|
+
const projects = projectManager.getProjectList();
|
|
484
|
+
const results = await Promise.allSettled(
|
|
485
|
+
projects.filter(p => p.enabled && p.status === 'active').map(async (proj) => {
|
|
486
|
+
const ctx = projectManager.getContext(proj.id);
|
|
487
|
+
if (!ctx) throw new Error('Project offline');
|
|
488
|
+
const config = ctx.workflowEngine.getConfig();
|
|
489
|
+
const overview = await ctx.gitService.getOverview(config.branchingMode ?? 'trunk');
|
|
490
|
+
return {
|
|
491
|
+
projectId: proj.id,
|
|
492
|
+
projectName: proj.name,
|
|
493
|
+
projectColor: proj.color,
|
|
494
|
+
status: 'ok' as const,
|
|
495
|
+
overview,
|
|
496
|
+
};
|
|
497
|
+
}),
|
|
498
|
+
);
|
|
499
|
+
|
|
500
|
+
const overviews = results.map((r, i) => {
|
|
501
|
+
if (r.status === 'fulfilled') return r.value;
|
|
502
|
+
const proj = projects.filter(p => p.enabled && p.status === 'active')[i];
|
|
503
|
+
return {
|
|
504
|
+
projectId: proj.id,
|
|
505
|
+
projectName: proj.name,
|
|
506
|
+
projectColor: proj.color,
|
|
507
|
+
status: 'error' as const,
|
|
508
|
+
error: String((r as PromiseRejectedResult).reason),
|
|
509
|
+
};
|
|
510
|
+
});
|
|
511
|
+
|
|
512
|
+
res.json(overviews);
|
|
513
|
+
} catch (err) {
|
|
514
|
+
log.error('Git overviews failed', { error: String(err) });
|
|
515
|
+
res.status(500).json({ error: 'Failed to aggregate git overviews' });
|
|
516
|
+
}
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
router.get('/aggregate/git/commits', async (req, res) => {
|
|
520
|
+
try {
|
|
521
|
+
const limit = Number(req.query.limit) || 50;
|
|
522
|
+
const projects = projectManager.getProjectList().filter(p => p.enabled && p.status === 'active');
|
|
523
|
+
|
|
524
|
+
const results = await Promise.allSettled(
|
|
525
|
+
projects.map(async (proj) => {
|
|
526
|
+
const ctx = projectManager.getContext(proj.id);
|
|
527
|
+
if (!ctx) return [];
|
|
528
|
+
const commits = await ctx.gitService.getCommits({ limit });
|
|
529
|
+
return commits.map(c => ({
|
|
530
|
+
...c,
|
|
531
|
+
project_id: proj.id,
|
|
532
|
+
projectName: proj.name,
|
|
533
|
+
projectColor: proj.color,
|
|
534
|
+
}));
|
|
535
|
+
}),
|
|
536
|
+
);
|
|
537
|
+
|
|
538
|
+
const allCommits: Array<Record<string, unknown>> = [];
|
|
539
|
+
for (const r of results) {
|
|
540
|
+
if (r.status === 'fulfilled') allCommits.push(...r.value);
|
|
541
|
+
}
|
|
542
|
+
allCommits.sort((a, b) => String(b.date).localeCompare(String(a.date)));
|
|
543
|
+
res.json(allCommits.slice(0, limit));
|
|
544
|
+
} catch (err) {
|
|
545
|
+
log.error('Commits aggregation failed', { error: String(err) });
|
|
546
|
+
res.status(500).json({ error: 'Failed to aggregate commits' });
|
|
547
|
+
}
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
router.get('/aggregate/github/prs', async (_req, res) => {
|
|
551
|
+
try {
|
|
552
|
+
const projects = projectManager.getProjectList().filter(p => p.enabled && p.status === 'active');
|
|
553
|
+
|
|
554
|
+
const results = await Promise.allSettled(
|
|
555
|
+
projects.map(async (proj) => {
|
|
556
|
+
const ctx = projectManager.getContext(proj.id);
|
|
557
|
+
if (!ctx) return [];
|
|
558
|
+
const prs = await ctx.githubService.getOpenPRs();
|
|
559
|
+
return prs.map(pr => ({
|
|
560
|
+
...pr,
|
|
561
|
+
project_id: proj.id,
|
|
562
|
+
projectName: proj.name,
|
|
563
|
+
projectColor: proj.color,
|
|
564
|
+
}));
|
|
565
|
+
}),
|
|
566
|
+
);
|
|
567
|
+
|
|
568
|
+
const allPrs: Array<Record<string, unknown>> = [];
|
|
569
|
+
for (const r of results) {
|
|
570
|
+
if (r.status === 'fulfilled') allPrs.push(...r.value);
|
|
571
|
+
}
|
|
572
|
+
allPrs.sort((a, b) => String(b.createdAt).localeCompare(String(a.createdAt)));
|
|
573
|
+
res.json(allPrs);
|
|
574
|
+
} catch (err) {
|
|
575
|
+
log.error('PRs aggregation failed', { error: String(err) });
|
|
576
|
+
res.status(500).json({ error: 'Failed to aggregate PRs' });
|
|
577
|
+
}
|
|
578
|
+
});
|
|
579
|
+
|
|
580
|
+
router.get('/aggregate/git/health', async (_req, res) => {
|
|
581
|
+
try {
|
|
582
|
+
const projects = projectManager.getProjectList().filter(p => p.enabled && p.status === 'active');
|
|
583
|
+
|
|
584
|
+
const results = await Promise.allSettled(
|
|
585
|
+
projects.map(async (proj) => {
|
|
586
|
+
const ctx = projectManager.getContext(proj.id);
|
|
587
|
+
if (!ctx) throw new Error('offline');
|
|
588
|
+
const branches = await ctx.gitService.getBranches();
|
|
589
|
+
const config = ctx.workflowEngine.getConfig();
|
|
590
|
+
const listsWithBranch = config.lists.filter(l => l.gitBranch).sort((a, b) => a.order - b.order);
|
|
591
|
+
const driftPairs: Array<{ from: string; to: string }> = [];
|
|
592
|
+
for (let i = 0; i < listsWithBranch.length - 1; i++) {
|
|
593
|
+
driftPairs.push({ from: listsWithBranch[i].gitBranch!, to: listsWithBranch[i + 1].gitBranch! });
|
|
594
|
+
}
|
|
595
|
+
const drift = driftPairs.length > 0 ? await ctx.gitService.getDrift(driftPairs) : [];
|
|
596
|
+
const maxDrift = Math.max(0, ...drift.map(d => d.count));
|
|
597
|
+
const staleBranches = branches.filter(b => b.isStale && !b.isRemote);
|
|
598
|
+
|
|
599
|
+
return {
|
|
600
|
+
projectId: proj.id,
|
|
601
|
+
projectName: proj.name,
|
|
602
|
+
projectColor: proj.color,
|
|
603
|
+
branchCount: branches.filter(b => !b.isRemote).length,
|
|
604
|
+
staleBranchCount: staleBranches.length,
|
|
605
|
+
featureBranchCount: branches.filter(b => !b.isRemote && /(?:feat|fix|scope)[/-]/.test(b.name)).length,
|
|
606
|
+
maxDriftSeverity: maxDrift === 0 ? 'clean' : maxDrift <= 5 ? 'low' : maxDrift <= 20 ? 'moderate' : 'high',
|
|
607
|
+
};
|
|
608
|
+
}),
|
|
609
|
+
);
|
|
610
|
+
|
|
611
|
+
const health: Array<Record<string, unknown>> = [];
|
|
612
|
+
for (const r of results) {
|
|
613
|
+
if (r.status === 'fulfilled') health.push(r.value);
|
|
614
|
+
}
|
|
615
|
+
res.json(health);
|
|
616
|
+
} catch (err) {
|
|
617
|
+
log.error('Branch health failed', { error: String(err) });
|
|
618
|
+
res.status(500).json({ error: 'Failed to aggregate branch health' });
|
|
619
|
+
}
|
|
620
|
+
});
|
|
621
|
+
|
|
622
|
+
router.get('/aggregate/git/activity', async (req, res) => {
|
|
623
|
+
try {
|
|
624
|
+
const days = Number(req.query.days) || 30;
|
|
625
|
+
const projects = projectManager.getProjectList().filter(p => p.enabled && p.status === 'active');
|
|
626
|
+
|
|
627
|
+
const results = await Promise.allSettled(
|
|
628
|
+
projects.map(async (proj) => {
|
|
629
|
+
const ctx = projectManager.getContext(proj.id);
|
|
630
|
+
if (!ctx) return { projectId: proj.id, series: [] };
|
|
631
|
+
const series = await ctx.gitService.getActivitySeries(days);
|
|
632
|
+
return { projectId: proj.id, projectName: proj.name, projectColor: proj.color, series };
|
|
633
|
+
}),
|
|
634
|
+
);
|
|
635
|
+
|
|
636
|
+
const activity: Array<Record<string, unknown>> = [];
|
|
637
|
+
for (const r of results) {
|
|
638
|
+
if (r.status === 'fulfilled') activity.push(r.value);
|
|
639
|
+
}
|
|
640
|
+
res.json(activity);
|
|
641
|
+
} catch (err) {
|
|
642
|
+
log.error('Activity aggregation failed', { error: String(err) });
|
|
643
|
+
res.status(500).json({ error: 'Failed to aggregate activity' });
|
|
644
|
+
}
|
|
645
|
+
});
|
|
646
|
+
|
|
647
|
+
router.get('/aggregate/scopes/:id/readiness', (req, res) => {
|
|
648
|
+
const scopeId = Number(req.params.id);
|
|
649
|
+
const projectId = req.query.project_id as string | undefined;
|
|
650
|
+
|
|
651
|
+
for (const [pid, ctx] of projectManager.getAllContexts()) {
|
|
652
|
+
if (projectId && pid !== projectId) continue;
|
|
653
|
+
const scope = ctx.scopeService.getById(scopeId);
|
|
654
|
+
if (scope) {
|
|
655
|
+
const readiness = ctx.readinessService.getReadiness(scopeId);
|
|
656
|
+
if (readiness) {
|
|
657
|
+
res.json(readiness);
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
res.status(404).json({ error: 'Scope not found in any project' });
|
|
663
|
+
});
|
|
664
|
+
|
|
665
|
+
router.get('/aggregate/dispatch/active-scopes', (_req, res) => {
|
|
666
|
+
const allActive: Array<{ scope_id: number; project_id: string }> = [];
|
|
667
|
+
const seenActive = new Set<string>();
|
|
668
|
+
const allAbandoned: Array<{ scope_id: number; project_id: string; from_status: string | null; abandoned_at: string }> = [];
|
|
669
|
+
const seenAbandoned = new Set<string>();
|
|
670
|
+
|
|
671
|
+
for (const [projectId, ctx] of projectManager.getAllContexts()) {
|
|
672
|
+
const activeIds = getActiveScopeIds(ctx.db, ctx.scopeService, ctx.workflowEngine);
|
|
673
|
+
for (const id of activeIds) {
|
|
674
|
+
const key = `${projectId}::${id}`;
|
|
675
|
+
if (!seenActive.has(key)) {
|
|
676
|
+
seenActive.add(key);
|
|
677
|
+
allActive.push({ scope_id: id, project_id: projectId });
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
const abandoned = getAbandonedScopeIds(ctx.db, ctx.scopeService, ctx.workflowEngine, activeIds);
|
|
682
|
+
for (const entry of abandoned) {
|
|
683
|
+
const key = `${projectId}::${entry.scope_id}`;
|
|
684
|
+
if (!seenAbandoned.has(key)) {
|
|
685
|
+
seenAbandoned.add(key);
|
|
686
|
+
allAbandoned.push({ ...entry, project_id: projectId });
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
res.json({ scope_ids: allActive, abandoned_scopes: allAbandoned });
|
|
692
|
+
});
|
|
693
|
+
|
|
694
|
+
router.get('/aggregate/dispatch/active', (req, res) => {
|
|
695
|
+
const scopeId = Number(req.query.scope_id);
|
|
696
|
+
if (isNaN(scopeId) || scopeId <= 0) {
|
|
697
|
+
res.status(400).json({ error: 'Valid scope_id query param required' });
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
for (const [, ctx] of projectManager.getAllContexts()) {
|
|
702
|
+
const scope = ctx.scopeService.getById(scopeId);
|
|
703
|
+
if (!scope) continue;
|
|
704
|
+
|
|
705
|
+
const active = ctx.db.prepare(
|
|
706
|
+
`SELECT id, timestamp, JSON_EXTRACT(data, '$.command') as command
|
|
707
|
+
FROM events
|
|
708
|
+
WHERE type = 'DISPATCH' AND scope_id = ? AND JSON_EXTRACT(data, '$.resolved') IS NULL
|
|
709
|
+
ORDER BY timestamp DESC LIMIT 1`
|
|
710
|
+
).get(scopeId) as { id: string; timestamp: string; command: string } | undefined;
|
|
711
|
+
|
|
712
|
+
res.json({ active: active ?? null });
|
|
713
|
+
return;
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
res.json({ active: null });
|
|
717
|
+
});
|
|
718
|
+
|
|
719
|
+
// ─── Aggregate: Manifest Health ────────────────────────────
|
|
720
|
+
|
|
721
|
+
router.get('/aggregate/manifest/status', (_req, res) => {
|
|
722
|
+
try {
|
|
723
|
+
const projects = projectManager.getProjectList().filter(p => p.enabled);
|
|
724
|
+
const pkgVersion = getPackageVersion();
|
|
725
|
+
|
|
726
|
+
const projectOverviews = projects.map((proj) => {
|
|
727
|
+
const ctx = projectManager.getContext(proj.id);
|
|
728
|
+
if (!ctx) {
|
|
729
|
+
return {
|
|
730
|
+
projectId: proj.id,
|
|
731
|
+
projectName: proj.name,
|
|
732
|
+
projectColor: proj.color,
|
|
733
|
+
status: 'error' as const,
|
|
734
|
+
manifest: null,
|
|
735
|
+
error: 'Project offline',
|
|
736
|
+
};
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
try {
|
|
740
|
+
const manifest = loadManifest(ctx.config.projectRoot);
|
|
741
|
+
if (!manifest) {
|
|
742
|
+
return {
|
|
743
|
+
projectId: proj.id,
|
|
744
|
+
projectName: proj.name,
|
|
745
|
+
projectColor: proj.color,
|
|
746
|
+
status: 'no-manifest' as const,
|
|
747
|
+
manifest: null,
|
|
748
|
+
};
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
const claudeDir = path.join(ctx.config.projectRoot, '.claude');
|
|
752
|
+
refreshFileStatuses(manifest, claudeDir);
|
|
753
|
+
const summary = summarizeManifest(manifest);
|
|
754
|
+
|
|
755
|
+
return {
|
|
756
|
+
projectId: proj.id,
|
|
757
|
+
projectName: proj.name,
|
|
758
|
+
projectColor: proj.color,
|
|
759
|
+
status: 'ok' as const,
|
|
760
|
+
manifest: {
|
|
761
|
+
exists: true,
|
|
762
|
+
packageVersion: pkgVersion,
|
|
763
|
+
installedVersion: manifest.packageVersion,
|
|
764
|
+
needsUpdate: manifest.packageVersion !== pkgVersion,
|
|
765
|
+
preset: manifest.preset,
|
|
766
|
+
files: summary,
|
|
767
|
+
lastUpdated: manifest.updatedAt,
|
|
768
|
+
},
|
|
769
|
+
};
|
|
770
|
+
} catch (err) {
|
|
771
|
+
return {
|
|
772
|
+
projectId: proj.id,
|
|
773
|
+
projectName: proj.name,
|
|
774
|
+
projectColor: proj.color,
|
|
775
|
+
status: 'error' as const,
|
|
776
|
+
manifest: null,
|
|
777
|
+
error: String(err),
|
|
778
|
+
};
|
|
779
|
+
}
|
|
780
|
+
});
|
|
781
|
+
|
|
782
|
+
const projectsUpToDate = projectOverviews.filter(p => p.status === 'ok' && !p.manifest?.needsUpdate).length;
|
|
783
|
+
const projectsOutdated = projectOverviews.filter(p => p.status === 'ok' && p.manifest?.needsUpdate).length;
|
|
784
|
+
const noManifest = projectOverviews.filter(p => p.status === 'no-manifest').length;
|
|
785
|
+
const totalOutdated = projectOverviews.reduce((sum, p) => sum + (p.manifest?.files.outdated ?? 0), 0);
|
|
786
|
+
const totalModified = projectOverviews.reduce((sum, p) => sum + (p.manifest?.files.modified ?? 0), 0);
|
|
787
|
+
const totalPinned = projectOverviews.reduce((sum, p) => sum + (p.manifest?.files.pinned ?? 0), 0);
|
|
788
|
+
const totalMissing = projectOverviews.reduce((sum, p) => sum + (p.manifest?.files.missing ?? 0), 0);
|
|
789
|
+
const totalSynced = projectOverviews.reduce((sum, p) => sum + (p.manifest?.files.synced ?? 0), 0);
|
|
790
|
+
const totalUserOwned = projectOverviews.reduce((sum, p) => sum + (p.manifest?.files.userOwned ?? 0), 0);
|
|
791
|
+
|
|
792
|
+
res.json({
|
|
793
|
+
total: projects.length,
|
|
794
|
+
projectsUpToDate,
|
|
795
|
+
projectsOutdated,
|
|
796
|
+
noManifest,
|
|
797
|
+
totalOutdated,
|
|
798
|
+
totalModified,
|
|
799
|
+
totalPinned,
|
|
800
|
+
totalMissing,
|
|
801
|
+
totalSynced,
|
|
802
|
+
totalUserOwned,
|
|
803
|
+
projects: projectOverviews,
|
|
804
|
+
});
|
|
805
|
+
} catch (err) {
|
|
806
|
+
log.error('Manifest status failed', { error: String(err) });
|
|
807
|
+
res.status(500).json({ error: 'Failed to aggregate manifest status' });
|
|
808
|
+
}
|
|
809
|
+
});
|
|
810
|
+
|
|
811
|
+
router.post('/aggregate/manifest/update-all', (_req, res) => {
|
|
812
|
+
try {
|
|
813
|
+
const projects = projectManager.getProjectList().filter(p => p.enabled);
|
|
814
|
+
const pkgVersion = getPackageVersion();
|
|
815
|
+
const results: Array<{ projectId: string; success: boolean; error?: string }> = [];
|
|
816
|
+
|
|
817
|
+
for (const proj of projects) {
|
|
818
|
+
const ctx = projectManager.getContext(proj.id);
|
|
819
|
+
if (!ctx) {
|
|
820
|
+
results.push({ projectId: proj.id, success: false, error: 'Project offline' });
|
|
821
|
+
continue;
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
const manifest = loadManifest(ctx.config.projectRoot);
|
|
825
|
+
if (!manifest) continue; // uninitialized — skip
|
|
826
|
+
|
|
827
|
+
// Refresh statuses and check if there's anything to update
|
|
828
|
+
const claudeDir = path.join(ctx.config.projectRoot, '.claude');
|
|
829
|
+
refreshFileStatuses(manifest, claudeDir);
|
|
830
|
+
const manifestSummary = summarizeManifest(manifest);
|
|
831
|
+
if (manifest.packageVersion === pkgVersion && manifestSummary.outdated === 0 && manifestSummary.missing === 0) {
|
|
832
|
+
continue; // fully up to date
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
try {
|
|
836
|
+
runUpdate(ctx.config.projectRoot, { dryRun: false });
|
|
837
|
+
ctx.emitter.emit('manifest:changed', { action: 'updated' });
|
|
838
|
+
results.push({ projectId: proj.id, success: true });
|
|
839
|
+
} catch (err) {
|
|
840
|
+
results.push({ projectId: proj.id, success: false, error: String(err) });
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
res.json({ success: true, results });
|
|
845
|
+
} catch (err) {
|
|
846
|
+
log.error('Update all projects failed', { error: String(err) });
|
|
847
|
+
res.status(500).json({ error: 'Failed to update all projects' });
|
|
848
|
+
}
|
|
849
|
+
});
|
|
850
|
+
|
|
851
|
+
// ─── Global: Dispatch Config ────────────────────────────────
|
|
852
|
+
// Dispatch settings are global — stored in ~/.orbital/config.json.
|
|
853
|
+
// Changes propagate to all active projects' in-memory config.
|
|
854
|
+
|
|
855
|
+
router.get('/aggregate/config/dispatch-flags', (_req, res) => {
|
|
856
|
+
const global = loadGlobalConfig();
|
|
857
|
+
res.json({ success: true, data: global.dispatchFlags ?? DEFAULT_DISPATCH_FLAGS });
|
|
858
|
+
});
|
|
859
|
+
|
|
860
|
+
router.put('/aggregate/config/dispatch-flags', (req, res) => {
|
|
861
|
+
const updates = req.body as Partial<DispatchFlags>;
|
|
862
|
+
const error = validateDispatchFlags(updates);
|
|
863
|
+
if (error) { res.status(400).json({ success: false, error }); return; }
|
|
864
|
+
const global = loadGlobalConfig();
|
|
865
|
+
const merged: DispatchFlags = { ...(global.dispatchFlags ?? DEFAULT_DISPATCH_FLAGS), ...updates };
|
|
866
|
+
global.dispatchFlags = merged;
|
|
867
|
+
saveGlobalConfig(global);
|
|
868
|
+
for (const [, ctx] of projectManager.getAllContexts()) {
|
|
869
|
+
ctx.config.claude.dispatchFlags = merged;
|
|
870
|
+
}
|
|
871
|
+
res.json({ success: true, data: merged });
|
|
872
|
+
});
|
|
873
|
+
|
|
874
|
+
router.get('/aggregate/config/dispatch-settings', (_req, res) => {
|
|
875
|
+
const global = loadGlobalConfig();
|
|
876
|
+
res.json({
|
|
877
|
+
success: true,
|
|
878
|
+
data: { ...(global.dispatch ?? DEFAULT_DISPATCH_CONFIG), terminalAdapter: global.terminalAdapter ?? 'auto' },
|
|
879
|
+
});
|
|
880
|
+
});
|
|
881
|
+
|
|
882
|
+
router.put('/aggregate/config/dispatch-settings', (req, res) => {
|
|
883
|
+
const { terminalAdapter, ...dispatchUpdates } = req.body as Partial<DispatchConfig> & { terminalAdapter?: string };
|
|
884
|
+
const error = validateDispatchConfig({ ...dispatchUpdates, terminalAdapter });
|
|
885
|
+
if (error) { res.status(400).json({ success: false, error }); return; }
|
|
886
|
+
const global = loadGlobalConfig();
|
|
887
|
+
const mergedDispatch: DispatchConfig = { ...(global.dispatch ?? DEFAULT_DISPATCH_CONFIG), ...dispatchUpdates };
|
|
888
|
+
global.dispatch = mergedDispatch;
|
|
889
|
+
if (terminalAdapter) global.terminalAdapter = terminalAdapter;
|
|
890
|
+
saveGlobalConfig(global);
|
|
891
|
+
for (const [, ctx] of projectManager.getAllContexts()) {
|
|
892
|
+
ctx.config.dispatch = mergedDispatch;
|
|
893
|
+
if (terminalAdapter) ctx.config.terminal.adapter = terminalAdapter as typeof ctx.config.terminal.adapter;
|
|
894
|
+
}
|
|
895
|
+
res.json({ success: true, data: { ...mergedDispatch, terminalAdapter: global.terminalAdapter ?? 'auto' } });
|
|
896
|
+
});
|
|
897
|
+
|
|
898
|
+
// ─── Aggregate: Config Primitives (Global) ────────────────
|
|
899
|
+
// In aggregate mode, config reads/writes target ~/.orbital/primitives/
|
|
900
|
+
// Writes propagate to all synced (non-overridden) projects via SyncService.
|
|
901
|
+
|
|
902
|
+
const globalConfigService = new ConfigService(GLOBAL_PRIMITIVES_DIR);
|
|
903
|
+
|
|
904
|
+
router.get('/aggregate/config/:type/tree', (req, res) => {
|
|
905
|
+
const type = req.params.type;
|
|
906
|
+
if (!isValidPrimitiveType(type)) {
|
|
907
|
+
res.status(400).json({ success: false, error: `Invalid type "${type}". Must be one of: agents, skills, hooks` });
|
|
908
|
+
return;
|
|
909
|
+
}
|
|
910
|
+
try {
|
|
911
|
+
const basePath = path.join(GLOBAL_PRIMITIVES_DIR, type);
|
|
912
|
+
const tree = globalConfigService.scanDirectory(basePath);
|
|
913
|
+
res.json({ success: true, data: tree });
|
|
914
|
+
} catch (err) {
|
|
915
|
+
log.error('Config tree read failed', { type, error: String(err) });
|
|
916
|
+
res.status(500).json({ success: false, error: 'Failed to read global config tree' });
|
|
917
|
+
}
|
|
918
|
+
});
|
|
919
|
+
|
|
920
|
+
router.get('/aggregate/config/:type/file', (req, res) => {
|
|
921
|
+
const type = req.params.type;
|
|
922
|
+
if (!isValidPrimitiveType(type)) {
|
|
923
|
+
res.status(400).json({ success: false, error: `Invalid type "${type}". Must be one of: agents, skills, hooks` });
|
|
924
|
+
return;
|
|
925
|
+
}
|
|
926
|
+
const filePath = req.query.path as string | undefined;
|
|
927
|
+
if (!filePath) { res.status(400).json({ success: false, error: 'path query parameter is required' }); return; }
|
|
928
|
+
|
|
929
|
+
try {
|
|
930
|
+
const basePath = path.join(GLOBAL_PRIMITIVES_DIR, type);
|
|
931
|
+
const content = globalConfigService.readFile(basePath, filePath);
|
|
932
|
+
res.json({ success: true, data: { path: filePath, content } });
|
|
933
|
+
} catch (err) {
|
|
934
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
935
|
+
const status = msg.includes('traversal') ? 403 : msg.includes('ENOENT') || msg.includes('not found') ? 404 : 500;
|
|
936
|
+
res.status(status).json({ success: false, error: msg });
|
|
937
|
+
}
|
|
938
|
+
});
|
|
939
|
+
|
|
940
|
+
router.put('/aggregate/config/:type/file', (req, res) => {
|
|
941
|
+
const type = req.params.type;
|
|
942
|
+
if (!isValidPrimitiveType(type)) {
|
|
943
|
+
res.status(400).json({ success: false, error: `Invalid type "${type}". Must be one of: agents, skills, hooks` });
|
|
944
|
+
return;
|
|
945
|
+
}
|
|
946
|
+
const { path: filePath, content } = req.body as { path?: string; content?: string };
|
|
947
|
+
if (!filePath || content === undefined) {
|
|
948
|
+
res.status(400).json({ success: false, error: 'path and content are required' });
|
|
949
|
+
return;
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
try {
|
|
953
|
+
const basePath = path.join(GLOBAL_PRIMITIVES_DIR, type);
|
|
954
|
+
globalConfigService.writeFile(basePath, filePath, content);
|
|
955
|
+
// Propagate to all synced projects
|
|
956
|
+
const relativePath = path.join(type, filePath);
|
|
957
|
+
const result = syncService.propagateGlobalChange(relativePath);
|
|
958
|
+
io.emit(`config:${type}:changed`, { action: 'updated', path: filePath, global: true });
|
|
959
|
+
res.json({ success: true, propagation: result });
|
|
960
|
+
} catch (err) {
|
|
961
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
962
|
+
const status = msg.includes('traversal') ? 403 : msg.includes('not found') ? 404 : 500;
|
|
963
|
+
res.status(status).json({ success: false, error: msg });
|
|
964
|
+
}
|
|
965
|
+
});
|
|
966
|
+
|
|
967
|
+
return router;
|
|
968
|
+
}
|