@codingame/monaco-vscode-chat-service-override 19.1.4 → 20.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (211) hide show
  1. package/index.js +20 -8
  2. package/package.json +36 -31
  3. package/vscode/src/vs/base/common/policy.d.ts +14 -0
  4. package/vscode/src/vs/base/common/policy.js +11 -0
  5. package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatAccessibilityHelp.js +53 -43
  6. package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatClearActions.js +54 -24
  7. package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatCodeblockActions.d.ts +2 -2
  8. package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatCodeblockActions.js +14 -14
  9. package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatContext.js +15 -15
  10. package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatContextActions.js +37 -25
  11. package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatCopyActions.js +4 -4
  12. package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatDeveloperActions.js +2 -2
  13. package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatFileTreeActions.js +4 -4
  14. package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatGettingStarted.js +1 -1
  15. package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatImportExport.js +6 -6
  16. package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatLanguageModelActions.js +23 -11
  17. package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatMoveActions.js +9 -9
  18. package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatQuickInputActions.d.ts +1 -1
  19. package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatQuickInputActions.js +11 -11
  20. package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatToolActions.js +83 -14
  21. package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatToolPicker.js +421 -21
  22. package/vscode/src/vs/workbench/contrib/chat/browser/actions/codeBlockOperations.d.ts +1 -1
  23. package/vscode/src/vs/workbench/contrib/chat/browser/actions/codeBlockOperations.js +20 -20
  24. package/vscode/src/vs/workbench/contrib/chat/browser/chat.contribution.js +215 -104
  25. package/vscode/src/vs/workbench/contrib/chat/browser/chatAccessibilityService.d.ts +3 -1
  26. package/vscode/src/vs/workbench/contrib/chat/browser/chatAccessibilityService.js +9 -3
  27. package/vscode/src/vs/workbench/contrib/chat/browser/chatAttachmentResolveService.d.ts +3 -1
  28. package/vscode/src/vs/workbench/contrib/chat/browser/chatAttachmentResolveService.js +18 -6
  29. package/vscode/src/vs/workbench/contrib/chat/browser/chatContentParts/chatMarkdownAnchorService.d.ts +1 -1
  30. package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingCodeEditorIntegration.js +4 -4
  31. package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingEditorActions.js +20 -20
  32. package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingEditorOverlay.js +14 -14
  33. package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingModifiedDocumentEntry.d.ts +1 -1
  34. package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingModifiedDocumentEntry.js +6 -3
  35. package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingModifiedFileEntry.d.ts +4 -2
  36. package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingModifiedFileEntry.js +9 -6
  37. package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingModifiedNotebookEntry.d.ts +1 -1
  38. package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingModifiedNotebookEntry.js +11 -8
  39. package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingServiceImpl.d.ts +5 -3
  40. package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingServiceImpl.js +16 -11
  41. package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingSession.d.ts +7 -23
  42. package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingSession.js +58 -326
  43. package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingSessionStorage.d.ts +0 -1
  44. package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingSessionStorage.js +33 -30
  45. package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingTextModelChangeService.d.ts +12 -1
  46. package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingTextModelChangeService.js +39 -17
  47. package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingTimeline.d.ts +55 -0
  48. package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingTimeline.js +380 -0
  49. package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/notebook/chatEditingModifiedNotebookSnapshot.js +3 -2
  50. package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/notebook/chatEditingNotebookCellEntry.d.ts +1 -1
  51. package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/notebook/chatEditingNotebookCellEntry.js +1 -1
  52. package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/notebook/chatEditingNotebookEditorIntegration.js +5 -5
  53. package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/notebook/notebookCellChanges.js +4 -2
  54. package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/notebook/overlayToolbarDecorator.d.ts +1 -1
  55. package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/notebook/overlayToolbarDecorator.js +1 -1
  56. package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/simpleBrowserEditorOverlay.js +22 -22
  57. package/vscode/src/vs/workbench/contrib/chat/browser/chatEditor.d.ts +9 -4
  58. package/vscode/src/vs/workbench/contrib/chat/browser/chatEditor.js +44 -10
  59. package/vscode/src/vs/workbench/contrib/chat/browser/chatOutputItemRenderer.d.ts +38 -0
  60. package/vscode/src/vs/workbench/contrib/chat/browser/chatOutputItemRenderer.js +145 -0
  61. package/vscode/src/vs/workbench/contrib/chat/browser/chatParticipant.contribution.js +34 -34
  62. package/vscode/src/vs/workbench/contrib/chat/browser/chatPasteProviders.js +7 -7
  63. package/vscode/src/vs/workbench/contrib/chat/browser/chatQuick.d.ts +1 -1
  64. package/vscode/src/vs/workbench/contrib/chat/browser/chatQuick.js +3 -3
  65. package/vscode/src/vs/workbench/contrib/chat/browser/chatResponseAccessibleView.d.ts +1 -1
  66. package/vscode/src/vs/workbench/contrib/chat/browser/chatResponseAccessibleView.js +36 -11
  67. package/vscode/src/vs/workbench/contrib/chat/browser/chatSessions.contribution.d.ts +49 -0
  68. package/vscode/src/vs/workbench/contrib/chat/browser/chatSessions.contribution.js +407 -0
  69. package/vscode/src/vs/workbench/contrib/chat/browser/chatSessions.d.ts +12 -0
  70. package/vscode/src/vs/workbench/contrib/chat/browser/chatSessions.js +738 -0
  71. package/vscode/src/vs/workbench/contrib/chat/browser/chatSetup.d.ts +1 -1
  72. package/vscode/src/vs/workbench/contrib/chat/browser/chatSetup.js +142 -151
  73. package/vscode/src/vs/workbench/contrib/chat/browser/chatStatus.d.ts +1 -1
  74. package/vscode/src/vs/workbench/contrib/chat/browser/chatStatus.js +54 -54
  75. package/vscode/src/vs/workbench/contrib/chat/browser/chatVariables.js +20 -0
  76. package/vscode/src/vs/workbench/contrib/chat/browser/chatViewPane.d.ts +4 -3
  77. package/vscode/src/vs/workbench/contrib/chat/browser/chatViewPane.js +5 -4
  78. package/vscode/src/vs/workbench/contrib/chat/browser/codeBlockContextProviderService.d.ts +1 -1
  79. package/vscode/src/vs/workbench/contrib/chat/browser/contrib/chatInputEditorContrib.js +23 -7
  80. package/vscode/src/vs/workbench/contrib/chat/browser/contrib/chatInputEditorHover.d.ts +1 -1
  81. package/vscode/src/vs/workbench/contrib/chat/browser/contrib/chatInputEditorHover.js +3 -3
  82. package/vscode/src/vs/workbench/contrib/chat/browser/languageModelToolsService.d.ts +1 -0
  83. package/vscode/src/vs/workbench/contrib/chat/browser/languageModelToolsService.js +13 -8
  84. package/vscode/src/vs/workbench/contrib/chat/browser/media/apple-dark.svg +3 -0
  85. package/vscode/src/vs/workbench/contrib/chat/browser/media/apple-light.svg +3 -0
  86. package/vscode/src/vs/workbench/contrib/chat/browser/media/chatSessions.css +28 -0
  87. package/vscode/src/vs/workbench/contrib/chat/browser/media/chatSetup.css +7 -7
  88. package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/attachInstructionsAction.d.ts +2 -2
  89. package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/attachInstructionsAction.js +14 -14
  90. package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/chatModeActions.js +8 -8
  91. package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/newPromptFileActions.js +10 -10
  92. package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/pickers/askForPromptName.d.ts +1 -1
  93. package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/pickers/askForPromptName.js +11 -11
  94. package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/pickers/askForPromptSourceFolder.d.ts +1 -1
  95. package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/pickers/askForPromptSourceFolder.js +19 -19
  96. package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/pickers/promptFilePickers.d.ts +1 -1
  97. package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/pickers/promptFilePickers.js +14 -14
  98. package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/promptCodingAgentActionContribution.js +1 -1
  99. package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/promptCodingAgentActionOverlay.js +3 -3
  100. package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/promptToolsCodeLensProvider.js +4 -4
  101. package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/promptUrlHandler.js +10 -10
  102. package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/runPromptAction.js +11 -11
  103. package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/saveToPromptAction.d.ts +1 -7
  104. package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/saveToPromptAction.js +52 -90
  105. package/vscode/src/vs/workbench/contrib/chat/browser/tools/toolSetsContribution.js +15 -15
  106. package/vscode/src/vs/workbench/contrib/chat/browser/viewsWelcome/chatViewsWelcomeHandler.js +6 -6
  107. package/vscode/src/vs/workbench/contrib/chat/common/chatProgressTypes/chatToolInvocation.d.ts +2 -2
  108. package/vscode/src/vs/workbench/contrib/chat/common/chatProgressTypes/chatToolInvocation.js +6 -2
  109. package/vscode/src/vs/workbench/contrib/chat/common/chatResponseResourceFileSystemProvider.js +9 -6
  110. package/vscode/src/vs/workbench/contrib/chat/common/chatServiceImpl.d.ts +11 -6
  111. package/vscode/src/vs/workbench/contrib/chat/common/chatServiceImpl.js +137 -30
  112. package/vscode/src/vs/workbench/contrib/chat/common/chatServiceTelemetry.js +8 -0
  113. package/vscode/src/vs/workbench/contrib/chat/common/chatSessionStore.d.ts +1 -1
  114. package/vscode/src/vs/workbench/contrib/chat/common/chatSessionStore.js +3 -3
  115. package/vscode/src/vs/workbench/contrib/chat/common/chatTodoListService.d.ts +27 -0
  116. package/vscode/src/vs/workbench/contrib/chat/common/chatTodoListService.js +44 -0
  117. package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/config/configMigration.js +1 -1
  118. package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/contentProviders/filePromptContentsProvider.js +2 -2
  119. package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/contentProviders/promptContentsProviderBase.d.ts +1 -1
  120. package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/contentProviders/promptContentsProviderBase.js +1 -1
  121. package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/languageProviders/promptHeaderAutocompletion.js +1 -1
  122. package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/languageProviders/promptHeaderDiagnosticsProvider.js +3 -5
  123. package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/languageProviders/promptHeaderHovers.js +14 -14
  124. package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/languageProviders/promptLinkDiagnosticsProvider.js +1 -1
  125. package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/languageProviders/promptPathAutocompletion.js +1 -1
  126. package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/languageProviders/providerInstanceManagerBase.js +2 -2
  127. package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/parsers/basePromptParser.js +1 -1
  128. package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/parsers/promptHeader/headerBase.js +4 -4
  129. package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/parsers/promptHeader/instructionsHeader.d.ts +1 -1
  130. package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/parsers/promptHeader/metadata/applyTo.js +3 -3
  131. package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/parsers/promptHeader/metadata/base/enum.js +1 -1
  132. package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/parsers/promptHeader/metadata/base/string.js +1 -1
  133. package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/parsers/promptHeader/metadata/tools.js +4 -4
  134. package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/parsers/promptHeader/modeHeader.d.ts +1 -1
  135. package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/parsers/promptHeader/promptHeader.d.ts +1 -1
  136. package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/parsers/promptHeader/promptHeader.js +1 -1
  137. package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/parsers/topError.js +9 -9
  138. package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/service/promptsServiceImpl.d.ts +1 -1
  139. package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/service/promptsServiceImpl.js +8 -8
  140. package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/utils/promptFilesLocator.d.ts +1 -1
  141. package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/utils/promptFilesLocator.js +2 -2
  142. package/vscode/src/vs/workbench/contrib/chat/common/tools/languageModelToolsContribution.js +27 -27
  143. package/vscode/src/vs/workbench/contrib/chat/common/voiceChatService.d.ts +1 -1
  144. package/vscode/src/vs/workbench/contrib/chat/common/voiceChatService.js +2 -2
  145. package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChat.contribution.js +9 -9
  146. package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatAccessibilityHelp.js +1 -1
  147. package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatAccessibleView.js +4 -4
  148. package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatActions.d.ts +104 -0
  149. package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatActions.js +667 -0
  150. package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatCurrentLine.js +14 -14
  151. package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatNotebook.js +1 -1
  152. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookModifiedCellDecorator.d.ts +1 -1
  153. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookModifiedCellDecorator.js +2 -2
  154. package/vscode/src/vs/workbench/contrib/remoteCodingAgents/browser/remoteCodingAgents.contribution.js +7 -7
  155. package/vscode/src/vs/workbench/contrib/terminalContrib/chat/browser/media/terminalChatWidget.css +56 -0
  156. package/vscode/src/vs/workbench/contrib/terminalContrib/chat/browser/terminal.chat.contribution.d.ts +1 -0
  157. package/vscode/src/vs/workbench/contrib/terminalContrib/chat/browser/terminal.chat.contribution.js +14 -0
  158. package/vscode/src/vs/workbench/contrib/terminalContrib/chat/browser/terminalChatAccessibilityHelp.d.ts +11 -0
  159. package/vscode/src/vs/workbench/contrib/terminalContrib/chat/browser/terminalChatAccessibilityHelp.js +111 -0
  160. package/vscode/src/vs/workbench/contrib/terminalContrib/chat/browser/terminalChatAccessibleView.d.ts +10 -0
  161. package/vscode/src/vs/workbench/contrib/terminalContrib/chat/browser/terminalChatAccessibleView.js +52 -0
  162. package/vscode/src/vs/workbench/contrib/terminalContrib/chat/browser/terminalChatActions.d.ts +1 -0
  163. package/vscode/src/vs/workbench/contrib/terminalContrib/chat/browser/terminalChatActions.js +262 -0
  164. package/vscode/src/vs/workbench/contrib/terminalContrib/chat/browser/terminalChatController.d.ts +35 -0
  165. package/vscode/src/vs/workbench/contrib/terminalContrib/chat/browser/terminalChatController.js +129 -0
  166. package/vscode/src/vs/workbench/contrib/terminalContrib/chat/browser/terminalChatControllerHolder.d.ts +3 -0
  167. package/vscode/src/vs/workbench/contrib/terminalContrib/chat/browser/terminalChatControllerHolder.js +8 -0
  168. package/vscode/src/vs/workbench/contrib/terminalContrib/chat/browser/terminalChatEnabler.d.ts +9 -0
  169. package/vscode/src/vs/workbench/contrib/terminalContrib/chat/browser/terminalChatEnabler.js +30 -0
  170. package/vscode/src/vs/workbench/contrib/terminalContrib/chat/browser/terminalChatWidget.d.ts +72 -0
  171. package/vscode/src/vs/workbench/contrib/terminalContrib/chat/browser/terminalChatWidget.js +411 -0
  172. package/vscode/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/alternativeRecommendation.d.ts +3 -0
  173. package/vscode/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/alternativeRecommendation.js +59 -0
  174. package/vscode/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/bufferOutputPolling.d.ts +51 -0
  175. package/vscode/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/bufferOutputPolling.js +163 -0
  176. package/vscode/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/commandLineAutoApprover.d.ts +24 -0
  177. package/vscode/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/commandLineAutoApprover.js +164 -0
  178. package/vscode/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/executeStrategy/basicExecuteStrategy.d.ts +14 -0
  179. package/vscode/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/executeStrategy/basicExecuteStrategy.js +101 -0
  180. package/vscode/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/executeStrategy/executeStrategy.d.ts +16 -0
  181. package/vscode/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/executeStrategy/executeStrategy.js +52 -0
  182. package/vscode/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/executeStrategy/noneExecuteStrategy.d.ts +12 -0
  183. package/vscode/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/executeStrategy/noneExecuteStrategy.js +71 -0
  184. package/vscode/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/executeStrategy/richExecuteStrategy.d.ts +14 -0
  185. package/vscode/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/executeStrategy/richExecuteStrategy.js +94 -0
  186. package/vscode/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/getTerminalOutputTool.d.ts +11 -0
  187. package/vscode/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/getTerminalOutputTool.js +44 -0
  188. package/vscode/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/outputHelpers.d.ts +3 -0
  189. package/vscode/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/outputHelpers.js +18 -0
  190. package/vscode/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/runInTerminalHelpers.d.ts +3 -0
  191. package/vscode/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/runInTerminalHelpers.js +13 -0
  192. package/vscode/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/runInTerminalTool.d.ts +55 -0
  193. package/vscode/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/runInTerminalTool.js +603 -0
  194. package/vscode/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/subCommands.d.ts +3 -0
  195. package/vscode/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/subCommands.js +113 -0
  196. package/vscode/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/task/createAndRunTaskTool.d.ts +21 -0
  197. package/vscode/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/task/createAndRunTaskTool.js +227 -0
  198. package/vscode/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/task/getTaskOutputTool.d.ts +19 -0
  199. package/vscode/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/task/getTaskOutputTool.js +88 -0
  200. package/vscode/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/task/runTaskTool.d.ts +21 -0
  201. package/vscode/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/task/runTaskTool.js +140 -0
  202. package/vscode/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/task/taskHelpers.d.ts +22 -0
  203. package/vscode/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/task/taskHelpers.js +80 -0
  204. package/vscode/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/task.chatAgentTools.contribution.d.ts +1 -0
  205. package/vscode/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/task.chatAgentTools.contribution.js +40 -0
  206. package/vscode/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/terminal.chatAgentTools.contribution.d.ts +1 -0
  207. package/vscode/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/terminal.chatAgentTools.contribution.js +36 -0
  208. package/vscode/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/toolTerminalCreator.d.ts +20 -0
  209. package/vscode/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/toolTerminalCreator.js +114 -0
  210. package/vscode/src/vs/workbench/contrib/chat/browser/media/google-mono-dark.svg +0 -3
  211. package/vscode/src/vs/workbench/contrib/chat/browser/media/google-mono-light.svg +0 -3
@@ -0,0 +1,603 @@
1
+
2
+ import { __decorate, __param } from '@codingame/monaco-vscode-api/external/tslib/tslib.es6';
3
+ import { timeout } from '@codingame/monaco-vscode-api/vscode/vs/base/common/async';
4
+ import { CancellationError } from '@codingame/monaco-vscode-api/vscode/vs/base/common/errors';
5
+ import { MarkdownString } from '@codingame/monaco-vscode-api/vscode/vs/base/common/htmlContent';
6
+ import { Disposable, DisposableStore } from '@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle';
7
+ import { OS, OperatingSystem } from '@codingame/monaco-vscode-api/vscode/vs/base/common/platform';
8
+ import { count } from '@codingame/monaco-vscode-api/vscode/vs/base/common/strings';
9
+ import { generateUuid } from '@codingame/monaco-vscode-api/vscode/vs/base/common/uuid';
10
+ import { localize } from '@codingame/monaco-vscode-api/vscode/vs/nls';
11
+ import { IInstantiationService } from '@codingame/monaco-vscode-api/vscode/vs/platform/instantiation/common/instantiation';
12
+ import { StorageScope, StorageTarget } from '@codingame/monaco-vscode-api/vscode/vs/platform/storage/common/storage';
13
+ import { IStorageService } from '@codingame/monaco-vscode-api/vscode/vs/platform/storage/common/storage.service';
14
+ import { ITelemetryService } from '@codingame/monaco-vscode-api/vscode/vs/platform/telemetry/common/telemetry.service';
15
+ import { TerminalCapability } from '@codingame/monaco-vscode-a9da9abe-278d-5ce6-9418-99c7c07c5c37-common/vscode/vs/platform/terminal/common/capabilities/capabilities';
16
+ import { ITerminalLogService } from '@codingame/monaco-vscode-api/vscode/vs/platform/terminal/common/terminal.service';
17
+ import { IWorkspaceContextService } from '@codingame/monaco-vscode-api/vscode/vs/platform/workspace/common/workspace.service';
18
+ import { IRemoteAgentService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/remote/common/remoteAgentService.service';
19
+ import { IChatService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/common/chatService.service';
20
+ import { ILanguageModelsService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/common/languageModels.service';
21
+ import { ToolDataSource } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/common/languageModelToolsService';
22
+ import { ILanguageModelToolsService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/common/languageModelToolsService.service';
23
+ import { ITerminalService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/terminal/browser/terminal.service';
24
+ import { ITerminalProfileResolverService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/terminal/common/terminal.service';
25
+ import { getRecommendedToolsOverRunInTerminal } from './alternativeRecommendation.js';
26
+ import { pollForOutputAndIdle, racePollingOrPrompt, promptForMorePolling, getOutput } from './bufferOutputPolling.js';
27
+ import { CommandLineAutoApprover } from './commandLineAutoApprover.js';
28
+ import { BasicExecuteStrategy } from './executeStrategy/basicExecuteStrategy.js';
29
+ import { NoneExecuteStrategy } from './executeStrategy/noneExecuteStrategy.js';
30
+ import { RichExecuteStrategy } from './executeStrategy/richExecuteStrategy.js';
31
+ import { isPowerShell } from './runInTerminalHelpers.js';
32
+ import { splitCommandLineIntoSubCommands, extractInlineSubCommands } from './subCommands.js';
33
+ import { ShellIntegrationQuality, ToolTerminalCreator } from './toolTerminalCreator.js';
34
+
35
+ var RunInTerminalTool_1;
36
+ const TERMINAL_SESSION_STORAGE_KEY = 'chat.terminalSessions';
37
+ const RunInTerminalToolData = {
38
+ id: 'run_in_terminal',
39
+ toolReferenceName: 'runInTerminal',
40
+ displayName: ( localize(11261, 'Run in Terminal')),
41
+ modelDescription: [
42
+ 'This tool allows you to execute shell commands in a persistent terminal session, preserving environment variables, working directory, and other context across multiple commands.',
43
+ '',
44
+ 'Command Execution:',
45
+ '- Supports multi-line commands',
46
+ '',
47
+ 'Directory Management:',
48
+ '- Must use absolute paths to avoid navigation issues.',
49
+ '',
50
+ 'Program Execution:',
51
+ '- Supports Python, Node.js, and other executables.',
52
+ '- Install dependencies via pip, npm, etc.',
53
+ '',
54
+ 'Background Processes:',
55
+ '- For long-running tasks (e.g., servers), set isBackground=true.',
56
+ '- Returns a terminal ID for checking status and runtime later.',
57
+ '',
58
+ 'Output Management:',
59
+ '- Output is automatically truncated if longer than 60KB to prevent context overflow',
60
+ '- Use filters like \'head\', \'tail\', \'grep\' to limit output size',
61
+ '- For pager commands, disable paging: use \'git --no-pager\' or add \'| cat\'',
62
+ '',
63
+ 'Best Practices:',
64
+ '- Be specific with commands to avoid excessive output',
65
+ '- Use targeted queries instead of broad scans',
66
+ '- Consider using \'wc -l\' to count before listing many items'
67
+ ].join('\n'),
68
+ userDescription: ( localize(11262, 'Tool for running commands in the terminal')),
69
+ source: ToolDataSource.Internal,
70
+ inputSchema: {
71
+ type: 'object',
72
+ properties: {
73
+ command: {
74
+ type: 'string',
75
+ description: 'The command to run in the terminal.'
76
+ },
77
+ explanation: {
78
+ type: 'string',
79
+ description: 'A one-sentence description of what the command does. This will be shown to the user before the command is run.'
80
+ },
81
+ isBackground: {
82
+ type: 'boolean',
83
+ description: 'Whether the command starts a background process. If true, the command will run in the background and you will not see the output. If false, the tool call will block on the command finishing, and then you will get the output. Examples of background processes: building in watch mode, starting a server. You can check the output of a background process later on by using get_terminal_output.'
84
+ },
85
+ },
86
+ required: [
87
+ 'command',
88
+ 'explanation',
89
+ 'isBackground',
90
+ ]
91
+ }
92
+ };
93
+ const telemetryIgnoredSequences = [
94
+ '\x1b[I',
95
+ '\x1b[O',
96
+ ];
97
+ let RunInTerminalTool = class RunInTerminalTool extends Disposable {
98
+ static { RunInTerminalTool_1 = this; }
99
+ static { this._backgroundExecutions = ( new Map()); }
100
+ static getBackgroundOutput(id) {
101
+ const backgroundExecution = RunInTerminalTool_1._backgroundExecutions.get(id);
102
+ if (!backgroundExecution) {
103
+ throw ( new Error('Invalid terminal ID'));
104
+ }
105
+ return backgroundExecution.getOutput();
106
+ }
107
+ constructor(_instantiationService, _languageModelToolsService, _storageService, _telemetryService, _logService, _terminalProfileResolverService, _terminalService, _remoteAgentService, _chatService, _workspaceContextService, _languageModelsService) {
108
+ super();
109
+ this._instantiationService = _instantiationService;
110
+ this._languageModelToolsService = _languageModelToolsService;
111
+ this._storageService = _storageService;
112
+ this._telemetryService = _telemetryService;
113
+ this._logService = _logService;
114
+ this._terminalProfileResolverService = _terminalProfileResolverService;
115
+ this._terminalService = _terminalService;
116
+ this._remoteAgentService = _remoteAgentService;
117
+ this._chatService = _chatService;
118
+ this._workspaceContextService = _workspaceContextService;
119
+ this._languageModelsService = _languageModelsService;
120
+ this._sessionTerminalAssociations = ( new Map());
121
+ this._commandLineAutoApprover = this._register(_instantiationService.createInstance(CommandLineAutoApprover));
122
+ this._osBackend = this._remoteAgentService.getEnvironment().then(remoteEnv => remoteEnv?.os ?? OS);
123
+ this._restoreTerminalAssociations();
124
+ this._register(this._terminalService.onDidDisposeInstance(e => {
125
+ for (const [sessionId, toolTerminal] of this._sessionTerminalAssociations.entries()) {
126
+ if (e === toolTerminal.instance) {
127
+ this._sessionTerminalAssociations.delete(sessionId);
128
+ }
129
+ }
130
+ }));
131
+ this._register(this._chatService.onDidDisposeSession(e => {
132
+ this._cleanupSessionTerminals(e.sessionId);
133
+ }));
134
+ }
135
+ async prepareToolInvocation(context, token) {
136
+ const args = context.parameters;
137
+ this._alternativeRecommendation = getRecommendedToolsOverRunInTerminal(args.command, this._languageModelToolsService);
138
+ const presentation = this._alternativeRecommendation ? 'hidden' : undefined;
139
+ const os = await this._osBackend;
140
+ const shell = await this._terminalProfileResolverService.getDefaultShell({
141
+ os,
142
+ remoteAuthority: this._remoteAgentService.getConnection()?.remoteAuthority
143
+ });
144
+ const language = os === OperatingSystem.Windows ? 'pwsh' : 'sh';
145
+ const instance = context.chatSessionId ? this._sessionTerminalAssociations.get(context.chatSessionId)?.instance : undefined;
146
+ let toolEditedCommand = await this._rewriteCommandIfNeeded(args, instance, shell);
147
+ if (toolEditedCommand === args.command) {
148
+ toolEditedCommand = undefined;
149
+ }
150
+ let confirmationMessages;
151
+ if (this._alternativeRecommendation) {
152
+ confirmationMessages = undefined;
153
+ }
154
+ else {
155
+ const actualCommand = toolEditedCommand ?? args.command;
156
+ const subCommands = splitCommandLineIntoSubCommands(actualCommand, shell, os);
157
+ const inlineSubCommands = ( subCommands.map(e => Array.from(extractInlineSubCommands(e, shell, os)))).flat();
158
+ const allSubCommands = [...subCommands, ...inlineSubCommands];
159
+ const subCommandResults = ( allSubCommands.map(e => this._commandLineAutoApprover.isCommandAutoApproved(e, shell, os)));
160
+ const commandLineResult = this._commandLineAutoApprover.isCommandLineAutoApproved(actualCommand);
161
+ const autoApproveReasons = [
162
+ ...( subCommandResults.map(e => e.reason)),
163
+ commandLineResult.reason,
164
+ ];
165
+ let isAutoApproved = false;
166
+ if (( subCommandResults.some(e => e.result === 'denied'))) {
167
+ this._logService.info('autoApprove: Sub-command DENIED auto approval');
168
+ }
169
+ else if (commandLineResult.result === 'denied') {
170
+ this._logService.info('autoApprove: Command line DENIED auto approval');
171
+ }
172
+ else {
173
+ if (subCommandResults.every(e => e.result === 'approved')) {
174
+ this._logService.info('autoApprove: All sub-commands auto-approved');
175
+ isAutoApproved = true;
176
+ }
177
+ else {
178
+ this._logService.info('autoApprove: All sub-commands NOT auto-approved');
179
+ if (commandLineResult.result === 'approved') {
180
+ this._logService.info('autoApprove: Command line auto-approved');
181
+ isAutoApproved = true;
182
+ }
183
+ else {
184
+ this._logService.info('autoApprove: Command line NOT auto-approved');
185
+ }
186
+ }
187
+ }
188
+ for (const reason of autoApproveReasons) {
189
+ this._logService.info(`- ${reason}`);
190
+ }
191
+ confirmationMessages = isAutoApproved ? undefined : {
192
+ title: args.isBackground
193
+ ? ( localize(11263, "Run command in background terminal"))
194
+ : ( localize(11264, "Run command in terminal")),
195
+ message: ( new MarkdownString(args.explanation)),
196
+ };
197
+ }
198
+ return {
199
+ confirmationMessages,
200
+ presentation,
201
+ toolSpecificData: {
202
+ kind: 'terminal',
203
+ commandLine: {
204
+ original: args.command,
205
+ toolEdited: toolEditedCommand
206
+ },
207
+ language,
208
+ }
209
+ };
210
+ }
211
+ async invoke(invocation, _countTokens, _progress, token) {
212
+ if (this._alternativeRecommendation) {
213
+ return this._alternativeRecommendation;
214
+ }
215
+ const args = invocation.parameters;
216
+ this._logService.debug(`RunInTerminalTool: Invoking with options ${JSON.stringify(args)}`);
217
+ const toolSpecificData = invocation.toolSpecificData;
218
+ if (!toolSpecificData) {
219
+ throw ( new Error('toolSpecificData must be provided for this tool'));
220
+ }
221
+ let toolResultMessage;
222
+ const chatSessionId = invocation.context?.sessionId ?? 'no-chat-session';
223
+ const command = toolSpecificData.commandLine.userEdited ?? toolSpecificData.commandLine.toolEdited ?? toolSpecificData.commandLine.original;
224
+ const didUserEditCommand = (toolSpecificData.commandLine.userEdited !== undefined &&
225
+ toolSpecificData.commandLine.userEdited !== toolSpecificData.commandLine.original);
226
+ const didToolEditCommand = (!didUserEditCommand &&
227
+ toolSpecificData.commandLine.toolEdited !== undefined &&
228
+ toolSpecificData.commandLine.toolEdited !== toolSpecificData.commandLine.original);
229
+ if (token.isCancellationRequested) {
230
+ throw ( new CancellationError());
231
+ }
232
+ let error;
233
+ const isNewSession = !args.isBackground && !( this._sessionTerminalAssociations.has(chatSessionId));
234
+ const timingStart = Date.now();
235
+ const termId = generateUuid();
236
+ const store = ( new DisposableStore());
237
+ this._logService.debug(`RunInTerminalTool: Creating ${args.isBackground ? 'background' : 'foreground'} terminal. termId=${termId}, chatSessionId=${chatSessionId}`);
238
+ const toolTerminal = await (args.isBackground
239
+ ? this._initBackgroundTerminal(chatSessionId, termId, token)
240
+ : this._initForegroundTerminal(chatSessionId, termId, token));
241
+ this._terminalService.setActiveInstance(toolTerminal.instance);
242
+ this._terminalService.revealTerminal(toolTerminal.instance, true);
243
+ const timingConnectMs = Date.now() - timingStart;
244
+ const xterm = await toolTerminal.instance.xtermReadyPromise;
245
+ if (!xterm) {
246
+ throw ( new Error('Instance was disposed before xterm.js was ready'));
247
+ }
248
+ let inputUserChars = 0;
249
+ let inputUserSigint = false;
250
+ store.add(xterm.raw.onData(data => {
251
+ if (!telemetryIgnoredSequences.includes(data)) {
252
+ inputUserChars += data.length;
253
+ }
254
+ inputUserSigint ||= data === '\x03';
255
+ }));
256
+ if (args.isBackground) {
257
+ let outputAndIdle = undefined;
258
+ try {
259
+ this._logService.debug(`RunInTerminalTool: Starting background execution \`${command}\``);
260
+ const execution = ( new BackgroundTerminalExecution(toolTerminal.instance, xterm, command));
261
+ RunInTerminalTool_1._backgroundExecutions.set(termId, execution);
262
+ outputAndIdle = await pollForOutputAndIdle(execution, false, token, this._languageModelsService);
263
+ if (token.isCancellationRequested) {
264
+ throw ( new CancellationError());
265
+ }
266
+ if (!outputAndIdle.terminalExecutionIdleBeforeTimeout) {
267
+ outputAndIdle = await racePollingOrPrompt(() => pollForOutputAndIdle(execution, true, token, this._languageModelsService), () => promptForMorePolling(command, token, invocation.context, this._chatService), outputAndIdle, token, this._languageModelsService, execution);
268
+ if (token.isCancellationRequested) {
269
+ throw ( new CancellationError());
270
+ }
271
+ }
272
+ let resultText = (didUserEditCommand
273
+ ? `Note: The user manually edited the command to \`${command}\`, and that command is now running in terminal with ID=${termId}`
274
+ : didToolEditCommand
275
+ ? `Note: The tool simplified the command to \`${command}\`, and that command is now running in terminal with ID=${termId}`
276
+ : `Command is running in terminal with ID=${termId}`);
277
+ if (outputAndIdle && outputAndIdle.modelOutputEvalResponse) {
278
+ resultText += `\n\ The command became idle with output:\n${outputAndIdle.modelOutputEvalResponse}`;
279
+ }
280
+ else if (outputAndIdle) {
281
+ resultText += `\n\ The command is still running, with output:\n${outputAndIdle.output}`;
282
+ }
283
+ return {
284
+ content: [{
285
+ kind: 'text',
286
+ value: resultText,
287
+ }]
288
+ };
289
+ }
290
+ catch (e) {
291
+ if (termId) {
292
+ RunInTerminalTool_1._backgroundExecutions.get(termId)?.dispose();
293
+ RunInTerminalTool_1._backgroundExecutions.delete(termId);
294
+ }
295
+ error = e instanceof CancellationError ? 'canceled' : 'unexpectedException';
296
+ throw e;
297
+ }
298
+ finally {
299
+ store.dispose();
300
+ this._logService.debug(`RunInTerminalTool: Finished polling \`${outputAndIdle?.output.length}\` lines of output in \`${outputAndIdle?.pollDurationMs}\``);
301
+ const timingExecuteMs = Date.now() - timingStart;
302
+ this._sendTelemetry(toolTerminal.instance, {
303
+ didUserEditCommand,
304
+ didToolEditCommand,
305
+ shellIntegrationQuality: toolTerminal.shellIntegrationQuality,
306
+ isBackground: true,
307
+ error,
308
+ exitCode: undefined,
309
+ isNewSession: true,
310
+ timingExecuteMs,
311
+ timingConnectMs,
312
+ terminalExecutionIdleBeforeTimeout: outputAndIdle?.terminalExecutionIdleBeforeTimeout,
313
+ outputLineCount: outputAndIdle?.output ? count(outputAndIdle.output, '\n') : 0,
314
+ pollDurationMs: outputAndIdle?.pollDurationMs,
315
+ inputUserChars,
316
+ inputUserSigint,
317
+ });
318
+ }
319
+ }
320
+ else {
321
+ let terminalResult = '';
322
+ let outputLineCount = -1;
323
+ let exitCode;
324
+ try {
325
+ let strategy;
326
+ const commandDetection = toolTerminal.instance.capabilities.get(TerminalCapability.CommandDetection);
327
+ switch (toolTerminal.shellIntegrationQuality) {
328
+ case ShellIntegrationQuality.None: {
329
+ strategy = this._instantiationService.createInstance(NoneExecuteStrategy, toolTerminal.instance);
330
+ toolResultMessage = ( new MarkdownString(
331
+ 'Enable [shell integration](https://code.visualstudio.com/docs/terminal/shell-integration) to improve command detection'
332
+ ));
333
+ break;
334
+ }
335
+ case ShellIntegrationQuality.Basic: {
336
+ strategy = this._instantiationService.createInstance(BasicExecuteStrategy, toolTerminal.instance, commandDetection);
337
+ break;
338
+ }
339
+ case ShellIntegrationQuality.Rich: {
340
+ strategy = this._instantiationService.createInstance(RichExecuteStrategy, toolTerminal.instance, commandDetection);
341
+ break;
342
+ }
343
+ }
344
+ this._logService.debug(`RunInTerminalTool: Using \`${strategy.type}\` execute strategy for command \`${command}\``);
345
+ const executeResult = await strategy.execute(command, token);
346
+ if (token.isCancellationRequested) {
347
+ throw ( new CancellationError());
348
+ }
349
+ this._logService.debug(`RunInTerminalTool: Finished \`${strategy.type}\` execute strategy with exitCode \`${executeResult.exitCode}\`, result.length \`${executeResult.output?.length}\`, error \`${executeResult.error}\``);
350
+ outputLineCount = executeResult.output === undefined ? 0 : count(executeResult.output.trim(), '\n') + 1;
351
+ exitCode = executeResult.exitCode;
352
+ error = executeResult.error;
353
+ const resultArr = [];
354
+ if (executeResult.output !== undefined) {
355
+ resultArr.push(executeResult.output);
356
+ }
357
+ if (executeResult.additionalInformation) {
358
+ resultArr.push(executeResult.additionalInformation);
359
+ }
360
+ terminalResult = resultArr.join('\n\n');
361
+ }
362
+ catch (e) {
363
+ this._logService.debug(`RunInTerminalTool: Threw exception`);
364
+ toolTerminal.instance.dispose();
365
+ error = e instanceof CancellationError ? 'canceled' : 'unexpectedException';
366
+ throw e;
367
+ }
368
+ finally {
369
+ store.dispose();
370
+ const timingExecuteMs = Date.now() - timingStart;
371
+ this._sendTelemetry(toolTerminal.instance, {
372
+ didUserEditCommand,
373
+ didToolEditCommand,
374
+ isBackground: false,
375
+ shellIntegrationQuality: toolTerminal.shellIntegrationQuality,
376
+ error,
377
+ isNewSession,
378
+ outputLineCount,
379
+ exitCode,
380
+ timingExecuteMs,
381
+ timingConnectMs,
382
+ inputUserChars,
383
+ inputUserSigint,
384
+ });
385
+ }
386
+ const resultText = [];
387
+ if (didUserEditCommand) {
388
+ resultText.push(`Note: The user manually edited the command to \`${command}\`, and this is the output of running that command instead:\n`);
389
+ }
390
+ else if (didToolEditCommand) {
391
+ resultText.push(`Note: The tool simplified the command to \`${command}\`, and this is the output of running that command instead:\n`);
392
+ }
393
+ resultText.push(terminalResult);
394
+ return {
395
+ toolResultMessage,
396
+ content: [{
397
+ kind: 'text',
398
+ value: resultText.join(''),
399
+ }]
400
+ };
401
+ }
402
+ }
403
+ async _initBackgroundTerminal(chatSessionId, termId, token) {
404
+ this._logService.debug(`RunInTerminalTool: Creating background terminal with ID=${termId}`);
405
+ const toolTerminal = await this._instantiationService.createInstance(ToolTerminalCreator).createTerminal(token);
406
+ this._sessionTerminalAssociations.set(chatSessionId, toolTerminal);
407
+ if (token.isCancellationRequested) {
408
+ toolTerminal.instance.dispose();
409
+ throw ( new CancellationError());
410
+ }
411
+ await this._setupProcessIdAssociation(toolTerminal, chatSessionId, termId, true);
412
+ return toolTerminal;
413
+ }
414
+ async _initForegroundTerminal(chatSessionId, termId, token) {
415
+ const cachedTerminal = this._sessionTerminalAssociations.get(chatSessionId);
416
+ if (cachedTerminal) {
417
+ this._logService.debug(`RunInTerminalTool: Using cached foreground terminal with session ID \`${chatSessionId}\``);
418
+ return cachedTerminal;
419
+ }
420
+ const toolTerminal = await this._instantiationService.createInstance(ToolTerminalCreator).createTerminal(token);
421
+ this._sessionTerminalAssociations.set(chatSessionId, toolTerminal);
422
+ if (token.isCancellationRequested) {
423
+ toolTerminal.instance.dispose();
424
+ throw ( new CancellationError());
425
+ }
426
+ await this._setupProcessIdAssociation(toolTerminal, chatSessionId, termId, false);
427
+ return toolTerminal;
428
+ }
429
+ async _rewriteCommandIfNeeded(args, instance, shell) {
430
+ const commandLine = args.command;
431
+ const os = await this._osBackend;
432
+ const isPwsh = isPowerShell(shell, os);
433
+ const cdPrefixMatch = commandLine.match(isPwsh
434
+ ? /^(?:cd(?: \/d)?|Set-Location(?: -Path)?) (?<dir>[^\s]+) ?(?:&&|;)\s+(?<suffix>.+)$/i
435
+ : /^cd (?<dir>[^\s]+) &&\s+(?<suffix>.+)$/);
436
+ const cdDir = cdPrefixMatch?.groups?.dir;
437
+ const cdSuffix = cdPrefixMatch?.groups?.suffix;
438
+ if (cdDir && cdSuffix) {
439
+ let cwd;
440
+ if (instance) {
441
+ cwd = await instance.getCwdResource();
442
+ }
443
+ if (!cwd) {
444
+ const workspaceFolders = this._workspaceContextService.getWorkspace().folders;
445
+ if (workspaceFolders.length === 1) {
446
+ cwd = workspaceFolders[0].uri;
447
+ }
448
+ }
449
+ if (cwd) {
450
+ let cdDirPath = cdDir;
451
+ if (cdDirPath.startsWith('"') && cdDirPath.endsWith('"')) {
452
+ cdDirPath = cdDirPath.slice(1, -1);
453
+ }
454
+ cdDirPath = cdDirPath.replace(/(?:[\\\/])$/, '');
455
+ let cwdFsPath = cwd.fsPath.replace(/(?:[\\\/])$/, '');
456
+ if (os === OperatingSystem.Windows) {
457
+ cdDirPath = cdDirPath.toLowerCase();
458
+ cwdFsPath = cwdFsPath.toLowerCase();
459
+ }
460
+ if (cdDirPath === cwdFsPath) {
461
+ return cdSuffix;
462
+ }
463
+ }
464
+ }
465
+ return commandLine;
466
+ }
467
+ _restoreTerminalAssociations() {
468
+ const storedAssociations = this._storageService.get(TERMINAL_SESSION_STORAGE_KEY, StorageScope.WORKSPACE, '{}');
469
+ try {
470
+ const associations = JSON.parse(storedAssociations);
471
+ for (const instance of this._terminalService.instances) {
472
+ if (instance.processId) {
473
+ const association = associations[instance.processId];
474
+ if (association) {
475
+ this._logService.debug(`RunInTerminalTool: Restored terminal association for PID ${instance.processId}, session ${association.sessionId}`);
476
+ const toolTerminal = {
477
+ instance,
478
+ shellIntegrationQuality: association.shellIntegrationQuality
479
+ };
480
+ this._sessionTerminalAssociations.set(association.sessionId, toolTerminal);
481
+ this._register(instance.onDisposed(() => {
482
+ this._removeProcessIdAssociation(instance.processId);
483
+ }));
484
+ }
485
+ }
486
+ }
487
+ }
488
+ catch (error) {
489
+ this._logService.debug(`RunInTerminalTool: Failed to restore terminal associations: ${error}`);
490
+ }
491
+ }
492
+ async _setupProcessIdAssociation(toolTerminal, chatSessionId, termId, isBackground) {
493
+ await this._associateProcessIdWithSession(toolTerminal.instance, chatSessionId, termId, toolTerminal.shellIntegrationQuality, isBackground);
494
+ this._register(toolTerminal.instance.onDisposed(() => {
495
+ if (toolTerminal.instance.processId) {
496
+ this._removeProcessIdAssociation(toolTerminal.instance.processId);
497
+ }
498
+ }));
499
+ }
500
+ async _associateProcessIdWithSession(terminal, sessionId, id, shellIntegrationQuality, isBackground) {
501
+ try {
502
+ const pid = await Promise.race([
503
+ terminal.processReady.then(() => terminal.processId),
504
+ timeout(5000).then(() => { throw ( new Error('Timeout')); })
505
+ ]);
506
+ if (typeof pid === 'number') {
507
+ const storedAssociations = this._storageService.get(TERMINAL_SESSION_STORAGE_KEY, StorageScope.WORKSPACE, '{}');
508
+ const associations = JSON.parse(storedAssociations);
509
+ const existingAssociation = associations[pid] || {};
510
+ associations[pid] = {
511
+ ...existingAssociation,
512
+ sessionId,
513
+ shellIntegrationQuality,
514
+ id,
515
+ isBackground
516
+ };
517
+ this._storageService.store(TERMINAL_SESSION_STORAGE_KEY, JSON.stringify(associations), StorageScope.WORKSPACE, StorageTarget.USER);
518
+ this._logService.debug(`RunInTerminalTool: Associated terminal PID ${pid} with session ${sessionId}`);
519
+ }
520
+ }
521
+ catch (error) {
522
+ this._logService.debug(`RunInTerminalTool: Failed to associate terminal with session: ${error}`);
523
+ }
524
+ }
525
+ async _removeProcessIdAssociation(pid) {
526
+ try {
527
+ const storedAssociations = this._storageService.get(TERMINAL_SESSION_STORAGE_KEY, StorageScope.WORKSPACE, '{}');
528
+ const associations = JSON.parse(storedAssociations);
529
+ if (associations[pid]) {
530
+ delete associations[pid];
531
+ this._storageService.store(TERMINAL_SESSION_STORAGE_KEY, JSON.stringify(associations), StorageScope.WORKSPACE, StorageTarget.USER);
532
+ this._logService.debug(`RunInTerminalTool: Removed terminal association for PID ${pid}`);
533
+ }
534
+ }
535
+ catch (error) {
536
+ this._logService.debug(`RunInTerminalTool: Failed to remove terminal association: ${error}`);
537
+ }
538
+ }
539
+ _cleanupSessionTerminals(sessionId) {
540
+ const toolTerminal = this._sessionTerminalAssociations.get(sessionId);
541
+ if (toolTerminal) {
542
+ this._logService.debug(`RunInTerminalTool: Cleaning up terminal for disposed chat session ${sessionId}`);
543
+ this._sessionTerminalAssociations.delete(sessionId);
544
+ toolTerminal.instance.dispose();
545
+ const terminalToRemove = [];
546
+ for (const [termId, execution] of RunInTerminalTool_1._backgroundExecutions.entries()) {
547
+ if (execution.instance === toolTerminal.instance) {
548
+ execution.dispose();
549
+ terminalToRemove.push(termId);
550
+ }
551
+ }
552
+ for (const termId of terminalToRemove) {
553
+ RunInTerminalTool_1._backgroundExecutions.delete(termId);
554
+ }
555
+ }
556
+ }
557
+ _sendTelemetry(instance, state) {
558
+ this._telemetryService.publicLog2('toolUse.runInTerminal', {
559
+ terminalSessionId: instance.sessionId,
560
+ result: state.error ?? 'success',
561
+ strategy: state.shellIntegrationQuality === ShellIntegrationQuality.Rich ? 2 : state.shellIntegrationQuality === ShellIntegrationQuality.Basic ? 1 : 0,
562
+ userEditedCommand: state.didUserEditCommand ? 1 : 0,
563
+ toolEditedCommand: state.didToolEditCommand ? 1 : 0,
564
+ isBackground: state.isBackground ? 1 : 0,
565
+ isNewSession: state.isNewSession ? 1 : 0,
566
+ outputLineCount: state.outputLineCount,
567
+ nonZeroExitCode: state.exitCode === undefined ? -1 : state.exitCode === 0 ? 0 : 1,
568
+ timingConnectMs: state.timingConnectMs,
569
+ pollDurationMs: state.pollDurationMs ?? 0,
570
+ terminalExecutionIdleBeforeTimeout: state.terminalExecutionIdleBeforeTimeout ?? false,
571
+ inputUserChars: state.inputUserChars,
572
+ inputUserSigint: state.inputUserSigint,
573
+ });
574
+ }
575
+ };
576
+ RunInTerminalTool = RunInTerminalTool_1 = ( __decorate([
577
+ ( __param(0, IInstantiationService)),
578
+ ( __param(1, ILanguageModelToolsService)),
579
+ ( __param(2, IStorageService)),
580
+ ( __param(3, ITelemetryService)),
581
+ ( __param(4, ITerminalLogService)),
582
+ ( __param(5, ITerminalProfileResolverService)),
583
+ ( __param(6, ITerminalService)),
584
+ ( __param(7, IRemoteAgentService)),
585
+ ( __param(8, IChatService)),
586
+ ( __param(9, IWorkspaceContextService)),
587
+ ( __param(10, ILanguageModelsService))
588
+ ], RunInTerminalTool));
589
+ class BackgroundTerminalExecution extends Disposable {
590
+ constructor(instance, _xterm, _commandLine) {
591
+ super();
592
+ this.instance = instance;
593
+ this._xterm = _xterm;
594
+ this._commandLine = _commandLine;
595
+ this._startMarker = this._register(this._xterm.raw.registerMarker());
596
+ this.instance.runCommand(this._commandLine, true);
597
+ }
598
+ getOutput() {
599
+ return getOutput(this.instance, this._startMarker);
600
+ }
601
+ }
602
+
603
+ export { RunInTerminalTool, RunInTerminalToolData };
@@ -0,0 +1,3 @@
1
+ import type { OperatingSystem } from "@codingame/monaco-vscode-api/vscode/vs/base/common/platform";
2
+ export declare function splitCommandLineIntoSubCommands(commandLine: string, envShell: string, envOS: OperatingSystem): string[];
3
+ export declare function extractInlineSubCommands(commandLine: string, envShell: string, envOS: OperatingSystem): Set<string>;