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,290 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Legacy migration — creates an orbital-manifest.json for projects
|
|
3
|
+
* that were initialized before the manifest system existed.
|
|
4
|
+
*
|
|
5
|
+
* Classifies existing files as synced/modified/user-owned by comparing
|
|
6
|
+
* their content hashes against the current template set.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import fs from 'fs';
|
|
10
|
+
import path from 'path';
|
|
11
|
+
import {
|
|
12
|
+
loadManifest,
|
|
13
|
+
saveManifest,
|
|
14
|
+
createManifest,
|
|
15
|
+
hashFile,
|
|
16
|
+
buildTemplateInventory,
|
|
17
|
+
templateFileRecord,
|
|
18
|
+
userFileRecord,
|
|
19
|
+
isSelfHosting,
|
|
20
|
+
getSymlinkTarget,
|
|
21
|
+
} from './manifest.js';
|
|
22
|
+
import type { OrbitalManifest } from './manifest-types.js';
|
|
23
|
+
import type { OrbitalSyncManifest } from './services/sync-types.js';
|
|
24
|
+
|
|
25
|
+
// ─── Constants ──────────────────────────────────────────────
|
|
26
|
+
|
|
27
|
+
/** Directories that contain managed primitives */
|
|
28
|
+
const MANAGED_DIRS = ['hooks', 'skills', 'agents'];
|
|
29
|
+
|
|
30
|
+
/** Gitignore entries that Orbital adds */
|
|
31
|
+
const GITIGNORE_ENTRIES = [
|
|
32
|
+
'scopes/',
|
|
33
|
+
'.claude/orbital/',
|
|
34
|
+
'.claude/orbital-events/',
|
|
35
|
+
'.claude/config/workflow-manifest.sh',
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
// ─── Migration ──────────────────────────────────────────────
|
|
39
|
+
|
|
40
|
+
export interface LegacyMigrationResult {
|
|
41
|
+
migrated: boolean;
|
|
42
|
+
synced: number;
|
|
43
|
+
modified: number;
|
|
44
|
+
userOwned: number;
|
|
45
|
+
importedPins: number;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Detect whether a project needs legacy migration.
|
|
50
|
+
* Returns true if it has an orbital config but no manifest.
|
|
51
|
+
*/
|
|
52
|
+
export function needsLegacyMigration(projectRoot: string): boolean {
|
|
53
|
+
const claudeDir = path.join(projectRoot, '.claude');
|
|
54
|
+
const hasConfig = fs.existsSync(path.join(claudeDir, 'orbital.config.json'));
|
|
55
|
+
const hasManifest = loadManifest(projectRoot) !== null;
|
|
56
|
+
return hasConfig && !hasManifest;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Create a manifest for an existing project that was initialized
|
|
61
|
+
* before the manifest system. Classifies every file in .claude/
|
|
62
|
+
* managed directories.
|
|
63
|
+
*/
|
|
64
|
+
export function migrateFromLegacy(
|
|
65
|
+
projectRoot: string,
|
|
66
|
+
templatesDir: string,
|
|
67
|
+
packageVersion: string,
|
|
68
|
+
): LegacyMigrationResult {
|
|
69
|
+
const claudeDir = path.join(projectRoot, '.claude');
|
|
70
|
+
|
|
71
|
+
// If manifest already exists, skip
|
|
72
|
+
if (loadManifest(projectRoot) !== null) {
|
|
73
|
+
return { migrated: false, synced: 0, modified: 0, userOwned: 0, importedPins: 0 };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Read existing config to get preset info
|
|
77
|
+
const preset = readPresetFromConfig(claudeDir);
|
|
78
|
+
|
|
79
|
+
// Read existing templateVersion from config, fall back to packageVersion
|
|
80
|
+
const configVersion = readTemplateVersion(claudeDir) || packageVersion;
|
|
81
|
+
|
|
82
|
+
const manifest = createManifest(configVersion, preset);
|
|
83
|
+
const selfHosting = isSelfHosting(projectRoot);
|
|
84
|
+
|
|
85
|
+
// Build template inventory (what files the current package ships)
|
|
86
|
+
const templateInventory = buildTemplateInventory(templatesDir);
|
|
87
|
+
|
|
88
|
+
let synced = 0;
|
|
89
|
+
let modified = 0;
|
|
90
|
+
let userOwned = 0;
|
|
91
|
+
|
|
92
|
+
// Walk managed directories and classify each file
|
|
93
|
+
for (const dir of MANAGED_DIRS) {
|
|
94
|
+
const dirPath = path.join(claudeDir, dir);
|
|
95
|
+
if (!fs.existsSync(dirPath)) continue;
|
|
96
|
+
|
|
97
|
+
walkDir(dirPath, dir, (relPath, absPath) => {
|
|
98
|
+
const templateHash = templateInventory.get(relPath);
|
|
99
|
+
|
|
100
|
+
if (templateHash) {
|
|
101
|
+
// File matches a known template path
|
|
102
|
+
if (selfHosting) {
|
|
103
|
+
const symlinkTarget = getSymlinkTarget(claudeDir, relPath);
|
|
104
|
+
if (symlinkTarget) {
|
|
105
|
+
manifest.files[relPath] = {
|
|
106
|
+
...templateFileRecord(templateHash, symlinkTarget),
|
|
107
|
+
};
|
|
108
|
+
synced++;
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const fileHash = hashFile(absPath);
|
|
114
|
+
if (fileHash === templateHash) {
|
|
115
|
+
manifest.files[relPath] = templateFileRecord(templateHash);
|
|
116
|
+
synced++;
|
|
117
|
+
} else {
|
|
118
|
+
manifest.files[relPath] = {
|
|
119
|
+
origin: 'template',
|
|
120
|
+
status: 'modified',
|
|
121
|
+
templateHash,
|
|
122
|
+
installedHash: fileHash,
|
|
123
|
+
};
|
|
124
|
+
modified++;
|
|
125
|
+
}
|
|
126
|
+
} else {
|
|
127
|
+
// File doesn't match any template — user-created
|
|
128
|
+
const fileHash = hashFile(absPath);
|
|
129
|
+
manifest.files[relPath] = userFileRecord(fileHash);
|
|
130
|
+
userOwned++;
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Also classify non-managed template files (quick/, anti-patterns/, config/, etc.)
|
|
136
|
+
classifyNonManagedFiles(claudeDir, templateInventory, manifest, selfHosting);
|
|
137
|
+
|
|
138
|
+
// Import from orbital-sync.json if it exists (override → pinned)
|
|
139
|
+
const importedPins = importFromSyncManifest(claudeDir, manifest);
|
|
140
|
+
|
|
141
|
+
// Record gitignore entries
|
|
142
|
+
manifest.gitignoreEntries = [...GITIGNORE_ENTRIES];
|
|
143
|
+
|
|
144
|
+
// Record settings hooks checksum
|
|
145
|
+
const settingsHooksPath = path.join(templatesDir, 'settings-hooks.json');
|
|
146
|
+
if (fs.existsSync(settingsHooksPath)) {
|
|
147
|
+
manifest.settingsHooksChecksum = hashFile(settingsHooksPath);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
saveManifest(projectRoot, manifest);
|
|
151
|
+
|
|
152
|
+
return { migrated: true, synced, modified, userOwned, importedPins };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// ─── Internal Helpers ───────────────────────────────────────
|
|
156
|
+
|
|
157
|
+
/** Recursively walk a directory, calling fn with relative and absolute paths. */
|
|
158
|
+
function walkDir(
|
|
159
|
+
dirPath: string,
|
|
160
|
+
prefix: string,
|
|
161
|
+
fn: (relPath: string, absPath: string) => void,
|
|
162
|
+
): void {
|
|
163
|
+
if (!fs.existsSync(dirPath)) return;
|
|
164
|
+
|
|
165
|
+
for (const entry of fs.readdirSync(dirPath, { withFileTypes: true })) {
|
|
166
|
+
if (entry.name.startsWith('.')) continue;
|
|
167
|
+
const absPath = path.join(dirPath, entry.name);
|
|
168
|
+
const relPath = `${prefix}/${entry.name}`;
|
|
169
|
+
|
|
170
|
+
// Follow symlinks: use stat() to check if target is a directory
|
|
171
|
+
const stat = fs.statSync(absPath);
|
|
172
|
+
if (stat.isDirectory()) {
|
|
173
|
+
walkDir(absPath, relPath, fn);
|
|
174
|
+
} else {
|
|
175
|
+
fn(relPath, absPath);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** Classify template files outside hooks/skills/agents (quick/, anti-patterns/, config/, etc.) */
|
|
181
|
+
function classifyNonManagedFiles(
|
|
182
|
+
claudeDir: string,
|
|
183
|
+
templateInventory: Map<string, string>,
|
|
184
|
+
manifest: OrbitalManifest,
|
|
185
|
+
selfHosting: boolean,
|
|
186
|
+
): void {
|
|
187
|
+
const nonManagedDirs = ['quick', 'anti-patterns', 'config'];
|
|
188
|
+
|
|
189
|
+
for (const dir of nonManagedDirs) {
|
|
190
|
+
const dirPath = path.join(claudeDir, dir);
|
|
191
|
+
if (!fs.existsSync(dirPath)) continue;
|
|
192
|
+
|
|
193
|
+
walkDir(dirPath, dir, (relPath, absPath) => {
|
|
194
|
+
const templateHash = templateInventory.get(relPath);
|
|
195
|
+
if (!templateHash) return; // Not a template file, skip
|
|
196
|
+
|
|
197
|
+
if (selfHosting) {
|
|
198
|
+
const symlinkTarget = getSymlinkTarget(claudeDir, relPath);
|
|
199
|
+
if (symlinkTarget) {
|
|
200
|
+
manifest.files[relPath] = templateFileRecord(templateHash, symlinkTarget);
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const fileHash = hashFile(absPath);
|
|
206
|
+
if (fileHash === templateHash) {
|
|
207
|
+
manifest.files[relPath] = templateFileRecord(templateHash);
|
|
208
|
+
} else {
|
|
209
|
+
manifest.files[relPath] = {
|
|
210
|
+
origin: 'template',
|
|
211
|
+
status: 'modified',
|
|
212
|
+
templateHash,
|
|
213
|
+
installedHash: fileHash,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// Top-level template files
|
|
220
|
+
const topLevel = ['lessons-learned.md'];
|
|
221
|
+
for (const file of topLevel) {
|
|
222
|
+
const filePath = path.join(claudeDir, file);
|
|
223
|
+
const templateHash = templateInventory.get(file);
|
|
224
|
+
if (!templateHash || !fs.existsSync(filePath)) continue;
|
|
225
|
+
|
|
226
|
+
const fileHash = hashFile(filePath);
|
|
227
|
+
if (fileHash === templateHash) {
|
|
228
|
+
manifest.files[file] = templateFileRecord(templateHash);
|
|
229
|
+
} else {
|
|
230
|
+
manifest.files[file] = {
|
|
231
|
+
origin: 'template',
|
|
232
|
+
status: 'modified',
|
|
233
|
+
templateHash,
|
|
234
|
+
installedHash: fileHash,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** Import pin information from the legacy orbital-sync.json manifest. */
|
|
241
|
+
function importFromSyncManifest(
|
|
242
|
+
claudeDir: string,
|
|
243
|
+
manifest: OrbitalManifest,
|
|
244
|
+
): number {
|
|
245
|
+
const syncManifestPath = path.join(claudeDir, 'orbital-sync.json');
|
|
246
|
+
if (!fs.existsSync(syncManifestPath)) return 0;
|
|
247
|
+
|
|
248
|
+
let imported = 0;
|
|
249
|
+
try {
|
|
250
|
+
const raw = fs.readFileSync(syncManifestPath, 'utf-8');
|
|
251
|
+
const syncManifest = JSON.parse(raw) as OrbitalSyncManifest;
|
|
252
|
+
|
|
253
|
+
for (const [relPath, record] of Object.entries(syncManifest.files)) {
|
|
254
|
+
if (record.mode === 'override' && manifest.files[relPath]) {
|
|
255
|
+
manifest.files[relPath].status = 'pinned';
|
|
256
|
+
manifest.files[relPath].pinnedAt = record.overriddenAt || new Date().toISOString();
|
|
257
|
+
manifest.files[relPath].pinnedReason = record.reason || 'Imported from orbital-sync.json override';
|
|
258
|
+
imported++;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
} catch {
|
|
262
|
+
// Malformed sync manifest — skip import
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
return imported;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/** Read the preset name from orbital.config.json, defaulting to "default". */
|
|
269
|
+
function readPresetFromConfig(claudeDir: string): string {
|
|
270
|
+
try {
|
|
271
|
+
const workflowPath = path.join(claudeDir, 'config', 'workflow.json');
|
|
272
|
+
if (fs.existsSync(workflowPath)) {
|
|
273
|
+
const workflow = JSON.parse(fs.readFileSync(workflowPath, 'utf-8'));
|
|
274
|
+
if (workflow.name) return workflow.name.toLowerCase().replace(/\s+/g, '-');
|
|
275
|
+
}
|
|
276
|
+
} catch { /* fall through */ }
|
|
277
|
+
return 'default';
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/** Read the templateVersion from orbital.config.json. */
|
|
281
|
+
function readTemplateVersion(claudeDir: string): string | null {
|
|
282
|
+
try {
|
|
283
|
+
const configPath = path.join(claudeDir, 'orbital.config.json');
|
|
284
|
+
if (fs.existsSync(configPath)) {
|
|
285
|
+
const config = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
|
|
286
|
+
return config.templateVersion || null;
|
|
287
|
+
}
|
|
288
|
+
} catch { /* fall through */ }
|
|
289
|
+
return null;
|
|
290
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest';
|
|
2
|
+
import { parseEventFile } from './event-parser.js';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import os from 'os';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
|
|
7
|
+
describe('parseEventFile', () => {
|
|
8
|
+
let tmpFile: string;
|
|
9
|
+
|
|
10
|
+
function writeEvent(data: Record<string, unknown>): string {
|
|
11
|
+
tmpFile = path.join(os.tmpdir(), `test-event-${Date.now()}-${Math.random().toString(36).slice(2)}.json`);
|
|
12
|
+
fs.writeFileSync(tmpFile, JSON.stringify(data));
|
|
13
|
+
return tmpFile;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
afterEach(() => {
|
|
17
|
+
if (tmpFile && fs.existsSync(tmpFile)) fs.unlinkSync(tmpFile);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// ─── Full format parsing ─────────────────────────────────
|
|
21
|
+
|
|
22
|
+
describe('full format (top-level fields)', () => {
|
|
23
|
+
it('extracts all fields correctly', () => {
|
|
24
|
+
const file = writeEvent({
|
|
25
|
+
id: 'evt-1', type: 'SCOPE_STATUS_CHANGED', scope_id: 42,
|
|
26
|
+
session_id: 'sess-abc', agent: 'architect',
|
|
27
|
+
data: { from: 'backlog', to: 'implementing' },
|
|
28
|
+
timestamp: '2026-04-08T10:00:00Z',
|
|
29
|
+
});
|
|
30
|
+
const result = parseEventFile(file);
|
|
31
|
+
expect(result).not.toBeNull();
|
|
32
|
+
expect(result!.id).toBe('evt-1');
|
|
33
|
+
expect(result!.type).toBe('SCOPE_STATUS_CHANGED');
|
|
34
|
+
expect(result!.scope_id).toBe(42);
|
|
35
|
+
expect(result!.session_id).toBe('sess-abc');
|
|
36
|
+
expect(result!.agent).toBe('architect');
|
|
37
|
+
expect(result!.data).toEqual({ from: 'backlog', to: 'implementing' });
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('preserves data payload as-is', () => {
|
|
41
|
+
const file = writeEvent({
|
|
42
|
+
id: 'evt-2', type: 'CUSTOM', timestamp: '2026-04-08T10:00:00Z',
|
|
43
|
+
data: { nested: { deep: true }, arr: [1, 2, 3] },
|
|
44
|
+
});
|
|
45
|
+
const result = parseEventFile(file)!;
|
|
46
|
+
expect(result.data).toEqual({ nested: { deep: true }, arr: [1, 2, 3] });
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// ─── Minimal format parsing ──────────────────────────────
|
|
51
|
+
|
|
52
|
+
describe('minimal format (fields in data)', () => {
|
|
53
|
+
it('extracts scope_id and session_id from data', () => {
|
|
54
|
+
const file = writeEvent({
|
|
55
|
+
id: 'evt-3', type: 'AGENT_STARTED', timestamp: '2026-04-08T10:00:00Z',
|
|
56
|
+
data: { scope_id: 99, session_id: 'sess-xyz' },
|
|
57
|
+
});
|
|
58
|
+
const result = parseEventFile(file)!;
|
|
59
|
+
expect(result.scope_id).toBe(99);
|
|
60
|
+
expect(result.session_id).toBe('sess-xyz');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('extracts agent from data.agents[0]', () => {
|
|
64
|
+
const file = writeEvent({
|
|
65
|
+
id: 'evt-4', type: 'AGENT_COMPLETED', timestamp: '2026-04-08T10:00:00Z',
|
|
66
|
+
data: { agents: ['attacker', 'chaos'] },
|
|
67
|
+
});
|
|
68
|
+
const result = parseEventFile(file)!;
|
|
69
|
+
expect(result.agent).toBe('attacker');
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// ─── Field fallback priority ─────────────────────────────
|
|
74
|
+
|
|
75
|
+
describe('field fallback priority', () => {
|
|
76
|
+
it('top-level scope_id wins over data.scope_id', () => {
|
|
77
|
+
const file = writeEvent({
|
|
78
|
+
id: 'evt-5', type: 'TEST', timestamp: 'now',
|
|
79
|
+
scope_id: 10, data: { scope_id: 20 },
|
|
80
|
+
});
|
|
81
|
+
expect(parseEventFile(file)!.scope_id).toBe(10);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('top-level agent wins over data.agent', () => {
|
|
85
|
+
const file = writeEvent({
|
|
86
|
+
id: 'evt-6', type: 'TEST', timestamp: 'now',
|
|
87
|
+
agent: 'top', data: { agent: 'nested' },
|
|
88
|
+
});
|
|
89
|
+
expect(parseEventFile(file)!.agent).toBe('top');
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('data.agent wins over data.agents[0]', () => {
|
|
93
|
+
const file = writeEvent({
|
|
94
|
+
id: 'evt-7', type: 'TEST', timestamp: 'now',
|
|
95
|
+
data: { agent: 'single', agents: ['array-first'] },
|
|
96
|
+
});
|
|
97
|
+
expect(parseEventFile(file)!.agent).toBe('single');
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
// ─── Edge cases ──────────────────────────────────────────
|
|
102
|
+
|
|
103
|
+
describe('edge cases', () => {
|
|
104
|
+
it('empty string scope_id falls through to data', () => {
|
|
105
|
+
const file = writeEvent({
|
|
106
|
+
id: 'evt-8', type: 'TEST', timestamp: 'now',
|
|
107
|
+
scope_id: '', data: { scope_id: 42 },
|
|
108
|
+
});
|
|
109
|
+
expect(parseEventFile(file)!.scope_id).toBe(42);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('null scope_id with no data fallback returns null', () => {
|
|
113
|
+
const file = writeEvent({
|
|
114
|
+
id: 'evt-9', type: 'TEST', timestamp: 'now',
|
|
115
|
+
scope_id: null, data: {},
|
|
116
|
+
});
|
|
117
|
+
expect(parseEventFile(file)!.scope_id).toBeNull();
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('returns null for malformed JSON', () => {
|
|
121
|
+
tmpFile = path.join(os.tmpdir(), `test-bad-${Date.now()}.json`);
|
|
122
|
+
fs.writeFileSync(tmpFile, '{ not valid json');
|
|
123
|
+
expect(parseEventFile(tmpFile)).toBeNull();
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('returns null for missing required fields', () => {
|
|
127
|
+
const file = writeEvent({ id: 'evt-10' }); // missing type and timestamp
|
|
128
|
+
expect(parseEventFile(file)).toBeNull();
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('returns null for non-existent file', () => {
|
|
132
|
+
expect(parseEventFile('/tmp/nonexistent-event-file.json')).toBeNull();
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
});
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
2
|
+
import { normalizeStatus, inferStatusFromDir, setValidStatuses, parseScopeFile, parseAllScopes } from './scope-parser.js';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import os from 'os';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
|
|
7
|
+
// ─── Pure function tests (no I/O) ──────────────────────────
|
|
8
|
+
|
|
9
|
+
describe('normalizeStatus()', () => {
|
|
10
|
+
it('maps "in-progress" to "implementing"', () => {
|
|
11
|
+
expect(normalizeStatus('in-progress')).toBe('implementing');
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('maps "in_progress" to "implementing"', () => {
|
|
15
|
+
expect(normalizeStatus('in_progress')).toBe('implementing');
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('maps "complete" to "completed"', () => {
|
|
19
|
+
expect(normalizeStatus('complete')).toBe('completed');
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('maps "done" to "production"', () => {
|
|
23
|
+
expect(normalizeStatus('done')).toBe('production');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('maps "exploring" to "planning"', () => {
|
|
27
|
+
expect(normalizeStatus('exploring')).toBe('planning');
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('maps "blocked" to "backlog"', () => {
|
|
31
|
+
expect(normalizeStatus('blocked')).toBe('backlog');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('maps "testing" to "review"', () => {
|
|
35
|
+
expect(normalizeStatus('testing')).toBe('review');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('returns identity for already-valid statuses', () => {
|
|
39
|
+
expect(normalizeStatus('implementing')).toBe('implementing');
|
|
40
|
+
expect(normalizeStatus('icebox')).toBe('icebox');
|
|
41
|
+
expect(normalizeStatus('staging')).toBe('staging');
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('returns raw value for unknown statuses', () => {
|
|
45
|
+
expect(normalizeStatus('custom-status')).toBe('custom-status');
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe('setValidStatuses() + inferStatusFromDir()', () => {
|
|
50
|
+
beforeEach(() => {
|
|
51
|
+
setValidStatuses(['icebox', 'planning', 'backlog', 'implementing', 'review', 'completed', 'main']);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('returns dir name when it is a valid status', () => {
|
|
55
|
+
expect(inferStatusFromDir('implementing')).toBe('implementing');
|
|
56
|
+
expect(inferStatusFromDir('backlog')).toBe('backlog');
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('returns "planning" for unknown dir name', () => {
|
|
60
|
+
expect(inferStatusFromDir('unknown-dir')).toBe('planning');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('returns dir name as-is when validDirStatuses not yet set', () => {
|
|
64
|
+
// Reset by setting to a set that doesn't include our test value
|
|
65
|
+
setValidStatuses([]);
|
|
66
|
+
expect(inferStatusFromDir('anything')).toBe('planning');
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// ─── File-based tests ───────────────────────────────────────
|
|
71
|
+
|
|
72
|
+
describe('parseScopeFile()', () => {
|
|
73
|
+
let tmpDir: string;
|
|
74
|
+
|
|
75
|
+
beforeEach(() => {
|
|
76
|
+
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'scope-test-'));
|
|
77
|
+
setValidStatuses(['icebox', 'planning', 'backlog', 'implementing', 'review', 'completed', 'main']);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
afterEach(() => {
|
|
81
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
function writeScopeFile(subDir: string, filename: string, content: string): string {
|
|
85
|
+
const dir = path.join(tmpDir, subDir);
|
|
86
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
87
|
+
const filePath = path.join(dir, filename);
|
|
88
|
+
fs.writeFileSync(filePath, content);
|
|
89
|
+
return filePath;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
it('parses YAML frontmatter scope', () => {
|
|
93
|
+
const file = writeScopeFile('backlog', '001-test-scope.md', `---
|
|
94
|
+
title: Test Scope
|
|
95
|
+
status: backlog
|
|
96
|
+
priority: high
|
|
97
|
+
tags: [feature, backend]
|
|
98
|
+
blocked_by: [2, 3]
|
|
99
|
+
---
|
|
100
|
+
# Test Scope
|
|
101
|
+
|
|
102
|
+
Some content here.
|
|
103
|
+
`);
|
|
104
|
+
const result = parseScopeFile(file);
|
|
105
|
+
expect(result).not.toBeNull();
|
|
106
|
+
expect(result!.id).toBe(1);
|
|
107
|
+
expect(result!.title).toBe('Test Scope');
|
|
108
|
+
expect(result!.status).toBe('backlog');
|
|
109
|
+
expect(result!.priority).toBe('high');
|
|
110
|
+
expect(result!.tags).toEqual(['feature', 'backend']);
|
|
111
|
+
expect(result!.blocked_by).toEqual([2, 3]);
|
|
112
|
+
expect(result!.raw_content).toContain('Some content here.');
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('extracts ID with suffix encoding: a→1000+base', () => {
|
|
116
|
+
const file = writeScopeFile('implementing', '047a-variant.md', `---
|
|
117
|
+
title: Variant A
|
|
118
|
+
status: implementing
|
|
119
|
+
---
|
|
120
|
+
Content
|
|
121
|
+
`);
|
|
122
|
+
const result = parseScopeFile(file);
|
|
123
|
+
expect(result!.id).toBe(1047); // 1000 + 47
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('extracts ID with suffix encoding: X→9000+base', () => {
|
|
127
|
+
const file = writeScopeFile('review', '075X-experimental.md', `---
|
|
128
|
+
title: Experimental
|
|
129
|
+
status: review
|
|
130
|
+
---
|
|
131
|
+
Content
|
|
132
|
+
`);
|
|
133
|
+
const result = parseScopeFile(file);
|
|
134
|
+
expect(result!.id).toBe(9075); // 9000 + 75
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('generates negative hash ID for slug-only icebox files', () => {
|
|
138
|
+
const file = writeScopeFile('icebox', 'onboarding-flow.md', `---
|
|
139
|
+
title: Onboarding Flow
|
|
140
|
+
status: icebox
|
|
141
|
+
---
|
|
142
|
+
An idea for onboarding.
|
|
143
|
+
`);
|
|
144
|
+
const result = parseScopeFile(file);
|
|
145
|
+
expect(result).not.toBeNull();
|
|
146
|
+
expect(result!.id).toBeLessThan(0);
|
|
147
|
+
expect(result!.slug).toBe('onboarding-flow');
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('parses markdown-only scope (no YAML)', () => {
|
|
151
|
+
const file = writeScopeFile('planning', '010-markdown-only.md', `# Scope 010: Markdown Feature
|
|
152
|
+
## Priority: high
|
|
153
|
+
## Estimated Effort: 3 days
|
|
154
|
+
## Category: Backend
|
|
155
|
+
|
|
156
|
+
Implementation details...
|
|
157
|
+
`);
|
|
158
|
+
const result = parseScopeFile(file);
|
|
159
|
+
expect(result).not.toBeNull();
|
|
160
|
+
expect(result!.id).toBe(10);
|
|
161
|
+
expect(result!.title).toBe('Markdown Feature');
|
|
162
|
+
expect(result!.priority).toBe('high');
|
|
163
|
+
expect(result!.effort_estimate).toBe('3 days');
|
|
164
|
+
expect(result!.category).toBe('Backend');
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('rejects invalid priority', () => {
|
|
168
|
+
const file = writeScopeFile('backlog', '002-test.md', `---
|
|
169
|
+
title: Bad Priority
|
|
170
|
+
status: backlog
|
|
171
|
+
priority: urgent
|
|
172
|
+
---
|
|
173
|
+
Content
|
|
174
|
+
`);
|
|
175
|
+
const result = parseScopeFile(file);
|
|
176
|
+
expect(result!.priority).toBeNull();
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it('validates session keys', () => {
|
|
180
|
+
const file = writeScopeFile('implementing', '003-sessions.md', `---
|
|
181
|
+
title: With Sessions
|
|
182
|
+
status: implementing
|
|
183
|
+
sessions:
|
|
184
|
+
implementScope: ["session-1"]
|
|
185
|
+
invalidKey: ["session-2"]
|
|
186
|
+
---
|
|
187
|
+
Content
|
|
188
|
+
`);
|
|
189
|
+
const result = parseScopeFile(file);
|
|
190
|
+
expect(result!.sessions).toHaveProperty('implementScope');
|
|
191
|
+
expect(result!.sessions).not.toHaveProperty('invalidKey');
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('handles ghost scopes', () => {
|
|
195
|
+
const file = writeScopeFile('icebox', '004-ghost.md', `---
|
|
196
|
+
title: Ghost Idea
|
|
197
|
+
status: icebox
|
|
198
|
+
ghost: true
|
|
199
|
+
---
|
|
200
|
+
AI-generated idea
|
|
201
|
+
`);
|
|
202
|
+
const result = parseScopeFile(file);
|
|
203
|
+
expect(result!.is_ghost).toBe(true);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it('returns null for template/non-scope files', () => {
|
|
207
|
+
const file = writeScopeFile('backlog', '_template.md', `---
|
|
208
|
+
title: Template
|
|
209
|
+
---
|
|
210
|
+
Template content
|
|
211
|
+
`);
|
|
212
|
+
expect(parseScopeFile(file)).toBeNull();
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
describe('parseAllScopes()', () => {
|
|
217
|
+
let tmpDir: string;
|
|
218
|
+
|
|
219
|
+
beforeEach(() => {
|
|
220
|
+
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'scopes-test-'));
|
|
221
|
+
setValidStatuses(['icebox', 'planning', 'backlog', 'implementing']);
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
afterEach(() => {
|
|
225
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it('recursively scans and parses all .md files', () => {
|
|
229
|
+
const backlogDir = path.join(tmpDir, 'backlog');
|
|
230
|
+
const planningDir = path.join(tmpDir, 'planning');
|
|
231
|
+
fs.mkdirSync(backlogDir, { recursive: true });
|
|
232
|
+
fs.mkdirSync(planningDir, { recursive: true });
|
|
233
|
+
|
|
234
|
+
fs.writeFileSync(path.join(backlogDir, '001-first.md'), '---\ntitle: First\nstatus: backlog\n---\nContent\n');
|
|
235
|
+
fs.writeFileSync(path.join(planningDir, '002-second.md'), '---\ntitle: Second\nstatus: planning\n---\nContent\n');
|
|
236
|
+
|
|
237
|
+
const scopes = parseAllScopes(tmpDir);
|
|
238
|
+
expect(scopes).toHaveLength(2);
|
|
239
|
+
expect(scopes[0].id).toBe(1);
|
|
240
|
+
expect(scopes[1].id).toBe(2);
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it('deduplicates by ID (first-seen wins)', () => {
|
|
244
|
+
const dir1 = path.join(tmpDir, 'backlog');
|
|
245
|
+
const dir2 = path.join(tmpDir, 'planning');
|
|
246
|
+
fs.mkdirSync(dir1, { recursive: true });
|
|
247
|
+
fs.mkdirSync(dir2, { recursive: true });
|
|
248
|
+
|
|
249
|
+
fs.writeFileSync(path.join(dir1, '001-original.md'), '---\ntitle: Original\nstatus: backlog\n---\n');
|
|
250
|
+
fs.writeFileSync(path.join(dir2, '001-duplicate.md'), '---\ntitle: Duplicate\nstatus: planning\n---\n');
|
|
251
|
+
|
|
252
|
+
const scopes = parseAllScopes(tmpDir);
|
|
253
|
+
expect(scopes).toHaveLength(1);
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
it('returns empty array for non-existent directory', () => {
|
|
257
|
+
expect(parseAllScopes('/tmp/nonexistent-scopes-dir')).toEqual([]);
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it('returns sorted by ID', () => {
|
|
261
|
+
const dir = path.join(tmpDir, 'backlog');
|
|
262
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
263
|
+
fs.writeFileSync(path.join(dir, '003-third.md'), '---\ntitle: Third\nstatus: backlog\n---\n');
|
|
264
|
+
fs.writeFileSync(path.join(dir, '001-first.md'), '---\ntitle: First\nstatus: backlog\n---\n');
|
|
265
|
+
fs.writeFileSync(path.join(dir, '002-second.md'), '---\ntitle: Second\nstatus: backlog\n---\n');
|
|
266
|
+
|
|
267
|
+
const scopes = parseAllScopes(tmpDir);
|
|
268
|
+
expect(scopes.map(s => s.id)).toEqual([1, 2, 3]);
|
|
269
|
+
});
|
|
270
|
+
});
|