@belboy47/brc-agent 0.0.0-stage → 2.0.18

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 (416) hide show
  1. package/LICENSE +30 -0
  2. package/LICENSE-desktop-commander +21 -0
  3. package/NOTICE +13 -0
  4. package/README.md +64 -2
  5. package/dist/cli.d.ts +2 -0
  6. package/dist/cli.js +487 -0
  7. package/dist/cli.js.map +1 -0
  8. package/dist/context.d.ts +31 -0
  9. package/dist/context.js +11 -0
  10. package/dist/context.js.map +1 -0
  11. package/dist/core/command-manager.d.ts +8 -0
  12. package/dist/core/command-manager.js +242 -0
  13. package/dist/core/command-manager.js.map +1 -0
  14. package/dist/core/config-field-definitions.d.ts +41 -0
  15. package/dist/core/config-field-definitions.js +38 -0
  16. package/dist/core/config-field-definitions.js.map +1 -0
  17. package/dist/core/config-manager.d.ts +102 -0
  18. package/dist/core/config-manager.js +451 -0
  19. package/dist/core/config-manager.js.map +1 -0
  20. package/dist/core/config.d.ts +6 -0
  21. package/dist/core/config.js +20 -0
  22. package/dist/core/config.js.map +1 -0
  23. package/dist/core/custom-stdio.d.ts +9 -0
  24. package/dist/core/custom-stdio.js +2 -0
  25. package/dist/core/custom-stdio.js.map +1 -0
  26. package/dist/core/error-handlers.d.ts +7 -0
  27. package/dist/core/error-handlers.js +16 -0
  28. package/dist/core/error-handlers.js.map +1 -0
  29. package/dist/core/file-transfer.d.ts +16 -0
  30. package/dist/core/file-transfer.js +316 -0
  31. package/dist/core/file-transfer.js.map +1 -0
  32. package/dist/core/handlers/edit-search-handlers.d.ts +6 -0
  33. package/dist/core/handlers/edit-search-handlers.js +7 -0
  34. package/dist/core/handlers/edit-search-handlers.js.map +1 -0
  35. package/dist/core/handlers/filesystem-handlers.d.ts +38 -0
  36. package/dist/core/handlers/filesystem-handlers.js +535 -0
  37. package/dist/core/handlers/filesystem-handlers.js.map +1 -0
  38. package/dist/core/handlers/history-handlers.d.ts +12 -0
  39. package/dist/core/handlers/history-handlers.js +68 -0
  40. package/dist/core/handlers/history-handlers.js.map +1 -0
  41. package/dist/core/handlers/index.d.ts +7 -0
  42. package/dist/core/handlers/index.js +9 -0
  43. package/dist/core/handlers/index.js.map +1 -0
  44. package/dist/core/handlers/process-handlers.d.ts +9 -0
  45. package/dist/core/handlers/process-handlers.js +16 -0
  46. package/dist/core/handlers/process-handlers.js.map +1 -0
  47. package/dist/core/handlers/search-handlers.d.ts +17 -0
  48. package/dist/core/handlers/search-handlers.js +336 -0
  49. package/dist/core/handlers/search-handlers.js.map +1 -0
  50. package/dist/core/handlers/terminal-handlers.d.ts +21 -0
  51. package/dist/core/handlers/terminal-handlers.js +36 -0
  52. package/dist/core/handlers/terminal-handlers.js.map +1 -0
  53. package/dist/core/handlers/transfer-handlers.d.ts +4 -0
  54. package/dist/core/handlers/transfer-handlers.js +76 -0
  55. package/dist/core/handlers/transfer-handlers.js.map +1 -0
  56. package/dist/core/search-manager.d.ts +162 -0
  57. package/dist/core/search-manager.js +929 -0
  58. package/dist/core/search-manager.js.map +1 -0
  59. package/dist/core/terminal-manager.d.ts +126 -0
  60. package/dist/core/terminal-manager.js +671 -0
  61. package/dist/core/terminal-manager.js.map +1 -0
  62. package/dist/core/tool-definitions.d.ts +9 -0
  63. package/dist/core/tool-definitions.js +1020 -0
  64. package/dist/core/tool-definitions.js.map +1 -0
  65. package/dist/core/tools/config.d.ts +98 -0
  66. package/dist/core/tools/config.js +279 -0
  67. package/dist/core/tools/config.js.map +1 -0
  68. package/dist/core/tools/edit.d.ts +49 -0
  69. package/dist/core/tools/edit.js +540 -0
  70. package/dist/core/tools/edit.js.map +1 -0
  71. package/dist/core/tools/feedback.d.ts +8 -0
  72. package/dist/core/tools/feedback.js +133 -0
  73. package/dist/core/tools/feedback.js.map +1 -0
  74. package/dist/core/tools/filesystem.d.ts +84 -0
  75. package/dist/core/tools/filesystem.js +991 -0
  76. package/dist/core/tools/filesystem.js.map +1 -0
  77. package/dist/core/tools/fuzzySearch.d.ts +14 -0
  78. package/dist/core/tools/fuzzySearch.js +141 -0
  79. package/dist/core/tools/fuzzySearch.js.map +1 -0
  80. package/dist/core/tools/fuzzySearchCore.d.ts +52 -0
  81. package/dist/core/tools/fuzzySearchCore.js +126 -0
  82. package/dist/core/tools/fuzzySearchCore.js.map +1 -0
  83. package/dist/core/tools/improved-process-tools.d.ts +24 -0
  84. package/dist/core/tools/improved-process-tools.js +645 -0
  85. package/dist/core/tools/improved-process-tools.js.map +1 -0
  86. package/dist/core/tools/mime-types.d.ts +3 -0
  87. package/dist/core/tools/mime-types.js +29 -0
  88. package/dist/core/tools/mime-types.js.map +1 -0
  89. package/dist/core/tools/pdf/extract-images.d.ts +34 -0
  90. package/dist/core/tools/pdf/extract-images.js +133 -0
  91. package/dist/core/tools/pdf/extract-images.js.map +1 -0
  92. package/dist/core/tools/pdf/index.d.ts +6 -0
  93. package/dist/core/tools/pdf/index.js +4 -0
  94. package/dist/core/tools/pdf/index.js.map +1 -0
  95. package/dist/core/tools/pdf/lib/pdf2md.d.ts +36 -0
  96. package/dist/core/tools/pdf/lib/pdf2md.js +77 -0
  97. package/dist/core/tools/pdf/lib/pdf2md.js.map +1 -0
  98. package/dist/core/tools/pdf/manipulations.d.ts +13 -0
  99. package/dist/core/tools/pdf/manipulations.js +100 -0
  100. package/dist/core/tools/pdf/manipulations.js.map +1 -0
  101. package/dist/core/tools/pdf/markdown.d.ts +26 -0
  102. package/dist/core/tools/pdf/markdown.js +276 -0
  103. package/dist/core/tools/pdf/markdown.js.map +1 -0
  104. package/dist/core/tools/pdf/utils.d.ts +12 -0
  105. package/dist/core/tools/pdf/utils.js +35 -0
  106. package/dist/core/tools/pdf/utils.js.map +1 -0
  107. package/dist/core/tools/process.d.ts +17 -0
  108. package/dist/core/tools/process.js +88 -0
  109. package/dist/core/tools/process.js.map +1 -0
  110. package/dist/core/tools/prompts.d.ts +28 -0
  111. package/dist/core/tools/prompts.js +260 -0
  112. package/dist/core/tools/prompts.js.map +1 -0
  113. package/dist/core/tools/schemas.d.ts +594 -0
  114. package/dist/core/tools/schemas.js +282 -0
  115. package/dist/core/tools/schemas.js.map +1 -0
  116. package/dist/core/tools/usage.d.ts +5 -0
  117. package/dist/core/tools/usage.js +25 -0
  118. package/dist/core/tools/usage.js.map +1 -0
  119. package/dist/core/types.d.ts +83 -0
  120. package/dist/core/types.js +2 -0
  121. package/dist/core/types.js.map +1 -0
  122. package/dist/core/ui/file-preview/shared/preview-file-types.d.ts +5 -0
  123. package/dist/core/ui/file-preview/shared/preview-file-types.js +60 -0
  124. package/dist/core/ui/file-preview/shared/preview-file-types.js.map +1 -0
  125. package/dist/core/utils/ab-test.d.ts +12 -0
  126. package/dist/core/utils/ab-test.js +105 -0
  127. package/dist/core/utils/ab-test.js.map +1 -0
  128. package/dist/core/utils/capture.d.ts +12 -0
  129. package/dist/core/utils/capture.js +38 -0
  130. package/dist/core/utils/capture.js.map +1 -0
  131. package/dist/core/utils/dockerPrompt.d.ts +17 -0
  132. package/dist/core/utils/dockerPrompt.js +54 -0
  133. package/dist/core/utils/dockerPrompt.js.map +1 -0
  134. package/dist/core/utils/feature-flags.d.ts +59 -0
  135. package/dist/core/utils/feature-flags.js +218 -0
  136. package/dist/core/utils/feature-flags.js.map +1 -0
  137. package/dist/core/utils/files/base.d.ts +173 -0
  138. package/dist/core/utils/files/base.js +6 -0
  139. package/dist/core/utils/files/base.js.map +1 -0
  140. package/dist/core/utils/files/binary.d.ts +21 -0
  141. package/dist/core/utils/files/binary.js +66 -0
  142. package/dist/core/utils/files/binary.js.map +1 -0
  143. package/dist/core/utils/files/docx.d.ts +47 -0
  144. package/dist/core/utils/files/docx.js +678 -0
  145. package/dist/core/utils/files/docx.js.map +1 -0
  146. package/dist/core/utils/files/excel.d.ts +24 -0
  147. package/dist/core/utils/files/excel.js +438 -0
  148. package/dist/core/utils/files/excel.js.map +1 -0
  149. package/dist/core/utils/files/factory.d.ts +29 -0
  150. package/dist/core/utils/files/factory.js +103 -0
  151. package/dist/core/utils/files/factory.js.map +1 -0
  152. package/dist/core/utils/files/image.d.ts +21 -0
  153. package/dist/core/utils/files/image.js +79 -0
  154. package/dist/core/utils/files/image.js.map +1 -0
  155. package/dist/core/utils/files/index.d.ts +9 -0
  156. package/dist/core/utils/files/index.js +15 -0
  157. package/dist/core/utils/files/index.js.map +1 -0
  158. package/dist/core/utils/files/pdf.d.ts +32 -0
  159. package/dist/core/utils/files/pdf.js +141 -0
  160. package/dist/core/utils/files/pdf.js.map +1 -0
  161. package/dist/core/utils/files/text.d.ts +70 -0
  162. package/dist/core/utils/files/text.js +552 -0
  163. package/dist/core/utils/files/text.js.map +1 -0
  164. package/dist/core/utils/fuzzySearchLogger.d.ts +26 -0
  165. package/dist/core/utils/fuzzySearchLogger.js +9 -0
  166. package/dist/core/utils/fuzzySearchLogger.js.map +1 -0
  167. package/dist/core/utils/lineEndingHandler.d.ts +21 -0
  168. package/dist/core/utils/lineEndingHandler.js +78 -0
  169. package/dist/core/utils/lineEndingHandler.js.map +1 -0
  170. package/dist/core/utils/logger.d.ts +17 -0
  171. package/dist/core/utils/logger.js +5 -0
  172. package/dist/core/utils/logger.js.map +1 -0
  173. package/dist/core/utils/mcp-ui-ab-test.d.ts +13 -0
  174. package/dist/core/utils/mcp-ui-ab-test.js +63 -0
  175. package/dist/core/utils/mcp-ui-ab-test.js.map +1 -0
  176. package/dist/core/utils/open-browser.d.ts +9 -0
  177. package/dist/core/utils/open-browser.js +47 -0
  178. package/dist/core/utils/open-browser.js.map +1 -0
  179. package/dist/core/utils/process-detection.d.ts +23 -0
  180. package/dist/core/utils/process-detection.js +151 -0
  181. package/dist/core/utils/process-detection.js.map +1 -0
  182. package/dist/core/utils/ripgrep-resolver.d.ts +9 -0
  183. package/dist/core/utils/ripgrep-resolver.js +96 -0
  184. package/dist/core/utils/ripgrep-resolver.js.map +1 -0
  185. package/dist/core/utils/system-info.d.ts +72 -0
  186. package/dist/core/utils/system-info.js +723 -0
  187. package/dist/core/utils/system-info.js.map +1 -0
  188. package/dist/core/utils/toolHistory.d.ts +31 -0
  189. package/dist/core/utils/toolHistory.js +17 -0
  190. package/dist/core/utils/toolHistory.js.map +1 -0
  191. package/dist/core/utils/trackTools.d.ts +1 -0
  192. package/dist/core/utils/trackTools.js +3 -0
  193. package/dist/core/utils/trackTools.js.map +1 -0
  194. package/dist/core/utils/unsupportedParams.d.ts +24 -0
  195. package/dist/core/utils/unsupportedParams.js +67 -0
  196. package/dist/core/utils/unsupportedParams.js.map +1 -0
  197. package/dist/core/utils/usageTracker.d.ts +125 -0
  198. package/dist/core/utils/usageTracker.js +475 -0
  199. package/dist/core/utils/usageTracker.js.map +1 -0
  200. package/dist/core/utils/welcome-onboarding.d.ts +11 -0
  201. package/dist/core/utils/welcome-onboarding.js +100 -0
  202. package/dist/core/utils/welcome-onboarding.js.map +1 -0
  203. package/dist/core/utils/withTimeout.d.ts +28 -0
  204. package/dist/core/utils/withTimeout.js +86 -0
  205. package/dist/core/utils/withTimeout.js.map +1 -0
  206. package/dist/core/version.d.ts +1 -0
  207. package/dist/core/version.js +2 -0
  208. package/dist/core/version.js.map +1 -0
  209. package/dist/dispatcher.d.ts +7 -0
  210. package/dist/dispatcher.js +179 -0
  211. package/dist/dispatcher.js.map +1 -0
  212. package/dist/index.d.ts +6 -0
  213. package/dist/index.js +7 -0
  214. package/dist/index.js.map +1 -0
  215. package/dist/plugins/cli-commands.d.ts +5 -0
  216. package/dist/plugins/cli-commands.js +240 -0
  217. package/dist/plugins/cli-commands.js.map +1 -0
  218. package/dist/plugins/defaults.d.ts +62 -0
  219. package/dist/plugins/defaults.js +260 -0
  220. package/dist/plugins/defaults.js.map +1 -0
  221. package/dist/plugins/first-run.d.ts +16 -0
  222. package/dist/plugins/first-run.js +89 -0
  223. package/dist/plugins/first-run.js.map +1 -0
  224. package/dist/plugins/host.d.ts +20 -0
  225. package/dist/plugins/host.js +175 -0
  226. package/dist/plugins/host.js.map +1 -0
  227. package/dist/plugins/installer.d.ts +21 -0
  228. package/dist/plugins/installer.js +350 -0
  229. package/dist/plugins/installer.js.map +1 -0
  230. package/dist/plugins/locate.d.ts +15 -0
  231. package/dist/plugins/locate.js +99 -0
  232. package/dist/plugins/locate.js.map +1 -0
  233. package/dist/plugins/manager.d.ts +32 -0
  234. package/dist/plugins/manager.js +139 -0
  235. package/dist/plugins/manager.js.map +1 -0
  236. package/dist/plugins/paths.d.ts +32 -0
  237. package/dist/plugins/paths.js +49 -0
  238. package/dist/plugins/paths.js.map +1 -0
  239. package/dist/plugins/python.d.ts +55 -0
  240. package/dist/plugins/python.js +234 -0
  241. package/dist/plugins/python.js.map +1 -0
  242. package/dist/plugins/store.d.ts +12 -0
  243. package/dist/plugins/store.js +76 -0
  244. package/dist/plugins/store.js.map +1 -0
  245. package/dist/plugins/types.d.ts +112 -0
  246. package/dist/plugins/types.js +9 -0
  247. package/dist/plugins/types.js.map +1 -0
  248. package/dist/plugins/util.d.ts +37 -0
  249. package/dist/plugins/util.js +283 -0
  250. package/dist/plugins/util.js.map +1 -0
  251. package/dist/runtime/activity.d.ts +49 -0
  252. package/dist/runtime/activity.js +158 -0
  253. package/dist/runtime/activity.js.map +1 -0
  254. package/dist/runtime/browser-workflow.d.ts +21 -0
  255. package/dist/runtime/browser-workflow.js +51 -0
  256. package/dist/runtime/browser-workflow.js.map +1 -0
  257. package/dist/runtime/code-graph.d.ts +156 -0
  258. package/dist/runtime/code-graph.js +330 -0
  259. package/dist/runtime/code-graph.js.map +1 -0
  260. package/dist/runtime/code-structure.d.ts +53 -0
  261. package/dist/runtime/code-structure.js +152 -0
  262. package/dist/runtime/code-structure.js.map +1 -0
  263. package/dist/runtime/coding-session.d.ts +97 -0
  264. package/dist/runtime/coding-session.js +142 -0
  265. package/dist/runtime/coding-session.js.map +1 -0
  266. package/dist/runtime/detach.d.ts +114 -0
  267. package/dist/runtime/detach.js +505 -0
  268. package/dist/runtime/detach.js.map +1 -0
  269. package/dist/runtime/docker-client.d.ts +47 -0
  270. package/dist/runtime/docker-client.js +40 -0
  271. package/dist/runtime/docker-client.js.map +1 -0
  272. package/dist/runtime/errors.d.ts +9 -0
  273. package/dist/runtime/errors.js +56 -0
  274. package/dist/runtime/errors.js.map +1 -0
  275. package/dist/runtime/failure-log.d.ts +22 -0
  276. package/dist/runtime/failure-log.js +112 -0
  277. package/dist/runtime/failure-log.js.map +1 -0
  278. package/dist/runtime/fast-batch.d.ts +55 -0
  279. package/dist/runtime/fast-batch.js +104 -0
  280. package/dist/runtime/fast-batch.js.map +1 -0
  281. package/dist/runtime/file-safety.d.ts +7 -0
  282. package/dist/runtime/file-safety.js +134 -0
  283. package/dist/runtime/file-safety.js.map +1 -0
  284. package/dist/runtime/generic-code.d.ts +9 -0
  285. package/dist/runtime/generic-code.js +123 -0
  286. package/dist/runtime/generic-code.js.map +1 -0
  287. package/dist/runtime/graph-outline.d.ts +54 -0
  288. package/dist/runtime/graph-outline.js +118 -0
  289. package/dist/runtime/graph-outline.js.map +1 -0
  290. package/dist/runtime/harness.d.ts +61 -0
  291. package/dist/runtime/harness.js +102 -0
  292. package/dist/runtime/harness.js.map +1 -0
  293. package/dist/runtime/instruction-context.d.ts +23 -0
  294. package/dist/runtime/instruction-context.js +136 -0
  295. package/dist/runtime/instruction-context.js.map +1 -0
  296. package/dist/runtime/lab-mode.d.ts +32 -0
  297. package/dist/runtime/lab-mode.js +138 -0
  298. package/dist/runtime/lab-mode.js.map +1 -0
  299. package/dist/runtime/languages.d.ts +30 -0
  300. package/dist/runtime/languages.js +59 -0
  301. package/dist/runtime/languages.js.map +1 -0
  302. package/dist/runtime/nav-cache.d.ts +2 -0
  303. package/dist/runtime/nav-cache.js +12 -0
  304. package/dist/runtime/nav-cache.js.map +1 -0
  305. package/dist/runtime/operations.d.ts +40 -0
  306. package/dist/runtime/operations.js +86 -0
  307. package/dist/runtime/operations.js.map +1 -0
  308. package/dist/runtime/platform-capabilities.d.ts +20 -0
  309. package/dist/runtime/platform-capabilities.js +36 -0
  310. package/dist/runtime/platform-capabilities.js.map +1 -0
  311. package/dist/runtime/program-runner.d.ts +4 -0
  312. package/dist/runtime/program-runner.js +73 -0
  313. package/dist/runtime/program-runner.js.map +1 -0
  314. package/dist/runtime/project-context.d.ts +53 -0
  315. package/dist/runtime/project-context.js +90 -0
  316. package/dist/runtime/project-context.js.map +1 -0
  317. package/dist/runtime/project-files.d.ts +2 -0
  318. package/dist/runtime/project-files.js +3 -0
  319. package/dist/runtime/project-files.js.map +1 -0
  320. package/dist/runtime/project-index.d.ts +40 -0
  321. package/dist/runtime/project-index.js +158 -0
  322. package/dist/runtime/project-index.js.map +1 -0
  323. package/dist/runtime/resource-limits.d.ts +42 -0
  324. package/dist/runtime/resource-limits.js +50 -0
  325. package/dist/runtime/resource-limits.js.map +1 -0
  326. package/dist/runtime/scratch-budget.d.ts +11 -0
  327. package/dist/runtime/scratch-budget.js +107 -0
  328. package/dist/runtime/scratch-budget.js.map +1 -0
  329. package/dist/runtime/search-diagnostics.d.ts +3 -0
  330. package/dist/runtime/search-diagnostics.js +45 -0
  331. package/dist/runtime/search-diagnostics.js.map +1 -0
  332. package/dist/runtime/toolchains.d.ts +25 -0
  333. package/dist/runtime/toolchains.js +70 -0
  334. package/dist/runtime/toolchains.js.map +1 -0
  335. package/dist/runtime/worker-coordination.d.ts +314 -0
  336. package/dist/runtime/worker-coordination.js +564 -0
  337. package/dist/runtime/worker-coordination.js.map +1 -0
  338. package/dist/runtime/workspace.d.ts +151 -0
  339. package/dist/runtime/workspace.js +267 -0
  340. package/dist/runtime/workspace.js.map +1 -0
  341. package/dist/service.d.ts +3 -0
  342. package/dist/service.js +102 -0
  343. package/dist/service.js.map +1 -0
  344. package/dist/terminal-setup.d.ts +33 -0
  345. package/dist/terminal-setup.js +219 -0
  346. package/dist/terminal-setup.js.map +1 -0
  347. package/dist/terminal-shortcuts.d.ts +22 -0
  348. package/dist/terminal-shortcuts.js +145 -0
  349. package/dist/terminal-shortcuts.js.map +1 -0
  350. package/dist/terminal-ui.d.ts +20 -0
  351. package/dist/terminal-ui.js +53 -0
  352. package/dist/terminal-ui.js.map +1 -0
  353. package/dist/tools/ast-grep.d.ts +132 -0
  354. package/dist/tools/ast-grep.js +625 -0
  355. package/dist/tools/ast-grep.js.map +1 -0
  356. package/dist/tools/brc-tools.d.ts +112 -0
  357. package/dist/tools/brc-tools.js +599 -0
  358. package/dist/tools/brc-tools.js.map +1 -0
  359. package/dist/tools/check-tools.d.ts +4 -0
  360. package/dist/tools/check-tools.js +29 -0
  361. package/dist/tools/check-tools.js.map +1 -0
  362. package/dist/tools/coding-tools.d.ts +33 -0
  363. package/dist/tools/coding-tools.js +190 -0
  364. package/dist/tools/coding-tools.js.map +1 -0
  365. package/dist/tools/command-shell.d.ts +17 -0
  366. package/dist/tools/command-shell.js +84 -0
  367. package/dist/tools/command-shell.js.map +1 -0
  368. package/dist/tools/dev-extras.d.ts +42 -0
  369. package/dist/tools/dev-extras.js +135 -0
  370. package/dist/tools/dev-extras.js.map +1 -0
  371. package/dist/tools/edit-tools.d.ts +4 -0
  372. package/dist/tools/edit-tools.js +293 -0
  373. package/dist/tools/edit-tools.js.map +1 -0
  374. package/dist/tools/fast-exec.d.ts +11 -0
  375. package/dist/tools/fast-exec.js +202 -0
  376. package/dist/tools/fast-exec.js.map +1 -0
  377. package/dist/tools/image-tools.d.ts +37 -0
  378. package/dist/tools/image-tools.js +293 -0
  379. package/dist/tools/image-tools.js.map +1 -0
  380. package/dist/tools/jobs.d.ts +227 -0
  381. package/dist/tools/jobs.js +608 -0
  382. package/dist/tools/jobs.js.map +1 -0
  383. package/dist/tools/ops-tools.d.ts +8 -0
  384. package/dist/tools/ops-tools.js +58 -0
  385. package/dist/tools/ops-tools.js.map +1 -0
  386. package/dist/tools/plugin-tools.d.ts +38 -0
  387. package/dist/tools/plugin-tools.js +133 -0
  388. package/dist/tools/plugin-tools.js.map +1 -0
  389. package/dist/tools/rtk.d.ts +60 -0
  390. package/dist/tools/rtk.js +245 -0
  391. package/dist/tools/rtk.js.map +1 -0
  392. package/dist/tools/sandbox-tools.d.ts +41 -0
  393. package/dist/tools/sandbox-tools.js +146 -0
  394. package/dist/tools/sandbox-tools.js.map +1 -0
  395. package/dist/tools/worker-tools.d.ts +231 -0
  396. package/dist/tools/worker-tools.js +55 -0
  397. package/dist/tools/worker-tools.js.map +1 -0
  398. package/dist/tools/workspace-batch.d.ts +262 -0
  399. package/dist/tools/workspace-batch.js +188 -0
  400. package/dist/tools/workspace-batch.js.map +1 -0
  401. package/dist/transport/pairing.d.ts +22 -0
  402. package/dist/transport/pairing.js +154 -0
  403. package/dist/transport/pairing.js.map +1 -0
  404. package/dist/transport/plugin-admin.d.ts +33 -0
  405. package/dist/transport/plugin-admin.js +156 -0
  406. package/dist/transport/plugin-admin.js.map +1 -0
  407. package/dist/transport/relay-url.d.ts +3 -0
  408. package/dist/transport/relay-url.js +38 -0
  409. package/dist/transport/relay-url.js.map +1 -0
  410. package/dist/transport/result-budget.d.ts +11 -0
  411. package/dist/transport/result-budget.js +45 -0
  412. package/dist/transport/result-budget.js.map +1 -0
  413. package/dist/transport/ws-client.d.ts +64 -0
  414. package/dist/transport/ws-client.js +242 -0
  415. package/dist/transport/ws-client.js.map +1 -0
  416. package/package.json +89 -3
@@ -0,0 +1,645 @@
1
+ import { terminalManager, MAX_BUFFERED_OUTPUT_CHARS } from '../terminal-manager.js';
2
+ import { commandManager } from '../command-manager.js';
3
+ import { StartProcessArgsSchema, ReadProcessOutputArgsSchema, InteractWithProcessArgsSchema, ForceTerminateArgsSchema } from './schemas.js';
4
+ import { capture } from "../utils/capture.js";
5
+ import { analyzeProcessState, cleanProcessOutput, formatProcessStateMessage } from '../utils/process-detection.js';
6
+ import * as os from 'os';
7
+ import { configManager } from '../config-manager.js';
8
+ import { selectRunCommandShell } from '../../tools/command-shell.js';
9
+ import { spawn } from 'child_process';
10
+ import fs from 'fs/promises';
11
+ import path from 'path';
12
+ import { fileURLToPath } from 'url';
13
+ // Get the directory where the MCP is installed (for ES module imports)
14
+ const __filename = fileURLToPath(import.meta.url);
15
+ const __dirname = path.dirname(__filename);
16
+ const mcpRoot = path.resolve(__dirname, '..', '..');
17
+ // Track virtual Node sessions (PIDs that are actually Node fallback sessions)
18
+ const virtualNodeSessions = new Map();
19
+ let virtualPidCounter = -1000; // Use negative PIDs for virtual sessions
20
+ /**
21
+ * Execute Node.js code via temp file (fallback when Python unavailable)
22
+ * Creates temp .mjs file in MCP directory for ES module import access
23
+ */
24
+ async function executeNodeCode(code, timeout_ms = 30000) {
25
+ const tempFile = path.join(mcpRoot, `.mcp-exec-${Date.now()}-${Math.random().toString(36).slice(2)}.mjs`);
26
+ try {
27
+ await fs.writeFile(tempFile, code, 'utf8');
28
+ const result = await new Promise((resolve) => {
29
+ const proc = spawn(process.execPath, [tempFile], {
30
+ cwd: mcpRoot,
31
+ timeout: timeout_ms,
32
+ windowsHide: true // Prevent visible console windows on Windows
33
+ });
34
+ let stdout = '';
35
+ let stderr = '';
36
+ proc.stdout.on('data', (data) => {
37
+ stdout += data.toString();
38
+ });
39
+ proc.stderr.on('data', (data) => {
40
+ stderr += data.toString();
41
+ });
42
+ proc.on('close', (exitCode) => {
43
+ resolve({ stdout, stderr, exitCode: exitCode ?? 1 });
44
+ });
45
+ proc.on('error', (err) => {
46
+ resolve({ stdout, stderr: stderr + '\n' + err.message, exitCode: 1 });
47
+ });
48
+ });
49
+ // Clean up temp file
50
+ await fs.unlink(tempFile).catch(() => { });
51
+ if (result.exitCode !== 0) {
52
+ return {
53
+ content: [{
54
+ type: "text",
55
+ text: `Execution failed (exit code ${result.exitCode}):\n${result.stderr}\n${result.stdout}`
56
+ }],
57
+ isError: true
58
+ };
59
+ }
60
+ return {
61
+ content: [{
62
+ type: "text",
63
+ text: result.stdout || '(no output)'
64
+ }]
65
+ };
66
+ }
67
+ catch (error) {
68
+ // Clean up temp file on error
69
+ await fs.unlink(tempFile).catch(() => { });
70
+ return {
71
+ content: [{
72
+ type: "text",
73
+ text: `Failed to execute Node.js code: ${error instanceof Error ? error.message : String(error)}`
74
+ }],
75
+ isError: true
76
+ };
77
+ }
78
+ }
79
+ /**
80
+ * Start a new process (renamed from execute_command)
81
+ * Includes early detection of process waiting for input
82
+ */
83
+ export async function startProcess(args) {
84
+ const parsed = StartProcessArgsSchema.safeParse(args);
85
+ if (!parsed.success) {
86
+ capture('server_start_process_failed');
87
+ return {
88
+ content: [{ type: "text", text: `Error: Invalid arguments for start_process: ${parsed.error}` }],
89
+ isError: true,
90
+ };
91
+ }
92
+ try {
93
+ const commands = commandManager.extractCommands(parsed.data.command).join(', ');
94
+ capture('server_start_process', {
95
+ command: commandManager.getBaseCommand(parsed.data.command),
96
+ commands: commands
97
+ });
98
+ }
99
+ catch (error) {
100
+ capture('server_start_process', {
101
+ command: commandManager.getBaseCommand(parsed.data.command)
102
+ });
103
+ }
104
+ const isAllowed = await commandManager.validateCommand(parsed.data.command);
105
+ if (!isAllowed) {
106
+ return {
107
+ content: [{ type: "text", text: `Error: Command not allowed: ${parsed.data.command}` }],
108
+ isError: true,
109
+ };
110
+ }
111
+ const commandToRun = parsed.data.command;
112
+ // Handle node:local - runs Node.js code directly on MCP server
113
+ if (commandToRun.trim() === 'node:local') {
114
+ const virtualPid = virtualPidCounter--;
115
+ virtualNodeSessions.set(virtualPid, { timeout_ms: parsed.data.timeout_ms || 30000 });
116
+ return {
117
+ content: [{
118
+ type: "text",
119
+ text: `Node.js session started with PID ${virtualPid} (MCP server execution)
120
+
121
+ IMPORTANT: Each interact_with_process call runs as a FRESH script.
122
+ State is NOT preserved between calls. Include ALL code in ONE call:
123
+ - imports, file reading, processing, and output together.
124
+
125
+ Available libraries:
126
+ - ExcelJS for Excel files: import ExcelJS from 'exceljs'
127
+ - All Node.js built-ins: fs, path, http, crypto, etc.
128
+
129
+ 🔄 Ready for code - send complete self-contained script via interact_with_process.`
130
+ }],
131
+ };
132
+ }
133
+ let shellUsed = parsed.data.shell;
134
+ if (!shellUsed) {
135
+ const config = await configManager.getConfig();
136
+ if (config.defaultShell) {
137
+ shellUsed = config.defaultShell;
138
+ }
139
+ else {
140
+ const isWindows = os.platform() === 'win32';
141
+ if (isWindows && process.env.COMSPEC) {
142
+ shellUsed = process.env.COMSPEC;
143
+ }
144
+ else if (!isWindows && process.env.SHELL) {
145
+ shellUsed = process.env.SHELL;
146
+ }
147
+ else {
148
+ shellUsed = isWindows ? 'cmd.exe' : '/bin/sh';
149
+ }
150
+ }
151
+ }
152
+ const configuredShell = shellUsed;
153
+ const shellChoice = selectRunCommandShell(commandToRun, configuredShell, parsed.data.shell !== undefined);
154
+ if (shellChoice.error) {
155
+ const suggested = shellChoice.suggestedShell
156
+ ? { command: commandToRun, shell: shellChoice.suggestedShell, timeout_ms: parsed.data.timeout_ms }
157
+ : null;
158
+ return {
159
+ isError: true,
160
+ content: [{ type: 'text', text: 'SHELL_SYNTAX: ' + shellChoice.error +
161
+ (suggested ? '\nSUGGESTED CALL (not executed): start_process(' + JSON.stringify(suggested) + ')' : '') }],
162
+ structuredContent: { error: { code: 'SHELL_SYNTAX', message: shellChoice.error, retryable: false },
163
+ commandExecuted: false, shell: configuredShell, platform: process.platform,
164
+ recovery: { automaticRetry: false, suggestion: shellChoice.error,
165
+ ...(suggested ? { next: { tool: 'start_process', args: suggested } } : {}) } }
166
+ };
167
+ }
168
+ shellUsed = shellChoice.shell;
169
+ const result = await terminalManager.executeCommand(commandToRun, parsed.data.timeout_ms, shellUsed, parsed.data.verbose_timing || false);
170
+ if (result.pid === -1) {
171
+ return {
172
+ content: [{ type: 'text', text: 'SHELL_START_FAILED: ' + result.output + '\nNEXT ACTION: Check shell executable, command permissions and PATH. No process started.' }],
173
+ isError: true,
174
+ structuredContent: { error: { code: 'SHELL_START_FAILED', message: result.output.slice(0, 1200), retryable: false },
175
+ commandExecuted: false, shell: shellUsed, platform: process.platform,
176
+ recovery: { automaticRetry: false, suggestion: 'Check shell, PATH and command permissions; correct the failure before retrying.' } },
177
+ };
178
+ }
179
+ // Analyze the process state to detect if it's waiting for input
180
+ const processState = analyzeProcessState(result.output, result.pid);
181
+ let statusMessage = '';
182
+ if (processState.isWaitingForInput) {
183
+ statusMessage = `\n🔄 ${formatProcessStateMessage(processState, result.pid)}`;
184
+ }
185
+ else if (processState.isFinished) {
186
+ statusMessage = `\n✅ ${formatProcessStateMessage(processState, result.pid)}`;
187
+ }
188
+ else if (result.isBlocked) {
189
+ statusMessage = '\n⏳ Process is running. Use read_process_output to get more output.';
190
+ }
191
+ // Add timing information if requested
192
+ let timingMessage = '';
193
+ if (result.timingInfo) {
194
+ timingMessage = formatTimingInfo(result.timingInfo);
195
+ }
196
+ return {
197
+ content: [{
198
+ type: "text",
199
+ text: `Process started with PID ${result.pid} (shell: ${shellUsed})\n${shellChoice.reason ? 'Shell selection: ' + shellChoice.reason + '\n' : ''}Initial output:\n${result.output}${statusMessage}${timingMessage}`
200
+ }],
201
+ };
202
+ }
203
+ function formatTimingInfo(timing) {
204
+ let msg = '\n\n📊 Timing Information:\n';
205
+ msg += ` Exit Reason: ${timing.exitReason}\n`;
206
+ msg += ` Total Duration: ${timing.totalDurationMs}ms\n`;
207
+ if (timing.timeToFirstOutputMs !== undefined) {
208
+ msg += ` Time to First Output: ${timing.timeToFirstOutputMs}ms\n`;
209
+ }
210
+ if (timing.firstOutputTime && timing.lastOutputTime) {
211
+ msg += ` Output Window: ${timing.lastOutputTime - timing.firstOutputTime}ms\n`;
212
+ }
213
+ if (timing.outputEvents && timing.outputEvents.length > 0) {
214
+ msg += `\n Output Events (${timing.outputEvents.length} total):\n`;
215
+ timing.outputEvents.forEach((event, idx) => {
216
+ msg += ` [${idx + 1}] +${event.deltaMs}ms | ${event.source} | ${event.length}b`;
217
+ if (event.matchedPattern) {
218
+ msg += ` | 🎯 ${event.matchedPattern}`;
219
+ }
220
+ msg += `\n "${event.snippet}"\n`;
221
+ });
222
+ }
223
+ return msg;
224
+ }
225
+ /**
226
+ * Read output from a running process with file-like pagination
227
+ * Supports offset/length parameters for controlled reading
228
+ */
229
+ export async function readProcessOutput(args) {
230
+ const parsed = ReadProcessOutputArgsSchema.safeParse(args);
231
+ if (!parsed.success) {
232
+ return {
233
+ content: [{ type: "text", text: `Error: Invalid arguments for read_process_output: ${parsed.error}` }],
234
+ isError: true,
235
+ };
236
+ }
237
+ // Get default line limit from config
238
+ const config = await configManager.getConfig();
239
+ const defaultLength = config.fileReadLineLimit ?? 1000;
240
+ const { pid, timeout_ms = 5000, offset = 0, // 0 = from last read, positive = absolute, negative = tail
241
+ length = defaultLength, // Default from config, same as file reading
242
+ verbose_timing = false } = parsed.data;
243
+ // Timing telemetry
244
+ const startTime = Date.now();
245
+ // For active sessions with no new output yet, optionally wait for output
246
+ const session = terminalManager.getSession(pid);
247
+ if (session && offset === 0) {
248
+ // Wait for new output to arrive (only for "new output" reads, not absolute/tail)
249
+ const waitForOutput = () => {
250
+ return new Promise((resolve) => {
251
+ // Check if there's already new output
252
+ const currentLines = terminalManager.getOutputLineCount(pid) || 0;
253
+ if (currentLines > session.lastReadIndex) {
254
+ resolve();
255
+ return;
256
+ }
257
+ let resolved = false;
258
+ let interval = null;
259
+ let timeout = null;
260
+ const cleanup = () => {
261
+ if (interval)
262
+ clearInterval(interval);
263
+ if (timeout)
264
+ clearTimeout(timeout);
265
+ };
266
+ const resolveOnce = () => {
267
+ if (resolved)
268
+ return;
269
+ resolved = true;
270
+ cleanup();
271
+ resolve();
272
+ };
273
+ // Poll for new output
274
+ interval = setInterval(() => {
275
+ const newLineCount = terminalManager.getOutputLineCount(pid) || 0;
276
+ if (newLineCount > session.lastReadIndex) {
277
+ resolveOnce();
278
+ }
279
+ }, 50);
280
+ // Timeout
281
+ timeout = setTimeout(() => {
282
+ resolveOnce();
283
+ }, timeout_ms);
284
+ });
285
+ };
286
+ await waitForOutput();
287
+ }
288
+ // Read output with pagination
289
+ const result = terminalManager.readOutputPaginated(pid, offset, length);
290
+ if (!result) {
291
+ return {
292
+ content: [{ type: "text", text: `No session found for PID ${pid}` }],
293
+ isError: true,
294
+ };
295
+ }
296
+ // Join lines back into string
297
+ const output = result.lines.join('\n');
298
+ // Generate status message similar to file reading
299
+ let statusMessage = '';
300
+ if (offset < 0) {
301
+ // Tail read - match file reading format for consistency
302
+ statusMessage = `[Reading last ${result.readCount} lines (total: ${result.totalLines} lines)]`;
303
+ }
304
+ else if (offset === 0) {
305
+ // "New output" read
306
+ if (result.remaining > 0) {
307
+ statusMessage = `[Reading ${result.readCount} new lines from line ${result.readFrom} (total: ${result.totalLines} lines, ${result.remaining} remaining)]`;
308
+ }
309
+ else {
310
+ statusMessage = `[Reading ${result.readCount} new lines (total: ${result.totalLines} lines)]`;
311
+ }
312
+ }
313
+ else {
314
+ // Absolute position read
315
+ statusMessage = `[Reading ${result.readCount} lines from line ${result.readFrom} (total: ${result.totalLines} lines, ${result.remaining} remaining)]`;
316
+ }
317
+ // Surface buffer-cap eviction so the model knows the retained output is not
318
+ // the full output and that line numbers shifted (matches the truncation
319
+ // markers used by other tools).
320
+ if (result.evictedLines && result.evictedLines > 0) {
321
+ const capMB = Math.round(MAX_BUFFERED_OUTPUT_CHARS / 1024 / 1024);
322
+ statusMessage += `\n[WARNING: output exceeded the ${capMB}MB buffer cap; the ${result.evictedLines} earliest lines were evicted and cannot be read. Line numbers and totals refer to the retained buffer only]`;
323
+ }
324
+ // Add process state info
325
+ let processStateMessage = '';
326
+ if (result.isComplete) {
327
+ const runtimeStr = result.runtimeMs !== undefined
328
+ ? ` (runtime: ${(result.runtimeMs / 1000).toFixed(2)}s)`
329
+ : '';
330
+ processStateMessage = `\n✅ Process completed with exit code ${result.exitCode}${runtimeStr}`;
331
+ }
332
+ else if (session) {
333
+ // Analyze state for running processes
334
+ const fullOutput = session.outputLines.join('\n');
335
+ const processState = analyzeProcessState(fullOutput, pid);
336
+ if (processState.isWaitingForInput) {
337
+ processStateMessage = `\n🔄 ${formatProcessStateMessage(processState, pid)}`;
338
+ }
339
+ }
340
+ // Add timing information if requested
341
+ let timingMessage = '';
342
+ if (verbose_timing) {
343
+ const endTime = Date.now();
344
+ timingMessage = `\n\n📊 Timing: ${endTime - startTime}ms`;
345
+ }
346
+ const responseText = output || '(No output in requested range)';
347
+ return {
348
+ content: [{
349
+ type: "text",
350
+ text: `${statusMessage}\n\n${responseText}${processStateMessage}${timingMessage}`
351
+ }],
352
+ };
353
+ }
354
+ /**
355
+ * Interact with a running process (renamed from send_input)
356
+ * Automatically detects when process is ready and returns output
357
+ */
358
+ export async function interactWithProcess(args) {
359
+ const parsed = InteractWithProcessArgsSchema.safeParse(args);
360
+ if (!parsed.success) {
361
+ capture('server_interact_with_process_failed', {
362
+ error: 'Invalid arguments'
363
+ });
364
+ return {
365
+ content: [{ type: "text", text: `Error: Invalid arguments for interact_with_process: ${parsed.error}` }],
366
+ isError: true,
367
+ };
368
+ }
369
+ const { pid, input, timeout_ms = 8000, wait_for_prompt = true, verbose_timing = false } = parsed.data;
370
+ // Get config for output line limit
371
+ const config = await configManager.getConfig();
372
+ const maxOutputLines = config.fileReadLineLimit ?? 1000;
373
+ // Check if this is a virtual Node session (node:local)
374
+ if (virtualNodeSessions.has(pid)) {
375
+ const session = virtualNodeSessions.get(pid);
376
+ capture('server_interact_with_process_node_fallback', {
377
+ pid: pid,
378
+ inputLength: input.length
379
+ });
380
+ // Execute code via temp file approach
381
+ // Respect per-call timeout if provided, otherwise use session default
382
+ const effectiveTimeout = timeout_ms ?? session.timeout_ms;
383
+ return executeNodeCode(input, effectiveTimeout);
384
+ }
385
+ // Timing telemetry
386
+ const startTime = Date.now();
387
+ let firstOutputTime;
388
+ let lastOutputTime;
389
+ const outputEvents = [];
390
+ let exitReason = 'timeout';
391
+ try {
392
+ capture('server_interact_with_process', {
393
+ pid: pid,
394
+ inputLength: input.length
395
+ });
396
+ // Capture output snapshot BEFORE sending input
397
+ // This handles REPLs where output is appended to the prompt line
398
+ const outputSnapshot = terminalManager.captureOutputSnapshot(pid);
399
+ const success = terminalManager.sendInputToProcess(pid, input);
400
+ if (!success) {
401
+ return {
402
+ content: [{ type: "text", text: `Error: Failed to send input to process ${pid}. The process may have exited or doesn't accept input.` }],
403
+ isError: true,
404
+ };
405
+ }
406
+ // If not waiting for response, return immediately
407
+ if (!wait_for_prompt) {
408
+ exitReason = 'no_wait';
409
+ let timingMessage = '';
410
+ if (verbose_timing) {
411
+ const endTime = Date.now();
412
+ const timingInfo = {
413
+ startTime,
414
+ endTime,
415
+ totalDurationMs: endTime - startTime,
416
+ exitReason,
417
+ firstOutputTime,
418
+ lastOutputTime,
419
+ timeToFirstOutputMs: undefined,
420
+ outputEvents: undefined
421
+ };
422
+ timingMessage = formatTimingInfo(timingInfo);
423
+ }
424
+ return {
425
+ content: [{
426
+ type: "text",
427
+ text: `✅ Input sent to process ${pid}. Use read_process_output to get the response.${timingMessage}`
428
+ }],
429
+ };
430
+ }
431
+ // Smart waiting with immediate and periodic detection
432
+ let output = "";
433
+ let processState;
434
+ let earlyExit = false;
435
+ // Quick prompt patterns for immediate detection
436
+ const quickPromptPatterns = />>>\s*$|>\s*$|\$\s*$|#\s*$/;
437
+ const waitForResponse = () => {
438
+ return new Promise((resolve) => {
439
+ let resolved = false;
440
+ let attempts = 0;
441
+ const pollIntervalMs = 50; // Poll every 50ms for faster response
442
+ const maxAttempts = Math.ceil(timeout_ms / pollIntervalMs);
443
+ let interval = null;
444
+ let lastOutputLength = 0; // Track output length to detect new output
445
+ let resolveOnce = () => {
446
+ if (resolved)
447
+ return;
448
+ resolved = true;
449
+ if (interval)
450
+ clearInterval(interval);
451
+ resolve();
452
+ };
453
+ // Fast-polling check - check every 50ms for quick responses
454
+ interval = setInterval(() => {
455
+ if (resolved)
456
+ return;
457
+ // Use snapshot-based reading to handle REPL prompt line appending
458
+ const newOutput = outputSnapshot
459
+ ? terminalManager.getOutputSinceSnapshot(pid, outputSnapshot)
460
+ : terminalManager.getNewOutput(pid);
461
+ if (newOutput && newOutput.length > lastOutputLength) {
462
+ const now = Date.now();
463
+ if (!firstOutputTime)
464
+ firstOutputTime = now;
465
+ lastOutputTime = now;
466
+ if (verbose_timing) {
467
+ outputEvents.push({
468
+ timestamp: now,
469
+ deltaMs: now - startTime,
470
+ source: 'periodic_poll',
471
+ length: newOutput.length - lastOutputLength,
472
+ snippet: newOutput.slice(lastOutputLength, lastOutputLength + 50).replace(/\n/g, '\\n')
473
+ });
474
+ }
475
+ output = newOutput; // Replace with full output since snapshot
476
+ lastOutputLength = newOutput.length;
477
+ // Analyze current state
478
+ processState = analyzeProcessState(output, pid);
479
+ // Exit early if we detect the process is waiting for input
480
+ if (processState.isWaitingForInput) {
481
+ earlyExit = true;
482
+ exitReason = 'early_exit_periodic_check';
483
+ if (verbose_timing && outputEvents.length > 0) {
484
+ outputEvents[outputEvents.length - 1].matchedPattern = 'periodic_check';
485
+ }
486
+ resolveOnce();
487
+ return;
488
+ }
489
+ // Also exit if process finished
490
+ if (processState.isFinished) {
491
+ exitReason = 'process_finished';
492
+ resolveOnce();
493
+ return;
494
+ }
495
+ }
496
+ attempts++;
497
+ if (attempts >= maxAttempts) {
498
+ exitReason = 'timeout';
499
+ resolveOnce();
500
+ }
501
+ }, pollIntervalMs);
502
+ });
503
+ };
504
+ await waitForResponse();
505
+ // Clean and format output
506
+ let cleanOutput = cleanProcessOutput(output, input);
507
+ const timeoutReached = !earlyExit && !processState?.isFinished && !processState?.isWaitingForInput;
508
+ // Apply output line limit to prevent context overflow
509
+ let truncationMessage = '';
510
+ const outputLines = cleanOutput.split('\n');
511
+ if (outputLines.length > maxOutputLines) {
512
+ const truncatedLines = outputLines.slice(0, maxOutputLines);
513
+ cleanOutput = truncatedLines.join('\n');
514
+ const remainingLines = outputLines.length - maxOutputLines;
515
+ truncationMessage = `\n\n⚠️ Output truncated: showing ${maxOutputLines} of ${outputLines.length} lines (${remainingLines} hidden). Use read_process_output with offset/length for full output.`;
516
+ }
517
+ // Determine final state
518
+ if (!processState) {
519
+ processState = analyzeProcessState(output, pid);
520
+ }
521
+ let statusMessage = '';
522
+ if (processState.isWaitingForInput) {
523
+ statusMessage = `\n🔄 ${formatProcessStateMessage(processState, pid)}`;
524
+ }
525
+ else if (processState.isFinished) {
526
+ statusMessage = `\n✅ ${formatProcessStateMessage(processState, pid)}`;
527
+ }
528
+ else if (timeoutReached) {
529
+ statusMessage = '\n⏱️ Response may be incomplete (timeout reached)';
530
+ }
531
+ // Add timing information if requested
532
+ let timingMessage = '';
533
+ if (verbose_timing) {
534
+ const endTime = Date.now();
535
+ const timingInfo = {
536
+ startTime,
537
+ endTime,
538
+ totalDurationMs: endTime - startTime,
539
+ exitReason,
540
+ firstOutputTime,
541
+ lastOutputTime,
542
+ timeToFirstOutputMs: firstOutputTime ? firstOutputTime - startTime : undefined,
543
+ outputEvents: outputEvents.length > 0 ? outputEvents : undefined
544
+ };
545
+ timingMessage = formatTimingInfo(timingInfo);
546
+ }
547
+ if (cleanOutput.trim().length === 0 && !timeoutReached) {
548
+ return {
549
+ content: [{
550
+ type: "text",
551
+ text: `✅ Input executed in process ${pid}.\n📭 (No output produced)${statusMessage}${timingMessage}`
552
+ }],
553
+ };
554
+ }
555
+ // Format response with better structure and consistent emojis
556
+ let responseText = `✅ Input executed in process ${pid}`;
557
+ if (cleanOutput && cleanOutput.trim().length > 0) {
558
+ responseText += `:\n\n📤 Output:\n${cleanOutput}`;
559
+ }
560
+ else {
561
+ responseText += `.\n📭 (No output produced)`;
562
+ }
563
+ if (statusMessage) {
564
+ responseText += `\n\n${statusMessage}`;
565
+ }
566
+ if (truncationMessage) {
567
+ responseText += truncationMessage;
568
+ }
569
+ if (timingMessage) {
570
+ responseText += timingMessage;
571
+ }
572
+ return {
573
+ content: [{
574
+ type: "text",
575
+ text: responseText
576
+ }],
577
+ };
578
+ }
579
+ catch (error) {
580
+ const errorMessage = error instanceof Error ? error.message : String(error);
581
+ capture('server_interact_with_process_error', {
582
+ error: errorMessage
583
+ });
584
+ return {
585
+ content: [{ type: "text", text: `Error interacting with process: ${errorMessage}` }],
586
+ isError: true,
587
+ };
588
+ }
589
+ }
590
+ /**
591
+ * Force terminate a process
592
+ */
593
+ export async function forceTerminate(args) {
594
+ const parsed = ForceTerminateArgsSchema.safeParse(args);
595
+ if (!parsed.success) {
596
+ return {
597
+ content: [{ type: "text", text: `Error: Invalid arguments for force_terminate: ${parsed.error}` }],
598
+ isError: true,
599
+ };
600
+ }
601
+ const pid = parsed.data.pid;
602
+ // Handle virtual Node.js sessions (node:local)
603
+ if (virtualNodeSessions.has(pid)) {
604
+ virtualNodeSessions.delete(pid);
605
+ return {
606
+ content: [{
607
+ type: "text",
608
+ text: `Cleared virtual Node.js session ${pid}`
609
+ }],
610
+ };
611
+ }
612
+ const success = terminalManager.forceTerminate(pid);
613
+ return {
614
+ content: [{
615
+ type: "text",
616
+ text: success
617
+ ? `Successfully initiated termination of session ${pid}`
618
+ : `No active session found for PID ${pid}`
619
+ }],
620
+ };
621
+ }
622
+ /**
623
+ * List active sessions
624
+ */
625
+ export async function listSessions() {
626
+ const sessions = terminalManager.listActiveSessions();
627
+ // Include virtual Node.js sessions
628
+ const virtualSessions = Array.from(virtualNodeSessions.entries()).map(([pid, session]) => ({
629
+ pid,
630
+ type: 'node:local',
631
+ timeout_ms: session.timeout_ms
632
+ }));
633
+ const realSessionsText = sessions.map(s => `PID: ${s.pid}, Blocked: ${s.isBlocked}, Runtime: ${Math.round(s.runtime / 1000)}s`);
634
+ const virtualSessionsText = virtualSessions.map(s => `PID: ${s.pid} (node:local), Timeout: ${s.timeout_ms}ms`);
635
+ const allSessions = [...realSessionsText, ...virtualSessionsText];
636
+ return {
637
+ content: [{
638
+ type: "text",
639
+ text: allSessions.length === 0
640
+ ? 'No active sessions'
641
+ : allSessions.join('\n')
642
+ }],
643
+ };
644
+ }
645
+ //# sourceMappingURL=improved-process-tools.js.map