@archpilotlabs/archpilot 0.2.2 → 0.2.4

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 (298) hide show
  1. package/CHANGELOG.md +538 -0
  2. package/README.md +1 -0
  3. package/dist/archpilot-cli.js +850 -159
  4. package/dist/cli/src/archpilot-cli.js +5523 -0
  5. package/dist/cli/src/archpilot-cli.js.map +1 -0
  6. package/dist/core/src/adr/adrLoader.js +97 -0
  7. package/dist/core/src/adr/adrLoader.js.map +1 -0
  8. package/dist/core/src/adr/adrParser.js +77 -0
  9. package/dist/core/src/adr/adrParser.js.map +1 -0
  10. package/dist/core/src/adr/adrTemplate.js +45 -0
  11. package/dist/core/src/adr/adrTemplate.js.map +1 -0
  12. package/dist/core/src/adr/adrTypes.js +3 -0
  13. package/dist/core/src/adr/adrTypes.js.map +1 -0
  14. package/dist/core/src/adr/adrValidation.js +160 -0
  15. package/dist/core/src/adr/adrValidation.js.map +1 -0
  16. package/dist/core/src/adr/index.js +9 -0
  17. package/dist/core/src/adr/index.js.map +1 -0
  18. package/dist/core/src/adrManagement.js +174 -0
  19. package/dist/core/src/adrManagement.js.map +1 -0
  20. package/dist/core/src/adrRequirementStatus.js +62 -0
  21. package/dist/core/src/adrRequirementStatus.js.map +1 -0
  22. package/dist/core/src/adrScaffoldGeneration.js +325 -0
  23. package/dist/core/src/adrScaffoldGeneration.js.map +1 -0
  24. package/dist/core/src/apiDesignAnalysis.js +869 -0
  25. package/dist/core/src/apiDesignAnalysis.js.map +1 -0
  26. package/dist/core/src/applicationLayeringAnalysis.js +920 -0
  27. package/dist/core/src/applicationLayeringAnalysis.js.map +1 -0
  28. package/dist/core/src/applyRulePack.js +117 -0
  29. package/dist/core/src/applyRulePack.js.map +1 -0
  30. package/dist/core/src/architectureBaseline.js +271 -0
  31. package/dist/core/src/architectureBaseline.js.map +1 -0
  32. package/dist/core/src/architectureComponentDiscoveryDefaults.js +139 -0
  33. package/dist/core/src/architectureComponentDiscoveryDefaults.js.map +1 -0
  34. package/dist/core/src/architectureDependencyContext.js +316 -0
  35. package/dist/core/src/architectureDependencyContext.js.map +1 -0
  36. package/dist/core/src/architectureDriftDetection.js +96 -0
  37. package/dist/core/src/architectureDriftDetection.js.map +1 -0
  38. package/dist/core/src/architectureDriftTimeline.js +221 -0
  39. package/dist/core/src/architectureDriftTimeline.js.map +1 -0
  40. package/dist/core/src/architectureGovernanceBaseline.js +469 -0
  41. package/dist/core/src/architectureGovernanceBaseline.js.map +1 -0
  42. package/dist/core/src/architectureHealthHistory.js +208 -0
  43. package/dist/core/src/architectureHealthHistory.js.map +1 -0
  44. package/dist/core/src/architectureHealthScore.js +657 -0
  45. package/dist/core/src/architectureHealthScore.js.map +1 -0
  46. package/dist/core/src/architectureInit.js +826 -0
  47. package/dist/core/src/architectureInit.js.map +1 -0
  48. package/dist/core/src/architectureMap.js +727 -0
  49. package/dist/core/src/architectureMap.js.map +1 -0
  50. package/dist/core/src/architectureMigrationPreview.js +467 -0
  51. package/dist/core/src/architectureMigrationPreview.js.map +1 -0
  52. package/dist/core/src/architectureModelRefresh.js +209 -0
  53. package/dist/core/src/architectureModelRefresh.js.map +1 -0
  54. package/dist/core/src/architectureReportWorkflow.js +139 -0
  55. package/dist/core/src/architectureReportWorkflow.js.map +1 -0
  56. package/dist/core/src/architectureValidation.js +3879 -0
  57. package/dist/core/src/architectureValidation.js.map +1 -0
  58. package/dist/core/src/architectureWorkspaceModel.js +166 -0
  59. package/dist/core/src/architectureWorkspaceModel.js.map +1 -0
  60. package/dist/core/src/authorizationTenantAnalysis.js +652 -0
  61. package/dist/core/src/authorizationTenantAnalysis.js.map +1 -0
  62. package/dist/core/src/bootstrapArchitectureConfig.js +150 -0
  63. package/dist/core/src/bootstrapArchitectureConfig.js.map +1 -0
  64. package/dist/core/src/changeRisk/changeRiskAssessment.js +251 -0
  65. package/dist/core/src/changeRisk/changeRiskAssessment.js.map +1 -0
  66. package/dist/core/src/changeRisk/changeRiskTypes.js +3 -0
  67. package/dist/core/src/changeRisk/changeRiskTypes.js.map +1 -0
  68. package/dist/core/src/changeRisk/index.js +6 -0
  69. package/dist/core/src/changeRisk/index.js.map +1 -0
  70. package/dist/core/src/ci/githubInlineAnnotations.js +245 -0
  71. package/dist/core/src/ci/githubInlineAnnotations.js.map +1 -0
  72. package/dist/core/src/ci/githubPrCommentAdapter.js +232 -0
  73. package/dist/core/src/ci/githubPrCommentAdapter.js.map +1 -0
  74. package/dist/core/src/ciWorkflowTemplates.js +1042 -0
  75. package/dist/core/src/ciWorkflowTemplates.js.map +1 -0
  76. package/dist/core/src/compliance/complianceExportBuilder.js +122 -0
  77. package/dist/core/src/compliance/complianceExportBuilder.js.map +1 -0
  78. package/dist/core/src/compliance/complianceExportTypes.js +3 -0
  79. package/dist/core/src/compliance/complianceExportTypes.js.map +1 -0
  80. package/dist/core/src/compliance/complianceExportWriter.js +48 -0
  81. package/dist/core/src/compliance/complianceExportWriter.js.map +1 -0
  82. package/dist/core/src/compliance/complianceRulePackResolver.js +62 -0
  83. package/dist/core/src/compliance/complianceRulePackResolver.js.map +1 -0
  84. package/dist/core/src/config/index.js +17 -0
  85. package/dist/core/src/config/index.js.map +1 -0
  86. package/dist/core/src/config/projectConfig.js +224 -0
  87. package/dist/core/src/config/projectConfig.js.map +1 -0
  88. package/dist/core/src/config/projectIdentity.js +160 -0
  89. package/dist/core/src/config/projectIdentity.js.map +1 -0
  90. package/dist/core/src/dataQueryRiskDetection.js +1203 -0
  91. package/dist/core/src/dataQueryRiskDetection.js.map +1 -0
  92. package/dist/core/src/dependencyValidation.js +2557 -0
  93. package/dist/core/src/dependencyValidation.js.map +1 -0
  94. package/dist/core/src/discoverAdrs.js +15 -0
  95. package/dist/core/src/discoverAdrs.js.map +1 -0
  96. package/dist/core/src/drift/driftComparator.js +49 -0
  97. package/dist/core/src/drift/driftComparator.js.map +1 -0
  98. package/dist/core/src/drift/driftSnapshotLoader.js +136 -0
  99. package/dist/core/src/drift/driftSnapshotLoader.js.map +1 -0
  100. package/dist/core/src/drift/driftSnapshotTypes.js +3 -0
  101. package/dist/core/src/drift/driftSnapshotTypes.js.map +1 -0
  102. package/dist/core/src/drift/driftSnapshotWriter.js +48 -0
  103. package/dist/core/src/drift/driftSnapshotWriter.js.map +1 -0
  104. package/dist/core/src/drift/index.js +6 -0
  105. package/dist/core/src/drift/index.js.map +1 -0
  106. package/dist/core/src/eventArchitectureAnalysis.js +925 -0
  107. package/dist/core/src/eventArchitectureAnalysis.js.map +1 -0
  108. package/dist/core/src/findingTargetResolution.js +117 -0
  109. package/dist/core/src/findingTargetResolution.js.map +1 -0
  110. package/dist/core/src/generateArchitectureDiagrams.js +57 -0
  111. package/dist/core/src/generateArchitectureDiagrams.js.map +1 -0
  112. package/dist/core/src/generateImpactAnalysis.js +366 -0
  113. package/dist/core/src/generateImpactAnalysis.js.map +1 -0
  114. package/dist/core/src/generateOnboardingDocs.js +262 -0
  115. package/dist/core/src/generateOnboardingDocs.js.map +1 -0
  116. package/dist/core/src/governance/cloudConnection.js +203 -0
  117. package/dist/core/src/governance/cloudConnection.js.map +1 -0
  118. package/dist/core/src/governance/governanceContracts.js +129 -0
  119. package/dist/core/src/governance/governanceContracts.js.map +1 -0
  120. package/dist/core/src/governance/governanceGitMetadata.js +78 -0
  121. package/dist/core/src/governance/governanceGitMetadata.js.map +1 -0
  122. package/dist/core/src/governance/governanceUploadClient.js +119 -0
  123. package/dist/core/src/governance/governanceUploadClient.js.map +1 -0
  124. package/dist/core/src/governance/governanceUploadLimitErrorFormatting.js +155 -0
  125. package/dist/core/src/governance/governanceUploadLimitErrorFormatting.js.map +1 -0
  126. package/dist/core/src/governance/governanceUploadPayload.js +439 -0
  127. package/dist/core/src/governance/governanceUploadPayload.js.map +1 -0
  128. package/dist/core/src/governance/runGovernanceUpload.js +103 -0
  129. package/dist/core/src/governance/runGovernanceUpload.js.map +1 -0
  130. package/dist/core/src/impactAnalysisEngine.js +376 -0
  131. package/dist/core/src/impactAnalysisEngine.js.map +1 -0
  132. package/dist/core/src/initializationState.js +99 -0
  133. package/dist/core/src/initializationState.js.map +1 -0
  134. package/dist/core/src/managedArtifacts.js +151 -0
  135. package/dist/core/src/managedArtifacts.js.map +1 -0
  136. package/dist/core/src/moduleContractValidation.js +266 -0
  137. package/dist/core/src/moduleContractValidation.js.map +1 -0
  138. package/dist/core/src/moduleContractsGenerator.js +337 -0
  139. package/dist/core/src/moduleContractsGenerator.js.map +1 -0
  140. package/dist/core/src/moduleDiscovery.js +416 -0
  141. package/dist/core/src/moduleDiscovery.js.map +1 -0
  142. package/dist/core/src/moduleScope.js +426 -0
  143. package/dist/core/src/moduleScope.js.map +1 -0
  144. package/dist/core/src/onboardingGuidance.js +74 -0
  145. package/dist/core/src/onboardingGuidance.js.map +1 -0
  146. package/dist/core/src/operationalLogging.js +7 -0
  147. package/dist/core/src/operationalLogging.js.map +1 -0
  148. package/dist/core/src/packageVersion.js +52 -0
  149. package/dist/core/src/packageVersion.js.map +1 -0
  150. package/dist/core/src/policy/effectivePolicyResolver.js +91 -0
  151. package/dist/core/src/policy/effectivePolicyResolver.js.map +1 -0
  152. package/dist/core/src/policy/exceptionLoader.js +285 -0
  153. package/dist/core/src/policy/exceptionLoader.js.map +1 -0
  154. package/dist/core/src/policy/remotePolicyLoader.js +227 -0
  155. package/dist/core/src/policy/remotePolicyLoader.js.map +1 -0
  156. package/dist/core/src/policy/remotePolicyTypes.js +3 -0
  157. package/dist/core/src/policy/remotePolicyTypes.js.map +1 -0
  158. package/dist/core/src/policy/riskPolicyConfig.js +206 -0
  159. package/dist/core/src/policy/riskPolicyConfig.js.map +1 -0
  160. package/dist/core/src/policy/riskPolicyEnforcement.js +203 -0
  161. package/dist/core/src/policy/riskPolicyEnforcement.js.map +1 -0
  162. package/dist/core/src/policy/riskPolicyExitCode.js +16 -0
  163. package/dist/core/src/policy/riskPolicyExitCode.js.map +1 -0
  164. package/dist/core/src/policy/riskPolicyInitializer.js +90 -0
  165. package/dist/core/src/policy/riskPolicyInitializer.js.map +1 -0
  166. package/dist/core/src/quickFix/quickFixEngine.js +132 -0
  167. package/dist/core/src/quickFix/quickFixEngine.js.map +1 -0
  168. package/dist/core/src/quickFix/quickFixMessaging.js +15 -0
  169. package/dist/core/src/quickFix/quickFixMessaging.js.map +1 -0
  170. package/dist/core/src/quickFix/quickFixProviders.js +87 -0
  171. package/dist/core/src/quickFix/quickFixProviders.js.map +1 -0
  172. package/dist/core/src/quickFix/quickFixTypes.js +3 -0
  173. package/dist/core/src/quickFix/quickFixTypes.js.map +1 -0
  174. package/dist/core/src/remediation/fileHelpers.js +86 -0
  175. package/dist/core/src/remediation/fileHelpers.js.map +1 -0
  176. package/dist/core/src/remediation/fixRegistry.js +645 -0
  177. package/dist/core/src/remediation/fixRegistry.js.map +1 -0
  178. package/dist/core/src/remediation/index.js +8 -0
  179. package/dist/core/src/remediation/index.js.map +1 -0
  180. package/dist/core/src/remediation/remediationEngine.js +207 -0
  181. package/dist/core/src/remediation/remediationEngine.js.map +1 -0
  182. package/dist/core/src/reporting/adrReporter.js +59 -0
  183. package/dist/core/src/reporting/adrReporter.js.map +1 -0
  184. package/dist/core/src/reporting/architectureBaselineReporter.js +64 -0
  185. package/dist/core/src/reporting/architectureBaselineReporter.js.map +1 -0
  186. package/dist/core/src/reporting/architectureDiagramReporter.js +148 -0
  187. package/dist/core/src/reporting/architectureDiagramReporter.js.map +1 -0
  188. package/dist/core/src/reporting/architectureDriftTimelineReporter.js +44 -0
  189. package/dist/core/src/reporting/architectureDriftTimelineReporter.js.map +1 -0
  190. package/dist/core/src/reporting/architectureHealthHistoryReporter.js +51 -0
  191. package/dist/core/src/reporting/architectureHealthHistoryReporter.js.map +1 -0
  192. package/dist/core/src/reporting/architectureMapReporter.js +228 -0
  193. package/dist/core/src/reporting/architectureMapReporter.js.map +1 -0
  194. package/dist/core/src/reporting/architecturePrCommentReporter.js +324 -0
  195. package/dist/core/src/reporting/architecturePrCommentReporter.js.map +1 -0
  196. package/dist/core/src/reporting/architecturePrReviewReporter.js +389 -0
  197. package/dist/core/src/reporting/architecturePrReviewReporter.js.map +1 -0
  198. package/dist/core/src/reporting/architectureReportArtifacts.js +166 -0
  199. package/dist/core/src/reporting/architectureReportArtifacts.js.map +1 -0
  200. package/dist/core/src/reporting/architectureReviewReportGenerator.js +382 -0
  201. package/dist/core/src/reporting/architectureReviewReportGenerator.js.map +1 -0
  202. package/dist/core/src/reporting/architectureReviewReporter.js +1633 -0
  203. package/dist/core/src/reporting/architectureReviewReporter.js.map +1 -0
  204. package/dist/core/src/reporting/architectureRiskAssessment.js +101 -0
  205. package/dist/core/src/reporting/architectureRiskAssessment.js.map +1 -0
  206. package/dist/core/src/reporting/architectureScoreBadge.js +177 -0
  207. package/dist/core/src/reporting/architectureScoreBadge.js.map +1 -0
  208. package/dist/core/src/reporting/architectureSupplementalReporters.js +124 -0
  209. package/dist/core/src/reporting/architectureSupplementalReporters.js.map +1 -0
  210. package/dist/core/src/reporting/changeRiskAssessment.js +6 -0
  211. package/dist/core/src/reporting/changeRiskAssessment.js.map +1 -0
  212. package/dist/core/src/reporting/changeRiskTypes.js +3 -0
  213. package/dist/core/src/reporting/changeRiskTypes.js.map +1 -0
  214. package/dist/core/src/reporting/impactAnalysisReporter.js +111 -0
  215. package/dist/core/src/reporting/impactAnalysisReporter.js.map +1 -0
  216. package/dist/core/src/reporting/onboardingDocsReporter.js +113 -0
  217. package/dist/core/src/reporting/onboardingDocsReporter.js.map +1 -0
  218. package/dist/core/src/reporting/rulePackReporter.js +61 -0
  219. package/dist/core/src/reporting/rulePackReporter.js.map +1 -0
  220. package/dist/core/src/reporting/safetyControlsDetection.js +343 -0
  221. package/dist/core/src/reporting/safetyControlsDetection.js.map +1 -0
  222. package/dist/core/src/resolveRuleAdrs.js +31 -0
  223. package/dist/core/src/resolveRuleAdrs.js.map +1 -0
  224. package/dist/core/src/reviewGenerationWorkflow.js +220 -0
  225. package/dist/core/src/reviewGenerationWorkflow.js.map +1 -0
  226. package/dist/core/src/rulePacks/index.js +17 -0
  227. package/dist/core/src/rulePacks/index.js.map +1 -0
  228. package/dist/core/src/rulePacks/layeredMonolithRulePack.js +45 -0
  229. package/dist/core/src/rulePacks/layeredMonolithRulePack.js.map +1 -0
  230. package/dist/core/src/rulePacks/modularMonolithRulePack.js +41 -0
  231. package/dist/core/src/rulePacks/modularMonolithRulePack.js.map +1 -0
  232. package/dist/core/src/rulePacks/types.js +3 -0
  233. package/dist/core/src/rulePacks/types.js.map +1 -0
  234. package/dist/core/src/setupNextSteps.js +939 -0
  235. package/dist/core/src/setupNextSteps.js.map +1 -0
  236. package/dist/core/src/setupRefresh.js +152 -0
  237. package/dist/core/src/setupRefresh.js.map +1 -0
  238. package/dist/core/src/smartInit/apiDbHintDetection.js +836 -0
  239. package/dist/core/src/smartInit/apiDbHintDetection.js.map +1 -0
  240. package/dist/core/src/smartInit/architectureProposalBuilder.js +1215 -0
  241. package/dist/core/src/smartInit/architectureProposalBuilder.js.map +1 -0
  242. package/dist/core/src/smartInit/architectureStyleDetection.js +472 -0
  243. package/dist/core/src/smartInit/architectureStyleDetection.js.map +1 -0
  244. package/dist/core/src/smartInit/archpilotIgnore.js +139 -0
  245. package/dist/core/src/smartInit/archpilotIgnore.js.map +1 -0
  246. package/dist/core/src/smartInit/componentDetection.js +1084 -0
  247. package/dist/core/src/smartInit/componentDetection.js.map +1 -0
  248. package/dist/core/src/smartInit/implementationProfileResolution.js +53 -0
  249. package/dist/core/src/smartInit/implementationProfileResolution.js.map +1 -0
  250. package/dist/core/src/smartInit/index.js +31 -0
  251. package/dist/core/src/smartInit/index.js.map +1 -0
  252. package/dist/core/src/smartInit/moduleDetection.js +982 -0
  253. package/dist/core/src/smartInit/moduleDetection.js.map +1 -0
  254. package/dist/core/src/smartInit/projectKindDetection.js +437 -0
  255. package/dist/core/src/smartInit/projectKindDetection.js.map +1 -0
  256. package/dist/core/src/smartInit/repoTopologyDetection.js +470 -0
  257. package/dist/core/src/smartInit/repoTopologyDetection.js.map +1 -0
  258. package/dist/core/src/smartInit/runContext.js +112 -0
  259. package/dist/core/src/smartInit/runContext.js.map +1 -0
  260. package/dist/core/src/smartInit/smartInitEngine.js +94 -0
  261. package/dist/core/src/smartInit/smartInitEngine.js.map +1 -0
  262. package/dist/core/src/smartInit/stackDetection.js +503 -0
  263. package/dist/core/src/smartInit/stackDetection.js.map +1 -0
  264. package/dist/core/src/smartInit/toolingHintDetection.js +345 -0
  265. package/dist/core/src/smartInit/toolingHintDetection.js.map +1 -0
  266. package/dist/core/src/sourceScopeClassification.js +83 -0
  267. package/dist/core/src/sourceScopeClassification.js.map +1 -0
  268. package/dist/core/src/stackAdapters.js +2475 -0
  269. package/dist/core/src/stackAdapters.js.map +1 -0
  270. package/dist/core/src/stackMetadata.js +157 -0
  271. package/dist/core/src/stackMetadata.js.map +1 -0
  272. package/dist/core/src/suppressions/index.js +3 -0
  273. package/dist/core/src/suppressions/index.js.map +1 -0
  274. package/dist/core/src/suppressions/suppressionReporter.js +38 -0
  275. package/dist/core/src/suppressions/suppressionReporter.js.map +1 -0
  276. package/dist/core/src/suppressions/suppressionTypes.js +3 -0
  277. package/dist/core/src/suppressions/suppressionTypes.js.map +1 -0
  278. package/dist/core/src/suppressions/suppressionValidator.js +119 -0
  279. package/dist/core/src/suppressions/suppressionValidator.js.map +1 -0
  280. package/dist/core/src/transactionDomainAnalysis.js +1416 -0
  281. package/dist/core/src/transactionDomainAnalysis.js.map +1 -0
  282. package/dist/core/src/validation/changedFilesResolver.js +165 -0
  283. package/dist/core/src/validation/changedFilesResolver.js.map +1 -0
  284. package/dist/core/src/validationProfiling.js +33 -0
  285. package/dist/core/src/validationProfiling.js.map +1 -0
  286. package/dist/core/src/validationRuleExplanations.js +69 -0
  287. package/dist/core/src/validationRuleExplanations.js.map +1 -0
  288. package/dist/core/src/validationSourceInventory.js +200 -0
  289. package/dist/core/src/validationSourceInventory.js.map +1 -0
  290. package/dist/core/src/validationSuppressions.js +231 -0
  291. package/dist/core/src/validationSuppressions.js.map +1 -0
  292. package/dist/core/src/validationTypeScriptAstCache.js +82 -0
  293. package/dist/core/src/validationTypeScriptAstCache.js.map +1 -0
  294. package/dist/core/src/validationWorkflow.js +222 -0
  295. package/dist/core/src/validationWorkflow.js.map +1 -0
  296. package/dist/core/src/workspaceRoot.js +68 -0
  297. package/dist/core/src/workspaceRoot.js.map +1 -0
  298. package/package.json +3 -2
@@ -0,0 +1,982 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.detectModules = detectModules;
37
+ exports.detectModuleCandidatesForRoot = detectModuleCandidatesForRoot;
38
+ const fs = __importStar(require("node:fs"));
39
+ const path = __importStar(require("node:path"));
40
+ const moduleScope_1 = require("../moduleScope");
41
+ const ignoredDirectoryNames = new Set([
42
+ '.git',
43
+ '.archpilot',
44
+ '.vscode-test',
45
+ 'node_modules',
46
+ 'dist',
47
+ 'build',
48
+ 'out',
49
+ 'coverage',
50
+ '.next',
51
+ 'target',
52
+ 'vendor',
53
+ '.venv',
54
+ 'venv',
55
+ '__pycache__',
56
+ ]);
57
+ const lowValueModuleNames = new Set([
58
+ 'utils',
59
+ 'shared',
60
+ 'common',
61
+ 'lib',
62
+ 'libs',
63
+ 'core',
64
+ 'infra',
65
+ 'infrastructure',
66
+ 'config',
67
+ 'scripts',
68
+ 'test',
69
+ 'tests',
70
+ 'cypress-tests',
71
+ '__tests__',
72
+ 'fixtures',
73
+ 'docs',
74
+ 'health',
75
+ 'assets',
76
+ 'public',
77
+ 'dist',
78
+ 'build',
79
+ 'node_modules',
80
+ 'types',
81
+ 'generated',
82
+ ]);
83
+ const technicalLayerNames = new Set([
84
+ 'action',
85
+ 'actions',
86
+ 'api',
87
+ 'auth',
88
+ 'authentication',
89
+ 'authorization',
90
+ 'config',
91
+ 'configuration',
92
+ 'console',
93
+ 'controller',
94
+ 'controllers',
95
+ 'dependency',
96
+ 'dependencies',
97
+ 'dependencyinjection',
98
+ 'dto',
99
+ 'dtos',
100
+ 'entity',
101
+ 'entities',
102
+ 'exception',
103
+ 'exceptions',
104
+ 'export',
105
+ 'exports',
106
+ 'handler',
107
+ 'handlers',
108
+ 'helper',
109
+ 'helpers',
110
+ 'hook',
111
+ 'hooks',
112
+ 'http',
113
+ 'import',
114
+ 'imports',
115
+ 'interceptor',
116
+ 'interceptors',
117
+ 'job',
118
+ 'jobs',
119
+ 'mail',
120
+ 'mailer',
121
+ 'mailers',
122
+ 'middleware',
123
+ 'middlewares',
124
+ 'migration',
125
+ 'migrations',
126
+ 'model',
127
+ 'models',
128
+ 'module',
129
+ 'modules',
130
+ 'payload',
131
+ 'payloads',
132
+ 'persistence',
133
+ 'provider',
134
+ 'providers',
135
+ 'repository',
136
+ 'repositories',
137
+ 'relation',
138
+ 'relations',
139
+ 'route',
140
+ 'routes',
141
+ 'rule',
142
+ 'rules',
143
+ 'security',
144
+ 'service',
145
+ 'services',
146
+ 'setting',
147
+ 'settings',
148
+ 'schema',
149
+ 'schemas',
150
+ 'trait',
151
+ 'traits',
152
+ 'ui',
153
+ 'validation',
154
+ 'validators',
155
+ 'view',
156
+ 'views',
157
+ ]);
158
+ const sharedInfrastructureNames = new Set([
159
+ 'common',
160
+ 'commons',
161
+ 'core',
162
+ 'infra',
163
+ 'infrastructure',
164
+ 'lib',
165
+ 'libs',
166
+ 'platform',
167
+ 'shared',
168
+ 'shared-ui',
169
+ 'tooling',
170
+ 'tools',
171
+ 'util',
172
+ 'utilities',
173
+ 'utils',
174
+ ]);
175
+ const highConfidenceDomainNames = new Set([
176
+ 'account',
177
+ 'accounts',
178
+ 'billing',
179
+ 'cart',
180
+ 'catalog',
181
+ 'chat',
182
+ 'checkout',
183
+ 'customer',
184
+ 'customers',
185
+ 'inventory',
186
+ 'invoice',
187
+ 'invoices',
188
+ 'master',
189
+ 'notification',
190
+ 'notifications',
191
+ 'order',
192
+ 'orders',
193
+ 'payment',
194
+ 'payments',
195
+ 'product',
196
+ 'products',
197
+ 'reporting',
198
+ 'scorecard',
199
+ 'subscription',
200
+ 'subscriptions',
201
+ 'tenant',
202
+ 'tenants',
203
+ 'user',
204
+ 'users',
205
+ 'vendor',
206
+ 'vendors',
207
+ 'workflow',
208
+ 'workflows',
209
+ ]);
210
+ const componentRoleNames = new Set([
211
+ 'app',
212
+ 'application',
213
+ 'backend',
214
+ 'bff',
215
+ 'client',
216
+ 'engine',
217
+ 'frontend',
218
+ 'gateway',
219
+ 'ledger',
220
+ 'mobile',
221
+ 'service',
222
+ 'web',
223
+ 'worker',
224
+ ]);
225
+ const frontendUtilityDirectoryNames = new Set([
226
+ 'components',
227
+ 'hooks',
228
+ 'utils',
229
+ 'lib',
230
+ 'libs',
231
+ 'common',
232
+ 'shared-ui',
233
+ 'styles',
234
+ 'assets',
235
+ 'public',
236
+ ]);
237
+ const appRouteReservedDirectoryNames = new Set([
238
+ 'api',
239
+ 'components',
240
+ 'hooks',
241
+ 'utils',
242
+ 'lib',
243
+ 'common',
244
+ 'shared-ui',
245
+ ]);
246
+ const sourceFileExtensions = new Set([
247
+ '.ts',
248
+ '.tsx',
249
+ '.js',
250
+ '.jsx',
251
+ '.vue',
252
+ '.java',
253
+ '.py',
254
+ '.php',
255
+ '.go',
256
+ '.cs',
257
+ '.rb',
258
+ '.kt',
259
+ '.swift',
260
+ '.rs',
261
+ ]);
262
+ const roleFileHints = [
263
+ 'index.ts',
264
+ 'index.js',
265
+ 'service.ts',
266
+ 'service.js',
267
+ 'controller.ts',
268
+ 'controller.js',
269
+ 'repository.ts',
270
+ 'repository.js',
271
+ 'routes.ts',
272
+ 'routes.js',
273
+ 'handler.ts',
274
+ 'handler.js',
275
+ 'model.ts',
276
+ 'model.js',
277
+ 'schema.ts',
278
+ 'schema.js',
279
+ 'dto.ts',
280
+ 'dto.js',
281
+ 'page.tsx',
282
+ 'page.jsx',
283
+ 'layout.tsx',
284
+ 'layout.jsx',
285
+ 'route.ts',
286
+ 'route.js',
287
+ 'view.vue',
288
+ 'page.vue',
289
+ ];
290
+ function normalizePath(value) {
291
+ return value.replaceAll('\\', '/');
292
+ }
293
+ function isUnderJvmResourceRoot(relativePath) {
294
+ return /(^|\/)src\/main\/resources(?:\/|$)/u.test(normalizePath(relativePath).toLowerCase());
295
+ }
296
+ function safeReadDirEntries(directoryPath) {
297
+ try {
298
+ return fs.readdirSync(directoryPath, { withFileTypes: true });
299
+ }
300
+ catch {
301
+ return [];
302
+ }
303
+ }
304
+ function pathExists(pathValue) {
305
+ try {
306
+ fs.accessSync(pathValue);
307
+ return true;
308
+ }
309
+ catch {
310
+ return false;
311
+ }
312
+ }
313
+ function isIgnoredPath(context, relativePath) {
314
+ return context?.ignoreMatcher?.isIgnored(normalizePath(relativePath)) ?? false;
315
+ }
316
+ function uniqueSorted(values) {
317
+ return [...new Set(values)].sort((left, right) => left.localeCompare(right));
318
+ }
319
+ function isLowValueModuleName(moduleName) {
320
+ return lowValueModuleNames.has(moduleName.trim().toLowerCase());
321
+ }
322
+ function moduleNameSegments(moduleName) {
323
+ return moduleName
324
+ .toLowerCase()
325
+ .split(/[\/._-]+/u)
326
+ .map((segment) => segment.trim())
327
+ .filter((segment) => segment.length > 0);
328
+ }
329
+ function normalizeIdentity(value) {
330
+ return value
331
+ .toLowerCase()
332
+ .replace(/[^a-z0-9]+/gu, '');
333
+ }
334
+ function pathLeafIdentity(value) {
335
+ const normalized = normalizePath(value).replace(/\/+$/gu, '');
336
+ const leaf = normalized.split('/').filter((segment) => segment.length > 0).at(-1) ?? normalized;
337
+ return normalizeIdentity(leaf);
338
+ }
339
+ function getComponentAlignedEvidence(input) {
340
+ const modulePath = normalizePath(input.modulePath).replace(/\/+$/gu, '');
341
+ const moduleNameIdentity = normalizeIdentity(input.moduleName);
342
+ const modulePathLeaf = pathLeafIdentity(modulePath);
343
+ const matchingPath = input.context?.componentPaths
344
+ ?.map((entry) => normalizePath(entry).replace(/\/+$/gu, ''))
345
+ .find((componentPath) => componentPath.length > 0 &&
346
+ componentPath !== '.' &&
347
+ (componentPath === modulePath ||
348
+ componentPath.startsWith(`${modulePath}/`)));
349
+ if (matchingPath) {
350
+ return `Matches detected component/service/app path ${matchingPath}`;
351
+ }
352
+ const matchingName = input.context?.componentNames
353
+ ?.map(normalizeIdentity)
354
+ .find((identity) => identity.length > 0 && (identity === moduleNameIdentity || identity === modulePathLeaf));
355
+ if (matchingName) {
356
+ return `Matches detected component/service/app identity ${input.moduleName}`;
357
+ }
358
+ const matchingResourcePath = input.context?.resourcePaths
359
+ ?.map((entry) => normalizePath(entry).replace(/\/+$/gu, ''))
360
+ .find((resourcePath) => resourcePath.length > 0 &&
361
+ resourcePath !== '.' &&
362
+ (resourcePath === modulePath ||
363
+ resourcePath.startsWith(`${modulePath}/`)));
364
+ if (matchingResourcePath) {
365
+ return `Matches detected resource path ${matchingResourcePath}`;
366
+ }
367
+ const matchingResourceName = input.context?.resourceNames
368
+ ?.map(normalizeIdentity)
369
+ .find((identity) => identity.length > 0 && (identity === moduleNameIdentity || identity === modulePathLeaf));
370
+ if (matchingResourceName) {
371
+ return `Matches detected resource identity ${input.moduleName}`;
372
+ }
373
+ return undefined;
374
+ }
375
+ function classifyModuleCandidate(input) {
376
+ const evidence = [];
377
+ const segments = moduleNameSegments(input.moduleName);
378
+ const leafName = segments[segments.length - 1] ?? input.moduleName.toLowerCase();
379
+ const rootLeaf = moduleNameSegments(input.rootPath).at(-1) ?? '';
380
+ const hasTechnicalLayerName = segments.some((segment) => technicalLayerNames.has(segment));
381
+ const hasSharedInfrastructureName = segments.some((segment) => sharedInfrastructureNames.has(segment));
382
+ const hasDomainName = segments.some((segment) => highConfidenceDomainNames.has(segment));
383
+ const hasComponentRoleName = segments.some((segment) => componentRoleNames.has(segment));
384
+ const underExplicitArchitectureRoot = ['modules', 'features', 'domain', 'domains'].includes(rootLeaf);
385
+ const underLayerRoot = ['application', 'infrastructure'].includes(rootLeaf);
386
+ const hasLowValueName = segments.some((segment) => lowValueModuleNames.has(segment));
387
+ if (underExplicitArchitectureRoot && input.hasSourceFiles && input.sourceFileCount >= 1) {
388
+ evidence.push(`Located under explicit architecture boundary root ${input.rootPath}`);
389
+ if (hasTechnicalLayerName || hasSharedInfrastructureName || hasLowValueName) {
390
+ evidence.push(`Name '${leafName}' may be infrastructure-oriented; leaving it optional`);
391
+ }
392
+ return {
393
+ classification: 'architecture-module',
394
+ evidence,
395
+ selectedByDefault: !hasTechnicalLayerName &&
396
+ !hasSharedInfrastructureName &&
397
+ !hasLowValueName &&
398
+ (input.hasRoleFiles || input.sourceFileCount >= 1),
399
+ };
400
+ }
401
+ if (hasTechnicalLayerName) {
402
+ evidence.push(`Name '${leafName}' is commonly a technical layer or framework convention`);
403
+ return {
404
+ classification: 'technical-layer',
405
+ evidence,
406
+ selectedByDefault: false,
407
+ };
408
+ }
409
+ if (hasSharedInfrastructureName) {
410
+ evidence.push(`Name '${leafName}' is commonly shared infrastructure or implementation support`);
411
+ return {
412
+ classification: 'shared-infrastructure',
413
+ evidence,
414
+ selectedByDefault: false,
415
+ };
416
+ }
417
+ if (underLayerRoot) {
418
+ evidence.push(`Located under ${input.rootPath}, which is commonly a layered architecture partition`);
419
+ return {
420
+ classification: 'technical-layer',
421
+ evidence,
422
+ selectedByDefault: false,
423
+ };
424
+ }
425
+ if (underExplicitArchitectureRoot && segments.length > 1 && hasComponentRoleName) {
426
+ evidence.push(`Name '${input.moduleName}' combines a module root with an app/service/component role`);
427
+ return {
428
+ classification: 'uncertain',
429
+ evidence,
430
+ selectedByDefault: false,
431
+ };
432
+ }
433
+ if (hasDomainName && input.hasSourceFiles) {
434
+ evidence.push(`Name '${leafName}' matches a common business/domain capability`);
435
+ return {
436
+ classification: 'architecture-module',
437
+ evidence,
438
+ selectedByDefault: input.hasRoleFiles || input.sourceFileCount >= 1,
439
+ };
440
+ }
441
+ if (input.hasRoleFiles && input.sourceFileCount >= 2) {
442
+ evidence.push('Contains multiple role-bearing source files');
443
+ return {
444
+ classification: 'architecture-module',
445
+ evidence,
446
+ selectedByDefault: true,
447
+ };
448
+ }
449
+ evidence.push('Candidate needs review before becoming a governed architecture boundary');
450
+ return {
451
+ classification: 'uncertain',
452
+ evidence,
453
+ selectedByDefault: false,
454
+ };
455
+ }
456
+ function toStackSlots(stacks) {
457
+ if (!stacks || stacks.length === 0) {
458
+ return {};
459
+ }
460
+ if (stacks.includes('nextjs')) {
461
+ return { frontendStack: 'nextjs' };
462
+ }
463
+ if (stacks.includes('react')) {
464
+ return { frontendStack: 'react' };
465
+ }
466
+ if (stacks.includes('angular')) {
467
+ return { frontendStack: 'angular' };
468
+ }
469
+ if (stacks.includes('vue')) {
470
+ return { frontendStack: 'vue' };
471
+ }
472
+ return { backendStack: 'node_typescript' };
473
+ }
474
+ function resolveModuleScope(workspaceRoot, modulePath, context) {
475
+ return (0, moduleScope_1.classifyModuleScope)({
476
+ modulePath,
477
+ workspaceRoot,
478
+ projectKinds: context?.projectKinds,
479
+ stacks: toStackSlots(context?.stacks),
480
+ });
481
+ }
482
+ function inspectModuleFolder(absolutePath) {
483
+ let hasSourceFiles = false;
484
+ let hasRoleFiles = false;
485
+ let sourceFileCount = 0;
486
+ const queue = [{ absolutePath, depth: 0 }];
487
+ while (queue.length > 0) {
488
+ const current = queue.shift();
489
+ if (!current) {
490
+ continue;
491
+ }
492
+ const entries = safeReadDirEntries(current.absolutePath);
493
+ for (const entry of entries) {
494
+ const entryPath = path.join(current.absolutePath, entry.name);
495
+ if (entry.isDirectory()) {
496
+ if (current.depth >= 2 || ignoredDirectoryNames.has(entry.name)) {
497
+ continue;
498
+ }
499
+ queue.push({ absolutePath: entryPath, depth: current.depth + 1 });
500
+ continue;
501
+ }
502
+ if (!entry.isFile()) {
503
+ continue;
504
+ }
505
+ const extension = path.extname(entry.name).toLowerCase();
506
+ if (sourceFileExtensions.has(extension)) {
507
+ hasSourceFiles = true;
508
+ sourceFileCount += 1;
509
+ }
510
+ const fileNameLower = entry.name.toLowerCase();
511
+ if (roleFileHints.some((hint) => fileNameLower.includes(hint))) {
512
+ hasRoleFiles = true;
513
+ }
514
+ }
515
+ }
516
+ return { hasSourceFiles, hasRoleFiles, sourceFileCount };
517
+ }
518
+ function containsAppRouteFiles(absolutePath) {
519
+ const queue = [{ absolutePath, depth: 0 }];
520
+ while (queue.length > 0) {
521
+ const current = queue.shift();
522
+ if (!current) {
523
+ continue;
524
+ }
525
+ for (const entry of safeReadDirEntries(current.absolutePath)) {
526
+ const entryPath = path.join(current.absolutePath, entry.name);
527
+ if (entry.isDirectory()) {
528
+ if (current.depth >= 2 || ignoredDirectoryNames.has(entry.name)) {
529
+ continue;
530
+ }
531
+ queue.push({ absolutePath: entryPath, depth: current.depth + 1 });
532
+ continue;
533
+ }
534
+ if (!entry.isFile()) {
535
+ continue;
536
+ }
537
+ const fileNameLower = entry.name.toLowerCase();
538
+ if (fileNameLower.startsWith('page.') ||
539
+ fileNameLower.startsWith('layout.') ||
540
+ fileNameLower.startsWith('route.') ||
541
+ fileNameLower.startsWith('loading.') ||
542
+ fileNameLower.startsWith('error.')) {
543
+ return true;
544
+ }
545
+ }
546
+ }
547
+ return false;
548
+ }
549
+ function makeDetectedModule(workspaceRoot, moduleName, modulePath, rootPath, hasSourceFiles, hasRoleFiles, sourceFileCount, context) {
550
+ if (isUnderJvmResourceRoot(modulePath)) {
551
+ return undefined;
552
+ }
553
+ const evidence = [];
554
+ if (hasSourceFiles) {
555
+ evidence.push('Contains source files');
556
+ }
557
+ if (hasRoleFiles) {
558
+ evidence.push('Found service/controller/repository style files');
559
+ }
560
+ evidence.push(`Located under ${rootPath}`);
561
+ let confidence = 'low';
562
+ if (hasRoleFiles || (hasSourceFiles && !isLowValueModuleName(moduleName))) {
563
+ confidence = 'high';
564
+ }
565
+ else if (hasSourceFiles) {
566
+ confidence = 'medium';
567
+ }
568
+ if (isLowValueModuleName(moduleName)) {
569
+ confidence = confidence === 'high' ? 'medium' : 'low';
570
+ evidence.push('Module name is commonly infrastructure-oriented');
571
+ }
572
+ if (!hasSourceFiles && !hasRoleFiles) {
573
+ return undefined;
574
+ }
575
+ const candidateClassification = classifyModuleCandidate({
576
+ moduleName,
577
+ modulePath,
578
+ rootPath,
579
+ hasSourceFiles,
580
+ hasRoleFiles,
581
+ sourceFileCount,
582
+ });
583
+ evidence.push(...candidateClassification.evidence);
584
+ const componentAlignedEvidence = getComponentAlignedEvidence({
585
+ moduleName,
586
+ modulePath,
587
+ context,
588
+ });
589
+ if (componentAlignedEvidence) {
590
+ evidence.push(componentAlignedEvidence);
591
+ }
592
+ const scope = resolveModuleScope(workspaceRoot, modulePath, context);
593
+ const classification = componentAlignedEvidence && candidateClassification.classification === 'architecture-module'
594
+ ? 'uncertain'
595
+ : candidateClassification.classification;
596
+ return {
597
+ name: moduleName,
598
+ path: modulePath,
599
+ confidence,
600
+ evidence,
601
+ ...(scope ? { scope } : {}),
602
+ classification,
603
+ selectedByDefault: classification === 'architecture-module' &&
604
+ candidateClassification.selectedByDefault &&
605
+ confidence !== 'low',
606
+ };
607
+ }
608
+ function collectModuleCandidatesFromRoot(workspaceRoot, modulesRootRelative, defaultConfidence, context) {
609
+ const absoluteRoot = path.join(workspaceRoot, ...modulesRootRelative.split('/'));
610
+ if (isIgnoredPath(context, modulesRootRelative)) {
611
+ return [];
612
+ }
613
+ const rootLower = modulesRootRelative.toLowerCase();
614
+ const skipFrontendUtilities = rootLower === 'src/features' ||
615
+ rootLower.endsWith('/src/features') ||
616
+ rootLower === 'app' ||
617
+ rootLower === 'src/app' ||
618
+ rootLower.endsWith('/app') ||
619
+ rootLower.endsWith('/src/app');
620
+ const entries = safeReadDirEntries(absoluteRoot)
621
+ .filter((entry) => entry.isDirectory() &&
622
+ !ignoredDirectoryNames.has(entry.name) &&
623
+ !isIgnoredPath(context, normalizePath(`${modulesRootRelative}/${entry.name}`)))
624
+ .sort((left, right) => left.name.localeCompare(right.name));
625
+ const modules = [];
626
+ for (const entry of entries) {
627
+ const candidateProjectRoot = normalizePath(`${modulesRootRelative}/${entry.name}`);
628
+ if (isUnderJvmResourceRoot(candidateProjectRoot)) {
629
+ continue;
630
+ }
631
+ if (['apps', 'packages', 'services', 'libs'].includes(rootLower) &&
632
+ (context?.projectRoots?.length ?? 0) > 0 &&
633
+ !context?.projectRoots?.includes(candidateProjectRoot)) {
634
+ continue;
635
+ }
636
+ if (skipFrontendUtilities && frontendUtilityDirectoryNames.has(entry.name.toLowerCase())) {
637
+ continue;
638
+ }
639
+ const rootSegments = modulesRootRelative.split('/').filter((segment) => segment.length > 0);
640
+ const sourceIndex = rootSegments.lastIndexOf('src');
641
+ const rootLeaf = rootSegments[rootSegments.length - 1]?.toLowerCase();
642
+ const parentName = sourceIndex > 0 && rootLeaf === 'src'
643
+ ? rootSegments[sourceIndex - 1]
644
+ : undefined;
645
+ const moduleName = parentName && parentName !== 'src'
646
+ ? `${parentName}/${entry.name}`
647
+ : ['domain', 'domains', 'application', 'infrastructure'].includes(rootLeaf ?? '')
648
+ ? `${rootSegments[rootSegments.length - 1]}/${entry.name}`
649
+ : entry.name;
650
+ const moduleAbsolutePath = path.join(absoluteRoot, entry.name);
651
+ const inspected = inspectModuleFolder(moduleAbsolutePath);
652
+ const detected = makeDetectedModule(workspaceRoot, moduleName, normalizePath(`${modulesRootRelative}/${entry.name}`), modulesRootRelative, inspected.hasSourceFiles, inspected.hasRoleFiles, inspected.sourceFileCount, context);
653
+ if (!detected) {
654
+ continue;
655
+ }
656
+ if (defaultConfidence === 'medium' && detected.confidence === 'high' && !inspected.hasRoleFiles) {
657
+ detected.confidence = 'medium';
658
+ }
659
+ modules.push(detected);
660
+ }
661
+ return modules;
662
+ }
663
+ function collectAppRouteModules(workspaceRoot, appRootRelative, context) {
664
+ const absoluteRoot = path.join(workspaceRoot, ...appRootRelative.split('/'));
665
+ if (isIgnoredPath(context, appRootRelative)) {
666
+ return [];
667
+ }
668
+ const entries = safeReadDirEntries(absoluteRoot)
669
+ .filter((entry) => entry.isDirectory() &&
670
+ !ignoredDirectoryNames.has(entry.name) &&
671
+ !isIgnoredPath(context, normalizePath(`${appRootRelative}/${entry.name}`)))
672
+ .sort((left, right) => left.name.localeCompare(right.name));
673
+ const modules = [];
674
+ for (const entry of entries) {
675
+ const rawName = entry.name;
676
+ const lowerName = rawName.toLowerCase();
677
+ if (appRouteReservedDirectoryNames.has(lowerName) ||
678
+ rawName.startsWith('_') ||
679
+ rawName.startsWith('[')) {
680
+ continue;
681
+ }
682
+ const isRouteGroup = rawName.startsWith('(') && rawName.endsWith(')');
683
+ const moduleName = isRouteGroup ? rawName.slice(1, -1).trim() : rawName;
684
+ if (!moduleName || frontendUtilityDirectoryNames.has(moduleName.toLowerCase())) {
685
+ continue;
686
+ }
687
+ const moduleRelativePath = normalizePath(`${appRootRelative}/${rawName}`);
688
+ const moduleAbsolutePath = path.join(absoluteRoot, rawName);
689
+ if (!containsAppRouteFiles(moduleAbsolutePath)) {
690
+ continue;
691
+ }
692
+ const inspected = inspectModuleFolder(moduleAbsolutePath);
693
+ const detected = makeDetectedModule(workspaceRoot, moduleName, moduleRelativePath, appRootRelative, inspected.hasSourceFiles, true, inspected.sourceFileCount, context);
694
+ if (!detected) {
695
+ continue;
696
+ }
697
+ detected.evidence.push(isRouteGroup
698
+ ? 'Detected Next.js route-group boundary'
699
+ : 'Detected app-router feature boundary');
700
+ modules.push(detected);
701
+ }
702
+ return modules;
703
+ }
704
+ function collectExplicitRoots(workspaceRoot, context) {
705
+ const roots = [];
706
+ for (const root of [
707
+ 'src/modules',
708
+ 'src/features',
709
+ 'src/domain',
710
+ 'src/domains',
711
+ 'src/application',
712
+ 'src/infrastructure',
713
+ 'src/app',
714
+ 'app',
715
+ 'backend/src/modules',
716
+ 'backend/src/features',
717
+ 'frontend/src/modules',
718
+ 'frontend/src/features',
719
+ 'frontend/src/views',
720
+ 'src/views',
721
+ 'routes',
722
+ 'src/routes',
723
+ 'app/Modules',
724
+ 'app/services',
725
+ 'services',
726
+ 'packages',
727
+ 'libs',
728
+ ]) {
729
+ if (['apps', 'packages', 'services', 'libs'].includes(root) &&
730
+ (context?.projectRoots?.length ?? 0) > 0 &&
731
+ !context?.projectRoots?.some((projectRoot) => projectRoot.startsWith(`${root}/`))) {
732
+ continue;
733
+ }
734
+ if (!isIgnoredPath(context, root) && pathExists(path.join(workspaceRoot, ...root.split('/')))) {
735
+ roots.push(root);
736
+ }
737
+ }
738
+ const appsRoot = path.join(workspaceRoot, 'apps');
739
+ for (const appEntry of safeReadDirEntries(appsRoot)) {
740
+ if (!appEntry.isDirectory() ||
741
+ ignoredDirectoryNames.has(appEntry.name) ||
742
+ isIgnoredPath(context, `apps/${appEntry.name}`)) {
743
+ continue;
744
+ }
745
+ for (const candidate of [
746
+ `apps/${appEntry.name}/src`,
747
+ `apps/${appEntry.name}/src/modules`,
748
+ `apps/${appEntry.name}/src/features`,
749
+ `apps/${appEntry.name}/src/domain`,
750
+ `apps/${appEntry.name}/src/domains`,
751
+ `apps/${appEntry.name}/src/application`,
752
+ `apps/${appEntry.name}/src/infrastructure`,
753
+ `apps/${appEntry.name}/app`,
754
+ `apps/${appEntry.name}/src/app`,
755
+ ]) {
756
+ if ((context?.projectRoots?.length ?? 0) > 0 && !context?.projectRoots?.includes(`apps/${appEntry.name}`)) {
757
+ continue;
758
+ }
759
+ if (!isIgnoredPath(context, candidate) && pathExists(path.join(workspaceRoot, ...candidate.split('/')))) {
760
+ roots.push(candidate);
761
+ }
762
+ }
763
+ }
764
+ for (const container of ['packages', 'services']) {
765
+ const containerRoot = path.join(workspaceRoot, container);
766
+ for (const containerEntry of safeReadDirEntries(containerRoot)) {
767
+ if (!containerEntry.isDirectory() ||
768
+ ignoredDirectoryNames.has(containerEntry.name) ||
769
+ isIgnoredPath(context, `${container}/${containerEntry.name}`)) {
770
+ continue;
771
+ }
772
+ for (const candidate of [
773
+ `${container}/${containerEntry.name}/src`,
774
+ `${container}/${containerEntry.name}/src/modules`,
775
+ `${container}/${containerEntry.name}/src/features`,
776
+ `${container}/${containerEntry.name}/src/domain`,
777
+ `${container}/${containerEntry.name}/src/domains`,
778
+ `${container}/${containerEntry.name}/src/application`,
779
+ `${container}/${containerEntry.name}/src/infrastructure`,
780
+ ]) {
781
+ if ((context?.projectRoots?.length ?? 0) > 0 &&
782
+ !context?.projectRoots?.includes(`${container}/${containerEntry.name}`)) {
783
+ continue;
784
+ }
785
+ if (!isIgnoredPath(context, candidate) && pathExists(path.join(workspaceRoot, ...candidate.split('/')))) {
786
+ roots.push(candidate);
787
+ }
788
+ }
789
+ }
790
+ }
791
+ return uniqueSorted(roots);
792
+ }
793
+ function collectJavaPackageRoots(workspaceRoot, context) {
794
+ const roots = [];
795
+ for (const sourceRoot of ['src/main/java', 'src/main/kotlin', 'src']) {
796
+ const absoluteSourceRoot = path.join(workspaceRoot, ...sourceRoot.split('/'));
797
+ if (isIgnoredPath(context, sourceRoot) || !pathExists(absoluteSourceRoot)) {
798
+ continue;
799
+ }
800
+ const queue = [
801
+ { absolutePath: absoluteSourceRoot, relativePath: sourceRoot, depth: 0 },
802
+ ];
803
+ while (queue.length > 0) {
804
+ const current = queue.shift();
805
+ if (!current) {
806
+ continue;
807
+ }
808
+ if (current.depth > 6) {
809
+ continue;
810
+ }
811
+ for (const entry of safeReadDirEntries(current.absolutePath)) {
812
+ const childRelativePath = normalizePath(`${current.relativePath}/${entry.name}`);
813
+ if (!entry.isDirectory() ||
814
+ ignoredDirectoryNames.has(entry.name) ||
815
+ isIgnoredPath(context, childRelativePath)) {
816
+ continue;
817
+ }
818
+ const lowerName = entry.name.toLowerCase();
819
+ if (lowerName === 'modules' || lowerName === 'features') {
820
+ const childCount = safeReadDirEntries(path.join(current.absolutePath, entry.name))
821
+ .filter((child) => child.isDirectory() &&
822
+ !ignoredDirectoryNames.has(child.name) &&
823
+ !isIgnoredPath(context, normalizePath(`${childRelativePath}/${child.name}`)))
824
+ .length;
825
+ if (childCount >= 2) {
826
+ roots.push(childRelativePath);
827
+ }
828
+ continue;
829
+ }
830
+ queue.push({
831
+ absolutePath: path.join(current.absolutePath, entry.name),
832
+ relativePath: childRelativePath,
833
+ depth: current.depth + 1,
834
+ });
835
+ }
836
+ }
837
+ }
838
+ return roots;
839
+ }
840
+ function collectFallbackSrcModules(workspaceRoot, context) {
841
+ const srcRoot = path.join(workspaceRoot, 'src');
842
+ if (isIgnoredPath(context, 'src')) {
843
+ return [];
844
+ }
845
+ const srcEntries = safeReadDirEntries(srcRoot)
846
+ .filter((entry) => entry.isDirectory() &&
847
+ !ignoredDirectoryNames.has(entry.name) &&
848
+ !isIgnoredPath(context, `src/${entry.name}`))
849
+ .sort((left, right) => left.name.localeCompare(right.name));
850
+ const modules = [];
851
+ for (const entry of srcEntries) {
852
+ if (entry.name === 'modules' ||
853
+ entry.name === 'features' ||
854
+ entry.name === 'app' ||
855
+ isLowValueModuleName(entry.name) ||
856
+ frontendUtilityDirectoryNames.has(entry.name.toLowerCase())) {
857
+ continue;
858
+ }
859
+ const relativePath = `src/${entry.name}`;
860
+ const inspected = inspectModuleFolder(path.join(srcRoot, entry.name));
861
+ const detected = makeDetectedModule(workspaceRoot, entry.name, relativePath, 'src', inspected.hasSourceFiles, inspected.hasRoleFiles, inspected.sourceFileCount, context);
862
+ if (!detected) {
863
+ continue;
864
+ }
865
+ if (detected.confidence === 'high' && !inspected.hasRoleFiles) {
866
+ detected.confidence = 'medium';
867
+ }
868
+ modules.push(detected);
869
+ }
870
+ return modules;
871
+ }
872
+ function detectModules(workspaceRoot, options) {
873
+ const evidence = [];
874
+ const modulesByPath = new Map();
875
+ const context = {
876
+ projectKinds: options?.projectKinds,
877
+ stacks: options?.stacks,
878
+ ignoreMatcher: options?.ignoreMatcher,
879
+ projectRoots: options?.projectRoots?.map(normalizePath),
880
+ componentPaths: options?.componentPaths?.map(normalizePath),
881
+ componentNames: options?.componentNames,
882
+ resourcePaths: options?.resourcePaths?.map(normalizePath),
883
+ resourceNames: options?.resourceNames,
884
+ };
885
+ const explicitRoots = collectExplicitRoots(workspaceRoot, context);
886
+ const usesFrontendAppRouter = options?.stacks?.some((stack) => stack === 'nextjs' || stack === 'react' || stack === 'vue' || stack === 'angular');
887
+ if (options?.stacks?.some((stack) => stack === 'java' || stack === 'spring' || stack === 'kotlin' || stack === 'kotlin_spring')) {
888
+ for (const root of collectJavaPackageRoots(workspaceRoot, context)) {
889
+ if (!explicitRoots.includes(root)) {
890
+ explicitRoots.push(root);
891
+ }
892
+ }
893
+ explicitRoots.sort((left, right) => left.localeCompare(right));
894
+ }
895
+ for (const root of explicitRoots) {
896
+ if (root.endsWith('/src/modules') ||
897
+ root === 'src/modules' ||
898
+ root === 'backend/src/modules') {
899
+ evidence.push(`Found ${root} directory`);
900
+ }
901
+ else {
902
+ evidence.push(`Found likely module root ${root}`);
903
+ }
904
+ const detectedModules = usesFrontendAppRouter && (root === 'app' ||
905
+ root === 'src/app' ||
906
+ root.endsWith('/app') ||
907
+ root.endsWith('/src/app'))
908
+ ? collectAppRouteModules(workspaceRoot, root, context)
909
+ : collectModuleCandidatesFromRoot(workspaceRoot, root, root.includes('modules') ? 'high' : 'medium', context);
910
+ for (const moduleEntry of detectedModules) {
911
+ modulesByPath.set(moduleEntry.path, moduleEntry);
912
+ }
913
+ if (detectedModules.length >= 2) {
914
+ evidence.push(`Detected repeated module folders under ${root}`);
915
+ }
916
+ }
917
+ if (modulesByPath.size === 0) {
918
+ const fallbackModules = collectFallbackSrcModules(workspaceRoot, context);
919
+ for (const moduleEntry of fallbackModules) {
920
+ modulesByPath.set(moduleEntry.path, moduleEntry);
921
+ }
922
+ if (fallbackModules.length > 0) {
923
+ evidence.push('Detected likely business modules under src/');
924
+ }
925
+ }
926
+ const modules = [...modulesByPath.values()].sort((left, right) => left.path.localeCompare(right.path));
927
+ if (modules.length === 0) {
928
+ return {
929
+ modules: [],
930
+ ...(explicitRoots.length > 0 ? { moduleRoots: explicitRoots } : {}),
931
+ confidence: 'low',
932
+ evidence: evidence.length > 0 ? uniqueSorted(evidence) : ['No clear module structure detected'],
933
+ };
934
+ }
935
+ const rootCounts = new Map();
936
+ for (const moduleEntry of modules) {
937
+ const root = moduleEntry.path.includes('/')
938
+ ? moduleEntry.path.slice(0, moduleEntry.path.lastIndexOf('/'))
939
+ : moduleEntry.path;
940
+ rootCounts.set(root, (rootCounts.get(root) ?? 0) + 1);
941
+ }
942
+ const bestRootEntry = [...rootCounts.entries()]
943
+ .sort((left, right) => {
944
+ if (right[1] !== left[1]) {
945
+ return right[1] - left[1];
946
+ }
947
+ return left[0].localeCompare(right[0]);
948
+ })[0];
949
+ const modulesRoot = bestRootEntry && bestRootEntry[1] >= 2 ? bestRootEntry[0] : undefined;
950
+ let confidence = 'low';
951
+ const highModules = modules.filter((entry) => entry.confidence === 'high').length;
952
+ if (modulesRoot && modules.length >= 2 && highModules >= 2) {
953
+ confidence = 'high';
954
+ }
955
+ else if (modules.length >= 1 && (highModules >= 1 || modulesRoot)) {
956
+ confidence = 'medium';
957
+ }
958
+ return {
959
+ modules,
960
+ ...(modulesRoot ? { modulesRoot } : {}),
961
+ ...(explicitRoots.length > 0 ? { moduleRoots: explicitRoots } : {}),
962
+ confidence,
963
+ evidence: uniqueSorted(evidence),
964
+ };
965
+ }
966
+ function detectModuleCandidatesForRoot(workspaceRoot, modulesRootRelative, options) {
967
+ const normalizedRoot = normalizePath(modulesRootRelative.trim()).replace(/^\/+|\/+$/gu, '');
968
+ if (normalizedRoot.length === 0) {
969
+ return [];
970
+ }
971
+ return collectModuleCandidatesFromRoot(workspaceRoot, normalizedRoot, normalizedRoot.includes('modules') ? 'high' : 'medium', {
972
+ projectKinds: options?.projectKinds,
973
+ stacks: options?.stacks,
974
+ ignoreMatcher: options?.ignoreMatcher,
975
+ projectRoots: options?.projectRoots?.map(normalizePath),
976
+ componentPaths: options?.componentPaths?.map(normalizePath),
977
+ componentNames: options?.componentNames,
978
+ resourcePaths: options?.resourcePaths?.map(normalizePath),
979
+ resourceNames: options?.resourceNames,
980
+ });
981
+ }
982
+ //# sourceMappingURL=moduleDetection.js.map