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

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 +367 -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 +14 -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
@@ -1,7 +1,7 @@
1
1
  import { describe, expect, test } from "bun:test";
2
2
  import path from "node:path";
3
+ import { tempDirs, writeText as write } from "../test/testHelpers";
3
4
  import { RouteJsBudget, type RouteJsSize } from "./routeJsBudget";
4
- import { tempDirs, writeText as write } from "./testHelpers";
5
5
 
6
6
  const makeTempRoot = tempDirs("akan-route-js-");
7
7
  const size = (routeId: string, brotliKB: number): RouteJsSize => ({
@@ -96,30 +96,50 @@ describe("RouteJsBudget", () => {
96
96
  const setup = async (text?: string) => {
97
97
  const budgetPath = path.join(await makeTempRoot(), "akan.budget.json");
98
98
  if (text !== undefined) await write(budgetPath, text);
99
- return { budgetPath, source: "apps/shop/akan.budget.json", environment: "local" };
99
+ return { app: "shop", budgetPath, source: "apps/shop/akan.budget.json", environment: "local" };
100
100
  };
101
101
 
102
- test("enforce fails a route over its limit and a file it cannot read", async () => {
102
+ test("enforce fails a route over its limit, a route with no entry, a file it cannot read, and an app with no file", async () => {
103
103
  const over = await setup(JSON.stringify({ env: "main", routeJsBrotliKB: { "/:lang/memo": 120 } }));
104
104
  await expect(RouteJsBudget.check(sizes, { ...over, mode: "enforce" })).rejects.toThrow(
105
105
  "1 route over the JS budget in apps/shop/akan.budget.json (recorded for main, built for local):",
106
106
  );
107
+ await expect(RouteJsBudget.check(sizes, { ...over, mode: "enforce" })).rejects.toThrow(
108
+ "in apps/shop/akan.budget.json by hand.\n1 route with no entry in apps/shop/akan.budget.json",
109
+ );
110
+ const missing = await setup(JSON.stringify({ routeJsBrotliKB: { "/:lang/memo": 130 } }));
111
+ await expect(RouteJsBudget.check(sizes, { ...missing, mode: "enforce" })).rejects.toThrow(
112
+ [
113
+ "1 route with no entry in apps/shop/akan.budget.json, which --check-budget checks every route against:",
114
+ " /:lang/new",
115
+ "Record it in the same change: `akan build shop --update-budget` adds each new route at its measured size.",
116
+ ].join("\n"),
117
+ );
107
118
  const broken = await setup("{");
108
119
  await expect(RouteJsBudget.check(sizes, { ...broken, mode: "enforce" })).rejects.toThrow("is not valid JSON");
120
+ await expect(RouteJsBudget.check(sizes, { ...(await setup()), mode: "enforce" })).rejects.toThrow(
121
+ "--check-budget found no apps/shop/akan.budget.json: record one with `akan build shop --update-budget`.",
122
+ );
109
123
  });
110
124
 
111
- test("report warns of an overage and a file it cannot read, and fails neither", async () => {
125
+ test("report warns of an overage, a route with no entry and a file it cannot read, and fails none", async () => {
126
+ const unbudgetedWarning = {
127
+ file: "apps/shop/akan.budget.json",
128
+ message: "/:lang/new has no entry; akan build --check-budget fails on it",
129
+ fix: "record it with akan build shop --update-budget",
130
+ };
112
131
  const over = await setup(JSON.stringify({ env: "main", routeJsBrotliKB: { "/:lang/memo": 120 } }));
113
132
  expect(await RouteJsBudget.check(sizes, { ...over, mode: "report" })).toEqual({
114
133
  summary:
115
- "1 route(s) over apps/shop/akan.budget.json (recorded for main, built for local), reported only: /:lang/memo",
134
+ "1 route(s) over apps/shop/akan.budget.json (recorded for main, built for local), reported only: /:lang/memo; 1 route(s) without an entry",
116
135
  warnings: [
117
136
  {
118
137
  file: "apps/shop/akan.budget.json",
119
138
  message:
120
- "/:lang/memo loads 133,120 bytes brotli, over its limit of 126,976 (recorded for main, built for local); akan build fails on it",
121
- fix: "shrink what the route loads, or raise its entry by hand in the same change",
139
+ "/:lang/memo loads 133,120 bytes brotli, over its limit of 126,976 (recorded for main, built for local); akan build --check-budget fails on it",
140
+ fix: "shrink what the route loads, or raise its entry with akan build shop --raise-budget",
122
141
  },
142
+ unbudgetedWarning,
123
143
  ],
124
144
  });
125
145
  const broken = await setup("{");
@@ -128,8 +148,8 @@ describe("RouteJsBudget", () => {
128
148
  warnings: [
129
149
  {
130
150
  file: "apps/shop/akan.budget.json",
131
- message: "apps/shop/akan.budget.json is not valid JSON; akan build fails on it",
132
- fix: "correct it, or rewrite it with akan build <app> --update-budget",
151
+ message: "apps/shop/akan.budget.json is not valid JSON; akan build --check-budget fails on it",
152
+ fix: "correct it, or rewrite it with akan build shop --update-budget",
133
153
  },
134
154
  ],
135
155
  });
@@ -138,7 +158,8 @@ describe("RouteJsBudget", () => {
138
158
  });
139
159
  const within = await setup(JSON.stringify({ routeJsBrotliKB: { "/:lang/memo": 130 } }));
140
160
  expect(await RouteJsBudget.check(sizes, { ...within, mode: "report" })).toEqual({
141
- summary: "within apps/shop/akan.budget.json, 1 route(s) without an entry",
161
+ summary: "within apps/shop/akan.budget.json; 1 route(s) without an entry",
162
+ warnings: [unbudgetedWarning],
142
163
  });
143
164
  });
144
165
 
@@ -157,20 +178,35 @@ describe("RouteJsBudget", () => {
157
178
  await expect(RouteJsBudget.check(sizes, { ...over, mode: "update" })).rejects.toThrow("/:lang/memo");
158
179
  expect(RouteJsBudget.parse(await Bun.file(over.budgetPath).text()).kbByRoute.get("/:lang/memo")).toBe(120);
159
180
  });
181
+
182
+ test("raise re-records every route at its measured size and names the entries it raised", async () => {
183
+ const over = await setup(
184
+ JSON.stringify({ env: "main", routeJsBrotliKB: { "/:lang/memo": 120, "/:lang/new": 90 } }),
185
+ );
186
+ expect(await RouteJsBudget.check(sizes, { ...over, mode: "raise" })).toEqual({
187
+ summary: "apps/shop/akan.budget.json re-recorded at each route's measured size, raised: /:lang/memo",
188
+ });
189
+ const written = RouteJsBudget.parse(await Bun.file(over.budgetPath).text());
190
+ expect(written.env).toBe("local");
191
+ expect(Object.fromEntries(written.kbByRoute)).toEqual({ "/:lang/memo": 130, "/:lang/new": 70 });
192
+ expect(await RouteJsBudget.check(sizes, { ...over, mode: "enforce" })).toEqual({
193
+ summary: "within apps/shop/akan.budget.json",
194
+ });
195
+ });
160
196
  });
161
197
 
162
198
  test("names each route over budget, its limit, and how to resolve it", () => {
163
199
  expect(
164
200
  RouteJsBudget.formatOverages(
165
201
  [{ routeId: "/:lang/memo", brotliBytes: 128_000, budgetKB: 120, limitBytes: 126_976 }],
166
- "apps/shop/akan.budget.json",
202
+ { app: "shop", source: "apps/shop/akan.budget.json" },
167
203
  " (recorded for main, built for local)",
168
204
  ),
169
205
  ).toBe(
170
206
  [
171
207
  "1 route over the JS budget in apps/shop/akan.budget.json (recorded for main, built for local):",
172
208
  " /:lang/memo: 128,000 bytes brotli, over its limit of 126,976 (120KB + the larger of 1% and 4KB)",
173
- "Shrink what the route loads. If the growth is intended, raise its entry by hand in the same change.",
209
+ 'Shrink what the route loads. If the growth is intended, record it in the same change: `akan build shop --raise-budget` re-records every route at its measured size, or raise the route\'s entry under "routeJsBrotliKB" in apps/shop/akan.budget.json by hand.',
174
210
  ].join("\n"),
175
211
  );
176
212
  });
@@ -1,7 +1,7 @@
1
1
  import path from "node:path";
2
2
  import { toError } from "akanjs/common";
3
- import { FontPruner } from "./frontendBuild/fontPruner";
4
- import { JsonFormatter } from "./jsonFormatter";
3
+ import { FontPruner } from "../frontendBuild/fontPruner";
4
+ import { JsonFormatter } from "../util/jsonFormatter";
5
5
 
6
6
  export interface RouteJsSize {
7
7
  routeId: string;
@@ -17,7 +17,7 @@ export interface RouteJsOverage {
17
17
  limitBytes: number;
18
18
  }
19
19
 
20
- export type RouteJsBudgetMode = "enforce" | "update" | "report" | "off";
20
+ export type RouteJsBudgetMode = "enforce" | "update" | "raise" | "report" | "off";
21
21
 
22
22
  export interface RouteJsBudgetWarning {
23
23
  file: string;
@@ -30,8 +30,20 @@ export interface RouteJsBudgetStatus {
30
30
  warnings?: RouteJsBudgetWarning[];
31
31
  }
32
32
 
33
+ export interface RouteJsBudgetFlags {
34
+ checkBudget?: boolean;
35
+ updateBudget?: boolean;
36
+ raiseBudget?: boolean;
37
+ }
38
+
39
+ interface BudgetTarget {
40
+ app: string;
41
+ source: string;
42
+ }
43
+
33
44
  export interface RouteJsBudgetCheck {
34
45
  mode: Exclude<RouteJsBudgetMode, "off">;
46
+ app: string;
35
47
  budgetPath: string;
36
48
  source: string;
37
49
  environment: string;
@@ -65,47 +77,85 @@ export class RouteJsBudget {
65
77
  .sort((a, b) => b.brotliBytes - a.brotliBytes || RouteJsBudget.#byCodeUnit(a.routeId, b.routeId));
66
78
  }
67
79
 
80
+ static modeOf({ checkBudget = false, updateBudget = false, raiseBudget = false }: RouteJsBudgetFlags) {
81
+ if ([checkBudget, updateBudget, raiseBudget].filter(Boolean).length > 1)
82
+ throw new Error("Pass at most one of --check-budget, --update-budget and --raise-budget.");
83
+ return checkBudget ? "enforce" : updateBudget ? "update" : raiseBudget ? "raise" : "report";
84
+ }
85
+
68
86
  static async load(filePath: string, source = filePath): Promise<RouteJsBudget | null> {
69
87
  const file = Bun.file(filePath);
70
88
  if (!(await file.exists())) return null;
71
89
  return RouteJsBudget.parse(await file.text(), source);
72
90
  }
73
91
 
74
- //? `report` runs inside `akan verify`, where an overage or a broken file is no code error to fix in the edit loop.
75
- static async check(
76
- sizes: RouteJsSize[],
77
- { mode, budgetPath, source, environment }: RouteJsBudgetCheck,
78
- ): Promise<RouteJsBudgetStatus> {
92
+ //? A deploy build and `akan verify`'s edit loop only report: `enforce` (`--check-budget`, run by CI) is the gate.
93
+ static async check(sizes: RouteJsSize[], check: RouteJsBudgetCheck): Promise<RouteJsBudgetStatus> {
94
+ const { mode, app, budgetPath, source, environment } = check;
79
95
  const { committed, unreadable } = await RouteJsBudget.#loadFor(mode, budgetPath, source);
80
- const budget = mode === "update" ? (committed ?? new RouteJsBudget()).tightenedBy(sizes, environment) : committed;
81
- if (mode === "update" && budget) await Bun.write(budgetPath, budget.stringify());
96
+ if (mode === "enforce" && !committed)
97
+ throw new Error(`--check-budget found no ${source}: record one with \`akan build ${app} --update-budget\`.`);
98
+ const budget =
99
+ mode === "raise"
100
+ ? new RouteJsBudget().tightenedBy(sizes, environment)
101
+ : mode === "update"
102
+ ? (committed ?? new RouteJsBudget()).tightenedBy(sizes, environment)
103
+ : committed;
104
+ if ((mode === "update" || mode === "raise") && budget) await Bun.write(budgetPath, budget.stringify());
82
105
  const overages = budget?.overages(sizes) ?? [];
106
+ const unbudgeted = budget?.unbudgeted(sizes) ?? [];
83
107
  const envNote = committed?.envNote(environment) ?? "";
84
- if (overages.length && mode !== "report") throw new Error(RouteJsBudget.formatOverages(overages, source, envNote));
85
- const unbudgeted = budget?.unbudgeted(sizes).length ?? 0;
86
- if (mode === "update") return { summary: `${source} ${unreadable ? `rewritten (${unreadable})` : "updated"}` };
108
+ const target = { app, source };
109
+ const failures = [
110
+ ...(overages.length && mode !== "report" ? [RouteJsBudget.formatOverages(overages, target, envNote)] : []),
111
+ ...(unbudgeted.length && mode === "enforce" ? [RouteJsBudget.formatUnbudgeted(unbudgeted, target)] : []),
112
+ ];
113
+ if (failures.length) throw new Error(failures.join("\n"));
114
+ if (mode === "update" || mode === "raise")
115
+ return { summary: RouteJsBudget.#writtenSummary(check, unreadable, committed, budget) };
87
116
  if (unreadable)
88
117
  return {
89
118
  summary: `${unreadable}, not checked`,
90
119
  warnings: [
91
120
  {
92
121
  file: source,
93
- message: `${unreadable}; akan build fails on it`,
94
- fix: "correct it, or rewrite it with akan build <app> --update-budget",
122
+ message: `${unreadable}; akan build --check-budget fails on it`,
123
+ fix: `correct it, or rewrite it with akan build ${app} --update-budget`,
95
124
  },
96
125
  ],
97
126
  };
98
127
  if (!budget) return { summary: `no ${RouteJsBudget.fileName}` };
99
- if (overages.length)
100
- return {
101
- summary: `${overages.length} route(s) over ${source}${envNote}, reported only: ${overages.map(({ routeId }) => routeId).join(", ")}`,
102
- warnings: overages.map(({ routeId, brotliBytes, limitBytes }) => ({
103
- file: source,
104
- message: `${routeId} loads ${RouteJsBudget.#bytes(brotliBytes)} bytes brotli, over its limit of ${RouteJsBudget.#bytes(limitBytes)}${envNote}; akan build fails on it`,
105
- fix: "shrink what the route loads, or raise its entry by hand in the same change",
106
- })),
107
- };
108
- return { summary: `within ${source}${envNote}${unbudgeted ? `, ${unbudgeted} route(s) without an entry` : ""}` };
128
+ const warnings = [
129
+ ...overages.map(({ routeId, brotliBytes, limitBytes }) => ({
130
+ file: source,
131
+ message: `${routeId} loads ${RouteJsBudget.#bytes(brotliBytes)} bytes brotli, over its limit of ${RouteJsBudget.#bytes(limitBytes)}${envNote}; akan build --check-budget fails on it`,
132
+ fix: `shrink what the route loads, or raise its entry with akan build ${app} --raise-budget`,
133
+ })),
134
+ ...unbudgeted.map((routeId) => ({
135
+ file: source,
136
+ message: `${routeId} has no entry; akan build --check-budget fails on it`,
137
+ fix: `record it with akan build ${app} --update-budget`,
138
+ })),
139
+ ];
140
+ const verdict = overages.length
141
+ ? `${overages.length} route(s) over ${source}${envNote}, reported only: ${overages.map(({ routeId }) => routeId).join(", ")}`
142
+ : `within ${source}${envNote}`;
143
+ const unbudgetedNote = unbudgeted.length ? `; ${unbudgeted.length} route(s) without an entry` : "";
144
+ return { summary: `${verdict}${unbudgetedNote}`, ...(warnings.length ? { warnings } : {}) };
145
+ }
146
+
147
+ static #writtenSummary(
148
+ { mode, source }: RouteJsBudgetCheck,
149
+ unreadable: string | null,
150
+ committed: RouteJsBudget | null,
151
+ written: RouteJsBudget | null,
152
+ ) {
153
+ if (unreadable) return `${source} rewritten (${unreadable})`;
154
+ if (mode === "update") return `${source} updated`;
155
+ const raised = [...(written?.kbByRoute ?? [])].filter(
156
+ ([routeId, kb]) => kb > (committed?.kbByRoute.get(routeId) ?? kb),
157
+ );
158
+ return `${source} re-recorded at each route's measured size${raised.length ? `, raised: ${raised.map(([routeId]) => routeId).join(", ")}` : ""}`;
109
159
  }
110
160
 
111
161
  static async #loadFor(mode: RouteJsBudgetCheck["mode"], budgetPath: string, source: string) {
@@ -158,18 +208,31 @@ export class RouteJsBudget {
158
208
  ];
159
209
  }
160
210
 
161
- static formatOverages(overages: RouteJsOverage[], source: string, envNote = ""): string {
211
+ static formatOverages(overages: RouteJsOverage[], target: BudgetTarget, envNote = ""): string {
162
212
  const bytes = RouteJsBudget.#bytes;
213
+ const { source } = target;
163
214
  return [
164
215
  `${overages.length} route${overages.length === 1 ? "" : "s"} over the JS budget in ${source}${envNote}:`,
165
216
  ...overages.map(
166
217
  ({ routeId, brotliBytes, budgetKB, limitBytes }) =>
167
218
  ` ${routeId}: ${bytes(brotliBytes)} bytes brotli, over its limit of ${bytes(limitBytes)} (${budgetKB}KB + the larger of 1% and 4KB)`,
168
219
  ),
169
- "Shrink what the route loads. If the growth is intended, raise its entry by hand in the same change.",
220
+ RouteJsBudget.#overageFix(target),
221
+ ].join("\n");
222
+ }
223
+
224
+ static formatUnbudgeted(routeIds: string[], { app, source }: BudgetTarget): string {
225
+ return [
226
+ `${routeIds.length} route${routeIds.length === 1 ? "" : "s"} with no entry in ${source}, which --check-budget checks every route against:`,
227
+ ...routeIds.map((routeId) => ` ${routeId}`),
228
+ `Record ${routeIds.length === 1 ? "it" : "them"} in the same change: \`akan build ${app} --update-budget\` adds each new route at its measured size.`,
170
229
  ].join("\n");
171
230
  }
172
231
 
232
+ static #overageFix({ app, source }: BudgetTarget) {
233
+ return `Shrink what the route loads. If the growth is intended, record it in the same change: \`akan build ${app} --raise-budget\` re-records every route at its measured size, or raise the route's entry under "${RouteJsBudget.section}" in ${source} by hand.`;
234
+ }
235
+
173
236
  static #bytes(value: number) {
174
237
  return value.toLocaleString("en-US");
175
238
  }
@@ -20,6 +20,23 @@ describe("RouteSourceValidator", () => {
20
20
  expect(() => validate(source, "layout", true)).not.toThrow();
21
21
  });
22
22
 
23
+ test("refuses an export only the generated root layout defines on an app's root layout, which it would ignore", () => {
24
+ const layout = "export default function Layout({ children }) { return children; }";
25
+ for (const source of [
26
+ `${layout}\nexport const LevelBoundary = ({ children }) => children;`,
27
+ `${layout}\nexport { Boundary as LevelBoundary } from "./boundary";`,
28
+ `${layout}\nexport function McpAppRoot({ children }) { return children; }`,
29
+ ]) {
30
+ const name = source.includes("McpAppRoot") ? "McpAppRoot" : "LevelBoundary";
31
+ expect(() => validate(source, "layout", true)).toThrow(
32
+ `unsupported export "${name}" in page/_layout.tsx: ${name} belongs to the root layout Akan.js generates, which never reads one from an app's layout`,
33
+ );
34
+ expect(() => validate(source, "layout")).toThrow(
35
+ new RegExp(`unsupported export "${name}" in page/_layout\\.tsx$`),
36
+ );
37
+ }
38
+ });
39
+
23
40
  test("rejects root-layout-only exports on a nested layout and on a page", () => {
24
41
  const source = ["export default function Layout() { return null; }", "export const wsConnect = true;"].join("\n");
25
42
 
@@ -1,4 +1,4 @@
1
- import { getRouteExports } from "akanjs/common";
1
+ import { GENERATED_ROOT_LAYOUT_EXPORTS, getRouteExports } from "akanjs/common";
2
2
  import ts from "typescript";
3
3
 
4
4
  /** What the build needs out of a route module without evaluating it. */
@@ -43,6 +43,10 @@ export class RouteSourceValidator {
43
43
  const allowed = getRouteExports(kind, { rootLayout: options.rootLayout });
44
44
  const exported = new Set<string>();
45
45
  const assertExport = (name: string) => {
46
+ if (options.rootLayout && GENERATED_ROOT_LAYOUT_EXPORTS.has(name))
47
+ throw new Error(
48
+ `[route-convention] unsupported export "${name}" in ${filePath}: ${name} belongs to the root layout Akan.js generates, which never reads one from an app's layout`,
49
+ );
46
50
  if (!allowed.has(name)) {
47
51
  throw new Error(`[route-convention] unsupported export "${name}" in ${filePath}`);
48
52
  }
@@ -1,6 +1,6 @@
1
1
  import { describe, expect, test } from "bun:test";
2
2
  import path from "node:path";
3
- import { tempDirs, writeText as write } from "../testHelpers";
3
+ import { tempDirs, writeText as write } from "../test/testHelpers";
4
4
  import { resolveSsrPageEntries } from "./implicitRootLayout";
5
5
 
6
6
  const makeTempRoot = tempDirs("akan-implicit-root-layout-");
@@ -53,11 +53,74 @@ describe("resolveSsrPageEntries", () => {
53
53
  // Its guard runs from that level too, ahead of this one, and an MCP view takes its providers from there.
54
54
  expect(generatedSource).toContain("export const guard = userLayout.guard;");
55
55
  expect(generatedSource).not.toContain("McpAppRoot");
56
+ expect(generatedSource).not.toContain("LevelBoundary");
56
57
  expect(generatedSource).toContain(
57
58
  "<UserLayout params={params} searchParams={searchParams}>{children}</UserLayout>",
58
59
  );
59
60
  });
60
61
 
62
+ test("bounds the System root layout's own content inside System.Provider, for a server render only", async () => {
63
+ const appRoot = await makeTempRoot();
64
+ await write(path.join(appRoot, "env", "env.client.ts"), "export const env = {};\n");
65
+ await write(
66
+ path.join(appRoot, "page", "_layout.tsx"),
67
+ "export default function Layout({ children }) { return children; }\n",
68
+ );
69
+ await write(
70
+ path.join(appRoot, "page", "(home)", "_layout.tsx"),
71
+ "export default function Layout({ children }) { return children; }\n",
72
+ );
73
+
74
+ const entries = await resolveSsrPageEntries({
75
+ appCwdPath: appRoot,
76
+ appName: "demo",
77
+ pageKeys: ["./_layout.tsx", "./(home)/_layout.tsx", "./(home)/_index.tsx"],
78
+ });
79
+
80
+ const source = await Bun.file(
81
+ entries.find((entry) => entry.key === "./__root_layout.tsx")?.moduleAbsPath ?? "",
82
+ ).text();
83
+ expect(source).toContain('import { RouteLevelBoundary } from "akanjs/webkit/RouteLevelBoundary.tsx";');
84
+ expect(source).toContain(
85
+ " const layout = <UserLayout params={params} searchParams={searchParams}>{children}</UserLayout>;\n return (\n <System.Provider",
86
+ );
87
+ expect(source).toContain(
88
+ ' >\n {process.env.AKAN_PUBLIC_RENDER_ENV === "csr" ? layout : <RouteLevelBoundary>{layout}</RouteLevelBoundary>}\n </System.Provider>',
89
+ );
90
+ expect(source.match(/<RouteLevelBoundary>/g)).toHaveLength(1);
91
+ expect(source.slice(source.indexOf("export function McpAppRoot"))).not.toContain("RouteLevelBoundary");
92
+
93
+ const nested = await Bun.file(
94
+ entries.find((entry) => entry.key === "./(home)/__root_layout.tsx")?.moduleAbsPath ?? "",
95
+ ).text();
96
+ expect(nested).not.toContain("RouteLevelBoundary");
97
+ });
98
+
99
+ test("leaves the boundary out of a CSR build, which an MCP App view's namespace import of the layout shares", async () => {
100
+ const appRoot = await makeTempRoot();
101
+ await write(path.join(appRoot, "env", "env.client.ts"), "export const env = {};\n");
102
+ await write(path.join(appRoot, "page", "_layout.tsx"), "export default ({ children }) => children;\n");
103
+ const entries = await resolveSsrPageEntries({
104
+ appCwdPath: appRoot,
105
+ appName: "demo",
106
+ pageKeys: ["./_layout.tsx", "./_index.tsx"],
107
+ });
108
+ const source = await Bun.file(
109
+ entries.find((entry) => entry.key === "./__root_layout.tsx")?.moduleAbsPath ?? "",
110
+ ).text();
111
+ const compiled = (renderEnv: "csr" | "ssr") =>
112
+ new Bun.Transpiler({
113
+ loader: "tsx",
114
+ define: { "process.env.AKAN_PUBLIC_RENDER_ENV": JSON.stringify(renderEnv) },
115
+ trimUnusedImports: true,
116
+ }).transformSync(source);
117
+
118
+ expect(compiled("csr")).toContain("export const LevelBoundary = undefined;");
119
+ expect(compiled("csr")).not.toMatch(/\bRouteLevelBoundary\b(?!\.tsx)/);
120
+ expect(compiled("ssr")).toContain("export const LevelBoundary = RouteLevelBoundary;");
121
+ expect(compiled("ssr")).toMatch(/import \{ ?RouteLevelBoundary ?\} from "akanjs\/webkit\/RouteLevelBoundary\.tsx"/);
122
+ });
123
+
61
124
  test("keeps system provider for grouped root boundaries without an ancestor root", async () => {
62
125
  const appRoot = await makeTempRoot();
63
126
  const pageRoot = path.join(appRoot, "page");
@@ -87,6 +150,9 @@ describe("resolveSsrPageEntries", () => {
87
150
  );
88
151
  expect(generatedSource).toContain("export function McpAppRoot({ children, params, path }: McpAppRootProps) {");
89
152
  expect(generatedSource).toContain("<System.App");
153
+ expect(generatedSource).toContain(
154
+ 'export const LevelBoundary = process.env.AKAN_PUBLIC_RENDER_ENV === "csr" ? undefined : RouteLevelBoundary;',
155
+ );
90
156
  expect(generatedSource).toContain('import { allDictionary } from "../dict/useDict.ts";');
91
157
  expect(generatedSource).toContain(
92
158
  'allDictionary={process.env.AKAN_PUBLIC_RENDER_ENV === "ssr" ? allDictionary : undefined}',
@@ -170,7 +236,9 @@ describe("resolveSsrPageEntries", () => {
170
236
  expect(userSource).toContain('process.env.AKAN_PUBLIC_RENDER_ENV === "csr"');
171
237
  expect(userSource).toContain("? await UserLayout({ params, searchParams, children })");
172
238
  expect(userSource).toContain(": <UserLayout params={params} searchParams={searchParams}>{children}</UserLayout>;");
173
- expect(userSource).toContain(" {layout}\n </System.Provider>");
239
+ expect(userSource).toContain(
240
+ ' {process.env.AKAN_PUBLIC_RENDER_ENV === "csr" ? layout : <RouteLevelBoundary>{layout}</RouteLevelBoundary>}\n </System.Provider>',
241
+ );
174
242
 
175
243
  const signRoot = entries.find((entry) => entry.key === "./(sign)/__root_layout.tsx");
176
244
  const signSource = await Bun.file(signRoot?.moduleAbsPath ?? "").text();
@@ -178,7 +246,7 @@ describe("resolveSsrPageEntries", () => {
178
246
  expect(signSource).toContain("export default function GeneratedLayout(");
179
247
  expect(signSource).not.toContain("await UserLayout(");
180
248
  expect(signSource).toContain(
181
- " <UserLayout params={params} searchParams={searchParams}>{children}</UserLayout>\n </System.Provider>",
249
+ " const layout = <UserLayout params={params} searchParams={searchParams}>{children}</UserLayout>;\n",
182
250
  );
183
251
  });
184
252
 
@@ -71,10 +71,21 @@ export function getRootBoundarySegments(key: string): string[] | null {
71
71
  return prefix.split("/").filter(Boolean);
72
72
  }
73
73
 
74
+ //? The generated root layout serves SSR, CSR and MCP App views alike; an SSR page renders only System's SSR shell.
75
+ export const ROOT_LAYOUT_SYSTEM = {
76
+ specifier: "akanjs/ui/System/index.tsx",
77
+ ssrShell: "akanjs/ui/System/SSR.tsx",
78
+ importsNoSsrPageRenders: ["./CSR", "./App"],
79
+ } as const;
80
+
74
81
  function implicitRootLayoutKey(segments: string[]): string {
75
82
  return `./${[...segments, "__root_layout"].join("/")}.tsx`;
76
83
  }
77
84
 
85
+ export function isImplicitRootLayoutKey(key: string): boolean {
86
+ return key.endsWith("/__root_layout.tsx");
87
+ }
88
+
78
89
  function implicitRootLayoutAbsPath(appCwdPath: string, segments: string[]): string {
79
90
  const filename = segments.length ? `${segments.join("__")}__root_layout.tsx` : "__root_layout.tsx";
80
91
  return path.join(path.resolve(appCwdPath), IMPLICIT_LAYOUT_DIR, filename);
@@ -188,8 +199,9 @@ async function writeGeneratedRootLayoutFile(opts: {
188
199
  ? await UserLayout({ params, searchParams, children })
189
200
  : ${userLayoutElement};
190
201
  `
191
- : "";
192
- const layoutChild = isAsyncUserLayout ? "{layout}" : userLayoutElement;
202
+ : opts.includeSystemProvider
203
+ ? ` const layout = ${userLayoutElement};\n`
204
+ : "";
193
205
  const layoutReturn = isAsyncUserLayout ? "layout" : userLayoutElement;
194
206
  //? Under an ancestor root boundary the route tree merges that root's head itself; merging it here would repeat it.
195
207
  const headLayouts = opts.includeSystemProvider ? "[inheritedLayout, userLayout]" : "[userLayout]";
@@ -214,12 +226,16 @@ ${layoutSignature}({ children, params, searchParams }: LayoutProps) {
214
226
  ${layoutBinding} return `;
215
227
  //? System from its file, not the barrel: a dev registry compiles every module the barrel names, and with them the
216
228
  //? optional peers (react-icons) an app drawing none of those components never installs.
229
+ //? The root level's boundary sits inside System.Provider, beside the bridge that starts the router its retry calls.
230
+ //? A CSR render has none: RenderLayer draws a failed level there, and a route control also carries a digest.
231
+ //? Its export is undefined there too, so the `import * as root` of an MCP App view, built as CSR, drops it.
217
232
  const source = opts.includeSystemProvider
218
233
  ? `import type { LayoutModule, LayoutProps, PageProps } from "akanjs/client";
219
234
  import { assertGuardOnChain, loadFonts, RouteGuards, resolveRouteModule, RouteHead } from "akanjs/client";
220
235
  import type { ReactNode } from "react";
221
- import { System } from "akanjs/ui/System/index.tsx";
236
+ import { System } from "${ROOT_LAYOUT_SYSTEM.specifier}";
222
237
  import type { McpAppRootProps } from "akanjs/webkit";
238
+ import { RouteLevelBoundary } from "akanjs/webkit/RouteLevelBoundary.tsx";
223
239
  import { env } from "@apps/${opts.appName}/env/env.client";
224
240
  import { allDictionary } from ${JSON.stringify(dictMacroSpecifier)};
225
241
  ${storeImport}${inheritedImport}${userImport}
@@ -231,6 +247,7 @@ const defaultFontClassName = defaultFont ? (defaultFont.className ?? \`font-\${d
231
247
  export const theme = userLayout.theme ?? inheritedLayout.theme;
232
248
  export const viewport = userLayout.viewport ?? inheritedLayout.viewport;
233
249
  export const manifest = userLayout.manifest ?? inheritedLayout.manifest;
250
+ export const LevelBoundary = process.env.AKAN_PUBLIC_RENDER_ENV === "csr" ? undefined : RouteLevelBoundary;
234
251
 
235
252
  ${layoutExports}(
236
253
  <System.Provider
@@ -248,7 +265,7 @@ ${layoutExports}(
248
265
  wsConnect={userLayout.wsConnect ?? inheritedLayout.wsConnect}
249
266
  allDictionary={process.env.AKAN_PUBLIC_RENDER_ENV === "ssr" ? allDictionary : undefined}
250
267
  >
251
- ${layoutChild}
268
+ {process.env.AKAN_PUBLIC_RENDER_ENV === "csr" ? layout : <RouteLevelBoundary>{layout}</RouteLevelBoundary>}
252
269
  </System.Provider>
253
270
  );
254
271
  }