@nexus-ai-nexoralabs/cli 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (411) hide show
  1. package/.env.example +16 -0
  2. package/LICENSE +21 -0
  3. package/README.md +106 -0
  4. package/dist/api/index.d.ts +81 -0
  5. package/dist/api/index.d.ts.map +1 -0
  6. package/dist/api/index.js +224 -0
  7. package/dist/api/index.js.map +1 -0
  8. package/dist/chat/chatService.d.ts +49 -0
  9. package/dist/chat/chatService.d.ts.map +1 -0
  10. package/dist/chat/chatService.js +163 -0
  11. package/dist/chat/chatService.js.map +1 -0
  12. package/dist/chat/contextBuilder.d.ts +19 -0
  13. package/dist/chat/contextBuilder.d.ts.map +1 -0
  14. package/dist/chat/contextBuilder.js +43 -0
  15. package/dist/chat/contextBuilder.js.map +1 -0
  16. package/dist/chat/conversationService.d.ts +25 -0
  17. package/dist/chat/conversationService.d.ts.map +1 -0
  18. package/dist/chat/conversationService.js +55 -0
  19. package/dist/chat/conversationService.js.map +1 -0
  20. package/dist/chat/index.d.ts +6 -0
  21. package/dist/chat/index.d.ts.map +1 -0
  22. package/dist/chat/index.js +6 -0
  23. package/dist/chat/index.js.map +1 -0
  24. package/dist/chat/messageService.d.ts +18 -0
  25. package/dist/chat/messageService.d.ts.map +1 -0
  26. package/dist/chat/messageService.js +26 -0
  27. package/dist/chat/messageService.js.map +1 -0
  28. package/dist/chat/promptTemplates.d.ts +19 -0
  29. package/dist/chat/promptTemplates.d.ts.map +1 -0
  30. package/dist/chat/promptTemplates.js +32 -0
  31. package/dist/chat/promptTemplates.js.map +1 -0
  32. package/dist/cli/agentRunner.d.ts +126 -0
  33. package/dist/cli/agentRunner.d.ts.map +1 -0
  34. package/dist/cli/agentRunner.js +892 -0
  35. package/dist/cli/agentRunner.js.map +1 -0
  36. package/dist/cli/bin.d.ts +14 -0
  37. package/dist/cli/bin.d.ts.map +1 -0
  38. package/dist/cli/bin.js +20 -0
  39. package/dist/cli/bin.js.map +1 -0
  40. package/dist/cli/index.d.ts +3 -0
  41. package/dist/cli/index.d.ts.map +1 -0
  42. package/dist/cli/index.js +2 -0
  43. package/dist/cli/index.js.map +1 -0
  44. package/dist/cli/inputEngine.d.ts +76 -0
  45. package/dist/cli/inputEngine.d.ts.map +1 -0
  46. package/dist/cli/inputEngine.js +281 -0
  47. package/dist/cli/inputEngine.js.map +1 -0
  48. package/dist/cli/main.d.ts +9 -0
  49. package/dist/cli/main.d.ts.map +1 -0
  50. package/dist/cli/main.js +144 -0
  51. package/dist/cli/main.js.map +1 -0
  52. package/dist/cli/uiFormatters.d.ts +108 -0
  53. package/dist/cli/uiFormatters.d.ts.map +1 -0
  54. package/dist/cli/uiFormatters.js +925 -0
  55. package/dist/cli/uiFormatters.js.map +1 -0
  56. package/dist/common/logger.d.ts +13 -0
  57. package/dist/common/logger.d.ts.map +1 -0
  58. package/dist/common/logger.js +43 -0
  59. package/dist/common/logger.js.map +1 -0
  60. package/dist/config/firstRunHealthCheck.d.ts +50 -0
  61. package/dist/config/firstRunHealthCheck.d.ts.map +1 -0
  62. package/dist/config/firstRunHealthCheck.js +196 -0
  63. package/dist/config/firstRunHealthCheck.js.map +1 -0
  64. package/dist/config/firstRunService.d.ts +53 -0
  65. package/dist/config/firstRunService.d.ts.map +1 -0
  66. package/dist/config/firstRunService.js +93 -0
  67. package/dist/config/firstRunService.js.map +1 -0
  68. package/dist/config/index.d.ts +30 -0
  69. package/dist/config/index.d.ts.map +1 -0
  70. package/dist/config/index.js +65 -0
  71. package/dist/config/index.js.map +1 -0
  72. package/dist/config/productionPaths.d.ts +34 -0
  73. package/dist/config/productionPaths.d.ts.map +1 -0
  74. package/dist/config/productionPaths.js +95 -0
  75. package/dist/config/productionPaths.js.map +1 -0
  76. package/dist/config/workspaceService.d.ts +42 -0
  77. package/dist/config/workspaceService.d.ts.map +1 -0
  78. package/dist/config/workspaceService.js +218 -0
  79. package/dist/config/workspaceService.js.map +1 -0
  80. package/dist/desktop/appWindow.d.ts +21 -0
  81. package/dist/desktop/appWindow.d.ts.map +1 -0
  82. package/dist/desktop/appWindow.js +77 -0
  83. package/dist/desktop/appWindow.js.map +1 -0
  84. package/dist/desktop/main.d.ts +14 -0
  85. package/dist/desktop/main.d.ts.map +1 -0
  86. package/dist/desktop/main.js +90 -0
  87. package/dist/desktop/main.js.map +1 -0
  88. package/dist/desktop/preload.d.ts +14 -0
  89. package/dist/desktop/preload.d.ts.map +1 -0
  90. package/dist/desktop/preload.js +20 -0
  91. package/dist/desktop/preload.js.map +1 -0
  92. package/dist/intelligence/index.d.ts +33 -0
  93. package/dist/intelligence/index.d.ts.map +1 -0
  94. package/dist/intelligence/index.js +82 -0
  95. package/dist/intelligence/index.js.map +1 -0
  96. package/dist/intelligence/modelGateway.d.ts +35 -0
  97. package/dist/intelligence/modelGateway.d.ts.map +1 -0
  98. package/dist/intelligence/modelGateway.js +123 -0
  99. package/dist/intelligence/modelGateway.js.map +1 -0
  100. package/dist/intelligence/modelRegistry.d.ts +17 -0
  101. package/dist/intelligence/modelRegistry.d.ts.map +1 -0
  102. package/dist/intelligence/modelRegistry.js +87 -0
  103. package/dist/intelligence/modelRegistry.js.map +1 -0
  104. package/dist/intelligence/modelRouter.d.ts +76 -0
  105. package/dist/intelligence/modelRouter.d.ts.map +1 -0
  106. package/dist/intelligence/modelRouter.js +256 -0
  107. package/dist/intelligence/modelRouter.js.map +1 -0
  108. package/dist/intelligence/ollamaAdapter.d.ts +49 -0
  109. package/dist/intelligence/ollamaAdapter.d.ts.map +1 -0
  110. package/dist/intelligence/ollamaAdapter.js +197 -0
  111. package/dist/intelligence/ollamaAdapter.js.map +1 -0
  112. package/dist/intelligence/prototype/runPrototype.d.ts +14 -0
  113. package/dist/intelligence/prototype/runPrototype.d.ts.map +1 -0
  114. package/dist/intelligence/prototype/runPrototype.js +87 -0
  115. package/dist/intelligence/prototype/runPrototype.js.map +1 -0
  116. package/dist/intelligence/providers/embeddedInferenceProvider.d.ts +29 -0
  117. package/dist/intelligence/providers/embeddedInferenceProvider.d.ts.map +1 -0
  118. package/dist/intelligence/providers/embeddedInferenceProvider.js +162 -0
  119. package/dist/intelligence/providers/embeddedInferenceProvider.js.map +1 -0
  120. package/dist/intelligence/providers/index.d.ts +4 -0
  121. package/dist/intelligence/providers/index.d.ts.map +1 -0
  122. package/dist/intelligence/providers/index.js +4 -0
  123. package/dist/intelligence/providers/index.js.map +1 -0
  124. package/dist/intelligence/providers/inferenceProvider.d.ts +98 -0
  125. package/dist/intelligence/providers/inferenceProvider.d.ts.map +1 -0
  126. package/dist/intelligence/providers/inferenceProvider.js +9 -0
  127. package/dist/intelligence/providers/inferenceProvider.js.map +1 -0
  128. package/dist/intelligence/providers/ollamaInferenceProvider.d.ts +17 -0
  129. package/dist/intelligence/providers/ollamaInferenceProvider.d.ts.map +1 -0
  130. package/dist/intelligence/providers/ollamaInferenceProvider.js +103 -0
  131. package/dist/intelligence/providers/ollamaInferenceProvider.js.map +1 -0
  132. package/dist/intelligence/provisioning/hardwareDetector.d.ts +5 -0
  133. package/dist/intelligence/provisioning/hardwareDetector.d.ts.map +1 -0
  134. package/dist/intelligence/provisioning/hardwareDetector.js +48 -0
  135. package/dist/intelligence/provisioning/hardwareDetector.js.map +1 -0
  136. package/dist/intelligence/provisioning/index.d.ts +12 -0
  137. package/dist/intelligence/provisioning/index.d.ts.map +1 -0
  138. package/dist/intelligence/provisioning/index.js +12 -0
  139. package/dist/intelligence/provisioning/index.js.map +1 -0
  140. package/dist/intelligence/provisioning/modelDownloader.d.ts +22 -0
  141. package/dist/intelligence/provisioning/modelDownloader.d.ts.map +1 -0
  142. package/dist/intelligence/provisioning/modelDownloader.js +134 -0
  143. package/dist/intelligence/provisioning/modelDownloader.js.map +1 -0
  144. package/dist/intelligence/provisioning/modelManifest.d.ts +10 -0
  145. package/dist/intelligence/provisioning/modelManifest.d.ts.map +1 -0
  146. package/dist/intelligence/provisioning/modelManifest.js +72 -0
  147. package/dist/intelligence/provisioning/modelManifest.js.map +1 -0
  148. package/dist/intelligence/provisioning/modelSelector.d.ts +14 -0
  149. package/dist/intelligence/provisioning/modelSelector.d.ts.map +1 -0
  150. package/dist/intelligence/provisioning/modelSelector.js +40 -0
  151. package/dist/intelligence/provisioning/modelSelector.js.map +1 -0
  152. package/dist/intelligence/provisioning/modelStorage.d.ts +12 -0
  153. package/dist/intelligence/provisioning/modelStorage.d.ts.map +1 -0
  154. package/dist/intelligence/provisioning/modelStorage.js +66 -0
  155. package/dist/intelligence/provisioning/modelStorage.js.map +1 -0
  156. package/dist/intelligence/provisioning/modelUpdater.d.ts +29 -0
  157. package/dist/intelligence/provisioning/modelUpdater.d.ts.map +1 -0
  158. package/dist/intelligence/provisioning/modelUpdater.js +89 -0
  159. package/dist/intelligence/provisioning/modelUpdater.js.map +1 -0
  160. package/dist/intelligence/provisioning/modelVerifier.d.ts +16 -0
  161. package/dist/intelligence/provisioning/modelVerifier.d.ts.map +1 -0
  162. package/dist/intelligence/provisioning/modelVerifier.js +108 -0
  163. package/dist/intelligence/provisioning/modelVerifier.js.map +1 -0
  164. package/dist/intelligence/provisioning/nativeRuntime.d.ts +18 -0
  165. package/dist/intelligence/provisioning/nativeRuntime.d.ts.map +1 -0
  166. package/dist/intelligence/provisioning/nativeRuntime.js +78 -0
  167. package/dist/intelligence/provisioning/nativeRuntime.js.map +1 -0
  168. package/dist/intelligence/provisioning/platformDetector.d.ts +15 -0
  169. package/dist/intelligence/provisioning/platformDetector.d.ts.map +1 -0
  170. package/dist/intelligence/provisioning/platformDetector.js +40 -0
  171. package/dist/intelligence/provisioning/platformDetector.js.map +1 -0
  172. package/dist/intelligence/provisioning/setupState.d.ts +10 -0
  173. package/dist/intelligence/provisioning/setupState.d.ts.map +1 -0
  174. package/dist/intelligence/provisioning/setupState.js +59 -0
  175. package/dist/intelligence/provisioning/setupState.js.map +1 -0
  176. package/dist/intelligence/provisioning/types.d.ts +51 -0
  177. package/dist/intelligence/provisioning/types.d.ts.map +1 -0
  178. package/dist/intelligence/provisioning/types.js +2 -0
  179. package/dist/intelligence/provisioning/types.js.map +1 -0
  180. package/dist/intelligence/runtime/embeddedRuntimeAdapter.d.ts +26 -0
  181. package/dist/intelligence/runtime/embeddedRuntimeAdapter.d.ts.map +1 -0
  182. package/dist/intelligence/runtime/embeddedRuntimeAdapter.js +119 -0
  183. package/dist/intelligence/runtime/embeddedRuntimeAdapter.js.map +1 -0
  184. package/dist/intelligence/runtime/ollamaRuntimeAdapter.d.ts +28 -0
  185. package/dist/intelligence/runtime/ollamaRuntimeAdapter.d.ts.map +1 -0
  186. package/dist/intelligence/runtime/ollamaRuntimeAdapter.js +131 -0
  187. package/dist/intelligence/runtime/ollamaRuntimeAdapter.js.map +1 -0
  188. package/dist/intelligence/runtime/runtimeManager.d.ts +37 -0
  189. package/dist/intelligence/runtime/runtimeManager.d.ts.map +1 -0
  190. package/dist/intelligence/runtime/runtimeManager.js +168 -0
  191. package/dist/intelligence/runtime/runtimeManager.js.map +1 -0
  192. package/dist/intelligence/runtime/types.d.ts +56 -0
  193. package/dist/intelligence/runtime/types.d.ts.map +1 -0
  194. package/dist/intelligence/runtime/types.js +7 -0
  195. package/dist/intelligence/runtime/types.js.map +1 -0
  196. package/dist/knowledge/chunker.d.ts +18 -0
  197. package/dist/knowledge/chunker.d.ts.map +1 -0
  198. package/dist/knowledge/chunker.js +55 -0
  199. package/dist/knowledge/chunker.js.map +1 -0
  200. package/dist/knowledge/citationService.d.ts +26 -0
  201. package/dist/knowledge/citationService.d.ts.map +1 -0
  202. package/dist/knowledge/citationService.js +47 -0
  203. package/dist/knowledge/citationService.js.map +1 -0
  204. package/dist/knowledge/embeddings.d.ts +11 -0
  205. package/dist/knowledge/embeddings.d.ts.map +1 -0
  206. package/dist/knowledge/embeddings.js +28 -0
  207. package/dist/knowledge/embeddings.js.map +1 -0
  208. package/dist/knowledge/hybridSearch.d.ts +13 -0
  209. package/dist/knowledge/hybridSearch.d.ts.map +1 -0
  210. package/dist/knowledge/hybridSearch.js +38 -0
  211. package/dist/knowledge/hybridSearch.js.map +1 -0
  212. package/dist/knowledge/index.d.ts +25 -0
  213. package/dist/knowledge/index.d.ts.map +1 -0
  214. package/dist/knowledge/index.js +37 -0
  215. package/dist/knowledge/index.js.map +1 -0
  216. package/dist/knowledge/parsers.d.ts +20 -0
  217. package/dist/knowledge/parsers.d.ts.map +1 -0
  218. package/dist/knowledge/parsers.js +94 -0
  219. package/dist/knowledge/parsers.js.map +1 -0
  220. package/dist/knowledge/ragEngine.d.ts +24 -0
  221. package/dist/knowledge/ragEngine.d.ts.map +1 -0
  222. package/dist/knowledge/ragEngine.js +121 -0
  223. package/dist/knowledge/ragEngine.js.map +1 -0
  224. package/dist/knowledge/reranker.d.ts +10 -0
  225. package/dist/knowledge/reranker.d.ts.map +1 -0
  226. package/dist/knowledge/reranker.js +11 -0
  227. package/dist/knowledge/reranker.js.map +1 -0
  228. package/dist/knowledge/vectorStore.d.ts +22 -0
  229. package/dist/knowledge/vectorStore.d.ts.map +1 -0
  230. package/dist/knowledge/vectorStore.js +74 -0
  231. package/dist/knowledge/vectorStore.js.map +1 -0
  232. package/dist/main.d.ts +2 -0
  233. package/dist/main.d.ts.map +1 -0
  234. package/dist/main.js +113 -0
  235. package/dist/main.js.map +1 -0
  236. package/dist/orchestration/agentExecutionService.d.ts +29 -0
  237. package/dist/orchestration/agentExecutionService.d.ts.map +1 -0
  238. package/dist/orchestration/agentExecutionService.js +306 -0
  239. package/dist/orchestration/agentExecutionService.js.map +1 -0
  240. package/dist/orchestration/agentStateMachine.d.ts +29 -0
  241. package/dist/orchestration/agentStateMachine.d.ts.map +1 -0
  242. package/dist/orchestration/agentStateMachine.js +153 -0
  243. package/dist/orchestration/agentStateMachine.js.map +1 -0
  244. package/dist/orchestration/agentTaskService.d.ts +44 -0
  245. package/dist/orchestration/agentTaskService.d.ts.map +1 -0
  246. package/dist/orchestration/agentTaskService.js +168 -0
  247. package/dist/orchestration/agentTaskService.js.map +1 -0
  248. package/dist/orchestration/codingAgentDiscovery.d.ts +32 -0
  249. package/dist/orchestration/codingAgentDiscovery.d.ts.map +1 -0
  250. package/dist/orchestration/codingAgentDiscovery.js +148 -0
  251. package/dist/orchestration/codingAgentDiscovery.js.map +1 -0
  252. package/dist/orchestration/codingAgentService.d.ts +40 -0
  253. package/dist/orchestration/codingAgentService.d.ts.map +1 -0
  254. package/dist/orchestration/codingAgentService.js +319 -0
  255. package/dist/orchestration/codingAgentService.js.map +1 -0
  256. package/dist/orchestration/codingAgentTypes.d.ts +111 -0
  257. package/dist/orchestration/codingAgentTypes.d.ts.map +1 -0
  258. package/dist/orchestration/codingAgentTypes.js +32 -0
  259. package/dist/orchestration/codingAgentTypes.js.map +1 -0
  260. package/dist/orchestration/codingAgentVerifier.d.ts +34 -0
  261. package/dist/orchestration/codingAgentVerifier.d.ts.map +1 -0
  262. package/dist/orchestration/codingAgentVerifier.js +109 -0
  263. package/dist/orchestration/codingAgentVerifier.js.map +1 -0
  264. package/dist/orchestration/codingRepairService.d.ts +34 -0
  265. package/dist/orchestration/codingRepairService.d.ts.map +1 -0
  266. package/dist/orchestration/codingRepairService.js +120 -0
  267. package/dist/orchestration/codingRepairService.js.map +1 -0
  268. package/dist/orchestration/goalCompletionVerifier.d.ts +36 -0
  269. package/dist/orchestration/goalCompletionVerifier.d.ts.map +1 -0
  270. package/dist/orchestration/goalCompletionVerifier.js +165 -0
  271. package/dist/orchestration/goalCompletionVerifier.js.map +1 -0
  272. package/dist/orchestration/humanApprovalService.d.ts +89 -0
  273. package/dist/orchestration/humanApprovalService.d.ts.map +1 -0
  274. package/dist/orchestration/humanApprovalService.js +346 -0
  275. package/dist/orchestration/humanApprovalService.js.map +1 -0
  276. package/dist/orchestration/index.d.ts +47 -0
  277. package/dist/orchestration/index.d.ts.map +1 -0
  278. package/dist/orchestration/index.js +67 -0
  279. package/dist/orchestration/index.js.map +1 -0
  280. package/dist/orchestration/planner.d.ts +105 -0
  281. package/dist/orchestration/planner.d.ts.map +1 -0
  282. package/dist/orchestration/planner.js +692 -0
  283. package/dist/orchestration/planner.js.map +1 -0
  284. package/dist/orchestration/types.d.ts +109 -0
  285. package/dist/orchestration/types.d.ts.map +1 -0
  286. package/dist/orchestration/types.js +20 -0
  287. package/dist/orchestration/types.js.map +1 -0
  288. package/dist/preview/previewServer.d.ts +39 -0
  289. package/dist/preview/previewServer.d.ts.map +1 -0
  290. package/dist/preview/previewServer.js +228 -0
  291. package/dist/preview/previewServer.js.map +1 -0
  292. package/dist/preview/previewService.d.ts +43 -0
  293. package/dist/preview/previewService.d.ts.map +1 -0
  294. package/dist/preview/previewService.js +289 -0
  295. package/dist/preview/previewService.js.map +1 -0
  296. package/dist/preview/previewTypes.d.ts +35 -0
  297. package/dist/preview/previewTypes.d.ts.map +1 -0
  298. package/dist/preview/previewTypes.js +5 -0
  299. package/dist/preview/previewTypes.js.map +1 -0
  300. package/dist/storage/database.d.ts +12 -0
  301. package/dist/storage/database.d.ts.map +1 -0
  302. package/dist/storage/database.js +46 -0
  303. package/dist/storage/database.js.map +1 -0
  304. package/dist/storage/health.d.ts +17 -0
  305. package/dist/storage/health.d.ts.map +1 -0
  306. package/dist/storage/health.js +48 -0
  307. package/dist/storage/health.js.map +1 -0
  308. package/dist/storage/index.d.ts +45 -0
  309. package/dist/storage/index.d.ts.map +1 -0
  310. package/dist/storage/index.js +96 -0
  311. package/dist/storage/index.js.map +1 -0
  312. package/dist/storage/migration.d.ts +17 -0
  313. package/dist/storage/migration.d.ts.map +1 -0
  314. package/dist/storage/migration.js +354 -0
  315. package/dist/storage/migration.js.map +1 -0
  316. package/dist/storage/projectService.d.ts +19 -0
  317. package/dist/storage/projectService.d.ts.map +1 -0
  318. package/dist/storage/projectService.js +29 -0
  319. package/dist/storage/projectService.js.map +1 -0
  320. package/dist/storage/repositories/agentTaskRepository.d.ts +34 -0
  321. package/dist/storage/repositories/agentTaskRepository.d.ts.map +1 -0
  322. package/dist/storage/repositories/agentTaskRepository.js +128 -0
  323. package/dist/storage/repositories/agentTaskRepository.js.map +1 -0
  324. package/dist/storage/repositories/approvalRepository.d.ts +20 -0
  325. package/dist/storage/repositories/approvalRepository.d.ts.map +1 -0
  326. package/dist/storage/repositories/approvalRepository.js +116 -0
  327. package/dist/storage/repositories/approvalRepository.js.map +1 -0
  328. package/dist/storage/repositories/conversationRepository.d.ts +16 -0
  329. package/dist/storage/repositories/conversationRepository.d.ts.map +1 -0
  330. package/dist/storage/repositories/conversationRepository.js +50 -0
  331. package/dist/storage/repositories/conversationRepository.js.map +1 -0
  332. package/dist/storage/repositories/knowledgeRepository.d.ts +109 -0
  333. package/dist/storage/repositories/knowledgeRepository.d.ts.map +1 -0
  334. package/dist/storage/repositories/knowledgeRepository.js +177 -0
  335. package/dist/storage/repositories/knowledgeRepository.js.map +1 -0
  336. package/dist/storage/repositories/messageRepository.d.ts +13 -0
  337. package/dist/storage/repositories/messageRepository.d.ts.map +1 -0
  338. package/dist/storage/repositories/messageRepository.js +39 -0
  339. package/dist/storage/repositories/messageRepository.js.map +1 -0
  340. package/dist/storage/repositories/modelsRepository.d.ts +39 -0
  341. package/dist/storage/repositories/modelsRepository.d.ts.map +1 -0
  342. package/dist/storage/repositories/modelsRepository.js +92 -0
  343. package/dist/storage/repositories/modelsRepository.js.map +1 -0
  344. package/dist/storage/repositories/projectRepository.d.ts +14 -0
  345. package/dist/storage/repositories/projectRepository.d.ts.map +1 -0
  346. package/dist/storage/repositories/projectRepository.js +44 -0
  347. package/dist/storage/repositories/projectRepository.js.map +1 -0
  348. package/dist/storage/repositories/settingsRepository.d.ts +10 -0
  349. package/dist/storage/repositories/settingsRepository.d.ts.map +1 -0
  350. package/dist/storage/repositories/settingsRepository.js +27 -0
  351. package/dist/storage/repositories/settingsRepository.js.map +1 -0
  352. package/dist/storage/repositories/types.d.ts +56 -0
  353. package/dist/storage/repositories/types.d.ts.map +1 -0
  354. package/dist/storage/repositories/types.js +2 -0
  355. package/dist/storage/repositories/types.js.map +1 -0
  356. package/dist/tools/adapters/filesystemAdapter.d.ts +121 -0
  357. package/dist/tools/adapters/filesystemAdapter.d.ts.map +1 -0
  358. package/dist/tools/adapters/filesystemAdapter.js +808 -0
  359. package/dist/tools/adapters/filesystemAdapter.js.map +1 -0
  360. package/dist/tools/adapters/terminalAdapter.d.ts +67 -0
  361. package/dist/tools/adapters/terminalAdapter.d.ts.map +1 -0
  362. package/dist/tools/adapters/terminalAdapter.js +487 -0
  363. package/dist/tools/adapters/terminalAdapter.js.map +1 -0
  364. package/dist/tools/adapters/terminalCommandPolicy.d.ts +44 -0
  365. package/dist/tools/adapters/terminalCommandPolicy.d.ts.map +1 -0
  366. package/dist/tools/adapters/terminalCommandPolicy.js +422 -0
  367. package/dist/tools/adapters/terminalCommandPolicy.js.map +1 -0
  368. package/dist/tools/adapters/terminalTypes.d.ts +111 -0
  369. package/dist/tools/adapters/terminalTypes.d.ts.map +1 -0
  370. package/dist/tools/adapters/terminalTypes.js +26 -0
  371. package/dist/tools/adapters/terminalTypes.js.map +1 -0
  372. package/dist/tools/approvalGate.d.ts +24 -0
  373. package/dist/tools/approvalGate.d.ts.map +1 -0
  374. package/dist/tools/approvalGate.js +137 -0
  375. package/dist/tools/approvalGate.js.map +1 -0
  376. package/dist/tools/approvalPolicyEngine.d.ts +32 -0
  377. package/dist/tools/approvalPolicyEngine.d.ts.map +1 -0
  378. package/dist/tools/approvalPolicyEngine.js +141 -0
  379. package/dist/tools/approvalPolicyEngine.js.map +1 -0
  380. package/dist/tools/approvalTypes.d.ts +67 -0
  381. package/dist/tools/approvalTypes.d.ts.map +1 -0
  382. package/dist/tools/approvalTypes.js +23 -0
  383. package/dist/tools/approvalTypes.js.map +1 -0
  384. package/dist/tools/index.d.ts +72 -0
  385. package/dist/tools/index.d.ts.map +1 -0
  386. package/dist/tools/index.js +353 -0
  387. package/dist/tools/index.js.map +1 -0
  388. package/dist/tools/permissionEngine.d.ts +27 -0
  389. package/dist/tools/permissionEngine.d.ts.map +1 -0
  390. package/dist/tools/permissionEngine.js +130 -0
  391. package/dist/tools/permissionEngine.js.map +1 -0
  392. package/dist/tools/toolExecutor.d.ts +37 -0
  393. package/dist/tools/toolExecutor.d.ts.map +1 -0
  394. package/dist/tools/toolExecutor.js +440 -0
  395. package/dist/tools/toolExecutor.js.map +1 -0
  396. package/dist/tools/toolRegistry.d.ts +34 -0
  397. package/dist/tools/toolRegistry.d.ts.map +1 -0
  398. package/dist/tools/toolRegistry.js +92 -0
  399. package/dist/tools/toolRegistry.js.map +1 -0
  400. package/dist/tools/types.d.ts +82 -0
  401. package/dist/tools/types.d.ts.map +1 -0
  402. package/dist/tools/types.js +33 -0
  403. package/dist/tools/types.js.map +1 -0
  404. package/dist/ui/public/app.js +777 -0
  405. package/dist/ui/public/index.html +117 -0
  406. package/dist/ui/public/styles.css +413 -0
  407. package/dist/ui/server.d.ts +27 -0
  408. package/dist/ui/server.d.ts.map +1 -0
  409. package/dist/ui/server.js +373 -0
  410. package/dist/ui/server.js.map +1 -0
  411. package/package.json +63 -0
@@ -0,0 +1,808 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ import * as crypto from 'crypto';
4
+ import { Logger } from '../../common/logger.js';
5
+ export function calculateContentHash(content) {
6
+ return crypto.createHash('sha256').update(content, 'utf8').digest('hex');
7
+ }
8
+ export function isSecretFile(relativePath) {
9
+ const baseName = path.basename(relativePath).toLowerCase();
10
+ const ext = path.extname(relativePath).toLowerCase();
11
+ if (baseName.startsWith('.env')) {
12
+ return true;
13
+ }
14
+ if (baseName.startsWith('id_rsa') ||
15
+ baseName.startsWith('id_dsa') ||
16
+ baseName.startsWith('id_ed25519') ||
17
+ baseName.startsWith('id_ecdsa')) {
18
+ return true;
19
+ }
20
+ if (ext === '.pem' || ext === '.key') {
21
+ return true;
22
+ }
23
+ if (baseName === 'credentials.json' ||
24
+ baseName === 'service_account.json' ||
25
+ baseName === 'secrets.json') {
26
+ return true;
27
+ }
28
+ return false;
29
+ }
30
+ export function generateUnifiedDiff(relativePath, oldContent, newContent) {
31
+ const isCreate = oldContent === null;
32
+ const beforeHash = isCreate ? null : calculateContentHash(oldContent);
33
+ const afterHash = calculateContentHash(newContent);
34
+ const beforeSize = isCreate ? 0 : Buffer.byteLength(oldContent, 'utf8');
35
+ const afterSize = Buffer.byteLength(newContent, 'utf8');
36
+ const normalizedPath = relativePath.replace(/\\/g, '/');
37
+ if (!isCreate && oldContent === newContent) {
38
+ return {
39
+ path: normalizedPath,
40
+ operation: 'modify',
41
+ beforeHash,
42
+ afterHash,
43
+ beforeSize,
44
+ afterSize,
45
+ changed: false,
46
+ unifiedDiff: '',
47
+ };
48
+ }
49
+ const oldLines = isCreate ? [] : oldContent.split(/\r?\n/);
50
+ const newLines = newContent.split(/\r?\n/);
51
+ const diffHeader = [
52
+ `--- a/${normalizedPath}`,
53
+ `+++ b/${normalizedPath}`,
54
+ `@@ -${isCreate ? 0 : 1},${oldLines.length} +1,${newLines.length} @@`,
55
+ ];
56
+ const bodyLines = [];
57
+ const maxDiffLines = 500;
58
+ if (isCreate) {
59
+ for (let i = 0; i < newLines.length; i++) {
60
+ if (bodyLines.length >= maxDiffLines) {
61
+ bodyLines.push('... [diff truncated]');
62
+ break;
63
+ }
64
+ bodyLines.push(`+${newLines[i]}`);
65
+ }
66
+ }
67
+ else {
68
+ // Simple, clean unified diff generator
69
+ let i = 0;
70
+ let j = 0;
71
+ // Prefix common lines
72
+ while (i < oldLines.length && j < newLines.length && oldLines[i] === newLines[j]) {
73
+ if (bodyLines.length < maxDiffLines) {
74
+ bodyLines.push(` ${oldLines[i]}`);
75
+ }
76
+ i++;
77
+ j++;
78
+ }
79
+ // Suffix common lines
80
+ let oldEnd = oldLines.length - 1;
81
+ let newEnd = newLines.length - 1;
82
+ while (oldEnd >= i && newEnd >= j && oldLines[oldEnd] === newLines[newEnd]) {
83
+ oldEnd--;
84
+ newEnd--;
85
+ }
86
+ // Changed lines
87
+ for (let k = i; k <= oldEnd; k++) {
88
+ if (bodyLines.length < maxDiffLines) {
89
+ bodyLines.push(`-${oldLines[k]}`);
90
+ }
91
+ }
92
+ for (let k = j; k <= newEnd; k++) {
93
+ if (bodyLines.length < maxDiffLines) {
94
+ bodyLines.push(`+${newLines[k]}`);
95
+ }
96
+ }
97
+ // Suffix context
98
+ for (let k = oldEnd + 1; k < oldLines.length; k++) {
99
+ if (bodyLines.length < maxDiffLines) {
100
+ bodyLines.push(` ${oldLines[k]}`);
101
+ }
102
+ }
103
+ if (bodyLines.length >= maxDiffLines) {
104
+ bodyLines.push('... [diff truncated]');
105
+ }
106
+ }
107
+ return {
108
+ path: normalizedPath,
109
+ operation: isCreate ? 'create' : 'modify',
110
+ beforeHash,
111
+ afterHash,
112
+ beforeSize,
113
+ afterSize,
114
+ changed: true,
115
+ unifiedDiff: diffHeader.concat(bodyLines).join('\n'),
116
+ };
117
+ }
118
+ export class FilesystemAdapter {
119
+ canonicalWorkspaceRoot;
120
+ logger;
121
+ maxFileSize;
122
+ constructor(workspaceRoot, maxFileSizeBytes = 2 * 1024 * 1024, // Default 2MB limit
123
+ logLevel = 'info') {
124
+ this.logger = new Logger('FilesystemAdapter', logLevel);
125
+ this.maxFileSize = maxFileSizeBytes;
126
+ if (!workspaceRoot || typeof workspaceRoot !== 'string' || workspaceRoot.trim() === '') {
127
+ throw new Error('FilesystemAdapter initialization failed: workspaceRoot must be a non-empty string.');
128
+ }
129
+ const resolvedRoot = path.resolve(workspaceRoot);
130
+ if (!fs.existsSync(resolvedRoot)) {
131
+ try {
132
+ fs.mkdirSync(resolvedRoot, { recursive: true });
133
+ }
134
+ catch (err) {
135
+ throw new Error(`FilesystemAdapter initialization failed: workspace directory '${resolvedRoot}' could not be created (${String(err)}).`);
136
+ }
137
+ }
138
+ try {
139
+ this.canonicalWorkspaceRoot = fs.realpathSync(resolvedRoot);
140
+ }
141
+ catch {
142
+ this.canonicalWorkspaceRoot = resolvedRoot;
143
+ }
144
+ }
145
+ /**
146
+ * Get the canonical workspace root directory.
147
+ */
148
+ getWorkspaceRoot() {
149
+ return this.canonicalWorkspaceRoot;
150
+ }
151
+ /**
152
+ * Validate and resolve a workspace-relative path safely within the canonical workspace sandbox.
153
+ */
154
+ validatePath(relativePath) {
155
+ if (typeof relativePath !== 'string') {
156
+ return {
157
+ valid: false,
158
+ errorCategory: 'INVALID_INPUT',
159
+ errorMessage: 'Path must be a non-empty string.',
160
+ };
161
+ }
162
+ const trimmed = relativePath.trim();
163
+ const effectivePath = trimmed === '' ? '.' : trimmed;
164
+ // Reject null bytes
165
+ if (effectivePath.includes('\0')) {
166
+ return {
167
+ valid: false,
168
+ errorCategory: 'PATH_TRAVERSAL_DENIED',
169
+ errorMessage: 'Path contains invalid null byte characters.',
170
+ };
171
+ }
172
+ const normalizedRelative = path.normalize(effectivePath);
173
+ // Resolve full target path against workspace root
174
+ let resolvedTarget = path.resolve(this.canonicalWorkspaceRoot, normalizedRelative);
175
+ // Check if relativePath is an alias referring to the workspace root directory itself
176
+ const workspaceBaseName = path.basename(this.canonicalWorkspaceRoot);
177
+ if (!fs.existsSync(resolvedTarget)) {
178
+ const parentResolved = path.resolve(path.dirname(this.canonicalWorkspaceRoot), normalizedRelative);
179
+ const isWin = process.platform === 'win32';
180
+ const p1 = isWin ? parentResolved.toLowerCase() : parentResolved;
181
+ const p2 = isWin ? this.canonicalWorkspaceRoot.toLowerCase() : this.canonicalWorkspaceRoot;
182
+ if (p1 === p2 || normalizedRelative === workspaceBaseName || normalizedRelative === `./${workspaceBaseName}`) {
183
+ resolvedTarget = this.canonicalWorkspaceRoot;
184
+ }
185
+ }
186
+ // Verify canonical path escape check
187
+ let canonicalTarget;
188
+ try {
189
+ if (fs.existsSync(resolvedTarget)) {
190
+ canonicalTarget = fs.realpathSync(resolvedTarget);
191
+ }
192
+ else {
193
+ const parentDir = path.dirname(resolvedTarget);
194
+ if (fs.existsSync(parentDir)) {
195
+ const canonicalParent = fs.realpathSync(parentDir);
196
+ canonicalTarget = path.join(canonicalParent, path.basename(resolvedTarget));
197
+ }
198
+ else {
199
+ canonicalTarget = resolvedTarget;
200
+ }
201
+ }
202
+ }
203
+ catch {
204
+ canonicalTarget = resolvedTarget;
205
+ }
206
+ const isWindows = process.platform === 'win32';
207
+ const rootToCheck = isWindows ? this.canonicalWorkspaceRoot.toLowerCase() : this.canonicalWorkspaceRoot;
208
+ const targetToCheck = isWindows ? canonicalTarget.toLowerCase() : canonicalTarget;
209
+ const isInsideWorkspace = targetToCheck === rootToCheck ||
210
+ targetToCheck.startsWith(rootToCheck + (isWindows ? '\\' : '/')) ||
211
+ targetToCheck.startsWith(rootToCheck + path.sep);
212
+ if (!isInsideWorkspace) {
213
+ return {
214
+ valid: false,
215
+ errorCategory: 'PATH_TRAVERSAL_DENIED',
216
+ errorMessage: `Access denied: Requested path '${relativePath}' escapes the configured workspace sandbox.`,
217
+ };
218
+ }
219
+ return {
220
+ valid: true,
221
+ canonicalPath: canonicalTarget,
222
+ };
223
+ }
224
+ /**
225
+ * Safely read the content of a file within the workspace sandbox.
226
+ */
227
+ readFile(relativePath) {
228
+ const pathValidation = this.validatePath(relativePath);
229
+ if (!pathValidation.valid || !pathValidation.canonicalPath) {
230
+ this.logger.warn(`File read rejected: path validation failed`, {
231
+ errorCategory: pathValidation.errorCategory,
232
+ });
233
+ return {
234
+ success: false,
235
+ errorCategory: pathValidation.errorCategory || 'PATH_TRAVERSAL_DENIED',
236
+ errorMessage: pathValidation.errorMessage || 'Path validation failed.',
237
+ };
238
+ }
239
+ const targetPath = pathValidation.canonicalPath;
240
+ if (!fs.existsSync(targetPath)) {
241
+ return {
242
+ success: false,
243
+ errorCategory: 'FILE_NOT_FOUND',
244
+ errorMessage: `File not found: '${relativePath}' does not exist in workspace.`,
245
+ };
246
+ }
247
+ let stats;
248
+ try {
249
+ stats = fs.statSync(targetPath);
250
+ }
251
+ catch (err) {
252
+ return {
253
+ success: false,
254
+ errorCategory: 'FILESYSTEM_ERROR',
255
+ errorMessage: `Failed to inspect path '${relativePath}': ${String(err)}`,
256
+ };
257
+ }
258
+ if (stats.isDirectory()) {
259
+ return {
260
+ success: false,
261
+ errorCategory: 'INVALID_FILE_TYPE',
262
+ errorMessage: `Target path '${relativePath}' is a directory, not a file.`,
263
+ };
264
+ }
265
+ if (stats.size > this.maxFileSize) {
266
+ return {
267
+ success: false,
268
+ errorCategory: 'FILE_TOO_LARGE',
269
+ errorMessage: `File size (${stats.size} bytes) exceeds maximum allowable limit (${this.maxFileSize} bytes).`,
270
+ };
271
+ }
272
+ try {
273
+ const content = fs.readFileSync(targetPath, 'utf8');
274
+ this.logger.info(`Successfully read file`, { bytes: stats.size });
275
+ return {
276
+ success: true,
277
+ content,
278
+ bytes: stats.size,
279
+ relativePath,
280
+ };
281
+ }
282
+ catch (err) {
283
+ return {
284
+ success: false,
285
+ errorCategory: 'READ_FAILED',
286
+ errorMessage: `Failed to read file contents: ${String(err)}`,
287
+ };
288
+ }
289
+ }
290
+ /**
291
+ * Safely return a bounded metadata representation of the directory tree.
292
+ */
293
+ getWorkspaceTree(relativePath = '.', options = {}) {
294
+ const maxDepth = options.maxDepth !== undefined ? Math.max(1, Math.min(options.maxDepth, 10)) : 5;
295
+ const maxEntries = options.maxEntries !== undefined ? Math.max(1, Math.min(options.maxEntries, 2000)) : 500;
296
+ const pathValidation = this.validatePath(relativePath);
297
+ if (!pathValidation.valid || !pathValidation.canonicalPath) {
298
+ return {
299
+ success: false,
300
+ root: relativePath,
301
+ errorCategory: pathValidation.errorCategory || 'PATH_TRAVERSAL_DENIED',
302
+ errorMessage: pathValidation.errorMessage || 'Path validation failed.',
303
+ };
304
+ }
305
+ const targetPath = pathValidation.canonicalPath;
306
+ if (!fs.existsSync(targetPath)) {
307
+ // Graceful fallback: if the target path doesn't exist yet (e.g. the planner
308
+ // wants to inspect a directory it is about to CREATE), fall back to the workspace
309
+ // root instead of failing. The path has already been verified as inside the sandbox.
310
+ this.logger.info(`workspace_tree: path '${relativePath}' does not exist yet — falling back to workspace root`, {
311
+ requestedPath: relativePath,
312
+ targetPath,
313
+ fallback: this.canonicalWorkspaceRoot,
314
+ });
315
+ return this.getWorkspaceTree('.', options);
316
+ }
317
+ let targetStats;
318
+ try {
319
+ targetStats = fs.statSync(targetPath);
320
+ }
321
+ catch (err) {
322
+ return {
323
+ success: false,
324
+ root: relativePath,
325
+ errorCategory: 'FILESYSTEM_ERROR',
326
+ errorMessage: `Failed to inspect path '${relativePath}': ${String(err)}`,
327
+ };
328
+ }
329
+ const entries = [];
330
+ let truncated = false;
331
+ const defaultExcludedDirs = new Set(['node_modules', '.git', 'dist', 'build', '.next', 'coverage']);
332
+ if (!targetStats.isDirectory()) {
333
+ const relPath = path.relative(this.canonicalWorkspaceRoot, targetPath).replace(/\\/g, '/') || '.';
334
+ entries.push({
335
+ path: relPath,
336
+ type: 'file',
337
+ size: targetStats.size,
338
+ });
339
+ return {
340
+ success: true,
341
+ root: relativePath,
342
+ entries,
343
+ truncated: false,
344
+ totalEntries: 1,
345
+ };
346
+ }
347
+ const isWindows = process.platform === 'win32';
348
+ const canonicalRoot = this.canonicalWorkspaceRoot;
349
+ const traverse = (currentDir, currentDepth) => {
350
+ if (currentDepth > maxDepth || truncated) {
351
+ return;
352
+ }
353
+ let dirEntries;
354
+ try {
355
+ dirEntries = fs.readdirSync(currentDir, { withFileTypes: true });
356
+ }
357
+ catch {
358
+ return;
359
+ }
360
+ for (const entry of dirEntries) {
361
+ if (entries.length >= maxEntries) {
362
+ truncated = true;
363
+ break;
364
+ }
365
+ const fullPath = path.join(currentDir, entry.name);
366
+ let canonicalEntryPath;
367
+ try {
368
+ canonicalEntryPath = fs.realpathSync(fullPath);
369
+ }
370
+ catch {
371
+ canonicalEntryPath = fullPath;
372
+ }
373
+ const rootCheck = isWindows ? canonicalRoot.toLowerCase() : canonicalRoot;
374
+ const entryCheck = isWindows ? canonicalEntryPath.toLowerCase() : canonicalEntryPath;
375
+ const isInside = entryCheck === rootCheck ||
376
+ entryCheck.startsWith(rootCheck + (isWindows ? '\\' : '/')) ||
377
+ entryCheck.startsWith(rootCheck + path.sep);
378
+ if (!isInside) {
379
+ continue;
380
+ }
381
+ const relPath = path.relative(canonicalRoot, canonicalEntryPath).replace(/\\/g, '/') || entry.name;
382
+ if (entry.isDirectory()) {
383
+ entries.push({
384
+ path: relPath,
385
+ type: 'directory',
386
+ });
387
+ if (!defaultExcludedDirs.has(entry.name)) {
388
+ traverse(canonicalEntryPath, currentDepth + 1);
389
+ }
390
+ }
391
+ else if (entry.isFile()) {
392
+ let fileSize = 0;
393
+ try {
394
+ fileSize = fs.statSync(canonicalEntryPath).size;
395
+ }
396
+ catch {
397
+ // ignore
398
+ }
399
+ entries.push({
400
+ path: relPath,
401
+ type: 'file',
402
+ size: fileSize,
403
+ });
404
+ }
405
+ }
406
+ };
407
+ traverse(targetPath, 1);
408
+ return {
409
+ success: true,
410
+ root: relativePath,
411
+ entries,
412
+ truncated,
413
+ totalEntries: entries.length,
414
+ };
415
+ }
416
+ /**
417
+ * Safely search source files within the workspace using deterministic text matching.
418
+ */
419
+ searchCode(query, relativePath = '.', options = {}) {
420
+ if (!query || typeof query !== 'string' || query.trim() === '') {
421
+ return {
422
+ success: false,
423
+ query: query || '',
424
+ errorCategory: 'INVALID_INPUT',
425
+ errorMessage: 'Query parameter must be a non-empty string.',
426
+ };
427
+ }
428
+ const maxResults = options.maxResults !== undefined ? Math.max(1, Math.min(options.maxResults, 200)) : 50;
429
+ const pathValidation = this.validatePath(relativePath);
430
+ if (!pathValidation.valid || !pathValidation.canonicalPath) {
431
+ return {
432
+ success: false,
433
+ query,
434
+ errorCategory: pathValidation.errorCategory || 'PATH_TRAVERSAL_DENIED',
435
+ errorMessage: pathValidation.errorMessage || 'Path validation failed.',
436
+ };
437
+ }
438
+ const targetPath = pathValidation.canonicalPath;
439
+ if (!fs.existsSync(targetPath)) {
440
+ return {
441
+ success: false,
442
+ query,
443
+ errorCategory: 'FILE_NOT_FOUND',
444
+ errorMessage: `Path not found: '${relativePath}' does not exist in workspace.`,
445
+ };
446
+ }
447
+ const defaultAllowedExts = new Set(['.ts', '.tsx', '.js', '.jsx', '.json', '.md', '.py', '.css', '.html', '.sql', '.yaml', '.yml', '.sh', '.txt']);
448
+ const allowedExts = options.fileExtensions && options.fileExtensions.length > 0
449
+ ? new Set(options.fileExtensions.map((e) => (e.startsWith('.') ? e.toLowerCase() : `.${e.toLowerCase()}`)))
450
+ : defaultAllowedExts;
451
+ const secretFileNames = new Set(['.env', '.env.local', '.env.development', '.env.production', '.env.test', 'id_rsa', 'id_dsa', 'id_ed25519']);
452
+ const defaultExcludedDirs = new Set(['node_modules', '.git', 'dist', 'build', '.next', 'coverage']);
453
+ const isWindows = process.platform === 'win32';
454
+ const canonicalRoot = this.canonicalWorkspaceRoot;
455
+ const filesToSearch = [];
456
+ const collectFiles = (currentPath) => {
457
+ let stats;
458
+ try {
459
+ stats = fs.statSync(currentPath);
460
+ }
461
+ catch {
462
+ return;
463
+ }
464
+ if (stats.isFile()) {
465
+ const ext = path.extname(currentPath).toLowerCase();
466
+ const baseName = path.basename(currentPath).toLowerCase();
467
+ if (secretFileNames.has(baseName) || baseName.startsWith('.env')) {
468
+ return;
469
+ }
470
+ if (allowedExts.has(ext) && stats.size <= this.maxFileSize) {
471
+ filesToSearch.push(currentPath);
472
+ }
473
+ return;
474
+ }
475
+ if (stats.isDirectory()) {
476
+ const baseName = path.basename(currentPath);
477
+ if (defaultExcludedDirs.has(baseName)) {
478
+ return;
479
+ }
480
+ let entries;
481
+ try {
482
+ entries = fs.readdirSync(currentPath);
483
+ }
484
+ catch {
485
+ return;
486
+ }
487
+ for (const entryName of entries) {
488
+ const fullPath = path.join(currentPath, entryName);
489
+ let canonicalEntryPath;
490
+ try {
491
+ canonicalEntryPath = fs.realpathSync(fullPath);
492
+ }
493
+ catch {
494
+ canonicalEntryPath = fullPath;
495
+ }
496
+ const rootCheck = isWindows ? canonicalRoot.toLowerCase() : canonicalRoot;
497
+ const entryCheck = isWindows ? canonicalEntryPath.toLowerCase() : canonicalEntryPath;
498
+ const isInside = entryCheck === rootCheck ||
499
+ entryCheck.startsWith(rootCheck + (isWindows ? '\\' : '/')) ||
500
+ entryCheck.startsWith(rootCheck + path.sep);
501
+ if (isInside) {
502
+ collectFiles(canonicalEntryPath);
503
+ }
504
+ }
505
+ }
506
+ };
507
+ collectFiles(targetPath);
508
+ const results = [];
509
+ let truncated = false;
510
+ let filesSearched = 0;
511
+ const lowerQuery = query.toLowerCase();
512
+ for (const filePath of filesToSearch) {
513
+ if (results.length >= maxResults) {
514
+ truncated = true;
515
+ break;
516
+ }
517
+ filesSearched++;
518
+ let content;
519
+ try {
520
+ const buf = fs.readFileSync(filePath);
521
+ if (buf.subarray(0, 512).includes(0)) {
522
+ continue;
523
+ }
524
+ content = buf.toString('utf8');
525
+ }
526
+ catch {
527
+ continue;
528
+ }
529
+ const lines = content.split(/\r?\n/);
530
+ const relPath = path.relative(canonicalRoot, filePath).replace(/\\/g, '/');
531
+ for (let i = 0; i < lines.length; i++) {
532
+ const lineText = lines[i];
533
+ const lowerLine = lineText.toLowerCase();
534
+ let matchIdx = lowerLine.indexOf(lowerQuery);
535
+ while (matchIdx !== -1) {
536
+ const lineNum = i + 1;
537
+ const colNum = matchIdx + 1;
538
+ const matchedSub = lineText.substring(matchIdx, matchIdx + query.length);
539
+ const snippet = lineText.trim().slice(0, 200);
540
+ results.push({
541
+ path: relPath,
542
+ line: lineNum,
543
+ column: colNum,
544
+ match: matchedSub,
545
+ snippet,
546
+ });
547
+ if (results.length >= maxResults) {
548
+ truncated = true;
549
+ break;
550
+ }
551
+ matchIdx = lowerLine.indexOf(lowerQuery, matchIdx + 1);
552
+ }
553
+ if (truncated)
554
+ break;
555
+ }
556
+ }
557
+ return {
558
+ success: true,
559
+ query,
560
+ results,
561
+ totalMatches: results.length,
562
+ filesSearched,
563
+ truncated,
564
+ };
565
+ }
566
+ /**
567
+ * Safely create or replace a file strictly inside the workspace sandbox.
568
+ */
569
+ writeFile(relativePath, content) {
570
+ if (typeof content !== 'string') {
571
+ return {
572
+ success: false,
573
+ errorCategory: 'INVALID_INPUT',
574
+ errorMessage: 'Content must be a string.',
575
+ };
576
+ }
577
+ const pathValidation = this.validatePath(relativePath);
578
+ if (!pathValidation.valid || !pathValidation.canonicalPath) {
579
+ return {
580
+ success: false,
581
+ errorCategory: pathValidation.errorCategory || 'PATH_TRAVERSAL_DENIED',
582
+ errorMessage: pathValidation.errorMessage || 'Path validation failed.',
583
+ };
584
+ }
585
+ if (isSecretFile(relativePath)) {
586
+ return {
587
+ success: false,
588
+ errorCategory: 'SECRET_FILE_PROTECTED',
589
+ errorMessage: `Security violation: Modification of secret file '${relativePath}' is strictly prohibited.`,
590
+ };
591
+ }
592
+ const targetPath = pathValidation.canonicalPath;
593
+ // Check directory target rejection
594
+ if (fs.existsSync(targetPath)) {
595
+ try {
596
+ const stats = fs.statSync(targetPath);
597
+ if (stats.isDirectory()) {
598
+ return {
599
+ success: false,
600
+ errorCategory: 'INVALID_TARGET',
601
+ errorMessage: `Target path '${relativePath}' is a directory, not a file.`,
602
+ };
603
+ }
604
+ }
605
+ catch (err) {
606
+ return {
607
+ success: false,
608
+ errorCategory: 'FILESYSTEM_ERROR',
609
+ errorMessage: `Failed to inspect path '${relativePath}': ${String(err)}`,
610
+ };
611
+ }
612
+ }
613
+ const contentBytes = Buffer.byteLength(content, 'utf8');
614
+ if (contentBytes > this.maxFileSize) {
615
+ return {
616
+ success: false,
617
+ errorCategory: 'FILE_TOO_LARGE',
618
+ errorMessage: `File size (${contentBytes} bytes) exceeds maximum allowable limit (${this.maxFileSize} bytes).`,
619
+ };
620
+ }
621
+ let oldContent = null;
622
+ if (fs.existsSync(targetPath)) {
623
+ try {
624
+ oldContent = fs.readFileSync(targetPath, 'utf8');
625
+ }
626
+ catch {
627
+ oldContent = null;
628
+ }
629
+ }
630
+ const parentDir = path.dirname(targetPath);
631
+ try {
632
+ if (!fs.existsSync(parentDir)) {
633
+ fs.mkdirSync(parentDir, { recursive: true });
634
+ }
635
+ }
636
+ catch (err) {
637
+ return {
638
+ success: false,
639
+ errorCategory: 'FILESYSTEM_ERROR',
640
+ errorMessage: `Failed to create parent directory for '${relativePath}': ${String(err)}`,
641
+ };
642
+ }
643
+ const tempFile = path.join(parentDir, `.nexus_tmp_${Date.now()}_${Math.random().toString(36).substring(2, 8)}`);
644
+ try {
645
+ fs.writeFileSync(tempFile, content, 'utf8');
646
+ const writtenSize = fs.statSync(tempFile).size;
647
+ if (writtenSize !== contentBytes) {
648
+ throw new Error(`Write verification failed: expected ${contentBytes} bytes, wrote ${writtenSize} bytes.`);
649
+ }
650
+ try {
651
+ fs.renameSync(tempFile, targetPath);
652
+ }
653
+ catch {
654
+ fs.copyFileSync(tempFile, targetPath);
655
+ fs.unlinkSync(tempFile);
656
+ }
657
+ this.logger.info(`Successfully wrote file '${relativePath}' (${contentBytes} bytes)`);
658
+ const relPathPosix = path.relative(this.canonicalWorkspaceRoot, targetPath).replace(/\\/g, '/');
659
+ const diff = generateUnifiedDiff(relPathPosix, oldContent, content);
660
+ return {
661
+ success: true,
662
+ path: relPathPosix,
663
+ bytesWritten: contentBytes,
664
+ created: oldContent === null,
665
+ diff,
666
+ };
667
+ }
668
+ catch (err) {
669
+ if (fs.existsSync(tempFile)) {
670
+ try {
671
+ fs.unlinkSync(tempFile);
672
+ }
673
+ catch { /* ignore */ }
674
+ }
675
+ return {
676
+ success: false,
677
+ errorCategory: 'WRITE_FAILED',
678
+ errorMessage: `Failed to write file '${relativePath}': ${String(err)}`,
679
+ };
680
+ }
681
+ }
682
+ /**
683
+ * Safely apply a deterministic, hash-verified edit to an existing file in the workspace.
684
+ */
685
+ editFile(relativePath, expectedContentHash, oldText, newText, replaceMode = 'single') {
686
+ if (!relativePath || typeof relativePath !== 'string') {
687
+ return {
688
+ success: false,
689
+ errorCategory: 'INVALID_INPUT',
690
+ errorMessage: 'Path must be a non-empty string.',
691
+ };
692
+ }
693
+ if (!expectedContentHash || typeof expectedContentHash !== 'string') {
694
+ return {
695
+ success: false,
696
+ errorCategory: 'INVALID_INPUT',
697
+ errorMessage: 'expectedContentHash must be a non-empty string.',
698
+ };
699
+ }
700
+ if (typeof oldText !== 'string' || oldText === '') {
701
+ return {
702
+ success: false,
703
+ errorCategory: 'INVALID_INPUT',
704
+ errorMessage: 'oldText must be a non-empty string.',
705
+ };
706
+ }
707
+ if (typeof newText !== 'string') {
708
+ return {
709
+ success: false,
710
+ errorCategory: 'INVALID_INPUT',
711
+ errorMessage: 'newText must be a string.',
712
+ };
713
+ }
714
+ const pathValidation = this.validatePath(relativePath);
715
+ if (!pathValidation.valid || !pathValidation.canonicalPath) {
716
+ return {
717
+ success: false,
718
+ errorCategory: pathValidation.errorCategory || 'PATH_TRAVERSAL_DENIED',
719
+ errorMessage: pathValidation.errorMessage || 'Path validation failed.',
720
+ };
721
+ }
722
+ if (isSecretFile(relativePath)) {
723
+ return {
724
+ success: false,
725
+ errorCategory: 'SECRET_FILE_PROTECTED',
726
+ errorMessage: `Security violation: Editing secret file '${relativePath}' is strictly prohibited.`,
727
+ };
728
+ }
729
+ const targetPath = pathValidation.canonicalPath;
730
+ if (!fs.existsSync(targetPath)) {
731
+ return {
732
+ success: false,
733
+ errorCategory: 'FILE_NOT_FOUND',
734
+ errorMessage: `File not found: '${relativePath}' does not exist in workspace.`,
735
+ };
736
+ }
737
+ let stats;
738
+ try {
739
+ stats = fs.statSync(targetPath);
740
+ }
741
+ catch (err) {
742
+ return {
743
+ success: false,
744
+ errorCategory: 'FILESYSTEM_ERROR',
745
+ errorMessage: `Failed to inspect path '${relativePath}': ${String(err)}`,
746
+ };
747
+ }
748
+ if (stats.isDirectory()) {
749
+ return {
750
+ success: false,
751
+ errorCategory: 'INVALID_TARGET',
752
+ errorMessage: `Target path '${relativePath}' is a directory, not a file.`,
753
+ };
754
+ }
755
+ let currentContent;
756
+ try {
757
+ currentContent = fs.readFileSync(targetPath, 'utf8');
758
+ }
759
+ catch (err) {
760
+ return {
761
+ success: false,
762
+ errorCategory: 'READ_FAILED',
763
+ errorMessage: `Failed to read file '${relativePath}' for edit: ${String(err)}`,
764
+ };
765
+ }
766
+ const currentHash = calculateContentHash(currentContent);
767
+ if (currentHash.toLowerCase() !== expectedContentHash.toLowerCase()) {
768
+ return {
769
+ success: false,
770
+ errorCategory: 'HASH_MISMATCH_CONFLICT',
771
+ errorMessage: `Edit conflict: File content has changed since it was read. Expected hash '${expectedContentHash}', found '${currentHash}'.`,
772
+ };
773
+ }
774
+ const occurrences = currentContent.split(oldText).length - 1;
775
+ if (occurrences === 0) {
776
+ return {
777
+ success: false,
778
+ errorCategory: 'EDIT_TARGET_NOT_FOUND',
779
+ errorMessage: `Edit rejected: oldText not found in file '${relativePath}'.`,
780
+ };
781
+ }
782
+ if (replaceMode === 'single' && occurrences > 1) {
783
+ return {
784
+ success: false,
785
+ errorCategory: 'AMBIGUOUS_EDIT_MATCH',
786
+ errorMessage: `Edit rejected: oldText matched ${occurrences} times in file '${relativePath}'. Disambiguate oldText to match a single instance.`,
787
+ };
788
+ }
789
+ const updatedContent = currentContent.replace(oldText, newText);
790
+ const writeResult = this.writeFile(relativePath, updatedContent);
791
+ if (!writeResult.success) {
792
+ return {
793
+ success: false,
794
+ errorCategory: writeResult.errorCategory,
795
+ errorMessage: writeResult.errorMessage,
796
+ };
797
+ }
798
+ return {
799
+ success: true,
800
+ path: writeResult.path,
801
+ bytesWritten: writeResult.bytesWritten,
802
+ diff: writeResult.diff,
803
+ };
804
+ }
805
+ }
806
+ export class ReadonlyFilesystemAdapter extends FilesystemAdapter {
807
+ }
808
+ //# sourceMappingURL=filesystemAdapter.js.map