orbital-command 0.1.4 → 0.3.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/bin/orbital.js +676 -53
- package/dist/assets/PrimitivesConfig-CrmQXYh4.js +32 -0
- package/dist/assets/QualityGates-BbasOsF3.js +21 -0
- package/dist/assets/SessionTimeline-CGeJsVvy.js +1 -0
- package/dist/assets/Settings-oiM496mc.js +12 -0
- package/dist/assets/SourceControl-B1fP2nJL.js +41 -0
- package/dist/assets/WorkflowVisualizer-CWLYf-f0.js +74 -0
- package/dist/assets/arrow-down-CPy85_J6.js +6 -0
- package/dist/assets/charts-DbDg0Psc.js +68 -0
- package/dist/assets/circle-x-Cwz6ZQDV.js +6 -0
- package/dist/assets/file-text-C46Xr65c.js +6 -0
- package/dist/assets/formatDistanceToNow-BMqsSP44.js +1 -0
- package/dist/assets/globe-Cn2yNZUD.js +6 -0
- package/dist/assets/index-Aj4sV8Al.css +1 -0
- package/dist/assets/index-Bc9dK3MW.js +354 -0
- package/dist/assets/key-OPaNTWJ5.js +6 -0
- package/dist/assets/minus-GMsbpKym.js +6 -0
- package/dist/assets/shield-DwAFkDYI.js +6 -0
- package/dist/assets/ui-BmsSg9jU.js +53 -0
- package/dist/assets/useWorkflowEditor-BJkTX_NR.js +16 -0
- package/dist/assets/{vendor-Dzv9lrRc.js → vendor-Bqt8AJn2.js} +1 -1
- package/dist/assets/zap-DfbUoOty.js +11 -0
- package/dist/favicon.svg +1 -0
- package/dist/index.html +6 -5
- package/dist/server/server/__tests__/data-routes.test.js +124 -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 +137 -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 +138 -0
- package/dist/server/server/config.js +17 -2
- package/dist/server/server/database.js +27 -12
- package/dist/server/server/global-config.js +143 -0
- package/dist/server/server/index.js +882 -252
- package/dist/server/server/init.js +579 -194
- 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.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 +255 -0
- package/dist/server/server/project-emitter.js +41 -0
- package/dist/server/server/project-manager.js +297 -0
- package/dist/server/server/routes/config-routes.js +1 -3
- package/dist/server/server/routes/data-routes.js +22 -110
- package/dist/server/server/routes/dispatch-routes.js +15 -9
- 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 +37 -23
- 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 +2 -0
- package/dist/server/server/services/batch-orchestrator.js +26 -16
- package/dist/server/server/services/claude-session-service.js +17 -14
- 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 +217 -126
- package/dist/server/server/services/scope-service.test.js +137 -0
- package/dist/server/server/services/sprint-orchestrator.js +7 -6
- package/dist/server/server/services/sprint-service.js +21 -1
- 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/telemetry-service.js +143 -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/update-planner.js +279 -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 +77 -20
- package/dist/server/server/utils/dispatch-utils.test.js +182 -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 +10 -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/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 +155 -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 +35 -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 +74 -0
- package/dist/server/shared/__fixtures__/workflow-configs.js +75 -0
- 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.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 +20 -15
- package/schemas/orbital.config.schema.json +16 -1
- package/scripts/postinstall.js +55 -7
- package/server/__tests__/data-routes.test.ts +149 -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 +157 -0
- package/server/__tests__/sprint-routes.test.ts +118 -0
- package/server/__tests__/workflow-routes.test.ts +120 -0
- package/server/config-migrator.ts +163 -0
- package/server/config.ts +26 -2
- package/server/database.ts +35 -18
- package/server/global-config.ts +200 -0
- package/server/index.ts +975 -287
- package/server/init.ts +625 -182
- 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/scope-parser.test.ts +270 -0
- package/server/parsers/scope-parser.ts +79 -31
- package/server/project-context.ts +309 -0
- package/server/project-emitter.ts +50 -0
- package/server/project-manager.ts +369 -0
- package/server/routes/config-routes.ts +3 -5
- package/server/routes/data-routes.ts +28 -141
- package/server/routes/dispatch-routes.ts +19 -11
- package/server/routes/git-routes.ts +77 -0
- package/server/routes/manifest-routes.ts +388 -0
- package/server/routes/scope-routes.ts +29 -25
- 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 +2 -0
- package/server/services/batch-orchestrator.ts +24 -16
- package/server/services/claude-session-service.ts +16 -14
- 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 +220 -126
- package/server/services/sprint-orchestrator.ts +7 -7
- package/server/services/sprint-service.test.ts +271 -0
- package/server/services/sprint-service.ts +27 -3
- package/server/services/sync-service.ts +482 -0
- package/server/services/sync-types.ts +77 -0
- package/server/services/telemetry-service.ts +195 -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/update-planner.ts +346 -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 +97 -27
- package/server/utils/logger.ts +40 -3
- package/server/utils/package-info.ts +32 -0
- package/server/utils/route-helpers.ts +12 -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/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 +187 -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 +43 -0
- package/server/wizard/phases/workflow-setup.ts +28 -0
- package/server/wizard/types.ts +56 -0
- package/server/wizard/ui.ts +93 -0
- package/shared/__fixtures__/workflow-configs.ts +80 -0
- package/shared/default-workflow.json +65 -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-normalizer.test.ts +119 -0
- package/shared/workflow-normalizer.ts +118 -0
- package/templates/hooks/end-session.sh +3 -1
- 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-create-cleanup.sh +2 -2
- package/templates/hooks/scope-create-gate.sh +0 -1
- package/templates/hooks/scope-helpers.sh +18 -0
- package/templates/hooks/scope-prepare.sh +66 -11
- package/templates/migrations/renames.json +1 -0
- package/templates/orbital.config.json +7 -2
- package/templates/settings-hooks.json +1 -1
- package/templates/skills/git-commit/SKILL.md +9 -4
- package/templates/skills/git-dev/SKILL.md +8 -3
- package/templates/skills/git-main/SKILL.md +8 -2
- package/templates/skills/git-production/SKILL.md +6 -2
- package/templates/skills/git-staging/SKILL.md +8 -3
- package/templates/skills/scope-create/SKILL.md +17 -3
- package/templates/skills/scope-fix-review/SKILL.md +6 -3
- package/templates/skills/scope-implement/SKILL.md +4 -1
- package/templates/skills/scope-post-review/SKILL.md +63 -5
- package/templates/skills/scope-pre-review/SKILL.md +5 -2
- 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 -49
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { describe, it, expect, beforeAll, vi } from 'vitest';
|
|
2
|
+
import express from 'express';
|
|
3
|
+
import request from 'supertest';
|
|
4
|
+
import { createWorkflowRoutes } from '../routes/workflow-routes.js';
|
|
5
|
+
import { WorkflowEngine } from '../../shared/workflow-engine.js';
|
|
6
|
+
import { DEFAULT_CONFIG, MINIMAL_CONFIG } from '../../shared/__fixtures__/workflow-configs.js';
|
|
7
|
+
|
|
8
|
+
describe('workflow-routes', () => {
|
|
9
|
+
let app: express.Express;
|
|
10
|
+
const engine = new WorkflowEngine(DEFAULT_CONFIG);
|
|
11
|
+
|
|
12
|
+
const mockWorkflowService = {
|
|
13
|
+
getActive: vi.fn().mockReturnValue(DEFAULT_CONFIG),
|
|
14
|
+
updateActive: vi.fn().mockReturnValue({ valid: true, errors: [], warnings: [] }),
|
|
15
|
+
listPresets: vi.fn().mockReturnValue([{ name: 'default', createdAt: '2026-01-01', listCount: 7, edgeCount: 14 }]),
|
|
16
|
+
savePreset: vi.fn(),
|
|
17
|
+
getPreset: vi.fn((name: string) => name === 'default' ? DEFAULT_CONFIG : (() => { throw new Error('Not found'); })()),
|
|
18
|
+
deletePreset: vi.fn((name: string) => { if (name === 'default') throw new Error('Cannot delete default'); }),
|
|
19
|
+
previewMigration: vi.fn().mockReturnValue({ orphanedScopes: [], addedLists: [], removedLists: [], scopeMoves: [] }),
|
|
20
|
+
applyMigration: vi.fn().mockReturnValue({ orphanedScopes: [], addedLists: [], removedLists: [], scopeMoves: [] }),
|
|
21
|
+
getEngine: vi.fn().mockReturnValue(engine),
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
beforeAll(() => {
|
|
25
|
+
const router = createWorkflowRoutes({
|
|
26
|
+
workflowService: mockWorkflowService as any,
|
|
27
|
+
projectRoot: '/tmp/test-project',
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
app = express();
|
|
31
|
+
app.use(express.json());
|
|
32
|
+
app.use('/api/orbital', router);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
describe('GET /workflow', () => {
|
|
36
|
+
it('returns active workflow config', async () => {
|
|
37
|
+
const res = await request(app).get('/api/orbital/workflow');
|
|
38
|
+
expect(res.status).toBe(200);
|
|
39
|
+
expect(res.body.success).toBe(true);
|
|
40
|
+
expect(res.body.data.name).toBe('Default Workflow');
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe('PUT /workflow', () => {
|
|
45
|
+
it('updates workflow config', async () => {
|
|
46
|
+
const res = await request(app)
|
|
47
|
+
.put('/api/orbital/workflow')
|
|
48
|
+
.send(MINIMAL_CONFIG);
|
|
49
|
+
expect(res.status).toBe(200);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('returns 400 for invalid config', async () => {
|
|
53
|
+
mockWorkflowService.updateActive.mockReturnValueOnce({ valid: false, errors: ['Missing lists'], warnings: [] });
|
|
54
|
+
const res = await request(app)
|
|
55
|
+
.put('/api/orbital/workflow')
|
|
56
|
+
.send({ version: 1, name: 'Bad', lists: [], edges: [] });
|
|
57
|
+
expect(res.status).toBe(400);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe('GET /workflow/presets', () => {
|
|
62
|
+
it('returns preset list', async () => {
|
|
63
|
+
const res = await request(app).get('/api/orbital/workflow/presets');
|
|
64
|
+
expect(res.status).toBe(200);
|
|
65
|
+
expect(res.body.success).toBe(true);
|
|
66
|
+
expect(Array.isArray(res.body.data)).toBe(true);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
describe('POST /workflow/presets', () => {
|
|
71
|
+
it('saves preset with valid name', async () => {
|
|
72
|
+
const res = await request(app)
|
|
73
|
+
.post('/api/orbital/workflow/presets')
|
|
74
|
+
.send({ name: 'my-preset' });
|
|
75
|
+
expect(res.status).toBe(200);
|
|
76
|
+
expect(mockWorkflowService.savePreset).toHaveBeenCalledWith('my-preset');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('rejects missing name (400)', async () => {
|
|
80
|
+
const res = await request(app)
|
|
81
|
+
.post('/api/orbital/workflow/presets')
|
|
82
|
+
.send({});
|
|
83
|
+
expect(res.status).toBe(400);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
describe('DELETE /workflow/presets/:name', () => {
|
|
88
|
+
it('rejects deleting default preset', async () => {
|
|
89
|
+
const res = await request(app).delete('/api/orbital/workflow/presets/default');
|
|
90
|
+
expect(res.status).toBe(400);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
describe('GET /workflow/hooks', () => {
|
|
95
|
+
it('returns hooks with edge mapping', async () => {
|
|
96
|
+
const res = await request(app).get('/api/orbital/workflow/hooks');
|
|
97
|
+
expect(res.status).toBe(200);
|
|
98
|
+
expect(res.body.success).toBe(true);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
describe('GET /workflow/hooks/:id/source', () => {
|
|
103
|
+
it('rejects path traversal attempts', async () => {
|
|
104
|
+
// The engine has hooks with targets like '.claude/hooks/blocker-check.sh'
|
|
105
|
+
// Trying to traverse out should fail
|
|
106
|
+
const res = await request(app).get('/api/orbital/workflow/hooks/../../etc/passwd/source');
|
|
107
|
+
expect([400, 404]).toContain(res.status);
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
describe('POST /workflow/preview', () => {
|
|
112
|
+
it('returns migration preview', async () => {
|
|
113
|
+
const res = await request(app)
|
|
114
|
+
.post('/api/orbital/workflow/preview')
|
|
115
|
+
.send(MINIMAL_CONFIG);
|
|
116
|
+
expect(res.status).toBe(200);
|
|
117
|
+
expect(res.body.success).toBe(true);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
});
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config migration runner for orbital.config.json.
|
|
3
|
+
*
|
|
4
|
+
* Applies incremental, idempotent migrations when upgrading between
|
|
5
|
+
* package versions. Also fills schema defaults for new fields that
|
|
6
|
+
* don't require explicit migration logic.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import fs from 'fs';
|
|
10
|
+
import type { ConfigMigration } from './manifest-types.js';
|
|
11
|
+
|
|
12
|
+
// ─── Migration Registry ─────────────────────────────────────
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* All config migrations, ordered by target version.
|
|
16
|
+
*
|
|
17
|
+
* Rules:
|
|
18
|
+
* - Each migration MUST be idempotent (safe to run twice)
|
|
19
|
+
* - Each migration MUST check before applying (don't blindly overwrite)
|
|
20
|
+
* - ID format: "fromVersion->toVersion"
|
|
21
|
+
*/
|
|
22
|
+
const MIGRATIONS: ConfigMigration[] = [
|
|
23
|
+
// Future migrations go here. Example:
|
|
24
|
+
// {
|
|
25
|
+
// id: '0.2.0->0.3.0',
|
|
26
|
+
// description: 'Add notifications config section',
|
|
27
|
+
// migrate: (config) => {
|
|
28
|
+
// if (!('notifications' in config)) {
|
|
29
|
+
// config.notifications = { enabled: false };
|
|
30
|
+
// }
|
|
31
|
+
// return config;
|
|
32
|
+
// },
|
|
33
|
+
// },
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
// ─── Schema Defaults ────────────────────────────────────────
|
|
37
|
+
|
|
38
|
+
/** Default values from the schema, keyed by property path. */
|
|
39
|
+
const SCHEMA_DEFAULTS: Record<string, unknown> = {
|
|
40
|
+
projectName: 'My Project',
|
|
41
|
+
scopesDir: 'scopes',
|
|
42
|
+
eventsDir: '.claude/orbital-events',
|
|
43
|
+
dbDir: '.claude/orbital',
|
|
44
|
+
configDir: '.claude/config',
|
|
45
|
+
serverPort: 4444,
|
|
46
|
+
clientPort: 4445,
|
|
47
|
+
logLevel: 'info',
|
|
48
|
+
categories: ['feature', 'bugfix', 'refactor', 'infrastructure', 'docs'],
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const NESTED_DEFAULTS: Record<string, Record<string, unknown>> = {
|
|
52
|
+
terminal: {
|
|
53
|
+
adapter: 'auto',
|
|
54
|
+
profilePrefix: 'Orbital',
|
|
55
|
+
},
|
|
56
|
+
claude: {
|
|
57
|
+
executable: 'claude',
|
|
58
|
+
flags: ['--dangerously-skip-permissions'],
|
|
59
|
+
},
|
|
60
|
+
commands: {
|
|
61
|
+
typeCheck: null,
|
|
62
|
+
lint: null,
|
|
63
|
+
build: null,
|
|
64
|
+
test: null,
|
|
65
|
+
validateTemplates: null,
|
|
66
|
+
validateDocs: null,
|
|
67
|
+
checkRules: null,
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// ─── Public API ─────────────────────────────────────────────
|
|
72
|
+
|
|
73
|
+
export interface MigrationResult {
|
|
74
|
+
applied: string[];
|
|
75
|
+
defaultsFilled: string[];
|
|
76
|
+
errors: string[];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Run all pending config migrations and fill schema defaults.
|
|
81
|
+
*
|
|
82
|
+
* @param configPath - Path to orbital.config.json
|
|
83
|
+
* @param appliedMigrations - IDs already recorded in the manifest
|
|
84
|
+
* @returns List of migration IDs that were applied
|
|
85
|
+
*/
|
|
86
|
+
export function migrateConfig(
|
|
87
|
+
configPath: string,
|
|
88
|
+
appliedMigrations: string[],
|
|
89
|
+
): MigrationResult {
|
|
90
|
+
const result: MigrationResult = { applied: [], defaultsFilled: [], errors: [] };
|
|
91
|
+
|
|
92
|
+
if (!fs.existsSync(configPath)) return result;
|
|
93
|
+
|
|
94
|
+
let config: Record<string, unknown>;
|
|
95
|
+
try {
|
|
96
|
+
config = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
|
|
97
|
+
} catch {
|
|
98
|
+
result.errors.push('Failed to parse orbital.config.json');
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const appliedSet = new Set(appliedMigrations);
|
|
103
|
+
|
|
104
|
+
// Apply explicit migrations in order
|
|
105
|
+
for (const migration of MIGRATIONS) {
|
|
106
|
+
if (appliedSet.has(migration.id)) continue;
|
|
107
|
+
|
|
108
|
+
try {
|
|
109
|
+
config = migration.migrate(config);
|
|
110
|
+
result.applied.push(migration.id);
|
|
111
|
+
} catch (err) {
|
|
112
|
+
result.errors.push(`Migration ${migration.id} failed: ${String(err)}`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Fill schema defaults for missing top-level properties
|
|
117
|
+
for (const [key, defaultValue] of Object.entries(SCHEMA_DEFAULTS)) {
|
|
118
|
+
if (!(key in config)) {
|
|
119
|
+
config[key] = defaultValue;
|
|
120
|
+
result.defaultsFilled.push(key);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Fill nested defaults
|
|
125
|
+
for (const [section, defaults] of Object.entries(NESTED_DEFAULTS)) {
|
|
126
|
+
if (!(section in config)) {
|
|
127
|
+
config[section] = { ...defaults };
|
|
128
|
+
result.defaultsFilled.push(section);
|
|
129
|
+
} else if (typeof config[section] === 'object' && config[section] !== null) {
|
|
130
|
+
const sectionObj = config[section] as Record<string, unknown>;
|
|
131
|
+
for (const [key, defaultValue] of Object.entries(defaults)) {
|
|
132
|
+
if (!(key in sectionObj)) {
|
|
133
|
+
sectionObj[key] = defaultValue;
|
|
134
|
+
result.defaultsFilled.push(`${section}.${key}`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Write back if any changes were made
|
|
141
|
+
if (result.applied.length > 0 || result.defaultsFilled.length > 0) {
|
|
142
|
+
fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + '\n', 'utf-8');
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return result;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Get all migration IDs that haven't been applied yet.
|
|
150
|
+
*/
|
|
151
|
+
export function getPendingMigrations(appliedMigrations: string[]): string[] {
|
|
152
|
+
const appliedSet = new Set(appliedMigrations);
|
|
153
|
+
return MIGRATIONS
|
|
154
|
+
.filter(m => !appliedSet.has(m.id))
|
|
155
|
+
.map(m => m.id);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Get all registered migrations (for display/debug).
|
|
160
|
+
*/
|
|
161
|
+
export function getAllMigrations(): Array<{ id: string; description: string }> {
|
|
162
|
+
return MIGRATIONS.map(m => ({ id: m.id, description: m.description }));
|
|
163
|
+
}
|
package/server/config.ts
CHANGED
|
@@ -29,6 +29,12 @@ export interface CommandsConfig {
|
|
|
29
29
|
export type { AgentConfig } from '../shared/api-types.js';
|
|
30
30
|
import type { AgentConfig } from '../shared/api-types.js';
|
|
31
31
|
|
|
32
|
+
export interface TelemetryConfig {
|
|
33
|
+
enabled: boolean;
|
|
34
|
+
url: string;
|
|
35
|
+
headers: Record<string, string>;
|
|
36
|
+
}
|
|
37
|
+
|
|
32
38
|
export interface OrbitalConfig {
|
|
33
39
|
projectName: string;
|
|
34
40
|
projectRoot: string;
|
|
@@ -58,6 +64,9 @@ export interface OrbitalConfig {
|
|
|
58
64
|
// Dynamic configuration
|
|
59
65
|
categories: string[];
|
|
60
66
|
agents: AgentConfig[];
|
|
67
|
+
|
|
68
|
+
// Telemetry
|
|
69
|
+
telemetry: TelemetryConfig;
|
|
61
70
|
}
|
|
62
71
|
|
|
63
72
|
// ─── Defaults ───────────────────────────────────────────────
|
|
@@ -88,6 +97,11 @@ const DEFAULT_CONFIG: Omit<OrbitalConfig, 'projectRoot'> = {
|
|
|
88
97
|
checkRules: null,
|
|
89
98
|
},
|
|
90
99
|
logLevel: 'info' as const,
|
|
100
|
+
telemetry: {
|
|
101
|
+
enabled: true,
|
|
102
|
+
url: '',
|
|
103
|
+
headers: {},
|
|
104
|
+
},
|
|
91
105
|
categories: ['feature', 'bugfix', 'refactor', 'infrastructure', 'docs'],
|
|
92
106
|
agents: [
|
|
93
107
|
{ id: 'attacker', label: 'Attacker', emoji: '\u{1F5E1}\u{FE0F}', color: '#ff1744' },
|
|
@@ -168,8 +182,11 @@ export function loadConfig(projectRoot?: string): OrbitalConfig {
|
|
|
168
182
|
}
|
|
169
183
|
}
|
|
170
184
|
|
|
171
|
-
// Merge with defaults
|
|
172
|
-
const
|
|
185
|
+
// Merge with defaults — derive project name from directory if not configured
|
|
186
|
+
const defaultProjectName = path.basename(root)
|
|
187
|
+
.replace(/[-_]+/g, ' ')
|
|
188
|
+
.replace(/\b\w/g, (c) => c.toUpperCase());
|
|
189
|
+
const projectName = (userConfig.projectName as string) ?? defaultProjectName;
|
|
173
190
|
|
|
174
191
|
const scopesDir = path.resolve(root, (userConfig.scopesDir as string) ?? DEFAULT_CONFIG.scopesDir);
|
|
175
192
|
const eventsDir = path.resolve(root, (userConfig.eventsDir as string) ?? DEFAULT_CONFIG.eventsDir);
|
|
@@ -198,6 +215,12 @@ export function loadConfig(projectRoot?: string): OrbitalConfig {
|
|
|
198
215
|
const categories = (userConfig.categories as string[]) ?? DEFAULT_CONFIG.categories;
|
|
199
216
|
const agents = (userConfig.agents as AgentConfig[]) ?? DEFAULT_CONFIG.agents;
|
|
200
217
|
|
|
218
|
+
const telemetry: TelemetryConfig = {
|
|
219
|
+
...DEFAULT_CONFIG.telemetry,
|
|
220
|
+
...(userConfig.telemetry as Partial<TelemetryConfig> ?? {}),
|
|
221
|
+
};
|
|
222
|
+
if (process.env.ORBITAL_TELEMETRY === 'false') telemetry.enabled = false;
|
|
223
|
+
|
|
201
224
|
return {
|
|
202
225
|
projectName,
|
|
203
226
|
projectRoot: root,
|
|
@@ -213,6 +236,7 @@ export function loadConfig(projectRoot?: string): OrbitalConfig {
|
|
|
213
236
|
logLevel,
|
|
214
237
|
categories,
|
|
215
238
|
agents,
|
|
239
|
+
telemetry,
|
|
216
240
|
};
|
|
217
241
|
}
|
|
218
242
|
|
package/server/database.ts
CHANGED
|
@@ -7,6 +7,34 @@ import { createLogger } from './utils/logger.js';
|
|
|
7
7
|
|
|
8
8
|
const log = createLogger('database');
|
|
9
9
|
|
|
10
|
+
// ─── Factory (multi-project) ────────────────────────────────
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Open a project-scoped SQLite database at the given directory.
|
|
14
|
+
* Creates the directory if needed, applies schema DDL and migrations.
|
|
15
|
+
*
|
|
16
|
+
* Each call returns a NEW connection — callers manage their own lifecycle.
|
|
17
|
+
* This is the multi-project replacement for the getDatabase() singleton.
|
|
18
|
+
*/
|
|
19
|
+
export function openProjectDatabase(dbDir: string): Database.Database {
|
|
20
|
+
fs.mkdirSync(dbDir, { recursive: true });
|
|
21
|
+
const file = path.join(dbDir, 'orbital.db');
|
|
22
|
+
|
|
23
|
+
const database = new Database(file);
|
|
24
|
+
log.info('Database initialized', { path: file });
|
|
25
|
+
|
|
26
|
+
database.pragma('journal_mode = WAL');
|
|
27
|
+
database.pragma('synchronous = NORMAL');
|
|
28
|
+
database.pragma('foreign_keys = ON');
|
|
29
|
+
|
|
30
|
+
database.exec(SCHEMA_DDL);
|
|
31
|
+
runMigrations(database);
|
|
32
|
+
|
|
33
|
+
return database;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// ─── Singleton (backward compat, used by index.ts) ──────────
|
|
37
|
+
|
|
10
38
|
function getDbPaths(): { dir: string; file: string } {
|
|
11
39
|
const config = getConfig();
|
|
12
40
|
return { dir: config.dbDir, file: path.join(config.dbDir, 'orbital.db') };
|
|
@@ -14,26 +42,10 @@ function getDbPaths(): { dir: string; file: string } {
|
|
|
14
42
|
|
|
15
43
|
let db: Database.Database | null = null;
|
|
16
44
|
|
|
45
|
+
/** @deprecated Use openProjectDatabase() for multi-project support. */
|
|
17
46
|
export function getDatabase(): Database.Database {
|
|
18
47
|
if (db) return db;
|
|
19
|
-
|
|
20
|
-
const { dir, file } = getDbPaths();
|
|
21
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
22
|
-
|
|
23
|
-
db = new Database(file);
|
|
24
|
-
log.info('Database initialized', { path: file });
|
|
25
|
-
|
|
26
|
-
// Performance pragmas for a local dev tool
|
|
27
|
-
db.pragma('journal_mode = WAL');
|
|
28
|
-
db.pragma('synchronous = NORMAL');
|
|
29
|
-
db.pragma('foreign_keys = ON');
|
|
30
|
-
|
|
31
|
-
// Run schema migrations (SQLite db.exec, not child_process)
|
|
32
|
-
db.exec(SCHEMA_DDL);
|
|
33
|
-
|
|
34
|
-
// Incremental migrations for existing databases
|
|
35
|
-
runMigrations(db);
|
|
36
|
-
|
|
48
|
+
db = openProjectDatabase(getDbPaths().dir);
|
|
37
49
|
return db;
|
|
38
50
|
}
|
|
39
51
|
|
|
@@ -59,6 +71,11 @@ function runMigrations(database: Database.Database): void {
|
|
|
59
71
|
database.exec('ALTER TABLE sessions ADD COLUMN action TEXT');
|
|
60
72
|
}
|
|
61
73
|
|
|
74
|
+
// Migration 9: Add telemetry_sent_at column to sessions
|
|
75
|
+
if (!sessionCols.some((c) => c.name === 'telemetry_sent_at')) {
|
|
76
|
+
database.exec('ALTER TABLE sessions ADD COLUMN telemetry_sent_at TEXT');
|
|
77
|
+
}
|
|
78
|
+
|
|
62
79
|
// Migration 8: Add batch group columns to sprints
|
|
63
80
|
const sprintCols = database.pragma('table_info(sprints)') as Array<{ name: string }>;
|
|
64
81
|
if (!sprintCols.some((c) => c.name === 'target_column')) {
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import crypto from 'crypto';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import os from 'os';
|
|
5
|
+
import { createLogger } from './utils/logger.js';
|
|
6
|
+
|
|
7
|
+
const log = createLogger('global-config');
|
|
8
|
+
|
|
9
|
+
// ─── Types ──────────────────────────────────────────────────
|
|
10
|
+
|
|
11
|
+
export interface ProjectRegistration {
|
|
12
|
+
/** Slug ID derived from directory name, e.g. "orbital-command" */
|
|
13
|
+
id: string;
|
|
14
|
+
/** Absolute path to project root */
|
|
15
|
+
path: string;
|
|
16
|
+
/** Human-readable display name */
|
|
17
|
+
name: string;
|
|
18
|
+
/** HSL color string for project badge, e.g. "210 80% 55%" */
|
|
19
|
+
color: string;
|
|
20
|
+
/** ISO 8601 timestamp of registration */
|
|
21
|
+
registeredAt: string;
|
|
22
|
+
/** Can be disabled without removal */
|
|
23
|
+
enabled: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface OrbitalGlobalConfig {
|
|
27
|
+
version: 1;
|
|
28
|
+
projects: ProjectRegistration[];
|
|
29
|
+
privateMode?: boolean;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// ─── Constants ──────────────────────────────────────────────
|
|
33
|
+
|
|
34
|
+
/** Global Orbital Command directory */
|
|
35
|
+
export const ORBITAL_HOME = path.join(os.homedir(), '.orbital');
|
|
36
|
+
|
|
37
|
+
/** Path to the global registry file */
|
|
38
|
+
export const REGISTRY_PATH = path.join(ORBITAL_HOME, 'config.json');
|
|
39
|
+
|
|
40
|
+
/** Path to global primitives directory */
|
|
41
|
+
export const GLOBAL_PRIMITIVES_DIR = path.join(ORBITAL_HOME, 'primitives');
|
|
42
|
+
|
|
43
|
+
/** Path to global workflow config */
|
|
44
|
+
export const GLOBAL_WORKFLOW_PATH = path.join(ORBITAL_HOME, 'workflow.json');
|
|
45
|
+
|
|
46
|
+
/** Import from shared — re-exported for convenience */
|
|
47
|
+
import { PROJECT_COLORS } from '../shared/project-colors.js';
|
|
48
|
+
export { PROJECT_COLORS };
|
|
49
|
+
|
|
50
|
+
// ─── Slug Generation ────────────────────────────────────────
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Generate a project slug from a filesystem path.
|
|
54
|
+
* Uses the directory basename, lowercased, with non-alphanumeric chars
|
|
55
|
+
* replaced by hyphens. Deduplicates against existing IDs with a 4-char hash.
|
|
56
|
+
*/
|
|
57
|
+
export function generateProjectId(projectRoot: string, existingIds: string[]): string {
|
|
58
|
+
const base = path.basename(projectRoot)
|
|
59
|
+
.toLowerCase()
|
|
60
|
+
.replace(/[^a-z0-9-]/g, '-')
|
|
61
|
+
.replace(/-+/g, '-')
|
|
62
|
+
.replace(/^-|-$/g, '');
|
|
63
|
+
|
|
64
|
+
const slug = base || 'project';
|
|
65
|
+
if (!existingIds.includes(slug)) return slug;
|
|
66
|
+
|
|
67
|
+
// Collision — append 4-char hash of the full path
|
|
68
|
+
const hash = crypto.createHash('sha256').update(projectRoot).digest('hex').slice(0, 4);
|
|
69
|
+
return `${slug}-${hash}`;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// ─── Registry I/O ───────────────────────────────────────────
|
|
73
|
+
|
|
74
|
+
/** Ensure ~/.orbital/ directory structure exists, including primitives subdirectories. */
|
|
75
|
+
export function ensureOrbitalHome(): void {
|
|
76
|
+
if (!fs.existsSync(ORBITAL_HOME)) {
|
|
77
|
+
fs.mkdirSync(ORBITAL_HOME, { recursive: true });
|
|
78
|
+
log.info('Created ~/.orbital/', { path: ORBITAL_HOME });
|
|
79
|
+
}
|
|
80
|
+
// Ensure primitives subdirectories exist so the global watcher can start
|
|
81
|
+
for (const sub of ['agents', 'skills', 'hooks', 'config']) {
|
|
82
|
+
const dir = path.join(GLOBAL_PRIMITIVES_DIR, sub);
|
|
83
|
+
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Load the global registry. Creates default if missing. */
|
|
88
|
+
export function loadGlobalConfig(): OrbitalGlobalConfig {
|
|
89
|
+
ensureOrbitalHome();
|
|
90
|
+
|
|
91
|
+
if (!fs.existsSync(REGISTRY_PATH)) {
|
|
92
|
+
const config: OrbitalGlobalConfig = { version: 1, projects: [] };
|
|
93
|
+
saveGlobalConfig(config);
|
|
94
|
+
return config;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
try {
|
|
98
|
+
const raw = fs.readFileSync(REGISTRY_PATH, 'utf-8');
|
|
99
|
+
return JSON.parse(raw) as OrbitalGlobalConfig;
|
|
100
|
+
} catch (err) {
|
|
101
|
+
log.error('Failed to read global config, creating fresh', { error: String(err) });
|
|
102
|
+
const config: OrbitalGlobalConfig = { version: 1, projects: [] };
|
|
103
|
+
saveGlobalConfig(config);
|
|
104
|
+
return config;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Save the global registry atomically. */
|
|
109
|
+
export function saveGlobalConfig(config: OrbitalGlobalConfig): void {
|
|
110
|
+
ensureOrbitalHome();
|
|
111
|
+
const tmpPath = REGISTRY_PATH + '.tmp';
|
|
112
|
+
fs.writeFileSync(tmpPath, JSON.stringify(config, null, 2), 'utf-8');
|
|
113
|
+
fs.renameSync(tmpPath, REGISTRY_PATH);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// ─── Project Registration ───────────────────────────────────
|
|
117
|
+
|
|
118
|
+
/** Pick the next unused color from the palette. */
|
|
119
|
+
function nextColor(usedColors: string[]): string {
|
|
120
|
+
const available = PROJECT_COLORS.filter(c => !usedColors.includes(c));
|
|
121
|
+
return available[0] ?? PROJECT_COLORS[0];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Register a project in the global config. Returns the registration. */
|
|
125
|
+
export function registerProject(
|
|
126
|
+
projectRoot: string,
|
|
127
|
+
options?: { name?: string; color?: string },
|
|
128
|
+
): ProjectRegistration {
|
|
129
|
+
const absPath = path.resolve(projectRoot);
|
|
130
|
+
const config = loadGlobalConfig();
|
|
131
|
+
|
|
132
|
+
// Check if already registered
|
|
133
|
+
const existing = config.projects.find(p => p.path === absPath);
|
|
134
|
+
if (existing) {
|
|
135
|
+
log.info('Project already registered', { id: existing.id, path: absPath });
|
|
136
|
+
return existing;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const existingIds = config.projects.map(p => p.id);
|
|
140
|
+
const usedColors = config.projects.map(p => p.color);
|
|
141
|
+
|
|
142
|
+
const registration: ProjectRegistration = {
|
|
143
|
+
id: generateProjectId(absPath, existingIds),
|
|
144
|
+
path: absPath,
|
|
145
|
+
name: options?.name ?? path.basename(absPath),
|
|
146
|
+
color: options?.color ?? nextColor(usedColors),
|
|
147
|
+
registeredAt: new Date().toISOString(),
|
|
148
|
+
enabled: true,
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
config.projects.push(registration);
|
|
152
|
+
saveGlobalConfig(config);
|
|
153
|
+
log.info('Project registered', { id: registration.id, path: absPath });
|
|
154
|
+
|
|
155
|
+
return registration;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** Unregister a project by ID or path. Returns true if found. */
|
|
159
|
+
export function unregisterProject(idOrPath: string): boolean {
|
|
160
|
+
const config = loadGlobalConfig();
|
|
161
|
+
const absPath = path.isAbsolute(idOrPath) ? idOrPath : path.resolve(idOrPath);
|
|
162
|
+
|
|
163
|
+
const idx = config.projects.findIndex(
|
|
164
|
+
p => p.id === idOrPath || p.path === absPath,
|
|
165
|
+
);
|
|
166
|
+
if (idx === -1) return false;
|
|
167
|
+
|
|
168
|
+
const removed = config.projects.splice(idx, 1)[0];
|
|
169
|
+
saveGlobalConfig(config);
|
|
170
|
+
log.info('Project unregistered', { id: removed.id, path: removed.path });
|
|
171
|
+
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** Update a project's registration (color, name, enabled). */
|
|
176
|
+
export function updateProject(
|
|
177
|
+
id: string,
|
|
178
|
+
updates: Partial<Pick<ProjectRegistration, 'name' | 'color' | 'enabled'>>,
|
|
179
|
+
): ProjectRegistration | null {
|
|
180
|
+
const config = loadGlobalConfig();
|
|
181
|
+
const project = config.projects.find(p => p.id === id);
|
|
182
|
+
if (!project) return null;
|
|
183
|
+
|
|
184
|
+
if (updates.name !== undefined) project.name = updates.name;
|
|
185
|
+
if (updates.color !== undefined) project.color = updates.color;
|
|
186
|
+
if (updates.enabled !== undefined) project.enabled = updates.enabled;
|
|
187
|
+
|
|
188
|
+
saveGlobalConfig(config);
|
|
189
|
+
return project;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** Get all registered projects. */
|
|
193
|
+
export function getRegisteredProjects(): ProjectRegistration[] {
|
|
194
|
+
return loadGlobalConfig().projects;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** Find a registered project by ID. */
|
|
198
|
+
export function findProject(id: string): ProjectRegistration | undefined {
|
|
199
|
+
return loadGlobalConfig().projects.find(p => p.id === id);
|
|
200
|
+
}
|