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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (365) hide show
  1. package/CHANGELOG.md +367 -11
  2. package/DEV_RUNTIME_KNOBS.md +4 -3
  3. package/README.ko.md +3 -2
  4. package/README.md +4 -2
  5. package/akanApp/BackendImportGraph.test.ts +1 -1
  6. package/akanApp/akanApp.host.test.ts +257 -1
  7. package/akanApp/akanApp.host.ts +146 -1223
  8. package/akanApp/akanApp.host.wiring.test.ts +727 -0
  9. package/akanApp/builderGap.ts +68 -0
  10. package/akanApp/builderRequestRelay.test.ts +93 -0
  11. package/akanApp/builderRequestRelay.ts +100 -0
  12. package/akanApp/builderRssRecycler.ts +182 -0
  13. package/akanApp/devBackend.ts +392 -0
  14. package/akanApp/devBuildStatusBoard.ts +128 -0
  15. package/akanApp/devBuilder.ts +196 -0
  16. package/akanApp/devHostPolicy.test.ts +11 -11
  17. package/akanApp/devHostPolicy.ts +2 -4
  18. package/akanApp/devIdleSuspend.test.ts +221 -0
  19. package/akanApp/devIdleSuspend.ts +192 -0
  20. package/akanApp/devIdleSuspend.watcher.test.ts +120 -0
  21. package/akanApp/devRecycler.test.ts +66 -0
  22. package/akanApp/devRecycler.ts +305 -0
  23. package/akanApp/processRss.ts +61 -0
  24. package/akanConfig/akanConfig.test.ts +24 -1
  25. package/akanConfig/akanConfig.ts +10 -10
  26. package/akanConfig/akanWorkspaceConfig.ts +1 -1
  27. package/akanConfig/productionLockfile.ts +1 -1
  28. package/apiReport/apiDeclarationPrinter.ts +120 -0
  29. package/apiReport/apiReport.test.ts +526 -0
  30. package/apiReport/apiReport.ts +232 -0
  31. package/apiReport/apiReportDiff.ts +160 -0
  32. package/apiReport/apiReportPolicy.ts +65 -0
  33. package/apiReport/apiTargets.ts +311 -0
  34. package/apiReport/changesetBump.ts +19 -0
  35. package/{applicationBuildReporter.test.ts → app/applicationBuildReporter.test.ts} +21 -0
  36. package/{applicationBuildReporter.ts → app/applicationBuildReporter.ts} +10 -49
  37. package/{applicationBuildRunner.test.ts → app/applicationBuildRunner.test.ts} +74 -7
  38. package/{applicationBuildRunner.ts → app/applicationBuildRunner.ts} +20 -15
  39. package/{applicationTestPreload.ts → app/applicationTestPreload.ts} +1 -1
  40. package/{routeJsBudget.test.ts → app/routeJsBudget.test.ts} +48 -12
  41. package/{routeJsBudget.ts → app/routeJsBudget.ts} +90 -27
  42. package/{routeSourceValidator.test.ts → app/routeSourceValidator.test.ts} +17 -0
  43. package/{routeSourceValidator.ts → app/routeSourceValidator.ts} +5 -1
  44. package/artifact/implicitRootLayout.test.ts +71 -3
  45. package/artifact/implicitRootLayout.ts +21 -4
  46. package/artifact/implicitRootLayoutRender.test.tsx +297 -0
  47. package/biome.base.json +2 -1
  48. package/cloud/cloudApi.test.ts +1 -1
  49. package/cloud/configLock.test.ts +1 -1
  50. package/cloud/globalConfig.test.ts +1 -1
  51. package/cloud/globalConfig.ts +1 -1
  52. package/cloud/updatePackUpload.test.ts +1 -1
  53. package/codeAgent/agent/AkanCodeEnv.ts +1 -1
  54. package/codeAgent/agent/akanCodePaths.ts +1 -1
  55. package/codeAgent/agent/akanSystemPrompt.ts +1 -1
  56. package/codeAgent/agent/codeAgent.test.ts +1 -1
  57. package/codeAgent/skills/akan-debug/SKILL.md +10 -3
  58. package/codeAgent/skills/akan-err/SKILL.md +7 -0
  59. package/codeAgent/skills/akan-mcp/SKILL.md +14 -2
  60. package/codeAgent/skills/akan-scaffold/SKILL.md +2 -2
  61. package/codeAgent/skills/akan-transport/SKILL.md +2 -0
  62. package/codeAgent/skills/akan-validate/SKILL.md +1 -0
  63. package/codeAgent/tools/AkanCli.ts +1 -1
  64. package/codeAgent/tools/AkanToolPack.ts +1 -1
  65. package/codeAgent/tools/McpClient.ts +28 -6
  66. package/codeAgent/tools/McpToolPack.ts +1 -1
  67. package/codeAgent/tools/akanCodePlugins.test.ts +14 -2
  68. package/commandDecorators/argMeta.ts +4 -0
  69. package/commandDecorators/cliError.ts +72 -0
  70. package/commandDecorators/command.ts +165 -91
  71. package/commandDecorators/commandBuilder.ts +1 -1
  72. package/commandDecorators/commandDecorators.test.ts +191 -16
  73. package/commandDecorators/exitCodeError.ts +6 -7
  74. package/commandDecorators/index.ts +1 -0
  75. package/commandDecorators/targetMeta.ts +1 -0
  76. package/commandDecorators/workspaceVersionCheck.test.ts +1 -1
  77. package/commandDecorators/workspaceVersionCheck.ts +1 -1
  78. package/context/akanContext.ts +576 -0
  79. package/context/akanContextInspection.ts +296 -0
  80. package/{akanMcpContract.test.ts → context/akanMcpContract.test.ts} +1 -1
  81. package/{akanMcpContract.ts → context/akanMcpContract.ts} +32 -262
  82. package/context/akanMcpToolError.ts +16 -0
  83. package/context/doctor/agentGuideCheck.ts +81 -0
  84. package/context/doctor/configLeftoverCheck.ts +35 -0
  85. package/context/doctor/doctorFindings.ts +70 -0
  86. package/context/doctor/generatedFreshness.ts +56 -0
  87. package/context/doctor/moduleShapeCheck.ts +88 -0
  88. package/context/doctor/recipeDuplicateCheck.ts +39 -0
  89. package/context/doctor/recipeIndexCheck.ts +87 -0
  90. package/context/doctor/rootShapeCheck.ts +55 -0
  91. package/context/doctor/workflowScope.ts +97 -0
  92. package/{constantFieldNames.test.ts → context/moduleFieldNames.test.ts} +24 -2
  93. package/context/moduleFieldNames.ts +25 -0
  94. package/{recipeScanner.test.ts → context/recipeScanner.test.ts} +1 -1
  95. package/context/safeRead.ts +9 -0
  96. package/csrE2e/csrE2eHarness.fixture.ts +1 -1
  97. package/devkitUtils.test.ts +39 -5
  98. package/{apiReference.test.ts → docs/apiReference.test.ts} +4 -4
  99. package/{apiReference.ts → docs/apiReference.ts} +2 -2
  100. package/docs/errorCodeReference.test.ts +282 -0
  101. package/docs/errorCodeReference.ts +71 -0
  102. package/docs/errorCodeScan.ts +551 -0
  103. package/{frameworkGraph.test.ts → docs/frameworkGraph.test.ts} +1 -1
  104. package/executors/appExecutor.ts +448 -0
  105. package/executors/commandExecutionError.ts +53 -0
  106. package/executors/executor.ts +527 -0
  107. package/{executors.linkFallback.test.ts → executors/executors.linkFallback.test.ts} +1 -1
  108. package/{executors.test.ts → executors/executors.test.ts} +76 -15
  109. package/executors/index.ts +8 -0
  110. package/executors/libExecutor.ts +23 -0
  111. package/executors/moduleExecutor.ts +18 -0
  112. package/executors/pkgExecutor.ts +129 -0
  113. package/executors/sysExecutor.ts +301 -0
  114. package/executors/workspaceExecutor.ts +277 -0
  115. package/frontendBuild/allRoutesBuilder.test.ts +17 -5
  116. package/frontendBuild/allRoutesBuilder.ts +24 -6
  117. package/frontendBuild/autoImportSync.test.ts +1 -1
  118. package/frontendBuild/autoImportSync.ts +1 -1
  119. package/frontendBuild/buildRouteClient.test.ts +1 -1
  120. package/frontendBuild/bundleDefine.ts +2 -0
  121. package/frontendBuild/clientBuildTypes.ts +5 -2
  122. package/frontendBuild/clientEntriesBundler.test.ts +1 -1
  123. package/frontendBuild/clientEntryDiscovery.test.ts +28 -0
  124. package/frontendBuild/clientEntryDiscovery.ts +25 -6
  125. package/frontendBuild/csrArtifactBuilder.test.ts +1 -1
  126. package/frontendBuild/csrDevArtifactWriter.ts +1 -1
  127. package/frontendBuild/cssCompiler.test.ts +1 -1
  128. package/frontendBuild/devGeneratedIndexSync.test.ts +1 -1
  129. package/frontendBuild/devGeneratedIndexSync.ts +7 -38
  130. package/frontendBuild/dictionaryAssetBuilder.test.ts +1 -1
  131. package/frontendBuild/fontOptimizer.test.ts +1 -1
  132. package/frontendBuild/fontPruner.test.ts +1 -1
  133. package/frontendBuild/frontendBuild.test.ts +3 -3
  134. package/frontendBuild/hmrWatcher.stop.test.ts +63 -0
  135. package/frontendBuild/hmrWatcher.test.ts +1 -1
  136. package/frontendBuild/hmrWatcher.ts +22 -1
  137. package/frontendBuild/mcpAppViewBuilder.test.ts +1 -1
  138. package/frontendBuild/mcpAppViewBuilder.ts +1 -1
  139. package/frontendBuild/nativeCore.test.ts +148 -0
  140. package/frontendBuild/optionalPeers.test.ts +36 -8
  141. package/frontendBuild/pagesBundleBuilder.test.ts +2 -3
  142. package/frontendBuild/pagesBundleBuilder.ts +1 -1
  143. package/frontendBuild/precompressArtifacts.test.ts +1 -1
  144. package/frontendBuild/precompressArtifacts.ts +1 -1
  145. package/frontendBuild/serverGraphFile.ts +1 -1
  146. package/frontendBuild/sourceMtimeIndex.test.ts +1 -1
  147. package/frontendBuild/ssrBaseArtifactBuilder.test.ts +26 -0
  148. package/frontendBuild/ssrBaseArtifactBuilder.ts +23 -19
  149. package/frontendBuild/ssrDevBundler.test.ts +1 -1
  150. package/frontendBuild/vendorImportScanner.test.ts +25 -4
  151. package/frontendBuild/vendorImportScanner.ts +25 -10
  152. package/frontendBuild/vendorNarrowing.test.ts +1 -1
  153. package/frontendBuild/watchRootResolver.test.ts +1 -1
  154. package/{agentAssets.test.ts → guideline/agentAssets.test.ts} +1 -1
  155. package/{agentAssets.ts → guideline/agentAssets.ts} +2 -2
  156. package/{agentsIndex.test.ts → guideline/agentsIndex.test.ts} +2 -2
  157. package/{agentsIndex.ts → guideline/agentsIndex.ts} +13 -10
  158. package/{conventionSet.test.ts → guideline/conventionSet.test.ts} +7 -4
  159. package/{conventionSet.ts → guideline/conventionSet.ts} +1 -1
  160. package/{prompter.ts → guideline/prompter.ts} +2 -3
  161. package/incrementalBuilder/buildBatch.proc.ts +14 -4
  162. package/incrementalBuilder/buildBatchProtocol.ts +2 -0
  163. package/incrementalBuilder/buildBatchRunner.test.ts +108 -1
  164. package/incrementalBuilder/buildBatchRunner.ts +17 -4
  165. package/incrementalBuilder/builderBoot.ts +106 -0
  166. package/incrementalBuilder/builderBuildStatus.ts +23 -0
  167. package/incrementalBuilder/builderChannel.test.ts +1 -1
  168. package/incrementalBuilder/builderChannel.ts +11 -0
  169. package/incrementalBuilder/builderGraphPayloads.ts +3 -3
  170. package/incrementalBuilder/builderLanes.ts +157 -0
  171. package/incrementalBuilder/builderWatch.ts +213 -0
  172. package/incrementalBuilder/csrRegistry.ts +234 -0
  173. package/incrementalBuilder/incrementalBuilder.host.test.ts +30 -1
  174. package/incrementalBuilder/incrementalBuilder.host.ts +10 -22
  175. package/incrementalBuilder/incrementalBuilder.proc.test.ts +93 -2
  176. package/incrementalBuilder/incrementalBuilder.proc.ts +81 -823
  177. package/incrementalBuilder/ssrRegistry.ts +278 -0
  178. package/index.ts +22 -22
  179. package/integration/devStability.integration.test.ts +62 -56
  180. package/integration/devStabilityHarness.test.ts +1 -1
  181. package/lint/__fixtures__/no-import-common-err/bad.tsx +13 -0
  182. package/lint/__fixtures__/no-import-common-err/good.tsx +12 -0
  183. package/{biomeBase.test.ts → lint/biomeBase.test.ts} +1 -1
  184. package/lint/gritRules.test.ts +1 -1
  185. package/{linter.test.ts → lint/linter.test.ts} +1 -1
  186. package/lint/no-import-common-err.grit +31 -0
  187. package/lint/no-init-fetch-in-client.grit +1 -1
  188. package/lint/no-web-only-api-outside-webkit.grit +3 -3
  189. package/mobile/desktopBin.test.ts +1 -1
  190. package/mobile/desktopRelease.test.ts +1 -1
  191. package/mobile/desktopServerStage.test.ts +2 -2
  192. package/mobile/desktopServerStage.ts +1 -1
  193. package/mobile/nativeApi.test.ts +1 -1
  194. package/mobile/nativeApp.test.ts +1 -1
  195. package/mobile/nativeConfig.test.ts +1 -1
  196. package/mobile/nativePluginFolders.test.ts +1 -1
  197. package/mobile/nativePublicEnv.test.ts +1 -1
  198. package/mobile/nativeWebDir.test.ts +1 -1
  199. package/mobile/serverBundleSecrets.test.ts +1 -1
  200. package/mobile/tarWriter.test.ts +1 -1
  201. package/mobile/updatePackFolder.test.ts +1 -1
  202. package/package.json +167 -3
  203. package/packageExports.test.ts +20 -2
  204. package/piDependencyPins.test.ts +1 -1
  205. package/pipeline/PipelineDefinition.ts +1 -1
  206. package/platformTest/IdleWatchedProcess.test.ts +1 -1
  207. package/platformTest/PlatformTestRun.test.ts +1 -1
  208. package/platformTest/TestSnapshot.test.ts +1 -1
  209. package/preview/PreviewView.ts +32 -13
  210. package/preview/previewView.test.ts +33 -3
  211. package/{abstractDoc.test.ts → quality/abstractDoc.test.ts} +2 -2
  212. package/{abstractDoc.ts → quality/abstractDoc.ts} +1 -1
  213. package/quality/bareErrorScanner.ts +126 -0
  214. package/{maintainabilityBaseline.test.ts → quality/maintainabilityBaseline.test.ts} +73 -0
  215. package/{maintainabilityBaseline.ts → quality/maintainabilityBaseline.ts} +97 -9
  216. package/{maintainabilityContract.test.ts → quality/maintainabilityContract.test.ts} +383 -2
  217. package/{maintainabilityContract.ts → quality/maintainabilityContract.ts} +151 -29
  218. package/{maintainabilityExceptionScanner.test.ts → quality/maintainabilityExceptionScanner.test.ts} +15 -1
  219. package/{maintainabilityExceptionScanner.ts → quality/maintainabilityExceptionScanner.ts} +5 -1
  220. package/{maintainabilityLimits.ts → quality/maintainabilityLimits.ts} +12 -0
  221. package/{maintainabilityReport.ts → quality/maintainabilityReport.ts} +20 -3
  222. package/{qualityScanner.test.ts → quality/qualityScanner.test.ts} +1 -1
  223. package/{qualityScanner.ts → quality/qualityScanner.ts} +8 -8
  224. package/{storeAccessScanner.ts → quality/storeAccessScanner.ts} +15 -2
  225. package/{subspace.test.ts → subspace/subspace.test.ts} +25 -4
  226. package/{subspace.ts → subspace/subspace.ts} +5 -5
  227. package/{subspaceClone.ts → subspace/subspaceClone.ts} +8 -8
  228. package/{subspaceConfig.ts → subspace/subspaceConfig.ts} +5 -1
  229. package/{testHelpers.ts → test/testHelpers.ts} +37 -1
  230. package/transforms/barrelAnalyzer.ts +31 -10
  231. package/transforms/browserDirnamePlugin.test.ts +1 -1
  232. package/transforms/externalizeFrameworkPlugin.test.ts +1 -1
  233. package/transforms/mcpAppPageTrimmer.test.ts +1 -1
  234. package/transforms/pureLazyMarker.test.ts +1 -1
  235. package/transforms/serverEnvPlugin.test.ts +1 -1
  236. package/transforms/serverEnvProfile.test.ts +1 -1
  237. package/transforms/sideEffectImportOrder.test.ts +1 -1
  238. package/transforms/transforms.test.ts +52 -2
  239. package/transforms/tsconfigPackageResolver.test.ts +1 -1
  240. package/{createTunnel.test.ts → tunnel/createTunnel.test.ts} +1 -1
  241. package/{createTunnel.ts → tunnel/createTunnel.ts} +2 -2
  242. package/{sshHostKeys.ts → tunnel/sshHostKeys.ts} +2 -2
  243. package/typecheck/projectTypecheck.test.ts +1 -1
  244. package/typecheck/projectTypecheck.ts +6 -2
  245. package/{typeChecker.test.ts → typecheck/typeChecker.test.ts} +1 -1
  246. package/{typeChecker.ts → typecheck/typeChecker.ts} +1 -1
  247. package/typecheck/typecheck.proc.ts +4 -3
  248. package/typecheck/typecheckFailure.ts +7 -2
  249. package/util/errorReport.ts +66 -0
  250. package/{jsonFormatter.test.ts → util/jsonFormatter.test.ts} +1 -1
  251. package/workflow/artifacts.ts +8 -7
  252. package/workflow/constantSource.ts +187 -0
  253. package/workflow/dictionarySource.ts +184 -0
  254. package/workflow/executor.ts +6 -9
  255. package/workflow/fieldExpression.ts +153 -0
  256. package/workflow/fieldLabel.ts +61 -0
  257. package/workflow/fieldOrder.ts +117 -0
  258. package/workflow/fieldType.ts +93 -0
  259. package/workflow/guardCatalog.test.ts +1 -1
  260. package/workflow/index.ts +1 -0
  261. package/workflow/keyRename.ts +1 -1
  262. package/workflow/moduleIndex.test.ts +2 -2
  263. package/workflow/moduleIndex.ts +2 -2
  264. package/workflow/modulePaths.ts +27 -0
  265. package/workflow/mutationScaffold.ts +7 -15
  266. package/workflow/mutationSource.ts +2 -1
  267. package/workflow/plainName.ts +16 -3
  268. package/workflow/plan.ts +14 -2
  269. package/workflow/primitiveReport.ts +78 -0
  270. package/workflow/rolloutGate.test.ts +1 -1
  271. package/workflow/rolloutGate.ts +1 -1
  272. package/workflow/serviceSource.ts +33 -0
  273. package/workflow/signalSource.ts +96 -0
  274. package/workflow/source.ts +50 -1105
  275. package/workflow/sourceAst.ts +30 -0
  276. package/workflow/sourceImports.ts +105 -0
  277. package/workflow/sourceText.ts +13 -0
  278. package/workflow/templateSource.ts +30 -0
  279. package/workflow/testSource.ts +31 -0
  280. package/workflow/types.ts +1 -1
  281. package/workflow/uiPolicy.ts +1 -1
  282. package/{appSelectionMemory.ts → workspace/appSelectionMemory.ts} +1 -1
  283. package/{codegenLock.test.ts → workspace/codegenLock.test.ts} +1 -1
  284. package/{dependencyScanner.test.ts → workspace/dependencyScanner.test.ts} +1 -1
  285. package/{dependencyScanner.ts → workspace/dependencyScanner.ts} +2 -2
  286. package/{envSeed.test.ts → workspace/envSeed.test.ts} +2 -2
  287. package/{envSeed.ts → workspace/envSeed.ts} +1 -1
  288. package/{libSource.test.ts → workspace/libSource.test.ts} +2 -2
  289. package/{libSource.ts → workspace/libSource.ts} +1 -1
  290. package/{scanInfo.ts → workspace/scanInfo.ts} +21 -10
  291. package/{slicePlanner.test.ts → workspace/slicePlanner.test.ts} +2 -2
  292. package/{slicePlanner.ts → workspace/slicePlanner.ts} +1 -1
  293. package/{workspaceGraph.test.ts → workspace/workspaceGraph.test.ts} +1 -1
  294. package/{workspaceGraph.ts → workspace/workspaceGraph.ts} +1 -1
  295. package/{workspaceLayout.test.ts → workspace/workspaceLayout.test.ts} +1 -1
  296. package/{workspaceLayout.ts → workspace/workspaceLayout.ts} +3 -1
  297. package/akanContext.ts +0 -1084
  298. package/constantFieldNames.ts +0 -18
  299. package/executors.ts +0 -1749
  300. /package/{recipeScanner.ts → context/recipeScanner.ts} +0 -0
  301. /package/{declarationReader.ts → docs/declarationReader.ts} +0 -0
  302. /package/{frameworkGraph.ts → docs/frameworkGraph.ts} +0 -0
  303. /package/{biomeBase.ts → lint/biomeBase.ts} +0 -0
  304. /package/{linter.ts → lint/linter.ts} +0 -0
  305. /package/{commentDensityScanner.test.ts → quality/commentDensityScanner.test.ts} +0 -0
  306. /package/{commentDensityScanner.ts → quality/commentDensityScanner.ts} +0 -0
  307. /package/{componentSizeScanner.test.ts → quality/componentSizeScanner.test.ts} +0 -0
  308. /package/{componentSizeScanner.ts → quality/componentSizeScanner.ts} +0 -0
  309. /package/{componentWriteChainScanner.test.ts → quality/componentWriteChainScanner.test.ts} +0 -0
  310. /package/{componentWriteChainScanner.ts → quality/componentWriteChainScanner.ts} +0 -0
  311. /package/{deprecatedCommentScanner.test.ts → quality/deprecatedCommentScanner.test.ts} +0 -0
  312. /package/{deprecatedCommentScanner.ts → quality/deprecatedCommentScanner.ts} +0 -0
  313. /package/{endpointReach.test.ts → quality/endpointReach.test.ts} +0 -0
  314. /package/{endpointReach.ts → quality/endpointReach.ts} +0 -0
  315. /package/{formSetterScanner.test.ts → quality/formSetterScanner.test.ts} +0 -0
  316. /package/{formSetterScanner.ts → quality/formSetterScanner.ts} +0 -0
  317. /package/{kindBranchScanner.test.ts → quality/kindBranchScanner.test.ts} +0 -0
  318. /package/{kindBranchScanner.ts → quality/kindBranchScanner.ts} +0 -0
  319. /package/{maintainabilityReport.test.ts → quality/maintainabilityReport.test.ts} +0 -0
  320. /package/{renderMutationScanner.test.ts → quality/renderMutationScanner.test.ts} +0 -0
  321. /package/{renderMutationScanner.ts → quality/renderMutationScanner.ts} +0 -0
  322. /package/{serviceLoopCallScanner.test.ts → quality/serviceLoopCallScanner.test.ts} +0 -0
  323. /package/{serviceLoopCallScanner.ts → quality/serviceLoopCallScanner.ts} +0 -0
  324. /package/{signalMutationIndex.test.ts → quality/signalMutationIndex.test.ts} +0 -0
  325. /package/{signalMutationIndex.ts → quality/signalMutationIndex.ts} +0 -0
  326. /package/{sourceComments.test.ts → quality/sourceComments.test.ts} +0 -0
  327. /package/{sourceComments.ts → quality/sourceComments.ts} +0 -0
  328. /package/{ssrScanner.test.ts → quality/ssrScanner.test.ts} +0 -0
  329. /package/{ssrScanner.ts → quality/ssrScanner.ts} +0 -0
  330. /package/{storeAccessScanner.test.ts → quality/storeAccessScanner.test.ts} +0 -0
  331. /package/{storeSource.ts → quality/storeSource.ts} +0 -0
  332. /package/{storeWriteScanner.test.ts → quality/storeWriteScanner.test.ts} +0 -0
  333. /package/{storeWriteScanner.ts → quality/storeWriteScanner.ts} +0 -0
  334. /package/{structureScanner.test.ts → quality/structureScanner.test.ts} +0 -0
  335. /package/{structureScanner.ts → quality/structureScanner.ts} +0 -0
  336. /package/{testOnlyExportScanner.test.ts → quality/testOnlyExportScanner.test.ts} +0 -0
  337. /package/{testOnlyExportScanner.ts → quality/testOnlyExportScanner.ts} +0 -0
  338. /package/{writePath.test.ts → quality/writePath.test.ts} +0 -0
  339. /package/{writePath.ts → quality/writePath.ts} +0 -0
  340. /package/{writePlacementScanner.test.ts → quality/writePlacementScanner.test.ts} +0 -0
  341. /package/{writePlacementScanner.ts → quality/writePlacementScanner.ts} +0 -0
  342. /package/{writingActionIndex.test.ts → quality/writingActionIndex.test.ts} +0 -0
  343. /package/{writingActionIndex.ts → quality/writingActionIndex.ts} +0 -0
  344. /package/{subspaceReport.ts → subspace/subspaceReport.ts} +0 -0
  345. /package/{sshTunnel.ts → tunnel/sshTunnel.ts} +0 -0
  346. /package/{fileEditor.ts → util/fileEditor.ts} +0 -0
  347. /package/{fileSys.test.ts → util/fileSys.test.ts} +0 -0
  348. /package/{fileSys.ts → util/fileSys.ts} +0 -0
  349. /package/{jsonFormatter.ts → util/jsonFormatter.ts} +0 -0
  350. /package/{selectModel.ts → util/selectModel.ts} +0 -0
  351. /package/{semver.test.ts → util/semver.test.ts} +0 -0
  352. /package/{semver.ts → util/semver.ts} +0 -0
  353. /package/{shellOnlyEnv.test.ts → util/shellOnlyEnv.test.ts} +0 -0
  354. /package/{shellOnlyEnv.ts → util/shellOnlyEnv.ts} +0 -0
  355. /package/{spinner.test.ts → util/spinner.test.ts} +0 -0
  356. /package/{spinner.ts → util/spinner.ts} +0 -0
  357. /package/{stripAnsi.ts → util/stripAnsi.ts} +0 -0
  358. /package/{codegenLock.ts → workspace/codegenLock.ts} +0 -0
  359. /package/{getRelatedCnsts.ts → workspace/getRelatedCnsts.ts} +0 -0
  360. /package/{gitRevision.test.ts → workspace/gitRevision.test.ts} +0 -0
  361. /package/{gitRevision.ts → workspace/gitRevision.ts} +0 -0
  362. /package/{manifestDependencies.ts → workspace/manifestDependencies.ts} +0 -0
  363. /package/{packageExportsMap.ts → workspace/packageExportsMap.ts} +0 -0
  364. /package/{repoIdentity.ts → workspace/repoIdentity.ts} +0 -0
  365. /package/{types.ts → workspace/types.ts} +0 -0
@@ -0,0 +1,117 @@
1
+ import ts from "typescript";
2
+ import { propertyName } from "./sourceAst";
3
+ import { lineEndAt, lineIndentAt, lineStartAt, spliceText } from "./sourceText";
4
+
5
+ export const fieldOrderingPriority = [
6
+ "id",
7
+ "name",
8
+ "title",
9
+ "status",
10
+ "category",
11
+ "description",
12
+ "content",
13
+ "startAt",
14
+ "dueAt",
15
+ "endAt",
16
+ "createdAt",
17
+ "updatedAt",
18
+ ] as const;
19
+
20
+ type FieldOrderingName = string;
21
+
22
+ interface LocatedField {
23
+ name: FieldOrderingName;
24
+ start: number;
25
+ fullStart: number;
26
+ end: number;
27
+ }
28
+
29
+ export interface ObjectInsertionLocator {
30
+ objectStart: number;
31
+ objectEnd: number;
32
+ fields: LocatedField[];
33
+ }
34
+
35
+ export const locatedObject = (
36
+ source: ts.SourceFile,
37
+ objectLiteral: ts.ObjectLiteralExpression,
38
+ ): ObjectInsertionLocator => ({
39
+ objectStart: objectLiteral.getStart(source),
40
+ objectEnd: objectLiteral.getEnd(),
41
+ fields: objectLiteral.properties
42
+ .map((property): LocatedField | null => {
43
+ const name = propertyName(property);
44
+ if (!name) return null;
45
+ return {
46
+ name,
47
+ start: property.getStart(source),
48
+ fullStart: property.getFullStart(),
49
+ end: property.getEnd(),
50
+ };
51
+ })
52
+ .filter((field): field is LocatedField => field !== null),
53
+ });
54
+
55
+ const priorityOf = (fieldName: string) => {
56
+ const priority = (fieldOrderingPriority as readonly string[]).indexOf(fieldName);
57
+ return priority < 0 ? null : priority;
58
+ };
59
+
60
+ export const insertionIndexForFieldOrder = (fieldNames: readonly string[], newFieldName: string) => {
61
+ const newPriority = priorityOf(newFieldName);
62
+ if (newPriority !== null) {
63
+ const greaterPriorityIndex = fieldNames.findIndex((name) => {
64
+ const existingPriority = priorityOf(name);
65
+ return existingPriority !== null && existingPriority > newPriority;
66
+ });
67
+ if (greaterPriorityIndex >= 0) return greaterPriorityIndex;
68
+
69
+ const lastPriorityIndex = fieldNames.reduce((lastIndex, name, index) => {
70
+ const existingPriority = priorityOf(name);
71
+ return existingPriority !== null ? index : lastIndex;
72
+ }, -1);
73
+ return lastPriorityIndex + 1;
74
+ }
75
+
76
+ const lastNonPriorityIndex = fieldNames.reduce(
77
+ (lastIndex, name, index) => (priorityOf(name) === null ? index : lastIndex),
78
+ -1,
79
+ );
80
+ return lastNonPriorityIndex >= 0 ? lastNonPriorityIndex + 1 : fieldNames.length;
81
+ };
82
+
83
+ export const insertOrderedFieldLine = (
84
+ content: string,
85
+ locator: ObjectInsertionLocator,
86
+ fieldName: string,
87
+ line: string,
88
+ options: { fieldIndent: string; closingIndent: string },
89
+ ) => {
90
+ if (locator.fields.some((field) => field.name === fieldName)) return content;
91
+ const insertIndex = insertionIndexForFieldOrder(
92
+ locator.fields.map((field) => field.name),
93
+ fieldName,
94
+ );
95
+ const formattedLine = line.trim();
96
+ if (locator.fields.length === 0) {
97
+ return spliceText(
98
+ content,
99
+ locator.objectStart,
100
+ locator.objectEnd,
101
+ `{\n${options.fieldIndent}${formattedLine}\n${options.closingIndent}}`,
102
+ );
103
+ }
104
+
105
+ const beforeField = locator.fields[insertIndex];
106
+ if (beforeField) {
107
+ const leadingComments = ts.getLeadingCommentRanges(content, beforeField.fullStart) ?? [];
108
+ const insertAt = lineStartAt(content, leadingComments[0]?.pos ?? beforeField.start);
109
+ const indent = lineIndentAt(content, beforeField.start) || options.fieldIndent;
110
+ return spliceText(content, insertAt, insertAt, `${indent}${formattedLine}\n`);
111
+ }
112
+
113
+ const afterField = locator.fields[locator.fields.length - 1];
114
+ const insertAt = lineEndAt(content, afterField.end);
115
+ const indent = lineIndentAt(content, afterField.start) || options.fieldIndent;
116
+ return spliceText(content, insertAt, insertAt, `${indent}${formattedLine}\n`);
117
+ };
@@ -0,0 +1,93 @@
1
+ import ts from "typescript";
2
+ import type { Sys } from "../commandDecorators";
3
+ import { getSysRoot, moduleComponentName, moduleSourcePaths } from "./modulePaths";
4
+ import { sourceFileFor } from "./sourceAst";
5
+ import { ensureBaseImport, ensureNamedImport } from "./sourceImports";
6
+ import type { WorkflowDiagnostic } from "./types";
7
+
8
+ const builtInFieldTypes = new Set(["String", "Boolean", "Date", "Map"]);
9
+ const baseFieldTypes = new Set(["Int", "Float", "ID", "Any", "Binary", "ImageResult"]);
10
+ const fieldTypeReference = /^\[*([A-Za-z_$][\w$]*)((?:\.[A-Za-z_$][\w$]*)*)\]*$/;
11
+
12
+ export const ensureBaseTypeImport = (content: string, typeName: string) => {
13
+ const [, name = "", member] = fieldTypeReference.exec(typeName) ?? [];
14
+ if (member || !baseFieldTypes.has(name)) return content;
15
+ return ensureBaseImport(content, name);
16
+ };
17
+
18
+ const valueNamesOf = (content: string) => {
19
+ const names = new Set<string>();
20
+ for (const statement of sourceFileFor("source.ts", content).statements) {
21
+ if (ts.isImportDeclaration(statement)) {
22
+ const clause = statement.importClause;
23
+ if (!clause || clause.isTypeOnly) continue;
24
+ if (clause.name) names.add(clause.name.text);
25
+ const bindings = clause.namedBindings;
26
+ if (bindings && ts.isNamespaceImport(bindings)) names.add(bindings.name.text);
27
+ else for (const element of bindings?.elements ?? []) if (!element.isTypeOnly) names.add(element.name.text);
28
+ } else if (ts.isVariableStatement(statement)) {
29
+ for (const declaration of statement.declarationList.declarations)
30
+ if (ts.isIdentifier(declaration.name)) names.add(declaration.name.text);
31
+ } else if (
32
+ (ts.isClassDeclaration(statement) || ts.isEnumDeclaration(statement) || ts.isFunctionDeclaration(statement)) &&
33
+ statement.name
34
+ )
35
+ names.add(statement.name.text);
36
+ }
37
+ return names;
38
+ };
39
+
40
+ export const fieldTypeSource = async (
41
+ sys: Sys,
42
+ module: string,
43
+ typeName: string,
44
+ constantContent: string,
45
+ ): Promise<{ import?: { name: string; from: string }; diagnostic?: WorkflowDiagnostic }> => {
46
+ const reference = fieldTypeReference.exec(typeName);
47
+ if (!reference)
48
+ return {
49
+ diagnostic: {
50
+ severity: "error",
51
+ code: "primitive-field-type-unknown",
52
+ input: "type",
53
+ message: `Field type "${typeName}" is not a type name field() takes. Name one type, such as Address, or a list of one, such as [Address], then plan this again.`,
54
+ },
55
+ };
56
+ const [, name = "", member] = reference;
57
+ if (builtInFieldTypes.has(name) || baseFieldTypes.has(name) || valueNamesOf(constantContent).has(name)) return {};
58
+ const [scalars, models] = await Promise.all([sys.getScalarModules(), sys.getDatabaseModules()]);
59
+ const scalar = member ? undefined : scalars.find((scalarName) => moduleComponentName(scalarName) === name);
60
+ if (scalar) return { import: { name, from: `../__scalar/${scalar}/${scalar}.constant` } };
61
+ const model = member ? undefined : models.find((modelName) => moduleComponentName(modelName) === name);
62
+ if (model) return { import: { name, from: `../${model}/${model}.constant` } };
63
+ const root = getSysRoot(sys);
64
+ const constantPath = `${root}/${moduleSourcePaths(module).constant}`;
65
+ const named = (kind: string, names: string[]) =>
66
+ names.length ? `Its ${kind} are ${names.map(moduleComponentName).join(", ")}.` : `It has no ${kind}.`;
67
+ return {
68
+ diagnostic: {
69
+ severity: "error",
70
+ code: "primitive-field-type-unknown",
71
+ input: "type",
72
+ message: [
73
+ `Field type "${typeName}" names ${name}, which is not a built-in or akanjs/base type, not imported by ${constantPath}, and not a scalar or model in ${root}.`,
74
+ named("scalars", scalars),
75
+ named("models", models),
76
+ `Create the scalar with the create-scalar workflow first, or import ${name} into ${constantPath}, then plan this again.`,
77
+ ].join(" "),
78
+ },
79
+ };
80
+ };
81
+
82
+ export const withFieldTypeImport = async (
83
+ sys: Sys,
84
+ module: string,
85
+ typeName: string,
86
+ content: string,
87
+ diagnostics: WorkflowDiagnostic[],
88
+ ) => {
89
+ const withBaseImport = ensureBaseTypeImport(content, typeName);
90
+ const source = await fieldTypeSource(sys, module, typeName, withBaseImport);
91
+ if (source.diagnostic) diagnostics.push(source.diagnostic);
92
+ return source.import ? ensureNamedImport(withBaseImport, source.import.from, source.import.name) : withBaseImport;
93
+ };
@@ -1,6 +1,6 @@
1
1
  import { describe, expect, test } from "bun:test";
2
2
  import path from "node:path";
3
- import { createTempApp, tempRoots, writeJson, writeText } from "../testHelpers";
3
+ import { createTempApp, tempRoots, writeJson, writeText } from "../test/testHelpers";
4
4
  import { GuardCatalog } from "./guardCatalog";
5
5
 
6
6
  const track = tempRoots();
package/workflow/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from "./artifacts";
2
2
  export * from "./executor";
3
+ export * from "./fieldType";
3
4
  export * from "./guardCatalog";
4
5
  export * from "./interactionScaffold";
5
6
  export * from "./keyRename";
@@ -4,7 +4,7 @@ import { AkanIndex, type AkanRenameEdit } from "@akanjs/language";
4
4
  import ts from "typescript";
5
5
  import type { Workspace } from "../commandDecorators";
6
6
  import { resolveWorkflowSys } from "./executor";
7
- import { getSysRoot, moduleSourcePaths } from "./source";
7
+ import { getSysRoot, moduleSourcePaths } from "./modulePaths";
8
8
  import type { RenameKeyInput, ScaffoldFile, WorkflowDiagnostic } from "./types";
9
9
 
10
10
  const indexedPath = /^(apps|libs)\/(?!(?:.*\/)?(?:node_modules|dist|\.akan)\/).*\.tsx?$/;
@@ -1,8 +1,8 @@
1
1
  import { describe, expect, test } from "bun:test";
2
2
  import path from "node:path";
3
- import type { AkanModuleContext } from "../akanContext";
4
3
  import type { Workspace } from "../commandDecorators";
5
- import { tempDirs, writeText } from "../testHelpers";
4
+ import type { AkanModuleContext } from "../context/akanContext";
5
+ import { tempDirs, writeText } from "../test/testHelpers";
6
6
  import { buildAkanModuleContextIndex } from "./moduleIndex";
7
7
 
8
8
  const tempRoot = tempDirs("akan-module-index-");
@@ -1,9 +1,9 @@
1
1
  import { access } from "node:fs/promises";
2
2
  import path from "node:path";
3
3
  import ts from "typescript";
4
- import type { AkanModuleContext } from "../akanContext";
5
4
  import type { Workspace } from "../commandDecorators";
6
- import { moduleComponentName, moduleSourcePaths } from "./source";
5
+ import type { AkanModuleContext } from "../context/akanContext";
6
+ import { moduleComponentName, moduleSourcePaths } from "./modulePaths";
7
7
  import {
8
8
  callExpressionName,
9
9
  expressionName,
@@ -0,0 +1,27 @@
1
+ import type { Sys } from "../commandDecorators";
2
+
3
+ export const getSysRoot = (sys: Sys) => `${sys.type}s/${sys.name}`;
4
+
5
+ export const moduleComponentName = (moduleName: string) =>
6
+ moduleName
7
+ .replace(/[-_]+/g, " ")
8
+ .replace(/(?<=^|\s)[a-zA-Z0-9]/g, (char) => char.toUpperCase())
9
+ .replace(/\s+/g, "");
10
+
11
+ export const moduleSourcePaths = (moduleName: string) => {
12
+ const componentName = moduleComponentName(moduleName);
13
+ return {
14
+ abstract: `lib/${moduleName}/${moduleName}.abstract.md`,
15
+ constant: `lib/${moduleName}/${moduleName}.constant.ts`,
16
+ dictionary: `lib/${moduleName}/${moduleName}.dictionary.ts`,
17
+ document: `lib/${moduleName}/${moduleName}.document.ts`,
18
+ service: `lib/${moduleName}/${moduleName}.service.ts`,
19
+ signal: `lib/${moduleName}/${moduleName}.signal.ts`,
20
+ store: `lib/${moduleName}/${moduleName}.store.ts`,
21
+ template: `lib/${moduleName}/${componentName}.Template.tsx`,
22
+ unit: `lib/${moduleName}/${componentName}.Unit.tsx`,
23
+ util: `lib/${moduleName}/${componentName}.Util.tsx`,
24
+ view: `lib/${moduleName}/${componentName}.View.tsx`,
25
+ zone: `lib/${moduleName}/${componentName}.Zone.tsx`,
26
+ };
27
+ };
@@ -1,22 +1,14 @@
1
1
  import { lowerlize, modelNames } from "akanjs/common";
2
2
  import type { Sys } from "../commandDecorators";
3
+ import { hasDictionaryEndpointEntry, insertDictionaryEndpointEntry } from "./dictionarySource";
3
4
  import { GuardCatalog } from "./guardCatalog";
5
+ import { moduleComponentName, moduleSourcePaths } from "./modulePaths";
4
6
  import { type MutationActingUser, type MutationCall, MutationSource } from "./mutationSource";
5
- import {
6
- appendTopLevelTestCases,
7
- classMethodParameters,
8
- ensureImportDeclaration,
9
- ensureNamedImport,
10
- hasClassMethod,
11
- hasDictionaryEndpointEntry,
12
- hasSignalFactoryEntry,
13
- hasSourceParseErrors,
14
- insertClassMethod,
15
- insertDictionaryEndpointEntry,
16
- insertSignalFactoryEntry,
17
- moduleComponentName,
18
- moduleSourcePaths,
19
- } from "./source";
7
+ import { classMethodParameters, hasClassMethod, insertClassMethod } from "./serviceSource";
8
+ import { hasSignalFactoryEntry, insertSignalFactoryEntry } from "./signalSource";
9
+ import { hasSourceParseErrors } from "./sourceAst";
10
+ import { ensureImportDeclaration, ensureNamedImport } from "./sourceImports";
11
+ import { appendTopLevelTestCases } from "./testSource";
20
12
  import type { ScaffoldFile, WorkflowDiagnostic, WorkflowRecommendation } from "./types";
21
13
 
22
14
  export interface MutationScaffoldInput {
@@ -1,5 +1,6 @@
1
1
  import { lowerlize } from "akanjs/common";
2
- import { bilingualLabelForField, moduleComponentName, titleize } from "./source";
2
+ import { bilingualLabelForField, titleize } from "./fieldLabel";
3
+ import { moduleComponentName } from "./modulePaths";
3
4
 
4
5
  export interface MutationCall {
5
6
  ref: string;
@@ -1,15 +1,28 @@
1
1
  export const sysNamePattern = /^[a-z0-9][a-zA-Z0-9_-]*$/;
2
2
  export const identifierPattern = /^_{0,2}[a-zA-Z][a-zA-Z0-9_-]*$/;
3
+ const packageNamePattern = /^(@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/;
4
+
5
+ export type PlainNameKind = "app" | "lib" | "module" | "service" | "scalar";
3
6
 
4
7
  export const isWorkflowSysName = (value: unknown): value is string =>
5
8
  typeof value === "string" && sysNamePattern.test(value);
6
9
  export const isWorkflowModuleName = (value: unknown): value is string =>
7
10
  typeof value === "string" && identifierPattern.test(value);
8
11
 
9
- export const assertPlainName = (kind: "app" | "lib" | "module" | "service" | "scalar", name: string) => {
12
+ export const plainNameProblem = (kind: PlainNameKind, name: string) => {
10
13
  const isSys = kind === "app" || kind === "lib";
11
- if (isSys ? isWorkflowSysName(name) : isWorkflowModuleName(name)) return;
14
+ if (isSys ? isWorkflowSysName(name) : isWorkflowModuleName(name)) return null;
15
+ return `${JSON.stringify(name)} is no ${kind} name; use letters, digits, - and _, starting with ${isSys ? "a lowercase letter or digit" : "a letter"}`;
16
+ };
17
+
18
+ export const assertPlainName = (kind: PlainNameKind, name: string) => {
19
+ const problem = plainNameProblem(kind, name);
20
+ if (problem) throw new Error(problem);
21
+ };
22
+
23
+ export const assertPackageName = (name: string) => {
24
+ if (packageNamePattern.test(name)) return;
12
25
  throw new Error(
13
- `${JSON.stringify(name)} is no ${kind} name; use letters, digits, - and _, starting with ${isSys ? "a lowercase letter or digit" : "a letter"}`,
26
+ `${JSON.stringify(name)} is no package name; use name or @scope/name, each of lowercase letters, digits, -, . and _, starting with a letter or digit`,
14
27
  );
15
28
  };
package/workflow/plan.ts CHANGED
@@ -2,11 +2,13 @@ import { capitalize } from "akanjs/common";
2
2
  import type { Sys, Workspace } from "../commandDecorators";
3
3
  import { withoutApplyHints, workflowPlanApproval } from "./artifacts";
4
4
  import { resolveWorkflowSys } from "./executor";
5
+ import { coerceFieldDefault, normalizeFieldType } from "./fieldExpression";
6
+ import { fieldTypeSource } from "./fieldType";
5
7
  import { InteractionScaffold } from "./interactionScaffold";
6
8
  import { KeyRename } from "./keyRename";
9
+ import { getSysRoot, moduleSourcePaths } from "./modulePaths";
7
10
  import { MutationScaffold } from "./mutationScaffold";
8
11
  import { identifierPattern, sysNamePattern } from "./plainName";
9
- import { coerceFieldDefault, getSysRoot, moduleSourcePaths } from "./source";
10
12
  import type {
11
13
  WorkflowDiagnostic,
12
14
  WorkflowInputSpec,
@@ -541,6 +543,13 @@ const moduleNotDatabase = async (sys: Sys, spec: WorkflowSpec, module: string):
541
543
  };
542
544
  };
543
545
 
546
+ const fieldTypeUnknown = async (sys: Sys, spec: WorkflowSpec, module: string, type: string | null) => {
547
+ if (spec.name !== "add-field" || !type || ["enum", "number", "numeric", "upload"].includes(type.toLowerCase()))
548
+ return null;
549
+ const constant = await sys.readFile(moduleSourcePaths(module).constant);
550
+ return (await fieldTypeSource(sys, module, normalizeFieldType(type), constant)).diagnostic ?? null;
551
+ };
552
+
544
553
  export const workflowTargetDiagnostics = async (
545
554
  workspace: Workspace,
546
555
  spec: WorkflowSpec,
@@ -563,7 +572,10 @@ export const workflowTargetDiagnostics = async (
563
572
  const module = planString(inputs, "module");
564
573
  const moduleSpec: WorkflowInputSpec | undefined = spec.inputs.module;
565
574
  if (!module || !moduleSpec?.mustExist) return [];
566
- const refused = (await moduleMissing(workspace, sys, module)) ?? (await moduleNotDatabase(sys, spec, module));
575
+ const refused =
576
+ (await moduleMissing(workspace, sys, module)) ??
577
+ (await moduleNotDatabase(sys, spec, module)) ??
578
+ (await fieldTypeUnknown(sys, spec, module, planString(inputs, "type")));
567
579
  return refused ? [refused] : [];
568
580
  };
569
581
 
@@ -0,0 +1,78 @@
1
+ import type { Sys } from "../commandDecorators";
2
+ import { generatedFilePathsForTarget } from "./artifacts";
3
+ import { getSysRoot } from "./modulePaths";
4
+ import type {
5
+ PrimitiveChangedFile,
6
+ PrimitiveFileMap,
7
+ PrimitiveGeneratedFile,
8
+ PrimitiveNextAction,
9
+ PrimitiveValidationCommand,
10
+ PrimitiveWriteReport,
11
+ } from "./types";
12
+
13
+ export const sourceFile = (sys: Sys, path: string, action: PrimitiveChangedFile["action"], reason: string) => ({
14
+ path: `${getSysRoot(sys)}/${path}`,
15
+ action,
16
+ reason,
17
+ });
18
+
19
+ export const generatedFilesForSync = (sys: Sys, reason = "Generated files may change after sync.") =>
20
+ generatedFilePathsForTarget(getSysRoot(sys), reason);
21
+
22
+ export const validationCommandsForTarget = (target: string) =>
23
+ [
24
+ { command: `akan verify ${target}`, reason: "Sync, lint, typecheck and build the target in one run." },
25
+ ] satisfies PrimitiveValidationCommand[];
26
+
27
+ export const nextActionsForTarget = (target: string) =>
28
+ [
29
+ { command: `akan verify ${target}`, reason: "Refresh generated files and validate the target in one run." },
30
+ ] satisfies PrimitiveNextAction[];
31
+
32
+ export const createPrimitiveWriteReport = ({
33
+ command,
34
+ status,
35
+ changedFiles = [],
36
+ generatedFiles = [],
37
+ validationCommands = [],
38
+ diagnostics = [],
39
+ nextActions = [],
40
+ }: Omit<PrimitiveWriteReport, "schemaVersion" | "status"> & {
41
+ status?: PrimitiveWriteReport["status"];
42
+ }): PrimitiveWriteReport => ({
43
+ schemaVersion: 1,
44
+ command,
45
+ status: status ?? (diagnostics.some((diagnostic) => diagnostic.severity === "error") ? "failed" : "passed"),
46
+ changedFiles,
47
+ generatedFiles,
48
+ validationCommands,
49
+ diagnostics,
50
+ nextActions,
51
+ });
52
+
53
+ export const createPassedPrimitiveReport = ({
54
+ command,
55
+ changedFiles,
56
+ generatedFiles,
57
+ target,
58
+ nextActions,
59
+ }: {
60
+ command: string;
61
+ changedFiles: PrimitiveChangedFile[];
62
+ generatedFiles?: PrimitiveGeneratedFile[];
63
+ target: string;
64
+ nextActions?: PrimitiveNextAction[];
65
+ }) =>
66
+ createPrimitiveWriteReport({
67
+ command,
68
+ changedFiles,
69
+ generatedFiles: generatedFiles ?? [],
70
+ validationCommands: validationCommandsForTarget(target),
71
+ diagnostics: [],
72
+ nextActions: nextActions ?? nextActionsForTarget(target),
73
+ });
74
+
75
+ export const scalarChangedFiles = (sys: Sys, scalarName: string, files: PrimitiveFileMap) =>
76
+ Object.values(files).map((file) =>
77
+ sourceFile(sys, `lib/__scalar/${scalarName}/${file.filename}`, "create", "Scalar source file was created."),
78
+ );
@@ -1,6 +1,6 @@
1
1
  import { describe, expect, test } from "bun:test";
2
2
  import path from "node:path";
3
- import type { PackageJson } from "../types";
3
+ import type { PackageJson } from "../workspace/types";
4
4
  import { findToolingRolloutViolations } from "./rolloutGate";
5
5
 
6
6
  const manifest = (overrides: Partial<PackageJson>): PackageJson => ({
@@ -1,4 +1,4 @@
1
- import type { PackageJson } from "../types";
1
+ import type { PackageJson } from "../workspace/types";
2
2
 
3
3
  export type ToolingRolloutDependencySection =
4
4
  | "dependencies"
@@ -0,0 +1,33 @@
1
+ import ts from "typescript";
2
+ import { findClassDeclaration, nodeName, sourceFileFor } from "./sourceAst";
3
+ import { spliceText } from "./sourceText";
4
+
5
+ export const hasClassMethod = (content: string, className: string, methodName: string) => {
6
+ const node = findClassDeclaration(sourceFileFor("service.ts", content), className);
7
+ return Boolean(
8
+ node?.members.some((member) => ts.isMethodDeclaration(member) && nodeName(member.name) === methodName),
9
+ );
10
+ };
11
+
12
+ export const classMethodParameters = (content: string, className: string, methodName: string) => {
13
+ const source = sourceFileFor("service.ts", content);
14
+ const method = findClassDeclaration(source, className)?.members.find(
15
+ (member): member is ts.MethodDeclaration => ts.isMethodDeclaration(member) && nodeName(member.name) === methodName,
16
+ );
17
+ return (
18
+ method?.parameters.map((parameter) => ({
19
+ name: nodeName(parameter.name),
20
+ optional: !!parameter.questionToken || !!parameter.initializer || !!parameter.dotDotDotToken,
21
+ })) ?? null
22
+ );
23
+ };
24
+
25
+ export const insertClassMethod = (content: string, className: string, methodBlock: string): string | null => {
26
+ const source = sourceFileFor("service.ts", content);
27
+ const node = findClassDeclaration(source, className);
28
+ if (!node) return null;
29
+ const closeBrace = node.getEnd() - 1;
30
+ if (content[closeBrace] !== "}") return null;
31
+ const lead = content.slice(0, closeBrace).endsWith("\n") ? "" : "\n";
32
+ return spliceText(content, closeBrace, closeBrace, `${lead}${methodBlock}\n`);
33
+ };
@@ -0,0 +1,96 @@
1
+ import ts from "typescript";
2
+ import { insertOrderedFieldLine, locatedObject } from "./fieldOrder";
3
+ import {
4
+ factoryArrowOf,
5
+ findClassDeclaration,
6
+ firstHeritageCall,
7
+ firstObjectReturnedByArrow,
8
+ nodeName,
9
+ propertyName,
10
+ sourceFileFor,
11
+ } from "./sourceAst";
12
+ import { spliceText } from "./sourceText";
13
+
14
+ export interface FactoryParamPlan {
15
+ mode: "destructure" | "positional";
16
+ name: string;
17
+ }
18
+
19
+ const arrowParamInnerRegion = (
20
+ content: string,
21
+ source: ts.SourceFile,
22
+ arrow: ts.ArrowFunction | ts.FunctionExpression,
23
+ ) => {
24
+ if (arrow.parameters.length > 0) {
25
+ return {
26
+ start: arrow.parameters[0].getStart(source),
27
+ end: arrow.parameters[arrow.parameters.length - 1].getEnd(),
28
+ };
29
+ }
30
+ const open = content.indexOf("(", arrow.getStart(source));
31
+ if (open < 0) return null;
32
+ const close = content.indexOf(")", open);
33
+ if (close < 0) return null;
34
+ return { start: open + 1, end: close };
35
+ };
36
+
37
+ const factoryParamEdit = (
38
+ content: string,
39
+ source: ts.SourceFile,
40
+ arrow: ts.ArrowFunction | ts.FunctionExpression,
41
+ plan: FactoryParamPlan,
42
+ ): { start: number; end: number; text: string } | "unchanged" | null => {
43
+ if (arrow.parameters.length > 1) return null;
44
+ const region = arrowParamInnerRegion(content, source, arrow);
45
+ if (!region) return null;
46
+ if (arrow.parameters.length === 0) {
47
+ return { ...region, text: plan.mode === "destructure" ? `{ ${plan.name} }` : plan.name };
48
+ }
49
+ const param = arrow.parameters[0];
50
+ if (plan.mode === "positional") return nodeName(param.name) === plan.name ? "unchanged" : null;
51
+ if (!ts.isObjectBindingPattern(param.name)) return null;
52
+ const names = param.name.elements.map((element) => (ts.isIdentifier(element.name) ? element.name.text : null));
53
+ if (names.some((name) => name === null)) return null;
54
+ if (names.includes(plan.name)) return "unchanged";
55
+ return {
56
+ start: param.getStart(source),
57
+ end: param.getEnd(),
58
+ text: `{ ${[...(names as string[]), plan.name].join(", ")} }`,
59
+ };
60
+ };
61
+
62
+ const factoryObjectOf = (source: ts.SourceFile, className: string) => {
63
+ const node = findClassDeclaration(source, className);
64
+ const call = node ? firstHeritageCall(node) : null;
65
+ const arrow = call ? factoryArrowOf(call) : null;
66
+ const object = arrow ? firstObjectReturnedByArrow(arrow) : null;
67
+ return arrow && object ? { arrow, object } : null;
68
+ };
69
+
70
+ export const hasSignalFactoryEntry = (content: string, className: string, entryName: string) => {
71
+ const located = factoryObjectOf(sourceFileFor("signal.ts", content), className);
72
+ return Boolean(located?.object.properties.some((property) => propertyName(property) === entryName));
73
+ };
74
+
75
+ export const insertSignalFactoryEntry = (
76
+ content: string,
77
+ className: string,
78
+ entryName: string,
79
+ entryLine: string,
80
+ param: FactoryParamPlan,
81
+ ): string | null => {
82
+ const source = sourceFileFor("signal.ts", content);
83
+ const located = factoryObjectOf(source, className);
84
+ if (!located) return null;
85
+ const locator = locatedObject(source, located.object);
86
+ if (locator.fields.some((field) => field.name === entryName)) return content;
87
+ // Apply the param edit last: it sits before the object, so applying it first would shift the object's offsets.
88
+ const paramEdit = factoryParamEdit(content, source, located.arrow, param);
89
+ if (paramEdit === null) return null;
90
+ const withEntry = insertOrderedFieldLine(content, locator, entryName, entryLine, {
91
+ fieldIndent: " ",
92
+ closingIndent: "",
93
+ });
94
+ if (withEntry === content) return null;
95
+ return paramEdit === "unchanged" ? withEntry : spliceText(withEntry, paramEdit.start, paramEdit.end, paramEdit.text);
96
+ };