@taskforcehq/taskforce 0.3.169 → 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 +20 -3
- 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
|
@@ -0,0 +1,1113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Document and context route module.
|
|
3
|
+
*
|
|
4
|
+
* Handles context uploads, document reads and writes, document listing,
|
|
5
|
+
* retention metadata, and plan-to-task generation.
|
|
6
|
+
*
|
|
7
|
+
* Routes registered here:
|
|
8
|
+
* POST /api/taskforce/context-upload/init
|
|
9
|
+
* POST /api/taskforce/context-upload/finalize
|
|
10
|
+
* POST /api/taskforce/context-upload
|
|
11
|
+
* GET /api/taskforce/context/:filename
|
|
12
|
+
* GET /api/taskforce/documents/:assetId/content
|
|
13
|
+
* GET /api/taskforce/context-link
|
|
14
|
+
* DELETE /api/taskforce/context/:filename
|
|
15
|
+
* GET /api/taskforce/context-metadata
|
|
16
|
+
* POST /api/taskforce/context/purge-expired
|
|
17
|
+
* GET /api/taskforce/documents
|
|
18
|
+
* DELETE /api/taskforce/documents/:assetId
|
|
19
|
+
* PATCH /api/taskforce/documents/:assetId
|
|
20
|
+
* POST /api/taskforce/documents/save
|
|
21
|
+
* POST /api/taskforce/documents/generate-tasks/preview
|
|
22
|
+
* POST /api/taskforce/documents/generate-tasks/commit
|
|
23
|
+
*/
|
|
24
|
+
import * as fs from 'fs';
|
|
25
|
+
import * as path from 'path';
|
|
26
|
+
import { normalizeTaskDataRelativePath } from '../../storage/objectStorageClient.js';
|
|
27
|
+
import { purgeExpiredDocuments } from '../../storage/documentPurge.js';
|
|
28
|
+
import { parsePlan } from '../../utils/planParser.js';
|
|
29
|
+
import { getCanonicalDocumentName, getReadableDocumentName, isGeneratedDocumentName } from '../../utils/documentNames.js';
|
|
30
|
+
import { parseJsonBody } from '../routes.js';
|
|
31
|
+
export function registerDocumentRoutes(deps) {
|
|
32
|
+
const { addRoute, core, context, requestWorkspaceId, ensureAdminRole, resolveEffectiveObjectStorageConfig, getObjectStorageClient, resolveStorageWorkspaceId, ensureContextUploadAllowed, parseStorageFolderSegments, buildCanonicalWorkspaceAssetRelativePath, inferAssetKindFromPath, appendStorageTelemetry, scanAndRecordDocument, buildTaskAttachmentPayload, workspaceAssetStore, taskAssetStore, normalizeDocumentPathInput, getAssetMetadata, getCanonicalAssetMetadata, documentRetentionDays, appendDocumentPurgeHistory, markAssetDeleted, isAssetDeleted, clearAssetDeleted, ensureWithinDir, sanitizeDownloadFilename, contentTypeForExt, inferInlineDocumentFromPath, resolveCanonicalDocumentRead, inferWorkspaceIdFromStoragePath, inferTaskIdFromStoragePath, } = deps;
|
|
33
|
+
addRoute('POST', '/api/taskforce/context-upload/init', async (req, res) => {
|
|
34
|
+
const resolvedObjectStorage = resolveEffectiveObjectStorageConfig();
|
|
35
|
+
const objectStorageClient = getObjectStorageClient();
|
|
36
|
+
const body = await parseJsonBody(req);
|
|
37
|
+
const { originalName, mimeType, taskId, folderPath } = body || {};
|
|
38
|
+
const workspaceId = resolveStorageWorkspaceId(req, body);
|
|
39
|
+
if (!workspaceId) {
|
|
40
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
41
|
+
res.end(JSON.stringify({ error: 'workspaceId is required and cannot be default for uploads.' }));
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (!ensureContextUploadAllowed(req, res, workspaceId))
|
|
45
|
+
return;
|
|
46
|
+
const folderSegments = parseStorageFolderSegments(folderPath);
|
|
47
|
+
if (folderSegments === null) {
|
|
48
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
49
|
+
res.end(JSON.stringify({ error: 'folderPath cannot contain . or .. segments.' }));
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const extFromMime = {
|
|
53
|
+
'image/png': '.png',
|
|
54
|
+
'image/jpeg': '.jpg',
|
|
55
|
+
'image/webp': '.webp',
|
|
56
|
+
'image/gif': '.gif',
|
|
57
|
+
'application/pdf': '.pdf',
|
|
58
|
+
'text/plain': '.txt',
|
|
59
|
+
'text/markdown': '.md',
|
|
60
|
+
'text/csv': '.csv',
|
|
61
|
+
'application/json': '.json',
|
|
62
|
+
'application/msword': '.doc',
|
|
63
|
+
'application/vnd.openxmlformats-officedocument.wordprocessingml.document': '.docx'
|
|
64
|
+
};
|
|
65
|
+
const safeOriginal = typeof originalName === 'string' ? originalName.trim() : '';
|
|
66
|
+
const originalExt = safeOriginal ? path.extname(safeOriginal).toLowerCase() : '';
|
|
67
|
+
const extension = originalExt || extFromMime[String(mimeType || '')] || '.bin';
|
|
68
|
+
const safeBase = (safeOriginal ? path.basename(safeOriginal, originalExt) : 'context-file')
|
|
69
|
+
.replace(/[^a-zA-Z0-9._-]/g, '-')
|
|
70
|
+
.slice(0, 64) || 'context-file';
|
|
71
|
+
const actualFilename = `${safeBase}-${Date.now()}${extension}`;
|
|
72
|
+
const { basePath, projectRoot } = core.getPaths();
|
|
73
|
+
const kind = String(mimeType || '').startsWith('image/')
|
|
74
|
+
? 'image'
|
|
75
|
+
: inferAssetKindFromPath(actualFilename);
|
|
76
|
+
const canonicalAsset = buildCanonicalWorkspaceAssetRelativePath({
|
|
77
|
+
workspaceIdRaw: workspaceId,
|
|
78
|
+
kind,
|
|
79
|
+
filename: actualFilename,
|
|
80
|
+
folderSegments
|
|
81
|
+
});
|
|
82
|
+
const relativeToStorage = canonicalAsset.relativePath;
|
|
83
|
+
const relativePath = path.relative(projectRoot, path.join(basePath, relativeToStorage));
|
|
84
|
+
if (objectStorageClient && resolvedObjectStorage.provider === 'r2' && resolvedObjectStorage.r2) {
|
|
85
|
+
const uploadUrl = objectStorageClient.createSignedPutUrl(relativeToStorage, resolvedObjectStorage.r2.signedUploadTtlSeconds, String(mimeType || 'application/octet-stream'));
|
|
86
|
+
appendStorageTelemetry('upload.initiated', {
|
|
87
|
+
path: relativeToStorage,
|
|
88
|
+
status: 'signed',
|
|
89
|
+
provider: 'r2'
|
|
90
|
+
});
|
|
91
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
92
|
+
res.end(JSON.stringify({
|
|
93
|
+
success: true,
|
|
94
|
+
mode: 'direct',
|
|
95
|
+
uploadUrl,
|
|
96
|
+
method: 'PUT',
|
|
97
|
+
headers: {
|
|
98
|
+
'Content-Type': String(mimeType || 'application/octet-stream')
|
|
99
|
+
},
|
|
100
|
+
filename: actualFilename,
|
|
101
|
+
relativePath: relativeToStorage,
|
|
102
|
+
path: kind === 'document'
|
|
103
|
+
? `/api/taskforce/documents/${encodeURIComponent(canonicalAsset.assetId)}/content`
|
|
104
|
+
: `/api/taskforce/context/${encodeURIComponent(relativeToStorage)}`,
|
|
105
|
+
fsPath: relativePath,
|
|
106
|
+
assetId: canonicalAsset.assetId,
|
|
107
|
+
taskId: typeof taskId === 'string' && taskId.trim().length > 0 ? taskId.trim() : null
|
|
108
|
+
}));
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
112
|
+
res.end(JSON.stringify({
|
|
113
|
+
success: true,
|
|
114
|
+
mode: 'server',
|
|
115
|
+
filename: actualFilename
|
|
116
|
+
}));
|
|
117
|
+
appendStorageTelemetry('upload.initiated', {
|
|
118
|
+
status: 'server',
|
|
119
|
+
provider: objectStorageClient ? 'r2' : 'local'
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
addRoute('POST', '/api/taskforce/context-upload/finalize', async (req, res) => {
|
|
123
|
+
const objectStorageClient = getObjectStorageClient();
|
|
124
|
+
const body = await parseJsonBody(req);
|
|
125
|
+
const relativeToStorage = normalizeTaskDataRelativePath(String(body?.relativePath || body?.path || '').trim());
|
|
126
|
+
if (!relativeToStorage) {
|
|
127
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
128
|
+
res.end(JSON.stringify({ error: 'relativePath is required.' }));
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const workspaceId = inferWorkspaceIdFromStoragePath(relativeToStorage) || requestWorkspaceId(req);
|
|
132
|
+
if (!ensureContextUploadAllowed(req, res, workspaceId))
|
|
133
|
+
return;
|
|
134
|
+
if (!objectStorageClient) {
|
|
135
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
136
|
+
res.end(JSON.stringify({ success: true, mode: 'local' }));
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const object = await objectStorageClient.getObject(relativeToStorage);
|
|
140
|
+
if (!object) {
|
|
141
|
+
res.writeHead(404, { 'Content-Type': 'application/json' });
|
|
142
|
+
res.end(JSON.stringify({ error: 'Uploaded file not found.' }));
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
try {
|
|
146
|
+
const taskId = typeof body?.taskId === 'string' && body.taskId.trim().length > 0
|
|
147
|
+
? body.taskId.trim()
|
|
148
|
+
: inferTaskIdFromStoragePath(relativeToStorage);
|
|
149
|
+
const metadata = await scanAndRecordDocument({
|
|
150
|
+
relativeToStorage,
|
|
151
|
+
buffer: object.body,
|
|
152
|
+
contentType: String(body?.mimeType || object.contentType || 'application/octet-stream'),
|
|
153
|
+
provider: 'r2',
|
|
154
|
+
workspaceId: inferWorkspaceIdFromStoragePath(relativeToStorage),
|
|
155
|
+
taskId,
|
|
156
|
+
originalName: typeof body?.originalName === 'string' ? body.originalName.trim() : null
|
|
157
|
+
});
|
|
158
|
+
appendStorageTelemetry('upload.finalized', {
|
|
159
|
+
path: relativeToStorage,
|
|
160
|
+
status: metadata.scan?.verdict || 'unknown',
|
|
161
|
+
provider: 'r2'
|
|
162
|
+
});
|
|
163
|
+
const attachment = buildTaskAttachmentPayload(relativeToStorage, {
|
|
164
|
+
caption: typeof body?.originalName === 'string' ? body.originalName.trim() : null,
|
|
165
|
+
assetId: workspaceAssetStore?.getByStorageKey(relativeToStorage, inferWorkspaceIdFromStoragePath(relativeToStorage))?.assetId || null,
|
|
166
|
+
taskId
|
|
167
|
+
});
|
|
168
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
169
|
+
res.end(JSON.stringify({
|
|
170
|
+
success: true,
|
|
171
|
+
metadata,
|
|
172
|
+
...(attachment ? attachment : {})
|
|
173
|
+
}));
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
if (error?.code === 'VIRUS_DETECTED') {
|
|
177
|
+
await objectStorageClient.deleteObject(relativeToStorage);
|
|
178
|
+
}
|
|
179
|
+
throw error;
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
addRoute('POST', '/api/taskforce/context-upload', async (req, res) => {
|
|
183
|
+
const objectStorageClient = getObjectStorageClient();
|
|
184
|
+
const body = await parseJsonBody(req);
|
|
185
|
+
const { file, originalName, taskId, folderPath } = body;
|
|
186
|
+
const workspaceId = resolveStorageWorkspaceId(req, body);
|
|
187
|
+
if (!workspaceId) {
|
|
188
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
189
|
+
res.end(JSON.stringify({ error: 'workspaceId is required and cannot be default for uploads.' }));
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
if (!ensureContextUploadAllowed(req, res, workspaceId))
|
|
193
|
+
return;
|
|
194
|
+
const folderSegments = parseStorageFolderSegments(folderPath);
|
|
195
|
+
if (folderSegments === null) {
|
|
196
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
197
|
+
res.end(JSON.stringify({ error: 'folderPath cannot contain . or .. segments.' }));
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
if (!file || typeof file !== 'string') {
|
|
201
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
202
|
+
res.end(JSON.stringify({ error: 'No file data' }));
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
const dataMatch = file.match(/^data:([^;]+);base64,(.+)$/);
|
|
206
|
+
if (!dataMatch) {
|
|
207
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
208
|
+
res.end(JSON.stringify({ error: 'Invalid file payload' }));
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
const [, mimeType, base64Data] = dataMatch;
|
|
212
|
+
const extFromMime = {
|
|
213
|
+
'image/png': '.png',
|
|
214
|
+
'image/jpeg': '.jpg',
|
|
215
|
+
'image/webp': '.webp',
|
|
216
|
+
'image/gif': '.gif',
|
|
217
|
+
'application/pdf': '.pdf',
|
|
218
|
+
'text/plain': '.txt',
|
|
219
|
+
'text/markdown': '.md',
|
|
220
|
+
'text/csv': '.csv',
|
|
221
|
+
'application/json': '.json',
|
|
222
|
+
'application/msword': '.doc',
|
|
223
|
+
'application/vnd.openxmlformats-officedocument.wordprocessingml.document': '.docx'
|
|
224
|
+
};
|
|
225
|
+
const safeOriginal = typeof originalName === 'string' ? originalName.trim() : '';
|
|
226
|
+
const originalExt = safeOriginal ? path.extname(safeOriginal).toLowerCase() : '';
|
|
227
|
+
const extension = originalExt || extFromMime[mimeType] || '.bin';
|
|
228
|
+
const safeBase = (safeOriginal ? path.basename(safeOriginal, originalExt) : 'context-file')
|
|
229
|
+
.replace(/[^a-zA-Z0-9._-]/g, '-')
|
|
230
|
+
.slice(0, 64) || 'context-file';
|
|
231
|
+
const actualFilename = `${safeBase}-${Date.now()}${extension}`;
|
|
232
|
+
const { basePath, projectRoot } = core.getPaths();
|
|
233
|
+
const buffer = Buffer.from(base64Data, 'base64');
|
|
234
|
+
const relativeToStorage = buildCanonicalWorkspaceAssetRelativePath({
|
|
235
|
+
workspaceIdRaw: workspaceId,
|
|
236
|
+
kind: mimeType.startsWith('image/') ? 'image' : inferAssetKindFromPath(actualFilename),
|
|
237
|
+
filename: actualFilename,
|
|
238
|
+
folderSegments
|
|
239
|
+
}).relativePath;
|
|
240
|
+
let relativePath;
|
|
241
|
+
if (objectStorageClient) {
|
|
242
|
+
await objectStorageClient.putObject(relativeToStorage, buffer, mimeType || 'application/octet-stream');
|
|
243
|
+
await scanAndRecordDocument({
|
|
244
|
+
relativeToStorage,
|
|
245
|
+
buffer,
|
|
246
|
+
contentType: mimeType || 'application/octet-stream',
|
|
247
|
+
provider: 'r2',
|
|
248
|
+
workspaceId,
|
|
249
|
+
taskId,
|
|
250
|
+
originalName: safeOriginal || actualFilename
|
|
251
|
+
});
|
|
252
|
+
appendStorageTelemetry('upload.completed', {
|
|
253
|
+
path: relativeToStorage,
|
|
254
|
+
provider: 'r2',
|
|
255
|
+
status: 'stored'
|
|
256
|
+
});
|
|
257
|
+
relativePath = path.relative(projectRoot, path.join(basePath, relativeToStorage));
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
const filePath = path.join(basePath, relativeToStorage);
|
|
261
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
262
|
+
fs.writeFileSync(filePath, buffer);
|
|
263
|
+
await scanAndRecordDocument({
|
|
264
|
+
relativeToStorage,
|
|
265
|
+
buffer,
|
|
266
|
+
contentType: mimeType || 'application/octet-stream',
|
|
267
|
+
provider: 'local',
|
|
268
|
+
workspaceId,
|
|
269
|
+
taskId,
|
|
270
|
+
originalName: safeOriginal || actualFilename
|
|
271
|
+
});
|
|
272
|
+
appendStorageTelemetry('upload.completed', {
|
|
273
|
+
path: relativeToStorage,
|
|
274
|
+
provider: 'local',
|
|
275
|
+
status: 'stored'
|
|
276
|
+
});
|
|
277
|
+
relativePath = path.relative(projectRoot, filePath);
|
|
278
|
+
}
|
|
279
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
280
|
+
const attachment = buildTaskAttachmentPayload(relativeToStorage, {
|
|
281
|
+
caption: safeOriginal || actualFilename,
|
|
282
|
+
taskId: typeof taskId === 'string' && taskId.trim().length > 0 ? taskId.trim() : null
|
|
283
|
+
});
|
|
284
|
+
res.end(JSON.stringify({
|
|
285
|
+
success: true,
|
|
286
|
+
filename: actualFilename,
|
|
287
|
+
...(attachment || {
|
|
288
|
+
path: `/api/taskforce/context/${encodeURIComponent(relativeToStorage)}`,
|
|
289
|
+
fsPath: relativePath
|
|
290
|
+
})
|
|
291
|
+
}));
|
|
292
|
+
});
|
|
293
|
+
addRoute('GET', '/api/taskforce/context/:filename', async (req, res, params) => {
|
|
294
|
+
const resolvedObjectStorage = resolveEffectiveObjectStorageConfig();
|
|
295
|
+
const objectStorageClient = getObjectStorageClient();
|
|
296
|
+
const { basePath } = core.getPaths();
|
|
297
|
+
const url = new URL(req.url || '', 'http://localhost');
|
|
298
|
+
const forceDownload = url.searchParams.get('download') === '1';
|
|
299
|
+
const requestedFilename = String(url.searchParams.get('filename') || '').trim();
|
|
300
|
+
const decoded = decodeURIComponent(params.filename);
|
|
301
|
+
const normalizedRelative = normalizeTaskDataRelativePath(decoded);
|
|
302
|
+
const contextAsset = normalizedRelative ? getAssetMetadata(normalizedRelative) : null;
|
|
303
|
+
const canonicalAsset = normalizedRelative ? getCanonicalAssetMetadata(normalizedRelative) : null;
|
|
304
|
+
if (normalizedRelative && contextAsset?.quarantineStatus === 'quarantined') {
|
|
305
|
+
res.writeHead(423, { 'Content-Type': 'text/plain' });
|
|
306
|
+
res.end('Context file is quarantined');
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
if (normalizedRelative && contextAsset?.scan?.verdict === 'pending') {
|
|
310
|
+
res.writeHead(425, { 'Content-Type': 'text/plain' });
|
|
311
|
+
res.end('Context file scan pending');
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
if (normalizedRelative && isAssetDeleted(normalizedRelative)) {
|
|
315
|
+
res.writeHead(404, { 'Content-Type': 'text/plain' });
|
|
316
|
+
res.end('Context file not found');
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
const filePath = normalizedRelative
|
|
320
|
+
? ensureWithinDir(path.join(basePath, normalizedRelative), basePath)
|
|
321
|
+
: null;
|
|
322
|
+
const ext = normalizedRelative ? path.extname(normalizedRelative).toLowerCase() : '';
|
|
323
|
+
const resolvedDownloadNameBase = sanitizeDownloadFilename(requestedFilename
|
|
324
|
+
|| canonicalAsset?.logicalName
|
|
325
|
+
|| canonicalAsset?.originalFilename
|
|
326
|
+
|| path.basename(normalizedRelative || '', ext)
|
|
327
|
+
|| 'download');
|
|
328
|
+
const resolvedDownloadName = ext && !resolvedDownloadNameBase.toLowerCase().endsWith(ext)
|
|
329
|
+
? `${resolvedDownloadNameBase}${ext}`
|
|
330
|
+
: resolvedDownloadNameBase;
|
|
331
|
+
const contentDisposition = forceDownload
|
|
332
|
+
? `attachment; filename="${resolvedDownloadName.replace(/"/g, '')}"`
|
|
333
|
+
: 'inline';
|
|
334
|
+
const shouldProxyInlineDocument = !forceDownload && (canonicalAsset?.kind === 'document' || inferInlineDocumentFromPath(normalizedRelative));
|
|
335
|
+
if (canonicalAsset?.kind === 'document' && !canonicalAsset.deletedAt) {
|
|
336
|
+
const response = await resolveCanonicalDocumentRead({
|
|
337
|
+
asset: canonicalAsset,
|
|
338
|
+
forceDownload,
|
|
339
|
+
requestedFilename
|
|
340
|
+
});
|
|
341
|
+
if (response.statusCode === 404) {
|
|
342
|
+
res.writeHead(404, { 'Content-Type': 'text/plain' });
|
|
343
|
+
res.end('Context file not found');
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
if (forceDownload && response.statusCode === 302 && response.headers?.Location) {
|
|
347
|
+
res.writeHead(302, { Location: response.headers.Location });
|
|
348
|
+
res.end();
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
res.writeHead(200, response.headers || {
|
|
352
|
+
'Content-Type': contentTypeForExt(ext),
|
|
353
|
+
'Content-Disposition': contentDisposition
|
|
354
|
+
});
|
|
355
|
+
res.end(response.body);
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
if (objectStorageClient && normalizedRelative && resolvedObjectStorage.provider === 'r2' && resolvedObjectStorage.r2) {
|
|
359
|
+
if (shouldProxyInlineDocument) {
|
|
360
|
+
const object = await objectStorageClient.getObject(normalizedRelative);
|
|
361
|
+
if (!object) {
|
|
362
|
+
res.writeHead(404, { 'Content-Type': 'text/plain' });
|
|
363
|
+
res.end('Context file not found');
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
res.writeHead(200, {
|
|
367
|
+
'Content-Type': object.contentType || contentTypeForExt(ext),
|
|
368
|
+
'Content-Disposition': contentDisposition
|
|
369
|
+
});
|
|
370
|
+
res.end(object.body);
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
const signedUrl = objectStorageClient.createSignedGetUrl(normalizedRelative, resolvedObjectStorage.r2.signedDownloadTtlSeconds, forceDownload ? { responseContentDisposition: contentDisposition } : undefined);
|
|
374
|
+
res.writeHead(302, { Location: signedUrl });
|
|
375
|
+
res.end();
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
if (filePath && fs.existsSync(filePath)) {
|
|
379
|
+
res.writeHead(200, {
|
|
380
|
+
'Content-Type': contentTypeForExt(ext),
|
|
381
|
+
'Content-Disposition': contentDisposition
|
|
382
|
+
});
|
|
383
|
+
res.end(fs.readFileSync(filePath));
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
res.writeHead(404, { 'Content-Type': 'text/plain' });
|
|
387
|
+
res.end('Context file not found');
|
|
388
|
+
});
|
|
389
|
+
addRoute('GET', '/api/taskforce/documents/:assetId/content', async (req, res, params) => {
|
|
390
|
+
const workspaceId = requestWorkspaceId(req);
|
|
391
|
+
const assetId = String(params.assetId || '').trim();
|
|
392
|
+
const url = new URL(req.url || '', 'http://localhost');
|
|
393
|
+
const forceDownload = url.searchParams.get('download') === '1';
|
|
394
|
+
const requestedFilename = String(url.searchParams.get('filename') || '').trim();
|
|
395
|
+
if (!workspaceAssetStore || !assetId) {
|
|
396
|
+
res.writeHead(404, { 'Content-Type': 'application/json' });
|
|
397
|
+
res.end(JSON.stringify({ error: 'Document not found' }));
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
const asset = workspaceAssetStore.get(assetId, workspaceId);
|
|
401
|
+
if (!asset || asset.kind !== 'document' || asset.deletedAt) {
|
|
402
|
+
res.writeHead(404, { 'Content-Type': 'application/json' });
|
|
403
|
+
res.end(JSON.stringify({ error: 'Document not found' }));
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
if (asset.scanStatus === 'infected') {
|
|
407
|
+
res.writeHead(423, { 'Content-Type': 'text/plain' });
|
|
408
|
+
res.end('Document is quarantined');
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
if (asset.scanStatus === 'pending') {
|
|
412
|
+
res.writeHead(425, { 'Content-Type': 'text/plain' });
|
|
413
|
+
res.end('Document scan pending');
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
const response = await resolveCanonicalDocumentRead({
|
|
417
|
+
asset,
|
|
418
|
+
forceDownload,
|
|
419
|
+
requestedFilename
|
|
420
|
+
});
|
|
421
|
+
if (response.statusCode === 404) {
|
|
422
|
+
res.writeHead(404, { 'Content-Type': 'application/json' });
|
|
423
|
+
res.end(JSON.stringify({ error: 'Document content not found' }));
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
if (forceDownload && response.statusCode === 302 && response.headers?.Location) {
|
|
427
|
+
res.writeHead(302, { Location: response.headers.Location });
|
|
428
|
+
res.end();
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
res.writeHead(200, response.headers || {
|
|
432
|
+
'Content-Type': asset.mimeType || 'text/markdown',
|
|
433
|
+
'Content-Disposition': forceDownload ? 'attachment' : 'inline'
|
|
434
|
+
});
|
|
435
|
+
res.end(response.body);
|
|
436
|
+
});
|
|
437
|
+
addRoute('GET', '/api/taskforce/context-link', async (req, res) => {
|
|
438
|
+
const url = new URL(req.url || '', 'http://localhost');
|
|
439
|
+
const linkedPath = (url.searchParams.get('path') || '').trim();
|
|
440
|
+
const forceDownload = url.searchParams.get('download') === '1';
|
|
441
|
+
const requestedFilename = String(url.searchParams.get('filename') || '').trim();
|
|
442
|
+
const { projectRoot } = core.getPaths();
|
|
443
|
+
if (!linkedPath) {
|
|
444
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
445
|
+
res.end(JSON.stringify({ error: 'path query parameter is required' }));
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
const resolvedPath = path.isAbsolute(linkedPath)
|
|
449
|
+
? path.resolve(linkedPath)
|
|
450
|
+
: path.resolve(projectRoot, linkedPath);
|
|
451
|
+
const realPath = fs.existsSync(resolvedPath) ? fs.realpathSync(resolvedPath) : resolvedPath;
|
|
452
|
+
if (!realPath.startsWith(projectRoot)) {
|
|
453
|
+
res.writeHead(403, { 'Content-Type': 'application/json' });
|
|
454
|
+
res.end(JSON.stringify({ error: 'Linked file must be within project root' }));
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
if (!fs.existsSync(realPath) || !fs.statSync(realPath).isFile()) {
|
|
458
|
+
res.writeHead(404, { 'Content-Type': 'application/json' });
|
|
459
|
+
res.end(JSON.stringify({ error: 'Linked file not found' }));
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
const ext = path.extname(realPath).toLowerCase();
|
|
463
|
+
res.writeHead(200, {
|
|
464
|
+
'Content-Type': contentTypeForExt(ext),
|
|
465
|
+
'Content-Disposition': forceDownload
|
|
466
|
+
? `attachment; filename="${sanitizeDownloadFilename(requestedFilename || path.basename(realPath)).replace(/"/g, '')}"`
|
|
467
|
+
: 'inline'
|
|
468
|
+
});
|
|
469
|
+
res.end(fs.readFileSync(realPath));
|
|
470
|
+
});
|
|
471
|
+
addRoute('DELETE', '/api/taskforce/context/:filename', async (req, res, params) => {
|
|
472
|
+
const objectStorageClient = getObjectStorageClient();
|
|
473
|
+
const { basePath } = core.getPaths();
|
|
474
|
+
const decoded = decodeURIComponent(params.filename);
|
|
475
|
+
const normalizedRelative = normalizeTaskDataRelativePath(decoded);
|
|
476
|
+
if (!normalizedRelative) {
|
|
477
|
+
res.writeHead(404, { 'Content-Type': 'application/json' });
|
|
478
|
+
res.end(JSON.stringify({ error: 'File not found' }));
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
const filePath = ensureWithinDir(path.join(basePath, normalizedRelative), basePath);
|
|
482
|
+
if (!objectStorageClient && (!filePath || !fs.existsSync(filePath)) && !getAssetMetadata(normalizedRelative)) {
|
|
483
|
+
res.writeHead(404, { 'Content-Type': 'application/json' });
|
|
484
|
+
res.end(JSON.stringify({ error: 'File not found' }));
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
const metadata = markAssetDeleted(normalizedRelative);
|
|
488
|
+
appendStorageTelemetry('delete.soft', {
|
|
489
|
+
path: normalizedRelative,
|
|
490
|
+
status: 'soft-deleted',
|
|
491
|
+
provider: metadata?.provider || (objectStorageClient ? 'r2' : 'local')
|
|
492
|
+
});
|
|
493
|
+
core.notifyDocumentMetadataMutation(inferWorkspaceIdFromStoragePath(normalizedRelative) || requestWorkspaceId(req) || 'default', [normalizedRelative], 'delete');
|
|
494
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
495
|
+
res.end(JSON.stringify({
|
|
496
|
+
success: true,
|
|
497
|
+
softDeleted: true,
|
|
498
|
+
retentionDays: documentRetentionDays,
|
|
499
|
+
purgeAfter: metadata?.purgeAfter || null
|
|
500
|
+
}));
|
|
501
|
+
});
|
|
502
|
+
addRoute('GET', '/api/taskforce/context-metadata', async (req, res) => {
|
|
503
|
+
if (!ensureAdminRole(req)) {
|
|
504
|
+
res.writeHead(403, { 'Content-Type': 'application/json' });
|
|
505
|
+
res.end(JSON.stringify({ error: 'Forbidden: admin role required.' }));
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
const url = new URL(req.url || '', 'http://localhost');
|
|
509
|
+
const normalizedPath = normalizeDocumentPathInput(url.searchParams.get('path'));
|
|
510
|
+
if (!normalizedPath) {
|
|
511
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
512
|
+
res.end(JSON.stringify({ error: 'path query parameter is required' }));
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
const metadata = getAssetMetadata(normalizedPath);
|
|
516
|
+
const canonicalAsset = getCanonicalAssetMetadata(normalizedPath);
|
|
517
|
+
if (!metadata) {
|
|
518
|
+
res.writeHead(404, { 'Content-Type': 'application/json' });
|
|
519
|
+
res.end(JSON.stringify({ error: 'Metadata not found' }));
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
522
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
523
|
+
res.end(JSON.stringify({
|
|
524
|
+
path: normalizedPath,
|
|
525
|
+
metadata,
|
|
526
|
+
...(canonicalAsset ? { canonicalAsset } : {}),
|
|
527
|
+
retentionDays: documentRetentionDays
|
|
528
|
+
}));
|
|
529
|
+
});
|
|
530
|
+
addRoute('POST', '/api/taskforce/context/purge-expired', async (req, res) => {
|
|
531
|
+
if (!ensureAdminRole(req)) {
|
|
532
|
+
res.writeHead(403, { 'Content-Type': 'application/json' });
|
|
533
|
+
res.end(JSON.stringify({ error: 'Forbidden: admin role required.' }));
|
|
534
|
+
return;
|
|
535
|
+
}
|
|
536
|
+
const { basePath } = core.getPaths();
|
|
537
|
+
const summary = await purgeExpiredDocuments({
|
|
538
|
+
basePath,
|
|
539
|
+
objectStorage: resolveEffectiveObjectStorageConfig(),
|
|
540
|
+
assetStore: taskAssetStore || undefined,
|
|
541
|
+
workspaceAssetStore: workspaceAssetStore || undefined
|
|
542
|
+
});
|
|
543
|
+
appendDocumentPurgeHistory(req, summary);
|
|
544
|
+
appendStorageTelemetry('purge.run', {
|
|
545
|
+
status: `purged:${summary.purged}/total:${summary.total}`,
|
|
546
|
+
provider: resolveEffectiveObjectStorageConfig().provider
|
|
547
|
+
});
|
|
548
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
549
|
+
res.end(JSON.stringify({ success: true, ...summary }));
|
|
550
|
+
});
|
|
551
|
+
addRoute('GET', '/api/taskforce/documents', async (req, res) => {
|
|
552
|
+
const workspaceId = requestWorkspaceId(req);
|
|
553
|
+
const { basePath, projectRoot } = core.getPaths();
|
|
554
|
+
const planningDocsDir = path.join(basePath, 'docs');
|
|
555
|
+
const runtimeMode = context.authConfig?.runtimeMode === 'cloud' ? 'cloud' : 'local';
|
|
556
|
+
function inferDocType(filename) {
|
|
557
|
+
const base = path.basename(filename, path.extname(filename)).toLowerCase();
|
|
558
|
+
if (base.includes('implementation-plan') || base.includes('implementation_plan'))
|
|
559
|
+
return 'implementation-plan';
|
|
560
|
+
if (base.includes('review'))
|
|
561
|
+
return 'review';
|
|
562
|
+
if (base.includes('walkthrough'))
|
|
563
|
+
return 'walkthrough';
|
|
564
|
+
return 'other';
|
|
565
|
+
}
|
|
566
|
+
function inferTitle(filename, assetId) {
|
|
567
|
+
return getReadableDocumentName({
|
|
568
|
+
assetId,
|
|
569
|
+
originalFilename: filename,
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
function normalizeDocumentRecord(input) {
|
|
573
|
+
const normalizedPath = normalizeTaskDataRelativePath(input.fsPath) || input.fsPath;
|
|
574
|
+
const fallbackFilename = path.basename(normalizedPath);
|
|
575
|
+
const inferredTitle = inferTitle(fallbackFilename, input.assetId || null) || fallbackFilename || 'Untitled document';
|
|
576
|
+
const originalFilename = String(input.originalFilename || '').trim() || fallbackFilename || null;
|
|
577
|
+
const displayName = getCanonicalDocumentName({
|
|
578
|
+
logicalName: String(input.displayName || '').trim() || null,
|
|
579
|
+
title: String(input.title || '').trim() || null,
|
|
580
|
+
originalFilename,
|
|
581
|
+
fsPath: normalizedPath,
|
|
582
|
+
assetId: input.assetId || null,
|
|
583
|
+
}) || inferredTitle;
|
|
584
|
+
const title = String(input.title || '').trim()
|
|
585
|
+
|| displayName
|
|
586
|
+
|| inferredTitle;
|
|
587
|
+
const taskId = String(input.taskId || '').trim() || null;
|
|
588
|
+
const attachmentCount = typeof input.attachmentCount === 'number' && Number.isFinite(input.attachmentCount)
|
|
589
|
+
? Math.max(0, Math.floor(input.attachmentCount))
|
|
590
|
+
: (taskId ? 1 : 0);
|
|
591
|
+
const attachmentState = input.attachmentState === 'attached'
|
|
592
|
+
|| input.attachmentState === 'unattached'
|
|
593
|
+
|| input.attachmentState === 'standalone'
|
|
594
|
+
? (attachmentCount > 0 || taskId
|
|
595
|
+
? 'attached'
|
|
596
|
+
: input.attachmentState === 'standalone'
|
|
597
|
+
? 'standalone'
|
|
598
|
+
: 'unattached')
|
|
599
|
+
: (attachmentCount > 0 || taskId ? 'attached' : 'unattached');
|
|
600
|
+
return {
|
|
601
|
+
id: input.id,
|
|
602
|
+
assetId: input.assetId || null,
|
|
603
|
+
referenceNumber: typeof input.referenceNumber === 'number' && Number.isFinite(input.referenceNumber)
|
|
604
|
+
? Math.max(1, Math.floor(input.referenceNumber))
|
|
605
|
+
: null,
|
|
606
|
+
referenceLabel: String(input.referenceLabel || '').trim() || null,
|
|
607
|
+
fsPath: normalizedPath,
|
|
608
|
+
apiUrl: input.apiUrl,
|
|
609
|
+
taskId,
|
|
610
|
+
displayName,
|
|
611
|
+
originalFilename,
|
|
612
|
+
title,
|
|
613
|
+
docType: input.docType,
|
|
614
|
+
sizeBytes: typeof input.sizeBytes === 'number' && Number.isFinite(input.sizeBytes) ? Math.max(0, input.sizeBytes) : 0,
|
|
615
|
+
updatedAt: input.updatedAt || null,
|
|
616
|
+
editable: input.editable !== false,
|
|
617
|
+
attachmentCount,
|
|
618
|
+
attachmentState
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
function safeRelative(fullPath) {
|
|
622
|
+
const rel = path.relative(projectRoot, fullPath);
|
|
623
|
+
if (rel.startsWith('..'))
|
|
624
|
+
return null;
|
|
625
|
+
return rel;
|
|
626
|
+
}
|
|
627
|
+
const documents = [];
|
|
628
|
+
const seenDocumentPaths = new Set();
|
|
629
|
+
const pushDocument = (doc) => {
|
|
630
|
+
const normalizedDoc = normalizeDocumentRecord(doc);
|
|
631
|
+
const key = normalizeTaskDataRelativePath(normalizedDoc.fsPath) || normalizedDoc.fsPath;
|
|
632
|
+
if (seenDocumentPaths.has(key))
|
|
633
|
+
return;
|
|
634
|
+
seenDocumentPaths.add(key);
|
|
635
|
+
documents.push(normalizedDoc);
|
|
636
|
+
};
|
|
637
|
+
const canonicalDocuments = workspaceAssetStore?.listAllByWorkspace(workspaceId, {
|
|
638
|
+
includeDeleted: false,
|
|
639
|
+
kind: 'document'
|
|
640
|
+
}) || [];
|
|
641
|
+
for (const asset of canonicalDocuments) {
|
|
642
|
+
const filename = asset.originalFilename || path.basename(asset.storageKey);
|
|
643
|
+
const repairedReadableName = getCanonicalDocumentName({
|
|
644
|
+
logicalName: asset.logicalName || null,
|
|
645
|
+
displayName: null,
|
|
646
|
+
originalFilename: asset.originalFilename || filename,
|
|
647
|
+
fsPath: asset.storageKey,
|
|
648
|
+
assetId: asset.assetId || null,
|
|
649
|
+
});
|
|
650
|
+
const activeLinks = (workspaceAssetStore?.listLinksForAsset(asset.assetId, workspaceId) || [])
|
|
651
|
+
.filter((link) => !link.deletedAt)
|
|
652
|
+
.filter((link) => !!core.getTask(link.taskId, workspaceId));
|
|
653
|
+
const firstLink = activeLinks[0] || null;
|
|
654
|
+
const repairedLogicalName = isGeneratedDocumentName(asset.logicalName || null, asset.assetId || null)
|
|
655
|
+
? (String(firstLink?.displayName || '').trim()
|
|
656
|
+
|| repairedReadableName)
|
|
657
|
+
: null;
|
|
658
|
+
if (repairedLogicalName && repairedLogicalName !== asset.logicalName) {
|
|
659
|
+
workspaceAssetStore?.upsertAsset({
|
|
660
|
+
assetId: asset.assetId,
|
|
661
|
+
workspaceId: asset.workspaceId,
|
|
662
|
+
kind: asset.kind,
|
|
663
|
+
logicalName: repairedLogicalName,
|
|
664
|
+
originalFilename: asset.originalFilename,
|
|
665
|
+
mimeType: asset.mimeType,
|
|
666
|
+
storageProvider: asset.storageProvider,
|
|
667
|
+
storageKey: asset.storageKey,
|
|
668
|
+
contentSha256: asset.contentSha256,
|
|
669
|
+
sizeBytes: asset.sizeBytes,
|
|
670
|
+
documentId: asset.documentId,
|
|
671
|
+
version: asset.version,
|
|
672
|
+
isLatest: asset.isLatest,
|
|
673
|
+
scanStatus: asset.scanStatus,
|
|
674
|
+
scanEngine: asset.scanEngine,
|
|
675
|
+
scanDetails: asset.scanDetails,
|
|
676
|
+
createdByUserId: asset.createdByUserId,
|
|
677
|
+
createdAt: asset.createdAt,
|
|
678
|
+
updatedAt: asset.updatedAt || new Date().toISOString(),
|
|
679
|
+
deletedAt: asset.deletedAt,
|
|
680
|
+
purgeAfter: asset.purgeAfter
|
|
681
|
+
});
|
|
682
|
+
}
|
|
683
|
+
const readableName = repairedLogicalName || repairedReadableName;
|
|
684
|
+
pushDocument({
|
|
685
|
+
id: asset.assetId || asset.storageKey,
|
|
686
|
+
assetId: asset.assetId || null,
|
|
687
|
+
referenceNumber: asset.referenceNumber,
|
|
688
|
+
referenceLabel: asset.referenceNumber ? `D-${asset.referenceNumber}` : null,
|
|
689
|
+
fsPath: asset.storageKey,
|
|
690
|
+
apiUrl: asset.assetId
|
|
691
|
+
? `/api/taskforce/documents/${encodeURIComponent(asset.assetId)}/content`
|
|
692
|
+
: `/api/taskforce/context/${encodeURIComponent(asset.storageKey)}`,
|
|
693
|
+
taskId: firstLink?.taskId || inferTaskIdFromStoragePath(asset.storageKey),
|
|
694
|
+
displayName: readableName,
|
|
695
|
+
originalFilename: asset.originalFilename || null,
|
|
696
|
+
title: readableName,
|
|
697
|
+
docType: inferDocType(filename),
|
|
698
|
+
sizeBytes: asset.sizeBytes ?? 0,
|
|
699
|
+
updatedAt: asset.updatedAt || null,
|
|
700
|
+
editable: true,
|
|
701
|
+
attachmentCount: activeLinks.length,
|
|
702
|
+
attachmentState: activeLinks.length > 0 ? 'attached' : 'unattached',
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
if (runtimeMode !== 'cloud') {
|
|
706
|
+
const walkMarkdownFiles = (dir, visitor) => {
|
|
707
|
+
let entries = [];
|
|
708
|
+
try {
|
|
709
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
710
|
+
}
|
|
711
|
+
catch {
|
|
712
|
+
return;
|
|
713
|
+
}
|
|
714
|
+
for (const entry of entries) {
|
|
715
|
+
const fullPath = path.join(dir, entry.name);
|
|
716
|
+
if (entry.isDirectory()) {
|
|
717
|
+
walkMarkdownFiles(fullPath, visitor);
|
|
718
|
+
continue;
|
|
719
|
+
}
|
|
720
|
+
if (!entry.isFile() || path.extname(entry.name).toLowerCase() !== '.md') {
|
|
721
|
+
continue;
|
|
722
|
+
}
|
|
723
|
+
let stat;
|
|
724
|
+
try {
|
|
725
|
+
stat = fs.statSync(fullPath);
|
|
726
|
+
}
|
|
727
|
+
catch {
|
|
728
|
+
continue;
|
|
729
|
+
}
|
|
730
|
+
const relativePath = safeRelative(fullPath);
|
|
731
|
+
if (!relativePath)
|
|
732
|
+
continue;
|
|
733
|
+
visitor({ relativePath, entryName: entry.name, stat });
|
|
734
|
+
}
|
|
735
|
+
};
|
|
736
|
+
walkMarkdownFiles(planningDocsDir, ({ relativePath, entryName, stat }) => {
|
|
737
|
+
pushDocument({
|
|
738
|
+
id: relativePath,
|
|
739
|
+
assetId: null,
|
|
740
|
+
referenceNumber: null,
|
|
741
|
+
referenceLabel: null,
|
|
742
|
+
fsPath: relativePath,
|
|
743
|
+
apiUrl: `/api/taskforce/context-link?path=${encodeURIComponent(relativePath)}`,
|
|
744
|
+
taskId: null,
|
|
745
|
+
displayName: inferTitle(entryName),
|
|
746
|
+
originalFilename: entryName,
|
|
747
|
+
title: inferTitle(entryName),
|
|
748
|
+
docType: 'planning',
|
|
749
|
+
sizeBytes: stat.size,
|
|
750
|
+
updatedAt: stat.mtime.toISOString(),
|
|
751
|
+
editable: true,
|
|
752
|
+
attachmentCount: 0,
|
|
753
|
+
attachmentState: 'standalone',
|
|
754
|
+
});
|
|
755
|
+
});
|
|
756
|
+
}
|
|
757
|
+
documents.sort((a, b) => {
|
|
758
|
+
if (!a.updatedAt && !b.updatedAt)
|
|
759
|
+
return 0;
|
|
760
|
+
if (!a.updatedAt)
|
|
761
|
+
return 1;
|
|
762
|
+
if (!b.updatedAt)
|
|
763
|
+
return -1;
|
|
764
|
+
return b.updatedAt.localeCompare(a.updatedAt);
|
|
765
|
+
});
|
|
766
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
767
|
+
res.end(JSON.stringify({ documents }));
|
|
768
|
+
});
|
|
769
|
+
addRoute('DELETE', '/api/taskforce/documents/:assetId', async (req, res, params) => {
|
|
770
|
+
const workspaceId = requestWorkspaceId(req);
|
|
771
|
+
const assetId = String(params.assetId || '').trim();
|
|
772
|
+
if (!workspaceAssetStore || !assetId) {
|
|
773
|
+
res.writeHead(404, { 'Content-Type': 'application/json' });
|
|
774
|
+
res.end(JSON.stringify({ error: 'Document not found' }));
|
|
775
|
+
return;
|
|
776
|
+
}
|
|
777
|
+
const asset = workspaceAssetStore.get(assetId, workspaceId);
|
|
778
|
+
if (!asset || asset.kind !== 'document' || asset.deletedAt) {
|
|
779
|
+
res.writeHead(404, { 'Content-Type': 'application/json' });
|
|
780
|
+
res.end(JSON.stringify({ error: 'Document not found' }));
|
|
781
|
+
return;
|
|
782
|
+
}
|
|
783
|
+
const activeLinks = workspaceAssetStore.listLinksForAsset(asset.assetId, workspaceId)
|
|
784
|
+
.filter((link) => !link.deletedAt)
|
|
785
|
+
.filter((link) => !!core.getTask(link.taskId, workspaceId));
|
|
786
|
+
if (activeLinks.length > 0) {
|
|
787
|
+
res.writeHead(409, { 'Content-Type': 'application/json' });
|
|
788
|
+
res.end(JSON.stringify({ error: 'Document is still attached to one or more tasks.' }));
|
|
789
|
+
return;
|
|
790
|
+
}
|
|
791
|
+
const nowIso = new Date().toISOString();
|
|
792
|
+
const purgeAfter = new Date(Date.now() + documentRetentionDays * 24 * 60 * 60 * 1000).toISOString();
|
|
793
|
+
const metadata = markAssetDeleted(asset.storageKey);
|
|
794
|
+
workspaceAssetStore.markDeleted(asset.assetId, workspaceId, nowIso, purgeAfter);
|
|
795
|
+
appendStorageTelemetry('delete.soft', {
|
|
796
|
+
path: asset.storageKey,
|
|
797
|
+
status: 'soft-deleted',
|
|
798
|
+
provider: asset.storageProvider
|
|
799
|
+
});
|
|
800
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
801
|
+
res.end(JSON.stringify({
|
|
802
|
+
success: true,
|
|
803
|
+
softDeleted: true,
|
|
804
|
+
retentionDays: documentRetentionDays,
|
|
805
|
+
purgeAfter: metadata?.purgeAfter || purgeAfter
|
|
806
|
+
}));
|
|
807
|
+
});
|
|
808
|
+
addRoute('PATCH', '/api/taskforce/documents/:assetId', async (req, res, params) => {
|
|
809
|
+
const workspaceId = requestWorkspaceId(req);
|
|
810
|
+
const assetId = String(params.assetId || '').trim();
|
|
811
|
+
const body = await parseJsonBody(req);
|
|
812
|
+
const displayName = String(body?.displayName || '').trim();
|
|
813
|
+
if (!workspaceAssetStore || !assetId) {
|
|
814
|
+
res.writeHead(404, { 'Content-Type': 'application/json' });
|
|
815
|
+
res.end(JSON.stringify({ error: 'Document not found' }));
|
|
816
|
+
return;
|
|
817
|
+
}
|
|
818
|
+
if (!displayName) {
|
|
819
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
820
|
+
res.end(JSON.stringify({ error: 'displayName is required' }));
|
|
821
|
+
return;
|
|
822
|
+
}
|
|
823
|
+
const asset = workspaceAssetStore.get(assetId, workspaceId);
|
|
824
|
+
if (!asset || asset.kind !== 'document' || asset.deletedAt) {
|
|
825
|
+
res.writeHead(404, { 'Content-Type': 'application/json' });
|
|
826
|
+
res.end(JSON.stringify({ error: 'Document not found' }));
|
|
827
|
+
return;
|
|
828
|
+
}
|
|
829
|
+
const updatedAt = new Date().toISOString();
|
|
830
|
+
const updated = workspaceAssetStore.upsertAsset({
|
|
831
|
+
assetId: asset.assetId,
|
|
832
|
+
workspaceId,
|
|
833
|
+
kind: asset.kind,
|
|
834
|
+
logicalName: displayName,
|
|
835
|
+
originalFilename: asset.originalFilename,
|
|
836
|
+
mimeType: asset.mimeType,
|
|
837
|
+
storageProvider: asset.storageProvider,
|
|
838
|
+
storageKey: asset.storageKey,
|
|
839
|
+
contentSha256: asset.contentSha256,
|
|
840
|
+
sizeBytes: asset.sizeBytes,
|
|
841
|
+
documentId: asset.documentId,
|
|
842
|
+
version: asset.version,
|
|
843
|
+
isLatest: asset.isLatest,
|
|
844
|
+
scanStatus: asset.scanStatus,
|
|
845
|
+
scanEngine: asset.scanEngine,
|
|
846
|
+
scanDetails: asset.scanDetails,
|
|
847
|
+
createdByUserId: asset.createdByUserId,
|
|
848
|
+
createdAt: asset.createdAt,
|
|
849
|
+
updatedAt,
|
|
850
|
+
deletedAt: null,
|
|
851
|
+
purgeAfter: asset.purgeAfter
|
|
852
|
+
});
|
|
853
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
854
|
+
res.end(JSON.stringify({ success: true, assetId: updated.assetId, displayName: updated.logicalName, updatedAt }));
|
|
855
|
+
});
|
|
856
|
+
addRoute('POST', '/api/taskforce/documents/save', async (req, res) => {
|
|
857
|
+
const workspaceId = requestWorkspaceId(req);
|
|
858
|
+
const { projectRoot, basePath } = core.getPaths();
|
|
859
|
+
const objectStorageClient = getObjectStorageClient();
|
|
860
|
+
const MAX_BODY_BYTES = 1_048_576;
|
|
861
|
+
let body = '';
|
|
862
|
+
let bodyBytes = 0;
|
|
863
|
+
let tooLarge = false;
|
|
864
|
+
await new Promise((resolve) => {
|
|
865
|
+
req.on('data', (chunk) => {
|
|
866
|
+
bodyBytes += chunk.length;
|
|
867
|
+
if (bodyBytes > MAX_BODY_BYTES) {
|
|
868
|
+
tooLarge = true;
|
|
869
|
+
resolve();
|
|
870
|
+
return;
|
|
871
|
+
}
|
|
872
|
+
body += chunk.toString();
|
|
873
|
+
});
|
|
874
|
+
req.on('end', () => resolve());
|
|
875
|
+
});
|
|
876
|
+
if (tooLarge) {
|
|
877
|
+
res.writeHead(413, { 'Content-Type': 'application/json' });
|
|
878
|
+
res.end(JSON.stringify({ error: 'Document exceeds maximum size of 1 MB' }));
|
|
879
|
+
return;
|
|
880
|
+
}
|
|
881
|
+
let fsPath;
|
|
882
|
+
let content;
|
|
883
|
+
try {
|
|
884
|
+
const parsed = JSON.parse(body);
|
|
885
|
+
fsPath = String(parsed.fsPath || '').trim();
|
|
886
|
+
content = typeof parsed.content === 'string' ? parsed.content : '';
|
|
887
|
+
}
|
|
888
|
+
catch {
|
|
889
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
890
|
+
res.end(JSON.stringify({ error: 'Invalid JSON body' }));
|
|
891
|
+
return;
|
|
892
|
+
}
|
|
893
|
+
if (!fsPath) {
|
|
894
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
895
|
+
res.end(JSON.stringify({ error: 'fsPath is required' }));
|
|
896
|
+
return;
|
|
897
|
+
}
|
|
898
|
+
const normalizedStoragePath = normalizeTaskDataRelativePath(fsPath.replace(/^\.taskforce[\\/]+/, '').replace(/\\/g, '/'));
|
|
899
|
+
if (normalizedStoragePath) {
|
|
900
|
+
const metadata = getAssetMetadata(normalizedStoragePath);
|
|
901
|
+
if (metadata?.quarantineStatus === 'quarantined') {
|
|
902
|
+
res.writeHead(423, { 'Content-Type': 'application/json' });
|
|
903
|
+
res.end(JSON.stringify({ error: 'Document is quarantined and cannot be edited.' }));
|
|
904
|
+
return;
|
|
905
|
+
}
|
|
906
|
+
if (metadata?.deletedAt || isAssetDeleted(normalizedStoragePath)) {
|
|
907
|
+
res.writeHead(404, { 'Content-Type': 'application/json' });
|
|
908
|
+
res.end(JSON.stringify({ error: 'Document not found' }));
|
|
909
|
+
return;
|
|
910
|
+
}
|
|
911
|
+
if (objectStorageClient && metadata?.provider === 'r2') {
|
|
912
|
+
const requestWorkspace = requestWorkspaceId(req);
|
|
913
|
+
const assetWorkspaceId = String(metadata.workspaceId || inferWorkspaceIdFromStoragePath(normalizedStoragePath) || 'default').trim() || 'default';
|
|
914
|
+
if (requestWorkspace !== assetWorkspaceId) {
|
|
915
|
+
res.writeHead(403, { 'Content-Type': 'application/json' });
|
|
916
|
+
res.end(JSON.stringify({ error: 'Document belongs to a different workspace.' }));
|
|
917
|
+
return;
|
|
918
|
+
}
|
|
919
|
+
try {
|
|
920
|
+
const buffer = Buffer.from(content, 'utf8');
|
|
921
|
+
await objectStorageClient.putObject(normalizedStoragePath, buffer, 'text/markdown; charset=utf-8');
|
|
922
|
+
await scanAndRecordDocument({
|
|
923
|
+
relativeToStorage: normalizedStoragePath,
|
|
924
|
+
buffer,
|
|
925
|
+
contentType: 'text/markdown; charset=utf-8',
|
|
926
|
+
provider: 'r2',
|
|
927
|
+
workspaceId: assetWorkspaceId,
|
|
928
|
+
originalName: metadata.logicalName || metadata.originalFilename || path.basename(normalizedStoragePath)
|
|
929
|
+
});
|
|
930
|
+
clearAssetDeleted(normalizedStoragePath);
|
|
931
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
932
|
+
res.end(JSON.stringify({ success: true, updatedAt: new Date().toISOString() }));
|
|
933
|
+
return;
|
|
934
|
+
}
|
|
935
|
+
catch (e) {
|
|
936
|
+
res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
937
|
+
res.end(JSON.stringify({ error: e?.message || 'Failed to write cloud document' }));
|
|
938
|
+
return;
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
if (fsPath.includes('..') || fsPath.includes('\0')) {
|
|
943
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
944
|
+
res.end(JSON.stringify({ error: 'Invalid path' }));
|
|
945
|
+
return;
|
|
946
|
+
}
|
|
947
|
+
const storageRelativeLocalPath = normalizedStoragePath
|
|
948
|
+
? ensureWithinDir(path.join(basePath, normalizedStoragePath), basePath)
|
|
949
|
+
: null;
|
|
950
|
+
const resolvedPath = path.isAbsolute(fsPath)
|
|
951
|
+
? path.resolve(fsPath)
|
|
952
|
+
: storageRelativeLocalPath || path.resolve(projectRoot, fsPath);
|
|
953
|
+
const realPath = fs.existsSync(resolvedPath) ? fs.realpathSync(resolvedPath) : resolvedPath;
|
|
954
|
+
if (!realPath.startsWith(projectRoot)) {
|
|
955
|
+
res.writeHead(403, { 'Content-Type': 'application/json' });
|
|
956
|
+
res.end(JSON.stringify({ error: 'File must be within project root' }));
|
|
957
|
+
return;
|
|
958
|
+
}
|
|
959
|
+
if (path.extname(realPath).toLowerCase() !== '.md') {
|
|
960
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
961
|
+
res.end(JSON.stringify({ error: 'Only .md files may be saved via this endpoint' }));
|
|
962
|
+
return;
|
|
963
|
+
}
|
|
964
|
+
if (!fs.existsSync(realPath) || !fs.statSync(realPath).isFile()) {
|
|
965
|
+
res.writeHead(404, { 'Content-Type': 'application/json' });
|
|
966
|
+
res.end(JSON.stringify({ error: 'File not found' }));
|
|
967
|
+
return;
|
|
968
|
+
}
|
|
969
|
+
try {
|
|
970
|
+
fs.writeFileSync(realPath, content, 'utf-8');
|
|
971
|
+
const updatedAt = fs.statSync(realPath).mtime.toISOString();
|
|
972
|
+
if (normalizedStoragePath) {
|
|
973
|
+
await scanAndRecordDocument({
|
|
974
|
+
relativeToStorage: normalizedStoragePath,
|
|
975
|
+
buffer: Buffer.from(content, 'utf8'),
|
|
976
|
+
contentType: 'text/markdown; charset=utf-8',
|
|
977
|
+
provider: 'local',
|
|
978
|
+
workspaceId: workspaceId || inferWorkspaceIdFromStoragePath(normalizedStoragePath),
|
|
979
|
+
originalName: path.basename(normalizedStoragePath)
|
|
980
|
+
});
|
|
981
|
+
clearAssetDeleted(normalizedStoragePath);
|
|
982
|
+
}
|
|
983
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
984
|
+
res.end(JSON.stringify({ success: true, updatedAt }));
|
|
985
|
+
}
|
|
986
|
+
catch (e) {
|
|
987
|
+
res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
988
|
+
res.end(JSON.stringify({ error: e?.message || 'Failed to write file' }));
|
|
989
|
+
}
|
|
990
|
+
});
|
|
991
|
+
addRoute('POST', '/api/taskforce/documents/generate-tasks/preview', async (req, res) => {
|
|
992
|
+
const MAX_PREVIEW_BYTES = 524_288;
|
|
993
|
+
let body = '';
|
|
994
|
+
let bodyBytes = 0;
|
|
995
|
+
let tooLarge = false;
|
|
996
|
+
await new Promise((resolve) => {
|
|
997
|
+
req.on('data', (chunk) => {
|
|
998
|
+
bodyBytes += chunk.length;
|
|
999
|
+
if (bodyBytes > MAX_PREVIEW_BYTES) {
|
|
1000
|
+
tooLarge = true;
|
|
1001
|
+
resolve();
|
|
1002
|
+
return;
|
|
1003
|
+
}
|
|
1004
|
+
body += chunk.toString();
|
|
1005
|
+
});
|
|
1006
|
+
req.on('end', () => resolve());
|
|
1007
|
+
});
|
|
1008
|
+
if (tooLarge) {
|
|
1009
|
+
res.writeHead(413, { 'Content-Type': 'application/json' });
|
|
1010
|
+
res.end(JSON.stringify({ error: 'Content exceeds maximum preview size of 512 KB' }));
|
|
1011
|
+
return;
|
|
1012
|
+
}
|
|
1013
|
+
let content;
|
|
1014
|
+
try {
|
|
1015
|
+
const parsed = JSON.parse(body);
|
|
1016
|
+
content = typeof parsed.content === 'string' ? parsed.content : '';
|
|
1017
|
+
}
|
|
1018
|
+
catch {
|
|
1019
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
1020
|
+
res.end(JSON.stringify({ error: 'Invalid JSON body' }));
|
|
1021
|
+
return;
|
|
1022
|
+
}
|
|
1023
|
+
if (!content.trim()) {
|
|
1024
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
1025
|
+
res.end(JSON.stringify({ error: 'content is required' }));
|
|
1026
|
+
return;
|
|
1027
|
+
}
|
|
1028
|
+
const tasks = parsePlan(content);
|
|
1029
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
1030
|
+
res.end(JSON.stringify({ tasks }));
|
|
1031
|
+
});
|
|
1032
|
+
addRoute('POST', '/api/taskforce/documents/generate-tasks/commit', async (req, res) => {
|
|
1033
|
+
const workspaceId = requestWorkspaceId(req);
|
|
1034
|
+
const MAX_COMMIT_BYTES = 524_288;
|
|
1035
|
+
const MAX_TASKS = 200;
|
|
1036
|
+
const MAX_TITLE_LENGTH = 200;
|
|
1037
|
+
const MAX_DEPTH = 4;
|
|
1038
|
+
let body = '';
|
|
1039
|
+
let bodyBytes = 0;
|
|
1040
|
+
let tooLarge = false;
|
|
1041
|
+
await new Promise((resolve) => {
|
|
1042
|
+
req.on('data', (chunk) => {
|
|
1043
|
+
bodyBytes += chunk.length;
|
|
1044
|
+
if (bodyBytes > MAX_COMMIT_BYTES) {
|
|
1045
|
+
tooLarge = true;
|
|
1046
|
+
resolve();
|
|
1047
|
+
return;
|
|
1048
|
+
}
|
|
1049
|
+
body += chunk.toString();
|
|
1050
|
+
});
|
|
1051
|
+
req.on('end', () => resolve());
|
|
1052
|
+
});
|
|
1053
|
+
if (tooLarge) {
|
|
1054
|
+
res.writeHead(413, { 'Content-Type': 'application/json' });
|
|
1055
|
+
res.end(JSON.stringify({ error: 'Request body too large' }));
|
|
1056
|
+
return;
|
|
1057
|
+
}
|
|
1058
|
+
let tasks;
|
|
1059
|
+
try {
|
|
1060
|
+
const parsed = JSON.parse(body);
|
|
1061
|
+
tasks = Array.isArray(parsed.tasks) ? parsed.tasks : [];
|
|
1062
|
+
}
|
|
1063
|
+
catch {
|
|
1064
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
1065
|
+
res.end(JSON.stringify({ error: 'Invalid JSON body' }));
|
|
1066
|
+
return;
|
|
1067
|
+
}
|
|
1068
|
+
if (tasks.length === 0) {
|
|
1069
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
1070
|
+
res.end(JSON.stringify({ error: 'No tasks provided' }));
|
|
1071
|
+
return;
|
|
1072
|
+
}
|
|
1073
|
+
function sanitiseTitle(raw) {
|
|
1074
|
+
return String(raw || '')
|
|
1075
|
+
.replace(/<[^>]*>/g, '')
|
|
1076
|
+
.replace(/[\x00-\x1F\x7F]/g, ' ')
|
|
1077
|
+
.trim()
|
|
1078
|
+
.slice(0, MAX_TITLE_LENGTH) || 'Untitled task';
|
|
1079
|
+
}
|
|
1080
|
+
const created = [];
|
|
1081
|
+
let totalCreated = 0;
|
|
1082
|
+
function createSelectedTasks(nodes, depth) {
|
|
1083
|
+
if (depth > MAX_DEPTH)
|
|
1084
|
+
return;
|
|
1085
|
+
for (const node of nodes) {
|
|
1086
|
+
if (Array.isArray(node.children) && node.children.length > 0) {
|
|
1087
|
+
createSelectedTasks(node.children, depth + 1);
|
|
1088
|
+
}
|
|
1089
|
+
if (!node.selected)
|
|
1090
|
+
continue;
|
|
1091
|
+
if (totalCreated >= MAX_TASKS)
|
|
1092
|
+
break;
|
|
1093
|
+
try {
|
|
1094
|
+
const taskItem = core.createTask({
|
|
1095
|
+
title: sanitiseTitle(node.title),
|
|
1096
|
+
description: String(node.description || '').slice(0, 2000).trim() || undefined,
|
|
1097
|
+
type: node.type || 'feature',
|
|
1098
|
+
priority: typeof node.priority === 'number' ? node.priority : 2,
|
|
1099
|
+
status: 'task',
|
|
1100
|
+
}, { workspaceId });
|
|
1101
|
+
created.push(taskItem.id);
|
|
1102
|
+
totalCreated++;
|
|
1103
|
+
}
|
|
1104
|
+
catch {
|
|
1105
|
+
// Skip individual failures and return a partial success summary.
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
createSelectedTasks(tasks, 0);
|
|
1110
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
1111
|
+
res.end(JSON.stringify({ created: created.length, taskIds: created }));
|
|
1112
|
+
});
|
|
1113
|
+
}
|