@akanjs/devkit 3.2.0-rc.9 → 3.3.0-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 (341) hide show
  1. package/CHANGELOG.md +57 -516
  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 +132 -3
  7. package/akanApp/akanApp.host.ts +146 -1216
  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/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/processRss.ts +61 -0
  22. package/akanConfig/akanConfig.test.ts +45 -17
  23. package/akanConfig/akanConfig.ts +10 -10
  24. package/akanConfig/akanWorkspaceConfig.ts +1 -1
  25. package/akanConfig/productionLockfile.ts +1 -1
  26. package/apiReport/apiReport.test.ts +34 -3
  27. package/apiReport/apiReportDiff.ts +35 -1
  28. package/apiReport/apiReportPolicy.ts +3 -2
  29. package/{applicationBuildReporter.ts → app/applicationBuildReporter.ts} +2 -49
  30. package/{applicationBuildRunner.test.ts → app/applicationBuildRunner.test.ts} +71 -8
  31. package/{applicationBuildRunner.ts → app/applicationBuildRunner.ts} +60 -21
  32. package/{applicationTestPreload.ts → app/applicationTestPreload.ts} +1 -1
  33. package/{routeJsBudget.test.ts → app/routeJsBudget.test.ts} +17 -1
  34. package/{routeJsBudget.ts → app/routeJsBudget.ts} +9 -3
  35. package/{routeSourceValidator.test.ts → app/routeSourceValidator.test.ts} +17 -0
  36. package/{routeSourceValidator.ts → app/routeSourceValidator.ts} +5 -1
  37. package/artifact/implicitRootLayout.test.ts +71 -3
  38. package/artifact/implicitRootLayout.ts +9 -3
  39. package/artifact/implicitRootLayoutRender.test.tsx +297 -0
  40. package/biome.base.json +2 -1
  41. package/cloud/cloudApi.test.ts +1 -1
  42. package/cloud/configLock.test.ts +1 -1
  43. package/cloud/globalConfig.test.ts +1 -1
  44. package/cloud/globalConfig.ts +1 -1
  45. package/cloud/updatePackUpload.test.ts +1 -1
  46. package/codeAgent/agent/AkanCodeEnv.ts +1 -1
  47. package/codeAgent/agent/AkanCodeServices.ts +23 -0
  48. package/codeAgent/agent/akanCodePaths.ts +1 -1
  49. package/codeAgent/agent/akanCodeServices.test.ts +54 -0
  50. package/codeAgent/agent/akanSystemPrompt.ts +1 -1
  51. package/codeAgent/agent/codeAgent.test.ts +1 -1
  52. package/codeAgent/skills/akan-debug/SKILL.md +8 -5
  53. package/codeAgent/skills/akan-err/SKILL.md +7 -0
  54. package/codeAgent/skills/akan-mcp/SKILL.md +19 -1
  55. package/codeAgent/skills/akan-scaffold/SKILL.md +1 -1
  56. package/codeAgent/skills/akan-validate/SKILL.md +3 -3
  57. package/codeAgent/tools/AkanCli.ts +1 -1
  58. package/codeAgent/tools/AkanToolPack.ts +2 -2
  59. package/codeAgent/tools/akanCodePlugins.test.ts +1 -1
  60. package/commandDecorators/command.ts +35 -6
  61. package/commandDecorators/commandBuilder.ts +1 -1
  62. package/commandDecorators/commandDecorators.test.ts +107 -6
  63. package/commandDecorators/targetMeta.ts +2 -0
  64. package/commandDecorators/workspaceVersionCheck.test.ts +70 -1
  65. package/commandDecorators/workspaceVersionCheck.ts +64 -14
  66. package/context/akanContext.ts +576 -0
  67. package/context/akanContextInspection.ts +296 -0
  68. package/{akanMcpContract.test.ts → context/akanMcpContract.test.ts} +1 -1
  69. package/{akanMcpContract.ts → context/akanMcpContract.ts} +16 -256
  70. package/context/doctor/agentGuideCheck.ts +81 -0
  71. package/context/doctor/configLeftoverCheck.ts +35 -0
  72. package/context/doctor/doctorFindings.ts +70 -0
  73. package/context/doctor/generatedFreshness.ts +56 -0
  74. package/context/doctor/moduleShapeCheck.ts +88 -0
  75. package/context/doctor/recipeDuplicateCheck.ts +42 -0
  76. package/context/doctor/recipeIndexCheck.ts +87 -0
  77. package/context/doctor/rootShapeCheck.ts +55 -0
  78. package/context/doctor/workflowScope.ts +97 -0
  79. package/{recipeScanner.test.ts → context/recipeScanner.test.ts} +1 -1
  80. package/context/safeRead.ts +9 -0
  81. package/csrE2e/csrE2eHarness.fixture.ts +1 -1
  82. package/devkitUtils.test.ts +39 -5
  83. package/{apiReference.test.ts → docs/apiReference.test.ts} +4 -4
  84. package/{apiReference.ts → docs/apiReference.ts} +2 -2
  85. package/docs/errorCodeReference.test.ts +282 -0
  86. package/docs/errorCodeReference.ts +71 -0
  87. package/docs/errorCodeScan.ts +551 -0
  88. package/{frameworkGraph.test.ts → docs/frameworkGraph.test.ts} +1 -1
  89. package/executors/appExecutor.ts +448 -0
  90. package/executors/commandExecutionError.ts +53 -0
  91. package/executors/executor.ts +527 -0
  92. package/{executors.linkFallback.test.ts → executors/executors.linkFallback.test.ts} +1 -1
  93. package/{executors.test.ts → executors/executors.test.ts} +76 -15
  94. package/executors/index.ts +8 -0
  95. package/executors/libExecutor.ts +23 -0
  96. package/executors/moduleExecutor.ts +18 -0
  97. package/executors/pkgExecutor.ts +129 -0
  98. package/executors/sysExecutor.ts +301 -0
  99. package/executors/workspaceExecutor.ts +277 -0
  100. package/frontendBuild/allRoutesBuilder.test.ts +1 -1
  101. package/frontendBuild/autoImportSync.test.ts +1 -1
  102. package/frontendBuild/autoImportSync.ts +1 -1
  103. package/frontendBuild/buildRouteClient.test.ts +1 -1
  104. package/frontendBuild/clientEntriesBundler.test.ts +1 -1
  105. package/frontendBuild/csrArtifactBuilder.test.ts +1 -1
  106. package/frontendBuild/csrDevArtifactWriter.ts +1 -1
  107. package/frontendBuild/cssCompiler.test.ts +3 -2
  108. package/frontendBuild/devGeneratedIndexSync.test.ts +1 -1
  109. package/frontendBuild/devGeneratedIndexSync.ts +7 -38
  110. package/frontendBuild/dictionaryAssetBuilder.test.ts +1 -1
  111. package/frontendBuild/fontOptimizer.test.ts +1 -1
  112. package/frontendBuild/fontPruner.test.ts +1 -1
  113. package/frontendBuild/frontendBuild.test.ts +3 -3
  114. package/frontendBuild/hmrWatcher.stop.test.ts +63 -0
  115. package/frontendBuild/hmrWatcher.test.ts +1 -1
  116. package/frontendBuild/hmrWatcher.ts +22 -1
  117. package/frontendBuild/mcpAppViewBuilder.test.ts +1 -1
  118. package/frontendBuild/mcpAppViewBuilder.ts +1 -1
  119. package/frontendBuild/nativeCore.test.ts +1 -1
  120. package/frontendBuild/optionalPeers.test.ts +36 -8
  121. package/frontendBuild/pagesBundleBuilder.test.ts +2 -3
  122. package/frontendBuild/pagesBundleBuilder.ts +1 -1
  123. package/frontendBuild/precompressArtifacts.test.ts +1 -1
  124. package/frontendBuild/precompressArtifacts.ts +19 -6
  125. package/frontendBuild/serverGraphFile.ts +1 -1
  126. package/frontendBuild/sourceMtimeIndex.test.ts +1 -1
  127. package/frontendBuild/ssrDevBundler.test.ts +1 -1
  128. package/frontendBuild/vendorImportScanner.test.ts +1 -1
  129. package/frontendBuild/vendorNarrowing.test.ts +1 -1
  130. package/frontendBuild/watchRootResolver.test.ts +1 -1
  131. package/{agentAssets.test.ts → guideline/agentAssets.test.ts} +1 -1
  132. package/{agentAssets.ts → guideline/agentAssets.ts} +2 -2
  133. package/{agentsIndex.test.ts → guideline/agentsIndex.test.ts} +2 -2
  134. package/{agentsIndex.ts → guideline/agentsIndex.ts} +13 -10
  135. package/{conventionSet.test.ts → guideline/conventionSet.test.ts} +7 -4
  136. package/{conventionSet.ts → guideline/conventionSet.ts} +1 -1
  137. package/{prompter.ts → guideline/prompter.ts} +2 -3
  138. package/incrementalBuilder/buildBatch.proc.ts +14 -4
  139. package/incrementalBuilder/buildBatchProtocol.ts +2 -0
  140. package/incrementalBuilder/buildBatchRunner.test.ts +122 -2
  141. package/incrementalBuilder/buildBatchRunner.ts +17 -4
  142. package/incrementalBuilder/builderBoot.ts +106 -0
  143. package/incrementalBuilder/builderBuildStatus.ts +23 -0
  144. package/incrementalBuilder/builderChannel.test.ts +1 -1
  145. package/incrementalBuilder/builderChannel.ts +11 -0
  146. package/incrementalBuilder/builderGraphPayloads.ts +3 -3
  147. package/incrementalBuilder/builderLanes.ts +157 -0
  148. package/incrementalBuilder/builderWatch.ts +213 -0
  149. package/incrementalBuilder/csrRegistry.ts +234 -0
  150. package/incrementalBuilder/incrementalBuilder.proc.test.ts +101 -7
  151. package/incrementalBuilder/incrementalBuilder.proc.ts +81 -823
  152. package/incrementalBuilder/ssrRegistry.ts +282 -0
  153. package/index.ts +22 -22
  154. package/integration/devStability.integration.test.ts +62 -56
  155. package/integration/devStabilityHarness.test.ts +1 -1
  156. package/lint/__fixtures__/no-import-common-err/bad.tsx +13 -0
  157. package/lint/__fixtures__/no-import-common-err/good.tsx +12 -0
  158. package/{biomeBase.test.ts → lint/biomeBase.test.ts} +1 -1
  159. package/lint/gritRules.test.ts +1 -1
  160. package/{linter.test.ts → lint/linter.test.ts} +1 -1
  161. package/lint/no-import-common-err.grit +31 -0
  162. package/lint/no-init-fetch-in-client.grit +1 -1
  163. package/mobile/desktopBin.test.ts +1 -1
  164. package/mobile/desktopRelease.test.ts +1 -1
  165. package/mobile/desktopServerStage.test.ts +2 -2
  166. package/mobile/desktopServerStage.ts +1 -1
  167. package/mobile/nativeApi.test.ts +1 -1
  168. package/mobile/nativeApp.test.ts +1 -1
  169. package/mobile/nativeConfig.test.ts +1 -1
  170. package/mobile/nativePluginFolders.test.ts +1 -1
  171. package/mobile/nativePublicEnv.test.ts +1 -1
  172. package/mobile/nativeWebDir.test.ts +1 -1
  173. package/mobile/serverBundleSecrets.test.ts +1 -1
  174. package/mobile/tarWriter.test.ts +1 -1
  175. package/mobile/updatePackFolder.test.ts +1 -1
  176. package/package.json +173 -9
  177. package/packageExports.test.ts +20 -2
  178. package/piDependencyPins.test.ts +1 -1
  179. package/pipeline/PipelineDefinition.ts +1 -1
  180. package/platformTest/IdleWatchedProcess.test.ts +1 -1
  181. package/platformTest/LinuxDockerTarget.ts +1 -1
  182. package/platformTest/PlatformTestRun.test.ts +1 -1
  183. package/platformTest/TestSnapshot.test.ts +1 -1
  184. package/platformTest/WindowsSshTarget.ts +1 -1
  185. package/preview/previewView.test.ts +23 -1
  186. package/{abstractDoc.test.ts → quality/abstractDoc.test.ts} +2 -2
  187. package/{abstractDoc.ts → quality/abstractDoc.ts} +1 -1
  188. package/quality/bareErrorScanner.ts +126 -0
  189. package/{maintainabilityBaseline.test.ts → quality/maintainabilityBaseline.test.ts} +73 -0
  190. package/{maintainabilityBaseline.ts → quality/maintainabilityBaseline.ts} +97 -9
  191. package/{maintainabilityContract.test.ts → quality/maintainabilityContract.test.ts} +383 -2
  192. package/{maintainabilityContract.ts → quality/maintainabilityContract.ts} +151 -29
  193. package/{maintainabilityExceptionScanner.test.ts → quality/maintainabilityExceptionScanner.test.ts} +15 -1
  194. package/{maintainabilityExceptionScanner.ts → quality/maintainabilityExceptionScanner.ts} +5 -1
  195. package/{maintainabilityLimits.ts → quality/maintainabilityLimits.ts} +12 -0
  196. package/{maintainabilityReport.ts → quality/maintainabilityReport.ts} +20 -3
  197. package/{qualityScanner.test.ts → quality/qualityScanner.test.ts} +41 -1
  198. package/{qualityScanner.ts → quality/qualityScanner.ts} +25 -91
  199. package/{storeAccessScanner.ts → quality/storeAccessScanner.ts} +15 -2
  200. package/quality/workspaceSourceFiles.ts +82 -0
  201. package/{subspace.test.ts → subspace/subspace.test.ts} +25 -4
  202. package/{subspace.ts → subspace/subspace.ts} +5 -5
  203. package/{subspaceClone.ts → subspace/subspaceClone.ts} +8 -8
  204. package/{subspaceConfig.ts → subspace/subspaceConfig.ts} +5 -1
  205. package/{testHelpers.ts → test/testHelpers.ts} +37 -1
  206. package/transforms/barrelAnalyzer.ts +31 -10
  207. package/transforms/browserDirnamePlugin.test.ts +1 -1
  208. package/transforms/externalizeFrameworkPlugin.test.ts +1 -1
  209. package/transforms/mcpAppPageTrimmer.test.ts +1 -1
  210. package/transforms/pureLazyMarker.test.ts +1 -1
  211. package/transforms/serverEnvPlugin.test.ts +1 -1
  212. package/transforms/serverEnvProfile.test.ts +1 -1
  213. package/transforms/sideEffectImportOrder.test.ts +1 -1
  214. package/transforms/transforms.test.ts +52 -2
  215. package/transforms/tsconfigPackageResolver.test.ts +1 -1
  216. package/{createTunnel.test.ts → tunnel/createTunnel.test.ts} +1 -1
  217. package/{createTunnel.ts → tunnel/createTunnel.ts} +2 -2
  218. package/{sshHostKeys.ts → tunnel/sshHostKeys.ts} +2 -2
  219. package/typecheck/projectTypecheck.test.ts +23 -1
  220. package/typecheck/projectTypecheck.ts +10 -2
  221. package/{typeChecker.test.ts → typecheck/typeChecker.test.ts} +1 -1
  222. package/{typeChecker.ts → typecheck/typeChecker.ts} +5 -4
  223. package/typecheck/typecheck.proc.ts +6 -2
  224. package/typecheck/typecheckFailure.ts +1 -1
  225. package/util/errorReport.ts +66 -0
  226. package/{jsonFormatter.test.ts → util/jsonFormatter.test.ts} +1 -1
  227. package/workflow/constantSource.ts +187 -0
  228. package/workflow/dictionarySource.ts +184 -0
  229. package/workflow/executor.ts +6 -9
  230. package/workflow/fieldExpression.ts +153 -0
  231. package/workflow/fieldLabel.ts +61 -0
  232. package/workflow/fieldOrder.ts +117 -0
  233. package/workflow/fieldType.ts +2 -1
  234. package/workflow/guardCatalog.test.ts +1 -1
  235. package/workflow/keyRename.ts +1 -1
  236. package/workflow/moduleIndex.test.ts +2 -2
  237. package/workflow/moduleIndex.ts +2 -2
  238. package/workflow/modulePaths.ts +27 -0
  239. package/workflow/mutationScaffold.ts +7 -15
  240. package/workflow/mutationSource.ts +2 -1
  241. package/workflow/plan.ts +2 -1
  242. package/workflow/primitiveReport.ts +78 -0
  243. package/workflow/rolloutGate.test.ts +1 -1
  244. package/workflow/rolloutGate.ts +1 -1
  245. package/workflow/serviceSource.ts +33 -0
  246. package/workflow/signalSource.ts +96 -0
  247. package/workflow/source.ts +50 -1100
  248. package/workflow/sourceAst.ts +30 -0
  249. package/workflow/sourceImports.ts +105 -0
  250. package/workflow/sourceText.ts +13 -0
  251. package/workflow/templateSource.ts +30 -0
  252. package/workflow/testSource.ts +31 -0
  253. package/workflow/types.ts +1 -1
  254. package/workflow/uiPolicy.ts +1 -1
  255. package/{appSelectionMemory.ts → workspace/appSelectionMemory.ts} +1 -1
  256. package/{codegenLock.test.ts → workspace/codegenLock.test.ts} +1 -1
  257. package/{dependencyScanner.test.ts → workspace/dependencyScanner.test.ts} +1 -1
  258. package/{dependencyScanner.ts → workspace/dependencyScanner.ts} +2 -2
  259. package/{envSeed.test.ts → workspace/envSeed.test.ts} +2 -2
  260. package/{envSeed.ts → workspace/envSeed.ts} +1 -1
  261. package/{libSource.test.ts → workspace/libSource.test.ts} +2 -2
  262. package/{libSource.ts → workspace/libSource.ts} +1 -1
  263. package/{scanInfo.ts → workspace/scanInfo.ts} +21 -10
  264. package/{slicePlanner.test.ts → workspace/slicePlanner.test.ts} +2 -2
  265. package/{slicePlanner.ts → workspace/slicePlanner.ts} +1 -1
  266. package/{workspaceGraph.test.ts → workspace/workspaceGraph.test.ts} +1 -1
  267. package/{workspaceGraph.ts → workspace/workspaceGraph.ts} +1 -1
  268. package/{workspaceLayout.test.ts → workspace/workspaceLayout.test.ts} +1 -1
  269. package/{workspaceLayout.ts → workspace/workspaceLayout.ts} +3 -1
  270. package/akanContext.ts +0 -1083
  271. package/executors.ts +0 -1749
  272. /package/{applicationBuildReporter.test.ts → app/applicationBuildReporter.test.ts} +0 -0
  273. /package/{akanMcpToolError.ts → context/akanMcpToolError.ts} +0 -0
  274. /package/{moduleFieldNames.test.ts → context/moduleFieldNames.test.ts} +0 -0
  275. /package/{moduleFieldNames.ts → context/moduleFieldNames.ts} +0 -0
  276. /package/{recipeScanner.ts → context/recipeScanner.ts} +0 -0
  277. /package/{declarationReader.ts → docs/declarationReader.ts} +0 -0
  278. /package/{frameworkGraph.ts → docs/frameworkGraph.ts} +0 -0
  279. /package/{biomeBase.ts → lint/biomeBase.ts} +0 -0
  280. /package/{linter.ts → lint/linter.ts} +0 -0
  281. /package/{commentDensityScanner.test.ts → quality/commentDensityScanner.test.ts} +0 -0
  282. /package/{commentDensityScanner.ts → quality/commentDensityScanner.ts} +0 -0
  283. /package/{componentSizeScanner.test.ts → quality/componentSizeScanner.test.ts} +0 -0
  284. /package/{componentSizeScanner.ts → quality/componentSizeScanner.ts} +0 -0
  285. /package/{componentWriteChainScanner.test.ts → quality/componentWriteChainScanner.test.ts} +0 -0
  286. /package/{componentWriteChainScanner.ts → quality/componentWriteChainScanner.ts} +0 -0
  287. /package/{deprecatedCommentScanner.test.ts → quality/deprecatedCommentScanner.test.ts} +0 -0
  288. /package/{deprecatedCommentScanner.ts → quality/deprecatedCommentScanner.ts} +0 -0
  289. /package/{endpointReach.test.ts → quality/endpointReach.test.ts} +0 -0
  290. /package/{endpointReach.ts → quality/endpointReach.ts} +0 -0
  291. /package/{formSetterScanner.test.ts → quality/formSetterScanner.test.ts} +0 -0
  292. /package/{formSetterScanner.ts → quality/formSetterScanner.ts} +0 -0
  293. /package/{kindBranchScanner.test.ts → quality/kindBranchScanner.test.ts} +0 -0
  294. /package/{kindBranchScanner.ts → quality/kindBranchScanner.ts} +0 -0
  295. /package/{maintainabilityReport.test.ts → quality/maintainabilityReport.test.ts} +0 -0
  296. /package/{renderMutationScanner.test.ts → quality/renderMutationScanner.test.ts} +0 -0
  297. /package/{renderMutationScanner.ts → quality/renderMutationScanner.ts} +0 -0
  298. /package/{serviceLoopCallScanner.test.ts → quality/serviceLoopCallScanner.test.ts} +0 -0
  299. /package/{serviceLoopCallScanner.ts → quality/serviceLoopCallScanner.ts} +0 -0
  300. /package/{signalMutationIndex.test.ts → quality/signalMutationIndex.test.ts} +0 -0
  301. /package/{signalMutationIndex.ts → quality/signalMutationIndex.ts} +0 -0
  302. /package/{sourceComments.test.ts → quality/sourceComments.test.ts} +0 -0
  303. /package/{sourceComments.ts → quality/sourceComments.ts} +0 -0
  304. /package/{ssrScanner.test.ts → quality/ssrScanner.test.ts} +0 -0
  305. /package/{ssrScanner.ts → quality/ssrScanner.ts} +0 -0
  306. /package/{storeAccessScanner.test.ts → quality/storeAccessScanner.test.ts} +0 -0
  307. /package/{storeSource.ts → quality/storeSource.ts} +0 -0
  308. /package/{storeWriteScanner.test.ts → quality/storeWriteScanner.test.ts} +0 -0
  309. /package/{storeWriteScanner.ts → quality/storeWriteScanner.ts} +0 -0
  310. /package/{structureScanner.test.ts → quality/structureScanner.test.ts} +0 -0
  311. /package/{structureScanner.ts → quality/structureScanner.ts} +0 -0
  312. /package/{testOnlyExportScanner.test.ts → quality/testOnlyExportScanner.test.ts} +0 -0
  313. /package/{testOnlyExportScanner.ts → quality/testOnlyExportScanner.ts} +0 -0
  314. /package/{writePath.test.ts → quality/writePath.test.ts} +0 -0
  315. /package/{writePath.ts → quality/writePath.ts} +0 -0
  316. /package/{writePlacementScanner.test.ts → quality/writePlacementScanner.test.ts} +0 -0
  317. /package/{writePlacementScanner.ts → quality/writePlacementScanner.ts} +0 -0
  318. /package/{writingActionIndex.test.ts → quality/writingActionIndex.test.ts} +0 -0
  319. /package/{writingActionIndex.ts → quality/writingActionIndex.ts} +0 -0
  320. /package/{subspaceReport.ts → subspace/subspaceReport.ts} +0 -0
  321. /package/{sshTunnel.ts → tunnel/sshTunnel.ts} +0 -0
  322. /package/{fileEditor.ts → util/fileEditor.ts} +0 -0
  323. /package/{fileSys.test.ts → util/fileSys.test.ts} +0 -0
  324. /package/{fileSys.ts → util/fileSys.ts} +0 -0
  325. /package/{jsonFormatter.ts → util/jsonFormatter.ts} +0 -0
  326. /package/{selectModel.ts → util/selectModel.ts} +0 -0
  327. /package/{semver.test.ts → util/semver.test.ts} +0 -0
  328. /package/{semver.ts → util/semver.ts} +0 -0
  329. /package/{shellOnlyEnv.test.ts → util/shellOnlyEnv.test.ts} +0 -0
  330. /package/{shellOnlyEnv.ts → util/shellOnlyEnv.ts} +0 -0
  331. /package/{spinner.test.ts → util/spinner.test.ts} +0 -0
  332. /package/{spinner.ts → util/spinner.ts} +0 -0
  333. /package/{stripAnsi.ts → util/stripAnsi.ts} +0 -0
  334. /package/{codegenLock.ts → workspace/codegenLock.ts} +0 -0
  335. /package/{getRelatedCnsts.ts → workspace/getRelatedCnsts.ts} +0 -0
  336. /package/{gitRevision.test.ts → workspace/gitRevision.test.ts} +0 -0
  337. /package/{gitRevision.ts → workspace/gitRevision.ts} +0 -0
  338. /package/{manifestDependencies.ts → workspace/manifestDependencies.ts} +0 -0
  339. /package/{packageExportsMap.ts → workspace/packageExportsMap.ts} +0 -0
  340. /package/{repoIdentity.ts → workspace/repoIdentity.ts} +0 -0
  341. /package/{types.ts → workspace/types.ts} +0 -0
@@ -0,0 +1,282 @@
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 type { ClientEntryDiscovery } from "@akanjs/devkit/frontendBuild/clientBuildTypes";
6
+ import { CsrDevPatcher } from "@akanjs/devkit/frontendBuild/csrDevPatcher";
7
+ import { ServerGraphFile } from "@akanjs/devkit/frontendBuild/serverGraphFile";
8
+ import { SsrDevBundler } from "@akanjs/devkit/frontendBuild/ssrDevBundler";
9
+ import type { Logger } from "akanjs/common";
10
+ import type { HmrTrace } from "akanjs/server";
11
+ import { CSR_DEV_PATCHING_MARKER } from "akanjs/server/hmr/csrDevManifest";
12
+ import type { BatchWork, BuildBatchResult } from "./buildBatchProtocol";
13
+ import { isCompileError, sendBuildStatus } from "./builderBuildStatus";
14
+ import { BuilderChannel } from "./builderChannel";
15
+ import type { BuilderLanes } from "./builderLanes";
16
+
17
+ interface SsrRegistryLinks {
18
+ generation: () => number;
19
+ discovery: () => ClientEntryDiscovery;
20
+ runBatch: (work: BatchWork) => Promise<BuildBatchResult>;
21
+ countDelegation: (registry: "csr" | "ssr", reason: string) => string;
22
+ }
23
+
24
+ export class SsrRegistry {
25
+ readonly #app: App;
26
+ readonly #logger: Logger;
27
+ readonly #lanes: BuilderLanes;
28
+ readonly #artifactDir: string;
29
+ readonly #links: SsrRegistryLinks;
30
+ #crashRetryTimer: ReturnType<typeof setTimeout> | null = null;
31
+ readonly #crashRetryEntries = new Set<string>();
32
+ /** Where SSR pages load their client code from in dev; route builds bundle only its server half. */
33
+ #ssrBundler: SsrDevBundler;
34
+ /** Null when `AKAN_DEV_CSR_PATCHER=off`: every registry save then goes to a build worker. */
35
+ #ssrPatcher: CsrDevPatcher | null;
36
+ //* Serializes everything that writes ssr-dev: a save's patch (fast lane), a route build adding the entries it names,
37
+ //* a queued worker batch with the ssr need, and the boot build. Never held while awaiting the slow lane.
38
+ #ssrLock: Promise<void> = Promise.resolve();
39
+ /** The boot build of the SSR registry while it runs; it holds every entry the routes reach once it lands. */
40
+ #ssrArming: Promise<void> | null = null;
41
+ //* A registry build that failed on the user's code fails again until the code changes, so route builds do not retry
42
+ //* it; the next attempt that touches the registry (a save's patch, a worker batch) settles it. A worker that died
43
+ //* before reporting (an OOM kill) route builds do retry, at most every `#crashRetryMs`.
44
+ #ssrBroken = false;
45
+ #ssrCrashedAt: number | null = null;
46
+ static get #crashRetryMs(): number {
47
+ //? `AKAN_DEV_SSR_CRASH_RETRY_MS` is a test hook: a builder test waits out a shorter window than a developer's.
48
+ const ms = Number(process.env.AKAN_DEV_SSR_CRASH_RETRY_MS);
49
+ return Number.isInteger(ms) && ms > 0 ? ms : 10_000;
50
+ }
51
+
52
+ constructor(
53
+ app: App,
54
+ { logger, lanes, artifactDir }: { logger: Logger; lanes: BuilderLanes; artifactDir: string },
55
+ links: SsrRegistryLinks,
56
+ ) {
57
+ this.#app = app;
58
+ this.#logger = logger;
59
+ this.#lanes = lanes;
60
+ this.#artifactDir = artifactDir;
61
+ this.#links = links;
62
+ this.#ssrBundler = new SsrDevBundler(app, { discovery: links.discovery });
63
+ this.#ssrPatcher =
64
+ process.env.AKAN_DEV_CSR_PATCHER === "off" ? null : new CsrDevPatcher(this.#ssrBundler, { resident: true });
65
+ }
66
+
67
+ get ssrPatcher(): CsrDevPatcher | null {
68
+ return this.#ssrPatcher;
69
+ }
70
+
71
+ // True when the save has to go to a build worker, as for CSR.
72
+ async patchSsr(generation: number, files: string[], trace: HmrTrace): Promise<boolean> {
73
+ const patcher = this.#ssrPatcher;
74
+ if (!patcher) return true;
75
+ const hold = await ServerGraphFile.touches(await ServerGraphFile.read(this.#artifactDir), files, (file) =>
76
+ ServerGraphFile.clientExportsOf(file),
77
+ );
78
+ //? Ahead of this save's own discovery job in the slow lane: which client entries a page still names decides which
79
+ //? pending roots this patch keeps.
80
+ this.#links.discovery().invalidate?.(files);
81
+ return await this.withSsrLock(
82
+ async () => await this.#runSsrPatcher(patcher, files, { trace, hold, batchGeneration: generation }),
83
+ );
84
+ }
85
+
86
+ //* Adds the entries a route build names to the registry, since the tab requires them by id. A registry that cannot
87
+ //* take them fails no route build: the page answers, and its tab waits for the registry while the overlay says why.
88
+ async ensureSsrEntries(entries: string[], { crashRetry = false }: { crashRetry?: boolean } = {}): Promise<void> {
89
+ if (entries.length === 0) return;
90
+ //? The boot build takes every entry the routes reach, so the first page answers now and its tab waits for the
91
+ //? registry (boot.json) instead; whatever that build missed is added right after it lands.
92
+ const arming = this.#ssrArming;
93
+ if (arming) {
94
+ void this.#lanes.runBeside(
95
+ arming
96
+ .then(async () => await this.ensureSsrEntries(entries, { crashRetry }))
97
+ .catch(this.#lanes.slowLaneFailed("ssr-ensure")),
98
+ );
99
+ return;
100
+ }
101
+ await this.withSsrLock(async () => {
102
+ const patcher = this.#ssrPatcher;
103
+ // The builder's generation, not the request's: its build-status joins the saves' `ssr` ones.
104
+ const generation = this.#links.generation();
105
+ if (
106
+ patcher &&
107
+ !(await this.#runSsrPatcher(patcher, [], { roots: entries, onlyRoots: true, batchGeneration: generation }))
108
+ )
109
+ return;
110
+ //? Read, not compiled: with the patcher off, the save's own worker batch already built every entry.
111
+ if (!patcher && (await this.#ssrBundler.holds(entries))) return;
112
+ //? Not retried per route build: the save that fixes the error rebuilds it, where each route build retrying held
113
+ //? the SSR lock that save's patch waits on.
114
+ if (this.#ssrBroken) return;
115
+ if (this.#ssrCrashedAt !== null && Date.now() - this.#ssrCrashedAt < SsrRegistry.#crashRetryMs) {
116
+ //? Handed over just now with nothing run for them: the retry must find them to hand over again.
117
+ patcher?.releaseHandedOver();
118
+ this.#retryAfterCrash(this.#ssrCrashedAt, entries);
119
+ return;
120
+ }
121
+ await this.#runSsrWorker(generation).catch((err: unknown) => {
122
+ this.#logger.error(
123
+ `ssr-registry could not take a route's entries; the save that fixes it rebuilds it: ${ApplicationBuildReporter.formatError(err, this.#app.workspace.workspaceRoot)}`,
124
+ );
125
+ });
126
+ //? A worker that died took these entries with it and left them pending nowhere: they are tried once more after the
127
+ //? crash window, but a retry that crashes again waits for the next route build or save.
128
+ if (this.#ssrCrashedAt !== null && !crashRetry) this.#retryAfterCrash(this.#ssrCrashedAt, entries);
129
+ });
130
+ }
131
+
132
+ //? Once the crash window closes, for the entries skipped in it: later route builds may name none (the first one
133
+ //? announced every entry to the route cache), so without this a tab could wait on boot.json until the next save.
134
+ #retryAfterCrash(crashedAt: number, entries: string[]): void {
135
+ for (const entry of entries) this.#crashRetryEntries.add(entry);
136
+ if (this.#crashRetryTimer) return;
137
+ const timer = setTimeout(
138
+ () => {
139
+ this.#crashRetryTimer = null;
140
+ const retried = [...this.#crashRetryEntries];
141
+ this.#crashRetryEntries.clear();
142
+ if (this.#lanes.shuttingDown || retried.length === 0) return;
143
+ void this.#lanes
144
+ .runBeside(this.ensureSsrEntries(retried, { crashRetry: true }))
145
+ .catch(this.#lanes.slowLaneFailed("ssr-crash-retry"));
146
+ },
147
+ Math.max(0, crashedAt + SsrRegistry.#crashRetryMs - Date.now()),
148
+ );
149
+ timer.unref?.();
150
+ this.#crashRetryTimer = timer;
151
+ }
152
+
153
+ //* The boot build of the SSR registry runs beside the slow lane, holding only the SSR lock: the first page's route
154
+ //* build bundles meanwhile instead of queueing behind it (on apps/akan it cost the first page about a second).
155
+ async armSsrRegistry(): Promise<void> {
156
+ //? `AKAN_DEV_SSR_ARM_DELAY_MS` is a test hook: an E2E has a tab reconnect before the boot build has run.
157
+ const delayMs = Number(process.env.AKAN_DEV_SSR_ARM_DELAY_MS);
158
+ if (Number.isInteger(delayMs) && delayMs > 0) await Bun.sleep(delayMs);
159
+ const arm = async () =>
160
+ await this.withSsrLock(async () => {
161
+ const generation = this.#links.generation();
162
+ if (this.#ssrPatcher && !(await this.#runSsrPatcher(this.#ssrPatcher, [], { batchGeneration: generation })))
163
+ return;
164
+ await this.#runSsrWorker(generation);
165
+ }).catch((err: unknown) => {
166
+ this.#logger.error(
167
+ `ssr-registry boot build failed; the next save retries it: ${ApplicationBuildReporter.formatError(err, this.#app.workspace.workspaceRoot)}`,
168
+ );
169
+ });
170
+ const arming = this.#lanes.runBeside(
171
+ (async () => {
172
+ await arm();
173
+ //? A boot build whose worker was killed (a small container's OOM) is tried once more before `boot-armed` lets
174
+ //? the next app boot: retried after that, the two biggest workers of a boot would run side by side.
175
+ const crashedAt = this.#ssrCrashedAt;
176
+ if (crashedAt === null) return;
177
+ while (!this.#lanes.shuttingDown && Date.now() < crashedAt + SsrRegistry.#crashRetryMs) await Bun.sleep(250);
178
+ if (!this.#lanes.shuttingDown) await arm();
179
+ })(),
180
+ );
181
+ this.#ssrArming = arming;
182
+ await arming;
183
+ this.#ssrArming = null;
184
+ }
185
+
186
+ async withSsrLock<T>(fn: () => Promise<T>): Promise<T> {
187
+ const run = this.#ssrLock.then(fn, fn);
188
+ this.#ssrLock = run.then(
189
+ () => undefined,
190
+ () => undefined,
191
+ );
192
+ return await run;
193
+ }
194
+
195
+ // Runs the worker directly, under the SSR lock its callers hold: queueing it could wait on a batch that waits on them.
196
+ async #runSsrWorker(generation: number): Promise<void> {
197
+ let result: BuildBatchResult;
198
+ try {
199
+ result = await this.#links.runBatch({ generation, needs: ["ssr"], changedFiles: [] });
200
+ } finally {
201
+ this.#ssrPatcher?.forget();
202
+ }
203
+ this.noteSsrWorker(result);
204
+ if (result.errors.ssr) throw new Error(result.errors.ssr);
205
+ }
206
+
207
+ noteSsrWorker(result: BuildBatchResult): void {
208
+ const crashed = !!result.crashed && (result.crashedNeeds ?? ["ssr"]).includes("ssr");
209
+ this.#ssrBroken = !!result.errors.ssr && !crashed;
210
+ this.#ssrCrashedAt = crashed ? Date.now() : null;
211
+ }
212
+
213
+ async #runSsrPatcher(
214
+ patcher: CsrDevPatcher,
215
+ files: string[],
216
+ {
217
+ roots,
218
+ onlyRoots,
219
+ trace,
220
+ hold,
221
+ batchGeneration,
222
+ }: { roots?: string[]; onlyRoots?: boolean; trace?: HmrTrace; hold?: boolean; batchGeneration?: number } = {},
223
+ ): Promise<boolean> {
224
+ const started = Date.now();
225
+ const marker = path.join(this.#ssrBundler.outDir, CSR_DEV_PATCHING_MARKER);
226
+ await Bun.write(marker, String(process.pid));
227
+ try {
228
+ const result = await patcher.update(files, {
229
+ roots,
230
+ onlyRoots,
231
+ announce: (update) => {
232
+ const now = Date.now();
233
+ BuilderChannel.emit({
234
+ type: "ssr-updated",
235
+ data: {
236
+ generation: update.generation,
237
+ reload: update.reload,
238
+ reason: update.reason,
239
+ patchUrl: update.patchUrl,
240
+ changedIds: update.changedIds,
241
+ ...(trace ? { trace: { ...trace, patchAt: now, sentAt: now } } : {}),
242
+ ...(hold ? { hold } : {}),
243
+ ...(batchGeneration !== undefined ? { batchGeneration } : {}),
244
+ ...(update.epoch !== undefined ? { epoch: update.epoch } : {}),
245
+ ...(update.first ? { first: true } : {}),
246
+ },
247
+ });
248
+ },
249
+ });
250
+ if (result.kind === "delegate") {
251
+ this.#logger.verbose(
252
+ `ssr-patch handed to a build worker (${this.#links.countDelegation("ssr", result.reason)}): ${result.reason}`,
253
+ );
254
+ return true;
255
+ }
256
+ //? A route build's check reports only a failure: it compiles the roots the registry lacks and nothing else, so
257
+ //? its ok, of the builder's current generation, would read as the fix of a save that broke something else.
258
+ if (!onlyRoots) {
259
+ this.#ssrBroken = false;
260
+ this.#ssrCrashedAt = null;
261
+ sendBuildStatus("ssr", { generation: batchGeneration, ok: true, files });
262
+ }
263
+ this.#logger.verbose(
264
+ result.kind === "unchanged"
265
+ ? `ssr-patch unchanged (${Date.now() - started}ms)`
266
+ : `ssr-patch generation=${result.update.generation} ${result.update.reload ? `reload (${result.update.reason})` : `patch modules=${result.update.changedIds.length}`} (${Date.now() - started}ms)`,
267
+ );
268
+ return false;
269
+ } catch (err) {
270
+ const message = ApplicationBuildReporter.formatError(err, this.#app.workspace.workspaceRoot);
271
+ if (isCompileError(err)) {
272
+ sendBuildStatus("ssr", { generation: batchGeneration, ok: false, files, message });
273
+ return false;
274
+ }
275
+ this.#logger.verbose(`ssr-patch threw; a build worker takes it: ${message}`);
276
+ patcher.forget();
277
+ return true;
278
+ } finally {
279
+ await rm(marker, { force: true });
280
+ }
281
+ }
282
+ }
package/index.ts CHANGED
@@ -1,35 +1,35 @@
1
1
  // XXX: types only. A value import from this barrel loads every facet (ink, typescript, ssh2, …) into the process;
2
- // `export type *` erases at runtime. Import values from the owning facet (`@akanjs/devkit/fileSys`) and never "fix" a
3
- // TS1362 by widening an entry back to `export *`.
2
+ // `export type *` erases at runtime. Import values from the owning facet (`@akanjs/devkit/util/fileSys`) and never
3
+ // "fix" a TS1362 by widening an entry back to `export *`.
4
4
  export type * from "./akanApp";
5
5
  export type * from "./akanConfig";
6
- export type * from "./akanContext";
7
- export type * from "./akanMcpContract";
8
- export type * from "./applicationBuildReporter";
9
- export type * from "./applicationBuildRunner";
10
- export type * from "./applicationTestPreload";
6
+ export type * from "./app/applicationBuildReporter";
7
+ export type * from "./app/applicationBuildRunner";
8
+ export type * from "./app/applicationTestPreload";
11
9
  export type * from "./artifact";
12
10
  export type * from "./cloud";
13
11
  export type * from "./codeAgent";
14
12
  export type * from "./commandDecorators";
15
- export type * from "./createTunnel";
16
- export type * from "./dependencyScanner";
13
+ export type * from "./context/akanContext";
14
+ export type * from "./context/akanMcpContract";
15
+ export type * from "./context/recipeScanner";
17
16
  export type * from "./executors";
18
- export type * from "./fileSys";
19
17
  export type * from "./frontendBuild";
20
- export type * from "./getRelatedCnsts";
18
+ export type * from "./guideline/prompter";
21
19
  export type * from "./incrementalBuilder";
22
- export type * from "./maintainabilityContract";
23
20
  export type * from "./mobile";
24
- export type * from "./packageExportsMap";
25
- export type * from "./prompter";
26
- export type * from "./qualityScanner";
27
- export type * from "./recipeScanner";
28
- export type * from "./scanInfo";
29
- export type * from "./selectModel";
30
- export type * from "./spinner";
31
- export type * from "./stripAnsi";
21
+ export type * from "./quality/maintainabilityContract";
22
+ export type * from "./quality/qualityScanner";
32
23
  export type * from "./transforms";
33
- export type * from "./typeChecker";
34
- export type * from "./types";
24
+ export type * from "./tunnel/createTunnel";
25
+ export type * from "./typecheck/typeChecker";
26
+ export type * from "./util/fileSys";
27
+ export type * from "./util/selectModel";
28
+ export type * from "./util/spinner";
29
+ export type * from "./util/stripAnsi";
35
30
  export type * from "./workflow";
31
+ export type * from "./workspace/dependencyScanner";
32
+ export type * from "./workspace/getRelatedCnsts";
33
+ export type * from "./workspace/packageExportsMap";
34
+ export type * from "./workspace/scanInfo";
35
+ export type * from "./workspace/types";
@@ -1,13 +1,18 @@
1
1
  import { afterAll, afterEach, beforeAll, describe, expect, test } from "bun:test";
2
+ import { rm } from "node:fs/promises";
3
+ import path from "node:path";
2
4
  import { AkanAppHost } from "../akanApp";
3
5
  import { DevGeneratedIndexSync } from "../frontendBuild";
6
+ import { tempDirs } from "../test/testHelpers";
4
7
  import { DevStabilityHarness, type DevStabilityHmrProbe } from "./devStabilityHarness.fixture";
5
8
 
6
9
  const integrationEnabled = process.env.AKAN_DEV_STABILITY_INTEGRATION === "1";
7
10
  // Contention pushes a cold dev-server boot from ~3s to nearly a minute; 120s ran out mid-restart.
8
11
  const INTEGRATION_TIMEOUT_MS = 180_000;
12
+ const WAIT_MS = 90_000;
9
13
  const MB = 1024 * 1024;
10
14
  const harnesses: DevStabilityHarness[] = [];
15
+ const tempDir = tempDirs("akan-builder-gate-");
11
16
 
12
17
  const integrationTest = (name: string, fn: () => Promise<void>): void => {
13
18
  if (integrationEnabled) test(name, fn, INTEGRATION_TIMEOUT_MS);
@@ -193,12 +198,7 @@ describe("dev stability integration harness", () => {
193
198
  const harness = await createHarness();
194
199
  const host = await harness.startHost();
195
200
  const hmr = await harness.tryConnectHmrProbe();
196
- const initialHtml = await harness.tryWaitForHttpText("initial-client-marker", 3_000);
197
- if (!initialHtml) {
198
- expect(host.proc.killed).toBe(false);
199
- hmr?.close();
200
- return;
201
- }
201
+ await harness.waitForHttpText("initial-client-marker", WAIT_MS);
202
202
  const hmrMark = hmr?.mark() ?? 0;
203
203
 
204
204
  const { mark } = await harness.editUntilSeen(
@@ -228,12 +228,7 @@ describe("dev stability integration harness", () => {
228
228
  const harness = await createHarness();
229
229
  const host = await harness.startHost();
230
230
  const hmr = await harness.tryConnectHmrProbe();
231
- const initialHtml = await harness.tryWaitForHttpText("initial-shared-marker", 3_000);
232
- if (!initialHtml) {
233
- expect(host.proc.killed).toBe(false);
234
- hmr?.close();
235
- return;
236
- }
231
+ await harness.waitForHttpText("initial-shared-marker", WAIT_MS);
237
232
  const { mark, evidence } = await harness.editUntilSeen(
238
233
  host,
239
234
  (attempt) => harness.replaceText("common/marker.ts", /"[^"]*"/, `"updated-shared-marker-${attempt}"`),
@@ -251,12 +246,7 @@ describe("dev stability integration harness", () => {
251
246
  const harness = await createHarness();
252
247
  const host = await harness.startHost();
253
248
  const hmr = await harness.tryConnectHmrProbe();
254
- const initialHtml = await harness.tryWaitForHttpText("initial-shared-marker", 3_000);
255
- if (!initialHtml) {
256
- expect(host.proc.killed).toBe(false);
257
- hmr?.close();
258
- return;
259
- }
249
+ await harness.waitForHttpText("initial-shared-marker", WAIT_MS);
260
250
  const { mark } = await harness.editUntilSeen(
261
251
  host,
262
252
  (attempt) =>
@@ -287,11 +277,7 @@ export const dictionary = serviceDictionary(["en", "ko"])
287
277
  integrationTest("config edits restart the dev host and keep serving", async () => {
288
278
  const harness = await createHarness();
289
279
  const host = await harness.startHost();
290
- const initialHtml = await harness.tryWaitForHttpText("initial-shared-marker", 3_000);
291
- if (!initialHtml) {
292
- expect(host.proc.killed).toBe(false);
293
- return;
294
- }
280
+ await harness.waitForHttpText("initial-shared-marker", WAIT_MS);
295
281
  const { mark } = await harness.editUntilSeen(
296
282
  host,
297
283
  (attempt) =>
@@ -318,12 +304,7 @@ export default config;
318
304
  const harness = await createHarness();
319
305
  const host = await harness.startHost();
320
306
  const hmr = await harness.tryConnectHmrProbe();
321
- const initialHtml = await harness.tryWaitForHttpText("initial-client-marker", 3_000);
322
- if (!initialHtml) {
323
- expect(host.proc.killed).toBe(false);
324
- hmr?.close();
325
- return;
326
- }
307
+ await harness.waitForHttpText("initial-client-marker", WAIT_MS);
327
308
  const failureHmrMark = hmr?.mark() ?? 0;
328
309
 
329
310
  const { mark: failureMark } = await harness.editUntilSeen(host, (attempt) =>
@@ -495,7 +476,6 @@ export class FixtureService extends serve("fixture" as const, { serverMode: "bat
495
476
  // not parallel-safe: run this block alone on an idle machine (`-t "dev resource budgets"`), never loosen it.
496
477
  describe("dev resource budgets", () => {
497
478
  const BOOT_MS = 150_000;
498
- const WAIT_MS = 90_000;
499
479
  // ~6x the measured 260-516ms per save: catches a path that got slower by a factor, not jitter.
500
480
  const SAVE_LATENCY_BUDGET_MS = 3_000;
501
481
  const budgetTest = (name: string, fn: () => Promise<void>): void => {
@@ -630,31 +610,50 @@ describe("dev resource budgets", () => {
630
610
  // throttled), never disabled for the session. Whether it is back over depends on the machine's allocator, so the
631
611
  // warning is asserted only when it is; the decision itself is unit-tested (devHostPolicy).
632
612
  const settledFrom = host.markLog();
633
- for (let i = 1; i <= 3; i++) {
613
+ const armed = /\[builder-recycle\] armed/;
614
+ const settleOutcome = /recycling builder pid=\d+|\[builder-recycle\] (?:skipped|settle check abandoned)/;
615
+ const answered = () =>
616
+ /ceiling costs about one boot build per interval/.test(host.logs.join("").slice(start)) ||
617
+ armed.test(host.logs.join("").slice(settledFrom)) ||
618
+ settleOutcome.test(host.logs.join("").slice(settledFrom));
619
+ let deadline = Number.POSITIVE_INFINITY;
620
+ for (let i = 1; ; i++) {
634
621
  const { mark } = await harness.editUntilSeen(host, (attempt) =>
635
622
  harness.replaceText("ui/ClientMarker.tsx", /marker(-[\w-]+)?/, `marker-settled-${i}-${attempt}`),
636
623
  );
637
- await host.waitForLogSince(mark, /pages-rebundle ok/, WAIT_MS).catch(() => undefined);
624
+ //? The builder reports its rss to the host only once idle, which is after `pages-rebundle ok`.
625
+ await host.waitForLogSince(mark, /\[work-queue\] batch finished/, WAIT_MS);
626
+ if (i < 3) continue;
627
+ if (i === 3) deadline = performance.now() + WAIT_MS;
628
+ const settled = await DevStabilityHarness.builderProcess(host.proc.pid);
629
+ //? Read as the host reads it: on macOS `ps` also counts the pages the builder freed.
630
+ const settledRss = settled ? await AkanAppHost.readProcessRssBytes(settled.pid) : null;
631
+ //? The host is silent on a report under the ceiling and on a first one over it: only another save asks again.
632
+ if (answered() || (settledRss ?? 0) < CEILING_MB * MB) break;
633
+ if (performance.now() > deadline)
634
+ throw new Error(
635
+ `The builder stayed over the ${CEILING_MB}MiB ceiling (${Math.round((settledRss ?? 0) / MB)}MiB) for ${i} saves and the host never answered`,
636
+ );
638
637
  }
639
- const settled = await DevStabilityHarness.builderProcess(host.proc.pid);
640
- //? Read as the host reads it: on macOS `ps` also counts the pages the builder freed.
641
- const settledRss = settled ? await AkanAppHost.readProcessRssBytes(settled.pid) : null;
642
- const warned = /ceiling costs about one boot build per interval/.test(host.logs.join("").slice(start));
643
- //? Past the interval (a slow machine) the next report recycles instead of warning: either answer settles it.
644
- if ((settledRss ?? 0) >= CEILING_MB * MB && !warned)
645
- await host.waitForLogSince(
646
- settledFrom,
647
- /ceiling costs about one boot build per interval|recycling builder pid=\d+|skipped: the builder fell to/,
648
- WAIT_MS,
649
- );
638
+ //? Past the interval (a slow machine) the host arms a recycle instead, and answers once its settle hold ends.
639
+ if (armed.test(host.logs.join("").slice(settledFrom)))
640
+ await host.waitForLogSince(settledFrom, settleOutcome, WAIT_MS);
650
641
  expect(host.logs.join("").slice(start)).not.toMatch(/no longer enforcing it this session/);
651
642
  });
652
643
 
653
644
  budgetTest("serves a page requested while the builder is being replaced", async () => {
654
645
  const harness = await createHarness();
655
- const host = await harness.startHost({ timeoutMs: BOOT_MS, env: { AKAN_BUILDER_MAX_RSS_MB: String(CEILING_MB) } });
646
+ // Outside the app, whose watcher would take a write to the gate for a save.
647
+ const readyGate = path.join(await tempDir(), "ready");
648
+ await Bun.write(readyGate, "");
649
+ const host = await harness.startHost({
650
+ timeoutMs: BOOT_MS,
651
+ env: { AKAN_BUILDER_MAX_RSS_MB: String(CEILING_MB), AKAN_DEV_BUILDER_READY_GATE: readyGate },
652
+ });
656
653
  const port = await harness.resolvePort();
657
654
  await harness.waitForHttpText("initial-client-marker", WAIT_MS);
655
+ // Shut from here on: the replacement stays between its spawn and its ready until the gate opens again.
656
+ await rm(readyGate);
658
657
 
659
658
  const start = host.markLog();
660
659
  // One save both evicts the route's cached client entries and arms the recycle.
@@ -670,28 +669,35 @@ describe("dev resource budgets", () => {
670
669
  async (response) => ({ status: response.status, html: await response.text() }),
671
670
  );
672
671
 
673
- // Anchored on the spawn: the replacement's boot build leaves a wide, known window rather than a race.
674
672
  await host.waitForLogSince(start, /exiting for recycle/, WAIT_MS);
675
673
  await host.waitForLogSince(start, /builder spawned pid=\d+ .*restart=1/, WAIT_MS);
676
674
 
677
- const holdMark = host.markLog();
678
- const startedAtMono = performance.now();
679
675
  // Never requested before, so no route cache can answer it; it has to reach a builder that is not there yet.
680
- const res = await fetch(`http://127.0.0.1:${port}/second`, { signal: AbortSignal.timeout(WAIT_MS) });
681
- const html = await res.text();
682
- const heldMs = Math.round(performance.now() - startedAtMono);
683
-
676
+ const second = fetch(`http://127.0.0.1:${port}/second`, { signal: AbortSignal.timeout(WAIT_MS) }).then(
677
+ async (response) => ({ status: response.status, html: await response.text() }),
678
+ );
679
+ //? By route, not by order or count: the drain request's hold can land before or after this one's.
680
+ const holding = /holding build-route \S*\/second until the builder is ready/;
681
+ // With the gate shut, an answer before that hold is a refusal.
682
+ const answeredUnheld = await Promise.race([
683
+ host.waitForLogSince(start, holding, WAIT_MS).then(() => null),
684
+ second.then((response) => response.status),
685
+ ]);
686
+ expect(answeredUnheld).toBeNull();
687
+ await Bun.write(readyGate, "");
688
+ const held = await host.waitForLogSince(start, holding);
689
+ const ready = await host.waitForLogSince(start, /builder ready after restart/, WAIT_MS);
690
+ expect(ready.index ?? -1).toBeGreaterThan(held.index ?? Number.POSITIVE_INFINITY);
691
+
692
+ const res = await second;
684
693
  // Without the hold this is a 500 from the dev error page, which never retries on its own.
685
694
  expect(res.status).toBe(200);
686
- expect(html).toContain("marker-through-recycle");
687
- expect(html).not.toContain("reload after the builder is ready");
688
- // Proves the request reached the hold, rather than arriving after the replacement was already ready.
689
- expect(host.logs.join("").slice(holdMark)).toMatch(/holding build-route until the builder is ready/);
695
+ expect(res.html).toContain("marker-through-recycle");
696
+ expect(res.html).not.toContain("reload after the builder is ready");
690
697
 
691
698
  const drained = await drainRequest;
692
699
  expect(drained.status).toBe(200);
693
700
  expect(drained.html).toContain("marker-through-recycle");
694
- console.info(`[restart-guard] page held ${heldMs}ms across the recycle, then rendered`);
695
701
  });
696
702
 
697
703
  budgetTest("keeps a save's round trip inside its budget", async () => {
@@ -1,7 +1,7 @@
1
1
  import { afterEach, describe, expect, test } from "bun:test";
2
2
  import { mkdir, readdir, writeFile } from "node:fs/promises";
3
3
  import path from "node:path";
4
- import { tempDirs } from "../testHelpers";
4
+ import { tempDirs } from "../test/testHelpers";
5
5
  import { DevStabilityHarness } from "./devStabilityHarness.fixture";
6
6
 
7
7
  const servers: Bun.Server<undefined>[] = [];
@@ -0,0 +1,13 @@
1
+ import { Err } from "akanjs/common"; // @flag
2
+ import { Err as Aliased } from "akanjs/common"; // @flag
3
+ import { Err as Mixed, Logger } from "akanjs/common"; // @flag
4
+ import { type ErrPayload, Err as MixedWithType } from "akanjs/common"; // @flag
5
+ import { Err as SingleQuoted } from 'akanjs/common'; // @flag
6
+ import { Err as DeepWithExtension } from "akanjs/common/err.ts"; // @flag
7
+ import { Err as ThroughIndex } from "akanjs/common/index.ts"; // @flag
8
+ import {
9
+ hasErrKey,
10
+ Err as MultiLine, // @flag
11
+ } from "akanjs/common";
12
+ export { Err as Reexported } from "akanjs/common"; // @flag
13
+ export { Err as DeepReexported } from "akanjs/common/err.ts"; // @flag
@@ -0,0 +1,12 @@
1
+ import { Err } from "../dict"; // @ok
2
+ import { Err as ClientErr } from "@libs/shared/client"; // @ok
3
+ import { Err as AppErr } from "@apps/demo/client"; // @ok
4
+ import type { Err as TypeOnly } from "akanjs/common"; // @ok
5
+ import { type Err as InlineType, Logger } from "akanjs/common"; // @ok
6
+ import type { Err as DeepType } from "akanjs/common/err.ts"; // @ok
7
+ import { hasErrKey } from "akanjs/common"; // @ok
8
+ import type { ErrConstructor, ErrPayload } from "akanjs/common"; // @ok
9
+ import { Err as NearName } from "akanjs/common/hasErrKey.ts"; // @ok
10
+ export type { Err as ReexportedType } from "akanjs/common"; // @ok
11
+ export { Logger as Log } from "akanjs/common"; // @ok
12
+ export const quotesTheRule = 'import { Err } from "akanjs/common"'; // @ok
@@ -6,7 +6,7 @@ import path from "node:path";
6
6
  import { biomeBaseConfig } from "./biomeBase";
7
7
  import { Linter, parseBiomeReport } from "./linter";
8
8
 
9
- const devkitDir = import.meta.dir;
9
+ const devkitDir = path.resolve(import.meta.dir, "..");
10
10
  const [biome, ...biomeArgs] = Linter.biomeCommand(path.resolve(devkitDir, "../../.."));
11
11
 
12
12
  const hookProbe = `export const Early = ({ id }: { id?: string }) => {
@@ -4,7 +4,7 @@ import { existsSync } from "node:fs";
4
4
  import { mkdir, mkdtemp, readdir, readFile, rm, writeFile } from "node:fs/promises";
5
5
  import os from "node:os";
6
6
  import path from "node:path";
7
- import { Linter } from "../linter";
7
+ import { Linter } from "./linter";
8
8
 
9
9
  //? A rule that stops matching reports zero diagnostics, not an error, so a biome upgrade can retire one silently.
10
10
  //? Each rule runs alone against a config written here; the path scoping in biome.base.json is deliberately not tested.
@@ -1,8 +1,8 @@
1
1
  import { describe, expect, test } from "bun:test";
2
2
  import { tmpdir } from "node:os";
3
3
  import path from "node:path";
4
+ import { hasBiome } from "../test/testHelpers";
4
5
  import { type BiomeReport, Linter, parseBiomeReport } from "./linter";
5
- import { hasBiome } from "./testHelpers";
6
6
 
7
7
  const reportOf = (diagnostics: BiomeReport["diagnostics"]): string =>
8
8
  JSON.stringify({ summary: { errors: diagnostics?.length ?? 0, warnings: 0 }, diagnostics });
@@ -0,0 +1,31 @@
1
+ engine biome(1.0)
2
+ language js(typescript, jsx)
3
+
4
+ // `akanjs/common`'s `Err` takes any string, so a mistyped key compiles and `no-throw-raw-error`, which only knows a raw
5
+ // `Error`, passes it. The `Err` from an app's or lib's dict is the same class typed with that dictionary's keys.
6
+ //
7
+ // `import type` stays legal, to annotate a caught `Err`: a type cannot be constructed. A namespace import is not
8
+ // matched, since the rule cannot tell `common.Err` from the helpers such an import is for.
9
+ or {
10
+ or {
11
+ JsShorthandNamedImportSpecifier() as $specifier where { $specifier <: r"Err" },
12
+ JsNamedImportSpecifier() as $specifier where { $specifier <: r"Err\s+as\s[\s\S]*" }
13
+ } where {
14
+ $specifier <: within JsImport() as $statement,
15
+ not $statement <: r"import\s+type[\s\S]*"
16
+ },
17
+ JsExportNamedFromSpecifier() as $specifier where {
18
+ $specifier <: r"Err(?:\s+as\s[\s\S]*)?",
19
+ $specifier <: within JsExport() as $statement,
20
+ not $statement <: r"export\s+type[\s\S]*"
21
+ }
22
+ } where {
23
+ $statement <: contains JsModuleSource() as $source where {
24
+ $source <: r"[\x22']akanjs/common(?:/(?:err|index)(?:\.ts)?)?[\x22']"
25
+ },
26
+ register_diagnostic(
27
+ span = $specifier,
28
+ message = "Do not import `Err` from akanjs/common: it takes any string, so a mistyped key compiles. Import the typed `Err` from the app/lib dict on the server (import { Err } from '../dict') or from the package client entrypoint in UI ('@libs/<lib>/client', '@apps/<app>/client'), and register the key in that module's dictionary `.error({})`. `common/` and `env/` have no legal `Err`: keep throwing code out of them. Write 'import type' if only the type is needed.",
29
+ severity = "error"
30
+ )
31
+ }