@straiffi/archon 1.11.14 → 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/assets/{ActivityView-CXlLfbio.js → ActivityView-jw3H-NeG.js} +1 -1
- package/dist/client/assets/{GitHubActionsDialog-COncogiu.js → GitHubActionsDialog-cUxcoLqx.js} +1 -1
- package/dist/client/assets/VerificationDialog-DP8d6ddQ.js +4 -0
- package/dist/client/assets/{architectureDiagram-3BPJPVTR-BgpjZv9J.js → architectureDiagram-3BPJPVTR-BhWOZPeu.js} +1 -1
- package/dist/client/assets/{blockDiagram-GPEHLZMM-DZOzPj8L.js → blockDiagram-GPEHLZMM-BJjjnCa4.js} +1 -1
- package/dist/client/assets/{c4Diagram-AAUBKEIU-CH8w_-4O.js → c4Diagram-AAUBKEIU-CQldjeAF.js} +1 -1
- package/dist/client/assets/channel-2Q4_MKqQ.js +1 -0
- package/dist/client/assets/{chunk-2J33WTMH-BhCJUMWk.js → chunk-2J33WTMH-D3ULHOwT.js} +1 -1
- package/dist/client/assets/{chunk-3OPIFGDE-B4ljJWcN.js → chunk-3OPIFGDE-zDE6O-L_.js} +1 -1
- package/dist/client/assets/{chunk-5ZQYHXKU-BokkrzzD.js → chunk-5ZQYHXKU-C7W7qahQ.js} +1 -1
- package/dist/client/assets/{chunk-727SXJPM-V-Kd95sz.js → chunk-727SXJPM-ChrtCiX1.js} +1 -1
- package/dist/client/assets/{chunk-AQP2D5EJ-D7ZyW65i.js → chunk-AQP2D5EJ-BJcMYTJ-.js} +1 -1
- package/dist/client/assets/{chunk-CSCIHK7Q-3cPiGWR4.js → chunk-CSCIHK7Q-uFhZVkuh.js} +1 -1
- package/dist/client/assets/{chunk-KSCS5N6A-fh-t3Kan.js → chunk-KSCS5N6A-DNE-cIoY.js} +1 -1
- package/dist/client/assets/{chunk-L5ZTLDWV-Bz_XmsGr.js → chunk-L5ZTLDWV-B1hsOai3.js} +1 -1
- package/dist/client/assets/{chunk-LZXEDZCA-DUQIbmfo.js → chunk-LZXEDZCA-BFcJgF2j.js} +2 -2
- package/dist/client/assets/{chunk-ND2GUHAM-BeaXA2cA.js → chunk-ND2GUHAM-oXJD3VO7.js} +1 -1
- package/dist/client/assets/{chunk-NZK2D7GU-Cljr0eIp.js → chunk-NZK2D7GU-DRK-yrm5.js} +1 -1
- package/dist/client/assets/{chunk-O5CBEL6O-BSZxUONE.js → chunk-O5CBEL6O-LQ2Eqsqb.js} +1 -1
- package/dist/client/assets/{chunk-WU5MYG2G-CqeEBV6t.js → chunk-WU5MYG2G-DW1hrICF.js} +1 -1
- package/dist/client/assets/classDiagram-4FO5ZUOK-DlhYAzjF.js +1 -0
- package/dist/client/assets/classDiagram-v2-Q7XG4LA2-DZsqIDkO.js +1 -0
- package/dist/client/assets/{dagre-BM42HDAG-C684sP5O.js → dagre-BM42HDAG-DAOujANI.js} +1 -1
- package/dist/client/assets/{diagram-2AECGRRQ-Bsuw7S1w.js → diagram-2AECGRRQ-CQoEIHep.js} +1 -1
- package/dist/client/assets/{diagram-5GNKFQAL-B7TKNAIK.js → diagram-5GNKFQAL-ChV233vS.js} +1 -1
- package/dist/client/assets/{diagram-KO2AKTUF-RPOTY2uQ.js → diagram-KO2AKTUF-CIkpG_DX.js} +1 -1
- package/dist/client/assets/{diagram-LMA3HP47-Dpk6toIw.js → diagram-LMA3HP47-kxcYwQT7.js} +1 -1
- package/dist/client/assets/{diagram-OG6HWLK6-DVJDTxyc.js → diagram-OG6HWLK6-J5YY8urL.js} +1 -1
- package/dist/client/assets/{erDiagram-TEJ5UH35-BTCHMpI9.js → erDiagram-TEJ5UH35-B5WiaYY1.js} +1 -1
- package/dist/client/assets/{flowDiagram-I6XJVG4X-DJHpUHaK.js → flowDiagram-I6XJVG4X-BuQ2YOAf.js} +1 -1
- package/dist/client/assets/{ganttDiagram-6RSMTGT7-B3lqQNjh.js → ganttDiagram-6RSMTGT7-BKgtiOWd.js} +1 -1
- package/dist/client/assets/{gitGraphDiagram-PVQCEYII-kSFZuvH6.js → gitGraphDiagram-PVQCEYII-ZT89EFiT.js} +1 -1
- package/dist/client/assets/index-DTsS9gs9.css +2 -0
- package/dist/client/assets/index-X4XsGor3.js +309 -0
- package/dist/client/assets/{infoDiagram-5YYISTIA-D7rhmUR9.js → infoDiagram-5YYISTIA-gSvPZVHC.js} +1 -1
- package/dist/client/assets/{ishikawaDiagram-YF4QCWOH-CFrqWdH6.js → ishikawaDiagram-YF4QCWOH-B4t29USy.js} +1 -1
- package/dist/client/assets/{journeyDiagram-JHISSGLW-BPgPF00X.js → journeyDiagram-JHISSGLW-CVmQq2kB.js} +1 -1
- package/dist/client/assets/{kanban-definition-UN3LZRKU-BJU3LTu3.js → kanban-definition-UN3LZRKU-b5O5VKrr.js} +1 -1
- package/dist/client/assets/{line-DTRSChYM.js → line-D6RHOz5K.js} +1 -1
- package/dist/client/assets/{mermaid-parser.core-X8EDtr9G.js → mermaid-parser.core-Cwq8hOlE.js} +1 -1
- package/dist/client/assets/{mermaid.core-CQDbIF5j.js → mermaid.core-D6EV8_i4.js} +3 -3
- package/dist/client/assets/{mindmap-definition-RKZ34NQL-Bcke6M7z.js → mindmap-definition-RKZ34NQL-DivmXvOE.js} +1 -1
- package/dist/client/assets/{pieDiagram-4H26LBE5-j8xeTgqq.js → pieDiagram-4H26LBE5-Bfemol_L.js} +1 -1
- package/dist/client/assets/{quadrantDiagram-W4KKPZXB-OlvBffG8.js → quadrantDiagram-W4KKPZXB-Cas_rlHH.js} +1 -1
- package/dist/client/assets/{requirementDiagram-4Y6WPE33-DA6zNi15.js → requirementDiagram-4Y6WPE33-BM8zTE_j.js} +1 -1
- package/dist/client/assets/{sankeyDiagram-5OEKKPKP-BsS5qud8.js → sankeyDiagram-5OEKKPKP-B6mxh_XP.js} +1 -1
- package/dist/client/assets/{sequenceDiagram-3UESZ5HK-BfZ_W9Jc.js → sequenceDiagram-3UESZ5HK-CYnnYFdz.js} +1 -1
- package/dist/client/assets/{stateDiagram-AJRCARHV-C7uuqC0M.js → stateDiagram-AJRCARHV-DzYqaPIm.js} +1 -1
- package/dist/client/assets/stateDiagram-v2-BHNVJYJU-BDRmC9KJ.js +1 -0
- package/dist/client/assets/{timeline-definition-PNZ67QCA-yuywaFQ6.js → timeline-definition-PNZ67QCA-IsLLwa3b.js} +1 -1
- package/dist/client/assets/{vennDiagram-CIIHVFJN-Cxlyjlnx.js → vennDiagram-CIIHVFJN-Dq0WBBOy.js} +1 -1
- package/dist/client/assets/{wardleyDiagram-YWT4CUSO-DcJ0jJo4.js → wardleyDiagram-YWT4CUSO-DD_3WNIO.js} +1 -1
- package/dist/client/assets/{xychartDiagram-2RQKCTM6-Cia16EBC.js → xychartDiagram-2RQKCTM6-Ds-PWhnZ.js} +1 -1
- package/dist/client/index.html +2 -2
- package/dist/server/db.js +32 -14
- package/dist/server/db.js.map +1 -1
- package/dist/server/epicRoutes.js +305 -0
- package/dist/server/epicRoutes.js.map +1 -0
- package/dist/server/index.js +186 -60
- package/dist/server/index.js.map +1 -1
- package/dist/server/lib/agent.js +239 -85
- package/dist/server/lib/agent.js.map +1 -1
- package/dist/server/lib/agentProvider.js.map +1 -1
- package/dist/server/lib/agentRuns.js +64 -31
- package/dist/server/lib/agentRuns.js.map +1 -1
- package/dist/server/lib/attachments.js +10 -0
- package/dist/server/lib/attachments.js.map +1 -1
- package/dist/server/lib/automationBuildContinuation.js +14 -2
- package/dist/server/lib/automationBuildContinuation.js.map +1 -1
- package/dist/server/lib/automationCheckEvidence.js +118 -0
- package/dist/server/lib/automationCheckEvidence.js.map +1 -0
- package/dist/server/lib/automationCheckGate.js +60 -162
- package/dist/server/lib/automationCheckGate.js.map +1 -1
- package/dist/server/lib/automationProcessInterruption.js +52 -0
- package/dist/server/lib/automationProcessInterruption.js.map +1 -0
- package/dist/server/lib/automationProgression.js +2 -0
- package/dist/server/lib/automationProgression.js.map +1 -1
- package/dist/server/lib/automationProgressionPurpose.js +27 -0
- package/dist/server/lib/automationProgressionPurpose.js.map +1 -0
- package/dist/server/lib/automationReconciliation.js +46 -17
- package/dist/server/lib/automationReconciliation.js.map +1 -1
- package/dist/server/lib/buildCheckpointSuccessor.js +49 -0
- package/dist/server/lib/buildCheckpointSuccessor.js.map +1 -0
- package/dist/server/lib/buildCompletionContinuation.js +214 -19
- package/dist/server/lib/buildCompletionContinuation.js.map +1 -1
- package/dist/server/lib/buildExecutionAdmission.js +25 -4
- package/dist/server/lib/buildExecutionAdmission.js.map +1 -1
- package/dist/server/lib/buildExecutionLineage.js +50 -0
- package/dist/server/lib/buildExecutionLineage.js.map +1 -0
- package/dist/server/lib/buildFlow.js +13 -0
- package/dist/server/lib/buildFlow.js.map +1 -1
- package/dist/server/lib/buildSequenceCheckpointOwnership.js +34 -0
- package/dist/server/lib/buildSequenceCheckpointOwnership.js.map +1 -0
- package/dist/server/lib/buildSequences.js +18 -1
- package/dist/server/lib/buildSequences.js.map +1 -1
- package/dist/server/lib/buildTicketCheckpointEligibility.js +6 -0
- package/dist/server/lib/buildTicketCheckpointEligibility.js.map +1 -0
- package/dist/server/lib/buildTicketCommit.js +87 -8
- package/dist/server/lib/buildTicketCommit.js.map +1 -1
- package/dist/server/lib/bundleBuildRecovery.js +18 -4
- package/dist/server/lib/bundleBuildRecovery.js.map +1 -1
- package/dist/server/lib/bundleDeletion.js +11 -0
- package/dist/server/lib/bundleDeletion.js.map +1 -1
- package/dist/server/lib/chatOperations.js +7 -0
- package/dist/server/lib/chatOperations.js.map +1 -1
- package/dist/server/lib/chatTurnPurpose.js +15 -0
- package/dist/server/lib/chatTurnPurpose.js.map +1 -0
- package/dist/server/lib/checkAttemptAdmission.js +27 -0
- package/dist/server/lib/checkAttemptAdmission.js.map +1 -0
- package/dist/server/lib/checkAutoFix.js +46 -14
- package/dist/server/lib/checkAutoFix.js.map +1 -1
- package/dist/server/lib/checkAutoFixStepPolicy.js +32 -0
- package/dist/server/lib/checkAutoFixStepPolicy.js.map +1 -0
- package/dist/server/lib/checkRepair.js +31 -14
- package/dist/server/lib/checkRepair.js.map +1 -1
- package/dist/server/lib/checkRepairStepPolicy.js +23 -0
- package/dist/server/lib/checkRepairStepPolicy.js.map +1 -0
- package/dist/server/lib/checkRunner.js +57 -32
- package/dist/server/lib/checkRunner.js.map +1 -1
- package/dist/server/lib/conversationResume.js +22 -0
- package/dist/server/lib/conversationResume.js.map +1 -1
- package/dist/server/lib/epicAdmission.js +173 -0
- package/dist/server/lib/epicAdmission.js.map +1 -0
- package/dist/server/lib/epicAttemptBuildRecovery.js +192 -0
- package/dist/server/lib/epicAttemptBuildRecovery.js.map +1 -0
- package/dist/server/lib/epicAttemptReconciliation.js +164 -0
- package/dist/server/lib/epicAttemptReconciliation.js.map +1 -0
- package/dist/server/lib/epicAttemptRecoverySchema.js +16 -0
- package/dist/server/lib/epicAttemptRecoverySchema.js.map +1 -0
- package/dist/server/lib/epicAttemptRecoveryStore.js +8 -0
- package/dist/server/lib/epicAttemptRecoveryStore.js.map +1 -0
- package/dist/server/lib/epicAutomation.js +104 -0
- package/dist/server/lib/epicAutomation.js.map +1 -0
- package/dist/server/lib/epicBuildCheckpoint.js +141 -0
- package/dist/server/lib/epicBuildCheckpoint.js.map +1 -0
- package/dist/server/lib/epicBuildDispatchInitiation.js +17 -0
- package/dist/server/lib/epicBuildDispatchInitiation.js.map +1 -0
- package/dist/server/lib/epicCheckpointAdmission.js +10 -0
- package/dist/server/lib/epicCheckpointAdmission.js.map +1 -0
- package/dist/server/lib/epicCheckpointAdmissionError.js +7 -0
- package/dist/server/lib/epicCheckpointAdmissionError.js.map +1 -0
- package/dist/server/lib/epicCheckpointAutomationIntegration.js +168 -0
- package/dist/server/lib/epicCheckpointAutomationIntegration.js.map +1 -0
- package/dist/server/lib/epicCheckpointContinuationSchema.js +93 -0
- package/dist/server/lib/epicCheckpointContinuationSchema.js.map +1 -0
- package/dist/server/lib/epicCheckpointContinuations.js +219 -0
- package/dist/server/lib/epicCheckpointContinuations.js.map +1 -0
- package/dist/server/lib/epicCheckpointTicketIntegration.js +69 -0
- package/dist/server/lib/epicCheckpointTicketIntegration.js.map +1 -0
- package/dist/server/lib/epicCommandRequests.js +30 -0
- package/dist/server/lib/epicCommandRequests.js.map +1 -0
- package/dist/server/lib/epicConversationStore.js +88 -0
- package/dist/server/lib/epicConversationStore.js.map +1 -0
- package/dist/server/lib/epicDeletedTargets.js +36 -0
- package/dist/server/lib/epicDeletedTargets.js.map +1 -0
- package/dist/server/lib/epicDeletion.js +101 -0
- package/dist/server/lib/epicDeletion.js.map +1 -0
- package/dist/server/lib/epicDeletionOperations.js +31 -0
- package/dist/server/lib/epicDeletionOperations.js.map +1 -0
- package/dist/server/lib/epicDeletionRuntime.js +63 -0
- package/dist/server/lib/epicDeletionRuntime.js.map +1 -0
- package/dist/server/lib/epicExecutionLineage.js +70 -0
- package/dist/server/lib/epicExecutionLineage.js.map +1 -0
- package/dist/server/lib/epicExecutionPlanOwnership.js +15 -0
- package/dist/server/lib/epicExecutionPlanOwnership.js.map +1 -0
- package/dist/server/lib/epicExecutionPlans.js +150 -0
- package/dist/server/lib/epicExecutionPlans.js.map +1 -0
- package/dist/server/lib/epicExecutionRecovery.js +376 -0
- package/dist/server/lib/epicExecutionRecovery.js.map +1 -0
- package/dist/server/lib/epicExport.js +186 -0
- package/dist/server/lib/epicExport.js.map +1 -0
- package/dist/server/lib/epicFollowUpDeferral.js +16 -0
- package/dist/server/lib/epicFollowUpDeferral.js.map +1 -0
- package/dist/server/lib/epicMaterialization.js +468 -0
- package/dist/server/lib/epicMaterialization.js.map +1 -0
- package/dist/server/lib/epicMessages.js +21 -0
- package/dist/server/lib/epicMessages.js.map +1 -0
- package/dist/server/lib/epicNumberSchema.js +56 -0
- package/dist/server/lib/epicNumberSchema.js.map +1 -0
- package/dist/server/lib/epicOperations.js +431 -0
- package/dist/server/lib/epicOperations.js.map +1 -0
- package/dist/server/lib/epicOrchestration.js +569 -0
- package/dist/server/lib/epicOrchestration.js.map +1 -0
- package/dist/server/lib/epicOwnedRuns.js +13 -0
- package/dist/server/lib/epicOwnedRuns.js.map +1 -0
- package/dist/server/lib/epicPackageInventory.js +49 -0
- package/dist/server/lib/epicPackageInventory.js.map +1 -0
- package/dist/server/lib/epicPlanArtifacts.js +85 -0
- package/dist/server/lib/epicPlanArtifacts.js.map +1 -0
- package/dist/server/lib/epicPlanDocuments.js +82 -0
- package/dist/server/lib/epicPlanDocuments.js.map +1 -0
- package/dist/server/lib/epicPlanningOperations.js +118 -0
- package/dist/server/lib/epicPlanningOperations.js.map +1 -0
- package/dist/server/lib/epicPlanningStore.js +157 -0
- package/dist/server/lib/epicPlanningStore.js.map +1 -0
- package/dist/server/lib/epicPostMergeEvidence.js +83 -0
- package/dist/server/lib/epicPostMergeEvidence.js.map +1 -0
- package/dist/server/lib/epicProposals.js +127 -0
- package/dist/server/lib/epicProposals.js.map +1 -0
- package/dist/server/lib/epicPullRequestExternalOwnership.js +184 -0
- package/dist/server/lib/epicPullRequestExternalOwnership.js.map +1 -0
- package/dist/server/lib/epicPullRequestObservation.js +95 -0
- package/dist/server/lib/epicPullRequestObservation.js.map +1 -0
- package/dist/server/lib/epicPullRequestOwnership.js +224 -0
- package/dist/server/lib/epicPullRequestOwnership.js.map +1 -0
- package/dist/server/lib/epicPullRequestRecovery.js +66 -0
- package/dist/server/lib/epicPullRequestRecovery.js.map +1 -0
- package/dist/server/lib/epicPullRequestTracking.js +353 -0
- package/dist/server/lib/epicPullRequestTracking.js.map +1 -0
- package/dist/server/lib/epicReconciliation.js +308 -0
- package/dist/server/lib/epicReconciliation.js.map +1 -0
- package/dist/server/lib/epicRecovery.js +69 -0
- package/dist/server/lib/epicRecovery.js.map +1 -0
- package/dist/server/lib/epicReferenceNotifications.js +29 -0
- package/dist/server/lib/epicReferenceNotifications.js.map +1 -0
- package/dist/server/lib/epicReferences.js +29 -0
- package/dist/server/lib/epicReferences.js.map +1 -0
- package/dist/server/lib/epicRepositoryIdentity.js +5 -0
- package/dist/server/lib/epicRepositoryIdentity.js.map +1 -0
- package/dist/server/lib/epicRevisionGuards.js +80 -0
- package/dist/server/lib/epicRevisionGuards.js.map +1 -0
- package/dist/server/lib/epicRoadmapValidation.js +99 -0
- package/dist/server/lib/epicRoadmapValidation.js.map +1 -0
- package/dist/server/lib/epicSchema.js +449 -0
- package/dist/server/lib/epicSchema.js.map +1 -0
- package/dist/server/lib/epicStepCheckApplicability.js +19 -0
- package/dist/server/lib/epicStepCheckApplicability.js.map +1 -0
- package/dist/server/lib/epicTargetChecks.js +59 -0
- package/dist/server/lib/epicTargetChecks.js.map +1 -0
- package/dist/server/lib/epicTargetObservation.js +28 -0
- package/dist/server/lib/epicTargetObservation.js.map +1 -0
- package/dist/server/lib/epics.js +840 -0
- package/dist/server/lib/epics.js.map +1 -0
- package/dist/server/lib/executionInterruption.js +20 -0
- package/dist/server/lib/executionInterruption.js.map +1 -0
- package/dist/server/lib/executionReconciliation.js +24 -5
- package/dist/server/lib/executionReconciliation.js.map +1 -1
- package/dist/server/lib/executionRetry.js +11 -1
- package/dist/server/lib/executionRetry.js.map +1 -1
- package/dist/server/lib/executionRetryContext.js +3 -2
- package/dist/server/lib/executionRetryContext.js.map +1 -1
- package/dist/server/lib/executionRunAuthority.js +4 -0
- package/dist/server/lib/executionRunAuthority.js.map +1 -1
- package/dist/server/lib/executionRunLinkMigration.js +37 -0
- package/dist/server/lib/executionRunLinkMigration.js.map +1 -0
- package/dist/server/lib/executionRunNotifications.js +104 -0
- package/dist/server/lib/executionRunNotifications.js.map +1 -0
- package/dist/server/lib/executionRuns.js +35 -20
- package/dist/server/lib/executionRuns.js.map +1 -1
- package/dist/server/lib/executionTimelineScope.js +30 -0
- package/dist/server/lib/executionTimelineScope.js.map +1 -0
- package/dist/server/lib/executionWorkloads.js +1 -1
- package/dist/server/lib/executionWorkloads.js.map +1 -1
- package/dist/server/lib/externalSource.js +18 -0
- package/dist/server/lib/externalSource.js.map +1 -1
- package/dist/server/lib/genericToolCall.js +7 -4
- package/dist/server/lib/genericToolCall.js.map +1 -1
- package/dist/server/lib/git.js +19 -2
- package/dist/server/lib/git.js.map +1 -1
- package/dist/server/lib/gitBranchTracking.js +26 -0
- package/dist/server/lib/gitBranchTracking.js.map +1 -0
- package/dist/server/lib/gitRebaseState.js +38 -0
- package/dist/server/lib/gitRebaseState.js.map +1 -0
- package/dist/server/lib/i18n/checkRepairPolicy.js +13 -0
- package/dist/server/lib/i18n/checkRepairPolicy.js.map +1 -0
- package/dist/server/lib/i18n/epicExecution.js +109 -0
- package/dist/server/lib/i18n/epicExecution.js.map +1 -0
- package/dist/server/lib/i18n/epicPlanning.js +71 -0
- package/dist/server/lib/i18n/epicPlanning.js.map +1 -0
- package/dist/server/lib/i18n/epicProposals.js +18 -0
- package/dist/server/lib/i18n/epicProposals.js.map +1 -0
- package/dist/server/lib/i18n/resources.js +14 -0
- package/dist/server/lib/i18n/resources.js.map +1 -1
- package/dist/server/lib/i18n/specPlanning.js +85 -0
- package/dist/server/lib/i18n/specPlanning.js.map +1 -0
- package/dist/server/lib/integrations/github.js +50 -11
- package/dist/server/lib/integrations/github.js.map +1 -1
- package/dist/server/lib/jsonControlChars.js +41 -0
- package/dist/server/lib/jsonControlChars.js.map +1 -0
- package/dist/server/lib/lightweightPrompt.js +20 -4
- package/dist/server/lib/lightweightPrompt.js.map +1 -1
- package/dist/server/lib/mobileAccess.js +12 -20
- package/dist/server/lib/mobileAccess.js.map +1 -1
- package/dist/server/lib/opencodeActivity.js +58 -0
- package/dist/server/lib/opencodeActivity.js.map +1 -0
- package/dist/server/lib/opencodeAgentProvider.js +11 -1
- package/dist/server/lib/opencodeAgentProvider.js.map +1 -1
- package/dist/server/lib/opencodeApprovalContext.js +38 -0
- package/dist/server/lib/opencodeApprovalContext.js.map +1 -0
- package/dist/server/lib/opencodeApprovalLifecycle.js +49 -0
- package/dist/server/lib/opencodeApprovalLifecycle.js.map +1 -0
- package/dist/server/lib/opencodeApprovalRoutes.js +51 -0
- package/dist/server/lib/opencodeApprovalRoutes.js.map +1 -0
- package/dist/server/lib/opencodeApprovalSchema.js +43 -0
- package/dist/server/lib/opencodeApprovalSchema.js.map +1 -0
- package/dist/server/lib/opencodeApprovalTransport.js +752 -0
- package/dist/server/lib/opencodeApprovalTransport.js.map +1 -0
- package/dist/server/lib/opencodeApprovalTypes.js +2 -0
- package/dist/server/lib/opencodeApprovalTypes.js.map +1 -0
- package/dist/server/lib/opencodeDescendantPermissions.js +52 -0
- package/dist/server/lib/opencodeDescendantPermissions.js.map +1 -0
- package/dist/server/lib/opencodeGuestTrustedPaths.js +44 -0
- package/dist/server/lib/opencodeGuestTrustedPaths.js.map +1 -0
- package/dist/server/lib/opencodeRunRouting.js +56 -0
- package/dist/server/lib/opencodeRunRouting.js.map +1 -0
- package/dist/server/lib/opencodeShellActivity.js +30 -0
- package/dist/server/lib/opencodeShellActivity.js.map +1 -0
- package/dist/server/lib/opencodeStream.js +3 -2
- package/dist/server/lib/opencodeStream.js.map +1 -1
- package/dist/server/lib/opencodeSubagentActivity.js +19 -0
- package/dist/server/lib/opencodeSubagentActivity.js.map +1 -0
- package/dist/server/lib/opencodeToolApprovals.js +371 -0
- package/dist/server/lib/opencodeToolApprovals.js.map +1 -0
- package/dist/server/lib/planModeQuestions.js +4 -0
- package/dist/server/lib/planModeQuestions.js.map +1 -1
- package/dist/server/lib/postBuildCheckRuns.js +81 -12
- package/dist/server/lib/postBuildCheckRuns.js.map +1 -1
- package/dist/server/lib/postBuildChecks.js +22 -1
- package/dist/server/lib/postBuildChecks.js.map +1 -1
- package/dist/server/lib/projectMemorySelections.js +4 -0
- package/dist/server/lib/projectMemorySelections.js.map +1 -1
- package/dist/server/lib/requiredCheckPolicy.js +12 -2
- package/dist/server/lib/requiredCheckPolicy.js.map +1 -1
- package/dist/server/lib/restrictedFilePrompt.js +11 -3
- package/dist/server/lib/restrictedFilePrompt.js.map +1 -1
- package/dist/server/lib/reviewAgentWatchdog.js +5 -5
- package/dist/server/lib/reviewAgentWatchdog.js.map +1 -1
- package/dist/server/lib/reviewPromptContext.js +5 -3
- package/dist/server/lib/reviewPromptContext.js.map +1 -1
- package/dist/server/lib/rootCheckGateEvidence.js +116 -0
- package/dist/server/lib/rootCheckGateEvidence.js.map +1 -0
- package/dist/server/lib/specAgentRuntime.js +37 -0
- package/dist/server/lib/specAgentRuntime.js.map +1 -0
- package/dist/server/lib/specArtifact.js +13 -54
- package/dist/server/lib/specArtifact.js.map +1 -1
- package/dist/server/lib/specDraft.js +2 -0
- package/dist/server/lib/specDraft.js.map +1 -1
- package/dist/server/lib/specEpicPlanFormatting.js +38 -0
- package/dist/server/lib/specEpicPlanFormatting.js.map +1 -0
- package/dist/server/lib/specExport.js +17 -7
- package/dist/server/lib/specExport.js.map +1 -1
- package/dist/server/lib/specMessages.js +9 -2
- package/dist/server/lib/specMessages.js.map +1 -1
- package/dist/server/lib/specOperations.js +76 -2
- package/dist/server/lib/specOperations.js.map +1 -1
- package/dist/server/lib/specPlanningArtifactAuthority.js +10 -0
- package/dist/server/lib/specPlanningArtifactAuthority.js.map +1 -0
- package/dist/server/lib/specPlanningReferences.js +147 -0
- package/dist/server/lib/specPlanningReferences.js.map +1 -0
- package/dist/server/lib/specPlanningSchema.js +39 -0
- package/dist/server/lib/specPlanningSchema.js.map +1 -0
- package/dist/server/lib/specPlanningTargets.js +53 -0
- package/dist/server/lib/specPlanningTargets.js.map +1 -0
- package/dist/server/lib/specReviewContext.js +31 -9
- package/dist/server/lib/specReviewContext.js.map +1 -1
- package/dist/server/lib/specReviewDraft.js +7 -2
- package/dist/server/lib/specReviewDraft.js.map +1 -1
- package/dist/server/lib/specReviewOperations.js +2 -0
- package/dist/server/lib/specReviewOperations.js.map +1 -1
- package/dist/server/lib/specReviewValidation.js +19 -0
- package/dist/server/lib/specReviewValidation.js.map +1 -1
- package/dist/server/lib/specTicketMaterialization.js +2 -0
- package/dist/server/lib/specTicketMaterialization.js.map +1 -1
- package/dist/server/lib/specs.js +116 -47
- package/dist/server/lib/specs.js.map +1 -1
- package/dist/server/lib/ticketAutomationCommit.js +95 -22
- package/dist/server/lib/ticketAutomationCommit.js.map +1 -1
- package/dist/server/lib/ticketPostBuildCheckRerun.js +124 -0
- package/dist/server/lib/ticketPostBuildCheckRerun.js.map +1 -0
- package/dist/server/lib/ticketRunOperations.js +4 -3
- package/dist/server/lib/ticketRunOperations.js.map +1 -1
- package/dist/server/lib/tickets.js +26 -5
- package/dist/server/lib/tickets.js.map +1 -1
- package/dist/server/lib/transcriptRuns.js +105 -3
- package/dist/server/lib/transcriptRuns.js.map +1 -1
- package/dist/server/lib/types.js +5 -1
- package/dist/server/lib/types.js.map +1 -1
- package/dist/server/workers/build.js +75 -42
- package/dist/server/workers/build.js.map +1 -1
- package/dist/server/workers/buildStatus.js +27 -0
- package/dist/server/workers/buildStatus.js.map +1 -0
- package/dist/server/workers/epicArtifactContract.js +156 -0
- package/dist/server/workers/epicArtifactContract.js.map +1 -0
- package/dist/server/workers/epicAssessmentResponse.js +27 -0
- package/dist/server/workers/epicAssessmentResponse.js.map +1 -0
- package/dist/server/workers/epicConversation.js +477 -0
- package/dist/server/workers/epicConversation.js.map +1 -0
- package/dist/server/workers/epicPlanning.js +642 -0
- package/dist/server/workers/epicPlanning.js.map +1 -0
- package/dist/server/workers/epicSpecArtifactContract.js +21 -0
- package/dist/server/workers/epicSpecArtifactContract.js.map +1 -0
- package/dist/server/workers/followUp.js +84 -36
- package/dist/server/workers/followUp.js.map +1 -1
- package/dist/server/workers/plan.js +62 -50
- package/dist/server/workers/plan.js.map +1 -1
- package/dist/server/workers/postBuildCheckRecovery.js +156 -0
- package/dist/server/workers/postBuildCheckRecovery.js.map +1 -0
- package/dist/server/workers/specEpicArtifact.js +4 -0
- package/dist/server/workers/specEpicArtifact.js.map +1 -0
- package/dist/server/workers/specSession.js +68 -28
- package/dist/server/workers/specSession.js.map +1 -1
- package/dist/shared/epicPlan.js +336 -0
- package/dist/shared/epicPlan.js.map +1 -0
- package/dist/shared/epics.js +115 -0
- package/dist/shared/epics.js.map +1 -0
- package/dist/shared/specPlanning.js +2 -0
- package/dist/shared/specPlanning.js.map +1 -0
- package/dist/shared/transcriptRuns.js +2 -0
- package/dist/shared/transcriptRuns.js.map +1 -0
- package/package.json +1 -1
- package/dist/client/assets/VerificationDialog-DcKjv3mg.js +0 -4
- package/dist/client/assets/channel-DOoXSYAr.js +0 -1
- package/dist/client/assets/classDiagram-4FO5ZUOK-DKWNm6Cx.js +0 -1
- package/dist/client/assets/classDiagram-v2-Q7XG4LA2-JFUHs0Z7.js +0 -1
- package/dist/client/assets/index-C1ZNfkTu.css +0 -2
- package/dist/client/assets/index-CXBsxrT1.js +0 -293
- package/dist/client/assets/stateDiagram-v2-BHNVJYJU-B2rL_9Nk.js +0 -1
|
@@ -0,0 +1,840 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'crypto';
|
|
2
|
+
import db from '../db.js';
|
|
3
|
+
import { allocateEpicNumber } from './epicNumberSchema.js';
|
|
4
|
+
import { epicMessageTranscripts, nextEpicMessageSequence, insertEpicMessage, listEpicMessages as listStoredEpicMessages } from './epicMessages.js';
|
|
5
|
+
import { inheritEpicAttemptCompletedBuild } from './epicAttemptBuildRecovery.js';
|
|
6
|
+
import { HttpError } from './httpError.js';
|
|
7
|
+
import { translateServerMessage as t } from './i18n/index.js';
|
|
8
|
+
import { assertSpecImplementationArtifact } from './specPlanningArtifactAuthority.js';
|
|
9
|
+
import { validateSpecEpicPlanArtifact } from './epicPlanArtifacts.js';
|
|
10
|
+
import { hasExactEpicExecutionInventory, sameEpicExecutionPlan } from './epicExecutionPlanOwnership.js';
|
|
11
|
+
import { supersedeUnreservedEpicExecutionPlans } from './epicExecutionPlans.js';
|
|
12
|
+
import { assertMappedEpicInventory, requireMappedEpicExecutionPlan, freezeEpicPlanningInventory } from './epicPackageInventory.js';
|
|
13
|
+
import { preserveEpicMaterializedScope as preserveMaterialized } from './epicRevisionGuards.js';
|
|
14
|
+
import { conversionEpicDocument, normalizeEpicDocument, normalizeEpicPlan } from './epicPlanDocuments.js';
|
|
15
|
+
import { epicPlanningMessage } from './i18n/epicPlanning.js';
|
|
16
|
+
import { epicProposalMessage } from './i18n/epicProposals.js';
|
|
17
|
+
import { parseEpicRoadmap } from './epicRoadmapValidation.js';
|
|
18
|
+
import { assertActiveEpicProposalOwner, assertReviewableEpicDraft, attachEpicProposalDraft, getEpicDraftProposal, markEpicProposalApproved, ownManualEpicDraft } from './epicProposals.js';
|
|
19
|
+
import { DEFAULT_EPIC_SETTINGS, emptyEpicContent, EPIC_PHASES, parseEpicContent, parseEpicBlockers } from '../../shared/epics.js';
|
|
20
|
+
const now = () => new Date().toISOString();
|
|
21
|
+
const fail = (message, status = 422) => {
|
|
22
|
+
throw new HttpError(status, message);
|
|
23
|
+
};
|
|
24
|
+
const text = (value, name, allowEmpty = false) => {
|
|
25
|
+
if (typeof value !== 'string' || (!allowEmpty && !value.trim()) || value.length > 100_000) {
|
|
26
|
+
fail(`Invalid ${name}`);
|
|
27
|
+
}
|
|
28
|
+
return value;
|
|
29
|
+
};
|
|
30
|
+
const object = (value) => {
|
|
31
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
32
|
+
fail('Expected an object');
|
|
33
|
+
}
|
|
34
|
+
return value;
|
|
35
|
+
};
|
|
36
|
+
const same = (a, b) => {
|
|
37
|
+
if (a === b) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
if (!a || !b || typeof a !== 'object' || typeof b !== 'object') {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
if (Array.isArray(a) || Array.isArray(b)) {
|
|
44
|
+
return Array.isArray(a) && Array.isArray(b) && a.length === b.length && a.every((v, i) => same(v, b[i]));
|
|
45
|
+
}
|
|
46
|
+
const left = a;
|
|
47
|
+
const right = b;
|
|
48
|
+
return Object.keys(left).length === Object.keys(right).length && Object.keys(left).every(key => same(left[key], right[key]));
|
|
49
|
+
};
|
|
50
|
+
const checkProject = (projectId) => {
|
|
51
|
+
const project = db.prepare('SELECT deletion_started_at FROM projects WHERE id = ?').get(projectId);
|
|
52
|
+
if (!project) {
|
|
53
|
+
fail('Project not found', 404);
|
|
54
|
+
}
|
|
55
|
+
if (project.deletion_started_at) {
|
|
56
|
+
fail('Project is being deleted', 409);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
const serializeEpic = (row) => {
|
|
60
|
+
const { settings_json, conversion_json, blockers_json, ...epic } = row;
|
|
61
|
+
return { ...epic, settings: JSON.parse(settings_json), conversion: conversion_json ? JSON.parse(conversion_json) : null, blockers: JSON.parse(blockers_json) };
|
|
62
|
+
};
|
|
63
|
+
export const getEpic = (epicId, projectId) => {
|
|
64
|
+
const row = db.prepare('SELECT id, project_id, epic_number, title, description, version, current_revision_id, execution_intent, phase, blockers_json, settings_json, conversion_json, created_at, updated_at FROM epics WHERE id = ? AND project_id = ?').get(epicId, projectId);
|
|
65
|
+
return row ? serializeEpic(row) : null;
|
|
66
|
+
};
|
|
67
|
+
export const listEpics = (projectId) => db.prepare('SELECT id, project_id, epic_number, title, description, version, current_revision_id, execution_intent, phase, blockers_json, settings_json, conversion_json, created_at, updated_at FROM epics WHERE project_id = ? ORDER BY updated_at DESC, id').all(projectId).map(serializeEpic);
|
|
68
|
+
const requireEpic = (scope) => getEpic(scope.epic_id, scope.project_id) ?? fail('Epic not found', 404);
|
|
69
|
+
/** Progress and transcript receipts do not change approval scope. Rebase only
|
|
70
|
+
* drafts that were current immediately before this trusted mutation. */
|
|
71
|
+
const advanceCurrentDrafts = (epic) => {
|
|
72
|
+
db.prepare(`UPDATE epic_drafts SET base_version = ? WHERE epic_id = ? AND project_id = ?
|
|
73
|
+
AND base_version = ? AND base_revision_id IS ?`).run(epic.version + 1, epic.id, epic.project_id, epic.version, epic.current_revision_id);
|
|
74
|
+
};
|
|
75
|
+
const mutate = (scope) => {
|
|
76
|
+
checkProject(scope.project_id);
|
|
77
|
+
const epic = requireEpic(scope);
|
|
78
|
+
if (!Number.isSafeInteger(scope.expected_version) || scope.expected_version !== epic.version) {
|
|
79
|
+
fail('Epic version conflict', 409);
|
|
80
|
+
}
|
|
81
|
+
const result = db.prepare('UPDATE epics SET version = version + 1, updated_at = ? WHERE id = ? AND project_id = ? AND version = ?').run(now(), scope.epic_id, scope.project_id, scope.expected_version);
|
|
82
|
+
if (result.changes !== 1) {
|
|
83
|
+
fail('Epic version conflict', 409);
|
|
84
|
+
}
|
|
85
|
+
return epic;
|
|
86
|
+
};
|
|
87
|
+
const settingsFor = (patch, previous = DEFAULT_EPIC_SETTINGS) => {
|
|
88
|
+
if (patch !== undefined) {
|
|
89
|
+
object(patch);
|
|
90
|
+
}
|
|
91
|
+
if (patch?.planner !== undefined) {
|
|
92
|
+
object(patch.planner);
|
|
93
|
+
}
|
|
94
|
+
const result = { ...previous, ...patch, planner: { ...previous.planner, ...patch?.planner } };
|
|
95
|
+
if (typeof result.auto_plan_next_bundle !== 'boolean' || typeof result.auto_build_planned_bundle !== 'boolean') {
|
|
96
|
+
fail('Automation settings must be booleans');
|
|
97
|
+
}
|
|
98
|
+
if (result.planner.agent !== null && !['claude', 'codex', 'opencode'].includes(result.planner.agent)) {
|
|
99
|
+
fail('Invalid planner agent');
|
|
100
|
+
}
|
|
101
|
+
for (const value of [result.planner.model, result.planner.variant]) {
|
|
102
|
+
if (value !== null) {
|
|
103
|
+
text(value, 'planner model/variant');
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return result;
|
|
107
|
+
};
|
|
108
|
+
const insertEpic = (input, conversion = null) => {
|
|
109
|
+
checkProject(input.project_id);
|
|
110
|
+
const request = { title: text(input.title, 'title'), description: text(input.description ?? '', 'description', true), settings: settingsFor(input.settings) };
|
|
111
|
+
if (input.idempotency_key !== undefined) {
|
|
112
|
+
text(input.idempotency_key, 'creation idempotency key');
|
|
113
|
+
const existing = db.prepare('SELECT id, creation_request_json FROM epics WHERE project_id = ? AND idempotency_key = ?').get(input.project_id, input.idempotency_key);
|
|
114
|
+
if (existing) {
|
|
115
|
+
if (!same(JSON.parse(existing.creation_request_json), request)) {
|
|
116
|
+
fail('Creation idempotency key was reused with different input', 409);
|
|
117
|
+
}
|
|
118
|
+
return requireEpic({ epic_id: existing.id, project_id: input.project_id });
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
const id = randomUUID();
|
|
122
|
+
const timestamp = now();
|
|
123
|
+
const epicNumber = allocateEpicNumber(db, input.project_id);
|
|
124
|
+
db.prepare(`INSERT INTO epics (id, project_id, epic_number, title, description, settings_json, conversion_json, source_ticket_id, created_at, updated_at, source_spec_snapshot_id, idempotency_key, creation_request_json)
|
|
125
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(id, input.project_id, epicNumber, request.title, request.description, JSON.stringify(request.settings), conversion ? JSON.stringify(conversion) : null, conversion?.source_ticket_id ?? null, timestamp, timestamp, conversion?.source_kind === 'spec_snapshot' ? conversion.source_spec_snapshot_id : null, input.idempotency_key ?? null, JSON.stringify(request));
|
|
126
|
+
return requireEpic({ project_id: input.project_id, epic_id: id });
|
|
127
|
+
};
|
|
128
|
+
export const createEpic = (input) => db.transaction(() => insertEpic(input)).immediate();
|
|
129
|
+
export const updateEpic = (input) => db.transaction(() => {
|
|
130
|
+
const epic = mutate(input);
|
|
131
|
+
const intent = input.execution_intent ?? epic.execution_intent;
|
|
132
|
+
if (!['idle', 'running', 'paused', 'cancelled'].includes(intent)) {
|
|
133
|
+
fail('Invalid execution intent');
|
|
134
|
+
}
|
|
135
|
+
if (intent === 'running' && epic.blockers.length) {
|
|
136
|
+
fail('Epic blockers must be explicitly resolved before resuming', 409);
|
|
137
|
+
}
|
|
138
|
+
db.prepare('UPDATE epics SET title = ?, description = ?, settings_json = ?, execution_intent = ? WHERE id = ?').run(text(input.title ?? epic.title, 'title'), text(input.description ?? epic.description, 'description', true), JSON.stringify(settingsFor(input.settings, epic.settings)), intent, epic.id);
|
|
139
|
+
return requireEpic(input);
|
|
140
|
+
}).immediate();
|
|
141
|
+
export const updateEpicProgress = (input) => db.transaction(() => {
|
|
142
|
+
const epic = mutate(input);
|
|
143
|
+
if (!EPIC_PHASES.includes(input.phase)) {
|
|
144
|
+
fail('Invalid epic phase');
|
|
145
|
+
}
|
|
146
|
+
const blockers = input.blockers ?? epic.blockers.filter(blocker => !input.resolved_blocker_ids?.includes(blocker.id));
|
|
147
|
+
const resolved = input.resolved_blocker_ids ?? [];
|
|
148
|
+
if (!Array.isArray(blockers) || !Array.isArray(resolved) || resolved.some(id => !epic.blockers.some(blocker => blocker.id === id))) {
|
|
149
|
+
fail('Invalid blocker resolution');
|
|
150
|
+
}
|
|
151
|
+
const roadmap = epic.current_revision_id ? requireRevision(input, epic.current_revision_id).roadmap : null;
|
|
152
|
+
try {
|
|
153
|
+
parseEpicBlockers(blockers, roadmap);
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
fail(error instanceof Error ? error.message : 'Invalid blockers');
|
|
157
|
+
}
|
|
158
|
+
if (epic.blockers.some(blocker => !resolved.includes(blocker.id) && !same(blockers.find(next => next.id === blocker.id), blocker))) {
|
|
159
|
+
fail('Existing blockers require explicit resolution', 409);
|
|
160
|
+
}
|
|
161
|
+
if (blockers.length && input.phase !== 'blocked') {
|
|
162
|
+
fail('Unresolved blockers require blocked phase', 409);
|
|
163
|
+
}
|
|
164
|
+
db.prepare('UPDATE epics SET phase = ?, blockers_json = ?, execution_intent = ? WHERE id = ?').run(input.phase, JSON.stringify(blockers), blockers.length ? 'paused' : epic.execution_intent, epic.id);
|
|
165
|
+
advanceCurrentDrafts(epic);
|
|
166
|
+
return requireEpic(input);
|
|
167
|
+
}).immediate();
|
|
168
|
+
export const validateEpicRoadmap = parseEpicRoadmap;
|
|
169
|
+
const revisionFrom = (row) => {
|
|
170
|
+
const { roadmap_json, content_json, document_json, plan_json, ...revision } = row;
|
|
171
|
+
return { ...revision, ...normalizeEpicPlan(plan_json ? { plan: JSON.parse(plan_json) } : { roadmap: JSON.parse(roadmap_json) }),
|
|
172
|
+
content: JSON.parse(content_json), document: document_json ? JSON.parse(document_json) : null };
|
|
173
|
+
};
|
|
174
|
+
export const getEpicRevision = (revisionId, epicId, projectId) => {
|
|
175
|
+
const row = db.prepare('SELECT * FROM epic_revisions WHERE id = ? AND epic_id = ? AND project_id = ?').get(revisionId, epicId, projectId);
|
|
176
|
+
return row ? revisionFrom(row) : null;
|
|
177
|
+
};
|
|
178
|
+
export const listEpicRevisions = (epicId, projectId) => db.prepare('SELECT * FROM epic_revisions WHERE epic_id = ? AND project_id = ? ORDER BY revision').all(epicId, projectId).map(revisionFrom);
|
|
179
|
+
const requireRevision = (scope, id) => getEpicRevision(id, scope.epic_id, scope.project_id) ?? fail('Epic revision not found', 404);
|
|
180
|
+
export const getEpicDraft = (draftId, epicId, projectId) => {
|
|
181
|
+
const row = db.prepare('SELECT * FROM epic_drafts WHERE id = ? AND epic_id = ? AND project_id = ?').get(draftId, epicId, projectId);
|
|
182
|
+
if (!row) {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
const { roadmap_json, content_json, document_json, plan_json, ...draft } = row;
|
|
186
|
+
return { ...draft, ...normalizeEpicPlan(plan_json ? { plan: JSON.parse(plan_json) } : { roadmap: JSON.parse(roadmap_json) }),
|
|
187
|
+
content: JSON.parse(content_json), document: document_json ? JSON.parse(document_json) : null };
|
|
188
|
+
};
|
|
189
|
+
export const listEpicDrafts = (epicId, projectId) => db.prepare(`SELECT id FROM epic_drafts d WHERE epic_id = ? AND project_id = ?
|
|
190
|
+
AND NOT EXISTS (SELECT 1 FROM epic_proposals p WHERE p.draft_id = d.id AND p.status NOT IN ('preparing', 'awaiting_review'))
|
|
191
|
+
ORDER BY created_at, id`).all(epicId, projectId).map(row => getEpicDraft(row.id, epicId, projectId));
|
|
192
|
+
export const getEpicMaterialization = (epicId, projectId) => ({
|
|
193
|
+
bundles: db.prepare(`SELECT roadmap_bundle_id, bundle_id, revision_id, execution_plan_id, execution_plan_digest FROM epic_materialized_bundles WHERE epic_id = ? AND project_id = ?
|
|
194
|
+
UNION SELECT roadmap_bundle_id, bundle_id, revision_id, NULL, NULL FROM epic_materialized_bundle_tombstones WHERE epic_id = ? AND project_id = ?
|
|
195
|
+
ORDER BY roadmap_bundle_id`).all(epicId, projectId, epicId, projectId).map(cleanPlanIdentity),
|
|
196
|
+
tickets: db.prepare(`SELECT roadmap_ticket_id, roadmap_bundle_id, ticket_id, revision_id, execution_plan_id, execution_plan_digest FROM epic_materialized_tickets WHERE epic_id = ? AND project_id = ?
|
|
197
|
+
UNION SELECT roadmap_ticket_id, roadmap_bundle_id, ticket_id, revision_id, NULL, NULL FROM epic_materialized_ticket_tombstones WHERE epic_id = ? AND project_id = ?
|
|
198
|
+
ORDER BY roadmap_ticket_id, roadmap_bundle_id`).all(epicId, projectId, epicId, projectId).map(cleanPlanIdentity),
|
|
199
|
+
});
|
|
200
|
+
const cleanPlanIdentity = (mapping) => {
|
|
201
|
+
const result = { ...mapping };
|
|
202
|
+
if (result.execution_plan_id == null) {
|
|
203
|
+
delete result.execution_plan_id;
|
|
204
|
+
}
|
|
205
|
+
if (result.execution_plan_digest == null) {
|
|
206
|
+
delete result.execution_plan_digest;
|
|
207
|
+
}
|
|
208
|
+
return result;
|
|
209
|
+
};
|
|
210
|
+
export const validateEpicContent = (value, roadmap, historicalRoadmaps = []) => {
|
|
211
|
+
try {
|
|
212
|
+
return parseEpicContent(value, roadmap, historicalRoadmaps);
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
return fail(error instanceof Error ? error.message : 'Invalid epic content');
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
const preserveRequirements = (scope, content) => {
|
|
219
|
+
const revisions = listEpicRevisions(scope.epic_id, scope.project_id);
|
|
220
|
+
for (const revision of revisions) {
|
|
221
|
+
for (const requirement of revision.content.requirements) {
|
|
222
|
+
const next = content.requirements.find(next => next.id === requirement.id);
|
|
223
|
+
if (!next || next.title !== requirement.title || !same(next.goal_ids, requirement.goal_ids)
|
|
224
|
+
|| (requirement.status === 'retired' && next.status !== 'retired')) {
|
|
225
|
+
fail('Historical requirement IDs must retain their identity; retire instead of removing or reusing', 409);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
if (revisions.length && !same(revisions.at(-1).content, content) && !content.revision_rationale.trim()) {
|
|
230
|
+
fail('Content revisions require revision rationale');
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
export const saveEpicDraft = (input) => db.transaction(() => {
|
|
234
|
+
if (input.proposal_owner) {
|
|
235
|
+
if (input.proposal_owner.epic_id !== input.epic_id || input.proposal_owner.project_id !== input.project_id) {
|
|
236
|
+
fail(epicProposalMessage('ownershipConflict'), 409);
|
|
237
|
+
}
|
|
238
|
+
assertActiveEpicProposalOwner(input.proposal_owner);
|
|
239
|
+
}
|
|
240
|
+
if (input.draft_id) {
|
|
241
|
+
const proposal = getEpicDraftProposal(input.draft_id, input.epic_id, input.project_id);
|
|
242
|
+
if (proposal && !['preparing', 'awaiting_review'].includes(proposal.status)) {
|
|
243
|
+
fail(epicProposalMessage('closed'), 409);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
const epic = mutate(input);
|
|
247
|
+
const { plan, roadmap } = normalizeEpicPlan(input);
|
|
248
|
+
if (plan.kind === 'legacy_roadmap') {
|
|
249
|
+
validateEpicRoadmap(roadmap);
|
|
250
|
+
}
|
|
251
|
+
preserveMaterialized(input, roadmap, plan);
|
|
252
|
+
const priorDraft = input.draft_id ? getEpicDraft(input.draft_id, epic.id, epic.project_id) : null;
|
|
253
|
+
const previous = priorDraft ?? (epic.current_revision_id ? requireRevision(input, epic.current_revision_id) : null);
|
|
254
|
+
const document = normalizeEpicDocument(input.document, previous?.document ?? null);
|
|
255
|
+
const content = validateEpicContent(input.content ?? priorDraft?.content ?? (epic.current_revision_id ? requireRevision(input, epic.current_revision_id).content : emptyEpicContent()), roadmap, listEpicRevisions(epic.id, epic.project_id).map(revision => revision.roadmap));
|
|
256
|
+
preserveRequirements(input, content);
|
|
257
|
+
const baseRevision = input.base_revision_id === undefined ? epic.current_revision_id : input.base_revision_id;
|
|
258
|
+
if (baseRevision !== epic.current_revision_id) {
|
|
259
|
+
fail('Draft must be based on the current revision', 409);
|
|
260
|
+
}
|
|
261
|
+
const timestamp = now();
|
|
262
|
+
const id = input.draft_id ?? randomUUID();
|
|
263
|
+
if (input.draft_id) {
|
|
264
|
+
const existing = getEpicDraft(id, epic.id, epic.project_id) ?? fail('Epic draft not found', 404);
|
|
265
|
+
if (existing.version !== input.expected_draft_version) {
|
|
266
|
+
fail('Epic draft version conflict', 409);
|
|
267
|
+
}
|
|
268
|
+
db.prepare('UPDATE epic_drafts SET version = version + 1, base_version = ?, base_revision_id = ?, roadmap_json = ?, content_json = ?, document_json = ?, plan_json = ?, updated_at = ? WHERE id = ?').run(epic.version + 1, baseRevision, JSON.stringify(roadmap), JSON.stringify(content), document ? JSON.stringify(document) : null, JSON.stringify(plan), timestamp, id);
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
db.prepare('INSERT INTO epic_drafts (id, epic_id, project_id, version, base_version, base_revision_id, roadmap_json, content_json, document_json, plan_json, created_at, updated_at) VALUES (?, ?, ?, 1, ?, ?, ?, ?, ?, ?, ?, ?)').run(id, epic.id, epic.project_id, epic.version + 1, baseRevision, JSON.stringify(roadmap), JSON.stringify(content), document ? JSON.stringify(document) : null, JSON.stringify(plan), timestamp, timestamp);
|
|
272
|
+
}
|
|
273
|
+
const draft = getEpicDraft(id, epic.id, epic.project_id);
|
|
274
|
+
if (input.proposal_owner) {
|
|
275
|
+
attachEpicProposalDraft(input.proposal_owner, draft.id);
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
ownManualEpicDraft(draft);
|
|
279
|
+
}
|
|
280
|
+
return draft;
|
|
281
|
+
}).immediate();
|
|
282
|
+
export const publishEpicDraft = (input) => db.transaction(() => {
|
|
283
|
+
const epic = mutate(input);
|
|
284
|
+
const draft = getEpicDraft(input.draft_id, epic.id, epic.project_id) ?? fail('Epic draft not found', 404);
|
|
285
|
+
const proposal = assertReviewableEpicDraft(draft);
|
|
286
|
+
if (draft.version !== input.expected_draft_version || draft.base_version !== epic.version || draft.base_revision_id !== epic.current_revision_id) {
|
|
287
|
+
fail('Epic draft is stale', 409);
|
|
288
|
+
}
|
|
289
|
+
const { plan, roadmap } = normalizeEpicPlan(draft.plan ? { plan: draft.plan } : { roadmap: draft.roadmap });
|
|
290
|
+
if (plan.kind === 'legacy_roadmap') {
|
|
291
|
+
validateEpicRoadmap(roadmap);
|
|
292
|
+
}
|
|
293
|
+
const document = normalizeEpicDocument(draft.document, null);
|
|
294
|
+
preserveMaterialized(input, roadmap, plan);
|
|
295
|
+
const content = validateEpicContent(draft.content, roadmap, listEpicRevisions(epic.id, epic.project_id).map(revision => revision.roadmap));
|
|
296
|
+
preserveRequirements(input, content);
|
|
297
|
+
const revision = epic.current_revision_id ? requireRevision(input, epic.current_revision_id).revision + 1 : 1;
|
|
298
|
+
const id = randomUUID();
|
|
299
|
+
db.prepare('INSERT INTO epic_revisions (id, epic_id, project_id, revision, parent_revision_id, base_version, roadmap_json, content_json, document_json, plan_json, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)').run(id, epic.id, epic.project_id, revision, epic.current_revision_id, epic.version, JSON.stringify(roadmap), JSON.stringify(content), document ? JSON.stringify(document) : null, JSON.stringify(plan), now());
|
|
300
|
+
db.prepare("UPDATE epics SET current_revision_id = ?, execution_intent = CASE WHEN execution_intent = 'running' THEN 'paused' ELSE execution_intent END WHERE id = ?").run(id, epic.id);
|
|
301
|
+
supersedeUnreservedEpicExecutionPlans(epic.id, epic.project_id, id);
|
|
302
|
+
markEpicProposalApproved(proposal, draft, id);
|
|
303
|
+
db.prepare('DELETE FROM epic_drafts WHERE id = ?').run(draft.id);
|
|
304
|
+
return requireRevision(input, id);
|
|
305
|
+
}).immediate();
|
|
306
|
+
const sourceId = (prefix, value) => `${prefix}-${createHash('sha256').update(value).digest('hex').slice(0, 24)}`;
|
|
307
|
+
const sourceSettings = (tool, model, variant, settings) => ({
|
|
308
|
+
...settings, planner: { agent: ['claude', 'codex', 'opencode'].includes(tool) ? tool : null,
|
|
309
|
+
model: typeof model === 'string' && model.trim() ? model : null, variant: typeof variant === 'string' && variant.trim() ? variant : null, ...settings?.planner },
|
|
310
|
+
});
|
|
311
|
+
const seedConversion = (epic, roadmap, content, actual) => {
|
|
312
|
+
const currentScope = () => ({ epic_id: epic.id, project_id: epic.project_id, expected_version: requireEpic({ epic_id: epic.id, project_id: epic.project_id }).version });
|
|
313
|
+
const draft = saveEpicDraft({ ...currentScope(), roadmap, content, document: conversionEpicDocument(epic.conversion, roadmap, content) });
|
|
314
|
+
const owned = actual.filter(ticket => ticket.bundle_id && db.prepare('SELECT 1 FROM worktree_bundles WHERE id = ? AND project_id = ?').get(ticket.bundle_id, epic.project_id));
|
|
315
|
+
if (owned.length) {
|
|
316
|
+
const revision = publishEpicDraft({ ...currentScope(), draft_id: draft.id, expected_draft_version: draft.version });
|
|
317
|
+
reconcileEpicMaterialization({ ...currentScope(),
|
|
318
|
+
bundles: [...new Set(owned.map(ticket => ticket.bundle_id))].map(id => ({ roadmap_bundle_id: sourceId('bundle', id), bundle_id: id, revision_id: revision.id })),
|
|
319
|
+
tickets: owned.map(ticket => ({ roadmap_ticket_id: sourceId('ticket', ticket.ticket_id), roadmap_bundle_id: sourceId('bundle', ticket.bundle_id), ticket_id: ticket.ticket_id, revision_id: revision.id })),
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
return requireEpic(currentScope());
|
|
323
|
+
};
|
|
324
|
+
export const convertTicketToEpic = (input) => db.transaction(() => {
|
|
325
|
+
checkProject(input.project_id);
|
|
326
|
+
const existing = db.prepare('SELECT id FROM epics WHERE project_id = ? AND source_ticket_id = ?').get(input.project_id, input.ticket_id);
|
|
327
|
+
if (existing) {
|
|
328
|
+
return requireEpic({ project_id: input.project_id, epic_id: existing.id });
|
|
329
|
+
}
|
|
330
|
+
const source = db.prepare(`SELECT title, description, state, branch, worktree_bundle_id, tool, model, variant, build_completed_at,
|
|
331
|
+
origin_spec_session_id, origin_spec_snapshot_id, external_provider, external_id, external_key, external_url, external_metadata_json
|
|
332
|
+
FROM tickets WHERE id = ? AND project_id = ?`).get(input.ticket_id, input.project_id);
|
|
333
|
+
if (!source) {
|
|
334
|
+
fail('Source ticket not found', 404);
|
|
335
|
+
}
|
|
336
|
+
const epic = insertEpic({ project_id: input.project_id, title: source.title, description: source.description ?? '', settings: sourceSettings(source.tool, source.model, source.variant, input.settings) }, {
|
|
337
|
+
source_kind: 'ticket', source_ticket_id: input.ticket_id, converted_at: now(), source_snapshot: source,
|
|
338
|
+
});
|
|
339
|
+
const requirement = { id: sourceId('requirement', input.ticket_id), title: source.title, description: source.description ?? '', acceptance_criteria: [source.description || source.title], goal_ids: ['goal-source'], status: 'active' };
|
|
340
|
+
return seedConversion(epic, { summary: source.title, bundles: [{ id: sourceId('bundle', source.worktree_bundle_id ?? input.ticket_id), title: source.title, description: '', depends_on: [],
|
|
341
|
+
tickets: [{ id: sourceId('ticket', input.ticket_id), title: source.title, description: source.description ?? '', depends_on: [], requirement_ids: [requirement.id] }] }] }, { ...emptyEpicContent(), goals: [{ id: 'goal-source', text: source.title }], requirements: [requirement], completion_criteria: requirement.acceptance_criteria, revision_rationale: 'Preserve original ticket acceptance and source work' }, [{ ticket_id: input.ticket_id, bundle_id: source.worktree_bundle_id }]);
|
|
342
|
+
}).immediate();
|
|
343
|
+
export const convertSpecSnapshotToEpic = (input) => db.transaction(() => {
|
|
344
|
+
checkProject(input.project_id);
|
|
345
|
+
const snapshot = db.prepare('SELECT * FROM spec_snapshots WHERE id = ? AND spec_session_id = ?').get(input.snapshot_id, input.spec_session_id);
|
|
346
|
+
if (snapshot?.planning_target === 'epic_plan' && !snapshot.epic_plan_json) {
|
|
347
|
+
fail(t('specPlanning:snapshotEpicArtifactRequired'), 409);
|
|
348
|
+
}
|
|
349
|
+
if (snapshot && snapshot.planning_target !== 'epic_plan') {
|
|
350
|
+
assertSpecImplementationArtifact(snapshot);
|
|
351
|
+
}
|
|
352
|
+
const prior = db.prepare('SELECT id FROM epics WHERE project_id = ? AND source_spec_snapshot_id = ?').get(input.project_id, input.snapshot_id);
|
|
353
|
+
if (prior) {
|
|
354
|
+
const epic = requireEpic({ epic_id: prior.id, project_id: input.project_id });
|
|
355
|
+
if (epic.conversion?.source_kind !== 'spec_snapshot' || epic.conversion.source_spec_session_id !== input.spec_session_id) {
|
|
356
|
+
fail('Snapshot conversion source session conflict', 409);
|
|
357
|
+
}
|
|
358
|
+
if (epic.conversion.source_snapshot.snapshot.planning_target !== 'epic_plan') {
|
|
359
|
+
assertSpecImplementationArtifact(epic.conversion.source_snapshot.snapshot);
|
|
360
|
+
}
|
|
361
|
+
return epic;
|
|
362
|
+
}
|
|
363
|
+
const session = db.prepare('SELECT * FROM spec_sessions WHERE id = ? AND project_id = ?').get(input.spec_session_id, input.project_id);
|
|
364
|
+
if (!session || !snapshot) {
|
|
365
|
+
fail('Source Spec session or snapshot not found', 404);
|
|
366
|
+
}
|
|
367
|
+
const parsed = (key) => {
|
|
368
|
+
const value = snapshot[key] == null ? [] : JSON.parse(snapshot[key]);
|
|
369
|
+
if (!Array.isArray(value)) {
|
|
370
|
+
fail('Invalid source snapshot array');
|
|
371
|
+
}
|
|
372
|
+
return value;
|
|
373
|
+
};
|
|
374
|
+
const artifact = snapshot.planning_target === 'epic_plan'
|
|
375
|
+
? validateSpecEpicPlanArtifact(JSON.parse(text(snapshot.epic_plan_json, 'Epic plan snapshot')))
|
|
376
|
+
: null;
|
|
377
|
+
const sourceTickets = artifact ? [] : parsed('tickets_json').map(value => object(value));
|
|
378
|
+
const actual = db.prepare('SELECT id AS ticket_id, worktree_bundle_id AS bundle_id, title, description, build_completed_at FROM tickets WHERE project_id = ? AND origin_spec_snapshot_id = ? ORDER BY id').all(input.project_id, input.snapshot_id);
|
|
379
|
+
const title = text(session.title, 'Spec title');
|
|
380
|
+
const epic = insertEpic({ project_id: input.project_id, title, description: text(snapshot.summary ?? '', 'Spec summary', true), settings: sourceSettings(session.tool, session.model, session.variant, input.settings) }, {
|
|
381
|
+
source_kind: 'spec_snapshot', source_ticket_id: null, source_spec_session_id: input.spec_session_id, source_spec_snapshot_id: input.snapshot_id, converted_at: now(), source_snapshot: { session, snapshot, materialized_tickets: actual },
|
|
382
|
+
});
|
|
383
|
+
if (artifact) {
|
|
384
|
+
const requirementIds = [...new Set(artifact.plan.packages.flatMap(entry => entry.requirement_ids ?? []))];
|
|
385
|
+
const requirements = requirementIds.map(id => {
|
|
386
|
+
const packages = artifact.plan.packages.filter(entry => entry.requirement_ids?.includes(id));
|
|
387
|
+
return { id, title: id, description: packages.map(entry => entry.description).join('\n\n'),
|
|
388
|
+
acceptance_criteria: [...new Set(packages.flatMap(entry => entry.completion_evidence))], goal_ids: [], status: 'active' };
|
|
389
|
+
});
|
|
390
|
+
const draft = saveEpicDraft({ project_id: epic.project_id, epic_id: epic.id, expected_version: epic.version,
|
|
391
|
+
plan: artifact.plan, document: artifact.document,
|
|
392
|
+
content: { ...emptyEpicContent(), requirements, completion_criteria: artifact.document.completion_criteria } });
|
|
393
|
+
publishEpicDraft({ project_id: epic.project_id, epic_id: epic.id, expected_version: requireEpic({ epic_id: epic.id, project_id: epic.project_id }).version,
|
|
394
|
+
draft_id: draft.id, expected_draft_version: draft.version });
|
|
395
|
+
return requireEpic({ epic_id: epic.id, project_id: epic.project_id });
|
|
396
|
+
}
|
|
397
|
+
const requirements = sourceTickets.map(ticket => ({ id: sourceId('requirement', text(ticket.key, 'source ticket key')), title: text(ticket.title, 'source title'), description: text(ticket.description, 'source description', true), acceptance_criteria: [text(ticket.description || ticket.title, 'source acceptance')], goal_ids: ['goal-source'], status: 'active' }));
|
|
398
|
+
const plan = { summary: epic.description, bundles: [] };
|
|
399
|
+
if (actual.length) {
|
|
400
|
+
for (const target of actual) {
|
|
401
|
+
const id = sourceId('bundle', target.bundle_id ?? target.ticket_id);
|
|
402
|
+
let bundle = plan.bundles.find(bundle => bundle.id === id);
|
|
403
|
+
if (!bundle) {
|
|
404
|
+
bundle = { id, title: target.title, description: '', depends_on: [], tickets: [] };
|
|
405
|
+
plan.bundles.push(bundle);
|
|
406
|
+
}
|
|
407
|
+
bundle.tickets.push({ id: sourceId('ticket', target.ticket_id), title: target.title, description: target.description ?? '', depends_on: [] });
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
else {
|
|
411
|
+
const groups = parsed('bundle_groups_json');
|
|
412
|
+
const dependencies = parsed('dependencies_json');
|
|
413
|
+
for (const ticket of sourceTickets) {
|
|
414
|
+
const key = text(ticket.key, 'source ticket key');
|
|
415
|
+
const group = groups.find(group => group.ticket_keys.includes(key));
|
|
416
|
+
const id = sourceId('bundle', group?.key ?? 'source');
|
|
417
|
+
let bundle = plan.bundles.find(bundle => bundle.id === id);
|
|
418
|
+
if (!bundle) {
|
|
419
|
+
bundle = { id, title: group?.name ?? title, description: '', depends_on: [], tickets: [] };
|
|
420
|
+
plan.bundles.push(bundle);
|
|
421
|
+
}
|
|
422
|
+
bundle.tickets.push({ id: sourceId('ticket', key), title: ticket.title, description: ticket.description, requirement_ids: [sourceId('requirement', key)], depends_on: dependencies.filter(edge => edge.dependent_key === key).map(edge => sourceId('ticket', edge.blocker_key)) });
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
const converted = seedConversion(epic, plan, { ...emptyEpicContent(), goals: [{ id: 'goal-source', text: epic.description || title }], requirements,
|
|
426
|
+
completion_criteria: requirements.flatMap(requirement => requirement.acceptance_criteria), architecture_constraints: parsed('assumptions_json').map(value => text(value, 'source assumption')), revision_rationale: 'Preserve original Spec acceptance and existing materialized work' }, actual);
|
|
427
|
+
const questions = parsed('open_questions_json').map(value => text(value, 'source question'));
|
|
428
|
+
return questions.length ? updateEpicProgress({ epic_id: epic.id, project_id: epic.project_id, expected_version: converted.version, phase: 'blocked',
|
|
429
|
+
blockers: questions.map((prompt, index) => ({ id: `source-question-${index + 1}`, kind: 'question', message: prompt, question: { prompt, options: [] } })) }) : converted;
|
|
430
|
+
}).immediate();
|
|
431
|
+
export const reconcileEpicMaterialization = (input) => db.transaction(() => {
|
|
432
|
+
const epic = mutate(input);
|
|
433
|
+
if (!epic.current_revision_id) {
|
|
434
|
+
fail('Epic has no published revision', 409);
|
|
435
|
+
}
|
|
436
|
+
const current = requireRevision(input, epic.current_revision_id);
|
|
437
|
+
const existing = getEpicMaterialization(epic.id, epic.project_id);
|
|
438
|
+
if (current.plan?.kind === 'packages') {
|
|
439
|
+
const inventory = { bundles: [...existing.bundles.filter(old => !input.bundles.some(next => next.roadmap_bundle_id === old.roadmap_bundle_id)), ...input.bundles],
|
|
440
|
+
tickets: [...existing.tickets.filter(old => !input.tickets.some(next => next.roadmap_bundle_id === old.roadmap_bundle_id && next.roadmap_ticket_id === old.roadmap_ticket_id)), ...input.tickets] };
|
|
441
|
+
const touched = new Set([...input.bundles, ...input.tickets].map(mapping => mapping.roadmap_bundle_id));
|
|
442
|
+
for (const mapping of inventory.bundles.filter(mapping => touched.has(mapping.roadmap_bundle_id))) {
|
|
443
|
+
assertMappedEpicInventory(current, mapping, inventory);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
for (const mapping of input.bundles) {
|
|
447
|
+
const revision = requireRevision(input, mapping.revision_id);
|
|
448
|
+
const original = revision.roadmap.bundles.find(bundle => bundle.id === mapping.roadmap_bundle_id);
|
|
449
|
+
const latest = current.roadmap.bundles.find(bundle => bundle.id === mapping.roadmap_bundle_id);
|
|
450
|
+
if (revision.plan?.kind === 'packages') {
|
|
451
|
+
requireMappedEpicExecutionPlan(revision, mapping);
|
|
452
|
+
const originalPackage = revision.plan.packages.find(pkg => pkg.id === mapping.roadmap_bundle_id);
|
|
453
|
+
if (current.plan?.kind !== 'packages' || !same(originalPackage, current.plan.packages.find(pkg => pkg.id === mapping.roadmap_bundle_id))) {
|
|
454
|
+
fail(epicPlanningMessage('packageApprovalChanged'), 409);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
else if (mapping.execution_plan_id || mapping.execution_plan_digest || !original || !latest || !same({ ...original, tickets: [] }, { ...latest, tickets: [] })) {
|
|
458
|
+
fail('Materialization does not match the current roadmap', 409);
|
|
459
|
+
}
|
|
460
|
+
const target = db.prepare('SELECT 1 FROM worktree_bundles WHERE id = ? AND project_id = ?').get(mapping.bundle_id, epic.project_id);
|
|
461
|
+
if (!target) {
|
|
462
|
+
fail('Materialized bundle not owned by project', 422);
|
|
463
|
+
}
|
|
464
|
+
const previous = existing.bundles.find(bundle => bundle.roadmap_bundle_id === mapping.roadmap_bundle_id);
|
|
465
|
+
if (previous && !same(previous, mapping)) {
|
|
466
|
+
fail('Materialized bundle cannot be rebound', 409);
|
|
467
|
+
}
|
|
468
|
+
if (!previous) {
|
|
469
|
+
if (db.prepare('SELECT 1 FROM epic_materialized_bundles WHERE bundle_id = ?').get(mapping.bundle_id)) {
|
|
470
|
+
fail('Bundle is already materialized under another roadmap identity', 409);
|
|
471
|
+
}
|
|
472
|
+
db.prepare('INSERT INTO epic_materialized_bundles (epic_id, project_id, roadmap_bundle_id, bundle_id, revision_id, execution_plan_id, execution_plan_digest) VALUES (?, ?, ?, ?, ?, ?, ?)').run(epic.id, epic.project_id, mapping.roadmap_bundle_id, mapping.bundle_id, mapping.revision_id, mapping.execution_plan_id ?? null, mapping.execution_plan_digest ?? null);
|
|
473
|
+
existing.bundles.push(mapping);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
for (const mapping of input.tickets) {
|
|
477
|
+
const revision = requireRevision(input, mapping.revision_id);
|
|
478
|
+
const original = revision.roadmap.bundles.find(bundle => bundle.id === mapping.roadmap_bundle_id)?.tickets.find(ticket => ticket.id === mapping.roadmap_ticket_id);
|
|
479
|
+
const latest = current.roadmap.bundles.find(bundle => bundle.id === mapping.roadmap_bundle_id)?.tickets.find(ticket => ticket.id === mapping.roadmap_ticket_id);
|
|
480
|
+
const bundle = existing.bundles.find(bundle => bundle.roadmap_bundle_id === mapping.roadmap_bundle_id);
|
|
481
|
+
if (revision.plan?.kind === 'packages') {
|
|
482
|
+
const plan = bundle && requireMappedEpicExecutionPlan(revision, bundle);
|
|
483
|
+
if (!plan || !sameEpicExecutionPlan(mapping, bundle) || !plan.tickets.some(ticket => ticket.key === mapping.roadmap_ticket_id)) {
|
|
484
|
+
fail(epicPlanningMessage('sealedTicketConflict'), 409);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
else if (mapping.execution_plan_id || mapping.execution_plan_digest || !original || !latest || !same(original, latest)) {
|
|
488
|
+
fail('Materialized ticket does not match the current roadmap', 409);
|
|
489
|
+
}
|
|
490
|
+
const target = db.prepare('SELECT 1 FROM tickets WHERE id = ? AND project_id = ? AND worktree_bundle_id = ?').get(mapping.ticket_id, epic.project_id, bundle?.bundle_id ?? null);
|
|
491
|
+
if (!bundle || !target) {
|
|
492
|
+
fail('Materialized ticket not owned by the project bundle');
|
|
493
|
+
}
|
|
494
|
+
const previous = existing.tickets.find(ticket => ticket.roadmap_ticket_id === mapping.roadmap_ticket_id && ticket.roadmap_bundle_id === mapping.roadmap_bundle_id);
|
|
495
|
+
if (previous && !same(previous, mapping)) {
|
|
496
|
+
fail('Materialized ticket cannot be rebound', 409);
|
|
497
|
+
}
|
|
498
|
+
if (!previous) {
|
|
499
|
+
if (db.prepare('SELECT 1 FROM epic_materialized_tickets WHERE ticket_id = ?').get(mapping.ticket_id)) {
|
|
500
|
+
fail('Ticket is already materialized under another roadmap identity', 409);
|
|
501
|
+
}
|
|
502
|
+
db.prepare('INSERT INTO epic_materialized_tickets (epic_id, project_id, roadmap_ticket_id, roadmap_bundle_id, ticket_id, revision_id, execution_plan_id, execution_plan_digest) VALUES (?, ?, ?, ?, ?, ?, ?, ?)').run(epic.id, epic.project_id, mapping.roadmap_ticket_id, mapping.roadmap_bundle_id, mapping.ticket_id, mapping.revision_id, mapping.execution_plan_id ?? null, mapping.execution_plan_digest ?? null);
|
|
503
|
+
existing.tickets.push(mapping);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
return getEpicMaterialization(epic.id, epic.project_id);
|
|
507
|
+
}).immediate();
|
|
508
|
+
const evidence = (table, scope, id) => {
|
|
509
|
+
const row = db.prepare(`SELECT data_json FROM ${table} WHERE id = ? AND epic_id = ? AND project_id = ?`).get(id, scope.epic_id, scope.project_id);
|
|
510
|
+
return row ? JSON.parse(row.data_json) : null;
|
|
511
|
+
};
|
|
512
|
+
const listEvidence = (table, scope) => db.prepare(`SELECT data_json FROM ${table} WHERE epic_id = ? AND project_id = ? ORDER BY rowid`).all(scope.epic_id, scope.project_id).map(row => JSON.parse(row.data_json));
|
|
513
|
+
export const getEpicAttempt = (attemptId, epicId, projectId) => evidence('epic_attempts', { epic_id: epicId, project_id: projectId }, attemptId);
|
|
514
|
+
export const listEpicAttempts = (epicId, projectId) => listEvidence('epic_attempts', { epic_id: epicId, project_id: projectId });
|
|
515
|
+
export const listEpicTicketCheckpoints = (epicId, projectId, attemptId) => listEvidence('epic_ticket_checkpoints', { epic_id: epicId, project_id: projectId }).filter(checkpoint => attemptId === undefined || checkpoint.attempt_id === attemptId);
|
|
516
|
+
export const listEpicMessages = listStoredEpicMessages;
|
|
517
|
+
export const listEpicDecisions = (epicId, projectId) => listEvidence('epic_decisions', { epic_id: epicId, project_id: projectId });
|
|
518
|
+
const requireAttempt = (scope, id) => evidence('epic_attempts', scope, id) ?? fail('Epic attempt not found', 404);
|
|
519
|
+
const validatePr = (value) => {
|
|
520
|
+
const identity = object(value);
|
|
521
|
+
if (value.provider !== undefined && value.provider !== 'github') {
|
|
522
|
+
fail('Unsupported PR provider');
|
|
523
|
+
}
|
|
524
|
+
for (const key of ['repository', 'head_branch', 'base_branch', 'head_sha']) {
|
|
525
|
+
text(identity[key], `PR ${key}`);
|
|
526
|
+
}
|
|
527
|
+
for (const key of ['repository_host', 'repository_owner', 'repository_name', 'head_repository']) {
|
|
528
|
+
if (identity[key] !== undefined) {
|
|
529
|
+
text(identity[key], `PR ${key}`);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
if (value.pull_request_number !== undefined && (!Number.isSafeInteger(value.pull_request_number) || value.pull_request_number <= 0)) {
|
|
533
|
+
fail('Invalid linked PR number');
|
|
534
|
+
}
|
|
535
|
+
if (value.head_branch === value.base_branch && (!value.head_repository || value.head_repository === value.repository)) {
|
|
536
|
+
fail('PR head and base must differ');
|
|
537
|
+
}
|
|
538
|
+
};
|
|
539
|
+
const validateBuild = (value) => {
|
|
540
|
+
const lineage = object(value);
|
|
541
|
+
for (const key of ['build_run_id', 'completed_at', 'commit_sha']) {
|
|
542
|
+
text(lineage[key], `build ${key}`);
|
|
543
|
+
}
|
|
544
|
+
if (!Number.isFinite(Date.parse(value.completed_at))) {
|
|
545
|
+
fail('Invalid build completion timestamp');
|
|
546
|
+
}
|
|
547
|
+
};
|
|
548
|
+
const terminal = (attempt) => ['completed', 'failed', 'cancelled'].includes(attempt.status);
|
|
549
|
+
export const createEpicAttempt = (input) => db.transaction(() => {
|
|
550
|
+
requireEpic(input);
|
|
551
|
+
text(input.idempotency_key, 'idempotency key');
|
|
552
|
+
const request = { revision_id: input.revision_id, roadmap_bundle_id: input.roadmap_bundle_id, kind: input.kind,
|
|
553
|
+
...(input.execution_plan_id || input.execution_plan_digest ? { execution_plan_id: input.execution_plan_id, execution_plan_digest: input.execution_plan_digest } : {}),
|
|
554
|
+
retry_of_attempt_id: input.retry_of_attempt_id ?? null, expected_pr: input.expected_pr ?? null,
|
|
555
|
+
completed_builds: input.completed_builds ?? {} };
|
|
556
|
+
const prior = listEpicAttempts(input.epic_id, input.project_id).find(attempt => attempt.idempotency_key === input.idempotency_key);
|
|
557
|
+
if (prior) {
|
|
558
|
+
const persisted = db.prepare('SELECT request_json FROM epic_attempts WHERE id = ?').get(prior.id);
|
|
559
|
+
if (!same(JSON.parse(persisted.request_json), request)) {
|
|
560
|
+
fail('Attempt idempotency key was reused with different input', 409);
|
|
561
|
+
}
|
|
562
|
+
return prior;
|
|
563
|
+
}
|
|
564
|
+
const epic = mutate(input);
|
|
565
|
+
if (['completed', 'failed', 'cancelled'].includes(epic.phase)) {
|
|
566
|
+
fail('Epic is terminal', 409);
|
|
567
|
+
}
|
|
568
|
+
if (input.revision_id !== epic.current_revision_id) {
|
|
569
|
+
fail('Attempt must use the current revision', 409);
|
|
570
|
+
}
|
|
571
|
+
if (epic.blockers.length) {
|
|
572
|
+
fail('Epic has unresolved blockers', 409);
|
|
573
|
+
}
|
|
574
|
+
if (!['plan', 'build'].includes(input.kind)) {
|
|
575
|
+
fail('Invalid attempt kind');
|
|
576
|
+
}
|
|
577
|
+
const revision = requireRevision(input, input.revision_id);
|
|
578
|
+
const mappings = getEpicMaterialization(epic.id, epic.project_id);
|
|
579
|
+
const packagePlan = revision.plan?.kind === 'packages';
|
|
580
|
+
const approvedPackage = revision.plan?.kind === 'packages' ? revision.plan.packages.find(pkg => pkg.id === input.roadmap_bundle_id) : null;
|
|
581
|
+
const packageMapping = mappings.bundles.find(mapping => mapping.roadmap_bundle_id === input.roadmap_bundle_id);
|
|
582
|
+
const sealed = packagePlan && input.kind === 'build' && packageMapping ? assertMappedEpicInventory(revision, packageMapping, mappings) : null;
|
|
583
|
+
if (sealed) {
|
|
584
|
+
const planning = requireAttempt(input, sealed.planning_attempt_id);
|
|
585
|
+
const planned = listEpicTicketCheckpoints(epic.id, epic.project_id, planning.id);
|
|
586
|
+
if (planning.status !== 'completed' || !hasExactEpicExecutionInventory(planning, sealed) || !sameEpicExecutionPlan(planning, packageMapping)
|
|
587
|
+
|| sealed.tickets.some(ticket => !planned.some(checkpoint => checkpoint.roadmap_ticket_id === ticket.key
|
|
588
|
+
&& checkpoint.phase === 'planned' && !checkpoint.deferred && sameEpicExecutionPlan(checkpoint, planning)))) {
|
|
589
|
+
fail(epicPlanningMessage('plannedCheckpointsRequired'), 409);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
if (packagePlan && (!approvedPackage || (input.kind === 'build' && !sealed))) {
|
|
593
|
+
fail(epicPlanningMessage('sealedMaterializationRequired'), 409);
|
|
594
|
+
}
|
|
595
|
+
if ((sealed && !sameEpicExecutionPlan(input, { execution_plan_id: sealed.id, execution_plan_digest: sealed.digest }))
|
|
596
|
+
|| (!sealed && (input.execution_plan_id || input.execution_plan_digest))) {
|
|
597
|
+
fail(epicPlanningMessage('attemptPlanConflict'), 409);
|
|
598
|
+
}
|
|
599
|
+
const bundle = packagePlan ? { id: input.roadmap_bundle_id, tickets: sealed?.tickets.map(ticket => ({ id: ticket.key, title: ticket.title, description: ticket.description })) ?? [] }
|
|
600
|
+
: revision.roadmap.bundles.find(bundle => bundle.id === input.roadmap_bundle_id) ?? fail('Roadmap bundle not found');
|
|
601
|
+
const materialized = mappings.bundles.find(mapping => mapping.roadmap_bundle_id === bundle.id);
|
|
602
|
+
const actual = materialized ? db.prepare('SELECT branch, base_branch FROM worktree_bundles WHERE id = ? AND project_id = ?').get(materialized.bundle_id, epic.project_id) : undefined;
|
|
603
|
+
if (input.kind === 'build' && !actual) {
|
|
604
|
+
fail('Materialized bundle no longer belongs to project', 409);
|
|
605
|
+
}
|
|
606
|
+
if (listEpicAttempts(epic.id, epic.project_id).some(attempt => attempt.roadmap_bundle_id === bundle.id && !terminal(attempt))) {
|
|
607
|
+
fail('Bundle already has an active attempt', 409);
|
|
608
|
+
}
|
|
609
|
+
if (input.expected_pr) {
|
|
610
|
+
validatePr(input.expected_pr);
|
|
611
|
+
if (input.kind !== 'build' || !actual || input.expected_pr.head_branch !== actual.branch || (actual.base_branch !== null && input.expected_pr.base_branch !== actual.base_branch)) {
|
|
612
|
+
fail('Expected PR identity does not match bundle', 409);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
const retry = input.retry_of_attempt_id ? requireAttempt(input, input.retry_of_attempt_id) : null;
|
|
616
|
+
const latestAttempt = retry ? db.prepare(`SELECT id FROM epic_attempts WHERE epic_id = ? AND project_id = ?
|
|
617
|
+
AND roadmap_bundle_id = ? AND kind = ? ORDER BY rowid DESC LIMIT 1`)
|
|
618
|
+
.get(epic.id, epic.project_id, bundle.id, input.kind) : undefined;
|
|
619
|
+
if (retry && (!terminal(retry) || retry.status === 'completed' || retry.roadmap_bundle_id !== bundle.id || retry.kind !== input.kind
|
|
620
|
+
|| (sealed && !hasExactEpicExecutionInventory(retry, sealed)) || (input.kind === 'build' && !sameEpicExecutionPlan(retry, input))
|
|
621
|
+
|| latestAttempt?.id !== retry.id || listEpicAttempts(epic.id, epic.project_id).some(attempt => attempt.retry_of_attempt_id === retry.id))) {
|
|
622
|
+
fail('Invalid retry lineage', 409);
|
|
623
|
+
}
|
|
624
|
+
for (const id of Object.keys(input.completed_builds ?? {})) {
|
|
625
|
+
if (!bundle.tickets.some(ticket => ticket.id === id)) {
|
|
626
|
+
fail('Completed build references an unknown roadmap ticket');
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
const checkpoints = retry ? listEpicTicketCheckpoints(epic.id, epic.project_id, retry.id) : [];
|
|
630
|
+
const tickets = bundle.tickets.map(ticket => {
|
|
631
|
+
const mapping = mappings.tickets.find(mapping => mapping.roadmap_ticket_id === ticket.id && mapping.roadmap_bundle_id === bundle.id);
|
|
632
|
+
if (input.kind === 'plan' && !mapping) {
|
|
633
|
+
return { roadmap_ticket_id: ticket.id, ticket_id: null, title: ticket.title, description: ticket.description, completed_build: null };
|
|
634
|
+
}
|
|
635
|
+
if (!mapping) {
|
|
636
|
+
return fail('Ticket is not materialized', 409);
|
|
637
|
+
}
|
|
638
|
+
const target = db.prepare('SELECT title, description FROM tickets WHERE id = ? AND project_id = ? AND worktree_bundle_id = ?').get(mapping.ticket_id, epic.project_id, materialized?.bundle_id ?? null);
|
|
639
|
+
if (!target) {
|
|
640
|
+
fail('Materialized ticket no longer belongs to bundle', 409);
|
|
641
|
+
}
|
|
642
|
+
const inherited = inheritEpicAttemptCompletedBuild(retry, ticket.id, mapping.ticket_id, checkpoints);
|
|
643
|
+
const explicit = input.completed_builds?.[ticket.id];
|
|
644
|
+
if (explicit) {
|
|
645
|
+
validateBuild(explicit);
|
|
646
|
+
if (!retry || !same(inherited, explicit)) {
|
|
647
|
+
fail('Completed build lineage has no matching retry checkpoint', 409);
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
return { roadmap_ticket_id: ticket.id, ticket_id: mapping.ticket_id, ...(sealed ? { title: ticket.title, description: ticket.description } : target), completed_build: inherited };
|
|
651
|
+
});
|
|
652
|
+
const timestamp = now();
|
|
653
|
+
const attempt = {
|
|
654
|
+
...(sealed ? { execution_plan_id: sealed.id, execution_plan_digest: sealed.digest } : {}),
|
|
655
|
+
id: randomUUID(), epic_id: epic.id, project_id: epic.project_id, revision_id: sealed?.revision_id ?? revision.id,
|
|
656
|
+
roadmap_bundle_id: bundle.id, bundle_id: materialized?.bundle_id ?? null, kind: input.kind, status: 'pending', version: 1,
|
|
657
|
+
idempotency_key: input.idempotency_key, retry_of_attempt_id: retry?.id ?? null, planner: epic.settings.planner,
|
|
658
|
+
expected_pr: input.expected_pr ?? null, pull_request: null, tickets, failure: null,
|
|
659
|
+
created_at: timestamp, updated_at: timestamp, completed_at: null,
|
|
660
|
+
};
|
|
661
|
+
db.prepare('INSERT INTO epic_attempts (id, epic_id, project_id, revision_id, roadmap_bundle_id, bundle_id, kind, status, version, idempotency_key, retry_of_attempt_id, request_json, data_json, execution_plan_id, execution_plan_digest) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)').run(attempt.id, epic.id, epic.project_id, attempt.revision_id, bundle.id, attempt.bundle_id, attempt.kind, attempt.status, attempt.version, attempt.idempotency_key, attempt.retry_of_attempt_id, JSON.stringify(request), JSON.stringify(attempt), attempt.execution_plan_id ?? null, attempt.execution_plan_digest ?? null);
|
|
662
|
+
return attempt;
|
|
663
|
+
}).immediate();
|
|
664
|
+
/** Server-side identity capture: pass the trusted repository adapter, never an HTTP body setter. */
|
|
665
|
+
export const captureEpicAttemptExpectedPr = async (input, resolveIdentity) => {
|
|
666
|
+
const snapshot = requireAttempt(input, input.attempt_id);
|
|
667
|
+
const identity = await resolveIdentity(JSON.parse(JSON.stringify(snapshot)));
|
|
668
|
+
validatePr(identity);
|
|
669
|
+
return db.transaction(() => {
|
|
670
|
+
const epic = requireEpic(input);
|
|
671
|
+
const attempt = requireAttempt(input, input.attempt_id);
|
|
672
|
+
if (epic.version !== input.expected_version || attempt.version !== input.expected_attempt_version || terminal(attempt) || attempt.kind !== 'build') {
|
|
673
|
+
fail('PR capture version or attempt conflict', 409);
|
|
674
|
+
}
|
|
675
|
+
const bundle = db.prepare('SELECT branch, base_branch FROM worktree_bundles WHERE id = ? AND project_id = ?').get(attempt.bundle_id, input.project_id);
|
|
676
|
+
if (!bundle || bundle.branch !== identity.head_branch || (bundle.base_branch !== null && bundle.base_branch !== identity.base_branch)) {
|
|
677
|
+
fail('Captured PR identity does not match the owned bundle', 409);
|
|
678
|
+
}
|
|
679
|
+
if (attempt.expected_pr) {
|
|
680
|
+
if (!same(attempt.expected_pr, identity)) {
|
|
681
|
+
fail('Expected PR identity snapshot is immutable', 409);
|
|
682
|
+
}
|
|
683
|
+
return attempt;
|
|
684
|
+
}
|
|
685
|
+
mutate(input);
|
|
686
|
+
const result = { ...attempt, expected_pr: identity, version: attempt.version + 1, updated_at: now() };
|
|
687
|
+
db.prepare('UPDATE epic_attempts SET version = ?, data_json = ? WHERE id = ? AND version = ?').run(result.version, JSON.stringify(result), attempt.id, attempt.version);
|
|
688
|
+
return result;
|
|
689
|
+
}).immediate();
|
|
690
|
+
};
|
|
691
|
+
export const updateEpicAttempt = (input) => db.transaction(() => {
|
|
692
|
+
mutate(input);
|
|
693
|
+
const attempt = requireAttempt(input, input.attempt_id);
|
|
694
|
+
if (attempt.version !== input.expected_attempt_version || terminal(attempt)) {
|
|
695
|
+
fail('Epic attempt version/terminal conflict', 409);
|
|
696
|
+
}
|
|
697
|
+
if (!['running', 'completed', 'failed', 'cancelled'].includes(input.status) || (attempt.status === 'pending' && input.status === 'completed')) {
|
|
698
|
+
fail('Invalid attempt status transition', 409);
|
|
699
|
+
}
|
|
700
|
+
const pr = input.pull_request === undefined ? attempt.pull_request : input.pull_request;
|
|
701
|
+
if (pr) {
|
|
702
|
+
validatePr(pr);
|
|
703
|
+
if (!Number.isSafeInteger(pr.number) || pr.number <= 0 || !pr.url || !Number.isFinite(Date.parse(pr.verified_at))) {
|
|
704
|
+
fail('Invalid verified PR evidence');
|
|
705
|
+
}
|
|
706
|
+
const identity = Object.fromEntries(Object.keys(attempt.expected_pr ?? {}).map(key => [key, key === 'pull_request_number' ? pr.number : pr[key]]));
|
|
707
|
+
if (!attempt.expected_pr || !same(attempt.expected_pr, identity)) {
|
|
708
|
+
fail('Verified PR does not match expected identity snapshot', 409);
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
if (attempt.pull_request && !same(pr, attempt.pull_request)) {
|
|
712
|
+
fail('Verified PR evidence is immutable', 409);
|
|
713
|
+
}
|
|
714
|
+
if (input.status === 'completed') {
|
|
715
|
+
const checkpoints = listEpicTicketCheckpoints(input.epic_id, input.project_id, attempt.id);
|
|
716
|
+
const phase = attempt.kind === 'plan' ? 'planned' : 'applied';
|
|
717
|
+
if (!attempt.tickets.length || attempt.tickets.some(ticket => !checkpoints.some(checkpoint => checkpoint.roadmap_ticket_id === ticket.roadmap_ticket_id && sameEpicExecutionPlan(checkpoint, attempt) && checkpoint.phase === phase && !checkpoint.deferred))) {
|
|
718
|
+
fail('Attempt has unfinished ticket checkpoints', 409);
|
|
719
|
+
}
|
|
720
|
+
if (attempt.expected_pr && !pr) {
|
|
721
|
+
fail('Attempt requires verified PR evidence', 409);
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
const result = { ...attempt, status: input.status, version: attempt.version + 1, pull_request: pr,
|
|
725
|
+
failure: input.failure === undefined ? attempt.failure : input.failure, updated_at: now(),
|
|
726
|
+
completed_at: ['completed', 'failed', 'cancelled'].includes(input.status) ? now() : null };
|
|
727
|
+
db.prepare('UPDATE epic_attempts SET status = ?, version = ?, data_json = ? WHERE id = ? AND version = ?').run(result.status, result.version, JSON.stringify(result), result.id, attempt.version);
|
|
728
|
+
return result;
|
|
729
|
+
}).immediate();
|
|
730
|
+
export const recordEpicTicketCheckpoint = (input) => db.transaction(() => {
|
|
731
|
+
requireEpic(input);
|
|
732
|
+
text(input.idempotency_key, 'checkpoint idempotency key');
|
|
733
|
+
const existing = listEpicTicketCheckpoints(input.epic_id, input.project_id).find(checkpoint => checkpoint.idempotency_key === input.idempotency_key);
|
|
734
|
+
if (existing) {
|
|
735
|
+
if (!sameEpicExecutionPlan(existing, input) || existing.attempt_id !== input.attempt_id || existing.roadmap_ticket_id !== input.roadmap_ticket_id || existing.phase !== input.phase
|
|
736
|
+
|| !same(existing.completed_build, input.completed_build ?? null) || existing.deferred !== (input.deferred ?? ['build_completed', 'pr_verified'].includes(input.phase))) {
|
|
737
|
+
fail('Checkpoint idempotency key was reused with different input', 409);
|
|
738
|
+
}
|
|
739
|
+
return existing;
|
|
740
|
+
}
|
|
741
|
+
mutate(input);
|
|
742
|
+
let attempt = requireAttempt(input, input.attempt_id);
|
|
743
|
+
if (attempt.status !== 'running') {
|
|
744
|
+
fail('Checkpoint requires a running attempt', 409);
|
|
745
|
+
}
|
|
746
|
+
const revision = requireRevision(input, attempt.revision_id);
|
|
747
|
+
if (attempt.kind === 'plan' && revision.plan?.kind === 'packages' && !attempt.tickets.length && input.phase === 'planned' && !input.deferred) {
|
|
748
|
+
attempt = freezeEpicPlanningInventory(attempt, getEpicMaterialization(input.epic_id, input.project_id));
|
|
749
|
+
}
|
|
750
|
+
if (!sameEpicExecutionPlan(attempt, input)) {
|
|
751
|
+
fail(epicPlanningMessage('checkpointPlanConflict'), 409);
|
|
752
|
+
}
|
|
753
|
+
const ticket = attempt.tickets.find(ticket => ticket.roadmap_ticket_id === input.roadmap_ticket_id) ?? fail('Ticket is not in attempt snapshot');
|
|
754
|
+
const phases = attempt.kind === 'plan' ? ['planned'] : ['build_completed', 'pr_verified', 'applied'];
|
|
755
|
+
const position = phases.indexOf(input.phase);
|
|
756
|
+
if (position < 0) {
|
|
757
|
+
fail('Checkpoint phase does not match attempt kind');
|
|
758
|
+
}
|
|
759
|
+
const previous = listEpicTicketCheckpoints(input.epic_id, input.project_id, attempt.id).filter(checkpoint => checkpoint.roadmap_ticket_id === ticket.roadmap_ticket_id);
|
|
760
|
+
if (previous.some(checkpoint => checkpoint.phase === input.phase)) {
|
|
761
|
+
fail('Ticket phase already checkpointed with a different key', 409);
|
|
762
|
+
}
|
|
763
|
+
if (position > 0 && !previous.some(checkpoint => checkpoint.phase === phases[position - 1])) {
|
|
764
|
+
fail('Checkpoint prerequisite is missing', 409);
|
|
765
|
+
}
|
|
766
|
+
const completed = input.completed_build ?? null;
|
|
767
|
+
if (attempt.kind === 'build') {
|
|
768
|
+
if (!completed) {
|
|
769
|
+
fail('Build checkpoints require completed build lineage');
|
|
770
|
+
}
|
|
771
|
+
validateBuild(completed);
|
|
772
|
+
if ((ticket.completed_build && !same(ticket.completed_build, completed)) || previous.some(checkpoint => !same(checkpoint.completed_build, completed))) {
|
|
773
|
+
fail('Completed build lineage cannot change', 409);
|
|
774
|
+
}
|
|
775
|
+
if (position > 0 && attempt.expected_pr && !attempt.pull_request) {
|
|
776
|
+
fail('PR verification must be recorded before ticket reconciliation', 409);
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
else if (completed) {
|
|
780
|
+
fail('Plan checkpoint cannot include build lineage');
|
|
781
|
+
}
|
|
782
|
+
const deferred = input.deferred ?? ['build_completed', 'pr_verified'].includes(input.phase);
|
|
783
|
+
if (typeof deferred !== 'boolean' || (input.phase === 'applied' && deferred)) {
|
|
784
|
+
fail('Applied checkpoint cannot remain deferred');
|
|
785
|
+
}
|
|
786
|
+
const checkpoint = { id: randomUUID(), epic_id: input.epic_id, project_id: input.project_id,
|
|
787
|
+
...(attempt.execution_plan_id ? { execution_plan_id: attempt.execution_plan_id, execution_plan_digest: attempt.execution_plan_digest } : {}),
|
|
788
|
+
attempt_id: attempt.id, roadmap_ticket_id: ticket.roadmap_ticket_id, ticket_id: ticket.ticket_id, phase: input.phase,
|
|
789
|
+
idempotency_key: input.idempotency_key, completed_build: completed, deferred, created_at: now() };
|
|
790
|
+
db.prepare('INSERT INTO epic_ticket_checkpoints (id, epic_id, project_id, attempt_id, roadmap_ticket_id, phase, idempotency_key, data_json, execution_plan_id, execution_plan_digest) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)').run(checkpoint.id, checkpoint.epic_id, checkpoint.project_id, attempt.id, ticket.roadmap_ticket_id, checkpoint.phase, checkpoint.idempotency_key, JSON.stringify(checkpoint), checkpoint.execution_plan_id ?? null, checkpoint.execution_plan_digest ?? null);
|
|
791
|
+
return checkpoint;
|
|
792
|
+
}).immediate();
|
|
793
|
+
export const appendEpicMessage = (input) => db.transaction(() => {
|
|
794
|
+
const epic = mutate(input);
|
|
795
|
+
if (!['user', 'assistant', 'system'].includes(input.role)) {
|
|
796
|
+
fail('Invalid message role');
|
|
797
|
+
}
|
|
798
|
+
if (input.attempt_id) {
|
|
799
|
+
requireAttempt(input, input.attempt_id);
|
|
800
|
+
}
|
|
801
|
+
const message = { id: randomUUID(), epic_id: input.epic_id, project_id: input.project_id,
|
|
802
|
+
role: input.role, content: text(input.content, 'message content'), attempt_id: input.attempt_id ?? null, created_at: now(),
|
|
803
|
+
mode: input.role === 'user' ? 'note' : 'planning', sequence: nextEpicMessageSequence(input.epic_id),
|
|
804
|
+
...epicMessageTranscripts(input.role, input.transcript_runs) };
|
|
805
|
+
insertEpicMessage(message);
|
|
806
|
+
advanceCurrentDrafts(epic);
|
|
807
|
+
return message;
|
|
808
|
+
}).immediate();
|
|
809
|
+
/** Transcript authority is independent of approval and execution authority. */
|
|
810
|
+
export const appendEpicConversationMessage = (input) => db.transaction(() => {
|
|
811
|
+
checkProject(input.project_id);
|
|
812
|
+
requireEpic(input);
|
|
813
|
+
if (!['user', 'assistant', 'system'].includes(input.role)) {
|
|
814
|
+
fail('Invalid message role');
|
|
815
|
+
}
|
|
816
|
+
const { transcript_runs: runs, ...fields } = input;
|
|
817
|
+
const message = { ...fields, id: randomUUID(), content: text(input.content, 'message content'),
|
|
818
|
+
attempt_id: null, sequence: nextEpicMessageSequence(input.epic_id), created_at: now(),
|
|
819
|
+
...epicMessageTranscripts(input.role, runs) };
|
|
820
|
+
insertEpicMessage(message);
|
|
821
|
+
return message;
|
|
822
|
+
}).immediate();
|
|
823
|
+
export const recordEpicDecision = (input) => db.transaction(() => {
|
|
824
|
+
mutate(input);
|
|
825
|
+
if (input.source_message_id && !evidence('epic_messages', input, input.source_message_id)) {
|
|
826
|
+
fail('Decision source message not found', 404);
|
|
827
|
+
}
|
|
828
|
+
if (input.supersedes_decision_id && !evidence('epic_decisions', input, input.supersedes_decision_id)) {
|
|
829
|
+
fail('Superseded decision not found', 404);
|
|
830
|
+
}
|
|
831
|
+
if (input.supersedes_decision_id && listEpicDecisions(input.epic_id, input.project_id).some(decision => decision.supersedes_decision_id === input.supersedes_decision_id)) {
|
|
832
|
+
fail('Decision is already superseded', 409);
|
|
833
|
+
}
|
|
834
|
+
const decision = { id: randomUUID(), epic_id: input.epic_id, project_id: input.project_id,
|
|
835
|
+
title: text(input.title, 'decision title'), decision: text(input.decision, 'decision'), rationale: input.rationale ?? null,
|
|
836
|
+
source_message_id: input.source_message_id ?? null, supersedes_decision_id: input.supersedes_decision_id ?? null, created_at: now() };
|
|
837
|
+
db.prepare('INSERT INTO epic_decisions (id, epic_id, project_id, source_message_id, supersedes_decision_id, data_json) VALUES (?, ?, ?, ?, ?, ?)').run(decision.id, decision.epic_id, decision.project_id, decision.source_message_id, decision.supersedes_decision_id, JSON.stringify(decision));
|
|
838
|
+
return decision;
|
|
839
|
+
}).immediate();
|
|
840
|
+
//# sourceMappingURL=epics.js.map
|