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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (365) hide show
  1. package/CHANGELOG.md +369 -11
  2. package/DEV_RUNTIME_KNOBS.md +4 -3
  3. package/README.ko.md +3 -2
  4. package/README.md +4 -2
  5. package/akanApp/BackendImportGraph.test.ts +1 -1
  6. package/akanApp/akanApp.host.test.ts +257 -1
  7. package/akanApp/akanApp.host.ts +146 -1223
  8. package/akanApp/akanApp.host.wiring.test.ts +727 -0
  9. package/akanApp/builderGap.ts +68 -0
  10. package/akanApp/builderRequestRelay.test.ts +93 -0
  11. package/akanApp/builderRequestRelay.ts +100 -0
  12. package/akanApp/builderRssRecycler.ts +182 -0
  13. package/akanApp/devBackend.ts +392 -0
  14. package/akanApp/devBuildStatusBoard.ts +128 -0
  15. package/akanApp/devBuilder.ts +196 -0
  16. package/akanApp/devHostPolicy.test.ts +11 -11
  17. package/akanApp/devHostPolicy.ts +2 -4
  18. package/akanApp/devIdleSuspend.test.ts +221 -0
  19. package/akanApp/devIdleSuspend.ts +192 -0
  20. package/akanApp/devIdleSuspend.watcher.test.ts +120 -0
  21. package/akanApp/devRecycler.test.ts +66 -0
  22. package/akanApp/devRecycler.ts +305 -0
  23. package/akanApp/processRss.ts +61 -0
  24. package/akanConfig/akanConfig.test.ts +24 -1
  25. package/akanConfig/akanConfig.ts +10 -10
  26. package/akanConfig/akanWorkspaceConfig.ts +1 -1
  27. package/akanConfig/productionLockfile.ts +1 -1
  28. package/apiReport/apiDeclarationPrinter.ts +120 -0
  29. package/apiReport/apiReport.test.ts +526 -0
  30. package/apiReport/apiReport.ts +232 -0
  31. package/apiReport/apiReportDiff.ts +160 -0
  32. package/apiReport/apiReportPolicy.ts +65 -0
  33. package/apiReport/apiTargets.ts +311 -0
  34. package/apiReport/changesetBump.ts +19 -0
  35. package/{applicationBuildReporter.test.ts → app/applicationBuildReporter.test.ts} +21 -0
  36. package/{applicationBuildReporter.ts → app/applicationBuildReporter.ts} +10 -49
  37. package/{applicationBuildRunner.test.ts → app/applicationBuildRunner.test.ts} +74 -7
  38. package/{applicationBuildRunner.ts → app/applicationBuildRunner.ts} +20 -15
  39. package/{applicationTestPreload.ts → app/applicationTestPreload.ts} +1 -1
  40. package/{routeJsBudget.test.ts → app/routeJsBudget.test.ts} +48 -12
  41. package/{routeJsBudget.ts → app/routeJsBudget.ts} +90 -27
  42. package/{routeSourceValidator.test.ts → app/routeSourceValidator.test.ts} +17 -0
  43. package/{routeSourceValidator.ts → app/routeSourceValidator.ts} +5 -1
  44. package/artifact/implicitRootLayout.test.ts +71 -3
  45. package/artifact/implicitRootLayout.ts +21 -4
  46. package/artifact/implicitRootLayoutRender.test.tsx +297 -0
  47. package/biome.base.json +2 -1
  48. package/cloud/cloudApi.test.ts +1 -1
  49. package/cloud/configLock.test.ts +1 -1
  50. package/cloud/globalConfig.test.ts +1 -1
  51. package/cloud/globalConfig.ts +1 -1
  52. package/cloud/updatePackUpload.test.ts +1 -1
  53. package/codeAgent/agent/AkanCodeEnv.ts +1 -1
  54. package/codeAgent/agent/akanCodePaths.ts +1 -1
  55. package/codeAgent/agent/akanSystemPrompt.ts +1 -1
  56. package/codeAgent/agent/codeAgent.test.ts +1 -1
  57. package/codeAgent/skills/akan-debug/SKILL.md +10 -3
  58. package/codeAgent/skills/akan-err/SKILL.md +7 -0
  59. package/codeAgent/skills/akan-mcp/SKILL.md +17 -2
  60. package/codeAgent/skills/akan-scaffold/SKILL.md +2 -2
  61. package/codeAgent/skills/akan-transport/SKILL.md +2 -0
  62. package/codeAgent/skills/akan-validate/SKILL.md +1 -0
  63. package/codeAgent/tools/AkanCli.ts +1 -1
  64. package/codeAgent/tools/AkanToolPack.ts +1 -1
  65. package/codeAgent/tools/McpClient.ts +28 -6
  66. package/codeAgent/tools/McpToolPack.ts +1 -1
  67. package/codeAgent/tools/akanCodePlugins.test.ts +14 -2
  68. package/commandDecorators/argMeta.ts +4 -0
  69. package/commandDecorators/cliError.ts +72 -0
  70. package/commandDecorators/command.ts +165 -91
  71. package/commandDecorators/commandBuilder.ts +1 -1
  72. package/commandDecorators/commandDecorators.test.ts +191 -16
  73. package/commandDecorators/exitCodeError.ts +6 -7
  74. package/commandDecorators/index.ts +1 -0
  75. package/commandDecorators/targetMeta.ts +1 -0
  76. package/commandDecorators/workspaceVersionCheck.test.ts +1 -1
  77. package/commandDecorators/workspaceVersionCheck.ts +1 -1
  78. package/context/akanContext.ts +576 -0
  79. package/context/akanContextInspection.ts +296 -0
  80. package/{akanMcpContract.test.ts → context/akanMcpContract.test.ts} +1 -1
  81. package/{akanMcpContract.ts → context/akanMcpContract.ts} +32 -262
  82. package/context/akanMcpToolError.ts +16 -0
  83. package/context/doctor/agentGuideCheck.ts +81 -0
  84. package/context/doctor/configLeftoverCheck.ts +35 -0
  85. package/context/doctor/doctorFindings.ts +70 -0
  86. package/context/doctor/generatedFreshness.ts +56 -0
  87. package/context/doctor/moduleShapeCheck.ts +88 -0
  88. package/context/doctor/recipeDuplicateCheck.ts +39 -0
  89. package/context/doctor/recipeIndexCheck.ts +87 -0
  90. package/context/doctor/rootShapeCheck.ts +55 -0
  91. package/context/doctor/workflowScope.ts +97 -0
  92. package/{constantFieldNames.test.ts → context/moduleFieldNames.test.ts} +24 -2
  93. package/context/moduleFieldNames.ts +25 -0
  94. package/{recipeScanner.test.ts → context/recipeScanner.test.ts} +1 -1
  95. package/context/safeRead.ts +9 -0
  96. package/csrE2e/csrE2eHarness.fixture.ts +1 -1
  97. package/devkitUtils.test.ts +39 -5
  98. package/{apiReference.test.ts → docs/apiReference.test.ts} +4 -4
  99. package/{apiReference.ts → docs/apiReference.ts} +2 -2
  100. package/docs/errorCodeReference.test.ts +282 -0
  101. package/docs/errorCodeReference.ts +71 -0
  102. package/docs/errorCodeScan.ts +551 -0
  103. package/{frameworkGraph.test.ts → docs/frameworkGraph.test.ts} +1 -1
  104. package/executors/appExecutor.ts +448 -0
  105. package/executors/commandExecutionError.ts +53 -0
  106. package/executors/executor.ts +527 -0
  107. package/{executors.linkFallback.test.ts → executors/executors.linkFallback.test.ts} +1 -1
  108. package/{executors.test.ts → executors/executors.test.ts} +76 -15
  109. package/executors/index.ts +8 -0
  110. package/executors/libExecutor.ts +23 -0
  111. package/executors/moduleExecutor.ts +18 -0
  112. package/executors/pkgExecutor.ts +129 -0
  113. package/executors/sysExecutor.ts +301 -0
  114. package/executors/workspaceExecutor.ts +277 -0
  115. package/frontendBuild/allRoutesBuilder.test.ts +17 -5
  116. package/frontendBuild/allRoutesBuilder.ts +24 -6
  117. package/frontendBuild/autoImportSync.test.ts +1 -1
  118. package/frontendBuild/autoImportSync.ts +1 -1
  119. package/frontendBuild/buildRouteClient.test.ts +1 -1
  120. package/frontendBuild/bundleDefine.ts +2 -0
  121. package/frontendBuild/clientBuildTypes.ts +5 -2
  122. package/frontendBuild/clientEntriesBundler.test.ts +1 -1
  123. package/frontendBuild/clientEntryDiscovery.test.ts +28 -0
  124. package/frontendBuild/clientEntryDiscovery.ts +25 -6
  125. package/frontendBuild/csrArtifactBuilder.test.ts +1 -1
  126. package/frontendBuild/csrDevArtifactWriter.ts +1 -1
  127. package/frontendBuild/cssCompiler.test.ts +1 -1
  128. package/frontendBuild/devGeneratedIndexSync.test.ts +1 -1
  129. package/frontendBuild/devGeneratedIndexSync.ts +7 -38
  130. package/frontendBuild/dictionaryAssetBuilder.test.ts +1 -1
  131. package/frontendBuild/fontOptimizer.test.ts +1 -1
  132. package/frontendBuild/fontPruner.test.ts +1 -1
  133. package/frontendBuild/frontendBuild.test.ts +3 -3
  134. package/frontendBuild/hmrWatcher.stop.test.ts +63 -0
  135. package/frontendBuild/hmrWatcher.test.ts +1 -1
  136. package/frontendBuild/hmrWatcher.ts +22 -1
  137. package/frontendBuild/mcpAppViewBuilder.test.ts +1 -1
  138. package/frontendBuild/mcpAppViewBuilder.ts +1 -1
  139. package/frontendBuild/nativeCore.test.ts +148 -0
  140. package/frontendBuild/optionalPeers.test.ts +36 -8
  141. package/frontendBuild/pagesBundleBuilder.test.ts +2 -3
  142. package/frontendBuild/pagesBundleBuilder.ts +1 -1
  143. package/frontendBuild/precompressArtifacts.test.ts +1 -1
  144. package/frontendBuild/precompressArtifacts.ts +1 -1
  145. package/frontendBuild/serverGraphFile.ts +1 -1
  146. package/frontendBuild/sourceMtimeIndex.test.ts +1 -1
  147. package/frontendBuild/ssrBaseArtifactBuilder.test.ts +26 -0
  148. package/frontendBuild/ssrBaseArtifactBuilder.ts +23 -19
  149. package/frontendBuild/ssrDevBundler.test.ts +1 -1
  150. package/frontendBuild/vendorImportScanner.test.ts +25 -4
  151. package/frontendBuild/vendorImportScanner.ts +25 -10
  152. package/frontendBuild/vendorNarrowing.test.ts +1 -1
  153. package/frontendBuild/watchRootResolver.test.ts +1 -1
  154. package/{agentAssets.test.ts → guideline/agentAssets.test.ts} +1 -1
  155. package/{agentAssets.ts → guideline/agentAssets.ts} +2 -2
  156. package/{agentsIndex.test.ts → guideline/agentsIndex.test.ts} +2 -2
  157. package/{agentsIndex.ts → guideline/agentsIndex.ts} +13 -10
  158. package/{conventionSet.test.ts → guideline/conventionSet.test.ts} +7 -4
  159. package/{conventionSet.ts → guideline/conventionSet.ts} +1 -1
  160. package/{prompter.ts → guideline/prompter.ts} +2 -3
  161. package/incrementalBuilder/buildBatch.proc.ts +14 -4
  162. package/incrementalBuilder/buildBatchProtocol.ts +2 -0
  163. package/incrementalBuilder/buildBatchRunner.test.ts +108 -1
  164. package/incrementalBuilder/buildBatchRunner.ts +17 -4
  165. package/incrementalBuilder/builderBoot.ts +106 -0
  166. package/incrementalBuilder/builderBuildStatus.ts +23 -0
  167. package/incrementalBuilder/builderChannel.test.ts +1 -1
  168. package/incrementalBuilder/builderChannel.ts +11 -0
  169. package/incrementalBuilder/builderGraphPayloads.ts +3 -3
  170. package/incrementalBuilder/builderLanes.ts +157 -0
  171. package/incrementalBuilder/builderWatch.ts +213 -0
  172. package/incrementalBuilder/csrRegistry.ts +234 -0
  173. package/incrementalBuilder/incrementalBuilder.host.test.ts +30 -1
  174. package/incrementalBuilder/incrementalBuilder.host.ts +10 -22
  175. package/incrementalBuilder/incrementalBuilder.proc.test.ts +93 -2
  176. package/incrementalBuilder/incrementalBuilder.proc.ts +81 -823
  177. package/incrementalBuilder/ssrRegistry.ts +278 -0
  178. package/index.ts +22 -22
  179. package/integration/devStability.integration.test.ts +62 -56
  180. package/integration/devStabilityHarness.test.ts +1 -1
  181. package/lint/__fixtures__/no-import-common-err/bad.tsx +13 -0
  182. package/lint/__fixtures__/no-import-common-err/good.tsx +12 -0
  183. package/{biomeBase.test.ts → lint/biomeBase.test.ts} +1 -1
  184. package/lint/gritRules.test.ts +1 -1
  185. package/{linter.test.ts → lint/linter.test.ts} +1 -1
  186. package/lint/no-import-common-err.grit +31 -0
  187. package/lint/no-init-fetch-in-client.grit +1 -1
  188. package/lint/no-web-only-api-outside-webkit.grit +3 -3
  189. package/mobile/desktopBin.test.ts +1 -1
  190. package/mobile/desktopRelease.test.ts +1 -1
  191. package/mobile/desktopServerStage.test.ts +2 -2
  192. package/mobile/desktopServerStage.ts +1 -1
  193. package/mobile/nativeApi.test.ts +1 -1
  194. package/mobile/nativeApp.test.ts +1 -1
  195. package/mobile/nativeConfig.test.ts +1 -1
  196. package/mobile/nativePluginFolders.test.ts +1 -1
  197. package/mobile/nativePublicEnv.test.ts +1 -1
  198. package/mobile/nativeWebDir.test.ts +1 -1
  199. package/mobile/serverBundleSecrets.test.ts +1 -1
  200. package/mobile/tarWriter.test.ts +1 -1
  201. package/mobile/updatePackFolder.test.ts +1 -1
  202. package/package.json +167 -3
  203. package/packageExports.test.ts +20 -2
  204. package/piDependencyPins.test.ts +1 -1
  205. package/pipeline/PipelineDefinition.ts +1 -1
  206. package/platformTest/IdleWatchedProcess.test.ts +1 -1
  207. package/platformTest/PlatformTestRun.test.ts +1 -1
  208. package/platformTest/TestSnapshot.test.ts +1 -1
  209. package/preview/PreviewView.ts +32 -13
  210. package/preview/previewView.test.ts +33 -3
  211. package/{abstractDoc.test.ts → quality/abstractDoc.test.ts} +2 -2
  212. package/{abstractDoc.ts → quality/abstractDoc.ts} +1 -1
  213. package/quality/bareErrorScanner.ts +126 -0
  214. package/{maintainabilityBaseline.test.ts → quality/maintainabilityBaseline.test.ts} +73 -0
  215. package/{maintainabilityBaseline.ts → quality/maintainabilityBaseline.ts} +97 -9
  216. package/{maintainabilityContract.test.ts → quality/maintainabilityContract.test.ts} +383 -2
  217. package/{maintainabilityContract.ts → quality/maintainabilityContract.ts} +151 -29
  218. package/{maintainabilityExceptionScanner.test.ts → quality/maintainabilityExceptionScanner.test.ts} +15 -1
  219. package/{maintainabilityExceptionScanner.ts → quality/maintainabilityExceptionScanner.ts} +5 -1
  220. package/{maintainabilityLimits.ts → quality/maintainabilityLimits.ts} +12 -0
  221. package/{maintainabilityReport.ts → quality/maintainabilityReport.ts} +20 -3
  222. package/{qualityScanner.test.ts → quality/qualityScanner.test.ts} +1 -1
  223. package/{qualityScanner.ts → quality/qualityScanner.ts} +8 -8
  224. package/{storeAccessScanner.ts → quality/storeAccessScanner.ts} +15 -2
  225. package/{subspace.test.ts → subspace/subspace.test.ts} +25 -4
  226. package/{subspace.ts → subspace/subspace.ts} +5 -5
  227. package/{subspaceClone.ts → subspace/subspaceClone.ts} +8 -8
  228. package/{subspaceConfig.ts → subspace/subspaceConfig.ts} +5 -1
  229. package/{testHelpers.ts → test/testHelpers.ts} +37 -1
  230. package/transforms/barrelAnalyzer.ts +31 -10
  231. package/transforms/browserDirnamePlugin.test.ts +1 -1
  232. package/transforms/externalizeFrameworkPlugin.test.ts +1 -1
  233. package/transforms/mcpAppPageTrimmer.test.ts +1 -1
  234. package/transforms/pureLazyMarker.test.ts +1 -1
  235. package/transforms/serverEnvPlugin.test.ts +1 -1
  236. package/transforms/serverEnvProfile.test.ts +1 -1
  237. package/transforms/sideEffectImportOrder.test.ts +1 -1
  238. package/transforms/transforms.test.ts +52 -2
  239. package/transforms/tsconfigPackageResolver.test.ts +1 -1
  240. package/{createTunnel.test.ts → tunnel/createTunnel.test.ts} +1 -1
  241. package/{createTunnel.ts → tunnel/createTunnel.ts} +2 -2
  242. package/{sshHostKeys.ts → tunnel/sshHostKeys.ts} +2 -2
  243. package/typecheck/projectTypecheck.test.ts +1 -1
  244. package/typecheck/projectTypecheck.ts +6 -2
  245. package/{typeChecker.test.ts → typecheck/typeChecker.test.ts} +1 -1
  246. package/{typeChecker.ts → typecheck/typeChecker.ts} +1 -1
  247. package/typecheck/typecheck.proc.ts +4 -3
  248. package/typecheck/typecheckFailure.ts +7 -2
  249. package/util/errorReport.ts +66 -0
  250. package/{jsonFormatter.test.ts → util/jsonFormatter.test.ts} +1 -1
  251. package/workflow/artifacts.ts +8 -7
  252. package/workflow/constantSource.ts +187 -0
  253. package/workflow/dictionarySource.ts +184 -0
  254. package/workflow/executor.ts +6 -9
  255. package/workflow/fieldExpression.ts +153 -0
  256. package/workflow/fieldLabel.ts +61 -0
  257. package/workflow/fieldOrder.ts +117 -0
  258. package/workflow/fieldType.ts +93 -0
  259. package/workflow/guardCatalog.test.ts +1 -1
  260. package/workflow/index.ts +1 -0
  261. package/workflow/keyRename.ts +1 -1
  262. package/workflow/moduleIndex.test.ts +2 -2
  263. package/workflow/moduleIndex.ts +2 -2
  264. package/workflow/modulePaths.ts +27 -0
  265. package/workflow/mutationScaffold.ts +7 -15
  266. package/workflow/mutationSource.ts +2 -1
  267. package/workflow/plainName.ts +16 -3
  268. package/workflow/plan.ts +14 -2
  269. package/workflow/primitiveReport.ts +78 -0
  270. package/workflow/rolloutGate.test.ts +1 -1
  271. package/workflow/rolloutGate.ts +1 -1
  272. package/workflow/serviceSource.ts +33 -0
  273. package/workflow/signalSource.ts +96 -0
  274. package/workflow/source.ts +50 -1105
  275. package/workflow/sourceAst.ts +30 -0
  276. package/workflow/sourceImports.ts +105 -0
  277. package/workflow/sourceText.ts +13 -0
  278. package/workflow/templateSource.ts +30 -0
  279. package/workflow/testSource.ts +31 -0
  280. package/workflow/types.ts +1 -1
  281. package/workflow/uiPolicy.ts +1 -1
  282. package/{appSelectionMemory.ts → workspace/appSelectionMemory.ts} +1 -1
  283. package/{codegenLock.test.ts → workspace/codegenLock.test.ts} +1 -1
  284. package/{dependencyScanner.test.ts → workspace/dependencyScanner.test.ts} +1 -1
  285. package/{dependencyScanner.ts → workspace/dependencyScanner.ts} +2 -2
  286. package/{envSeed.test.ts → workspace/envSeed.test.ts} +2 -2
  287. package/{envSeed.ts → workspace/envSeed.ts} +1 -1
  288. package/{libSource.test.ts → workspace/libSource.test.ts} +2 -2
  289. package/{libSource.ts → workspace/libSource.ts} +1 -1
  290. package/{scanInfo.ts → workspace/scanInfo.ts} +21 -10
  291. package/{slicePlanner.test.ts → workspace/slicePlanner.test.ts} +2 -2
  292. package/{slicePlanner.ts → workspace/slicePlanner.ts} +1 -1
  293. package/{workspaceGraph.test.ts → workspace/workspaceGraph.test.ts} +1 -1
  294. package/{workspaceGraph.ts → workspace/workspaceGraph.ts} +1 -1
  295. package/{workspaceLayout.test.ts → workspace/workspaceLayout.test.ts} +1 -1
  296. package/{workspaceLayout.ts → workspace/workspaceLayout.ts} +3 -1
  297. package/akanContext.ts +0 -1084
  298. package/constantFieldNames.ts +0 -18
  299. package/executors.ts +0 -1749
  300. /package/{recipeScanner.ts → context/recipeScanner.ts} +0 -0
  301. /package/{declarationReader.ts → docs/declarationReader.ts} +0 -0
  302. /package/{frameworkGraph.ts → docs/frameworkGraph.ts} +0 -0
  303. /package/{biomeBase.ts → lint/biomeBase.ts} +0 -0
  304. /package/{linter.ts → lint/linter.ts} +0 -0
  305. /package/{commentDensityScanner.test.ts → quality/commentDensityScanner.test.ts} +0 -0
  306. /package/{commentDensityScanner.ts → quality/commentDensityScanner.ts} +0 -0
  307. /package/{componentSizeScanner.test.ts → quality/componentSizeScanner.test.ts} +0 -0
  308. /package/{componentSizeScanner.ts → quality/componentSizeScanner.ts} +0 -0
  309. /package/{componentWriteChainScanner.test.ts → quality/componentWriteChainScanner.test.ts} +0 -0
  310. /package/{componentWriteChainScanner.ts → quality/componentWriteChainScanner.ts} +0 -0
  311. /package/{deprecatedCommentScanner.test.ts → quality/deprecatedCommentScanner.test.ts} +0 -0
  312. /package/{deprecatedCommentScanner.ts → quality/deprecatedCommentScanner.ts} +0 -0
  313. /package/{endpointReach.test.ts → quality/endpointReach.test.ts} +0 -0
  314. /package/{endpointReach.ts → quality/endpointReach.ts} +0 -0
  315. /package/{formSetterScanner.test.ts → quality/formSetterScanner.test.ts} +0 -0
  316. /package/{formSetterScanner.ts → quality/formSetterScanner.ts} +0 -0
  317. /package/{kindBranchScanner.test.ts → quality/kindBranchScanner.test.ts} +0 -0
  318. /package/{kindBranchScanner.ts → quality/kindBranchScanner.ts} +0 -0
  319. /package/{maintainabilityReport.test.ts → quality/maintainabilityReport.test.ts} +0 -0
  320. /package/{renderMutationScanner.test.ts → quality/renderMutationScanner.test.ts} +0 -0
  321. /package/{renderMutationScanner.ts → quality/renderMutationScanner.ts} +0 -0
  322. /package/{serviceLoopCallScanner.test.ts → quality/serviceLoopCallScanner.test.ts} +0 -0
  323. /package/{serviceLoopCallScanner.ts → quality/serviceLoopCallScanner.ts} +0 -0
  324. /package/{signalMutationIndex.test.ts → quality/signalMutationIndex.test.ts} +0 -0
  325. /package/{signalMutationIndex.ts → quality/signalMutationIndex.ts} +0 -0
  326. /package/{sourceComments.test.ts → quality/sourceComments.test.ts} +0 -0
  327. /package/{sourceComments.ts → quality/sourceComments.ts} +0 -0
  328. /package/{ssrScanner.test.ts → quality/ssrScanner.test.ts} +0 -0
  329. /package/{ssrScanner.ts → quality/ssrScanner.ts} +0 -0
  330. /package/{storeAccessScanner.test.ts → quality/storeAccessScanner.test.ts} +0 -0
  331. /package/{storeSource.ts → quality/storeSource.ts} +0 -0
  332. /package/{storeWriteScanner.test.ts → quality/storeWriteScanner.test.ts} +0 -0
  333. /package/{storeWriteScanner.ts → quality/storeWriteScanner.ts} +0 -0
  334. /package/{structureScanner.test.ts → quality/structureScanner.test.ts} +0 -0
  335. /package/{structureScanner.ts → quality/structureScanner.ts} +0 -0
  336. /package/{testOnlyExportScanner.test.ts → quality/testOnlyExportScanner.test.ts} +0 -0
  337. /package/{testOnlyExportScanner.ts → quality/testOnlyExportScanner.ts} +0 -0
  338. /package/{writePath.test.ts → quality/writePath.test.ts} +0 -0
  339. /package/{writePath.ts → quality/writePath.ts} +0 -0
  340. /package/{writePlacementScanner.test.ts → quality/writePlacementScanner.test.ts} +0 -0
  341. /package/{writePlacementScanner.ts → quality/writePlacementScanner.ts} +0 -0
  342. /package/{writingActionIndex.test.ts → quality/writingActionIndex.test.ts} +0 -0
  343. /package/{writingActionIndex.ts → quality/writingActionIndex.ts} +0 -0
  344. /package/{subspaceReport.ts → subspace/subspaceReport.ts} +0 -0
  345. /package/{sshTunnel.ts → tunnel/sshTunnel.ts} +0 -0
  346. /package/{fileEditor.ts → util/fileEditor.ts} +0 -0
  347. /package/{fileSys.test.ts → util/fileSys.test.ts} +0 -0
  348. /package/{fileSys.ts → util/fileSys.ts} +0 -0
  349. /package/{jsonFormatter.ts → util/jsonFormatter.ts} +0 -0
  350. /package/{selectModel.ts → util/selectModel.ts} +0 -0
  351. /package/{semver.test.ts → util/semver.test.ts} +0 -0
  352. /package/{semver.ts → util/semver.ts} +0 -0
  353. /package/{shellOnlyEnv.test.ts → util/shellOnlyEnv.test.ts} +0 -0
  354. /package/{shellOnlyEnv.ts → util/shellOnlyEnv.ts} +0 -0
  355. /package/{spinner.test.ts → util/spinner.test.ts} +0 -0
  356. /package/{spinner.ts → util/spinner.ts} +0 -0
  357. /package/{stripAnsi.ts → util/stripAnsi.ts} +0 -0
  358. /package/{codegenLock.ts → workspace/codegenLock.ts} +0 -0
  359. /package/{getRelatedCnsts.ts → workspace/getRelatedCnsts.ts} +0 -0
  360. /package/{gitRevision.test.ts → workspace/gitRevision.test.ts} +0 -0
  361. /package/{gitRevision.ts → workspace/gitRevision.ts} +0 -0
  362. /package/{manifestDependencies.ts → workspace/manifestDependencies.ts} +0 -0
  363. /package/{packageExportsMap.ts → workspace/packageExportsMap.ts} +0 -0
  364. /package/{repoIdentity.ts → workspace/repoIdentity.ts} +0 -0
  365. /package/{types.ts → workspace/types.ts} +0 -0
@@ -0,0 +1,120 @@
1
+ import { afterEach, beforeEach, expect, mock, test } from "bun:test";
2
+ import path from "node:path";
3
+ import type { Logger } from "akanjs/common";
4
+ import type { ChangeBatch } from "akanjs/server";
5
+ import type { App } from "../commandDecorators";
6
+ import { heldMtimeIndex, saveUntil, tempDirs, writeText } from "../test/testHelpers";
7
+
8
+ const held = heldMtimeIndex();
9
+ let root = "";
10
+ mock.module("../frontendBuild/sourceMtimeIndex", () => ({ SourceMtimeIndex: held.SourceMtimeIndex }));
11
+ mock.module("../frontendBuild/watchRootResolver", () => ({
12
+ WatchRootResolver: class {
13
+ async resolve() {
14
+ return [root];
15
+ }
16
+ },
17
+ }));
18
+
19
+ const { DevIdleSuspend } = await import("./devIdleSuspend");
20
+
21
+ const logger = {
22
+ info: () => undefined,
23
+ verbose: () => undefined,
24
+ warn: () => undefined,
25
+ error: () => undefined,
26
+ } as unknown as Logger;
27
+ const tick = (ms = 0) => new Promise((resolve) => setTimeout(resolve, ms));
28
+ const makeRoot = tempDirs("akan-idle-suspend-watcher-");
29
+
30
+ let previous: string | undefined;
31
+ beforeEach(() => {
32
+ held.primes.length = 0;
33
+ held.scans.length = 0;
34
+ previous = process.env.AKAN_DEV_IDLE_SUSPEND_MS;
35
+ process.env.AKAN_DEV_IDLE_SUSPEND_MS = "5";
36
+ });
37
+ afterEach(() => {
38
+ if (previous === undefined) delete process.env.AKAN_DEV_IDLE_SUSPEND_MS;
39
+ else process.env.AKAN_DEV_IDLE_SUSPEND_MS = previous;
40
+ });
41
+
42
+ test("a save while the idle watcher primes stays with the awake builder, and the next wake does not replay it", async () => {
43
+ root = await makeRoot();
44
+ const source = path.join(root, "lib/a.ts");
45
+ await writeText(source, "export const x = 0;\n");
46
+ let released = 0;
47
+ const wokenWith: (ChangeBatch | null)[] = [];
48
+ const idle = new DevIdleSuspend(
49
+ {} as App,
50
+ { logger },
51
+ {
52
+ readiness: () => ({ builderReady: true, backendReady: true, buildFailed: false, restartPending: false }),
53
+ release: () => {
54
+ released++;
55
+ },
56
+ wake: async (batch) => {
57
+ wokenWith.push(batch);
58
+ },
59
+ wakeFailed: () => undefined,
60
+ flushHeld: () => undefined,
61
+ awake: () => undefined,
62
+ },
63
+ );
64
+ idle.arm();
65
+ expect(await saveUntil(source, () => held.scans.length > 0)).toBe(true);
66
+ idle.markActivity();
67
+ held.primes[0].resolve();
68
+ await tick();
69
+ expect(released).toBe(0);
70
+ held.scans[0].resolve([]);
71
+ await tick(20);
72
+ expect(held.primes).toHaveLength(2);
73
+ held.primes[1].resolve();
74
+ await tick();
75
+ expect(released).toBe(1);
76
+ const woken = idle.wake("a route request");
77
+ await tick();
78
+ held.scans[1].resolve([]);
79
+ await woken;
80
+ expect(wokenWith).toEqual([null]);
81
+ idle.stop();
82
+ }, 15_000);
83
+
84
+ test("a config save found by the scan a wake interrupts reaches that wake", async () => {
85
+ root = await makeRoot();
86
+ const source = path.join(root, "lib/a.ts");
87
+ const config = path.join(root, "akan.config.ts");
88
+ await writeText(source, "export const x = 0;\n");
89
+ let released = 0;
90
+ const wokenWith: (ChangeBatch | null)[] = [];
91
+ const idle = new DevIdleSuspend(
92
+ {} as App,
93
+ { logger },
94
+ {
95
+ readiness: () => ({ builderReady: true, backendReady: true, buildFailed: false, restartPending: false }),
96
+ release: () => {
97
+ released++;
98
+ },
99
+ wake: async (batch) => {
100
+ wokenWith.push(batch);
101
+ },
102
+ wakeFailed: () => undefined,
103
+ flushHeld: () => undefined,
104
+ awake: () => undefined,
105
+ },
106
+ );
107
+ idle.arm();
108
+ while (held.primes.length === 0) await tick(5);
109
+ held.primes[0].resolve();
110
+ await tick();
111
+ expect(released).toBe(1);
112
+ expect(await saveUntil(source, () => held.scans.length > 0)).toBe(true);
113
+ const woken = idle.wake("a route request");
114
+ held.scans[0].resolve([config]);
115
+ await tick();
116
+ held.scans[1]?.resolve([]);
117
+ await woken;
118
+ expect(wokenWith).toEqual([{ files: [config], kinds: new Set(["config"]) }]);
119
+ idle.stop();
120
+ }, 15_000);
@@ -0,0 +1,66 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import type { Logger } from "akanjs/common";
3
+ import type { BuilderMessage, DevBuildStatus } from "akanjs/server";
4
+ import type { App } from "../commandDecorators";
5
+ import type { BackendImportGraph } from "./BackendImportGraph";
6
+ import type { BuilderGap } from "./builderGap";
7
+ import type { BuilderRssRecycler } from "./builderRssRecycler";
8
+ import type { DevBackend } from "./devBackend";
9
+ import type { DevBuilder } from "./devBuilder";
10
+ import type { DevBuildStatusBoard } from "./devBuildStatusBoard";
11
+ import { DevRecycler } from "./devRecycler";
12
+
13
+ const logger = { verbose: () => undefined, warn: () => undefined, info: () => undefined } as unknown as Logger;
14
+
15
+ const restartBuilder = {
16
+ type: "invalidate",
17
+ kinds: ["code"],
18
+ files: ["/repo/libs/shared/common/foo.ts"],
19
+ generation: 7,
20
+ devPlan: {
21
+ generation: 7,
22
+ files: ["/repo/libs/shared/common/foo.ts"],
23
+ generatedFiles: [],
24
+ roles: ["shared"],
25
+ actions: ["restart-builder"],
26
+ reasonByFile: {},
27
+ },
28
+ } as unknown as Extract<BuilderMessage, { type: "invalidate" }>;
29
+
30
+ describe("DevRecycler", () => {
31
+ test("defers a builder restart while its generation's build is failing", async () => {
32
+ const recorded: DevBuildStatus[] = [];
33
+ const queued: DevBuildStatus[] = [];
34
+ const touched: string[] = [];
35
+ const recycler = new DevRecycler({} as App, {
36
+ env: {},
37
+ logger,
38
+ isStopping: () => false,
39
+ graph: {} as BackendImportGraph,
40
+ statuses: {
41
+ failedAt: (generation: number) => generation === 7,
42
+ record: (status: DevBuildStatus) => recorded.push(status),
43
+ } as unknown as DevBuildStatusBoard,
44
+ backend: {
45
+ sendOrQueueStatus: (status: DevBuildStatus) => queued.push(status),
46
+ send: () => touched.push("backend.send"),
47
+ scheduleRestart: () => touched.push("backend.scheduleRestart"),
48
+ stop: () => touched.push("backend.stop"),
49
+ } as unknown as DevBackend,
50
+ builder: {
51
+ stop: () => touched.push("builder.stop"),
52
+ start: () => touched.push("builder.start"),
53
+ } as unknown as DevBuilder,
54
+ gap: {} as BuilderGap,
55
+ rss: { rearm: () => undefined } as unknown as BuilderRssRecycler,
56
+ });
57
+
58
+ await recycler.handleInvalidate(restartBuilder);
59
+
60
+ expect(recycler.pending).toBe(true);
61
+ expect(touched).toEqual([]);
62
+ expect(recorded).toHaveLength(1);
63
+ expect(queued).toEqual(recorded);
64
+ expect(recorded[0]).toMatchObject({ generation: 7, phase: "scan", ok: false, files: restartBuilder.files });
65
+ });
66
+ });
@@ -0,0 +1,305 @@
1
+ import path from "node:path";
2
+ import type { Logger } from "akanjs/common";
3
+ import type { BuilderMessage, ChangeBatch, DevBuildStatus } from "akanjs/server";
4
+ import type { App } from "../commandDecorators";
5
+ import type { BackendImportGraph } from "./BackendImportGraph";
6
+ import type { BuilderGap } from "./builderGap";
7
+ import type { BuilderRssRecycler } from "./builderRssRecycler";
8
+ import type { DevBackend } from "./devBackend";
9
+ import type { BuilderRecoveryReason, DevBuilder } from "./devBuilder";
10
+ import type { DevBuildStatusBoard } from "./devBuildStatusBoard";
11
+ import {
12
+ backendRestartReasonFromMessage,
13
+ isLegacyBackendFallbackFile,
14
+ mergeInvalidateMessages,
15
+ shouldRefreshConfigOnIdleWake,
16
+ shouldRestartBackendByDevPlan,
17
+ shouldRestartBuilderByDevPlan,
18
+ shouldRestartDevHostByDevPlan,
19
+ } from "./devHostPolicy";
20
+
21
+ type InvalidateMessage = Extract<BuilderMessage, { type: "invalidate" }>;
22
+
23
+ export class DevRecycler {
24
+ readonly #app: App;
25
+ readonly #env: Record<string, string>;
26
+ readonly #logger: Logger;
27
+ readonly #isStopping: () => boolean;
28
+ readonly #graph: BackendImportGraph;
29
+ readonly #statuses: DevBuildStatusBoard;
30
+ readonly #backend: DevBackend;
31
+ readonly #builder: DevBuilder;
32
+ readonly #gap: BuilderGap;
33
+ readonly #rss: BuilderRssRecycler;
34
+ #pending: {
35
+ message: InvalidateMessage;
36
+ refreshConfig: boolean;
37
+ failed?: boolean;
38
+ failedGeneration?: number;
39
+ } | null = null;
40
+ //? A restart that failed after its change applied (the builder or backend did not come up): the builder's return is
41
+ //? its recovery, reported past the failure's generation so the scan overlay clears.
42
+ #restartFailedAfterApply: number | null = null;
43
+
44
+ constructor(
45
+ app: App,
46
+ parts: {
47
+ env: Record<string, string>;
48
+ logger: Logger;
49
+ isStopping: () => boolean;
50
+ graph: BackendImportGraph;
51
+ statuses: DevBuildStatusBoard;
52
+ backend: DevBackend;
53
+ builder: DevBuilder;
54
+ gap: BuilderGap;
55
+ rss: BuilderRssRecycler;
56
+ },
57
+ ) {
58
+ this.#app = app;
59
+ this.#env = parts.env;
60
+ this.#logger = parts.logger;
61
+ this.#isStopping = parts.isStopping;
62
+ this.#graph = parts.graph;
63
+ this.#statuses = parts.statuses;
64
+ this.#backend = parts.backend;
65
+ this.#builder = parts.builder;
66
+ this.#gap = parts.gap;
67
+ this.#rss = parts.rss;
68
+ }
69
+
70
+ get pending(): boolean {
71
+ return !!this.#pending;
72
+ }
73
+
74
+ drop(): void {
75
+ this.#pending = null;
76
+ }
77
+
78
+ async handleInvalidate(message: InvalidateMessage) {
79
+ this.#logDevPlan(message);
80
+ this.#rss.rearm();
81
+ // Checked first: a dev-host restart also recycles the builder and backend.
82
+ const wantsDevHostRestart = shouldRestartDevHostByDevPlan(message);
83
+ const pending = this.#pending;
84
+ // A deferred recycle resumes on the next code batch; a css-only batch cannot heal a compile error.
85
+ const resumes = !!pending && message.kinds.includes("code") && this.#touchesFailedRecycle(message.files);
86
+ if (wantsDevHostRestart || shouldRestartBuilderByDevPlan(message) || resumes) {
87
+ const refreshConfig = wantsDevHostRestart || (pending?.refreshConfig ?? false);
88
+ const merged = pending ? mergeInvalidateMessages(pending.message, message) : message;
89
+ const generation = message.devPlan?.generation ?? message.generation;
90
+ if (this.#statuses.failedAt(generation)) {
91
+ this.#defer(merged, { refreshConfig, generation });
92
+ return;
93
+ }
94
+ await this.apply(merged, refreshConfig);
95
+ return;
96
+ }
97
+ if (await this.#shouldRestartBackend(message)) {
98
+ this.#backend.scheduleRestart(backendRestartReasonFromMessage(message));
99
+ return;
100
+ }
101
+ this.#backend.send(message);
102
+ }
103
+
104
+ async apply(message: InvalidateMessage, refreshConfig: boolean): Promise<void> {
105
+ if (this.#isStopping()) return;
106
+ this.#pending = null;
107
+ const progress = { applied: !refreshConfig };
108
+ try {
109
+ if (refreshConfig) await this.#restartDevHost(message, progress);
110
+ else await this.#restartDevChildren(message);
111
+ } catch (err) {
112
+ const kind = refreshConfig ? "Config" : "Runtime metadata";
113
+ const generation = this.#recordRestartFailure(message, err, kind, { applied: progress.applied });
114
+ //? Kept only when the change itself did not apply: a builder that booted degraded (a broken akan.config.ts)
115
+ //? takes the fixing save itself and sends no invalidate, so without this the old config would keep running.
116
+ if (progress.applied) this.#restartFailedAfterApply = generation;
117
+ else this.#pending = { message, refreshConfig, failed: true, failedGeneration: generation };
118
+ this.#resurrectDevChildren(message);
119
+ }
120
+ }
121
+
122
+ //? The first green pages build after a failed restart that touches its change is the fix: the change applies then. A
123
+ //? cause no save fixes (an env value) waits for the next change of those files, not for every green save.
124
+ async resumeFailed(status: DevBuildStatus): Promise<void> {
125
+ const pending = this.#pending;
126
+ if (!pending?.failed || !status.ok || status.phase !== "pages" || !this.#touchesFailedRecycle(status.files)) return;
127
+ //? Newer than the failure: the batch that carried the change reports its own pages ok while the restart runs.
128
+ if (status.generation <= (pending.failedGeneration ?? -1)) return;
129
+ await this.apply(pending.message, pending.refreshConfig);
130
+ }
131
+
132
+ async applyIdleWake(batch: ChangeBatch | null): Promise<void> {
133
+ const files = batch?.files ?? [];
134
+ if (shouldRefreshConfigOnIdleWake(batch)) {
135
+ this.#logger.verbose("[idle-suspend] config changed while suspended; restarting the dev host");
136
+ // Replaces the backend too, and a baseline kept past its own gap costs a restart at the next one.
137
+ this.#gap.discard("config change replaces the backend anyway");
138
+ //? Through the same path as a save's: a failure is reported and stays pending, as one would be awake.
139
+ await this.apply({ type: "invalidate", kinds: [...(batch?.kinds ?? [])], files }, true);
140
+ return;
141
+ }
142
+ // Refresh before deciding: a file created while suspended is not in the graph yet.
143
+ if (files.length > 0) await this.#graph.refresh();
144
+ await this.#builder.start({ announceBootState: true });
145
+ // Merged: the watcher's batch and the stamps overlap on the ordinary one-save-during-suspend case.
146
+ const missed = await this.#gap.take();
147
+ const backendFiles = [...new Set([...files.filter((file) => this.#graph.has(file)), ...missed])];
148
+ if (backendFiles.length === 0) return;
149
+ this.#logger.verbose(`[idle-suspend] ${backendFiles.length} backend file(s) changed while suspended`);
150
+ this.#backend.scheduleRestart({ files: backendFiles, roles: [] });
151
+ }
152
+
153
+ builderRecovered(reason: BuilderRecoveryReason): void {
154
+ void this.#gap.restartBackendForChanges();
155
+ const failedAfterApply = this.#restartFailedAfterApply;
156
+ this.#restartFailedAfterApply = null;
157
+ const status: DevBuildStatus = {
158
+ generation:
159
+ failedAfterApply !== null
160
+ ? this.#statuses.nextBackendGeneration(failedAfterApply + 1)
161
+ : (reason.generation ?? this.#statuses.nextBackendGeneration()),
162
+ phase: "scan",
163
+ ok: true,
164
+ files: reason.files,
165
+ message: "Builder recovered",
166
+ };
167
+ this.#statuses.record(status);
168
+ this.#backend.sendOrQueueStatus(status);
169
+ if (!this.#backend.running && !this.#backend.recovering) {
170
+ this.#backend.start({ generation: reason.generation, files: reason.files });
171
+ }
172
+ }
173
+
174
+ #touchesFailedRecycle(files: string[]): boolean {
175
+ const pending = this.#pending;
176
+ if (!pending?.failed) return true;
177
+ const changed = new Set(pending.message.files);
178
+ return files.some((file) => changed.has(file));
179
+ }
180
+
181
+ #defer(message: InvalidateMessage, { refreshConfig, generation }: { refreshConfig: boolean; generation?: number }) {
182
+ this.#pending = { message, refreshConfig };
183
+ const kind = refreshConfig ? "Config" : "Runtime metadata";
184
+ this.#logger.warn(
185
+ `[dev-host] ${kind.toLowerCase()} restart deferred generation=${generation ?? "(unknown)"}; keeping the running dev server until the build error is fixed`,
186
+ );
187
+ const status: DevBuildStatus = {
188
+ generation: generation ?? this.#statuses.nextBackendGeneration(),
189
+ phase: "scan",
190
+ ok: false,
191
+ files: message.files,
192
+ message: `${kind} change is on hold while the build is failing; it will apply automatically once the error is fixed.`,
193
+ };
194
+ this.#statuses.record(status);
195
+ this.#backend.sendOrQueueStatus(status);
196
+ }
197
+
198
+ // The backend returns on the last-good artifact so the error overlay stays reachable.
199
+ #resurrectDevChildren(message: InvalidateMessage): void {
200
+ const generation = message.devPlan?.generation ?? message.generation;
201
+ if (!this.#backend.running) this.#backend.start({ generation, files: message.files });
202
+ this.#builder.scheduleRecovery({ generation, files: message.files });
203
+ }
204
+
205
+ async #restartDevChildren(message: InvalidateMessage): Promise<void> {
206
+ const generation = message.devPlan?.generation ?? message.generation;
207
+ this.#logger.warn(
208
+ `[dev-host] recycling builder/backend for runtime metadata generation=${generation ?? "(unknown)"} files=${message.files.length}`,
209
+ );
210
+ await this.#recycleDevChildren(message);
211
+ }
212
+
213
+ // The config is re-imported with a cache-busting query, but modules it imports stay cached: a change inside an
214
+ // imported plugin file still needs a manual `akan start` restart.
215
+ async #restartDevHost(message: InvalidateMessage, progress?: { applied: boolean }): Promise<void> {
216
+ const generation = message.devPlan?.generation ?? message.generation;
217
+ this.#logger.warn(
218
+ `[dev-host] config change detected; restarting dev host generation=${generation ?? "(unknown)"} files=${message.files.length}`,
219
+ );
220
+ await this.#recycleDevChildren(message, { refreshConfig: true, progress });
221
+ }
222
+
223
+ async #recycleDevChildren(
224
+ message: InvalidateMessage,
225
+ { refreshConfig = false, progress }: { refreshConfig?: boolean; progress?: { applied: boolean } } = {},
226
+ ): Promise<void> {
227
+ const generation = message.devPlan?.generation ?? message.generation;
228
+ this.#backend.cancelTimers();
229
+ this.#builder.cancelRecovery();
230
+ this.#builder.resetRecovery();
231
+ this.#backend.dropPendingRestart();
232
+ await this.#backend.restarting;
233
+ this.#statuses.reset();
234
+ this.#backend.dropQueuedStatuses();
235
+ await this.#backend.stop();
236
+ this.#builder.stop();
237
+ this.#builder.clearPatcherOff();
238
+ if (refreshConfig) {
239
+ await this.#app.getConfig({ refresh: true });
240
+ // Merge, not replace: `start()` added values prepare does not produce (REDIS_HOST from the tunnel).
241
+ const { env } = await this.#app.prepareCommand("start");
242
+ Object.assign(this.#env, env);
243
+ if (progress) progress.applied = true;
244
+ }
245
+ await this.#graph.refresh();
246
+ await this.#builder.start();
247
+ this.#backend.start({ generation, files: message.files });
248
+ }
249
+
250
+ #recordRestartFailure(
251
+ message: InvalidateMessage,
252
+ err: unknown,
253
+ kind: "Config" | "Runtime metadata",
254
+ { applied }: { applied: boolean },
255
+ ): number {
256
+ const generation = message.devPlan?.generation ?? message.generation ?? this.#statuses.nextBackendGeneration();
257
+ const detail = err instanceof Error ? err.message : String(err);
258
+ this.#logger.warn(`[dev-host] ${kind.toLowerCase()} restart failed generation=${generation}: ${detail}`);
259
+ const names = message.files.slice(0, 3).map((file) => path.basename(file));
260
+ const saved = names.length > 0 ? names.join(", ") : "the changed file";
261
+ const status: DevBuildStatus = {
262
+ generation,
263
+ phase: "scan",
264
+ ok: false,
265
+ files: message.files,
266
+ message: applied
267
+ ? `${kind} change applied, but the dev server failed to restart: ${detail}. It is recovering on its own.`
268
+ : `${kind} change failed to apply: ${detail}. The dev server keeps running on the previous ${kind.toLowerCase()}; once it is fixed, save ${saved} again or restart the dev server to apply it.`,
269
+ };
270
+ this.#statuses.record(status);
271
+ this.#backend.sendOrQueueStatus(status);
272
+ return generation;
273
+ }
274
+
275
+ #logDevPlan(message: InvalidateMessage): void {
276
+ if (!message.devPlan) return;
277
+ const { generation, roles, actions, reasonByFile } = message.devPlan;
278
+ this.#logger.verbose(
279
+ `[dev-plan] generation=${generation} roles=${roles.join(",") || "(none)"} actions=${actions.join(",") || "(none)"} reasons=${Object.keys(reasonByFile).length}`,
280
+ );
281
+ }
282
+
283
+ async #shouldRestartBackend(message: InvalidateMessage): Promise<boolean> {
284
+ if (message.kinds.length === 1 && message.kinds[0] === "css") return false;
285
+ if (message.devPlan) {
286
+ const shouldRestart = shouldRestartBackendByDevPlan(message) ?? false;
287
+ if (shouldRestart && message.kinds.includes("code")) await this.#graph.refresh();
288
+ return shouldRestart;
289
+ }
290
+ if (message.kinds.includes("code")) await this.#graph.refresh();
291
+ if (message.files.some((file) => this.#graph.has(file))) return true;
292
+ if (!this.#graph.lastRefreshSucceeded) {
293
+ const fallbackFiles = message.files.filter((file) =>
294
+ isLegacyBackendFallbackFile(file, this.#app.workspace.workspaceRoot),
295
+ );
296
+ if (fallbackFiles.length > 0) {
297
+ this.#logger.warn(
298
+ `[backend-graph] using path-role fallback for legacy invalidate; restart files=${fallbackFiles.length}`,
299
+ );
300
+ return true;
301
+ }
302
+ }
303
+ return false;
304
+ }
305
+ }
@@ -0,0 +1,61 @@
1
+ const PS_RSS_TIMEOUT_MS = 2_000;
2
+
3
+ export class ProcessRss {
4
+ static async bytesOf(pid: number): Promise<number | null> {
5
+ if (process.platform === "win32")
6
+ return await ProcessRss.#readRssKbVia(
7
+ ["tasklist", "/FI", `PID eq ${pid}`, "/FO", "CSV", "/NH"],
8
+ ProcessRss.#tasklistRssKb,
9
+ );
10
+ if (process.platform === "darwin") {
11
+ const footprintBytes = await ProcessRss.#readRssKbVia(
12
+ ["footprint", "-p", String(pid), "-f", "bytes"],
13
+ ProcessRss.#footprintKb,
14
+ );
15
+ if (footprintBytes !== null) return footprintBytes;
16
+ }
17
+ const status = await Bun.file(`/proc/${pid}/status`)
18
+ .text()
19
+ .catch(() => null);
20
+ const vmRssKb = status === null ? null : /VmRSS:\s+(\d+) kB/.exec(status)?.[1];
21
+ if (vmRssKb) return Number(vmRssKb) * 1024;
22
+ return await ProcessRss.#readRssKbVia(["ps", "-o", "rss=", "-p", String(pid)], (output) => Number(output.trim()));
23
+ }
24
+
25
+ // Bounded: a `ps` that hangs under load would silently cancel the recycle awaiting it.
26
+ static async #readRssKbVia(
27
+ command: string[],
28
+ parseKb: (output: string) => number,
29
+ timeoutMs = PS_RSS_TIMEOUT_MS,
30
+ ): Promise<number | null> {
31
+ let proc: Bun.Subprocess<"ignore", "pipe", "ignore">;
32
+ try {
33
+ proc = Bun.spawn(command, { stdio: ["ignore", "pipe", "ignore"] });
34
+ } catch {
35
+ return null;
36
+ }
37
+ const killer = setTimeout(() => proc.kill("SIGKILL"), timeoutMs);
38
+ try {
39
+ const output = await new Response(proc.stdout).text();
40
+ await proc.exited;
41
+ const rssKb = parseKb(output);
42
+ return Number.isFinite(rssKb) && rssKb > 0 ? rssKb * 1024 : null;
43
+ } catch {
44
+ return null;
45
+ } finally {
46
+ clearTimeout(killer);
47
+ }
48
+ }
49
+
50
+ // `Mem Usage` is the working set (what `process.memoryUsage.rss()` reports on Windows) in locale-grouped KB.
51
+ static #tasklistRssKb(output: string): number {
52
+ const memUsage = /"([^"]*)"\s*$/m.exec(output)?.[1];
53
+ return memUsage ? Number(memUsage.replace(/\D/g, "")) : Number.NaN;
54
+ }
55
+
56
+ // The footprint is what `process.memoryUsage.rss()` reports on macOS; `ps` also counts pages freed for reuse.
57
+ static #footprintKb(output: string): number {
58
+ const bytes = /Footprint: (\d+) B\b/.exec(output)?.[1];
59
+ return bytes ? Number(bytes) / 1024 : Number.NaN;
60
+ }
61
+ }
@@ -5,7 +5,7 @@ import path from "node:path";
5
5
  import { fileURLToPath } from "node:url";
6
6
  import { AppExecutor, WorkspaceExecutor } from "../executors";
7
7
  import { NativeConfig } from "../mobile/nativeConfig";
8
- import type { PackageJson } from "../types";
8
+ import type { PackageJson } from "../workspace/types";
9
9
  import { AkanAppConfig, AkanLibConfig, deriveDefaultAppId } from "./akanConfig";
10
10
  import type { LibConfigInput } from "./types";
11
11
 
@@ -1079,6 +1079,29 @@ describe("AkanAppConfig.importConfigModule", () => {
1079
1079
  });
1080
1080
  });
1081
1081
 
1082
+ describe("AkanAppConfig.from", () => {
1083
+ test("a busted reload re-reads an edited lib config", async () => {
1084
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), "akan-config-lib-bust-"));
1085
+ try {
1086
+ const libConfigPath = path.join(root, "libs/extlib/akan.config.ts");
1087
+ fs.mkdirSync(path.join(root, "apps/extapp"), { recursive: true });
1088
+ fs.mkdirSync(path.join(root, "libs/extlib"), { recursive: true });
1089
+ fs.writeFileSync(path.join(root, "apps/extapp/akan.config.ts"), "export default {};\n");
1090
+ fs.writeFileSync(libConfigPath, "export default { externalLibs: ['first'] };\n");
1091
+ fs.writeFileSync(path.join(root, "package.json"), JSON.stringify({ name: "extrepo", version: "1.0.0" }));
1092
+ fs.writeFileSync(path.join(root, ".env"), "AKAN_PUBLIC_REPO_NAME=extrepo\nAKAN_PUBLIC_SERVE_DOMAIN=ext.test\n");
1093
+ const workspace = WorkspaceExecutor.fromRoot({ workspaceRoot: root, repoName: "extrepo" });
1094
+ const app = AppExecutor.from(workspace, "extapp");
1095
+ expect((await AkanAppConfig.from(app)).externalLibs).toEqual(["first"]);
1096
+
1097
+ fs.writeFileSync(libConfigPath, "export default { externalLibs: ['second'] };\n");
1098
+ expect((await AkanAppConfig.from(app, { bustImportCache: true })).externalLibs).toEqual(["second"]);
1099
+ } finally {
1100
+ fs.rmSync(root, { recursive: true, force: true });
1101
+ }
1102
+ });
1103
+ });
1104
+
1082
1105
  describe("pipeline and workspace keys in app and lib configs", () => {
1083
1106
  test("an app's pipeline is dropped before the instance exists, so it never reaches akan.app.json", async () => {
1084
1107
  const config = await loadExtAppConfig(
@@ -7,9 +7,9 @@ import { type AkanI18nConfig, resolveAkanI18nConfig, trimSlashes } from "akanjs/
7
7
  import type { ServerPolicy } from "akanjs/native/api";
8
8
  import type { AkanImageConfig } from "akanjs/server";
9
9
  import type { App, Lib } from "../commandDecorators";
10
- import { LibExecutor, WorkspaceExecutor } from "../executors";
10
+ import { WorkspaceExecutor } from "../executors/workspaceExecutor";
11
11
  import { ServerEnvProfile } from "../transforms/serverEnvProfile";
12
- import type { BaseDevEnv, PackageJson } from "../types";
12
+ import type { BaseDevEnv, PackageJson } from "../workspace/types";
13
13
  import { AkanBin } from "./akanBin";
14
14
  import {
15
15
  type AkanApiConfig,
@@ -708,16 +708,16 @@ CMD [${command.map((c) => `"${c}"`).join(",")}]`;
708
708
  //* Every workspace lib is read, not just this app's lib deps: narrowing the set needs the dependency
709
709
  //* scan, and the incremental page rebundle re-reads this config on every file change.
710
710
  static async #collectLibContributions(app: App, libs: string[], bustImportCache: boolean): Promise<LibContributions> {
711
+ //? Imported on use: sysExecutor.ts imports this file, so a static import would load a SysExecutor subclass first.
712
+ const { LibExecutor } = await import("../executors/libExecutor");
711
713
  const libConfigs = await Promise.all(
712
714
  libs.map(async (libName) =>
713
- LibExecutor.from(app, libName)
714
- .getConfig({ refresh: bustImportCache })
715
- .catch((error: unknown) => {
716
- //? Skipping a refused lib config would build the image without its docker steps, and the build would pass.
717
- if (error instanceof LibConfigRefusal) throw error;
718
- app.logger.warn(`Skipped libs/${libName}/akan.config.ts contributions: ${String(error)}`);
719
- return null;
720
- }),
715
+ AkanLibConfig.from(LibExecutor.from(app, libName), { bustImportCache }).catch((error: unknown) => {
716
+ //? Skipping a refused lib config would build the image without its docker steps, and the build would pass.
717
+ if (error instanceof LibConfigRefusal) throw error;
718
+ app.logger.warn(`Skipped libs/${libName}/akan.config.ts contributions: ${String(error)}`);
719
+ return null;
720
+ }),
721
721
  ),
722
722
  );
723
723
  return {
@@ -1,7 +1,7 @@
1
1
  import path from "node:path";
2
2
  import type { SubspaceConfigInput, WorkspaceConfig, WorkspacePipelineConfig } from "akanjs";
3
3
  import type { WorkspaceExecutor } from "../executors";
4
- import { FileSys } from "../fileSys";
4
+ import { FileSys } from "../util/fileSys";
5
5
  import { AkanAppConfig } from "./akanConfig";
6
6
 
7
7
  /** The workspace root's own `akan.config.ts`: settings that belong to no app. */
@@ -1,7 +1,7 @@
1
1
  import { mkdtemp, rm } from "node:fs/promises";
2
2
  import os from "node:os";
3
3
  import path from "node:path";
4
- import type { PackageJson } from "../types";
4
+ import type { PackageJson } from "../workspace/types";
5
5
 
6
6
  export class ProductionLockfile {
7
7
  static readonly fileName = "bun.lock";