imcp 0.1.7 → 0.1.8-dev

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 (314) hide show
  1. package/dist/cli/commands/install.js +1 -106
  2. package/dist/cli/commands/install.js.map +1 -0
  3. package/dist/cli/commands/list.js +1 -90
  4. package/dist/cli/commands/list.js.map +1 -0
  5. package/dist/cli/commands/pull.js +1 -16
  6. package/dist/cli/commands/pull.js.map +1 -0
  7. package/dist/cli/commands/serve.js +1 -33
  8. package/dist/cli/commands/serve.js.map +1 -0
  9. package/dist/cli/commands/uninstall.js +1 -46
  10. package/dist/cli/commands/uninstall.js.map +1 -0
  11. package/dist/cli/index.js +1 -65
  12. package/dist/cli/index.js.map +1 -0
  13. package/dist/core/installers/clients/BaseClientInstaller.js +1 -282
  14. package/dist/core/installers/clients/BaseClientInstaller.js.map +1 -0
  15. package/dist/core/installers/clients/ClientInstaller.js +1 -163
  16. package/dist/core/installers/clients/ClientInstaller.js.map +1 -0
  17. package/dist/core/installers/clients/ClientInstallerFactory.js +1 -36
  18. package/dist/core/installers/clients/ClientInstallerFactory.js.map +1 -0
  19. package/dist/core/installers/clients/ClineInstaller.js +1 -30
  20. package/dist/core/installers/clients/ClineInstaller.js.map +1 -0
  21. package/dist/core/installers/clients/ExtensionInstaller.js +1 -151
  22. package/dist/core/installers/clients/ExtensionInstaller.js.map +1 -0
  23. package/dist/core/installers/clients/GithubCopilotInstaller.js +1 -68
  24. package/dist/core/installers/clients/GithubCopilotInstaller.js.map +1 -0
  25. package/dist/core/installers/clients/MSRooCodeInstaller.js +1 -28
  26. package/dist/core/installers/clients/MSRooCodeInstaller.js.map +1 -0
  27. package/dist/core/installers/index.js +1 -8
  28. package/dist/core/installers/index.js.map +1 -0
  29. package/dist/core/installers/requirements/BaseInstaller.js +1 -56
  30. package/dist/core/installers/requirements/BaseInstaller.js.map +1 -0
  31. package/dist/core/installers/requirements/CommandInstaller.js +1 -213
  32. package/dist/core/installers/requirements/CommandInstaller.js.map +1 -0
  33. package/dist/core/installers/requirements/GeneralInstaller.js +1 -126
  34. package/dist/core/installers/requirements/GeneralInstaller.js.map +1 -0
  35. package/dist/core/installers/requirements/InstallerFactory.js +1 -99
  36. package/dist/core/installers/requirements/InstallerFactory.js.map +1 -0
  37. package/dist/core/installers/requirements/NpmInstaller.js +1 -235
  38. package/dist/core/installers/requirements/NpmInstaller.js.map +1 -0
  39. package/dist/core/installers/requirements/NugetInstaller.js +1 -188
  40. package/dist/core/installers/requirements/NugetInstaller.js.map +1 -0
  41. package/dist/core/installers/requirements/PipInstaller.js +1 -192
  42. package/dist/core/installers/requirements/PipInstaller.js.map +1 -0
  43. package/dist/core/installers/requirements/RequirementInstaller.js +1 -2
  44. package/dist/core/installers/requirements/RequirementInstaller.js.map +1 -0
  45. package/dist/core/loaders/ConfigurationLoader.js +1 -256
  46. package/dist/core/loaders/ConfigurationLoader.js.map +1 -0
  47. package/dist/core/loaders/ConfigurationProvider.js +1 -383
  48. package/dist/core/loaders/ConfigurationProvider.js.map +1 -0
  49. package/dist/core/loaders/InstallOperationManager.js +1 -310
  50. package/dist/core/loaders/InstallOperationManager.js.map +1 -0
  51. package/dist/core/loaders/ServerSchemaLoader.js +1 -108
  52. package/dist/core/loaders/ServerSchemaLoader.js.map +1 -0
  53. package/dist/core/loaders/ServerSchemaProvider.js +1 -89
  54. package/dist/core/loaders/ServerSchemaProvider.js.map +1 -0
  55. package/dist/core/loaders/SystemSettingsManager.js +1 -256
  56. package/dist/core/loaders/SystemSettingsManager.js.map +1 -0
  57. package/dist/core/metadatas/constants.js +1 -100
  58. package/dist/core/metadatas/constants.js.map +1 -0
  59. package/dist/core/metadatas/recordingConstants.js +1 -46
  60. package/dist/core/metadatas/recordingConstants.js.map +1 -0
  61. package/dist/core/metadatas/types.js +1 -15
  62. package/dist/core/metadatas/types.js.map +1 -0
  63. package/dist/core/onboard/FeedOnboardService.js +1 -422
  64. package/dist/core/onboard/FeedOnboardService.js.map +1 -0
  65. package/dist/core/onboard/OnboardProcessor.js +1 -333
  66. package/dist/core/onboard/OnboardProcessor.js.map +1 -0
  67. package/dist/core/onboard/OnboardStatus.js +1 -9
  68. package/dist/core/onboard/OnboardStatus.js.map +1 -0
  69. package/dist/core/onboard/OnboardStatusManager.js +1 -360
  70. package/dist/core/onboard/OnboardStatusManager.js.map +1 -0
  71. package/dist/core/validators/FeedValidator.js +1 -133
  72. package/dist/core/validators/FeedValidator.js.map +1 -0
  73. package/dist/core/validators/IServerValidator.js +1 -1
  74. package/dist/core/validators/IServerValidator.js.map +1 -0
  75. package/dist/core/validators/SSEServerValidator.js +1 -38
  76. package/dist/core/validators/SSEServerValidator.js.map +1 -0
  77. package/dist/core/validators/ServerValidatorFactory.js +1 -44
  78. package/dist/core/validators/ServerValidatorFactory.js.map +1 -0
  79. package/dist/core/validators/StdioServerValidator.js +1 -281
  80. package/dist/core/validators/StdioServerValidator.js.map +1 -0
  81. package/dist/index.js +1 -18
  82. package/dist/index.js.map +1 -0
  83. package/dist/services/InstallationService.js +1 -81
  84. package/dist/services/InstallationService.js.map +1 -0
  85. package/dist/services/MCPManager.js +1 -197
  86. package/dist/services/MCPManager.js.map +1 -0
  87. package/dist/services/RequirementService.js +1 -548
  88. package/dist/services/RequirementService.js.map +1 -0
  89. package/dist/services/ServerService.js +1 -127
  90. package/dist/services/ServerService.js.map +1 -0
  91. package/dist/services/TelemetryService.js +1 -53
  92. package/dist/services/TelemetryService.js.map +1 -0
  93. package/dist/utils/UpdateCheckTracker.js +1 -79
  94. package/dist/utils/UpdateCheckTracker.js.map +1 -0
  95. package/dist/utils/adoUtils.js +1 -254
  96. package/dist/utils/adoUtils.js.map +1 -0
  97. package/dist/utils/clientUtils.js +1 -65
  98. package/dist/utils/clientUtils.js.map +1 -0
  99. package/dist/utils/feedUtils.js +1 -28
  100. package/dist/utils/feedUtils.js.map +1 -0
  101. package/dist/utils/githubAuth.js +1 -177
  102. package/dist/utils/githubAuth.js.map +1 -0
  103. package/dist/utils/githubUtils.js +1 -125
  104. package/dist/utils/githubUtils.js.map +1 -0
  105. package/dist/utils/logger.js +1 -176
  106. package/dist/utils/logger.js.map +1 -0
  107. package/dist/utils/macroExpressionUtils.js +1 -93
  108. package/dist/utils/macroExpressionUtils.js.map +1 -0
  109. package/dist/utils/osUtils.js +1 -664
  110. package/dist/utils/osUtils.js.map +1 -0
  111. package/dist/utils/versionUtils.js +1 -101
  112. package/dist/utils/versionUtils.js.map +1 -0
  113. package/dist/web/contract/serverContract.js +1 -1
  114. package/dist/web/contract/serverContract.js.map +1 -0
  115. package/dist/web/public/js/api.js +2 -132
  116. package/dist/web/public/js/api.js.map +1 -0
  117. package/dist/web/public/js/detailsWidget.js +2 -264
  118. package/dist/web/public/js/detailsWidget.js.map +1 -0
  119. package/dist/web/public/js/flights/flights.js +2 -127
  120. package/dist/web/public/js/flights/flights.js.map +1 -0
  121. package/dist/web/public/js/modal/index.js +2 -52
  122. package/dist/web/public/js/modal/index.js.map +1 -0
  123. package/dist/web/public/js/modal/installModal.js +2 -162
  124. package/dist/web/public/js/modal/installModal.js.map +1 -0
  125. package/dist/web/public/js/modal/installation.js +2 -266
  126. package/dist/web/public/js/modal/installation.js.map +1 -0
  127. package/dist/web/public/js/modal/loadingModal.js +2 -182
  128. package/dist/web/public/js/modal/loadingModal.js.map +1 -0
  129. package/dist/web/public/js/modal/modalSetup.js +2 -595
  130. package/dist/web/public/js/modal/modalSetup.js.map +1 -0
  131. package/dist/web/public/js/modal/modalUtils.js +2 -37
  132. package/dist/web/public/js/modal/modalUtils.js.map +1 -0
  133. package/dist/web/public/js/modal/versionUtils.js +2 -20
  134. package/dist/web/public/js/modal/versionUtils.js.map +1 -0
  135. package/dist/web/public/js/modal.js +2 -42
  136. package/dist/web/public/js/modal.js.map +1 -0
  137. package/dist/web/public/js/notifications.js +2 -137
  138. package/dist/web/public/js/notifications.js.map +1 -0
  139. package/dist/web/public/js/onboard/formProcessor.js +2 -1037
  140. package/dist/web/public/js/onboard/formProcessor.js.map +1 -0
  141. package/dist/web/public/js/onboard/index.js +2 -374
  142. package/dist/web/public/js/onboard/index.js.map +1 -0
  143. package/dist/web/public/js/onboard/publishHandler.js +2 -172
  144. package/dist/web/public/js/onboard/publishHandler.js.map +1 -0
  145. package/dist/web/public/js/onboard/state.js +2 -76
  146. package/dist/web/public/js/onboard/state.js.map +1 -0
  147. package/dist/web/public/js/onboard/templates.js +2 -342
  148. package/dist/web/public/js/onboard/templates.js.map +1 -0
  149. package/dist/web/public/js/onboard/uiHandlers.js +2 -1076
  150. package/dist/web/public/js/onboard/uiHandlers.js.map +1 -0
  151. package/dist/web/public/js/onboard/validationHandlers.js +2 -493
  152. package/dist/web/public/js/onboard/validationHandlers.js.map +1 -0
  153. package/dist/web/public/js/serverCategoryDetails.js +2 -364
  154. package/dist/web/public/js/serverCategoryDetails.js.map +1 -0
  155. package/dist/web/public/js/serverCategoryList.js +2 -241
  156. package/dist/web/public/js/serverCategoryList.js.map +1 -0
  157. package/dist/web/public/js/settings.js +2 -314
  158. package/dist/web/public/js/settings.js.map +1 -0
  159. package/dist/web/server.js +1 -404
  160. package/dist/web/server.js.map +1 -0
  161. package/package.json +8 -2
  162. package/.github/ISSUE_TEMPLATE/JitAccess.yml +0 -28
  163. package/.github/acl/access.yml +0 -20
  164. package/.github/compliance/inventory.yml +0 -5
  165. package/.github/policies/jit.yml +0 -19
  166. package/.github/workflows/build.yml +0 -28
  167. package/.roo/rules-code/rules.md +0 -88
  168. package/dist/cli/commands/start.d.ts +0 -2
  169. package/dist/cli/commands/start.js +0 -32
  170. package/dist/cli/commands/sync.d.ts +0 -2
  171. package/dist/cli/commands/sync.js +0 -17
  172. package/dist/core/ConfigurationLoader.d.ts +0 -32
  173. package/dist/core/ConfigurationLoader.js +0 -236
  174. package/dist/core/ConfigurationProvider.d.ts +0 -35
  175. package/dist/core/ConfigurationProvider.js +0 -375
  176. package/dist/core/InstallationService.d.ts +0 -50
  177. package/dist/core/InstallationService.js +0 -350
  178. package/dist/core/MCPManager.d.ts +0 -28
  179. package/dist/core/MCPManager.js +0 -188
  180. package/dist/core/RequirementService.d.ts +0 -40
  181. package/dist/core/RequirementService.js +0 -110
  182. package/dist/core/ServerSchemaLoader.d.ts +0 -11
  183. package/dist/core/ServerSchemaLoader.js +0 -43
  184. package/dist/core/ServerSchemaProvider.d.ts +0 -17
  185. package/dist/core/ServerSchemaProvider.js +0 -120
  186. package/dist/core/constants.d.ts +0 -47
  187. package/dist/core/constants.js +0 -94
  188. package/dist/core/installers/BaseInstaller.d.ts +0 -74
  189. package/dist/core/installers/BaseInstaller.js +0 -253
  190. package/dist/core/installers/ClientInstaller.d.ts +0 -23
  191. package/dist/core/installers/ClientInstaller.js +0 -564
  192. package/dist/core/installers/CommandInstaller.d.ts +0 -37
  193. package/dist/core/installers/CommandInstaller.js +0 -173
  194. package/dist/core/installers/GeneralInstaller.d.ts +0 -33
  195. package/dist/core/installers/GeneralInstaller.js +0 -85
  196. package/dist/core/installers/InstallerFactory.d.ts +0 -54
  197. package/dist/core/installers/InstallerFactory.js +0 -97
  198. package/dist/core/installers/NpmInstaller.d.ts +0 -26
  199. package/dist/core/installers/NpmInstaller.js +0 -127
  200. package/dist/core/installers/PipInstaller.d.ts +0 -28
  201. package/dist/core/installers/PipInstaller.js +0 -127
  202. package/dist/core/installers/RequirementInstaller.d.ts +0 -33
  203. package/dist/core/installers/RequirementInstaller.js +0 -3
  204. package/dist/core/types.d.ts +0 -166
  205. package/dist/core/types.js +0 -16
  206. package/dist/services/InstallRequestValidator.d.ts +0 -21
  207. package/dist/services/InstallRequestValidator.js +0 -99
  208. package/dist/web/public/js/modal/installHandler.js +0 -227
  209. package/dist/web/public/js/modal/loadingUI.js +0 -74
  210. package/dist/web/public/js/modal/messageQueue.js +0 -112
  211. package/dist/web/public/js/modal/modalUI.js +0 -214
  212. package/dist/web/public/js/modal/version.js +0 -20
  213. package/dist/web/public/js/onboard/ONBOARDING_PAGE_DESIGN.md +0 -370
  214. package/docs/ONBOARDING_PAGE_DESIGN.md +0 -260
  215. package/docs/Telemetry.md +0 -136
  216. package/memory-bank/activeContext.md +0 -26
  217. package/memory-bank/decisionLog.md +0 -91
  218. package/memory-bank/productContext.md +0 -41
  219. package/memory-bank/progress.md +0 -35
  220. package/memory-bank/systemPatterns.md +0 -10
  221. package/src/cli/commands/install.ts +0 -139
  222. package/src/cli/commands/list.ts +0 -113
  223. package/src/cli/commands/pull.ts +0 -16
  224. package/src/cli/commands/serve.ts +0 -39
  225. package/src/cli/commands/uninstall.ts +0 -64
  226. package/src/cli/index.ts +0 -82
  227. package/src/core/installers/clients/BaseClientInstaller.ts +0 -341
  228. package/src/core/installers/clients/ClientInstaller.ts +0 -222
  229. package/src/core/installers/clients/ClientInstallerFactory.ts +0 -43
  230. package/src/core/installers/clients/ClineInstaller.ts +0 -35
  231. package/src/core/installers/clients/ExtensionInstaller.ts +0 -165
  232. package/src/core/installers/clients/GithubCopilotInstaller.ts +0 -79
  233. package/src/core/installers/clients/MSRooCodeInstaller.ts +0 -32
  234. package/src/core/installers/index.ts +0 -11
  235. package/src/core/installers/requirements/BaseInstaller.ts +0 -85
  236. package/src/core/installers/requirements/CommandInstaller.ts +0 -231
  237. package/src/core/installers/requirements/GeneralInstaller.ts +0 -133
  238. package/src/core/installers/requirements/InstallerFactory.ts +0 -114
  239. package/src/core/installers/requirements/NpmInstaller.ts +0 -271
  240. package/src/core/installers/requirements/NugetInstaller.ts +0 -203
  241. package/src/core/installers/requirements/PipInstaller.ts +0 -207
  242. package/src/core/installers/requirements/RequirementInstaller.ts +0 -42
  243. package/src/core/loaders/ConfigurationLoader.ts +0 -298
  244. package/src/core/loaders/ConfigurationProvider.ts +0 -462
  245. package/src/core/loaders/InstallOperationManager.ts +0 -367
  246. package/src/core/loaders/ServerSchemaLoader.ts +0 -117
  247. package/src/core/loaders/ServerSchemaProvider.ts +0 -99
  248. package/src/core/loaders/SystemSettingsManager.ts +0 -278
  249. package/src/core/metadatas/constants.ts +0 -122
  250. package/src/core/metadatas/recordingConstants.ts +0 -65
  251. package/src/core/metadatas/types.ts +0 -202
  252. package/src/core/onboard/FeedOnboardService.ts +0 -501
  253. package/src/core/onboard/OnboardProcessor.ts +0 -356
  254. package/src/core/onboard/OnboardStatus.ts +0 -60
  255. package/src/core/onboard/OnboardStatusManager.ts +0 -416
  256. package/src/core/validators/FeedValidator.ts +0 -135
  257. package/src/core/validators/IServerValidator.ts +0 -21
  258. package/src/core/validators/SSEServerValidator.ts +0 -43
  259. package/src/core/validators/ServerValidatorFactory.ts +0 -51
  260. package/src/core/validators/StdioServerValidator.ts +0 -313
  261. package/src/index.ts +0 -44
  262. package/src/services/InstallationService.ts +0 -102
  263. package/src/services/MCPManager.ts +0 -249
  264. package/src/services/RequirementService.ts +0 -627
  265. package/src/services/ServerService.ts +0 -161
  266. package/src/services/TelemetryService.ts +0 -59
  267. package/src/utils/UpdateCheckTracker.ts +0 -86
  268. package/src/utils/adoUtils.ts +0 -293
  269. package/src/utils/clientUtils.ts +0 -72
  270. package/src/utils/feedUtils.ts +0 -31
  271. package/src/utils/githubAuth.ts +0 -212
  272. package/src/utils/githubUtils.ts +0 -164
  273. package/src/utils/logger.ts +0 -195
  274. package/src/utils/macroExpressionUtils.ts +0 -104
  275. package/src/utils/osUtils.ts +0 -700
  276. package/src/utils/versionUtils.ts +0 -114
  277. package/src/web/contract/serverContract.ts +0 -74
  278. package/src/web/public/css/detailsWidget.css +0 -235
  279. package/src/web/public/css/modal.css +0 -757
  280. package/src/web/public/css/notifications.css +0 -101
  281. package/src/web/public/css/onboard.css +0 -107
  282. package/src/web/public/css/serverCategoryList.css +0 -120
  283. package/src/web/public/css/serverDetails.css +0 -139
  284. package/src/web/public/index.html +0 -359
  285. package/src/web/public/js/api.js +0 -132
  286. package/src/web/public/js/detailsWidget.js +0 -264
  287. package/src/web/public/js/flights/flights.js +0 -127
  288. package/src/web/public/js/modal/index.js +0 -52
  289. package/src/web/public/js/modal/installModal.js +0 -162
  290. package/src/web/public/js/modal/installation.js +0 -266
  291. package/src/web/public/js/modal/loadingModal.js +0 -182
  292. package/src/web/public/js/modal/modalSetup.js +0 -595
  293. package/src/web/public/js/modal/modalUtils.js +0 -37
  294. package/src/web/public/js/modal/versionUtils.js +0 -20
  295. package/src/web/public/js/modal.js +0 -42
  296. package/src/web/public/js/notifications.js +0 -137
  297. package/src/web/public/js/onboard/formProcessor.js +0 -1037
  298. package/src/web/public/js/onboard/index.js +0 -374
  299. package/src/web/public/js/onboard/publishHandler.js +0 -172
  300. package/src/web/public/js/onboard/state.js +0 -76
  301. package/src/web/public/js/onboard/templates.js +0 -342
  302. package/src/web/public/js/onboard/uiHandlers.js +0 -1076
  303. package/src/web/public/js/onboard/validationHandlers.js +0 -493
  304. package/src/web/public/js/serverCategoryDetails.js +0 -364
  305. package/src/web/public/js/serverCategoryList.js +0 -241
  306. package/src/web/public/js/settings.js +0 -314
  307. package/src/web/public/modal.html +0 -84
  308. package/src/web/public/onboard.html +0 -296
  309. package/src/web/public/settings.html +0 -135
  310. package/src/web/public/styles.css +0 -277
  311. package/src/web/server.ts +0 -478
  312. package/tsconfig.json +0 -18
  313. package/wiki/Installation.md +0 -3
  314. package/wiki/Publish.md +0 -3
@@ -1,665 +1,2 @@
1
- import { OSType } from '../core/metadatas/types.js';
2
- import os from 'os';
3
- import { exec } from 'child_process';
4
- import util from 'util';
5
- import { Logger } from './logger.js';
6
- import fs from 'fs';
7
- import path from 'path';
8
- import { execSync } from 'child_process';
9
- import * as fsSync from 'fs';
10
- const execAsync = util.promisify(exec);
11
- export function getOSType() {
12
- const platform = os.platform();
13
- Logger.debug({
14
- action: 'get_os_type',
15
- platform
16
- });
17
- switch (platform) {
18
- case 'win32':
19
- return OSType.Windows;
20
- case 'darwin':
21
- return OSType.MacOS;
22
- case 'linux':
23
- return OSType.Linux;
24
- default:
25
- const error = `Unsupported operating system: ${platform}`;
26
- Logger.error(error);
27
- throw new Error(error);
28
- }
29
- }
30
- export async function installCLI(tool) {
31
- const osType = getOSType();
32
- Logger.debug({
33
- action: 'install_cli',
34
- tool,
35
- osType
36
- });
37
- try {
38
- switch (osType) {
39
- case OSType.Windows:
40
- if (tool === 'git') {
41
- await execAsync('winget install --id Git.Git -e --source winget --silent');
42
- }
43
- else {
44
- await execAsync('winget install --id GitHub.cli --silent');
45
- }
46
- // Refresh PATH environment variable after installation
47
- await refreshPathEnv();
48
- break;
49
- case OSType.MacOS:
50
- if (tool === 'git') {
51
- await execAsync('brew install git');
52
- }
53
- else {
54
- await execAsync('brew install gh');
55
- }
56
- // On macOS, we may need to source profile files
57
- if (tool === 'git') {
58
- await execAsync('source ~/.zshrc || source ~/.bash_profile || source ~/.bashrc || true');
59
- }
60
- break;
61
- case OSType.Linux:
62
- if (tool === 'git') {
63
- await execAsync('sudo apt-get update && sudo apt-get install -y git');
64
- }
65
- else {
66
- await execAsync('curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg && sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null && sudo apt update && sudo apt install -y gh');
67
- }
68
- // Source bash profile to refresh PATH
69
- await execAsync('source ~/.bashrc || source ~/.profile || true');
70
- break;
71
- default:
72
- throw new Error(`Unsupported operating system for installing ${tool}`);
73
- }
74
- // Wait a moment for system to register the new binaries
75
- await new Promise(resolve => setTimeout(resolve, 1000));
76
- Logger.debug({
77
- action: 'install_cli_success',
78
- tool,
79
- osType
80
- });
81
- }
82
- catch (error) {
83
- Logger.error('Failed to install CLI tool', {
84
- tool,
85
- osType,
86
- error
87
- });
88
- throw error;
89
- }
90
- }
91
- /**
92
- * Refreshes the PATH environment variable for the current Node.js process
93
- */
94
- export async function refreshPathEnv() {
95
- const osType = getOSType();
96
- Logger.debug({
97
- action: 'refresh_path_env',
98
- osType
99
- });
100
- try {
101
- switch (osType) {
102
- case OSType.Windows:
103
- // On Windows, get the PATH from registry
104
- const { stdout: winPath } = await execAsync('powershell -command "[Environment]::GetEnvironmentVariable(\'Path\', \'Machine\') + \';\' + [Environment]::GetEnvironmentVariable(\'Path\', \'User\')"');
105
- if (winPath) {
106
- process.env.PATH = winPath.trim();
107
- Logger.debug('Refreshed PATH from Windows registry');
108
- }
109
- break;
110
- case OSType.MacOS:
111
- case OSType.Linux:
112
- // On Unix systems, typical installation locations if PATH isn't updated
113
- const commonPaths = [
114
- '/usr/local/bin',
115
- '/usr/bin',
116
- '/bin',
117
- '/usr/sbin',
118
- '/sbin',
119
- '/usr/local/git/bin',
120
- '/opt/homebrew/bin', // For M1 Macs
121
- `${os.homedir()}/.local/bin`
122
- ];
123
- // Ensure these paths are in process.env.PATH
124
- if (process.env.PATH) {
125
- const currentPaths = process.env.PATH.split(':');
126
- const newPaths = [...new Set([...currentPaths, ...commonPaths])];
127
- process.env.PATH = newPaths.join(':');
128
- Logger.debug('Expanded PATH with common Unix binary locations');
129
- }
130
- break;
131
- }
132
- Logger.debug({
133
- action: 'refresh_path_env_success',
134
- path: process.env.PATH
135
- });
136
- }
137
- catch (error) {
138
- Logger.error('Failed to refresh PATH environment variable', error);
139
- // Continue execution even if PATH refresh fails
140
- }
141
- }
142
- /**
143
- * Check if a command is available on the system
144
- * Handles special cases for VS Code on different platforms
145
- */
146
- export async function isCommandAvailable(command) {
147
- try {
148
- // For VS Code on macOS, check both command-line tool and app bundle
149
- if (process.platform === 'darwin' && (command === 'code' || command === 'code-insiders')) {
150
- try {
151
- // Try which command first
152
- await execAsync(`which ${command}`);
153
- return true;
154
- }
155
- catch (error) {
156
- // If which fails, check application bundles
157
- const systemVSCodePath = command === 'code' ?
158
- '/Applications/Visual Studio Code.app' :
159
- '/Applications/Visual Studio Code - Insiders.app';
160
- try {
161
- // Check system Applications first
162
- await execAsync(`test -d "${systemVSCodePath}"`);
163
- return true;
164
- }
165
- catch (error) {
166
- // If system Applications check fails, try user Applications
167
- const homedir = process.env.HOME;
168
- if (homedir) {
169
- const userVSCodePath = command === 'code' ?
170
- `${homedir}/Applications/Visual Studio Code.app` :
171
- `${homedir}/Applications/Visual Studio Code - Insiders.app`;
172
- try {
173
- await execAsync(`test -d "${userVSCodePath}"`);
174
- return true;
175
- }
176
- catch (error) {
177
- return false;
178
- }
179
- }
180
- return false;
181
- }
182
- }
183
- }
184
- // For Windows, use where command
185
- if (process.platform === 'win32') {
186
- await execAsync(`where ${command}`);
187
- return true;
188
- }
189
- // For all other cases (Unix-like systems), use which command
190
- await execAsync(`which ${command}`);
191
- return true;
192
- }
193
- catch (error) {
194
- return false;
195
- }
196
- }
197
- export async function isToolInstalled(tool, retries = 3) {
198
- try {
199
- Logger.debug({
200
- action: 'check_tool_installed',
201
- tool,
202
- retries
203
- });
204
- // Try to execute tool command
205
- try {
206
- await execAsync(`${tool} --version`);
207
- Logger.debug({
208
- action: 'check_tool_installed_success',
209
- tool,
210
- installed: true
211
- });
212
- return true;
213
- }
214
- catch (error) {
215
- // If we have retries left, refresh PATH and try again
216
- if (retries > 0) {
217
- Logger.debug(`${tool} not found, refreshing PATH and retrying...`);
218
- // Refresh environment PATH variable
219
- await refreshPathEnv();
220
- // Wait a moment before retrying
221
- await new Promise(resolve => setTimeout(resolve, 500));
222
- // Recursive retry with decremented counter
223
- return isToolInstalled(tool, retries - 1);
224
- }
225
- // No retries left, tool is not installed
226
- Logger.debug({
227
- action: 'check_tool_installed_success',
228
- tool,
229
- installed: false
230
- });
231
- return false;
232
- }
233
- }
234
- catch (error) {
235
- Logger.error(`Error checking if ${tool} is installed`, error);
236
- return false;
237
- }
238
- }
239
- export async function openBrowser(url) {
240
- const osType = getOSType();
241
- Logger.debug({
242
- action: 'open_browser',
243
- url,
244
- osType
245
- });
246
- try {
247
- switch (osType) {
248
- case OSType.Windows:
249
- await execAsync(`start ${url}`);
250
- break;
251
- case OSType.MacOS:
252
- await execAsync(`open ${url}`);
253
- break;
254
- case OSType.Linux:
255
- // Try different commands that might be available
256
- try {
257
- await execAsync(`xdg-open ${url}`);
258
- }
259
- catch (error) {
260
- // Try alternative commands
261
- try {
262
- await execAsync(`sensible-browser ${url}`);
263
- }
264
- catch (error) {
265
- await execAsync(`gnome-open ${url}`);
266
- }
267
- }
268
- break;
269
- default:
270
- throw new Error(`Unsupported operating system for opening browser`);
271
- }
272
- Logger.debug({
273
- action: 'open_browser_success',
274
- url,
275
- osType
276
- });
277
- }
278
- catch (error) {
279
- Logger.error('Failed to open browser', {
280
- url,
281
- osType,
282
- error
283
- });
284
- // Don't throw the error - just log it and continue
285
- }
286
- }
287
- export function getPythonPackagePath(pythonExecutablePath) {
288
- Logger.debug({
289
- action: 'get_python_package_path',
290
- pythonExecutablePath
291
- });
292
- try {
293
- const dir = path.dirname(pythonExecutablePath);
294
- const isWindows = process.platform === 'win32';
295
- // Handle common Python installation patterns
296
- if (isWindows) {
297
- // Windows: Handle different Python installations
298
- if (dir.endsWith('WindowsApps')) {
299
- // For Windows Store Python, find the actual Python installation directory
300
- const entries = fs.readdirSync(dir);
301
- const pythonDir = entries.find(e => e.startsWith('PythonSoftwareFoundation.Python'));
302
- if (pythonDir && pythonDir.includes('.')) {
303
- // Extract version from format like "PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0"
304
- const parts = pythonDir.split('.');
305
- const majorVer = parts[2];
306
- const minorVer = parts[3].split('_')[0];
307
- const version = majorVer + minorVer; // Combines "3" and "13" to "313"
308
- const localAppData = process.env.LOCALAPPDATA;
309
- if (localAppData) {
310
- const sitePkgsPath = path.join(localAppData, 'Packages', pythonDir, 'LocalCache', 'local-packages', 'Python' + version, 'site-packages');
311
- Logger.debug(`Resolved Windows Store Python site-packages path: ${sitePkgsPath}`);
312
- return sitePkgsPath;
313
- }
314
- }
315
- Logger.debug('Could not resolve Windows Store Python site-packages path');
316
- // Fallback to user's site-packages
317
- return path.join(process.env.APPDATA || '', 'Python', 'Python3', 'site-packages');
318
- }
319
- else if (dir.endsWith('Scripts')) {
320
- // Virtual environment structure on Windows: <venv>/Scripts/python.exe
321
- const venvRoot = path.dirname(dir);
322
- return path.join(venvRoot, 'Lib', 'site-packages');
323
- }
324
- else {
325
- // System Python or Conda on Windows
326
- return path.join(dir, 'Lib', 'site-packages');
327
- }
328
- }
329
- else {
330
- // Unix systems (MacOS/Linux)
331
- if (dir.endsWith('bin')) {
332
- // Virtual environment structure on Unix: <venv>/bin/python
333
- const venvRoot = path.dirname(dir);
334
- // Try to find python version-specific site-packages
335
- const libDir = path.join(venvRoot, 'lib');
336
- if (fs.existsSync(libDir)) {
337
- const pythonDirs = fs.readdirSync(libDir).filter(d => d.startsWith('python'));
338
- if (pythonDirs.length > 0) {
339
- // Use the first python directory found
340
- return path.join(libDir, pythonDirs[0], 'site-packages');
341
- }
342
- }
343
- // Fallback to a generic lib/python3/site-packages if version-specific not found
344
- return path.join(venvRoot, 'lib', 'python3', 'site-packages');
345
- }
346
- else if (dir.toLowerCase().includes('python')) {
347
- // System Python or Conda on Unix
348
- const libDir = path.join(dir, 'lib');
349
- if (fs.existsSync(libDir)) {
350
- const pythonDirs = fs.readdirSync(libDir).filter(d => d.startsWith('python'));
351
- if (pythonDirs.length > 0) {
352
- // Use the first python directory found
353
- return path.join(libDir, pythonDirs[0], 'site-packages');
354
- }
355
- }
356
- // Fallback to a generic lib/python3/site-packages
357
- return path.join(dir, 'lib', 'python3', 'site-packages');
358
- }
359
- }
360
- // Default fallback: return the original directory
361
- Logger.debug('No standard Python directory structure found, using original directory');
362
- return dir;
363
- }
364
- catch (error) {
365
- Logger.error('Error getting Python package path', {
366
- pythonExecutablePath,
367
- error
368
- });
369
- return path.dirname(pythonExecutablePath);
370
- }
371
- }
372
- export async function getSystemPythonPackageDirectory() {
373
- const command = process.platform === 'win32' ? 'where python' : 'which python';
374
- Logger.debug({
375
- action: 'get_system_python_package_directory',
376
- command
377
- });
378
- try {
379
- const { stdout } = await execAsync(command);
380
- // Use the first path found, trim whitespace
381
- const pythonPath = stdout.split('\n')[0].trim();
382
- if (pythonPath) {
383
- const packagePath = getPythonPackagePath(pythonPath);
384
- Logger.debug({
385
- action: 'get_system_python_package_directory_success',
386
- pythonPath,
387
- packagePath
388
- });
389
- return packagePath;
390
- }
391
- Logger.debug('No Python executable found');
392
- return null;
393
- }
394
- catch (error) {
395
- Logger.debug(`Could not find system python using "${command}": ${error}`);
396
- return null;
397
- }
398
- }
399
- /**
400
- * Get the system Python executable path.
401
- * This function returns the absolute path to the system Python executable (e.g., /Users/penwa/miniconda3/envs/browser-use-temp/bin/python).
402
- * It uses 'which python' (Unix) or 'where python' (Windows) to locate the executable.
403
- * @returns {Promise<string | null>} The path to the Python executable, or null if not found.
404
- */
405
- export async function getSystemPythonExecutablePath() {
406
- const command = process.platform === 'win32' ? 'where python' : 'which python';
407
- Logger.debug({
408
- action: 'get_system_python_executable_path',
409
- command
410
- });
411
- try {
412
- const { stdout } = await execAsync(command);
413
- // Use the first path found, trim whitespace
414
- const pythonPath = stdout.split('\n')[0].trim();
415
- if (pythonPath) {
416
- Logger.debug({
417
- action: 'get_system_python_executable_path_success',
418
- pythonPath
419
- });
420
- return pythonPath;
421
- }
422
- Logger.debug('No Python executable found');
423
- return null;
424
- }
425
- catch (error) {
426
- Logger.debug(`Could not find system python using "${command}": ${error}`);
427
- return null;
428
- }
429
- }
430
- export async function getBrowserPath() {
431
- const osType = getOSType();
432
- Logger.debug({
433
- action: 'get_system_browser_path',
434
- osType
435
- });
436
- try {
437
- switch (osType) {
438
- case OSType.Windows: {
439
- // Check for Edge first
440
- const edgePaths = [
441
- `${process.env['PROGRAMFILES(X86)']}\\Microsoft\\Edge\\Application\\msedge.exe`,
442
- `${process.env['PROGRAMFILES']}\\Microsoft\\Edge\\Application\\msedge.exe`
443
- ];
444
- for (const path of edgePaths) {
445
- if (fs.existsSync(path)) {
446
- return path;
447
- }
448
- }
449
- // Then check for Chrome
450
- const chromePaths = [
451
- `${process.env['PROGRAMFILES(X86)']}\\Google\\Chrome\\Application\\chrome.exe`,
452
- `${process.env['PROGRAMFILES']}\\Google\\Chrome\\Application\\chrome.exe`
453
- ];
454
- for (const path of chromePaths) {
455
- if (fs.existsSync(path)) {
456
- return path;
457
- }
458
- }
459
- break;
460
- }
461
- case OSType.MacOS: {
462
- // Check for Edge first
463
- const edgePath = '/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge';
464
- if (fs.existsSync(edgePath)) {
465
- return edgePath;
466
- }
467
- // Then check for Chrome
468
- const chromePath = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome';
469
- if (fs.existsSync(chromePath)) {
470
- return chromePath;
471
- }
472
- // Finally check for Safari
473
- const safariPath = '/Applications/Safari.app/Contents/MacOS/Safari';
474
- if (fs.existsSync(safariPath)) {
475
- return safariPath;
476
- }
477
- break;
478
- }
479
- case OSType.Linux: {
480
- // Try Edge first
481
- try {
482
- const { stdout: edgePath } = await execAsync('which microsoft-edge');
483
- if (edgePath.trim()) {
484
- return edgePath.trim();
485
- }
486
- }
487
- catch { }
488
- // Then try Chrome or Chromium
489
- try {
490
- const { stdout: chromePath } = await execAsync('which google-chrome chromium');
491
- if (chromePath.trim()) {
492
- return chromePath.trim();
493
- }
494
- }
495
- catch { }
496
- break;
497
- }
498
- }
499
- // If no browser found, throw error
500
- throw new Error('No supported browser found on the system');
501
- }
502
- catch (error) {
503
- Logger.error('Failed to get browser path', error);
504
- throw error;
505
- }
506
- }
507
- /**
508
- * Get the global NPM path
509
- * This function checks if NVM is installed and retrieves the global NPM path accordingly.
510
- * If NVM is not installed, it falls back to the global NPM path.
511
- * @returns The global NPM path as a string.
512
- * @throws Error if the NPM path cannot be determined.
513
- * */
514
- export function getGlobalNPMPackagePath() {
515
- const nvmHome = process.env.NVM_HOME;
516
- if (nvmHome) {
517
- try {
518
- const nodeVersion = execSync('node -v').toString().trim();
519
- const nvmNodePath = path.join(nvmHome, nodeVersion);
520
- // Check if this path exists
521
- try {
522
- fsSync.accessSync(nvmNodePath);
523
- return nvmNodePath;
524
- }
525
- catch (error) {
526
- Logger.debug(`NVM controlled path doesn't exist: ${nvmNodePath}, will try global npm`);
527
- }
528
- }
529
- catch (error) {
530
- Logger.debug(`Error determining Node version for NVM: ${error}, will use global npm`);
531
- }
532
- }
533
- const globalNpmPath = execSync('npm root -g').toString().trim();
534
- return globalNpmPath;
535
- }
536
- /**
537
- * Get the NPM executable path on the current platform (Windows, macOS, Linux).
538
- * On Windows, uses PowerShell to locate npm. On macOS/Linux, uses 'which' to locate npm.
539
- * Returns the directory containing the npm executable, or a platform-appropriate default if not found.
540
- */
541
- export async function getNpmExecutablePath() {
542
- try {
543
- if (process.platform === 'win32') {
544
- const { stdout } = await execAsync('powershell -Command "get-command npm | Select-Object -ExpandProperty Source"');
545
- return stdout.trim().replace(/\\npm\.cmd$/, '');
546
- }
547
- else {
548
- // macOS or Linux
549
- const { stdout } = await execAsync('which npm');
550
- // Remove the trailing '/npm' to get the directory
551
- return stdout.trim().replace(/\/npm$/, '');
552
- }
553
- }
554
- catch (error) {
555
- Logger.error('Error getting npm path:', error);
556
- if (process.platform === 'win32') {
557
- return 'C:\\Program Files\\nodejs';
558
- }
559
- else {
560
- // Common default for Unix systems
561
- return '/usr/local/bin';
562
- }
563
- }
564
- }
565
- /**
566
- * Ensures the .NET global tools path is added to the system PATH for the current user
567
- * on macOS and Linux by modifying shell configuration files.
568
- * This function is idempotent and will not add the path if it already exists.
569
- */
570
- export async function ensureDotnetToolsInPath() {
571
- const osType = getOSType();
572
- Logger.debug({
573
- action: 'ensure_dotnet_tools_in_path',
574
- osType
575
- });
576
- if (osType === OSType.Windows) {
577
- Logger.debug('.NET tools PATH is usually handled by the installer on Windows. Skipping explicit PATH modification.');
578
- return;
579
- }
580
- if (osType === OSType.MacOS || osType === OSType.Linux) {
581
- const dotnetToolsPath = getDotnetGlobalToolsPath(); // This is typically ~/.dotnet/tools
582
- const exportLine = `export PATH="${dotnetToolsPath}:$PATH"`;
583
- // Determine shell configuration files to check/update
584
- const shellConfigFiles = [];
585
- const shell = process.env.SHELL;
586
- if (shell && shell.includes('zsh')) {
587
- shellConfigFiles.push(path.join(os.homedir(), '.zshrc'));
588
- }
589
- else if (shell && shell.includes('bash')) {
590
- shellConfigFiles.push(path.join(os.homedir(), '.bashrc'));
591
- // .bash_profile is often sourced by .bashrc or used for login shells
592
- shellConfigFiles.push(path.join(os.homedir(), '.bash_profile'));
593
- }
594
- else {
595
- // Fallback for other shells or if SHELL is not set
596
- shellConfigFiles.push(path.join(os.homedir(), '.profile'));
597
- shellConfigFiles.push(path.join(os.homedir(), '.bashrc'));
598
- shellConfigFiles.push(path.join(os.homedir(), '.zshrc'));
599
- }
600
- let updatedAnyFile = false;
601
- for (const configFile of shellConfigFiles) {
602
- try {
603
- if (fs.existsSync(configFile)) {
604
- const content = await fs.promises.readFile(configFile, 'utf-8');
605
- // Check if the exact line or a line setting dotnetToolsPath in PATH exists
606
- // A more robust check might involve parsing, but this covers common cases.
607
- // Regex to check if dotnetToolsPath is part of an PATH export, avoiding duplicates.
608
- // It looks for `export PATH=...$dotnetToolsPath...` or `export PATH=...${HOME}/.dotnet/tools...`
609
- const pathRegex = new RegExp(`export\\s+PATH=.*${dotnetToolsPath.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}.*`);
610
- const homePathRegex = new RegExp(`export\\s+PATH=.*\\$HOME\\/\\.dotnet\\/tools.*`);
611
- if (!pathRegex.test(content) && !homePathRegex.test(content)) {
612
- Logger.debug(`Adding .NET tools path to ${configFile}`);
613
- await fs.promises.appendFile(configFile, `\n# Add .NET Core SDK tools to PATH\n${exportLine}\n`);
614
- Logger.log(`Appended '${exportLine}' to ${configFile}. You may need to source this file or restart your terminal.`);
615
- updatedAnyFile = true;
616
- }
617
- else {
618
- Logger.debug(`.NET tools path already configured in ${configFile}`);
619
- }
620
- }
621
- else if (shellConfigFiles.length === 1 || configFile === path.join(os.homedir(), '.profile')) {
622
- // If it's the only config file determined or it's .profile, and it doesn't exist, create it.
623
- Logger.debug(`${configFile} does not exist. Creating and adding .NET tools path.`);
624
- await fs.promises.writeFile(configFile, `# Add .NET Core SDK tools to PATH\n${exportLine}\n`);
625
- Logger.log(`Created ${configFile} and added '${exportLine}'. You may need to source this file or restart your terminal.`);
626
- updatedAnyFile = true;
627
- }
628
- }
629
- catch (error) {
630
- Logger.error(`Failed to update ${configFile} for .NET tools PATH: ${error instanceof Error ? error.message : String(error)}`);
631
- }
632
- }
633
- if (updatedAnyFile) {
634
- Logger.log(`Dotnet tools path has been added to shell configuration. Please source the relevant file (e.g., 'source ~/.zshrc') or restart your terminal session for changes to take effect.`);
635
- }
636
- // Also update the current process's PATH environment variable
637
- if (process.env.PATH && !process.env.PATH.includes(dotnetToolsPath)) {
638
- process.env.PATH = `${dotnetToolsPath}:${process.env.PATH}`;
639
- Logger.debug(`Updated current process.env.PATH to include: ${dotnetToolsPath}`);
640
- }
641
- else if (!process.env.PATH) {
642
- process.env.PATH = dotnetToolsPath;
643
- Logger.debug(`Set current process.env.PATH to: ${dotnetToolsPath}`);
644
- }
645
- }
646
- }
647
- /**
648
- *
649
- * @returns The path to the .dotnet global tools directory.
650
- */
651
- export function getDotnetGlobalToolsPath() {
652
- const homeDir = os.homedir();
653
- if (process.platform === 'win32') {
654
- // Example: C:\Users\YourName\.dotnet\tools
655
- return path.join(homeDir, '.dotnet', 'tools');
656
- }
657
- else if (process.platform === 'darwin' || process.platform === 'linux') {
658
- // macOS or Linux: ~/.dotnet/tools
659
- return path.join(homeDir, '.dotnet', 'tools');
660
- }
661
- else {
662
- throw new Error(`Unsupported platform: ${process.platform}`);
663
- }
664
- }
1
+ import{OSType}from"../core/metadatas/types.js";import os from"os";import{exec}from"child_process";import util from"util";import{Logger}from"./logger.js";import fs from"fs";import path from"path";import{execSync}from"child_process";import*as fsSync from"fs";const execAsync=util.promisify(exec);export function getOSType(){const e=os.platform();switch(Logger.debug({action:"get_os_type",platform:e}),e){case"win32":return OSType.Windows;case"darwin":return OSType.MacOS;case"linux":return OSType.Linux;default:const t=`Unsupported operating system: ${e}`;throw Logger.error(t),new Error(t)}}export async function installCLI(e){const t=getOSType();Logger.debug({action:"install_cli",tool:e,osType:t});try{switch(t){case OSType.Windows:"git"===e?await execAsync("winget install --id Git.Git -e --source winget --silent"):await execAsync("winget install --id GitHub.cli --silent"),await refreshPathEnv();break;case OSType.MacOS:"git"===e?await execAsync("brew install git"):await execAsync("brew install gh"),"git"===e&&await execAsync("source ~/.zshrc || source ~/.bash_profile || source ~/.bashrc || true");break;case OSType.Linux:"git"===e?await execAsync("sudo apt-get update && sudo apt-get install -y git"):await execAsync('curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg && sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null && sudo apt update && sudo apt install -y gh'),await execAsync("source ~/.bashrc || source ~/.profile || true");break;default:throw new Error(`Unsupported operating system for installing ${e}`)}await new Promise((e=>setTimeout(e,1e3))),Logger.debug({action:"install_cli_success",tool:e,osType:t})}catch(o){throw Logger.error("Failed to install CLI tool",{tool:e,osType:t,error:o}),o}}export async function refreshPathEnv(){const e=getOSType();Logger.debug({action:"refresh_path_env",osType:e});try{switch(e){case OSType.Windows:const{stdout:e}=await execAsync("powershell -command \"[Environment]::GetEnvironmentVariable('Path', 'Machine') + ';' + [Environment]::GetEnvironmentVariable('Path', 'User')\"");e&&(process.env.PATH=e.trim(),Logger.debug("Refreshed PATH from Windows registry"));break;case OSType.MacOS:case OSType.Linux:const t=["/usr/local/bin","/usr/bin","/bin","/usr/sbin","/sbin","/usr/local/git/bin","/opt/homebrew/bin",`${os.homedir()}/.local/bin`];if(process.env.PATH){const e=process.env.PATH.split(":"),o=[...new Set([...e,...t])];process.env.PATH=o.join(":"),Logger.debug("Expanded PATH with common Unix binary locations")}}Logger.debug({action:"refresh_path_env_success",path:process.env.PATH})}catch(e){Logger.error("Failed to refresh PATH environment variable",e)}}export async function isCommandAvailable(e){try{if("darwin"===process.platform&&("code"===e||"code-insiders"===e))try{return await execAsync(`which ${e}`),!0}catch(t){const o="code"===e?"/Applications/Visual Studio Code.app":"/Applications/Visual Studio Code - Insiders.app";try{return await execAsync(`test -d "${o}"`),!0}catch(t){const o=process.env.HOME;if(o){const t="code"===e?`${o}/Applications/Visual Studio Code.app`:`${o}/Applications/Visual Studio Code - Insiders.app`;try{return await execAsync(`test -d "${t}"`),!0}catch(e){return!1}}return!1}}return"win32"===process.platform?(await execAsync(`where ${e}`),!0):(await execAsync(`which ${e}`),!0)}catch(e){return!1}}export async function isToolInstalled(e,t=3){try{Logger.debug({action:"check_tool_installed",tool:e,retries:t});try{return await execAsync(`${e} --version`),Logger.debug({action:"check_tool_installed_success",tool:e,installed:!0}),!0}catch(o){return t>0?(Logger.debug(`${e} not found, refreshing PATH and retrying...`),await refreshPathEnv(),await new Promise((e=>setTimeout(e,500))),isToolInstalled(e,t-1)):(Logger.debug({action:"check_tool_installed_success",tool:e,installed:!1}),!1)}}catch(t){return Logger.error(`Error checking if ${e} is installed`,t),!1}}export async function openBrowser(e){const t=getOSType();Logger.debug({action:"open_browser",url:e,osType:t});try{switch(t){case OSType.Windows:await execAsync(`start ${e}`);break;case OSType.MacOS:await execAsync(`open ${e}`);break;case OSType.Linux:try{await execAsync(`xdg-open ${e}`)}catch(t){try{await execAsync(`sensible-browser ${e}`)}catch(t){await execAsync(`gnome-open ${e}`)}}break;default:throw new Error("Unsupported operating system for opening browser")}Logger.debug({action:"open_browser_success",url:e,osType:t})}catch(o){Logger.error("Failed to open browser",{url:e,osType:t,error:o})}}export function getPythonPackagePath(e){Logger.debug({action:"get_python_package_path",pythonExecutablePath:e});try{const t=path.dirname(e);if("win32"===process.platform){if(t.endsWith("WindowsApps")){const e=fs.readdirSync(t).find((e=>e.startsWith("PythonSoftwareFoundation.Python")));if(e&&e.includes(".")){const t=e.split("."),o=t[2]+t[3].split("_")[0],r=process.env.LOCALAPPDATA;if(r){const t=path.join(r,"Packages",e,"LocalCache","local-packages","Python"+o,"site-packages");return Logger.debug(`Resolved Windows Store Python site-packages path: ${t}`),t}}return Logger.debug("Could not resolve Windows Store Python site-packages path"),path.join(process.env.APPDATA||"","Python","Python3","site-packages")}if(t.endsWith("Scripts")){const e=path.dirname(t);return path.join(e,"Lib","site-packages")}return path.join(t,"Lib","site-packages")}if(t.endsWith("bin")){const e=path.dirname(t),o=path.join(e,"lib");if(fs.existsSync(o)){const e=fs.readdirSync(o).filter((e=>e.startsWith("python")));if(e.length>0)return path.join(o,e[0],"site-packages")}return path.join(e,"lib","python3","site-packages")}if(t.toLowerCase().includes("python")){const e=path.join(t,"lib");if(fs.existsSync(e)){const t=fs.readdirSync(e).filter((e=>e.startsWith("python")));if(t.length>0)return path.join(e,t[0],"site-packages")}return path.join(t,"lib","python3","site-packages")}return Logger.debug("No standard Python directory structure found, using original directory"),t}catch(t){return Logger.error("Error getting Python package path",{pythonExecutablePath:e,error:t}),path.dirname(e)}}export async function getSystemPythonPackageDirectory(){const e="win32"===process.platform?"where python":"which python";Logger.debug({action:"get_system_python_package_directory",command:e});try{const{stdout:t}=await execAsync(e),o=t.split("\n")[0].trim();if(o){const e=getPythonPackagePath(o);return Logger.debug({action:"get_system_python_package_directory_success",pythonPath:o,packagePath:e}),e}return Logger.debug("No Python executable found"),null}catch(t){return Logger.debug(`Could not find system python using "${e}": ${t}`),null}}export async function getSystemPythonExecutablePath(){const e="win32"===process.platform?"where python":"which python";Logger.debug({action:"get_system_python_executable_path",command:e});try{const{stdout:t}=await execAsync(e),o=t.split("\n")[0].trim();return o?(Logger.debug({action:"get_system_python_executable_path_success",pythonPath:o}),o):(Logger.debug("No Python executable found"),null)}catch(t){return Logger.debug(`Could not find system python using "${e}": ${t}`),null}}export async function getBrowserPath(){const e=getOSType();Logger.debug({action:"get_system_browser_path",osType:e});try{switch(e){case OSType.Windows:{const e=[`${process.env["PROGRAMFILES(X86)"]}\\Microsoft\\Edge\\Application\\msedge.exe`,`${process.env.PROGRAMFILES}\\Microsoft\\Edge\\Application\\msedge.exe`];for(const t of e)if(fs.existsSync(t))return t;const t=[`${process.env["PROGRAMFILES(X86)"]}\\Google\\Chrome\\Application\\chrome.exe`,`${process.env.PROGRAMFILES}\\Google\\Chrome\\Application\\chrome.exe`];for(const e of t)if(fs.existsSync(e))return e;break}case OSType.MacOS:{const e="/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge";if(fs.existsSync(e))return e;const t="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome";if(fs.existsSync(t))return t;const o="/Applications/Safari.app/Contents/MacOS/Safari";if(fs.existsSync(o))return o;break}case OSType.Linux:try{const{stdout:e}=await execAsync("which microsoft-edge");if(e.trim())return e.trim()}catch{}try{const{stdout:e}=await execAsync("which google-chrome chromium");if(e.trim())return e.trim()}catch{}}throw new Error("No supported browser found on the system")}catch(e){throw Logger.error("Failed to get browser path",e),e}}export function getGlobalNPMPackagePath(){const e=process.env.NVM_HOME;if(e)try{const t=execSync("node -v").toString().trim(),o=path.join(e,t);try{return fsSync.accessSync(o),o}catch(e){Logger.debug(`NVM controlled path doesn't exist: ${o}, will try global npm`)}}catch(e){Logger.debug(`Error determining Node version for NVM: ${e}, will use global npm`)}return execSync("npm root -g").toString().trim()}export async function getNpmExecutablePath(){try{if("win32"===process.platform){const{stdout:e}=await execAsync('powershell -Command "get-command npm | Select-Object -ExpandProperty Source"');return e.trim().replace(/\\npm\.cmd$/,"")}{const{stdout:e}=await execAsync("which npm");return e.trim().replace(/\/npm$/,"")}}catch(e){return Logger.error("Error getting npm path:",e),"win32"===process.platform?"C:\\Program Files\\nodejs":"/usr/local/bin"}}export async function ensureDotnetToolsInPath(){const e=getOSType();if(Logger.debug({action:"ensure_dotnet_tools_in_path",osType:e}),e!==OSType.Windows){if(e===OSType.MacOS||e===OSType.Linux){const e=getDotnetGlobalToolsPath(),t=`export PATH="${e}:$PATH"`,o=[],r=process.env.SHELL;r&&r.includes("zsh")?o.push(path.join(os.homedir(),".zshrc")):r&&r.includes("bash")?(o.push(path.join(os.homedir(),".bashrc")),o.push(path.join(os.homedir(),".bash_profile"))):(o.push(path.join(os.homedir(),".profile")),o.push(path.join(os.homedir(),".bashrc")),o.push(path.join(os.homedir(),".zshrc")));let s=!1;for(const r of o)try{if(fs.existsSync(r)){const o=await fs.promises.readFile(r,"utf-8"),n=new RegExp(`export\\s+PATH=.*${e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}.*`),i=new RegExp("export\\s+PATH=.*\\$HOME\\/\\.dotnet\\/tools.*");n.test(o)||i.test(o)?Logger.debug(`.NET tools path already configured in ${r}`):(Logger.debug(`Adding .NET tools path to ${r}`),await fs.promises.appendFile(r,`\n# Add .NET Core SDK tools to PATH\n${t}\n`),Logger.log(`Appended '${t}' to ${r}. You may need to source this file or restart your terminal.`),s=!0)}else 1!==o.length&&r!==path.join(os.homedir(),".profile")||(Logger.debug(`${r} does not exist. Creating and adding .NET tools path.`),await fs.promises.writeFile(r,`# Add .NET Core SDK tools to PATH\n${t}\n`),Logger.log(`Created ${r} and added '${t}'. You may need to source this file or restart your terminal.`),s=!0)}catch(e){Logger.error(`Failed to update ${r} for .NET tools PATH: ${e instanceof Error?e.message:String(e)}`)}s&&Logger.log("Dotnet tools path has been added to shell configuration. Please source the relevant file (e.g., 'source ~/.zshrc') or restart your terminal session for changes to take effect."),process.env.PATH&&!process.env.PATH.includes(e)?(process.env.PATH=`${e}:${process.env.PATH}`,Logger.debug(`Updated current process.env.PATH to include: ${e}`)):process.env.PATH||(process.env.PATH=e,Logger.debug(`Set current process.env.PATH to: ${e}`))}}else Logger.debug(".NET tools PATH is usually handled by the installer on Windows. Skipping explicit PATH modification.")}export function getDotnetGlobalToolsPath(){const e=os.homedir();if("win32"===process.platform)return path.join(e,".dotnet","tools");if("darwin"===process.platform||"linux"===process.platform)return path.join(e,".dotnet","tools");throw new Error(`Unsupported platform: ${process.platform}`)}
665
2
  //# sourceMappingURL=osUtils.js.map