@akanjs/devkit 3.2.0-rc.3 → 3.2.0-rc.31

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