@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,671 @@
1
+ import { spawn } from 'child_process';
2
+ import path from 'path';
3
+ import { DEFAULT_COMMAND_TIMEOUT } from './config.js';
4
+ import { configManager } from './config-manager.js';
5
+ import { capture } from "./utils/capture.js";
6
+ import { analyzeProcessState } from './utils/process-detection.js';
7
+ /**
8
+ * Standard Windows PATHEXT value, used to repair a corrupted PATHEXT before
9
+ * spawning child shells.
10
+ *
11
+ * On some Windows Claude Desktop / DXT launches the server process inherits a
12
+ * broken PATHEXT (observed as ".CPL" only). Because we build the child env from
13
+ * { ...process.env }, that broken value would propagate into every spawned
14
+ * shell, stripping ".EXE" and breaking resolution of git / node / python / rg /
15
+ * etc. (and even full-path .exe invocations under PowerShell). See issue #481.
16
+ */
17
+ const STANDARD_PATHEXT = '.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC';
18
+ /**
19
+ * Return a healthy PATHEXT for spawned Windows shells.
20
+ * - Unset -> use the standard list.
21
+ * - Missing ".EXE" -> corrupted; merge the standard list with whatever was
22
+ * present (preserves any extra extensions, order-stable).
23
+ * - Otherwise -> leave the inherited value untouched.
24
+ */
25
+ export function getRepairedPathExt() {
26
+ const current = process.env.PATHEXT;
27
+ if (!current)
28
+ return STANDARD_PATHEXT;
29
+ const exts = current.split(';').map(e => e.trim().toUpperCase()).filter(Boolean);
30
+ if (!exts.includes('.EXE')) {
31
+ return [...new Set([...STANDARD_PATHEXT.split(';'), ...exts])].join(';');
32
+ }
33
+ return current;
34
+ }
35
+ /**
36
+ * Output buffering caps. Without a cap, a process emitting enough output makes
37
+ * string concatenation throw "RangeError: Invalid string length" at V8's max
38
+ * string size (~536M chars) inside a stdout 'data' handler — an uncaught
39
+ * exception that kills the whole server (index.ts exits on uncaughtException).
40
+ * The cap also bounds the join() cost in snapshot reads and the periodic
41
+ * process-state scan, both of which are O(total output).
42
+ */
43
+ export const MAX_BUFFERED_OUTPUT_CHARS = 50 * 1024 * 1024; // per session; oldest lines evicted first
44
+ const MAX_LINE_CHARS = 1024 * 1024; // force-split longer lines so eviction can work
45
+ const MAX_WAIT_OUTPUT_CHARS = 2 * 1024 * 1024; // start_process wait buffer (prompt/state detection)
46
+ /**
47
+ * Get the appropriate spawn configuration for a given shell
48
+ * This handles login shell flags for different shell types
49
+ */
50
+ export function getShellSpawnArgs(shellPath, command) {
51
+ const shellName = path.basename(shellPath).toLowerCase();
52
+ // Unix shells with login flag support
53
+ if (shellName.includes('bash') || shellName.includes('zsh')) {
54
+ return {
55
+ executable: shellPath,
56
+ args: ['-l', '-c', command],
57
+ useShellOption: false
58
+ };
59
+ }
60
+ // PowerShell Core (cross-platform, supports -Login)
61
+ if (shellName === 'pwsh' || shellName === 'pwsh.exe') {
62
+ return {
63
+ executable: shellPath,
64
+ args: ['-Login', '-Command', command],
65
+ useShellOption: false
66
+ };
67
+ }
68
+ // Windows PowerShell 5.1 (no login flag support)
69
+ if (shellName === 'powershell' || shellName === 'powershell.exe') {
70
+ return {
71
+ executable: shellPath,
72
+ args: ['-Command', command],
73
+ useShellOption: false
74
+ };
75
+ }
76
+ // CMD
77
+ if (shellName === 'cmd' || shellName === 'cmd.exe') {
78
+ return {
79
+ executable: shellPath,
80
+ args: ['/c', command],
81
+ windowsVerbatim: true,
82
+ useShellOption: false
83
+ };
84
+ }
85
+ // Fish shell (uses -l for login, -c for command)
86
+ if (shellName.includes('fish')) {
87
+ return {
88
+ executable: shellPath,
89
+ args: ['-l', '-c', command],
90
+ useShellOption: false
91
+ };
92
+ }
93
+ // Unknown/other shells - use shell option for safety
94
+ // This provides a fallback for shells we don't explicitly handle
95
+ return {
96
+ executable: command,
97
+ args: [],
98
+ useShellOption: shellPath
99
+ };
100
+ }
101
+ export class TerminalManager {
102
+ sessions = new Map();
103
+ completedSessions = new Map();
104
+ /**
105
+ * Send input to a running process
106
+ * @param pid Process ID
107
+ * @param input Text to send to the process
108
+ * @returns Whether input was successfully sent
109
+ */
110
+ sendInputToProcess(pid, input) {
111
+ const session = this.sessions.get(pid);
112
+ if (!session) {
113
+ return false;
114
+ }
115
+ try {
116
+ if (session.process.stdin && !session.process.stdin.destroyed) {
117
+ // Ensure input ends with a newline for most REPLs
118
+ const inputWithNewline = input.endsWith('\n') ? input : input + '\n';
119
+ session.process.stdin.write(inputWithNewline);
120
+ return true;
121
+ }
122
+ return false;
123
+ }
124
+ catch (error) {
125
+ console.error(`Error sending input to process ${pid}:`, error);
126
+ return false;
127
+ }
128
+ }
129
+ async executeCommand(command, timeoutMs = DEFAULT_COMMAND_TIMEOUT, shell, collectTiming = false) {
130
+ // Get the shell from config if not specified
131
+ let shellToUse = shell;
132
+ if (!shellToUse) {
133
+ try {
134
+ const config = await configManager.getConfig();
135
+ shellToUse = config.defaultShell || true;
136
+ }
137
+ catch (error) {
138
+ // If there's an error getting the config, fall back to default
139
+ shellToUse = true;
140
+ }
141
+ }
142
+ // For REPL interactions, we need to ensure stdin, stdout, and stderr are properly configured
143
+ // Note: No special stdio options needed here, Node.js handles pipes by default
144
+ // Enhance SSH commands automatically
145
+ let enhancedCommand = command;
146
+ if (command.trim().startsWith('ssh ') && !command.includes(' -t')) {
147
+ enhancedCommand = command.replace(/^ssh /, 'ssh -t ');
148
+ // Do not print the command: SSH arguments can contain credentials.
149
+ }
150
+ // Get the appropriate spawn configuration for the shell
151
+ let spawnConfig;
152
+ let spawnOptions;
153
+ if (typeof shellToUse === 'string') {
154
+ // Use shell-specific configuration with login flags where appropriate
155
+ spawnConfig = getShellSpawnArgs(shellToUse, enhancedCommand);
156
+ spawnOptions = {
157
+ env: {
158
+ ...process.env,
159
+ TERM: 'xterm-256color' // Better terminal compatibility
160
+ },
161
+ windowsHide: true // Prevent visible console windows on Windows
162
+ };
163
+ // Add shell option if needed (for unknown shells)
164
+ if (spawnConfig.useShellOption) {
165
+ spawnOptions.shell = spawnConfig.useShellOption;
166
+ }
167
+ }
168
+ else {
169
+ // Boolean or undefined shell - use default shell option behavior
170
+ spawnConfig = {
171
+ executable: enhancedCommand,
172
+ args: [],
173
+ useShellOption: shellToUse
174
+ };
175
+ spawnOptions = {
176
+ shell: shellToUse,
177
+ env: {
178
+ ...process.env,
179
+ TERM: 'xterm-256color'
180
+ },
181
+ windowsHide: true // Prevent visible console windows on Windows
182
+ };
183
+ }
184
+ // Repair PATHEXT on Windows before spawning. On some Windows DXT launches
185
+ // the server process inherits a corrupted PATHEXT (e.g. ".CPL"), which we
186
+ // would otherwise propagate via { ...process.env } and break command
187
+ // resolution (git, node, python, rg, ...) in the spawned shell. See #481.
188
+ if (process.platform === 'win32' && spawnOptions.env) {
189
+ spawnOptions.env.PATHEXT = getRepairedPathExt();
190
+ }
191
+ // On Windows, when we invoke cmd.exe directly and pass the user's command as a
192
+ // single argument, Node/libuv applies MSVCRT-style quoting that escapes embedded
193
+ // double quotes as \" . cmd.exe does not understand that escaping, so any command
194
+ // containing quotes (e.g. a quoted path with spaces like "C:\Program Files\app.exe")
195
+ // is corrupted before the shell ever parses it. Passing arguments verbatim lets
196
+ // cmd handle its own quoting. Scoped to shells that set windowsVerbatim (cmd only)
197
+ // because PowerShell/pwsh have different quote rules and must NOT use verbatim.
198
+ if (process.platform === 'win32' && spawnConfig.windowsVerbatim) {
199
+ spawnOptions.windowsVerbatimArguments = true;
200
+ }
201
+ // Spawn the process with appropriate arguments
202
+ const childProcess = spawn(spawnConfig.executable, spawnConfig.args, spawnOptions);
203
+ let output = '';
204
+ // spawn() reports failure asynchronously via an 'error' event; it does not
205
+ // throw. Node rethrows an 'error' that has no listener as an uncaught
206
+ // exception, and our process-level handler (src/index.ts) turns that into
207
+ // process.exit(1). So an unresolvable executable — e.g. shell: "/usr/bin/bash"
208
+ // on Windows — used to kill the entire MCP server one tick AFTER this
209
+ // function had already returned "Failed to get process ID", making the crash
210
+ // look unrelated to the command that caused it. Under `remote` the parent
211
+ // then kept accepting tool calls over a dead stdio pipe ("Not connected").
212
+ //
213
+ // Attach before any return path below, and keep it for the session lifetime
214
+ // so a later runtime error (EPIPE on a closed stdin, ...) can't crash us either.
215
+ let forwardProcessError = null;
216
+ let pendingProcessError = null;
217
+ childProcess.on('error', (err) => {
218
+ if (forwardProcessError) {
219
+ forwardProcessError(err);
220
+ }
221
+ else {
222
+ pendingProcessError = err;
223
+ console.error(`Process error for "${command}": ${err.message}`);
224
+ }
225
+ });
226
+ // Ensure childProcess.pid is defined before proceeding
227
+ if (!childProcess.pid) {
228
+ // Return a consistent error object instead of throwing
229
+ return {
230
+ pid: -1, // Use -1 to indicate an error state
231
+ output: 'Error: Failed to get process ID. The command could not be executed.',
232
+ isBlocked: false
233
+ };
234
+ }
235
+ const session = {
236
+ pid: childProcess.pid,
237
+ process: childProcess,
238
+ outputLines: [], // Line-based buffer
239
+ lastReadIndex: 0, // Track where "new" output starts
240
+ isBlocked: false,
241
+ startTime: new Date(),
242
+ bufferedChars: 0,
243
+ evictedLines: 0,
244
+ evictedChars: 0
245
+ };
246
+ this.sessions.set(childProcess.pid, session);
247
+ // Timing telemetry
248
+ const startTime = Date.now();
249
+ let firstOutputTime;
250
+ let lastOutputTime;
251
+ const outputEvents = [];
252
+ let exitReason = 'timeout';
253
+ return new Promise((resolve) => {
254
+ let resolved = false;
255
+ let periodicCheck = null;
256
+ // Quick prompt patterns for immediate detection
257
+ const quickPromptPatterns = />>>\s*$|>\s*$|\$\s*$|#\s*$/;
258
+ const resolveOnce = (result) => {
259
+ if (resolved)
260
+ return;
261
+ resolved = true;
262
+ if (periodicCheck)
263
+ clearInterval(periodicCheck);
264
+ // Add timing info if requested
265
+ if (collectTiming) {
266
+ const endTime = Date.now();
267
+ result.timingInfo = {
268
+ startTime,
269
+ endTime,
270
+ totalDurationMs: endTime - startTime,
271
+ exitReason,
272
+ firstOutputTime,
273
+ lastOutputTime,
274
+ timeToFirstOutputMs: firstOutputTime ? firstOutputTime - startTime : undefined,
275
+ outputEvents: outputEvents.length > 0 ? outputEvents : undefined
276
+ };
277
+ }
278
+ resolve(result);
279
+ };
280
+ // Now that resolveOnce exists, route process errors into it: an error after
281
+ // a successful spawn means the process is gone, so the caller must not sit
282
+ // waiting for output that will never arrive.
283
+ forwardProcessError = (err) => {
284
+ this.sessions.delete(childProcess.pid);
285
+ exitReason = 'process_exit';
286
+ resolveOnce({
287
+ pid: childProcess.pid,
288
+ output: output + `\nProcess error: ${err.message}`,
289
+ isBlocked: false
290
+ });
291
+ };
292
+ // An error emitted between spawn and here (the common case — spawn errors
293
+ // land on the next tick) is replayed rather than dropped.
294
+ if (pendingProcessError) {
295
+ forwardProcessError(pendingProcessError);
296
+ }
297
+ childProcess.stdout.on('data', (data) => {
298
+ const text = data.toString();
299
+ const now = Date.now();
300
+ if (!firstOutputTime)
301
+ firstOutputTime = now;
302
+ lastOutputTime = now;
303
+ // `output` only feeds the wait-phase result and prompt/state detection,
304
+ // so stop growing it once resolved and keep only a bounded tail.
305
+ if (!resolved) {
306
+ output += text;
307
+ if (output.length > MAX_WAIT_OUTPUT_CHARS) {
308
+ output = output.slice(-Math.floor(MAX_WAIT_OUTPUT_CHARS / 2));
309
+ }
310
+ }
311
+ // Append to line-based buffer
312
+ this.appendToLineBuffer(session, text);
313
+ // Record output event if collecting timing
314
+ if (collectTiming) {
315
+ outputEvents.push({
316
+ timestamp: now,
317
+ deltaMs: now - startTime,
318
+ source: 'stdout',
319
+ length: text.length,
320
+ snippet: text.slice(0, 50).replace(/\n/g, '\\n')
321
+ });
322
+ }
323
+ // Immediate check for obvious prompts
324
+ if (quickPromptPatterns.test(text)) {
325
+ session.isBlocked = true;
326
+ exitReason = 'early_exit_quick_pattern';
327
+ if (collectTiming && outputEvents.length > 0) {
328
+ outputEvents[outputEvents.length - 1].matchedPattern = 'quick_pattern';
329
+ }
330
+ resolveOnce({
331
+ pid: childProcess.pid,
332
+ output,
333
+ isBlocked: true
334
+ });
335
+ }
336
+ });
337
+ childProcess.stderr.on('data', (data) => {
338
+ const text = data.toString();
339
+ const now = Date.now();
340
+ if (!firstOutputTime)
341
+ firstOutputTime = now;
342
+ lastOutputTime = now;
343
+ if (!resolved) {
344
+ output += text;
345
+ if (output.length > MAX_WAIT_OUTPUT_CHARS) {
346
+ output = output.slice(-Math.floor(MAX_WAIT_OUTPUT_CHARS / 2));
347
+ }
348
+ }
349
+ // Append to line-based buffer
350
+ this.appendToLineBuffer(session, text);
351
+ // Record output event if collecting timing
352
+ if (collectTiming) {
353
+ outputEvents.push({
354
+ timestamp: now,
355
+ deltaMs: now - startTime,
356
+ source: 'stderr',
357
+ length: text.length,
358
+ snippet: text.slice(0, 50).replace(/\n/g, '\\n')
359
+ });
360
+ }
361
+ });
362
+ // Periodic comprehensive check every 100ms
363
+ periodicCheck = setInterval(() => {
364
+ if (output.trim()) {
365
+ const processState = analyzeProcessState(output, childProcess.pid);
366
+ if (processState.isWaitingForInput) {
367
+ session.isBlocked = true;
368
+ exitReason = 'early_exit_periodic_check';
369
+ resolveOnce({
370
+ pid: childProcess.pid,
371
+ output,
372
+ isBlocked: true
373
+ });
374
+ }
375
+ }
376
+ }, 100);
377
+ // Timeout fallback
378
+ setTimeout(() => {
379
+ session.isBlocked = true;
380
+ exitReason = 'timeout';
381
+ resolveOnce({
382
+ pid: childProcess.pid,
383
+ output,
384
+ isBlocked: true
385
+ });
386
+ }, timeoutMs);
387
+ childProcess.on('exit', (code) => {
388
+ if (childProcess.pid) {
389
+ // Store completed session before removing active session
390
+ this.completedSessions.set(childProcess.pid, {
391
+ pid: childProcess.pid,
392
+ outputLines: [...session.outputLines], // Copy line buffer
393
+ exitCode: code,
394
+ startTime: session.startTime,
395
+ endTime: new Date(),
396
+ evictedLines: session.evictedLines,
397
+ evictedChars: session.evictedChars
398
+ });
399
+ // Keep only last 100 completed sessions
400
+ if (this.completedSessions.size > 100) {
401
+ const oldestKey = Array.from(this.completedSessions.keys())[0];
402
+ this.completedSessions.delete(oldestKey);
403
+ }
404
+ this.sessions.delete(childProcess.pid);
405
+ }
406
+ exitReason = 'process_exit';
407
+ resolveOnce({
408
+ pid: childProcess.pid,
409
+ output,
410
+ isBlocked: false
411
+ });
412
+ });
413
+ });
414
+ }
415
+ /**
416
+ * Append text to a session's line buffer
417
+ * Handles partial lines and newline splitting
418
+ */
419
+ appendToLineBuffer(session, text) {
420
+ if (!text)
421
+ return;
422
+ // Split text into lines, keeping track of whether text ends with newline
423
+ const lines = text.split('\n');
424
+ for (let i = 0; i < lines.length; i++) {
425
+ const line = lines[i];
426
+ const isLastFragment = i === lines.length - 1;
427
+ const endsWithNewline = text.endsWith('\n');
428
+ if (session.outputLines.length === 0) {
429
+ // First line ever
430
+ session.outputLines.push(line);
431
+ }
432
+ else if (i === 0) {
433
+ // First fragment - append to last line (might be partial)
434
+ session.outputLines[session.outputLines.length - 1] += line;
435
+ }
436
+ else {
437
+ // Subsequent lines - add as new lines
438
+ session.outputLines.push(line);
439
+ }
440
+ }
441
+ // Appended text contributes exactly its length to the joined buffer
442
+ // (its newlines become the join separators).
443
+ session.bufferedChars += text.length;
444
+ // A process printing without newlines grows a single line forever, which
445
+ // eviction can't bound — force-split so no line exceeds MAX_LINE_CHARS.
446
+ // Each inserted break adds one separator to the joined length.
447
+ let lastIndex = session.outputLines.length - 1;
448
+ while (session.outputLines[lastIndex].length > MAX_LINE_CHARS) {
449
+ const overlong = session.outputLines[lastIndex];
450
+ session.outputLines[lastIndex] = overlong.slice(0, MAX_LINE_CHARS);
451
+ session.outputLines.push(overlong.slice(MAX_LINE_CHARS));
452
+ session.bufferedChars += 1;
453
+ lastIndex++;
454
+ }
455
+ // Enforce the per-session cap by evicting the oldest lines. Keeps the
456
+ // buffer far below V8's max string length so concatenation and join()
457
+ // can never throw "Invalid string length" and kill the server.
458
+ while (session.bufferedChars > MAX_BUFFERED_OUTPUT_CHARS && session.outputLines.length > 1) {
459
+ const dropped = session.outputLines.shift();
460
+ const droppedJoinedChars = dropped.length + 1; // +1 for its join separator
461
+ session.bufferedChars -= droppedJoinedChars;
462
+ session.evictedChars += droppedJoinedChars;
463
+ session.evictedLines++;
464
+ if (session.lastReadIndex > 0)
465
+ session.lastReadIndex--;
466
+ }
467
+ }
468
+ /**
469
+ * Read process output with pagination (like file reading)
470
+ * @param pid Process ID
471
+ * @param offset Line offset: 0=from lastReadIndex, positive=absolute, negative=tail
472
+ * @param length Max lines to return
473
+ * @param updateReadIndex Whether to update lastReadIndex (default: true for offset=0)
474
+ */
475
+ readOutputPaginated(pid, offset = 0, length = 1000) {
476
+ // First check active sessions
477
+ const session = this.sessions.get(pid);
478
+ if (session) {
479
+ const result = this.readFromLineBuffer(session.outputLines, offset, length, session.lastReadIndex, (newIndex) => { session.lastReadIndex = newIndex; }, false, undefined);
480
+ result.evictedLines = session.evictedLines;
481
+ return result;
482
+ }
483
+ // Then check completed sessions
484
+ const completedSession = this.completedSessions.get(pid);
485
+ if (completedSession) {
486
+ const runtimeMs = completedSession.endTime.getTime() - completedSession.startTime.getTime();
487
+ const result = this.readFromLineBuffer(completedSession.outputLines, offset, length, 0, // Completed sessions don't track read position
488
+ () => { }, // No-op for completed sessions
489
+ true, completedSession.exitCode, runtimeMs);
490
+ result.evictedLines = completedSession.evictedLines;
491
+ return result;
492
+ }
493
+ return null;
494
+ }
495
+ /**
496
+ * Internal helper to read from a line buffer with offset/length
497
+ */
498
+ readFromLineBuffer(lines, offset, length, lastReadIndex, updateLastRead, isComplete, exitCode, runtimeMs) {
499
+ const totalLines = lines.length;
500
+ let startIndex;
501
+ let linesToRead;
502
+ if (offset < 0) {
503
+ // Negative offset = start position from end, then read 'length' lines forward
504
+ // e.g., offset=-50, length=10 means: start 50 lines from end, read 10 lines
505
+ const fromEnd = Math.abs(offset);
506
+ startIndex = Math.max(0, totalLines - fromEnd);
507
+ linesToRead = lines.slice(startIndex, startIndex + length);
508
+ // Don't update lastReadIndex for tail reads
509
+ }
510
+ else if (offset === 0) {
511
+ // offset=0 means "from where I last read" (like getNewOutput)
512
+ startIndex = lastReadIndex;
513
+ linesToRead = lines.slice(startIndex, startIndex + length);
514
+ // Update lastReadIndex for "new output" behavior
515
+ updateLastRead(Math.min(startIndex + linesToRead.length, totalLines));
516
+ }
517
+ else {
518
+ // Positive offset = absolute position
519
+ startIndex = offset;
520
+ linesToRead = lines.slice(startIndex, startIndex + length);
521
+ // Don't update lastReadIndex for absolute position reads
522
+ }
523
+ const readCount = linesToRead.length;
524
+ const endIndex = startIndex + readCount;
525
+ const remaining = Math.max(0, totalLines - endIndex);
526
+ return {
527
+ lines: linesToRead,
528
+ totalLines,
529
+ readFrom: startIndex,
530
+ readCount,
531
+ remaining,
532
+ isComplete,
533
+ exitCode,
534
+ runtimeMs
535
+ };
536
+ }
537
+ /**
538
+ * Get total line count for a process
539
+ */
540
+ getOutputLineCount(pid) {
541
+ const session = this.sessions.get(pid);
542
+ if (session) {
543
+ return session.outputLines.length;
544
+ }
545
+ const completedSession = this.completedSessions.get(pid);
546
+ if (completedSession) {
547
+ return completedSession.outputLines.length;
548
+ }
549
+ return null;
550
+ }
551
+ /**
552
+ * Legacy method for backward compatibility
553
+ * Returns all new output since last read
554
+ * @param maxLines Maximum lines to return (default: 1000 for context protection)
555
+ * @deprecated Use readOutputPaginated instead
556
+ */
557
+ getNewOutput(pid, maxLines = 1000) {
558
+ const result = this.readOutputPaginated(pid, 0, maxLines);
559
+ if (!result)
560
+ return null;
561
+ const output = result.lines.join('\n').trim();
562
+ // For completed sessions, append completion info with runtime
563
+ if (result.isComplete) {
564
+ const runtimeStr = result.runtimeMs !== undefined
565
+ ? `\nRuntime: ${(result.runtimeMs / 1000).toFixed(2)}s`
566
+ : '';
567
+ if (output) {
568
+ return `${output}\n\nProcess completed with exit code ${result.exitCode}${runtimeStr}`;
569
+ }
570
+ else {
571
+ return `Process completed with exit code ${result.exitCode}${runtimeStr}\n(No output produced)`;
572
+ }
573
+ }
574
+ // Add truncation warning if there's more output
575
+ if (result.remaining > 0) {
576
+ return `${output}\n\n[Output truncated: ${result.remaining} more lines available. Use read_process_output with offset/length for full output.]`;
577
+ }
578
+ return output || null;
579
+ }
580
+ /**
581
+ * Capture a snapshot of current output state for interaction tracking.
582
+ * Used by interactWithProcess to know what output existed before sending input.
583
+ */
584
+ captureOutputSnapshot(pid) {
585
+ const session = this.sessions.get(pid);
586
+ if (session) {
587
+ const fullOutput = session.outputLines.join('\n');
588
+ return {
589
+ // Absolute since process start (includes evicted output), so the
590
+ // offset stays valid even if the cap evicts lines between
591
+ // snapshot and read.
592
+ totalChars: session.evictedChars + fullOutput.length,
593
+ lineCount: session.evictedLines + session.outputLines.length
594
+ };
595
+ }
596
+ return null;
597
+ }
598
+ /**
599
+ * Get output that appeared since a snapshot was taken.
600
+ * This handles the case where output is appended to the last line (REPL prompts).
601
+ * Also checks completed sessions in case process finished between snapshot and poll.
602
+ */
603
+ getOutputSinceSnapshot(pid, snapshot) {
604
+ // Check active session first
605
+ const session = this.sessions.get(pid);
606
+ if (session) {
607
+ return TerminalManager.outputSinceSnapshot(session.outputLines, session.evictedChars, snapshot.totalChars);
608
+ }
609
+ // Fallback to completed sessions - process may have finished between snapshot and poll
610
+ const completedSession = this.completedSessions.get(pid);
611
+ if (completedSession) {
612
+ return TerminalManager.outputSinceSnapshot(completedSession.outputLines, completedSession.evictedChars, snapshot.totalChars);
613
+ }
614
+ return null;
615
+ }
616
+ /**
617
+ * New output since a snapshot, in absolute (since process start) offsets.
618
+ * If eviction dropped part of the unseen output, returns what the buffer
619
+ * still holds — the oldest unseen chars are lost to the cap.
620
+ */
621
+ static outputSinceSnapshot(outputLines, evictedChars, snapshotTotalChars) {
622
+ const fullOutput = outputLines.join('\n');
623
+ const newChars = evictedChars + fullOutput.length - snapshotTotalChars;
624
+ if (newChars <= 0) {
625
+ return ''; // No new output
626
+ }
627
+ return fullOutput.substring(Math.max(0, fullOutput.length - newChars));
628
+ }
629
+ /**
630
+ * Get a session by PID
631
+ * @param pid Process ID
632
+ * @returns The session or undefined if not found
633
+ */
634
+ getSession(pid) {
635
+ return this.sessions.get(pid);
636
+ }
637
+ forceTerminate(pid) {
638
+ const session = this.sessions.get(pid);
639
+ if (!session) {
640
+ return false;
641
+ }
642
+ try {
643
+ session.process.kill('SIGINT');
644
+ setTimeout(() => {
645
+ if (this.sessions.has(pid)) {
646
+ session.process.kill('SIGKILL');
647
+ }
648
+ }, 1000);
649
+ return true;
650
+ }
651
+ catch (error) {
652
+ // Convert error to string, handling both Error objects and other types
653
+ const errorMessage = error instanceof Error ? error.message : String(error);
654
+ capture('server_request_error', { error: errorMessage, message: `Failed to terminate process ${pid}:` });
655
+ return false;
656
+ }
657
+ }
658
+ listActiveSessions() {
659
+ const now = new Date();
660
+ return Array.from(this.sessions.values()).map(session => ({
661
+ pid: session.pid,
662
+ isBlocked: session.isBlocked,
663
+ runtime: now.getTime() - session.startTime.getTime()
664
+ }));
665
+ }
666
+ listCompletedSessions() {
667
+ return Array.from(this.completedSessions.values());
668
+ }
669
+ }
670
+ export const terminalManager = new TerminalManager();
671
+ //# sourceMappingURL=terminal-manager.js.map