@akanjs/devkit 3.2.0-rc.2 → 3.2.0-rc.21
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 +350 -11
- 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 +257 -1
- package/akanApp/akanApp.host.ts +146 -1223
- package/akanApp/akanApp.host.wiring.test.ts +727 -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 +392 -0
- package/akanApp/devBuildStatusBoard.ts +128 -0
- package/akanApp/devBuilder.ts +196 -0
- package/akanApp/devHostPolicy.test.ts +11 -11
- package/akanApp/devHostPolicy.ts +2 -4
- 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/processRss.ts +61 -0
- package/akanConfig/akanConfig.test.ts +24 -1
- package/akanConfig/akanConfig.ts +10 -10
- package/akanConfig/akanWorkspaceConfig.ts +1 -1
- package/akanConfig/productionLockfile.ts +1 -1
- package/apiReport/apiDeclarationPrinter.ts +120 -0
- package/apiReport/apiReport.test.ts +526 -0
- package/apiReport/apiReport.ts +232 -0
- package/apiReport/apiReportDiff.ts +160 -0
- package/apiReport/apiReportPolicy.ts +65 -0
- package/apiReport/apiTargets.ts +311 -0
- package/apiReport/changesetBump.ts +19 -0
- package/{applicationBuildReporter.test.ts → app/applicationBuildReporter.test.ts} +21 -0
- package/{applicationBuildReporter.ts → app/applicationBuildReporter.ts} +10 -49
- package/{applicationBuildRunner.test.ts → app/applicationBuildRunner.test.ts} +74 -7
- package/{applicationBuildRunner.ts → app/applicationBuildRunner.ts} +20 -15
- package/{applicationTestPreload.ts → app/applicationTestPreload.ts} +1 -1
- package/{routeJsBudget.test.ts → app/routeJsBudget.test.ts} +48 -12
- package/{routeJsBudget.ts → app/routeJsBudget.ts} +90 -27
- 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 +21 -4
- 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/akanCodePaths.ts +1 -1
- package/codeAgent/agent/akanSystemPrompt.ts +1 -1
- package/codeAgent/agent/codeAgent.test.ts +1 -1
- package/codeAgent/skills/akan-debug/SKILL.md +10 -3
- package/codeAgent/skills/akan-err/SKILL.md +7 -0
- package/codeAgent/skills/akan-mcp/SKILL.md +13 -2
- package/codeAgent/skills/akan-scaffold/SKILL.md +2 -2
- package/codeAgent/skills/akan-transport/SKILL.md +2 -0
- package/codeAgent/skills/akan-validate/SKILL.md +1 -0
- package/codeAgent/tools/AkanCli.ts +1 -1
- package/codeAgent/tools/AkanToolPack.ts +1 -1
- package/codeAgent/tools/McpClient.ts +28 -6
- package/codeAgent/tools/McpToolPack.ts +1 -1
- package/codeAgent/tools/akanCodePlugins.test.ts +14 -2
- package/commandDecorators/argMeta.ts +4 -0
- package/commandDecorators/cliError.ts +72 -0
- package/commandDecorators/command.ts +165 -91
- package/commandDecorators/commandBuilder.ts +1 -1
- package/commandDecorators/commandDecorators.test.ts +191 -16
- package/commandDecorators/exitCodeError.ts +6 -7
- package/commandDecorators/index.ts +1 -0
- package/commandDecorators/targetMeta.ts +1 -0
- package/commandDecorators/workspaceVersionCheck.test.ts +1 -1
- package/commandDecorators/workspaceVersionCheck.ts +1 -1
- 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} +33 -263
- package/context/akanMcpToolError.ts +16 -0
- 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 +39 -0
- package/context/doctor/recipeIndexCheck.ts +87 -0
- package/context/doctor/rootShapeCheck.ts +55 -0
- package/context/doctor/workflowScope.ts +97 -0
- package/{constantFieldNames.test.ts → context/moduleFieldNames.test.ts} +24 -2
- package/context/moduleFieldNames.ts +25 -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 +448 -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} +76 -15
- 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 +17 -5
- package/frontendBuild/allRoutesBuilder.ts +24 -6
- package/frontendBuild/autoImportSync.test.ts +1 -1
- package/frontendBuild/autoImportSync.ts +1 -1
- package/frontendBuild/buildRouteClient.test.ts +1 -1
- package/frontendBuild/bundleDefine.ts +2 -0
- package/frontendBuild/clientBuildTypes.ts +5 -2
- package/frontendBuild/clientEntriesBundler.test.ts +1 -1
- package/frontendBuild/clientEntryDiscovery.test.ts +58 -0
- package/frontendBuild/clientEntryDiscovery.ts +25 -6
- package/frontendBuild/csrArtifactBuilder.test.ts +1 -1
- package/frontendBuild/csrDevArtifactWriter.ts +1 -1
- package/frontendBuild/cssCompiler.test.ts +1 -1
- 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 +1 -1
- 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 +148 -0
- 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 +1 -1
- package/frontendBuild/serverGraphFile.ts +1 -1
- package/frontendBuild/sourceMtimeIndex.test.ts +1 -1
- package/frontendBuild/ssrBaseArtifactBuilder.test.ts +26 -0
- package/frontendBuild/ssrBaseArtifactBuilder.ts +23 -19
- package/frontendBuild/ssrDevBundler.test.ts +1 -1
- package/frontendBuild/vendorImportScanner.test.ts +25 -4
- package/frontendBuild/vendorImportScanner.ts +25 -10
- 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 +14 -4
- package/incrementalBuilder/buildBatchProtocol.ts +2 -0
- package/incrementalBuilder/buildBatchRunner.test.ts +108 -1
- package/incrementalBuilder/buildBatchRunner.ts +17 -4
- package/incrementalBuilder/builderBoot.ts +106 -0
- package/incrementalBuilder/builderBuildStatus.ts +23 -0
- package/incrementalBuilder/builderChannel.test.ts +1 -1
- package/incrementalBuilder/builderChannel.ts +11 -0
- 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 +30 -1
- package/incrementalBuilder/incrementalBuilder.host.ts +10 -22
- package/incrementalBuilder/incrementalBuilder.proc.test.ts +93 -2
- package/incrementalBuilder/incrementalBuilder.proc.ts +81 -823
- package/incrementalBuilder/ssrRegistry.ts +278 -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/lint/no-web-only-api-outside-webkit.grit +3 -3
- 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/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 +167 -3
- 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/PlatformTestRun.test.ts +1 -1
- package/platformTest/TestSnapshot.test.ts +1 -1
- package/preview/PreviewView.ts +32 -11
- package/preview/previewView.test.ts +76 -9
- 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} +1 -1
- package/{qualityScanner.ts → quality/qualityScanner.ts} +8 -8
- package/{storeAccessScanner.ts → quality/storeAccessScanner.ts} +15 -2
- package/{subspace.test.ts → subspace/subspace.test.ts} +9 -3
- 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 +26 -8
- 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 +29 -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 +1 -1
- package/typecheck/projectTypecheck.ts +6 -2
- package/{typeChecker.test.ts → typecheck/typeChecker.test.ts} +1 -1
- package/{typeChecker.ts → typecheck/typeChecker.ts} +1 -1
- package/typecheck/typecheck.proc.ts +4 -3
- package/typecheck/typecheckFailure.ts +7 -2
- package/util/errorReport.ts +66 -0
- package/{jsonFormatter.test.ts → util/jsonFormatter.test.ts} +1 -1
- package/workflow/artifacts.ts +8 -7
- 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 +93 -0
- package/workflow/guardCatalog.test.ts +1 -1
- package/workflow/index.ts +2 -0
- 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/plainName.ts +28 -0
- package/workflow/plan.ts +15 -9
- 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 -1105
- 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} +85 -1
- package/{workspaceGraph.ts → workspace/workspaceGraph.ts} +41 -6
- package/{workspaceLayout.test.ts → workspace/workspaceLayout.test.ts} +1 -1
- package/{workspaceLayout.ts → workspace/workspaceLayout.ts} +3 -1
- package/akanContext.ts +0 -1084
- package/constantFieldNames.ts +0 -18
- package/executors.ts +0 -1749
- /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/{fileSys.test.ts → util/fileSys.test.ts} +0 -0
- /package/{fileSys.ts → util/fileSys.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,196 @@
|
|
|
1
|
+
import { type Logger, RestartSchedule } from "akanjs/common";
|
|
2
|
+
import type { BuilderMessage } from "akanjs/server";
|
|
3
|
+
import type { App } from "../commandDecorators";
|
|
4
|
+
import { type DevStdioMode, IncrementalBuilderHost } from "../incrementalBuilder";
|
|
5
|
+
|
|
6
|
+
const BUILDER_READY_TIMEOUT_MS = 150000;
|
|
7
|
+
|
|
8
|
+
const BUILDER_START_MAX_ATTEMPTS = 3;
|
|
9
|
+
|
|
10
|
+
export interface BuilderRecoveryReason {
|
|
11
|
+
generation?: number;
|
|
12
|
+
files: string[];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface DevBuilderLinks {
|
|
16
|
+
isStopping: () => boolean;
|
|
17
|
+
onMessage: (message: BuilderMessage) => void;
|
|
18
|
+
onAway: () => void;
|
|
19
|
+
onReady: () => void;
|
|
20
|
+
onRestartReady: () => void;
|
|
21
|
+
onStartFailed: () => void;
|
|
22
|
+
onStop: () => void;
|
|
23
|
+
onRecovered: (reason: BuilderRecoveryReason) => void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export class DevBuilder {
|
|
27
|
+
readonly #app: App;
|
|
28
|
+
readonly #env: Record<string, string>;
|
|
29
|
+
readonly #stdio: DevStdioMode;
|
|
30
|
+
readonly #logger: Logger;
|
|
31
|
+
readonly #links: DevBuilderLinks;
|
|
32
|
+
#host: IncrementalBuilderHost | null = null;
|
|
33
|
+
//? Outlives the builder host, which idle wake and recovery replace; a config or metadata restart clears it.
|
|
34
|
+
#patcherOff = false;
|
|
35
|
+
//? The builder is the file watcher, so unlike the backend its recovery never gives up; it only backs off.
|
|
36
|
+
readonly #recovery = new RestartSchedule({ min: 2_000, max: 60_000 });
|
|
37
|
+
#abandonStart: ((error: Error) => void) | null = null;
|
|
38
|
+
#generation = 0;
|
|
39
|
+
|
|
40
|
+
constructor(
|
|
41
|
+
app: App,
|
|
42
|
+
{ env, stdio, logger }: { env: Record<string, string>; stdio: DevStdioMode; logger: Logger },
|
|
43
|
+
links: DevBuilderLinks,
|
|
44
|
+
) {
|
|
45
|
+
this.#app = app;
|
|
46
|
+
this.#env = env;
|
|
47
|
+
this.#stdio = stdio;
|
|
48
|
+
this.#logger = logger;
|
|
49
|
+
this.#links = links;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
get current(): IncrementalBuilderHost | null {
|
|
53
|
+
return this.#host;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
get recovering(): boolean {
|
|
57
|
+
return this.#recovery.pending;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async start({ announceBootState = false }: { announceBootState?: boolean } = {}): Promise<IncrementalBuilderHost> {
|
|
61
|
+
const startTime = Date.now();
|
|
62
|
+
this.#app.verbose(`[cli] waiting for builder to complete initial base build…`);
|
|
63
|
+
let lastError: unknown;
|
|
64
|
+
for (let attempt = 1; attempt <= BUILDER_START_MAX_ATTEMPTS; attempt++) {
|
|
65
|
+
const builder = await IncrementalBuilderHost.create(
|
|
66
|
+
this.#app,
|
|
67
|
+
this.#env,
|
|
68
|
+
(msg) => {
|
|
69
|
+
this.#links.onMessage(msg);
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
stdio: this.#stdio,
|
|
73
|
+
onOutput: (kind, text) => void (kind === "stderr" ? process.stderr : process.stdout).write(text),
|
|
74
|
+
patcherOff: this.#patcherOff,
|
|
75
|
+
},
|
|
76
|
+
);
|
|
77
|
+
if (this.#links.isStopping()) {
|
|
78
|
+
builder.stop();
|
|
79
|
+
throw new Error("dev server stopped before the builder started");
|
|
80
|
+
}
|
|
81
|
+
this.#host = builder;
|
|
82
|
+
try {
|
|
83
|
+
await this.#waitForReady(attempt, { announceBootState });
|
|
84
|
+
this.#app.verbose(`[cli] base build ready in ${Date.now() - startTime}ms — starting backend`);
|
|
85
|
+
return this.#host;
|
|
86
|
+
} catch (err) {
|
|
87
|
+
lastError = err;
|
|
88
|
+
this.stop();
|
|
89
|
+
if (attempt >= BUILDER_START_MAX_ATTEMPTS || this.#links.isStopping()) break;
|
|
90
|
+
this.#app.verbose(`[cli] builder failed before ready; retrying (${attempt + 1}/${BUILDER_START_MAX_ATTEMPTS})`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
this.#links.onStartFailed();
|
|
94
|
+
throw lastError instanceof Error ? lastError : new Error(String(lastError));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
stop(): void {
|
|
98
|
+
this.#links.onStop();
|
|
99
|
+
if (!this.#host) return;
|
|
100
|
+
if (this.#host.patcherOff) this.#patcherOff = true;
|
|
101
|
+
this.#host.stop();
|
|
102
|
+
this.#host = null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
abandonStart(error: Error): void {
|
|
106
|
+
this.#abandonStart?.(error);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
cancelRecovery(): void {
|
|
110
|
+
this.#recovery.cancel();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
resetRecovery(): void {
|
|
114
|
+
this.#recovery.reset();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
clearPatcherOff(): void {
|
|
118
|
+
this.#patcherOff = false;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
scheduleRecovery(reason: BuilderRecoveryReason): void {
|
|
122
|
+
if (this.#links.isStopping() || this.#recovery.pending || this.#host) return;
|
|
123
|
+
const delay = this.#recovery.schedule(() => {
|
|
124
|
+
if (this.#links.isStopping() || this.#host) return;
|
|
125
|
+
void this.#recover(reason);
|
|
126
|
+
});
|
|
127
|
+
this.#logger.warn(
|
|
128
|
+
`[builder-recovery] builder is down; retrying start in ${delay}ms (attempt ${this.#recovery.attempts})`,
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// In `env`, which every builder spawn re-reads: a replacement (recycled, crashed, restarted) continues from here.
|
|
133
|
+
trackGeneration(message: BuilderMessage): void {
|
|
134
|
+
const generation = DevBuilder.#generationOf(message);
|
|
135
|
+
if (generation === undefined || generation <= this.#generation) return;
|
|
136
|
+
this.#generation = generation;
|
|
137
|
+
Object.assign(this.#env, { AKAN_BUILDER_INITIAL_GENERATION: String(generation) });
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Not `csr-updated` / `ssr-updated`: their generation is the registry's.
|
|
141
|
+
static #generationOf(message: BuilderMessage): number | undefined {
|
|
142
|
+
if (message.type === "invalidate") return message.generation;
|
|
143
|
+
if (message.type === "build-status" || message.type === "builder-metrics") return message.data.generation;
|
|
144
|
+
if (message.type === "pages-updated" || message.type === "css-updated") return message.data.generation;
|
|
145
|
+
return undefined;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
async #recover(reason: BuilderRecoveryReason): Promise<void> {
|
|
149
|
+
try {
|
|
150
|
+
await this.start();
|
|
151
|
+
} catch (err) {
|
|
152
|
+
if (this.#links.isStopping()) return;
|
|
153
|
+
this.#logger.warn(`[builder-recovery] builder start failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
154
|
+
this.scheduleRecovery(reason);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
this.#recovery.reset();
|
|
158
|
+
this.#logger.info("[builder-recovery] builder recovered");
|
|
159
|
+
this.#links.onRecovered(reason);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
#waitForReady(attempt: number, { announceBootState = false }: { announceBootState?: boolean } = {}): Promise<void> {
|
|
163
|
+
return new Promise<void>((resolve, reject) => {
|
|
164
|
+
if (!this.#host) throw new Error("Builder Not Found");
|
|
165
|
+
let settled = false;
|
|
166
|
+
const settle = (fn: () => void) => {
|
|
167
|
+
if (settled) return;
|
|
168
|
+
settled = true;
|
|
169
|
+
clearTimeout(timeout);
|
|
170
|
+
if (this.#abandonStart === abandon) this.#abandonStart = null;
|
|
171
|
+
fn();
|
|
172
|
+
};
|
|
173
|
+
const abandon = (error: Error) => settle(() => reject(error));
|
|
174
|
+
this.#abandonStart = abandon;
|
|
175
|
+
const timeout = setTimeout(() => {
|
|
176
|
+
settle(() => reject(new Error("[cli] builder timed out before emitting builder-ready")));
|
|
177
|
+
}, BUILDER_READY_TIMEOUT_MS);
|
|
178
|
+
this.#host.start({
|
|
179
|
+
announceBootState,
|
|
180
|
+
onExit: () => {
|
|
181
|
+
settle(() => reject(new Error(`[cli] builder exited before emitting builder-ready (attempt ${attempt})`)));
|
|
182
|
+
},
|
|
183
|
+
onAway: () => {
|
|
184
|
+
this.#links.onAway();
|
|
185
|
+
},
|
|
186
|
+
onReady: () => {
|
|
187
|
+
settle(resolve);
|
|
188
|
+
this.#links.onReady();
|
|
189
|
+
},
|
|
190
|
+
onRestartReady: () => {
|
|
191
|
+
this.#links.onRestartReady();
|
|
192
|
+
},
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { RestartSchedule } from "akanjs/common";
|
|
2
3
|
import type { BuilderMessage, BuildPhase, DevBuildStatus, DevChangeAction } from "akanjs/server";
|
|
3
4
|
//? The source itself, not the package: the published akanjs exports no such subpath, and tests are not bundled.
|
|
4
5
|
import { DevBuildRecovery } from "../../../akanjs/server/artifact/devBuildRecovery";
|
|
5
6
|
import {
|
|
7
|
+
backendRecoveryPolicy,
|
|
6
8
|
backendRestartReasonFromMessage,
|
|
7
9
|
buildStatusReplaySequence,
|
|
8
10
|
createBackendBuildStatus,
|
|
@@ -18,7 +20,6 @@ import {
|
|
|
18
20
|
normalizeBackendReportedGeneration,
|
|
19
21
|
redisTunnelPolicy,
|
|
20
22
|
resolveIdleSuspendMs,
|
|
21
|
-
shouldAbandonBackendRecovery,
|
|
22
23
|
shouldHoldForReturningBuilder,
|
|
23
24
|
shouldKeepBuildFailure,
|
|
24
25
|
shouldMarkBuildPhaseRecovered,
|
|
@@ -489,16 +490,15 @@ describe("legacy backend graph fallback", () => {
|
|
|
489
490
|
});
|
|
490
491
|
|
|
491
492
|
describe("backend recovery abandonment", () => {
|
|
492
|
-
test("
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
expect(
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
expect(
|
|
501
|
-
expect(shouldAbandonBackendRecovery(3, 3)).toBe(true);
|
|
493
|
+
test("backs off from 1s and gives up after five failed restarts in a row", () => {
|
|
494
|
+
const recovery = new RestartSchedule(backendRecoveryPolicy);
|
|
495
|
+
const delays = [1, 2, 3, 4].map(() => recovery.next());
|
|
496
|
+
expect(recovery.exhausted).toBe(false);
|
|
497
|
+
delays.push(recovery.next());
|
|
498
|
+
expect(delays).toEqual([1_000, 2_000, 4_000, 8_000, 16_000]);
|
|
499
|
+
expect(recovery.exhausted).toBe(true);
|
|
500
|
+
recovery.reset();
|
|
501
|
+
expect(recovery.exhausted).toBe(false);
|
|
502
502
|
});
|
|
503
503
|
});
|
|
504
504
|
|
package/akanApp/devHostPolicy.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
+
import type { RestartPolicy } from "akanjs/common";
|
|
2
3
|
import type {
|
|
3
4
|
BuilderMessage,
|
|
4
5
|
BuildPhase,
|
|
@@ -20,7 +21,7 @@ export const redisTunnelPolicy = ({
|
|
|
20
21
|
}): "none" | "optional" | "required" =>
|
|
21
22
|
environment === "local" ? "none" : databaseMode === "single" ? "optional" : "required";
|
|
22
23
|
|
|
23
|
-
const
|
|
24
|
+
export const backendRecoveryPolicy: RestartPolicy = { min: 1_000, max: 30_000, maxAttempts: 5 };
|
|
24
25
|
|
|
25
26
|
// A page load asks for several routes, but a builder that never returns must not grow the hold queue unbounded.
|
|
26
27
|
const HELD_BUILDER_REQUEST_LIMIT = 64;
|
|
@@ -57,9 +58,6 @@ export const shouldRestartBackendByDevPlan = (
|
|
|
57
58
|
export const shouldRestartBuilderByDevPlan = (message: Extract<BuilderMessage, { type: "invalidate" }>): boolean =>
|
|
58
59
|
message.devPlan?.actions.includes("restart-builder") ?? false;
|
|
59
60
|
|
|
60
|
-
export const shouldAbandonBackendRecovery = (attempts: number, maxAttempts = BACKEND_RECOVERY_MAX_ATTEMPTS): boolean =>
|
|
61
|
-
attempts >= maxAttempts;
|
|
62
|
-
|
|
63
61
|
/** The gateway reports backend failures with `generation: -1`; the host assigns its own counter then. */
|
|
64
62
|
export const normalizeBackendReportedGeneration = (generation: number): number | undefined =>
|
|
65
63
|
generation >= 0 ? generation : undefined;
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test";
|
|
2
|
+
import type { Logger } from "akanjs/common";
|
|
3
|
+
import type { BuilderMessage } from "akanjs/server";
|
|
4
|
+
import type { App } from "../commandDecorators";
|
|
5
|
+
import type { IncrementalBuilderHost } from "../incrementalBuilder";
|
|
6
|
+
import { BuilderRequestRelay } from "./builderRequestRelay";
|
|
7
|
+
|
|
8
|
+
const watchers: { stopped: number; started: PromiseWithResolvers<void> }[] = [];
|
|
9
|
+
const releaseStart = () => watchers.at(-1)?.started.resolve();
|
|
10
|
+
|
|
11
|
+
mock.module("../frontendBuild/watchRootResolver", () => ({
|
|
12
|
+
WatchRootResolver: class {
|
|
13
|
+
async resolve() {
|
|
14
|
+
return ["/repo"];
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
}));
|
|
18
|
+
mock.module("../frontendBuild/hmrWatcher", () => ({
|
|
19
|
+
HmrWatcher: class {
|
|
20
|
+
readonly #record = { stopped: 0, started: Promise.withResolvers<void>() };
|
|
21
|
+
constructor() {
|
|
22
|
+
watchers.push(this.#record);
|
|
23
|
+
}
|
|
24
|
+
start() {
|
|
25
|
+
return this.#record.started.promise;
|
|
26
|
+
}
|
|
27
|
+
stop() {
|
|
28
|
+
this.#record.stopped++;
|
|
29
|
+
}
|
|
30
|
+
async close() {
|
|
31
|
+
this.#record.stopped++;
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
}));
|
|
36
|
+
|
|
37
|
+
const { DevIdleSuspend } = await import("./devIdleSuspend");
|
|
38
|
+
|
|
39
|
+
const logger = { info: () => undefined, verbose: () => undefined, warn: () => undefined, error: () => undefined };
|
|
40
|
+
const tick = (ms = 0) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
41
|
+
|
|
42
|
+
const suspendOf = () => {
|
|
43
|
+
const calls = { readiness: 0, release: 0, wake: 0, awake: 0 };
|
|
44
|
+
const readiness = { builderReady: true, backendReady: true, buildFailed: false, restartPending: false };
|
|
45
|
+
let finishWake: () => void = () => undefined;
|
|
46
|
+
const idle = new DevIdleSuspend(
|
|
47
|
+
{} as App,
|
|
48
|
+
{ logger: logger as unknown as Logger },
|
|
49
|
+
{
|
|
50
|
+
readiness: () => {
|
|
51
|
+
calls.readiness++;
|
|
52
|
+
return { ...readiness };
|
|
53
|
+
},
|
|
54
|
+
release: () => {
|
|
55
|
+
calls.release++;
|
|
56
|
+
},
|
|
57
|
+
wake: () => {
|
|
58
|
+
calls.wake++;
|
|
59
|
+
return new Promise<void>((resolve) => {
|
|
60
|
+
finishWake = resolve;
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
wakeFailed: () => undefined,
|
|
64
|
+
flushHeld: () => undefined,
|
|
65
|
+
awake: () => {
|
|
66
|
+
calls.awake++;
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
);
|
|
70
|
+
return { idle, calls, readiness, finishWake: () => finishWake() };
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
let previous: string | undefined;
|
|
74
|
+
beforeEach(() => {
|
|
75
|
+
previous = process.env.AKAN_DEV_IDLE_SUSPEND_MS;
|
|
76
|
+
process.env.AKAN_DEV_IDLE_SUSPEND_MS = "5";
|
|
77
|
+
watchers.length = 0;
|
|
78
|
+
});
|
|
79
|
+
afterEach(() => {
|
|
80
|
+
if (previous === undefined) delete process.env.AKAN_DEV_IDLE_SUSPEND_MS;
|
|
81
|
+
else process.env.AKAN_DEV_IDLE_SUSPEND_MS = previous;
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
describe("DevIdleSuspend after stop", () => {
|
|
85
|
+
test("stops a watcher that finished starting after the host stopped, and suspends nothing", async () => {
|
|
86
|
+
const { idle, calls } = suspendOf();
|
|
87
|
+
idle.arm();
|
|
88
|
+
await tick(20);
|
|
89
|
+
expect(watchers).toHaveLength(1);
|
|
90
|
+
idle.stop();
|
|
91
|
+
releaseStart();
|
|
92
|
+
await tick(20);
|
|
93
|
+
expect(watchers[0].stopped).toBe(1);
|
|
94
|
+
expect(calls.release).toBe(0);
|
|
95
|
+
expect(calls.readiness).toBe(1);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test("a wake that settles after stop neither re-arms nor reports the host awake", async () => {
|
|
99
|
+
const { idle, calls, finishWake } = suspendOf();
|
|
100
|
+
idle.arm();
|
|
101
|
+
await tick(20);
|
|
102
|
+
releaseStart();
|
|
103
|
+
await tick(0);
|
|
104
|
+
expect(calls.release).toBe(1);
|
|
105
|
+
const woken = idle.wake("an edit");
|
|
106
|
+
idle.stop();
|
|
107
|
+
finishWake();
|
|
108
|
+
await woken;
|
|
109
|
+
await tick(20);
|
|
110
|
+
expect(calls.awake).toBe(0);
|
|
111
|
+
expect(calls.readiness).toBe(2);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test("a suspended host stops being away once stopped, so a late request is refused instead of held", async () => {
|
|
115
|
+
const { idle, calls } = suspendOf();
|
|
116
|
+
idle.arm();
|
|
117
|
+
await tick(20);
|
|
118
|
+
releaseStart();
|
|
119
|
+
await tick(0);
|
|
120
|
+
expect(calls.release).toBe(1);
|
|
121
|
+
expect(idle.away).toBe(true);
|
|
122
|
+
idle.stop();
|
|
123
|
+
expect(idle.away).toBe(false);
|
|
124
|
+
await idle.wake("a route request");
|
|
125
|
+
expect(calls.wake).toBe(0);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test("activity after stop arms nothing", async () => {
|
|
129
|
+
const { idle, calls } = suspendOf();
|
|
130
|
+
idle.stop();
|
|
131
|
+
idle.markActivity();
|
|
132
|
+
idle.arm();
|
|
133
|
+
await tick(20);
|
|
134
|
+
expect(calls.readiness).toBe(0);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
describe("DevIdleSuspend while the idle watcher starts", () => {
|
|
139
|
+
const suspendOnNextIdle = async (calls: { release: number }) => {
|
|
140
|
+
await tick(20);
|
|
141
|
+
expect(watchers).toHaveLength(2);
|
|
142
|
+
releaseStart();
|
|
143
|
+
await tick(0);
|
|
144
|
+
expect(calls.release).toBe(1);
|
|
145
|
+
expect(watchers[1].stopped).toBe(0);
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
test("a builder request that lands meanwhile keeps the builder, and a later idle period still suspends", async () => {
|
|
149
|
+
const { idle, calls } = suspendOf();
|
|
150
|
+
const sent: BuilderMessage[] = [];
|
|
151
|
+
const builder = {
|
|
152
|
+
status: "ready",
|
|
153
|
+
send: (message: BuilderMessage) => {
|
|
154
|
+
sent.push(message);
|
|
155
|
+
return true;
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
const relay = new BuilderRequestRelay(
|
|
159
|
+
{ logger: logger as unknown as Logger, env: {} },
|
|
160
|
+
{
|
|
161
|
+
builder: () => builder as unknown as IncrementalBuilderHost,
|
|
162
|
+
toBackend: () => undefined,
|
|
163
|
+
markActivity: () => idle.markActivity(),
|
|
164
|
+
away: () => idle.away,
|
|
165
|
+
wake: (reason) => void idle.wake(reason),
|
|
166
|
+
},
|
|
167
|
+
);
|
|
168
|
+
idle.arm();
|
|
169
|
+
await tick(20);
|
|
170
|
+
expect(watchers).toHaveLength(1);
|
|
171
|
+
relay.send({ type: "build-graph", id: 1 } as BuilderMessage);
|
|
172
|
+
releaseStart();
|
|
173
|
+
await tick(0);
|
|
174
|
+
expect(sent).toHaveLength(1);
|
|
175
|
+
expect(calls.release).toBe(0);
|
|
176
|
+
expect(watchers[0].stopped).toBe(1);
|
|
177
|
+
await suspendOnNextIdle(calls);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
test("a backend that went down meanwhile keeps the builder", async () => {
|
|
181
|
+
const { idle, calls, readiness } = suspendOf();
|
|
182
|
+
idle.arm();
|
|
183
|
+
await tick(20);
|
|
184
|
+
readiness.backendReady = false;
|
|
185
|
+
releaseStart();
|
|
186
|
+
await tick(0);
|
|
187
|
+
expect(calls.release).toBe(0);
|
|
188
|
+
expect(watchers[0].stopped).toBe(1);
|
|
189
|
+
readiness.backendReady = true;
|
|
190
|
+
await suspendOnNextIdle(calls);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
test("a stop that lands as the start settles stops that watcher and releases nothing", async () => {
|
|
194
|
+
const { idle, calls } = suspendOf();
|
|
195
|
+
idle.arm();
|
|
196
|
+
await tick(20);
|
|
197
|
+
//? Queued behind the start's own await, so the stop lands after the start settles and before the suspend resumes.
|
|
198
|
+
void watchers[0].started.promise.then(() => idle.stop());
|
|
199
|
+
releaseStart();
|
|
200
|
+
await tick(0);
|
|
201
|
+
expect(calls.release).toBe(0);
|
|
202
|
+
expect(watchers[0].stopped).toBe(1);
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
test("a watcher that fails to start stops only itself, not the one a later suspend committed", async () => {
|
|
206
|
+
const { idle, calls } = suspendOf();
|
|
207
|
+
idle.arm();
|
|
208
|
+
await tick(20);
|
|
209
|
+
idle.markActivity();
|
|
210
|
+
await tick(20);
|
|
211
|
+
expect(watchers).toHaveLength(2);
|
|
212
|
+
releaseStart();
|
|
213
|
+
await tick(0);
|
|
214
|
+
expect(calls.release).toBe(1);
|
|
215
|
+
watchers[0].started.reject(new Error("no watch roots"));
|
|
216
|
+
await tick(0);
|
|
217
|
+
expect(watchers[0].stopped).toBe(1);
|
|
218
|
+
expect(watchers[1].stopped).toBe(0);
|
|
219
|
+
idle.stop();
|
|
220
|
+
});
|
|
221
|
+
});
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import type { Logger } from "akanjs/common";
|
|
2
|
+
import type { ChangeBatch } from "akanjs/server";
|
|
3
|
+
import type { App } from "../commandDecorators";
|
|
4
|
+
// Not via `../frontendBuild`: that barrel loads typescript and tailwind, which a suspended dev host must not hold.
|
|
5
|
+
import { HmrWatcher } from "../frontendBuild/hmrWatcher";
|
|
6
|
+
import { WatchRootResolver } from "../frontendBuild/watchRootResolver";
|
|
7
|
+
import { decideIdleSuspend, type IdleSuspendDecision, resolveIdleSuspendMs } from "./devHostPolicy";
|
|
8
|
+
|
|
9
|
+
interface DevIdleSuspendLinks {
|
|
10
|
+
readiness: () => { builderReady: boolean; backendReady: boolean; buildFailed: boolean; restartPending: boolean };
|
|
11
|
+
release: (detail: string) => void;
|
|
12
|
+
wake: (batch: ChangeBatch | null) => Promise<void>;
|
|
13
|
+
wakeFailed: (files: string[]) => void;
|
|
14
|
+
flushHeld: () => void;
|
|
15
|
+
awake: () => void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export class DevIdleSuspend {
|
|
19
|
+
readonly #app: App;
|
|
20
|
+
readonly #logger: Logger;
|
|
21
|
+
readonly #links: DevIdleSuspendLinks;
|
|
22
|
+
#timer: ReturnType<typeof setTimeout> | null = null;
|
|
23
|
+
#suspended = false;
|
|
24
|
+
#waking = false;
|
|
25
|
+
#stopped = false;
|
|
26
|
+
#activity = 0;
|
|
27
|
+
#wokeAtMono: number | null = null;
|
|
28
|
+
#watcher: HmrWatcher | null = null;
|
|
29
|
+
#suspendedChanges: ChangeBatch | null = null;
|
|
30
|
+
|
|
31
|
+
constructor(app: App, { logger }: { logger: Logger }, links: DevIdleSuspendLinks) {
|
|
32
|
+
this.#app = app;
|
|
33
|
+
this.#logger = logger;
|
|
34
|
+
this.#links = links;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
static idleMs(): number | null {
|
|
38
|
+
return resolveIdleSuspendMs(process.env.AKAN_DEV_IDLE_SUSPEND_MS);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
get away(): boolean {
|
|
42
|
+
return !this.#stopped && (this.#suspended || this.#waking);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
markActivity(): void {
|
|
46
|
+
this.#activity++;
|
|
47
|
+
if (this.#suspended || this.#waking) return;
|
|
48
|
+
this.arm();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
arm(): void {
|
|
52
|
+
const idleMs = DevIdleSuspend.idleMs();
|
|
53
|
+
this.#cancel();
|
|
54
|
+
if (idleMs === null || this.#stopped) return;
|
|
55
|
+
this.#timer = setTimeout(() => {
|
|
56
|
+
this.#timer = null;
|
|
57
|
+
void this.#suspendWhenIdle(idleMs);
|
|
58
|
+
}, idleMs);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
#cancel(): void {
|
|
62
|
+
if (!this.#timer) return;
|
|
63
|
+
clearTimeout(this.#timer);
|
|
64
|
+
this.#timer = null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
#stopWatcher(): void {
|
|
68
|
+
this.#watcher?.stop();
|
|
69
|
+
this.#watcher = null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
//? For good: a wake, a builder message or a relayed request that comes after the host stops must not re-arm it, and
|
|
73
|
+
//? a request must reach the stopped builder, which refuses it, rather than wait on a wake that will not come.
|
|
74
|
+
stop(): void {
|
|
75
|
+
this.#stopped = true;
|
|
76
|
+
this.#cancel();
|
|
77
|
+
this.#stopWatcher();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async wake(reason: string): Promise<void> {
|
|
81
|
+
if (!this.#suspended || this.#waking || this.#stopped) return;
|
|
82
|
+
this.#waking = true;
|
|
83
|
+
this.#cancel();
|
|
84
|
+
const startedAtMono = performance.now();
|
|
85
|
+
this.#logger.info(`[idle-suspend] waking (${reason})`);
|
|
86
|
+
const watcher = this.#watcher;
|
|
87
|
+
this.#watcher = null;
|
|
88
|
+
let batch: ChangeBatch | null = null;
|
|
89
|
+
try {
|
|
90
|
+
//? Closed, not stopped: a save its last scan found, a config one included, has no other record once released.
|
|
91
|
+
const unreported = await watcher?.close();
|
|
92
|
+
if (unreported) this.#recordSuspendedChange(unreported);
|
|
93
|
+
batch = this.#suspendedChanges;
|
|
94
|
+
this.#suspendedChanges = null;
|
|
95
|
+
if (this.#stopped) return;
|
|
96
|
+
await this.#links.wake(batch);
|
|
97
|
+
this.#logger.info(`[idle-suspend] awake in ${Math.round(performance.now() - startedAtMono)}ms`);
|
|
98
|
+
} catch (err) {
|
|
99
|
+
this.#logger.error(
|
|
100
|
+
`[idle-suspend] wake failed; recovering the builder: ${err instanceof Error ? err.message : String(err)}`,
|
|
101
|
+
);
|
|
102
|
+
this.#links.wakeFailed(batch?.files ?? []);
|
|
103
|
+
} finally {
|
|
104
|
+
this.#suspended = false;
|
|
105
|
+
this.#waking = false;
|
|
106
|
+
this.#wokeAtMono = performance.now();
|
|
107
|
+
this.#links.flushHeld();
|
|
108
|
+
this.arm();
|
|
109
|
+
// A wake often leaves the backend state untouched, so nothing else would tell a supervisor it came back.
|
|
110
|
+
if (!this.#stopped) this.#links.awake();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
#decide(): IdleSuspendDecision {
|
|
115
|
+
return decideIdleSuspend({
|
|
116
|
+
enabled: true,
|
|
117
|
+
suspended: this.#suspended,
|
|
118
|
+
...this.#links.readiness(),
|
|
119
|
+
msSinceWake: this.#wokeAtMono === null ? null : performance.now() - this.#wokeAtMono,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async #suspendWhenIdle(idleMs: number): Promise<void> {
|
|
124
|
+
const decision = this.#decide();
|
|
125
|
+
if (decision !== "suspend") {
|
|
126
|
+
this.#logger.verbose(`[idle-suspend] skipped (${decision}); re-arming`);
|
|
127
|
+
this.arm();
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
const activity = this.#activity;
|
|
131
|
+
// Watch before stopping: an edit in the gap would be lost, and nothing would wake the dev server.
|
|
132
|
+
const watcher = await this.#startWatcher();
|
|
133
|
+
if (!watcher) {
|
|
134
|
+
this.arm();
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
if (this.#stopped) {
|
|
138
|
+
watcher.stop();
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
//? Decided again: a request or builder message that marked activity meanwhile is on the awake builder.
|
|
142
|
+
const recheck = this.#activity === activity ? this.#decide() : "busy";
|
|
143
|
+
if (recheck !== "suspend") {
|
|
144
|
+
this.#logger.verbose(`[idle-suspend] skipped (${recheck} while the idle watcher started); re-arming`);
|
|
145
|
+
watcher.stop();
|
|
146
|
+
this.arm();
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
this.#watcher = watcher;
|
|
150
|
+
this.#suspended = true;
|
|
151
|
+
this.#links.release(`idle ${Math.round(idleMs / 1000)}s`);
|
|
152
|
+
this.#logger.info(
|
|
153
|
+
`[idle-suspend] no build activity for ${Math.round(idleMs / 1000)}s; released the builder — the next edit or route request brings it back`,
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
async #startWatcher(): Promise<HmrWatcher | null> {
|
|
158
|
+
let watcher: HmrWatcher | null = null;
|
|
159
|
+
try {
|
|
160
|
+
const roots = await new WatchRootResolver(this.#app).resolve();
|
|
161
|
+
watcher = new HmrWatcher({
|
|
162
|
+
roots,
|
|
163
|
+
logger: this.#logger,
|
|
164
|
+
onBatch: (batch) => {
|
|
165
|
+
this.#recordSuspendedChange(batch);
|
|
166
|
+
void this.wake(`${batch.files.length} file(s) changed`);
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
// Awaited so the mtime baseline exists before the first edit; a file missing from the batch is never rebuilt.
|
|
170
|
+
await watcher.start();
|
|
171
|
+
return watcher;
|
|
172
|
+
} catch (err) {
|
|
173
|
+
this.#logger.warn(
|
|
174
|
+
`[idle-suspend] could not install the idle watcher; staying awake: ${err instanceof Error ? err.message : String(err)}`,
|
|
175
|
+
);
|
|
176
|
+
watcher?.stop();
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
#recordSuspendedChange(batch: ChangeBatch): void {
|
|
182
|
+
const current = this.#suspendedChanges;
|
|
183
|
+
if (!current) {
|
|
184
|
+
this.#suspendedChanges = { files: [...batch.files], kinds: new Set(batch.kinds) };
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
this.#suspendedChanges = {
|
|
188
|
+
files: [...new Set([...current.files, ...batch.files])],
|
|
189
|
+
kinds: new Set([...current.kinds, ...batch.kinds]),
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
}
|