@akanjs/devkit 3.2.0-rc.9 → 3.2.1-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (353) hide show
  1. package/CHANGELOG.md +0 -529
  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 +152 -6
  7. package/akanApp/akanApp.host.ts +187 -1220
  8. package/akanApp/akanApp.host.wiring.test.ts +931 -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 +394 -0
  14. package/akanApp/devBuildStatusBoard.ts +128 -0
  15. package/akanApp/devBuilder.ts +200 -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/devStartTimeline.test.ts +115 -0
  22. package/akanApp/devStartTimeline.ts +69 -0
  23. package/akanApp/processRss.ts +61 -0
  24. package/akanConfig/akanConfig.test.ts +45 -17
  25. package/akanConfig/akanConfig.ts +10 -10
  26. package/akanConfig/akanWorkspaceConfig.ts +1 -1
  27. package/akanConfig/productionLockfile.ts +1 -1
  28. package/apiReport/apiReport.test.ts +34 -3
  29. package/apiReport/apiReportDiff.ts +35 -1
  30. package/apiReport/apiReportPolicy.ts +3 -2
  31. package/{applicationBuildReporter.ts → app/applicationBuildReporter.ts} +2 -49
  32. package/{applicationBuildRunner.test.ts → app/applicationBuildRunner.test.ts} +71 -8
  33. package/{applicationBuildRunner.ts → app/applicationBuildRunner.ts} +60 -21
  34. package/{applicationTestPreload.ts → app/applicationTestPreload.ts} +1 -1
  35. package/{routeJsBudget.test.ts → app/routeJsBudget.test.ts} +17 -1
  36. package/{routeJsBudget.ts → app/routeJsBudget.ts} +9 -3
  37. package/{routeSourceValidator.test.ts → app/routeSourceValidator.test.ts} +17 -0
  38. package/{routeSourceValidator.ts → app/routeSourceValidator.ts} +5 -1
  39. package/artifact/implicitRootLayout.test.ts +71 -3
  40. package/artifact/implicitRootLayout.ts +9 -3
  41. package/artifact/implicitRootLayoutRender.test.tsx +297 -0
  42. package/biome.base.json +2 -1
  43. package/cloud/cloudApi.test.ts +1 -1
  44. package/cloud/configLock.test.ts +1 -1
  45. package/cloud/globalConfig.test.ts +1 -1
  46. package/cloud/globalConfig.ts +1 -1
  47. package/cloud/updatePackUpload.test.ts +1 -1
  48. package/codeAgent/agent/AkanCodeEnv.ts +1 -1
  49. package/codeAgent/agent/AkanCodeServices.ts +23 -0
  50. package/codeAgent/agent/akanCodePaths.ts +1 -1
  51. package/codeAgent/agent/akanCodeServices.test.ts +54 -0
  52. package/codeAgent/agent/akanSystemPrompt.ts +1 -1
  53. package/codeAgent/agent/codeAgent.test.ts +1 -1
  54. package/codeAgent/skills/akan-debug/SKILL.md +8 -5
  55. package/codeAgent/skills/akan-err/SKILL.md +7 -0
  56. package/codeAgent/skills/akan-mcp/SKILL.md +19 -1
  57. package/codeAgent/skills/akan-scaffold/SKILL.md +1 -1
  58. package/codeAgent/skills/akan-validate/SKILL.md +3 -3
  59. package/codeAgent/tools/AkanCli.ts +1 -1
  60. package/codeAgent/tools/AkanToolPack.ts +2 -2
  61. package/codeAgent/tools/akanCodePlugins.test.ts +1 -1
  62. package/commandDecorators/command.ts +35 -6
  63. package/commandDecorators/commandBuilder.ts +1 -1
  64. package/commandDecorators/commandDecorators.test.ts +107 -6
  65. package/commandDecorators/targetMeta.ts +2 -0
  66. package/commandDecorators/workspaceVersionCheck.test.ts +70 -1
  67. package/commandDecorators/workspaceVersionCheck.ts +64 -14
  68. package/context/akanContext.ts +576 -0
  69. package/context/akanContextInspection.ts +296 -0
  70. package/{akanMcpContract.test.ts → context/akanMcpContract.test.ts} +1 -1
  71. package/{akanMcpContract.ts → context/akanMcpContract.ts} +16 -256
  72. package/context/doctor/agentGuideCheck.ts +81 -0
  73. package/context/doctor/configLeftoverCheck.ts +35 -0
  74. package/context/doctor/doctorFindings.ts +70 -0
  75. package/context/doctor/generatedFreshness.ts +56 -0
  76. package/context/doctor/moduleShapeCheck.ts +88 -0
  77. package/context/doctor/recipeDuplicateCheck.ts +42 -0
  78. package/context/doctor/recipeIndexCheck.ts +87 -0
  79. package/context/doctor/rootShapeCheck.ts +55 -0
  80. package/context/doctor/workflowScope.ts +97 -0
  81. package/{recipeScanner.test.ts → context/recipeScanner.test.ts} +1 -1
  82. package/context/safeRead.ts +9 -0
  83. package/csrE2e/csrE2eHarness.fixture.ts +1 -1
  84. package/devkitUtils.test.ts +39 -5
  85. package/{apiReference.test.ts → docs/apiReference.test.ts} +4 -4
  86. package/{apiReference.ts → docs/apiReference.ts} +2 -2
  87. package/docs/errorCodeReference.test.ts +282 -0
  88. package/docs/errorCodeReference.ts +71 -0
  89. package/docs/errorCodeScan.ts +551 -0
  90. package/{frameworkGraph.test.ts → docs/frameworkGraph.test.ts} +1 -1
  91. package/executors/appExecutor.ts +463 -0
  92. package/executors/commandExecutionError.ts +53 -0
  93. package/executors/executor.ts +527 -0
  94. package/{executors.linkFallback.test.ts → executors/executors.linkFallback.test.ts} +1 -1
  95. package/{executors.test.ts → executors/executors.test.ts} +106 -18
  96. package/executors/index.ts +8 -0
  97. package/executors/libExecutor.ts +23 -0
  98. package/executors/moduleExecutor.ts +18 -0
  99. package/executors/pkgExecutor.ts +129 -0
  100. package/executors/sysExecutor.ts +301 -0
  101. package/executors/workspaceExecutor.ts +277 -0
  102. package/frontendBuild/allRoutesBuilder.test.ts +1 -1
  103. package/frontendBuild/autoImportSync.test.ts +1 -1
  104. package/frontendBuild/autoImportSync.ts +1 -1
  105. package/frontendBuild/buildCacheStamp.test.ts +42 -0
  106. package/frontendBuild/buildCacheStamp.ts +23 -0
  107. package/frontendBuild/buildRouteClient.test.ts +1 -1
  108. package/frontendBuild/clientEntriesBundler.test.ts +1 -1
  109. package/frontendBuild/csrArtifactBuilder.test.ts +1 -1
  110. package/frontendBuild/csrDevArtifactWriter.ts +1 -1
  111. package/frontendBuild/cssCandidateCache.test.ts +70 -1
  112. package/frontendBuild/cssCandidateCache.ts +17 -10
  113. package/frontendBuild/cssCompiler.test.ts +3 -2
  114. package/frontendBuild/devGeneratedIndexSync.test.ts +1 -1
  115. package/frontendBuild/devGeneratedIndexSync.ts +7 -38
  116. package/frontendBuild/dictionaryAssetBuilder.test.ts +1 -1
  117. package/frontendBuild/fontOptimizer.test.ts +145 -4
  118. package/frontendBuild/fontOptimizer.ts +103 -18
  119. package/frontendBuild/fontPruner.test.ts +1 -1
  120. package/frontendBuild/frontendBuild.test.ts +3 -3
  121. package/frontendBuild/hmrWatcher.stop.test.ts +63 -0
  122. package/frontendBuild/hmrWatcher.test.ts +1 -1
  123. package/frontendBuild/hmrWatcher.ts +22 -1
  124. package/frontendBuild/mcpAppViewBuilder.test.ts +1 -1
  125. package/frontendBuild/mcpAppViewBuilder.ts +1 -1
  126. package/frontendBuild/nativeCore.test.ts +1 -1
  127. package/frontendBuild/optionalPeers.test.ts +36 -8
  128. package/frontendBuild/pagesBundleBuilder.test.ts +2 -3
  129. package/frontendBuild/pagesBundleBuilder.ts +1 -1
  130. package/frontendBuild/precompressArtifacts.test.ts +1 -1
  131. package/frontendBuild/precompressArtifacts.ts +19 -6
  132. package/frontendBuild/serverGraphFile.ts +1 -1
  133. package/frontendBuild/sourceMtimeIndex.test.ts +1 -1
  134. package/frontendBuild/ssrBaseArtifactBuilder.test.ts +30 -1
  135. package/frontendBuild/ssrBaseArtifactBuilder.ts +40 -12
  136. package/frontendBuild/ssrDevBundler.test.ts +1 -1
  137. package/frontendBuild/vendorImportScanner.test.ts +1 -1
  138. package/frontendBuild/vendorNarrowing.test.ts +1 -1
  139. package/frontendBuild/watchRootResolver.test.ts +1 -1
  140. package/{agentAssets.test.ts → guideline/agentAssets.test.ts} +1 -1
  141. package/{agentAssets.ts → guideline/agentAssets.ts} +2 -2
  142. package/{agentsIndex.test.ts → guideline/agentsIndex.test.ts} +2 -2
  143. package/{agentsIndex.ts → guideline/agentsIndex.ts} +13 -10
  144. package/{conventionSet.test.ts → guideline/conventionSet.test.ts} +7 -4
  145. package/{conventionSet.ts → guideline/conventionSet.ts} +1 -1
  146. package/{prompter.ts → guideline/prompter.ts} +2 -3
  147. package/incrementalBuilder/buildBatch.proc.ts +16 -5
  148. package/incrementalBuilder/buildBatchProtocol.ts +3 -0
  149. package/incrementalBuilder/buildBatchRunner.test.ts +122 -2
  150. package/incrementalBuilder/buildBatchRunner.ts +17 -4
  151. package/incrementalBuilder/builderBoot.ts +113 -0
  152. package/incrementalBuilder/builderBuildStatus.ts +23 -0
  153. package/incrementalBuilder/builderChannel.test.ts +1 -1
  154. package/incrementalBuilder/builderChannel.ts +19 -2
  155. package/incrementalBuilder/builderGraphPayloads.ts +3 -3
  156. package/incrementalBuilder/builderLanes.ts +157 -0
  157. package/incrementalBuilder/builderWatch.ts +213 -0
  158. package/incrementalBuilder/csrRegistry.ts +234 -0
  159. package/incrementalBuilder/incrementalBuilder.host.test.ts +16 -0
  160. package/incrementalBuilder/incrementalBuilder.host.ts +7 -1
  161. package/incrementalBuilder/incrementalBuilder.proc.test.ts +142 -7
  162. package/incrementalBuilder/incrementalBuilder.proc.ts +82 -823
  163. package/incrementalBuilder/ssrRegistry.ts +282 -0
  164. package/index.ts +22 -22
  165. package/integration/devStability.integration.test.ts +62 -56
  166. package/integration/devStabilityHarness.test.ts +1 -1
  167. package/lint/__fixtures__/no-import-common-err/bad.tsx +13 -0
  168. package/lint/__fixtures__/no-import-common-err/good.tsx +12 -0
  169. package/{biomeBase.test.ts → lint/biomeBase.test.ts} +1 -1
  170. package/lint/gritRules.test.ts +1 -1
  171. package/{linter.test.ts → lint/linter.test.ts} +1 -1
  172. package/lint/no-import-common-err.grit +31 -0
  173. package/lint/no-init-fetch-in-client.grit +1 -1
  174. package/mobile/desktopBin.test.ts +1 -1
  175. package/mobile/desktopRelease.test.ts +1 -1
  176. package/mobile/desktopServerStage.test.ts +2 -2
  177. package/mobile/desktopServerStage.ts +1 -1
  178. package/mobile/nativeApi.test.ts +1 -1
  179. package/mobile/nativeApp.test.ts +1 -1
  180. package/mobile/nativeConfig.test.ts +1 -1
  181. package/mobile/nativePluginFolders.test.ts +1 -1
  182. package/mobile/nativePublicEnv.test.ts +1 -1
  183. package/mobile/nativePublicEnv.ts +2 -1
  184. package/mobile/nativeWebDir.test.ts +1 -1
  185. package/mobile/serverBundleSecrets.test.ts +1 -1
  186. package/mobile/tarWriter.test.ts +1 -1
  187. package/mobile/updatePackFolder.test.ts +1 -1
  188. package/package.json +173 -9
  189. package/packageExports.test.ts +20 -2
  190. package/piDependencyPins.test.ts +1 -1
  191. package/pipeline/PipelineDefinition.ts +1 -1
  192. package/platformTest/IdleWatchedProcess.test.ts +1 -1
  193. package/platformTest/LinuxDockerTarget.ts +1 -1
  194. package/platformTest/PlatformTestRun.test.ts +1 -1
  195. package/platformTest/TestSnapshot.test.ts +1 -1
  196. package/platformTest/WindowsSshTarget.ts +1 -1
  197. package/preview/previewView.test.ts +23 -1
  198. package/{abstractDoc.test.ts → quality/abstractDoc.test.ts} +2 -2
  199. package/{abstractDoc.ts → quality/abstractDoc.ts} +1 -1
  200. package/quality/bareErrorScanner.ts +126 -0
  201. package/{maintainabilityBaseline.test.ts → quality/maintainabilityBaseline.test.ts} +73 -0
  202. package/{maintainabilityBaseline.ts → quality/maintainabilityBaseline.ts} +97 -9
  203. package/{maintainabilityContract.test.ts → quality/maintainabilityContract.test.ts} +383 -2
  204. package/{maintainabilityContract.ts → quality/maintainabilityContract.ts} +151 -29
  205. package/{maintainabilityExceptionScanner.test.ts → quality/maintainabilityExceptionScanner.test.ts} +15 -1
  206. package/{maintainabilityExceptionScanner.ts → quality/maintainabilityExceptionScanner.ts} +5 -1
  207. package/{maintainabilityLimits.ts → quality/maintainabilityLimits.ts} +12 -0
  208. package/{maintainabilityReport.ts → quality/maintainabilityReport.ts} +20 -3
  209. package/{qualityScanner.test.ts → quality/qualityScanner.test.ts} +41 -1
  210. package/{qualityScanner.ts → quality/qualityScanner.ts} +25 -91
  211. package/{storeAccessScanner.ts → quality/storeAccessScanner.ts} +15 -2
  212. package/quality/workspaceSourceFiles.ts +82 -0
  213. package/{subspace.test.ts → subspace/subspace.test.ts} +25 -4
  214. package/{subspace.ts → subspace/subspace.ts} +5 -5
  215. package/{subspaceClone.ts → subspace/subspaceClone.ts} +8 -8
  216. package/{subspaceConfig.ts → subspace/subspaceConfig.ts} +5 -1
  217. package/{testHelpers.ts → test/testHelpers.ts} +37 -1
  218. package/transforms/barrelAnalyzer.ts +31 -10
  219. package/transforms/browserDirnamePlugin.test.ts +1 -1
  220. package/transforms/externalizeFrameworkPlugin.test.ts +1 -1
  221. package/transforms/mcpAppPageTrimmer.test.ts +1 -1
  222. package/transforms/pureLazyMarker.test.ts +1 -1
  223. package/transforms/serverEnvPlugin.test.ts +1 -1
  224. package/transforms/serverEnvProfile.test.ts +1 -1
  225. package/transforms/sideEffectImportOrder.test.ts +1 -1
  226. package/transforms/transforms.test.ts +52 -2
  227. package/transforms/tsconfigPackageResolver.test.ts +1 -1
  228. package/{createTunnel.test.ts → tunnel/createTunnel.test.ts} +1 -1
  229. package/{createTunnel.ts → tunnel/createTunnel.ts} +2 -2
  230. package/{sshHostKeys.ts → tunnel/sshHostKeys.ts} +2 -2
  231. package/typecheck/projectTypecheck.test.ts +23 -1
  232. package/typecheck/projectTypecheck.ts +10 -2
  233. package/{typeChecker.test.ts → typecheck/typeChecker.test.ts} +1 -1
  234. package/{typeChecker.ts → typecheck/typeChecker.ts} +5 -4
  235. package/typecheck/typecheck.proc.ts +6 -2
  236. package/typecheck/typecheckFailure.ts +1 -1
  237. package/util/errorReport.ts +66 -0
  238. package/{fileSys.test.ts → util/fileSys.test.ts} +13 -0
  239. package/{fileSys.ts → util/fileSys.ts} +2 -2
  240. package/{jsonFormatter.test.ts → util/jsonFormatter.test.ts} +1 -1
  241. package/workflow/constantSource.ts +187 -0
  242. package/workflow/dictionarySource.ts +184 -0
  243. package/workflow/executor.ts +6 -9
  244. package/workflow/fieldExpression.ts +153 -0
  245. package/workflow/fieldLabel.ts +61 -0
  246. package/workflow/fieldOrder.ts +117 -0
  247. package/workflow/fieldType.ts +2 -1
  248. package/workflow/guardCatalog.test.ts +1 -1
  249. package/workflow/keyRename.ts +1 -1
  250. package/workflow/moduleIndex.test.ts +2 -2
  251. package/workflow/moduleIndex.ts +2 -2
  252. package/workflow/modulePaths.ts +27 -0
  253. package/workflow/mutationScaffold.ts +7 -15
  254. package/workflow/mutationSource.ts +2 -1
  255. package/workflow/plan.ts +2 -1
  256. package/workflow/primitiveReport.ts +78 -0
  257. package/workflow/rolloutGate.test.ts +1 -1
  258. package/workflow/rolloutGate.ts +1 -1
  259. package/workflow/serviceSource.ts +33 -0
  260. package/workflow/signalSource.ts +96 -0
  261. package/workflow/source.ts +50 -1100
  262. package/workflow/sourceAst.ts +30 -0
  263. package/workflow/sourceImports.ts +105 -0
  264. package/workflow/sourceText.ts +13 -0
  265. package/workflow/templateSource.ts +30 -0
  266. package/workflow/testSource.ts +31 -0
  267. package/workflow/types.ts +1 -1
  268. package/workflow/uiPolicy.ts +1 -1
  269. package/{appSelectionMemory.ts → workspace/appSelectionMemory.ts} +1 -1
  270. package/{codegenLock.test.ts → workspace/codegenLock.test.ts} +1 -1
  271. package/{dependencyScanner.test.ts → workspace/dependencyScanner.test.ts} +1 -1
  272. package/{dependencyScanner.ts → workspace/dependencyScanner.ts} +2 -2
  273. package/{envSeed.test.ts → workspace/envSeed.test.ts} +2 -2
  274. package/{envSeed.ts → workspace/envSeed.ts} +1 -1
  275. package/{libSource.test.ts → workspace/libSource.test.ts} +2 -2
  276. package/{libSource.ts → workspace/libSource.ts} +1 -1
  277. package/{scanInfo.ts → workspace/scanInfo.ts} +21 -10
  278. package/{slicePlanner.test.ts → workspace/slicePlanner.test.ts} +2 -2
  279. package/{slicePlanner.ts → workspace/slicePlanner.ts} +1 -1
  280. package/{workspaceGraph.test.ts → workspace/workspaceGraph.test.ts} +1 -1
  281. package/{workspaceGraph.ts → workspace/workspaceGraph.ts} +1 -1
  282. package/{workspaceLayout.test.ts → workspace/workspaceLayout.test.ts} +1 -1
  283. package/{workspaceLayout.ts → workspace/workspaceLayout.ts} +3 -1
  284. package/akanContext.ts +0 -1083
  285. package/executors.ts +0 -1749
  286. /package/{applicationBuildReporter.test.ts → app/applicationBuildReporter.test.ts} +0 -0
  287. /package/{akanMcpToolError.ts → context/akanMcpToolError.ts} +0 -0
  288. /package/{moduleFieldNames.test.ts → context/moduleFieldNames.test.ts} +0 -0
  289. /package/{moduleFieldNames.ts → context/moduleFieldNames.ts} +0 -0
  290. /package/{recipeScanner.ts → context/recipeScanner.ts} +0 -0
  291. /package/{declarationReader.ts → docs/declarationReader.ts} +0 -0
  292. /package/{frameworkGraph.ts → docs/frameworkGraph.ts} +0 -0
  293. /package/{biomeBase.ts → lint/biomeBase.ts} +0 -0
  294. /package/{linter.ts → lint/linter.ts} +0 -0
  295. /package/{commentDensityScanner.test.ts → quality/commentDensityScanner.test.ts} +0 -0
  296. /package/{commentDensityScanner.ts → quality/commentDensityScanner.ts} +0 -0
  297. /package/{componentSizeScanner.test.ts → quality/componentSizeScanner.test.ts} +0 -0
  298. /package/{componentSizeScanner.ts → quality/componentSizeScanner.ts} +0 -0
  299. /package/{componentWriteChainScanner.test.ts → quality/componentWriteChainScanner.test.ts} +0 -0
  300. /package/{componentWriteChainScanner.ts → quality/componentWriteChainScanner.ts} +0 -0
  301. /package/{deprecatedCommentScanner.test.ts → quality/deprecatedCommentScanner.test.ts} +0 -0
  302. /package/{deprecatedCommentScanner.ts → quality/deprecatedCommentScanner.ts} +0 -0
  303. /package/{endpointReach.test.ts → quality/endpointReach.test.ts} +0 -0
  304. /package/{endpointReach.ts → quality/endpointReach.ts} +0 -0
  305. /package/{formSetterScanner.test.ts → quality/formSetterScanner.test.ts} +0 -0
  306. /package/{formSetterScanner.ts → quality/formSetterScanner.ts} +0 -0
  307. /package/{kindBranchScanner.test.ts → quality/kindBranchScanner.test.ts} +0 -0
  308. /package/{kindBranchScanner.ts → quality/kindBranchScanner.ts} +0 -0
  309. /package/{maintainabilityReport.test.ts → quality/maintainabilityReport.test.ts} +0 -0
  310. /package/{renderMutationScanner.test.ts → quality/renderMutationScanner.test.ts} +0 -0
  311. /package/{renderMutationScanner.ts → quality/renderMutationScanner.ts} +0 -0
  312. /package/{serviceLoopCallScanner.test.ts → quality/serviceLoopCallScanner.test.ts} +0 -0
  313. /package/{serviceLoopCallScanner.ts → quality/serviceLoopCallScanner.ts} +0 -0
  314. /package/{signalMutationIndex.test.ts → quality/signalMutationIndex.test.ts} +0 -0
  315. /package/{signalMutationIndex.ts → quality/signalMutationIndex.ts} +0 -0
  316. /package/{sourceComments.test.ts → quality/sourceComments.test.ts} +0 -0
  317. /package/{sourceComments.ts → quality/sourceComments.ts} +0 -0
  318. /package/{ssrScanner.test.ts → quality/ssrScanner.test.ts} +0 -0
  319. /package/{ssrScanner.ts → quality/ssrScanner.ts} +0 -0
  320. /package/{storeAccessScanner.test.ts → quality/storeAccessScanner.test.ts} +0 -0
  321. /package/{storeSource.ts → quality/storeSource.ts} +0 -0
  322. /package/{storeWriteScanner.test.ts → quality/storeWriteScanner.test.ts} +0 -0
  323. /package/{storeWriteScanner.ts → quality/storeWriteScanner.ts} +0 -0
  324. /package/{structureScanner.test.ts → quality/structureScanner.test.ts} +0 -0
  325. /package/{structureScanner.ts → quality/structureScanner.ts} +0 -0
  326. /package/{testOnlyExportScanner.test.ts → quality/testOnlyExportScanner.test.ts} +0 -0
  327. /package/{testOnlyExportScanner.ts → quality/testOnlyExportScanner.ts} +0 -0
  328. /package/{writePath.test.ts → quality/writePath.test.ts} +0 -0
  329. /package/{writePath.ts → quality/writePath.ts} +0 -0
  330. /package/{writePlacementScanner.test.ts → quality/writePlacementScanner.test.ts} +0 -0
  331. /package/{writePlacementScanner.ts → quality/writePlacementScanner.ts} +0 -0
  332. /package/{writingActionIndex.test.ts → quality/writingActionIndex.test.ts} +0 -0
  333. /package/{writingActionIndex.ts → quality/writingActionIndex.ts} +0 -0
  334. /package/{subspaceReport.ts → subspace/subspaceReport.ts} +0 -0
  335. /package/{sshTunnel.ts → tunnel/sshTunnel.ts} +0 -0
  336. /package/{fileEditor.ts → util/fileEditor.ts} +0 -0
  337. /package/{jsonFormatter.ts → util/jsonFormatter.ts} +0 -0
  338. /package/{selectModel.ts → util/selectModel.ts} +0 -0
  339. /package/{semver.test.ts → util/semver.test.ts} +0 -0
  340. /package/{semver.ts → util/semver.ts} +0 -0
  341. /package/{shellOnlyEnv.test.ts → util/shellOnlyEnv.test.ts} +0 -0
  342. /package/{shellOnlyEnv.ts → util/shellOnlyEnv.ts} +0 -0
  343. /package/{spinner.test.ts → util/spinner.test.ts} +0 -0
  344. /package/{spinner.ts → util/spinner.ts} +0 -0
  345. /package/{stripAnsi.ts → util/stripAnsi.ts} +0 -0
  346. /package/{codegenLock.ts → workspace/codegenLock.ts} +0 -0
  347. /package/{getRelatedCnsts.ts → workspace/getRelatedCnsts.ts} +0 -0
  348. /package/{gitRevision.test.ts → workspace/gitRevision.test.ts} +0 -0
  349. /package/{gitRevision.ts → workspace/gitRevision.ts} +0 -0
  350. /package/{manifestDependencies.ts → workspace/manifestDependencies.ts} +0 -0
  351. /package/{packageExportsMap.ts → workspace/packageExportsMap.ts} +0 -0
  352. /package/{repoIdentity.ts → workspace/repoIdentity.ts} +0 -0
  353. /package/{types.ts → workspace/types.ts} +0 -0
@@ -0,0 +1,551 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import path from "node:path";
3
+ import ts from "typescript";
4
+ import { MaintainabilityLimits } from "../quality/maintainabilityLimits";
5
+
6
+ export interface ErrorCodeRow {
7
+ code: string | null;
8
+ byStatus: boolean;
9
+ statusCode: number | null;
10
+ error: string;
11
+ forwarded: boolean;
12
+ wire: boolean;
13
+ file: string;
14
+ }
15
+
16
+ const byStatus = Symbol("byStatus");
17
+
18
+ type Value = string | number | undefined | typeof byStatus;
19
+ type Values = readonly Value[] | null;
20
+ type Env = ReadonlyMap<string, Binding>;
21
+ type Pins = ReadonlyMap<ts.ParameterDeclaration, Value>;
22
+
23
+ interface Binding {
24
+ values: Values;
25
+ source: { expression: ts.Expression; env: Env } | null;
26
+ }
27
+
28
+ interface Call {
29
+ args: readonly ts.Expression[];
30
+ env: Env;
31
+ }
32
+
33
+ interface Evaluation {
34
+ codes: Values;
35
+ statuses: Values;
36
+ }
37
+
38
+ type ClassNode = ts.ClassDeclaration | ts.ClassExpression;
39
+
40
+ const unwrapped = (expression: ts.Expression) => {
41
+ let current = expression;
42
+ while (
43
+ ts.isParenthesizedExpression(current) ||
44
+ ts.isAsExpression(current) ||
45
+ ts.isSatisfiesExpression(current) ||
46
+ ts.isNonNullExpression(current)
47
+ )
48
+ current = current.expression;
49
+ return current;
50
+ };
51
+
52
+ const isClassNode = (node: ts.Node | undefined): node is ClassNode =>
53
+ !!node && (ts.isClassDeclaration(node) || ts.isClassExpression(node));
54
+
55
+ const statusCodeOf = (property: ts.ObjectLiteralElementLike): ts.Expression | null => {
56
+ if (ts.isPropertyAssignment(property) && property.name.getText() === "statusCode") return property.initializer;
57
+ if (ts.isShorthandPropertyAssignment(property) && property.name.text === "statusCode") return property.name;
58
+ return null;
59
+ };
60
+
61
+ const byCodeUnit = (a: string, b: string) => (a < b ? -1 : a > b ? 1 : 0);
62
+
63
+ export class ErrorCodeScan {
64
+ readonly #dir: string;
65
+ readonly #roots: ReadonlySet<string>;
66
+ readonly #program: ts.Program;
67
+ readonly #checker: ts.TypeChecker;
68
+ readonly #akanError: ts.ClassDeclaration;
69
+ readonly #statuses: ReadonlyMap<number, readonly [code: string, reason: string]>;
70
+ readonly #callSites = new Map<ClassNode, Call[]>();
71
+ readonly #descends = new Map<ClassNode, boolean>();
72
+
73
+ constructor(akanjsDir: string) {
74
+ this.#dir = akanjsDir;
75
+ this.#roots = ErrorCodeScan.#rootsOf(akanjsDir);
76
+ const configPath = path.join(akanjsDir, "tsconfig.json");
77
+ const config = ts.sys.fileExists(configPath) ? ts.readConfigFile(configPath, ts.sys.readFile).config : {};
78
+ const parsed = ts.parseJsonConfigFileContent(config, ts.sys, akanjsDir, undefined, configPath);
79
+ this.#program = ts.createProgram({
80
+ rootNames: [...this.#roots].map((file) => path.join(akanjsDir, file)),
81
+ options: { ...parsed.options, noEmit: true },
82
+ });
83
+ this.#checker = this.#program.getTypeChecker();
84
+ const base = this.#program.getSourceFile(path.join(akanjsDir, "base", "akanError.ts"));
85
+ const akanError = base?.statements.find(
86
+ (statement): statement is ts.ClassDeclaration =>
87
+ ts.isClassDeclaration(statement) && statement.name?.text === "AkanError",
88
+ );
89
+ if (!akanError) throw new Error(`${akanjsDir}/base/akanError.ts declares no AkanError class`);
90
+ this.#akanError = akanError;
91
+ this.#statuses = ErrorCodeScan.#statusTableOf(akanError);
92
+ }
93
+
94
+ get statuses() {
95
+ return this.#statuses;
96
+ }
97
+
98
+ rows(): ErrorCodeRow[] {
99
+ const classes = this.#classes();
100
+ for (const call of this.#newExpressions()) {
101
+ const target = this.#classOf(call.expression);
102
+ if (target && classes.includes(target))
103
+ this.#callSites.set(target, [
104
+ ...(this.#callSites.get(target) ?? []),
105
+ { args: call.arguments ?? [], env: new Map() },
106
+ ]);
107
+ }
108
+ const rows = new Map<string, ErrorCodeRow>();
109
+ for (const node of classes) {
110
+ const forwardedOf = this.#forwardedOf(node);
111
+ const toJsonHasCode = this.#toJsonHasCode(node);
112
+ const file = this.#relative(node.getSourceFile().fileName);
113
+ for (const { codes, statuses } of this.#evaluationsOf(node))
114
+ for (const code of codes ?? [null])
115
+ for (const statusCode of statuses ?? [null]) {
116
+ const forwarded = forwardedOf(code);
117
+ const row: ErrorCodeRow = {
118
+ code: typeof code === "string" ? code : null,
119
+ byStatus: code === byStatus,
120
+ statusCode: typeof statusCode === "number" ? statusCode : null,
121
+ error: this.#nameOf(node),
122
+ forwarded,
123
+ wire: !forwarded || toJsonHasCode,
124
+ file,
125
+ };
126
+ rows.set(`${row.code}|${row.byStatus}|${row.statusCode}|${row.error}|${row.file}`, row);
127
+ }
128
+ }
129
+ return [...rows.values()].sort(ErrorCodeScan.#byCode);
130
+ }
131
+
132
+ #evaluationsOf(node: ClassNode): Evaluation[] {
133
+ const sites = this.#callSites.get(node) ?? [];
134
+ if (node === this.#akanError) return sites.map((call) => this.#akanErrorCall(call));
135
+ const free = this.#evaluate(node, null);
136
+ if (free.codes !== null && free.statuses !== null) return this.#perCode(node, free);
137
+ return sites.length ? sites.map((call) => this.#evaluate(node, call)) : [free];
138
+ }
139
+
140
+ #perCode(node: ClassNode, free: Evaluation): Evaluation[] {
141
+ const codes = free.codes ?? [];
142
+ if (codes.length < 2 || (free.statuses?.length ?? 0) < 2) return [free];
143
+ const parameter = this.#freeParametersOf(node).find((each) => {
144
+ const values = this.#literalsOf(this.#checker.getTypeAtLocation(each.name));
145
+ return values?.length === codes.length && values.every((value) => codes.includes(value));
146
+ });
147
+ if (!parameter) return [free];
148
+ return codes.map((code) => this.#evaluate(node, null, new Map([[parameter, code]])));
149
+ }
150
+
151
+ #freeParametersOf(node: ClassNode): readonly ts.ParameterDeclaration[] {
152
+ for (
153
+ let current: ClassNode | null = node;
154
+ current && current !== this.#akanError;
155
+ current = this.#baseOf(current)
156
+ ) {
157
+ const ctor = current.members.find(
158
+ (member): member is ts.ConstructorDeclaration => ts.isConstructorDeclaration(member) && !!member.body,
159
+ );
160
+ if (ctor) return ctor.parameters;
161
+ }
162
+ return [];
163
+ }
164
+
165
+ #evaluate(node: ClassNode, call: Call | null, pins: Pins = new Map()): Evaluation {
166
+ const base = this.#baseOf(node);
167
+ const ctor = node.members.find(
168
+ (member): member is ts.ConstructorDeclaration => ts.isConstructorDeclaration(member) && !!member.body,
169
+ );
170
+ if (!ctor) {
171
+ if (base === this.#akanError) return this.#akanErrorCall(call);
172
+ return base ? this.#evaluate(base, call, pins) : { codes: null, statuses: null };
173
+ }
174
+ const env = new Map<string, Binding>();
175
+ ctor.parameters.forEach((parameter, idx) => {
176
+ if (!ts.isIdentifier(parameter.name)) return;
177
+ env.set(parameter.name.text, this.#bindingOf(parameter, idx, call, env, pins));
178
+ });
179
+ const superCall = ctor.body?.statements
180
+ .map((statement) => (ts.isExpressionStatement(statement) ? unwrapped(statement.expression) : null))
181
+ .find(
182
+ (expression): expression is ts.CallExpression =>
183
+ !!expression && ts.isCallExpression(expression) && expression.expression.kind === ts.SyntaxKind.SuperKeyword,
184
+ );
185
+ if (!superCall) return { codes: null, statuses: null };
186
+ const passed: Call = { args: superCall.arguments, env };
187
+ if (base === this.#akanError) return this.#akanErrorCall(passed);
188
+ return base ? this.#evaluate(base, passed) : { codes: null, statuses: null };
189
+ }
190
+
191
+ #bindingOf(parameter: ts.ParameterDeclaration, idx: number, call: Call | null, env: Env, pins: Pins): Binding {
192
+ if (call === null) {
193
+ const pinned: Values = pins.has(parameter) ? [pins.get(parameter)] : null;
194
+ return { values: pinned ?? this.#literalsOf(this.#checker.getTypeAtLocation(parameter.name)), source: null };
195
+ }
196
+ if (parameter.dotDotDotToken || call.args.slice(0, idx + 1).some(ts.isSpreadElement))
197
+ return { values: null, source: null };
198
+ const expression = call.args[idx] ?? parameter.initializer;
199
+ if (!expression) return { values: [undefined], source: null };
200
+ const scope = call.args[idx] ? call.env : env;
201
+ return { values: this.#value(expression, scope), source: { expression, env: scope } };
202
+ }
203
+
204
+ #akanErrorCall(call: Call | null): Evaluation {
205
+ if (!call) return { codes: null, statuses: null };
206
+ const [code, , options] = call.args;
207
+ return { codes: code ? this.#value(code, call.env) : null, statuses: this.#statusOf(options, call.env) };
208
+ }
209
+
210
+ #statusOf(options: ts.Expression | undefined, env: Env): Values {
211
+ if (!options) return [500];
212
+ const inner = unwrapped(options);
213
+ const binding = ts.isIdentifier(inner) ? env.get(inner.text) : undefined;
214
+ if (binding?.source) return this.#statusOf(binding.source.expression, binding.source.env);
215
+ if (binding?.values?.every((each) => each === undefined)) return [500];
216
+ if (!ts.isObjectLiteralExpression(inner)) return this.#holdsStatusCode(inner) ? null : [500];
217
+ for (const property of [...inner.properties].reverse()) {
218
+ if (ts.isSpreadAssignment(property)) {
219
+ if (this.#holdsStatusCode(property.expression)) return null;
220
+ continue;
221
+ }
222
+ const initializer = statusCodeOf(property);
223
+ if (initializer) return this.#value(initializer, env)?.map((each) => (each === undefined ? 500 : each)) ?? null;
224
+ }
225
+ return [500];
226
+ }
227
+
228
+ #holdsStatusCode(expression: ts.Expression) {
229
+ const type = this.#checker.getNonNullableType(this.#checker.getTypeAtLocation(expression));
230
+ return !!type.getProperty("statusCode");
231
+ }
232
+
233
+ #value(expression: ts.Expression, env: Env): Values {
234
+ const inner = unwrapped(expression);
235
+ if (ts.isStringLiteral(inner) || ts.isNoSubstitutionTemplateLiteral(inner)) return [inner.text];
236
+ if (ts.isNumericLiteral(inner)) return [Number(inner.text)];
237
+ if (ts.isConditionalExpression(inner)) {
238
+ const holds = this.#holds(inner.condition, env);
239
+ if (holds !== null) return this.#value(holds ? inner.whenTrue : inner.whenFalse, env);
240
+ const [whenTrue, whenFalse] = [this.#value(inner.whenTrue, env), this.#value(inner.whenFalse, env)];
241
+ return whenTrue && whenFalse ? [...new Set([...whenTrue, ...whenFalse])] : null;
242
+ }
243
+ if (ts.isIdentifier(inner)) {
244
+ const binding = env.get(inner.text);
245
+ if (binding) return binding.values;
246
+ if (inner.text === "undefined") return [undefined];
247
+ }
248
+ if (ts.isElementAccessExpression(inner)) return this.#lookup(inner, env);
249
+ if (ts.isCallExpression(inner) && this.#isCodeOfStatus(inner.expression)) {
250
+ const [status] = inner.arguments;
251
+ const statuses = status ? this.#value(status, env) : null;
252
+ const known = statuses?.filter((each): each is number => typeof each === "number") ?? [];
253
+ return statuses && known.length === statuses.length ? known.map((each) => this.#codeOf(each)) : [byStatus];
254
+ }
255
+ return this.#literalsOf(this.#checker.getTypeAtLocation(inner));
256
+ }
257
+
258
+ #holds(condition: ts.Expression, env: Env): boolean | null {
259
+ const inner = unwrapped(condition);
260
+ if (!ts.isBinaryExpression(inner)) return null;
261
+ const operator = inner.operatorToken.kind;
262
+ const equal = operator === ts.SyntaxKind.EqualsEqualsEqualsToken;
263
+ if (!equal && operator !== ts.SyntaxKind.ExclamationEqualsEqualsToken) return null;
264
+ const [left, right] = [this.#value(inner.left, env), this.#value(inner.right, env)];
265
+ if (left?.length !== 1 || right?.length !== 1) return null;
266
+ return (left[0] === right[0]) === equal;
267
+ }
268
+
269
+ #lookup(access: ts.ElementAccessExpression, env: Env): Values {
270
+ const table = this.#tableOf(access.expression);
271
+ const keys = this.#value(access.argumentExpression, env);
272
+ if (!table || !keys) return null;
273
+ const values = new Set<Value>();
274
+ for (const key of keys) {
275
+ const entry = table.properties.find(
276
+ (property): property is ts.PropertyAssignment =>
277
+ ts.isPropertyAssignment(property) &&
278
+ (ts.isIdentifier(property.name) || ts.isStringLiteral(property.name) || ts.isNumericLiteral(property.name)) &&
279
+ property.name.text === String(key),
280
+ );
281
+ const found = entry ? this.#value(entry.initializer, new Map()) : null;
282
+ if (!found) return null;
283
+ for (const value of found) values.add(value);
284
+ }
285
+ return [...values];
286
+ }
287
+
288
+ #tableOf(expression: ts.Expression): ts.ObjectLiteralExpression | null {
289
+ const symbol = this.#checker.getSymbolAtLocation(unwrapped(expression));
290
+ for (const declaration of symbol?.declarations ?? []) {
291
+ if (!ts.isPropertyDeclaration(declaration) || !declaration.initializer) continue;
292
+ if (!(ts.getCombinedModifierFlags(declaration) & ts.ModifierFlags.Readonly)) continue;
293
+ const initializer = unwrapped(declaration.initializer);
294
+ if (ts.isObjectLiteralExpression(initializer)) return initializer;
295
+ }
296
+ return null;
297
+ }
298
+
299
+ #codeOf(statusCode: number) {
300
+ return this.#statuses.get(statusCode)?.[0] ?? `http${statusCode}`;
301
+ }
302
+
303
+ #isCodeOfStatus(callee: ts.Expression) {
304
+ return (
305
+ ts.isPropertyAccessExpression(callee) &&
306
+ callee.name.text === "codeOfStatus" &&
307
+ this.#classOf(callee.expression) === this.#akanError
308
+ );
309
+ }
310
+
311
+ #literalsOf(type: ts.Type): Values {
312
+ const members = type.isUnion() ? type.types : [type];
313
+ const values: Value[] = [];
314
+ for (const member of members) {
315
+ if (member.isStringLiteral() || member.isNumberLiteral()) values.push(member.value);
316
+ else if (!(member.flags & ts.TypeFlags.Undefined)) return null;
317
+ }
318
+ return values.length ? values : null;
319
+ }
320
+
321
+ #forwardedOf(node: ClassNode): (code: Value | null) => boolean {
322
+ for (let current: ClassNode | null = node; current; current = this.#baseOf(current)) {
323
+ const getter = current.members.find(
324
+ (member): member is ts.GetAccessorDeclaration =>
325
+ ts.isGetAccessorDeclaration(member) && member.name.getText() === "forwarded",
326
+ );
327
+ if (!getter) continue;
328
+ const [statement, ...rest] = getter.body?.statements ?? [];
329
+ const returned =
330
+ statement && !rest.length && ts.isReturnStatement(statement) && statement.expression
331
+ ? unwrapped(statement.expression)
332
+ : null;
333
+ if (returned?.kind === ts.SyntaxKind.TrueKeyword) return () => true;
334
+ if (returned?.kind === ts.SyntaxKind.FalseKeyword) return () => false;
335
+ const byCode = returned ? ErrorCodeScan.#codeComparisonOf(returned) : null;
336
+ if (byCode) return byCode;
337
+ if (returned && ErrorCodeScan.#readsRestoredState(returned)) return () => true;
338
+ throw new Error(
339
+ `${this.#nameOf(current)}'s forwarded getter returns more than a literal true or false, or this.code compared to a literal`,
340
+ );
341
+ }
342
+ return () => false;
343
+ }
344
+
345
+ //? `wireCodeOf(this) === undefined`: only a copy restored from the wire holds that state, and this scan reads `new` sites.
346
+ static #readsRestoredState(expression: ts.Expression) {
347
+ if (!ts.isBinaryExpression(expression)) return false;
348
+ if (expression.operatorToken.kind !== ts.SyntaxKind.EqualsEqualsEqualsToken) return false;
349
+ const read = unwrapped(expression.left);
350
+ const compared = unwrapped(expression.right);
351
+ return (
352
+ ts.isCallExpression(read) &&
353
+ read.arguments.length === 1 &&
354
+ read.arguments[0]?.kind === ts.SyntaxKind.ThisKeyword &&
355
+ ts.isIdentifier(compared) &&
356
+ compared.text === "undefined"
357
+ );
358
+ }
359
+
360
+ static #codeComparisonOf(expression: ts.Expression): ((code: Value | null) => boolean) | null {
361
+ if (!ts.isBinaryExpression(expression)) return null;
362
+ const operator = expression.operatorToken.kind;
363
+ const equal = operator === ts.SyntaxKind.EqualsEqualsEqualsToken;
364
+ if (!equal && operator !== ts.SyntaxKind.ExclamationEqualsEqualsToken) return null;
365
+ const isThisCode = (side: ts.Expression) => {
366
+ const property = unwrapped(side);
367
+ return (
368
+ ts.isPropertyAccessExpression(property) &&
369
+ property.expression.kind === ts.SyntaxKind.ThisKeyword &&
370
+ property.name.text === "code"
371
+ );
372
+ };
373
+ const literalOf = (side: ts.Expression) => {
374
+ const literal = unwrapped(side);
375
+ return ts.isStringLiteralLike(literal) ? literal.text : null;
376
+ };
377
+ const compared = isThisCode(expression.left)
378
+ ? literalOf(expression.right)
379
+ : isThisCode(expression.right)
380
+ ? literalOf(expression.left)
381
+ : null;
382
+ if (compared === null) return null;
383
+ return (code) => (code === compared) === equal;
384
+ }
385
+
386
+ #toJsonHasCode(node: ClassNode): boolean {
387
+ for (let current: ClassNode | null = node; current; current = this.#baseOf(current)) {
388
+ if (current === this.#akanError) return true;
389
+ const method = current.members.find(
390
+ (member): member is ts.MethodDeclaration =>
391
+ ts.isMethodDeclaration(member) && member.name.getText() === "toJSON",
392
+ );
393
+ if (!method) continue;
394
+ const returned = method.body?.statements.find(ts.isReturnStatement)?.expression;
395
+ const base = this.#baseOf(current);
396
+ return !!returned && this.#carriesCode(returned, base);
397
+ }
398
+ return true;
399
+ }
400
+
401
+ #carriesCode(expression: ts.Expression, base: ClassNode | null): boolean {
402
+ const inner = unwrapped(expression);
403
+ if (ts.isConditionalExpression(inner))
404
+ return this.#carriesCode(inner.whenTrue, base) || this.#carriesCode(inner.whenFalse, base);
405
+ if (ts.isCallExpression(inner) && ts.isPropertyAccessExpression(inner.expression))
406
+ return inner.expression.expression.kind === ts.SyntaxKind.SuperKeyword && !!base && this.#toJsonHasCode(base);
407
+ if (!ts.isObjectLiteralExpression(inner)) return false;
408
+ return inner.properties.some((property) =>
409
+ ts.isSpreadAssignment(property)
410
+ ? this.#carriesCode(property.expression, base)
411
+ : property.name?.getText() === "code",
412
+ );
413
+ }
414
+
415
+ #classes(): ClassNode[] {
416
+ const classes: ClassNode[] = [this.#akanError];
417
+ const visit = (node: ts.Node) => {
418
+ if (isClassNode(node) && node !== this.#akanError && this.#descendsFromAkanError(node)) classes.push(node);
419
+ ts.forEachChild(node, visit);
420
+ };
421
+ for (const sourceFile of this.#ownSources()) visit(sourceFile);
422
+ return classes;
423
+ }
424
+
425
+ #descendsFromAkanError(node: ClassNode): boolean {
426
+ const known = this.#descends.get(node);
427
+ if (known !== undefined) return known;
428
+ this.#descends.set(node, false);
429
+ const base = this.#baseOf(node);
430
+ const descends = !!base && (base === this.#akanError || this.#descendsFromAkanError(base));
431
+ this.#descends.set(node, descends);
432
+ return descends;
433
+ }
434
+
435
+ #baseOf(node: ClassNode): ClassNode | null {
436
+ const extended = node.heritageClauses?.find((clause) => clause.token === ts.SyntaxKind.ExtendsKeyword)?.types[0];
437
+ return extended ? this.#classOf(extended.expression) : null;
438
+ }
439
+
440
+ #classOf(expression: ts.Expression): ClassNode | null {
441
+ let symbol = this.#checker.getSymbolAtLocation(expression);
442
+ if (symbol && symbol.flags & ts.SymbolFlags.Alias) symbol = this.#checker.getAliasedSymbol(symbol);
443
+ for (const declaration of symbol?.declarations ?? []) {
444
+ if (isClassNode(declaration)) return declaration;
445
+ if (ts.isPropertyDeclaration(declaration) && declaration.initializer) {
446
+ const initializer = unwrapped(declaration.initializer);
447
+ if (isClassNode(initializer)) return initializer;
448
+ }
449
+ }
450
+ return null;
451
+ }
452
+
453
+ #nameOf(node: ClassNode) {
454
+ const { parent } = node;
455
+ if (ts.isPropertyDeclaration(parent) && isClassNode(parent.parent) && parent.parent.name)
456
+ return `${parent.parent.name.text}.${parent.name.getText()}`;
457
+ return node.name?.text ?? "(anonymous)";
458
+ }
459
+
460
+ #newExpressions() {
461
+ const found: ts.NewExpression[] = [];
462
+ const visit = (node: ts.Node) => {
463
+ if (ts.isNewExpression(node)) found.push(node);
464
+ ts.forEachChild(node, visit);
465
+ };
466
+ for (const sourceFile of this.#ownSources()) visit(sourceFile);
467
+ return found;
468
+ }
469
+
470
+ #ownSources() {
471
+ return this.#program.getSourceFiles().filter((sourceFile) => this.#roots.has(this.#relative(sourceFile.fileName)));
472
+ }
473
+
474
+ #relative(fileName: string) {
475
+ return path.relative(this.#dir, fileName).split(path.sep).join("/");
476
+ }
477
+
478
+ //? Tracked files only, unlike the gate: an untracked scratch file would otherwise shift the page CI compares.
479
+ static #sourcesOf(dir: string) {
480
+ const listed = Bun.spawnSync(["git", "ls-files", "-z", "--", "."], { cwd: dir, stdout: "pipe", stderr: "pipe" });
481
+ if (listed.exitCode !== 0) throw new Error(`git ls-files failed in ${dir}: ${listed.stderr.toString().trim()}`);
482
+ return listed.stdout
483
+ .toString()
484
+ .split("\0")
485
+ .filter((file) => file && !file.includes("node_modules/") && MaintainabilityLimits.isPackageSource(file));
486
+ }
487
+
488
+ //? Parsing every source costs seconds; a file that names no AkanError descendant can neither declare nor build one.
489
+ static #rootsOf(dir: string) {
490
+ const texts = ErrorCodeScan.#sourcesOf(dir)
491
+ .filter((file) => existsSync(path.join(dir, file)))
492
+ .map((file) => [file, readFileSync(path.join(dir, file), "utf8")] as const);
493
+ const edges = texts.flatMap(([, text]) => [...ErrorCodeScan.#extendsIn(text)]);
494
+ const names = new Set(["AkanError"]);
495
+ for (let grown = true; grown; ) {
496
+ grown = false;
497
+ for (const [name, base] of edges) {
498
+ if (!names.has(base) || names.has(name)) continue;
499
+ names.add(name);
500
+ grown = true;
501
+ }
502
+ }
503
+ const escaped = [...names].map((name) => name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
504
+ const mention = new RegExp(`(?<![\\w$])(?:${escaped.join("|")})(?![\\w$])`);
505
+ return new Set(texts.filter(([, text]) => mention.test(text)).map(([file]) => file));
506
+ }
507
+
508
+ static *#extendsIn(text: string): Generator<readonly [name: string, base: string]> {
509
+ for (const head of text.matchAll(/\bclass\s+([A-Za-z_$][\w$]*)\s*/g)) {
510
+ const [matched, name] = head;
511
+ if (!name) continue;
512
+ let at = head.index + matched.length;
513
+ for (let depth = 0; at < text.length && (text[at] === "<" || depth > 0); at++) {
514
+ if (text[at] === "<") depth++;
515
+ else if (text[at] === ">" && text[at - 1] !== "=") depth--;
516
+ }
517
+ const heritage = /\s*extends\s+([A-Za-z_$][\w$]*)/y;
518
+ heritage.lastIndex = at;
519
+ const extended: RegExpExecArray | null = heritage.exec(text);
520
+ const base = extended?.[1];
521
+ if (base) yield [name, base];
522
+ }
523
+ }
524
+
525
+ static #statusTableOf(akanError: ts.ClassDeclaration) {
526
+ const table = new Map<number, readonly [string, string]>();
527
+ const property = akanError.members.find(
528
+ (member): member is ts.PropertyDeclaration =>
529
+ ts.isPropertyDeclaration(member) && member.name.getText() === "#statuses",
530
+ );
531
+ const initializer = property?.initializer ? unwrapped(property.initializer) : null;
532
+ if (!initializer || !ts.isObjectLiteralExpression(initializer))
533
+ throw new Error("AkanError holds no #statuses table to name a status's code by");
534
+ for (const entry of initializer.properties) {
535
+ if (!ts.isPropertyAssignment(entry) || !ts.isArrayLiteralExpression(entry.initializer)) continue;
536
+ const [code, reason] = entry.initializer.elements;
537
+ if (code && reason && ts.isStringLiteral(code) && ts.isStringLiteral(reason))
538
+ table.set(Number(entry.name.getText()), [code.text, reason.text]);
539
+ }
540
+ return table;
541
+ }
542
+
543
+ static #byCode(a: ErrorCodeRow, b: ErrorCodeRow) {
544
+ return (
545
+ byCodeUnit(a.code ?? "~", b.code ?? "~") ||
546
+ Number(a.byStatus) - Number(b.byStatus) ||
547
+ (a.statusCode ?? 0) - (b.statusCode ?? 0) ||
548
+ byCodeUnit(a.error, b.error)
549
+ );
550
+ }
551
+ }
@@ -4,7 +4,7 @@ import { tmpdir } from "node:os";
4
4
  import path from "node:path";
5
5
  import { FrameworkGraph } from "./frameworkGraph";
6
6
 
7
- const workspaceRoot = path.resolve(import.meta.dir, "../../..");
7
+ const workspaceRoot = path.resolve(import.meta.dir, "../../../..");
8
8
  //? The other end of these lies outside the source read here: @akanjs/native's desktop shell answers file and secret
9
9
  //? requests, AkanApp's child reports a boot error from a code string, and the browser tab sends `sync-navigation` and
10
10
  //? handles every HmrMessage in a script string. `ws.*` and HMR `ok` have no site.