@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.
Files changed (353) hide show
  1. package/CHANGELOG.md +0 -529
  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 +152 -6
  7. package/akanApp/akanApp.host.ts +187 -1220
  8. package/akanApp/akanApp.host.wiring.test.ts +931 -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 +394 -0
  14. package/akanApp/devBuildStatusBoard.ts +128 -0
  15. package/akanApp/devBuilder.ts +200 -0
  16. package/akanApp/devIdleSuspend.test.ts +221 -0
  17. package/akanApp/devIdleSuspend.ts +192 -0
  18. package/akanApp/devIdleSuspend.watcher.test.ts +120 -0
  19. package/akanApp/devRecycler.test.ts +66 -0
  20. package/akanApp/devRecycler.ts +305 -0
  21. package/akanApp/devStartTimeline.test.ts +115 -0
  22. package/akanApp/devStartTimeline.ts +69 -0
  23. package/akanApp/processRss.ts +61 -0
  24. package/akanConfig/akanConfig.test.ts +45 -17
  25. package/akanConfig/akanConfig.ts +10 -10
  26. package/akanConfig/akanWorkspaceConfig.ts +1 -1
  27. package/akanConfig/productionLockfile.ts +1 -1
  28. package/apiReport/apiReport.test.ts +34 -3
  29. package/apiReport/apiReportDiff.ts +35 -1
  30. package/apiReport/apiReportPolicy.ts +3 -2
  31. package/{applicationBuildReporter.ts → app/applicationBuildReporter.ts} +2 -49
  32. package/{applicationBuildRunner.test.ts → app/applicationBuildRunner.test.ts} +71 -8
  33. package/{applicationBuildRunner.ts → app/applicationBuildRunner.ts} +60 -21
  34. package/{applicationTestPreload.ts → app/applicationTestPreload.ts} +1 -1
  35. package/{routeJsBudget.test.ts → app/routeJsBudget.test.ts} +17 -1
  36. package/{routeJsBudget.ts → app/routeJsBudget.ts} +9 -3
  37. package/{routeSourceValidator.test.ts → app/routeSourceValidator.test.ts} +17 -0
  38. package/{routeSourceValidator.ts → app/routeSourceValidator.ts} +5 -1
  39. package/artifact/implicitRootLayout.test.ts +71 -3
  40. package/artifact/implicitRootLayout.ts +9 -3
  41. package/artifact/implicitRootLayoutRender.test.tsx +297 -0
  42. package/biome.base.json +2 -1
  43. package/cloud/cloudApi.test.ts +1 -1
  44. package/cloud/configLock.test.ts +1 -1
  45. package/cloud/globalConfig.test.ts +1 -1
  46. package/cloud/globalConfig.ts +1 -1
  47. package/cloud/updatePackUpload.test.ts +1 -1
  48. package/codeAgent/agent/AkanCodeEnv.ts +1 -1
  49. package/codeAgent/agent/AkanCodeServices.ts +23 -0
  50. package/codeAgent/agent/akanCodePaths.ts +1 -1
  51. package/codeAgent/agent/akanCodeServices.test.ts +54 -0
  52. package/codeAgent/agent/akanSystemPrompt.ts +1 -1
  53. package/codeAgent/agent/codeAgent.test.ts +1 -1
  54. package/codeAgent/skills/akan-debug/SKILL.md +8 -5
  55. package/codeAgent/skills/akan-err/SKILL.md +7 -0
  56. package/codeAgent/skills/akan-mcp/SKILL.md +19 -1
  57. package/codeAgent/skills/akan-scaffold/SKILL.md +1 -1
  58. package/codeAgent/skills/akan-validate/SKILL.md +3 -3
  59. package/codeAgent/tools/AkanCli.ts +1 -1
  60. package/codeAgent/tools/AkanToolPack.ts +2 -2
  61. package/codeAgent/tools/akanCodePlugins.test.ts +1 -1
  62. package/commandDecorators/command.ts +35 -6
  63. package/commandDecorators/commandBuilder.ts +1 -1
  64. package/commandDecorators/commandDecorators.test.ts +107 -6
  65. package/commandDecorators/targetMeta.ts +2 -0
  66. package/commandDecorators/workspaceVersionCheck.test.ts +70 -1
  67. package/commandDecorators/workspaceVersionCheck.ts +64 -14
  68. package/context/akanContext.ts +576 -0
  69. package/context/akanContextInspection.ts +296 -0
  70. package/{akanMcpContract.test.ts → context/akanMcpContract.test.ts} +1 -1
  71. package/{akanMcpContract.ts → context/akanMcpContract.ts} +16 -256
  72. package/context/doctor/agentGuideCheck.ts +81 -0
  73. package/context/doctor/configLeftoverCheck.ts +35 -0
  74. package/context/doctor/doctorFindings.ts +70 -0
  75. package/context/doctor/generatedFreshness.ts +56 -0
  76. package/context/doctor/moduleShapeCheck.ts +88 -0
  77. package/context/doctor/recipeDuplicateCheck.ts +42 -0
  78. package/context/doctor/recipeIndexCheck.ts +87 -0
  79. package/context/doctor/rootShapeCheck.ts +55 -0
  80. package/context/doctor/workflowScope.ts +97 -0
  81. package/{recipeScanner.test.ts → context/recipeScanner.test.ts} +1 -1
  82. package/context/safeRead.ts +9 -0
  83. package/csrE2e/csrE2eHarness.fixture.ts +1 -1
  84. package/devkitUtils.test.ts +39 -5
  85. package/{apiReference.test.ts → docs/apiReference.test.ts} +4 -4
  86. package/{apiReference.ts → docs/apiReference.ts} +2 -2
  87. package/docs/errorCodeReference.test.ts +282 -0
  88. package/docs/errorCodeReference.ts +71 -0
  89. package/docs/errorCodeScan.ts +551 -0
  90. package/{frameworkGraph.test.ts → docs/frameworkGraph.test.ts} +1 -1
  91. package/executors/appExecutor.ts +463 -0
  92. package/executors/commandExecutionError.ts +53 -0
  93. package/executors/executor.ts +527 -0
  94. package/{executors.linkFallback.test.ts → executors/executors.linkFallback.test.ts} +1 -1
  95. package/{executors.test.ts → executors/executors.test.ts} +106 -18
  96. package/executors/index.ts +8 -0
  97. package/executors/libExecutor.ts +23 -0
  98. package/executors/moduleExecutor.ts +18 -0
  99. package/executors/pkgExecutor.ts +129 -0
  100. package/executors/sysExecutor.ts +301 -0
  101. package/executors/workspaceExecutor.ts +277 -0
  102. package/frontendBuild/allRoutesBuilder.test.ts +1 -1
  103. package/frontendBuild/autoImportSync.test.ts +1 -1
  104. package/frontendBuild/autoImportSync.ts +1 -1
  105. package/frontendBuild/buildCacheStamp.test.ts +42 -0
  106. package/frontendBuild/buildCacheStamp.ts +23 -0
  107. package/frontendBuild/buildRouteClient.test.ts +1 -1
  108. package/frontendBuild/clientEntriesBundler.test.ts +1 -1
  109. package/frontendBuild/csrArtifactBuilder.test.ts +1 -1
  110. package/frontendBuild/csrDevArtifactWriter.ts +1 -1
  111. package/frontendBuild/cssCandidateCache.test.ts +70 -1
  112. package/frontendBuild/cssCandidateCache.ts +17 -10
  113. package/frontendBuild/cssCompiler.test.ts +3 -2
  114. package/frontendBuild/devGeneratedIndexSync.test.ts +1 -1
  115. package/frontendBuild/devGeneratedIndexSync.ts +7 -38
  116. package/frontendBuild/dictionaryAssetBuilder.test.ts +1 -1
  117. package/frontendBuild/fontOptimizer.test.ts +145 -4
  118. package/frontendBuild/fontOptimizer.ts +103 -18
  119. package/frontendBuild/fontPruner.test.ts +1 -1
  120. package/frontendBuild/frontendBuild.test.ts +3 -3
  121. package/frontendBuild/hmrWatcher.stop.test.ts +63 -0
  122. package/frontendBuild/hmrWatcher.test.ts +1 -1
  123. package/frontendBuild/hmrWatcher.ts +22 -1
  124. package/frontendBuild/mcpAppViewBuilder.test.ts +1 -1
  125. package/frontendBuild/mcpAppViewBuilder.ts +1 -1
  126. package/frontendBuild/nativeCore.test.ts +1 -1
  127. package/frontendBuild/optionalPeers.test.ts +36 -8
  128. package/frontendBuild/pagesBundleBuilder.test.ts +2 -3
  129. package/frontendBuild/pagesBundleBuilder.ts +1 -1
  130. package/frontendBuild/precompressArtifacts.test.ts +1 -1
  131. package/frontendBuild/precompressArtifacts.ts +19 -6
  132. package/frontendBuild/serverGraphFile.ts +1 -1
  133. package/frontendBuild/sourceMtimeIndex.test.ts +1 -1
  134. package/frontendBuild/ssrBaseArtifactBuilder.test.ts +30 -1
  135. package/frontendBuild/ssrBaseArtifactBuilder.ts +40 -12
  136. package/frontendBuild/ssrDevBundler.test.ts +1 -1
  137. package/frontendBuild/vendorImportScanner.test.ts +1 -1
  138. package/frontendBuild/vendorNarrowing.test.ts +1 -1
  139. package/frontendBuild/watchRootResolver.test.ts +1 -1
  140. package/{agentAssets.test.ts → guideline/agentAssets.test.ts} +1 -1
  141. package/{agentAssets.ts → guideline/agentAssets.ts} +2 -2
  142. package/{agentsIndex.test.ts → guideline/agentsIndex.test.ts} +2 -2
  143. package/{agentsIndex.ts → guideline/agentsIndex.ts} +13 -10
  144. package/{conventionSet.test.ts → guideline/conventionSet.test.ts} +7 -4
  145. package/{conventionSet.ts → guideline/conventionSet.ts} +1 -1
  146. package/{prompter.ts → guideline/prompter.ts} +2 -3
  147. package/incrementalBuilder/buildBatch.proc.ts +16 -5
  148. package/incrementalBuilder/buildBatchProtocol.ts +3 -0
  149. package/incrementalBuilder/buildBatchRunner.test.ts +122 -2
  150. package/incrementalBuilder/buildBatchRunner.ts +17 -4
  151. package/incrementalBuilder/builderBoot.ts +113 -0
  152. package/incrementalBuilder/builderBuildStatus.ts +23 -0
  153. package/incrementalBuilder/builderChannel.test.ts +1 -1
  154. package/incrementalBuilder/builderChannel.ts +19 -2
  155. package/incrementalBuilder/builderGraphPayloads.ts +3 -3
  156. package/incrementalBuilder/builderLanes.ts +157 -0
  157. package/incrementalBuilder/builderWatch.ts +213 -0
  158. package/incrementalBuilder/csrRegistry.ts +234 -0
  159. package/incrementalBuilder/incrementalBuilder.host.test.ts +16 -0
  160. package/incrementalBuilder/incrementalBuilder.host.ts +7 -1
  161. package/incrementalBuilder/incrementalBuilder.proc.test.ts +142 -7
  162. package/incrementalBuilder/incrementalBuilder.proc.ts +82 -823
  163. package/incrementalBuilder/ssrRegistry.ts +282 -0
  164. package/index.ts +22 -22
  165. package/integration/devStability.integration.test.ts +62 -56
  166. package/integration/devStabilityHarness.test.ts +1 -1
  167. package/lint/__fixtures__/no-import-common-err/bad.tsx +13 -0
  168. package/lint/__fixtures__/no-import-common-err/good.tsx +12 -0
  169. package/{biomeBase.test.ts → lint/biomeBase.test.ts} +1 -1
  170. package/lint/gritRules.test.ts +1 -1
  171. package/{linter.test.ts → lint/linter.test.ts} +1 -1
  172. package/lint/no-import-common-err.grit +31 -0
  173. package/lint/no-init-fetch-in-client.grit +1 -1
  174. package/mobile/desktopBin.test.ts +1 -1
  175. package/mobile/desktopRelease.test.ts +1 -1
  176. package/mobile/desktopServerStage.test.ts +2 -2
  177. package/mobile/desktopServerStage.ts +1 -1
  178. package/mobile/nativeApi.test.ts +1 -1
  179. package/mobile/nativeApp.test.ts +1 -1
  180. package/mobile/nativeConfig.test.ts +1 -1
  181. package/mobile/nativePluginFolders.test.ts +1 -1
  182. package/mobile/nativePublicEnv.test.ts +1 -1
  183. package/mobile/nativePublicEnv.ts +2 -1
  184. package/mobile/nativeWebDir.test.ts +1 -1
  185. package/mobile/serverBundleSecrets.test.ts +1 -1
  186. package/mobile/tarWriter.test.ts +1 -1
  187. package/mobile/updatePackFolder.test.ts +1 -1
  188. package/package.json +173 -9
  189. package/packageExports.test.ts +20 -2
  190. package/piDependencyPins.test.ts +1 -1
  191. package/pipeline/PipelineDefinition.ts +1 -1
  192. package/platformTest/IdleWatchedProcess.test.ts +1 -1
  193. package/platformTest/LinuxDockerTarget.ts +1 -1
  194. package/platformTest/PlatformTestRun.test.ts +1 -1
  195. package/platformTest/TestSnapshot.test.ts +1 -1
  196. package/platformTest/WindowsSshTarget.ts +1 -1
  197. package/preview/previewView.test.ts +23 -1
  198. package/{abstractDoc.test.ts → quality/abstractDoc.test.ts} +2 -2
  199. package/{abstractDoc.ts → quality/abstractDoc.ts} +1 -1
  200. package/quality/bareErrorScanner.ts +126 -0
  201. package/{maintainabilityBaseline.test.ts → quality/maintainabilityBaseline.test.ts} +73 -0
  202. package/{maintainabilityBaseline.ts → quality/maintainabilityBaseline.ts} +97 -9
  203. package/{maintainabilityContract.test.ts → quality/maintainabilityContract.test.ts} +383 -2
  204. package/{maintainabilityContract.ts → quality/maintainabilityContract.ts} +151 -29
  205. package/{maintainabilityExceptionScanner.test.ts → quality/maintainabilityExceptionScanner.test.ts} +15 -1
  206. package/{maintainabilityExceptionScanner.ts → quality/maintainabilityExceptionScanner.ts} +5 -1
  207. package/{maintainabilityLimits.ts → quality/maintainabilityLimits.ts} +12 -0
  208. package/{maintainabilityReport.ts → quality/maintainabilityReport.ts} +20 -3
  209. package/{qualityScanner.test.ts → quality/qualityScanner.test.ts} +41 -1
  210. package/{qualityScanner.ts → quality/qualityScanner.ts} +25 -91
  211. package/{storeAccessScanner.ts → quality/storeAccessScanner.ts} +15 -2
  212. package/quality/workspaceSourceFiles.ts +82 -0
  213. package/{subspace.test.ts → subspace/subspace.test.ts} +25 -4
  214. package/{subspace.ts → subspace/subspace.ts} +5 -5
  215. package/{subspaceClone.ts → subspace/subspaceClone.ts} +8 -8
  216. package/{subspaceConfig.ts → subspace/subspaceConfig.ts} +5 -1
  217. package/{testHelpers.ts → test/testHelpers.ts} +37 -1
  218. package/transforms/barrelAnalyzer.ts +31 -10
  219. package/transforms/browserDirnamePlugin.test.ts +1 -1
  220. package/transforms/externalizeFrameworkPlugin.test.ts +1 -1
  221. package/transforms/mcpAppPageTrimmer.test.ts +1 -1
  222. package/transforms/pureLazyMarker.test.ts +1 -1
  223. package/transforms/serverEnvPlugin.test.ts +1 -1
  224. package/transforms/serverEnvProfile.test.ts +1 -1
  225. package/transforms/sideEffectImportOrder.test.ts +1 -1
  226. package/transforms/transforms.test.ts +52 -2
  227. package/transforms/tsconfigPackageResolver.test.ts +1 -1
  228. package/{createTunnel.test.ts → tunnel/createTunnel.test.ts} +1 -1
  229. package/{createTunnel.ts → tunnel/createTunnel.ts} +2 -2
  230. package/{sshHostKeys.ts → tunnel/sshHostKeys.ts} +2 -2
  231. package/typecheck/projectTypecheck.test.ts +23 -1
  232. package/typecheck/projectTypecheck.ts +10 -2
  233. package/{typeChecker.test.ts → typecheck/typeChecker.test.ts} +1 -1
  234. package/{typeChecker.ts → typecheck/typeChecker.ts} +5 -4
  235. package/typecheck/typecheck.proc.ts +6 -2
  236. package/typecheck/typecheckFailure.ts +1 -1
  237. package/util/errorReport.ts +66 -0
  238. package/{fileSys.test.ts → util/fileSys.test.ts} +13 -0
  239. package/{fileSys.ts → util/fileSys.ts} +2 -2
  240. package/{jsonFormatter.test.ts → util/jsonFormatter.test.ts} +1 -1
  241. package/workflow/constantSource.ts +187 -0
  242. package/workflow/dictionarySource.ts +184 -0
  243. package/workflow/executor.ts +6 -9
  244. package/workflow/fieldExpression.ts +153 -0
  245. package/workflow/fieldLabel.ts +61 -0
  246. package/workflow/fieldOrder.ts +117 -0
  247. package/workflow/fieldType.ts +2 -1
  248. package/workflow/guardCatalog.test.ts +1 -1
  249. package/workflow/keyRename.ts +1 -1
  250. package/workflow/moduleIndex.test.ts +2 -2
  251. package/workflow/moduleIndex.ts +2 -2
  252. package/workflow/modulePaths.ts +27 -0
  253. package/workflow/mutationScaffold.ts +7 -15
  254. package/workflow/mutationSource.ts +2 -1
  255. package/workflow/plan.ts +2 -1
  256. package/workflow/primitiveReport.ts +78 -0
  257. package/workflow/rolloutGate.test.ts +1 -1
  258. package/workflow/rolloutGate.ts +1 -1
  259. package/workflow/serviceSource.ts +33 -0
  260. package/workflow/signalSource.ts +96 -0
  261. package/workflow/source.ts +50 -1100
  262. package/workflow/sourceAst.ts +30 -0
  263. package/workflow/sourceImports.ts +105 -0
  264. package/workflow/sourceText.ts +13 -0
  265. package/workflow/templateSource.ts +30 -0
  266. package/workflow/testSource.ts +31 -0
  267. package/workflow/types.ts +1 -1
  268. package/workflow/uiPolicy.ts +1 -1
  269. package/{appSelectionMemory.ts → workspace/appSelectionMemory.ts} +1 -1
  270. package/{codegenLock.test.ts → workspace/codegenLock.test.ts} +1 -1
  271. package/{dependencyScanner.test.ts → workspace/dependencyScanner.test.ts} +1 -1
  272. package/{dependencyScanner.ts → workspace/dependencyScanner.ts} +2 -2
  273. package/{envSeed.test.ts → workspace/envSeed.test.ts} +2 -2
  274. package/{envSeed.ts → workspace/envSeed.ts} +1 -1
  275. package/{libSource.test.ts → workspace/libSource.test.ts} +2 -2
  276. package/{libSource.ts → workspace/libSource.ts} +1 -1
  277. package/{scanInfo.ts → workspace/scanInfo.ts} +21 -10
  278. package/{slicePlanner.test.ts → workspace/slicePlanner.test.ts} +2 -2
  279. package/{slicePlanner.ts → workspace/slicePlanner.ts} +1 -1
  280. package/{workspaceGraph.test.ts → workspace/workspaceGraph.test.ts} +1 -1
  281. package/{workspaceGraph.ts → workspace/workspaceGraph.ts} +1 -1
  282. package/{workspaceLayout.test.ts → workspace/workspaceLayout.test.ts} +1 -1
  283. package/{workspaceLayout.ts → workspace/workspaceLayout.ts} +3 -1
  284. package/akanContext.ts +0 -1083
  285. package/executors.ts +0 -1749
  286. /package/{applicationBuildReporter.test.ts → app/applicationBuildReporter.test.ts} +0 -0
  287. /package/{akanMcpToolError.ts → context/akanMcpToolError.ts} +0 -0
  288. /package/{moduleFieldNames.test.ts → context/moduleFieldNames.test.ts} +0 -0
  289. /package/{moduleFieldNames.ts → context/moduleFieldNames.ts} +0 -0
  290. /package/{recipeScanner.ts → context/recipeScanner.ts} +0 -0
  291. /package/{declarationReader.ts → docs/declarationReader.ts} +0 -0
  292. /package/{frameworkGraph.ts → docs/frameworkGraph.ts} +0 -0
  293. /package/{biomeBase.ts → lint/biomeBase.ts} +0 -0
  294. /package/{linter.ts → lint/linter.ts} +0 -0
  295. /package/{commentDensityScanner.test.ts → quality/commentDensityScanner.test.ts} +0 -0
  296. /package/{commentDensityScanner.ts → quality/commentDensityScanner.ts} +0 -0
  297. /package/{componentSizeScanner.test.ts → quality/componentSizeScanner.test.ts} +0 -0
  298. /package/{componentSizeScanner.ts → quality/componentSizeScanner.ts} +0 -0
  299. /package/{componentWriteChainScanner.test.ts → quality/componentWriteChainScanner.test.ts} +0 -0
  300. /package/{componentWriteChainScanner.ts → quality/componentWriteChainScanner.ts} +0 -0
  301. /package/{deprecatedCommentScanner.test.ts → quality/deprecatedCommentScanner.test.ts} +0 -0
  302. /package/{deprecatedCommentScanner.ts → quality/deprecatedCommentScanner.ts} +0 -0
  303. /package/{endpointReach.test.ts → quality/endpointReach.test.ts} +0 -0
  304. /package/{endpointReach.ts → quality/endpointReach.ts} +0 -0
  305. /package/{formSetterScanner.test.ts → quality/formSetterScanner.test.ts} +0 -0
  306. /package/{formSetterScanner.ts → quality/formSetterScanner.ts} +0 -0
  307. /package/{kindBranchScanner.test.ts → quality/kindBranchScanner.test.ts} +0 -0
  308. /package/{kindBranchScanner.ts → quality/kindBranchScanner.ts} +0 -0
  309. /package/{maintainabilityReport.test.ts → quality/maintainabilityReport.test.ts} +0 -0
  310. /package/{renderMutationScanner.test.ts → quality/renderMutationScanner.test.ts} +0 -0
  311. /package/{renderMutationScanner.ts → quality/renderMutationScanner.ts} +0 -0
  312. /package/{serviceLoopCallScanner.test.ts → quality/serviceLoopCallScanner.test.ts} +0 -0
  313. /package/{serviceLoopCallScanner.ts → quality/serviceLoopCallScanner.ts} +0 -0
  314. /package/{signalMutationIndex.test.ts → quality/signalMutationIndex.test.ts} +0 -0
  315. /package/{signalMutationIndex.ts → quality/signalMutationIndex.ts} +0 -0
  316. /package/{sourceComments.test.ts → quality/sourceComments.test.ts} +0 -0
  317. /package/{sourceComments.ts → quality/sourceComments.ts} +0 -0
  318. /package/{ssrScanner.test.ts → quality/ssrScanner.test.ts} +0 -0
  319. /package/{ssrScanner.ts → quality/ssrScanner.ts} +0 -0
  320. /package/{storeAccessScanner.test.ts → quality/storeAccessScanner.test.ts} +0 -0
  321. /package/{storeSource.ts → quality/storeSource.ts} +0 -0
  322. /package/{storeWriteScanner.test.ts → quality/storeWriteScanner.test.ts} +0 -0
  323. /package/{storeWriteScanner.ts → quality/storeWriteScanner.ts} +0 -0
  324. /package/{structureScanner.test.ts → quality/structureScanner.test.ts} +0 -0
  325. /package/{structureScanner.ts → quality/structureScanner.ts} +0 -0
  326. /package/{testOnlyExportScanner.test.ts → quality/testOnlyExportScanner.test.ts} +0 -0
  327. /package/{testOnlyExportScanner.ts → quality/testOnlyExportScanner.ts} +0 -0
  328. /package/{writePath.test.ts → quality/writePath.test.ts} +0 -0
  329. /package/{writePath.ts → quality/writePath.ts} +0 -0
  330. /package/{writePlacementScanner.test.ts → quality/writePlacementScanner.test.ts} +0 -0
  331. /package/{writePlacementScanner.ts → quality/writePlacementScanner.ts} +0 -0
  332. /package/{writingActionIndex.test.ts → quality/writingActionIndex.test.ts} +0 -0
  333. /package/{writingActionIndex.ts → quality/writingActionIndex.ts} +0 -0
  334. /package/{subspaceReport.ts → subspace/subspaceReport.ts} +0 -0
  335. /package/{sshTunnel.ts → tunnel/sshTunnel.ts} +0 -0
  336. /package/{fileEditor.ts → util/fileEditor.ts} +0 -0
  337. /package/{jsonFormatter.ts → util/jsonFormatter.ts} +0 -0
  338. /package/{selectModel.ts → util/selectModel.ts} +0 -0
  339. /package/{semver.test.ts → util/semver.test.ts} +0 -0
  340. /package/{semver.ts → util/semver.ts} +0 -0
  341. /package/{shellOnlyEnv.test.ts → util/shellOnlyEnv.test.ts} +0 -0
  342. /package/{shellOnlyEnv.ts → util/shellOnlyEnv.ts} +0 -0
  343. /package/{spinner.test.ts → util/spinner.test.ts} +0 -0
  344. /package/{spinner.ts → util/spinner.ts} +0 -0
  345. /package/{stripAnsi.ts → util/stripAnsi.ts} +0 -0
  346. /package/{codegenLock.ts → workspace/codegenLock.ts} +0 -0
  347. /package/{getRelatedCnsts.ts → workspace/getRelatedCnsts.ts} +0 -0
  348. /package/{gitRevision.test.ts → workspace/gitRevision.test.ts} +0 -0
  349. /package/{gitRevision.ts → workspace/gitRevision.ts} +0 -0
  350. /package/{manifestDependencies.ts → workspace/manifestDependencies.ts} +0 -0
  351. /package/{packageExportsMap.ts → workspace/packageExportsMap.ts} +0 -0
  352. /package/{repoIdentity.ts → workspace/repoIdentity.ts} +0 -0
  353. /package/{types.ts → workspace/types.ts} +0 -0
@@ -0,0 +1,213 @@
1
+ import path from "node:path";
2
+ import type { App } from "@akanjs/devkit/commandDecorators";
3
+ import type { PageRoot } from "@akanjs/devkit/executors";
4
+ import { AutoImportSync } from "@akanjs/devkit/frontendBuild/autoImportSync";
5
+ import { DevChangePlanner } from "@akanjs/devkit/frontendBuild/devChangePlanner";
6
+ import { DevGeneratedIndexSync } from "@akanjs/devkit/frontendBuild/devGeneratedIndexSync";
7
+ import { HmrWatcher } from "@akanjs/devkit/frontendBuild/hmrWatcher";
8
+ import { WatchRootResolver } from "@akanjs/devkit/frontendBuild/watchRootResolver";
9
+ import { CodegenLock } from "@akanjs/devkit/workspace/codegenLock";
10
+ import type { Logger } from "akanjs/common";
11
+ import type { ChangeBatch } from "akanjs/server";
12
+ import type { BuildBatchNeed } from "./buildBatchProtocol";
13
+ import { sendBuildStatus } from "./builderBuildStatus";
14
+ import { BuilderChannel } from "./builderChannel";
15
+ import type { BuilderGraphPayloads } from "./builderGraphPayloads";
16
+ import type { BuilderLanes } from "./builderLanes";
17
+ import type { BatchJob, DiscoveryJob } from "./builderWorkQueue";
18
+ import type { CsrRegistry } from "./csrRegistry";
19
+ import { prepareDevWatchBatch } from "./devWatchBatch";
20
+ import type { SsrRegistry } from "./ssrRegistry";
21
+
22
+ interface BuilderWatchParts {
23
+ logger: Logger;
24
+ lanes: BuilderLanes;
25
+ csr: CsrRegistry;
26
+ ssr: SsrRegistry;
27
+ graphPayloads: BuilderGraphPayloads;
28
+ }
29
+
30
+ interface BuilderWatchLinks {
31
+ nextGeneration: () => number;
32
+ refreshDiscovery: (job: DiscoveryJob) => Promise<void>;
33
+ }
34
+
35
+ export class BuilderWatch {
36
+ readonly #app: App;
37
+ readonly #logger: Logger;
38
+ readonly #lanes: BuilderLanes;
39
+ readonly #csr: CsrRegistry;
40
+ readonly #ssr: SsrRegistry;
41
+ readonly #graphPayloads: BuilderGraphPayloads;
42
+ readonly #links: BuilderWatchLinks;
43
+ #changePlanner: DevChangePlanner;
44
+ #generatedIndexSync: DevGeneratedIndexSync;
45
+ #autoImportSync: AutoImportSync;
46
+ #watcher: HmrWatcher | null = null;
47
+ #barrelFailed = false;
48
+
49
+ constructor(app: App, { logger, lanes, csr, ssr, graphPayloads }: BuilderWatchParts, links: BuilderWatchLinks) {
50
+ this.#app = app;
51
+ this.#logger = logger;
52
+ this.#lanes = lanes;
53
+ this.#csr = csr;
54
+ this.#ssr = ssr;
55
+ this.#graphPayloads = graphPayloads;
56
+ this.#links = links;
57
+ this.#changePlanner = new DevChangePlanner({ workspaceRoot: app.workspace.workspaceRoot });
58
+ this.#generatedIndexSync = new DevGeneratedIndexSync({ workspaceRoot: app.workspace.workspaceRoot });
59
+ this.#autoImportSync = new AutoImportSync({ workspaceRoot: app.workspace.workspaceRoot });
60
+ }
61
+
62
+ stop(): void {
63
+ this.#watcher?.stop();
64
+ }
65
+
66
+ //* Watch events carry real paths: synced lib pages match by `realDir`, their keys keep the `(libs)/(<lib>)` prefix.
67
+ static #matchPageRoot(roots: PageRoot[], abs: string): PageRoot | null {
68
+ for (const root of roots) {
69
+ const absRoot = path.resolve(root.realDir);
70
+ if (abs === absRoot || abs.startsWith(`${absRoot}${path.sep}`)) return root;
71
+ }
72
+ return null;
73
+ }
74
+ batchTouchesPagesTree(roots: PageRoot[], batch: ChangeBatch): boolean {
75
+ for (const f of batch.files) {
76
+ const abs = path.resolve(f);
77
+ if (!BuilderWatch.#matchPageRoot(roots, abs)) continue;
78
+ if (/\.(tsx|ts|jsx|js)$/.test(abs)) return true;
79
+ }
80
+ return false;
81
+ }
82
+ async batchMayChangePageKeys(roots: PageRoot[], batch: ChangeBatch): Promise<boolean> {
83
+ const pageKeys = new Set((await this.#app.getPageKeys()).map((key) => path.normalize(key)));
84
+ for (const f of batch.files) {
85
+ const abs = path.resolve(f);
86
+ const root = BuilderWatch.#matchPageRoot(roots, abs);
87
+ if (!root) continue;
88
+ if (!/\.(tsx|ts|jsx|js)$/.test(abs)) continue;
89
+ const rel = path.normalize(`${root.keyPrefix}${path.relative(path.resolve(root.realDir), abs)}`);
90
+ if (!(await Bun.file(abs).exists()) || !pageKeys.has(rel)) return true;
91
+ }
92
+ return false;
93
+ }
94
+ async installWatcher() {
95
+ const roots = await new WatchRootResolver(this.#app).resolve();
96
+ const watcher = new HmrWatcher({
97
+ roots,
98
+ logger: this.#logger,
99
+ onBatch: async (batch: ChangeBatch) => {
100
+ await this.#lanes.enqueueFast("hmr-batch", async () => this.#handleWatchBatch(batch));
101
+ },
102
+ });
103
+ await watcher.start();
104
+ this.#watcher = watcher;
105
+ this.#logger.verbose(`watching ${roots.length} roots`);
106
+ }
107
+
108
+ async #handleWatchBatch(batch: ChangeBatch) {
109
+ this.#graphPayloads.touched(batch.files);
110
+ const rawKinds = new Set(batch.kinds);
111
+ if (rawKinds.size === 0) return;
112
+ const generation = this.#links.nextGeneration();
113
+ const trace = { ...batch.trace, batchAt: Date.now() };
114
+ //* Auto-import edits touch only this batch's files, so they rebuild in this same generation.
115
+ const [autoImport, indexSync] = await CodegenLock.run(
116
+ this.#app.workspace.workspaceRoot,
117
+ `hmr-batch:${this.#app.name}`,
118
+ async () => {
119
+ const auto = await this.#autoImportSync.syncForBatch(batch.files);
120
+ return [auto, await this.#generatedIndexSync.syncForBatch(batch.files)] as const;
121
+ },
122
+ );
123
+ for (const error of autoImport.errors) this.#logger.error(error);
124
+ if (autoImport.changedFiles.length > 0)
125
+ this.#logger.verbose(`[auto-import] inserted imports into ${autoImport.changedFiles.length} file(s)`);
126
+ //* Absorbed so the watcher's verification scan does not replay these writes as a user edit next generation.
127
+ await this.#watcher?.absorb([...autoImport.changedFiles, ...indexSync.changedFiles]);
128
+ const { files, kinds, expandedBatch, devPlan, event, hasSyncErrors } = prepareDevWatchBatch({
129
+ generation,
130
+ batch,
131
+ indexSync,
132
+ changePlanner: this.#changePlanner,
133
+ });
134
+ this.#logger.verbose(
135
+ `[hmr] batch generation=${generation} kinds=${kinds.join(",")} files=${files.length} generated=${indexSync.changedFiles.length} roles=${devPlan.roles.join(",") || "(none)"} actions=${devPlan.actions.join(",") || "(none)"}`,
136
+ );
137
+ for (const error of indexSync.errors) this.#logger.error(error);
138
+
139
+ // Invalidated in the slow lane, under the route builds that read it; a registry check reading it beside them caches
140
+ // nothing a walk began before the invalidation (the discovery's epoch).
141
+ const discovery = kinds.includes("code") ? { files, refresh: kinds.includes("config"), generation } : undefined;
142
+
143
+ if (hasSyncErrors) {
144
+ this.#barrelFailed = true;
145
+ sendBuildStatus("barrel", { generation, ok: false, files, message: indexSync.errors.join("\n") });
146
+ BuilderChannel.emit(event);
147
+ if (discovery)
148
+ void this.#lanes.workQueue
149
+ .enqueue("discovery", async () => await this.#links.refreshDiscovery(discovery))
150
+ .catch(this.#lanes.slowLaneFailed("discovery"));
151
+ return;
152
+ }
153
+ // After a failure too, where nothing changed on disk: the host re-sends a phase still failing to every new tab.
154
+ if (indexSync.changedFiles.length > 0 || this.#barrelFailed)
155
+ sendBuildStatus("barrel", { generation, ok: true, files });
156
+ this.#barrelFailed = false;
157
+
158
+ // Server-only generations skip the client: a fresh pages buildId would rsc-refresh browsers for no visible change.
159
+ const rebuildClient = devPlan.actions.includes("rebuild-client");
160
+ if (kinds.includes("code") && !rebuildClient) {
161
+ this.#logger.verbose(`client rebuild skipped; devPlan actions=${devPlan.actions.join(",") || "(none)"}`);
162
+ }
163
+
164
+ const pageRoots = await this.#app.getPageRoots();
165
+ if (kinds.includes("code") && rebuildClient && (await this.batchMayChangePageKeys(pageRoots, expandedBatch))) {
166
+ const started = Date.now();
167
+ await this.#app.getPageKeys({ refresh: true });
168
+ this.#logger.verbose(`pageKeys updated, app pageKeys are refreshed (${Date.now() - started}ms)`);
169
+ } else if (kinds.includes("code") && rebuildClient && this.batchTouchesPagesTree(pageRoots, expandedBatch)) {
170
+ this.#logger.verbose("pageKeys refresh skipped; changed page source cannot add/remove a route key");
171
+ }
172
+
173
+ BuilderChannel.emit(event);
174
+
175
+ if (kinds.includes("code") && rebuildClient) {
176
+ // Css rides the pages batch rather than its own debounce: the slow lane folds a burst of saves into one batch.
177
+ const needs: BuildBatchNeed[] = ["pages", "css"];
178
+ if (!this.#csr.csrActive)
179
+ this.#logger.verbose(
180
+ `csr-rebundle skipped; request /__csr or ?csr=true (or set AKAN_DEV_CSR_REBUILD=1) to enable per-save CSR rebuilds`,
181
+ );
182
+ //? One after the other, since two compiles side by side slow both. CSR goes first unless its build is being armed:
183
+ //? a CSR patch then waits behind #csrGate, which SSR tabs must not.
184
+ const patchCsr = async () => (this.#csr.csrActive ? await this.#csr.patchCsr(generation, files, trace) : false);
185
+ const patchSsr = async () => await this.#ssr.patchSsr(generation, files, trace);
186
+ let csrToWorker: boolean;
187
+ let ssrToWorker: boolean;
188
+ if (this.#csr.csrArming) {
189
+ ssrToWorker = await patchSsr();
190
+ csrToWorker = await patchCsr();
191
+ } else {
192
+ csrToWorker = await patchCsr();
193
+ ssrToWorker = await patchSsr();
194
+ }
195
+ if (csrToWorker) needs.unshift("csr");
196
+ if (ssrToWorker) needs.unshift("ssr");
197
+ const batch: BatchJob = { generation, needs, changedFiles: files, trace, ...(discovery ? { discovery } : {}) };
198
+ // A worker's registry build rewrites the directory its patcher reads, so the next save waits for it.
199
+ if (needs.includes("csr") || needs.includes("ssr")) await this.#lanes.workQueue.enqueueBatch(batch);
200
+ else void this.#lanes.workQueue.enqueueBatch(batch).catch(this.#lanes.slowLaneFailed("batch"));
201
+ return;
202
+ }
203
+ if (discovery)
204
+ void this.#lanes.workQueue
205
+ .enqueue("discovery", async () => await this.#links.refreshDiscovery(discovery))
206
+ .catch(this.#lanes.slowLaneFailed("discovery"));
207
+ // Css-only batches keep the debounce: they arrive in bursts while a stylesheet is edited.
208
+ if (kinds.includes("css")) {
209
+ this.#lanes.scheduleCssRebuild({ generation, changedFiles: files });
210
+ this.#logger.verbose(`css-rebuild scheduled generation=${generation}`);
211
+ }
212
+ }
213
+ }
@@ -0,0 +1,234 @@
1
+ import { rm } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { ApplicationBuildReporter } from "@akanjs/devkit/app/applicationBuildReporter";
4
+ import type { App } from "@akanjs/devkit/commandDecorators";
5
+ import { CsrDevBundler } from "@akanjs/devkit/frontendBuild/csrDevBundler";
6
+ import { CsrDevPatcher } from "@akanjs/devkit/frontendBuild/csrDevPatcher";
7
+ import type { Logger } from "akanjs/common";
8
+ import type { BaseBuildArtifact, BuilderCsrReq, HmrTrace } from "akanjs/server";
9
+ import { CSR_DEV_PATCHING_MARKER } from "akanjs/server/hmr/csrDevManifest";
10
+ import type { BatchWork, BuildBatchRequest } from "./buildBatchProtocol";
11
+ import type { BuildBatchRunner } from "./buildBatchRunner";
12
+ import { isCompileError, sendBuildStatus } from "./builderBuildStatus";
13
+ import { BuilderChannel } from "./builderChannel";
14
+ import type { BuilderLanes } from "./builderLanes";
15
+
16
+ interface CsrRegistryLinks {
17
+ generation: () => number;
18
+ artifact: () => BaseBuildArtifact;
19
+ batchRequest: (work: BatchWork) => Promise<BuildBatchRequest>;
20
+ countDelegation: (registry: "csr" | "ssr", reason: string) => string;
21
+ }
22
+
23
+ export class CsrRegistry {
24
+ readonly #app: App;
25
+ readonly #logger: Logger;
26
+ readonly #lanes: BuilderLanes;
27
+ readonly #batchRunner: BuildBatchRunner;
28
+ readonly #links: CsrRegistryLinks;
29
+ #shellKey: string | null = null;
30
+ #csrActive = CsrRegistry.#csrArmedByEnv();
31
+ #csrBundler: CsrDevBundler;
32
+ /** Null when `AKAN_DEV_CSR_PATCHER=off`: every CSR save then goes to a build worker, as before the patcher. */
33
+ #patcher: CsrDevPatcher | null;
34
+ /** A worker's full CSR build (arming, re-arming) that a patch must not race for the csr-dev directory. */
35
+ #csrGate: Promise<void> = Promise.resolve();
36
+ #csrArming = false;
37
+ #csrArms = 0;
38
+ #csrWasActive = false;
39
+ #csrArmSucceeded = false;
40
+
41
+ constructor(
42
+ app: App,
43
+ { logger, lanes, batchRunner }: { logger: Logger; lanes: BuilderLanes; batchRunner: BuildBatchRunner },
44
+ links: CsrRegistryLinks,
45
+ ) {
46
+ this.#app = app;
47
+ this.#logger = logger;
48
+ this.#lanes = lanes;
49
+ this.#batchRunner = batchRunner;
50
+ this.#links = links;
51
+ this.#csrBundler = new CsrDevBundler(app);
52
+ this.#patcher =
53
+ process.env.AKAN_DEV_CSR_PATCHER === "off" ? null : new CsrDevPatcher(this.#csrBundler, { resident: true });
54
+ }
55
+
56
+ get csrActive(): boolean {
57
+ return this.#csrActive;
58
+ }
59
+
60
+ get csrArming(): boolean {
61
+ return this.#csrArming;
62
+ }
63
+
64
+ get patcher(): CsrDevPatcher | null {
65
+ return this.#patcher;
66
+ }
67
+
68
+ // True when the save has to go to a build worker: the patcher handed it back, or threw (the worker reports why).
69
+ async patchCsr(generation: number, files: string[], trace: HmrTrace): Promise<boolean> {
70
+ const patcher = this.#patcher;
71
+ if (!patcher) return true;
72
+ await this.#csrGate;
73
+ // The arming build this save waited for failed: CSR is off again, and the next request arms it anew.
74
+ if (!this.#csrActive) return false;
75
+ const started = Date.now();
76
+ const marker = path.join(this.#csrBundler.outDir, CSR_DEV_PATCHING_MARKER);
77
+ await Bun.write(marker, String(process.pid));
78
+ try {
79
+ const result = await patcher.update(files, {
80
+ announce: (update) => {
81
+ const now = Date.now();
82
+ BuilderChannel.emit({
83
+ type: "csr-updated",
84
+ data: {
85
+ generation: update.generation,
86
+ mode: "registry",
87
+ reload: update.reload,
88
+ reason: update.reason,
89
+ patchUrl: update.patchUrl,
90
+ changedIds: update.changedIds,
91
+ trace: { ...trace, patchAt: now, sentAt: now },
92
+ },
93
+ });
94
+ },
95
+ });
96
+ if (result.kind === "delegate") {
97
+ this.#logger.verbose(
98
+ `csr-patch handed to a build worker (${this.#links.countDelegation("csr", result.reason)}): ${result.reason}`,
99
+ );
100
+ return true;
101
+ }
102
+ sendBuildStatus("csr", { generation, ok: true, files });
103
+ this.#logger.verbose(
104
+ result.kind === "unchanged"
105
+ ? `csr-patch unchanged (${Date.now() - started}ms)`
106
+ : `csr-patch generation=${result.update.generation} ${result.update.reload ? `reload (${result.update.reason})` : `patch modules=${result.update.changedIds.length}`} (${Date.now() - started}ms)`,
107
+ );
108
+ return false;
109
+ } catch (err) {
110
+ const message = ApplicationBuildReporter.formatError(err, this.#app.workspace.workspaceRoot);
111
+ if (isCompileError(err)) {
112
+ sendBuildStatus("csr", { generation, ok: false, files, message });
113
+ return false;
114
+ }
115
+ this.#logger.verbose(`csr-patch threw; a build worker takes this save: ${message}`);
116
+ patcher.forget();
117
+ return true;
118
+ } finally {
119
+ await rm(marker, { force: true });
120
+ }
121
+ }
122
+
123
+ // On demand: dev serves CSR only via the opt-in `/__csr` and `?csr=true` routes; once built, it rebuilds every save.
124
+ async handleBuildCsr(msg: BuilderCsrReq): Promise<void> {
125
+ if (msg.shell) {
126
+ await this.#buildShell(msg);
127
+ return;
128
+ }
129
+ //? Armed now, not when the build lands: a save handled meanwhile then patches CSR behind #csrGate instead of skipping.
130
+ this.#beginCsrArm();
131
+ this.#csrActive = true;
132
+ const armed = this.#lanes.workQueue.enqueue("build-csr", async (): Promise<void> => {
133
+ const started = Date.now();
134
+ let error: string | undefined;
135
+ try {
136
+ // Not relayed: an on-demand CSR build is request/response, and its error travels in the response.
137
+ const result = await this.#batchRunner.run(
138
+ await this.#links.batchRequest({ generation: this.#links.generation(), needs: ["csr"], changedFiles: [] }),
139
+ );
140
+ error = result.errors.csr;
141
+ } catch (err) {
142
+ error = ApplicationBuildReporter.formatError(err, this.#app.workspace.workspaceRoot);
143
+ }
144
+ if (error) {
145
+ this.#logger.error(`csr-build failed: ${error}`);
146
+ await BuilderChannel.send({ type: "build-csr-res", id: msg.id, ok: false, error });
147
+ return;
148
+ }
149
+ this.#csrArmSucceeded = true;
150
+ this.#patcher?.forget();
151
+ this.#logger.info(`csr-build ok on demand (${Date.now() - started}ms); rebuilding CSR on every save now`);
152
+ await BuilderChannel.send({ type: "build-csr-res", id: msg.id, ok: true });
153
+ });
154
+ this.#csrGate = this.#armingCsr(armed);
155
+ await armed;
156
+ }
157
+
158
+ // Asked on every view read and rebuilt only when a save moved the generation or the css it inlines, instead of armed
159
+ // per save: a restarted builder has no last build to trust, and so rebuilds once on the next read.
160
+ async #buildShell(msg: BuilderCsrReq): Promise<void> {
161
+ await this.#lanes.workQueue.enqueue("build-shell", async (): Promise<void> => {
162
+ const generation = this.#links.generation();
163
+ //? A save moves the generation before its css compile lands, so a shell built in between holds the old css.
164
+ const shellKey = `${generation}:${JSON.stringify(this.#links.artifact().cssAssets)}`;
165
+ let error: string | undefined;
166
+ if (this.#shellKey !== shellKey)
167
+ try {
168
+ const result = await this.#batchRunner.run(
169
+ await this.#links.batchRequest({ generation, needs: ["shell"], changedFiles: [] }),
170
+ );
171
+ error = result.errors.shell;
172
+ if (!error) this.#shellKey = shellKey;
173
+ } catch (err) {
174
+ error = ApplicationBuildReporter.formatError(err, this.#app.workspace.workspaceRoot);
175
+ }
176
+ await BuilderChannel.send(
177
+ error
178
+ ? { type: "build-csr-res", id: msg.id, ok: false, error }
179
+ : { type: "build-csr-res", id: msg.id, ok: true },
180
+ );
181
+ });
182
+ }
183
+
184
+ //? Settled by the last of the arming builds in flight, not by each: two requests that both fail would otherwise leave
185
+ //? CSR on (the second saw the first's optimistic flag as where it started), and the first to finish would let saves
186
+ //? patch CSR first while the second still builds.
187
+ #beginCsrArm(): void {
188
+ if (this.#csrArms === 0) {
189
+ this.#csrWasActive = this.#csrActive;
190
+ this.#csrArmSucceeded = false;
191
+ }
192
+ this.#csrArms += 1;
193
+ this.#csrArming = true;
194
+ }
195
+
196
+ #armingCsr(armed: Promise<void>): Promise<void> {
197
+ const settle = () => {
198
+ this.#csrArms -= 1;
199
+ if (this.#csrArms > 0) return;
200
+ this.#csrArming = false;
201
+ this.#csrActive = this.#csrWasActive || this.#csrArmSucceeded;
202
+ };
203
+ return armed.then(settle, settle);
204
+ }
205
+
206
+ static #csrArmedByEnv() {
207
+ return process.env.AKAN_DEV_CSR_REBUILD === "1";
208
+ }
209
+
210
+ // The env flag carries an armed CSR session across builder restarts, so the replacement rebuilds it after ready.
211
+ async rearmCsrFromEnv(): Promise<void> {
212
+ if (!CsrRegistry.#csrArmedByEnv()) return;
213
+ this.#beginCsrArm();
214
+ this.#csrActive = true;
215
+ //? The env keeps CSR armed whatever this build does, as it did before the builder restarted.
216
+ this.#csrArmSucceeded = true;
217
+ const rearmed = this.#lanes.workQueue.enqueue("build-csr-rearm", async () => {
218
+ //? Relayed, unlike an on-demand build: a rebuild for a metadata save must reach the CSR tabs as their reload.
219
+ const result = await this.#batchRunner.run(
220
+ await this.#links.batchRequest({ generation: this.#links.generation(), needs: ["csr"], changedFiles: [] }),
221
+ (msg) => BuilderChannel.emit(msg),
222
+ );
223
+ this.#patcher?.forget();
224
+ if (result.errors.csr) this.#logger.error(`csr-rearm failed: ${result.errors.csr}`);
225
+ else this.#logger.verbose("csr-rearm ok; this session had CSR armed before the builder restarted");
226
+ });
227
+ this.#csrGate = this.#armingCsr(rearmed);
228
+ await rearmed.catch((err: unknown) =>
229
+ this.#logger.error(
230
+ `csr-rearm failed: ${ApplicationBuildReporter.formatError(err, this.#app.workspace.workspaceRoot)}`,
231
+ ),
232
+ );
233
+ }
234
+ }
@@ -43,6 +43,22 @@ const startRecordingHost = () => {
43
43
  };
44
44
 
45
45
  describe("IncrementalBuilderHost", () => {
46
+ test("tells its starter the boot artifact is built, ahead of ready, and relays nothing for it", () => {
47
+ const spawns = mockSpawns();
48
+ const messages: unknown[] = [];
49
+ const onBaseBuilt = mock();
50
+ const host = createHost((message) => messages.push(message));
51
+
52
+ host.start({ onBaseBuilt });
53
+ spawns[0]?.options.ipc?.({ type: "base-built", phaseMs: { pages: 5, total: 9 } });
54
+
55
+ expect(onBaseBuilt).toHaveBeenCalledWith({ pages: 5, total: 9 });
56
+ expect(host.status).toBe("starting");
57
+ expect(messages).toEqual([]);
58
+
59
+ host.stop();
60
+ });
61
+
46
62
  test("restarts after a ready builder exits", async () => {
47
63
  const spawns = mockSpawns();
48
64
 
@@ -5,6 +5,7 @@ import type { BuilderMessage, BuilderRequest } from "akanjs/server";
5
5
  import { CSR_DEV_DIRNAME, CSR_DEV_PATCHING_MARKER, SSR_DEV_DIRNAME } from "akanjs/server/hmr/csrDevManifest";
6
6
  import { MemoryLimit } from "akanjs/server/memoryLimit";
7
7
  import type { App } from "../commandDecorators";
8
+ import type { BaseBuiltMessage } from "./builderChannel";
8
9
 
9
10
  const builderMsgTypeSet = new Set<BuilderMessage["type"]>([
10
11
  "build-route-res",
@@ -41,6 +42,7 @@ export type IncrementalBuilderStatus = "starting" | "ready" | "recycling" | "res
41
42
  interface IncrementalBuilderStartOptions {
42
43
  onExit?: () => void;
43
44
  onReady?: () => void;
45
+ onBaseBuilt?: (phaseMs: Record<string, number>) => void;
44
46
  onRestartReady?: () => void;
45
47
  /** The builder is gone and a replacement is coming (unwatched until then); `onExit` means it gave up. */
46
48
  onAway?: () => void;
@@ -124,9 +126,13 @@ export class IncrementalBuilderHost {
124
126
  ...(this.#patcherOff ? { AKAN_DEV_CSR_PATCHER: "off" } : {}),
125
127
  },
126
128
  stdio: ["ignore", this.#stdio, this.#stdio],
127
- ipc: (msg: BuilderMessage) => {
129
+ ipc: (msg: BuilderMessage | BaseBuiltMessage) => {
128
130
  if (this.#proc !== proc) return;
129
131
  if (!msg || typeof msg !== "object") return;
132
+ if (msg.type === "base-built") {
133
+ this.#startOptions.onBaseBuilt?.(msg.phaseMs);
134
+ return;
135
+ }
130
136
  if (msg.type === "build-route-res" || msg.type === "build-csr-res" || msg.type === "build-graph-res")
131
137
  this.#inFlight.delete(msg.id);
132
138
  if (builderMsgTypeSet.has(msg.type)) this.#onMessage(msg);