@akanjs/devkit 3.2.0-rc.8 → 3.2.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 +0 -528
  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
@@ -16,11 +16,14 @@ the server errors logged meanwhile, console errors and warnings, and layout smel
16
16
  running one.
17
17
  - Paths are comma-separated (`akan preview <app> /board,/board/new`) and get the default locale when they lack
18
18
  one, unless the app sets `localePrefix: "as-needed"` and `--csr` is off. What the server answers outside a
19
- locale opens as written: a `/_akan` route such as Studio (`/_akan/studio?view=runtime`), a route under the
20
- API prefix, `/__csr`, `/__rsc`, `/.well-known`, `/openapi.json`, the default `/mcp`, `/favicon.ico`,
21
- `/robots.txt`, `/sitemap.xml`, `manifest.webmanifest` and a file in the app's `public/`. A full URL
22
- (`http://localhost:<port>/oauth/token`) opens exactly as written: use it for an endpoint mounted outside the
23
- API prefix or a custom MCP path. A page `--changed` finds always gets the locale.
19
+ locale opens as written, with no locale and no CSR boot query: a `/_akan` route such as Studio
20
+ (`/_akan/studio?view=runtime`), a route under the API prefix, `/__csr`, `/__rsc`, `/.well-known`,
21
+ `/openapi.json`, `/mcp`, `/favicon.ico`, `/robots.txt`, `/sitemap.xml`, `manifest.webmanifest` and a file in
22
+ the app's `public/`; `--csr` prints a note naming them. `/mcp` answers only `POST`, so preview cannot check it
23
+ (it fails with 405); the `akan-mcp` exposure test does. A full URL (`http://localhost:<port>/oauth/token`)
24
+ opens its path and query the same way, always on the app's dev server, with a note when it names another
25
+ server: use it for an endpoint mounted outside the API prefix. A page `--changed` finds opens as a page even at
26
+ a server route's path, under the same locale rule, and `/en` and `/en/` open once.
24
27
  `--changed` adds the pages your uncommitted page and layout edits reach. A dynamic route needs a concrete
25
28
  path (`/memo/1`); `akan context --app <app>` lists every route with its params and search names.
26
29
  - The viewport is a 390x844 phone; `--desktop` is 1280x800. `--csr` loads each page in the CSR boot the native
@@ -15,6 +15,8 @@ This is the common failure. Import `Err` from the source matching the **runtime
15
15
  - server code: `import { Err } from "../dict"`
16
16
  - UI: `from "@libs/<lib>/client"` or `from "@apps/<app>/client"`
17
17
 
18
+ Never `from "akanjs/common"` (`no-import-common-err.grit`): that `Err` takes any string, so a mistyped key compiles.
19
+
18
20
  ## Where the rule does not apply
19
21
 
20
22
  The lint rule exempts tests, `*.constant.ts`, `common/**`, and `env/**`. The last two have **no legal `Err`
@@ -38,3 +40,8 @@ discards what the endpoint chose to say, and a bare `Error` is generalized to "I
38
40
  way out.
39
41
 
40
42
  Korean `.error()` messages end in `다.`.
43
+
44
+ **The framework's own failures carry a code.** A `NoDocumentError`, an `Exception` status class or another
45
+ `AkanError` names its kind in `code`; branch on that with `AkanError.is(error, "<code>")`, never on its message.
46
+
47
+ Every code, its status and whether the caller's JSON carries it: `get_guideline` with `errorCodes`.
@@ -13,7 +13,7 @@ an endpoint with a real guard is published, one with none is refused, and so is
13
13
 
14
14
  - `mcp: false` on an endpoint, or a `slice()` `mcp` map mirroring `guards`, keeps a perfectly guarded step (a UI
15
15
  state-machine step a model would only call by mistake) off the shelf. It is an opt-out; everything else still
16
- publishes.
16
+ publishes. `mcp: "agent"` keeps an entry off `/mcp` but listed to `AgentToolsRole` and `agentService.loop`.
17
17
  - `guards: [Every, Person]` reserves an act for a person; `.with(AgentCall)` narrows what an agent's call may do.
18
18
  - A guard's `static scope` decides whether a listing can hide the entry: `"account"` guards are evaluated per
19
19
  caller, `"resource"` guards stay visible and stop the call.
@@ -32,6 +32,24 @@ an endpoint with a real guard is published, one with none is refused, and so is
32
32
  - `page().app(name, description, load)` publishes one component a host draws in the chat, as a read-only tool
33
33
  whose `load` may only query.
34
34
 
35
+ ## Calling it from the server
36
+
37
+ - `plug(AgentToolsRole)` gives a service `listAs(account, { allow })` / `callAs(account, call)`: the same catalogue
38
+ and refusals in-process plus the `mcp: "agent"` entries, batch servers included. Pass only an account the server resolved, never client input.
39
+ - `this.agentService.loop({ account | principal, allow, messages, approve, untrusted, onMessage, meta, budget })`
40
+ runs a model over those tools until it answers; `option.setAgentAccountResolver` resolves a stored `principal`
41
+ before every round. Each round is metered as its own turn with `turn.loop` and `turn.meta`. With no `untrusted`,
42
+ everything a tool returns counts as untrusted: a run with no `approve` then writes only before its first result,
43
+ so pass `approve`, or `untrusted` to name the results that carry another party's text. `toolkits` holds named
44
+ groups of `allow` back until the model calls `openToolkit`; `clientTools` (from `AgentClientTools` on an open page)
45
+ parks a call as `awaiting { client: true }` for the page to run; `ask: true` lists `askUser`, which parks as
46
+ `awaiting { question: true }`. Resume either with `answer: { id, result | error }`, never by appending a
47
+ client's result to `messages`, and never take `messages` from a request: store what `onMessage` hands out.
48
+ - `remotes: this.remoteService.sources(account, [{ name, url, description }])` (`libs/shared`, `remote.enabled`) lets
49
+ the loop call another server's `/mcp` as the user: each is a toolkit, tools read `<name>.<tool>`, a missing
50
+ connection parks as `awaiting { connect: name }` for `<Remote.Util.Connect>`, and every remote result taints the run.
51
+ Once connected, resume with the stored messages; when the user declines, resume with `answer: { id, error }`.
52
+
35
53
  ## Verify
36
54
 
37
55
  - One exposure test per app in `srvkit/mcpExposure.signal.test.ts`: list the tools with a user token, pin the names
@@ -16,7 +16,7 @@ Everything else is pages, sections, and props.
16
16
  - A page or section whose content you can write as static JSX or props is not an entity. "A self-intro page
17
17
  with two detail pages" is pages only — no `profile` module.
18
18
  - Never invent a supporting entity (profile, category, tag, author, like) to round out a design. If one looks
19
- genuinely necessary, say so in your reply and let the user decide.
19
+ genuinely necessary, build the request without it and say in your reply why it may be needed; the user decides.
20
20
  - "… plus a comment zone that saves to a database" is exactly one new module: `comment`.
21
21
  - Check what exists first (`list_modules`) and extend it when it already fits — `add-field` / `add-slice` /
22
22
  `create-ui` beat a whole new module.
@@ -7,9 +7,9 @@ description: "Run the akan check loop after editing and fix each failure class t
7
7
 
8
8
  ## One call does the whole chain
9
9
 
10
- `akan verify` (the `akan_verify` tool in akan code) syncs, lints with fixes, typechecks, fast-builds each
11
- changed app, and runs the SSR check for a `.tsx` change — over everything the working tree has changed, in one
12
- process. It prints one line when it passes and one line per problem when it fails. **Run it after editing,
10
+ `akan verify` (the `akan_verify` tool in akan code) syncs, lints with fixes, typechecks, builds each
11
+ changed app's server and SSR routes, and runs the SSR check for a `.tsx` change — over everything the working tree has changed, in one
12
+ process. A changed lib also typechecks every app and lib that uses it, so an error can name a file you did not edit. It prints one line when it passes and one line per problem when it fails. **Run it after editing,
13
13
  before you say you are done.** In akan code it also runs itself at the end of a turn that changed source.
14
14
 
15
15
  Never run `akan lint`, `akan typecheck` and `akan build` in turn: that is the same work three times over, at
@@ -1,6 +1,6 @@
1
1
  import { existsSync } from "node:fs";
2
2
  import path from "node:path";
3
- import { stripAnsi } from "../../stripAnsi";
3
+ import { stripAnsi } from "../../util/stripAnsi";
4
4
 
5
5
  export interface AkanCliResult {
6
6
  command: string;
@@ -65,7 +65,7 @@ export class AkanToolPack {
65
65
  name: AkanToolPack.verifyToolName,
66
66
  label: "akan verify",
67
67
  description:
68
- "Run `akan verify` over everything the working tree has changed: sync, lint (with fixes), typecheck, a fast build of each changed app, and the SSR check for .tsx changes, in one call. It prints one line when it passes and one line per problem when it fails. Call this after editing, before you finish; never run lint, typecheck or build separately.",
68
+ "Run `akan verify` over everything the working tree has changed: sync, lint (with fixes), typecheck, a build of each changed app's server and SSR routes, and the SSR check for .tsx changes, in one call. It prints one line when it passes and one line per problem when it fails. Call this after editing, before you finish; never run lint, typecheck or build separately.",
69
69
  promptSnippet: "akan_verify: sync, lint, typecheck and build what the working tree changed, in one call",
70
70
  parameters: Type.Object({}),
71
71
  execute: async () => {
@@ -77,7 +77,7 @@ export class AkanToolPack {
77
77
 
78
78
  static async #guidelineNames() {
79
79
  try {
80
- const { Prompter } = await import("../../prompter");
80
+ const { Prompter } = await import("../../guideline/prompter");
81
81
  return await Prompter.listGuidelines();
82
82
  } catch {
83
83
  return [];
@@ -3,7 +3,7 @@ import { mkdtempSync, rmSync } from "node:fs";
3
3
  import { tmpdir } from "node:os";
4
4
  import path from "node:path";
5
5
  import { codeAgentPresets } from "akanjs/common";
6
- import { makeCliTempWorkspace, tempRoots, writeText } from "../../testHelpers";
6
+ import { makeCliTempWorkspace, tempRoots, writeText } from "../../test/testHelpers";
7
7
  import { CodeAgent, type CodeAgentOptions } from "../agent/CodeAgent";
8
8
  import { SubagentPool } from "../agent/SubagentPool";
9
9
  import { WorkspaceTrust } from "../agent/WorkspaceTrust";
@@ -8,7 +8,6 @@ import type {
8
8
  import { Logger } from "akanjs/common";
9
9
  import chalk from "chalk";
10
10
  import { type Command, type CommanderError, program } from "commander";
11
- import { AppSelectionMemory } from "../appSelectionMemory";
12
11
  import {
13
12
  AppExecutor,
14
13
  Executor,
@@ -18,9 +17,11 @@ import {
18
17
  type SysExecutor,
19
18
  WorkspaceExecutor,
20
19
  } from "../executors";
20
+ import { ErrorReport } from "../util/errorReport";
21
21
  // Never the root barrel: it drags ink, ssh2 and the cloud stack into every command process.
22
- import { FileSys, getDirname } from "../fileSys";
23
- import type { PackageJson } from "../types";
22
+ import { FileSys, getDirname } from "../util/fileSys";
23
+ import { AppSelectionMemory } from "../workspace/appSelectionMemory";
24
+ import type { PackageJson } from "../workspace/types";
24
25
  import {
25
26
  type ArgMeta,
26
27
  type CommandContext,
@@ -57,7 +58,7 @@ const printCliError = (error: unknown, stream: "log" | "error" = "log") => {
57
58
  if (loggedCliErrorObjects.has(error)) return;
58
59
  loggedCliErrorObjects.add(error);
59
60
  }
60
- const message = CliError.messageOf(error);
61
+ const message = error instanceof Error ? ErrorReport.format(error) || error.name : CliError.messageOf(error);
61
62
  if (loggedCliErrorMessages.has(message)) return;
62
63
  loggedCliErrorMessages.add(message);
63
64
  Logger.rawLog(`\n${chalk.red(message)}`, undefined, stream);
@@ -142,6 +143,32 @@ const givenOptionsOf = (argMetas: (ArgMeta | InternalArgMeta)[], opt: Record<str
142
143
  return given;
143
144
  };
144
145
 
146
+ const argValuesOf = (argMetas: (ArgMeta | InternalArgMeta)[], cmdArgs: unknown[], opt: Record<string, unknown>) => {
147
+ const values = givenOptionsOf(argMetas, opt);
148
+ for (const argMeta of argMetas) {
149
+ if (argMeta.type === "Argument") values[argMeta.name] = cmdArgs[argMeta.idx] ?? argMeta.argsOption.default;
150
+ else if (argMeta.type === "Option") values[argMeta.name] ??= argMeta.argsOption.default;
151
+ }
152
+ return values;
153
+ };
154
+
155
+ const resolvedValuesOf = (argMetas: (ArgMeta | InternalArgMeta)[], commandArgs: unknown[]) =>
156
+ Object.fromEntries(
157
+ argMetas.flatMap((argMeta) =>
158
+ argMeta.type === "Option" || argMeta.type === "Argument" ? [[argMeta.name, commandArgs[argMeta.idx]]] : [],
159
+ ),
160
+ );
161
+
162
+ const versionGateOf = (cliVersion: string | undefined) => {
163
+ let warning = WorkspaceVersionCheck.warning(cliVersion, process.argv, process.cwd());
164
+ const refusal = WorkspaceVersionCheck.refusal(cliVersion, process.argv, process.cwd());
165
+ return (targetOption: TargetOption, values: { [name: string]: unknown }) => {
166
+ if (refusal && !WorkspaceVersionCheck.readsOnly(targetOption, values)) throw new CliError("refused", refusal);
167
+ if (warning) Logger.rawLog(chalk.yellow(`\n${warning}`), undefined, "error");
168
+ warning = null;
169
+ };
170
+ };
171
+
145
172
  const normalizeEnumChoices = (enumChoices: EnumChoices) =>
146
173
  enumChoices.map((choice: EnumChoice) =>
147
174
  typeof choice === "object"
@@ -508,8 +535,7 @@ export const runCommands = async (...commands: CommandCls[]) => {
508
535
  program.version(process.env.AKAN_VERSION).description("Akan CLI").configureHelp({
509
536
  helpWidth: 100,
510
537
  });
511
- const versionWarning = WorkspaceVersionCheck.warning(cliPackageJson?.version, process.argv, process.cwd());
512
- if (versionWarning) Logger.rawLog(chalk.yellow(`\n${versionWarning}`), undefined, "error");
538
+ const checkVersion = versionGateOf(cliPackageJson?.version);
513
539
 
514
540
  for (const command of commands) {
515
541
  const targetMetas = getTargetMetas(command);
@@ -568,6 +594,7 @@ export const runCommands = async (...commands: CommandCls[]) => {
568
594
  usage: false,
569
595
  given: givenOptionsOf(allArgMetas, opt),
570
596
  });
597
+ checkVersion(targetMeta.targetOption, argValuesOf(allArgMetas, cmdArgs, opt));
571
598
  const commandArgs = [] as unknown[];
572
599
  if (targetMeta.targetOption.runsOnWorkspaceRoot) {
573
600
  await assertCurrentDirectoryIsWorkspaceRoot();
@@ -605,6 +632,8 @@ export const runCommands = async (...commands: CommandCls[]) => {
605
632
  assignCommandContext(commandContext, argMeta, commandArgs[argMeta.idx]);
606
633
  if ((opt as { verbose?: boolean }).verbose) Executor.setVerbose(true);
607
634
  }
635
+ //? Again on the answers: a left-out argument reads as read-only above, then may be answered `apply`.
636
+ checkVersion(targetMeta.targetOption, resolvedValuesOf(allArgMetas, commandArgs));
608
637
  const cmd = CommandContainer.get(command);
609
638
 
610
639
  try {
@@ -137,7 +137,7 @@ class TargetBuilder<Deps extends readonly DependencyCls[], Params extends unknow
137
137
  }
138
138
 
139
139
  type TargetDefinition = ReturnType<TargetBuilder<readonly DependencyCls[], unknown[]>["exec"]>;
140
- type CommandBuilderContext<Deps extends readonly DependencyCls[]> = {
140
+ export type CommandBuilderContext<Deps extends readonly DependencyCls[]> = {
141
141
  public: (targetOption?: Omit<TargetOption, "type">) => TargetBuilder<Deps>;
142
142
  cloud: (targetOption?: Omit<TargetOption, "type">) => TargetBuilder<Deps>;
143
143
  dev: (targetOption?: Omit<TargetOption, "type">) => TargetBuilder<Deps>;
@@ -1,7 +1,7 @@
1
1
  import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test";
2
2
  import path from "node:path";
3
3
  import { AppExecutor, LibExecutor, ModuleExecutor, PkgExecutor, WorkspaceExecutor } from "../executors";
4
- import { makeCliTempWorkspace, tempRoots, writeText } from "../testHelpers";
4
+ import { makeCliTempWorkspace, tempRoots, writeText } from "../test/testHelpers";
5
5
  import {
6
6
  App,
7
7
  type ArgMeta,
@@ -440,7 +440,6 @@ describe("enum arg type inference", () => {
440
440
 
441
441
  describe("a Sys that defaults to the only app", () => {
442
442
  const ownIsTTY = Object.getOwnPropertyDescriptor(process.stdin, "isTTY");
443
- const ownCwd = process.cwd();
444
443
  const asked: unknown[] = [];
445
444
  let answer = "";
446
445
  const setTTY = (isTTY: boolean | undefined) =>
@@ -456,7 +455,6 @@ describe("a Sys that defaults to the only app", () => {
456
455
  });
457
456
  afterEach(() => {
458
457
  CommandContainer.clear();
459
- process.chdir(ownCwd);
460
458
  if (ownIsTTY) Object.defineProperty(process.stdin, "isTTY", ownIsTTY);
461
459
  else Reflect.deleteProperty(process.stdin, "isTTY");
462
460
  });
@@ -479,10 +477,8 @@ describe("a Sys that defaults to the only app", () => {
479
477
  return meta;
480
478
  };
481
479
  const track = tempRoots();
482
- //? From the workspace root, as the CLI runs: getDirInModule stats its entries relative to the process directory.
483
480
  const moduleWorkspace = async () => {
484
481
  const { root, workspace } = track(await makeCliTempWorkspace());
485
- process.chdir(root);
486
482
  for (const [sys, name] of [
487
483
  ["apps/web", "card"],
488
484
  ["libs/util", "photo"],
@@ -767,6 +763,83 @@ describe("a target left out where no terminal can ask for it", () => {
767
763
  }, 30_000);
768
764
  });
769
765
 
766
+ describe("a CLI of another major.minor than the workspace's akanjs", () => {
767
+ const track = tempRoots();
768
+ const run = async (args: string[], env: { [name: string]: string } = {}) => {
769
+ const { root } = track(await makeCliTempWorkspace());
770
+ await writeText(path.join(root, "package.json"), '{ "name": "repo", "version": "1.0.0" }\n');
771
+ await writeText(path.join(root, "tsconfig.json"), "{}\n");
772
+ await writeText(path.join(root, "node_modules/akanjs/package.json"), '{ "name": "akanjs", "version": "1.0.0" }\n');
773
+ const entry = path.join(root, "cli.ts");
774
+ await writeText(
775
+ entry,
776
+ [
777
+ `import { command, runCommands } from ${JSON.stringify(path.join(import.meta.dir, "index.ts"))};`,
778
+ 'class ThingCommand extends command("thing", ({ public: target }) => ({',
779
+ ' makeThing: target({ desc: "writes a thing" }).exec(async function () {',
780
+ ' process.stdout.write("made\\n");',
781
+ " }),",
782
+ ' showThing: target({ desc: "reads a thing", readOnly: true }).exec(async function () {',
783
+ ' process.stdout.write("shown\\n");',
784
+ " }),",
785
+ ' fixThing: target({ desc: "fixes a thing", readOnly: ({ fix }) => fix === false })',
786
+ ' .option("fix", Boolean, { default: true })',
787
+ " .exec(async function (fix) {",
788
+ ' process.stdout.write("fix " + fix + "\\n");',
789
+ " }),",
790
+ ' actThing: target({ desc: "acts on a thing", readOnly: ({ action }) => action !== "apply" })',
791
+ ' .option("action", String, { enum: () => ["apply"] })',
792
+ " .exec(async function (action) {",
793
+ ' process.stdout.write("acted " + action + "\\n");',
794
+ " }),",
795
+ "})) {}",
796
+ "await runCommands(ThingCommand);",
797
+ "",
798
+ ].join("\n"),
799
+ );
800
+ const proc = Bun.spawn(["bun", entry, ...args], {
801
+ cwd: root,
802
+ env: { ...process.env, AKAN_ALLOW_VERSION_MISMATCH: "", ...env },
803
+ stdin: "ignore",
804
+ stdout: "pipe",
805
+ stderr: "pipe",
806
+ });
807
+ const [stdout, stderr, code] = await Promise.all([
808
+ new Response(proc.stdout).text(),
809
+ new Response(proc.stderr).text(),
810
+ proc.exited,
811
+ ]);
812
+ return { stdout, stderr, code };
813
+ };
814
+
815
+ test("refuses a command that writes, before it runs, naming akan update and the override", async () => {
816
+ const refused = await run(["make-thing"]);
817
+ expect(refused.code).toBe(2);
818
+ expect(refused.stdout).toContain("but this workspace has akanjs 1.0.0, another major.minor");
819
+ expect(refused.stdout).toContain("akan update");
820
+ expect(refused.stdout).toContain("AKAN_ALLOW_VERSION_MISMATCH=1");
821
+ expect(refused.stdout).not.toContain("made");
822
+ expect((await run(["fix-thing"])).code).toBe(2);
823
+ }, 30_000);
824
+
825
+ test("decides on the values the left-out arguments resolve to, so one answered later cannot slip through", async () => {
826
+ const acted = await run(["act-thing"]);
827
+ expect(acted.code).toBe(2);
828
+ expect(acted.stdout).toContain("AKAN_ALLOW_VERSION_MISMATCH=1");
829
+ expect(acted.stdout).not.toContain("acted");
830
+ expect((await run(["act-thing"], { AKAN_ALLOW_VERSION_MISMATCH: "1" })).stdout).toContain("acted apply\n");
831
+ }, 30_000);
832
+
833
+ test("only warns for a read-only command, and runs a writing one with the override set", async () => {
834
+ const shown = await run(["show-thing"]);
835
+ expect([shown.code, shown.stdout.trim()]).toEqual([0, "shown"]);
836
+ expect(shown.stderr).toContain("but this workspace has akanjs 1.0.0");
837
+ expect((await run(["fix-thing", "--fix", "false"])).stdout).toContain("fix false\n");
838
+ const overridden = await run(["make-thing"], { AKAN_ALLOW_VERSION_MISMATCH: "1" });
839
+ expect([overridden.code, overridden.stdout.trim()]).toEqual([0, "made"]);
840
+ }, 30_000);
841
+ });
842
+
770
843
  describe("the exit code of a command that failed", () => {
771
844
  const track = tempRoots();
772
845
  const run = async (
@@ -926,6 +999,34 @@ describe("the exit code of a command that failed", () => {
926
999
  expect(rejected.code).toBe(2);
927
1000
  }, 60_000);
928
1001
 
1002
+ test("ends with each reason an aggregate holds, where a bundler log names its file and line", async () => {
1003
+ const graphFailure = [
1004
+ "await (async () => {",
1005
+ ' await Bun.write("graph/server.ts", \'import { env } from "./env.server.debug";\\nexport default env;\\n\');',
1006
+ ' const result = await Bun.build({ entrypoints: ["graph/server.ts"], target: "bun", throw: false });',
1007
+ ' return new AggregateError(result.logs, "[licenseNotices] server graph failed");',
1008
+ "})()",
1009
+ ].join("\n");
1010
+ const reason = ' Could not resolve: "./env.server.debug" (graph/server.ts:1:21)';
1011
+ const json = ' }).option("json", Boolean, { default: false';
1012
+ const [text, asJson] = await Promise.all([
1013
+ run(graphFailure),
1014
+ run(graphFailure, { option: json, args: ["--json"] }),
1015
+ ]);
1016
+ expect(text.code).toBe(1);
1017
+ expect(stripAnsi(text.stdout).trimEnd().split("\n").slice(-2)).toEqual([
1018
+ "[licenseNotices] server graph failed",
1019
+ reason,
1020
+ ]);
1021
+ expect(asJson.code).toBe(1);
1022
+ expect(JSON.parse(asJson.stdout)).toEqual({
1023
+ ok: false,
1024
+ error: "[licenseNotices] server graph failed",
1025
+ code: "failed",
1026
+ });
1027
+ expect(stripAnsi(asJson.stderr).trimEnd().split("\n").at(-1)).toBe(reason);
1028
+ }, 30_000);
1029
+
929
1030
  test("prints nothing more for an error the command marked as printed", async () => {
930
1031
  const marked = await run(
931
1032
  '(() => { const error = new Error("printed already"); markCliErrorPrinted(error); return error; })()',
@@ -1031,7 +1132,7 @@ describe("a workspace whose akanjs is not the CLI's version", () => {
1031
1132
  'class PlanRunner extends runner("plan") {}',
1032
1133
  'class PlanScript extends script("plan", [PlanRunner]) {}',
1033
1134
  'class PlanCommand extends command("plan", [PlanScript], ({ public: target }) => ({',
1034
- ' plan: target({ desc: "plans", stdio: true }).exec(async function () {',
1135
+ ' plan: target({ desc: "plans", stdio: true, readOnly: true }).exec(async function () {',
1035
1136
  " process.stdout.write(JSON.stringify({ phases: 1 }));",
1036
1137
  " }),",
1037
1138
  "})) {}",
@@ -48,6 +48,8 @@ export interface TargetOption {
48
48
  usageExitCode?: number;
49
49
  /** It deletes files in its app, lib, pkg or module, so one left out or unknown is refused, never picked or asked. */
50
50
  destructive?: boolean;
51
+ /** Writes nothing akanjs's version shapes, so another major.minor CLI only warns; left out, it is refused. */
52
+ readOnly?: boolean | ((values: { [name: string]: unknown }) => boolean);
51
53
  /** Runs after the CLI printed a failure and before it exits, so what it writes ends the output. */
52
54
  onFailure?: (error: unknown, failure: TargetFailure) => void | Promise<void>;
53
55
  }
@@ -1,7 +1,7 @@
1
1
  import { describe, expect, test } from "bun:test";
2
2
  import { mkdir, symlink } from "node:fs/promises";
3
3
  import path from "node:path";
4
- import { tempDirs, writeJson } from "../testHelpers";
4
+ import { tempDirs, writeJson } from "../test/testHelpers";
5
5
  import { WorkspaceVersionCheck } from "./workspaceVersionCheck";
6
6
 
7
7
  const makeRoot = tempDirs("akan-version-check-");
@@ -77,4 +77,73 @@ describe("WorkspaceVersionCheck", () => {
77
77
  expect(WorkspaceVersionCheck.installedAkanVersion(root)).toBeNull();
78
78
  expect(WorkspaceVersionCheck.warning("3.1.0", argv("sync", "demo"), root)).toBeNull();
79
79
  });
80
+
81
+ describe("refusal", () => {
82
+ test("refuses another major.minor, naming both versions, akan update and the variable that overrides it", async () => {
83
+ const root = await makeWorkspace({ akanjs: "3.1.4" });
84
+
85
+ const refusal = WorkspaceVersionCheck.refusal("3.2.0", argv("sync", "demo"), root, {});
86
+
87
+ expect(refusal).toContain("@akanjs/cli 3.2.0, but this workspace has akanjs 3.1.4, another major.minor");
88
+ expect(refusal).toContain("`akan sync` is refused");
89
+ expect(refusal).toContain("Move the workspace and this CLI to one release together: akan update\n");
90
+ expect(refusal).toContain("Or run the matching CLI once: bunx -p @akanjs/cli@3.1.4 akan sync demo");
91
+ expect(refusal).toEndWith("Or set AKAN_ALLOW_VERSION_MISMATCH=1 to run it anyway.");
92
+ expect(WorkspaceVersionCheck.refusal("4.0.0-rc.1", argv("sync"), root, {})).toContain("akan update --tag rc");
93
+ });
94
+
95
+ test("tells a CLI older than the workspace to install the matching one, not to run akan update", async () => {
96
+ const refusal = WorkspaceVersionCheck.refusal(
97
+ "3.1.4",
98
+ argv("sync", "demo"),
99
+ await makeWorkspace({ akanjs: "3.2.0" }),
100
+ {},
101
+ );
102
+
103
+ expect(refusal).toContain("Install the CLI this workspace was moved to: bun add -g @akanjs/cli@3.2.0");
104
+ expect(refusal).not.toContain("akan update");
105
+ });
106
+
107
+ test("passes the same major.minor, prereleases of it included, leaving the warning", async () => {
108
+ for (const [cli, akanjs] of [
109
+ ["3.2.0-rc.5", "3.2.0-rc.3"],
110
+ ["3.2.1", "3.2.0"],
111
+ ["3.2.0", "3.2.0-rc.9"],
112
+ ] as const) {
113
+ const root = await makeWorkspace({ akanjs });
114
+ expect(WorkspaceVersionCheck.refusal(cli, argv("sync"), root, {})).toBeNull();
115
+ expect(WorkspaceVersionCheck.warning(cli, argv("sync"), root)).toContain(`akanjs ${akanjs}`);
116
+ }
117
+ });
118
+
119
+ test("never refuses update, create-workspace, help or version, nor with the override set", async () => {
120
+ const root = await makeWorkspace({ akanjs: "3.1.4" });
121
+ for (const args of [["update"], ["create-workspace", "next"], ["--version"], ["sync", "--help"]])
122
+ expect(WorkspaceVersionCheck.refusal("3.2.0", argv(...args), root, {})).toBeNull();
123
+ for (const value of ["1", "true"])
124
+ expect(
125
+ WorkspaceVersionCheck.refusal("3.2.0", argv("sync"), root, { AKAN_ALLOW_VERSION_MISMATCH: value }),
126
+ ).toBeNull();
127
+ expect(
128
+ WorkspaceVersionCheck.refusal("3.2.0", argv("sync"), root, { AKAN_ALLOW_VERSION_MISMATCH: "0" }),
129
+ ).not.toBeNull();
130
+ });
131
+
132
+ test("never refuses a workspace that links akanjs from its own source", async () => {
133
+ const root = await makeWorkspace({});
134
+ await writeJson(path.join(root, "pkgs/akanjs/package.json"), { name: "akanjs", version: "2.0.0" });
135
+ await mkdir(path.join(root, "node_modules"), { recursive: true });
136
+ await symlink(path.join(root, "pkgs/akanjs"), path.join(root, "node_modules/akanjs"), "dir");
137
+
138
+ expect(WorkspaceVersionCheck.refusal("3.2.0", argv("sync", "demo"), root, {})).toBeNull();
139
+ });
140
+
141
+ test("counts a command as writing unless it is marked read-only, for the values it was given", () => {
142
+ expect(WorkspaceVersionCheck.readsOnly({ type: "public" }, {})).toBe(false);
143
+ expect(WorkspaceVersionCheck.readsOnly({ type: "public", readOnly: true }, {})).toBe(true);
144
+ const lint = { type: "public", readOnly: ({ fix }: { [name: string]: unknown }) => fix === false } as const;
145
+ expect(WorkspaceVersionCheck.readsOnly(lint, { fix: true })).toBe(false);
146
+ expect(WorkspaceVersionCheck.readsOnly(lint, { fix: false })).toBe(true);
147
+ });
148
+ });
80
149
  });
@@ -1,35 +1,66 @@
1
1
  import { existsSync, readFileSync, realpathSync } from "node:fs";
2
2
  import path from "node:path";
3
- import type { PackageJson } from "../types";
3
+ import type { PackageJson } from "../workspace/types";
4
+ import type { TargetOption } from "./targetMeta";
5
+
6
+ interface Mismatch {
7
+ args: string[];
8
+ cliVersion: string;
9
+ installed: string;
10
+ pinnedCli: string | null;
11
+ rerun: string;
12
+ update: string;
13
+ }
4
14
 
5
15
  export class WorkspaceVersionCheck {
16
+ static readonly overrideEnv = "AKAN_ALLOW_VERSION_MISMATCH";
6
17
  static readonly #exemptCommands = new Set(["update", "create-workspace"]);
7
18
  static readonly #infoFlags = new Set(["--help", "-h", "--version", "-V"]);
8
19
  static readonly #updateTags = new Set(["dev", "canary", "beta", "rc", "alpha"]);
9
20
 
10
21
  static warning(cliVersion: string | undefined, argv: string[], workspaceRoot: string) {
11
- const args = argv.slice(2);
12
- if (!cliVersion || WorkspaceVersionCheck.#exemptCommands.has(args[0] ?? "")) return null;
13
- if (args.some((arg) => WorkspaceVersionCheck.#infoFlags.has(arg))) return null;
14
- const installed = WorkspaceVersionCheck.installedAkanVersion(workspaceRoot);
15
- if (!installed || installed === cliVersion) return null;
16
- const pinnedCli = WorkspaceVersionCheck.#versionAt(path.join(workspaceRoot, "node_modules/@akanjs/cli"));
17
- const runner = pinnedCli === installed ? ["bunx"] : ["bunx", "-p", `@akanjs/cli@${installed}`];
18
- const rerun = [...runner, "akan", ...args].map(WorkspaceVersionCheck.#quote).join(" ");
19
- const [, prerelease = ""] = cliVersion.split("-");
20
- const tag = prerelease.split(".")[0];
21
- const update = `akan update${WorkspaceVersionCheck.#updateTags.has(tag) ? ` --tag ${tag}` : ""}`;
22
+ const mismatch = WorkspaceVersionCheck.#mismatchOf(cliVersion, argv, workspaceRoot);
23
+ if (!mismatch) return null;
24
+ const { cliVersion: cli, installed, pinnedCli, rerun, update } = mismatch;
22
25
  const lines = [
23
- `This akan is @akanjs/cli ${cliVersion}, but this workspace has akanjs ${installed}: what it generates may not match the installed framework.`,
26
+ `This akan is @akanjs/cli ${cli}, but this workspace has akanjs ${installed}: what it generates may not match the installed framework.`,
24
27
  `Run the matching CLI: ${rerun}`,
25
28
  ];
26
- if (Bun.semver.order(cliVersion, installed) > 0)
29
+ if (Bun.semver.order(cli, installed) > 0)
27
30
  lines.push(`Or move the workspace and this CLI to the newest release of the line together: ${update}`);
28
31
  else if (pinnedCli !== installed)
29
32
  lines.push(`Pin it so \`bunx akan\` runs it: bun add -d @akanjs/cli@${installed}`);
30
33
  return lines.join("\n");
31
34
  }
32
35
 
36
+ static refusal(
37
+ cliVersion: string | undefined,
38
+ argv: string[],
39
+ workspaceRoot: string,
40
+ env: { [name: string]: string | undefined } = process.env,
41
+ ) {
42
+ const mismatch = WorkspaceVersionCheck.#mismatchOf(cliVersion, argv, workspaceRoot);
43
+ if (!mismatch || ["1", "true"].includes(env[WorkspaceVersionCheck.overrideEnv] ?? "")) return null;
44
+ const { args, cliVersion: cli, installed, rerun, update } = mismatch;
45
+ if (WorkspaceVersionCheck.#lineOf(cli) === WorkspaceVersionCheck.#lineOf(installed)) return null;
46
+ //? An older CLI is not told `akan update`: it resolves the tag this CLI came from and could move akanjs back.
47
+ const realign =
48
+ Bun.semver.order(cli, installed) > 0
49
+ ? `Move the workspace and this CLI to one release together: ${update}`
50
+ : `Install the CLI this workspace was moved to: bun add -g @akanjs/cli@${installed}`;
51
+ return [
52
+ `This akan is @akanjs/cli ${cli}, but this workspace has akanjs ${installed}, another major.minor, so \`akan ${args[0]}\` is refused: it writes to the workspace, and what it writes would not match the installed framework.`,
53
+ realign,
54
+ `Or run the matching CLI once: ${rerun}`,
55
+ `Or set ${WorkspaceVersionCheck.overrideEnv}=1 to run it anyway.`,
56
+ ].join("\n");
57
+ }
58
+
59
+ static readsOnly(targetOption: TargetOption, values: { [name: string]: unknown }) {
60
+ const { readOnly = false } = targetOption;
61
+ return typeof readOnly === "function" ? readOnly(values) : readOnly;
62
+ }
63
+
33
64
  static installedAkanVersion(workspaceRoot: string) {
34
65
  const packageDir = path.join(workspaceRoot, "node_modules", "akanjs");
35
66
  if (!existsSync(packageDir)) return null;
@@ -38,6 +69,25 @@ export class WorkspaceVersionCheck {
38
69
  return WorkspaceVersionCheck.#versionAt(packageDir);
39
70
  }
40
71
 
72
+ static #mismatchOf(cliVersion: string | undefined, argv: string[], workspaceRoot: string): Mismatch | null {
73
+ const args = argv.slice(2);
74
+ if (!cliVersion || WorkspaceVersionCheck.#exemptCommands.has(args[0] ?? "")) return null;
75
+ if (args.some((arg) => WorkspaceVersionCheck.#infoFlags.has(arg))) return null;
76
+ const installed = WorkspaceVersionCheck.installedAkanVersion(workspaceRoot);
77
+ if (!installed || installed === cliVersion) return null;
78
+ const pinnedCli = WorkspaceVersionCheck.#versionAt(path.join(workspaceRoot, "node_modules/@akanjs/cli"));
79
+ const runner = pinnedCli === installed ? ["bunx"] : ["bunx", "-p", `@akanjs/cli@${installed}`];
80
+ const rerun = [...runner, "akan", ...args].map(WorkspaceVersionCheck.#quote).join(" ");
81
+ const [, prerelease = ""] = cliVersion.split("-");
82
+ const tag = prerelease.split(".")[0];
83
+ const update = `akan update${WorkspaceVersionCheck.#updateTags.has(tag) ? ` --tag ${tag}` : ""}`;
84
+ return { args, cliVersion, installed, pinnedCli, rerun, update };
85
+ }
86
+
87
+ static #lineOf(version: string) {
88
+ return version.split("-")[0]?.split(".").slice(0, 2).join(".");
89
+ }
90
+
41
91
  static #versionAt(packageDir: string) {
42
92
  const packageJsonPath = path.join(packageDir, "package.json");
43
93
  if (!existsSync(packageJsonPath)) return null;