codereview-aia 0.1.0 → 0.1.2

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 (422) hide show
  1. package/dist/analysis/FindingsExtractor.d.ts +105 -0
  2. package/dist/analysis/FindingsExtractor.js +363 -0
  3. package/dist/analysis/FindingsExtractor.js.map +1 -0
  4. package/dist/analysis/ai-detection/analyzers/BaseAnalyzer.d.ts +111 -0
  5. package/dist/analysis/ai-detection/analyzers/BaseAnalyzer.js +215 -0
  6. package/dist/analysis/ai-detection/analyzers/BaseAnalyzer.js.map +1 -0
  7. package/dist/analysis/ai-detection/analyzers/DocumentationAnalyzer.d.ts +142 -0
  8. package/dist/analysis/ai-detection/analyzers/DocumentationAnalyzer.js +503 -0
  9. package/dist/analysis/ai-detection/analyzers/DocumentationAnalyzer.js.map +1 -0
  10. package/dist/analysis/ai-detection/analyzers/GitHistoryAnalyzer.d.ts +88 -0
  11. package/dist/analysis/ai-detection/analyzers/GitHistoryAnalyzer.js +343 -0
  12. package/dist/analysis/ai-detection/analyzers/GitHistoryAnalyzer.js.map +1 -0
  13. package/dist/analysis/ai-detection/core/AIDetectionEngine.d.ts +104 -0
  14. package/dist/analysis/ai-detection/core/AIDetectionEngine.js +369 -0
  15. package/dist/analysis/ai-detection/core/AIDetectionEngine.js.map +1 -0
  16. package/dist/analysis/ai-detection/types/DetectionTypes.d.ts +364 -0
  17. package/dist/analysis/ai-detection/types/DetectionTypes.js +32 -0
  18. package/dist/analysis/ai-detection/types/DetectionTypes.js.map +1 -0
  19. package/dist/analysis/ai-detection/utils/SubmissionConverter.d.ts +97 -0
  20. package/dist/analysis/ai-detection/utils/SubmissionConverter.js +339 -0
  21. package/dist/analysis/ai-detection/utils/SubmissionConverter.js.map +1 -0
  22. package/dist/analysis/context/ReviewContext.d.ts +184 -0
  23. package/dist/analysis/context/ReviewContext.js +294 -0
  24. package/dist/analysis/context/ReviewContext.js.map +1 -0
  25. package/dist/analysis/context/index.d.ts +6 -0
  26. package/dist/analysis/context/index.js +23 -0
  27. package/dist/analysis/context/index.js.map +1 -0
  28. package/dist/analysis/index.d.ts +7 -0
  29. package/dist/analysis/index.js +24 -0
  30. package/dist/analysis/index.js.map +1 -0
  31. package/dist/analysis/tokens/TokenAnalysisFormatter.d.ts +27 -0
  32. package/dist/analysis/tokens/TokenAnalysisFormatter.js +143 -0
  33. package/dist/analysis/tokens/TokenAnalysisFormatter.js.map +1 -0
  34. package/dist/analysis/tokens/TokenAnalyzer.d.ts +155 -0
  35. package/dist/analysis/tokens/TokenAnalyzer.js +502 -0
  36. package/dist/analysis/tokens/TokenAnalyzer.js.map +1 -0
  37. package/dist/analysis/tokens/index.d.ts +7 -0
  38. package/dist/analysis/tokens/index.js +24 -0
  39. package/dist/analysis/tokens/index.js.map +1 -0
  40. package/dist/clients/base/abstractClient.d.ts +99 -0
  41. package/dist/clients/base/abstractClient.js +98 -0
  42. package/dist/clients/base/abstractClient.js.map +1 -0
  43. package/dist/clients/base/httpClient.d.ts +24 -0
  44. package/dist/clients/base/httpClient.js +147 -0
  45. package/dist/clients/base/httpClient.js.map +1 -0
  46. package/dist/clients/base/index.d.ts +11 -0
  47. package/dist/clients/base/index.js +28 -0
  48. package/dist/clients/base/index.js.map +1 -0
  49. package/dist/clients/base/modelDetection.d.ts +41 -0
  50. package/dist/clients/base/modelDetection.js +88 -0
  51. package/dist/clients/base/modelDetection.js.map +1 -0
  52. package/dist/clients/base/responseProcessor.d.ts +45 -0
  53. package/dist/clients/base/responseProcessor.js +495 -0
  54. package/dist/clients/base/responseProcessor.js.map +1 -0
  55. package/dist/clients/factory/clientFactory.d.ts +23 -0
  56. package/dist/clients/factory/clientFactory.js +50 -0
  57. package/dist/clients/factory/clientFactory.js.map +1 -0
  58. package/dist/clients/factory/index.d.ts +7 -0
  59. package/dist/clients/factory/index.js +24 -0
  60. package/dist/clients/factory/index.js.map +1 -0
  61. package/dist/clients/implementations/index.d.ts +7 -0
  62. package/dist/clients/implementations/index.js +24 -0
  63. package/dist/clients/implementations/index.js.map +1 -0
  64. package/dist/clients/implementations/openRouterClient.d.ts +69 -0
  65. package/dist/clients/implementations/openRouterClient.js +294 -0
  66. package/dist/clients/implementations/openRouterClient.js.map +1 -0
  67. package/dist/clients/openRouterClient.d.ts +42 -0
  68. package/dist/clients/openRouterClient.js +738 -0
  69. package/dist/clients/openRouterClient.js.map +1 -0
  70. package/dist/clients/openRouterClientWrapper.d.ts +22 -0
  71. package/dist/clients/openRouterClientWrapper.js +64 -0
  72. package/dist/clients/openRouterClientWrapper.js.map +1 -0
  73. package/dist/clients/utils/directoryStructure.d.ts +14 -0
  74. package/dist/clients/utils/directoryStructure.js +48 -0
  75. package/dist/clients/utils/directoryStructure.js.map +1 -0
  76. package/dist/clients/utils/index.d.ts +10 -0
  77. package/dist/clients/utils/index.js +31 -0
  78. package/dist/clients/utils/index.js.map +1 -0
  79. package/dist/clients/utils/languageDetection.d.ts +13 -0
  80. package/dist/clients/utils/languageDetection.js +46 -0
  81. package/dist/clients/utils/languageDetection.js.map +1 -0
  82. package/dist/clients/utils/promptFormatter.d.ts +36 -0
  83. package/dist/clients/utils/promptFormatter.js +92 -0
  84. package/dist/clients/utils/promptFormatter.js.map +1 -0
  85. package/dist/clients/utils/promptLoader.d.ts +27 -0
  86. package/dist/clients/utils/promptLoader.js +49 -0
  87. package/dist/clients/utils/promptLoader.js.map +1 -0
  88. package/dist/clients/utils/tokenCounter.d.ts +81 -0
  89. package/dist/clients/utils/tokenCounter.js +209 -0
  90. package/dist/clients/utils/tokenCounter.js.map +1 -0
  91. package/dist/core/ApiClientSelector.d.ts +8 -0
  92. package/dist/core/ApiClientSelector.js +29 -0
  93. package/dist/core/ApiClientSelector.js.map +1 -0
  94. package/dist/core/ConfigurationService.d.ts +286 -0
  95. package/dist/core/ConfigurationService.js +477 -0
  96. package/dist/core/ConfigurationService.js.map +1 -0
  97. package/dist/core/ConsolidationService.d.ts +99 -0
  98. package/dist/core/ConsolidationService.js +341 -0
  99. package/dist/core/ConsolidationService.js.map +1 -0
  100. package/dist/core/InteractiveDisplayManager.d.ts +22 -0
  101. package/dist/core/InteractiveDisplayManager.js +70 -0
  102. package/dist/core/InteractiveDisplayManager.js.map +1 -0
  103. package/dist/core/OutputManager.d.ts +26 -0
  104. package/dist/core/OutputManager.js +217 -0
  105. package/dist/core/OutputManager.js.map +1 -0
  106. package/dist/core/ReviewGenerator.d.ts +13 -0
  107. package/dist/core/ReviewGenerator.js +102 -0
  108. package/dist/core/ReviewGenerator.js.map +1 -0
  109. package/dist/core/fileDiscovery.d.ts +35 -0
  110. package/dist/core/fileDiscovery.js +202 -0
  111. package/dist/core/fileDiscovery.js.map +1 -0
  112. package/dist/core/handlers/EstimationHandler.d.ts +18 -0
  113. package/dist/core/handlers/EstimationHandler.js +110 -0
  114. package/dist/core/handlers/EstimationHandler.js.map +1 -0
  115. package/dist/core/handlers/FileProcessingHandler.d.ts +31 -0
  116. package/dist/core/handlers/FileProcessingHandler.js +159 -0
  117. package/dist/core/handlers/FileProcessingHandler.js.map +1 -0
  118. package/dist/core/handlers/OutputHandler.d.ts +27 -0
  119. package/dist/core/handlers/OutputHandler.js +127 -0
  120. package/dist/core/handlers/OutputHandler.js.map +1 -0
  121. package/dist/core/handlers/ReviewExecutor.d.ts +32 -0
  122. package/dist/core/handlers/ReviewExecutor.js +111 -0
  123. package/dist/core/handlers/ReviewExecutor.js.map +1 -0
  124. package/dist/core/reviewOrchestrator.d.ts +24 -0
  125. package/dist/core/reviewOrchestrator.js +294 -0
  126. package/dist/core/reviewOrchestrator.js.map +1 -0
  127. package/dist/core/utils/ModelInfoUtils.d.ts +16 -0
  128. package/dist/core/utils/ModelInfoUtils.js +54 -0
  129. package/dist/core/utils/ModelInfoUtils.js.map +1 -0
  130. package/dist/formatters/outputFormatter.d.ts +31 -0
  131. package/dist/formatters/outputFormatter.js +65 -0
  132. package/dist/formatters/outputFormatter.js.map +1 -0
  133. package/dist/formatters/utils/IssueFormatters.d.ts +20 -0
  134. package/dist/formatters/utils/IssueFormatters.js +67 -0
  135. package/dist/formatters/utils/IssueFormatters.js.map +1 -0
  136. package/dist/formatters/utils/JsonFormatter.d.ts +13 -0
  137. package/dist/formatters/utils/JsonFormatter.js +57 -0
  138. package/dist/formatters/utils/JsonFormatter.js.map +1 -0
  139. package/dist/formatters/utils/MarkdownFormatters.d.ts +51 -0
  140. package/dist/formatters/utils/MarkdownFormatters.js +456 -0
  141. package/dist/formatters/utils/MarkdownFormatters.js.map +1 -0
  142. package/dist/formatters/utils/MetadataFormatter.d.ts +65 -0
  143. package/dist/formatters/utils/MetadataFormatter.js +219 -0
  144. package/dist/formatters/utils/MetadataFormatter.js.map +1 -0
  145. package/dist/formatters/utils/ModelInfoExtractor.d.ts +33 -0
  146. package/dist/formatters/utils/ModelInfoExtractor.js +111 -0
  147. package/dist/formatters/utils/ModelInfoExtractor.js.map +1 -0
  148. package/dist/index.d.ts +2 -0
  149. package/dist/index.js +1 -0
  150. package/dist/index.js.map +1 -0
  151. package/dist/plugins/PluginInterface.d.ts +44 -0
  152. package/dist/plugins/PluginInterface.js +9 -0
  153. package/dist/plugins/PluginInterface.js.map +1 -0
  154. package/dist/plugins/PluginManager.d.ts +51 -0
  155. package/dist/plugins/PluginManager.js +151 -0
  156. package/dist/plugins/PluginManager.js.map +1 -0
  157. package/dist/prompts/PromptManager.d.ts +30 -0
  158. package/dist/prompts/PromptManager.js +62 -0
  159. package/dist/prompts/PromptManager.js.map +1 -0
  160. package/dist/prompts/cache/PromptCache.d.ts +32 -0
  161. package/dist/prompts/cache/PromptCache.js +48 -0
  162. package/dist/prompts/cache/PromptCache.js.map +1 -0
  163. package/dist/runtime/auth/service.d.ts +2 -0
  164. package/dist/runtime/auth/service.js +41 -0
  165. package/dist/runtime/auth/service.js.map +1 -0
  166. package/dist/runtime/auth/session.d.ts +5 -0
  167. package/dist/runtime/auth/session.js +87 -0
  168. package/dist/runtime/auth/session.js.map +1 -0
  169. package/dist/runtime/auth/types.d.ts +9 -0
  170. package/dist/runtime/auth/types.js +3 -0
  171. package/dist/runtime/auth/types.js.map +1 -0
  172. package/dist/runtime/cliEntry.d.ts +1 -0
  173. package/dist/runtime/cliEntry.js +213 -0
  174. package/dist/runtime/cliEntry.js.map +1 -0
  175. package/dist/runtime/debug/logManager.d.ts +5 -0
  176. package/dist/runtime/debug/logManager.js +31 -0
  177. package/dist/runtime/debug/logManager.js.map +1 -0
  178. package/dist/runtime/errors.d.ts +5 -0
  179. package/dist/runtime/errors.js +15 -0
  180. package/dist/runtime/errors.js.map +1 -0
  181. package/dist/runtime/fileCollector.d.ts +5 -0
  182. package/dist/runtime/fileCollector.js +167 -0
  183. package/dist/runtime/fileCollector.js.map +1 -0
  184. package/dist/runtime/manifest.d.ts +1 -0
  185. package/dist/runtime/manifest.js +65 -0
  186. package/dist/runtime/manifest.js.map +1 -0
  187. package/dist/runtime/openrouterProxy.d.ts +4 -0
  188. package/dist/runtime/openrouterProxy.js +43 -0
  189. package/dist/runtime/openrouterProxy.js.map +1 -0
  190. package/dist/runtime/preprod/webCheck.d.ts +1 -0
  191. package/dist/runtime/preprod/webCheck.js +98 -0
  192. package/dist/runtime/preprod/webCheck.js.map +1 -0
  193. package/dist/runtime/proxyConfig.d.ts +6 -0
  194. package/dist/runtime/proxyConfig.js +86 -0
  195. package/dist/runtime/proxyConfig.js.map +1 -0
  196. package/dist/runtime/proxyEnvironment.d.ts +3 -0
  197. package/dist/runtime/proxyEnvironment.js +63 -0
  198. package/dist/runtime/proxyEnvironment.js.map +1 -0
  199. package/dist/runtime/reportMerge.d.ts +30 -0
  200. package/dist/runtime/reportMerge.js +70 -0
  201. package/dist/runtime/reportMerge.js.map +1 -0
  202. package/dist/runtime/reporting/markdownReportBuilder.d.ts +15 -0
  203. package/dist/runtime/reporting/markdownReportBuilder.js +97 -0
  204. package/dist/runtime/reporting/markdownReportBuilder.js.map +1 -0
  205. package/dist/runtime/reporting/reportDataCollector.d.ts +31 -0
  206. package/dist/runtime/reporting/reportDataCollector.js +170 -0
  207. package/dist/runtime/reporting/reportDataCollector.js.map +1 -0
  208. package/dist/runtime/reporting/summaryGenerator.d.ts +10 -0
  209. package/dist/runtime/reporting/summaryGenerator.js +67 -0
  210. package/dist/runtime/reporting/summaryGenerator.js.map +1 -0
  211. package/dist/runtime/reviewPipeline.d.ts +28 -0
  212. package/dist/runtime/reviewPipeline.js +122 -0
  213. package/dist/runtime/reviewPipeline.js.map +1 -0
  214. package/dist/runtime/runAiCodeReview.d.ts +10 -0
  215. package/dist/runtime/runAiCodeReview.js +138 -0
  216. package/dist/runtime/runAiCodeReview.js.map +1 -0
  217. package/dist/runtime/runtimeConfig.d.ts +4 -0
  218. package/dist/runtime/runtimeConfig.js +7 -0
  219. package/dist/runtime/runtimeConfig.js.map +1 -0
  220. package/dist/runtime/ui/Layout.d.ts +11 -0
  221. package/dist/runtime/ui/Layout.js +47 -0
  222. package/dist/runtime/ui/Layout.js.map +1 -0
  223. package/dist/runtime/ui/RuntimeApp.d.ts +6 -0
  224. package/dist/runtime/ui/RuntimeApp.js +161 -0
  225. package/dist/runtime/ui/RuntimeApp.js.map +1 -0
  226. package/dist/runtime/ui/inkModules.d.ts +10 -0
  227. package/dist/runtime/ui/inkModules.js +63 -0
  228. package/dist/runtime/ui/inkModules.js.map +1 -0
  229. package/dist/runtime/ui/screens/AuthScreen.d.ts +6 -0
  230. package/dist/runtime/ui/screens/AuthScreen.js +67 -0
  231. package/dist/runtime/ui/screens/AuthScreen.js.map +1 -0
  232. package/dist/runtime/ui/screens/ModeSelection.d.ts +10 -0
  233. package/dist/runtime/ui/screens/ModeSelection.js +100 -0
  234. package/dist/runtime/ui/screens/ModeSelection.js.map +1 -0
  235. package/dist/runtime/ui/screens/ProgressScreen.d.ts +7 -0
  236. package/dist/runtime/ui/screens/ProgressScreen.js +38 -0
  237. package/dist/runtime/ui/screens/ProgressScreen.js.map +1 -0
  238. package/dist/runtime/ui/screens/ResultsScreen.d.ts +7 -0
  239. package/dist/runtime/ui/screens/ResultsScreen.js +22 -0
  240. package/dist/runtime/ui/screens/ResultsScreen.js.map +1 -0
  241. package/dist/strategies/ArchitecturalReviewStrategy.d.ts +29 -0
  242. package/dist/strategies/ArchitecturalReviewStrategy.js +42 -0
  243. package/dist/strategies/ArchitecturalReviewStrategy.js.map +1 -0
  244. package/dist/strategies/CodingTestReviewStrategy.d.ts +194 -0
  245. package/dist/strategies/CodingTestReviewStrategy.js +681 -0
  246. package/dist/strategies/CodingTestReviewStrategy.js.map +1 -0
  247. package/dist/strategies/ConsolidatedReviewStrategy.d.ts +25 -0
  248. package/dist/strategies/ConsolidatedReviewStrategy.js +45 -0
  249. package/dist/strategies/ConsolidatedReviewStrategy.js.map +1 -0
  250. package/dist/strategies/ExtractPatternsReviewStrategy.d.ts +30 -0
  251. package/dist/strategies/ExtractPatternsReviewStrategy.js +51 -0
  252. package/dist/strategies/ExtractPatternsReviewStrategy.js.map +1 -0
  253. package/dist/strategies/MultiPassReviewStrategy.d.ts +86 -0
  254. package/dist/strategies/MultiPassReviewStrategy.js +590 -0
  255. package/dist/strategies/MultiPassReviewStrategy.js.map +1 -0
  256. package/dist/strategies/ReviewStrategy.d.ts +45 -0
  257. package/dist/strategies/ReviewStrategy.js +24 -0
  258. package/dist/strategies/ReviewStrategy.js.map +1 -0
  259. package/dist/strategies/StrategyFactory.d.ts +19 -0
  260. package/dist/strategies/StrategyFactory.js +72 -0
  261. package/dist/strategies/StrategyFactory.js.map +1 -0
  262. package/dist/strategies/index.d.ts +13 -0
  263. package/dist/strategies/index.js +30 -0
  264. package/dist/strategies/index.js.map +1 -0
  265. package/dist/tokenizers/baseTokenizer.d.ts +25 -0
  266. package/dist/tokenizers/baseTokenizer.js +48 -0
  267. package/dist/tokenizers/baseTokenizer.js.map +1 -0
  268. package/dist/tokenizers/gptTokenizer.d.ts +7 -0
  269. package/dist/tokenizers/gptTokenizer.js +28 -0
  270. package/dist/tokenizers/gptTokenizer.js.map +1 -0
  271. package/dist/tokenizers/index.d.ts +7 -0
  272. package/dist/tokenizers/index.js +24 -0
  273. package/dist/tokenizers/index.js.map +1 -0
  274. package/dist/types/apiResponses.d.ts +39 -0
  275. package/dist/types/apiResponses.js +9 -0
  276. package/dist/types/apiResponses.js.map +1 -0
  277. package/dist/types/cli.d.ts +22 -0
  278. package/dist/types/cli.js +3 -0
  279. package/dist/types/cli.js.map +1 -0
  280. package/dist/types/common.d.ts +22 -0
  281. package/dist/types/common.js +14 -0
  282. package/dist/types/common.js.map +1 -0
  283. package/dist/types/configuration.d.ts +682 -0
  284. package/dist/types/configuration.js +65 -0
  285. package/dist/types/configuration.js.map +1 -0
  286. package/dist/types/review.d.ts +258 -0
  287. package/dist/types/review.js +8 -0
  288. package/dist/types/review.js.map +1 -0
  289. package/dist/types/reviewSchema.d.ts +543 -0
  290. package/dist/types/reviewSchema.js +121 -0
  291. package/dist/types/reviewSchema.js.map +1 -0
  292. package/dist/types/structuredReview.d.ts +119 -0
  293. package/dist/types/structuredReview.js +6 -0
  294. package/dist/types/structuredReview.js.map +1 -0
  295. package/dist/types/tokenAnalysis.d.ts +44 -0
  296. package/dist/types/tokenAnalysis.js +4 -0
  297. package/dist/types/tokenAnalysis.js.map +1 -0
  298. package/dist/utils/FileReader.d.ts +33 -0
  299. package/dist/utils/FileReader.js +88 -0
  300. package/dist/utils/FileReader.js.map +1 -0
  301. package/dist/utils/FileWriter.d.ts +26 -0
  302. package/dist/utils/FileWriter.js +76 -0
  303. package/dist/utils/FileWriter.js.map +1 -0
  304. package/dist/utils/PathGenerator.d.ts +30 -0
  305. package/dist/utils/PathGenerator.js +82 -0
  306. package/dist/utils/PathGenerator.js.map +1 -0
  307. package/dist/utils/api/apiUtils.d.ts +3 -0
  308. package/dist/utils/api/apiUtils.js +20 -0
  309. package/dist/utils/api/apiUtils.js.map +1 -0
  310. package/dist/utils/api/index.d.ts +1 -0
  311. package/dist/utils/api/index.js +18 -0
  312. package/dist/utils/api/index.js.map +1 -0
  313. package/dist/utils/apiErrorHandler.d.ts +130 -0
  314. package/dist/utils/apiErrorHandler.js +256 -0
  315. package/dist/utils/apiErrorHandler.js.map +1 -0
  316. package/dist/utils/ciDataCollector.d.ts +51 -0
  317. package/dist/utils/ciDataCollector.js +197 -0
  318. package/dist/utils/ciDataCollector.js.map +1 -0
  319. package/dist/utils/codingTestConfigLoader.d.ts +66 -0
  320. package/dist/utils/codingTestConfigLoader.js +420 -0
  321. package/dist/utils/codingTestConfigLoader.js.map +1 -0
  322. package/dist/utils/dependencies/aiDependencyAnalyzer.d.ts +30 -0
  323. package/dist/utils/dependencies/aiDependencyAnalyzer.js +343 -0
  324. package/dist/utils/dependencies/aiDependencyAnalyzer.js.map +1 -0
  325. package/dist/utils/detection/frameworkDetector.d.ts +43 -0
  326. package/dist/utils/detection/frameworkDetector.js +795 -0
  327. package/dist/utils/detection/frameworkDetector.js.map +1 -0
  328. package/dist/utils/detection/index.d.ts +9 -0
  329. package/dist/utils/detection/index.js +28 -0
  330. package/dist/utils/detection/index.js.map +1 -0
  331. package/dist/utils/detection/projectTypeDetector.d.ts +27 -0
  332. package/dist/utils/detection/projectTypeDetector.js +469 -0
  333. package/dist/utils/detection/projectTypeDetector.js.map +1 -0
  334. package/dist/utils/diagramGenerator.d.ts +49 -0
  335. package/dist/utils/diagramGenerator.js +218 -0
  336. package/dist/utils/diagramGenerator.js.map +1 -0
  337. package/dist/utils/errorLogger.d.ts +24 -0
  338. package/dist/utils/errorLogger.js +59 -0
  339. package/dist/utils/errorLogger.js.map +1 -0
  340. package/dist/utils/estimationUtils.d.ts +139 -0
  341. package/dist/utils/estimationUtils.js +329 -0
  342. package/dist/utils/estimationUtils.js.map +1 -0
  343. package/dist/utils/fileFilters.d.ts +72 -0
  344. package/dist/utils/fileFilters.js +338 -0
  345. package/dist/utils/fileFilters.js.map +1 -0
  346. package/dist/utils/fileSystem.d.ts +22 -0
  347. package/dist/utils/fileSystem.js +45 -0
  348. package/dist/utils/fileSystem.js.map +1 -0
  349. package/dist/utils/index.d.ts +22 -0
  350. package/dist/utils/index.js +52 -0
  351. package/dist/utils/index.js.map +1 -0
  352. package/dist/utils/logger.d.ts +77 -0
  353. package/dist/utils/logger.js +271 -0
  354. package/dist/utils/logger.js.map +1 -0
  355. package/dist/utils/pathValidator.d.ts +40 -0
  356. package/dist/utils/pathValidator.js +98 -0
  357. package/dist/utils/pathValidator.js.map +1 -0
  358. package/dist/utils/priorityFilter.d.ts +34 -0
  359. package/dist/utils/priorityFilter.js +54 -0
  360. package/dist/utils/priorityFilter.js.map +1 -0
  361. package/dist/utils/projectDocs.d.ts +47 -0
  362. package/dist/utils/projectDocs.js +158 -0
  363. package/dist/utils/projectDocs.js.map +1 -0
  364. package/dist/utils/promptPaths.d.ts +6 -0
  365. package/dist/utils/promptPaths.js +33 -0
  366. package/dist/utils/promptPaths.js.map +1 -0
  367. package/dist/utils/promptTemplateManager.d.ts +34 -0
  368. package/dist/utils/promptTemplateManager.js +140 -0
  369. package/dist/utils/promptTemplateManager.js.map +1 -0
  370. package/dist/utils/review/consolidateReview.d.ts +15 -0
  371. package/dist/utils/review/consolidateReview.js +481 -0
  372. package/dist/utils/review/consolidateReview.js.map +1 -0
  373. package/dist/utils/review/fixDisplay.d.ts +20 -0
  374. package/dist/utils/review/fixDisplay.js +84 -0
  375. package/dist/utils/review/fixDisplay.js.map +1 -0
  376. package/dist/utils/review/fixImplementation.d.ts +28 -0
  377. package/dist/utils/review/fixImplementation.js +60 -0
  378. package/dist/utils/review/fixImplementation.js.map +1 -0
  379. package/dist/utils/review/index.d.ts +13 -0
  380. package/dist/utils/review/index.js +50 -0
  381. package/dist/utils/review/index.js.map +1 -0
  382. package/dist/utils/review/interactiveProcessing.d.ts +25 -0
  383. package/dist/utils/review/interactiveProcessing.js +251 -0
  384. package/dist/utils/review/interactiveProcessing.js.map +1 -0
  385. package/dist/utils/review/progressTracker.d.ts +106 -0
  386. package/dist/utils/review/progressTracker.js +227 -0
  387. package/dist/utils/review/progressTracker.js.map +1 -0
  388. package/dist/utils/review/reviewExtraction.d.ts +31 -0
  389. package/dist/utils/review/reviewExtraction.js +324 -0
  390. package/dist/utils/review/reviewExtraction.js.map +1 -0
  391. package/dist/utils/review/types.d.ts +45 -0
  392. package/dist/utils/review/types.js +18 -0
  393. package/dist/utils/review/types.js.map +1 -0
  394. package/dist/utils/reviewActionHandler.d.ts +16 -0
  395. package/dist/utils/reviewActionHandler.js +34 -0
  396. package/dist/utils/reviewActionHandler.js.map +1 -0
  397. package/dist/utils/reviewParser.d.ts +34 -0
  398. package/dist/utils/reviewParser.js +218 -0
  399. package/dist/utils/reviewParser.js.map +1 -0
  400. package/dist/utils/sanitizer.d.ts +82 -0
  401. package/dist/utils/sanitizer.js +239 -0
  402. package/dist/utils/sanitizer.js.map +1 -0
  403. package/dist/utils/smartFileSelector.d.ts +50 -0
  404. package/dist/utils/smartFileSelector.js +261 -0
  405. package/dist/utils/smartFileSelector.js.map +1 -0
  406. package/dist/utils/templateLoader.d.ts +44 -0
  407. package/dist/utils/templateLoader.js +431 -0
  408. package/dist/utils/templateLoader.js.map +1 -0
  409. package/dist/utils/treeGenerator.d.ts +12 -0
  410. package/dist/utils/treeGenerator.js +133 -0
  411. package/dist/utils/treeGenerator.js.map +1 -0
  412. package/package.json +11 -12
  413. package/src/index.ts +1 -0
  414. package/src/runtime/debug/logManager.ts +37 -0
  415. package/src/runtime/fileCollector.ts +58 -24
  416. package/src/runtime/preprod/webCheck.ts +104 -0
  417. package/src/runtime/reviewPipeline.ts +10 -4
  418. package/src/runtime/ui/RuntimeApp.tsx +96 -13
  419. package/src/runtime/ui/screens/ModeSelection.tsx +148 -15
  420. package/src/runtime/ui/screens/ProgressScreen.tsx +10 -3
  421. package/src/runtime/ui/screens/ResultsScreen.tsx +8 -1
  422. package/src/utils/logger.ts +64 -14
@@ -0,0 +1,155 @@
1
+ /**
2
+ * @fileoverview Token analysis service for pre-review token counting and estimation.
3
+ *
4
+ * This module provides fast, provider-agnostic token counting and analysis functionality
5
+ * to estimate token usage and costs before performing actual reviews.
6
+ */
7
+ import type { FileInfo } from '../../types/review';
8
+ /**
9
+ * Result of token analysis for a single file
10
+ */
11
+ export interface FileTokenAnalysis {
12
+ /** Path to the file */
13
+ path: string;
14
+ /** Relative path to the file */
15
+ relativePath: string | undefined;
16
+ /** Number of tokens in the file */
17
+ tokenCount: number;
18
+ /** Size of file in bytes */
19
+ sizeInBytes: number;
20
+ /** Tokens per byte ratio (used for optimization analysis) */
21
+ tokensPerByte: number;
22
+ }
23
+ /**
24
+ * Result of token analysis for a set of files
25
+ */
26
+ export interface TokenAnalysisResult {
27
+ /** Analysis of individual files */
28
+ files: FileTokenAnalysis[];
29
+ /** Total number of tokens across all files */
30
+ totalTokens: number;
31
+ /** Total size of all files in bytes */
32
+ totalSizeInBytes: number;
33
+ /** Average tokens per byte across all files */
34
+ averageTokensPerByte: number;
35
+ /** Total number of files analyzed */
36
+ fileCount: number;
37
+ /** Token overhead for prompts, instructions, etc. */
38
+ promptOverheadTokens: number;
39
+ /** Estimated total token count including overhead */
40
+ estimatedTotalTokens: number;
41
+ /** Maximum context window size for the model */
42
+ contextWindowSize: number;
43
+ /** Whether the content exceeds the context window */
44
+ exceedsContextWindow: boolean;
45
+ /** Number of passes needed for multi-pass review */
46
+ estimatedPassesNeeded: number;
47
+ /** Chunking strategy recommendation */
48
+ chunkingRecommendation: ChunkingRecommendation;
49
+ }
50
+ /**
51
+ * Recommendation for chunking strategy
52
+ */
53
+ export interface ChunkingRecommendation {
54
+ /** Whether chunking is recommended */
55
+ chunkingRecommended: boolean;
56
+ /** Approximate file chunks for multi-pass processing */
57
+ recommendedChunks: FileChunk[];
58
+ /** Reason for chunking recommendation */
59
+ reason: string;
60
+ }
61
+ /**
62
+ * A chunk of files for multi-pass processing
63
+ */
64
+ export interface FileChunk {
65
+ /** Files in this chunk */
66
+ files: string[];
67
+ /** Estimated token count for this chunk */
68
+ estimatedTokenCount: number;
69
+ /** Priority of this chunk (higher = more important) */
70
+ priority: number;
71
+ }
72
+ /**
73
+ * Options for token analysis
74
+ */
75
+ export interface TokenAnalysisOptions {
76
+ /** Type of review being performed */
77
+ reviewType: string;
78
+ /** Name of the model being used */
79
+ modelName: string;
80
+ /** Whether to optimize for speed (less accurate) or precision */
81
+ optimizeForSpeed?: boolean;
82
+ /** Additional prompt overhead to consider */
83
+ additionalPromptOverhead?: number;
84
+ /** Context maintenance factor for multi-pass reviews (0-1) */
85
+ contextMaintenanceFactor?: number;
86
+ /** Safety margin factor for context window (0-1) */
87
+ safetyMarginFactor?: number;
88
+ /** Force single pass mode regardless of token count */
89
+ forceSinglePass?: boolean;
90
+ /** Force maximum tokens per batch (for testing consolidation) */
91
+ batchTokenLimit?: number;
92
+ }
93
+ /**
94
+ * Service for analyzing token usage in files
95
+ */
96
+ export declare class TokenAnalyzer {
97
+ private static DEFAULT_PROMPT_OVERHEAD;
98
+ private static DEFAULT_CONTEXT_MAINTENANCE_FACTOR;
99
+ private static DEFAULT_SAFETY_MARGIN_FACTOR;
100
+ private static DEFAULT_CONTEXT_WINDOW;
101
+ /**
102
+ * Context window mapping for supported models.
103
+ * Leave values as null if the exact window is unknown so they can be filled in later.
104
+ */
105
+ private static MODEL_CONTEXT_WINDOWS;
106
+ /**
107
+ * Get the context window size for a model
108
+ * @param modelName Name of the model
109
+ * @returns Context window size in tokens
110
+ */
111
+ private static getContextWindowSize;
112
+ private static lookupConfiguredContextWindow;
113
+ /**
114
+ * Analyze token usage for a set of files
115
+ * @param files Files to analyze
116
+ * @param options Analysis options
117
+ * @returns Token analysis result
118
+ */
119
+ static analyzeFiles(files: FileInfo[], options: TokenAnalysisOptions): TokenAnalysisResult;
120
+ /**
121
+ * Generate a chunking recommendation for files that exceed context window
122
+ * @param fileAnalyses Array of file token analyses
123
+ * @param estimatedTotalTokens Total tokens including overhead
124
+ * @param contextWindowSize Maximum context window size
125
+ * @param contextMaintenanceFactor Context maintenance overhead factor
126
+ * @param forceSinglePass Force single pass mode regardless of token count
127
+ * @param batchTokenLimit Force maximum tokens per batch (for testing)
128
+ * @returns Chunking recommendation
129
+ */
130
+ private static generateChunkingRecommendation;
131
+ /**
132
+ * Optimized bin-packing algorithm to minimize the number of chunks
133
+ * Uses an advanced first-fit decreasing with multi-level optimization
134
+ * @param fileAnalyses Array of file token analyses
135
+ * @param maxChunkSize Maximum size for each chunk in tokens
136
+ * @param contextWindowSize Original context window for logging
137
+ * @returns Array of optimized file chunks
138
+ */
139
+ private static optimizedBinPacking;
140
+ /**
141
+ * Aggressive balancing to minimize chunk count and maximize efficiency
142
+ * @param chunks Initial chunks from bin-packing
143
+ * @param fileAnalyses Original file analyses for lookup
144
+ * @param maxChunkSize Maximum size for each chunk
145
+ * @returns Balanced chunks with minimized count
146
+ */
147
+ private static aggressiveBalance;
148
+ /**
149
+ * Analyze a single file for token usage
150
+ * @param file File to analyze
151
+ * @param options Analysis options
152
+ * @returns Token analysis for the file
153
+ */
154
+ static analyzeFile(file: FileInfo, options: TokenAnalysisOptions): FileTokenAnalysis;
155
+ }
@@ -0,0 +1,502 @@
1
+ "use strict";
2
+ /**
3
+ * @fileoverview Token analysis service for pre-review token counting and estimation.
4
+ *
5
+ * This module provides fast, provider-agnostic token counting and analysis functionality
6
+ * to estimate token usage and costs before performing actual reviews.
7
+ */
8
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.TokenAnalyzer = void 0;
13
+ const tokenizers_1 = require("../../tokenizers");
14
+ const logger_1 = __importDefault(require("../../utils/logger"));
15
+ /**
16
+ * Service for analyzing token usage in files
17
+ */
18
+ class TokenAnalyzer {
19
+ static DEFAULT_PROMPT_OVERHEAD = 1500;
20
+ static DEFAULT_CONTEXT_MAINTENANCE_FACTOR = 0.08; // Reduced to 8% for better efficiency
21
+ static DEFAULT_SAFETY_MARGIN_FACTOR = 0.1; // Use 90% of context window by default
22
+ static DEFAULT_CONTEXT_WINDOW = 100000; // Default fallback
23
+ /**
24
+ * Context window mapping for supported models.
25
+ * Leave values as null if the exact window is unknown so they can be filled in later.
26
+ */
27
+ static MODEL_CONTEXT_WINDOWS = {
28
+ 'openai/gpt-5.1-codex': 400000,
29
+ 'gpt-5.1-codex': 400000,
30
+ 'anthropic/claude-haiku-4.5': 200000,
31
+ 'claude-haiku-4.5': 200000,
32
+ 'moonshotai/kimi-k2-thinking': 262144,
33
+ 'kimi-k2-thinking': 262144,
34
+ 'x-ai/grok-4-fast': 2000000,
35
+ 'grok-4-fast': 2000000,
36
+ };
37
+ /**
38
+ * Get the context window size for a model
39
+ * @param modelName Name of the model
40
+ * @returns Context window size in tokens
41
+ */
42
+ static getContextWindowSize(modelName) {
43
+ logger_1.default.debug(`getContextWindowSize: modelName=${modelName}`);
44
+ const configured = TokenAnalyzer.lookupConfiguredContextWindow(modelName);
45
+ if (typeof configured === 'number') {
46
+ logger_1.default.info(`Using configured context window for ${modelName}: ${configured.toLocaleString()} tokens`);
47
+ return configured;
48
+ }
49
+ if (configured === null) {
50
+ logger_1.default.warn(`Context window size for ${modelName} has not been set. Update TokenAnalyzer.MODEL_CONTEXT_WINDOWS to provide the exact token limit.`);
51
+ }
52
+ else {
53
+ logger_1.default.warn(`No matching context window size found for model: ${modelName}`);
54
+ }
55
+ logger_1.default.warn(`Using default context window size: ${TokenAnalyzer.DEFAULT_CONTEXT_WINDOW.toLocaleString()} tokens`);
56
+ return TokenAnalyzer.DEFAULT_CONTEXT_WINDOW;
57
+ }
58
+ static lookupConfiguredContextWindow(modelName) {
59
+ const normalized = modelName.toLowerCase();
60
+ if (normalized in TokenAnalyzer.MODEL_CONTEXT_WINDOWS) {
61
+ return TokenAnalyzer.MODEL_CONTEXT_WINDOWS[normalized];
62
+ }
63
+ if (normalized.includes(':')) {
64
+ const [, baseName] = normalized.split(':');
65
+ if (baseName && baseName in TokenAnalyzer.MODEL_CONTEXT_WINDOWS) {
66
+ return TokenAnalyzer.MODEL_CONTEXT_WINDOWS[baseName];
67
+ }
68
+ }
69
+ return undefined;
70
+ }
71
+ /**
72
+ * Analyze token usage for a set of files
73
+ * @param files Files to analyze
74
+ * @param options Analysis options
75
+ * @returns Token analysis result
76
+ */
77
+ static analyzeFiles(files, options) {
78
+ logger_1.default.info('Analyzing token usage for files...');
79
+ logger_1.default.debug(`TokenAnalyzer: modelName=${options.modelName}`);
80
+ const contextWindowSize = TokenAnalyzer.getContextWindowSize(options.modelName);
81
+ const promptOverhead = options.additionalPromptOverhead || TokenAnalyzer.DEFAULT_PROMPT_OVERHEAD;
82
+ const contextMaintenanceFactor = options.contextMaintenanceFactor || TokenAnalyzer.DEFAULT_CONTEXT_MAINTENANCE_FACTOR;
83
+ const safetyMarginFactor = options.safetyMarginFactor || TokenAnalyzer.DEFAULT_SAFETY_MARGIN_FACTOR;
84
+ // Calculate effective context window size with safety margin
85
+ const effectiveContextWindowSize = Math.floor(contextWindowSize * (1 - safetyMarginFactor));
86
+ logger_1.default.info(`Using effective context window size: ${effectiveContextWindowSize.toLocaleString()} tokens (${Math.round((1 - safetyMarginFactor) * 100)}% of ${contextWindowSize.toLocaleString()} tokens)`);
87
+ // Analyze each file
88
+ const fileAnalyses = files.map((file) => {
89
+ const content = file.content;
90
+ const tokenCount = (0, tokenizers_1.countTokens)(content, options.modelName);
91
+ const sizeInBytes = content.length;
92
+ const tokensPerByte = sizeInBytes > 0 ? tokenCount / sizeInBytes : 0;
93
+ return {
94
+ path: file.path,
95
+ relativePath: file.relativePath,
96
+ tokenCount,
97
+ sizeInBytes,
98
+ tokensPerByte,
99
+ };
100
+ });
101
+ // Calculate totals
102
+ const totalTokens = fileAnalyses.reduce((sum, file) => sum + file.tokenCount, 0);
103
+ const totalSizeInBytes = fileAnalyses.reduce((sum, file) => sum + file.sizeInBytes, 0);
104
+ const averageTokensPerByte = totalSizeInBytes > 0 ? totalTokens / totalSizeInBytes : 0;
105
+ // Estimate total tokens with overhead
106
+ const estimatedTotalTokens = totalTokens + promptOverhead;
107
+ // Determine if chunking is needed
108
+ const exceedsContextWindow = estimatedTotalTokens > effectiveContextWindowSize;
109
+ logger_1.default.info(`Token analysis summary:`);
110
+ logger_1.default.info(`- Total files: ${files.length}`);
111
+ logger_1.default.info(`- Total tokens: ${totalTokens.toLocaleString()}`);
112
+ logger_1.default.info(`- Prompt overhead: ${promptOverhead.toLocaleString()}`);
113
+ logger_1.default.info(`- Estimated total tokens: ${estimatedTotalTokens.toLocaleString()}`);
114
+ logger_1.default.info(`- Context window size: ${contextWindowSize.toLocaleString()}`);
115
+ logger_1.default.info(`- Effective context size (with safety margin): ${effectiveContextWindowSize.toLocaleString()}`);
116
+ logger_1.default.info(`- Context utilization: ${((estimatedTotalTokens / effectiveContextWindowSize) * 100).toFixed(2)}%`);
117
+ // Calculate recommended chunks if needed
118
+ const chunkingRecommendation = TokenAnalyzer.generateChunkingRecommendation(fileAnalyses, estimatedTotalTokens, effectiveContextWindowSize, contextMaintenanceFactor, options.forceSinglePass, options.batchTokenLimit);
119
+ // Log chunking decision
120
+ if (chunkingRecommendation.chunkingRecommended) {
121
+ logger_1.default.info(`Multi-pass review recommended: ${chunkingRecommendation.reason}`);
122
+ logger_1.default.info(`Estimated passes needed: ${chunkingRecommendation.recommendedChunks.length}`);
123
+ }
124
+ else {
125
+ logger_1.default.info(`Single-pass review recommended: ${chunkingRecommendation.reason}`);
126
+ }
127
+ return {
128
+ files: fileAnalyses,
129
+ totalTokens,
130
+ totalSizeInBytes,
131
+ averageTokensPerByte,
132
+ fileCount: files.length,
133
+ promptOverheadTokens: promptOverhead,
134
+ estimatedTotalTokens,
135
+ contextWindowSize,
136
+ exceedsContextWindow,
137
+ estimatedPassesNeeded: chunkingRecommendation.recommendedChunks.length,
138
+ chunkingRecommendation,
139
+ };
140
+ }
141
+ /**
142
+ * Generate a chunking recommendation for files that exceed context window
143
+ * @param fileAnalyses Array of file token analyses
144
+ * @param estimatedTotalTokens Total tokens including overhead
145
+ * @param contextWindowSize Maximum context window size
146
+ * @param contextMaintenanceFactor Context maintenance overhead factor
147
+ * @param forceSinglePass Force single pass mode regardless of token count
148
+ * @param batchTokenLimit Force maximum tokens per batch (for testing)
149
+ * @returns Chunking recommendation
150
+ */
151
+ static generateChunkingRecommendation(fileAnalyses, estimatedTotalTokens, contextWindowSize, contextMaintenanceFactor, forceSinglePass, batchTokenLimit) {
152
+ // If forceSinglePass is true, skip chunking regardless of token count
153
+ if (forceSinglePass) {
154
+ logger_1.default.debug(`Forcing single-pass review mode as requested (forceSinglePass=true)`);
155
+ return {
156
+ chunkingRecommended: false,
157
+ recommendedChunks: [
158
+ {
159
+ files: fileAnalyses.map((f) => f.path),
160
+ estimatedTokenCount: estimatedTotalTokens,
161
+ priority: 1,
162
+ },
163
+ ],
164
+ reason: 'Single-pass mode forced by configuration',
165
+ };
166
+ }
167
+ // If batchTokenLimit is provided, use it to force smaller batches
168
+ let effectiveContextLimit = contextWindowSize;
169
+ if (batchTokenLimit && batchTokenLimit > 0) {
170
+ effectiveContextLimit = Math.min(batchTokenLimit, contextWindowSize);
171
+ logger_1.default.info(`Using batch token limit: ${batchTokenLimit.toLocaleString()} tokens (forcing smaller batches for testing)`);
172
+ if (batchTokenLimit < contextWindowSize) {
173
+ logger_1.default.info(`This will force chunking even if content would fit in the model's context window`);
174
+ }
175
+ }
176
+ // If content fits within context window, no chunking needed
177
+ if (estimatedTotalTokens <= effectiveContextLimit) {
178
+ logger_1.default.debug(`Content fits within effective limit (${estimatedTotalTokens.toLocaleString()} <= ${effectiveContextLimit.toLocaleString()} tokens)`);
179
+ return {
180
+ chunkingRecommended: false,
181
+ recommendedChunks: [
182
+ {
183
+ files: fileAnalyses.map((f) => f.path),
184
+ estimatedTokenCount: estimatedTotalTokens,
185
+ priority: 1,
186
+ },
187
+ ],
188
+ reason: batchTokenLimit
189
+ ? 'Content fits within batch token limit'
190
+ : 'Content fits within model context window',
191
+ };
192
+ }
193
+ logger_1.default.debug(`Content exceeds effective limit (${estimatedTotalTokens.toLocaleString()} > ${effectiveContextLimit.toLocaleString()} tokens)`);
194
+ logger_1.default.debug(`Generating chunking recommendation with context maintenance factor: ${contextMaintenanceFactor}`);
195
+ // Calculate effective context window size accounting for context maintenance
196
+ const effectiveContextSize = Math.floor(effectiveContextLimit * (1 - contextMaintenanceFactor));
197
+ logger_1.default.debug(`Effective context size for chunking: ${effectiveContextSize.toLocaleString()} tokens (${Math.round((1 - contextMaintenanceFactor) * 100)}% of ${effectiveContextLimit.toLocaleString()} tokens)`);
198
+ // Use optimized bin-packing algorithm for better chunk distribution
199
+ const chunks = TokenAnalyzer.optimizedBinPacking(fileAnalyses, effectiveContextSize, effectiveContextLimit);
200
+ logger_1.default.info(`Created ${chunks.length} optimized chunks for multi-pass review`);
201
+ let reason = `Content exceeds effective limit (${estimatedTotalTokens.toLocaleString()} > ${effectiveContextLimit.toLocaleString()} tokens)`;
202
+ if (batchTokenLimit && batchTokenLimit < contextWindowSize) {
203
+ reason = `Batch token limit forcing smaller batches (limit: ${batchTokenLimit.toLocaleString()} tokens)`;
204
+ }
205
+ return {
206
+ chunkingRecommended: true,
207
+ recommendedChunks: chunks,
208
+ reason,
209
+ };
210
+ }
211
+ /**
212
+ * Optimized bin-packing algorithm to minimize the number of chunks
213
+ * Uses an advanced first-fit decreasing with multi-level optimization
214
+ * @param fileAnalyses Array of file token analyses
215
+ * @param maxChunkSize Maximum size for each chunk in tokens
216
+ * @param contextWindowSize Original context window for logging
217
+ * @returns Array of optimized file chunks
218
+ */
219
+ static optimizedBinPacking(fileAnalyses, maxChunkSize, _contextWindowSize) {
220
+ // Sort files by token count (largest first) for first-fit decreasing
221
+ const sortedFiles = [...fileAnalyses].sort((a, b) => b.tokenCount - a.tokenCount);
222
+ // Calculate target chunk size for optimal distribution
223
+ const totalTokens = sortedFiles.reduce((sum, f) => sum + f.tokenCount, 0);
224
+ const minChunksNeeded = Math.ceil(totalTokens / maxChunkSize);
225
+ const targetChunkSize = Math.floor(totalTokens / minChunksNeeded);
226
+ logger_1.default.debug(`Bin-packing optimization:`);
227
+ logger_1.default.debug(` - Total tokens: ${totalTokens.toLocaleString()}`);
228
+ logger_1.default.debug(` - Max chunk size: ${maxChunkSize.toLocaleString()}`);
229
+ logger_1.default.debug(` - Min chunks needed: ${minChunksNeeded}`);
230
+ logger_1.default.debug(` - Target chunk size: ${targetChunkSize.toLocaleString()}`);
231
+ // Initialize chunks array
232
+ const chunks = [];
233
+ // Track oversized files separately
234
+ const oversizedFiles = [];
235
+ const largeFiles = [];
236
+ const mediumFiles = [];
237
+ const smallFiles = [];
238
+ // Categorize files by size for better packing
239
+ for (const file of sortedFiles) {
240
+ if (file.tokenCount > maxChunkSize) {
241
+ oversizedFiles.push(file);
242
+ logger_1.default.warn(`File "${file.path}" is oversized (${file.tokenCount.toLocaleString()} > ${maxChunkSize.toLocaleString()} tokens)`);
243
+ }
244
+ else if (file.tokenCount > maxChunkSize * 0.5) {
245
+ largeFiles.push(file);
246
+ }
247
+ else if (file.tokenCount > maxChunkSize * 0.2) {
248
+ mediumFiles.push(file);
249
+ }
250
+ else {
251
+ smallFiles.push(file);
252
+ }
253
+ }
254
+ logger_1.default.debug(`File categorization:`);
255
+ logger_1.default.debug(` - Oversized: ${oversizedFiles.length}`);
256
+ logger_1.default.debug(` - Large (>50% of max): ${largeFiles.length}`);
257
+ logger_1.default.debug(` - Medium (20-50% of max): ${mediumFiles.length}`);
258
+ logger_1.default.debug(` - Small (<20% of max): ${smallFiles.length}`);
259
+ // Process oversized files first (split them if possible)
260
+ for (const file of oversizedFiles) {
261
+ // For now, put oversized files in their own chunks
262
+ // TODO: In future, we could split file content
263
+ chunks.push({
264
+ files: [file.path],
265
+ estimatedTokenCount: file.tokenCount,
266
+ priority: chunks.length + 1,
267
+ });
268
+ logger_1.default.debug(`Created dedicated chunk ${chunks.length} for oversized file "${file.path}" (${file.tokenCount.toLocaleString()} tokens)`);
269
+ }
270
+ // Process large files - try to pair them optimally
271
+ for (const file of largeFiles) {
272
+ let placed = false;
273
+ // Try to find a chunk with complementary space
274
+ for (let i = 0; i < chunks.length; i++) {
275
+ const chunk = chunks[i];
276
+ const remainingSpace = maxChunkSize - chunk.estimatedTokenCount;
277
+ // Check if this file fits well (within 80% efficiency)
278
+ if (remainingSpace >= file.tokenCount &&
279
+ chunk.estimatedTokenCount + file.tokenCount >= targetChunkSize * 0.8) {
280
+ chunk.files.push(file.path);
281
+ chunk.estimatedTokenCount += file.tokenCount;
282
+ placed = true;
283
+ logger_1.default.debug(`Added large file "${file.path}" (${file.tokenCount.toLocaleString()} tokens) to chunk ${i + 1}`);
284
+ break;
285
+ }
286
+ }
287
+ if (!placed) {
288
+ // Create a new chunk for this large file
289
+ chunks.push({
290
+ files: [file.path],
291
+ estimatedTokenCount: file.tokenCount,
292
+ priority: chunks.length + 1,
293
+ });
294
+ logger_1.default.debug(`Created new chunk ${chunks.length} for large file "${file.path}" (${file.tokenCount.toLocaleString()} tokens)`);
295
+ }
296
+ }
297
+ // Process medium files - use first-fit with efficiency threshold
298
+ for (const file of mediumFiles) {
299
+ let placed = false;
300
+ // Find first chunk where this file fits efficiently
301
+ for (let i = 0; i < chunks.length; i++) {
302
+ const chunk = chunks[i];
303
+ const remainingSpace = maxChunkSize - chunk.estimatedTokenCount;
304
+ if (remainingSpace >= file.tokenCount) {
305
+ chunk.files.push(file.path);
306
+ chunk.estimatedTokenCount += file.tokenCount;
307
+ placed = true;
308
+ logger_1.default.debug(`Added medium file "${file.path}" (${file.tokenCount.toLocaleString()} tokens) to chunk ${i + 1}`);
309
+ break;
310
+ }
311
+ }
312
+ if (!placed) {
313
+ // Create a new chunk
314
+ chunks.push({
315
+ files: [file.path],
316
+ estimatedTokenCount: file.tokenCount,
317
+ priority: chunks.length + 1,
318
+ });
319
+ logger_1.default.debug(`Created new chunk ${chunks.length} for medium file "${file.path}" (${file.tokenCount.toLocaleString()} tokens)`);
320
+ }
321
+ }
322
+ // Process small files - pack them to fill gaps
323
+ // Sort small files for better packing (largest first)
324
+ smallFiles.sort((a, b) => b.tokenCount - a.tokenCount);
325
+ for (const file of smallFiles) {
326
+ let placed = false;
327
+ // Find the fullest chunk that can still fit this file
328
+ let bestChunkIndex = -1;
329
+ let bestChunkFullness = 0;
330
+ for (let i = 0; i < chunks.length; i++) {
331
+ const chunk = chunks[i];
332
+ const remainingSpace = maxChunkSize - chunk.estimatedTokenCount;
333
+ const chunkFullness = chunk.estimatedTokenCount / maxChunkSize;
334
+ if (remainingSpace >= file.tokenCount && chunkFullness > bestChunkFullness) {
335
+ bestChunkIndex = i;
336
+ bestChunkFullness = chunkFullness;
337
+ }
338
+ }
339
+ if (bestChunkIndex !== -1) {
340
+ const chunk = chunks[bestChunkIndex];
341
+ chunk.files.push(file.path);
342
+ chunk.estimatedTokenCount += file.tokenCount;
343
+ placed = true;
344
+ logger_1.default.debug(`Added small file "${file.path}" (${file.tokenCount.toLocaleString()} tokens) to chunk ${bestChunkIndex + 1}`);
345
+ }
346
+ if (!placed) {
347
+ // Create a new chunk only if absolutely necessary
348
+ chunks.push({
349
+ files: [file.path],
350
+ estimatedTokenCount: file.tokenCount,
351
+ priority: chunks.length + 1,
352
+ });
353
+ logger_1.default.debug(`Created new chunk ${chunks.length} for small file "${file.path}" (${file.tokenCount.toLocaleString()} tokens)`);
354
+ }
355
+ }
356
+ // Perform aggressive balancing to minimize chunk count
357
+ const balancedChunks = TokenAnalyzer.aggressiveBalance(chunks, fileAnalyses, maxChunkSize);
358
+ // Log chunk statistics
359
+ const avgTokensPerChunk = Math.round(balancedChunks.reduce((sum, c) => sum + c.estimatedTokenCount, 0) / balancedChunks.length);
360
+ const maxTokensInChunk = Math.max(...balancedChunks.map((c) => c.estimatedTokenCount));
361
+ const minTokensInChunk = Math.min(...balancedChunks.map((c) => c.estimatedTokenCount));
362
+ logger_1.default.info(`Chunk statistics:`);
363
+ logger_1.default.info(` - Total chunks: ${balancedChunks.length}`);
364
+ logger_1.default.info(` - Average tokens per chunk: ${avgTokensPerChunk.toLocaleString()}`);
365
+ logger_1.default.info(` - Max tokens in a chunk: ${maxTokensInChunk.toLocaleString()}`);
366
+ logger_1.default.info(` - Min tokens in a chunk: ${minTokensInChunk.toLocaleString()}`);
367
+ logger_1.default.info(` - Chunk efficiency: ${((avgTokensPerChunk / maxChunkSize) * 100).toFixed(1)}%`);
368
+ return balancedChunks;
369
+ }
370
+ /**
371
+ * Aggressive balancing to minimize chunk count and maximize efficiency
372
+ * @param chunks Initial chunks from bin-packing
373
+ * @param fileAnalyses Original file analyses for lookup
374
+ * @param maxChunkSize Maximum size for each chunk
375
+ * @returns Balanced chunks with minimized count
376
+ */
377
+ static aggressiveBalance(chunks, fileAnalyses, maxChunkSize) {
378
+ // Create a map for quick file lookups
379
+ const fileMap = new Map();
380
+ for (const file of fileAnalyses) {
381
+ fileMap.set(file.path, file);
382
+ }
383
+ // First pass: Try to merge small chunks
384
+ const mergedChunks = [];
385
+ const sortedForMerging = [...chunks].sort((a, b) => a.estimatedTokenCount - b.estimatedTokenCount);
386
+ const usedChunks = new Set();
387
+ for (let i = 0; i < sortedForMerging.length; i++) {
388
+ if (usedChunks.has(i))
389
+ continue;
390
+ const chunk1 = sortedForMerging[i];
391
+ const mergedChunk = {
392
+ files: [...chunk1.files],
393
+ estimatedTokenCount: chunk1.estimatedTokenCount,
394
+ priority: mergedChunks.length + 1,
395
+ };
396
+ usedChunks.add(i);
397
+ // Try to merge with other small chunks
398
+ for (let j = i + 1; j < sortedForMerging.length; j++) {
399
+ if (usedChunks.has(j))
400
+ continue;
401
+ const chunk2 = sortedForMerging[j];
402
+ const combinedSize = mergedChunk.estimatedTokenCount + chunk2.estimatedTokenCount;
403
+ // Merge if combined size is still within limits
404
+ if (combinedSize <= maxChunkSize) {
405
+ mergedChunk.files.push(...chunk2.files);
406
+ mergedChunk.estimatedTokenCount = combinedSize;
407
+ usedChunks.add(j);
408
+ logger_1.default.debug(`Merged chunks: ${chunk2.files.length} files (${chunk2.estimatedTokenCount.toLocaleString()} tokens) into chunk with ${mergedChunk.files.length} files`);
409
+ }
410
+ }
411
+ mergedChunks.push(mergedChunk);
412
+ }
413
+ logger_1.default.debug(`Chunk merging reduced count from ${chunks.length} to ${mergedChunks.length}`);
414
+ // Second pass: Balance the merged chunks
415
+ const sortedChunks = [...mergedChunks].sort((a, b) => a.estimatedTokenCount - b.estimatedTokenCount);
416
+ // Try to move files to achieve better balance
417
+ let improved = true;
418
+ let iterations = 0;
419
+ const maxIterations = 20; // More iterations for aggressive optimization
420
+ while (improved && iterations < maxIterations) {
421
+ improved = false;
422
+ iterations++;
423
+ // Find the most and least full chunks
424
+ sortedChunks.sort((a, b) => a.estimatedTokenCount - b.estimatedTokenCount);
425
+ for (let i = 0; i < Math.floor(sortedChunks.length / 2); i++) {
426
+ const smallChunk = sortedChunks[i];
427
+ const largeChunk = sortedChunks[sortedChunks.length - 1 - i];
428
+ // Calculate variance threshold based on chunk count
429
+ const varianceThreshold = Math.max(500, maxChunkSize * 0.05); // 5% of max or 500 tokens
430
+ // Skip if chunks are already well balanced
431
+ if (largeChunk.estimatedTokenCount - smallChunk.estimatedTokenCount < varianceThreshold) {
432
+ continue;
433
+ }
434
+ // Try to find optimal file to move
435
+ let bestFile = null;
436
+ let bestImprovement = 0;
437
+ for (const filePath of largeChunk.files) {
438
+ const file = fileMap.get(filePath);
439
+ if (!file)
440
+ continue;
441
+ const newSmallSize = smallChunk.estimatedTokenCount + file.tokenCount;
442
+ const newLargeSize = largeChunk.estimatedTokenCount - file.tokenCount;
443
+ // Check if moving this file would improve balance
444
+ if (newSmallSize <= maxChunkSize && newLargeSize > 0) {
445
+ const currentDiff = largeChunk.estimatedTokenCount - smallChunk.estimatedTokenCount;
446
+ const newDiff = Math.abs(newLargeSize - newSmallSize);
447
+ const improvement = currentDiff - newDiff;
448
+ if (improvement > bestImprovement) {
449
+ bestFile = filePath;
450
+ bestImprovement = improvement;
451
+ }
452
+ }
453
+ }
454
+ // Move the best file if found
455
+ if (bestFile && bestImprovement > 100) {
456
+ const file = fileMap.get(bestFile);
457
+ largeChunk.files = largeChunk.files.filter((f) => f !== bestFile);
458
+ smallChunk.files.push(bestFile);
459
+ // Update token counts
460
+ largeChunk.estimatedTokenCount -= file.tokenCount;
461
+ smallChunk.estimatedTokenCount += file.tokenCount;
462
+ logger_1.default.debug(`Balanced: Moved file "${bestFile}" (${file.tokenCount.toLocaleString()} tokens) - improvement: ${bestImprovement.toLocaleString()} tokens`);
463
+ improved = true;
464
+ }
465
+ }
466
+ }
467
+ // Final pass: Remove any empty chunks
468
+ const finalChunks = sortedChunks.filter((chunk) => chunk.files.length > 0);
469
+ // Re-assign priorities based on token count (largest first for processing)
470
+ finalChunks.sort((a, b) => b.estimatedTokenCount - a.estimatedTokenCount);
471
+ finalChunks.forEach((chunk, index) => {
472
+ chunk.priority = index + 1;
473
+ });
474
+ if (iterations === maxIterations) {
475
+ logger_1.default.debug(`Aggressive balancing stopped after ${maxIterations} iterations`);
476
+ }
477
+ else {
478
+ logger_1.default.debug(`Aggressive balancing completed in ${iterations} iterations`);
479
+ }
480
+ return finalChunks;
481
+ }
482
+ /**
483
+ * Analyze a single file for token usage
484
+ * @param file File to analyze
485
+ * @param options Analysis options
486
+ * @returns Token analysis for the file
487
+ */
488
+ static analyzeFile(file, options) {
489
+ const content = file.content;
490
+ const tokenCount = (0, tokenizers_1.countTokens)(content, options.modelName);
491
+ const sizeInBytes = content.length;
492
+ return {
493
+ path: file.path,
494
+ relativePath: file.relativePath,
495
+ tokenCount,
496
+ sizeInBytes,
497
+ tokensPerByte: sizeInBytes > 0 ? tokenCount / sizeInBytes : 0,
498
+ };
499
+ }
500
+ }
501
+ exports.TokenAnalyzer = TokenAnalyzer;
502
+ //# sourceMappingURL=TokenAnalyzer.js.map