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
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type Database from 'better-sqlite3';
|
|
2
|
-
import type {
|
|
2
|
+
import type { Emitter } from '../project-emitter.js';
|
|
3
3
|
import type { ScopeService } from '../services/scope-service.js';
|
|
4
4
|
import type { WorkflowEngine } from '../../shared/workflow-engine.js';
|
|
5
5
|
import { isSessionPidAlive } from './terminal-launcher.js';
|
|
6
6
|
import { createLogger } from './logger.js';
|
|
7
7
|
|
|
8
|
-
const log = createLogger('dispatch');
|
|
8
|
+
const log = createLogger('dispatch-utils');
|
|
9
9
|
|
|
10
10
|
interface DispatchRow {
|
|
11
11
|
data: string;
|
|
@@ -15,7 +15,7 @@ interface DispatchRow {
|
|
|
15
15
|
/** Mark a DISPATCH event as resolved and emit socket notification. */
|
|
16
16
|
export function resolveDispatchEvent(
|
|
17
17
|
db: Database.Database,
|
|
18
|
-
io:
|
|
18
|
+
io: Emitter,
|
|
19
19
|
eventId: string,
|
|
20
20
|
outcome: 'completed' | 'failed' | 'abandoned',
|
|
21
21
|
error?: string,
|
|
@@ -42,10 +42,73 @@ export function resolveDispatchEvent(
|
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
/** Auto-revert scope status when a dispatch is abandoned, if the forward edge
|
|
46
|
+
* has autoRevert=true and the scope is still at the dispatch target.
|
|
47
|
+
* Safe: only reverts if the scope hasn't been moved since the dispatch.
|
|
48
|
+
* Returns true if revert was successful. */
|
|
49
|
+
function autoRevertAbandonedScope(
|
|
50
|
+
scopeService: ScopeService,
|
|
51
|
+
engine: WorkflowEngine,
|
|
52
|
+
scopeId: number,
|
|
53
|
+
data: Record<string, unknown>,
|
|
54
|
+
): boolean {
|
|
55
|
+
try {
|
|
56
|
+
const transition = data.transition as { from: string; to: string } | null;
|
|
57
|
+
if (!transition?.from || !transition?.to) return false;
|
|
58
|
+
|
|
59
|
+
const scope = scopeService.getById(scopeId);
|
|
60
|
+
// Only revert if scope is still at the dispatch target (hasn't been moved)
|
|
61
|
+
if (!scope || scope.status !== transition.to) return false;
|
|
62
|
+
|
|
63
|
+
const edge = engine.findEdge(transition.from, transition.to);
|
|
64
|
+
if (!edge?.autoRevert) return false;
|
|
65
|
+
|
|
66
|
+
const result = scopeService.updateStatus(scopeId, transition.from, 'rollback');
|
|
67
|
+
if (!result.ok) return false;
|
|
68
|
+
log.info('Auto-reverted abandoned dispatch', {
|
|
69
|
+
scopeId, from: transition.to, to: transition.from,
|
|
70
|
+
});
|
|
71
|
+
return true;
|
|
72
|
+
} catch (err) {
|
|
73
|
+
log.error('Auto-revert failed', { scopeId, error: String(err) });
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Attempt auto-revert for an abandoned dispatch and clear the abandoned state if successful.
|
|
79
|
+
* Loads the dispatch event data, tries auto-revert, and re-resolves as 'completed' if the
|
|
80
|
+
* scope was successfully reverted. Returns true if auto-revert + clear succeeded. */
|
|
81
|
+
export function tryAutoRevertAndClear(
|
|
82
|
+
db: Database.Database,
|
|
83
|
+
io: Emitter,
|
|
84
|
+
scopeService: ScopeService,
|
|
85
|
+
engine: WorkflowEngine,
|
|
86
|
+
eventId: string,
|
|
87
|
+
): boolean {
|
|
88
|
+
const row = db.prepare('SELECT data, scope_id FROM events WHERE id = ?')
|
|
89
|
+
.get(eventId) as DispatchRow | undefined;
|
|
90
|
+
if (!row || row.scope_id == null) return false;
|
|
91
|
+
|
|
92
|
+
let data: Record<string, unknown>;
|
|
93
|
+
try {
|
|
94
|
+
data = JSON.parse(row.data);
|
|
95
|
+
} catch {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const reverted = autoRevertAbandonedScope(scopeService, engine, row.scope_id, data);
|
|
100
|
+
if (reverted) {
|
|
101
|
+
// Clear the abandoned state so getAbandonedScopeIds won't return this scope
|
|
102
|
+
resolveDispatchEvent(db, io, eventId, 'completed');
|
|
103
|
+
log.info('Cleared abandoned dispatch after auto-revert', { eventId, scope_id: row.scope_id });
|
|
104
|
+
}
|
|
105
|
+
return reverted;
|
|
106
|
+
}
|
|
107
|
+
|
|
45
108
|
/** Resolve all unresolved DISPATCH events for a given scope */
|
|
46
109
|
export function resolveActiveDispatchesForScope(
|
|
47
110
|
db: Database.Database,
|
|
48
|
-
io:
|
|
111
|
+
io: Emitter,
|
|
49
112
|
scopeId: number,
|
|
50
113
|
outcome: 'completed' | 'failed' | 'abandoned',
|
|
51
114
|
): void {
|
|
@@ -63,7 +126,7 @@ export function resolveActiveDispatchesForScope(
|
|
|
63
126
|
* Used by both recover and dismiss-abandoned routes to clear abandoned state. */
|
|
64
127
|
export function resolveAbandonedDispatchesForScope(
|
|
65
128
|
db: Database.Database,
|
|
66
|
-
io:
|
|
129
|
+
io: Emitter,
|
|
67
130
|
scopeId: number,
|
|
68
131
|
): number {
|
|
69
132
|
const rows = db.prepare(
|
|
@@ -104,15 +167,13 @@ export function linkPidToDispatch(
|
|
|
104
167
|
/** Resolve all unresolved DISPATCH events linked to a specific PID.
|
|
105
168
|
* Called when a SESSION_END event is received, indicating the Claude session
|
|
106
169
|
* process has exited and its dispatches should be cleared.
|
|
107
|
-
*
|
|
108
|
-
* NOTE: Does NOT revert scope status. Skills like /scope-implement intentionally
|
|
109
|
-
* keep scopes at the transition target (e.g. "implementing") after completion.
|
|
110
|
-
* Reverting on session end was destroying completed work and deleting scope files. */
|
|
170
|
+
* Returns the resolved event IDs so callers can attempt auto-revert. */
|
|
111
171
|
export function resolveDispatchesByPid(
|
|
112
172
|
db: Database.Database,
|
|
113
|
-
io:
|
|
173
|
+
io: Emitter,
|
|
114
174
|
pid: number,
|
|
115
|
-
|
|
175
|
+
outcome: 'completed' | 'abandoned' = 'abandoned',
|
|
176
|
+
): string[] {
|
|
116
177
|
const rows = db.prepare(
|
|
117
178
|
`SELECT id FROM events
|
|
118
179
|
WHERE type = 'DISPATCH'
|
|
@@ -121,38 +182,39 @@ export function resolveDispatchesByPid(
|
|
|
121
182
|
).all(pid) as Array<{ id: string }>;
|
|
122
183
|
|
|
123
184
|
for (const row of rows) {
|
|
124
|
-
resolveDispatchEvent(db, io, row.id,
|
|
185
|
+
resolveDispatchEvent(db, io, row.id, outcome);
|
|
125
186
|
}
|
|
126
187
|
|
|
127
|
-
return rows.
|
|
188
|
+
return rows.map(r => r.id);
|
|
128
189
|
}
|
|
129
190
|
|
|
130
191
|
/** Resolve all unresolved DISPATCH events linked to a specific dispatch ID.
|
|
131
192
|
* Called when a SESSION_END event includes dispatch_id from ORBITAL_DISPATCH_ID env var.
|
|
132
|
-
*
|
|
133
|
-
*
|
|
193
|
+
* Outcome depends on how the session ended: normal_exit → completed, otherwise → abandoned.
|
|
194
|
+
* Returns the resolved event IDs so callers can attempt auto-revert. */
|
|
134
195
|
export function resolveDispatchesByDispatchId(
|
|
135
196
|
db: Database.Database,
|
|
136
|
-
io:
|
|
197
|
+
io: Emitter,
|
|
137
198
|
dispatchId: string,
|
|
138
|
-
|
|
199
|
+
outcome: 'completed' | 'abandoned' = 'abandoned',
|
|
200
|
+
): string[] {
|
|
139
201
|
const row = db.prepare(
|
|
140
202
|
`SELECT id FROM events
|
|
141
203
|
WHERE id = ? AND type = 'DISPATCH' AND JSON_EXTRACT(data, '$.resolved') IS NULL`,
|
|
142
204
|
).get(dispatchId) as { id: string } | undefined;
|
|
143
205
|
|
|
144
|
-
if (!row) return
|
|
145
|
-
resolveDispatchEvent(db, io, row.id,
|
|
146
|
-
return
|
|
206
|
+
if (!row) return [];
|
|
207
|
+
resolveDispatchEvent(db, io, row.id, outcome);
|
|
208
|
+
return [row.id];
|
|
147
209
|
}
|
|
148
210
|
|
|
149
|
-
/**
|
|
150
|
-
const
|
|
211
|
+
/** Default fallback age threshold for dispatches without a linked PID (10 minutes). */
|
|
212
|
+
const DEFAULT_STALE_AGE_MS = 10 * 60 * 1000;
|
|
151
213
|
|
|
152
214
|
/** Get all scope IDs that have actively running DISPATCH events.
|
|
153
215
|
* Uses PID liveness (process.kill(pid, 0)) when available, falls back to
|
|
154
216
|
* age-based heuristic for legacy dispatches without a linked PID. */
|
|
155
|
-
export function getActiveScopeIds(db: Database.Database, scopeService: ScopeService, engine: WorkflowEngine): number[] {
|
|
217
|
+
export function getActiveScopeIds(db: Database.Database, scopeService: ScopeService, engine: WorkflowEngine, staleTimeoutMinutes?: number): number[] {
|
|
156
218
|
const rows = db.prepare(
|
|
157
219
|
`SELECT scope_id, data FROM events
|
|
158
220
|
WHERE type = 'DISPATCH'
|
|
@@ -160,7 +222,8 @@ export function getActiveScopeIds(db: Database.Database, scopeService: ScopeServ
|
|
|
160
222
|
AND JSON_EXTRACT(data, '$.resolved') IS NULL`,
|
|
161
223
|
).all() as Array<{ scope_id: number; data: string }>;
|
|
162
224
|
|
|
163
|
-
const
|
|
225
|
+
const staleMs = staleTimeoutMinutes != null ? staleTimeoutMinutes * 60 * 1000 : DEFAULT_STALE_AGE_MS;
|
|
226
|
+
const cutoff = new Date(Date.now() - staleMs).toISOString();
|
|
164
227
|
const active = new Set<number>();
|
|
165
228
|
|
|
166
229
|
for (const row of rows) {
|
|
@@ -209,6 +272,7 @@ export function getActiveScopeIds(db: Database.Database, scopeService: ScopeServ
|
|
|
209
272
|
try {
|
|
210
273
|
batchData = JSON.parse(batchRow.data);
|
|
211
274
|
} catch {
|
|
275
|
+
log.warn('Skipping unparseable batch dispatch event data', { data: batchRow.data });
|
|
212
276
|
continue;
|
|
213
277
|
}
|
|
214
278
|
|
|
@@ -242,12 +306,14 @@ export function getActiveScopeIds(db: Database.Database, scopeService: ScopeServ
|
|
|
242
306
|
* 3. No linked PID and dispatch older than STALE_AGE_MS (fallback)
|
|
243
307
|
* Called once at startup and periodically to clean up unresolved dispatches.
|
|
244
308
|
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
*
|
|
249
|
-
|
|
250
|
-
|
|
309
|
+
* When a dispatch is abandoned, auto-reverts scope status if the forward edge
|
|
310
|
+
* has autoRevert=true AND the scope is still at the dispatch target. This allows
|
|
311
|
+
* safe recovery for edges like backlog→implementing where the session crashed
|
|
312
|
+
* before doing meaningful work. Edges without autoRevert leave the scope in place
|
|
313
|
+
* for manual recovery from the dashboard. */
|
|
314
|
+
export function resolveStaleDispatches(db: Database.Database, io: Emitter, scopeService: ScopeService, engine: WorkflowEngine, staleTimeoutMinutes?: number): number {
|
|
315
|
+
const staleMs = staleTimeoutMinutes != null ? staleTimeoutMinutes * 60 * 1000 : DEFAULT_STALE_AGE_MS;
|
|
316
|
+
const cutoff = new Date(Date.now() - staleMs).toISOString();
|
|
251
317
|
|
|
252
318
|
// Single query on events only — split by cache status
|
|
253
319
|
const rows = db.prepare(
|
|
@@ -288,6 +354,8 @@ export function resolveStaleDispatches(db: Database.Database, io: Server, scopeS
|
|
|
288
354
|
|
|
289
355
|
if (isStale) {
|
|
290
356
|
resolveDispatchEvent(db, io, row.id, 'abandoned');
|
|
357
|
+
// Try auto-revert; if successful, clear the abandoned state
|
|
358
|
+
tryAutoRevertAndClear(db, io, scopeService, engine, row.id);
|
|
291
359
|
resolved++;
|
|
292
360
|
}
|
|
293
361
|
}
|
|
@@ -306,6 +374,7 @@ export function resolveStaleDispatches(db: Database.Database, io: Server, scopeS
|
|
|
306
374
|
try {
|
|
307
375
|
batchData = JSON.parse(batchRow.data);
|
|
308
376
|
} catch {
|
|
377
|
+
log.warn('Skipping unparseable batch dispatch event data', { eventId: batchRow.id });
|
|
309
378
|
continue;
|
|
310
379
|
}
|
|
311
380
|
|
|
@@ -388,6 +457,9 @@ export function getAbandonedScopeIds(
|
|
|
388
457
|
const fromStatus = transition?.from as string ?? null;
|
|
389
458
|
const abandonedAt = resolved?.at as string ?? row.timestamp;
|
|
390
459
|
|
|
460
|
+
// Defense-in-depth: skip scopes already at their pre-dispatch status (already reverted)
|
|
461
|
+
if (fromStatus && scope.status === fromStatus) continue;
|
|
462
|
+
|
|
391
463
|
result.push({ scope_id: row.scope_id, from_status: fromStatus, abandoned_at: abandonedAt });
|
|
392
464
|
}
|
|
393
465
|
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { DispatchFlags } from '../../shared/api-types.js';
|
|
2
|
+
import { VALID_OUTPUT_FORMATS, validateToolName, validateEnvKey } from '../../shared/api-types.js';
|
|
3
|
+
import { shellQuote } from './terminal-launcher.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Compile a structured DispatchFlags object into a CLI flags string
|
|
7
|
+
* for the `claude` command. All parameterized values are validated
|
|
8
|
+
* and shell-quoted to prevent injection.
|
|
9
|
+
*/
|
|
10
|
+
export function buildClaudeFlags(flags: DispatchFlags): string {
|
|
11
|
+
const parts: string[] = [];
|
|
12
|
+
|
|
13
|
+
// Permission mode — 'default' means no flag (use Claude's built-in default)
|
|
14
|
+
if (flags.permissionMode === 'bypass') {
|
|
15
|
+
parts.push('--dangerously-skip-permissions');
|
|
16
|
+
} else if (flags.permissionMode && flags.permissionMode !== 'default') {
|
|
17
|
+
parts.push('--permission-mode', flags.permissionMode);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (flags.verbose) parts.push('--verbose');
|
|
21
|
+
if (flags.noMarkdown) parts.push('--no-markdown');
|
|
22
|
+
if (flags.printMode) parts.push('-p');
|
|
23
|
+
|
|
24
|
+
if (flags.outputFormat && VALID_OUTPUT_FORMATS.includes(flags.outputFormat)) {
|
|
25
|
+
parts.push('--output-format', flags.outputFormat);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (flags.allowedTools.length > 0) {
|
|
29
|
+
const safe = flags.allowedTools.filter(validateToolName);
|
|
30
|
+
if (safe.length > 0) parts.push('--allowedTools', safe.join(','));
|
|
31
|
+
}
|
|
32
|
+
if (flags.disallowedTools.length > 0) {
|
|
33
|
+
const safe = flags.disallowedTools.filter(validateToolName);
|
|
34
|
+
if (safe.length > 0) parts.push('--disallowedTools', safe.join(','));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (flags.appendSystemPrompt) {
|
|
38
|
+
const sanitized = flags.appendSystemPrompt.replace(/\n/g, '\\n');
|
|
39
|
+
parts.push('--append-system-prompt', `'${shellQuote(sanitized)}'`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return parts.join(' ');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Build env var prefix string for dispatch commands.
|
|
47
|
+
* Keys are validated against POSIX naming rules.
|
|
48
|
+
* Returns empty string if no vars configured.
|
|
49
|
+
*/
|
|
50
|
+
export function buildEnvVarPrefix(envVars: Record<string, string>): string {
|
|
51
|
+
const entries = Object.entries(envVars).filter(([k]) => validateEnvKey(k));
|
|
52
|
+
if (entries.length === 0) return '';
|
|
53
|
+
return entries
|
|
54
|
+
.map(([k, v]) => `${k}='${v.replace(/'/g, "'\\''")}'`)
|
|
55
|
+
.join(' ') + ' ';
|
|
56
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { parseJsonFields } from './json-fields.js';
|
|
3
|
+
|
|
4
|
+
describe('parseJsonFields', () => {
|
|
5
|
+
it('parses stringified JSON arrays in known fields', () => {
|
|
6
|
+
const row = { tags: '["a","b"]', blocked_by: '[1,2]', title: 'scope-1' };
|
|
7
|
+
const result = parseJsonFields(row);
|
|
8
|
+
expect(result.tags).toEqual(['a', 'b']);
|
|
9
|
+
expect(result.blocked_by).toEqual([1, 2]);
|
|
10
|
+
expect(result.title).toBe('scope-1');
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('parses stringified JSON objects in data field', () => {
|
|
14
|
+
const row = { data: '{"key":"val","nested":{"a":1}}' };
|
|
15
|
+
const result = parseJsonFields(row);
|
|
16
|
+
expect(result.data).toEqual({ key: 'val', nested: { a: 1 } });
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('handles all 7 known JSON fields', () => {
|
|
20
|
+
const row = {
|
|
21
|
+
tags: '[]', blocked_by: '[]', blocks: '[]',
|
|
22
|
+
data: '{}', discoveries: '[]', next_steps: '[]', details: '{}',
|
|
23
|
+
};
|
|
24
|
+
const result = parseJsonFields(row);
|
|
25
|
+
expect(result.tags).toEqual([]);
|
|
26
|
+
expect(result.blocked_by).toEqual([]);
|
|
27
|
+
expect(result.blocks).toEqual([]);
|
|
28
|
+
expect(result.data).toEqual({});
|
|
29
|
+
expect(result.discoveries).toEqual([]);
|
|
30
|
+
expect(result.next_steps).toEqual([]);
|
|
31
|
+
expect(result.details).toEqual({});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('passes through already-parsed objects untouched', () => {
|
|
35
|
+
const tags = ['a', 'b'];
|
|
36
|
+
const row = { tags, data: { foo: 1 } };
|
|
37
|
+
const result = parseJsonFields(row);
|
|
38
|
+
expect(result.tags).toBe(tags); // same reference — not re-parsed
|
|
39
|
+
expect(result.data).toEqual({ foo: 1 });
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('keeps malformed JSON strings as-is without throwing', () => {
|
|
43
|
+
const row = { tags: '{broken json', data: 'not json at all', blocks: '["valid"]' };
|
|
44
|
+
const result = parseJsonFields(row);
|
|
45
|
+
expect(result.tags).toBe('{broken json');
|
|
46
|
+
expect(result.data).toBe('not json at all');
|
|
47
|
+
expect(result.blocks).toEqual(['valid']);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('returns row unchanged when no JSON fields are present', () => {
|
|
51
|
+
const row = { id: 1, title: 'hello', status: 'active' };
|
|
52
|
+
const result = parseJsonFields(row);
|
|
53
|
+
expect(result).toEqual(row);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('does not mutate the original row', () => {
|
|
57
|
+
const row = { tags: '["x"]', title: 'scope' };
|
|
58
|
+
const result = parseJsonFields(row);
|
|
59
|
+
expect(row.tags).toBe('["x"]'); // original unchanged
|
|
60
|
+
expect(result.tags).toEqual(['x']); // copy was parsed
|
|
61
|
+
expect(result).not.toBe(row);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('handles null and undefined field values', () => {
|
|
65
|
+
const row = { tags: null, data: undefined, blocks: '["a"]' };
|
|
66
|
+
const result = parseJsonFields(row);
|
|
67
|
+
expect(result.tags).toBeNull();
|
|
68
|
+
expect(result.data).toBeUndefined();
|
|
69
|
+
expect(result.blocks).toEqual(['a']);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('handles empty row', () => {
|
|
73
|
+
const result = parseJsonFields({});
|
|
74
|
+
expect(result).toEqual({});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('ignores non-JSON-field strings', () => {
|
|
78
|
+
const row = { title: '["not a json field"]', tags: '["real"]' };
|
|
79
|
+
const result = parseJsonFields(row);
|
|
80
|
+
expect(result.title).toBe('["not a json field"]'); // title is not in JSON_FIELDS
|
|
81
|
+
expect(result.tags).toEqual(['real']);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const JSON_FIELDS = ['tags', 'blocked_by', 'blocks', 'data', 'discoveries', 'next_steps', 'details'];
|
|
2
|
+
|
|
3
|
+
export type Row = Record<string, unknown>;
|
|
4
|
+
|
|
5
|
+
/** Parse stringified JSON fields in a database row back to objects. */
|
|
6
|
+
export function parseJsonFields(row: Row): Row {
|
|
7
|
+
const parsed = { ...row };
|
|
8
|
+
for (const field of JSON_FIELDS) {
|
|
9
|
+
if (typeof parsed[field] === 'string') {
|
|
10
|
+
try { parsed[field] = JSON.parse(parsed[field] as string); } catch { /* keep string */ }
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return parsed;
|
|
14
|
+
}
|
package/server/utils/logger.ts
CHANGED
|
@@ -33,8 +33,14 @@ const useColor = process.stdout.isTTY && !process.env.NO_COLOR;
|
|
|
33
33
|
const c = {
|
|
34
34
|
reset: useColor ? '\x1b[0m' : '',
|
|
35
35
|
dim: useColor ? '\x1b[2m' : '',
|
|
36
|
-
|
|
36
|
+
green: useColor ? '\x1b[32m' : '',
|
|
37
|
+
blue: useColor ? '\x1b[34m' : '',
|
|
38
|
+
magenta: useColor ? '\x1b[35m' : '',
|
|
37
39
|
cyan: useColor ? '\x1b[36m' : '',
|
|
40
|
+
white: useColor ? '\x1b[37m' : '',
|
|
41
|
+
gray: useColor ? '\x1b[90m' : '',
|
|
42
|
+
brightMagenta: useColor ? '\x1b[95m' : '',
|
|
43
|
+
brightCyan: useColor ? '\x1b[96m' : '',
|
|
38
44
|
yellow: useColor ? '\x1b[33m' : '',
|
|
39
45
|
red: useColor ? '\x1b[31m' : '',
|
|
40
46
|
};
|
|
@@ -53,6 +59,34 @@ const LEVEL_LABEL: Record<LogLevel, string> = {
|
|
|
53
59
|
error: 'ERROR',
|
|
54
60
|
};
|
|
55
61
|
|
|
62
|
+
// ─── Component Colors ───────────────────────────────────────
|
|
63
|
+
|
|
64
|
+
const COMPONENT_COLOR: Record<string, string> = {
|
|
65
|
+
// Scope (green)
|
|
66
|
+
'scope': c.green, 'scope-watcher': c.green,
|
|
67
|
+
// Dispatch (magenta)
|
|
68
|
+
'dispatch': c.magenta, 'dispatch-utils': c.magenta, 'batch': c.magenta,
|
|
69
|
+
// Git (blue)
|
|
70
|
+
'git': c.blue, 'worktree': c.blue,
|
|
71
|
+
// Workflow (cyan)
|
|
72
|
+
'workflow': c.cyan, 'sprint': c.cyan,
|
|
73
|
+
// Sync / Config (yellow)
|
|
74
|
+
'sync': c.yellow, 'config': c.yellow, 'manifest': c.yellow, 'global-config': c.yellow,
|
|
75
|
+
// Events (white)
|
|
76
|
+
'event': c.white, 'event-watcher': c.white, 'global-watcher': c.white,
|
|
77
|
+
// Infrastructure (white)
|
|
78
|
+
'server': c.white, 'central': c.white, 'database': c.white,
|
|
79
|
+
'project-context': c.white, 'project-manager': c.white, 'launch': c.white,
|
|
80
|
+
// Terminal (bright magenta)
|
|
81
|
+
'terminal': c.brightMagenta,
|
|
82
|
+
// Services (bright cyan)
|
|
83
|
+
'gate': c.brightCyan, 'deploy': c.brightCyan, 'telemetry': c.brightCyan, 'version': c.brightCyan,
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
function componentColor(name: string): string {
|
|
87
|
+
return COMPONENT_COLOR[name] ?? c.dim;
|
|
88
|
+
}
|
|
89
|
+
|
|
56
90
|
// ─── Formatting ─────────────────────────────────────────────
|
|
57
91
|
|
|
58
92
|
function timestamp(): string {
|
|
@@ -87,10 +121,13 @@ export interface Logger {
|
|
|
87
121
|
function write(level: LogLevel, component: string, msg: string, data?: Record<string, unknown>): void {
|
|
88
122
|
if (LEVEL_VALUE[level] < LEVEL_VALUE[currentLevel]) return;
|
|
89
123
|
|
|
90
|
-
const
|
|
124
|
+
const lvl = LEVEL_COLOR[level];
|
|
91
125
|
const label = LEVEL_LABEL[level];
|
|
92
126
|
const kv = formatData(data);
|
|
93
|
-
const
|
|
127
|
+
const cc = componentColor(component);
|
|
128
|
+
// Message uses level color for warn/error (urgency), component color otherwise
|
|
129
|
+
const mc = (level === 'warn' || level === 'error') ? lvl : cc;
|
|
130
|
+
const line = `${c.dim}${timestamp()}${c.reset} ${lvl}${label}${c.reset} ${cc}[${component}]${c.reset} ${mc}${msg}${c.reset}${c.dim}${kv}${c.reset}\n`;
|
|
94
131
|
|
|
95
132
|
if (level === 'warn' || level === 'error') {
|
|
96
133
|
process.stderr.write(line);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
|
|
5
|
+
const __selfDir = path.dirname(fileURLToPath(import.meta.url));
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Resolve the root directory of the orbital-command package itself.
|
|
9
|
+
* Walks up from the current file until it finds package.json.
|
|
10
|
+
*/
|
|
11
|
+
export function getOrbitalRoot(): string {
|
|
12
|
+
let dir = __selfDir;
|
|
13
|
+
for (let i = 0; i < 6; i++) {
|
|
14
|
+
if (fs.existsSync(path.join(dir, 'package.json'))) {
|
|
15
|
+
return dir;
|
|
16
|
+
}
|
|
17
|
+
dir = path.dirname(dir);
|
|
18
|
+
}
|
|
19
|
+
// Fallback: assume dev layout (server/utils/ → 2 levels up)
|
|
20
|
+
return path.resolve(__selfDir, '../..');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Read package version from package.json in the given root, or the orbital root. */
|
|
24
|
+
export function getPackageVersion(rootDir?: string): string {
|
|
25
|
+
try {
|
|
26
|
+
const dir = rootDir ?? getOrbitalRoot();
|
|
27
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf-8'));
|
|
28
|
+
return pkg.version || '0.0.0';
|
|
29
|
+
} catch {
|
|
30
|
+
return '0.0.0';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import express from 'express';
|
|
3
|
+
import request from 'supertest';
|
|
4
|
+
import { errMsg, isValidRelativePath, inferErrorStatus, catchRoute } from './route-helpers.js';
|
|
5
|
+
|
|
6
|
+
// ─── errMsg ─────────────────────────────────────────────────
|
|
7
|
+
|
|
8
|
+
describe('errMsg', () => {
|
|
9
|
+
it('extracts message from Error instances', () => {
|
|
10
|
+
expect(errMsg(new Error('something broke'))).toBe('something broke');
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('converts non-Error values to strings', () => {
|
|
14
|
+
expect(errMsg('raw string')).toBe('raw string');
|
|
15
|
+
expect(errMsg(42)).toBe('42');
|
|
16
|
+
expect(errMsg(null)).toBe('null');
|
|
17
|
+
expect(errMsg(undefined)).toBe('undefined');
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// ─── isValidRelativePath ────────────────────────────────────
|
|
22
|
+
|
|
23
|
+
describe('isValidRelativePath', () => {
|
|
24
|
+
it('accepts normal relative paths', () => {
|
|
25
|
+
expect(isValidRelativePath('hooks/init.sh')).toBe(true);
|
|
26
|
+
expect(isValidRelativePath('agents/attacker/AGENT.md')).toBe(true);
|
|
27
|
+
expect(isValidRelativePath('file.txt')).toBe(true);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('rejects directory traversal', () => {
|
|
31
|
+
expect(isValidRelativePath('../etc/passwd')).toBe(false);
|
|
32
|
+
expect(isValidRelativePath('hooks/../../secret')).toBe(false);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('rejects absolute paths', () => {
|
|
36
|
+
expect(isValidRelativePath('/etc/passwd')).toBe(false);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('rejects null bytes', () => {
|
|
40
|
+
expect(isValidRelativePath('file\0.txt')).toBe(false);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// ─── inferErrorStatus ───────────────────────────────────────
|
|
45
|
+
|
|
46
|
+
describe('inferErrorStatus', () => {
|
|
47
|
+
it('returns 403 for traversal errors', () => {
|
|
48
|
+
expect(inferErrorStatus('Path traversal detected')).toBe(403);
|
|
49
|
+
expect(inferErrorStatus('directory traversal not allowed')).toBe(403);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('returns 404 for not-found errors', () => {
|
|
53
|
+
expect(inferErrorStatus('File not found')).toBe(404);
|
|
54
|
+
expect(inferErrorStatus('ENOENT: no such file')).toBe(404);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('returns 409 for already-exists errors', () => {
|
|
58
|
+
expect(inferErrorStatus('File already exists at path')).toBe(409);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('returns 400 for directory errors', () => {
|
|
62
|
+
expect(inferErrorStatus('Cannot delete directory')).toBe(400);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('returns 500 for unrecognized errors', () => {
|
|
66
|
+
expect(inferErrorStatus('something unexpected')).toBe(500);
|
|
67
|
+
expect(inferErrorStatus('')).toBe(500);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('matches the first keyword when multiple are present', () => {
|
|
71
|
+
// "traversal" comes first in the chain, should win
|
|
72
|
+
expect(inferErrorStatus('traversal not found')).toBe(403);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// ─── catchRoute ─────────────────────────────────────────────
|
|
77
|
+
|
|
78
|
+
describe('catchRoute', () => {
|
|
79
|
+
function createApp(handler: express.RequestHandler) {
|
|
80
|
+
const app = express();
|
|
81
|
+
app.get('/test', handler);
|
|
82
|
+
return app;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
it('returns normal response when handler succeeds', async () => {
|
|
86
|
+
const app = createApp(catchRoute((_req, res) => {
|
|
87
|
+
res.json({ ok: true });
|
|
88
|
+
}));
|
|
89
|
+
|
|
90
|
+
const res = await request(app).get('/test');
|
|
91
|
+
expect(res.status).toBe(200);
|
|
92
|
+
expect(res.body).toEqual({ ok: true });
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('catches sync throws and returns 500', async () => {
|
|
96
|
+
const app = createApp(catchRoute(() => {
|
|
97
|
+
throw new Error('sync failure');
|
|
98
|
+
}));
|
|
99
|
+
|
|
100
|
+
const res = await request(app).get('/test');
|
|
101
|
+
expect(res.status).toBe(500);
|
|
102
|
+
expect(res.body).toEqual({ success: false, error: 'sync failure' });
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('catches async throws and returns 500', async () => {
|
|
106
|
+
const app = createApp(catchRoute(async () => {
|
|
107
|
+
throw new Error('async failure');
|
|
108
|
+
}));
|
|
109
|
+
|
|
110
|
+
const res = await request(app).get('/test');
|
|
111
|
+
expect(res.status).toBe(500);
|
|
112
|
+
expect(res.body).toEqual({ success: false, error: 'async failure' });
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('uses custom statusFn for error status codes', async () => {
|
|
116
|
+
const app = createApp(catchRoute(() => {
|
|
117
|
+
throw new Error('File not found at path');
|
|
118
|
+
}, inferErrorStatus));
|
|
119
|
+
|
|
120
|
+
const res = await request(app).get('/test');
|
|
121
|
+
expect(res.status).toBe(404);
|
|
122
|
+
expect(res.body).toEqual({ success: false, error: 'File not found at path' });
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('uses custom statusFn for traversal errors', async () => {
|
|
126
|
+
const app = createApp(catchRoute(() => {
|
|
127
|
+
throw new Error('Path traversal detected');
|
|
128
|
+
}, inferErrorStatus));
|
|
129
|
+
|
|
130
|
+
const res = await request(app).get('/test');
|
|
131
|
+
expect(res.status).toBe(403);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('handles non-Error thrown values', async () => {
|
|
135
|
+
const app = createApp(catchRoute(() => {
|
|
136
|
+
// eslint-disable-next-line no-throw-literal
|
|
137
|
+
throw 'raw string error';
|
|
138
|
+
}));
|
|
139
|
+
|
|
140
|
+
const res = await request(app).get('/test');
|
|
141
|
+
expect(res.status).toBe(500);
|
|
142
|
+
expect(res.body).toEqual({ success: false, error: 'raw string error' });
|
|
143
|
+
});
|
|
144
|
+
});
|