@akanjs/devkit 3.2.0-rc.9 → 3.2.1-rc.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/CHANGELOG.md +0 -529
- package/DEV_RUNTIME_KNOBS.md +4 -3
- package/README.ko.md +3 -2
- package/README.md +4 -2
- package/akanApp/BackendImportGraph.test.ts +1 -1
- package/akanApp/akanApp.host.test.ts +152 -6
- package/akanApp/akanApp.host.ts +187 -1220
- package/akanApp/akanApp.host.wiring.test.ts +931 -0
- package/akanApp/builderGap.ts +68 -0
- package/akanApp/builderRequestRelay.test.ts +93 -0
- package/akanApp/builderRequestRelay.ts +100 -0
- package/akanApp/builderRssRecycler.ts +182 -0
- package/akanApp/devBackend.ts +394 -0
- package/akanApp/devBuildStatusBoard.ts +128 -0
- package/akanApp/devBuilder.ts +200 -0
- package/akanApp/devIdleSuspend.test.ts +221 -0
- package/akanApp/devIdleSuspend.ts +192 -0
- package/akanApp/devIdleSuspend.watcher.test.ts +120 -0
- package/akanApp/devRecycler.test.ts +66 -0
- package/akanApp/devRecycler.ts +305 -0
- package/akanApp/devStartTimeline.test.ts +115 -0
- package/akanApp/devStartTimeline.ts +69 -0
- package/akanApp/processRss.ts +61 -0
- package/akanConfig/akanConfig.test.ts +45 -17
- package/akanConfig/akanConfig.ts +10 -10
- package/akanConfig/akanWorkspaceConfig.ts +1 -1
- package/akanConfig/productionLockfile.ts +1 -1
- package/apiReport/apiReport.test.ts +34 -3
- package/apiReport/apiReportDiff.ts +35 -1
- package/apiReport/apiReportPolicy.ts +3 -2
- package/{applicationBuildReporter.ts → app/applicationBuildReporter.ts} +2 -49
- package/{applicationBuildRunner.test.ts → app/applicationBuildRunner.test.ts} +71 -8
- package/{applicationBuildRunner.ts → app/applicationBuildRunner.ts} +60 -21
- package/{applicationTestPreload.ts → app/applicationTestPreload.ts} +1 -1
- package/{routeJsBudget.test.ts → app/routeJsBudget.test.ts} +17 -1
- package/{routeJsBudget.ts → app/routeJsBudget.ts} +9 -3
- package/{routeSourceValidator.test.ts → app/routeSourceValidator.test.ts} +17 -0
- package/{routeSourceValidator.ts → app/routeSourceValidator.ts} +5 -1
- package/artifact/implicitRootLayout.test.ts +71 -3
- package/artifact/implicitRootLayout.ts +9 -3
- package/artifact/implicitRootLayoutRender.test.tsx +297 -0
- package/biome.base.json +2 -1
- package/cloud/cloudApi.test.ts +1 -1
- package/cloud/configLock.test.ts +1 -1
- package/cloud/globalConfig.test.ts +1 -1
- package/cloud/globalConfig.ts +1 -1
- package/cloud/updatePackUpload.test.ts +1 -1
- package/codeAgent/agent/AkanCodeEnv.ts +1 -1
- package/codeAgent/agent/AkanCodeServices.ts +23 -0
- package/codeAgent/agent/akanCodePaths.ts +1 -1
- package/codeAgent/agent/akanCodeServices.test.ts +54 -0
- package/codeAgent/agent/akanSystemPrompt.ts +1 -1
- package/codeAgent/agent/codeAgent.test.ts +1 -1
- package/codeAgent/skills/akan-debug/SKILL.md +8 -5
- package/codeAgent/skills/akan-err/SKILL.md +7 -0
- package/codeAgent/skills/akan-mcp/SKILL.md +19 -1
- package/codeAgent/skills/akan-scaffold/SKILL.md +1 -1
- package/codeAgent/skills/akan-validate/SKILL.md +3 -3
- package/codeAgent/tools/AkanCli.ts +1 -1
- package/codeAgent/tools/AkanToolPack.ts +2 -2
- package/codeAgent/tools/akanCodePlugins.test.ts +1 -1
- package/commandDecorators/command.ts +35 -6
- package/commandDecorators/commandBuilder.ts +1 -1
- package/commandDecorators/commandDecorators.test.ts +107 -6
- package/commandDecorators/targetMeta.ts +2 -0
- package/commandDecorators/workspaceVersionCheck.test.ts +70 -1
- package/commandDecorators/workspaceVersionCheck.ts +64 -14
- package/context/akanContext.ts +576 -0
- package/context/akanContextInspection.ts +296 -0
- package/{akanMcpContract.test.ts → context/akanMcpContract.test.ts} +1 -1
- package/{akanMcpContract.ts → context/akanMcpContract.ts} +16 -256
- package/context/doctor/agentGuideCheck.ts +81 -0
- package/context/doctor/configLeftoverCheck.ts +35 -0
- package/context/doctor/doctorFindings.ts +70 -0
- package/context/doctor/generatedFreshness.ts +56 -0
- package/context/doctor/moduleShapeCheck.ts +88 -0
- package/context/doctor/recipeDuplicateCheck.ts +42 -0
- package/context/doctor/recipeIndexCheck.ts +87 -0
- package/context/doctor/rootShapeCheck.ts +55 -0
- package/context/doctor/workflowScope.ts +97 -0
- package/{recipeScanner.test.ts → context/recipeScanner.test.ts} +1 -1
- package/context/safeRead.ts +9 -0
- package/csrE2e/csrE2eHarness.fixture.ts +1 -1
- package/devkitUtils.test.ts +39 -5
- package/{apiReference.test.ts → docs/apiReference.test.ts} +4 -4
- package/{apiReference.ts → docs/apiReference.ts} +2 -2
- package/docs/errorCodeReference.test.ts +282 -0
- package/docs/errorCodeReference.ts +71 -0
- package/docs/errorCodeScan.ts +551 -0
- package/{frameworkGraph.test.ts → docs/frameworkGraph.test.ts} +1 -1
- package/executors/appExecutor.ts +463 -0
- package/executors/commandExecutionError.ts +53 -0
- package/executors/executor.ts +527 -0
- package/{executors.linkFallback.test.ts → executors/executors.linkFallback.test.ts} +1 -1
- package/{executors.test.ts → executors/executors.test.ts} +106 -18
- package/executors/index.ts +8 -0
- package/executors/libExecutor.ts +23 -0
- package/executors/moduleExecutor.ts +18 -0
- package/executors/pkgExecutor.ts +129 -0
- package/executors/sysExecutor.ts +301 -0
- package/executors/workspaceExecutor.ts +277 -0
- package/frontendBuild/allRoutesBuilder.test.ts +1 -1
- package/frontendBuild/autoImportSync.test.ts +1 -1
- package/frontendBuild/autoImportSync.ts +1 -1
- package/frontendBuild/buildCacheStamp.test.ts +42 -0
- package/frontendBuild/buildCacheStamp.ts +23 -0
- package/frontendBuild/buildRouteClient.test.ts +1 -1
- package/frontendBuild/clientEntriesBundler.test.ts +1 -1
- package/frontendBuild/csrArtifactBuilder.test.ts +1 -1
- package/frontendBuild/csrDevArtifactWriter.ts +1 -1
- package/frontendBuild/cssCandidateCache.test.ts +70 -1
- package/frontendBuild/cssCandidateCache.ts +17 -10
- package/frontendBuild/cssCompiler.test.ts +3 -2
- package/frontendBuild/devGeneratedIndexSync.test.ts +1 -1
- package/frontendBuild/devGeneratedIndexSync.ts +7 -38
- package/frontendBuild/dictionaryAssetBuilder.test.ts +1 -1
- package/frontendBuild/fontOptimizer.test.ts +145 -4
- package/frontendBuild/fontOptimizer.ts +103 -18
- package/frontendBuild/fontPruner.test.ts +1 -1
- package/frontendBuild/frontendBuild.test.ts +3 -3
- package/frontendBuild/hmrWatcher.stop.test.ts +63 -0
- package/frontendBuild/hmrWatcher.test.ts +1 -1
- package/frontendBuild/hmrWatcher.ts +22 -1
- package/frontendBuild/mcpAppViewBuilder.test.ts +1 -1
- package/frontendBuild/mcpAppViewBuilder.ts +1 -1
- package/frontendBuild/nativeCore.test.ts +1 -1
- package/frontendBuild/optionalPeers.test.ts +36 -8
- package/frontendBuild/pagesBundleBuilder.test.ts +2 -3
- package/frontendBuild/pagesBundleBuilder.ts +1 -1
- package/frontendBuild/precompressArtifacts.test.ts +1 -1
- package/frontendBuild/precompressArtifacts.ts +19 -6
- package/frontendBuild/serverGraphFile.ts +1 -1
- package/frontendBuild/sourceMtimeIndex.test.ts +1 -1
- package/frontendBuild/ssrBaseArtifactBuilder.test.ts +30 -1
- package/frontendBuild/ssrBaseArtifactBuilder.ts +40 -12
- package/frontendBuild/ssrDevBundler.test.ts +1 -1
- package/frontendBuild/vendorImportScanner.test.ts +1 -1
- package/frontendBuild/vendorNarrowing.test.ts +1 -1
- package/frontendBuild/watchRootResolver.test.ts +1 -1
- package/{agentAssets.test.ts → guideline/agentAssets.test.ts} +1 -1
- package/{agentAssets.ts → guideline/agentAssets.ts} +2 -2
- package/{agentsIndex.test.ts → guideline/agentsIndex.test.ts} +2 -2
- package/{agentsIndex.ts → guideline/agentsIndex.ts} +13 -10
- package/{conventionSet.test.ts → guideline/conventionSet.test.ts} +7 -4
- package/{conventionSet.ts → guideline/conventionSet.ts} +1 -1
- package/{prompter.ts → guideline/prompter.ts} +2 -3
- package/incrementalBuilder/buildBatch.proc.ts +16 -5
- package/incrementalBuilder/buildBatchProtocol.ts +3 -0
- package/incrementalBuilder/buildBatchRunner.test.ts +122 -2
- package/incrementalBuilder/buildBatchRunner.ts +17 -4
- package/incrementalBuilder/builderBoot.ts +113 -0
- package/incrementalBuilder/builderBuildStatus.ts +23 -0
- package/incrementalBuilder/builderChannel.test.ts +1 -1
- package/incrementalBuilder/builderChannel.ts +19 -2
- package/incrementalBuilder/builderGraphPayloads.ts +3 -3
- package/incrementalBuilder/builderLanes.ts +157 -0
- package/incrementalBuilder/builderWatch.ts +213 -0
- package/incrementalBuilder/csrRegistry.ts +234 -0
- package/incrementalBuilder/incrementalBuilder.host.test.ts +16 -0
- package/incrementalBuilder/incrementalBuilder.host.ts +7 -1
- package/incrementalBuilder/incrementalBuilder.proc.test.ts +142 -7
- package/incrementalBuilder/incrementalBuilder.proc.ts +82 -823
- package/incrementalBuilder/ssrRegistry.ts +282 -0
- package/index.ts +22 -22
- package/integration/devStability.integration.test.ts +62 -56
- package/integration/devStabilityHarness.test.ts +1 -1
- package/lint/__fixtures__/no-import-common-err/bad.tsx +13 -0
- package/lint/__fixtures__/no-import-common-err/good.tsx +12 -0
- package/{biomeBase.test.ts → lint/biomeBase.test.ts} +1 -1
- package/lint/gritRules.test.ts +1 -1
- package/{linter.test.ts → lint/linter.test.ts} +1 -1
- package/lint/no-import-common-err.grit +31 -0
- package/lint/no-init-fetch-in-client.grit +1 -1
- package/mobile/desktopBin.test.ts +1 -1
- package/mobile/desktopRelease.test.ts +1 -1
- package/mobile/desktopServerStage.test.ts +2 -2
- package/mobile/desktopServerStage.ts +1 -1
- package/mobile/nativeApi.test.ts +1 -1
- package/mobile/nativeApp.test.ts +1 -1
- package/mobile/nativeConfig.test.ts +1 -1
- package/mobile/nativePluginFolders.test.ts +1 -1
- package/mobile/nativePublicEnv.test.ts +1 -1
- package/mobile/nativePublicEnv.ts +2 -1
- package/mobile/nativeWebDir.test.ts +1 -1
- package/mobile/serverBundleSecrets.test.ts +1 -1
- package/mobile/tarWriter.test.ts +1 -1
- package/mobile/updatePackFolder.test.ts +1 -1
- package/package.json +173 -9
- package/packageExports.test.ts +20 -2
- package/piDependencyPins.test.ts +1 -1
- package/pipeline/PipelineDefinition.ts +1 -1
- package/platformTest/IdleWatchedProcess.test.ts +1 -1
- package/platformTest/LinuxDockerTarget.ts +1 -1
- package/platformTest/PlatformTestRun.test.ts +1 -1
- package/platformTest/TestSnapshot.test.ts +1 -1
- package/platformTest/WindowsSshTarget.ts +1 -1
- package/preview/previewView.test.ts +23 -1
- package/{abstractDoc.test.ts → quality/abstractDoc.test.ts} +2 -2
- package/{abstractDoc.ts → quality/abstractDoc.ts} +1 -1
- package/quality/bareErrorScanner.ts +126 -0
- package/{maintainabilityBaseline.test.ts → quality/maintainabilityBaseline.test.ts} +73 -0
- package/{maintainabilityBaseline.ts → quality/maintainabilityBaseline.ts} +97 -9
- package/{maintainabilityContract.test.ts → quality/maintainabilityContract.test.ts} +383 -2
- package/{maintainabilityContract.ts → quality/maintainabilityContract.ts} +151 -29
- package/{maintainabilityExceptionScanner.test.ts → quality/maintainabilityExceptionScanner.test.ts} +15 -1
- package/{maintainabilityExceptionScanner.ts → quality/maintainabilityExceptionScanner.ts} +5 -1
- package/{maintainabilityLimits.ts → quality/maintainabilityLimits.ts} +12 -0
- package/{maintainabilityReport.ts → quality/maintainabilityReport.ts} +20 -3
- package/{qualityScanner.test.ts → quality/qualityScanner.test.ts} +41 -1
- package/{qualityScanner.ts → quality/qualityScanner.ts} +25 -91
- package/{storeAccessScanner.ts → quality/storeAccessScanner.ts} +15 -2
- package/quality/workspaceSourceFiles.ts +82 -0
- package/{subspace.test.ts → subspace/subspace.test.ts} +25 -4
- package/{subspace.ts → subspace/subspace.ts} +5 -5
- package/{subspaceClone.ts → subspace/subspaceClone.ts} +8 -8
- package/{subspaceConfig.ts → subspace/subspaceConfig.ts} +5 -1
- package/{testHelpers.ts → test/testHelpers.ts} +37 -1
- package/transforms/barrelAnalyzer.ts +31 -10
- package/transforms/browserDirnamePlugin.test.ts +1 -1
- package/transforms/externalizeFrameworkPlugin.test.ts +1 -1
- package/transforms/mcpAppPageTrimmer.test.ts +1 -1
- package/transforms/pureLazyMarker.test.ts +1 -1
- package/transforms/serverEnvPlugin.test.ts +1 -1
- package/transforms/serverEnvProfile.test.ts +1 -1
- package/transforms/sideEffectImportOrder.test.ts +1 -1
- package/transforms/transforms.test.ts +52 -2
- package/transforms/tsconfigPackageResolver.test.ts +1 -1
- package/{createTunnel.test.ts → tunnel/createTunnel.test.ts} +1 -1
- package/{createTunnel.ts → tunnel/createTunnel.ts} +2 -2
- package/{sshHostKeys.ts → tunnel/sshHostKeys.ts} +2 -2
- package/typecheck/projectTypecheck.test.ts +23 -1
- package/typecheck/projectTypecheck.ts +10 -2
- package/{typeChecker.test.ts → typecheck/typeChecker.test.ts} +1 -1
- package/{typeChecker.ts → typecheck/typeChecker.ts} +5 -4
- package/typecheck/typecheck.proc.ts +6 -2
- package/typecheck/typecheckFailure.ts +1 -1
- package/util/errorReport.ts +66 -0
- package/{fileSys.test.ts → util/fileSys.test.ts} +13 -0
- package/{fileSys.ts → util/fileSys.ts} +2 -2
- package/{jsonFormatter.test.ts → util/jsonFormatter.test.ts} +1 -1
- package/workflow/constantSource.ts +187 -0
- package/workflow/dictionarySource.ts +184 -0
- package/workflow/executor.ts +6 -9
- package/workflow/fieldExpression.ts +153 -0
- package/workflow/fieldLabel.ts +61 -0
- package/workflow/fieldOrder.ts +117 -0
- package/workflow/fieldType.ts +2 -1
- package/workflow/guardCatalog.test.ts +1 -1
- package/workflow/keyRename.ts +1 -1
- package/workflow/moduleIndex.test.ts +2 -2
- package/workflow/moduleIndex.ts +2 -2
- package/workflow/modulePaths.ts +27 -0
- package/workflow/mutationScaffold.ts +7 -15
- package/workflow/mutationSource.ts +2 -1
- package/workflow/plan.ts +2 -1
- package/workflow/primitiveReport.ts +78 -0
- package/workflow/rolloutGate.test.ts +1 -1
- package/workflow/rolloutGate.ts +1 -1
- package/workflow/serviceSource.ts +33 -0
- package/workflow/signalSource.ts +96 -0
- package/workflow/source.ts +50 -1100
- package/workflow/sourceAst.ts +30 -0
- package/workflow/sourceImports.ts +105 -0
- package/workflow/sourceText.ts +13 -0
- package/workflow/templateSource.ts +30 -0
- package/workflow/testSource.ts +31 -0
- package/workflow/types.ts +1 -1
- package/workflow/uiPolicy.ts +1 -1
- package/{appSelectionMemory.ts → workspace/appSelectionMemory.ts} +1 -1
- package/{codegenLock.test.ts → workspace/codegenLock.test.ts} +1 -1
- package/{dependencyScanner.test.ts → workspace/dependencyScanner.test.ts} +1 -1
- package/{dependencyScanner.ts → workspace/dependencyScanner.ts} +2 -2
- package/{envSeed.test.ts → workspace/envSeed.test.ts} +2 -2
- package/{envSeed.ts → workspace/envSeed.ts} +1 -1
- package/{libSource.test.ts → workspace/libSource.test.ts} +2 -2
- package/{libSource.ts → workspace/libSource.ts} +1 -1
- package/{scanInfo.ts → workspace/scanInfo.ts} +21 -10
- package/{slicePlanner.test.ts → workspace/slicePlanner.test.ts} +2 -2
- package/{slicePlanner.ts → workspace/slicePlanner.ts} +1 -1
- package/{workspaceGraph.test.ts → workspace/workspaceGraph.test.ts} +1 -1
- package/{workspaceGraph.ts → workspace/workspaceGraph.ts} +1 -1
- package/{workspaceLayout.test.ts → workspace/workspaceLayout.test.ts} +1 -1
- package/{workspaceLayout.ts → workspace/workspaceLayout.ts} +3 -1
- package/akanContext.ts +0 -1083
- package/executors.ts +0 -1749
- /package/{applicationBuildReporter.test.ts → app/applicationBuildReporter.test.ts} +0 -0
- /package/{akanMcpToolError.ts → context/akanMcpToolError.ts} +0 -0
- /package/{moduleFieldNames.test.ts → context/moduleFieldNames.test.ts} +0 -0
- /package/{moduleFieldNames.ts → context/moduleFieldNames.ts} +0 -0
- /package/{recipeScanner.ts → context/recipeScanner.ts} +0 -0
- /package/{declarationReader.ts → docs/declarationReader.ts} +0 -0
- /package/{frameworkGraph.ts → docs/frameworkGraph.ts} +0 -0
- /package/{biomeBase.ts → lint/biomeBase.ts} +0 -0
- /package/{linter.ts → lint/linter.ts} +0 -0
- /package/{commentDensityScanner.test.ts → quality/commentDensityScanner.test.ts} +0 -0
- /package/{commentDensityScanner.ts → quality/commentDensityScanner.ts} +0 -0
- /package/{componentSizeScanner.test.ts → quality/componentSizeScanner.test.ts} +0 -0
- /package/{componentSizeScanner.ts → quality/componentSizeScanner.ts} +0 -0
- /package/{componentWriteChainScanner.test.ts → quality/componentWriteChainScanner.test.ts} +0 -0
- /package/{componentWriteChainScanner.ts → quality/componentWriteChainScanner.ts} +0 -0
- /package/{deprecatedCommentScanner.test.ts → quality/deprecatedCommentScanner.test.ts} +0 -0
- /package/{deprecatedCommentScanner.ts → quality/deprecatedCommentScanner.ts} +0 -0
- /package/{endpointReach.test.ts → quality/endpointReach.test.ts} +0 -0
- /package/{endpointReach.ts → quality/endpointReach.ts} +0 -0
- /package/{formSetterScanner.test.ts → quality/formSetterScanner.test.ts} +0 -0
- /package/{formSetterScanner.ts → quality/formSetterScanner.ts} +0 -0
- /package/{kindBranchScanner.test.ts → quality/kindBranchScanner.test.ts} +0 -0
- /package/{kindBranchScanner.ts → quality/kindBranchScanner.ts} +0 -0
- /package/{maintainabilityReport.test.ts → quality/maintainabilityReport.test.ts} +0 -0
- /package/{renderMutationScanner.test.ts → quality/renderMutationScanner.test.ts} +0 -0
- /package/{renderMutationScanner.ts → quality/renderMutationScanner.ts} +0 -0
- /package/{serviceLoopCallScanner.test.ts → quality/serviceLoopCallScanner.test.ts} +0 -0
- /package/{serviceLoopCallScanner.ts → quality/serviceLoopCallScanner.ts} +0 -0
- /package/{signalMutationIndex.test.ts → quality/signalMutationIndex.test.ts} +0 -0
- /package/{signalMutationIndex.ts → quality/signalMutationIndex.ts} +0 -0
- /package/{sourceComments.test.ts → quality/sourceComments.test.ts} +0 -0
- /package/{sourceComments.ts → quality/sourceComments.ts} +0 -0
- /package/{ssrScanner.test.ts → quality/ssrScanner.test.ts} +0 -0
- /package/{ssrScanner.ts → quality/ssrScanner.ts} +0 -0
- /package/{storeAccessScanner.test.ts → quality/storeAccessScanner.test.ts} +0 -0
- /package/{storeSource.ts → quality/storeSource.ts} +0 -0
- /package/{storeWriteScanner.test.ts → quality/storeWriteScanner.test.ts} +0 -0
- /package/{storeWriteScanner.ts → quality/storeWriteScanner.ts} +0 -0
- /package/{structureScanner.test.ts → quality/structureScanner.test.ts} +0 -0
- /package/{structureScanner.ts → quality/structureScanner.ts} +0 -0
- /package/{testOnlyExportScanner.test.ts → quality/testOnlyExportScanner.test.ts} +0 -0
- /package/{testOnlyExportScanner.ts → quality/testOnlyExportScanner.ts} +0 -0
- /package/{writePath.test.ts → quality/writePath.test.ts} +0 -0
- /package/{writePath.ts → quality/writePath.ts} +0 -0
- /package/{writePlacementScanner.test.ts → quality/writePlacementScanner.test.ts} +0 -0
- /package/{writePlacementScanner.ts → quality/writePlacementScanner.ts} +0 -0
- /package/{writingActionIndex.test.ts → quality/writingActionIndex.test.ts} +0 -0
- /package/{writingActionIndex.ts → quality/writingActionIndex.ts} +0 -0
- /package/{subspaceReport.ts → subspace/subspaceReport.ts} +0 -0
- /package/{sshTunnel.ts → tunnel/sshTunnel.ts} +0 -0
- /package/{fileEditor.ts → util/fileEditor.ts} +0 -0
- /package/{jsonFormatter.ts → util/jsonFormatter.ts} +0 -0
- /package/{selectModel.ts → util/selectModel.ts} +0 -0
- /package/{semver.test.ts → util/semver.test.ts} +0 -0
- /package/{semver.ts → util/semver.ts} +0 -0
- /package/{shellOnlyEnv.test.ts → util/shellOnlyEnv.test.ts} +0 -0
- /package/{shellOnlyEnv.ts → util/shellOnlyEnv.ts} +0 -0
- /package/{spinner.test.ts → util/spinner.test.ts} +0 -0
- /package/{spinner.ts → util/spinner.ts} +0 -0
- /package/{stripAnsi.ts → util/stripAnsi.ts} +0 -0
- /package/{codegenLock.ts → workspace/codegenLock.ts} +0 -0
- /package/{getRelatedCnsts.ts → workspace/getRelatedCnsts.ts} +0 -0
- /package/{gitRevision.test.ts → workspace/gitRevision.test.ts} +0 -0
- /package/{gitRevision.ts → workspace/gitRevision.ts} +0 -0
- /package/{manifestDependencies.ts → workspace/manifestDependencies.ts} +0 -0
- /package/{packageExportsMap.ts → workspace/packageExportsMap.ts} +0 -0
- /package/{repoIdentity.ts → workspace/repoIdentity.ts} +0 -0
- /package/{types.ts → workspace/types.ts} +0 -0
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
import { type Logger, RestartSchedule } from "akanjs/common";
|
|
2
|
+
import type { BuilderMessage, DevBuildStatus } from "akanjs/server";
|
|
3
|
+
import type { App } from "../commandDecorators";
|
|
4
|
+
import type { DevStdioMode } from "../incrementalBuilder";
|
|
5
|
+
import type { BackendImportGraph } from "./BackendImportGraph";
|
|
6
|
+
import type { DevBuildStatusBoard } from "./devBuildStatusBoard";
|
|
7
|
+
import {
|
|
8
|
+
type BackendLifecycleState,
|
|
9
|
+
type BackendRestartReason,
|
|
10
|
+
backendRecoveryPolicy,
|
|
11
|
+
type DevHostState,
|
|
12
|
+
devHostStateOf,
|
|
13
|
+
mergeBackendRestartReasons,
|
|
14
|
+
normalizeBackendReportedGeneration,
|
|
15
|
+
shouldQueueBuildStatusReplay,
|
|
16
|
+
} from "./devHostPolicy";
|
|
17
|
+
|
|
18
|
+
const backendMsgTypeSet = new Set<BuilderMessage["type"]>(["build-route", "build-csr", "build-graph"]);
|
|
19
|
+
|
|
20
|
+
const BACKEND_RESTART_DEBOUNCE_MS = 120;
|
|
21
|
+
|
|
22
|
+
// Above the gateway's ~5s child-shutdown wait: a gateway SIGKILLed mid-shutdown strands orphan replicas.
|
|
23
|
+
const BACKEND_GRACEFUL_TIMEOUT_MS = 8_000;
|
|
24
|
+
|
|
25
|
+
const BACKEND_STDERR_TAIL_LIMIT = 40;
|
|
26
|
+
|
|
27
|
+
type BackendProcess = Bun.Subprocess<"ignore", "inherit" | "pipe", "inherit" | "pipe">;
|
|
28
|
+
|
|
29
|
+
interface DevBackendLinks {
|
|
30
|
+
isStopping: () => boolean;
|
|
31
|
+
emit: (state: DevHostState, detail?: string) => void;
|
|
32
|
+
beforeSpawn: () => void;
|
|
33
|
+
awaitsArtifact: () => boolean;
|
|
34
|
+
toBuilder: (message: BuilderMessage) => void;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export class DevBackend {
|
|
38
|
+
readonly #app: App;
|
|
39
|
+
readonly #env: Record<string, string>;
|
|
40
|
+
readonly #stdio: DevStdioMode;
|
|
41
|
+
readonly #logger: Logger;
|
|
42
|
+
readonly #statuses: DevBuildStatusBoard;
|
|
43
|
+
readonly #graph: BackendImportGraph;
|
|
44
|
+
readonly #links: DevBackendLinks;
|
|
45
|
+
#process: BackendProcess | null = null;
|
|
46
|
+
#ready = false;
|
|
47
|
+
#plannedStops = new WeakSet<Bun.Subprocess<"ignore", "inherit", "inherit">>();
|
|
48
|
+
#restartTimer: ReturnType<typeof setTimeout> | null = null;
|
|
49
|
+
readonly #recovery = new RestartSchedule(backendRecoveryPolicy);
|
|
50
|
+
#gaveUp = false;
|
|
51
|
+
#lifecycleState: BackendLifecycleState = "stopped";
|
|
52
|
+
#pendingRestartReason: BackendRestartReason | null = null;
|
|
53
|
+
//? One replacement at a time: `stop()` clears `#process` only once the old process exits, so a second restart inside
|
|
54
|
+
//? that wait signals the same pid and spawns a second backend, and the one the host stops tracking keeps the port.
|
|
55
|
+
#restart: Promise<void> | null = null;
|
|
56
|
+
#startStatus: { generation?: number; files: string[] } | null = null;
|
|
57
|
+
#stderrTail: string[] = [];
|
|
58
|
+
#queuedStatuses: DevBuildStatus[] = [];
|
|
59
|
+
|
|
60
|
+
constructor(
|
|
61
|
+
app: App,
|
|
62
|
+
{
|
|
63
|
+
env,
|
|
64
|
+
stdio,
|
|
65
|
+
logger,
|
|
66
|
+
statuses,
|
|
67
|
+
graph,
|
|
68
|
+
}: {
|
|
69
|
+
env: Record<string, string>;
|
|
70
|
+
stdio: DevStdioMode;
|
|
71
|
+
logger: Logger;
|
|
72
|
+
statuses: DevBuildStatusBoard;
|
|
73
|
+
graph: BackendImportGraph;
|
|
74
|
+
},
|
|
75
|
+
links: DevBackendLinks,
|
|
76
|
+
) {
|
|
77
|
+
this.#app = app;
|
|
78
|
+
this.#env = env;
|
|
79
|
+
this.#stdio = stdio;
|
|
80
|
+
this.#logger = logger;
|
|
81
|
+
this.#statuses = statuses;
|
|
82
|
+
this.#graph = graph;
|
|
83
|
+
this.#links = links;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
get running(): boolean {
|
|
87
|
+
return !!this.#process;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
get ready(): boolean {
|
|
91
|
+
return this.#ready;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
get gaveUp(): boolean {
|
|
95
|
+
return this.#gaveUp;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
get lifecycleState(): BackendLifecycleState {
|
|
99
|
+
return this.#lifecycleState;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
get restartScheduled(): boolean {
|
|
103
|
+
return !!this.#restartTimer;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
get recovering(): boolean {
|
|
107
|
+
return this.#recovery.pending;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
get restartPending(): boolean {
|
|
111
|
+
return !!(this.#restartTimer || this.#restart || this.#recovery.pending);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
get restarting(): Promise<void> | null {
|
|
115
|
+
return this.#restart;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
start(startStatus: { generation?: number; files: string[] } | null = null) {
|
|
119
|
+
if (this.#links.isStopping()) return;
|
|
120
|
+
if (this.#process) {
|
|
121
|
+
this.#logger.warn(`backend pid=${this.#process.pid} is still running; not starting a second one`);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
this.#links.beforeSpawn();
|
|
125
|
+
this.#startStatus = startStatus;
|
|
126
|
+
this.#gaveUp = false;
|
|
127
|
+
this.#setLifecycleState("starting");
|
|
128
|
+
this.#ready = false;
|
|
129
|
+
this.#stderrTail = [];
|
|
130
|
+
const backend = Bun.spawn(["bun", `apps/${this.#app.name}/main.ts`], {
|
|
131
|
+
cwd: this.#app.workspace.workspaceRoot,
|
|
132
|
+
stdio: this.#stdio === "pipe" ? ["ignore", "pipe", "pipe"] : ["inherit", "inherit", "inherit"],
|
|
133
|
+
//? The first base build is still running: the backend boots beside it and holds its web surface for the artifact.
|
|
134
|
+
env: this.#links.awaitsArtifact() ? { ...this.#env, AKAN_DEV_AWAIT_ARTIFACT: "1" } : this.#env,
|
|
135
|
+
ipc: (msg: BuilderMessage) => {
|
|
136
|
+
if (!msg || typeof msg !== "object") return;
|
|
137
|
+
if (msg.type === "backend-ready") {
|
|
138
|
+
this.#ready = true;
|
|
139
|
+
this.#recovery.reset();
|
|
140
|
+
this.#setLifecycleState("ready", `pid=${msg.pid}`);
|
|
141
|
+
this.#recordReadyStatus();
|
|
142
|
+
this.#logger.verbose(`backend ready pid=${msg.pid}`);
|
|
143
|
+
this.#forgetRouteBuildStatus();
|
|
144
|
+
this.replay();
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
if (msg.type === "build-status") {
|
|
148
|
+
// The gateway reports replica boot failures (crash loops, port conflicts) as build-status.
|
|
149
|
+
const status = this.#statuses.recordBackend({
|
|
150
|
+
generation: normalizeBackendReportedGeneration(msg.data.generation),
|
|
151
|
+
ok: msg.data.ok,
|
|
152
|
+
files: msg.data.files,
|
|
153
|
+
message: msg.data.message,
|
|
154
|
+
});
|
|
155
|
+
this.sendOrQueueStatus(status);
|
|
156
|
+
//? A replica crash loop leaves the gateway up, waiting for an edit: no exit reaches the host's own give-up.
|
|
157
|
+
if (!status.ok) this.#links.emit("failed", status.message);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if (backendMsgTypeSet.has(msg.type)) this.#links.toBuilder(msg);
|
|
161
|
+
},
|
|
162
|
+
serialization: "advanced",
|
|
163
|
+
onExit: () => {
|
|
164
|
+
this.#ready = false;
|
|
165
|
+
if (this.#process === backend) this.#process = null;
|
|
166
|
+
if (this.#plannedStops.has(backend)) {
|
|
167
|
+
this.#plannedStops.delete(backend);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
this.#scheduleRecovery("backend-exit");
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
this.#process = backend;
|
|
174
|
+
this.#logger.verbose(`backend spawned pid=${backend.pid}`);
|
|
175
|
+
if (this.#stdio === "pipe") {
|
|
176
|
+
// Undrained pipes swallow runtime errors and leave the crash-loop stderr tail empty.
|
|
177
|
+
void this.#forwardStream(backend.stderr as unknown as ReadableStream<Uint8Array> | undefined, "stderr");
|
|
178
|
+
void this.#forwardStream(backend.stdout as unknown as ReadableStream<Uint8Array> | undefined, "stdout");
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
send(message: BuilderMessage) {
|
|
183
|
+
if (!this.#process || !this.#ready) {
|
|
184
|
+
if (message.type === "css-updated" || message.type === "pages-updated" || message.type === "build-status") {
|
|
185
|
+
this.#logger.verbose(`backend is not ready; will replay ${message.type}`);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
if (message.type !== "builder-ready") this.#logger.warn(`backend is not ready; dropping ${message.type}`);
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
try {
|
|
192
|
+
this.#process.send(message);
|
|
193
|
+
} catch (err) {
|
|
194
|
+
this.#logger.warn(
|
|
195
|
+
`failed to send ${message.type} to backend: ${err instanceof Error ? err.message : String(err)}`,
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
sendOrQueueStatus(status: DevBuildStatus): void {
|
|
201
|
+
if (!this.#process || shouldQueueBuildStatusReplay(this.#ready, this.#queuedStatuses.length)) {
|
|
202
|
+
this.#queuedStatuses.push(status);
|
|
203
|
+
this.#logger.verbose(
|
|
204
|
+
`backend is not ready; will replay build-status generation=${status.generation} phase=${status.phase}`,
|
|
205
|
+
);
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
this.send({ type: "build-status", data: status });
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
replay(): void {
|
|
212
|
+
if (!this.#ready) return;
|
|
213
|
+
const { css, pages } = this.#statuses.lastGood;
|
|
214
|
+
if (css) this.send(css);
|
|
215
|
+
if (pages) this.send(pages);
|
|
216
|
+
const queuedStatuses = this.#queuedStatuses.splice(0);
|
|
217
|
+
for (const status of this.#statuses.replaySequence(queuedStatuses)) {
|
|
218
|
+
this.send({ type: "build-status", data: status });
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
dropQueuedStatuses(): void {
|
|
223
|
+
this.#queuedStatuses = [];
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
async stop() {
|
|
227
|
+
if (!this.#process) return;
|
|
228
|
+
const backend = this.#process;
|
|
229
|
+
this.#plannedStops.add(backend);
|
|
230
|
+
this.#ready = false;
|
|
231
|
+
this.#setLifecycleState("stopping", `pid=${backend.pid}`);
|
|
232
|
+
this.#logger.verbose(`stopping backend pid=${backend.pid}`);
|
|
233
|
+
try {
|
|
234
|
+
backend.kill("SIGTERM");
|
|
235
|
+
const timeout = new Promise<"timeout">((resolve) =>
|
|
236
|
+
setTimeout(() => resolve("timeout"), BACKEND_GRACEFUL_TIMEOUT_MS),
|
|
237
|
+
);
|
|
238
|
+
const result = await Promise.race([backend.exited, timeout]);
|
|
239
|
+
if (result === "timeout") {
|
|
240
|
+
this.#logger.warn(`backend pid=${backend.pid} did not exit in ${BACKEND_GRACEFUL_TIMEOUT_MS}ms; force killing`);
|
|
241
|
+
backend.kill("SIGKILL");
|
|
242
|
+
await backend.exited.catch(() => undefined);
|
|
243
|
+
}
|
|
244
|
+
} finally {
|
|
245
|
+
if (this.#process === backend) this.#process = null;
|
|
246
|
+
this.#setLifecycleState("stopped", `pid=${backend.pid}`);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
cancelTimers(): void {
|
|
251
|
+
if (this.#restartTimer) clearTimeout(this.#restartTimer);
|
|
252
|
+
this.#restartTimer = null;
|
|
253
|
+
this.#recovery.cancel();
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
dropPendingRestart(): void {
|
|
257
|
+
this.#pendingRestartReason = null;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
scheduleRestart(reason: BackendRestartReason) {
|
|
261
|
+
this.#pendingRestartReason = mergeBackendRestartReasons(this.#pendingRestartReason, reason);
|
|
262
|
+
const pending = this.#pendingRestartReason;
|
|
263
|
+
this.#setLifecycleState(
|
|
264
|
+
"restart-pending",
|
|
265
|
+
`generation=${pending.generation ?? "(unknown)"} files=${pending.files.length} roles=${pending.roles.join(",") || "(none)"}`,
|
|
266
|
+
);
|
|
267
|
+
this.#recovery.cancel();
|
|
268
|
+
if (this.#restartTimer) clearTimeout(this.#restartTimer);
|
|
269
|
+
this.#restartTimer = setTimeout(() => {
|
|
270
|
+
this.#restartTimer = null;
|
|
271
|
+
this.#restart ??= this.#drainRestarts().finally(() => {
|
|
272
|
+
this.#restart = null;
|
|
273
|
+
});
|
|
274
|
+
}, BACKEND_RESTART_DEBOUNCE_MS);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
reviveAfterGreenBuild(status: DevBuildStatus): void {
|
|
278
|
+
if (!status.ok || !this.#gaveUp || this.#process || this.#recovery.pending) return;
|
|
279
|
+
this.#logger.info(`[backend-recovery] build went green (generation=${status.generation}); retrying backend`);
|
|
280
|
+
this.#recovery.reset();
|
|
281
|
+
this.start({ generation: status.generation, files: status.files });
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
#recordStderr(chunk: string) {
|
|
285
|
+
const lines = chunk.split(/\r?\n/).filter((line) => line.length > 0);
|
|
286
|
+
if (lines.length === 0) return;
|
|
287
|
+
this.#stderrTail.push(...lines);
|
|
288
|
+
if (this.#stderrTail.length > BACKEND_STDERR_TAIL_LIMIT) {
|
|
289
|
+
this.#stderrTail.splice(0, this.#stderrTail.length - BACKEND_STDERR_TAIL_LIMIT);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// Verbatim, not re-logged: a level floor would swallow runtime output and re-rendering doubles the timestamp.
|
|
294
|
+
async #forwardStream(stream: ReadableStream<Uint8Array> | undefined | null, kind: "stdout" | "stderr") {
|
|
295
|
+
if (!stream) return;
|
|
296
|
+
const decoder = new TextDecoder();
|
|
297
|
+
try {
|
|
298
|
+
for await (const chunk of stream) {
|
|
299
|
+
const text = decoder.decode(chunk, { stream: true });
|
|
300
|
+
if (!text) continue;
|
|
301
|
+
if (kind === "stderr") {
|
|
302
|
+
this.#recordStderr(text);
|
|
303
|
+
process.stderr.write(text);
|
|
304
|
+
} else process.stdout.write(text);
|
|
305
|
+
}
|
|
306
|
+
} catch {
|
|
307
|
+
// The stream closes when the backend exits; nothing further to surface here.
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
#recordReadyStatus(): void {
|
|
312
|
+
const previous = this.#statuses.phase("backend");
|
|
313
|
+
const startStatus = this.#startStatus;
|
|
314
|
+
if (startStatus || previous?.ok === false) {
|
|
315
|
+
const status = this.#statuses.recordBackend({
|
|
316
|
+
generation: startStatus?.generation ?? previous?.generation,
|
|
317
|
+
ok: true,
|
|
318
|
+
files: startStatus?.files ?? previous?.files ?? [],
|
|
319
|
+
message: "Backend ready",
|
|
320
|
+
});
|
|
321
|
+
this.sendOrQueueStatus(status);
|
|
322
|
+
}
|
|
323
|
+
this.#startStatus = null;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
//? A route status belongs to the route cache of the backend that asked for the build: a new backend builds its routes
|
|
327
|
+
//? again, and reports each one itself.
|
|
328
|
+
#forgetRouteBuildStatus(): void {
|
|
329
|
+
this.#statuses.forgetRoute();
|
|
330
|
+
this.#queuedStatuses = this.#queuedStatuses.filter((status) => status.phase !== "route");
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
#setLifecycleState(next: BackendLifecycleState, detail?: string): void {
|
|
334
|
+
if (this.#lifecycleState === next && !detail) return;
|
|
335
|
+
const prev = this.#lifecycleState;
|
|
336
|
+
this.#lifecycleState = next;
|
|
337
|
+
this.#logger.verbose(`[backend-lifecycle] ${prev} -> ${next}${detail ? ` ${detail}` : ""}`);
|
|
338
|
+
this.#links.emit(devHostStateOf(next, this.#gaveUp), detail);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
//? A reason that arrived during a restart runs after it; one whose debounce is still pending waits for its timer.
|
|
342
|
+
async #drainRestarts() {
|
|
343
|
+
while (this.#pendingRestartReason && !this.#restartTimer && !this.#links.isStopping()) {
|
|
344
|
+
const next = this.#pendingRestartReason;
|
|
345
|
+
this.#pendingRestartReason = null;
|
|
346
|
+
await this.#restartWith(next);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
async #restartWith(reason: BackendRestartReason) {
|
|
351
|
+
this.#logger.verbose(
|
|
352
|
+
`[backend-reload] restarting backend generation=${reason.generation ?? "(unknown)"} files=${reason.files.length} roles=${reason.roles.join(",") || "(none)"}`,
|
|
353
|
+
);
|
|
354
|
+
this.#recovery.reset();
|
|
355
|
+
await Promise.all([this.stop(), this.#graph.refresh()]);
|
|
356
|
+
this.start({ generation: reason.generation, files: reason.files });
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
#scheduleRecovery(reason: string) {
|
|
360
|
+
if (this.#recovery.pending || this.#process) return;
|
|
361
|
+
if (this.#recovery.exhausted) {
|
|
362
|
+
const message = `Backend exited ${this.#recovery.attempts} times in a row (${reason}); waiting for an edit or a green build to retry.`;
|
|
363
|
+
this.#gaveUp = true;
|
|
364
|
+
this.#setLifecycleState("stopped", `gave up after ${this.#recovery.attempts} recovery attempts`);
|
|
365
|
+
this.#logger.error(`[backend-recovery] ${message}`);
|
|
366
|
+
if (this.#stderrTail.length > 0) {
|
|
367
|
+
this.#logger.error(`[backend-recovery] recent backend stderr:\n${this.#stderrTail.join("\n")}`);
|
|
368
|
+
}
|
|
369
|
+
const abandonedStatus = this.#statuses.recordBackend({ ok: false, files: [], message });
|
|
370
|
+
this.sendOrQueueStatus(abandonedStatus);
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
this.#setLifecycleState("recovering", reason);
|
|
374
|
+
const delay = this.#recovery.next();
|
|
375
|
+
const failureStatus = this.#statuses.recordBackend({
|
|
376
|
+
ok: false,
|
|
377
|
+
files: [],
|
|
378
|
+
message: `Backend exited unexpectedly (${reason}); restarting in ${delay}ms`,
|
|
379
|
+
});
|
|
380
|
+
this.sendOrQueueStatus(failureStatus);
|
|
381
|
+
this.#logger.warn(
|
|
382
|
+
`[backend-recovery] backend exited unexpectedly (${reason}); restarting in ${delay}ms (attempt ${this.#recovery.attempts})`,
|
|
383
|
+
);
|
|
384
|
+
if (this.#stderrTail.length > 0) {
|
|
385
|
+
this.#logger.warn(`[backend-recovery] recent backend stderr:\n${this.#stderrTail.join("\n")}`);
|
|
386
|
+
}
|
|
387
|
+
this.#recovery.arm(delay, () => {
|
|
388
|
+
if (this.#process) return;
|
|
389
|
+
void this.#graph.refresh().finally(() => {
|
|
390
|
+
if (!this.#process) this.start({ generation: failureStatus.generation, files: failureStatus.files });
|
|
391
|
+
});
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import type { Logger } from "akanjs/common";
|
|
2
|
+
import type { BuilderMessage, BuildPhase, DevBuildStatus } from "akanjs/server";
|
|
3
|
+
import {
|
|
4
|
+
buildStatusReplaySequence,
|
|
5
|
+
createBackendBuildStatus,
|
|
6
|
+
hasAnyBuildFailure,
|
|
7
|
+
hasBuildFailureForGeneration,
|
|
8
|
+
shouldKeepBuildFailure,
|
|
9
|
+
shouldMarkBuildPhaseRecovered,
|
|
10
|
+
shouldRelayRecycledFrontendState,
|
|
11
|
+
shouldReplaceLastGoodMessage,
|
|
12
|
+
} from "./devHostPolicy";
|
|
13
|
+
|
|
14
|
+
type FrontendStateMessage =
|
|
15
|
+
| Extract<BuilderMessage, { type: "pages-updated" }>
|
|
16
|
+
| Extract<BuilderMessage, { type: "css-updated" }>;
|
|
17
|
+
|
|
18
|
+
interface LastGoodFrontendState {
|
|
19
|
+
pages?: Extract<BuilderMessage, { type: "pages-updated" }>;
|
|
20
|
+
css?: Extract<BuilderMessage, { type: "css-updated" }>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export class DevBuildStatusBoard {
|
|
24
|
+
readonly #logger: Logger;
|
|
25
|
+
readonly #byPhase = new Map<BuildPhase, DevBuildStatus>();
|
|
26
|
+
#backendGeneration = 0;
|
|
27
|
+
#lastGood: LastGoodFrontendState = {};
|
|
28
|
+
|
|
29
|
+
constructor(logger: Logger) {
|
|
30
|
+
this.#logger = logger;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
get lastGood(): Readonly<LastGoodFrontendState> {
|
|
34
|
+
return this.#lastGood;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
get failing(): boolean {
|
|
38
|
+
return hasAnyBuildFailure(this.#byPhase);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
phase(phase: BuildPhase): DevBuildStatus | undefined {
|
|
42
|
+
return this.#byPhase.get(phase);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
failedAt(generation: number | undefined): boolean {
|
|
46
|
+
return hasBuildFailureForGeneration(this.#byPhase, generation);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
replaySequence(queued: readonly DevBuildStatus[]): DevBuildStatus[] {
|
|
50
|
+
return buildStatusReplaySequence(queued, this.#byPhase);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
nextBackendGeneration(generation?: number): number {
|
|
54
|
+
if (typeof generation === "number") {
|
|
55
|
+
this.#backendGeneration = Math.max(this.#backendGeneration, generation);
|
|
56
|
+
return generation;
|
|
57
|
+
}
|
|
58
|
+
this.#backendGeneration += 1;
|
|
59
|
+
return this.#backendGeneration;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
record(status: DevBuildStatus): void {
|
|
63
|
+
const recovered = shouldMarkBuildPhaseRecovered(this.#byPhase, status);
|
|
64
|
+
if (shouldKeepBuildFailure(this.#byPhase, status)) return;
|
|
65
|
+
this.#byPhase.set(status.phase, status);
|
|
66
|
+
const label = `[build-status] generation=${status.generation} phase=${status.phase} ok=${status.ok} files=${status.files.length}`;
|
|
67
|
+
if (status.ok) this.#logger.verbose(`${label}${recovered ? " recovered=1" : ""}`);
|
|
68
|
+
else this.#logger.warn(`${label}${status.message ? ` message=${status.message}` : ""}`);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
recordBackend({
|
|
72
|
+
generation,
|
|
73
|
+
ok,
|
|
74
|
+
files,
|
|
75
|
+
message,
|
|
76
|
+
}: {
|
|
77
|
+
generation?: number;
|
|
78
|
+
ok: boolean;
|
|
79
|
+
files?: string[];
|
|
80
|
+
message?: string;
|
|
81
|
+
}): DevBuildStatus {
|
|
82
|
+
const status = createBackendBuildStatus({
|
|
83
|
+
generation: this.nextBackendGeneration(generation),
|
|
84
|
+
ok,
|
|
85
|
+
files,
|
|
86
|
+
message,
|
|
87
|
+
});
|
|
88
|
+
this.record(status);
|
|
89
|
+
return status;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
forgetRoute(): void {
|
|
93
|
+
this.#byPhase.delete("route");
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
reset(): void {
|
|
97
|
+
this.#lastGood = {};
|
|
98
|
+
this.#byPhase.clear();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// `supersede`: a recycled builder's re-announcement is what is on disk now, whatever generation it carries.
|
|
102
|
+
recordLastGood(message: FrontendStateMessage, { supersede = false }: { supersede?: boolean } = {}): void {
|
|
103
|
+
if (message.type === "pages-updated") {
|
|
104
|
+
if (!supersede && !shouldReplaceLastGoodMessage(this.#lastGood.pages, message)) return;
|
|
105
|
+
this.#lastGood.pages = message;
|
|
106
|
+
this.#logger.verbose(
|
|
107
|
+
`[last-good] pages generation=${message.data.generation ?? "(unknown)"} buildId=${message.data.buildId}`,
|
|
108
|
+
);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (!supersede && !shouldReplaceLastGoodMessage(this.#lastGood.css, message)) return;
|
|
112
|
+
this.#lastGood.css = message;
|
|
113
|
+
this.#logger.verbose(
|
|
114
|
+
`[last-good] css generation=${message.data.generation ?? "(unknown)"} assets=${Object.keys(message.data.cssAssets).length}`,
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// The backend reads `base-artifact.json` once, so a recycled builder re-announces it; unchanged hashes are dropped.
|
|
119
|
+
shouldRelayRecycled(message: FrontendStateMessage): boolean {
|
|
120
|
+
const current = message.type === "pages-updated" ? this.#lastGood.pages : this.#lastGood.css;
|
|
121
|
+
if (shouldRelayRecycledFrontendState(current, message)) {
|
|
122
|
+
this.#logger.verbose(`[builder-recycle] ${message.type} moved during the recycle; pushing it to the backend`);
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
this.#logger.verbose(`[builder-recycle] ${message.type} unchanged after the recycle; backend left as is`);
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
}
|