@taskforcehq/taskforce 0.3.170 → 0.3.300
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 +52 -21
- package/dist/Taskforce.module.css +3394 -5981
- package/dist/TaskforceCore.CategoryFallback.test.js +5 -2
- package/dist/TaskforceCore.filter-persistence.test.js +402 -0
- package/dist/TaskforceCore.js +388 -71
- package/dist/TaskforceCore.routing.test.js +311 -0
- package/dist/TaskforceCore.test.js +3344 -615
- package/dist/TaskforceWidget.js +3 -2
- package/dist/__tests__/localizationCatalogs.test.js +48 -31
- package/dist/__tests__/workflowSimulation.test.js +2 -2
- package/dist/annotatedAttachments/AnnotatedAttachmentSessionStore.d.ts +60 -0
- package/dist/annotatedAttachments/AnnotatedAttachmentSessionStore.js +324 -0
- package/dist/annotatedAttachments/AnnotatedAttachmentSessionStore.test.js +278 -0
- package/dist/annotatedAttachments/payload.d.ts +2 -0
- package/dist/annotatedAttachments/payload.js +54 -0
- package/dist/annotatedAttachments/payload.test.js +67 -0
- package/dist/annotatedAttachments/service.d.ts +49 -0
- package/dist/annotatedAttachments/service.js +121 -0
- package/dist/annotatedAttachments/types.d.ts +86 -0
- package/dist/cli.js +74 -25
- package/dist/compat/deploymentCompat.d.ts +12 -0
- package/dist/compat/deploymentCompat.js +43 -0
- package/dist/compat/workspaceSyncCompat.d.ts +6 -0
- package/dist/compat/workspaceSyncCompat.js +79 -0
- package/dist/compat/workspaceSyncCompat.test.js +87 -0
- package/dist/components/features/AgentsModule.d.ts +5 -0
- package/dist/components/features/AgentsModule.js +131 -0
- package/dist/components/features/AgentsModule.test.js +102 -0
- package/dist/components/features/AnnotatedAttachmentWorkspace.d.ts +24 -0
- package/dist/components/features/AnnotatedAttachmentWorkspace.js +1942 -0
- package/dist/components/features/AnnotatedAttachmentWorkspace.test.js +2831 -0
- package/dist/components/features/DocumentGenerateModal.js +8 -16
- package/dist/components/features/DocumentIndex.d.ts +3 -4
- package/dist/components/features/DocumentIndex.js +22 -10
- package/dist/components/features/DocumentViewer.d.ts +6 -2
- package/dist/components/features/DocumentViewer.js +1000 -18
- package/dist/components/features/DocumentWorkspace.d.ts +40 -2
- package/dist/components/features/DocumentWorkspace.js +96 -16
- package/dist/components/features/DocumentWorkspace.test.js +1202 -0
- package/dist/components/features/InitiativesModule.d.ts +22 -0
- package/dist/components/features/InitiativesModule.js +33 -0
- package/dist/components/features/TaskSettings.d.ts +41 -32
- package/dist/components/features/TaskSettings.js +798 -313
- package/dist/components/features/TaskSettings.test.js +1221 -47
- package/dist/components/features/WorkflowsModule.d.ts +27 -0
- package/dist/components/features/WorkflowsModule.js +21 -0
- package/dist/components/features/documentWorkspaceFilters.d.ts +10 -0
- package/dist/components/features/documentWorkspaceFilters.js +11 -0
- package/dist/components/features/settings/CategoryManager.d.ts +2 -0
- package/dist/components/features/settings/CategoryManager.js +15 -8
- package/dist/components/features/settings/PriorityManager.d.ts +18 -0
- package/dist/components/features/settings/PriorityManager.js +51 -0
- package/dist/components/features/settings/TaxonomyEditor.d.ts +2 -1
- package/dist/components/features/settings/TaxonomyEditor.js +41 -18
- package/dist/components/features/settings/TaxonomyLibraryManager.d.ts +26 -0
- package/dist/components/features/settings/TaxonomyLibraryManager.js +301 -0
- package/dist/components/features/settings/TaxonomyLibraryManager.test.js +141 -0
- package/dist/components/features/settings/TaxonomyManager.d.ts +35 -12
- package/dist/components/features/settings/TaxonomyManager.js +59 -27
- package/dist/components/features/settings/TypeManager.d.ts +11 -0
- package/dist/components/features/settings/TypeManager.js +48 -11
- package/dist/components/features/settings/{WorkflowEditorPrototype.d.ts → WorkflowEditor.d.ts} +2 -2
- package/dist/components/features/settings/{WorkflowEditorPrototype.js → WorkflowEditor.js} +3 -3
- package/dist/components/task/TaskActionHeader.d.ts +12 -2
- package/dist/components/task/TaskActionHeader.js +64 -8
- package/dist/components/task/TaskActionHeader.test.js +73 -0
- package/dist/components/task/TaskCard.d.ts +14 -16
- package/dist/components/task/TaskCard.js +144 -174
- package/dist/components/task/TaskCard.test.js +416 -64
- package/dist/components/task/TaskContextUpload.d.ts +6 -5
- package/dist/components/task/TaskContextUpload.js +199 -64
- package/dist/components/task/TaskContextUpload.test.js +331 -14
- package/dist/components/task/TaskForm.d.ts +23 -29
- package/dist/components/task/TaskForm.js +348 -169
- package/dist/components/task/TaskForm.test.js +419 -23
- package/dist/components/task/TaskKanban.d.ts +20 -21
- package/dist/components/task/TaskKanban.js +176 -316
- package/dist/components/task/TaskKanban.planning-drop.test.js +93 -0
- package/dist/components/task/TaskList.d.ts +22 -11
- package/dist/components/task/TaskList.js +98 -12
- package/dist/components/task/TaskList.test.js +206 -7
- package/dist/components/task/TaskReferenceBadge.d.ts +12 -0
- package/dist/components/task/TaskReferenceBadge.js +5 -0
- package/dist/components/task/TaskStatusActions.d.ts +12 -0
- package/dist/components/task/TaskStatusActions.js +18 -0
- package/dist/components/task/TaskStatusActions.test.js +45 -0
- package/dist/components/ui/ImageReferenceBadge.d.ts +12 -0
- package/dist/components/ui/ImageReferenceBadge.js +5 -0
- package/dist/components/ui/LevelSelector.d.ts +2 -1
- package/dist/components/ui/LevelSelector.js +2 -2
- package/dist/components/ui/Markdown.d.ts +1 -2
- package/dist/components/ui/Markdown.js +2 -13
- package/dist/components/ui/Modal.d.ts +3 -2
- package/dist/components/ui/Modal.js +4 -3
- package/dist/components/ui/MultiSelectFilter.d.ts +3 -1
- package/dist/components/ui/MultiSelectFilter.js +2 -2
- package/dist/components/ui/ReferenceBadgeButton.d.ts +13 -0
- package/dist/components/ui/ReferenceBadgeButton.js +6 -0
- package/dist/components/ui/TaxonomyDropdown.d.ts +7 -1
- package/dist/components/ui/TaxonomyDropdown.js +58 -23
- package/dist/components/ui/TopNoticeLayer.d.ts +7 -0
- package/dist/components/ui/TopNoticeLayer.js +14 -0
- package/dist/components/ui/TopNoticeLayer.test.js +25 -0
- package/dist/components/views/AppShellHeader.d.ts +13 -0
- package/dist/components/views/AppShellHeader.js +19 -0
- package/dist/components/views/AppShellHeader.test.js +21 -0
- package/dist/components/views/PlanComparisonPage.d.ts +73 -0
- package/dist/components/views/PlanComparisonPage.js +196 -0
- package/dist/components/views/PlanComparisonPage.test.js +251 -0
- package/dist/components/views/PlansPage.d.ts +14 -0
- package/dist/components/views/PlansPage.js +355 -0
- package/dist/components/views/StandaloneLayout.d.ts +2 -2
- package/dist/components/views/StandaloneLayout.js +2212 -1194
- package/dist/components/views/WidgetView.d.ts +2 -2
- package/dist/components/views/WidgetView.js +149 -43
- package/dist/components/views/chrome/WorkspaceChromeSections.d.ts +57 -0
- package/dist/components/views/chrome/WorkspaceChromeSections.js +38 -0
- package/dist/components/views/chrome/WorkspaceChromeSections.test.js +54 -0
- package/dist/components/views/chrome/workspaceChrome.d.ts +31 -0
- package/dist/components/views/chrome/workspaceChrome.js +108 -0
- package/dist/components/views/chrome/workspaceChrome.test.js +52 -0
- package/dist/components/views/panels/DocumentFilterToolbar.d.ts +10 -0
- package/dist/components/views/panels/DocumentFilterToolbar.js +7 -0
- package/dist/components/views/panels/DocumentFilterToolbar.test.js +19 -0
- package/dist/components/views/panels/FilterToolbar.d.ts +66 -0
- package/dist/components/views/panels/FilterToolbar.js +21 -0
- package/dist/components/views/panels/FilterToolbar.test.d.ts +1 -0
- package/dist/components/views/panels/FilterToolbar.test.js +45 -0
- package/dist/components/views/panels/FilterToolbarControls.d.ts +46 -0
- package/dist/components/views/panels/FilterToolbarControls.js +61 -0
- package/dist/components/views/panels/PlanningDrawer.d.ts +115 -0
- package/dist/components/views/panels/PlanningDrawer.js +220 -0
- package/dist/components/views/panels/ScheduleSidebar.d.ts +52 -0
- package/dist/components/views/panels/ScheduleSidebar.js +127 -0
- package/dist/components/views/panels/scheduleUtils.d.ts +14 -0
- package/dist/components/views/panels/scheduleUtils.js +79 -0
- package/dist/components/views/teamManagementAccess.d.ts +6 -0
- package/dist/components/views/teamManagementAccess.js +18 -0
- package/dist/components/views/teamManagementAccess.test.d.ts +1 -0
- package/dist/components/views/teamManagementAccess.test.js +44 -0
- package/dist/config/clientDeployment.d.ts +2 -0
- package/dist/config/clientDeployment.js +13 -0
- package/dist/config/cloudEnvironment.d.ts +15 -0
- package/dist/config/cloudEnvironment.js +60 -0
- package/dist/config/deployment.d.ts +20 -0
- package/dist/config/deployment.js +67 -0
- package/dist/config/deployment.test.d.ts +1 -0
- package/dist/config/deployment.test.js +88 -0
- package/dist/config/envSchema.js +36 -8
- package/dist/config/envSchema.test.js +28 -0
- package/dist/core/AiProfileService.d.ts +66 -0
- package/dist/core/AiProfileService.js +320 -0
- package/dist/core/AiProfileService.test.d.ts +1 -0
- package/dist/core/AiProfileService.test.js +164 -0
- package/dist/core/AiProfiles.test.d.ts +1 -0
- package/dist/core/AiProfiles.test.js +449 -0
- package/dist/core/AttachmentLinkService.d.ts +15 -0
- package/dist/core/AttachmentLinkService.js +157 -0
- package/dist/core/AuthTokenService.d.ts +44 -0
- package/dist/core/AuthTokenService.js +207 -0
- package/dist/core/CreatedBy.test.js +134 -6
- package/dist/core/DeletedTaskLifecycleService.d.ts +33 -0
- package/dist/core/DeletedTaskLifecycleService.js +158 -0
- package/dist/core/DeletedTaskTrash.test.d.ts +1 -0
- package/dist/core/DeletedTaskTrash.test.js +104 -0
- package/dist/core/EntitlementsPolicy.test.js +78 -5
- package/dist/core/GlobalSettingsService.d.ts +16 -0
- package/dist/core/GlobalSettingsService.js +370 -0
- package/dist/core/JsonBackupRuntime.test.d.ts +1 -0
- package/dist/core/JsonBackupRuntime.test.js +155 -0
- package/dist/core/McpTokenService.d.ts +118 -0
- package/dist/core/McpTokenService.js +921 -0
- package/dist/core/PlanEntitlementService.d.ts +201 -0
- package/dist/core/PlanEntitlementService.js +1442 -0
- package/dist/core/PlanVersionPolicy.test.d.ts +1 -0
- package/dist/core/PlanVersionPolicy.test.js +178 -0
- package/dist/core/PlanningEntities.test.d.ts +1 -0
- package/dist/core/PlanningEntities.test.js +95 -0
- package/dist/core/ScheduleFields.test.js +15 -19
- package/dist/core/SignupMonetizationSettings.test.d.ts +1 -0
- package/dist/core/SignupMonetizationSettings.test.js +159 -0
- package/dist/core/Stats.test.d.ts +1 -0
- package/dist/core/Stats.test.js +36 -0
- package/dist/core/SyncReconciliationService.d.ts +93 -0
- package/dist/core/SyncReconciliationService.js +406 -0
- package/dist/core/SystemAdmin.test.js +578 -13
- package/dist/core/TaskActivityService.d.ts +21 -0
- package/dist/core/TaskActivityService.js +130 -0
- package/dist/core/TaskAttachmentsCanonical.test.d.ts +1 -0
- package/dist/core/TaskAttachmentsCanonical.test.js +306 -0
- package/dist/core/TaskAuditTimeline.test.d.ts +1 -0
- package/dist/core/TaskAuditTimeline.test.js +132 -0
- package/dist/core/TaskTaxonomyValidation.test.js +338 -15
- package/dist/core/Taskforce.d.ts +930 -183
- package/dist/core/Taskforce.ids.test.js +252 -0
- package/dist/core/Taskforce.js +3848 -2532
- package/dist/core/Taskforce.mcpAuth.test.d.ts +1 -0
- package/dist/core/Taskforce.mcpAuth.test.js +343 -0
- package/dist/core/Taskforce.realtimeMutation.test.js +57 -2
- package/dist/core/TaxonomySettingsService.d.ts +18 -0
- package/dist/core/TaxonomySettingsService.js +162 -0
- package/dist/core/WorkspaceDelete.test.js +32 -13
- package/dist/core/WorkspaceLifecycleService.d.ts +11 -0
- package/dist/core/WorkspaceLifecycleService.js +88 -0
- package/dist/core/WorkspacePermissions.test.js +95 -0
- package/dist/core/WorkspacePlanMode.test.js +114 -1
- package/dist/core/WorkspacePreferenceService.d.ts +41 -0
- package/dist/core/WorkspacePreferenceService.js +246 -0
- package/dist/core/WorkspaceSyncSettings.test.d.ts +1 -0
- package/dist/core/WorkspaceSyncSettings.test.js +65 -0
- package/dist/core/__tests__/TaskAttachmentsCanonical.test.d.ts +1 -0
- package/dist/core/__tests__/TaskAttachmentsCanonical.test.js +212 -0
- package/dist/core/shared.d.ts +36 -0
- package/dist/core/shared.js +128 -0
- package/dist/core/types.d.ts +614 -0
- package/dist/core/types.js +27 -0
- package/dist/documentReviews/DocumentReviewCommentStore.d.ts +56 -0
- package/dist/documentReviews/DocumentReviewCommentStore.js +230 -0
- package/dist/documentReviews/DocumentReviewSessionStore.d.ts +52 -0
- package/dist/documentReviews/DocumentReviewSessionStore.js +193 -0
- package/dist/documentReviews/DocumentReviewSessionStore.test.d.ts +1 -0
- package/dist/documentReviews/DocumentReviewSessionStore.test.js +127 -0
- package/dist/documentReviews/service.d.ts +68 -0
- package/dist/documentReviews/service.js +210 -0
- package/dist/documentReviews/types.d.ts +58 -0
- package/dist/documentReviews/types.js +1 -0
- package/dist/hooks/auth/useAuthGuardPolicy.d.ts +2 -0
- package/dist/hooks/auth/useAuthGuardPolicy.js +1 -0
- package/dist/hooks/tasks/useCurrentTaskRelations.d.ts +15 -0
- package/dist/hooks/tasks/useCurrentTaskRelations.js +37 -0
- package/dist/hooks/tasks/useTaskActions.d.ts +3 -0
- package/dist/hooks/tasks/useTaskActions.js +2 -0
- package/dist/hooks/tasks/useTaskEditorNavigation.d.ts +65 -0
- package/dist/hooks/tasks/useTaskEditorNavigation.js +235 -0
- package/dist/hooks/tasks/useTaskFilters.d.ts +2 -0
- package/dist/hooks/tasks/useTaskFilters.js +2 -0
- package/dist/hooks/tasks/useTaskFormActions.d.ts +58 -0
- package/dist/hooks/tasks/useTaskFormActions.js +365 -0
- package/dist/hooks/tasks/useTaskRelationships.d.ts +16 -0
- package/dist/hooks/tasks/useTaskRelationships.js +64 -0
- package/dist/hooks/ui/useResourceExport.d.ts +19 -0
- package/dist/hooks/ui/useResourceExport.js +84 -0
- package/dist/hooks/ui/useSettingsModel.d.ts +203 -0
- package/dist/hooks/ui/useSettingsModel.js +125 -0
- package/dist/hooks/ui/useSettingsPersistence.d.ts +36 -0
- package/dist/hooks/ui/useSettingsPersistence.js +254 -0
- package/dist/hooks/ui/useSettingsTaxonomyManagement.d.ts +119 -0
- package/dist/hooks/ui/useSettingsTaxonomyManagement.js +536 -0
- package/dist/hooks/ui/useUiNotice.d.ts +1 -0
- package/dist/hooks/ui/useUiNotice.js +1 -0
- package/dist/hooks/ui/useWorkflowTemplates.d.ts +37 -0
- package/dist/hooks/ui/useWorkflowTemplates.js +111 -0
- package/dist/hooks/ui/useZenMode.d.ts +5 -0
- package/dist/hooks/ui/useZenMode.js +32 -0
- package/dist/hooks/useFilterSort.d.ts +60 -0
- package/dist/hooks/useFilterSort.js +362 -0
- package/dist/hooks/useFilterSort.test.d.ts +1 -0
- package/dist/hooks/useFilterSort.test.js +333 -0
- package/dist/hooks/useRealtimeSync.d.ts +1 -0
- package/dist/hooks/useRealtimeSync.js +24 -9
- package/dist/hooks/useRealtimeSync.test.js +28 -1
- package/dist/hooks/useSyncOrchestrator.aiProfiles.test.d.ts +1 -0
- package/dist/hooks/useSyncOrchestrator.aiProfiles.test.js +34 -0
- package/dist/hooks/useSyncOrchestrator.d.ts +65 -103
- package/dist/hooks/useSyncOrchestrator.js +1538 -670
- package/dist/hooks/useSyncOrchestrator.retry-closure.test.js +700 -174
- package/dist/hooks/useTaskData.d.ts +35 -0
- package/dist/hooks/useTaskData.js +239 -0
- package/dist/hooks/useTaskData.test.d.ts +1 -0
- package/dist/hooks/useTaskData.test.js +119 -0
- package/dist/hooks/useTaskMutations.d.ts +46 -0
- package/dist/hooks/useTaskMutations.js +472 -0
- package/dist/hooks/useTaskMutations.test.d.ts +1 -0
- package/dist/hooks/useTaskMutations.test.js +80 -0
- package/dist/hooks/useTaskforce.contract.test.d.ts +1 -0
- package/dist/hooks/useTaskforce.contract.test.js +7 -0
- package/dist/hooks/useTaskforce.d.ts +260 -295
- package/dist/hooks/useTaskforce.js +1954 -2623
- package/dist/hooks/useTaskforce.priority-filters.test.js +6 -11
- package/dist/hooks/useTaskforce.sync-behavior.test.d.ts +1 -0
- package/dist/hooks/useTaskforce.sync-behavior.test.js +1120 -0
- package/dist/hooks/useUiNotice.d.ts +16 -0
- package/dist/hooks/useUiNotice.js +49 -0
- package/dist/hooks/useWorkspaceSyncController.d.ts +23 -46
- package/dist/hooks/useWorkspaceSyncController.js +280 -461
- package/dist/hooks/useWorkspaceSyncController.test.js +106 -199
- package/dist/hooks/workspace/useTaskforceApiRouting.d.ts +8 -0
- package/dist/hooks/workspace/useTaskforceApiRouting.js +91 -0
- package/dist/hooks/workspace/useTaskforceApiRouting.test.d.ts +1 -0
- package/dist/hooks/workspace/useTaskforceApiRouting.test.js +60 -0
- package/dist/hooks/workspace/useWorkspaceSyncController.d.ts +1 -0
- package/dist/hooks/workspace/useWorkspaceSyncController.js +1 -0
- package/dist/hooks/workspace/workspaceLocalState.d.ts +30 -0
- package/dist/hooks/workspace/workspaceLocalState.js +101 -0
- package/dist/localization/locales/en-US.d.ts +1 -8
- package/dist/localization/locales/en-US.js +4 -11
- package/dist/localization/locales/es-419.js +2 -9
- package/dist/localization/locales/pt-BR.js +2 -9
- package/dist/localization/localizationCatalogs.test.d.ts +1 -0
- package/dist/localization/localizationCatalogs.test.js +37 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.js +9 -15
- package/dist/mcp/clientIntegrations.d.ts +33 -0
- package/dist/mcp/clientIntegrations.js +199 -0
- package/dist/mcp/clientIntegrations.test.d.ts +1 -0
- package/dist/mcp/clientIntegrations.test.js +110 -0
- package/dist/mcp/index.d.ts +2 -0
- package/dist/mcp/index.js +2 -0
- package/dist/mcp/optionResolution.test.js +6 -2
- package/dist/mcp/runtime.d.ts +120 -0
- package/dist/mcp/runtime.js +5668 -0
- package/dist/mcp/runtime.test.d.ts +1 -0
- package/dist/mcp/runtime.test.js +3293 -0
- package/dist/mcp/server.js +2 -1793
- package/dist/mcp/structuredCommentValidation.test.d.ts +1 -0
- package/dist/{__tests__ → mcp}/structuredCommentValidation.test.js +1 -1
- package/dist/mcp/structuredDocValidation.js +1 -2
- package/dist/mcp/structuredDocValidation.test.d.ts +1 -0
- package/dist/{__tests__ → mcp}/structuredDocValidation.test.js +9 -4
- package/dist/mcp/toolRegistry.d.ts +570 -0
- package/dist/mcp/toolRegistry.js +90 -0
- package/dist/mcp/toolRegistry.test.d.ts +1 -0
- package/dist/mcp/toolRegistry.test.js +30 -0
- package/dist/migrations/billingSchemaParity.test.js +111 -0
- package/dist/migrations/taskSchemaMigrations.d.ts +5 -0
- package/dist/migrations/taskSchemaMigrations.js +681 -39
- package/dist/migrations/taskSchemaMigrations.test.d.ts +1 -0
- package/dist/migrations/taskSchemaMigrations.test.js +210 -0
- package/dist/plugins/vite.js +13 -7
- package/dist/public/apple-touch-icon.png +0 -0
- package/dist/public/archive/phoenix/apple-touch-icon.png +0 -0
- package/dist/public/archive/phoenix/favicon.ico +0 -0
- package/dist/public/archive/phoenix/site.webmanifest +1 -0
- package/dist/public/favicon-96x96.png +0 -0
- package/dist/public/favicon.ico +0 -0
- package/dist/public/favicon.svg +17 -0
- package/dist/public/site.webmanifest +21 -1
- package/dist/public/web-app-manifest-192x192.png +0 -0
- package/dist/public/web-app-manifest-512x512.png +0 -0
- package/dist/releaseVersion.test.d.ts +1 -0
- package/dist/{__tests__/releaseVersion.test.js → releaseVersion.test.js} +1 -1
- package/dist/resources/templates/WORKFLOW_V2_POLICY.md +1 -1
- package/dist/resources/templates/workflow-sources/workflowDocs.mjs +62 -52
- package/dist/resources/templates/workflows/collaborate.yaml +11 -5
- package/dist/resources/templates/workflows/do.yaml +8 -2
- package/dist/resources/templates/workflows/evaluate.yaml +13 -7
- package/dist/resources/templates/workflows/execute.yaml +40 -23
- package/dist/resources/templates/workflows/plan.yaml +15 -8
- package/dist/resources/templates/workflows/review.yaml +14 -8
- package/dist/runtime/appGateDefinitions.d.ts +32 -0
- package/dist/runtime/appGateDefinitions.js +32 -0
- package/dist/runtime/appGates.d.ts +29 -0
- package/dist/runtime/appGates.js +53 -0
- package/dist/runtime/appGates.test.d.ts +1 -0
- package/dist/runtime/appGates.test.js +42 -0
- package/dist/runtime/migrationFlags.d.ts +1 -0
- package/dist/runtime/migrationFlags.js +1 -0
- package/dist/server/annotatedAttachmentsRoutes.test.d.ts +1 -0
- package/dist/server/annotatedAttachmentsRoutes.test.js +473 -0
- package/dist/server/auth.js +14 -2
- package/dist/server/auth.test.js +21 -1
- package/dist/server/cors.js +11 -5
- package/dist/server/cors.test.js +6 -0
- package/dist/server/documentReviewRoutes.test.d.ts +1 -0
- package/dist/server/documentReviewRoutes.test.js +157 -0
- package/dist/server/index.cookieProxy.test.js +46 -1
- package/dist/server/index.d.ts +20 -0
- package/dist/server/index.js +168 -41
- package/dist/server/index.rateLimit.test.js +6 -0
- package/dist/server/index.test.js +133 -2
- package/dist/server/mockStripe.d.ts +72 -0
- package/dist/server/mockStripe.js +357 -0
- package/dist/server/realtimeSyncWs.js +4 -0
- package/dist/server/routes/admin.d.ts +114 -0
- package/dist/server/routes/admin.js +2226 -0
- package/dist/server/routes/annotatedAttachments.d.ts +24 -0
- package/dist/server/routes/annotatedAttachments.js +235 -0
- package/dist/server/routes/auth.d.ts +61 -0
- package/dist/server/routes/auth.js +1296 -0
- package/dist/server/{routes.billing.d.ts → routes/billing.d.ts} +3 -2
- package/dist/server/routes/billing.js +2001 -0
- package/dist/server/routes/billing.test.d.ts +1 -0
- package/dist/server/routes/billing.test.js +1631 -0
- package/dist/server/routes/documentReviews.d.ts +11 -0
- package/dist/server/routes/documentReviews.js +191 -0
- package/dist/server/routes/documents.d.ts +118 -0
- package/dist/server/routes/documents.js +1113 -0
- package/dist/server/routes/resources.d.ts +25 -0
- package/dist/server/routes/resources.js +225 -0
- package/dist/server/routes/shared.d.ts +35 -0
- package/dist/server/routes/shared.js +305 -0
- package/dist/server/routes/shared.test.d.ts +1 -0
- package/dist/server/routes/shared.test.js +32 -0
- package/dist/server/{routes.sync.d.ts → routes/sync.d.ts} +5 -5
- package/dist/server/routes/sync.integration.test.d.ts +1 -0
- package/dist/server/routes/sync.integration.test.js +2003 -0
- package/dist/server/routes/sync.js +3143 -0
- package/dist/server/routes/tasks.d.ts +72 -0
- package/dist/server/routes/tasks.js +1252 -0
- package/dist/server/routes/workspaces.d.ts +32 -0
- package/dist/server/routes/workspaces.js +307 -0
- package/dist/server/routes.d.ts +8 -9
- package/dist/server/routes.js +968 -4092
- package/dist/server/routes.test.js +9043 -2415
- package/dist/server/runtimeMode.d.ts +1 -1
- package/dist/server/runtimeMode.js +3 -18
- package/dist/server/runtimeMode.test.js +3 -3
- package/dist/server/securityHeaders.d.ts +1 -1
- package/dist/server/securityHeaders.js +65 -6
- package/dist/server/securityHeaders.test.js +40 -2
- package/dist/services/templateEngine.test.d.ts +1 -0
- package/dist/{__tests__ → services}/templateEngine.test.js +1 -1
- package/dist/services/templates.test.d.ts +1 -0
- package/dist/{__tests__ → services}/templates.test.js +1 -1
- package/dist/services/workflowDocumentFixtures.test.d.ts +1 -0
- package/dist/{__tests__ → services}/workflowDocumentFixtures.test.js +4 -4
- package/dist/services/workflowExportMatrix.test.d.ts +1 -0
- package/dist/{__tests__ → services}/workflowExportMatrix.test.js +1 -1
- package/dist/services/workflowExportSnapshots.test.d.ts +1 -0
- package/dist/services/workflowGeneration.test.d.ts +1 -0
- package/dist/services/workflowSimulation.test.d.ts +1 -0
- package/dist/services/workflowSimulation.test.js +113 -0
- package/dist/services/workflowV2Policy.test.d.ts +1 -0
- package/dist/{__tests__ → services}/workflowV2Policy.test.js +2 -2
- package/dist/shared/aiProfileSurfaceType.d.ts +9 -0
- package/dist/shared/aiProfileSurfaceType.js +49 -0
- package/dist/shared/customTaxonomyLibrary.d.ts +11 -0
- package/dist/shared/customTaxonomyLibrary.js +276 -0
- package/dist/shared/customTaxonomyLibrary.test.d.ts +1 -0
- package/dist/shared/customTaxonomyLibrary.test.js +20 -0
- package/dist/shared/taxonomyCatalog.d.ts +19 -0
- package/dist/shared/taxonomyCatalog.js +36 -0
- package/dist/shared/taxonomyDefaults.d.ts +29 -0
- package/dist/shared/taxonomyDefaults.js +26 -0
- package/dist/shared/taxonomyLibrary.d.ts +15 -0
- package/dist/shared/taxonomyLibrary.js +98 -0
- package/dist/shared/taxonomyLibrary.test.d.ts +1 -0
- package/dist/shared/taxonomyLibrary.test.js +26 -0
- package/dist/shared/taxonomyState.d.ts +36 -0
- package/dist/shared/taxonomyState.js +73 -0
- package/dist/shared/taxonomyState.test.d.ts +1 -0
- package/dist/shared/taxonomyState.test.js +71 -0
- package/dist/shared/workflowDefaults.d.ts +9 -0
- package/dist/shared/workflowDefaults.js +11 -0
- package/dist/storage/documentIntegrity.d.ts +2 -0
- package/dist/storage/documentIntegrity.js +34 -17
- package/dist/storage/documentPurge.d.ts +2 -1
- package/dist/storage/documentPurge.js +35 -8
- package/dist/storage/index.d.ts +4 -0
- package/dist/storage/index.js +2 -0
- package/dist/storage/objectStorage.d.ts +1 -1
- package/dist/storage/objectStorageClient.d.ts +6 -4
- package/dist/storage/objectStorageClient.js +77 -29
- package/dist/storage/objectStorageClient.test.d.ts +1 -0
- package/dist/storage/objectStorageClient.test.js +57 -0
- package/dist/storage/objectStorageConfig.js +3 -1
- package/dist/storage/objectStorageConfig.test.d.ts +1 -0
- package/dist/storage/objectStorageConfig.test.js +38 -0
- package/dist/storage/postgresAdapter.d.ts +5 -0
- package/dist/storage/postgresAdapter.js +2 -2
- package/dist/storage/postgresAdapter.test.d.ts +1 -0
- package/dist/storage/postgresAdapter.test.js +29 -0
- package/dist/storage/taskAssetStore.d.ts +7 -4
- package/dist/storage/taskAssetStore.js +65 -60
- package/dist/storage/workspaceAssetStore.d.ts +122 -0
- package/dist/storage/workspaceAssetStore.js +496 -0
- package/dist/storage/workspaceAssetStore.test.d.ts +1 -0
- package/dist/storage/workspaceAssetStore.test.js +501 -0
- package/dist/sync/cloudSyncApi.d.ts +33 -2
- package/dist/sync/cloudSyncApi.js +37 -15
- package/dist/sync/cloudSyncApi.test.js +60 -3
- package/dist/sync/index.d.ts +2 -0
- package/dist/sync/index.js +3 -0
- package/dist/sync/syncService.d.ts +25 -0
- package/dist/sync/syncService.js +184 -16
- package/dist/sync/syncService.test.js +289 -25
- package/dist/sync/workspaceRepair.d.ts +114 -0
- package/dist/sync/workspaceRepair.js +566 -0
- package/dist/sync/workspaceSyncModel.d.ts +230 -2
- package/dist/sync/workspaceSyncModel.js +456 -17
- package/dist/sync/workspaceSyncModel.test.js +642 -0
- package/dist/sync/workspaceSyncState.d.ts +12 -0
- package/dist/sync/workspaceSyncState.js +12 -0
- package/dist/sync/workspaceSyncSurface.d.ts +33 -0
- package/dist/sync/workspaceSyncSurface.js +74 -0
- package/dist/types.d.ts +143 -18
- package/dist/types.js +9 -24
- package/dist/ui/assets/AgentsModule-TVmCgizS.js +1 -0
- package/dist/ui/assets/AnnotatedAttachmentWorkspace-BaS2VwIr.css +1 -0
- package/dist/ui/assets/AnnotatedAttachmentWorkspace-CAyhnPeR.js +3 -0
- package/dist/ui/assets/DocumentWorkspace-BOCw5e4D.js +250 -0
- package/dist/ui/assets/DocumentWorkspace-C_8T8oz-.css +1 -0
- package/dist/ui/assets/InitiativesModule-CN0r02Oi.js +1 -0
- package/dist/ui/assets/PlansPage-BlVC_lRq.css +1 -0
- package/dist/ui/assets/PlansPage-FcQSNLZd.js +1 -0
- package/dist/ui/assets/TaskSettings-BwB9NtmJ.css +1 -0
- package/dist/ui/assets/TaskSettings-Cw5zYD1L.js +8 -0
- package/dist/ui/assets/WorkflowsModule-CY9R2zPB.js +5 -0
- package/dist/ui/assets/index-Bzqy5QGm.js +6 -0
- package/dist/ui/assets/index-DxRiI3tY.css +1 -0
- package/dist/ui/assets/vendor-dnd-DRzYolkg.js +5 -0
- package/dist/ui/assets/{vendor-icons-ZFG3SGwo.js → vendor-icons-QZyhEwgT.js} +1 -1
- package/dist/ui/assets/{vendor-markdown-CKYkQHfj.js → vendor-markdown-BUxTU7dS.js} +1 -1
- package/dist/ui/assets/vendor-react-CKJs5o3c.js +61 -0
- package/dist/ui/assets/vendor-router-BbWMxlnO.js +3 -0
- package/dist/ui/branding/logos/logo.png +0 -0
- package/dist/ui/branding/logos/logo_dark.svg +27 -0
- package/dist/ui/branding/logos/logo_favicon.svg +35 -0
- package/dist/ui/branding/logos/logo_light.svg +27 -0
- package/dist/ui/favicon/apple-touch-icon.png +0 -0
- package/dist/ui/favicon/archive/phoenix/apple-touch-icon.png +0 -0
- package/dist/ui/favicon/archive/phoenix/favicon.ico +0 -0
- package/dist/ui/favicon/archive/phoenix/site.webmanifest +1 -0
- package/dist/ui/favicon/favicon-96x96.png +0 -0
- package/dist/ui/favicon/favicon.ico +0 -0
- package/dist/ui/favicon/favicon.svg +17 -0
- package/dist/ui/favicon/site.webmanifest +21 -1
- package/dist/ui/favicon/web-app-manifest-192x192.png +0 -0
- package/dist/ui/favicon/web-app-manifest-512x512.png +0 -0
- package/dist/ui/index.html +10 -7
- package/dist/ui/product/screen_01.png +0 -0
- package/dist/ui/product/screen_02.png +0 -0
- package/dist/ui/product/screen_03.png +0 -0
- package/dist/utils/annotatedAttachments.d.ts +20 -0
- package/dist/utils/annotatedAttachments.js +74 -0
- package/dist/utils/annotatedAttachments.test.d.ts +1 -0
- package/dist/utils/annotatedAttachments.test.js +108 -0
- package/dist/utils/assignees.d.ts +26 -0
- package/dist/utils/assignees.js +132 -0
- package/dist/utils/canonicalAssetKind.d.ts +16 -0
- package/dist/utils/canonicalAssetKind.js +39 -0
- package/dist/utils/canonicalAssetKind.test.d.ts +1 -0
- package/dist/utils/canonicalAssetKind.test.js +24 -0
- package/dist/utils/coalescedRefresh.d.ts +5 -0
- package/dist/utils/coalescedRefresh.js +16 -0
- package/dist/utils/coalescedRefresh.test.d.ts +1 -0
- package/dist/utils/coalescedRefresh.test.js +30 -0
- package/dist/utils/constants.d.ts +16 -3
- package/dist/utils/constants.icons.test.js +2 -1
- package/dist/utils/constants.js +70 -13
- package/dist/utils/contextAssetEvents.d.ts +7 -0
- package/dist/utils/contextAssetEvents.js +6 -0
- package/dist/utils/contextFiles.d.ts +14 -3
- package/dist/utils/contextFiles.js +40 -8
- package/dist/utils/documentManagerApi.d.ts +6 -0
- package/dist/utils/documentManagerApi.js +19 -0
- package/dist/utils/documentNames.d.ts +24 -0
- package/dist/utils/documentNames.js +91 -0
- package/dist/utils/documentReferences.d.ts +9 -0
- package/dist/utils/documentReferences.js +11 -0
- package/dist/utils/entityReferences.d.ts +9 -0
- package/dist/utils/entityReferences.js +32 -0
- package/dist/utils/imageReferences.d.ts +9 -0
- package/dist/utils/imageReferences.js +11 -0
- package/dist/utils/planParser.d.ts +2 -2
- package/dist/utils/planParser.js +11 -11
- package/dist/utils/planParser.test.d.ts +1 -0
- package/dist/{__tests__ → utils}/planParser.test.js +22 -22
- package/dist/utils/planningReferences.d.ts +17 -0
- package/dist/utils/planningReferences.js +30 -0
- package/dist/utils/planningReferences.test.d.ts +1 -0
- package/dist/utils/planningReferences.test.js +17 -0
- package/dist/utils/taskActivity.d.ts +9 -0
- package/dist/utils/taskActivity.js +147 -0
- package/dist/utils/taskActivity.test.d.ts +1 -0
- package/dist/utils/taskActivity.test.js +34 -0
- package/dist/utils/taskDraftDefaults.d.ts +21 -0
- package/dist/utils/taskDraftDefaults.js +40 -0
- package/dist/utils/taskDraftDefaults.test.d.ts +1 -0
- package/dist/utils/taskDraftDefaults.test.js +34 -0
- package/dist/utils/taskNormalization.d.ts +25 -0
- package/dist/utils/taskNormalization.js +161 -0
- package/dist/utils/taskNormalization.test.d.ts +1 -0
- package/dist/utils/taskNormalization.test.js +158 -0
- package/dist/utils/taskReferences.d.ts +5 -0
- package/dist/utils/taskReferences.js +11 -0
- package/dist/utils/taskforceApiClient.d.ts +2 -0
- package/dist/utils/taskforceApiClient.js +101 -3
- package/dist/utils/taskforceApiClient.test.d.ts +1 -0
- package/dist/utils/taskforceApiClient.test.js +44 -0
- package/dist/utils/taxonomyFilterOptions.d.ts +2 -0
- package/dist/utils/taxonomyFilterOptions.js +17 -0
- package/dist/utils/taxonomyFormDefaults.d.ts +3 -0
- package/dist/utils/taxonomyFormDefaults.js +28 -0
- package/dist/utils/taxonomyFormDefaults.test.d.ts +1 -0
- package/dist/utils/taxonomyFormDefaults.test.js +63 -0
- package/dist/utils/taxonomyLifecycle.d.ts +3 -0
- package/dist/utils/taxonomyLifecycle.js +17 -0
- package/dist/utils/taxonomySorting.d.ts +7 -0
- package/dist/utils/taxonomySorting.js +74 -0
- package/dist/utils/theme.d.ts +15 -0
- package/dist/utils/theme.js +23 -0
- package/dist/utils/uiNotice.d.ts +7 -0
- package/dist/utils/uiNotice.js +6 -0
- package/dist/utils/uiNotice.test.d.ts +1 -0
- package/dist/utils/uiNotice.test.js +18 -0
- package/dist/utils/workspaceIdentity.d.ts +14 -0
- package/dist/utils/workspaceIdentity.js +21 -0
- package/dist/utils/workspaceIdentity.test.js +30 -1
- package/dist/utils/workspaceSyncPresentation.d.ts +20 -0
- package/dist/utils/workspaceSyncPresentation.js +21 -0
- package/dist/utils/workspaceSyncPresentation.test.d.ts +1 -0
- package/dist/utils/workspaceSyncPresentation.test.js +36 -0
- package/package.json +28 -23
- package/scripts/bootstrap-playwright-auth.mjs +155 -0
- package/scripts/check-compat-boundaries.mjs +41 -0
- package/scripts/check-env.ts +9 -2
- package/scripts/debug-login.mjs +32 -0
- package/scripts/migrate-planning-model.ts +233 -0
- package/scripts/migrate-task-data-assets.mjs +408 -0
- package/scripts/playwright-auth.sh +11 -0
- package/scripts/run-dev-proxy.sh +2 -0
- package/scripts/update-homebrew-formula.sh +2 -2
- package/scripts/with-esbuild.sh +11 -0
- package/src/resources/templates/WORKFLOW_V2_POLICY.md +1 -1
- package/src/resources/templates/workflow-sources/workflowDocs.mjs +62 -52
- package/src/resources/templates/workflows/collaborate.yaml +11 -5
- package/src/resources/templates/workflows/do.yaml +8 -2
- package/src/resources/templates/workflows/evaluate.yaml +13 -7
- package/src/resources/templates/workflows/execute.yaml +40 -23
- package/src/resources/templates/workflows/plan.yaml +15 -8
- package/src/resources/templates/workflows/review.yaml +14 -8
- package/dist/TaskforceScreenshot.d.ts +0 -11
- package/dist/TaskforceScreenshot.js +0 -113
- package/dist/compat/priorityCompat.d.ts +0 -2
- package/dist/compat/priorityCompat.js +0 -24
- package/dist/components/features/settings/TaxonomyManager 2.d.ts +0 -52
- package/dist/components/features/settings/TaxonomyManager 2.js +0 -75
- package/dist/components/task/TaskKanban 2.d.ts +0 -76
- package/dist/components/task/TaskKanban 2.js +0 -1004
- package/dist/components/task/TaskScreenshotSection.d.ts +0 -15
- package/dist/components/task/TaskScreenshotSection.js +0 -22
- package/dist/components/views/StandaloneLayout 2.d.ts +0 -8
- package/dist/components/views/StandaloneLayout 2.js +0 -1660
- package/dist/core/InitiativeTemplates.test.js +0 -50
- package/dist/core/ParentLifecycle.test.js +0 -98
- package/dist/migrations/clientMigrations.d.ts +0 -9
- package/dist/migrations/clientMigrations.js +0 -74
- package/dist/migrations/flags.d.ts +0 -6
- package/dist/migrations/flags.js +0 -8
- package/dist/migrations/taskMigrations.d.ts +0 -71
- package/dist/migrations/taskMigrations.js +0 -236
- package/dist/migrations/taskMigrations.test.js +0 -34
- package/dist/server/routes.billing.js +0 -991
- package/dist/server/routes.billing.test.js +0 -387
- package/dist/server/routes.sync.integration.test.js +0 -470
- package/dist/server/routes.sync.js +0 -1141
- package/dist/soak/syncSoakHarness.d.ts +0 -6
- package/dist/soak/syncSoakHarness.js +0 -10
- package/dist/ui/assets/index-0W5vyCpn.css +0 -1
- package/dist/ui/assets/index-MCZuNNfn.js +0 -23
- package/dist/ui/assets/logo_white_01-0Vx-iIIv.png +0 -0
- package/dist/ui/assets/vendor-dnd-BI1K77C1.js +0 -5
- package/dist/ui/assets/vendor-react-DdIDsh7f.js +0 -9
- package/dist/ui/assets/vendor-router-BtiNU7Dl.js +0 -3
- package/dist/utils/taskHierarchy.d.ts +0 -4
- package/dist/utils/taskHierarchy.js +0 -69
- package/dist/utils/taskHierarchy.test.js +0 -38
- package/dist/utils/taskParenting.d.ts +0 -3
- package/dist/utils/taskParenting.js +0 -24
- package/dist/utils/taskParenting.test.js +0 -21
- package/dist/utils/taskRelations.d.ts +0 -6
- package/dist/utils/taskRelations.js +0 -24
- package/dist/utils/taskRelations.test.js +0 -34
- package/scripts/check-compat-boundaries.js +0 -48
- /package/dist/{__tests__/planParser.test.d.ts → TaskforceCore.filter-persistence.test.d.ts} +0 -0
- /package/dist/{__tests__/releaseVersion.test.d.ts → TaskforceCore.routing.test.d.ts} +0 -0
- /package/dist/{__tests__/structuredCommentValidation.test.d.ts → annotatedAttachments/AnnotatedAttachmentSessionStore.test.d.ts} +0 -0
- /package/dist/{__tests__/structuredDocValidation.test.d.ts → annotatedAttachments/payload.test.d.ts} +0 -0
- /package/dist/{__tests__/templateEngine.test.d.ts → annotatedAttachments/types.js} +0 -0
- /package/dist/{__tests__/templates.test.d.ts → compat/workspaceSyncCompat.test.d.ts} +0 -0
- /package/dist/{__tests__/workflowDocumentFixtures.test.d.ts → components/features/AgentsModule.test.d.ts} +0 -0
- /package/dist/{__tests__/workflowExportMatrix.test.d.ts → components/features/AnnotatedAttachmentWorkspace.test.d.ts} +0 -0
- /package/dist/{__tests__/workflowExportSnapshots.test.d.ts → components/features/DocumentWorkspace.test.d.ts} +0 -0
- /package/dist/{__tests__/workflowGeneration.test.d.ts → components/features/settings/TaxonomyLibraryManager.test.d.ts} +0 -0
- /package/dist/{__tests__/workflowV2Policy.test.d.ts → components/task/TaskActionHeader.test.d.ts} +0 -0
- /package/dist/{core/InitiativeTemplates.test.d.ts → components/task/TaskKanban.planning-drop.test.d.ts} +0 -0
- /package/dist/{core/ParentLifecycle.test.d.ts → components/task/TaskStatusActions.test.d.ts} +0 -0
- /package/dist/{migrations/taskMigrations.test.d.ts → components/ui/TopNoticeLayer.test.d.ts} +0 -0
- /package/dist/{server/routes.billing.test.d.ts → components/views/AppShellHeader.test.d.ts} +0 -0
- /package/dist/{server/routes.sync.integration.test.d.ts → components/views/PlanComparisonPage.test.d.ts} +0 -0
- /package/dist/{utils/taskHierarchy.test.d.ts → components/views/chrome/WorkspaceChromeSections.test.d.ts} +0 -0
- /package/dist/{utils/taskParenting.test.d.ts → components/views/chrome/workspaceChrome.test.d.ts} +0 -0
- /package/dist/{utils/taskRelations.test.d.ts → components/views/panels/DocumentFilterToolbar.test.d.ts} +0 -0
- /package/dist/public/{android-chrome-192x192.png → archive/phoenix/android-chrome-192x192.png} +0 -0
- /package/dist/public/{android-chrome-512x512.png → archive/phoenix/android-chrome-512x512.png} +0 -0
- /package/dist/public/{favicon-16x16.png → archive/phoenix/favicon-16x16.png} +0 -0
- /package/dist/public/{favicon-32x32.png → archive/phoenix/favicon-32x32.png} +0 -0
- /package/dist/public/{favicon.png → archive/phoenix/favicon.png} +0 -0
- /package/dist/{__tests__ → services}/workflowExportSnapshots.test.js +0 -0
- /package/dist/{__tests__ → services}/workflowGeneration.test.js +0 -0
- /package/dist/ui/favicon/{android-chrome-192x192.png → archive/phoenix/android-chrome-192x192.png} +0 -0
- /package/dist/ui/favicon/{android-chrome-512x512.png → archive/phoenix/android-chrome-512x512.png} +0 -0
- /package/dist/ui/favicon/{favicon-16x16.png → archive/phoenix/favicon-16x16.png} +0 -0
- /package/dist/ui/favicon/{favicon-32x32.png → archive/phoenix/favicon-32x32.png} +0 -0
- /package/dist/ui/favicon/{favicon.png → archive/phoenix/favicon.png} +0 -0
|
@@ -1,1141 +0,0 @@
|
|
|
1
|
-
import * as fs from 'fs';
|
|
2
|
-
import * as path from 'path';
|
|
3
|
-
import { createHash } from 'crypto';
|
|
4
|
-
import { parseJsonBody } from './routes.js';
|
|
5
|
-
import { normalizeTaskDataRelativePath } from '../storage/objectStorageClient.js';
|
|
6
|
-
import { resolveSessionCookieAttributesForRequest } from './auth.js';
|
|
7
|
-
function decodeWorkspaceSyncCursor(raw) {
|
|
8
|
-
const value = String(raw || '').trim();
|
|
9
|
-
if (!value)
|
|
10
|
-
return null;
|
|
11
|
-
try {
|
|
12
|
-
const json = Buffer.from(value, 'base64url').toString('utf8');
|
|
13
|
-
const parsed = JSON.parse(json);
|
|
14
|
-
const u = String(parsed?.u || '').trim();
|
|
15
|
-
const id = String(parsed?.id || '').trim();
|
|
16
|
-
if (!u || !id)
|
|
17
|
-
return null;
|
|
18
|
-
if (!Number.isFinite(Date.parse(u)))
|
|
19
|
-
return null;
|
|
20
|
-
return { u, id };
|
|
21
|
-
}
|
|
22
|
-
catch {
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
function encodeWorkspaceSyncCursor(cursor) {
|
|
27
|
-
if (!cursor)
|
|
28
|
-
return null;
|
|
29
|
-
return Buffer.from(JSON.stringify(cursor), 'utf8').toString('base64url');
|
|
30
|
-
}
|
|
31
|
-
export function registerSyncRoutes(deps) {
|
|
32
|
-
const { addRoute, core, context, auditAuthAction, resolveErrorStatusCode, requestWorkspaceId, resolveRequestAccess, isReservedWorkspaceId, createSessionTokenCookie } = deps;
|
|
33
|
-
const readPushIdempotency = (workspaceId, key) => {
|
|
34
|
-
if (typeof core.readPushIdempotency === 'function') {
|
|
35
|
-
return core.readPushIdempotency(workspaceId, key);
|
|
36
|
-
}
|
|
37
|
-
return null;
|
|
38
|
-
};
|
|
39
|
-
const writePushIdempotency = (workspaceId, key, payload) => {
|
|
40
|
-
if (typeof core.writePushIdempotency === 'function') {
|
|
41
|
-
core.writePushIdempotency(workspaceId, key, payload);
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
const recordSyncDiagnostic = (workspaceId, eventType, errorMessage, details) => {
|
|
45
|
-
try {
|
|
46
|
-
core.recordSyncEvent(workspaceId, {
|
|
47
|
-
eventType,
|
|
48
|
-
status: 'error',
|
|
49
|
-
errorMessage,
|
|
50
|
-
requestMs: 0
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
catch {
|
|
54
|
-
// diagnostics must never throw
|
|
55
|
-
}
|
|
56
|
-
if (details && Object.keys(details).length > 0) {
|
|
57
|
-
// eslint-disable-next-line no-console
|
|
58
|
-
console.warn('[Taskforce Sync Diagnostic]', { workspaceId, eventType, errorMessage, ...details });
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
const workspaceDocumentSnapshotCache = new Map();
|
|
62
|
-
const workspaceTaxonomySyncMeta = new Map();
|
|
63
|
-
const isMarkdownPath = (relativePath) => {
|
|
64
|
-
const lower = relativePath.toLowerCase();
|
|
65
|
-
return lower.endsWith('.md') || lower.endsWith('.markdown');
|
|
66
|
-
};
|
|
67
|
-
const normalizeWorkspaceSyncDocumentPath = (rawPath) => {
|
|
68
|
-
const value = String(rawPath || '').trim().replace(/\\/g, '/');
|
|
69
|
-
if (!value || value.includes('\0'))
|
|
70
|
-
return null;
|
|
71
|
-
if (value.startsWith('/'))
|
|
72
|
-
return null;
|
|
73
|
-
const normalized = path.posix.normalize(value);
|
|
74
|
-
if (!normalized || normalized.startsWith('../') || normalized.includes('/../') || normalized === '..')
|
|
75
|
-
return null;
|
|
76
|
-
if (!isMarkdownPath(normalized))
|
|
77
|
-
return null;
|
|
78
|
-
if (normalized.startsWith('docs/'))
|
|
79
|
-
return normalized;
|
|
80
|
-
const normalizedTaskData = normalizeTaskDataRelativePath(normalized);
|
|
81
|
-
if (!normalizedTaskData || !isMarkdownPath(normalizedTaskData))
|
|
82
|
-
return null;
|
|
83
|
-
return normalizedTaskData;
|
|
84
|
-
};
|
|
85
|
-
const listWorkspaceSyncDocumentsSnapshot = (basePath, workspaceId = 'default') => {
|
|
86
|
-
const collectFiles = (dirPath, baseRelative, out) => {
|
|
87
|
-
if (!fs.existsSync(dirPath))
|
|
88
|
-
return;
|
|
89
|
-
let entries = [];
|
|
90
|
-
try {
|
|
91
|
-
entries = fs.readdirSync(dirPath, { withFileTypes: true });
|
|
92
|
-
}
|
|
93
|
-
catch (error) {
|
|
94
|
-
recordSyncDiagnostic(workspaceId, 'pull', 'Failed to read sync document directory.', {
|
|
95
|
-
source: 'documents.collectFiles',
|
|
96
|
-
dirPath,
|
|
97
|
-
error: String(error?.message || error || '')
|
|
98
|
-
});
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
for (const entry of entries) {
|
|
102
|
-
if (!entry || typeof entry.name !== 'string')
|
|
103
|
-
continue;
|
|
104
|
-
const absPath = path.join(dirPath, entry.name);
|
|
105
|
-
const relPath = path.posix.join(baseRelative, entry.name);
|
|
106
|
-
if (entry.isDirectory()) {
|
|
107
|
-
collectFiles(absPath, relPath, out);
|
|
108
|
-
continue;
|
|
109
|
-
}
|
|
110
|
-
if (!entry.isFile())
|
|
111
|
-
continue;
|
|
112
|
-
if (!isMarkdownPath(relPath))
|
|
113
|
-
continue;
|
|
114
|
-
const normalized = normalizeWorkspaceSyncDocumentPath(relPath);
|
|
115
|
-
if (!normalized)
|
|
116
|
-
continue;
|
|
117
|
-
out.push(normalized);
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
const candidatePaths = [];
|
|
121
|
-
collectFiles(path.join(basePath, '.taskforce', 'docs'), 'docs', candidatePaths);
|
|
122
|
-
collectFiles(path.join(basePath, '.taskforce', 'task-data'), 'task-data', candidatePaths);
|
|
123
|
-
const uniquePaths = Array.from(new Set(candidatePaths)).sort((a, b) => a.localeCompare(b));
|
|
124
|
-
const workspaceCache = workspaceDocumentSnapshotCache.get(workspaceId) || new Map();
|
|
125
|
-
workspaceDocumentSnapshotCache.set(workspaceId, workspaceCache);
|
|
126
|
-
const remainingPaths = new Set(uniquePaths);
|
|
127
|
-
const docs = [];
|
|
128
|
-
for (const relativePath of uniquePaths) {
|
|
129
|
-
const absPath = path.resolve(path.join(basePath, '.taskforce'), relativePath);
|
|
130
|
-
const safeRoot = path.resolve(path.join(basePath, '.taskforce'));
|
|
131
|
-
if (absPath !== safeRoot && !absPath.startsWith(`${safeRoot}${path.sep}`))
|
|
132
|
-
continue;
|
|
133
|
-
try {
|
|
134
|
-
const stat = fs.statSync(absPath);
|
|
135
|
-
if (!stat.isFile())
|
|
136
|
-
continue;
|
|
137
|
-
const cached = workspaceCache.get(relativePath);
|
|
138
|
-
if (cached
|
|
139
|
-
&& cached.size === stat.size
|
|
140
|
-
&& cached.mtimeMs === stat.mtimeMs
|
|
141
|
-
&& cached.ctimeMs === stat.ctimeMs) {
|
|
142
|
-
docs.push({
|
|
143
|
-
path: relativePath,
|
|
144
|
-
updatedAt: cached.updatedAt,
|
|
145
|
-
content: cached.content
|
|
146
|
-
});
|
|
147
|
-
continue;
|
|
148
|
-
}
|
|
149
|
-
const content = fs.readFileSync(absPath, 'utf8');
|
|
150
|
-
// Hash the content so we can detect real changes regardless of mtime.
|
|
151
|
-
const contentHash = createHash('sha256').update(content).digest('hex');
|
|
152
|
-
const existing = core.getDocumentWatermark?.(workspaceId, relativePath);
|
|
153
|
-
let updatedAt;
|
|
154
|
-
if (existing && existing.contentHash === contentHash) {
|
|
155
|
-
// Content unchanged — use the stable stored timestamp.
|
|
156
|
-
updatedAt = existing.updatedAt;
|
|
157
|
-
}
|
|
158
|
-
else {
|
|
159
|
-
// New or changed content — seed from mtime, then persist.
|
|
160
|
-
updatedAt = Number.isFinite(stat.mtimeMs)
|
|
161
|
-
? new Date(stat.mtimeMs).toISOString()
|
|
162
|
-
: new Date().toISOString();
|
|
163
|
-
try {
|
|
164
|
-
core.upsertDocumentWatermark?.(workspaceId, relativePath, contentHash, updatedAt);
|
|
165
|
-
}
|
|
166
|
-
catch (error) {
|
|
167
|
-
recordSyncDiagnostic(workspaceId, 'pull', 'Failed to persist document watermark during snapshot.', {
|
|
168
|
-
source: 'documents.snapshot.upsertWatermark',
|
|
169
|
-
path: relativePath,
|
|
170
|
-
error: String(error?.message || error || '')
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
docs.push({
|
|
175
|
-
path: relativePath,
|
|
176
|
-
updatedAt,
|
|
177
|
-
content
|
|
178
|
-
});
|
|
179
|
-
workspaceCache.set(relativePath, {
|
|
180
|
-
path: relativePath,
|
|
181
|
-
mtimeMs: stat.mtimeMs,
|
|
182
|
-
ctimeMs: stat.ctimeMs,
|
|
183
|
-
size: stat.size,
|
|
184
|
-
updatedAt,
|
|
185
|
-
content
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
catch (error) {
|
|
189
|
-
recordSyncDiagnostic(workspaceId, 'pull', 'Failed to read sync document snapshot entry.', {
|
|
190
|
-
source: 'documents.snapshot.readEntry',
|
|
191
|
-
path: relativePath,
|
|
192
|
-
error: String(error?.message || error || '')
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
for (const cachedPath of Array.from(workspaceCache.keys())) {
|
|
197
|
-
if (!remainingPaths.has(cachedPath))
|
|
198
|
-
workspaceCache.delete(cachedPath);
|
|
199
|
-
}
|
|
200
|
-
return docs;
|
|
201
|
-
};
|
|
202
|
-
const writeWorkspaceSyncDocument = (basePath, doc, workspaceId = 'default') => {
|
|
203
|
-
const normalizedPath = normalizeWorkspaceSyncDocumentPath(doc.path);
|
|
204
|
-
if (!normalizedPath)
|
|
205
|
-
return;
|
|
206
|
-
const root = path.resolve(path.join(basePath, '.taskforce'));
|
|
207
|
-
const targetPath = path.resolve(root, normalizedPath);
|
|
208
|
-
if (targetPath !== root && !targetPath.startsWith(`${root}${path.sep}`))
|
|
209
|
-
return;
|
|
210
|
-
fs.mkdirSync(path.dirname(targetPath), { recursive: true });
|
|
211
|
-
const content = String(doc.content || '');
|
|
212
|
-
fs.writeFileSync(targetPath, content, 'utf8');
|
|
213
|
-
const updatedAt = String(doc.updatedAt || '').trim();
|
|
214
|
-
const watermarkMs = Date.parse(updatedAt);
|
|
215
|
-
if (Number.isFinite(watermarkMs) && watermarkMs > 0) {
|
|
216
|
-
const when = new Date(watermarkMs);
|
|
217
|
-
fs.utimesSync(targetPath, when, when);
|
|
218
|
-
}
|
|
219
|
-
// Persist content hash + timestamp to SQLite so the snapshot function uses a
|
|
220
|
-
// stable watermark instead of relying on non-deterministic filesystem mtime.
|
|
221
|
-
try {
|
|
222
|
-
const contentHash = createHash('sha256').update(content).digest('hex');
|
|
223
|
-
core.upsertDocumentWatermark?.(workspaceId, normalizedPath, contentHash, updatedAt || new Date().toISOString());
|
|
224
|
-
}
|
|
225
|
-
catch (error) {
|
|
226
|
-
recordSyncDiagnostic(workspaceId, 'apply', 'Failed to persist document watermark after write.', {
|
|
227
|
-
source: 'documents.write.upsertWatermark',
|
|
228
|
-
path: normalizedPath,
|
|
229
|
-
error: String(error?.message || error || '')
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
workspaceDocumentSnapshotCache.get(workspaceId)?.delete(normalizedPath);
|
|
233
|
-
};
|
|
234
|
-
const deleteWorkspaceSyncDocument = (basePath, docPath, workspaceId = 'default') => {
|
|
235
|
-
const normalizedPath = normalizeWorkspaceSyncDocumentPath(docPath);
|
|
236
|
-
if (!normalizedPath)
|
|
237
|
-
return;
|
|
238
|
-
const root = path.resolve(path.join(basePath, '.taskforce'));
|
|
239
|
-
const targetPath = path.resolve(root, normalizedPath);
|
|
240
|
-
if (targetPath !== root && !targetPath.startsWith(`${root}${path.sep}`))
|
|
241
|
-
return;
|
|
242
|
-
try {
|
|
243
|
-
if (fs.existsSync(targetPath))
|
|
244
|
-
fs.unlinkSync(targetPath);
|
|
245
|
-
}
|
|
246
|
-
catch (error) {
|
|
247
|
-
recordSyncDiagnostic(workspaceId, 'apply', 'Failed to delete workspace sync document.', {
|
|
248
|
-
source: 'documents.delete.file',
|
|
249
|
-
path: normalizedPath,
|
|
250
|
-
error: String(error?.message || error || '')
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
try {
|
|
254
|
-
core.deleteDocumentWatermark?.(workspaceId, normalizedPath);
|
|
255
|
-
}
|
|
256
|
-
catch (error) {
|
|
257
|
-
recordSyncDiagnostic(workspaceId, 'apply', 'Failed to delete document watermark.', {
|
|
258
|
-
source: 'documents.delete.watermark',
|
|
259
|
-
path: normalizedPath,
|
|
260
|
-
error: String(error?.message || error || '')
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
workspaceDocumentSnapshotCache.get(workspaceId)?.delete(normalizedPath);
|
|
264
|
-
};
|
|
265
|
-
const resolveConflictOrdering = (incomingWatermark, existingWatermark, incomingTieBreak, existingTieBreak) => {
|
|
266
|
-
const incomingMs = Date.parse(String(incomingWatermark || '').trim());
|
|
267
|
-
const existingMs = Date.parse(String(existingWatermark || '').trim());
|
|
268
|
-
const incomingHasWatermark = Number.isFinite(incomingMs);
|
|
269
|
-
const existingHasWatermark = Number.isFinite(existingMs);
|
|
270
|
-
if (incomingHasWatermark && existingHasWatermark) {
|
|
271
|
-
if (incomingMs > existingMs)
|
|
272
|
-
return 1;
|
|
273
|
-
if (incomingMs < existingMs)
|
|
274
|
-
return -1;
|
|
275
|
-
}
|
|
276
|
-
else if (incomingHasWatermark && !existingHasWatermark) {
|
|
277
|
-
return 1;
|
|
278
|
-
}
|
|
279
|
-
else if (!incomingHasWatermark && existingHasWatermark) {
|
|
280
|
-
return -1;
|
|
281
|
-
}
|
|
282
|
-
return incomingTieBreak.localeCompare(existingTieBreak);
|
|
283
|
-
};
|
|
284
|
-
const dispatchWorkspaceSyncChanges = (workspaceId, incomingChanges) => {
|
|
285
|
-
const tasks = [];
|
|
286
|
-
const archived = [];
|
|
287
|
-
const deleteTaskIds = new Set();
|
|
288
|
-
const emittedEventIds = new Set();
|
|
289
|
-
const unsubscribeRealtime = typeof core.onRealtimeMutation === 'function'
|
|
290
|
-
? core.onRealtimeMutation((event) => {
|
|
291
|
-
const eventWorkspaceId = String(event?.workspaceId || '').trim();
|
|
292
|
-
if (eventWorkspaceId !== workspaceId)
|
|
293
|
-
return;
|
|
294
|
-
const eventId = String(event?.eventId || '').trim();
|
|
295
|
-
if (eventId)
|
|
296
|
-
emittedEventIds.add(eventId);
|
|
297
|
-
})
|
|
298
|
-
: () => { };
|
|
299
|
-
let incomingTaxonomies = null;
|
|
300
|
-
let incomingTaxonomiesUpdatedAt = '';
|
|
301
|
-
const incomingDocuments = [];
|
|
302
|
-
const incomingDocumentDeletes = new Set();
|
|
303
|
-
try {
|
|
304
|
-
for (const change of incomingChanges) {
|
|
305
|
-
const raw = change;
|
|
306
|
-
const op = String(raw.op || '').trim().toLowerCase();
|
|
307
|
-
if (op === 'taxonomy-upsert') {
|
|
308
|
-
if (Array.isArray(raw.taxonomies)) {
|
|
309
|
-
incomingTaxonomies = raw.taxonomies;
|
|
310
|
-
incomingTaxonomiesUpdatedAt = String(raw.updatedAt || raw.watermark || '').trim();
|
|
311
|
-
}
|
|
312
|
-
continue;
|
|
313
|
-
}
|
|
314
|
-
if (op === 'document-upsert') {
|
|
315
|
-
const normalizedPath = normalizeWorkspaceSyncDocumentPath(raw.path);
|
|
316
|
-
if (normalizedPath) {
|
|
317
|
-
incomingDocuments.push({
|
|
318
|
-
path: normalizedPath,
|
|
319
|
-
updatedAt: String(raw.updatedAt || raw.watermark || '').trim(),
|
|
320
|
-
content: typeof raw.content === 'string' ? raw.content : ''
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
continue;
|
|
324
|
-
}
|
|
325
|
-
if (op === 'document-delete') {
|
|
326
|
-
const normalizedPath = normalizeWorkspaceSyncDocumentPath(raw.path);
|
|
327
|
-
if (normalizedPath)
|
|
328
|
-
incomingDocumentDeletes.add(normalizedPath);
|
|
329
|
-
continue;
|
|
330
|
-
}
|
|
331
|
-
if (op !== 'delete')
|
|
332
|
-
continue;
|
|
333
|
-
const task = raw.task;
|
|
334
|
-
const deleteTaskId = String(raw.taskId || raw.id || task?.id || '').trim();
|
|
335
|
-
if (deleteTaskId)
|
|
336
|
-
deleteTaskIds.add(deleteTaskId);
|
|
337
|
-
}
|
|
338
|
-
for (const change of incomingChanges) {
|
|
339
|
-
const raw = change;
|
|
340
|
-
const op = String(raw.op || '').trim().toLowerCase();
|
|
341
|
-
if (op === 'delete' || op === 'document-upsert' || op === 'document-delete')
|
|
342
|
-
continue;
|
|
343
|
-
const task = raw.task && typeof raw.task === 'object' ? raw.task : null;
|
|
344
|
-
if (!task)
|
|
345
|
-
continue;
|
|
346
|
-
const taskId = String(task.id || '').trim();
|
|
347
|
-
if (taskId && deleteTaskIds.has(taskId))
|
|
348
|
-
continue;
|
|
349
|
-
const markedArchived = raw.archived === true || task?.isArchived === true;
|
|
350
|
-
if (markedArchived)
|
|
351
|
-
archived.push(task);
|
|
352
|
-
else
|
|
353
|
-
tasks.push(task);
|
|
354
|
-
}
|
|
355
|
-
for (const taskId of deleteTaskIds) {
|
|
356
|
-
try {
|
|
357
|
-
if (typeof core.deleteTaskForSync === 'function') {
|
|
358
|
-
core.deleteTaskForSync(taskId, workspaceId, { persistBackup: false });
|
|
359
|
-
}
|
|
360
|
-
else {
|
|
361
|
-
core.deleteTask(taskId, workspaceId, { persistBackup: false });
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
catch (error) {
|
|
365
|
-
recordSyncDiagnostic(workspaceId, 'apply', 'Failed to delete task during sync apply.', {
|
|
366
|
-
source: 'apply.deleteTask',
|
|
367
|
-
taskId,
|
|
368
|
-
error: String(error?.message || error || '')
|
|
369
|
-
});
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
if (Array.isArray(incomingTaxonomies)) {
|
|
373
|
-
if (!incomingTaxonomiesUpdatedAt) {
|
|
374
|
-
core.updateTaxonomies(incomingTaxonomies);
|
|
375
|
-
const fallbackHash = createHash('sha256').update(JSON.stringify(incomingTaxonomies)).digest('hex');
|
|
376
|
-
workspaceTaxonomySyncMeta.set(workspaceId, {
|
|
377
|
-
updatedAt: new Date().toISOString(),
|
|
378
|
-
hash: fallbackHash
|
|
379
|
-
});
|
|
380
|
-
}
|
|
381
|
-
else {
|
|
382
|
-
const incomingTaxonomyHash = createHash('sha256').update(JSON.stringify(incomingTaxonomies)).digest('hex');
|
|
383
|
-
const currentMeta = workspaceTaxonomySyncMeta.get(workspaceId) || { updatedAt: '', hash: '' };
|
|
384
|
-
const compare = resolveConflictOrdering(incomingTaxonomiesUpdatedAt, currentMeta.updatedAt, incomingTaxonomyHash, currentMeta.hash);
|
|
385
|
-
if (compare >= 0) {
|
|
386
|
-
core.updateTaxonomies(incomingTaxonomies);
|
|
387
|
-
workspaceTaxonomySyncMeta.set(workspaceId, {
|
|
388
|
-
updatedAt: incomingTaxonomiesUpdatedAt,
|
|
389
|
-
hash: incomingTaxonomyHash
|
|
390
|
-
});
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
if (incomingDocuments.length > 0) {
|
|
395
|
-
for (const doc of incomingDocuments) {
|
|
396
|
-
const existingDoc = core.getDocumentWatermark?.(workspaceId, doc.path);
|
|
397
|
-
const incomingHash = createHash('sha256').update(String(doc.content || '')).digest('hex');
|
|
398
|
-
const existingUpdatedAt = String(existingDoc?.updatedAt || '').trim();
|
|
399
|
-
const existingHash = String(existingDoc?.contentHash || '').trim();
|
|
400
|
-
const compare = resolveConflictOrdering(doc.updatedAt, existingUpdatedAt, incomingHash, existingHash);
|
|
401
|
-
if (compare < 0)
|
|
402
|
-
continue;
|
|
403
|
-
if (compare === 0 && existingHash === incomingHash)
|
|
404
|
-
continue;
|
|
405
|
-
writeWorkspaceSyncDocument(core.getPaths().basePath, doc, workspaceId);
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
if (incomingDocumentDeletes.size > 0) {
|
|
409
|
-
for (const docPath of incomingDocumentDeletes) {
|
|
410
|
-
deleteWorkspaceSyncDocument(core.getPaths().basePath, docPath, workspaceId);
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
const result = core.applyWorkspaceSyncSnapshot({ tasks, archived }, workspaceId);
|
|
414
|
-
return { result, deleteCount: deleteTaskIds.size, emittedEventIds: Array.from(emittedEventIds) };
|
|
415
|
-
}
|
|
416
|
-
finally {
|
|
417
|
-
unsubscribeRealtime();
|
|
418
|
-
}
|
|
419
|
-
};
|
|
420
|
-
// GET /api/taskforce/sync/user-settings - Pull user-global sync payload for authenticated user
|
|
421
|
-
addRoute('GET', '/api/taskforce/sync/user-settings', async (req, res) => {
|
|
422
|
-
const authConfig = context.authConfig;
|
|
423
|
-
if (!authConfig || !authConfig.enabled) {
|
|
424
|
-
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
425
|
-
res.end(JSON.stringify({ success: false, error: 'Sync is unavailable when auth is disabled.' }));
|
|
426
|
-
return;
|
|
427
|
-
}
|
|
428
|
-
const access = resolveRequestAccess(req, authConfig);
|
|
429
|
-
if (!access.authenticated || !access.userId || access.userId === 'anonymous') {
|
|
430
|
-
res.writeHead(401, { 'Content-Type': 'application/json' });
|
|
431
|
-
res.end(JSON.stringify({ success: false, error: 'Authentication required.' }));
|
|
432
|
-
return;
|
|
433
|
-
}
|
|
434
|
-
const snapshot = core.getUserGlobalSyncSettings(access.userId);
|
|
435
|
-
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
436
|
-
res.end(JSON.stringify({
|
|
437
|
-
success: true,
|
|
438
|
-
settings: snapshot.settings,
|
|
439
|
-
updatedAt: snapshot.updatedAt
|
|
440
|
-
}));
|
|
441
|
-
});
|
|
442
|
-
// POST /api/taskforce/sync/user-settings - Push user-global sync payload for authenticated user
|
|
443
|
-
addRoute('POST', '/api/taskforce/sync/user-settings', async (req, res) => {
|
|
444
|
-
const authConfig = context.authConfig;
|
|
445
|
-
if (!authConfig || !authConfig.enabled) {
|
|
446
|
-
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
447
|
-
res.end(JSON.stringify({ success: false, error: 'Sync is unavailable when auth is disabled.' }));
|
|
448
|
-
return;
|
|
449
|
-
}
|
|
450
|
-
const access = resolveRequestAccess(req, authConfig);
|
|
451
|
-
if (!access.authenticated || !access.userId || access.userId === 'anonymous') {
|
|
452
|
-
res.writeHead(401, { 'Content-Type': 'application/json' });
|
|
453
|
-
res.end(JSON.stringify({ success: false, error: 'Authentication required.' }));
|
|
454
|
-
return;
|
|
455
|
-
}
|
|
456
|
-
const body = await parseJsonBody(req);
|
|
457
|
-
const incomingSettings = body?.settings;
|
|
458
|
-
const incomingUpdatedAt = typeof body?.updatedAt === 'string' ? body.updatedAt : undefined;
|
|
459
|
-
const result = core.upsertUserGlobalSyncSettings(access.userId, incomingSettings, incomingUpdatedAt);
|
|
460
|
-
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
461
|
-
res.end(JSON.stringify({
|
|
462
|
-
success: true,
|
|
463
|
-
settings: result.settings,
|
|
464
|
-
updatedAt: result.updatedAt,
|
|
465
|
-
applied: result.applied
|
|
466
|
-
}));
|
|
467
|
-
});
|
|
468
|
-
// POST /api/taskforce/sync/workspace/handshake - Enforce workspace-id match before workspace sync
|
|
469
|
-
addRoute('POST', '/api/taskforce/sync/workspace/handshake', async (req, res) => {
|
|
470
|
-
const authConfig = context.authConfig;
|
|
471
|
-
if (!authConfig || !authConfig.enabled) {
|
|
472
|
-
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
473
|
-
res.end(JSON.stringify({ success: false, error: 'Sync is unavailable when auth is disabled.' }));
|
|
474
|
-
return;
|
|
475
|
-
}
|
|
476
|
-
const access = resolveRequestAccess(req, authConfig);
|
|
477
|
-
if (!access.authenticated || !access.userId || access.userId === 'anonymous') {
|
|
478
|
-
auditAuthAction(req, 'sync-workspace-handshake-unauthorized', {});
|
|
479
|
-
res.writeHead(401, { 'Content-Type': 'application/json' });
|
|
480
|
-
res.end(JSON.stringify({ success: false, error: 'Authentication required.' }));
|
|
481
|
-
return;
|
|
482
|
-
}
|
|
483
|
-
const body = await parseJsonBody(req);
|
|
484
|
-
const localWorkspaceId = String(body?.workspaceId || '').trim();
|
|
485
|
-
if (!localWorkspaceId) {
|
|
486
|
-
auditAuthAction(req, 'sync-workspace-handshake-invalid', { code: 'WORKSPACE_ID_REQUIRED' });
|
|
487
|
-
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
488
|
-
res.end(JSON.stringify({ success: false, error: 'workspaceId is required.' }));
|
|
489
|
-
return;
|
|
490
|
-
}
|
|
491
|
-
const cloudWorkspaceId = String(access.workspaceId || '').trim();
|
|
492
|
-
if (!cloudWorkspaceId) {
|
|
493
|
-
auditAuthAction(req, 'sync-workspace-handshake-missing-cloud-workspace', { code: 'WORKSPACE_ID_REQUIRED' });
|
|
494
|
-
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
495
|
-
res.end(JSON.stringify({
|
|
496
|
-
success: false,
|
|
497
|
-
error: 'No cloud workspace is selected. Complete workspace setup first.',
|
|
498
|
-
code: 'WORKSPACE_ID_REQUIRED'
|
|
499
|
-
}));
|
|
500
|
-
return;
|
|
501
|
-
}
|
|
502
|
-
if (localWorkspaceId !== cloudWorkspaceId) {
|
|
503
|
-
auditAuthAction(req, 'sync-workspace-handshake-mismatch', {
|
|
504
|
-
localWorkspaceId,
|
|
505
|
-
cloudWorkspaceId
|
|
506
|
-
});
|
|
507
|
-
res.writeHead(409, { 'Content-Type': 'application/json' });
|
|
508
|
-
res.end(JSON.stringify({
|
|
509
|
-
success: false,
|
|
510
|
-
error: 'Workspace mismatch. Sync requires matching local and cloud workspace IDs.',
|
|
511
|
-
code: 'WORKSPACE_ID_MISMATCH',
|
|
512
|
-
localWorkspaceId,
|
|
513
|
-
cloudWorkspaceId
|
|
514
|
-
}));
|
|
515
|
-
return;
|
|
516
|
-
}
|
|
517
|
-
auditAuthAction(req, 'sync-workspace-handshake-success', { workspaceId: localWorkspaceId });
|
|
518
|
-
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
519
|
-
res.end(JSON.stringify({
|
|
520
|
-
success: true,
|
|
521
|
-
localWorkspaceId,
|
|
522
|
-
cloudWorkspaceId
|
|
523
|
-
}));
|
|
524
|
-
});
|
|
525
|
-
// POST /api/taskforce/sync/workspace/provision - Switch to existing cloud workspace that matches local workspace id
|
|
526
|
-
addRoute('POST', '/api/taskforce/sync/workspace/provision', async (req, res) => {
|
|
527
|
-
const authConfig = context.authConfig;
|
|
528
|
-
if (!authConfig || !authConfig.enabled) {
|
|
529
|
-
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
530
|
-
res.end(JSON.stringify({ success: false, error: 'Sync is unavailable when auth is disabled.' }));
|
|
531
|
-
return;
|
|
532
|
-
}
|
|
533
|
-
const access = resolveRequestAccess(req, authConfig);
|
|
534
|
-
if (!access.authenticated || !access.sessionId || !access.userId || access.userId === 'anonymous') {
|
|
535
|
-
res.writeHead(401, { 'Content-Type': 'application/json' });
|
|
536
|
-
res.end(JSON.stringify({ success: false, error: 'Authentication required.' }));
|
|
537
|
-
return;
|
|
538
|
-
}
|
|
539
|
-
const body = await parseJsonBody(req);
|
|
540
|
-
const requestedWorkspaceId = String(body?.workspaceId || '').trim();
|
|
541
|
-
const requestedWorkspaceName = String(body?.name || requestedWorkspaceId || '').trim();
|
|
542
|
-
const requestedWorkspaceDescription = typeof body?.description === 'string' ? body.description : undefined;
|
|
543
|
-
if (!requestedWorkspaceId) {
|
|
544
|
-
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
545
|
-
res.end(JSON.stringify({ success: false, error: 'workspaceId is required.' }));
|
|
546
|
-
return;
|
|
547
|
-
}
|
|
548
|
-
if (isReservedWorkspaceId(requestedWorkspaceId)) {
|
|
549
|
-
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
550
|
-
res.end(JSON.stringify({
|
|
551
|
-
success: false,
|
|
552
|
-
error: 'workspaceId "default" is reserved.',
|
|
553
|
-
code: 'WORKSPACE_ID_RESERVED'
|
|
554
|
-
}));
|
|
555
|
-
return;
|
|
556
|
-
}
|
|
557
|
-
if (!requestedWorkspaceName) {
|
|
558
|
-
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
559
|
-
res.end(JSON.stringify({ success: false, error: 'name is required.' }));
|
|
560
|
-
return;
|
|
561
|
-
}
|
|
562
|
-
const existing = core.listUserWorkspaces(access.userId).find((workspace) => workspace.id === requestedWorkspaceId);
|
|
563
|
-
if (existing) {
|
|
564
|
-
const cookie = createSessionTokenCookie(access.sessionId, authConfig, {
|
|
565
|
-
role: existing.role,
|
|
566
|
-
workspaceId: existing.id,
|
|
567
|
-
userId: access.userId,
|
|
568
|
-
...resolveSessionCookieAttributesForRequest(req, authConfig)
|
|
569
|
-
});
|
|
570
|
-
res.setHeader('Set-Cookie', cookie);
|
|
571
|
-
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
572
|
-
res.end(JSON.stringify({
|
|
573
|
-
success: true,
|
|
574
|
-
workspace: existing,
|
|
575
|
-
existing: true
|
|
576
|
-
}));
|
|
577
|
-
return;
|
|
578
|
-
}
|
|
579
|
-
try {
|
|
580
|
-
const created = core.createWorkspaceForUser({
|
|
581
|
-
userId: access.userId,
|
|
582
|
-
name: requestedWorkspaceName,
|
|
583
|
-
description: requestedWorkspaceDescription,
|
|
584
|
-
role: 'owner',
|
|
585
|
-
preferredWorkspaceId: requestedWorkspaceId
|
|
586
|
-
});
|
|
587
|
-
const cookie = createSessionTokenCookie(access.sessionId, authConfig, {
|
|
588
|
-
role: created.role,
|
|
589
|
-
workspaceId: created.id,
|
|
590
|
-
userId: access.userId,
|
|
591
|
-
...resolveSessionCookieAttributesForRequest(req, authConfig)
|
|
592
|
-
});
|
|
593
|
-
res.setHeader('Set-Cookie', cookie);
|
|
594
|
-
auditAuthAction(req, 'sync-workspace-provision-created', {
|
|
595
|
-
workspaceId: created.id,
|
|
596
|
-
workspaceName: created.name
|
|
597
|
-
});
|
|
598
|
-
res.writeHead(201, { 'Content-Type': 'application/json' });
|
|
599
|
-
res.end(JSON.stringify({
|
|
600
|
-
success: true,
|
|
601
|
-
workspace: created,
|
|
602
|
-
existing: false
|
|
603
|
-
}));
|
|
604
|
-
return;
|
|
605
|
-
}
|
|
606
|
-
catch (error) {
|
|
607
|
-
res.writeHead(resolveErrorStatusCode(error, 400), { 'Content-Type': 'application/json' });
|
|
608
|
-
res.end(JSON.stringify({
|
|
609
|
-
success: false,
|
|
610
|
-
error: String(error?.message || 'Unable to provision workspace for sync.'),
|
|
611
|
-
code: error?.code
|
|
612
|
-
}));
|
|
613
|
-
return;
|
|
614
|
-
}
|
|
615
|
-
});
|
|
616
|
-
// POST /api/taskforce/sync/workspace/bootstrap-push - Initial local snapshot push into authenticated cloud workspace
|
|
617
|
-
addRoute('POST', '/api/taskforce/sync/workspace/bootstrap-push', async (req, res) => {
|
|
618
|
-
const authConfig = context.authConfig;
|
|
619
|
-
if (!authConfig || !authConfig.enabled) {
|
|
620
|
-
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
621
|
-
res.end(JSON.stringify({ success: false, error: 'Sync is unavailable when auth is disabled.' }));
|
|
622
|
-
return;
|
|
623
|
-
}
|
|
624
|
-
const access = resolveRequestAccess(req, authConfig);
|
|
625
|
-
if (!access.authenticated || !access.userId || access.userId === 'anonymous') {
|
|
626
|
-
auditAuthAction(req, 'sync-workspace-bootstrap-unauthorized', {});
|
|
627
|
-
res.writeHead(401, { 'Content-Type': 'application/json' });
|
|
628
|
-
res.end(JSON.stringify({ success: false, error: 'Authentication required.' }));
|
|
629
|
-
return;
|
|
630
|
-
}
|
|
631
|
-
const body = await parseJsonBody(req);
|
|
632
|
-
const requestedWorkspaceId = String(body?.workspaceId || '').trim();
|
|
633
|
-
const cloudWorkspaceId = String(access.workspaceId || '').trim();
|
|
634
|
-
if (!requestedWorkspaceId) {
|
|
635
|
-
auditAuthAction(req, 'sync-workspace-bootstrap-invalid', { code: 'WORKSPACE_ID_REQUIRED' });
|
|
636
|
-
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
637
|
-
res.end(JSON.stringify({ success: false, error: 'workspaceId is required.', code: 'WORKSPACE_ID_REQUIRED' }));
|
|
638
|
-
return;
|
|
639
|
-
}
|
|
640
|
-
if (!cloudWorkspaceId) {
|
|
641
|
-
auditAuthAction(req, 'sync-workspace-bootstrap-missing-workspace', { code: 'WORKSPACE_ID_REQUIRED' });
|
|
642
|
-
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
643
|
-
res.end(JSON.stringify({
|
|
644
|
-
success: false,
|
|
645
|
-
error: 'No workspace selected. Create or select a workspace first.',
|
|
646
|
-
code: 'WORKSPACE_ID_REQUIRED'
|
|
647
|
-
}));
|
|
648
|
-
return;
|
|
649
|
-
}
|
|
650
|
-
if (requestedWorkspaceId !== cloudWorkspaceId) {
|
|
651
|
-
auditAuthAction(req, 'sync-workspace-bootstrap-mismatch', {
|
|
652
|
-
requestedWorkspaceId,
|
|
653
|
-
cloudWorkspaceId
|
|
654
|
-
});
|
|
655
|
-
res.writeHead(409, { 'Content-Type': 'application/json' });
|
|
656
|
-
res.end(JSON.stringify({
|
|
657
|
-
success: false,
|
|
658
|
-
error: 'Workspace mismatch. Sync requires matching local and cloud workspace IDs.',
|
|
659
|
-
code: 'WORKSPACE_ID_MISMATCH',
|
|
660
|
-
localWorkspaceId: requestedWorkspaceId,
|
|
661
|
-
cloudWorkspaceId
|
|
662
|
-
}));
|
|
663
|
-
return;
|
|
664
|
-
}
|
|
665
|
-
const tasks = Array.isArray(body?.tasks) ? body.tasks : [];
|
|
666
|
-
const archived = Array.isArray(body?.archived) ? body.archived : [];
|
|
667
|
-
const incomingTaxonomies = Array.isArray(body?.taxonomies) ? body.taxonomies : null;
|
|
668
|
-
const incomingDocuments = Array.isArray(body?.documents) ? body.documents : [];
|
|
669
|
-
try {
|
|
670
|
-
if (incomingTaxonomies) {
|
|
671
|
-
core.updateTaxonomies(incomingTaxonomies);
|
|
672
|
-
}
|
|
673
|
-
for (const doc of incomingDocuments) {
|
|
674
|
-
const docEntry = {
|
|
675
|
-
path: String(doc?.path || '').trim(),
|
|
676
|
-
updatedAt: String(doc?.updatedAt || '').trim(),
|
|
677
|
-
content: typeof doc?.content === 'string' ? doc.content : ''
|
|
678
|
-
};
|
|
679
|
-
if (docEntry.path) {
|
|
680
|
-
writeWorkspaceSyncDocument(core.getPaths().basePath, docEntry, cloudWorkspaceId);
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
const result = core.applyWorkspaceSyncSnapshot({
|
|
684
|
-
tasks,
|
|
685
|
-
archived
|
|
686
|
-
}, cloudWorkspaceId);
|
|
687
|
-
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
688
|
-
res.end(JSON.stringify({
|
|
689
|
-
success: true,
|
|
690
|
-
workspaceId: cloudWorkspaceId,
|
|
691
|
-
result
|
|
692
|
-
}));
|
|
693
|
-
auditAuthAction(req, 'sync-workspace-bootstrap-success', {
|
|
694
|
-
workspaceId: cloudWorkspaceId,
|
|
695
|
-
taskCount: tasks.length,
|
|
696
|
-
archivedCount: archived.length,
|
|
697
|
-
taxonomyCount: incomingTaxonomies?.length ?? 0,
|
|
698
|
-
documentCount: incomingDocuments.length
|
|
699
|
-
});
|
|
700
|
-
}
|
|
701
|
-
catch (error) {
|
|
702
|
-
const statusCode = resolveErrorStatusCode(error, 400);
|
|
703
|
-
auditAuthAction(req, 'sync-workspace-bootstrap-failed', {
|
|
704
|
-
workspaceId: cloudWorkspaceId,
|
|
705
|
-
code: error?.code || null,
|
|
706
|
-
statusCode
|
|
707
|
-
});
|
|
708
|
-
res.writeHead(statusCode, { 'Content-Type': 'application/json' });
|
|
709
|
-
res.end(JSON.stringify({
|
|
710
|
-
success: false,
|
|
711
|
-
error: String(error?.message || 'Failed to apply workspace snapshot'),
|
|
712
|
-
code: error?.code
|
|
713
|
-
}));
|
|
714
|
-
}
|
|
715
|
-
});
|
|
716
|
-
// GET /api/taskforce/sync/workspace/documents - Snapshot markdown documents for workspace sync payload/signature
|
|
717
|
-
addRoute('GET', '/api/taskforce/sync/workspace/documents', async (req, res) => {
|
|
718
|
-
const authConfig = context.authConfig;
|
|
719
|
-
if (authConfig?.runtimeMode === 'cloud') {
|
|
720
|
-
const access = resolveRequestAccess(req, authConfig);
|
|
721
|
-
if (!access.authenticated || !access.userId || access.userId === 'anonymous') {
|
|
722
|
-
res.writeHead(401, { 'Content-Type': 'application/json' });
|
|
723
|
-
res.end(JSON.stringify({ success: false, error: 'Authentication required.' }));
|
|
724
|
-
return;
|
|
725
|
-
}
|
|
726
|
-
}
|
|
727
|
-
const basePath = core.getPaths().basePath;
|
|
728
|
-
const documents = listWorkspaceSyncDocumentsSnapshot(basePath, 'default');
|
|
729
|
-
const fingerprint = JSON.stringify(documents.map((doc) => `${doc.path}:${doc.updatedAt}:${doc.content.length}`));
|
|
730
|
-
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
731
|
-
res.end(JSON.stringify({
|
|
732
|
-
success: true,
|
|
733
|
-
documents,
|
|
734
|
-
fingerprint
|
|
735
|
-
}));
|
|
736
|
-
});
|
|
737
|
-
// GET /api/taskforce/sync/workspace/pull - Incremental workspace task deltas with cursor paging
|
|
738
|
-
addRoute('GET', '/api/taskforce/sync/workspace/pull', async (req, res) => {
|
|
739
|
-
const authConfig = context.authConfig;
|
|
740
|
-
if (!authConfig || !authConfig.enabled) {
|
|
741
|
-
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
742
|
-
res.end(JSON.stringify({ success: false, error: 'Sync is unavailable when auth is disabled.' }));
|
|
743
|
-
return;
|
|
744
|
-
}
|
|
745
|
-
const access = resolveRequestAccess(req, authConfig);
|
|
746
|
-
if (!access.authenticated || !access.userId || access.userId === 'anonymous') {
|
|
747
|
-
auditAuthAction(req, 'sync-workspace-pull-unauthorized', {});
|
|
748
|
-
res.writeHead(401, { 'Content-Type': 'application/json' });
|
|
749
|
-
res.end(JSON.stringify({ success: false, error: 'Authentication required.' }));
|
|
750
|
-
return;
|
|
751
|
-
}
|
|
752
|
-
const url = new URL(req.url || '/api/taskforce/sync/workspace/pull', 'http://localhost');
|
|
753
|
-
const requestedWorkspaceId = String(url.searchParams.get('workspaceId') || '').trim();
|
|
754
|
-
if (!requestedWorkspaceId) {
|
|
755
|
-
auditAuthAction(req, 'sync-workspace-pull-missing-workspace', { code: 'WORKSPACE_ID_REQUIRED' });
|
|
756
|
-
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
757
|
-
res.end(JSON.stringify({
|
|
758
|
-
success: false,
|
|
759
|
-
error: 'workspaceId is required.',
|
|
760
|
-
code: 'WORKSPACE_ID_REQUIRED',
|
|
761
|
-
workspaceId: null
|
|
762
|
-
}));
|
|
763
|
-
return;
|
|
764
|
-
}
|
|
765
|
-
const allowed = core.listUserWorkspaces(access.userId).find((workspace) => workspace.id === requestedWorkspaceId);
|
|
766
|
-
if (!allowed) {
|
|
767
|
-
auditAuthAction(req, 'sync-workspace-pull-forbidden', {
|
|
768
|
-
requestedWorkspaceId
|
|
769
|
-
});
|
|
770
|
-
res.writeHead(403, { 'Content-Type': 'application/json' });
|
|
771
|
-
res.end(JSON.stringify({
|
|
772
|
-
success: false,
|
|
773
|
-
error: 'You do not have access to this workspace.',
|
|
774
|
-
code: 'WORKSPACE_ACCESS_DENIED',
|
|
775
|
-
workspaceId: requestedWorkspaceId
|
|
776
|
-
}));
|
|
777
|
-
return;
|
|
778
|
-
}
|
|
779
|
-
const targetWorkspaceId = requestedWorkspaceId;
|
|
780
|
-
const cursor = decodeWorkspaceSyncCursor(url.searchParams.get('cursor'));
|
|
781
|
-
const requestedLimit = Number.parseInt(String(url.searchParams.get('limit') || ''), 10);
|
|
782
|
-
const pageSize = Number.isFinite(requestedLimit) && requestedLimit > 0
|
|
783
|
-
? Math.max(1, Math.min(500, Math.floor(requestedLimit)))
|
|
784
|
-
: 200;
|
|
785
|
-
// Use watermark-indexed queries to avoid full table scans (Finding 12).
|
|
786
|
-
// Fetch up to pageSize * 2 tasks/deletes from DB since the cursor, then merge with
|
|
787
|
-
// small in-memory collections (taxonomy, documents) before slicing to pageSize.
|
|
788
|
-
const syncCursor = cursor ? { watermark: cursor.u, id: cursor.id } : null;
|
|
789
|
-
const dbFetchLimit = pageSize * 2 + 10;
|
|
790
|
-
const taskRows = typeof core.listTasksForSync === 'function'
|
|
791
|
-
? core.listTasksForSync(targetWorkspaceId, syncCursor, dbFetchLimit)
|
|
792
|
-
: [
|
|
793
|
-
...(core.listTasks(targetWorkspaceId)?.tasks || []).map((task) => ({ task, archived: false })),
|
|
794
|
-
...(core.listArchive(targetWorkspaceId)?.archived || []).map((task) => ({ task, archived: true }))
|
|
795
|
-
];
|
|
796
|
-
const upsertEntries = taskRows
|
|
797
|
-
.map((entry) => {
|
|
798
|
-
const watermark = String(entry.task?.updatedAt || entry.task?.createdAt || '').trim();
|
|
799
|
-
const taskId = String(entry.task?.id || '').trim();
|
|
800
|
-
return {
|
|
801
|
-
kind: 'upsert',
|
|
802
|
-
watermark,
|
|
803
|
-
sortId: taskId,
|
|
804
|
-
task: entry.task,
|
|
805
|
-
archived: Boolean(entry.archived)
|
|
806
|
-
};
|
|
807
|
-
})
|
|
808
|
-
.filter((entry) => Number.isFinite(Date.parse(entry.watermark)) && entry.sortId.length > 0);
|
|
809
|
-
const rawDeleteEntries = typeof core.listWorkspaceSyncDeletesSince === 'function'
|
|
810
|
-
? core.listWorkspaceSyncDeletesSince(targetWorkspaceId, syncCursor, dbFetchLimit)
|
|
811
|
-
: (typeof core.listWorkspaceSyncDeletes === 'function'
|
|
812
|
-
? core.listWorkspaceSyncDeletes(targetWorkspaceId)
|
|
813
|
-
: []);
|
|
814
|
-
const deleteEntries = rawDeleteEntries
|
|
815
|
-
.map((entry) => ({
|
|
816
|
-
kind: 'delete',
|
|
817
|
-
watermark: String(entry.deletedAt || '').trim(),
|
|
818
|
-
sortId: String(entry.taskId || '').trim(),
|
|
819
|
-
taskId: String(entry.taskId || '').trim()
|
|
820
|
-
}))
|
|
821
|
-
.filter((entry) => Number.isFinite(Date.parse(entry.watermark)) && entry.sortId.length > 0);
|
|
822
|
-
const taxonomySnapshot = (typeof core.getTaxonomiesSyncSnapshot === 'function'
|
|
823
|
-
? core.getTaxonomiesSyncSnapshot()
|
|
824
|
-
: null);
|
|
825
|
-
const taxonomyEntries = (taxonomySnapshot
|
|
826
|
-
&& Array.isArray(taxonomySnapshot.taxonomies)
|
|
827
|
-
&& Number.isFinite(Date.parse(String(taxonomySnapshot.updatedAt || '').trim())))
|
|
828
|
-
? [{
|
|
829
|
-
kind: 'taxonomy',
|
|
830
|
-
watermark: String(taxonomySnapshot.updatedAt || '').trim(),
|
|
831
|
-
sortId: '__taxonomy_config__',
|
|
832
|
-
taxonomies: taxonomySnapshot.taxonomies
|
|
833
|
-
}]
|
|
834
|
-
: [];
|
|
835
|
-
const documentEntries = listWorkspaceSyncDocumentsSnapshot(core.getPaths().basePath, targetWorkspaceId)
|
|
836
|
-
.map((doc) => ({
|
|
837
|
-
kind: 'document',
|
|
838
|
-
watermark: String(doc.updatedAt || '').trim(),
|
|
839
|
-
sortId: `doc:${String(doc.path || '').trim()}`,
|
|
840
|
-
path: String(doc.path || '').trim(),
|
|
841
|
-
content: String(doc.content || '')
|
|
842
|
-
}))
|
|
843
|
-
.filter((entry) => Number.isFinite(Date.parse(entry.watermark)) && entry.path.length > 0);
|
|
844
|
-
const all = [...upsertEntries, ...deleteEntries, ...taxonomyEntries, ...documentEntries];
|
|
845
|
-
const afterCursor = all.filter((entry) => {
|
|
846
|
-
if (!cursor)
|
|
847
|
-
return true;
|
|
848
|
-
const watermark = entry.watermark;
|
|
849
|
-
const sortId = entry.sortId;
|
|
850
|
-
if (watermark > cursor.u)
|
|
851
|
-
return true;
|
|
852
|
-
if (watermark < cursor.u)
|
|
853
|
-
return false;
|
|
854
|
-
return sortId > cursor.id;
|
|
855
|
-
});
|
|
856
|
-
afterCursor.sort((a, b) => {
|
|
857
|
-
if (a.watermark !== b.watermark)
|
|
858
|
-
return a.watermark.localeCompare(b.watermark);
|
|
859
|
-
return String(a.sortId || '').localeCompare(String(b.sortId || ''));
|
|
860
|
-
});
|
|
861
|
-
const page = afterCursor.slice(0, pageSize);
|
|
862
|
-
const hasMore = afterCursor.length > pageSize;
|
|
863
|
-
const last = page.length > 0 ? page[page.length - 1] : null;
|
|
864
|
-
const nextCursor = encodeWorkspaceSyncCursor(last
|
|
865
|
-
? { u: last.watermark, id: String(last.sortId || '') }
|
|
866
|
-
: cursor);
|
|
867
|
-
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
868
|
-
res.end(JSON.stringify({
|
|
869
|
-
success: true,
|
|
870
|
-
workspaceId: targetWorkspaceId,
|
|
871
|
-
changes: page.map((entry) => (entry.kind === 'delete'
|
|
872
|
-
? {
|
|
873
|
-
op: 'delete',
|
|
874
|
-
taskId: entry.taskId,
|
|
875
|
-
watermark: entry.watermark
|
|
876
|
-
}
|
|
877
|
-
: entry.kind === 'taxonomy'
|
|
878
|
-
? {
|
|
879
|
-
op: 'taxonomy-upsert',
|
|
880
|
-
taxonomies: entry.taxonomies,
|
|
881
|
-
watermark: entry.watermark
|
|
882
|
-
}
|
|
883
|
-
: entry.kind === 'document'
|
|
884
|
-
? {
|
|
885
|
-
op: 'document-upsert',
|
|
886
|
-
path: entry.path,
|
|
887
|
-
updatedAt: entry.watermark,
|
|
888
|
-
content: entry.content,
|
|
889
|
-
watermark: entry.watermark
|
|
890
|
-
}
|
|
891
|
-
: {
|
|
892
|
-
op: 'upsert',
|
|
893
|
-
task: entry.task,
|
|
894
|
-
archived: Boolean(entry.archived),
|
|
895
|
-
watermark: entry.watermark
|
|
896
|
-
})),
|
|
897
|
-
nextCursor,
|
|
898
|
-
hasMore
|
|
899
|
-
}));
|
|
900
|
-
auditAuthAction(req, 'sync-workspace-pull-success', {
|
|
901
|
-
workspaceId: targetWorkspaceId,
|
|
902
|
-
returnedChanges: page.length,
|
|
903
|
-
hasMore
|
|
904
|
-
});
|
|
905
|
-
});
|
|
906
|
-
// POST /api/taskforce/sync/workspace/apply-local - Apply pulled cloud deltas into local workspace store
|
|
907
|
-
addRoute('POST', '/api/taskforce/sync/workspace/apply-local', async (req, res) => {
|
|
908
|
-
const startedAtMs = Date.now();
|
|
909
|
-
const authConfig = context.authConfig;
|
|
910
|
-
if (authConfig?.runtimeMode === 'cloud') {
|
|
911
|
-
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
912
|
-
res.end(JSON.stringify({ success: false, error: 'Local apply endpoint is only available in local runtime.' }));
|
|
913
|
-
return;
|
|
914
|
-
}
|
|
915
|
-
const body = await parseJsonBody(req);
|
|
916
|
-
const bodyWorkspaceId = String(body?.workspaceId || '').trim();
|
|
917
|
-
const headerWorkspaceId = String(Array.isArray(req.headers['x-taskforce-workspace-id'])
|
|
918
|
-
? req.headers['x-taskforce-workspace-id'][0]
|
|
919
|
-
: req.headers['x-taskforce-workspace-id'] || '').trim();
|
|
920
|
-
let workspaceId = bodyWorkspaceId || headerWorkspaceId || requestWorkspaceId(req);
|
|
921
|
-
if (authConfig?.enabled) {
|
|
922
|
-
const access = resolveRequestAccess(req, authConfig);
|
|
923
|
-
if (!access.authenticated || !access.userId || access.userId === 'anonymous') {
|
|
924
|
-
auditAuthAction(req, 'sync-workspace-apply-unauthorized', {});
|
|
925
|
-
res.writeHead(401, { 'Content-Type': 'application/json' });
|
|
926
|
-
res.end(JSON.stringify({ success: false, error: 'Authentication required.' }));
|
|
927
|
-
return;
|
|
928
|
-
}
|
|
929
|
-
const accessWorkspaceId = String(access.workspaceId || '').trim();
|
|
930
|
-
if (accessWorkspaceId && accessWorkspaceId !== 'default') {
|
|
931
|
-
workspaceId = accessWorkspaceId;
|
|
932
|
-
}
|
|
933
|
-
}
|
|
934
|
-
if (!workspaceId || workspaceId === 'default' || workspaceId === 'null') {
|
|
935
|
-
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
936
|
-
res.end(JSON.stringify({
|
|
937
|
-
success: false,
|
|
938
|
-
error: 'Workspace ID required.',
|
|
939
|
-
code: 'WORKSPACE_ID_REQUIRED'
|
|
940
|
-
}));
|
|
941
|
-
return;
|
|
942
|
-
}
|
|
943
|
-
const incomingChanges = Array.isArray(body?.changes) ? body.changes : [];
|
|
944
|
-
try {
|
|
945
|
-
const { result } = dispatchWorkspaceSyncChanges(workspaceId, incomingChanges);
|
|
946
|
-
const durationMs = Date.now() - startedAtMs;
|
|
947
|
-
core.recordSyncEvent(workspaceId, {
|
|
948
|
-
eventType: 'apply',
|
|
949
|
-
status: 'success',
|
|
950
|
-
changeCount: incomingChanges.length,
|
|
951
|
-
requestMs: durationMs
|
|
952
|
-
});
|
|
953
|
-
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
954
|
-
res.end(JSON.stringify({
|
|
955
|
-
success: true,
|
|
956
|
-
workspaceId,
|
|
957
|
-
result,
|
|
958
|
-
durationMs
|
|
959
|
-
}));
|
|
960
|
-
}
|
|
961
|
-
catch (error) {
|
|
962
|
-
const statusCode = resolveErrorStatusCode(error, 400);
|
|
963
|
-
const durationMs = Date.now() - startedAtMs;
|
|
964
|
-
core.recordSyncEvent(workspaceId, {
|
|
965
|
-
eventType: 'apply',
|
|
966
|
-
status: 'error',
|
|
967
|
-
statusCode,
|
|
968
|
-
errorMessage: String(error?.message || 'Failed to apply local workspace deltas'),
|
|
969
|
-
changeCount: incomingChanges.length,
|
|
970
|
-
requestMs: durationMs
|
|
971
|
-
});
|
|
972
|
-
res.writeHead(statusCode, { 'Content-Type': 'application/json' });
|
|
973
|
-
res.end(JSON.stringify({
|
|
974
|
-
success: false,
|
|
975
|
-
error: String(error?.message || 'Failed to apply local workspace deltas'),
|
|
976
|
-
code: error?.code,
|
|
977
|
-
durationMs
|
|
978
|
-
}));
|
|
979
|
-
}
|
|
980
|
-
});
|
|
981
|
-
// POST /api/taskforce/sync/workspace/push - Incremental workspace deltas from local to cloud
|
|
982
|
-
addRoute('POST', '/api/taskforce/sync/workspace/push', async (req, res) => {
|
|
983
|
-
const startedAtMs = Date.now();
|
|
984
|
-
const authConfig = context.authConfig;
|
|
985
|
-
if (!authConfig || !authConfig.enabled) {
|
|
986
|
-
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
987
|
-
res.end(JSON.stringify({ success: false, error: 'Sync is unavailable when auth is disabled.' }));
|
|
988
|
-
return;
|
|
989
|
-
}
|
|
990
|
-
const access = resolveRequestAccess(req, authConfig);
|
|
991
|
-
if (!access.authenticated || !access.userId || access.userId === 'anonymous') {
|
|
992
|
-
auditAuthAction(req, 'sync-workspace-push-unauthorized', {});
|
|
993
|
-
res.writeHead(401, { 'Content-Type': 'application/json' });
|
|
994
|
-
res.end(JSON.stringify({ success: false, error: 'Authentication required.' }));
|
|
995
|
-
return;
|
|
996
|
-
}
|
|
997
|
-
const body = await parseJsonBody(req);
|
|
998
|
-
const requestedWorkspaceId = String(body?.workspaceId || '').trim();
|
|
999
|
-
if (!requestedWorkspaceId) {
|
|
1000
|
-
auditAuthAction(req, 'sync-workspace-push-missing-workspace', { code: 'WORKSPACE_ID_REQUIRED' });
|
|
1001
|
-
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
1002
|
-
res.end(JSON.stringify({
|
|
1003
|
-
success: false,
|
|
1004
|
-
error: 'workspaceId is required.',
|
|
1005
|
-
code: 'WORKSPACE_ID_REQUIRED',
|
|
1006
|
-
workspaceId: null,
|
|
1007
|
-
durationMs: Date.now() - startedAtMs
|
|
1008
|
-
}));
|
|
1009
|
-
return;
|
|
1010
|
-
}
|
|
1011
|
-
const allowed = core.listUserWorkspaces(access.userId).find((workspace) => workspace.id === requestedWorkspaceId);
|
|
1012
|
-
if (!allowed) {
|
|
1013
|
-
auditAuthAction(req, 'sync-workspace-push-forbidden', {
|
|
1014
|
-
requestedWorkspaceId
|
|
1015
|
-
});
|
|
1016
|
-
res.writeHead(403, { 'Content-Type': 'application/json' });
|
|
1017
|
-
res.end(JSON.stringify({
|
|
1018
|
-
success: false,
|
|
1019
|
-
error: 'You do not have access to this workspace.',
|
|
1020
|
-
code: 'WORKSPACE_ACCESS_DENIED',
|
|
1021
|
-
workspaceId: requestedWorkspaceId
|
|
1022
|
-
}));
|
|
1023
|
-
return;
|
|
1024
|
-
}
|
|
1025
|
-
const targetWorkspaceId = requestedWorkspaceId;
|
|
1026
|
-
const idempotencyKey = String(body?.idempotencyKey || '').trim();
|
|
1027
|
-
if (idempotencyKey) {
|
|
1028
|
-
const replay = readPushIdempotency(targetWorkspaceId, idempotencyKey);
|
|
1029
|
-
if (replay) {
|
|
1030
|
-
auditAuthAction(req, 'sync-workspace-push-idempotent-replay', {
|
|
1031
|
-
workspaceId: targetWorkspaceId,
|
|
1032
|
-
idempotencyKey
|
|
1033
|
-
});
|
|
1034
|
-
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
1035
|
-
res.end(replay);
|
|
1036
|
-
return;
|
|
1037
|
-
}
|
|
1038
|
-
}
|
|
1039
|
-
const incomingChanges = Array.isArray(body?.changes) ? body.changes : [];
|
|
1040
|
-
try {
|
|
1041
|
-
const { result, deleteCount, emittedEventIds } = dispatchWorkspaceSyncChanges(targetWorkspaceId, incomingChanges);
|
|
1042
|
-
const durationMs = Date.now() - startedAtMs;
|
|
1043
|
-
const payload = JSON.stringify({
|
|
1044
|
-
success: true,
|
|
1045
|
-
workspaceId: targetWorkspaceId,
|
|
1046
|
-
idempotencyKey: idempotencyKey || null,
|
|
1047
|
-
emittedEventIds,
|
|
1048
|
-
result,
|
|
1049
|
-
durationMs
|
|
1050
|
-
});
|
|
1051
|
-
if (idempotencyKey) {
|
|
1052
|
-
writePushIdempotency(targetWorkspaceId, idempotencyKey, payload);
|
|
1053
|
-
}
|
|
1054
|
-
core.recordSyncEvent(targetWorkspaceId, {
|
|
1055
|
-
eventType: 'push',
|
|
1056
|
-
status: 'success',
|
|
1057
|
-
changeCount: incomingChanges.length,
|
|
1058
|
-
requestMs: durationMs
|
|
1059
|
-
});
|
|
1060
|
-
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
1061
|
-
res.end(payload);
|
|
1062
|
-
auditAuthAction(req, 'sync-workspace-push-success', {
|
|
1063
|
-
workspaceId: targetWorkspaceId,
|
|
1064
|
-
idempotencyKey: idempotencyKey || null,
|
|
1065
|
-
changeCount: incomingChanges.length,
|
|
1066
|
-
deleteCount: deleteCount,
|
|
1067
|
-
durationMs
|
|
1068
|
-
});
|
|
1069
|
-
}
|
|
1070
|
-
catch (error) {
|
|
1071
|
-
const statusCode = resolveErrorStatusCode(error, 400);
|
|
1072
|
-
const durationMs = Date.now() - startedAtMs;
|
|
1073
|
-
core.recordSyncEvent(targetWorkspaceId, {
|
|
1074
|
-
eventType: 'push',
|
|
1075
|
-
status: 'error',
|
|
1076
|
-
statusCode,
|
|
1077
|
-
errorMessage: String(error?.message || 'Failed to apply workspace deltas'),
|
|
1078
|
-
changeCount: incomingChanges.length,
|
|
1079
|
-
requestMs: durationMs
|
|
1080
|
-
});
|
|
1081
|
-
auditAuthAction(req, 'sync-workspace-push-failed', {
|
|
1082
|
-
workspaceId: targetWorkspaceId,
|
|
1083
|
-
code: error?.code || null,
|
|
1084
|
-
statusCode,
|
|
1085
|
-
durationMs
|
|
1086
|
-
});
|
|
1087
|
-
res.writeHead(statusCode, { 'Content-Type': 'application/json' });
|
|
1088
|
-
res.end(JSON.stringify({
|
|
1089
|
-
success: false,
|
|
1090
|
-
error: String(error?.message || 'Failed to apply workspace deltas'),
|
|
1091
|
-
code: error?.code,
|
|
1092
|
-
durationMs
|
|
1093
|
-
}));
|
|
1094
|
-
}
|
|
1095
|
-
});
|
|
1096
|
-
// GET /api/taskforce/sync/events - Query recent sync events (local runtime only)
|
|
1097
|
-
addRoute('GET', '/api/taskforce/sync/events', async (req, res) => {
|
|
1098
|
-
const authConfig = context.authConfig;
|
|
1099
|
-
const access = authConfig?.enabled ? resolveRequestAccess(req, authConfig) : null;
|
|
1100
|
-
if (access && (!access.authenticated || !access.userId || access.userId === 'anonymous')) {
|
|
1101
|
-
res.writeHead(401, { 'Content-Type': 'application/json' });
|
|
1102
|
-
res.end(JSON.stringify({ success: false, error: 'Authentication required.' }));
|
|
1103
|
-
return;
|
|
1104
|
-
}
|
|
1105
|
-
const url = new URL(req.url || '/', 'http://localhost');
|
|
1106
|
-
const workspaceId = String(url.searchParams.get('workspace_id') || access?.workspaceId || '').trim() || 'default';
|
|
1107
|
-
const limit = Math.min(500, Math.max(1, Number(url.searchParams.get('limit') || '100')));
|
|
1108
|
-
const events = core.listSyncEvents(workspaceId, limit);
|
|
1109
|
-
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
1110
|
-
res.end(JSON.stringify({ success: true, events }));
|
|
1111
|
-
});
|
|
1112
|
-
// POST /api/taskforce/sync/events - Record a client-side sync event (pull results, handshake outcomes)
|
|
1113
|
-
addRoute('POST', '/api/taskforce/sync/events', async (req, res) => {
|
|
1114
|
-
const authConfig = context.authConfig;
|
|
1115
|
-
const access = authConfig?.enabled ? resolveRequestAccess(req, authConfig) : null;
|
|
1116
|
-
if (access && (!access.authenticated || !access.userId || access.userId === 'anonymous')) {
|
|
1117
|
-
res.writeHead(401, { 'Content-Type': 'application/json' });
|
|
1118
|
-
res.end(JSON.stringify({ success: false, error: 'Authentication required.' }));
|
|
1119
|
-
return;
|
|
1120
|
-
}
|
|
1121
|
-
const body = await parseJsonBody(req);
|
|
1122
|
-
const allowedEventTypes = ['pull', 'handshake', 'bootstrap', 'apply', 'push'];
|
|
1123
|
-
const eventType = String(body?.eventType || '').trim().toLowerCase();
|
|
1124
|
-
if (!allowedEventTypes.includes(eventType)) {
|
|
1125
|
-
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
1126
|
-
res.end(JSON.stringify({ success: false, error: 'Invalid eventType.' }));
|
|
1127
|
-
return;
|
|
1128
|
-
}
|
|
1129
|
-
const workspaceId = String(body?.workspaceId || access?.workspaceId || '').trim() || 'default';
|
|
1130
|
-
core.recordSyncEvent(workspaceId, {
|
|
1131
|
-
eventType: eventType,
|
|
1132
|
-
status: String(body?.status || '') === 'error' ? 'error' : 'success',
|
|
1133
|
-
statusCode: typeof body?.statusCode === 'number' ? body.statusCode : undefined,
|
|
1134
|
-
errorMessage: typeof body?.errorMessage === 'string' ? body.errorMessage.slice(0, 500) : undefined,
|
|
1135
|
-
changeCount: typeof body?.changeCount === 'number' ? body.changeCount : undefined,
|
|
1136
|
-
requestMs: typeof body?.requestMs === 'number' ? body.requestMs : undefined
|
|
1137
|
-
});
|
|
1138
|
-
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
1139
|
-
res.end(JSON.stringify({ success: true }));
|
|
1140
|
-
});
|
|
1141
|
-
}
|